4 #include "extensions.h"
12 #include <X11/Xutil.h>
14 /*! The event mask to grab on client windows */
15 #define CLIENT_EVENTMASK (PropertyChangeMask | FocusChangeMask | \
18 #define CLIENT_NOPROPAGATEMASK (ButtonPressMask | ButtonReleaseMask | \
21 GSList *client_list = NULL;
22 GHashTable *client_map = NULL;
24 static void client_get_all(Client *self);
25 static void client_toggle_border(Client *self, gboolean show);
26 static void client_get_area(Client *self);
27 static void client_get_desktop(Client *self);
28 static void client_get_state(Client *self);
29 static void client_get_shaped(Client *self);
30 static void client_get_mwm_hints(Client *self);
31 static void client_get_gravity(Client *self);
32 static void client_showhide(Client *self);
33 static void client_change_allowed_actions(Client *self);
34 static void client_change_state(Client *self);
35 static Client *search_focus_tree(Client *node, Client *skip);
36 static void client_apply_startup_state(Client *self);
37 static Client *search_modal_tree(Client *node, Client *skip);
39 static guint map_hash(Window w) { return w; }
40 static gboolean map_key_comp(Window w1, Window w2) { return w1 == w2; }
44 client_map = g_hash_table_new((GHashFunc)map_hash,
45 (GEqualFunc)map_key_comp);
49 void client_shutdown()
51 g_hash_table_destroy(client_map);
54 void client_set_list()
56 Window *windows, *win_it;
58 guint size = g_slist_length(client_list);
60 /* create an array of the window ids */
62 windows = g_new(Window, size);
64 for (it = client_list; it != NULL; it = it->next, ++win_it)
65 *win_it = ((Client*)it->data)->window;
69 PROP_SET32A(ob_root, net_client_list, window, windows, size);
77 void client_manage_all()
79 unsigned int i, j, nchild;
82 XWindowAttributes attrib;
84 XQueryTree(ob_display, ob_root, &w, &w, &children, &nchild);
86 /* remove all icon windows from the list */
87 for (i = 0; i < nchild; i++) {
88 if (children[i] == None) continue;
89 wmhints = XGetWMHints(ob_display, children[i]);
91 if ((wmhints->flags & IconWindowHint) &&
92 (wmhints->icon_window != children[i]))
93 for (j = 0; j < nchild; j++)
94 if (children[j] == wmhints->icon_window) {
102 for (i = 0; i < nchild; ++i) {
103 if (children[i] == None)
105 if (XGetWindowAttributes(ob_display, children[i], &attrib)) {
106 if (attrib.override_redirect) continue;
108 if (attrib.map_state != IsUnmapped)
109 client_manage(children[i]);
115 void client_manage(Window window)
119 XWindowAttributes attrib;
120 XSetWindowAttributes attrib_set;
121 /* XWMHints *wmhint; */
123 XGrabServer(ob_display);
124 XSync(ob_display, FALSE);
126 /* check if it has already been unmapped by the time we started mapping
127 the grab does a sync so we don't have to here */
128 if (XCheckTypedWindowEvent(ob_display, window, DestroyNotify, &e) ||
129 XCheckTypedWindowEvent(ob_display, window, UnmapNotify, &e)) {
130 XPutBackEvent(ob_display, &e);
132 XUngrabServer(ob_display);
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) {
140 XUngrabServer(ob_display);
142 return; /* don't manage it */
145 /* /\* is the window a docking app *\/
146 if ((wmhint = XGetWMHints(ob_display, window))) {
147 if ((wmhint->flags & StateHint) &&
148 wmhint->initial_state == WithdrawnState) {
149 /\* XXX: make dock apps work! *\/
150 XUngrabServer(ob_display);
159 /* choose the events we want to receive on the CLIENT window */
160 attrib_set.event_mask = CLIENT_EVENTMASK;
161 attrib_set.do_not_propagate_mask = CLIENT_NOPROPAGATEMASK;
162 XChangeWindowAttributes(ob_display, window,
163 CWEventMask|CWDontPropagate, &attrib_set);
166 /* create the Client struct, and populate it from the hints on the
168 client = g_new(Client, 1);
169 client->window = window;
170 client_get_all(client);
172 /* remove the client's border (and adjust re gravity) */
173 client_toggle_border(client, FALSE);
175 /* specify that if we exit, the window should not be destroyed and should
176 be reparented back to root automatically */
177 XChangeSaveSet(ob_display, window, SetModeInsert);
179 /* create the decoration frame for the client window */
180 client->frame = engine_frame_new();
182 engine_frame_grab_client(client->frame, client);
184 client_apply_startup_state(client);
186 XUngrabServer(ob_display);
189 client_list = g_slist_append(client_list, client);
190 stacking_list = g_list_append(stacking_list, client);
191 g_hash_table_insert(client_map, (gpointer)window, client);
193 stacking_raise(client);
195 screen_update_struts();
197 /*HOOKFIRECLIENT(managed, client);XXX*/
199 client_showhide(client);
201 /* grab all mouse bindings */
202 /*pointer_grab_all(client, TRUE);XXX*/
204 /* update the list hints */
207 g_message("Managed window 0x%lx", window);
210 void client_unmanage_all()
212 while (client_list != NULL)
213 client_unmanage(client_list->data);
216 void client_unmanage(Client *client)
221 g_message("Unmanaging window: %lx", client->window);
223 /*HOOKFIRECLIENT(closed, client);XXX*/
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 /* once the client is out of the list, update the struts to remove it's
248 screen_update_struts();
250 /* tell our parent that we're gone */
251 if (client->transient_for != NULL)
252 client->transient_for->transients =
253 g_slist_remove(client->transient_for->transients, client);
255 /* tell our transients that we're gone */
256 for (it = client->transients; it != NULL; it = it->next) {
257 ((Client*)it->data)->transient_for = NULL;
258 client_calc_layer(it->data);
261 /* unfocus the client (calls the focus callbacks) (we're out of the
262 transient lists already, so being modal doesn't matter) */
264 client_unfocus(client);
266 if (ob_state != State_Exiting) {
267 /* these values should not be persisted across a window
269 prop_erase(client->window, prop_atoms.net_wm_desktop);
270 prop_erase(client->window, prop_atoms.net_wm_state);
272 /* if we're left in an iconic state, the client wont be mapped. this is
273 bad, since we will no longer be managing the window on restart */
275 XMapWindow(ob_display, client->window);
278 /* free all data allocated in the client struct */
279 g_slist_free(client->transients);
280 for (j = 0; j < client->nicons; ++j)
281 g_free(client->icons[j].data);
282 if (client->nicons > 0)
283 g_free(client->icons);
284 g_free(client->title);
285 g_free(client->icon_title);
286 g_free(client->res_name);
287 g_free(client->res_class);
288 g_free(client->role);
291 /* update the list hints */
295 static void client_toggle_border(Client *self, gboolean show)
297 /* adjust our idea of where the client is, based on its border. When the
298 border is removed, the client should now be considered to be in a
300 when re-adding the border to the client, the same operation needs to be
302 int oldx = self->area.x, oldy = self->area.y;
303 int x = oldx, y = oldy;
304 switch(self->gravity) {
306 case NorthWestGravity:
308 case SouthWestGravity:
310 case NorthEastGravity:
312 case SouthEastGravity:
313 if (show) x -= self->border_width * 2;
314 else x += self->border_width * 2;
321 if (show) x -= self->border_width;
322 else x += self->border_width;
325 switch(self->gravity) {
327 case NorthWestGravity:
329 case NorthEastGravity:
331 case SouthWestGravity:
333 case SouthEastGravity:
334 if (show) y -= self->border_width * 2;
335 else y += self->border_width * 2;
342 if (show) y -= self->border_width;
343 else y += self->border_width;
350 XSetWindowBorderWidth(ob_display, self->window, self->border_width);
352 /* move the client so it is back it the right spot _with_ its
354 if (x != oldx || y != oldy)
355 XMoveWindow(ob_display, self->window, x, y);
357 XSetWindowBorderWidth(ob_display, self->window, 0);
361 static void client_get_all(Client *self)
363 /* update EVERYTHING!! */
365 self->ignore_unmaps = 0;
369 self->title = self->icon_title = NULL;
370 self->res_name = self->res_class = self->role = NULL;
371 self->wmstate = NormalState;
372 self->focused = FALSE;
373 self->transient = FALSE;
374 self->transients = NULL;
375 self->transient_for = NULL;
377 self->urgent = FALSE;
378 self->positioned = FALSE;
379 self->disabled_decorations = 0;
383 client_get_area(self);
384 client_get_desktop(self);
385 client_get_state(self);
386 client_get_shaped(self);
388 client_update_transient_for(self);
389 client_get_mwm_hints(self);
390 client_get_type(self);/* this can change the mwmhints for special cases */
392 client_update_protocols(self);
394 client_get_gravity(self); /* get the attribute gravity */
395 client_update_normal_hints(self); /* this may override the attribute
398 /* got the type, the mwmhints, the protocols, and the normal hints
399 (min/max sizes), so we're ready to set up the decorations/functions */
400 client_setup_decor_and_functions(self);
402 client_update_wmhints(self);
403 client_update_title(self);
404 client_update_icon_title(self);
405 client_update_class(self);
406 client_update_strut(self);
407 client_update_icons(self);
408 client_update_kwm_icon(self);
410 /* this makes sure that these windows appear on all desktops */
411 if (self->type == Type_Desktop)
412 self->desktop = DESKTOP_ALL;
414 /* set the desktop hint, to make sure that it always exists, and to
415 reflect any changes we've made here */
416 PROP_SET32(self->window, net_wm_desktop, cardinal, self->desktop);
418 client_change_state(self);
421 static void client_get_area(Client *self)
423 XWindowAttributes wattrib;
426 ret = XGetWindowAttributes(ob_display, self->window, &wattrib);
427 g_assert(ret != BadWindow);
429 RECT_SET(self->area, wattrib.x, wattrib.y, wattrib.width, wattrib.height);
430 self->border_width = wattrib.border_width;
433 static void client_get_desktop(Client *self)
437 if (PROP_GET32(self->window, net_wm_desktop, cardinal, d)) {
438 if (d >= screen_num_desktops && d != DESKTOP_ALL)
439 d = screen_num_desktops - 1;
442 /* defaults to the current desktop */
443 self->desktop = screen_desktop;
447 static void client_get_state(Client *self)
452 self->modal = self->shaded = self->max_horz = self->max_vert =
453 self->fullscreen = self->above = self->below = self->iconic =
454 self->skip_taskbar = self->skip_pager = FALSE;
456 if (PROP_GET32U(self->window, net_wm_state, atom, state, num)) {
458 for (i = 0; i < num; ++i) {
459 if (state[i] == prop_atoms.net_wm_state_modal)
461 else if (state[i] == prop_atoms.net_wm_state_shaded)
463 else if (state[i] == prop_atoms.net_wm_state_hidden)
465 else if (state[i] == prop_atoms.net_wm_state_skip_taskbar)
466 self->skip_taskbar = TRUE;
467 else if (state[i] == prop_atoms.net_wm_state_skip_pager)
468 self->skip_pager = TRUE;
469 else if (state[i] == prop_atoms.net_wm_state_fullscreen)
470 self->fullscreen = TRUE;
471 else if (state[i] == prop_atoms.net_wm_state_maximized_vert)
472 self->max_vert = TRUE;
473 else if (state[i] == prop_atoms.net_wm_state_maximized_horz)
474 self->max_horz = TRUE;
475 else if (state[i] == prop_atoms.net_wm_state_above)
477 else if (state[i] == prop_atoms.net_wm_state_below)
485 static void client_get_shaped(Client *self)
487 self->shaped = FALSE;
489 if (extensions_shape) {
494 XShapeSelectInput(ob_display, self->window, ShapeNotifyMask);
496 XShapeQueryExtents(ob_display, self->window, &s, &foo,
497 &foo, &ufoo, &ufoo, &foo, &foo, &foo, &ufoo,
499 self->shaped = (s != 0);
504 void client_update_transient_for(Client *self)
509 if (XGetTransientForHint(ob_display, self->window, &t) &&
510 t != self->window) { /* cant be transient to itself! */
511 self->transient = TRUE;
512 c = g_hash_table_lookup(client_map, (gpointer)t);
513 g_assert(c != self);/* if this happens then we need to check for it*/
515 if (!c /*XXX: && _group*/) {
516 /* not transient to a client, see if it is transient for a
518 if (/*t == _group->leader() || */
521 /* window is a transient for its group! */
522 /* XXX: for now this is treated as non-transient.
523 this needs to be fixed! */
527 self->transient = FALSE;
529 /* if anything has changed... */
530 if (c != self->transient_for) {
531 if (self->transient_for)
532 /* remove from old parent */
533 g_slist_remove(self->transient_for->transients, self);
534 self->transient_for = c;
535 if (self->transient_for)
536 /* add to new parent */
537 g_slist_append(self->transient_for->transients, self);
541 static void client_get_mwm_hints(Client *self)
544 unsigned long *hints;
546 self->mwmhints.flags = 0; /* default to none */
548 if (PROP_GET32U(self->window, motif_wm_hints, motif_wm_hints, hints, num)) {
549 if (num >= MWM_ELEMENTS) {
550 self->mwmhints.flags = hints[0];
551 self->mwmhints.functions = hints[1];
552 self->mwmhints.decorations = hints[2];
558 void client_get_type(Client *self)
564 if (PROP_GET32U(self->window, net_wm_window_type, atom, val, num)) {
565 /* use the first value that we know about in the array */
566 for (i = 0; i < num; ++i) {
567 if (val[i] == prop_atoms.net_wm_window_type_desktop)
568 self->type = Type_Desktop;
569 else if (val[i] == prop_atoms.net_wm_window_type_dock)
570 self->type = Type_Dock;
571 else if (val[i] == prop_atoms.net_wm_window_type_toolbar)
572 self->type = Type_Toolbar;
573 else if (val[i] == prop_atoms.net_wm_window_type_menu)
574 self->type = Type_Menu;
575 else if (val[i] == prop_atoms.net_wm_window_type_utility)
576 self->type = Type_Utility;
577 else if (val[i] == prop_atoms.net_wm_window_type_splash)
578 self->type = Type_Splash;
579 else if (val[i] == prop_atoms.net_wm_window_type_dialog)
580 self->type = Type_Dialog;
581 else if (val[i] == prop_atoms.net_wm_window_type_normal)
582 self->type = Type_Normal;
583 else if (val[i] == prop_atoms.kde_net_wm_window_type_override) {
584 /* prevent this window from getting any decor or
586 self->mwmhints.flags &= (MwmFlag_Functions |
587 MwmFlag_Decorations);
588 self->mwmhints.decorations = 0;
589 self->mwmhints.functions = 0;
591 if (self->type != (WindowType) -1)
592 break; /* grab the first legit type */
597 if (self->type == (WindowType) -1) {
598 /*the window type hint was not set, which means we either classify
599 ourself as a normal window or a dialog, depending on if we are a
602 self->type = Type_Dialog;
604 self->type = Type_Normal;
608 void client_update_protocols(Client *self)
611 gulong num_return, i;
613 self->focus_notify = FALSE;
614 self->delete_window = FALSE;
616 if (PROP_GET32U(self->window, wm_protocols, atom, proto, num_return)) {
617 for (i = 0; i < num_return; ++i) {
618 if (proto[i] == prop_atoms.wm_delete_window) {
619 /* this means we can request the window to close */
620 self->delete_window = TRUE;
621 } else if (proto[i] == prop_atoms.wm_take_focus)
622 /* if this protocol is requested, then the window will be
623 notified whenever we want it to receive focus */
624 self->focus_notify = TRUE;
630 static void client_get_gravity(Client *self)
632 XWindowAttributes wattrib;
635 ret = XGetWindowAttributes(ob_display, self->window, &wattrib);
636 g_assert(ret != BadWindow);
637 self->gravity = wattrib.win_gravity;
640 void client_update_normal_hints(Client *self)
644 int oldgravity = self->gravity;
647 self->min_ratio = 0.0f;
648 self->max_ratio = 0.0f;
649 SIZE_SET(self->size_inc, 1, 1);
650 SIZE_SET(self->base_size, 0, 0);
651 SIZE_SET(self->min_size, 0, 0);
652 SIZE_SET(self->max_size, G_MAXINT, G_MAXINT);
654 /* get the hints from the window */
655 if (XGetWMNormalHints(ob_display, self->window, &size, &ret)) {
656 self->positioned = (size.flags & (PPosition|USPosition));
658 if (size.flags & PWinGravity) {
659 self->gravity = size.win_gravity;
661 /* if the client has a frame, i.e. has already been mapped and
662 is changing its gravity */
663 if (self->frame && self->gravity != oldgravity) {
664 /* move our idea of the client's position based on its new
666 self->area.x = self->frame->area.x;
667 self->area.y = self->frame->area.y;
668 frame_frame_gravity(self->frame, &self->area.x, &self->area.y);
672 if (size.flags & PAspect) {
673 if (size.min_aspect.y)
674 self->min_ratio = (float)size.min_aspect.x / size.min_aspect.y;
675 if (size.max_aspect.y)
676 self->max_ratio = (float)size.max_aspect.x / size.max_aspect.y;
679 if (size.flags & PMinSize)
680 SIZE_SET(self->min_size, size.min_width, size.min_height);
682 if (size.flags & PMaxSize)
683 SIZE_SET(self->max_size, size.max_width, size.max_height);
685 if (size.flags & PBaseSize)
686 SIZE_SET(self->base_size, size.base_width, size.base_height);
688 if (size.flags & PResizeInc)
689 SIZE_SET(self->size_inc, size.width_inc, size.height_inc);
693 void client_setup_decor_and_functions(Client *self)
695 /* start with everything (cept fullscreen) */
696 self->decorations = Decor_Titlebar | Decor_Handle | Decor_Border |
697 Decor_Icon | Decor_AllDesktops | Decor_Iconify | Decor_Maximize;
698 self->functions = Func_Resize | Func_Move | Func_Iconify | Func_Maximize |
700 if (self->delete_window) {
701 self->decorations |= Decor_Close;
702 self->functions |= Func_Close;
705 if (!(self->min_size.width < self->max_size.width ||
706 self->min_size.height < self->max_size.height)) {
707 self->decorations &= ~(Decor_Maximize | Decor_Handle);
708 self->functions &= ~(Func_Resize | Func_Maximize);
711 switch (self->type) {
713 /* normal windows retain all of the possible decorations and
714 functionality, and are the only windows that you can fullscreen */
715 self->functions |= Func_Fullscreen;
719 /* dialogs cannot be maximized */
720 self->decorations &= ~Decor_Maximize;
721 self->functions &= ~Func_Maximize;
727 /* these windows get less functionality */
728 self->decorations &= ~(Decor_Iconify | Decor_Handle);
729 self->functions &= ~(Func_Iconify | Func_Resize);
735 /* none of these windows are manipulated by the window manager */
736 self->decorations = 0;
741 /* Mwm Hints are applied subtractively to what has already been chosen for
742 decor and functionality */
743 if (self->mwmhints.flags & MwmFlag_Decorations) {
744 if (! (self->mwmhints.decorations & MwmDecor_All)) {
745 if (! (self->mwmhints.decorations & MwmDecor_Border))
746 self->decorations &= ~Decor_Border;
747 if (! (self->mwmhints.decorations & MwmDecor_Handle))
748 self->decorations &= ~Decor_Handle;
749 if (! (self->mwmhints.decorations & MwmDecor_Title))
750 self->decorations &= ~Decor_Titlebar;
751 if (! (self->mwmhints.decorations & MwmDecor_Iconify))
752 self->decorations &= ~Decor_Iconify;
753 if (! (self->mwmhints.decorations & MwmDecor_Maximize))
754 self->decorations &= ~Decor_Maximize;
758 if (self->mwmhints.flags & MwmFlag_Functions) {
759 if (! (self->mwmhints.functions & MwmFunc_All)) {
760 if (! (self->mwmhints.functions & MwmFunc_Resize))
761 self->functions &= ~Func_Resize;
762 if (! (self->mwmhints.functions & MwmFunc_Move))
763 self->functions &= ~Func_Move;
764 if (! (self->mwmhints.functions & MwmFunc_Iconify))
765 self->functions &= ~Func_Iconify;
766 if (! (self->mwmhints.functions & MwmFunc_Maximize))
767 self->functions &= ~Func_Maximize;
768 /* dont let mwm hints kill the close button
769 if (! (self->mwmhints.functions & MwmFunc_Close))
770 self->functions &= ~Func_Close; */
774 /* can't maximize without moving/resizing */
775 if (!((self->functions & Func_Move) && (self->functions & Func_Resize)))
776 self->functions &= ~Func_Maximize;
778 /* finally, user specified disabled decorations are applied to subtract
780 if (self->disabled_decorations & Decor_Titlebar)
781 self->decorations &= ~Decor_Titlebar;
782 if (self->disabled_decorations & Decor_Handle)
783 self->decorations &= ~Decor_Handle;
784 if (self->disabled_decorations & Decor_Border)
785 self->decorations &= ~Decor_Border;
786 if (self->disabled_decorations & Decor_Iconify)
787 self->decorations &= ~Decor_Iconify;
788 if (self->disabled_decorations & Decor_Maximize)
789 self->decorations &= ~Decor_Maximize;
790 if (self->disabled_decorations & Decor_AllDesktops)
791 self->decorations &= ~Decor_AllDesktops;
792 if (self->disabled_decorations & Decor_Close)
793 self->decorations &= ~Decor_Close;
795 /* if we don't have a titlebar, then we cannot shade! */
796 if (!(self->decorations & Decor_Titlebar))
797 self->functions &= ~Func_Shade;
799 client_change_allowed_actions(self);
802 /* change the decors on the frame */
803 engine_frame_adjust_size(self->frame);
804 /* with more/less decorations, we may need to be repositioned */
805 engine_frame_adjust_position(self->frame);
806 /* with new decor, the window's maximized size may change */
807 client_remaximize(self);
811 static void client_change_allowed_actions(Client *self)
816 actions[num++] = prop_atoms.net_wm_action_change_desktop;
818 if (self->functions & Func_Shade)
819 actions[num++] = prop_atoms.net_wm_action_shade;
820 if (self->functions & Func_Close)
821 actions[num++] = prop_atoms.net_wm_action_close;
822 if (self->functions & Func_Move)
823 actions[num++] = prop_atoms.net_wm_action_move;
824 if (self->functions & Func_Iconify)
825 actions[num++] = prop_atoms.net_wm_action_minimize;
826 if (self->functions & Func_Resize)
827 actions[num++] = prop_atoms.net_wm_action_resize;
828 if (self->functions & Func_Fullscreen)
829 actions[num++] = prop_atoms.net_wm_action_fullscreen;
830 if (self->functions & Func_Maximize) {
831 actions[num++] = prop_atoms.net_wm_action_maximize_horz;
832 actions[num++] = prop_atoms.net_wm_action_maximize_vert;
835 PROP_SET32A(self->window, net_wm_allowed_actions, atom, actions, num);
837 /* make sure the window isn't breaking any rules now */
839 if (!(self->functions & Func_Shade) && self->shaded) {
840 if (self->frame) client_shade(self, FALSE);
841 else self->shaded = FALSE;
843 if (!(self->functions & Func_Iconify) && self->iconic) {
844 if (self->frame) client_iconify(self, FALSE, TRUE);
845 else self->iconic = FALSE;
847 if (!(self->functions & Func_Fullscreen) && self->fullscreen) {
848 if (self->frame) client_fullscreen(self, FALSE, TRUE);
849 else self->fullscreen = FALSE;
851 if (!(self->functions & Func_Maximize) && (self->max_horz ||
853 if (self->frame) client_maximize(self, FALSE, 0, TRUE);
854 else self->max_vert = self->max_horz = FALSE;
858 void client_remaximize(Client *self)
861 if (self->max_horz && self->max_vert)
863 else if (self->max_horz)
865 else if (self->max_vert)
868 return; /* not maximized */
869 self->max_horz = self->max_vert = FALSE;
870 client_maximize(self, TRUE, dir, FALSE);
873 void client_update_wmhints(Client *self)
878 /* assume a window takes input if it doesnt specify */
879 self->can_focus = TRUE;
881 if ((hints = XGetWMHints(ob_display, self->window)) != NULL) {
882 if (hints->flags & InputHint)
883 self->can_focus = hints->input;
885 /* only do this when starting! */
886 if (ob_state == State_Starting && (hints->flags & StateHint))
887 self->iconic = hints->initial_state == IconicState;
889 if (hints->flags & XUrgencyHint)
892 if (hints->flags & WindowGroupHint) {
893 if (hints->window_group != self->group) {
894 /* XXX: remove from the old group if there was one */
895 self->group = hints->window_group;
896 /* XXX: do stuff with the group */
898 } else /* no group! */
901 if (hints->flags & IconPixmapHint) {
902 client_update_kwm_icon(self);
903 /* try get the kwm icon first, this is a fallback only */
904 if (self->pixmap_icon == None) {
905 self->pixmap_icon = hints->icon_pixmap;
906 if (hints->flags & IconMaskHint)
907 self->pixmap_icon_mask = hints->icon_mask;
909 self->pixmap_icon_mask = None;
912 engine_frame_adjust_icon(self->frame);
919 if (ur != self->urgent) {
921 g_message("Urgent Hint for 0x%lx: %s\n", self->window,
923 /* fire the urgent callback if we're mapped, otherwise, wait until
924 after we're mapped */
926 /*HOOKFIRECLIENT(urgent, self)XXX*/;
930 void client_update_title(Client *self)
934 if (self->title != NULL)
938 if (!PROP_GETS(self->window, net_wm_name, utf8, data)) {
939 /* try old x stuff */
940 if (PROP_GETS(self->window, wm_name, string, data)) {
941 /* convert it to UTF-8 */
945 u = g_locale_to_utf8(data, -1, &r, &w, NULL);
947 g_warning("Unable to convert string to UTF-8");
954 data = g_strdup("Unnamed Window");
956 PROP_SETS(self->window, net_wm_visible_name, utf8, data);
962 engine_frame_adjust_title(self->frame);
965 void client_update_icon_title(Client *self)
969 if (self->icon_title != NULL)
970 g_free(self->icon_title);
973 if (!PROP_GETS(self->window, net_wm_icon_name, utf8, data)) {
974 /* try old x stuff */
975 if (PROP_GETS(self->window, wm_icon_name, string, data)) {
976 /* convert it to UTF-8 */
980 u = g_locale_to_utf8(data, -1, &r, &w, NULL);
982 g_warning("Unable to convert string to UTF-8");
989 data = g_strdup("Unnamed Window");
991 PROP_SETS(self->window, net_wm_visible_icon_name, utf8, data);
994 self->icon_title = data;
997 void client_update_class(Client *self)
1003 if (self->res_name) g_free(self->res_name);
1004 if (self->res_class) g_free(self->res_class);
1005 if (self->role) g_free(self->role);
1007 self->res_name = self->res_class = self->role = NULL;
1009 data = g_ptr_array_new();
1011 if (PROP_GETSA(self->window, wm_class, string, data)) {
1013 self->res_name = g_strdup(g_ptr_array_index(data, 0));
1015 self->res_class = g_strdup(g_ptr_array_index(data, 1));
1018 for (i = 0; i < data->len; ++i)
1019 g_free(g_ptr_array_index(data, i));
1020 g_ptr_array_free(data, TRUE);
1022 if (PROP_GETS(self->window, wm_window_role, string, s))
1023 self->role = g_strdup(s);
1025 if (self->res_name == NULL) self->res_name = g_strdup("");
1026 if (self->res_class == NULL) self->res_class = g_strdup("");
1027 if (self->role == NULL) self->role = g_strdup("");
1030 void client_update_strut(Client *self)
1034 if (PROP_GET32A(self->window, net_wm_strut, cardinal, data, 4)) {
1035 STRUT_SET(self->strut, data[0], data[1], data[2], data[3]);
1038 STRUT_SET(self->strut, 0, 0, 0, 0);
1040 /* updating here is pointless while we're being mapped cuz we're not in
1041 the client list yet */
1043 screen_update_struts();
1046 void client_update_icons(Client *self)
1049 unsigned long *data;
1050 unsigned long w, h, i;
1053 for (j = 0; j < self->nicons; ++j)
1054 g_free(self->icons[j].data);
1055 if (self->nicons > 0)
1056 g_free(self->icons);
1059 if (PROP_GET32U(self->window, net_wm_icon, cardinal, data, num)) {
1060 /* figure out how many valid icons are in here */
1062 while (num - i > 2) {
1070 self->icons = g_new(Icon, self->nicons);
1072 /* store the icons */
1074 for (j = 0; j < self->nicons; ++j) {
1075 w = self->icons[j].w = data[i++];
1076 h = self->icons[j].h = data[i++];
1077 self->icons[j].data =
1078 g_memdup(&data[i], w * h * sizeof(gulong));
1086 if (self->nicons <= 0) {
1088 self->icons = g_new0(Icon, 1);
1092 engine_frame_adjust_icon(self->frame);
1095 void client_update_kwm_icon(Client *self)
1099 if (PROP_GET32A(self->window, kwm_win_icon, kwm_win_icon, data, 2)) {
1100 self->pixmap_icon = data[0];
1101 self->pixmap_icon_mask = data[1];
1104 self->pixmap_icon = self->pixmap_icon_mask = None;
1107 engine_frame_adjust_icon(self->frame);
1110 static void client_change_state(Client *self)
1112 unsigned long state[2];
1116 state[0] = self->wmstate;
1118 PROP_SET32A(self->window, wm_state, wm_state, state, 2);
1122 netstate[num++] = prop_atoms.net_wm_state_modal;
1124 netstate[num++] = prop_atoms.net_wm_state_shaded;
1126 netstate[num++] = prop_atoms.net_wm_state_hidden;
1127 if (self->skip_taskbar)
1128 netstate[num++] = prop_atoms.net_wm_state_skip_taskbar;
1129 if (self->skip_pager)
1130 netstate[num++] = prop_atoms.net_wm_state_skip_pager;
1131 if (self->fullscreen)
1132 netstate[num++] = prop_atoms.net_wm_state_fullscreen;
1134 netstate[num++] = prop_atoms.net_wm_state_maximized_vert;
1136 netstate[num++] = prop_atoms.net_wm_state_maximized_horz;
1138 netstate[num++] = prop_atoms.net_wm_state_above;
1140 netstate[num++] = prop_atoms.net_wm_state_below;
1141 PROP_SET32A(self->window, net_wm_state, atom, netstate, num);
1143 client_calc_layer(self);
1146 engine_frame_adjust_state(self->frame);
1149 static Client *search_focus_tree(Client *node, Client *skip)
1154 for (it = node->transients; it != NULL; it = g_slist_next(it)) {
1155 Client *c = it->data;
1156 if (c == skip) continue; /* circular? */
1157 if ((ret = search_focus_tree(c, skip))) return ret;
1158 if (c->focused) return c;
1163 void client_calc_layer(Client *self)
1169 /* are we fullscreen, or do we have a fullscreen transient parent? */
1173 if (c->fullscreen) {
1177 c = c->transient_for;
1179 if (!fs && self->fullscreen) {
1180 /* is one of our transients focused? */
1181 c = search_focus_tree(self, self);
1182 if (c != NULL) fs = TRUE;
1185 if (self->iconic) l = Layer_Icon;
1186 else if (fs) l = Layer_Fullscreen;
1187 else if (self->type == Type_Desktop) l = Layer_Desktop;
1188 else if (self->type == Type_Dock) {
1189 if (!self->below) l = Layer_Top;
1190 else l = Layer_Normal;
1192 else if (self->above) l = Layer_Above;
1193 else if (self->below) l = Layer_Below;
1194 else l = Layer_Normal;
1196 if (l != self->layer) {
1199 stacking_raise(self);
1203 gboolean client_should_show(Client *self)
1205 if (self->iconic) return FALSE;
1206 else if (!(self->desktop == screen_desktop ||
1207 self->desktop == DESKTOP_ALL)) return FALSE;
1208 else if (client_normal(self) && screen_showing_desktop) return FALSE;
1213 static void client_showhide(Client *self)
1216 if (client_should_show(self))
1217 engine_frame_show(self->frame);
1219 engine_frame_hide(self->frame);
1221 /*HOOKFIRECLIENT(visible, self);XXX*/
1224 gboolean client_normal(Client *self) {
1225 return ! (self->type == Type_Desktop || self->type == Type_Dock ||
1226 self->type == Type_Splash);
1229 static void client_apply_startup_state(Client *self)
1231 /* these are in a carefully crafted order.. */
1234 self->iconic = FALSE;
1235 client_iconify(self, TRUE, FALSE);
1237 if (self->fullscreen) {
1238 self->fullscreen = FALSE;
1239 client_fullscreen(self, TRUE, FALSE);
1242 self->shaded = FALSE;
1243 client_shade(self, TRUE);
1246 /*HOOKFIRECLIENT(urgent, self)XXX*/;
1248 if (self->max_vert && self->max_horz) {
1249 self->max_vert = self->max_horz = FALSE;
1250 client_maximize(self, TRUE, 0, FALSE);
1251 } else if (self->max_vert) {
1252 self->max_vert = FALSE;
1253 client_maximize(self, TRUE, 2, FALSE);
1254 } else if (self->max_horz) {
1255 self->max_horz = FALSE;
1256 client_maximize(self, TRUE, 1, FALSE);
1259 /* nothing to do for the other states:
1268 void client_configure(Client *self, Corner anchor, int x, int y, int w, int h,
1269 gboolean user, gboolean final)
1271 gboolean moved = FALSE, resized = FALSE;
1273 w -= self->base_size.width;
1274 h -= self->base_size.height;
1277 /* for interactive resizing. have to move half an increment in each
1280 /* how far we are towards the next size inc */
1281 int mw = w % self->size_inc.width;
1282 int mh = h % self->size_inc.height;
1284 int aw = self->size_inc.width / 2;
1285 int ah = self->size_inc.height / 2;
1286 /* don't let us move into a new size increment */
1287 if (mw + aw >= self->size_inc.width)
1288 aw = self->size_inc.width - mw - 1;
1289 if (mh + ah >= self->size_inc.height)
1290 ah = self->size_inc.height - mh - 1;
1294 /* if this is a user-requested resize, then check against min/max
1295 sizes and aspect ratios */
1297 /* smaller than min size or bigger than max size? */
1298 if (w > self->max_size.width) w = self->max_size.width;
1299 if (w < self->min_size.width) w = self->min_size.width;
1300 if (h > self->max_size.height) h = self->max_size.height;
1301 if (h < self->min_size.height) h = self->min_size.height;
1303 /* adjust the height ot match the width for the aspect ratios */
1304 if (self->min_ratio)
1305 if (h * self->min_ratio > w) h = (int)(w / self->min_ratio);
1306 if (self->max_ratio)
1307 if (h * self->max_ratio < w) h = (int)(w / self->max_ratio);
1310 /* keep to the increments */
1311 w /= self->size_inc.width;
1312 h /= self->size_inc.height;
1314 /* you cannot resize to nothing */
1318 /* store the logical size */
1319 SIZE_SET(self->logical_size, w, h);
1321 w *= self->size_inc.width;
1322 h *= self->size_inc.height;
1324 w += self->base_size.width;
1325 h += self->base_size.height;
1328 case Corner_TopLeft:
1330 case Corner_TopRight:
1331 x -= w - self->area.width;
1333 case Corner_BottomLeft:
1334 y -= h - self->area.height;
1336 case Corner_BottomRight:
1337 x -= w - self->area.width;
1338 y -= h - self->area.height;
1342 moved = x != self->area.x || y != self->area.y;
1343 resized = w != self->area.width || h != self->area.height;
1345 RECT_SET(self->area, x, y, w, h);
1348 XResizeWindow(ob_display, self->window, w, h);
1350 /* move/resize the frame to match the request */
1352 /* Adjust the size and then the position, as required by the EWMH */
1354 engine_frame_adjust_size(self->frame);
1356 engine_frame_adjust_position(self->frame);
1358 if (!user || final) {
1360 event.type = ConfigureNotify;
1361 event.xconfigure.display = ob_display;
1362 event.xconfigure.event = self->window;
1363 event.xconfigure.window = self->window;
1365 /* root window coords with border in mind */
1366 event.xconfigure.x = x - self->border_width +
1367 self->frame->size.left;
1368 event.xconfigure.y = y - self->border_width +
1369 self->frame->size.top;
1371 event.xconfigure.width = self->area.width;
1372 event.xconfigure.height = self->area.height;
1373 event.xconfigure.border_width = self->border_width;
1374 event.xconfigure.above = self->frame->plate;
1375 event.xconfigure.override_redirect = FALSE;
1376 XSendEvent(event.xconfigure.display, event.xconfigure.window,
1377 FALSE, StructureNotifyMask, &event);
1383 void client_fullscreen(Client *self, gboolean fs, gboolean savearea)
1385 static int saved_func, saved_decor;
1388 if (!(self->functions & Func_Fullscreen) || /* can't */
1389 self->fullscreen == fs) return; /* already done */
1391 self->fullscreen = fs;
1392 client_change_state(self); /* change the state hints on the client */
1395 /* save the functions and remove them */
1396 saved_func = self->functions;
1397 self->functions &= (Func_Close | Func_Fullscreen |
1399 /* save the decorations and remove them */
1400 saved_decor = self->decorations;
1401 self->decorations = 0;
1404 dimensions[0] = self->area.x;
1405 dimensions[1] = self->area.y;
1406 dimensions[2] = self->area.width;
1407 dimensions[3] = self->area.height;
1409 PROP_SET32A(self->window, openbox_premax, cardinal,
1414 w = screen_physical_size.width;
1415 h = screen_physical_size.height;
1419 self->functions = saved_func;
1420 self->decorations = saved_decor;
1422 if (PROP_GET32A(self->window, openbox_premax, cardinal,
1430 /* pick some fallbacks... */
1431 x = screen_area(self->desktop)->x +
1432 screen_area(self->desktop)->width / 4;
1433 y = screen_area(self->desktop)->y +
1434 screen_area(self->desktop)->height / 4;
1435 w = screen_area(self->desktop)->width / 2;
1436 h = screen_area(self->desktop)->height / 2;
1440 client_change_allowed_actions(self); /* based on the new _functions */
1442 /* when fullscreening, don't obey things like increments, fill the
1444 client_configure(self, Corner_TopLeft, x, y, w, h, !fs, TRUE);
1446 /* raise (back) into our stacking layer */
1447 stacking_raise(self);
1449 /* try focus us when we go into fullscreen mode */
1453 void client_iconify(Client *self, gboolean iconic, gboolean curdesk)
1455 if (self->iconic == iconic) return; /* nothing to do */
1457 g_message("%sconifying window: 0x%lx\n", (iconic ? "I" : "Uni"),
1460 self->iconic = iconic;
1463 self->wmstate = IconicState;
1464 self->ignore_unmaps++;
1465 /* we unmap the client itself so that we can get MapRequest events,
1466 and because the ICCCM tells us to! */
1467 XUnmapWindow(ob_display, self->window);
1470 client_set_desktop(self, screen_desktop);
1471 self->wmstate = self->shaded ? IconicState : NormalState;
1472 XMapWindow(ob_display, self->window);
1474 client_change_state(self);
1475 client_showhide(self);
1476 screen_update_struts();
1479 void client_maximize(Client *self, gboolean max, int dir, gboolean savearea)
1483 g_assert(dir == 0 || dir == 1 || dir == 2);
1484 if (!(self->functions & Func_Maximize)) return; /* can't */
1486 /* check if already done */
1488 if (dir == 0 && self->max_horz && self->max_vert) return;
1489 if (dir == 1 && self->max_horz) return;
1490 if (dir == 2 && self->max_vert) return;
1492 if (dir == 0 && !self->max_horz && !self->max_vert) return;
1493 if (dir == 1 && !self->max_horz) return;
1494 if (dir == 2 && !self->max_vert) return;
1497 /* work with the frame's coords */
1498 x = self->frame->area.x;
1499 y = self->frame->area.y;
1500 w = self->area.width;
1501 h = self->area.height;
1513 /* get the property off the window and use it for the dimensions
1514 we are already maxed on */
1515 if (PROP_GET32A(self->window, openbox_premax, cardinal,
1517 if (self->max_horz) {
1518 dimensions[0] = readdim[0];
1519 dimensions[2] = readdim[2];
1521 if (self->max_vert) {
1522 dimensions[1] = readdim[1];
1523 dimensions[3] = readdim[3];
1528 PROP_SET32A(self->window, openbox_premax, cardinal,
1531 if (dir == 0 || dir == 1) { /* horz */
1532 x = screen_area(self->desktop)->x - self->frame->size.left;
1533 w = screen_area(self->desktop)->x +
1534 screen_area(self->desktop)->width;
1536 if (dir == 0 || dir == 2) { /* vert */
1537 y = screen_area(self->desktop)->y;
1538 h = screen_area(self->desktop)->y +
1539 screen_area(self->desktop)->height -
1540 self->frame->size.top - self->frame->size.bottom;
1545 if (PROP_GET32A(self->window, openbox_premax, cardinal,
1547 if (dir == 0 || dir == 1) { /* horz */
1551 if (dir == 0 || dir == 2) { /* vert */
1557 /* pick some fallbacks... */
1558 if (dir == 0 || dir == 1) { /* horz */
1559 x = screen_area(self->desktop)->x +
1560 screen_area(self->desktop)->width / 4;
1561 w = screen_area(self->desktop)->width / 2;
1563 if (dir == 0 || dir == 2) { /* vert */
1564 y = screen_area(self->desktop)->y +
1565 screen_area(self->desktop)->height / 4;
1566 h = screen_area(self->desktop)->height / 2;
1571 if (dir == 0 || dir == 1) /* horz */
1572 self->max_horz = max;
1573 if (dir == 0 || dir == 2) /* vert */
1574 self->max_vert = max;
1576 if (!self->max_horz && !self->max_vert)
1577 PROP_ERASE(self->window, openbox_premax);
1579 client_change_state(self); /* change the state hints on the client */
1581 /* figure out where the client should be going */
1582 frame_frame_gravity(self->frame, &x, &y);
1583 client_configure(self, Corner_TopLeft, x, y, w, h, TRUE, TRUE);
1586 void client_shade(Client *self, gboolean shade)
1588 if (!(self->functions & Func_Shade) || /* can't */
1589 self->shaded == shade) return; /* already done */
1591 /* when we're iconic, don't change the wmstate */
1593 self->wmstate = shade ? IconicState : NormalState;
1594 self->shaded = shade;
1595 client_change_state(self);
1596 engine_frame_adjust_size(self->frame);
1599 void client_close(Client *self)
1603 if (!(self->functions & Func_Close)) return;
1606 XXX: itd be cool to do timeouts and shit here for killing the client's
1608 like... if the window is around after 5 seconds, then the close button
1609 turns a nice red, and if this function is called again, the client is
1613 ce.xclient.type = ClientMessage;
1614 ce.xclient.message_type = prop_atoms.wm_protocols;
1615 ce.xclient.display = ob_display;
1616 ce.xclient.window = self->window;
1617 ce.xclient.format = 32;
1618 ce.xclient.data.l[0] = prop_atoms.wm_delete_window;
1619 ce.xclient.data.l[1] = CurrentTime;
1620 ce.xclient.data.l[2] = 0l;
1621 ce.xclient.data.l[3] = 0l;
1622 ce.xclient.data.l[4] = 0l;
1623 XSendEvent(ob_display, self->window, FALSE, NoEventMask, &ce);
1626 void client_set_desktop(Client *self, unsigned int target)
1628 if (target == self->desktop) return;
1630 g_message("Setting desktop %u\n", target);
1632 if (!(target < screen_num_desktops ||
1633 target == DESKTOP_ALL))
1636 self->desktop = target;
1637 PROP_SET32(self->window, net_wm_desktop, cardinal, target);
1638 /* the frame can display the current desktop state */
1639 engine_frame_adjust_state(self->frame);
1640 /* 'move' the window to the new desktop */
1641 client_showhide(self);
1642 screen_update_struts();
1645 static Client *search_modal_tree(Client *node, Client *skip)
1650 for (it = node->transients; it != NULL; it = it->next) {
1651 Client *c = it->data;
1652 if (c == skip) continue; /* circular? */
1653 if ((ret = search_modal_tree(c, skip))) return ret;
1654 if (c->modal) return c;
1659 Client *client_find_modal_child(Client *self)
1661 return search_modal_tree(self, self);
1664 gboolean client_validate(Client *self)
1668 XSync(ob_display, FALSE); /* get all events on the server */
1670 if (XCheckTypedWindowEvent(ob_display, self->window, DestroyNotify, &e) ||
1671 XCheckTypedWindowEvent(ob_display, self->window, UnmapNotify, &e)) {
1672 XPutBackEvent(ob_display, &e);
1679 void client_set_wm_state(Client *self, long state)
1681 if (state == self->wmstate) return; /* no change */
1685 client_iconify(self, TRUE, TRUE);
1688 client_iconify(self, FALSE, TRUE);
1693 void client_set_state(Client *self, Atom action, long data1, long data2)
1695 gboolean shaded = self->shaded;
1696 gboolean fullscreen = self->fullscreen;
1697 gboolean max_horz = self->max_horz;
1698 gboolean max_vert = self->max_vert;
1701 if (!(action == prop_atoms.net_wm_state_add ||
1702 action == prop_atoms.net_wm_state_remove ||
1703 action == prop_atoms.net_wm_state_toggle))
1704 /* an invalid action was passed to the client message, ignore it */
1707 for (i = 0; i < 2; ++i) {
1708 Atom state = i == 0 ? data1 : data2;
1710 if (!state) continue;
1712 /* if toggling, then pick whether we're adding or removing */
1713 if (action == prop_atoms.net_wm_state_toggle) {
1714 if (state == prop_atoms.net_wm_state_modal)
1715 action = self->modal ? prop_atoms.net_wm_state_remove :
1716 prop_atoms.net_wm_state_add;
1717 else if (state == prop_atoms.net_wm_state_maximized_vert)
1718 action = self->max_vert ? prop_atoms.net_wm_state_remove :
1719 prop_atoms.net_wm_state_add;
1720 else if (state == prop_atoms.net_wm_state_maximized_horz)
1721 action = self->max_horz ? prop_atoms.net_wm_state_remove :
1722 prop_atoms.net_wm_state_add;
1723 else if (state == prop_atoms.net_wm_state_shaded)
1724 action = self->shaded ? prop_atoms.net_wm_state_remove :
1725 prop_atoms.net_wm_state_add;
1726 else if (state == prop_atoms.net_wm_state_skip_taskbar)
1727 action = self->skip_taskbar ?
1728 prop_atoms.net_wm_state_remove :
1729 prop_atoms.net_wm_state_add;
1730 else if (state == prop_atoms.net_wm_state_skip_pager)
1731 action = self->skip_pager ?
1732 prop_atoms.net_wm_state_remove :
1733 prop_atoms.net_wm_state_add;
1734 else if (state == prop_atoms.net_wm_state_fullscreen)
1735 action = self->fullscreen ?
1736 prop_atoms.net_wm_state_remove :
1737 prop_atoms.net_wm_state_add;
1738 else if (state == prop_atoms.net_wm_state_above)
1739 action = self->above ? prop_atoms.net_wm_state_remove :
1740 prop_atoms.net_wm_state_add;
1741 else if (state == prop_atoms.net_wm_state_below)
1742 action = self->below ? prop_atoms.net_wm_state_remove :
1743 prop_atoms.net_wm_state_add;
1746 if (action == prop_atoms.net_wm_state_add) {
1747 if (state == prop_atoms.net_wm_state_modal) {
1748 /* XXX raise here or something? */
1750 } else if (state == prop_atoms.net_wm_state_maximized_vert) {
1752 } else if (state == prop_atoms.net_wm_state_maximized_horz) {
1754 } else if (state == prop_atoms.net_wm_state_shaded) {
1756 } else if (state == prop_atoms.net_wm_state_skip_taskbar) {
1757 self->skip_taskbar = TRUE;
1758 } else if (state == prop_atoms.net_wm_state_skip_pager) {
1759 self->skip_pager = TRUE;
1760 } else if (state == prop_atoms.net_wm_state_fullscreen) {
1762 } else if (state == prop_atoms.net_wm_state_above) {
1764 } else if (state == prop_atoms.net_wm_state_below) {
1768 } else { /* action == prop_atoms.net_wm_state_remove */
1769 if (state == prop_atoms.net_wm_state_modal) {
1770 self->modal = FALSE;
1771 } else if (state == prop_atoms.net_wm_state_maximized_vert) {
1773 } else if (state == prop_atoms.net_wm_state_maximized_horz) {
1775 } else if (state == prop_atoms.net_wm_state_shaded) {
1777 } else if (state == prop_atoms.net_wm_state_skip_taskbar) {
1778 self->skip_taskbar = FALSE;
1779 } else if (state == prop_atoms.net_wm_state_skip_pager) {
1780 self->skip_pager = FALSE;
1781 } else if (state == prop_atoms.net_wm_state_fullscreen) {
1783 } else if (state == prop_atoms.net_wm_state_above) {
1784 self->above = FALSE;
1785 } else if (state == prop_atoms.net_wm_state_below) {
1786 self->below = FALSE;
1790 if (max_horz != self->max_horz || max_vert != self->max_vert) {
1791 if (max_horz != self->max_horz && max_vert != self->max_vert) {
1793 if (max_horz == max_vert) { /* both going the same way */
1794 client_maximize(self, max_horz, 0, TRUE);
1796 client_maximize(self, max_horz, 1, TRUE);
1797 client_maximize(self, max_vert, 2, TRUE);
1801 if (max_horz != self->max_horz)
1802 client_maximize(self, max_horz, 1, TRUE);
1804 client_maximize(self, max_vert, 2, TRUE);
1807 /* change fullscreen state before shading, as it will affect if the window
1809 if (fullscreen != self->fullscreen)
1810 client_fullscreen(self, fullscreen, TRUE);
1811 if (shaded != self->shaded)
1812 client_shade(self, shaded);
1813 client_calc_layer(self);
1814 client_change_state(self); /* change the hint to relect these changes */
1817 gboolean client_focus(Client *self)
1822 /* if we have a modal child, then focus it, not us */
1823 child = client_find_modal_child(self);
1825 return client_focus(child);
1827 /* won't try focus if the client doesn't want it, or if the window isn't
1828 visible on the screen */
1829 if (!(self->frame->visible &&
1830 (self->can_focus || self->focus_notify)))
1833 /* do a check to see if the window has already been unmapped or destroyed
1834 do this intelligently while watching out for unmaps we've generated
1835 (ignore_unmaps > 0) */
1836 if (XCheckTypedWindowEvent(ob_display, self->window,
1837 DestroyNotify, &ev)) {
1838 XPutBackEvent(ob_display, &ev);
1841 while (XCheckTypedWindowEvent(ob_display, self->window,
1842 UnmapNotify, &ev)) {
1843 if (self->ignore_unmaps) {
1844 self->ignore_unmaps--;
1846 XPutBackEvent(ob_display, &ev);
1851 if (self->can_focus)
1852 XSetInputFocus(ob_display, self->window, RevertToNone, CurrentTime);
1854 if (self->focus_notify) {
1856 ce.xclient.type = ClientMessage;
1857 ce.xclient.message_type = prop_atoms.wm_protocols;
1858 ce.xclient.display = ob_display;
1859 ce.xclient.window = self->window;
1860 ce.xclient.format = 32;
1861 ce.xclient.data.l[0] = prop_atoms.wm_take_focus;
1862 ce.xclient.data.l[1] = event_lasttime;
1863 ce.xclient.data.l[2] = 0l;
1864 ce.xclient.data.l[3] = 0l;
1865 ce.xclient.data.l[4] = 0l;
1866 XSendEvent(ob_display, self->window, FALSE, NoEventMask, &ce);
1869 /*XSync(ob_display, FALSE); XXX Why sync? */
1873 void client_unfocus(Client *self)
1875 g_assert(focus_client == self);
1876 focus_set_client(NULL);