7 #include "moveresize.h"
9 #include "extensions.h"
21 #include "render/render.h"
24 #include <X11/Xutil.h>
26 /*! The event mask to grab on client windows */
27 #define CLIENT_EVENTMASK (PropertyChangeMask | FocusChangeMask | \
30 #define CLIENT_NOPROPAGATEMASK (ButtonPressMask | ButtonReleaseMask | \
33 GList *client_list = NULL;
35 static void client_get_all(ObClient *self);
36 static void client_toggle_border(ObClient *self, gboolean show);
37 static void client_get_area(ObClient *self);
38 static void client_get_desktop(ObClient *self);
39 static void client_get_state(ObClient *self);
40 static void client_get_shaped(ObClient *self);
41 static void client_get_mwm_hints(ObClient *self);
42 static void client_get_gravity(ObClient *self);
43 static void client_showhide(ObClient *self);
44 static void client_change_allowed_actions(ObClient *self);
45 static void client_change_state(ObClient *self);
46 static void client_apply_startup_state(ObClient *self);
47 static void client_restore_session_state(ObClient *self);
54 void client_shutdown()
58 void client_set_list()
60 Window *windows, *win_it;
62 guint size = g_list_length(client_list);
64 /* create an array of the window ids */
66 windows = g_new(Window, size);
68 for (it = client_list; it != NULL; it = it->next, ++win_it)
69 *win_it = ((ObClient*)it->data)->window;
73 PROP_SETA32(RootWindow(ob_display, ob_screen),
74 net_client_list, window, (guint32*)windows, size);
83 void client_foreach_transient(ObClient *self, ObClientForeachFunc func, void *data)
87 for (it = self->transients; it; it = it->next) {
88 if (!func(it->data, data)) return;
89 client_foreach_transient(it->data, func, data);
93 void client_foreach_ancestor(ObClient *self, ObClientForeachFunc func, void *data)
95 if (self->transient_for) {
96 if (self->transient_for != OB_TRAN_GROUP) {
97 if (!func(self->transient_for, data)) return;
98 client_foreach_ancestor(self->transient_for, func, data);
102 for (it = self->group->members; it; it = it->next)
103 if (it->data != self &&
104 !((ObClient*)it->data)->transient_for) {
105 if (!func(it->data, data)) return;
106 client_foreach_ancestor(it->data, func, data);
113 void client_manage_all()
115 unsigned int i, j, nchild;
118 XWindowAttributes attrib;
120 XQueryTree(ob_display, RootWindow(ob_display, ob_screen),
121 &w, &w, &children, &nchild);
123 /* remove all icon windows from the list */
124 for (i = 0; i < nchild; i++) {
125 if (children[i] == None) continue;
126 wmhints = XGetWMHints(ob_display, children[i]);
128 if ((wmhints->flags & IconWindowHint) &&
129 (wmhints->icon_window != children[i]))
130 for (j = 0; j < nchild; j++)
131 if (children[j] == wmhints->icon_window) {
139 for (i = 0; i < nchild; ++i) {
140 if (children[i] == None)
142 if (XGetWindowAttributes(ob_display, children[i], &attrib)) {
143 if (attrib.override_redirect) continue;
145 if (attrib.map_state != IsUnmapped)
146 client_manage(children[i]);
151 /* stack them as they were on startup!
152 why with stacking_lower? Why, because then windows who aren't in the
153 stacking list are on the top where you can see them instead of buried
155 for (i = startup_stack_size; i > 0; --i) {
158 w = startup_stack_order[i-1];
159 obw = g_hash_table_lookup(window_map, &w);
161 g_assert(WINDOW_IS_CLIENT(obw));
162 stacking_lower(CLIENT_AS_WINDOW(obw));
165 g_free(startup_stack_order);
166 startup_stack_order = NULL;
167 startup_stack_size = 0;
169 if (config_focus_new) {
172 active = g_hash_table_lookup(window_map, &startup_active);
174 g_assert(WINDOW_IS_CLIENT(active));
175 if (!client_focus(WINDOW_AS_CLIENT(active)))
176 focus_fallback(OB_FOCUS_FALLBACK_NOFOCUS);
178 focus_fallback(OB_FOCUS_FALLBACK_NOFOCUS);
182 void client_manage(Window window)
186 XWindowAttributes attrib;
187 XSetWindowAttributes attrib_set;
189 gboolean activate = FALSE;
193 /* check if it has already been unmapped by the time we started mapping
194 the grab does a sync so we don't have to here */
195 if (XCheckTypedWindowEvent(ob_display, window, DestroyNotify, &e) ||
196 XCheckTypedWindowEvent(ob_display, window, UnmapNotify, &e)) {
197 XPutBackEvent(ob_display, &e);
200 return; /* don't manage it */
203 /* make sure it isn't an override-redirect window */
204 if (!XGetWindowAttributes(ob_display, window, &attrib) ||
205 attrib.override_redirect) {
207 return; /* don't manage it */
210 /* is the window a docking app */
211 if ((wmhint = XGetWMHints(ob_display, window))) {
212 if ((wmhint->flags & StateHint) &&
213 wmhint->initial_state == WithdrawnState) {
214 dock_add(window, wmhint);
222 ob_debug("Managing window: %lx\n", window);
224 /* choose the events we want to receive on the CLIENT window */
225 attrib_set.event_mask = CLIENT_EVENTMASK;
226 attrib_set.do_not_propagate_mask = CLIENT_NOPROPAGATEMASK;
227 XChangeWindowAttributes(ob_display, window,
228 CWEventMask|CWDontPropagate, &attrib_set);
231 /* create the ObClient struct, and populate it from the hints on the
233 self = g_new(ObClient, 1);
234 self->obwin.type = Window_Client;
235 self->window = window;
237 client_get_all(self);
238 client_restore_session_state(self);
240 client_change_state(self);
242 /* remove the client's border (and adjust re gravity) */
243 client_toggle_border(self, FALSE);
245 /* specify that if we exit, the window should not be destroyed and should
246 be reparented back to root automatically */
247 XChangeSaveSet(ob_display, window, SetModeInsert);
249 /* create the decoration frame for the client window */
250 self->frame = frame_new();
252 frame_grab_client(self->frame, self);
254 client_apply_startup_state(self);
258 /* update the focus lists */
259 focus_order_add_new(self);
261 stacking_add(CLIENT_AS_WINDOW(self));
263 /* focus the new window? */
264 if (ob_state() != OB_STATE_STARTING && config_focus_new &&
265 /* note the check against Type_Normal/Dialog, not client_normal(self),
266 which would also include other types. in this case we want more
267 strict rules for focus */
268 (self->type == OB_CLIENT_TYPE_NORMAL ||
269 self->type == OB_CLIENT_TYPE_DIALOG))
271 if (self->desktop != screen_desktop) {
272 /* activate the window */
275 gboolean group_foc = FALSE;
280 for (it = self->group->members; it; it = it->next)
282 if (client_focused(it->data))
290 (!self->transient_for && (!self->group ||
291 !self->group->members->next))) ||
292 client_search_focus_tree_full(self) ||
294 !client_normal(focus_client))
296 /* activate the window */
302 dispatch_client(Event_Client_New, self, 0, 0);
304 /* make sure the window is visible */
305 client_move_onscreen(self, TRUE);
307 screen_update_areas();
309 client_showhide(self);
311 /* use client_focus instead of client_activate cuz client_activate does
312 stuff like switch desktops etc and I'm not interested in all that when
313 a window maps since its not based on an action from the user like
314 clicking a window to activate is. so keep the new window out of the way
316 if (activate) client_focus(self);
318 /* client_activate does this but we aret using it so we have to do it
320 if (screen_showing_desktop)
321 screen_show_desktop(FALSE);
323 /* add to client list/map */
324 client_list = g_list_append(client_list, self);
325 g_hash_table_insert(window_map, &self->window, self);
327 /* update the list hints */
330 dispatch_client(Event_Client_Mapped, self, 0, 0);
332 ob_debug("Managed window 0x%lx (%s)\n", window, self->class);
335 void client_unmanage_all()
337 while (client_list != NULL)
338 client_unmanage(client_list->data);
341 /* called by client_unmanage() to close any menus referencing this client */
342 void client_close_menus(gpointer key, gpointer value, gpointer self)
344 if (((ObMenu *)value)->client == (ObClient *)self)
345 menu_hide((ObMenu *)value);
348 void client_unmanage(ObClient *self)
353 ob_debug("Unmanaging window: %lx (%s)\n", self->window, self->class);
355 dispatch_client(Event_Client_Destroy, self, 0, 0);
356 g_assert(self != NULL);
358 /* remove the window from our save set */
359 XChangeSaveSet(ob_display, self->window, SetModeDelete);
361 /* we dont want events no more */
362 XSelectInput(ob_display, self->window, NoEventMask);
364 frame_hide(self->frame);
366 client_list = g_list_remove(client_list, self);
367 stacking_remove(self);
368 g_hash_table_remove(window_map, &self->window);
370 /* update the focus lists */
371 focus_order_remove(self);
373 /* once the client is out of the list, update the struts to remove it's
375 screen_update_areas();
377 /* tell our parent(s) that we're gone */
378 if (self->transient_for == OB_TRAN_GROUP) { /* transient of group */
381 for (it = self->group->members; it; it = it->next)
382 if (it->data != self)
383 ((ObClient*)it->data)->transients =
384 g_slist_remove(((ObClient*)it->data)->transients, self);
385 } else if (self->transient_for) { /* transient of window */
386 self->transient_for->transients =
387 g_slist_remove(self->transient_for->transients, self);
390 /* tell our transients that we're gone */
391 for (it = self->transients; it != NULL; it = it->next) {
392 if (((ObClient*)it->data)->transient_for != OB_TRAN_GROUP) {
393 ((ObClient*)it->data)->transient_for = NULL;
394 client_calc_layer(it->data);
398 if (moveresize_client == self)
399 moveresize_end(TRUE);
401 /* close any windows that are attached to this window */
402 g_hash_table_foreach(menu_hash, client_close_menus, self);
405 if (focus_client == self) {
408 /* focus the last focused window on the desktop, and ignore enter
409 events from the unmap so it doesnt mess with the focus */
410 while (XCheckTypedEvent(ob_display, EnterNotify, &e));
411 client_unfocus(self);
414 /* remove from its group */
416 group_remove(self->group, self);
420 /* dispatch the unmapped event */
421 dispatch_client(Event_Client_Unmapped, self, 0, 0);
422 g_assert(self != NULL);
424 /* give the client its border back */
425 client_toggle_border(self, TRUE);
427 /* reparent the window out of the frame, and free the frame */
428 frame_release_client(self->frame, self);
431 if (ob_state() != OB_STATE_EXITING) {
432 /* these values should not be persisted across a window
434 PROP_ERASE(self->window, net_wm_desktop);
435 PROP_ERASE(self->window, net_wm_state);
436 PROP_ERASE(self->window, wm_state);
438 /* if we're left in an iconic state, the client wont be mapped. this is
439 bad, since we will no longer be managing the window on restart */
441 XMapWindow(ob_display, self->window);
445 ob_debug("Unmanaged window 0x%lx\n", self->window);
447 /* free all data allocated in the client struct */
448 g_slist_free(self->transients);
449 for (j = 0; j < self->nicons; ++j)
450 g_free(self->icons[j].data);
451 if (self->nicons > 0)
454 g_free(self->icon_title);
460 /* update the list hints */
464 static void client_restore_session_state(ObClient *self)
468 s = session_state_find(self);
471 RECT_SET(self->area, s->x, s->y, s->w, s->h);
472 self->positioned = TRUE;
473 XResizeWindow(ob_display, self->window, s->w, s->h);
475 self->desktop = s->desktop == DESKTOP_ALL ? s->desktop :
476 MIN(screen_num_desktops - 1, s->desktop);
477 PROP_SET32(self->window, net_wm_desktop, cardinal, self->desktop);
479 self->shaded = s->shaded;
480 self->iconic = s->iconic;
481 self->skip_pager = s->skip_pager;
482 self->skip_taskbar = s->skip_taskbar;
483 self->fullscreen = s->fullscreen;
484 self->above = s->above;
485 self->below = s->below;
486 self->max_horz = s->max_horz;
487 self->max_vert = s->max_vert;
489 session_state_free(s);
492 void client_move_onscreen(ObClient *self, gboolean rude)
494 int x = self->area.x;
495 int y = self->area.y;
496 if (client_find_onscreen(self, &x, &y,
497 self->area.width, self->area.height, rude)) {
498 client_configure(self, OB_CORNER_TOPLEFT, x, y,
499 self->area.width, self->area.height,
504 gboolean client_find_onscreen(ObClient *self, int *x, int *y, int w, int h,
508 int ox = *x, oy = *y;
510 frame_client_gravity(self->frame, x, y); /* get where the frame
513 /* XXX watch for xinerama dead areas */
515 a = screen_area(self->desktop);
516 if (!self->strut.right && *x >= a->x + a->width - 1)
517 *x = a->x + a->width - self->frame->area.width;
518 if (!self->strut.bottom && *y >= a->y + a->height - 1)
519 *y = a->y + a->height - self->frame->area.height;
520 if (!self->strut.left && *x + self->frame->area.width - 1 < a->x)
522 if (!self->strut.top && *y + self->frame->area.height - 1 < a->y)
526 /* this is my MOZILLA BITCHSLAP. oh ya it fucking feels good.
527 Java can suck it too. */
529 /* dont let windows map/move into the strut unless they
530 are bigger than the available area */
532 if (!self->strut.left && *x < a->x) *x = a->x;
533 if (!self->strut.right && *x + w > a->x + a->width)
534 *x = a->x + a->width - w;
536 if (h <= a->height) {
537 if (!self->strut.top && *y < a->y) *y = a->y;
538 if (!self->strut.bottom && *y + h > a->y + a->height)
539 *y = a->y + a->height - h;
543 frame_frame_gravity(self->frame, x, y); /* get where the client
546 return ox != *x || oy != *y;
549 static void client_toggle_border(ObClient *self, gboolean show)
551 /* adjust our idea of where the client is, based on its border. When the
552 border is removed, the client should now be considered to be in a
554 when re-adding the border to the client, the same operation needs to be
556 int oldx = self->area.x, oldy = self->area.y;
557 int x = oldx, y = oldy;
558 switch(self->gravity) {
560 case NorthWestGravity:
562 case SouthWestGravity:
564 case NorthEastGravity:
566 case SouthEastGravity:
567 if (show) x -= self->border_width * 2;
568 else x += self->border_width * 2;
575 if (show) x -= self->border_width;
576 else x += self->border_width;
579 switch(self->gravity) {
581 case NorthWestGravity:
583 case NorthEastGravity:
585 case SouthWestGravity:
587 case SouthEastGravity:
588 if (show) y -= self->border_width * 2;
589 else y += self->border_width * 2;
596 if (show) y -= self->border_width;
597 else y += self->border_width;
604 XSetWindowBorderWidth(ob_display, self->window, self->border_width);
606 /* move the client so it is back it the right spot _with_ its
608 if (x != oldx || y != oldy)
609 XMoveWindow(ob_display, self->window, x, y);
611 XSetWindowBorderWidth(ob_display, self->window, 0);
615 static void client_get_all(ObClient *self)
617 /* update EVERYTHING!! */
619 self->ignore_unmaps = 0;
623 self->title = self->icon_title = NULL;
624 self->title_count = 1;
625 self->name = self->class = self->role = NULL;
626 self->wmstate = NormalState;
627 self->transient = FALSE;
628 self->transients = NULL;
629 self->transient_for = NULL;
631 self->urgent = FALSE;
632 self->positioned = FALSE;
633 self->decorate = TRUE;
637 client_get_area(self);
638 client_update_transient_for(self);
639 client_update_wmhints(self);
640 client_get_desktop(self);
641 client_get_state(self);
642 client_get_shaped(self);
644 client_get_mwm_hints(self);
645 client_get_type(self);/* this can change the mwmhints for special cases */
647 client_update_protocols(self);
649 client_get_gravity(self); /* get the attribute gravity */
650 client_update_normal_hints(self); /* this may override the attribute
653 /* got the type, the mwmhints, the protocols, and the normal hints
654 (min/max sizes), so we're ready to set up the decorations/functions */
655 client_setup_decor_and_functions(self);
657 client_update_title(self);
658 client_update_class(self);
659 client_update_strut(self);
660 client_update_icons(self);
663 static void client_get_area(ObClient *self)
665 XWindowAttributes wattrib;
668 ret = XGetWindowAttributes(ob_display, self->window, &wattrib);
669 g_assert(ret != BadWindow);
671 RECT_SET(self->area, wattrib.x, wattrib.y, wattrib.width, wattrib.height);
672 self->border_width = wattrib.border_width;
675 static void client_get_desktop(ObClient *self)
677 guint32 d = screen_num_desktops; /* an always-invalid value */
679 if (PROP_GET32(self->window, net_wm_desktop, cardinal, &d)) {
680 if (d >= screen_num_desktops && d != DESKTOP_ALL)
681 self->desktop = screen_num_desktops - 1;
685 gboolean trdesk = FALSE;
687 if (self->transient_for) {
688 if (self->transient_for != OB_TRAN_GROUP) {
689 self->desktop = self->transient_for->desktop;
694 for (it = self->group->members; it; it = it->next)
695 if (it->data != self &&
696 !((ObClient*)it->data)->transient_for) {
697 self->desktop = ((ObClient*)it->data)->desktop;
704 /* defaults to the current desktop */
705 self->desktop = screen_desktop;
707 if (self->desktop != d) {
708 /* set the desktop hint, to make sure that it always exists */
709 PROP_SET32(self->window, net_wm_desktop, cardinal, self->desktop);
713 static void client_get_state(ObClient *self)
718 self->modal = self->shaded = self->max_horz = self->max_vert =
719 self->fullscreen = self->above = self->below = self->iconic =
720 self->skip_taskbar = self->skip_pager = FALSE;
722 if (PROP_GETA32(self->window, net_wm_state, atom, &state, &num)) {
724 for (i = 0; i < num; ++i) {
725 if (state[i] == prop_atoms.net_wm_state_modal)
727 else if (state[i] == prop_atoms.net_wm_state_shaded)
729 else if (state[i] == prop_atoms.net_wm_state_hidden)
731 else if (state[i] == prop_atoms.net_wm_state_skip_taskbar)
732 self->skip_taskbar = TRUE;
733 else if (state[i] == prop_atoms.net_wm_state_skip_pager)
734 self->skip_pager = TRUE;
735 else if (state[i] == prop_atoms.net_wm_state_fullscreen)
736 self->fullscreen = TRUE;
737 else if (state[i] == prop_atoms.net_wm_state_maximized_vert)
738 self->max_vert = TRUE;
739 else if (state[i] == prop_atoms.net_wm_state_maximized_horz)
740 self->max_horz = TRUE;
741 else if (state[i] == prop_atoms.net_wm_state_above)
743 else if (state[i] == prop_atoms.net_wm_state_below)
751 static void client_get_shaped(ObClient *self)
753 self->shaped = FALSE;
755 if (extensions_shape) {
760 XShapeSelectInput(ob_display, self->window, ShapeNotifyMask);
762 XShapeQueryExtents(ob_display, self->window, &s, &foo,
763 &foo, &ufoo, &ufoo, &foo, &foo, &foo, &ufoo,
765 self->shaped = (s != 0);
770 void client_update_transient_for(ObClient *self)
773 ObClient *target = NULL;
775 if (XGetTransientForHint(ob_display, self->window, &t)) {
776 self->transient = TRUE;
777 if (t != self->window) { /* cant be transient to itself! */
778 target = g_hash_table_lookup(window_map, &t);
779 /* if this happens then we need to check for it*/
780 g_assert(target != self);
781 g_assert(!target || WINDOW_IS_CLIENT(target));
783 if (!target && self->group) {
784 /* not transient to a client, see if it is transient for a
786 if (t == self->group->leader ||
788 t == RootWindow(ob_display, ob_screen)) {
789 /* window is a transient for its group! */
790 target = OB_TRAN_GROUP;
795 self->transient = FALSE;
797 /* if anything has changed... */
798 if (target != self->transient_for) {
799 if (self->transient_for == OB_TRAN_GROUP) { /* transient of group */
802 /* remove from old parents */
803 for (it = self->group->members; it; it = g_slist_next(it)) {
804 ObClient *c = it->data;
805 if (c != self && !c->transient_for)
806 c->transients = g_slist_remove(c->transients, self);
808 } else if (self->transient_for != NULL) { /* transient of window */
809 /* remove from old parent */
810 self->transient_for->transients =
811 g_slist_remove(self->transient_for->transients, self);
813 self->transient_for = target;
814 if (self->transient_for == OB_TRAN_GROUP) { /* transient of group */
817 /* add to new parents */
818 for (it = self->group->members; it; it = g_slist_next(it)) {
819 ObClient *c = it->data;
820 if (c != self && !c->transient_for)
821 c->transients = g_slist_append(c->transients, self);
824 /* remove all transients which are in the group, that causes
825 circlular pointer hell of doom */
826 for (it = self->group->members; it; it = g_slist_next(it)) {
828 for (sit = self->transients; sit; sit = next) {
829 next = g_slist_next(sit);
830 if (sit->data == it->data)
832 g_slist_delete_link(self->transients, sit);
835 } else if (self->transient_for != NULL) { /* transient of window */
836 /* add to new parent */
837 self->transient_for->transients =
838 g_slist_append(self->transient_for->transients, self);
843 static void client_get_mwm_hints(ObClient *self)
848 self->mwmhints.flags = 0; /* default to none */
850 if (PROP_GETA32(self->window, motif_wm_hints, motif_wm_hints,
852 if (num >= OB_MWM_ELEMENTS) {
853 self->mwmhints.flags = hints[0];
854 self->mwmhints.functions = hints[1];
855 self->mwmhints.decorations = hints[2];
861 void client_get_type(ObClient *self)
868 if (PROP_GETA32(self->window, net_wm_window_type, atom, &val, &num)) {
869 /* use the first value that we know about in the array */
870 for (i = 0; i < num; ++i) {
871 if (val[i] == prop_atoms.net_wm_window_type_desktop)
872 self->type = OB_CLIENT_TYPE_DESKTOP;
873 else if (val[i] == prop_atoms.net_wm_window_type_dock)
874 self->type = OB_CLIENT_TYPE_DOCK;
875 else if (val[i] == prop_atoms.net_wm_window_type_toolbar)
876 self->type = OB_CLIENT_TYPE_TOOLBAR;
877 else if (val[i] == prop_atoms.net_wm_window_type_menu)
878 self->type = OB_CLIENT_TYPE_MENU;
879 else if (val[i] == prop_atoms.net_wm_window_type_utility)
880 self->type = OB_CLIENT_TYPE_UTILITY;
881 else if (val[i] == prop_atoms.net_wm_window_type_splash)
882 self->type = OB_CLIENT_TYPE_SPLASH;
883 else if (val[i] == prop_atoms.net_wm_window_type_dialog)
884 self->type = OB_CLIENT_TYPE_DIALOG;
885 else if (val[i] == prop_atoms.net_wm_window_type_normal)
886 self->type = OB_CLIENT_TYPE_NORMAL;
887 else if (val[i] == prop_atoms.kde_net_wm_window_type_override) {
888 /* prevent this window from getting any decor or
890 self->mwmhints.flags &= (OB_MWM_FLAG_FUNCTIONS |
891 OB_MWM_FLAG_DECORATIONS);
892 self->mwmhints.decorations = 0;
893 self->mwmhints.functions = 0;
895 if (self->type != (ObClientType) -1)
896 break; /* grab the first legit type */
901 if (self->type == (ObClientType) -1) {
902 /*the window type hint was not set, which means we either classify
903 ourself as a normal window or a dialog, depending on if we are a
906 self->type = OB_CLIENT_TYPE_DIALOG;
908 self->type = OB_CLIENT_TYPE_NORMAL;
912 void client_update_protocols(ObClient *self)
917 self->focus_notify = FALSE;
918 self->delete_window = FALSE;
920 if (PROP_GETA32(self->window, wm_protocols, atom, &proto, &num_return)) {
921 for (i = 0; i < num_return; ++i) {
922 if (proto[i] == prop_atoms.wm_delete_window) {
923 /* this means we can request the window to close */
924 self->delete_window = TRUE;
925 } else if (proto[i] == prop_atoms.wm_take_focus)
926 /* if this protocol is requested, then the window will be
927 notified whenever we want it to receive focus */
928 self->focus_notify = TRUE;
934 static void client_get_gravity(ObClient *self)
936 XWindowAttributes wattrib;
939 ret = XGetWindowAttributes(ob_display, self->window, &wattrib);
940 g_assert(ret != BadWindow);
941 self->gravity = wattrib.win_gravity;
944 void client_update_normal_hints(ObClient *self)
948 int oldgravity = self->gravity;
951 self->min_ratio = 0.0f;
952 self->max_ratio = 0.0f;
953 SIZE_SET(self->size_inc, 1, 1);
954 SIZE_SET(self->base_size, 0, 0);
955 SIZE_SET(self->min_size, 0, 0);
956 SIZE_SET(self->max_size, G_MAXINT, G_MAXINT);
958 /* get the hints from the window */
959 if (XGetWMNormalHints(ob_display, self->window, &size, &ret)) {
960 /* don't let apps tell me where to put transient windows, but only if
961 they have a valid parent */
962 self->positioned = !!(size.flags & (PPosition|USPosition)) &&
963 !self->transient_for;
965 if (size.flags & PWinGravity) {
966 self->gravity = size.win_gravity;
968 /* if the client has a frame, i.e. has already been mapped and
969 is changing its gravity */
970 if (self->frame && self->gravity != oldgravity) {
971 /* move our idea of the client's position based on its new
973 self->area.x = self->frame->area.x;
974 self->area.y = self->frame->area.y;
975 frame_frame_gravity(self->frame, &self->area.x, &self->area.y);
979 if (size.flags & PAspect) {
980 if (size.min_aspect.y)
981 self->min_ratio = (float)size.min_aspect.x / size.min_aspect.y;
982 if (size.max_aspect.y)
983 self->max_ratio = (float)size.max_aspect.x / size.max_aspect.y;
986 if (size.flags & PMinSize)
987 SIZE_SET(self->min_size, size.min_width, size.min_height);
989 if (size.flags & PMaxSize)
990 SIZE_SET(self->max_size, size.max_width, size.max_height);
992 if (size.flags & PBaseSize)
993 SIZE_SET(self->base_size, size.base_width, size.base_height);
995 if (size.flags & PResizeInc)
996 SIZE_SET(self->size_inc, size.width_inc, size.height_inc);
1000 void client_setup_decor_and_functions(ObClient *self)
1002 /* start with everything (cept fullscreen) */
1003 self->decorations = (OB_FRAME_DECOR_TITLEBAR |
1004 OB_FRAME_DECOR_HANDLE |
1005 OB_FRAME_DECOR_GRIPS |
1006 OB_FRAME_DECOR_BORDER |
1007 OB_FRAME_DECOR_ICON |
1008 OB_FRAME_DECOR_ALLDESKTOPS |
1009 OB_FRAME_DECOR_ICONIFY |
1010 OB_FRAME_DECOR_MAXIMIZE |
1011 OB_FRAME_DECOR_SHADE);
1012 self->functions = (OB_CLIENT_FUNC_RESIZE |
1013 OB_CLIENT_FUNC_MOVE |
1014 OB_CLIENT_FUNC_ICONIFY |
1015 OB_CLIENT_FUNC_MAXIMIZE |
1016 OB_CLIENT_FUNC_SHADE);
1017 if (self->delete_window) {
1018 self->functions |= OB_CLIENT_FUNC_CLOSE;
1019 self->decorations |= OB_FRAME_DECOR_CLOSE;
1022 if (!(self->min_size.width < self->max_size.width ||
1023 self->min_size.height < self->max_size.height))
1024 self->functions &= ~OB_CLIENT_FUNC_RESIZE;
1026 switch (self->type) {
1027 case OB_CLIENT_TYPE_NORMAL:
1028 /* normal windows retain all of the possible decorations and
1029 functionality, and are the only windows that you can fullscreen */
1030 self->functions |= OB_CLIENT_FUNC_FULLSCREEN;
1033 case OB_CLIENT_TYPE_DIALOG:
1034 case OB_CLIENT_TYPE_UTILITY:
1035 /* these windows cannot be maximized */
1036 self->functions &= ~OB_CLIENT_FUNC_MAXIMIZE;
1039 case OB_CLIENT_TYPE_MENU:
1040 case OB_CLIENT_TYPE_TOOLBAR:
1041 /* these windows get less functionality */
1042 self->functions &= ~(OB_CLIENT_FUNC_ICONIFY | OB_CLIENT_FUNC_RESIZE);
1045 case OB_CLIENT_TYPE_DESKTOP:
1046 case OB_CLIENT_TYPE_DOCK:
1047 case OB_CLIENT_TYPE_SPLASH:
1048 /* none of these windows are manipulated by the window manager */
1049 self->decorations = 0;
1050 self->functions = 0;
1054 /* Mwm Hints are applied subtractively to what has already been chosen for
1055 decor and functionality */
1056 if (self->mwmhints.flags & OB_MWM_FLAG_DECORATIONS) {
1057 if (! (self->mwmhints.decorations & OB_MWM_DECOR_ALL)) {
1058 if (! ((self->mwmhints.decorations & OB_MWM_DECOR_HANDLE) ||
1059 (self->mwmhints.decorations & OB_MWM_DECOR_TITLE)))
1060 /* if the mwm hints request no handle or title, then all
1061 decorations are disabled */
1062 self->decorations = 0;
1066 if (self->mwmhints.flags & OB_MWM_FLAG_FUNCTIONS) {
1067 if (! (self->mwmhints.functions & OB_MWM_FUNC_ALL)) {
1068 if (! (self->mwmhints.functions & OB_MWM_FUNC_RESIZE))
1069 self->functions &= ~OB_CLIENT_FUNC_RESIZE;
1070 if (! (self->mwmhints.functions & OB_MWM_FUNC_MOVE))
1071 self->functions &= ~OB_CLIENT_FUNC_MOVE;
1072 /* dont let mwm hints kill any buttons
1073 if (! (self->mwmhints.functions & OB_MWM_FUNC_ICONIFY))
1074 self->functions &= ~OB_CLIENT_FUNC_ICONIFY;
1075 if (! (self->mwmhints.functions & OB_MWM_FUNC_MAXIMIZE))
1076 self->functions &= ~OB_CLIENT_FUNC_MAXIMIZE;
1078 /* dont let mwm hints kill the close button
1079 if (! (self->mwmhints.functions & MwmFunc_Close))
1080 self->functions &= ~OB_CLIENT_FUNC_CLOSE; */
1084 if (!(self->functions & OB_CLIENT_FUNC_SHADE))
1085 self->decorations &= ~OB_FRAME_DECOR_SHADE;
1086 if (!(self->functions & OB_CLIENT_FUNC_ICONIFY))
1087 self->decorations &= ~OB_FRAME_DECOR_ICONIFY;
1088 if (!(self->functions & OB_CLIENT_FUNC_RESIZE))
1089 self->decorations &= ~OB_FRAME_DECOR_GRIPS;
1091 /* can't maximize without moving/resizing */
1092 if (!((self->functions & OB_CLIENT_FUNC_MAXIMIZE) &&
1093 (self->functions & OB_CLIENT_FUNC_MOVE) &&
1094 (self->functions & OB_CLIENT_FUNC_RESIZE))) {
1095 self->functions &= ~OB_CLIENT_FUNC_MAXIMIZE;
1096 self->decorations &= ~OB_FRAME_DECOR_MAXIMIZE;
1099 /* finally, the user can have requested no decorations, which overrides
1101 if (!self->decorate)
1102 self->decorations = 0;
1104 /* if we don't have a titlebar, then we cannot shade! */
1105 if (!(self->decorations & OB_FRAME_DECOR_TITLEBAR))
1106 self->functions &= ~OB_CLIENT_FUNC_SHADE;
1108 /* now we need to check against rules for the client's current state */
1109 if (self->fullscreen) {
1110 self->functions &= (OB_CLIENT_FUNC_CLOSE |
1111 OB_CLIENT_FUNC_FULLSCREEN |
1112 OB_CLIENT_FUNC_ICONIFY);
1113 self->decorations = 0;
1116 client_change_allowed_actions(self);
1119 /* this makes sure that these windows appear on all desktops */
1120 if (self->type == OB_CLIENT_TYPE_DESKTOP &&
1121 self->desktop != DESKTOP_ALL)
1122 client_set_desktop(self, DESKTOP_ALL, FALSE);
1124 /* adjust the client's decorations, etc. */
1125 client_reconfigure(self);
1127 /* this makes sure that these windows appear on all desktops */
1128 if (self->type == OB_CLIENT_TYPE_DESKTOP &&
1129 self->desktop != DESKTOP_ALL)
1131 self->desktop = DESKTOP_ALL;
1136 static void client_change_allowed_actions(ObClient *self)
1141 /* desktop windows are kept on all desktops */
1142 if (self->type != OB_CLIENT_TYPE_DESKTOP)
1143 actions[num++] = prop_atoms.net_wm_action_change_desktop;
1145 if (self->functions & OB_CLIENT_FUNC_SHADE)
1146 actions[num++] = prop_atoms.net_wm_action_shade;
1147 if (self->functions & OB_CLIENT_FUNC_CLOSE)
1148 actions[num++] = prop_atoms.net_wm_action_close;
1149 if (self->functions & OB_CLIENT_FUNC_MOVE)
1150 actions[num++] = prop_atoms.net_wm_action_move;
1151 if (self->functions & OB_CLIENT_FUNC_ICONIFY)
1152 actions[num++] = prop_atoms.net_wm_action_minimize;
1153 if (self->functions & OB_CLIENT_FUNC_RESIZE)
1154 actions[num++] = prop_atoms.net_wm_action_resize;
1155 if (self->functions & OB_CLIENT_FUNC_FULLSCREEN)
1156 actions[num++] = prop_atoms.net_wm_action_fullscreen;
1157 if (self->functions & OB_CLIENT_FUNC_MAXIMIZE) {
1158 actions[num++] = prop_atoms.net_wm_action_maximize_horz;
1159 actions[num++] = prop_atoms.net_wm_action_maximize_vert;
1162 PROP_SETA32(self->window, net_wm_allowed_actions, atom, actions, num);
1164 /* make sure the window isn't breaking any rules now */
1166 if (!(self->functions & OB_CLIENT_FUNC_SHADE) && self->shaded) {
1167 if (self->frame) client_shade(self, FALSE);
1168 else self->shaded = FALSE;
1170 if (!(self->functions & OB_CLIENT_FUNC_ICONIFY) && self->iconic) {
1171 if (self->frame) client_iconify(self, FALSE, TRUE);
1172 else self->iconic = FALSE;
1174 if (!(self->functions & OB_CLIENT_FUNC_FULLSCREEN) && self->fullscreen) {
1175 if (self->frame) client_fullscreen(self, FALSE, TRUE);
1176 else self->fullscreen = FALSE;
1178 if (!(self->functions & OB_CLIENT_FUNC_MAXIMIZE) && (self->max_horz ||
1180 if (self->frame) client_maximize(self, FALSE, 0, TRUE);
1181 else self->max_vert = self->max_horz = FALSE;
1185 void client_reconfigure(ObClient *self)
1187 /* by making this pass FALSE for user, we avoid the emacs event storm where
1188 every configurenotify causes an update in its normal hints, i think this
1189 is generally what we want anyways... */
1190 client_configure(self, OB_CORNER_TOPLEFT, self->area.x, self->area.y,
1191 self->area.width, self->area.height, FALSE, TRUE);
1194 void client_update_wmhints(ObClient *self)
1197 gboolean ur = FALSE;
1200 /* assume a window takes input if it doesnt specify */
1201 self->can_focus = TRUE;
1203 if ((hints = XGetWMHints(ob_display, self->window)) != NULL) {
1204 if (hints->flags & InputHint)
1205 self->can_focus = hints->input;
1207 /* only do this when first managing the window *AND* when we aren't
1209 if (ob_state() != OB_STATE_STARTING && self->frame == NULL)
1210 if (hints->flags & StateHint)
1211 self->iconic = hints->initial_state == IconicState;
1213 if (hints->flags & XUrgencyHint)
1216 if (!(hints->flags & WindowGroupHint))
1217 hints->window_group = None;
1219 /* did the group state change? */
1220 if (hints->window_group !=
1221 (self->group ? self->group->leader : None)) {
1222 /* remove from the old group if there was one */
1223 if (self->group != NULL) {
1224 /* remove transients of the group */
1225 for (it = self->group->members; it; it = it->next)
1226 self->transients = g_slist_remove(self->transients,
1228 group_remove(self->group, self);
1231 if (hints->window_group != None) {
1232 self->group = group_add(hints->window_group, self);
1234 /* i can only have transients from the group if i am not
1236 if (!self->transient_for) {
1237 /* add other transients of the group that are already
1239 for (it = self->group->members; it; it = it->next) {
1240 ObClient *c = it->data;
1241 if (c != self && c->transient_for == OB_TRAN_GROUP)
1243 g_slist_append(self->transients, c);
1248 /* the WM_HINTS can contain an icon */
1249 client_update_icons(self);
1251 /* because the self->transient flag wont change from this call,
1252 we don't need to update the window's type and such, only its
1253 transient_for, and the transients lists of other windows in
1254 the group may be affected */
1255 client_update_transient_for(self);
1261 if (ur != self->urgent) {
1263 ob_debug("Urgent Hint for 0x%lx: %s\n", self->window,
1265 /* fire the urgent callback if we're mapped, otherwise, wait until
1266 after we're mapped */
1268 dispatch_client(Event_Client_Urgent, self, self->urgent, 0);
1272 void client_update_title(ObClient *self)
1278 gboolean read_title;
1280 g_free(self->title);
1283 if (!PROP_GETS(self->window, net_wm_name, utf8, &data))
1284 /* try old x stuff */
1285 if (!PROP_GETS(self->window, wm_name, locale, &data))
1286 data = g_strdup("Unnamed Window");
1288 /* look for duplicates and append a number */
1290 for (it = client_list; it; it = it->next)
1291 if (it->data != self) {
1292 ObClient *c = it->data;
1293 if (0 == strncmp(c->title, data, strlen(data)))
1294 nums |= 1 << c->title_count;
1296 /* find first free number */
1297 for (i = 1; i <= 32; ++i)
1298 if (!(nums & (1 << i))) {
1299 if (self->title_count == 1 || i == 1)
1300 self->title_count = i;
1303 /* dont display the number for the first window */
1304 if (self->title_count > 1) {
1305 char *vdata, *ndata;
1306 ndata = g_strdup_printf(" - [%u]", self->title_count);
1307 vdata = g_strconcat(data, ndata, NULL);
1313 PROP_SETS(self->window, net_wm_visible_name, data);
1318 frame_adjust_title(self->frame);
1320 /* update the icon title */
1322 g_free(self->icon_title);
1326 if (!PROP_GETS(self->window, net_wm_icon_name, utf8, &data))
1327 /* try old x stuff */
1328 if (!PROP_GETS(self->window, wm_icon_name, locale, &data)) {
1329 data = g_strdup(self->title);
1333 /* append the title count, dont display the number for the first window */
1334 if (read_title && self->title_count > 1) {
1335 char *vdata, *ndata;
1336 ndata = g_strdup_printf(" - [%u]", self->title_count);
1337 vdata = g_strconcat(data, ndata, NULL);
1343 PROP_SETS(self->window, net_wm_visible_icon_name, data);
1345 self->icon_title = data;
1348 void client_update_class(ObClient *self)
1353 if (self->name) g_free(self->name);
1354 if (self->class) g_free(self->class);
1355 if (self->role) g_free(self->role);
1357 self->name = self->class = self->role = NULL;
1359 if (PROP_GETSS(self->window, wm_class, locale, &data)) {
1361 self->name = g_strdup(data[0]);
1363 self->class = g_strdup(data[1]);
1368 if (PROP_GETS(self->window, wm_window_role, locale, &s))
1369 self->role = g_strdup(s);
1371 if (self->name == NULL) self->name = g_strdup("");
1372 if (self->class == NULL) self->class = g_strdup("");
1373 if (self->role == NULL) self->role = g_strdup("");
1376 void client_update_strut(ObClient *self)
1381 if (!PROP_GETA32(self->window, net_wm_strut, cardinal, &data, &num)) {
1382 STRUT_SET(self->strut, 0, 0, 0, 0);
1385 STRUT_SET(self->strut, data[0], data[2], data[1], data[3]);
1387 STRUT_SET(self->strut, 0, 0, 0, 0);
1391 /* updating here is pointless while we're being mapped cuz we're not in
1392 the client list yet */
1394 screen_update_areas();
1397 void client_update_icons(ObClient *self)
1403 for (i = 0; i < self->nicons; ++i)
1404 g_free(self->icons[i].data);
1405 if (self->nicons > 0)
1406 g_free(self->icons);
1409 if (PROP_GETA32(self->window, net_wm_icon, cardinal, &data, &num)) {
1410 /* figure out how many valid icons are in here */
1412 while (num - i > 2) {
1416 if (i > num || w*h == 0) break;
1420 self->icons = g_new(ObClientIcon, self->nicons);
1422 /* store the icons */
1424 for (j = 0; j < self->nicons; ++j) {
1427 w = self->icons[j].width = data[i++];
1428 h = self->icons[j].height = data[i++];
1430 if (w*h == 0) continue;
1432 self->icons[j].data = g_new(RrPixel32, w * h);
1433 for (x = 0, y = 0, t = 0; t < w * h; ++t, ++x, ++i) {
1438 self->icons[j].data[t] =
1439 (((data[i] >> 24) & 0xff) << RrDefaultAlphaOffset) +
1440 (((data[i] >> 16) & 0xff) << RrDefaultRedOffset) +
1441 (((data[i] >> 8) & 0xff) << RrDefaultGreenOffset) +
1442 (((data[i] >> 0) & 0xff) << RrDefaultBlueOffset);
1448 } else if (PROP_GETA32(self->window, kwm_win_icon,
1449 kwm_win_icon, &data, &num)) {
1452 self->icons = g_new(ObClientIcon, self->nicons);
1453 xerror_set_ignore(TRUE);
1454 if (!RrPixmapToRGBA(ob_rr_inst,
1456 &self->icons[self->nicons-1].width,
1457 &self->icons[self->nicons-1].height,
1458 &self->icons[self->nicons-1].data)) {
1459 g_free(&self->icons[self->nicons-1]);
1462 xerror_set_ignore(FALSE);
1468 if ((hints = XGetWMHints(ob_display, self->window))) {
1469 if (hints->flags & IconPixmapHint) {
1471 self->icons = g_new(ObClientIcon, self->nicons);
1472 xerror_set_ignore(TRUE);
1473 if (!RrPixmapToRGBA(ob_rr_inst,
1475 (hints->flags & IconMaskHint ?
1476 hints->icon_mask : None),
1477 &self->icons[self->nicons-1].width,
1478 &self->icons[self->nicons-1].height,
1479 &self->icons[self->nicons-1].data)){
1480 g_free(&self->icons[self->nicons-1]);
1483 xerror_set_ignore(FALSE);
1490 frame_adjust_icon(self->frame);
1493 static void client_change_state(ObClient *self)
1496 guint32 netstate[10];
1499 state[0] = self->wmstate;
1501 PROP_SETA32(self->window, wm_state, wm_state, state, 2);
1505 netstate[num++] = prop_atoms.net_wm_state_modal;
1507 netstate[num++] = prop_atoms.net_wm_state_shaded;
1509 netstate[num++] = prop_atoms.net_wm_state_hidden;
1510 if (self->skip_taskbar)
1511 netstate[num++] = prop_atoms.net_wm_state_skip_taskbar;
1512 if (self->skip_pager)
1513 netstate[num++] = prop_atoms.net_wm_state_skip_pager;
1514 if (self->fullscreen)
1515 netstate[num++] = prop_atoms.net_wm_state_fullscreen;
1517 netstate[num++] = prop_atoms.net_wm_state_maximized_vert;
1519 netstate[num++] = prop_atoms.net_wm_state_maximized_horz;
1521 netstate[num++] = prop_atoms.net_wm_state_above;
1523 netstate[num++] = prop_atoms.net_wm_state_below;
1524 PROP_SETA32(self->window, net_wm_state, atom, netstate, num);
1526 client_calc_layer(self);
1529 frame_adjust_state(self->frame);
1532 ObClient *client_search_focus_tree(ObClient *self)
1537 for (it = self->transients; it != NULL; it = it->next) {
1538 if (client_focused(it->data)) return it->data;
1539 if ((ret = client_search_focus_tree(it->data))) return ret;
1544 ObClient *client_search_focus_tree_full(ObClient *self)
1546 if (self->transient_for) {
1547 if (self->transient_for != OB_TRAN_GROUP) {
1548 return client_search_focus_tree_full(self->transient_for);
1551 gboolean recursed = FALSE;
1553 for (it = self->group->members; it; it = it->next)
1554 if (!((ObClient*)it->data)->transient_for) {
1556 if ((c = client_search_focus_tree_full(it->data)))
1565 /* this function checks the whole tree, the client_search_focus_tree~
1566 does not, so we need to check this window */
1567 if (client_focused(self))
1569 return client_search_focus_tree(self);
1572 static ObStackingLayer calc_layer(ObClient *self)
1576 if (self->fullscreen) l = OB_STACKING_LAYER_FULLSCREEN;
1577 else if (self->type == OB_CLIENT_TYPE_DESKTOP)
1578 l = OB_STACKING_LAYER_DESKTOP;
1579 else if (self->type == OB_CLIENT_TYPE_DOCK) {
1580 if (!self->below) l = OB_STACKING_LAYER_TOP;
1581 else l = OB_STACKING_LAYER_NORMAL;
1583 else if (self->above) l = OB_STACKING_LAYER_ABOVE;
1584 else if (self->below) l = OB_STACKING_LAYER_BELOW;
1585 else l = OB_STACKING_LAYER_NORMAL;
1590 static void client_calc_layer_recursive(ObClient *self, ObClient *orig,
1591 ObStackingLayer l, gboolean raised)
1593 ObStackingLayer old, own;
1597 own = calc_layer(self);
1598 self->layer = l > own ? l : own;
1600 for (it = self->transients; it; it = it->next)
1601 client_calc_layer_recursive(it->data, orig,
1602 l, raised ? raised : l != old);
1604 if (!raised && l != old)
1605 if (orig->frame) { /* only restack if the original window is managed */
1606 /* XXX add_non_intrusive ever? */
1607 stacking_remove(CLIENT_AS_WINDOW(self));
1608 stacking_add(CLIENT_AS_WINDOW(self));
1612 void client_calc_layer(ObClient *self)
1619 /* transients take on the layer of their parents */
1620 self = client_search_top_transient(self);
1622 l = calc_layer(self);
1624 client_calc_layer_recursive(self, orig, l, FALSE);
1627 gboolean client_should_show(ObClient *self)
1629 if (self->iconic) return FALSE;
1630 else if (!(self->desktop == screen_desktop ||
1631 self->desktop == DESKTOP_ALL)) return FALSE;
1632 else if (client_normal(self) && screen_showing_desktop) return FALSE;
1637 static void client_showhide(ObClient *self)
1640 if (client_should_show(self))
1641 frame_show(self->frame);
1643 frame_hide(self->frame);
1646 gboolean client_normal(ObClient *self) {
1647 return ! (self->type == OB_CLIENT_TYPE_DESKTOP ||
1648 self->type == OB_CLIENT_TYPE_DOCK ||
1649 self->type == OB_CLIENT_TYPE_SPLASH);
1652 static void client_apply_startup_state(ObClient *self)
1654 /* these are in a carefully crafted order.. */
1657 self->iconic = FALSE;
1658 client_iconify(self, TRUE, FALSE);
1660 if (self->fullscreen) {
1661 self->fullscreen = FALSE;
1662 client_fullscreen(self, TRUE, FALSE);
1665 self->shaded = FALSE;
1666 client_shade(self, TRUE);
1669 dispatch_client(Event_Client_Urgent, self, self->urgent, 0);
1671 if (self->max_vert && self->max_horz) {
1672 self->max_vert = self->max_horz = FALSE;
1673 client_maximize(self, TRUE, 0, FALSE);
1674 } else if (self->max_vert) {
1675 self->max_vert = FALSE;
1676 client_maximize(self, TRUE, 2, FALSE);
1677 } else if (self->max_horz) {
1678 self->max_horz = FALSE;
1679 client_maximize(self, TRUE, 1, FALSE);
1682 /* nothing to do for the other states:
1691 void client_configure_full(ObClient *self, ObCorner anchor,
1692 int x, int y, int w, int h,
1693 gboolean user, gboolean final,
1694 gboolean force_reply)
1696 gboolean moved = FALSE, resized = FALSE;
1698 /* gets the frame's position */
1699 frame_client_gravity(self->frame, &x, &y);
1701 /* these positions are frame positions, not client positions */
1703 /* set the size and position if fullscreen */
1704 if (self->fullscreen) {
1707 XF86VidModeModeLine mode;
1712 i = client_monitor(self);
1713 a = screen_physical_area_monitor(i);
1716 if (i == 0 && /* primary head */
1717 extensions_vidmode &&
1718 XF86VidModeGetViewPort(ob_display, ob_screen, &x, &y) &&
1719 /* get the mode last so the mode.privsize isnt freed incorrectly */
1720 XF86VidModeGetModeLine(ob_display, ob_screen, &dot, &mode)) {
1725 if (mode.privsize) XFree(mode.private);
1735 user = FALSE; /* ignore that increment etc shit when in fullscreen */
1739 a = screen_area_monitor(self->desktop, client_monitor(self));
1741 /* set the size and position if maximized */
1742 if (self->max_horz) {
1743 x = a->x - self->frame->size.left;
1746 if (self->max_vert) {
1748 h = a->height - self->frame->size.top - self->frame->size.bottom;
1752 /* gets the client's position */
1753 frame_frame_gravity(self->frame, &x, &y);
1755 /* these override the above states! if you cant move you can't move! */
1757 if (!(self->functions & OB_CLIENT_FUNC_MOVE)) {
1761 if (!(self->functions & OB_CLIENT_FUNC_RESIZE)) {
1762 w = self->area.width;
1763 h = self->area.height;
1767 if (!(w == self->area.width && h == self->area.height)) {
1768 int basew, baseh, minw, minh;
1770 /* base size is substituted with min size if not specified */
1771 if (self->base_size.width || self->base_size.height) {
1772 basew = self->base_size.width;
1773 baseh = self->base_size.height;
1775 basew = self->min_size.width;
1776 baseh = self->min_size.height;
1778 /* min size is substituted with base size if not specified */
1779 if (self->min_size.width || self->min_size.height) {
1780 minw = self->min_size.width;
1781 minh = self->min_size.height;
1783 minw = self->base_size.width;
1784 minh = self->base_size.height;
1788 /* for interactive resizing. have to move half an increment in each
1791 /* how far we are towards the next size inc */
1792 int mw = (w - basew) % self->size_inc.width;
1793 int mh = (h - baseh) % self->size_inc.height;
1795 int aw = self->size_inc.width / 2;
1796 int ah = self->size_inc.height / 2;
1797 /* don't let us move into a new size increment */
1798 if (mw + aw >= self->size_inc.width)
1799 aw = self->size_inc.width - mw - 1;
1800 if (mh + ah >= self->size_inc.height)
1801 ah = self->size_inc.height - mh - 1;
1805 /* if this is a user-requested resize, then check against min/max
1808 /* smaller than min size or bigger than max size? */
1809 if (w > self->max_size.width) w = self->max_size.width;
1810 if (w < minw) w = minw;
1811 if (h > self->max_size.height) h = self->max_size.height;
1812 if (h < minh) h = minh;
1818 /* keep to the increments */
1819 w /= self->size_inc.width;
1820 h /= self->size_inc.height;
1822 /* you cannot resize to nothing */
1823 if (basew + w < 1) w = 1 - basew;
1824 if (baseh + h < 1) h = 1 - baseh;
1826 /* store the logical size */
1827 SIZE_SET(self->logical_size,
1828 self->size_inc.width > 1 ? w : w + basew,
1829 self->size_inc.height > 1 ? h : h + baseh);
1831 w *= self->size_inc.width;
1832 h *= self->size_inc.height;
1838 /* adjust the height to match the width for the aspect ratios.
1839 for this, min size is not substituted for base size ever. */
1840 w -= self->base_size.width;
1841 h -= self->base_size.height;
1843 if (self->min_ratio)
1844 if (h * self->min_ratio > w) h = (int)(w / self->min_ratio);
1845 if (self->max_ratio)
1846 if (h * self->max_ratio < w) h = (int)(w / self->max_ratio);
1848 w += self->base_size.width;
1849 h += self->base_size.height;
1854 case OB_CORNER_TOPLEFT:
1856 case OB_CORNER_TOPRIGHT:
1857 x -= w - self->area.width;
1859 case OB_CORNER_BOTTOMLEFT:
1860 y -= h - self->area.height;
1862 case OB_CORNER_BOTTOMRIGHT:
1863 x -= w - self->area.width;
1864 y -= h - self->area.height;
1868 moved = x != self->area.x || y != self->area.y;
1869 resized = w != self->area.width || h != self->area.height;
1871 RECT_SET(self->area, x, y, w, h);
1873 /* for app-requested resizes, always resize if 'resized' is true.
1874 for user-requested ones, only resize if final is true, or when
1875 resizing in opaque mode */
1876 if ((!user && resized) ||
1877 (user && (final || (resized && config_opaque_resize))))
1878 XResizeWindow(ob_display, self->window, w, h);
1880 /* move/resize the frame to match the request */
1882 if (self->decorations != self->frame->decorations)
1883 moved = resized = TRUE;
1885 if (moved || resized)
1886 frame_adjust_area(self->frame, moved, resized);
1888 if (!resized && (force_reply || ((!user && moved) || (user && final))))
1891 event.type = ConfigureNotify;
1892 event.xconfigure.display = ob_display;
1893 event.xconfigure.event = self->window;
1894 event.xconfigure.window = self->window;
1896 /* root window real coords */
1897 event.xconfigure.x = self->frame->area.x + self->frame->size.left -
1899 event.xconfigure.y = self->frame->area.y + self->frame->size.top -
1901 event.xconfigure.width = w;
1902 event.xconfigure.height = h;
1903 event.xconfigure.border_width = 0;
1904 event.xconfigure.above = self->frame->plate;
1905 event.xconfigure.override_redirect = FALSE;
1906 XSendEvent(event.xconfigure.display, event.xconfigure.window,
1907 FALSE, StructureNotifyMask, &event);
1912 void client_fullscreen(ObClient *self, gboolean fs, gboolean savearea)
1916 if (!(self->functions & OB_CLIENT_FUNC_FULLSCREEN) || /* can't */
1917 self->fullscreen == fs) return; /* already done */
1919 self->fullscreen = fs;
1920 client_change_state(self); /* change the state hints on the client,
1921 and adjust out layer/stacking */
1925 guint32 dimensions[4];
1926 dimensions[0] = self->area.x;
1927 dimensions[1] = self->area.y;
1928 dimensions[2] = self->area.width;
1929 dimensions[3] = self->area.height;
1931 PROP_SETA32(self->window, openbox_premax, cardinal,
1935 /* these are not actually used cuz client_configure will set them
1936 as appropriate when the window is fullscreened */
1943 /* pick some fallbacks... */
1944 a = screen_area_monitor(self->desktop, 0);
1945 x = a->x + a->width / 4;
1946 y = a->y + a->height / 4;
1950 if (PROP_GETA32(self->window, openbox_premax, cardinal,
1951 (guint32**)&dimensions, &num)) {
1962 client_setup_decor_and_functions(self);
1964 client_configure(self, OB_CORNER_TOPLEFT, x, y, w, h, TRUE, TRUE);
1966 /* try focus us when we go into fullscreen mode */
1970 static void client_iconify_recursive(ObClient *self,
1971 gboolean iconic, gboolean curdesk)
1974 gboolean changed = FALSE;
1977 if (self->iconic != iconic) {
1978 ob_debug("%sconifying window: 0x%lx\n", (iconic ? "I" : "Uni"),
1981 self->iconic = iconic;
1984 if (self->functions & OB_CLIENT_FUNC_ICONIFY) {
1985 self->wmstate = IconicState;
1986 self->ignore_unmaps++;
1987 /* we unmap the client itself so that we can get MapRequest
1988 events, and because the ICCCM tells us to! */
1989 XUnmapWindow(ob_display, self->window);
1991 /* update the focus lists.. iconic windows go to the bottom of
1992 the list, put the new iconic window at the 'top of the
1994 focus_order_to_top(self);
2000 client_set_desktop(self, screen_desktop, FALSE);
2001 self->wmstate = self->shaded ? IconicState : NormalState;
2002 XMapWindow(ob_display, self->window);
2004 /* this puts it after the current focused window */
2005 focus_order_remove(self);
2006 focus_order_add_new(self);
2008 /* this is here cuz with the VIDMODE extension, the viewport can
2009 change while a fullscreen window is iconic, and when it
2010 uniconifies, it would be nice if it did so to the new position
2012 client_reconfigure(self);
2019 client_change_state(self);
2020 client_showhide(self);
2021 screen_update_areas();
2023 dispatch_client(iconic ? Event_Client_Unmapped : Event_Client_Mapped,
2027 /* iconify all transients */
2028 for (it = self->transients; it != NULL; it = it->next)
2029 if (it->data != self) client_iconify_recursive(it->data,
2033 void client_iconify(ObClient *self, gboolean iconic, gboolean curdesk)
2035 /* move up the transient chain as far as possible first */
2036 self = client_search_top_transient(self);
2038 client_iconify_recursive(client_search_top_transient(self),
2042 void client_maximize(ObClient *self, gboolean max, int dir, gboolean savearea)
2046 g_assert(dir == 0 || dir == 1 || dir == 2);
2047 if (!(self->functions & OB_CLIENT_FUNC_MAXIMIZE)) return; /* can't */
2049 /* check if already done */
2051 if (dir == 0 && self->max_horz && self->max_vert) return;
2052 if (dir == 1 && self->max_horz) return;
2053 if (dir == 2 && self->max_vert) return;
2055 if (dir == 0 && !self->max_horz && !self->max_vert) return;
2056 if (dir == 1 && !self->max_horz) return;
2057 if (dir == 2 && !self->max_vert) return;
2060 /* work with the frame's coords */
2061 x = self->frame->area.x;
2062 y = self->frame->area.y;
2063 w = self->area.width;
2064 h = self->area.height;
2068 gint32 dimensions[4];
2077 /* get the property off the window and use it for the dimensions
2078 we are already maxed on */
2079 if (PROP_GETA32(self->window, openbox_premax, cardinal,
2080 (guint32**)&readdim, &num)) {
2082 if (self->max_horz) {
2083 dimensions[0] = readdim[0];
2084 dimensions[2] = readdim[2];
2086 if (self->max_vert) {
2087 dimensions[1] = readdim[1];
2088 dimensions[3] = readdim[3];
2094 PROP_SETA32(self->window, openbox_premax, cardinal,
2095 (guint32*)dimensions, 4);
2102 /* pick some fallbacks... */
2103 a = screen_area_monitor(self->desktop, 0);
2104 if (dir == 0 || dir == 1) { /* horz */
2105 x = a->x + a->width / 4;
2108 if (dir == 0 || dir == 2) { /* vert */
2109 y = a->y + a->height / 4;
2113 if (PROP_GETA32(self->window, openbox_premax, cardinal,
2114 (guint32**)&dimensions, &num)) {
2116 if (dir == 0 || dir == 1) { /* horz */
2120 if (dir == 0 || dir == 2) { /* vert */
2129 if (dir == 0 || dir == 1) /* horz */
2130 self->max_horz = max;
2131 if (dir == 0 || dir == 2) /* vert */
2132 self->max_vert = max;
2134 if (!self->max_horz && !self->max_vert)
2135 PROP_ERASE(self->window, openbox_premax);
2137 client_change_state(self); /* change the state hints on the client */
2139 /* figure out where the client should be going */
2140 frame_frame_gravity(self->frame, &x, &y);
2141 client_configure(self, OB_CORNER_TOPLEFT, x, y, w, h, TRUE, TRUE);
2144 void client_shade(ObClient *self, gboolean shade)
2146 if ((!(self->functions & OB_CLIENT_FUNC_SHADE) &&
2147 shade) || /* can't shade */
2148 self->shaded == shade) return; /* already done */
2150 /* when we're iconic, don't change the wmstate */
2152 self->wmstate = shade ? IconicState : NormalState;
2153 self->shaded = shade;
2154 client_change_state(self);
2155 /* resize the frame to just the titlebar */
2156 frame_adjust_area(self->frame, FALSE, FALSE);
2159 void client_close(ObClient *self)
2163 if (!(self->functions & OB_CLIENT_FUNC_CLOSE)) return;
2166 XXX: itd be cool to do timeouts and shit here for killing the client's
2168 like... if the window is around after 5 seconds, then the close button
2169 turns a nice red, and if this function is called again, the client is
2173 ce.xclient.type = ClientMessage;
2174 ce.xclient.message_type = prop_atoms.wm_protocols;
2175 ce.xclient.display = ob_display;
2176 ce.xclient.window = self->window;
2177 ce.xclient.format = 32;
2178 ce.xclient.data.l[0] = prop_atoms.wm_delete_window;
2179 ce.xclient.data.l[1] = event_lasttime;
2180 ce.xclient.data.l[2] = 0l;
2181 ce.xclient.data.l[3] = 0l;
2182 ce.xclient.data.l[4] = 0l;
2183 XSendEvent(ob_display, self->window, FALSE, NoEventMask, &ce);
2186 void client_kill(ObClient *self)
2188 XKillClient(ob_display, self->window);
2191 void client_set_desktop_recursive(ObClient *self,
2192 guint target, gboolean donthide)
2197 if (target != self->desktop) {
2199 ob_debug("Setting desktop %u\n", target+1);
2201 g_assert(target < screen_num_desktops || target == DESKTOP_ALL);
2203 /* remove from the old desktop(s) */
2204 focus_order_remove(self);
2206 old = self->desktop;
2207 self->desktop = target;
2208 PROP_SET32(self->window, net_wm_desktop, cardinal, target);
2209 /* the frame can display the current desktop state */
2210 frame_adjust_state(self->frame);
2211 /* 'move' the window to the new desktop */
2213 client_showhide(self);
2214 /* raise if it was not already on the desktop */
2215 if (old != DESKTOP_ALL)
2216 stacking_raise(CLIENT_AS_WINDOW(self));
2217 screen_update_areas();
2219 /* add to the new desktop(s) */
2220 if (config_focus_new)
2221 focus_order_to_top(self);
2223 focus_order_to_bottom(self);
2225 dispatch_client(Event_Client_Desktop, self, target, old);
2228 /* move all transients */
2229 for (it = self->transients; it != NULL; it = it->next)
2230 if (it->data != self) client_set_desktop_recursive(it->data,
2234 void client_set_desktop(ObClient *self, guint target, gboolean donthide)
2236 client_set_desktop_recursive(client_search_top_transient(self),
2240 ObClient *client_search_modal_child(ObClient *self)
2245 for (it = self->transients; it != NULL; it = it->next) {
2246 ObClient *c = it->data;
2247 if ((ret = client_search_modal_child(c))) return ret;
2248 if (c->modal) return c;
2253 gboolean client_validate(ObClient *self)
2257 XSync(ob_display, FALSE); /* get all events on the server */
2259 if (XCheckTypedWindowEvent(ob_display, self->window, DestroyNotify, &e) ||
2260 XCheckTypedWindowEvent(ob_display, self->window, UnmapNotify, &e)) {
2261 XPutBackEvent(ob_display, &e);
2268 void client_set_wm_state(ObClient *self, long state)
2270 if (state == self->wmstate) return; /* no change */
2274 client_iconify(self, TRUE, TRUE);
2277 client_iconify(self, FALSE, TRUE);
2282 void client_set_state(ObClient *self, Atom action, long data1, long data2)
2284 gboolean shaded = self->shaded;
2285 gboolean fullscreen = self->fullscreen;
2286 gboolean max_horz = self->max_horz;
2287 gboolean max_vert = self->max_vert;
2290 if (!(action == prop_atoms.net_wm_state_add ||
2291 action == prop_atoms.net_wm_state_remove ||
2292 action == prop_atoms.net_wm_state_toggle))
2293 /* an invalid action was passed to the client message, ignore it */
2296 for (i = 0; i < 2; ++i) {
2297 Atom state = i == 0 ? data1 : data2;
2299 if (!state) continue;
2301 /* if toggling, then pick whether we're adding or removing */
2302 if (action == prop_atoms.net_wm_state_toggle) {
2303 if (state == prop_atoms.net_wm_state_modal)
2304 action = self->modal ? prop_atoms.net_wm_state_remove :
2305 prop_atoms.net_wm_state_add;
2306 else if (state == prop_atoms.net_wm_state_maximized_vert)
2307 action = self->max_vert ? prop_atoms.net_wm_state_remove :
2308 prop_atoms.net_wm_state_add;
2309 else if (state == prop_atoms.net_wm_state_maximized_horz)
2310 action = self->max_horz ? prop_atoms.net_wm_state_remove :
2311 prop_atoms.net_wm_state_add;
2312 else if (state == prop_atoms.net_wm_state_shaded)
2313 action = self->shaded ? prop_atoms.net_wm_state_remove :
2314 prop_atoms.net_wm_state_add;
2315 else if (state == prop_atoms.net_wm_state_skip_taskbar)
2316 action = self->skip_taskbar ?
2317 prop_atoms.net_wm_state_remove :
2318 prop_atoms.net_wm_state_add;
2319 else if (state == prop_atoms.net_wm_state_skip_pager)
2320 action = self->skip_pager ?
2321 prop_atoms.net_wm_state_remove :
2322 prop_atoms.net_wm_state_add;
2323 else if (state == prop_atoms.net_wm_state_fullscreen)
2324 action = self->fullscreen ?
2325 prop_atoms.net_wm_state_remove :
2326 prop_atoms.net_wm_state_add;
2327 else if (state == prop_atoms.net_wm_state_above)
2328 action = self->above ? prop_atoms.net_wm_state_remove :
2329 prop_atoms.net_wm_state_add;
2330 else if (state == prop_atoms.net_wm_state_below)
2331 action = self->below ? prop_atoms.net_wm_state_remove :
2332 prop_atoms.net_wm_state_add;
2335 if (action == prop_atoms.net_wm_state_add) {
2336 if (state == prop_atoms.net_wm_state_modal) {
2337 /* XXX raise here or something? */
2339 } else if (state == prop_atoms.net_wm_state_maximized_vert) {
2341 } else if (state == prop_atoms.net_wm_state_maximized_horz) {
2343 } else if (state == prop_atoms.net_wm_state_shaded) {
2345 } else if (state == prop_atoms.net_wm_state_skip_taskbar) {
2346 self->skip_taskbar = TRUE;
2347 } else if (state == prop_atoms.net_wm_state_skip_pager) {
2348 self->skip_pager = TRUE;
2349 } else if (state == prop_atoms.net_wm_state_fullscreen) {
2351 } else if (state == prop_atoms.net_wm_state_above) {
2353 } else if (state == prop_atoms.net_wm_state_below) {
2357 } else { /* action == prop_atoms.net_wm_state_remove */
2358 if (state == prop_atoms.net_wm_state_modal) {
2359 self->modal = FALSE;
2360 } else if (state == prop_atoms.net_wm_state_maximized_vert) {
2362 } else if (state == prop_atoms.net_wm_state_maximized_horz) {
2364 } else if (state == prop_atoms.net_wm_state_shaded) {
2366 } else if (state == prop_atoms.net_wm_state_skip_taskbar) {
2367 self->skip_taskbar = FALSE;
2368 } else if (state == prop_atoms.net_wm_state_skip_pager) {
2369 self->skip_pager = FALSE;
2370 } else if (state == prop_atoms.net_wm_state_fullscreen) {
2372 } else if (state == prop_atoms.net_wm_state_above) {
2373 self->above = FALSE;
2374 } else if (state == prop_atoms.net_wm_state_below) {
2375 self->below = FALSE;
2379 if (max_horz != self->max_horz || max_vert != self->max_vert) {
2380 if (max_horz != self->max_horz && max_vert != self->max_vert) {
2382 if (max_horz == max_vert) { /* both going the same way */
2383 client_maximize(self, max_horz, 0, TRUE);
2385 client_maximize(self, max_horz, 1, TRUE);
2386 client_maximize(self, max_vert, 2, TRUE);
2390 if (max_horz != self->max_horz)
2391 client_maximize(self, max_horz, 1, TRUE);
2393 client_maximize(self, max_vert, 2, TRUE);
2396 /* change fullscreen state before shading, as it will affect if the window
2398 if (fullscreen != self->fullscreen)
2399 client_fullscreen(self, fullscreen, TRUE);
2400 if (shaded != self->shaded)
2401 client_shade(self, shaded);
2402 client_calc_layer(self);
2403 client_change_state(self); /* change the hint to reflect these changes */
2406 ObClient *client_focus_target(ObClient *self)
2410 /* if we have a modal child, then focus it, not us */
2411 child = client_search_modal_child(self);
2412 if (child) return child;
2416 gboolean client_can_focus(ObClient *self)
2420 /* choose the correct target */
2421 self = client_focus_target(self);
2423 if (!self->frame->visible)
2426 if (!((self->can_focus || self->focus_notify) &&
2427 (self->desktop == screen_desktop ||
2428 self->desktop == DESKTOP_ALL) &&
2432 /* do a check to see if the window has already been unmapped or destroyed
2433 do this intelligently while watching out for unmaps we've generated
2434 (ignore_unmaps > 0) */
2435 if (XCheckTypedWindowEvent(ob_display, self->window,
2436 DestroyNotify, &ev)) {
2437 XPutBackEvent(ob_display, &ev);
2440 while (XCheckTypedWindowEvent(ob_display, self->window,
2441 UnmapNotify, &ev)) {
2442 if (self->ignore_unmaps) {
2443 self->ignore_unmaps--;
2445 XPutBackEvent(ob_display, &ev);
2453 gboolean client_focus(ObClient *self)
2455 /* choose the correct target */
2456 self = client_focus_target(self);
2458 if (!client_can_focus(self)) {
2459 if (!self->frame->visible) {
2460 /* update the focus lists */
2461 focus_order_to_top(self);
2466 if (self->can_focus)
2467 /* RevertToPointerRoot causes much more headache than RevertToNone, so
2468 I choose to use it always, hopefully to find errors quicker, if any
2469 are left. (I hate X. I hate focus events.) */
2470 XSetInputFocus(ob_display, self->window, RevertToPointerRoot,
2473 if (self->focus_notify) {
2475 ce.xclient.type = ClientMessage;
2476 ce.xclient.message_type = prop_atoms.wm_protocols;
2477 ce.xclient.display = ob_display;
2478 ce.xclient.window = self->window;
2479 ce.xclient.format = 32;
2480 ce.xclient.data.l[0] = prop_atoms.wm_take_focus;
2481 ce.xclient.data.l[1] = event_lasttime;
2482 ce.xclient.data.l[2] = 0l;
2483 ce.xclient.data.l[3] = 0l;
2484 ce.xclient.data.l[4] = 0l;
2485 XSendEvent(ob_display, self->window, FALSE, NoEventMask, &ce);
2489 ob_debug("%sively focusing %lx at %d\n",
2490 (self->can_focus ? "act" : "pass"),
2491 self->window, (int) event_lasttime);
2494 /* Cause the FocusIn to come back to us. Important for desktop switches,
2495 since otherwise we'll have no FocusIn on the queue and send it off to
2496 the focus_backup. */
2497 XSync(ob_display, FALSE);
2501 void client_unfocus(ObClient *self)
2503 g_assert(focus_client == self);
2505 ob_debug("client_unfocus for %lx\n", self->window);
2507 focus_fallback(OB_FOCUS_FALLBACK_UNFOCUSING);
2510 void client_activate(ObClient *self)
2512 if (client_normal(self) && screen_showing_desktop)
2513 screen_show_desktop(FALSE);
2515 client_iconify(self, FALSE, FALSE);
2516 if (self->desktop != DESKTOP_ALL &&
2517 self->desktop != screen_desktop)
2518 screen_set_desktop(self->desktop);
2519 else if (!self->frame->visible)
2520 /* if its not visible for other reasons, then don't mess
2524 client_shade(self, FALSE);
2526 stacking_raise(CLIENT_AS_WINDOW(self));
2529 gboolean client_focused(ObClient *self)
2531 return self == focus_client;
2534 ObClientIcon *client_icon(ObClient *self, int w, int h)
2537 /* si is the smallest image >= req */
2538 /* li is the largest image < req */
2539 unsigned long size, smallest = 0xffffffff, largest = 0, si = 0, li = 0;
2541 if (!self->nicons) return NULL;
2543 for (i = 0; i < self->nicons; ++i) {
2544 size = self->icons[i].width * self->icons[i].height;
2545 if (size < smallest && size >= (unsigned)(w * h)) {
2549 if (size > largest && size <= (unsigned)(w * h)) {
2554 if (largest == 0) /* didnt find one smaller than the requested size */
2555 return &self->icons[si];
2556 return &self->icons[li];
2559 /* this be mostly ripped from fvwm */
2560 ObClient *client_find_directional(ObClient *c, ObDirection dir)
2562 int my_cx, my_cy, his_cx, his_cy;
2565 int score, best_score;
2566 ObClient *best_client, *cur;
2572 /* first, find the centre coords of the currently focused window */
2573 my_cx = c->frame->area.x + c->frame->area.width / 2;
2574 my_cy = c->frame->area.y + c->frame->area.height / 2;
2579 for(it = g_list_first(client_list); it; it = it->next) {
2582 /* the currently selected window isn't interesting */
2585 if (!client_normal(cur))
2587 if(c->desktop != cur->desktop && cur->desktop != DESKTOP_ALL)
2591 if(client_focus_target(cur) == cur &&
2592 !(cur->can_focus || cur->focus_notify))
2595 /* find the centre coords of this window, from the
2596 * currently focused window's point of view */
2597 his_cx = (cur->frame->area.x - my_cx)
2598 + cur->frame->area.width / 2;
2599 his_cy = (cur->frame->area.y - my_cy)
2600 + cur->frame->area.height / 2;
2604 /* Rotate the diagonals 45 degrees counterclockwise.
2605 * To do this, multiply the matrix /+h +h\ with the
2606 * vector (x y). \-h +h/
2607 * h = sqrt(0.5). We can set h := 1 since absolute
2608 * distance doesn't matter here. */
2609 tx = his_cx + his_cy;
2610 his_cy = -his_cx + his_cy;
2615 case OB_DIRECTION_NORTH:
2616 case OB_DIRECTION_SOUTH:
2617 case OB_DIRECTION_NORTHEAST:
2618 case OB_DIRECTION_SOUTHWEST:
2619 offset = (his_cx < 0) ? -his_cx : his_cx;
2620 distance = ((dir == OB_DIRECTION_NORTH ||
2621 dir == OB_DIRECTION_NORTHEAST) ?
2624 case OB_DIRECTION_EAST:
2625 case OB_DIRECTION_WEST:
2626 case OB_DIRECTION_SOUTHEAST:
2627 case OB_DIRECTION_NORTHWEST:
2628 offset = (his_cy < 0) ? -his_cy : his_cy;
2629 distance = ((dir == OB_DIRECTION_WEST ||
2630 dir == OB_DIRECTION_NORTHWEST) ?
2635 /* the target must be in the requested direction */
2639 /* Calculate score for this window. The smaller the better. */
2640 score = distance + offset;
2642 /* windows more than 45 degrees off the direction are
2643 * heavily penalized and will only be chosen if nothing
2644 * else within a million pixels */
2645 if(offset > distance)
2648 if(best_score == -1 || score < best_score)
2656 void client_set_layer(ObClient *self, int layer)
2660 self->above = FALSE;
2661 } else if (layer == 0) {
2662 self->below = self->above = FALSE;
2664 self->below = FALSE;
2667 client_calc_layer(self);
2668 client_change_state(self); /* reflect this in the state hints */
2671 guint client_monitor(ObClient *self)
2675 for (i = 0; i < screen_num_monitors; ++i) {
2676 Rect *area = screen_physical_area_monitor(i);
2677 if (RECT_INTERSECTS_RECT(*area, self->frame->area))
2680 if (i == screen_num_monitors) i = 0;
2681 g_assert(i < screen_num_monitors);
2685 ObClient *client_search_top_transient(ObClient *self)
2687 /* move up the transient chain as far as possible */
2688 if (self->transient_for) {
2689 if (self->transient_for != OB_TRAN_GROUP) {
2690 return client_search_top_transient(self->transient_for);
2694 for (it = self->group->members; it; it = it->next) {
2695 ObClient *c = it->data;
2697 /* checking transient_for prevents infinate loops! */
2698 if (c != self && !c->transient_for)
2709 ObClient *client_search_transient(ObClient *self, ObClient *search)
2713 for (sit = self->transients; sit; sit = g_slist_next(sit)) {
2714 if (sit->data == search)
2716 if (client_search_transient(sit->data, search))
2722 gchar* client_get_sm_client_id(ObClient *self)
2726 if (!PROP_GETS(self->window, sm_client_id, locale, &id) && self->group)
2727 PROP_GETS(self->group->leader, sm_client_id, locale, &id);