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 Window *client_startup_stack_order = NULL;
27 static gulong client_startup_stack_size = 0;
29 static void client_get_all(Client *self);
30 static void client_toggle_border(Client *self, gboolean show);
31 static void client_get_area(Client *self);
32 static void client_get_desktop(Client *self);
33 static void client_get_state(Client *self);
34 static void client_get_shaped(Client *self);
35 static void client_get_mwm_hints(Client *self);
36 static void client_get_gravity(Client *self);
37 static void client_showhide(Client *self);
38 static void client_change_allowed_actions(Client *self);
39 static void client_change_state(Client *self);
40 static Client *search_focus_tree(Client *node, Client *skip);
41 static void client_apply_startup_state(Client *self);
42 static Client *search_modal_tree(Client *node, Client *skip);
44 static guint map_hash(Window *w) { return *w; }
45 static gboolean map_key_comp(Window *w1, Window *w2) { return *w1 == *w2; }
49 client_map = g_hash_table_new((GHashFunc)map_hash,
50 (GEqualFunc)map_key_comp);
52 /* save the stacking order on startup! */
53 if (!PROP_GET32U(ob_root, net_client_list_stacking, window,
54 client_startup_stack_order, client_startup_stack_size))
56 g_message("%ld", client_startup_stack_size);
61 void client_shutdown()
63 g_hash_table_destroy(client_map);
66 void client_set_list()
68 Window *windows, *win_it;
70 guint size = g_slist_length(client_list);
72 /* create an array of the window ids */
74 windows = g_new(Window, size);
76 for (it = client_list; it != NULL; it = it->next, ++win_it)
77 *win_it = ((Client*)it->data)->window;
81 PROP_SET32A(ob_root, net_client_list, window, windows, size);
89 void client_manage_all()
91 unsigned int i, j, nchild;
94 XWindowAttributes attrib;
96 XQueryTree(ob_display, ob_root, &w, &w, &children, &nchild);
98 /* remove all icon windows from the list */
99 for (i = 0; i < nchild; i++) {
100 if (children[i] == None) continue;
101 wmhints = XGetWMHints(ob_display, children[i]);
103 if ((wmhints->flags & IconWindowHint) &&
104 (wmhints->icon_window != children[i]))
105 for (j = 0; j < nchild; j++)
106 if (children[j] == wmhints->icon_window) {
114 for (i = 0; i < nchild; ++i) {
115 if (children[i] == None)
117 if (XGetWindowAttributes(ob_display, children[i], &attrib)) {
118 if (attrib.override_redirect) continue;
120 if (attrib.map_state != IsUnmapped)
121 client_manage(children[i]);
126 /* stack them as they were on startup! */
127 for (i = client_startup_stack_size; i > 0; --i) {
130 w = client_startup_stack_order[i-1];
131 c = g_hash_table_lookup(client_map, &w);
132 if (c) stacking_lower(c);
134 g_free(client_startup_stack_order);
135 client_startup_stack_order = NULL;
136 client_startup_stack_size = 0;
139 void client_manage(Window window)
143 XWindowAttributes attrib;
144 XSetWindowAttributes attrib_set;
145 /* XWMHints *wmhint; */
150 /* check if it has already been unmapped by the time we started mapping
151 the grab does a sync so we don't have to here */
152 if (XCheckTypedWindowEvent(ob_display, window, DestroyNotify, &e) ||
153 XCheckTypedWindowEvent(ob_display, window, UnmapNotify, &e)) {
154 XPutBackEvent(ob_display, &e);
157 return; /* don't manage it */
160 /* make sure it isn't an override-redirect window */
161 if (!XGetWindowAttributes(ob_display, window, &attrib) ||
162 attrib.override_redirect) {
164 return; /* don't manage it */
167 /* /\* is the window a docking app *\/
168 if ((wmhint = XGetWMHints(ob_display, window))) {
169 if ((wmhint->flags & StateHint) &&
170 wmhint->initial_state == WithdrawnState) {
171 /\* XXX: make dock apps work! *\/
180 /* choose the events we want to receive on the CLIENT window */
181 attrib_set.event_mask = CLIENT_EVENTMASK;
182 attrib_set.do_not_propagate_mask = CLIENT_NOPROPAGATEMASK;
183 XChangeWindowAttributes(ob_display, window,
184 CWEventMask|CWDontPropagate, &attrib_set);
187 /* create the Client struct, and populate it from the hints on the
189 client = g_new(Client, 1);
190 client->window = window;
191 client_get_all(client);
193 /* remove the client's border (and adjust re gravity) */
194 client_toggle_border(client, FALSE);
196 /* specify that if we exit, the window should not be destroyed and should
197 be reparented back to root automatically */
198 XChangeSaveSet(ob_display, window, SetModeInsert);
200 /* create the decoration frame for the client window */
201 client->frame = engine_frame_new();
203 engine_frame_grab_client(client->frame, client);
205 client_apply_startup_state(client);
209 client_list = g_slist_append(client_list, client);
210 stacking_list = g_list_append(stacking_list, client);
211 g_assert(!g_hash_table_lookup(client_map, &client->window));
212 g_hash_table_insert(client_map, &client->window, client);
214 /* update the focus lists */
215 if (client->desktop == DESKTOP_ALL) {
216 for (i = 0; i < screen_num_desktops; ++i)
217 focus_order[i] = g_list_append(focus_order[i], client);
220 focus_order[i] = g_list_append(focus_order[i], client);
223 stacking_raise(client);
225 screen_update_struts();
227 dispatch_client(Event_Client_New, client, 0, 0);
229 client_showhide(client);
231 dispatch_client(Event_Client_Mapped, client, 0, 0);
233 /* update the list hints */
236 g_message("Managed window 0x%lx", window);
239 void client_unmanage_all()
241 while (client_list != NULL)
242 client_unmanage(client_list->data);
245 void client_unmanage(Client *client)
251 g_message("Unmanaging window: %lx", client->window);
253 dispatch_client(Event_Client_Destroy, client, 0, 0);
254 g_assert(client != NULL);
256 /* remove the window from our save set */
257 XChangeSaveSet(ob_display, client->window, SetModeDelete);
259 /* we dont want events no more */
260 XSelectInput(ob_display, client->window, NoEventMask);
262 engine_frame_hide(client->frame);
264 client_list = g_slist_remove(client_list, client);
265 stacking_list = g_list_remove(stacking_list, client);
266 g_hash_table_remove(client_map, &client->window);
268 /* update the focus lists */
269 if (client->desktop == DESKTOP_ALL) {
270 for (i = 0; i < screen_num_desktops; ++i)
271 focus_order[i] = g_list_remove(focus_order[i], client);
274 focus_order[i] = g_list_remove(focus_order[i], client);
277 /* once the client is out of the list, update the struts to remove it's
279 screen_update_struts();
281 /* tell our parent that we're gone */
282 if (client->transient_for != NULL)
283 client->transient_for->transients =
284 g_slist_remove(client->transient_for->transients, client);
286 /* tell our transients that we're gone */
287 for (it = client->transients; it != NULL; it = it->next) {
288 ((Client*)it->data)->transient_for = NULL;
289 client_calc_layer(it->data);
292 /* dispatch the unmapped event */
293 dispatch_client(Event_Client_Unmapped, client, 0, 0);
294 g_assert(client != NULL);
296 /* unfocus the client (dispatchs the focus event) (we're out of the
297 transient lists already, so being modal doesn't matter) */
298 if (client_focused(client))
299 client_unfocus(client);
301 /* give the client its border back */
302 client_toggle_border(client, TRUE);
304 /* reparent the window out of the frame, and free the frame */
305 engine_frame_release_client(client->frame, client);
306 client->frame = NULL;
308 if (ob_state != State_Exiting) {
309 /* these values should not be persisted across a window
311 prop_erase(client->window, prop_atoms.net_wm_desktop);
312 prop_erase(client->window, prop_atoms.net_wm_state);
314 /* if we're left in an iconic state, the client wont be mapped. this is
315 bad, since we will no longer be managing the window on restart */
317 XMapWindow(ob_display, client->window);
320 /* free all data allocated in the client struct */
321 g_slist_free(client->transients);
322 for (j = 0; j < client->nicons; ++j)
323 g_free(client->icons[j].data);
324 if (client->nicons > 0)
325 g_free(client->icons);
326 g_free(client->title);
327 g_free(client->icon_title);
328 g_free(client->name);
329 g_free(client->class);
330 g_free(client->role);
333 /* update the list hints */
337 static void client_toggle_border(Client *self, gboolean show)
339 /* adjust our idea of where the client is, based on its border. When the
340 border is removed, the client should now be considered to be in a
342 when re-adding the border to the client, the same operation needs to be
344 int oldx = self->area.x, oldy = self->area.y;
345 int x = oldx, y = oldy;
346 switch(self->gravity) {
348 case NorthWestGravity:
350 case SouthWestGravity:
352 case NorthEastGravity:
354 case SouthEastGravity:
355 if (show) x -= self->border_width * 2;
356 else x += self->border_width * 2;
363 if (show) x -= self->border_width;
364 else x += self->border_width;
367 switch(self->gravity) {
369 case NorthWestGravity:
371 case NorthEastGravity:
373 case SouthWestGravity:
375 case SouthEastGravity:
376 if (show) y -= self->border_width * 2;
377 else y += self->border_width * 2;
384 if (show) y -= self->border_width;
385 else y += self->border_width;
392 XSetWindowBorderWidth(ob_display, self->window, self->border_width);
394 /* move the client so it is back it the right spot _with_ its
396 if (x != oldx || y != oldy)
397 XMoveWindow(ob_display, self->window, x, y);
399 XSetWindowBorderWidth(ob_display, self->window, 0);
403 static void client_get_all(Client *self)
405 /* update EVERYTHING!! */
407 self->ignore_unmaps = 0;
411 self->title = self->icon_title = NULL;
412 self->name = self->class = self->role = NULL;
413 self->wmstate = NormalState;
414 self->transient = FALSE;
415 self->transients = NULL;
416 self->transient_for = NULL;
418 self->urgent = FALSE;
419 self->positioned = FALSE;
420 self->disabled_decorations = 0;
424 client_get_area(self);
425 client_get_desktop(self);
426 client_get_state(self);
427 client_get_shaped(self);
429 client_update_transient_for(self);
430 client_get_mwm_hints(self);
431 client_get_type(self);/* this can change the mwmhints for special cases */
433 client_update_protocols(self);
435 client_get_gravity(self); /* get the attribute gravity */
436 client_update_normal_hints(self); /* this may override the attribute
439 /* got the type, the mwmhints, the protocols, and the normal hints
440 (min/max sizes), so we're ready to set up the decorations/functions */
441 client_setup_decor_and_functions(self);
443 client_update_wmhints(self);
444 client_update_title(self);
445 client_update_icon_title(self);
446 client_update_class(self);
447 client_update_strut(self);
448 client_update_icons(self);
449 client_update_kwm_icon(self);
451 /* this makes sure that these windows appear on all desktops */
452 if (self->type == Type_Desktop)
453 self->desktop = DESKTOP_ALL;
455 /* set the desktop hint, to make sure that it always exists, and to
456 reflect any changes we've made here */
457 PROP_SET32(self->window, net_wm_desktop, cardinal, self->desktop);
459 client_change_state(self);
462 static void client_get_area(Client *self)
464 XWindowAttributes wattrib;
467 ret = XGetWindowAttributes(ob_display, self->window, &wattrib);
468 g_assert(ret != BadWindow);
470 RECT_SET(self->area, wattrib.x, wattrib.y, wattrib.width, wattrib.height);
471 self->border_width = wattrib.border_width;
474 static void client_get_desktop(Client *self)
478 if (PROP_GET32(self->window, net_wm_desktop, cardinal, d)) {
479 if (d >= screen_num_desktops && d != DESKTOP_ALL)
480 d = screen_num_desktops - 1;
483 /* defaults to the current desktop */
484 self->desktop = screen_desktop;
488 static void client_get_state(Client *self)
493 self->modal = self->shaded = self->max_horz = self->max_vert =
494 self->fullscreen = self->above = self->below = self->iconic =
495 self->skip_taskbar = self->skip_pager = FALSE;
497 if (PROP_GET32U(self->window, net_wm_state, atom, state, num)) {
499 for (i = 0; i < num; ++i) {
500 if (state[i] == prop_atoms.net_wm_state_modal)
502 else if (state[i] == prop_atoms.net_wm_state_shaded)
504 else if (state[i] == prop_atoms.net_wm_state_hidden)
506 else if (state[i] == prop_atoms.net_wm_state_skip_taskbar)
507 self->skip_taskbar = TRUE;
508 else if (state[i] == prop_atoms.net_wm_state_skip_pager)
509 self->skip_pager = TRUE;
510 else if (state[i] == prop_atoms.net_wm_state_fullscreen)
511 self->fullscreen = TRUE;
512 else if (state[i] == prop_atoms.net_wm_state_maximized_vert)
513 self->max_vert = TRUE;
514 else if (state[i] == prop_atoms.net_wm_state_maximized_horz)
515 self->max_horz = TRUE;
516 else if (state[i] == prop_atoms.net_wm_state_above)
518 else if (state[i] == prop_atoms.net_wm_state_below)
526 static void client_get_shaped(Client *self)
528 self->shaped = FALSE;
530 if (extensions_shape) {
535 XShapeSelectInput(ob_display, self->window, ShapeNotifyMask);
537 XShapeQueryExtents(ob_display, self->window, &s, &foo,
538 &foo, &ufoo, &ufoo, &foo, &foo, &foo, &ufoo,
540 self->shaped = (s != 0);
545 void client_update_transient_for(Client *self)
550 if (XGetTransientForHint(ob_display, self->window, &t) &&
551 t != self->window) { /* cant be transient to itself! */
552 self->transient = TRUE;
553 c = g_hash_table_lookup(client_map, &t);
554 g_assert(c != self);/* if this happens then we need to check for it*/
556 if (!c /*XXX: && _group*/) {
557 /* not transient to a client, see if it is transient for a
559 if (/*t == _group->leader() || */
562 /* window is a transient for its group! */
563 /* XXX: for now this is treated as non-transient.
564 this needs to be fixed! */
568 self->transient = FALSE;
570 /* if anything has changed... */
571 if (c != self->transient_for) {
572 if (self->transient_for)
573 /* remove from old parent */
574 self->transient_for->transients =
575 g_slist_remove(self->transient_for->transients, self);
576 self->transient_for = c;
577 if (self->transient_for)
578 /* add to new parent */
579 self->transient_for->transients =
580 g_slist_append(self->transient_for->transients, self);
584 static void client_get_mwm_hints(Client *self)
587 unsigned long *hints;
589 self->mwmhints.flags = 0; /* default to none */
591 if (PROP_GET32U(self->window, motif_wm_hints, motif_wm_hints, hints, num)) {
592 if (num >= MWM_ELEMENTS) {
593 self->mwmhints.flags = hints[0];
594 self->mwmhints.functions = hints[1];
595 self->mwmhints.decorations = hints[2];
601 void client_get_type(Client *self)
607 if (PROP_GET32U(self->window, net_wm_window_type, atom, val, num)) {
608 /* use the first value that we know about in the array */
609 for (i = 0; i < num; ++i) {
610 if (val[i] == prop_atoms.net_wm_window_type_desktop)
611 self->type = Type_Desktop;
612 else if (val[i] == prop_atoms.net_wm_window_type_dock)
613 self->type = Type_Dock;
614 else if (val[i] == prop_atoms.net_wm_window_type_toolbar)
615 self->type = Type_Toolbar;
616 else if (val[i] == prop_atoms.net_wm_window_type_menu)
617 self->type = Type_Menu;
618 else if (val[i] == prop_atoms.net_wm_window_type_utility)
619 self->type = Type_Utility;
620 else if (val[i] == prop_atoms.net_wm_window_type_splash)
621 self->type = Type_Splash;
622 else if (val[i] == prop_atoms.net_wm_window_type_dialog)
623 self->type = Type_Dialog;
624 else if (val[i] == prop_atoms.net_wm_window_type_normal)
625 self->type = Type_Normal;
626 else if (val[i] == prop_atoms.kde_net_wm_window_type_override) {
627 /* prevent this window from getting any decor or
629 self->mwmhints.flags &= (MwmFlag_Functions |
630 MwmFlag_Decorations);
631 self->mwmhints.decorations = 0;
632 self->mwmhints.functions = 0;
634 if (self->type != (WindowType) -1)
635 break; /* grab the first legit type */
640 if (self->type == (WindowType) -1) {
641 /*the window type hint was not set, which means we either classify
642 ourself as a normal window or a dialog, depending on if we are a
645 self->type = Type_Dialog;
647 self->type = Type_Normal;
651 void client_update_protocols(Client *self)
654 gulong num_return, i;
656 self->focus_notify = FALSE;
657 self->delete_window = FALSE;
659 if (PROP_GET32U(self->window, wm_protocols, atom, proto, num_return)) {
660 for (i = 0; i < num_return; ++i) {
661 if (proto[i] == prop_atoms.wm_delete_window) {
662 /* this means we can request the window to close */
663 self->delete_window = TRUE;
664 } else if (proto[i] == prop_atoms.wm_take_focus)
665 /* if this protocol is requested, then the window will be
666 notified whenever we want it to receive focus */
667 self->focus_notify = TRUE;
673 static void client_get_gravity(Client *self)
675 XWindowAttributes wattrib;
678 ret = XGetWindowAttributes(ob_display, self->window, &wattrib);
679 g_assert(ret != BadWindow);
680 self->gravity = wattrib.win_gravity;
683 void client_update_normal_hints(Client *self)
687 int oldgravity = self->gravity;
690 self->min_ratio = 0.0f;
691 self->max_ratio = 0.0f;
692 SIZE_SET(self->size_inc, 1, 1);
693 SIZE_SET(self->base_size, 0, 0);
694 SIZE_SET(self->min_size, 0, 0);
695 SIZE_SET(self->max_size, G_MAXINT, G_MAXINT);
697 /* get the hints from the window */
698 if (XGetWMNormalHints(ob_display, self->window, &size, &ret)) {
699 self->positioned = (size.flags & (PPosition|USPosition));
701 if (size.flags & PWinGravity) {
702 self->gravity = size.win_gravity;
704 /* if the client has a frame, i.e. has already been mapped and
705 is changing its gravity */
706 if (self->frame && self->gravity != oldgravity) {
707 /* move our idea of the client's position based on its new
709 self->area.x = self->frame->area.x;
710 self->area.y = self->frame->area.y;
711 frame_frame_gravity(self->frame, &self->area.x, &self->area.y);
715 if (size.flags & PAspect) {
716 if (size.min_aspect.y)
717 self->min_ratio = (float)size.min_aspect.x / size.min_aspect.y;
718 if (size.max_aspect.y)
719 self->max_ratio = (float)size.max_aspect.x / size.max_aspect.y;
722 if (size.flags & PMinSize)
723 SIZE_SET(self->min_size, size.min_width, size.min_height);
725 if (size.flags & PMaxSize)
726 SIZE_SET(self->max_size, size.max_width, size.max_height);
728 if (size.flags & PBaseSize)
729 SIZE_SET(self->base_size, size.base_width, size.base_height);
731 if (size.flags & PResizeInc)
732 SIZE_SET(self->size_inc, size.width_inc, size.height_inc);
736 void client_setup_decor_and_functions(Client *self)
738 /* start with everything (cept fullscreen) */
739 self->decorations = Decor_Titlebar | Decor_Handle | Decor_Border |
740 Decor_Icon | Decor_AllDesktops | Decor_Iconify | Decor_Maximize;
741 self->functions = Func_Resize | Func_Move | Func_Iconify | Func_Maximize |
743 if (self->delete_window) {
744 self->decorations |= Decor_Close;
745 self->functions |= Func_Close;
748 if (!(self->min_size.width < self->max_size.width ||
749 self->min_size.height < self->max_size.height)) {
750 self->decorations &= ~(Decor_Maximize | Decor_Handle);
751 self->functions &= ~(Func_Resize | Func_Maximize);
754 switch (self->type) {
756 /* normal windows retain all of the possible decorations and
757 functionality, and are the only windows that you can fullscreen */
758 self->functions |= Func_Fullscreen;
762 /* dialogs cannot be maximized */
763 self->decorations &= ~Decor_Maximize;
764 self->functions &= ~Func_Maximize;
770 /* these windows get less functionality */
771 self->decorations &= ~(Decor_Iconify | Decor_Handle);
772 self->functions &= ~(Func_Iconify | Func_Resize);
778 /* none of these windows are manipulated by the window manager */
779 self->decorations = 0;
784 /* Mwm Hints are applied subtractively to what has already been chosen for
785 decor and functionality */
786 if (self->mwmhints.flags & MwmFlag_Decorations) {
787 if (! (self->mwmhints.decorations & MwmDecor_All)) {
788 if (! (self->mwmhints.decorations & MwmDecor_Border))
789 self->decorations &= ~Decor_Border;
790 if (! (self->mwmhints.decorations & MwmDecor_Handle))
791 self->decorations &= ~Decor_Handle;
792 if (! (self->mwmhints.decorations & MwmDecor_Title))
793 self->decorations &= ~Decor_Titlebar;
794 if (! (self->mwmhints.decorations & MwmDecor_Iconify))
795 self->decorations &= ~Decor_Iconify;
796 if (! (self->mwmhints.decorations & MwmDecor_Maximize))
797 self->decorations &= ~Decor_Maximize;
801 if (self->mwmhints.flags & MwmFlag_Functions) {
802 if (! (self->mwmhints.functions & MwmFunc_All)) {
803 if (! (self->mwmhints.functions & MwmFunc_Resize))
804 self->functions &= ~Func_Resize;
805 if (! (self->mwmhints.functions & MwmFunc_Move))
806 self->functions &= ~Func_Move;
807 if (! (self->mwmhints.functions & MwmFunc_Iconify))
808 self->functions &= ~Func_Iconify;
809 if (! (self->mwmhints.functions & MwmFunc_Maximize))
810 self->functions &= ~Func_Maximize;
811 /* dont let mwm hints kill the close button
812 if (! (self->mwmhints.functions & MwmFunc_Close))
813 self->functions &= ~Func_Close; */
817 /* can't maximize without moving/resizing */
818 if (!((self->functions & Func_Move) && (self->functions & Func_Resize)))
819 self->functions &= ~(Func_Maximize | Func_Fullscreen);
821 /* finally, user specified disabled decorations are applied to subtract
823 if (self->disabled_decorations & Decor_Titlebar)
824 self->decorations &= ~Decor_Titlebar;
825 if (self->disabled_decorations & Decor_Handle)
826 self->decorations &= ~Decor_Handle;
827 if (self->disabled_decorations & Decor_Border)
828 self->decorations &= ~Decor_Border;
829 if (self->disabled_decorations & Decor_Iconify)
830 self->decorations &= ~Decor_Iconify;
831 if (self->disabled_decorations & Decor_Maximize)
832 self->decorations &= ~Decor_Maximize;
833 if (self->disabled_decorations & Decor_AllDesktops)
834 self->decorations &= ~Decor_AllDesktops;
835 if (self->disabled_decorations & Decor_Close)
836 self->decorations &= ~Decor_Close;
838 /* if we don't have a titlebar, then we cannot shade! */
839 if (!(self->decorations & Decor_Titlebar))
840 self->functions &= ~Func_Shade;
842 client_change_allowed_actions(self);
845 /* change the decors on the frame, and with more/less decorations,
846 we may also need to be repositioned */
847 engine_frame_adjust_area(self->frame, TRUE, TRUE);
848 /* with new decor, the window's maximized size may change */
849 client_remaximize(self);
853 static void client_change_allowed_actions(Client *self)
858 actions[num++] = prop_atoms.net_wm_action_change_desktop;
860 if (self->functions & Func_Shade)
861 actions[num++] = prop_atoms.net_wm_action_shade;
862 if (self->functions & Func_Close)
863 actions[num++] = prop_atoms.net_wm_action_close;
864 if (self->functions & Func_Move)
865 actions[num++] = prop_atoms.net_wm_action_move;
866 if (self->functions & Func_Iconify)
867 actions[num++] = prop_atoms.net_wm_action_minimize;
868 if (self->functions & Func_Resize)
869 actions[num++] = prop_atoms.net_wm_action_resize;
870 if (self->functions & Func_Fullscreen)
871 actions[num++] = prop_atoms.net_wm_action_fullscreen;
872 if (self->functions & Func_Maximize) {
873 actions[num++] = prop_atoms.net_wm_action_maximize_horz;
874 actions[num++] = prop_atoms.net_wm_action_maximize_vert;
877 PROP_SET32A(self->window, net_wm_allowed_actions, atom, actions, num);
879 /* make sure the window isn't breaking any rules now */
881 if (!(self->functions & Func_Shade) && self->shaded) {
882 if (self->frame) client_shade(self, FALSE);
883 else self->shaded = FALSE;
885 if (!(self->functions & Func_Iconify) && self->iconic) {
886 if (self->frame) client_iconify(self, FALSE, TRUE);
887 else self->iconic = FALSE;
889 if (!(self->functions & Func_Fullscreen) && self->fullscreen) {
890 if (self->frame) client_fullscreen(self, FALSE, TRUE);
891 else self->fullscreen = FALSE;
893 if (!(self->functions & Func_Maximize) && (self->max_horz ||
895 if (self->frame) client_maximize(self, FALSE, 0, TRUE);
896 else self->max_vert = self->max_horz = FALSE;
900 void client_remaximize(Client *self)
903 if (self->max_horz && self->max_vert)
905 else if (self->max_horz)
907 else if (self->max_vert)
910 return; /* not maximized */
911 self->max_horz = self->max_vert = FALSE;
912 client_maximize(self, TRUE, dir, FALSE);
915 void client_update_wmhints(Client *self)
920 /* assume a window takes input if it doesnt specify */
921 self->can_focus = TRUE;
923 if ((hints = XGetWMHints(ob_display, self->window)) != NULL) {
924 if (hints->flags & InputHint)
925 self->can_focus = hints->input;
927 /* only do this when starting! */
928 if (ob_state == State_Starting && (hints->flags & StateHint))
929 self->iconic = hints->initial_state == IconicState;
931 if (hints->flags & XUrgencyHint)
934 if (hints->flags & WindowGroupHint) {
935 if (hints->window_group != self->group) {
936 /* XXX: remove from the old group if there was one */
937 self->group = hints->window_group;
938 /* XXX: do stuff with the group */
940 } else /* no group! */
943 if (hints->flags & IconPixmapHint) {
944 client_update_kwm_icon(self);
945 /* try get the kwm icon first, this is a fallback only */
946 if (self->pixmap_icon == None) {
947 self->pixmap_icon = hints->icon_pixmap;
948 if (hints->flags & IconMaskHint)
949 self->pixmap_icon_mask = hints->icon_mask;
951 self->pixmap_icon_mask = None;
954 engine_frame_adjust_icon(self->frame);
961 if (ur != self->urgent) {
963 g_message("Urgent Hint for 0x%lx: %s", self->window,
965 /* fire the urgent callback if we're mapped, otherwise, wait until
966 after we're mapped */
968 dispatch_client(Event_Client_Urgent, self, self->urgent, 0);
972 void client_update_title(Client *self)
979 if (!PROP_GETS(self->window, net_wm_name, utf8, data)) {
980 /* try old x stuff */
981 if (PROP_GETS(self->window, wm_name, string, data)) {
982 /* convert it to UTF-8 */
986 u = g_locale_to_utf8(data, -1, &r, &w, NULL);
988 g_warning("Unable to convert string to UTF-8");
995 data = g_strdup("Unnamed Window");
997 PROP_SETS(self->window, net_wm_visible_name, utf8, data);
1003 engine_frame_adjust_title(self->frame);
1006 void client_update_icon_title(Client *self)
1010 g_free(self->icon_title);
1013 if (!PROP_GETS(self->window, net_wm_icon_name, utf8, data)) {
1014 /* try old x stuff */
1015 if (PROP_GETS(self->window, wm_icon_name, string, data)) {
1016 /* convert it to UTF-8 */
1020 u = g_locale_to_utf8(data, -1, &r, &w, NULL);
1022 g_warning("Unable to convert string to UTF-8");
1029 data = g_strdup("Unnamed Window");
1031 PROP_SETS(self->window, net_wm_visible_icon_name, utf8, data);
1034 self->icon_title = data;
1037 void client_update_class(Client *self)
1043 if (self->name) g_free(self->name);
1044 if (self->class) g_free(self->class);
1045 if (self->role) g_free(self->role);
1047 self->name = self->class = self->role = NULL;
1049 data = g_ptr_array_new();
1051 if (PROP_GETSA(self->window, wm_class, string, data)) {
1053 self->name = g_strdup(g_ptr_array_index(data, 0));
1055 self->class = g_strdup(g_ptr_array_index(data, 1));
1058 for (i = 0; i < data->len; ++i)
1059 g_free(g_ptr_array_index(data, i));
1060 g_ptr_array_free(data, TRUE);
1062 if (PROP_GETS(self->window, wm_window_role, string, s))
1063 self->role = g_strdup(s);
1065 if (self->name == NULL) self->name = g_strdup("");
1066 if (self->class == NULL) self->class = g_strdup("");
1067 if (self->role == NULL) self->role = g_strdup("");
1070 void client_update_strut(Client *self)
1074 if (PROP_GET32A(self->window, net_wm_strut, cardinal, data, 4)) {
1075 STRUT_SET(self->strut, data[0], data[1], data[2], data[3]);
1078 STRUT_SET(self->strut, 0, 0, 0, 0);
1080 /* updating here is pointless while we're being mapped cuz we're not in
1081 the client list yet */
1083 screen_update_struts();
1086 void client_update_icons(Client *self)
1089 unsigned long *data;
1090 unsigned long w, h, i;
1093 for (j = 0; j < self->nicons; ++j)
1094 g_free(self->icons[j].data);
1095 if (self->nicons > 0)
1096 g_free(self->icons);
1099 if (PROP_GET32U(self->window, net_wm_icon, cardinal, data, num)) {
1100 /* figure out how many valid icons are in here */
1102 while (num - i > 2) {
1110 self->icons = g_new(Icon, self->nicons);
1112 /* store the icons */
1114 for (j = 0; j < self->nicons; ++j) {
1115 w = self->icons[j].w = data[i++];
1116 h = self->icons[j].h = data[i++];
1117 self->icons[j].data =
1118 g_memdup(&data[i], w * h * sizeof(gulong));
1126 if (self->nicons <= 0) {
1128 self->icons = g_new0(Icon, 1);
1132 engine_frame_adjust_icon(self->frame);
1135 void client_update_kwm_icon(Client *self)
1139 if (PROP_GET32A(self->window, kwm_win_icon, kwm_win_icon, data, 2)) {
1140 self->pixmap_icon = data[0];
1141 self->pixmap_icon_mask = data[1];
1144 self->pixmap_icon = self->pixmap_icon_mask = None;
1147 engine_frame_adjust_icon(self->frame);
1150 static void client_change_state(Client *self)
1152 unsigned long state[2];
1156 state[0] = self->wmstate;
1158 PROP_SET32A(self->window, wm_state, wm_state, state, 2);
1162 netstate[num++] = prop_atoms.net_wm_state_modal;
1164 netstate[num++] = prop_atoms.net_wm_state_shaded;
1166 netstate[num++] = prop_atoms.net_wm_state_hidden;
1167 if (self->skip_taskbar)
1168 netstate[num++] = prop_atoms.net_wm_state_skip_taskbar;
1169 if (self->skip_pager)
1170 netstate[num++] = prop_atoms.net_wm_state_skip_pager;
1171 if (self->fullscreen)
1172 netstate[num++] = prop_atoms.net_wm_state_fullscreen;
1174 netstate[num++] = prop_atoms.net_wm_state_maximized_vert;
1176 netstate[num++] = prop_atoms.net_wm_state_maximized_horz;
1178 netstate[num++] = prop_atoms.net_wm_state_above;
1180 netstate[num++] = prop_atoms.net_wm_state_below;
1181 PROP_SET32A(self->window, net_wm_state, atom, netstate, num);
1183 client_calc_layer(self);
1186 engine_frame_adjust_state(self->frame);
1189 static Client *search_focus_tree(Client *node, Client *skip)
1194 for (it = node->transients; it != NULL; it = it->next) {
1195 Client *c = it->data;
1196 if (c == skip) continue; /* circular? */
1197 if ((ret = search_focus_tree(c, skip))) return ret;
1198 if (client_focused(c)) return c;
1203 void client_calc_layer(Client *self)
1209 /* are we fullscreen, or do we have a fullscreen transient parent? */
1213 if (c->fullscreen) {
1217 c = c->transient_for;
1219 if (!fs && self->fullscreen) {
1220 /* is one of our transients focused? */
1221 c = search_focus_tree(self, self);
1222 if (c != NULL) fs = TRUE;
1225 if (self->iconic) l = Layer_Icon;
1226 else if (fs) l = Layer_Fullscreen;
1227 else if (self->type == Type_Desktop) l = Layer_Desktop;
1228 else if (self->type == Type_Dock) {
1229 if (!self->below) l = Layer_Top;
1230 else l = Layer_Normal;
1232 else if (self->above) l = Layer_Above;
1233 else if (self->below) l = Layer_Below;
1234 else l = Layer_Normal;
1236 if (l != self->layer) {
1239 stacking_raise(self);
1243 gboolean client_should_show(Client *self)
1245 if (self->iconic) return FALSE;
1246 else if (!(self->desktop == screen_desktop ||
1247 self->desktop == DESKTOP_ALL)) return FALSE;
1248 else if (client_normal(self) && screen_showing_desktop) return FALSE;
1253 static void client_showhide(Client *self)
1256 if (client_should_show(self))
1257 engine_frame_show(self->frame);
1259 engine_frame_hide(self->frame);
1262 gboolean client_normal(Client *self) {
1263 return ! (self->type == Type_Desktop || self->type == Type_Dock ||
1264 self->type == Type_Splash);
1267 static void client_apply_startup_state(Client *self)
1269 /* these are in a carefully crafted order.. */
1272 self->iconic = FALSE;
1273 client_iconify(self, TRUE, FALSE);
1275 if (self->fullscreen) {
1276 self->fullscreen = FALSE;
1277 client_fullscreen(self, TRUE, FALSE);
1280 self->shaded = FALSE;
1281 client_shade(self, TRUE);
1284 dispatch_client(Event_Client_Urgent, self, self->urgent, 0);
1286 if (self->max_vert && self->max_horz) {
1287 self->max_vert = self->max_horz = FALSE;
1288 client_maximize(self, TRUE, 0, FALSE);
1289 } else if (self->max_vert) {
1290 self->max_vert = FALSE;
1291 client_maximize(self, TRUE, 2, FALSE);
1292 } else if (self->max_horz) {
1293 self->max_horz = FALSE;
1294 client_maximize(self, TRUE, 1, FALSE);
1297 /* nothing to do for the other states:
1306 void client_configure(Client *self, Corner anchor, int x, int y, int w, int h,
1307 gboolean user, gboolean final)
1309 gboolean moved = FALSE, resized = FALSE;
1311 /* set the size and position if fullscreen */
1312 if (self->fullscreen) {
1315 w = screen_physical_size.width;
1316 h = screen_physical_size.height;
1318 /* set the size and position if maximized */
1319 if (self->max_horz) {
1320 x = screen_area(self->desktop)->x - self->frame->size.left;
1321 w = screen_area(self->desktop)->x +
1322 screen_area(self->desktop)->width;
1324 if (self->max_vert) {
1325 y = screen_area(self->desktop)->y;
1326 h = screen_area(self->desktop)->y +
1327 screen_area(self->desktop)->height -
1328 self->frame->size.top - self->frame->size.bottom;
1332 /* these override the above states! if you cant move you can't move! */
1334 if (!(self->functions & Func_Move)) {
1338 if (!(self->functions & Func_Resize)) {
1339 w = self->area.width;
1340 h = self->area.height;
1344 if (!(w == self->area.width && h == self->area.height)) {
1345 w -= self->base_size.width;
1346 h -= self->base_size.height;
1349 /* for interactive resizing. have to move half an increment in each
1352 /* how far we are towards the next size inc */
1353 int mw = w % self->size_inc.width;
1354 int mh = h % self->size_inc.height;
1356 int aw = self->size_inc.width / 2;
1357 int ah = self->size_inc.height / 2;
1358 /* don't let us move into a new size increment */
1359 if (mw + aw >= self->size_inc.width)
1360 aw = self->size_inc.width - mw - 1;
1361 if (mh + ah >= self->size_inc.height)
1362 ah = self->size_inc.height - mh - 1;
1366 /* if this is a user-requested resize, then check against min/max
1367 sizes and aspect ratios */
1369 /* smaller than min size or bigger than max size? */
1370 if (w > self->max_size.width) w = self->max_size.width;
1371 if (w < self->min_size.width) w = self->min_size.width;
1372 if (h > self->max_size.height) h = self->max_size.height;
1373 if (h < self->min_size.height) h = self->min_size.height;
1375 /* adjust the height ot match the width for the aspect ratios */
1376 if (self->min_ratio)
1377 if (h * self->min_ratio > w) h = (int)(w / self->min_ratio);
1378 if (self->max_ratio)
1379 if (h * self->max_ratio < w) h = (int)(w / self->max_ratio);
1382 /* keep to the increments */
1383 w /= self->size_inc.width;
1384 h /= self->size_inc.height;
1386 /* you cannot resize to nothing */
1390 /* store the logical size */
1391 SIZE_SET(self->logical_size, w, h);
1393 w *= self->size_inc.width;
1394 h *= self->size_inc.height;
1396 w += self->base_size.width;
1397 h += self->base_size.height;
1401 case Corner_TopLeft:
1403 case Corner_TopRight:
1404 x -= w - self->area.width;
1406 case Corner_BottomLeft:
1407 y -= h - self->area.height;
1409 case Corner_BottomRight:
1410 x -= w - self->area.width;
1411 y -= h - self->area.height;
1415 moved = x != self->area.x || y != self->area.y;
1416 resized = w != self->area.width || h != self->area.height;
1418 RECT_SET(self->area, x, y, w, h);
1421 XResizeWindow(ob_display, self->window, w, h);
1423 /* move/resize the frame to match the request */
1425 if (moved || resized)
1426 engine_frame_adjust_area(self->frame, moved, resized);
1428 if (!user || final) {
1430 event.type = ConfigureNotify;
1431 event.xconfigure.display = ob_display;
1432 event.xconfigure.event = self->window;
1433 event.xconfigure.window = self->window;
1435 /* root window coords with border in mind */
1436 event.xconfigure.x = x - self->border_width +
1437 self->frame->size.left;
1438 event.xconfigure.y = y - self->border_width +
1439 self->frame->size.top;
1441 event.xconfigure.width = self->area.width;
1442 event.xconfigure.height = self->area.height;
1443 event.xconfigure.border_width = self->border_width;
1444 event.xconfigure.above = self->frame->plate;
1445 event.xconfigure.override_redirect = FALSE;
1446 XSendEvent(event.xconfigure.display, event.xconfigure.window,
1447 FALSE, StructureNotifyMask, &event);
1452 void client_fullscreen(Client *self, gboolean fs, gboolean savearea)
1456 if (!(self->functions & Func_Fullscreen) || /* can't */
1457 self->fullscreen == fs) return; /* already done */
1459 self->fullscreen = fs;
1460 client_change_state(self); /* change the state hints on the client */
1463 /* save the functions and remove them */
1464 self->pre_fs_func = self->functions;
1465 self->functions &= (Func_Close | Func_Fullscreen |
1467 /* save the decorations and remove them */
1468 self->pre_fs_decor = self->decorations;
1469 self->decorations = 0;
1472 dimensions[0] = self->area.x;
1473 dimensions[1] = self->area.y;
1474 dimensions[2] = self->area.width;
1475 dimensions[3] = self->area.height;
1477 PROP_SET32A(self->window, openbox_premax, cardinal,
1481 /* these are not actually used cuz client_configure will set them
1482 as appropriate when the window is fullscreened */
1487 self->functions = self->pre_fs_func;
1488 self->decorations = self->pre_fs_decor;
1490 if (PROP_GET32A(self->window, openbox_premax, cardinal,
1498 /* pick some fallbacks... */
1499 x = screen_area(self->desktop)->x +
1500 screen_area(self->desktop)->width / 4;
1501 y = screen_area(self->desktop)->y +
1502 screen_area(self->desktop)->height / 4;
1503 w = screen_area(self->desktop)->width / 2;
1504 h = screen_area(self->desktop)->height / 2;
1508 client_change_allowed_actions(self); /* based on the new _functions */
1510 /* when fullscreening, don't obey things like increments, fill the
1512 client_configure(self, Corner_TopLeft, x, y, w, h, !fs, TRUE);
1514 /* raise (back) into our stacking layer */
1515 stacking_raise(self);
1517 /* try focus us when we go into fullscreen mode */
1521 void client_iconify(Client *self, gboolean iconic, gboolean curdesk)
1523 if (self->iconic == iconic) return; /* nothing to do */
1525 g_message("%sconifying window: 0x%lx", (iconic ? "I" : "Uni"),
1528 self->iconic = iconic;
1531 self->wmstate = IconicState;
1532 self->ignore_unmaps++;
1533 /* we unmap the client itself so that we can get MapRequest events,
1534 and because the ICCCM tells us to! */
1535 XUnmapWindow(ob_display, self->window);
1538 client_set_desktop(self, screen_desktop);
1539 self->wmstate = self->shaded ? IconicState : NormalState;
1540 XMapWindow(ob_display, self->window);
1542 client_change_state(self);
1543 client_showhide(self);
1544 screen_update_struts();
1546 dispatch_client(iconic ? Event_Client_Unmapped : Event_Client_Mapped,
1550 void client_maximize(Client *self, gboolean max, int dir, gboolean savearea)
1554 g_assert(dir == 0 || dir == 1 || dir == 2);
1555 if (!(self->functions & Func_Maximize)) return; /* can't */
1557 /* check if already done */
1559 if (dir == 0 && self->max_horz && self->max_vert) return;
1560 if (dir == 1 && self->max_horz) return;
1561 if (dir == 2 && self->max_vert) return;
1563 if (dir == 0 && !self->max_horz && !self->max_vert) return;
1564 if (dir == 1 && !self->max_horz) return;
1565 if (dir == 2 && !self->max_vert) return;
1568 /* work with the frame's coords */
1569 x = self->frame->area.x;
1570 y = self->frame->area.y;
1571 w = self->area.width;
1572 h = self->area.height;
1584 /* get the property off the window and use it for the dimensions
1585 we are already maxed on */
1586 if (PROP_GET32A(self->window, openbox_premax, cardinal,
1588 if (self->max_horz) {
1589 dimensions[0] = readdim[0];
1590 dimensions[2] = readdim[2];
1592 if (self->max_vert) {
1593 dimensions[1] = readdim[1];
1594 dimensions[3] = readdim[3];
1599 PROP_SET32A(self->window, openbox_premax, cardinal,
1603 /* pass the client's current position info. the client_configure
1604 will move/size stuff as appropriate for a maximized window */
1607 w = self->area.width;
1608 h = self->area.height;
1612 if (PROP_GET32A(self->window, openbox_premax, cardinal,
1614 if (dir == 0 || dir == 1) { /* horz */
1618 if (dir == 0 || dir == 2) { /* vert */
1624 /* pick some fallbacks... */
1625 if (dir == 0 || dir == 1) { /* horz */
1626 x = screen_area(self->desktop)->x +
1627 screen_area(self->desktop)->width / 4;
1628 w = screen_area(self->desktop)->width / 2;
1630 if (dir == 0 || dir == 2) { /* vert */
1631 y = screen_area(self->desktop)->y +
1632 screen_area(self->desktop)->height / 4;
1633 h = screen_area(self->desktop)->height / 2;
1638 if (dir == 0 || dir == 1) /* horz */
1639 self->max_horz = max;
1640 if (dir == 0 || dir == 2) /* vert */
1641 self->max_vert = max;
1643 if (!self->max_horz && !self->max_vert)
1644 PROP_ERASE(self->window, openbox_premax);
1646 client_change_state(self); /* change the state hints on the client */
1648 /* figure out where the client should be going */
1649 frame_frame_gravity(self->frame, &x, &y);
1650 client_configure(self, Corner_TopLeft, x, y, w, h, TRUE, TRUE);
1653 void client_shade(Client *self, gboolean shade)
1655 if (!(self->functions & Func_Shade) || /* can't */
1656 self->shaded == shade) return; /* already done */
1658 /* when we're iconic, don't change the wmstate */
1660 self->wmstate = shade ? IconicState : NormalState;
1661 self->shaded = shade;
1662 client_change_state(self);
1663 /* resize the frame to just the titlebar */
1664 engine_frame_adjust_area(self->frame, FALSE, FALSE);
1667 void client_close(Client *self)
1671 if (!(self->functions & Func_Close)) return;
1674 XXX: itd be cool to do timeouts and shit here for killing the client's
1676 like... if the window is around after 5 seconds, then the close button
1677 turns a nice red, and if this function is called again, the client is
1681 ce.xclient.type = ClientMessage;
1682 ce.xclient.message_type = prop_atoms.wm_protocols;
1683 ce.xclient.display = ob_display;
1684 ce.xclient.window = self->window;
1685 ce.xclient.format = 32;
1686 ce.xclient.data.l[0] = prop_atoms.wm_delete_window;
1687 ce.xclient.data.l[1] = event_lasttime;
1688 ce.xclient.data.l[2] = 0l;
1689 ce.xclient.data.l[3] = 0l;
1690 ce.xclient.data.l[4] = 0l;
1691 XSendEvent(ob_display, self->window, FALSE, NoEventMask, &ce);
1694 void client_kill(Client *self)
1696 XKillClient(ob_display, self->window);
1699 void client_set_desktop(Client *self, guint target)
1703 if (target == self->desktop) return;
1705 g_message("Setting desktop %u\n", target);
1707 g_assert(target < screen_num_desktops || target == DESKTOP_ALL);
1709 old = self->desktop;
1710 self->desktop = target;
1711 PROP_SET32(self->window, net_wm_desktop, cardinal, target);
1712 /* the frame can display the current desktop state */
1713 engine_frame_adjust_state(self->frame);
1714 /* 'move' the window to the new desktop */
1715 client_showhide(self);
1716 screen_update_struts();
1718 /* update the focus lists */
1719 if (old == DESKTOP_ALL) {
1720 for (i = 0; i < screen_num_desktops; ++i)
1721 focus_order[i] = g_list_remove(focus_order[i], self);
1722 focus_order[target] = g_list_prepend(focus_order[target], self);
1724 focus_order[old] = g_list_remove(focus_order[old], self);
1725 if (target == DESKTOP_ALL)
1726 for (i = 0; i < screen_num_desktops; ++i)
1727 focus_order[i] = g_list_prepend(focus_order[i], self);
1730 dispatch_client(Event_Client_Desktop, self, target, old);
1733 static Client *search_modal_tree(Client *node, Client *skip)
1738 for (it = node->transients; it != NULL; it = it->next) {
1739 Client *c = it->data;
1740 if (c == skip) continue; /* circular? */
1741 if ((ret = search_modal_tree(c, skip))) return ret;
1742 if (c->modal) return c;
1747 Client *client_find_modal_child(Client *self)
1749 return search_modal_tree(self, self);
1752 gboolean client_validate(Client *self)
1756 XSync(ob_display, FALSE); /* get all events on the server */
1758 if (XCheckTypedWindowEvent(ob_display, self->window, DestroyNotify, &e) ||
1759 XCheckTypedWindowEvent(ob_display, self->window, UnmapNotify, &e)) {
1760 XPutBackEvent(ob_display, &e);
1767 void client_set_wm_state(Client *self, long state)
1769 if (state == self->wmstate) return; /* no change */
1773 client_iconify(self, TRUE, TRUE);
1776 client_iconify(self, FALSE, TRUE);
1781 void client_set_state(Client *self, Atom action, long data1, long data2)
1783 gboolean shaded = self->shaded;
1784 gboolean fullscreen = self->fullscreen;
1785 gboolean max_horz = self->max_horz;
1786 gboolean max_vert = self->max_vert;
1789 if (!(action == prop_atoms.net_wm_state_add ||
1790 action == prop_atoms.net_wm_state_remove ||
1791 action == prop_atoms.net_wm_state_toggle))
1792 /* an invalid action was passed to the client message, ignore it */
1795 for (i = 0; i < 2; ++i) {
1796 Atom state = i == 0 ? data1 : data2;
1798 if (!state) continue;
1800 /* if toggling, then pick whether we're adding or removing */
1801 if (action == prop_atoms.net_wm_state_toggle) {
1802 if (state == prop_atoms.net_wm_state_modal)
1803 action = self->modal ? prop_atoms.net_wm_state_remove :
1804 prop_atoms.net_wm_state_add;
1805 else if (state == prop_atoms.net_wm_state_maximized_vert)
1806 action = self->max_vert ? prop_atoms.net_wm_state_remove :
1807 prop_atoms.net_wm_state_add;
1808 else if (state == prop_atoms.net_wm_state_maximized_horz)
1809 action = self->max_horz ? prop_atoms.net_wm_state_remove :
1810 prop_atoms.net_wm_state_add;
1811 else if (state == prop_atoms.net_wm_state_shaded)
1812 action = self->shaded ? prop_atoms.net_wm_state_remove :
1813 prop_atoms.net_wm_state_add;
1814 else if (state == prop_atoms.net_wm_state_skip_taskbar)
1815 action = self->skip_taskbar ?
1816 prop_atoms.net_wm_state_remove :
1817 prop_atoms.net_wm_state_add;
1818 else if (state == prop_atoms.net_wm_state_skip_pager)
1819 action = self->skip_pager ?
1820 prop_atoms.net_wm_state_remove :
1821 prop_atoms.net_wm_state_add;
1822 else if (state == prop_atoms.net_wm_state_fullscreen)
1823 action = self->fullscreen ?
1824 prop_atoms.net_wm_state_remove :
1825 prop_atoms.net_wm_state_add;
1826 else if (state == prop_atoms.net_wm_state_above)
1827 action = self->above ? prop_atoms.net_wm_state_remove :
1828 prop_atoms.net_wm_state_add;
1829 else if (state == prop_atoms.net_wm_state_below)
1830 action = self->below ? prop_atoms.net_wm_state_remove :
1831 prop_atoms.net_wm_state_add;
1834 if (action == prop_atoms.net_wm_state_add) {
1835 if (state == prop_atoms.net_wm_state_modal) {
1836 /* XXX raise here or something? */
1838 } else if (state == prop_atoms.net_wm_state_maximized_vert) {
1840 } else if (state == prop_atoms.net_wm_state_maximized_horz) {
1842 } else if (state == prop_atoms.net_wm_state_shaded) {
1844 } else if (state == prop_atoms.net_wm_state_skip_taskbar) {
1845 self->skip_taskbar = TRUE;
1846 } else if (state == prop_atoms.net_wm_state_skip_pager) {
1847 self->skip_pager = TRUE;
1848 } else if (state == prop_atoms.net_wm_state_fullscreen) {
1850 } else if (state == prop_atoms.net_wm_state_above) {
1852 } else if (state == prop_atoms.net_wm_state_below) {
1856 } else { /* action == prop_atoms.net_wm_state_remove */
1857 if (state == prop_atoms.net_wm_state_modal) {
1858 self->modal = FALSE;
1859 } else if (state == prop_atoms.net_wm_state_maximized_vert) {
1861 } else if (state == prop_atoms.net_wm_state_maximized_horz) {
1863 } else if (state == prop_atoms.net_wm_state_shaded) {
1865 } else if (state == prop_atoms.net_wm_state_skip_taskbar) {
1866 self->skip_taskbar = FALSE;
1867 } else if (state == prop_atoms.net_wm_state_skip_pager) {
1868 self->skip_pager = FALSE;
1869 } else if (state == prop_atoms.net_wm_state_fullscreen) {
1871 } else if (state == prop_atoms.net_wm_state_above) {
1872 self->above = FALSE;
1873 } else if (state == prop_atoms.net_wm_state_below) {
1874 self->below = FALSE;
1878 if (max_horz != self->max_horz || max_vert != self->max_vert) {
1879 if (max_horz != self->max_horz && max_vert != self->max_vert) {
1881 if (max_horz == max_vert) { /* both going the same way */
1882 client_maximize(self, max_horz, 0, TRUE);
1884 client_maximize(self, max_horz, 1, TRUE);
1885 client_maximize(self, max_vert, 2, TRUE);
1889 if (max_horz != self->max_horz)
1890 client_maximize(self, max_horz, 1, TRUE);
1892 client_maximize(self, max_vert, 2, TRUE);
1895 /* change fullscreen state before shading, as it will affect if the window
1897 if (fullscreen != self->fullscreen)
1898 client_fullscreen(self, fullscreen, TRUE);
1899 if (shaded != self->shaded)
1900 client_shade(self, shaded);
1901 client_calc_layer(self);
1902 client_change_state(self); /* change the hint to relect these changes */
1905 gboolean client_focus(Client *self)
1910 /* if we have a modal child, then focus it, not us */
1911 child = client_find_modal_child(self);
1913 return client_focus(child);
1915 /* won't try focus if the client doesn't want it, or if the window isn't
1916 visible on the screen */
1917 if (!(self->frame->visible &&
1918 (self->can_focus || self->focus_notify)))
1921 /* do a check to see if the window has already been unmapped or destroyed
1922 do this intelligently while watching out for unmaps we've generated
1923 (ignore_unmaps > 0) */
1924 if (XCheckTypedWindowEvent(ob_display, self->window,
1925 DestroyNotify, &ev)) {
1926 XPutBackEvent(ob_display, &ev);
1929 while (XCheckTypedWindowEvent(ob_display, self->window,
1930 UnmapNotify, &ev)) {
1931 if (self->ignore_unmaps) {
1932 self->ignore_unmaps--;
1934 XPutBackEvent(ob_display, &ev);
1939 if (self->can_focus)
1940 XSetInputFocus(ob_display, self->window, RevertToNone,
1943 if (self->focus_notify) {
1945 ce.xclient.type = ClientMessage;
1946 ce.xclient.message_type = prop_atoms.wm_protocols;
1947 ce.xclient.display = ob_display;
1948 ce.xclient.window = self->window;
1949 ce.xclient.format = 32;
1950 ce.xclient.data.l[0] = prop_atoms.wm_take_focus;
1951 ce.xclient.data.l[1] = CurrentTime;
1952 ce.xclient.data.l[2] = 0l;
1953 ce.xclient.data.l[3] = 0l;
1954 ce.xclient.data.l[4] = 0l;
1955 XSendEvent(ob_display, self->window, FALSE, NoEventMask, &ce);
1958 /* XSync(ob_display, FALSE); XXX Why sync? */
1962 void client_unfocus(Client *self)
1964 g_assert(focus_client == self);
1965 client_set_focused(self, FALSE);
1968 gboolean client_focused(Client *self)
1970 return self == focus_client;
1973 void client_set_focused(Client *self, gboolean focused)
1976 if (focus_client != self)
1977 focus_set_client(self);
1979 if (focus_client == self)
1980 focus_set_client(NULL);
1983 /* focus state can affect the stacking layer */
1984 client_calc_layer(self);
1986 engine_frame_adjust_focus(self->frame);