4 #include "moveresize.h"
6 #include "extensions.h"
18 #include <X11/Xutil.h>
20 /*! The event mask to grab on client windows */
21 #define CLIENT_EVENTMASK (PropertyChangeMask | FocusChangeMask | \
24 #define CLIENT_NOPROPAGATEMASK (ButtonPressMask | ButtonReleaseMask | \
27 GList *client_list = NULL;
28 GHashTable *client_map = NULL;
30 static void client_get_all(Client *self);
31 static void client_toggle_border(Client *self, gboolean show);
32 static void client_get_area(Client *self);
33 static void client_get_desktop(Client *self);
34 static void client_get_state(Client *self);
35 static void client_get_shaped(Client *self);
36 static void client_get_mwm_hints(Client *self);
37 static void client_get_gravity(Client *self);
38 static void client_showhide(Client *self);
39 static void client_change_allowed_actions(Client *self);
40 static void client_change_state(Client *self);
41 static void client_move_onscreen(Client *self);
42 static Client *search_focus_tree(Client *node, Client *skip);
43 static void client_apply_startup_state(Client *self);
44 static Client *search_modal_tree(Client *node, Client *skip);
46 static guint map_hash(Window *w) { return *w; }
47 static gboolean map_key_comp(Window *w1, Window *w2) { return *w1 == *w2; }
51 client_map = g_hash_table_new((GHashFunc)map_hash,
52 (GEqualFunc)map_key_comp);
57 void client_shutdown()
59 g_hash_table_destroy(client_map);
62 void client_set_list()
64 Window *windows, *win_it;
66 guint size = g_list_length(client_list);
68 /* create an array of the window ids */
70 windows = g_new(Window, size);
72 for (it = client_list; it != NULL; it = it->next, ++win_it)
73 *win_it = ((Client*)it->data)->window;
77 PROP_SETA32(ob_root, net_client_list, window, (guint32*)windows, size);
85 void client_manage_all()
87 unsigned int i, j, nchild;
90 XWindowAttributes attrib;
93 XQueryTree(ob_display, ob_root, &w, &w, &children, &nchild);
95 /* remove all icon windows from the list */
96 for (i = 0; i < nchild; i++) {
97 if (children[i] == None) continue;
98 wmhints = XGetWMHints(ob_display, children[i]);
100 if ((wmhints->flags & IconWindowHint) &&
101 (wmhints->icon_window != children[i]))
102 for (j = 0; j < nchild; j++)
103 if (children[j] == wmhints->icon_window) {
111 for (i = 0; i < nchild; ++i) {
112 if (children[i] == None)
114 if (XGetWindowAttributes(ob_display, children[i], &attrib)) {
115 if (attrib.override_redirect) continue;
117 if (attrib.map_state != IsUnmapped)
118 client_manage(children[i]);
123 /* stack them as they were on startup!
124 why with stacking_lower? Why, because then windows who aren't in the
125 stacking list are on the top where you can see them instead of buried
127 for (i = startup_stack_size; i > 0; --i) {
130 w = startup_stack_order[i-1];
131 c = g_hash_table_lookup(client_map, &w);
132 if (c) stacking_lower(c);
134 g_free(startup_stack_order);
135 startup_stack_order = NULL;
136 startup_stack_size = 0;
138 active = g_hash_table_lookup(client_map, &startup_active);
139 if (!active || !client_focus(active))
140 if (config_focus_new)
141 focus_fallback(Fallback_NoFocus);
144 void client_manage(Window window)
148 XWindowAttributes attrib;
149 XSetWindowAttributes attrib_set;
150 /* XWMHints *wmhint; */
154 /* check if it has already been unmapped by the time we started mapping
155 the grab does a sync so we don't have to here */
156 if (XCheckTypedWindowEvent(ob_display, window, DestroyNotify, &e) ||
157 XCheckTypedWindowEvent(ob_display, window, UnmapNotify, &e)) {
158 XPutBackEvent(ob_display, &e);
161 return; /* don't manage it */
164 /* make sure it isn't an override-redirect window */
165 if (!XGetWindowAttributes(ob_display, window, &attrib) ||
166 attrib.override_redirect) {
168 return; /* don't manage it */
171 /* /\* is the window a docking app *\/
172 if ((wmhint = XGetWMHints(ob_display, window))) {
173 if ((wmhint->flags & StateHint) &&
174 wmhint->initial_state == WithdrawnState) {
175 /\* XXX: make dock apps work! *\/
183 g_message("Managing window: %lx", window);
185 /* choose the events we want to receive on the CLIENT window */
186 attrib_set.event_mask = CLIENT_EVENTMASK;
187 attrib_set.do_not_propagate_mask = CLIENT_NOPROPAGATEMASK;
188 XChangeWindowAttributes(ob_display, window,
189 CWEventMask|CWDontPropagate, &attrib_set);
192 /* create the Client struct, and populate it from the hints on the
194 self = g_new(Client, 1);
195 self->window = window;
196 client_get_all(self);
198 /* remove the client's border (and adjust re gravity) */
199 client_toggle_border(self, FALSE);
201 /* specify that if we exit, the window should not be destroyed and should
202 be reparented back to root automatically */
203 XChangeSaveSet(ob_display, window, SetModeInsert);
205 /* create the decoration frame for the client window */
206 self->frame = frame_new();
208 frame_grab_client(self->frame, self);
210 client_apply_startup_state(self);
214 client_list = g_list_append(client_list, self);
215 stacking_list = g_list_append(stacking_list, self);
216 g_assert(!g_hash_table_lookup(client_map, &self->window));
217 g_hash_table_insert(client_map, &self->window, self);
219 /* update the focus lists */
220 focus_order_add_new(self);
222 stacking_raise(self);
224 screen_update_struts();
226 dispatch_client(Event_Client_New, self, 0, 0);
228 client_showhide(self);
230 /* focus the new window? */
231 if (ob_state != State_Starting) {
233 gboolean group_foc = FALSE;
240 for (it = self->group->members; it; it = it->next)
241 if (client_focused(it->data)) {
246 if (!group_foc && self->transient_for) {
247 if (self->transient_for != TRAN_GROUP) {/* transient of a window */
248 parent = self->transient_for;
249 } else { /* transient of a group */
252 for (it = self->group->members; it; it = it->next)
253 if (it->data != self &&
254 ((Client*)it->data)->transient_for != TRAN_GROUP)
258 /* note the check against Type_Normal, not client_normal(self), which
259 would also include dialog types. in this case we want more strict
261 if ((config_focus_new &&
262 (self->type == Type_Normal ||
263 (self->type == Type_Dialog &&
265 (!parent && (!self->group ||
266 !self->group->members->next)))))) ||
267 (parent && (client_focused(parent) ||
268 search_focus_tree(parent, parent)))) {
273 /* update the list hints */
276 /* make sure the window is visible */
277 client_move_onscreen(self);
279 dispatch_client(Event_Client_Mapped, self, 0, 0);
281 g_message("Managed window 0x%lx", window);
284 void client_unmanage_all()
286 while (client_list != NULL)
287 client_unmanage(client_list->data);
290 void client_unmanage(Client *self)
295 g_message("Unmanaging window: %lx", self->window);
297 dispatch_client(Event_Client_Destroy, self, 0, 0);
298 g_assert(self != NULL);
300 /* remove the window from our save set */
301 XChangeSaveSet(ob_display, self->window, SetModeDelete);
303 /* we dont want events no more */
304 XSelectInput(ob_display, self->window, NoEventMask);
306 frame_hide(self->frame);
308 client_list = g_list_remove(client_list, self);
309 stacking_list = g_list_remove(stacking_list, self);
310 g_hash_table_remove(client_map, &self->window);
312 /* update the focus lists */
313 focus_order_remove(self);
315 /* once the client is out of the list, update the struts to remove it's
317 screen_update_struts();
319 /* tell our parent(s) that we're gone */
320 if (self->transient_for == TRAN_GROUP) { /* transient of group */
323 for (it = self->group->members; it; it = it->next)
324 if (it->data != self)
325 ((Client*)it->data)->transients =
326 g_slist_remove(((Client*)it->data)->transients, self);
327 } else if (self->transient_for) { /* transient of window */
328 self->transient_for->transients =
329 g_slist_remove(self->transient_for->transients, self);
332 /* tell our transients that we're gone */
333 for (it = self->transients; it != NULL; it = it->next) {
334 if (((Client*)it->data)->transient_for != TRAN_GROUP) {
335 ((Client*)it->data)->transient_for = NULL;
336 client_calc_layer(it->data);
340 if (moveresize_client == self)
341 moveresize_end(TRUE);
343 if (focus_client == self) {
346 /* focus the last focused window on the desktop, and ignore enter
347 events from the unmap so it doesnt mess with the focus */
348 while (XCheckTypedEvent(ob_display, EnterNotify, &e));
349 client_unfocus(self);
352 /* remove from its group */
354 group_remove(self->group, self);
358 /* dispatch the unmapped event */
359 dispatch_client(Event_Client_Unmapped, self, 0, 0);
360 g_assert(self != NULL);
362 /* give the client its border back */
363 client_toggle_border(self, TRUE);
365 /* reparent the window out of the frame, and free the frame */
366 frame_release_client(self->frame, self);
369 if (ob_state != State_Exiting) {
370 /* these values should not be persisted across a window
372 prop_erase(self->window, prop_atoms.net_wm_desktop);
373 prop_erase(self->window, prop_atoms.net_wm_state);
375 /* if we're left in an iconic state, the client wont be mapped. this is
376 bad, since we will no longer be managing the window on restart */
378 XMapWindow(ob_display, self->window);
382 g_message("Unmanaged window 0x%lx", self->window);
384 /* free all data allocated in the client struct */
385 g_slist_free(self->transients);
386 for (j = 0; j < self->nicons; ++j)
387 g_free(self->icons[j].data);
388 if (self->nicons > 0)
391 g_free(self->icon_title);
397 /* update the list hints */
401 static void client_move_onscreen(Client *self)
404 int x = self->frame->area.x, y = self->frame->area.y;
406 a = screen_area(self->desktop);
407 if (x >= a->x + a->width - 1)
408 x = a->x + a->width - self->frame->area.width;
409 if (y >= a->y + a->height - 1)
410 y = a->y + a->height - self->frame->area.height;
411 if (x + self->frame->area.width - 1 < a->x)
413 if (y + self->frame->area.height - 1< a->y)
416 frame_frame_gravity(self->frame, &x, &y); /* get where the client
418 client_configure(self , Corner_TopLeft, x, y,
419 self->area.width, self->area.height,
423 static void client_toggle_border(Client *self, gboolean show)
425 /* adjust our idea of where the client is, based on its border. When the
426 border is removed, the client should now be considered to be in a
428 when re-adding the border to the client, the same operation needs to be
430 int oldx = self->area.x, oldy = self->area.y;
431 int x = oldx, y = oldy;
432 switch(self->gravity) {
434 case NorthWestGravity:
436 case SouthWestGravity:
438 case NorthEastGravity:
440 case SouthEastGravity:
441 if (show) x -= self->border_width * 2;
442 else x += self->border_width * 2;
449 if (show) x -= self->border_width;
450 else x += self->border_width;
453 switch(self->gravity) {
455 case NorthWestGravity:
457 case NorthEastGravity:
459 case SouthWestGravity:
461 case SouthEastGravity:
462 if (show) y -= self->border_width * 2;
463 else y += self->border_width * 2;
470 if (show) y -= self->border_width;
471 else y += self->border_width;
478 XSetWindowBorderWidth(ob_display, self->window, self->border_width);
480 /* move the client so it is back it the right spot _with_ its
482 if (x != oldx || y != oldy)
483 XMoveWindow(ob_display, self->window, x, y);
485 XSetWindowBorderWidth(ob_display, self->window, 0);
489 static void client_get_all(Client *self)
491 /* update EVERYTHING!! */
493 self->ignore_unmaps = 0;
497 self->title = self->icon_title = NULL;
498 self->name = self->class = self->role = NULL;
499 self->wmstate = NormalState;
500 self->transient = FALSE;
501 self->transients = NULL;
502 self->transient_for = NULL;
504 self->urgent = FALSE;
505 self->positioned = FALSE;
506 self->disabled_decorations = 0;
510 client_get_area(self);
511 client_update_transient_for(self);
512 client_update_wmhints(self);
513 client_get_desktop(self);
514 client_get_state(self);
515 client_get_shaped(self);
517 client_get_mwm_hints(self);
518 client_get_type(self);/* this can change the mwmhints for special cases */
520 client_update_protocols(self);
522 client_get_gravity(self); /* get the attribute gravity */
523 client_update_normal_hints(self); /* this may override the attribute
526 /* got the type, the mwmhints, the protocols, and the normal hints
527 (min/max sizes), so we're ready to set up the decorations/functions */
528 client_setup_decor_and_functions(self);
530 client_update_title(self);
531 client_update_icon_title(self);
532 client_update_class(self);
533 client_update_strut(self);
534 client_update_icons(self);
535 client_update_kwm_icon(self);
537 client_change_state(self);
540 static void client_get_area(Client *self)
542 XWindowAttributes wattrib;
545 ret = XGetWindowAttributes(ob_display, self->window, &wattrib);
546 g_assert(ret != BadWindow);
548 RECT_SET(self->area, wattrib.x, wattrib.y, wattrib.width, wattrib.height);
549 self->border_width = wattrib.border_width;
552 static void client_get_desktop(Client *self)
556 if (PROP_GET32(self->window, net_wm_desktop, cardinal, &d)) {
557 if (d >= screen_num_desktops && d != DESKTOP_ALL)
558 d = screen_num_desktops - 1;
561 gboolean trdesk = FALSE;
563 if (self->transient_for) {
564 if (self->transient_for != TRAN_GROUP) {
565 self->desktop = self->transient_for->desktop;
570 for (it = self->group->members; it; it = it->next)
571 if (it->data != self &&
572 ((Client*)it->data)->transient_for != TRAN_GROUP) {
573 self->desktop = ((Client*)it->data)->desktop;
580 /* defaults to the current desktop */
581 self->desktop = screen_desktop;
583 /* set the desktop hint, to make sure that it always exists */
584 PROP_SET32(self->window, net_wm_desktop, cardinal, self->desktop);
588 static void client_get_state(Client *self)
593 self->modal = self->shaded = self->max_horz = self->max_vert =
594 self->fullscreen = self->above = self->below = self->iconic =
595 self->skip_taskbar = self->skip_pager = FALSE;
597 if (PROP_GETA32(self->window, net_wm_state, atom, &state, &num)) {
599 for (i = 0; i < num; ++i) {
600 if (state[i] == prop_atoms.net_wm_state_modal)
602 else if (state[i] == prop_atoms.net_wm_state_shaded)
604 else if (state[i] == prop_atoms.net_wm_state_hidden)
606 else if (state[i] == prop_atoms.net_wm_state_skip_taskbar)
607 self->skip_taskbar = TRUE;
608 else if (state[i] == prop_atoms.net_wm_state_skip_pager)
609 self->skip_pager = TRUE;
610 else if (state[i] == prop_atoms.net_wm_state_fullscreen)
611 self->fullscreen = TRUE;
612 else if (state[i] == prop_atoms.net_wm_state_maximized_vert)
613 self->max_vert = TRUE;
614 else if (state[i] == prop_atoms.net_wm_state_maximized_horz)
615 self->max_horz = TRUE;
616 else if (state[i] == prop_atoms.net_wm_state_above)
618 else if (state[i] == prop_atoms.net_wm_state_below)
626 static void client_get_shaped(Client *self)
628 self->shaped = FALSE;
630 if (extensions_shape) {
635 XShapeSelectInput(ob_display, self->window, ShapeNotifyMask);
637 XShapeQueryExtents(ob_display, self->window, &s, &foo,
638 &foo, &ufoo, &ufoo, &foo, &foo, &foo, &ufoo,
640 self->shaped = (s != 0);
645 void client_update_transient_for(Client *self)
650 if (XGetTransientForHint(ob_display, self->window, &t)) {
651 self->transient = TRUE;
652 if (t != self->window) { /* cant be transient to itself! */
653 c = g_hash_table_lookup(client_map, &t);
654 /* if this happens then we need to check for it*/
657 if (!c && self->group) {
658 /* not transient to a client, see if it is transient for a
660 if (t == self->group->leader ||
663 /* window is a transient for its group! */
669 self->transient = FALSE;
671 /* if anything has changed... */
672 if (c != self->transient_for) {
673 if (self->transient_for == TRAN_GROUP) { /* transient of group */
676 /* remove from old parents */
677 for (it = self->group->members; it; it = it->next)
678 if (it->data != self &&
679 (((Client*)it->data)->transient_for != TRAN_GROUP))
680 ((Client*)it->data)->transients =
681 g_slist_remove(((Client*)it->data)->transients, self);
682 } else if (self->transient_for != NULL) { /* transient of window */
683 /* remove from old parent */
684 self->transient_for->transients =
685 g_slist_remove(self->transient_for->transients, self);
687 self->transient_for = c;
688 if (self->transient_for == TRAN_GROUP) { /* transient of group */
691 /* add to new parents */
692 for (it = self->group->members; it; it = it->next)
693 if (it->data != self &&
694 (((Client*)it->data)->transient_for != TRAN_GROUP))
695 ((Client*)it->data)->transients =
696 g_slist_append(((Client*)it->data)->transients, self);
698 /* remove all transients which are in the group, that causes
699 circlular pointer hell of doom */
700 for (it = self->group->members; it; it = it->next) {
702 for (sit = self->transients; sit; sit = next) {
704 if (sit->data == it->data)
705 self->transients = g_slist_remove(self->transients,
709 } else if (self->transient_for != NULL) { /* transient of window */
710 /* add to new parent */
711 self->transient_for->transients =
712 g_slist_append(self->transient_for->transients, self);
717 static void client_get_mwm_hints(Client *self)
722 self->mwmhints.flags = 0; /* default to none */
724 if (PROP_GETA32(self->window, motif_wm_hints, motif_wm_hints,
726 if (num >= MWM_ELEMENTS) {
727 self->mwmhints.flags = hints[0];
728 self->mwmhints.functions = hints[1];
729 self->mwmhints.decorations = hints[2];
735 void client_get_type(Client *self)
742 if (PROP_GETA32(self->window, net_wm_window_type, atom, &val, &num)) {
743 /* use the first value that we know about in the array */
744 for (i = 0; i < num; ++i) {
745 if (val[i] == prop_atoms.net_wm_window_type_desktop)
746 self->type = Type_Desktop;
747 else if (val[i] == prop_atoms.net_wm_window_type_dock)
748 self->type = Type_Dock;
749 else if (val[i] == prop_atoms.net_wm_window_type_toolbar)
750 self->type = Type_Toolbar;
751 else if (val[i] == prop_atoms.net_wm_window_type_menu)
752 self->type = Type_Menu;
753 else if (val[i] == prop_atoms.net_wm_window_type_utility)
754 self->type = Type_Utility;
755 else if (val[i] == prop_atoms.net_wm_window_type_splash)
756 self->type = Type_Splash;
757 else if (val[i] == prop_atoms.net_wm_window_type_dialog)
758 self->type = Type_Dialog;
759 else if (val[i] == prop_atoms.net_wm_window_type_normal)
760 self->type = Type_Normal;
761 else if (val[i] == prop_atoms.kde_net_wm_window_type_override) {
762 /* prevent this window from getting any decor or
764 self->mwmhints.flags &= (MwmFlag_Functions |
765 MwmFlag_Decorations);
766 self->mwmhints.decorations = 0;
767 self->mwmhints.functions = 0;
769 if (self->type != (WindowType) -1)
770 break; /* grab the first legit type */
775 if (self->type == (WindowType) -1) {
776 /*the window type hint was not set, which means we either classify
777 ourself as a normal window or a dialog, depending on if we are a
780 self->type = Type_Dialog;
782 self->type = Type_Normal;
785 /* this makes sure that these windows appear on all desktops */
786 if (self->type == Type_Desktop)
787 self->desktop = DESKTOP_ALL;
790 void client_update_protocols(Client *self)
795 self->focus_notify = FALSE;
796 self->delete_window = FALSE;
798 if (PROP_GETA32(self->window, wm_protocols, atom, &proto, &num_return)) {
799 for (i = 0; i < num_return; ++i) {
800 if (proto[i] == prop_atoms.wm_delete_window) {
801 /* this means we can request the window to close */
802 self->delete_window = TRUE;
803 } else if (proto[i] == prop_atoms.wm_take_focus)
804 /* if this protocol is requested, then the window will be
805 notified whenever we want it to receive focus */
806 self->focus_notify = TRUE;
812 static void client_get_gravity(Client *self)
814 XWindowAttributes wattrib;
817 ret = XGetWindowAttributes(ob_display, self->window, &wattrib);
818 g_assert(ret != BadWindow);
819 self->gravity = wattrib.win_gravity;
822 void client_update_normal_hints(Client *self)
826 int oldgravity = self->gravity;
829 self->min_ratio = 0.0f;
830 self->max_ratio = 0.0f;
831 SIZE_SET(self->size_inc, 1, 1);
832 SIZE_SET(self->base_size, 0, 0);
833 SIZE_SET(self->min_size, 0, 0);
834 SIZE_SET(self->max_size, G_MAXINT, G_MAXINT);
836 /* get the hints from the window */
837 if (XGetWMNormalHints(ob_display, self->window, &size, &ret)) {
838 self->positioned = !!(size.flags & (PPosition|USPosition));
840 if (size.flags & PWinGravity) {
841 self->gravity = size.win_gravity;
843 /* if the client has a frame, i.e. has already been mapped and
844 is changing its gravity */
845 if (self->frame && self->gravity != oldgravity) {
846 /* move our idea of the client's position based on its new
848 self->area.x = self->frame->area.x;
849 self->area.y = self->frame->area.y;
850 frame_frame_gravity(self->frame, &self->area.x, &self->area.y);
854 if (size.flags & PAspect) {
855 if (size.min_aspect.y)
856 self->min_ratio = (float)size.min_aspect.x / size.min_aspect.y;
857 if (size.max_aspect.y)
858 self->max_ratio = (float)size.max_aspect.x / size.max_aspect.y;
861 if (size.flags & PMinSize)
862 SIZE_SET(self->min_size, size.min_width, size.min_height);
864 if (size.flags & PMaxSize)
865 SIZE_SET(self->max_size, size.max_width, size.max_height);
867 if (size.flags & PBaseSize)
868 SIZE_SET(self->base_size, size.base_width, size.base_height);
870 if (size.flags & PResizeInc)
871 SIZE_SET(self->size_inc, size.width_inc, size.height_inc);
875 void client_setup_decor_and_functions(Client *self)
877 /* start with everything (cept fullscreen) */
878 self->decorations = Decor_Titlebar | Decor_Handle | Decor_Border |
879 Decor_Icon | Decor_AllDesktops | Decor_Iconify | Decor_Maximize |
881 self->functions = Func_Resize | Func_Move | Func_Iconify | Func_Maximize |
883 if (self->delete_window) {
884 self->decorations |= Decor_Close;
885 self->functions |= Func_Close;
888 if (!(self->min_size.width < self->max_size.width ||
889 self->min_size.height < self->max_size.height)) {
890 self->decorations &= ~(Decor_Maximize | Decor_Handle);
891 self->functions &= ~(Func_Resize | Func_Maximize);
894 switch (self->type) {
896 /* normal windows retain all of the possible decorations and
897 functionality, and are the only windows that you can fullscreen */
898 self->functions |= Func_Fullscreen;
903 /* these windows cannot be maximized */
904 self->decorations &= ~Decor_Maximize;
905 self->functions &= ~Func_Maximize;
910 /* these windows get less functionality */
911 self->decorations &= ~(Decor_Iconify | Decor_Handle);
912 self->functions &= ~(Func_Iconify | Func_Resize);
918 /* none of these windows are manipulated by the window manager */
919 self->decorations = 0;
924 /* Mwm Hints are applied subtractively to what has already been chosen for
925 decor and functionality */
926 if (self->mwmhints.flags & MwmFlag_Decorations) {
927 if (! (self->mwmhints.decorations & MwmDecor_All)) {
928 if (! (self->mwmhints.decorations & MwmDecor_Border))
929 self->decorations &= ~Decor_Border;
930 if (! (self->mwmhints.decorations & MwmDecor_Handle))
931 self->decorations &= ~Decor_Handle;
932 if (! (self->mwmhints.decorations & MwmDecor_Title))
933 self->decorations &= ~Decor_Titlebar;
934 if (! (self->mwmhints.decorations & MwmDecor_Iconify))
935 self->decorations &= ~Decor_Iconify;
936 if (! (self->mwmhints.decorations & MwmDecor_Maximize))
937 self->decorations &= ~Decor_Maximize;
941 if (self->mwmhints.flags & MwmFlag_Functions) {
942 if (! (self->mwmhints.functions & MwmFunc_All)) {
943 if (! (self->mwmhints.functions & MwmFunc_Resize))
944 self->functions &= ~Func_Resize;
945 if (! (self->mwmhints.functions & MwmFunc_Move))
946 self->functions &= ~Func_Move;
947 if (! (self->mwmhints.functions & MwmFunc_Iconify))
948 self->functions &= ~Func_Iconify;
949 if (! (self->mwmhints.functions & MwmFunc_Maximize))
950 self->functions &= ~Func_Maximize;
951 /* dont let mwm hints kill the close button
952 if (! (self->mwmhints.functions & MwmFunc_Close))
953 self->functions &= ~Func_Close; */
957 /* can't maximize without moving/resizing */
958 if (!((self->functions & Func_Move) && (self->functions & Func_Resize)))
959 self->functions &= ~(Func_Maximize | Func_Fullscreen);
961 /* finally, user specified disabled decorations are applied to subtract
963 if (self->disabled_decorations & Decor_Titlebar)
964 self->decorations &= ~Decor_Titlebar;
965 if (self->disabled_decorations & Decor_Handle)
966 self->decorations &= ~Decor_Handle;
967 if (self->disabled_decorations & Decor_Border)
968 self->decorations &= ~Decor_Border;
969 if (self->disabled_decorations & Decor_Iconify)
970 self->decorations &= ~Decor_Iconify;
971 if (self->disabled_decorations & Decor_Maximize)
972 self->decorations &= ~Decor_Maximize;
973 if (self->disabled_decorations & Decor_AllDesktops)
974 self->decorations &= ~Decor_AllDesktops;
975 if (self->disabled_decorations & Decor_Shade)
976 self->decorations &= ~Decor_Shade;
977 if (self->disabled_decorations & Decor_Close)
978 self->decorations &= ~Decor_Close;
980 /* if we don't have a titlebar, then we cannot shade! */
981 if (!(self->decorations & Decor_Titlebar))
982 self->functions &= ~Func_Shade;
984 /* now we need to check against rules for the client's current state */
985 if (self->fullscreen) {
986 self->functions &= (Func_Close | Func_Fullscreen | Func_Iconify);
987 self->decorations = 0;
990 client_change_allowed_actions(self);
993 /* change the decors on the frame, and with more/less decorations,
994 we may also need to be repositioned */
995 frame_adjust_area(self->frame, TRUE, TRUE);
996 /* with new decor, the window's maximized size may change */
997 client_remaximize(self);
1001 static void client_change_allowed_actions(Client *self)
1006 actions[num++] = prop_atoms.net_wm_action_change_desktop;
1008 if (self->functions & Func_Shade)
1009 actions[num++] = prop_atoms.net_wm_action_shade;
1010 if (self->functions & Func_Close)
1011 actions[num++] = prop_atoms.net_wm_action_close;
1012 if (self->functions & Func_Move)
1013 actions[num++] = prop_atoms.net_wm_action_move;
1014 if (self->functions & Func_Iconify)
1015 actions[num++] = prop_atoms.net_wm_action_minimize;
1016 if (self->functions & Func_Resize)
1017 actions[num++] = prop_atoms.net_wm_action_resize;
1018 if (self->functions & Func_Fullscreen)
1019 actions[num++] = prop_atoms.net_wm_action_fullscreen;
1020 if (self->functions & Func_Maximize) {
1021 actions[num++] = prop_atoms.net_wm_action_maximize_horz;
1022 actions[num++] = prop_atoms.net_wm_action_maximize_vert;
1025 PROP_SETA32(self->window, net_wm_allowed_actions, atom, actions, num);
1027 /* make sure the window isn't breaking any rules now */
1029 if (!(self->functions & Func_Shade) && self->shaded) {
1030 if (self->frame) client_shade(self, FALSE);
1031 else self->shaded = FALSE;
1033 if (!(self->functions & Func_Iconify) && self->iconic) {
1034 g_message("UNSETTING ICONIC");
1035 if (self->frame) client_iconify(self, FALSE, TRUE);
1036 else self->iconic = FALSE;
1038 if (!(self->functions & Func_Fullscreen) && self->fullscreen) {
1039 if (self->frame) client_fullscreen(self, FALSE, TRUE);
1040 else self->fullscreen = FALSE;
1042 if (!(self->functions & Func_Maximize) && (self->max_horz ||
1044 if (self->frame) client_maximize(self, FALSE, 0, TRUE);
1045 else self->max_vert = self->max_horz = FALSE;
1049 void client_remaximize(Client *self)
1052 if (self->max_horz && self->max_vert)
1054 else if (self->max_horz)
1056 else if (self->max_vert)
1059 return; /* not maximized */
1060 self->max_horz = self->max_vert = FALSE;
1061 client_maximize(self, TRUE, dir, FALSE);
1064 void client_update_wmhints(Client *self)
1067 gboolean ur = FALSE;
1070 /* assume a window takes input if it doesnt specify */
1071 self->can_focus = TRUE;
1073 if ((hints = XGetWMHints(ob_display, self->window)) != NULL) {
1074 if (hints->flags & InputHint)
1075 self->can_focus = hints->input;
1077 /* only do this when first managing the window *AND* when we aren't
1079 if (ob_state != State_Starting && self->frame == NULL)
1080 if (hints->flags & StateHint)
1081 self->iconic = hints->initial_state == IconicState;
1083 if (hints->flags & XUrgencyHint)
1086 if (!(hints->flags & WindowGroupHint))
1087 hints->window_group = None;
1089 /* did the group state change? */
1090 if (hints->window_group !=
1091 (self->group ? self->group->leader : None)) {
1092 /* remove from the old group if there was one */
1093 if (self->group != NULL) {
1094 /* remove transients of the group */
1095 for (it = self->group->members; it; it = it->next)
1096 if (it->data != self &&
1097 ((Client*)it->data)->transient_for == TRAN_GROUP) {
1098 self->transients = g_slist_remove(self->transients,
1101 group_remove(self->group, self);
1104 if (hints->window_group != None) {
1105 self->group = group_add(hints->window_group, self);
1107 /* add other transients of the group that are already
1109 for (it = self->group->members; it; it = it->next)
1110 if (it->data != self &&
1111 ((Client*)it->data)->transient_for == TRAN_GROUP)
1112 self->transients = g_slist_append(self->transients,
1116 /* because the self->transient flag wont change from this call,
1117 we don't need to update the window's type and such, only its
1118 transient_for, and the transients lists of other windows in
1119 the group may be affected */
1120 client_update_transient_for(self);
1123 client_update_kwm_icon(self);
1124 /* try get the kwm icon first, this is a fallback only */
1125 if (self->pixmap_icon == None) {
1126 if (hints->flags & IconPixmapHint) {
1127 if (self->pixmap_icon == None) {
1128 self->pixmap_icon = hints->icon_pixmap;
1129 if (hints->flags & IconMaskHint)
1130 self->pixmap_icon_mask = hints->icon_mask;
1132 self->pixmap_icon_mask = None;
1135 frame_adjust_icon(self->frame);
1143 if (ur != self->urgent) {
1145 g_message("Urgent Hint for 0x%lx: %s", self->window,
1147 /* fire the urgent callback if we're mapped, otherwise, wait until
1148 after we're mapped */
1150 dispatch_client(Event_Client_Urgent, self, self->urgent, 0);
1154 void client_update_title(Client *self)
1158 g_free(self->title);
1161 if (!PROP_GETS(self->window, net_wm_name, utf8, &data))
1162 /* try old x stuff */
1163 if (!PROP_GETS(self->window, wm_name, locale, &data))
1164 data = g_strdup("Unnamed Window");
1166 /* look for duplicates and append a number */
1168 PROP_SETS(self->window, net_wm_visible_name, data);
1173 frame_adjust_title(self->frame);
1176 void client_update_icon_title(Client *self)
1180 g_free(self->icon_title);
1183 if (!PROP_GETS(self->window, net_wm_icon_name, utf8, &data))
1184 /* try old x stuff */
1185 if (!PROP_GETS(self->window, wm_icon_name, locale, &data))
1186 data = g_strdup("Unnamed Window");
1188 PROP_SETS(self->window, net_wm_visible_icon_name, data);
1190 self->icon_title = data;
1193 void client_update_class(Client *self)
1198 if (self->name) g_free(self->name);
1199 if (self->class) g_free(self->class);
1200 if (self->role) g_free(self->role);
1202 self->name = self->class = self->role = NULL;
1204 if (PROP_GETSS(self->window, wm_class, locale, &data)) {
1206 self->name = g_strdup(data[0]);
1208 self->class = g_strdup(data[1]);
1213 if (PROP_GETS(self->window, wm_window_role, locale, &s))
1214 self->role = g_strdup(s);
1216 if (self->name == NULL) self->name = g_strdup("");
1217 if (self->class == NULL) self->class = g_strdup("");
1218 if (self->role == NULL) self->role = g_strdup("");
1221 void client_update_strut(Client *self)
1226 if (!PROP_GETA32(self->window, net_wm_strut, cardinal, &data, &num)) {
1227 STRUT_SET(self->strut, 0, 0, 0, 0);
1230 STRUT_SET(self->strut, data[0], data[2], data[1], data[3]);
1232 STRUT_SET(self->strut, 0, 0, 0, 0);
1236 /* updating here is pointless while we're being mapped cuz we're not in
1237 the client list yet */
1239 screen_update_struts();
1242 void client_update_icons(Client *self)
1249 for (j = 0; j < self->nicons; ++j)
1250 g_free(self->icons[j].data);
1251 if (self->nicons > 0)
1252 g_free(self->icons);
1255 if (PROP_GETA32(self->window, net_wm_icon, cardinal, &data, &num)) {
1256 /* figure out how many valid icons are in here */
1258 while (num - i > 2) {
1266 self->icons = g_new(Icon, self->nicons);
1268 /* store the icons */
1270 for (j = 0; j < self->nicons; ++j) {
1271 w = self->icons[j].width = data[i++];
1272 h = self->icons[j].height = data[i++];
1273 self->icons[j].data =
1274 g_memdup(&data[i], w * h * sizeof(gulong));
1283 frame_adjust_icon(self->frame);
1286 void client_update_kwm_icon(Client *self)
1291 if (!PROP_GETA32(self->window, kwm_win_icon, kwm_win_icon, &data, &num)) {
1292 self->pixmap_icon = self->pixmap_icon_mask = None;
1295 self->pixmap_icon = data[0];
1296 self->pixmap_icon_mask = data[1];
1298 self->pixmap_icon = self->pixmap_icon_mask = None;
1302 frame_adjust_icon(self->frame);
1305 static void client_change_state(Client *self)
1308 guint32 netstate[10];
1311 state[0] = self->wmstate;
1313 PROP_SETA32(self->window, wm_state, wm_state, state, 2);
1317 netstate[num++] = prop_atoms.net_wm_state_modal;
1319 netstate[num++] = prop_atoms.net_wm_state_shaded;
1321 netstate[num++] = prop_atoms.net_wm_state_hidden;
1322 if (self->skip_taskbar)
1323 netstate[num++] = prop_atoms.net_wm_state_skip_taskbar;
1324 if (self->skip_pager)
1325 netstate[num++] = prop_atoms.net_wm_state_skip_pager;
1326 if (self->fullscreen)
1327 netstate[num++] = prop_atoms.net_wm_state_fullscreen;
1329 netstate[num++] = prop_atoms.net_wm_state_maximized_vert;
1331 netstate[num++] = prop_atoms.net_wm_state_maximized_horz;
1333 netstate[num++] = prop_atoms.net_wm_state_above;
1335 netstate[num++] = prop_atoms.net_wm_state_below;
1336 PROP_SETA32(self->window, net_wm_state, atom, netstate, num);
1338 client_calc_layer(self);
1341 frame_adjust_state(self->frame);
1344 static Client *search_focus_tree(Client *node, Client *skip)
1349 for (it = node->transients; it != NULL; it = it->next) {
1350 Client *c = it->data;
1351 if (c == skip) continue; /* circular? */
1352 if ((ret = search_focus_tree(c, skip))) return ret;
1353 if (client_focused(c)) return c;
1358 static void calc_recursive(Client *self, StackLayer l, gboolean raised)
1366 for (it = self->transients; it; it = it->next)
1367 calc_recursive(it->data, l, raised ? raised : l != old);
1369 if (!raised && l != old)
1371 stacking_raise(self);
1374 void client_calc_layer(Client *self)
1379 /* transients take on the layer of their parents */
1380 if (self->transient_for) {
1381 if (self->transient_for != TRAN_GROUP) {
1382 self = self->transient_for;
1386 for (it = self->group->members; it; it = it->next)
1387 if (it->data != self &&
1388 ((Client*)it->data)->transient_for != TRAN_GROUP) {
1395 /* is us or one of our transients focused? */
1396 if (client_focused(self))
1398 else if (search_focus_tree(self, self))
1403 if (self->iconic) l = Layer_Icon;
1404 /* fullscreen windows are only in the fullscreen layer while focused */
1405 else if (self->fullscreen && f) l = Layer_Fullscreen;
1406 else if (self->type == Type_Desktop) l = Layer_Desktop;
1407 else if (self->type == Type_Dock) {
1408 if (!self->below) l = Layer_Top;
1409 else l = Layer_Normal;
1411 else if (self->above) l = Layer_Above;
1412 else if (self->below) l = Layer_Below;
1413 else l = Layer_Normal;
1415 calc_recursive(self, l, FALSE);
1418 gboolean client_should_show(Client *self)
1420 if (self->iconic) return FALSE;
1421 else if (!(self->desktop == screen_desktop ||
1422 self->desktop == DESKTOP_ALL)) return FALSE;
1423 else if (client_normal(self) && screen_showing_desktop) return FALSE;
1428 static void client_showhide(Client *self)
1431 if (client_should_show(self))
1432 frame_show(self->frame);
1434 frame_hide(self->frame);
1437 gboolean client_normal(Client *self) {
1438 return ! (self->type == Type_Desktop || self->type == Type_Dock ||
1439 self->type == Type_Splash);
1442 static void client_apply_startup_state(Client *self)
1444 /* these are in a carefully crafted order.. */
1447 self->iconic = FALSE;
1448 client_iconify(self, TRUE, FALSE);
1450 if (self->fullscreen) {
1451 self->fullscreen = FALSE;
1452 client_fullscreen(self, TRUE, FALSE);
1455 self->shaded = FALSE;
1456 client_shade(self, TRUE);
1459 dispatch_client(Event_Client_Urgent, self, self->urgent, 0);
1461 if (self->max_vert && self->max_horz) {
1462 self->max_vert = self->max_horz = FALSE;
1463 client_maximize(self, TRUE, 0, FALSE);
1464 } else if (self->max_vert) {
1465 self->max_vert = FALSE;
1466 client_maximize(self, TRUE, 2, FALSE);
1467 } else if (self->max_horz) {
1468 self->max_horz = FALSE;
1469 client_maximize(self, TRUE, 1, FALSE);
1472 /* nothing to do for the other states:
1481 void client_configure(Client *self, Corner anchor, int x, int y, int w, int h,
1482 gboolean user, gboolean final)
1484 gboolean moved = FALSE, resized = FALSE;
1486 /* gets the frame's position */
1487 frame_client_gravity(self->frame, &x, &y);
1489 /* these positions are frame positions, not client positions */
1491 /* set the size and position if fullscreen */
1492 if (self->fullscreen) {
1495 w = screen_physical_size.width;
1496 h = screen_physical_size.height;
1497 user = FALSE; /* ignore that increment etc shit when in fullscreen */
1499 /* set the size and position if maximized */
1500 if (self->max_horz) {
1501 x = screen_area(self->desktop)->x - self->frame->size.left;
1502 w = screen_area(self->desktop)->width;
1504 if (self->max_vert) {
1505 y = screen_area(self->desktop)->y;
1506 h = screen_area(self->desktop)->height -
1507 self->frame->size.top - self->frame->size.bottom;
1511 /* gets the client's position */
1512 frame_frame_gravity(self->frame, &x, &y);
1514 /* these override the above states! if you cant move you can't move! */
1516 if (!(self->functions & Func_Move)) {
1520 if (!(self->functions & Func_Resize)) {
1521 w = self->area.width;
1522 h = self->area.height;
1526 if (!(w == self->area.width && h == self->area.height)) {
1527 w -= self->base_size.width;
1528 h -= self->base_size.height;
1531 /* for interactive resizing. have to move half an increment in each
1534 /* how far we are towards the next size inc */
1535 int mw = w % self->size_inc.width;
1536 int mh = h % self->size_inc.height;
1538 int aw = self->size_inc.width / 2;
1539 int ah = self->size_inc.height / 2;
1540 /* don't let us move into a new size increment */
1541 if (mw + aw >= self->size_inc.width)
1542 aw = self->size_inc.width - mw - 1;
1543 if (mh + ah >= self->size_inc.height)
1544 ah = self->size_inc.height - mh - 1;
1548 /* if this is a user-requested resize, then check against min/max
1549 sizes and aspect ratios */
1551 /* smaller than min size or bigger than max size? */
1552 if (w > self->max_size.width) w = self->max_size.width;
1553 if (w < self->min_size.width) w = self->min_size.width;
1554 if (h > self->max_size.height) h = self->max_size.height;
1555 if (h < self->min_size.height) h = self->min_size.height;
1557 /* adjust the height ot match the width for the aspect ratios */
1558 if (self->min_ratio)
1559 if (h * self->min_ratio > w) h = (int)(w / self->min_ratio);
1560 if (self->max_ratio)
1561 if (h * self->max_ratio < w) h = (int)(w / self->max_ratio);
1564 /* keep to the increments */
1565 w /= self->size_inc.width;
1566 h /= self->size_inc.height;
1568 /* you cannot resize to nothing */
1572 /* store the logical size */
1573 SIZE_SET(self->logical_size, w, h);
1575 w *= self->size_inc.width;
1576 h *= self->size_inc.height;
1578 w += self->base_size.width;
1579 h += self->base_size.height;
1583 case Corner_TopLeft:
1585 case Corner_TopRight:
1586 x -= w - self->area.width;
1588 case Corner_BottomLeft:
1589 y -= h - self->area.height;
1591 case Corner_BottomRight:
1592 x -= w - self->area.width;
1593 y -= h - self->area.height;
1597 moved = x != self->area.x || y != self->area.y;
1598 resized = w != self->area.width || h != self->area.height;
1600 RECT_SET(self->area, x, y, w, h);
1603 XResizeWindow(ob_display, self->window, w, h);
1605 /* move/resize the frame to match the request */
1607 if (moved || resized)
1608 frame_adjust_area(self->frame, moved, resized);
1610 if (!user || final) {
1612 event.type = ConfigureNotify;
1613 event.xconfigure.display = ob_display;
1614 event.xconfigure.event = self->window;
1615 event.xconfigure.window = self->window;
1617 /* root window coords with border in mind */
1618 event.xconfigure.x = x - self->border_width +
1619 self->frame->size.left;
1620 event.xconfigure.y = y - self->border_width +
1621 self->frame->size.top;
1623 event.xconfigure.width = self->area.width;
1624 event.xconfigure.height = self->area.height;
1625 event.xconfigure.border_width = self->border_width;
1626 event.xconfigure.above = self->frame->plate;
1627 event.xconfigure.override_redirect = FALSE;
1628 XSendEvent(event.xconfigure.display, event.xconfigure.window,
1629 FALSE, StructureNotifyMask, &event);
1634 void client_fullscreen(Client *self, gboolean fs, gboolean savearea)
1638 if (!(self->functions & Func_Fullscreen) || /* can't */
1639 self->fullscreen == fs) return; /* already done */
1641 self->fullscreen = fs;
1642 client_change_state(self); /* change the state hints on the client,
1643 and adjust out layer/stacking */
1647 guint32 dimensions[4];
1648 dimensions[0] = self->area.x;
1649 dimensions[1] = self->area.y;
1650 dimensions[2] = self->area.width;
1651 dimensions[3] = self->area.height;
1653 PROP_SETA32(self->window, openbox_premax, cardinal,
1657 /* these are not actually used cuz client_configure will set them
1658 as appropriate when the window is fullscreened */
1664 /* pick some fallbacks... */
1665 x = screen_area(self->desktop)->x +
1666 screen_area(self->desktop)->width / 4;
1667 y = screen_area(self->desktop)->y +
1668 screen_area(self->desktop)->height / 4;
1669 w = screen_area(self->desktop)->width / 2;
1670 h = screen_area(self->desktop)->height / 2;
1672 if (PROP_GETA32(self->window, openbox_premax, cardinal,
1673 (guint32**)&dimensions, &num)) {
1684 client_setup_decor_and_functions(self);
1686 client_configure(self, Corner_TopLeft, x, y, w, h, TRUE, TRUE);
1688 /* try focus us when we go into fullscreen mode */
1692 void client_iconify(Client *self, gboolean iconic, gboolean curdesk)
1696 /* move up the transient chain as far as possible first if deiconifying */
1698 while (self->transient_for) {
1699 if (self->transient_for != TRAN_GROUP) {
1700 if (self->transient_for->iconic == iconic)
1702 self = self->transient_for;
1706 /* the check for TRAN_GROUP is to prevent an infinate loop with
1707 2 transients of the same group at the head of the group's
1709 for (it = self->group->members; it; it = it->next) {
1710 Client *c = it->data;
1712 if (c != self && c->transient_for->iconic != iconic &&
1713 c->transient_for != TRAN_GROUP) {
1718 if (it == NULL) break;
1722 if (self->iconic == iconic) return; /* nothing to do */
1724 g_message("%sconifying window: 0x%lx", (iconic ? "I" : "Uni"),
1727 self->iconic = iconic;
1730 self->wmstate = IconicState;
1731 self->ignore_unmaps++;
1732 /* we unmap the client itself so that we can get MapRequest events,
1733 and because the ICCCM tells us to! */
1734 XUnmapWindow(ob_display, self->window);
1736 /* update the focus lists.. iconic windows go to the bottom */
1737 focus_order_to_bottom(self);
1740 client_set_desktop(self, screen_desktop, FALSE);
1741 self->wmstate = self->shaded ? IconicState : NormalState;
1742 XMapWindow(ob_display, self->window);
1744 client_change_state(self);
1745 client_showhide(self);
1746 screen_update_struts();
1748 dispatch_client(iconic ? Event_Client_Unmapped : Event_Client_Mapped,
1751 /* iconify all transients */
1752 for (it = self->transients; it != NULL; it = it->next)
1753 if (it->data != self) client_iconify(it->data, iconic, curdesk);
1756 void client_maximize(Client *self, gboolean max, int dir, gboolean savearea)
1760 g_assert(dir == 0 || dir == 1 || dir == 2);
1761 if (!(self->functions & Func_Maximize)) return; /* can't */
1763 /* check if already done */
1765 if (dir == 0 && self->max_horz && self->max_vert) return;
1766 if (dir == 1 && self->max_horz) return;
1767 if (dir == 2 && self->max_vert) return;
1769 if (dir == 0 && !self->max_horz && !self->max_vert) return;
1770 if (dir == 1 && !self->max_horz) return;
1771 if (dir == 2 && !self->max_vert) return;
1774 /* work with the frame's coords */
1775 x = self->frame->area.x;
1776 y = self->frame->area.y;
1777 w = self->area.width;
1778 h = self->area.height;
1782 gint32 dimensions[4];
1791 /* get the property off the window and use it for the dimensions
1792 we are already maxed on */
1793 if (PROP_GETA32(self->window, openbox_premax, cardinal,
1794 (guint32**)&readdim, &num)) {
1796 if (self->max_horz) {
1797 dimensions[0] = readdim[0];
1798 dimensions[2] = readdim[2];
1800 if (self->max_vert) {
1801 dimensions[1] = readdim[1];
1802 dimensions[3] = readdim[3];
1808 PROP_SETA32(self->window, openbox_premax, cardinal,
1809 (guint32*)dimensions, 4);
1815 /* pick some fallbacks... */
1816 if (dir == 0 || dir == 1) { /* horz */
1817 x = screen_area(self->desktop)->x +
1818 screen_area(self->desktop)->width / 4;
1819 w = screen_area(self->desktop)->width / 2;
1821 if (dir == 0 || dir == 2) { /* vert */
1822 y = screen_area(self->desktop)->y +
1823 screen_area(self->desktop)->height / 4;
1824 h = screen_area(self->desktop)->height / 2;
1827 if (PROP_GETA32(self->window, openbox_premax, cardinal,
1828 (guint32**)&dimensions, &num)) {
1830 if (dir == 0 || dir == 1) { /* horz */
1834 if (dir == 0 || dir == 2) { /* vert */
1843 if (dir == 0 || dir == 1) /* horz */
1844 self->max_horz = max;
1845 if (dir == 0 || dir == 2) /* vert */
1846 self->max_vert = max;
1848 if (!self->max_horz && !self->max_vert)
1849 PROP_ERASE(self->window, openbox_premax);
1851 client_change_state(self); /* change the state hints on the client */
1853 /* figure out where the client should be going */
1854 frame_frame_gravity(self->frame, &x, &y);
1855 client_configure(self, Corner_TopLeft, x, y, w, h, TRUE, TRUE);
1858 void client_shade(Client *self, gboolean shade)
1860 if ((!(self->functions & Func_Shade) && shade) || /* can't shade */
1861 self->shaded == shade) return; /* already done */
1863 /* when we're iconic, don't change the wmstate */
1865 self->wmstate = shade ? IconicState : NormalState;
1866 self->shaded = shade;
1867 client_change_state(self);
1868 /* resize the frame to just the titlebar */
1869 frame_adjust_area(self->frame, FALSE, FALSE);
1872 void client_close(Client *self)
1876 if (!(self->functions & Func_Close)) return;
1879 XXX: itd be cool to do timeouts and shit here for killing the client's
1881 like... if the window is around after 5 seconds, then the close button
1882 turns a nice red, and if this function is called again, the client is
1886 ce.xclient.type = ClientMessage;
1887 ce.xclient.message_type = prop_atoms.wm_protocols;
1888 ce.xclient.display = ob_display;
1889 ce.xclient.window = self->window;
1890 ce.xclient.format = 32;
1891 ce.xclient.data.l[0] = prop_atoms.wm_delete_window;
1892 ce.xclient.data.l[1] = event_lasttime;
1893 ce.xclient.data.l[2] = 0l;
1894 ce.xclient.data.l[3] = 0l;
1895 ce.xclient.data.l[4] = 0l;
1896 XSendEvent(ob_display, self->window, FALSE, NoEventMask, &ce);
1899 void client_kill(Client *self)
1901 XKillClient(ob_display, self->window);
1904 void client_set_desktop(Client *self, guint target, gboolean donthide)
1908 if (target == self->desktop) return;
1910 g_message("Setting desktop %u", target);
1912 g_assert(target < screen_num_desktops || target == DESKTOP_ALL);
1914 /* remove from the old desktop(s) */
1915 focus_order_remove(self);
1917 old = self->desktop;
1918 self->desktop = target;
1919 PROP_SET32(self->window, net_wm_desktop, cardinal, target);
1920 /* the frame can display the current desktop state */
1921 frame_adjust_state(self->frame);
1922 /* 'move' the window to the new desktop */
1924 client_showhide(self);
1925 /* raise if it was not already on the desktop */
1926 if (old != DESKTOP_ALL)
1927 stacking_raise(self);
1928 screen_update_struts();
1930 /* add to the new desktop(s) */
1931 if (config_focus_new)
1932 focus_order_to_top(self);
1934 focus_order_to_bottom(self);
1936 dispatch_client(Event_Client_Desktop, self, target, old);
1939 static Client *search_modal_tree(Client *node, Client *skip)
1944 for (it = node->transients; it != NULL; it = it->next) {
1945 Client *c = it->data;
1946 if (c == skip) continue; /* circular? */
1947 if ((ret = search_modal_tree(c, skip))) return ret;
1948 if (c->modal) return c;
1953 Client *client_find_modal_child(Client *self)
1955 return search_modal_tree(self, self);
1958 gboolean client_validate(Client *self)
1962 XSync(ob_display, FALSE); /* get all events on the server */
1964 if (XCheckTypedWindowEvent(ob_display, self->window, DestroyNotify, &e) ||
1965 XCheckTypedWindowEvent(ob_display, self->window, UnmapNotify, &e)) {
1966 XPutBackEvent(ob_display, &e);
1973 void client_set_wm_state(Client *self, long state)
1975 if (state == self->wmstate) return; /* no change */
1979 client_iconify(self, TRUE, TRUE);
1982 client_iconify(self, FALSE, TRUE);
1987 void client_set_state(Client *self, Atom action, long data1, long data2)
1989 gboolean shaded = self->shaded;
1990 gboolean fullscreen = self->fullscreen;
1991 gboolean max_horz = self->max_horz;
1992 gboolean max_vert = self->max_vert;
1995 if (!(action == prop_atoms.net_wm_state_add ||
1996 action == prop_atoms.net_wm_state_remove ||
1997 action == prop_atoms.net_wm_state_toggle))
1998 /* an invalid action was passed to the client message, ignore it */
2001 for (i = 0; i < 2; ++i) {
2002 Atom state = i == 0 ? data1 : data2;
2004 if (!state) continue;
2006 /* if toggling, then pick whether we're adding or removing */
2007 if (action == prop_atoms.net_wm_state_toggle) {
2008 if (state == prop_atoms.net_wm_state_modal)
2009 action = self->modal ? prop_atoms.net_wm_state_remove :
2010 prop_atoms.net_wm_state_add;
2011 else if (state == prop_atoms.net_wm_state_maximized_vert)
2012 action = self->max_vert ? prop_atoms.net_wm_state_remove :
2013 prop_atoms.net_wm_state_add;
2014 else if (state == prop_atoms.net_wm_state_maximized_horz)
2015 action = self->max_horz ? prop_atoms.net_wm_state_remove :
2016 prop_atoms.net_wm_state_add;
2017 else if (state == prop_atoms.net_wm_state_shaded)
2018 action = self->shaded ? prop_atoms.net_wm_state_remove :
2019 prop_atoms.net_wm_state_add;
2020 else if (state == prop_atoms.net_wm_state_skip_taskbar)
2021 action = self->skip_taskbar ?
2022 prop_atoms.net_wm_state_remove :
2023 prop_atoms.net_wm_state_add;
2024 else if (state == prop_atoms.net_wm_state_skip_pager)
2025 action = self->skip_pager ?
2026 prop_atoms.net_wm_state_remove :
2027 prop_atoms.net_wm_state_add;
2028 else if (state == prop_atoms.net_wm_state_fullscreen)
2029 action = self->fullscreen ?
2030 prop_atoms.net_wm_state_remove :
2031 prop_atoms.net_wm_state_add;
2032 else if (state == prop_atoms.net_wm_state_above)
2033 action = self->above ? prop_atoms.net_wm_state_remove :
2034 prop_atoms.net_wm_state_add;
2035 else if (state == prop_atoms.net_wm_state_below)
2036 action = self->below ? prop_atoms.net_wm_state_remove :
2037 prop_atoms.net_wm_state_add;
2040 if (action == prop_atoms.net_wm_state_add) {
2041 if (state == prop_atoms.net_wm_state_modal) {
2042 /* XXX raise here or something? */
2044 } else if (state == prop_atoms.net_wm_state_maximized_vert) {
2046 } else if (state == prop_atoms.net_wm_state_maximized_horz) {
2048 } else if (state == prop_atoms.net_wm_state_shaded) {
2050 } else if (state == prop_atoms.net_wm_state_skip_taskbar) {
2051 self->skip_taskbar = TRUE;
2052 } else if (state == prop_atoms.net_wm_state_skip_pager) {
2053 self->skip_pager = TRUE;
2054 } else if (state == prop_atoms.net_wm_state_fullscreen) {
2056 } else if (state == prop_atoms.net_wm_state_above) {
2058 } else if (state == prop_atoms.net_wm_state_below) {
2062 } else { /* action == prop_atoms.net_wm_state_remove */
2063 if (state == prop_atoms.net_wm_state_modal) {
2064 self->modal = FALSE;
2065 } else if (state == prop_atoms.net_wm_state_maximized_vert) {
2067 } else if (state == prop_atoms.net_wm_state_maximized_horz) {
2069 } else if (state == prop_atoms.net_wm_state_shaded) {
2071 } else if (state == prop_atoms.net_wm_state_skip_taskbar) {
2072 self->skip_taskbar = FALSE;
2073 } else if (state == prop_atoms.net_wm_state_skip_pager) {
2074 self->skip_pager = FALSE;
2075 } else if (state == prop_atoms.net_wm_state_fullscreen) {
2077 } else if (state == prop_atoms.net_wm_state_above) {
2078 self->above = FALSE;
2079 } else if (state == prop_atoms.net_wm_state_below) {
2080 self->below = FALSE;
2084 if (max_horz != self->max_horz || max_vert != self->max_vert) {
2085 if (max_horz != self->max_horz && max_vert != self->max_vert) {
2087 if (max_horz == max_vert) { /* both going the same way */
2088 client_maximize(self, max_horz, 0, TRUE);
2090 client_maximize(self, max_horz, 1, TRUE);
2091 client_maximize(self, max_vert, 2, TRUE);
2095 if (max_horz != self->max_horz)
2096 client_maximize(self, max_horz, 1, TRUE);
2098 client_maximize(self, max_vert, 2, TRUE);
2101 /* change fullscreen state before shading, as it will affect if the window
2103 if (fullscreen != self->fullscreen)
2104 client_fullscreen(self, fullscreen, TRUE);
2105 if (shaded != self->shaded)
2106 client_shade(self, shaded);
2107 client_calc_layer(self);
2108 client_change_state(self); /* change the hint to relect these changes */
2111 Client *client_focus_target(Client *self)
2115 /* if we have a modal child, then focus it, not us */
2116 child = client_find_modal_child(self);
2117 if (child) return child;
2121 gboolean client_focus(Client *self)
2125 /* choose the correct target */
2126 self = client_focus_target(self);
2128 if (self->desktop != DESKTOP_ALL && self->desktop != screen_desktop) {
2129 /* update the focus lists */
2130 focus_order_to_top(self);
2134 if (!((self->can_focus || self->focus_notify) &&
2135 (self->desktop == screen_desktop ||
2136 self->desktop == DESKTOP_ALL) &&
2140 /* do a check to see if the window has already been unmapped or destroyed
2141 do this intelligently while watching out for unmaps we've generated
2142 (ignore_unmaps > 0) */
2143 if (XCheckTypedWindowEvent(ob_display, self->window,
2144 DestroyNotify, &ev)) {
2145 XPutBackEvent(ob_display, &ev);
2148 while (XCheckTypedWindowEvent(ob_display, self->window,
2149 UnmapNotify, &ev)) {
2150 if (self->ignore_unmaps) {
2151 self->ignore_unmaps--;
2153 XPutBackEvent(ob_display, &ev);
2158 if (self->can_focus)
2159 /* RevertToPointerRoot causes much more headache than RevertToNone, so
2160 I choose to use it always, hopefully to find errors quicker, if any
2161 are left. (I hate X. I hate focus events.) */
2162 XSetInputFocus(ob_display, self->window, RevertToPointerRoot,
2165 if (self->focus_notify) {
2167 ce.xclient.type = ClientMessage;
2168 ce.xclient.message_type = prop_atoms.wm_protocols;
2169 ce.xclient.display = ob_display;
2170 ce.xclient.window = self->window;
2171 ce.xclient.format = 32;
2172 ce.xclient.data.l[0] = prop_atoms.wm_take_focus;
2173 ce.xclient.data.l[1] = event_lasttime;
2174 ce.xclient.data.l[2] = 0l;
2175 ce.xclient.data.l[3] = 0l;
2176 ce.xclient.data.l[4] = 0l;
2177 XSendEvent(ob_display, self->window, FALSE, NoEventMask, &ce);
2181 g_message("%sively focusing %lx at %d", (self->can_focus ? "act" : "pass"),
2186 /* Cause the FocusIn to come back to us. Important for desktop switches,
2187 since otherwise we'll have no FocusIn on the queue and send it off to
2188 the focus_backup. */
2189 XSync(ob_display, FALSE);
2193 void client_unfocus(Client *self)
2195 g_assert(focus_client == self);
2197 g_message("client_unfocus for %lx", self->window);
2199 focus_fallback(Fallback_Unfocusing);
2202 gboolean client_focused(Client *self)
2204 return self == focus_client;
2207 Icon *client_icon(Client *self, int w, int h)
2210 /* si is the smallest image >= req */
2211 /* li is the largest image < req */
2212 unsigned long size, smallest = 0xffffffff, largest = 0, si = 0, li = 0;
2214 if (!self->nicons) return NULL;
2216 for (i = 0; i < self->nicons; ++i) {
2217 size = self->icons[i].width * self->icons[i].height;
2218 if (size < smallest && size >= (unsigned)(w * h)) {
2222 if (size > largest && size <= (unsigned)(w * h)) {
2227 if (largest == 0) /* didnt find one smaller than the requested size */
2228 return &self->icons[si];
2229 return &self->icons[li];