1 /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
3 client.c for the Openbox window manager
4 Copyright (c) 2006 Mikael Magnusson
5 Copyright (c) 2003-2007 Dana Jansens
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 See the COPYING file for a copy of the GNU General Public License.
22 #include "startupnotify.h"
26 #include "moveresize.h"
29 #include "extensions.h"
39 #include "menuframe.h"
42 #include "render/render.h"
49 #include <X11/Xutil.h>
51 /*! The event mask to grab on client windows */
52 #define CLIENT_EVENTMASK (PropertyChangeMask | StructureNotifyMask)
54 #define CLIENT_NOPROPAGATEMASK (ButtonPressMask | ButtonReleaseMask | \
59 ObClientDestructor func;
63 GList *client_list = NULL;
65 static GSList *client_destructors = NULL;
67 static void client_get_all(ObClient *self);
68 static void client_toggle_border(ObClient *self, gboolean show);
69 static void client_get_startup_id(ObClient *self);
70 static void client_get_area(ObClient *self);
71 static void client_get_desktop(ObClient *self);
72 static void client_get_state(ObClient *self);
73 static void client_get_layer(ObClient *self);
74 static void client_get_shaped(ObClient *self);
75 static void client_get_mwm_hints(ObClient *self);
76 static void client_get_gravity(ObClient *self);
77 static void client_get_client_machine(ObClient *self);
78 static void client_change_allowed_actions(ObClient *self);
79 static void client_change_state(ObClient *self);
80 static void client_change_wm_state(ObClient *self);
81 static void client_apply_startup_state(ObClient *self, gint x, gint y);
82 static void client_restore_session_state(ObClient *self);
83 static void client_restore_session_stacking(ObClient *self);
84 static ObAppSettings *client_get_settings_state(ObClient *self);
86 void client_startup(gboolean reconfig)
93 void client_shutdown(gboolean reconfig)
97 void client_add_destructor(ObClientDestructor func, gpointer data)
99 Destructor *d = g_new(Destructor, 1);
102 client_destructors = g_slist_prepend(client_destructors, d);
105 void client_remove_destructor(ObClientDestructor func)
109 for (it = client_destructors; it; it = g_slist_next(it)) {
110 Destructor *d = it->data;
111 if (d->func == func) {
113 client_destructors = g_slist_delete_link(client_destructors, it);
119 void client_set_list()
121 Window *windows, *win_it;
123 guint size = g_list_length(client_list);
125 /* create an array of the window ids */
127 windows = g_new(Window, size);
129 for (it = client_list; it; it = g_list_next(it), ++win_it)
130 *win_it = ((ObClient*)it->data)->window;
134 PROP_SETA32(RootWindow(ob_display, ob_screen),
135 net_client_list, window, (gulong*)windows, size);
144 void client_foreach_transient(ObClient *self, ObClientForeachFunc func, gpointer data)
148 for (it = self->transients; it; it = g_slist_next(it)) {
149 if (!func(it->data, data)) return;
150 client_foreach_transient(it->data, func, data);
154 void client_foreach_ancestor(ObClient *self, ObClientForeachFunc func, gpointer data)
156 if (self->transient_for) {
157 if (self->transient_for != OB_TRAN_GROUP) {
158 if (!func(self->transient_for, data)) return;
159 client_foreach_ancestor(self->transient_for, func, data);
163 for (it = self->group->members; it; it = g_slist_next(it))
164 if (it->data != self &&
165 !((ObClient*)it->data)->transient_for) {
166 if (!func(it->data, data)) return;
167 client_foreach_ancestor(it->data, func, data);
174 void client_manage_all()
179 XWindowAttributes attrib;
181 XQueryTree(ob_display, RootWindow(ob_display, ob_screen),
182 &w, &w, &children, &nchild);
184 /* remove all icon windows from the list */
185 for (i = 0; i < nchild; i++) {
186 if (children[i] == None) continue;
187 wmhints = XGetWMHints(ob_display, children[i]);
189 if ((wmhints->flags & IconWindowHint) &&
190 (wmhints->icon_window != children[i]))
191 for (j = 0; j < nchild; j++)
192 if (children[j] == wmhints->icon_window) {
200 for (i = 0; i < nchild; ++i) {
201 if (children[i] == None)
203 if (XGetWindowAttributes(ob_display, children[i], &attrib)) {
204 if (attrib.override_redirect) continue;
206 if (attrib.map_state != IsUnmapped)
207 client_manage(children[i]);
213 void client_manage(Window window)
217 XWindowAttributes attrib;
218 XSetWindowAttributes attrib_set;
220 gboolean activate = FALSE;
221 ObAppSettings *settings;
226 /* check if it has already been unmapped by the time we started mapping.
227 the grab does a sync so we don't have to here */
228 if (XCheckTypedWindowEvent(ob_display, window, DestroyNotify, &e) ||
229 XCheckTypedWindowEvent(ob_display, window, UnmapNotify, &e))
231 XPutBackEvent(ob_display, &e);
233 ob_debug("Trying to manage unmapped window. Aborting that.\n");
235 return; /* don't manage it */
238 /* make sure it isn't an override-redirect window */
239 if (!XGetWindowAttributes(ob_display, window, &attrib) ||
240 attrib.override_redirect)
243 return; /* don't manage it */
246 /* is the window a docking app */
247 if ((wmhint = XGetWMHints(ob_display, window))) {
248 if ((wmhint->flags & StateHint) &&
249 wmhint->initial_state == WithdrawnState)
251 dock_add(window, wmhint);
259 ob_debug("Managing window: %lx\n", window);
261 /* choose the events we want to receive on the CLIENT window */
262 attrib_set.event_mask = CLIENT_EVENTMASK;
263 attrib_set.do_not_propagate_mask = CLIENT_NOPROPAGATEMASK;
264 XChangeWindowAttributes(ob_display, window,
265 CWEventMask|CWDontPropagate, &attrib_set);
268 /* create the ObClient struct, and populate it from the hints on the
270 self = g_new0(ObClient, 1);
271 self->obwin.type = Window_Client;
272 self->window = window;
274 /* non-zero defaults */
275 self->wmstate = WithdrawnState; /* make sure it gets updated first time */
277 self->desktop = screen_num_desktops; /* always an invalid value */
278 self->user_time = CurrentTime;
280 client_get_all(self);
281 /* per-app settings override stuff, and return the settings for other
283 settings = client_get_settings_state(self);
284 /* the session should get the last say */
285 client_restore_session_state(self);
287 client_calc_layer(self);
290 Time t = sn_app_started(self->startup_id, self->class);
291 if (t) self->user_time = t;
294 /* update the focus lists, do this before the call to change_state or
295 it can end up in the list twice! */
296 focus_order_add_new(self);
298 /* remove the client's border (and adjust re gravity) */
299 client_toggle_border(self, FALSE);
301 /* specify that if we exit, the window should not be destroyed and should
302 be reparented back to root automatically */
303 XChangeSaveSet(ob_display, window, SetModeInsert);
305 /* create the decoration frame for the client window */
306 self->frame = frame_new(self);
308 frame_grab_client(self->frame, self);
310 /* do this after we have a frame.. it uses the frame to help determine the
311 WM_STATE to apply. */
312 client_change_state(self);
316 stacking_add_nonintrusive(CLIENT_AS_WINDOW(self));
317 client_restore_session_stacking(self);
319 /* focus the new window? */
320 if (ob_state() != OB_STATE_STARTING &&
321 /* this means focus=true for window is same as config_focus_new=true */
322 ((config_focus_new || (settings && settings->focus == 1)) ||
323 client_search_focus_parent(self)) &&
324 /* this checks for focus=false for the window */
325 (!settings || settings->focus != 0) &&
326 /* note the check against Type_Normal/Dialog, not client_normal(self),
327 which would also include other types. in this case we want more
328 strict rules for focus */
329 (self->type == OB_CLIENT_TYPE_NORMAL ||
330 self->type == OB_CLIENT_TYPE_DIALOG))
334 if (self->desktop != screen_desktop) {
335 /* activate the window */
338 gboolean group_foc = FALSE;
343 for (it = self->group->members; it; it = g_slist_next(it))
345 if (client_focused(it->data))
353 (!self->transient_for && (!self->group ||
354 !self->group->members->next))) ||
355 client_search_focus_tree_full(self) ||
357 !client_normal(focus_client))
359 /* activate the window */
366 /* get the current position */
370 /* figure out placement for the window */
371 if (ob_state() == OB_STATE_RUNNING) {
374 transient = place_client(self, &newx, &newy, settings);
376 /* make sure the window is visible. */
377 client_find_onscreen(self, &newx, &newy,
378 self->frame->area.width,
379 self->frame->area.height,
380 /* non-normal clients has less rules, and
381 windows that are being restored from a
382 session do also. we can assume you want
383 it back where you saved it. Clients saying
384 they placed themselves are subjected to
385 harder rules, ones that are placed by
386 place.c or by the user are allowed partially
387 off-screen and on xinerama divides (ie,
388 it is up to the placement routines to avoid
389 the xinerama divides) */
391 (((self->positioned & PPosition) &&
392 !(self->positioned & USPosition)) &&
393 client_normal(self) &&
397 /* do this after the window is placed, so the premax/prefullscreen numbers
399 also, this moves the window to the position where it has been placed
401 ob_debug("placing window 0x%x at %d, %d with size %d x %d\n",
402 self->window, newx, newy, self->area.width, self->area.height);
403 client_apply_startup_state(self, newx, newy);
405 keyboard_grab_for_client(self, TRUE);
406 mouse_grab_for_client(self, TRUE);
409 guint32 last_time = focus_client ?
410 focus_client->user_time : CurrentTime;
412 /* This is focus stealing prevention */
413 ob_debug("Want to focus new window 0x%x with time %u (last time %u)\n",
414 self->window, self->user_time, last_time);
416 /* If a nothing at all, or a parent was focused, then focus this
419 if (!focus_client || client_search_focus_parent(self) != NULL)
423 /* If time stamp is old, don't steal focus */
424 if (self->user_time && last_time &&
425 !event_time_after(self->user_time, last_time))
429 /* Don't steal focus from globally active clients.
430 I stole this idea from KWin. It seems nice.
432 if (!(focus_client->can_focus || focus_client->focus_notify))
438 /* since focus can change the stacking orders, if we focus the
439 window then the standard raise it gets is not enough, we need
440 to queue one for after the focus change takes place */
443 ob_debug("Focus stealing prevention activated for %s with time %u "
445 self->title, self->user_time, last_time);
446 /* if the client isn't focused, then hilite it so the user
448 client_hilite(self, TRUE);
452 /* This may look rather odd. Well it's because new windows are added
453 to the stacking order non-intrusively. If we're not going to focus
454 the new window or hilite it, then we raise it to the top. This will
455 take affect for things that don't get focused like splash screens.
456 Also if you don't have focus_new enabled, then it's going to get
457 raised to the top. Legacy begets legacy I guess?
462 /* this has to happen before we try focus the window, but we want it to
463 happen after the client's stacking has been determined or it looks bad
467 /* use client_focus instead of client_activate cuz client_activate does
468 stuff like switch desktops etc and I'm not interested in all that when
469 a window maps since its not based on an action from the user like
470 clicking a window to activate it. so keep the new window out of the way
473 /* if using focus_delay, stop the timer now so that focus doesn't
475 event_halt_focus_delay();
479 /* client_activate does this but we aren't using it so we have to do it
481 if (screen_showing_desktop)
482 screen_show_desktop(FALSE);
484 /* add to client list/map */
485 client_list = g_list_append(client_list, self);
486 g_hash_table_insert(window_map, &self->window, self);
488 /* this has to happen after we're in the client_list */
489 if (STRUT_EXISTS(self->strut))
490 screen_update_areas();
492 /* update the list hints */
495 ob_debug("Managed window 0x%lx (%s)\n", window, self->class);
498 void client_unmanage_all()
500 while (client_list != NULL)
501 client_unmanage(client_list->data);
504 void client_unmanage(ObClient *self)
509 ob_debug("Unmanaging window: %lx (%s) (%s)\n", self->window, self->class,
510 self->title ? self->title : "");
512 g_assert(self != NULL);
514 /* we dont want events no more. do this before hiding the frame so we
515 don't generate more events */
516 XSelectInput(ob_display, self->window, NoEventMask);
518 frame_hide(self->frame);
519 /* flush to send the hide to the server quickly */
522 if (focus_client == self) {
523 /* ignore enter events from the unmap so it doesnt mess with the focus
525 event_ignore_queued_enters();
529 keyboard_grab_for_client(self, FALSE);
530 mouse_grab_for_client(self, FALSE);
532 /* remove the window from our save set */
533 XChangeSaveSet(ob_display, self->window, SetModeDelete);
535 /* update the focus lists */
536 focus_order_remove(self);
538 client_list = g_list_remove(client_list, self);
539 stacking_remove(self);
540 g_hash_table_remove(window_map, &self->window);
542 /* once the client is out of the list, update the struts to remove its
544 if (STRUT_EXISTS(self->strut))
545 screen_update_areas();
547 for (it = client_destructors; it; it = g_slist_next(it)) {
548 Destructor *d = it->data;
549 d->func(self, d->data);
552 /* tell our parent(s) that we're gone */
553 if (self->transient_for == OB_TRAN_GROUP) { /* transient of group */
554 for (it = self->group->members; it; it = g_slist_next(it))
555 if (it->data != self)
556 ((ObClient*)it->data)->transients =
557 g_slist_remove(((ObClient*)it->data)->transients, self);
558 } else if (self->transient_for) { /* transient of window */
559 self->transient_for->transients =
560 g_slist_remove(self->transient_for->transients, self);
563 /* tell our transients that we're gone */
564 for (it = self->transients; it; it = g_slist_next(it)) {
565 if (((ObClient*)it->data)->transient_for != OB_TRAN_GROUP) {
566 ((ObClient*)it->data)->transient_for = NULL;
567 client_calc_layer(it->data);
571 /* remove from its group */
573 group_remove(self->group, self);
577 /* restore the window's original geometry so it is not lost */
581 if (self->fullscreen)
582 a = self->pre_fullscreen_area;
583 else if (self->max_horz || self->max_vert) {
584 if (self->max_horz) {
585 a.x = self->pre_max_area.x;
586 a.width = self->pre_max_area.width;
588 if (self->max_vert) {
589 a.y = self->pre_max_area.y;
590 a.height = self->pre_max_area.height;
594 /* give the client its border back */
595 client_toggle_border(self, TRUE);
597 self->fullscreen = self->max_horz = self->max_vert = FALSE;
598 self->decorations = 0; /* unmanaged windows have no decor */
600 client_move_resize(self, a.x, a.y, a.width, a.height);
603 /* reparent the window out of the frame, and free the frame */
604 frame_release_client(self->frame, self);
607 if (ob_state() != OB_STATE_EXITING) {
608 /* these values should not be persisted across a window
610 PROP_ERASE(self->window, net_wm_desktop);
611 PROP_ERASE(self->window, net_wm_state);
612 PROP_ERASE(self->window, wm_state);
614 /* if we're left in an unmapped state, the client wont be mapped. this
615 is bad, since we will no longer be managing the window on restart */
616 XMapWindow(ob_display, self->window);
619 ob_debug("Unmanaged window 0x%lx\n", self->window);
621 /* free all data allocated in the client struct */
622 g_slist_free(self->transients);
623 for (j = 0; j < self->nicons; ++j)
624 g_free(self->icons[j].data);
625 if (self->nicons > 0)
628 g_free(self->icon_title);
632 g_free(self->client_machine);
633 g_free(self->sm_client_id);
636 /* update the list hints */
640 static ObAppSettings *client_get_settings_state(ObClient *self)
642 ObAppSettings *settings = NULL;
645 for (it = config_per_app_settings; it; it = g_slist_next(it)) {
646 ObAppSettings *app = it->data;
648 if ((app->name && !app->class && !strcmp(app->name, self->name))
649 || (app->class && !app->name && !strcmp(app->class, self->class))
650 || (app->class && app->name && !strcmp(app->class, self->class)
651 && !strcmp(app->name, self->name)))
653 ob_debug("Window matching: %s\n", app->name);
654 /* Match if no role was specified in the per app setting, or if the
655 * string matches the beginning of the role, since apps like to set
656 * the role to things like browser-window-23c4b2f */
658 || !strncmp(app->role, self->role, strlen(app->role)))
668 if (settings->shade != -1)
669 self->shaded = !!settings->shade;
670 if (settings->decor != -1)
671 self->undecorated = !settings->decor;
672 if (settings->iconic != -1)
673 self->iconic = !!settings->iconic;
674 if (settings->skip_pager != -1)
675 self->skip_pager = !!settings->skip_pager;
676 if (settings->skip_taskbar != -1)
677 self->skip_taskbar = !!settings->skip_taskbar;
679 if (settings->max_vert != -1)
680 self->max_vert = !!settings->max_vert;
681 if (settings->max_horz != -1)
682 self->max_vert = !!settings->max_horz;
684 if (settings->fullscreen != -1)
685 self->fullscreen = !!settings->fullscreen;
687 if (settings->desktop < screen_num_desktops
688 || settings->desktop == DESKTOP_ALL)
689 self->desktop = settings->desktop;
691 if (settings->layer == -1) {
695 else if (settings->layer == 0) {
699 else if (settings->layer == 1) {
707 static void client_restore_session_state(ObClient *self)
711 if (!(it = session_state_find(self)))
714 self->session = it->data;
716 RECT_SET_POINT(self->area, self->session->x, self->session->y);
717 self->positioned = PPosition;
718 if (self->session->w > 0)
719 self->area.width = self->session->w;
720 if (self->session->h > 0)
721 self->area.height = self->session->h;
722 XResizeWindow(ob_display, self->window,
723 self->area.width, self->area.height);
725 self->desktop = (self->session->desktop == DESKTOP_ALL ?
726 self->session->desktop :
727 MIN(screen_num_desktops - 1, self->session->desktop));
728 PROP_SET32(self->window, net_wm_desktop, cardinal, self->desktop);
730 self->shaded = self->session->shaded;
731 self->iconic = self->session->iconic;
732 self->skip_pager = self->session->skip_pager;
733 self->skip_taskbar = self->session->skip_taskbar;
734 self->fullscreen = self->session->fullscreen;
735 self->above = self->session->above;
736 self->below = self->session->below;
737 self->max_horz = self->session->max_horz;
738 self->max_vert = self->session->max_vert;
741 static void client_restore_session_stacking(ObClient *self)
745 if (!self->session) return;
747 it = g_list_find(session_saved_state, self->session);
748 for (it = g_list_previous(it); it; it = g_list_previous(it)) {
751 for (cit = client_list; cit; cit = g_list_next(cit))
752 if (session_state_cmp(it->data, cit->data))
755 client_calc_layer(self);
756 stacking_below(CLIENT_AS_WINDOW(self),
757 CLIENT_AS_WINDOW(cit->data));
763 void client_move_onscreen(ObClient *self, gboolean rude)
765 gint x = self->area.x;
766 gint y = self->area.y;
767 if (client_find_onscreen(self, &x, &y,
768 self->frame->area.width,
769 self->frame->area.height, rude)) {
770 client_move(self, x, y);
774 gboolean client_find_onscreen(ObClient *self, gint *x, gint *y, gint w, gint h,
778 gint ox = *x, oy = *y;
780 frame_client_gravity(self->frame, x, y); /* get where the frame
783 /* XXX watch for xinerama dead areas */
784 /* This makes sure windows aren't entirely outside of the screen so you
785 can't see them at all.
786 It makes sure 10% of the window is on the screen at least. At don't let
787 it move itself off the top of the screen, which would hide the titlebar
788 on you. (The user can still do this if they want too, it's only limiting
791 if (client_normal(self)) {
792 a = screen_area(self->desktop);
793 if (!self->strut.right &&
794 *x + self->frame->area.width/10 >= a->x + a->width - 1)
795 *x = a->x + a->width - self->frame->area.width/10;
796 if (!self->strut.bottom &&
797 *y + self->frame->area.height/10 >= a->y + a->height - 1)
798 *y = a->y + a->height - self->frame->area.height/10;
799 if (!self->strut.left && *x + self->frame->area.width*9/10 - 1 < a->x)
800 *x = a->x - self->frame->area.width*9/10;
801 if (!self->strut.top && *y + self->frame->area.height*9/10 - 1 < a->y)
802 *y = a->y - self->frame->area.width*9/10;
805 /* This here doesn't let windows even a pixel outside the screen,
806 * when called from client_manage, programs placing themselves are
807 * forced completely onscreen, while things like
808 * xterm -geometry resolution-width/2 will work fine. Trying to
809 * place it completely offscreen will be handled in the above code.
810 * Sorry for this confused comment, i am tired. */
812 /* avoid the xinerama monitor divide while we're at it,
813 * remember to fix the placement stuff to avoid it also and
814 * then remove this XXX */
815 a = screen_area_monitor(self->desktop, client_monitor(self));
816 /* dont let windows map into the strut unless they
817 are bigger than the available area */
819 if (!self->strut.left && *x < a->x) *x = a->x;
820 if (!self->strut.right && *x + w > a->x + a->width)
821 *x = a->x + a->width - w;
823 if (h <= a->height) {
824 if (!self->strut.top && *y < a->y) *y = a->y;
825 if (!self->strut.bottom && *y + h > a->y + a->height)
826 *y = a->y + a->height - h;
830 frame_frame_gravity(self->frame, x, y); /* get where the client
833 return ox != *x || oy != *y;
836 static void client_toggle_border(ObClient *self, gboolean show)
838 /* adjust our idea of where the client is, based on its border. When the
839 border is removed, the client should now be considered to be in a
841 when re-adding the border to the client, the same operation needs to be
843 gint oldx = self->area.x, oldy = self->area.y;
844 gint x = oldx, y = oldy;
845 switch(self->gravity) {
847 case NorthWestGravity:
849 case SouthWestGravity:
851 case NorthEastGravity:
853 case SouthEastGravity:
854 if (show) x -= self->border_width * 2;
855 else x += self->border_width * 2;
862 if (show) x -= self->border_width;
863 else x += self->border_width;
866 switch(self->gravity) {
868 case NorthWestGravity:
870 case NorthEastGravity:
872 case SouthWestGravity:
874 case SouthEastGravity:
875 if (show) y -= self->border_width * 2;
876 else y += self->border_width * 2;
883 if (show) y -= self->border_width;
884 else y += self->border_width;
891 XSetWindowBorderWidth(ob_display, self->window, self->border_width);
893 /* set border_width to 0 because there is no border to add into
894 calculations anymore */
895 self->border_width = 0;
897 XSetWindowBorderWidth(ob_display, self->window, 0);
901 static void client_get_all(ObClient *self)
903 client_get_area(self);
904 client_get_mwm_hints(self);
906 /* The transient hint is used to pick a type, but the type can also affect
907 transiency (dialogs are always made transients of their group if they
908 have one). This is Havoc's idea, but it is needed to make some apps
909 work right (eg tsclient). */
910 client_update_transient_for(self);
911 client_get_type(self);/* this can change the mwmhints for special cases */
912 client_get_state(self);
913 client_update_transient_for(self);
915 client_update_wmhints(self);
916 client_get_startup_id(self);
917 client_get_desktop(self);/* uses transient data/group/startup id if a
918 desktop is not specified */
919 client_get_shaped(self);
921 client_get_layer(self); /* if layer hasn't been specified, get it from
922 other sources if possible */
925 /* a couple type-based defaults for new windows */
927 /* this makes sure that these windows appear on all desktops */
928 if (self->type == OB_CLIENT_TYPE_DESKTOP)
929 self->desktop = DESKTOP_ALL;
932 client_update_protocols(self);
934 client_get_gravity(self); /* get the attribute gravity */
935 client_update_normal_hints(self); /* this may override the attribute
938 /* got the type, the mwmhints, the protocols, and the normal hints
939 (min/max sizes), so we're ready to set up the decorations/functions */
940 client_setup_decor_and_functions(self);
942 client_get_client_machine(self);
943 client_update_title(self);
944 client_update_class(self);
945 client_update_sm_client_id(self);
946 client_update_strut(self);
947 client_update_icons(self);
948 client_update_user_time(self);
951 static void client_get_startup_id(ObClient *self)
953 if (!(PROP_GETS(self->window, net_startup_id, utf8, &self->startup_id)))
955 PROP_GETS(self->group->leader,
956 net_startup_id, utf8, &self->startup_id);
959 static void client_get_area(ObClient *self)
961 XWindowAttributes wattrib;
964 ret = XGetWindowAttributes(ob_display, self->window, &wattrib);
965 g_assert(ret != BadWindow);
967 RECT_SET(self->area, wattrib.x, wattrib.y, wattrib.width, wattrib.height);
968 POINT_SET(self->root_pos, wattrib.x, wattrib.y);
969 self->border_width = wattrib.border_width;
971 ob_debug("client area: %d %d %d %d\n", wattrib.x, wattrib.y,
972 wattrib.width, wattrib.height);
975 static void client_get_desktop(ObClient *self)
977 guint32 d = screen_num_desktops; /* an always-invalid value */
979 if (PROP_GET32(self->window, net_wm_desktop, cardinal, &d)) {
980 if (d >= screen_num_desktops && d != DESKTOP_ALL)
981 self->desktop = screen_num_desktops - 1;
985 gboolean trdesk = FALSE;
987 if (self->transient_for) {
988 if (self->transient_for != OB_TRAN_GROUP) {
989 self->desktop = self->transient_for->desktop;
994 for (it = self->group->members; it; it = g_slist_next(it))
995 if (it->data != self &&
996 !((ObClient*)it->data)->transient_for) {
997 self->desktop = ((ObClient*)it->data)->desktop;
1004 /* try get from the startup-notification protocol */
1005 if (sn_get_desktop(self->startup_id, &self->desktop)) {
1006 if (self->desktop >= screen_num_desktops &&
1007 self->desktop != DESKTOP_ALL)
1008 self->desktop = screen_num_desktops - 1;
1010 /* defaults to the current desktop */
1011 self->desktop = screen_desktop;
1014 if (self->desktop != d) {
1015 /* set the desktop hint, to make sure that it always exists */
1016 PROP_SET32(self->window, net_wm_desktop, cardinal, self->desktop);
1020 static void client_get_layer(ObClient *self)
1022 if (!(self->above || self->below)) {
1024 /* apply stuff from the group */
1028 for (it = self->group->members; it; it = g_slist_next(it)) {
1029 ObClient *c = it->data;
1030 if (c != self && !client_search_transient(self, c) &&
1031 client_normal(self) && client_normal(c))
1034 (c->above ? 1 : (c->below ? -1 : 0)));
1048 g_assert_not_reached();
1055 static void client_get_state(ObClient *self)
1060 if (PROP_GETA32(self->window, net_wm_state, atom, &state, &num)) {
1062 for (i = 0; i < num; ++i) {
1063 if (state[i] == prop_atoms.net_wm_state_modal)
1065 else if (state[i] == prop_atoms.net_wm_state_shaded)
1066 self->shaded = TRUE;
1067 else if (state[i] == prop_atoms.net_wm_state_hidden)
1068 self->iconic = TRUE;
1069 else if (state[i] == prop_atoms.net_wm_state_skip_taskbar)
1070 self->skip_taskbar = TRUE;
1071 else if (state[i] == prop_atoms.net_wm_state_skip_pager)
1072 self->skip_pager = TRUE;
1073 else if (state[i] == prop_atoms.net_wm_state_fullscreen)
1074 self->fullscreen = TRUE;
1075 else if (state[i] == prop_atoms.net_wm_state_maximized_vert)
1076 self->max_vert = TRUE;
1077 else if (state[i] == prop_atoms.net_wm_state_maximized_horz)
1078 self->max_horz = TRUE;
1079 else if (state[i] == prop_atoms.net_wm_state_above)
1081 else if (state[i] == prop_atoms.net_wm_state_below)
1083 else if (state[i] == prop_atoms.net_wm_state_demands_attention)
1084 self->demands_attention = TRUE;
1085 else if (state[i] == prop_atoms.ob_wm_state_undecorated)
1086 self->undecorated = TRUE;
1093 static void client_get_shaped(ObClient *self)
1095 self->shaped = FALSE;
1097 if (extensions_shape) {
1102 XShapeSelectInput(ob_display, self->window, ShapeNotifyMask);
1104 XShapeQueryExtents(ob_display, self->window, &s, &foo,
1105 &foo, &ufoo, &ufoo, &foo, &foo, &foo, &ufoo,
1107 self->shaped = (s != 0);
1112 void client_update_transient_for(ObClient *self)
1115 ObClient *target = NULL;
1117 if (XGetTransientForHint(ob_display, self->window, &t)) {
1118 self->transient = TRUE;
1119 if (t != self->window) { /* cant be transient to itself! */
1120 target = g_hash_table_lookup(window_map, &t);
1121 /* if this happens then we need to check for it*/
1122 g_assert(target != self);
1123 if (target && !WINDOW_IS_CLIENT(target)) {
1124 /* this can happen when a dialog is a child of
1125 a dockapp, for example */
1129 /* THIS IS SO ANNOYING ! ! ! ! Let me explain.... have a seat..
1131 Setting the transient_for to Root is actually illegal, however
1132 applications from time have done this to specify transient for
1135 Now you can do that by being a TYPE_DIALOG and not setting
1136 the transient_for hint at all on your window. But people still
1137 use Root, and Kwin is very strange in this regard.
1139 KWin 3.0 will not consider windows with transient_for set to
1140 Root as transient for their group *UNLESS* they are also modal.
1141 In that case, it will make them transient for the group. This
1142 leads to all sorts of weird behavior from KDE apps which are
1143 only tested in KWin. I'd like to follow their behavior just to
1144 make this work right with KDE stuff, but that seems wrong.
1146 if (!target && self->group) {
1147 /* not transient to a client, see if it is transient for a
1149 if (t == RootWindow(ob_display, ob_screen)) {
1150 /* window is a transient for its group! */
1151 target = OB_TRAN_GROUP;
1155 } else if (self->group) {
1156 if (self->type == OB_CLIENT_TYPE_DIALOG ||
1157 self->type == OB_CLIENT_TYPE_TOOLBAR ||
1158 self->type == OB_CLIENT_TYPE_MENU ||
1159 self->type == OB_CLIENT_TYPE_UTILITY)
1161 self->transient = TRUE;
1162 target = OB_TRAN_GROUP;
1165 self->transient = FALSE;
1167 /* if anything has changed... */
1168 if (target != self->transient_for) {
1169 if (self->transient_for == OB_TRAN_GROUP) { /* transient of group */
1172 /* remove from old parents */
1173 for (it = self->group->members; it; it = g_slist_next(it)) {
1174 ObClient *c = it->data;
1175 if (c != self && !c->transient_for)
1176 c->transients = g_slist_remove(c->transients, self);
1178 } else if (self->transient_for != NULL) { /* transient of window */
1179 /* remove from old parent */
1180 self->transient_for->transients =
1181 g_slist_remove(self->transient_for->transients, self);
1183 self->transient_for = target;
1184 if (self->transient_for == OB_TRAN_GROUP) { /* transient of group */
1187 /* add to new parents */
1188 for (it = self->group->members; it; it = g_slist_next(it)) {
1189 ObClient *c = it->data;
1190 if (c != self && !c->transient_for)
1191 c->transients = g_slist_append(c->transients, self);
1194 /* remove all transients which are in the group, that causes
1195 circlular pointer hell of doom */
1196 for (it = self->group->members; it; it = g_slist_next(it)) {
1198 for (sit = self->transients; sit; sit = next) {
1199 next = g_slist_next(sit);
1200 if (sit->data == it->data)
1202 g_slist_delete_link(self->transients, sit);
1205 } else if (self->transient_for != NULL) { /* transient of window */
1206 /* add to new parent */
1207 self->transient_for->transients =
1208 g_slist_append(self->transient_for->transients, self);
1213 static void client_get_mwm_hints(ObClient *self)
1218 self->mwmhints.flags = 0; /* default to none */
1220 if (PROP_GETA32(self->window, motif_wm_hints, motif_wm_hints,
1222 if (num >= OB_MWM_ELEMENTS) {
1223 self->mwmhints.flags = hints[0];
1224 self->mwmhints.functions = hints[1];
1225 self->mwmhints.decorations = hints[2];
1231 void client_get_type(ObClient *self)
1238 if (PROP_GETA32(self->window, net_wm_window_type, atom, &val, &num)) {
1239 /* use the first value that we know about in the array */
1240 for (i = 0; i < num; ++i) {
1241 if (val[i] == prop_atoms.net_wm_window_type_desktop)
1242 self->type = OB_CLIENT_TYPE_DESKTOP;
1243 else if (val[i] == prop_atoms.net_wm_window_type_dock)
1244 self->type = OB_CLIENT_TYPE_DOCK;
1245 else if (val[i] == prop_atoms.net_wm_window_type_toolbar)
1246 self->type = OB_CLIENT_TYPE_TOOLBAR;
1247 else if (val[i] == prop_atoms.net_wm_window_type_menu)
1248 self->type = OB_CLIENT_TYPE_MENU;
1249 else if (val[i] == prop_atoms.net_wm_window_type_utility)
1250 self->type = OB_CLIENT_TYPE_UTILITY;
1251 else if (val[i] == prop_atoms.net_wm_window_type_splash)
1252 self->type = OB_CLIENT_TYPE_SPLASH;
1253 else if (val[i] == prop_atoms.net_wm_window_type_dialog)
1254 self->type = OB_CLIENT_TYPE_DIALOG;
1255 else if (val[i] == prop_atoms.net_wm_window_type_normal)
1256 self->type = OB_CLIENT_TYPE_NORMAL;
1257 else if (val[i] == prop_atoms.kde_net_wm_window_type_override) {
1258 /* prevent this window from getting any decor or
1260 self->mwmhints.flags &= (OB_MWM_FLAG_FUNCTIONS |
1261 OB_MWM_FLAG_DECORATIONS);
1262 self->mwmhints.decorations = 0;
1263 self->mwmhints.functions = 0;
1265 if (self->type != (ObClientType) -1)
1266 break; /* grab the first legit type */
1271 if (self->type == (ObClientType) -1) {
1272 /*the window type hint was not set, which means we either classify
1273 ourself as a normal window or a dialog, depending on if we are a
1275 if (self->transient)
1276 self->type = OB_CLIENT_TYPE_DIALOG;
1278 self->type = OB_CLIENT_TYPE_NORMAL;
1282 void client_update_protocols(ObClient *self)
1285 guint num_return, i;
1287 self->focus_notify = FALSE;
1288 self->delete_window = FALSE;
1290 if (PROP_GETA32(self->window, wm_protocols, atom, &proto, &num_return)) {
1291 for (i = 0; i < num_return; ++i) {
1292 if (proto[i] == prop_atoms.wm_delete_window) {
1293 /* this means we can request the window to close */
1294 self->delete_window = TRUE;
1295 } else if (proto[i] == prop_atoms.wm_take_focus)
1296 /* if this protocol is requested, then the window will be
1297 notified whenever we want it to receive focus */
1298 self->focus_notify = TRUE;
1304 static void client_get_gravity(ObClient *self)
1306 XWindowAttributes wattrib;
1309 ret = XGetWindowAttributes(ob_display, self->window, &wattrib);
1310 g_assert(ret != BadWindow);
1311 self->gravity = wattrib.win_gravity;
1314 void client_update_normal_hints(ObClient *self)
1318 gint oldgravity = self->gravity;
1321 self->min_ratio = 0.0f;
1322 self->max_ratio = 0.0f;
1323 SIZE_SET(self->size_inc, 1, 1);
1324 SIZE_SET(self->base_size, 0, 0);
1325 SIZE_SET(self->min_size, 0, 0);
1326 SIZE_SET(self->max_size, G_MAXINT, G_MAXINT);
1328 /* get the hints from the window */
1329 if (XGetWMNormalHints(ob_display, self->window, &size, &ret)) {
1330 /* normal windows can't request placement! har har
1331 if (!client_normal(self))
1333 self->positioned = (size.flags & (PPosition|USPosition));
1335 if (size.flags & PWinGravity) {
1336 self->gravity = size.win_gravity;
1338 /* if the client has a frame, i.e. has already been mapped and
1339 is changing its gravity */
1340 if (self->frame && self->gravity != oldgravity) {
1341 /* move our idea of the client's position based on its new
1343 self->area.x = self->frame->area.x;
1344 self->area.y = self->frame->area.y;
1345 frame_frame_gravity(self->frame, &self->area.x, &self->area.y);
1349 if (size.flags & PAspect) {
1350 if (size.min_aspect.y)
1352 (gfloat) size.min_aspect.x / size.min_aspect.y;
1353 if (size.max_aspect.y)
1355 (gfloat) size.max_aspect.x / size.max_aspect.y;
1358 if (size.flags & PMinSize)
1359 SIZE_SET(self->min_size, size.min_width, size.min_height);
1361 if (size.flags & PMaxSize)
1362 SIZE_SET(self->max_size, size.max_width, size.max_height);
1364 if (size.flags & PBaseSize)
1365 SIZE_SET(self->base_size, size.base_width, size.base_height);
1367 if (size.flags & PResizeInc && size.width_inc && size.height_inc)
1368 SIZE_SET(self->size_inc, size.width_inc, size.height_inc);
1372 void client_setup_decor_and_functions(ObClient *self)
1374 /* start with everything (cept fullscreen) */
1376 (OB_FRAME_DECOR_TITLEBAR |
1377 OB_FRAME_DECOR_HANDLE |
1378 OB_FRAME_DECOR_GRIPS |
1379 OB_FRAME_DECOR_BORDER |
1380 OB_FRAME_DECOR_ICON |
1381 OB_FRAME_DECOR_ALLDESKTOPS |
1382 OB_FRAME_DECOR_ICONIFY |
1383 OB_FRAME_DECOR_MAXIMIZE |
1384 OB_FRAME_DECOR_SHADE |
1385 OB_FRAME_DECOR_CLOSE);
1387 (OB_CLIENT_FUNC_RESIZE |
1388 OB_CLIENT_FUNC_MOVE |
1389 OB_CLIENT_FUNC_ICONIFY |
1390 OB_CLIENT_FUNC_MAXIMIZE |
1391 OB_CLIENT_FUNC_SHADE |
1392 OB_CLIENT_FUNC_CLOSE);
1394 if (!(self->min_size.width < self->max_size.width ||
1395 self->min_size.height < self->max_size.height))
1396 self->functions &= ~OB_CLIENT_FUNC_RESIZE;
1398 switch (self->type) {
1399 case OB_CLIENT_TYPE_NORMAL:
1400 /* normal windows retain all of the possible decorations and
1401 functionality, and are the only windows that you can fullscreen */
1402 self->functions |= OB_CLIENT_FUNC_FULLSCREEN;
1405 case OB_CLIENT_TYPE_DIALOG:
1406 case OB_CLIENT_TYPE_UTILITY:
1407 /* these windows cannot be maximized */
1408 self->functions &= ~OB_CLIENT_FUNC_MAXIMIZE;
1411 case OB_CLIENT_TYPE_MENU:
1412 case OB_CLIENT_TYPE_TOOLBAR:
1413 /* these windows get less functionality */
1414 self->functions &= ~(OB_CLIENT_FUNC_ICONIFY | OB_CLIENT_FUNC_RESIZE);
1417 case OB_CLIENT_TYPE_DESKTOP:
1418 case OB_CLIENT_TYPE_DOCK:
1419 case OB_CLIENT_TYPE_SPLASH:
1420 /* none of these windows are manipulated by the window manager */
1421 self->decorations = 0;
1422 self->functions = 0;
1426 /* Mwm Hints are applied subtractively to what has already been chosen for
1427 decor and functionality */
1428 if (self->mwmhints.flags & OB_MWM_FLAG_DECORATIONS) {
1429 if (! (self->mwmhints.decorations & OB_MWM_DECOR_ALL)) {
1430 if (! ((self->mwmhints.decorations & OB_MWM_DECOR_HANDLE) ||
1431 (self->mwmhints.decorations & OB_MWM_DECOR_TITLE)))
1433 /* if the mwm hints request no handle or title, then all
1434 decorations are disabled, but keep the border if that's
1436 if (self->mwmhints.decorations & OB_MWM_DECOR_BORDER)
1437 self->decorations = OB_FRAME_DECOR_BORDER;
1439 self->decorations = 0;
1444 if (self->mwmhints.flags & OB_MWM_FLAG_FUNCTIONS) {
1445 if (! (self->mwmhints.functions & OB_MWM_FUNC_ALL)) {
1446 if (! (self->mwmhints.functions & OB_MWM_FUNC_RESIZE))
1447 self->functions &= ~OB_CLIENT_FUNC_RESIZE;
1448 if (! (self->mwmhints.functions & OB_MWM_FUNC_MOVE))
1449 self->functions &= ~OB_CLIENT_FUNC_MOVE;
1450 /* dont let mwm hints kill any buttons
1451 if (! (self->mwmhints.functions & OB_MWM_FUNC_ICONIFY))
1452 self->functions &= ~OB_CLIENT_FUNC_ICONIFY;
1453 if (! (self->mwmhints.functions & OB_MWM_FUNC_MAXIMIZE))
1454 self->functions &= ~OB_CLIENT_FUNC_MAXIMIZE;
1456 /* dont let mwm hints kill the close button
1457 if (! (self->mwmhints.functions & MwmFunc_Close))
1458 self->functions &= ~OB_CLIENT_FUNC_CLOSE; */
1462 if (!(self->functions & OB_CLIENT_FUNC_SHADE))
1463 self->decorations &= ~OB_FRAME_DECOR_SHADE;
1464 if (!(self->functions & OB_CLIENT_FUNC_ICONIFY))
1465 self->decorations &= ~OB_FRAME_DECOR_ICONIFY;
1466 if (!(self->functions & OB_CLIENT_FUNC_RESIZE))
1467 self->decorations &= ~OB_FRAME_DECOR_GRIPS;
1469 /* can't maximize without moving/resizing */
1470 if (!((self->functions & OB_CLIENT_FUNC_MAXIMIZE) &&
1471 (self->functions & OB_CLIENT_FUNC_MOVE) &&
1472 (self->functions & OB_CLIENT_FUNC_RESIZE))) {
1473 self->functions &= ~OB_CLIENT_FUNC_MAXIMIZE;
1474 self->decorations &= ~OB_FRAME_DECOR_MAXIMIZE;
1477 /* kill the handle on fully maxed windows */
1478 if (self->max_vert && self->max_horz)
1479 self->decorations &= ~OB_FRAME_DECOR_HANDLE;
1481 /* finally, the user can have requested no decorations, which overrides
1482 everything (but doesnt give it a border if it doesnt have one) */
1483 if (self->undecorated) {
1484 if (config_theme_keepborder)
1485 self->decorations &= OB_FRAME_DECOR_BORDER;
1487 self->decorations = 0;
1490 /* if we don't have a titlebar, then we cannot shade! */
1491 if (!(self->decorations & OB_FRAME_DECOR_TITLEBAR))
1492 self->functions &= ~OB_CLIENT_FUNC_SHADE;
1494 /* now we need to check against rules for the client's current state */
1495 if (self->fullscreen) {
1496 self->functions &= (OB_CLIENT_FUNC_CLOSE |
1497 OB_CLIENT_FUNC_FULLSCREEN |
1498 OB_CLIENT_FUNC_ICONIFY);
1499 self->decorations = 0;
1502 client_change_allowed_actions(self);
1505 /* adjust the client's decorations, etc. */
1506 client_reconfigure(self);
1510 static void client_change_allowed_actions(ObClient *self)
1515 /* desktop windows are kept on all desktops */
1516 if (self->type != OB_CLIENT_TYPE_DESKTOP)
1517 actions[num++] = prop_atoms.net_wm_action_change_desktop;
1519 if (self->functions & OB_CLIENT_FUNC_SHADE)
1520 actions[num++] = prop_atoms.net_wm_action_shade;
1521 if (self->functions & OB_CLIENT_FUNC_CLOSE)
1522 actions[num++] = prop_atoms.net_wm_action_close;
1523 if (self->functions & OB_CLIENT_FUNC_MOVE)
1524 actions[num++] = prop_atoms.net_wm_action_move;
1525 if (self->functions & OB_CLIENT_FUNC_ICONIFY)
1526 actions[num++] = prop_atoms.net_wm_action_minimize;
1527 if (self->functions & OB_CLIENT_FUNC_RESIZE)
1528 actions[num++] = prop_atoms.net_wm_action_resize;
1529 if (self->functions & OB_CLIENT_FUNC_FULLSCREEN)
1530 actions[num++] = prop_atoms.net_wm_action_fullscreen;
1531 if (self->functions & OB_CLIENT_FUNC_MAXIMIZE) {
1532 actions[num++] = prop_atoms.net_wm_action_maximize_horz;
1533 actions[num++] = prop_atoms.net_wm_action_maximize_vert;
1536 PROP_SETA32(self->window, net_wm_allowed_actions, atom, actions, num);
1538 /* make sure the window isn't breaking any rules now */
1540 if (!(self->functions & OB_CLIENT_FUNC_SHADE) && self->shaded) {
1541 if (self->frame) client_shade(self, FALSE);
1542 else self->shaded = FALSE;
1544 if (!(self->functions & OB_CLIENT_FUNC_ICONIFY) && self->iconic) {
1545 if (self->frame) client_iconify(self, FALSE, TRUE);
1546 else self->iconic = FALSE;
1548 if (!(self->functions & OB_CLIENT_FUNC_FULLSCREEN) && self->fullscreen) {
1549 if (self->frame) client_fullscreen(self, FALSE);
1550 else self->fullscreen = FALSE;
1552 if (!(self->functions & OB_CLIENT_FUNC_MAXIMIZE) && (self->max_horz ||
1554 if (self->frame) client_maximize(self, FALSE, 0);
1555 else self->max_vert = self->max_horz = FALSE;
1559 void client_reconfigure(ObClient *self)
1561 /* by making this pass FALSE for user, we avoid the emacs event storm where
1562 every configurenotify causes an update in its normal hints, i think this
1563 is generally what we want anyways... */
1564 client_configure(self, OB_CORNER_TOPLEFT, self->area.x, self->area.y,
1565 self->area.width, self->area.height, FALSE, TRUE);
1568 void client_update_wmhints(ObClient *self)
1573 /* assume a window takes input if it doesnt specify */
1574 self->can_focus = TRUE;
1576 if ((hints = XGetWMHints(ob_display, self->window)) != NULL) {
1577 if (hints->flags & InputHint)
1578 self->can_focus = hints->input;
1580 /* only do this when first managing the window *AND* when we aren't
1582 if (ob_state() != OB_STATE_STARTING && self->frame == NULL)
1583 if (hints->flags & StateHint)
1584 self->iconic = hints->initial_state == IconicState;
1586 if (!(hints->flags & WindowGroupHint))
1587 hints->window_group = None;
1589 /* did the group state change? */
1590 if (hints->window_group !=
1591 (self->group ? self->group->leader : None)) {
1592 /* remove from the old group if there was one */
1593 if (self->group != NULL) {
1594 /* remove transients of the group */
1595 for (it = self->group->members; it; it = g_slist_next(it))
1596 self->transients = g_slist_remove(self->transients,
1599 /* remove myself from parents in the group */
1600 if (self->transient_for == OB_TRAN_GROUP) {
1601 for (it = self->group->members; it;
1602 it = g_slist_next(it))
1604 ObClient *c = it->data;
1606 if (c != self && !c->transient_for)
1607 c->transients = g_slist_remove(c->transients,
1612 group_remove(self->group, self);
1615 if (hints->window_group != None) {
1616 self->group = group_add(hints->window_group, self);
1618 /* i can only have transients from the group if i am not
1620 if (!self->transient_for) {
1621 /* add other transients of the group that are already
1623 for (it = self->group->members; it;
1624 it = g_slist_next(it))
1626 ObClient *c = it->data;
1627 if (c != self && c->transient_for == OB_TRAN_GROUP)
1629 g_slist_append(self->transients, c);
1634 /* because the self->transient flag wont change from this call,
1635 we don't need to update the window's type and such, only its
1636 transient_for, and the transients lists of other windows in
1637 the group may be affected */
1638 client_update_transient_for(self);
1641 /* the WM_HINTS can contain an icon */
1642 client_update_icons(self);
1648 void client_update_title(ObClient *self)
1651 gchar *visible = NULL;
1653 g_free(self->title);
1656 if (!PROP_GETS(self->window, net_wm_name, utf8, &data)) {
1657 /* try old x stuff */
1658 if (!(PROP_GETS(self->window, wm_name, locale, &data)
1659 || PROP_GETS(self->window, wm_name, utf8, &data))) {
1660 if (self->transient) {
1662 GNOME alert windows are not given titles:
1663 http://developer.gnome.org/projects/gup/hig/draft_hig_new/windows-alert.html
1665 data = g_strdup("");
1667 data = g_strdup("Unnamed Window");
1671 if (self->client_machine) {
1672 visible = g_strdup_printf("%s (%s)", data, self->client_machine);
1677 PROP_SETS(self->window, net_wm_visible_name, visible);
1678 self->title = visible;
1681 frame_adjust_title(self->frame);
1683 /* update the icon title */
1685 g_free(self->icon_title);
1688 if (!PROP_GETS(self->window, net_wm_icon_name, utf8, &data))
1689 /* try old x stuff */
1690 if (!(PROP_GETS(self->window, wm_icon_name, locale, &data) ||
1691 PROP_GETS(self->window, wm_icon_name, utf8, &data)))
1692 data = g_strdup(self->title);
1694 PROP_SETS(self->window, net_wm_visible_icon_name, data);
1695 self->icon_title = data;
1698 void client_update_class(ObClient *self)
1703 if (self->name) g_free(self->name);
1704 if (self->class) g_free(self->class);
1705 if (self->role) g_free(self->role);
1707 self->name = self->class = self->role = NULL;
1709 if (PROP_GETSS(self->window, wm_class, locale, &data)) {
1711 self->name = g_strdup(data[0]);
1713 self->class = g_strdup(data[1]);
1718 if (PROP_GETS(self->window, wm_window_role, locale, &s))
1721 if (self->name == NULL) self->name = g_strdup("");
1722 if (self->class == NULL) self->class = g_strdup("");
1723 if (self->role == NULL) self->role = g_strdup("");
1726 void client_update_strut(ObClient *self)
1730 gboolean got = FALSE;
1733 if (PROP_GETA32(self->window, net_wm_strut_partial, cardinal,
1737 STRUT_PARTIAL_SET(strut,
1738 data[0], data[2], data[1], data[3],
1739 data[4], data[5], data[8], data[9],
1740 data[6], data[7], data[10], data[11]);
1746 PROP_GETA32(self->window, net_wm_strut, cardinal, &data, &num)) {
1752 /* use the screen's width/height */
1753 a = screen_physical_area();
1755 STRUT_PARTIAL_SET(strut,
1756 data[0], data[2], data[1], data[3],
1757 a->y, a->y + a->height - 1,
1758 a->x, a->x + a->width - 1,
1759 a->y, a->y + a->height - 1,
1760 a->x, a->x + a->width - 1);
1766 STRUT_PARTIAL_SET(strut, 0, 0, 0, 0,
1767 0, 0, 0, 0, 0, 0, 0, 0);
1769 if (!STRUT_EQUAL(strut, self->strut)) {
1770 self->strut = strut;
1772 /* updating here is pointless while we're being mapped cuz we're not in
1773 the client list yet */
1775 screen_update_areas();
1779 void client_update_icons(ObClient *self)
1785 for (i = 0; i < self->nicons; ++i)
1786 g_free(self->icons[i].data);
1787 if (self->nicons > 0)
1788 g_free(self->icons);
1791 if (PROP_GETA32(self->window, net_wm_icon, cardinal, &data, &num)) {
1792 /* figure out how many valid icons are in here */
1794 while (num - i > 2) {
1798 if (i > num || w*h == 0) break;
1802 self->icons = g_new(ObClientIcon, self->nicons);
1804 /* store the icons */
1806 for (j = 0; j < self->nicons; ++j) {
1809 w = self->icons[j].width = data[i++];
1810 h = self->icons[j].height = data[i++];
1812 if (w*h == 0) continue;
1814 self->icons[j].data = g_new(RrPixel32, w * h);
1815 for (x = 0, y = 0, t = 0; t < w * h; ++t, ++x, ++i) {
1820 self->icons[j].data[t] =
1821 (((data[i] >> 24) & 0xff) << RrDefaultAlphaOffset) +
1822 (((data[i] >> 16) & 0xff) << RrDefaultRedOffset) +
1823 (((data[i] >> 8) & 0xff) << RrDefaultGreenOffset) +
1824 (((data[i] >> 0) & 0xff) << RrDefaultBlueOffset);
1833 if ((hints = XGetWMHints(ob_display, self->window))) {
1834 if (hints->flags & IconPixmapHint) {
1836 self->icons = g_new(ObClientIcon, self->nicons);
1837 xerror_set_ignore(TRUE);
1838 if (!RrPixmapToRGBA(ob_rr_inst,
1840 (hints->flags & IconMaskHint ?
1841 hints->icon_mask : None),
1842 &self->icons[self->nicons-1].width,
1843 &self->icons[self->nicons-1].height,
1844 &self->icons[self->nicons-1].data)){
1845 g_free(&self->icons[self->nicons-1]);
1848 xerror_set_ignore(FALSE);
1855 frame_adjust_icon(self->frame);
1858 void client_update_user_time(ObClient *self)
1862 if (PROP_GET32(self->window, net_wm_user_time, cardinal, &time)) {
1863 /* we set this every time, not just when it grows, because in practice
1864 sometimes time goes backwards! (ntpdate.. yay....) so.. if it goes
1865 backward we don't want all windows to stop focusing. we'll just
1866 assume noone is setting times older than the last one, cuz that
1867 would be pretty stupid anyways
1869 self->user_time = time;
1872 ob_debug("window %s user time %u\n", self->title, time);
1877 static void client_get_client_machine(ObClient *self)
1880 gchar localhost[128];
1882 g_free(self->client_machine);
1884 if (PROP_GETS(self->window, wm_client_machine, locale, &data)) {
1885 gethostname(localhost, 127);
1886 localhost[127] = '\0';
1887 if (strcmp(localhost, data))
1888 self->client_machine = data;
1892 static void client_change_wm_state(ObClient *self)
1897 old = self->wmstate;
1899 if (self->shaded || self->iconic || !self->frame->visible)
1900 self->wmstate = IconicState;
1902 self->wmstate = NormalState;
1904 if (old != self->wmstate) {
1905 PROP_MSG(self->window, kde_wm_change_state,
1906 self->wmstate, 1, 0, 0);
1908 state[0] = self->wmstate;
1910 PROP_SETA32(self->window, wm_state, wm_state, state, 2);
1914 static void client_change_state(ObClient *self)
1916 gulong netstate[11];
1921 netstate[num++] = prop_atoms.net_wm_state_modal;
1923 netstate[num++] = prop_atoms.net_wm_state_shaded;
1925 netstate[num++] = prop_atoms.net_wm_state_hidden;
1926 if (self->skip_taskbar)
1927 netstate[num++] = prop_atoms.net_wm_state_skip_taskbar;
1928 if (self->skip_pager)
1929 netstate[num++] = prop_atoms.net_wm_state_skip_pager;
1930 if (self->fullscreen)
1931 netstate[num++] = prop_atoms.net_wm_state_fullscreen;
1933 netstate[num++] = prop_atoms.net_wm_state_maximized_vert;
1935 netstate[num++] = prop_atoms.net_wm_state_maximized_horz;
1937 netstate[num++] = prop_atoms.net_wm_state_above;
1939 netstate[num++] = prop_atoms.net_wm_state_below;
1940 if (self->demands_attention)
1941 netstate[num++] = prop_atoms.net_wm_state_demands_attention;
1942 if (self->undecorated)
1943 netstate[num++] = prop_atoms.ob_wm_state_undecorated;
1944 PROP_SETA32(self->window, net_wm_state, atom, netstate, num);
1947 frame_adjust_state(self->frame);
1950 ObClient *client_search_focus_tree(ObClient *self)
1955 for (it = self->transients; it; it = g_slist_next(it)) {
1956 if (client_focused(it->data)) return it->data;
1957 if ((ret = client_search_focus_tree(it->data))) return ret;
1962 ObClient *client_search_focus_tree_full(ObClient *self)
1964 if (self->transient_for) {
1965 if (self->transient_for != OB_TRAN_GROUP) {
1966 return client_search_focus_tree_full(self->transient_for);
1969 gboolean recursed = FALSE;
1971 for (it = self->group->members; it; it = g_slist_next(it))
1972 if (!((ObClient*)it->data)->transient_for) {
1974 if ((c = client_search_focus_tree_full(it->data)))
1983 /* this function checks the whole tree, the client_search_focus_tree~
1984 does not, so we need to check this window */
1985 if (client_focused(self))
1987 return client_search_focus_tree(self);
1990 static ObStackingLayer calc_layer(ObClient *self)
1994 if (self->fullscreen &&
1995 (client_focused(self) || client_search_focus_tree(self)))
1996 l = OB_STACKING_LAYER_FULLSCREEN;
1997 else if (self->type == OB_CLIENT_TYPE_DESKTOP)
1998 l = OB_STACKING_LAYER_DESKTOP;
1999 else if (self->type == OB_CLIENT_TYPE_DOCK) {
2000 if (self->below) l = OB_STACKING_LAYER_NORMAL;
2001 else l = OB_STACKING_LAYER_ABOVE;
2003 else if (self->above) l = OB_STACKING_LAYER_ABOVE;
2004 else if (self->below) l = OB_STACKING_LAYER_BELOW;
2005 else l = OB_STACKING_LAYER_NORMAL;
2010 static void client_calc_layer_recursive(ObClient *self, ObClient *orig,
2011 ObStackingLayer min, gboolean raised)
2013 ObStackingLayer old, own;
2017 own = calc_layer(self);
2018 self->layer = MAX(own, min);
2020 for (it = self->transients; it; it = g_slist_next(it))
2021 client_calc_layer_recursive(it->data, orig,
2023 raised ? raised : self->layer != old);
2025 if (!raised && self->layer != old)
2026 if (orig->frame) { /* only restack if the original window is managed */
2027 stacking_remove(CLIENT_AS_WINDOW(self));
2028 stacking_add(CLIENT_AS_WINDOW(self));
2032 void client_calc_layer(ObClient *self)
2039 /* transients take on the layer of their parents */
2040 it = client_search_all_top_parents(self);
2042 for (; it; it = g_slist_next(it))
2043 client_calc_layer_recursive(it->data, orig, 0, FALSE);
2046 gboolean client_should_show(ObClient *self)
2050 if (client_normal(self) && screen_showing_desktop)
2053 if (self->transient_for) {
2054 if (self->transient_for != OB_TRAN_GROUP)
2055 return client_should_show(self->transient_for);
2059 for (it = self->group->members; it; it = g_slist_next(it)) {
2060 ObClient *c = it->data;
2061 if (c != self && !c->transient_for) {
2062 if (client_should_show(c))
2069 if (self->desktop == screen_desktop || self->desktop == DESKTOP_ALL)
2075 void client_show(ObClient *self)
2078 if (client_should_show(self)) {
2079 frame_show(self->frame);
2082 /* According to the ICCCM (sec 4.1.3.1) when a window is not visible, it
2083 needs to be in IconicState. This includes when it is on another
2086 client_change_wm_state(self);
2089 void client_hide(ObClient *self)
2091 if (!client_should_show(self)) {
2092 frame_hide(self->frame);
2095 /* According to the ICCCM (sec 4.1.3.1) when a window is not visible, it
2096 needs to be in IconicState. This includes when it is on another
2099 client_change_wm_state(self);
2102 void client_showhide(ObClient *self)
2105 if (client_should_show(self)) {
2106 frame_show(self->frame);
2109 frame_hide(self->frame);
2112 /* According to the ICCCM (sec 4.1.3.1) when a window is not visible, it
2113 needs to be in IconicState. This includes when it is on another
2116 client_change_wm_state(self);
2119 gboolean client_normal(ObClient *self) {
2120 return ! (self->type == OB_CLIENT_TYPE_DESKTOP ||
2121 self->type == OB_CLIENT_TYPE_DOCK ||
2122 self->type == OB_CLIENT_TYPE_SPLASH);
2125 static void client_apply_startup_state(ObClient *self, gint x, gint y)
2127 gboolean pos = FALSE; /* has the window's position been configured? */
2130 /* save the position, and set self->area for these to use */
2136 /* these are in a carefully crafted order.. */
2139 self->iconic = FALSE;
2140 client_iconify(self, TRUE, FALSE);
2142 if (self->fullscreen) {
2143 self->fullscreen = FALSE;
2144 client_fullscreen(self, TRUE);
2147 if (self->undecorated) {
2148 self->undecorated = FALSE;
2149 client_set_undecorated(self, TRUE);
2152 self->shaded = FALSE;
2153 client_shade(self, TRUE);
2155 if (self->demands_attention) {
2156 self->demands_attention = FALSE;
2157 client_hilite(self, TRUE);
2160 if (self->max_vert && self->max_horz) {
2161 self->max_vert = self->max_horz = FALSE;
2162 client_maximize(self, TRUE, 0);
2164 } else if (self->max_vert) {
2165 self->max_vert = FALSE;
2166 client_maximize(self, TRUE, 2);
2168 } else if (self->max_horz) {
2169 self->max_horz = FALSE;
2170 client_maximize(self, TRUE, 1);
2174 /* if the client didn't get positioned yet, then do so now
2175 call client_move even if the window is not being moved anywhere, because
2176 when we reparent it and decorate it, it is getting moved and we need to
2177 be telling it so with a ConfigureNotify event.
2180 /* use the saved position */
2183 client_move(self, x, y);
2186 /* nothing to do for the other states:
2195 void client_try_configure(ObClient *self, ObCorner anchor,
2196 gint *x, gint *y, gint *w, gint *h,
2197 gint *logicalw, gint *logicalh,
2200 Rect desired_area = {*x, *y, *w, *h};
2202 /* make the frame recalculate its dimentions n shit without changing
2203 anything visible for real, this way the constraints below can work with
2204 the updated frame dimensions. */
2205 frame_adjust_area(self->frame, TRUE, TRUE, TRUE);
2207 /* work within the prefered sizes given by the window */
2208 if (!(*w == self->area.width && *h == self->area.height)) {
2209 gint basew, baseh, minw, minh;
2211 /* base size is substituted with min size if not specified */
2212 if (self->base_size.width || self->base_size.height) {
2213 basew = self->base_size.width;
2214 baseh = self->base_size.height;
2216 basew = self->min_size.width;
2217 baseh = self->min_size.height;
2219 /* min size is substituted with base size if not specified */
2220 if (self->min_size.width || self->min_size.height) {
2221 minw = self->min_size.width;
2222 minh = self->min_size.height;
2224 minw = self->base_size.width;
2225 minh = self->base_size.height;
2228 /* if this is a user-requested resize, then check against min/max
2231 /* smaller than min size or bigger than max size? */
2232 if (*w > self->max_size.width) *w = self->max_size.width;
2233 if (*w < minw) *w = minw;
2234 if (*h > self->max_size.height) *h = self->max_size.height;
2235 if (*h < minh) *h = minh;
2240 /* keep to the increments */
2241 *w /= self->size_inc.width;
2242 *h /= self->size_inc.height;
2244 /* you cannot resize to nothing */
2245 if (basew + *w < 1) *w = 1 - basew;
2246 if (baseh + *h < 1) *h = 1 - baseh;
2248 /* save the logical size */
2249 *logicalw = self->size_inc.width > 1 ? *w : *w + basew;
2250 *logicalh = self->size_inc.height > 1 ? *h : *h + baseh;
2252 *w *= self->size_inc.width;
2253 *h *= self->size_inc.height;
2258 /* adjust the height to match the width for the aspect ratios.
2259 for this, min size is not substituted for base size ever. */
2260 *w -= self->base_size.width;
2261 *h -= self->base_size.height;
2263 if (!self->fullscreen) {
2264 if (self->min_ratio)
2265 if (*h * self->min_ratio > *w) {
2266 *h = (gint)(*w / self->min_ratio);
2268 /* you cannot resize to nothing */
2271 *w = (gint)(*h * self->min_ratio);
2274 if (self->max_ratio)
2275 if (*h * self->max_ratio < *w) {
2276 *h = (gint)(*w / self->max_ratio);
2278 /* you cannot resize to nothing */
2281 *w = (gint)(*h * self->min_ratio);
2286 *w += self->base_size.width;
2287 *h += self->base_size.height;
2290 /* gets the frame's position */
2291 frame_client_gravity(self->frame, x, y);
2293 /* these positions are frame positions, not client positions */
2295 /* set the size and position if fullscreen */
2296 if (self->fullscreen) {
2300 i = screen_find_monitor(&desired_area);
2301 a = screen_physical_area_monitor(i);
2308 user = FALSE; /* ignore if the client can't be moved/resized when it
2309 is entering fullscreen */
2310 } else if (self->max_horz || self->max_vert) {
2314 i = screen_find_monitor(&desired_area);
2315 a = screen_area_monitor(self->desktop, i);
2317 /* set the size and position if maximized */
2318 if (self->max_horz) {
2320 *w = a->width - self->frame->size.left - self->frame->size.right;
2322 if (self->max_vert) {
2324 *h = a->height - self->frame->size.top - self->frame->size.bottom;
2327 /* maximizing is not allowed if the user can't move+resize the window
2331 /* gets the client's position */
2332 frame_frame_gravity(self->frame, x, y);
2334 /* these override the above states! if you cant move you can't move! */
2336 if (!(self->functions & OB_CLIENT_FUNC_MOVE)) {
2340 if (!(self->functions & OB_CLIENT_FUNC_RESIZE)) {
2341 *w = self->area.width;
2342 *h = self->area.height;
2350 case OB_CORNER_TOPLEFT:
2352 case OB_CORNER_TOPRIGHT:
2353 *x -= *w - self->area.width;
2355 case OB_CORNER_BOTTOMLEFT:
2356 *y -= *h - self->area.height;
2358 case OB_CORNER_BOTTOMRIGHT:
2359 *x -= *w - self->area.width;
2360 *y -= *h - self->area.height;
2366 void client_configure_full(ObClient *self, ObCorner anchor,
2367 gint x, gint y, gint w, gint h,
2368 gboolean user, gboolean final,
2369 gboolean force_reply)
2371 gint oldw, oldh, oldrx, oldry;
2372 gboolean send_resize_client;
2373 gboolean moved = FALSE, resized = FALSE, rootmoved = FALSE;
2374 guint fdecor = self->frame->decorations;
2375 gboolean fhorz = self->frame->max_horz;
2376 gint logicalw, logicalh;
2378 /* find the new x, y, width, and height (and logical size) */
2379 client_try_configure(self, anchor, &x, &y, &w, &h,
2380 &logicalw, &logicalh, user);
2382 /* set the logical size if things changed */
2383 if (!(w == self->area.width && h == self->area.height))
2384 SIZE_SET(self->logical_size, logicalw, logicalh);
2386 /* figure out if we moved or resized or what */
2387 moved = x != self->area.x || y != self->area.y;
2388 resized = w != self->area.width || h != self->area.height;
2390 oldw = self->area.width;
2391 oldh = self->area.height;
2392 RECT_SET(self->area, x, y, w, h);
2394 /* for app-requested resizes, always resize if 'resized' is true.
2395 for user-requested ones, only resize if final is true, or when
2396 resizing in redraw mode */
2397 send_resize_client = ((!user && resized) ||
2399 (resized && config_resize_redraw))));
2401 /* if the client is enlarging, then resize the client before the frame */
2402 if (send_resize_client && user && (w > oldw || h > oldh))
2403 XResizeWindow(ob_display, self->window, MAX(w, oldw), MAX(h, oldh));
2405 /* find the frame's dimensions and move/resize it */
2406 if (self->decorations != fdecor || self->max_horz != fhorz)
2407 moved = resized = TRUE;
2408 if (moved || resized)
2409 frame_adjust_area(self->frame, moved, resized, FALSE);
2411 /* find the client's position relative to the root window */
2412 oldrx = self->root_pos.x;
2413 oldry = self->root_pos.y;
2414 rootmoved = (oldrx != (signed)(self->frame->area.x +
2415 self->frame->size.left -
2416 self->border_width) ||
2417 oldry != (signed)(self->frame->area.y +
2418 self->frame->size.top -
2419 self->border_width));
2421 if (force_reply || ((!user || (user && final)) && rootmoved))
2425 POINT_SET(self->root_pos,
2426 self->frame->area.x + self->frame->size.left -
2428 self->frame->area.y + self->frame->size.top -
2429 self->border_width);
2431 event.type = ConfigureNotify;
2432 event.xconfigure.display = ob_display;
2433 event.xconfigure.event = self->window;
2434 event.xconfigure.window = self->window;
2436 /* root window real coords */
2437 event.xconfigure.x = self->root_pos.x;
2438 event.xconfigure.y = self->root_pos.y;
2439 event.xconfigure.width = w;
2440 event.xconfigure.height = h;
2441 event.xconfigure.border_width = 0;
2442 event.xconfigure.above = self->frame->plate;
2443 event.xconfigure.override_redirect = FALSE;
2444 XSendEvent(event.xconfigure.display, event.xconfigure.window,
2445 FALSE, StructureNotifyMask, &event);
2448 /* if the client is shrinking, then resize the frame before the client */
2449 if (send_resize_client && (!user || (w <= oldw || h <= oldh)))
2450 XResizeWindow(ob_display, self->window, w, h);
2455 void client_fullscreen(ObClient *self, gboolean fs)
2459 if (!(self->functions & OB_CLIENT_FUNC_FULLSCREEN) || /* can't */
2460 self->fullscreen == fs) return; /* already done */
2462 self->fullscreen = fs;
2463 client_change_state(self); /* change the state hints on the client */
2464 client_calc_layer(self); /* and adjust out layer/stacking */
2467 self->pre_fullscreen_area = self->area;
2468 /* if the window is maximized, its area isn't all that meaningful.
2469 save it's premax area instead. */
2470 if (self->max_horz) {
2471 self->pre_fullscreen_area.x = self->pre_max_area.x;
2472 self->pre_fullscreen_area.width = self->pre_max_area.width;
2474 if (self->max_vert) {
2475 self->pre_fullscreen_area.y = self->pre_max_area.y;
2476 self->pre_fullscreen_area.height = self->pre_max_area.height;
2479 /* these are not actually used cuz client_configure will set them
2480 as appropriate when the window is fullscreened */
2485 if (self->pre_fullscreen_area.width > 0 &&
2486 self->pre_fullscreen_area.height > 0)
2488 x = self->pre_fullscreen_area.x;
2489 y = self->pre_fullscreen_area.y;
2490 w = self->pre_fullscreen_area.width;
2491 h = self->pre_fullscreen_area.height;
2492 RECT_SET(self->pre_fullscreen_area, 0, 0, 0, 0);
2494 /* pick some fallbacks... */
2495 a = screen_area_monitor(self->desktop, 0);
2496 x = a->x + a->width / 4;
2497 y = a->y + a->height / 4;
2503 client_setup_decor_and_functions(self);
2505 client_move_resize(self, x, y, w, h);
2507 /* try focus us when we go into fullscreen mode */
2511 static void client_iconify_recursive(ObClient *self,
2512 gboolean iconic, gboolean curdesk)
2515 gboolean changed = FALSE;
2518 if (self->iconic != iconic) {
2519 ob_debug("%sconifying window: 0x%lx\n", (iconic ? "I" : "Uni"),
2523 if (self->functions & OB_CLIENT_FUNC_ICONIFY) {
2524 self->iconic = iconic;
2526 /* update the focus lists.. iconic windows go to the bottom of
2527 the list, put the new iconic window at the 'top of the
2529 focus_order_to_top(self);
2534 self->iconic = iconic;
2537 client_set_desktop(self, screen_desktop, FALSE);
2539 /* this puts it after the current focused window */
2540 focus_order_remove(self);
2541 focus_order_add_new(self);
2548 client_change_state(self);
2549 client_showhide(self);
2550 if (STRUT_EXISTS(self->strut))
2551 screen_update_areas();
2554 /* iconify all direct transients */
2555 for (it = self->transients; it; it = g_slist_next(it))
2556 if (it->data != self)
2557 if (client_is_direct_child(self, it->data))
2558 client_iconify_recursive(it->data, iconic, curdesk);
2561 void client_iconify(ObClient *self, gboolean iconic, gboolean curdesk)
2563 /* move up the transient chain as far as possible first */
2564 self = client_search_top_parent(self);
2565 client_iconify_recursive(self, iconic, curdesk);
2568 void client_maximize(ObClient *self, gboolean max, gint dir)
2572 g_assert(dir == 0 || dir == 1 || dir == 2);
2573 if (!(self->functions & OB_CLIENT_FUNC_MAXIMIZE)) return; /* can't */
2575 /* check if already done */
2577 if (dir == 0 && self->max_horz && self->max_vert) return;
2578 if (dir == 1 && self->max_horz) return;
2579 if (dir == 2 && self->max_vert) return;
2581 if (dir == 0 && !self->max_horz && !self->max_vert) return;
2582 if (dir == 1 && !self->max_horz) return;
2583 if (dir == 2 && !self->max_vert) return;
2586 /* we just tell it to configure in the same place and client_configure
2587 worries about filling the screen with the window */
2590 w = self->area.width;
2591 h = self->area.height;
2594 if ((dir == 0 || dir == 1) && !self->max_horz) { /* horz */
2595 RECT_SET(self->pre_max_area,
2596 self->area.x, self->pre_max_area.y,
2597 self->area.width, self->pre_max_area.height);
2599 if ((dir == 0 || dir == 2) && !self->max_vert) { /* vert */
2600 RECT_SET(self->pre_max_area,
2601 self->pre_max_area.x, self->area.y,
2602 self->pre_max_area.width, self->area.height);
2607 a = screen_area_monitor(self->desktop, 0);
2608 if ((dir == 0 || dir == 1) && self->max_horz) { /* horz */
2609 if (self->pre_max_area.width > 0) {
2610 x = self->pre_max_area.x;
2611 w = self->pre_max_area.width;
2613 RECT_SET(self->pre_max_area, 0, self->pre_max_area.y,
2614 0, self->pre_max_area.height);
2616 /* pick some fallbacks... */
2617 x = a->x + a->width / 4;
2621 if ((dir == 0 || dir == 2) && self->max_vert) { /* vert */
2622 if (self->pre_max_area.height > 0) {
2623 y = self->pre_max_area.y;
2624 h = self->pre_max_area.height;
2626 RECT_SET(self->pre_max_area, self->pre_max_area.x, 0,
2627 self->pre_max_area.width, 0);
2629 /* pick some fallbacks... */
2630 y = a->y + a->height / 4;
2636 if (dir == 0 || dir == 1) /* horz */
2637 self->max_horz = max;
2638 if (dir == 0 || dir == 2) /* vert */
2639 self->max_vert = max;
2641 client_change_state(self); /* change the state hints on the client */
2643 client_setup_decor_and_functions(self);
2645 client_move_resize(self, x, y, w, h);
2648 void client_shade(ObClient *self, gboolean shade)
2650 if ((!(self->functions & OB_CLIENT_FUNC_SHADE) &&
2651 shade) || /* can't shade */
2652 self->shaded == shade) return; /* already done */
2654 self->shaded = shade;
2655 client_change_state(self);
2656 client_change_wm_state(self); /* the window is being hidden/shown */
2657 /* resize the frame to just the titlebar */
2658 frame_adjust_area(self->frame, FALSE, FALSE, FALSE);
2661 void client_close(ObClient *self)
2665 if (!(self->functions & OB_CLIENT_FUNC_CLOSE)) return;
2667 /* in the case that the client provides no means to requesting that it
2668 close, we just kill it */
2669 if (!self->delete_window)
2673 XXX: itd be cool to do timeouts and shit here for killing the client's
2675 like... if the window is around after 5 seconds, then the close button
2676 turns a nice red, and if this function is called again, the client is
2680 ce.xclient.type = ClientMessage;
2681 ce.xclient.message_type = prop_atoms.wm_protocols;
2682 ce.xclient.display = ob_display;
2683 ce.xclient.window = self->window;
2684 ce.xclient.format = 32;
2685 ce.xclient.data.l[0] = prop_atoms.wm_delete_window;
2686 ce.xclient.data.l[1] = event_curtime;
2687 ce.xclient.data.l[2] = 0l;
2688 ce.xclient.data.l[3] = 0l;
2689 ce.xclient.data.l[4] = 0l;
2690 XSendEvent(ob_display, self->window, FALSE, NoEventMask, &ce);
2693 void client_kill(ObClient *self)
2695 XKillClient(ob_display, self->window);
2698 void client_hilite(ObClient *self, gboolean hilite)
2700 if (self->demands_attention == hilite)
2701 return; /* no change */
2703 /* don't allow focused windows to hilite */
2704 self->demands_attention = hilite && !client_focused(self);
2705 if (self->demands_attention)
2706 frame_flash_start(self->frame);
2708 frame_flash_stop(self->frame);
2709 client_change_state(self);
2712 void client_set_desktop_recursive(ObClient *self,
2713 guint target, gboolean donthide)
2718 if (target != self->desktop) {
2720 ob_debug("Setting desktop %u\n", target+1);
2722 g_assert(target < screen_num_desktops || target == DESKTOP_ALL);
2724 /* remove from the old desktop(s) */
2725 focus_order_remove(self);
2727 old = self->desktop;
2728 self->desktop = target;
2729 PROP_SET32(self->window, net_wm_desktop, cardinal, target);
2730 /* the frame can display the current desktop state */
2731 frame_adjust_state(self->frame);
2732 /* 'move' the window to the new desktop */
2734 client_showhide(self);
2735 /* raise if it was not already on the desktop */
2736 if (old != DESKTOP_ALL)
2738 if (STRUT_EXISTS(self->strut))
2739 screen_update_areas();
2741 /* add to the new desktop(s) */
2742 if (config_focus_new)
2743 focus_order_to_top(self);
2745 focus_order_to_bottom(self);
2748 /* move all transients */
2749 for (it = self->transients; it; it = g_slist_next(it))
2750 if (it->data != self)
2751 if (client_is_direct_child(self, it->data))
2752 client_set_desktop_recursive(it->data, target, donthide);
2755 void client_set_desktop(ObClient *self, guint target, gboolean donthide)
2757 self = client_search_top_parent(self);
2758 client_set_desktop_recursive(self, target, donthide);
2761 gboolean client_is_direct_child(ObClient *parent, ObClient *child)
2763 while (child != parent &&
2764 child->transient_for && child->transient_for != OB_TRAN_GROUP)
2765 child = child->transient_for;
2766 return child == parent;
2769 ObClient *client_search_modal_child(ObClient *self)
2774 for (it = self->transients; it; it = g_slist_next(it)) {
2775 ObClient *c = it->data;
2776 if ((ret = client_search_modal_child(c))) return ret;
2777 if (c->modal) return c;
2782 gboolean client_validate(ObClient *self)
2786 XSync(ob_display, FALSE); /* get all events on the server */
2788 if (XCheckTypedWindowEvent(ob_display, self->window, DestroyNotify, &e) ||
2789 XCheckTypedWindowEvent(ob_display, self->window, UnmapNotify, &e)) {
2790 XPutBackEvent(ob_display, &e);
2797 void client_set_wm_state(ObClient *self, glong state)
2799 if (state == self->wmstate) return; /* no change */
2803 client_iconify(self, TRUE, TRUE);
2806 client_iconify(self, FALSE, TRUE);
2811 void client_set_state(ObClient *self, Atom action, glong data1, glong data2)
2813 gboolean shaded = self->shaded;
2814 gboolean fullscreen = self->fullscreen;
2815 gboolean undecorated = self->undecorated;
2816 gboolean max_horz = self->max_horz;
2817 gboolean max_vert = self->max_vert;
2818 gboolean modal = self->modal;
2819 gboolean iconic = self->iconic;
2820 gboolean demands_attention = self->demands_attention;
2823 if (!(action == prop_atoms.net_wm_state_add ||
2824 action == prop_atoms.net_wm_state_remove ||
2825 action == prop_atoms.net_wm_state_toggle))
2826 /* an invalid action was passed to the client message, ignore it */
2829 for (i = 0; i < 2; ++i) {
2830 Atom state = i == 0 ? data1 : data2;
2832 if (!state) continue;
2834 /* if toggling, then pick whether we're adding or removing */
2835 if (action == prop_atoms.net_wm_state_toggle) {
2836 if (state == prop_atoms.net_wm_state_modal)
2837 action = modal ? prop_atoms.net_wm_state_remove :
2838 prop_atoms.net_wm_state_add;
2839 else if (state == prop_atoms.net_wm_state_maximized_vert)
2840 action = self->max_vert ? prop_atoms.net_wm_state_remove :
2841 prop_atoms.net_wm_state_add;
2842 else if (state == prop_atoms.net_wm_state_maximized_horz)
2843 action = self->max_horz ? prop_atoms.net_wm_state_remove :
2844 prop_atoms.net_wm_state_add;
2845 else if (state == prop_atoms.net_wm_state_shaded)
2846 action = shaded ? prop_atoms.net_wm_state_remove :
2847 prop_atoms.net_wm_state_add;
2848 else if (state == prop_atoms.net_wm_state_skip_taskbar)
2849 action = self->skip_taskbar ?
2850 prop_atoms.net_wm_state_remove :
2851 prop_atoms.net_wm_state_add;
2852 else if (state == prop_atoms.net_wm_state_skip_pager)
2853 action = self->skip_pager ?
2854 prop_atoms.net_wm_state_remove :
2855 prop_atoms.net_wm_state_add;
2856 else if (state == prop_atoms.net_wm_state_hidden)
2857 action = self->iconic ?
2858 prop_atoms.net_wm_state_remove :
2859 prop_atoms.net_wm_state_add;
2860 else if (state == prop_atoms.net_wm_state_fullscreen)
2861 action = fullscreen ?
2862 prop_atoms.net_wm_state_remove :
2863 prop_atoms.net_wm_state_add;
2864 else if (state == prop_atoms.net_wm_state_above)
2865 action = self->above ? prop_atoms.net_wm_state_remove :
2866 prop_atoms.net_wm_state_add;
2867 else if (state == prop_atoms.net_wm_state_below)
2868 action = self->below ? prop_atoms.net_wm_state_remove :
2869 prop_atoms.net_wm_state_add;
2870 else if (state == prop_atoms.net_wm_state_demands_attention)
2871 action = self->demands_attention ?
2872 prop_atoms.net_wm_state_remove :
2873 prop_atoms.net_wm_state_add;
2874 else if (state == prop_atoms.ob_wm_state_undecorated)
2875 action = undecorated ? prop_atoms.net_wm_state_remove :
2876 prop_atoms.net_wm_state_add;
2879 if (action == prop_atoms.net_wm_state_add) {
2880 if (state == prop_atoms.net_wm_state_modal) {
2882 } else if (state == prop_atoms.net_wm_state_maximized_vert) {
2884 } else if (state == prop_atoms.net_wm_state_maximized_horz) {
2886 } else if (state == prop_atoms.net_wm_state_shaded) {
2888 } else if (state == prop_atoms.net_wm_state_skip_taskbar) {
2889 self->skip_taskbar = TRUE;
2890 } else if (state == prop_atoms.net_wm_state_skip_pager) {
2891 self->skip_pager = TRUE;
2892 } else if (state == prop_atoms.net_wm_state_hidden) {
2894 } else if (state == prop_atoms.net_wm_state_fullscreen) {
2896 } else if (state == prop_atoms.net_wm_state_above) {
2898 self->below = FALSE;
2899 } else if (state == prop_atoms.net_wm_state_below) {
2900 self->above = FALSE;
2902 } else if (state == prop_atoms.net_wm_state_demands_attention) {
2903 demands_attention = TRUE;
2904 } else if (state == prop_atoms.ob_wm_state_undecorated) {
2908 } else { /* action == prop_atoms.net_wm_state_remove */
2909 if (state == prop_atoms.net_wm_state_modal) {
2911 } else if (state == prop_atoms.net_wm_state_maximized_vert) {
2913 } else if (state == prop_atoms.net_wm_state_maximized_horz) {
2915 } else if (state == prop_atoms.net_wm_state_shaded) {
2917 } else if (state == prop_atoms.net_wm_state_skip_taskbar) {
2918 self->skip_taskbar = FALSE;
2919 } else if (state == prop_atoms.net_wm_state_skip_pager) {
2920 self->skip_pager = FALSE;
2921 } else if (state == prop_atoms.net_wm_state_hidden) {
2923 } else if (state == prop_atoms.net_wm_state_fullscreen) {
2925 } else if (state == prop_atoms.net_wm_state_above) {
2926 self->above = FALSE;
2927 } else if (state == prop_atoms.net_wm_state_below) {
2928 self->below = FALSE;
2929 } else if (state == prop_atoms.net_wm_state_demands_attention) {
2930 demands_attention = FALSE;
2931 } else if (state == prop_atoms.ob_wm_state_undecorated) {
2932 undecorated = FALSE;
2936 if (max_horz != self->max_horz || max_vert != self->max_vert) {
2937 if (max_horz != self->max_horz && max_vert != self->max_vert) {
2939 if (max_horz == max_vert) { /* both going the same way */
2940 client_maximize(self, max_horz, 0);
2942 client_maximize(self, max_horz, 1);
2943 client_maximize(self, max_vert, 2);
2947 if (max_horz != self->max_horz)
2948 client_maximize(self, max_horz, 1);
2950 client_maximize(self, max_vert, 2);
2953 /* change fullscreen state before shading, as it will affect if the window
2955 if (fullscreen != self->fullscreen)
2956 client_fullscreen(self, fullscreen);
2957 if (shaded != self->shaded)
2958 client_shade(self, shaded);
2959 if (undecorated != self->undecorated)
2960 client_set_undecorated(self, undecorated);
2961 if (modal != self->modal) {
2962 self->modal = modal;
2963 /* when a window changes modality, then its stacking order with its
2964 transients needs to change */
2967 if (iconic != self->iconic)
2968 client_iconify(self, iconic, FALSE);
2970 if (demands_attention != self->demands_attention)
2971 client_hilite(self, demands_attention);
2973 client_change_state(self); /* change the hint to reflect these changes */
2976 ObClient *client_focus_target(ObClient *self)
2978 ObClient *child = NULL;
2980 child = client_search_modal_child(self);
2981 if (child) return child;
2985 gboolean client_can_focus(ObClient *self)
2989 /* choose the correct target */
2990 self = client_focus_target(self);
2992 if (!self->frame->visible)
2995 if (!(self->can_focus || self->focus_notify))
2998 /* do a check to see if the window has already been unmapped or destroyed
2999 do this intelligently while watching out for unmaps we've generated
3000 (ignore_unmaps > 0) */
3001 if (XCheckTypedWindowEvent(ob_display, self->window,
3002 DestroyNotify, &ev)) {
3003 XPutBackEvent(ob_display, &ev);
3006 while (XCheckTypedWindowEvent(ob_display, self->window,
3007 UnmapNotify, &ev)) {
3008 if (self->ignore_unmaps) {
3009 self->ignore_unmaps--;
3011 XPutBackEvent(ob_display, &ev);
3019 gboolean client_focus(ObClient *self)
3021 /* choose the correct target */
3022 self = client_focus_target(self);
3024 if (!client_can_focus(self)) {
3025 if (!self->frame->visible) {
3026 /* update the focus lists */
3027 focus_order_to_top(self);
3032 ob_debug_type(OB_DEBUG_FOCUS,
3033 "Focusing client \"%s\" at time %u\n",
3034 self->title, event_curtime);
3036 if (self->can_focus) {
3037 /* This can cause a BadMatch error with CurrentTime, or if an app
3038 passed in a bad time for _NET_WM_ACTIVE_WINDOW. */
3039 xerror_set_ignore(TRUE);
3040 XSetInputFocus(ob_display, self->window, RevertToPointerRoot,
3042 xerror_set_ignore(FALSE);
3045 if (self->focus_notify) {
3047 ce.xclient.type = ClientMessage;
3048 ce.xclient.message_type = prop_atoms.wm_protocols;
3049 ce.xclient.display = ob_display;
3050 ce.xclient.window = self->window;
3051 ce.xclient.format = 32;
3052 ce.xclient.data.l[0] = prop_atoms.wm_take_focus;
3053 ce.xclient.data.l[1] = event_curtime;
3054 ce.xclient.data.l[2] = 0l;
3055 ce.xclient.data.l[3] = 0l;
3056 ce.xclient.data.l[4] = 0l;
3057 XSendEvent(ob_display, self->window, FALSE, NoEventMask, &ce);
3061 ob_debug("%sively focusing %lx at %d\n",
3062 (self->can_focus ? "act" : "pass"),
3063 self->window, (gint) event_curtime);
3066 /* Cause the FocusIn to come back to us. Important for desktop switches,
3067 since otherwise we'll have no FocusIn on the queue and send it off to
3068 the focus_backup. */
3069 XSync(ob_display, FALSE);
3073 void client_activate(ObClient *self, gboolean here, gboolean user)
3075 guint32 last_time = focus_client ? focus_client->user_time : CurrentTime;
3077 /* XXX do some stuff here if user is false to determine if we really want
3078 to activate it or not (a parent or group member is currently
3081 ob_debug("Want to activate window 0x%x with time %u (last time %u), "
3083 self->window, event_curtime, last_time,
3084 (user ? "user" : "application"));
3086 if (!user && event_curtime && last_time &&
3087 !event_time_after(event_curtime, last_time))
3089 client_hilite(self, TRUE);
3091 if (client_normal(self) && screen_showing_desktop)
3092 screen_show_desktop(FALSE);
3094 client_iconify(self, FALSE, here);
3095 if (self->desktop != DESKTOP_ALL &&
3096 self->desktop != screen_desktop) {
3098 client_set_desktop(self, screen_desktop, FALSE);
3100 screen_set_desktop(self->desktop);
3101 } else if (!self->frame->visible)
3102 /* if its not visible for other reasons, then don't mess
3106 client_shade(self, FALSE);
3110 /* we do this an action here. this is rather important. this is because
3111 we want the results from the focus change to take place BEFORE we go
3112 about raising the window. when a fullscreen window loses focus, we
3113 need this or else the raise wont be able to raise above the
3114 to-lose-focus fullscreen window. */
3119 void client_raise(ObClient *self)
3121 action_run_string("Raise", self, CurrentTime);
3124 void client_lower(ObClient *self)
3126 action_run_string("Lower", self, CurrentTime);
3129 gboolean client_focused(ObClient *self)
3131 return self == focus_client;
3134 static ObClientIcon* client_icon_recursive(ObClient *self, gint w, gint h)
3137 /* si is the smallest image >= req */
3138 /* li is the largest image < req */
3139 gulong size, smallest = 0xffffffff, largest = 0, si = 0, li = 0;
3141 if (!self->nicons) {
3142 ObClientIcon *parent = NULL;
3144 if (self->transient_for) {
3145 if (self->transient_for != OB_TRAN_GROUP)
3146 parent = client_icon_recursive(self->transient_for, w, h);
3149 for (it = self->group->members; it; it = g_slist_next(it)) {
3150 ObClient *c = it->data;
3151 if (c != self && !c->transient_for) {
3152 if ((parent = client_icon_recursive(c, w, h)))
3162 for (i = 0; i < self->nicons; ++i) {
3163 size = self->icons[i].width * self->icons[i].height;
3164 if (size < smallest && size >= (unsigned)(w * h)) {
3168 if (size > largest && size <= (unsigned)(w * h)) {
3173 if (largest == 0) /* didnt find one smaller than the requested size */
3174 return &self->icons[si];
3175 return &self->icons[li];
3178 const ObClientIcon* client_icon(ObClient *self, gint w, gint h)
3181 static ObClientIcon deficon;
3183 if (!(ret = client_icon_recursive(self, w, h))) {
3184 deficon.width = deficon.height = 48;
3185 deficon.data = ob_rr_theme->def_win_icon;
3191 void client_set_layer(ObClient *self, gint layer)
3195 self->above = FALSE;
3196 } else if (layer == 0) {
3197 self->below = self->above = FALSE;
3199 self->below = FALSE;
3202 client_calc_layer(self);
3203 client_change_state(self); /* reflect this in the state hints */
3206 void client_set_undecorated(ObClient *self, gboolean undecorated)
3208 if (self->undecorated != undecorated) {
3209 self->undecorated = undecorated;
3210 client_setup_decor_and_functions(self);
3211 /* Make sure the client knows it might have moved. Maybe there is a
3212 * better way of doing this so only one client_configure is sent, but
3213 * since 125 of these are sent per second when moving the window (with
3214 * user = FALSE) i doubt it matters much.
3216 client_configure(self, OB_CORNER_TOPLEFT, self->area.x, self->area.y,
3217 self->area.width, self->area.height, TRUE, TRUE);
3218 client_change_state(self); /* reflect this in the state hints */
3222 guint client_monitor(ObClient *self)
3224 return screen_find_monitor(&self->frame->area);
3227 ObClient *client_search_top_parent(ObClient *self)
3229 while (self->transient_for && self->transient_for != OB_TRAN_GROUP)
3230 self = self->transient_for;
3234 GSList *client_search_all_top_parents(ObClient *self)
3238 /* move up the direct transient chain as far as possible */
3239 while (self->transient_for && self->transient_for != OB_TRAN_GROUP)
3240 self = self->transient_for;
3242 if (!self->transient_for)
3243 ret = g_slist_prepend(ret, self);
3247 g_assert(self->group);
3249 for (it = self->group->members; it; it = g_slist_next(it)) {
3250 ObClient *c = it->data;
3252 if (!c->transient_for && client_normal(c))
3253 ret = g_slist_prepend(ret, c);
3256 if (ret == NULL) /* no group parents */
3257 ret = g_slist_prepend(ret, self);
3263 ObClient *client_search_focus_parent(ObClient *self)
3265 if (self->transient_for) {
3266 if (self->transient_for != OB_TRAN_GROUP) {
3267 if (client_focused(self->transient_for))
3268 return self->transient_for;
3272 for (it = self->group->members; it; it = g_slist_next(it)) {
3273 ObClient *c = it->data;
3275 /* checking transient_for prevents infinate loops! */
3276 if (c != self && !c->transient_for)
3277 if (client_focused(c))
3286 ObClient *client_search_parent(ObClient *self, ObClient *search)
3288 if (self->transient_for) {
3289 if (self->transient_for != OB_TRAN_GROUP) {
3290 if (self->transient_for == search)
3295 for (it = self->group->members; it; it = g_slist_next(it)) {
3296 ObClient *c = it->data;
3298 /* checking transient_for prevents infinate loops! */
3299 if (c != self && !c->transient_for)
3309 ObClient *client_search_transient(ObClient *self, ObClient *search)
3313 for (sit = self->transients; sit; sit = g_slist_next(sit)) {
3314 if (sit->data == search)
3316 if (client_search_transient(sit->data, search))
3322 void client_update_sm_client_id(ObClient *self)
3324 g_free(self->sm_client_id);
3325 self->sm_client_id = NULL;
3327 if (!PROP_GETS(self->window, sm_client_id, locale, &self->sm_client_id) &&
3329 PROP_GETS(self->group->leader, sm_client_id, locale,
3330 &self->sm_client_id);
3333 #define WANT_EDGE(cur, c) \
3336 if(!client_normal(cur)) \
3338 if(screen_desktop != cur->desktop && cur->desktop != DESKTOP_ALL) \
3342 if(cur->layer < c->layer && !config_resist_layers_below) \
3345 #define HIT_EDGE(my_edge_start, my_edge_end, his_edge_start, his_edge_end) \
3346 if ((his_edge_start >= my_edge_start && \
3347 his_edge_start <= my_edge_end) || \
3348 (my_edge_start >= his_edge_start && \
3349 my_edge_start <= his_edge_end)) \
3352 /* finds the nearest edge in the given direction from the current client
3353 * note to self: the edge is the -frame- edge (the actual one), not the
3356 gint client_directional_edge_search(ObClient *c, ObDirection dir, gboolean hang)
3358 gint dest, monitor_dest;
3359 gint my_edge_start, my_edge_end, my_offset;
3366 a = screen_area(c->desktop);
3367 monitor = screen_area_monitor(c->desktop, client_monitor(c));
3370 case OB_DIRECTION_NORTH:
3371 my_edge_start = c->frame->area.x;
3372 my_edge_end = c->frame->area.x + c->frame->area.width;
3373 my_offset = c->frame->area.y + (hang ? c->frame->area.height : 0);
3375 /* default: top of screen */
3376 dest = a->y + (hang ? c->frame->area.height : 0);
3377 monitor_dest = monitor->y + (hang ? c->frame->area.height : 0);
3378 /* if the monitor edge comes before the screen edge, */
3379 /* use that as the destination instead. (For xinerama) */
3380 if (monitor_dest != dest && my_offset > monitor_dest)
3381 dest = monitor_dest;
3383 for(it = client_list; it && my_offset != dest; it = g_list_next(it)) {
3384 gint his_edge_start, his_edge_end, his_offset;
3385 ObClient *cur = it->data;
3389 his_edge_start = cur->frame->area.x;
3390 his_edge_end = cur->frame->area.x + cur->frame->area.width;
3391 his_offset = cur->frame->area.y +
3392 (hang ? 0 : cur->frame->area.height);
3394 if(his_offset + 1 > my_offset)
3397 if(his_offset < dest)
3400 HIT_EDGE(my_edge_start, my_edge_end, his_edge_start, his_edge_end)
3403 case OB_DIRECTION_SOUTH:
3404 my_edge_start = c->frame->area.x;
3405 my_edge_end = c->frame->area.x + c->frame->area.width;
3406 my_offset = c->frame->area.y + (hang ? 0 : c->frame->area.height);
3408 /* default: bottom of screen */
3409 dest = a->y + a->height - (hang ? c->frame->area.height : 0);
3410 monitor_dest = monitor->y + monitor->height -
3411 (hang ? c->frame->area.height : 0);
3412 /* if the monitor edge comes before the screen edge, */
3413 /* use that as the destination instead. (For xinerama) */
3414 if (monitor_dest != dest && my_offset < monitor_dest)
3415 dest = monitor_dest;
3417 for(it = client_list; it && my_offset != dest; it = g_list_next(it)) {
3418 gint his_edge_start, his_edge_end, his_offset;
3419 ObClient *cur = it->data;
3423 his_edge_start = cur->frame->area.x;
3424 his_edge_end = cur->frame->area.x + cur->frame->area.width;
3425 his_offset = cur->frame->area.y +
3426 (hang ? cur->frame->area.height : 0);
3429 if(his_offset - 1 < my_offset)
3432 if(his_offset > dest)
3435 HIT_EDGE(my_edge_start, my_edge_end, his_edge_start, his_edge_end)
3438 case OB_DIRECTION_WEST:
3439 my_edge_start = c->frame->area.y;
3440 my_edge_end = c->frame->area.y + c->frame->area.height;
3441 my_offset = c->frame->area.x + (hang ? c->frame->area.width : 0);
3443 /* default: leftmost egde of screen */
3444 dest = a->x + (hang ? c->frame->area.width : 0);
3445 monitor_dest = monitor->x + (hang ? c->frame->area.width : 0);
3446 /* if the monitor edge comes before the screen edge, */
3447 /* use that as the destination instead. (For xinerama) */
3448 if (monitor_dest != dest && my_offset > monitor_dest)
3449 dest = monitor_dest;
3451 for(it = client_list; it && my_offset != dest; it = g_list_next(it)) {
3452 gint his_edge_start, his_edge_end, his_offset;
3453 ObClient *cur = it->data;
3457 his_edge_start = cur->frame->area.y;
3458 his_edge_end = cur->frame->area.y + cur->frame->area.height;
3459 his_offset = cur->frame->area.x +
3460 (hang ? 0 : cur->frame->area.width);
3462 if(his_offset + 1 > my_offset)
3465 if(his_offset < dest)
3468 HIT_EDGE(my_edge_start, my_edge_end, his_edge_start, his_edge_end)
3471 case OB_DIRECTION_EAST:
3472 my_edge_start = c->frame->area.y;
3473 my_edge_end = c->frame->area.y + c->frame->area.height;
3474 my_offset = c->frame->area.x + (hang ? 0 : c->frame->area.width);
3476 /* default: rightmost edge of screen */
3477 dest = a->x + a->width - (hang ? c->frame->area.width : 0);
3478 monitor_dest = monitor->x + monitor->width -
3479 (hang ? c->frame->area.width : 0);
3480 /* if the monitor edge comes before the screen edge, */
3481 /* use that as the destination instead. (For xinerama) */
3482 if (monitor_dest != dest && my_offset < monitor_dest)
3483 dest = monitor_dest;
3485 for(it = client_list; it && my_offset != dest; it = g_list_next(it)) {
3486 gint his_edge_start, his_edge_end, his_offset;
3487 ObClient *cur = it->data;
3491 his_edge_start = cur->frame->area.y;
3492 his_edge_end = cur->frame->area.y + cur->frame->area.height;
3493 his_offset = cur->frame->area.x +
3494 (hang ? cur->frame->area.width : 0);
3496 if(his_offset - 1 < my_offset)
3499 if(his_offset > dest)
3502 HIT_EDGE(my_edge_start, my_edge_end, his_edge_start, his_edge_end)
3505 case OB_DIRECTION_NORTHEAST:
3506 case OB_DIRECTION_SOUTHEAST:
3507 case OB_DIRECTION_NORTHWEST:
3508 case OB_DIRECTION_SOUTHWEST:
3509 /* not implemented */
3511 g_assert_not_reached();
3512 dest = 0; /* suppress warning */
3517 ObClient* client_under_pointer()
3521 ObClient *ret = NULL;
3523 if (screen_pointer_pos(&x, &y)) {
3524 for (it = stacking_list; it; it = g_list_next(it)) {
3525 if (WINDOW_IS_CLIENT(it->data)) {
3526 ObClient *c = WINDOW_AS_CLIENT(it->data);
3527 if (c->frame->visible &&
3528 RECT_CONTAINS(c->frame->area, x, y)) {
3538 gboolean client_has_group_siblings(ObClient *self)
3540 return self->group && self->group->members->next;