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, TRUE);
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 void client_showhide(Client *self, gboolean firehook)
1230 if (self->iconic) show = FALSE;
1231 else if (!(self->desktop == screen_desktop ||
1232 self->desktop == DESKTOP_ALL)) show = FALSE;
1233 else if (client_normal(self) && screen_showing_desktop) show = FALSE;
1236 if (show) engine_frame_show(self->frame);
1237 else engine_frame_hide(self->frame);
1240 HOOKFIRECLIENT(visible, self);
1243 gboolean client_normal(Client *self) {
1244 return ! (self->type == Type_Desktop || self->type == Type_Dock ||
1245 self->type == Type_Splash);
1248 static void client_apply_startup_state(Client *self)
1250 /* these are in a carefully crafted order.. */
1253 self->iconic = FALSE;
1254 client_iconify(self, TRUE, FALSE);
1256 if (self->fullscreen) {
1257 self->fullscreen = FALSE;
1258 client_fullscreen(self, TRUE, FALSE);
1261 self->shaded = FALSE;
1262 client_shade(self, TRUE);
1265 HOOKFIRECLIENT(urgent, self);
1267 if (self->max_vert && self->max_horz) {
1268 self->max_vert = self->max_horz = FALSE;
1269 client_maximize(self, TRUE, 0, FALSE);
1270 } else if (self->max_vert) {
1271 self->max_vert = FALSE;
1272 client_maximize(self, TRUE, 2, FALSE);
1273 } else if (self->max_horz) {
1274 self->max_horz = FALSE;
1275 client_maximize(self, TRUE, 1, FALSE);
1278 /* nothing to do for the other states:
1287 void client_configure(Client *self, Corner anchor, int x, int y, int w, int h,
1288 gboolean user, gboolean final)
1290 gboolean moved = FALSE, resized = FALSE;
1292 w -= self->base_size.width;
1293 h -= self->base_size.height;
1296 /* for interactive resizing. have to move half an increment in each
1299 /* how far we are towards the next size inc */
1300 int mw = w % self->size_inc.width;
1301 int mh = h % self->size_inc.height;
1303 int aw = self->size_inc.width / 2;
1304 int ah = self->size_inc.height / 2;
1305 /* don't let us move into a new size increment */
1306 if (mw + aw >= self->size_inc.width)
1307 aw = self->size_inc.width - mw - 1;
1308 if (mh + ah >= self->size_inc.height)
1309 ah = self->size_inc.height - mh - 1;
1313 /* if this is a user-requested resize, then check against min/max
1314 sizes and aspect ratios */
1316 /* smaller than min size or bigger than max size? */
1317 if (w > self->max_size.width) w = self->max_size.width;
1318 if (w < self->min_size.width) w = self->min_size.width;
1319 if (h > self->max_size.height) h = self->max_size.height;
1320 if (h < self->min_size.height) h = self->min_size.height;
1322 /* adjust the height ot match the width for the aspect ratios */
1323 if (self->min_ratio)
1324 if (h * self->min_ratio > w) h = (int)(w / self->min_ratio);
1325 if (self->max_ratio)
1326 if (h * self->max_ratio < w) h = (int)(w / self->max_ratio);
1329 /* keep to the increments */
1330 w /= self->size_inc.width;
1331 h /= self->size_inc.height;
1333 /* you cannot resize to nothing */
1337 /* store the logical size */
1338 SIZE_SET(self->logical_size, w, h);
1340 w *= self->size_inc.width;
1341 h *= self->size_inc.height;
1343 w += self->base_size.width;
1344 h += self->base_size.height;
1347 case Corner_TopLeft:
1349 case Corner_TopRight:
1350 x -= w - self->area.width;
1352 case Corner_BottomLeft:
1353 y -= h - self->area.height;
1355 case Corner_BottomRight:
1356 x -= w - self->area.width;
1357 y -= h - self->area.height;
1361 moved = x != self->area.x || y != self->area.y;
1362 resized = w != self->area.width || h != self->area.height;
1364 RECT_SET(self->area, x, y, w, h);
1367 XResizeWindow(ob_display, self->window, w, h);
1369 /* move/resize the frame to match the request */
1371 /* Adjust the size and then the position, as required by the EWMH */
1373 engine_frame_adjust_size(self->frame);
1375 engine_frame_adjust_position(self->frame);
1377 if (!user || final) {
1379 event.type = ConfigureNotify;
1380 event.xconfigure.display = ob_display;
1381 event.xconfigure.event = self->window;
1382 event.xconfigure.window = self->window;
1384 /* root window coords with border in mind */
1385 event.xconfigure.x = x - self->border_width +
1386 self->frame->size.left;
1387 event.xconfigure.y = y - self->border_width +
1388 self->frame->size.top;
1390 event.xconfigure.width = self->area.width;
1391 event.xconfigure.height = self->area.height;
1392 event.xconfigure.border_width = self->border_width;
1393 event.xconfigure.above = self->frame->plate;
1394 event.xconfigure.override_redirect = FALSE;
1395 XSendEvent(event.xconfigure.display, event.xconfigure.window,
1396 FALSE, StructureNotifyMask, &event);
1402 void client_fullscreen(Client *self, gboolean fs, gboolean savearea)
1404 static int saved_func, saved_decor;
1407 if (!(self->functions & Func_Fullscreen) || /* can't */
1408 self->fullscreen == fs) return; /* already done */
1410 self->fullscreen = fs;
1411 client_change_state(self); /* change the state hints on the client */
1414 /* save the functions and remove them */
1415 saved_func = self->functions;
1416 self->functions &= (Func_Close | Func_Fullscreen |
1418 /* save the decorations and remove them */
1419 saved_decor = self->decorations;
1420 self->decorations = 0;
1423 dimensions[0] = self->area.x;
1424 dimensions[1] = self->area.y;
1425 dimensions[2] = self->area.width;
1426 dimensions[3] = self->area.height;
1428 PROP_SET32A(self->window, openbox_premax, cardinal,
1433 w = screen_physical_size.width;
1434 h = screen_physical_size.height;
1438 self->functions = saved_func;
1439 self->decorations = saved_decor;
1441 if (PROP_GET32A(self->window, openbox_premax, cardinal,
1449 /* pick some fallbacks... */
1450 x = screen_area(self->desktop)->x +
1451 screen_area(self->desktop)->width / 4;
1452 y = screen_area(self->desktop)->y +
1453 screen_area(self->desktop)->height / 4;
1454 w = screen_area(self->desktop)->width / 2;
1455 h = screen_area(self->desktop)->height / 2;
1459 client_change_allowed_actions(self); /* based on the new _functions */
1461 /* when fullscreening, don't obey things like increments, fill the
1463 client_configure(self, Corner_TopLeft, x, y, w, h, !fs, TRUE);
1465 /* raise (back) into our stacking layer */
1466 stacking_raise(self);
1468 /* try focus us when we go into fullscreen mode */
1472 void client_iconify(Client *self, gboolean iconic, gboolean curdesk)
1474 if (self->iconic == iconic) return; /* nothing to do */
1476 g_message("%sconifying window: 0x%lx\n", (iconic ? "I" : "Uni"),
1479 self->iconic = iconic;
1482 self->wmstate = IconicState;
1483 self->ignore_unmaps++;
1484 /* we unmap the client itself so that we can get MapRequest events,
1485 and because the ICCCM tells us to! */
1486 XUnmapWindow(ob_display, self->window);
1489 client_set_desktop(self, screen_desktop);
1490 self->wmstate = self->shaded ? IconicState : NormalState;
1491 XMapWindow(ob_display, self->window);
1493 client_change_state(self);
1494 client_showhide(self, TRUE);
1495 screen_update_struts();
1498 void client_maximize(Client *self, gboolean max, int dir, gboolean savearea)
1502 g_assert(dir == 0 || dir == 1 || dir == 2);
1503 if (!(self->functions & Func_Maximize)) return; /* can't */
1505 /* check if already done */
1507 if (dir == 0 && self->max_horz && self->max_vert) return;
1508 if (dir == 1 && self->max_horz) return;
1509 if (dir == 2 && self->max_vert) return;
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;
1516 /* work with the frame's coords */
1517 x = self->frame->area.x;
1518 y = self->frame->area.y;
1519 w = self->area.width;
1520 h = self->area.height;
1532 /* get the property off the window and use it for the dimensions
1533 we are already maxed on */
1534 if (PROP_GET32A(self->window, openbox_premax, cardinal,
1536 if (self->max_horz) {
1537 dimensions[0] = readdim[0];
1538 dimensions[2] = readdim[2];
1540 if (self->max_vert) {
1541 dimensions[1] = readdim[1];
1542 dimensions[3] = readdim[3];
1547 PROP_SET32A(self->window, openbox_premax, cardinal,
1550 if (dir == 0 || dir == 1) { /* horz */
1551 x = screen_area(self->desktop)->x - self->frame->size.left;
1552 w = screen_area(self->desktop)->x +
1553 screen_area(self->desktop)->width;
1555 if (dir == 0 || dir == 2) { /* vert */
1556 y = screen_area(self->desktop)->y;
1557 h = screen_area(self->desktop)->y +
1558 screen_area(self->desktop)->height -
1559 self->frame->size.top - self->frame->size.bottom;
1564 if (PROP_GET32A(self->window, openbox_premax, cardinal,
1566 if (dir == 0 || dir == 1) { /* horz */
1570 if (dir == 0 || dir == 2) { /* vert */
1576 /* pick some fallbacks... */
1577 if (dir == 0 || dir == 1) { /* horz */
1578 x = screen_area(self->desktop)->x +
1579 screen_area(self->desktop)->width / 4;
1580 w = screen_area(self->desktop)->width / 2;
1582 if (dir == 0 || dir == 2) { /* vert */
1583 y = screen_area(self->desktop)->y +
1584 screen_area(self->desktop)->height / 4;
1585 h = screen_area(self->desktop)->height / 2;
1590 if (dir == 0 || dir == 1) /* horz */
1591 self->max_horz = max;
1592 if (dir == 0 || dir == 2) /* vert */
1593 self->max_vert = max;
1595 if (!self->max_horz && !self->max_vert)
1596 PROP_ERASE(self->window, openbox_premax);
1598 client_change_state(self); /* change the state hints on the client */
1600 /* figure out where the client should be going */
1601 frame_frame_gravity(self->frame, &x, &y);
1602 client_configure(self, Corner_TopLeft, x, y, w, h, TRUE, TRUE);
1605 void client_shade(Client *self, gboolean shade)
1607 if (!(self->functions & Func_Shade) || /* can't */
1608 self->shaded == shade) return; /* already done */
1610 /* when we're iconic, don't change the wmstate */
1612 self->wmstate = shade ? IconicState : NormalState;
1613 self->shaded = shade;
1614 client_change_state(self);
1615 engine_frame_adjust_size(self->frame);
1618 void client_close(Client *self)
1622 if (!(self->functions & Func_Close)) return;
1625 XXX: itd be cool to do timeouts and shit here for killing the client's
1627 like... if the window is around after 5 seconds, then the close button
1628 turns a nice red, and if this function is called again, the client is
1632 ce.xclient.type = ClientMessage;
1633 ce.xclient.message_type = prop_atoms.wm_protocols;
1634 ce.xclient.display = ob_display;
1635 ce.xclient.window = self->window;
1636 ce.xclient.format = 32;
1637 ce.xclient.data.l[0] = prop_atoms.wm_delete_window;
1638 ce.xclient.data.l[1] = CurrentTime;
1639 ce.xclient.data.l[2] = 0l;
1640 ce.xclient.data.l[3] = 0l;
1641 ce.xclient.data.l[4] = 0l;
1642 XSendEvent(ob_display, self->window, FALSE, NoEventMask, &ce);
1645 void client_set_desktop(Client *self, unsigned int target)
1647 if (target == self->desktop) return;
1649 g_message("Setting desktop %u\n", target);
1651 if (!(target < screen_num_desktops ||
1652 target == DESKTOP_ALL))
1655 self->desktop = target;
1656 PROP_SET32(self->window, net_wm_desktop, cardinal, target);
1657 /* the frame can display the current desktop state */
1658 engine_frame_adjust_state(self->frame);
1659 /* 'move' the window to the new desktop */
1660 client_showhide(self, TRUE);
1661 screen_update_struts();
1664 static Client *search_modal_tree(Client *node, Client *skip)
1669 for (it = node->transients; it != NULL; it = it->next) {
1670 Client *c = it->data;
1671 if (c == skip) continue; /* circular? */
1672 if ((ret = search_modal_tree(c, skip))) return ret;
1673 if (c->modal) return c;
1678 Client *client_find_modal_child(Client *self)
1680 return search_modal_tree(self, self);
1683 gboolean client_validate(Client *self)
1687 XSync(ob_display, FALSE); /* get all events on the server */
1689 if (XCheckTypedWindowEvent(ob_display, self->window, DestroyNotify, &e) ||
1690 XCheckTypedWindowEvent(ob_display, self->window, UnmapNotify, &e)) {
1691 XPutBackEvent(ob_display, &e);
1698 void client_set_wm_state(Client *self, long state)
1700 if (state == self->wmstate) return; /* no change */
1704 client_iconify(self, TRUE, TRUE);
1707 client_iconify(self, FALSE, TRUE);
1712 void client_set_state(Client *self, Atom action, long data1, long data2)
1714 gboolean shaded = self->shaded;
1715 gboolean fullscreen = self->fullscreen;
1716 gboolean max_horz = self->max_horz;
1717 gboolean max_vert = self->max_vert;
1720 if (!(action == prop_atoms.net_wm_state_add ||
1721 action == prop_atoms.net_wm_state_remove ||
1722 action == prop_atoms.net_wm_state_toggle))
1723 /* an invalid action was passed to the client message, ignore it */
1726 for (i = 0; i < 2; ++i) {
1727 Atom state = i == 0 ? data1 : data2;
1729 if (!state) continue;
1731 /* if toggling, then pick whether we're adding or removing */
1732 if (action == prop_atoms.net_wm_state_toggle) {
1733 if (state == prop_atoms.net_wm_state_modal)
1734 action = self->modal ? prop_atoms.net_wm_state_remove :
1735 prop_atoms.net_wm_state_add;
1736 else if (state == prop_atoms.net_wm_state_maximized_vert)
1737 action = self->max_vert ? prop_atoms.net_wm_state_remove :
1738 prop_atoms.net_wm_state_add;
1739 else if (state == prop_atoms.net_wm_state_maximized_horz)
1740 action = self->max_horz ? prop_atoms.net_wm_state_remove :
1741 prop_atoms.net_wm_state_add;
1742 else if (state == prop_atoms.net_wm_state_shaded)
1743 action = self->shaded ? prop_atoms.net_wm_state_remove :
1744 prop_atoms.net_wm_state_add;
1745 else if (state == prop_atoms.net_wm_state_skip_taskbar)
1746 action = self->skip_taskbar ?
1747 prop_atoms.net_wm_state_remove :
1748 prop_atoms.net_wm_state_add;
1749 else if (state == prop_atoms.net_wm_state_skip_pager)
1750 action = self->skip_pager ?
1751 prop_atoms.net_wm_state_remove :
1752 prop_atoms.net_wm_state_add;
1753 else if (state == prop_atoms.net_wm_state_fullscreen)
1754 action = self->fullscreen ?
1755 prop_atoms.net_wm_state_remove :
1756 prop_atoms.net_wm_state_add;
1757 else if (state == prop_atoms.net_wm_state_above)
1758 action = self->above ? prop_atoms.net_wm_state_remove :
1759 prop_atoms.net_wm_state_add;
1760 else if (state == prop_atoms.net_wm_state_below)
1761 action = self->below ? prop_atoms.net_wm_state_remove :
1762 prop_atoms.net_wm_state_add;
1765 if (action == prop_atoms.net_wm_state_add) {
1766 if (state == prop_atoms.net_wm_state_modal) {
1767 /* XXX raise here or something? */
1769 } else if (state == prop_atoms.net_wm_state_maximized_vert) {
1771 } else if (state == prop_atoms.net_wm_state_maximized_horz) {
1773 } else if (state == prop_atoms.net_wm_state_shaded) {
1775 } else if (state == prop_atoms.net_wm_state_skip_taskbar) {
1776 self->skip_taskbar = TRUE;
1777 } else if (state == prop_atoms.net_wm_state_skip_pager) {
1778 self->skip_pager = TRUE;
1779 } else if (state == prop_atoms.net_wm_state_fullscreen) {
1781 } else if (state == prop_atoms.net_wm_state_above) {
1783 } else if (state == prop_atoms.net_wm_state_below) {
1787 } else { /* action == prop_atoms.net_wm_state_remove */
1788 if (state == prop_atoms.net_wm_state_modal) {
1789 self->modal = FALSE;
1790 } else if (state == prop_atoms.net_wm_state_maximized_vert) {
1792 } else if (state == prop_atoms.net_wm_state_maximized_horz) {
1794 } else if (state == prop_atoms.net_wm_state_shaded) {
1796 } else if (state == prop_atoms.net_wm_state_skip_taskbar) {
1797 self->skip_taskbar = FALSE;
1798 } else if (state == prop_atoms.net_wm_state_skip_pager) {
1799 self->skip_pager = FALSE;
1800 } else if (state == prop_atoms.net_wm_state_fullscreen) {
1802 } else if (state == prop_atoms.net_wm_state_above) {
1803 self->above = FALSE;
1804 } else if (state == prop_atoms.net_wm_state_below) {
1805 self->below = FALSE;
1809 if (max_horz != self->max_horz || max_vert != self->max_vert) {
1810 if (max_horz != self->max_horz && max_vert != self->max_vert) {
1812 if (max_horz == max_vert) { /* both going the same way */
1813 client_maximize(self, max_horz, 0, TRUE);
1815 client_maximize(self, max_horz, 1, TRUE);
1816 client_maximize(self, max_vert, 2, TRUE);
1820 if (max_horz != self->max_horz)
1821 client_maximize(self, max_horz, 1, TRUE);
1823 client_maximize(self, max_vert, 2, TRUE);
1826 /* change fullscreen state before shading, as it will affect if the window
1828 if (fullscreen != self->fullscreen)
1829 client_fullscreen(self, fullscreen, TRUE);
1830 if (shaded != self->shaded)
1831 client_shade(self, shaded);
1832 client_calc_layer(self);
1833 client_change_state(self); /* change the hint to relect these changes */
1836 gboolean client_focus(Client *self)
1841 /* if we have a modal child, then focus it, not us */
1842 child = client_find_modal_child(self);
1844 return client_focus(child);
1846 /* won't try focus if the client doesn't want it, or if the window isn't
1847 visible on the screen */
1848 if (!(self->frame->visible &&
1849 (self->can_focus || self->focus_notify)))
1852 /* do a check to see if the window has already been unmapped or destroyed
1853 do this intelligently while watching out for unmaps we've generated
1854 (ignore_unmaps > 0) */
1855 if (XCheckTypedWindowEvent(ob_display, self->window,
1856 DestroyNotify, &ev)) {
1857 XPutBackEvent(ob_display, &ev);
1860 while (XCheckTypedWindowEvent(ob_display, self->window,
1861 UnmapNotify, &ev)) {
1862 if (self->ignore_unmaps) {
1863 self->ignore_unmaps--;
1865 XPutBackEvent(ob_display, &ev);
1870 if (self->can_focus)
1871 XSetInputFocus(ob_display, self->window, RevertToNone, CurrentTime);
1873 if (self->focus_notify) {
1875 ce.xclient.type = ClientMessage;
1876 ce.xclient.message_type = prop_atoms.wm_protocols;
1877 ce.xclient.display = ob_display;
1878 ce.xclient.window = self->window;
1879 ce.xclient.format = 32;
1880 ce.xclient.data.l[0] = prop_atoms.wm_take_focus;
1881 ce.xclient.data.l[1] = event_lasttime;
1882 ce.xclient.data.l[2] = 0l;
1883 ce.xclient.data.l[3] = 0l;
1884 ce.xclient.data.l[4] = 0l;
1885 XSendEvent(ob_display, self->window, FALSE, NoEventMask, &ce);
1888 /*XSync(ob_display, FALSE); XXX Why sync? */
1892 void client_unfocus(Client *self)
1894 g_assert(focus_client == self);
1895 focus_set_client(NULL);