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 (!(self->strut.left || self->strut.right ||
304 self->strut.top || self->strut.bottom))
305 client_move_onscreen(self, TRUE);
307 screen_update_areas();
309 client_showhide(self);
311 /* use client_focus instead of client_activate cuz client_activate does
312 stuff like switch desktops etc and I'm not interested in all that when
313 a window maps since its not based on an action from the user like
314 clicking a window to activate is. so keep the new window out of the way
316 if (activate) client_focus(self);
318 /* client_activate does this but we aret using it so we have to do it
320 if (screen_showing_desktop)
321 screen_show_desktop(FALSE);
323 /* update the list hints */
326 dispatch_client(Event_Client_Mapped, self, 0, 0);
328 ob_debug("Managed window 0x%lx (%s)\n", window, self->class);
331 void client_unmanage_all()
333 while (client_list != NULL)
334 client_unmanage(client_list->data);
337 /* called by client_unmanage() to close any menus referencing this client */
338 void client_close_menus(gpointer key, gpointer value, gpointer self)
340 if (((ObMenu *)value)->client == (ObClient *)self)
341 menu_hide((ObMenu *)value);
344 void client_unmanage(ObClient *self)
349 ob_debug("Unmanaging window: %lx (%s)\n", self->window, self->class);
351 dispatch_client(Event_Client_Destroy, self, 0, 0);
352 g_assert(self != NULL);
354 /* remove the window from our save set */
355 XChangeSaveSet(ob_display, self->window, SetModeDelete);
357 /* we dont want events no more */
358 XSelectInput(ob_display, self->window, NoEventMask);
360 frame_hide(self->frame);
362 client_list = g_list_remove(client_list, self);
363 stacking_remove(self);
364 g_hash_table_remove(window_map, &self->window);
366 /* update the focus lists */
367 focus_order_remove(self);
369 /* once the client is out of the list, update the struts to remove it's
371 screen_update_areas();
373 /* tell our parent(s) that we're gone */
374 if (self->transient_for == OB_TRAN_GROUP) { /* transient of group */
377 for (it = self->group->members; it; it = it->next)
378 if (it->data != self)
379 ((ObClient*)it->data)->transients =
380 g_slist_remove(((ObClient*)it->data)->transients, self);
381 } else if (self->transient_for) { /* transient of window */
382 self->transient_for->transients =
383 g_slist_remove(self->transient_for->transients, self);
386 /* tell our transients that we're gone */
387 for (it = self->transients; it != NULL; it = it->next) {
388 if (((ObClient*)it->data)->transient_for != OB_TRAN_GROUP) {
389 ((ObClient*)it->data)->transient_for = NULL;
390 client_calc_layer(it->data);
394 if (moveresize_client == self)
395 moveresize_end(TRUE);
397 /* close any windows that are attached to this window */
398 g_hash_table_foreach(menu_hash, client_close_menus, self);
401 if (focus_client == self) {
404 /* focus the last focused window on the desktop, and ignore enter
405 events from the unmap so it doesnt mess with the focus */
406 while (XCheckTypedEvent(ob_display, EnterNotify, &e));
407 client_unfocus(self);
410 /* remove from its group */
412 group_remove(self->group, self);
416 /* dispatch the unmapped event */
417 dispatch_client(Event_Client_Unmapped, self, 0, 0);
418 g_assert(self != NULL);
420 /* give the client its border back */
421 client_toggle_border(self, TRUE);
423 /* reparent the window out of the frame, and free the frame */
424 frame_release_client(self->frame, self);
427 if (ob_state() != OB_STATE_EXITING) {
428 /* these values should not be persisted across a window
430 PROP_ERASE(self->window, net_wm_desktop);
431 PROP_ERASE(self->window, net_wm_state);
433 /* if we're left in an iconic state, the client wont be mapped. this is
434 bad, since we will no longer be managing the window on restart */
436 XMapWindow(ob_display, self->window);
440 ob_debug("Unmanaged window 0x%lx\n", self->window);
442 /* free all data allocated in the client struct */
443 g_slist_free(self->transients);
444 for (j = 0; j < self->nicons; ++j)
445 g_free(self->icons[j].data);
446 if (self->nicons > 0)
449 g_free(self->icon_title);
455 /* update the list hints */
459 void client_move_onscreen(ObClient *self, gboolean rude)
461 int x = self->area.x;
462 int y = self->area.y;
463 if (client_find_onscreen(self, &x, &y,
464 self->area.width, self->area.height, rude)) {
465 client_configure(self, OB_CORNER_TOPLEFT, x, y,
466 self->area.width, self->area.height,
471 gboolean client_find_onscreen(ObClient *self, int *x, int *y, int w, int h,
475 int ox = *x, oy = *y;
477 frame_client_gravity(self->frame, x, y); /* get where the frame
480 /* XXX watch for xinerama dead areas */
482 a = screen_area(self->desktop);
483 if (*x >= a->x + a->width - 1)
484 *x = a->x + a->width - self->frame->area.width;
485 if (*y >= a->y + a->height - 1)
486 *y = a->y + a->height - self->frame->area.height;
487 if (*x + self->frame->area.width - 1 < a->x)
489 if (*y + self->frame->area.height - 1 < a->y)
493 /* this is my MOZILLA BITCHSLAP. oh ya it fucking feels good.
494 Java can suck it too. */
496 /* dont let windows map/move into the strut unless they
497 are bigger than the available area */
499 if (*x < a->x) *x = a->x;
500 if (*x + w > a->x + a->width)
501 *x = a->x + a->width - w;
503 if (h <= a->height) {
504 if (*y < a->y) *y = a->y;
505 if (*y + h > a->y + a->height)
506 *y = a->y + a->height - h;
510 frame_frame_gravity(self->frame, x, y); /* get where the client
513 return ox != *x || oy != *y;
516 static void client_toggle_border(ObClient *self, gboolean show)
518 /* adjust our idea of where the client is, based on its border. When the
519 border is removed, the client should now be considered to be in a
521 when re-adding the border to the client, the same operation needs to be
523 int oldx = self->area.x, oldy = self->area.y;
524 int x = oldx, y = oldy;
525 switch(self->gravity) {
527 case NorthWestGravity:
529 case SouthWestGravity:
531 case NorthEastGravity:
533 case SouthEastGravity:
534 if (show) x -= self->border_width * 2;
535 else x += self->border_width * 2;
542 if (show) x -= self->border_width;
543 else x += self->border_width;
546 switch(self->gravity) {
548 case NorthWestGravity:
550 case NorthEastGravity:
552 case SouthWestGravity:
554 case SouthEastGravity:
555 if (show) y -= self->border_width * 2;
556 else y += self->border_width * 2;
563 if (show) y -= self->border_width;
564 else y += self->border_width;
571 XSetWindowBorderWidth(ob_display, self->window, self->border_width);
573 /* move the client so it is back it the right spot _with_ its
575 if (x != oldx || y != oldy)
576 XMoveWindow(ob_display, self->window, x, y);
578 XSetWindowBorderWidth(ob_display, self->window, 0);
582 static void client_get_all(ObClient *self)
584 /* update EVERYTHING!! */
586 self->ignore_unmaps = 0;
590 self->title = self->icon_title = NULL;
591 self->title_count = 1;
592 self->name = self->class = self->role = NULL;
593 self->wmstate = NormalState;
594 self->transient = FALSE;
595 self->transients = NULL;
596 self->transient_for = NULL;
598 self->urgent = FALSE;
599 self->positioned = FALSE;
600 self->decorate = TRUE;
604 client_get_area(self);
605 client_update_transient_for(self);
606 client_update_wmhints(self);
607 client_get_desktop(self);
608 client_get_state(self);
609 client_get_shaped(self);
611 client_get_mwm_hints(self);
612 client_get_type(self);/* this can change the mwmhints for special cases */
614 client_update_protocols(self);
616 client_get_gravity(self); /* get the attribute gravity */
617 client_update_normal_hints(self); /* this may override the attribute
620 /* got the type, the mwmhints, the protocols, and the normal hints
621 (min/max sizes), so we're ready to set up the decorations/functions */
622 client_setup_decor_and_functions(self);
624 client_update_title(self);
625 client_update_class(self);
626 client_update_strut(self);
627 client_update_icons(self);
629 client_change_state(self);
632 static void client_get_area(ObClient *self)
634 XWindowAttributes wattrib;
637 ret = XGetWindowAttributes(ob_display, self->window, &wattrib);
638 g_assert(ret != BadWindow);
640 RECT_SET(self->area, wattrib.x, wattrib.y, wattrib.width, wattrib.height);
641 self->border_width = wattrib.border_width;
644 static void client_get_desktop(ObClient *self)
646 guint32 d = screen_num_desktops; /* an always-invalid value */
648 if (PROP_GET32(self->window, net_wm_desktop, cardinal, &d)) {
649 if (d >= screen_num_desktops && d != DESKTOP_ALL)
650 self->desktop = screen_num_desktops - 1;
654 gboolean trdesk = FALSE;
656 if (self->transient_for) {
657 if (self->transient_for != OB_TRAN_GROUP) {
658 self->desktop = self->transient_for->desktop;
663 for (it = self->group->members; it; it = it->next)
664 if (it->data != self &&
665 !((ObClient*)it->data)->transient_for) {
666 self->desktop = ((ObClient*)it->data)->desktop;
673 /* defaults to the current desktop */
674 self->desktop = screen_desktop;
677 if (self->desktop != d) {
678 /* set the desktop hint, to make sure that it always exists */
679 PROP_SET32(self->window, net_wm_desktop, cardinal, self->desktop);
683 static void client_get_state(ObClient *self)
688 self->modal = self->shaded = self->max_horz = self->max_vert =
689 self->fullscreen = self->above = self->below = self->iconic =
690 self->skip_taskbar = self->skip_pager = FALSE;
692 if (PROP_GETA32(self->window, net_wm_state, atom, &state, &num)) {
694 for (i = 0; i < num; ++i) {
695 if (state[i] == prop_atoms.net_wm_state_modal)
697 else if (state[i] == prop_atoms.net_wm_state_shaded)
699 else if (state[i] == prop_atoms.net_wm_state_hidden)
701 else if (state[i] == prop_atoms.net_wm_state_skip_taskbar)
702 self->skip_taskbar = TRUE;
703 else if (state[i] == prop_atoms.net_wm_state_skip_pager)
704 self->skip_pager = TRUE;
705 else if (state[i] == prop_atoms.net_wm_state_fullscreen)
706 self->fullscreen = TRUE;
707 else if (state[i] == prop_atoms.net_wm_state_maximized_vert)
708 self->max_vert = TRUE;
709 else if (state[i] == prop_atoms.net_wm_state_maximized_horz)
710 self->max_horz = TRUE;
711 else if (state[i] == prop_atoms.net_wm_state_above)
713 else if (state[i] == prop_atoms.net_wm_state_below)
721 static void client_get_shaped(ObClient *self)
723 self->shaped = FALSE;
725 if (extensions_shape) {
730 XShapeSelectInput(ob_display, self->window, ShapeNotifyMask);
732 XShapeQueryExtents(ob_display, self->window, &s, &foo,
733 &foo, &ufoo, &ufoo, &foo, &foo, &foo, &ufoo,
735 self->shaped = (s != 0);
740 void client_update_transient_for(ObClient *self)
743 ObClient *target = NULL;
745 if (XGetTransientForHint(ob_display, self->window, &t)) {
746 self->transient = TRUE;
747 if (t != self->window) { /* cant be transient to itself! */
748 target = g_hash_table_lookup(window_map, &t);
749 /* if this happens then we need to check for it*/
750 g_assert(target != self);
751 g_assert(!target || WINDOW_IS_CLIENT(target));
753 if (!target && self->group) {
754 /* not transient to a client, see if it is transient for a
756 if (t == self->group->leader ||
758 t == RootWindow(ob_display, ob_screen)) {
759 /* window is a transient for its group! */
760 target = OB_TRAN_GROUP;
765 self->transient = FALSE;
767 /* if anything has changed... */
768 if (target != self->transient_for) {
769 if (self->transient_for == OB_TRAN_GROUP) { /* transient of group */
772 /* remove from old parents */
773 for (it = self->group->members; it; it = g_slist_next(it)) {
774 ObClient *c = it->data;
775 if (c != self && !c->transient_for)
776 c->transients = g_slist_remove(c->transients, self);
778 } else if (self->transient_for != NULL) { /* transient of window */
779 /* remove from old parent */
780 self->transient_for->transients =
781 g_slist_remove(self->transient_for->transients, self);
783 self->transient_for = target;
784 if (self->transient_for == OB_TRAN_GROUP) { /* transient of group */
787 /* add to new parents */
788 for (it = self->group->members; it; it = g_slist_next(it)) {
789 ObClient *c = it->data;
790 if (c != self && !c->transient_for)
791 c->transients = g_slist_append(c->transients, self);
794 /* remove all transients which are in the group, that causes
795 circlular pointer hell of doom */
796 for (it = self->group->members; it; it = g_slist_next(it)) {
798 for (sit = self->transients; sit; sit = next) {
799 next = g_slist_next(sit);
800 if (sit->data == it->data)
802 g_slist_delete_link(self->transients, sit);
805 } else if (self->transient_for != NULL) { /* transient of window */
806 /* add to new parent */
807 self->transient_for->transients =
808 g_slist_append(self->transient_for->transients, self);
813 static void client_get_mwm_hints(ObClient *self)
818 self->mwmhints.flags = 0; /* default to none */
820 if (PROP_GETA32(self->window, motif_wm_hints, motif_wm_hints,
822 if (num >= OB_MWM_ELEMENTS) {
823 self->mwmhints.flags = hints[0];
824 self->mwmhints.functions = hints[1];
825 self->mwmhints.decorations = hints[2];
831 void client_get_type(ObClient *self)
838 if (PROP_GETA32(self->window, net_wm_window_type, atom, &val, &num)) {
839 /* use the first value that we know about in the array */
840 for (i = 0; i < num; ++i) {
841 if (val[i] == prop_atoms.net_wm_window_type_desktop)
842 self->type = OB_CLIENT_TYPE_DESKTOP;
843 else if (val[i] == prop_atoms.net_wm_window_type_dock)
844 self->type = OB_CLIENT_TYPE_DOCK;
845 else if (val[i] == prop_atoms.net_wm_window_type_toolbar)
846 self->type = OB_CLIENT_TYPE_TOOLBAR;
847 else if (val[i] == prop_atoms.net_wm_window_type_menu)
848 self->type = OB_CLIENT_TYPE_MENU;
849 else if (val[i] == prop_atoms.net_wm_window_type_utility)
850 self->type = OB_CLIENT_TYPE_UTILITY;
851 else if (val[i] == prop_atoms.net_wm_window_type_splash)
852 self->type = OB_CLIENT_TYPE_SPLASH;
853 else if (val[i] == prop_atoms.net_wm_window_type_dialog)
854 self->type = OB_CLIENT_TYPE_DIALOG;
855 else if (val[i] == prop_atoms.net_wm_window_type_normal)
856 self->type = OB_CLIENT_TYPE_NORMAL;
857 else if (val[i] == prop_atoms.kde_net_wm_window_type_override) {
858 /* prevent this window from getting any decor or
860 self->mwmhints.flags &= (OB_MWM_FLAG_FUNCTIONS |
861 OB_MWM_FLAG_DECORATIONS);
862 self->mwmhints.decorations = 0;
863 self->mwmhints.functions = 0;
865 if (self->type != (ObClientType) -1)
866 break; /* grab the first legit type */
871 if (self->type == (ObClientType) -1) {
872 /*the window type hint was not set, which means we either classify
873 ourself as a normal window or a dialog, depending on if we are a
876 self->type = OB_CLIENT_TYPE_DIALOG;
878 self->type = OB_CLIENT_TYPE_NORMAL;
882 void client_update_protocols(ObClient *self)
887 self->focus_notify = FALSE;
888 self->delete_window = FALSE;
890 if (PROP_GETA32(self->window, wm_protocols, atom, &proto, &num_return)) {
891 for (i = 0; i < num_return; ++i) {
892 if (proto[i] == prop_atoms.wm_delete_window) {
893 /* this means we can request the window to close */
894 self->delete_window = TRUE;
895 } else if (proto[i] == prop_atoms.wm_take_focus)
896 /* if this protocol is requested, then the window will be
897 notified whenever we want it to receive focus */
898 self->focus_notify = TRUE;
904 static void client_get_gravity(ObClient *self)
906 XWindowAttributes wattrib;
909 ret = XGetWindowAttributes(ob_display, self->window, &wattrib);
910 g_assert(ret != BadWindow);
911 self->gravity = wattrib.win_gravity;
914 void client_update_normal_hints(ObClient *self)
918 int oldgravity = self->gravity;
921 self->min_ratio = 0.0f;
922 self->max_ratio = 0.0f;
923 SIZE_SET(self->size_inc, 1, 1);
924 SIZE_SET(self->base_size, 0, 0);
925 SIZE_SET(self->min_size, 0, 0);
926 SIZE_SET(self->max_size, G_MAXINT, G_MAXINT);
928 /* get the hints from the window */
929 if (XGetWMNormalHints(ob_display, self->window, &size, &ret)) {
930 self->positioned = !!(size.flags & (PPosition|USPosition));
932 if (size.flags & PWinGravity) {
933 self->gravity = size.win_gravity;
935 /* if the client has a frame, i.e. has already been mapped and
936 is changing its gravity */
937 if (self->frame && self->gravity != oldgravity) {
938 /* move our idea of the client's position based on its new
940 self->area.x = self->frame->area.x;
941 self->area.y = self->frame->area.y;
942 frame_frame_gravity(self->frame, &self->area.x, &self->area.y);
946 if (size.flags & PAspect) {
947 if (size.min_aspect.y)
948 self->min_ratio = (float)size.min_aspect.x / size.min_aspect.y;
949 if (size.max_aspect.y)
950 self->max_ratio = (float)size.max_aspect.x / size.max_aspect.y;
953 if (size.flags & PMinSize)
954 SIZE_SET(self->min_size, size.min_width, size.min_height);
956 if (size.flags & PMaxSize)
957 SIZE_SET(self->max_size, size.max_width, size.max_height);
959 if (size.flags & PBaseSize)
960 SIZE_SET(self->base_size, size.base_width, size.base_height);
962 if (size.flags & PResizeInc)
963 SIZE_SET(self->size_inc, size.width_inc, size.height_inc);
967 void client_setup_decor_and_functions(ObClient *self)
969 /* start with everything (cept fullscreen) */
970 self->decorations = (OB_FRAME_DECOR_TITLEBAR |
971 OB_FRAME_DECOR_HANDLE |
972 OB_FRAME_DECOR_GRIPS |
973 OB_FRAME_DECOR_BORDER |
974 OB_FRAME_DECOR_ICON |
975 OB_FRAME_DECOR_ALLDESKTOPS |
976 OB_FRAME_DECOR_ICONIFY |
977 OB_FRAME_DECOR_MAXIMIZE |
978 OB_FRAME_DECOR_SHADE);
979 self->functions = (OB_CLIENT_FUNC_RESIZE |
980 OB_CLIENT_FUNC_MOVE |
981 OB_CLIENT_FUNC_ICONIFY |
982 OB_CLIENT_FUNC_MAXIMIZE |
983 OB_CLIENT_FUNC_SHADE);
984 if (self->delete_window) {
985 self->functions |= OB_CLIENT_FUNC_CLOSE;
986 self->decorations |= OB_FRAME_DECOR_CLOSE;
989 if (!(self->min_size.width < self->max_size.width ||
990 self->min_size.height < self->max_size.height))
991 self->functions &= ~OB_CLIENT_FUNC_RESIZE;
993 switch (self->type) {
994 case OB_CLIENT_TYPE_NORMAL:
995 /* normal windows retain all of the possible decorations and
996 functionality, and are the only windows that you can fullscreen */
997 self->functions |= OB_CLIENT_FUNC_FULLSCREEN;
1000 case OB_CLIENT_TYPE_DIALOG:
1001 case OB_CLIENT_TYPE_UTILITY:
1002 /* these windows cannot be maximized */
1003 self->functions &= ~OB_CLIENT_FUNC_MAXIMIZE;
1006 case OB_CLIENT_TYPE_MENU:
1007 case OB_CLIENT_TYPE_TOOLBAR:
1008 /* these windows get less functionality */
1009 self->functions &= ~(OB_CLIENT_FUNC_ICONIFY | OB_CLIENT_FUNC_RESIZE);
1012 case OB_CLIENT_TYPE_DESKTOP:
1013 case OB_CLIENT_TYPE_DOCK:
1014 case OB_CLIENT_TYPE_SPLASH:
1015 /* none of these windows are manipulated by the window manager */
1016 self->decorations = 0;
1017 self->functions = 0;
1021 /* Mwm Hints are applied subtractively to what has already been chosen for
1022 decor and functionality */
1023 if (self->mwmhints.flags & OB_MWM_FLAG_DECORATIONS) {
1024 if (! (self->mwmhints.decorations & OB_MWM_DECOR_ALL)) {
1025 if (! ((self->mwmhints.decorations & OB_MWM_DECOR_HANDLE) ||
1026 (self->mwmhints.decorations & OB_MWM_DECOR_TITLE)))
1027 /* if the mwm hints request no handle or title, then all
1028 decorations are disabled */
1029 self->decorations = 0;
1033 if (self->mwmhints.flags & OB_MWM_FLAG_FUNCTIONS) {
1034 if (! (self->mwmhints.functions & OB_MWM_FUNC_ALL)) {
1035 if (! (self->mwmhints.functions & OB_MWM_FUNC_RESIZE))
1036 self->functions &= ~OB_CLIENT_FUNC_RESIZE;
1037 if (! (self->mwmhints.functions & OB_MWM_FUNC_MOVE))
1038 self->functions &= ~OB_CLIENT_FUNC_MOVE;
1039 /* dont let mwm hints kill any buttons
1040 if (! (self->mwmhints.functions & OB_MWM_FUNC_ICONIFY))
1041 self->functions &= ~OB_CLIENT_FUNC_ICONIFY;
1042 if (! (self->mwmhints.functions & OB_MWM_FUNC_MAXIMIZE))
1043 self->functions &= ~OB_CLIENT_FUNC_MAXIMIZE;
1045 /* dont let mwm hints kill the close button
1046 if (! (self->mwmhints.functions & MwmFunc_Close))
1047 self->functions &= ~OB_CLIENT_FUNC_CLOSE; */
1051 if (!(self->functions & OB_CLIENT_FUNC_SHADE))
1052 self->decorations &= ~OB_FRAME_DECOR_SHADE;
1053 if (!(self->functions & OB_CLIENT_FUNC_ICONIFY))
1054 self->decorations &= ~OB_FRAME_DECOR_ICONIFY;
1055 if (!(self->functions & OB_CLIENT_FUNC_RESIZE))
1056 self->decorations &= ~OB_FRAME_DECOR_GRIPS;
1058 /* can't maximize without moving/resizing */
1059 if (!((self->functions & OB_CLIENT_FUNC_MAXIMIZE) &&
1060 (self->functions & OB_CLIENT_FUNC_MOVE) &&
1061 (self->functions & OB_CLIENT_FUNC_RESIZE))) {
1062 self->functions &= ~OB_CLIENT_FUNC_MAXIMIZE;
1063 self->decorations &= ~OB_FRAME_DECOR_MAXIMIZE;
1066 /* finally, the user can have requested no decorations, which overrides
1068 if (!self->decorate)
1069 self->decorations = 0;
1071 /* if we don't have a titlebar, then we cannot shade! */
1072 if (!(self->decorations & OB_FRAME_DECOR_TITLEBAR))
1073 self->functions &= ~OB_CLIENT_FUNC_SHADE;
1075 /* now we need to check against rules for the client's current state */
1076 if (self->fullscreen) {
1077 self->functions &= (OB_CLIENT_FUNC_CLOSE |
1078 OB_CLIENT_FUNC_FULLSCREEN |
1079 OB_CLIENT_FUNC_ICONIFY);
1080 self->decorations = 0;
1083 client_change_allowed_actions(self);
1086 /* this makes sure that these windows appear on all desktops */
1087 if (self->type == OB_CLIENT_TYPE_DESKTOP &&
1088 self->desktop != DESKTOP_ALL)
1089 client_set_desktop(self, DESKTOP_ALL, FALSE);
1091 /* adjust the client's decorations, etc. */
1092 client_reconfigure(self);
1094 /* this makes sure that these windows appear on all desktops */
1095 if (self->type == OB_CLIENT_TYPE_DESKTOP &&
1096 self->desktop != DESKTOP_ALL)
1098 self->desktop = DESKTOP_ALL;
1103 static void client_change_allowed_actions(ObClient *self)
1108 /* desktop windows are kept on all desktops */
1109 if (self->type != OB_CLIENT_TYPE_DESKTOP)
1110 actions[num++] = prop_atoms.net_wm_action_change_desktop;
1112 if (self->functions & OB_CLIENT_FUNC_SHADE)
1113 actions[num++] = prop_atoms.net_wm_action_shade;
1114 if (self->functions & OB_CLIENT_FUNC_CLOSE)
1115 actions[num++] = prop_atoms.net_wm_action_close;
1116 if (self->functions & OB_CLIENT_FUNC_MOVE)
1117 actions[num++] = prop_atoms.net_wm_action_move;
1118 if (self->functions & OB_CLIENT_FUNC_ICONIFY)
1119 actions[num++] = prop_atoms.net_wm_action_minimize;
1120 if (self->functions & OB_CLIENT_FUNC_RESIZE)
1121 actions[num++] = prop_atoms.net_wm_action_resize;
1122 if (self->functions & OB_CLIENT_FUNC_FULLSCREEN)
1123 actions[num++] = prop_atoms.net_wm_action_fullscreen;
1124 if (self->functions & OB_CLIENT_FUNC_MAXIMIZE) {
1125 actions[num++] = prop_atoms.net_wm_action_maximize_horz;
1126 actions[num++] = prop_atoms.net_wm_action_maximize_vert;
1129 PROP_SETA32(self->window, net_wm_allowed_actions, atom, actions, num);
1131 /* make sure the window isn't breaking any rules now */
1133 if (!(self->functions & OB_CLIENT_FUNC_SHADE) && self->shaded) {
1134 if (self->frame) client_shade(self, FALSE);
1135 else self->shaded = FALSE;
1137 if (!(self->functions & OB_CLIENT_FUNC_ICONIFY) && self->iconic) {
1138 if (self->frame) client_iconify(self, FALSE, TRUE);
1139 else self->iconic = FALSE;
1141 if (!(self->functions & OB_CLIENT_FUNC_FULLSCREEN) && self->fullscreen) {
1142 if (self->frame) client_fullscreen(self, FALSE, TRUE);
1143 else self->fullscreen = FALSE;
1145 if (!(self->functions & OB_CLIENT_FUNC_MAXIMIZE) && (self->max_horz ||
1147 if (self->frame) client_maximize(self, FALSE, 0, TRUE);
1148 else self->max_vert = self->max_horz = FALSE;
1152 void client_reconfigure(ObClient *self)
1154 /* by making this pass FALSE for user, we avoid the emacs event storm where
1155 every configurenotify causes an update in its normal hints, i think this
1156 is generally what we want anyways... */
1157 client_configure(self, OB_CORNER_TOPLEFT, self->area.x, self->area.y,
1158 self->area.width, self->area.height, FALSE, TRUE);
1161 void client_update_wmhints(ObClient *self)
1164 gboolean ur = FALSE;
1167 /* assume a window takes input if it doesnt specify */
1168 self->can_focus = TRUE;
1170 if ((hints = XGetWMHints(ob_display, self->window)) != NULL) {
1171 if (hints->flags & InputHint)
1172 self->can_focus = hints->input;
1174 /* only do this when first managing the window *AND* when we aren't
1176 if (ob_state() != OB_STATE_STARTING && self->frame == NULL)
1177 if (hints->flags & StateHint)
1178 self->iconic = hints->initial_state == IconicState;
1180 if (hints->flags & XUrgencyHint)
1183 if (!(hints->flags & WindowGroupHint))
1184 hints->window_group = None;
1186 /* did the group state change? */
1187 if (hints->window_group !=
1188 (self->group ? self->group->leader : None)) {
1189 /* remove from the old group if there was one */
1190 if (self->group != NULL) {
1191 /* remove transients of the group */
1192 for (it = self->group->members; it; it = it->next)
1193 self->transients = g_slist_remove(self->transients,
1195 group_remove(self->group, self);
1198 if (hints->window_group != None) {
1199 self->group = group_add(hints->window_group, self);
1201 /* i can only have transients from the group if i am not
1203 if (!self->transient_for) {
1204 /* add other transients of the group that are already
1206 for (it = self->group->members; it; it = it->next) {
1207 ObClient *c = it->data;
1208 if (c != self && c->transient_for == OB_TRAN_GROUP)
1210 g_slist_append(self->transients, c);
1215 /* the WM_HINTS can contain an icon */
1216 client_update_icons(self);
1218 /* because the self->transient flag wont change from this call,
1219 we don't need to update the window's type and such, only its
1220 transient_for, and the transients lists of other windows in
1221 the group may be affected */
1222 client_update_transient_for(self);
1228 if (ur != self->urgent) {
1230 ob_debug("Urgent Hint for 0x%lx: %s\n", self->window,
1232 /* fire the urgent callback if we're mapped, otherwise, wait until
1233 after we're mapped */
1235 dispatch_client(Event_Client_Urgent, self, self->urgent, 0);
1239 void client_update_title(ObClient *self)
1245 gboolean read_title;
1247 g_free(self->title);
1250 if (!PROP_GETS(self->window, net_wm_name, utf8, &data))
1251 /* try old x stuff */
1252 if (!PROP_GETS(self->window, wm_name, locale, &data))
1253 data = g_strdup("Unnamed Window");
1255 /* look for duplicates and append a number */
1257 for (it = client_list; it; it = it->next)
1258 if (it->data != self) {
1259 ObClient *c = it->data;
1260 if (0 == strncmp(c->title, data, strlen(data)))
1261 nums |= 1 << c->title_count;
1263 /* find first free number */
1264 for (i = 1; i <= 32; ++i)
1265 if (!(nums & (1 << i))) {
1266 if (self->title_count == 1 || i == 1)
1267 self->title_count = i;
1270 /* dont display the number for the first window */
1271 if (self->title_count > 1) {
1272 char *vdata, *ndata;
1273 ndata = g_strdup_printf(" - [%u]", self->title_count);
1274 vdata = g_strconcat(data, ndata, NULL);
1280 PROP_SETS(self->window, net_wm_visible_name, data);
1285 frame_adjust_title(self->frame);
1287 /* update the icon title */
1289 g_free(self->icon_title);
1293 if (!PROP_GETS(self->window, net_wm_icon_name, utf8, &data))
1294 /* try old x stuff */
1295 if (!PROP_GETS(self->window, wm_icon_name, locale, &data)) {
1296 data = g_strdup(self->title);
1300 /* append the title count, dont display the number for the first window */
1301 if (read_title && self->title_count > 1) {
1302 char *vdata, *ndata;
1303 ndata = g_strdup_printf(" - [%u]", self->title_count);
1304 vdata = g_strconcat(data, ndata, NULL);
1310 PROP_SETS(self->window, net_wm_visible_icon_name, data);
1312 self->icon_title = data;
1315 void client_update_class(ObClient *self)
1320 if (self->name) g_free(self->name);
1321 if (self->class) g_free(self->class);
1322 if (self->role) g_free(self->role);
1324 self->name = self->class = self->role = NULL;
1326 if (PROP_GETSS(self->window, wm_class, locale, &data)) {
1328 self->name = g_strdup(data[0]);
1330 self->class = g_strdup(data[1]);
1335 if (PROP_GETS(self->window, wm_window_role, locale, &s))
1336 self->role = g_strdup(s);
1338 if (self->name == NULL) self->name = g_strdup("");
1339 if (self->class == NULL) self->class = g_strdup("");
1340 if (self->role == NULL) self->role = g_strdup("");
1343 void client_update_strut(ObClient *self)
1348 if (!PROP_GETA32(self->window, net_wm_strut, cardinal, &data, &num)) {
1349 STRUT_SET(self->strut, 0, 0, 0, 0);
1352 g_message("new strut: %d %d %d %d",
1353 data[0], data[2], data[1], data[3]);
1354 STRUT_SET(self->strut, data[0], data[2], data[1], data[3]);
1357 STRUT_SET(self->strut, 0, 0, 0, 0);
1361 /* updating here is pointless while we're being mapped cuz we're not in
1362 the client list yet */
1364 screen_update_areas();
1367 void client_update_icons(ObClient *self)
1373 for (i = 0; i < self->nicons; ++i)
1374 g_free(self->icons[i].data);
1375 if (self->nicons > 0)
1376 g_free(self->icons);
1379 if (PROP_GETA32(self->window, net_wm_icon, cardinal, &data, &num)) {
1380 /* figure out how many valid icons are in here */
1382 while (num - i > 2) {
1386 if (i > num || w*h == 0) break;
1390 self->icons = g_new(ObClientIcon, self->nicons);
1392 /* store the icons */
1394 for (j = 0; j < self->nicons; ++j) {
1397 w = self->icons[j].width = data[i++];
1398 h = self->icons[j].height = data[i++];
1400 if (w*h == 0) continue;
1402 self->icons[j].data = g_new(RrPixel32, w * h);
1403 for (x = 0, y = 0, t = 0; t < w * h; ++t, ++x, ++i) {
1408 self->icons[j].data[t] =
1409 (((data[i] >> 24) & 0xff) << RrDefaultAlphaOffset) +
1410 (((data[i] >> 16) & 0xff) << RrDefaultRedOffset) +
1411 (((data[i] >> 8) & 0xff) << RrDefaultGreenOffset) +
1412 (((data[i] >> 0) & 0xff) << RrDefaultBlueOffset);
1418 } else if (PROP_GETA32(self->window, kwm_win_icon,
1419 kwm_win_icon, &data, &num)) {
1422 self->icons = g_new(ObClientIcon, self->nicons);
1423 xerror_set_ignore(TRUE);
1424 if (!RrPixmapToRGBA(ob_rr_inst,
1426 &self->icons[self->nicons-1].width,
1427 &self->icons[self->nicons-1].height,
1428 &self->icons[self->nicons-1].data)) {
1429 g_free(&self->icons[self->nicons-1]);
1432 xerror_set_ignore(FALSE);
1438 if ((hints = XGetWMHints(ob_display, self->window))) {
1439 if (hints->flags & IconPixmapHint) {
1441 self->icons = g_new(ObClientIcon, self->nicons);
1442 xerror_set_ignore(TRUE);
1443 if (!RrPixmapToRGBA(ob_rr_inst,
1445 (hints->flags & IconMaskHint ?
1446 hints->icon_mask : None),
1447 &self->icons[self->nicons-1].width,
1448 &self->icons[self->nicons-1].height,
1449 &self->icons[self->nicons-1].data)){
1450 g_free(&self->icons[self->nicons-1]);
1453 xerror_set_ignore(FALSE);
1460 frame_adjust_icon(self->frame);
1463 static void client_change_state(ObClient *self)
1466 guint32 netstate[10];
1469 state[0] = self->wmstate;
1471 PROP_SETA32(self->window, wm_state, wm_state, state, 2);
1475 netstate[num++] = prop_atoms.net_wm_state_modal;
1477 netstate[num++] = prop_atoms.net_wm_state_shaded;
1479 netstate[num++] = prop_atoms.net_wm_state_hidden;
1480 if (self->skip_taskbar)
1481 netstate[num++] = prop_atoms.net_wm_state_skip_taskbar;
1482 if (self->skip_pager)
1483 netstate[num++] = prop_atoms.net_wm_state_skip_pager;
1484 if (self->fullscreen)
1485 netstate[num++] = prop_atoms.net_wm_state_fullscreen;
1487 netstate[num++] = prop_atoms.net_wm_state_maximized_vert;
1489 netstate[num++] = prop_atoms.net_wm_state_maximized_horz;
1491 netstate[num++] = prop_atoms.net_wm_state_above;
1493 netstate[num++] = prop_atoms.net_wm_state_below;
1494 PROP_SETA32(self->window, net_wm_state, atom, netstate, num);
1496 client_calc_layer(self);
1499 frame_adjust_state(self->frame);
1502 ObClient *client_search_focus_tree(ObClient *self)
1507 for (it = self->transients; it != NULL; it = it->next) {
1508 if (client_focused(it->data)) return it->data;
1509 if ((ret = client_search_focus_tree(it->data))) return ret;
1514 ObClient *client_search_focus_tree_full(ObClient *self)
1516 if (self->transient_for) {
1517 if (self->transient_for != OB_TRAN_GROUP) {
1518 return client_search_focus_tree_full(self->transient_for);
1521 gboolean recursed = FALSE;
1523 for (it = self->group->members; it; it = it->next)
1524 if (!((ObClient*)it->data)->transient_for) {
1526 if ((c = client_search_focus_tree_full(it->data)))
1535 /* this function checks the whole tree, the client_search_focus_tree~
1536 does not, so we need to check this window */
1537 if (client_focused(self))
1539 return client_search_focus_tree(self);
1542 static ObStackingLayer calc_layer(ObClient *self)
1546 if (self->fullscreen) l = OB_STACKING_LAYER_FULLSCREEN;
1547 else if (self->type == OB_CLIENT_TYPE_DESKTOP)
1548 l = OB_STACKING_LAYER_DESKTOP;
1549 else if (self->type == OB_CLIENT_TYPE_DOCK) {
1550 if (!self->below) l = OB_STACKING_LAYER_TOP;
1551 else l = OB_STACKING_LAYER_NORMAL;
1553 else if (self->above) l = OB_STACKING_LAYER_ABOVE;
1554 else if (self->below) l = OB_STACKING_LAYER_BELOW;
1555 else l = OB_STACKING_LAYER_NORMAL;
1560 static void client_calc_layer_recursive(ObClient *self, ObClient *orig,
1561 ObStackingLayer l, gboolean raised)
1563 ObStackingLayer old, own;
1567 own = calc_layer(self);
1568 self->layer = l > own ? l : own;
1570 for (it = self->transients; it; it = it->next)
1571 client_calc_layer_recursive(it->data, orig,
1572 l, raised ? raised : l != old);
1574 if (!raised && l != old)
1575 if (orig->frame) { /* only restack if the original window is managed */
1576 /* XXX add_non_intrusive ever? */
1577 stacking_remove(CLIENT_AS_WINDOW(self));
1578 stacking_add(CLIENT_AS_WINDOW(self));
1582 void client_calc_layer(ObClient *self)
1589 /* transients take on the layer of their parents */
1590 self = client_search_top_transient(self);
1592 l = calc_layer(self);
1594 client_calc_layer_recursive(self, orig, l, FALSE);
1597 gboolean client_should_show(ObClient *self)
1599 if (self->iconic) return FALSE;
1600 else if (!(self->desktop == screen_desktop ||
1601 self->desktop == DESKTOP_ALL)) return FALSE;
1602 else if (client_normal(self) && screen_showing_desktop) return FALSE;
1607 static void client_showhide(ObClient *self)
1610 if (client_should_show(self))
1611 frame_show(self->frame);
1613 frame_hide(self->frame);
1616 gboolean client_normal(ObClient *self) {
1617 return ! (self->type == OB_CLIENT_TYPE_DESKTOP ||
1618 self->type == OB_CLIENT_TYPE_DOCK ||
1619 self->type == OB_CLIENT_TYPE_SPLASH);
1622 static void client_apply_startup_state(ObClient *self)
1624 /* these are in a carefully crafted order.. */
1627 self->iconic = FALSE;
1628 client_iconify(self, TRUE, FALSE);
1630 if (self->fullscreen) {
1631 self->fullscreen = FALSE;
1632 client_fullscreen(self, TRUE, FALSE);
1635 self->shaded = FALSE;
1636 client_shade(self, TRUE);
1639 dispatch_client(Event_Client_Urgent, self, self->urgent, 0);
1641 if (self->max_vert && self->max_horz) {
1642 self->max_vert = self->max_horz = FALSE;
1643 client_maximize(self, TRUE, 0, FALSE);
1644 } else if (self->max_vert) {
1645 self->max_vert = FALSE;
1646 client_maximize(self, TRUE, 2, FALSE);
1647 } else if (self->max_horz) {
1648 self->max_horz = FALSE;
1649 client_maximize(self, TRUE, 1, FALSE);
1652 /* nothing to do for the other states:
1661 void client_configure(ObClient *self, ObCorner anchor,
1662 int x, int y, int w, int h,
1663 gboolean user, gboolean final)
1665 gboolean moved = FALSE, resized = FALSE;
1667 /* gets the frame's position */
1668 frame_client_gravity(self->frame, &x, &y);
1670 /* these positions are frame positions, not client positions */
1672 /* set the size and position if fullscreen */
1673 if (self->fullscreen) {
1676 XF86VidModeModeLine mode;
1681 i = client_monitor(self);
1682 a = screen_physical_area_monitor(i);
1685 if (i == 0 && /* primary head */
1686 extensions_vidmode &&
1687 XF86VidModeGetViewPort(ob_display, ob_screen, &x, &y) &&
1688 /* get the mode last so the mode.privsize isnt freed incorrectly */
1689 XF86VidModeGetModeLine(ob_display, ob_screen, &dot, &mode)) {
1694 if (mode.privsize) XFree(mode.private);
1704 user = FALSE; /* ignore that increment etc shit when in fullscreen */
1708 a = screen_area_monitor(self->desktop, client_monitor(self));
1710 /* set the size and position if maximized */
1711 if (self->max_horz) {
1712 x = a->x - self->frame->size.left;
1715 if (self->max_vert) {
1717 h = a->height - self->frame->size.top - self->frame->size.bottom;
1721 /* gets the client's position */
1722 frame_frame_gravity(self->frame, &x, &y);
1724 /* these override the above states! if you cant move you can't move! */
1726 if (!(self->functions & OB_CLIENT_FUNC_MOVE)) {
1730 if (!(self->functions & OB_CLIENT_FUNC_RESIZE)) {
1731 w = self->area.width;
1732 h = self->area.height;
1736 if (!(w == self->area.width && h == self->area.height)) {
1737 int basew, baseh, minw, minh;
1739 /* base size is substituted with min size if not specified */
1740 if (self->base_size.width || self->base_size.height) {
1741 basew = self->base_size.width;
1742 baseh = self->base_size.height;
1744 basew = self->min_size.width;
1745 baseh = self->min_size.height;
1747 /* min size is substituted with base size if not specified */
1748 if (self->min_size.width || self->min_size.height) {
1749 minw = self->min_size.width;
1750 minh = self->min_size.height;
1752 minw = self->base_size.width;
1753 minh = self->base_size.height;
1757 /* for interactive resizing. have to move half an increment in each
1760 /* how far we are towards the next size inc */
1761 int mw = (w - basew) % self->size_inc.width;
1762 int mh = (h - baseh) % self->size_inc.height;
1764 int aw = self->size_inc.width / 2;
1765 int ah = self->size_inc.height / 2;
1766 /* don't let us move into a new size increment */
1767 if (mw + aw >= self->size_inc.width)
1768 aw = self->size_inc.width - mw - 1;
1769 if (mh + ah >= self->size_inc.height)
1770 ah = self->size_inc.height - mh - 1;
1774 /* if this is a user-requested resize, then check against min/max
1777 /* smaller than min size or bigger than max size? */
1778 if (w > self->max_size.width) w = self->max_size.width;
1779 if (w < minw) w = minw;
1780 if (h > self->max_size.height) h = self->max_size.height;
1781 if (h < minh) h = minh;
1787 /* keep to the increments */
1788 w /= self->size_inc.width;
1789 h /= self->size_inc.height;
1791 /* you cannot resize to nothing */
1795 /* store the logical size */
1796 SIZE_SET(self->logical_size, w, h);
1798 w *= self->size_inc.width;
1799 h *= self->size_inc.height;
1805 /* adjust the height to match the width for the aspect ratios.
1806 for this, min size is not substituted for base size ever. */
1807 w -= self->base_size.width;
1808 h -= self->base_size.height;
1810 if (self->min_ratio)
1811 if (h * self->min_ratio > w) h = (int)(w / self->min_ratio);
1812 if (self->max_ratio)
1813 if (h * self->max_ratio < w) h = (int)(w / self->max_ratio);
1815 w += self->base_size.width;
1816 h += self->base_size.height;
1821 case OB_CORNER_TOPLEFT:
1823 case OB_CORNER_TOPRIGHT:
1824 x -= w - self->area.width;
1826 case OB_CORNER_BOTTOMLEFT:
1827 y -= h - self->area.height;
1829 case OB_CORNER_BOTTOMRIGHT:
1830 x -= w - self->area.width;
1831 y -= h - self->area.height;
1835 moved = x != self->area.x || y != self->area.y;
1836 resized = w != self->area.width || h != self->area.height;
1838 RECT_SET(self->area, x, y, w, h);
1840 /* for app-requested resizes, always resize if 'resized' is true.
1841 for user-requested ones, only resize if final is true, or when
1842 resizing in opaque mode */
1843 if ((!user && resized) ||
1844 (user && (final || (resized && config_opaque_resize))))
1845 XResizeWindow(ob_display, self->window, w, h);
1847 /* move/resize the frame to match the request */
1849 if (self->decorations != self->frame->decorations)
1850 moved = resized = TRUE;
1852 if (moved || resized)
1853 frame_adjust_area(self->frame, moved, resized);
1855 /* If you send this and the client hasn't changed you end up with buggy
1856 clients (emacs) freaking out, cuz they send back a configure every
1857 time they receive this event, which resends them this event... etc.
1859 if ((!user && moved) || (user && final)) {
1861 event.type = ConfigureNotify;
1862 event.xconfigure.display = ob_display;
1863 event.xconfigure.event = self->window;
1864 event.xconfigure.window = self->window;
1866 /* root window real coords */
1867 event.xconfigure.x = self->frame->area.x + self->frame->size.left;
1868 event.xconfigure.y = self->frame->area.y + self->frame->size.top;
1870 event.xconfigure.width = w;
1871 event.xconfigure.height = h;
1872 event.xconfigure.border_width = 0;
1873 event.xconfigure.above = self->frame->plate;
1874 event.xconfigure.override_redirect = FALSE;
1875 XSendEvent(event.xconfigure.display, event.xconfigure.window,
1876 FALSE, StructureNotifyMask, &event);
1881 void client_fullscreen(ObClient *self, gboolean fs, gboolean savearea)
1885 if (!(self->functions & OB_CLIENT_FUNC_FULLSCREEN) || /* can't */
1886 self->fullscreen == fs) return; /* already done */
1888 self->fullscreen = fs;
1889 client_change_state(self); /* change the state hints on the client,
1890 and adjust out layer/stacking */
1894 guint32 dimensions[4];
1895 dimensions[0] = self->area.x;
1896 dimensions[1] = self->area.y;
1897 dimensions[2] = self->area.width;
1898 dimensions[3] = self->area.height;
1900 PROP_SETA32(self->window, openbox_premax, cardinal,
1904 /* these are not actually used cuz client_configure will set them
1905 as appropriate when the window is fullscreened */
1912 /* pick some fallbacks... */
1913 a = screen_area_monitor(self->desktop, 0);
1914 x = a->x + a->width / 4;
1915 y = a->y + a->height / 4;
1919 if (PROP_GETA32(self->window, openbox_premax, cardinal,
1920 (guint32**)&dimensions, &num)) {
1931 client_setup_decor_and_functions(self);
1933 client_configure(self, OB_CORNER_TOPLEFT, x, y, w, h, TRUE, TRUE);
1935 /* try focus us when we go into fullscreen mode */
1939 static void client_iconify_recursive(ObClient *self,
1940 gboolean iconic, gboolean curdesk)
1943 gboolean changed = FALSE;
1946 if (self->iconic != iconic) {
1947 ob_debug("%sconifying window: 0x%lx\n", (iconic ? "I" : "Uni"),
1950 self->iconic = iconic;
1953 if (self->functions & OB_CLIENT_FUNC_ICONIFY) {
1954 self->wmstate = IconicState;
1955 self->ignore_unmaps++;
1956 /* we unmap the client itself so that we can get MapRequest
1957 events, and because the ICCCM tells us to! */
1958 XUnmapWindow(ob_display, self->window);
1960 /* update the focus lists.. iconic windows go to the bottom of
1961 the list, put the new iconic window at the 'top of the
1963 focus_order_to_top(self);
1969 client_set_desktop(self, screen_desktop, FALSE);
1970 self->wmstate = self->shaded ? IconicState : NormalState;
1971 XMapWindow(ob_display, self->window);
1973 /* this puts it after the current focused window */
1974 focus_order_remove(self);
1975 focus_order_add_new(self);
1977 /* this is here cuz with the VIDMODE extension, the viewport can
1978 change while a fullscreen window is iconic, and when it
1979 uniconifies, it would be nice if it did so to the new position
1981 client_reconfigure(self);
1988 client_change_state(self);
1989 client_showhide(self);
1990 screen_update_areas();
1992 dispatch_client(iconic ? Event_Client_Unmapped : Event_Client_Mapped,
1996 /* iconify all transients */
1997 for (it = self->transients; it != NULL; it = it->next)
1998 if (it->data != self) client_iconify_recursive(it->data,
2002 void client_iconify(ObClient *self, gboolean iconic, gboolean curdesk)
2004 /* move up the transient chain as far as possible first */
2005 self = client_search_top_transient(self);
2007 client_iconify_recursive(client_search_top_transient(self),
2011 void client_maximize(ObClient *self, gboolean max, int dir, gboolean savearea)
2015 g_assert(dir == 0 || dir == 1 || dir == 2);
2016 if (!(self->functions & OB_CLIENT_FUNC_MAXIMIZE)) return; /* can't */
2018 /* check if already done */
2020 if (dir == 0 && self->max_horz && self->max_vert) return;
2021 if (dir == 1 && self->max_horz) return;
2022 if (dir == 2 && self->max_vert) return;
2024 if (dir == 0 && !self->max_horz && !self->max_vert) return;
2025 if (dir == 1 && !self->max_horz) return;
2026 if (dir == 2 && !self->max_vert) return;
2029 /* work with the frame's coords */
2030 x = self->frame->area.x;
2031 y = self->frame->area.y;
2032 w = self->area.width;
2033 h = self->area.height;
2037 gint32 dimensions[4];
2046 /* get the property off the window and use it for the dimensions
2047 we are already maxed on */
2048 if (PROP_GETA32(self->window, openbox_premax, cardinal,
2049 (guint32**)&readdim, &num)) {
2051 if (self->max_horz) {
2052 dimensions[0] = readdim[0];
2053 dimensions[2] = readdim[2];
2055 if (self->max_vert) {
2056 dimensions[1] = readdim[1];
2057 dimensions[3] = readdim[3];
2063 PROP_SETA32(self->window, openbox_premax, cardinal,
2064 (guint32*)dimensions, 4);
2071 /* pick some fallbacks... */
2072 a = screen_area_monitor(self->desktop, 0);
2073 if (dir == 0 || dir == 1) { /* horz */
2074 x = a->x + a->width / 4;
2077 if (dir == 0 || dir == 2) { /* vert */
2078 y = a->y + a->height / 4;
2082 if (PROP_GETA32(self->window, openbox_premax, cardinal,
2083 (guint32**)&dimensions, &num)) {
2085 if (dir == 0 || dir == 1) { /* horz */
2089 if (dir == 0 || dir == 2) { /* vert */
2098 if (dir == 0 || dir == 1) /* horz */
2099 self->max_horz = max;
2100 if (dir == 0 || dir == 2) /* vert */
2101 self->max_vert = max;
2103 if (!self->max_horz && !self->max_vert)
2104 PROP_ERASE(self->window, openbox_premax);
2106 client_change_state(self); /* change the state hints on the client */
2108 /* figure out where the client should be going */
2109 frame_frame_gravity(self->frame, &x, &y);
2110 client_configure(self, OB_CORNER_TOPLEFT, x, y, w, h, TRUE, TRUE);
2113 void client_shade(ObClient *self, gboolean shade)
2115 if ((!(self->functions & OB_CLIENT_FUNC_SHADE) &&
2116 shade) || /* can't shade */
2117 self->shaded == shade) return; /* already done */
2119 /* when we're iconic, don't change the wmstate */
2121 self->wmstate = shade ? IconicState : NormalState;
2122 self->shaded = shade;
2123 client_change_state(self);
2124 /* resize the frame to just the titlebar */
2125 frame_adjust_area(self->frame, FALSE, FALSE);
2128 void client_close(ObClient *self)
2132 if (!(self->functions & OB_CLIENT_FUNC_CLOSE)) return;
2135 XXX: itd be cool to do timeouts and shit here for killing the client's
2137 like... if the window is around after 5 seconds, then the close button
2138 turns a nice red, and if this function is called again, the client is
2142 ce.xclient.type = ClientMessage;
2143 ce.xclient.message_type = prop_atoms.wm_protocols;
2144 ce.xclient.display = ob_display;
2145 ce.xclient.window = self->window;
2146 ce.xclient.format = 32;
2147 ce.xclient.data.l[0] = prop_atoms.wm_delete_window;
2148 ce.xclient.data.l[1] = event_lasttime;
2149 ce.xclient.data.l[2] = 0l;
2150 ce.xclient.data.l[3] = 0l;
2151 ce.xclient.data.l[4] = 0l;
2152 XSendEvent(ob_display, self->window, FALSE, NoEventMask, &ce);
2155 void client_kill(ObClient *self)
2157 XKillClient(ob_display, self->window);
2160 void client_set_desktop_recursive(ObClient *self,
2161 guint target, gboolean donthide)
2166 if (target != self->desktop) {
2168 ob_debug("Setting desktop %u\n", target+1);
2170 g_assert(target < screen_num_desktops || target == DESKTOP_ALL);
2172 /* remove from the old desktop(s) */
2173 focus_order_remove(self);
2175 old = self->desktop;
2176 self->desktop = target;
2177 PROP_SET32(self->window, net_wm_desktop, cardinal, target);
2178 /* the frame can display the current desktop state */
2179 frame_adjust_state(self->frame);
2180 /* 'move' the window to the new desktop */
2182 client_showhide(self);
2183 /* raise if it was not already on the desktop */
2184 if (old != DESKTOP_ALL)
2185 stacking_raise(CLIENT_AS_WINDOW(self));
2186 screen_update_areas();
2188 /* add to the new desktop(s) */
2189 if (config_focus_new)
2190 focus_order_to_top(self);
2192 focus_order_to_bottom(self);
2194 dispatch_client(Event_Client_Desktop, self, target, old);
2197 /* move all transients */
2198 for (it = self->transients; it != NULL; it = it->next)
2199 if (it->data != self) client_set_desktop_recursive(it->data,
2203 void client_set_desktop(ObClient *self, guint target, gboolean donthide)
2205 client_set_desktop_recursive(client_search_top_transient(self),
2209 ObClient *client_search_modal_child(ObClient *self)
2214 for (it = self->transients; it != NULL; it = it->next) {
2215 ObClient *c = it->data;
2216 if ((ret = client_search_modal_child(c))) return ret;
2217 if (c->modal) return c;
2222 gboolean client_validate(ObClient *self)
2226 XSync(ob_display, FALSE); /* get all events on the server */
2228 if (XCheckTypedWindowEvent(ob_display, self->window, DestroyNotify, &e) ||
2229 XCheckTypedWindowEvent(ob_display, self->window, UnmapNotify, &e)) {
2230 XPutBackEvent(ob_display, &e);
2237 void client_set_wm_state(ObClient *self, long state)
2239 if (state == self->wmstate) return; /* no change */
2243 client_iconify(self, TRUE, TRUE);
2246 client_iconify(self, FALSE, TRUE);
2251 void client_set_state(ObClient *self, Atom action, long data1, long data2)
2253 gboolean shaded = self->shaded;
2254 gboolean fullscreen = self->fullscreen;
2255 gboolean max_horz = self->max_horz;
2256 gboolean max_vert = self->max_vert;
2259 if (!(action == prop_atoms.net_wm_state_add ||
2260 action == prop_atoms.net_wm_state_remove ||
2261 action == prop_atoms.net_wm_state_toggle))
2262 /* an invalid action was passed to the client message, ignore it */
2265 for (i = 0; i < 2; ++i) {
2266 Atom state = i == 0 ? data1 : data2;
2268 if (!state) continue;
2270 /* if toggling, then pick whether we're adding or removing */
2271 if (action == prop_atoms.net_wm_state_toggle) {
2272 if (state == prop_atoms.net_wm_state_modal)
2273 action = self->modal ? prop_atoms.net_wm_state_remove :
2274 prop_atoms.net_wm_state_add;
2275 else if (state == prop_atoms.net_wm_state_maximized_vert)
2276 action = self->max_vert ? prop_atoms.net_wm_state_remove :
2277 prop_atoms.net_wm_state_add;
2278 else if (state == prop_atoms.net_wm_state_maximized_horz)
2279 action = self->max_horz ? prop_atoms.net_wm_state_remove :
2280 prop_atoms.net_wm_state_add;
2281 else if (state == prop_atoms.net_wm_state_shaded)
2282 action = self->shaded ? prop_atoms.net_wm_state_remove :
2283 prop_atoms.net_wm_state_add;
2284 else if (state == prop_atoms.net_wm_state_skip_taskbar)
2285 action = self->skip_taskbar ?
2286 prop_atoms.net_wm_state_remove :
2287 prop_atoms.net_wm_state_add;
2288 else if (state == prop_atoms.net_wm_state_skip_pager)
2289 action = self->skip_pager ?
2290 prop_atoms.net_wm_state_remove :
2291 prop_atoms.net_wm_state_add;
2292 else if (state == prop_atoms.net_wm_state_fullscreen)
2293 action = self->fullscreen ?
2294 prop_atoms.net_wm_state_remove :
2295 prop_atoms.net_wm_state_add;
2296 else if (state == prop_atoms.net_wm_state_above)
2297 action = self->above ? prop_atoms.net_wm_state_remove :
2298 prop_atoms.net_wm_state_add;
2299 else if (state == prop_atoms.net_wm_state_below)
2300 action = self->below ? prop_atoms.net_wm_state_remove :
2301 prop_atoms.net_wm_state_add;
2304 if (action == prop_atoms.net_wm_state_add) {
2305 if (state == prop_atoms.net_wm_state_modal) {
2306 /* XXX raise here or something? */
2308 } else if (state == prop_atoms.net_wm_state_maximized_vert) {
2310 } else if (state == prop_atoms.net_wm_state_maximized_horz) {
2312 } else if (state == prop_atoms.net_wm_state_shaded) {
2314 } else if (state == prop_atoms.net_wm_state_skip_taskbar) {
2315 self->skip_taskbar = TRUE;
2316 } else if (state == prop_atoms.net_wm_state_skip_pager) {
2317 self->skip_pager = TRUE;
2318 } else if (state == prop_atoms.net_wm_state_fullscreen) {
2320 } else if (state == prop_atoms.net_wm_state_above) {
2322 } else if (state == prop_atoms.net_wm_state_below) {
2326 } else { /* action == prop_atoms.net_wm_state_remove */
2327 if (state == prop_atoms.net_wm_state_modal) {
2328 self->modal = FALSE;
2329 } else if (state == prop_atoms.net_wm_state_maximized_vert) {
2331 } else if (state == prop_atoms.net_wm_state_maximized_horz) {
2333 } else if (state == prop_atoms.net_wm_state_shaded) {
2335 } else if (state == prop_atoms.net_wm_state_skip_taskbar) {
2336 self->skip_taskbar = FALSE;
2337 } else if (state == prop_atoms.net_wm_state_skip_pager) {
2338 self->skip_pager = FALSE;
2339 } else if (state == prop_atoms.net_wm_state_fullscreen) {
2341 } else if (state == prop_atoms.net_wm_state_above) {
2342 self->above = FALSE;
2343 } else if (state == prop_atoms.net_wm_state_below) {
2344 self->below = FALSE;
2348 if (max_horz != self->max_horz || max_vert != self->max_vert) {
2349 if (max_horz != self->max_horz && max_vert != self->max_vert) {
2351 if (max_horz == max_vert) { /* both going the same way */
2352 client_maximize(self, max_horz, 0, TRUE);
2354 client_maximize(self, max_horz, 1, TRUE);
2355 client_maximize(self, max_vert, 2, TRUE);
2359 if (max_horz != self->max_horz)
2360 client_maximize(self, max_horz, 1, TRUE);
2362 client_maximize(self, max_vert, 2, TRUE);
2365 /* change fullscreen state before shading, as it will affect if the window
2367 if (fullscreen != self->fullscreen)
2368 client_fullscreen(self, fullscreen, TRUE);
2369 if (shaded != self->shaded)
2370 client_shade(self, shaded);
2371 client_calc_layer(self);
2372 client_change_state(self); /* change the hint to reflect these changes */
2375 ObClient *client_focus_target(ObClient *self)
2379 /* if we have a modal child, then focus it, not us */
2380 child = client_search_modal_child(self);
2381 if (child) return child;
2385 gboolean client_can_focus(ObClient *self)
2389 /* choose the correct target */
2390 self = client_focus_target(self);
2392 if (!self->frame->visible)
2395 if (!((self->can_focus || self->focus_notify) &&
2396 (self->desktop == screen_desktop ||
2397 self->desktop == DESKTOP_ALL) &&
2401 /* do a check to see if the window has already been unmapped or destroyed
2402 do this intelligently while watching out for unmaps we've generated
2403 (ignore_unmaps > 0) */
2404 if (XCheckTypedWindowEvent(ob_display, self->window,
2405 DestroyNotify, &ev)) {
2406 XPutBackEvent(ob_display, &ev);
2409 while (XCheckTypedWindowEvent(ob_display, self->window,
2410 UnmapNotify, &ev)) {
2411 if (self->ignore_unmaps) {
2412 self->ignore_unmaps--;
2414 XPutBackEvent(ob_display, &ev);
2422 gboolean client_focus(ObClient *self)
2424 /* choose the correct target */
2425 self = client_focus_target(self);
2427 if (!client_can_focus(self)) {
2428 if (!self->frame->visible) {
2429 /* update the focus lists */
2430 focus_order_to_top(self);
2435 if (self->can_focus)
2436 /* RevertToPointerRoot causes much more headache than RevertToNone, so
2437 I choose to use it always, hopefully to find errors quicker, if any
2438 are left. (I hate X. I hate focus events.) */
2439 XSetInputFocus(ob_display, self->window, RevertToPointerRoot,
2442 if (self->focus_notify) {
2444 ce.xclient.type = ClientMessage;
2445 ce.xclient.message_type = prop_atoms.wm_protocols;
2446 ce.xclient.display = ob_display;
2447 ce.xclient.window = self->window;
2448 ce.xclient.format = 32;
2449 ce.xclient.data.l[0] = prop_atoms.wm_take_focus;
2450 ce.xclient.data.l[1] = event_lasttime;
2451 ce.xclient.data.l[2] = 0l;
2452 ce.xclient.data.l[3] = 0l;
2453 ce.xclient.data.l[4] = 0l;
2454 XSendEvent(ob_display, self->window, FALSE, NoEventMask, &ce);
2458 ob_debug("%sively focusing %lx at %d\n",
2459 (self->can_focus ? "act" : "pass"),
2460 self->window, (int) event_lasttime);
2463 /* Cause the FocusIn to come back to us. Important for desktop switches,
2464 since otherwise we'll have no FocusIn on the queue and send it off to
2465 the focus_backup. */
2466 XSync(ob_display, FALSE);
2470 void client_unfocus(ObClient *self)
2472 g_assert(focus_client == self);
2474 ob_debug("client_unfocus for %lx\n", self->window);
2476 focus_fallback(OB_FOCUS_FALLBACK_UNFOCUSING);
2479 void client_activate(ObClient *self)
2481 if (client_normal(self) && screen_showing_desktop)
2482 screen_show_desktop(FALSE);
2484 client_iconify(self, FALSE, FALSE);
2485 if (self->desktop != DESKTOP_ALL &&
2486 self->desktop != screen_desktop)
2487 screen_set_desktop(self->desktop);
2488 else if (!self->frame->visible)
2489 /* if its not visible for other reasons, then don't mess
2493 client_shade(self, FALSE);
2495 stacking_raise(CLIENT_AS_WINDOW(self));
2498 gboolean client_focused(ObClient *self)
2500 return self == focus_client;
2503 ObClientIcon *client_icon(ObClient *self, int w, int h)
2506 /* si is the smallest image >= req */
2507 /* li is the largest image < req */
2508 unsigned long size, smallest = 0xffffffff, largest = 0, si = 0, li = 0;
2510 if (!self->nicons) return NULL;
2512 for (i = 0; i < self->nicons; ++i) {
2513 size = self->icons[i].width * self->icons[i].height;
2514 if (size < smallest && size >= (unsigned)(w * h)) {
2518 if (size > largest && size <= (unsigned)(w * h)) {
2523 if (largest == 0) /* didnt find one smaller than the requested size */
2524 return &self->icons[si];
2525 return &self->icons[li];
2528 /* this be mostly ripped from fvwm */
2529 ObClient *client_find_directional(ObClient *c, ObDirection dir)
2531 int my_cx, my_cy, his_cx, his_cy;
2534 int score, best_score;
2535 ObClient *best_client, *cur;
2541 /* first, find the centre coords of the currently focused window */
2542 my_cx = c->frame->area.x + c->frame->area.width / 2;
2543 my_cy = c->frame->area.y + c->frame->area.height / 2;
2548 for(it = g_list_first(client_list); it; it = it->next) {
2551 /* the currently selected window isn't interesting */
2554 if (!client_normal(cur))
2556 if(c->desktop != cur->desktop && cur->desktop != DESKTOP_ALL)
2560 if(client_focus_target(cur) == cur &&
2561 !(cur->can_focus || cur->focus_notify))
2564 /* find the centre coords of this window, from the
2565 * currently focused window's point of view */
2566 his_cx = (cur->frame->area.x - my_cx)
2567 + cur->frame->area.width / 2;
2568 his_cy = (cur->frame->area.y - my_cy)
2569 + cur->frame->area.height / 2;
2573 /* Rotate the diagonals 45 degrees counterclockwise.
2574 * To do this, multiply the matrix /+h +h\ with the
2575 * vector (x y). \-h +h/
2576 * h = sqrt(0.5). We can set h := 1 since absolute
2577 * distance doesn't matter here. */
2578 tx = his_cx + his_cy;
2579 his_cy = -his_cx + his_cy;
2584 case OB_DIRECTION_NORTH:
2585 case OB_DIRECTION_SOUTH:
2586 case OB_DIRECTION_NORTHEAST:
2587 case OB_DIRECTION_SOUTHWEST:
2588 offset = (his_cx < 0) ? -his_cx : his_cx;
2589 distance = ((dir == OB_DIRECTION_NORTH ||
2590 dir == OB_DIRECTION_NORTHEAST) ?
2593 case OB_DIRECTION_EAST:
2594 case OB_DIRECTION_WEST:
2595 case OB_DIRECTION_SOUTHEAST:
2596 case OB_DIRECTION_NORTHWEST:
2597 offset = (his_cy < 0) ? -his_cy : his_cy;
2598 distance = ((dir == OB_DIRECTION_WEST ||
2599 dir == OB_DIRECTION_NORTHWEST) ?
2604 /* the target must be in the requested direction */
2608 /* Calculate score for this window. The smaller the better. */
2609 score = distance + offset;
2611 /* windows more than 45 degrees off the direction are
2612 * heavily penalized and will only be chosen if nothing
2613 * else within a million pixels */
2614 if(offset > distance)
2617 if(best_score == -1 || score < best_score)
2625 void client_set_layer(ObClient *self, int layer)
2629 self->above = FALSE;
2630 } else if (layer == 0) {
2631 self->below = self->above = FALSE;
2633 self->below = FALSE;
2636 client_calc_layer(self);
2637 client_change_state(self); /* reflect this in the state hints */
2640 guint client_monitor(ObClient *self)
2644 for (i = 0; i < screen_num_monitors; ++i) {
2645 Rect *area = screen_physical_area_monitor(i);
2646 if (RECT_INTERSECTS_RECT(*area, self->frame->area))
2649 if (i == screen_num_monitors) i = 0;
2650 g_assert(i < screen_num_monitors);
2654 ObClient *client_search_top_transient(ObClient *self)
2656 /* move up the transient chain as far as possible */
2657 if (self->transient_for) {
2658 if (self->transient_for != OB_TRAN_GROUP) {
2659 return client_search_top_transient(self->transient_for);
2663 for (it = self->group->members; it; it = it->next) {
2664 ObClient *c = it->data;
2666 /* checking transient_for prevents infinate loops! */
2667 if (c != self && !c->transient_for)
2678 ObClient *client_search_transient(ObClient *self, ObClient *search)
2682 for (sit = self->transients; sit; sit = g_slist_next(sit)) {
2683 if (sit->data == search)
2685 if (client_search_transient(sit->data, search))