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"
40 #include "menuframe.h"
43 #include "render/render.h"
50 #include <X11/Xutil.h>
52 /*! The event mask to grab on client windows */
53 #define CLIENT_EVENTMASK (PropertyChangeMask | StructureNotifyMask | \
56 #define CLIENT_NOPROPAGATEMASK (ButtonPressMask | ButtonReleaseMask | \
61 ObClientCallback func;
65 GList *client_list = NULL;
67 static GSList *client_destroy_notifies = NULL;
69 static void client_get_all(ObClient *self, gboolean real);
70 static void client_get_startup_id(ObClient *self);
71 static void client_get_session_ids(ObClient *self);
72 static void client_get_area(ObClient *self);
73 static void client_get_desktop(ObClient *self);
74 static void client_get_state(ObClient *self);
75 static void client_get_shaped(ObClient *self);
76 static void client_get_mwm_hints(ObClient *self);
77 static void client_get_colormap(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,
82 gint x, gint y, gint w, gint h);
83 static void client_restore_session_state(ObClient *self);
84 static gboolean client_restore_session_stacking(ObClient *self);
85 static ObAppSettings *client_get_settings_state(ObClient *self);
86 static void client_update_transient_tree(ObClient *self,
87 ObGroup *oldgroup, ObGroup *newgroup,
90 static void client_present(ObClient *self, gboolean here, gboolean raise);
91 static GSList *client_search_all_top_parents_internal(ObClient *self,
93 ObStackingLayer layer);
94 static void client_call_notifies(ObClient *self, GSList *list);
96 void client_startup(gboolean reconfig)
103 void client_shutdown(gboolean reconfig)
105 if (reconfig) return;
108 static void client_call_notifies(ObClient *self, GSList *list)
112 for (it = list; it; it = g_slist_next(it)) {
113 ClientCallback *d = it->data;
114 d->func(self, d->data);
118 void client_add_destroy_notify(ObClientCallback func, gpointer data)
120 ClientCallback *d = g_new(ClientCallback, 1);
123 client_destroy_notifies = g_slist_prepend(client_destroy_notifies, d);
126 void client_remove_destroy_notify(ObClientCallback func)
130 for (it = client_destroy_notifies; it; it = g_slist_next(it)) {
131 ClientCallback *d = it->data;
132 if (d->func == func) {
134 client_destroy_notifies =
135 g_slist_delete_link(client_destroy_notifies, it);
141 void client_set_list()
143 Window *windows, *win_it;
145 guint size = g_list_length(client_list);
147 /* create an array of the window ids */
149 windows = g_new(Window, size);
151 for (it = client_list; it; it = g_list_next(it), ++win_it)
152 *win_it = ((ObClient*)it->data)->window;
156 PROP_SETA32(RootWindow(ob_display, ob_screen),
157 net_client_list, window, (gulong*)windows, size);
166 void client_foreach_transient(ObClient *self, ObClientForeachFunc func, gpointer data)
170 for (it = self->transients; it; it = g_slist_next(it)) {
171 if (!func(it->data, data)) return;
172 client_foreach_transient(it->data, func, data);
176 void client_foreach_ancestor(ObClient *self, ObClientForeachFunc func, gpointer data)
178 if (self->transient_for) {
179 if (self->transient_for != OB_TRAN_GROUP) {
180 if (!func(self->transient_for, data)) return;
181 client_foreach_ancestor(self->transient_for, func, data);
185 for (it = self->group->members; it; it = g_slist_next(it))
186 if (it->data != self &&
187 !((ObClient*)it->data)->transient_for) {
188 if (!func(it->data, data)) return;
189 client_foreach_ancestor(it->data, func, data);
196 void client_manage_all()
201 XWindowAttributes attrib;
203 XQueryTree(ob_display, RootWindow(ob_display, ob_screen),
204 &w, &w, &children, &nchild);
206 /* remove all icon windows from the list */
207 for (i = 0; i < nchild; i++) {
208 if (children[i] == None) continue;
209 wmhints = XGetWMHints(ob_display, children[i]);
211 if ((wmhints->flags & IconWindowHint) &&
212 (wmhints->icon_window != children[i]))
213 for (j = 0; j < nchild; j++)
214 if (children[j] == wmhints->icon_window) {
222 for (i = 0; i < nchild; ++i) {
223 if (children[i] == None)
225 if (XGetWindowAttributes(ob_display, children[i], &attrib)) {
226 if (attrib.override_redirect) continue;
228 if (attrib.map_state != IsUnmapped)
229 client_manage(children[i]);
235 void client_manage(Window window)
239 XWindowAttributes attrib;
240 XSetWindowAttributes attrib_set;
242 gboolean activate = FALSE;
243 ObAppSettings *settings;
244 gint placex, placey, placew, placeh;
245 gboolean transient = FALSE;
249 /* check if it has already been unmapped by the time we started
250 mapping. the grab does a sync so we don't have to here */
251 if (XCheckTypedWindowEvent(ob_display, window, DestroyNotify, &e) ||
252 XCheckTypedWindowEvent(ob_display, window, UnmapNotify, &e))
254 XPutBackEvent(ob_display, &e);
256 ob_debug("Trying to manage unmapped window. Aborting that.\n");
258 return; /* don't manage it */
261 /* make sure it isn't an override-redirect window */
262 if (!XGetWindowAttributes(ob_display, window, &attrib) ||
263 attrib.override_redirect)
266 return; /* don't manage it */
269 /* is the window a docking app */
270 if ((wmhint = XGetWMHints(ob_display, window))) {
271 if ((wmhint->flags & StateHint) &&
272 wmhint->initial_state == WithdrawnState)
274 dock_add(window, wmhint);
282 ob_debug("Managing window: 0x%lx\n", window);
284 /* choose the events we want to receive on the CLIENT window */
285 attrib_set.event_mask = CLIENT_EVENTMASK;
286 attrib_set.do_not_propagate_mask = CLIENT_NOPROPAGATEMASK;
287 XChangeWindowAttributes(ob_display, window,
288 CWEventMask|CWDontPropagate, &attrib_set);
290 /* create the ObClient struct, and populate it from the hints on the
292 self = g_new0(ObClient, 1);
293 self->obwin.type = Window_Client;
294 self->window = window;
296 /* non-zero defaults */
297 self->wmstate = WithdrawnState; /* make sure it gets updated first time */
298 self->gravity = NorthWestGravity;
299 self->desktop = screen_num_desktops; /* always an invalid value */
300 self->user_time = focus_client ? focus_client->user_time : CurrentTime;
302 /* get all the stuff off the window */
303 client_get_all(self, TRUE);
305 /* specify that if we exit, the window should not be destroyed and
306 should be reparented back to root automatically */
307 XChangeSaveSet(ob_display, window, SetModeInsert);
309 /* create the decoration frame for the client window */
310 self->frame = frame_new(self);
312 frame_grab_client(self->frame);
314 /* we've grabbed everything and set everything that we need to at mapping
318 /* per-app settings override stuff from client_get_all, and return the
319 settings for other uses too. the returned settings is a shallow copy,
320 that needs to be freed with g_free(). */
321 settings = client_get_settings_state(self);
322 /* the session should get the last say thought */
323 client_restore_session_state(self);
325 /* now we have all of the window's information so we can set this up */
326 client_setup_decor_and_functions(self, FALSE);
329 Time t = sn_app_started(self->startup_id, self->class);
330 if (t) self->user_time = t;
333 /* do this after we have a frame.. it uses the frame to help determine the
334 WM_STATE to apply. */
335 client_change_state(self);
337 /* add ourselves to the focus order */
338 focus_order_add_new(self);
340 /* do this to add ourselves to the stacking list in a non-intrusive way */
341 client_calc_layer(self);
343 /* focus the new window? */
344 if (ob_state() != OB_STATE_STARTING &&
345 (!self->session || self->session->focused) &&
347 /* this means focus=true for window is same as config_focus_new=true */
348 ((config_focus_new || (settings && settings->focus == 1)) ||
349 client_search_focus_tree_full(self)) &&
350 /* this checks for focus=false for the window */
351 (!settings || settings->focus != 0) &&
352 /* note the check against Type_Normal/Dialog, not client_normal(self),
353 which would also include other types. in this case we want more
354 strict rules for focus */
355 (self->type == OB_CLIENT_TYPE_NORMAL ||
356 self->type == OB_CLIENT_TYPE_DIALOG))
361 /* adjust the frame to the client's size before showing or placing
363 frame_adjust_area(self->frame, FALSE, TRUE, FALSE);
364 frame_adjust_client_area(self->frame);
366 /* where the frame was placed is where the window was originally */
367 placex = self->area.x;
368 placey = self->area.y;
369 placew = self->area.width;
370 placeh = self->area.height;
372 /* figure out placement for the window if the window is new */
373 if (ob_state() == OB_STATE_RUNNING) {
374 ob_debug("Positioned: %s @ %d %d\n",
375 (!self->positioned ? "no" :
376 (self->positioned == PPosition ? "program specified" :
377 (self->positioned == USPosition ? "user specified" :
378 (self->positioned == (PPosition | USPosition) ?
379 "program + user specified" :
380 "BADNESS !?")))), placex, placey);
382 ob_debug("Sized: %s @ %d %d\n",
383 (!self->sized ? "no" :
384 (self->sized == PSize ? "program specified" :
385 (self->sized == USSize ? "user specified" :
386 (self->sized == (PSize | USSize) ?
387 "program + user specified" :
388 "BADNESS !?")))), placew, placeh);
390 transient = place_client(self, &placex, &placey, settings);
392 /* make sure the window is visible. */
393 client_find_onscreen(self, &placex, &placey, placew, placeh,
394 /* non-normal clients has less rules, and
395 windows that are being restored from a
396 session do also. we can assume you want
397 it back where you saved it. Clients saying
398 they placed themselves are subjected to
399 harder rules, ones that are placed by
400 place.c or by the user are allowed partially
401 off-screen and on xinerama divides (ie,
402 it is up to the placement routines to avoid
403 the xinerama divides) */
405 (!(self->positioned & USPosition) &&
406 client_normal(self) &&
410 /* if the window isn't user-sized, then make it fit inside
411 the visible screen area on its monitor. Use basically the same rules
412 for forcing the window on screen in the client_find_onscreen call.
414 do this after place_client, it chooses the monitor! */
416 (!(self->sized & USSize) &&
417 client_normal(self) &&
420 /* make a copy to modify */
421 Rect a = *screen_area_monitor(self->desktop, client_monitor(self));
423 /* shrink by the frame's area */
424 a.width -= self->frame->size.left + self->frame->size.right;
425 a.height -= self->frame->size.top + self->frame->size.bottom;
427 /* fit the window inside the area */
428 if (placew > a.width || self->area.height > a.height) {
429 placew = MAX(MIN(MIN(self->area.width, a.width),
430 self->max_size.width),
431 self->min_size.width);
432 placeh = MAX(MIN(MIN(self->area.height, a.height),
433 self->max_size.height),
434 self->min_size.height);
436 ob_debug("setting window size to %dx%d\n",
437 self->area.width, self->area.height);
442 ob_debug("placing window 0x%x at %d, %d with size %d x %d. "
443 "some restrictions may apply\n",
444 self->window, placex, placey, placew, placeh);
446 ob_debug(" but session requested %d, %d %d x %d instead, "
448 self->session->x, self->session->y,
449 self->session->w, self->session->h);
451 /* do this after the window is placed, so the premax/prefullscreen numbers
454 this also places the window
456 client_apply_startup_state(self, placex, placey, placew, placeh);
459 guint32 last_time = focus_client ?
460 focus_client->user_time : CurrentTime;
462 /* This is focus stealing prevention */
463 ob_debug_type(OB_DEBUG_FOCUS,
464 "Want to focus new window 0x%x with time %u "
466 self->window, self->user_time, last_time);
468 /* if it's on another desktop */
469 if (!(self->desktop == screen_desktop || self->desktop == DESKTOP_ALL)
470 && /* the timestamp is from before you changed desktops */
471 self->user_time && screen_desktop_user_time &&
472 !event_time_after(self->user_time, screen_desktop_user_time))
475 ob_debug_type(OB_DEBUG_FOCUS,
476 "Not focusing the window because its on another "
479 /* If something is focused, and it's not our relative... */
480 else if (focus_client && client_search_focus_tree_full(self) == NULL)
482 /* If time stamp is old, don't steal focus */
483 if (self->user_time && last_time &&
484 !event_time_after(self->user_time, last_time))
487 ob_debug_type(OB_DEBUG_FOCUS,
488 "Not focusing the window because the time is "
491 /* If its a transient (and parents aren't focused) and the time
492 is ambiguous (either the current focus target doesn't have
493 a timestamp, or they are the same (we probably inherited it
495 else if (client_has_parent(self) &&
496 (!last_time || self->user_time == last_time))
499 ob_debug_type(OB_DEBUG_FOCUS,
500 "Not focusing the window because it is a "
501 "transient, and the time is very ambiguous\n");
503 /* Don't steal focus from globally active clients.
504 I stole this idea from KWin. It seems nice.
506 else if (!(focus_client->can_focus ||
507 focus_client->focus_notify))
510 ob_debug_type(OB_DEBUG_FOCUS,
511 "Not focusing the window because a globally "
512 "active client has focus\n");
514 /* Don't move focus if it's not going to go to this window
516 else if (client_focus_target(self) != self) {
518 ob_debug_type(OB_DEBUG_FOCUS,
519 "Not focusing the window because another window "
520 "would get the focus anyway\n");
525 ob_debug_type(OB_DEBUG_FOCUS,
526 "Focus stealing prevention activated for %s with "
527 "time %u (last time %u)\n",
528 self->title, self->user_time, last_time);
529 /* if the client isn't focused, then hilite it so the user
531 client_hilite(self, TRUE);
535 /* This may look rather odd. Well it's because new windows are added
536 to the stacking order non-intrusively. If we're not going to focus
537 the new window or hilite it, then we raise it to the top. This will
538 take affect for things that don't get focused like splash screens.
539 Also if you don't have focus_new enabled, then it's going to get
540 raised to the top. Legacy begets legacy I guess?
542 if (!client_restore_session_stacking(self))
543 stacking_raise(CLIENT_AS_WINDOW(self));
546 mouse_grab_for_client(self, TRUE);
548 /* this has to happen before we try focus the window, but we want it to
549 happen after the client's stacking has been determined or it looks bad
554 gboolean stacked = client_restore_session_stacking(self);
555 client_present(self, FALSE, !stacked);
558 /* add to client list/map */
559 client_list = g_list_append(client_list, self);
560 g_hash_table_insert(window_map, &self->window, self);
562 /* this has to happen after we're in the client_list */
563 if (STRUT_EXISTS(self->strut))
564 screen_update_areas();
566 /* update the list hints */
569 /* free the ObAppSettings shallow copy */
572 ob_debug("Managed window 0x%lx plate 0x%x (%s)\n",
573 window, self->frame->plate, self->class);
579 ObClient *client_fake_manage(Window window)
582 ObAppSettings *settings;
584 ob_debug("Pretend-managing window: %lx\n", window);
586 /* do this minimal stuff to figure out the client's decorations */
588 self = g_new0(ObClient, 1);
589 self->window = window;
591 client_get_all(self, FALSE);
592 /* per-app settings override stuff, and return the settings for other
593 uses too. this returns a shallow copy that needs to be freed */
594 settings = client_get_settings_state(self);
596 client_setup_decor_and_functions(self, FALSE);
598 /* create the decoration frame for the client window and adjust its size */
599 self->frame = frame_new(self);
600 frame_adjust_area(self->frame, FALSE, TRUE, TRUE);
602 ob_debug("gave extents left %d right %d top %d bottom %d\n",
603 self->frame->size.left, self->frame->size.right,
604 self->frame->size.top, self->frame->size.bottom);
606 /* free the ObAppSettings shallow copy */
612 void client_unmanage_all()
614 while (client_list != NULL)
615 client_unmanage(client_list->data);
618 void client_unmanage(ObClient *self)
623 ob_debug("Unmanaging window: 0x%x plate 0x%x (%s) (%s)\n",
624 self->window, self->frame->plate,
625 self->class, self->title ? self->title : "");
627 g_assert(self != NULL);
629 /* we dont want events no more. do this before hiding the frame so we
630 don't generate more events */
631 XSelectInput(ob_display, self->window, NoEventMask);
633 frame_hide(self->frame);
634 /* flush to send the hide to the server quickly */
637 /* ignore enter events from the unmap so it doesnt mess with the
639 event_ignore_all_queued_enters();
641 mouse_grab_for_client(self, FALSE);
643 /* remove the window from our save set */
644 XChangeSaveSet(ob_display, self->window, SetModeDelete);
646 /* kill the property windows */
647 propwin_remove(self->user_time_window, OB_PROPWIN_USER_TIME, self);
649 /* update the focus lists */
650 focus_order_remove(self);
651 if (client_focused(self)) {
652 /* don't leave an invalid focus_client */
656 client_list = g_list_remove(client_list, self);
657 stacking_remove(self);
658 g_hash_table_remove(window_map, &self->window);
660 /* once the client is out of the list, update the struts to remove its
662 if (STRUT_EXISTS(self->strut))
663 screen_update_areas();
665 client_call_notifies(self, client_destroy_notifies);
667 /* tell our parent(s) that we're gone */
668 if (self->transient_for == OB_TRAN_GROUP) { /* transient of group */
669 for (it = self->group->members; it; it = g_slist_next(it))
670 if (it->data != self)
671 ((ObClient*)it->data)->transients =
672 g_slist_remove(((ObClient*)it->data)->transients,self);
673 } else if (self->transient_for) { /* transient of window */
674 self->transient_for->transients =
675 g_slist_remove(self->transient_for->transients, self);
678 /* tell our transients that we're gone */
679 for (it = self->transients; it; it = g_slist_next(it)) {
680 if (((ObClient*)it->data)->transient_for != OB_TRAN_GROUP) {
681 ((ObClient*)it->data)->transient_for = NULL;
682 client_calc_layer(it->data);
686 /* remove from its group */
688 group_remove(self->group, self);
692 /* restore the window's original geometry so it is not lost */
698 if (self->fullscreen)
699 a = self->pre_fullscreen_area;
700 else if (self->max_horz || self->max_vert) {
701 if (self->max_horz) {
702 a.x = self->pre_max_area.x;
703 a.width = self->pre_max_area.width;
705 if (self->max_vert) {
706 a.y = self->pre_max_area.y;
707 a.height = self->pre_max_area.height;
711 self->fullscreen = self->max_horz = self->max_vert = FALSE;
712 /* let it be moved and resized no matter what */
713 self->functions = OB_CLIENT_FUNC_MOVE | OB_CLIENT_FUNC_RESIZE;
714 self->decorations = 0; /* unmanaged windows have no decor */
716 client_move_resize(self, a.x, a.y, a.width, a.height);
719 /* reparent the window out of the frame, and free the frame */
720 frame_release_client(self->frame);
721 frame_free(self->frame);
724 if (ob_state() != OB_STATE_EXITING) {
725 /* these values should not be persisted across a window
727 PROP_ERASE(self->window, net_wm_desktop);
728 PROP_ERASE(self->window, net_wm_state);
729 PROP_ERASE(self->window, wm_state);
731 /* if we're left in an unmapped state, the client wont be mapped.
732 this is bad, since we will no longer be managing the window on
734 XMapWindow(ob_display, self->window);
737 /* update the list hints */
740 ob_debug("Unmanaged window 0x%lx\n", self->window);
742 /* free all data allocated in the client struct */
743 g_slist_free(self->transients);
744 for (j = 0; j < self->nicons; ++j)
745 g_free(self->icons[j].data);
746 if (self->nicons > 0)
748 g_free(self->wm_command);
750 g_free(self->icon_title);
754 g_free(self->client_machine);
755 g_free(self->sm_client_id);
759 void client_fake_unmanage(ObClient *self)
761 /* this is all that got allocated to get the decorations */
763 frame_free(self->frame);
767 /*! Returns a new structure containing the per-app settings for this client.
768 The returned structure needs to be freed with g_free. */
769 static ObAppSettings *client_get_settings_state(ObClient *self)
771 ObAppSettings *settings;
774 settings = config_create_app_settings();
776 for (it = config_per_app_settings; it; it = g_slist_next(it)) {
777 ObAppSettings *app = it->data;
778 gboolean match = TRUE;
780 g_assert(app->name != NULL || app->class != NULL);
782 /* we know that either name or class is not NULL so it will have to
783 match to use the rule */
785 !g_pattern_match(app->name, strlen(self->name), self->name, NULL))
787 else if (app->class &&
788 !g_pattern_match(app->class,
789 strlen(self->class), self->class, NULL))
791 else if (app->role &&
792 !g_pattern_match(app->role,
793 strlen(self->role), self->role, NULL))
797 ob_debug("Window matching: %s\n", app->name);
799 /* copy the settings to our struct, overriding the existing
800 settings if they are not defaults */
801 config_app_settings_copy_non_defaults(app, settings);
805 if (settings->shade != -1)
806 self->shaded = !!settings->shade;
807 if (settings->decor != -1)
808 self->undecorated = !settings->decor;
809 if (settings->iconic != -1)
810 self->iconic = !!settings->iconic;
811 if (settings->skip_pager != -1)
812 self->skip_pager = !!settings->skip_pager;
813 if (settings->skip_taskbar != -1)
814 self->skip_taskbar = !!settings->skip_taskbar;
816 if (settings->max_vert != -1)
817 self->max_vert = !!settings->max_vert;
818 if (settings->max_horz != -1)
819 self->max_horz = !!settings->max_horz;
821 if (settings->fullscreen != -1)
822 self->fullscreen = !!settings->fullscreen;
824 if (settings->desktop) {
825 if (settings->desktop == DESKTOP_ALL)
826 self->desktop = settings->desktop;
827 else if (settings->desktop > 0 &&
828 settings->desktop <= screen_num_desktops)
829 self->desktop = settings->desktop - 1;
832 if (settings->layer == -1) {
836 else if (settings->layer == 0) {
840 else if (settings->layer == 1) {
847 static void client_restore_session_state(ObClient *self)
851 ob_debug_type(OB_DEBUG_SM,
852 "Restore session for client %s\n", self->title);
854 if (!(it = session_state_find(self))) {
855 ob_debug_type(OB_DEBUG_SM,
856 "Session data not found for client %s\n", self->title);
860 self->session = it->data;
862 ob_debug_type(OB_DEBUG_SM, "Session data loaded for client %s\n",
865 RECT_SET_POINT(self->area, self->session->x, self->session->y);
866 self->positioned = USPosition;
867 self->sized = USSize;
868 if (self->session->w > 0)
869 self->area.width = self->session->w;
870 if (self->session->h > 0)
871 self->area.height = self->session->h;
872 XResizeWindow(ob_display, self->window,
873 self->area.width, self->area.height);
875 self->desktop = (self->session->desktop == DESKTOP_ALL ?
876 self->session->desktop :
877 MIN(screen_num_desktops - 1, self->session->desktop));
878 PROP_SET32(self->window, net_wm_desktop, cardinal, self->desktop);
880 self->shaded = self->session->shaded;
881 self->iconic = self->session->iconic;
882 self->skip_pager = self->session->skip_pager;
883 self->skip_taskbar = self->session->skip_taskbar;
884 self->fullscreen = self->session->fullscreen;
885 self->above = self->session->above;
886 self->below = self->session->below;
887 self->max_horz = self->session->max_horz;
888 self->max_vert = self->session->max_vert;
889 self->undecorated = self->session->undecorated;
892 static gboolean client_restore_session_stacking(ObClient *self)
896 if (!self->session) return FALSE;
898 mypos = g_list_find(session_saved_state, self->session);
899 if (!mypos) return FALSE;
901 /* start above me and look for the first client */
902 for (it = g_list_previous(mypos); it; it = g_list_previous(it)) {
905 for (cit = client_list; cit; cit = g_list_next(cit)) {
906 ObClient *c = cit->data;
907 /* found a client that was in the session, so go below it */
908 if (c->session == it->data) {
909 stacking_below(CLIENT_AS_WINDOW(self),
910 CLIENT_AS_WINDOW(cit->data));
918 void client_move_onscreen(ObClient *self, gboolean rude)
920 gint x = self->area.x;
921 gint y = self->area.y;
922 if (client_find_onscreen(self, &x, &y,
924 self->area.height, rude)) {
925 client_move(self, x, y);
929 gboolean client_find_onscreen(ObClient *self, gint *x, gint *y, gint w, gint h,
933 gint ox = *x, oy = *y;
934 gboolean rudel = rude, ruder = rude, rudet = rude, rudeb = rude;
938 RECT_SET(desired, *x, *y, w, h);
939 all_a = screen_area(self->desktop);
940 mon_a = screen_area_monitor(self->desktop, screen_find_monitor(&desired));
942 /* get where the frame would be */
943 frame_client_gravity(self->frame, x, y, w, h);
945 /* get the requested size of the window with decorations */
946 fw = self->frame->size.left + w + self->frame->size.right;
947 fh = self->frame->size.top + h + self->frame->size.bottom;
949 /* This makes sure windows aren't entirely outside of the screen so you
950 can't see them at all.
951 It makes sure 10% of the window is on the screen at least. At don't let
952 it move itself off the top of the screen, which would hide the titlebar
953 on you. (The user can still do this if they want too, it's only limiting
956 XXX watch for xinerama dead areas...
958 if (client_normal(self)) {
959 if (!self->strut.right && *x + fw/10 >= all_a->x + all_a->width - 1)
960 *x = all_a->x + all_a->width - fw/10;
961 if (!self->strut.bottom && *y + fh/10 >= all_a->y + all_a->height - 1)
962 *y = all_a->y + all_a->height - fh/10;
963 if (!self->strut.left && *x + fw*9/10 - 1 < all_a->x)
964 *x = all_a->x - fw*9/10;
965 if (!self->strut.top && *y + fh*9/10 - 1 < all_a->y)
966 *y = all_a->y - fw*9/10;
969 /* If rudeness wasn't requested, then figure out of the client is currently
970 entirely on the screen. If it is, and the position isn't changing by
971 request, and it is enlarging, then be rude even though it wasn't
974 Point oldtl, oldtr, oldbl, oldbr;
975 Point newtl, newtr, newbl, newbr;
976 gboolean stationary_l, stationary_r, stationary_t, stationary_b;
978 POINT_SET(oldtl, self->frame->area.x, self->frame->area.y);
979 POINT_SET(oldbr, self->frame->area.x + self->frame->area.width - 1,
980 self->frame->area.y + self->frame->area.height - 1);
981 POINT_SET(oldtr, oldbr.x, oldtl.y);
982 POINT_SET(oldbl, oldtl.x, oldbr.y);
984 POINT_SET(newtl, *x, *y);
985 POINT_SET(newbr, *x + fw - 1, *y + fh - 1);
986 POINT_SET(newtr, newbr.x, newtl.y);
987 POINT_SET(newbl, newtl.x, newbr.y);
989 /* is it moving or just resizing from some corner? */
990 stationary_l = oldtl.x == newtl.x;
991 stationary_r = oldtr.x == newtr.x;
992 stationary_t = oldtl.y == newtl.y;
993 stationary_b = oldbl.y == newbl.y;
995 /* if left edge is growing and didnt move right edge */
996 if (stationary_r && newtl.x < oldtl.x)
998 /* if right edge is growing and didnt move left edge */
999 if (stationary_l && newtr.x > oldtr.x)
1001 /* if top edge is growing and didnt move bottom edge */
1002 if (stationary_b && newtl.y < oldtl.y)
1004 /* if bottom edge is growing and didnt move top edge */
1005 if (stationary_t && newbl.y > oldbl.y)
1009 /* This here doesn't let windows even a pixel outside the struts/screen.
1010 * When called from client_manage, programs placing themselves are
1011 * forced completely onscreen, while things like
1012 * xterm -geometry resolution-width/2 will work fine. Trying to
1013 * place it completely offscreen will be handled in the above code.
1014 * Sorry for this confused comment, i am tired. */
1015 if (rudel && !self->strut.left && *x < mon_a->x) *x = mon_a->x;
1016 if (ruder && !self->strut.right && *x + fw > mon_a->x + mon_a->width)
1017 *x = mon_a->x + MAX(0, mon_a->width - fw);
1019 if (rudet && !self->strut.top && *y < mon_a->y) *y = mon_a->y;
1020 if (rudeb && !self->strut.bottom && *y + fh > mon_a->y + mon_a->height)
1021 *y = mon_a->y + MAX(0, mon_a->height - fh);
1023 /* get where the client should be */
1024 frame_frame_gravity(self->frame, x, y, w, h);
1026 return ox != *x || oy != *y;
1029 static void client_get_all(ObClient *self, gboolean real)
1031 /* this is needed for the frame to set itself up */
1032 client_get_area(self);
1034 /* these things can change the decor and functions of the window */
1036 client_get_mwm_hints(self);
1037 /* this can change the mwmhints for special cases */
1038 client_get_type_and_transientness(self);
1039 client_get_state(self);
1040 client_update_normal_hints(self);
1042 /* get the session related properties, these can change decorations
1043 from per-app settings */
1044 client_get_session_ids(self);
1046 /* now we got everything that can affect the decorations */
1050 /* get this early so we have it for debugging */
1051 client_update_title(self);
1053 client_update_protocols(self);
1055 client_update_wmhints(self);
1056 /* this may have already been called from client_update_wmhints */
1057 if (self->transient_for == NULL)
1058 client_update_transient_for(self);
1060 client_get_startup_id(self);
1061 client_get_desktop(self);/* uses transient data/group/startup id if a
1062 desktop is not specified */
1063 client_get_shaped(self);
1066 /* a couple type-based defaults for new windows */
1068 /* this makes sure that these windows appear on all desktops */
1069 if (self->type == OB_CLIENT_TYPE_DESKTOP)
1070 self->desktop = DESKTOP_ALL;
1074 client_update_sync_request_counter(self);
1077 client_get_colormap(self);
1078 client_update_strut(self);
1079 client_update_icons(self);
1080 client_update_user_time_window(self);
1081 if (!self->user_time_window) /* check if this would have been called */
1082 client_update_user_time(self);
1083 client_update_icon_geometry(self);
1086 static void client_get_startup_id(ObClient *self)
1088 if (!(PROP_GETS(self->window, net_startup_id, utf8, &self->startup_id)))
1090 PROP_GETS(self->group->leader,
1091 net_startup_id, utf8, &self->startup_id);
1094 static void client_get_area(ObClient *self)
1096 XWindowAttributes wattrib;
1099 ret = XGetWindowAttributes(ob_display, self->window, &wattrib);
1100 g_assert(ret != BadWindow);
1102 RECT_SET(self->area, wattrib.x, wattrib.y, wattrib.width, wattrib.height);
1103 POINT_SET(self->root_pos, wattrib.x, wattrib.y);
1104 self->border_width = wattrib.border_width;
1106 ob_debug("client area: %d %d %d %d bw %d\n", wattrib.x, wattrib.y,
1107 wattrib.width, wattrib.height, wattrib.border_width);
1110 static void client_get_desktop(ObClient *self)
1112 guint32 d = screen_num_desktops; /* an always-invalid value */
1114 if (PROP_GET32(self->window, net_wm_desktop, cardinal, &d)) {
1115 if (d >= screen_num_desktops && d != DESKTOP_ALL)
1116 self->desktop = screen_num_desktops - 1;
1119 ob_debug("client requested desktop 0x%x\n", self->desktop);
1121 gboolean trdesk = FALSE;
1123 if (self->transient_for) {
1124 if (self->transient_for != OB_TRAN_GROUP) {
1125 if (self->transient_for->desktop != DESKTOP_ALL) {
1126 self->desktop = self->transient_for->desktop;
1130 /* if all the group is on one desktop, then open it on the
1133 gboolean first = TRUE;
1134 guint all = screen_num_desktops; /* not a valid value */
1136 for (it = self->group->members; it; it = g_slist_next(it)) {
1137 ObClient *c = it->data;
1143 else if (all != c->desktop)
1144 all = screen_num_desktops; /* make it invalid */
1147 if (all != screen_num_desktops) {
1148 self->desktop = all;
1154 /* try get from the startup-notification protocol */
1155 if (sn_get_desktop(self->startup_id, &self->desktop)) {
1156 if (self->desktop >= screen_num_desktops &&
1157 self->desktop != DESKTOP_ALL)
1158 self->desktop = screen_num_desktops - 1;
1160 /* defaults to the current desktop */
1161 self->desktop = screen_desktop;
1166 static void client_get_state(ObClient *self)
1171 if (PROP_GETA32(self->window, net_wm_state, atom, &state, &num)) {
1173 for (i = 0; i < num; ++i) {
1174 if (state[i] == prop_atoms.net_wm_state_modal)
1176 else if (state[i] == prop_atoms.net_wm_state_shaded)
1177 self->shaded = TRUE;
1178 else if (state[i] == prop_atoms.net_wm_state_hidden)
1179 self->iconic = TRUE;
1180 else if (state[i] == prop_atoms.net_wm_state_skip_taskbar)
1181 self->skip_taskbar = TRUE;
1182 else if (state[i] == prop_atoms.net_wm_state_skip_pager)
1183 self->skip_pager = TRUE;
1184 else if (state[i] == prop_atoms.net_wm_state_fullscreen)
1185 self->fullscreen = TRUE;
1186 else if (state[i] == prop_atoms.net_wm_state_maximized_vert)
1187 self->max_vert = TRUE;
1188 else if (state[i] == prop_atoms.net_wm_state_maximized_horz)
1189 self->max_horz = TRUE;
1190 else if (state[i] == prop_atoms.net_wm_state_above)
1192 else if (state[i] == prop_atoms.net_wm_state_below)
1194 else if (state[i] == prop_atoms.net_wm_state_demands_attention)
1195 self->demands_attention = TRUE;
1196 else if (state[i] == prop_atoms.ob_wm_state_undecorated)
1197 self->undecorated = TRUE;
1204 static void client_get_shaped(ObClient *self)
1206 self->shaped = FALSE;
1208 if (extensions_shape) {
1213 XShapeSelectInput(ob_display, self->window, ShapeNotifyMask);
1215 XShapeQueryExtents(ob_display, self->window, &s, &foo,
1216 &foo, &ufoo, &ufoo, &foo, &foo, &foo, &ufoo,
1218 self->shaped = (s != 0);
1223 void client_update_transient_for(ObClient *self)
1226 ObClient *target = NULL;
1228 if (XGetTransientForHint(ob_display, self->window, &t)) {
1229 if (t != self->window) { /* cant be transient to itself! */
1230 target = g_hash_table_lookup(window_map, &t);
1231 /* if this happens then we need to check for it*/
1232 g_assert(target != self);
1233 if (target && !WINDOW_IS_CLIENT(target)) {
1234 /* this can happen when a dialog is a child of
1235 a dockapp, for example */
1239 /* THIS IS SO ANNOYING ! ! ! ! Let me explain.... have a seat..
1241 Setting the transient_for to Root is actually illegal, however
1242 applications from time have done this to specify transient for
1245 Now you can do that by being a TYPE_DIALOG and not setting
1246 the transient_for hint at all on your window. But people still
1247 use Root, and Kwin is very strange in this regard.
1249 KWin 3.0 will not consider windows with transient_for set to
1250 Root as transient for their group *UNLESS* they are also modal.
1251 In that case, it will make them transient for the group. This
1252 leads to all sorts of weird behavior from KDE apps which are
1253 only tested in KWin. I'd like to follow their behavior just to
1254 make this work right with KDE stuff, but that seems wrong.
1256 if (!target && self->group) {
1257 /* not transient to a client, see if it is transient for a
1259 if (t == RootWindow(ob_display, ob_screen)) {
1260 /* window is a transient for its group! */
1261 target = OB_TRAN_GROUP;
1265 } else if (self->transient && self->group)
1266 target = OB_TRAN_GROUP;
1268 client_update_transient_tree(self, self->group, self->group,
1269 self->transient_for, target);
1270 self->transient_for = target;
1274 static void client_update_transient_tree(ObClient *self,
1275 ObGroup *oldgroup, ObGroup *newgroup,
1276 ObClient* oldparent,
1277 ObClient *newparent)
1283 Group transient windows are not allowed to have other group
1284 transient windows as their children.
1288 /* No change has occured */
1289 if (oldgroup == newgroup && oldparent == newparent) return;
1291 /** Remove the client from the transient tree wherever it has changed **/
1293 /* If the window is becoming a direct transient for a window in its group
1294 then any group transients which were our children and are now becoming
1295 our parents need to stop being our children.
1297 Group transients can't be children of group transients already, but
1298 we could have any number of direct parents above up, any of which could
1299 be transient for the group, and we need to remove it from our children.
1301 if (oldparent != newparent &&
1302 newparent != NULL && newparent != OB_TRAN_GROUP &&
1303 newgroup != NULL && newgroup == oldgroup)
1305 ObClient *look = newparent;
1307 self->transients = g_slist_remove(self->transients, look);
1308 look = look->transient_for;
1309 } while (look != NULL && look != OB_TRAN_GROUP);
1313 /* If the group changed, or if we are just becoming transient for the
1314 group, then we need to remove any old group transient windows
1315 from our children. But if we were already transient for the group, then
1316 other group transients are not our children. */
1317 if ((oldgroup != newgroup ||
1318 (newparent == OB_TRAN_GROUP && oldparent != newparent)) &&
1319 oldgroup != NULL && oldparent != OB_TRAN_GROUP)
1321 for (it = self->transients; it; it = next) {
1322 next = g_slist_next(it);
1324 if (c->group == oldgroup)
1325 self->transients = g_slist_delete_link(self->transients, it);
1329 /* If we used to be transient for a group and now we are not, or we're
1330 transient for a new group, then we need to remove ourselves from all
1332 if (oldparent == OB_TRAN_GROUP && (oldgroup != newgroup ||
1333 oldparent != newparent))
1335 for (it = oldgroup->members; it; it = g_slist_next(it)) {
1337 if (c != self && (!c->transient_for ||
1338 c->transient_for != OB_TRAN_GROUP))
1339 c->transients = g_slist_remove(c->transients, self);
1342 /* If we used to be transient for a single window and we are no longer
1343 transient for it, then we need to remove ourself from its children */
1344 else if (oldparent != NULL && oldparent != OB_TRAN_GROUP &&
1345 oldparent != newparent)
1346 oldparent->transients = g_slist_remove(oldparent->transients, self);
1349 /** Re-add the client to the transient tree wherever it has changed **/
1351 /* If we're now transient for a group and we weren't transient for it
1352 before then we need to add ourselves to all our new parents */
1353 if (newparent == OB_TRAN_GROUP && (oldgroup != newgroup ||
1354 oldparent != newparent))
1356 for (it = oldgroup->members; it; it = g_slist_next(it)) {
1358 if (c != self && (!c->transient_for ||
1359 c->transient_for != OB_TRAN_GROUP))
1360 c->transients = g_slist_prepend(c->transients, self);
1363 /* If we are now transient for a single window which we weren't before,
1364 we need to add ourselves to its children
1366 WARNING: Cyclical transient ness is possible if two windows are
1367 transient for eachother.
1369 else if (newparent != NULL && newparent != OB_TRAN_GROUP &&
1370 newparent != oldparent &&
1371 /* don't make ourself its child if it is already our child */
1372 !client_is_direct_child(self, newparent))
1373 newparent->transients = g_slist_prepend(newparent->transients, self);
1375 /* If the group changed then we need to add any new group transient
1376 windows to our children. But if we're transient for the group, then
1377 other group transients are not our children.
1379 WARNING: Cyclical transient-ness is possible. For e.g. if:
1380 A is transient for the group
1381 B is transient for A
1382 C is transient for B
1383 A can't be transient for C or we have a cycle
1385 if (oldgroup != newgroup && newgroup != NULL &&
1386 newparent != OB_TRAN_GROUP)
1388 for (it = newgroup->members; it; it = g_slist_next(it)) {
1390 if (c != self && c->transient_for == OB_TRAN_GROUP &&
1391 /* Don't make it our child if it is already our parent */
1392 !client_is_direct_child(c, self))
1394 self->transients = g_slist_prepend(self->transients, c);
1400 static void client_get_mwm_hints(ObClient *self)
1405 self->mwmhints.flags = 0; /* default to none */
1407 if (PROP_GETA32(self->window, motif_wm_hints, motif_wm_hints,
1409 if (num >= OB_MWM_ELEMENTS) {
1410 self->mwmhints.flags = hints[0];
1411 self->mwmhints.functions = hints[1];
1412 self->mwmhints.decorations = hints[2];
1418 void client_get_type_and_transientness(ObClient *self)
1425 self->transient = FALSE;
1427 if (PROP_GETA32(self->window, net_wm_window_type, atom, &val, &num)) {
1428 /* use the first value that we know about in the array */
1429 for (i = 0; i < num; ++i) {
1430 if (val[i] == prop_atoms.net_wm_window_type_desktop)
1431 self->type = OB_CLIENT_TYPE_DESKTOP;
1432 else if (val[i] == prop_atoms.net_wm_window_type_dock)
1433 self->type = OB_CLIENT_TYPE_DOCK;
1434 else if (val[i] == prop_atoms.net_wm_window_type_toolbar)
1435 self->type = OB_CLIENT_TYPE_TOOLBAR;
1436 else if (val[i] == prop_atoms.net_wm_window_type_menu)
1437 self->type = OB_CLIENT_TYPE_MENU;
1438 else if (val[i] == prop_atoms.net_wm_window_type_utility)
1439 self->type = OB_CLIENT_TYPE_UTILITY;
1440 else if (val[i] == prop_atoms.net_wm_window_type_splash)
1441 self->type = OB_CLIENT_TYPE_SPLASH;
1442 else if (val[i] == prop_atoms.net_wm_window_type_dialog)
1443 self->type = OB_CLIENT_TYPE_DIALOG;
1444 else if (val[i] == prop_atoms.net_wm_window_type_normal)
1445 self->type = OB_CLIENT_TYPE_NORMAL;
1446 else if (val[i] == prop_atoms.kde_net_wm_window_type_override) {
1447 /* prevent this window from getting any decor or
1449 self->mwmhints.flags &= (OB_MWM_FLAG_FUNCTIONS |
1450 OB_MWM_FLAG_DECORATIONS);
1451 self->mwmhints.decorations = 0;
1452 self->mwmhints.functions = 0;
1454 if (self->type != (ObClientType) -1)
1455 break; /* grab the first legit type */
1460 if (XGetTransientForHint(ob_display, self->window, &t))
1461 self->transient = TRUE;
1463 if (self->type == (ObClientType) -1) {
1464 /*the window type hint was not set, which means we either classify
1465 ourself as a normal window or a dialog, depending on if we are a
1467 if (self->transient)
1468 self->type = OB_CLIENT_TYPE_DIALOG;
1470 self->type = OB_CLIENT_TYPE_NORMAL;
1473 /* then, based on our type, we can update our transientness.. */
1474 if (self->type == OB_CLIENT_TYPE_DIALOG ||
1475 self->type == OB_CLIENT_TYPE_TOOLBAR ||
1476 self->type == OB_CLIENT_TYPE_MENU ||
1477 self->type == OB_CLIENT_TYPE_UTILITY)
1479 self->transient = TRUE;
1483 void client_update_protocols(ObClient *self)
1486 guint num_return, i;
1488 self->focus_notify = FALSE;
1489 self->delete_window = FALSE;
1491 if (PROP_GETA32(self->window, wm_protocols, atom, &proto, &num_return)) {
1492 for (i = 0; i < num_return; ++i) {
1493 if (proto[i] == prop_atoms.wm_delete_window)
1494 /* this means we can request the window to close */
1495 self->delete_window = TRUE;
1496 else if (proto[i] == prop_atoms.wm_take_focus)
1497 /* if this protocol is requested, then the window will be
1498 notified whenever we want it to receive focus */
1499 self->focus_notify = TRUE;
1501 else if (proto[i] == prop_atoms.net_wm_sync_request)
1502 /* if this protocol is requested, then resizing the
1503 window will be synchronized between the frame and the
1505 self->sync_request = TRUE;
1513 void client_update_sync_request_counter(ObClient *self)
1517 if (PROP_GET32(self->window, net_wm_sync_request_counter, cardinal, &i)) {
1518 self->sync_counter = i;
1520 self->sync_counter = None;
1524 void client_get_colormap(ObClient *self)
1526 XWindowAttributes wa;
1528 if (XGetWindowAttributes(ob_display, self->window, &wa))
1529 client_update_colormap(self, wa.colormap);
1532 void client_update_colormap(ObClient *self, Colormap colormap)
1534 if (colormap == self->colormap) return;
1536 ob_debug("Setting client %s colormap: 0x%x\n", self->title, colormap);
1538 if (client_focused(self)) {
1539 screen_install_colormap(self, FALSE); /* uninstall old one */
1540 self->colormap = colormap;
1541 screen_install_colormap(self, FALSE); /* install new one */
1543 self->colormap = colormap;
1546 void client_update_normal_hints(ObClient *self)
1552 self->min_ratio = 0.0f;
1553 self->max_ratio = 0.0f;
1554 SIZE_SET(self->size_inc, 1, 1);
1555 SIZE_SET(self->base_size, 0, 0);
1556 SIZE_SET(self->min_size, 0, 0);
1557 SIZE_SET(self->max_size, G_MAXINT, G_MAXINT);
1559 /* get the hints from the window */
1560 if (XGetWMNormalHints(ob_display, self->window, &size, &ret)) {
1561 /* normal windows can't request placement! har har
1562 if (!client_normal(self))
1564 self->positioned = (size.flags & (PPosition|USPosition));
1565 self->sized = (size.flags & (PSize|USSize));
1567 if (size.flags & PWinGravity)
1568 self->gravity = size.win_gravity;
1570 if (size.flags & PAspect) {
1571 if (size.min_aspect.y)
1573 (gfloat) size.min_aspect.x / size.min_aspect.y;
1574 if (size.max_aspect.y)
1576 (gfloat) size.max_aspect.x / size.max_aspect.y;
1579 if (size.flags & PMinSize)
1580 SIZE_SET(self->min_size, size.min_width, size.min_height);
1582 if (size.flags & PMaxSize)
1583 SIZE_SET(self->max_size, size.max_width, size.max_height);
1585 if (size.flags & PBaseSize)
1586 SIZE_SET(self->base_size, size.base_width, size.base_height);
1588 if (size.flags & PResizeInc && size.width_inc && size.height_inc)
1589 SIZE_SET(self->size_inc, size.width_inc, size.height_inc);
1593 void client_setup_decor_and_functions(ObClient *self, gboolean reconfig)
1595 /* start with everything (cept fullscreen) */
1597 (OB_FRAME_DECOR_TITLEBAR |
1598 OB_FRAME_DECOR_HANDLE |
1599 OB_FRAME_DECOR_GRIPS |
1600 OB_FRAME_DECOR_BORDER |
1601 OB_FRAME_DECOR_ICON |
1602 OB_FRAME_DECOR_ALLDESKTOPS |
1603 OB_FRAME_DECOR_ICONIFY |
1604 OB_FRAME_DECOR_MAXIMIZE |
1605 OB_FRAME_DECOR_SHADE |
1606 OB_FRAME_DECOR_CLOSE);
1608 (OB_CLIENT_FUNC_RESIZE |
1609 OB_CLIENT_FUNC_MOVE |
1610 OB_CLIENT_FUNC_ICONIFY |
1611 OB_CLIENT_FUNC_MAXIMIZE |
1612 OB_CLIENT_FUNC_SHADE |
1613 OB_CLIENT_FUNC_CLOSE |
1614 OB_CLIENT_FUNC_BELOW |
1615 OB_CLIENT_FUNC_ABOVE |
1616 OB_CLIENT_FUNC_UNDECORATE);
1618 if (!(self->min_size.width < self->max_size.width ||
1619 self->min_size.height < self->max_size.height))
1620 self->functions &= ~OB_CLIENT_FUNC_RESIZE;
1622 switch (self->type) {
1623 case OB_CLIENT_TYPE_NORMAL:
1624 /* normal windows retain all of the possible decorations and
1625 functionality, and are the only windows that you can fullscreen */
1626 self->functions |= OB_CLIENT_FUNC_FULLSCREEN;
1629 case OB_CLIENT_TYPE_DIALOG:
1630 case OB_CLIENT_TYPE_UTILITY:
1631 /* these windows don't have anything added or removed by default */
1634 case OB_CLIENT_TYPE_MENU:
1635 case OB_CLIENT_TYPE_TOOLBAR:
1636 /* these windows can't iconify or maximize */
1637 self->decorations &= ~(OB_FRAME_DECOR_ICONIFY |
1638 OB_FRAME_DECOR_MAXIMIZE);
1639 self->functions &= ~(OB_CLIENT_FUNC_ICONIFY |
1640 OB_CLIENT_FUNC_MAXIMIZE);
1643 case OB_CLIENT_TYPE_SPLASH:
1644 /* these don't get get any decorations, and the only thing you can
1645 do with them is move them */
1646 self->decorations = 0;
1647 self->functions = OB_CLIENT_FUNC_MOVE;
1650 case OB_CLIENT_TYPE_DESKTOP:
1651 /* these windows are not manipulated by the window manager */
1652 self->decorations = 0;
1653 self->functions = 0;
1656 case OB_CLIENT_TYPE_DOCK:
1657 /* these windows are not manipulated by the window manager, but they
1658 can set below layer which has a special meaning */
1659 self->decorations = 0;
1660 self->functions = OB_CLIENT_FUNC_BELOW;
1664 /* Mwm Hints are applied subtractively to what has already been chosen for
1665 decor and functionality */
1666 if (self->mwmhints.flags & OB_MWM_FLAG_DECORATIONS) {
1667 if (! (self->mwmhints.decorations & OB_MWM_DECOR_ALL)) {
1668 if (! ((self->mwmhints.decorations & OB_MWM_DECOR_HANDLE) ||
1669 (self->mwmhints.decorations & OB_MWM_DECOR_TITLE)))
1671 /* if the mwm hints request no handle or title, then all
1672 decorations are disabled, but keep the border if that's
1674 if (self->mwmhints.decorations & OB_MWM_DECOR_BORDER)
1675 self->decorations = OB_FRAME_DECOR_BORDER;
1677 self->decorations = 0;
1682 if (self->mwmhints.flags & OB_MWM_FLAG_FUNCTIONS) {
1683 if (! (self->mwmhints.functions & OB_MWM_FUNC_ALL)) {
1684 if (! (self->mwmhints.functions & OB_MWM_FUNC_RESIZE))
1685 self->functions &= ~OB_CLIENT_FUNC_RESIZE;
1686 if (! (self->mwmhints.functions & OB_MWM_FUNC_MOVE))
1687 self->functions &= ~OB_CLIENT_FUNC_MOVE;
1688 /* dont let mwm hints kill any buttons
1689 if (! (self->mwmhints.functions & OB_MWM_FUNC_ICONIFY))
1690 self->functions &= ~OB_CLIENT_FUNC_ICONIFY;
1691 if (! (self->mwmhints.functions & OB_MWM_FUNC_MAXIMIZE))
1692 self->functions &= ~OB_CLIENT_FUNC_MAXIMIZE;
1694 /* dont let mwm hints kill the close button
1695 if (! (self->mwmhints.functions & MwmFunc_Close))
1696 self->functions &= ~OB_CLIENT_FUNC_CLOSE; */
1700 if (!(self->functions & OB_CLIENT_FUNC_SHADE))
1701 self->decorations &= ~OB_FRAME_DECOR_SHADE;
1702 if (!(self->functions & OB_CLIENT_FUNC_ICONIFY))
1703 self->decorations &= ~OB_FRAME_DECOR_ICONIFY;
1704 if (!(self->functions & OB_CLIENT_FUNC_RESIZE))
1705 self->decorations &= ~(OB_FRAME_DECOR_GRIPS | OB_FRAME_DECOR_HANDLE);
1707 /* can't maximize without moving/resizing */
1708 if (!((self->functions & OB_CLIENT_FUNC_MAXIMIZE) &&
1709 (self->functions & OB_CLIENT_FUNC_MOVE) &&
1710 (self->functions & OB_CLIENT_FUNC_RESIZE))) {
1711 self->functions &= ~OB_CLIENT_FUNC_MAXIMIZE;
1712 self->decorations &= ~OB_FRAME_DECOR_MAXIMIZE;
1715 if (self->max_horz && self->max_vert) {
1716 /* you can't resize fully maximized windows */
1717 self->functions &= ~OB_CLIENT_FUNC_RESIZE;
1718 /* kill the handle on fully maxed windows */
1719 self->decorations &= ~(OB_FRAME_DECOR_HANDLE | OB_FRAME_DECOR_GRIPS);
1722 /* If there are no decorations to remove, don't allow the user to try
1724 if (self->decorations == 0)
1725 self->functions &= ~OB_CLIENT_FUNC_UNDECORATE;
1727 /* finally, the user can have requested no decorations, which overrides
1728 everything (but doesnt give it a border if it doesnt have one) */
1729 if (self->undecorated) {
1730 if (config_theme_keepborder)
1731 self->decorations &= OB_FRAME_DECOR_BORDER;
1733 self->decorations = 0;
1736 /* if we don't have a titlebar, then we cannot shade! */
1737 if (!(self->decorations & OB_FRAME_DECOR_TITLEBAR))
1738 self->functions &= ~OB_CLIENT_FUNC_SHADE;
1740 /* now we need to check against rules for the client's current state */
1741 if (self->fullscreen) {
1742 self->functions &= (OB_CLIENT_FUNC_CLOSE |
1743 OB_CLIENT_FUNC_FULLSCREEN |
1744 OB_CLIENT_FUNC_ICONIFY);
1745 self->decorations = 0;
1748 client_change_allowed_actions(self);
1751 client_reconfigure(self);
1754 static void client_change_allowed_actions(ObClient *self)
1759 /* desktop windows are kept on all desktops */
1760 if (self->type != OB_CLIENT_TYPE_DESKTOP)
1761 actions[num++] = prop_atoms.net_wm_action_change_desktop;
1763 if (self->functions & OB_CLIENT_FUNC_SHADE)
1764 actions[num++] = prop_atoms.net_wm_action_shade;
1765 if (self->functions & OB_CLIENT_FUNC_CLOSE)
1766 actions[num++] = prop_atoms.net_wm_action_close;
1767 if (self->functions & OB_CLIENT_FUNC_MOVE)
1768 actions[num++] = prop_atoms.net_wm_action_move;
1769 if (self->functions & OB_CLIENT_FUNC_ICONIFY)
1770 actions[num++] = prop_atoms.net_wm_action_minimize;
1771 if (self->functions & OB_CLIENT_FUNC_RESIZE)
1772 actions[num++] = prop_atoms.net_wm_action_resize;
1773 if (self->functions & OB_CLIENT_FUNC_FULLSCREEN)
1774 actions[num++] = prop_atoms.net_wm_action_fullscreen;
1775 if (self->functions & OB_CLIENT_FUNC_MAXIMIZE) {
1776 actions[num++] = prop_atoms.net_wm_action_maximize_horz;
1777 actions[num++] = prop_atoms.net_wm_action_maximize_vert;
1779 if (self->functions & OB_CLIENT_FUNC_ABOVE)
1780 actions[num++] = prop_atoms.net_wm_action_above;
1781 if (self->functions & OB_CLIENT_FUNC_BELOW)
1782 actions[num++] = prop_atoms.net_wm_action_below;
1783 if (self->functions & OB_CLIENT_FUNC_UNDECORATE)
1784 actions[num++] = prop_atoms.ob_wm_action_undecorate;
1786 PROP_SETA32(self->window, net_wm_allowed_actions, atom, actions, num);
1788 /* make sure the window isn't breaking any rules now */
1790 if (!(self->functions & OB_CLIENT_FUNC_SHADE) && self->shaded) {
1791 if (self->frame) client_shade(self, FALSE);
1792 else self->shaded = FALSE;
1794 if (!(self->functions & OB_CLIENT_FUNC_ICONIFY) && self->iconic) {
1795 if (self->frame) client_iconify(self, FALSE, TRUE, FALSE);
1796 else self->iconic = FALSE;
1798 if (!(self->functions & OB_CLIENT_FUNC_FULLSCREEN) && self->fullscreen) {
1799 if (self->frame) client_fullscreen(self, FALSE);
1800 else self->fullscreen = FALSE;
1802 if (!(self->functions & OB_CLIENT_FUNC_MAXIMIZE) && (self->max_horz ||
1804 if (self->frame) client_maximize(self, FALSE, 0);
1805 else self->max_vert = self->max_horz = FALSE;
1809 void client_reconfigure(ObClient *self)
1811 client_configure(self, self->area.x, self->area.y,
1812 self->area.width, self->area.height,
1813 self->border_width, FALSE, TRUE);
1816 void client_update_wmhints(ObClient *self)
1820 /* assume a window takes input if it doesnt specify */
1821 self->can_focus = TRUE;
1823 if ((hints = XGetWMHints(ob_display, self->window)) != NULL) {
1826 if (hints->flags & InputHint)
1827 self->can_focus = hints->input;
1829 /* only do this when first managing the window *AND* when we aren't
1831 if (ob_state() != OB_STATE_STARTING && self->frame == NULL)
1832 if (hints->flags & StateHint)
1833 self->iconic = hints->initial_state == IconicState;
1836 self->urgent = (hints->flags & XUrgencyHint);
1837 if (self->urgent && !ur)
1838 client_hilite(self, TRUE);
1839 else if (!self->urgent && ur && self->demands_attention)
1840 client_hilite(self, FALSE);
1842 if (!(hints->flags & WindowGroupHint))
1843 hints->window_group = None;
1845 /* did the group state change? */
1846 if (hints->window_group !=
1847 (self->group ? self->group->leader : None))
1849 ObGroup *oldgroup = self->group;
1851 /* remove from the old group if there was one */
1852 if (self->group != NULL) {
1853 group_remove(self->group, self);
1857 /* add ourself to the group if we have one */
1858 if (hints->window_group != None) {
1859 self->group = group_add(hints->window_group, self);
1862 /* Put ourselves into the new group's transient tree, and remove
1863 ourselves from the old group's */
1864 client_update_transient_tree(self, oldgroup, self->group,
1865 self->transient_for,
1866 self->transient_for);
1868 /* Lastly, being in a group, or not, can change if the window is
1869 transient for anything.
1871 The logic for this is:
1872 self->transient = TRUE always if the window wants to be
1873 transient for something, even if transient_for was NULL because
1874 it wasn't in a group before.
1876 If transient_for was NULL and oldgroup was NULL we can assume
1877 that when we add the new group, it will become transient for
1880 If transient_for was OB_TRAN_GROUP, then it must have already
1881 had a group. If it is getting a new group, the above call to
1882 client_update_transient_tree has already taken care of
1883 everything ! If it is losing all group status then it will
1884 no longer be transient for anything and that needs to be
1887 if (self->transient &&
1888 ((self->transient_for == NULL && oldgroup == NULL) ||
1889 (self->transient_for == OB_TRAN_GROUP && !self->group)))
1890 client_update_transient_for(self);
1893 /* the WM_HINTS can contain an icon */
1894 if (hints->flags & IconPixmapHint)
1895 client_update_icons(self);
1901 void client_update_title(ObClient *self)
1904 gchar *visible = NULL;
1906 g_free(self->title);
1909 if (!PROP_GETS(self->window, net_wm_name, utf8, &data)) {
1910 /* try old x stuff */
1911 if (!(PROP_GETS(self->window, wm_name, locale, &data)
1912 || PROP_GETS(self->window, wm_name, utf8, &data))) {
1913 if (self->transient) {
1915 GNOME alert windows are not given titles:
1916 http://developer.gnome.org/projects/gup/hig/draft_hig_new/windows-alert.html
1918 data = g_strdup("");
1920 data = g_strdup("Unnamed Window");
1924 if (self->client_machine) {
1925 visible = g_strdup_printf("%s (%s)", data, self->client_machine);
1930 PROP_SETS(self->window, net_wm_visible_name, visible);
1931 self->title = visible;
1934 frame_adjust_title(self->frame);
1936 /* update the icon title */
1938 g_free(self->icon_title);
1941 if (!PROP_GETS(self->window, net_wm_icon_name, utf8, &data))
1942 /* try old x stuff */
1943 if (!(PROP_GETS(self->window, wm_icon_name, locale, &data) ||
1944 PROP_GETS(self->window, wm_icon_name, utf8, &data)))
1945 data = g_strdup(self->title);
1947 if (self->client_machine) {
1948 visible = g_strdup_printf("%s (%s)", data, self->client_machine);
1953 PROP_SETS(self->window, net_wm_visible_icon_name, visible);
1954 self->icon_title = visible;
1957 void client_update_strut(ObClient *self)
1961 gboolean got = FALSE;
1964 if (PROP_GETA32(self->window, net_wm_strut_partial, cardinal,
1968 STRUT_PARTIAL_SET(strut,
1969 data[0], data[2], data[1], data[3],
1970 data[4], data[5], data[8], data[9],
1971 data[6], data[7], data[10], data[11]);
1977 PROP_GETA32(self->window, net_wm_strut, cardinal, &data, &num)) {
1983 /* use the screen's width/height */
1984 a = screen_physical_area();
1986 STRUT_PARTIAL_SET(strut,
1987 data[0], data[2], data[1], data[3],
1988 a->y, a->y + a->height - 1,
1989 a->x, a->x + a->width - 1,
1990 a->y, a->y + a->height - 1,
1991 a->x, a->x + a->width - 1);
1997 STRUT_PARTIAL_SET(strut, 0, 0, 0, 0,
1998 0, 0, 0, 0, 0, 0, 0, 0);
2000 if (!STRUT_EQUAL(strut, self->strut)) {
2001 self->strut = strut;
2003 /* updating here is pointless while we're being mapped cuz we're not in
2004 the client list yet */
2006 screen_update_areas();
2010 void client_update_icons(ObClient *self)
2016 for (i = 0; i < self->nicons; ++i)
2017 g_free(self->icons[i].data);
2018 if (self->nicons > 0)
2019 g_free(self->icons);
2022 if (PROP_GETA32(self->window, net_wm_icon, cardinal, &data, &num)) {
2023 /* figure out how many valid icons are in here */
2025 while (num - i > 2) {
2029 if (i > num || w*h == 0) break;
2033 self->icons = g_new(ObClientIcon, self->nicons);
2035 /* store the icons */
2037 for (j = 0; j < self->nicons; ++j) {
2040 w = self->icons[j].width = data[i++];
2041 h = self->icons[j].height = data[i++];
2043 if (w*h == 0) continue;
2045 self->icons[j].data = g_new(RrPixel32, w * h);
2046 for (x = 0, y = 0, t = 0; t < w * h; ++t, ++x, ++i) {
2051 self->icons[j].data[t] =
2052 (((data[i] >> 24) & 0xff) << RrDefaultAlphaOffset) +
2053 (((data[i] >> 16) & 0xff) << RrDefaultRedOffset) +
2054 (((data[i] >> 8) & 0xff) << RrDefaultGreenOffset) +
2055 (((data[i] >> 0) & 0xff) << RrDefaultBlueOffset);
2064 if ((hints = XGetWMHints(ob_display, self->window))) {
2065 if (hints->flags & IconPixmapHint) {
2067 self->icons = g_new(ObClientIcon, self->nicons);
2068 xerror_set_ignore(TRUE);
2069 if (!RrPixmapToRGBA(ob_rr_inst,
2071 (hints->flags & IconMaskHint ?
2072 hints->icon_mask : None),
2073 &self->icons[self->nicons-1].width,
2074 &self->icons[self->nicons-1].height,
2075 &self->icons[self->nicons-1].data)){
2076 g_free(&self->icons[self->nicons-1]);
2079 xerror_set_ignore(FALSE);
2085 /* set the default icon onto the window
2086 in theory, this could be a race, but if a window doesn't set an icon
2087 or removes it entirely, it's not very likely it is going to set one
2088 right away afterwards */
2089 if (self->nicons == 0) {
2090 RrPixel32 *icon = ob_rr_theme->def_win_icon;
2093 data = g_new(gulong, 48*48+2);
2094 data[0] = data[1] = 48;
2095 for (i = 0; i < 48*48; ++i)
2096 data[i+2] = (((icon[i] >> RrDefaultAlphaOffset) & 0xff) << 24) +
2097 (((icon[i] >> RrDefaultRedOffset) & 0xff) << 16) +
2098 (((icon[i] >> RrDefaultGreenOffset) & 0xff) << 8) +
2099 (((icon[i] >> RrDefaultBlueOffset) & 0xff) << 0);
2100 PROP_SETA32(self->window, net_wm_icon, cardinal, data, 48*48+2);
2102 } else if (self->frame)
2103 /* don't draw the icon empty if we're just setting one now anyways,
2104 we'll get the property change any second */
2105 frame_adjust_icon(self->frame);
2108 void client_update_user_time(ObClient *self)
2111 gboolean got = FALSE;
2113 if (self->user_time_window)
2114 got = PROP_GET32(self->user_time_window,
2115 net_wm_user_time, cardinal, &time);
2117 got = PROP_GET32(self->window, net_wm_user_time, cardinal, &time);
2120 /* we set this every time, not just when it grows, because in practice
2121 sometimes time goes backwards! (ntpdate.. yay....) so.. if it goes
2122 backward we don't want all windows to stop focusing. we'll just
2123 assume noone is setting times older than the last one, cuz that
2124 would be pretty stupid anyways
2126 self->user_time = time;
2128 /*ob_debug("window %s user time %u\n", self->title, time);*/
2132 void client_update_user_time_window(ObClient *self)
2136 if (!PROP_GET32(self->window, net_wm_user_time_window, window, &w))
2139 if (w != self->user_time_window) {
2140 /* remove the old window */
2141 propwin_remove(self->user_time_window, OB_PROPWIN_USER_TIME, self);
2142 self->user_time_window = None;
2144 if (self->group && self->group->leader == w) {
2145 ob_debug_type(OB_DEBUG_APP_BUGS, "Window is setting its "
2146 "_NET_WM_USER_TYPE_WINDOW to its group leader\n");
2147 /* do it anyways..? */
2149 else if (w == self->window) {
2150 ob_debug_type(OB_DEBUG_APP_BUGS, "Window is setting its "
2151 "_NET_WM_USER_TIME_WINDOW to itself\n");
2152 w = None; /* don't do it */
2155 /* add the new window */
2156 propwin_add(w, OB_PROPWIN_USER_TIME, self);
2157 self->user_time_window = w;
2159 /* and update from it */
2160 client_update_user_time(self);
2164 void client_update_icon_geometry(ObClient *self)
2169 RECT_SET(self->icon_geometry, 0, 0, 0, 0);
2171 if (PROP_GETA32(self->window, net_wm_icon_geometry, cardinal, &data, &num)
2174 /* don't let them set it with an area < 0 */
2175 RECT_SET(self->icon_geometry, data[0], data[1],
2176 MAX(data[2],0), MAX(data[3],0));
2180 static void client_get_session_ids(ObClient *self)
2187 if (!PROP_GET32(self->window, wm_client_leader, window, &leader))
2190 /* get the SM_CLIENT_ID */
2193 got = PROP_GETS(leader, sm_client_id, locale, &self->sm_client_id);
2195 PROP_GETS(self->window, sm_client_id, locale, &self->sm_client_id);
2197 /* get the WM_CLASS (name and class). make them "" if they are not
2201 got = PROP_GETSS(leader, wm_class, locale, &ss);
2203 got = PROP_GETSS(self->window, wm_class, locale, &ss);
2207 self->name = g_strdup(ss[0]);
2209 self->class = g_strdup(ss[1]);
2214 if (self->name == NULL) self->name = g_strdup("");
2215 if (self->class == NULL) self->class = g_strdup("");
2217 /* get the WM_WINDOW_ROLE. make it "" if it is not provided */
2220 got = PROP_GETS(leader, wm_window_role, locale, &s);
2222 got = PROP_GETS(self->window, wm_window_role, locale, &s);
2227 self->role = g_strdup("");
2229 /* get the WM_COMMAND */
2233 got = PROP_GETSS(leader, wm_command, locale, &ss);
2235 got = PROP_GETSS(self->window, wm_command, locale, &ss);
2238 /* merge/mash them all together */
2239 gchar *merge = NULL;
2242 for (i = 0; ss[i]; ++i) {
2245 merge = g_strconcat(merge, ss[i], NULL);
2247 merge = g_strconcat(ss[i], NULL);
2252 self->wm_command = merge;
2255 /* get the WM_CLIENT_MACHINE */
2258 got = PROP_GETS(leader, wm_client_machine, locale, &s);
2260 got = PROP_GETS(self->window, wm_client_machine, locale, &s);
2263 gchar localhost[128];
2265 gethostname(localhost, 127);
2266 localhost[127] = '\0';
2267 if (strcmp(localhost, s) != 0)
2268 self->client_machine = s;
2274 static void client_change_wm_state(ObClient *self)
2279 old = self->wmstate;
2281 if (self->shaded || self->iconic ||
2282 (self->desktop != DESKTOP_ALL && self->desktop != screen_desktop))
2284 self->wmstate = IconicState;
2286 self->wmstate = NormalState;
2288 if (old != self->wmstate) {
2289 PROP_MSG(self->window, kde_wm_change_state,
2290 self->wmstate, 1, 0, 0);
2292 state[0] = self->wmstate;
2294 PROP_SETA32(self->window, wm_state, wm_state, state, 2);
2298 static void client_change_state(ObClient *self)
2300 gulong netstate[11];
2305 netstate[num++] = prop_atoms.net_wm_state_modal;
2307 netstate[num++] = prop_atoms.net_wm_state_shaded;
2309 netstate[num++] = prop_atoms.net_wm_state_hidden;
2310 if (self->skip_taskbar)
2311 netstate[num++] = prop_atoms.net_wm_state_skip_taskbar;
2312 if (self->skip_pager)
2313 netstate[num++] = prop_atoms.net_wm_state_skip_pager;
2314 if (self->fullscreen)
2315 netstate[num++] = prop_atoms.net_wm_state_fullscreen;
2317 netstate[num++] = prop_atoms.net_wm_state_maximized_vert;
2319 netstate[num++] = prop_atoms.net_wm_state_maximized_horz;
2321 netstate[num++] = prop_atoms.net_wm_state_above;
2323 netstate[num++] = prop_atoms.net_wm_state_below;
2324 if (self->demands_attention)
2325 netstate[num++] = prop_atoms.net_wm_state_demands_attention;
2326 if (self->undecorated)
2327 netstate[num++] = prop_atoms.ob_wm_state_undecorated;
2328 PROP_SETA32(self->window, net_wm_state, atom, netstate, num);
2331 frame_adjust_state(self->frame);
2334 ObClient *client_search_focus_tree(ObClient *self)
2339 for (it = self->transients; it; it = g_slist_next(it)) {
2340 if (client_focused(it->data)) return it->data;
2341 if ((ret = client_search_focus_tree(it->data))) return ret;
2346 ObClient *client_search_focus_tree_full(ObClient *self)
2348 if (self->transient_for) {
2349 if (self->transient_for != OB_TRAN_GROUP) {
2350 return client_search_focus_tree_full(self->transient_for);
2354 for (it = self->group->members; it; it = g_slist_next(it)) {
2355 if (it->data != self) {
2356 ObClient *c = it->data;
2358 if (client_focused(c)) return c;
2359 if ((c = client_search_focus_tree(it->data))) return c;
2365 /* this function checks the whole tree, the client_search_focus_tree
2366 does not, so we need to check this window */
2367 if (client_focused(self))
2369 return client_search_focus_tree(self);
2372 gboolean client_has_parent(ObClient *self)
2374 if (self->transient_for) {
2375 if (self->transient_for != OB_TRAN_GROUP) {
2376 if (client_normal(self->transient_for))
2379 else if (self->group) {
2382 for (it = self->group->members; it; it = g_slist_next(it)) {
2383 if (it->data != self && client_normal(it->data))
2391 static ObStackingLayer calc_layer(ObClient *self)
2395 if (self->type == OB_CLIENT_TYPE_DESKTOP)
2396 l = OB_STACKING_LAYER_DESKTOP;
2397 else if (self->type == OB_CLIENT_TYPE_DOCK) {
2398 if (self->below) l = OB_STACKING_LAYER_NORMAL;
2399 else l = OB_STACKING_LAYER_ABOVE;
2401 else if ((self->fullscreen ||
2402 /* No decorations and fills the monitor = oldskool fullscreen.
2403 But not for maximized windows.
2405 (self->decorations == 0 &&
2406 !(self->max_horz && self->max_vert) &&
2407 RECT_EQUAL(self->area,
2408 *screen_physical_area_monitor
2409 (client_monitor(self))))) &&
2410 (client_focused(self) || client_search_focus_tree(self)))
2411 l = OB_STACKING_LAYER_FULLSCREEN;
2412 else if (self->above) l = OB_STACKING_LAYER_ABOVE;
2413 else if (self->below) l = OB_STACKING_LAYER_BELOW;
2414 else l = OB_STACKING_LAYER_NORMAL;
2419 static void client_calc_layer_recursive(ObClient *self, ObClient *orig,
2420 ObStackingLayer min)
2422 ObStackingLayer old, own;
2426 own = calc_layer(self);
2427 self->layer = MAX(own, min);
2429 if (self->layer != old) {
2430 stacking_remove(CLIENT_AS_WINDOW(self));
2431 stacking_add_nonintrusive(CLIENT_AS_WINDOW(self));
2434 for (it = self->transients; it; it = g_slist_next(it))
2435 client_calc_layer_recursive(it->data, orig,
2439 void client_calc_layer(ObClient *self)
2446 /* transients take on the layer of their parents */
2447 it = client_search_all_top_parents(self);
2449 for (; it; it = g_slist_next(it))
2450 client_calc_layer_recursive(it->data, orig, 0);
2453 gboolean client_should_show(ObClient *self)
2457 if (client_normal(self) && screen_showing_desktop)
2459 if (self->desktop == screen_desktop || self->desktop == DESKTOP_ALL)
2465 gboolean client_show(ObClient *self)
2467 gboolean show = FALSE;
2469 if (client_should_show(self)) {
2470 frame_show(self->frame);
2473 /* According to the ICCCM (sec 4.1.3.1) when a window is not visible,
2474 it needs to be in IconicState. This includes when it is on another
2477 client_change_wm_state(self);
2482 gboolean client_hide(ObClient *self)
2484 gboolean hide = FALSE;
2486 if (!client_should_show(self)) {
2487 if (self == focus_client) {
2488 /* if there is a grab going on, then we need to cancel it. if we
2489 move focus during the grab, applications will get
2490 NotifyWhileGrabbed events and ignore them !
2492 actions should not rely on being able to move focus during an
2495 event_cancel_all_key_grabs();
2498 frame_hide(self->frame);
2501 /* According to the ICCCM (sec 4.1.3.1) when a window is not visible,
2502 it needs to be in IconicState. This includes when it is on another
2505 client_change_wm_state(self);
2510 void client_showhide(ObClient *self)
2512 if (!client_show(self))
2516 gboolean client_normal(ObClient *self) {
2517 return ! (self->type == OB_CLIENT_TYPE_DESKTOP ||
2518 self->type == OB_CLIENT_TYPE_DOCK ||
2519 self->type == OB_CLIENT_TYPE_SPLASH);
2522 gboolean client_helper(ObClient *self)
2524 return (self->type == OB_CLIENT_TYPE_UTILITY ||
2525 self->type == OB_CLIENT_TYPE_MENU ||
2526 self->type == OB_CLIENT_TYPE_TOOLBAR);
2529 gboolean client_mouse_focusable(ObClient *self)
2531 return !(self->type == OB_CLIENT_TYPE_MENU ||
2532 self->type == OB_CLIENT_TYPE_TOOLBAR ||
2533 self->type == OB_CLIENT_TYPE_SPLASH ||
2534 self->type == OB_CLIENT_TYPE_DOCK);
2537 gboolean client_enter_focusable(ObClient *self)
2539 /* you can focus desktops but it shouldn't on enter */
2540 return (client_mouse_focusable(self) &&
2541 self->type != OB_CLIENT_TYPE_DESKTOP);
2545 static void client_apply_startup_state(ObClient *self,
2546 gint x, gint y, gint w, gint h)
2548 /* save the states that we are going to apply */
2549 gboolean iconic = self->iconic;
2550 gboolean fullscreen = self->fullscreen;
2551 gboolean undecorated = self->undecorated;
2552 gboolean shaded = self->shaded;
2553 gboolean demands_attention = self->demands_attention;
2554 gboolean max_horz = self->max_horz;
2555 gboolean max_vert = self->max_vert;
2557 /* turn them all off in the client, so they won't affect the window
2559 self->iconic = self->fullscreen = self->undecorated = self->shaded =
2560 self->demands_attention = self->max_horz = self->max_vert = FALSE;
2562 /* move the client to its placed position, or it it's already there,
2563 generate a ConfigureNotify telling the client where it is.
2565 do this after adjusting the frame. otherwise it gets all weird and
2566 clients don't work right
2568 do this before applying the states so they have the correct
2569 pre-max/pre-fullscreen values
2571 client_configure(self, x, y, w, h, self->border_width, FALSE, TRUE);
2572 ob_debug("placed window 0x%x at %d, %d with size %d x %d\n",
2573 self->window, self->area.x, self->area.y,
2574 self->area.width, self->area.height);
2576 /* apply the states. these are in a carefully crafted order.. */
2579 client_iconify(self, TRUE, FALSE, TRUE);
2581 client_fullscreen(self, TRUE);
2583 client_set_undecorated(self, TRUE);
2585 client_shade(self, TRUE);
2586 if (demands_attention)
2587 client_hilite(self, TRUE);
2589 if (max_vert && max_horz)
2590 client_maximize(self, TRUE, 0);
2592 client_maximize(self, TRUE, 2);
2594 client_maximize(self, TRUE, 1);
2596 /* set the desktop hint, to make sure that it always exists */
2597 PROP_SET32(self->window, net_wm_desktop, cardinal, self->desktop);
2599 /* nothing to do for the other states:
2608 void client_gravity_resize_w(ObClient *self, gint *x, gint oldw, gint neww)
2610 /* these should be the current values. this is for when you're not moving,
2612 g_assert(*x == self->area.x);
2613 g_assert(oldw == self->area.width);
2616 switch (self->gravity) {
2618 case NorthWestGravity:
2620 case SouthWestGravity:
2627 *x -= (neww - oldw) / 2;
2629 case NorthEastGravity:
2631 case SouthEastGravity:
2637 void client_gravity_resize_h(ObClient *self, gint *y, gint oldh, gint newh)
2639 /* these should be the current values. this is for when you're not moving,
2641 g_assert(*y == self->area.y);
2642 g_assert(oldh == self->area.height);
2645 switch (self->gravity) {
2647 case NorthWestGravity:
2649 case NorthEastGravity:
2656 *y -= (newh - oldh) / 2;
2658 case SouthWestGravity:
2660 case SouthEastGravity:
2666 void client_try_configure(ObClient *self, gint *x, gint *y, gint *w, gint *h,
2667 gint *logicalw, gint *logicalh,
2670 Rect desired_area = {*x, *y, *w, *h};
2672 /* make the frame recalculate its dimentions n shit without changing
2673 anything visible for real, this way the constraints below can work with
2674 the updated frame dimensions. */
2675 frame_adjust_area(self->frame, FALSE, TRUE, TRUE);
2677 /* work within the prefered sizes given by the window */
2678 if (!(*w == self->area.width && *h == self->area.height)) {
2679 gint basew, baseh, minw, minh;
2681 /* base size is substituted with min size if not specified */
2682 if (self->base_size.width || self->base_size.height) {
2683 basew = self->base_size.width;
2684 baseh = self->base_size.height;
2686 basew = self->min_size.width;
2687 baseh = self->min_size.height;
2689 /* min size is substituted with base size if not specified */
2690 if (self->min_size.width || self->min_size.height) {
2691 minw = self->min_size.width;
2692 minh = self->min_size.height;
2694 minw = self->base_size.width;
2695 minh = self->base_size.height;
2698 /* if this is a user-requested resize, then check against min/max
2701 /* smaller than min size or bigger than max size? */
2702 if (*w > self->max_size.width) *w = self->max_size.width;
2703 if (*w < minw) *w = minw;
2704 if (*h > self->max_size.height) *h = self->max_size.height;
2705 if (*h < minh) *h = minh;
2710 /* keep to the increments */
2711 *w /= self->size_inc.width;
2712 *h /= self->size_inc.height;
2714 /* you cannot resize to nothing */
2715 if (basew + *w < 1) *w = 1 - basew;
2716 if (baseh + *h < 1) *h = 1 - baseh;
2718 /* save the logical size */
2719 *logicalw = self->size_inc.width > 1 ? *w : *w + basew;
2720 *logicalh = self->size_inc.height > 1 ? *h : *h + baseh;
2722 *w *= self->size_inc.width;
2723 *h *= self->size_inc.height;
2728 /* adjust the height to match the width for the aspect ratios.
2729 for this, min size is not substituted for base size ever. */
2730 *w -= self->base_size.width;
2731 *h -= self->base_size.height;
2733 if (!self->fullscreen) {
2734 if (self->min_ratio)
2735 if (*h * self->min_ratio > *w) {
2736 *h = (gint)(*w / self->min_ratio);
2738 /* you cannot resize to nothing */
2741 *w = (gint)(*h * self->min_ratio);
2744 if (self->max_ratio)
2745 if (*h * self->max_ratio < *w) {
2746 *h = (gint)(*w / self->max_ratio);
2748 /* you cannot resize to nothing */
2751 *w = (gint)(*h * self->min_ratio);
2756 *w += self->base_size.width;
2757 *h += self->base_size.height;
2760 /* gets the frame's position */
2761 frame_client_gravity(self->frame, x, y, *w, *h);
2763 /* these positions are frame positions, not client positions */
2765 /* set the size and position if fullscreen */
2766 if (self->fullscreen) {
2770 i = screen_find_monitor(&desired_area);
2771 a = screen_physical_area_monitor(i);
2778 user = FALSE; /* ignore if the client can't be moved/resized when it
2780 } else if (self->max_horz || self->max_vert) {
2784 i = screen_find_monitor(&desired_area);
2785 a = screen_area_monitor(self->desktop, i);
2787 /* set the size and position if maximized */
2788 if (self->max_horz) {
2790 *w = a->width - self->frame->size.left - self->frame->size.right;
2792 if (self->max_vert) {
2794 *h = a->height - self->frame->size.top - self->frame->size.bottom;
2797 user = FALSE; /* ignore if the client can't be moved/resized when it
2801 /* gets the client's position */
2802 frame_frame_gravity(self->frame, x, y, *w, *h);
2804 /* these override the above states! if you cant move you can't move! */
2806 if (!(self->functions & OB_CLIENT_FUNC_MOVE)) {
2810 if (!(self->functions & OB_CLIENT_FUNC_RESIZE)) {
2811 *w = self->area.width;
2812 *h = self->area.height;
2821 void client_configure(ObClient *self, gint x, gint y, gint w, gint h, gint b,
2822 gboolean user, gboolean final)
2825 gboolean send_resize_client;
2826 gboolean moved = FALSE, resized = FALSE;
2827 gboolean fmoved, fresized;
2828 guint fdecor = self->frame->decorations;
2829 gboolean fhorz = self->frame->max_horz;
2830 gboolean fvert = self->frame->max_vert;
2831 gint logicalw, logicalh;
2833 /* find the new x, y, width, and height (and logical size) */
2834 client_try_configure(self, &x, &y, &w, &h, &logicalw, &logicalh, user);
2836 /* set the logical size if things changed */
2837 if (!(w == self->area.width && h == self->area.height))
2838 SIZE_SET(self->logical_size, logicalw, logicalh);
2840 /* figure out if we moved or resized or what */
2841 moved = x != self->area.x || y != self->area.y;
2842 resized = w != self->area.width || h != self->area.height ||
2843 b != self->border_width;
2845 oldw = self->area.width;
2846 oldh = self->area.height;
2847 RECT_SET(self->area, x, y, w, h);
2848 self->border_width = b;
2850 /* for app-requested resizes, always resize if 'resized' is true.
2851 for user-requested ones, only resize if final is true, or when
2852 resizing in redraw mode */
2853 send_resize_client = ((!user && resized) ||
2855 (resized && config_resize_redraw))));
2857 /* if the client is enlarging, then resize the client before the frame */
2858 if (send_resize_client && (w > oldw || h > oldh)) {
2859 XWindowChanges changes;
2860 changes.x = -self->border_width;
2861 changes.y = -self->border_width;
2862 changes.width = MAX(w, oldw);
2863 changes.height = MAX(h, oldh);
2864 changes.border_width = self->border_width;
2865 XConfigureWindow(ob_display, self->window,
2866 CWX|CWY|CWWidth|CWHeight|CWBorderWidth,
2868 /* resize the plate to show the client padding color underneath */
2869 frame_adjust_client_area(self->frame);
2872 /* find the frame's dimensions and move/resize it */
2876 /* if decorations changed, then readjust everything for the frame */
2877 if (self->decorations != fdecor ||
2878 self->max_horz != fhorz || self->max_vert != fvert)
2880 fmoved = fresized = TRUE;
2883 /* adjust the frame */
2884 if (fmoved || fresized)
2885 frame_adjust_area(self->frame, fmoved, fresized, FALSE);
2887 if ((!user || (user && final)) && !resized)
2891 /* we have reset the client to 0 border width, so don't include
2892 it in these coords */
2893 POINT_SET(self->root_pos,
2894 self->frame->area.x + self->frame->size.left -
2896 self->frame->area.y + self->frame->size.top -
2897 self->border_width);
2899 event.type = ConfigureNotify;
2900 event.xconfigure.display = ob_display;
2901 event.xconfigure.event = self->window;
2902 event.xconfigure.window = self->window;
2904 ob_debug("Sending ConfigureNotify to %s for %d,%d %dx%d\n",
2905 self->title, self->root_pos.x, self->root_pos.y, w, h);
2907 /* root window real coords */
2908 event.xconfigure.x = self->root_pos.x;
2909 event.xconfigure.y = self->root_pos.y;
2910 event.xconfigure.width = w;
2911 event.xconfigure.height = h;
2912 event.xconfigure.border_width = self->border_width;
2913 event.xconfigure.above = None;
2914 event.xconfigure.override_redirect = FALSE;
2915 XSendEvent(event.xconfigure.display, event.xconfigure.window,
2916 FALSE, StructureNotifyMask, &event);
2919 /* if the client is shrinking, then resize the frame before the client */
2920 if (send_resize_client && (w <= oldw && h <= oldh)) {
2921 /* resize the plate to show the client padding color underneath */
2922 frame_adjust_client_area(self->frame);
2924 if (send_resize_client) {
2925 XWindowChanges changes;
2926 changes.x = -self->border_width;
2927 changes.y = -self->border_width;
2930 changes.border_width = self->border_width;
2931 XConfigureWindow(ob_display, self->window,
2932 CWX|CWY|CWWidth|CWHeight|CWBorderWidth,
2940 void client_fullscreen(ObClient *self, gboolean fs)
2944 if (!(self->functions & OB_CLIENT_FUNC_FULLSCREEN) || /* can't */
2945 self->fullscreen == fs) return; /* already done */
2947 self->fullscreen = fs;
2948 client_change_state(self); /* change the state hints on the client */
2951 self->pre_fullscreen_area = self->area;
2952 /* if the window is maximized, its area isn't all that meaningful.
2953 save it's premax area instead. */
2954 if (self->max_horz) {
2955 self->pre_fullscreen_area.x = self->pre_max_area.x;
2956 self->pre_fullscreen_area.width = self->pre_max_area.width;
2958 if (self->max_vert) {
2959 self->pre_fullscreen_area.y = self->pre_max_area.y;
2960 self->pre_fullscreen_area.height = self->pre_max_area.height;
2963 /* these will help configure_full figure out where to fullscreen
2967 w = self->area.width;
2968 h = self->area.height;
2970 g_assert(self->pre_fullscreen_area.width > 0 &&
2971 self->pre_fullscreen_area.height > 0);
2973 x = self->pre_fullscreen_area.x;
2974 y = self->pre_fullscreen_area.y;
2975 w = self->pre_fullscreen_area.width;
2976 h = self->pre_fullscreen_area.height;
2977 RECT_SET(self->pre_fullscreen_area, 0, 0, 0, 0);
2980 client_setup_decor_and_functions(self, FALSE);
2981 client_move_resize(self, x, y, w, h);
2983 /* and adjust our layer/stacking. do this after resizing the window,
2984 and applying decorations, because windows which fill the screen are
2985 considered "fullscreen" and it affects their layer */
2986 client_calc_layer(self);
2989 /* try focus us when we go into fullscreen mode */
2994 static void client_iconify_recursive(ObClient *self,
2995 gboolean iconic, gboolean curdesk,
2996 gboolean hide_animation)
2999 gboolean changed = FALSE;
3002 if (self->iconic != iconic) {
3003 ob_debug("%sconifying window: 0x%lx\n", (iconic ? "I" : "Uni"),
3007 /* don't let non-normal windows iconify along with their parents
3009 if (client_normal(self)) {
3010 self->iconic = iconic;
3012 /* update the focus lists.. iconic windows go to the bottom of
3014 focus_order_to_bottom(self);
3019 self->iconic = iconic;
3021 if (curdesk && self->desktop != screen_desktop &&
3022 self->desktop != DESKTOP_ALL)
3023 client_set_desktop(self, screen_desktop, FALSE);
3025 /* this puts it after the current focused window */
3026 focus_order_remove(self);
3027 focus_order_add_new(self);
3034 client_change_state(self);
3035 if (config_animate_iconify && !hide_animation)
3036 frame_begin_iconify_animation(self->frame, iconic);
3037 /* do this after starting the animation so it doesn't flash */
3038 client_showhide(self);
3041 /* iconify all direct transients, and deiconify all transients
3043 for (it = self->transients; it; it = g_slist_next(it))
3044 if (it->data != self)
3045 if (client_is_direct_child(self, it->data) || !iconic)
3046 client_iconify_recursive(it->data, iconic, curdesk,
3050 void client_iconify(ObClient *self, gboolean iconic, gboolean curdesk,
3051 gboolean hide_animation)
3053 if (self->functions & OB_CLIENT_FUNC_ICONIFY || !iconic) {
3054 /* move up the transient chain as far as possible first */
3055 self = client_search_top_normal_parent(self);
3056 client_iconify_recursive(self, iconic, curdesk, hide_animation);
3060 void client_maximize(ObClient *self, gboolean max, gint dir)
3064 g_assert(dir == 0 || dir == 1 || dir == 2);
3065 if (!(self->functions & OB_CLIENT_FUNC_MAXIMIZE)) return; /* can't */
3067 /* check if already done */
3069 if (dir == 0 && self->max_horz && self->max_vert) return;
3070 if (dir == 1 && self->max_horz) return;
3071 if (dir == 2 && self->max_vert) return;
3073 if (dir == 0 && !self->max_horz && !self->max_vert) return;
3074 if (dir == 1 && !self->max_horz) return;
3075 if (dir == 2 && !self->max_vert) return;
3078 /* these will help configure_full figure out which screen to fill with
3082 w = self->area.width;
3083 h = self->area.height;
3086 if ((dir == 0 || dir == 1) && !self->max_horz) { /* horz */
3087 RECT_SET(self->pre_max_area,
3088 self->area.x, self->pre_max_area.y,
3089 self->area.width, self->pre_max_area.height);
3091 if ((dir == 0 || dir == 2) && !self->max_vert) { /* vert */
3092 RECT_SET(self->pre_max_area,
3093 self->pre_max_area.x, self->area.y,
3094 self->pre_max_area.width, self->area.height);
3097 if ((dir == 0 || dir == 1) && self->max_horz) { /* horz */
3098 g_assert(self->pre_max_area.width > 0);
3100 x = self->pre_max_area.x;
3101 w = self->pre_max_area.width;
3103 RECT_SET(self->pre_max_area, 0, self->pre_max_area.y,
3104 0, self->pre_max_area.height);
3106 if ((dir == 0 || dir == 2) && self->max_vert) { /* vert */
3107 g_assert(self->pre_max_area.height > 0);
3109 y = self->pre_max_area.y;
3110 h = self->pre_max_area.height;
3112 RECT_SET(self->pre_max_area, self->pre_max_area.x, 0,
3113 self->pre_max_area.width, 0);
3117 if (dir == 0 || dir == 1) /* horz */
3118 self->max_horz = max;
3119 if (dir == 0 || dir == 2) /* vert */
3120 self->max_vert = max;
3122 client_change_state(self); /* change the state hints on the client */
3124 client_setup_decor_and_functions(self, FALSE);
3125 client_move_resize(self, x, y, w, h);
3128 void client_shade(ObClient *self, gboolean shade)
3130 if ((!(self->functions & OB_CLIENT_FUNC_SHADE) &&
3131 shade) || /* can't shade */
3132 self->shaded == shade) return; /* already done */
3134 self->shaded = shade;
3135 client_change_state(self);
3136 client_change_wm_state(self); /* the window is being hidden/shown */
3137 /* resize the frame to just the titlebar */
3138 frame_adjust_area(self->frame, FALSE, FALSE, FALSE);
3141 void client_close(ObClient *self)
3145 if (!(self->functions & OB_CLIENT_FUNC_CLOSE)) return;
3147 /* in the case that the client provides no means to requesting that it
3148 close, we just kill it */
3149 if (!self->delete_window)
3153 XXX: itd be cool to do timeouts and shit here for killing the client's
3155 like... if the window is around after 5 seconds, then the close button
3156 turns a nice red, and if this function is called again, the client is
3160 ce.xclient.type = ClientMessage;
3161 ce.xclient.message_type = prop_atoms.wm_protocols;
3162 ce.xclient.display = ob_display;
3163 ce.xclient.window = self->window;
3164 ce.xclient.format = 32;
3165 ce.xclient.data.l[0] = prop_atoms.wm_delete_window;
3166 ce.xclient.data.l[1] = event_curtime;
3167 ce.xclient.data.l[2] = 0l;
3168 ce.xclient.data.l[3] = 0l;
3169 ce.xclient.data.l[4] = 0l;
3170 XSendEvent(ob_display, self->window, FALSE, NoEventMask, &ce);
3173 void client_kill(ObClient *self)
3175 XKillClient(ob_display, self->window);
3178 void client_hilite(ObClient *self, gboolean hilite)
3180 if (self->demands_attention == hilite)
3181 return; /* no change */
3183 /* don't allow focused windows to hilite */
3184 self->demands_attention = hilite && !client_focused(self);
3185 if (self->frame != NULL) { /* if we're mapping, just set the state */
3186 if (self->demands_attention)
3187 frame_flash_start(self->frame);
3189 frame_flash_stop(self->frame);
3190 client_change_state(self);
3194 void client_set_desktop_recursive(ObClient *self,
3201 if (target != self->desktop && self->type != OB_CLIENT_TYPE_DESKTOP) {
3203 ob_debug("Setting desktop %u\n", target+1);
3205 g_assert(target < screen_num_desktops || target == DESKTOP_ALL);
3207 old = self->desktop;
3208 self->desktop = target;
3209 PROP_SET32(self->window, net_wm_desktop, cardinal, target);
3210 /* the frame can display the current desktop state */
3211 frame_adjust_state(self->frame);
3212 /* 'move' the window to the new desktop */
3214 client_showhide(self);
3215 /* raise if it was not already on the desktop */
3216 if (old != DESKTOP_ALL)
3217 stacking_raise(CLIENT_AS_WINDOW(self));
3218 if (STRUT_EXISTS(self->strut))
3219 screen_update_areas();
3222 /* move all transients */
3223 for (it = self->transients; it; it = g_slist_next(it))
3224 if (it->data != self)
3225 if (client_is_direct_child(self, it->data))
3226 client_set_desktop_recursive(it->data, target, donthide);
3229 void client_set_desktop(ObClient *self, guint target,
3232 self = client_search_top_normal_parent(self);
3233 client_set_desktop_recursive(self, target, donthide);
3236 gboolean client_is_direct_child(ObClient *parent, ObClient *child)
3238 while (child != parent &&
3239 child->transient_for && child->transient_for != OB_TRAN_GROUP)
3240 child = child->transient_for;
3241 return child == parent;
3244 ObClient *client_search_modal_child(ObClient *self)
3249 for (it = self->transients; it; it = g_slist_next(it)) {
3250 ObClient *c = it->data;
3251 if ((ret = client_search_modal_child(c))) return ret;
3252 if (c->modal) return c;
3257 gboolean client_validate(ObClient *self)
3261 XSync(ob_display, FALSE); /* get all events on the server */
3263 if (XCheckTypedWindowEvent(ob_display, self->window, DestroyNotify, &e) ||
3264 XCheckTypedWindowEvent(ob_display, self->window, UnmapNotify, &e)) {
3265 XPutBackEvent(ob_display, &e);
3272 void client_set_wm_state(ObClient *self, glong state)
3274 if (state == self->wmstate) return; /* no change */
3278 client_iconify(self, TRUE, TRUE, FALSE);
3281 client_iconify(self, FALSE, TRUE, FALSE);
3286 void client_set_state(ObClient *self, Atom action, glong data1, glong data2)
3288 gboolean shaded = self->shaded;
3289 gboolean fullscreen = self->fullscreen;
3290 gboolean undecorated = self->undecorated;
3291 gboolean max_horz = self->max_horz;
3292 gboolean max_vert = self->max_vert;
3293 gboolean modal = self->modal;
3294 gboolean iconic = self->iconic;
3295 gboolean demands_attention = self->demands_attention;
3296 gboolean above = self->above;
3297 gboolean below = self->below;
3300 if (!(action == prop_atoms.net_wm_state_add ||
3301 action == prop_atoms.net_wm_state_remove ||
3302 action == prop_atoms.net_wm_state_toggle))
3303 /* an invalid action was passed to the client message, ignore it */
3306 for (i = 0; i < 2; ++i) {
3307 Atom state = i == 0 ? data1 : data2;
3309 if (!state) continue;
3311 /* if toggling, then pick whether we're adding or removing */
3312 if (action == prop_atoms.net_wm_state_toggle) {
3313 if (state == prop_atoms.net_wm_state_modal)
3314 action = modal ? prop_atoms.net_wm_state_remove :
3315 prop_atoms.net_wm_state_add;
3316 else if (state == prop_atoms.net_wm_state_maximized_vert)
3317 action = self->max_vert ? prop_atoms.net_wm_state_remove :
3318 prop_atoms.net_wm_state_add;
3319 else if (state == prop_atoms.net_wm_state_maximized_horz)
3320 action = self->max_horz ? prop_atoms.net_wm_state_remove :
3321 prop_atoms.net_wm_state_add;
3322 else if (state == prop_atoms.net_wm_state_shaded)
3323 action = shaded ? prop_atoms.net_wm_state_remove :
3324 prop_atoms.net_wm_state_add;
3325 else if (state == prop_atoms.net_wm_state_skip_taskbar)
3326 action = self->skip_taskbar ?
3327 prop_atoms.net_wm_state_remove :
3328 prop_atoms.net_wm_state_add;
3329 else if (state == prop_atoms.net_wm_state_skip_pager)
3330 action = self->skip_pager ?
3331 prop_atoms.net_wm_state_remove :
3332 prop_atoms.net_wm_state_add;
3333 else if (state == prop_atoms.net_wm_state_hidden)
3334 action = self->iconic ?
3335 prop_atoms.net_wm_state_remove :
3336 prop_atoms.net_wm_state_add;
3337 else if (state == prop_atoms.net_wm_state_fullscreen)
3338 action = fullscreen ?
3339 prop_atoms.net_wm_state_remove :
3340 prop_atoms.net_wm_state_add;
3341 else if (state == prop_atoms.net_wm_state_above)
3342 action = self->above ? prop_atoms.net_wm_state_remove :
3343 prop_atoms.net_wm_state_add;
3344 else if (state == prop_atoms.net_wm_state_below)
3345 action = self->below ? prop_atoms.net_wm_state_remove :
3346 prop_atoms.net_wm_state_add;
3347 else if (state == prop_atoms.net_wm_state_demands_attention)
3348 action = self->demands_attention ?
3349 prop_atoms.net_wm_state_remove :
3350 prop_atoms.net_wm_state_add;
3351 else if (state == prop_atoms.ob_wm_state_undecorated)
3352 action = undecorated ? prop_atoms.net_wm_state_remove :
3353 prop_atoms.net_wm_state_add;
3356 if (action == prop_atoms.net_wm_state_add) {
3357 if (state == prop_atoms.net_wm_state_modal) {
3359 } else if (state == prop_atoms.net_wm_state_maximized_vert) {
3361 } else if (state == prop_atoms.net_wm_state_maximized_horz) {
3363 } else if (state == prop_atoms.net_wm_state_shaded) {
3365 } else if (state == prop_atoms.net_wm_state_skip_taskbar) {
3366 self->skip_taskbar = TRUE;
3367 } else if (state == prop_atoms.net_wm_state_skip_pager) {
3368 self->skip_pager = TRUE;
3369 } else if (state == prop_atoms.net_wm_state_hidden) {
3371 } else if (state == prop_atoms.net_wm_state_fullscreen) {
3373 } else if (state == prop_atoms.net_wm_state_above) {
3376 } else if (state == prop_atoms.net_wm_state_below) {
3379 } else if (state == prop_atoms.net_wm_state_demands_attention) {
3380 demands_attention = TRUE;
3381 } else if (state == prop_atoms.ob_wm_state_undecorated) {
3385 } else { /* action == prop_atoms.net_wm_state_remove */
3386 if (state == prop_atoms.net_wm_state_modal) {
3388 } else if (state == prop_atoms.net_wm_state_maximized_vert) {
3390 } else if (state == prop_atoms.net_wm_state_maximized_horz) {
3392 } else if (state == prop_atoms.net_wm_state_shaded) {
3394 } else if (state == prop_atoms.net_wm_state_skip_taskbar) {
3395 self->skip_taskbar = FALSE;
3396 } else if (state == prop_atoms.net_wm_state_skip_pager) {
3397 self->skip_pager = FALSE;
3398 } else if (state == prop_atoms.net_wm_state_hidden) {
3400 } else if (state == prop_atoms.net_wm_state_fullscreen) {
3402 } else if (state == prop_atoms.net_wm_state_above) {
3404 } else if (state == prop_atoms.net_wm_state_below) {
3406 } else if (state == prop_atoms.net_wm_state_demands_attention) {
3407 demands_attention = FALSE;
3408 } else if (state == prop_atoms.ob_wm_state_undecorated) {
3409 undecorated = FALSE;
3414 if (max_horz != self->max_horz || max_vert != self->max_vert) {
3415 if (max_horz != self->max_horz && max_vert != self->max_vert) {
3417 if (max_horz == max_vert) { /* both going the same way */
3418 client_maximize(self, max_horz, 0);
3420 client_maximize(self, max_horz, 1);
3421 client_maximize(self, max_vert, 2);
3425 if (max_horz != self->max_horz)
3426 client_maximize(self, max_horz, 1);
3428 client_maximize(self, max_vert, 2);
3431 /* change fullscreen state before shading, as it will affect if the window
3433 if (fullscreen != self->fullscreen)
3434 client_fullscreen(self, fullscreen);
3435 if (shaded != self->shaded)
3436 client_shade(self, shaded);
3437 if (undecorated != self->undecorated)
3438 client_set_undecorated(self, undecorated);
3439 if (above != self->above || below != self->below) {
3440 self->above = above;
3441 self->below = below;
3442 client_calc_layer(self);
3445 if (modal != self->modal) {
3446 self->modal = modal;
3447 /* when a window changes modality, then its stacking order with its
3448 transients needs to change */
3449 stacking_raise(CLIENT_AS_WINDOW(self));
3451 /* it also may get focused. if something is focused that shouldn't
3452 be focused anymore, then move the focus */
3453 if (focus_client && client_focus_target(focus_client) != focus_client)
3454 client_focus(focus_client);
3457 if (iconic != self->iconic)
3458 client_iconify(self, iconic, FALSE, FALSE);
3460 if (demands_attention != self->demands_attention)
3461 client_hilite(self, demands_attention);
3463 client_change_state(self); /* change the hint to reflect these changes */
3466 ObClient *client_focus_target(ObClient *self)
3468 ObClient *child = NULL;
3470 child = client_search_modal_child(self);
3471 if (child) return child;
3475 gboolean client_can_focus(ObClient *self)
3477 /* choose the correct target */
3478 self = client_focus_target(self);
3480 if (!self->frame->visible)
3483 if (!(self->can_focus || self->focus_notify))
3489 gboolean client_focus(ObClient *self)
3491 /* we might not focus this window, so if we have modal children which would
3492 be focused instead, bring them to this desktop */
3493 client_bring_modal_windows(self);
3495 /* choose the correct target */
3496 self = client_focus_target(self);
3498 if (!client_can_focus(self)) {
3499 if (!self->frame->visible) {
3500 /* update the focus lists */
3501 focus_order_to_top(self);
3503 ob_debug_type(OB_DEBUG_FOCUS,
3504 "Client %s can't be focused\n", self->title);
3508 ob_debug_type(OB_DEBUG_FOCUS,
3509 "Focusing client \"%s\" (0x%x) at time %u\n",
3510 self->title, self->window, event_curtime);
3512 /* if there is a grab going on, then we need to cancel it. if we move
3513 focus during the grab, applications will get NotifyWhileGrabbed events
3516 actions should not rely on being able to move focus during an
3519 event_cancel_all_key_grabs();
3521 xerror_set_ignore(TRUE);
3522 xerror_occured = FALSE;
3524 if (self->can_focus) {
3525 /* This can cause a BadMatch error with CurrentTime, or if an app
3526 passed in a bad time for _NET_WM_ACTIVE_WINDOW. */
3527 XSetInputFocus(ob_display, self->window, RevertToPointerRoot,
3531 if (self->focus_notify) {
3533 ce.xclient.type = ClientMessage;
3534 ce.xclient.message_type = prop_atoms.wm_protocols;
3535 ce.xclient.display = ob_display;
3536 ce.xclient.window = self->window;
3537 ce.xclient.format = 32;
3538 ce.xclient.data.l[0] = prop_atoms.wm_take_focus;
3539 ce.xclient.data.l[1] = event_curtime;
3540 ce.xclient.data.l[2] = 0l;
3541 ce.xclient.data.l[3] = 0l;
3542 ce.xclient.data.l[4] = 0l;
3543 XSendEvent(ob_display, self->window, FALSE, NoEventMask, &ce);
3546 xerror_set_ignore(FALSE);
3548 ob_debug_type(OB_DEBUG_FOCUS, "Error focusing? %d\n", xerror_occured);
3549 return !xerror_occured;
3552 /*! Present the client to the user.
3553 @param raise If the client should be raised or not. You should only set
3554 raise to false if you don't care if the window is completely
3557 static void client_present(ObClient *self, gboolean here, gboolean raise)
3559 /* if using focus_delay, stop the timer now so that focus doesn't
3561 event_halt_focus_delay();
3563 if (client_normal(self) && screen_showing_desktop)
3564 screen_show_desktop(FALSE, self);
3566 client_iconify(self, FALSE, here, FALSE);
3567 if (self->desktop != DESKTOP_ALL &&
3568 self->desktop != screen_desktop)
3571 client_set_desktop(self, screen_desktop, FALSE);
3573 screen_set_desktop(self->desktop, FALSE);
3574 } else if (!self->frame->visible)
3575 /* if its not visible for other reasons, then don't mess
3579 client_shade(self, FALSE);
3581 stacking_raise(CLIENT_AS_WINDOW(self));
3586 void client_activate(ObClient *self, gboolean here, gboolean user)
3588 guint32 last_time = focus_client ? focus_client->user_time : CurrentTime;
3589 gboolean allow = FALSE;
3591 /* if the request came from the user, or if nothing is focused, then grant
3593 if the currently focused app doesn't set a user_time, then it can't
3594 benefit from any focus stealing prevention.
3596 if (user || !focus_client || !last_time)
3598 /* otherwise, if they didn't give a time stamp or if it is too old, they
3601 allow = event_curtime && event_time_after(event_curtime, last_time);
3603 ob_debug_type(OB_DEBUG_FOCUS,
3604 "Want to activate window 0x%x with time %u (last time %u), "
3605 "source=%s allowing? %d\n",
3606 self->window, event_curtime, last_time,
3607 (user ? "user" : "application"), allow);
3610 client_present(self, here, TRUE);
3612 /* don't focus it but tell the user it wants attention */
3613 client_hilite(self, TRUE);
3616 static void client_bring_windows_recursive(ObClient *self,
3623 for (it = self->transients; it; it = g_slist_next(it))
3624 client_bring_windows_recursive(it->data, desktop, helpers, modals);
3626 if (((helpers && client_helper(self)) ||
3627 (modals && self->modal))&&
3628 self->desktop != desktop && self->desktop != DESKTOP_ALL)
3630 client_set_desktop(self, desktop, FALSE);
3634 void client_bring_helper_windows(ObClient *self)
3636 client_bring_windows_recursive(self, self->desktop, TRUE, FALSE);
3639 void client_bring_modal_windows(ObClient *self)
3641 client_bring_windows_recursive(self, self->desktop, FALSE, TRUE);
3644 gboolean client_focused(ObClient *self)
3646 return self == focus_client;
3649 static ObClientIcon* client_icon_recursive(ObClient *self, gint w, gint h)
3652 gulong min_diff, min_i;
3654 if (!self->nicons) {
3655 ObClientIcon *parent = NULL;
3657 if (self->transient_for) {
3658 if (self->transient_for != OB_TRAN_GROUP)
3659 parent = client_icon_recursive(self->transient_for, w, h);
3662 for (it = self->group->members; it; it = g_slist_next(it)) {
3663 ObClient *c = it->data;
3664 if (c != self && !c->transient_for) {
3665 if ((parent = client_icon_recursive(c, w, h)))
3675 /* some kind of crappy approximation to find the icon closest in size to
3676 what we requested, but icons are generally all the same ratio as
3677 eachother so it's good enough. */
3679 min_diff = ABS(self->icons[0].width - w) + ABS(self->icons[0].height - h);
3682 for (i = 1; i < self->nicons; ++i) {
3685 diff = ABS(self->icons[i].width - w) + ABS(self->icons[i].height - h);
3686 if (diff < min_diff) {
3691 return &self->icons[min_i];
3694 const ObClientIcon* client_icon(ObClient *self, gint w, gint h)
3697 static ObClientIcon deficon;
3699 if (!(ret = client_icon_recursive(self, w, h))) {
3700 deficon.width = deficon.height = 48;
3701 deficon.data = ob_rr_theme->def_win_icon;
3707 void client_set_layer(ObClient *self, gint layer)
3711 self->above = FALSE;
3712 } else if (layer == 0) {
3713 self->below = self->above = FALSE;
3715 self->below = FALSE;
3718 client_calc_layer(self);
3719 client_change_state(self); /* reflect this in the state hints */
3722 void client_set_undecorated(ObClient *self, gboolean undecorated)
3724 if (self->undecorated != undecorated &&
3725 /* don't let it undecorate if the function is missing, but let
3727 (self->functions & OB_CLIENT_FUNC_UNDECORATE || !undecorated))
3729 self->undecorated = undecorated;
3730 client_setup_decor_and_functions(self, TRUE);
3731 client_change_state(self); /* reflect this in the state hints */
3735 guint client_monitor(ObClient *self)
3737 return screen_find_monitor(&self->frame->area);
3740 ObClient *client_search_top_normal_parent(ObClient *self)
3742 while (self->transient_for && self->transient_for != OB_TRAN_GROUP &&
3743 client_normal(self->transient_for))
3744 self = self->transient_for;
3748 static GSList *client_search_all_top_parents_internal(ObClient *self,
3750 ObStackingLayer layer)
3754 /* move up the direct transient chain as far as possible */
3755 while (self->transient_for && self->transient_for != OB_TRAN_GROUP &&
3756 (!bylayer || self->transient_for->layer == layer) &&
3757 client_normal(self->transient_for))
3758 self = self->transient_for;
3760 if (!self->transient_for)
3761 ret = g_slist_prepend(ret, self);
3765 g_assert(self->group);
3767 for (it = self->group->members; it; it = g_slist_next(it)) {
3768 ObClient *c = it->data;
3770 if (!c->transient_for && client_normal(c) &&
3771 (!bylayer || c->layer == layer))
3773 ret = g_slist_prepend(ret, c);
3777 if (ret == NULL) /* no group parents */
3778 ret = g_slist_prepend(ret, self);
3784 GSList *client_search_all_top_parents(ObClient *self)
3786 return client_search_all_top_parents_internal(self, FALSE, 0);
3789 GSList *client_search_all_top_parents_layer(ObClient *self)
3791 return client_search_all_top_parents_internal(self, TRUE, self->layer);
3794 ObClient *client_search_focus_parent(ObClient *self)
3796 if (self->transient_for) {
3797 if (self->transient_for != OB_TRAN_GROUP) {
3798 if (client_focused(self->transient_for))
3799 return self->transient_for;
3803 for (it = self->group->members; it; it = g_slist_next(it)) {
3804 ObClient *c = it->data;
3806 /* checking transient_for prevents infinate loops! */
3807 if (c != self && !c->transient_for)
3808 if (client_focused(c))
3817 ObClient *client_search_parent(ObClient *self, ObClient *search)
3819 if (self->transient_for) {
3820 if (self->transient_for != OB_TRAN_GROUP) {
3821 if (self->transient_for == search)
3826 for (it = self->group->members; it; it = g_slist_next(it)) {
3827 ObClient *c = it->data;
3829 /* checking transient_for prevents infinate loops! */
3830 if (c != self && !c->transient_for)
3840 ObClient *client_search_transient(ObClient *self, ObClient *search)
3844 for (sit = self->transients; sit; sit = g_slist_next(sit)) {
3845 if (sit->data == search)
3847 if (client_search_transient(sit->data, search))
3853 #define WANT_EDGE(cur, c) \
3856 if(!client_normal(cur)) \
3858 if(screen_desktop != cur->desktop && cur->desktop != DESKTOP_ALL) \
3863 #define HIT_EDGE(my_edge_start, my_edge_end, his_edge_start, his_edge_end) \
3864 if ((his_edge_start >= my_edge_start && \
3865 his_edge_start <= my_edge_end) || \
3866 (my_edge_start >= his_edge_start && \
3867 my_edge_start <= his_edge_end)) \
3870 /* finds the nearest edge in the given direction from the current client
3871 * note to self: the edge is the -frame- edge (the actual one), not the
3874 gint client_directional_edge_search(ObClient *c, ObDirection dir, gboolean hang)
3876 gint dest, monitor_dest;
3877 gint my_edge_start, my_edge_end, my_offset;
3884 a = screen_area(c->desktop);
3885 monitor = screen_area_monitor(c->desktop, client_monitor(c));
3888 case OB_DIRECTION_NORTH:
3889 my_edge_start = c->frame->area.x;
3890 my_edge_end = c->frame->area.x + c->frame->area.width;
3891 my_offset = c->frame->area.y + (hang ? c->frame->area.height : 0);
3893 /* default: top of screen */
3894 dest = a->y + (hang ? c->frame->area.height : 0);
3895 monitor_dest = monitor->y + (hang ? c->frame->area.height : 0);
3896 /* if the monitor edge comes before the screen edge, */
3897 /* use that as the destination instead. (For xinerama) */
3898 if (monitor_dest != dest && my_offset > monitor_dest)
3899 dest = monitor_dest;
3901 for(it = client_list; it && my_offset != dest; it = g_list_next(it)) {
3902 gint his_edge_start, his_edge_end, his_offset;
3903 ObClient *cur = it->data;
3907 his_edge_start = cur->frame->area.x;
3908 his_edge_end = cur->frame->area.x + cur->frame->area.width;
3909 his_offset = cur->frame->area.y +
3910 (hang ? 0 : cur->frame->area.height);
3912 if(his_offset + 1 > my_offset)
3915 if(his_offset < dest)
3918 HIT_EDGE(my_edge_start, my_edge_end, his_edge_start, his_edge_end)
3921 case OB_DIRECTION_SOUTH:
3922 my_edge_start = c->frame->area.x;
3923 my_edge_end = c->frame->area.x + c->frame->area.width;
3924 my_offset = c->frame->area.y + (hang ? 0 : c->frame->area.height);
3926 /* default: bottom of screen */
3927 dest = a->y + a->height - (hang ? c->frame->area.height : 0);
3928 monitor_dest = monitor->y + monitor->height -
3929 (hang ? c->frame->area.height : 0);
3930 /* if the monitor edge comes before the screen edge, */
3931 /* use that as the destination instead. (For xinerama) */
3932 if (monitor_dest != dest && my_offset < monitor_dest)
3933 dest = monitor_dest;
3935 for(it = client_list; it && my_offset != dest; it = g_list_next(it)) {
3936 gint his_edge_start, his_edge_end, his_offset;
3937 ObClient *cur = it->data;
3941 his_edge_start = cur->frame->area.x;
3942 his_edge_end = cur->frame->area.x + cur->frame->area.width;
3943 his_offset = cur->frame->area.y +
3944 (hang ? cur->frame->area.height : 0);
3947 if(his_offset - 1 < my_offset)
3950 if(his_offset > dest)
3953 HIT_EDGE(my_edge_start, my_edge_end, his_edge_start, his_edge_end)
3956 case OB_DIRECTION_WEST:
3957 my_edge_start = c->frame->area.y;
3958 my_edge_end = c->frame->area.y + c->frame->area.height;
3959 my_offset = c->frame->area.x + (hang ? c->frame->area.width : 0);
3961 /* default: leftmost egde of screen */
3962 dest = a->x + (hang ? c->frame->area.width : 0);
3963 monitor_dest = monitor->x + (hang ? c->frame->area.width : 0);
3964 /* if the monitor edge comes before the screen edge, */
3965 /* use that as the destination instead. (For xinerama) */
3966 if (monitor_dest != dest && my_offset > monitor_dest)
3967 dest = monitor_dest;
3969 for(it = client_list; it && my_offset != dest; it = g_list_next(it)) {
3970 gint his_edge_start, his_edge_end, his_offset;
3971 ObClient *cur = it->data;
3975 his_edge_start = cur->frame->area.y;
3976 his_edge_end = cur->frame->area.y + cur->frame->area.height;
3977 his_offset = cur->frame->area.x +
3978 (hang ? 0 : cur->frame->area.width);
3980 if(his_offset + 1 > my_offset)
3983 if(his_offset < dest)
3986 HIT_EDGE(my_edge_start, my_edge_end, his_edge_start, his_edge_end)
3989 case OB_DIRECTION_EAST:
3990 my_edge_start = c->frame->area.y;
3991 my_edge_end = c->frame->area.y + c->frame->area.height;
3992 my_offset = c->frame->area.x + (hang ? 0 : c->frame->area.width);
3994 /* default: rightmost edge of screen */
3995 dest = a->x + a->width - (hang ? c->frame->area.width : 0);
3996 monitor_dest = monitor->x + monitor->width -
3997 (hang ? c->frame->area.width : 0);
3998 /* if the monitor edge comes before the screen edge, */
3999 /* use that as the destination instead. (For xinerama) */
4000 if (monitor_dest != dest && my_offset < monitor_dest)
4001 dest = monitor_dest;
4003 for(it = client_list; it && my_offset != dest; it = g_list_next(it)) {
4004 gint his_edge_start, his_edge_end, his_offset;
4005 ObClient *cur = it->data;
4009 his_edge_start = cur->frame->area.y;
4010 his_edge_end = cur->frame->area.y + cur->frame->area.height;
4011 his_offset = cur->frame->area.x +
4012 (hang ? cur->frame->area.width : 0);
4014 if(his_offset - 1 < my_offset)
4017 if(his_offset > dest)
4020 HIT_EDGE(my_edge_start, my_edge_end, his_edge_start, his_edge_end)
4023 case OB_DIRECTION_NORTHEAST:
4024 case OB_DIRECTION_SOUTHEAST:
4025 case OB_DIRECTION_NORTHWEST:
4026 case OB_DIRECTION_SOUTHWEST:
4027 /* not implemented */
4029 g_assert_not_reached();
4030 dest = 0; /* suppress warning */
4035 ObClient* client_under_pointer()
4039 ObClient *ret = NULL;
4041 if (screen_pointer_pos(&x, &y)) {
4042 for (it = stacking_list; it; it = g_list_next(it)) {
4043 if (WINDOW_IS_CLIENT(it->data)) {
4044 ObClient *c = WINDOW_AS_CLIENT(it->data);
4045 if (c->frame->visible &&
4046 /* ignore all animating windows */
4047 !frame_iconify_animating(c->frame) &&
4048 RECT_CONTAINS(c->frame->area, x, y))
4059 gboolean client_has_group_siblings(ObClient *self)
4061 return self->group && self->group->members->next;