4 #include "extensions.h"
14 #include <X11/Xutil.h>
16 /*! The event mask to grab on client windows */
17 #define CLIENT_EVENTMASK (PropertyChangeMask | FocusChangeMask | \
20 #define CLIENT_NOPROPAGATEMASK (ButtonPressMask | ButtonReleaseMask | \
23 GSList *client_list = NULL;
24 GHashTable *client_map = NULL;
26 static void client_get_all(Client *self);
27 static void client_toggle_border(Client *self, gboolean show);
28 static void client_get_area(Client *self);
29 static void client_get_desktop(Client *self);
30 static void client_get_state(Client *self);
31 static void client_get_shaped(Client *self);
32 static void client_get_mwm_hints(Client *self);
33 static void client_get_gravity(Client *self);
34 static void client_showhide(Client *self);
35 static void client_change_allowed_actions(Client *self);
36 static void client_change_state(Client *self);
37 static Client *search_focus_tree(Client *node, Client *skip);
38 static void client_apply_startup_state(Client *self);
39 static Client *search_modal_tree(Client *node, Client *skip);
41 static guint map_hash(Window w) { return w; }
42 static gboolean map_key_comp(Window w1, Window w2) { return w1 == w2; }
46 client_map = g_hash_table_new((GHashFunc)map_hash,
47 (GEqualFunc)map_key_comp);
51 void client_shutdown()
53 g_hash_table_destroy(client_map);
56 void client_set_list()
58 Window *windows, *win_it;
60 guint size = g_slist_length(client_list);
62 /* create an array of the window ids */
64 windows = g_new(Window, size);
66 for (it = client_list; it != NULL; it = it->next, ++win_it)
67 *win_it = ((Client*)it->data)->window;
71 PROP_SET32A(ob_root, net_client_list, window, windows, size);
79 void client_manage_all()
81 unsigned int i, j, nchild;
84 XWindowAttributes attrib;
86 XQueryTree(ob_display, ob_root, &w, &w, &children, &nchild);
88 /* remove all icon windows from the list */
89 for (i = 0; i < nchild; i++) {
90 if (children[i] == None) continue;
91 wmhints = XGetWMHints(ob_display, children[i]);
93 if ((wmhints->flags & IconWindowHint) &&
94 (wmhints->icon_window != children[i]))
95 for (j = 0; j < nchild; j++)
96 if (children[j] == wmhints->icon_window) {
104 for (i = 0; i < nchild; ++i) {
105 if (children[i] == None)
107 if (XGetWindowAttributes(ob_display, children[i], &attrib)) {
108 if (attrib.override_redirect) continue;
110 if (attrib.map_state != IsUnmapped)
111 client_manage(children[i]);
117 void client_manage(Window window)
121 XWindowAttributes attrib;
122 XSetWindowAttributes attrib_set;
123 /* XWMHints *wmhint; */
127 /* check if it has already been unmapped by the time we started mapping
128 the grab does a sync so we don't have to here */
129 if (XCheckTypedWindowEvent(ob_display, window, DestroyNotify, &e) ||
130 XCheckTypedWindowEvent(ob_display, window, UnmapNotify, &e)) {
131 XPutBackEvent(ob_display, &e);
134 return; /* don't manage it */
137 /* make sure it isn't an override-redirect window */
138 if (!XGetWindowAttributes(ob_display, window, &attrib) ||
139 attrib.override_redirect) {
141 return; /* don't manage it */
144 /* /\* is the window a docking app *\/
145 if ((wmhint = XGetWMHints(ob_display, window))) {
146 if ((wmhint->flags & StateHint) &&
147 wmhint->initial_state == WithdrawnState) {
148 /\* XXX: make dock apps work! *\/
157 /* choose the events we want to receive on the CLIENT window */
158 attrib_set.event_mask = CLIENT_EVENTMASK;
159 attrib_set.do_not_propagate_mask = CLIENT_NOPROPAGATEMASK;
160 XChangeWindowAttributes(ob_display, window,
161 CWEventMask|CWDontPropagate, &attrib_set);
164 /* create the Client struct, and populate it from the hints on the
166 client = g_new(Client, 1);
167 client->window = window;
168 client_get_all(client);
170 /* remove the client's border (and adjust re gravity) */
171 client_toggle_border(client, FALSE);
173 /* specify that if we exit, the window should not be destroyed and should
174 be reparented back to root automatically */
175 XChangeSaveSet(ob_display, window, SetModeInsert);
177 /* create the decoration frame for the client window */
178 client->frame = engine_frame_new();
180 engine_frame_grab_client(client->frame, client);
182 client_apply_startup_state(client);
186 client_list = g_slist_append(client_list, client);
187 stacking_list = g_list_append(stacking_list, client);
188 g_hash_table_insert(client_map, (gpointer)window, client);
190 stacking_raise(client);
192 screen_update_struts();
194 dispatch_client(Event_Client_New, client, 0, 0);
196 client_showhide(client);
198 dispatch_client(Event_Client_Mapped, client, 0, 0);
200 /* grab all mouse bindings */
201 /*pointer_grab_all(client, TRUE);XXX*/
203 /* update the list hints */
206 g_message("Managed window 0x%lx", window);
209 void client_unmanage_all()
211 while (client_list != NULL)
212 client_unmanage(client_list->data);
215 void client_unmanage(Client *client)
221 g_message("Unmanaging window: %lx", client->window);
223 dispatch_client(Event_Client_Destroy, client, 0, 0);
225 /* remove the window from our save set */
226 XChangeSaveSet(ob_display, client->window, SetModeDelete);
228 /* we dont want events no more */
229 XSelectInput(ob_display, client->window, NoEventMask);
231 /* ungrab any mouse bindings */
232 /*pointer_grab_all(client, FALSE);XXX*/
234 engine_frame_hide(client->frame);
236 /* give the client its border back */
237 client_toggle_border(client, TRUE);
239 /* reparent the window out of the frame, and free the frame */
240 engine_frame_release_client(client->frame, client);
242 client_list = g_slist_remove(client_list, client);
243 stacking_list = g_list_remove(stacking_list, client);
244 g_hash_table_remove(client_map, (gpointer)client->window);
246 /* update the focus lists */
247 if (client->desktop == DESKTOP_ALL) {
248 for (i = 0; i < screen_num_desktops; ++i)
249 focus_order[i] = g_list_remove(focus_order[i], client);
252 focus_order[i] = g_list_remove(focus_order[i], client);
255 /* once the client is out of the list, update the struts to remove it's
257 screen_update_struts();
259 /* tell our parent that we're gone */
260 if (client->transient_for != NULL)
261 client->transient_for->transients =
262 g_slist_remove(client->transient_for->transients, client);
264 /* tell our transients that we're gone */
265 for (it = client->transients; it != NULL; it = it->next) {
266 ((Client*)it->data)->transient_for = NULL;
267 client_calc_layer(it->data);
270 /* unfocus the client (dispatchs the focus event) (we're out of the
271 transient lists already, so being modal doesn't matter) */
273 client_unfocus(client);
275 if (ob_state != State_Exiting) {
276 /* these values should not be persisted across a window
278 prop_erase(client->window, prop_atoms.net_wm_desktop);
279 prop_erase(client->window, prop_atoms.net_wm_state);
281 /* if we're left in an iconic state, the client wont be mapped. this is
282 bad, since we will no longer be managing the window on restart */
284 XMapWindow(ob_display, client->window);
287 /* free all data allocated in the client struct */
288 g_slist_free(client->transients);
289 for (j = 0; j < client->nicons; ++j)
290 g_free(client->icons[j].data);
291 if (client->nicons > 0)
292 g_free(client->icons);
293 g_free(client->title);
294 g_free(client->icon_title);
295 g_free(client->res_name);
296 g_free(client->res_class);
297 g_free(client->role);
300 /* update the list hints */
304 static void client_toggle_border(Client *self, gboolean show)
306 /* adjust our idea of where the client is, based on its border. When the
307 border is removed, the client should now be considered to be in a
309 when re-adding the border to the client, the same operation needs to be
311 int oldx = self->area.x, oldy = self->area.y;
312 int x = oldx, y = oldy;
313 switch(self->gravity) {
315 case NorthWestGravity:
317 case SouthWestGravity:
319 case NorthEastGravity:
321 case SouthEastGravity:
322 if (show) x -= self->border_width * 2;
323 else x += self->border_width * 2;
330 if (show) x -= self->border_width;
331 else x += self->border_width;
334 switch(self->gravity) {
336 case NorthWestGravity:
338 case NorthEastGravity:
340 case SouthWestGravity:
342 case SouthEastGravity:
343 if (show) y -= self->border_width * 2;
344 else y += self->border_width * 2;
351 if (show) y -= self->border_width;
352 else y += self->border_width;
359 XSetWindowBorderWidth(ob_display, self->window, self->border_width);
361 /* move the client so it is back it the right spot _with_ its
363 if (x != oldx || y != oldy)
364 XMoveWindow(ob_display, self->window, x, y);
366 XSetWindowBorderWidth(ob_display, self->window, 0);
370 static void client_get_all(Client *self)
372 /* update EVERYTHING!! */
374 self->ignore_unmaps = 0;
378 self->title = self->icon_title = NULL;
379 self->res_name = self->res_class = self->role = NULL;
380 self->wmstate = NormalState;
381 self->focused = FALSE;
382 self->transient = FALSE;
383 self->transients = NULL;
384 self->transient_for = NULL;
386 self->urgent = FALSE;
387 self->positioned = FALSE;
388 self->disabled_decorations = 0;
392 client_get_area(self);
393 client_get_desktop(self);
394 client_get_state(self);
395 client_get_shaped(self);
397 client_update_transient_for(self);
398 client_get_mwm_hints(self);
399 client_get_type(self);/* this can change the mwmhints for special cases */
401 client_update_protocols(self);
403 client_get_gravity(self); /* get the attribute gravity */
404 client_update_normal_hints(self); /* this may override the attribute
407 /* got the type, the mwmhints, the protocols, and the normal hints
408 (min/max sizes), so we're ready to set up the decorations/functions */
409 client_setup_decor_and_functions(self);
411 client_update_wmhints(self);
412 client_update_title(self);
413 client_update_icon_title(self);
414 client_update_class(self);
415 client_update_strut(self);
416 client_update_icons(self);
417 client_update_kwm_icon(self);
419 /* this makes sure that these windows appear on all desktops */
420 if (self->type == Type_Desktop)
421 self->desktop = DESKTOP_ALL;
423 /* set the desktop hint, to make sure that it always exists, and to
424 reflect any changes we've made here */
425 PROP_SET32(self->window, net_wm_desktop, cardinal, self->desktop);
427 client_change_state(self);
430 static void client_get_area(Client *self)
432 XWindowAttributes wattrib;
435 ret = XGetWindowAttributes(ob_display, self->window, &wattrib);
436 g_assert(ret != BadWindow);
438 RECT_SET(self->area, wattrib.x, wattrib.y, wattrib.width, wattrib.height);
439 self->border_width = wattrib.border_width;
442 static void client_get_desktop(Client *self)
446 if (PROP_GET32(self->window, net_wm_desktop, cardinal, d)) {
447 if (d >= screen_num_desktops && d != DESKTOP_ALL)
448 d = screen_num_desktops - 1;
451 /* defaults to the current desktop */
452 self->desktop = screen_desktop;
456 static void client_get_state(Client *self)
461 self->modal = self->shaded = self->max_horz = self->max_vert =
462 self->fullscreen = self->above = self->below = self->iconic =
463 self->skip_taskbar = self->skip_pager = FALSE;
465 if (PROP_GET32U(self->window, net_wm_state, atom, state, num)) {
467 for (i = 0; i < num; ++i) {
468 if (state[i] == prop_atoms.net_wm_state_modal)
470 else if (state[i] == prop_atoms.net_wm_state_shaded)
472 else if (state[i] == prop_atoms.net_wm_state_hidden)
474 else if (state[i] == prop_atoms.net_wm_state_skip_taskbar)
475 self->skip_taskbar = TRUE;
476 else if (state[i] == prop_atoms.net_wm_state_skip_pager)
477 self->skip_pager = TRUE;
478 else if (state[i] == prop_atoms.net_wm_state_fullscreen)
479 self->fullscreen = TRUE;
480 else if (state[i] == prop_atoms.net_wm_state_maximized_vert)
481 self->max_vert = TRUE;
482 else if (state[i] == prop_atoms.net_wm_state_maximized_horz)
483 self->max_horz = TRUE;
484 else if (state[i] == prop_atoms.net_wm_state_above)
486 else if (state[i] == prop_atoms.net_wm_state_below)
494 static void client_get_shaped(Client *self)
496 self->shaped = FALSE;
498 if (extensions_shape) {
503 XShapeSelectInput(ob_display, self->window, ShapeNotifyMask);
505 XShapeQueryExtents(ob_display, self->window, &s, &foo,
506 &foo, &ufoo, &ufoo, &foo, &foo, &foo, &ufoo,
508 self->shaped = (s != 0);
513 void client_update_transient_for(Client *self)
518 if (XGetTransientForHint(ob_display, self->window, &t) &&
519 t != self->window) { /* cant be transient to itself! */
520 self->transient = TRUE;
521 c = g_hash_table_lookup(client_map, (gpointer)t);
522 g_assert(c != self);/* if this happens then we need to check for it*/
524 if (!c /*XXX: && _group*/) {
525 /* not transient to a client, see if it is transient for a
527 if (/*t == _group->leader() || */
530 /* window is a transient for its group! */
531 /* XXX: for now this is treated as non-transient.
532 this needs to be fixed! */
536 self->transient = FALSE;
538 /* if anything has changed... */
539 if (c != self->transient_for) {
540 if (self->transient_for)
541 /* remove from old parent */
542 g_slist_remove(self->transient_for->transients, self);
543 self->transient_for = c;
544 if (self->transient_for)
545 /* add to new parent */
546 g_slist_append(self->transient_for->transients, self);
550 static void client_get_mwm_hints(Client *self)
553 unsigned long *hints;
555 self->mwmhints.flags = 0; /* default to none */
557 if (PROP_GET32U(self->window, motif_wm_hints, motif_wm_hints, hints, num)) {
558 if (num >= MWM_ELEMENTS) {
559 self->mwmhints.flags = hints[0];
560 self->mwmhints.functions = hints[1];
561 self->mwmhints.decorations = hints[2];
567 void client_get_type(Client *self)
573 if (PROP_GET32U(self->window, net_wm_window_type, atom, val, num)) {
574 /* use the first value that we know about in the array */
575 for (i = 0; i < num; ++i) {
576 if (val[i] == prop_atoms.net_wm_window_type_desktop)
577 self->type = Type_Desktop;
578 else if (val[i] == prop_atoms.net_wm_window_type_dock)
579 self->type = Type_Dock;
580 else if (val[i] == prop_atoms.net_wm_window_type_toolbar)
581 self->type = Type_Toolbar;
582 else if (val[i] == prop_atoms.net_wm_window_type_menu)
583 self->type = Type_Menu;
584 else if (val[i] == prop_atoms.net_wm_window_type_utility)
585 self->type = Type_Utility;
586 else if (val[i] == prop_atoms.net_wm_window_type_splash)
587 self->type = Type_Splash;
588 else if (val[i] == prop_atoms.net_wm_window_type_dialog)
589 self->type = Type_Dialog;
590 else if (val[i] == prop_atoms.net_wm_window_type_normal)
591 self->type = Type_Normal;
592 else if (val[i] == prop_atoms.kde_net_wm_window_type_override) {
593 /* prevent this window from getting any decor or
595 self->mwmhints.flags &= (MwmFlag_Functions |
596 MwmFlag_Decorations);
597 self->mwmhints.decorations = 0;
598 self->mwmhints.functions = 0;
600 if (self->type != (WindowType) -1)
601 break; /* grab the first legit type */
606 if (self->type == (WindowType) -1) {
607 /*the window type hint was not set, which means we either classify
608 ourself as a normal window or a dialog, depending on if we are a
611 self->type = Type_Dialog;
613 self->type = Type_Normal;
617 void client_update_protocols(Client *self)
620 gulong num_return, i;
622 self->focus_notify = FALSE;
623 self->delete_window = FALSE;
625 if (PROP_GET32U(self->window, wm_protocols, atom, proto, num_return)) {
626 for (i = 0; i < num_return; ++i) {
627 if (proto[i] == prop_atoms.wm_delete_window) {
628 /* this means we can request the window to close */
629 self->delete_window = TRUE;
630 } else if (proto[i] == prop_atoms.wm_take_focus)
631 /* if this protocol is requested, then the window will be
632 notified whenever we want it to receive focus */
633 self->focus_notify = TRUE;
639 static void client_get_gravity(Client *self)
641 XWindowAttributes wattrib;
644 ret = XGetWindowAttributes(ob_display, self->window, &wattrib);
645 g_assert(ret != BadWindow);
646 self->gravity = wattrib.win_gravity;
649 void client_update_normal_hints(Client *self)
653 int oldgravity = self->gravity;
656 self->min_ratio = 0.0f;
657 self->max_ratio = 0.0f;
658 SIZE_SET(self->size_inc, 1, 1);
659 SIZE_SET(self->base_size, 0, 0);
660 SIZE_SET(self->min_size, 0, 0);
661 SIZE_SET(self->max_size, G_MAXINT, G_MAXINT);
663 /* get the hints from the window */
664 if (XGetWMNormalHints(ob_display, self->window, &size, &ret)) {
665 self->positioned = (size.flags & (PPosition|USPosition));
667 if (size.flags & PWinGravity) {
668 self->gravity = size.win_gravity;
670 /* if the client has a frame, i.e. has already been mapped and
671 is changing its gravity */
672 if (self->frame && self->gravity != oldgravity) {
673 /* move our idea of the client's position based on its new
675 self->area.x = self->frame->area.x;
676 self->area.y = self->frame->area.y;
677 frame_frame_gravity(self->frame, &self->area.x, &self->area.y);
681 if (size.flags & PAspect) {
682 if (size.min_aspect.y)
683 self->min_ratio = (float)size.min_aspect.x / size.min_aspect.y;
684 if (size.max_aspect.y)
685 self->max_ratio = (float)size.max_aspect.x / size.max_aspect.y;
688 if (size.flags & PMinSize)
689 SIZE_SET(self->min_size, size.min_width, size.min_height);
691 if (size.flags & PMaxSize)
692 SIZE_SET(self->max_size, size.max_width, size.max_height);
694 if (size.flags & PBaseSize)
695 SIZE_SET(self->base_size, size.base_width, size.base_height);
697 if (size.flags & PResizeInc)
698 SIZE_SET(self->size_inc, size.width_inc, size.height_inc);
702 void client_setup_decor_and_functions(Client *self)
704 /* start with everything (cept fullscreen) */
705 self->decorations = Decor_Titlebar | Decor_Handle | Decor_Border |
706 Decor_Icon | Decor_AllDesktops | Decor_Iconify | Decor_Maximize;
707 self->functions = Func_Resize | Func_Move | Func_Iconify | Func_Maximize |
709 if (self->delete_window) {
710 self->decorations |= Decor_Close;
711 self->functions |= Func_Close;
714 if (!(self->min_size.width < self->max_size.width ||
715 self->min_size.height < self->max_size.height)) {
716 self->decorations &= ~(Decor_Maximize | Decor_Handle);
717 self->functions &= ~(Func_Resize | Func_Maximize);
720 switch (self->type) {
722 /* normal windows retain all of the possible decorations and
723 functionality, and are the only windows that you can fullscreen */
724 self->functions |= Func_Fullscreen;
728 /* dialogs cannot be maximized */
729 self->decorations &= ~Decor_Maximize;
730 self->functions &= ~Func_Maximize;
736 /* these windows get less functionality */
737 self->decorations &= ~(Decor_Iconify | Decor_Handle);
738 self->functions &= ~(Func_Iconify | Func_Resize);
744 /* none of these windows are manipulated by the window manager */
745 self->decorations = 0;
750 /* Mwm Hints are applied subtractively to what has already been chosen for
751 decor and functionality */
752 if (self->mwmhints.flags & MwmFlag_Decorations) {
753 if (! (self->mwmhints.decorations & MwmDecor_All)) {
754 if (! (self->mwmhints.decorations & MwmDecor_Border))
755 self->decorations &= ~Decor_Border;
756 if (! (self->mwmhints.decorations & MwmDecor_Handle))
757 self->decorations &= ~Decor_Handle;
758 if (! (self->mwmhints.decorations & MwmDecor_Title))
759 self->decorations &= ~Decor_Titlebar;
760 if (! (self->mwmhints.decorations & MwmDecor_Iconify))
761 self->decorations &= ~Decor_Iconify;
762 if (! (self->mwmhints.decorations & MwmDecor_Maximize))
763 self->decorations &= ~Decor_Maximize;
767 if (self->mwmhints.flags & MwmFlag_Functions) {
768 if (! (self->mwmhints.functions & MwmFunc_All)) {
769 if (! (self->mwmhints.functions & MwmFunc_Resize))
770 self->functions &= ~Func_Resize;
771 if (! (self->mwmhints.functions & MwmFunc_Move))
772 self->functions &= ~Func_Move;
773 if (! (self->mwmhints.functions & MwmFunc_Iconify))
774 self->functions &= ~Func_Iconify;
775 if (! (self->mwmhints.functions & MwmFunc_Maximize))
776 self->functions &= ~Func_Maximize;
777 /* dont let mwm hints kill the close button
778 if (! (self->mwmhints.functions & MwmFunc_Close))
779 self->functions &= ~Func_Close; */
783 /* can't maximize without moving/resizing */
784 if (!((self->functions & Func_Move) && (self->functions & Func_Resize)))
785 self->functions &= ~Func_Maximize;
787 /* finally, user specified disabled decorations are applied to subtract
789 if (self->disabled_decorations & Decor_Titlebar)
790 self->decorations &= ~Decor_Titlebar;
791 if (self->disabled_decorations & Decor_Handle)
792 self->decorations &= ~Decor_Handle;
793 if (self->disabled_decorations & Decor_Border)
794 self->decorations &= ~Decor_Border;
795 if (self->disabled_decorations & Decor_Iconify)
796 self->decorations &= ~Decor_Iconify;
797 if (self->disabled_decorations & Decor_Maximize)
798 self->decorations &= ~Decor_Maximize;
799 if (self->disabled_decorations & Decor_AllDesktops)
800 self->decorations &= ~Decor_AllDesktops;
801 if (self->disabled_decorations & Decor_Close)
802 self->decorations &= ~Decor_Close;
804 /* if we don't have a titlebar, then we cannot shade! */
805 if (!(self->decorations & Decor_Titlebar))
806 self->functions &= ~Func_Shade;
808 client_change_allowed_actions(self);
811 /* change the decors on the frame */
812 engine_frame_adjust_size(self->frame);
813 /* with more/less decorations, we may need to be repositioned */
814 engine_frame_adjust_position(self->frame);
815 /* with new decor, the window's maximized size may change */
816 client_remaximize(self);
820 static void client_change_allowed_actions(Client *self)
825 actions[num++] = prop_atoms.net_wm_action_change_desktop;
827 if (self->functions & Func_Shade)
828 actions[num++] = prop_atoms.net_wm_action_shade;
829 if (self->functions & Func_Close)
830 actions[num++] = prop_atoms.net_wm_action_close;
831 if (self->functions & Func_Move)
832 actions[num++] = prop_atoms.net_wm_action_move;
833 if (self->functions & Func_Iconify)
834 actions[num++] = prop_atoms.net_wm_action_minimize;
835 if (self->functions & Func_Resize)
836 actions[num++] = prop_atoms.net_wm_action_resize;
837 if (self->functions & Func_Fullscreen)
838 actions[num++] = prop_atoms.net_wm_action_fullscreen;
839 if (self->functions & Func_Maximize) {
840 actions[num++] = prop_atoms.net_wm_action_maximize_horz;
841 actions[num++] = prop_atoms.net_wm_action_maximize_vert;
844 PROP_SET32A(self->window, net_wm_allowed_actions, atom, actions, num);
846 /* make sure the window isn't breaking any rules now */
848 if (!(self->functions & Func_Shade) && self->shaded) {
849 if (self->frame) client_shade(self, FALSE);
850 else self->shaded = FALSE;
852 if (!(self->functions & Func_Iconify) && self->iconic) {
853 if (self->frame) client_iconify(self, FALSE, TRUE);
854 else self->iconic = FALSE;
856 if (!(self->functions & Func_Fullscreen) && self->fullscreen) {
857 if (self->frame) client_fullscreen(self, FALSE, TRUE);
858 else self->fullscreen = FALSE;
860 if (!(self->functions & Func_Maximize) && (self->max_horz ||
862 if (self->frame) client_maximize(self, FALSE, 0, TRUE);
863 else self->max_vert = self->max_horz = FALSE;
867 void client_remaximize(Client *self)
870 if (self->max_horz && self->max_vert)
872 else if (self->max_horz)
874 else if (self->max_vert)
877 return; /* not maximized */
878 self->max_horz = self->max_vert = FALSE;
879 client_maximize(self, TRUE, dir, FALSE);
882 void client_update_wmhints(Client *self)
887 /* assume a window takes input if it doesnt specify */
888 self->can_focus = TRUE;
890 if ((hints = XGetWMHints(ob_display, self->window)) != NULL) {
891 if (hints->flags & InputHint)
892 self->can_focus = hints->input;
894 /* only do this when starting! */
895 if (ob_state == State_Starting && (hints->flags & StateHint))
896 self->iconic = hints->initial_state == IconicState;
898 if (hints->flags & XUrgencyHint)
901 if (hints->flags & WindowGroupHint) {
902 if (hints->window_group != self->group) {
903 /* XXX: remove from the old group if there was one */
904 self->group = hints->window_group;
905 /* XXX: do stuff with the group */
907 } else /* no group! */
910 if (hints->flags & IconPixmapHint) {
911 client_update_kwm_icon(self);
912 /* try get the kwm icon first, this is a fallback only */
913 if (self->pixmap_icon == None) {
914 self->pixmap_icon = hints->icon_pixmap;
915 if (hints->flags & IconMaskHint)
916 self->pixmap_icon_mask = hints->icon_mask;
918 self->pixmap_icon_mask = None;
921 engine_frame_adjust_icon(self->frame);
928 if (ur != self->urgent) {
930 g_message("Urgent Hint for 0x%lx: %s\n", self->window,
932 /* fire the urgent callback if we're mapped, otherwise, wait until
933 after we're mapped */
935 dispatch_client(Event_Client_Urgent, self, self->urgent, 0);
939 void client_update_title(Client *self)
943 if (self->title != NULL)
947 if (!PROP_GETS(self->window, net_wm_name, utf8, data)) {
948 /* try old x stuff */
949 if (PROP_GETS(self->window, wm_name, string, data)) {
950 /* convert it to UTF-8 */
954 u = g_locale_to_utf8(data, -1, &r, &w, NULL);
956 g_warning("Unable to convert string to UTF-8");
963 data = g_strdup("Unnamed Window");
965 PROP_SETS(self->window, net_wm_visible_name, utf8, data);
971 engine_frame_adjust_title(self->frame);
974 void client_update_icon_title(Client *self)
978 if (self->icon_title != NULL)
979 g_free(self->icon_title);
982 if (!PROP_GETS(self->window, net_wm_icon_name, utf8, data)) {
983 /* try old x stuff */
984 if (PROP_GETS(self->window, wm_icon_name, string, data)) {
985 /* convert it to UTF-8 */
989 u = g_locale_to_utf8(data, -1, &r, &w, NULL);
991 g_warning("Unable to convert string to UTF-8");
998 data = g_strdup("Unnamed Window");
1000 PROP_SETS(self->window, net_wm_visible_icon_name, utf8, data);
1003 self->icon_title = data;
1006 void client_update_class(Client *self)
1012 if (self->res_name) g_free(self->res_name);
1013 if (self->res_class) g_free(self->res_class);
1014 if (self->role) g_free(self->role);
1016 self->res_name = self->res_class = self->role = NULL;
1018 data = g_ptr_array_new();
1020 if (PROP_GETSA(self->window, wm_class, string, data)) {
1022 self->res_name = g_strdup(g_ptr_array_index(data, 0));
1024 self->res_class = g_strdup(g_ptr_array_index(data, 1));
1027 for (i = 0; i < data->len; ++i)
1028 g_free(g_ptr_array_index(data, i));
1029 g_ptr_array_free(data, TRUE);
1031 if (PROP_GETS(self->window, wm_window_role, string, s))
1032 self->role = g_strdup(s);
1034 if (self->res_name == NULL) self->res_name = g_strdup("");
1035 if (self->res_class == NULL) self->res_class = g_strdup("");
1036 if (self->role == NULL) self->role = g_strdup("");
1039 void client_update_strut(Client *self)
1043 if (PROP_GET32A(self->window, net_wm_strut, cardinal, data, 4)) {
1044 STRUT_SET(self->strut, data[0], data[1], data[2], data[3]);
1047 STRUT_SET(self->strut, 0, 0, 0, 0);
1049 /* updating here is pointless while we're being mapped cuz we're not in
1050 the client list yet */
1052 screen_update_struts();
1055 void client_update_icons(Client *self)
1058 unsigned long *data;
1059 unsigned long w, h, i;
1062 for (j = 0; j < self->nicons; ++j)
1063 g_free(self->icons[j].data);
1064 if (self->nicons > 0)
1065 g_free(self->icons);
1068 if (PROP_GET32U(self->window, net_wm_icon, cardinal, data, num)) {
1069 /* figure out how many valid icons are in here */
1071 while (num - i > 2) {
1079 self->icons = g_new(Icon, self->nicons);
1081 /* store the icons */
1083 for (j = 0; j < self->nicons; ++j) {
1084 w = self->icons[j].w = data[i++];
1085 h = self->icons[j].h = data[i++];
1086 self->icons[j].data =
1087 g_memdup(&data[i], w * h * sizeof(gulong));
1095 if (self->nicons <= 0) {
1097 self->icons = g_new0(Icon, 1);
1101 engine_frame_adjust_icon(self->frame);
1104 void client_update_kwm_icon(Client *self)
1108 if (PROP_GET32A(self->window, kwm_win_icon, kwm_win_icon, data, 2)) {
1109 self->pixmap_icon = data[0];
1110 self->pixmap_icon_mask = data[1];
1113 self->pixmap_icon = self->pixmap_icon_mask = None;
1116 engine_frame_adjust_icon(self->frame);
1119 static void client_change_state(Client *self)
1121 unsigned long state[2];
1125 state[0] = self->wmstate;
1127 PROP_SET32A(self->window, wm_state, wm_state, state, 2);
1131 netstate[num++] = prop_atoms.net_wm_state_modal;
1133 netstate[num++] = prop_atoms.net_wm_state_shaded;
1135 netstate[num++] = prop_atoms.net_wm_state_hidden;
1136 if (self->skip_taskbar)
1137 netstate[num++] = prop_atoms.net_wm_state_skip_taskbar;
1138 if (self->skip_pager)
1139 netstate[num++] = prop_atoms.net_wm_state_skip_pager;
1140 if (self->fullscreen)
1141 netstate[num++] = prop_atoms.net_wm_state_fullscreen;
1143 netstate[num++] = prop_atoms.net_wm_state_maximized_vert;
1145 netstate[num++] = prop_atoms.net_wm_state_maximized_horz;
1147 netstate[num++] = prop_atoms.net_wm_state_above;
1149 netstate[num++] = prop_atoms.net_wm_state_below;
1150 PROP_SET32A(self->window, net_wm_state, atom, netstate, num);
1152 client_calc_layer(self);
1155 engine_frame_adjust_state(self->frame);
1158 static Client *search_focus_tree(Client *node, Client *skip)
1163 for (it = node->transients; it != NULL; it = g_slist_next(it)) {
1164 Client *c = it->data;
1165 if (c == skip) continue; /* circular? */
1166 if ((ret = search_focus_tree(c, skip))) return ret;
1167 if (c->focused) return c;
1172 void client_calc_layer(Client *self)
1178 /* are we fullscreen, or do we have a fullscreen transient parent? */
1182 if (c->fullscreen) {
1186 c = c->transient_for;
1188 if (!fs && self->fullscreen) {
1189 /* is one of our transients focused? */
1190 c = search_focus_tree(self, self);
1191 if (c != NULL) fs = TRUE;
1194 if (self->iconic) l = Layer_Icon;
1195 else if (fs) l = Layer_Fullscreen;
1196 else if (self->type == Type_Desktop) l = Layer_Desktop;
1197 else if (self->type == Type_Dock) {
1198 if (!self->below) l = Layer_Top;
1199 else l = Layer_Normal;
1201 else if (self->above) l = Layer_Above;
1202 else if (self->below) l = Layer_Below;
1203 else l = Layer_Normal;
1205 if (l != self->layer) {
1208 stacking_raise(self);
1212 gboolean client_should_show(Client *self)
1214 if (self->iconic) return FALSE;
1215 else if (!(self->desktop == screen_desktop ||
1216 self->desktop == DESKTOP_ALL)) return FALSE;
1217 else if (client_normal(self) && screen_showing_desktop) return FALSE;
1222 static void client_showhide(Client *self)
1225 if (client_should_show(self))
1226 engine_frame_show(self->frame);
1228 engine_frame_hide(self->frame);
1231 gboolean client_normal(Client *self) {
1232 return ! (self->type == Type_Desktop || self->type == Type_Dock ||
1233 self->type == Type_Splash);
1236 static void client_apply_startup_state(Client *self)
1238 /* these are in a carefully crafted order.. */
1241 self->iconic = FALSE;
1242 client_iconify(self, TRUE, FALSE);
1244 if (self->fullscreen) {
1245 self->fullscreen = FALSE;
1246 client_fullscreen(self, TRUE, FALSE);
1249 self->shaded = FALSE;
1250 client_shade(self, TRUE);
1253 dispatch_client(Event_Client_Urgent, self, self->urgent, 0);
1255 if (self->max_vert && self->max_horz) {
1256 self->max_vert = self->max_horz = FALSE;
1257 client_maximize(self, TRUE, 0, FALSE);
1258 } else if (self->max_vert) {
1259 self->max_vert = FALSE;
1260 client_maximize(self, TRUE, 2, FALSE);
1261 } else if (self->max_horz) {
1262 self->max_horz = FALSE;
1263 client_maximize(self, TRUE, 1, FALSE);
1266 /* nothing to do for the other states:
1275 void client_configure(Client *self, Corner anchor, int x, int y, int w, int h,
1276 gboolean user, gboolean final)
1278 gboolean moved = FALSE, resized = FALSE;
1280 w -= self->base_size.width;
1281 h -= self->base_size.height;
1284 /* for interactive resizing. have to move half an increment in each
1287 /* how far we are towards the next size inc */
1288 int mw = w % self->size_inc.width;
1289 int mh = h % self->size_inc.height;
1291 int aw = self->size_inc.width / 2;
1292 int ah = self->size_inc.height / 2;
1293 /* don't let us move into a new size increment */
1294 if (mw + aw >= self->size_inc.width)
1295 aw = self->size_inc.width - mw - 1;
1296 if (mh + ah >= self->size_inc.height)
1297 ah = self->size_inc.height - mh - 1;
1301 /* if this is a user-requested resize, then check against min/max
1302 sizes and aspect ratios */
1304 /* smaller than min size or bigger than max size? */
1305 if (w > self->max_size.width) w = self->max_size.width;
1306 if (w < self->min_size.width) w = self->min_size.width;
1307 if (h > self->max_size.height) h = self->max_size.height;
1308 if (h < self->min_size.height) h = self->min_size.height;
1310 /* adjust the height ot match the width for the aspect ratios */
1311 if (self->min_ratio)
1312 if (h * self->min_ratio > w) h = (int)(w / self->min_ratio);
1313 if (self->max_ratio)
1314 if (h * self->max_ratio < w) h = (int)(w / self->max_ratio);
1317 /* keep to the increments */
1318 w /= self->size_inc.width;
1319 h /= self->size_inc.height;
1321 /* you cannot resize to nothing */
1325 /* store the logical size */
1326 SIZE_SET(self->logical_size, w, h);
1328 w *= self->size_inc.width;
1329 h *= self->size_inc.height;
1331 w += self->base_size.width;
1332 h += self->base_size.height;
1335 case Corner_TopLeft:
1337 case Corner_TopRight:
1338 x -= w - self->area.width;
1340 case Corner_BottomLeft:
1341 y -= h - self->area.height;
1343 case Corner_BottomRight:
1344 x -= w - self->area.width;
1345 y -= h - self->area.height;
1349 moved = x != self->area.x || y != self->area.y;
1350 resized = w != self->area.width || h != self->area.height;
1352 RECT_SET(self->area, x, y, w, h);
1355 XResizeWindow(ob_display, self->window, w, h);
1357 /* move/resize the frame to match the request */
1359 /* Adjust the size and then the position, as required by the EWMH */
1361 engine_frame_adjust_size(self->frame);
1363 engine_frame_adjust_position(self->frame);
1365 if (!user || final) {
1367 event.type = ConfigureNotify;
1368 event.xconfigure.display = ob_display;
1369 event.xconfigure.event = self->window;
1370 event.xconfigure.window = self->window;
1372 /* root window coords with border in mind */
1373 event.xconfigure.x = x - self->border_width +
1374 self->frame->size.left;
1375 event.xconfigure.y = y - self->border_width +
1376 self->frame->size.top;
1378 event.xconfigure.width = self->area.width;
1379 event.xconfigure.height = self->area.height;
1380 event.xconfigure.border_width = self->border_width;
1381 event.xconfigure.above = self->frame->plate;
1382 event.xconfigure.override_redirect = FALSE;
1383 XSendEvent(event.xconfigure.display, event.xconfigure.window,
1384 FALSE, StructureNotifyMask, &event);
1390 void client_fullscreen(Client *self, gboolean fs, gboolean savearea)
1392 static int saved_func, saved_decor;
1395 if (!(self->functions & Func_Fullscreen) || /* can't */
1396 self->fullscreen == fs) return; /* already done */
1398 self->fullscreen = fs;
1399 client_change_state(self); /* change the state hints on the client */
1402 /* save the functions and remove them */
1403 saved_func = self->functions;
1404 self->functions &= (Func_Close | Func_Fullscreen |
1406 /* save the decorations and remove them */
1407 saved_decor = self->decorations;
1408 self->decorations = 0;
1411 dimensions[0] = self->area.x;
1412 dimensions[1] = self->area.y;
1413 dimensions[2] = self->area.width;
1414 dimensions[3] = self->area.height;
1416 PROP_SET32A(self->window, openbox_premax, cardinal,
1421 w = screen_physical_size.width;
1422 h = screen_physical_size.height;
1426 self->functions = saved_func;
1427 self->decorations = saved_decor;
1429 if (PROP_GET32A(self->window, openbox_premax, cardinal,
1437 /* pick some fallbacks... */
1438 x = screen_area(self->desktop)->x +
1439 screen_area(self->desktop)->width / 4;
1440 y = screen_area(self->desktop)->y +
1441 screen_area(self->desktop)->height / 4;
1442 w = screen_area(self->desktop)->width / 2;
1443 h = screen_area(self->desktop)->height / 2;
1447 client_change_allowed_actions(self); /* based on the new _functions */
1449 /* when fullscreening, don't obey things like increments, fill the
1451 client_configure(self, Corner_TopLeft, x, y, w, h, !fs, TRUE);
1453 /* raise (back) into our stacking layer */
1454 stacking_raise(self);
1456 /* try focus us when we go into fullscreen mode */
1460 void client_iconify(Client *self, gboolean iconic, gboolean curdesk)
1462 if (self->iconic == iconic) return; /* nothing to do */
1464 g_message("%sconifying window: 0x%lx\n", (iconic ? "I" : "Uni"),
1467 self->iconic = iconic;
1470 self->wmstate = IconicState;
1471 self->ignore_unmaps++;
1472 /* we unmap the client itself so that we can get MapRequest events,
1473 and because the ICCCM tells us to! */
1474 XUnmapWindow(ob_display, self->window);
1477 client_set_desktop(self, screen_desktop);
1478 self->wmstate = self->shaded ? IconicState : NormalState;
1479 XMapWindow(ob_display, self->window);
1481 client_change_state(self);
1482 client_showhide(self);
1483 screen_update_struts();
1486 void client_maximize(Client *self, gboolean max, int dir, gboolean savearea)
1490 g_assert(dir == 0 || dir == 1 || dir == 2);
1491 if (!(self->functions & Func_Maximize)) return; /* can't */
1493 /* check if already done */
1495 if (dir == 0 && self->max_horz && self->max_vert) return;
1496 if (dir == 1 && self->max_horz) return;
1497 if (dir == 2 && self->max_vert) return;
1499 if (dir == 0 && !self->max_horz && !self->max_vert) return;
1500 if (dir == 1 && !self->max_horz) return;
1501 if (dir == 2 && !self->max_vert) return;
1504 /* work with the frame's coords */
1505 x = self->frame->area.x;
1506 y = self->frame->area.y;
1507 w = self->area.width;
1508 h = self->area.height;
1520 /* get the property off the window and use it for the dimensions
1521 we are already maxed on */
1522 if (PROP_GET32A(self->window, openbox_premax, cardinal,
1524 if (self->max_horz) {
1525 dimensions[0] = readdim[0];
1526 dimensions[2] = readdim[2];
1528 if (self->max_vert) {
1529 dimensions[1] = readdim[1];
1530 dimensions[3] = readdim[3];
1535 PROP_SET32A(self->window, openbox_premax, cardinal,
1538 if (dir == 0 || dir == 1) { /* horz */
1539 x = screen_area(self->desktop)->x - self->frame->size.left;
1540 w = screen_area(self->desktop)->x +
1541 screen_area(self->desktop)->width;
1543 if (dir == 0 || dir == 2) { /* vert */
1544 y = screen_area(self->desktop)->y;
1545 h = screen_area(self->desktop)->y +
1546 screen_area(self->desktop)->height -
1547 self->frame->size.top - self->frame->size.bottom;
1552 if (PROP_GET32A(self->window, openbox_premax, cardinal,
1554 if (dir == 0 || dir == 1) { /* horz */
1558 if (dir == 0 || dir == 2) { /* vert */
1564 /* pick some fallbacks... */
1565 if (dir == 0 || dir == 1) { /* horz */
1566 x = screen_area(self->desktop)->x +
1567 screen_area(self->desktop)->width / 4;
1568 w = screen_area(self->desktop)->width / 2;
1570 if (dir == 0 || dir == 2) { /* vert */
1571 y = screen_area(self->desktop)->y +
1572 screen_area(self->desktop)->height / 4;
1573 h = screen_area(self->desktop)->height / 2;
1578 if (dir == 0 || dir == 1) /* horz */
1579 self->max_horz = max;
1580 if (dir == 0 || dir == 2) /* vert */
1581 self->max_vert = max;
1583 if (!self->max_horz && !self->max_vert)
1584 PROP_ERASE(self->window, openbox_premax);
1586 client_change_state(self); /* change the state hints on the client */
1588 /* figure out where the client should be going */
1589 frame_frame_gravity(self->frame, &x, &y);
1590 client_configure(self, Corner_TopLeft, x, y, w, h, TRUE, TRUE);
1593 void client_shade(Client *self, gboolean shade)
1595 if (!(self->functions & Func_Shade) || /* can't */
1596 self->shaded == shade) return; /* already done */
1598 /* when we're iconic, don't change the wmstate */
1600 self->wmstate = shade ? IconicState : NormalState;
1601 self->shaded = shade;
1602 client_change_state(self);
1603 engine_frame_adjust_size(self->frame);
1606 void client_close(Client *self)
1610 if (!(self->functions & Func_Close)) return;
1613 XXX: itd be cool to do timeouts and shit here for killing the client's
1615 like... if the window is around after 5 seconds, then the close button
1616 turns a nice red, and if this function is called again, the client is
1620 ce.xclient.type = ClientMessage;
1621 ce.xclient.message_type = prop_atoms.wm_protocols;
1622 ce.xclient.display = ob_display;
1623 ce.xclient.window = self->window;
1624 ce.xclient.format = 32;
1625 ce.xclient.data.l[0] = prop_atoms.wm_delete_window;
1626 ce.xclient.data.l[1] = CurrentTime;
1627 ce.xclient.data.l[2] = 0l;
1628 ce.xclient.data.l[3] = 0l;
1629 ce.xclient.data.l[4] = 0l;
1630 XSendEvent(ob_display, self->window, FALSE, NoEventMask, &ce);
1633 void client_set_desktop(Client *self, guint target)
1637 if (target == self->desktop) return;
1639 g_message("Setting desktop %u\n", target);
1641 g_assert(target < screen_num_desktops || target == DESKTOP_ALL);
1643 old = self->desktop;
1644 self->desktop = target;
1645 PROP_SET32(self->window, net_wm_desktop, cardinal, target);
1646 /* the frame can display the current desktop state */
1647 engine_frame_adjust_state(self->frame);
1648 /* 'move' the window to the new desktop */
1649 client_showhide(self);
1650 screen_update_struts();
1652 /* update the focus lists */
1653 if (old == DESKTOP_ALL) {
1654 for (i = 0; i < screen_num_desktops; ++i)
1655 focus_order[i] = g_list_remove(focus_order[i], self);
1657 focus_order[old] = g_list_remove(focus_order[old], self);
1659 if (target == DESKTOP_ALL) {
1660 for (i = 0; i < screen_num_desktops; ++i)
1661 focus_order[i] = g_list_prepend(focus_order[i], self);
1663 focus_order[target] = g_list_prepend(focus_order[target], self);
1666 dispatch_client(Event_Client_Desktop, self, target, old);
1669 static Client *search_modal_tree(Client *node, Client *skip)
1674 for (it = node->transients; it != NULL; it = it->next) {
1675 Client *c = it->data;
1676 if (c == skip) continue; /* circular? */
1677 if ((ret = search_modal_tree(c, skip))) return ret;
1678 if (c->modal) return c;
1683 Client *client_find_modal_child(Client *self)
1685 return search_modal_tree(self, self);
1688 gboolean client_validate(Client *self)
1692 XSync(ob_display, FALSE); /* get all events on the server */
1694 if (XCheckTypedWindowEvent(ob_display, self->window, DestroyNotify, &e) ||
1695 XCheckTypedWindowEvent(ob_display, self->window, UnmapNotify, &e)) {
1696 XPutBackEvent(ob_display, &e);
1703 void client_set_wm_state(Client *self, long state)
1705 if (state == self->wmstate) return; /* no change */
1709 client_iconify(self, TRUE, TRUE);
1712 client_iconify(self, FALSE, TRUE);
1717 void client_set_state(Client *self, Atom action, long data1, long data2)
1719 gboolean shaded = self->shaded;
1720 gboolean fullscreen = self->fullscreen;
1721 gboolean max_horz = self->max_horz;
1722 gboolean max_vert = self->max_vert;
1725 if (!(action == prop_atoms.net_wm_state_add ||
1726 action == prop_atoms.net_wm_state_remove ||
1727 action == prop_atoms.net_wm_state_toggle))
1728 /* an invalid action was passed to the client message, ignore it */
1731 for (i = 0; i < 2; ++i) {
1732 Atom state = i == 0 ? data1 : data2;
1734 if (!state) continue;
1736 /* if toggling, then pick whether we're adding or removing */
1737 if (action == prop_atoms.net_wm_state_toggle) {
1738 if (state == prop_atoms.net_wm_state_modal)
1739 action = self->modal ? prop_atoms.net_wm_state_remove :
1740 prop_atoms.net_wm_state_add;
1741 else if (state == prop_atoms.net_wm_state_maximized_vert)
1742 action = self->max_vert ? prop_atoms.net_wm_state_remove :
1743 prop_atoms.net_wm_state_add;
1744 else if (state == prop_atoms.net_wm_state_maximized_horz)
1745 action = self->max_horz ? prop_atoms.net_wm_state_remove :
1746 prop_atoms.net_wm_state_add;
1747 else if (state == prop_atoms.net_wm_state_shaded)
1748 action = self->shaded ? prop_atoms.net_wm_state_remove :
1749 prop_atoms.net_wm_state_add;
1750 else if (state == prop_atoms.net_wm_state_skip_taskbar)
1751 action = self->skip_taskbar ?
1752 prop_atoms.net_wm_state_remove :
1753 prop_atoms.net_wm_state_add;
1754 else if (state == prop_atoms.net_wm_state_skip_pager)
1755 action = self->skip_pager ?
1756 prop_atoms.net_wm_state_remove :
1757 prop_atoms.net_wm_state_add;
1758 else if (state == prop_atoms.net_wm_state_fullscreen)
1759 action = self->fullscreen ?
1760 prop_atoms.net_wm_state_remove :
1761 prop_atoms.net_wm_state_add;
1762 else if (state == prop_atoms.net_wm_state_above)
1763 action = self->above ? prop_atoms.net_wm_state_remove :
1764 prop_atoms.net_wm_state_add;
1765 else if (state == prop_atoms.net_wm_state_below)
1766 action = self->below ? prop_atoms.net_wm_state_remove :
1767 prop_atoms.net_wm_state_add;
1770 if (action == prop_atoms.net_wm_state_add) {
1771 if (state == prop_atoms.net_wm_state_modal) {
1772 /* XXX raise here or something? */
1774 } else if (state == prop_atoms.net_wm_state_maximized_vert) {
1776 } else if (state == prop_atoms.net_wm_state_maximized_horz) {
1778 } else if (state == prop_atoms.net_wm_state_shaded) {
1780 } else if (state == prop_atoms.net_wm_state_skip_taskbar) {
1781 self->skip_taskbar = TRUE;
1782 } else if (state == prop_atoms.net_wm_state_skip_pager) {
1783 self->skip_pager = TRUE;
1784 } else if (state == prop_atoms.net_wm_state_fullscreen) {
1786 } else if (state == prop_atoms.net_wm_state_above) {
1788 } else if (state == prop_atoms.net_wm_state_below) {
1792 } else { /* action == prop_atoms.net_wm_state_remove */
1793 if (state == prop_atoms.net_wm_state_modal) {
1794 self->modal = FALSE;
1795 } else if (state == prop_atoms.net_wm_state_maximized_vert) {
1797 } else if (state == prop_atoms.net_wm_state_maximized_horz) {
1799 } else if (state == prop_atoms.net_wm_state_shaded) {
1801 } else if (state == prop_atoms.net_wm_state_skip_taskbar) {
1802 self->skip_taskbar = FALSE;
1803 } else if (state == prop_atoms.net_wm_state_skip_pager) {
1804 self->skip_pager = FALSE;
1805 } else if (state == prop_atoms.net_wm_state_fullscreen) {
1807 } else if (state == prop_atoms.net_wm_state_above) {
1808 self->above = FALSE;
1809 } else if (state == prop_atoms.net_wm_state_below) {
1810 self->below = FALSE;
1814 if (max_horz != self->max_horz || max_vert != self->max_vert) {
1815 if (max_horz != self->max_horz && max_vert != self->max_vert) {
1817 if (max_horz == max_vert) { /* both going the same way */
1818 client_maximize(self, max_horz, 0, TRUE);
1820 client_maximize(self, max_horz, 1, TRUE);
1821 client_maximize(self, max_vert, 2, TRUE);
1825 if (max_horz != self->max_horz)
1826 client_maximize(self, max_horz, 1, TRUE);
1828 client_maximize(self, max_vert, 2, TRUE);
1831 /* change fullscreen state before shading, as it will affect if the window
1833 if (fullscreen != self->fullscreen)
1834 client_fullscreen(self, fullscreen, TRUE);
1835 if (shaded != self->shaded)
1836 client_shade(self, shaded);
1837 client_calc_layer(self);
1838 client_change_state(self); /* change the hint to relect these changes */
1841 gboolean client_focus(Client *self)
1846 /* if we have a modal child, then focus it, not us */
1847 child = client_find_modal_child(self);
1849 return client_focus(child);
1851 /* won't try focus if the client doesn't want it, or if the window isn't
1852 visible on the screen */
1853 if (!(self->frame->visible &&
1854 (self->can_focus || self->focus_notify)))
1857 /* do a check to see if the window has already been unmapped or destroyed
1858 do this intelligently while watching out for unmaps we've generated
1859 (ignore_unmaps > 0) */
1860 if (XCheckTypedWindowEvent(ob_display, self->window,
1861 DestroyNotify, &ev)) {
1862 XPutBackEvent(ob_display, &ev);
1865 while (XCheckTypedWindowEvent(ob_display, self->window,
1866 UnmapNotify, &ev)) {
1867 if (self->ignore_unmaps) {
1868 self->ignore_unmaps--;
1870 XPutBackEvent(ob_display, &ev);
1875 if (self->can_focus)
1876 XSetInputFocus(ob_display, self->window, RevertToNone, CurrentTime);
1878 if (self->focus_notify) {
1880 ce.xclient.type = ClientMessage;
1881 ce.xclient.message_type = prop_atoms.wm_protocols;
1882 ce.xclient.display = ob_display;
1883 ce.xclient.window = self->window;
1884 ce.xclient.format = 32;
1885 ce.xclient.data.l[0] = prop_atoms.wm_take_focus;
1886 ce.xclient.data.l[1] = event_lasttime;
1887 ce.xclient.data.l[2] = 0l;
1888 ce.xclient.data.l[3] = 0l;
1889 ce.xclient.data.l[4] = 0l;
1890 XSendEvent(ob_display, self->window, FALSE, NoEventMask, &ce);
1893 /*XSync(ob_display, FALSE); XXX Why sync? */
1897 void client_unfocus(Client *self)
1899 g_assert(focus_client == self);
1900 focus_set_client(NULL);