7 #include "moveresize.h"
10 #include "extensions.h"
20 #include "menuframe.h"
23 #include "render/render.h"
26 #include <X11/Xutil.h>
28 /*! The event mask to grab on client windows */
29 #define CLIENT_EVENTMASK (PropertyChangeMask | FocusChangeMask | \
32 #define CLIENT_NOPROPAGATEMASK (ButtonPressMask | ButtonReleaseMask | \
35 GList *client_list = NULL;
36 GSList *client_destructors = NULL;
38 static void client_get_all(ObClient *self);
39 static void client_toggle_border(ObClient *self, gboolean show);
40 static void client_get_area(ObClient *self);
41 static void client_get_desktop(ObClient *self);
42 static void client_get_state(ObClient *self);
43 static void client_get_shaped(ObClient *self);
44 static void client_get_mwm_hints(ObClient *self);
45 static void client_get_gravity(ObClient *self);
46 static void client_showhide(ObClient *self);
47 static void client_change_allowed_actions(ObClient *self);
48 static void client_change_state(ObClient *self);
49 static void client_apply_startup_state(ObClient *self);
50 static void client_restore_session_state(ObClient *self);
51 static void client_restore_session_stacking(ObClient *self);
52 static void client_act_urgent(ObClient *self);
59 void client_shutdown()
63 void client_add_destructor(ObClientDestructorFunc func)
65 client_destructors = g_slist_prepend(client_destructors, (gpointer)func);
68 void client_remove_destructor(ObClientDestructorFunc func)
70 client_destructors = g_slist_remove(client_destructors, (gpointer)func);
73 void client_set_list()
75 Window *windows, *win_it;
77 guint size = g_list_length(client_list);
79 /* create an array of the window ids */
81 windows = g_new(Window, size);
83 for (it = client_list; it != NULL; it = it->next, ++win_it)
84 *win_it = ((ObClient*)it->data)->window;
88 PROP_SETA32(RootWindow(ob_display, ob_screen),
89 net_client_list, window, (guint32*)windows, size);
98 void client_foreach_transient(ObClient *self, ObClientForeachFunc func, void *data)
102 for (it = self->transients; it; it = it->next) {
103 if (!func(it->data, data)) return;
104 client_foreach_transient(it->data, func, data);
108 void client_foreach_ancestor(ObClient *self, ObClientForeachFunc func, void *data)
110 if (self->transient_for) {
111 if (self->transient_for != OB_TRAN_GROUP) {
112 if (!func(self->transient_for, data)) return;
113 client_foreach_ancestor(self->transient_for, func, data);
117 for (it = self->group->members; it; it = it->next)
118 if (it->data != self &&
119 !((ObClient*)it->data)->transient_for) {
120 if (!func(it->data, data)) return;
121 client_foreach_ancestor(it->data, func, data);
128 void client_manage_all()
130 unsigned int i, j, nchild;
133 XWindowAttributes attrib;
135 XQueryTree(ob_display, RootWindow(ob_display, ob_screen),
136 &w, &w, &children, &nchild);
138 /* remove all icon windows from the list */
139 for (i = 0; i < nchild; i++) {
140 if (children[i] == None) continue;
141 wmhints = XGetWMHints(ob_display, children[i]);
143 if ((wmhints->flags & IconWindowHint) &&
144 (wmhints->icon_window != children[i]))
145 for (j = 0; j < nchild; j++)
146 if (children[j] == wmhints->icon_window) {
154 for (i = 0; i < nchild; ++i) {
155 if (children[i] == None)
157 if (XGetWindowAttributes(ob_display, children[i], &attrib)) {
158 if (attrib.override_redirect) continue;
160 if (attrib.map_state != IsUnmapped)
161 client_manage(children[i]);
166 /* stack them as they were on startup!
167 why with stacking_lower? Why, because then windows who aren't in the
168 stacking list are on the top where you can see them instead of buried
170 for (i = startup_stack_size; i > 0; --i) {
173 w = startup_stack_order[i-1];
174 obw = g_hash_table_lookup(window_map, &w);
176 g_assert(WINDOW_IS_CLIENT(obw));
177 stacking_lower(CLIENT_AS_WINDOW(obw));
180 g_free(startup_stack_order);
181 startup_stack_order = NULL;
182 startup_stack_size = 0;
184 if (config_focus_new) {
187 active = g_hash_table_lookup(window_map, &startup_active);
189 g_assert(WINDOW_IS_CLIENT(active));
190 if (!client_focus(WINDOW_AS_CLIENT(active)))
191 focus_fallback(OB_FOCUS_FALLBACK_NOFOCUS);
193 focus_fallback(OB_FOCUS_FALLBACK_NOFOCUS);
197 void client_manage(Window window)
201 XWindowAttributes attrib;
202 XSetWindowAttributes attrib_set;
204 gboolean activate = FALSE;
208 /* check if it has already been unmapped by the time we started mapping
209 the grab does a sync so we don't have to here */
210 if (XCheckTypedWindowEvent(ob_display, window, DestroyNotify, &e) ||
211 XCheckTypedWindowEvent(ob_display, window, UnmapNotify, &e)) {
212 XPutBackEvent(ob_display, &e);
215 return; /* don't manage it */
218 /* make sure it isn't an override-redirect window */
219 if (!XGetWindowAttributes(ob_display, window, &attrib) ||
220 attrib.override_redirect) {
222 return; /* don't manage it */
225 /* is the window a docking app */
226 if ((wmhint = XGetWMHints(ob_display, window))) {
227 if ((wmhint->flags & StateHint) &&
228 wmhint->initial_state == WithdrawnState) {
229 dock_add(window, wmhint);
237 ob_debug("Managing window: %lx\n", window);
239 /* choose the events we want to receive on the CLIENT window */
240 attrib_set.event_mask = CLIENT_EVENTMASK;
241 attrib_set.do_not_propagate_mask = CLIENT_NOPROPAGATEMASK;
242 XChangeWindowAttributes(ob_display, window,
243 CWEventMask|CWDontPropagate, &attrib_set);
246 /* create the ObClient struct, and populate it from the hints on the
248 self = g_new0(ObClient, 1);
249 self->obwin.type = Window_Client;
250 self->window = window;
252 client_get_all(self);
253 client_restore_session_state(self);
255 client_change_state(self);
257 /* remove the client's border (and adjust re gravity) */
258 client_toggle_border(self, FALSE);
260 /* specify that if we exit, the window should not be destroyed and should
261 be reparented back to root automatically */
262 XChangeSaveSet(ob_display, window, SetModeInsert);
264 /* create the decoration frame for the client window */
265 self->frame = frame_new();
267 frame_grab_client(self->frame, self);
271 client_apply_startup_state(self);
273 /* update the focus lists */
274 focus_order_add_new(self);
276 stacking_add(CLIENT_AS_WINDOW(self));
277 client_restore_session_stacking(self);
279 /* focus the new window? */
280 if (ob_state() != OB_STATE_STARTING && config_focus_new &&
281 /* note the check against Type_Normal/Dialog, not client_normal(self),
282 which would also include other types. in this case we want more
283 strict rules for focus */
284 (self->type == OB_CLIENT_TYPE_NORMAL ||
285 self->type == OB_CLIENT_TYPE_DIALOG))
289 if (self->desktop != screen_desktop) {
290 /* activate the window */
293 gboolean group_foc = FALSE;
298 for (it = self->group->members; it; it = it->next)
300 if (client_focused(it->data))
308 (!self->transient_for && (!self->group ||
309 !self->group->members->next))) ||
310 client_search_focus_tree_full(self) ||
312 !client_normal(focus_client))
314 /* activate the window */
321 if (ob_state() == OB_STATE_RUNNING) {
322 int x = self->area.x, ox = x;
323 int y = self->area.y, oy = y;
325 place_client(self, &x, &y);
327 /* make sure the window is visible */
328 client_find_onscreen(self, &x, &y,
329 self->frame->area.width,
330 self->frame->area.height,
331 client_normal(self));
333 if (x != ox || y != oy)
334 client_move(self, x, y);
337 client_showhide(self);
339 /* use client_focus instead of client_activate cuz client_activate does
340 stuff like switch desktops etc and I'm not interested in all that when
341 a window maps since its not based on an action from the user like
342 clicking a window to activate is. so keep the new window out of the way
344 if (activate) client_focus(self);
346 /* client_activate does this but we aret using it so we have to do it
348 if (screen_showing_desktop)
349 screen_show_desktop(FALSE);
351 /* add to client list/map */
352 client_list = g_list_append(client_list, self);
353 g_hash_table_insert(window_map, &self->window, self);
355 /* this has to happen after we're in the client_list */
356 screen_update_areas();
358 /* update the list hints */
361 keyboard_grab_for_client(self, TRUE);
362 mouse_grab_for_client(self, TRUE);
364 ob_debug("Managed window 0x%lx (%s)\n", window, self->class);
367 void client_unmanage_all()
369 while (client_list != NULL)
370 client_unmanage(client_list->data);
373 void client_unmanage(ObClient *self)
378 ob_debug("Unmanaging window: %lx (%s)\n", self->window, self->class);
380 g_assert(self != NULL);
382 keyboard_grab_for_client(self, FALSE);
383 mouse_grab_for_client(self, FALSE);
385 /* remove the window from our save set */
386 XChangeSaveSet(ob_display, self->window, SetModeDelete);
388 /* we dont want events no more */
389 XSelectInput(ob_display, self->window, NoEventMask);
391 frame_hide(self->frame);
393 client_list = g_list_remove(client_list, self);
394 stacking_remove(self);
395 g_hash_table_remove(window_map, &self->window);
397 /* update the focus lists */
398 focus_order_remove(self);
400 /* once the client is out of the list, update the struts to remove it's
402 screen_update_areas();
404 /* tell our parent(s) that we're gone */
405 if (self->transient_for == OB_TRAN_GROUP) { /* transient of group */
408 for (it = self->group->members; it; it = it->next)
409 if (it->data != self)
410 ((ObClient*)it->data)->transients =
411 g_slist_remove(((ObClient*)it->data)->transients, self);
412 } else if (self->transient_for) { /* transient of window */
413 self->transient_for->transients =
414 g_slist_remove(self->transient_for->transients, self);
417 /* tell our transients that we're gone */
418 for (it = self->transients; it != NULL; it = it->next) {
419 if (((ObClient*)it->data)->transient_for != OB_TRAN_GROUP) {
420 ((ObClient*)it->data)->transient_for = NULL;
421 client_calc_layer(it->data);
425 for (it = client_destructors; it; it = g_slist_next(it)) {
426 ObClientDestructorFunc func = (ObClientDestructorFunc) it->data;
430 if (focus_client == self) {
433 /* focus the last focused window on the desktop, and ignore enter
434 events from the unmap so it doesnt mess with the focus */
435 while (XCheckTypedEvent(ob_display, EnterNotify, &e));
436 client_unfocus(self);
439 /* remove from its group */
441 group_remove(self->group, self);
445 /* give the client its border back */
446 client_toggle_border(self, TRUE);
448 /* reparent the window out of the frame, and free the frame */
449 frame_release_client(self->frame, self);
452 if (ob_state() != OB_STATE_EXITING) {
453 /* these values should not be persisted across a window
455 PROP_ERASE(self->window, net_wm_desktop);
456 PROP_ERASE(self->window, net_wm_state);
457 PROP_ERASE(self->window, wm_state);
459 /* if we're left in an iconic state, the client wont be mapped. this is
460 bad, since we will no longer be managing the window on restart */
462 XMapWindow(ob_display, self->window);
466 ob_debug("Unmanaged window 0x%lx\n", self->window);
468 /* free all data allocated in the client struct */
469 g_slist_free(self->transients);
470 for (j = 0; j < self->nicons; ++j)
471 g_free(self->icons[j].data);
472 if (self->nicons > 0)
475 g_free(self->icon_title);
481 /* update the list hints */
485 static void client_act_urgent(ObClient *self)
489 for (it = config_urgent_actions; it; it = g_slist_next(it)) {
490 ObAction *a = it->data;
492 a->data.any.c = self;
497 static void client_restore_session_state(ObClient *self)
501 if (!(it = session_state_find(self)))
504 self->session = it->data;
506 RECT_SET(self->area, self->session->x, self->session->y,
507 self->session->w, self->session->h);
508 self->positioned = TRUE;
509 XResizeWindow(ob_display, self->window,
510 self->session->w, self->session->h);
512 self->desktop = (self->session->desktop == DESKTOP_ALL ?
513 self->session->desktop :
514 MIN(screen_num_desktops - 1, self->session->desktop));
515 PROP_SET32(self->window, net_wm_desktop, cardinal, self->desktop);
517 self->shaded = self->session->shaded;
518 self->iconic = self->session->iconic;
519 self->skip_pager = self->session->skip_pager;
520 self->skip_taskbar = self->session->skip_taskbar;
521 self->fullscreen = self->session->fullscreen;
522 self->above = self->session->above;
523 self->below = self->session->below;
524 self->max_horz = self->session->max_horz;
525 self->max_vert = self->session->max_vert;
528 static void client_restore_session_stacking(ObClient *self)
532 if (!self->session) return;
534 it = g_list_find(session_saved_state, self->session);
535 for (it = g_list_previous(it); it; it = g_list_previous(it)) {
538 for (cit = client_list; cit; cit = g_list_next(cit))
539 if (session_state_cmp(it->data, cit->data))
542 client_calc_layer(self);
543 stacking_below(CLIENT_AS_WINDOW(self),
544 CLIENT_AS_WINDOW(cit->data));
550 void client_move_onscreen(ObClient *self, gboolean rude)
552 int x = self->area.x;
553 int y = self->area.y;
554 if (client_find_onscreen(self, &x, &y,
555 self->frame->area.width,
556 self->frame->area.height, rude)) {
557 client_move(self, x, y);
561 gboolean client_find_onscreen(ObClient *self, int *x, int *y, int w, int h,
565 int ox = *x, oy = *y;
567 frame_client_gravity(self->frame, x, y); /* get where the frame
570 /* XXX watch for xinerama dead areas */
572 a = screen_area(self->desktop);
573 if (!self->strut.right && *x >= a->x + a->width - 1)
574 *x = a->x + a->width - self->frame->area.width;
575 if (!self->strut.bottom && *y >= a->y + a->height - 1)
576 *y = a->y + a->height - self->frame->area.height;
577 if (!self->strut.left && *x + self->frame->area.width - 1 < a->x)
579 if (!self->strut.top && *y + self->frame->area.height - 1 < a->y)
583 /* this is my MOZILLA BITCHSLAP. oh ya it fucking feels good.
584 Java can suck it too. */
586 /* dont let windows map/move into the strut unless they
587 are bigger than the available area */
589 if (!self->strut.left && *x < a->x) *x = a->x;
590 if (!self->strut.right && *x + w > a->x + a->width)
591 *x = a->x + a->width - w;
593 if (h <= a->height) {
594 if (!self->strut.top && *y < a->y) *y = a->y;
595 if (!self->strut.bottom && *y + h > a->y + a->height)
596 *y = a->y + a->height - h;
600 frame_frame_gravity(self->frame, x, y); /* get where the client
603 return ox != *x || oy != *y;
606 static void client_toggle_border(ObClient *self, gboolean show)
608 /* adjust our idea of where the client is, based on its border. When the
609 border is removed, the client should now be considered to be in a
611 when re-adding the border to the client, the same operation needs to be
613 int oldx = self->area.x, oldy = self->area.y;
614 int x = oldx, y = oldy;
615 switch(self->gravity) {
617 case NorthWestGravity:
619 case SouthWestGravity:
621 case NorthEastGravity:
623 case SouthEastGravity:
624 if (show) x -= self->border_width * 2;
625 else x += self->border_width * 2;
632 if (show) x -= self->border_width;
633 else x += self->border_width;
636 switch(self->gravity) {
638 case NorthWestGravity:
640 case NorthEastGravity:
642 case SouthWestGravity:
644 case SouthEastGravity:
645 if (show) y -= self->border_width * 2;
646 else y += self->border_width * 2;
653 if (show) y -= self->border_width;
654 else y += self->border_width;
661 XSetWindowBorderWidth(ob_display, self->window, self->border_width);
663 /* move the client so it is back it the right spot _with_ its
665 if (x != oldx || y != oldy)
666 XMoveWindow(ob_display, self->window, x, y);
668 XSetWindowBorderWidth(ob_display, self->window, 0);
672 static void client_get_all(ObClient *self)
674 /* non-zero defaults */
675 self->title_count = 1;
676 self->wmstate = NormalState;
678 self->decorate = TRUE;
680 client_get_area(self);
681 client_update_transient_for(self);
682 client_update_wmhints(self);
683 client_get_desktop(self);
684 client_get_state(self);
685 client_get_shaped(self);
687 client_get_mwm_hints(self);
688 client_get_type(self);/* this can change the mwmhints for special cases */
690 client_update_protocols(self);
692 client_get_gravity(self); /* get the attribute gravity */
693 client_update_normal_hints(self); /* this may override the attribute
696 /* got the type, the mwmhints, the protocols, and the normal hints
697 (min/max sizes), so we're ready to set up the decorations/functions */
698 client_setup_decor_and_functions(self);
700 client_update_title(self);
701 client_update_class(self);
702 client_update_strut(self);
703 client_update_icons(self);
706 static void client_get_area(ObClient *self)
708 XWindowAttributes wattrib;
711 ret = XGetWindowAttributes(ob_display, self->window, &wattrib);
712 g_assert(ret != BadWindow);
714 RECT_SET(self->area, wattrib.x, wattrib.y, wattrib.width, wattrib.height);
715 self->border_width = wattrib.border_width;
718 static void client_get_desktop(ObClient *self)
720 guint32 d = screen_num_desktops; /* an always-invalid value */
722 if (PROP_GET32(self->window, net_wm_desktop, cardinal, &d)) {
723 if (d >= screen_num_desktops && d != DESKTOP_ALL)
724 self->desktop = screen_num_desktops - 1;
728 gboolean trdesk = FALSE;
730 if (self->transient_for) {
731 if (self->transient_for != OB_TRAN_GROUP) {
732 self->desktop = self->transient_for->desktop;
737 for (it = self->group->members; it; it = it->next)
738 if (it->data != self &&
739 !((ObClient*)it->data)->transient_for) {
740 self->desktop = ((ObClient*)it->data)->desktop;
747 /* defaults to the current desktop */
748 self->desktop = screen_desktop;
750 if (self->desktop != d) {
751 /* set the desktop hint, to make sure that it always exists */
752 PROP_SET32(self->window, net_wm_desktop, cardinal, self->desktop);
756 static void client_get_state(ObClient *self)
761 self->modal = self->shaded = self->max_horz = self->max_vert =
762 self->fullscreen = self->above = self->below = self->iconic =
763 self->skip_taskbar = self->skip_pager = FALSE;
765 if (PROP_GETA32(self->window, net_wm_state, atom, &state, &num)) {
767 for (i = 0; i < num; ++i) {
768 if (state[i] == prop_atoms.net_wm_state_modal)
770 else if (state[i] == prop_atoms.net_wm_state_shaded)
772 else if (state[i] == prop_atoms.net_wm_state_hidden)
774 else if (state[i] == prop_atoms.net_wm_state_skip_taskbar)
775 self->skip_taskbar = TRUE;
776 else if (state[i] == prop_atoms.net_wm_state_skip_pager)
777 self->skip_pager = TRUE;
778 else if (state[i] == prop_atoms.net_wm_state_fullscreen)
779 self->fullscreen = TRUE;
780 else if (state[i] == prop_atoms.net_wm_state_maximized_vert)
781 self->max_vert = TRUE;
782 else if (state[i] == prop_atoms.net_wm_state_maximized_horz)
783 self->max_horz = TRUE;
784 else if (state[i] == prop_atoms.net_wm_state_above)
786 else if (state[i] == prop_atoms.net_wm_state_below)
794 static void client_get_shaped(ObClient *self)
796 self->shaped = FALSE;
798 if (extensions_shape) {
803 XShapeSelectInput(ob_display, self->window, ShapeNotifyMask);
805 XShapeQueryExtents(ob_display, self->window, &s, &foo,
806 &foo, &ufoo, &ufoo, &foo, &foo, &foo, &ufoo,
808 self->shaped = (s != 0);
813 void client_update_transient_for(ObClient *self)
816 ObClient *target = NULL;
818 if (XGetTransientForHint(ob_display, self->window, &t)) {
819 self->transient = TRUE;
820 if (t != self->window) { /* cant be transient to itself! */
821 target = g_hash_table_lookup(window_map, &t);
822 /* if this happens then we need to check for it*/
823 g_assert(target != self);
824 g_assert(!target || WINDOW_IS_CLIENT(target));
826 if (!target && self->group) {
827 /* not transient to a client, see if it is transient for a
829 if (t == self->group->leader ||
831 t == RootWindow(ob_display, ob_screen)) {
832 /* window is a transient for its group! */
833 target = OB_TRAN_GROUP;
838 self->transient = FALSE;
840 /* if anything has changed... */
841 if (target != self->transient_for) {
842 if (self->transient_for == OB_TRAN_GROUP) { /* transient of group */
845 /* remove from old parents */
846 for (it = self->group->members; it; it = g_slist_next(it)) {
847 ObClient *c = it->data;
848 if (c != self && !c->transient_for)
849 c->transients = g_slist_remove(c->transients, self);
851 } else if (self->transient_for != NULL) { /* transient of window */
852 /* remove from old parent */
853 self->transient_for->transients =
854 g_slist_remove(self->transient_for->transients, self);
856 self->transient_for = target;
857 if (self->transient_for == OB_TRAN_GROUP) { /* transient of group */
860 /* add to new parents */
861 for (it = self->group->members; it; it = g_slist_next(it)) {
862 ObClient *c = it->data;
863 if (c != self && !c->transient_for)
864 c->transients = g_slist_append(c->transients, self);
867 /* remove all transients which are in the group, that causes
868 circlular pointer hell of doom */
869 for (it = self->group->members; it; it = g_slist_next(it)) {
871 for (sit = self->transients; sit; sit = next) {
872 next = g_slist_next(sit);
873 if (sit->data == it->data)
875 g_slist_delete_link(self->transients, sit);
878 } else if (self->transient_for != NULL) { /* transient of window */
879 /* add to new parent */
880 self->transient_for->transients =
881 g_slist_append(self->transient_for->transients, self);
886 static void client_get_mwm_hints(ObClient *self)
891 self->mwmhints.flags = 0; /* default to none */
893 if (PROP_GETA32(self->window, motif_wm_hints, motif_wm_hints,
895 if (num >= OB_MWM_ELEMENTS) {
896 self->mwmhints.flags = hints[0];
897 self->mwmhints.functions = hints[1];
898 self->mwmhints.decorations = hints[2];
904 void client_get_type(ObClient *self)
911 if (PROP_GETA32(self->window, net_wm_window_type, atom, &val, &num)) {
912 /* use the first value that we know about in the array */
913 for (i = 0; i < num; ++i) {
914 if (val[i] == prop_atoms.net_wm_window_type_desktop)
915 self->type = OB_CLIENT_TYPE_DESKTOP;
916 else if (val[i] == prop_atoms.net_wm_window_type_dock)
917 self->type = OB_CLIENT_TYPE_DOCK;
918 else if (val[i] == prop_atoms.net_wm_window_type_toolbar)
919 self->type = OB_CLIENT_TYPE_TOOLBAR;
920 else if (val[i] == prop_atoms.net_wm_window_type_menu)
921 self->type = OB_CLIENT_TYPE_MENU;
922 else if (val[i] == prop_atoms.net_wm_window_type_utility)
923 self->type = OB_CLIENT_TYPE_UTILITY;
924 else if (val[i] == prop_atoms.net_wm_window_type_splash)
925 self->type = OB_CLIENT_TYPE_SPLASH;
926 else if (val[i] == prop_atoms.net_wm_window_type_dialog)
927 self->type = OB_CLIENT_TYPE_DIALOG;
928 else if (val[i] == prop_atoms.net_wm_window_type_normal)
929 self->type = OB_CLIENT_TYPE_NORMAL;
930 else if (val[i] == prop_atoms.kde_net_wm_window_type_override) {
931 /* prevent this window from getting any decor or
933 self->mwmhints.flags &= (OB_MWM_FLAG_FUNCTIONS |
934 OB_MWM_FLAG_DECORATIONS);
935 self->mwmhints.decorations = 0;
936 self->mwmhints.functions = 0;
938 if (self->type != (ObClientType) -1)
939 break; /* grab the first legit type */
944 if (self->type == (ObClientType) -1) {
945 /*the window type hint was not set, which means we either classify
946 ourself as a normal window or a dialog, depending on if we are a
949 self->type = OB_CLIENT_TYPE_DIALOG;
951 self->type = OB_CLIENT_TYPE_NORMAL;
955 void client_update_protocols(ObClient *self)
960 self->focus_notify = FALSE;
961 self->delete_window = FALSE;
963 if (PROP_GETA32(self->window, wm_protocols, atom, &proto, &num_return)) {
964 for (i = 0; i < num_return; ++i) {
965 if (proto[i] == prop_atoms.wm_delete_window) {
966 /* this means we can request the window to close */
967 self->delete_window = TRUE;
968 } else if (proto[i] == prop_atoms.wm_take_focus)
969 /* if this protocol is requested, then the window will be
970 notified whenever we want it to receive focus */
971 self->focus_notify = TRUE;
977 static void client_get_gravity(ObClient *self)
979 XWindowAttributes wattrib;
982 ret = XGetWindowAttributes(ob_display, self->window, &wattrib);
983 g_assert(ret != BadWindow);
984 self->gravity = wattrib.win_gravity;
987 void client_update_normal_hints(ObClient *self)
991 int oldgravity = self->gravity;
994 self->min_ratio = 0.0f;
995 self->max_ratio = 0.0f;
996 SIZE_SET(self->size_inc, 1, 1);
997 SIZE_SET(self->base_size, 0, 0);
998 SIZE_SET(self->min_size, 0, 0);
999 SIZE_SET(self->max_size, G_MAXINT, G_MAXINT);
1001 /* get the hints from the window */
1002 if (XGetWMNormalHints(ob_display, self->window, &size, &ret)) {
1003 self->positioned = !!(size.flags & (PPosition|USPosition));
1005 if (size.flags & PWinGravity) {
1006 self->gravity = size.win_gravity;
1008 /* if the client has a frame, i.e. has already been mapped and
1009 is changing its gravity */
1010 if (self->frame && self->gravity != oldgravity) {
1011 /* move our idea of the client's position based on its new
1013 self->area.x = self->frame->area.x;
1014 self->area.y = self->frame->area.y;
1015 frame_frame_gravity(self->frame, &self->area.x, &self->area.y);
1019 if (size.flags & PAspect) {
1020 if (size.min_aspect.y)
1021 self->min_ratio = (float)size.min_aspect.x / size.min_aspect.y;
1022 if (size.max_aspect.y)
1023 self->max_ratio = (float)size.max_aspect.x / size.max_aspect.y;
1026 if (size.flags & PMinSize)
1027 SIZE_SET(self->min_size, size.min_width, size.min_height);
1029 if (size.flags & PMaxSize)
1030 SIZE_SET(self->max_size, size.max_width, size.max_height);
1032 if (size.flags & PBaseSize)
1033 SIZE_SET(self->base_size, size.base_width, size.base_height);
1035 if (size.flags & PResizeInc)
1036 SIZE_SET(self->size_inc, size.width_inc, size.height_inc);
1040 void client_setup_decor_and_functions(ObClient *self)
1042 /* start with everything (cept fullscreen) */
1044 (OB_FRAME_DECOR_TITLEBAR |
1045 (ob_rr_theme->show_handle ? OB_FRAME_DECOR_HANDLE : 0) |
1046 OB_FRAME_DECOR_GRIPS |
1047 OB_FRAME_DECOR_BORDER |
1048 OB_FRAME_DECOR_ICON |
1049 OB_FRAME_DECOR_ALLDESKTOPS |
1050 OB_FRAME_DECOR_ICONIFY |
1051 OB_FRAME_DECOR_MAXIMIZE |
1052 OB_FRAME_DECOR_SHADE);
1054 (OB_CLIENT_FUNC_RESIZE |
1055 OB_CLIENT_FUNC_MOVE |
1056 OB_CLIENT_FUNC_ICONIFY |
1057 OB_CLIENT_FUNC_MAXIMIZE |
1058 OB_CLIENT_FUNC_SHADE);
1059 if (self->delete_window) {
1060 self->functions |= OB_CLIENT_FUNC_CLOSE;
1061 self->decorations |= OB_FRAME_DECOR_CLOSE;
1064 if (!(self->min_size.width < self->max_size.width ||
1065 self->min_size.height < self->max_size.height))
1066 self->functions &= ~OB_CLIENT_FUNC_RESIZE;
1068 switch (self->type) {
1069 case OB_CLIENT_TYPE_NORMAL:
1070 /* normal windows retain all of the possible decorations and
1071 functionality, and are the only windows that you can fullscreen */
1072 self->functions |= OB_CLIENT_FUNC_FULLSCREEN;
1075 case OB_CLIENT_TYPE_DIALOG:
1076 case OB_CLIENT_TYPE_UTILITY:
1077 /* these windows cannot be maximized */
1078 self->functions &= ~OB_CLIENT_FUNC_MAXIMIZE;
1081 case OB_CLIENT_TYPE_MENU:
1082 case OB_CLIENT_TYPE_TOOLBAR:
1083 /* these windows get less functionality */
1084 self->functions &= ~(OB_CLIENT_FUNC_ICONIFY | OB_CLIENT_FUNC_RESIZE);
1087 case OB_CLIENT_TYPE_DESKTOP:
1088 case OB_CLIENT_TYPE_DOCK:
1089 case OB_CLIENT_TYPE_SPLASH:
1090 /* none of these windows are manipulated by the window manager */
1091 self->decorations = 0;
1092 self->functions = 0;
1096 /* Mwm Hints are applied subtractively to what has already been chosen for
1097 decor and functionality */
1098 if (self->mwmhints.flags & OB_MWM_FLAG_DECORATIONS) {
1099 if (! (self->mwmhints.decorations & OB_MWM_DECOR_ALL)) {
1100 if (! ((self->mwmhints.decorations & OB_MWM_DECOR_HANDLE) ||
1101 (self->mwmhints.decorations & OB_MWM_DECOR_TITLE)))
1102 /* if the mwm hints request no handle or title, then all
1103 decorations are disabled */
1104 self->decorations = 0;
1108 if (self->mwmhints.flags & OB_MWM_FLAG_FUNCTIONS) {
1109 if (! (self->mwmhints.functions & OB_MWM_FUNC_ALL)) {
1110 if (! (self->mwmhints.functions & OB_MWM_FUNC_RESIZE))
1111 self->functions &= ~OB_CLIENT_FUNC_RESIZE;
1112 if (! (self->mwmhints.functions & OB_MWM_FUNC_MOVE))
1113 self->functions &= ~OB_CLIENT_FUNC_MOVE;
1114 /* dont let mwm hints kill any buttons
1115 if (! (self->mwmhints.functions & OB_MWM_FUNC_ICONIFY))
1116 self->functions &= ~OB_CLIENT_FUNC_ICONIFY;
1117 if (! (self->mwmhints.functions & OB_MWM_FUNC_MAXIMIZE))
1118 self->functions &= ~OB_CLIENT_FUNC_MAXIMIZE;
1120 /* dont let mwm hints kill the close button
1121 if (! (self->mwmhints.functions & MwmFunc_Close))
1122 self->functions &= ~OB_CLIENT_FUNC_CLOSE; */
1126 if (!(self->functions & OB_CLIENT_FUNC_SHADE))
1127 self->decorations &= ~OB_FRAME_DECOR_SHADE;
1128 if (!(self->functions & OB_CLIENT_FUNC_ICONIFY))
1129 self->decorations &= ~OB_FRAME_DECOR_ICONIFY;
1130 if (!(self->functions & OB_CLIENT_FUNC_RESIZE))
1131 self->decorations &= ~OB_FRAME_DECOR_GRIPS;
1133 /* can't maximize without moving/resizing */
1134 if (!((self->functions & OB_CLIENT_FUNC_MAXIMIZE) &&
1135 (self->functions & OB_CLIENT_FUNC_MOVE) &&
1136 (self->functions & OB_CLIENT_FUNC_RESIZE))) {
1137 self->functions &= ~OB_CLIENT_FUNC_MAXIMIZE;
1138 self->decorations &= ~OB_FRAME_DECOR_MAXIMIZE;
1141 /* kill the handle on fully maxed windows */
1142 if (self->max_vert && self->max_horz)
1143 self->decorations &= ~OB_FRAME_DECOR_HANDLE;
1145 /* finally, the user can have requested no decorations, which overrides
1147 if (!self->decorate)
1148 self->decorations = OB_FRAME_DECOR_BORDER;
1150 /* if we don't have a titlebar, then we cannot shade! */
1151 if (!(self->decorations & OB_FRAME_DECOR_TITLEBAR))
1152 self->functions &= ~OB_CLIENT_FUNC_SHADE;
1154 /* now we need to check against rules for the client's current state */
1155 if (self->fullscreen) {
1156 self->functions &= (OB_CLIENT_FUNC_CLOSE |
1157 OB_CLIENT_FUNC_FULLSCREEN |
1158 OB_CLIENT_FUNC_ICONIFY);
1159 self->decorations = 0;
1162 client_change_allowed_actions(self);
1165 /* adjust the client's decorations, etc. */
1166 client_reconfigure(self);
1168 /* this makes sure that these windows appear on all desktops */
1169 if (self->type == OB_CLIENT_TYPE_DESKTOP &&
1170 self->desktop != DESKTOP_ALL)
1172 self->desktop = DESKTOP_ALL;
1177 static void client_change_allowed_actions(ObClient *self)
1182 /* desktop windows are kept on all desktops */
1183 if (self->type != OB_CLIENT_TYPE_DESKTOP)
1184 actions[num++] = prop_atoms.net_wm_action_change_desktop;
1186 if (self->functions & OB_CLIENT_FUNC_SHADE)
1187 actions[num++] = prop_atoms.net_wm_action_shade;
1188 if (self->functions & OB_CLIENT_FUNC_CLOSE)
1189 actions[num++] = prop_atoms.net_wm_action_close;
1190 if (self->functions & OB_CLIENT_FUNC_MOVE)
1191 actions[num++] = prop_atoms.net_wm_action_move;
1192 if (self->functions & OB_CLIENT_FUNC_ICONIFY)
1193 actions[num++] = prop_atoms.net_wm_action_minimize;
1194 if (self->functions & OB_CLIENT_FUNC_RESIZE)
1195 actions[num++] = prop_atoms.net_wm_action_resize;
1196 if (self->functions & OB_CLIENT_FUNC_FULLSCREEN)
1197 actions[num++] = prop_atoms.net_wm_action_fullscreen;
1198 if (self->functions & OB_CLIENT_FUNC_MAXIMIZE) {
1199 actions[num++] = prop_atoms.net_wm_action_maximize_horz;
1200 actions[num++] = prop_atoms.net_wm_action_maximize_vert;
1203 PROP_SETA32(self->window, net_wm_allowed_actions, atom, actions, num);
1205 /* make sure the window isn't breaking any rules now */
1207 if (!(self->functions & OB_CLIENT_FUNC_SHADE) && self->shaded) {
1208 if (self->frame) client_shade(self, FALSE);
1209 else self->shaded = FALSE;
1211 if (!(self->functions & OB_CLIENT_FUNC_ICONIFY) && self->iconic) {
1212 if (self->frame) client_iconify(self, FALSE, TRUE);
1213 else self->iconic = FALSE;
1215 if (!(self->functions & OB_CLIENT_FUNC_FULLSCREEN) && self->fullscreen) {
1216 if (self->frame) client_fullscreen(self, FALSE, TRUE);
1217 else self->fullscreen = FALSE;
1219 if (!(self->functions & OB_CLIENT_FUNC_MAXIMIZE) && (self->max_horz ||
1221 if (self->frame) client_maximize(self, FALSE, 0, TRUE);
1222 else self->max_vert = self->max_horz = FALSE;
1226 void client_reconfigure(ObClient *self)
1228 /* by making this pass FALSE for user, we avoid the emacs event storm where
1229 every configurenotify causes an update in its normal hints, i think this
1230 is generally what we want anyways... */
1231 client_configure(self, OB_CORNER_TOPLEFT, self->area.x, self->area.y,
1232 self->area.width, self->area.height, FALSE, TRUE);
1235 void client_update_wmhints(ObClient *self)
1238 gboolean ur = FALSE;
1241 /* assume a window takes input if it doesnt specify */
1242 self->can_focus = TRUE;
1244 if ((hints = XGetWMHints(ob_display, self->window)) != NULL) {
1245 if (hints->flags & InputHint)
1246 self->can_focus = hints->input;
1248 /* only do this when first managing the window *AND* when we aren't
1250 if (ob_state() != OB_STATE_STARTING && self->frame == NULL)
1251 if (hints->flags & StateHint)
1252 self->iconic = hints->initial_state == IconicState;
1254 if (hints->flags & XUrgencyHint)
1257 if (!(hints->flags & WindowGroupHint))
1258 hints->window_group = None;
1260 /* did the group state change? */
1261 if (hints->window_group !=
1262 (self->group ? self->group->leader : None)) {
1263 /* remove from the old group if there was one */
1264 if (self->group != NULL) {
1265 /* remove transients of the group */
1266 for (it = self->group->members; it; it = it->next)
1267 self->transients = g_slist_remove(self->transients,
1269 group_remove(self->group, self);
1272 if (hints->window_group != None) {
1273 self->group = group_add(hints->window_group, self);
1275 /* i can only have transients from the group if i am not
1277 if (!self->transient_for) {
1278 /* add other transients of the group that are already
1280 for (it = self->group->members; it; it = it->next) {
1281 ObClient *c = it->data;
1282 if (c != self && c->transient_for == OB_TRAN_GROUP)
1284 g_slist_append(self->transients, c);
1289 /* because the self->transient flag wont change from this call,
1290 we don't need to update the window's type and such, only its
1291 transient_for, and the transients lists of other windows in
1292 the group may be affected */
1293 client_update_transient_for(self);
1296 /* the WM_HINTS can contain an icon */
1297 client_update_icons(self);
1302 if (ur != self->urgent) {
1304 ob_debug("Urgent Hint for 0x%lx: %s\n", self->window,
1306 /* fire the urgent callback if we're mapped, otherwise, wait until
1307 after we're mapped */
1308 if (self->frame && self->urgent)
1309 client_act_urgent(self);
1313 void client_update_title(ObClient *self)
1319 gboolean read_title;
1321 g_free(self->title);
1324 if (!PROP_GETS(self->window, net_wm_name, utf8, &data))
1325 /* try old x stuff */
1326 if (!PROP_GETS(self->window, wm_name, locale, &data))
1327 data = g_strdup("Unnamed Window");
1329 /* look for duplicates and append a number */
1331 for (it = client_list; it; it = it->next)
1332 if (it->data != self) {
1333 ObClient *c = it->data;
1334 if (0 == strncmp(c->title, data, strlen(data)))
1335 nums |= 1 << c->title_count;
1337 /* find first free number */
1338 for (i = 1; i <= 32; ++i)
1339 if (!(nums & (1 << i))) {
1340 if (self->title_count == 1 || i == 1)
1341 self->title_count = i;
1344 /* dont display the number for the first window */
1345 if (self->title_count > 1) {
1346 char *vdata, *ndata;
1347 ndata = g_strdup_printf(" - [%u]", self->title_count);
1348 vdata = g_strconcat(data, ndata, NULL);
1354 PROP_SETS(self->window, net_wm_visible_name, data);
1359 frame_adjust_title(self->frame);
1361 /* update the icon title */
1363 g_free(self->icon_title);
1367 if (!PROP_GETS(self->window, net_wm_icon_name, utf8, &data))
1368 /* try old x stuff */
1369 if (!PROP_GETS(self->window, wm_icon_name, locale, &data)) {
1370 data = g_strdup(self->title);
1374 /* append the title count, dont display the number for the first window */
1375 if (read_title && self->title_count > 1) {
1376 char *vdata, *ndata;
1377 ndata = g_strdup_printf(" - [%u]", self->title_count);
1378 vdata = g_strconcat(data, ndata, NULL);
1384 PROP_SETS(self->window, net_wm_visible_icon_name, data);
1386 self->icon_title = data;
1389 void client_update_class(ObClient *self)
1394 if (self->name) g_free(self->name);
1395 if (self->class) g_free(self->class);
1396 if (self->role) g_free(self->role);
1398 self->name = self->class = self->role = NULL;
1400 if (PROP_GETSS(self->window, wm_class, locale, &data)) {
1402 self->name = g_strdup(data[0]);
1404 self->class = g_strdup(data[1]);
1409 if (PROP_GETS(self->window, wm_window_role, locale, &s))
1410 self->role = g_strdup(s);
1412 if (self->name == NULL) self->name = g_strdup("");
1413 if (self->class == NULL) self->class = g_strdup("");
1414 if (self->role == NULL) self->role = g_strdup("");
1417 void client_update_strut(ObClient *self)
1421 gboolean got = FALSE;
1424 if (PROP_GETA32(self->window, net_wm_strut_partial, cardinal,
1428 STRUT_PARTIAL_SET(strut,
1429 data[0], data[2], data[1], data[3],
1430 data[4], data[5], data[8], data[9],
1431 data[6], data[7], data[10], data[11]);
1437 PROP_GETA32(self->window, net_wm_strut, cardinal, &data, &num)) {
1440 STRUT_PARTIAL_SET(strut,
1441 data[0], data[2], data[1], data[3],
1442 0, 0, 0, 0, 0, 0, 0, 0);
1448 STRUT_PARTIAL_SET(strut, 0, 0, 0, 0,
1449 0, 0, 0, 0, 0, 0, 0, 0);
1451 if (!STRUT_EQUAL(strut, self->strut)) {
1452 self->strut = strut;
1454 /* updating here is pointless while we're being mapped cuz we're not in
1455 the client list yet */
1457 screen_update_areas();
1461 void client_update_icons(ObClient *self)
1467 for (i = 0; i < self->nicons; ++i)
1468 g_free(self->icons[i].data);
1469 if (self->nicons > 0)
1470 g_free(self->icons);
1473 if (PROP_GETA32(self->window, net_wm_icon, cardinal, &data, &num)) {
1474 /* figure out how many valid icons are in here */
1476 while (num - i > 2) {
1480 if (i > num || w*h == 0) break;
1484 self->icons = g_new(ObClientIcon, self->nicons);
1486 /* store the icons */
1488 for (j = 0; j < self->nicons; ++j) {
1491 w = self->icons[j].width = data[i++];
1492 h = self->icons[j].height = data[i++];
1494 if (w*h == 0) continue;
1496 self->icons[j].data = g_new(RrPixel32, w * h);
1497 for (x = 0, y = 0, t = 0; t < w * h; ++t, ++x, ++i) {
1502 self->icons[j].data[t] =
1503 (((data[i] >> 24) & 0xff) << RrDefaultAlphaOffset) +
1504 (((data[i] >> 16) & 0xff) << RrDefaultRedOffset) +
1505 (((data[i] >> 8) & 0xff) << RrDefaultGreenOffset) +
1506 (((data[i] >> 0) & 0xff) << RrDefaultBlueOffset);
1512 } else if (PROP_GETA32(self->window, kwm_win_icon,
1513 kwm_win_icon, &data, &num)) {
1516 self->icons = g_new(ObClientIcon, self->nicons);
1517 xerror_set_ignore(TRUE);
1518 if (!RrPixmapToRGBA(ob_rr_inst,
1520 &self->icons[self->nicons-1].width,
1521 &self->icons[self->nicons-1].height,
1522 &self->icons[self->nicons-1].data)) {
1523 g_free(&self->icons[self->nicons-1]);
1526 xerror_set_ignore(FALSE);
1532 if ((hints = XGetWMHints(ob_display, self->window))) {
1533 if (hints->flags & IconPixmapHint) {
1535 self->icons = g_new(ObClientIcon, self->nicons);
1536 xerror_set_ignore(TRUE);
1537 if (!RrPixmapToRGBA(ob_rr_inst,
1539 (hints->flags & IconMaskHint ?
1540 hints->icon_mask : None),
1541 &self->icons[self->nicons-1].width,
1542 &self->icons[self->nicons-1].height,
1543 &self->icons[self->nicons-1].data)){
1544 g_free(&self->icons[self->nicons-1]);
1547 xerror_set_ignore(FALSE);
1554 frame_adjust_icon(self->frame);
1557 static void client_change_state(ObClient *self)
1560 guint32 netstate[10];
1563 state[0] = self->wmstate;
1565 PROP_SETA32(self->window, wm_state, wm_state, state, 2);
1569 netstate[num++] = prop_atoms.net_wm_state_modal;
1571 netstate[num++] = prop_atoms.net_wm_state_shaded;
1573 netstate[num++] = prop_atoms.net_wm_state_hidden;
1574 if (self->skip_taskbar)
1575 netstate[num++] = prop_atoms.net_wm_state_skip_taskbar;
1576 if (self->skip_pager)
1577 netstate[num++] = prop_atoms.net_wm_state_skip_pager;
1578 if (self->fullscreen)
1579 netstate[num++] = prop_atoms.net_wm_state_fullscreen;
1581 netstate[num++] = prop_atoms.net_wm_state_maximized_vert;
1583 netstate[num++] = prop_atoms.net_wm_state_maximized_horz;
1585 netstate[num++] = prop_atoms.net_wm_state_above;
1587 netstate[num++] = prop_atoms.net_wm_state_below;
1588 PROP_SETA32(self->window, net_wm_state, atom, netstate, num);
1590 client_calc_layer(self);
1593 frame_adjust_state(self->frame);
1596 ObClient *client_search_focus_tree(ObClient *self)
1601 for (it = self->transients; it != NULL; it = it->next) {
1602 if (client_focused(it->data)) return it->data;
1603 if ((ret = client_search_focus_tree(it->data))) return ret;
1608 ObClient *client_search_focus_tree_full(ObClient *self)
1610 if (self->transient_for) {
1611 if (self->transient_for != OB_TRAN_GROUP) {
1612 return client_search_focus_tree_full(self->transient_for);
1615 gboolean recursed = FALSE;
1617 for (it = self->group->members; it; it = it->next)
1618 if (!((ObClient*)it->data)->transient_for) {
1620 if ((c = client_search_focus_tree_full(it->data)))
1629 /* this function checks the whole tree, the client_search_focus_tree~
1630 does not, so we need to check this window */
1631 if (client_focused(self))
1633 return client_search_focus_tree(self);
1636 static ObStackingLayer calc_layer(ObClient *self)
1640 if (self->fullscreen) l = OB_STACKING_LAYER_FULLSCREEN;
1641 else if (self->type == OB_CLIENT_TYPE_DESKTOP)
1642 l = OB_STACKING_LAYER_DESKTOP;
1643 else if (self->type == OB_CLIENT_TYPE_DOCK) {
1644 if (!self->below) l = OB_STACKING_LAYER_TOP;
1645 else l = OB_STACKING_LAYER_NORMAL;
1647 else if (self->above) l = OB_STACKING_LAYER_ABOVE;
1648 else if (self->below) l = OB_STACKING_LAYER_BELOW;
1649 else l = OB_STACKING_LAYER_NORMAL;
1654 static void client_calc_layer_recursive(ObClient *self, ObClient *orig,
1655 ObStackingLayer l, gboolean raised)
1657 ObStackingLayer old, own;
1661 own = calc_layer(self);
1662 self->layer = l > own ? l : own;
1664 for (it = self->transients; it; it = it->next)
1665 client_calc_layer_recursive(it->data, orig,
1666 l, raised ? raised : l != old);
1668 if (!raised && l != old)
1669 if (orig->frame) { /* only restack if the original window is managed */
1670 /* XXX add_non_intrusive ever? */
1671 stacking_remove(CLIENT_AS_WINDOW(self));
1672 stacking_add(CLIENT_AS_WINDOW(self));
1676 void client_calc_layer(ObClient *self)
1683 /* transients take on the layer of their parents */
1684 self = client_search_top_transient(self);
1686 l = calc_layer(self);
1688 client_calc_layer_recursive(self, orig, l, FALSE);
1691 gboolean client_should_show(ObClient *self)
1693 if (self->iconic) return FALSE;
1694 else if (!(self->desktop == screen_desktop ||
1695 self->desktop == DESKTOP_ALL)) return FALSE;
1696 else if (client_normal(self) && screen_showing_desktop) return FALSE;
1701 static void client_showhide(ObClient *self)
1704 if (client_should_show(self))
1705 frame_show(self->frame);
1707 frame_hide(self->frame);
1710 gboolean client_normal(ObClient *self) {
1711 return ! (self->type == OB_CLIENT_TYPE_DESKTOP ||
1712 self->type == OB_CLIENT_TYPE_DOCK ||
1713 self->type == OB_CLIENT_TYPE_SPLASH);
1716 static void client_apply_startup_state(ObClient *self)
1718 /* these are in a carefully crafted order.. */
1721 self->iconic = FALSE;
1722 client_iconify(self, TRUE, FALSE);
1724 if (self->fullscreen) {
1725 self->fullscreen = FALSE;
1726 client_fullscreen(self, TRUE, FALSE);
1729 self->shaded = FALSE;
1730 client_shade(self, TRUE);
1733 client_act_urgent(self);
1735 if (self->max_vert && self->max_horz) {
1736 self->max_vert = self->max_horz = FALSE;
1737 client_maximize(self, TRUE, 0, FALSE);
1738 } else if (self->max_vert) {
1739 self->max_vert = FALSE;
1740 client_maximize(self, TRUE, 2, FALSE);
1741 } else if (self->max_horz) {
1742 self->max_horz = FALSE;
1743 client_maximize(self, TRUE, 1, FALSE);
1746 /* nothing to do for the other states:
1755 void client_configure_full(ObClient *self, ObCorner anchor,
1756 int x, int y, int w, int h,
1757 gboolean user, gboolean final,
1758 gboolean force_reply)
1760 gboolean moved = FALSE, resized = FALSE;
1761 guint fdecor = self->frame->decorations;
1762 gboolean fhorz = self->frame->max_horz;
1764 /* make the frame recalculate its dimentions n shit without changing
1765 anything visible for real, this way the constraints below can work with
1766 the updated frame dimensions. */
1767 frame_adjust_area(self->frame, TRUE, TRUE, TRUE);
1769 /* gets the frame's position */
1770 frame_client_gravity(self->frame, &x, &y);
1772 /* these positions are frame positions, not client positions */
1774 /* set the size and position if fullscreen */
1775 if (self->fullscreen) {
1778 XF86VidModeModeLine mode;
1783 i = client_monitor(self);
1784 a = screen_physical_area_monitor(i);
1787 if (i == 0 && /* primary head */
1788 extensions_vidmode &&
1789 XF86VidModeGetViewPort(ob_display, ob_screen, &x, &y) &&
1790 /* get the mode last so the mode.privsize isnt freed incorrectly */
1791 XF86VidModeGetModeLine(ob_display, ob_screen, &dot, &mode)) {
1796 if (mode.privsize) XFree(mode.private);
1806 user = FALSE; /* ignore that increment etc shit when in fullscreen */
1810 a = screen_area_monitor(self->desktop, client_monitor(self));
1812 /* set the size and position if maximized */
1813 if (self->max_horz) {
1815 w = a->width - self->frame->size.left - self->frame->size.right;
1817 if (self->max_vert) {
1819 h = a->height - self->frame->size.top - self->frame->size.bottom;
1823 /* gets the client's position */
1824 frame_frame_gravity(self->frame, &x, &y);
1826 /* these override the above states! if you cant move you can't move! */
1828 if (!(self->functions & OB_CLIENT_FUNC_MOVE)) {
1832 if (!(self->functions & OB_CLIENT_FUNC_RESIZE)) {
1833 w = self->area.width;
1834 h = self->area.height;
1838 if (!(w == self->area.width && h == self->area.height)) {
1839 int basew, baseh, minw, minh;
1842 /* base size is substituted with min size if not specified */
1843 if (self->base_size.width || self->base_size.height) {
1844 basew = self->base_size.width;
1845 baseh = self->base_size.height;
1847 basew = self->min_size.width;
1848 baseh = self->min_size.height;
1850 /* min size is substituted with base size if not specified */
1851 if (self->min_size.width || self->min_size.height) {
1852 minw = self->min_size.width;
1853 minh = self->min_size.height;
1855 minw = self->base_size.width;
1856 minh = self->base_size.height;
1859 /* for interactive resizing. have to move half an increment in each
1862 /* how far we are towards the next size inc */
1863 mw = (w - basew) % self->size_inc.width;
1864 mh = (h - baseh) % self->size_inc.height;
1866 aw = self->size_inc.width / 2;
1867 ah = self->size_inc.height / 2;
1868 /* don't let us move into a new size increment */
1869 if (mw + aw >= self->size_inc.width)
1870 aw = self->size_inc.width - mw - 1;
1871 if (mh + ah >= self->size_inc.height)
1872 ah = self->size_inc.height - mh - 1;
1876 /* if this is a user-requested resize, then check against min/max
1879 /* smaller than min size or bigger than max size? */
1880 if (w > self->max_size.width) w = self->max_size.width;
1881 if (w < minw) w = minw;
1882 if (h > self->max_size.height) h = self->max_size.height;
1883 if (h < minh) h = minh;
1888 /* keep to the increments */
1889 w /= self->size_inc.width;
1890 h /= self->size_inc.height;
1892 /* you cannot resize to nothing */
1893 if (basew + w < 1) w = 1 - basew;
1894 if (baseh + h < 1) h = 1 - baseh;
1896 /* store the logical size */
1897 SIZE_SET(self->logical_size,
1898 self->size_inc.width > 1 ? w : w + basew,
1899 self->size_inc.height > 1 ? h : h + baseh);
1901 w *= self->size_inc.width;
1902 h *= self->size_inc.height;
1907 /* adjust the height to match the width for the aspect ratios.
1908 for this, min size is not substituted for base size ever. */
1909 w -= self->base_size.width;
1910 h -= self->base_size.height;
1912 if (self->min_ratio)
1913 if (h * self->min_ratio > w) h = (int)(w / self->min_ratio);
1914 if (self->max_ratio)
1915 if (h * self->max_ratio < w) h = (int)(w / self->max_ratio);
1917 w += self->base_size.width;
1918 h += self->base_size.height;
1922 case OB_CORNER_TOPLEFT:
1924 case OB_CORNER_TOPRIGHT:
1925 x -= w - self->area.width;
1927 case OB_CORNER_BOTTOMLEFT:
1928 y -= h - self->area.height;
1930 case OB_CORNER_BOTTOMRIGHT:
1931 x -= w - self->area.width;
1932 y -= h - self->area.height;
1936 moved = x != self->area.x || y != self->area.y;
1937 resized = w != self->area.width || h != self->area.height;
1939 RECT_SET(self->area, x, y, w, h);
1941 /* for app-requested resizes, always resize if 'resized' is true.
1942 for user-requested ones, only resize if final is true, or when
1943 resizing in redraw mode */
1944 if ((!user && resized) ||
1945 (user && (final || (resized && config_redraw_resize))))
1946 XResizeWindow(ob_display, self->window, w, h);
1948 /* move/resize the frame to match the request */
1950 if (self->decorations != fdecor || self->max_horz != fhorz)
1951 moved = resized = TRUE;
1953 if (moved || resized)
1954 frame_adjust_area(self->frame, moved, resized, FALSE);
1956 if (!resized && (force_reply || ((!user && moved) || (user && final))))
1959 event.type = ConfigureNotify;
1960 event.xconfigure.display = ob_display;
1961 event.xconfigure.event = self->window;
1962 event.xconfigure.window = self->window;
1964 /* root window real coords */
1965 event.xconfigure.x = self->frame->area.x + self->frame->size.left -
1967 event.xconfigure.y = self->frame->area.y + self->frame->size.top -
1969 event.xconfigure.width = w;
1970 event.xconfigure.height = h;
1971 event.xconfigure.border_width = 0;
1972 event.xconfigure.above = self->frame->plate;
1973 event.xconfigure.override_redirect = FALSE;
1974 XSendEvent(event.xconfigure.display, event.xconfigure.window,
1975 FALSE, StructureNotifyMask, &event);
1980 void client_fullscreen(ObClient *self, gboolean fs, gboolean savearea)
1984 if (!(self->functions & OB_CLIENT_FUNC_FULLSCREEN) || /* can't */
1985 self->fullscreen == fs) return; /* already done */
1987 self->fullscreen = fs;
1988 client_change_state(self); /* change the state hints on the client,
1989 and adjust out layer/stacking */
1993 guint32 dimensions[4];
1994 dimensions[0] = self->area.x;
1995 dimensions[1] = self->area.y;
1996 dimensions[2] = self->area.width;
1997 dimensions[3] = self->area.height;
1999 PROP_SETA32(self->window, openbox_premax, cardinal,
2003 /* these are not actually used cuz client_configure will set them
2004 as appropriate when the window is fullscreened */
2011 /* pick some fallbacks... */
2012 a = screen_area_monitor(self->desktop, 0);
2013 x = a->x + a->width / 4;
2014 y = a->y + a->height / 4;
2018 if (PROP_GETA32(self->window, openbox_premax, cardinal,
2019 (guint32**)&dimensions, &num)) {
2030 client_setup_decor_and_functions(self);
2032 client_move_resize(self, x, y, w, h);
2034 /* try focus us when we go into fullscreen mode */
2038 static void client_iconify_recursive(ObClient *self,
2039 gboolean iconic, gboolean curdesk)
2042 gboolean changed = FALSE;
2045 if (self->iconic != iconic) {
2046 ob_debug("%sconifying window: 0x%lx\n", (iconic ? "I" : "Uni"),
2049 self->iconic = iconic;
2052 if (self->functions & OB_CLIENT_FUNC_ICONIFY) {
2053 self->wmstate = IconicState;
2054 self->ignore_unmaps++;
2055 /* we unmap the client itself so that we can get MapRequest
2056 events, and because the ICCCM tells us to! */
2057 XUnmapWindow(ob_display, self->window);
2059 /* update the focus lists.. iconic windows go to the bottom of
2060 the list, put the new iconic window at the 'top of the
2062 focus_order_to_top(self);
2068 client_set_desktop(self, screen_desktop, FALSE);
2069 self->wmstate = self->shaded ? IconicState : NormalState;
2070 XMapWindow(ob_display, self->window);
2072 /* this puts it after the current focused window */
2073 focus_order_remove(self);
2074 focus_order_add_new(self);
2076 /* this is here cuz with the VIDMODE extension, the viewport can
2077 change while a fullscreen window is iconic, and when it
2078 uniconifies, it would be nice if it did so to the new position
2080 client_reconfigure(self);
2087 client_change_state(self);
2088 client_showhide(self);
2089 screen_update_areas();
2092 /* iconify all transients */
2093 for (it = self->transients; it != NULL; it = it->next)
2094 if (it->data != self) client_iconify_recursive(it->data,
2098 void client_iconify(ObClient *self, gboolean iconic, gboolean curdesk)
2100 /* move up the transient chain as far as possible first */
2101 self = client_search_top_transient(self);
2103 client_iconify_recursive(client_search_top_transient(self),
2107 void client_maximize(ObClient *self, gboolean max, int dir, gboolean savearea)
2111 g_assert(dir == 0 || dir == 1 || dir == 2);
2112 if (!(self->functions & OB_CLIENT_FUNC_MAXIMIZE)) return; /* can't */
2114 /* check if already done */
2116 if (dir == 0 && self->max_horz && self->max_vert) return;
2117 if (dir == 1 && self->max_horz) return;
2118 if (dir == 2 && self->max_vert) return;
2120 if (dir == 0 && !self->max_horz && !self->max_vert) return;
2121 if (dir == 1 && !self->max_horz) return;
2122 if (dir == 2 && !self->max_vert) return;
2125 /* work with the frame's coords */
2126 x = self->frame->area.x;
2127 y = self->frame->area.y;
2128 w = self->area.width;
2129 h = self->area.height;
2133 gint32 dimensions[4];
2142 /* get the property off the window and use it for the dimensions
2143 we are already maxed on */
2144 if (PROP_GETA32(self->window, openbox_premax, cardinal,
2145 (guint32**)&readdim, &num)) {
2147 if (self->max_horz) {
2148 dimensions[0] = readdim[0];
2149 dimensions[2] = readdim[2];
2151 if (self->max_vert) {
2152 dimensions[1] = readdim[1];
2153 dimensions[3] = readdim[3];
2159 PROP_SETA32(self->window, openbox_premax, cardinal,
2160 (guint32*)dimensions, 4);
2167 /* pick some fallbacks... */
2168 a = screen_area_monitor(self->desktop, 0);
2169 if (dir == 0 || dir == 1) { /* horz */
2170 x = a->x + a->width / 4;
2173 if (dir == 0 || dir == 2) { /* vert */
2174 y = a->y + a->height / 4;
2178 if (PROP_GETA32(self->window, openbox_premax, cardinal,
2179 (guint32**)&dimensions, &num)) {
2181 if (dir == 0 || dir == 1) { /* horz */
2185 if (dir == 0 || dir == 2) { /* vert */
2194 if (dir == 0 || dir == 1) /* horz */
2195 self->max_horz = max;
2196 if (dir == 0 || dir == 2) /* vert */
2197 self->max_vert = max;
2199 if (!self->max_horz && !self->max_vert)
2200 PROP_ERASE(self->window, openbox_premax);
2202 client_change_state(self); /* change the state hints on the client */
2204 client_setup_decor_and_functions(self);
2206 /* figure out where the client should be going */
2207 frame_frame_gravity(self->frame, &x, &y);
2208 client_move_resize(self, x, y, w, h);
2211 void client_shade(ObClient *self, gboolean shade)
2213 if ((!(self->functions & OB_CLIENT_FUNC_SHADE) &&
2214 shade) || /* can't shade */
2215 self->shaded == shade) return; /* already done */
2217 /* when we're iconic, don't change the wmstate */
2219 self->wmstate = shade ? IconicState : NormalState;
2220 self->shaded = shade;
2221 client_change_state(self);
2222 /* resize the frame to just the titlebar */
2223 frame_adjust_area(self->frame, FALSE, FALSE, FALSE);
2226 void client_close(ObClient *self)
2230 if (!(self->functions & OB_CLIENT_FUNC_CLOSE)) return;
2233 XXX: itd be cool to do timeouts and shit here for killing the client's
2235 like... if the window is around after 5 seconds, then the close button
2236 turns a nice red, and if this function is called again, the client is
2240 ce.xclient.type = ClientMessage;
2241 ce.xclient.message_type = prop_atoms.wm_protocols;
2242 ce.xclient.display = ob_display;
2243 ce.xclient.window = self->window;
2244 ce.xclient.format = 32;
2245 ce.xclient.data.l[0] = prop_atoms.wm_delete_window;
2246 ce.xclient.data.l[1] = event_lasttime;
2247 ce.xclient.data.l[2] = 0l;
2248 ce.xclient.data.l[3] = 0l;
2249 ce.xclient.data.l[4] = 0l;
2250 XSendEvent(ob_display, self->window, FALSE, NoEventMask, &ce);
2253 void client_kill(ObClient *self)
2255 XKillClient(ob_display, self->window);
2258 void client_set_desktop_recursive(ObClient *self,
2259 guint target, gboolean donthide)
2264 if (target != self->desktop) {
2266 ob_debug("Setting desktop %u\n", target+1);
2268 g_assert(target < screen_num_desktops || target == DESKTOP_ALL);
2270 /* remove from the old desktop(s) */
2271 focus_order_remove(self);
2273 old = self->desktop;
2274 self->desktop = target;
2275 PROP_SET32(self->window, net_wm_desktop, cardinal, target);
2276 /* the frame can display the current desktop state */
2277 frame_adjust_state(self->frame);
2278 /* 'move' the window to the new desktop */
2280 client_showhide(self);
2281 /* raise if it was not already on the desktop */
2282 if (old != DESKTOP_ALL)
2283 stacking_raise(CLIENT_AS_WINDOW(self));
2284 screen_update_areas();
2286 /* add to the new desktop(s) */
2287 if (config_focus_new)
2288 focus_order_to_top(self);
2290 focus_order_to_bottom(self);
2293 /* move all transients */
2294 for (it = self->transients; it != NULL; it = it->next)
2295 if (it->data != self) client_set_desktop_recursive(it->data,
2299 void client_set_desktop(ObClient *self, guint target, gboolean donthide)
2301 client_set_desktop_recursive(client_search_top_transient(self),
2305 ObClient *client_search_modal_child(ObClient *self)
2310 for (it = self->transients; it != NULL; it = it->next) {
2311 ObClient *c = it->data;
2312 if ((ret = client_search_modal_child(c))) return ret;
2313 if (c->modal) return c;
2318 gboolean client_validate(ObClient *self)
2322 XSync(ob_display, FALSE); /* get all events on the server */
2324 if (XCheckTypedWindowEvent(ob_display, self->window, DestroyNotify, &e) ||
2325 XCheckTypedWindowEvent(ob_display, self->window, UnmapNotify, &e)) {
2326 XPutBackEvent(ob_display, &e);
2333 void client_set_wm_state(ObClient *self, long state)
2335 if (state == self->wmstate) return; /* no change */
2339 client_iconify(self, TRUE, TRUE);
2342 client_iconify(self, FALSE, TRUE);
2347 void client_set_state(ObClient *self, Atom action, long data1, long data2)
2349 gboolean shaded = self->shaded;
2350 gboolean fullscreen = self->fullscreen;
2351 gboolean max_horz = self->max_horz;
2352 gboolean max_vert = self->max_vert;
2355 if (!(action == prop_atoms.net_wm_state_add ||
2356 action == prop_atoms.net_wm_state_remove ||
2357 action == prop_atoms.net_wm_state_toggle))
2358 /* an invalid action was passed to the client message, ignore it */
2361 for (i = 0; i < 2; ++i) {
2362 Atom state = i == 0 ? data1 : data2;
2364 if (!state) continue;
2366 /* if toggling, then pick whether we're adding or removing */
2367 if (action == prop_atoms.net_wm_state_toggle) {
2368 if (state == prop_atoms.net_wm_state_modal)
2369 action = self->modal ? prop_atoms.net_wm_state_remove :
2370 prop_atoms.net_wm_state_add;
2371 else if (state == prop_atoms.net_wm_state_maximized_vert)
2372 action = self->max_vert ? prop_atoms.net_wm_state_remove :
2373 prop_atoms.net_wm_state_add;
2374 else if (state == prop_atoms.net_wm_state_maximized_horz)
2375 action = self->max_horz ? prop_atoms.net_wm_state_remove :
2376 prop_atoms.net_wm_state_add;
2377 else if (state == prop_atoms.net_wm_state_shaded)
2378 action = self->shaded ? prop_atoms.net_wm_state_remove :
2379 prop_atoms.net_wm_state_add;
2380 else if (state == prop_atoms.net_wm_state_skip_taskbar)
2381 action = self->skip_taskbar ?
2382 prop_atoms.net_wm_state_remove :
2383 prop_atoms.net_wm_state_add;
2384 else if (state == prop_atoms.net_wm_state_skip_pager)
2385 action = self->skip_pager ?
2386 prop_atoms.net_wm_state_remove :
2387 prop_atoms.net_wm_state_add;
2388 else if (state == prop_atoms.net_wm_state_fullscreen)
2389 action = self->fullscreen ?
2390 prop_atoms.net_wm_state_remove :
2391 prop_atoms.net_wm_state_add;
2392 else if (state == prop_atoms.net_wm_state_above)
2393 action = self->above ? prop_atoms.net_wm_state_remove :
2394 prop_atoms.net_wm_state_add;
2395 else if (state == prop_atoms.net_wm_state_below)
2396 action = self->below ? prop_atoms.net_wm_state_remove :
2397 prop_atoms.net_wm_state_add;
2400 if (action == prop_atoms.net_wm_state_add) {
2401 if (state == prop_atoms.net_wm_state_modal) {
2402 /* XXX raise here or something? */
2404 } else if (state == prop_atoms.net_wm_state_maximized_vert) {
2406 } else if (state == prop_atoms.net_wm_state_maximized_horz) {
2408 } else if (state == prop_atoms.net_wm_state_shaded) {
2410 } else if (state == prop_atoms.net_wm_state_skip_taskbar) {
2411 self->skip_taskbar = TRUE;
2412 } else if (state == prop_atoms.net_wm_state_skip_pager) {
2413 self->skip_pager = TRUE;
2414 } else if (state == prop_atoms.net_wm_state_fullscreen) {
2416 } else if (state == prop_atoms.net_wm_state_above) {
2418 } else if (state == prop_atoms.net_wm_state_below) {
2422 } else { /* action == prop_atoms.net_wm_state_remove */
2423 if (state == prop_atoms.net_wm_state_modal) {
2424 self->modal = FALSE;
2425 } else if (state == prop_atoms.net_wm_state_maximized_vert) {
2427 } else if (state == prop_atoms.net_wm_state_maximized_horz) {
2429 } else if (state == prop_atoms.net_wm_state_shaded) {
2431 } else if (state == prop_atoms.net_wm_state_skip_taskbar) {
2432 self->skip_taskbar = FALSE;
2433 } else if (state == prop_atoms.net_wm_state_skip_pager) {
2434 self->skip_pager = FALSE;
2435 } else if (state == prop_atoms.net_wm_state_fullscreen) {
2437 } else if (state == prop_atoms.net_wm_state_above) {
2438 self->above = FALSE;
2439 } else if (state == prop_atoms.net_wm_state_below) {
2440 self->below = FALSE;
2444 if (max_horz != self->max_horz || max_vert != self->max_vert) {
2445 if (max_horz != self->max_horz && max_vert != self->max_vert) {
2447 if (max_horz == max_vert) { /* both going the same way */
2448 client_maximize(self, max_horz, 0, TRUE);
2450 client_maximize(self, max_horz, 1, TRUE);
2451 client_maximize(self, max_vert, 2, TRUE);
2455 if (max_horz != self->max_horz)
2456 client_maximize(self, max_horz, 1, TRUE);
2458 client_maximize(self, max_vert, 2, TRUE);
2461 /* change fullscreen state before shading, as it will affect if the window
2463 if (fullscreen != self->fullscreen)
2464 client_fullscreen(self, fullscreen, TRUE);
2465 if (shaded != self->shaded)
2466 client_shade(self, shaded);
2467 client_calc_layer(self);
2468 client_change_state(self); /* change the hint to reflect these changes */
2471 ObClient *client_focus_target(ObClient *self)
2475 /* if we have a modal child, then focus it, not us */
2476 child = client_search_modal_child(self);
2477 if (child) return child;
2481 gboolean client_can_focus(ObClient *self)
2485 /* choose the correct target */
2486 self = client_focus_target(self);
2488 if (!self->frame->visible)
2491 if (!((self->can_focus || self->focus_notify) &&
2492 (self->desktop == screen_desktop ||
2493 self->desktop == DESKTOP_ALL) &&
2497 /* do a check to see if the window has already been unmapped or destroyed
2498 do this intelligently while watching out for unmaps we've generated
2499 (ignore_unmaps > 0) */
2500 if (XCheckTypedWindowEvent(ob_display, self->window,
2501 DestroyNotify, &ev)) {
2502 XPutBackEvent(ob_display, &ev);
2505 while (XCheckTypedWindowEvent(ob_display, self->window,
2506 UnmapNotify, &ev)) {
2507 if (self->ignore_unmaps) {
2508 self->ignore_unmaps--;
2510 XPutBackEvent(ob_display, &ev);
2518 gboolean client_focus(ObClient *self)
2520 /* choose the correct target */
2521 self = client_focus_target(self);
2523 if (!client_can_focus(self)) {
2524 if (!self->frame->visible) {
2525 /* update the focus lists */
2526 focus_order_to_top(self);
2531 if (self->can_focus)
2532 /* RevertToPointerRoot causes much more headache than RevertToNone, so
2533 I choose to use it always, hopefully to find errors quicker, if any
2534 are left. (I hate X. I hate focus events.) */
2535 XSetInputFocus(ob_display, self->window, RevertToPointerRoot,
2538 if (self->focus_notify) {
2540 ce.xclient.type = ClientMessage;
2541 ce.xclient.message_type = prop_atoms.wm_protocols;
2542 ce.xclient.display = ob_display;
2543 ce.xclient.window = self->window;
2544 ce.xclient.format = 32;
2545 ce.xclient.data.l[0] = prop_atoms.wm_take_focus;
2546 ce.xclient.data.l[1] = event_lasttime;
2547 ce.xclient.data.l[2] = 0l;
2548 ce.xclient.data.l[3] = 0l;
2549 ce.xclient.data.l[4] = 0l;
2550 XSendEvent(ob_display, self->window, FALSE, NoEventMask, &ce);
2554 ob_debug("%sively focusing %lx at %d\n",
2555 (self->can_focus ? "act" : "pass"),
2556 self->window, (int) event_lasttime);
2559 /* Cause the FocusIn to come back to us. Important for desktop switches,
2560 since otherwise we'll have no FocusIn on the queue and send it off to
2561 the focus_backup. */
2562 XSync(ob_display, FALSE);
2566 void client_unfocus(ObClient *self)
2568 g_assert(focus_client == self);
2570 ob_debug("client_unfocus for %lx\n", self->window);
2572 focus_fallback(OB_FOCUS_FALLBACK_UNFOCUSING);
2575 void client_activate(ObClient *self, gboolean here)
2577 if (client_normal(self) && screen_showing_desktop)
2578 screen_show_desktop(FALSE);
2580 client_iconify(self, FALSE, FALSE);
2581 if (self->desktop != DESKTOP_ALL &&
2582 self->desktop != screen_desktop) {
2584 client_set_desktop(self, screen_desktop, FALSE);
2586 screen_set_desktop(self->desktop);
2587 } else if (!self->frame->visible)
2588 /* if its not visible for other reasons, then don't mess
2592 client_shade(self, FALSE);
2594 stacking_raise(CLIENT_AS_WINDOW(self));
2597 gboolean client_focused(ObClient *self)
2599 return self == focus_client;
2602 ObClientIcon *client_icon(ObClient *self, int w, int h)
2605 /* si is the smallest image >= req */
2606 /* li is the largest image < req */
2607 unsigned long size, smallest = 0xffffffff, largest = 0, si = 0, li = 0;
2609 if (!self->nicons) return NULL;
2611 for (i = 0; i < self->nicons; ++i) {
2612 size = self->icons[i].width * self->icons[i].height;
2613 if (size < smallest && size >= (unsigned)(w * h)) {
2617 if (size > largest && size <= (unsigned)(w * h)) {
2622 if (largest == 0) /* didnt find one smaller than the requested size */
2623 return &self->icons[si];
2624 return &self->icons[li];
2627 /* this be mostly ripped from fvwm */
2628 ObClient *client_find_directional(ObClient *c, ObDirection dir)
2630 int my_cx, my_cy, his_cx, his_cy;
2633 int score, best_score;
2634 ObClient *best_client, *cur;
2640 /* first, find the centre coords of the currently focused window */
2641 my_cx = c->frame->area.x + c->frame->area.width / 2;
2642 my_cy = c->frame->area.y + c->frame->area.height / 2;
2647 for(it = g_list_first(client_list); it; it = it->next) {
2650 /* the currently selected window isn't interesting */
2653 if (!client_normal(cur))
2655 if(c->desktop != cur->desktop && cur->desktop != DESKTOP_ALL)
2659 if(client_focus_target(cur) == cur &&
2660 !(cur->can_focus || cur->focus_notify))
2663 /* find the centre coords of this window, from the
2664 * currently focused window's point of view */
2665 his_cx = (cur->frame->area.x - my_cx)
2666 + cur->frame->area.width / 2;
2667 his_cy = (cur->frame->area.y - my_cy)
2668 + cur->frame->area.height / 2;
2670 if(dir == OB_DIRECTION_NORTHEAST || dir == OB_DIRECTION_SOUTHEAST ||
2671 dir == OB_DIRECTION_SOUTHWEST || dir == OB_DIRECTION_NORTHWEST) {
2673 /* Rotate the diagonals 45 degrees counterclockwise.
2674 * To do this, multiply the matrix /+h +h\ with the
2675 * vector (x y). \-h +h/
2676 * h = sqrt(0.5). We can set h := 1 since absolute
2677 * distance doesn't matter here. */
2678 tx = his_cx + his_cy;
2679 his_cy = -his_cx + his_cy;
2684 case OB_DIRECTION_NORTH:
2685 case OB_DIRECTION_SOUTH:
2686 case OB_DIRECTION_NORTHEAST:
2687 case OB_DIRECTION_SOUTHWEST:
2688 offset = (his_cx < 0) ? -his_cx : his_cx;
2689 distance = ((dir == OB_DIRECTION_NORTH ||
2690 dir == OB_DIRECTION_NORTHEAST) ?
2693 case OB_DIRECTION_EAST:
2694 case OB_DIRECTION_WEST:
2695 case OB_DIRECTION_SOUTHEAST:
2696 case OB_DIRECTION_NORTHWEST:
2697 offset = (his_cy < 0) ? -his_cy : his_cy;
2698 distance = ((dir == OB_DIRECTION_WEST ||
2699 dir == OB_DIRECTION_NORTHWEST) ?
2704 /* the target must be in the requested direction */
2708 /* Calculate score for this window. The smaller the better. */
2709 score = distance + offset;
2711 /* windows more than 45 degrees off the direction are
2712 * heavily penalized and will only be chosen if nothing
2713 * else within a million pixels */
2714 if(offset > distance)
2717 if(best_score == -1 || score < best_score)
2725 void client_set_layer(ObClient *self, int layer)
2729 self->above = FALSE;
2730 } else if (layer == 0) {
2731 self->below = self->above = FALSE;
2733 self->below = FALSE;
2736 client_calc_layer(self);
2737 client_change_state(self); /* reflect this in the state hints */
2740 guint client_monitor(ObClient *self)
2744 for (i = 0; i < screen_num_monitors; ++i) {
2745 Rect *area = screen_physical_area_monitor(i);
2746 if (RECT_INTERSECTS_RECT(*area, self->frame->area))
2749 if (i == screen_num_monitors) i = 0;
2750 g_assert(i < screen_num_monitors);
2754 ObClient *client_search_top_transient(ObClient *self)
2756 /* move up the transient chain as far as possible */
2757 if (self->transient_for) {
2758 if (self->transient_for != OB_TRAN_GROUP) {
2759 return client_search_top_transient(self->transient_for);
2763 for (it = self->group->members; it; it = it->next) {
2764 ObClient *c = it->data;
2766 /* checking transient_for prevents infinate loops! */
2767 if (c != self && !c->transient_for)
2778 ObClient *client_search_transient(ObClient *self, ObClient *search)
2782 for (sit = self->transients; sit; sit = g_slist_next(sit)) {
2783 if (sit->data == search)
2785 if (client_search_transient(sit->data, search))
2791 gchar* client_get_sm_client_id(ObClient *self)
2795 if (!PROP_GETS(self->window, sm_client_id, locale, &id) && self->group)
2796 PROP_GETS(self->group->leader, sm_client_id, locale, &id);
2800 /* finds the nearest edge in the given direction from the current client
2801 * note to self: the edge is the -frame- edge (the actual one), not the
2804 int client_directional_edge_search(ObClient *c, ObDirection dir)
2807 int my_edge_start, my_edge_end, my_offset;
2814 a = screen_area(c->desktop);
2817 case OB_DIRECTION_NORTH:
2818 my_edge_start = c->frame->area.x;
2819 my_edge_end = c->frame->area.x + c->frame->area.width;
2820 my_offset = c->frame->area.y;
2822 dest = a->y; /* default: top of screen */
2824 for(it = g_list_first(client_list); it; it = it->next) {
2825 int his_edge_start, his_edge_end, his_offset;
2826 ObClient *cur = it->data;
2830 if(!client_normal(cur))
2832 if(c->desktop != cur->desktop && cur->desktop != DESKTOP_ALL)
2837 his_edge_start = cur->frame->area.x;
2838 his_edge_end = cur->frame->area.x + cur->frame->area.width;
2839 his_offset = cur->frame->area.y + cur->frame->area.height;
2841 if(his_offset + 1 > my_offset)
2844 if(his_offset < dest)
2847 if(his_edge_start >= my_edge_start &&
2848 his_edge_start <= my_edge_end)
2851 if(my_edge_start >= his_edge_start &&
2852 my_edge_start <= his_edge_end)
2857 case OB_DIRECTION_SOUTH:
2858 my_edge_start = c->frame->area.x;
2859 my_edge_end = c->frame->area.x + c->frame->area.width;
2860 my_offset = c->frame->area.y + c->frame->area.height;
2862 dest = a->y + a->height; /* default: bottom of screen */
2864 for(it = g_list_first(client_list); it; it = it->next) {
2865 int his_edge_start, his_edge_end, his_offset;
2866 ObClient *cur = it->data;
2870 if(!client_normal(cur))
2872 if(c->desktop != cur->desktop && cur->desktop != DESKTOP_ALL)
2877 his_edge_start = cur->frame->area.x;
2878 his_edge_end = cur->frame->area.x + cur->frame->area.width;
2879 his_offset = cur->frame->area.y;
2882 if(his_offset - 1 < my_offset)
2885 if(his_offset > dest)
2888 if(his_edge_start >= my_edge_start &&
2889 his_edge_start <= my_edge_end)
2892 if(my_edge_start >= his_edge_start &&
2893 my_edge_start <= his_edge_end)
2898 case OB_DIRECTION_WEST:
2899 my_edge_start = c->frame->area.y;
2900 my_edge_end = c->frame->area.y + c->frame->area.height;
2901 my_offset = c->frame->area.x;
2903 dest = a->x; /* default: leftmost egde of screen */
2905 for(it = g_list_first(client_list); it; it = it->next) {
2906 int his_edge_start, his_edge_end, his_offset;
2907 ObClient *cur = it->data;
2911 if(!client_normal(cur))
2913 if(c->desktop != cur->desktop && cur->desktop != DESKTOP_ALL)
2918 his_edge_start = cur->frame->area.y;
2919 his_edge_end = cur->frame->area.y + cur->frame->area.height;
2920 his_offset = cur->frame->area.x + cur->frame->area.width;
2922 if(his_offset + 1 > my_offset)
2925 if(his_offset < dest)
2928 if(his_edge_start >= my_edge_start &&
2929 his_edge_start <= my_edge_end)
2932 if(my_edge_start >= his_edge_start &&
2933 my_edge_start <= his_edge_end)
2939 case OB_DIRECTION_EAST:
2940 my_edge_start = c->frame->area.y;
2941 my_edge_end = c->frame->area.y + c->frame->area.height;
2942 my_offset = c->frame->area.x + c->frame->area.width;
2944 dest = a->x + a->width; /* default: rightmost edge of screen */
2946 for(it = g_list_first(client_list); it; it = it->next) {
2947 int his_edge_start, his_edge_end, his_offset;
2948 ObClient *cur = it->data;
2952 if(!client_normal(cur))
2954 if(c->desktop != cur->desktop && cur->desktop != DESKTOP_ALL)
2959 his_edge_start = cur->frame->area.y;
2960 his_edge_end = cur->frame->area.y + cur->frame->area.height;
2961 his_offset = cur->frame->area.x;
2963 if(his_offset - 1 < my_offset)
2966 if(his_offset > dest)
2969 if(his_edge_start >= my_edge_start &&
2970 his_edge_start <= my_edge_end)
2973 if(my_edge_start >= his_edge_start &&
2974 my_edge_start <= his_edge_end)
2979 case OB_DIRECTION_NORTHEAST:
2980 case OB_DIRECTION_SOUTHEAST:
2981 case OB_DIRECTION_NORTHWEST:
2982 case OB_DIRECTION_SOUTHWEST:
2983 /* not implemented */
2986 g_assert_not_reached();