1 /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
3 client.c for the Openbox window manager
4 Copyright (c) 2004 Mikael Magnusson
5 Copyright (c) 2003 Ben Jansens
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 See the COPYING file for a copy of the GNU General Public License.
22 #include "startupnotify.h"
26 #include "moveresize.h"
29 #include "extensions.h"
39 #include "menuframe.h"
42 #include "render/render.h"
45 #include <X11/Xutil.h>
47 /*! The event mask to grab on client windows */
48 #define CLIENT_EVENTMASK (PropertyChangeMask | FocusChangeMask | \
51 #define CLIENT_NOPROPAGATEMASK (ButtonPressMask | ButtonReleaseMask | \
56 ObClientDestructor func;
60 GList *client_list = NULL;
61 GSList *client_destructors = NULL;
63 static void client_get_all(ObClient *self);
64 static void client_toggle_border(ObClient *self, gboolean show);
65 static void client_get_startup_id(ObClient *self);
66 static void client_get_area(ObClient *self);
67 static void client_get_desktop(ObClient *self);
68 static void client_get_state(ObClient *self);
69 static void client_get_shaped(ObClient *self);
70 static void client_get_mwm_hints(ObClient *self);
71 static void client_get_gravity(ObClient *self);
72 static void client_showhide(ObClient *self);
73 static void client_change_allowed_actions(ObClient *self);
74 static void client_change_state(ObClient *self);
75 static void client_apply_startup_state(ObClient *self);
76 static void client_restore_session_state(ObClient *self);
77 static void client_restore_session_stacking(ObClient *self);
78 static void client_urgent_notify(ObClient *self);
80 void client_startup(gboolean reconfig)
87 void client_shutdown(gboolean reconfig)
91 void client_add_destructor(ObClientDestructor func, gpointer data)
93 Destructor *d = g_new(Destructor, 1);
96 client_destructors = g_slist_prepend(client_destructors, d);
99 void client_remove_destructor(ObClientDestructor func)
103 for (it = client_destructors; it; it = g_slist_next(it)) {
104 Destructor *d = it->data;
105 if (d->func == func) {
107 client_destructors = g_slist_delete_link(client_destructors, it);
113 void client_set_list()
115 Window *windows, *win_it;
117 guint size = g_list_length(client_list);
119 /* create an array of the window ids */
121 windows = g_new(Window, size);
123 for (it = client_list; it; it = g_list_next(it), ++win_it)
124 *win_it = ((ObClient*)it->data)->window;
128 PROP_SETA32(RootWindow(ob_display, ob_screen),
129 net_client_list, window, (guint32*)windows, size);
138 void client_foreach_transient(ObClient *self, ObClientForeachFunc func, gpointer data)
142 for (it = self->transients; it; it = g_slist_next(it)) {
143 if (!func(it->data, data)) return;
144 client_foreach_transient(it->data, func, data);
148 void client_foreach_ancestor(ObClient *self, ObClientForeachFunc func, gpointer data)
150 if (self->transient_for) {
151 if (self->transient_for != OB_TRAN_GROUP) {
152 if (!func(self->transient_for, data)) return;
153 client_foreach_ancestor(self->transient_for, func, data);
157 for (it = self->group->members; it; it = g_slist_next(it))
158 if (it->data != self &&
159 !((ObClient*)it->data)->transient_for) {
160 if (!func(it->data, data)) return;
161 client_foreach_ancestor(it->data, func, data);
168 void client_manage_all()
173 XWindowAttributes attrib;
175 XQueryTree(ob_display, RootWindow(ob_display, ob_screen),
176 &w, &w, &children, &nchild);
178 /* remove all icon windows from the list */
179 for (i = 0; i < nchild; i++) {
180 if (children[i] == None) continue;
181 wmhints = XGetWMHints(ob_display, children[i]);
183 if ((wmhints->flags & IconWindowHint) &&
184 (wmhints->icon_window != children[i]))
185 for (j = 0; j < nchild; j++)
186 if (children[j] == wmhints->icon_window) {
194 for (i = 0; i < nchild; ++i) {
195 if (children[i] == None)
197 if (XGetWindowAttributes(ob_display, children[i], &attrib)) {
198 if (attrib.override_redirect) continue;
200 if (attrib.map_state != IsUnmapped)
201 client_manage(children[i]);
207 void client_manage(Window window)
211 XWindowAttributes attrib;
212 XSetWindowAttributes attrib_set;
214 gboolean activate = FALSE;
218 /* check if it has already been unmapped by the time we started mapping
219 the grab does a sync so we don't have to here */
220 if (XCheckTypedWindowEvent(ob_display, window, DestroyNotify, &e) ||
221 XCheckTypedWindowEvent(ob_display, window, UnmapNotify, &e)) {
222 XPutBackEvent(ob_display, &e);
225 return; /* don't manage it */
228 /* make sure it isn't an override-redirect window */
229 if (!XGetWindowAttributes(ob_display, window, &attrib) ||
230 attrib.override_redirect) {
232 return; /* don't manage it */
235 /* is the window a docking app */
236 if ((wmhint = XGetWMHints(ob_display, window))) {
237 if ((wmhint->flags & StateHint) &&
238 wmhint->initial_state == WithdrawnState) {
239 dock_add(window, wmhint);
247 ob_debug("Managing window: %lx\n", window);
249 /* choose the events we want to receive on the CLIENT window */
250 attrib_set.event_mask = CLIENT_EVENTMASK;
251 attrib_set.do_not_propagate_mask = CLIENT_NOPROPAGATEMASK;
252 XChangeWindowAttributes(ob_display, window,
253 CWEventMask|CWDontPropagate, &attrib_set);
256 /* create the ObClient struct, and populate it from the hints on the
258 self = g_new0(ObClient, 1);
259 self->obwin.type = Window_Client;
260 self->window = window;
262 /* non-zero defaults */
263 self->title_count = 1;
264 self->wmstate = NormalState;
266 self->desktop = screen_num_desktops; /* always an invalid value */
268 client_get_all(self);
269 client_restore_session_state(self);
271 sn_app_started(self->class);
273 /* update the focus lists, do this before the call to change_state or
274 it can end up in the list twice! */
275 focus_order_add_new(self);
277 client_change_state(self);
279 /* remove the client's border (and adjust re gravity) */
280 client_toggle_border(self, FALSE);
282 /* specify that if we exit, the window should not be destroyed and should
283 be reparented back to root automatically */
284 XChangeSaveSet(ob_display, window, SetModeInsert);
286 /* create the decoration frame for the client window */
287 self->frame = frame_new();
289 frame_grab_client(self->frame, self);
293 client_apply_startup_state(self);
295 stacking_add(CLIENT_AS_WINDOW(self));
296 client_restore_session_stacking(self);
298 /* focus the new window? */
299 if (ob_state() != OB_STATE_STARTING &&
300 (config_focus_new || client_search_focus_parent(self)) &&
301 /* note the check against Type_Normal/Dialog, not client_normal(self),
302 which would also include other types. in this case we want more
303 strict rules for focus */
304 (self->type == OB_CLIENT_TYPE_NORMAL ||
305 self->type == OB_CLIENT_TYPE_DIALOG))
309 if (self->desktop != screen_desktop) {
310 /* activate the window */
313 gboolean group_foc = FALSE;
318 for (it = self->group->members; it; it = g_slist_next(it))
320 if (client_focused(it->data))
328 (!self->transient_for && (!self->group ||
329 !self->group->members->next))) ||
330 client_search_focus_tree_full(self) ||
332 !client_normal(focus_client))
334 /* activate the window */
341 if (ob_state() == OB_STATE_RUNNING) {
342 gint x = self->area.x, ox = x;
343 gint y = self->area.y, oy = y;
345 place_client(self, &x, &y);
347 if (x != ox || y != oy)
348 client_move(self, x, y);
351 keyboard_grab_for_client(self, TRUE);
352 mouse_grab_for_client(self, TRUE);
354 client_showhide(self);
356 /* use client_focus instead of client_activate cuz client_activate does
357 stuff like switch desktops etc and I'm not interested in all that when
358 a window maps since its not based on an action from the user like
359 clicking a window to activate is. so keep the new window out of the way
362 /* if using focus_delay, stop the timer now so that focus doesn't go
364 event_halt_focus_delay();
367 /* since focus can change the stacking orders, if we focus the window
368 then the standard raise it gets is not enough, we need to queue one
369 for after the focus change takes place */
373 /* client_activate does this but we aret using it so we have to do it
375 if (screen_showing_desktop)
376 screen_show_desktop(FALSE);
378 /* add to client list/map */
379 client_list = g_list_append(client_list, self);
380 g_hash_table_insert(window_map, &self->window, self);
382 /* this has to happen after we're in the client_list */
383 screen_update_areas();
385 /* update the list hints */
388 ob_debug("Managed window 0x%lx (%s)\n", window, self->class);
391 void client_unmanage_all()
393 while (client_list != NULL)
394 client_unmanage(client_list->data);
397 void client_unmanage(ObClient *self)
402 ob_debug("Unmanaging window: %lx (%s)\n", self->window, self->class);
404 g_assert(self != NULL);
406 keyboard_grab_for_client(self, FALSE);
407 mouse_grab_for_client(self, FALSE);
409 /* potentially fix focusLast */
410 if (config_focus_last)
411 grab_pointer(TRUE, OB_CURSOR_NONE);
413 /* remove the window from our save set */
414 XChangeSaveSet(ob_display, self->window, SetModeDelete);
416 /* we dont want events no more */
417 XSelectInput(ob_display, self->window, NoEventMask);
419 frame_hide(self->frame);
421 client_list = g_list_remove(client_list, self);
422 stacking_remove(self);
423 g_hash_table_remove(window_map, &self->window);
425 /* update the focus lists */
426 focus_order_remove(self);
428 /* once the client is out of the list, update the struts to remove it's
430 screen_update_areas();
432 for (it = client_destructors; it; it = g_slist_next(it)) {
433 Destructor *d = it->data;
434 d->func(self, d->data);
437 if (focus_client == self) {
440 /* focus the last focused window on the desktop, and ignore enter
441 events from the unmap so it doesnt mess with the focus */
442 while (XCheckTypedEvent(ob_display, EnterNotify, &e));
443 /* remove these flags so we don't end up getting focused in the
445 self->can_focus = FALSE;
446 self->focus_notify = FALSE;
448 client_unfocus(self);
451 /* tell our parent(s) that we're gone */
452 if (self->transient_for == OB_TRAN_GROUP) { /* transient of group */
453 for (it = self->group->members; it; it = g_slist_next(it))
454 if (it->data != self)
455 ((ObClient*)it->data)->transients =
456 g_slist_remove(((ObClient*)it->data)->transients, self);
457 } else if (self->transient_for) { /* transient of window */
458 self->transient_for->transients =
459 g_slist_remove(self->transient_for->transients, self);
462 /* tell our transients that we're gone */
463 for (it = self->transients; it; it = g_slist_next(it)) {
464 if (((ObClient*)it->data)->transient_for != OB_TRAN_GROUP) {
465 ((ObClient*)it->data)->transient_for = NULL;
466 client_calc_layer(it->data);
470 /* remove from its group */
472 group_remove(self->group, self);
476 /* give the client its border back */
477 client_toggle_border(self, TRUE);
479 /* reparent the window out of the frame, and free the frame */
480 frame_release_client(self->frame, self);
483 if (ob_state() != OB_STATE_EXITING) {
484 /* these values should not be persisted across a window
486 PROP_ERASE(self->window, net_wm_desktop);
487 PROP_ERASE(self->window, net_wm_state);
488 PROP_ERASE(self->window, wm_state);
490 /* if we're left in an unmapped state, the client wont be mapped. this
491 is bad, since we will no longer be managing the window on restart */
492 XMapWindow(ob_display, self->window);
496 ob_debug("Unmanaged window 0x%lx\n", self->window);
498 /* free all data allocated in the client struct */
499 g_slist_free(self->transients);
500 for (j = 0; j < self->nicons; ++j)
501 g_free(self->icons[j].data);
502 if (self->nicons > 0)
505 g_free(self->icon_title);
509 g_free(self->sm_client_id);
512 /* update the list hints */
515 if (config_focus_last)
516 grab_pointer(FALSE, OB_CURSOR_NONE);
519 static void client_urgent_notify(ObClient *self)
522 frame_flash_start(self->frame);
524 frame_flash_stop(self->frame);
527 static void client_restore_session_state(ObClient *self)
531 if (!(it = session_state_find(self)))
534 self->session = it->data;
536 RECT_SET_POINT(self->area, self->session->x, self->session->y);
537 self->positioned = TRUE;
538 if (self->session->w > 0)
539 self->area.width = self->session->w;
540 if (self->session->h > 0)
541 self->area.height = self->session->h;
542 XResizeWindow(ob_display, self->window,
543 self->area.width, self->area.height);
545 self->desktop = (self->session->desktop == DESKTOP_ALL ?
546 self->session->desktop :
547 MIN(screen_num_desktops - 1, self->session->desktop));
548 PROP_SET32(self->window, net_wm_desktop, cardinal, self->desktop);
550 self->shaded = self->session->shaded;
551 self->iconic = self->session->iconic;
552 self->skip_pager = self->session->skip_pager;
553 self->skip_taskbar = self->session->skip_taskbar;
554 self->fullscreen = self->session->fullscreen;
555 self->above = self->session->above;
556 self->below = self->session->below;
557 self->max_horz = self->session->max_horz;
558 self->max_vert = self->session->max_vert;
561 static void client_restore_session_stacking(ObClient *self)
565 if (!self->session) return;
567 it = g_list_find(session_saved_state, self->session);
568 for (it = g_list_previous(it); it; it = g_list_previous(it)) {
571 for (cit = client_list; cit; cit = g_list_next(cit))
572 if (session_state_cmp(it->data, cit->data))
575 client_calc_layer(self);
576 stacking_below(CLIENT_AS_WINDOW(self),
577 CLIENT_AS_WINDOW(cit->data));
583 void client_move_onscreen(ObClient *self, gboolean rude)
585 gint x = self->area.x;
586 gint y = self->area.y;
587 if (client_find_onscreen(self, &x, &y,
588 self->frame->area.width,
589 self->frame->area.height, rude)) {
590 client_move(self, x, y);
594 gboolean client_find_onscreen(ObClient *self, gint *x, gint *y, gint w, gint h,
598 gint ox = *x, oy = *y;
600 frame_client_gravity(self->frame, x, y); /* get where the frame
603 /* XXX watch for xinerama dead areas */
604 /* This makes sure windows aren't entirely outside of the screen so you
605 * can't see them at all */
606 //a = screen_area(self->desktop);
607 a = screen_physical_area_monitor(client_monitor(self));
608 if (client_normal(self)) {
609 if (!self->strut.right && *x >= a->x + a->width - 1)
610 *x = a->x + a->width - self->frame->area.width;
611 if (!self->strut.bottom && *y >= a->y + a->height - 1)
612 *y = a->y + a->height - self->frame->area.height;
613 if (!self->strut.left && *x + self->frame->area.width - 1 < a->x)
615 if (!self->strut.top && *y + self->frame->area.height - 1 < a->y)
619 /* This here doesn't let windows even a pixel outside the screen,
620 * not applied to all windows. Not sure if it's going to stay at all.
621 * I wonder if disabling this will break struts somehow? Let's find out. */
623 /* this is ben's MOZILLA BITCHSLAP. "oh ya it fucking feels good.
624 Java can suck it too." */
626 /* dont let windows map/move into the strut unless they
627 are bigger than the available area */
629 if (!self->strut.left && *x < a->x) *x = a->x;
630 if (!self->strut.right && *x + w > a->x + a->width)
631 *x = a->x + a->width - w;
633 if (h <= a->height) {
634 if (!self->strut.top && *y < a->y) *y = a->y;
635 if (!self->strut.bottom && *y + h > a->y + a->height)
636 *y = a->y + a->height - h;
640 frame_frame_gravity(self->frame, x, y); /* get where the client
643 return ox != *x || oy != *y;
646 static void client_toggle_border(ObClient *self, gboolean show)
648 /* adjust our idea of where the client is, based on its border. When the
649 border is removed, the client should now be considered to be in a
651 when re-adding the border to the client, the same operation needs to be
653 gint oldx = self->area.x, oldy = self->area.y;
654 gint x = oldx, y = oldy;
655 switch(self->gravity) {
657 case NorthWestGravity:
659 case SouthWestGravity:
661 case NorthEastGravity:
663 case SouthEastGravity:
664 if (show) x -= self->border_width * 2;
665 else x += self->border_width * 2;
672 if (show) x -= self->border_width;
673 else x += self->border_width;
676 switch(self->gravity) {
678 case NorthWestGravity:
680 case NorthEastGravity:
682 case SouthWestGravity:
684 case SouthEastGravity:
685 if (show) y -= self->border_width * 2;
686 else y += self->border_width * 2;
693 if (show) y -= self->border_width;
694 else y += self->border_width;
701 XSetWindowBorderWidth(ob_display, self->window, self->border_width);
703 /* move the client so it is back it the right spot _with_ its
705 if (x != oldx || y != oldy)
706 XMoveWindow(ob_display, self->window, x, y);
708 XSetWindowBorderWidth(ob_display, self->window, 0);
712 static void client_get_all(ObClient *self)
714 client_get_area(self);
715 client_update_transient_for(self);
716 client_update_wmhints(self);
717 client_get_startup_id(self);
718 client_get_desktop(self);
719 client_get_shaped(self);
721 client_get_mwm_hints(self);
722 client_get_type(self);/* this can change the mwmhints for special cases */
724 /* The transient hint is used to pick a type, but the type can also affect
725 transiency (dialogs are always made transients). This is Havoc's idea,
726 but it is needed to make some apps work right (eg tsclient). */
727 client_update_transient_for(self);
729 client_get_state(self);
732 /* a couple type-based defaults for new windows */
734 /* this makes sure that these windows appear on all desktops */
735 if (self->type == OB_CLIENT_TYPE_DESKTOP)
736 self->desktop = DESKTOP_ALL;
739 client_update_protocols(self);
741 client_get_gravity(self); /* get the attribute gravity */
742 client_update_normal_hints(self); /* this may override the attribute
745 /* got the type, the mwmhints, the protocols, and the normal hints
746 (min/max sizes), so we're ready to set up the decorations/functions */
747 client_setup_decor_and_functions(self);
749 client_update_title(self);
750 client_update_class(self);
751 client_update_sm_client_id(self);
752 client_update_strut(self);
753 client_update_icons(self);
756 static void client_get_startup_id(ObClient *self)
758 if (!(PROP_GETS(self->window, net_startup_id, utf8, &self->startup_id)))
760 PROP_GETS(self->group->leader,
761 net_startup_id, utf8, &self->startup_id);
764 static void client_get_area(ObClient *self)
766 XWindowAttributes wattrib;
769 ret = XGetWindowAttributes(ob_display, self->window, &wattrib);
770 g_assert(ret != BadWindow);
772 RECT_SET(self->area, wattrib.x, wattrib.y, wattrib.width, wattrib.height);
773 self->border_width = wattrib.border_width;
776 static void client_get_desktop(ObClient *self)
778 guint32 d = screen_num_desktops; /* an always-invalid value */
780 if (PROP_GET32(self->window, net_wm_desktop, cardinal, &d)) {
781 if (d >= screen_num_desktops && d != DESKTOP_ALL)
782 self->desktop = screen_num_desktops - 1;
786 gboolean trdesk = FALSE;
788 if (self->transient_for) {
789 if (self->transient_for != OB_TRAN_GROUP) {
790 self->desktop = self->transient_for->desktop;
795 for (it = self->group->members; it; it = g_slist_next(it))
796 if (it->data != self &&
797 !((ObClient*)it->data)->transient_for) {
798 self->desktop = ((ObClient*)it->data)->desktop;
805 /* try get from the startup-notification protocol */
806 if (sn_get_desktop(self->startup_id, &self->desktop)) {
807 if (self->desktop >= screen_num_desktops &&
808 self->desktop != DESKTOP_ALL)
809 self->desktop = screen_num_desktops - 1;
811 /* defaults to the current desktop */
812 self->desktop = screen_desktop;
815 if (self->desktop != d) {
816 /* set the desktop hint, to make sure that it always exists */
817 PROP_SET32(self->window, net_wm_desktop, cardinal, self->desktop);
821 static void client_get_state(ObClient *self)
826 if (PROP_GETA32(self->window, net_wm_state, atom, &state, &num)) {
828 for (i = 0; i < num; ++i) {
829 if (state[i] == prop_atoms.net_wm_state_modal)
831 else if (state[i] == prop_atoms.net_wm_state_shaded)
833 else if (state[i] == prop_atoms.net_wm_state_hidden)
835 else if (state[i] == prop_atoms.net_wm_state_skip_taskbar)
836 self->skip_taskbar = TRUE;
837 else if (state[i] == prop_atoms.net_wm_state_skip_pager)
838 self->skip_pager = TRUE;
839 else if (state[i] == prop_atoms.net_wm_state_fullscreen)
840 self->fullscreen = TRUE;
841 else if (state[i] == prop_atoms.net_wm_state_maximized_vert)
842 self->max_vert = TRUE;
843 else if (state[i] == prop_atoms.net_wm_state_maximized_horz)
844 self->max_horz = TRUE;
845 else if (state[i] == prop_atoms.net_wm_state_above)
847 else if (state[i] == prop_atoms.net_wm_state_below)
849 else if (state[i] == prop_atoms.ob_wm_state_undecorated)
850 self->undecorated = TRUE;
856 if (!(self->above || self->below)) {
858 /* apply stuff from the group */
862 for (it = self->group->members; it; it = g_slist_next(it)) {
863 ObClient *c = it->data;
864 if (c != self && !client_search_transient(self, c) &&
865 client_normal(self) && client_normal(c))
868 (c->above ? 1 : (c->below ? -1 : 0)));
882 g_assert_not_reached();
889 static void client_get_shaped(ObClient *self)
891 self->shaped = FALSE;
893 if (extensions_shape) {
898 XShapeSelectInput(ob_display, self->window, ShapeNotifyMask);
900 XShapeQueryExtents(ob_display, self->window, &s, &foo,
901 &foo, &ufoo, &ufoo, &foo, &foo, &foo, &ufoo,
903 self->shaped = (s != 0);
908 void client_update_transient_for(ObClient *self)
911 ObClient *target = NULL;
913 if (XGetTransientForHint(ob_display, self->window, &t)) {
914 self->transient = TRUE;
915 if (t != self->window) { /* cant be transient to itself! */
916 target = g_hash_table_lookup(window_map, &t);
917 /* if this happens then we need to check for it*/
918 g_assert(target != self);
919 if (target && !WINDOW_IS_CLIENT(target)) {
920 /* this can happen when a dialog is a child of
921 a dockapp, for example */
925 if (!target && self->group) {
926 /* not transient to a client, see if it is transient for a
928 if (t == self->group->leader ||
930 t == RootWindow(ob_display, ob_screen))
932 /* window is a transient for its group! */
933 target = OB_TRAN_GROUP;
937 } else if (self->type == OB_CLIENT_TYPE_DIALOG && self->group) {
938 self->transient = TRUE;
939 target = OB_TRAN_GROUP;
941 self->transient = FALSE;
943 /* if anything has changed... */
944 if (target != self->transient_for) {
945 if (self->transient_for == OB_TRAN_GROUP) { /* transient of group */
948 /* remove from old parents */
949 for (it = self->group->members; it; it = g_slist_next(it)) {
950 ObClient *c = it->data;
951 if (c != self && !c->transient_for)
952 c->transients = g_slist_remove(c->transients, self);
954 } else if (self->transient_for != NULL) { /* transient of window */
955 /* remove from old parent */
956 self->transient_for->transients =
957 g_slist_remove(self->transient_for->transients, self);
959 self->transient_for = target;
960 if (self->transient_for == OB_TRAN_GROUP) { /* transient of group */
963 /* add to new parents */
964 for (it = self->group->members; it; it = g_slist_next(it)) {
965 ObClient *c = it->data;
966 if (c != self && !c->transient_for)
967 c->transients = g_slist_append(c->transients, self);
970 /* remove all transients which are in the group, that causes
971 circlular pointer hell of doom */
972 for (it = self->group->members; it; it = g_slist_next(it)) {
974 for (sit = self->transients; sit; sit = next) {
975 next = g_slist_next(sit);
976 if (sit->data == it->data)
978 g_slist_delete_link(self->transients, sit);
981 } else if (self->transient_for != NULL) { /* transient of window */
982 /* add to new parent */
983 self->transient_for->transients =
984 g_slist_append(self->transient_for->transients, self);
989 static void client_get_mwm_hints(ObClient *self)
994 self->mwmhints.flags = 0; /* default to none */
996 if (PROP_GETA32(self->window, motif_wm_hints, motif_wm_hints,
998 if (num >= OB_MWM_ELEMENTS) {
999 self->mwmhints.flags = hints[0];
1000 self->mwmhints.functions = hints[1];
1001 self->mwmhints.decorations = hints[2];
1007 void client_get_type(ObClient *self)
1014 if (PROP_GETA32(self->window, net_wm_window_type, atom, &val, &num)) {
1015 /* use the first value that we know about in the array */
1016 for (i = 0; i < num; ++i) {
1017 if (val[i] == prop_atoms.net_wm_window_type_desktop)
1018 self->type = OB_CLIENT_TYPE_DESKTOP;
1019 else if (val[i] == prop_atoms.net_wm_window_type_dock)
1020 self->type = OB_CLIENT_TYPE_DOCK;
1021 else if (val[i] == prop_atoms.net_wm_window_type_toolbar)
1022 self->type = OB_CLIENT_TYPE_TOOLBAR;
1023 else if (val[i] == prop_atoms.net_wm_window_type_menu)
1024 self->type = OB_CLIENT_TYPE_MENU;
1025 else if (val[i] == prop_atoms.net_wm_window_type_utility)
1026 self->type = OB_CLIENT_TYPE_UTILITY;
1027 else if (val[i] == prop_atoms.net_wm_window_type_splash)
1028 self->type = OB_CLIENT_TYPE_SPLASH;
1029 else if (val[i] == prop_atoms.net_wm_window_type_dialog)
1030 self->type = OB_CLIENT_TYPE_DIALOG;
1031 else if (val[i] == prop_atoms.net_wm_window_type_normal)
1032 self->type = OB_CLIENT_TYPE_NORMAL;
1033 else if (val[i] == prop_atoms.kde_net_wm_window_type_override) {
1034 /* prevent this window from getting any decor or
1036 self->mwmhints.flags &= (OB_MWM_FLAG_FUNCTIONS |
1037 OB_MWM_FLAG_DECORATIONS);
1038 self->mwmhints.decorations = 0;
1039 self->mwmhints.functions = 0;
1041 if (self->type != (ObClientType) -1)
1042 break; /* grab the first legit type */
1047 if (self->type == (ObClientType) -1) {
1048 /*the window type hint was not set, which means we either classify
1049 ourself as a normal window or a dialog, depending on if we are a
1051 if (self->transient)
1052 self->type = OB_CLIENT_TYPE_DIALOG;
1054 self->type = OB_CLIENT_TYPE_NORMAL;
1058 void client_update_protocols(ObClient *self)
1061 guint num_return, i;
1063 self->focus_notify = FALSE;
1064 self->delete_window = FALSE;
1066 if (PROP_GETA32(self->window, wm_protocols, atom, &proto, &num_return)) {
1067 for (i = 0; i < num_return; ++i) {
1068 if (proto[i] == prop_atoms.wm_delete_window) {
1069 /* this means we can request the window to close */
1070 self->delete_window = TRUE;
1071 } else if (proto[i] == prop_atoms.wm_take_focus)
1072 /* if this protocol is requested, then the window will be
1073 notified whenever we want it to receive focus */
1074 self->focus_notify = TRUE;
1080 static void client_get_gravity(ObClient *self)
1082 XWindowAttributes wattrib;
1085 ret = XGetWindowAttributes(ob_display, self->window, &wattrib);
1086 g_assert(ret != BadWindow);
1087 self->gravity = wattrib.win_gravity;
1090 void client_update_normal_hints(ObClient *self)
1094 gint oldgravity = self->gravity;
1097 self->min_ratio = 0.0f;
1098 self->max_ratio = 0.0f;
1099 SIZE_SET(self->size_inc, 1, 1);
1100 SIZE_SET(self->base_size, 0, 0);
1101 SIZE_SET(self->min_size, 0, 0);
1102 SIZE_SET(self->max_size, G_MAXINT, G_MAXINT);
1104 /* get the hints from the window */
1105 if (XGetWMNormalHints(ob_display, self->window, &size, &ret)) {
1106 /* normal windows can't request placement! har har
1107 if (!client_normal(self))
1109 self->positioned = !!(size.flags & (PPosition|USPosition));
1111 if (size.flags & PWinGravity) {
1112 self->gravity = size.win_gravity;
1114 /* if the client has a frame, i.e. has already been mapped and
1115 is changing its gravity */
1116 if (self->frame && self->gravity != oldgravity) {
1117 /* move our idea of the client's position based on its new
1119 self->area.x = self->frame->area.x;
1120 self->area.y = self->frame->area.y;
1121 frame_frame_gravity(self->frame, &self->area.x, &self->area.y);
1125 if (size.flags & PAspect) {
1126 if (size.min_aspect.y)
1128 (gfloat) size.min_aspect.x / size.min_aspect.y;
1129 if (size.max_aspect.y)
1131 (gfloat) size.max_aspect.x / size.max_aspect.y;
1134 if (size.flags & PMinSize)
1135 SIZE_SET(self->min_size, size.min_width, size.min_height);
1137 if (size.flags & PMaxSize)
1138 SIZE_SET(self->max_size, size.max_width, size.max_height);
1140 if (size.flags & PBaseSize)
1141 SIZE_SET(self->base_size, size.base_width, size.base_height);
1143 if (size.flags & PResizeInc)
1144 SIZE_SET(self->size_inc, size.width_inc, size.height_inc);
1148 void client_setup_decor_and_functions(ObClient *self)
1150 /* start with everything (cept fullscreen) */
1152 (OB_FRAME_DECOR_TITLEBAR |
1153 (ob_rr_theme->show_handle ? OB_FRAME_DECOR_HANDLE : 0) |
1154 OB_FRAME_DECOR_GRIPS |
1155 OB_FRAME_DECOR_BORDER |
1156 OB_FRAME_DECOR_ICON |
1157 OB_FRAME_DECOR_ALLDESKTOPS |
1158 OB_FRAME_DECOR_ICONIFY |
1159 OB_FRAME_DECOR_MAXIMIZE |
1160 OB_FRAME_DECOR_SHADE |
1161 OB_FRAME_DECOR_CLOSE);
1163 (OB_CLIENT_FUNC_RESIZE |
1164 OB_CLIENT_FUNC_MOVE |
1165 OB_CLIENT_FUNC_ICONIFY |
1166 OB_CLIENT_FUNC_MAXIMIZE |
1167 OB_CLIENT_FUNC_SHADE |
1168 OB_CLIENT_FUNC_CLOSE);
1170 if (!(self->min_size.width < self->max_size.width ||
1171 self->min_size.height < self->max_size.height))
1172 self->functions &= ~OB_CLIENT_FUNC_RESIZE;
1174 switch (self->type) {
1175 case OB_CLIENT_TYPE_NORMAL:
1176 /* normal windows retain all of the possible decorations and
1177 functionality, and are the only windows that you can fullscreen */
1178 self->functions |= OB_CLIENT_FUNC_FULLSCREEN;
1181 case OB_CLIENT_TYPE_DIALOG:
1182 case OB_CLIENT_TYPE_UTILITY:
1183 /* these windows cannot be maximized */
1184 self->functions &= ~OB_CLIENT_FUNC_MAXIMIZE;
1187 case OB_CLIENT_TYPE_MENU:
1188 case OB_CLIENT_TYPE_TOOLBAR:
1189 /* these windows get less functionality */
1190 self->functions &= ~(OB_CLIENT_FUNC_ICONIFY | OB_CLIENT_FUNC_RESIZE);
1193 case OB_CLIENT_TYPE_DESKTOP:
1194 case OB_CLIENT_TYPE_DOCK:
1195 case OB_CLIENT_TYPE_SPLASH:
1196 /* none of these windows are manipulated by the window manager */
1197 self->decorations = 0;
1198 self->functions = 0;
1202 /* Mwm Hints are applied subtractively to what has already been chosen for
1203 decor and functionality */
1204 if (self->mwmhints.flags & OB_MWM_FLAG_DECORATIONS) {
1205 if (! (self->mwmhints.decorations & OB_MWM_DECOR_ALL)) {
1206 if (! ((self->mwmhints.decorations & OB_MWM_DECOR_HANDLE) ||
1207 (self->mwmhints.decorations & OB_MWM_DECOR_TITLE)))
1208 /* if the mwm hints request no handle or title, then all
1209 decorations are disabled */
1210 self->decorations = 0;
1214 if (self->mwmhints.flags & OB_MWM_FLAG_FUNCTIONS) {
1215 if (! (self->mwmhints.functions & OB_MWM_FUNC_ALL)) {
1216 if (! (self->mwmhints.functions & OB_MWM_FUNC_RESIZE))
1217 self->functions &= ~OB_CLIENT_FUNC_RESIZE;
1218 if (! (self->mwmhints.functions & OB_MWM_FUNC_MOVE))
1219 self->functions &= ~OB_CLIENT_FUNC_MOVE;
1220 /* dont let mwm hints kill any buttons
1221 if (! (self->mwmhints.functions & OB_MWM_FUNC_ICONIFY))
1222 self->functions &= ~OB_CLIENT_FUNC_ICONIFY;
1223 if (! (self->mwmhints.functions & OB_MWM_FUNC_MAXIMIZE))
1224 self->functions &= ~OB_CLIENT_FUNC_MAXIMIZE;
1226 /* dont let mwm hints kill the close button
1227 if (! (self->mwmhints.functions & MwmFunc_Close))
1228 self->functions &= ~OB_CLIENT_FUNC_CLOSE; */
1232 if (!(self->functions & OB_CLIENT_FUNC_SHADE))
1233 self->decorations &= ~OB_FRAME_DECOR_SHADE;
1234 if (!(self->functions & OB_CLIENT_FUNC_ICONIFY))
1235 self->decorations &= ~OB_FRAME_DECOR_ICONIFY;
1236 if (!(self->functions & OB_CLIENT_FUNC_RESIZE))
1237 self->decorations &= ~OB_FRAME_DECOR_GRIPS;
1239 /* can't maximize without moving/resizing */
1240 if (!((self->functions & OB_CLIENT_FUNC_MAXIMIZE) &&
1241 (self->functions & OB_CLIENT_FUNC_MOVE) &&
1242 (self->functions & OB_CLIENT_FUNC_RESIZE))) {
1243 self->functions &= ~OB_CLIENT_FUNC_MAXIMIZE;
1244 self->decorations &= ~OB_FRAME_DECOR_MAXIMIZE;
1247 /* kill the handle on fully maxed windows */
1248 if (self->max_vert && self->max_horz)
1249 self->decorations &= ~OB_FRAME_DECOR_HANDLE;
1251 /* finally, the user can have requested no decorations, which overrides
1252 everything (but doesnt give it a border if it doesnt have one) */
1253 if (self->undecorated) {
1254 if (config_theme_keepborder)
1255 self->decorations &= OB_FRAME_DECOR_BORDER;
1257 self->decorations = 0;
1260 /* if we don't have a titlebar, then we cannot shade! */
1261 if (!(self->decorations & OB_FRAME_DECOR_TITLEBAR))
1262 self->functions &= ~OB_CLIENT_FUNC_SHADE;
1264 /* now we need to check against rules for the client's current state */
1265 if (self->fullscreen) {
1266 self->functions &= (OB_CLIENT_FUNC_CLOSE |
1267 OB_CLIENT_FUNC_FULLSCREEN |
1268 OB_CLIENT_FUNC_ICONIFY);
1269 self->decorations = 0;
1272 client_change_allowed_actions(self);
1275 /* adjust the client's decorations, etc. */
1276 client_reconfigure(self);
1280 static void client_change_allowed_actions(ObClient *self)
1285 /* desktop windows are kept on all desktops */
1286 if (self->type != OB_CLIENT_TYPE_DESKTOP)
1287 actions[num++] = prop_atoms.net_wm_action_change_desktop;
1289 if (self->functions & OB_CLIENT_FUNC_SHADE)
1290 actions[num++] = prop_atoms.net_wm_action_shade;
1291 if (self->functions & OB_CLIENT_FUNC_CLOSE)
1292 actions[num++] = prop_atoms.net_wm_action_close;
1293 if (self->functions & OB_CLIENT_FUNC_MOVE)
1294 actions[num++] = prop_atoms.net_wm_action_move;
1295 if (self->functions & OB_CLIENT_FUNC_ICONIFY)
1296 actions[num++] = prop_atoms.net_wm_action_minimize;
1297 if (self->functions & OB_CLIENT_FUNC_RESIZE)
1298 actions[num++] = prop_atoms.net_wm_action_resize;
1299 if (self->functions & OB_CLIENT_FUNC_FULLSCREEN)
1300 actions[num++] = prop_atoms.net_wm_action_fullscreen;
1301 if (self->functions & OB_CLIENT_FUNC_MAXIMIZE) {
1302 actions[num++] = prop_atoms.net_wm_action_maximize_horz;
1303 actions[num++] = prop_atoms.net_wm_action_maximize_vert;
1306 PROP_SETA32(self->window, net_wm_allowed_actions, atom, actions, num);
1308 /* make sure the window isn't breaking any rules now */
1310 if (!(self->functions & OB_CLIENT_FUNC_SHADE) && self->shaded) {
1311 if (self->frame) client_shade(self, FALSE);
1312 else self->shaded = FALSE;
1314 if (!(self->functions & OB_CLIENT_FUNC_ICONIFY) && self->iconic) {
1315 if (self->frame) client_iconify(self, FALSE, TRUE);
1316 else self->iconic = FALSE;
1318 if (!(self->functions & OB_CLIENT_FUNC_FULLSCREEN) && self->fullscreen) {
1319 if (self->frame) client_fullscreen(self, FALSE, TRUE);
1320 else self->fullscreen = FALSE;
1322 if (!(self->functions & OB_CLIENT_FUNC_MAXIMIZE) && (self->max_horz ||
1324 if (self->frame) client_maximize(self, FALSE, 0, TRUE);
1325 else self->max_vert = self->max_horz = FALSE;
1329 void client_reconfigure(ObClient *self)
1331 /* by making this pass FALSE for user, we avoid the emacs event storm where
1332 every configurenotify causes an update in its normal hints, i think this
1333 is generally what we want anyways... */
1334 client_configure(self, OB_CORNER_TOPLEFT, self->area.x, self->area.y,
1335 self->area.width, self->area.height, FALSE, TRUE);
1338 void client_update_wmhints(ObClient *self)
1341 gboolean ur = FALSE;
1344 /* assume a window takes input if it doesnt specify */
1345 self->can_focus = TRUE;
1347 if ((hints = XGetWMHints(ob_display, self->window)) != NULL) {
1348 if (hints->flags & InputHint)
1349 self->can_focus = hints->input;
1351 /* only do this when first managing the window *AND* when we aren't
1353 if (ob_state() != OB_STATE_STARTING && self->frame == NULL)
1354 if (hints->flags & StateHint)
1355 self->iconic = hints->initial_state == IconicState;
1357 if (hints->flags & XUrgencyHint)
1360 if (!(hints->flags & WindowGroupHint))
1361 hints->window_group = None;
1363 /* did the group state change? */
1364 if (hints->window_group !=
1365 (self->group ? self->group->leader : None)) {
1366 /* remove from the old group if there was one */
1367 if (self->group != NULL) {
1368 /* remove transients of the group */
1369 for (it = self->group->members; it; it = g_slist_next(it))
1370 self->transients = g_slist_remove(self->transients,
1373 /* remove myself from parents in the group */
1374 if (self->transient_for == OB_TRAN_GROUP) {
1375 for (it = self->group->members; it;
1376 it = g_slist_next(it))
1378 ObClient *c = it->data;
1380 if (c != self && !c->transient_for)
1381 c->transients = g_slist_remove(c->transients,
1386 group_remove(self->group, self);
1389 if (hints->window_group != None) {
1390 self->group = group_add(hints->window_group, self);
1392 /* i can only have transients from the group if i am not
1394 if (!self->transient_for) {
1395 /* add other transients of the group that are already
1397 for (it = self->group->members; it;
1398 it = g_slist_next(it))
1400 ObClient *c = it->data;
1401 if (c != self && c->transient_for == OB_TRAN_GROUP)
1403 g_slist_append(self->transients, c);
1408 /* because the self->transient flag wont change from this call,
1409 we don't need to update the window's type and such, only its
1410 transient_for, and the transients lists of other windows in
1411 the group may be affected */
1412 client_update_transient_for(self);
1415 /* the WM_HINTS can contain an icon */
1416 client_update_icons(self);
1421 if (ur != self->urgent) {
1423 /* fire the urgent callback if we're mapped, otherwise, wait until
1424 after we're mapped */
1426 client_urgent_notify(self);
1430 void client_update_title(ObClient *self)
1436 gboolean read_title;
1439 old_title = self->title;
1442 if (!PROP_GETS(self->window, net_wm_name, utf8, &data)) {
1443 /* try old x stuff */
1444 if (!PROP_GETS(self->window, wm_name, locale, &data)) {
1445 // http://developer.gnome.org/projects/gup/hig/draft_hig_new/windows-alert.html
1446 if (self->transient) {
1447 data = g_strdup("");
1450 data = g_strdup("Unnamed Window");
1454 /* did the title change? then reset the title_count */
1455 if (old_title && 0 != strncmp(old_title, data, strlen(data)))
1456 self->title_count = 1;
1458 /* look for duplicates and append a number */
1460 for (it = client_list; it; it = g_list_next(it))
1461 if (it->data != self) {
1462 ObClient *c = it->data;
1463 if (0 == strncmp(c->title, data, strlen(data)))
1464 nums |= 1 << c->title_count;
1466 /* find first free number */
1467 for (i = 1; i <= 32; ++i)
1468 if (!(nums & (1 << i))) {
1469 if (self->title_count == 1 || i == 1)
1470 self->title_count = i;
1473 /* dont display the number for the first window */
1474 if (self->title_count > 1) {
1476 ndata = g_strdup_printf("%s - [%u]", data, self->title_count);
1481 PROP_SETS(self->window, net_wm_visible_name, data);
1486 frame_adjust_title(self->frame);
1490 /* update the icon title */
1492 g_free(self->icon_title);
1496 if (!PROP_GETS(self->window, net_wm_icon_name, utf8, &data))
1497 /* try old x stuff */
1498 if (!PROP_GETS(self->window, wm_icon_name, locale, &data)) {
1499 data = g_strdup(self->title);
1503 /* append the title count, dont display the number for the first window */
1504 if (read_title && self->title_count > 1) {
1505 gchar *vdata, *ndata;
1506 ndata = g_strdup_printf(" - [%u]", self->title_count);
1507 vdata = g_strconcat(data, ndata, NULL);
1513 PROP_SETS(self->window, net_wm_visible_icon_name, data);
1515 self->icon_title = data;
1518 void client_update_class(ObClient *self)
1523 if (self->name) g_free(self->name);
1524 if (self->class) g_free(self->class);
1525 if (self->role) g_free(self->role);
1527 self->name = self->class = self->role = NULL;
1529 if (PROP_GETSS(self->window, wm_class, locale, &data)) {
1531 self->name = g_strdup(data[0]);
1533 self->class = g_strdup(data[1]);
1538 if (PROP_GETS(self->window, wm_window_role, locale, &s))
1541 if (self->name == NULL) self->name = g_strdup("");
1542 if (self->class == NULL) self->class = g_strdup("");
1543 if (self->role == NULL) self->role = g_strdup("");
1546 void client_update_strut(ObClient *self)
1550 gboolean got = FALSE;
1553 if (PROP_GETA32(self->window, net_wm_strut_partial, cardinal,
1557 STRUT_PARTIAL_SET(strut,
1558 data[0], data[2], data[1], data[3],
1559 data[4], data[5], data[8], data[9],
1560 data[6], data[7], data[10], data[11]);
1566 PROP_GETA32(self->window, net_wm_strut, cardinal, &data, &num)) {
1572 /* use the screen's width/height */
1573 a = screen_physical_area();
1575 STRUT_PARTIAL_SET(strut,
1576 data[0], data[2], data[1], data[3],
1577 a->y, a->y + a->height - 1,
1578 a->x, a->x + a->width - 1,
1579 a->y, a->y + a->height - 1,
1580 a->x, a->x + a->width - 1);
1586 STRUT_PARTIAL_SET(strut, 0, 0, 0, 0,
1587 0, 0, 0, 0, 0, 0, 0, 0);
1589 if (!STRUT_EQUAL(strut, self->strut)) {
1590 self->strut = strut;
1592 /* updating here is pointless while we're being mapped cuz we're not in
1593 the client list yet */
1595 screen_update_areas();
1599 void client_update_icons(ObClient *self)
1605 for (i = 0; i < self->nicons; ++i)
1606 g_free(self->icons[i].data);
1607 if (self->nicons > 0)
1608 g_free(self->icons);
1611 if (PROP_GETA32(self->window, net_wm_icon, cardinal, &data, &num)) {
1612 /* figure out how many valid icons are in here */
1614 while (num - i > 2) {
1618 if (i > num || w*h == 0) break;
1622 self->icons = g_new(ObClientIcon, self->nicons);
1624 /* store the icons */
1626 for (j = 0; j < self->nicons; ++j) {
1629 w = self->icons[j].width = data[i++];
1630 h = self->icons[j].height = data[i++];
1632 if (w*h == 0) continue;
1634 self->icons[j].data = g_new(RrPixel32, w * h);
1635 for (x = 0, y = 0, t = 0; t < w * h; ++t, ++x, ++i) {
1640 self->icons[j].data[t] =
1641 (((data[i] >> 24) & 0xff) << RrDefaultAlphaOffset) +
1642 (((data[i] >> 16) & 0xff) << RrDefaultRedOffset) +
1643 (((data[i] >> 8) & 0xff) << RrDefaultGreenOffset) +
1644 (((data[i] >> 0) & 0xff) << RrDefaultBlueOffset);
1650 } else if (PROP_GETA32(self->window, kwm_win_icon,
1651 kwm_win_icon, &data, &num)) {
1654 self->icons = g_new(ObClientIcon, self->nicons);
1655 xerror_set_ignore(TRUE);
1656 if (!RrPixmapToRGBA(ob_rr_inst,
1658 &self->icons[self->nicons-1].width,
1659 &self->icons[self->nicons-1].height,
1660 &self->icons[self->nicons-1].data)) {
1661 g_free(&self->icons[self->nicons-1]);
1664 xerror_set_ignore(FALSE);
1670 if ((hints = XGetWMHints(ob_display, self->window))) {
1671 if (hints->flags & IconPixmapHint) {
1673 self->icons = g_new(ObClientIcon, self->nicons);
1674 xerror_set_ignore(TRUE);
1675 if (!RrPixmapToRGBA(ob_rr_inst,
1677 (hints->flags & IconMaskHint ?
1678 hints->icon_mask : None),
1679 &self->icons[self->nicons-1].width,
1680 &self->icons[self->nicons-1].height,
1681 &self->icons[self->nicons-1].data)){
1682 g_free(&self->icons[self->nicons-1]);
1685 xerror_set_ignore(FALSE);
1692 frame_adjust_icon(self->frame);
1695 static void client_change_state(ObClient *self)
1698 guint32 netstate[11];
1701 state[0] = self->wmstate;
1703 PROP_SETA32(self->window, wm_state, wm_state, state, 2);
1707 netstate[num++] = prop_atoms.net_wm_state_modal;
1709 netstate[num++] = prop_atoms.net_wm_state_shaded;
1711 netstate[num++] = prop_atoms.net_wm_state_hidden;
1712 if (self->skip_taskbar)
1713 netstate[num++] = prop_atoms.net_wm_state_skip_taskbar;
1714 if (self->skip_pager)
1715 netstate[num++] = prop_atoms.net_wm_state_skip_pager;
1716 if (self->fullscreen)
1717 netstate[num++] = prop_atoms.net_wm_state_fullscreen;
1719 netstate[num++] = prop_atoms.net_wm_state_maximized_vert;
1721 netstate[num++] = prop_atoms.net_wm_state_maximized_horz;
1723 netstate[num++] = prop_atoms.net_wm_state_above;
1725 netstate[num++] = prop_atoms.net_wm_state_below;
1726 if (self->undecorated)
1727 netstate[num++] = prop_atoms.ob_wm_state_undecorated;
1728 PROP_SETA32(self->window, net_wm_state, atom, netstate, num);
1730 client_calc_layer(self);
1733 frame_adjust_state(self->frame);
1736 ObClient *client_search_focus_tree(ObClient *self)
1741 for (it = self->transients; it; it = g_slist_next(it)) {
1742 if (client_focused(it->data)) return it->data;
1743 if ((ret = client_search_focus_tree(it->data))) return ret;
1748 ObClient *client_search_focus_tree_full(ObClient *self)
1750 if (self->transient_for) {
1751 if (self->transient_for != OB_TRAN_GROUP) {
1752 return client_search_focus_tree_full(self->transient_for);
1755 gboolean recursed = FALSE;
1757 for (it = self->group->members; it; it = g_slist_next(it))
1758 if (!((ObClient*)it->data)->transient_for) {
1760 if ((c = client_search_focus_tree_full(it->data)))
1769 /* this function checks the whole tree, the client_search_focus_tree~
1770 does not, so we need to check this window */
1771 if (client_focused(self))
1773 return client_search_focus_tree(self);
1776 static ObStackingLayer calc_layer(ObClient *self)
1780 if (self->fullscreen &&
1781 (client_focused(self) || client_search_focus_tree(self)))
1782 l = OB_STACKING_LAYER_FULLSCREEN;
1783 else if (self->type == OB_CLIENT_TYPE_DESKTOP)
1784 l = OB_STACKING_LAYER_DESKTOP;
1785 else if (self->type == OB_CLIENT_TYPE_DOCK) {
1786 if (self->above) l = OB_STACKING_LAYER_DOCK_ABOVE;
1787 else if (self->below) l = OB_STACKING_LAYER_DOCK_BELOW;
1788 else l = OB_STACKING_LAYER_DOCK_NORMAL;
1790 else if (self->above) l = OB_STACKING_LAYER_ABOVE;
1791 else if (self->below) l = OB_STACKING_LAYER_BELOW;
1792 else l = OB_STACKING_LAYER_NORMAL;
1797 static void client_calc_layer_recursive(ObClient *self, ObClient *orig,
1798 ObStackingLayer l, gboolean raised)
1800 ObStackingLayer old, own;
1804 own = calc_layer(self);
1805 self->layer = l > own ? l : own;
1807 for (it = self->transients; it; it = g_slist_next(it))
1808 client_calc_layer_recursive(it->data, orig,
1809 l, raised ? raised : l != old);
1811 if (!raised && l != old)
1812 if (orig->frame) { /* only restack if the original window is managed */
1813 stacking_remove(CLIENT_AS_WINDOW(self));
1814 stacking_add(CLIENT_AS_WINDOW(self));
1818 void client_calc_layer(ObClient *self)
1825 /* transients take on the layer of their parents */
1826 self = client_search_top_transient(self);
1828 l = calc_layer(self);
1830 client_calc_layer_recursive(self, orig, l, FALSE);
1833 gboolean client_should_show(ObClient *self)
1837 if (client_normal(self) && screen_showing_desktop)
1840 if (self->transient_for) {
1841 if (self->transient_for != OB_TRAN_GROUP)
1842 return client_should_show(self->transient_for);
1846 for (it = self->group->members; it; it = g_slist_next(it)) {
1847 ObClient *c = it->data;
1848 if (c != self && !c->transient_for) {
1849 if (client_should_show(c))
1856 if (self->desktop == screen_desktop || self->desktop == DESKTOP_ALL)
1862 static void client_showhide(ObClient *self)
1865 if (client_should_show(self))
1866 frame_show(self->frame);
1868 frame_hide(self->frame);
1871 gboolean client_normal(ObClient *self) {
1872 return ! (self->type == OB_CLIENT_TYPE_DESKTOP ||
1873 self->type == OB_CLIENT_TYPE_DOCK ||
1874 self->type == OB_CLIENT_TYPE_SPLASH);
1877 static void client_apply_startup_state(ObClient *self)
1879 /* these are in a carefully crafted order.. */
1882 self->iconic = FALSE;
1883 client_iconify(self, TRUE, FALSE);
1885 if (self->fullscreen) {
1886 self->fullscreen = FALSE;
1887 client_fullscreen(self, TRUE, FALSE);
1889 if (self->undecorated) {
1890 self->undecorated = FALSE;
1891 client_set_undecorated(self, TRUE);
1894 self->shaded = FALSE;
1895 client_shade(self, TRUE);
1898 client_urgent_notify(self);
1900 if (self->max_vert && self->max_horz) {
1901 self->max_vert = self->max_horz = FALSE;
1902 client_maximize(self, TRUE, 0, FALSE);
1903 } else if (self->max_vert) {
1904 self->max_vert = FALSE;
1905 client_maximize(self, TRUE, 2, FALSE);
1906 } else if (self->max_horz) {
1907 self->max_horz = FALSE;
1908 client_maximize(self, TRUE, 1, FALSE);
1911 /* nothing to do for the other states:
1920 void client_configure_full(ObClient *self, ObCorner anchor,
1921 gint x, gint y, gint w, gint h,
1922 gboolean user, gboolean final,
1923 gboolean force_reply)
1926 gboolean send_resize_client;
1927 gboolean moved = FALSE, resized = FALSE;
1928 guint fdecor = self->frame->decorations;
1929 gboolean fhorz = self->frame->max_horz;
1931 /* make the frame recalculate its dimentions n shit without changing
1932 anything visible for real, this way the constraints below can work with
1933 the updated frame dimensions. */
1934 frame_adjust_area(self->frame, TRUE, TRUE, TRUE);
1936 /* gets the frame's position */
1937 frame_client_gravity(self->frame, &x, &y);
1939 /* these positions are frame positions, not client positions */
1941 /* set the size and position if fullscreen */
1942 if (self->fullscreen) {
1945 XF86VidModeModeLine mode;
1950 i = client_monitor(self);
1951 a = screen_physical_area_monitor(i);
1954 if (i == 0 && /* primary head */
1955 extensions_vidmode &&
1956 XF86VidModeGetViewPort(ob_display, ob_screen, &x, &y) &&
1957 /* get the mode last so the mode.privsize isnt freed incorrectly */
1958 XF86VidModeGetModeLine(ob_display, ob_screen, &dot, &mode)) {
1963 if (mode.privsize) XFree(mode.private);
1973 user = FALSE; /* ignore that increment etc shit when in fullscreen */
1977 a = screen_area_monitor(self->desktop, client_monitor(self));
1979 /* set the size and position if maximized */
1980 if (self->max_horz) {
1982 w = a->width - self->frame->size.left - self->frame->size.right;
1984 if (self->max_vert) {
1986 h = a->height - self->frame->size.top - self->frame->size.bottom;
1990 /* gets the client's position */
1991 frame_frame_gravity(self->frame, &x, &y);
1993 /* these override the above states! if you cant move you can't move! */
1995 if (!(self->functions & OB_CLIENT_FUNC_MOVE)) {
1999 if (!(self->functions & OB_CLIENT_FUNC_RESIZE)) {
2000 w = self->area.width;
2001 h = self->area.height;
2005 if (!(w == self->area.width && h == self->area.height)) {
2006 gint basew, baseh, minw, minh;
2008 /* base size is substituted with min size if not specified */
2009 if (self->base_size.width || self->base_size.height) {
2010 basew = self->base_size.width;
2011 baseh = self->base_size.height;
2013 basew = self->min_size.width;
2014 baseh = self->min_size.height;
2016 /* min size is substituted with base size if not specified */
2017 if (self->min_size.width || self->min_size.height) {
2018 minw = self->min_size.width;
2019 minh = self->min_size.height;
2021 minw = self->base_size.width;
2022 minh = self->base_size.height;
2025 /* if this is a user-requested resize, then check against min/max
2028 /* smaller than min size or bigger than max size? */
2029 if (w > self->max_size.width) w = self->max_size.width;
2030 if (w < minw) w = minw;
2031 if (h > self->max_size.height) h = self->max_size.height;
2032 if (h < minh) h = minh;
2037 /* keep to the increments */
2038 w /= self->size_inc.width;
2039 h /= self->size_inc.height;
2041 /* you cannot resize to nothing */
2042 if (basew + w < 1) w = 1 - basew;
2043 if (baseh + h < 1) h = 1 - baseh;
2045 /* store the logical size */
2046 SIZE_SET(self->logical_size,
2047 self->size_inc.width > 1 ? w : w + basew,
2048 self->size_inc.height > 1 ? h : h + baseh);
2050 w *= self->size_inc.width;
2051 h *= self->size_inc.height;
2056 /* adjust the height to match the width for the aspect ratios.
2057 for this, min size is not substituted for base size ever. */
2058 w -= self->base_size.width;
2059 h -= self->base_size.height;
2061 if (!self->fullscreen) {
2062 if (self->min_ratio)
2063 if (h * self->min_ratio > w) {
2064 h = (gint)(w / self->min_ratio);
2066 /* you cannot resize to nothing */
2069 w = (gint)(h * self->min_ratio);
2072 if (self->max_ratio)
2073 if (h * self->max_ratio < w) {
2074 h = (gint)(w / self->max_ratio);
2076 /* you cannot resize to nothing */
2079 w = (gint)(h * self->min_ratio);
2084 w += self->base_size.width;
2085 h += self->base_size.height;
2092 case OB_CORNER_TOPLEFT:
2094 case OB_CORNER_TOPRIGHT:
2095 x -= w - self->area.width;
2097 case OB_CORNER_BOTTOMLEFT:
2098 y -= h - self->area.height;
2100 case OB_CORNER_BOTTOMRIGHT:
2101 x -= w - self->area.width;
2102 y -= h - self->area.height;
2106 moved = x != self->area.x || y != self->area.y;
2107 resized = w != self->area.width || h != self->area.height;
2109 oldw = self->area.width;
2110 oldh = self->area.height;
2111 RECT_SET(self->area, x, y, w, h);
2113 /* for app-requested resizes, always resize if 'resized' is true.
2114 for user-requested ones, only resize if final is true, or when
2115 resizing in redraw mode */
2116 send_resize_client = ((!user && resized) ||
2118 (resized && config_resize_redraw))));
2120 /* if the client is enlarging, then resize the client before the frame */
2121 if (send_resize_client && user && (w > oldw || h > oldh))
2122 XResizeWindow(ob_display, self->window, MAX(w, oldw), MAX(h, oldh));
2124 /* move/resize the frame to match the request */
2126 if (self->decorations != fdecor || self->max_horz != fhorz)
2127 moved = resized = TRUE;
2129 if (moved || resized)
2130 frame_adjust_area(self->frame, moved, resized, FALSE);
2132 if (!resized && (force_reply || ((!user && moved) || (user && final))))
2135 event.type = ConfigureNotify;
2136 event.xconfigure.display = ob_display;
2137 event.xconfigure.event = self->window;
2138 event.xconfigure.window = self->window;
2140 /* root window real coords */
2141 event.xconfigure.x = self->frame->area.x + self->frame->size.left -
2143 event.xconfigure.y = self->frame->area.y + self->frame->size.top -
2145 event.xconfigure.width = w;
2146 event.xconfigure.height = h;
2147 event.xconfigure.border_width = 0;
2148 event.xconfigure.above = self->frame->plate;
2149 event.xconfigure.override_redirect = FALSE;
2150 XSendEvent(event.xconfigure.display, event.xconfigure.window,
2151 FALSE, StructureNotifyMask, &event);
2155 /* if the client is shrinking, then resize the frame before the client */
2156 if (send_resize_client && (!user || (w <= oldw || h <= oldh)))
2157 XResizeWindow(ob_display, self->window, w, h);
2162 void client_fullscreen(ObClient *self, gboolean fs, gboolean savearea)
2166 if (!(self->functions & OB_CLIENT_FUNC_FULLSCREEN) || /* can't */
2167 self->fullscreen == fs) return; /* already done */
2169 self->fullscreen = fs;
2170 client_change_state(self); /* change the state hints on the client,
2171 and adjust out layer/stacking */
2175 self->pre_fullscreen_area = self->area;
2177 /* these are not actually used cuz client_configure will set them
2178 as appropriate when the window is fullscreened */
2183 if (self->pre_fullscreen_area.width > 0 &&
2184 self->pre_fullscreen_area.height > 0)
2186 x = self->pre_fullscreen_area.x;
2187 y = self->pre_fullscreen_area.y;
2188 w = self->pre_fullscreen_area.width;
2189 h = self->pre_fullscreen_area.height;
2190 RECT_SET(self->pre_fullscreen_area, 0, 0, 0, 0);
2192 /* pick some fallbacks... */
2193 a = screen_area_monitor(self->desktop, 0);
2194 x = a->x + a->width / 4;
2195 y = a->y + a->height / 4;
2201 client_setup_decor_and_functions(self);
2203 client_move_resize(self, x, y, w, h);
2205 /* try focus us when we go into fullscreen mode */
2209 static void client_iconify_recursive(ObClient *self,
2210 gboolean iconic, gboolean curdesk)
2213 gboolean changed = FALSE;
2216 if (self->iconic != iconic) {
2217 ob_debug("%sconifying window: 0x%lx\n", (iconic ? "I" : "Uni"),
2220 self->iconic = iconic;
2223 if (self->functions & OB_CLIENT_FUNC_ICONIFY) {
2226 old = self->wmstate;
2227 self->wmstate = IconicState;
2228 if (old != self->wmstate)
2229 PROP_MSG(self->window, kde_wm_change_state,
2230 self->wmstate, 1, 0, 0);
2232 /* update the focus lists.. iconic windows go to the bottom of
2233 the list, put the new iconic window at the 'top of the
2235 focus_order_to_top(self);
2243 client_set_desktop(self, screen_desktop, FALSE);
2245 old = self->wmstate;
2246 self->wmstate = self->shaded ? IconicState : NormalState;
2247 if (old != self->wmstate)
2248 PROP_MSG(self->window, kde_wm_change_state,
2249 self->wmstate, 1, 0, 0);
2251 /* this puts it after the current focused window */
2252 focus_order_remove(self);
2253 focus_order_add_new(self);
2255 /* this is here cuz with the VIDMODE extension, the viewport can
2256 change while a fullscreen window is iconic, and when it
2257 uniconifies, it would be nice if it did so to the new position
2259 client_reconfigure(self);
2266 client_change_state(self);
2267 client_showhide(self);
2268 screen_update_areas();
2271 /* iconify all transients */
2272 for (it = self->transients; it; it = g_slist_next(it))
2273 if (it->data != self) client_iconify_recursive(it->data,
2277 void client_iconify(ObClient *self, gboolean iconic, gboolean curdesk)
2279 /* move up the transient chain as far as possible first */
2280 self = client_search_top_transient(self);
2282 client_iconify_recursive(client_search_top_transient(self),
2286 void client_maximize(ObClient *self, gboolean max, gint dir, gboolean savearea)
2290 g_assert(dir == 0 || dir == 1 || dir == 2);
2291 if (!(self->functions & OB_CLIENT_FUNC_MAXIMIZE)) return; /* can't */
2293 /* check if already done */
2295 if (dir == 0 && self->max_horz && self->max_vert) return;
2296 if (dir == 1 && self->max_horz) return;
2297 if (dir == 2 && self->max_vert) return;
2299 if (dir == 0 && !self->max_horz && !self->max_vert) return;
2300 if (dir == 1 && !self->max_horz) return;
2301 if (dir == 2 && !self->max_vert) return;
2304 /* we just tell it to configure in the same place and client_configure
2305 worries about filling the screen with the window */
2308 w = self->area.width;
2309 h = self->area.height;
2313 if ((dir == 0 || dir == 1) && !self->max_horz) { /* horz */
2314 RECT_SET(self->pre_max_area,
2315 self->area.x, self->pre_max_area.y,
2316 self->area.width, self->pre_max_area.height);
2318 if ((dir == 0 || dir == 2) && !self->max_vert) { /* vert */
2319 RECT_SET(self->pre_max_area,
2320 self->pre_max_area.x, self->area.y,
2321 self->pre_max_area.width, self->area.height);
2327 a = screen_area_monitor(self->desktop, 0);
2328 if ((dir == 0 || dir == 1) && self->max_horz) { /* horz */
2329 if (self->pre_max_area.width > 0) {
2330 x = self->pre_max_area.x;
2331 w = self->pre_max_area.width;
2333 RECT_SET(self->pre_max_area, 0, self->pre_max_area.y,
2334 0, self->pre_max_area.height);
2336 /* pick some fallbacks... */
2337 x = a->x + a->width / 4;
2341 if ((dir == 0 || dir == 2) && self->max_vert) { /* vert */
2342 if (self->pre_max_area.height > 0) {
2343 y = self->pre_max_area.y;
2344 h = self->pre_max_area.height;
2346 RECT_SET(self->pre_max_area, self->pre_max_area.x, 0,
2347 self->pre_max_area.width, 0);
2349 /* pick some fallbacks... */
2350 y = a->y + a->height / 4;
2356 if (dir == 0 || dir == 1) /* horz */
2357 self->max_horz = max;
2358 if (dir == 0 || dir == 2) /* vert */
2359 self->max_vert = max;
2361 client_change_state(self); /* change the state hints on the client */
2363 client_setup_decor_and_functions(self);
2365 client_move_resize(self, x, y, w, h);
2368 void client_shade(ObClient *self, gboolean shade)
2370 if ((!(self->functions & OB_CLIENT_FUNC_SHADE) &&
2371 shade) || /* can't shade */
2372 self->shaded == shade) return; /* already done */
2374 /* when we're iconic, don't change the wmstate */
2375 if (!self->iconic) {
2378 old = self->wmstate;
2379 self->wmstate = shade ? IconicState : NormalState;
2380 if (old != self->wmstate)
2381 PROP_MSG(self->window, kde_wm_change_state,
2382 self->wmstate, 1, 0, 0);
2385 self->shaded = shade;
2386 client_change_state(self);
2387 /* resize the frame to just the titlebar */
2388 frame_adjust_area(self->frame, FALSE, FALSE, FALSE);
2391 void client_close(ObClient *self)
2395 if (!(self->functions & OB_CLIENT_FUNC_CLOSE)) return;
2397 /* in the case that the client provides no means to requesting that it
2398 close, we just kill it */
2399 if (!self->delete_window)
2403 XXX: itd be cool to do timeouts and shit here for killing the client's
2405 like... if the window is around after 5 seconds, then the close button
2406 turns a nice red, and if this function is called again, the client is
2410 ce.xclient.type = ClientMessage;
2411 ce.xclient.message_type = prop_atoms.wm_protocols;
2412 ce.xclient.display = ob_display;
2413 ce.xclient.window = self->window;
2414 ce.xclient.format = 32;
2415 ce.xclient.data.l[0] = prop_atoms.wm_delete_window;
2416 ce.xclient.data.l[1] = event_lasttime;
2417 ce.xclient.data.l[2] = 0l;
2418 ce.xclient.data.l[3] = 0l;
2419 ce.xclient.data.l[4] = 0l;
2420 XSendEvent(ob_display, self->window, FALSE, NoEventMask, &ce);
2423 void client_kill(ObClient *self)
2425 XKillClient(ob_display, self->window);
2428 void client_set_desktop_recursive(ObClient *self,
2429 guint target, gboolean donthide)
2434 if (target != self->desktop) {
2436 ob_debug("Setting desktop %u\n", target+1);
2438 g_assert(target < screen_num_desktops || target == DESKTOP_ALL);
2440 /* remove from the old desktop(s) */
2441 focus_order_remove(self);
2443 old = self->desktop;
2444 self->desktop = target;
2445 PROP_SET32(self->window, net_wm_desktop, cardinal, target);
2446 /* the frame can display the current desktop state */
2447 frame_adjust_state(self->frame);
2448 /* 'move' the window to the new desktop */
2450 client_showhide(self);
2451 /* raise if it was not already on the desktop */
2452 if (old != DESKTOP_ALL)
2454 screen_update_areas();
2456 /* add to the new desktop(s) */
2457 if (config_focus_new)
2458 focus_order_to_top(self);
2460 focus_order_to_bottom(self);
2463 /* move all transients */
2464 for (it = self->transients; it; it = g_slist_next(it))
2465 if (it->data != self) client_set_desktop_recursive(it->data,
2469 void client_set_desktop(ObClient *self, guint target, gboolean donthide)
2471 client_set_desktop_recursive(client_search_top_transient(self),
2475 ObClient *client_search_modal_child(ObClient *self)
2480 for (it = self->transients; it; it = g_slist_next(it)) {
2481 ObClient *c = it->data;
2482 if ((ret = client_search_modal_child(c))) return ret;
2483 if (c->modal) return c;
2488 gboolean client_validate(ObClient *self)
2492 XSync(ob_display, FALSE); /* get all events on the server */
2494 if (XCheckTypedWindowEvent(ob_display, self->window, DestroyNotify, &e) ||
2495 XCheckTypedWindowEvent(ob_display, self->window, UnmapNotify, &e)) {
2496 XPutBackEvent(ob_display, &e);
2503 void client_set_wm_state(ObClient *self, glong state)
2505 if (state == self->wmstate) return; /* no change */
2509 client_iconify(self, TRUE, TRUE);
2512 client_iconify(self, FALSE, TRUE);
2517 void client_set_state(ObClient *self, Atom action, glong data1, glong data2)
2519 gboolean shaded = self->shaded;
2520 gboolean fullscreen = self->fullscreen;
2521 gboolean undecorated = self->undecorated;
2522 gboolean max_horz = self->max_horz;
2523 gboolean max_vert = self->max_vert;
2524 gboolean modal = self->modal;
2525 gboolean iconic = self->iconic;
2528 if (!(action == prop_atoms.net_wm_state_add ||
2529 action == prop_atoms.net_wm_state_remove ||
2530 action == prop_atoms.net_wm_state_toggle))
2531 /* an invalid action was passed to the client message, ignore it */
2534 for (i = 0; i < 2; ++i) {
2535 Atom state = i == 0 ? data1 : data2;
2537 if (!state) continue;
2539 /* if toggling, then pick whether we're adding or removing */
2540 if (action == prop_atoms.net_wm_state_toggle) {
2541 if (state == prop_atoms.net_wm_state_modal)
2542 action = modal ? prop_atoms.net_wm_state_remove :
2543 prop_atoms.net_wm_state_add;
2544 else if (state == prop_atoms.net_wm_state_maximized_vert)
2545 action = self->max_vert ? prop_atoms.net_wm_state_remove :
2546 prop_atoms.net_wm_state_add;
2547 else if (state == prop_atoms.net_wm_state_maximized_horz)
2548 action = self->max_horz ? prop_atoms.net_wm_state_remove :
2549 prop_atoms.net_wm_state_add;
2550 else if (state == prop_atoms.net_wm_state_shaded)
2551 action = shaded ? prop_atoms.net_wm_state_remove :
2552 prop_atoms.net_wm_state_add;
2553 else if (state == prop_atoms.net_wm_state_skip_taskbar)
2554 action = self->skip_taskbar ?
2555 prop_atoms.net_wm_state_remove :
2556 prop_atoms.net_wm_state_add;
2557 else if (state == prop_atoms.net_wm_state_skip_pager)
2558 action = self->skip_pager ?
2559 prop_atoms.net_wm_state_remove :
2560 prop_atoms.net_wm_state_add;
2561 else if (state == prop_atoms.net_wm_state_hidden)
2562 action = self->iconic ?
2563 prop_atoms.net_wm_state_remove :
2564 prop_atoms.net_wm_state_add;
2565 else if (state == prop_atoms.net_wm_state_fullscreen)
2566 action = fullscreen ?
2567 prop_atoms.net_wm_state_remove :
2568 prop_atoms.net_wm_state_add;
2569 else if (state == prop_atoms.net_wm_state_above)
2570 action = self->above ? prop_atoms.net_wm_state_remove :
2571 prop_atoms.net_wm_state_add;
2572 else if (state == prop_atoms.net_wm_state_below)
2573 action = self->below ? prop_atoms.net_wm_state_remove :
2574 prop_atoms.net_wm_state_add;
2575 else if (state == prop_atoms.ob_wm_state_undecorated)
2576 action = undecorated ? prop_atoms.net_wm_state_remove :
2577 prop_atoms.net_wm_state_add;
2580 if (action == prop_atoms.net_wm_state_add) {
2581 if (state == prop_atoms.net_wm_state_modal) {
2583 } else if (state == prop_atoms.net_wm_state_maximized_vert) {
2585 } else if (state == prop_atoms.net_wm_state_maximized_horz) {
2587 } else if (state == prop_atoms.net_wm_state_shaded) {
2589 } else if (state == prop_atoms.net_wm_state_skip_taskbar) {
2590 self->skip_taskbar = TRUE;
2591 } else if (state == prop_atoms.net_wm_state_skip_pager) {
2592 self->skip_pager = TRUE;
2593 } else if (state == prop_atoms.net_wm_state_hidden) {
2595 } else if (state == prop_atoms.net_wm_state_fullscreen) {
2597 } else if (state == prop_atoms.net_wm_state_above) {
2599 self->below = FALSE;
2600 } else if (state == prop_atoms.net_wm_state_below) {
2601 self->above = FALSE;
2603 } else if (state == prop_atoms.ob_wm_state_undecorated) {
2607 } else { /* action == prop_atoms.net_wm_state_remove */
2608 if (state == prop_atoms.net_wm_state_modal) {
2610 } else if (state == prop_atoms.net_wm_state_maximized_vert) {
2612 } else if (state == prop_atoms.net_wm_state_maximized_horz) {
2614 } else if (state == prop_atoms.net_wm_state_shaded) {
2616 } else if (state == prop_atoms.net_wm_state_skip_taskbar) {
2617 self->skip_taskbar = FALSE;
2618 } else if (state == prop_atoms.net_wm_state_skip_pager) {
2619 self->skip_pager = FALSE;
2620 } else if (state == prop_atoms.net_wm_state_hidden) {
2622 } else if (state == prop_atoms.net_wm_state_fullscreen) {
2624 } else if (state == prop_atoms.net_wm_state_above) {
2625 self->above = FALSE;
2626 } else if (state == prop_atoms.net_wm_state_below) {
2627 self->below = FALSE;
2628 } else if (state == prop_atoms.ob_wm_state_undecorated) {
2629 undecorated = FALSE;
2633 if (max_horz != self->max_horz || max_vert != self->max_vert) {
2634 if (max_horz != self->max_horz && max_vert != self->max_vert) {
2636 if (max_horz == max_vert) { /* both going the same way */
2637 client_maximize(self, max_horz, 0, TRUE);
2639 client_maximize(self, max_horz, 1, TRUE);
2640 client_maximize(self, max_vert, 2, TRUE);
2644 if (max_horz != self->max_horz)
2645 client_maximize(self, max_horz, 1, TRUE);
2647 client_maximize(self, max_vert, 2, TRUE);
2650 /* change fullscreen state before shading, as it will affect if the window
2652 if (fullscreen != self->fullscreen)
2653 client_fullscreen(self, fullscreen, TRUE);
2654 if (shaded != self->shaded)
2655 client_shade(self, shaded);
2656 if (undecorated != self->undecorated)
2657 client_set_undecorated(self, undecorated);
2658 if (modal != self->modal) {
2659 self->modal = modal;
2660 /* when a window changes modality, then its stacking order with its
2661 transients needs to change */
2664 if (iconic != self->iconic)
2665 client_iconify(self, iconic, FALSE);
2667 client_calc_layer(self);
2668 client_change_state(self); /* change the hint to reflect these changes */
2671 ObClient *client_focus_target(ObClient *self)
2675 /* if we have a modal child, then focus it, not us */
2676 child = client_search_modal_child(client_search_top_transient(self));
2677 if (child) return child;
2681 gboolean client_can_focus(ObClient *self)
2685 /* choose the correct target */
2686 self = client_focus_target(self);
2688 if (!self->frame->visible)
2691 if (!(self->can_focus || self->focus_notify))
2694 /* do a check to see if the window has already been unmapped or destroyed
2695 do this intelligently while watching out for unmaps we've generated
2696 (ignore_unmaps > 0) */
2697 if (XCheckTypedWindowEvent(ob_display, self->window,
2698 DestroyNotify, &ev)) {
2699 XPutBackEvent(ob_display, &ev);
2702 while (XCheckTypedWindowEvent(ob_display, self->window,
2703 UnmapNotify, &ev)) {
2704 if (self->ignore_unmaps) {
2705 self->ignore_unmaps--;
2707 XPutBackEvent(ob_display, &ev);
2715 gboolean client_focus(ObClient *self)
2717 /* choose the correct target */
2718 self = client_focus_target(self);
2720 if (!client_can_focus(self)) {
2721 if (!self->frame->visible) {
2722 /* update the focus lists */
2723 focus_order_to_top(self);
2728 if (self->can_focus) {
2729 /* RevertToPointerRoot causes much more headache than RevertToNone, so
2730 I choose to use it always, hopefully to find errors quicker, if any
2731 are left. (I hate X. I hate focus events.)
2733 Update: Changing this to RevertToNone fixed a bug with mozilla (bug
2734 #799. So now it is RevertToNone again.
2736 XSetInputFocus(ob_display, self->window, RevertToNone,
2740 if (self->focus_notify) {
2742 ce.xclient.type = ClientMessage;
2743 ce.xclient.message_type = prop_atoms.wm_protocols;
2744 ce.xclient.display = ob_display;
2745 ce.xclient.window = self->window;
2746 ce.xclient.format = 32;
2747 ce.xclient.data.l[0] = prop_atoms.wm_take_focus;
2748 ce.xclient.data.l[1] = event_lasttime;
2749 ce.xclient.data.l[2] = 0l;
2750 ce.xclient.data.l[3] = 0l;
2751 ce.xclient.data.l[4] = 0l;
2752 XSendEvent(ob_display, self->window, FALSE, NoEventMask, &ce);
2756 ob_debug("%sively focusing %lx at %d\n",
2757 (self->can_focus ? "act" : "pass"),
2758 self->window, (gint) event_lasttime);
2761 /* Cause the FocusIn to come back to us. Important for desktop switches,
2762 since otherwise we'll have no FocusIn on the queue and send it off to
2763 the focus_backup. */
2764 XSync(ob_display, FALSE);
2768 void client_unfocus(ObClient *self)
2770 if (focus_client == self) {
2772 ob_debug("client_unfocus for %lx\n", self->window);
2774 focus_fallback(OB_FOCUS_FALLBACK_UNFOCUSING);
2778 void client_activate(ObClient *self, gboolean here)
2780 if (client_normal(self) && screen_showing_desktop)
2781 screen_show_desktop(FALSE);
2783 client_iconify(self, FALSE, here);
2784 if (self->desktop != DESKTOP_ALL &&
2785 self->desktop != screen_desktop) {
2787 client_set_desktop(self, screen_desktop, FALSE);
2789 screen_set_desktop(self->desktop);
2790 } else if (!self->frame->visible)
2791 /* if its not visible for other reasons, then don't mess
2795 client_shade(self, FALSE);
2799 /* we do this an action here. this is rather important. this is because
2800 we want the results from the focus change to take place BEFORE we go
2801 about raising the window. when a fullscreen window loses focus, we need
2802 this or else the raise wont be able to raise above the to-lose-focus
2803 fullscreen window. */
2807 void client_raise(ObClient *self)
2809 action_run_string("Raise", self);
2812 void client_lower(ObClient *self)
2814 action_run_string("Lower", self);
2817 gboolean client_focused(ObClient *self)
2819 return self == focus_client;
2822 static ObClientIcon* client_icon_recursive(ObClient *self, gint w, gint h)
2825 /* si is the smallest image >= req */
2826 /* li is the largest image < req */
2827 gulong size, smallest = 0xffffffff, largest = 0, si = 0, li = 0;
2829 if (!self->nicons) {
2830 ObClientIcon *parent = NULL;
2832 if (self->transient_for) {
2833 if (self->transient_for != OB_TRAN_GROUP)
2834 parent = client_icon_recursive(self->transient_for, w, h);
2837 for (it = self->group->members; it; it = g_slist_next(it)) {
2838 ObClient *c = it->data;
2839 if (c != self && !c->transient_for) {
2840 if ((parent = client_icon_recursive(c, w, h)))
2850 for (i = 0; i < self->nicons; ++i) {
2851 size = self->icons[i].width * self->icons[i].height;
2852 if (size < smallest && size >= (unsigned)(w * h)) {
2856 if (size > largest && size <= (unsigned)(w * h)) {
2861 if (largest == 0) /* didnt find one smaller than the requested size */
2862 return &self->icons[si];
2863 return &self->icons[li];
2866 const ObClientIcon* client_icon(ObClient *self, gint w, gint h)
2869 static ObClientIcon deficon;
2871 if (!(ret = client_icon_recursive(self, w, h))) {
2872 deficon.width = deficon.height = 48;
2873 deficon.data = ob_rr_theme->def_win_icon;
2879 /* this be mostly ripped from fvwm */
2880 ObClient *client_find_directional(ObClient *c, ObDirection dir)
2882 gint my_cx, my_cy, his_cx, his_cy;
2885 gint score, best_score;
2886 ObClient *best_client, *cur;
2892 /* first, find the centre coords of the currently focused window */
2893 my_cx = c->frame->area.x + c->frame->area.width / 2;
2894 my_cy = c->frame->area.y + c->frame->area.height / 2;
2899 for(it = g_list_first(client_list); it; it = g_list_next(it)) {
2902 /* the currently selected window isn't interesting */
2905 if (!client_normal(cur))
2907 /* using c->desktop instead of screen_desktop doesn't work if the
2908 * current window was omnipresent, hope this doesn't have any other
2910 if(screen_desktop != cur->desktop && cur->desktop != DESKTOP_ALL)
2914 if(client_focus_target(cur) == cur &&
2915 !(cur->can_focus || cur->focus_notify))
2918 /* find the centre coords of this window, from the
2919 * currently focused window's point of view */
2920 his_cx = (cur->frame->area.x - my_cx)
2921 + cur->frame->area.width / 2;
2922 his_cy = (cur->frame->area.y - my_cy)
2923 + cur->frame->area.height / 2;
2925 if(dir == OB_DIRECTION_NORTHEAST || dir == OB_DIRECTION_SOUTHEAST ||
2926 dir == OB_DIRECTION_SOUTHWEST || dir == OB_DIRECTION_NORTHWEST) {
2928 /* Rotate the diagonals 45 degrees counterclockwise.
2929 * To do this, multiply the matrix /+h +h\ with the
2930 * vector (x y). \-h +h/
2931 * h = sqrt(0.5). We can set h := 1 since absolute
2932 * distance doesn't matter here. */
2933 tx = his_cx + his_cy;
2934 his_cy = -his_cx + his_cy;
2939 case OB_DIRECTION_NORTH:
2940 case OB_DIRECTION_SOUTH:
2941 case OB_DIRECTION_NORTHEAST:
2942 case OB_DIRECTION_SOUTHWEST:
2943 offset = (his_cx < 0) ? -his_cx : his_cx;
2944 distance = ((dir == OB_DIRECTION_NORTH ||
2945 dir == OB_DIRECTION_NORTHEAST) ?
2948 case OB_DIRECTION_EAST:
2949 case OB_DIRECTION_WEST:
2950 case OB_DIRECTION_SOUTHEAST:
2951 case OB_DIRECTION_NORTHWEST:
2952 offset = (his_cy < 0) ? -his_cy : his_cy;
2953 distance = ((dir == OB_DIRECTION_WEST ||
2954 dir == OB_DIRECTION_NORTHWEST) ?
2959 /* the target must be in the requested direction */
2963 /* Calculate score for this window. The smaller the better. */
2964 score = distance + offset;
2966 /* windows more than 45 degrees off the direction are
2967 * heavily penalized and will only be chosen if nothing
2968 * else within a million pixels */
2969 if(offset > distance)
2972 if(best_score == -1 || score < best_score)
2980 void client_set_layer(ObClient *self, gint layer)
2984 self->above = FALSE;
2985 } else if (layer == 0) {
2986 self->below = self->above = FALSE;
2988 self->below = FALSE;
2991 client_calc_layer(self);
2992 client_change_state(self); /* reflect this in the state hints */
2995 void client_set_undecorated(ObClient *self, gboolean undecorated)
2997 if (self->undecorated != undecorated) {
2998 self->undecorated = undecorated;
2999 client_setup_decor_and_functions(self);
3000 client_change_state(self); /* reflect this in the state hints */
3004 /* Determines which physical monitor a client is on by calculating the
3005 area of the part of the client on each monitor. The number of the
3006 monitor containing the greatest area of the client is returned.*/
3007 guint client_monitor(ObClient *self)
3013 for (i = 0; i < screen_num_monitors; ++i) {
3014 Rect *area = screen_physical_area_monitor(i);
3015 if (RECT_INTERSECTS_RECT(*area, self->frame->area)) {
3019 RECT_SET_INTERSECTION(r, *area, self->frame->area);
3020 v = r.width * r.height;
3031 ObClient *client_search_top_transient(ObClient *self)
3033 /* move up the transient chain as far as possible */
3034 if (self->transient_for) {
3035 if (self->transient_for != OB_TRAN_GROUP) {
3036 return client_search_top_transient(self->transient_for);
3040 g_assert(self->group);
3042 for (it = self->group->members; it; it = g_slist_next(it)) {
3043 ObClient *c = it->data;
3045 /* checking transient_for prevents infinate loops! */
3046 if (c != self && !c->transient_for)
3057 ObClient *client_search_focus_parent(ObClient *self)
3059 if (self->transient_for) {
3060 if (self->transient_for != OB_TRAN_GROUP) {
3061 if (client_focused(self->transient_for))
3062 return self->transient_for;
3066 for (it = self->group->members; it; it = g_slist_next(it)) {
3067 ObClient *c = it->data;
3069 /* checking transient_for prevents infinate loops! */
3070 if (c != self && !c->transient_for)
3071 if (client_focused(c))
3080 ObClient *client_search_parent(ObClient *self, ObClient *search)
3082 if (self->transient_for) {
3083 if (self->transient_for != OB_TRAN_GROUP) {
3084 if (self->transient_for == search)
3089 for (it = self->group->members; it; it = g_slist_next(it)) {
3090 ObClient *c = it->data;
3092 /* checking transient_for prevents infinate loops! */
3093 if (c != self && !c->transient_for)
3103 ObClient *client_search_transient(ObClient *self, ObClient *search)
3107 for (sit = self->transients; sit; sit = g_slist_next(sit)) {
3108 if (sit->data == search)
3110 if (client_search_transient(sit->data, search))
3116 void client_update_sm_client_id(ObClient *self)
3118 g_free(self->sm_client_id);
3119 self->sm_client_id = NULL;
3121 if (!PROP_GETS(self->window, sm_client_id, locale, &self->sm_client_id) &&
3123 PROP_GETS(self->group->leader, sm_client_id, locale,
3124 &self->sm_client_id);
3127 /* finds the nearest edge in the given direction from the current client
3128 * note to self: the edge is the -frame- edge (the actual one), not the
3131 gint client_directional_edge_search(ObClient *c, ObDirection dir)
3133 gint dest, monitor_dest;
3134 gint my_edge_start, my_edge_end, my_offset;
3141 a = screen_area(c->desktop);
3142 monitor = screen_area_monitor(c->desktop, client_monitor(c));
3145 case OB_DIRECTION_NORTH:
3146 my_edge_start = c->frame->area.x;
3147 my_edge_end = c->frame->area.x + c->frame->area.width;
3148 my_offset = c->frame->area.y;
3150 /* default: top of screen */
3152 monitor_dest = monitor->y;
3153 /* if the monitor edge comes before the screen edge, */
3154 /* use that as the destination instead. (For xinerama) */
3155 if (monitor_dest != dest && my_offset > monitor_dest)
3156 dest = monitor_dest;
3158 for(it = client_list; it && my_offset != dest; it = g_list_next(it)) {
3159 gint his_edge_start, his_edge_end, his_offset;
3160 ObClient *cur = it->data;
3164 if(!client_normal(cur))
3166 if(screen_desktop != cur->desktop && cur->desktop != DESKTOP_ALL)
3170 if(cur->layer < c->layer && !config_resist_layers_below)
3173 his_edge_start = cur->frame->area.x;
3174 his_edge_end = cur->frame->area.x + cur->frame->area.width;
3175 his_offset = cur->frame->area.y + cur->frame->area.height;
3177 if(his_offset + 1 > my_offset)
3180 if(his_offset < dest)
3183 if(his_edge_start >= my_edge_start &&
3184 his_edge_start <= my_edge_end)
3187 if(my_edge_start >= his_edge_start &&
3188 my_edge_start <= his_edge_end)
3193 case OB_DIRECTION_SOUTH:
3194 my_edge_start = c->frame->area.x;
3195 my_edge_end = c->frame->area.x + c->frame->area.width;
3196 my_offset = c->frame->area.y + c->frame->area.height;
3198 /* default: bottom of screen */
3199 dest = a->y + a->height;
3200 monitor_dest = monitor->y + monitor->height;
3201 /* if the monitor edge comes before the screen edge, */
3202 /* use that as the destination instead. (For xinerama) */
3203 if (monitor_dest != dest && my_offset < monitor_dest)
3204 dest = monitor_dest;
3206 for(it = client_list; it && my_offset != dest; it = g_list_next(it)) {
3207 gint his_edge_start, his_edge_end, his_offset;
3208 ObClient *cur = it->data;
3212 if(!client_normal(cur))
3214 if(screen_desktop != cur->desktop && cur->desktop != DESKTOP_ALL)
3218 if(cur->layer < c->layer && !config_resist_layers_below)
3221 his_edge_start = cur->frame->area.x;
3222 his_edge_end = cur->frame->area.x + cur->frame->area.width;
3223 his_offset = cur->frame->area.y;
3226 if(his_offset - 1 < my_offset)
3229 if(his_offset > dest)
3232 if(his_edge_start >= my_edge_start &&
3233 his_edge_start <= my_edge_end)
3236 if(my_edge_start >= his_edge_start &&
3237 my_edge_start <= his_edge_end)
3242 case OB_DIRECTION_WEST:
3243 my_edge_start = c->frame->area.y;
3244 my_edge_end = c->frame->area.y + c->frame->area.height;
3245 my_offset = c->frame->area.x;
3247 /* default: leftmost egde of screen */
3249 monitor_dest = monitor->x;
3250 /* if the monitor edge comes before the screen edge, */
3251 /* use that as the destination instead. (For xinerama) */
3252 if (monitor_dest != dest && my_offset > monitor_dest)
3253 dest = monitor_dest;
3255 for(it = client_list; it && my_offset != dest; it = g_list_next(it)) {
3256 gint his_edge_start, his_edge_end, his_offset;
3257 ObClient *cur = it->data;
3261 if(!client_normal(cur))
3263 if(screen_desktop != cur->desktop && cur->desktop != DESKTOP_ALL)
3267 if(cur->layer < c->layer && !config_resist_layers_below)
3270 his_edge_start = cur->frame->area.y;
3271 his_edge_end = cur->frame->area.y + cur->frame->area.height;
3272 his_offset = cur->frame->area.x + cur->frame->area.width;
3274 if(his_offset + 1 > my_offset)
3277 if(his_offset < dest)
3280 if(his_edge_start >= my_edge_start &&
3281 his_edge_start <= my_edge_end)
3284 if(my_edge_start >= his_edge_start &&
3285 my_edge_start <= his_edge_end)
3291 case OB_DIRECTION_EAST:
3292 my_edge_start = c->frame->area.y;
3293 my_edge_end = c->frame->area.y + c->frame->area.height;
3294 my_offset = c->frame->area.x + c->frame->area.width;
3296 /* default: rightmost edge of screen */
3297 dest = a->x + a->width;
3298 monitor_dest = monitor->x + monitor->width;
3299 /* if the monitor edge comes before the screen edge, */
3300 /* use that as the destination instead. (For xinerama) */
3301 if (monitor_dest != dest && my_offset < monitor_dest)
3302 dest = monitor_dest;
3304 for(it = client_list; it && my_offset != dest; it = g_list_next(it)) {
3305 gint his_edge_start, his_edge_end, his_offset;
3306 ObClient *cur = it->data;
3310 if(!client_normal(cur))
3312 if(screen_desktop != cur->desktop && cur->desktop != DESKTOP_ALL)
3316 if(cur->layer < c->layer && !config_resist_layers_below)
3319 his_edge_start = cur->frame->area.y;
3320 his_edge_end = cur->frame->area.y + cur->frame->area.height;
3321 his_offset = cur->frame->area.x;
3323 if(his_offset - 1 < my_offset)
3326 if(his_offset > dest)
3329 if(his_edge_start >= my_edge_start &&
3330 his_edge_start <= my_edge_end)
3333 if(my_edge_start >= his_edge_start &&
3334 my_edge_start <= his_edge_end)
3339 case OB_DIRECTION_NORTHEAST:
3340 case OB_DIRECTION_SOUTHEAST:
3341 case OB_DIRECTION_NORTHWEST:
3342 case OB_DIRECTION_SOUTHWEST:
3343 /* not implemented */
3345 g_assert_not_reached();
3346 dest = 0; /* suppress warning */
3351 ObClient* client_under_pointer()
3355 ObClient *ret = NULL;
3357 if (screen_pointer_pos(&x, &y)) {
3358 for (it = stacking_list; it; it = g_list_next(it)) {
3359 if (WINDOW_IS_CLIENT(it->data)) {
3360 ObClient *c = WINDOW_AS_CLIENT(it->data);
3361 if (c->frame->visible &&
3362 RECT_CONTAINS(c->frame->area, x, y)) {
3372 gboolean client_has_group_siblings(ObClient *self)
3374 return self->group && self->group->members->next;