1 /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
3 client.c for the Openbox window manager
4 Copyright (c) 2003 Ben Jansens
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 See the COPYING file for a copy of the GNU General Public License.
21 #include "startupnotify.h"
25 #include "moveresize.h"
28 #include "extensions.h"
38 #include "menuframe.h"
41 #include "render/render.h"
44 #include <X11/Xutil.h>
46 /*! The event mask to grab on client windows */
47 #define CLIENT_EVENTMASK (PropertyChangeMask | FocusChangeMask | \
50 #define CLIENT_NOPROPAGATEMASK (ButtonPressMask | ButtonReleaseMask | \
55 ObClientDestructor func;
59 GList *client_list = NULL;
60 GSList *client_destructors = NULL;
62 static void client_get_all(ObClient *self);
63 static void client_toggle_border(ObClient *self, gboolean show);
64 static void client_get_startup_id(ObClient *self);
65 static void client_get_area(ObClient *self);
66 static void client_get_desktop(ObClient *self);
67 static void client_get_state(ObClient *self);
68 static void client_get_shaped(ObClient *self);
69 static void client_get_mwm_hints(ObClient *self);
70 static void client_get_gravity(ObClient *self);
71 static void client_showhide(ObClient *self);
72 static void client_change_allowed_actions(ObClient *self);
73 static void client_change_state(ObClient *self);
74 static void client_apply_startup_state(ObClient *self);
75 static void client_restore_session_state(ObClient *self);
76 static void client_restore_session_stacking(ObClient *self);
77 static void client_urgent_notify(ObClient *self);
79 void client_startup(gboolean reconfig)
86 void client_shutdown(gboolean reconfig)
90 void client_add_destructor(ObClientDestructor func, gpointer data)
92 Destructor *d = g_new(Destructor, 1);
95 client_destructors = g_slist_prepend(client_destructors, d);
98 void client_remove_destructor(ObClientDestructor func)
102 for (it = client_destructors; it; it = g_slist_next(it)) {
103 Destructor *d = it->data;
104 if (d->func == func) {
106 client_destructors = g_slist_delete_link(client_destructors, it);
112 void client_set_list()
114 Window *windows, *win_it;
116 guint size = g_list_length(client_list);
118 /* create an array of the window ids */
120 windows = g_new(Window, size);
122 for (it = client_list; it; it = g_list_next(it), ++win_it)
123 *win_it = ((ObClient*)it->data)->window;
127 PROP_SETA32(RootWindow(ob_display, ob_screen),
128 net_client_list, window, (guint32*)windows, size);
137 void client_foreach_transient(ObClient *self, ObClientForeachFunc func, gpointer data)
141 for (it = self->transients; it; it = g_slist_next(it)) {
142 if (!func(it->data, data)) return;
143 client_foreach_transient(it->data, func, data);
147 void client_foreach_ancestor(ObClient *self, ObClientForeachFunc func, gpointer data)
149 if (self->transient_for) {
150 if (self->transient_for != OB_TRAN_GROUP) {
151 if (!func(self->transient_for, data)) return;
152 client_foreach_ancestor(self->transient_for, func, data);
156 for (it = self->group->members; it; it = g_slist_next(it))
157 if (it->data != self &&
158 !((ObClient*)it->data)->transient_for) {
159 if (!func(it->data, data)) return;
160 client_foreach_ancestor(it->data, func, data);
167 void client_manage_all()
172 XWindowAttributes attrib;
174 XQueryTree(ob_display, RootWindow(ob_display, ob_screen),
175 &w, &w, &children, &nchild);
177 /* remove all icon windows from the list */
178 for (i = 0; i < nchild; i++) {
179 if (children[i] == None) continue;
180 wmhints = XGetWMHints(ob_display, children[i]);
182 if ((wmhints->flags & IconWindowHint) &&
183 (wmhints->icon_window != children[i]))
184 for (j = 0; j < nchild; j++)
185 if (children[j] == wmhints->icon_window) {
193 for (i = 0; i < nchild; ++i) {
194 if (children[i] == None)
196 if (XGetWindowAttributes(ob_display, children[i], &attrib)) {
197 if (attrib.override_redirect) continue;
199 if (attrib.map_state != IsUnmapped)
200 client_manage(children[i]);
206 void client_manage(Window window)
210 XWindowAttributes attrib;
211 XSetWindowAttributes attrib_set;
213 gboolean activate = FALSE;
217 /* check if it has already been unmapped by the time we started mapping
218 the grab does a sync so we don't have to here */
219 if (XCheckTypedWindowEvent(ob_display, window, DestroyNotify, &e) ||
220 XCheckTypedWindowEvent(ob_display, window, UnmapNotify, &e)) {
221 XPutBackEvent(ob_display, &e);
224 return; /* don't manage it */
227 /* make sure it isn't an override-redirect window */
228 if (!XGetWindowAttributes(ob_display, window, &attrib) ||
229 attrib.override_redirect) {
231 return; /* don't manage it */
234 /* is the window a docking app */
235 if ((wmhint = XGetWMHints(ob_display, window))) {
236 if ((wmhint->flags & StateHint) &&
237 wmhint->initial_state == WithdrawnState) {
238 dock_add(window, wmhint);
246 ob_debug("Managing window: %lx\n", window);
248 /* choose the events we want to receive on the CLIENT window */
249 attrib_set.event_mask = CLIENT_EVENTMASK;
250 attrib_set.do_not_propagate_mask = CLIENT_NOPROPAGATEMASK;
251 XChangeWindowAttributes(ob_display, window,
252 CWEventMask|CWDontPropagate, &attrib_set);
255 /* create the ObClient struct, and populate it from the hints on the
257 self = g_new0(ObClient, 1);
258 self->obwin.type = Window_Client;
259 self->window = window;
261 /* non-zero defaults */
262 self->title_count = 1;
263 self->wmstate = NormalState;
265 self->desktop = screen_num_desktops; /* always an invalid value */
267 client_get_all(self);
268 client_restore_session_state(self);
270 sn_app_started(self->class);
272 /* update the focus lists, do this before the call to change_state or
273 it can end up in the list twice! */
274 focus_order_add_new(self);
276 client_change_state(self);
278 /* remove the client's border (and adjust re gravity) */
279 client_toggle_border(self, FALSE);
281 /* specify that if we exit, the window should not be destroyed and should
282 be reparented back to root automatically */
283 XChangeSaveSet(ob_display, window, SetModeInsert);
285 /* create the decoration frame for the client window */
286 self->frame = frame_new();
288 frame_grab_client(self->frame, self);
292 client_apply_startup_state(self);
294 stacking_add(CLIENT_AS_WINDOW(self));
295 client_restore_session_stacking(self);
297 /* focus the new window? */
298 if (ob_state() != OB_STATE_STARTING &&
299 (config_focus_new || client_search_focus_parent(self)) &&
300 /* note the check against Type_Normal/Dialog, not client_normal(self),
301 which would also include other types. in this case we want more
302 strict rules for focus */
303 (self->type == OB_CLIENT_TYPE_NORMAL ||
304 self->type == OB_CLIENT_TYPE_DIALOG))
308 if (self->desktop != screen_desktop) {
309 /* activate the window */
312 gboolean group_foc = FALSE;
317 for (it = self->group->members; it; it = g_slist_next(it))
319 if (client_focused(it->data))
327 (!self->transient_for && (!self->group ||
328 !self->group->members->next))) ||
329 client_search_focus_tree_full(self) ||
331 !client_normal(focus_client))
333 /* activate the window */
340 if (ob_state() == OB_STATE_RUNNING) {
341 gint x = self->area.x, ox = x;
342 gint y = self->area.y, oy = y;
344 place_client(self, &x, &y);
346 /* make sure the window is visible */
347 client_find_onscreen(self, &x, &y,
348 self->frame->area.width,
349 self->frame->area.height,
350 /* non-normal clients has less rules, and
351 windows that are being restored from a session
352 do also. we can assume you want it back where
354 client_normal(self) && !self->session);
356 if (x != ox || y != oy)
357 client_move(self, x, y);
360 client_showhide(self);
362 /* use client_focus instead of client_activate cuz client_activate does
363 stuff like switch desktops etc and I'm not interested in all that when
364 a window maps since its not based on an action from the user like
365 clicking a window to activate is. so keep the new window out of the way
368 /* if using focus_delay, stop the timer now so that focus doesn't go
370 event_halt_focus_delay();
373 /* since focus can change the stacking orders, if we focus the window
374 then the standard raise it gets is not enough, we need to queue one
375 for after the focus change takes place */
379 /* client_activate does this but we aret using it so we have to do it
381 if (screen_showing_desktop)
382 screen_show_desktop(FALSE);
384 /* add to client list/map */
385 client_list = g_list_append(client_list, self);
386 g_hash_table_insert(window_map, &self->window, self);
388 /* this has to happen after we're in the client_list */
389 screen_update_areas();
391 /* update the list hints */
394 keyboard_grab_for_client(self, TRUE);
395 mouse_grab_for_client(self, TRUE);
397 ob_debug("Managed window 0x%lx (%s)\n", window, self->class);
400 void client_unmanage_all()
402 while (client_list != NULL)
403 client_unmanage(client_list->data);
406 void client_unmanage(ObClient *self)
411 ob_debug("Unmanaging window: %lx (%s)\n", self->window, self->class);
413 g_assert(self != NULL);
415 keyboard_grab_for_client(self, FALSE);
416 mouse_grab_for_client(self, FALSE);
418 /* remove the window from our save set */
419 XChangeSaveSet(ob_display, self->window, SetModeDelete);
421 /* we dont want events no more */
422 XSelectInput(ob_display, self->window, NoEventMask);
424 frame_hide(self->frame);
426 client_list = g_list_remove(client_list, self);
427 stacking_remove(self);
428 g_hash_table_remove(window_map, &self->window);
430 /* update the focus lists */
431 focus_order_remove(self);
433 /* once the client is out of the list, update the struts to remove it's
435 screen_update_areas();
437 for (it = client_destructors; it; it = g_slist_next(it)) {
438 Destructor *d = it->data;
439 d->func(self, d->data);
442 if (focus_client == self) {
445 /* focus the last focused window on the desktop, and ignore enter
446 events from the unmap so it doesnt mess with the focus */
447 while (XCheckTypedEvent(ob_display, EnterNotify, &e));
448 /* remove these flags so we don't end up getting focused in the
450 self->can_focus = FALSE;
451 self->focus_notify = FALSE;
453 client_unfocus(self);
456 /* tell our parent(s) that we're gone */
457 if (self->transient_for == OB_TRAN_GROUP) { /* transient of group */
460 for (it = self->group->members; it; it = g_slist_next(it))
461 if (it->data != self)
462 ((ObClient*)it->data)->transients =
463 g_slist_remove(((ObClient*)it->data)->transients, self);
464 } else if (self->transient_for) { /* transient of window */
465 self->transient_for->transients =
466 g_slist_remove(self->transient_for->transients, self);
469 /* tell our transients that we're gone */
470 for (it = self->transients; it; it = g_slist_next(it)) {
471 if (((ObClient*)it->data)->transient_for != OB_TRAN_GROUP) {
472 ((ObClient*)it->data)->transient_for = NULL;
473 client_calc_layer(it->data);
477 /* remove from its group */
479 group_remove(self->group, self);
483 /* give the client its border back */
484 client_toggle_border(self, TRUE);
486 /* reparent the window out of the frame, and free the frame */
487 frame_release_client(self->frame, self);
490 if (ob_state() != OB_STATE_EXITING) {
491 /* these values should not be persisted across a window
493 PROP_ERASE(self->window, net_wm_desktop);
494 PROP_ERASE(self->window, net_wm_state);
495 PROP_ERASE(self->window, wm_state);
497 /* if we're left in an unmapped state, the client wont be mapped. this
498 is bad, since we will no longer be managing the window on restart */
499 XMapWindow(ob_display, self->window);
503 ob_debug("Unmanaged window 0x%lx\n", self->window);
505 /* free all data allocated in the client struct */
506 g_slist_free(self->transients);
507 for (j = 0; j < self->nicons; ++j)
508 g_free(self->icons[j].data);
509 if (self->nicons > 0)
512 g_free(self->icon_title);
516 g_free(self->sm_client_id);
519 /* update the list hints */
523 static void client_urgent_notify(ObClient *self)
526 frame_flash_start(self->frame);
528 frame_flash_stop(self->frame);
531 static void client_restore_session_state(ObClient *self)
535 if (!(it = session_state_find(self)))
538 self->session = it->data;
540 RECT_SET_POINT(self->area, self->session->x, self->session->y);
541 self->positioned = TRUE;
542 if (self->session->w > 0)
543 self->area.width = self->session->w;
544 if (self->session->h > 0)
545 self->area.height = self->session->h;
546 XResizeWindow(ob_display, self->window,
547 self->area.width, self->area.height);
549 self->desktop = (self->session->desktop == DESKTOP_ALL ?
550 self->session->desktop :
551 MIN(screen_num_desktops - 1, self->session->desktop));
552 PROP_SET32(self->window, net_wm_desktop, cardinal, self->desktop);
554 self->shaded = self->session->shaded;
555 self->iconic = self->session->iconic;
556 self->skip_pager = self->session->skip_pager;
557 self->skip_taskbar = self->session->skip_taskbar;
558 self->fullscreen = self->session->fullscreen;
559 self->above = self->session->above;
560 self->below = self->session->below;
561 self->max_horz = self->session->max_horz;
562 self->max_vert = self->session->max_vert;
565 static void client_restore_session_stacking(ObClient *self)
569 if (!self->session) return;
571 it = g_list_find(session_saved_state, self->session);
572 for (it = g_list_previous(it); it; it = g_list_previous(it)) {
575 for (cit = client_list; cit; cit = g_list_next(cit))
576 if (session_state_cmp(it->data, cit->data))
579 client_calc_layer(self);
580 stacking_below(CLIENT_AS_WINDOW(self),
581 CLIENT_AS_WINDOW(cit->data));
587 void client_move_onscreen(ObClient *self, gboolean rude)
589 gint x = self->area.x;
590 gint y = self->area.y;
591 if (client_find_onscreen(self, &x, &y,
592 self->frame->area.width,
593 self->frame->area.height, rude)) {
594 client_move(self, x, y);
598 gboolean client_find_onscreen(ObClient *self, gint *x, gint *y, gint w, gint h,
602 gint ox = *x, oy = *y;
604 frame_client_gravity(self->frame, x, y); /* get where the frame
607 /* XXX watch for xinerama dead areas */
609 a = screen_area(self->desktop);
610 if (client_normal(self)) {
611 if (!self->strut.right && *x >= a->x + a->width - 1)
612 *x = a->x + a->width - self->frame->area.width;
613 if (!self->strut.bottom && *y >= a->y + a->height - 1)
614 *y = a->y + a->height - self->frame->area.height;
615 if (!self->strut.left && *x + self->frame->area.width - 1 < a->x)
617 if (!self->strut.top && *y + self->frame->area.height - 1 < a->y)
622 /* this is my MOZILLA BITCHSLAP. oh ya it fucking feels good.
623 Java can suck it too. */
625 /* dont let windows map/move into the strut unless they
626 are bigger than the available area */
628 if (!self->strut.left && *x < a->x) *x = a->x;
629 if (!self->strut.right && *x + w > a->x + a->width)
630 *x = a->x + a->width - w;
632 if (h <= a->height) {
633 if (!self->strut.top && *y < a->y) *y = a->y;
634 if (!self->strut.bottom && *y + h > a->y + a->height)
635 *y = a->y + a->height - h;
639 frame_frame_gravity(self->frame, x, y); /* get where the client
642 return ox != *x || oy != *y;
645 static void client_toggle_border(ObClient *self, gboolean show)
647 /* adjust our idea of where the client is, based on its border. When the
648 border is removed, the client should now be considered to be in a
650 when re-adding the border to the client, the same operation needs to be
652 gint oldx = self->area.x, oldy = self->area.y;
653 gint x = oldx, y = oldy;
654 switch(self->gravity) {
656 case NorthWestGravity:
658 case SouthWestGravity:
660 case NorthEastGravity:
662 case SouthEastGravity:
663 if (show) x -= self->border_width * 2;
664 else x += self->border_width * 2;
671 if (show) x -= self->border_width;
672 else x += self->border_width;
675 switch(self->gravity) {
677 case NorthWestGravity:
679 case NorthEastGravity:
681 case SouthWestGravity:
683 case SouthEastGravity:
684 if (show) y -= self->border_width * 2;
685 else y += self->border_width * 2;
692 if (show) y -= self->border_width;
693 else y += self->border_width;
700 XSetWindowBorderWidth(ob_display, self->window, self->border_width);
702 /* move the client so it is back it the right spot _with_ its
704 if (x != oldx || y != oldy)
705 XMoveWindow(ob_display, self->window, x, y);
707 XSetWindowBorderWidth(ob_display, self->window, 0);
711 static void client_get_all(ObClient *self)
713 client_get_area(self);
714 client_update_transient_for(self);
715 client_update_wmhints(self);
716 client_get_startup_id(self);
717 client_get_desktop(self);
718 client_get_shaped(self);
720 client_get_mwm_hints(self);
721 client_get_type(self);/* this can change the mwmhints for special cases */
723 /* The transient hint is used to pick a type, but the type can also affect
724 transiency (dialogs are always made transients). This is Havoc's idea,
725 but it is needed to make some apps work right (eg tsclient). */
726 client_update_transient_for(self);
728 client_get_state(self);
731 /* a couple type-based defaults for new windows */
733 /* this makes sure that these windows appear on all desktops */
734 if (self->type == OB_CLIENT_TYPE_DESKTOP)
735 self->desktop = DESKTOP_ALL;
738 client_update_protocols(self);
740 client_get_gravity(self); /* get the attribute gravity */
741 client_update_normal_hints(self); /* this may override the attribute
744 /* got the type, the mwmhints, the protocols, and the normal hints
745 (min/max sizes), so we're ready to set up the decorations/functions */
746 client_setup_decor_and_functions(self);
748 client_update_title(self);
749 client_update_class(self);
750 client_update_sm_client_id(self);
751 client_update_strut(self);
752 client_update_icons(self);
755 static void client_get_startup_id(ObClient *self)
757 if (!(PROP_GETS(self->window, net_startup_id, utf8, &self->startup_id)))
759 PROP_GETS(self->group->leader,
760 net_startup_id, utf8, &self->startup_id);
763 static void client_get_area(ObClient *self)
765 XWindowAttributes wattrib;
768 ret = XGetWindowAttributes(ob_display, self->window, &wattrib);
769 g_assert(ret != BadWindow);
771 RECT_SET(self->area, wattrib.x, wattrib.y, wattrib.width, wattrib.height);
772 self->border_width = wattrib.border_width;
775 static void client_get_desktop(ObClient *self)
777 guint32 d = screen_num_desktops; /* an always-invalid value */
779 if (PROP_GET32(self->window, net_wm_desktop, cardinal, &d)) {
780 if (d >= screen_num_desktops && d != DESKTOP_ALL)
781 self->desktop = screen_num_desktops - 1;
785 gboolean trdesk = FALSE;
787 if (self->transient_for) {
788 if (self->transient_for != OB_TRAN_GROUP) {
789 self->desktop = self->transient_for->desktop;
794 for (it = self->group->members; it; it = g_slist_next(it))
795 if (it->data != self &&
796 !((ObClient*)it->data)->transient_for) {
797 self->desktop = ((ObClient*)it->data)->desktop;
804 /* try get from the startup-notification protocol */
805 if (sn_get_desktop(self->startup_id, &self->desktop)) {
806 if (self->desktop >= screen_num_desktops &&
807 self->desktop != DESKTOP_ALL)
808 self->desktop = screen_num_desktops - 1;
810 /* defaults to the current desktop */
811 self->desktop = screen_desktop;
814 if (self->desktop != d) {
815 /* set the desktop hint, to make sure that it always exists */
816 PROP_SET32(self->window, net_wm_desktop, cardinal, self->desktop);
820 static void client_get_state(ObClient *self)
825 if (PROP_GETA32(self->window, net_wm_state, atom, &state, &num)) {
827 for (i = 0; i < num; ++i) {
828 if (state[i] == prop_atoms.net_wm_state_modal)
830 else if (state[i] == prop_atoms.net_wm_state_shaded)
832 else if (state[i] == prop_atoms.net_wm_state_hidden)
834 else if (state[i] == prop_atoms.net_wm_state_skip_taskbar)
835 self->skip_taskbar = TRUE;
836 else if (state[i] == prop_atoms.net_wm_state_skip_pager)
837 self->skip_pager = TRUE;
838 else if (state[i] == prop_atoms.net_wm_state_fullscreen)
839 self->fullscreen = TRUE;
840 else if (state[i] == prop_atoms.net_wm_state_maximized_vert)
841 self->max_vert = TRUE;
842 else if (state[i] == prop_atoms.net_wm_state_maximized_horz)
843 self->max_horz = TRUE;
844 else if (state[i] == prop_atoms.net_wm_state_above)
846 else if (state[i] == prop_atoms.net_wm_state_below)
848 else if (state[i] == prop_atoms.ob_wm_state_undecorated)
849 self->undecorated = TRUE;
855 if (!(self->above || self->below)) {
857 /* apply stuff from the group */
861 for (it = self->group->members; it; it = g_slist_next(it)) {
862 ObClient *c = it->data;
863 if (c != self && !client_search_transient(self, c) &&
864 client_normal(self) && client_normal(c))
867 (c->above ? 1 : (c->below ? -1 : 0)));
881 g_assert_not_reached();
888 static void client_get_shaped(ObClient *self)
890 self->shaped = FALSE;
892 if (extensions_shape) {
897 XShapeSelectInput(ob_display, self->window, ShapeNotifyMask);
899 XShapeQueryExtents(ob_display, self->window, &s, &foo,
900 &foo, &ufoo, &ufoo, &foo, &foo, &foo, &ufoo,
902 self->shaped = (s != 0);
907 void client_update_transient_for(ObClient *self)
910 ObClient *target = NULL;
912 if (XGetTransientForHint(ob_display, self->window, &t)) {
913 self->transient = TRUE;
914 if (t != self->window) { /* cant be transient to itself! */
915 target = g_hash_table_lookup(window_map, &t);
916 /* if this happens then we need to check for it*/
917 g_assert(target != self);
918 if (target && !WINDOW_IS_CLIENT(target)) {
919 /* this can happen when a dialog is a child of
920 a dockapp, for example */
924 if (!target && self->group) {
925 /* not transient to a client, see if it is transient for a
927 if (t == self->group->leader ||
929 t == RootWindow(ob_display, ob_screen))
931 /* window is a transient for its group! */
932 target = OB_TRAN_GROUP;
936 } else if (self->type == OB_CLIENT_TYPE_DIALOG && self->group) {
937 self->transient = TRUE;
938 target = OB_TRAN_GROUP;
940 self->transient = FALSE;
942 /* if anything has changed... */
943 if (target != self->transient_for) {
944 if (self->transient_for == OB_TRAN_GROUP) { /* transient of group */
947 /* remove from old parents */
948 for (it = self->group->members; it; it = g_slist_next(it)) {
949 ObClient *c = it->data;
950 if (c != self && !c->transient_for)
951 c->transients = g_slist_remove(c->transients, self);
953 } else if (self->transient_for != NULL) { /* transient of window */
954 /* remove from old parent */
955 self->transient_for->transients =
956 g_slist_remove(self->transient_for->transients, self);
958 self->transient_for = target;
959 if (self->transient_for == OB_TRAN_GROUP) { /* transient of group */
962 /* add to new parents */
963 for (it = self->group->members; it; it = g_slist_next(it)) {
964 ObClient *c = it->data;
965 if (c != self && !c->transient_for)
966 c->transients = g_slist_append(c->transients, self);
969 /* remove all transients which are in the group, that causes
970 circlular pointer hell of doom */
971 for (it = self->group->members; it; it = g_slist_next(it)) {
973 for (sit = self->transients; sit; sit = next) {
974 next = g_slist_next(sit);
975 if (sit->data == it->data)
977 g_slist_delete_link(self->transients, sit);
980 } else if (self->transient_for != NULL) { /* transient of window */
981 /* add to new parent */
982 self->transient_for->transients =
983 g_slist_append(self->transient_for->transients, self);
988 static void client_get_mwm_hints(ObClient *self)
993 self->mwmhints.flags = 0; /* default to none */
995 if (PROP_GETA32(self->window, motif_wm_hints, motif_wm_hints,
997 if (num >= OB_MWM_ELEMENTS) {
998 self->mwmhints.flags = hints[0];
999 self->mwmhints.functions = hints[1];
1000 self->mwmhints.decorations = hints[2];
1006 void client_get_type(ObClient *self)
1013 if (PROP_GETA32(self->window, net_wm_window_type, atom, &val, &num)) {
1014 /* use the first value that we know about in the array */
1015 for (i = 0; i < num; ++i) {
1016 if (val[i] == prop_atoms.net_wm_window_type_desktop)
1017 self->type = OB_CLIENT_TYPE_DESKTOP;
1018 else if (val[i] == prop_atoms.net_wm_window_type_dock)
1019 self->type = OB_CLIENT_TYPE_DOCK;
1020 else if (val[i] == prop_atoms.net_wm_window_type_toolbar)
1021 self->type = OB_CLIENT_TYPE_TOOLBAR;
1022 else if (val[i] == prop_atoms.net_wm_window_type_menu)
1023 self->type = OB_CLIENT_TYPE_MENU;
1024 else if (val[i] == prop_atoms.net_wm_window_type_utility)
1025 self->type = OB_CLIENT_TYPE_UTILITY;
1026 else if (val[i] == prop_atoms.net_wm_window_type_splash)
1027 self->type = OB_CLIENT_TYPE_SPLASH;
1028 else if (val[i] == prop_atoms.net_wm_window_type_dialog)
1029 self->type = OB_CLIENT_TYPE_DIALOG;
1030 else if (val[i] == prop_atoms.net_wm_window_type_normal)
1031 self->type = OB_CLIENT_TYPE_NORMAL;
1032 else if (val[i] == prop_atoms.kde_net_wm_window_type_override) {
1033 /* prevent this window from getting any decor or
1035 self->mwmhints.flags &= (OB_MWM_FLAG_FUNCTIONS |
1036 OB_MWM_FLAG_DECORATIONS);
1037 self->mwmhints.decorations = 0;
1038 self->mwmhints.functions = 0;
1040 if (self->type != (ObClientType) -1)
1041 break; /* grab the first legit type */
1046 if (self->type == (ObClientType) -1) {
1047 /*the window type hint was not set, which means we either classify
1048 ourself as a normal window or a dialog, depending on if we are a
1050 if (self->transient)
1051 self->type = OB_CLIENT_TYPE_DIALOG;
1053 self->type = OB_CLIENT_TYPE_NORMAL;
1057 void client_update_protocols(ObClient *self)
1060 guint num_return, i;
1062 self->focus_notify = FALSE;
1063 self->delete_window = FALSE;
1065 if (PROP_GETA32(self->window, wm_protocols, atom, &proto, &num_return)) {
1066 for (i = 0; i < num_return; ++i) {
1067 if (proto[i] == prop_atoms.wm_delete_window) {
1068 /* this means we can request the window to close */
1069 self->delete_window = TRUE;
1070 } else if (proto[i] == prop_atoms.wm_take_focus)
1071 /* if this protocol is requested, then the window will be
1072 notified whenever we want it to receive focus */
1073 self->focus_notify = TRUE;
1079 static void client_get_gravity(ObClient *self)
1081 XWindowAttributes wattrib;
1084 ret = XGetWindowAttributes(ob_display, self->window, &wattrib);
1085 g_assert(ret != BadWindow);
1086 self->gravity = wattrib.win_gravity;
1089 void client_update_normal_hints(ObClient *self)
1093 gint oldgravity = self->gravity;
1096 self->min_ratio = 0.0f;
1097 self->max_ratio = 0.0f;
1098 SIZE_SET(self->size_inc, 1, 1);
1099 SIZE_SET(self->base_size, 0, 0);
1100 SIZE_SET(self->min_size, 0, 0);
1101 SIZE_SET(self->max_size, G_MAXINT, G_MAXINT);
1103 /* get the hints from the window */
1104 if (XGetWMNormalHints(ob_display, self->window, &size, &ret)) {
1105 /* normal windows can't request placement! har har
1106 if (!client_normal(self))
1108 self->positioned = !!(size.flags & (PPosition|USPosition));
1110 if (size.flags & PWinGravity) {
1111 self->gravity = size.win_gravity;
1113 /* if the client has a frame, i.e. has already been mapped and
1114 is changing its gravity */
1115 if (self->frame && self->gravity != oldgravity) {
1116 /* move our idea of the client's position based on its new
1118 self->area.x = self->frame->area.x;
1119 self->area.y = self->frame->area.y;
1120 frame_frame_gravity(self->frame, &self->area.x, &self->area.y);
1124 if (size.flags & PAspect) {
1125 if (size.min_aspect.y)
1127 (gfloat) size.min_aspect.x / size.min_aspect.y;
1128 if (size.max_aspect.y)
1130 (gfloat) size.max_aspect.x / size.max_aspect.y;
1133 if (size.flags & PMinSize)
1134 SIZE_SET(self->min_size, size.min_width, size.min_height);
1136 if (size.flags & PMaxSize)
1137 SIZE_SET(self->max_size, size.max_width, size.max_height);
1139 if (size.flags & PBaseSize)
1140 SIZE_SET(self->base_size, size.base_width, size.base_height);
1142 if (size.flags & PResizeInc)
1143 SIZE_SET(self->size_inc, size.width_inc, size.height_inc);
1147 void client_setup_decor_and_functions(ObClient *self)
1149 /* start with everything (cept fullscreen) */
1151 (OB_FRAME_DECOR_TITLEBAR |
1152 (ob_rr_theme->show_handle ? OB_FRAME_DECOR_HANDLE : 0) |
1153 OB_FRAME_DECOR_GRIPS |
1154 OB_FRAME_DECOR_BORDER |
1155 OB_FRAME_DECOR_ICON |
1156 OB_FRAME_DECOR_ALLDESKTOPS |
1157 OB_FRAME_DECOR_ICONIFY |
1158 OB_FRAME_DECOR_MAXIMIZE |
1159 OB_FRAME_DECOR_SHADE |
1160 OB_FRAME_DECOR_CLOSE);
1162 (OB_CLIENT_FUNC_RESIZE |
1163 OB_CLIENT_FUNC_MOVE |
1164 OB_CLIENT_FUNC_ICONIFY |
1165 OB_CLIENT_FUNC_MAXIMIZE |
1166 OB_CLIENT_FUNC_SHADE |
1167 OB_CLIENT_FUNC_CLOSE);
1169 if (!(self->min_size.width < self->max_size.width ||
1170 self->min_size.height < self->max_size.height))
1171 self->functions &= ~OB_CLIENT_FUNC_RESIZE;
1173 switch (self->type) {
1174 case OB_CLIENT_TYPE_NORMAL:
1175 /* normal windows retain all of the possible decorations and
1176 functionality, and are the only windows that you can fullscreen */
1177 self->functions |= OB_CLIENT_FUNC_FULLSCREEN;
1180 case OB_CLIENT_TYPE_DIALOG:
1181 case OB_CLIENT_TYPE_UTILITY:
1182 /* these windows cannot be maximized */
1183 self->functions &= ~OB_CLIENT_FUNC_MAXIMIZE;
1186 case OB_CLIENT_TYPE_MENU:
1187 case OB_CLIENT_TYPE_TOOLBAR:
1188 /* these windows get less functionality */
1189 self->functions &= ~(OB_CLIENT_FUNC_ICONIFY | OB_CLIENT_FUNC_RESIZE);
1192 case OB_CLIENT_TYPE_DESKTOP:
1193 case OB_CLIENT_TYPE_DOCK:
1194 case OB_CLIENT_TYPE_SPLASH:
1195 /* none of these windows are manipulated by the window manager */
1196 self->decorations = 0;
1197 self->functions = 0;
1201 /* Mwm Hints are applied subtractively to what has already been chosen for
1202 decor and functionality */
1203 if (self->mwmhints.flags & OB_MWM_FLAG_DECORATIONS) {
1204 if (! (self->mwmhints.decorations & OB_MWM_DECOR_ALL)) {
1205 if (! ((self->mwmhints.decorations & OB_MWM_DECOR_HANDLE) ||
1206 (self->mwmhints.decorations & OB_MWM_DECOR_TITLE)))
1207 /* if the mwm hints request no handle or title, then all
1208 decorations are disabled */
1209 self->decorations = 0;
1213 if (self->mwmhints.flags & OB_MWM_FLAG_FUNCTIONS) {
1214 if (! (self->mwmhints.functions & OB_MWM_FUNC_ALL)) {
1215 if (! (self->mwmhints.functions & OB_MWM_FUNC_RESIZE))
1216 self->functions &= ~OB_CLIENT_FUNC_RESIZE;
1217 if (! (self->mwmhints.functions & OB_MWM_FUNC_MOVE))
1218 self->functions &= ~OB_CLIENT_FUNC_MOVE;
1219 /* dont let mwm hints kill any buttons
1220 if (! (self->mwmhints.functions & OB_MWM_FUNC_ICONIFY))
1221 self->functions &= ~OB_CLIENT_FUNC_ICONIFY;
1222 if (! (self->mwmhints.functions & OB_MWM_FUNC_MAXIMIZE))
1223 self->functions &= ~OB_CLIENT_FUNC_MAXIMIZE;
1225 /* dont let mwm hints kill the close button
1226 if (! (self->mwmhints.functions & MwmFunc_Close))
1227 self->functions &= ~OB_CLIENT_FUNC_CLOSE; */
1231 if (!(self->functions & OB_CLIENT_FUNC_SHADE))
1232 self->decorations &= ~OB_FRAME_DECOR_SHADE;
1233 if (!(self->functions & OB_CLIENT_FUNC_ICONIFY))
1234 self->decorations &= ~OB_FRAME_DECOR_ICONIFY;
1235 if (!(self->functions & OB_CLIENT_FUNC_RESIZE))
1236 self->decorations &= ~OB_FRAME_DECOR_GRIPS;
1238 /* can't maximize without moving/resizing */
1239 if (!((self->functions & OB_CLIENT_FUNC_MAXIMIZE) &&
1240 (self->functions & OB_CLIENT_FUNC_MOVE) &&
1241 (self->functions & OB_CLIENT_FUNC_RESIZE))) {
1242 self->functions &= ~OB_CLIENT_FUNC_MAXIMIZE;
1243 self->decorations &= ~OB_FRAME_DECOR_MAXIMIZE;
1246 /* kill the handle on fully maxed windows */
1247 if (self->max_vert && self->max_horz)
1248 self->decorations &= ~OB_FRAME_DECOR_HANDLE;
1250 /* finally, the user can have requested no decorations, which overrides
1251 everything (but doesnt give it a border if it doesnt have one) */
1252 if (self->undecorated)
1253 self->decorations &= OB_FRAME_DECOR_BORDER;
1255 /* if we don't have a titlebar, then we cannot shade! */
1256 if (!(self->decorations & OB_FRAME_DECOR_TITLEBAR))
1257 self->functions &= ~OB_CLIENT_FUNC_SHADE;
1259 /* now we need to check against rules for the client's current state */
1260 if (self->fullscreen) {
1261 self->functions &= (OB_CLIENT_FUNC_CLOSE |
1262 OB_CLIENT_FUNC_FULLSCREEN |
1263 OB_CLIENT_FUNC_ICONIFY);
1264 self->decorations = 0;
1267 client_change_allowed_actions(self);
1270 /* adjust the client's decorations, etc. */
1271 client_reconfigure(self);
1275 static void client_change_allowed_actions(ObClient *self)
1280 /* desktop windows are kept on all desktops */
1281 if (self->type != OB_CLIENT_TYPE_DESKTOP)
1282 actions[num++] = prop_atoms.net_wm_action_change_desktop;
1284 if (self->functions & OB_CLIENT_FUNC_SHADE)
1285 actions[num++] = prop_atoms.net_wm_action_shade;
1286 if (self->functions & OB_CLIENT_FUNC_CLOSE)
1287 actions[num++] = prop_atoms.net_wm_action_close;
1288 if (self->functions & OB_CLIENT_FUNC_MOVE)
1289 actions[num++] = prop_atoms.net_wm_action_move;
1290 if (self->functions & OB_CLIENT_FUNC_ICONIFY)
1291 actions[num++] = prop_atoms.net_wm_action_minimize;
1292 if (self->functions & OB_CLIENT_FUNC_RESIZE)
1293 actions[num++] = prop_atoms.net_wm_action_resize;
1294 if (self->functions & OB_CLIENT_FUNC_FULLSCREEN)
1295 actions[num++] = prop_atoms.net_wm_action_fullscreen;
1296 if (self->functions & OB_CLIENT_FUNC_MAXIMIZE) {
1297 actions[num++] = prop_atoms.net_wm_action_maximize_horz;
1298 actions[num++] = prop_atoms.net_wm_action_maximize_vert;
1301 PROP_SETA32(self->window, net_wm_allowed_actions, atom, actions, num);
1303 /* make sure the window isn't breaking any rules now */
1305 if (!(self->functions & OB_CLIENT_FUNC_SHADE) && self->shaded) {
1306 if (self->frame) client_shade(self, FALSE);
1307 else self->shaded = FALSE;
1309 if (!(self->functions & OB_CLIENT_FUNC_ICONIFY) && self->iconic) {
1310 if (self->frame) client_iconify(self, FALSE, TRUE);
1311 else self->iconic = FALSE;
1313 if (!(self->functions & OB_CLIENT_FUNC_FULLSCREEN) && self->fullscreen) {
1314 if (self->frame) client_fullscreen(self, FALSE, TRUE);
1315 else self->fullscreen = FALSE;
1317 if (!(self->functions & OB_CLIENT_FUNC_MAXIMIZE) && (self->max_horz ||
1319 if (self->frame) client_maximize(self, FALSE, 0, TRUE);
1320 else self->max_vert = self->max_horz = FALSE;
1324 void client_reconfigure(ObClient *self)
1326 /* by making this pass FALSE for user, we avoid the emacs event storm where
1327 every configurenotify causes an update in its normal hints, i think this
1328 is generally what we want anyways... */
1329 client_configure(self, OB_CORNER_TOPLEFT, self->area.x, self->area.y,
1330 self->area.width, self->area.height, FALSE, TRUE);
1333 void client_update_wmhints(ObClient *self)
1336 gboolean ur = FALSE;
1339 /* assume a window takes input if it doesnt specify */
1340 self->can_focus = TRUE;
1342 if ((hints = XGetWMHints(ob_display, self->window)) != NULL) {
1343 if (hints->flags & InputHint)
1344 self->can_focus = hints->input;
1346 /* only do this when first managing the window *AND* when we aren't
1348 if (ob_state() != OB_STATE_STARTING && self->frame == NULL)
1349 if (hints->flags & StateHint)
1350 self->iconic = hints->initial_state == IconicState;
1352 if (hints->flags & XUrgencyHint)
1355 if (!(hints->flags & WindowGroupHint))
1356 hints->window_group = None;
1358 /* did the group state change? */
1359 if (hints->window_group !=
1360 (self->group ? self->group->leader : None)) {
1361 /* remove from the old group if there was one */
1362 if (self->group != NULL) {
1363 /* remove transients of the group */
1364 for (it = self->group->members; it; it = g_slist_next(it))
1365 self->transients = g_slist_remove(self->transients,
1368 /* remove myself from parents in the group */
1369 if (self->transient_for == OB_TRAN_GROUP) {
1370 for (it = self->group->members; it;
1371 it = g_slist_next(it))
1373 ObClient *c = it->data;
1375 if (c != self && !c->transient_for)
1376 c->transients = g_slist_remove(c->transients,
1381 group_remove(self->group, self);
1384 if (hints->window_group != None) {
1385 self->group = group_add(hints->window_group, self);
1387 /* i can only have transients from the group if i am not
1389 if (!self->transient_for) {
1390 /* add other transients of the group that are already
1392 for (it = self->group->members; it;
1393 it = g_slist_next(it))
1395 ObClient *c = it->data;
1396 if (c != self && c->transient_for == OB_TRAN_GROUP)
1398 g_slist_append(self->transients, c);
1403 /* because the self->transient flag wont change from this call,
1404 we don't need to update the window's type and such, only its
1405 transient_for, and the transients lists of other windows in
1406 the group may be affected */
1407 client_update_transient_for(self);
1410 /* the WM_HINTS can contain an icon */
1411 client_update_icons(self);
1416 if (ur != self->urgent) {
1418 /* fire the urgent callback if we're mapped, otherwise, wait until
1419 after we're mapped */
1421 client_urgent_notify(self);
1425 void client_update_title(ObClient *self)
1431 gboolean read_title;
1434 old_title = self->title;
1437 if (!PROP_GETS(self->window, net_wm_name, utf8, &data))
1438 /* try old x stuff */
1439 if (!PROP_GETS(self->window, wm_name, locale, &data))
1440 data = g_strdup("Unnamed Window");
1442 /* did the title change? then reset the title_count */
1443 if (old_title && 0 != strncmp(old_title, data, strlen(data)))
1444 self->title_count = 1;
1446 /* look for duplicates and append a number */
1448 for (it = client_list; it; it = g_list_next(it))
1449 if (it->data != self) {
1450 ObClient *c = it->data;
1451 if (0 == strncmp(c->title, data, strlen(data)))
1452 nums |= 1 << c->title_count;
1454 /* find first free number */
1455 for (i = 1; i <= 32; ++i)
1456 if (!(nums & (1 << i))) {
1457 if (self->title_count == 1 || i == 1)
1458 self->title_count = i;
1461 /* dont display the number for the first window */
1462 if (self->title_count > 1) {
1464 ndata = g_strdup_printf("%s - [%u]", data, self->title_count);
1469 PROP_SETS(self->window, net_wm_visible_name, data);
1474 frame_adjust_title(self->frame);
1478 /* update the icon title */
1480 g_free(self->icon_title);
1484 if (!PROP_GETS(self->window, net_wm_icon_name, utf8, &data))
1485 /* try old x stuff */
1486 if (!PROP_GETS(self->window, wm_icon_name, locale, &data)) {
1487 data = g_strdup(self->title);
1491 /* append the title count, dont display the number for the first window */
1492 if (read_title && self->title_count > 1) {
1493 gchar *vdata, *ndata;
1494 ndata = g_strdup_printf(" - [%u]", self->title_count);
1495 vdata = g_strconcat(data, ndata, NULL);
1501 PROP_SETS(self->window, net_wm_visible_icon_name, data);
1503 self->icon_title = data;
1506 void client_update_class(ObClient *self)
1511 if (self->name) g_free(self->name);
1512 if (self->class) g_free(self->class);
1513 if (self->role) g_free(self->role);
1515 self->name = self->class = self->role = NULL;
1517 if (PROP_GETSS(self->window, wm_class, locale, &data)) {
1519 self->name = g_strdup(data[0]);
1521 self->class = g_strdup(data[1]);
1526 if (PROP_GETS(self->window, wm_window_role, locale, &s))
1529 if (self->name == NULL) self->name = g_strdup("");
1530 if (self->class == NULL) self->class = g_strdup("");
1531 if (self->role == NULL) self->role = g_strdup("");
1534 void client_update_strut(ObClient *self)
1538 gboolean got = FALSE;
1541 if (PROP_GETA32(self->window, net_wm_strut_partial, cardinal,
1545 STRUT_PARTIAL_SET(strut,
1546 data[0], data[2], data[1], data[3],
1547 data[4], data[5], data[8], data[9],
1548 data[6], data[7], data[10], data[11]);
1554 PROP_GETA32(self->window, net_wm_strut, cardinal, &data, &num)) {
1560 /* use the screen's width/height */
1561 a = screen_physical_area();
1563 STRUT_PARTIAL_SET(strut,
1564 data[0], data[2], data[1], data[3],
1565 a->y, a->y + a->height - 1,
1566 a->x, a->x + a->width - 1,
1567 a->y, a->y + a->height - 1,
1568 a->x, a->x + a->width - 1);
1574 STRUT_PARTIAL_SET(strut, 0, 0, 0, 0,
1575 0, 0, 0, 0, 0, 0, 0, 0);
1577 if (!STRUT_EQUAL(strut, self->strut)) {
1578 self->strut = strut;
1580 /* updating here is pointless while we're being mapped cuz we're not in
1581 the client list yet */
1583 screen_update_areas();
1587 void client_update_icons(ObClient *self)
1593 for (i = 0; i < self->nicons; ++i)
1594 g_free(self->icons[i].data);
1595 if (self->nicons > 0)
1596 g_free(self->icons);
1599 if (PROP_GETA32(self->window, net_wm_icon, cardinal, &data, &num)) {
1600 /* figure out how many valid icons are in here */
1602 while (num - i > 2) {
1606 if (i > num || w*h == 0) break;
1610 self->icons = g_new(ObClientIcon, self->nicons);
1612 /* store the icons */
1614 for (j = 0; j < self->nicons; ++j) {
1617 w = self->icons[j].width = data[i++];
1618 h = self->icons[j].height = data[i++];
1620 if (w*h == 0) continue;
1622 self->icons[j].data = g_new(RrPixel32, w * h);
1623 for (x = 0, y = 0, t = 0; t < w * h; ++t, ++x, ++i) {
1628 self->icons[j].data[t] =
1629 (((data[i] >> 24) & 0xff) << RrDefaultAlphaOffset) +
1630 (((data[i] >> 16) & 0xff) << RrDefaultRedOffset) +
1631 (((data[i] >> 8) & 0xff) << RrDefaultGreenOffset) +
1632 (((data[i] >> 0) & 0xff) << RrDefaultBlueOffset);
1638 } else if (PROP_GETA32(self->window, kwm_win_icon,
1639 kwm_win_icon, &data, &num)) {
1642 self->icons = g_new(ObClientIcon, self->nicons);
1643 xerror_set_ignore(TRUE);
1644 if (!RrPixmapToRGBA(ob_rr_inst,
1646 &self->icons[self->nicons-1].width,
1647 &self->icons[self->nicons-1].height,
1648 &self->icons[self->nicons-1].data)) {
1649 g_free(&self->icons[self->nicons-1]);
1652 xerror_set_ignore(FALSE);
1658 if ((hints = XGetWMHints(ob_display, self->window))) {
1659 if (hints->flags & IconPixmapHint) {
1661 self->icons = g_new(ObClientIcon, self->nicons);
1662 xerror_set_ignore(TRUE);
1663 if (!RrPixmapToRGBA(ob_rr_inst,
1665 (hints->flags & IconMaskHint ?
1666 hints->icon_mask : None),
1667 &self->icons[self->nicons-1].width,
1668 &self->icons[self->nicons-1].height,
1669 &self->icons[self->nicons-1].data)){
1670 g_free(&self->icons[self->nicons-1]);
1673 xerror_set_ignore(FALSE);
1680 frame_adjust_icon(self->frame);
1683 static void client_change_state(ObClient *self)
1686 guint32 netstate[11];
1689 state[0] = self->wmstate;
1691 PROP_SETA32(self->window, wm_state, wm_state, state, 2);
1695 netstate[num++] = prop_atoms.net_wm_state_modal;
1697 netstate[num++] = prop_atoms.net_wm_state_shaded;
1699 netstate[num++] = prop_atoms.net_wm_state_hidden;
1700 if (self->skip_taskbar)
1701 netstate[num++] = prop_atoms.net_wm_state_skip_taskbar;
1702 if (self->skip_pager)
1703 netstate[num++] = prop_atoms.net_wm_state_skip_pager;
1704 if (self->fullscreen)
1705 netstate[num++] = prop_atoms.net_wm_state_fullscreen;
1707 netstate[num++] = prop_atoms.net_wm_state_maximized_vert;
1709 netstate[num++] = prop_atoms.net_wm_state_maximized_horz;
1711 netstate[num++] = prop_atoms.net_wm_state_above;
1713 netstate[num++] = prop_atoms.net_wm_state_below;
1714 if (self->undecorated)
1715 netstate[num++] = prop_atoms.ob_wm_state_undecorated;
1716 PROP_SETA32(self->window, net_wm_state, atom, netstate, num);
1718 client_calc_layer(self);
1721 frame_adjust_state(self->frame);
1724 ObClient *client_search_focus_tree(ObClient *self)
1729 for (it = self->transients; it; it = g_slist_next(it)) {
1730 if (client_focused(it->data)) return it->data;
1731 if ((ret = client_search_focus_tree(it->data))) return ret;
1736 ObClient *client_search_focus_tree_full(ObClient *self)
1738 if (self->transient_for) {
1739 if (self->transient_for != OB_TRAN_GROUP) {
1740 return client_search_focus_tree_full(self->transient_for);
1743 gboolean recursed = FALSE;
1745 for (it = self->group->members; it; it = g_slist_next(it))
1746 if (!((ObClient*)it->data)->transient_for) {
1748 if ((c = client_search_focus_tree_full(it->data)))
1757 /* this function checks the whole tree, the client_search_focus_tree~
1758 does not, so we need to check this window */
1759 if (client_focused(self))
1761 return client_search_focus_tree(self);
1764 static ObStackingLayer calc_layer(ObClient *self)
1768 if (self->fullscreen &&
1769 (client_focused(self) || client_search_focus_tree(self)))
1770 l = OB_STACKING_LAYER_FULLSCREEN;
1771 else if (self->type == OB_CLIENT_TYPE_DESKTOP)
1772 l = OB_STACKING_LAYER_DESKTOP;
1773 else if (self->type == OB_CLIENT_TYPE_DOCK) {
1774 if (self->above) l = OB_STACKING_LAYER_DOCK_ABOVE;
1775 else if (self->below) l = OB_STACKING_LAYER_DOCK_BELOW;
1776 else l = OB_STACKING_LAYER_DOCK_NORMAL;
1778 else if (self->above) l = OB_STACKING_LAYER_ABOVE;
1779 else if (self->below) l = OB_STACKING_LAYER_BELOW;
1780 else l = OB_STACKING_LAYER_NORMAL;
1785 static void client_calc_layer_recursive(ObClient *self, ObClient *orig,
1786 ObStackingLayer l, gboolean raised)
1788 ObStackingLayer old, own;
1792 own = calc_layer(self);
1793 self->layer = l > own ? l : own;
1795 for (it = self->transients; it; it = g_slist_next(it))
1796 client_calc_layer_recursive(it->data, orig,
1797 l, raised ? raised : l != old);
1799 if (!raised && l != old)
1800 if (orig->frame) { /* only restack if the original window is managed */
1801 stacking_remove(CLIENT_AS_WINDOW(self));
1802 stacking_add(CLIENT_AS_WINDOW(self));
1806 void client_calc_layer(ObClient *self)
1813 /* transients take on the layer of their parents */
1814 self = client_search_top_transient(self);
1816 l = calc_layer(self);
1818 client_calc_layer_recursive(self, orig, l, FALSE);
1821 gboolean client_should_show(ObClient *self)
1825 if (client_normal(self) && screen_showing_desktop)
1828 if (self->transient_for) {
1829 if (self->transient_for != OB_TRAN_GROUP)
1830 return client_should_show(self->transient_for);
1834 for (it = self->group->members; it; it = g_slist_next(it)) {
1835 ObClient *c = it->data;
1836 if (c != self && !c->transient_for) {
1837 if (client_should_show(c))
1844 if (self->desktop == screen_desktop || self->desktop == DESKTOP_ALL)
1850 static void client_showhide(ObClient *self)
1853 if (client_should_show(self))
1854 frame_show(self->frame);
1856 frame_hide(self->frame);
1859 gboolean client_normal(ObClient *self) {
1860 return ! (self->type == OB_CLIENT_TYPE_DESKTOP ||
1861 self->type == OB_CLIENT_TYPE_DOCK ||
1862 self->type == OB_CLIENT_TYPE_SPLASH);
1865 static void client_apply_startup_state(ObClient *self)
1867 /* these are in a carefully crafted order.. */
1870 self->iconic = FALSE;
1871 client_iconify(self, TRUE, FALSE);
1873 if (self->fullscreen) {
1874 self->fullscreen = FALSE;
1875 client_fullscreen(self, TRUE, FALSE);
1877 if (self->undecorated) {
1878 self->undecorated = FALSE;
1879 client_set_undecorated(self, TRUE);
1882 self->shaded = FALSE;
1883 client_shade(self, TRUE);
1886 client_urgent_notify(self);
1888 if (self->max_vert && self->max_horz) {
1889 self->max_vert = self->max_horz = FALSE;
1890 client_maximize(self, TRUE, 0, FALSE);
1891 } else if (self->max_vert) {
1892 self->max_vert = FALSE;
1893 client_maximize(self, TRUE, 2, FALSE);
1894 } else if (self->max_horz) {
1895 self->max_horz = FALSE;
1896 client_maximize(self, TRUE, 1, FALSE);
1899 /* nothing to do for the other states:
1908 void client_configure_full(ObClient *self, ObCorner anchor,
1909 gint x, gint y, gint w, gint h,
1910 gboolean user, gboolean final,
1911 gboolean force_reply)
1914 gboolean send_resize_client;
1915 gboolean moved = FALSE, resized = FALSE;
1916 guint fdecor = self->frame->decorations;
1917 gboolean fhorz = self->frame->max_horz;
1919 /* make the frame recalculate its dimentions n shit without changing
1920 anything visible for real, this way the constraints below can work with
1921 the updated frame dimensions. */
1922 frame_adjust_area(self->frame, TRUE, TRUE, TRUE);
1924 /* gets the frame's position */
1925 frame_client_gravity(self->frame, &x, &y);
1927 /* these positions are frame positions, not client positions */
1929 /* set the size and position if fullscreen */
1930 if (self->fullscreen) {
1933 XF86VidModeModeLine mode;
1938 i = client_monitor(self);
1939 a = screen_physical_area_monitor(i);
1942 if (i == 0 && /* primary head */
1943 extensions_vidmode &&
1944 XF86VidModeGetViewPort(ob_display, ob_screen, &x, &y) &&
1945 /* get the mode last so the mode.privsize isnt freed incorrectly */
1946 XF86VidModeGetModeLine(ob_display, ob_screen, &dot, &mode)) {
1951 if (mode.privsize) XFree(mode.private);
1961 user = FALSE; /* ignore that increment etc shit when in fullscreen */
1965 a = screen_area_monitor(self->desktop, client_monitor(self));
1967 /* set the size and position if maximized */
1968 if (self->max_horz) {
1970 w = a->width - self->frame->size.left - self->frame->size.right;
1972 if (self->max_vert) {
1974 h = a->height - self->frame->size.top - self->frame->size.bottom;
1978 /* gets the client's position */
1979 frame_frame_gravity(self->frame, &x, &y);
1981 /* these override the above states! if you cant move you can't move! */
1983 if (!(self->functions & OB_CLIENT_FUNC_MOVE)) {
1987 if (!(self->functions & OB_CLIENT_FUNC_RESIZE)) {
1988 w = self->area.width;
1989 h = self->area.height;
1993 if (!(w == self->area.width && h == self->area.height)) {
1994 gint basew, baseh, minw, minh;
1996 /* base size is substituted with min size if not specified */
1997 if (self->base_size.width || self->base_size.height) {
1998 basew = self->base_size.width;
1999 baseh = self->base_size.height;
2001 basew = self->min_size.width;
2002 baseh = self->min_size.height;
2004 /* min size is substituted with base size if not specified */
2005 if (self->min_size.width || self->min_size.height) {
2006 minw = self->min_size.width;
2007 minh = self->min_size.height;
2009 minw = self->base_size.width;
2010 minh = self->base_size.height;
2013 /* if this is a user-requested resize, then check against min/max
2016 /* smaller than min size or bigger than max size? */
2017 if (w > self->max_size.width) w = self->max_size.width;
2018 if (w < minw) w = minw;
2019 if (h > self->max_size.height) h = self->max_size.height;
2020 if (h < minh) h = minh;
2025 /* keep to the increments */
2026 w /= self->size_inc.width;
2027 h /= self->size_inc.height;
2029 /* you cannot resize to nothing */
2030 if (basew + w < 1) w = 1 - basew;
2031 if (baseh + h < 1) h = 1 - baseh;
2033 /* store the logical size */
2034 SIZE_SET(self->logical_size,
2035 self->size_inc.width > 1 ? w : w + basew,
2036 self->size_inc.height > 1 ? h : h + baseh);
2038 w *= self->size_inc.width;
2039 h *= self->size_inc.height;
2044 /* adjust the height to match the width for the aspect ratios.
2045 for this, min size is not substituted for base size ever. */
2046 w -= self->base_size.width;
2047 h -= self->base_size.height;
2049 if (self->min_ratio)
2050 if (h * self->min_ratio > w) {
2051 h = (gint)(w / self->min_ratio);
2053 /* you cannot resize to nothing */
2056 w = (gint)(h * self->min_ratio);
2059 if (self->max_ratio)
2060 if (h * self->max_ratio < w) {
2061 h = (gint)(w / self->max_ratio);
2063 /* you cannot resize to nothing */
2066 w = (gint)(h * self->min_ratio);
2070 w += self->base_size.width;
2071 h += self->base_size.height;
2078 case OB_CORNER_TOPLEFT:
2080 case OB_CORNER_TOPRIGHT:
2081 x -= w - self->area.width;
2083 case OB_CORNER_BOTTOMLEFT:
2084 y -= h - self->area.height;
2086 case OB_CORNER_BOTTOMRIGHT:
2087 x -= w - self->area.width;
2088 y -= h - self->area.height;
2092 moved = x != self->area.x || y != self->area.y;
2093 resized = w != self->area.width || h != self->area.height;
2095 oldw = self->area.width;
2096 oldh = self->area.height;
2097 RECT_SET(self->area, x, y, w, h);
2099 /* for app-requested resizes, always resize if 'resized' is true.
2100 for user-requested ones, only resize if final is true, or when
2101 resizing in redraw mode */
2102 send_resize_client = ((!user && resized) ||
2104 (resized && config_redraw_resize))));
2106 /* if the client is enlarging, the resize the client before the frame */
2107 if (send_resize_client && user && (w > oldw || h > oldh))
2108 XResizeWindow(ob_display, self->window, MAX(w, oldw), MAX(h, oldh));
2110 /* move/resize the frame to match the request */
2112 if (self->decorations != fdecor || self->max_horz != fhorz)
2113 moved = resized = TRUE;
2115 if (moved || resized)
2116 frame_adjust_area(self->frame, moved, resized, FALSE);
2118 if (!resized && (force_reply || ((!user && moved) || (user && final))))
2121 event.type = ConfigureNotify;
2122 event.xconfigure.display = ob_display;
2123 event.xconfigure.event = self->window;
2124 event.xconfigure.window = self->window;
2126 /* root window real coords */
2127 event.xconfigure.x = self->frame->area.x + self->frame->size.left -
2129 event.xconfigure.y = self->frame->area.y + self->frame->size.top -
2131 event.xconfigure.width = w;
2132 event.xconfigure.height = h;
2133 event.xconfigure.border_width = 0;
2134 event.xconfigure.above = self->frame->plate;
2135 event.xconfigure.override_redirect = FALSE;
2136 XSendEvent(event.xconfigure.display, event.xconfigure.window,
2137 FALSE, StructureNotifyMask, &event);
2141 /* if the client is shrinking, then resize the frame before the client */
2142 if (send_resize_client && (!user || (w <= oldw || h <= oldh)))
2143 XResizeWindow(ob_display, self->window, w, h);
2148 void client_fullscreen(ObClient *self, gboolean fs, gboolean savearea)
2152 if (!(self->functions & OB_CLIENT_FUNC_FULLSCREEN) || /* can't */
2153 self->fullscreen == fs) return; /* already done */
2155 self->fullscreen = fs;
2156 client_change_state(self); /* change the state hints on the client,
2157 and adjust out layer/stacking */
2161 self->pre_fullscreen_area = self->area;
2163 /* these are not actually used cuz client_configure will set them
2164 as appropriate when the window is fullscreened */
2169 if (self->pre_fullscreen_area.width > 0 &&
2170 self->pre_fullscreen_area.height > 0)
2172 x = self->pre_fullscreen_area.x;
2173 y = self->pre_fullscreen_area.y;
2174 w = self->pre_fullscreen_area.width;
2175 h = self->pre_fullscreen_area.height;
2176 RECT_SET(self->pre_fullscreen_area, 0, 0, 0, 0);
2178 /* pick some fallbacks... */
2179 a = screen_area_monitor(self->desktop, 0);
2180 x = a->x + a->width / 4;
2181 y = a->y + a->height / 4;
2187 client_setup_decor_and_functions(self);
2189 client_move_resize(self, x, y, w, h);
2191 /* try focus us when we go into fullscreen mode */
2195 static void client_iconify_recursive(ObClient *self,
2196 gboolean iconic, gboolean curdesk)
2199 gboolean changed = FALSE;
2202 if (self->iconic != iconic) {
2203 ob_debug("%sconifying window: 0x%lx\n", (iconic ? "I" : "Uni"),
2206 self->iconic = iconic;
2209 if (self->functions & OB_CLIENT_FUNC_ICONIFY) {
2212 old = self->wmstate;
2213 self->wmstate = IconicState;
2214 if (old != self->wmstate)
2215 PROP_MSG(self->window, kde_wm_change_state,
2216 self->wmstate, 1, 0, 0);
2218 /* update the focus lists.. iconic windows go to the bottom of
2219 the list, put the new iconic window at the 'top of the
2221 focus_order_to_top(self);
2229 client_set_desktop(self, screen_desktop, FALSE);
2231 old = self->wmstate;
2232 self->wmstate = self->shaded ? IconicState : NormalState;
2233 if (old != self->wmstate)
2234 PROP_MSG(self->window, kde_wm_change_state,
2235 self->wmstate, 1, 0, 0);
2237 /* this puts it after the current focused window */
2238 focus_order_remove(self);
2239 focus_order_add_new(self);
2241 /* this is here cuz with the VIDMODE extension, the viewport can
2242 change while a fullscreen window is iconic, and when it
2243 uniconifies, it would be nice if it did so to the new position
2245 client_reconfigure(self);
2252 client_change_state(self);
2253 client_showhide(self);
2254 screen_update_areas();
2257 /* iconify all transients */
2258 for (it = self->transients; it; it = g_slist_next(it))
2259 if (it->data != self) client_iconify_recursive(it->data,
2263 void client_iconify(ObClient *self, gboolean iconic, gboolean curdesk)
2265 /* move up the transient chain as far as possible first */
2266 self = client_search_top_transient(self);
2268 client_iconify_recursive(client_search_top_transient(self),
2272 void client_maximize(ObClient *self, gboolean max, gint dir, gboolean savearea)
2276 g_assert(dir == 0 || dir == 1 || dir == 2);
2277 if (!(self->functions & OB_CLIENT_FUNC_MAXIMIZE)) return; /* can't */
2279 /* check if already done */
2281 if (dir == 0 && self->max_horz && self->max_vert) return;
2282 if (dir == 1 && self->max_horz) return;
2283 if (dir == 2 && self->max_vert) return;
2285 if (dir == 0 && !self->max_horz && !self->max_vert) return;
2286 if (dir == 1 && !self->max_horz) return;
2287 if (dir == 2 && !self->max_vert) return;
2290 /* we just tell it to configure in the same place and client_configure
2291 worries about filling the screen with the window */
2294 w = self->area.width;
2295 h = self->area.height;
2299 if ((dir == 0 || dir == 1) && !self->max_horz) { /* horz */
2300 RECT_SET(self->pre_max_area,
2301 self->area.x, self->pre_max_area.y,
2302 self->area.width, self->pre_max_area.height);
2304 if ((dir == 0 || dir == 2) && !self->max_vert) { /* vert */
2305 RECT_SET(self->pre_max_area,
2306 self->pre_max_area.x, self->area.y,
2307 self->pre_max_area.width, self->area.height);
2313 a = screen_area_monitor(self->desktop, 0);
2314 if ((dir == 0 || dir == 1) && self->max_horz) { /* horz */
2315 if (self->pre_max_area.width > 0) {
2316 x = self->pre_max_area.x;
2317 w = self->pre_max_area.width;
2319 RECT_SET(self->pre_max_area, 0, self->pre_max_area.y,
2320 0, self->pre_max_area.height);
2322 /* pick some fallbacks... */
2323 x = a->x + a->width / 4;
2327 if ((dir == 0 || dir == 2) && self->max_vert) { /* vert */
2328 if (self->pre_max_area.height > 0) {
2329 y = self->pre_max_area.y;
2330 h = self->pre_max_area.height;
2332 RECT_SET(self->pre_max_area, self->pre_max_area.x, 0,
2333 self->pre_max_area.width, 0);
2335 /* pick some fallbacks... */
2336 y = a->y + a->height / 4;
2342 if (dir == 0 || dir == 1) /* horz */
2343 self->max_horz = max;
2344 if (dir == 0 || dir == 2) /* vert */
2345 self->max_vert = max;
2347 client_change_state(self); /* change the state hints on the client */
2349 client_setup_decor_and_functions(self);
2351 client_move_resize(self, x, y, w, h);
2354 void client_shade(ObClient *self, gboolean shade)
2356 if ((!(self->functions & OB_CLIENT_FUNC_SHADE) &&
2357 shade) || /* can't shade */
2358 self->shaded == shade) return; /* already done */
2360 /* when we're iconic, don't change the wmstate */
2361 if (!self->iconic) {
2364 old = self->wmstate;
2365 self->wmstate = shade ? IconicState : NormalState;
2366 if (old != self->wmstate)
2367 PROP_MSG(self->window, kde_wm_change_state,
2368 self->wmstate, 1, 0, 0);
2371 self->shaded = shade;
2372 client_change_state(self);
2373 /* resize the frame to just the titlebar */
2374 frame_adjust_area(self->frame, FALSE, FALSE, FALSE);
2377 void client_close(ObClient *self)
2381 if (!(self->functions & OB_CLIENT_FUNC_CLOSE)) return;
2383 /* in the case that the client provides no means to requesting that it
2384 close, we just kill it */
2385 if (!self->delete_window)
2389 XXX: itd be cool to do timeouts and shit here for killing the client's
2391 like... if the window is around after 5 seconds, then the close button
2392 turns a nice red, and if this function is called again, the client is
2396 ce.xclient.type = ClientMessage;
2397 ce.xclient.message_type = prop_atoms.wm_protocols;
2398 ce.xclient.display = ob_display;
2399 ce.xclient.window = self->window;
2400 ce.xclient.format = 32;
2401 ce.xclient.data.l[0] = prop_atoms.wm_delete_window;
2402 ce.xclient.data.l[1] = event_lasttime;
2403 ce.xclient.data.l[2] = 0l;
2404 ce.xclient.data.l[3] = 0l;
2405 ce.xclient.data.l[4] = 0l;
2406 XSendEvent(ob_display, self->window, FALSE, NoEventMask, &ce);
2409 void client_kill(ObClient *self)
2411 XKillClient(ob_display, self->window);
2414 void client_set_desktop_recursive(ObClient *self,
2415 guint target, gboolean donthide)
2420 if (target != self->desktop) {
2422 ob_debug("Setting desktop %u\n", target+1);
2424 g_assert(target < screen_num_desktops || target == DESKTOP_ALL);
2426 /* remove from the old desktop(s) */
2427 focus_order_remove(self);
2429 old = self->desktop;
2430 self->desktop = target;
2431 PROP_SET32(self->window, net_wm_desktop, cardinal, target);
2432 /* the frame can display the current desktop state */
2433 frame_adjust_state(self->frame);
2434 /* 'move' the window to the new desktop */
2436 client_showhide(self);
2437 /* raise if it was not already on the desktop */
2438 if (old != DESKTOP_ALL)
2440 screen_update_areas();
2442 /* add to the new desktop(s) */
2443 if (config_focus_new)
2444 focus_order_to_top(self);
2446 focus_order_to_bottom(self);
2449 /* move all transients */
2450 for (it = self->transients; it; it = g_slist_next(it))
2451 if (it->data != self) client_set_desktop_recursive(it->data,
2455 void client_set_desktop(ObClient *self, guint target, gboolean donthide)
2457 client_set_desktop_recursive(client_search_top_transient(self),
2461 ObClient *client_search_modal_child(ObClient *self)
2466 for (it = self->transients; it; it = g_slist_next(it)) {
2467 ObClient *c = it->data;
2468 if ((ret = client_search_modal_child(c))) return ret;
2469 if (c->modal) return c;
2474 gboolean client_validate(ObClient *self)
2478 XSync(ob_display, FALSE); /* get all events on the server */
2480 if (XCheckTypedWindowEvent(ob_display, self->window, DestroyNotify, &e) ||
2481 XCheckTypedWindowEvent(ob_display, self->window, UnmapNotify, &e)) {
2482 XPutBackEvent(ob_display, &e);
2489 void client_set_wm_state(ObClient *self, glong state)
2491 if (state == self->wmstate) return; /* no change */
2495 client_iconify(self, TRUE, TRUE);
2498 client_iconify(self, FALSE, TRUE);
2503 void client_set_state(ObClient *self, Atom action, glong data1, glong data2)
2505 gboolean shaded = self->shaded;
2506 gboolean fullscreen = self->fullscreen;
2507 gboolean undecorated = self->undecorated;
2508 gboolean max_horz = self->max_horz;
2509 gboolean max_vert = self->max_vert;
2510 gboolean modal = self->modal;
2513 if (!(action == prop_atoms.net_wm_state_add ||
2514 action == prop_atoms.net_wm_state_remove ||
2515 action == prop_atoms.net_wm_state_toggle))
2516 /* an invalid action was passed to the client message, ignore it */
2519 for (i = 0; i < 2; ++i) {
2520 Atom state = i == 0 ? data1 : data2;
2522 if (!state) continue;
2524 /* if toggling, then pick whether we're adding or removing */
2525 if (action == prop_atoms.net_wm_state_toggle) {
2526 if (state == prop_atoms.net_wm_state_modal)
2527 action = modal ? prop_atoms.net_wm_state_remove :
2528 prop_atoms.net_wm_state_add;
2529 else if (state == prop_atoms.net_wm_state_maximized_vert)
2530 action = self->max_vert ? prop_atoms.net_wm_state_remove :
2531 prop_atoms.net_wm_state_add;
2532 else if (state == prop_atoms.net_wm_state_maximized_horz)
2533 action = self->max_horz ? prop_atoms.net_wm_state_remove :
2534 prop_atoms.net_wm_state_add;
2535 else if (state == prop_atoms.net_wm_state_shaded)
2536 action = shaded ? prop_atoms.net_wm_state_remove :
2537 prop_atoms.net_wm_state_add;
2538 else if (state == prop_atoms.net_wm_state_skip_taskbar)
2539 action = self->skip_taskbar ?
2540 prop_atoms.net_wm_state_remove :
2541 prop_atoms.net_wm_state_add;
2542 else if (state == prop_atoms.net_wm_state_skip_pager)
2543 action = self->skip_pager ?
2544 prop_atoms.net_wm_state_remove :
2545 prop_atoms.net_wm_state_add;
2546 else if (state == prop_atoms.net_wm_state_fullscreen)
2547 action = fullscreen ?
2548 prop_atoms.net_wm_state_remove :
2549 prop_atoms.net_wm_state_add;
2550 else if (state == prop_atoms.net_wm_state_above)
2551 action = self->above ? prop_atoms.net_wm_state_remove :
2552 prop_atoms.net_wm_state_add;
2553 else if (state == prop_atoms.net_wm_state_below)
2554 action = self->below ? prop_atoms.net_wm_state_remove :
2555 prop_atoms.net_wm_state_add;
2556 else if (state == prop_atoms.ob_wm_state_undecorated)
2557 action = undecorated ? prop_atoms.net_wm_state_remove :
2558 prop_atoms.net_wm_state_add;
2561 if (action == prop_atoms.net_wm_state_add) {
2562 if (state == prop_atoms.net_wm_state_modal) {
2564 } else if (state == prop_atoms.net_wm_state_maximized_vert) {
2566 } else if (state == prop_atoms.net_wm_state_maximized_horz) {
2568 } else if (state == prop_atoms.net_wm_state_shaded) {
2570 } else if (state == prop_atoms.net_wm_state_skip_taskbar) {
2571 self->skip_taskbar = TRUE;
2572 } else if (state == prop_atoms.net_wm_state_skip_pager) {
2573 self->skip_pager = TRUE;
2574 } else if (state == prop_atoms.net_wm_state_fullscreen) {
2576 } else if (state == prop_atoms.net_wm_state_above) {
2578 self->below = FALSE;
2579 } else if (state == prop_atoms.net_wm_state_below) {
2580 self->above = FALSE;
2582 } else if (state == prop_atoms.ob_wm_state_undecorated) {
2586 } else { /* action == prop_atoms.net_wm_state_remove */
2587 if (state == prop_atoms.net_wm_state_modal) {
2589 } else if (state == prop_atoms.net_wm_state_maximized_vert) {
2591 } else if (state == prop_atoms.net_wm_state_maximized_horz) {
2593 } else if (state == prop_atoms.net_wm_state_shaded) {
2595 } else if (state == prop_atoms.net_wm_state_skip_taskbar) {
2596 self->skip_taskbar = FALSE;
2597 } else if (state == prop_atoms.net_wm_state_skip_pager) {
2598 self->skip_pager = FALSE;
2599 } else if (state == prop_atoms.net_wm_state_fullscreen) {
2601 } else if (state == prop_atoms.net_wm_state_above) {
2602 self->above = FALSE;
2603 } else if (state == prop_atoms.net_wm_state_below) {
2604 self->below = FALSE;
2605 } else if (state == prop_atoms.ob_wm_state_undecorated) {
2606 undecorated = FALSE;
2610 if (max_horz != self->max_horz || max_vert != self->max_vert) {
2611 if (max_horz != self->max_horz && max_vert != self->max_vert) {
2613 if (max_horz == max_vert) { /* both going the same way */
2614 client_maximize(self, max_horz, 0, TRUE);
2616 client_maximize(self, max_horz, 1, TRUE);
2617 client_maximize(self, max_vert, 2, TRUE);
2621 if (max_horz != self->max_horz)
2622 client_maximize(self, max_horz, 1, TRUE);
2624 client_maximize(self, max_vert, 2, TRUE);
2627 /* change fullscreen state before shading, as it will affect if the window
2629 if (fullscreen != self->fullscreen)
2630 client_fullscreen(self, fullscreen, TRUE);
2631 if (shaded != self->shaded)
2632 client_shade(self, shaded);
2633 if (undecorated != self->undecorated)
2634 client_set_undecorated(self, undecorated);
2635 if (modal != self->modal) {
2636 self->modal = modal;
2637 /* when a window changes modality, then its stacking order with its
2638 transients needs to change */
2641 client_calc_layer(self);
2642 client_change_state(self); /* change the hint to reflect these changes */
2645 ObClient *client_focus_target(ObClient *self)
2649 /* if we have a modal child, then focus it, not us */
2650 child = client_search_modal_child(client_search_top_transient(self));
2651 if (child) return child;
2655 gboolean client_can_focus(ObClient *self)
2659 /* choose the correct target */
2660 self = client_focus_target(self);
2662 if (!self->frame->visible)
2665 if (!(self->can_focus || self->focus_notify))
2668 /* do a check to see if the window has already been unmapped or destroyed
2669 do this intelligently while watching out for unmaps we've generated
2670 (ignore_unmaps > 0) */
2671 if (XCheckTypedWindowEvent(ob_display, self->window,
2672 DestroyNotify, &ev)) {
2673 XPutBackEvent(ob_display, &ev);
2676 while (XCheckTypedWindowEvent(ob_display, self->window,
2677 UnmapNotify, &ev)) {
2678 if (self->ignore_unmaps) {
2679 self->ignore_unmaps--;
2681 XPutBackEvent(ob_display, &ev);
2689 gboolean client_focus(ObClient *self)
2691 /* choose the correct target */
2692 self = client_focus_target(self);
2694 if (!client_can_focus(self)) {
2695 if (!self->frame->visible) {
2696 /* update the focus lists */
2697 focus_order_to_top(self);
2702 if (self->can_focus) {
2703 /* RevertToPointerRoot causes much more headache than RevertToNone, so
2704 I choose to use it always, hopefully to find errors quicker, if any
2705 are left. (I hate X. I hate focus events.)
2707 Update: Changing this to RevertToNone fixed a bug with mozilla (bug
2708 #799. So now it is RevertToNone again.
2710 XSetInputFocus(ob_display, self->window, RevertToNone,
2714 if (self->focus_notify) {
2716 ce.xclient.type = ClientMessage;
2717 ce.xclient.message_type = prop_atoms.wm_protocols;
2718 ce.xclient.display = ob_display;
2719 ce.xclient.window = self->window;
2720 ce.xclient.format = 32;
2721 ce.xclient.data.l[0] = prop_atoms.wm_take_focus;
2722 ce.xclient.data.l[1] = event_lasttime;
2723 ce.xclient.data.l[2] = 0l;
2724 ce.xclient.data.l[3] = 0l;
2725 ce.xclient.data.l[4] = 0l;
2726 XSendEvent(ob_display, self->window, FALSE, NoEventMask, &ce);
2730 ob_debug("%sively focusing %lx at %d\n",
2731 (self->can_focus ? "act" : "pass"),
2732 self->window, (gint) event_lasttime);
2735 /* Cause the FocusIn to come back to us. Important for desktop switches,
2736 since otherwise we'll have no FocusIn on the queue and send it off to
2737 the focus_backup. */
2738 XSync(ob_display, FALSE);
2742 void client_unfocus(ObClient *self)
2744 if (focus_client == self) {
2746 ob_debug("client_unfocus for %lx\n", self->window);
2748 focus_fallback(OB_FOCUS_FALLBACK_UNFOCUSING);
2752 void client_activate(ObClient *self, gboolean here)
2754 if (client_normal(self) && screen_showing_desktop)
2755 screen_show_desktop(FALSE);
2757 client_iconify(self, FALSE, here);
2758 if (self->desktop != DESKTOP_ALL &&
2759 self->desktop != screen_desktop) {
2761 client_set_desktop(self, screen_desktop, FALSE);
2763 screen_set_desktop(self->desktop);
2764 } else if (!self->frame->visible)
2765 /* if its not visible for other reasons, then don't mess
2769 client_shade(self, FALSE);
2773 /* we do this an action here. this is rather important. this is because
2774 we want the results from the focus change to take place BEFORE we go
2775 about raising the window. when a fullscreen window loses focus, we need
2776 this or else the raise wont be able to raise above the to-lose-focus
2777 fullscreen window. */
2781 void client_raise(ObClient *self)
2783 action_run_string("Raise", self);
2786 void client_lower(ObClient *self)
2788 action_run_string("Lower", self);
2791 gboolean client_focused(ObClient *self)
2793 return self == focus_client;
2796 static ObClientIcon* client_icon_recursive(ObClient *self, gint w, gint h)
2799 /* si is the smallest image >= req */
2800 /* li is the largest image < req */
2801 gulong size, smallest = 0xffffffff, largest = 0, si = 0, li = 0;
2803 if (!self->nicons) {
2804 ObClientIcon *parent = NULL;
2806 if (self->transient_for) {
2807 if (self->transient_for != OB_TRAN_GROUP)
2808 parent = client_icon_recursive(self->transient_for, w, h);
2811 for (it = self->group->members; it; it = g_slist_next(it)) {
2812 ObClient *c = it->data;
2813 if (c != self && !c->transient_for) {
2814 if ((parent = client_icon_recursive(c, w, h)))
2824 for (i = 0; i < self->nicons; ++i) {
2825 size = self->icons[i].width * self->icons[i].height;
2826 if (size < smallest && size >= (unsigned)(w * h)) {
2830 if (size > largest && size <= (unsigned)(w * h)) {
2835 if (largest == 0) /* didnt find one smaller than the requested size */
2836 return &self->icons[si];
2837 return &self->icons[li];
2840 const ObClientIcon* client_icon(ObClient *self, gint w, gint h)
2843 static ObClientIcon deficon;
2845 if (!(ret = client_icon_recursive(self, w, h))) {
2846 deficon.width = deficon.height = 48;
2847 deficon.data = ob_rr_theme->def_win_icon;
2853 /* this be mostly ripped from fvwm */
2854 ObClient *client_find_directional(ObClient *c, ObDirection dir)
2856 gint my_cx, my_cy, his_cx, his_cy;
2859 gint score, best_score;
2860 ObClient *best_client, *cur;
2866 /* first, find the centre coords of the currently focused window */
2867 my_cx = c->frame->area.x + c->frame->area.width / 2;
2868 my_cy = c->frame->area.y + c->frame->area.height / 2;
2873 for(it = g_list_first(client_list); it; it = g_list_next(it)) {
2876 /* the currently selected window isn't interesting */
2879 if (!client_normal(cur))
2881 if(c->desktop != cur->desktop && cur->desktop != DESKTOP_ALL)
2885 if(client_focus_target(cur) == cur &&
2886 !(cur->can_focus || cur->focus_notify))
2889 /* find the centre coords of this window, from the
2890 * currently focused window's point of view */
2891 his_cx = (cur->frame->area.x - my_cx)
2892 + cur->frame->area.width / 2;
2893 his_cy = (cur->frame->area.y - my_cy)
2894 + cur->frame->area.height / 2;
2896 if(dir == OB_DIRECTION_NORTHEAST || dir == OB_DIRECTION_SOUTHEAST ||
2897 dir == OB_DIRECTION_SOUTHWEST || dir == OB_DIRECTION_NORTHWEST) {
2899 /* Rotate the diagonals 45 degrees counterclockwise.
2900 * To do this, multiply the matrix /+h +h\ with the
2901 * vector (x y). \-h +h/
2902 * h = sqrt(0.5). We can set h := 1 since absolute
2903 * distance doesn't matter here. */
2904 tx = his_cx + his_cy;
2905 his_cy = -his_cx + his_cy;
2910 case OB_DIRECTION_NORTH:
2911 case OB_DIRECTION_SOUTH:
2912 case OB_DIRECTION_NORTHEAST:
2913 case OB_DIRECTION_SOUTHWEST:
2914 offset = (his_cx < 0) ? -his_cx : his_cx;
2915 distance = ((dir == OB_DIRECTION_NORTH ||
2916 dir == OB_DIRECTION_NORTHEAST) ?
2919 case OB_DIRECTION_EAST:
2920 case OB_DIRECTION_WEST:
2921 case OB_DIRECTION_SOUTHEAST:
2922 case OB_DIRECTION_NORTHWEST:
2923 offset = (his_cy < 0) ? -his_cy : his_cy;
2924 distance = ((dir == OB_DIRECTION_WEST ||
2925 dir == OB_DIRECTION_NORTHWEST) ?
2930 /* the target must be in the requested direction */
2934 /* Calculate score for this window. The smaller the better. */
2935 score = distance + offset;
2937 /* windows more than 45 degrees off the direction are
2938 * heavily penalized and will only be chosen if nothing
2939 * else within a million pixels */
2940 if(offset > distance)
2943 if(best_score == -1 || score < best_score)
2951 void client_set_layer(ObClient *self, gint layer)
2955 self->above = FALSE;
2956 } else if (layer == 0) {
2957 self->below = self->above = FALSE;
2959 self->below = FALSE;
2962 client_calc_layer(self);
2963 client_change_state(self); /* reflect this in the state hints */
2966 void client_set_undecorated(ObClient *self, gboolean undecorated)
2968 if (self->undecorated != undecorated) {
2969 self->undecorated = undecorated;
2970 client_setup_decor_and_functions(self);
2971 client_change_state(self); /* reflect this in the state hints */
2975 guint client_monitor(ObClient *self)
2981 for (i = 0; i < screen_num_monitors; ++i) {
2982 Rect *area = screen_physical_area_monitor(i);
2983 if (RECT_INTERSECTS_RECT(*area, self->frame->area)) {
2987 RECT_SET_INTERSECTION(r, *area, self->frame->area);
2988 v = r.width * r.height;
2999 ObClient *client_search_top_transient(ObClient *self)
3001 /* move up the transient chain as far as possible */
3002 if (self->transient_for) {
3003 if (self->transient_for != OB_TRAN_GROUP) {
3004 return client_search_top_transient(self->transient_for);
3008 g_assert(self->group);
3010 for (it = self->group->members; it; it = g_slist_next(it)) {
3011 ObClient *c = it->data;
3013 /* checking transient_for prevents infinate loops! */
3014 if (c != self && !c->transient_for)
3025 ObClient *client_search_focus_parent(ObClient *self)
3027 if (self->transient_for) {
3028 if (self->transient_for != OB_TRAN_GROUP) {
3029 if (client_focused(self->transient_for))
3030 return self->transient_for;
3034 for (it = self->group->members; it; it = g_slist_next(it)) {
3035 ObClient *c = it->data;
3037 /* checking transient_for prevents infinate loops! */
3038 if (c != self && !c->transient_for)
3039 if (client_focused(c))
3048 ObClient *client_search_parent(ObClient *self, ObClient *search)
3050 if (self->transient_for) {
3051 if (self->transient_for != OB_TRAN_GROUP) {
3052 if (self->transient_for == search)
3057 for (it = self->group->members; it; it = g_slist_next(it)) {
3058 ObClient *c = it->data;
3060 /* checking transient_for prevents infinate loops! */
3061 if (c != self && !c->transient_for)
3071 ObClient *client_search_transient(ObClient *self, ObClient *search)
3075 for (sit = self->transients; sit; sit = g_slist_next(sit)) {
3076 if (sit->data == search)
3078 if (client_search_transient(sit->data, search))
3084 void client_update_sm_client_id(ObClient *self)
3086 g_free(self->sm_client_id);
3087 self->sm_client_id = NULL;
3089 if (!PROP_GETS(self->window, sm_client_id, locale, &self->sm_client_id) &&
3091 PROP_GETS(self->group->leader, sm_client_id, locale,
3092 &self->sm_client_id);
3095 /* finds the nearest edge in the given direction from the current client
3096 * note to self: the edge is the -frame- edge (the actual one), not the
3099 gint client_directional_edge_search(ObClient *c, ObDirection dir)
3102 gint my_edge_start, my_edge_end, my_offset;
3109 a = screen_area(c->desktop);
3112 case OB_DIRECTION_NORTH:
3113 my_edge_start = c->frame->area.x;
3114 my_edge_end = c->frame->area.x + c->frame->area.width;
3115 my_offset = c->frame->area.y;
3117 /* default: top of screen */
3120 for(it = client_list; it; it = g_list_next(it)) {
3121 gint his_edge_start, his_edge_end, his_offset;
3122 ObClient *cur = it->data;
3126 if(!client_normal(cur))
3128 if(c->desktop != cur->desktop && cur->desktop != DESKTOP_ALL)
3133 his_edge_start = cur->frame->area.x;
3134 his_edge_end = cur->frame->area.x + cur->frame->area.width;
3135 his_offset = cur->frame->area.y + cur->frame->area.height;
3137 if(his_offset + 1 > my_offset)
3140 if(his_offset < dest)
3143 if(his_edge_start >= my_edge_start &&
3144 his_edge_start <= my_edge_end)
3147 if(my_edge_start >= his_edge_start &&
3148 my_edge_start <= his_edge_end)
3153 case OB_DIRECTION_SOUTH:
3154 my_edge_start = c->frame->area.x;
3155 my_edge_end = c->frame->area.x + c->frame->area.width;
3156 my_offset = c->frame->area.y + c->frame->area.height;
3158 /* default: bottom of screen */
3159 dest = a->y + a->height;
3161 for(it = client_list; it; it = g_list_next(it)) {
3162 gint his_edge_start, his_edge_end, his_offset;
3163 ObClient *cur = it->data;
3167 if(!client_normal(cur))
3169 if(c->desktop != cur->desktop && cur->desktop != DESKTOP_ALL)
3174 his_edge_start = cur->frame->area.x;
3175 his_edge_end = cur->frame->area.x + cur->frame->area.width;
3176 his_offset = cur->frame->area.y;
3179 if(his_offset - 1 < my_offset)
3182 if(his_offset > dest)
3185 if(his_edge_start >= my_edge_start &&
3186 his_edge_start <= my_edge_end)
3189 if(my_edge_start >= his_edge_start &&
3190 my_edge_start <= his_edge_end)
3195 case OB_DIRECTION_WEST:
3196 my_edge_start = c->frame->area.y;
3197 my_edge_end = c->frame->area.y + c->frame->area.height;
3198 my_offset = c->frame->area.x;
3200 /* default: leftmost egde of screen */
3203 for(it = client_list; it; it = g_list_next(it)) {
3204 gint his_edge_start, his_edge_end, his_offset;
3205 ObClient *cur = it->data;
3209 if(!client_normal(cur))
3211 if(c->desktop != cur->desktop && cur->desktop != DESKTOP_ALL)
3216 his_edge_start = cur->frame->area.y;
3217 his_edge_end = cur->frame->area.y + cur->frame->area.height;
3218 his_offset = cur->frame->area.x + cur->frame->area.width;
3220 if(his_offset + 1 > my_offset)
3223 if(his_offset < dest)
3226 if(his_edge_start >= my_edge_start &&
3227 his_edge_start <= my_edge_end)
3230 if(my_edge_start >= his_edge_start &&
3231 my_edge_start <= his_edge_end)
3237 case OB_DIRECTION_EAST:
3238 my_edge_start = c->frame->area.y;
3239 my_edge_end = c->frame->area.y + c->frame->area.height;
3240 my_offset = c->frame->area.x + c->frame->area.width;
3242 /* default: rightmost edge of screen */
3243 dest = a->x + a->width;
3245 for(it = client_list; it; it = g_list_next(it)) {
3246 gint his_edge_start, his_edge_end, his_offset;
3247 ObClient *cur = it->data;
3251 if(!client_normal(cur))
3253 if(c->desktop != cur->desktop && cur->desktop != DESKTOP_ALL)
3258 his_edge_start = cur->frame->area.y;
3259 his_edge_end = cur->frame->area.y + cur->frame->area.height;
3260 his_offset = cur->frame->area.x;
3262 if(his_offset - 1 < my_offset)
3265 if(his_offset > dest)
3268 if(his_edge_start >= my_edge_start &&
3269 his_edge_start <= my_edge_end)
3272 if(my_edge_start >= his_edge_start &&
3273 my_edge_start <= his_edge_end)
3278 case OB_DIRECTION_NORTHEAST:
3279 case OB_DIRECTION_SOUTHEAST:
3280 case OB_DIRECTION_NORTHWEST:
3281 case OB_DIRECTION_SOUTHWEST:
3282 /* not implemented */
3284 g_assert_not_reached();
3289 ObClient* client_under_pointer()
3293 ObClient *ret = NULL;
3295 if (screen_pointer_pos(&x, &y)) {
3296 for (it = stacking_list; it; it = g_list_next(it)) {
3297 if (WINDOW_IS_CLIENT(it->data)) {
3298 ObClient *c = WINDOW_AS_CLIENT(it->data);
3299 if (c->frame->visible &&
3300 RECT_CONTAINS(c->frame->area, x, y)) {
3310 gboolean client_has_group_siblings(ObClient *self)
3312 return self->group && self->group->members->next;