7 #include "moveresize.h"
9 #include "extensions.h"
23 #include "render/render.h"
26 #include <X11/Xutil.h>
28 /*! The event mask to grab on client windows */
29 #define CLIENT_EVENTMASK (PropertyChangeMask | FocusChangeMask | \
32 #define CLIENT_NOPROPAGATEMASK (ButtonPressMask | ButtonReleaseMask | \
35 GList *client_list = NULL;
37 static void client_get_all(ObClient *self);
38 static void client_toggle_border(ObClient *self, gboolean show);
39 static void client_get_area(ObClient *self);
40 static void client_get_desktop(ObClient *self);
41 static void client_get_state(ObClient *self);
42 static void client_get_shaped(ObClient *self);
43 static void client_get_mwm_hints(ObClient *self);
44 static void client_get_gravity(ObClient *self);
45 static void client_showhide(ObClient *self);
46 static void client_change_allowed_actions(ObClient *self);
47 static void client_change_state(ObClient *self);
48 static void client_apply_startup_state(ObClient *self);
49 static void client_restore_session_state(ObClient *self);
56 void client_shutdown()
60 void client_set_list()
62 Window *windows, *win_it;
64 guint size = g_list_length(client_list);
66 /* create an array of the window ids */
68 windows = g_new(Window, size);
70 for (it = client_list; it != NULL; it = it->next, ++win_it)
71 *win_it = ((ObClient*)it->data)->window;
75 PROP_SETA32(RootWindow(ob_display, ob_screen),
76 net_client_list, window, (guint32*)windows, size);
85 void client_foreach_transient(ObClient *self, ObClientForeachFunc func, void *data)
89 for (it = self->transients; it; it = it->next) {
90 if (!func(it->data, data)) return;
91 client_foreach_transient(it->data, func, data);
95 void client_foreach_ancestor(ObClient *self, ObClientForeachFunc func, void *data)
97 if (self->transient_for) {
98 if (self->transient_for != OB_TRAN_GROUP) {
99 if (!func(self->transient_for, data)) return;
100 client_foreach_ancestor(self->transient_for, func, data);
104 for (it = self->group->members; it; it = it->next)
105 if (it->data != self &&
106 !((ObClient*)it->data)->transient_for) {
107 if (!func(it->data, data)) return;
108 client_foreach_ancestor(it->data, func, data);
115 void client_manage_all()
117 unsigned int i, j, nchild;
120 XWindowAttributes attrib;
122 XQueryTree(ob_display, RootWindow(ob_display, ob_screen),
123 &w, &w, &children, &nchild);
125 /* remove all icon windows from the list */
126 for (i = 0; i < nchild; i++) {
127 if (children[i] == None) continue;
128 wmhints = XGetWMHints(ob_display, children[i]);
130 if ((wmhints->flags & IconWindowHint) &&
131 (wmhints->icon_window != children[i]))
132 for (j = 0; j < nchild; j++)
133 if (children[j] == wmhints->icon_window) {
141 for (i = 0; i < nchild; ++i) {
142 if (children[i] == None)
144 if (XGetWindowAttributes(ob_display, children[i], &attrib)) {
145 if (attrib.override_redirect) continue;
147 if (attrib.map_state != IsUnmapped)
148 client_manage(children[i]);
153 /* stack them as they were on startup!
154 why with stacking_lower? Why, because then windows who aren't in the
155 stacking list are on the top where you can see them instead of buried
157 for (i = startup_stack_size; i > 0; --i) {
160 w = startup_stack_order[i-1];
161 obw = g_hash_table_lookup(window_map, &w);
163 g_assert(WINDOW_IS_CLIENT(obw));
164 stacking_lower(CLIENT_AS_WINDOW(obw));
167 g_free(startup_stack_order);
168 startup_stack_order = NULL;
169 startup_stack_size = 0;
171 if (config_focus_new) {
174 active = g_hash_table_lookup(window_map, &startup_active);
176 g_assert(WINDOW_IS_CLIENT(active));
177 if (!client_focus(WINDOW_AS_CLIENT(active)))
178 focus_fallback(OB_FOCUS_FALLBACK_NOFOCUS);
180 focus_fallback(OB_FOCUS_FALLBACK_NOFOCUS);
184 void client_manage(Window window)
188 XWindowAttributes attrib;
189 XSetWindowAttributes attrib_set;
191 gboolean activate = FALSE;
195 /* check if it has already been unmapped by the time we started mapping
196 the grab does a sync so we don't have to here */
197 if (XCheckTypedWindowEvent(ob_display, window, DestroyNotify, &e) ||
198 XCheckTypedWindowEvent(ob_display, window, UnmapNotify, &e)) {
199 XPutBackEvent(ob_display, &e);
202 return; /* don't manage it */
205 /* make sure it isn't an override-redirect window */
206 if (!XGetWindowAttributes(ob_display, window, &attrib) ||
207 attrib.override_redirect) {
209 return; /* don't manage it */
212 /* is the window a docking app */
213 if ((wmhint = XGetWMHints(ob_display, window))) {
214 if ((wmhint->flags & StateHint) &&
215 wmhint->initial_state == WithdrawnState) {
216 dock_add(window, wmhint);
224 ob_debug("Managing window: %lx\n", window);
226 /* choose the events we want to receive on the CLIENT window */
227 attrib_set.event_mask = CLIENT_EVENTMASK;
228 attrib_set.do_not_propagate_mask = CLIENT_NOPROPAGATEMASK;
229 XChangeWindowAttributes(ob_display, window,
230 CWEventMask|CWDontPropagate, &attrib_set);
233 /* create the ObClient struct, and populate it from the hints on the
235 self = g_new(ObClient, 1);
236 self->obwin.type = Window_Client;
237 self->window = window;
239 client_get_all(self);
240 client_restore_session_state(self);
242 client_change_state(self);
244 /* remove the client's border (and adjust re gravity) */
245 client_toggle_border(self, FALSE);
247 /* specify that if we exit, the window should not be destroyed and should
248 be reparented back to root automatically */
249 XChangeSaveSet(ob_display, window, SetModeInsert);
251 /* create the decoration frame for the client window */
252 self->frame = frame_new();
254 frame_grab_client(self->frame, self);
256 client_apply_startup_state(self);
260 /* update the focus lists */
261 focus_order_add_new(self);
263 stacking_add(CLIENT_AS_WINDOW(self));
265 /* focus the new window? */
266 if (ob_state() != OB_STATE_STARTING && config_focus_new &&
267 /* note the check against Type_Normal/Dialog, not client_normal(self),
268 which would also include other types. in this case we want more
269 strict rules for focus */
270 (self->type == OB_CLIENT_TYPE_NORMAL ||
271 self->type == OB_CLIENT_TYPE_DIALOG))
273 if (self->desktop != screen_desktop) {
274 /* activate the window */
277 gboolean group_foc = FALSE;
282 for (it = self->group->members; it; it = it->next)
284 if (client_focused(it->data))
292 (!self->transient_for && (!self->group ||
293 !self->group->members->next))) ||
294 client_search_focus_tree_full(self) ||
296 !client_normal(focus_client))
298 /* activate the window */
304 dispatch_client(Event_Client_New, self, 0, 0);
306 /* make sure the window is visible */
307 client_move_onscreen(self, TRUE);
309 screen_update_areas();
311 client_showhide(self);
313 /* use client_focus instead of client_activate cuz client_activate does
314 stuff like switch desktops etc and I'm not interested in all that when
315 a window maps since its not based on an action from the user like
316 clicking a window to activate is. so keep the new window out of the way
318 if (activate) client_focus(self);
320 /* client_activate does this but we aret using it so we have to do it
322 if (screen_showing_desktop)
323 screen_show_desktop(FALSE);
325 /* add to client list/map */
326 client_list = g_list_append(client_list, self);
327 g_hash_table_insert(window_map, &self->window, self);
329 /* update the list hints */
332 keyboard_grab_for_client(self, TRUE);
333 mouse_grab_for_client(self, TRUE);
335 dispatch_client(Event_Client_Mapped, self, 0, 0);
337 ob_debug("Managed window 0x%lx (%s)\n", window, self->class);
340 void client_unmanage_all()
342 while (client_list != NULL)
343 client_unmanage(client_list->data);
346 /* called by client_unmanage() to close any menus referencing this client */
347 void client_close_menus(gpointer key, gpointer value, gpointer self)
349 if (((ObMenu *)value)->client == (ObClient *)self)
350 menu_hide((ObMenu *)value);
353 void client_unmanage(ObClient *self)
358 ob_debug("Unmanaging window: %lx (%s)\n", self->window, self->class);
360 dispatch_client(Event_Client_Destroy, self, 0, 0);
361 g_assert(self != NULL);
363 keyboard_grab_for_client(self, FALSE);
364 mouse_grab_for_client(self, FALSE);
366 /* remove the window from our save set */
367 XChangeSaveSet(ob_display, self->window, SetModeDelete);
369 /* we dont want events no more */
370 XSelectInput(ob_display, self->window, NoEventMask);
372 frame_hide(self->frame);
374 client_list = g_list_remove(client_list, self);
375 stacking_remove(self);
376 g_hash_table_remove(window_map, &self->window);
378 /* update the focus lists */
379 focus_order_remove(self);
381 /* once the client is out of the list, update the struts to remove it's
383 screen_update_areas();
385 /* tell our parent(s) that we're gone */
386 if (self->transient_for == OB_TRAN_GROUP) { /* transient of group */
389 for (it = self->group->members; it; it = it->next)
390 if (it->data != self)
391 ((ObClient*)it->data)->transients =
392 g_slist_remove(((ObClient*)it->data)->transients, self);
393 } else if (self->transient_for) { /* transient of window */
394 self->transient_for->transients =
395 g_slist_remove(self->transient_for->transients, self);
398 /* tell our transients that we're gone */
399 for (it = self->transients; it != NULL; it = it->next) {
400 if (((ObClient*)it->data)->transient_for != OB_TRAN_GROUP) {
401 ((ObClient*)it->data)->transient_for = NULL;
402 client_calc_layer(it->data);
406 if (moveresize_client == self)
407 moveresize_end(TRUE);
409 /* close any windows that are attached to this window */
410 g_hash_table_foreach(menu_hash, client_close_menus, self);
413 if (focus_client == self) {
416 /* focus the last focused window on the desktop, and ignore enter
417 events from the unmap so it doesnt mess with the focus */
418 while (XCheckTypedEvent(ob_display, EnterNotify, &e));
419 client_unfocus(self);
422 /* remove from its group */
424 group_remove(self->group, self);
428 /* dispatch the unmapped event */
429 dispatch_client(Event_Client_Unmapped, self, 0, 0);
430 g_assert(self != NULL);
432 /* give the client its border back */
433 client_toggle_border(self, TRUE);
435 /* reparent the window out of the frame, and free the frame */
436 frame_release_client(self->frame, self);
439 if (ob_state() != OB_STATE_EXITING) {
440 /* these values should not be persisted across a window
442 PROP_ERASE(self->window, net_wm_desktop);
443 PROP_ERASE(self->window, net_wm_state);
444 PROP_ERASE(self->window, wm_state);
446 /* if we're left in an iconic state, the client wont be mapped. this is
447 bad, since we will no longer be managing the window on restart */
449 XMapWindow(ob_display, self->window);
453 ob_debug("Unmanaged window 0x%lx\n", self->window);
455 /* free all data allocated in the client struct */
456 g_slist_free(self->transients);
457 for (j = 0; j < self->nicons; ++j)
458 g_free(self->icons[j].data);
459 if (self->nicons > 0)
462 g_free(self->icon_title);
468 /* update the list hints */
472 static void client_restore_session_state(ObClient *self)
476 s = session_state_find(self);
479 RECT_SET(self->area, s->x, s->y, s->w, s->h);
480 self->positioned = TRUE;
481 XResizeWindow(ob_display, self->window, s->w, s->h);
483 self->desktop = s->desktop == DESKTOP_ALL ? s->desktop :
484 MIN(screen_num_desktops - 1, s->desktop);
485 PROP_SET32(self->window, net_wm_desktop, cardinal, self->desktop);
487 self->shaded = s->shaded;
488 self->iconic = s->iconic;
489 self->skip_pager = s->skip_pager;
490 self->skip_taskbar = s->skip_taskbar;
491 self->fullscreen = s->fullscreen;
492 self->above = s->above;
493 self->below = s->below;
494 self->max_horz = s->max_horz;
495 self->max_vert = s->max_vert;
497 session_state_free(s);
500 void client_move_onscreen(ObClient *self, gboolean rude)
502 int x = self->area.x;
503 int y = self->area.y;
504 if (client_find_onscreen(self, &x, &y,
505 self->frame->area.width,
506 self->frame->area.height, rude)) {
507 client_configure(self, OB_CORNER_TOPLEFT, x, y,
508 self->area.width, self->area.height,
513 gboolean client_find_onscreen(ObClient *self, int *x, int *y, int w, int h,
517 int ox = *x, oy = *y;
519 frame_client_gravity(self->frame, x, y); /* get where the frame
522 /* XXX watch for xinerama dead areas */
524 a = screen_area(self->desktop);
525 if (!self->strut.right && *x >= a->x + a->width - 1)
526 *x = a->x + a->width - self->frame->area.width;
527 if (!self->strut.bottom && *y >= a->y + a->height - 1)
528 *y = a->y + a->height - self->frame->area.height;
529 if (!self->strut.left && *x + self->frame->area.width - 1 < a->x)
531 if (!self->strut.top && *y + self->frame->area.height - 1 < a->y)
535 /* this is my MOZILLA BITCHSLAP. oh ya it fucking feels good.
536 Java can suck it too. */
538 /* dont let windows map/move into the strut unless they
539 are bigger than the available area */
541 if (!self->strut.left && *x < a->x) *x = a->x;
542 if (!self->strut.right && *x + w > a->x + a->width)
543 *x = a->x + a->width - w;
545 if (h <= a->height) {
546 if (!self->strut.top && *y < a->y) *y = a->y;
547 if (!self->strut.bottom && *y + h > a->y + a->height)
548 *y = a->y + a->height - h;
552 frame_frame_gravity(self->frame, x, y); /* get where the client
555 return ox != *x || oy != *y;
558 static void client_toggle_border(ObClient *self, gboolean show)
560 /* adjust our idea of where the client is, based on its border. When the
561 border is removed, the client should now be considered to be in a
563 when re-adding the border to the client, the same operation needs to be
565 int oldx = self->area.x, oldy = self->area.y;
566 int x = oldx, y = oldy;
567 switch(self->gravity) {
569 case NorthWestGravity:
571 case SouthWestGravity:
573 case NorthEastGravity:
575 case SouthEastGravity:
576 if (show) x -= self->border_width * 2;
577 else x += self->border_width * 2;
584 if (show) x -= self->border_width;
585 else x += self->border_width;
588 switch(self->gravity) {
590 case NorthWestGravity:
592 case NorthEastGravity:
594 case SouthWestGravity:
596 case SouthEastGravity:
597 if (show) y -= self->border_width * 2;
598 else y += self->border_width * 2;
605 if (show) y -= self->border_width;
606 else y += self->border_width;
613 XSetWindowBorderWidth(ob_display, self->window, self->border_width);
615 /* move the client so it is back it the right spot _with_ its
617 if (x != oldx || y != oldy)
618 XMoveWindow(ob_display, self->window, x, y);
620 XSetWindowBorderWidth(ob_display, self->window, 0);
624 static void client_get_all(ObClient *self)
626 /* update EVERYTHING!! */
628 self->ignore_unmaps = 0;
632 self->title = self->icon_title = NULL;
633 self->title_count = 1;
634 self->name = self->class = self->role = NULL;
635 self->wmstate = NormalState;
636 self->transient = FALSE;
637 self->transients = NULL;
638 self->transient_for = NULL;
640 self->urgent = FALSE;
641 self->positioned = FALSE;
642 self->decorate = TRUE;
646 client_get_area(self);
647 client_update_transient_for(self);
648 client_update_wmhints(self);
649 client_get_desktop(self);
650 client_get_state(self);
651 client_get_shaped(self);
653 client_get_mwm_hints(self);
654 client_get_type(self);/* this can change the mwmhints for special cases */
656 client_update_protocols(self);
658 client_get_gravity(self); /* get the attribute gravity */
659 client_update_normal_hints(self); /* this may override the attribute
662 /* got the type, the mwmhints, the protocols, and the normal hints
663 (min/max sizes), so we're ready to set up the decorations/functions */
664 client_setup_decor_and_functions(self);
666 client_update_title(self);
667 client_update_class(self);
668 client_update_strut(self);
669 client_update_icons(self);
672 static void client_get_area(ObClient *self)
674 XWindowAttributes wattrib;
677 ret = XGetWindowAttributes(ob_display, self->window, &wattrib);
678 g_assert(ret != BadWindow);
680 RECT_SET(self->area, wattrib.x, wattrib.y, wattrib.width, wattrib.height);
681 self->border_width = wattrib.border_width;
684 static void client_get_desktop(ObClient *self)
686 guint32 d = screen_num_desktops; /* an always-invalid value */
688 if (PROP_GET32(self->window, net_wm_desktop, cardinal, &d)) {
689 if (d >= screen_num_desktops && d != DESKTOP_ALL)
690 self->desktop = screen_num_desktops - 1;
694 gboolean trdesk = FALSE;
696 if (self->transient_for) {
697 if (self->transient_for != OB_TRAN_GROUP) {
698 self->desktop = self->transient_for->desktop;
703 for (it = self->group->members; it; it = it->next)
704 if (it->data != self &&
705 !((ObClient*)it->data)->transient_for) {
706 self->desktop = ((ObClient*)it->data)->desktop;
713 /* defaults to the current desktop */
714 self->desktop = screen_desktop;
716 if (self->desktop != d) {
717 /* set the desktop hint, to make sure that it always exists */
718 PROP_SET32(self->window, net_wm_desktop, cardinal, self->desktop);
722 static void client_get_state(ObClient *self)
727 self->modal = self->shaded = self->max_horz = self->max_vert =
728 self->fullscreen = self->above = self->below = self->iconic =
729 self->skip_taskbar = self->skip_pager = FALSE;
731 if (PROP_GETA32(self->window, net_wm_state, atom, &state, &num)) {
733 for (i = 0; i < num; ++i) {
734 if (state[i] == prop_atoms.net_wm_state_modal)
736 else if (state[i] == prop_atoms.net_wm_state_shaded)
738 else if (state[i] == prop_atoms.net_wm_state_hidden)
740 else if (state[i] == prop_atoms.net_wm_state_skip_taskbar)
741 self->skip_taskbar = TRUE;
742 else if (state[i] == prop_atoms.net_wm_state_skip_pager)
743 self->skip_pager = TRUE;
744 else if (state[i] == prop_atoms.net_wm_state_fullscreen)
745 self->fullscreen = TRUE;
746 else if (state[i] == prop_atoms.net_wm_state_maximized_vert)
747 self->max_vert = TRUE;
748 else if (state[i] == prop_atoms.net_wm_state_maximized_horz)
749 self->max_horz = TRUE;
750 else if (state[i] == prop_atoms.net_wm_state_above)
752 else if (state[i] == prop_atoms.net_wm_state_below)
760 static void client_get_shaped(ObClient *self)
762 self->shaped = FALSE;
764 if (extensions_shape) {
769 XShapeSelectInput(ob_display, self->window, ShapeNotifyMask);
771 XShapeQueryExtents(ob_display, self->window, &s, &foo,
772 &foo, &ufoo, &ufoo, &foo, &foo, &foo, &ufoo,
774 self->shaped = (s != 0);
779 void client_update_transient_for(ObClient *self)
782 ObClient *target = NULL;
784 if (XGetTransientForHint(ob_display, self->window, &t)) {
785 self->transient = TRUE;
786 if (t != self->window) { /* cant be transient to itself! */
787 target = g_hash_table_lookup(window_map, &t);
788 /* if this happens then we need to check for it*/
789 g_assert(target != self);
790 g_assert(!target || WINDOW_IS_CLIENT(target));
792 if (!target && self->group) {
793 /* not transient to a client, see if it is transient for a
795 if (t == self->group->leader ||
797 t == RootWindow(ob_display, ob_screen)) {
798 /* window is a transient for its group! */
799 target = OB_TRAN_GROUP;
804 self->transient = FALSE;
806 /* if anything has changed... */
807 if (target != self->transient_for) {
808 if (self->transient_for == OB_TRAN_GROUP) { /* transient of group */
811 /* remove from old parents */
812 for (it = self->group->members; it; it = g_slist_next(it)) {
813 ObClient *c = it->data;
814 if (c != self && !c->transient_for)
815 c->transients = g_slist_remove(c->transients, self);
817 } else if (self->transient_for != NULL) { /* transient of window */
818 /* remove from old parent */
819 self->transient_for->transients =
820 g_slist_remove(self->transient_for->transients, self);
822 self->transient_for = target;
823 if (self->transient_for == OB_TRAN_GROUP) { /* transient of group */
826 /* add to new parents */
827 for (it = self->group->members; it; it = g_slist_next(it)) {
828 ObClient *c = it->data;
829 if (c != self && !c->transient_for)
830 c->transients = g_slist_append(c->transients, self);
833 /* remove all transients which are in the group, that causes
834 circlular pointer hell of doom */
835 for (it = self->group->members; it; it = g_slist_next(it)) {
837 for (sit = self->transients; sit; sit = next) {
838 next = g_slist_next(sit);
839 if (sit->data == it->data)
841 g_slist_delete_link(self->transients, sit);
844 } else if (self->transient_for != NULL) { /* transient of window */
845 /* add to new parent */
846 self->transient_for->transients =
847 g_slist_append(self->transient_for->transients, self);
852 static void client_get_mwm_hints(ObClient *self)
857 self->mwmhints.flags = 0; /* default to none */
859 if (PROP_GETA32(self->window, motif_wm_hints, motif_wm_hints,
861 if (num >= OB_MWM_ELEMENTS) {
862 self->mwmhints.flags = hints[0];
863 self->mwmhints.functions = hints[1];
864 self->mwmhints.decorations = hints[2];
870 void client_get_type(ObClient *self)
877 if (PROP_GETA32(self->window, net_wm_window_type, atom, &val, &num)) {
878 /* use the first value that we know about in the array */
879 for (i = 0; i < num; ++i) {
880 if (val[i] == prop_atoms.net_wm_window_type_desktop)
881 self->type = OB_CLIENT_TYPE_DESKTOP;
882 else if (val[i] == prop_atoms.net_wm_window_type_dock)
883 self->type = OB_CLIENT_TYPE_DOCK;
884 else if (val[i] == prop_atoms.net_wm_window_type_toolbar)
885 self->type = OB_CLIENT_TYPE_TOOLBAR;
886 else if (val[i] == prop_atoms.net_wm_window_type_menu)
887 self->type = OB_CLIENT_TYPE_MENU;
888 else if (val[i] == prop_atoms.net_wm_window_type_utility)
889 self->type = OB_CLIENT_TYPE_UTILITY;
890 else if (val[i] == prop_atoms.net_wm_window_type_splash)
891 self->type = OB_CLIENT_TYPE_SPLASH;
892 else if (val[i] == prop_atoms.net_wm_window_type_dialog)
893 self->type = OB_CLIENT_TYPE_DIALOG;
894 else if (val[i] == prop_atoms.net_wm_window_type_normal)
895 self->type = OB_CLIENT_TYPE_NORMAL;
896 else if (val[i] == prop_atoms.kde_net_wm_window_type_override) {
897 /* prevent this window from getting any decor or
899 self->mwmhints.flags &= (OB_MWM_FLAG_FUNCTIONS |
900 OB_MWM_FLAG_DECORATIONS);
901 self->mwmhints.decorations = 0;
902 self->mwmhints.functions = 0;
904 if (self->type != (ObClientType) -1)
905 break; /* grab the first legit type */
910 if (self->type == (ObClientType) -1) {
911 /*the window type hint was not set, which means we either classify
912 ourself as a normal window or a dialog, depending on if we are a
915 self->type = OB_CLIENT_TYPE_DIALOG;
917 self->type = OB_CLIENT_TYPE_NORMAL;
921 void client_update_protocols(ObClient *self)
926 self->focus_notify = FALSE;
927 self->delete_window = FALSE;
929 if (PROP_GETA32(self->window, wm_protocols, atom, &proto, &num_return)) {
930 for (i = 0; i < num_return; ++i) {
931 if (proto[i] == prop_atoms.wm_delete_window) {
932 /* this means we can request the window to close */
933 self->delete_window = TRUE;
934 } else if (proto[i] == prop_atoms.wm_take_focus)
935 /* if this protocol is requested, then the window will be
936 notified whenever we want it to receive focus */
937 self->focus_notify = TRUE;
943 static void client_get_gravity(ObClient *self)
945 XWindowAttributes wattrib;
948 ret = XGetWindowAttributes(ob_display, self->window, &wattrib);
949 g_assert(ret != BadWindow);
950 self->gravity = wattrib.win_gravity;
953 void client_update_normal_hints(ObClient *self)
957 int oldgravity = self->gravity;
960 self->min_ratio = 0.0f;
961 self->max_ratio = 0.0f;
962 SIZE_SET(self->size_inc, 1, 1);
963 SIZE_SET(self->base_size, 0, 0);
964 SIZE_SET(self->min_size, 0, 0);
965 SIZE_SET(self->max_size, G_MAXINT, G_MAXINT);
967 /* get the hints from the window */
968 if (XGetWMNormalHints(ob_display, self->window, &size, &ret)) {
969 self->positioned = !!(size.flags & (PPosition|USPosition));
971 if (size.flags & PWinGravity) {
972 self->gravity = size.win_gravity;
974 /* if the client has a frame, i.e. has already been mapped and
975 is changing its gravity */
976 if (self->frame && self->gravity != oldgravity) {
977 /* move our idea of the client's position based on its new
979 self->area.x = self->frame->area.x;
980 self->area.y = self->frame->area.y;
981 frame_frame_gravity(self->frame, &self->area.x, &self->area.y);
985 if (size.flags & PAspect) {
986 if (size.min_aspect.y)
987 self->min_ratio = (float)size.min_aspect.x / size.min_aspect.y;
988 if (size.max_aspect.y)
989 self->max_ratio = (float)size.max_aspect.x / size.max_aspect.y;
992 if (size.flags & PMinSize)
993 SIZE_SET(self->min_size, size.min_width, size.min_height);
995 if (size.flags & PMaxSize)
996 SIZE_SET(self->max_size, size.max_width, size.max_height);
998 if (size.flags & PBaseSize)
999 SIZE_SET(self->base_size, size.base_width, size.base_height);
1001 if (size.flags & PResizeInc)
1002 SIZE_SET(self->size_inc, size.width_inc, size.height_inc);
1006 void client_setup_decor_and_functions(ObClient *self)
1008 /* start with everything (cept fullscreen) */
1009 self->decorations = (OB_FRAME_DECOR_TITLEBAR |
1010 OB_FRAME_DECOR_HANDLE |
1011 OB_FRAME_DECOR_GRIPS |
1012 OB_FRAME_DECOR_BORDER |
1013 OB_FRAME_DECOR_ICON |
1014 OB_FRAME_DECOR_ALLDESKTOPS |
1015 OB_FRAME_DECOR_ICONIFY |
1016 OB_FRAME_DECOR_MAXIMIZE |
1017 OB_FRAME_DECOR_SHADE);
1018 self->functions = (OB_CLIENT_FUNC_RESIZE |
1019 OB_CLIENT_FUNC_MOVE |
1020 OB_CLIENT_FUNC_ICONIFY |
1021 OB_CLIENT_FUNC_MAXIMIZE |
1022 OB_CLIENT_FUNC_SHADE);
1023 if (self->delete_window) {
1024 self->functions |= OB_CLIENT_FUNC_CLOSE;
1025 self->decorations |= OB_FRAME_DECOR_CLOSE;
1028 if (!(self->min_size.width < self->max_size.width ||
1029 self->min_size.height < self->max_size.height))
1030 self->functions &= ~OB_CLIENT_FUNC_RESIZE;
1032 switch (self->type) {
1033 case OB_CLIENT_TYPE_NORMAL:
1034 /* normal windows retain all of the possible decorations and
1035 functionality, and are the only windows that you can fullscreen */
1036 self->functions |= OB_CLIENT_FUNC_FULLSCREEN;
1039 case OB_CLIENT_TYPE_DIALOG:
1040 case OB_CLIENT_TYPE_UTILITY:
1041 /* these windows cannot be maximized */
1042 self->functions &= ~OB_CLIENT_FUNC_MAXIMIZE;
1045 case OB_CLIENT_TYPE_MENU:
1046 case OB_CLIENT_TYPE_TOOLBAR:
1047 /* these windows get less functionality */
1048 self->functions &= ~(OB_CLIENT_FUNC_ICONIFY | OB_CLIENT_FUNC_RESIZE);
1051 case OB_CLIENT_TYPE_DESKTOP:
1052 case OB_CLIENT_TYPE_DOCK:
1053 case OB_CLIENT_TYPE_SPLASH:
1054 /* none of these windows are manipulated by the window manager */
1055 self->decorations = 0;
1056 self->functions = 0;
1060 /* Mwm Hints are applied subtractively to what has already been chosen for
1061 decor and functionality */
1062 if (self->mwmhints.flags & OB_MWM_FLAG_DECORATIONS) {
1063 if (! (self->mwmhints.decorations & OB_MWM_DECOR_ALL)) {
1064 if (! ((self->mwmhints.decorations & OB_MWM_DECOR_HANDLE) ||
1065 (self->mwmhints.decorations & OB_MWM_DECOR_TITLE)))
1066 /* if the mwm hints request no handle or title, then all
1067 decorations are disabled */
1068 self->decorations = 0;
1072 if (self->mwmhints.flags & OB_MWM_FLAG_FUNCTIONS) {
1073 if (! (self->mwmhints.functions & OB_MWM_FUNC_ALL)) {
1074 if (! (self->mwmhints.functions & OB_MWM_FUNC_RESIZE))
1075 self->functions &= ~OB_CLIENT_FUNC_RESIZE;
1076 if (! (self->mwmhints.functions & OB_MWM_FUNC_MOVE))
1077 self->functions &= ~OB_CLIENT_FUNC_MOVE;
1078 /* dont let mwm hints kill any buttons
1079 if (! (self->mwmhints.functions & OB_MWM_FUNC_ICONIFY))
1080 self->functions &= ~OB_CLIENT_FUNC_ICONIFY;
1081 if (! (self->mwmhints.functions & OB_MWM_FUNC_MAXIMIZE))
1082 self->functions &= ~OB_CLIENT_FUNC_MAXIMIZE;
1084 /* dont let mwm hints kill the close button
1085 if (! (self->mwmhints.functions & MwmFunc_Close))
1086 self->functions &= ~OB_CLIENT_FUNC_CLOSE; */
1090 if (!(self->functions & OB_CLIENT_FUNC_SHADE))
1091 self->decorations &= ~OB_FRAME_DECOR_SHADE;
1092 if (!(self->functions & OB_CLIENT_FUNC_ICONIFY))
1093 self->decorations &= ~OB_FRAME_DECOR_ICONIFY;
1094 if (!(self->functions & OB_CLIENT_FUNC_RESIZE))
1095 self->decorations &= ~OB_FRAME_DECOR_GRIPS;
1097 /* can't maximize without moving/resizing */
1098 if (!((self->functions & OB_CLIENT_FUNC_MAXIMIZE) &&
1099 (self->functions & OB_CLIENT_FUNC_MOVE) &&
1100 (self->functions & OB_CLIENT_FUNC_RESIZE))) {
1101 self->functions &= ~OB_CLIENT_FUNC_MAXIMIZE;
1102 self->decorations &= ~OB_FRAME_DECOR_MAXIMIZE;
1105 /* finally, the user can have requested no decorations, which overrides
1107 if (!self->decorate)
1108 self->decorations = OB_FRAME_DECOR_BORDER;
1110 /* if we don't have a titlebar, then we cannot shade! */
1111 if (!(self->decorations & OB_FRAME_DECOR_TITLEBAR))
1112 self->functions &= ~OB_CLIENT_FUNC_SHADE;
1114 /* now we need to check against rules for the client's current state */
1115 if (self->fullscreen) {
1116 self->functions &= (OB_CLIENT_FUNC_CLOSE |
1117 OB_CLIENT_FUNC_FULLSCREEN |
1118 OB_CLIENT_FUNC_ICONIFY);
1119 self->decorations = 0;
1122 client_change_allowed_actions(self);
1125 /* adjust the client's decorations, etc. */
1126 client_reconfigure(self);
1128 /* this makes sure that these windows appear on all desktops */
1129 if (self->type == OB_CLIENT_TYPE_DESKTOP &&
1130 self->desktop != DESKTOP_ALL)
1132 self->desktop = DESKTOP_ALL;
1137 static void client_change_allowed_actions(ObClient *self)
1142 /* desktop windows are kept on all desktops */
1143 if (self->type != OB_CLIENT_TYPE_DESKTOP)
1144 actions[num++] = prop_atoms.net_wm_action_change_desktop;
1146 if (self->functions & OB_CLIENT_FUNC_SHADE)
1147 actions[num++] = prop_atoms.net_wm_action_shade;
1148 if (self->functions & OB_CLIENT_FUNC_CLOSE)
1149 actions[num++] = prop_atoms.net_wm_action_close;
1150 if (self->functions & OB_CLIENT_FUNC_MOVE)
1151 actions[num++] = prop_atoms.net_wm_action_move;
1152 if (self->functions & OB_CLIENT_FUNC_ICONIFY)
1153 actions[num++] = prop_atoms.net_wm_action_minimize;
1154 if (self->functions & OB_CLIENT_FUNC_RESIZE)
1155 actions[num++] = prop_atoms.net_wm_action_resize;
1156 if (self->functions & OB_CLIENT_FUNC_FULLSCREEN)
1157 actions[num++] = prop_atoms.net_wm_action_fullscreen;
1158 if (self->functions & OB_CLIENT_FUNC_MAXIMIZE) {
1159 actions[num++] = prop_atoms.net_wm_action_maximize_horz;
1160 actions[num++] = prop_atoms.net_wm_action_maximize_vert;
1163 PROP_SETA32(self->window, net_wm_allowed_actions, atom, actions, num);
1165 /* make sure the window isn't breaking any rules now */
1167 if (!(self->functions & OB_CLIENT_FUNC_SHADE) && self->shaded) {
1168 if (self->frame) client_shade(self, FALSE);
1169 else self->shaded = FALSE;
1171 if (!(self->functions & OB_CLIENT_FUNC_ICONIFY) && self->iconic) {
1172 if (self->frame) client_iconify(self, FALSE, TRUE);
1173 else self->iconic = FALSE;
1175 if (!(self->functions & OB_CLIENT_FUNC_FULLSCREEN) && self->fullscreen) {
1176 if (self->frame) client_fullscreen(self, FALSE, TRUE);
1177 else self->fullscreen = FALSE;
1179 if (!(self->functions & OB_CLIENT_FUNC_MAXIMIZE) && (self->max_horz ||
1181 if (self->frame) client_maximize(self, FALSE, 0, TRUE);
1182 else self->max_vert = self->max_horz = FALSE;
1186 void client_reconfigure(ObClient *self)
1188 /* by making this pass FALSE for user, we avoid the emacs event storm where
1189 every configurenotify causes an update in its normal hints, i think this
1190 is generally what we want anyways... */
1191 client_configure(self, OB_CORNER_TOPLEFT, self->area.x, self->area.y,
1192 self->area.width, self->area.height, FALSE, TRUE);
1195 void client_update_wmhints(ObClient *self)
1198 gboolean ur = FALSE;
1201 /* assume a window takes input if it doesnt specify */
1202 self->can_focus = TRUE;
1204 if ((hints = XGetWMHints(ob_display, self->window)) != NULL) {
1205 if (hints->flags & InputHint)
1206 self->can_focus = hints->input;
1208 /* only do this when first managing the window *AND* when we aren't
1210 if (ob_state() != OB_STATE_STARTING && self->frame == NULL)
1211 if (hints->flags & StateHint)
1212 self->iconic = hints->initial_state == IconicState;
1214 if (hints->flags & XUrgencyHint)
1217 if (!(hints->flags & WindowGroupHint))
1218 hints->window_group = None;
1220 /* did the group state change? */
1221 if (hints->window_group !=
1222 (self->group ? self->group->leader : None)) {
1223 /* remove from the old group if there was one */
1224 if (self->group != NULL) {
1225 /* remove transients of the group */
1226 for (it = self->group->members; it; it = it->next)
1227 self->transients = g_slist_remove(self->transients,
1229 group_remove(self->group, self);
1232 if (hints->window_group != None) {
1233 self->group = group_add(hints->window_group, self);
1235 /* i can only have transients from the group if i am not
1237 if (!self->transient_for) {
1238 /* add other transients of the group that are already
1240 for (it = self->group->members; it; it = it->next) {
1241 ObClient *c = it->data;
1242 if (c != self && c->transient_for == OB_TRAN_GROUP)
1244 g_slist_append(self->transients, c);
1249 /* because the self->transient flag wont change from this call,
1250 we don't need to update the window's type and such, only its
1251 transient_for, and the transients lists of other windows in
1252 the group may be affected */
1253 client_update_transient_for(self);
1256 /* the WM_HINTS can contain an icon */
1257 client_update_icons(self);
1262 if (ur != self->urgent) {
1264 ob_debug("Urgent Hint for 0x%lx: %s\n", self->window,
1266 /* fire the urgent callback if we're mapped, otherwise, wait until
1267 after we're mapped */
1269 dispatch_client(Event_Client_Urgent, self, self->urgent, 0);
1273 void client_update_title(ObClient *self)
1279 gboolean read_title;
1281 g_free(self->title);
1284 if (!PROP_GETS(self->window, net_wm_name, utf8, &data))
1285 /* try old x stuff */
1286 if (!PROP_GETS(self->window, wm_name, locale, &data))
1287 data = g_strdup("Unnamed Window");
1289 /* look for duplicates and append a number */
1291 for (it = client_list; it; it = it->next)
1292 if (it->data != self) {
1293 ObClient *c = it->data;
1294 if (0 == strncmp(c->title, data, strlen(data)))
1295 nums |= 1 << c->title_count;
1297 /* find first free number */
1298 for (i = 1; i <= 32; ++i)
1299 if (!(nums & (1 << i))) {
1300 if (self->title_count == 1 || i == 1)
1301 self->title_count = i;
1304 /* dont display the number for the first window */
1305 if (self->title_count > 1) {
1306 char *vdata, *ndata;
1307 ndata = g_strdup_printf(" - [%u]", self->title_count);
1308 vdata = g_strconcat(data, ndata, NULL);
1314 PROP_SETS(self->window, net_wm_visible_name, data);
1319 frame_adjust_title(self->frame);
1321 /* update the icon title */
1323 g_free(self->icon_title);
1327 if (!PROP_GETS(self->window, net_wm_icon_name, utf8, &data))
1328 /* try old x stuff */
1329 if (!PROP_GETS(self->window, wm_icon_name, locale, &data)) {
1330 data = g_strdup(self->title);
1334 /* append the title count, dont display the number for the first window */
1335 if (read_title && self->title_count > 1) {
1336 char *vdata, *ndata;
1337 ndata = g_strdup_printf(" - [%u]", self->title_count);
1338 vdata = g_strconcat(data, ndata, NULL);
1344 PROP_SETS(self->window, net_wm_visible_icon_name, data);
1346 self->icon_title = data;
1349 void client_update_class(ObClient *self)
1354 if (self->name) g_free(self->name);
1355 if (self->class) g_free(self->class);
1356 if (self->role) g_free(self->role);
1358 self->name = self->class = self->role = NULL;
1360 if (PROP_GETSS(self->window, wm_class, locale, &data)) {
1362 self->name = g_strdup(data[0]);
1364 self->class = g_strdup(data[1]);
1369 if (PROP_GETS(self->window, wm_window_role, locale, &s))
1370 self->role = g_strdup(s);
1372 if (self->name == NULL) self->name = g_strdup("");
1373 if (self->class == NULL) self->class = g_strdup("");
1374 if (self->role == NULL) self->role = g_strdup("");
1377 void client_update_strut(ObClient *self)
1381 gboolean got = FALSE;
1383 if (PROP_GETA32(self->window, net_wm_strut_partial, cardinal,
1387 STRUT_PARTIAL_SET(self->strut,
1388 data[0], data[2], data[1], data[3],
1389 data[4], data[5], data[8], data[9],
1390 data[6], data[7], data[10], data[11]);
1396 PROP_GETA32(self->window, net_wm_strut, cardinal, &data, &num)) {
1399 STRUT_PARTIAL_SET(self->strut,
1400 data[0], data[2], data[1], data[3],
1401 0, 0, 0, 0, 0, 0, 0, 0);
1407 STRUT_PARTIAL_SET(self->strut, 0, 0, 0, 0,
1408 0, 0, 0, 0, 0, 0, 0, 0);
1410 /* updating here is pointless while we're being mapped cuz we're not in
1411 the client list yet */
1413 screen_update_areas();
1416 void client_update_icons(ObClient *self)
1422 for (i = 0; i < self->nicons; ++i)
1423 g_free(self->icons[i].data);
1424 if (self->nicons > 0)
1425 g_free(self->icons);
1428 if (PROP_GETA32(self->window, net_wm_icon, cardinal, &data, &num)) {
1429 /* figure out how many valid icons are in here */
1431 while (num - i > 2) {
1435 if (i > num || w*h == 0) break;
1439 self->icons = g_new(ObClientIcon, self->nicons);
1441 /* store the icons */
1443 for (j = 0; j < self->nicons; ++j) {
1446 w = self->icons[j].width = data[i++];
1447 h = self->icons[j].height = data[i++];
1449 if (w*h == 0) continue;
1451 self->icons[j].data = g_new(RrPixel32, w * h);
1452 for (x = 0, y = 0, t = 0; t < w * h; ++t, ++x, ++i) {
1457 self->icons[j].data[t] =
1458 (((data[i] >> 24) & 0xff) << RrDefaultAlphaOffset) +
1459 (((data[i] >> 16) & 0xff) << RrDefaultRedOffset) +
1460 (((data[i] >> 8) & 0xff) << RrDefaultGreenOffset) +
1461 (((data[i] >> 0) & 0xff) << RrDefaultBlueOffset);
1467 } else if (PROP_GETA32(self->window, kwm_win_icon,
1468 kwm_win_icon, &data, &num)) {
1471 self->icons = g_new(ObClientIcon, self->nicons);
1472 xerror_set_ignore(TRUE);
1473 if (!RrPixmapToRGBA(ob_rr_inst,
1475 &self->icons[self->nicons-1].width,
1476 &self->icons[self->nicons-1].height,
1477 &self->icons[self->nicons-1].data)) {
1478 g_free(&self->icons[self->nicons-1]);
1481 xerror_set_ignore(FALSE);
1487 if ((hints = XGetWMHints(ob_display, self->window))) {
1488 if (hints->flags & IconPixmapHint) {
1490 self->icons = g_new(ObClientIcon, self->nicons);
1491 xerror_set_ignore(TRUE);
1492 if (!RrPixmapToRGBA(ob_rr_inst,
1494 (hints->flags & IconMaskHint ?
1495 hints->icon_mask : None),
1496 &self->icons[self->nicons-1].width,
1497 &self->icons[self->nicons-1].height,
1498 &self->icons[self->nicons-1].data)){
1499 g_free(&self->icons[self->nicons-1]);
1502 xerror_set_ignore(FALSE);
1509 frame_adjust_icon(self->frame);
1512 static void client_change_state(ObClient *self)
1515 guint32 netstate[10];
1518 state[0] = self->wmstate;
1520 PROP_SETA32(self->window, wm_state, wm_state, state, 2);
1524 netstate[num++] = prop_atoms.net_wm_state_modal;
1526 netstate[num++] = prop_atoms.net_wm_state_shaded;
1528 netstate[num++] = prop_atoms.net_wm_state_hidden;
1529 if (self->skip_taskbar)
1530 netstate[num++] = prop_atoms.net_wm_state_skip_taskbar;
1531 if (self->skip_pager)
1532 netstate[num++] = prop_atoms.net_wm_state_skip_pager;
1533 if (self->fullscreen)
1534 netstate[num++] = prop_atoms.net_wm_state_fullscreen;
1536 netstate[num++] = prop_atoms.net_wm_state_maximized_vert;
1538 netstate[num++] = prop_atoms.net_wm_state_maximized_horz;
1540 netstate[num++] = prop_atoms.net_wm_state_above;
1542 netstate[num++] = prop_atoms.net_wm_state_below;
1543 PROP_SETA32(self->window, net_wm_state, atom, netstate, num);
1545 client_calc_layer(self);
1548 frame_adjust_state(self->frame);
1551 ObClient *client_search_focus_tree(ObClient *self)
1556 for (it = self->transients; it != NULL; it = it->next) {
1557 if (client_focused(it->data)) return it->data;
1558 if ((ret = client_search_focus_tree(it->data))) return ret;
1563 ObClient *client_search_focus_tree_full(ObClient *self)
1565 if (self->transient_for) {
1566 if (self->transient_for != OB_TRAN_GROUP) {
1567 return client_search_focus_tree_full(self->transient_for);
1570 gboolean recursed = FALSE;
1572 for (it = self->group->members; it; it = it->next)
1573 if (!((ObClient*)it->data)->transient_for) {
1575 if ((c = client_search_focus_tree_full(it->data)))
1584 /* this function checks the whole tree, the client_search_focus_tree~
1585 does not, so we need to check this window */
1586 if (client_focused(self))
1588 return client_search_focus_tree(self);
1591 static ObStackingLayer calc_layer(ObClient *self)
1595 if (self->fullscreen) l = OB_STACKING_LAYER_FULLSCREEN;
1596 else if (self->type == OB_CLIENT_TYPE_DESKTOP)
1597 l = OB_STACKING_LAYER_DESKTOP;
1598 else if (self->type == OB_CLIENT_TYPE_DOCK) {
1599 if (!self->below) l = OB_STACKING_LAYER_TOP;
1600 else l = OB_STACKING_LAYER_NORMAL;
1602 else if (self->above) l = OB_STACKING_LAYER_ABOVE;
1603 else if (self->below) l = OB_STACKING_LAYER_BELOW;
1604 else l = OB_STACKING_LAYER_NORMAL;
1609 static void client_calc_layer_recursive(ObClient *self, ObClient *orig,
1610 ObStackingLayer l, gboolean raised)
1612 ObStackingLayer old, own;
1616 own = calc_layer(self);
1617 self->layer = l > own ? l : own;
1619 for (it = self->transients; it; it = it->next)
1620 client_calc_layer_recursive(it->data, orig,
1621 l, raised ? raised : l != old);
1623 if (!raised && l != old)
1624 if (orig->frame) { /* only restack if the original window is managed */
1625 /* XXX add_non_intrusive ever? */
1626 stacking_remove(CLIENT_AS_WINDOW(self));
1627 stacking_add(CLIENT_AS_WINDOW(self));
1631 void client_calc_layer(ObClient *self)
1638 /* transients take on the layer of their parents */
1639 self = client_search_top_transient(self);
1641 l = calc_layer(self);
1643 client_calc_layer_recursive(self, orig, l, FALSE);
1646 gboolean client_should_show(ObClient *self)
1648 if (self->iconic) return FALSE;
1649 else if (!(self->desktop == screen_desktop ||
1650 self->desktop == DESKTOP_ALL)) return FALSE;
1651 else if (client_normal(self) && screen_showing_desktop) return FALSE;
1656 static void client_showhide(ObClient *self)
1659 if (client_should_show(self))
1660 frame_show(self->frame);
1662 frame_hide(self->frame);
1665 gboolean client_normal(ObClient *self) {
1666 return ! (self->type == OB_CLIENT_TYPE_DESKTOP ||
1667 self->type == OB_CLIENT_TYPE_DOCK ||
1668 self->type == OB_CLIENT_TYPE_SPLASH);
1671 static void client_apply_startup_state(ObClient *self)
1673 /* these are in a carefully crafted order.. */
1676 self->iconic = FALSE;
1677 client_iconify(self, TRUE, FALSE);
1679 if (self->fullscreen) {
1680 self->fullscreen = FALSE;
1681 client_fullscreen(self, TRUE, FALSE);
1684 self->shaded = FALSE;
1685 client_shade(self, TRUE);
1688 dispatch_client(Event_Client_Urgent, self, self->urgent, 0);
1690 if (self->max_vert && self->max_horz) {
1691 self->max_vert = self->max_horz = FALSE;
1692 client_maximize(self, TRUE, 0, FALSE);
1693 } else if (self->max_vert) {
1694 self->max_vert = FALSE;
1695 client_maximize(self, TRUE, 2, FALSE);
1696 } else if (self->max_horz) {
1697 self->max_horz = FALSE;
1698 client_maximize(self, TRUE, 1, FALSE);
1701 /* nothing to do for the other states:
1710 void client_configure_full(ObClient *self, ObCorner anchor,
1711 int x, int y, int w, int h,
1712 gboolean user, gboolean final,
1713 gboolean force_reply)
1715 gboolean moved = FALSE, resized = FALSE;
1716 guint fdecor = self->frame->decorations;
1718 /* make the frame recalculate its dimentions n shit without changing
1719 anything visible for real, this way the constraints below can work with
1720 the updated frame dimensions. */
1721 frame_adjust_area(self->frame, TRUE, TRUE, TRUE);
1723 /* gets the frame's position */
1724 frame_client_gravity(self->frame, &x, &y);
1726 /* these positions are frame positions, not client positions */
1728 /* set the size and position if fullscreen */
1729 if (self->fullscreen) {
1732 XF86VidModeModeLine mode;
1737 i = client_monitor(self);
1738 a = screen_physical_area_monitor(i);
1741 if (i == 0 && /* primary head */
1742 extensions_vidmode &&
1743 XF86VidModeGetViewPort(ob_display, ob_screen, &x, &y) &&
1744 /* get the mode last so the mode.privsize isnt freed incorrectly */
1745 XF86VidModeGetModeLine(ob_display, ob_screen, &dot, &mode)) {
1750 if (mode.privsize) XFree(mode.private);
1760 user = FALSE; /* ignore that increment etc shit when in fullscreen */
1764 a = screen_area_monitor(self->desktop, client_monitor(self));
1766 /* set the size and position if maximized */
1767 if (self->max_horz) {
1769 w = a->width - self->frame->size.left - self->frame->size.right;
1771 if (self->max_vert) {
1773 h = a->height - self->frame->size.top - self->frame->size.bottom;
1777 /* gets the client's position */
1778 frame_frame_gravity(self->frame, &x, &y);
1780 /* these override the above states! if you cant move you can't move! */
1782 if (!(self->functions & OB_CLIENT_FUNC_MOVE)) {
1786 if (!(self->functions & OB_CLIENT_FUNC_RESIZE)) {
1787 w = self->area.width;
1788 h = self->area.height;
1792 if (!(w == self->area.width && h == self->area.height)) {
1793 int basew, baseh, minw, minh;
1795 /* base size is substituted with min size if not specified */
1796 if (self->base_size.width || self->base_size.height) {
1797 basew = self->base_size.width;
1798 baseh = self->base_size.height;
1800 basew = self->min_size.width;
1801 baseh = self->min_size.height;
1803 /* min size is substituted with base size if not specified */
1804 if (self->min_size.width || self->min_size.height) {
1805 minw = self->min_size.width;
1806 minh = self->min_size.height;
1808 minw = self->base_size.width;
1809 minh = self->base_size.height;
1813 /* for interactive resizing. have to move half an increment in each
1816 /* how far we are towards the next size inc */
1817 int mw = (w - basew) % self->size_inc.width;
1818 int mh = (h - baseh) % self->size_inc.height;
1820 int aw = self->size_inc.width / 2;
1821 int ah = self->size_inc.height / 2;
1822 /* don't let us move into a new size increment */
1823 if (mw + aw >= self->size_inc.width)
1824 aw = self->size_inc.width - mw - 1;
1825 if (mh + ah >= self->size_inc.height)
1826 ah = self->size_inc.height - mh - 1;
1830 /* if this is a user-requested resize, then check against min/max
1833 /* smaller than min size or bigger than max size? */
1834 if (w > self->max_size.width) w = self->max_size.width;
1835 if (w < minw) w = minw;
1836 if (h > self->max_size.height) h = self->max_size.height;
1837 if (h < minh) h = minh;
1843 /* keep to the increments */
1844 w /= self->size_inc.width;
1845 h /= self->size_inc.height;
1847 /* you cannot resize to nothing */
1848 if (basew + w < 1) w = 1 - basew;
1849 if (baseh + h < 1) h = 1 - baseh;
1851 /* store the logical size */
1852 SIZE_SET(self->logical_size,
1853 self->size_inc.width > 1 ? w : w + basew,
1854 self->size_inc.height > 1 ? h : h + baseh);
1856 w *= self->size_inc.width;
1857 h *= self->size_inc.height;
1863 /* adjust the height to match the width for the aspect ratios.
1864 for this, min size is not substituted for base size ever. */
1865 w -= self->base_size.width;
1866 h -= self->base_size.height;
1868 if (self->min_ratio)
1869 if (h * self->min_ratio > w) h = (int)(w / self->min_ratio);
1870 if (self->max_ratio)
1871 if (h * self->max_ratio < w) h = (int)(w / self->max_ratio);
1873 w += self->base_size.width;
1874 h += self->base_size.height;
1879 case OB_CORNER_TOPLEFT:
1881 case OB_CORNER_TOPRIGHT:
1882 x -= w - self->area.width;
1884 case OB_CORNER_BOTTOMLEFT:
1885 y -= h - self->area.height;
1887 case OB_CORNER_BOTTOMRIGHT:
1888 x -= w - self->area.width;
1889 y -= h - self->area.height;
1893 moved = x != self->area.x || y != self->area.y;
1894 resized = w != self->area.width || h != self->area.height;
1896 RECT_SET(self->area, x, y, w, h);
1898 /* for app-requested resizes, always resize if 'resized' is true.
1899 for user-requested ones, only resize if final is true, or when
1900 resizing in redraw mode */
1901 if ((!user && resized) ||
1902 (user && (final || (resized && config_redraw_resize))))
1903 XResizeWindow(ob_display, self->window, w, h);
1905 /* move/resize the frame to match the request */
1907 if (self->decorations != fdecor)
1908 moved = resized = TRUE;
1910 if (moved || resized)
1911 frame_adjust_area(self->frame, moved, resized, FALSE);
1913 if (!resized && (force_reply || ((!user && moved) || (user && final))))
1916 event.type = ConfigureNotify;
1917 event.xconfigure.display = ob_display;
1918 event.xconfigure.event = self->window;
1919 event.xconfigure.window = self->window;
1921 /* root window real coords */
1922 event.xconfigure.x = self->frame->area.x + self->frame->size.left -
1924 event.xconfigure.y = self->frame->area.y + self->frame->size.top -
1926 event.xconfigure.width = w;
1927 event.xconfigure.height = h;
1928 event.xconfigure.border_width = 0;
1929 event.xconfigure.above = self->frame->plate;
1930 event.xconfigure.override_redirect = FALSE;
1931 XSendEvent(event.xconfigure.display, event.xconfigure.window,
1932 FALSE, StructureNotifyMask, &event);
1937 void client_fullscreen(ObClient *self, gboolean fs, gboolean savearea)
1941 if (!(self->functions & OB_CLIENT_FUNC_FULLSCREEN) || /* can't */
1942 self->fullscreen == fs) return; /* already done */
1944 self->fullscreen = fs;
1945 client_change_state(self); /* change the state hints on the client,
1946 and adjust out layer/stacking */
1950 guint32 dimensions[4];
1951 dimensions[0] = self->area.x;
1952 dimensions[1] = self->area.y;
1953 dimensions[2] = self->area.width;
1954 dimensions[3] = self->area.height;
1956 PROP_SETA32(self->window, openbox_premax, cardinal,
1960 /* these are not actually used cuz client_configure will set them
1961 as appropriate when the window is fullscreened */
1968 /* pick some fallbacks... */
1969 a = screen_area_monitor(self->desktop, 0);
1970 x = a->x + a->width / 4;
1971 y = a->y + a->height / 4;
1975 if (PROP_GETA32(self->window, openbox_premax, cardinal,
1976 (guint32**)&dimensions, &num)) {
1987 client_setup_decor_and_functions(self);
1989 client_configure(self, OB_CORNER_TOPLEFT, x, y, w, h, TRUE, TRUE);
1991 /* try focus us when we go into fullscreen mode */
1995 static void client_iconify_recursive(ObClient *self,
1996 gboolean iconic, gboolean curdesk)
1999 gboolean changed = FALSE;
2002 if (self->iconic != iconic) {
2003 ob_debug("%sconifying window: 0x%lx\n", (iconic ? "I" : "Uni"),
2006 self->iconic = iconic;
2009 if (self->functions & OB_CLIENT_FUNC_ICONIFY) {
2010 self->wmstate = IconicState;
2011 self->ignore_unmaps++;
2012 /* we unmap the client itself so that we can get MapRequest
2013 events, and because the ICCCM tells us to! */
2014 XUnmapWindow(ob_display, self->window);
2016 /* update the focus lists.. iconic windows go to the bottom of
2017 the list, put the new iconic window at the 'top of the
2019 focus_order_to_top(self);
2025 client_set_desktop(self, screen_desktop, FALSE);
2026 self->wmstate = self->shaded ? IconicState : NormalState;
2027 XMapWindow(ob_display, self->window);
2029 /* this puts it after the current focused window */
2030 focus_order_remove(self);
2031 focus_order_add_new(self);
2033 /* this is here cuz with the VIDMODE extension, the viewport can
2034 change while a fullscreen window is iconic, and when it
2035 uniconifies, it would be nice if it did so to the new position
2037 client_reconfigure(self);
2044 client_change_state(self);
2045 client_showhide(self);
2046 screen_update_areas();
2048 dispatch_client(iconic ? Event_Client_Unmapped : Event_Client_Mapped,
2052 /* iconify all transients */
2053 for (it = self->transients; it != NULL; it = it->next)
2054 if (it->data != self) client_iconify_recursive(it->data,
2058 void client_iconify(ObClient *self, gboolean iconic, gboolean curdesk)
2060 /* move up the transient chain as far as possible first */
2061 self = client_search_top_transient(self);
2063 client_iconify_recursive(client_search_top_transient(self),
2067 void client_maximize(ObClient *self, gboolean max, int dir, gboolean savearea)
2071 g_assert(dir == 0 || dir == 1 || dir == 2);
2072 if (!(self->functions & OB_CLIENT_FUNC_MAXIMIZE)) return; /* can't */
2074 /* check if already done */
2076 if (dir == 0 && self->max_horz && self->max_vert) return;
2077 if (dir == 1 && self->max_horz) return;
2078 if (dir == 2 && self->max_vert) return;
2080 if (dir == 0 && !self->max_horz && !self->max_vert) return;
2081 if (dir == 1 && !self->max_horz) return;
2082 if (dir == 2 && !self->max_vert) return;
2085 /* work with the frame's coords */
2086 x = self->frame->area.x;
2087 y = self->frame->area.y;
2088 w = self->area.width;
2089 h = self->area.height;
2093 gint32 dimensions[4];
2102 /* get the property off the window and use it for the dimensions
2103 we are already maxed on */
2104 if (PROP_GETA32(self->window, openbox_premax, cardinal,
2105 (guint32**)&readdim, &num)) {
2107 if (self->max_horz) {
2108 dimensions[0] = readdim[0];
2109 dimensions[2] = readdim[2];
2111 if (self->max_vert) {
2112 dimensions[1] = readdim[1];
2113 dimensions[3] = readdim[3];
2119 PROP_SETA32(self->window, openbox_premax, cardinal,
2120 (guint32*)dimensions, 4);
2127 /* pick some fallbacks... */
2128 a = screen_area_monitor(self->desktop, 0);
2129 if (dir == 0 || dir == 1) { /* horz */
2130 x = a->x + a->width / 4;
2133 if (dir == 0 || dir == 2) { /* vert */
2134 y = a->y + a->height / 4;
2138 if (PROP_GETA32(self->window, openbox_premax, cardinal,
2139 (guint32**)&dimensions, &num)) {
2141 if (dir == 0 || dir == 1) { /* horz */
2145 if (dir == 0 || dir == 2) { /* vert */
2154 if (dir == 0 || dir == 1) /* horz */
2155 self->max_horz = max;
2156 if (dir == 0 || dir == 2) /* vert */
2157 self->max_vert = max;
2159 if (!self->max_horz && !self->max_vert)
2160 PROP_ERASE(self->window, openbox_premax);
2162 client_change_state(self); /* change the state hints on the client */
2164 /* figure out where the client should be going */
2165 frame_frame_gravity(self->frame, &x, &y);
2166 client_configure(self, OB_CORNER_TOPLEFT, x, y, w, h, TRUE, TRUE);
2169 void client_shade(ObClient *self, gboolean shade)
2171 if ((!(self->functions & OB_CLIENT_FUNC_SHADE) &&
2172 shade) || /* can't shade */
2173 self->shaded == shade) return; /* already done */
2175 /* when we're iconic, don't change the wmstate */
2177 self->wmstate = shade ? IconicState : NormalState;
2178 self->shaded = shade;
2179 client_change_state(self);
2180 /* resize the frame to just the titlebar */
2181 frame_adjust_area(self->frame, FALSE, FALSE, FALSE);
2184 void client_close(ObClient *self)
2188 if (!(self->functions & OB_CLIENT_FUNC_CLOSE)) return;
2191 XXX: itd be cool to do timeouts and shit here for killing the client's
2193 like... if the window is around after 5 seconds, then the close button
2194 turns a nice red, and if this function is called again, the client is
2198 ce.xclient.type = ClientMessage;
2199 ce.xclient.message_type = prop_atoms.wm_protocols;
2200 ce.xclient.display = ob_display;
2201 ce.xclient.window = self->window;
2202 ce.xclient.format = 32;
2203 ce.xclient.data.l[0] = prop_atoms.wm_delete_window;
2204 ce.xclient.data.l[1] = event_lasttime;
2205 ce.xclient.data.l[2] = 0l;
2206 ce.xclient.data.l[3] = 0l;
2207 ce.xclient.data.l[4] = 0l;
2208 XSendEvent(ob_display, self->window, FALSE, NoEventMask, &ce);
2211 void client_kill(ObClient *self)
2213 XKillClient(ob_display, self->window);
2216 void client_set_desktop_recursive(ObClient *self,
2217 guint target, gboolean donthide)
2222 if (target != self->desktop) {
2224 ob_debug("Setting desktop %u\n", target+1);
2226 g_assert(target < screen_num_desktops || target == DESKTOP_ALL);
2228 /* remove from the old desktop(s) */
2229 focus_order_remove(self);
2231 old = self->desktop;
2232 self->desktop = target;
2233 PROP_SET32(self->window, net_wm_desktop, cardinal, target);
2234 /* the frame can display the current desktop state */
2235 frame_adjust_state(self->frame);
2236 /* 'move' the window to the new desktop */
2238 client_showhide(self);
2239 /* raise if it was not already on the desktop */
2240 if (old != DESKTOP_ALL)
2241 stacking_raise(CLIENT_AS_WINDOW(self));
2242 screen_update_areas();
2244 /* add to the new desktop(s) */
2245 if (config_focus_new)
2246 focus_order_to_top(self);
2248 focus_order_to_bottom(self);
2250 dispatch_client(Event_Client_Desktop, self, target, old);
2253 /* move all transients */
2254 for (it = self->transients; it != NULL; it = it->next)
2255 if (it->data != self) client_set_desktop_recursive(it->data,
2259 void client_set_desktop(ObClient *self, guint target, gboolean donthide)
2261 client_set_desktop_recursive(client_search_top_transient(self),
2265 ObClient *client_search_modal_child(ObClient *self)
2270 for (it = self->transients; it != NULL; it = it->next) {
2271 ObClient *c = it->data;
2272 if ((ret = client_search_modal_child(c))) return ret;
2273 if (c->modal) return c;
2278 gboolean client_validate(ObClient *self)
2282 XSync(ob_display, FALSE); /* get all events on the server */
2284 if (XCheckTypedWindowEvent(ob_display, self->window, DestroyNotify, &e) ||
2285 XCheckTypedWindowEvent(ob_display, self->window, UnmapNotify, &e)) {
2286 XPutBackEvent(ob_display, &e);
2293 void client_set_wm_state(ObClient *self, long state)
2295 if (state == self->wmstate) return; /* no change */
2299 client_iconify(self, TRUE, TRUE);
2302 client_iconify(self, FALSE, TRUE);
2307 void client_set_state(ObClient *self, Atom action, long data1, long data2)
2309 gboolean shaded = self->shaded;
2310 gboolean fullscreen = self->fullscreen;
2311 gboolean max_horz = self->max_horz;
2312 gboolean max_vert = self->max_vert;
2315 if (!(action == prop_atoms.net_wm_state_add ||
2316 action == prop_atoms.net_wm_state_remove ||
2317 action == prop_atoms.net_wm_state_toggle))
2318 /* an invalid action was passed to the client message, ignore it */
2321 for (i = 0; i < 2; ++i) {
2322 Atom state = i == 0 ? data1 : data2;
2324 if (!state) continue;
2326 /* if toggling, then pick whether we're adding or removing */
2327 if (action == prop_atoms.net_wm_state_toggle) {
2328 if (state == prop_atoms.net_wm_state_modal)
2329 action = self->modal ? prop_atoms.net_wm_state_remove :
2330 prop_atoms.net_wm_state_add;
2331 else if (state == prop_atoms.net_wm_state_maximized_vert)
2332 action = self->max_vert ? prop_atoms.net_wm_state_remove :
2333 prop_atoms.net_wm_state_add;
2334 else if (state == prop_atoms.net_wm_state_maximized_horz)
2335 action = self->max_horz ? prop_atoms.net_wm_state_remove :
2336 prop_atoms.net_wm_state_add;
2337 else if (state == prop_atoms.net_wm_state_shaded)
2338 action = self->shaded ? prop_atoms.net_wm_state_remove :
2339 prop_atoms.net_wm_state_add;
2340 else if (state == prop_atoms.net_wm_state_skip_taskbar)
2341 action = self->skip_taskbar ?
2342 prop_atoms.net_wm_state_remove :
2343 prop_atoms.net_wm_state_add;
2344 else if (state == prop_atoms.net_wm_state_skip_pager)
2345 action = self->skip_pager ?
2346 prop_atoms.net_wm_state_remove :
2347 prop_atoms.net_wm_state_add;
2348 else if (state == prop_atoms.net_wm_state_fullscreen)
2349 action = self->fullscreen ?
2350 prop_atoms.net_wm_state_remove :
2351 prop_atoms.net_wm_state_add;
2352 else if (state == prop_atoms.net_wm_state_above)
2353 action = self->above ? prop_atoms.net_wm_state_remove :
2354 prop_atoms.net_wm_state_add;
2355 else if (state == prop_atoms.net_wm_state_below)
2356 action = self->below ? prop_atoms.net_wm_state_remove :
2357 prop_atoms.net_wm_state_add;
2360 if (action == prop_atoms.net_wm_state_add) {
2361 if (state == prop_atoms.net_wm_state_modal) {
2362 /* XXX raise here or something? */
2364 } else if (state == prop_atoms.net_wm_state_maximized_vert) {
2366 } else if (state == prop_atoms.net_wm_state_maximized_horz) {
2368 } else if (state == prop_atoms.net_wm_state_shaded) {
2370 } else if (state == prop_atoms.net_wm_state_skip_taskbar) {
2371 self->skip_taskbar = TRUE;
2372 } else if (state == prop_atoms.net_wm_state_skip_pager) {
2373 self->skip_pager = TRUE;
2374 } else if (state == prop_atoms.net_wm_state_fullscreen) {
2376 } else if (state == prop_atoms.net_wm_state_above) {
2378 } else if (state == prop_atoms.net_wm_state_below) {
2382 } else { /* action == prop_atoms.net_wm_state_remove */
2383 if (state == prop_atoms.net_wm_state_modal) {
2384 self->modal = FALSE;
2385 } else if (state == prop_atoms.net_wm_state_maximized_vert) {
2387 } else if (state == prop_atoms.net_wm_state_maximized_horz) {
2389 } else if (state == prop_atoms.net_wm_state_shaded) {
2391 } else if (state == prop_atoms.net_wm_state_skip_taskbar) {
2392 self->skip_taskbar = FALSE;
2393 } else if (state == prop_atoms.net_wm_state_skip_pager) {
2394 self->skip_pager = FALSE;
2395 } else if (state == prop_atoms.net_wm_state_fullscreen) {
2397 } else if (state == prop_atoms.net_wm_state_above) {
2398 self->above = FALSE;
2399 } else if (state == prop_atoms.net_wm_state_below) {
2400 self->below = FALSE;
2404 if (max_horz != self->max_horz || max_vert != self->max_vert) {
2405 if (max_horz != self->max_horz && max_vert != self->max_vert) {
2407 if (max_horz == max_vert) { /* both going the same way */
2408 client_maximize(self, max_horz, 0, TRUE);
2410 client_maximize(self, max_horz, 1, TRUE);
2411 client_maximize(self, max_vert, 2, TRUE);
2415 if (max_horz != self->max_horz)
2416 client_maximize(self, max_horz, 1, TRUE);
2418 client_maximize(self, max_vert, 2, TRUE);
2421 /* change fullscreen state before shading, as it will affect if the window
2423 if (fullscreen != self->fullscreen)
2424 client_fullscreen(self, fullscreen, TRUE);
2425 if (shaded != self->shaded)
2426 client_shade(self, shaded);
2427 client_calc_layer(self);
2428 client_change_state(self); /* change the hint to reflect these changes */
2431 ObClient *client_focus_target(ObClient *self)
2435 /* if we have a modal child, then focus it, not us */
2436 child = client_search_modal_child(self);
2437 if (child) return child;
2441 gboolean client_can_focus(ObClient *self)
2445 /* choose the correct target */
2446 self = client_focus_target(self);
2448 if (!self->frame->visible)
2451 if (!((self->can_focus || self->focus_notify) &&
2452 (self->desktop == screen_desktop ||
2453 self->desktop == DESKTOP_ALL) &&
2457 /* do a check to see if the window has already been unmapped or destroyed
2458 do this intelligently while watching out for unmaps we've generated
2459 (ignore_unmaps > 0) */
2460 if (XCheckTypedWindowEvent(ob_display, self->window,
2461 DestroyNotify, &ev)) {
2462 XPutBackEvent(ob_display, &ev);
2465 while (XCheckTypedWindowEvent(ob_display, self->window,
2466 UnmapNotify, &ev)) {
2467 if (self->ignore_unmaps) {
2468 self->ignore_unmaps--;
2470 XPutBackEvent(ob_display, &ev);
2478 gboolean client_focus(ObClient *self)
2480 /* choose the correct target */
2481 self = client_focus_target(self);
2483 if (!client_can_focus(self)) {
2484 if (!self->frame->visible) {
2485 /* update the focus lists */
2486 focus_order_to_top(self);
2491 if (self->can_focus)
2492 /* RevertToPointerRoot causes much more headache than RevertToNone, so
2493 I choose to use it always, hopefully to find errors quicker, if any
2494 are left. (I hate X. I hate focus events.) */
2495 XSetInputFocus(ob_display, self->window, RevertToPointerRoot,
2498 if (self->focus_notify) {
2500 ce.xclient.type = ClientMessage;
2501 ce.xclient.message_type = prop_atoms.wm_protocols;
2502 ce.xclient.display = ob_display;
2503 ce.xclient.window = self->window;
2504 ce.xclient.format = 32;
2505 ce.xclient.data.l[0] = prop_atoms.wm_take_focus;
2506 ce.xclient.data.l[1] = event_lasttime;
2507 ce.xclient.data.l[2] = 0l;
2508 ce.xclient.data.l[3] = 0l;
2509 ce.xclient.data.l[4] = 0l;
2510 XSendEvent(ob_display, self->window, FALSE, NoEventMask, &ce);
2514 ob_debug("%sively focusing %lx at %d\n",
2515 (self->can_focus ? "act" : "pass"),
2516 self->window, (int) event_lasttime);
2519 /* Cause the FocusIn to come back to us. Important for desktop switches,
2520 since otherwise we'll have no FocusIn on the queue and send it off to
2521 the focus_backup. */
2522 XSync(ob_display, FALSE);
2526 void client_unfocus(ObClient *self)
2528 g_assert(focus_client == self);
2530 ob_debug("client_unfocus for %lx\n", self->window);
2532 focus_fallback(OB_FOCUS_FALLBACK_UNFOCUSING);
2535 void client_activate(ObClient *self)
2537 if (client_normal(self) && screen_showing_desktop)
2538 screen_show_desktop(FALSE);
2540 client_iconify(self, FALSE, FALSE);
2541 if (self->desktop != DESKTOP_ALL &&
2542 self->desktop != screen_desktop)
2543 screen_set_desktop(self->desktop);
2544 else if (!self->frame->visible)
2545 /* if its not visible for other reasons, then don't mess
2549 client_shade(self, FALSE);
2551 stacking_raise(CLIENT_AS_WINDOW(self));
2554 gboolean client_focused(ObClient *self)
2556 return self == focus_client;
2559 ObClientIcon *client_icon(ObClient *self, int w, int h)
2562 /* si is the smallest image >= req */
2563 /* li is the largest image < req */
2564 unsigned long size, smallest = 0xffffffff, largest = 0, si = 0, li = 0;
2566 if (!self->nicons) return NULL;
2568 for (i = 0; i < self->nicons; ++i) {
2569 size = self->icons[i].width * self->icons[i].height;
2570 if (size < smallest && size >= (unsigned)(w * h)) {
2574 if (size > largest && size <= (unsigned)(w * h)) {
2579 if (largest == 0) /* didnt find one smaller than the requested size */
2580 return &self->icons[si];
2581 return &self->icons[li];
2584 /* this be mostly ripped from fvwm */
2585 ObClient *client_find_directional(ObClient *c, ObDirection dir)
2587 int my_cx, my_cy, his_cx, his_cy;
2590 int score, best_score;
2591 ObClient *best_client, *cur;
2597 /* first, find the centre coords of the currently focused window */
2598 my_cx = c->frame->area.x + c->frame->area.width / 2;
2599 my_cy = c->frame->area.y + c->frame->area.height / 2;
2604 for(it = g_list_first(client_list); it; it = it->next) {
2607 /* the currently selected window isn't interesting */
2610 if (!client_normal(cur))
2612 if(c->desktop != cur->desktop && cur->desktop != DESKTOP_ALL)
2616 if(client_focus_target(cur) == cur &&
2617 !(cur->can_focus || cur->focus_notify))
2620 /* find the centre coords of this window, from the
2621 * currently focused window's point of view */
2622 his_cx = (cur->frame->area.x - my_cx)
2623 + cur->frame->area.width / 2;
2624 his_cy = (cur->frame->area.y - my_cy)
2625 + cur->frame->area.height / 2;
2627 if(dir == OB_DIRECTION_NORTHEAST || dir == OB_DIRECTION_SOUTHEAST ||
2628 dir == OB_DIRECTION_SOUTHWEST || dir == OB_DIRECTION_NORTHWEST) {
2630 /* Rotate the diagonals 45 degrees counterclockwise.
2631 * To do this, multiply the matrix /+h +h\ with the
2632 * vector (x y). \-h +h/
2633 * h = sqrt(0.5). We can set h := 1 since absolute
2634 * distance doesn't matter here. */
2635 tx = his_cx + his_cy;
2636 his_cy = -his_cx + his_cy;
2641 case OB_DIRECTION_NORTH:
2642 case OB_DIRECTION_SOUTH:
2643 case OB_DIRECTION_NORTHEAST:
2644 case OB_DIRECTION_SOUTHWEST:
2645 offset = (his_cx < 0) ? -his_cx : his_cx;
2646 distance = ((dir == OB_DIRECTION_NORTH ||
2647 dir == OB_DIRECTION_NORTHEAST) ?
2650 case OB_DIRECTION_EAST:
2651 case OB_DIRECTION_WEST:
2652 case OB_DIRECTION_SOUTHEAST:
2653 case OB_DIRECTION_NORTHWEST:
2654 offset = (his_cy < 0) ? -his_cy : his_cy;
2655 distance = ((dir == OB_DIRECTION_WEST ||
2656 dir == OB_DIRECTION_NORTHWEST) ?
2661 /* the target must be in the requested direction */
2665 /* Calculate score for this window. The smaller the better. */
2666 score = distance + offset;
2668 /* windows more than 45 degrees off the direction are
2669 * heavily penalized and will only be chosen if nothing
2670 * else within a million pixels */
2671 if(offset > distance)
2674 if(best_score == -1 || score < best_score)
2682 void client_set_layer(ObClient *self, int layer)
2686 self->above = FALSE;
2687 } else if (layer == 0) {
2688 self->below = self->above = FALSE;
2690 self->below = FALSE;
2693 client_calc_layer(self);
2694 client_change_state(self); /* reflect this in the state hints */
2697 guint client_monitor(ObClient *self)
2701 for (i = 0; i < screen_num_monitors; ++i) {
2702 Rect *area = screen_physical_area_monitor(i);
2703 if (RECT_INTERSECTS_RECT(*area, self->frame->area))
2706 if (i == screen_num_monitors) i = 0;
2707 g_assert(i < screen_num_monitors);
2711 ObClient *client_search_top_transient(ObClient *self)
2713 /* move up the transient chain as far as possible */
2714 if (self->transient_for) {
2715 if (self->transient_for != OB_TRAN_GROUP) {
2716 return client_search_top_transient(self->transient_for);
2720 for (it = self->group->members; it; it = it->next) {
2721 ObClient *c = it->data;
2723 /* checking transient_for prevents infinate loops! */
2724 if (c != self && !c->transient_for)
2735 ObClient *client_search_transient(ObClient *self, ObClient *search)
2739 for (sit = self->transients; sit; sit = g_slist_next(sit)) {
2740 if (sit->data == search)
2742 if (client_search_transient(sit->data, search))
2748 gchar* client_get_sm_client_id(ObClient *self)
2752 if (!PROP_GETS(self->window, sm_client_id, locale, &id) && self->group)
2753 PROP_GETS(self->group->leader, sm_client_id, locale, &id);
2757 /* finds the nearest edge in the given direction from the current client
2758 * note to self: the edge is the -frame- edge (the actual one), not the
2761 int client_directional_edge_search(ObClient *c, ObDirection dir)
2764 int my_edge_start, my_edge_end, my_offset;
2771 a = screen_area(c->desktop);
2774 case OB_DIRECTION_NORTH:
2775 my_edge_start = c->frame->area.x;
2776 my_edge_end = c->frame->area.x + c->frame->area.width;
2777 my_offset = c->frame->area.y;
2779 dest = a->y; /* default: top of screen */
2781 for(it = g_list_first(client_list); it; it = it->next) {
2782 int his_edge_start, his_edge_end, his_offset;
2783 ObClient *cur = it->data;
2787 if(!client_normal(cur))
2789 if(c->desktop != cur->desktop && cur->desktop != DESKTOP_ALL)
2794 his_edge_start = cur->frame->area.x;
2795 his_edge_end = cur->frame->area.x + cur->frame->area.width;
2796 his_offset = cur->frame->area.y + cur->frame->area.height;
2798 if(his_offset + c->size_inc.height > my_offset)
2801 if(his_offset < dest)
2804 if(his_edge_start >= my_edge_start &&
2805 his_edge_start <= my_edge_end)
2808 if(my_edge_start >= his_edge_start &&
2809 my_edge_start <= his_edge_end)
2814 case OB_DIRECTION_SOUTH:
2815 my_edge_start = c->frame->area.x;
2816 my_edge_end = c->frame->area.x + c->frame->area.width;
2817 my_offset = c->frame->area.y + c->frame->area.height;
2819 dest = a->y + a->height; /* default: bottom of screen */
2821 for(it = g_list_first(client_list); it; it = it->next) {
2822 int his_edge_start, his_edge_end, his_offset;
2823 ObClient *cur = it->data;
2827 if(!client_normal(cur))
2829 if(c->desktop != cur->desktop && cur->desktop != DESKTOP_ALL)
2834 his_edge_start = cur->frame->area.x;
2835 his_edge_end = cur->frame->area.x + cur->frame->area.width;
2836 his_offset = cur->frame->area.y;
2839 if(his_offset - c->size_inc.height < my_offset)
2842 if(his_offset > dest)
2845 if(his_edge_start >= my_edge_start &&
2846 his_edge_start <= my_edge_end)
2849 if(my_edge_start >= his_edge_start &&
2850 my_edge_start <= his_edge_end)
2855 case OB_DIRECTION_WEST:
2856 my_edge_start = c->frame->area.y;
2857 my_edge_end = c->frame->area.y + c->frame->area.height;
2858 my_offset = c->frame->area.x;
2860 dest = a->x; /* default: leftmost egde of screen */
2862 for(it = g_list_first(client_list); it; it = it->next) {
2863 int his_edge_start, his_edge_end, his_offset;
2864 ObClient *cur = it->data;
2868 if(!client_normal(cur))
2870 if(c->desktop != cur->desktop && cur->desktop != DESKTOP_ALL)
2875 his_edge_start = cur->frame->area.y;
2876 his_edge_end = cur->frame->area.y + cur->frame->area.height;
2877 his_offset = cur->frame->area.x + cur->frame->area.width;
2879 if(his_offset + c->size_inc.width > my_offset)
2882 if(his_offset < dest)
2885 if(his_edge_start >= my_edge_start &&
2886 his_edge_start <= my_edge_end)
2889 if(my_edge_start >= his_edge_start &&
2890 my_edge_start <= his_edge_end)
2896 case OB_DIRECTION_EAST:
2897 my_edge_start = c->frame->area.y;
2898 my_edge_end = c->frame->area.y + c->frame->area.height;
2899 my_offset = c->frame->area.x + c->frame->area.width;
2901 dest = a->x + a->width; /* default: rightmost edge of screen */
2903 for(it = g_list_first(client_list); it; it = it->next) {
2904 int his_edge_start, his_edge_end, his_offset;
2905 ObClient *cur = it->data;
2909 if(!client_normal(cur))
2911 if(c->desktop != cur->desktop && cur->desktop != DESKTOP_ALL)
2916 his_edge_start = cur->frame->area.y;
2917 his_edge_end = cur->frame->area.y + cur->frame->area.height;
2918 his_offset = cur->frame->area.x;
2920 if(his_offset - c->size_inc.width < my_offset)
2923 if(his_offset > dest)
2926 if(his_edge_start >= my_edge_start &&
2927 his_edge_start <= my_edge_end)
2930 if(my_edge_start >= his_edge_start &&
2931 my_edge_start <= his_edge_end)
2936 case OB_DIRECTION_NORTHEAST:
2937 case OB_DIRECTION_SOUTHEAST:
2938 case OB_DIRECTION_NORTHWEST:
2939 case OB_DIRECTION_SOUTHWEST:
2940 /* not implemented */
2943 g_assert_not_reached();