3 #include "moveresize.h"
5 #include "extensions.h"
17 #include <X11/Xutil.h>
19 /*! The event mask to grab on client windows */
20 #define CLIENT_EVENTMASK (PropertyChangeMask | FocusChangeMask | \
23 #define CLIENT_NOPROPAGATEMASK (ButtonPressMask | ButtonReleaseMask | \
26 GList *client_list = NULL;
27 GHashTable *client_map = NULL;
29 static Window *client_startup_stack_order = NULL;
30 static guint client_startup_stack_size = 0;
32 static void client_get_all(Client *self);
33 static void client_toggle_border(Client *self, gboolean show);
34 static void client_get_area(Client *self);
35 static void client_get_desktop(Client *self);
36 static void client_get_state(Client *self);
37 static void client_get_shaped(Client *self);
38 static void client_get_mwm_hints(Client *self);
39 static void client_get_gravity(Client *self);
40 static void client_showhide(Client *self);
41 static void client_change_allowed_actions(Client *self);
42 static void client_change_state(Client *self);
43 static void client_move_onscreen(Client *self);
44 static Client *search_focus_tree(Client *node, Client *skip);
45 static void client_apply_startup_state(Client *self);
46 static Client *search_modal_tree(Client *node, Client *skip);
48 static guint map_hash(Window *w) { return *w; }
49 static gboolean map_key_comp(Window *w1, Window *w2) { return *w1 == *w2; }
53 client_map = g_hash_table_new((GHashFunc)map_hash,
54 (GEqualFunc)map_key_comp);
56 /* save the stacking order on startup! */
57 PROP_GETA32(ob_root, net_client_list_stacking, window,
58 (guint32**)&client_startup_stack_order,
59 &client_startup_stack_size);
64 void client_shutdown()
66 g_hash_table_destroy(client_map);
69 void client_set_list()
71 Window *windows, *win_it;
73 guint size = g_list_length(client_list);
75 /* create an array of the window ids */
77 windows = g_new(Window, size);
79 for (it = client_list; it != NULL; it = it->next, ++win_it)
80 *win_it = ((Client*)it->data)->window;
84 PROP_SETA32(ob_root, net_client_list, window, (guint32*)windows, size);
92 void client_manage_all()
94 unsigned int i, j, nchild;
97 XWindowAttributes attrib;
99 XQueryTree(ob_display, ob_root, &w, &w, &children, &nchild);
101 /* remove all icon windows from the list */
102 for (i = 0; i < nchild; i++) {
103 if (children[i] == None) continue;
104 wmhints = XGetWMHints(ob_display, children[i]);
106 if ((wmhints->flags & IconWindowHint) &&
107 (wmhints->icon_window != children[i]))
108 for (j = 0; j < nchild; j++)
109 if (children[j] == wmhints->icon_window) {
117 for (i = 0; i < nchild; ++i) {
118 if (children[i] == None)
120 if (XGetWindowAttributes(ob_display, children[i], &attrib)) {
121 if (attrib.override_redirect) continue;
123 if (attrib.map_state != IsUnmapped)
124 client_manage(children[i]);
129 /* stack them as they were on startup!
130 why with stacking_lower? Why, because then windows who aren't in the
131 stacking list are on the top where you can see them instead of buried
133 for (i = client_startup_stack_size; i > 0; --i) {
136 w = client_startup_stack_order[i-1];
137 c = g_hash_table_lookup(client_map, &w);
138 if (c) stacking_lower(c);
140 g_free(client_startup_stack_order);
141 client_startup_stack_order = NULL;
142 client_startup_stack_size = 0;
144 if (config_focus_new)
145 focus_fallback(Fallback_NoFocus);
148 void client_manage(Window window)
152 XWindowAttributes attrib;
153 XSetWindowAttributes attrib_set;
154 /* XWMHints *wmhint; */
160 /* check if it has already been unmapped by the time we started mapping
161 the grab does a sync so we don't have to here */
162 if (XCheckTypedWindowEvent(ob_display, window, DestroyNotify, &e) ||
163 XCheckTypedWindowEvent(ob_display, window, UnmapNotify, &e)) {
164 XPutBackEvent(ob_display, &e);
167 return; /* don't manage it */
170 /* make sure it isn't an override-redirect window */
171 if (!XGetWindowAttributes(ob_display, window, &attrib) ||
172 attrib.override_redirect) {
174 return; /* don't manage it */
177 /* /\* is the window a docking app *\/
178 if ((wmhint = XGetWMHints(ob_display, window))) {
179 if ((wmhint->flags & StateHint) &&
180 wmhint->initial_state == WithdrawnState) {
181 /\* XXX: make dock apps work! *\/
189 g_message("Managing window: %lx", window);
191 /* choose the events we want to receive on the CLIENT window */
192 attrib_set.event_mask = CLIENT_EVENTMASK;
193 attrib_set.do_not_propagate_mask = CLIENT_NOPROPAGATEMASK;
194 XChangeWindowAttributes(ob_display, window,
195 CWEventMask|CWDontPropagate, &attrib_set);
198 /* create the Client struct, and populate it from the hints on the
200 self = g_new(Client, 1);
201 self->window = window;
202 client_get_all(self);
204 /* remove the client's border (and adjust re gravity) */
205 client_toggle_border(self, FALSE);
207 /* specify that if we exit, the window should not be destroyed and should
208 be reparented back to root automatically */
209 XChangeSaveSet(ob_display, window, SetModeInsert);
211 /* create the decoration frame for the client window */
212 self->frame = frame_new();
214 frame_grab_client(self->frame, self);
216 client_apply_startup_state(self);
220 client_list = g_list_append(client_list, self);
221 stacking_list = g_list_append(stacking_list, self);
222 g_assert(!g_hash_table_lookup(client_map, &self->window));
223 g_hash_table_insert(client_map, &self->window, self);
225 /* update the focus lists */
226 if (self->desktop == DESKTOP_ALL) {
227 for (i = 0; i < screen_num_desktops; ++i)
228 focus_order[i] = g_list_insert(focus_order[i], self, 1);
231 focus_order[i] = g_list_insert(focus_order[i], self, 1);
234 stacking_raise(self);
236 screen_update_struts();
238 dispatch_client(Event_Client_New, self, 0, 0);
240 client_showhide(self);
242 /* focus the new window? */
243 if (ob_state != State_Starting) {
246 if (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 && !parent && !self->group))) ||
264 (parent && (client_focused(parent) ||
265 search_focus_tree(parent, parent)))) {
270 /* update the list hints */
273 /* make sure the window is visible */
274 client_move_onscreen(self);
276 dispatch_client(Event_Client_Mapped, self, 0, 0);
278 g_message("Managed window 0x%lx", window);
281 void client_unmanage_all()
283 while (client_list != NULL)
284 client_unmanage(client_list->data);
287 void client_unmanage(Client *self)
293 g_message("Unmanaging window: %lx", self->window);
295 dispatch_client(Event_Client_Destroy, self, 0, 0);
296 g_assert(self != NULL);
298 /* remove the window from our save set */
299 XChangeSaveSet(ob_display, self->window, SetModeDelete);
301 /* we dont want events no more */
302 XSelectInput(ob_display, self->window, NoEventMask);
304 frame_hide(self->frame);
306 client_list = g_list_remove(client_list, self);
307 stacking_list = g_list_remove(stacking_list, self);
308 g_hash_table_remove(client_map, &self->window);
310 /* update the focus lists */
311 if (self->desktop == DESKTOP_ALL) {
312 for (i = 0; i < screen_num_desktops; ++i)
313 focus_order[i] = g_list_remove(focus_order[i], self);
316 focus_order[i] = g_list_remove(focus_order[i], self);
319 /* once the client is out of the list, update the struts to remove it's
321 screen_update_struts();
323 /* tell our parent(s) that we're gone */
324 if (self->transient_for == TRAN_GROUP) { /* transient of group */
327 for (it = self->group->members; it; it = it->next)
328 if (it->data != self)
329 ((Client*)it->data)->transients =
330 g_slist_remove(((Client*)it->data)->transients, self);
331 } else if (self->transient_for) { /* transient of window */
332 self->transient_for->transients =
333 g_slist_remove(self->transient_for->transients, self);
336 /* tell our transients that we're gone */
337 for (it = self->transients; it != NULL; it = it->next) {
338 if (((Client*)it->data)->transient_for != TRAN_GROUP) {
339 ((Client*)it->data)->transient_for = NULL;
340 client_calc_layer(it->data);
344 if (moveresize_client == self)
345 moveresize_end(TRUE);
347 if (focus_client == self) {
350 /* focus the last focused window on the desktop, and ignore enter
351 events from the unmap so it doesnt mess with the focus */
352 while (XCheckTypedEvent(ob_display, EnterNotify, &e));
353 client_unfocus(self);
356 /* remove from its group */
358 group_remove(self->group, self);
362 /* dispatch the unmapped event */
363 dispatch_client(Event_Client_Unmapped, self, 0, 0);
364 g_assert(self != NULL);
366 /* give the client its border back */
367 client_toggle_border(self, TRUE);
369 /* reparent the window out of the frame, and free the frame */
370 frame_release_client(self->frame, self);
373 if (ob_state != State_Exiting) {
374 /* these values should not be persisted across a window
376 prop_erase(self->window, prop_atoms.net_wm_desktop);
377 prop_erase(self->window, prop_atoms.net_wm_state);
379 /* if we're left in an iconic state, the client wont be mapped. this is
380 bad, since we will no longer be managing the window on restart */
382 XMapWindow(ob_display, self->window);
386 g_message("Unmanaged window 0x%lx", self->window);
388 /* free all data allocated in the client struct */
389 g_slist_free(self->transients);
390 for (j = 0; j < self->nicons; ++j)
391 g_free(self->icons[j].data);
392 if (self->nicons > 0)
395 g_free(self->icon_title);
401 /* update the list hints */
405 static void client_move_onscreen(Client *self)
408 int x = self->frame->area.x, y = self->frame->area.y;
410 a = screen_area(self->desktop);
411 if (x >= a->x + a->width - 1)
412 x = a->x + a->width - self->frame->area.width;
413 if (y >= a->y + a->height - 1)
414 y = a->y + a->height - self->frame->area.height;
415 if (x + self->frame->area.width - 1 < a->x)
417 if (y + self->frame->area.height - 1< a->y)
420 frame_frame_gravity(self->frame, &x, &y); /* get where the client
422 client_configure(self , Corner_TopLeft, x, y,
423 self->area.width, self->area.height,
427 static void client_toggle_border(Client *self, gboolean show)
429 /* adjust our idea of where the client is, based on its border. When the
430 border is removed, the client should now be considered to be in a
432 when re-adding the border to the client, the same operation needs to be
434 int oldx = self->area.x, oldy = self->area.y;
435 int x = oldx, y = oldy;
436 switch(self->gravity) {
438 case NorthWestGravity:
440 case SouthWestGravity:
442 case NorthEastGravity:
444 case SouthEastGravity:
445 if (show) x -= self->border_width * 2;
446 else x += self->border_width * 2;
453 if (show) x -= self->border_width;
454 else x += self->border_width;
457 switch(self->gravity) {
459 case NorthWestGravity:
461 case NorthEastGravity:
463 case SouthWestGravity:
465 case SouthEastGravity:
466 if (show) y -= self->border_width * 2;
467 else y += self->border_width * 2;
474 if (show) y -= self->border_width;
475 else y += self->border_width;
482 XSetWindowBorderWidth(ob_display, self->window, self->border_width);
484 /* move the client so it is back it the right spot _with_ its
486 if (x != oldx || y != oldy)
487 XMoveWindow(ob_display, self->window, x, y);
489 XSetWindowBorderWidth(ob_display, self->window, 0);
493 static void client_get_all(Client *self)
495 /* update EVERYTHING!! */
497 self->ignore_unmaps = 0;
501 self->title = self->icon_title = NULL;
502 self->name = self->class = self->role = NULL;
503 self->wmstate = NormalState;
504 self->transient = FALSE;
505 self->transients = NULL;
506 self->transient_for = NULL;
508 self->urgent = FALSE;
509 self->positioned = FALSE;
510 self->disabled_decorations = 0;
514 client_get_area(self);
515 client_update_transient_for(self);
516 client_update_wmhints(self);
517 client_get_desktop(self);
518 client_get_state(self);
519 client_get_shaped(self);
521 client_get_mwm_hints(self);
522 client_get_type(self);/* this can change the mwmhints for special cases */
524 client_update_protocols(self);
526 client_get_gravity(self); /* get the attribute gravity */
527 client_update_normal_hints(self); /* this may override the attribute
530 /* got the type, the mwmhints, the protocols, and the normal hints
531 (min/max sizes), so we're ready to set up the decorations/functions */
532 client_setup_decor_and_functions(self);
534 client_update_title(self);
535 client_update_icon_title(self);
536 client_update_class(self);
537 client_update_strut(self);
538 client_update_icons(self);
539 client_update_kwm_icon(self);
541 client_change_state(self);
544 static void client_get_area(Client *self)
546 XWindowAttributes wattrib;
549 ret = XGetWindowAttributes(ob_display, self->window, &wattrib);
550 g_assert(ret != BadWindow);
552 RECT_SET(self->area, wattrib.x, wattrib.y, wattrib.width, wattrib.height);
553 self->border_width = wattrib.border_width;
556 static void client_get_desktop(Client *self)
560 if (PROP_GET32(self->window, net_wm_desktop, cardinal, &d)) {
561 if (d >= screen_num_desktops && d != DESKTOP_ALL)
562 d = screen_num_desktops - 1;
565 gboolean trdesk = FALSE;
567 if (self->transient_for) {
568 if (self->transient_for != TRAN_GROUP) {
569 self->desktop = self->transient_for->desktop;
574 for (it = self->group->members; it; it = it->next)
575 if (it->data != self &&
576 ((Client*)it->data)->transient_for != TRAN_GROUP) {
577 self->desktop = ((Client*)it->data)->desktop;
584 /* defaults to the current desktop */
585 self->desktop = screen_desktop;
587 /* set the desktop hint, to make sure that it always exists */
588 PROP_SET32(self->window, net_wm_desktop, cardinal, self->desktop);
592 static void client_get_state(Client *self)
597 self->modal = self->shaded = self->max_horz = self->max_vert =
598 self->fullscreen = self->above = self->below = self->iconic =
599 self->skip_taskbar = self->skip_pager = FALSE;
601 if (PROP_GETA32(self->window, net_wm_state, atom, &state, &num)) {
603 for (i = 0; i < num; ++i) {
604 if (state[i] == prop_atoms.net_wm_state_modal)
606 else if (state[i] == prop_atoms.net_wm_state_shaded)
608 else if (state[i] == prop_atoms.net_wm_state_hidden)
610 else if (state[i] == prop_atoms.net_wm_state_skip_taskbar)
611 self->skip_taskbar = TRUE;
612 else if (state[i] == prop_atoms.net_wm_state_skip_pager)
613 self->skip_pager = TRUE;
614 else if (state[i] == prop_atoms.net_wm_state_fullscreen)
615 self->fullscreen = TRUE;
616 else if (state[i] == prop_atoms.net_wm_state_maximized_vert)
617 self->max_vert = TRUE;
618 else if (state[i] == prop_atoms.net_wm_state_maximized_horz)
619 self->max_horz = TRUE;
620 else if (state[i] == prop_atoms.net_wm_state_above)
622 else if (state[i] == prop_atoms.net_wm_state_below)
630 static void client_get_shaped(Client *self)
632 self->shaped = FALSE;
634 if (extensions_shape) {
639 XShapeSelectInput(ob_display, self->window, ShapeNotifyMask);
641 XShapeQueryExtents(ob_display, self->window, &s, &foo,
642 &foo, &ufoo, &ufoo, &foo, &foo, &foo, &ufoo,
644 self->shaped = (s != 0);
649 void client_update_transient_for(Client *self)
654 if (XGetTransientForHint(ob_display, self->window, &t) &&
655 t != self->window) { /* cant be transient to itself! */
656 self->transient = TRUE;
657 c = g_hash_table_lookup(client_map, &t);
658 g_assert(c != self);/* if this happens then we need to check for it*/
660 if (!c && self->group) {
661 /* not transient to a client, see if it is transient for a
663 if (t == self->group->leader ||
666 /* window is a transient for its group! */
671 self->transient = FALSE;
673 /* if anything has changed... */
674 if (c != self->transient_for) {
675 if (self->transient_for == TRAN_GROUP) { /* transient of group */
678 /* remove from old parents */
679 for (it = self->group->members; it; it = it->next)
680 if (it->data != self)
681 ((Client*)it->data)->transients =
682 g_slist_remove(((Client*)it->data)->transients, self);
683 } else if (self->transient_for != NULL) { /* transient of window */
684 /* remove from old parent */
685 self->transient_for->transients =
686 g_slist_remove(self->transient_for->transients, self);
688 self->transient_for = c;
689 if (self->transient_for == TRAN_GROUP) { /* transient of group */
692 /* add to new parents */
693 for (it = self->group->members; it; it = it->next)
694 if (it->data != self)
695 ((Client*)it->data)->transients =
696 g_slist_append(((Client*)it->data)->transients, self);
697 } else if (self->transient_for != NULL) { /* transient of window */
698 /* add to new parent */
699 self->transient_for->transients =
700 g_slist_append(self->transient_for->transients, self);
705 static void client_get_mwm_hints(Client *self)
710 self->mwmhints.flags = 0; /* default to none */
712 if (PROP_GETA32(self->window, motif_wm_hints, motif_wm_hints,
714 if (num >= MWM_ELEMENTS) {
715 self->mwmhints.flags = hints[0];
716 self->mwmhints.functions = hints[1];
717 self->mwmhints.decorations = hints[2];
723 void client_get_type(Client *self)
730 if (PROP_GETA32(self->window, net_wm_window_type, atom, &val, &num)) {
731 /* use the first value that we know about in the array */
732 for (i = 0; i < num; ++i) {
733 if (val[i] == prop_atoms.net_wm_window_type_desktop)
734 self->type = Type_Desktop;
735 else if (val[i] == prop_atoms.net_wm_window_type_dock)
736 self->type = Type_Dock;
737 else if (val[i] == prop_atoms.net_wm_window_type_toolbar)
738 self->type = Type_Toolbar;
739 else if (val[i] == prop_atoms.net_wm_window_type_menu)
740 self->type = Type_Menu;
741 else if (val[i] == prop_atoms.net_wm_window_type_utility)
742 self->type = Type_Utility;
743 else if (val[i] == prop_atoms.net_wm_window_type_splash)
744 self->type = Type_Splash;
745 else if (val[i] == prop_atoms.net_wm_window_type_dialog)
746 self->type = Type_Dialog;
747 else if (val[i] == prop_atoms.net_wm_window_type_normal)
748 self->type = Type_Normal;
749 else if (val[i] == prop_atoms.kde_net_wm_window_type_override) {
750 /* prevent this window from getting any decor or
752 self->mwmhints.flags &= (MwmFlag_Functions |
753 MwmFlag_Decorations);
754 self->mwmhints.decorations = 0;
755 self->mwmhints.functions = 0;
757 if (self->type != (WindowType) -1)
758 break; /* grab the first legit type */
763 if (self->type == (WindowType) -1) {
764 /*the window type hint was not set, which means we either classify
765 ourself as a normal window or a dialog, depending on if we are a
768 self->type = Type_Dialog;
770 self->type = Type_Normal;
773 /* this makes sure that these windows appear on all desktops */
774 if (self->type == Type_Desktop)
775 self->desktop = DESKTOP_ALL;
778 void client_update_protocols(Client *self)
783 self->focus_notify = FALSE;
784 self->delete_window = FALSE;
786 if (PROP_GETA32(self->window, wm_protocols, atom, &proto, &num_return)) {
787 for (i = 0; i < num_return; ++i) {
788 if (proto[i] == prop_atoms.wm_delete_window) {
789 /* this means we can request the window to close */
790 self->delete_window = TRUE;
791 } else if (proto[i] == prop_atoms.wm_take_focus)
792 /* if this protocol is requested, then the window will be
793 notified whenever we want it to receive focus */
794 self->focus_notify = TRUE;
800 static void client_get_gravity(Client *self)
802 XWindowAttributes wattrib;
805 ret = XGetWindowAttributes(ob_display, self->window, &wattrib);
806 g_assert(ret != BadWindow);
807 self->gravity = wattrib.win_gravity;
810 void client_update_normal_hints(Client *self)
814 int oldgravity = self->gravity;
817 self->min_ratio = 0.0f;
818 self->max_ratio = 0.0f;
819 SIZE_SET(self->size_inc, 1, 1);
820 SIZE_SET(self->base_size, 0, 0);
821 SIZE_SET(self->min_size, 0, 0);
822 SIZE_SET(self->max_size, G_MAXINT, G_MAXINT);
824 /* get the hints from the window */
825 if (XGetWMNormalHints(ob_display, self->window, &size, &ret)) {
826 self->positioned = !!(size.flags & (PPosition|USPosition));
828 if (size.flags & PWinGravity) {
829 self->gravity = size.win_gravity;
831 /* if the client has a frame, i.e. has already been mapped and
832 is changing its gravity */
833 if (self->frame && self->gravity != oldgravity) {
834 /* move our idea of the client's position based on its new
836 self->area.x = self->frame->area.x;
837 self->area.y = self->frame->area.y;
838 frame_frame_gravity(self->frame, &self->area.x, &self->area.y);
842 if (size.flags & PAspect) {
843 if (size.min_aspect.y)
844 self->min_ratio = (float)size.min_aspect.x / size.min_aspect.y;
845 if (size.max_aspect.y)
846 self->max_ratio = (float)size.max_aspect.x / size.max_aspect.y;
849 if (size.flags & PMinSize)
850 SIZE_SET(self->min_size, size.min_width, size.min_height);
852 if (size.flags & PMaxSize)
853 SIZE_SET(self->max_size, size.max_width, size.max_height);
855 if (size.flags & PBaseSize)
856 SIZE_SET(self->base_size, size.base_width, size.base_height);
858 if (size.flags & PResizeInc)
859 SIZE_SET(self->size_inc, size.width_inc, size.height_inc);
863 void client_setup_decor_and_functions(Client *self)
865 /* start with everything (cept fullscreen) */
866 self->decorations = Decor_Titlebar | Decor_Handle | Decor_Border |
867 Decor_Icon | Decor_AllDesktops | Decor_Iconify | Decor_Maximize |
869 self->functions = Func_Resize | Func_Move | Func_Iconify | Func_Maximize |
871 if (self->delete_window) {
872 self->decorations |= Decor_Close;
873 self->functions |= Func_Close;
876 if (!(self->min_size.width < self->max_size.width ||
877 self->min_size.height < self->max_size.height)) {
878 self->decorations &= ~(Decor_Maximize | Decor_Handle);
879 self->functions &= ~(Func_Resize | Func_Maximize);
882 switch (self->type) {
884 /* normal windows retain all of the possible decorations and
885 functionality, and are the only windows that you can fullscreen */
886 self->functions |= Func_Fullscreen;
891 /* these windows cannot be maximized */
892 self->decorations &= ~Decor_Maximize;
893 self->functions &= ~Func_Maximize;
898 /* these windows get less functionality */
899 self->decorations &= ~(Decor_Iconify | Decor_Handle);
900 self->functions &= ~(Func_Iconify | Func_Resize);
906 /* none of these windows are manipulated by the window manager */
907 self->decorations = 0;
912 /* Mwm Hints are applied subtractively to what has already been chosen for
913 decor and functionality */
914 if (self->mwmhints.flags & MwmFlag_Decorations) {
915 if (! (self->mwmhints.decorations & MwmDecor_All)) {
916 if (! (self->mwmhints.decorations & MwmDecor_Border))
917 self->decorations &= ~Decor_Border;
918 if (! (self->mwmhints.decorations & MwmDecor_Handle))
919 self->decorations &= ~Decor_Handle;
920 if (! (self->mwmhints.decorations & MwmDecor_Title))
921 self->decorations &= ~Decor_Titlebar;
922 if (! (self->mwmhints.decorations & MwmDecor_Iconify))
923 self->decorations &= ~Decor_Iconify;
924 if (! (self->mwmhints.decorations & MwmDecor_Maximize))
925 self->decorations &= ~Decor_Maximize;
929 if (self->mwmhints.flags & MwmFlag_Functions) {
930 if (! (self->mwmhints.functions & MwmFunc_All)) {
931 if (! (self->mwmhints.functions & MwmFunc_Resize))
932 self->functions &= ~Func_Resize;
933 if (! (self->mwmhints.functions & MwmFunc_Move))
934 self->functions &= ~Func_Move;
935 if (! (self->mwmhints.functions & MwmFunc_Iconify))
936 self->functions &= ~Func_Iconify;
937 if (! (self->mwmhints.functions & MwmFunc_Maximize))
938 self->functions &= ~Func_Maximize;
939 /* dont let mwm hints kill the close button
940 if (! (self->mwmhints.functions & MwmFunc_Close))
941 self->functions &= ~Func_Close; */
945 /* can't maximize without moving/resizing */
946 if (!((self->functions & Func_Move) && (self->functions & Func_Resize)))
947 self->functions &= ~(Func_Maximize | Func_Fullscreen);
949 /* finally, user specified disabled decorations are applied to subtract
951 if (self->disabled_decorations & Decor_Titlebar)
952 self->decorations &= ~Decor_Titlebar;
953 if (self->disabled_decorations & Decor_Handle)
954 self->decorations &= ~Decor_Handle;
955 if (self->disabled_decorations & Decor_Border)
956 self->decorations &= ~Decor_Border;
957 if (self->disabled_decorations & Decor_Iconify)
958 self->decorations &= ~Decor_Iconify;
959 if (self->disabled_decorations & Decor_Maximize)
960 self->decorations &= ~Decor_Maximize;
961 if (self->disabled_decorations & Decor_AllDesktops)
962 self->decorations &= ~Decor_AllDesktops;
963 if (self->disabled_decorations & Decor_Shade)
964 self->decorations &= ~Decor_Shade;
965 if (self->disabled_decorations & Decor_Close)
966 self->decorations &= ~Decor_Close;
968 /* if we don't have a titlebar, then we cannot shade! */
969 if (!(self->decorations & Decor_Titlebar))
970 self->functions &= ~Func_Shade;
972 /* now we need to check against rules for the client's current state */
973 if (self->fullscreen) {
974 self->functions &= (Func_Close | Func_Fullscreen | Func_Iconify);
975 self->decorations = 0;
978 client_change_allowed_actions(self);
981 /* change the decors on the frame, and with more/less decorations,
982 we may also need to be repositioned */
983 frame_adjust_area(self->frame, TRUE, TRUE);
984 /* with new decor, the window's maximized size may change */
985 client_remaximize(self);
989 static void client_change_allowed_actions(Client *self)
994 actions[num++] = prop_atoms.net_wm_action_change_desktop;
996 if (self->functions & Func_Shade)
997 actions[num++] = prop_atoms.net_wm_action_shade;
998 if (self->functions & Func_Close)
999 actions[num++] = prop_atoms.net_wm_action_close;
1000 if (self->functions & Func_Move)
1001 actions[num++] = prop_atoms.net_wm_action_move;
1002 if (self->functions & Func_Iconify)
1003 actions[num++] = prop_atoms.net_wm_action_minimize;
1004 if (self->functions & Func_Resize)
1005 actions[num++] = prop_atoms.net_wm_action_resize;
1006 if (self->functions & Func_Fullscreen)
1007 actions[num++] = prop_atoms.net_wm_action_fullscreen;
1008 if (self->functions & Func_Maximize) {
1009 actions[num++] = prop_atoms.net_wm_action_maximize_horz;
1010 actions[num++] = prop_atoms.net_wm_action_maximize_vert;
1013 PROP_SETA32(self->window, net_wm_allowed_actions, atom, actions, num);
1015 /* make sure the window isn't breaking any rules now */
1017 if (!(self->functions & Func_Shade) && self->shaded) {
1018 if (self->frame) client_shade(self, FALSE);
1019 else self->shaded = FALSE;
1021 if (!(self->functions & Func_Iconify) && self->iconic) {
1022 g_message("UNSETTING ICONIC");
1023 if (self->frame) client_iconify(self, FALSE, TRUE);
1024 else self->iconic = FALSE;
1026 if (!(self->functions & Func_Fullscreen) && self->fullscreen) {
1027 if (self->frame) client_fullscreen(self, FALSE, TRUE);
1028 else self->fullscreen = FALSE;
1030 if (!(self->functions & Func_Maximize) && (self->max_horz ||
1032 if (self->frame) client_maximize(self, FALSE, 0, TRUE);
1033 else self->max_vert = self->max_horz = FALSE;
1037 void client_remaximize(Client *self)
1040 if (self->max_horz && self->max_vert)
1042 else if (self->max_horz)
1044 else if (self->max_vert)
1047 return; /* not maximized */
1048 self->max_horz = self->max_vert = FALSE;
1049 client_maximize(self, TRUE, dir, FALSE);
1052 void client_update_wmhints(Client *self)
1055 gboolean ur = FALSE;
1058 /* assume a window takes input if it doesnt specify */
1059 self->can_focus = TRUE;
1061 if ((hints = XGetWMHints(ob_display, self->window)) != NULL) {
1062 if (hints->flags & InputHint)
1063 self->can_focus = hints->input;
1065 /* only do this when first managing the window *AND* when we aren't
1067 if (ob_state != State_Starting && self->frame == NULL)
1068 if (hints->flags & StateHint)
1069 self->iconic = hints->initial_state == IconicState;
1071 if (hints->flags & XUrgencyHint)
1074 if (!(hints->flags & WindowGroupHint))
1075 hints->window_group = None;
1077 /* did the group state change? */
1078 if (hints->window_group !=
1079 (self->group ? self->group->leader : None)) {
1080 /* remove from the old group if there was one */
1081 if (self->group != NULL) {
1082 /* remove transients of the group */
1083 for (it = self->group->members; it; it = it->next)
1084 if (it->data != self &&
1085 ((Client*)it->data)->transient_for == TRAN_GROUP) {
1086 self->transients = g_slist_remove(self->transients,
1089 group_remove(self->group, self);
1092 if (hints->window_group != None) {
1093 self->group = group_add(hints->window_group, self);
1095 /* add other transients of the group that are already
1097 for (it = self->group->members; it; it = it->next)
1098 if (it->data != self &&
1099 ((Client*)it->data)->transient_for == TRAN_GROUP)
1100 self->transients = g_slist_append(self->transients,
1104 /* because the self->transient flag wont change from this call,
1105 we don't need to update the window's type and such, only its
1106 transient_for, and the transients lists of other windows in
1107 the group may be affected */
1108 client_update_transient_for(self);
1111 client_update_kwm_icon(self);
1112 /* try get the kwm icon first, this is a fallback only */
1113 if (self->pixmap_icon == None) {
1114 if (hints->flags & IconPixmapHint) {
1115 if (self->pixmap_icon == None) {
1116 self->pixmap_icon = hints->icon_pixmap;
1117 if (hints->flags & IconMaskHint)
1118 self->pixmap_icon_mask = hints->icon_mask;
1120 self->pixmap_icon_mask = None;
1123 frame_adjust_icon(self->frame);
1131 if (ur != self->urgent) {
1133 g_message("Urgent Hint for 0x%lx: %s", self->window,
1135 /* fire the urgent callback if we're mapped, otherwise, wait until
1136 after we're mapped */
1138 dispatch_client(Event_Client_Urgent, self, self->urgent, 0);
1142 void client_update_title(Client *self)
1146 g_free(self->title);
1149 if (!PROP_GETS(self->window, net_wm_name, utf8, &data))
1150 /* try old x stuff */
1151 if (!PROP_GETS(self->window, wm_name, locale, &data))
1152 data = g_strdup("Unnamed Window");
1154 /* look for duplicates and append a number */
1156 PROP_SETS(self->window, net_wm_visible_name, data);
1161 frame_adjust_title(self->frame);
1164 void client_update_icon_title(Client *self)
1168 g_free(self->icon_title);
1171 if (!PROP_GETS(self->window, net_wm_icon_name, utf8, &data))
1172 /* try old x stuff */
1173 if (!PROP_GETS(self->window, wm_icon_name, locale, &data))
1174 data = g_strdup("Unnamed Window");
1176 PROP_SETS(self->window, net_wm_visible_icon_name, data);
1178 self->icon_title = data;
1181 void client_update_class(Client *self)
1186 if (self->name) g_free(self->name);
1187 if (self->class) g_free(self->class);
1188 if (self->role) g_free(self->role);
1190 self->name = self->class = self->role = NULL;
1192 if (PROP_GETSS(self->window, wm_class, locale, &data)) {
1194 self->name = g_strdup(data[0]);
1196 self->class = g_strdup(data[1]);
1201 if (PROP_GETS(self->window, wm_window_role, locale, &s))
1202 self->role = g_strdup(s);
1204 if (self->name == NULL) self->name = g_strdup("");
1205 if (self->class == NULL) self->class = g_strdup("");
1206 if (self->role == NULL) self->role = g_strdup("");
1209 void client_update_strut(Client *self)
1214 if (!PROP_GETA32(self->window, net_wm_strut, cardinal, &data, &num)) {
1215 STRUT_SET(self->strut, 0, 0, 0, 0);
1218 STRUT_SET(self->strut, data[0], data[2], data[1], data[3]);
1220 STRUT_SET(self->strut, 0, 0, 0, 0);
1224 /* updating here is pointless while we're being mapped cuz we're not in
1225 the client list yet */
1227 screen_update_struts();
1230 void client_update_icons(Client *self)
1237 for (j = 0; j < self->nicons; ++j)
1238 g_free(self->icons[j].data);
1239 if (self->nicons > 0)
1240 g_free(self->icons);
1243 if (PROP_GETA32(self->window, net_wm_icon, cardinal, &data, &num)) {
1244 /* figure out how many valid icons are in here */
1246 while (num - i > 2) {
1254 self->icons = g_new(Icon, self->nicons);
1256 /* store the icons */
1258 for (j = 0; j < self->nicons; ++j) {
1259 w = self->icons[j].width = data[i++];
1260 h = self->icons[j].height = data[i++];
1261 self->icons[j].data =
1262 g_memdup(&data[i], w * h * sizeof(gulong));
1271 frame_adjust_icon(self->frame);
1274 void client_update_kwm_icon(Client *self)
1279 if (!PROP_GETA32(self->window, kwm_win_icon, kwm_win_icon, &data, &num)) {
1280 self->pixmap_icon = self->pixmap_icon_mask = None;
1283 self->pixmap_icon = data[0];
1284 self->pixmap_icon_mask = data[1];
1286 self->pixmap_icon = self->pixmap_icon_mask = None;
1290 frame_adjust_icon(self->frame);
1293 static void client_change_state(Client *self)
1296 guint32 netstate[10];
1299 state[0] = self->wmstate;
1301 PROP_SETA32(self->window, wm_state, wm_state, state, 2);
1305 netstate[num++] = prop_atoms.net_wm_state_modal;
1307 netstate[num++] = prop_atoms.net_wm_state_shaded;
1309 netstate[num++] = prop_atoms.net_wm_state_hidden;
1310 if (self->skip_taskbar)
1311 netstate[num++] = prop_atoms.net_wm_state_skip_taskbar;
1312 if (self->skip_pager)
1313 netstate[num++] = prop_atoms.net_wm_state_skip_pager;
1314 if (self->fullscreen)
1315 netstate[num++] = prop_atoms.net_wm_state_fullscreen;
1317 netstate[num++] = prop_atoms.net_wm_state_maximized_vert;
1319 netstate[num++] = prop_atoms.net_wm_state_maximized_horz;
1321 netstate[num++] = prop_atoms.net_wm_state_above;
1323 netstate[num++] = prop_atoms.net_wm_state_below;
1324 PROP_SETA32(self->window, net_wm_state, atom, netstate, num);
1326 client_calc_layer(self);
1329 frame_adjust_state(self->frame);
1332 static Client *search_focus_tree(Client *node, Client *skip)
1337 for (it = node->transients; it != NULL; it = it->next) {
1338 Client *c = it->data;
1339 if (c == skip) continue; /* circular? */
1340 if ((ret = search_focus_tree(c, skip))) return ret;
1341 if (client_focused(c)) return c;
1346 static void calc_recursive(Client *self, StackLayer l, gboolean raised)
1354 for (it = self->transients; it; it = it->next)
1355 calc_recursive(it->data, l, raised ? raised : l != old);
1357 if (!raised && l != old)
1359 stacking_raise(self);
1362 void client_calc_layer(Client *self)
1367 /* transients take on the layer of their parents */
1368 if (self->transient_for) {
1369 if (self->transient_for != TRAN_GROUP) {
1370 self = self->transient_for;
1374 for (it = self->group->members; it; it = it->next)
1375 if (it->data != self &&
1376 ((Client*)it->data)->transient_for != TRAN_GROUP) {
1383 /* is us or one of our transients focused? */
1384 if (client_focused(self))
1386 else if (search_focus_tree(self, self))
1391 if (self->iconic) l = Layer_Icon;
1392 /* fullscreen windows are only in the fullscreen layer while focused */
1393 else if (self->fullscreen && f) l = Layer_Fullscreen;
1394 else if (self->type == Type_Desktop) l = Layer_Desktop;
1395 else if (self->type == Type_Dock) {
1396 if (!self->below) l = Layer_Top;
1397 else l = Layer_Normal;
1399 else if (self->above) l = Layer_Above;
1400 else if (self->below) l = Layer_Below;
1401 else l = Layer_Normal;
1403 calc_recursive(self, l, FALSE);
1406 gboolean client_should_show(Client *self)
1408 if (self->iconic) return FALSE;
1409 else if (!(self->desktop == screen_desktop ||
1410 self->desktop == DESKTOP_ALL)) return FALSE;
1411 else if (client_normal(self) && screen_showing_desktop) return FALSE;
1416 static void client_showhide(Client *self)
1419 if (client_should_show(self))
1420 frame_show(self->frame);
1422 frame_hide(self->frame);
1425 gboolean client_normal(Client *self) {
1426 return ! (self->type == Type_Desktop || self->type == Type_Dock ||
1427 self->type == Type_Splash);
1430 static void client_apply_startup_state(Client *self)
1432 /* these are in a carefully crafted order.. */
1435 self->iconic = FALSE;
1436 client_iconify(self, TRUE, FALSE);
1438 if (self->fullscreen) {
1439 self->fullscreen = FALSE;
1440 client_fullscreen(self, TRUE, FALSE);
1443 self->shaded = FALSE;
1444 client_shade(self, TRUE);
1447 dispatch_client(Event_Client_Urgent, self, self->urgent, 0);
1449 if (self->max_vert && self->max_horz) {
1450 self->max_vert = self->max_horz = FALSE;
1451 client_maximize(self, TRUE, 0, FALSE);
1452 } else if (self->max_vert) {
1453 self->max_vert = FALSE;
1454 client_maximize(self, TRUE, 2, FALSE);
1455 } else if (self->max_horz) {
1456 self->max_horz = FALSE;
1457 client_maximize(self, TRUE, 1, FALSE);
1460 /* nothing to do for the other states:
1469 void client_configure(Client *self, Corner anchor, int x, int y, int w, int h,
1470 gboolean user, gboolean final)
1472 gboolean moved = FALSE, resized = FALSE;
1474 /* gets the frame's position */
1475 frame_client_gravity(self->frame, &x, &y);
1477 /* these positions are frame positions, not client positions */
1479 /* set the size and position if fullscreen */
1480 if (self->fullscreen) {
1483 w = screen_physical_size.width;
1484 h = screen_physical_size.height;
1485 user = FALSE; /* ignore that increment etc shit when in fullscreen */
1487 /* set the size and position if maximized */
1488 if (self->max_horz) {
1489 x = screen_area(self->desktop)->x - self->frame->size.left;
1490 w = screen_area(self->desktop)->width;
1492 if (self->max_vert) {
1493 y = screen_area(self->desktop)->y;
1494 h = screen_area(self->desktop)->height -
1495 self->frame->size.top - self->frame->size.bottom;
1499 /* gets the client's position */
1500 frame_frame_gravity(self->frame, &x, &y);
1502 /* these override the above states! if you cant move you can't move! */
1504 if (!(self->functions & Func_Move)) {
1508 if (!(self->functions & Func_Resize)) {
1509 w = self->area.width;
1510 h = self->area.height;
1514 if (!(w == self->area.width && h == self->area.height)) {
1515 w -= self->base_size.width;
1516 h -= self->base_size.height;
1519 /* for interactive resizing. have to move half an increment in each
1522 /* how far we are towards the next size inc */
1523 int mw = w % self->size_inc.width;
1524 int mh = h % self->size_inc.height;
1526 int aw = self->size_inc.width / 2;
1527 int ah = self->size_inc.height / 2;
1528 /* don't let us move into a new size increment */
1529 if (mw + aw >= self->size_inc.width)
1530 aw = self->size_inc.width - mw - 1;
1531 if (mh + ah >= self->size_inc.height)
1532 ah = self->size_inc.height - mh - 1;
1536 /* if this is a user-requested resize, then check against min/max
1537 sizes and aspect ratios */
1539 /* smaller than min size or bigger than max size? */
1540 if (w > self->max_size.width) w = self->max_size.width;
1541 if (w < self->min_size.width) w = self->min_size.width;
1542 if (h > self->max_size.height) h = self->max_size.height;
1543 if (h < self->min_size.height) h = self->min_size.height;
1545 /* adjust the height ot match the width for the aspect ratios */
1546 if (self->min_ratio)
1547 if (h * self->min_ratio > w) h = (int)(w / self->min_ratio);
1548 if (self->max_ratio)
1549 if (h * self->max_ratio < w) h = (int)(w / self->max_ratio);
1552 /* keep to the increments */
1553 w /= self->size_inc.width;
1554 h /= self->size_inc.height;
1556 /* you cannot resize to nothing */
1560 /* store the logical size */
1561 SIZE_SET(self->logical_size, w, h);
1563 w *= self->size_inc.width;
1564 h *= self->size_inc.height;
1566 w += self->base_size.width;
1567 h += self->base_size.height;
1571 case Corner_TopLeft:
1573 case Corner_TopRight:
1574 x -= w - self->area.width;
1576 case Corner_BottomLeft:
1577 y -= h - self->area.height;
1579 case Corner_BottomRight:
1580 x -= w - self->area.width;
1581 y -= h - self->area.height;
1585 moved = x != self->area.x || y != self->area.y;
1586 resized = w != self->area.width || h != self->area.height;
1588 RECT_SET(self->area, x, y, w, h);
1591 XResizeWindow(ob_display, self->window, w, h);
1593 /* move/resize the frame to match the request */
1595 if (moved || resized)
1596 frame_adjust_area(self->frame, moved, resized);
1598 if (!user || final) {
1600 event.type = ConfigureNotify;
1601 event.xconfigure.display = ob_display;
1602 event.xconfigure.event = self->window;
1603 event.xconfigure.window = self->window;
1605 /* root window coords with border in mind */
1606 event.xconfigure.x = x - self->border_width +
1607 self->frame->size.left;
1608 event.xconfigure.y = y - self->border_width +
1609 self->frame->size.top;
1611 event.xconfigure.width = self->area.width;
1612 event.xconfigure.height = self->area.height;
1613 event.xconfigure.border_width = self->border_width;
1614 event.xconfigure.above = self->frame->plate;
1615 event.xconfigure.override_redirect = FALSE;
1616 XSendEvent(event.xconfigure.display, event.xconfigure.window,
1617 FALSE, StructureNotifyMask, &event);
1622 void client_fullscreen(Client *self, gboolean fs, gboolean savearea)
1626 if (!(self->functions & Func_Fullscreen) || /* can't */
1627 self->fullscreen == fs) return; /* already done */
1629 self->fullscreen = fs;
1630 client_change_state(self); /* change the state hints on the client,
1631 and adjust out layer/stacking */
1635 guint32 dimensions[4];
1636 dimensions[0] = self->area.x;
1637 dimensions[1] = self->area.y;
1638 dimensions[2] = self->area.width;
1639 dimensions[3] = self->area.height;
1641 PROP_SETA32(self->window, openbox_premax, cardinal,
1645 /* these are not actually used cuz client_configure will set them
1646 as appropriate when the window is fullscreened */
1652 /* pick some fallbacks... */
1653 x = screen_area(self->desktop)->x +
1654 screen_area(self->desktop)->width / 4;
1655 y = screen_area(self->desktop)->y +
1656 screen_area(self->desktop)->height / 4;
1657 w = screen_area(self->desktop)->width / 2;
1658 h = screen_area(self->desktop)->height / 2;
1660 if (PROP_GETA32(self->window, openbox_premax, cardinal,
1661 (guint32**)&dimensions, &num)) {
1672 client_setup_decor_and_functions(self);
1674 client_configure(self, Corner_TopLeft, x, y, w, h, TRUE, TRUE);
1676 /* try focus us when we go into fullscreen mode */
1680 void client_iconify(Client *self, gboolean iconic, gboolean curdesk)
1684 /* move up the transient chain as far as possible first if deiconifying */
1686 while (self->transient_for) {
1687 if (self->transient_for != TRAN_GROUP) {
1688 if (self->transient_for->iconic == iconic)
1690 self = self->transient_for;
1694 /* the check for TRAN_GROUP is to prevent an infinate loop with
1695 2 transients of the same group at the head of the group's
1697 for (it = self->group->members; it; it = it->next) {
1698 Client *c = it->data;
1700 if (c != self && c->transient_for->iconic != iconic &&
1701 c->transient_for != TRAN_GROUP) {
1706 if (it == NULL) break;
1710 if (self->iconic == iconic) return; /* nothing to do */
1712 g_message("%sconifying window: 0x%lx", (iconic ? "I" : "Uni"),
1715 self->iconic = iconic;
1718 self->wmstate = IconicState;
1719 self->ignore_unmaps++;
1720 /* we unmap the client itself so that we can get MapRequest events,
1721 and because the ICCCM tells us to! */
1722 XUnmapWindow(ob_display, self->window);
1725 client_set_desktop(self, screen_desktop, FALSE);
1726 self->wmstate = self->shaded ? IconicState : NormalState;
1727 XMapWindow(ob_display, self->window);
1729 client_change_state(self);
1730 client_showhide(self);
1731 screen_update_struts();
1733 dispatch_client(iconic ? Event_Client_Unmapped : Event_Client_Mapped,
1736 /* iconify all transients */
1737 for (it = self->transients; it != NULL; it = it->next)
1738 if (it->data != self) client_iconify(it->data, iconic, curdesk);
1741 void client_maximize(Client *self, gboolean max, int dir, gboolean savearea)
1745 g_assert(dir == 0 || dir == 1 || dir == 2);
1746 if (!(self->functions & Func_Maximize)) return; /* can't */
1748 /* check if already done */
1750 if (dir == 0 && self->max_horz && self->max_vert) return;
1751 if (dir == 1 && self->max_horz) return;
1752 if (dir == 2 && self->max_vert) return;
1754 if (dir == 0 && !self->max_horz && !self->max_vert) return;
1755 if (dir == 1 && !self->max_horz) return;
1756 if (dir == 2 && !self->max_vert) return;
1759 /* work with the frame's coords */
1760 x = self->frame->area.x;
1761 y = self->frame->area.y;
1762 w = self->area.width;
1763 h = self->area.height;
1767 gint32 dimensions[4];
1776 /* get the property off the window and use it for the dimensions
1777 we are already maxed on */
1778 if (PROP_GETA32(self->window, openbox_premax, cardinal,
1779 (guint32**)&readdim, &num)) {
1781 if (self->max_horz) {
1782 dimensions[0] = readdim[0];
1783 dimensions[2] = readdim[2];
1785 if (self->max_vert) {
1786 dimensions[1] = readdim[1];
1787 dimensions[3] = readdim[3];
1793 PROP_SETA32(self->window, openbox_premax, cardinal,
1794 (guint32*)dimensions, 4);
1800 /* pick some fallbacks... */
1801 if (dir == 0 || dir == 1) { /* horz */
1802 x = screen_area(self->desktop)->x +
1803 screen_area(self->desktop)->width / 4;
1804 w = screen_area(self->desktop)->width / 2;
1806 if (dir == 0 || dir == 2) { /* vert */
1807 y = screen_area(self->desktop)->y +
1808 screen_area(self->desktop)->height / 4;
1809 h = screen_area(self->desktop)->height / 2;
1812 if (PROP_GETA32(self->window, openbox_premax, cardinal,
1813 (guint32**)&dimensions, &num)) {
1815 if (dir == 0 || dir == 1) { /* horz */
1819 if (dir == 0 || dir == 2) { /* vert */
1828 if (dir == 0 || dir == 1) /* horz */
1829 self->max_horz = max;
1830 if (dir == 0 || dir == 2) /* vert */
1831 self->max_vert = max;
1833 if (!self->max_horz && !self->max_vert)
1834 PROP_ERASE(self->window, openbox_premax);
1836 client_change_state(self); /* change the state hints on the client */
1838 /* figure out where the client should be going */
1839 frame_frame_gravity(self->frame, &x, &y);
1840 client_configure(self, Corner_TopLeft, x, y, w, h, TRUE, TRUE);
1843 void client_shade(Client *self, gboolean shade)
1845 if ((!(self->functions & Func_Shade) && shade) || /* can't shade */
1846 self->shaded == shade) return; /* already done */
1848 /* when we're iconic, don't change the wmstate */
1850 self->wmstate = shade ? IconicState : NormalState;
1851 self->shaded = shade;
1852 client_change_state(self);
1853 /* resize the frame to just the titlebar */
1854 frame_adjust_area(self->frame, FALSE, FALSE);
1857 void client_close(Client *self)
1861 if (!(self->functions & Func_Close)) return;
1864 XXX: itd be cool to do timeouts and shit here for killing the client's
1866 like... if the window is around after 5 seconds, then the close button
1867 turns a nice red, and if this function is called again, the client is
1871 ce.xclient.type = ClientMessage;
1872 ce.xclient.message_type = prop_atoms.wm_protocols;
1873 ce.xclient.display = ob_display;
1874 ce.xclient.window = self->window;
1875 ce.xclient.format = 32;
1876 ce.xclient.data.l[0] = prop_atoms.wm_delete_window;
1877 ce.xclient.data.l[1] = event_lasttime;
1878 ce.xclient.data.l[2] = 0l;
1879 ce.xclient.data.l[3] = 0l;
1880 ce.xclient.data.l[4] = 0l;
1881 XSendEvent(ob_display, self->window, FALSE, NoEventMask, &ce);
1884 void client_kill(Client *self)
1886 XKillClient(ob_display, self->window);
1889 void client_set_desktop(Client *self, guint target, gboolean donthide)
1893 if (target == self->desktop) return;
1895 g_message("Setting desktop %u", target);
1897 g_assert(target < screen_num_desktops || target == DESKTOP_ALL);
1899 old = self->desktop;
1900 self->desktop = target;
1901 PROP_SET32(self->window, net_wm_desktop, cardinal, target);
1902 /* the frame can display the current desktop state */
1903 frame_adjust_state(self->frame);
1904 /* 'move' the window to the new desktop */
1906 client_showhide(self);
1907 /* raise if it was not already on the desktop */
1908 if (old != DESKTOP_ALL)
1909 stacking_raise(self);
1910 screen_update_struts();
1912 /* update the focus lists */
1913 if (old == DESKTOP_ALL) {
1914 for (i = 0; i < screen_num_desktops; ++i)
1915 focus_order[i] = g_list_remove(focus_order[i], self);
1917 focus_order[old] = g_list_remove(focus_order[old], self);
1918 if (target == DESKTOP_ALL) {
1919 for (i = 0; i < screen_num_desktops; ++i) {
1920 if (config_focus_new)
1921 focus_order[i] = g_list_prepend(focus_order[i], self);
1923 focus_order[i] = g_list_append(focus_order[i], self);
1926 if (config_focus_new)
1927 focus_order[target] = g_list_prepend(focus_order[target], self);
1929 focus_order[target] = g_list_append(focus_order[target], self);
1932 dispatch_client(Event_Client_Desktop, self, target, old);
1935 static Client *search_modal_tree(Client *node, Client *skip)
1940 for (it = node->transients; it != NULL; it = it->next) {
1941 Client *c = it->data;
1942 if (c == skip) continue; /* circular? */
1943 if ((ret = search_modal_tree(c, skip))) return ret;
1944 if (c->modal) return c;
1949 Client *client_find_modal_child(Client *self)
1951 return search_modal_tree(self, self);
1954 gboolean client_validate(Client *self)
1958 XSync(ob_display, FALSE); /* get all events on the server */
1960 if (XCheckTypedWindowEvent(ob_display, self->window, DestroyNotify, &e) ||
1961 XCheckTypedWindowEvent(ob_display, self->window, UnmapNotify, &e)) {
1962 XPutBackEvent(ob_display, &e);
1969 void client_set_wm_state(Client *self, long state)
1971 if (state == self->wmstate) return; /* no change */
1975 client_iconify(self, TRUE, TRUE);
1978 client_iconify(self, FALSE, TRUE);
1983 void client_set_state(Client *self, Atom action, long data1, long data2)
1985 gboolean shaded = self->shaded;
1986 gboolean fullscreen = self->fullscreen;
1987 gboolean max_horz = self->max_horz;
1988 gboolean max_vert = self->max_vert;
1991 if (!(action == prop_atoms.net_wm_state_add ||
1992 action == prop_atoms.net_wm_state_remove ||
1993 action == prop_atoms.net_wm_state_toggle))
1994 /* an invalid action was passed to the client message, ignore it */
1997 for (i = 0; i < 2; ++i) {
1998 Atom state = i == 0 ? data1 : data2;
2000 if (!state) continue;
2002 /* if toggling, then pick whether we're adding or removing */
2003 if (action == prop_atoms.net_wm_state_toggle) {
2004 if (state == prop_atoms.net_wm_state_modal)
2005 action = self->modal ? prop_atoms.net_wm_state_remove :
2006 prop_atoms.net_wm_state_add;
2007 else if (state == prop_atoms.net_wm_state_maximized_vert)
2008 action = self->max_vert ? prop_atoms.net_wm_state_remove :
2009 prop_atoms.net_wm_state_add;
2010 else if (state == prop_atoms.net_wm_state_maximized_horz)
2011 action = self->max_horz ? prop_atoms.net_wm_state_remove :
2012 prop_atoms.net_wm_state_add;
2013 else if (state == prop_atoms.net_wm_state_shaded)
2014 action = self->shaded ? prop_atoms.net_wm_state_remove :
2015 prop_atoms.net_wm_state_add;
2016 else if (state == prop_atoms.net_wm_state_skip_taskbar)
2017 action = self->skip_taskbar ?
2018 prop_atoms.net_wm_state_remove :
2019 prop_atoms.net_wm_state_add;
2020 else if (state == prop_atoms.net_wm_state_skip_pager)
2021 action = self->skip_pager ?
2022 prop_atoms.net_wm_state_remove :
2023 prop_atoms.net_wm_state_add;
2024 else if (state == prop_atoms.net_wm_state_fullscreen)
2025 action = self->fullscreen ?
2026 prop_atoms.net_wm_state_remove :
2027 prop_atoms.net_wm_state_add;
2028 else if (state == prop_atoms.net_wm_state_above)
2029 action = self->above ? prop_atoms.net_wm_state_remove :
2030 prop_atoms.net_wm_state_add;
2031 else if (state == prop_atoms.net_wm_state_below)
2032 action = self->below ? prop_atoms.net_wm_state_remove :
2033 prop_atoms.net_wm_state_add;
2036 if (action == prop_atoms.net_wm_state_add) {
2037 if (state == prop_atoms.net_wm_state_modal) {
2038 /* XXX raise here or something? */
2040 } else if (state == prop_atoms.net_wm_state_maximized_vert) {
2042 } else if (state == prop_atoms.net_wm_state_maximized_horz) {
2044 } else if (state == prop_atoms.net_wm_state_shaded) {
2046 } else if (state == prop_atoms.net_wm_state_skip_taskbar) {
2047 self->skip_taskbar = TRUE;
2048 } else if (state == prop_atoms.net_wm_state_skip_pager) {
2049 self->skip_pager = TRUE;
2050 } else if (state == prop_atoms.net_wm_state_fullscreen) {
2052 } else if (state == prop_atoms.net_wm_state_above) {
2054 } else if (state == prop_atoms.net_wm_state_below) {
2058 } else { /* action == prop_atoms.net_wm_state_remove */
2059 if (state == prop_atoms.net_wm_state_modal) {
2060 self->modal = FALSE;
2061 } else if (state == prop_atoms.net_wm_state_maximized_vert) {
2063 } else if (state == prop_atoms.net_wm_state_maximized_horz) {
2065 } else if (state == prop_atoms.net_wm_state_shaded) {
2067 } else if (state == prop_atoms.net_wm_state_skip_taskbar) {
2068 self->skip_taskbar = FALSE;
2069 } else if (state == prop_atoms.net_wm_state_skip_pager) {
2070 self->skip_pager = FALSE;
2071 } else if (state == prop_atoms.net_wm_state_fullscreen) {
2073 } else if (state == prop_atoms.net_wm_state_above) {
2074 self->above = FALSE;
2075 } else if (state == prop_atoms.net_wm_state_below) {
2076 self->below = FALSE;
2080 if (max_horz != self->max_horz || max_vert != self->max_vert) {
2081 if (max_horz != self->max_horz && max_vert != self->max_vert) {
2083 if (max_horz == max_vert) { /* both going the same way */
2084 client_maximize(self, max_horz, 0, TRUE);
2086 client_maximize(self, max_horz, 1, TRUE);
2087 client_maximize(self, max_vert, 2, TRUE);
2091 if (max_horz != self->max_horz)
2092 client_maximize(self, max_horz, 1, TRUE);
2094 client_maximize(self, max_vert, 2, TRUE);
2097 /* change fullscreen state before shading, as it will affect if the window
2099 if (fullscreen != self->fullscreen)
2100 client_fullscreen(self, fullscreen, TRUE);
2101 if (shaded != self->shaded)
2102 client_shade(self, shaded);
2103 client_calc_layer(self);
2104 client_change_state(self); /* change the hint to relect these changes */
2107 Client *client_focus_target(Client *self)
2111 /* if we have a modal child, then focus it, not us */
2112 child = client_find_modal_child(self);
2113 if (child) return child;
2117 gboolean client_focusable(Client *self)
2119 /* won't try focus if the client doesn't want it, or if the window isn't
2120 visible on the screen */
2121 return self->frame->visible &&
2122 (self->can_focus || self->focus_notify);
2125 gboolean client_focus(Client *self)
2130 /* choose the correct target */
2131 self = client_focus_target(self);
2133 if (self->desktop != DESKTOP_ALL && self->desktop != screen_desktop) {
2134 /* update the focus lists */
2135 if (self->desktop == DESKTOP_ALL) {
2136 for (i = 0; i < screen_num_desktops; ++i) {
2137 focus_order[i] = g_list_remove(focus_order[i], self);
2138 focus_order[i] = g_list_prepend(focus_order[i], self);
2142 focus_order[i] = g_list_remove(focus_order[i], self);
2143 focus_order[i] = g_list_prepend(focus_order[i], self);
2148 if (!client_focusable(self))
2151 /* do a check to see if the window has already been unmapped or destroyed
2152 do this intelligently while watching out for unmaps we've generated
2153 (ignore_unmaps > 0) */
2154 if (XCheckTypedWindowEvent(ob_display, self->window,
2155 DestroyNotify, &ev)) {
2156 XPutBackEvent(ob_display, &ev);
2159 while (XCheckTypedWindowEvent(ob_display, self->window,
2160 UnmapNotify, &ev)) {
2161 if (self->ignore_unmaps) {
2162 self->ignore_unmaps--;
2164 XPutBackEvent(ob_display, &ev);
2169 if (self->can_focus)
2170 /* RevertToPointerRoot causes much more headache than RevertToNone, so
2171 I choose to use it always, hopefully to find errors quicker, if any
2172 are left. (I hate X. I hate focus events.) */
2173 XSetInputFocus(ob_display, self->window, RevertToPointerRoot,
2176 if (self->focus_notify) {
2178 ce.xclient.type = ClientMessage;
2179 ce.xclient.message_type = prop_atoms.wm_protocols;
2180 ce.xclient.display = ob_display;
2181 ce.xclient.window = self->window;
2182 ce.xclient.format = 32;
2183 ce.xclient.data.l[0] = prop_atoms.wm_take_focus;
2184 ce.xclient.data.l[1] = event_lasttime;
2185 ce.xclient.data.l[2] = 0l;
2186 ce.xclient.data.l[3] = 0l;
2187 ce.xclient.data.l[4] = 0l;
2188 XSendEvent(ob_display, self->window, FALSE, NoEventMask, &ce);
2192 g_message("%sively focusing %lx at %d", (self->can_focus ? "act" : "pass"),
2197 /* Cause the FocusIn to come back to us. Important for desktop switches,
2198 since otherwise we'll have no FocusIn on the queue and send it off to
2199 the focus_backup. */
2200 XSync(ob_display, FALSE);
2204 void client_unfocus(Client *self)
2206 g_assert(focus_client == self);
2208 g_message("client_unfocus for %lx", self->window);
2210 focus_fallback(Fallback_Unfocusing);
2213 gboolean client_focused(Client *self)
2215 return self == focus_client;
2218 Icon *client_icon(Client *self, int w, int h)
2221 /* si is the smallest image >= req */
2222 /* li is the largest image < req */
2223 unsigned long size, smallest = 0xffffffff, largest = 0, si = 0, li = 0;
2225 if (!self->nicons) return NULL;
2227 for (i = 0; i < self->nicons; ++i) {
2228 size = self->icons[i].width * self->icons[i].height;
2229 if (size < smallest && size >= (unsigned)(w * h)) {
2233 if (size > largest && size <= (unsigned)(w * h)) {
2238 if (largest == 0) /* didnt find one smaller than the requested size */
2239 return &self->icons[si];
2240 return &self->icons[li];