7 #include "moveresize.h"
9 #include "extensions.h"
20 #include "render/render.h"
23 #include <X11/Xutil.h>
25 /*! The event mask to grab on client windows */
26 #define CLIENT_EVENTMASK (PropertyChangeMask | FocusChangeMask | \
29 #define CLIENT_NOPROPAGATEMASK (ButtonPressMask | ButtonReleaseMask | \
32 GList *client_list = NULL;
34 static void client_get_all(ObClient *self);
35 static void client_toggle_border(ObClient *self, gboolean show);
36 static void client_get_area(ObClient *self);
37 static void client_get_desktop(ObClient *self);
38 static void client_get_state(ObClient *self);
39 static void client_get_shaped(ObClient *self);
40 static void client_get_mwm_hints(ObClient *self);
41 static void client_get_gravity(ObClient *self);
42 static void client_showhide(ObClient *self);
43 static void client_change_allowed_actions(ObClient *self);
44 static void client_change_state(ObClient *self);
45 static void client_apply_startup_state(ObClient *self);
52 void client_shutdown()
56 void client_set_list()
58 Window *windows, *win_it;
60 guint size = g_list_length(client_list);
62 /* create an array of the window ids */
64 windows = g_new(Window, size);
66 for (it = client_list; it != NULL; it = it->next, ++win_it)
67 *win_it = ((ObClient*)it->data)->window;
71 PROP_SETA32(RootWindow(ob_display, ob_screen),
72 net_client_list, window, (guint32*)windows, size);
81 void client_foreach_transient(ObClient *self, ObClientForeachFunc func, void *data)
85 for (it = self->transients; it; it = it->next) {
86 if (!func(it->data, data)) return;
87 client_foreach_transient(it->data, func, data);
91 void client_foreach_ancestor(ObClient *self, ObClientForeachFunc func, void *data)
93 if (self->transient_for) {
94 if (self->transient_for != OB_TRAN_GROUP) {
95 if (!func(self->transient_for, data)) return;
96 client_foreach_ancestor(self->transient_for, func, data);
100 for (it = self->group->members; it; it = it->next)
101 if (it->data != self &&
102 !((ObClient*)it->data)->transient_for) {
103 if (!func(it->data, data)) return;
104 client_foreach_ancestor(it->data, func, data);
111 void client_manage_all()
113 unsigned int i, j, nchild;
116 XWindowAttributes attrib;
118 XQueryTree(ob_display, RootWindow(ob_display, ob_screen),
119 &w, &w, &children, &nchild);
121 /* remove all icon windows from the list */
122 for (i = 0; i < nchild; i++) {
123 if (children[i] == None) continue;
124 wmhints = XGetWMHints(ob_display, children[i]);
126 if ((wmhints->flags & IconWindowHint) &&
127 (wmhints->icon_window != children[i]))
128 for (j = 0; j < nchild; j++)
129 if (children[j] == wmhints->icon_window) {
137 for (i = 0; i < nchild; ++i) {
138 if (children[i] == None)
140 if (XGetWindowAttributes(ob_display, children[i], &attrib)) {
141 if (attrib.override_redirect) continue;
143 if (attrib.map_state != IsUnmapped)
144 client_manage(children[i]);
149 /* stack them as they were on startup!
150 why with stacking_lower? Why, because then windows who aren't in the
151 stacking list are on the top where you can see them instead of buried
153 for (i = startup_stack_size; i > 0; --i) {
156 w = startup_stack_order[i-1];
157 obw = g_hash_table_lookup(window_map, &w);
159 g_assert(WINDOW_IS_CLIENT(obw));
160 stacking_lower(CLIENT_AS_WINDOW(obw));
163 g_free(startup_stack_order);
164 startup_stack_order = NULL;
165 startup_stack_size = 0;
167 if (config_focus_new) {
170 active = g_hash_table_lookup(window_map, &startup_active);
172 g_assert(WINDOW_IS_CLIENT(active));
173 if (!client_focus(WINDOW_AS_CLIENT(active)))
174 focus_fallback(OB_FOCUS_FALLBACK_NOFOCUS);
176 focus_fallback(OB_FOCUS_FALLBACK_NOFOCUS);
180 void client_manage(Window window)
184 XWindowAttributes attrib;
185 XSetWindowAttributes attrib_set;
187 gboolean activate = FALSE;
191 /* check if it has already been unmapped by the time we started mapping
192 the grab does a sync so we don't have to here */
193 if (XCheckTypedWindowEvent(ob_display, window, DestroyNotify, &e) ||
194 XCheckTypedWindowEvent(ob_display, window, UnmapNotify, &e)) {
195 XPutBackEvent(ob_display, &e);
198 return; /* don't manage it */
201 /* make sure it isn't an override-redirect window */
202 if (!XGetWindowAttributes(ob_display, window, &attrib) ||
203 attrib.override_redirect) {
205 return; /* don't manage it */
208 /* is the window a docking app */
209 if ((wmhint = XGetWMHints(ob_display, window))) {
210 if ((wmhint->flags & StateHint) &&
211 wmhint->initial_state == WithdrawnState) {
212 dock_add(window, wmhint);
220 ob_debug("Managing window: %lx\n", window);
222 /* choose the events we want to receive on the CLIENT window */
223 attrib_set.event_mask = CLIENT_EVENTMASK;
224 attrib_set.do_not_propagate_mask = CLIENT_NOPROPAGATEMASK;
225 XChangeWindowAttributes(ob_display, window,
226 CWEventMask|CWDontPropagate, &attrib_set);
229 /* create the ObClient struct, and populate it from the hints on the
231 self = g_new(ObClient, 1);
232 self->obwin.type = Window_Client;
233 self->window = window;
234 client_get_all(self);
236 /* remove the client's border (and adjust re gravity) */
237 client_toggle_border(self, FALSE);
239 /* specify that if we exit, the window should not be destroyed and should
240 be reparented back to root automatically */
241 XChangeSaveSet(ob_display, window, SetModeInsert);
243 /* create the decoration frame for the client window */
244 self->frame = frame_new();
246 frame_grab_client(self->frame, self);
248 client_apply_startup_state(self);
252 /* add to client list/map */
253 client_list = g_list_append(client_list, self);
254 g_hash_table_insert(window_map, &self->window, self);
256 /* update the focus lists */
257 focus_order_add_new(self);
259 stacking_add(CLIENT_AS_WINDOW(self));
261 /* focus the new window? */
262 if (ob_state() != OB_STATE_STARTING && config_focus_new &&
263 /* note the check against Type_Normal/Dialog, not client_normal(self),
264 which would also include other types. in this case we want more
265 strict rules for focus */
266 (self->type == OB_CLIENT_TYPE_NORMAL ||
267 self->type == OB_CLIENT_TYPE_DIALOG))
269 if (self->desktop != screen_desktop) {
270 /* activate the window */
273 gboolean group_foc = FALSE;
278 for (it = self->group->members; it; it = it->next)
280 if (client_focused(it->data))
288 (!self->transient_for && (!self->group ||
289 !self->group->members->next))) ||
290 client_search_focus_tree_full(self) ||
292 !client_normal(focus_client))
294 /* activate the window */
300 dispatch_client(Event_Client_New, self, 0, 0);
302 /* make sure the window is visible */
303 if (client_normal(self))
304 client_move_onscreen(self, TRUE);
306 screen_update_areas();
308 client_showhide(self);
310 /* use client_focus instead of client_activate cuz client_activate does
311 stuff like switch desktops etc and I'm not interested in all that when
312 a window maps since its not based on an action from the user like
313 clicking a window to activate is. so keep the new window out of the way
315 if (activate) client_focus(self);
317 /* client_activate does this but we aret using it so we have to do it
319 if (screen_showing_desktop)
320 screen_show_desktop(FALSE);
322 /* update the list hints */
325 dispatch_client(Event_Client_Mapped, self, 0, 0);
327 ob_debug("Managed window 0x%lx (%s)\n", window, self->class);
330 void client_unmanage_all()
332 while (client_list != NULL)
333 client_unmanage(client_list->data);
336 /* called by client_unmanage() to close any menus referencing this client */
337 void client_close_menus(gpointer key, gpointer value, gpointer self)
339 if (((ObMenu *)value)->client == (ObClient *)self)
340 menu_hide((ObMenu *)value);
343 void client_unmanage(ObClient *self)
348 ob_debug("Unmanaging window: %lx (%s)\n", self->window, self->class);
350 dispatch_client(Event_Client_Destroy, self, 0, 0);
351 g_assert(self != NULL);
353 /* remove the window from our save set */
354 XChangeSaveSet(ob_display, self->window, SetModeDelete);
356 /* we dont want events no more */
357 XSelectInput(ob_display, self->window, NoEventMask);
359 frame_hide(self->frame);
361 client_list = g_list_remove(client_list, self);
362 stacking_remove(self);
363 g_hash_table_remove(window_map, &self->window);
365 /* update the focus lists */
366 focus_order_remove(self);
368 /* once the client is out of the list, update the struts to remove it's
370 screen_update_areas();
372 /* tell our parent(s) that we're gone */
373 if (self->transient_for == OB_TRAN_GROUP) { /* transient of group */
376 for (it = self->group->members; it; it = it->next)
377 if (it->data != self)
378 ((ObClient*)it->data)->transients =
379 g_slist_remove(((ObClient*)it->data)->transients, self);
380 } else if (self->transient_for) { /* transient of window */
381 self->transient_for->transients =
382 g_slist_remove(self->transient_for->transients, self);
385 /* tell our transients that we're gone */
386 for (it = self->transients; it != NULL; it = it->next) {
387 if (((ObClient*)it->data)->transient_for != OB_TRAN_GROUP) {
388 ((ObClient*)it->data)->transient_for = NULL;
389 client_calc_layer(it->data);
393 if (moveresize_client == self)
394 moveresize_end(TRUE);
396 /* close any windows that are attached to this window */
397 g_hash_table_foreach(menu_hash, client_close_menus, self);
400 if (focus_client == self) {
403 /* focus the last focused window on the desktop, and ignore enter
404 events from the unmap so it doesnt mess with the focus */
405 while (XCheckTypedEvent(ob_display, EnterNotify, &e));
406 client_unfocus(self);
409 /* remove from its group */
411 group_remove(self->group, self);
415 /* dispatch the unmapped event */
416 dispatch_client(Event_Client_Unmapped, self, 0, 0);
417 g_assert(self != NULL);
419 /* give the client its border back */
420 client_toggle_border(self, TRUE);
422 /* reparent the window out of the frame, and free the frame */
423 frame_release_client(self->frame, self);
426 if (ob_state() != OB_STATE_EXITING) {
427 /* these values should not be persisted across a window
429 PROP_ERASE(self->window, net_wm_desktop);
430 PROP_ERASE(self->window, net_wm_state);
432 /* if we're left in an iconic state, the client wont be mapped. this is
433 bad, since we will no longer be managing the window on restart */
435 XMapWindow(ob_display, self->window);
439 ob_debug("Unmanaged window 0x%lx\n", self->window);
441 /* free all data allocated in the client struct */
442 g_slist_free(self->transients);
443 for (j = 0; j < self->nicons; ++j)
444 g_free(self->icons[j].data);
445 if (self->nicons > 0)
448 g_free(self->icon_title);
454 /* update the list hints */
458 void client_move_onscreen(ObClient *self, gboolean rude)
460 int x = self->area.x;
461 int y = self->area.y;
462 if (client_find_onscreen(self, &x, &y,
463 self->area.width, self->area.height, rude)) {
464 client_configure(self, OB_CORNER_TOPLEFT, x, y,
465 self->area.width, self->area.height,
470 gboolean client_find_onscreen(ObClient *self, int *x, int *y, int w, int h,
474 int ox = *x, oy = *y;
476 frame_client_gravity(self->frame, x, y); /* get where the frame
479 /* XXX watch for xinerama dead areas */
481 a = screen_area(self->desktop);
482 if (*x >= a->x + a->width - 1)
483 *x = a->x + a->width - self->frame->area.width;
484 if (*y >= a->y + a->height - 1)
485 *y = a->y + a->height - self->frame->area.height;
486 if (*x + self->frame->area.width - 1 < a->x)
488 if (*y + self->frame->area.height - 1 < a->y)
492 /* this is my MOZILLA BITCHSLAP. oh ya it fucking feels good.
493 Java can suck it too. */
495 /* dont let windows map/move into the strut unless they
496 are bigger than the available area */
498 if (*x < a->x) *x = a->x;
499 if (*x + w > a->x + a->width)
500 *x = a->x + a->width - w;
502 if (h <= a->height) {
503 if (*y < a->y) *y = a->y;
504 if (*y + h > a->y + a->height)
505 *y = a->y + a->height - h;
509 frame_frame_gravity(self->frame, x, y); /* get where the client
512 return ox != *x || oy != *y;
515 static void client_toggle_border(ObClient *self, gboolean show)
517 /* adjust our idea of where the client is, based on its border. When the
518 border is removed, the client should now be considered to be in a
520 when re-adding the border to the client, the same operation needs to be
522 int oldx = self->area.x, oldy = self->area.y;
523 int x = oldx, y = oldy;
524 switch(self->gravity) {
526 case NorthWestGravity:
528 case SouthWestGravity:
530 case NorthEastGravity:
532 case SouthEastGravity:
533 if (show) x -= self->border_width * 2;
534 else x += self->border_width * 2;
541 if (show) x -= self->border_width;
542 else x += self->border_width;
545 switch(self->gravity) {
547 case NorthWestGravity:
549 case NorthEastGravity:
551 case SouthWestGravity:
553 case SouthEastGravity:
554 if (show) y -= self->border_width * 2;
555 else y += self->border_width * 2;
562 if (show) y -= self->border_width;
563 else y += self->border_width;
570 XSetWindowBorderWidth(ob_display, self->window, self->border_width);
572 /* move the client so it is back it the right spot _with_ its
574 if (x != oldx || y != oldy)
575 XMoveWindow(ob_display, self->window, x, y);
577 XSetWindowBorderWidth(ob_display, self->window, 0);
581 static void client_get_all(ObClient *self)
583 /* update EVERYTHING!! */
585 self->ignore_unmaps = 0;
589 self->title = self->icon_title = NULL;
590 self->title_count = 1;
591 self->name = self->class = self->role = NULL;
592 self->wmstate = NormalState;
593 self->transient = FALSE;
594 self->transients = NULL;
595 self->transient_for = NULL;
597 self->urgent = FALSE;
598 self->positioned = FALSE;
599 self->decorate = TRUE;
603 client_get_area(self);
604 client_update_transient_for(self);
605 client_update_wmhints(self);
606 client_get_desktop(self);
607 client_get_state(self);
608 client_get_shaped(self);
610 client_get_mwm_hints(self);
611 client_get_type(self);/* this can change the mwmhints for special cases */
613 client_update_protocols(self);
615 client_get_gravity(self); /* get the attribute gravity */
616 client_update_normal_hints(self); /* this may override the attribute
619 /* got the type, the mwmhints, the protocols, and the normal hints
620 (min/max sizes), so we're ready to set up the decorations/functions */
621 client_setup_decor_and_functions(self);
623 client_update_title(self);
624 client_update_class(self);
625 client_update_strut(self);
626 client_update_icons(self);
628 client_change_state(self);
631 static void client_get_area(ObClient *self)
633 XWindowAttributes wattrib;
636 ret = XGetWindowAttributes(ob_display, self->window, &wattrib);
637 g_assert(ret != BadWindow);
639 RECT_SET(self->area, wattrib.x, wattrib.y, wattrib.width, wattrib.height);
640 self->border_width = wattrib.border_width;
643 static void client_get_desktop(ObClient *self)
645 guint32 d = screen_num_desktops; /* an always-invalid value */
647 if (PROP_GET32(self->window, net_wm_desktop, cardinal, &d)) {
648 if (d >= screen_num_desktops && d != DESKTOP_ALL)
649 self->desktop = screen_num_desktops - 1;
653 gboolean trdesk = FALSE;
655 if (self->transient_for) {
656 if (self->transient_for != OB_TRAN_GROUP) {
657 self->desktop = self->transient_for->desktop;
662 for (it = self->group->members; it; it = it->next)
663 if (it->data != self &&
664 !((ObClient*)it->data)->transient_for) {
665 self->desktop = ((ObClient*)it->data)->desktop;
672 /* defaults to the current desktop */
673 self->desktop = screen_desktop;
676 if (self->desktop != d) {
677 /* set the desktop hint, to make sure that it always exists */
678 PROP_SET32(self->window, net_wm_desktop, cardinal, self->desktop);
682 static void client_get_state(ObClient *self)
687 self->modal = self->shaded = self->max_horz = self->max_vert =
688 self->fullscreen = self->above = self->below = self->iconic =
689 self->skip_taskbar = self->skip_pager = FALSE;
691 if (PROP_GETA32(self->window, net_wm_state, atom, &state, &num)) {
693 for (i = 0; i < num; ++i) {
694 if (state[i] == prop_atoms.net_wm_state_modal)
696 else if (state[i] == prop_atoms.net_wm_state_shaded)
698 else if (state[i] == prop_atoms.net_wm_state_hidden)
700 else if (state[i] == prop_atoms.net_wm_state_skip_taskbar)
701 self->skip_taskbar = TRUE;
702 else if (state[i] == prop_atoms.net_wm_state_skip_pager)
703 self->skip_pager = TRUE;
704 else if (state[i] == prop_atoms.net_wm_state_fullscreen)
705 self->fullscreen = TRUE;
706 else if (state[i] == prop_atoms.net_wm_state_maximized_vert)
707 self->max_vert = TRUE;
708 else if (state[i] == prop_atoms.net_wm_state_maximized_horz)
709 self->max_horz = TRUE;
710 else if (state[i] == prop_atoms.net_wm_state_above)
712 else if (state[i] == prop_atoms.net_wm_state_below)
720 static void client_get_shaped(ObClient *self)
722 self->shaped = FALSE;
724 if (extensions_shape) {
729 XShapeSelectInput(ob_display, self->window, ShapeNotifyMask);
731 XShapeQueryExtents(ob_display, self->window, &s, &foo,
732 &foo, &ufoo, &ufoo, &foo, &foo, &foo, &ufoo,
734 self->shaped = (s != 0);
739 void client_update_transient_for(ObClient *self)
742 ObClient *target = NULL;
744 if (XGetTransientForHint(ob_display, self->window, &t)) {
745 self->transient = TRUE;
746 if (t != self->window) { /* cant be transient to itself! */
747 target = g_hash_table_lookup(window_map, &t);
748 /* if this happens then we need to check for it*/
749 g_assert(target != self);
750 g_assert(!target || WINDOW_IS_CLIENT(target));
752 if (!target && self->group) {
753 /* not transient to a client, see if it is transient for a
755 if (t == self->group->leader ||
757 t == RootWindow(ob_display, ob_screen)) {
758 /* window is a transient for its group! */
759 target = OB_TRAN_GROUP;
764 self->transient = FALSE;
766 /* if anything has changed... */
767 if (target != self->transient_for) {
768 if (self->transient_for == OB_TRAN_GROUP) { /* transient of group */
771 /* remove from old parents */
772 for (it = self->group->members; it; it = g_slist_next(it)) {
773 ObClient *c = it->data;
774 if (c != self && !c->transient_for)
775 c->transients = g_slist_remove(c->transients, self);
777 } else if (self->transient_for != NULL) { /* transient of window */
778 /* remove from old parent */
779 self->transient_for->transients =
780 g_slist_remove(self->transient_for->transients, self);
782 self->transient_for = target;
783 if (self->transient_for == OB_TRAN_GROUP) { /* transient of group */
786 /* add to new parents */
787 for (it = self->group->members; it; it = g_slist_next(it)) {
788 ObClient *c = it->data;
789 if (c != self && !c->transient_for)
790 c->transients = g_slist_append(c->transients, self);
793 /* remove all transients which are in the group, that causes
794 circlular pointer hell of doom */
795 for (it = self->group->members; it; it = g_slist_next(it)) {
797 for (sit = self->transients; sit; sit = next) {
798 next = g_slist_next(sit);
799 if (sit->data == it->data)
801 g_slist_delete_link(self->transients, sit);
804 } else if (self->transient_for != NULL) { /* transient of window */
805 /* add to new parent */
806 self->transient_for->transients =
807 g_slist_append(self->transient_for->transients, self);
812 static void client_get_mwm_hints(ObClient *self)
817 self->mwmhints.flags = 0; /* default to none */
819 if (PROP_GETA32(self->window, motif_wm_hints, motif_wm_hints,
821 if (num >= OB_MWM_ELEMENTS) {
822 self->mwmhints.flags = hints[0];
823 self->mwmhints.functions = hints[1];
824 self->mwmhints.decorations = hints[2];
830 void client_get_type(ObClient *self)
837 if (PROP_GETA32(self->window, net_wm_window_type, atom, &val, &num)) {
838 /* use the first value that we know about in the array */
839 for (i = 0; i < num; ++i) {
840 if (val[i] == prop_atoms.net_wm_window_type_desktop)
841 self->type = OB_CLIENT_TYPE_DESKTOP;
842 else if (val[i] == prop_atoms.net_wm_window_type_dock)
843 self->type = OB_CLIENT_TYPE_DOCK;
844 else if (val[i] == prop_atoms.net_wm_window_type_toolbar)
845 self->type = OB_CLIENT_TYPE_TOOLBAR;
846 else if (val[i] == prop_atoms.net_wm_window_type_menu)
847 self->type = OB_CLIENT_TYPE_MENU;
848 else if (val[i] == prop_atoms.net_wm_window_type_utility)
849 self->type = OB_CLIENT_TYPE_UTILITY;
850 else if (val[i] == prop_atoms.net_wm_window_type_splash)
851 self->type = OB_CLIENT_TYPE_SPLASH;
852 else if (val[i] == prop_atoms.net_wm_window_type_dialog)
853 self->type = OB_CLIENT_TYPE_DIALOG;
854 else if (val[i] == prop_atoms.net_wm_window_type_normal)
855 self->type = OB_CLIENT_TYPE_NORMAL;
856 else if (val[i] == prop_atoms.kde_net_wm_window_type_override) {
857 /* prevent this window from getting any decor or
859 self->mwmhints.flags &= (OB_MWM_FLAG_FUNCTIONS |
860 OB_MWM_FLAG_DECORATIONS);
861 self->mwmhints.decorations = 0;
862 self->mwmhints.functions = 0;
864 if (self->type != (ObClientType) -1)
865 break; /* grab the first legit type */
870 if (self->type == (ObClientType) -1) {
871 /*the window type hint was not set, which means we either classify
872 ourself as a normal window or a dialog, depending on if we are a
875 self->type = OB_CLIENT_TYPE_DIALOG;
877 self->type = OB_CLIENT_TYPE_NORMAL;
881 void client_update_protocols(ObClient *self)
886 self->focus_notify = FALSE;
887 self->delete_window = FALSE;
889 if (PROP_GETA32(self->window, wm_protocols, atom, &proto, &num_return)) {
890 for (i = 0; i < num_return; ++i) {
891 if (proto[i] == prop_atoms.wm_delete_window) {
892 /* this means we can request the window to close */
893 self->delete_window = TRUE;
894 } else if (proto[i] == prop_atoms.wm_take_focus)
895 /* if this protocol is requested, then the window will be
896 notified whenever we want it to receive focus */
897 self->focus_notify = TRUE;
903 static void client_get_gravity(ObClient *self)
905 XWindowAttributes wattrib;
908 ret = XGetWindowAttributes(ob_display, self->window, &wattrib);
909 g_assert(ret != BadWindow);
910 self->gravity = wattrib.win_gravity;
913 void client_update_normal_hints(ObClient *self)
917 int oldgravity = self->gravity;
920 self->min_ratio = 0.0f;
921 self->max_ratio = 0.0f;
922 SIZE_SET(self->size_inc, 1, 1);
923 SIZE_SET(self->base_size, 0, 0);
924 SIZE_SET(self->min_size, 0, 0);
925 SIZE_SET(self->max_size, G_MAXINT, G_MAXINT);
927 /* get the hints from the window */
928 if (XGetWMNormalHints(ob_display, self->window, &size, &ret)) {
929 self->positioned = !!(size.flags & (PPosition|USPosition));
931 if (size.flags & PWinGravity) {
932 self->gravity = size.win_gravity;
934 /* if the client has a frame, i.e. has already been mapped and
935 is changing its gravity */
936 if (self->frame && self->gravity != oldgravity) {
937 /* move our idea of the client's position based on its new
939 self->area.x = self->frame->area.x;
940 self->area.y = self->frame->area.y;
941 frame_frame_gravity(self->frame, &self->area.x, &self->area.y);
945 if (size.flags & PAspect) {
946 if (size.min_aspect.y)
947 self->min_ratio = (float)size.min_aspect.x / size.min_aspect.y;
948 if (size.max_aspect.y)
949 self->max_ratio = (float)size.max_aspect.x / size.max_aspect.y;
952 if (size.flags & PMinSize)
953 SIZE_SET(self->min_size, size.min_width, size.min_height);
955 if (size.flags & PMaxSize)
956 SIZE_SET(self->max_size, size.max_width, size.max_height);
958 if (size.flags & PBaseSize)
959 SIZE_SET(self->base_size, size.base_width, size.base_height);
961 if (size.flags & PResizeInc)
962 SIZE_SET(self->size_inc, size.width_inc, size.height_inc);
966 void client_setup_decor_and_functions(ObClient *self)
968 /* start with everything (cept fullscreen) */
969 self->decorations = (OB_FRAME_DECOR_TITLEBAR |
970 OB_FRAME_DECOR_HANDLE |
971 OB_FRAME_DECOR_GRIPS |
972 OB_FRAME_DECOR_BORDER |
973 OB_FRAME_DECOR_ICON |
974 OB_FRAME_DECOR_ALLDESKTOPS |
975 OB_FRAME_DECOR_ICONIFY |
976 OB_FRAME_DECOR_MAXIMIZE |
977 OB_FRAME_DECOR_SHADE);
978 self->functions = (OB_CLIENT_FUNC_RESIZE |
979 OB_CLIENT_FUNC_MOVE |
980 OB_CLIENT_FUNC_ICONIFY |
981 OB_CLIENT_FUNC_MAXIMIZE |
982 OB_CLIENT_FUNC_SHADE);
983 if (self->delete_window) {
984 self->functions |= OB_CLIENT_FUNC_CLOSE;
985 self->decorations |= OB_FRAME_DECOR_CLOSE;
988 if (!(self->min_size.width < self->max_size.width ||
989 self->min_size.height < self->max_size.height))
990 self->functions &= ~OB_CLIENT_FUNC_RESIZE;
992 switch (self->type) {
993 case OB_CLIENT_TYPE_NORMAL:
994 /* normal windows retain all of the possible decorations and
995 functionality, and are the only windows that you can fullscreen */
996 self->functions |= OB_CLIENT_FUNC_FULLSCREEN;
999 case OB_CLIENT_TYPE_DIALOG:
1000 case OB_CLIENT_TYPE_UTILITY:
1001 /* these windows cannot be maximized */
1002 self->functions &= ~OB_CLIENT_FUNC_MAXIMIZE;
1005 case OB_CLIENT_TYPE_MENU:
1006 case OB_CLIENT_TYPE_TOOLBAR:
1007 /* these windows get less functionality */
1008 self->functions &= ~(OB_CLIENT_FUNC_ICONIFY | OB_CLIENT_FUNC_RESIZE);
1011 case OB_CLIENT_TYPE_DESKTOP:
1012 case OB_CLIENT_TYPE_DOCK:
1013 case OB_CLIENT_TYPE_SPLASH:
1014 /* none of these windows are manipulated by the window manager */
1015 self->decorations = 0;
1016 self->functions = 0;
1020 /* Mwm Hints are applied subtractively to what has already been chosen for
1021 decor and functionality */
1022 if (self->mwmhints.flags & OB_MWM_FLAG_DECORATIONS) {
1023 if (! (self->mwmhints.decorations & OB_MWM_DECOR_ALL)) {
1024 if (! ((self->mwmhints.decorations & OB_MWM_DECOR_HANDLE) ||
1025 (self->mwmhints.decorations & OB_MWM_DECOR_TITLE)))
1026 /* if the mwm hints request no handle or title, then all
1027 decorations are disabled */
1028 self->decorations = 0;
1032 if (self->mwmhints.flags & OB_MWM_FLAG_FUNCTIONS) {
1033 if (! (self->mwmhints.functions & OB_MWM_FUNC_ALL)) {
1034 if (! (self->mwmhints.functions & OB_MWM_FUNC_RESIZE))
1035 self->functions &= ~OB_CLIENT_FUNC_RESIZE;
1036 if (! (self->mwmhints.functions & OB_MWM_FUNC_MOVE))
1037 self->functions &= ~OB_CLIENT_FUNC_MOVE;
1038 /* dont let mwm hints kill any buttons
1039 if (! (self->mwmhints.functions & OB_MWM_FUNC_ICONIFY))
1040 self->functions &= ~OB_CLIENT_FUNC_ICONIFY;
1041 if (! (self->mwmhints.functions & OB_MWM_FUNC_MAXIMIZE))
1042 self->functions &= ~OB_CLIENT_FUNC_MAXIMIZE;
1044 /* dont let mwm hints kill the close button
1045 if (! (self->mwmhints.functions & MwmFunc_Close))
1046 self->functions &= ~OB_CLIENT_FUNC_CLOSE; */
1050 if (!(self->functions & OB_CLIENT_FUNC_SHADE))
1051 self->decorations &= ~OB_FRAME_DECOR_SHADE;
1052 if (!(self->functions & OB_CLIENT_FUNC_ICONIFY))
1053 self->decorations &= ~OB_FRAME_DECOR_ICONIFY;
1054 if (!(self->functions & OB_CLIENT_FUNC_RESIZE))
1055 self->decorations &= ~OB_FRAME_DECOR_GRIPS;
1057 /* can't maximize without moving/resizing */
1058 if (!((self->functions & OB_CLIENT_FUNC_MAXIMIZE) &&
1059 (self->functions & OB_CLIENT_FUNC_MOVE) &&
1060 (self->functions & OB_CLIENT_FUNC_RESIZE))) {
1061 self->functions &= ~OB_CLIENT_FUNC_MAXIMIZE;
1062 self->decorations &= ~OB_FRAME_DECOR_MAXIMIZE;
1065 /* finally, the user can have requested no decorations, which overrides
1067 if (!self->decorate)
1068 self->decorations = 0;
1070 /* if we don't have a titlebar, then we cannot shade! */
1071 if (!(self->decorations & OB_FRAME_DECOR_TITLEBAR))
1072 self->functions &= ~OB_CLIENT_FUNC_SHADE;
1074 /* now we need to check against rules for the client's current state */
1075 if (self->fullscreen) {
1076 self->functions &= (OB_CLIENT_FUNC_CLOSE |
1077 OB_CLIENT_FUNC_FULLSCREEN |
1078 OB_CLIENT_FUNC_ICONIFY);
1079 self->decorations = 0;
1082 client_change_allowed_actions(self);
1085 /* this makes sure that these windows appear on all desktops */
1086 if (self->type == OB_CLIENT_TYPE_DESKTOP &&
1087 self->desktop != DESKTOP_ALL)
1088 client_set_desktop(self, DESKTOP_ALL, FALSE);
1090 /* adjust the client's decorations, etc. */
1091 client_reconfigure(self);
1093 /* this makes sure that these windows appear on all desktops */
1094 if (self->type == OB_CLIENT_TYPE_DESKTOP &&
1095 self->desktop != DESKTOP_ALL)
1097 self->desktop = DESKTOP_ALL;
1102 static void client_change_allowed_actions(ObClient *self)
1107 /* desktop windows are kept on all desktops */
1108 if (self->type != OB_CLIENT_TYPE_DESKTOP)
1109 actions[num++] = prop_atoms.net_wm_action_change_desktop;
1111 if (self->functions & OB_CLIENT_FUNC_SHADE)
1112 actions[num++] = prop_atoms.net_wm_action_shade;
1113 if (self->functions & OB_CLIENT_FUNC_CLOSE)
1114 actions[num++] = prop_atoms.net_wm_action_close;
1115 if (self->functions & OB_CLIENT_FUNC_MOVE)
1116 actions[num++] = prop_atoms.net_wm_action_move;
1117 if (self->functions & OB_CLIENT_FUNC_ICONIFY)
1118 actions[num++] = prop_atoms.net_wm_action_minimize;
1119 if (self->functions & OB_CLIENT_FUNC_RESIZE)
1120 actions[num++] = prop_atoms.net_wm_action_resize;
1121 if (self->functions & OB_CLIENT_FUNC_FULLSCREEN)
1122 actions[num++] = prop_atoms.net_wm_action_fullscreen;
1123 if (self->functions & OB_CLIENT_FUNC_MAXIMIZE) {
1124 actions[num++] = prop_atoms.net_wm_action_maximize_horz;
1125 actions[num++] = prop_atoms.net_wm_action_maximize_vert;
1128 PROP_SETA32(self->window, net_wm_allowed_actions, atom, actions, num);
1130 /* make sure the window isn't breaking any rules now */
1132 if (!(self->functions & OB_CLIENT_FUNC_SHADE) && self->shaded) {
1133 if (self->frame) client_shade(self, FALSE);
1134 else self->shaded = FALSE;
1136 if (!(self->functions & OB_CLIENT_FUNC_ICONIFY) && self->iconic) {
1137 if (self->frame) client_iconify(self, FALSE, TRUE);
1138 else self->iconic = FALSE;
1140 if (!(self->functions & OB_CLIENT_FUNC_FULLSCREEN) && self->fullscreen) {
1141 if (self->frame) client_fullscreen(self, FALSE, TRUE);
1142 else self->fullscreen = FALSE;
1144 if (!(self->functions & OB_CLIENT_FUNC_MAXIMIZE) && (self->max_horz ||
1146 if (self->frame) client_maximize(self, FALSE, 0, TRUE);
1147 else self->max_vert = self->max_horz = FALSE;
1151 void client_reconfigure(ObClient *self)
1153 /* by making this pass FALSE for user, we avoid the emacs event storm where
1154 every configurenotify causes an update in its normal hints, i think this
1155 is generally what we want anyways... */
1156 client_configure(self, OB_CORNER_TOPLEFT, self->area.x, self->area.y,
1157 self->area.width, self->area.height, FALSE, TRUE);
1160 void client_update_wmhints(ObClient *self)
1163 gboolean ur = FALSE;
1166 /* assume a window takes input if it doesnt specify */
1167 self->can_focus = TRUE;
1169 if ((hints = XGetWMHints(ob_display, self->window)) != NULL) {
1170 if (hints->flags & InputHint)
1171 self->can_focus = hints->input;
1173 /* only do this when first managing the window *AND* when we aren't
1175 if (ob_state() != OB_STATE_STARTING && self->frame == NULL)
1176 if (hints->flags & StateHint)
1177 self->iconic = hints->initial_state == IconicState;
1179 if (hints->flags & XUrgencyHint)
1182 if (!(hints->flags & WindowGroupHint))
1183 hints->window_group = None;
1185 /* did the group state change? */
1186 if (hints->window_group !=
1187 (self->group ? self->group->leader : None)) {
1188 /* remove from the old group if there was one */
1189 if (self->group != NULL) {
1190 /* remove transients of the group */
1191 for (it = self->group->members; it; it = it->next)
1192 self->transients = g_slist_remove(self->transients,
1194 group_remove(self->group, self);
1197 if (hints->window_group != None) {
1198 self->group = group_add(hints->window_group, self);
1200 /* i can only have transients from the group if i am not
1202 if (!self->transient_for) {
1203 /* add other transients of the group that are already
1205 for (it = self->group->members; it; it = it->next) {
1206 ObClient *c = it->data;
1207 if (c != self && c->transient_for == OB_TRAN_GROUP)
1209 g_slist_append(self->transients, c);
1214 /* the WM_HINTS can contain an icon */
1215 client_update_icons(self);
1217 /* because the self->transient flag wont change from this call,
1218 we don't need to update the window's type and such, only its
1219 transient_for, and the transients lists of other windows in
1220 the group may be affected */
1221 client_update_transient_for(self);
1227 if (ur != self->urgent) {
1229 ob_debug("Urgent Hint for 0x%lx: %s\n", self->window,
1231 /* fire the urgent callback if we're mapped, otherwise, wait until
1232 after we're mapped */
1234 dispatch_client(Event_Client_Urgent, self, self->urgent, 0);
1238 void client_update_title(ObClient *self)
1244 gboolean read_title;
1246 g_free(self->title);
1249 if (!PROP_GETS(self->window, net_wm_name, utf8, &data))
1250 /* try old x stuff */
1251 if (!PROP_GETS(self->window, wm_name, locale, &data))
1252 data = g_strdup("Unnamed Window");
1254 /* look for duplicates and append a number */
1256 for (it = client_list; it; it = it->next)
1257 if (it->data != self) {
1258 ObClient *c = it->data;
1259 if (0 == strncmp(c->title, data, strlen(data)))
1260 nums |= 1 << c->title_count;
1262 /* find first free number */
1263 for (i = 1; i <= 32; ++i)
1264 if (!(nums & (1 << i))) {
1265 if (self->title_count == 1 || i == 1)
1266 self->title_count = i;
1269 /* dont display the number for the first window */
1270 if (self->title_count > 1) {
1271 char *vdata, *ndata;
1272 ndata = g_strdup_printf(" - [%u]", self->title_count);
1273 vdata = g_strconcat(data, ndata, NULL);
1279 PROP_SETS(self->window, net_wm_visible_name, data);
1284 frame_adjust_title(self->frame);
1286 /* update the icon title */
1288 g_free(self->icon_title);
1292 if (!PROP_GETS(self->window, net_wm_icon_name, utf8, &data))
1293 /* try old x stuff */
1294 if (!PROP_GETS(self->window, wm_icon_name, locale, &data)) {
1295 data = g_strdup(self->title);
1299 /* append the title count, dont display the number for the first window */
1300 if (read_title && self->title_count > 1) {
1301 char *vdata, *ndata;
1302 ndata = g_strdup_printf(" - [%u]", self->title_count);
1303 vdata = g_strconcat(data, ndata, NULL);
1309 PROP_SETS(self->window, net_wm_visible_icon_name, data);
1311 self->icon_title = data;
1314 void client_update_class(ObClient *self)
1319 if (self->name) g_free(self->name);
1320 if (self->class) g_free(self->class);
1321 if (self->role) g_free(self->role);
1323 self->name = self->class = self->role = NULL;
1325 if (PROP_GETSS(self->window, wm_class, locale, &data)) {
1327 self->name = g_strdup(data[0]);
1329 self->class = g_strdup(data[1]);
1334 if (PROP_GETS(self->window, wm_window_role, locale, &s))
1335 self->role = g_strdup(s);
1337 if (self->name == NULL) self->name = g_strdup("");
1338 if (self->class == NULL) self->class = g_strdup("");
1339 if (self->role == NULL) self->role = g_strdup("");
1342 void client_update_strut(ObClient *self)
1347 if (!PROP_GETA32(self->window, net_wm_strut, cardinal, &data, &num)) {
1348 STRUT_SET(self->strut, 0, 0, 0, 0);
1351 g_message("new strut: %d %d %d %d",
1352 data[0], data[2], data[1], data[3]);
1353 STRUT_SET(self->strut, data[0], data[2], data[1], data[3]);
1356 STRUT_SET(self->strut, 0, 0, 0, 0);
1360 /* updating here is pointless while we're being mapped cuz we're not in
1361 the client list yet */
1363 screen_update_areas();
1366 void client_update_icons(ObClient *self)
1372 for (i = 0; i < self->nicons; ++i)
1373 g_free(self->icons[i].data);
1374 if (self->nicons > 0)
1375 g_free(self->icons);
1378 if (PROP_GETA32(self->window, net_wm_icon, cardinal, &data, &num)) {
1379 /* figure out how many valid icons are in here */
1381 while (num - i > 2) {
1385 if (i > num || w*h == 0) break;
1389 self->icons = g_new(ObClientIcon, self->nicons);
1391 /* store the icons */
1393 for (j = 0; j < self->nicons; ++j) {
1396 w = self->icons[j].width = data[i++];
1397 h = self->icons[j].height = data[i++];
1399 if (w*h == 0) continue;
1401 self->icons[j].data = g_new(RrPixel32, w * h);
1402 for (x = 0, y = 0, t = 0; t < w * h; ++t, ++x, ++i) {
1407 self->icons[j].data[t] =
1408 (((data[i] >> 24) & 0xff) << RrDefaultAlphaOffset) +
1409 (((data[i] >> 16) & 0xff) << RrDefaultRedOffset) +
1410 (((data[i] >> 8) & 0xff) << RrDefaultGreenOffset) +
1411 (((data[i] >> 0) & 0xff) << RrDefaultBlueOffset);
1417 } else if (PROP_GETA32(self->window, kwm_win_icon,
1418 kwm_win_icon, &data, &num)) {
1421 self->icons = g_new(ObClientIcon, self->nicons);
1422 xerror_set_ignore(TRUE);
1423 if (!RrPixmapToRGBA(ob_rr_inst,
1425 &self->icons[self->nicons-1].width,
1426 &self->icons[self->nicons-1].height,
1427 &self->icons[self->nicons-1].data)) {
1428 g_free(&self->icons[self->nicons-1]);
1431 xerror_set_ignore(FALSE);
1437 if ((hints = XGetWMHints(ob_display, self->window))) {
1438 if (hints->flags & IconPixmapHint) {
1440 self->icons = g_new(ObClientIcon, self->nicons);
1441 xerror_set_ignore(TRUE);
1442 if (!RrPixmapToRGBA(ob_rr_inst,
1444 (hints->flags & IconMaskHint ?
1445 hints->icon_mask : None),
1446 &self->icons[self->nicons-1].width,
1447 &self->icons[self->nicons-1].height,
1448 &self->icons[self->nicons-1].data)){
1449 g_free(&self->icons[self->nicons-1]);
1452 xerror_set_ignore(FALSE);
1459 frame_adjust_icon(self->frame);
1462 static void client_change_state(ObClient *self)
1465 guint32 netstate[10];
1468 state[0] = self->wmstate;
1470 PROP_SETA32(self->window, wm_state, wm_state, state, 2);
1474 netstate[num++] = prop_atoms.net_wm_state_modal;
1476 netstate[num++] = prop_atoms.net_wm_state_shaded;
1478 netstate[num++] = prop_atoms.net_wm_state_hidden;
1479 if (self->skip_taskbar)
1480 netstate[num++] = prop_atoms.net_wm_state_skip_taskbar;
1481 if (self->skip_pager)
1482 netstate[num++] = prop_atoms.net_wm_state_skip_pager;
1483 if (self->fullscreen)
1484 netstate[num++] = prop_atoms.net_wm_state_fullscreen;
1486 netstate[num++] = prop_atoms.net_wm_state_maximized_vert;
1488 netstate[num++] = prop_atoms.net_wm_state_maximized_horz;
1490 netstate[num++] = prop_atoms.net_wm_state_above;
1492 netstate[num++] = prop_atoms.net_wm_state_below;
1493 PROP_SETA32(self->window, net_wm_state, atom, netstate, num);
1495 client_calc_layer(self);
1498 frame_adjust_state(self->frame);
1501 ObClient *client_search_focus_tree(ObClient *self)
1506 for (it = self->transients; it != NULL; it = it->next) {
1507 if (client_focused(it->data)) return it->data;
1508 if ((ret = client_search_focus_tree(it->data))) return ret;
1513 ObClient *client_search_focus_tree_full(ObClient *self)
1515 if (self->transient_for) {
1516 if (self->transient_for != OB_TRAN_GROUP) {
1517 return client_search_focus_tree_full(self->transient_for);
1520 gboolean recursed = FALSE;
1522 for (it = self->group->members; it; it = it->next)
1523 if (!((ObClient*)it->data)->transient_for) {
1525 if ((c = client_search_focus_tree_full(it->data)))
1534 /* this function checks the whole tree, the client_search_focus_tree~
1535 does not, so we need to check this window */
1536 if (client_focused(self))
1538 return client_search_focus_tree(self);
1541 static ObStackingLayer calc_layer(ObClient *self)
1545 if (self->fullscreen) l = OB_STACKING_LAYER_FULLSCREEN;
1546 else if (self->type == OB_CLIENT_TYPE_DESKTOP)
1547 l = OB_STACKING_LAYER_DESKTOP;
1548 else if (self->type == OB_CLIENT_TYPE_DOCK) {
1549 if (!self->below) l = OB_STACKING_LAYER_TOP;
1550 else l = OB_STACKING_LAYER_NORMAL;
1552 else if (self->above) l = OB_STACKING_LAYER_ABOVE;
1553 else if (self->below) l = OB_STACKING_LAYER_BELOW;
1554 else l = OB_STACKING_LAYER_NORMAL;
1559 static void client_calc_layer_recursive(ObClient *self, ObClient *orig,
1560 ObStackingLayer l, gboolean raised)
1562 ObStackingLayer old, own;
1566 own = calc_layer(self);
1567 self->layer = l > own ? l : own;
1569 for (it = self->transients; it; it = it->next)
1570 client_calc_layer_recursive(it->data, orig,
1571 l, raised ? raised : l != old);
1573 if (!raised && l != old)
1574 if (orig->frame) { /* only restack if the original window is managed */
1575 /* XXX add_non_intrusive ever? */
1576 stacking_remove(CLIENT_AS_WINDOW(self));
1577 stacking_add(CLIENT_AS_WINDOW(self));
1581 void client_calc_layer(ObClient *self)
1588 /* transients take on the layer of their parents */
1589 self = client_search_top_transient(self);
1591 l = calc_layer(self);
1593 client_calc_layer_recursive(self, orig, l, FALSE);
1596 gboolean client_should_show(ObClient *self)
1598 if (self->iconic) return FALSE;
1599 else if (!(self->desktop == screen_desktop ||
1600 self->desktop == DESKTOP_ALL)) return FALSE;
1601 else if (client_normal(self) && screen_showing_desktop) return FALSE;
1606 static void client_showhide(ObClient *self)
1609 if (client_should_show(self))
1610 frame_show(self->frame);
1612 frame_hide(self->frame);
1615 gboolean client_normal(ObClient *self) {
1616 return ! (self->type == OB_CLIENT_TYPE_DESKTOP ||
1617 self->type == OB_CLIENT_TYPE_DOCK ||
1618 self->type == OB_CLIENT_TYPE_SPLASH);
1621 static void client_apply_startup_state(ObClient *self)
1623 /* these are in a carefully crafted order.. */
1626 self->iconic = FALSE;
1627 client_iconify(self, TRUE, FALSE);
1629 if (self->fullscreen) {
1630 self->fullscreen = FALSE;
1631 client_fullscreen(self, TRUE, FALSE);
1634 self->shaded = FALSE;
1635 client_shade(self, TRUE);
1638 dispatch_client(Event_Client_Urgent, self, self->urgent, 0);
1640 if (self->max_vert && self->max_horz) {
1641 self->max_vert = self->max_horz = FALSE;
1642 client_maximize(self, TRUE, 0, FALSE);
1643 } else if (self->max_vert) {
1644 self->max_vert = FALSE;
1645 client_maximize(self, TRUE, 2, FALSE);
1646 } else if (self->max_horz) {
1647 self->max_horz = FALSE;
1648 client_maximize(self, TRUE, 1, FALSE);
1651 /* nothing to do for the other states:
1660 void client_configure(ObClient *self, ObCorner anchor,
1661 int x, int y, int w, int h,
1662 gboolean user, gboolean final)
1664 gboolean moved = FALSE, resized = FALSE;
1666 /* gets the frame's position */
1667 frame_client_gravity(self->frame, &x, &y);
1669 /* these positions are frame positions, not client positions */
1671 /* set the size and position if fullscreen */
1672 if (self->fullscreen) {
1675 XF86VidModeModeLine mode;
1680 i = client_monitor(self);
1681 a = screen_physical_area_monitor(i);
1684 if (i == 0 && /* primary head */
1685 extensions_vidmode &&
1686 XF86VidModeGetViewPort(ob_display, ob_screen, &x, &y) &&
1687 /* get the mode last so the mode.privsize isnt freed incorrectly */
1688 XF86VidModeGetModeLine(ob_display, ob_screen, &dot, &mode)) {
1693 if (mode.privsize) XFree(mode.private);
1703 user = FALSE; /* ignore that increment etc shit when in fullscreen */
1707 a = screen_area_monitor(self->desktop, client_monitor(self));
1709 /* set the size and position if maximized */
1710 if (self->max_horz) {
1711 x = a->x - self->frame->size.left;
1714 if (self->max_vert) {
1716 h = a->height - self->frame->size.top - self->frame->size.bottom;
1720 /* gets the client's position */
1721 frame_frame_gravity(self->frame, &x, &y);
1723 /* these override the above states! if you cant move you can't move! */
1725 if (!(self->functions & OB_CLIENT_FUNC_MOVE)) {
1729 if (!(self->functions & OB_CLIENT_FUNC_RESIZE)) {
1730 w = self->area.width;
1731 h = self->area.height;
1735 if (!(w == self->area.width && h == self->area.height)) {
1736 int basew, baseh, minw, minh;
1738 /* base size is substituted with min size if not specified */
1739 if (self->base_size.width || self->base_size.height) {
1740 basew = self->base_size.width;
1741 baseh = self->base_size.height;
1743 basew = self->min_size.width;
1744 baseh = self->min_size.height;
1746 /* min size is substituted with base size if not specified */
1747 if (self->min_size.width || self->min_size.height) {
1748 minw = self->min_size.width;
1749 minh = self->min_size.height;
1751 minw = self->base_size.width;
1752 minh = self->base_size.height;
1756 /* for interactive resizing. have to move half an increment in each
1759 /* how far we are towards the next size inc */
1760 int mw = (w - basew) % self->size_inc.width;
1761 int mh = (h - baseh) % self->size_inc.height;
1763 int aw = self->size_inc.width / 2;
1764 int ah = self->size_inc.height / 2;
1765 /* don't let us move into a new size increment */
1766 if (mw + aw >= self->size_inc.width)
1767 aw = self->size_inc.width - mw - 1;
1768 if (mh + ah >= self->size_inc.height)
1769 ah = self->size_inc.height - mh - 1;
1773 /* if this is a user-requested resize, then check against min/max
1776 /* smaller than min size or bigger than max size? */
1777 if (w > self->max_size.width) w = self->max_size.width;
1778 if (w < minw) w = minw;
1779 if (h > self->max_size.height) h = self->max_size.height;
1780 if (h < minh) h = minh;
1786 /* keep to the increments */
1787 w /= self->size_inc.width;
1788 h /= self->size_inc.height;
1790 /* you cannot resize to nothing */
1794 /* store the logical size */
1795 SIZE_SET(self->logical_size, w, h);
1797 w *= self->size_inc.width;
1798 h *= self->size_inc.height;
1804 /* adjust the height to match the width for the aspect ratios.
1805 for this, min size is not substituted for base size ever. */
1806 w -= self->base_size.width;
1807 h -= self->base_size.height;
1809 if (self->min_ratio)
1810 if (h * self->min_ratio > w) h = (int)(w / self->min_ratio);
1811 if (self->max_ratio)
1812 if (h * self->max_ratio < w) h = (int)(w / self->max_ratio);
1814 w += self->base_size.width;
1815 h += self->base_size.height;
1820 case OB_CORNER_TOPLEFT:
1822 case OB_CORNER_TOPRIGHT:
1823 x -= w - self->area.width;
1825 case OB_CORNER_BOTTOMLEFT:
1826 y -= h - self->area.height;
1828 case OB_CORNER_BOTTOMRIGHT:
1829 x -= w - self->area.width;
1830 y -= h - self->area.height;
1834 moved = x != self->area.x || y != self->area.y;
1835 resized = w != self->area.width || h != self->area.height;
1837 RECT_SET(self->area, x, y, w, h);
1839 /* for app-requested resizes, always resize if 'resized' is true.
1840 for user-requested ones, only resize if final is true, or when
1841 resizing in opaque mode */
1842 if ((!user && resized) ||
1843 (user && (final || (resized && config_opaque_resize))))
1844 XResizeWindow(ob_display, self->window, w, h);
1846 /* move/resize the frame to match the request */
1848 if (self->decorations != self->frame->decorations)
1849 moved = resized = TRUE;
1851 if (moved || resized)
1852 frame_adjust_area(self->frame, moved, resized);
1854 /* If you send this and the client hasn't changed you end up with buggy
1855 clients (emacs) freaking out, cuz they send back a configure every
1856 time they receive this event, which resends them this event... etc.
1858 if ((!user && moved) || (user && final)) {
1860 event.type = ConfigureNotify;
1861 event.xconfigure.display = ob_display;
1862 event.xconfigure.event = self->window;
1863 event.xconfigure.window = self->window;
1865 /* root window real coords */
1866 event.xconfigure.x = self->frame->area.x + self->frame->size.left;
1867 event.xconfigure.y = self->frame->area.y + self->frame->size.top;
1869 event.xconfigure.width = w;
1870 event.xconfigure.height = h;
1871 event.xconfigure.border_width = 0;
1872 event.xconfigure.above = self->frame->plate;
1873 event.xconfigure.override_redirect = FALSE;
1874 XSendEvent(event.xconfigure.display, event.xconfigure.window,
1875 FALSE, StructureNotifyMask, &event);
1880 void client_fullscreen(ObClient *self, gboolean fs, gboolean savearea)
1884 if (!(self->functions & OB_CLIENT_FUNC_FULLSCREEN) || /* can't */
1885 self->fullscreen == fs) return; /* already done */
1887 self->fullscreen = fs;
1888 client_change_state(self); /* change the state hints on the client,
1889 and adjust out layer/stacking */
1893 guint32 dimensions[4];
1894 dimensions[0] = self->area.x;
1895 dimensions[1] = self->area.y;
1896 dimensions[2] = self->area.width;
1897 dimensions[3] = self->area.height;
1899 PROP_SETA32(self->window, openbox_premax, cardinal,
1903 /* these are not actually used cuz client_configure will set them
1904 as appropriate when the window is fullscreened */
1911 /* pick some fallbacks... */
1912 a = screen_area_monitor(self->desktop, 0);
1913 x = a->x + a->width / 4;
1914 y = a->y + a->height / 4;
1918 if (PROP_GETA32(self->window, openbox_premax, cardinal,
1919 (guint32**)&dimensions, &num)) {
1930 client_setup_decor_and_functions(self);
1932 client_configure(self, OB_CORNER_TOPLEFT, x, y, w, h, TRUE, TRUE);
1934 /* try focus us when we go into fullscreen mode */
1938 static void client_iconify_recursive(ObClient *self,
1939 gboolean iconic, gboolean curdesk)
1942 gboolean changed = FALSE;
1945 if (self->iconic != iconic) {
1946 ob_debug("%sconifying window: 0x%lx\n", (iconic ? "I" : "Uni"),
1949 self->iconic = iconic;
1952 if (self->functions & OB_CLIENT_FUNC_ICONIFY) {
1953 self->wmstate = IconicState;
1954 self->ignore_unmaps++;
1955 /* we unmap the client itself so that we can get MapRequest
1956 events, and because the ICCCM tells us to! */
1957 XUnmapWindow(ob_display, self->window);
1959 /* update the focus lists.. iconic windows go to the bottom of
1960 the list, put the new iconic window at the 'top of the
1962 focus_order_to_top(self);
1968 client_set_desktop(self, screen_desktop, FALSE);
1969 self->wmstate = self->shaded ? IconicState : NormalState;
1970 XMapWindow(ob_display, self->window);
1972 /* this puts it after the current focused window */
1973 focus_order_remove(self);
1974 focus_order_add_new(self);
1976 /* this is here cuz with the VIDMODE extension, the viewport can
1977 change while a fullscreen window is iconic, and when it
1978 uniconifies, it would be nice if it did so to the new position
1980 client_reconfigure(self);
1987 client_change_state(self);
1988 client_showhide(self);
1989 screen_update_areas();
1991 dispatch_client(iconic ? Event_Client_Unmapped : Event_Client_Mapped,
1995 /* iconify all transients */
1996 for (it = self->transients; it != NULL; it = it->next)
1997 if (it->data != self) client_iconify_recursive(it->data,
2001 void client_iconify(ObClient *self, gboolean iconic, gboolean curdesk)
2003 /* move up the transient chain as far as possible first */
2004 self = client_search_top_transient(self);
2006 client_iconify_recursive(client_search_top_transient(self),
2010 void client_maximize(ObClient *self, gboolean max, int dir, gboolean savearea)
2014 g_assert(dir == 0 || dir == 1 || dir == 2);
2015 if (!(self->functions & OB_CLIENT_FUNC_MAXIMIZE)) return; /* can't */
2017 /* check if already done */
2019 if (dir == 0 && self->max_horz && self->max_vert) return;
2020 if (dir == 1 && self->max_horz) return;
2021 if (dir == 2 && self->max_vert) return;
2023 if (dir == 0 && !self->max_horz && !self->max_vert) return;
2024 if (dir == 1 && !self->max_horz) return;
2025 if (dir == 2 && !self->max_vert) return;
2028 /* work with the frame's coords */
2029 x = self->frame->area.x;
2030 y = self->frame->area.y;
2031 w = self->area.width;
2032 h = self->area.height;
2036 gint32 dimensions[4];
2045 /* get the property off the window and use it for the dimensions
2046 we are already maxed on */
2047 if (PROP_GETA32(self->window, openbox_premax, cardinal,
2048 (guint32**)&readdim, &num)) {
2050 if (self->max_horz) {
2051 dimensions[0] = readdim[0];
2052 dimensions[2] = readdim[2];
2054 if (self->max_vert) {
2055 dimensions[1] = readdim[1];
2056 dimensions[3] = readdim[3];
2062 PROP_SETA32(self->window, openbox_premax, cardinal,
2063 (guint32*)dimensions, 4);
2070 /* pick some fallbacks... */
2071 a = screen_area_monitor(self->desktop, 0);
2072 if (dir == 0 || dir == 1) { /* horz */
2073 x = a->x + a->width / 4;
2076 if (dir == 0 || dir == 2) { /* vert */
2077 y = a->y + a->height / 4;
2081 if (PROP_GETA32(self->window, openbox_premax, cardinal,
2082 (guint32**)&dimensions, &num)) {
2084 if (dir == 0 || dir == 1) { /* horz */
2088 if (dir == 0 || dir == 2) { /* vert */
2097 if (dir == 0 || dir == 1) /* horz */
2098 self->max_horz = max;
2099 if (dir == 0 || dir == 2) /* vert */
2100 self->max_vert = max;
2102 if (!self->max_horz && !self->max_vert)
2103 PROP_ERASE(self->window, openbox_premax);
2105 client_change_state(self); /* change the state hints on the client */
2107 /* figure out where the client should be going */
2108 frame_frame_gravity(self->frame, &x, &y);
2109 client_configure(self, OB_CORNER_TOPLEFT, x, y, w, h, TRUE, TRUE);
2112 void client_shade(ObClient *self, gboolean shade)
2114 if ((!(self->functions & OB_CLIENT_FUNC_SHADE) &&
2115 shade) || /* can't shade */
2116 self->shaded == shade) return; /* already done */
2118 /* when we're iconic, don't change the wmstate */
2120 self->wmstate = shade ? IconicState : NormalState;
2121 self->shaded = shade;
2122 client_change_state(self);
2123 /* resize the frame to just the titlebar */
2124 frame_adjust_area(self->frame, FALSE, FALSE);
2127 void client_close(ObClient *self)
2131 if (!(self->functions & OB_CLIENT_FUNC_CLOSE)) return;
2134 XXX: itd be cool to do timeouts and shit here for killing the client's
2136 like... if the window is around after 5 seconds, then the close button
2137 turns a nice red, and if this function is called again, the client is
2141 ce.xclient.type = ClientMessage;
2142 ce.xclient.message_type = prop_atoms.wm_protocols;
2143 ce.xclient.display = ob_display;
2144 ce.xclient.window = self->window;
2145 ce.xclient.format = 32;
2146 ce.xclient.data.l[0] = prop_atoms.wm_delete_window;
2147 ce.xclient.data.l[1] = event_lasttime;
2148 ce.xclient.data.l[2] = 0l;
2149 ce.xclient.data.l[3] = 0l;
2150 ce.xclient.data.l[4] = 0l;
2151 XSendEvent(ob_display, self->window, FALSE, NoEventMask, &ce);
2154 void client_kill(ObClient *self)
2156 XKillClient(ob_display, self->window);
2159 void client_set_desktop_recursive(ObClient *self,
2160 guint target, gboolean donthide)
2165 if (target != self->desktop) {
2167 ob_debug("Setting desktop %u\n", target+1);
2169 g_assert(target < screen_num_desktops || target == DESKTOP_ALL);
2171 /* remove from the old desktop(s) */
2172 focus_order_remove(self);
2174 old = self->desktop;
2175 self->desktop = target;
2176 PROP_SET32(self->window, net_wm_desktop, cardinal, target);
2177 /* the frame can display the current desktop state */
2178 frame_adjust_state(self->frame);
2179 /* 'move' the window to the new desktop */
2181 client_showhide(self);
2182 /* raise if it was not already on the desktop */
2183 if (old != DESKTOP_ALL)
2184 stacking_raise(CLIENT_AS_WINDOW(self));
2185 screen_update_areas();
2187 /* add to the new desktop(s) */
2188 if (config_focus_new)
2189 focus_order_to_top(self);
2191 focus_order_to_bottom(self);
2193 dispatch_client(Event_Client_Desktop, self, target, old);
2196 /* move all transients */
2197 for (it = self->transients; it != NULL; it = it->next)
2198 if (it->data != self) client_set_desktop_recursive(it->data,
2202 void client_set_desktop(ObClient *self, guint target, gboolean donthide)
2204 client_set_desktop_recursive(client_search_top_transient(self),
2208 ObClient *client_search_modal_child(ObClient *self)
2213 for (it = self->transients; it != NULL; it = it->next) {
2214 ObClient *c = it->data;
2215 if ((ret = client_search_modal_child(c))) return ret;
2216 if (c->modal) return c;
2221 gboolean client_validate(ObClient *self)
2225 XSync(ob_display, FALSE); /* get all events on the server */
2227 if (XCheckTypedWindowEvent(ob_display, self->window, DestroyNotify, &e) ||
2228 XCheckTypedWindowEvent(ob_display, self->window, UnmapNotify, &e)) {
2229 XPutBackEvent(ob_display, &e);
2236 void client_set_wm_state(ObClient *self, long state)
2238 if (state == self->wmstate) return; /* no change */
2242 client_iconify(self, TRUE, TRUE);
2245 client_iconify(self, FALSE, TRUE);
2250 void client_set_state(ObClient *self, Atom action, long data1, long data2)
2252 gboolean shaded = self->shaded;
2253 gboolean fullscreen = self->fullscreen;
2254 gboolean max_horz = self->max_horz;
2255 gboolean max_vert = self->max_vert;
2258 if (!(action == prop_atoms.net_wm_state_add ||
2259 action == prop_atoms.net_wm_state_remove ||
2260 action == prop_atoms.net_wm_state_toggle))
2261 /* an invalid action was passed to the client message, ignore it */
2264 for (i = 0; i < 2; ++i) {
2265 Atom state = i == 0 ? data1 : data2;
2267 if (!state) continue;
2269 /* if toggling, then pick whether we're adding or removing */
2270 if (action == prop_atoms.net_wm_state_toggle) {
2271 if (state == prop_atoms.net_wm_state_modal)
2272 action = self->modal ? prop_atoms.net_wm_state_remove :
2273 prop_atoms.net_wm_state_add;
2274 else if (state == prop_atoms.net_wm_state_maximized_vert)
2275 action = self->max_vert ? prop_atoms.net_wm_state_remove :
2276 prop_atoms.net_wm_state_add;
2277 else if (state == prop_atoms.net_wm_state_maximized_horz)
2278 action = self->max_horz ? prop_atoms.net_wm_state_remove :
2279 prop_atoms.net_wm_state_add;
2280 else if (state == prop_atoms.net_wm_state_shaded)
2281 action = self->shaded ? prop_atoms.net_wm_state_remove :
2282 prop_atoms.net_wm_state_add;
2283 else if (state == prop_atoms.net_wm_state_skip_taskbar)
2284 action = self->skip_taskbar ?
2285 prop_atoms.net_wm_state_remove :
2286 prop_atoms.net_wm_state_add;
2287 else if (state == prop_atoms.net_wm_state_skip_pager)
2288 action = self->skip_pager ?
2289 prop_atoms.net_wm_state_remove :
2290 prop_atoms.net_wm_state_add;
2291 else if (state == prop_atoms.net_wm_state_fullscreen)
2292 action = self->fullscreen ?
2293 prop_atoms.net_wm_state_remove :
2294 prop_atoms.net_wm_state_add;
2295 else if (state == prop_atoms.net_wm_state_above)
2296 action = self->above ? prop_atoms.net_wm_state_remove :
2297 prop_atoms.net_wm_state_add;
2298 else if (state == prop_atoms.net_wm_state_below)
2299 action = self->below ? prop_atoms.net_wm_state_remove :
2300 prop_atoms.net_wm_state_add;
2303 if (action == prop_atoms.net_wm_state_add) {
2304 if (state == prop_atoms.net_wm_state_modal) {
2305 /* XXX raise here or something? */
2307 } else if (state == prop_atoms.net_wm_state_maximized_vert) {
2309 } else if (state == prop_atoms.net_wm_state_maximized_horz) {
2311 } else if (state == prop_atoms.net_wm_state_shaded) {
2313 } else if (state == prop_atoms.net_wm_state_skip_taskbar) {
2314 self->skip_taskbar = TRUE;
2315 } else if (state == prop_atoms.net_wm_state_skip_pager) {
2316 self->skip_pager = TRUE;
2317 } else if (state == prop_atoms.net_wm_state_fullscreen) {
2319 } else if (state == prop_atoms.net_wm_state_above) {
2321 } else if (state == prop_atoms.net_wm_state_below) {
2325 } else { /* action == prop_atoms.net_wm_state_remove */
2326 if (state == prop_atoms.net_wm_state_modal) {
2327 self->modal = FALSE;
2328 } else if (state == prop_atoms.net_wm_state_maximized_vert) {
2330 } else if (state == prop_atoms.net_wm_state_maximized_horz) {
2332 } else if (state == prop_atoms.net_wm_state_shaded) {
2334 } else if (state == prop_atoms.net_wm_state_skip_taskbar) {
2335 self->skip_taskbar = FALSE;
2336 } else if (state == prop_atoms.net_wm_state_skip_pager) {
2337 self->skip_pager = FALSE;
2338 } else if (state == prop_atoms.net_wm_state_fullscreen) {
2340 } else if (state == prop_atoms.net_wm_state_above) {
2341 self->above = FALSE;
2342 } else if (state == prop_atoms.net_wm_state_below) {
2343 self->below = FALSE;
2347 if (max_horz != self->max_horz || max_vert != self->max_vert) {
2348 if (max_horz != self->max_horz && max_vert != self->max_vert) {
2350 if (max_horz == max_vert) { /* both going the same way */
2351 client_maximize(self, max_horz, 0, TRUE);
2353 client_maximize(self, max_horz, 1, TRUE);
2354 client_maximize(self, max_vert, 2, TRUE);
2358 if (max_horz != self->max_horz)
2359 client_maximize(self, max_horz, 1, TRUE);
2361 client_maximize(self, max_vert, 2, TRUE);
2364 /* change fullscreen state before shading, as it will affect if the window
2366 if (fullscreen != self->fullscreen)
2367 client_fullscreen(self, fullscreen, TRUE);
2368 if (shaded != self->shaded)
2369 client_shade(self, shaded);
2370 client_calc_layer(self);
2371 client_change_state(self); /* change the hint to reflect these changes */
2374 ObClient *client_focus_target(ObClient *self)
2378 /* if we have a modal child, then focus it, not us */
2379 child = client_search_modal_child(self);
2380 if (child) return child;
2384 gboolean client_can_focus(ObClient *self)
2388 /* choose the correct target */
2389 self = client_focus_target(self);
2391 if (!self->frame->visible)
2394 if (!((self->can_focus || self->focus_notify) &&
2395 (self->desktop == screen_desktop ||
2396 self->desktop == DESKTOP_ALL) &&
2400 /* do a check to see if the window has already been unmapped or destroyed
2401 do this intelligently while watching out for unmaps we've generated
2402 (ignore_unmaps > 0) */
2403 if (XCheckTypedWindowEvent(ob_display, self->window,
2404 DestroyNotify, &ev)) {
2405 XPutBackEvent(ob_display, &ev);
2408 while (XCheckTypedWindowEvent(ob_display, self->window,
2409 UnmapNotify, &ev)) {
2410 if (self->ignore_unmaps) {
2411 self->ignore_unmaps--;
2413 XPutBackEvent(ob_display, &ev);
2421 gboolean client_focus(ObClient *self)
2423 /* choose the correct target */
2424 self = client_focus_target(self);
2426 if (!client_can_focus(self)) {
2427 if (!self->frame->visible) {
2428 /* update the focus lists */
2429 focus_order_to_top(self);
2434 if (self->can_focus)
2435 /* RevertToPointerRoot causes much more headache than RevertToNone, so
2436 I choose to use it always, hopefully to find errors quicker, if any
2437 are left. (I hate X. I hate focus events.) */
2438 XSetInputFocus(ob_display, self->window, RevertToPointerRoot,
2441 if (self->focus_notify) {
2443 ce.xclient.type = ClientMessage;
2444 ce.xclient.message_type = prop_atoms.wm_protocols;
2445 ce.xclient.display = ob_display;
2446 ce.xclient.window = self->window;
2447 ce.xclient.format = 32;
2448 ce.xclient.data.l[0] = prop_atoms.wm_take_focus;
2449 ce.xclient.data.l[1] = event_lasttime;
2450 ce.xclient.data.l[2] = 0l;
2451 ce.xclient.data.l[3] = 0l;
2452 ce.xclient.data.l[4] = 0l;
2453 XSendEvent(ob_display, self->window, FALSE, NoEventMask, &ce);
2457 ob_debug("%sively focusing %lx at %d\n",
2458 (self->can_focus ? "act" : "pass"),
2459 self->window, (int) event_lasttime);
2462 /* Cause the FocusIn to come back to us. Important for desktop switches,
2463 since otherwise we'll have no FocusIn on the queue and send it off to
2464 the focus_backup. */
2465 XSync(ob_display, FALSE);
2469 void client_unfocus(ObClient *self)
2471 g_assert(focus_client == self);
2473 ob_debug("client_unfocus for %lx\n", self->window);
2475 focus_fallback(OB_FOCUS_FALLBACK_UNFOCUSING);
2478 void client_activate(ObClient *self)
2480 if (client_normal(self) && screen_showing_desktop)
2481 screen_show_desktop(FALSE);
2483 client_iconify(self, FALSE, FALSE);
2484 if (self->desktop != DESKTOP_ALL &&
2485 self->desktop != screen_desktop)
2486 screen_set_desktop(self->desktop);
2487 else if (!self->frame->visible)
2488 /* if its not visible for other reasons, then don't mess
2492 client_shade(self, FALSE);
2494 stacking_raise(CLIENT_AS_WINDOW(self));
2497 gboolean client_focused(ObClient *self)
2499 return self == focus_client;
2502 ObClientIcon *client_icon(ObClient *self, int w, int h)
2505 /* si is the smallest image >= req */
2506 /* li is the largest image < req */
2507 unsigned long size, smallest = 0xffffffff, largest = 0, si = 0, li = 0;
2509 if (!self->nicons) return NULL;
2511 for (i = 0; i < self->nicons; ++i) {
2512 size = self->icons[i].width * self->icons[i].height;
2513 if (size < smallest && size >= (unsigned)(w * h)) {
2517 if (size > largest && size <= (unsigned)(w * h)) {
2522 if (largest == 0) /* didnt find one smaller than the requested size */
2523 return &self->icons[si];
2524 return &self->icons[li];
2527 /* this be mostly ripped from fvwm */
2528 ObClient *client_find_directional(ObClient *c, ObDirection dir)
2530 int my_cx, my_cy, his_cx, his_cy;
2533 int score, best_score;
2534 ObClient *best_client, *cur;
2540 /* first, find the centre coords of the currently focused window */
2541 my_cx = c->frame->area.x + c->frame->area.width / 2;
2542 my_cy = c->frame->area.y + c->frame->area.height / 2;
2547 for(it = g_list_first(client_list); it; it = it->next) {
2550 /* the currently selected window isn't interesting */
2553 if (!client_normal(cur))
2555 if(c->desktop != cur->desktop && cur->desktop != DESKTOP_ALL)
2559 if(client_focus_target(cur) == cur &&
2560 !(cur->can_focus || cur->focus_notify))
2563 /* find the centre coords of this window, from the
2564 * currently focused window's point of view */
2565 his_cx = (cur->frame->area.x - my_cx)
2566 + cur->frame->area.width / 2;
2567 his_cy = (cur->frame->area.y - my_cy)
2568 + cur->frame->area.height / 2;
2572 /* Rotate the diagonals 45 degrees counterclockwise.
2573 * To do this, multiply the matrix /+h +h\ with the
2574 * vector (x y). \-h +h/
2575 * h = sqrt(0.5). We can set h := 1 since absolute
2576 * distance doesn't matter here. */
2577 tx = his_cx + his_cy;
2578 his_cy = -his_cx + his_cy;
2583 case OB_DIRECTION_NORTH:
2584 case OB_DIRECTION_SOUTH:
2585 case OB_DIRECTION_NORTHEAST:
2586 case OB_DIRECTION_SOUTHWEST:
2587 offset = (his_cx < 0) ? -his_cx : his_cx;
2588 distance = ((dir == OB_DIRECTION_NORTH ||
2589 dir == OB_DIRECTION_NORTHEAST) ?
2592 case OB_DIRECTION_EAST:
2593 case OB_DIRECTION_WEST:
2594 case OB_DIRECTION_SOUTHEAST:
2595 case OB_DIRECTION_NORTHWEST:
2596 offset = (his_cy < 0) ? -his_cy : his_cy;
2597 distance = ((dir == OB_DIRECTION_WEST ||
2598 dir == OB_DIRECTION_NORTHWEST) ?
2603 /* the target must be in the requested direction */
2607 /* Calculate score for this window. The smaller the better. */
2608 score = distance + offset;
2610 /* windows more than 45 degrees off the direction are
2611 * heavily penalized and will only be chosen if nothing
2612 * else within a million pixels */
2613 if(offset > distance)
2616 if(best_score == -1 || score < best_score)
2624 void client_set_layer(ObClient *self, int layer)
2628 self->above = FALSE;
2629 } else if (layer == 0) {
2630 self->below = self->above = FALSE;
2632 self->below = FALSE;
2635 client_calc_layer(self);
2636 client_change_state(self); /* reflect this in the state hints */
2639 guint client_monitor(ObClient *self)
2643 for (i = 0; i < screen_num_monitors; ++i) {
2644 Rect *area = screen_physical_area_monitor(i);
2645 if (RECT_INTERSECTS_RECT(*area, self->frame->area))
2648 if (i == screen_num_monitors) i = 0;
2649 g_assert(i < screen_num_monitors);
2653 ObClient *client_search_top_transient(ObClient *self)
2655 /* move up the transient chain as far as possible */
2656 if (self->transient_for) {
2657 if (self->transient_for != OB_TRAN_GROUP) {
2658 return client_search_top_transient(self->transient_for);
2662 for (it = self->group->members; it; it = it->next) {
2663 ObClient *c = it->data;
2665 /* checking transient_for prevents infinate loops! */
2666 if (c != self && !c->transient_for)
2677 ObClient *client_search_transient(ObClient *self, ObClient *search)
2681 for (sit = self->transients; sit; sit = g_slist_next(sit)) {
2682 if (sit->data == search)
2684 if (client_search_transient(sit->data, search))