7 #include "moveresize.h"
10 #include "extensions.h"
20 #include "menuframe.h"
23 #include "render/render.h"
26 #include <X11/Xutil.h>
28 /*! The event mask to grab on client windows */
29 #define CLIENT_EVENTMASK (PropertyChangeMask | FocusChangeMask | \
32 #define CLIENT_NOPROPAGATEMASK (ButtonPressMask | ButtonReleaseMask | \
35 GList *client_list = NULL;
36 GSList *client_destructors = NULL;
38 static void client_get_all(ObClient *self);
39 static void client_toggle_border(ObClient *self, gboolean show);
40 static void client_get_area(ObClient *self);
41 static void client_get_desktop(ObClient *self);
42 static void client_get_state(ObClient *self);
43 static void client_get_shaped(ObClient *self);
44 static void client_get_mwm_hints(ObClient *self);
45 static void client_get_gravity(ObClient *self);
46 static void client_showhide(ObClient *self);
47 static void client_change_allowed_actions(ObClient *self);
48 static void client_change_state(ObClient *self);
49 static void client_apply_startup_state(ObClient *self);
50 static void client_restore_session_state(ObClient *self);
51 static void client_restore_session_stacking(ObClient *self);
58 void client_shutdown()
62 void client_add_destructor(ObClientDestructorFunc func)
64 client_destructors = g_slist_prepend(client_destructors, (gpointer)func);
67 void client_remove_destructor(ObClientDestructorFunc func)
69 client_destructors = g_slist_remove(client_destructors, (gpointer)func);
72 void client_set_list()
74 Window *windows, *win_it;
76 guint size = g_list_length(client_list);
78 /* create an array of the window ids */
80 windows = g_new(Window, size);
82 for (it = client_list; it != NULL; it = it->next, ++win_it)
83 *win_it = ((ObClient*)it->data)->window;
87 PROP_SETA32(RootWindow(ob_display, ob_screen),
88 net_client_list, window, (guint32*)windows, size);
97 void client_foreach_transient(ObClient *self, ObClientForeachFunc func, void *data)
101 for (it = self->transients; it; it = it->next) {
102 if (!func(it->data, data)) return;
103 client_foreach_transient(it->data, func, data);
107 void client_foreach_ancestor(ObClient *self, ObClientForeachFunc func, void *data)
109 if (self->transient_for) {
110 if (self->transient_for != OB_TRAN_GROUP) {
111 if (!func(self->transient_for, data)) return;
112 client_foreach_ancestor(self->transient_for, func, data);
116 for (it = self->group->members; it; it = it->next)
117 if (it->data != self &&
118 !((ObClient*)it->data)->transient_for) {
119 if (!func(it->data, data)) return;
120 client_foreach_ancestor(it->data, func, data);
127 void client_manage_all()
129 unsigned int i, j, nchild;
132 XWindowAttributes attrib;
134 XQueryTree(ob_display, RootWindow(ob_display, ob_screen),
135 &w, &w, &children, &nchild);
137 /* remove all icon windows from the list */
138 for (i = 0; i < nchild; i++) {
139 if (children[i] == None) continue;
140 wmhints = XGetWMHints(ob_display, children[i]);
142 if ((wmhints->flags & IconWindowHint) &&
143 (wmhints->icon_window != children[i]))
144 for (j = 0; j < nchild; j++)
145 if (children[j] == wmhints->icon_window) {
153 for (i = 0; i < nchild; ++i) {
154 if (children[i] == None)
156 if (XGetWindowAttributes(ob_display, children[i], &attrib)) {
157 if (attrib.override_redirect) continue;
159 if (attrib.map_state != IsUnmapped)
160 client_manage(children[i]);
165 /* stack them as they were on startup!
166 why with stacking_lower? Why, because then windows who aren't in the
167 stacking list are on the top where you can see them instead of buried
169 for (i = startup_stack_size; i > 0; --i) {
172 w = startup_stack_order[i-1];
173 obw = g_hash_table_lookup(window_map, &w);
175 g_assert(WINDOW_IS_CLIENT(obw));
176 stacking_lower(CLIENT_AS_WINDOW(obw));
179 g_free(startup_stack_order);
180 startup_stack_order = NULL;
181 startup_stack_size = 0;
183 if (config_focus_new) {
186 active = g_hash_table_lookup(window_map, &startup_active);
188 g_assert(WINDOW_IS_CLIENT(active));
189 if (!client_focus(WINDOW_AS_CLIENT(active)))
190 focus_fallback(OB_FOCUS_FALLBACK_NOFOCUS);
192 focus_fallback(OB_FOCUS_FALLBACK_NOFOCUS);
196 void client_manage(Window window)
200 XWindowAttributes attrib;
201 XSetWindowAttributes attrib_set;
203 gboolean activate = FALSE;
207 /* check if it has already been unmapped by the time we started mapping
208 the grab does a sync so we don't have to here */
209 if (XCheckTypedWindowEvent(ob_display, window, DestroyNotify, &e) ||
210 XCheckTypedWindowEvent(ob_display, window, UnmapNotify, &e)) {
211 XPutBackEvent(ob_display, &e);
214 return; /* don't manage it */
217 /* make sure it isn't an override-redirect window */
218 if (!XGetWindowAttributes(ob_display, window, &attrib) ||
219 attrib.override_redirect) {
221 return; /* don't manage it */
224 /* is the window a docking app */
225 if ((wmhint = XGetWMHints(ob_display, window))) {
226 if ((wmhint->flags & StateHint) &&
227 wmhint->initial_state == WithdrawnState) {
228 dock_add(window, wmhint);
236 ob_debug("Managing window: %lx\n", window);
238 /* choose the events we want to receive on the CLIENT window */
239 attrib_set.event_mask = CLIENT_EVENTMASK;
240 attrib_set.do_not_propagate_mask = CLIENT_NOPROPAGATEMASK;
241 XChangeWindowAttributes(ob_display, window,
242 CWEventMask|CWDontPropagate, &attrib_set);
245 /* create the ObClient struct, and populate it from the hints on the
247 self = g_new0(ObClient, 1);
248 self->obwin.type = Window_Client;
249 self->window = window;
251 client_get_all(self);
252 client_restore_session_state(self);
254 client_change_state(self);
256 /* remove the client's border (and adjust re gravity) */
257 client_toggle_border(self, FALSE);
259 /* specify that if we exit, the window should not be destroyed and should
260 be reparented back to root automatically */
261 XChangeSaveSet(ob_display, window, SetModeInsert);
263 /* create the decoration frame for the client window */
264 self->frame = frame_new();
266 frame_grab_client(self->frame, self);
270 client_apply_startup_state(self);
272 /* update the focus lists */
273 focus_order_add_new(self);
275 stacking_add(CLIENT_AS_WINDOW(self));
276 client_restore_session_stacking(self);
278 /* focus the new window? */
279 if (ob_state() != OB_STATE_STARTING && config_focus_new &&
280 /* note the check against Type_Normal/Dialog, not client_normal(self),
281 which would also include other types. in this case we want more
282 strict rules for focus */
283 (self->type == OB_CLIENT_TYPE_NORMAL ||
284 self->type == OB_CLIENT_TYPE_DIALOG))
288 if (self->desktop != screen_desktop) {
289 /* activate the window */
292 gboolean group_foc = FALSE;
297 for (it = self->group->members; it; it = it->next)
299 if (client_focused(it->data))
307 (!self->transient_for && (!self->group ||
308 !self->group->members->next))) ||
309 client_search_focus_tree_full(self) ||
311 !client_normal(focus_client))
313 /* activate the window */
320 if (ob_state() == OB_STATE_RUNNING) {
321 int x = self->area.x, ox = x;
322 int y = self->area.y, oy = y;
324 place_client(self, &x, &y);
326 /* make sure the window is visible */
327 client_find_onscreen(self, &x, &y,
328 self->frame->area.width,
329 self->frame->area.height,
330 client_normal(self));
332 if (x != ox || y != oy)
333 client_configure(self, OB_CORNER_TOPLEFT, x, y,
334 self->area.width, self->area.height,
338 client_showhide(self);
340 /* use client_focus instead of client_activate cuz client_activate does
341 stuff like switch desktops etc and I'm not interested in all that when
342 a window maps since its not based on an action from the user like
343 clicking a window to activate is. so keep the new window out of the way
345 if (activate) client_focus(self);
347 /* client_activate does this but we aret using it so we have to do it
349 if (screen_showing_desktop)
350 screen_show_desktop(FALSE);
352 /* add to client list/map */
353 client_list = g_list_append(client_list, self);
354 g_hash_table_insert(window_map, &self->window, self);
356 /* this has to happen after we're in the client_list */
357 screen_update_areas();
359 /* update the list hints */
362 keyboard_grab_for_client(self, TRUE);
363 mouse_grab_for_client(self, TRUE);
365 ob_debug("Managed window 0x%lx (%s)\n", window, self->class);
368 void client_unmanage_all()
370 while (client_list != NULL)
371 client_unmanage(client_list->data);
374 void client_unmanage(ObClient *self)
379 ob_debug("Unmanaging window: %lx (%s)\n", self->window, self->class);
381 g_assert(self != NULL);
383 keyboard_grab_for_client(self, FALSE);
384 mouse_grab_for_client(self, FALSE);
386 /* remove the window from our save set */
387 XChangeSaveSet(ob_display, self->window, SetModeDelete);
389 /* we dont want events no more */
390 XSelectInput(ob_display, self->window, NoEventMask);
392 frame_hide(self->frame);
394 client_list = g_list_remove(client_list, self);
395 stacking_remove(self);
396 g_hash_table_remove(window_map, &self->window);
398 /* update the focus lists */
399 focus_order_remove(self);
401 /* once the client is out of the list, update the struts to remove it's
403 screen_update_areas();
405 /* tell our parent(s) that we're gone */
406 if (self->transient_for == OB_TRAN_GROUP) { /* transient of group */
409 for (it = self->group->members; it; it = it->next)
410 if (it->data != self)
411 ((ObClient*)it->data)->transients =
412 g_slist_remove(((ObClient*)it->data)->transients, self);
413 } else if (self->transient_for) { /* transient of window */
414 self->transient_for->transients =
415 g_slist_remove(self->transient_for->transients, self);
418 /* tell our transients that we're gone */
419 for (it = self->transients; it != NULL; it = it->next) {
420 if (((ObClient*)it->data)->transient_for != OB_TRAN_GROUP) {
421 ((ObClient*)it->data)->transient_for = NULL;
422 client_calc_layer(it->data);
426 for (it = client_destructors; it; it = g_slist_next(it)) {
427 ObClientDestructorFunc func = (ObClientDestructorFunc) it->data;
431 if (focus_client == self) {
434 /* focus the last focused window on the desktop, and ignore enter
435 events from the unmap so it doesnt mess with the focus */
436 while (XCheckTypedEvent(ob_display, EnterNotify, &e));
437 client_unfocus(self);
440 /* remove from its group */
442 group_remove(self->group, self);
446 /* give the client its border back */
447 client_toggle_border(self, TRUE);
449 /* reparent the window out of the frame, and free the frame */
450 frame_release_client(self->frame, self);
453 if (ob_state() != OB_STATE_EXITING) {
454 /* these values should not be persisted across a window
456 PROP_ERASE(self->window, net_wm_desktop);
457 PROP_ERASE(self->window, net_wm_state);
458 PROP_ERASE(self->window, wm_state);
460 /* if we're left in an iconic state, the client wont be mapped. this is
461 bad, since we will no longer be managing the window on restart */
463 XMapWindow(ob_display, self->window);
467 ob_debug("Unmanaged window 0x%lx\n", self->window);
469 /* free all data allocated in the client struct */
470 g_slist_free(self->transients);
471 for (j = 0; j < self->nicons; ++j)
472 g_free(self->icons[j].data);
473 if (self->nicons > 0)
476 g_free(self->icon_title);
482 /* update the list hints */
486 static void client_restore_session_state(ObClient *self)
490 if (!(it = session_state_find(self)))
493 self->session = it->data;
495 RECT_SET(self->area, self->session->x, self->session->y,
496 self->session->w, self->session->h);
497 self->positioned = TRUE;
498 XResizeWindow(ob_display, self->window,
499 self->session->w, self->session->h);
501 self->desktop = (self->session->desktop == DESKTOP_ALL ?
502 self->session->desktop :
503 MIN(screen_num_desktops - 1, self->session->desktop));
504 PROP_SET32(self->window, net_wm_desktop, cardinal, self->desktop);
506 self->shaded = self->session->shaded;
507 self->iconic = self->session->iconic;
508 self->skip_pager = self->session->skip_pager;
509 self->skip_taskbar = self->session->skip_taskbar;
510 self->fullscreen = self->session->fullscreen;
511 self->above = self->session->above;
512 self->below = self->session->below;
513 self->max_horz = self->session->max_horz;
514 self->max_vert = self->session->max_vert;
517 static void client_restore_session_stacking(ObClient *self)
521 if (!self->session) return;
523 it = g_list_find(session_saved_state, self->session);
524 for (it = g_list_previous(it); it; it = g_list_previous(it)) {
527 for (cit = client_list; cit; cit = g_list_next(cit))
528 if (session_state_cmp(it->data, cit->data))
531 client_calc_layer(self);
532 stacking_below(CLIENT_AS_WINDOW(self),
533 CLIENT_AS_WINDOW(cit->data));
539 void client_move_onscreen(ObClient *self, gboolean rude)
541 int x = self->area.x;
542 int y = self->area.y;
543 if (client_find_onscreen(self, &x, &y,
544 self->frame->area.width,
545 self->frame->area.height, rude)) {
546 client_configure(self, OB_CORNER_TOPLEFT, x, y,
547 self->area.width, self->area.height,
552 gboolean client_find_onscreen(ObClient *self, int *x, int *y, int w, int h,
556 int ox = *x, oy = *y;
558 frame_client_gravity(self->frame, x, y); /* get where the frame
561 /* XXX watch for xinerama dead areas */
563 a = screen_area(self->desktop);
564 if (!self->strut.right && *x >= a->x + a->width - 1)
565 *x = a->x + a->width - self->frame->area.width;
566 if (!self->strut.bottom && *y >= a->y + a->height - 1)
567 *y = a->y + a->height - self->frame->area.height;
568 if (!self->strut.left && *x + self->frame->area.width - 1 < a->x)
570 if (!self->strut.top && *y + self->frame->area.height - 1 < a->y)
574 /* this is my MOZILLA BITCHSLAP. oh ya it fucking feels good.
575 Java can suck it too. */
577 /* dont let windows map/move into the strut unless they
578 are bigger than the available area */
580 if (!self->strut.left && *x < a->x) *x = a->x;
581 if (!self->strut.right && *x + w > a->x + a->width)
582 *x = a->x + a->width - w;
584 if (h <= a->height) {
585 if (!self->strut.top && *y < a->y) *y = a->y;
586 if (!self->strut.bottom && *y + h > a->y + a->height)
587 *y = a->y + a->height - h;
591 frame_frame_gravity(self->frame, x, y); /* get where the client
594 return ox != *x || oy != *y;
597 static void client_toggle_border(ObClient *self, gboolean show)
599 /* adjust our idea of where the client is, based on its border. When the
600 border is removed, the client should now be considered to be in a
602 when re-adding the border to the client, the same operation needs to be
604 int oldx = self->area.x, oldy = self->area.y;
605 int x = oldx, y = oldy;
606 switch(self->gravity) {
608 case NorthWestGravity:
610 case SouthWestGravity:
612 case NorthEastGravity:
614 case SouthEastGravity:
615 if (show) x -= self->border_width * 2;
616 else x += self->border_width * 2;
623 if (show) x -= self->border_width;
624 else x += self->border_width;
627 switch(self->gravity) {
629 case NorthWestGravity:
631 case NorthEastGravity:
633 case SouthWestGravity:
635 case SouthEastGravity:
636 if (show) y -= self->border_width * 2;
637 else y += self->border_width * 2;
644 if (show) y -= self->border_width;
645 else y += self->border_width;
652 XSetWindowBorderWidth(ob_display, self->window, self->border_width);
654 /* move the client so it is back it the right spot _with_ its
656 if (x != oldx || y != oldy)
657 XMoveWindow(ob_display, self->window, x, y);
659 XSetWindowBorderWidth(ob_display, self->window, 0);
663 static void client_get_all(ObClient *self)
665 /* non-zero defaults */
666 self->title_count = 1;
667 self->wmstate = NormalState;
669 self->decorate = TRUE;
671 client_get_area(self);
672 client_update_transient_for(self);
673 client_update_wmhints(self);
674 client_get_desktop(self);
675 client_get_state(self);
676 client_get_shaped(self);
678 client_get_mwm_hints(self);
679 client_get_type(self);/* this can change the mwmhints for special cases */
681 client_update_protocols(self);
683 client_get_gravity(self); /* get the attribute gravity */
684 client_update_normal_hints(self); /* this may override the attribute
687 /* got the type, the mwmhints, the protocols, and the normal hints
688 (min/max sizes), so we're ready to set up the decorations/functions */
689 client_setup_decor_and_functions(self);
691 client_update_title(self);
692 client_update_class(self);
693 client_update_strut(self);
694 client_update_icons(self);
697 static void client_get_area(ObClient *self)
699 XWindowAttributes wattrib;
702 ret = XGetWindowAttributes(ob_display, self->window, &wattrib);
703 g_assert(ret != BadWindow);
705 RECT_SET(self->area, wattrib.x, wattrib.y, wattrib.width, wattrib.height);
706 self->border_width = wattrib.border_width;
709 static void client_get_desktop(ObClient *self)
711 guint32 d = screen_num_desktops; /* an always-invalid value */
713 if (PROP_GET32(self->window, net_wm_desktop, cardinal, &d)) {
714 if (d >= screen_num_desktops && d != DESKTOP_ALL)
715 self->desktop = screen_num_desktops - 1;
719 gboolean trdesk = FALSE;
721 if (self->transient_for) {
722 if (self->transient_for != OB_TRAN_GROUP) {
723 self->desktop = self->transient_for->desktop;
728 for (it = self->group->members; it; it = it->next)
729 if (it->data != self &&
730 !((ObClient*)it->data)->transient_for) {
731 self->desktop = ((ObClient*)it->data)->desktop;
738 /* defaults to the current desktop */
739 self->desktop = screen_desktop;
741 if (self->desktop != d) {
742 /* set the desktop hint, to make sure that it always exists */
743 PROP_SET32(self->window, net_wm_desktop, cardinal, self->desktop);
747 static void client_get_state(ObClient *self)
752 self->modal = self->shaded = self->max_horz = self->max_vert =
753 self->fullscreen = self->above = self->below = self->iconic =
754 self->skip_taskbar = self->skip_pager = FALSE;
756 if (PROP_GETA32(self->window, net_wm_state, atom, &state, &num)) {
758 for (i = 0; i < num; ++i) {
759 if (state[i] == prop_atoms.net_wm_state_modal)
761 else if (state[i] == prop_atoms.net_wm_state_shaded)
763 else if (state[i] == prop_atoms.net_wm_state_hidden)
765 else if (state[i] == prop_atoms.net_wm_state_skip_taskbar)
766 self->skip_taskbar = TRUE;
767 else if (state[i] == prop_atoms.net_wm_state_skip_pager)
768 self->skip_pager = TRUE;
769 else if (state[i] == prop_atoms.net_wm_state_fullscreen)
770 self->fullscreen = TRUE;
771 else if (state[i] == prop_atoms.net_wm_state_maximized_vert)
772 self->max_vert = TRUE;
773 else if (state[i] == prop_atoms.net_wm_state_maximized_horz)
774 self->max_horz = TRUE;
775 else if (state[i] == prop_atoms.net_wm_state_above)
777 else if (state[i] == prop_atoms.net_wm_state_below)
785 static void client_get_shaped(ObClient *self)
787 self->shaped = FALSE;
789 if (extensions_shape) {
794 XShapeSelectInput(ob_display, self->window, ShapeNotifyMask);
796 XShapeQueryExtents(ob_display, self->window, &s, &foo,
797 &foo, &ufoo, &ufoo, &foo, &foo, &foo, &ufoo,
799 self->shaped = (s != 0);
804 void client_update_transient_for(ObClient *self)
807 ObClient *target = NULL;
809 if (XGetTransientForHint(ob_display, self->window, &t)) {
810 self->transient = TRUE;
811 if (t != self->window) { /* cant be transient to itself! */
812 target = g_hash_table_lookup(window_map, &t);
813 /* if this happens then we need to check for it*/
814 g_assert(target != self);
815 g_assert(!target || WINDOW_IS_CLIENT(target));
817 if (!target && self->group) {
818 /* not transient to a client, see if it is transient for a
820 if (t == self->group->leader ||
822 t == RootWindow(ob_display, ob_screen)) {
823 /* window is a transient for its group! */
824 target = OB_TRAN_GROUP;
829 self->transient = FALSE;
831 /* if anything has changed... */
832 if (target != self->transient_for) {
833 if (self->transient_for == OB_TRAN_GROUP) { /* transient of group */
836 /* remove from old parents */
837 for (it = self->group->members; it; it = g_slist_next(it)) {
838 ObClient *c = it->data;
839 if (c != self && !c->transient_for)
840 c->transients = g_slist_remove(c->transients, self);
842 } else if (self->transient_for != NULL) { /* transient of window */
843 /* remove from old parent */
844 self->transient_for->transients =
845 g_slist_remove(self->transient_for->transients, self);
847 self->transient_for = target;
848 if (self->transient_for == OB_TRAN_GROUP) { /* transient of group */
851 /* add to new parents */
852 for (it = self->group->members; it; it = g_slist_next(it)) {
853 ObClient *c = it->data;
854 if (c != self && !c->transient_for)
855 c->transients = g_slist_append(c->transients, self);
858 /* remove all transients which are in the group, that causes
859 circlular pointer hell of doom */
860 for (it = self->group->members; it; it = g_slist_next(it)) {
862 for (sit = self->transients; sit; sit = next) {
863 next = g_slist_next(sit);
864 if (sit->data == it->data)
866 g_slist_delete_link(self->transients, sit);
869 } else if (self->transient_for != NULL) { /* transient of window */
870 /* add to new parent */
871 self->transient_for->transients =
872 g_slist_append(self->transient_for->transients, self);
877 static void client_get_mwm_hints(ObClient *self)
882 self->mwmhints.flags = 0; /* default to none */
884 if (PROP_GETA32(self->window, motif_wm_hints, motif_wm_hints,
886 if (num >= OB_MWM_ELEMENTS) {
887 self->mwmhints.flags = hints[0];
888 self->mwmhints.functions = hints[1];
889 self->mwmhints.decorations = hints[2];
895 void client_get_type(ObClient *self)
902 if (PROP_GETA32(self->window, net_wm_window_type, atom, &val, &num)) {
903 /* use the first value that we know about in the array */
904 for (i = 0; i < num; ++i) {
905 if (val[i] == prop_atoms.net_wm_window_type_desktop)
906 self->type = OB_CLIENT_TYPE_DESKTOP;
907 else if (val[i] == prop_atoms.net_wm_window_type_dock)
908 self->type = OB_CLIENT_TYPE_DOCK;
909 else if (val[i] == prop_atoms.net_wm_window_type_toolbar)
910 self->type = OB_CLIENT_TYPE_TOOLBAR;
911 else if (val[i] == prop_atoms.net_wm_window_type_menu)
912 self->type = OB_CLIENT_TYPE_MENU;
913 else if (val[i] == prop_atoms.net_wm_window_type_utility)
914 self->type = OB_CLIENT_TYPE_UTILITY;
915 else if (val[i] == prop_atoms.net_wm_window_type_splash)
916 self->type = OB_CLIENT_TYPE_SPLASH;
917 else if (val[i] == prop_atoms.net_wm_window_type_dialog)
918 self->type = OB_CLIENT_TYPE_DIALOG;
919 else if (val[i] == prop_atoms.net_wm_window_type_normal)
920 self->type = OB_CLIENT_TYPE_NORMAL;
921 else if (val[i] == prop_atoms.kde_net_wm_window_type_override) {
922 /* prevent this window from getting any decor or
924 self->mwmhints.flags &= (OB_MWM_FLAG_FUNCTIONS |
925 OB_MWM_FLAG_DECORATIONS);
926 self->mwmhints.decorations = 0;
927 self->mwmhints.functions = 0;
929 if (self->type != (ObClientType) -1)
930 break; /* grab the first legit type */
935 if (self->type == (ObClientType) -1) {
936 /*the window type hint was not set, which means we either classify
937 ourself as a normal window or a dialog, depending on if we are a
940 self->type = OB_CLIENT_TYPE_DIALOG;
942 self->type = OB_CLIENT_TYPE_NORMAL;
946 void client_update_protocols(ObClient *self)
951 self->focus_notify = FALSE;
952 self->delete_window = FALSE;
954 if (PROP_GETA32(self->window, wm_protocols, atom, &proto, &num_return)) {
955 for (i = 0; i < num_return; ++i) {
956 if (proto[i] == prop_atoms.wm_delete_window) {
957 /* this means we can request the window to close */
958 self->delete_window = TRUE;
959 } else if (proto[i] == prop_atoms.wm_take_focus)
960 /* if this protocol is requested, then the window will be
961 notified whenever we want it to receive focus */
962 self->focus_notify = TRUE;
968 static void client_get_gravity(ObClient *self)
970 XWindowAttributes wattrib;
973 ret = XGetWindowAttributes(ob_display, self->window, &wattrib);
974 g_assert(ret != BadWindow);
975 self->gravity = wattrib.win_gravity;
978 void client_update_normal_hints(ObClient *self)
982 int oldgravity = self->gravity;
985 self->min_ratio = 0.0f;
986 self->max_ratio = 0.0f;
987 SIZE_SET(self->size_inc, 1, 1);
988 SIZE_SET(self->base_size, 0, 0);
989 SIZE_SET(self->min_size, 0, 0);
990 SIZE_SET(self->max_size, G_MAXINT, G_MAXINT);
992 /* get the hints from the window */
993 if (XGetWMNormalHints(ob_display, self->window, &size, &ret)) {
994 self->positioned = !!(size.flags & (PPosition|USPosition));
996 if (size.flags & PWinGravity) {
997 self->gravity = size.win_gravity;
999 /* if the client has a frame, i.e. has already been mapped and
1000 is changing its gravity */
1001 if (self->frame && self->gravity != oldgravity) {
1002 /* move our idea of the client's position based on its new
1004 self->area.x = self->frame->area.x;
1005 self->area.y = self->frame->area.y;
1006 frame_frame_gravity(self->frame, &self->area.x, &self->area.y);
1010 if (size.flags & PAspect) {
1011 if (size.min_aspect.y)
1012 self->min_ratio = (float)size.min_aspect.x / size.min_aspect.y;
1013 if (size.max_aspect.y)
1014 self->max_ratio = (float)size.max_aspect.x / size.max_aspect.y;
1017 if (size.flags & PMinSize)
1018 SIZE_SET(self->min_size, size.min_width, size.min_height);
1020 if (size.flags & PMaxSize)
1021 SIZE_SET(self->max_size, size.max_width, size.max_height);
1023 if (size.flags & PBaseSize)
1024 SIZE_SET(self->base_size, size.base_width, size.base_height);
1026 if (size.flags & PResizeInc)
1027 SIZE_SET(self->size_inc, size.width_inc, size.height_inc);
1031 void client_setup_decor_and_functions(ObClient *self)
1033 /* start with everything (cept fullscreen) */
1035 (OB_FRAME_DECOR_TITLEBAR |
1036 (ob_rr_theme->show_handle ? OB_FRAME_DECOR_HANDLE : 0) |
1037 OB_FRAME_DECOR_GRIPS |
1038 OB_FRAME_DECOR_BORDER |
1039 OB_FRAME_DECOR_ICON |
1040 OB_FRAME_DECOR_ALLDESKTOPS |
1041 OB_FRAME_DECOR_ICONIFY |
1042 OB_FRAME_DECOR_MAXIMIZE |
1043 OB_FRAME_DECOR_SHADE);
1045 (OB_CLIENT_FUNC_RESIZE |
1046 OB_CLIENT_FUNC_MOVE |
1047 OB_CLIENT_FUNC_ICONIFY |
1048 OB_CLIENT_FUNC_MAXIMIZE |
1049 OB_CLIENT_FUNC_SHADE);
1050 if (self->delete_window) {
1051 self->functions |= OB_CLIENT_FUNC_CLOSE;
1052 self->decorations |= OB_FRAME_DECOR_CLOSE;
1055 if (!(self->min_size.width < self->max_size.width ||
1056 self->min_size.height < self->max_size.height))
1057 self->functions &= ~OB_CLIENT_FUNC_RESIZE;
1059 switch (self->type) {
1060 case OB_CLIENT_TYPE_NORMAL:
1061 /* normal windows retain all of the possible decorations and
1062 functionality, and are the only windows that you can fullscreen */
1063 self->functions |= OB_CLIENT_FUNC_FULLSCREEN;
1066 case OB_CLIENT_TYPE_DIALOG:
1067 case OB_CLIENT_TYPE_UTILITY:
1068 /* these windows cannot be maximized */
1069 self->functions &= ~OB_CLIENT_FUNC_MAXIMIZE;
1072 case OB_CLIENT_TYPE_MENU:
1073 case OB_CLIENT_TYPE_TOOLBAR:
1074 /* these windows get less functionality */
1075 self->functions &= ~(OB_CLIENT_FUNC_ICONIFY | OB_CLIENT_FUNC_RESIZE);
1078 case OB_CLIENT_TYPE_DESKTOP:
1079 case OB_CLIENT_TYPE_DOCK:
1080 case OB_CLIENT_TYPE_SPLASH:
1081 /* none of these windows are manipulated by the window manager */
1082 self->decorations = 0;
1083 self->functions = 0;
1087 /* Mwm Hints are applied subtractively to what has already been chosen for
1088 decor and functionality */
1089 if (self->mwmhints.flags & OB_MWM_FLAG_DECORATIONS) {
1090 if (! (self->mwmhints.decorations & OB_MWM_DECOR_ALL)) {
1091 if (! ((self->mwmhints.decorations & OB_MWM_DECOR_HANDLE) ||
1092 (self->mwmhints.decorations & OB_MWM_DECOR_TITLE)))
1093 /* if the mwm hints request no handle or title, then all
1094 decorations are disabled */
1095 self->decorations = 0;
1099 if (self->mwmhints.flags & OB_MWM_FLAG_FUNCTIONS) {
1100 if (! (self->mwmhints.functions & OB_MWM_FUNC_ALL)) {
1101 if (! (self->mwmhints.functions & OB_MWM_FUNC_RESIZE))
1102 self->functions &= ~OB_CLIENT_FUNC_RESIZE;
1103 if (! (self->mwmhints.functions & OB_MWM_FUNC_MOVE))
1104 self->functions &= ~OB_CLIENT_FUNC_MOVE;
1105 /* dont let mwm hints kill any buttons
1106 if (! (self->mwmhints.functions & OB_MWM_FUNC_ICONIFY))
1107 self->functions &= ~OB_CLIENT_FUNC_ICONIFY;
1108 if (! (self->mwmhints.functions & OB_MWM_FUNC_MAXIMIZE))
1109 self->functions &= ~OB_CLIENT_FUNC_MAXIMIZE;
1111 /* dont let mwm hints kill the close button
1112 if (! (self->mwmhints.functions & MwmFunc_Close))
1113 self->functions &= ~OB_CLIENT_FUNC_CLOSE; */
1117 if (!(self->functions & OB_CLIENT_FUNC_SHADE))
1118 self->decorations &= ~OB_FRAME_DECOR_SHADE;
1119 if (!(self->functions & OB_CLIENT_FUNC_ICONIFY))
1120 self->decorations &= ~OB_FRAME_DECOR_ICONIFY;
1121 if (!(self->functions & OB_CLIENT_FUNC_RESIZE))
1122 self->decorations &= ~OB_FRAME_DECOR_GRIPS;
1124 /* can't maximize without moving/resizing */
1125 if (!((self->functions & OB_CLIENT_FUNC_MAXIMIZE) &&
1126 (self->functions & OB_CLIENT_FUNC_MOVE) &&
1127 (self->functions & OB_CLIENT_FUNC_RESIZE))) {
1128 self->functions &= ~OB_CLIENT_FUNC_MAXIMIZE;
1129 self->decorations &= ~OB_FRAME_DECOR_MAXIMIZE;
1132 /* kill the handle on fully maxed windows */
1133 if (self->max_vert && self->max_horz)
1134 self->decorations &= ~OB_FRAME_DECOR_HANDLE;
1136 /* finally, the user can have requested no decorations, which overrides
1138 if (!self->decorate)
1139 self->decorations = OB_FRAME_DECOR_BORDER;
1141 /* if we don't have a titlebar, then we cannot shade! */
1142 if (!(self->decorations & OB_FRAME_DECOR_TITLEBAR))
1143 self->functions &= ~OB_CLIENT_FUNC_SHADE;
1145 /* now we need to check against rules for the client's current state */
1146 if (self->fullscreen) {
1147 self->functions &= (OB_CLIENT_FUNC_CLOSE |
1148 OB_CLIENT_FUNC_FULLSCREEN |
1149 OB_CLIENT_FUNC_ICONIFY);
1150 self->decorations = 0;
1153 client_change_allowed_actions(self);
1156 /* adjust the client's decorations, etc. */
1157 client_reconfigure(self);
1159 /* this makes sure that these windows appear on all desktops */
1160 if (self->type == OB_CLIENT_TYPE_DESKTOP &&
1161 self->desktop != DESKTOP_ALL)
1163 self->desktop = DESKTOP_ALL;
1168 static void client_change_allowed_actions(ObClient *self)
1173 /* desktop windows are kept on all desktops */
1174 if (self->type != OB_CLIENT_TYPE_DESKTOP)
1175 actions[num++] = prop_atoms.net_wm_action_change_desktop;
1177 if (self->functions & OB_CLIENT_FUNC_SHADE)
1178 actions[num++] = prop_atoms.net_wm_action_shade;
1179 if (self->functions & OB_CLIENT_FUNC_CLOSE)
1180 actions[num++] = prop_atoms.net_wm_action_close;
1181 if (self->functions & OB_CLIENT_FUNC_MOVE)
1182 actions[num++] = prop_atoms.net_wm_action_move;
1183 if (self->functions & OB_CLIENT_FUNC_ICONIFY)
1184 actions[num++] = prop_atoms.net_wm_action_minimize;
1185 if (self->functions & OB_CLIENT_FUNC_RESIZE)
1186 actions[num++] = prop_atoms.net_wm_action_resize;
1187 if (self->functions & OB_CLIENT_FUNC_FULLSCREEN)
1188 actions[num++] = prop_atoms.net_wm_action_fullscreen;
1189 if (self->functions & OB_CLIENT_FUNC_MAXIMIZE) {
1190 actions[num++] = prop_atoms.net_wm_action_maximize_horz;
1191 actions[num++] = prop_atoms.net_wm_action_maximize_vert;
1194 PROP_SETA32(self->window, net_wm_allowed_actions, atom, actions, num);
1196 /* make sure the window isn't breaking any rules now */
1198 if (!(self->functions & OB_CLIENT_FUNC_SHADE) && self->shaded) {
1199 if (self->frame) client_shade(self, FALSE);
1200 else self->shaded = FALSE;
1202 if (!(self->functions & OB_CLIENT_FUNC_ICONIFY) && self->iconic) {
1203 if (self->frame) client_iconify(self, FALSE, TRUE);
1204 else self->iconic = FALSE;
1206 if (!(self->functions & OB_CLIENT_FUNC_FULLSCREEN) && self->fullscreen) {
1207 if (self->frame) client_fullscreen(self, FALSE, TRUE);
1208 else self->fullscreen = FALSE;
1210 if (!(self->functions & OB_CLIENT_FUNC_MAXIMIZE) && (self->max_horz ||
1212 if (self->frame) client_maximize(self, FALSE, 0, TRUE);
1213 else self->max_vert = self->max_horz = FALSE;
1217 void client_reconfigure(ObClient *self)
1219 /* by making this pass FALSE for user, we avoid the emacs event storm where
1220 every configurenotify causes an update in its normal hints, i think this
1221 is generally what we want anyways... */
1222 client_configure(self, OB_CORNER_TOPLEFT, self->area.x, self->area.y,
1223 self->area.width, self->area.height, FALSE, TRUE);
1226 void client_update_wmhints(ObClient *self)
1229 gboolean ur = FALSE;
1232 /* assume a window takes input if it doesnt specify */
1233 self->can_focus = TRUE;
1235 if ((hints = XGetWMHints(ob_display, self->window)) != NULL) {
1236 if (hints->flags & InputHint)
1237 self->can_focus = hints->input;
1239 /* only do this when first managing the window *AND* when we aren't
1241 if (ob_state() != OB_STATE_STARTING && self->frame == NULL)
1242 if (hints->flags & StateHint)
1243 self->iconic = hints->initial_state == IconicState;
1245 if (hints->flags & XUrgencyHint)
1248 if (!(hints->flags & WindowGroupHint))
1249 hints->window_group = None;
1251 /* did the group state change? */
1252 if (hints->window_group !=
1253 (self->group ? self->group->leader : None)) {
1254 /* remove from the old group if there was one */
1255 if (self->group != NULL) {
1256 /* remove transients of the group */
1257 for (it = self->group->members; it; it = it->next)
1258 self->transients = g_slist_remove(self->transients,
1260 group_remove(self->group, self);
1263 if (hints->window_group != None) {
1264 self->group = group_add(hints->window_group, self);
1266 /* i can only have transients from the group if i am not
1268 if (!self->transient_for) {
1269 /* add other transients of the group that are already
1271 for (it = self->group->members; it; it = it->next) {
1272 ObClient *c = it->data;
1273 if (c != self && c->transient_for == OB_TRAN_GROUP)
1275 g_slist_append(self->transients, c);
1280 /* because the self->transient flag wont change from this call,
1281 we don't need to update the window's type and such, only its
1282 transient_for, and the transients lists of other windows in
1283 the group may be affected */
1284 client_update_transient_for(self);
1287 /* the WM_HINTS can contain an icon */
1288 client_update_icons(self);
1293 if (ur != self->urgent) {
1295 ob_debug("Urgent Hint for 0x%lx: %s\n", self->window,
1297 /* fire the urgent callback if we're mapped, otherwise, wait until
1298 after we're mapped */
1305 void client_update_title(ObClient *self)
1311 gboolean read_title;
1313 g_free(self->title);
1316 if (!PROP_GETS(self->window, net_wm_name, utf8, &data))
1317 /* try old x stuff */
1318 if (!PROP_GETS(self->window, wm_name, locale, &data))
1319 data = g_strdup("Unnamed Window");
1321 /* look for duplicates and append a number */
1323 for (it = client_list; it; it = it->next)
1324 if (it->data != self) {
1325 ObClient *c = it->data;
1326 if (0 == strncmp(c->title, data, strlen(data)))
1327 nums |= 1 << c->title_count;
1329 /* find first free number */
1330 for (i = 1; i <= 32; ++i)
1331 if (!(nums & (1 << i))) {
1332 if (self->title_count == 1 || i == 1)
1333 self->title_count = i;
1336 /* dont display the number for the first window */
1337 if (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_name, data);
1351 frame_adjust_title(self->frame);
1353 /* update the icon title */
1355 g_free(self->icon_title);
1359 if (!PROP_GETS(self->window, net_wm_icon_name, utf8, &data))
1360 /* try old x stuff */
1361 if (!PROP_GETS(self->window, wm_icon_name, locale, &data)) {
1362 data = g_strdup(self->title);
1366 /* append the title count, dont display the number for the first window */
1367 if (read_title && self->title_count > 1) {
1368 char *vdata, *ndata;
1369 ndata = g_strdup_printf(" - [%u]", self->title_count);
1370 vdata = g_strconcat(data, ndata, NULL);
1376 PROP_SETS(self->window, net_wm_visible_icon_name, data);
1378 self->icon_title = data;
1381 void client_update_class(ObClient *self)
1386 if (self->name) g_free(self->name);
1387 if (self->class) g_free(self->class);
1388 if (self->role) g_free(self->role);
1390 self->name = self->class = self->role = NULL;
1392 if (PROP_GETSS(self->window, wm_class, locale, &data)) {
1394 self->name = g_strdup(data[0]);
1396 self->class = g_strdup(data[1]);
1401 if (PROP_GETS(self->window, wm_window_role, locale, &s))
1402 self->role = g_strdup(s);
1404 if (self->name == NULL) self->name = g_strdup("");
1405 if (self->class == NULL) self->class = g_strdup("");
1406 if (self->role == NULL) self->role = g_strdup("");
1409 void client_update_strut(ObClient *self)
1413 gboolean got = FALSE;
1416 if (PROP_GETA32(self->window, net_wm_strut_partial, cardinal,
1420 STRUT_PARTIAL_SET(strut,
1421 data[0], data[2], data[1], data[3],
1422 data[4], data[5], data[8], data[9],
1423 data[6], data[7], data[10], data[11]);
1429 PROP_GETA32(self->window, net_wm_strut, cardinal, &data, &num)) {
1432 STRUT_PARTIAL_SET(strut,
1433 data[0], data[2], data[1], data[3],
1434 0, 0, 0, 0, 0, 0, 0, 0);
1440 STRUT_PARTIAL_SET(strut, 0, 0, 0, 0,
1441 0, 0, 0, 0, 0, 0, 0, 0);
1443 if (!STRUT_EQUAL(strut, self->strut)) {
1444 self->strut = strut;
1446 /* updating here is pointless while we're being mapped cuz we're not in
1447 the client list yet */
1449 screen_update_areas();
1453 void client_update_icons(ObClient *self)
1459 for (i = 0; i < self->nicons; ++i)
1460 g_free(self->icons[i].data);
1461 if (self->nicons > 0)
1462 g_free(self->icons);
1465 if (PROP_GETA32(self->window, net_wm_icon, cardinal, &data, &num)) {
1466 /* figure out how many valid icons are in here */
1468 while (num - i > 2) {
1472 if (i > num || w*h == 0) break;
1476 self->icons = g_new(ObClientIcon, self->nicons);
1478 /* store the icons */
1480 for (j = 0; j < self->nicons; ++j) {
1483 w = self->icons[j].width = data[i++];
1484 h = self->icons[j].height = data[i++];
1486 if (w*h == 0) continue;
1488 self->icons[j].data = g_new(RrPixel32, w * h);
1489 for (x = 0, y = 0, t = 0; t < w * h; ++t, ++x, ++i) {
1494 self->icons[j].data[t] =
1495 (((data[i] >> 24) & 0xff) << RrDefaultAlphaOffset) +
1496 (((data[i] >> 16) & 0xff) << RrDefaultRedOffset) +
1497 (((data[i] >> 8) & 0xff) << RrDefaultGreenOffset) +
1498 (((data[i] >> 0) & 0xff) << RrDefaultBlueOffset);
1504 } else if (PROP_GETA32(self->window, kwm_win_icon,
1505 kwm_win_icon, &data, &num)) {
1508 self->icons = g_new(ObClientIcon, self->nicons);
1509 xerror_set_ignore(TRUE);
1510 if (!RrPixmapToRGBA(ob_rr_inst,
1512 &self->icons[self->nicons-1].width,
1513 &self->icons[self->nicons-1].height,
1514 &self->icons[self->nicons-1].data)) {
1515 g_free(&self->icons[self->nicons-1]);
1518 xerror_set_ignore(FALSE);
1524 if ((hints = XGetWMHints(ob_display, self->window))) {
1525 if (hints->flags & IconPixmapHint) {
1527 self->icons = g_new(ObClientIcon, self->nicons);
1528 xerror_set_ignore(TRUE);
1529 if (!RrPixmapToRGBA(ob_rr_inst,
1531 (hints->flags & IconMaskHint ?
1532 hints->icon_mask : None),
1533 &self->icons[self->nicons-1].width,
1534 &self->icons[self->nicons-1].height,
1535 &self->icons[self->nicons-1].data)){
1536 g_free(&self->icons[self->nicons-1]);
1539 xerror_set_ignore(FALSE);
1546 frame_adjust_icon(self->frame);
1549 static void client_change_state(ObClient *self)
1552 guint32 netstate[10];
1555 state[0] = self->wmstate;
1557 PROP_SETA32(self->window, wm_state, wm_state, state, 2);
1561 netstate[num++] = prop_atoms.net_wm_state_modal;
1563 netstate[num++] = prop_atoms.net_wm_state_shaded;
1565 netstate[num++] = prop_atoms.net_wm_state_hidden;
1566 if (self->skip_taskbar)
1567 netstate[num++] = prop_atoms.net_wm_state_skip_taskbar;
1568 if (self->skip_pager)
1569 netstate[num++] = prop_atoms.net_wm_state_skip_pager;
1570 if (self->fullscreen)
1571 netstate[num++] = prop_atoms.net_wm_state_fullscreen;
1573 netstate[num++] = prop_atoms.net_wm_state_maximized_vert;
1575 netstate[num++] = prop_atoms.net_wm_state_maximized_horz;
1577 netstate[num++] = prop_atoms.net_wm_state_above;
1579 netstate[num++] = prop_atoms.net_wm_state_below;
1580 PROP_SETA32(self->window, net_wm_state, atom, netstate, num);
1582 client_calc_layer(self);
1585 frame_adjust_state(self->frame);
1588 ObClient *client_search_focus_tree(ObClient *self)
1593 for (it = self->transients; it != NULL; it = it->next) {
1594 if (client_focused(it->data)) return it->data;
1595 if ((ret = client_search_focus_tree(it->data))) return ret;
1600 ObClient *client_search_focus_tree_full(ObClient *self)
1602 if (self->transient_for) {
1603 if (self->transient_for != OB_TRAN_GROUP) {
1604 return client_search_focus_tree_full(self->transient_for);
1607 gboolean recursed = FALSE;
1609 for (it = self->group->members; it; it = it->next)
1610 if (!((ObClient*)it->data)->transient_for) {
1612 if ((c = client_search_focus_tree_full(it->data)))
1621 /* this function checks the whole tree, the client_search_focus_tree~
1622 does not, so we need to check this window */
1623 if (client_focused(self))
1625 return client_search_focus_tree(self);
1628 static ObStackingLayer calc_layer(ObClient *self)
1632 if (self->fullscreen) l = OB_STACKING_LAYER_FULLSCREEN;
1633 else if (self->type == OB_CLIENT_TYPE_DESKTOP)
1634 l = OB_STACKING_LAYER_DESKTOP;
1635 else if (self->type == OB_CLIENT_TYPE_DOCK) {
1636 if (!self->below) l = OB_STACKING_LAYER_TOP;
1637 else l = OB_STACKING_LAYER_NORMAL;
1639 else if (self->above) l = OB_STACKING_LAYER_ABOVE;
1640 else if (self->below) l = OB_STACKING_LAYER_BELOW;
1641 else l = OB_STACKING_LAYER_NORMAL;
1646 static void client_calc_layer_recursive(ObClient *self, ObClient *orig,
1647 ObStackingLayer l, gboolean raised)
1649 ObStackingLayer old, own;
1653 own = calc_layer(self);
1654 self->layer = l > own ? l : own;
1656 for (it = self->transients; it; it = it->next)
1657 client_calc_layer_recursive(it->data, orig,
1658 l, raised ? raised : l != old);
1660 if (!raised && l != old)
1661 if (orig->frame) { /* only restack if the original window is managed */
1662 /* XXX add_non_intrusive ever? */
1663 stacking_remove(CLIENT_AS_WINDOW(self));
1664 stacking_add(CLIENT_AS_WINDOW(self));
1668 void client_calc_layer(ObClient *self)
1675 /* transients take on the layer of their parents */
1676 self = client_search_top_transient(self);
1678 l = calc_layer(self);
1680 client_calc_layer_recursive(self, orig, l, FALSE);
1683 gboolean client_should_show(ObClient *self)
1685 if (self->iconic) return FALSE;
1686 else if (!(self->desktop == screen_desktop ||
1687 self->desktop == DESKTOP_ALL)) return FALSE;
1688 else if (client_normal(self) && screen_showing_desktop) return FALSE;
1693 static void client_showhide(ObClient *self)
1696 if (client_should_show(self))
1697 frame_show(self->frame);
1699 frame_hide(self->frame);
1702 gboolean client_normal(ObClient *self) {
1703 return ! (self->type == OB_CLIENT_TYPE_DESKTOP ||
1704 self->type == OB_CLIENT_TYPE_DOCK ||
1705 self->type == OB_CLIENT_TYPE_SPLASH);
1708 static void client_apply_startup_state(ObClient *self)
1710 /* these are in a carefully crafted order.. */
1713 self->iconic = FALSE;
1714 client_iconify(self, TRUE, FALSE);
1716 if (self->fullscreen) {
1717 self->fullscreen = FALSE;
1718 client_fullscreen(self, TRUE, FALSE);
1721 self->shaded = FALSE;
1722 client_shade(self, TRUE);
1727 if (self->max_vert && self->max_horz) {
1728 self->max_vert = self->max_horz = FALSE;
1729 client_maximize(self, TRUE, 0, FALSE);
1730 } else if (self->max_vert) {
1731 self->max_vert = FALSE;
1732 client_maximize(self, TRUE, 2, FALSE);
1733 } else if (self->max_horz) {
1734 self->max_horz = FALSE;
1735 client_maximize(self, TRUE, 1, FALSE);
1738 /* nothing to do for the other states:
1747 void client_configure_full(ObClient *self, ObCorner anchor,
1748 int x, int y, int w, int h,
1749 gboolean user, gboolean final,
1750 gboolean force_reply)
1752 gboolean moved = FALSE, resized = FALSE;
1753 guint fdecor = self->frame->decorations;
1754 gboolean fhorz = self->frame->max_horz;
1756 /* make the frame recalculate its dimentions n shit without changing
1757 anything visible for real, this way the constraints below can work with
1758 the updated frame dimensions. */
1759 frame_adjust_area(self->frame, TRUE, TRUE, TRUE);
1761 /* gets the frame's position */
1762 frame_client_gravity(self->frame, &x, &y);
1764 /* these positions are frame positions, not client positions */
1766 /* set the size and position if fullscreen */
1767 if (self->fullscreen) {
1770 XF86VidModeModeLine mode;
1775 i = client_monitor(self);
1776 a = screen_physical_area_monitor(i);
1779 if (i == 0 && /* primary head */
1780 extensions_vidmode &&
1781 XF86VidModeGetViewPort(ob_display, ob_screen, &x, &y) &&
1782 /* get the mode last so the mode.privsize isnt freed incorrectly */
1783 XF86VidModeGetModeLine(ob_display, ob_screen, &dot, &mode)) {
1788 if (mode.privsize) XFree(mode.private);
1798 user = FALSE; /* ignore that increment etc shit when in fullscreen */
1802 a = screen_area_monitor(self->desktop, client_monitor(self));
1804 /* set the size and position if maximized */
1805 if (self->max_horz) {
1807 w = a->width - self->frame->size.left - self->frame->size.right;
1809 if (self->max_vert) {
1811 h = a->height - self->frame->size.top - self->frame->size.bottom;
1815 /* gets the client's position */
1816 frame_frame_gravity(self->frame, &x, &y);
1818 /* these override the above states! if you cant move you can't move! */
1820 if (!(self->functions & OB_CLIENT_FUNC_MOVE)) {
1824 if (!(self->functions & OB_CLIENT_FUNC_RESIZE)) {
1825 w = self->area.width;
1826 h = self->area.height;
1830 if (!(w == self->area.width && h == self->area.height)) {
1831 int basew, baseh, minw, minh;
1834 /* base size is substituted with min size if not specified */
1835 if (self->base_size.width || self->base_size.height) {
1836 basew = self->base_size.width;
1837 baseh = self->base_size.height;
1839 basew = self->min_size.width;
1840 baseh = self->min_size.height;
1842 /* min size is substituted with base size if not specified */
1843 if (self->min_size.width || self->min_size.height) {
1844 minw = self->min_size.width;
1845 minh = self->min_size.height;
1847 minw = self->base_size.width;
1848 minh = self->base_size.height;
1851 /* for interactive resizing. have to move half an increment in each
1854 /* how far we are towards the next size inc */
1855 mw = (w - basew) % self->size_inc.width;
1856 mh = (h - baseh) % self->size_inc.height;
1858 aw = self->size_inc.width / 2;
1859 ah = self->size_inc.height / 2;
1860 /* don't let us move into a new size increment */
1861 if (mw + aw >= self->size_inc.width)
1862 aw = self->size_inc.width - mw - 1;
1863 if (mh + ah >= self->size_inc.height)
1864 ah = self->size_inc.height - mh - 1;
1868 /* if this is a user-requested resize, then check against min/max
1871 /* smaller than min size or bigger than max size? */
1872 if (w > self->max_size.width) w = self->max_size.width;
1873 if (w < minw) w = minw;
1874 if (h > self->max_size.height) h = self->max_size.height;
1875 if (h < minh) h = minh;
1880 /* keep to the increments */
1881 w /= self->size_inc.width;
1882 h /= self->size_inc.height;
1884 /* you cannot resize to nothing */
1885 if (basew + w < 1) w = 1 - basew;
1886 if (baseh + h < 1) h = 1 - baseh;
1888 /* store the logical size */
1889 SIZE_SET(self->logical_size,
1890 self->size_inc.width > 1 ? w : w + basew,
1891 self->size_inc.height > 1 ? h : h + baseh);
1893 w *= self->size_inc.width;
1894 h *= self->size_inc.height;
1899 /* adjust the height to match the width for the aspect ratios.
1900 for this, min size is not substituted for base size ever. */
1901 w -= self->base_size.width;
1902 h -= self->base_size.height;
1904 if (self->min_ratio)
1905 if (h * self->min_ratio > w) h = (int)(w / self->min_ratio);
1906 if (self->max_ratio)
1907 if (h * self->max_ratio < w) h = (int)(w / self->max_ratio);
1909 w += self->base_size.width;
1910 h += self->base_size.height;
1914 case OB_CORNER_TOPLEFT:
1916 case OB_CORNER_TOPRIGHT:
1917 x -= w - self->area.width;
1919 case OB_CORNER_BOTTOMLEFT:
1920 y -= h - self->area.height;
1922 case OB_CORNER_BOTTOMRIGHT:
1923 x -= w - self->area.width;
1924 y -= h - self->area.height;
1928 moved = x != self->area.x || y != self->area.y;
1929 resized = w != self->area.width || h != self->area.height;
1931 RECT_SET(self->area, x, y, w, h);
1933 /* for app-requested resizes, always resize if 'resized' is true.
1934 for user-requested ones, only resize if final is true, or when
1935 resizing in redraw mode */
1936 if ((!user && resized) ||
1937 (user && (final || (resized && config_redraw_resize))))
1938 XResizeWindow(ob_display, self->window, w, h);
1940 /* move/resize the frame to match the request */
1942 if (self->decorations != fdecor || self->max_horz != fhorz)
1943 moved = resized = TRUE;
1945 if (moved || resized)
1946 frame_adjust_area(self->frame, moved, resized, FALSE);
1948 if (!resized && (force_reply || ((!user && moved) || (user && final))))
1951 event.type = ConfigureNotify;
1952 event.xconfigure.display = ob_display;
1953 event.xconfigure.event = self->window;
1954 event.xconfigure.window = self->window;
1956 /* root window real coords */
1957 event.xconfigure.x = self->frame->area.x + self->frame->size.left -
1959 event.xconfigure.y = self->frame->area.y + self->frame->size.top -
1961 event.xconfigure.width = w;
1962 event.xconfigure.height = h;
1963 event.xconfigure.border_width = 0;
1964 event.xconfigure.above = self->frame->plate;
1965 event.xconfigure.override_redirect = FALSE;
1966 XSendEvent(event.xconfigure.display, event.xconfigure.window,
1967 FALSE, StructureNotifyMask, &event);
1972 void client_fullscreen(ObClient *self, gboolean fs, gboolean savearea)
1976 if (!(self->functions & OB_CLIENT_FUNC_FULLSCREEN) || /* can't */
1977 self->fullscreen == fs) return; /* already done */
1979 self->fullscreen = fs;
1980 client_change_state(self); /* change the state hints on the client,
1981 and adjust out layer/stacking */
1985 guint32 dimensions[4];
1986 dimensions[0] = self->area.x;
1987 dimensions[1] = self->area.y;
1988 dimensions[2] = self->area.width;
1989 dimensions[3] = self->area.height;
1991 PROP_SETA32(self->window, openbox_premax, cardinal,
1995 /* these are not actually used cuz client_configure will set them
1996 as appropriate when the window is fullscreened */
2003 /* pick some fallbacks... */
2004 a = screen_area_monitor(self->desktop, 0);
2005 x = a->x + a->width / 4;
2006 y = a->y + a->height / 4;
2010 if (PROP_GETA32(self->window, openbox_premax, cardinal,
2011 (guint32**)&dimensions, &num)) {
2022 client_setup_decor_and_functions(self);
2024 client_configure(self, OB_CORNER_TOPLEFT, x, y, w, h, TRUE, TRUE);
2026 /* try focus us when we go into fullscreen mode */
2030 static void client_iconify_recursive(ObClient *self,
2031 gboolean iconic, gboolean curdesk)
2034 gboolean changed = FALSE;
2037 if (self->iconic != iconic) {
2038 ob_debug("%sconifying window: 0x%lx\n", (iconic ? "I" : "Uni"),
2041 self->iconic = iconic;
2044 if (self->functions & OB_CLIENT_FUNC_ICONIFY) {
2045 self->wmstate = IconicState;
2046 self->ignore_unmaps++;
2047 /* we unmap the client itself so that we can get MapRequest
2048 events, and because the ICCCM tells us to! */
2049 XUnmapWindow(ob_display, self->window);
2051 /* update the focus lists.. iconic windows go to the bottom of
2052 the list, put the new iconic window at the 'top of the
2054 focus_order_to_top(self);
2060 client_set_desktop(self, screen_desktop, FALSE);
2061 self->wmstate = self->shaded ? IconicState : NormalState;
2062 XMapWindow(ob_display, self->window);
2064 /* this puts it after the current focused window */
2065 focus_order_remove(self);
2066 focus_order_add_new(self);
2068 /* this is here cuz with the VIDMODE extension, the viewport can
2069 change while a fullscreen window is iconic, and when it
2070 uniconifies, it would be nice if it did so to the new position
2072 client_reconfigure(self);
2079 client_change_state(self);
2080 client_showhide(self);
2081 screen_update_areas();
2084 /* iconify all transients */
2085 for (it = self->transients; it != NULL; it = it->next)
2086 if (it->data != self) client_iconify_recursive(it->data,
2090 void client_iconify(ObClient *self, gboolean iconic, gboolean curdesk)
2092 /* move up the transient chain as far as possible first */
2093 self = client_search_top_transient(self);
2095 client_iconify_recursive(client_search_top_transient(self),
2099 void client_maximize(ObClient *self, gboolean max, int dir, gboolean savearea)
2103 g_assert(dir == 0 || dir == 1 || dir == 2);
2104 if (!(self->functions & OB_CLIENT_FUNC_MAXIMIZE)) return; /* can't */
2106 /* check if already done */
2108 if (dir == 0 && self->max_horz && self->max_vert) return;
2109 if (dir == 1 && self->max_horz) return;
2110 if (dir == 2 && self->max_vert) return;
2112 if (dir == 0 && !self->max_horz && !self->max_vert) return;
2113 if (dir == 1 && !self->max_horz) return;
2114 if (dir == 2 && !self->max_vert) return;
2117 /* work with the frame's coords */
2118 x = self->frame->area.x;
2119 y = self->frame->area.y;
2120 w = self->area.width;
2121 h = self->area.height;
2125 gint32 dimensions[4];
2134 /* get the property off the window and use it for the dimensions
2135 we are already maxed on */
2136 if (PROP_GETA32(self->window, openbox_premax, cardinal,
2137 (guint32**)&readdim, &num)) {
2139 if (self->max_horz) {
2140 dimensions[0] = readdim[0];
2141 dimensions[2] = readdim[2];
2143 if (self->max_vert) {
2144 dimensions[1] = readdim[1];
2145 dimensions[3] = readdim[3];
2151 PROP_SETA32(self->window, openbox_premax, cardinal,
2152 (guint32*)dimensions, 4);
2159 /* pick some fallbacks... */
2160 a = screen_area_monitor(self->desktop, 0);
2161 if (dir == 0 || dir == 1) { /* horz */
2162 x = a->x + a->width / 4;
2165 if (dir == 0 || dir == 2) { /* vert */
2166 y = a->y + a->height / 4;
2170 if (PROP_GETA32(self->window, openbox_premax, cardinal,
2171 (guint32**)&dimensions, &num)) {
2173 if (dir == 0 || dir == 1) { /* horz */
2177 if (dir == 0 || dir == 2) { /* vert */
2186 if (dir == 0 || dir == 1) /* horz */
2187 self->max_horz = max;
2188 if (dir == 0 || dir == 2) /* vert */
2189 self->max_vert = max;
2191 if (!self->max_horz && !self->max_vert)
2192 PROP_ERASE(self->window, openbox_premax);
2194 client_change_state(self); /* change the state hints on the client */
2196 client_setup_decor_and_functions(self);
2198 /* figure out where the client should be going */
2199 frame_frame_gravity(self->frame, &x, &y);
2200 client_configure(self, OB_CORNER_TOPLEFT, x, y, w, h, TRUE, TRUE);
2203 void client_shade(ObClient *self, gboolean shade)
2205 if ((!(self->functions & OB_CLIENT_FUNC_SHADE) &&
2206 shade) || /* can't shade */
2207 self->shaded == shade) return; /* already done */
2209 /* when we're iconic, don't change the wmstate */
2211 self->wmstate = shade ? IconicState : NormalState;
2212 self->shaded = shade;
2213 client_change_state(self);
2214 /* resize the frame to just the titlebar */
2215 frame_adjust_area(self->frame, FALSE, FALSE, FALSE);
2218 void client_close(ObClient *self)
2222 if (!(self->functions & OB_CLIENT_FUNC_CLOSE)) return;
2225 XXX: itd be cool to do timeouts and shit here for killing the client's
2227 like... if the window is around after 5 seconds, then the close button
2228 turns a nice red, and if this function is called again, the client is
2232 ce.xclient.type = ClientMessage;
2233 ce.xclient.message_type = prop_atoms.wm_protocols;
2234 ce.xclient.display = ob_display;
2235 ce.xclient.window = self->window;
2236 ce.xclient.format = 32;
2237 ce.xclient.data.l[0] = prop_atoms.wm_delete_window;
2238 ce.xclient.data.l[1] = event_lasttime;
2239 ce.xclient.data.l[2] = 0l;
2240 ce.xclient.data.l[3] = 0l;
2241 ce.xclient.data.l[4] = 0l;
2242 XSendEvent(ob_display, self->window, FALSE, NoEventMask, &ce);
2245 void client_kill(ObClient *self)
2247 XKillClient(ob_display, self->window);
2250 void client_set_desktop_recursive(ObClient *self,
2251 guint target, gboolean donthide)
2256 if (target != self->desktop) {
2258 ob_debug("Setting desktop %u\n", target+1);
2260 g_assert(target < screen_num_desktops || target == DESKTOP_ALL);
2262 /* remove from the old desktop(s) */
2263 focus_order_remove(self);
2265 old = self->desktop;
2266 self->desktop = target;
2267 PROP_SET32(self->window, net_wm_desktop, cardinal, target);
2268 /* the frame can display the current desktop state */
2269 frame_adjust_state(self->frame);
2270 /* 'move' the window to the new desktop */
2272 client_showhide(self);
2273 /* raise if it was not already on the desktop */
2274 if (old != DESKTOP_ALL)
2275 stacking_raise(CLIENT_AS_WINDOW(self));
2276 screen_update_areas();
2278 /* add to the new desktop(s) */
2279 if (config_focus_new)
2280 focus_order_to_top(self);
2282 focus_order_to_bottom(self);
2285 /* move all transients */
2286 for (it = self->transients; it != NULL; it = it->next)
2287 if (it->data != self) client_set_desktop_recursive(it->data,
2291 void client_set_desktop(ObClient *self, guint target, gboolean donthide)
2293 client_set_desktop_recursive(client_search_top_transient(self),
2297 ObClient *client_search_modal_child(ObClient *self)
2302 for (it = self->transients; it != NULL; it = it->next) {
2303 ObClient *c = it->data;
2304 if ((ret = client_search_modal_child(c))) return ret;
2305 if (c->modal) return c;
2310 gboolean client_validate(ObClient *self)
2314 XSync(ob_display, FALSE); /* get all events on the server */
2316 if (XCheckTypedWindowEvent(ob_display, self->window, DestroyNotify, &e) ||
2317 XCheckTypedWindowEvent(ob_display, self->window, UnmapNotify, &e)) {
2318 XPutBackEvent(ob_display, &e);
2325 void client_set_wm_state(ObClient *self, long state)
2327 if (state == self->wmstate) return; /* no change */
2331 client_iconify(self, TRUE, TRUE);
2334 client_iconify(self, FALSE, TRUE);
2339 void client_set_state(ObClient *self, Atom action, long data1, long data2)
2341 gboolean shaded = self->shaded;
2342 gboolean fullscreen = self->fullscreen;
2343 gboolean max_horz = self->max_horz;
2344 gboolean max_vert = self->max_vert;
2347 if (!(action == prop_atoms.net_wm_state_add ||
2348 action == prop_atoms.net_wm_state_remove ||
2349 action == prop_atoms.net_wm_state_toggle))
2350 /* an invalid action was passed to the client message, ignore it */
2353 for (i = 0; i < 2; ++i) {
2354 Atom state = i == 0 ? data1 : data2;
2356 if (!state) continue;
2358 /* if toggling, then pick whether we're adding or removing */
2359 if (action == prop_atoms.net_wm_state_toggle) {
2360 if (state == prop_atoms.net_wm_state_modal)
2361 action = self->modal ? prop_atoms.net_wm_state_remove :
2362 prop_atoms.net_wm_state_add;
2363 else if (state == prop_atoms.net_wm_state_maximized_vert)
2364 action = self->max_vert ? prop_atoms.net_wm_state_remove :
2365 prop_atoms.net_wm_state_add;
2366 else if (state == prop_atoms.net_wm_state_maximized_horz)
2367 action = self->max_horz ? prop_atoms.net_wm_state_remove :
2368 prop_atoms.net_wm_state_add;
2369 else if (state == prop_atoms.net_wm_state_shaded)
2370 action = self->shaded ? prop_atoms.net_wm_state_remove :
2371 prop_atoms.net_wm_state_add;
2372 else if (state == prop_atoms.net_wm_state_skip_taskbar)
2373 action = self->skip_taskbar ?
2374 prop_atoms.net_wm_state_remove :
2375 prop_atoms.net_wm_state_add;
2376 else if (state == prop_atoms.net_wm_state_skip_pager)
2377 action = self->skip_pager ?
2378 prop_atoms.net_wm_state_remove :
2379 prop_atoms.net_wm_state_add;
2380 else if (state == prop_atoms.net_wm_state_fullscreen)
2381 action = self->fullscreen ?
2382 prop_atoms.net_wm_state_remove :
2383 prop_atoms.net_wm_state_add;
2384 else if (state == prop_atoms.net_wm_state_above)
2385 action = self->above ? prop_atoms.net_wm_state_remove :
2386 prop_atoms.net_wm_state_add;
2387 else if (state == prop_atoms.net_wm_state_below)
2388 action = self->below ? prop_atoms.net_wm_state_remove :
2389 prop_atoms.net_wm_state_add;
2392 if (action == prop_atoms.net_wm_state_add) {
2393 if (state == prop_atoms.net_wm_state_modal) {
2394 /* XXX raise here or something? */
2396 } else if (state == prop_atoms.net_wm_state_maximized_vert) {
2398 } else if (state == prop_atoms.net_wm_state_maximized_horz) {
2400 } else if (state == prop_atoms.net_wm_state_shaded) {
2402 } else if (state == prop_atoms.net_wm_state_skip_taskbar) {
2403 self->skip_taskbar = TRUE;
2404 } else if (state == prop_atoms.net_wm_state_skip_pager) {
2405 self->skip_pager = TRUE;
2406 } else if (state == prop_atoms.net_wm_state_fullscreen) {
2408 } else if (state == prop_atoms.net_wm_state_above) {
2410 } else if (state == prop_atoms.net_wm_state_below) {
2414 } else { /* action == prop_atoms.net_wm_state_remove */
2415 if (state == prop_atoms.net_wm_state_modal) {
2416 self->modal = FALSE;
2417 } else if (state == prop_atoms.net_wm_state_maximized_vert) {
2419 } else if (state == prop_atoms.net_wm_state_maximized_horz) {
2421 } else if (state == prop_atoms.net_wm_state_shaded) {
2423 } else if (state == prop_atoms.net_wm_state_skip_taskbar) {
2424 self->skip_taskbar = FALSE;
2425 } else if (state == prop_atoms.net_wm_state_skip_pager) {
2426 self->skip_pager = FALSE;
2427 } else if (state == prop_atoms.net_wm_state_fullscreen) {
2429 } else if (state == prop_atoms.net_wm_state_above) {
2430 self->above = FALSE;
2431 } else if (state == prop_atoms.net_wm_state_below) {
2432 self->below = FALSE;
2436 if (max_horz != self->max_horz || max_vert != self->max_vert) {
2437 if (max_horz != self->max_horz && max_vert != self->max_vert) {
2439 if (max_horz == max_vert) { /* both going the same way */
2440 client_maximize(self, max_horz, 0, TRUE);
2442 client_maximize(self, max_horz, 1, TRUE);
2443 client_maximize(self, max_vert, 2, TRUE);
2447 if (max_horz != self->max_horz)
2448 client_maximize(self, max_horz, 1, TRUE);
2450 client_maximize(self, max_vert, 2, TRUE);
2453 /* change fullscreen state before shading, as it will affect if the window
2455 if (fullscreen != self->fullscreen)
2456 client_fullscreen(self, fullscreen, TRUE);
2457 if (shaded != self->shaded)
2458 client_shade(self, shaded);
2459 client_calc_layer(self);
2460 client_change_state(self); /* change the hint to reflect these changes */
2463 ObClient *client_focus_target(ObClient *self)
2467 /* if we have a modal child, then focus it, not us */
2468 child = client_search_modal_child(self);
2469 if (child) return child;
2473 gboolean client_can_focus(ObClient *self)
2477 /* choose the correct target */
2478 self = client_focus_target(self);
2480 if (!self->frame->visible)
2483 if (!((self->can_focus || self->focus_notify) &&
2484 (self->desktop == screen_desktop ||
2485 self->desktop == DESKTOP_ALL) &&
2489 /* do a check to see if the window has already been unmapped or destroyed
2490 do this intelligently while watching out for unmaps we've generated
2491 (ignore_unmaps > 0) */
2492 if (XCheckTypedWindowEvent(ob_display, self->window,
2493 DestroyNotify, &ev)) {
2494 XPutBackEvent(ob_display, &ev);
2497 while (XCheckTypedWindowEvent(ob_display, self->window,
2498 UnmapNotify, &ev)) {
2499 if (self->ignore_unmaps) {
2500 self->ignore_unmaps--;
2502 XPutBackEvent(ob_display, &ev);
2510 gboolean client_focus(ObClient *self)
2512 /* choose the correct target */
2513 self = client_focus_target(self);
2515 if (!client_can_focus(self)) {
2516 if (!self->frame->visible) {
2517 /* update the focus lists */
2518 focus_order_to_top(self);
2523 if (self->can_focus)
2524 /* RevertToPointerRoot causes much more headache than RevertToNone, so
2525 I choose to use it always, hopefully to find errors quicker, if any
2526 are left. (I hate X. I hate focus events.) */
2527 XSetInputFocus(ob_display, self->window, RevertToPointerRoot,
2530 if (self->focus_notify) {
2532 ce.xclient.type = ClientMessage;
2533 ce.xclient.message_type = prop_atoms.wm_protocols;
2534 ce.xclient.display = ob_display;
2535 ce.xclient.window = self->window;
2536 ce.xclient.format = 32;
2537 ce.xclient.data.l[0] = prop_atoms.wm_take_focus;
2538 ce.xclient.data.l[1] = event_lasttime;
2539 ce.xclient.data.l[2] = 0l;
2540 ce.xclient.data.l[3] = 0l;
2541 ce.xclient.data.l[4] = 0l;
2542 XSendEvent(ob_display, self->window, FALSE, NoEventMask, &ce);
2546 ob_debug("%sively focusing %lx at %d\n",
2547 (self->can_focus ? "act" : "pass"),
2548 self->window, (int) event_lasttime);
2551 /* Cause the FocusIn to come back to us. Important for desktop switches,
2552 since otherwise we'll have no FocusIn on the queue and send it off to
2553 the focus_backup. */
2554 XSync(ob_display, FALSE);
2558 void client_unfocus(ObClient *self)
2560 g_assert(focus_client == self);
2562 ob_debug("client_unfocus for %lx\n", self->window);
2564 focus_fallback(OB_FOCUS_FALLBACK_UNFOCUSING);
2567 void client_activate(ObClient *self, gboolean here)
2569 if (client_normal(self) && screen_showing_desktop)
2570 screen_show_desktop(FALSE);
2572 client_iconify(self, FALSE, FALSE);
2573 if (self->desktop != DESKTOP_ALL &&
2574 self->desktop != screen_desktop) {
2576 client_set_desktop(self, screen_desktop, FALSE);
2578 screen_set_desktop(self->desktop);
2579 } else if (!self->frame->visible)
2580 /* if its not visible for other reasons, then don't mess
2584 client_shade(self, FALSE);
2586 stacking_raise(CLIENT_AS_WINDOW(self));
2589 gboolean client_focused(ObClient *self)
2591 return self == focus_client;
2594 ObClientIcon *client_icon(ObClient *self, int w, int h)
2597 /* si is the smallest image >= req */
2598 /* li is the largest image < req */
2599 unsigned long size, smallest = 0xffffffff, largest = 0, si = 0, li = 0;
2601 if (!self->nicons) return NULL;
2603 for (i = 0; i < self->nicons; ++i) {
2604 size = self->icons[i].width * self->icons[i].height;
2605 if (size < smallest && size >= (unsigned)(w * h)) {
2609 if (size > largest && size <= (unsigned)(w * h)) {
2614 if (largest == 0) /* didnt find one smaller than the requested size */
2615 return &self->icons[si];
2616 return &self->icons[li];
2619 /* this be mostly ripped from fvwm */
2620 ObClient *client_find_directional(ObClient *c, ObDirection dir)
2622 int my_cx, my_cy, his_cx, his_cy;
2625 int score, best_score;
2626 ObClient *best_client, *cur;
2632 /* first, find the centre coords of the currently focused window */
2633 my_cx = c->frame->area.x + c->frame->area.width / 2;
2634 my_cy = c->frame->area.y + c->frame->area.height / 2;
2639 for(it = g_list_first(client_list); it; it = it->next) {
2642 /* the currently selected window isn't interesting */
2645 if (!client_normal(cur))
2647 if(c->desktop != cur->desktop && cur->desktop != DESKTOP_ALL)
2651 if(client_focus_target(cur) == cur &&
2652 !(cur->can_focus || cur->focus_notify))
2655 /* find the centre coords of this window, from the
2656 * currently focused window's point of view */
2657 his_cx = (cur->frame->area.x - my_cx)
2658 + cur->frame->area.width / 2;
2659 his_cy = (cur->frame->area.y - my_cy)
2660 + cur->frame->area.height / 2;
2662 if(dir == OB_DIRECTION_NORTHEAST || dir == OB_DIRECTION_SOUTHEAST ||
2663 dir == OB_DIRECTION_SOUTHWEST || dir == OB_DIRECTION_NORTHWEST) {
2665 /* Rotate the diagonals 45 degrees counterclockwise.
2666 * To do this, multiply the matrix /+h +h\ with the
2667 * vector (x y). \-h +h/
2668 * h = sqrt(0.5). We can set h := 1 since absolute
2669 * distance doesn't matter here. */
2670 tx = his_cx + his_cy;
2671 his_cy = -his_cx + his_cy;
2676 case OB_DIRECTION_NORTH:
2677 case OB_DIRECTION_SOUTH:
2678 case OB_DIRECTION_NORTHEAST:
2679 case OB_DIRECTION_SOUTHWEST:
2680 offset = (his_cx < 0) ? -his_cx : his_cx;
2681 distance = ((dir == OB_DIRECTION_NORTH ||
2682 dir == OB_DIRECTION_NORTHEAST) ?
2685 case OB_DIRECTION_EAST:
2686 case OB_DIRECTION_WEST:
2687 case OB_DIRECTION_SOUTHEAST:
2688 case OB_DIRECTION_NORTHWEST:
2689 offset = (his_cy < 0) ? -his_cy : his_cy;
2690 distance = ((dir == OB_DIRECTION_WEST ||
2691 dir == OB_DIRECTION_NORTHWEST) ?
2696 /* the target must be in the requested direction */
2700 /* Calculate score for this window. The smaller the better. */
2701 score = distance + offset;
2703 /* windows more than 45 degrees off the direction are
2704 * heavily penalized and will only be chosen if nothing
2705 * else within a million pixels */
2706 if(offset > distance)
2709 if(best_score == -1 || score < best_score)
2717 void client_set_layer(ObClient *self, int layer)
2721 self->above = FALSE;
2722 } else if (layer == 0) {
2723 self->below = self->above = FALSE;
2725 self->below = FALSE;
2728 client_calc_layer(self);
2729 client_change_state(self); /* reflect this in the state hints */
2732 guint client_monitor(ObClient *self)
2736 for (i = 0; i < screen_num_monitors; ++i) {
2737 Rect *area = screen_physical_area_monitor(i);
2738 if (RECT_INTERSECTS_RECT(*area, self->frame->area))
2741 if (i == screen_num_monitors) i = 0;
2742 g_assert(i < screen_num_monitors);
2746 ObClient *client_search_top_transient(ObClient *self)
2748 /* move up the transient chain as far as possible */
2749 if (self->transient_for) {
2750 if (self->transient_for != OB_TRAN_GROUP) {
2751 return client_search_top_transient(self->transient_for);
2755 for (it = self->group->members; it; it = it->next) {
2756 ObClient *c = it->data;
2758 /* checking transient_for prevents infinate loops! */
2759 if (c != self && !c->transient_for)
2770 ObClient *client_search_transient(ObClient *self, ObClient *search)
2774 for (sit = self->transients; sit; sit = g_slist_next(sit)) {
2775 if (sit->data == search)
2777 if (client_search_transient(sit->data, search))
2783 gchar* client_get_sm_client_id(ObClient *self)
2787 if (!PROP_GETS(self->window, sm_client_id, locale, &id) && self->group)
2788 PROP_GETS(self->group->leader, sm_client_id, locale, &id);
2792 /* finds the nearest edge in the given direction from the current client
2793 * note to self: the edge is the -frame- edge (the actual one), not the
2796 int client_directional_edge_search(ObClient *c, ObDirection dir)
2799 int my_edge_start, my_edge_end, my_offset;
2806 a = screen_area(c->desktop);
2809 case OB_DIRECTION_NORTH:
2810 my_edge_start = c->frame->area.x;
2811 my_edge_end = c->frame->area.x + c->frame->area.width;
2812 my_offset = c->frame->area.y;
2814 dest = a->y; /* default: top of screen */
2816 for(it = g_list_first(client_list); it; it = it->next) {
2817 int his_edge_start, his_edge_end, his_offset;
2818 ObClient *cur = it->data;
2822 if(!client_normal(cur))
2824 if(c->desktop != cur->desktop && cur->desktop != DESKTOP_ALL)
2829 his_edge_start = cur->frame->area.x;
2830 his_edge_end = cur->frame->area.x + cur->frame->area.width;
2831 his_offset = cur->frame->area.y + cur->frame->area.height;
2833 if(his_offset + 1 > my_offset)
2836 if(his_offset < dest)
2839 if(his_edge_start >= my_edge_start &&
2840 his_edge_start <= my_edge_end)
2843 if(my_edge_start >= his_edge_start &&
2844 my_edge_start <= his_edge_end)
2849 case OB_DIRECTION_SOUTH:
2850 my_edge_start = c->frame->area.x;
2851 my_edge_end = c->frame->area.x + c->frame->area.width;
2852 my_offset = c->frame->area.y + c->frame->area.height;
2854 dest = a->y + a->height; /* default: bottom of screen */
2856 for(it = g_list_first(client_list); it; it = it->next) {
2857 int his_edge_start, his_edge_end, his_offset;
2858 ObClient *cur = it->data;
2862 if(!client_normal(cur))
2864 if(c->desktop != cur->desktop && cur->desktop != DESKTOP_ALL)
2869 his_edge_start = cur->frame->area.x;
2870 his_edge_end = cur->frame->area.x + cur->frame->area.width;
2871 his_offset = cur->frame->area.y;
2874 if(his_offset - 1 < my_offset)
2877 if(his_offset > dest)
2880 if(his_edge_start >= my_edge_start &&
2881 his_edge_start <= my_edge_end)
2884 if(my_edge_start >= his_edge_start &&
2885 my_edge_start <= his_edge_end)
2890 case OB_DIRECTION_WEST:
2891 my_edge_start = c->frame->area.y;
2892 my_edge_end = c->frame->area.y + c->frame->area.height;
2893 my_offset = c->frame->area.x;
2895 dest = a->x; /* default: leftmost egde of screen */
2897 for(it = g_list_first(client_list); it; it = it->next) {
2898 int his_edge_start, his_edge_end, his_offset;
2899 ObClient *cur = it->data;
2903 if(!client_normal(cur))
2905 if(c->desktop != cur->desktop && cur->desktop != DESKTOP_ALL)
2910 his_edge_start = cur->frame->area.y;
2911 his_edge_end = cur->frame->area.y + cur->frame->area.height;
2912 his_offset = cur->frame->area.x + cur->frame->area.width;
2914 if(his_offset + 1 > my_offset)
2917 if(his_offset < dest)
2920 if(his_edge_start >= my_edge_start &&
2921 his_edge_start <= my_edge_end)
2924 if(my_edge_start >= his_edge_start &&
2925 my_edge_start <= his_edge_end)
2931 case OB_DIRECTION_EAST:
2932 my_edge_start = c->frame->area.y;
2933 my_edge_end = c->frame->area.y + c->frame->area.height;
2934 my_offset = c->frame->area.x + c->frame->area.width;
2936 dest = a->x + a->width; /* default: rightmost edge of screen */
2938 for(it = g_list_first(client_list); it; it = it->next) {
2939 int his_edge_start, his_edge_end, his_offset;
2940 ObClient *cur = it->data;
2944 if(!client_normal(cur))
2946 if(c->desktop != cur->desktop && cur->desktop != DESKTOP_ALL)
2951 his_edge_start = cur->frame->area.y;
2952 his_edge_end = cur->frame->area.y + cur->frame->area.height;
2953 his_offset = cur->frame->area.x;
2955 if(his_offset - 1 < my_offset)
2958 if(his_offset > dest)
2961 if(his_edge_start >= my_edge_start &&
2962 his_edge_start <= my_edge_end)
2965 if(my_edge_start >= his_edge_start &&
2966 my_edge_start <= his_edge_end)
2971 case OB_DIRECTION_NORTHEAST:
2972 case OB_DIRECTION_SOUTHEAST:
2973 case OB_DIRECTION_NORTHWEST:
2974 case OB_DIRECTION_SOUTHWEST:
2975 /* not implemented */
2978 g_assert_not_reached();