5 #include "moveresize.h"
7 #include "extensions.h"
19 #include <X11/Xutil.h>
21 /*! The event mask to grab on client windows */
22 #define CLIENT_EVENTMASK (PropertyChangeMask | FocusChangeMask | \
25 #define CLIENT_NOPROPAGATEMASK (ButtonPressMask | ButtonReleaseMask | \
28 GList *client_list = NULL;
29 GHashTable *client_map = NULL;
31 static void client_get_all(Client *self);
32 static void client_toggle_border(Client *self, gboolean show);
33 static void client_get_area(Client *self);
34 static void client_get_desktop(Client *self);
35 static void client_get_state(Client *self);
36 static void client_get_shaped(Client *self);
37 static void client_get_mwm_hints(Client *self);
38 static void client_get_gravity(Client *self);
39 static void client_showhide(Client *self);
40 static void client_change_allowed_actions(Client *self);
41 static void client_change_state(Client *self);
42 static void client_apply_startup_state(Client *self);
44 static guint map_hash(Window *w) { return *w; }
45 static gboolean map_key_comp(Window *w1, Window *w2) { return *w1 == *w2; }
49 client_map = g_hash_table_new((GHashFunc)map_hash,
50 (GEqualFunc)map_key_comp);
55 void client_shutdown()
57 g_hash_table_destroy(client_map);
60 void client_set_list()
62 Window *windows, *win_it;
64 guint size = g_list_length(client_list);
66 /* create an array of the window ids */
68 windows = g_new(Window, size);
70 for (it = client_list; it != NULL; it = it->next, ++win_it)
71 *win_it = ((Client*)it->data)->window;
75 PROP_SETA32(ob_root, net_client_list, window, (guint32*)windows, size);
84 void client_foreach_transient(Client *self, ClientForeachFunc func, void *data)
88 for (it = self->transients; it; it = it->next) {
89 if (!func(it->data, data)) return;
90 client_foreach_transient(it->data, func, data);
94 void client_foreach_ancestor(Client *self, ClientForeachFunc func, void *data)
96 if (self->transient_for) {
97 if (self->transient_for != TRAN_GROUP) {
98 if (!func(self->transient_for, data)) return;
99 client_foreach_ancestor(self->transient_for, func, data);
103 for (it = self->group->members; it; it = it->next)
104 if (it->data != self &&
105 ((Client*)it->data)->transient_for != TRAN_GROUP) {
106 if (!func(it->data, data)) return;
107 client_foreach_ancestor(it->data, func, data);
114 void client_manage_all()
116 unsigned int i, j, nchild;
119 XWindowAttributes attrib;
122 XQueryTree(ob_display, ob_root, &w, &w, &children, &nchild);
124 /* remove all icon windows from the list */
125 for (i = 0; i < nchild; i++) {
126 if (children[i] == None) continue;
127 wmhints = XGetWMHints(ob_display, children[i]);
129 if ((wmhints->flags & IconWindowHint) &&
130 (wmhints->icon_window != children[i]))
131 for (j = 0; j < nchild; j++)
132 if (children[j] == wmhints->icon_window) {
140 for (i = 0; i < nchild; ++i) {
141 if (children[i] == None)
143 if (XGetWindowAttributes(ob_display, children[i], &attrib)) {
144 if (attrib.override_redirect) continue;
146 if (attrib.map_state != IsUnmapped)
147 client_manage(children[i]);
152 /* stack them as they were on startup!
153 why with stacking_lower? Why, because then windows who aren't in the
154 stacking list are on the top where you can see them instead of buried
156 for (i = startup_stack_size; i > 0; --i) {
159 w = startup_stack_order[i-1];
160 c = g_hash_table_lookup(client_map, &w);
161 if (c) stacking_lower(CLIENT_AS_WINDOW(c));
163 g_free(startup_stack_order);
164 startup_stack_order = NULL;
165 startup_stack_size = 0;
167 if (config_focus_new) {
168 active = g_hash_table_lookup(client_map, &startup_active);
169 if (!(active && client_focus(active)))
170 focus_fallback(Fallback_NoFocus);
174 void client_manage(Window window)
178 XWindowAttributes attrib;
179 XSetWindowAttributes attrib_set;
181 gboolean activate = FALSE;
185 /* check if it has already been unmapped by the time we started mapping
186 the grab does a sync so we don't have to here */
187 if (XCheckTypedWindowEvent(ob_display, window, DestroyNotify, &e) ||
188 XCheckTypedWindowEvent(ob_display, window, UnmapNotify, &e)) {
189 XPutBackEvent(ob_display, &e);
192 return; /* don't manage it */
195 /* make sure it isn't an override-redirect window */
196 if (!XGetWindowAttributes(ob_display, window, &attrib) ||
197 attrib.override_redirect) {
199 return; /* don't manage it */
202 /* is the window a docking app */
203 if ((wmhint = XGetWMHints(ob_display, window))) {
204 if ((wmhint->flags & StateHint) &&
205 wmhint->initial_state == WithdrawnState) {
206 slit_add(window, wmhint);
214 g_message("Managing window: %lx", window);
216 /* choose the events we want to receive on the CLIENT window */
217 attrib_set.event_mask = CLIENT_EVENTMASK;
218 attrib_set.do_not_propagate_mask = CLIENT_NOPROPAGATEMASK;
219 XChangeWindowAttributes(ob_display, window,
220 CWEventMask|CWDontPropagate, &attrib_set);
223 /* create the Client struct, and populate it from the hints on the
225 self = g_new(Client, 1);
226 self->obwin.type = Window_Client;
227 self->window = window;
228 client_get_all(self);
230 /* remove the client's border (and adjust re gravity) */
231 client_toggle_border(self, FALSE);
233 /* specify that if we exit, the window should not be destroyed and should
234 be reparented back to root automatically */
235 XChangeSaveSet(ob_display, window, SetModeInsert);
237 /* create the decoration frame for the client window */
238 self->frame = frame_new();
240 frame_grab_client(self->frame, self);
242 client_apply_startup_state(self);
246 /* add to client list/map */
247 client_list = g_list_append(client_list, self);
248 g_hash_table_insert(client_map, &self->window, self);
250 /* update the focus lists */
251 focus_order_add_new(self);
253 /* focus the new window? */
254 if (ob_state != State_Starting && config_focus_new) {
255 gboolean group_foc = FALSE;
260 for (it = self->group->members; it; it = it->next)
261 if (client_focused(it->data)) {
266 /* note the check against Type_Normal/Dialog, not client_normal(self),
267 which would also include other types. in this case we want more
268 strict rules for focus */
269 if (((self->type == Type_Normal ||
270 (self->type == Type_Dialog &&
272 (!self->transient_for && (!self->group ||
273 !self->group->members->next)))))) ||
274 client_search_focus_tree_full(self) ||
276 !client_normal(focus_client)) {
277 /* activate the window */
278 stacking_add(CLIENT_AS_WINDOW(self));
281 /* try to not get in the way */
282 stacking_add_nonintrusive(CLIENT_AS_WINDOW(self));
285 stacking_add(CLIENT_AS_WINDOW(self));
288 screen_update_struts();
290 /* make sure the window is visible */
291 client_move_onscreen(self);
293 dispatch_client(Event_Client_New, self, 0, 0);
295 client_showhide(self);
297 if (activate) client_activate(self);
299 /* update the list hints */
302 dispatch_client(Event_Client_Mapped, self, 0, 0);
304 g_message("Managed window 0x%lx", window);
307 void client_unmanage_all()
309 while (client_list != NULL)
310 client_unmanage(client_list->data);
313 void client_unmanage(Client *self)
318 g_message("Unmanaging window: %lx", self->window);
320 dispatch_client(Event_Client_Destroy, self, 0, 0);
321 g_assert(self != NULL);
323 /* remove the window from our save set */
324 XChangeSaveSet(ob_display, self->window, SetModeDelete);
326 /* we dont want events no more */
327 XSelectInput(ob_display, self->window, NoEventMask);
329 frame_hide(self->frame);
331 client_list = g_list_remove(client_list, self);
332 stacking_remove(self);
333 g_hash_table_remove(client_map, &self->window);
335 /* update the focus lists */
336 focus_order_remove(self);
338 /* once the client is out of the list, update the struts to remove it's
340 screen_update_struts();
342 /* tell our parent(s) that we're gone */
343 if (self->transient_for == TRAN_GROUP) { /* transient of group */
346 for (it = self->group->members; it; it = it->next)
347 if (it->data != self)
348 ((Client*)it->data)->transients =
349 g_slist_remove(((Client*)it->data)->transients, self);
350 } else if (self->transient_for) { /* transient of window */
351 self->transient_for->transients =
352 g_slist_remove(self->transient_for->transients, self);
355 /* tell our transients that we're gone */
356 for (it = self->transients; it != NULL; it = it->next) {
357 if (((Client*)it->data)->transient_for != TRAN_GROUP) {
358 ((Client*)it->data)->transient_for = NULL;
359 client_calc_layer(it->data);
363 if (moveresize_client == self)
364 moveresize_end(TRUE);
366 if (focus_client == self) {
369 /* focus the last focused window on the desktop, and ignore enter
370 events from the unmap so it doesnt mess with the focus */
371 while (XCheckTypedEvent(ob_display, EnterNotify, &e));
372 client_unfocus(self);
375 /* remove from its group */
377 group_remove(self->group, self);
381 /* dispatch the unmapped event */
382 dispatch_client(Event_Client_Unmapped, self, 0, 0);
383 g_assert(self != NULL);
385 /* give the client its border back */
386 client_toggle_border(self, TRUE);
388 /* reparent the window out of the frame, and free the frame */
389 frame_release_client(self->frame, self);
392 if (ob_state != State_Exiting) {
393 /* these values should not be persisted across a window
395 prop_erase(self->window, prop_atoms.net_wm_desktop);
396 prop_erase(self->window, prop_atoms.net_wm_state);
398 /* if we're left in an iconic state, the client wont be mapped. this is
399 bad, since we will no longer be managing the window on restart */
401 XMapWindow(ob_display, self->window);
405 g_message("Unmanaged window 0x%lx", self->window);
407 /* free all data allocated in the client struct */
408 g_slist_free(self->transients);
409 for (j = 0; j < self->nicons; ++j)
410 g_free(self->icons[j].data);
411 if (self->nicons > 0)
414 g_free(self->icon_title);
420 /* update the list hints */
424 void client_move_onscreen(Client *self)
427 int x = self->frame->area.x, y = self->frame->area.y;
429 a = screen_area(self->desktop);
430 if (x >= a->x + a->width - 1)
431 x = a->x + a->width - self->frame->area.width;
432 if (y >= a->y + a->height - 1)
433 y = a->y + a->height - self->frame->area.height;
434 if (x + self->frame->area.width - 1 < a->x)
436 if (y + self->frame->area.height - 1< a->y)
439 frame_frame_gravity(self->frame, &x, &y); /* get where the client
441 client_configure(self , Corner_TopLeft, x, y,
442 self->area.width, self->area.height,
446 static void client_toggle_border(Client *self, gboolean show)
448 /* adjust our idea of where the client is, based on its border. When the
449 border is removed, the client should now be considered to be in a
451 when re-adding the border to the client, the same operation needs to be
453 int oldx = self->area.x, oldy = self->area.y;
454 int x = oldx, y = oldy;
455 switch(self->gravity) {
457 case NorthWestGravity:
459 case SouthWestGravity:
461 case NorthEastGravity:
463 case SouthEastGravity:
464 if (show) x -= self->border_width * 2;
465 else x += self->border_width * 2;
472 if (show) x -= self->border_width;
473 else x += self->border_width;
476 switch(self->gravity) {
478 case NorthWestGravity:
480 case NorthEastGravity:
482 case SouthWestGravity:
484 case SouthEastGravity:
485 if (show) y -= self->border_width * 2;
486 else y += self->border_width * 2;
493 if (show) y -= self->border_width;
494 else y += self->border_width;
501 XSetWindowBorderWidth(ob_display, self->window, self->border_width);
503 /* move the client so it is back it the right spot _with_ its
505 if (x != oldx || y != oldy)
506 XMoveWindow(ob_display, self->window, x, y);
508 XSetWindowBorderWidth(ob_display, self->window, 0);
512 static void client_get_all(Client *self)
514 /* update EVERYTHING!! */
516 self->ignore_unmaps = 0;
520 self->title = self->icon_title = NULL;
521 self->title_count = 1;
522 self->name = self->class = self->role = NULL;
523 self->wmstate = NormalState;
524 self->transient = FALSE;
525 self->transients = NULL;
526 self->transient_for = NULL;
528 self->urgent = FALSE;
529 self->positioned = FALSE;
530 self->disabled_decorations = 0;
534 client_get_area(self);
535 client_update_transient_for(self);
536 client_update_wmhints(self);
537 client_get_desktop(self);
538 client_get_state(self);
539 client_get_shaped(self);
541 client_get_mwm_hints(self);
542 client_get_type(self);/* this can change the mwmhints for special cases */
544 client_update_protocols(self);
546 client_get_gravity(self); /* get the attribute gravity */
547 client_update_normal_hints(self); /* this may override the attribute
550 /* got the type, the mwmhints, the protocols, and the normal hints
551 (min/max sizes), so we're ready to set up the decorations/functions */
552 client_setup_decor_and_functions(self);
554 client_update_title(self);
555 client_update_class(self);
556 client_update_strut(self);
557 client_update_icons(self);
558 client_update_kwm_icon(self);
560 client_change_state(self);
563 static void client_get_area(Client *self)
565 XWindowAttributes wattrib;
568 ret = XGetWindowAttributes(ob_display, self->window, &wattrib);
569 g_assert(ret != BadWindow);
571 RECT_SET(self->area, wattrib.x, wattrib.y, wattrib.width, wattrib.height);
572 self->border_width = wattrib.border_width;
575 static void client_get_desktop(Client *self)
579 if (PROP_GET32(self->window, net_wm_desktop, cardinal, &d)) {
580 if (d >= screen_num_desktops && d != DESKTOP_ALL)
581 d = screen_num_desktops - 1;
584 gboolean trdesk = FALSE;
586 if (self->transient_for) {
587 if (self->transient_for != TRAN_GROUP) {
588 self->desktop = self->transient_for->desktop;
593 for (it = self->group->members; it; it = it->next)
594 if (it->data != self &&
595 ((Client*)it->data)->transient_for != TRAN_GROUP) {
596 self->desktop = ((Client*)it->data)->desktop;
603 /* defaults to the current desktop */
604 self->desktop = screen_desktop;
606 /* set the desktop hint, to make sure that it always exists */
607 PROP_SET32(self->window, net_wm_desktop, cardinal, self->desktop);
611 static void client_get_state(Client *self)
616 self->modal = self->shaded = self->max_horz = self->max_vert =
617 self->fullscreen = self->above = self->below = self->iconic =
618 self->skip_taskbar = self->skip_pager = FALSE;
620 if (PROP_GETA32(self->window, net_wm_state, atom, &state, &num)) {
622 for (i = 0; i < num; ++i) {
623 if (state[i] == prop_atoms.net_wm_state_modal)
625 else if (state[i] == prop_atoms.net_wm_state_shaded)
627 else if (state[i] == prop_atoms.net_wm_state_hidden)
629 else if (state[i] == prop_atoms.net_wm_state_skip_taskbar)
630 self->skip_taskbar = TRUE;
631 else if (state[i] == prop_atoms.net_wm_state_skip_pager)
632 self->skip_pager = TRUE;
633 else if (state[i] == prop_atoms.net_wm_state_fullscreen)
634 self->fullscreen = TRUE;
635 else if (state[i] == prop_atoms.net_wm_state_maximized_vert)
636 self->max_vert = TRUE;
637 else if (state[i] == prop_atoms.net_wm_state_maximized_horz)
638 self->max_horz = TRUE;
639 else if (state[i] == prop_atoms.net_wm_state_above)
641 else if (state[i] == prop_atoms.net_wm_state_below)
649 static void client_get_shaped(Client *self)
651 self->shaped = FALSE;
653 if (extensions_shape) {
658 XShapeSelectInput(ob_display, self->window, ShapeNotifyMask);
660 XShapeQueryExtents(ob_display, self->window, &s, &foo,
661 &foo, &ufoo, &ufoo, &foo, &foo, &foo, &ufoo,
663 self->shaped = (s != 0);
668 void client_update_transient_for(Client *self)
673 if (XGetTransientForHint(ob_display, self->window, &t)) {
674 self->transient = TRUE;
675 if (t != self->window) { /* cant be transient to itself! */
676 c = g_hash_table_lookup(client_map, &t);
677 /* if this happens then we need to check for it*/
680 if (!c && self->group) {
681 /* not transient to a client, see if it is transient for a
683 if (t == self->group->leader ||
686 /* window is a transient for its group! */
692 self->transient = FALSE;
694 /* if anything has changed... */
695 if (c != self->transient_for) {
696 if (self->transient_for == TRAN_GROUP) { /* transient of group */
699 /* remove from old parents */
700 for (it = self->group->members; it; it = it->next)
701 if (it->data != self &&
702 (((Client*)it->data)->transient_for != TRAN_GROUP))
703 ((Client*)it->data)->transients =
704 g_slist_remove(((Client*)it->data)->transients, self);
705 } else if (self->transient_for != NULL) { /* transient of window */
706 /* remove from old parent */
707 self->transient_for->transients =
708 g_slist_remove(self->transient_for->transients, self);
710 self->transient_for = c;
711 if (self->transient_for == TRAN_GROUP) { /* transient of group */
714 /* add to new parents */
715 for (it = self->group->members; it; it = it->next)
716 if (it->data != self &&
717 (((Client*)it->data)->transient_for != TRAN_GROUP))
718 ((Client*)it->data)->transients =
719 g_slist_append(((Client*)it->data)->transients, self);
721 /* remove all transients which are in the group, that causes
722 circlular pointer hell of doom */
723 for (it = self->group->members; it; it = it->next) {
725 for (sit = self->transients; sit; sit = next) {
727 if (sit->data == it->data)
728 self->transients = g_slist_remove(self->transients,
732 } else if (self->transient_for != NULL) { /* transient of window */
733 /* add to new parent */
734 self->transient_for->transients =
735 g_slist_append(self->transient_for->transients, self);
740 static void client_get_mwm_hints(Client *self)
745 self->mwmhints.flags = 0; /* default to none */
747 if (PROP_GETA32(self->window, motif_wm_hints, motif_wm_hints,
749 if (num >= MWM_ELEMENTS) {
750 self->mwmhints.flags = hints[0];
751 self->mwmhints.functions = hints[1];
752 self->mwmhints.decorations = hints[2];
758 void client_get_type(Client *self)
765 if (PROP_GETA32(self->window, net_wm_window_type, atom, &val, &num)) {
766 /* use the first value that we know about in the array */
767 for (i = 0; i < num; ++i) {
768 if (val[i] == prop_atoms.net_wm_window_type_desktop)
769 self->type = Type_Desktop;
770 else if (val[i] == prop_atoms.net_wm_window_type_dock)
771 self->type = Type_Dock;
772 else if (val[i] == prop_atoms.net_wm_window_type_toolbar)
773 self->type = Type_Toolbar;
774 else if (val[i] == prop_atoms.net_wm_window_type_menu)
775 self->type = Type_Menu;
776 else if (val[i] == prop_atoms.net_wm_window_type_utility)
777 self->type = Type_Utility;
778 else if (val[i] == prop_atoms.net_wm_window_type_splash)
779 self->type = Type_Splash;
780 else if (val[i] == prop_atoms.net_wm_window_type_dialog)
781 self->type = Type_Dialog;
782 else if (val[i] == prop_atoms.net_wm_window_type_normal)
783 self->type = Type_Normal;
784 else if (val[i] == prop_atoms.kde_net_wm_window_type_override) {
785 /* prevent this window from getting any decor or
787 self->mwmhints.flags &= (MwmFlag_Functions |
788 MwmFlag_Decorations);
789 self->mwmhints.decorations = 0;
790 self->mwmhints.functions = 0;
792 if (self->type != (WindowType) -1)
793 break; /* grab the first legit type */
798 if (self->type == (WindowType) -1) {
799 /*the window type hint was not set, which means we either classify
800 ourself as a normal window or a dialog, depending on if we are a
803 self->type = Type_Dialog;
805 self->type = Type_Normal;
809 void client_update_protocols(Client *self)
814 self->focus_notify = FALSE;
815 self->delete_window = FALSE;
817 if (PROP_GETA32(self->window, wm_protocols, atom, &proto, &num_return)) {
818 for (i = 0; i < num_return; ++i) {
819 if (proto[i] == prop_atoms.wm_delete_window) {
820 /* this means we can request the window to close */
821 self->delete_window = TRUE;
822 } else if (proto[i] == prop_atoms.wm_take_focus)
823 /* if this protocol is requested, then the window will be
824 notified whenever we want it to receive focus */
825 self->focus_notify = TRUE;
831 static void client_get_gravity(Client *self)
833 XWindowAttributes wattrib;
836 ret = XGetWindowAttributes(ob_display, self->window, &wattrib);
837 g_assert(ret != BadWindow);
838 self->gravity = wattrib.win_gravity;
841 void client_update_normal_hints(Client *self)
845 int oldgravity = self->gravity;
848 self->min_ratio = 0.0f;
849 self->max_ratio = 0.0f;
850 SIZE_SET(self->size_inc, 1, 1);
851 SIZE_SET(self->base_size, 0, 0);
852 SIZE_SET(self->min_size, 0, 0);
853 SIZE_SET(self->max_size, G_MAXINT, G_MAXINT);
855 /* get the hints from the window */
856 if (XGetWMNormalHints(ob_display, self->window, &size, &ret)) {
857 self->positioned = !!(size.flags & (PPosition|USPosition));
859 if (size.flags & PWinGravity) {
860 self->gravity = size.win_gravity;
862 /* if the client has a frame, i.e. has already been mapped and
863 is changing its gravity */
864 if (self->frame && self->gravity != oldgravity) {
865 /* move our idea of the client's position based on its new
867 self->area.x = self->frame->area.x;
868 self->area.y = self->frame->area.y;
869 frame_frame_gravity(self->frame, &self->area.x, &self->area.y);
873 if (size.flags & PAspect) {
874 if (size.min_aspect.y)
875 self->min_ratio = (float)size.min_aspect.x / size.min_aspect.y;
876 if (size.max_aspect.y)
877 self->max_ratio = (float)size.max_aspect.x / size.max_aspect.y;
880 if (size.flags & PMinSize)
881 SIZE_SET(self->min_size, size.min_width, size.min_height);
883 if (size.flags & PMaxSize)
884 SIZE_SET(self->max_size, size.max_width, size.max_height);
886 if (size.flags & PBaseSize)
887 SIZE_SET(self->base_size, size.base_width, size.base_height);
889 if (size.flags & PResizeInc)
890 SIZE_SET(self->size_inc, size.width_inc, size.height_inc);
894 void client_setup_decor_and_functions(Client *self)
896 /* start with everything (cept fullscreen) */
897 self->decorations = Decor_Titlebar | Decor_Handle | Decor_Border |
898 Decor_Icon | Decor_AllDesktops | Decor_Iconify | Decor_Maximize |
900 self->functions = Func_Resize | Func_Move | Func_Iconify | Func_Maximize |
902 if (self->delete_window) {
903 self->decorations |= Decor_Close;
904 self->functions |= Func_Close;
907 if (!(self->min_size.width < self->max_size.width ||
908 self->min_size.height < self->max_size.height)) {
909 self->decorations &= ~(Decor_Maximize | Decor_Handle);
910 self->functions &= ~(Func_Resize | Func_Maximize);
913 switch (self->type) {
915 /* normal windows retain all of the possible decorations and
916 functionality, and are the only windows that you can fullscreen */
917 self->functions |= Func_Fullscreen;
922 /* these windows cannot be maximized */
923 self->decorations &= ~Decor_Maximize;
924 self->functions &= ~Func_Maximize;
929 /* these windows get less functionality */
930 self->decorations &= ~(Decor_Iconify | Decor_Handle);
931 self->functions &= ~(Func_Iconify | Func_Resize);
937 /* none of these windows are manipulated by the window manager */
938 self->decorations = 0;
943 /* Mwm Hints are applied subtractively to what has already been chosen for
944 decor and functionality */
945 if (self->mwmhints.flags & MwmFlag_Decorations) {
946 if (! (self->mwmhints.decorations & MwmDecor_All)) {
947 if (! (self->mwmhints.decorations & MwmDecor_Border))
948 self->decorations &= ~Decor_Border;
949 if (! (self->mwmhints.decorations & MwmDecor_Handle))
950 self->decorations &= ~Decor_Handle;
951 if (! (self->mwmhints.decorations & MwmDecor_Title))
952 self->decorations &= ~Decor_Titlebar;
953 if (! (self->mwmhints.decorations & MwmDecor_Iconify))
954 self->decorations &= ~Decor_Iconify;
955 if (! (self->mwmhints.decorations & MwmDecor_Maximize))
956 self->decorations &= ~Decor_Maximize;
960 if (self->mwmhints.flags & MwmFlag_Functions) {
961 if (! (self->mwmhints.functions & MwmFunc_All)) {
962 if (! (self->mwmhints.functions & MwmFunc_Resize))
963 self->functions &= ~Func_Resize;
964 if (! (self->mwmhints.functions & MwmFunc_Move))
965 self->functions &= ~Func_Move;
966 if (! (self->mwmhints.functions & MwmFunc_Iconify))
967 self->functions &= ~Func_Iconify;
968 if (! (self->mwmhints.functions & MwmFunc_Maximize))
969 self->functions &= ~Func_Maximize;
970 /* dont let mwm hints kill the close button
971 if (! (self->mwmhints.functions & MwmFunc_Close))
972 self->functions &= ~Func_Close; */
976 /* can't maximize without moving/resizing */
977 if (!((self->functions & Func_Move) && (self->functions & Func_Resize)))
978 self->functions &= ~(Func_Maximize | Func_Fullscreen);
980 /* finally, user specified disabled decorations are applied to subtract
982 if (self->disabled_decorations & Decor_Titlebar)
983 self->decorations &= ~Decor_Titlebar;
984 if (self->disabled_decorations & Decor_Handle)
985 self->decorations &= ~Decor_Handle;
986 if (self->disabled_decorations & Decor_Border)
987 self->decorations &= ~Decor_Border;
988 if (self->disabled_decorations & Decor_Iconify)
989 self->decorations &= ~Decor_Iconify;
990 if (self->disabled_decorations & Decor_Maximize)
991 self->decorations &= ~Decor_Maximize;
992 if (self->disabled_decorations & Decor_AllDesktops)
993 self->decorations &= ~Decor_AllDesktops;
994 if (self->disabled_decorations & Decor_Shade)
995 self->decorations &= ~Decor_Shade;
996 if (self->disabled_decorations & Decor_Close)
997 self->decorations &= ~Decor_Close;
999 /* if we don't have a titlebar, then we cannot shade! */
1000 if (!(self->decorations & Decor_Titlebar))
1001 self->functions &= ~Func_Shade;
1003 /* now we need to check against rules for the client's current state */
1004 if (self->fullscreen) {
1005 self->functions &= (Func_Close | Func_Fullscreen | Func_Iconify);
1006 self->decorations = 0;
1009 client_change_allowed_actions(self);
1012 /* this makes sure that these windows appear on all desktops */
1013 if (self->type == Type_Desktop && self->desktop != DESKTOP_ALL)
1014 client_set_desktop(self, DESKTOP_ALL, FALSE);
1016 /* change the decors on the frame, and with more/less decorations,
1017 we may also need to be repositioned */
1018 frame_adjust_area(self->frame, TRUE, TRUE);
1019 /* with new decor, the window's maximized size may change */
1020 client_remaximize(self);
1022 /* this makes sure that these windows appear on all desktops */
1023 if (self->type == Type_Desktop && self->desktop != DESKTOP_ALL)
1024 self->desktop = DESKTOP_ALL;
1028 static void client_change_allowed_actions(Client *self)
1033 /* desktop windows are kept on all desktops */
1034 if (self->type != Type_Desktop)
1035 actions[num++] = prop_atoms.net_wm_action_change_desktop;
1037 if (self->functions & Func_Shade)
1038 actions[num++] = prop_atoms.net_wm_action_shade;
1039 if (self->functions & Func_Close)
1040 actions[num++] = prop_atoms.net_wm_action_close;
1041 if (self->functions & Func_Move)
1042 actions[num++] = prop_atoms.net_wm_action_move;
1043 if (self->functions & Func_Iconify)
1044 actions[num++] = prop_atoms.net_wm_action_minimize;
1045 if (self->functions & Func_Resize)
1046 actions[num++] = prop_atoms.net_wm_action_resize;
1047 if (self->functions & Func_Fullscreen)
1048 actions[num++] = prop_atoms.net_wm_action_fullscreen;
1049 if (self->functions & Func_Maximize) {
1050 actions[num++] = prop_atoms.net_wm_action_maximize_horz;
1051 actions[num++] = prop_atoms.net_wm_action_maximize_vert;
1054 PROP_SETA32(self->window, net_wm_allowed_actions, atom, actions, num);
1056 /* make sure the window isn't breaking any rules now */
1058 if (!(self->functions & Func_Shade) && self->shaded) {
1059 if (self->frame) client_shade(self, FALSE);
1060 else self->shaded = FALSE;
1062 if (!(self->functions & Func_Iconify) && self->iconic) {
1063 g_message("UNSETTING ICONIC");
1064 if (self->frame) client_iconify(self, FALSE, TRUE);
1065 else self->iconic = FALSE;
1067 if (!(self->functions & Func_Fullscreen) && self->fullscreen) {
1068 if (self->frame) client_fullscreen(self, FALSE, TRUE);
1069 else self->fullscreen = FALSE;
1071 if (!(self->functions & Func_Maximize) && (self->max_horz ||
1073 if (self->frame) client_maximize(self, FALSE, 0, TRUE);
1074 else self->max_vert = self->max_horz = FALSE;
1078 void client_remaximize(Client *self)
1081 if (self->max_horz && self->max_vert)
1083 else if (self->max_horz)
1085 else if (self->max_vert)
1088 return; /* not maximized */
1089 self->max_horz = self->max_vert = FALSE;
1090 client_maximize(self, TRUE, dir, FALSE);
1093 void client_update_wmhints(Client *self)
1096 gboolean ur = FALSE;
1099 /* assume a window takes input if it doesnt specify */
1100 self->can_focus = TRUE;
1102 if ((hints = XGetWMHints(ob_display, self->window)) != NULL) {
1103 if (hints->flags & InputHint)
1104 self->can_focus = hints->input;
1106 /* only do this when first managing the window *AND* when we aren't
1108 if (ob_state != State_Starting && self->frame == NULL)
1109 if (hints->flags & StateHint)
1110 self->iconic = hints->initial_state == IconicState;
1112 if (hints->flags & XUrgencyHint)
1115 if (!(hints->flags & WindowGroupHint))
1116 hints->window_group = None;
1118 /* did the group state change? */
1119 if (hints->window_group !=
1120 (self->group ? self->group->leader : None)) {
1121 /* remove from the old group if there was one */
1122 if (self->group != NULL) {
1123 /* remove transients of the group */
1124 for (it = self->group->members; it; it = it->next)
1125 if (it->data != self &&
1126 ((Client*)it->data)->transient_for == TRAN_GROUP) {
1127 self->transients = g_slist_remove(self->transients,
1130 group_remove(self->group, self);
1133 if (hints->window_group != None) {
1134 self->group = group_add(hints->window_group, self);
1136 /* add other transients of the group that are already
1138 for (it = self->group->members; it; it = it->next)
1139 if (it->data != self &&
1140 ((Client*)it->data)->transient_for == TRAN_GROUP)
1141 self->transients = g_slist_append(self->transients,
1145 /* because the self->transient flag wont change from this call,
1146 we don't need to update the window's type and such, only its
1147 transient_for, and the transients lists of other windows in
1148 the group may be affected */
1149 client_update_transient_for(self);
1152 client_update_kwm_icon(self);
1153 /* try get the kwm icon first, this is a fallback only */
1154 if (self->pixmap_icon == None) {
1155 if (hints->flags & IconPixmapHint) {
1156 if (self->pixmap_icon == None) {
1157 self->pixmap_icon = hints->icon_pixmap;
1158 if (hints->flags & IconMaskHint)
1159 self->pixmap_icon_mask = hints->icon_mask;
1161 self->pixmap_icon_mask = None;
1164 frame_adjust_icon(self->frame);
1172 if (ur != self->urgent) {
1174 g_message("Urgent Hint for 0x%lx: %s", self->window,
1176 /* fire the urgent callback if we're mapped, otherwise, wait until
1177 after we're mapped */
1179 dispatch_client(Event_Client_Urgent, self, self->urgent, 0);
1183 void client_update_title(Client *self)
1189 gboolean read_title;
1191 g_free(self->title);
1194 if (!PROP_GETS(self->window, net_wm_name, utf8, &data))
1195 /* try old x stuff */
1196 if (!PROP_GETS(self->window, wm_name, locale, &data))
1197 data = g_strdup("Unnamed Window");
1199 /* look for duplicates and append a number */
1201 for (it = client_list; it; it = it->next)
1202 if (it->data != self) {
1203 Client *c = it->data;
1204 if (0 == strncmp(c->title, data, strlen(data)))
1205 nums |= 1 << c->title_count;
1207 /* find first free number */
1208 for (i = 1; i <= 32; ++i)
1209 if (!(nums & (1 << i))) {
1210 if (self->title_count == 1 || i == 1)
1211 self->title_count = i;
1214 /* dont display the number for the first window */
1215 if (self->title_count > 1) {
1216 char *vdata, *ndata;
1217 ndata = g_strdup_printf(" - [%u]", self->title_count);
1218 vdata = g_strconcat(data, ndata, NULL);
1224 PROP_SETS(self->window, net_wm_visible_name, data);
1229 frame_adjust_title(self->frame);
1231 /* update the icon title */
1233 g_free(self->icon_title);
1237 if (!PROP_GETS(self->window, net_wm_icon_name, utf8, &data))
1238 /* try old x stuff */
1239 if (!PROP_GETS(self->window, wm_icon_name, locale, &data)) {
1240 data = g_strdup(self->title);
1244 /* append the title count, dont display the number for the first window */
1245 if (read_title && self->title_count > 1) {
1246 char *vdata, *ndata;
1247 ndata = g_strdup_printf(" - [%u]", self->title_count);
1248 vdata = g_strconcat(data, ndata, NULL);
1254 PROP_SETS(self->window, net_wm_visible_icon_name, data);
1256 self->icon_title = data;
1259 void client_update_class(Client *self)
1264 if (self->name) g_free(self->name);
1265 if (self->class) g_free(self->class);
1266 if (self->role) g_free(self->role);
1268 self->name = self->class = self->role = NULL;
1270 if (PROP_GETSS(self->window, wm_class, locale, &data)) {
1272 self->name = g_strdup(data[0]);
1274 self->class = g_strdup(data[1]);
1279 if (PROP_GETS(self->window, wm_window_role, locale, &s))
1280 self->role = g_strdup(s);
1282 if (self->name == NULL) self->name = g_strdup("");
1283 if (self->class == NULL) self->class = g_strdup("");
1284 if (self->role == NULL) self->role = g_strdup("");
1287 void client_update_strut(Client *self)
1292 if (!PROP_GETA32(self->window, net_wm_strut, cardinal, &data, &num)) {
1293 STRUT_SET(self->strut, 0, 0, 0, 0);
1296 STRUT_SET(self->strut, data[0], data[2], data[1], data[3]);
1298 STRUT_SET(self->strut, 0, 0, 0, 0);
1302 /* updating here is pointless while we're being mapped cuz we're not in
1303 the client list yet */
1305 screen_update_struts();
1308 void client_update_icons(Client *self)
1315 for (j = 0; j < self->nicons; ++j)
1316 g_free(self->icons[j].data);
1317 if (self->nicons > 0)
1318 g_free(self->icons);
1321 if (PROP_GETA32(self->window, net_wm_icon, cardinal, &data, &num)) {
1322 /* figure out how many valid icons are in here */
1324 while (num - i > 2) {
1332 self->icons = g_new(Icon, self->nicons);
1334 /* store the icons */
1336 for (j = 0; j < self->nicons; ++j) {
1337 w = self->icons[j].width = data[i++];
1338 h = self->icons[j].height = data[i++];
1339 self->icons[j].data =
1340 g_memdup(&data[i], w * h * sizeof(gulong));
1349 frame_adjust_icon(self->frame);
1352 void client_update_kwm_icon(Client *self)
1357 if (!PROP_GETA32(self->window, kwm_win_icon, kwm_win_icon, &data, &num)) {
1358 self->pixmap_icon = self->pixmap_icon_mask = None;
1361 self->pixmap_icon = data[0];
1362 self->pixmap_icon_mask = data[1];
1364 self->pixmap_icon = self->pixmap_icon_mask = None;
1368 frame_adjust_icon(self->frame);
1371 static void client_change_state(Client *self)
1374 guint32 netstate[10];
1377 state[0] = self->wmstate;
1379 PROP_SETA32(self->window, wm_state, wm_state, state, 2);
1383 netstate[num++] = prop_atoms.net_wm_state_modal;
1385 netstate[num++] = prop_atoms.net_wm_state_shaded;
1387 netstate[num++] = prop_atoms.net_wm_state_hidden;
1388 if (self->skip_taskbar)
1389 netstate[num++] = prop_atoms.net_wm_state_skip_taskbar;
1390 if (self->skip_pager)
1391 netstate[num++] = prop_atoms.net_wm_state_skip_pager;
1392 if (self->fullscreen)
1393 netstate[num++] = prop_atoms.net_wm_state_fullscreen;
1395 netstate[num++] = prop_atoms.net_wm_state_maximized_vert;
1397 netstate[num++] = prop_atoms.net_wm_state_maximized_horz;
1399 netstate[num++] = prop_atoms.net_wm_state_above;
1401 netstate[num++] = prop_atoms.net_wm_state_below;
1402 PROP_SETA32(self->window, net_wm_state, atom, netstate, num);
1404 client_calc_layer(self);
1407 frame_adjust_state(self->frame);
1410 Client *client_search_focus_tree(Client *self)
1415 for (it = self->transients; it != NULL; it = it->next) {
1416 if (client_focused(it->data)) return it->data;
1417 if ((ret = client_search_focus_tree(it->data))) return ret;
1422 Client *client_search_focus_tree_full(Client *self)
1424 if (self->transient_for) {
1425 if (self->transient_for != TRAN_GROUP) {
1426 return client_search_focus_tree_full(self->transient_for);
1430 for (it = self->group->members; it; it = it->next)
1431 if (((Client*)it->data)->transient_for != TRAN_GROUP) {
1433 if ((c = client_search_focus_tree_full(it->data)))
1439 /* this function checks the whole tree, the client_search_focus_tree
1440 does not, so we need to check this window */
1441 if (client_focused(self))
1443 return client_search_focus_tree(self);
1447 static StackLayer calc_layer(Client *self)
1451 if (self->fullscreen) l = Layer_Fullscreen;
1452 else if (self->type == Type_Desktop) l = Layer_Desktop;
1453 else if (self->type == Type_Dock) {
1454 if (!self->below) l = Layer_Top;
1455 else l = Layer_Normal;
1457 else if (self->above) l = Layer_Above;
1458 else if (self->below) l = Layer_Below;
1459 else l = Layer_Normal;
1464 static void calc_recursive(Client *self, Client *orig, StackLayer l,
1467 StackLayer old, own;
1471 own = calc_layer(self);
1472 self->layer = l > own ? l : own;
1474 for (it = self->transients; it; it = it->next)
1475 calc_recursive(it->data, orig, l, raised ? raised : l != old);
1477 if (!raised && l != old)
1478 if (orig->frame) /* only restack if the original window is managed */
1479 stacking_raise(CLIENT_AS_WINDOW(self));
1482 void client_calc_layer(Client *self)
1489 /* transients take on the layer of their parents */
1490 if (self->transient_for) {
1491 if (self->transient_for != TRAN_GROUP) {
1492 self = self->transient_for;
1496 for (it = self->group->members; it; it = it->next)
1497 if (it->data != self &&
1498 ((Client*)it->data)->transient_for != TRAN_GROUP) {
1505 l = calc_layer(self);
1507 calc_recursive(self, orig, l, FALSE);
1510 gboolean client_should_show(Client *self)
1512 if (self->iconic) return FALSE;
1513 else if (!(self->desktop == screen_desktop ||
1514 self->desktop == DESKTOP_ALL)) return FALSE;
1515 else if (client_normal(self) && screen_showing_desktop) return FALSE;
1520 static void client_showhide(Client *self)
1523 if (client_should_show(self))
1524 frame_show(self->frame);
1526 frame_hide(self->frame);
1529 gboolean client_normal(Client *self) {
1530 return ! (self->type == Type_Desktop || self->type == Type_Dock ||
1531 self->type == Type_Splash);
1534 static void client_apply_startup_state(Client *self)
1536 /* these are in a carefully crafted order.. */
1539 self->iconic = FALSE;
1540 client_iconify(self, TRUE, FALSE);
1542 if (self->fullscreen) {
1543 self->fullscreen = FALSE;
1544 client_fullscreen(self, TRUE, FALSE);
1547 self->shaded = FALSE;
1548 client_shade(self, TRUE);
1551 dispatch_client(Event_Client_Urgent, self, self->urgent, 0);
1553 if (self->max_vert && self->max_horz) {
1554 self->max_vert = self->max_horz = FALSE;
1555 client_maximize(self, TRUE, 0, FALSE);
1556 } else if (self->max_vert) {
1557 self->max_vert = FALSE;
1558 client_maximize(self, TRUE, 2, FALSE);
1559 } else if (self->max_horz) {
1560 self->max_horz = FALSE;
1561 client_maximize(self, TRUE, 1, FALSE);
1564 /* nothing to do for the other states:
1573 void client_configure(Client *self, Corner anchor, int x, int y, int w, int h,
1574 gboolean user, gboolean final)
1576 gboolean moved = FALSE, resized = FALSE;
1578 /* gets the frame's position */
1579 frame_client_gravity(self->frame, &x, &y);
1581 /* these positions are frame positions, not client positions */
1583 /* set the size and position if fullscreen */
1584 if (self->fullscreen) {
1587 w = screen_physical_size.width;
1588 h = screen_physical_size.height;
1589 user = FALSE; /* ignore that increment etc shit when in fullscreen */
1591 /* set the size and position if maximized */
1592 if (self->max_horz) {
1593 x = screen_area(self->desktop)->x - self->frame->size.left;
1594 w = screen_area(self->desktop)->width;
1596 if (self->max_vert) {
1597 y = screen_area(self->desktop)->y;
1598 h = screen_area(self->desktop)->height -
1599 self->frame->size.top - self->frame->size.bottom;
1603 /* gets the client's position */
1604 frame_frame_gravity(self->frame, &x, &y);
1606 /* these override the above states! if you cant move you can't move! */
1608 if (!(self->functions & Func_Move)) {
1612 if (!(self->functions & Func_Resize)) {
1613 w = self->area.width;
1614 h = self->area.height;
1618 if (!(w == self->area.width && h == self->area.height)) {
1619 w -= self->base_size.width;
1620 h -= self->base_size.height;
1623 /* for interactive resizing. have to move half an increment in each
1626 /* how far we are towards the next size inc */
1627 int mw = w % self->size_inc.width;
1628 int mh = h % self->size_inc.height;
1630 int aw = self->size_inc.width / 2;
1631 int ah = self->size_inc.height / 2;
1632 /* don't let us move into a new size increment */
1633 if (mw + aw >= self->size_inc.width)
1634 aw = self->size_inc.width - mw - 1;
1635 if (mh + ah >= self->size_inc.height)
1636 ah = self->size_inc.height - mh - 1;
1640 /* if this is a user-requested resize, then check against min/max
1641 sizes and aspect ratios */
1643 /* smaller than min size or bigger than max size? */
1644 if (w > self->max_size.width) w = self->max_size.width;
1645 if (w < self->min_size.width) w = self->min_size.width;
1646 if (h > self->max_size.height) h = self->max_size.height;
1647 if (h < self->min_size.height) h = self->min_size.height;
1649 /* adjust the height ot match the width for the aspect ratios */
1650 if (self->min_ratio)
1651 if (h * self->min_ratio > w) h = (int)(w / self->min_ratio);
1652 if (self->max_ratio)
1653 if (h * self->max_ratio < w) h = (int)(w / self->max_ratio);
1656 /* keep to the increments */
1657 w /= self->size_inc.width;
1658 h /= self->size_inc.height;
1660 /* you cannot resize to nothing */
1664 /* store the logical size */
1665 SIZE_SET(self->logical_size, w, h);
1667 w *= self->size_inc.width;
1668 h *= self->size_inc.height;
1670 w += self->base_size.width;
1671 h += self->base_size.height;
1675 case Corner_TopLeft:
1677 case Corner_TopRight:
1678 x -= w - self->area.width;
1680 case Corner_BottomLeft:
1681 y -= h - self->area.height;
1683 case Corner_BottomRight:
1684 x -= w - self->area.width;
1685 y -= h - self->area.height;
1689 moved = x != self->area.x || y != self->area.y;
1690 resized = w != self->area.width || h != self->area.height;
1692 RECT_SET(self->area, x, y, w, h);
1695 XResizeWindow(ob_display, self->window, w, h);
1697 /* move/resize the frame to match the request */
1699 if (moved || resized)
1700 frame_adjust_area(self->frame, moved, resized);
1702 if (!user || final) {
1704 event.type = ConfigureNotify;
1705 event.xconfigure.display = ob_display;
1706 event.xconfigure.event = self->window;
1707 event.xconfigure.window = self->window;
1709 /* root window real coords */
1710 event.xconfigure.x = self->frame->area.x + self->frame->size.left;
1711 event.xconfigure.y = self->frame->area.y + self->frame->size.top;
1713 event.xconfigure.width = w;
1714 event.xconfigure.height = h;
1715 event.xconfigure.border_width = 0;
1716 event.xconfigure.above = self->frame->plate;
1717 event.xconfigure.override_redirect = FALSE;
1718 XSendEvent(event.xconfigure.display, event.xconfigure.window,
1719 FALSE, StructureNotifyMask, &event);
1724 void client_fullscreen(Client *self, gboolean fs, gboolean savearea)
1728 if (!(self->functions & Func_Fullscreen) || /* can't */
1729 self->fullscreen == fs) return; /* already done */
1731 self->fullscreen = fs;
1732 client_change_state(self); /* change the state hints on the client,
1733 and adjust out layer/stacking */
1737 guint32 dimensions[4];
1738 dimensions[0] = self->area.x;
1739 dimensions[1] = self->area.y;
1740 dimensions[2] = self->area.width;
1741 dimensions[3] = self->area.height;
1743 PROP_SETA32(self->window, openbox_premax, cardinal,
1747 /* these are not actually used cuz client_configure will set them
1748 as appropriate when the window is fullscreened */
1754 /* pick some fallbacks... */
1755 x = screen_area(self->desktop)->x +
1756 screen_area(self->desktop)->width / 4;
1757 y = screen_area(self->desktop)->y +
1758 screen_area(self->desktop)->height / 4;
1759 w = screen_area(self->desktop)->width / 2;
1760 h = screen_area(self->desktop)->height / 2;
1762 if (PROP_GETA32(self->window, openbox_premax, cardinal,
1763 (guint32**)&dimensions, &num)) {
1774 client_setup_decor_and_functions(self);
1776 client_configure(self, Corner_TopLeft, x, y, w, h, TRUE, TRUE);
1778 /* try focus us when we go into fullscreen mode */
1782 void client_iconify(Client *self, gboolean iconic, gboolean curdesk)
1786 /* move up the transient chain as far as possible first */
1787 if (self->transient_for) {
1788 if (self->transient_for != TRAN_GROUP) {
1789 if (self->transient_for->iconic != iconic) {
1790 client_iconify(self->transient_for, iconic, curdesk);
1796 /* the check for TRAN_GROUP is to prevent an infinate loop with
1797 2 transients of the same group at the head of the group's
1799 for (it = self->group->members; it; it = it->next) {
1800 Client *c = it->data;
1801 if (c != self && c->iconic != iconic &&
1802 c->transient_for != TRAN_GROUP) {
1803 client_iconify(it->data, iconic, curdesk);
1807 if (it != NULL) return;
1811 if (self->iconic == iconic) return; /* nothing to do */
1813 g_message("%sconifying window: 0x%lx", (iconic ? "I" : "Uni"),
1816 self->iconic = iconic;
1819 self->wmstate = IconicState;
1820 self->ignore_unmaps++;
1821 /* we unmap the client itself so that we can get MapRequest events,
1822 and because the ICCCM tells us to! */
1823 XUnmapWindow(ob_display, self->window);
1825 /* update the focus lists.. iconic windows go to the bottom of the
1826 list, put the new iconic window at the 'top of the bottom'. */
1827 focus_order_to_top(self);
1830 client_set_desktop(self, screen_desktop, FALSE);
1831 self->wmstate = self->shaded ? IconicState : NormalState;
1832 XMapWindow(ob_display, self->window);
1834 /* this puts it after the current focused window */
1835 focus_order_remove(self);
1836 focus_order_add_new(self);
1838 client_change_state(self);
1839 client_showhide(self);
1840 screen_update_struts();
1842 dispatch_client(iconic ? Event_Client_Unmapped : Event_Client_Mapped,
1845 /* iconify all transients */
1846 for (it = self->transients; it != NULL; it = it->next)
1847 if (it->data != self) client_iconify(it->data, iconic, curdesk);
1850 void client_maximize(Client *self, gboolean max, int dir, gboolean savearea)
1854 g_assert(dir == 0 || dir == 1 || dir == 2);
1855 if (!(self->functions & Func_Maximize)) return; /* can't */
1857 /* check if already done */
1859 if (dir == 0 && self->max_horz && self->max_vert) return;
1860 if (dir == 1 && self->max_horz) return;
1861 if (dir == 2 && self->max_vert) return;
1863 if (dir == 0 && !self->max_horz && !self->max_vert) return;
1864 if (dir == 1 && !self->max_horz) return;
1865 if (dir == 2 && !self->max_vert) return;
1868 /* work with the frame's coords */
1869 x = self->frame->area.x;
1870 y = self->frame->area.y;
1871 w = self->area.width;
1872 h = self->area.height;
1876 gint32 dimensions[4];
1885 /* get the property off the window and use it for the dimensions
1886 we are already maxed on */
1887 if (PROP_GETA32(self->window, openbox_premax, cardinal,
1888 (guint32**)&readdim, &num)) {
1890 if (self->max_horz) {
1891 dimensions[0] = readdim[0];
1892 dimensions[2] = readdim[2];
1894 if (self->max_vert) {
1895 dimensions[1] = readdim[1];
1896 dimensions[3] = readdim[3];
1902 PROP_SETA32(self->window, openbox_premax, cardinal,
1903 (guint32*)dimensions, 4);
1909 /* pick some fallbacks... */
1910 if (dir == 0 || dir == 1) { /* horz */
1911 x = screen_area(self->desktop)->x +
1912 screen_area(self->desktop)->width / 4;
1913 w = screen_area(self->desktop)->width / 2;
1915 if (dir == 0 || dir == 2) { /* vert */
1916 y = screen_area(self->desktop)->y +
1917 screen_area(self->desktop)->height / 4;
1918 h = screen_area(self->desktop)->height / 2;
1921 if (PROP_GETA32(self->window, openbox_premax, cardinal,
1922 (guint32**)&dimensions, &num)) {
1924 if (dir == 0 || dir == 1) { /* horz */
1928 if (dir == 0 || dir == 2) { /* vert */
1937 if (dir == 0 || dir == 1) /* horz */
1938 self->max_horz = max;
1939 if (dir == 0 || dir == 2) /* vert */
1940 self->max_vert = max;
1942 if (!self->max_horz && !self->max_vert)
1943 PROP_ERASE(self->window, openbox_premax);
1945 client_change_state(self); /* change the state hints on the client */
1947 /* figure out where the client should be going */
1948 frame_frame_gravity(self->frame, &x, &y);
1949 client_configure(self, Corner_TopLeft, x, y, w, h, TRUE, TRUE);
1952 void client_shade(Client *self, gboolean shade)
1954 if ((!(self->functions & Func_Shade) && shade) || /* can't shade */
1955 self->shaded == shade) return; /* already done */
1957 /* when we're iconic, don't change the wmstate */
1959 self->wmstate = shade ? IconicState : NormalState;
1960 self->shaded = shade;
1961 client_change_state(self);
1962 /* resize the frame to just the titlebar */
1963 frame_adjust_area(self->frame, FALSE, FALSE);
1966 void client_close(Client *self)
1970 if (!(self->functions & Func_Close)) return;
1973 XXX: itd be cool to do timeouts and shit here for killing the client's
1975 like... if the window is around after 5 seconds, then the close button
1976 turns a nice red, and if this function is called again, the client is
1980 ce.xclient.type = ClientMessage;
1981 ce.xclient.message_type = prop_atoms.wm_protocols;
1982 ce.xclient.display = ob_display;
1983 ce.xclient.window = self->window;
1984 ce.xclient.format = 32;
1985 ce.xclient.data.l[0] = prop_atoms.wm_delete_window;
1986 ce.xclient.data.l[1] = event_lasttime;
1987 ce.xclient.data.l[2] = 0l;
1988 ce.xclient.data.l[3] = 0l;
1989 ce.xclient.data.l[4] = 0l;
1990 XSendEvent(ob_display, self->window, FALSE, NoEventMask, &ce);
1993 void client_kill(Client *self)
1995 XKillClient(ob_display, self->window);
1998 void client_set_desktop(Client *self, guint target, gboolean donthide)
2002 if (target == self->desktop) return;
2004 g_message("Setting desktop %u", target);
2006 g_assert(target < screen_num_desktops || target == DESKTOP_ALL);
2008 /* remove from the old desktop(s) */
2009 focus_order_remove(self);
2011 old = self->desktop;
2012 self->desktop = target;
2013 PROP_SET32(self->window, net_wm_desktop, cardinal, target);
2014 /* the frame can display the current desktop state */
2015 frame_adjust_state(self->frame);
2016 /* 'move' the window to the new desktop */
2018 client_showhide(self);
2019 /* raise if it was not already on the desktop */
2020 if (old != DESKTOP_ALL)
2021 stacking_raise(CLIENT_AS_WINDOW(self));
2022 screen_update_struts();
2024 /* add to the new desktop(s) */
2025 if (config_focus_new)
2026 focus_order_to_top(self);
2028 focus_order_to_bottom(self);
2030 dispatch_client(Event_Client_Desktop, self, target, old);
2033 Client *client_search_modal_child(Client *self)
2038 for (it = self->transients; it != NULL; it = it->next) {
2039 Client *c = it->data;
2040 if ((ret = client_search_modal_child(c))) return ret;
2041 if (c->modal) return c;
2046 gboolean client_validate(Client *self)
2050 XSync(ob_display, FALSE); /* get all events on the server */
2052 if (XCheckTypedWindowEvent(ob_display, self->window, DestroyNotify, &e) ||
2053 XCheckTypedWindowEvent(ob_display, self->window, UnmapNotify, &e)) {
2054 XPutBackEvent(ob_display, &e);
2061 void client_set_wm_state(Client *self, long state)
2063 if (state == self->wmstate) return; /* no change */
2067 client_iconify(self, TRUE, TRUE);
2070 client_iconify(self, FALSE, TRUE);
2075 void client_set_state(Client *self, Atom action, long data1, long data2)
2077 gboolean shaded = self->shaded;
2078 gboolean fullscreen = self->fullscreen;
2079 gboolean max_horz = self->max_horz;
2080 gboolean max_vert = self->max_vert;
2083 if (!(action == prop_atoms.net_wm_state_add ||
2084 action == prop_atoms.net_wm_state_remove ||
2085 action == prop_atoms.net_wm_state_toggle))
2086 /* an invalid action was passed to the client message, ignore it */
2089 for (i = 0; i < 2; ++i) {
2090 Atom state = i == 0 ? data1 : data2;
2092 if (!state) continue;
2094 /* if toggling, then pick whether we're adding or removing */
2095 if (action == prop_atoms.net_wm_state_toggle) {
2096 if (state == prop_atoms.net_wm_state_modal)
2097 action = self->modal ? prop_atoms.net_wm_state_remove :
2098 prop_atoms.net_wm_state_add;
2099 else if (state == prop_atoms.net_wm_state_maximized_vert)
2100 action = self->max_vert ? prop_atoms.net_wm_state_remove :
2101 prop_atoms.net_wm_state_add;
2102 else if (state == prop_atoms.net_wm_state_maximized_horz)
2103 action = self->max_horz ? prop_atoms.net_wm_state_remove :
2104 prop_atoms.net_wm_state_add;
2105 else if (state == prop_atoms.net_wm_state_shaded)
2106 action = self->shaded ? prop_atoms.net_wm_state_remove :
2107 prop_atoms.net_wm_state_add;
2108 else if (state == prop_atoms.net_wm_state_skip_taskbar)
2109 action = self->skip_taskbar ?
2110 prop_atoms.net_wm_state_remove :
2111 prop_atoms.net_wm_state_add;
2112 else if (state == prop_atoms.net_wm_state_skip_pager)
2113 action = self->skip_pager ?
2114 prop_atoms.net_wm_state_remove :
2115 prop_atoms.net_wm_state_add;
2116 else if (state == prop_atoms.net_wm_state_fullscreen)
2117 action = self->fullscreen ?
2118 prop_atoms.net_wm_state_remove :
2119 prop_atoms.net_wm_state_add;
2120 else if (state == prop_atoms.net_wm_state_above)
2121 action = self->above ? prop_atoms.net_wm_state_remove :
2122 prop_atoms.net_wm_state_add;
2123 else if (state == prop_atoms.net_wm_state_below)
2124 action = self->below ? prop_atoms.net_wm_state_remove :
2125 prop_atoms.net_wm_state_add;
2128 if (action == prop_atoms.net_wm_state_add) {
2129 if (state == prop_atoms.net_wm_state_modal) {
2130 /* XXX raise here or something? */
2132 } else if (state == prop_atoms.net_wm_state_maximized_vert) {
2134 } else if (state == prop_atoms.net_wm_state_maximized_horz) {
2136 } else if (state == prop_atoms.net_wm_state_shaded) {
2138 } else if (state == prop_atoms.net_wm_state_skip_taskbar) {
2139 self->skip_taskbar = TRUE;
2140 } else if (state == prop_atoms.net_wm_state_skip_pager) {
2141 self->skip_pager = TRUE;
2142 } else if (state == prop_atoms.net_wm_state_fullscreen) {
2144 } else if (state == prop_atoms.net_wm_state_above) {
2146 } else if (state == prop_atoms.net_wm_state_below) {
2150 } else { /* action == prop_atoms.net_wm_state_remove */
2151 if (state == prop_atoms.net_wm_state_modal) {
2152 self->modal = FALSE;
2153 } else if (state == prop_atoms.net_wm_state_maximized_vert) {
2155 } else if (state == prop_atoms.net_wm_state_maximized_horz) {
2157 } else if (state == prop_atoms.net_wm_state_shaded) {
2159 } else if (state == prop_atoms.net_wm_state_skip_taskbar) {
2160 self->skip_taskbar = FALSE;
2161 } else if (state == prop_atoms.net_wm_state_skip_pager) {
2162 self->skip_pager = FALSE;
2163 } else if (state == prop_atoms.net_wm_state_fullscreen) {
2165 } else if (state == prop_atoms.net_wm_state_above) {
2166 self->above = FALSE;
2167 } else if (state == prop_atoms.net_wm_state_below) {
2168 self->below = FALSE;
2172 if (max_horz != self->max_horz || max_vert != self->max_vert) {
2173 if (max_horz != self->max_horz && max_vert != self->max_vert) {
2175 if (max_horz == max_vert) { /* both going the same way */
2176 client_maximize(self, max_horz, 0, TRUE);
2178 client_maximize(self, max_horz, 1, TRUE);
2179 client_maximize(self, max_vert, 2, TRUE);
2183 if (max_horz != self->max_horz)
2184 client_maximize(self, max_horz, 1, TRUE);
2186 client_maximize(self, max_vert, 2, TRUE);
2189 /* change fullscreen state before shading, as it will affect if the window
2191 if (fullscreen != self->fullscreen)
2192 client_fullscreen(self, fullscreen, TRUE);
2193 if (shaded != self->shaded)
2194 client_shade(self, shaded);
2195 client_calc_layer(self);
2196 client_change_state(self); /* change the hint to relect these changes */
2199 Client *client_focus_target(Client *self)
2203 /* if we have a modal child, then focus it, not us */
2204 child = client_search_modal_child(self);
2205 if (child) return child;
2209 gboolean client_focus(Client *self)
2213 /* choose the correct target */
2214 self = client_focus_target(self);
2216 if (self->desktop != DESKTOP_ALL && self->desktop != screen_desktop) {
2217 /* update the focus lists */
2218 focus_order_to_top(self);
2222 if (!((self->can_focus || self->focus_notify) &&
2223 (self->desktop == screen_desktop ||
2224 self->desktop == DESKTOP_ALL) &&
2228 /* do a check to see if the window has already been unmapped or destroyed
2229 do this intelligently while watching out for unmaps we've generated
2230 (ignore_unmaps > 0) */
2231 if (XCheckTypedWindowEvent(ob_display, self->window,
2232 DestroyNotify, &ev)) {
2233 XPutBackEvent(ob_display, &ev);
2236 while (XCheckTypedWindowEvent(ob_display, self->window,
2237 UnmapNotify, &ev)) {
2238 if (self->ignore_unmaps) {
2239 self->ignore_unmaps--;
2241 XPutBackEvent(ob_display, &ev);
2246 if (self->can_focus)
2247 /* RevertToPointerRoot causes much more headache than RevertToNone, so
2248 I choose to use it always, hopefully to find errors quicker, if any
2249 are left. (I hate X. I hate focus events.) */
2250 XSetInputFocus(ob_display, self->window, RevertToPointerRoot,
2253 if (self->focus_notify) {
2255 ce.xclient.type = ClientMessage;
2256 ce.xclient.message_type = prop_atoms.wm_protocols;
2257 ce.xclient.display = ob_display;
2258 ce.xclient.window = self->window;
2259 ce.xclient.format = 32;
2260 ce.xclient.data.l[0] = prop_atoms.wm_take_focus;
2261 ce.xclient.data.l[1] = event_lasttime;
2262 ce.xclient.data.l[2] = 0l;
2263 ce.xclient.data.l[3] = 0l;
2264 ce.xclient.data.l[4] = 0l;
2265 XSendEvent(ob_display, self->window, FALSE, NoEventMask, &ce);
2269 g_message("%sively focusing %lx at %d", (self->can_focus ? "act" : "pass"),
2274 /* Cause the FocusIn to come back to us. Important for desktop switches,
2275 since otherwise we'll have no FocusIn on the queue and send it off to
2276 the focus_backup. */
2277 XSync(ob_display, FALSE);
2281 void client_unfocus(Client *self)
2283 g_assert(focus_client == self);
2285 g_message("client_unfocus for %lx", self->window);
2287 focus_fallback(Fallback_Unfocusing);
2290 void client_activate(Client *self)
2292 if (client_normal(self) && screen_showing_desktop)
2293 screen_show_desktop(FALSE);
2295 client_iconify(self, FALSE, TRUE);
2296 else if (!self->frame->visible)
2297 /* if its not visible for other reasons, then don't mess
2301 client_shade(self, FALSE);
2303 stacking_raise(CLIENT_AS_WINDOW(self));
2306 gboolean client_focused(Client *self)
2308 return self == focus_client;
2311 Icon *client_icon(Client *self, int w, int h)
2314 /* si is the smallest image >= req */
2315 /* li is the largest image < req */
2316 unsigned long size, smallest = 0xffffffff, largest = 0, si = 0, li = 0;
2318 if (!self->nicons) return NULL;
2320 for (i = 0; i < self->nicons; ++i) {
2321 size = self->icons[i].width * self->icons[i].height;
2322 if (size < smallest && size >= (unsigned)(w * h)) {
2326 if (size > largest && size <= (unsigned)(w * h)) {
2331 if (largest == 0) /* didnt find one smaller than the requested size */
2332 return &self->icons[si];
2333 return &self->icons[li];