4 #include "extensions.h"
16 #include <X11/Xutil.h>
18 /*! The event mask to grab on client windows */
19 #define CLIENT_EVENTMASK (PropertyChangeMask | FocusChangeMask | \
22 #define CLIENT_NOPROPAGATEMASK (ButtonPressMask | ButtonReleaseMask | \
25 GList *client_list = NULL;
26 GHashTable *client_map = NULL;
28 static Window *client_startup_stack_order = NULL;
29 static guint client_startup_stack_size = 0;
31 static void client_get_all(Client *self);
32 static void client_toggle_border(Client *self, gboolean show);
33 static void client_get_area(Client *self);
34 static void client_get_desktop(Client *self);
35 static void client_get_state(Client *self);
36 static void client_get_shaped(Client *self);
37 static void client_get_mwm_hints(Client *self);
38 static void client_get_gravity(Client *self);
39 static void client_showhide(Client *self);
40 static void client_change_allowed_actions(Client *self);
41 static void client_change_state(Client *self);
42 static void client_move_onscreen(Client *self);
43 static Client *search_focus_tree(Client *node, Client *skip);
44 static void client_apply_startup_state(Client *self);
45 static Client *search_modal_tree(Client *node, Client *skip);
47 static guint map_hash(Window *w) { return *w; }
48 static gboolean map_key_comp(Window *w1, Window *w2) { return *w1 == *w2; }
52 client_map = g_hash_table_new((GHashFunc)map_hash,
53 (GEqualFunc)map_key_comp);
55 /* save the stacking order on startup! */
56 PROP_GETA32(ob_root, net_client_list_stacking, window,
57 (guint32**)&client_startup_stack_order,
58 &client_startup_stack_size);
63 void client_shutdown()
65 g_hash_table_destroy(client_map);
68 void client_set_list()
70 Window *windows, *win_it;
72 guint size = g_list_length(client_list);
74 /* create an array of the window ids */
76 windows = g_new(Window, size);
78 for (it = client_list; it != NULL; it = it->next, ++win_it)
79 *win_it = ((Client*)it->data)->window;
83 PROP_SETA32(ob_root, net_client_list, window, (guint32*)windows, size);
91 void client_manage_all()
93 unsigned int i, j, nchild;
96 XWindowAttributes attrib;
98 XQueryTree(ob_display, ob_root, &w, &w, &children, &nchild);
100 /* remove all icon windows from the list */
101 for (i = 0; i < nchild; i++) {
102 if (children[i] == None) continue;
103 wmhints = XGetWMHints(ob_display, children[i]);
105 if ((wmhints->flags & IconWindowHint) &&
106 (wmhints->icon_window != children[i]))
107 for (j = 0; j < nchild; j++)
108 if (children[j] == wmhints->icon_window) {
116 for (i = 0; i < nchild; ++i) {
117 if (children[i] == None)
119 if (XGetWindowAttributes(ob_display, children[i], &attrib)) {
120 if (attrib.override_redirect) continue;
122 if (attrib.map_state != IsUnmapped)
123 client_manage(children[i]);
128 /* stack them as they were on startup!
129 why with stacking_lower? Why, because then windows who aren't in the
130 stacking list are on the top where you can see them instead of buried
132 for (i = client_startup_stack_size; i > 0; --i) {
135 w = client_startup_stack_order[i-1];
136 c = g_hash_table_lookup(client_map, &w);
137 if (c) stacking_lower(c);
139 g_free(client_startup_stack_order);
140 client_startup_stack_order = NULL;
141 client_startup_stack_size = 0;
143 if (config_focus_new)
144 focus_fallback(Fallback_NoFocus);
147 void client_manage(Window window)
151 XWindowAttributes attrib;
152 XSetWindowAttributes attrib_set;
153 /* XWMHints *wmhint; */
158 /* check if it has already been unmapped by the time we started mapping
159 the grab does a sync so we don't have to here */
160 if (XCheckTypedWindowEvent(ob_display, window, DestroyNotify, &e) ||
161 XCheckTypedWindowEvent(ob_display, window, UnmapNotify, &e)) {
162 XPutBackEvent(ob_display, &e);
165 return; /* don't manage it */
168 /* make sure it isn't an override-redirect window */
169 if (!XGetWindowAttributes(ob_display, window, &attrib) ||
170 attrib.override_redirect) {
172 return; /* don't manage it */
175 /* /\* is the window a docking app *\/
176 if ((wmhint = XGetWMHints(ob_display, window))) {
177 if ((wmhint->flags & StateHint) &&
178 wmhint->initial_state == WithdrawnState) {
179 /\* XXX: make dock apps work! *\/
187 g_message("Managing window: %lx", window);
189 /* choose the events we want to receive on the CLIENT window */
190 attrib_set.event_mask = CLIENT_EVENTMASK;
191 attrib_set.do_not_propagate_mask = CLIENT_NOPROPAGATEMASK;
192 XChangeWindowAttributes(ob_display, window,
193 CWEventMask|CWDontPropagate, &attrib_set);
196 /* create the Client struct, and populate it from the hints on the
198 self = g_new(Client, 1);
199 self->window = window;
200 client_get_all(self);
202 /* remove the client's border (and adjust re gravity) */
203 client_toggle_border(self, FALSE);
205 /* specify that if we exit, the window should not be destroyed and should
206 be reparented back to root automatically */
207 XChangeSaveSet(ob_display, window, SetModeInsert);
209 /* create the decoration frame for the client window */
210 self->frame = frame_new();
212 frame_grab_client(self->frame, self);
214 client_apply_startup_state(self);
218 client_list = g_list_append(client_list, self);
219 stacking_list = g_list_append(stacking_list, self);
220 g_assert(!g_hash_table_lookup(client_map, &self->window));
221 g_hash_table_insert(client_map, &self->window, self);
223 /* update the focus lists */
224 if (self->desktop == DESKTOP_ALL) {
225 for (i = 0; i < screen_num_desktops; ++i)
226 focus_order[i] = g_list_append(focus_order[i], self);
229 focus_order[i] = g_list_append(focus_order[i], self);
232 stacking_raise(self);
234 screen_update_struts();
236 dispatch_client(Event_Client_New, self, 0, 0);
238 client_showhide(self);
240 dispatch_client(Event_Client_Mapped, self, 0, 0);
242 /* focus the new window? */
243 if (ob_state != State_Starting && client_normal(self)) {
244 if (config_focus_new)
246 else if (self->transient_for) {
247 if (self->transient_for != TRAN_GROUP) {/* transient of a window */
248 if (focus_client == self->transient_for)
250 } else { /* transient of a group */
253 for (it = self->group->members; it; it = it->next)
254 if (focus_client == it->data) {
262 /* update the list hints */
265 /* make sure the window is visible */
266 client_move_onscreen(self);
268 g_message("Managed window 0x%lx", window);
271 void client_unmanage_all()
273 while (client_list != NULL)
274 client_unmanage(client_list->data);
277 void client_unmanage(Client *self)
283 g_message("Unmanaging window: %lx", self->window);
285 dispatch_client(Event_Client_Destroy, self, 0, 0);
286 g_assert(self != NULL);
288 /* remove the window from our save set */
289 XChangeSaveSet(ob_display, self->window, SetModeDelete);
291 /* we dont want events no more */
292 XSelectInput(ob_display, self->window, NoEventMask);
294 frame_hide(self->frame);
296 client_list = g_list_remove(client_list, self);
297 stacking_list = g_list_remove(stacking_list, self);
298 g_hash_table_remove(client_map, &self->window);
300 /* update the focus lists */
301 if (self->desktop == DESKTOP_ALL) {
302 for (i = 0; i < screen_num_desktops; ++i)
303 focus_order[i] = g_list_remove(focus_order[i], self);
306 focus_order[i] = g_list_remove(focus_order[i], self);
309 /* once the client is out of the list, update the struts to remove it's
311 screen_update_struts();
313 /* tell our parent(s) that we're gone */
314 if (self->transient_for == TRAN_GROUP) { /* transient of group */
317 for (it = self->group->members; it; it = it->next)
318 if (it->data != self)
319 ((Client*)it->data)->transients =
320 g_slist_remove(((Client*)it->data)->transients, self);
321 } else if (self->transient_for) { /* transient of window */
322 self->transient_for->transients =
323 g_slist_remove(self->transient_for->transients, self);
326 /* tell our transients that we're gone */
327 for (it = self->transients; it != NULL; it = it->next) {
328 if (((Client*)it->data)->transient_for != TRAN_GROUP) {
329 ((Client*)it->data)->transient_for = NULL;
330 client_calc_layer(it->data);
334 if (focus_client == self)
335 client_unfocus(self);
337 /* remove from its group */
339 group_remove(self->group, self);
343 /* dispatch the unmapped event */
344 dispatch_client(Event_Client_Unmapped, self, 0, 0);
345 g_assert(self != NULL);
347 /* give the client its border back */
348 client_toggle_border(self, TRUE);
350 /* reparent the window out of the frame, and free the frame */
351 frame_release_client(self->frame, self);
354 if (ob_state != State_Exiting) {
355 /* these values should not be persisted across a window
357 prop_erase(self->window, prop_atoms.net_wm_desktop);
358 prop_erase(self->window, prop_atoms.net_wm_state);
360 /* if we're left in an iconic state, the client wont be mapped. this is
361 bad, since we will no longer be managing the window on restart */
363 XMapWindow(ob_display, self->window);
366 g_message("Unmanaged window 0x%lx", self->window);
368 /* free all data allocated in the client struct */
369 g_slist_free(self->transients);
370 for (j = 0; j < self->nicons; ++j)
371 g_free(self->icons[j].data);
372 if (self->nicons > 0)
375 g_free(self->icon_title);
381 /* update the list hints */
385 static void client_move_onscreen(Client *self)
388 int x = self->frame->area.x, y = self->frame->area.y;
390 a = screen_area(self->desktop);
391 if (x >= a->x + a->width - 1)
392 x = a->x + a->width - self->frame->area.width;
393 if (y >= a->y + a->height - 1)
394 y = a->y + a->height - self->frame->area.height;
395 if (x + self->frame->area.width - 1 < a->x)
397 if (y + self->frame->area.height - 1< a->y)
400 frame_frame_gravity(self->frame, &x, &y); /* get where the client
402 client_configure(self , Corner_TopLeft, x, y,
403 self->area.width, self->area.height,
407 static void client_toggle_border(Client *self, gboolean show)
409 /* adjust our idea of where the client is, based on its border. When the
410 border is removed, the client should now be considered to be in a
412 when re-adding the border to the client, the same operation needs to be
414 int oldx = self->area.x, oldy = self->area.y;
415 int x = oldx, y = oldy;
416 switch(self->gravity) {
418 case NorthWestGravity:
420 case SouthWestGravity:
422 case NorthEastGravity:
424 case SouthEastGravity:
425 if (show) x -= self->border_width * 2;
426 else x += self->border_width * 2;
433 if (show) x -= self->border_width;
434 else x += self->border_width;
437 switch(self->gravity) {
439 case NorthWestGravity:
441 case NorthEastGravity:
443 case SouthWestGravity:
445 case SouthEastGravity:
446 if (show) y -= self->border_width * 2;
447 else y += self->border_width * 2;
454 if (show) y -= self->border_width;
455 else y += self->border_width;
462 XSetWindowBorderWidth(ob_display, self->window, self->border_width);
464 /* move the client so it is back it the right spot _with_ its
466 if (x != oldx || y != oldy)
467 XMoveWindow(ob_display, self->window, x, y);
469 XSetWindowBorderWidth(ob_display, self->window, 0);
473 static void client_get_all(Client *self)
475 /* update EVERYTHING!! */
477 self->ignore_unmaps = 0;
481 self->title = self->icon_title = NULL;
482 self->name = self->class = self->role = NULL;
483 self->wmstate = NormalState;
484 self->transient = FALSE;
485 self->transients = NULL;
486 self->transient_for = NULL;
488 self->urgent = FALSE;
489 self->positioned = FALSE;
490 self->disabled_decorations = 0;
494 client_get_area(self);
495 client_get_desktop(self);
496 client_get_state(self);
497 client_get_shaped(self);
499 client_update_transient_for(self);
500 client_get_mwm_hints(self);
501 client_get_type(self);/* this can change the mwmhints for special cases */
503 client_update_protocols(self);
505 client_get_gravity(self); /* get the attribute gravity */
506 client_update_normal_hints(self); /* this may override the attribute
509 /* got the type, the mwmhints, the protocols, and the normal hints
510 (min/max sizes), so we're ready to set up the decorations/functions */
511 client_setup_decor_and_functions(self);
513 client_update_wmhints(self);
514 client_update_title(self);
515 client_update_icon_title(self);
516 client_update_class(self);
517 client_update_strut(self);
518 client_update_icons(self);
519 client_update_kwm_icon(self);
521 /* this makes sure that these windows appear on all desktops */
522 if (self->type == Type_Desktop)
523 self->desktop = DESKTOP_ALL;
525 /* set the desktop hint, to make sure that it always exists, and to
526 reflect any changes we've made here */
527 PROP_SET32(self->window, net_wm_desktop, cardinal, self->desktop);
529 client_change_state(self);
532 static void client_get_area(Client *self)
534 XWindowAttributes wattrib;
537 ret = XGetWindowAttributes(ob_display, self->window, &wattrib);
538 g_assert(ret != BadWindow);
540 RECT_SET(self->area, wattrib.x, wattrib.y, wattrib.width, wattrib.height);
541 self->border_width = wattrib.border_width;
544 static void client_get_desktop(Client *self)
548 if (PROP_GET32(self->window, net_wm_desktop, cardinal, &d)) {
549 if (d >= screen_num_desktops && d != DESKTOP_ALL)
550 d = screen_num_desktops - 1;
553 /* defaults to the current desktop */
554 self->desktop = screen_desktop;
558 static void client_get_state(Client *self)
563 self->modal = self->shaded = self->max_horz = self->max_vert =
564 self->fullscreen = self->above = self->below = self->iconic =
565 self->skip_taskbar = self->skip_pager = FALSE;
567 if (PROP_GETA32(self->window, net_wm_state, atom, &state, &num)) {
569 for (i = 0; i < num; ++i) {
570 if (state[i] == prop_atoms.net_wm_state_modal)
572 else if (state[i] == prop_atoms.net_wm_state_shaded)
574 else if (state[i] == prop_atoms.net_wm_state_hidden)
576 else if (state[i] == prop_atoms.net_wm_state_skip_taskbar)
577 self->skip_taskbar = TRUE;
578 else if (state[i] == prop_atoms.net_wm_state_skip_pager)
579 self->skip_pager = TRUE;
580 else if (state[i] == prop_atoms.net_wm_state_fullscreen)
581 self->fullscreen = TRUE;
582 else if (state[i] == prop_atoms.net_wm_state_maximized_vert)
583 self->max_vert = TRUE;
584 else if (state[i] == prop_atoms.net_wm_state_maximized_horz)
585 self->max_horz = TRUE;
586 else if (state[i] == prop_atoms.net_wm_state_above)
588 else if (state[i] == prop_atoms.net_wm_state_below)
596 static void client_get_shaped(Client *self)
598 self->shaped = FALSE;
600 if (extensions_shape) {
605 XShapeSelectInput(ob_display, self->window, ShapeNotifyMask);
607 XShapeQueryExtents(ob_display, self->window, &s, &foo,
608 &foo, &ufoo, &ufoo, &foo, &foo, &foo, &ufoo,
610 self->shaped = (s != 0);
615 void client_update_transient_for(Client *self)
620 if (XGetTransientForHint(ob_display, self->window, &t) &&
621 t != self->window) { /* cant be transient to itself! */
622 self->transient = TRUE;
623 c = g_hash_table_lookup(client_map, &t);
624 g_assert(c != self);/* if this happens then we need to check for it*/
626 if (!c && self->group) {
627 /* not transient to a client, see if it is transient for a
629 if (t == self->group->leader ||
632 /* window is a transient for its group! */
637 self->transient = FALSE;
639 /* if anything has changed... */
640 if (c != self->transient_for) {
641 if (self->transient_for == TRAN_GROUP) { /* transient of group */
644 /* remove from old parents */
645 for (it = self->group->members; it; it = it->next)
646 if (it->data != self)
647 ((Client*)it->data)->transients =
648 g_slist_remove(((Client*)it->data)->transients, self);
649 } else if (self->transient_for != NULL) { /* transient of window */
650 /* remove from old parent */
651 self->transient_for->transients =
652 g_slist_remove(self->transient_for->transients, self);
654 self->transient_for = c;
655 if (self->transient_for == TRAN_GROUP) { /* transient of group */
658 /* add to new parents */
659 for (it = self->group->members; it; it = it->next)
660 if (it->data != self)
661 ((Client*)it->data)->transients =
662 g_slist_append(((Client*)it->data)->transients, self);
663 } else if (self->transient_for != NULL) { /* transient of window */
664 /* add to new parent */
665 self->transient_for->transients =
666 g_slist_append(self->transient_for->transients, self);
671 static void client_get_mwm_hints(Client *self)
676 self->mwmhints.flags = 0; /* default to none */
678 if (PROP_GETA32(self->window, motif_wm_hints, motif_wm_hints,
680 if (num >= MWM_ELEMENTS) {
681 self->mwmhints.flags = hints[0];
682 self->mwmhints.functions = hints[1];
683 self->mwmhints.decorations = hints[2];
689 void client_get_type(Client *self)
696 if (PROP_GETA32(self->window, net_wm_window_type, atom, &val, &num)) {
697 /* use the first value that we know about in the array */
698 for (i = 0; i < num; ++i) {
699 if (val[i] == prop_atoms.net_wm_window_type_desktop)
700 self->type = Type_Desktop;
701 else if (val[i] == prop_atoms.net_wm_window_type_dock)
702 self->type = Type_Dock;
703 else if (val[i] == prop_atoms.net_wm_window_type_toolbar)
704 self->type = Type_Toolbar;
705 else if (val[i] == prop_atoms.net_wm_window_type_menu)
706 self->type = Type_Menu;
707 else if (val[i] == prop_atoms.net_wm_window_type_utility)
708 self->type = Type_Utility;
709 else if (val[i] == prop_atoms.net_wm_window_type_splash)
710 self->type = Type_Splash;
711 else if (val[i] == prop_atoms.net_wm_window_type_dialog)
712 self->type = Type_Dialog;
713 else if (val[i] == prop_atoms.net_wm_window_type_normal)
714 self->type = Type_Normal;
715 else if (val[i] == prop_atoms.kde_net_wm_window_type_override) {
716 /* prevent this window from getting any decor or
718 self->mwmhints.flags &= (MwmFlag_Functions |
719 MwmFlag_Decorations);
720 self->mwmhints.decorations = 0;
721 self->mwmhints.functions = 0;
723 if (self->type != (WindowType) -1)
724 break; /* grab the first legit type */
729 if (self->type == (WindowType) -1) {
730 /*the window type hint was not set, which means we either classify
731 ourself as a normal window or a dialog, depending on if we are a
734 self->type = Type_Dialog;
736 self->type = Type_Normal;
740 void client_update_protocols(Client *self)
745 self->focus_notify = FALSE;
746 self->delete_window = FALSE;
748 if (PROP_GETA32(self->window, wm_protocols, atom, &proto, &num_return)) {
749 for (i = 0; i < num_return; ++i) {
750 if (proto[i] == prop_atoms.wm_delete_window) {
751 /* this means we can request the window to close */
752 self->delete_window = TRUE;
753 } else if (proto[i] == prop_atoms.wm_take_focus)
754 /* if this protocol is requested, then the window will be
755 notified whenever we want it to receive focus */
756 self->focus_notify = TRUE;
762 static void client_get_gravity(Client *self)
764 XWindowAttributes wattrib;
767 ret = XGetWindowAttributes(ob_display, self->window, &wattrib);
768 g_assert(ret != BadWindow);
769 self->gravity = wattrib.win_gravity;
772 void client_update_normal_hints(Client *self)
776 int oldgravity = self->gravity;
779 self->min_ratio = 0.0f;
780 self->max_ratio = 0.0f;
781 SIZE_SET(self->size_inc, 1, 1);
782 SIZE_SET(self->base_size, 0, 0);
783 SIZE_SET(self->min_size, 0, 0);
784 SIZE_SET(self->max_size, G_MAXINT, G_MAXINT);
786 /* get the hints from the window */
787 if (XGetWMNormalHints(ob_display, self->window, &size, &ret)) {
788 self->positioned = !!(size.flags & (PPosition|USPosition));
790 if (size.flags & PWinGravity) {
791 self->gravity = size.win_gravity;
793 /* if the client has a frame, i.e. has already been mapped and
794 is changing its gravity */
795 if (self->frame && self->gravity != oldgravity) {
796 /* move our idea of the client's position based on its new
798 self->area.x = self->frame->area.x;
799 self->area.y = self->frame->area.y;
800 frame_frame_gravity(self->frame, &self->area.x, &self->area.y);
804 if (size.flags & PAspect) {
805 if (size.min_aspect.y)
806 self->min_ratio = (float)size.min_aspect.x / size.min_aspect.y;
807 if (size.max_aspect.y)
808 self->max_ratio = (float)size.max_aspect.x / size.max_aspect.y;
811 if (size.flags & PMinSize)
812 SIZE_SET(self->min_size, size.min_width, size.min_height);
814 if (size.flags & PMaxSize)
815 SIZE_SET(self->max_size, size.max_width, size.max_height);
817 if (size.flags & PBaseSize)
818 SIZE_SET(self->base_size, size.base_width, size.base_height);
820 if (size.flags & PResizeInc)
821 SIZE_SET(self->size_inc, size.width_inc, size.height_inc);
825 void client_setup_decor_and_functions(Client *self)
827 /* start with everything (cept fullscreen) */
828 self->decorations = Decor_Titlebar | Decor_Handle | Decor_Border |
829 Decor_Icon | Decor_AllDesktops | Decor_Iconify | Decor_Maximize |
831 self->functions = Func_Resize | Func_Move | Func_Iconify | Func_Maximize |
833 if (self->delete_window) {
834 self->decorations |= Decor_Close;
835 self->functions |= Func_Close;
838 if (!(self->min_size.width < self->max_size.width ||
839 self->min_size.height < self->max_size.height)) {
840 self->decorations &= ~(Decor_Maximize | Decor_Handle);
841 self->functions &= ~(Func_Resize | Func_Maximize);
844 switch (self->type) {
846 /* normal windows retain all of the possible decorations and
847 functionality, and are the only windows that you can fullscreen */
848 self->functions |= Func_Fullscreen;
853 /* these windows cannot be maximized */
854 self->decorations &= ~Decor_Maximize;
855 self->functions &= ~Func_Maximize;
860 /* these windows get less functionality */
861 self->decorations &= ~(Decor_Iconify | Decor_Handle);
862 self->functions &= ~(Func_Iconify | Func_Resize);
868 /* none of these windows are manipulated by the window manager */
869 self->decorations = 0;
874 /* Mwm Hints are applied subtractively to what has already been chosen for
875 decor and functionality */
876 if (self->mwmhints.flags & MwmFlag_Decorations) {
877 if (! (self->mwmhints.decorations & MwmDecor_All)) {
878 if (! (self->mwmhints.decorations & MwmDecor_Border))
879 self->decorations &= ~Decor_Border;
880 if (! (self->mwmhints.decorations & MwmDecor_Handle))
881 self->decorations &= ~Decor_Handle;
882 if (! (self->mwmhints.decorations & MwmDecor_Title))
883 self->decorations &= ~Decor_Titlebar;
884 if (! (self->mwmhints.decorations & MwmDecor_Iconify))
885 self->decorations &= ~Decor_Iconify;
886 if (! (self->mwmhints.decorations & MwmDecor_Maximize))
887 self->decorations &= ~Decor_Maximize;
891 if (self->mwmhints.flags & MwmFlag_Functions) {
892 if (! (self->mwmhints.functions & MwmFunc_All)) {
893 if (! (self->mwmhints.functions & MwmFunc_Resize))
894 self->functions &= ~Func_Resize;
895 if (! (self->mwmhints.functions & MwmFunc_Move))
896 self->functions &= ~Func_Move;
897 if (! (self->mwmhints.functions & MwmFunc_Iconify))
898 self->functions &= ~Func_Iconify;
899 if (! (self->mwmhints.functions & MwmFunc_Maximize))
900 self->functions &= ~Func_Maximize;
901 /* dont let mwm hints kill the close button
902 if (! (self->mwmhints.functions & MwmFunc_Close))
903 self->functions &= ~Func_Close; */
907 /* can't maximize without moving/resizing */
908 if (!((self->functions & Func_Move) && (self->functions & Func_Resize)))
909 self->functions &= ~(Func_Maximize | Func_Fullscreen);
911 /* finally, user specified disabled decorations are applied to subtract
913 if (self->disabled_decorations & Decor_Titlebar)
914 self->decorations &= ~Decor_Titlebar;
915 if (self->disabled_decorations & Decor_Handle)
916 self->decorations &= ~Decor_Handle;
917 if (self->disabled_decorations & Decor_Border)
918 self->decorations &= ~Decor_Border;
919 if (self->disabled_decorations & Decor_Iconify)
920 self->decorations &= ~Decor_Iconify;
921 if (self->disabled_decorations & Decor_Maximize)
922 self->decorations &= ~Decor_Maximize;
923 if (self->disabled_decorations & Decor_AllDesktops)
924 self->decorations &= ~Decor_AllDesktops;
925 if (self->disabled_decorations & Decor_Shade)
926 self->decorations &= ~Decor_Shade;
927 if (self->disabled_decorations & Decor_Close)
928 self->decorations &= ~Decor_Close;
930 /* if we don't have a titlebar, then we cannot shade! */
931 if (!(self->decorations & Decor_Titlebar))
932 self->functions &= ~Func_Shade;
934 /* now we need to check against rules for the client's current state */
935 if (self->fullscreen) {
936 self->functions &= (Func_Close | Func_Fullscreen | Func_Iconify);
937 self->decorations = 0;
940 client_change_allowed_actions(self);
943 /* change the decors on the frame, and with more/less decorations,
944 we may also need to be repositioned */
945 frame_adjust_area(self->frame, TRUE, TRUE);
946 /* with new decor, the window's maximized size may change */
947 client_remaximize(self);
951 static void client_change_allowed_actions(Client *self)
956 actions[num++] = prop_atoms.net_wm_action_change_desktop;
958 if (self->functions & Func_Shade)
959 actions[num++] = prop_atoms.net_wm_action_shade;
960 if (self->functions & Func_Close)
961 actions[num++] = prop_atoms.net_wm_action_close;
962 if (self->functions & Func_Move)
963 actions[num++] = prop_atoms.net_wm_action_move;
964 if (self->functions & Func_Iconify)
965 actions[num++] = prop_atoms.net_wm_action_minimize;
966 if (self->functions & Func_Resize)
967 actions[num++] = prop_atoms.net_wm_action_resize;
968 if (self->functions & Func_Fullscreen)
969 actions[num++] = prop_atoms.net_wm_action_fullscreen;
970 if (self->functions & Func_Maximize) {
971 actions[num++] = prop_atoms.net_wm_action_maximize_horz;
972 actions[num++] = prop_atoms.net_wm_action_maximize_vert;
975 PROP_SETA32(self->window, net_wm_allowed_actions, atom, actions, num);
977 /* make sure the window isn't breaking any rules now */
979 if (!(self->functions & Func_Shade) && self->shaded) {
980 if (self->frame) client_shade(self, FALSE);
981 else self->shaded = FALSE;
983 if (!(self->functions & Func_Iconify) && self->iconic) {
984 g_message("UNSETTING ICONIC");
985 if (self->frame) client_iconify(self, FALSE, TRUE);
986 else self->iconic = FALSE;
988 if (!(self->functions & Func_Fullscreen) && self->fullscreen) {
989 if (self->frame) client_fullscreen(self, FALSE, TRUE);
990 else self->fullscreen = FALSE;
992 if (!(self->functions & Func_Maximize) && (self->max_horz ||
994 if (self->frame) client_maximize(self, FALSE, 0, TRUE);
995 else self->max_vert = self->max_horz = FALSE;
999 void client_remaximize(Client *self)
1002 if (self->max_horz && self->max_vert)
1004 else if (self->max_horz)
1006 else if (self->max_vert)
1009 return; /* not maximized */
1010 self->max_horz = self->max_vert = FALSE;
1011 client_maximize(self, TRUE, dir, FALSE);
1014 void client_update_wmhints(Client *self)
1017 gboolean ur = FALSE;
1020 /* assume a window takes input if it doesnt specify */
1021 self->can_focus = TRUE;
1023 if ((hints = XGetWMHints(ob_display, self->window)) != NULL) {
1024 if (hints->flags & InputHint)
1025 self->can_focus = hints->input;
1027 /* only do this when first managing the window *AND* when we aren't
1029 if (ob_state != State_Starting && self->frame == NULL)
1030 if (hints->flags & StateHint)
1031 self->iconic = hints->initial_state == IconicState;
1033 if (hints->flags & XUrgencyHint)
1036 if (!(hints->flags & WindowGroupHint))
1037 hints->window_group = None; /* no group */
1038 /* did the group state change? */
1039 if (hints->window_group != (self->group ? self->group->leader : None)){
1040 /* remove from the old group if there was one */
1041 if (self->group != NULL) {
1042 group_remove(self->group, self);
1044 /* remove transients of the group */
1045 for (it = self->group->members; it; it = it->next)
1046 if (it->data != self &&
1047 ((Client*)it->data)->transient_for == TRAN_GROUP) {
1048 self->transients = g_slist_remove(self->transients,
1053 if (hints->window_group != None)
1054 self->group = group_add(hints->window_group, self);
1056 /* add other transients of the group that are already set up */
1057 for (it = self->group->members; it; it = it->next)
1058 if (it->data != self &&
1059 ((Client*)it->data)->transient_for == TRAN_GROUP)
1060 self->transients = g_slist_append(self->transients,
1063 /* because the self->transient flag wont change from this call,
1064 we don't need to update the window's type and such, only its
1065 transient_for, and the transients lists of other windows in the
1066 group may be affected */
1067 client_update_transient_for(self);
1070 if (hints->flags & IconPixmapHint) {
1071 client_update_kwm_icon(self);
1072 /* try get the kwm icon first, this is a fallback only */
1073 if (self->pixmap_icon == None) {
1074 self->pixmap_icon = hints->icon_pixmap;
1075 if (hints->flags & IconMaskHint)
1076 self->pixmap_icon_mask = hints->icon_mask;
1078 self->pixmap_icon_mask = None;
1081 frame_adjust_icon(self->frame);
1088 if (ur != self->urgent) {
1090 g_message("Urgent Hint for 0x%lx: %s", self->window,
1092 /* fire the urgent callback if we're mapped, otherwise, wait until
1093 after we're mapped */
1095 dispatch_client(Event_Client_Urgent, self, self->urgent, 0);
1099 void client_update_title(Client *self)
1103 g_free(self->title);
1106 if (!PROP_GETS(self->window, net_wm_name, utf8, &data))
1107 /* try old x stuff */
1108 if (!PROP_GETS(self->window, wm_name, locale, &data))
1109 data = g_strdup("Unnamed Window");
1111 /* look for duplicates and append a number */
1113 PROP_SETS(self->window, net_wm_visible_name, data);
1118 frame_adjust_title(self->frame);
1121 void client_update_icon_title(Client *self)
1125 g_free(self->icon_title);
1128 if (!PROP_GETS(self->window, net_wm_icon_name, utf8, &data))
1129 /* try old x stuff */
1130 if (!PROP_GETS(self->window, wm_icon_name, locale, &data))
1131 data = g_strdup("Unnamed Window");
1133 PROP_SETS(self->window, net_wm_visible_icon_name, data);
1135 self->icon_title = data;
1138 void client_update_class(Client *self)
1143 if (self->name) g_free(self->name);
1144 if (self->class) g_free(self->class);
1145 if (self->role) g_free(self->role);
1147 self->name = self->class = self->role = NULL;
1149 if (PROP_GETSS(self->window, wm_class, locale, &data)) {
1151 self->name = g_strdup(data[0]);
1153 self->class = g_strdup(data[1]);
1158 if (PROP_GETS(self->window, wm_window_role, locale, &s))
1159 self->role = g_strdup(s);
1161 if (self->name == NULL) self->name = g_strdup("");
1162 if (self->class == NULL) self->class = g_strdup("");
1163 if (self->role == NULL) self->role = g_strdup("");
1166 void client_update_strut(Client *self)
1171 if (!PROP_GETA32(self->window, net_wm_strut, cardinal, &data, &num)) {
1172 STRUT_SET(self->strut, 0, 0, 0, 0);
1175 STRUT_SET(self->strut, data[0], data[2], data[1], data[3]);
1177 STRUT_SET(self->strut, 0, 0, 0, 0);
1181 /* updating here is pointless while we're being mapped cuz we're not in
1182 the client list yet */
1184 screen_update_struts();
1187 void client_update_icons(Client *self)
1194 for (j = 0; j < self->nicons; ++j)
1195 g_free(self->icons[j].data);
1196 if (self->nicons > 0)
1197 g_free(self->icons);
1200 if (PROP_GETA32(self->window, net_wm_icon, cardinal, &data, &num)) {
1201 /* figure out how many valid icons are in here */
1203 while (num - i > 2) {
1211 self->icons = g_new(Icon, self->nicons);
1213 /* store the icons */
1215 for (j = 0; j < self->nicons; ++j) {
1216 w = self->icons[j].width = data[i++];
1217 h = self->icons[j].height = data[i++];
1218 self->icons[j].data =
1219 g_memdup(&data[i], w * h * sizeof(gulong));
1228 frame_adjust_icon(self->frame);
1231 void client_update_kwm_icon(Client *self)
1236 if (!PROP_GETA32(self->window, kwm_win_icon, kwm_win_icon, &data, &num)) {
1237 self->pixmap_icon = self->pixmap_icon_mask = None;
1240 self->pixmap_icon = data[0];
1241 self->pixmap_icon_mask = data[1];
1243 self->pixmap_icon = self->pixmap_icon_mask = None;
1247 frame_adjust_icon(self->frame);
1250 static void client_change_state(Client *self)
1253 guint32 netstate[10];
1256 state[0] = self->wmstate;
1258 PROP_SETA32(self->window, wm_state, wm_state, state, 2);
1262 netstate[num++] = prop_atoms.net_wm_state_modal;
1264 netstate[num++] = prop_atoms.net_wm_state_shaded;
1266 netstate[num++] = prop_atoms.net_wm_state_hidden;
1267 if (self->skip_taskbar)
1268 netstate[num++] = prop_atoms.net_wm_state_skip_taskbar;
1269 if (self->skip_pager)
1270 netstate[num++] = prop_atoms.net_wm_state_skip_pager;
1271 if (self->fullscreen)
1272 netstate[num++] = prop_atoms.net_wm_state_fullscreen;
1274 netstate[num++] = prop_atoms.net_wm_state_maximized_vert;
1276 netstate[num++] = prop_atoms.net_wm_state_maximized_horz;
1278 netstate[num++] = prop_atoms.net_wm_state_above;
1280 netstate[num++] = prop_atoms.net_wm_state_below;
1281 PROP_SETA32(self->window, net_wm_state, atom, netstate, num);
1283 client_calc_layer(self);
1286 frame_adjust_state(self->frame);
1289 static Client *search_focus_tree(Client *node, Client *skip)
1294 for (it = node->transients; it != NULL; it = it->next) {
1295 Client *c = it->data;
1296 if (c == skip) continue; /* circular? */
1297 if ((ret = search_focus_tree(c, skip))) return ret;
1298 if (client_focused(c)) return c;
1303 static void calc_recursive(Client *self, StackLayer l, gboolean raised)
1311 for (it = self->transients; it; it = it->next)
1312 calc_recursive(it->data, l, raised ? raised : l != old);
1314 if (!raised && l != old)
1316 stacking_raise(self);
1319 void client_calc_layer(Client *self)
1324 /* transients take on the layer of their parents */
1325 if (self->transient_for) {
1326 if (self->transient_for != TRAN_GROUP) {
1327 self = self->transient_for;
1331 for (it = self->group->members; it; it = it->next)
1332 if (it->data != self &&
1333 ((Client*)it->data)->transient_for != TRAN_GROUP) {
1340 /* is us or one of our transients focused? */
1341 if (client_focused(self))
1343 else if (search_focus_tree(self, self))
1348 if (self->iconic) l = Layer_Icon;
1349 /* fullscreen windows are only in the fullscreen layer while focused */
1350 else if (self->fullscreen && f) l = Layer_Fullscreen;
1351 else if (self->type == Type_Desktop) l = Layer_Desktop;
1352 else if (self->type == Type_Dock) {
1353 if (!self->below) l = Layer_Top;
1354 else l = Layer_Normal;
1356 else if (self->above) l = Layer_Above;
1357 else if (self->below) l = Layer_Below;
1358 else l = Layer_Normal;
1360 calc_recursive(self, l, FALSE);
1363 gboolean client_should_show(Client *self)
1365 if (self->iconic) return FALSE;
1366 else if (!(self->desktop == screen_desktop ||
1367 self->desktop == DESKTOP_ALL)) return FALSE;
1368 else if (client_normal(self) && screen_showing_desktop) return FALSE;
1373 static void client_showhide(Client *self)
1376 if (client_should_show(self))
1377 frame_show(self->frame);
1379 frame_hide(self->frame);
1382 gboolean client_normal(Client *self) {
1383 return ! (self->type == Type_Desktop || self->type == Type_Dock ||
1384 self->type == Type_Splash);
1387 static void client_apply_startup_state(Client *self)
1389 /* these are in a carefully crafted order.. */
1392 self->iconic = FALSE;
1393 client_iconify(self, TRUE, FALSE);
1395 if (self->fullscreen) {
1396 self->fullscreen = FALSE;
1397 client_fullscreen(self, TRUE, FALSE);
1400 self->shaded = FALSE;
1401 client_shade(self, TRUE);
1404 dispatch_client(Event_Client_Urgent, self, self->urgent, 0);
1406 if (self->max_vert && self->max_horz) {
1407 self->max_vert = self->max_horz = FALSE;
1408 client_maximize(self, TRUE, 0, FALSE);
1409 } else if (self->max_vert) {
1410 self->max_vert = FALSE;
1411 client_maximize(self, TRUE, 2, FALSE);
1412 } else if (self->max_horz) {
1413 self->max_horz = FALSE;
1414 client_maximize(self, TRUE, 1, FALSE);
1417 /* nothing to do for the other states:
1426 void client_configure(Client *self, Corner anchor, int x, int y, int w, int h,
1427 gboolean user, gboolean final)
1429 gboolean moved = FALSE, resized = FALSE;
1431 /* gets the frame's position */
1432 frame_client_gravity(self->frame, &x, &y);
1434 /* these positions are frame positions, not client positions */
1436 /* set the size and position if fullscreen */
1437 if (self->fullscreen) {
1440 w = screen_physical_size.width;
1441 h = screen_physical_size.height;
1442 user = FALSE; /* ignore that increment etc shit when in fullscreen */
1444 /* set the size and position if maximized */
1445 if (self->max_horz) {
1446 x = screen_area(self->desktop)->x - self->frame->size.left;
1447 w = screen_area(self->desktop)->width;
1449 if (self->max_vert) {
1450 y = screen_area(self->desktop)->y;
1451 h = screen_area(self->desktop)->height -
1452 self->frame->size.top - self->frame->size.bottom;
1456 /* gets the client's position */
1457 frame_frame_gravity(self->frame, &x, &y);
1459 /* these override the above states! if you cant move you can't move! */
1461 if (!(self->functions & Func_Move)) {
1465 if (!(self->functions & Func_Resize)) {
1466 w = self->area.width;
1467 h = self->area.height;
1471 if (!(w == self->area.width && h == self->area.height)) {
1472 w -= self->base_size.width;
1473 h -= self->base_size.height;
1476 /* for interactive resizing. have to move half an increment in each
1479 /* how far we are towards the next size inc */
1480 int mw = w % self->size_inc.width;
1481 int mh = h % self->size_inc.height;
1483 int aw = self->size_inc.width / 2;
1484 int ah = self->size_inc.height / 2;
1485 /* don't let us move into a new size increment */
1486 if (mw + aw >= self->size_inc.width)
1487 aw = self->size_inc.width - mw - 1;
1488 if (mh + ah >= self->size_inc.height)
1489 ah = self->size_inc.height - mh - 1;
1493 /* if this is a user-requested resize, then check against min/max
1494 sizes and aspect ratios */
1496 /* smaller than min size or bigger than max size? */
1497 if (w > self->max_size.width) w = self->max_size.width;
1498 if (w < self->min_size.width) w = self->min_size.width;
1499 if (h > self->max_size.height) h = self->max_size.height;
1500 if (h < self->min_size.height) h = self->min_size.height;
1502 /* adjust the height ot match the width for the aspect ratios */
1503 if (self->min_ratio)
1504 if (h * self->min_ratio > w) h = (int)(w / self->min_ratio);
1505 if (self->max_ratio)
1506 if (h * self->max_ratio < w) h = (int)(w / self->max_ratio);
1509 /* keep to the increments */
1510 w /= self->size_inc.width;
1511 h /= self->size_inc.height;
1513 /* you cannot resize to nothing */
1517 /* store the logical size */
1518 SIZE_SET(self->logical_size, w, h);
1520 w *= self->size_inc.width;
1521 h *= self->size_inc.height;
1523 w += self->base_size.width;
1524 h += self->base_size.height;
1528 case Corner_TopLeft:
1530 case Corner_TopRight:
1531 x -= w - self->area.width;
1533 case Corner_BottomLeft:
1534 y -= h - self->area.height;
1536 case Corner_BottomRight:
1537 x -= w - self->area.width;
1538 y -= h - self->area.height;
1542 moved = x != self->area.x || y != self->area.y;
1543 resized = w != self->area.width || h != self->area.height;
1545 RECT_SET(self->area, x, y, w, h);
1548 XResizeWindow(ob_display, self->window, w, h);
1550 /* move/resize the frame to match the request */
1552 if (moved || resized)
1553 frame_adjust_area(self->frame, moved, resized);
1555 if (!user || final) {
1557 event.type = ConfigureNotify;
1558 event.xconfigure.display = ob_display;
1559 event.xconfigure.event = self->window;
1560 event.xconfigure.window = self->window;
1562 /* root window coords with border in mind */
1563 event.xconfigure.x = x - self->border_width +
1564 self->frame->size.left;
1565 event.xconfigure.y = y - self->border_width +
1566 self->frame->size.top;
1568 event.xconfigure.width = self->area.width;
1569 event.xconfigure.height = self->area.height;
1570 event.xconfigure.border_width = self->border_width;
1571 event.xconfigure.above = self->frame->plate;
1572 event.xconfigure.override_redirect = FALSE;
1573 XSendEvent(event.xconfigure.display, event.xconfigure.window,
1574 FALSE, StructureNotifyMask, &event);
1579 void client_fullscreen(Client *self, gboolean fs, gboolean savearea)
1583 if (!(self->functions & Func_Fullscreen) || /* can't */
1584 self->fullscreen == fs) return; /* already done */
1586 self->fullscreen = fs;
1587 client_change_state(self); /* change the state hints on the client,
1588 and adjust out layer/stacking */
1592 guint32 dimensions[4];
1593 dimensions[0] = self->area.x;
1594 dimensions[1] = self->area.y;
1595 dimensions[2] = self->area.width;
1596 dimensions[3] = self->area.height;
1598 PROP_SETA32(self->window, openbox_premax, cardinal,
1602 /* these are not actually used cuz client_configure will set them
1603 as appropriate when the window is fullscreened */
1609 /* pick some fallbacks... */
1610 x = screen_area(self->desktop)->x +
1611 screen_area(self->desktop)->width / 4;
1612 y = screen_area(self->desktop)->y +
1613 screen_area(self->desktop)->height / 4;
1614 w = screen_area(self->desktop)->width / 2;
1615 h = screen_area(self->desktop)->height / 2;
1617 if (PROP_GETA32(self->window, openbox_premax, cardinal,
1618 (guint32**)&dimensions, &num)) {
1629 client_setup_decor_and_functions(self);
1631 client_configure(self, Corner_TopLeft, x, y, w, h, TRUE, TRUE);
1633 /* try focus us when we go into fullscreen mode */
1637 void client_iconify(Client *self, gboolean iconic, gboolean curdesk)
1641 /* move up the transient chain as far as possible first if deiconifying */
1643 while (self->transient_for) {
1644 if (self->transient_for != TRAN_GROUP) {
1645 if (self->transient_for->iconic == iconic)
1647 self = self->transient_for;
1651 /* the check for TRAN_GROUP is to prevent an infinate loop with
1652 2 transients of the same group at the head of the group's
1654 for (it = self->group->members; it; it = it->next) {
1655 Client *c = it->data;
1657 if (c != self && c->transient_for->iconic != iconic &&
1658 c->transient_for != TRAN_GROUP) {
1663 if (it == NULL) break;
1667 if (self->iconic == iconic) return; /* nothing to do */
1669 g_message("%sconifying window: 0x%lx", (iconic ? "I" : "Uni"),
1672 self->iconic = iconic;
1675 self->wmstate = IconicState;
1676 self->ignore_unmaps++;
1677 /* we unmap the client itself so that we can get MapRequest events,
1678 and because the ICCCM tells us to! */
1679 XUnmapWindow(ob_display, self->window);
1682 client_set_desktop(self, screen_desktop, FALSE);
1683 self->wmstate = self->shaded ? IconicState : NormalState;
1684 XMapWindow(ob_display, self->window);
1686 client_change_state(self);
1687 client_showhide(self);
1688 screen_update_struts();
1690 dispatch_client(iconic ? Event_Client_Unmapped : Event_Client_Mapped,
1693 /* iconify all transients */
1694 for (it = self->transients; it != NULL; it = it->next)
1695 if (it->data != self) client_iconify(it->data, iconic, curdesk);
1698 void client_maximize(Client *self, gboolean max, int dir, gboolean savearea)
1702 g_assert(dir == 0 || dir == 1 || dir == 2);
1703 if (!(self->functions & Func_Maximize)) return; /* can't */
1705 /* check if already done */
1707 if (dir == 0 && self->max_horz && self->max_vert) return;
1708 if (dir == 1 && self->max_horz) return;
1709 if (dir == 2 && self->max_vert) return;
1711 if (dir == 0 && !self->max_horz && !self->max_vert) return;
1712 if (dir == 1 && !self->max_horz) return;
1713 if (dir == 2 && !self->max_vert) return;
1716 /* work with the frame's coords */
1717 x = self->frame->area.x;
1718 y = self->frame->area.y;
1719 w = self->area.width;
1720 h = self->area.height;
1724 gint32 dimensions[4];
1733 /* get the property off the window and use it for the dimensions
1734 we are already maxed on */
1735 if (PROP_GETA32(self->window, openbox_premax, cardinal,
1736 (guint32**)&readdim, &num)) {
1738 if (self->max_horz) {
1739 dimensions[0] = readdim[0];
1740 dimensions[2] = readdim[2];
1742 if (self->max_vert) {
1743 dimensions[1] = readdim[1];
1744 dimensions[3] = readdim[3];
1750 PROP_SETA32(self->window, openbox_premax, cardinal,
1751 (guint32*)dimensions, 4);
1757 /* pick some fallbacks... */
1758 if (dir == 0 || dir == 1) { /* horz */
1759 x = screen_area(self->desktop)->x +
1760 screen_area(self->desktop)->width / 4;
1761 w = screen_area(self->desktop)->width / 2;
1763 if (dir == 0 || dir == 2) { /* vert */
1764 y = screen_area(self->desktop)->y +
1765 screen_area(self->desktop)->height / 4;
1766 h = screen_area(self->desktop)->height / 2;
1769 if (PROP_GETA32(self->window, openbox_premax, cardinal,
1770 (guint32**)&dimensions, &num)) {
1772 if (dir == 0 || dir == 1) { /* horz */
1776 if (dir == 0 || dir == 2) { /* vert */
1785 if (dir == 0 || dir == 1) /* horz */
1786 self->max_horz = max;
1787 if (dir == 0 || dir == 2) /* vert */
1788 self->max_vert = max;
1790 if (!self->max_horz && !self->max_vert)
1791 PROP_ERASE(self->window, openbox_premax);
1793 client_change_state(self); /* change the state hints on the client */
1795 /* figure out where the client should be going */
1796 frame_frame_gravity(self->frame, &x, &y);
1797 client_configure(self, Corner_TopLeft, x, y, w, h, TRUE, TRUE);
1800 void client_shade(Client *self, gboolean shade)
1802 if ((!(self->functions & Func_Shade) && shade) || /* can't shade */
1803 self->shaded == shade) return; /* already done */
1805 /* when we're iconic, don't change the wmstate */
1807 self->wmstate = shade ? IconicState : NormalState;
1808 self->shaded = shade;
1809 client_change_state(self);
1810 /* resize the frame to just the titlebar */
1811 frame_adjust_area(self->frame, FALSE, FALSE);
1814 void client_close(Client *self)
1818 if (!(self->functions & Func_Close)) return;
1821 XXX: itd be cool to do timeouts and shit here for killing the client's
1823 like... if the window is around after 5 seconds, then the close button
1824 turns a nice red, and if this function is called again, the client is
1828 ce.xclient.type = ClientMessage;
1829 ce.xclient.message_type = prop_atoms.wm_protocols;
1830 ce.xclient.display = ob_display;
1831 ce.xclient.window = self->window;
1832 ce.xclient.format = 32;
1833 ce.xclient.data.l[0] = prop_atoms.wm_delete_window;
1834 ce.xclient.data.l[1] = event_lasttime;
1835 ce.xclient.data.l[2] = 0l;
1836 ce.xclient.data.l[3] = 0l;
1837 ce.xclient.data.l[4] = 0l;
1838 XSendEvent(ob_display, self->window, FALSE, NoEventMask, &ce);
1841 void client_kill(Client *self)
1843 XKillClient(ob_display, self->window);
1846 void client_set_desktop(Client *self, guint target, gboolean donthide)
1850 if (target == self->desktop) return;
1852 g_message("Setting desktop %u", target);
1854 g_assert(target < screen_num_desktops || target == DESKTOP_ALL);
1856 old = self->desktop;
1857 self->desktop = target;
1858 PROP_SET32(self->window, net_wm_desktop, cardinal, target);
1859 /* the frame can display the current desktop state */
1860 frame_adjust_state(self->frame);
1861 /* 'move' the window to the new desktop */
1863 client_showhide(self);
1864 /* raise if it was not already on the desktop */
1865 if (old != DESKTOP_ALL)
1866 stacking_raise(self);
1867 screen_update_struts();
1869 /* update the focus lists */
1870 if (old == DESKTOP_ALL) {
1871 for (i = 0; i < screen_num_desktops; ++i)
1872 focus_order[i] = g_list_remove(focus_order[i], self);
1874 focus_order[old] = g_list_remove(focus_order[old], self);
1875 if (target == DESKTOP_ALL) {
1876 for (i = 0; i < screen_num_desktops; ++i) {
1877 if (config_focus_new)
1878 focus_order[i] = g_list_prepend(focus_order[i], self);
1880 focus_order[i] = g_list_append(focus_order[i], self);
1883 if (config_focus_new)
1884 focus_order[target] = g_list_prepend(focus_order[target], self);
1886 focus_order[target] = g_list_append(focus_order[target], self);
1889 dispatch_client(Event_Client_Desktop, self, target, old);
1892 static Client *search_modal_tree(Client *node, Client *skip)
1897 for (it = node->transients; it != NULL; it = it->next) {
1898 Client *c = it->data;
1899 if (c == skip) continue; /* circular? */
1900 if ((ret = search_modal_tree(c, skip))) return ret;
1901 if (c->modal) return c;
1906 Client *client_find_modal_child(Client *self)
1908 return search_modal_tree(self, self);
1911 gboolean client_validate(Client *self)
1915 XSync(ob_display, FALSE); /* get all events on the server */
1917 if (XCheckTypedWindowEvent(ob_display, self->window, DestroyNotify, &e) ||
1918 XCheckTypedWindowEvent(ob_display, self->window, UnmapNotify, &e)) {
1919 XPutBackEvent(ob_display, &e);
1926 void client_set_wm_state(Client *self, long state)
1928 if (state == self->wmstate) return; /* no change */
1932 client_iconify(self, TRUE, TRUE);
1935 client_iconify(self, FALSE, TRUE);
1940 void client_set_state(Client *self, Atom action, long data1, long data2)
1942 gboolean shaded = self->shaded;
1943 gboolean fullscreen = self->fullscreen;
1944 gboolean max_horz = self->max_horz;
1945 gboolean max_vert = self->max_vert;
1948 if (!(action == prop_atoms.net_wm_state_add ||
1949 action == prop_atoms.net_wm_state_remove ||
1950 action == prop_atoms.net_wm_state_toggle))
1951 /* an invalid action was passed to the client message, ignore it */
1954 for (i = 0; i < 2; ++i) {
1955 Atom state = i == 0 ? data1 : data2;
1957 if (!state) continue;
1959 /* if toggling, then pick whether we're adding or removing */
1960 if (action == prop_atoms.net_wm_state_toggle) {
1961 if (state == prop_atoms.net_wm_state_modal)
1962 action = self->modal ? prop_atoms.net_wm_state_remove :
1963 prop_atoms.net_wm_state_add;
1964 else if (state == prop_atoms.net_wm_state_maximized_vert)
1965 action = self->max_vert ? prop_atoms.net_wm_state_remove :
1966 prop_atoms.net_wm_state_add;
1967 else if (state == prop_atoms.net_wm_state_maximized_horz)
1968 action = self->max_horz ? prop_atoms.net_wm_state_remove :
1969 prop_atoms.net_wm_state_add;
1970 else if (state == prop_atoms.net_wm_state_shaded)
1971 action = self->shaded ? prop_atoms.net_wm_state_remove :
1972 prop_atoms.net_wm_state_add;
1973 else if (state == prop_atoms.net_wm_state_skip_taskbar)
1974 action = self->skip_taskbar ?
1975 prop_atoms.net_wm_state_remove :
1976 prop_atoms.net_wm_state_add;
1977 else if (state == prop_atoms.net_wm_state_skip_pager)
1978 action = self->skip_pager ?
1979 prop_atoms.net_wm_state_remove :
1980 prop_atoms.net_wm_state_add;
1981 else if (state == prop_atoms.net_wm_state_fullscreen)
1982 action = self->fullscreen ?
1983 prop_atoms.net_wm_state_remove :
1984 prop_atoms.net_wm_state_add;
1985 else if (state == prop_atoms.net_wm_state_above)
1986 action = self->above ? prop_atoms.net_wm_state_remove :
1987 prop_atoms.net_wm_state_add;
1988 else if (state == prop_atoms.net_wm_state_below)
1989 action = self->below ? prop_atoms.net_wm_state_remove :
1990 prop_atoms.net_wm_state_add;
1993 if (action == prop_atoms.net_wm_state_add) {
1994 if (state == prop_atoms.net_wm_state_modal) {
1995 /* XXX raise here or something? */
1997 } else if (state == prop_atoms.net_wm_state_maximized_vert) {
1999 } else if (state == prop_atoms.net_wm_state_maximized_horz) {
2001 } else if (state == prop_atoms.net_wm_state_shaded) {
2003 } else if (state == prop_atoms.net_wm_state_skip_taskbar) {
2004 self->skip_taskbar = TRUE;
2005 } else if (state == prop_atoms.net_wm_state_skip_pager) {
2006 self->skip_pager = TRUE;
2007 } else if (state == prop_atoms.net_wm_state_fullscreen) {
2009 } else if (state == prop_atoms.net_wm_state_above) {
2011 } else if (state == prop_atoms.net_wm_state_below) {
2015 } else { /* action == prop_atoms.net_wm_state_remove */
2016 if (state == prop_atoms.net_wm_state_modal) {
2017 self->modal = FALSE;
2018 } else if (state == prop_atoms.net_wm_state_maximized_vert) {
2020 } else if (state == prop_atoms.net_wm_state_maximized_horz) {
2022 } else if (state == prop_atoms.net_wm_state_shaded) {
2024 } else if (state == prop_atoms.net_wm_state_skip_taskbar) {
2025 self->skip_taskbar = FALSE;
2026 } else if (state == prop_atoms.net_wm_state_skip_pager) {
2027 self->skip_pager = FALSE;
2028 } else if (state == prop_atoms.net_wm_state_fullscreen) {
2030 } else if (state == prop_atoms.net_wm_state_above) {
2031 self->above = FALSE;
2032 } else if (state == prop_atoms.net_wm_state_below) {
2033 self->below = FALSE;
2037 if (max_horz != self->max_horz || max_vert != self->max_vert) {
2038 if (max_horz != self->max_horz && max_vert != self->max_vert) {
2040 if (max_horz == max_vert) { /* both going the same way */
2041 client_maximize(self, max_horz, 0, TRUE);
2043 client_maximize(self, max_horz, 1, TRUE);
2044 client_maximize(self, max_vert, 2, TRUE);
2048 if (max_horz != self->max_horz)
2049 client_maximize(self, max_horz, 1, TRUE);
2051 client_maximize(self, max_vert, 2, TRUE);
2054 /* change fullscreen state before shading, as it will affect if the window
2056 if (fullscreen != self->fullscreen)
2057 client_fullscreen(self, fullscreen, TRUE);
2058 if (shaded != self->shaded)
2059 client_shade(self, shaded);
2060 client_calc_layer(self);
2061 client_change_state(self); /* change the hint to relect these changes */
2064 Client *client_focus_target(Client *self)
2068 /* if we have a modal child, then focus it, not us */
2069 child = client_find_modal_child(self);
2070 if (child) return child;
2074 gboolean client_focusable(Client *self)
2076 /* won't try focus if the client doesn't want it, or if the window isn't
2077 visible on the screen */
2078 return self->frame->visible &&
2079 (self->can_focus || self->focus_notify);
2082 gboolean client_focus(Client *self)
2086 /* choose the correct target */
2087 self = client_focus_target(self);
2089 if (!client_focusable(self))
2092 /* do a check to see if the window has already been unmapped or destroyed
2093 do this intelligently while watching out for unmaps we've generated
2094 (ignore_unmaps > 0) */
2095 if (XCheckTypedWindowEvent(ob_display, self->window,
2096 DestroyNotify, &ev)) {
2097 XPutBackEvent(ob_display, &ev);
2100 while (XCheckTypedWindowEvent(ob_display, self->window,
2101 UnmapNotify, &ev)) {
2102 if (self->ignore_unmaps) {
2103 self->ignore_unmaps--;
2105 XPutBackEvent(ob_display, &ev);
2110 if (self->can_focus)
2111 /* RevertToPointerRoot causes much more headache than TevertToNone, so
2112 I choose to use it always, hopefully to find errors quicker, if any
2113 are left. (I hate X. I hate focus events.) */
2114 XSetInputFocus(ob_display, self->window, RevertToPointerRoot,
2117 if (self->focus_notify) {
2119 ce.xclient.type = ClientMessage;
2120 ce.xclient.message_type = prop_atoms.wm_protocols;
2121 ce.xclient.display = ob_display;
2122 ce.xclient.window = self->window;
2123 ce.xclient.format = 32;
2124 ce.xclient.data.l[0] = prop_atoms.wm_take_focus;
2125 ce.xclient.data.l[1] = event_lasttime;
2126 ce.xclient.data.l[2] = 0l;
2127 ce.xclient.data.l[3] = 0l;
2128 ce.xclient.data.l[4] = 0l;
2129 XSendEvent(ob_display, self->window, FALSE, NoEventMask, &ce);
2133 g_message("focusing %lx", self->window);
2136 /* Cause the FocusIn to come back to us. Important for desktop switches,
2137 since otherwise we'll have no FocusIn on the queue and send it off to
2138 the focus_backup. */
2139 XSync(ob_display, FALSE);
2143 void client_unfocus(Client *self)
2145 g_assert(focus_client == self);
2147 g_message("client_unfocus");
2149 focus_fallback(Fallback_Unfocusing);
2152 gboolean client_focused(Client *self)
2154 return self == focus_client;
2157 Icon *client_icon(Client *self, int w, int h)
2160 /* si is the smallest image >= req */
2161 /* li is the largest image < req */
2162 unsigned long size, smallest = 0xffffffff, largest = 0, si = 0, li = 0;
2164 if (!self->nicons) return NULL;
2166 for (i = 0; i < self->nicons; ++i) {
2167 size = self->icons[i].width * self->icons[i].height;
2168 if (size < smallest && size >= (unsigned)(w * h)) {
2172 if (size > largest && size <= (unsigned)(w * h)) {
2177 if (largest == 0) /* didnt find one smaller than the requested size */
2178 return &self->icons[si];
2179 return &self->icons[li];