4 #include "extensions.h"
12 #include "openboxwrap.h"
13 #include "clientwrap.h"
15 #include <X11/Xutil.h>
17 /*! The event mask to grab on client windows */
18 #define CLIENT_EVENTMASK (PropertyChangeMask | FocusChangeMask | \
21 #define CLIENT_NOPROPAGATEMASK (ButtonPressMask | ButtonReleaseMask | \
24 GSList *client_list = NULL;
25 GHashTable *client_map = NULL;
27 static void client_get_all(Client *self);
28 static void client_toggle_border(Client *self, gboolean show);
29 static void client_get_area(Client *self);
30 static void client_get_desktop(Client *self);
31 static void client_get_state(Client *self);
32 static void client_get_shaped(Client *self);
33 static void client_get_mwm_hints(Client *self);
34 static void client_get_gravity(Client *self);
35 static void client_change_allowed_actions(Client *self);
36 static void client_change_state(Client *self);
37 static Client *search_focus_tree(Client *node, Client *skip);
38 static void client_apply_startup_state(Client *self);
39 static Client *search_modal_tree(Client *node, Client *skip);
41 static guint map_hash(Window w) { return w; }
42 static gboolean map_key_comp(Window w1, Window w2) { return w1 == w2; }
46 client_map = g_hash_table_new((GHashFunc)map_hash,
47 (GEqualFunc)map_key_comp);
51 void client_shutdown()
53 g_hash_table_destroy(client_map);
56 void client_set_list()
58 Window *windows, *win_it;
60 guint size = g_slist_length(client_list);
62 /* create an array of the window ids */
64 windows = g_new(Window, size);
66 for (it = client_list; it != NULL; it = it->next, ++win_it)
67 *win_it = ((Client*)it->data)->window;
71 PROP_SET32A(ob_root, net_client_list, window, windows, size);
79 void client_manage_all()
81 unsigned int i, j, nchild;
84 XWindowAttributes attrib;
86 XQueryTree(ob_display, ob_root, &w, &w, &children, &nchild);
88 /* remove all icon windows from the list */
89 for (i = 0; i < nchild; i++) {
90 if (children[i] == None) continue;
91 wmhints = XGetWMHints(ob_display, children[i]);
93 if ((wmhints->flags & IconWindowHint) &&
94 (wmhints->icon_window != children[i]))
95 for (j = 0; j < nchild; j++)
96 if (children[j] == wmhints->icon_window) {
104 for (i = 0; i < nchild; ++i) {
105 if (children[i] == None)
107 if (XGetWindowAttributes(ob_display, children[i], &attrib)) {
108 if (attrib.override_redirect) continue;
110 if (attrib.map_state != IsUnmapped)
111 client_manage(children[i]);
117 void client_manage(Window window)
121 XWindowAttributes attrib;
122 XSetWindowAttributes attrib_set;
123 /* XWMHints *wmhint; */
126 XGrabServer(ob_display);
127 XSync(ob_display, FALSE);
129 /* check if it has already been unmapped by the time we started mapping
130 the grab does a sync so we don't have to here */
131 if (XCheckTypedWindowEvent(ob_display, window, DestroyNotify, &e) ||
132 XCheckTypedWindowEvent(ob_display, window, UnmapNotify, &e)) {
133 XPutBackEvent(ob_display, &e);
135 XUngrabServer(ob_display);
137 return; /* don't manage it */
140 /* make sure it isn't an override-redirect window */
141 if (!XGetWindowAttributes(ob_display, window, &attrib) ||
142 attrib.override_redirect) {
143 XUngrabServer(ob_display);
145 return; /* don't manage it */
148 /* /\* is the window a docking app *\/
149 if ((wmhint = XGetWMHints(ob_display, window))) {
150 if ((wmhint->flags & StateHint) &&
151 wmhint->initial_state == WithdrawnState) {
152 /\* XXX: make dock apps work! *\/
153 XUngrabServer(ob_display);
162 /* choose the events we want to receive on the CLIENT window */
163 attrib_set.event_mask = CLIENT_EVENTMASK;
164 attrib_set.do_not_propagate_mask = CLIENT_NOPROPAGATEMASK;
165 XChangeWindowAttributes(ob_display, window,
166 CWEventMask|CWDontPropagate, &attrib_set);
169 /* create the Client struct, and populate it from the hints on the
171 client = g_new(Client, 1);
172 client->window = window;
173 client_get_all(client);
175 /* remove the client's border (and adjust re gravity) */
176 client_toggle_border(client, FALSE);
178 /* specify that if we exit, the window should not be destroyed and should
179 be reparented back to root automatically */
180 XChangeSaveSet(ob_display, window, SetModeInsert);
182 /* create the decoration frame for the client window */
183 client->frame = engine_frame_new();
185 engine_frame_grab_client(client->frame, client);
187 client_apply_startup_state(client);
189 XUngrabServer(ob_display);
192 client_list = g_slist_append(client_list, client);
193 stacking_list = g_list_append(stacking_list, client);
194 g_hash_table_insert(client_map, (gpointer)window, client);
196 stacking_raise(client);
198 screen_update_struts();
200 /* add to the python list */
201 cw = clientwrap_new(client);
202 PyList_Append(openboxwrap_obj->client_list, cw);
205 HOOKFIRECLIENT(managed, client);
207 client_showhide(client);
209 /* grab all mouse bindings */
210 pointer_grab_all(client, TRUE);
212 /* update the list hints */
215 g_message("Managed window 0x%lx", window);
218 void client_unmanage_all()
220 while (client_list != NULL)
221 client_unmanage(client_list->data);
224 void client_unmanage(Client *client)
230 g_message("Unmanaging window: %lx", client->window);
232 HOOKFIRECLIENT(closed, client);
234 /* remove the window from our save set */
235 XChangeSaveSet(ob_display, client->window, SetModeDelete);
237 /* we dont want events no more */
238 XSelectInput(ob_display, client->window, NoEventMask);
240 /* ungrab any mouse bindings */
241 pointer_grab_all(client, FALSE);
243 engine_frame_hide(client->frame);
245 /* give the client its border back */
246 client_toggle_border(client, TRUE);
248 /* reparent the window out of the frame, and free the frame */
249 engine_frame_release_client(client->frame, client);
251 client_list = g_slist_remove(client_list, client);
252 stacking_list = g_list_remove(stacking_list, client);
253 g_hash_table_remove(client_map, (gpointer)client->window);
255 /* once the client is out of the list, update the struts to remove it's
257 screen_update_struts();
259 /* remove from the python list */
260 cw = clientwrap_new(client);
261 seq = PySequence_Index(openboxwrap_obj->client_list, cw);
265 PySequence_DelItem(openboxwrap_obj->client_list, seq);
268 /* notify the wrapper that its useless now */
269 if (client->wrap != NULL)
270 client->wrap->client = NULL;
272 /* tell our parent that we're gone */
273 if (client->transient_for != NULL)
274 client->transient_for->transients =
275 g_slist_remove(client->transient_for->transients, client);
277 /* tell our transients that we're gone */
278 for (it = client->transients; it != NULL; it = it->next) {
279 ((Client*)it->data)->transient_for = NULL;
280 client_calc_layer(it->data);
283 /* unfocus the client (calls the focus callbacks) (we're out of the
284 transient lists already, so being modal doesn't matter) */
286 client_unfocus(client);
288 if (ob_state != State_Exiting) {
289 /* these values should not be persisted across a window
291 prop_erase(client->window, prop_atoms.net_wm_desktop);
292 prop_erase(client->window, prop_atoms.net_wm_state);
294 /* if we're left in an iconic state, the client wont be mapped. this is
295 bad, since we will no longer be managing the window on restart */
297 XMapWindow(ob_display, client->window);
300 /* free all data allocated in the client struct */
301 g_slist_free(client->transients);
302 for (j = 0; j < client->nicons; ++j)
303 g_free(client->icons[j].data);
304 if (client->nicons > 0)
305 g_free(client->icons);
306 g_free(client->title);
307 g_free(client->icon_title);
308 g_free(client->res_name);
309 g_free(client->res_class);
310 g_free(client->role);
313 /* update the list hints */
317 static void client_toggle_border(Client *self, gboolean show)
319 /* adjust our idea of where the client is, based on its border. When the
320 border is removed, the client should now be considered to be in a
322 when re-adding the border to the client, the same operation needs to be
324 int oldx = self->area.x, oldy = self->area.y;
325 int x = oldx, y = oldy;
326 switch(self->gravity) {
328 case NorthWestGravity:
330 case SouthWestGravity:
332 case NorthEastGravity:
334 case SouthEastGravity:
335 if (show) x -= self->border_width * 2;
336 else x += self->border_width * 2;
343 if (show) x -= self->border_width;
344 else x += self->border_width;
347 switch(self->gravity) {
349 case NorthWestGravity:
351 case NorthEastGravity:
353 case SouthWestGravity:
355 case SouthEastGravity:
356 if (show) y -= self->border_width * 2;
357 else y += self->border_width * 2;
364 if (show) y -= self->border_width;
365 else y += self->border_width;
372 XSetWindowBorderWidth(ob_display, self->window, self->border_width);
374 /* move the client so it is back it the right spot _with_ its
376 if (x != oldx || y != oldy)
377 XMoveWindow(ob_display, self->window, x, y);
379 XSetWindowBorderWidth(ob_display, self->window, 0);
383 static void client_get_all(Client *self)
385 /* update EVERYTHING!! */
387 self->ignore_unmaps = 0;
391 self->title = self->icon_title = NULL;
392 self->res_name = self->res_class = self->role = NULL;
393 self->wmstate = NormalState;
394 self->focused = FALSE;
395 self->transient = FALSE;
396 self->transients = NULL;
397 self->transient_for = NULL;
399 self->urgent = FALSE;
400 self->positioned = FALSE;
401 self->disabled_decorations = 0;
406 client_get_area(self);
407 client_get_desktop(self);
408 client_get_state(self);
409 client_get_shaped(self);
411 client_update_transient_for(self);
412 client_get_mwm_hints(self);
413 client_get_type(self);/* this can change the mwmhints for special cases */
415 client_update_protocols(self);
417 client_get_gravity(self); /* get the attribute gravity */
418 client_update_normal_hints(self); /* this may override the attribute
421 /* got the type, the mwmhints, the protocols, and the normal hints
422 (min/max sizes), so we're ready to set up the decorations/functions */
423 client_setup_decor_and_functions(self);
425 client_update_wmhints(self);
426 client_update_title(self);
427 client_update_icon_title(self);
428 client_update_class(self);
429 client_update_strut(self);
430 client_update_icons(self);
431 client_update_kwm_icon(self);
433 /* this makes sure that these windows appear on all desktops */
434 if (self->type == Type_Desktop)
435 self->desktop = DESKTOP_ALL;
437 /* set the desktop hint, to make sure that it always exists, and to
438 reflect any changes we've made here */
439 PROP_SET32(self->window, net_wm_desktop, cardinal, self->desktop);
441 client_change_state(self);
444 static void client_get_area(Client *self)
446 XWindowAttributes wattrib;
449 ret = XGetWindowAttributes(ob_display, self->window, &wattrib);
450 g_assert(ret != BadWindow);
452 RECT_SET(self->area, wattrib.x, wattrib.y, wattrib.width, wattrib.height);
453 self->border_width = wattrib.border_width;
456 static void client_get_desktop(Client *self)
460 if (PROP_GET32(self->window, net_wm_desktop, cardinal, d)) {
461 if (d >= screen_num_desktops && d != DESKTOP_ALL)
462 d = screen_num_desktops - 1;
465 /* defaults to the current desktop */
466 self->desktop = screen_desktop;
470 static void client_get_state(Client *self)
475 self->modal = self->shaded = self->max_horz = self->max_vert =
476 self->fullscreen = self->above = self->below = self->iconic =
477 self->skip_taskbar = self->skip_pager = FALSE;
479 if (PROP_GET32U(self->window, net_wm_state, atom, state, num)) {
481 for (i = 0; i < num; ++i) {
482 if (state[i] == prop_atoms.net_wm_state_modal)
484 else if (state[i] == prop_atoms.net_wm_state_shaded)
486 else if (state[i] == prop_atoms.net_wm_state_hidden)
488 else if (state[i] == prop_atoms.net_wm_state_skip_taskbar)
489 self->skip_taskbar = TRUE;
490 else if (state[i] == prop_atoms.net_wm_state_skip_pager)
491 self->skip_pager = TRUE;
492 else if (state[i] == prop_atoms.net_wm_state_fullscreen)
493 self->fullscreen = TRUE;
494 else if (state[i] == prop_atoms.net_wm_state_maximized_vert)
495 self->max_vert = TRUE;
496 else if (state[i] == prop_atoms.net_wm_state_maximized_horz)
497 self->max_horz = TRUE;
498 else if (state[i] == prop_atoms.net_wm_state_above)
500 else if (state[i] == prop_atoms.net_wm_state_below)
508 static void client_get_shaped(Client *self)
510 self->shaped = FALSE;
512 if (extensions_shape) {
517 XShapeSelectInput(ob_display, self->window, ShapeNotifyMask);
519 XShapeQueryExtents(ob_display, self->window, &s, &foo,
520 &foo, &ufoo, &ufoo, &foo, &foo, &foo, &ufoo,
522 self->shaped = (s != 0);
527 void client_update_transient_for(Client *self)
532 if (XGetTransientForHint(ob_display, self->window, &t) &&
533 t != self->window) { /* cant be transient to itself! */
534 self->transient = TRUE;
535 c = g_hash_table_lookup(client_map, (gpointer)t);
536 g_assert(c != self);/* if this happens then we need to check for it*/
538 if (!c /*XXX: && _group*/) {
539 /* not transient to a client, see if it is transient for a
541 if (/*t == _group->leader() || */
544 /* window is a transient for its group! */
545 /* XXX: for now this is treated as non-transient.
546 this needs to be fixed! */
550 self->transient = FALSE;
552 /* if anything has changed... */
553 if (c != self->transient_for) {
554 if (self->transient_for)
555 /* remove from old parent */
556 g_slist_remove(self->transient_for->transients, self);
557 self->transient_for = c;
558 if (self->transient_for)
559 /* add to new parent */
560 g_slist_append(self->transient_for->transients, self);
564 static void client_get_mwm_hints(Client *self)
567 unsigned long *hints;
569 self->mwmhints.flags = 0; /* default to none */
571 if (PROP_GET32U(self->window, motif_wm_hints, motif_wm_hints, hints, num)) {
572 if (num >= MWM_ELEMENTS) {
573 self->mwmhints.flags = hints[0];
574 self->mwmhints.functions = hints[1];
575 self->mwmhints.decorations = hints[2];
581 void client_get_type(Client *self)
587 if (PROP_GET32U(self->window, net_wm_window_type, atom, val, num)) {
588 /* use the first value that we know about in the array */
589 for (i = 0; i < num; ++i) {
590 if (val[i] == prop_atoms.net_wm_window_type_desktop)
591 self->type = Type_Desktop;
592 else if (val[i] == prop_atoms.net_wm_window_type_dock)
593 self->type = Type_Dock;
594 else if (val[i] == prop_atoms.net_wm_window_type_toolbar)
595 self->type = Type_Toolbar;
596 else if (val[i] == prop_atoms.net_wm_window_type_menu)
597 self->type = Type_Menu;
598 else if (val[i] == prop_atoms.net_wm_window_type_utility)
599 self->type = Type_Utility;
600 else if (val[i] == prop_atoms.net_wm_window_type_splash)
601 self->type = Type_Splash;
602 else if (val[i] == prop_atoms.net_wm_window_type_dialog)
603 self->type = Type_Dialog;
604 else if (val[i] == prop_atoms.net_wm_window_type_normal)
605 self->type = Type_Normal;
606 else if (val[i] == prop_atoms.kde_net_wm_window_type_override) {
607 /* prevent this window from getting any decor or
609 self->mwmhints.flags &= (MwmFlag_Functions |
610 MwmFlag_Decorations);
611 self->mwmhints.decorations = 0;
612 self->mwmhints.functions = 0;
614 if (self->type != (WindowType) -1)
615 break; /* grab the first legit type */
620 if (self->type == (WindowType) -1) {
621 /*the window type hint was not set, which means we either classify
622 ourself as a normal window or a dialog, depending on if we are a
625 self->type = Type_Dialog;
627 self->type = Type_Normal;
631 void client_update_protocols(Client *self)
634 gulong num_return, i;
636 self->focus_notify = FALSE;
637 self->delete_window = FALSE;
639 if (PROP_GET32U(self->window, wm_protocols, atom, proto, num_return)) {
640 for (i = 0; i < num_return; ++i) {
641 if (proto[i] == prop_atoms.wm_delete_window) {
642 /* this means we can request the window to close */
643 self->delete_window = TRUE;
644 } else if (proto[i] == prop_atoms.wm_take_focus)
645 /* if this protocol is requested, then the window will be
646 notified whenever we want it to receive focus */
647 self->focus_notify = TRUE;
653 static void client_get_gravity(Client *self)
655 XWindowAttributes wattrib;
658 ret = XGetWindowAttributes(ob_display, self->window, &wattrib);
659 g_assert(ret != BadWindow);
660 self->gravity = wattrib.win_gravity;
663 void client_update_normal_hints(Client *self)
667 int oldgravity = self->gravity;
670 self->min_ratio = 0.0f;
671 self->max_ratio = 0.0f;
672 SIZE_SET(self->size_inc, 1, 1);
673 SIZE_SET(self->base_size, 0, 0);
674 SIZE_SET(self->min_size, 0, 0);
675 SIZE_SET(self->max_size, G_MAXINT, G_MAXINT);
677 /* get the hints from the window */
678 if (XGetWMNormalHints(ob_display, self->window, &size, &ret)) {
679 self->positioned = (size.flags & (PPosition|USPosition));
681 if (size.flags & PWinGravity) {
682 self->gravity = size.win_gravity;
684 /* if the client has a frame, i.e. has already been mapped and
685 is changing its gravity */
686 if (self->frame && self->gravity != oldgravity) {
687 /* move our idea of the client's position based on its new
689 self->area.x = self->frame->area.x;
690 self->area.y = self->frame->area.y;
691 frame_frame_gravity(self->frame, &self->area.x, &self->area.y);
695 if (size.flags & PAspect) {
696 if (size.min_aspect.y)
697 self->min_ratio = (float)size.min_aspect.x / size.min_aspect.y;
698 if (size.max_aspect.y)
699 self->max_ratio = (float)size.max_aspect.x / size.max_aspect.y;
702 if (size.flags & PMinSize)
703 SIZE_SET(self->min_size, size.min_width, size.min_height);
705 if (size.flags & PMaxSize)
706 SIZE_SET(self->max_size, size.max_width, size.max_height);
708 if (size.flags & PBaseSize)
709 SIZE_SET(self->base_size, size.base_width, size.base_height);
711 if (size.flags & PResizeInc)
712 SIZE_SET(self->size_inc, size.width_inc, size.height_inc);
716 void client_setup_decor_and_functions(Client *self)
718 /* start with everything (cept fullscreen) */
719 self->decorations = Decor_Titlebar | Decor_Handle | Decor_Border |
720 Decor_Icon | Decor_AllDesktops | Decor_Iconify | Decor_Maximize;
721 self->functions = Func_Resize | Func_Move | Func_Iconify | Func_Maximize |
723 if (self->delete_window) {
724 self->decorations |= Decor_Close;
725 self->functions |= Func_Close;
728 if (!(self->min_size.width < self->max_size.width ||
729 self->min_size.height < self->max_size.height)) {
730 self->decorations &= ~(Decor_Maximize | Decor_Handle);
731 self->functions &= ~(Func_Resize | Func_Maximize);
734 switch (self->type) {
736 /* normal windows retain all of the possible decorations and
737 functionality, and are the only windows that you can fullscreen */
738 self->functions |= Func_Fullscreen;
742 /* dialogs cannot be maximized */
743 self->decorations &= ~Decor_Maximize;
744 self->functions &= ~Func_Maximize;
750 /* these windows get less functionality */
751 self->decorations &= ~(Decor_Iconify | Decor_Handle);
752 self->functions &= ~(Func_Iconify | Func_Resize);
758 /* none of these windows are manipulated by the window manager */
759 self->decorations = 0;
764 /* Mwm Hints are applied subtractively to what has already been chosen for
765 decor and functionality */
766 if (self->mwmhints.flags & MwmFlag_Decorations) {
767 if (! (self->mwmhints.decorations & MwmDecor_All)) {
768 if (! (self->mwmhints.decorations & MwmDecor_Border))
769 self->decorations &= ~Decor_Border;
770 if (! (self->mwmhints.decorations & MwmDecor_Handle))
771 self->decorations &= ~Decor_Handle;
772 if (! (self->mwmhints.decorations & MwmDecor_Title))
773 self->decorations &= ~Decor_Titlebar;
774 if (! (self->mwmhints.decorations & MwmDecor_Iconify))
775 self->decorations &= ~Decor_Iconify;
776 if (! (self->mwmhints.decorations & MwmDecor_Maximize))
777 self->decorations &= ~Decor_Maximize;
781 if (self->mwmhints.flags & MwmFlag_Functions) {
782 if (! (self->mwmhints.functions & MwmFunc_All)) {
783 if (! (self->mwmhints.functions & MwmFunc_Resize))
784 self->functions &= ~Func_Resize;
785 if (! (self->mwmhints.functions & MwmFunc_Move))
786 self->functions &= ~Func_Move;
787 if (! (self->mwmhints.functions & MwmFunc_Iconify))
788 self->functions &= ~Func_Iconify;
789 if (! (self->mwmhints.functions & MwmFunc_Maximize))
790 self->functions &= ~Func_Maximize;
791 /* dont let mwm hints kill the close button
792 if (! (self->mwmhints.functions & MwmFunc_Close))
793 self->functions &= ~Func_Close; */
797 /* can't maximize without moving/resizing */
798 if (!((self->functions & Func_Move) && (self->functions & Func_Resize)))
799 self->functions &= ~Func_Maximize;
801 /* finally, user specified disabled decorations are applied to subtract
803 if (self->disabled_decorations & Decor_Titlebar)
804 self->decorations &= ~Decor_Titlebar;
805 if (self->disabled_decorations & Decor_Handle)
806 self->decorations &= ~Decor_Handle;
807 if (self->disabled_decorations & Decor_Border)
808 self->decorations &= ~Decor_Border;
809 if (self->disabled_decorations & Decor_Iconify)
810 self->decorations &= ~Decor_Iconify;
811 if (self->disabled_decorations & Decor_Maximize)
812 self->decorations &= ~Decor_Maximize;
813 if (self->disabled_decorations & Decor_AllDesktops)
814 self->decorations &= ~Decor_AllDesktops;
815 if (self->disabled_decorations & Decor_Close)
816 self->decorations &= ~Decor_Close;
818 /* if we don't have a titlebar, then we cannot shade! */
819 if (!(self->decorations & Decor_Titlebar))
820 self->functions &= ~Func_Shade;
822 client_change_allowed_actions(self);
825 /* change the decors on the frame */
826 engine_frame_adjust_size(self->frame);
827 /* with more/less decorations, we may need to be repositioned */
828 engine_frame_adjust_position(self->frame);
829 /* with new decor, the window's maximized size may change */
830 client_remaximize(self);
834 static void client_change_allowed_actions(Client *self)
839 actions[num++] = prop_atoms.net_wm_action_change_desktop;
841 if (self->functions & Func_Shade)
842 actions[num++] = prop_atoms.net_wm_action_shade;
843 if (self->functions & Func_Close)
844 actions[num++] = prop_atoms.net_wm_action_close;
845 if (self->functions & Func_Move)
846 actions[num++] = prop_atoms.net_wm_action_move;
847 if (self->functions & Func_Iconify)
848 actions[num++] = prop_atoms.net_wm_action_minimize;
849 if (self->functions & Func_Resize)
850 actions[num++] = prop_atoms.net_wm_action_resize;
851 if (self->functions & Func_Fullscreen)
852 actions[num++] = prop_atoms.net_wm_action_fullscreen;
853 if (self->functions & Func_Maximize) {
854 actions[num++] = prop_atoms.net_wm_action_maximize_horz;
855 actions[num++] = prop_atoms.net_wm_action_maximize_vert;
858 PROP_SET32A(self->window, net_wm_allowed_actions, atom, actions, num);
860 /* make sure the window isn't breaking any rules now */
862 if (!(self->functions & Func_Shade) && self->shaded) {
863 if (self->frame) client_shade(self, FALSE);
864 else self->shaded = FALSE;
866 if (!(self->functions & Func_Iconify) && self->iconic) {
867 if (self->frame) client_iconify(self, FALSE, TRUE);
868 else self->iconic = FALSE;
870 if (!(self->functions & Func_Fullscreen) && self->fullscreen) {
871 if (self->frame) client_fullscreen(self, FALSE, TRUE);
872 else self->fullscreen = FALSE;
874 if (!(self->functions & Func_Maximize) && (self->max_horz ||
876 if (self->frame) client_maximize(self, FALSE, 0, TRUE);
877 else self->max_vert = self->max_horz = FALSE;
881 void client_remaximize(Client *self)
884 if (self->max_horz && self->max_vert)
886 else if (self->max_horz)
888 else if (self->max_vert)
891 return; /* not maximized */
892 self->max_horz = self->max_vert = FALSE;
893 client_maximize(self, TRUE, dir, FALSE);
896 void client_update_wmhints(Client *self)
901 /* assume a window takes input if it doesnt specify */
902 self->can_focus = TRUE;
904 if ((hints = XGetWMHints(ob_display, self->window)) != NULL) {
905 if (hints->flags & InputHint)
906 self->can_focus = hints->input;
908 /* only do this when starting! */
909 if (ob_state == State_Starting && (hints->flags & StateHint))
910 self->iconic = hints->initial_state == IconicState;
912 if (hints->flags & XUrgencyHint)
915 if (hints->flags & WindowGroupHint) {
916 if (hints->window_group != self->group) {
917 /* XXX: remove from the old group if there was one */
918 self->group = hints->window_group;
919 /* XXX: do stuff with the group */
921 } else /* no group! */
924 if (hints->flags & IconPixmapHint) {
925 client_update_kwm_icon(self);
926 /* try get the kwm icon first, this is a fallback only */
927 if (self->pixmap_icon == None) {
928 self->pixmap_icon = hints->icon_pixmap;
929 if (hints->flags & IconMaskHint)
930 self->pixmap_icon_mask = hints->icon_mask;
932 self->pixmap_icon_mask = None;
935 engine_frame_adjust_icon(self->frame);
942 if (ur != self->urgent) {
944 g_message("Urgent Hint for 0x%lx: %s\n", self->window,
946 /* fire the urgent callback if we're mapped, otherwise, wait until
947 after we're mapped */
949 HOOKFIRECLIENT(urgent, self);
953 void client_update_title(Client *self)
957 if (self->title != NULL)
961 if (!PROP_GETS(self->window, net_wm_name, utf8, data)) {
962 /* try old x stuff */
963 if (PROP_GETS(self->window, wm_name, string, data)) {
964 /* convert it to UTF-8 */
968 u = g_locale_to_utf8(data, -1, &r, &w, NULL);
970 g_warning("Unable to convert string to UTF-8");
977 data = g_strdup("Unnamed Window");
979 PROP_SETS(self->window, net_wm_visible_name, utf8, data);
985 engine_frame_adjust_title(self->frame);
988 void client_update_icon_title(Client *self)
992 if (self->icon_title != NULL)
993 g_free(self->icon_title);
996 if (!PROP_GETS(self->window, net_wm_icon_name, utf8, data)) {
997 /* try old x stuff */
998 if (PROP_GETS(self->window, wm_icon_name, string, data)) {
999 /* convert it to UTF-8 */
1003 u = g_locale_to_utf8(data, -1, &r, &w, NULL);
1005 g_warning("Unable to convert string to UTF-8");
1012 data = g_strdup("Unnamed Window");
1014 PROP_SETS(self->window, net_wm_visible_icon_name, utf8, data);
1017 self->icon_title = data;
1020 void client_update_class(Client *self)
1026 if (self->res_name) g_free(self->res_name);
1027 if (self->res_class) g_free(self->res_class);
1028 if (self->role) g_free(self->role);
1030 self->res_name = self->res_class = self->role = NULL;
1032 data = g_ptr_array_new();
1034 if (PROP_GETSA(self->window, wm_class, string, data)) {
1036 self->res_name = g_strdup(g_ptr_array_index(data, 0));
1038 self->res_class = g_strdup(g_ptr_array_index(data, 1));
1041 for (i = 0; i < data->len; ++i)
1042 g_free(g_ptr_array_index(data, i));
1043 g_ptr_array_free(data, TRUE);
1045 if (PROP_GETS(self->window, wm_window_role, string, s))
1046 self->role = g_strdup(s);
1048 if (self->res_name == NULL) self->res_name = g_strdup("");
1049 if (self->res_class == NULL) self->res_class = g_strdup("");
1050 if (self->role == NULL) self->role = g_strdup("");
1053 void client_update_strut(Client *self)
1057 if (PROP_GET32A(self->window, net_wm_strut, cardinal, data, 4)) {
1058 STRUT_SET(self->strut, data[0], data[1], data[2], data[3]);
1061 STRUT_SET(self->strut, 0, 0, 0, 0);
1063 /* updating here is pointless while we're being mapped cuz we're not in
1064 the client list yet */
1066 screen_update_struts();
1069 void client_update_icons(Client *self)
1072 unsigned long *data;
1073 unsigned long w, h, i;
1076 for (j = 0; j < self->nicons; ++j)
1077 g_free(self->icons[j].data);
1078 if (self->nicons > 0)
1079 g_free(self->icons);
1082 if (PROP_GET32U(self->window, net_wm_icon, cardinal, data, num)) {
1083 /* figure out how many valid icons are in here */
1085 while (num - i > 2) {
1093 self->icons = g_new(Icon, self->nicons);
1095 /* store the icons */
1097 for (j = 0; j < self->nicons; ++j) {
1098 w = self->icons[j].w = data[i++];
1099 h = self->icons[j].h = data[i++];
1100 self->icons[j].data =
1101 g_memdup(&data[i], w * h * sizeof(gulong));
1109 if (self->nicons <= 0) {
1111 self->icons = g_new0(Icon, 1);
1115 engine_frame_adjust_icon(self->frame);
1118 void client_update_kwm_icon(Client *self)
1122 if (PROP_GET32A(self->window, kwm_win_icon, kwm_win_icon, data, 2)) {
1123 self->pixmap_icon = data[0];
1124 self->pixmap_icon_mask = data[1];
1127 self->pixmap_icon = self->pixmap_icon_mask = None;
1130 engine_frame_adjust_icon(self->frame);
1133 static void client_change_state(Client *self)
1135 unsigned long state[2];
1139 state[0] = self->wmstate;
1141 PROP_SET32A(self->window, wm_state, wm_state, state, 2);
1145 netstate[num++] = prop_atoms.net_wm_state_modal;
1147 netstate[num++] = prop_atoms.net_wm_state_shaded;
1149 netstate[num++] = prop_atoms.net_wm_state_hidden;
1150 if (self->skip_taskbar)
1151 netstate[num++] = prop_atoms.net_wm_state_skip_taskbar;
1152 if (self->skip_pager)
1153 netstate[num++] = prop_atoms.net_wm_state_skip_pager;
1154 if (self->fullscreen)
1155 netstate[num++] = prop_atoms.net_wm_state_fullscreen;
1157 netstate[num++] = prop_atoms.net_wm_state_maximized_vert;
1159 netstate[num++] = prop_atoms.net_wm_state_maximized_horz;
1161 netstate[num++] = prop_atoms.net_wm_state_above;
1163 netstate[num++] = prop_atoms.net_wm_state_below;
1164 PROP_SET32A(self->window, net_wm_state, atom, netstate, num);
1166 client_calc_layer(self);
1169 engine_frame_adjust_state(self->frame);
1172 static Client *search_focus_tree(Client *node, Client *skip)
1177 for (it = node->transients; it != NULL; it = g_slist_next(it)) {
1178 Client *c = it->data;
1179 if (c == skip) continue; /* circular? */
1180 if ((ret = search_focus_tree(c, skip))) return ret;
1181 if (c->focused) return c;
1186 void client_calc_layer(Client *self)
1192 /* are we fullscreen, or do we have a fullscreen transient parent? */
1196 if (c->fullscreen) {
1200 c = c->transient_for;
1202 if (!fs && self->fullscreen) {
1203 /* is one of our transients focused? */
1204 c = search_focus_tree(self, self);
1205 if (c != NULL) fs = TRUE;
1208 if (self->iconic) l = Layer_Icon;
1209 else if (fs) l = Layer_Fullscreen;
1210 else if (self->type == Type_Desktop) l = Layer_Desktop;
1211 else if (self->type == Type_Dock) {
1212 if (!self->below) l = Layer_Top;
1213 else l = Layer_Normal;
1215 else if (self->above) l = Layer_Above;
1216 else if (self->below) l = Layer_Below;
1217 else l = Layer_Normal;
1219 if (l != self->layer) {
1222 stacking_raise(self);
1226 gboolean client_should_show(Client *self)
1228 if (self->iconic) return FALSE;
1229 else if (!(self->desktop == screen_desktop ||
1230 self->desktop == DESKTOP_ALL)) return FALSE;
1231 else if (client_normal(self) && screen_showing_desktop) return FALSE;
1236 void client_showhide(Client *self)
1239 if (client_should_show(self))
1240 engine_frame_show(self->frame);
1242 engine_frame_hide(self->frame);
1244 HOOKFIRECLIENT(visible, self);
1247 gboolean client_normal(Client *self) {
1248 return ! (self->type == Type_Desktop || self->type == Type_Dock ||
1249 self->type == Type_Splash);
1252 static void client_apply_startup_state(Client *self)
1254 /* these are in a carefully crafted order.. */
1257 self->iconic = FALSE;
1258 client_iconify(self, TRUE, FALSE);
1260 if (self->fullscreen) {
1261 self->fullscreen = FALSE;
1262 client_fullscreen(self, TRUE, FALSE);
1265 self->shaded = FALSE;
1266 client_shade(self, TRUE);
1269 HOOKFIRECLIENT(urgent, self);
1271 if (self->max_vert && self->max_horz) {
1272 self->max_vert = self->max_horz = FALSE;
1273 client_maximize(self, TRUE, 0, FALSE);
1274 } else if (self->max_vert) {
1275 self->max_vert = FALSE;
1276 client_maximize(self, TRUE, 2, FALSE);
1277 } else if (self->max_horz) {
1278 self->max_horz = FALSE;
1279 client_maximize(self, TRUE, 1, FALSE);
1282 /* nothing to do for the other states:
1291 void client_configure(Client *self, Corner anchor, int x, int y, int w, int h,
1292 gboolean user, gboolean final)
1294 gboolean moved = FALSE, resized = FALSE;
1296 w -= self->base_size.width;
1297 h -= self->base_size.height;
1300 /* for interactive resizing. have to move half an increment in each
1303 /* how far we are towards the next size inc */
1304 int mw = w % self->size_inc.width;
1305 int mh = h % self->size_inc.height;
1307 int aw = self->size_inc.width / 2;
1308 int ah = self->size_inc.height / 2;
1309 /* don't let us move into a new size increment */
1310 if (mw + aw >= self->size_inc.width)
1311 aw = self->size_inc.width - mw - 1;
1312 if (mh + ah >= self->size_inc.height)
1313 ah = self->size_inc.height - mh - 1;
1317 /* if this is a user-requested resize, then check against min/max
1318 sizes and aspect ratios */
1320 /* smaller than min size or bigger than max size? */
1321 if (w > self->max_size.width) w = self->max_size.width;
1322 if (w < self->min_size.width) w = self->min_size.width;
1323 if (h > self->max_size.height) h = self->max_size.height;
1324 if (h < self->min_size.height) h = self->min_size.height;
1326 /* adjust the height ot match the width for the aspect ratios */
1327 if (self->min_ratio)
1328 if (h * self->min_ratio > w) h = (int)(w / self->min_ratio);
1329 if (self->max_ratio)
1330 if (h * self->max_ratio < w) h = (int)(w / self->max_ratio);
1333 /* keep to the increments */
1334 w /= self->size_inc.width;
1335 h /= self->size_inc.height;
1337 /* you cannot resize to nothing */
1341 /* store the logical size */
1342 SIZE_SET(self->logical_size, w, h);
1344 w *= self->size_inc.width;
1345 h *= self->size_inc.height;
1347 w += self->base_size.width;
1348 h += self->base_size.height;
1351 case Corner_TopLeft:
1353 case Corner_TopRight:
1354 x -= w - self->area.width;
1356 case Corner_BottomLeft:
1357 y -= h - self->area.height;
1359 case Corner_BottomRight:
1360 x -= w - self->area.width;
1361 y -= h - self->area.height;
1365 moved = x != self->area.x || y != self->area.y;
1366 resized = w != self->area.width || h != self->area.height;
1368 RECT_SET(self->area, x, y, w, h);
1371 XResizeWindow(ob_display, self->window, w, h);
1373 /* move/resize the frame to match the request */
1375 /* Adjust the size and then the position, as required by the EWMH */
1377 engine_frame_adjust_size(self->frame);
1379 engine_frame_adjust_position(self->frame);
1381 if (!user || final) {
1383 event.type = ConfigureNotify;
1384 event.xconfigure.display = ob_display;
1385 event.xconfigure.event = self->window;
1386 event.xconfigure.window = self->window;
1388 /* root window coords with border in mind */
1389 event.xconfigure.x = x - self->border_width +
1390 self->frame->size.left;
1391 event.xconfigure.y = y - self->border_width +
1392 self->frame->size.top;
1394 event.xconfigure.width = self->area.width;
1395 event.xconfigure.height = self->area.height;
1396 event.xconfigure.border_width = self->border_width;
1397 event.xconfigure.above = self->frame->plate;
1398 event.xconfigure.override_redirect = FALSE;
1399 XSendEvent(event.xconfigure.display, event.xconfigure.window,
1400 FALSE, StructureNotifyMask, &event);
1406 void client_fullscreen(Client *self, gboolean fs, gboolean savearea)
1408 static int saved_func, saved_decor;
1411 if (!(self->functions & Func_Fullscreen) || /* can't */
1412 self->fullscreen == fs) return; /* already done */
1414 self->fullscreen = fs;
1415 client_change_state(self); /* change the state hints on the client */
1418 /* save the functions and remove them */
1419 saved_func = self->functions;
1420 self->functions &= (Func_Close | Func_Fullscreen |
1422 /* save the decorations and remove them */
1423 saved_decor = self->decorations;
1424 self->decorations = 0;
1427 dimensions[0] = self->area.x;
1428 dimensions[1] = self->area.y;
1429 dimensions[2] = self->area.width;
1430 dimensions[3] = self->area.height;
1432 PROP_SET32A(self->window, openbox_premax, cardinal,
1437 w = screen_physical_size.width;
1438 h = screen_physical_size.height;
1442 self->functions = saved_func;
1443 self->decorations = saved_decor;
1445 if (PROP_GET32A(self->window, openbox_premax, cardinal,
1453 /* pick some fallbacks... */
1454 x = screen_area(self->desktop)->x +
1455 screen_area(self->desktop)->width / 4;
1456 y = screen_area(self->desktop)->y +
1457 screen_area(self->desktop)->height / 4;
1458 w = screen_area(self->desktop)->width / 2;
1459 h = screen_area(self->desktop)->height / 2;
1463 client_change_allowed_actions(self); /* based on the new _functions */
1465 /* when fullscreening, don't obey things like increments, fill the
1467 client_configure(self, Corner_TopLeft, x, y, w, h, !fs, TRUE);
1469 /* raise (back) into our stacking layer */
1470 stacking_raise(self);
1472 /* try focus us when we go into fullscreen mode */
1476 void client_iconify(Client *self, gboolean iconic, gboolean curdesk)
1478 if (self->iconic == iconic) return; /* nothing to do */
1480 g_message("%sconifying window: 0x%lx\n", (iconic ? "I" : "Uni"),
1483 self->iconic = iconic;
1486 self->wmstate = IconicState;
1487 self->ignore_unmaps++;
1488 /* we unmap the client itself so that we can get MapRequest events,
1489 and because the ICCCM tells us to! */
1490 XUnmapWindow(ob_display, self->window);
1493 client_set_desktop(self, screen_desktop);
1494 self->wmstate = self->shaded ? IconicState : NormalState;
1495 XMapWindow(ob_display, self->window);
1497 client_change_state(self);
1498 client_showhide(self);
1499 screen_update_struts();
1502 void client_maximize(Client *self, gboolean max, int dir, gboolean savearea)
1506 g_assert(dir == 0 || dir == 1 || dir == 2);
1507 if (!(self->functions & Func_Maximize)) return; /* can't */
1509 /* check if already done */
1511 if (dir == 0 && self->max_horz && self->max_vert) return;
1512 if (dir == 1 && self->max_horz) return;
1513 if (dir == 2 && self->max_vert) return;
1515 if (dir == 0 && !self->max_horz && !self->max_vert) return;
1516 if (dir == 1 && !self->max_horz) return;
1517 if (dir == 2 && !self->max_vert) return;
1520 /* work with the frame's coords */
1521 x = self->frame->area.x;
1522 y = self->frame->area.y;
1523 w = self->area.width;
1524 h = self->area.height;
1536 /* get the property off the window and use it for the dimensions
1537 we are already maxed on */
1538 if (PROP_GET32A(self->window, openbox_premax, cardinal,
1540 if (self->max_horz) {
1541 dimensions[0] = readdim[0];
1542 dimensions[2] = readdim[2];
1544 if (self->max_vert) {
1545 dimensions[1] = readdim[1];
1546 dimensions[3] = readdim[3];
1551 PROP_SET32A(self->window, openbox_premax, cardinal,
1554 if (dir == 0 || dir == 1) { /* horz */
1555 x = screen_area(self->desktop)->x - self->frame->size.left;
1556 w = screen_area(self->desktop)->x +
1557 screen_area(self->desktop)->width;
1559 if (dir == 0 || dir == 2) { /* vert */
1560 y = screen_area(self->desktop)->y;
1561 h = screen_area(self->desktop)->y +
1562 screen_area(self->desktop)->height -
1563 self->frame->size.top - self->frame->size.bottom;
1568 if (PROP_GET32A(self->window, openbox_premax, cardinal,
1570 if (dir == 0 || dir == 1) { /* horz */
1574 if (dir == 0 || dir == 2) { /* vert */
1580 /* pick some fallbacks... */
1581 if (dir == 0 || dir == 1) { /* horz */
1582 x = screen_area(self->desktop)->x +
1583 screen_area(self->desktop)->width / 4;
1584 w = screen_area(self->desktop)->width / 2;
1586 if (dir == 0 || dir == 2) { /* vert */
1587 y = screen_area(self->desktop)->y +
1588 screen_area(self->desktop)->height / 4;
1589 h = screen_area(self->desktop)->height / 2;
1594 if (dir == 0 || dir == 1) /* horz */
1595 self->max_horz = max;
1596 if (dir == 0 || dir == 2) /* vert */
1597 self->max_vert = max;
1599 if (!self->max_horz && !self->max_vert)
1600 PROP_ERASE(self->window, openbox_premax);
1602 client_change_state(self); /* change the state hints on the client */
1604 /* figure out where the client should be going */
1605 frame_frame_gravity(self->frame, &x, &y);
1606 client_configure(self, Corner_TopLeft, x, y, w, h, TRUE, TRUE);
1609 void client_shade(Client *self, gboolean shade)
1611 if (!(self->functions & Func_Shade) || /* can't */
1612 self->shaded == shade) return; /* already done */
1614 /* when we're iconic, don't change the wmstate */
1616 self->wmstate = shade ? IconicState : NormalState;
1617 self->shaded = shade;
1618 client_change_state(self);
1619 engine_frame_adjust_size(self->frame);
1622 void client_close(Client *self)
1626 if (!(self->functions & Func_Close)) return;
1629 XXX: itd be cool to do timeouts and shit here for killing the client's
1631 like... if the window is around after 5 seconds, then the close button
1632 turns a nice red, and if this function is called again, the client is
1636 ce.xclient.type = ClientMessage;
1637 ce.xclient.message_type = prop_atoms.wm_protocols;
1638 ce.xclient.display = ob_display;
1639 ce.xclient.window = self->window;
1640 ce.xclient.format = 32;
1641 ce.xclient.data.l[0] = prop_atoms.wm_delete_window;
1642 ce.xclient.data.l[1] = CurrentTime;
1643 ce.xclient.data.l[2] = 0l;
1644 ce.xclient.data.l[3] = 0l;
1645 ce.xclient.data.l[4] = 0l;
1646 XSendEvent(ob_display, self->window, FALSE, NoEventMask, &ce);
1649 void client_set_desktop(Client *self, unsigned int target)
1651 if (target == self->desktop) return;
1653 g_message("Setting desktop %u\n", target);
1655 if (!(target < screen_num_desktops ||
1656 target == DESKTOP_ALL))
1659 self->desktop = target;
1660 PROP_SET32(self->window, net_wm_desktop, cardinal, target);
1661 /* the frame can display the current desktop state */
1662 engine_frame_adjust_state(self->frame);
1663 /* 'move' the window to the new desktop */
1664 client_showhide(self);
1665 screen_update_struts();
1668 static Client *search_modal_tree(Client *node, Client *skip)
1673 for (it = node->transients; it != NULL; it = it->next) {
1674 Client *c = it->data;
1675 if (c == skip) continue; /* circular? */
1676 if ((ret = search_modal_tree(c, skip))) return ret;
1677 if (c->modal) return c;
1682 Client *client_find_modal_child(Client *self)
1684 return search_modal_tree(self, self);
1687 gboolean client_validate(Client *self)
1691 XSync(ob_display, FALSE); /* get all events on the server */
1693 if (XCheckTypedWindowEvent(ob_display, self->window, DestroyNotify, &e) ||
1694 XCheckTypedWindowEvent(ob_display, self->window, UnmapNotify, &e)) {
1695 XPutBackEvent(ob_display, &e);
1702 void client_set_wm_state(Client *self, long state)
1704 if (state == self->wmstate) return; /* no change */
1708 client_iconify(self, TRUE, TRUE);
1711 client_iconify(self, FALSE, TRUE);
1716 void client_set_state(Client *self, Atom action, long data1, long data2)
1718 gboolean shaded = self->shaded;
1719 gboolean fullscreen = self->fullscreen;
1720 gboolean max_horz = self->max_horz;
1721 gboolean max_vert = self->max_vert;
1724 if (!(action == prop_atoms.net_wm_state_add ||
1725 action == prop_atoms.net_wm_state_remove ||
1726 action == prop_atoms.net_wm_state_toggle))
1727 /* an invalid action was passed to the client message, ignore it */
1730 for (i = 0; i < 2; ++i) {
1731 Atom state = i == 0 ? data1 : data2;
1733 if (!state) continue;
1735 /* if toggling, then pick whether we're adding or removing */
1736 if (action == prop_atoms.net_wm_state_toggle) {
1737 if (state == prop_atoms.net_wm_state_modal)
1738 action = self->modal ? prop_atoms.net_wm_state_remove :
1739 prop_atoms.net_wm_state_add;
1740 else if (state == prop_atoms.net_wm_state_maximized_vert)
1741 action = self->max_vert ? prop_atoms.net_wm_state_remove :
1742 prop_atoms.net_wm_state_add;
1743 else if (state == prop_atoms.net_wm_state_maximized_horz)
1744 action = self->max_horz ? prop_atoms.net_wm_state_remove :
1745 prop_atoms.net_wm_state_add;
1746 else if (state == prop_atoms.net_wm_state_shaded)
1747 action = self->shaded ? prop_atoms.net_wm_state_remove :
1748 prop_atoms.net_wm_state_add;
1749 else if (state == prop_atoms.net_wm_state_skip_taskbar)
1750 action = self->skip_taskbar ?
1751 prop_atoms.net_wm_state_remove :
1752 prop_atoms.net_wm_state_add;
1753 else if (state == prop_atoms.net_wm_state_skip_pager)
1754 action = self->skip_pager ?
1755 prop_atoms.net_wm_state_remove :
1756 prop_atoms.net_wm_state_add;
1757 else if (state == prop_atoms.net_wm_state_fullscreen)
1758 action = self->fullscreen ?
1759 prop_atoms.net_wm_state_remove :
1760 prop_atoms.net_wm_state_add;
1761 else if (state == prop_atoms.net_wm_state_above)
1762 action = self->above ? prop_atoms.net_wm_state_remove :
1763 prop_atoms.net_wm_state_add;
1764 else if (state == prop_atoms.net_wm_state_below)
1765 action = self->below ? prop_atoms.net_wm_state_remove :
1766 prop_atoms.net_wm_state_add;
1769 if (action == prop_atoms.net_wm_state_add) {
1770 if (state == prop_atoms.net_wm_state_modal) {
1771 /* XXX raise here or something? */
1773 } else if (state == prop_atoms.net_wm_state_maximized_vert) {
1775 } else if (state == prop_atoms.net_wm_state_maximized_horz) {
1777 } else if (state == prop_atoms.net_wm_state_shaded) {
1779 } else if (state == prop_atoms.net_wm_state_skip_taskbar) {
1780 self->skip_taskbar = TRUE;
1781 } else if (state == prop_atoms.net_wm_state_skip_pager) {
1782 self->skip_pager = TRUE;
1783 } else if (state == prop_atoms.net_wm_state_fullscreen) {
1785 } else if (state == prop_atoms.net_wm_state_above) {
1787 } else if (state == prop_atoms.net_wm_state_below) {
1791 } else { /* action == prop_atoms.net_wm_state_remove */
1792 if (state == prop_atoms.net_wm_state_modal) {
1793 self->modal = FALSE;
1794 } else if (state == prop_atoms.net_wm_state_maximized_vert) {
1796 } else if (state == prop_atoms.net_wm_state_maximized_horz) {
1798 } else if (state == prop_atoms.net_wm_state_shaded) {
1800 } else if (state == prop_atoms.net_wm_state_skip_taskbar) {
1801 self->skip_taskbar = FALSE;
1802 } else if (state == prop_atoms.net_wm_state_skip_pager) {
1803 self->skip_pager = FALSE;
1804 } else if (state == prop_atoms.net_wm_state_fullscreen) {
1806 } else if (state == prop_atoms.net_wm_state_above) {
1807 self->above = FALSE;
1808 } else if (state == prop_atoms.net_wm_state_below) {
1809 self->below = FALSE;
1813 if (max_horz != self->max_horz || max_vert != self->max_vert) {
1814 if (max_horz != self->max_horz && max_vert != self->max_vert) {
1816 if (max_horz == max_vert) { /* both going the same way */
1817 client_maximize(self, max_horz, 0, TRUE);
1819 client_maximize(self, max_horz, 1, TRUE);
1820 client_maximize(self, max_vert, 2, TRUE);
1824 if (max_horz != self->max_horz)
1825 client_maximize(self, max_horz, 1, TRUE);
1827 client_maximize(self, max_vert, 2, TRUE);
1830 /* change fullscreen state before shading, as it will affect if the window
1832 if (fullscreen != self->fullscreen)
1833 client_fullscreen(self, fullscreen, TRUE);
1834 if (shaded != self->shaded)
1835 client_shade(self, shaded);
1836 client_calc_layer(self);
1837 client_change_state(self); /* change the hint to relect these changes */
1840 gboolean client_focus(Client *self)
1845 /* if we have a modal child, then focus it, not us */
1846 child = client_find_modal_child(self);
1848 return client_focus(child);
1850 /* won't try focus if the client doesn't want it, or if the window isn't
1851 visible on the screen */
1852 if (!(self->frame->visible &&
1853 (self->can_focus || self->focus_notify)))
1856 /* do a check to see if the window has already been unmapped or destroyed
1857 do this intelligently while watching out for unmaps we've generated
1858 (ignore_unmaps > 0) */
1859 if (XCheckTypedWindowEvent(ob_display, self->window,
1860 DestroyNotify, &ev)) {
1861 XPutBackEvent(ob_display, &ev);
1864 while (XCheckTypedWindowEvent(ob_display, self->window,
1865 UnmapNotify, &ev)) {
1866 if (self->ignore_unmaps) {
1867 self->ignore_unmaps--;
1869 XPutBackEvent(ob_display, &ev);
1874 if (self->can_focus)
1875 XSetInputFocus(ob_display, self->window, RevertToNone, CurrentTime);
1877 if (self->focus_notify) {
1879 ce.xclient.type = ClientMessage;
1880 ce.xclient.message_type = prop_atoms.wm_protocols;
1881 ce.xclient.display = ob_display;
1882 ce.xclient.window = self->window;
1883 ce.xclient.format = 32;
1884 ce.xclient.data.l[0] = prop_atoms.wm_take_focus;
1885 ce.xclient.data.l[1] = event_lasttime;
1886 ce.xclient.data.l[2] = 0l;
1887 ce.xclient.data.l[3] = 0l;
1888 ce.xclient.data.l[4] = 0l;
1889 XSendEvent(ob_display, self->window, FALSE, NoEventMask, &ce);
1892 /*XSync(ob_display, FALSE); XXX Why sync? */
1896 void client_unfocus(Client *self)
1898 g_assert(focus_client == self);
1899 focus_set_client(NULL);