7 #include "moveresize.h"
9 #include "extensions.h"
21 #include "render/render.h"
24 #include <X11/Xutil.h>
26 /*! The event mask to grab on client windows */
27 #define CLIENT_EVENTMASK (PropertyChangeMask | FocusChangeMask | \
30 #define CLIENT_NOPROPAGATEMASK (ButtonPressMask | ButtonReleaseMask | \
33 GList *client_list = NULL;
35 static void client_get_all(ObClient *self);
36 static void client_toggle_border(ObClient *self, gboolean show);
37 static void client_get_area(ObClient *self);
38 static void client_get_desktop(ObClient *self);
39 static void client_get_state(ObClient *self);
40 static void client_get_shaped(ObClient *self);
41 static void client_get_mwm_hints(ObClient *self);
42 static void client_get_gravity(ObClient *self);
43 static void client_showhide(ObClient *self);
44 static void client_change_allowed_actions(ObClient *self);
45 static void client_change_state(ObClient *self);
46 static void client_apply_startup_state(ObClient *self);
47 static void client_restore_session_state(ObClient *self);
54 void client_shutdown()
58 void client_set_list()
60 Window *windows, *win_it;
62 guint size = g_list_length(client_list);
64 /* create an array of the window ids */
66 windows = g_new(Window, size);
68 for (it = client_list; it != NULL; it = it->next, ++win_it)
69 *win_it = ((ObClient*)it->data)->window;
73 PROP_SETA32(RootWindow(ob_display, ob_screen),
74 net_client_list, window, (guint32*)windows, size);
83 void client_foreach_transient(ObClient *self, ObClientForeachFunc func, void *data)
87 for (it = self->transients; it; it = it->next) {
88 if (!func(it->data, data)) return;
89 client_foreach_transient(it->data, func, data);
93 void client_foreach_ancestor(ObClient *self, ObClientForeachFunc func, void *data)
95 if (self->transient_for) {
96 if (self->transient_for != OB_TRAN_GROUP) {
97 if (!func(self->transient_for, data)) return;
98 client_foreach_ancestor(self->transient_for, func, data);
102 for (it = self->group->members; it; it = it->next)
103 if (it->data != self &&
104 !((ObClient*)it->data)->transient_for) {
105 if (!func(it->data, data)) return;
106 client_foreach_ancestor(it->data, func, data);
113 void client_manage_all()
115 unsigned int i, j, nchild;
118 XWindowAttributes attrib;
120 XQueryTree(ob_display, RootWindow(ob_display, ob_screen),
121 &w, &w, &children, &nchild);
123 /* remove all icon windows from the list */
124 for (i = 0; i < nchild; i++) {
125 if (children[i] == None) continue;
126 wmhints = XGetWMHints(ob_display, children[i]);
128 if ((wmhints->flags & IconWindowHint) &&
129 (wmhints->icon_window != children[i]))
130 for (j = 0; j < nchild; j++)
131 if (children[j] == wmhints->icon_window) {
139 for (i = 0; i < nchild; ++i) {
140 if (children[i] == None)
142 if (XGetWindowAttributes(ob_display, children[i], &attrib)) {
143 if (attrib.override_redirect) continue;
145 if (attrib.map_state != IsUnmapped)
146 client_manage(children[i]);
151 /* stack them as they were on startup!
152 why with stacking_lower? Why, because then windows who aren't in the
153 stacking list are on the top where you can see them instead of buried
155 for (i = startup_stack_size; i > 0; --i) {
158 w = startup_stack_order[i-1];
159 obw = g_hash_table_lookup(window_map, &w);
161 g_assert(WINDOW_IS_CLIENT(obw));
162 stacking_lower(CLIENT_AS_WINDOW(obw));
165 g_free(startup_stack_order);
166 startup_stack_order = NULL;
167 startup_stack_size = 0;
169 if (config_focus_new) {
172 active = g_hash_table_lookup(window_map, &startup_active);
174 g_assert(WINDOW_IS_CLIENT(active));
175 if (!client_focus(WINDOW_AS_CLIENT(active)))
176 focus_fallback(OB_FOCUS_FALLBACK_NOFOCUS);
178 focus_fallback(OB_FOCUS_FALLBACK_NOFOCUS);
182 void client_manage(Window window)
186 XWindowAttributes attrib;
187 XSetWindowAttributes attrib_set;
189 gboolean activate = FALSE;
193 /* check if it has already been unmapped by the time we started mapping
194 the grab does a sync so we don't have to here */
195 if (XCheckTypedWindowEvent(ob_display, window, DestroyNotify, &e) ||
196 XCheckTypedWindowEvent(ob_display, window, UnmapNotify, &e)) {
197 XPutBackEvent(ob_display, &e);
200 return; /* don't manage it */
203 /* make sure it isn't an override-redirect window */
204 if (!XGetWindowAttributes(ob_display, window, &attrib) ||
205 attrib.override_redirect) {
207 return; /* don't manage it */
210 /* is the window a docking app */
211 if ((wmhint = XGetWMHints(ob_display, window))) {
212 if ((wmhint->flags & StateHint) &&
213 wmhint->initial_state == WithdrawnState) {
214 dock_add(window, wmhint);
222 ob_debug("Managing window: %lx\n", window);
224 /* choose the events we want to receive on the CLIENT window */
225 attrib_set.event_mask = CLIENT_EVENTMASK;
226 attrib_set.do_not_propagate_mask = CLIENT_NOPROPAGATEMASK;
227 XChangeWindowAttributes(ob_display, window,
228 CWEventMask|CWDontPropagate, &attrib_set);
231 /* create the ObClient struct, and populate it from the hints on the
233 self = g_new(ObClient, 1);
234 self->obwin.type = Window_Client;
235 self->window = window;
236 client_get_all(self);
237 client_restore_session_state(self);
238 client_change_state(self);
240 /* remove the client's border (and adjust re gravity) */
241 client_toggle_border(self, FALSE);
243 /* specify that if we exit, the window should not be destroyed and should
244 be reparented back to root automatically */
245 XChangeSaveSet(ob_display, window, SetModeInsert);
247 /* create the decoration frame for the client window */
248 self->frame = frame_new();
250 frame_grab_client(self->frame, self);
252 client_apply_startup_state(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 client_move_onscreen(self, TRUE);
305 screen_update_areas();
307 client_showhide(self);
309 /* use client_focus instead of client_activate cuz client_activate does
310 stuff like switch desktops etc and I'm not interested in all that when
311 a window maps since its not based on an action from the user like
312 clicking a window to activate is. so keep the new window out of the way
314 if (activate) client_focus(self);
316 /* client_activate does this but we aret using it so we have to do it
318 if (screen_showing_desktop)
319 screen_show_desktop(FALSE);
321 /* update the list hints */
324 dispatch_client(Event_Client_Mapped, self, 0, 0);
326 /* add to client list/map */
327 client_list = g_list_append(client_list, self);
328 g_hash_table_insert(window_map, &self->window, self);
330 ob_debug("Managed window 0x%lx (%s)\n", window, self->class);
333 void client_unmanage_all()
335 while (client_list != NULL)
336 client_unmanage(client_list->data);
339 /* called by client_unmanage() to close any menus referencing this client */
340 void client_close_menus(gpointer key, gpointer value, gpointer self)
342 if (((ObMenu *)value)->client == (ObClient *)self)
343 menu_hide((ObMenu *)value);
346 void client_unmanage(ObClient *self)
351 ob_debug("Unmanaging window: %lx (%s)\n", self->window, self->class);
353 dispatch_client(Event_Client_Destroy, self, 0, 0);
354 g_assert(self != NULL);
356 /* remove the window from our save set */
357 XChangeSaveSet(ob_display, self->window, SetModeDelete);
359 /* we dont want events no more */
360 XSelectInput(ob_display, self->window, NoEventMask);
362 frame_hide(self->frame);
364 client_list = g_list_remove(client_list, self);
365 stacking_remove(self);
366 g_hash_table_remove(window_map, &self->window);
368 /* update the focus lists */
369 focus_order_remove(self);
371 /* once the client is out of the list, update the struts to remove it's
373 screen_update_areas();
375 /* tell our parent(s) that we're gone */
376 if (self->transient_for == OB_TRAN_GROUP) { /* transient of group */
379 for (it = self->group->members; it; it = it->next)
380 if (it->data != self)
381 ((ObClient*)it->data)->transients =
382 g_slist_remove(((ObClient*)it->data)->transients, self);
383 } else if (self->transient_for) { /* transient of window */
384 self->transient_for->transients =
385 g_slist_remove(self->transient_for->transients, self);
388 /* tell our transients that we're gone */
389 for (it = self->transients; it != NULL; it = it->next) {
390 if (((ObClient*)it->data)->transient_for != OB_TRAN_GROUP) {
391 ((ObClient*)it->data)->transient_for = NULL;
392 client_calc_layer(it->data);
396 if (moveresize_client == self)
397 moveresize_end(TRUE);
399 /* close any windows that are attached to this window */
400 g_hash_table_foreach(menu_hash, client_close_menus, self);
403 if (focus_client == self) {
406 /* focus the last focused window on the desktop, and ignore enter
407 events from the unmap so it doesnt mess with the focus */
408 while (XCheckTypedEvent(ob_display, EnterNotify, &e));
409 client_unfocus(self);
412 /* remove from its group */
414 group_remove(self->group, self);
418 /* dispatch the unmapped event */
419 dispatch_client(Event_Client_Unmapped, self, 0, 0);
420 g_assert(self != NULL);
422 /* give the client its border back */
423 client_toggle_border(self, TRUE);
425 /* reparent the window out of the frame, and free the frame */
426 frame_release_client(self->frame, self);
429 if (ob_state() != OB_STATE_EXITING) {
430 /* these values should not be persisted across a window
432 PROP_ERASE(self->window, net_wm_desktop);
433 PROP_ERASE(self->window, net_wm_state);
434 PROP_ERASE(self->window, wm_state);
436 /* if we're left in an iconic state, the client wont be mapped. this is
437 bad, since we will no longer be managing the window on restart */
439 XMapWindow(ob_display, self->window);
443 ob_debug("Unmanaged window 0x%lx\n", self->window);
445 /* free all data allocated in the client struct */
446 g_slist_free(self->transients);
447 for (j = 0; j < self->nicons; ++j)
448 g_free(self->icons[j].data);
449 if (self->nicons > 0)
452 g_free(self->icon_title);
458 /* update the list hints */
462 static void client_restore_session_state(ObClient *self)
466 g_message("looking for %s", self->name);
468 s = session_state_find(self);
469 g_message("returned %p %d", s, self->positioned);
472 g_message("restoring state for %s", s->name);
474 g_message("%d %d %d %d", s->x, s->y, s->w, s->h);
475 RECT_SET(self->area, s->x, s->y, s->w, s->h);
476 XResizeWindow(ob_display, self->window, s->w, s->h);
477 self->positioned = TRUE;
478 g_message("desktop %d", s->desktop);
479 self->desktop = s->desktop == DESKTOP_ALL ? s->desktop :
480 MIN(screen_num_desktops - 1, s->desktop);
481 self->shaded = s->shaded;
482 self->iconic = s->iconic;
483 self->skip_pager = s->skip_pager;
484 self->skip_taskbar = s->skip_taskbar;
485 self->fullscreen = s->fullscreen;
486 self->above = s->above;
487 self->below = s->below;
488 self->max_horz = s->max_horz;
489 self->max_vert = s->max_vert;
491 session_state_free(s);
494 void client_move_onscreen(ObClient *self, gboolean rude)
496 int x = self->area.x;
497 int y = self->area.y;
498 if (client_find_onscreen(self, &x, &y,
499 self->area.width, self->area.height, rude)) {
500 client_configure(self, OB_CORNER_TOPLEFT, x, y,
501 self->area.width, self->area.height,
506 gboolean client_find_onscreen(ObClient *self, int *x, int *y, int w, int h,
510 int ox = *x, oy = *y;
512 frame_client_gravity(self->frame, x, y); /* get where the frame
515 /* XXX watch for xinerama dead areas */
517 a = screen_area(self->desktop);
518 if (!self->strut.right && *x >= a->x + a->width - 1)
519 *x = a->x + a->width - self->frame->area.width;
520 if (!self->strut.bottom && *y >= a->y + a->height - 1)
521 *y = a->y + a->height - self->frame->area.height;
522 if (!self->strut.left && *x + self->frame->area.width - 1 < a->x)
524 if (!self->strut.top && *y + self->frame->area.height - 1 < a->y)
528 /* this is my MOZILLA BITCHSLAP. oh ya it fucking feels good.
529 Java can suck it too. */
531 /* dont let windows map/move into the strut unless they
532 are bigger than the available area */
534 if (!self->strut.left && *x < a->x) *x = a->x;
535 if (!self->strut.right && *x + w > a->x + a->width)
536 *x = a->x + a->width - w;
538 if (h <= a->height) {
539 if (!self->strut.top && *y < a->y) *y = a->y;
540 if (!self->strut.bottom && *y + h > a->y + a->height)
541 *y = a->y + a->height - h;
545 frame_frame_gravity(self->frame, x, y); /* get where the client
548 return ox != *x || oy != *y;
551 static void client_toggle_border(ObClient *self, gboolean show)
553 /* adjust our idea of where the client is, based on its border. When the
554 border is removed, the client should now be considered to be in a
556 when re-adding the border to the client, the same operation needs to be
558 int oldx = self->area.x, oldy = self->area.y;
559 int x = oldx, y = oldy;
560 switch(self->gravity) {
562 case NorthWestGravity:
564 case SouthWestGravity:
566 case NorthEastGravity:
568 case SouthEastGravity:
569 if (show) x -= self->border_width * 2;
570 else x += self->border_width * 2;
577 if (show) x -= self->border_width;
578 else x += self->border_width;
581 switch(self->gravity) {
583 case NorthWestGravity:
585 case NorthEastGravity:
587 case SouthWestGravity:
589 case SouthEastGravity:
590 if (show) y -= self->border_width * 2;
591 else y += self->border_width * 2;
598 if (show) y -= self->border_width;
599 else y += self->border_width;
606 XSetWindowBorderWidth(ob_display, self->window, self->border_width);
608 /* move the client so it is back it the right spot _with_ its
610 if (x != oldx || y != oldy)
611 XMoveWindow(ob_display, self->window, x, y);
613 XSetWindowBorderWidth(ob_display, self->window, 0);
617 static void client_get_all(ObClient *self)
619 /* update EVERYTHING!! */
621 self->ignore_unmaps = 0;
625 self->title = self->icon_title = NULL;
626 self->title_count = 1;
627 self->name = self->class = self->role = NULL;
628 self->wmstate = NormalState;
629 self->transient = FALSE;
630 self->transients = NULL;
631 self->transient_for = NULL;
633 self->urgent = FALSE;
634 self->positioned = FALSE;
635 self->decorate = TRUE;
639 client_get_area(self);
640 client_update_transient_for(self);
641 client_update_wmhints(self);
642 client_get_desktop(self);
643 client_get_state(self);
644 client_get_shaped(self);
646 client_get_mwm_hints(self);
647 client_get_type(self);/* this can change the mwmhints for special cases */
649 client_update_protocols(self);
651 client_get_gravity(self); /* get the attribute gravity */
652 client_update_normal_hints(self); /* this may override the attribute
655 /* got the type, the mwmhints, the protocols, and the normal hints
656 (min/max sizes), so we're ready to set up the decorations/functions */
657 client_setup_decor_and_functions(self);
659 client_update_title(self);
660 client_update_class(self);
661 client_update_strut(self);
662 client_update_icons(self);
665 static void client_get_area(ObClient *self)
667 XWindowAttributes wattrib;
670 ret = XGetWindowAttributes(ob_display, self->window, &wattrib);
671 g_assert(ret != BadWindow);
673 RECT_SET(self->area, wattrib.x, wattrib.y, wattrib.width, wattrib.height);
674 self->border_width = wattrib.border_width;
677 static void client_get_desktop(ObClient *self)
679 guint32 d = screen_num_desktops; /* an always-invalid value */
681 if (PROP_GET32(self->window, net_wm_desktop, cardinal, &d)) {
682 if (d >= screen_num_desktops && d != DESKTOP_ALL)
683 self->desktop = screen_num_desktops - 1;
687 gboolean trdesk = FALSE;
689 if (self->transient_for) {
690 if (self->transient_for != OB_TRAN_GROUP) {
691 self->desktop = self->transient_for->desktop;
696 for (it = self->group->members; it; it = it->next)
697 if (it->data != self &&
698 !((ObClient*)it->data)->transient_for) {
699 self->desktop = ((ObClient*)it->data)->desktop;
706 /* defaults to the current desktop */
707 self->desktop = screen_desktop;
710 if (self->desktop != d) {
711 /* set the desktop hint, to make sure that it always exists */
712 PROP_SET32(self->window, net_wm_desktop, cardinal, self->desktop);
716 static void client_get_state(ObClient *self)
721 self->modal = self->shaded = self->max_horz = self->max_vert =
722 self->fullscreen = self->above = self->below = self->iconic =
723 self->skip_taskbar = self->skip_pager = FALSE;
725 if (PROP_GETA32(self->window, net_wm_state, atom, &state, &num)) {
727 for (i = 0; i < num; ++i) {
728 if (state[i] == prop_atoms.net_wm_state_modal)
730 else if (state[i] == prop_atoms.net_wm_state_shaded)
732 else if (state[i] == prop_atoms.net_wm_state_hidden)
734 else if (state[i] == prop_atoms.net_wm_state_skip_taskbar)
735 self->skip_taskbar = TRUE;
736 else if (state[i] == prop_atoms.net_wm_state_skip_pager)
737 self->skip_pager = TRUE;
738 else if (state[i] == prop_atoms.net_wm_state_fullscreen)
739 self->fullscreen = TRUE;
740 else if (state[i] == prop_atoms.net_wm_state_maximized_vert)
741 self->max_vert = TRUE;
742 else if (state[i] == prop_atoms.net_wm_state_maximized_horz)
743 self->max_horz = TRUE;
744 else if (state[i] == prop_atoms.net_wm_state_above)
746 else if (state[i] == prop_atoms.net_wm_state_below)
754 static void client_get_shaped(ObClient *self)
756 self->shaped = FALSE;
758 if (extensions_shape) {
763 XShapeSelectInput(ob_display, self->window, ShapeNotifyMask);
765 XShapeQueryExtents(ob_display, self->window, &s, &foo,
766 &foo, &ufoo, &ufoo, &foo, &foo, &foo, &ufoo,
768 self->shaped = (s != 0);
773 void client_update_transient_for(ObClient *self)
776 ObClient *target = NULL;
778 if (XGetTransientForHint(ob_display, self->window, &t)) {
779 self->transient = TRUE;
780 if (t != self->window) { /* cant be transient to itself! */
781 target = g_hash_table_lookup(window_map, &t);
782 /* if this happens then we need to check for it*/
783 g_assert(target != self);
784 g_assert(!target || WINDOW_IS_CLIENT(target));
786 if (!target && self->group) {
787 /* not transient to a client, see if it is transient for a
789 if (t == self->group->leader ||
791 t == RootWindow(ob_display, ob_screen)) {
792 /* window is a transient for its group! */
793 target = OB_TRAN_GROUP;
798 self->transient = FALSE;
800 /* if anything has changed... */
801 if (target != self->transient_for) {
802 if (self->transient_for == OB_TRAN_GROUP) { /* transient of group */
805 /* remove from old parents */
806 for (it = self->group->members; it; it = g_slist_next(it)) {
807 ObClient *c = it->data;
808 if (c != self && !c->transient_for)
809 c->transients = g_slist_remove(c->transients, self);
811 } else if (self->transient_for != NULL) { /* transient of window */
812 /* remove from old parent */
813 self->transient_for->transients =
814 g_slist_remove(self->transient_for->transients, self);
816 self->transient_for = target;
817 if (self->transient_for == OB_TRAN_GROUP) { /* transient of group */
820 /* add to new parents */
821 for (it = self->group->members; it; it = g_slist_next(it)) {
822 ObClient *c = it->data;
823 if (c != self && !c->transient_for)
824 c->transients = g_slist_append(c->transients, self);
827 /* remove all transients which are in the group, that causes
828 circlular pointer hell of doom */
829 for (it = self->group->members; it; it = g_slist_next(it)) {
831 for (sit = self->transients; sit; sit = next) {
832 next = g_slist_next(sit);
833 if (sit->data == it->data)
835 g_slist_delete_link(self->transients, sit);
838 } else if (self->transient_for != NULL) { /* transient of window */
839 /* add to new parent */
840 self->transient_for->transients =
841 g_slist_append(self->transient_for->transients, self);
846 static void client_get_mwm_hints(ObClient *self)
851 self->mwmhints.flags = 0; /* default to none */
853 if (PROP_GETA32(self->window, motif_wm_hints, motif_wm_hints,
855 if (num >= OB_MWM_ELEMENTS) {
856 self->mwmhints.flags = hints[0];
857 self->mwmhints.functions = hints[1];
858 self->mwmhints.decorations = hints[2];
864 void client_get_type(ObClient *self)
871 if (PROP_GETA32(self->window, net_wm_window_type, atom, &val, &num)) {
872 /* use the first value that we know about in the array */
873 for (i = 0; i < num; ++i) {
874 if (val[i] == prop_atoms.net_wm_window_type_desktop)
875 self->type = OB_CLIENT_TYPE_DESKTOP;
876 else if (val[i] == prop_atoms.net_wm_window_type_dock)
877 self->type = OB_CLIENT_TYPE_DOCK;
878 else if (val[i] == prop_atoms.net_wm_window_type_toolbar)
879 self->type = OB_CLIENT_TYPE_TOOLBAR;
880 else if (val[i] == prop_atoms.net_wm_window_type_menu)
881 self->type = OB_CLIENT_TYPE_MENU;
882 else if (val[i] == prop_atoms.net_wm_window_type_utility)
883 self->type = OB_CLIENT_TYPE_UTILITY;
884 else if (val[i] == prop_atoms.net_wm_window_type_splash)
885 self->type = OB_CLIENT_TYPE_SPLASH;
886 else if (val[i] == prop_atoms.net_wm_window_type_dialog)
887 self->type = OB_CLIENT_TYPE_DIALOG;
888 else if (val[i] == prop_atoms.net_wm_window_type_normal)
889 self->type = OB_CLIENT_TYPE_NORMAL;
890 else if (val[i] == prop_atoms.kde_net_wm_window_type_override) {
891 /* prevent this window from getting any decor or
893 self->mwmhints.flags &= (OB_MWM_FLAG_FUNCTIONS |
894 OB_MWM_FLAG_DECORATIONS);
895 self->mwmhints.decorations = 0;
896 self->mwmhints.functions = 0;
898 if (self->type != (ObClientType) -1)
899 break; /* grab the first legit type */
904 if (self->type == (ObClientType) -1) {
905 /*the window type hint was not set, which means we either classify
906 ourself as a normal window or a dialog, depending on if we are a
909 self->type = OB_CLIENT_TYPE_DIALOG;
911 self->type = OB_CLIENT_TYPE_NORMAL;
915 void client_update_protocols(ObClient *self)
920 self->focus_notify = FALSE;
921 self->delete_window = FALSE;
923 if (PROP_GETA32(self->window, wm_protocols, atom, &proto, &num_return)) {
924 for (i = 0; i < num_return; ++i) {
925 if (proto[i] == prop_atoms.wm_delete_window) {
926 /* this means we can request the window to close */
927 self->delete_window = TRUE;
928 } else if (proto[i] == prop_atoms.wm_take_focus)
929 /* if this protocol is requested, then the window will be
930 notified whenever we want it to receive focus */
931 self->focus_notify = TRUE;
937 static void client_get_gravity(ObClient *self)
939 XWindowAttributes wattrib;
942 ret = XGetWindowAttributes(ob_display, self->window, &wattrib);
943 g_assert(ret != BadWindow);
944 self->gravity = wattrib.win_gravity;
947 void client_update_normal_hints(ObClient *self)
951 int oldgravity = self->gravity;
954 self->min_ratio = 0.0f;
955 self->max_ratio = 0.0f;
956 SIZE_SET(self->size_inc, 1, 1);
957 SIZE_SET(self->base_size, 0, 0);
958 SIZE_SET(self->min_size, 0, 0);
959 SIZE_SET(self->max_size, G_MAXINT, G_MAXINT);
961 /* get the hints from the window */
962 if (XGetWMNormalHints(ob_display, self->window, &size, &ret)) {
963 /* don't let apps tell me where to put transient windows, but only if
964 they have a valid parent */
965 self->positioned = !!(size.flags & (PPosition|USPosition)) &&
966 !self->transient_for;
968 if (size.flags & PWinGravity) {
969 self->gravity = size.win_gravity;
971 /* if the client has a frame, i.e. has already been mapped and
972 is changing its gravity */
973 if (self->frame && self->gravity != oldgravity) {
974 /* move our idea of the client's position based on its new
976 self->area.x = self->frame->area.x;
977 self->area.y = self->frame->area.y;
978 frame_frame_gravity(self->frame, &self->area.x, &self->area.y);
982 if (size.flags & PAspect) {
983 if (size.min_aspect.y)
984 self->min_ratio = (float)size.min_aspect.x / size.min_aspect.y;
985 if (size.max_aspect.y)
986 self->max_ratio = (float)size.max_aspect.x / size.max_aspect.y;
989 if (size.flags & PMinSize)
990 SIZE_SET(self->min_size, size.min_width, size.min_height);
992 if (size.flags & PMaxSize)
993 SIZE_SET(self->max_size, size.max_width, size.max_height);
995 if (size.flags & PBaseSize)
996 SIZE_SET(self->base_size, size.base_width, size.base_height);
998 if (size.flags & PResizeInc)
999 SIZE_SET(self->size_inc, size.width_inc, size.height_inc);
1003 void client_setup_decor_and_functions(ObClient *self)
1005 /* start with everything (cept fullscreen) */
1006 self->decorations = (OB_FRAME_DECOR_TITLEBAR |
1007 OB_FRAME_DECOR_HANDLE |
1008 OB_FRAME_DECOR_GRIPS |
1009 OB_FRAME_DECOR_BORDER |
1010 OB_FRAME_DECOR_ICON |
1011 OB_FRAME_DECOR_ALLDESKTOPS |
1012 OB_FRAME_DECOR_ICONIFY |
1013 OB_FRAME_DECOR_MAXIMIZE |
1014 OB_FRAME_DECOR_SHADE);
1015 self->functions = (OB_CLIENT_FUNC_RESIZE |
1016 OB_CLIENT_FUNC_MOVE |
1017 OB_CLIENT_FUNC_ICONIFY |
1018 OB_CLIENT_FUNC_MAXIMIZE |
1019 OB_CLIENT_FUNC_SHADE);
1020 if (self->delete_window) {
1021 self->functions |= OB_CLIENT_FUNC_CLOSE;
1022 self->decorations |= OB_FRAME_DECOR_CLOSE;
1025 if (!(self->min_size.width < self->max_size.width ||
1026 self->min_size.height < self->max_size.height))
1027 self->functions &= ~OB_CLIENT_FUNC_RESIZE;
1029 switch (self->type) {
1030 case OB_CLIENT_TYPE_NORMAL:
1031 /* normal windows retain all of the possible decorations and
1032 functionality, and are the only windows that you can fullscreen */
1033 self->functions |= OB_CLIENT_FUNC_FULLSCREEN;
1036 case OB_CLIENT_TYPE_DIALOG:
1037 case OB_CLIENT_TYPE_UTILITY:
1038 /* these windows cannot be maximized */
1039 self->functions &= ~OB_CLIENT_FUNC_MAXIMIZE;
1042 case OB_CLIENT_TYPE_MENU:
1043 case OB_CLIENT_TYPE_TOOLBAR:
1044 /* these windows get less functionality */
1045 self->functions &= ~(OB_CLIENT_FUNC_ICONIFY | OB_CLIENT_FUNC_RESIZE);
1048 case OB_CLIENT_TYPE_DESKTOP:
1049 case OB_CLIENT_TYPE_DOCK:
1050 case OB_CLIENT_TYPE_SPLASH:
1051 /* none of these windows are manipulated by the window manager */
1052 self->decorations = 0;
1053 self->functions = 0;
1057 /* Mwm Hints are applied subtractively to what has already been chosen for
1058 decor and functionality */
1059 if (self->mwmhints.flags & OB_MWM_FLAG_DECORATIONS) {
1060 if (! (self->mwmhints.decorations & OB_MWM_DECOR_ALL)) {
1061 if (! ((self->mwmhints.decorations & OB_MWM_DECOR_HANDLE) ||
1062 (self->mwmhints.decorations & OB_MWM_DECOR_TITLE)))
1063 /* if the mwm hints request no handle or title, then all
1064 decorations are disabled */
1065 self->decorations = 0;
1069 if (self->mwmhints.flags & OB_MWM_FLAG_FUNCTIONS) {
1070 if (! (self->mwmhints.functions & OB_MWM_FUNC_ALL)) {
1071 if (! (self->mwmhints.functions & OB_MWM_FUNC_RESIZE))
1072 self->functions &= ~OB_CLIENT_FUNC_RESIZE;
1073 if (! (self->mwmhints.functions & OB_MWM_FUNC_MOVE))
1074 self->functions &= ~OB_CLIENT_FUNC_MOVE;
1075 /* dont let mwm hints kill any buttons
1076 if (! (self->mwmhints.functions & OB_MWM_FUNC_ICONIFY))
1077 self->functions &= ~OB_CLIENT_FUNC_ICONIFY;
1078 if (! (self->mwmhints.functions & OB_MWM_FUNC_MAXIMIZE))
1079 self->functions &= ~OB_CLIENT_FUNC_MAXIMIZE;
1081 /* dont let mwm hints kill the close button
1082 if (! (self->mwmhints.functions & MwmFunc_Close))
1083 self->functions &= ~OB_CLIENT_FUNC_CLOSE; */
1087 if (!(self->functions & OB_CLIENT_FUNC_SHADE))
1088 self->decorations &= ~OB_FRAME_DECOR_SHADE;
1089 if (!(self->functions & OB_CLIENT_FUNC_ICONIFY))
1090 self->decorations &= ~OB_FRAME_DECOR_ICONIFY;
1091 if (!(self->functions & OB_CLIENT_FUNC_RESIZE))
1092 self->decorations &= ~OB_FRAME_DECOR_GRIPS;
1094 /* can't maximize without moving/resizing */
1095 if (!((self->functions & OB_CLIENT_FUNC_MAXIMIZE) &&
1096 (self->functions & OB_CLIENT_FUNC_MOVE) &&
1097 (self->functions & OB_CLIENT_FUNC_RESIZE))) {
1098 self->functions &= ~OB_CLIENT_FUNC_MAXIMIZE;
1099 self->decorations &= ~OB_FRAME_DECOR_MAXIMIZE;
1102 /* finally, the user can have requested no decorations, which overrides
1104 if (!self->decorate)
1105 self->decorations = 0;
1107 /* if we don't have a titlebar, then we cannot shade! */
1108 if (!(self->decorations & OB_FRAME_DECOR_TITLEBAR))
1109 self->functions &= ~OB_CLIENT_FUNC_SHADE;
1111 /* now we need to check against rules for the client's current state */
1112 if (self->fullscreen) {
1113 self->functions &= (OB_CLIENT_FUNC_CLOSE |
1114 OB_CLIENT_FUNC_FULLSCREEN |
1115 OB_CLIENT_FUNC_ICONIFY);
1116 self->decorations = 0;
1119 client_change_allowed_actions(self);
1122 /* this makes sure that these windows appear on all desktops */
1123 if (self->type == OB_CLIENT_TYPE_DESKTOP &&
1124 self->desktop != DESKTOP_ALL)
1125 client_set_desktop(self, DESKTOP_ALL, FALSE);
1127 /* adjust the client's decorations, etc. */
1128 client_reconfigure(self);
1130 /* this makes sure that these windows appear on all desktops */
1131 if (self->type == OB_CLIENT_TYPE_DESKTOP &&
1132 self->desktop != DESKTOP_ALL)
1134 self->desktop = DESKTOP_ALL;
1139 static void client_change_allowed_actions(ObClient *self)
1144 /* desktop windows are kept on all desktops */
1145 if (self->type != OB_CLIENT_TYPE_DESKTOP)
1146 actions[num++] = prop_atoms.net_wm_action_change_desktop;
1148 if (self->functions & OB_CLIENT_FUNC_SHADE)
1149 actions[num++] = prop_atoms.net_wm_action_shade;
1150 if (self->functions & OB_CLIENT_FUNC_CLOSE)
1151 actions[num++] = prop_atoms.net_wm_action_close;
1152 if (self->functions & OB_CLIENT_FUNC_MOVE)
1153 actions[num++] = prop_atoms.net_wm_action_move;
1154 if (self->functions & OB_CLIENT_FUNC_ICONIFY)
1155 actions[num++] = prop_atoms.net_wm_action_minimize;
1156 if (self->functions & OB_CLIENT_FUNC_RESIZE)
1157 actions[num++] = prop_atoms.net_wm_action_resize;
1158 if (self->functions & OB_CLIENT_FUNC_FULLSCREEN)
1159 actions[num++] = prop_atoms.net_wm_action_fullscreen;
1160 if (self->functions & OB_CLIENT_FUNC_MAXIMIZE) {
1161 actions[num++] = prop_atoms.net_wm_action_maximize_horz;
1162 actions[num++] = prop_atoms.net_wm_action_maximize_vert;
1165 PROP_SETA32(self->window, net_wm_allowed_actions, atom, actions, num);
1167 /* make sure the window isn't breaking any rules now */
1169 if (!(self->functions & OB_CLIENT_FUNC_SHADE) && self->shaded) {
1170 if (self->frame) client_shade(self, FALSE);
1171 else self->shaded = FALSE;
1173 if (!(self->functions & OB_CLIENT_FUNC_ICONIFY) && self->iconic) {
1174 if (self->frame) client_iconify(self, FALSE, TRUE);
1175 else self->iconic = FALSE;
1177 if (!(self->functions & OB_CLIENT_FUNC_FULLSCREEN) && self->fullscreen) {
1178 if (self->frame) client_fullscreen(self, FALSE, TRUE);
1179 else self->fullscreen = FALSE;
1181 if (!(self->functions & OB_CLIENT_FUNC_MAXIMIZE) && (self->max_horz ||
1183 if (self->frame) client_maximize(self, FALSE, 0, TRUE);
1184 else self->max_vert = self->max_horz = FALSE;
1188 void client_reconfigure(ObClient *self)
1190 /* by making this pass FALSE for user, we avoid the emacs event storm where
1191 every configurenotify causes an update in its normal hints, i think this
1192 is generally what we want anyways... */
1193 client_configure(self, OB_CORNER_TOPLEFT, self->area.x, self->area.y,
1194 self->area.width, self->area.height, FALSE, TRUE);
1197 void client_update_wmhints(ObClient *self)
1200 gboolean ur = FALSE;
1203 /* assume a window takes input if it doesnt specify */
1204 self->can_focus = TRUE;
1206 if ((hints = XGetWMHints(ob_display, self->window)) != NULL) {
1207 if (hints->flags & InputHint)
1208 self->can_focus = hints->input;
1210 /* only do this when first managing the window *AND* when we aren't
1212 if (ob_state() != OB_STATE_STARTING && self->frame == NULL)
1213 if (hints->flags & StateHint)
1214 self->iconic = hints->initial_state == IconicState;
1216 if (hints->flags & XUrgencyHint)
1219 if (!(hints->flags & WindowGroupHint))
1220 hints->window_group = None;
1222 /* did the group state change? */
1223 if (hints->window_group !=
1224 (self->group ? self->group->leader : None)) {
1225 /* remove from the old group if there was one */
1226 if (self->group != NULL) {
1227 /* remove transients of the group */
1228 for (it = self->group->members; it; it = it->next)
1229 self->transients = g_slist_remove(self->transients,
1231 group_remove(self->group, self);
1234 if (hints->window_group != None) {
1235 self->group = group_add(hints->window_group, self);
1237 /* i can only have transients from the group if i am not
1239 if (!self->transient_for) {
1240 /* add other transients of the group that are already
1242 for (it = self->group->members; it; it = it->next) {
1243 ObClient *c = it->data;
1244 if (c != self && c->transient_for == OB_TRAN_GROUP)
1246 g_slist_append(self->transients, c);
1251 /* the WM_HINTS can contain an icon */
1252 client_update_icons(self);
1254 /* because the self->transient flag wont change from this call,
1255 we don't need to update the window's type and such, only its
1256 transient_for, and the transients lists of other windows in
1257 the group may be affected */
1258 client_update_transient_for(self);
1264 if (ur != self->urgent) {
1266 ob_debug("Urgent Hint for 0x%lx: %s\n", self->window,
1268 /* fire the urgent callback if we're mapped, otherwise, wait until
1269 after we're mapped */
1271 dispatch_client(Event_Client_Urgent, self, self->urgent, 0);
1275 void client_update_title(ObClient *self)
1281 gboolean read_title;
1283 g_free(self->title);
1286 if (!PROP_GETS(self->window, net_wm_name, utf8, &data))
1287 /* try old x stuff */
1288 if (!PROP_GETS(self->window, wm_name, locale, &data))
1289 data = g_strdup("Unnamed Window");
1291 /* look for duplicates and append a number */
1293 for (it = client_list; it; it = it->next)
1294 if (it->data != self) {
1295 ObClient *c = it->data;
1296 if (0 == strncmp(c->title, data, strlen(data)))
1297 nums |= 1 << c->title_count;
1299 /* find first free number */
1300 for (i = 1; i <= 32; ++i)
1301 if (!(nums & (1 << i))) {
1302 if (self->title_count == 1 || i == 1)
1303 self->title_count = i;
1306 /* dont display the number for the first window */
1307 if (self->title_count > 1) {
1308 char *vdata, *ndata;
1309 ndata = g_strdup_printf(" - [%u]", self->title_count);
1310 vdata = g_strconcat(data, ndata, NULL);
1316 PROP_SETS(self->window, net_wm_visible_name, data);
1321 frame_adjust_title(self->frame);
1323 /* update the icon title */
1325 g_free(self->icon_title);
1329 if (!PROP_GETS(self->window, net_wm_icon_name, utf8, &data))
1330 /* try old x stuff */
1331 if (!PROP_GETS(self->window, wm_icon_name, locale, &data)) {
1332 data = g_strdup(self->title);
1336 /* append the title count, dont display the number for the first window */
1337 if (read_title && self->title_count > 1) {
1338 char *vdata, *ndata;
1339 ndata = g_strdup_printf(" - [%u]", self->title_count);
1340 vdata = g_strconcat(data, ndata, NULL);
1346 PROP_SETS(self->window, net_wm_visible_icon_name, data);
1348 self->icon_title = data;
1351 void client_update_class(ObClient *self)
1356 if (self->name) g_free(self->name);
1357 if (self->class) g_free(self->class);
1358 if (self->role) g_free(self->role);
1360 self->name = self->class = self->role = NULL;
1362 if (PROP_GETSS(self->window, wm_class, locale, &data)) {
1364 self->name = g_strdup(data[0]);
1366 self->class = g_strdup(data[1]);
1371 if (PROP_GETS(self->window, wm_window_role, locale, &s))
1372 self->role = g_strdup(s);
1374 if (self->name == NULL) self->name = g_strdup("");
1375 if (self->class == NULL) self->class = g_strdup("");
1376 if (self->role == NULL) self->role = g_strdup("");
1379 void client_update_strut(ObClient *self)
1384 if (!PROP_GETA32(self->window, net_wm_strut, cardinal, &data, &num)) {
1385 STRUT_SET(self->strut, 0, 0, 0, 0);
1388 STRUT_SET(self->strut, data[0], data[2], data[1], data[3]);
1390 STRUT_SET(self->strut, 0, 0, 0, 0);
1394 /* updating here is pointless while we're being mapped cuz we're not in
1395 the client list yet */
1397 screen_update_areas();
1400 void client_update_icons(ObClient *self)
1406 for (i = 0; i < self->nicons; ++i)
1407 g_free(self->icons[i].data);
1408 if (self->nicons > 0)
1409 g_free(self->icons);
1412 if (PROP_GETA32(self->window, net_wm_icon, cardinal, &data, &num)) {
1413 /* figure out how many valid icons are in here */
1415 while (num - i > 2) {
1419 if (i > num || w*h == 0) break;
1423 self->icons = g_new(ObClientIcon, self->nicons);
1425 /* store the icons */
1427 for (j = 0; j < self->nicons; ++j) {
1430 w = self->icons[j].width = data[i++];
1431 h = self->icons[j].height = data[i++];
1433 if (w*h == 0) continue;
1435 self->icons[j].data = g_new(RrPixel32, w * h);
1436 for (x = 0, y = 0, t = 0; t < w * h; ++t, ++x, ++i) {
1441 self->icons[j].data[t] =
1442 (((data[i] >> 24) & 0xff) << RrDefaultAlphaOffset) +
1443 (((data[i] >> 16) & 0xff) << RrDefaultRedOffset) +
1444 (((data[i] >> 8) & 0xff) << RrDefaultGreenOffset) +
1445 (((data[i] >> 0) & 0xff) << RrDefaultBlueOffset);
1451 } else if (PROP_GETA32(self->window, kwm_win_icon,
1452 kwm_win_icon, &data, &num)) {
1455 self->icons = g_new(ObClientIcon, self->nicons);
1456 xerror_set_ignore(TRUE);
1457 if (!RrPixmapToRGBA(ob_rr_inst,
1459 &self->icons[self->nicons-1].width,
1460 &self->icons[self->nicons-1].height,
1461 &self->icons[self->nicons-1].data)) {
1462 g_free(&self->icons[self->nicons-1]);
1465 xerror_set_ignore(FALSE);
1471 if ((hints = XGetWMHints(ob_display, self->window))) {
1472 if (hints->flags & IconPixmapHint) {
1474 self->icons = g_new(ObClientIcon, self->nicons);
1475 xerror_set_ignore(TRUE);
1476 if (!RrPixmapToRGBA(ob_rr_inst,
1478 (hints->flags & IconMaskHint ?
1479 hints->icon_mask : None),
1480 &self->icons[self->nicons-1].width,
1481 &self->icons[self->nicons-1].height,
1482 &self->icons[self->nicons-1].data)){
1483 g_free(&self->icons[self->nicons-1]);
1486 xerror_set_ignore(FALSE);
1493 frame_adjust_icon(self->frame);
1496 static void client_change_state(ObClient *self)
1499 guint32 netstate[10];
1502 state[0] = self->wmstate;
1504 PROP_SETA32(self->window, wm_state, wm_state, state, 2);
1508 netstate[num++] = prop_atoms.net_wm_state_modal;
1510 netstate[num++] = prop_atoms.net_wm_state_shaded;
1512 netstate[num++] = prop_atoms.net_wm_state_hidden;
1513 if (self->skip_taskbar)
1514 netstate[num++] = prop_atoms.net_wm_state_skip_taskbar;
1515 if (self->skip_pager)
1516 netstate[num++] = prop_atoms.net_wm_state_skip_pager;
1517 if (self->fullscreen)
1518 netstate[num++] = prop_atoms.net_wm_state_fullscreen;
1520 netstate[num++] = prop_atoms.net_wm_state_maximized_vert;
1522 netstate[num++] = prop_atoms.net_wm_state_maximized_horz;
1524 netstate[num++] = prop_atoms.net_wm_state_above;
1526 netstate[num++] = prop_atoms.net_wm_state_below;
1527 PROP_SETA32(self->window, net_wm_state, atom, netstate, num);
1529 client_calc_layer(self);
1532 frame_adjust_state(self->frame);
1535 ObClient *client_search_focus_tree(ObClient *self)
1540 for (it = self->transients; it != NULL; it = it->next) {
1541 if (client_focused(it->data)) return it->data;
1542 if ((ret = client_search_focus_tree(it->data))) return ret;
1547 ObClient *client_search_focus_tree_full(ObClient *self)
1549 if (self->transient_for) {
1550 if (self->transient_for != OB_TRAN_GROUP) {
1551 return client_search_focus_tree_full(self->transient_for);
1554 gboolean recursed = FALSE;
1556 for (it = self->group->members; it; it = it->next)
1557 if (!((ObClient*)it->data)->transient_for) {
1559 if ((c = client_search_focus_tree_full(it->data)))
1568 /* this function checks the whole tree, the client_search_focus_tree~
1569 does not, so we need to check this window */
1570 if (client_focused(self))
1572 return client_search_focus_tree(self);
1575 static ObStackingLayer calc_layer(ObClient *self)
1579 if (self->fullscreen) l = OB_STACKING_LAYER_FULLSCREEN;
1580 else if (self->type == OB_CLIENT_TYPE_DESKTOP)
1581 l = OB_STACKING_LAYER_DESKTOP;
1582 else if (self->type == OB_CLIENT_TYPE_DOCK) {
1583 if (!self->below) l = OB_STACKING_LAYER_TOP;
1584 else l = OB_STACKING_LAYER_NORMAL;
1586 else if (self->above) l = OB_STACKING_LAYER_ABOVE;
1587 else if (self->below) l = OB_STACKING_LAYER_BELOW;
1588 else l = OB_STACKING_LAYER_NORMAL;
1593 static void client_calc_layer_recursive(ObClient *self, ObClient *orig,
1594 ObStackingLayer l, gboolean raised)
1596 ObStackingLayer old, own;
1600 own = calc_layer(self);
1601 self->layer = l > own ? l : own;
1603 for (it = self->transients; it; it = it->next)
1604 client_calc_layer_recursive(it->data, orig,
1605 l, raised ? raised : l != old);
1607 if (!raised && l != old)
1608 if (orig->frame) { /* only restack if the original window is managed */
1609 /* XXX add_non_intrusive ever? */
1610 stacking_remove(CLIENT_AS_WINDOW(self));
1611 stacking_add(CLIENT_AS_WINDOW(self));
1615 void client_calc_layer(ObClient *self)
1622 /* transients take on the layer of their parents */
1623 self = client_search_top_transient(self);
1625 l = calc_layer(self);
1627 client_calc_layer_recursive(self, orig, l, FALSE);
1630 gboolean client_should_show(ObClient *self)
1632 if (self->iconic) return FALSE;
1633 else if (!(self->desktop == screen_desktop ||
1634 self->desktop == DESKTOP_ALL)) return FALSE;
1635 else if (client_normal(self) && screen_showing_desktop) return FALSE;
1640 static void client_showhide(ObClient *self)
1643 if (client_should_show(self))
1644 frame_show(self->frame);
1646 frame_hide(self->frame);
1649 gboolean client_normal(ObClient *self) {
1650 return ! (self->type == OB_CLIENT_TYPE_DESKTOP ||
1651 self->type == OB_CLIENT_TYPE_DOCK ||
1652 self->type == OB_CLIENT_TYPE_SPLASH);
1655 static void client_apply_startup_state(ObClient *self)
1657 /* these are in a carefully crafted order.. */
1660 self->iconic = FALSE;
1661 client_iconify(self, TRUE, FALSE);
1663 if (self->fullscreen) {
1664 self->fullscreen = FALSE;
1665 client_fullscreen(self, TRUE, FALSE);
1668 self->shaded = FALSE;
1669 client_shade(self, TRUE);
1672 dispatch_client(Event_Client_Urgent, self, self->urgent, 0);
1674 if (self->max_vert && self->max_horz) {
1675 self->max_vert = self->max_horz = FALSE;
1676 client_maximize(self, TRUE, 0, FALSE);
1677 } else if (self->max_vert) {
1678 self->max_vert = FALSE;
1679 client_maximize(self, TRUE, 2, FALSE);
1680 } else if (self->max_horz) {
1681 self->max_horz = FALSE;
1682 client_maximize(self, TRUE, 1, FALSE);
1685 /* nothing to do for the other states:
1694 void client_configure_full(ObClient *self, ObCorner anchor,
1695 int x, int y, int w, int h,
1696 gboolean user, gboolean final,
1697 gboolean force_reply)
1699 gboolean moved = FALSE, resized = FALSE;
1701 /* gets the frame's position */
1702 frame_client_gravity(self->frame, &x, &y);
1704 /* these positions are frame positions, not client positions */
1706 /* set the size and position if fullscreen */
1707 if (self->fullscreen) {
1710 XF86VidModeModeLine mode;
1715 i = client_monitor(self);
1716 a = screen_physical_area_monitor(i);
1719 if (i == 0 && /* primary head */
1720 extensions_vidmode &&
1721 XF86VidModeGetViewPort(ob_display, ob_screen, &x, &y) &&
1722 /* get the mode last so the mode.privsize isnt freed incorrectly */
1723 XF86VidModeGetModeLine(ob_display, ob_screen, &dot, &mode)) {
1728 if (mode.privsize) XFree(mode.private);
1738 user = FALSE; /* ignore that increment etc shit when in fullscreen */
1742 a = screen_area_monitor(self->desktop, client_monitor(self));
1744 /* set the size and position if maximized */
1745 if (self->max_horz) {
1746 x = a->x - self->frame->size.left;
1749 if (self->max_vert) {
1751 h = a->height - self->frame->size.top - self->frame->size.bottom;
1755 /* gets the client's position */
1756 frame_frame_gravity(self->frame, &x, &y);
1758 /* these override the above states! if you cant move you can't move! */
1760 if (!(self->functions & OB_CLIENT_FUNC_MOVE)) {
1764 if (!(self->functions & OB_CLIENT_FUNC_RESIZE)) {
1765 w = self->area.width;
1766 h = self->area.height;
1770 if (!(w == self->area.width && h == self->area.height)) {
1771 int basew, baseh, minw, minh;
1773 /* base size is substituted with min size if not specified */
1774 if (self->base_size.width || self->base_size.height) {
1775 basew = self->base_size.width;
1776 baseh = self->base_size.height;
1778 basew = self->min_size.width;
1779 baseh = self->min_size.height;
1781 /* min size is substituted with base size if not specified */
1782 if (self->min_size.width || self->min_size.height) {
1783 minw = self->min_size.width;
1784 minh = self->min_size.height;
1786 minw = self->base_size.width;
1787 minh = self->base_size.height;
1791 /* for interactive resizing. have to move half an increment in each
1794 /* how far we are towards the next size inc */
1795 int mw = (w - basew) % self->size_inc.width;
1796 int mh = (h - baseh) % self->size_inc.height;
1798 int aw = self->size_inc.width / 2;
1799 int ah = self->size_inc.height / 2;
1800 /* don't let us move into a new size increment */
1801 if (mw + aw >= self->size_inc.width)
1802 aw = self->size_inc.width - mw - 1;
1803 if (mh + ah >= self->size_inc.height)
1804 ah = self->size_inc.height - mh - 1;
1808 /* if this is a user-requested resize, then check against min/max
1811 /* smaller than min size or bigger than max size? */
1812 if (w > self->max_size.width) w = self->max_size.width;
1813 if (w < minw) w = minw;
1814 if (h > self->max_size.height) h = self->max_size.height;
1815 if (h < minh) h = minh;
1821 /* keep to the increments */
1822 w /= self->size_inc.width;
1823 h /= self->size_inc.height;
1825 /* you cannot resize to nothing */
1826 if (basew + w < 1) w = 1 - basew;
1827 if (baseh + h < 1) h = 1 - baseh;
1829 /* store the logical size */
1830 SIZE_SET(self->logical_size,
1831 self->size_inc.width > 1 ? w : w + basew,
1832 self->size_inc.height > 1 ? h : h + baseh);
1834 w *= self->size_inc.width;
1835 h *= self->size_inc.height;
1841 /* adjust the height to match the width for the aspect ratios.
1842 for this, min size is not substituted for base size ever. */
1843 w -= self->base_size.width;
1844 h -= self->base_size.height;
1846 if (self->min_ratio)
1847 if (h * self->min_ratio > w) h = (int)(w / self->min_ratio);
1848 if (self->max_ratio)
1849 if (h * self->max_ratio < w) h = (int)(w / self->max_ratio);
1851 w += self->base_size.width;
1852 h += self->base_size.height;
1857 case OB_CORNER_TOPLEFT:
1859 case OB_CORNER_TOPRIGHT:
1860 x -= w - self->area.width;
1862 case OB_CORNER_BOTTOMLEFT:
1863 y -= h - self->area.height;
1865 case OB_CORNER_BOTTOMRIGHT:
1866 x -= w - self->area.width;
1867 y -= h - self->area.height;
1871 moved = x != self->area.x || y != self->area.y;
1872 resized = w != self->area.width || h != self->area.height;
1874 RECT_SET(self->area, x, y, w, h);
1876 /* for app-requested resizes, always resize if 'resized' is true.
1877 for user-requested ones, only resize if final is true, or when
1878 resizing in opaque mode */
1879 if ((!user && resized) ||
1880 (user && (final || (resized && config_opaque_resize))))
1881 XResizeWindow(ob_display, self->window, w, h);
1883 /* move/resize the frame to match the request */
1885 if (self->decorations != self->frame->decorations)
1886 moved = resized = TRUE;
1888 if (moved || resized)
1889 frame_adjust_area(self->frame, moved, resized);
1891 if (!resized && (force_reply || ((!user && moved) || (user && final))))
1894 event.type = ConfigureNotify;
1895 event.xconfigure.display = ob_display;
1896 event.xconfigure.event = self->window;
1897 event.xconfigure.window = self->window;
1899 /* root window real coords */
1900 event.xconfigure.x = self->frame->area.x + self->frame->size.left -
1902 event.xconfigure.y = self->frame->area.y + self->frame->size.top -
1904 event.xconfigure.width = w;
1905 event.xconfigure.height = h;
1906 event.xconfigure.border_width = 0;
1907 event.xconfigure.above = self->frame->plate;
1908 event.xconfigure.override_redirect = FALSE;
1909 XSendEvent(event.xconfigure.display, event.xconfigure.window,
1910 FALSE, StructureNotifyMask, &event);
1915 void client_fullscreen(ObClient *self, gboolean fs, gboolean savearea)
1919 if (!(self->functions & OB_CLIENT_FUNC_FULLSCREEN) || /* can't */
1920 self->fullscreen == fs) return; /* already done */
1922 self->fullscreen = fs;
1923 client_change_state(self); /* change the state hints on the client,
1924 and adjust out layer/stacking */
1928 guint32 dimensions[4];
1929 dimensions[0] = self->area.x;
1930 dimensions[1] = self->area.y;
1931 dimensions[2] = self->area.width;
1932 dimensions[3] = self->area.height;
1934 PROP_SETA32(self->window, openbox_premax, cardinal,
1938 /* these are not actually used cuz client_configure will set them
1939 as appropriate when the window is fullscreened */
1946 /* pick some fallbacks... */
1947 a = screen_area_monitor(self->desktop, 0);
1948 x = a->x + a->width / 4;
1949 y = a->y + a->height / 4;
1953 if (PROP_GETA32(self->window, openbox_premax, cardinal,
1954 (guint32**)&dimensions, &num)) {
1965 client_setup_decor_and_functions(self);
1967 client_configure(self, OB_CORNER_TOPLEFT, x, y, w, h, TRUE, TRUE);
1969 /* try focus us when we go into fullscreen mode */
1973 static void client_iconify_recursive(ObClient *self,
1974 gboolean iconic, gboolean curdesk)
1977 gboolean changed = FALSE;
1980 if (self->iconic != iconic) {
1981 ob_debug("%sconifying window: 0x%lx\n", (iconic ? "I" : "Uni"),
1984 self->iconic = iconic;
1987 if (self->functions & OB_CLIENT_FUNC_ICONIFY) {
1988 self->wmstate = IconicState;
1989 self->ignore_unmaps++;
1990 /* we unmap the client itself so that we can get MapRequest
1991 events, and because the ICCCM tells us to! */
1992 XUnmapWindow(ob_display, self->window);
1994 /* update the focus lists.. iconic windows go to the bottom of
1995 the list, put the new iconic window at the 'top of the
1997 focus_order_to_top(self);
2003 client_set_desktop(self, screen_desktop, FALSE);
2004 self->wmstate = self->shaded ? IconicState : NormalState;
2005 XMapWindow(ob_display, self->window);
2007 /* this puts it after the current focused window */
2008 focus_order_remove(self);
2009 focus_order_add_new(self);
2011 /* this is here cuz with the VIDMODE extension, the viewport can
2012 change while a fullscreen window is iconic, and when it
2013 uniconifies, it would be nice if it did so to the new position
2015 client_reconfigure(self);
2022 client_change_state(self);
2023 client_showhide(self);
2024 screen_update_areas();
2026 dispatch_client(iconic ? Event_Client_Unmapped : Event_Client_Mapped,
2030 /* iconify all transients */
2031 for (it = self->transients; it != NULL; it = it->next)
2032 if (it->data != self) client_iconify_recursive(it->data,
2036 void client_iconify(ObClient *self, gboolean iconic, gboolean curdesk)
2038 /* move up the transient chain as far as possible first */
2039 self = client_search_top_transient(self);
2041 client_iconify_recursive(client_search_top_transient(self),
2045 void client_maximize(ObClient *self, gboolean max, int dir, gboolean savearea)
2049 g_assert(dir == 0 || dir == 1 || dir == 2);
2050 if (!(self->functions & OB_CLIENT_FUNC_MAXIMIZE)) return; /* can't */
2052 /* check if already done */
2054 if (dir == 0 && self->max_horz && self->max_vert) return;
2055 if (dir == 1 && self->max_horz) return;
2056 if (dir == 2 && self->max_vert) return;
2058 if (dir == 0 && !self->max_horz && !self->max_vert) return;
2059 if (dir == 1 && !self->max_horz) return;
2060 if (dir == 2 && !self->max_vert) return;
2063 /* work with the frame's coords */
2064 x = self->frame->area.x;
2065 y = self->frame->area.y;
2066 w = self->area.width;
2067 h = self->area.height;
2071 gint32 dimensions[4];
2080 /* get the property off the window and use it for the dimensions
2081 we are already maxed on */
2082 if (PROP_GETA32(self->window, openbox_premax, cardinal,
2083 (guint32**)&readdim, &num)) {
2085 if (self->max_horz) {
2086 dimensions[0] = readdim[0];
2087 dimensions[2] = readdim[2];
2089 if (self->max_vert) {
2090 dimensions[1] = readdim[1];
2091 dimensions[3] = readdim[3];
2097 PROP_SETA32(self->window, openbox_premax, cardinal,
2098 (guint32*)dimensions, 4);
2105 /* pick some fallbacks... */
2106 a = screen_area_monitor(self->desktop, 0);
2107 if (dir == 0 || dir == 1) { /* horz */
2108 x = a->x + a->width / 4;
2111 if (dir == 0 || dir == 2) { /* vert */
2112 y = a->y + a->height / 4;
2116 if (PROP_GETA32(self->window, openbox_premax, cardinal,
2117 (guint32**)&dimensions, &num)) {
2119 if (dir == 0 || dir == 1) { /* horz */
2123 if (dir == 0 || dir == 2) { /* vert */
2132 if (dir == 0 || dir == 1) /* horz */
2133 self->max_horz = max;
2134 if (dir == 0 || dir == 2) /* vert */
2135 self->max_vert = max;
2137 if (!self->max_horz && !self->max_vert)
2138 PROP_ERASE(self->window, openbox_premax);
2140 client_change_state(self); /* change the state hints on the client */
2142 /* figure out where the client should be going */
2143 frame_frame_gravity(self->frame, &x, &y);
2144 client_configure(self, OB_CORNER_TOPLEFT, x, y, w, h, TRUE, TRUE);
2147 void client_shade(ObClient *self, gboolean shade)
2149 if ((!(self->functions & OB_CLIENT_FUNC_SHADE) &&
2150 shade) || /* can't shade */
2151 self->shaded == shade) return; /* already done */
2153 /* when we're iconic, don't change the wmstate */
2155 self->wmstate = shade ? IconicState : NormalState;
2156 self->shaded = shade;
2157 client_change_state(self);
2158 /* resize the frame to just the titlebar */
2159 frame_adjust_area(self->frame, FALSE, FALSE);
2162 void client_close(ObClient *self)
2166 if (!(self->functions & OB_CLIENT_FUNC_CLOSE)) return;
2169 XXX: itd be cool to do timeouts and shit here for killing the client's
2171 like... if the window is around after 5 seconds, then the close button
2172 turns a nice red, and if this function is called again, the client is
2176 ce.xclient.type = ClientMessage;
2177 ce.xclient.message_type = prop_atoms.wm_protocols;
2178 ce.xclient.display = ob_display;
2179 ce.xclient.window = self->window;
2180 ce.xclient.format = 32;
2181 ce.xclient.data.l[0] = prop_atoms.wm_delete_window;
2182 ce.xclient.data.l[1] = event_lasttime;
2183 ce.xclient.data.l[2] = 0l;
2184 ce.xclient.data.l[3] = 0l;
2185 ce.xclient.data.l[4] = 0l;
2186 XSendEvent(ob_display, self->window, FALSE, NoEventMask, &ce);
2189 void client_kill(ObClient *self)
2191 XKillClient(ob_display, self->window);
2194 void client_set_desktop_recursive(ObClient *self,
2195 guint target, gboolean donthide)
2200 if (target != self->desktop) {
2202 ob_debug("Setting desktop %u\n", target+1);
2204 g_assert(target < screen_num_desktops || target == DESKTOP_ALL);
2206 /* remove from the old desktop(s) */
2207 focus_order_remove(self);
2209 old = self->desktop;
2210 self->desktop = target;
2211 PROP_SET32(self->window, net_wm_desktop, cardinal, target);
2212 /* the frame can display the current desktop state */
2213 frame_adjust_state(self->frame);
2214 /* 'move' the window to the new desktop */
2216 client_showhide(self);
2217 /* raise if it was not already on the desktop */
2218 if (old != DESKTOP_ALL)
2219 stacking_raise(CLIENT_AS_WINDOW(self));
2220 screen_update_areas();
2222 /* add to the new desktop(s) */
2223 if (config_focus_new)
2224 focus_order_to_top(self);
2226 focus_order_to_bottom(self);
2228 dispatch_client(Event_Client_Desktop, self, target, old);
2231 /* move all transients */
2232 for (it = self->transients; it != NULL; it = it->next)
2233 if (it->data != self) client_set_desktop_recursive(it->data,
2237 void client_set_desktop(ObClient *self, guint target, gboolean donthide)
2239 client_set_desktop_recursive(client_search_top_transient(self),
2243 ObClient *client_search_modal_child(ObClient *self)
2248 for (it = self->transients; it != NULL; it = it->next) {
2249 ObClient *c = it->data;
2250 if ((ret = client_search_modal_child(c))) return ret;
2251 if (c->modal) return c;
2256 gboolean client_validate(ObClient *self)
2260 XSync(ob_display, FALSE); /* get all events on the server */
2262 if (XCheckTypedWindowEvent(ob_display, self->window, DestroyNotify, &e) ||
2263 XCheckTypedWindowEvent(ob_display, self->window, UnmapNotify, &e)) {
2264 XPutBackEvent(ob_display, &e);
2271 void client_set_wm_state(ObClient *self, long state)
2273 if (state == self->wmstate) return; /* no change */
2277 client_iconify(self, TRUE, TRUE);
2280 client_iconify(self, FALSE, TRUE);
2285 void client_set_state(ObClient *self, Atom action, long data1, long data2)
2287 gboolean shaded = self->shaded;
2288 gboolean fullscreen = self->fullscreen;
2289 gboolean max_horz = self->max_horz;
2290 gboolean max_vert = self->max_vert;
2293 if (!(action == prop_atoms.net_wm_state_add ||
2294 action == prop_atoms.net_wm_state_remove ||
2295 action == prop_atoms.net_wm_state_toggle))
2296 /* an invalid action was passed to the client message, ignore it */
2299 for (i = 0; i < 2; ++i) {
2300 Atom state = i == 0 ? data1 : data2;
2302 if (!state) continue;
2304 /* if toggling, then pick whether we're adding or removing */
2305 if (action == prop_atoms.net_wm_state_toggle) {
2306 if (state == prop_atoms.net_wm_state_modal)
2307 action = self->modal ? prop_atoms.net_wm_state_remove :
2308 prop_atoms.net_wm_state_add;
2309 else if (state == prop_atoms.net_wm_state_maximized_vert)
2310 action = self->max_vert ? prop_atoms.net_wm_state_remove :
2311 prop_atoms.net_wm_state_add;
2312 else if (state == prop_atoms.net_wm_state_maximized_horz)
2313 action = self->max_horz ? prop_atoms.net_wm_state_remove :
2314 prop_atoms.net_wm_state_add;
2315 else if (state == prop_atoms.net_wm_state_shaded)
2316 action = self->shaded ? prop_atoms.net_wm_state_remove :
2317 prop_atoms.net_wm_state_add;
2318 else if (state == prop_atoms.net_wm_state_skip_taskbar)
2319 action = self->skip_taskbar ?
2320 prop_atoms.net_wm_state_remove :
2321 prop_atoms.net_wm_state_add;
2322 else if (state == prop_atoms.net_wm_state_skip_pager)
2323 action = self->skip_pager ?
2324 prop_atoms.net_wm_state_remove :
2325 prop_atoms.net_wm_state_add;
2326 else if (state == prop_atoms.net_wm_state_fullscreen)
2327 action = self->fullscreen ?
2328 prop_atoms.net_wm_state_remove :
2329 prop_atoms.net_wm_state_add;
2330 else if (state == prop_atoms.net_wm_state_above)
2331 action = self->above ? prop_atoms.net_wm_state_remove :
2332 prop_atoms.net_wm_state_add;
2333 else if (state == prop_atoms.net_wm_state_below)
2334 action = self->below ? prop_atoms.net_wm_state_remove :
2335 prop_atoms.net_wm_state_add;
2338 if (action == prop_atoms.net_wm_state_add) {
2339 if (state == prop_atoms.net_wm_state_modal) {
2340 /* XXX raise here or something? */
2342 } else if (state == prop_atoms.net_wm_state_maximized_vert) {
2344 } else if (state == prop_atoms.net_wm_state_maximized_horz) {
2346 } else if (state == prop_atoms.net_wm_state_shaded) {
2348 } else if (state == prop_atoms.net_wm_state_skip_taskbar) {
2349 self->skip_taskbar = TRUE;
2350 } else if (state == prop_atoms.net_wm_state_skip_pager) {
2351 self->skip_pager = TRUE;
2352 } else if (state == prop_atoms.net_wm_state_fullscreen) {
2354 } else if (state == prop_atoms.net_wm_state_above) {
2356 } else if (state == prop_atoms.net_wm_state_below) {
2360 } else { /* action == prop_atoms.net_wm_state_remove */
2361 if (state == prop_atoms.net_wm_state_modal) {
2362 self->modal = FALSE;
2363 } else if (state == prop_atoms.net_wm_state_maximized_vert) {
2365 } else if (state == prop_atoms.net_wm_state_maximized_horz) {
2367 } else if (state == prop_atoms.net_wm_state_shaded) {
2369 } else if (state == prop_atoms.net_wm_state_skip_taskbar) {
2370 self->skip_taskbar = FALSE;
2371 } else if (state == prop_atoms.net_wm_state_skip_pager) {
2372 self->skip_pager = FALSE;
2373 } else if (state == prop_atoms.net_wm_state_fullscreen) {
2375 } else if (state == prop_atoms.net_wm_state_above) {
2376 self->above = FALSE;
2377 } else if (state == prop_atoms.net_wm_state_below) {
2378 self->below = FALSE;
2382 if (max_horz != self->max_horz || max_vert != self->max_vert) {
2383 if (max_horz != self->max_horz && max_vert != self->max_vert) {
2385 if (max_horz == max_vert) { /* both going the same way */
2386 client_maximize(self, max_horz, 0, TRUE);
2388 client_maximize(self, max_horz, 1, TRUE);
2389 client_maximize(self, max_vert, 2, TRUE);
2393 if (max_horz != self->max_horz)
2394 client_maximize(self, max_horz, 1, TRUE);
2396 client_maximize(self, max_vert, 2, TRUE);
2399 /* change fullscreen state before shading, as it will affect if the window
2401 if (fullscreen != self->fullscreen)
2402 client_fullscreen(self, fullscreen, TRUE);
2403 if (shaded != self->shaded)
2404 client_shade(self, shaded);
2405 client_calc_layer(self);
2406 client_change_state(self); /* change the hint to reflect these changes */
2409 ObClient *client_focus_target(ObClient *self)
2413 /* if we have a modal child, then focus it, not us */
2414 child = client_search_modal_child(self);
2415 if (child) return child;
2419 gboolean client_can_focus(ObClient *self)
2423 /* choose the correct target */
2424 self = client_focus_target(self);
2426 if (!self->frame->visible)
2429 if (!((self->can_focus || self->focus_notify) &&
2430 (self->desktop == screen_desktop ||
2431 self->desktop == DESKTOP_ALL) &&
2435 /* do a check to see if the window has already been unmapped or destroyed
2436 do this intelligently while watching out for unmaps we've generated
2437 (ignore_unmaps > 0) */
2438 if (XCheckTypedWindowEvent(ob_display, self->window,
2439 DestroyNotify, &ev)) {
2440 XPutBackEvent(ob_display, &ev);
2443 while (XCheckTypedWindowEvent(ob_display, self->window,
2444 UnmapNotify, &ev)) {
2445 if (self->ignore_unmaps) {
2446 self->ignore_unmaps--;
2448 XPutBackEvent(ob_display, &ev);
2456 gboolean client_focus(ObClient *self)
2458 /* choose the correct target */
2459 self = client_focus_target(self);
2461 if (!client_can_focus(self)) {
2462 if (!self->frame->visible) {
2463 /* update the focus lists */
2464 focus_order_to_top(self);
2469 if (self->can_focus)
2470 /* RevertToPointerRoot causes much more headache than RevertToNone, so
2471 I choose to use it always, hopefully to find errors quicker, if any
2472 are left. (I hate X. I hate focus events.) */
2473 XSetInputFocus(ob_display, self->window, RevertToPointerRoot,
2476 if (self->focus_notify) {
2478 ce.xclient.type = ClientMessage;
2479 ce.xclient.message_type = prop_atoms.wm_protocols;
2480 ce.xclient.display = ob_display;
2481 ce.xclient.window = self->window;
2482 ce.xclient.format = 32;
2483 ce.xclient.data.l[0] = prop_atoms.wm_take_focus;
2484 ce.xclient.data.l[1] = event_lasttime;
2485 ce.xclient.data.l[2] = 0l;
2486 ce.xclient.data.l[3] = 0l;
2487 ce.xclient.data.l[4] = 0l;
2488 XSendEvent(ob_display, self->window, FALSE, NoEventMask, &ce);
2492 ob_debug("%sively focusing %lx at %d\n",
2493 (self->can_focus ? "act" : "pass"),
2494 self->window, (int) event_lasttime);
2497 /* Cause the FocusIn to come back to us. Important for desktop switches,
2498 since otherwise we'll have no FocusIn on the queue and send it off to
2499 the focus_backup. */
2500 XSync(ob_display, FALSE);
2504 void client_unfocus(ObClient *self)
2506 g_assert(focus_client == self);
2508 ob_debug("client_unfocus for %lx\n", self->window);
2510 focus_fallback(OB_FOCUS_FALLBACK_UNFOCUSING);
2513 void client_activate(ObClient *self)
2515 if (client_normal(self) && screen_showing_desktop)
2516 screen_show_desktop(FALSE);
2518 client_iconify(self, FALSE, FALSE);
2519 if (self->desktop != DESKTOP_ALL &&
2520 self->desktop != screen_desktop)
2521 screen_set_desktop(self->desktop);
2522 else if (!self->frame->visible)
2523 /* if its not visible for other reasons, then don't mess
2527 client_shade(self, FALSE);
2529 stacking_raise(CLIENT_AS_WINDOW(self));
2532 gboolean client_focused(ObClient *self)
2534 return self == focus_client;
2537 ObClientIcon *client_icon(ObClient *self, int w, int h)
2540 /* si is the smallest image >= req */
2541 /* li is the largest image < req */
2542 unsigned long size, smallest = 0xffffffff, largest = 0, si = 0, li = 0;
2544 if (!self->nicons) return NULL;
2546 for (i = 0; i < self->nicons; ++i) {
2547 size = self->icons[i].width * self->icons[i].height;
2548 if (size < smallest && size >= (unsigned)(w * h)) {
2552 if (size > largest && size <= (unsigned)(w * h)) {
2557 if (largest == 0) /* didnt find one smaller than the requested size */
2558 return &self->icons[si];
2559 return &self->icons[li];
2562 /* this be mostly ripped from fvwm */
2563 ObClient *client_find_directional(ObClient *c, ObDirection dir)
2565 int my_cx, my_cy, his_cx, his_cy;
2568 int score, best_score;
2569 ObClient *best_client, *cur;
2575 /* first, find the centre coords of the currently focused window */
2576 my_cx = c->frame->area.x + c->frame->area.width / 2;
2577 my_cy = c->frame->area.y + c->frame->area.height / 2;
2582 for(it = g_list_first(client_list); it; it = it->next) {
2585 /* the currently selected window isn't interesting */
2588 if (!client_normal(cur))
2590 if(c->desktop != cur->desktop && cur->desktop != DESKTOP_ALL)
2594 if(client_focus_target(cur) == cur &&
2595 !(cur->can_focus || cur->focus_notify))
2598 /* find the centre coords of this window, from the
2599 * currently focused window's point of view */
2600 his_cx = (cur->frame->area.x - my_cx)
2601 + cur->frame->area.width / 2;
2602 his_cy = (cur->frame->area.y - my_cy)
2603 + cur->frame->area.height / 2;
2607 /* Rotate the diagonals 45 degrees counterclockwise.
2608 * To do this, multiply the matrix /+h +h\ with the
2609 * vector (x y). \-h +h/
2610 * h = sqrt(0.5). We can set h := 1 since absolute
2611 * distance doesn't matter here. */
2612 tx = his_cx + his_cy;
2613 his_cy = -his_cx + his_cy;
2618 case OB_DIRECTION_NORTH:
2619 case OB_DIRECTION_SOUTH:
2620 case OB_DIRECTION_NORTHEAST:
2621 case OB_DIRECTION_SOUTHWEST:
2622 offset = (his_cx < 0) ? -his_cx : his_cx;
2623 distance = ((dir == OB_DIRECTION_NORTH ||
2624 dir == OB_DIRECTION_NORTHEAST) ?
2627 case OB_DIRECTION_EAST:
2628 case OB_DIRECTION_WEST:
2629 case OB_DIRECTION_SOUTHEAST:
2630 case OB_DIRECTION_NORTHWEST:
2631 offset = (his_cy < 0) ? -his_cy : his_cy;
2632 distance = ((dir == OB_DIRECTION_WEST ||
2633 dir == OB_DIRECTION_NORTHWEST) ?
2638 /* the target must be in the requested direction */
2642 /* Calculate score for this window. The smaller the better. */
2643 score = distance + offset;
2645 /* windows more than 45 degrees off the direction are
2646 * heavily penalized and will only be chosen if nothing
2647 * else within a million pixels */
2648 if(offset > distance)
2651 if(best_score == -1 || score < best_score)
2659 void client_set_layer(ObClient *self, int layer)
2663 self->above = FALSE;
2664 } else if (layer == 0) {
2665 self->below = self->above = FALSE;
2667 self->below = FALSE;
2670 client_calc_layer(self);
2671 client_change_state(self); /* reflect this in the state hints */
2674 guint client_monitor(ObClient *self)
2678 for (i = 0; i < screen_num_monitors; ++i) {
2679 Rect *area = screen_physical_area_monitor(i);
2680 if (RECT_INTERSECTS_RECT(*area, self->frame->area))
2683 if (i == screen_num_monitors) i = 0;
2684 g_assert(i < screen_num_monitors);
2688 ObClient *client_search_top_transient(ObClient *self)
2690 /* move up the transient chain as far as possible */
2691 if (self->transient_for) {
2692 if (self->transient_for != OB_TRAN_GROUP) {
2693 return client_search_top_transient(self->transient_for);
2697 for (it = self->group->members; it; it = it->next) {
2698 ObClient *c = it->data;
2700 /* checking transient_for prevents infinate loops! */
2701 if (c != self && !c->transient_for)
2712 ObClient *client_search_transient(ObClient *self, ObClient *search)
2716 for (sit = self->transients; sit; sit = g_slist_next(sit)) {
2717 if (sit->data == search)
2719 if (client_search_transient(sit->data, search))
2725 gchar* client_get_sm_client_id(ObClient *self)
2729 if (!PROP_GETS(self->window, sm_client_id, locale, &id) && self->group)
2730 PROP_GETS(self->group->leader, sm_client_id, locale, &id);