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);
50 static void client_restore_session_stacking(ObClient *self);
57 void client_shutdown()
61 void client_set_list()
63 Window *windows, *win_it;
65 guint size = g_list_length(client_list);
67 /* create an array of the window ids */
69 windows = g_new(Window, size);
71 for (it = client_list; it != NULL; it = it->next, ++win_it)
72 *win_it = ((ObClient*)it->data)->window;
76 PROP_SETA32(RootWindow(ob_display, ob_screen),
77 net_client_list, window, (guint32*)windows, size);
86 void client_foreach_transient(ObClient *self, ObClientForeachFunc func, void *data)
90 for (it = self->transients; it; it = it->next) {
91 if (!func(it->data, data)) return;
92 client_foreach_transient(it->data, func, data);
96 void client_foreach_ancestor(ObClient *self, ObClientForeachFunc func, void *data)
98 if (self->transient_for) {
99 if (self->transient_for != OB_TRAN_GROUP) {
100 if (!func(self->transient_for, data)) return;
101 client_foreach_ancestor(self->transient_for, func, data);
105 for (it = self->group->members; it; it = it->next)
106 if (it->data != self &&
107 !((ObClient*)it->data)->transient_for) {
108 if (!func(it->data, data)) return;
109 client_foreach_ancestor(it->data, func, data);
116 void client_manage_all()
118 unsigned int i, j, nchild;
121 XWindowAttributes attrib;
123 XQueryTree(ob_display, RootWindow(ob_display, ob_screen),
124 &w, &w, &children, &nchild);
126 /* remove all icon windows from the list */
127 for (i = 0; i < nchild; i++) {
128 if (children[i] == None) continue;
129 wmhints = XGetWMHints(ob_display, children[i]);
131 if ((wmhints->flags & IconWindowHint) &&
132 (wmhints->icon_window != children[i]))
133 for (j = 0; j < nchild; j++)
134 if (children[j] == wmhints->icon_window) {
142 for (i = 0; i < nchild; ++i) {
143 if (children[i] == None)
145 if (XGetWindowAttributes(ob_display, children[i], &attrib)) {
146 if (attrib.override_redirect) continue;
148 if (attrib.map_state != IsUnmapped)
149 client_manage(children[i]);
154 /* stack them as they were on startup!
155 why with stacking_lower? Why, because then windows who aren't in the
156 stacking list are on the top where you can see them instead of buried
158 for (i = startup_stack_size; i > 0; --i) {
161 w = startup_stack_order[i-1];
162 obw = g_hash_table_lookup(window_map, &w);
164 g_assert(WINDOW_IS_CLIENT(obw));
165 stacking_lower(CLIENT_AS_WINDOW(obw));
168 g_free(startup_stack_order);
169 startup_stack_order = NULL;
170 startup_stack_size = 0;
172 if (config_focus_new) {
175 active = g_hash_table_lookup(window_map, &startup_active);
177 g_assert(WINDOW_IS_CLIENT(active));
178 if (!client_focus(WINDOW_AS_CLIENT(active)))
179 focus_fallback(OB_FOCUS_FALLBACK_NOFOCUS);
181 focus_fallback(OB_FOCUS_FALLBACK_NOFOCUS);
185 void client_manage(Window window)
189 XWindowAttributes attrib;
190 XSetWindowAttributes attrib_set;
192 gboolean activate = FALSE;
196 /* check if it has already been unmapped by the time we started mapping
197 the grab does a sync so we don't have to here */
198 if (XCheckTypedWindowEvent(ob_display, window, DestroyNotify, &e) ||
199 XCheckTypedWindowEvent(ob_display, window, UnmapNotify, &e)) {
200 XPutBackEvent(ob_display, &e);
203 return; /* don't manage it */
206 /* make sure it isn't an override-redirect window */
207 if (!XGetWindowAttributes(ob_display, window, &attrib) ||
208 attrib.override_redirect) {
210 return; /* don't manage it */
213 /* is the window a docking app */
214 if ((wmhint = XGetWMHints(ob_display, window))) {
215 if ((wmhint->flags & StateHint) &&
216 wmhint->initial_state == WithdrawnState) {
217 dock_add(window, wmhint);
225 ob_debug("Managing window: %lx\n", window);
227 /* choose the events we want to receive on the CLIENT window */
228 attrib_set.event_mask = CLIENT_EVENTMASK;
229 attrib_set.do_not_propagate_mask = CLIENT_NOPROPAGATEMASK;
230 XChangeWindowAttributes(ob_display, window,
231 CWEventMask|CWDontPropagate, &attrib_set);
234 /* create the ObClient struct, and populate it from the hints on the
236 self = g_new0(ObClient, 1);
237 self->obwin.type = Window_Client;
238 self->window = window;
240 client_get_all(self);
241 client_restore_session_state(self);
243 client_change_state(self);
245 /* remove the client's border (and adjust re gravity) */
246 client_toggle_border(self, FALSE);
248 /* specify that if we exit, the window should not be destroyed and should
249 be reparented back to root automatically */
250 XChangeSaveSet(ob_display, window, SetModeInsert);
252 /* create the decoration frame for the client window */
253 self->frame = frame_new();
255 frame_grab_client(self->frame, self);
257 client_apply_startup_state(self);
261 /* update the focus lists */
262 focus_order_add_new(self);
264 stacking_add(CLIENT_AS_WINDOW(self));
265 client_restore_session_stacking(self);
267 /* focus the new window? */
268 if (ob_state() != OB_STATE_STARTING && config_focus_new &&
269 /* note the check against Type_Normal/Dialog, not client_normal(self),
270 which would also include other types. in this case we want more
271 strict rules for focus */
272 (self->type == OB_CLIENT_TYPE_NORMAL ||
273 self->type == OB_CLIENT_TYPE_DIALOG))
277 if (self->desktop != screen_desktop) {
278 /* activate the window */
281 gboolean group_foc = FALSE;
286 for (it = self->group->members; it; it = it->next)
288 if (client_focused(it->data))
296 (!self->transient_for && (!self->group ||
297 !self->group->members->next))) ||
298 client_search_focus_tree_full(self) ||
300 !client_normal(focus_client))
302 /* activate the window */
309 dispatch_client(Event_Client_New, self, 0, 0);
311 /* make sure the window is visible */
312 if (ob_state() == OB_STATE_RUNNING)
313 client_move_onscreen(self, client_normal(self));
315 client_showhide(self);
317 /* use client_focus instead of client_activate cuz client_activate does
318 stuff like switch desktops etc and I'm not interested in all that when
319 a window maps since its not based on an action from the user like
320 clicking a window to activate is. so keep the new window out of the way
322 if (activate) client_focus(self);
324 /* client_activate does this but we aret using it so we have to do it
326 if (screen_showing_desktop)
327 screen_show_desktop(FALSE);
329 /* add to client list/map */
330 client_list = g_list_append(client_list, self);
331 g_hash_table_insert(window_map, &self->window, self);
333 /* this has to happen after we're in the client_list */
334 screen_update_areas();
336 /* update the list hints */
339 keyboard_grab_for_client(self, TRUE);
340 mouse_grab_for_client(self, TRUE);
342 dispatch_client(Event_Client_Mapped, self, 0, 0);
344 ob_debug("Managed window 0x%lx (%s)\n", window, self->class);
347 void client_unmanage_all()
349 while (client_list != NULL)
350 client_unmanage(client_list->data);
353 /* called by client_unmanage() to close any menus referencing this client */
354 void client_close_menus(gpointer key, gpointer value, gpointer self)
356 if (((ObMenu *)value)->client == (ObClient *)self)
357 menu_hide((ObMenu *)value);
360 void client_unmanage(ObClient *self)
365 ob_debug("Unmanaging window: %lx (%s)\n", self->window, self->class);
367 dispatch_client(Event_Client_Destroy, self, 0, 0);
368 g_assert(self != NULL);
370 keyboard_grab_for_client(self, FALSE);
371 mouse_grab_for_client(self, FALSE);
373 /* remove the window from our save set */
374 XChangeSaveSet(ob_display, self->window, SetModeDelete);
376 /* we dont want events no more */
377 XSelectInput(ob_display, self->window, NoEventMask);
379 frame_hide(self->frame);
381 client_list = g_list_remove(client_list, self);
382 stacking_remove(self);
383 g_hash_table_remove(window_map, &self->window);
385 /* update the focus lists */
386 focus_order_remove(self);
388 /* once the client is out of the list, update the struts to remove it's
390 screen_update_areas();
392 /* tell our parent(s) that we're gone */
393 if (self->transient_for == OB_TRAN_GROUP) { /* transient of group */
396 for (it = self->group->members; it; it = it->next)
397 if (it->data != self)
398 ((ObClient*)it->data)->transients =
399 g_slist_remove(((ObClient*)it->data)->transients, self);
400 } else if (self->transient_for) { /* transient of window */
401 self->transient_for->transients =
402 g_slist_remove(self->transient_for->transients, self);
405 /* tell our transients that we're gone */
406 for (it = self->transients; it != NULL; it = it->next) {
407 if (((ObClient*)it->data)->transient_for != OB_TRAN_GROUP) {
408 ((ObClient*)it->data)->transient_for = NULL;
409 client_calc_layer(it->data);
413 if (moveresize_client == self)
414 moveresize_end(TRUE);
416 /* close any windows that are attached to this window */
417 g_hash_table_foreach(menu_hash, client_close_menus, self);
420 if (focus_client == self) {
423 /* focus the last focused window on the desktop, and ignore enter
424 events from the unmap so it doesnt mess with the focus */
425 while (XCheckTypedEvent(ob_display, EnterNotify, &e));
426 client_unfocus(self);
429 /* remove from its group */
431 group_remove(self->group, self);
435 /* dispatch the unmapped event */
436 dispatch_client(Event_Client_Unmapped, self, 0, 0);
437 g_assert(self != NULL);
439 /* give the client its border back */
440 client_toggle_border(self, TRUE);
442 /* reparent the window out of the frame, and free the frame */
443 frame_release_client(self->frame, self);
446 if (ob_state() != OB_STATE_EXITING) {
447 /* these values should not be persisted across a window
449 PROP_ERASE(self->window, net_wm_desktop);
450 PROP_ERASE(self->window, net_wm_state);
451 PROP_ERASE(self->window, wm_state);
453 /* if we're left in an iconic state, the client wont be mapped. this is
454 bad, since we will no longer be managing the window on restart */
456 XMapWindow(ob_display, self->window);
460 ob_debug("Unmanaged window 0x%lx\n", self->window);
462 /* free all data allocated in the client struct */
463 g_slist_free(self->transients);
464 for (j = 0; j < self->nicons; ++j)
465 g_free(self->icons[j].data);
466 if (self->nicons > 0)
469 g_free(self->icon_title);
475 /* update the list hints */
479 static void client_restore_session_state(ObClient *self)
483 if (!(it = session_state_find(self)))
486 self->session = it->data;
488 RECT_SET(self->area, self->session->x, self->session->y,
489 self->session->w, self->session->h);
490 self->positioned = TRUE;
491 XResizeWindow(ob_display, self->window,
492 self->session->w, self->session->h);
494 self->desktop = (self->session->desktop == DESKTOP_ALL ?
495 self->session->desktop :
496 MIN(screen_num_desktops - 1, self->session->desktop));
497 PROP_SET32(self->window, net_wm_desktop, cardinal, self->desktop);
499 self->shaded = self->session->shaded;
500 self->iconic = self->session->iconic;
501 self->skip_pager = self->session->skip_pager;
502 self->skip_taskbar = self->session->skip_taskbar;
503 self->fullscreen = self->session->fullscreen;
504 self->above = self->session->above;
505 self->below = self->session->below;
506 self->max_horz = self->session->max_horz;
507 self->max_vert = self->session->max_vert;
510 static void client_restore_session_stacking(ObClient *self)
514 if (!self->session) return;
516 it = g_list_find(session_saved_state, self->session);
517 for (it = g_list_previous(it); it; it = g_list_previous(it)) {
520 for (cit = client_list; cit; cit = g_list_next(cit))
521 if (session_state_cmp(it->data, cit->data))
524 client_calc_layer(self);
525 stacking_below(CLIENT_AS_WINDOW(self),
526 CLIENT_AS_WINDOW(cit->data));
532 void client_move_onscreen(ObClient *self, gboolean rude)
534 int x = self->area.x;
535 int y = self->area.y;
536 if (client_find_onscreen(self, &x, &y,
537 self->frame->area.width,
538 self->frame->area.height, rude)) {
539 client_configure(self, OB_CORNER_TOPLEFT, x, y,
540 self->area.width, self->area.height,
545 gboolean client_find_onscreen(ObClient *self, int *x, int *y, int w, int h,
549 int ox = *x, oy = *y;
551 frame_client_gravity(self->frame, x, y); /* get where the frame
554 /* XXX watch for xinerama dead areas */
556 a = screen_area(self->desktop);
557 if (!self->strut.right && *x >= a->x + a->width - 1)
558 *x = a->x + a->width - self->frame->area.width;
559 if (!self->strut.bottom && *y >= a->y + a->height - 1)
560 *y = a->y + a->height - self->frame->area.height;
561 if (!self->strut.left && *x + self->frame->area.width - 1 < a->x)
563 if (!self->strut.top && *y + self->frame->area.height - 1 < a->y)
567 /* this is my MOZILLA BITCHSLAP. oh ya it fucking feels good.
568 Java can suck it too. */
570 /* dont let windows map/move into the strut unless they
571 are bigger than the available area */
573 if (!self->strut.left && *x < a->x) *x = a->x;
574 if (!self->strut.right && *x + w > a->x + a->width)
575 *x = a->x + a->width - w;
577 if (h <= a->height) {
578 if (!self->strut.top && *y < a->y) *y = a->y;
579 if (!self->strut.bottom && *y + h > a->y + a->height)
580 *y = a->y + a->height - h;
584 frame_frame_gravity(self->frame, x, y); /* get where the client
587 return ox != *x || oy != *y;
590 static void client_toggle_border(ObClient *self, gboolean show)
592 /* adjust our idea of where the client is, based on its border. When the
593 border is removed, the client should now be considered to be in a
595 when re-adding the border to the client, the same operation needs to be
597 int oldx = self->area.x, oldy = self->area.y;
598 int x = oldx, y = oldy;
599 switch(self->gravity) {
601 case NorthWestGravity:
603 case SouthWestGravity:
605 case NorthEastGravity:
607 case SouthEastGravity:
608 if (show) x -= self->border_width * 2;
609 else x += self->border_width * 2;
616 if (show) x -= self->border_width;
617 else x += self->border_width;
620 switch(self->gravity) {
622 case NorthWestGravity:
624 case NorthEastGravity:
626 case SouthWestGravity:
628 case SouthEastGravity:
629 if (show) y -= self->border_width * 2;
630 else y += self->border_width * 2;
637 if (show) y -= self->border_width;
638 else y += self->border_width;
645 XSetWindowBorderWidth(ob_display, self->window, self->border_width);
647 /* move the client so it is back it the right spot _with_ its
649 if (x != oldx || y != oldy)
650 XMoveWindow(ob_display, self->window, x, y);
652 XSetWindowBorderWidth(ob_display, self->window, 0);
656 static void client_get_all(ObClient *self)
658 /* non-zero defaults */
659 self->title_count = 1;
660 self->wmstate = NormalState;
662 self->decorate = TRUE;
664 client_get_area(self);
665 client_update_transient_for(self);
666 client_update_wmhints(self);
667 client_get_desktop(self);
668 client_get_state(self);
669 client_get_shaped(self);
671 client_get_mwm_hints(self);
672 client_get_type(self);/* this can change the mwmhints for special cases */
674 client_update_protocols(self);
676 client_get_gravity(self); /* get the attribute gravity */
677 client_update_normal_hints(self); /* this may override the attribute
680 /* got the type, the mwmhints, the protocols, and the normal hints
681 (min/max sizes), so we're ready to set up the decorations/functions */
682 client_setup_decor_and_functions(self);
684 client_update_title(self);
685 client_update_class(self);
686 client_update_strut(self);
687 client_update_icons(self);
690 static void client_get_area(ObClient *self)
692 XWindowAttributes wattrib;
695 ret = XGetWindowAttributes(ob_display, self->window, &wattrib);
696 g_assert(ret != BadWindow);
698 RECT_SET(self->area, wattrib.x, wattrib.y, wattrib.width, wattrib.height);
699 self->border_width = wattrib.border_width;
702 static void client_get_desktop(ObClient *self)
704 guint32 d = screen_num_desktops; /* an always-invalid value */
706 if (PROP_GET32(self->window, net_wm_desktop, cardinal, &d)) {
707 if (d >= screen_num_desktops && d != DESKTOP_ALL)
708 self->desktop = screen_num_desktops - 1;
712 gboolean trdesk = FALSE;
714 if (self->transient_for) {
715 if (self->transient_for != OB_TRAN_GROUP) {
716 self->desktop = self->transient_for->desktop;
721 for (it = self->group->members; it; it = it->next)
722 if (it->data != self &&
723 !((ObClient*)it->data)->transient_for) {
724 self->desktop = ((ObClient*)it->data)->desktop;
731 /* defaults to the current desktop */
732 self->desktop = screen_desktop;
734 if (self->desktop != d) {
735 /* set the desktop hint, to make sure that it always exists */
736 PROP_SET32(self->window, net_wm_desktop, cardinal, self->desktop);
740 static void client_get_state(ObClient *self)
745 self->modal = self->shaded = self->max_horz = self->max_vert =
746 self->fullscreen = self->above = self->below = self->iconic =
747 self->skip_taskbar = self->skip_pager = FALSE;
749 if (PROP_GETA32(self->window, net_wm_state, atom, &state, &num)) {
751 for (i = 0; i < num; ++i) {
752 if (state[i] == prop_atoms.net_wm_state_modal)
754 else if (state[i] == prop_atoms.net_wm_state_shaded)
756 else if (state[i] == prop_atoms.net_wm_state_hidden)
758 else if (state[i] == prop_atoms.net_wm_state_skip_taskbar)
759 self->skip_taskbar = TRUE;
760 else if (state[i] == prop_atoms.net_wm_state_skip_pager)
761 self->skip_pager = TRUE;
762 else if (state[i] == prop_atoms.net_wm_state_fullscreen)
763 self->fullscreen = TRUE;
764 else if (state[i] == prop_atoms.net_wm_state_maximized_vert)
765 self->max_vert = TRUE;
766 else if (state[i] == prop_atoms.net_wm_state_maximized_horz)
767 self->max_horz = TRUE;
768 else if (state[i] == prop_atoms.net_wm_state_above)
770 else if (state[i] == prop_atoms.net_wm_state_below)
778 static void client_get_shaped(ObClient *self)
780 self->shaped = FALSE;
782 if (extensions_shape) {
787 XShapeSelectInput(ob_display, self->window, ShapeNotifyMask);
789 XShapeQueryExtents(ob_display, self->window, &s, &foo,
790 &foo, &ufoo, &ufoo, &foo, &foo, &foo, &ufoo,
792 self->shaped = (s != 0);
797 void client_update_transient_for(ObClient *self)
800 ObClient *target = NULL;
802 if (XGetTransientForHint(ob_display, self->window, &t)) {
803 self->transient = TRUE;
804 if (t != self->window) { /* cant be transient to itself! */
805 target = g_hash_table_lookup(window_map, &t);
806 /* if this happens then we need to check for it*/
807 g_assert(target != self);
808 g_assert(!target || WINDOW_IS_CLIENT(target));
810 if (!target && self->group) {
811 /* not transient to a client, see if it is transient for a
813 if (t == self->group->leader ||
815 t == RootWindow(ob_display, ob_screen)) {
816 /* window is a transient for its group! */
817 target = OB_TRAN_GROUP;
822 self->transient = FALSE;
824 /* if anything has changed... */
825 if (target != self->transient_for) {
826 if (self->transient_for == OB_TRAN_GROUP) { /* transient of group */
829 /* remove from old parents */
830 for (it = self->group->members; it; it = g_slist_next(it)) {
831 ObClient *c = it->data;
832 if (c != self && !c->transient_for)
833 c->transients = g_slist_remove(c->transients, self);
835 } else if (self->transient_for != NULL) { /* transient of window */
836 /* remove from old parent */
837 self->transient_for->transients =
838 g_slist_remove(self->transient_for->transients, self);
840 self->transient_for = target;
841 if (self->transient_for == OB_TRAN_GROUP) { /* transient of group */
844 /* add to new parents */
845 for (it = self->group->members; it; it = g_slist_next(it)) {
846 ObClient *c = it->data;
847 if (c != self && !c->transient_for)
848 c->transients = g_slist_append(c->transients, self);
851 /* remove all transients which are in the group, that causes
852 circlular pointer hell of doom */
853 for (it = self->group->members; it; it = g_slist_next(it)) {
855 for (sit = self->transients; sit; sit = next) {
856 next = g_slist_next(sit);
857 if (sit->data == it->data)
859 g_slist_delete_link(self->transients, sit);
862 } else if (self->transient_for != NULL) { /* transient of window */
863 /* add to new parent */
864 self->transient_for->transients =
865 g_slist_append(self->transient_for->transients, self);
870 static void client_get_mwm_hints(ObClient *self)
875 self->mwmhints.flags = 0; /* default to none */
877 if (PROP_GETA32(self->window, motif_wm_hints, motif_wm_hints,
879 if (num >= OB_MWM_ELEMENTS) {
880 self->mwmhints.flags = hints[0];
881 self->mwmhints.functions = hints[1];
882 self->mwmhints.decorations = hints[2];
888 void client_get_type(ObClient *self)
895 if (PROP_GETA32(self->window, net_wm_window_type, atom, &val, &num)) {
896 /* use the first value that we know about in the array */
897 for (i = 0; i < num; ++i) {
898 if (val[i] == prop_atoms.net_wm_window_type_desktop)
899 self->type = OB_CLIENT_TYPE_DESKTOP;
900 else if (val[i] == prop_atoms.net_wm_window_type_dock)
901 self->type = OB_CLIENT_TYPE_DOCK;
902 else if (val[i] == prop_atoms.net_wm_window_type_toolbar)
903 self->type = OB_CLIENT_TYPE_TOOLBAR;
904 else if (val[i] == prop_atoms.net_wm_window_type_menu)
905 self->type = OB_CLIENT_TYPE_MENU;
906 else if (val[i] == prop_atoms.net_wm_window_type_utility)
907 self->type = OB_CLIENT_TYPE_UTILITY;
908 else if (val[i] == prop_atoms.net_wm_window_type_splash)
909 self->type = OB_CLIENT_TYPE_SPLASH;
910 else if (val[i] == prop_atoms.net_wm_window_type_dialog)
911 self->type = OB_CLIENT_TYPE_DIALOG;
912 else if (val[i] == prop_atoms.net_wm_window_type_normal)
913 self->type = OB_CLIENT_TYPE_NORMAL;
914 else if (val[i] == prop_atoms.kde_net_wm_window_type_override) {
915 /* prevent this window from getting any decor or
917 self->mwmhints.flags &= (OB_MWM_FLAG_FUNCTIONS |
918 OB_MWM_FLAG_DECORATIONS);
919 self->mwmhints.decorations = 0;
920 self->mwmhints.functions = 0;
922 if (self->type != (ObClientType) -1)
923 break; /* grab the first legit type */
928 if (self->type == (ObClientType) -1) {
929 /*the window type hint was not set, which means we either classify
930 ourself as a normal window or a dialog, depending on if we are a
933 self->type = OB_CLIENT_TYPE_DIALOG;
935 self->type = OB_CLIENT_TYPE_NORMAL;
939 void client_update_protocols(ObClient *self)
944 self->focus_notify = FALSE;
945 self->delete_window = FALSE;
947 if (PROP_GETA32(self->window, wm_protocols, atom, &proto, &num_return)) {
948 for (i = 0; i < num_return; ++i) {
949 if (proto[i] == prop_atoms.wm_delete_window) {
950 /* this means we can request the window to close */
951 self->delete_window = TRUE;
952 } else if (proto[i] == prop_atoms.wm_take_focus)
953 /* if this protocol is requested, then the window will be
954 notified whenever we want it to receive focus */
955 self->focus_notify = TRUE;
961 static void client_get_gravity(ObClient *self)
963 XWindowAttributes wattrib;
966 ret = XGetWindowAttributes(ob_display, self->window, &wattrib);
967 g_assert(ret != BadWindow);
968 self->gravity = wattrib.win_gravity;
971 void client_update_normal_hints(ObClient *self)
975 int oldgravity = self->gravity;
978 self->min_ratio = 0.0f;
979 self->max_ratio = 0.0f;
980 SIZE_SET(self->size_inc, 1, 1);
981 SIZE_SET(self->base_size, 0, 0);
982 SIZE_SET(self->min_size, 0, 0);
983 SIZE_SET(self->max_size, G_MAXINT, G_MAXINT);
985 /* get the hints from the window */
986 if (XGetWMNormalHints(ob_display, self->window, &size, &ret)) {
987 self->positioned = !!(size.flags & (PPosition|USPosition));
989 if (size.flags & PWinGravity) {
990 self->gravity = size.win_gravity;
992 /* if the client has a frame, i.e. has already been mapped and
993 is changing its gravity */
994 if (self->frame && self->gravity != oldgravity) {
995 /* move our idea of the client's position based on its new
997 self->area.x = self->frame->area.x;
998 self->area.y = self->frame->area.y;
999 frame_frame_gravity(self->frame, &self->area.x, &self->area.y);
1003 if (size.flags & PAspect) {
1004 if (size.min_aspect.y)
1005 self->min_ratio = (float)size.min_aspect.x / size.min_aspect.y;
1006 if (size.max_aspect.y)
1007 self->max_ratio = (float)size.max_aspect.x / size.max_aspect.y;
1010 if (size.flags & PMinSize)
1011 SIZE_SET(self->min_size, size.min_width, size.min_height);
1013 if (size.flags & PMaxSize)
1014 SIZE_SET(self->max_size, size.max_width, size.max_height);
1016 if (size.flags & PBaseSize)
1017 SIZE_SET(self->base_size, size.base_width, size.base_height);
1019 if (size.flags & PResizeInc)
1020 SIZE_SET(self->size_inc, size.width_inc, size.height_inc);
1024 void client_setup_decor_and_functions(ObClient *self)
1026 /* start with everything (cept fullscreen) */
1027 self->decorations = (OB_FRAME_DECOR_TITLEBAR |
1028 OB_FRAME_DECOR_HANDLE |
1029 OB_FRAME_DECOR_GRIPS |
1030 OB_FRAME_DECOR_BORDER |
1031 OB_FRAME_DECOR_ICON |
1032 OB_FRAME_DECOR_ALLDESKTOPS |
1033 OB_FRAME_DECOR_ICONIFY |
1034 OB_FRAME_DECOR_MAXIMIZE |
1035 OB_FRAME_DECOR_SHADE);
1036 self->functions = (OB_CLIENT_FUNC_RESIZE |
1037 OB_CLIENT_FUNC_MOVE |
1038 OB_CLIENT_FUNC_ICONIFY |
1039 OB_CLIENT_FUNC_MAXIMIZE |
1040 OB_CLIENT_FUNC_SHADE);
1041 if (self->delete_window) {
1042 self->functions |= OB_CLIENT_FUNC_CLOSE;
1043 self->decorations |= OB_FRAME_DECOR_CLOSE;
1046 if (!(self->min_size.width < self->max_size.width ||
1047 self->min_size.height < self->max_size.height))
1048 self->functions &= ~OB_CLIENT_FUNC_RESIZE;
1050 switch (self->type) {
1051 case OB_CLIENT_TYPE_NORMAL:
1052 /* normal windows retain all of the possible decorations and
1053 functionality, and are the only windows that you can fullscreen */
1054 self->functions |= OB_CLIENT_FUNC_FULLSCREEN;
1057 case OB_CLIENT_TYPE_DIALOG:
1058 case OB_CLIENT_TYPE_UTILITY:
1059 /* these windows cannot be maximized */
1060 self->functions &= ~OB_CLIENT_FUNC_MAXIMIZE;
1063 case OB_CLIENT_TYPE_MENU:
1064 case OB_CLIENT_TYPE_TOOLBAR:
1065 /* these windows get less functionality */
1066 self->functions &= ~(OB_CLIENT_FUNC_ICONIFY | OB_CLIENT_FUNC_RESIZE);
1069 case OB_CLIENT_TYPE_DESKTOP:
1070 case OB_CLIENT_TYPE_DOCK:
1071 case OB_CLIENT_TYPE_SPLASH:
1072 /* none of these windows are manipulated by the window manager */
1073 self->decorations = 0;
1074 self->functions = 0;
1078 /* Mwm Hints are applied subtractively to what has already been chosen for
1079 decor and functionality */
1080 if (self->mwmhints.flags & OB_MWM_FLAG_DECORATIONS) {
1081 if (! (self->mwmhints.decorations & OB_MWM_DECOR_ALL)) {
1082 if (! ((self->mwmhints.decorations & OB_MWM_DECOR_HANDLE) ||
1083 (self->mwmhints.decorations & OB_MWM_DECOR_TITLE)))
1084 /* if the mwm hints request no handle or title, then all
1085 decorations are disabled */
1086 self->decorations = 0;
1090 if (self->mwmhints.flags & OB_MWM_FLAG_FUNCTIONS) {
1091 if (! (self->mwmhints.functions & OB_MWM_FUNC_ALL)) {
1092 if (! (self->mwmhints.functions & OB_MWM_FUNC_RESIZE))
1093 self->functions &= ~OB_CLIENT_FUNC_RESIZE;
1094 if (! (self->mwmhints.functions & OB_MWM_FUNC_MOVE))
1095 self->functions &= ~OB_CLIENT_FUNC_MOVE;
1096 /* dont let mwm hints kill any buttons
1097 if (! (self->mwmhints.functions & OB_MWM_FUNC_ICONIFY))
1098 self->functions &= ~OB_CLIENT_FUNC_ICONIFY;
1099 if (! (self->mwmhints.functions & OB_MWM_FUNC_MAXIMIZE))
1100 self->functions &= ~OB_CLIENT_FUNC_MAXIMIZE;
1102 /* dont let mwm hints kill the close button
1103 if (! (self->mwmhints.functions & MwmFunc_Close))
1104 self->functions &= ~OB_CLIENT_FUNC_CLOSE; */
1108 if (!(self->functions & OB_CLIENT_FUNC_SHADE))
1109 self->decorations &= ~OB_FRAME_DECOR_SHADE;
1110 if (!(self->functions & OB_CLIENT_FUNC_ICONIFY))
1111 self->decorations &= ~OB_FRAME_DECOR_ICONIFY;
1112 if (!(self->functions & OB_CLIENT_FUNC_RESIZE))
1113 self->decorations &= ~OB_FRAME_DECOR_GRIPS;
1115 /* can't maximize without moving/resizing */
1116 if (!((self->functions & OB_CLIENT_FUNC_MAXIMIZE) &&
1117 (self->functions & OB_CLIENT_FUNC_MOVE) &&
1118 (self->functions & OB_CLIENT_FUNC_RESIZE))) {
1119 self->functions &= ~OB_CLIENT_FUNC_MAXIMIZE;
1120 self->decorations &= ~OB_FRAME_DECOR_MAXIMIZE;
1123 /* kill the handle on fully maxed windows */
1124 if (self->max_vert && self->max_horz)
1125 self->decorations &= ~OB_FRAME_DECOR_HANDLE;
1127 /* finally, the user can have requested no decorations, which overrides
1129 if (!self->decorate)
1130 self->decorations = OB_FRAME_DECOR_BORDER;
1132 /* if we don't have a titlebar, then we cannot shade! */
1133 if (!(self->decorations & OB_FRAME_DECOR_TITLEBAR))
1134 self->functions &= ~OB_CLIENT_FUNC_SHADE;
1136 /* now we need to check against rules for the client's current state */
1137 if (self->fullscreen) {
1138 self->functions &= (OB_CLIENT_FUNC_CLOSE |
1139 OB_CLIENT_FUNC_FULLSCREEN |
1140 OB_CLIENT_FUNC_ICONIFY);
1141 self->decorations = 0;
1144 client_change_allowed_actions(self);
1147 /* adjust the client's decorations, etc. */
1148 client_reconfigure(self);
1150 /* this makes sure that these windows appear on all desktops */
1151 if (self->type == OB_CLIENT_TYPE_DESKTOP &&
1152 self->desktop != DESKTOP_ALL)
1154 self->desktop = DESKTOP_ALL;
1159 static void client_change_allowed_actions(ObClient *self)
1164 /* desktop windows are kept on all desktops */
1165 if (self->type != OB_CLIENT_TYPE_DESKTOP)
1166 actions[num++] = prop_atoms.net_wm_action_change_desktop;
1168 if (self->functions & OB_CLIENT_FUNC_SHADE)
1169 actions[num++] = prop_atoms.net_wm_action_shade;
1170 if (self->functions & OB_CLIENT_FUNC_CLOSE)
1171 actions[num++] = prop_atoms.net_wm_action_close;
1172 if (self->functions & OB_CLIENT_FUNC_MOVE)
1173 actions[num++] = prop_atoms.net_wm_action_move;
1174 if (self->functions & OB_CLIENT_FUNC_ICONIFY)
1175 actions[num++] = prop_atoms.net_wm_action_minimize;
1176 if (self->functions & OB_CLIENT_FUNC_RESIZE)
1177 actions[num++] = prop_atoms.net_wm_action_resize;
1178 if (self->functions & OB_CLIENT_FUNC_FULLSCREEN)
1179 actions[num++] = prop_atoms.net_wm_action_fullscreen;
1180 if (self->functions & OB_CLIENT_FUNC_MAXIMIZE) {
1181 actions[num++] = prop_atoms.net_wm_action_maximize_horz;
1182 actions[num++] = prop_atoms.net_wm_action_maximize_vert;
1185 PROP_SETA32(self->window, net_wm_allowed_actions, atom, actions, num);
1187 /* make sure the window isn't breaking any rules now */
1189 if (!(self->functions & OB_CLIENT_FUNC_SHADE) && self->shaded) {
1190 if (self->frame) client_shade(self, FALSE);
1191 else self->shaded = FALSE;
1193 if (!(self->functions & OB_CLIENT_FUNC_ICONIFY) && self->iconic) {
1194 if (self->frame) client_iconify(self, FALSE, TRUE);
1195 else self->iconic = FALSE;
1197 if (!(self->functions & OB_CLIENT_FUNC_FULLSCREEN) && self->fullscreen) {
1198 if (self->frame) client_fullscreen(self, FALSE, TRUE);
1199 else self->fullscreen = FALSE;
1201 if (!(self->functions & OB_CLIENT_FUNC_MAXIMIZE) && (self->max_horz ||
1203 if (self->frame) client_maximize(self, FALSE, 0, TRUE);
1204 else self->max_vert = self->max_horz = FALSE;
1208 void client_reconfigure(ObClient *self)
1210 /* by making this pass FALSE for user, we avoid the emacs event storm where
1211 every configurenotify causes an update in its normal hints, i think this
1212 is generally what we want anyways... */
1213 client_configure(self, OB_CORNER_TOPLEFT, self->area.x, self->area.y,
1214 self->area.width, self->area.height, FALSE, TRUE);
1217 void client_update_wmhints(ObClient *self)
1220 gboolean ur = FALSE;
1223 /* assume a window takes input if it doesnt specify */
1224 self->can_focus = TRUE;
1226 if ((hints = XGetWMHints(ob_display, self->window)) != NULL) {
1227 if (hints->flags & InputHint)
1228 self->can_focus = hints->input;
1230 /* only do this when first managing the window *AND* when we aren't
1232 if (ob_state() != OB_STATE_STARTING && self->frame == NULL)
1233 if (hints->flags & StateHint)
1234 self->iconic = hints->initial_state == IconicState;
1236 if (hints->flags & XUrgencyHint)
1239 if (!(hints->flags & WindowGroupHint))
1240 hints->window_group = None;
1242 /* did the group state change? */
1243 if (hints->window_group !=
1244 (self->group ? self->group->leader : None)) {
1245 /* remove from the old group if there was one */
1246 if (self->group != NULL) {
1247 /* remove transients of the group */
1248 for (it = self->group->members; it; it = it->next)
1249 self->transients = g_slist_remove(self->transients,
1251 group_remove(self->group, self);
1254 if (hints->window_group != None) {
1255 self->group = group_add(hints->window_group, self);
1257 /* i can only have transients from the group if i am not
1259 if (!self->transient_for) {
1260 /* add other transients of the group that are already
1262 for (it = self->group->members; it; it = it->next) {
1263 ObClient *c = it->data;
1264 if (c != self && c->transient_for == OB_TRAN_GROUP)
1266 g_slist_append(self->transients, c);
1271 /* because the self->transient flag wont change from this call,
1272 we don't need to update the window's type and such, only its
1273 transient_for, and the transients lists of other windows in
1274 the group may be affected */
1275 client_update_transient_for(self);
1278 /* the WM_HINTS can contain an icon */
1279 client_update_icons(self);
1284 if (ur != self->urgent) {
1286 ob_debug("Urgent Hint for 0x%lx: %s\n", self->window,
1288 /* fire the urgent callback if we're mapped, otherwise, wait until
1289 after we're mapped */
1291 dispatch_client(Event_Client_Urgent, self, self->urgent, 0);
1295 void client_update_title(ObClient *self)
1301 gboolean read_title;
1303 g_free(self->title);
1306 if (!PROP_GETS(self->window, net_wm_name, utf8, &data))
1307 /* try old x stuff */
1308 if (!PROP_GETS(self->window, wm_name, locale, &data))
1309 data = g_strdup("Unnamed Window");
1311 /* look for duplicates and append a number */
1313 for (it = client_list; it; it = it->next)
1314 if (it->data != self) {
1315 ObClient *c = it->data;
1316 if (0 == strncmp(c->title, data, strlen(data)))
1317 nums |= 1 << c->title_count;
1319 /* find first free number */
1320 for (i = 1; i <= 32; ++i)
1321 if (!(nums & (1 << i))) {
1322 if (self->title_count == 1 || i == 1)
1323 self->title_count = i;
1326 /* dont display the number for the first window */
1327 if (self->title_count > 1) {
1328 char *vdata, *ndata;
1329 ndata = g_strdup_printf(" - [%u]", self->title_count);
1330 vdata = g_strconcat(data, ndata, NULL);
1336 PROP_SETS(self->window, net_wm_visible_name, data);
1341 frame_adjust_title(self->frame);
1343 /* update the icon title */
1345 g_free(self->icon_title);
1349 if (!PROP_GETS(self->window, net_wm_icon_name, utf8, &data))
1350 /* try old x stuff */
1351 if (!PROP_GETS(self->window, wm_icon_name, locale, &data)) {
1352 data = g_strdup(self->title);
1356 /* append the title count, dont display the number for the first window */
1357 if (read_title && self->title_count > 1) {
1358 char *vdata, *ndata;
1359 ndata = g_strdup_printf(" - [%u]", self->title_count);
1360 vdata = g_strconcat(data, ndata, NULL);
1366 PROP_SETS(self->window, net_wm_visible_icon_name, data);
1368 self->icon_title = data;
1371 void client_update_class(ObClient *self)
1376 if (self->name) g_free(self->name);
1377 if (self->class) g_free(self->class);
1378 if (self->role) g_free(self->role);
1380 self->name = self->class = self->role = NULL;
1382 if (PROP_GETSS(self->window, wm_class, locale, &data)) {
1384 self->name = g_strdup(data[0]);
1386 self->class = g_strdup(data[1]);
1391 if (PROP_GETS(self->window, wm_window_role, locale, &s))
1392 self->role = g_strdup(s);
1394 if (self->name == NULL) self->name = g_strdup("");
1395 if (self->class == NULL) self->class = g_strdup("");
1396 if (self->role == NULL) self->role = g_strdup("");
1399 void client_update_strut(ObClient *self)
1403 gboolean got = FALSE;
1406 if (PROP_GETA32(self->window, net_wm_strut_partial, cardinal,
1410 STRUT_PARTIAL_SET(strut,
1411 data[0], data[2], data[1], data[3],
1412 data[4], data[5], data[8], data[9],
1413 data[6], data[7], data[10], data[11]);
1419 PROP_GETA32(self->window, net_wm_strut, cardinal, &data, &num)) {
1422 STRUT_PARTIAL_SET(strut,
1423 data[0], data[2], data[1], data[3],
1424 0, 0, 0, 0, 0, 0, 0, 0);
1430 STRUT_PARTIAL_SET(strut, 0, 0, 0, 0,
1431 0, 0, 0, 0, 0, 0, 0, 0);
1433 if (!STRUT_EQUAL(strut, self->strut)) {
1434 self->strut = strut;
1436 /* updating here is pointless while we're being mapped cuz we're not in
1437 the client list yet */
1439 screen_update_areas();
1443 void client_update_icons(ObClient *self)
1449 for (i = 0; i < self->nicons; ++i)
1450 g_free(self->icons[i].data);
1451 if (self->nicons > 0)
1452 g_free(self->icons);
1455 if (PROP_GETA32(self->window, net_wm_icon, cardinal, &data, &num)) {
1456 /* figure out how many valid icons are in here */
1458 while (num - i > 2) {
1462 if (i > num || w*h == 0) break;
1466 self->icons = g_new(ObClientIcon, self->nicons);
1468 /* store the icons */
1470 for (j = 0; j < self->nicons; ++j) {
1473 w = self->icons[j].width = data[i++];
1474 h = self->icons[j].height = data[i++];
1476 if (w*h == 0) continue;
1478 self->icons[j].data = g_new(RrPixel32, w * h);
1479 for (x = 0, y = 0, t = 0; t < w * h; ++t, ++x, ++i) {
1484 self->icons[j].data[t] =
1485 (((data[i] >> 24) & 0xff) << RrDefaultAlphaOffset) +
1486 (((data[i] >> 16) & 0xff) << RrDefaultRedOffset) +
1487 (((data[i] >> 8) & 0xff) << RrDefaultGreenOffset) +
1488 (((data[i] >> 0) & 0xff) << RrDefaultBlueOffset);
1494 } else if (PROP_GETA32(self->window, kwm_win_icon,
1495 kwm_win_icon, &data, &num)) {
1498 self->icons = g_new(ObClientIcon, self->nicons);
1499 xerror_set_ignore(TRUE);
1500 if (!RrPixmapToRGBA(ob_rr_inst,
1502 &self->icons[self->nicons-1].width,
1503 &self->icons[self->nicons-1].height,
1504 &self->icons[self->nicons-1].data)) {
1505 g_free(&self->icons[self->nicons-1]);
1508 xerror_set_ignore(FALSE);
1514 if ((hints = XGetWMHints(ob_display, self->window))) {
1515 if (hints->flags & IconPixmapHint) {
1517 self->icons = g_new(ObClientIcon, self->nicons);
1518 xerror_set_ignore(TRUE);
1519 if (!RrPixmapToRGBA(ob_rr_inst,
1521 (hints->flags & IconMaskHint ?
1522 hints->icon_mask : None),
1523 &self->icons[self->nicons-1].width,
1524 &self->icons[self->nicons-1].height,
1525 &self->icons[self->nicons-1].data)){
1526 g_free(&self->icons[self->nicons-1]);
1529 xerror_set_ignore(FALSE);
1536 frame_adjust_icon(self->frame);
1539 static void client_change_state(ObClient *self)
1542 guint32 netstate[10];
1545 state[0] = self->wmstate;
1547 PROP_SETA32(self->window, wm_state, wm_state, state, 2);
1551 netstate[num++] = prop_atoms.net_wm_state_modal;
1553 netstate[num++] = prop_atoms.net_wm_state_shaded;
1555 netstate[num++] = prop_atoms.net_wm_state_hidden;
1556 if (self->skip_taskbar)
1557 netstate[num++] = prop_atoms.net_wm_state_skip_taskbar;
1558 if (self->skip_pager)
1559 netstate[num++] = prop_atoms.net_wm_state_skip_pager;
1560 if (self->fullscreen)
1561 netstate[num++] = prop_atoms.net_wm_state_fullscreen;
1563 netstate[num++] = prop_atoms.net_wm_state_maximized_vert;
1565 netstate[num++] = prop_atoms.net_wm_state_maximized_horz;
1567 netstate[num++] = prop_atoms.net_wm_state_above;
1569 netstate[num++] = prop_atoms.net_wm_state_below;
1570 PROP_SETA32(self->window, net_wm_state, atom, netstate, num);
1572 client_calc_layer(self);
1575 frame_adjust_state(self->frame);
1578 ObClient *client_search_focus_tree(ObClient *self)
1583 for (it = self->transients; it != NULL; it = it->next) {
1584 if (client_focused(it->data)) return it->data;
1585 if ((ret = client_search_focus_tree(it->data))) return ret;
1590 ObClient *client_search_focus_tree_full(ObClient *self)
1592 if (self->transient_for) {
1593 if (self->transient_for != OB_TRAN_GROUP) {
1594 return client_search_focus_tree_full(self->transient_for);
1597 gboolean recursed = FALSE;
1599 for (it = self->group->members; it; it = it->next)
1600 if (!((ObClient*)it->data)->transient_for) {
1602 if ((c = client_search_focus_tree_full(it->data)))
1611 /* this function checks the whole tree, the client_search_focus_tree~
1612 does not, so we need to check this window */
1613 if (client_focused(self))
1615 return client_search_focus_tree(self);
1618 static ObStackingLayer calc_layer(ObClient *self)
1622 if (self->fullscreen) l = OB_STACKING_LAYER_FULLSCREEN;
1623 else if (self->type == OB_CLIENT_TYPE_DESKTOP)
1624 l = OB_STACKING_LAYER_DESKTOP;
1625 else if (self->type == OB_CLIENT_TYPE_DOCK) {
1626 if (!self->below) l = OB_STACKING_LAYER_TOP;
1627 else l = OB_STACKING_LAYER_NORMAL;
1629 else if (self->above) l = OB_STACKING_LAYER_ABOVE;
1630 else if (self->below) l = OB_STACKING_LAYER_BELOW;
1631 else l = OB_STACKING_LAYER_NORMAL;
1636 static void client_calc_layer_recursive(ObClient *self, ObClient *orig,
1637 ObStackingLayer l, gboolean raised)
1639 ObStackingLayer old, own;
1643 own = calc_layer(self);
1644 self->layer = l > own ? l : own;
1646 for (it = self->transients; it; it = it->next)
1647 client_calc_layer_recursive(it->data, orig,
1648 l, raised ? raised : l != old);
1650 if (!raised && l != old)
1651 if (orig->frame) { /* only restack if the original window is managed */
1652 /* XXX add_non_intrusive ever? */
1653 stacking_remove(CLIENT_AS_WINDOW(self));
1654 stacking_add(CLIENT_AS_WINDOW(self));
1658 void client_calc_layer(ObClient *self)
1665 /* transients take on the layer of their parents */
1666 self = client_search_top_transient(self);
1668 l = calc_layer(self);
1670 client_calc_layer_recursive(self, orig, l, FALSE);
1673 gboolean client_should_show(ObClient *self)
1675 if (self->iconic) return FALSE;
1676 else if (!(self->desktop == screen_desktop ||
1677 self->desktop == DESKTOP_ALL)) return FALSE;
1678 else if (client_normal(self) && screen_showing_desktop) return FALSE;
1683 static void client_showhide(ObClient *self)
1686 if (client_should_show(self))
1687 frame_show(self->frame);
1689 frame_hide(self->frame);
1692 gboolean client_normal(ObClient *self) {
1693 return ! (self->type == OB_CLIENT_TYPE_DESKTOP ||
1694 self->type == OB_CLIENT_TYPE_DOCK ||
1695 self->type == OB_CLIENT_TYPE_SPLASH);
1698 static void client_apply_startup_state(ObClient *self)
1700 /* these are in a carefully crafted order.. */
1703 self->iconic = FALSE;
1704 client_iconify(self, TRUE, FALSE);
1706 if (self->fullscreen) {
1707 self->fullscreen = FALSE;
1708 client_fullscreen(self, TRUE, FALSE);
1711 self->shaded = FALSE;
1712 client_shade(self, TRUE);
1715 dispatch_client(Event_Client_Urgent, self, self->urgent, 0);
1717 if (self->max_vert && self->max_horz) {
1718 self->max_vert = self->max_horz = FALSE;
1719 client_maximize(self, TRUE, 0, FALSE);
1720 } else if (self->max_vert) {
1721 self->max_vert = FALSE;
1722 client_maximize(self, TRUE, 2, FALSE);
1723 } else if (self->max_horz) {
1724 self->max_horz = FALSE;
1725 client_maximize(self, TRUE, 1, FALSE);
1728 /* nothing to do for the other states:
1737 void client_configure_full(ObClient *self, ObCorner anchor,
1738 int x, int y, int w, int h,
1739 gboolean user, gboolean final,
1740 gboolean force_reply)
1742 gboolean moved = FALSE, resized = FALSE;
1743 guint fdecor = self->frame->decorations;
1744 gboolean fhorz = self->frame->max_horz;
1746 /* make the frame recalculate its dimentions n shit without changing
1747 anything visible for real, this way the constraints below can work with
1748 the updated frame dimensions. */
1749 frame_adjust_area(self->frame, TRUE, TRUE, TRUE);
1751 /* gets the frame's position */
1752 frame_client_gravity(self->frame, &x, &y);
1754 /* these positions are frame positions, not client positions */
1756 /* set the size and position if fullscreen */
1757 if (self->fullscreen) {
1760 XF86VidModeModeLine mode;
1765 i = client_monitor(self);
1766 a = screen_physical_area_monitor(i);
1769 if (i == 0 && /* primary head */
1770 extensions_vidmode &&
1771 XF86VidModeGetViewPort(ob_display, ob_screen, &x, &y) &&
1772 /* get the mode last so the mode.privsize isnt freed incorrectly */
1773 XF86VidModeGetModeLine(ob_display, ob_screen, &dot, &mode)) {
1778 if (mode.privsize) XFree(mode.private);
1788 user = FALSE; /* ignore that increment etc shit when in fullscreen */
1792 a = screen_area_monitor(self->desktop, client_monitor(self));
1794 /* set the size and position if maximized */
1795 if (self->max_horz) {
1797 w = a->width - self->frame->size.left - self->frame->size.right;
1799 if (self->max_vert) {
1801 h = a->height - self->frame->size.top - self->frame->size.bottom;
1805 /* gets the client's position */
1806 frame_frame_gravity(self->frame, &x, &y);
1808 /* these override the above states! if you cant move you can't move! */
1810 if (!(self->functions & OB_CLIENT_FUNC_MOVE)) {
1814 if (!(self->functions & OB_CLIENT_FUNC_RESIZE)) {
1815 w = self->area.width;
1816 h = self->area.height;
1820 if (!(w == self->area.width && h == self->area.height)) {
1821 int basew, baseh, minw, minh;
1824 /* base size is substituted with min size if not specified */
1825 if (self->base_size.width || self->base_size.height) {
1826 basew = self->base_size.width;
1827 baseh = self->base_size.height;
1829 basew = self->min_size.width;
1830 baseh = self->min_size.height;
1832 /* min size is substituted with base size if not specified */
1833 if (self->min_size.width || self->min_size.height) {
1834 minw = self->min_size.width;
1835 minh = self->min_size.height;
1837 minw = self->base_size.width;
1838 minh = self->base_size.height;
1841 /* for interactive resizing. have to move half an increment in each
1844 /* how far we are towards the next size inc */
1845 mw = (w - basew) % self->size_inc.width;
1846 mh = (h - baseh) % self->size_inc.height;
1848 aw = self->size_inc.width / 2;
1849 ah = self->size_inc.height / 2;
1850 /* don't let us move into a new size increment */
1851 if (mw + aw >= self->size_inc.width)
1852 aw = self->size_inc.width - mw - 1;
1853 if (mh + ah >= self->size_inc.height)
1854 ah = self->size_inc.height - mh - 1;
1858 /* if this is a user-requested resize, then check against min/max
1861 /* smaller than min size or bigger than max size? */
1862 if (w > self->max_size.width) w = self->max_size.width;
1863 if (w < minw) w = minw;
1864 if (h > self->max_size.height) h = self->max_size.height;
1865 if (h < minh) h = minh;
1870 /* keep to the increments */
1871 w /= self->size_inc.width;
1872 h /= self->size_inc.height;
1874 /* you cannot resize to nothing */
1875 if (basew + w < 1) w = 1 - basew;
1876 if (baseh + h < 1) h = 1 - baseh;
1878 /* store the logical size */
1879 SIZE_SET(self->logical_size,
1880 self->size_inc.width > 1 ? w : w + basew,
1881 self->size_inc.height > 1 ? h : h + baseh);
1883 w *= self->size_inc.width;
1884 h *= self->size_inc.height;
1889 /* adjust the height to match the width for the aspect ratios.
1890 for this, min size is not substituted for base size ever. */
1891 w -= self->base_size.width;
1892 h -= self->base_size.height;
1894 if (self->min_ratio)
1895 if (h * self->min_ratio > w) h = (int)(w / self->min_ratio);
1896 if (self->max_ratio)
1897 if (h * self->max_ratio < w) h = (int)(w / self->max_ratio);
1899 w += self->base_size.width;
1900 h += self->base_size.height;
1904 case OB_CORNER_TOPLEFT:
1906 case OB_CORNER_TOPRIGHT:
1907 x -= w - self->area.width;
1909 case OB_CORNER_BOTTOMLEFT:
1910 y -= h - self->area.height;
1912 case OB_CORNER_BOTTOMRIGHT:
1913 x -= w - self->area.width;
1914 y -= h - self->area.height;
1918 moved = x != self->area.x || y != self->area.y;
1919 resized = w != self->area.width || h != self->area.height;
1921 RECT_SET(self->area, x, y, w, h);
1923 /* for app-requested resizes, always resize if 'resized' is true.
1924 for user-requested ones, only resize if final is true, or when
1925 resizing in redraw mode */
1926 if ((!user && resized) ||
1927 (user && (final || (resized && config_redraw_resize))))
1928 XResizeWindow(ob_display, self->window, w, h);
1930 /* move/resize the frame to match the request */
1932 if (self->decorations != fdecor || self->max_horz != fhorz)
1933 moved = resized = TRUE;
1935 if (moved || resized)
1936 frame_adjust_area(self->frame, moved, resized, FALSE);
1938 if (!resized && (force_reply || ((!user && moved) || (user && final))))
1941 event.type = ConfigureNotify;
1942 event.xconfigure.display = ob_display;
1943 event.xconfigure.event = self->window;
1944 event.xconfigure.window = self->window;
1946 /* root window real coords */
1947 event.xconfigure.x = self->frame->area.x + self->frame->size.left -
1949 event.xconfigure.y = self->frame->area.y + self->frame->size.top -
1951 event.xconfigure.width = w;
1952 event.xconfigure.height = h;
1953 event.xconfigure.border_width = 0;
1954 event.xconfigure.above = self->frame->plate;
1955 event.xconfigure.override_redirect = FALSE;
1956 XSendEvent(event.xconfigure.display, event.xconfigure.window,
1957 FALSE, StructureNotifyMask, &event);
1962 void client_fullscreen(ObClient *self, gboolean fs, gboolean savearea)
1966 if (!(self->functions & OB_CLIENT_FUNC_FULLSCREEN) || /* can't */
1967 self->fullscreen == fs) return; /* already done */
1969 self->fullscreen = fs;
1970 client_change_state(self); /* change the state hints on the client,
1971 and adjust out layer/stacking */
1975 guint32 dimensions[4];
1976 dimensions[0] = self->area.x;
1977 dimensions[1] = self->area.y;
1978 dimensions[2] = self->area.width;
1979 dimensions[3] = self->area.height;
1981 PROP_SETA32(self->window, openbox_premax, cardinal,
1985 /* these are not actually used cuz client_configure will set them
1986 as appropriate when the window is fullscreened */
1993 /* pick some fallbacks... */
1994 a = screen_area_monitor(self->desktop, 0);
1995 x = a->x + a->width / 4;
1996 y = a->y + a->height / 4;
2000 if (PROP_GETA32(self->window, openbox_premax, cardinal,
2001 (guint32**)&dimensions, &num)) {
2012 client_setup_decor_and_functions(self);
2014 client_configure(self, OB_CORNER_TOPLEFT, x, y, w, h, TRUE, TRUE);
2016 /* try focus us when we go into fullscreen mode */
2020 static void client_iconify_recursive(ObClient *self,
2021 gboolean iconic, gboolean curdesk)
2024 gboolean changed = FALSE;
2027 if (self->iconic != iconic) {
2028 ob_debug("%sconifying window: 0x%lx\n", (iconic ? "I" : "Uni"),
2031 self->iconic = iconic;
2034 if (self->functions & OB_CLIENT_FUNC_ICONIFY) {
2035 self->wmstate = IconicState;
2036 self->ignore_unmaps++;
2037 /* we unmap the client itself so that we can get MapRequest
2038 events, and because the ICCCM tells us to! */
2039 XUnmapWindow(ob_display, self->window);
2041 /* update the focus lists.. iconic windows go to the bottom of
2042 the list, put the new iconic window at the 'top of the
2044 focus_order_to_top(self);
2050 client_set_desktop(self, screen_desktop, FALSE);
2051 self->wmstate = self->shaded ? IconicState : NormalState;
2052 XMapWindow(ob_display, self->window);
2054 /* this puts it after the current focused window */
2055 focus_order_remove(self);
2056 focus_order_add_new(self);
2058 /* this is here cuz with the VIDMODE extension, the viewport can
2059 change while a fullscreen window is iconic, and when it
2060 uniconifies, it would be nice if it did so to the new position
2062 client_reconfigure(self);
2069 client_change_state(self);
2070 client_showhide(self);
2071 screen_update_areas();
2073 dispatch_client(iconic ? Event_Client_Unmapped : Event_Client_Mapped,
2077 /* iconify all transients */
2078 for (it = self->transients; it != NULL; it = it->next)
2079 if (it->data != self) client_iconify_recursive(it->data,
2083 void client_iconify(ObClient *self, gboolean iconic, gboolean curdesk)
2085 /* move up the transient chain as far as possible first */
2086 self = client_search_top_transient(self);
2088 client_iconify_recursive(client_search_top_transient(self),
2092 void client_maximize(ObClient *self, gboolean max, int dir, gboolean savearea)
2096 g_assert(dir == 0 || dir == 1 || dir == 2);
2097 if (!(self->functions & OB_CLIENT_FUNC_MAXIMIZE)) return; /* can't */
2099 /* check if already done */
2101 if (dir == 0 && self->max_horz && self->max_vert) return;
2102 if (dir == 1 && self->max_horz) return;
2103 if (dir == 2 && self->max_vert) return;
2105 if (dir == 0 && !self->max_horz && !self->max_vert) return;
2106 if (dir == 1 && !self->max_horz) return;
2107 if (dir == 2 && !self->max_vert) return;
2110 /* work with the frame's coords */
2111 x = self->frame->area.x;
2112 y = self->frame->area.y;
2113 w = self->area.width;
2114 h = self->area.height;
2118 gint32 dimensions[4];
2127 /* get the property off the window and use it for the dimensions
2128 we are already maxed on */
2129 if (PROP_GETA32(self->window, openbox_premax, cardinal,
2130 (guint32**)&readdim, &num)) {
2132 if (self->max_horz) {
2133 dimensions[0] = readdim[0];
2134 dimensions[2] = readdim[2];
2136 if (self->max_vert) {
2137 dimensions[1] = readdim[1];
2138 dimensions[3] = readdim[3];
2144 PROP_SETA32(self->window, openbox_premax, cardinal,
2145 (guint32*)dimensions, 4);
2152 /* pick some fallbacks... */
2153 a = screen_area_monitor(self->desktop, 0);
2154 if (dir == 0 || dir == 1) { /* horz */
2155 x = a->x + a->width / 4;
2158 if (dir == 0 || dir == 2) { /* vert */
2159 y = a->y + a->height / 4;
2163 if (PROP_GETA32(self->window, openbox_premax, cardinal,
2164 (guint32**)&dimensions, &num)) {
2166 if (dir == 0 || dir == 1) { /* horz */
2170 if (dir == 0 || dir == 2) { /* vert */
2179 if (dir == 0 || dir == 1) /* horz */
2180 self->max_horz = max;
2181 if (dir == 0 || dir == 2) /* vert */
2182 self->max_vert = max;
2184 if (!self->max_horz && !self->max_vert)
2185 PROP_ERASE(self->window, openbox_premax);
2187 client_change_state(self); /* change the state hints on the client */
2189 client_setup_decor_and_functions(self);
2191 /* figure out where the client should be going */
2192 frame_frame_gravity(self->frame, &x, &y);
2193 client_configure(self, OB_CORNER_TOPLEFT, x, y, w, h, TRUE, TRUE);
2196 void client_shade(ObClient *self, gboolean shade)
2198 if ((!(self->functions & OB_CLIENT_FUNC_SHADE) &&
2199 shade) || /* can't shade */
2200 self->shaded == shade) return; /* already done */
2202 /* when we're iconic, don't change the wmstate */
2204 self->wmstate = shade ? IconicState : NormalState;
2205 self->shaded = shade;
2206 client_change_state(self);
2207 /* resize the frame to just the titlebar */
2208 frame_adjust_area(self->frame, FALSE, FALSE, FALSE);
2211 void client_close(ObClient *self)
2215 if (!(self->functions & OB_CLIENT_FUNC_CLOSE)) return;
2218 XXX: itd be cool to do timeouts and shit here for killing the client's
2220 like... if the window is around after 5 seconds, then the close button
2221 turns a nice red, and if this function is called again, the client is
2225 ce.xclient.type = ClientMessage;
2226 ce.xclient.message_type = prop_atoms.wm_protocols;
2227 ce.xclient.display = ob_display;
2228 ce.xclient.window = self->window;
2229 ce.xclient.format = 32;
2230 ce.xclient.data.l[0] = prop_atoms.wm_delete_window;
2231 ce.xclient.data.l[1] = event_lasttime;
2232 ce.xclient.data.l[2] = 0l;
2233 ce.xclient.data.l[3] = 0l;
2234 ce.xclient.data.l[4] = 0l;
2235 XSendEvent(ob_display, self->window, FALSE, NoEventMask, &ce);
2238 void client_kill(ObClient *self)
2240 XKillClient(ob_display, self->window);
2243 void client_set_desktop_recursive(ObClient *self,
2244 guint target, gboolean donthide)
2249 if (target != self->desktop) {
2251 ob_debug("Setting desktop %u\n", target+1);
2253 g_assert(target < screen_num_desktops || target == DESKTOP_ALL);
2255 /* remove from the old desktop(s) */
2256 focus_order_remove(self);
2258 old = self->desktop;
2259 self->desktop = target;
2260 PROP_SET32(self->window, net_wm_desktop, cardinal, target);
2261 /* the frame can display the current desktop state */
2262 frame_adjust_state(self->frame);
2263 /* 'move' the window to the new desktop */
2265 client_showhide(self);
2266 /* raise if it was not already on the desktop */
2267 if (old != DESKTOP_ALL)
2268 stacking_raise(CLIENT_AS_WINDOW(self));
2269 screen_update_areas();
2271 /* add to the new desktop(s) */
2272 if (config_focus_new)
2273 focus_order_to_top(self);
2275 focus_order_to_bottom(self);
2277 dispatch_client(Event_Client_Desktop, self, target, old);
2280 /* move all transients */
2281 for (it = self->transients; it != NULL; it = it->next)
2282 if (it->data != self) client_set_desktop_recursive(it->data,
2286 void client_set_desktop(ObClient *self, guint target, gboolean donthide)
2288 client_set_desktop_recursive(client_search_top_transient(self),
2292 ObClient *client_search_modal_child(ObClient *self)
2297 for (it = self->transients; it != NULL; it = it->next) {
2298 ObClient *c = it->data;
2299 if ((ret = client_search_modal_child(c))) return ret;
2300 if (c->modal) return c;
2305 gboolean client_validate(ObClient *self)
2309 XSync(ob_display, FALSE); /* get all events on the server */
2311 if (XCheckTypedWindowEvent(ob_display, self->window, DestroyNotify, &e) ||
2312 XCheckTypedWindowEvent(ob_display, self->window, UnmapNotify, &e)) {
2313 XPutBackEvent(ob_display, &e);
2320 void client_set_wm_state(ObClient *self, long state)
2322 if (state == self->wmstate) return; /* no change */
2326 client_iconify(self, TRUE, TRUE);
2329 client_iconify(self, FALSE, TRUE);
2334 void client_set_state(ObClient *self, Atom action, long data1, long data2)
2336 gboolean shaded = self->shaded;
2337 gboolean fullscreen = self->fullscreen;
2338 gboolean max_horz = self->max_horz;
2339 gboolean max_vert = self->max_vert;
2342 if (!(action == prop_atoms.net_wm_state_add ||
2343 action == prop_atoms.net_wm_state_remove ||
2344 action == prop_atoms.net_wm_state_toggle))
2345 /* an invalid action was passed to the client message, ignore it */
2348 for (i = 0; i < 2; ++i) {
2349 Atom state = i == 0 ? data1 : data2;
2351 if (!state) continue;
2353 /* if toggling, then pick whether we're adding or removing */
2354 if (action == prop_atoms.net_wm_state_toggle) {
2355 if (state == prop_atoms.net_wm_state_modal)
2356 action = self->modal ? prop_atoms.net_wm_state_remove :
2357 prop_atoms.net_wm_state_add;
2358 else if (state == prop_atoms.net_wm_state_maximized_vert)
2359 action = self->max_vert ? prop_atoms.net_wm_state_remove :
2360 prop_atoms.net_wm_state_add;
2361 else if (state == prop_atoms.net_wm_state_maximized_horz)
2362 action = self->max_horz ? prop_atoms.net_wm_state_remove :
2363 prop_atoms.net_wm_state_add;
2364 else if (state == prop_atoms.net_wm_state_shaded)
2365 action = self->shaded ? prop_atoms.net_wm_state_remove :
2366 prop_atoms.net_wm_state_add;
2367 else if (state == prop_atoms.net_wm_state_skip_taskbar)
2368 action = self->skip_taskbar ?
2369 prop_atoms.net_wm_state_remove :
2370 prop_atoms.net_wm_state_add;
2371 else if (state == prop_atoms.net_wm_state_skip_pager)
2372 action = self->skip_pager ?
2373 prop_atoms.net_wm_state_remove :
2374 prop_atoms.net_wm_state_add;
2375 else if (state == prop_atoms.net_wm_state_fullscreen)
2376 action = self->fullscreen ?
2377 prop_atoms.net_wm_state_remove :
2378 prop_atoms.net_wm_state_add;
2379 else if (state == prop_atoms.net_wm_state_above)
2380 action = self->above ? prop_atoms.net_wm_state_remove :
2381 prop_atoms.net_wm_state_add;
2382 else if (state == prop_atoms.net_wm_state_below)
2383 action = self->below ? prop_atoms.net_wm_state_remove :
2384 prop_atoms.net_wm_state_add;
2387 if (action == prop_atoms.net_wm_state_add) {
2388 if (state == prop_atoms.net_wm_state_modal) {
2389 /* XXX raise here or something? */
2391 } else if (state == prop_atoms.net_wm_state_maximized_vert) {
2393 } else if (state == prop_atoms.net_wm_state_maximized_horz) {
2395 } else if (state == prop_atoms.net_wm_state_shaded) {
2397 } else if (state == prop_atoms.net_wm_state_skip_taskbar) {
2398 self->skip_taskbar = TRUE;
2399 } else if (state == prop_atoms.net_wm_state_skip_pager) {
2400 self->skip_pager = TRUE;
2401 } else if (state == prop_atoms.net_wm_state_fullscreen) {
2403 } else if (state == prop_atoms.net_wm_state_above) {
2405 } else if (state == prop_atoms.net_wm_state_below) {
2409 } else { /* action == prop_atoms.net_wm_state_remove */
2410 if (state == prop_atoms.net_wm_state_modal) {
2411 self->modal = FALSE;
2412 } else if (state == prop_atoms.net_wm_state_maximized_vert) {
2414 } else if (state == prop_atoms.net_wm_state_maximized_horz) {
2416 } else if (state == prop_atoms.net_wm_state_shaded) {
2418 } else if (state == prop_atoms.net_wm_state_skip_taskbar) {
2419 self->skip_taskbar = FALSE;
2420 } else if (state == prop_atoms.net_wm_state_skip_pager) {
2421 self->skip_pager = FALSE;
2422 } else if (state == prop_atoms.net_wm_state_fullscreen) {
2424 } else if (state == prop_atoms.net_wm_state_above) {
2425 self->above = FALSE;
2426 } else if (state == prop_atoms.net_wm_state_below) {
2427 self->below = FALSE;
2431 if (max_horz != self->max_horz || max_vert != self->max_vert) {
2432 if (max_horz != self->max_horz && max_vert != self->max_vert) {
2434 if (max_horz == max_vert) { /* both going the same way */
2435 client_maximize(self, max_horz, 0, TRUE);
2437 client_maximize(self, max_horz, 1, TRUE);
2438 client_maximize(self, max_vert, 2, TRUE);
2442 if (max_horz != self->max_horz)
2443 client_maximize(self, max_horz, 1, TRUE);
2445 client_maximize(self, max_vert, 2, TRUE);
2448 /* change fullscreen state before shading, as it will affect if the window
2450 if (fullscreen != self->fullscreen)
2451 client_fullscreen(self, fullscreen, TRUE);
2452 if (shaded != self->shaded)
2453 client_shade(self, shaded);
2454 client_calc_layer(self);
2455 client_change_state(self); /* change the hint to reflect these changes */
2458 ObClient *client_focus_target(ObClient *self)
2462 /* if we have a modal child, then focus it, not us */
2463 child = client_search_modal_child(self);
2464 if (child) return child;
2468 gboolean client_can_focus(ObClient *self)
2472 /* choose the correct target */
2473 self = client_focus_target(self);
2475 if (!self->frame->visible)
2478 if (!((self->can_focus || self->focus_notify) &&
2479 (self->desktop == screen_desktop ||
2480 self->desktop == DESKTOP_ALL) &&
2484 /* do a check to see if the window has already been unmapped or destroyed
2485 do this intelligently while watching out for unmaps we've generated
2486 (ignore_unmaps > 0) */
2487 if (XCheckTypedWindowEvent(ob_display, self->window,
2488 DestroyNotify, &ev)) {
2489 XPutBackEvent(ob_display, &ev);
2492 while (XCheckTypedWindowEvent(ob_display, self->window,
2493 UnmapNotify, &ev)) {
2494 if (self->ignore_unmaps) {
2495 self->ignore_unmaps--;
2497 XPutBackEvent(ob_display, &ev);
2505 gboolean client_focus(ObClient *self)
2507 /* choose the correct target */
2508 self = client_focus_target(self);
2510 if (!client_can_focus(self)) {
2511 if (!self->frame->visible) {
2512 /* update the focus lists */
2513 focus_order_to_top(self);
2518 if (self->can_focus)
2519 /* RevertToPointerRoot causes much more headache than RevertToNone, so
2520 I choose to use it always, hopefully to find errors quicker, if any
2521 are left. (I hate X. I hate focus events.) */
2522 XSetInputFocus(ob_display, self->window, RevertToPointerRoot,
2525 if (self->focus_notify) {
2527 ce.xclient.type = ClientMessage;
2528 ce.xclient.message_type = prop_atoms.wm_protocols;
2529 ce.xclient.display = ob_display;
2530 ce.xclient.window = self->window;
2531 ce.xclient.format = 32;
2532 ce.xclient.data.l[0] = prop_atoms.wm_take_focus;
2533 ce.xclient.data.l[1] = event_lasttime;
2534 ce.xclient.data.l[2] = 0l;
2535 ce.xclient.data.l[3] = 0l;
2536 ce.xclient.data.l[4] = 0l;
2537 XSendEvent(ob_display, self->window, FALSE, NoEventMask, &ce);
2541 ob_debug("%sively focusing %lx at %d\n",
2542 (self->can_focus ? "act" : "pass"),
2543 self->window, (int) event_lasttime);
2546 /* Cause the FocusIn to come back to us. Important for desktop switches,
2547 since otherwise we'll have no FocusIn on the queue and send it off to
2548 the focus_backup. */
2549 XSync(ob_display, FALSE);
2553 void client_unfocus(ObClient *self)
2555 g_assert(focus_client == self);
2557 ob_debug("client_unfocus for %lx\n", self->window);
2559 focus_fallback(OB_FOCUS_FALLBACK_UNFOCUSING);
2562 void client_activate(ObClient *self, gboolean here)
2564 if (client_normal(self) && screen_showing_desktop)
2565 screen_show_desktop(FALSE);
2567 client_iconify(self, FALSE, FALSE);
2568 if (self->desktop != DESKTOP_ALL &&
2569 self->desktop != screen_desktop) {
2571 client_set_desktop(self, screen_desktop, FALSE);
2573 screen_set_desktop(self->desktop);
2574 } else if (!self->frame->visible)
2575 /* if its not visible for other reasons, then don't mess
2579 client_shade(self, FALSE);
2581 stacking_raise(CLIENT_AS_WINDOW(self));
2584 gboolean client_focused(ObClient *self)
2586 return self == focus_client;
2589 ObClientIcon *client_icon(ObClient *self, int w, int h)
2592 /* si is the smallest image >= req */
2593 /* li is the largest image < req */
2594 unsigned long size, smallest = 0xffffffff, largest = 0, si = 0, li = 0;
2596 if (!self->nicons) return NULL;
2598 for (i = 0; i < self->nicons; ++i) {
2599 size = self->icons[i].width * self->icons[i].height;
2600 if (size < smallest && size >= (unsigned)(w * h)) {
2604 if (size > largest && size <= (unsigned)(w * h)) {
2609 if (largest == 0) /* didnt find one smaller than the requested size */
2610 return &self->icons[si];
2611 return &self->icons[li];
2614 /* this be mostly ripped from fvwm */
2615 ObClient *client_find_directional(ObClient *c, ObDirection dir)
2617 int my_cx, my_cy, his_cx, his_cy;
2620 int score, best_score;
2621 ObClient *best_client, *cur;
2627 /* first, find the centre coords of the currently focused window */
2628 my_cx = c->frame->area.x + c->frame->area.width / 2;
2629 my_cy = c->frame->area.y + c->frame->area.height / 2;
2634 for(it = g_list_first(client_list); it; it = it->next) {
2637 /* the currently selected window isn't interesting */
2640 if (!client_normal(cur))
2642 if(c->desktop != cur->desktop && cur->desktop != DESKTOP_ALL)
2646 if(client_focus_target(cur) == cur &&
2647 !(cur->can_focus || cur->focus_notify))
2650 /* find the centre coords of this window, from the
2651 * currently focused window's point of view */
2652 his_cx = (cur->frame->area.x - my_cx)
2653 + cur->frame->area.width / 2;
2654 his_cy = (cur->frame->area.y - my_cy)
2655 + cur->frame->area.height / 2;
2657 if(dir == OB_DIRECTION_NORTHEAST || dir == OB_DIRECTION_SOUTHEAST ||
2658 dir == OB_DIRECTION_SOUTHWEST || dir == OB_DIRECTION_NORTHWEST) {
2660 /* Rotate the diagonals 45 degrees counterclockwise.
2661 * To do this, multiply the matrix /+h +h\ with the
2662 * vector (x y). \-h +h/
2663 * h = sqrt(0.5). We can set h := 1 since absolute
2664 * distance doesn't matter here. */
2665 tx = his_cx + his_cy;
2666 his_cy = -his_cx + his_cy;
2671 case OB_DIRECTION_NORTH:
2672 case OB_DIRECTION_SOUTH:
2673 case OB_DIRECTION_NORTHEAST:
2674 case OB_DIRECTION_SOUTHWEST:
2675 offset = (his_cx < 0) ? -his_cx : his_cx;
2676 distance = ((dir == OB_DIRECTION_NORTH ||
2677 dir == OB_DIRECTION_NORTHEAST) ?
2680 case OB_DIRECTION_EAST:
2681 case OB_DIRECTION_WEST:
2682 case OB_DIRECTION_SOUTHEAST:
2683 case OB_DIRECTION_NORTHWEST:
2684 offset = (his_cy < 0) ? -his_cy : his_cy;
2685 distance = ((dir == OB_DIRECTION_WEST ||
2686 dir == OB_DIRECTION_NORTHWEST) ?
2691 /* the target must be in the requested direction */
2695 /* Calculate score for this window. The smaller the better. */
2696 score = distance + offset;
2698 /* windows more than 45 degrees off the direction are
2699 * heavily penalized and will only be chosen if nothing
2700 * else within a million pixels */
2701 if(offset > distance)
2704 if(best_score == -1 || score < best_score)
2712 void client_set_layer(ObClient *self, int layer)
2716 self->above = FALSE;
2717 } else if (layer == 0) {
2718 self->below = self->above = FALSE;
2720 self->below = FALSE;
2723 client_calc_layer(self);
2724 client_change_state(self); /* reflect this in the state hints */
2727 guint client_monitor(ObClient *self)
2731 for (i = 0; i < screen_num_monitors; ++i) {
2732 Rect *area = screen_physical_area_monitor(i);
2733 if (RECT_INTERSECTS_RECT(*area, self->frame->area))
2736 if (i == screen_num_monitors) i = 0;
2737 g_assert(i < screen_num_monitors);
2741 ObClient *client_search_top_transient(ObClient *self)
2743 /* move up the transient chain as far as possible */
2744 if (self->transient_for) {
2745 if (self->transient_for != OB_TRAN_GROUP) {
2746 return client_search_top_transient(self->transient_for);
2750 for (it = self->group->members; it; it = it->next) {
2751 ObClient *c = it->data;
2753 /* checking transient_for prevents infinate loops! */
2754 if (c != self && !c->transient_for)
2765 ObClient *client_search_transient(ObClient *self, ObClient *search)
2769 for (sit = self->transients; sit; sit = g_slist_next(sit)) {
2770 if (sit->data == search)
2772 if (client_search_transient(sit->data, search))
2778 gchar* client_get_sm_client_id(ObClient *self)
2782 if (!PROP_GETS(self->window, sm_client_id, locale, &id) && self->group)
2783 PROP_GETS(self->group->leader, sm_client_id, locale, &id);
2787 /* finds the nearest edge in the given direction from the current client
2788 * note to self: the edge is the -frame- edge (the actual one), not the
2791 int client_directional_edge_search(ObClient *c, ObDirection dir)
2794 int my_edge_start, my_edge_end, my_offset;
2801 a = screen_area(c->desktop);
2804 case OB_DIRECTION_NORTH:
2805 my_edge_start = c->frame->area.x;
2806 my_edge_end = c->frame->area.x + c->frame->area.width;
2807 my_offset = c->frame->area.y;
2809 dest = a->y; /* default: top of screen */
2811 for(it = g_list_first(client_list); it; it = it->next) {
2812 int his_edge_start, his_edge_end, his_offset;
2813 ObClient *cur = it->data;
2817 if(!client_normal(cur))
2819 if(c->desktop != cur->desktop && cur->desktop != DESKTOP_ALL)
2824 his_edge_start = cur->frame->area.x;
2825 his_edge_end = cur->frame->area.x + cur->frame->area.width;
2826 his_offset = cur->frame->area.y + cur->frame->area.height;
2828 if(his_offset + 1 > my_offset)
2831 if(his_offset < dest)
2834 if(his_edge_start >= my_edge_start &&
2835 his_edge_start <= my_edge_end)
2838 if(my_edge_start >= his_edge_start &&
2839 my_edge_start <= his_edge_end)
2844 case OB_DIRECTION_SOUTH:
2845 my_edge_start = c->frame->area.x;
2846 my_edge_end = c->frame->area.x + c->frame->area.width;
2847 my_offset = c->frame->area.y + c->frame->area.height;
2849 dest = a->y + a->height; /* default: bottom of screen */
2851 for(it = g_list_first(client_list); it; it = it->next) {
2852 int his_edge_start, his_edge_end, his_offset;
2853 ObClient *cur = it->data;
2857 if(!client_normal(cur))
2859 if(c->desktop != cur->desktop && cur->desktop != DESKTOP_ALL)
2864 his_edge_start = cur->frame->area.x;
2865 his_edge_end = cur->frame->area.x + cur->frame->area.width;
2866 his_offset = cur->frame->area.y;
2869 if(his_offset - 1 < my_offset)
2872 if(his_offset > dest)
2875 if(his_edge_start >= my_edge_start &&
2876 his_edge_start <= my_edge_end)
2879 if(my_edge_start >= his_edge_start &&
2880 my_edge_start <= his_edge_end)
2885 case OB_DIRECTION_WEST:
2886 my_edge_start = c->frame->area.y;
2887 my_edge_end = c->frame->area.y + c->frame->area.height;
2888 my_offset = c->frame->area.x;
2890 dest = a->x; /* default: leftmost egde of screen */
2892 for(it = g_list_first(client_list); it; it = it->next) {
2893 int his_edge_start, his_edge_end, his_offset;
2894 ObClient *cur = it->data;
2898 if(!client_normal(cur))
2900 if(c->desktop != cur->desktop && cur->desktop != DESKTOP_ALL)
2905 his_edge_start = cur->frame->area.y;
2906 his_edge_end = cur->frame->area.y + cur->frame->area.height;
2907 his_offset = cur->frame->area.x + cur->frame->area.width;
2909 if(his_offset + 1 > my_offset)
2912 if(his_offset < dest)
2915 if(his_edge_start >= my_edge_start &&
2916 his_edge_start <= my_edge_end)
2919 if(my_edge_start >= his_edge_start &&
2920 my_edge_start <= his_edge_end)
2926 case OB_DIRECTION_EAST:
2927 my_edge_start = c->frame->area.y;
2928 my_edge_end = c->frame->area.y + c->frame->area.height;
2929 my_offset = c->frame->area.x + c->frame->area.width;
2931 dest = a->x + a->width; /* default: rightmost edge of screen */
2933 for(it = g_list_first(client_list); it; it = it->next) {
2934 int his_edge_start, his_edge_end, his_offset;
2935 ObClient *cur = it->data;
2939 if(!client_normal(cur))
2941 if(c->desktop != cur->desktop && cur->desktop != DESKTOP_ALL)
2946 his_edge_start = cur->frame->area.y;
2947 his_edge_end = cur->frame->area.y + cur->frame->area.height;
2948 his_offset = cur->frame->area.x;
2950 if(his_offset - 1 < my_offset)
2953 if(his_offset > dest)
2956 if(his_edge_start >= my_edge_start &&
2957 his_edge_start <= my_edge_end)
2960 if(my_edge_start >= his_edge_start &&
2961 my_edge_start <= his_edge_end)
2966 case OB_DIRECTION_NORTHEAST:
2967 case OB_DIRECTION_SOUTHEAST:
2968 case OB_DIRECTION_NORTHWEST:
2969 case OB_DIRECTION_SOUTHWEST:
2970 /* not implemented */
2973 g_assert_not_reached();