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"
25 #include "moveresize.h"
34 #include "focus_cycle.h"
40 #include "menuframe.h"
43 #include "render/render.h"
45 #include "obt/display.h"
53 # include <signal.h> /* for kill() */
57 #include <X11/Xutil.h>
59 /*! The event mask to grab on client windows */
60 #define CLIENT_EVENTMASK (PropertyChangeMask | StructureNotifyMask | \
63 #define CLIENT_NOPROPAGATEMASK (ButtonPressMask | ButtonReleaseMask | \
68 ObClientCallback func;
72 GList *client_list = NULL;
74 static GSList *client_destroy_notifies = NULL;
75 static RrImage *client_default_icon = NULL;
77 static void client_get_all(ObClient *self, gboolean real);
78 static void client_get_startup_id(ObClient *self);
79 static void client_get_session_ids(ObClient *self);
80 static void client_get_area(ObClient *self);
81 static void client_get_desktop(ObClient *self);
82 static void client_get_state(ObClient *self);
83 static void client_get_shaped(ObClient *self);
84 static void client_get_mwm_hints(ObClient *self);
85 static void client_get_colormap(ObClient *self);
86 static void client_set_desktop_recursive(ObClient *self,
90 static void client_change_allowed_actions(ObClient *self);
91 static void client_change_state(ObClient *self);
92 static void client_change_wm_state(ObClient *self);
93 static void client_apply_startup_state(ObClient *self,
94 gint x, gint y, gint w, gint h);
95 static void client_restore_session_state(ObClient *self);
96 static gboolean client_restore_session_stacking(ObClient *self);
97 static ObAppSettings *client_get_settings_state(ObClient *self);
98 static void client_update_transient_tree(ObClient *self,
99 ObGroup *oldgroup, ObGroup *newgroup,
100 gboolean oldgtran, gboolean newgtran,
102 ObClient *newparent);
103 static void client_present(ObClient *self, gboolean here, gboolean raise,
105 static GSList *client_search_all_top_parents_internal(ObClient *self,
107 ObStackingLayer layer);
108 static void client_call_notifies(ObClient *self, GSList *list);
109 static void client_ping_event(ObClient *self, gboolean dead);
110 static void client_prompt_kill(ObClient *self);
112 void client_startup(gboolean reconfig)
114 if ((client_default_icon = RrImageCacheFind(ob_rr_icons,
115 ob_rr_theme->def_win_icon,
116 ob_rr_theme->def_win_icon_w,
117 ob_rr_theme->def_win_icon_h)))
118 RrImageRef(client_default_icon);
120 client_default_icon = RrImageNew(ob_rr_icons);
121 RrImageAddPicture(client_default_icon,
122 ob_rr_theme->def_win_icon,
123 ob_rr_theme->def_win_icon_w,
124 ob_rr_theme->def_win_icon_h);
127 if (reconfig) return;
132 void client_shutdown(gboolean reconfig)
134 RrImageUnref(client_default_icon);
135 client_default_icon = NULL;
137 if (reconfig) return;
140 static void client_call_notifies(ObClient *self, GSList *list)
144 for (it = list; it; it = g_slist_next(it)) {
145 ClientCallback *d = it->data;
146 d->func(self, d->data);
150 void client_add_destroy_notify(ObClientCallback func, gpointer data)
152 ClientCallback *d = g_new(ClientCallback, 1);
155 client_destroy_notifies = g_slist_prepend(client_destroy_notifies, d);
158 void client_remove_destroy_notify(ObClientCallback func)
162 for (it = client_destroy_notifies; it; it = g_slist_next(it)) {
163 ClientCallback *d = it->data;
164 if (d->func == func) {
166 client_destroy_notifies =
167 g_slist_delete_link(client_destroy_notifies, it);
173 void client_set_list(void)
175 Window *windows, *win_it;
177 guint size = g_list_length(client_list);
179 /* create an array of the window ids */
181 windows = g_new(Window, size);
183 for (it = client_list; it; it = g_list_next(it), ++win_it)
184 *win_it = ((ObClient*)it->data)->window;
188 OBT_PROP_SETA32(obt_root(ob_screen), NET_CLIENT_LIST, WINDOW,
189 (gulong*)windows, size);
197 void client_manage(Window window, ObPrompt *prompt)
200 XSetWindowAttributes attrib_set;
201 gboolean activate = FALSE;
202 ObAppSettings *settings;
203 gboolean transient = FALSE;
204 Rect place, *monitor;
205 Time launch_time, map_time;
207 ob_debug("Managing window: 0x%lx", window);
209 map_time = event_get_server_time();
211 /* choose the events we want to receive on the CLIENT window
212 (ObPrompt windows can request events too) */
213 attrib_set.event_mask = CLIENT_EVENTMASK |
214 (prompt ? prompt->event_mask : 0);
215 attrib_set.do_not_propagate_mask = CLIENT_NOPROPAGATEMASK;
216 XChangeWindowAttributes(obt_display, window,
217 CWEventMask|CWDontPropagate, &attrib_set);
219 /* create the ObClient struct, and populate it from the hints on the
221 self = g_new0(ObClient, 1);
222 self->obwin.type = OB_WINDOW_CLASS_CLIENT;
223 self->window = window;
224 self->prompt = prompt;
226 /* non-zero defaults */
227 self->wmstate = WithdrawnState; /* make sure it gets updated first time */
228 self->gravity = NorthWestGravity;
229 self->desktop = screen_num_desktops; /* always an invalid value */
231 /* get all the stuff off the window */
232 client_get_all(self, TRUE);
234 ob_debug("Window type: %d", self->type);
235 ob_debug("Window group: 0x%x", self->group?self->group->leader:0);
236 ob_debug("Window name: %s class: %s", self->name, self->class);
238 /* now we have all of the window's information so we can set this up.
239 do this before creating the frame, so it can tell that we are still
240 mapping and doesn't go applying things right away */
241 client_setup_decor_and_functions(self, FALSE);
243 /* specify that if we exit, the window should not be destroyed and
244 should be reparented back to root automatically, unless we are managing
245 an internal ObPrompt window */
247 XChangeSaveSet(obt_display, window, SetModeInsert);
249 /* create the decoration frame for the client window */
250 self->frame = frame_new(self);
252 frame_grab_client(self->frame);
254 /* we've grabbed everything and set everything that we need to at mapping
258 /* per-app settings override stuff from client_get_all, and return the
259 settings for other uses too. the returned settings is a shallow copy,
260 that needs to be freed with g_free(). */
261 settings = client_get_settings_state(self);
262 /* the session should get the last say though */
263 client_restore_session_state(self);
265 /* tell startup notification that this app started */
266 launch_time = sn_app_started(self->startup_id, self->class, self->name);
268 /* do this after we have a frame.. it uses the frame to help determine the
269 WM_STATE to apply. */
270 client_change_state(self);
272 /* add ourselves to the focus order */
273 focus_order_add_new(self);
275 /* do this to add ourselves to the stacking list in a non-intrusive way */
276 client_calc_layer(self);
278 /* focus the new window? */
279 if (ob_state() != OB_STATE_STARTING &&
280 (!self->session || self->session->focused) &&
281 /* this means focus=true for window is same as config_focus_new=true */
282 ((config_focus_new || (settings && settings->focus == 1)) ||
283 client_search_focus_tree_full(self)) &&
284 /* this checks for focus=false for the window */
285 (!settings || settings->focus != 0) &&
286 focus_valid_target(self, FALSE, FALSE, TRUE, FALSE, FALSE) &&
287 (!focus_cycle_target || !config_focus_dontstop))
292 /* remove the client's border */
293 XSetWindowBorderWidth(obt_display, self->window, 0);
295 /* adjust the frame to the client's size before showing or placing
297 frame_adjust_area(self->frame, FALSE, TRUE, FALSE);
298 frame_adjust_client_area(self->frame);
300 /* where the frame was placed is where the window was originally */
302 monitor = screen_physical_area_monitor(screen_find_monitor(&place));
304 /* figure out placement for the window if the window is new */
305 if (ob_state() == OB_STATE_RUNNING) {
306 ob_debug("Positioned: %s @ %d %d",
307 (!self->positioned ? "no" :
308 (self->positioned == PPosition ? "program specified" :
309 (self->positioned == USPosition ? "user specified" :
310 (self->positioned == (PPosition | USPosition) ?
311 "program + user specified" :
312 "BADNESS !?")))), place.x, place.y);
314 ob_debug("Sized: %s @ %d %d",
315 (!self->sized ? "no" :
316 (self->sized == PSize ? "program specified" :
317 (self->sized == USSize ? "user specified" :
318 (self->sized == (PSize | USSize) ?
319 "program + user specified" :
320 "BADNESS !?")))), place.width, place.height);
322 /* splash screens are also returned as TRUE for transient,
323 and so will be forced on screen below */
324 transient = place_client(self, &place.x, &place.y, settings);
326 /* make sure the window is visible. */
327 client_find_onscreen(self, &place.x, &place.y,
328 place.width, place.height,
329 /* non-normal clients has less rules, and
330 windows that are being restored from a
331 session do also. we can assume you want
332 it back where you saved it. Clients saying
333 they placed themselves are subjected to
334 harder rules, ones that are placed by
335 place.c or by the user are allowed partially
336 off-screen and on xinerama divides (ie,
337 it is up to the placement routines to avoid
338 the xinerama divides)
340 splash screens get "transient" set to TRUE by
341 the place_client call
343 ob_state() == OB_STATE_RUNNING &&
345 (!((self->positioned & USPosition) ||
346 (settings && settings->pos_given)) &&
347 client_normal(self) &&
349 /* don't move oldschool fullscreen windows to
350 fit inside the struts (fixes Acroread, which
351 makes its fullscreen window fit the screen
352 but it is not USSize'd or USPosition'd) */
353 !(self->decorations == 0 &&
354 RECT_EQUAL(place, *monitor)))));
357 /* if the window isn't user-sized, then make it fit inside
358 the visible screen area on its monitor. Use basically the same rules
359 for forcing the window on screen in the client_find_onscreen call.
361 do this after place_client, it chooses the monitor!
363 splash screens get "transient" set to TRUE by
364 the place_client call
366 if (ob_state() == OB_STATE_RUNNING &&
368 (!(self->sized & USSize || self->positioned & USPosition) &&
369 client_normal(self) &&
371 /* don't shrink oldschool fullscreen windows to fit inside the
372 struts (fixes Acroread, which makes its fullscreen window
373 fit the screen but it is not USSize'd or USPosition'd) */
374 !(self->decorations == 0 && RECT_EQUAL(place, *monitor)))))
376 Rect *a = screen_area(self->desktop, SCREEN_AREA_ONE_MONITOR, &place);
378 /* get the size of the frame */
379 place.width += self->frame->size.left + self->frame->size.right;
380 place.height += self->frame->size.top + self->frame->size.bottom;
382 /* fit the window inside the area */
383 place.width = MIN(place.width, a->width);
384 place.height = MIN(place.height, a->height);
386 ob_debug("setting window size to %dx%d", place.width, place.height);
388 /* get the size of the client back */
389 place.width -= self->frame->size.left + self->frame->size.right;
390 place.height -= self->frame->size.top + self->frame->size.bottom;
395 ob_debug("placing window 0x%x at %d, %d with size %d x %d. "
396 "some restrictions may apply",
397 self->window, place.x, place.y, place.width, place.height);
399 ob_debug(" but session requested %d, %d %d x %d instead, "
401 self->session->x, self->session->y,
402 self->session->w, self->session->h);
404 /* do this after the window is placed, so the premax/prefullscreen numbers
407 this also places the window
409 client_apply_startup_state(self, place.x, place.y,
410 place.width, place.height);
415 ob_debug_type(OB_DEBUG_FOCUS, "Going to try activate new window? %s",
416 activate ? "yes" : "no");
418 gboolean raise = FALSE;
419 gboolean relative_focused;
420 gboolean parent_focused;
422 parent_focused = (focus_client != NULL &&
423 client_search_focus_parent(self));
424 relative_focused = (focus_client != NULL &&
425 (client_search_focus_tree_full(self) != NULL ||
426 client_search_focus_group_full(self) != NULL));
428 /* This is focus stealing prevention */
429 ob_debug_type(OB_DEBUG_FOCUS,
430 "Want to focus new window 0x%x at time %u "
431 "launched at %u (last user interaction time %u)",
432 self->window, map_time, launch_time,
433 event_last_user_time);
434 ob_debug_type(OB_DEBUG_FOCUS,
435 "Current focus_client: %s",
436 (focus_client ? focus_client->title : "(none)"));
437 ob_debug_type(OB_DEBUG_FOCUS,
438 "parent focuesed: %d relative focused: %d",
439 parent_focused, relative_focused);
441 /* if it's on another desktop */
442 if (!(self->desktop == screen_desktop ||
443 self->desktop == DESKTOP_ALL) &&
444 /* the timestamp is from before you changed desktops */
445 launch_time && screen_desktop_user_time &&
446 !event_time_after(launch_time, screen_desktop_user_time))
450 ob_debug_type(OB_DEBUG_FOCUS,
451 "Not focusing the window because its on another "
454 /* If something is focused... */
455 else if (focus_client) {
456 /* If the user is working in another window right now, then don't
458 if (!parent_focused &&
459 event_last_user_time && launch_time &&
460 event_time_after(event_last_user_time, launch_time) &&
461 event_last_user_time != launch_time &&
462 event_time_after(event_last_user_time,
463 map_time - OB_EVENT_USER_TIME_DELAY))
466 ob_debug_type(OB_DEBUG_FOCUS,
467 "Not focusing the window because the user is "
468 "working in another window that is not "
471 /* If the new window is a transient (and its relatives aren't
473 else if (client_has_parent(self) && !relative_focused) {
475 ob_debug_type(OB_DEBUG_FOCUS,
476 "Not focusing the window because it is a "
477 "transient, and its relatives aren't focused");
479 /* Don't steal focus from globally active clients.
480 I stole this idea from KWin. It seems nice.
482 else if (!(focus_client->can_focus ||
483 focus_client->focus_notify))
486 ob_debug_type(OB_DEBUG_FOCUS,
487 "Not focusing the window because a globally "
488 "active client has focus");
490 /* Don't move focus if it's not going to go to this window
492 else if (client_focus_target(self) != self) {
495 ob_debug_type(OB_DEBUG_FOCUS,
496 "Not focusing the window because another window "
497 "would get the focus anyway");
499 /* Don't move focus if the window is not visible on the current
500 desktop and none of its relatives are focused */
501 else if (!(self->desktop == screen_desktop ||
502 self->desktop == DESKTOP_ALL) &&
507 ob_debug_type(OB_DEBUG_FOCUS,
508 "Not focusing the window because it is on "
509 "another desktop and no relatives are focused ");
514 ob_debug_type(OB_DEBUG_FOCUS,
515 "Focus stealing prevention activated for %s at "
516 "time %u (last user interaction time %u)",
517 self->title, map_time, event_last_user_time);
518 /* if the client isn't focused, then hilite it so the user
520 client_hilite(self, TRUE);
521 /* we may want to raise it even tho we're not activating it */
522 if (raise && !client_restore_session_stacking(self))
523 stacking_raise(CLIENT_AS_WINDOW(self));
527 /* This may look rather odd. Well it's because new windows are added
528 to the stacking order non-intrusively. If we're not going to focus
529 the new window or hilite it, then we raise it to the top. This will
530 take affect for things that don't get focused like splash screens.
531 Also if you don't have focus_new enabled, then it's going to get
532 raised to the top. Legacy begets legacy I guess?
534 if (!client_restore_session_stacking(self))
535 stacking_raise(CLIENT_AS_WINDOW(self));
538 mouse_grab_for_client(self, TRUE);
540 /* this has to happen before we try focus the window, but we want it to
541 happen after the client's stacking has been determined or it looks bad
545 if (!config_focus_under_mouse)
546 ignore_start = event_start_ignore_all_enters();
550 if (!config_focus_under_mouse)
551 event_end_ignore_all_enters(ignore_start);
555 gboolean stacked = client_restore_session_stacking(self);
556 client_present(self, FALSE, !stacked, TRUE);
559 /* add to client list/map */
560 client_list = g_list_append(client_list, self);
561 window_add(&self->window, CLIENT_AS_WINDOW(self));
563 /* this has to happen after we're in the client_list */
564 if (STRUT_EXISTS(self->strut))
565 screen_update_areas();
567 /* update the list hints */
570 /* free the ObAppSettings shallow copy */
573 ob_debug("Managed window 0x%lx plate 0x%x (%s)",
574 window, self->frame->window, self->class);
576 hooks_queue(OB_HOOK_WIN_NEW, self);
579 ObClient *client_fake_manage(Window window)
582 ObAppSettings *settings;
584 ob_debug("Pretend-managing window: %lx", 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",
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(void)
615 client_unmanage(client_list->data);
618 void client_unmanage(ObClient *self)
623 ob_debug("Unmanaging window: 0x%x plate 0x%x (%s) (%s)",
624 self->window, self->frame->window,
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(obt_display, self->window, NoEventMask);
633 /* ignore enter events from the unmap so it doesnt mess with the focus */
634 if (!config_focus_under_mouse)
635 ignore_start = event_start_ignore_all_enters();
637 frame_hide(self->frame);
638 /* flush to send the hide to the server quickly */
641 if (!config_focus_under_mouse)
642 event_end_ignore_all_enters(ignore_start);
644 mouse_grab_for_client(self, FALSE);
646 /* remove the window from our save set, unless we are managing an internal
649 XChangeSaveSet(obt_display, self->window, SetModeDelete);
651 /* this can't be queued to run later */
652 hooks_run(OB_HOOK_WIN_CLOSE, self);
654 /* update the focus lists */
655 focus_order_remove(self);
656 if (client_focused(self)) {
657 /* don't leave an invalid focus_client */
661 /* if we're prompting to kill the client, close that */
662 prompt_unref(self->kill_prompt);
663 self->kill_prompt = NULL;
665 client_list = g_list_remove(client_list, self);
666 stacking_remove(self);
667 window_remove(self->window);
669 /* once the client is out of the list, update the struts to remove its
671 if (STRUT_EXISTS(self->strut))
672 screen_update_areas();
674 client_call_notifies(self, client_destroy_notifies);
676 /* tell our parent(s) that we're gone */
677 for (it = self->parents; it; it = g_slist_next(it))
678 ((ObClient*)it->data)->transients =
679 g_slist_remove(((ObClient*)it->data)->transients,self);
681 /* tell our transients that we're gone */
682 for (it = self->transients; it; it = g_slist_next(it)) {
683 ((ObClient*)it->data)->parents =
684 g_slist_remove(((ObClient*)it->data)->parents, self);
685 /* we could be keeping our children in a higher layer */
686 client_calc_layer(it->data);
689 /* remove from its group */
691 group_remove(self->group, self);
695 /* restore the window's original geometry so it is not lost */
701 if (self->fullscreen)
702 a = self->pre_fullscreen_area;
703 else if (self->max_horz || self->max_vert) {
704 if (self->max_horz) {
705 a.x = self->pre_max_area.x;
706 a.width = self->pre_max_area.width;
708 if (self->max_vert) {
709 a.y = self->pre_max_area.y;
710 a.height = self->pre_max_area.height;
714 self->fullscreen = self->max_horz = self->max_vert = FALSE;
715 /* let it be moved and resized no matter what */
716 self->functions = OB_CLIENT_FUNC_MOVE | OB_CLIENT_FUNC_RESIZE;
717 self->decorations = 0; /* unmanaged windows have no decor */
719 /* give the client its border back */
720 XSetWindowBorderWidth(obt_display, self->window, self->border_width);
722 client_move_resize(self, a.x, a.y, a.width, a.height);
725 /* reparent the window out of the frame, and free the frame */
726 frame_release_client(self->frame);
727 frame_free(self->frame);
730 if (ob_state() != OB_STATE_EXITING) {
731 /* these values should not be persisted across a window
733 OBT_PROP_ERASE(self->window, NET_WM_DESKTOP);
734 OBT_PROP_ERASE(self->window, NET_WM_STATE);
735 OBT_PROP_ERASE(self->window, WM_STATE);
737 /* if we're left in an unmapped state, the client wont be mapped.
738 this is bad, since we will no longer be managing the window on
740 XMapWindow(obt_display, self->window);
743 /* these should not be left on the window ever. other window managers
744 don't necessarily use them and it will mess them up (like compiz) */
745 OBT_PROP_ERASE(self->window, NET_WM_VISIBLE_NAME);
746 OBT_PROP_ERASE(self->window, NET_WM_VISIBLE_ICON_NAME);
748 /* update the list hints */
751 ob_debug("Unmanaged window 0x%lx", self->window);
753 /* free all data allocated in the client struct */
754 RrImageUnref(self->icon_set);
755 g_slist_free(self->transients);
756 g_free(self->startup_id);
757 g_free(self->wm_command);
759 g_free(self->icon_title);
760 g_free(self->original_title);
764 g_free(self->client_machine);
765 g_free(self->sm_client_id);
769 void client_fake_unmanage(ObClient *self)
771 /* this is all that got allocated to get the decorations */
773 frame_free(self->frame);
777 /*! Returns a new structure containing the per-app settings for this client.
778 The returned structure needs to be freed with g_free. */
779 static ObAppSettings *client_get_settings_state(ObClient *self)
781 ObAppSettings *settings;
784 settings = config_create_app_settings();
786 for (it = config_per_app_settings; it; it = g_slist_next(it)) {
787 ObAppSettings *app = it->data;
788 gboolean match = TRUE;
790 g_assert(app->name != NULL || app->class != NULL);
792 /* we know that either name or class is not NULL so it will have to
793 match to use the rule */
795 !g_pattern_match(app->name, strlen(self->name), self->name, NULL))
797 else if (app->class &&
798 !g_pattern_match(app->class,
799 strlen(self->class), self->class, NULL))
801 else if (app->role &&
802 !g_pattern_match(app->role,
803 strlen(self->role), self->role, NULL))
805 else if ((signed)app->type >= 0 && app->type != self->type)
809 ob_debug("Window matching: %s", app->name);
811 /* copy the settings to our struct, overriding the existing
812 settings if they are not defaults */
813 config_app_settings_copy_non_defaults(app, settings);
817 if (settings->shade != -1)
818 self->shaded = !!settings->shade;
819 if (settings->decor != -1)
820 self->undecorated = !settings->decor;
821 if (settings->iconic != -1)
822 self->iconic = !!settings->iconic;
823 if (settings->skip_pager != -1)
824 self->skip_pager = !!settings->skip_pager;
825 if (settings->skip_taskbar != -1)
826 self->skip_taskbar = !!settings->skip_taskbar;
828 if (settings->max_vert != -1)
829 self->max_vert = !!settings->max_vert;
830 if (settings->max_horz != -1)
831 self->max_horz = !!settings->max_horz;
833 if (settings->fullscreen != -1)
834 self->fullscreen = !!settings->fullscreen;
836 if (settings->desktop) {
837 if (settings->desktop == DESKTOP_ALL)
838 self->desktop = settings->desktop;
839 else if (settings->desktop > 0 &&
840 settings->desktop <= screen_num_desktops)
841 self->desktop = settings->desktop - 1;
844 if (settings->layer == -1) {
848 else if (settings->layer == 0) {
852 else if (settings->layer == 1) {
859 static void client_restore_session_state(ObClient *self)
863 ob_debug_type(OB_DEBUG_SM,
864 "Restore session for client %s", self->title);
866 if (!(it = session_state_find(self))) {
867 ob_debug_type(OB_DEBUG_SM,
868 "Session data not found for client %s", self->title);
872 self->session = it->data;
874 ob_debug_type(OB_DEBUG_SM, "Session data loaded for client %s",
877 RECT_SET_POINT(self->area, self->session->x, self->session->y);
878 self->positioned = USPosition;
879 self->sized = USSize;
880 if (self->session->w > 0)
881 self->area.width = self->session->w;
882 if (self->session->h > 0)
883 self->area.height = self->session->h;
884 XResizeWindow(obt_display, self->window,
885 self->area.width, self->area.height);
887 self->desktop = (self->session->desktop == DESKTOP_ALL ?
888 self->session->desktop :
889 MIN(screen_num_desktops - 1, self->session->desktop));
890 OBT_PROP_SET32(self->window, NET_WM_DESKTOP, CARDINAL, self->desktop);
892 self->shaded = self->session->shaded;
893 self->iconic = self->session->iconic;
894 self->skip_pager = self->session->skip_pager;
895 self->skip_taskbar = self->session->skip_taskbar;
896 self->fullscreen = self->session->fullscreen;
897 self->above = self->session->above;
898 self->below = self->session->below;
899 self->max_horz = self->session->max_horz;
900 self->max_vert = self->session->max_vert;
901 self->undecorated = self->session->undecorated;
904 static gboolean client_restore_session_stacking(ObClient *self)
908 if (!self->session) return FALSE;
910 mypos = g_list_find(session_saved_state, self->session);
911 if (!mypos) return FALSE;
913 /* start above me and look for the first client */
914 for (it = g_list_previous(mypos); it; it = g_list_previous(it)) {
917 for (cit = client_list; cit; cit = g_list_next(cit)) {
918 ObClient *c = cit->data;
919 /* found a client that was in the session, so go below it */
920 if (c->session == it->data) {
921 stacking_below(CLIENT_AS_WINDOW(self),
922 CLIENT_AS_WINDOW(cit->data));
930 void client_move_onscreen(ObClient *self, gboolean rude)
932 gint x = self->area.x;
933 gint y = self->area.y;
934 if (client_find_onscreen(self, &x, &y,
936 self->area.height, rude)) {
937 client_move(self, x, y);
941 gboolean client_find_onscreen(ObClient *self, gint *x, gint *y, gint w, gint h,
944 gint ox = *x, oy = *y;
945 gboolean rudel = rude, ruder = rude, rudet = rude, rudeb = rude;
951 RECT_SET(desired, *x, *y, w, h);
952 frame_rect_to_frame(self->frame, &desired);
954 /* get where the frame would be */
955 frame_client_gravity(self->frame, x, y);
957 /* get the requested size of the window with decorations */
958 fw = self->frame->size.left + w + self->frame->size.right;
959 fh = self->frame->size.top + h + self->frame->size.bottom;
961 /* If rudeness wasn't requested, then still be rude in a given direction
962 if the client is not moving, only resizing in that direction */
964 Point oldtl, oldtr, oldbl, oldbr;
965 Point newtl, newtr, newbl, newbr;
966 gboolean stationary_l, stationary_r, stationary_t, stationary_b;
968 POINT_SET(oldtl, self->frame->area.x, self->frame->area.y);
969 POINT_SET(oldbr, self->frame->area.x + self->frame->area.width - 1,
970 self->frame->area.y + self->frame->area.height - 1);
971 POINT_SET(oldtr, oldbr.x, oldtl.y);
972 POINT_SET(oldbl, oldtl.x, oldbr.y);
974 POINT_SET(newtl, *x, *y);
975 POINT_SET(newbr, *x + fw - 1, *y + fh - 1);
976 POINT_SET(newtr, newbr.x, newtl.y);
977 POINT_SET(newbl, newtl.x, newbr.y);
979 /* is it moving or just resizing from some corner? */
980 stationary_l = oldtl.x == newtl.x;
981 stationary_r = oldtr.x == newtr.x;
982 stationary_t = oldtl.y == newtl.y;
983 stationary_b = oldbl.y == newbl.y;
985 /* if left edge is growing and didnt move right edge */
986 if (stationary_r && newtl.x < oldtl.x)
988 /* if right edge is growing and didnt move left edge */
989 if (stationary_l && newtr.x > oldtr.x)
991 /* if top edge is growing and didnt move bottom edge */
992 if (stationary_b && newtl.y < oldtl.y)
994 /* if bottom edge is growing and didnt move top edge */
995 if (stationary_t && newbl.y > oldbl.y)
999 /* we iterate through every monitor that the window is at least partially
1000 on, to make sure it is obeying the rules on them all
1002 if the window does not appear on any monitors, then use the first one
1005 for (i = 0; i < screen_num_monitors; ++i) {
1008 if (!screen_physical_area_monitor_contains(i, &desired)) {
1009 if (i < screen_num_monitors - 1 || found_mon)
1012 /* the window is not inside any monitor! so just use the first
1014 a = screen_area(self->desktop, 0, NULL);
1017 a = screen_area(self->desktop, SCREEN_AREA_ONE_MONITOR, &desired);
1020 /* This makes sure windows aren't entirely outside of the screen so you
1021 can't see them at all.
1022 It makes sure 10% of the window is on the screen at least. And don't
1023 let it move itself off the top of the screen, which would hide the
1024 titlebar on you. (The user can still do this if they want too, it's
1025 only limiting the application.
1027 if (client_normal(self)) {
1028 if (!self->strut.right && *x + fw/10 >= a->x + a->width - 1)
1029 *x = a->x + a->width - fw/10;
1030 if (!self->strut.bottom && *y + fh/10 >= a->y + a->height - 1)
1031 *y = a->y + a->height - fh/10;
1032 if (!self->strut.left && *x + fw*9/10 - 1 < a->x)
1033 *x = a->x - fw*9/10;
1034 if (!self->strut.top && *y + fh*9/10 - 1 < a->y)
1035 *y = a->y - fh*9/10;
1038 /* This here doesn't let windows even a pixel outside the
1039 struts/screen. When called from client_manage, programs placing
1040 themselves are forced completely onscreen, while things like
1041 xterm -geometry resolution-width/2 will work fine. Trying to
1042 place it completely offscreen will be handled in the above code.
1043 Sorry for this confused comment, i am tired. */
1044 if (rudel && !self->strut.left && *x < a->x) *x = a->x;
1045 if (ruder && !self->strut.right && *x + fw > a->x + a->width)
1046 *x = a->x + MAX(0, a->width - fw);
1048 if (rudet && !self->strut.top && *y < a->y) *y = a->y;
1049 if (rudeb && !self->strut.bottom && *y + fh > a->y + a->height)
1050 *y = a->y + MAX(0, a->height - fh);
1055 /* get where the client should be */
1056 frame_frame_gravity(self->frame, x, y);
1058 return ox != *x || oy != *y;
1061 static void client_get_all(ObClient *self, gboolean real)
1063 /* this is needed for the frame to set itself up */
1064 client_get_area(self);
1066 /* these things can change the decor and functions of the window */
1068 client_get_mwm_hints(self);
1069 /* this can change the mwmhints for special cases */
1070 client_get_type_and_transientness(self);
1071 client_get_state(self);
1072 client_update_normal_hints(self);
1074 /* get the session related properties, these can change decorations
1075 from per-app settings */
1076 client_get_session_ids(self);
1078 /* now we got everything that can affect the decorations */
1082 /* get this early so we have it for debugging */
1083 client_update_title(self);
1085 client_update_protocols(self);
1087 client_update_wmhints(self);
1088 /* this may have already been called from client_update_wmhints */
1089 if (!self->parents && !self->transient_for_group)
1090 client_update_transient_for(self);
1092 client_get_startup_id(self);
1093 client_get_desktop(self);/* uses transient data/group/startup id if a
1094 desktop is not specified */
1095 client_get_shaped(self);
1098 /* a couple type-based defaults for new windows */
1100 /* this makes sure that these windows appear on all desktops */
1101 if (self->type == OB_CLIENT_TYPE_DESKTOP)
1102 self->desktop = DESKTOP_ALL;
1106 client_update_sync_request_counter(self);
1109 client_get_colormap(self);
1110 client_update_strut(self);
1111 client_update_icons(self);
1112 client_update_icon_geometry(self);
1115 static void client_get_startup_id(ObClient *self)
1117 if (!(OBT_PROP_GETS(self->window, NET_STARTUP_ID, utf8,
1118 &self->startup_id)))
1120 OBT_PROP_GETS(self->group->leader,
1121 NET_STARTUP_ID, utf8, &self->startup_id);
1124 static void client_get_area(ObClient *self)
1126 XWindowAttributes wattrib;
1129 ret = XGetWindowAttributes(obt_display, self->window, &wattrib);
1130 g_assert(ret != BadWindow);
1132 RECT_SET(self->area, wattrib.x, wattrib.y, wattrib.width, wattrib.height);
1133 POINT_SET(self->root_pos, wattrib.x, wattrib.y);
1134 self->border_width = wattrib.border_width;
1136 ob_debug("client area: %d %d %d %d bw %d", wattrib.x, wattrib.y,
1137 wattrib.width, wattrib.height, wattrib.border_width);
1140 static void client_get_desktop(ObClient *self)
1142 guint32 d = screen_num_desktops; /* an always-invalid value */
1144 if (OBT_PROP_GET32(self->window, NET_WM_DESKTOP, CARDINAL, &d)) {
1145 if (d >= screen_num_desktops && d != DESKTOP_ALL)
1146 self->desktop = screen_num_desktops - 1;
1149 ob_debug("client requested desktop 0x%x", self->desktop);
1152 gboolean first = TRUE;
1153 guint all = screen_num_desktops; /* not a valid value */
1155 /* if they are all on one desktop, then open it on the
1157 for (it = self->parents; it; it = g_slist_next(it)) {
1158 ObClient *c = it->data;
1160 if (c->desktop == DESKTOP_ALL) continue;
1166 else if (all != c->desktop)
1167 all = screen_num_desktops; /* make it invalid */
1169 if (all != screen_num_desktops) {
1170 self->desktop = all;
1172 ob_debug("client desktop set from parents: 0x%x",
1175 /* try get from the startup-notification protocol */
1176 else if (sn_get_desktop(self->startup_id, &self->desktop)) {
1177 if (self->desktop >= screen_num_desktops &&
1178 self->desktop != DESKTOP_ALL)
1179 self->desktop = screen_num_desktops - 1;
1180 ob_debug("client desktop set from startup-notification: 0x%x",
1183 /* defaults to the current desktop */
1185 self->desktop = screen_desktop;
1186 ob_debug("client desktop set to the current desktop: %d",
1192 static void client_get_state(ObClient *self)
1197 if (OBT_PROP_GETA32(self->window, NET_WM_STATE, ATOM, &state, &num)) {
1199 for (i = 0; i < num; ++i) {
1200 if (state[i] == OBT_PROP_ATOM(NET_WM_STATE_MODAL))
1202 else if (state[i] == OBT_PROP_ATOM(NET_WM_STATE_SHADED))
1203 self->shaded = TRUE;
1204 else if (state[i] == OBT_PROP_ATOM(NET_WM_STATE_HIDDEN))
1205 self->iconic = TRUE;
1206 else if (state[i] == OBT_PROP_ATOM(NET_WM_STATE_SKIP_TASKBAR))
1207 self->skip_taskbar = TRUE;
1208 else if (state[i] == OBT_PROP_ATOM(NET_WM_STATE_SKIP_PAGER))
1209 self->skip_pager = TRUE;
1210 else if (state[i] == OBT_PROP_ATOM(NET_WM_STATE_FULLSCREEN))
1211 self->fullscreen = TRUE;
1212 else if (state[i] == OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_VERT))
1213 self->max_vert = TRUE;
1214 else if (state[i] == OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_HORZ))
1215 self->max_horz = TRUE;
1216 else if (state[i] == OBT_PROP_ATOM(NET_WM_STATE_ABOVE))
1218 else if (state[i] == OBT_PROP_ATOM(NET_WM_STATE_BELOW))
1220 else if (state[i] == OBT_PROP_ATOM(NET_WM_STATE_DEMANDS_ATTENTION))
1221 self->demands_attention = TRUE;
1222 else if (state[i] == OBT_PROP_ATOM(OB_WM_STATE_UNDECORATED))
1223 self->undecorated = TRUE;
1224 else if (state[i] == OBT_PROP_ATOM(OB_WM_STATE_LOCKED))
1225 self->locked = TRUE;
1232 static void client_get_shaped(ObClient *self)
1234 self->shaped = FALSE;
1236 if (obt_display_extension_shape) {
1241 XShapeSelectInput(obt_display, self->window, ShapeNotifyMask);
1243 XShapeQueryExtents(obt_display, self->window, &s, &foo,
1244 &foo, &ufoo, &ufoo, &foo, &foo, &foo, &ufoo,
1251 void client_update_transient_for(ObClient *self)
1254 ObClient *target = NULL;
1255 gboolean trangroup = FALSE;
1257 if (XGetTransientForHint(obt_display, self->window, &t)) {
1258 if (t != self->window) { /* can't be transient to itself! */
1259 ObWindow *tw = window_find(t);
1260 /* if this happens then we need to check for it */
1261 g_assert(tw != CLIENT_AS_WINDOW(self));
1262 if (tw && WINDOW_IS_CLIENT(tw)) {
1263 /* watch out for windows with a parent that is something
1264 different, like a dockapp for example */
1265 target = WINDOW_AS_CLIENT(tw);
1269 /* Setting the transient_for to Root is actually illegal, however
1270 applications from time have done this to specify transient for
1272 if (!target && self->group && t == obt_root(ob_screen))
1274 } else if (self->group && self->transient)
1277 client_update_transient_tree(self, self->group, self->group,
1278 self->transient_for_group, trangroup,
1279 client_direct_parent(self), target);
1280 self->transient_for_group = trangroup;
1284 static void client_update_transient_tree(ObClient *self,
1285 ObGroup *oldgroup, ObGroup *newgroup,
1286 gboolean oldgtran, gboolean newgtran,
1287 ObClient* oldparent,
1288 ObClient *newparent)
1293 g_assert(!oldgtran || oldgroup);
1294 g_assert(!newgtran || newgroup);
1295 g_assert((!oldgtran && !oldparent) ||
1296 (oldgtran && !oldparent) ||
1297 (!oldgtran && oldparent));
1298 g_assert((!newgtran && !newparent) ||
1299 (newgtran && !newparent) ||
1300 (!newgtran && newparent));
1303 Group transient windows are not allowed to have other group
1304 transient windows as their children.
1307 /* No change has occured */
1308 if (oldgroup == newgroup &&
1309 oldgtran == newgtran &&
1310 oldparent == newparent) return;
1312 /** Remove the client from the transient tree **/
1314 for (it = self->transients; it; it = next) {
1315 next = g_slist_next(it);
1317 self->transients = g_slist_delete_link(self->transients, it);
1318 c->parents = g_slist_remove(c->parents, self);
1320 for (it = self->parents; it; it = next) {
1321 next = g_slist_next(it);
1323 self->parents = g_slist_delete_link(self->parents, it);
1324 c->transients = g_slist_remove(c->transients, self);
1327 /** Re-add the client to the transient tree **/
1329 /* If we're transient for a group then we need to add ourselves to all our
1332 for (it = newgroup->members; it; it = g_slist_next(it)) {
1335 !client_search_top_direct_parent(c)->transient_for_group &&
1338 c->transients = g_slist_prepend(c->transients, self);
1339 self->parents = g_slist_prepend(self->parents, c);
1344 /* If we are now transient for a single window we need to add ourselves to
1347 WARNING: Cyclical transient-ness is possible if two windows are
1348 transient for eachother.
1350 else if (newparent &&
1351 /* don't make ourself its child if it is already our child */
1352 !client_is_direct_child(self, newparent) &&
1353 client_normal(newparent))
1355 newparent->transients = g_slist_prepend(newparent->transients, self);
1356 self->parents = g_slist_prepend(self->parents, newparent);
1359 /* Add any group transient windows to our children. But if we're transient
1360 for the group, then other group transients are not our children.
1362 WARNING: Cyclical transient-ness is possible. For e.g. if:
1363 A is transient for the group
1364 B is transient for A
1365 C is transient for B
1366 A can't be transient for C or we have a cycle
1368 if (!newgtran && newgroup &&
1370 !client_search_top_direct_parent(newparent)->transient_for_group) &&
1371 client_normal(self))
1373 for (it = newgroup->members; it; it = g_slist_next(it)) {
1375 if (c != self && c->transient_for_group &&
1376 /* Don't make it our child if it is already our parent */
1377 !client_is_direct_child(c, self))
1379 self->transients = g_slist_prepend(self->transients, c);
1380 c->parents = g_slist_prepend(c->parents, self);
1385 /** If we change our group transient-ness, our children change their
1386 effective group transient-ness, which affects how they relate to other
1389 for (it = self->transients; it; it = g_slist_next(it)) {
1391 if (!c->transient_for_group)
1392 client_update_transient_tree(c, c->group, c->group,
1393 c->transient_for_group,
1394 c->transient_for_group,
1395 client_direct_parent(c),
1396 client_direct_parent(c));
1400 static void client_get_mwm_hints(ObClient *self)
1405 self->mwmhints.flags = 0; /* default to none */
1407 if (OBT_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 (OBT_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] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_DESKTOP))
1431 self->type = OB_CLIENT_TYPE_DESKTOP;
1432 else if (val[i] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_DOCK))
1433 self->type = OB_CLIENT_TYPE_DOCK;
1434 else if (val[i] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_TOOLBAR))
1435 self->type = OB_CLIENT_TYPE_TOOLBAR;
1436 else if (val[i] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_MENU))
1437 self->type = OB_CLIENT_TYPE_MENU;
1438 else if (val[i] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_UTILITY))
1439 self->type = OB_CLIENT_TYPE_UTILITY;
1440 else if (val[i] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_SPLASH))
1441 self->type = OB_CLIENT_TYPE_SPLASH;
1442 else if (val[i] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_DIALOG))
1443 self->type = OB_CLIENT_TYPE_DIALOG;
1444 else if (val[i] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_NORMAL))
1445 self->type = OB_CLIENT_TYPE_NORMAL;
1446 else if (val[i] == OBT_PROP_ATOM(KDE_NET_WM_WINDOW_TYPE_OVERRIDE))
1448 /* prevent this window from getting any decor or
1450 self->mwmhints.flags &= (OB_MWM_FLAG_FUNCTIONS |
1451 OB_MWM_FLAG_DECORATIONS);
1452 self->mwmhints.decorations = 0;
1453 self->mwmhints.functions = 0;
1455 if (self->type != (ObClientType) -1)
1456 break; /* grab the first legit type */
1461 if (XGetTransientForHint(obt_display, self->window, &t))
1462 self->transient = TRUE;
1464 if (self->type == (ObClientType) -1) {
1465 /*the window type hint was not set, which means we either classify
1466 ourself as a normal window or a dialog, depending on if we are a
1468 if (self->transient)
1469 self->type = OB_CLIENT_TYPE_DIALOG;
1471 self->type = OB_CLIENT_TYPE_NORMAL;
1474 /* then, based on our type, we can update our transientness.. */
1475 if (self->type == OB_CLIENT_TYPE_DIALOG ||
1476 self->type == OB_CLIENT_TYPE_TOOLBAR ||
1477 self->type == OB_CLIENT_TYPE_MENU ||
1478 self->type == OB_CLIENT_TYPE_UTILITY)
1480 self->transient = TRUE;
1484 void client_update_protocols(ObClient *self)
1489 self->focus_notify = FALSE;
1490 self->delete_window = FALSE;
1492 if (OBT_PROP_GETA32(self->window, WM_PROTOCOLS, ATOM, &proto, &num_ret)) {
1493 for (i = 0; i < num_ret; ++i) {
1494 if (proto[i] == OBT_PROP_ATOM(WM_DELETE_WINDOW))
1495 /* this means we can request the window to close */
1496 self->delete_window = TRUE;
1497 else if (proto[i] == OBT_PROP_ATOM(WM_TAKE_FOCUS))
1498 /* if this protocol is requested, then the window will be
1499 notified whenever we want it to receive focus */
1500 self->focus_notify = TRUE;
1501 else if (proto[i] == OBT_PROP_ATOM(NET_WM_PING))
1502 /* if this protocol is requested, then the window will allow
1503 pings to determine if it is still alive */
1506 else if (proto[i] == OBT_PROP_ATOM(NET_WM_SYNC_REQUEST))
1507 /* if this protocol is requested, then resizing the
1508 window will be synchronized between the frame and the
1510 self->sync_request = TRUE;
1518 void client_update_sync_request_counter(ObClient *self)
1522 if (OBT_PROP_GET32(self->window, NET_WM_SYNC_REQUEST_COUNTER, CARDINAL,&i))
1524 self->sync_counter = i;
1526 self->sync_counter = None;
1530 static void client_get_colormap(ObClient *self)
1532 XWindowAttributes wa;
1534 if (XGetWindowAttributes(obt_display, self->window, &wa))
1535 client_update_colormap(self, wa.colormap);
1538 void client_update_colormap(ObClient *self, Colormap colormap)
1540 if (colormap == self->colormap) return;
1542 ob_debug("Setting client %s colormap: 0x%x", self->title, colormap);
1544 if (client_focused(self)) {
1545 screen_install_colormap(self, FALSE); /* uninstall old one */
1546 self->colormap = colormap;
1547 screen_install_colormap(self, TRUE); /* install new one */
1549 self->colormap = colormap;
1552 void client_update_normal_hints(ObClient *self)
1558 self->min_ratio = 0.0f;
1559 self->max_ratio = 0.0f;
1560 SIZE_SET(self->size_inc, 1, 1);
1561 SIZE_SET(self->base_size, -1, -1);
1562 SIZE_SET(self->min_size, 0, 0);
1563 SIZE_SET(self->max_size, G_MAXINT, G_MAXINT);
1565 /* get the hints from the window */
1566 if (XGetWMNormalHints(obt_display, self->window, &size, &ret)) {
1567 /* normal windows can't request placement! har har
1568 if (!client_normal(self))
1570 self->positioned = (size.flags & (PPosition|USPosition));
1571 self->sized = (size.flags & (PSize|USSize));
1573 if (size.flags & PWinGravity)
1574 self->gravity = size.win_gravity;
1576 if (size.flags & PAspect) {
1577 if (size.min_aspect.y)
1579 (gfloat) size.min_aspect.x / size.min_aspect.y;
1580 if (size.max_aspect.y)
1582 (gfloat) size.max_aspect.x / size.max_aspect.y;
1585 if (size.flags & PMinSize)
1586 SIZE_SET(self->min_size, size.min_width, size.min_height);
1588 if (size.flags & PMaxSize)
1589 SIZE_SET(self->max_size, size.max_width, size.max_height);
1591 if (size.flags & PBaseSize)
1592 SIZE_SET(self->base_size, size.base_width, size.base_height);
1594 if (size.flags & PResizeInc && size.width_inc && size.height_inc)
1595 SIZE_SET(self->size_inc, size.width_inc, size.height_inc);
1597 ob_debug("Normal hints: min size (%d %d) max size (%d %d)",
1598 self->min_size.width, self->min_size.height,
1599 self->max_size.width, self->max_size.height);
1600 ob_debug("size inc (%d %d) base size (%d %d)",
1601 self->size_inc.width, self->size_inc.height,
1602 self->base_size.width, self->base_size.height);
1605 ob_debug("Normal hints: not set");
1608 void client_setup_decor_and_functions(ObClient *self, gboolean reconfig)
1610 /* start with everything (cept fullscreen) */
1612 (OB_FRAME_DECOR_TITLEBAR |
1613 OB_FRAME_DECOR_HANDLE |
1614 OB_FRAME_DECOR_GRIPS |
1615 OB_FRAME_DECOR_BORDER |
1616 OB_FRAME_DECOR_ICON |
1617 OB_FRAME_DECOR_ALLDESKTOPS |
1618 OB_FRAME_DECOR_ICONIFY |
1619 OB_FRAME_DECOR_MAXIMIZE |
1620 OB_FRAME_DECOR_SHADE |
1621 OB_FRAME_DECOR_CLOSE);
1623 (OB_CLIENT_FUNC_RESIZE |
1624 OB_CLIENT_FUNC_MOVE |
1625 OB_CLIENT_FUNC_ICONIFY |
1626 OB_CLIENT_FUNC_MAXIMIZE |
1627 OB_CLIENT_FUNC_SHADE |
1628 OB_CLIENT_FUNC_CLOSE |
1629 OB_CLIENT_FUNC_BELOW |
1630 OB_CLIENT_FUNC_ABOVE |
1631 OB_CLIENT_FUNC_UNDECORATE);
1633 if (!(self->min_size.width < self->max_size.width ||
1634 self->min_size.height < self->max_size.height))
1635 self->functions &= ~OB_CLIENT_FUNC_RESIZE;
1637 switch (self->type) {
1638 case OB_CLIENT_TYPE_NORMAL:
1639 /* normal windows retain all of the possible decorations and
1640 functionality, and can be fullscreen */
1641 self->functions |= OB_CLIENT_FUNC_FULLSCREEN;
1644 case OB_CLIENT_TYPE_DIALOG:
1645 /* sometimes apps make dialog windows fullscreen for some reason (for
1646 e.g. kpdf does this..) */
1647 self->functions |= OB_CLIENT_FUNC_FULLSCREEN;
1650 case OB_CLIENT_TYPE_UTILITY:
1651 /* these windows don't have anything added or removed by default */
1654 case OB_CLIENT_TYPE_MENU:
1655 case OB_CLIENT_TYPE_TOOLBAR:
1656 /* these windows can't iconify or maximize */
1657 self->decorations &= ~(OB_FRAME_DECOR_ICONIFY |
1658 OB_FRAME_DECOR_MAXIMIZE);
1659 self->functions &= ~(OB_CLIENT_FUNC_ICONIFY |
1660 OB_CLIENT_FUNC_MAXIMIZE);
1663 case OB_CLIENT_TYPE_SPLASH:
1664 /* these don't get get any decorations, and the only thing you can
1665 do with them is move them */
1666 self->decorations = 0;
1667 self->functions = OB_CLIENT_FUNC_MOVE;
1670 case OB_CLIENT_TYPE_DESKTOP:
1671 /* these windows are not manipulated by the window manager */
1672 self->decorations = 0;
1673 self->functions = 0;
1676 case OB_CLIENT_TYPE_DOCK:
1677 /* these windows are not manipulated by the window manager, but they
1678 can set below layer which has a special meaning */
1679 self->decorations = 0;
1680 self->functions = OB_CLIENT_FUNC_BELOW;
1684 /* Mwm Hints are applied subtractively to what has already been chosen for
1685 decor and functionality */
1686 if (self->mwmhints.flags & OB_MWM_FLAG_DECORATIONS) {
1687 if (! (self->mwmhints.decorations & OB_MWM_DECOR_ALL)) {
1688 if (! ((self->mwmhints.decorations & OB_MWM_DECOR_HANDLE) ||
1689 (self->mwmhints.decorations & OB_MWM_DECOR_TITLE)))
1691 /* if the mwm hints request no handle or title, then all
1692 decorations are disabled, but keep the border if that's
1694 if (self->mwmhints.decorations & OB_MWM_DECOR_BORDER)
1695 self->decorations = OB_FRAME_DECOR_BORDER;
1697 self->decorations = 0;
1702 if (self->mwmhints.flags & OB_MWM_FLAG_FUNCTIONS) {
1703 if (! (self->mwmhints.functions & OB_MWM_FUNC_ALL)) {
1704 if (! (self->mwmhints.functions & OB_MWM_FUNC_RESIZE))
1705 self->functions &= ~OB_CLIENT_FUNC_RESIZE;
1706 if (! (self->mwmhints.functions & OB_MWM_FUNC_MOVE))
1707 self->functions &= ~OB_CLIENT_FUNC_MOVE;
1708 /* dont let mwm hints kill any buttons
1709 if (! (self->mwmhints.functions & OB_MWM_FUNC_ICONIFY))
1710 self->functions &= ~OB_CLIENT_FUNC_ICONIFY;
1711 if (! (self->mwmhints.functions & OB_MWM_FUNC_MAXIMIZE))
1712 self->functions &= ~OB_CLIENT_FUNC_MAXIMIZE;
1714 /* dont let mwm hints kill the close button
1715 if (! (self->mwmhints.functions & MwmFunc_Close))
1716 self->functions &= ~OB_CLIENT_FUNC_CLOSE; */
1720 if (!(self->functions & OB_CLIENT_FUNC_SHADE))
1721 self->decorations &= ~OB_FRAME_DECOR_SHADE;
1722 if (!(self->functions & OB_CLIENT_FUNC_ICONIFY))
1723 self->decorations &= ~OB_FRAME_DECOR_ICONIFY;
1724 if (!(self->functions & OB_CLIENT_FUNC_RESIZE))
1725 self->decorations &= ~(OB_FRAME_DECOR_GRIPS | OB_FRAME_DECOR_HANDLE);
1727 /* can't maximize without moving/resizing */
1728 if (!((self->functions & OB_CLIENT_FUNC_MAXIMIZE) &&
1729 (self->functions & OB_CLIENT_FUNC_MOVE) &&
1730 (self->functions & OB_CLIENT_FUNC_RESIZE))) {
1731 self->functions &= ~OB_CLIENT_FUNC_MAXIMIZE;
1732 self->decorations &= ~OB_FRAME_DECOR_MAXIMIZE;
1735 if (self->max_horz && self->max_vert) {
1736 /* you can't resize fully maximized windows */
1737 self->functions &= ~OB_CLIENT_FUNC_RESIZE;
1738 /* kill the handle on fully maxed windows */
1739 self->decorations &= ~(OB_FRAME_DECOR_HANDLE | OB_FRAME_DECOR_GRIPS);
1742 /* If there are no decorations to remove, don't allow the user to try
1744 if (self->decorations == 0)
1745 self->functions &= ~OB_CLIENT_FUNC_UNDECORATE;
1747 /* finally, the user can have requested no decorations, which overrides
1748 everything (but doesnt give it a border if it doesnt have one) */
1749 if (self->undecorated)
1750 self->decorations = 0;
1752 /* if we don't have a titlebar, then we cannot shade! */
1753 if (!(self->decorations & OB_FRAME_DECOR_TITLEBAR))
1754 self->functions &= ~OB_CLIENT_FUNC_SHADE;
1756 /* now we need to check against rules for the client's current state */
1757 if (self->fullscreen) {
1758 self->functions &= (OB_CLIENT_FUNC_CLOSE |
1759 OB_CLIENT_FUNC_FULLSCREEN |
1760 OB_CLIENT_FUNC_ICONIFY);
1761 self->decorations = 0;
1764 client_change_allowed_actions(self);
1767 /* force reconfigure to make sure decorations are updated */
1768 client_reconfigure(self, TRUE);
1771 static void client_change_allowed_actions(ObClient *self)
1776 /* desktop windows are kept on all desktops */
1777 if (self->type != OB_CLIENT_TYPE_DESKTOP)
1778 actions[num++] = OBT_PROP_ATOM(NET_WM_ACTION_CHANGE_DESKTOP);
1780 if (self->functions & OB_CLIENT_FUNC_SHADE)
1781 actions[num++] = OBT_PROP_ATOM(NET_WM_ACTION_SHADE);
1782 if (self->functions & OB_CLIENT_FUNC_CLOSE)
1783 actions[num++] = OBT_PROP_ATOM(NET_WM_ACTION_CLOSE);
1784 if (self->functions & OB_CLIENT_FUNC_MOVE)
1785 actions[num++] = OBT_PROP_ATOM(NET_WM_ACTION_MOVE);
1786 if (self->functions & OB_CLIENT_FUNC_ICONIFY)
1787 actions[num++] = OBT_PROP_ATOM(NET_WM_ACTION_MINIMIZE);
1788 if (self->functions & OB_CLIENT_FUNC_RESIZE)
1789 actions[num++] = OBT_PROP_ATOM(NET_WM_ACTION_RESIZE);
1790 if (self->functions & OB_CLIENT_FUNC_FULLSCREEN)
1791 actions[num++] = OBT_PROP_ATOM(NET_WM_ACTION_FULLSCREEN);
1792 if (self->functions & OB_CLIENT_FUNC_MAXIMIZE) {
1793 actions[num++] = OBT_PROP_ATOM(NET_WM_ACTION_MAXIMIZE_HORZ);
1794 actions[num++] = OBT_PROP_ATOM(NET_WM_ACTION_MAXIMIZE_VERT);
1796 if (self->functions & OB_CLIENT_FUNC_ABOVE)
1797 actions[num++] = OBT_PROP_ATOM(NET_WM_ACTION_ABOVE);
1798 if (self->functions & OB_CLIENT_FUNC_BELOW)
1799 actions[num++] = OBT_PROP_ATOM(NET_WM_ACTION_BELOW);
1800 if (self->functions & OB_CLIENT_FUNC_UNDECORATE)
1801 actions[num++] = OBT_PROP_ATOM(OB_WM_ACTION_UNDECORATE);
1803 OBT_PROP_SETA32(self->window, NET_WM_ALLOWED_ACTIONS, ATOM, actions, num);
1805 /* make sure the window isn't breaking any rules now
1807 don't check ICONIFY here. just cuz a window can't iconify doesnt mean
1808 it can't be iconified with its parent
1811 if (!(self->functions & OB_CLIENT_FUNC_SHADE) && self->shaded) {
1812 if (self->frame) client_shade(self, FALSE);
1813 else self->shaded = FALSE;
1815 if (!(self->functions & OB_CLIENT_FUNC_FULLSCREEN) && self->fullscreen) {
1816 if (self->frame) client_fullscreen(self, FALSE);
1817 else self->fullscreen = FALSE;
1819 if (!(self->functions & OB_CLIENT_FUNC_MAXIMIZE) && (self->max_horz ||
1821 if (self->frame) client_maximize(self, FALSE, 0);
1822 else self->max_vert = self->max_horz = FALSE;
1826 void client_update_wmhints(ObClient *self)
1830 /* assume a window takes input if it doesn't specify */
1831 self->can_focus = TRUE;
1833 if ((hints = XGetWMHints(obt_display, self->window)) != NULL) {
1836 if (hints->flags & InputHint)
1837 self->can_focus = hints->input;
1839 /* only do this when first managing the window *AND* when we aren't
1841 if (ob_state() != OB_STATE_STARTING && self->frame == NULL)
1842 if (hints->flags & StateHint)
1843 self->iconic = hints->initial_state == IconicState;
1846 self->urgent = (hints->flags & XUrgencyHint);
1847 if (self->urgent && !ur)
1848 client_hilite(self, TRUE);
1849 else if (!self->urgent && ur && self->demands_attention)
1850 client_hilite(self, FALSE);
1852 if (!(hints->flags & WindowGroupHint))
1853 hints->window_group = None;
1855 /* did the group state change? */
1856 if (hints->window_group !=
1857 (self->group ? self->group->leader : None))
1859 ObGroup *oldgroup = self->group;
1861 /* remove from the old group if there was one */
1863 group_remove(self->group, self);
1867 /* add ourself to the group if we have one */
1868 if (hints->window_group != None) {
1869 self->group = group_add(hints->window_group, self);
1872 /* Put ourselves into the new group's transient tree, and remove
1873 ourselves from the old group's */
1874 client_update_transient_tree(self, oldgroup, self->group,
1875 self->transient_for_group,
1876 self->transient_for_group,
1877 client_direct_parent(self),
1878 client_direct_parent(self));
1880 /* Lastly, being in a group, or not, can change if the window is
1881 transient for anything.
1883 The logic for this is:
1884 self->transient = TRUE always if the window wants to be
1885 transient for something, even if transient_for was NULL because
1886 it wasn't in a group before.
1888 If parents was NULL and oldgroup was NULL we can assume
1889 that when we add the new group, it will become transient for
1892 If transient_for_group is TRUE, then it must have already
1893 had a group. If it is getting a new group, the above call to
1894 client_update_transient_tree has already taken care of
1895 everything ! If it is losing all group status then it will
1896 no longer be transient for anything and that needs to be
1899 if (self->transient &&
1900 ((self->parents == NULL && oldgroup == NULL) ||
1901 (self->transient_for_group && !self->group)))
1902 client_update_transient_for(self);
1905 /* the WM_HINTS can contain an icon */
1906 if (hints->flags & IconPixmapHint)
1907 client_update_icons(self);
1913 void client_update_title(ObClient *self)
1916 gchar *visible = NULL;
1918 g_free(self->title);
1919 g_free(self->original_title);
1922 if (!OBT_PROP_GETS(self->window, NET_WM_NAME, utf8, &data)) {
1923 /* try old x stuff */
1924 if (!(OBT_PROP_GETS(self->window, WM_NAME, locale, &data)
1925 || OBT_PROP_GETS(self->window, WM_NAME, utf8, &data))) {
1926 if (self->transient) {
1928 GNOME alert windows are not given titles:
1929 http://developer.gnome.org/projects/gup/hig/draft_hig_new/windows-alert.html
1931 data = g_strdup("");
1933 data = g_strdup(_("Unnamed Window"));
1936 self->original_title = g_strdup(data);
1938 if (self->client_machine) {
1939 visible = g_strdup_printf("%s (%s)", data, self->client_machine);
1944 if (self->not_responding) {
1946 if (self->kill_level > 0)
1947 visible = g_strdup_printf("%s - [%s]", data, _("Killing..."));
1949 visible = g_strdup_printf("%s - [%s]", data, _("Not Responding"));
1953 OBT_PROP_SETS(self->window, NET_WM_VISIBLE_NAME, utf8, visible);
1954 self->title = visible;
1957 frame_adjust_title(self->frame);
1959 /* update the icon title */
1961 g_free(self->icon_title);
1964 if (!OBT_PROP_GETS(self->window, NET_WM_ICON_NAME, utf8, &data))
1965 /* try old x stuff */
1966 if (!(OBT_PROP_GETS(self->window, WM_ICON_NAME, locale, &data) ||
1967 OBT_PROP_GETS(self->window, WM_ICON_NAME, utf8, &data)))
1968 data = g_strdup(self->title);
1970 if (self->client_machine) {
1971 visible = g_strdup_printf("%s (%s)", data, self->client_machine);
1976 if (self->not_responding) {
1978 if (self->kill_level > 0)
1979 visible = g_strdup_printf("%s - [%s]", data, _("Killing..."));
1981 visible = g_strdup_printf("%s - [%s]", data, _("Not Responding"));
1985 OBT_PROP_SETS(self->window, NET_WM_VISIBLE_ICON_NAME, utf8, visible);
1986 self->icon_title = visible;
1989 void client_update_strut(ObClient *self)
1993 gboolean got = FALSE;
1996 if (OBT_PROP_GETA32(self->window, NET_WM_STRUT_PARTIAL, CARDINAL,
2001 STRUT_PARTIAL_SET(strut,
2002 data[0], data[2], data[1], data[3],
2003 data[4], data[5], data[8], data[9],
2004 data[6], data[7], data[10], data[11]);
2010 OBT_PROP_GETA32(self->window, NET_WM_STRUT, CARDINAL, &data, &num)) {
2016 /* use the screen's width/height */
2017 a = screen_physical_area_all_monitors();
2019 STRUT_PARTIAL_SET(strut,
2020 data[0], data[2], data[1], data[3],
2021 a->y, a->y + a->height - 1,
2022 a->x, a->x + a->width - 1,
2023 a->y, a->y + a->height - 1,
2024 a->x, a->x + a->width - 1);
2031 STRUT_PARTIAL_SET(strut, 0, 0, 0, 0,
2032 0, 0, 0, 0, 0, 0, 0, 0);
2034 if (!STRUT_EQUAL(strut, self->strut)) {
2035 self->strut = strut;
2037 /* updating here is pointless while we're being mapped cuz we're not in
2038 the client list yet */
2040 screen_update_areas();
2044 void client_update_icons(ObClient *self)
2049 guint num_seen; /* number of icons present */
2054 /* grab the server, because we might be setting the window's icon and
2055 we don't want them to set it in between and we overwrite their own
2059 if (OBT_PROP_GETA32(self->window, NET_WM_ICON, CARDINAL, &data, &num)) {
2060 /* figure out how many valid icons are in here */
2063 while (i + 2 < num) { /* +2 is to make sure there is a w and h */
2066 /* watch for the data being too small for the specified size,
2067 or for zero sized icons. */
2068 if (i + w*h > num || w == 0 || h == 0) break;
2070 /* convert it to the right bit order for ObRender */
2071 for (j = 0; j < w*h; ++j)
2073 (((data[i+j] >> 24) & 0xff) << RrDefaultAlphaOffset) +
2074 (((data[i+j] >> 16) & 0xff) << RrDefaultRedOffset) +
2075 (((data[i+j] >> 8) & 0xff) << RrDefaultGreenOffset) +
2076 (((data[i+j] >> 0) & 0xff) << RrDefaultBlueOffset);
2078 /* is it in the cache? */
2079 img = RrImageCacheFind(ob_rr_icons, &data[i], w, h);
2080 if (img) RrImageRef(img); /* own it */
2085 /* don't bother looping anymore if we already found it in the cache
2086 since we'll just use that! */
2090 /* if it's not in the cache yet, then add it to the cache now.
2091 we have already converted it to the correct bit order above */
2092 if (!img && num_seen > 0) {
2093 img = RrImageNew(ob_rr_icons);
2095 for (j = 0; j < num_seen; ++j) {
2098 RrImageAddPicture(img, &data[i], w, h);
2106 /* if we didn't find an image from the NET_WM_ICON stuff, then try the
2111 if ((hints = XGetWMHints(obt_display, self->window))) {
2112 if (hints->flags & IconPixmapHint) {
2114 obt_display_ignore_errors(TRUE);
2115 xicon = RrPixmapToRGBA(ob_rr_inst,
2117 (hints->flags & IconMaskHint ?
2118 hints->icon_mask : None),
2119 (gint*)&w, (gint*)&h, &data);
2120 obt_display_ignore_errors(FALSE);
2123 if (w > 0 && h > 0) {
2124 /* is this icon in the cache yet? */
2125 img = RrImageCacheFind(ob_rr_icons, data, w, h);
2126 if (img) RrImageRef(img); /* own it */
2128 /* if not, then add it */
2130 img = RrImageNew(ob_rr_icons);
2131 RrImageAddPicture(img, data, w, h);
2142 /* set the client's icons to be whatever we found */
2143 RrImageUnref(self->icon_set);
2144 self->icon_set = img;
2146 /* if the client has no icon at all, then we set a default icon onto it.
2147 but, if it has parents, then one of them will have an icon already
2149 if (!self->icon_set && !self->parents) {
2150 RrPixel32 *icon = ob_rr_theme->def_win_icon;
2151 gulong *ldata; /* use a long here to satisfy OBT_PROP_SETA32 */
2153 r = g_random_int_range(0,255);
2154 g = g_random_int_range(0,255);
2155 b = g_random_int_range(0,255);
2157 w = ob_rr_theme->def_win_icon_w;
2158 h = ob_rr_theme->def_win_icon_h;
2159 ldata = g_new(gulong, w*h+2);
2162 for (i = 0; i < w*h; ++i)
2163 ldata[i+2] = (((icon[i] >> RrDefaultAlphaOffset) & 0xff) << 24) +
2164 ((((icon[i] >> RrDefaultRedOffset) & 0xff)*r/255) << 16) +
2165 ((((icon[i] >> RrDefaultGreenOffset) & 0xff)*g/255) << 8) +
2166 ((((icon[i] >> RrDefaultBlueOffset) & 0xff)*b/255) << 0);
2167 OBT_PROP_SETA32(self->window, NET_WM_ICON, CARDINAL, ldata, w*h+2);
2169 } else if (self->frame)
2170 /* don't draw the icon empty if we're just setting one now anyways,
2171 we'll get the property change any second */
2172 frame_adjust_icon(self->frame);
2177 void client_update_icon_geometry(ObClient *self)
2182 RECT_SET(self->icon_geometry, 0, 0, 0, 0);
2184 if (OBT_PROP_GETA32(self->window, NET_WM_ICON_GEOMETRY, CARDINAL,
2188 /* don't let them set it with an area < 0 */
2189 RECT_SET(self->icon_geometry, data[0], data[1],
2190 MAX(data[2],0), MAX(data[3],0));
2195 static void client_get_session_ids(ObClient *self)
2202 if (!OBT_PROP_GET32(self->window, WM_CLIENT_LEADER, WINDOW, &leader))
2205 /* get the SM_CLIENT_ID */
2208 got = OBT_PROP_GETS(leader, SM_CLIENT_ID, locale, &self->sm_client_id);
2210 OBT_PROP_GETS(self->window, SM_CLIENT_ID, locale, &self->sm_client_id);
2212 /* get the WM_CLASS (name and class). make them "" if they are not
2216 got = OBT_PROP_GETSS(leader, WM_CLASS, locale, &ss);
2218 got = OBT_PROP_GETSS(self->window, WM_CLASS, locale, &ss);
2222 self->name = g_strdup(ss[0]);
2224 self->class = g_strdup(ss[1]);
2229 if (self->name == NULL) self->name = g_strdup("");
2230 if (self->class == NULL) self->class = g_strdup("");
2232 /* get the WM_WINDOW_ROLE. make it "" if it is not provided */
2235 got = OBT_PROP_GETS(leader, WM_WINDOW_ROLE, locale, &s);
2237 got = OBT_PROP_GETS(self->window, WM_WINDOW_ROLE, locale, &s);
2242 self->role = g_strdup("");
2244 /* get the WM_COMMAND */
2248 got = OBT_PROP_GETSS(leader, WM_COMMAND, locale, &ss);
2250 got = OBT_PROP_GETSS(self->window, WM_COMMAND, locale, &ss);
2253 /* merge/mash them all together */
2254 gchar *merge = NULL;
2257 for (i = 0; ss[i]; ++i) {
2260 merge = g_strconcat(merge, ss[i], NULL);
2262 merge = g_strconcat(ss[i], NULL);
2267 self->wm_command = merge;
2270 /* get the WM_CLIENT_MACHINE */
2273 got = OBT_PROP_GETS(leader, WM_CLIENT_MACHINE, locale, &s);
2275 got = OBT_PROP_GETS(self->window, WM_CLIENT_MACHINE, locale, &s);
2278 gchar localhost[128];
2281 gethostname(localhost, 127);
2282 localhost[127] = '\0';
2283 if (strcmp(localhost, s) != 0)
2284 self->client_machine = s;
2288 /* see if it has the PID set too (the PID requires that the
2289 WM_CLIENT_MACHINE be set) */
2290 if (OBT_PROP_GET32(self->window, NET_WM_PID, CARDINAL, &pid))
2295 static void client_change_wm_state(ObClient *self)
2300 old = self->wmstate;
2302 if (self->shaded || self->iconic ||
2303 (self->desktop != DESKTOP_ALL && self->desktop != screen_desktop))
2305 self->wmstate = IconicState;
2307 self->wmstate = NormalState;
2309 if (old != self->wmstate) {
2310 OBT_PROP_MSG(ob_screen, self->window, KDE_WM_CHANGE_STATE,
2311 self->wmstate, 1, 0, 0, 0);
2313 state[0] = self->wmstate;
2315 OBT_PROP_SETA32(self->window, WM_STATE, WM_STATE, state, 2);
2319 static void client_change_state(ObClient *self)
2321 gulong netstate[13];
2326 netstate[num++] = OBT_PROP_ATOM(NET_WM_STATE_MODAL);
2328 netstate[num++] = OBT_PROP_ATOM(NET_WM_STATE_SHADED);
2330 netstate[num++] = OBT_PROP_ATOM(NET_WM_STATE_HIDDEN);
2331 if (self->skip_taskbar)
2332 netstate[num++] = OBT_PROP_ATOM(NET_WM_STATE_SKIP_TASKBAR);
2333 if (self->skip_pager)
2334 netstate[num++] = OBT_PROP_ATOM(NET_WM_STATE_SKIP_PAGER);
2335 if (self->fullscreen)
2336 netstate[num++] = OBT_PROP_ATOM(NET_WM_STATE_FULLSCREEN);
2338 netstate[num++] = OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_VERT);
2340 netstate[num++] = OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_HORZ);
2342 netstate[num++] = OBT_PROP_ATOM(NET_WM_STATE_ABOVE);
2344 netstate[num++] = OBT_PROP_ATOM(NET_WM_STATE_BELOW);
2345 if (self->demands_attention)
2346 netstate[num++] = OBT_PROP_ATOM(NET_WM_STATE_DEMANDS_ATTENTION);
2347 if (self->undecorated)
2348 netstate[num++] = OBT_PROP_ATOM(OB_WM_STATE_UNDECORATED);
2350 netstate[num++] = OBT_PROP_ATOM(OB_WM_STATE_LOCKED);
2351 OBT_PROP_SETA32(self->window, NET_WM_STATE, ATOM, netstate, num);
2354 frame_adjust_state(self->frame);
2357 ObClient *client_search_focus_tree(ObClient *self)
2362 for (it = self->transients; it; it = g_slist_next(it)) {
2363 if (client_focused(it->data)) return it->data;
2364 if ((ret = client_search_focus_tree(it->data))) return ret;
2369 ObClient *client_search_focus_tree_full(ObClient *self)
2371 if (self->parents) {
2374 for (it = self->parents; it; it = g_slist_next(it)) {
2375 ObClient *c = it->data;
2376 if ((c = client_search_focus_tree_full(it->data))) return c;
2382 /* this function checks the whole tree, the client_search_focus_tree
2383 does not, so we need to check this window */
2384 if (client_focused(self))
2386 return client_search_focus_tree(self);
2390 ObClient *client_search_focus_group_full(ObClient *self)
2395 for (it = self->group->members; it; it = g_slist_next(it)) {
2396 ObClient *c = it->data;
2398 if (client_focused(c)) return c;
2399 if ((c = client_search_focus_tree(it->data))) return c;
2402 if (client_focused(self)) return self;
2406 gboolean client_has_parent(ObClient *self)
2408 return self->parents != NULL;
2411 static ObStackingLayer calc_layer(ObClient *self)
2416 monitor = screen_physical_area_monitor(client_monitor(self));
2418 if (self->type == OB_CLIENT_TYPE_DESKTOP)
2419 l = OB_STACKING_LAYER_DESKTOP;
2420 else if (self->type == OB_CLIENT_TYPE_DOCK) {
2421 if (self->below) l = OB_STACKING_LAYER_NORMAL;
2422 else l = OB_STACKING_LAYER_ABOVE;
2424 else if ((self->fullscreen ||
2425 /* No decorations and fills the monitor = oldskool fullscreen.
2426 But not for maximized windows.
2428 (self->decorations == 0 &&
2429 !(self->max_horz && self->max_vert) &&
2430 RECT_EQUAL(self->area, *monitor))) &&
2431 /* you are fullscreen while you or your children are focused.. */
2432 (client_focused(self) || client_search_focus_tree(self) ||
2433 /* you can be fullscreen if you're on another desktop */
2434 (self->desktop != screen_desktop &&
2435 self->desktop != DESKTOP_ALL) ||
2436 /* and you can also be fullscreen if the focused client is on
2437 another monitor, or nothing else is focused */
2439 client_monitor(focus_client) != client_monitor(self))))
2440 l = OB_STACKING_LAYER_FULLSCREEN;
2441 else if (self->above) l = OB_STACKING_LAYER_ABOVE;
2442 else if (self->below) l = OB_STACKING_LAYER_BELOW;
2443 else l = OB_STACKING_LAYER_NORMAL;
2450 static void client_calc_layer_recursive(ObClient *self, ObClient *orig,
2451 ObStackingLayer min)
2453 ObStackingLayer old, own;
2457 own = calc_layer(self);
2458 self->layer = MAX(own, min);
2460 if (self->layer != old) {
2461 stacking_remove(CLIENT_AS_WINDOW(self));
2462 stacking_add_nonintrusive(CLIENT_AS_WINDOW(self));
2465 /* we've been restacked */
2466 self->visited = TRUE;
2468 for (it = self->transients; it; it = g_slist_next(it))
2469 client_calc_layer_recursive(it->data, orig,
2473 static void client_calc_layer_internal(ObClient *self)
2477 /* transients take on the layer of their parents */
2478 sit = client_search_all_top_parents(self);
2480 for (; sit; sit = g_slist_next(sit))
2481 client_calc_layer_recursive(sit->data, self, 0);
2484 void client_calc_layer(ObClient *self)
2488 /* skip over stuff above fullscreen layer */
2489 for (it = stacking_list; it; it = g_list_next(it))
2490 if (window_layer(it->data) <= OB_STACKING_LAYER_FULLSCREEN) break;
2492 /* find the windows in the fullscreen layer, and mark them not-visited */
2493 for (; it; it = g_list_next(it)) {
2494 if (window_layer(it->data) < OB_STACKING_LAYER_FULLSCREEN) break;
2495 else if (WINDOW_IS_CLIENT(it->data))
2496 WINDOW_AS_CLIENT(it->data)->visited = FALSE;
2499 client_calc_layer_internal(self);
2501 /* skip over stuff above fullscreen layer */
2502 for (it = stacking_list; it; it = g_list_next(it))
2503 if (window_layer(it->data) <= OB_STACKING_LAYER_FULLSCREEN) break;
2505 /* now recalc any windows in the fullscreen layer which have not
2506 had their layer recalced already */
2507 for (; it; it = g_list_next(it)) {
2508 if (window_layer(it->data) < OB_STACKING_LAYER_FULLSCREEN) break;
2509 else if (WINDOW_IS_CLIENT(it->data) &&
2510 !WINDOW_AS_CLIENT(it->data)->visited)
2511 client_calc_layer_internal(it->data);
2515 gboolean client_should_show(ObClient *self)
2519 if (client_normal(self) && screen_showing_desktop)
2521 if (self->desktop == screen_desktop || self->desktop == DESKTOP_ALL)
2527 gboolean client_show(ObClient *self)
2529 gboolean show = FALSE;
2531 if (client_should_show(self)) {
2532 /* replay pending pointer event before showing the window, in case it
2533 should be going to something under the window */
2534 mouse_replay_pointer();
2536 frame_show(self->frame);
2539 /* According to the ICCCM (sec 4.1.3.1) when a window is not visible,
2540 it needs to be in IconicState. This includes when it is on another
2543 client_change_wm_state(self);
2545 hooks_queue(OB_HOOK_WIN_VISIBLE, self);
2550 gboolean client_hide(ObClient *self)
2552 gboolean hide = FALSE;
2554 if (!client_should_show(self)) {
2555 if (self == focus_client) {
2556 event_cancel_all_key_grabs();
2559 /* We don't need to ignore enter events here.
2560 The window can hide/iconify in 3 different ways:
2561 1 - through an x message. in this case we ignore all enter events
2562 caused by responding to the x message (unless underMouse)
2563 2 - by a keyboard action. in this case we ignore all enter events
2564 caused by the action
2565 3 - by a mouse action. in this case they are doing stuff with the
2566 mouse and focus _should_ move.
2568 Also in action_end, we simulate an enter event that can't be ignored
2569 so trying to ignore them is futile in case 3 anyways
2572 /* replay pending pointer event before hiding the window, in case it
2573 should be going to the window */
2574 mouse_replay_pointer();
2576 frame_hide(self->frame);
2579 /* According to the ICCCM (sec 4.1.3.1) when a window is not visible,
2580 it needs to be in IconicState. This includes when it is on another
2583 client_change_wm_state(self);
2585 hooks_queue(OB_HOOK_WIN_INVISIBLE, self);
2590 void client_showhide(ObClient *self)
2592 if (!client_show(self))
2596 gboolean client_normal(ObClient *self) {
2597 return ! (self->type == OB_CLIENT_TYPE_DESKTOP ||
2598 self->type == OB_CLIENT_TYPE_DOCK ||
2599 self->type == OB_CLIENT_TYPE_SPLASH);
2602 gboolean client_helper(ObClient *self)
2604 return (self->type == OB_CLIENT_TYPE_UTILITY ||
2605 self->type == OB_CLIENT_TYPE_MENU ||
2606 self->type == OB_CLIENT_TYPE_TOOLBAR);
2609 gboolean client_mouse_focusable(ObClient *self)
2611 return !(/*self->type == OB_CLIENT_TYPE_MENU ||*/
2612 self->type == OB_CLIENT_TYPE_TOOLBAR ||
2613 self->type == OB_CLIENT_TYPE_SPLASH ||
2614 self->type == OB_CLIENT_TYPE_DOCK);
2617 gboolean client_enter_focusable(ObClient *self)
2619 /* you can focus desktops but it shouldn't on enter */
2620 return (client_mouse_focusable(self) &&
2621 self->type != OB_CLIENT_TYPE_DESKTOP);
2624 static void client_apply_startup_state(ObClient *self,
2625 gint x, gint y, gint w, gint h)
2627 /* save the states that we are going to apply */
2628 gboolean iconic = self->iconic;
2629 gboolean fullscreen = self->fullscreen;
2630 gboolean undecorated = self->undecorated;
2631 gboolean shaded = self->shaded;
2632 gboolean demands_attention = self->demands_attention;
2633 gboolean max_horz = self->max_horz;
2634 gboolean max_vert = self->max_vert;
2638 /* turn them all off in the client, so they won't affect the window
2640 self->iconic = self->fullscreen = self->undecorated = self->shaded =
2641 self->demands_attention = self->max_horz = self->max_vert = FALSE;
2643 /* move the client to its placed position, or it it's already there,
2644 generate a ConfigureNotify telling the client where it is.
2646 do this after adjusting the frame. otherwise it gets all weird and
2647 clients don't work right
2649 do this before applying the states so they have the correct
2650 pre-max/pre-fullscreen values
2652 client_try_configure(self, &x, &y, &w, &h, &l, &l, FALSE);
2653 ob_debug("placed window 0x%x at %d, %d with size %d x %d",
2654 self->window, x, y, w, h);
2655 /* save the area, and make it where it should be for the premax stuff */
2656 oldarea = self->area;
2657 RECT_SET(self->area, x, y, w, h);
2659 /* apply the states. these are in a carefully crafted order.. */
2662 client_iconify(self, TRUE, FALSE, TRUE);
2664 client_fullscreen(self, TRUE);
2666 client_set_undecorated(self, TRUE);
2668 client_shade(self, TRUE);
2669 if (demands_attention)
2670 client_hilite(self, TRUE);
2672 if (max_vert && max_horz)
2673 client_maximize(self, TRUE, 0);
2675 client_maximize(self, TRUE, 2);
2677 client_maximize(self, TRUE, 1);
2679 /* if the window hasn't been configured yet, then do so now, in fact the
2680 x,y,w,h may _not_ be the same as the area rect, which can end up
2681 meaning that the client isn't properly moved/resized by the fullscreen
2683 pho can cause this because it maps at size of the screen but not 0,0
2684 so openbox moves it on screen to 0,0 (thus x,y=0,0 and area.x,y don't).
2685 then fullscreen'ing makes it go to 0,0 which it thinks it already is at
2686 cuz thats where the pre-fullscreen will be. however the actual area is
2687 not, so this needs to be called even if we have fullscreened/maxed
2689 self->area = oldarea;
2690 client_configure(self, x, y, w, h, FALSE, TRUE, FALSE);
2692 /* set the desktop hint, to make sure that it always exists */
2693 OBT_PROP_SET32(self->window, NET_WM_DESKTOP, CARDINAL, self->desktop);
2695 /* nothing to do for the other states:
2704 void client_gravity_resize_w(ObClient *self, gint *x, gint oldw, gint neww)
2706 /* these should be the current values. this is for when you're not moving,
2708 g_assert(*x == self->area.x);
2709 g_assert(oldw == self->area.width);
2712 switch (self->gravity) {
2714 case NorthWestGravity:
2716 case SouthWestGravity:
2723 *x -= (neww - oldw) / 2;
2725 case NorthEastGravity:
2727 case SouthEastGravity:
2733 void client_gravity_resize_h(ObClient *self, gint *y, gint oldh, gint newh)
2735 /* these should be the current values. this is for when you're not moving,
2737 g_assert(*y == self->area.y);
2738 g_assert(oldh == self->area.height);
2741 switch (self->gravity) {
2743 case NorthWestGravity:
2745 case NorthEastGravity:
2752 *y -= (newh - oldh) / 2;
2754 case SouthWestGravity:
2756 case SouthEastGravity:
2762 void client_try_configure(ObClient *self, gint *x, gint *y, gint *w, gint *h,
2763 gint *logicalw, gint *logicalh,
2766 Rect desired = {*x, *y, *w, *h};
2767 frame_rect_to_frame(self->frame, &desired);
2769 /* make the frame recalculate its dimensions n shit without changing
2770 anything visible for real, this way the constraints below can work with
2771 the updated frame dimensions. */
2772 frame_adjust_area(self->frame, FALSE, TRUE, TRUE);
2774 /* gets the frame's position */
2775 frame_client_gravity(self->frame, x, y);
2777 /* these positions are frame positions, not client positions */
2779 /* set the size and position if fullscreen */
2780 if (self->fullscreen) {
2784 i = screen_find_monitor(&desired);
2785 a = screen_physical_area_monitor(i);
2792 user = FALSE; /* ignore if the client can't be moved/resized when it
2796 } else if (self->max_horz || self->max_vert) {
2800 /* use all possible struts when maximizing to the full screen */
2801 i = screen_find_monitor(&desired);
2802 a = screen_area(self->desktop, i,
2803 (self->max_horz && self->max_vert ? NULL : &desired));
2805 /* set the size and position if maximized */
2806 if (self->max_horz) {
2808 *w = a->width - self->frame->size.left - self->frame->size.right;
2810 if (self->max_vert) {
2812 *h = a->height - self->frame->size.top - self->frame->size.bottom;
2815 user = FALSE; /* ignore if the client can't be moved/resized when it
2821 /* gets the client's position */
2822 frame_frame_gravity(self->frame, x, y);
2824 /* work within the preferred sizes given by the window, these may have
2825 changed rather than it's requested width and height, so always run
2826 through this code */
2828 gint basew, baseh, minw, minh;
2830 gfloat minratio, maxratio;
2832 incw = self->fullscreen || self->max_horz ? 1 : self->size_inc.width;
2833 inch = self->fullscreen || self->max_vert ? 1 : self->size_inc.height;
2834 minratio = self->fullscreen || (self->max_horz && self->max_vert) ?
2835 0 : self->min_ratio;
2836 maxratio = self->fullscreen || (self->max_horz && self->max_vert) ?
2837 0 : self->max_ratio;
2839 /* base size is substituted with min size if not specified */
2840 if (self->base_size.width >= 0 || self->base_size.height >= 0) {
2841 basew = self->base_size.width;
2842 baseh = self->base_size.height;
2844 basew = self->min_size.width;
2845 baseh = self->min_size.height;
2847 /* min size is substituted with base size if not specified */
2848 if (self->min_size.width || self->min_size.height) {
2849 minw = self->min_size.width;
2850 minh = self->min_size.height;
2852 minw = self->base_size.width;
2853 minh = self->base_size.height;
2856 /* This comment is no longer true */
2857 /* if this is a user-requested resize, then check against min/max
2860 /* smaller than min size or bigger than max size? */
2861 if (*w > self->max_size.width) *w = self->max_size.width;
2862 if (*w < minw) *w = minw;
2863 if (*h > self->max_size.height) *h = self->max_size.height;
2864 if (*h < minh) *h = minh;
2869 /* keep to the increments */
2873 /* you cannot resize to nothing */
2874 if (basew + *w < 1) *w = 1 - basew;
2875 if (baseh + *h < 1) *h = 1 - baseh;
2877 /* save the logical size */
2878 *logicalw = incw > 1 ? *w : *w + basew;
2879 *logicalh = inch > 1 ? *h : *h + baseh;
2887 /* adjust the height to match the width for the aspect ratios.
2888 for this, min size is not substituted for base size ever. */
2889 *w -= self->base_size.width;
2890 *h -= self->base_size.height;
2893 if (*h * minratio > *w) {
2894 *h = (gint)(*w / minratio);
2896 /* you cannot resize to nothing */
2899 *w = (gint)(*h * minratio);
2903 if (*h * maxratio < *w) {
2904 *h = (gint)(*w / maxratio);
2906 /* you cannot resize to nothing */
2909 *w = (gint)(*h * minratio);
2913 *w += self->base_size.width;
2914 *h += self->base_size.height;
2917 /* these override the above states! if you cant move you can't move! */
2919 if (!(self->functions & OB_CLIENT_FUNC_MOVE)) {
2923 if (!(self->functions & OB_CLIENT_FUNC_RESIZE)) {
2924 *w = self->area.width;
2925 *h = self->area.height;
2933 void client_configure(ObClient *self, gint x, gint y, gint w, gint h,
2934 gboolean user, gboolean final, gboolean force_reply)
2938 gboolean send_resize_client;
2939 gboolean moved = FALSE, resized = FALSE, rootmoved = FALSE;
2940 gboolean fmoved, fresized;
2941 guint fdecor = self->frame->decorations;
2942 gboolean fhorz = self->frame->max_horz;
2943 gboolean fvert = self->frame->max_vert;
2944 gint logicalw, logicalh;
2946 /* find the new x, y, width, and height (and logical size) */
2947 client_try_configure(self, &x, &y, &w, &h, &logicalw, &logicalh, user);
2949 /* set the logical size if things changed */
2950 if (!(w == self->area.width && h == self->area.height))
2951 SIZE_SET(self->logical_size, logicalw, logicalh);
2953 /* figure out if we moved or resized or what */
2954 moved = (x != self->area.x || y != self->area.y);
2955 resized = (w != self->area.width || h != self->area.height);
2957 oldw = self->area.width;
2958 oldh = self->area.height;
2959 oldframe = self->frame->area;
2960 RECT_SET(self->area, x, y, w, h);
2962 /* for app-requested resizes, always resize if 'resized' is true.
2963 for user-requested ones, only resize if final is true, or when
2964 resizing in redraw mode */
2965 send_resize_client = ((!user && resized) ||
2967 (resized && config_resize_redraw))));
2969 /* if the client is enlarging, then resize the client before the frame */
2970 if (send_resize_client && (w > oldw || h > oldh)) {
2971 XMoveResizeWindow(obt_display, self->window,
2972 self->frame->size.left, self->frame->size.top,
2973 MAX(w, oldw), MAX(h, oldh));
2974 frame_adjust_client_area(self->frame);
2977 /* find the frame's dimensions and move/resize it */
2981 /* if decorations changed, then readjust everything for the frame */
2982 if (self->decorations != fdecor ||
2983 self->max_horz != fhorz || self->max_vert != fvert)
2985 fmoved = fresized = TRUE;
2988 /* adjust the frame */
2989 if (fmoved || fresized) {
2990 gulong ignore_start;
2992 ignore_start = event_start_ignore_all_enters();
2994 /* replay pending pointer event before move the window, in case it
2995 would change what window gets the event */
2996 mouse_replay_pointer();
2998 frame_adjust_area(self->frame, fmoved, fresized, FALSE);
3001 event_end_ignore_all_enters(ignore_start);
3004 if (!user || final) {
3005 gint oldrx = self->root_pos.x;
3006 gint oldry = self->root_pos.y;
3007 /* we have reset the client to 0 border width, so don't include
3008 it in these coords */
3009 POINT_SET(self->root_pos,
3010 self->frame->area.x + self->frame->size.left -
3012 self->frame->area.y + self->frame->size.top -
3013 self->border_width);
3014 if (self->root_pos.x != oldrx || self->root_pos.y != oldry)
3018 /* This is kinda tricky and should not be changed.. let me explain!
3020 When user = FALSE, then the request is coming from the application
3021 itself, and we are more strict about when to send a synthetic
3022 ConfigureNotify. We strictly follow the rules of the ICCCM sec 4.1.5
3023 in this case (if force_reply is true)
3025 When user = TRUE, then the request is coming from "us", like when we
3026 maximize a window or something. In this case we are more lenient. We
3027 used to follow the same rules as above, but _Java_ Swing can't handle
3028 this. So just to appease Swing, when user = TRUE, we always send
3029 a synthetic ConfigureNotify to give the window its root coordinates.
3031 if ((!user && !resized && (rootmoved || force_reply)) ||
3032 (user && final && rootmoved))
3036 event.type = ConfigureNotify;
3037 event.xconfigure.display = obt_display;
3038 event.xconfigure.event = self->window;
3039 event.xconfigure.window = self->window;
3041 ob_debug("Sending ConfigureNotify to %s for %d,%d %dx%d",
3042 self->title, self->root_pos.x, self->root_pos.y, w, h);
3044 /* root window real coords */
3045 event.xconfigure.x = self->root_pos.x;
3046 event.xconfigure.y = self->root_pos.y;
3047 event.xconfigure.width = w;
3048 event.xconfigure.height = h;
3049 event.xconfigure.border_width = self->border_width;
3050 event.xconfigure.above = None;
3051 event.xconfigure.override_redirect = FALSE;
3052 XSendEvent(event.xconfigure.display, event.xconfigure.window,
3053 FALSE, StructureNotifyMask, &event);
3056 /* if the client is shrinking, then resize the frame before the client.
3058 both of these resize sections may run, because the top one only resizes
3059 in the direction that is growing
3061 if (send_resize_client && (w <= oldw || h <= oldh)) {
3062 frame_adjust_client_area(self->frame);
3063 XMoveResizeWindow(obt_display, self->window,
3064 self->frame->size.left, self->frame->size.top, w, h);
3067 XFlush(obt_display);
3069 /* if it moved between monitors, then this can affect the stacking
3070 layer of this window or others - for fullscreen windows */
3071 if (screen_find_monitor(&self->frame->area) !=
3072 screen_find_monitor(&oldframe))
3074 client_calc_layer(self);
3078 void client_fullscreen(ObClient *self, gboolean fs)
3082 if (!(self->functions & OB_CLIENT_FUNC_FULLSCREEN) || /* can't */
3083 self->fullscreen == fs) return; /* already done */
3085 self->fullscreen = fs;
3086 client_change_state(self); /* change the state hints on the client */
3089 self->pre_fullscreen_area = self->area;
3090 /* if the window is maximized, its area isn't all that meaningful.
3091 save its premax area instead. */
3092 if (self->max_horz) {
3093 self->pre_fullscreen_area.x = self->pre_max_area.x;
3094 self->pre_fullscreen_area.width = self->pre_max_area.width;
3096 if (self->max_vert) {
3097 self->pre_fullscreen_area.y = self->pre_max_area.y;
3098 self->pre_fullscreen_area.height = self->pre_max_area.height;
3101 /* these will help configure_full figure out where to fullscreen
3105 w = self->area.width;
3106 h = self->area.height;
3108 g_assert(self->pre_fullscreen_area.width > 0 &&
3109 self->pre_fullscreen_area.height > 0);
3111 x = self->pre_fullscreen_area.x;
3112 y = self->pre_fullscreen_area.y;
3113 w = self->pre_fullscreen_area.width;
3114 h = self->pre_fullscreen_area.height;
3115 RECT_SET(self->pre_fullscreen_area, 0, 0, 0, 0);
3118 ob_debug("Window %s going fullscreen (%d)",
3119 self->title, self->fullscreen);
3121 client_setup_decor_and_functions(self, FALSE);
3122 client_move_resize(self, x, y, w, h);
3124 /* and adjust our layer/stacking. do this after resizing the window,
3125 and applying decorations, because windows which fill the screen are
3126 considered "fullscreen" and it affects their layer */
3127 client_calc_layer(self);
3130 /* try focus us when we go into fullscreen mode */
3135 static void client_iconify_recursive(ObClient *self,
3136 gboolean iconic, gboolean curdesk,
3137 gboolean hide_animation)
3140 gboolean changed = FALSE;
3142 if (self->iconic != iconic) {
3143 ob_debug("%sconifying window: 0x%lx", (iconic ? "I" : "Uni"),
3147 /* don't let non-normal windows iconify along with their parents
3149 if (client_normal(self)) {
3150 self->iconic = iconic;
3152 /* update the focus lists.. iconic windows go to the bottom of
3154 focus_order_to_bottom(self);
3159 self->iconic = iconic;
3161 if (curdesk && self->desktop != screen_desktop &&
3162 self->desktop != DESKTOP_ALL)
3163 client_set_desktop(self, screen_desktop, FALSE, FALSE);
3165 /* this puts it after the current focused window */
3166 focus_order_remove(self);
3167 focus_order_add_new(self);
3174 client_change_state(self);
3175 if (config_animate_iconify && !hide_animation)
3176 frame_begin_iconify_animation(self->frame, iconic);
3177 /* do this after starting the animation so it doesn't flash */
3178 client_showhide(self);
3180 hooks_queue((iconic ? OB_HOOK_WIN_ICONIC : OB_HOOK_WIN_UNICONIC),
3184 /* iconify all direct transients, and deiconify all transients
3186 for (it = self->transients; it; it = g_slist_next(it))
3187 if (it->data != self)
3188 if (client_is_direct_child(self, it->data) || !iconic)
3189 client_iconify_recursive(it->data, iconic, curdesk,
3193 void client_iconify(ObClient *self, gboolean iconic, gboolean curdesk,
3194 gboolean hide_animation)
3196 if (self->functions & OB_CLIENT_FUNC_ICONIFY || !iconic) {
3197 /* move up the transient chain as far as possible first */
3198 self = client_search_top_direct_parent(self);
3199 client_iconify_recursive(self, iconic, curdesk, hide_animation);
3203 void client_maximize(ObClient *self, gboolean max, gint dir)
3207 g_assert(dir == 0 || dir == 1 || dir == 2);
3208 if (!(self->functions & OB_CLIENT_FUNC_MAXIMIZE) && max) return;/* can't */
3210 /* check if already done */
3212 if (dir == 0 && self->max_horz && self->max_vert) return;
3213 if (dir == 1 && self->max_horz) return;
3214 if (dir == 2 && self->max_vert) return;
3216 if (dir == 0 && !self->max_horz && !self->max_vert) return;
3217 if (dir == 1 && !self->max_horz) return;
3218 if (dir == 2 && !self->max_vert) return;
3221 /* these will help configure_full figure out which screen to fill with
3225 w = self->area.width;
3226 h = self->area.height;
3229 if ((dir == 0 || dir == 1) && !self->max_horz) { /* horz */
3230 RECT_SET(self->pre_max_area,
3231 self->area.x, self->pre_max_area.y,
3232 self->area.width, self->pre_max_area.height);
3234 if ((dir == 0 || dir == 2) && !self->max_vert) { /* vert */
3235 RECT_SET(self->pre_max_area,
3236 self->pre_max_area.x, self->area.y,
3237 self->pre_max_area.width, self->area.height);
3240 if ((dir == 0 || dir == 1) && self->max_horz) { /* horz */
3241 g_assert(self->pre_max_area.width > 0);
3243 x = self->pre_max_area.x;
3244 w = self->pre_max_area.width;
3246 RECT_SET(self->pre_max_area, 0, self->pre_max_area.y,
3247 0, self->pre_max_area.height);
3249 if ((dir == 0 || dir == 2) && self->max_vert) { /* vert */
3250 g_assert(self->pre_max_area.height > 0);
3252 y = self->pre_max_area.y;
3253 h = self->pre_max_area.height;
3255 RECT_SET(self->pre_max_area, self->pre_max_area.x, 0,
3256 self->pre_max_area.width, 0);
3260 if (dir == 0 || dir == 1) /* horz */
3261 self->max_horz = max;
3262 if (dir == 0 || dir == 2) /* vert */
3263 self->max_vert = max;
3265 client_change_state(self); /* change the state hints on the client */
3267 client_setup_decor_and_functions(self, FALSE);
3268 client_move_resize(self, x, y, w, h);
3270 hooks_queue((max ? OB_HOOK_WIN_MAX : OB_HOOK_WIN_UNMAX), self);
3273 void client_shade(ObClient *self, gboolean shade)
3275 if ((!(self->functions & OB_CLIENT_FUNC_SHADE) &&
3276 shade) || /* can't shade */
3277 self->shaded == shade) return; /* already done */
3279 self->shaded = shade;
3280 client_change_state(self);
3281 client_change_wm_state(self); /* the window is being hidden/shown */
3282 /* resize the frame to just the titlebar */
3283 frame_adjust_area(self->frame, FALSE, TRUE, FALSE);
3285 hooks_queue((shade ? OB_HOOK_WIN_SHADE : OB_HOOK_WIN_UNSHADE), self);
3288 static void client_ping_event(ObClient *self, gboolean dead)
3290 if (self->not_responding != dead) {
3291 self->not_responding = dead;
3292 client_update_title(self);
3295 /* the client isn't responding, so ask to kill it */
3296 client_prompt_kill(self);
3298 /* it came back to life ! */
3300 if (self->kill_prompt) {
3301 prompt_unref(self->kill_prompt);
3302 self->kill_prompt = NULL;
3305 self->kill_level = 0;
3310 void client_close(ObClient *self)
3312 if (!(self->functions & OB_CLIENT_FUNC_CLOSE)) return;
3314 /* if closing an internal obprompt, that is just cancelling it */
3316 prompt_cancel(self->prompt);
3320 /* in the case that the client provides no means to requesting that it
3321 close, we just kill it */
3322 if (!self->delete_window)
3323 /* don't use client_kill(), we should only kill based on PID in
3324 response to a lack of PING replies */
3325 XKillClient(obt_display, self->window);
3327 /* request the client to close with WM_DELETE_WINDOW */
3328 OBT_PROP_MSG_TO(self->window, self->window, WM_PROTOCOLS,
3329 OBT_PROP_ATOM(WM_DELETE_WINDOW), event_curtime,
3330 0, 0, 0, NoEventMask);
3332 /* we're trying to close the window, so see if it is responding. if it
3333 is not, then we will let them kill the window */
3335 ping_start(self, client_ping_event);
3337 /* if we already know the window isn't responding (maybe they clicked
3338 no in the kill dialog but it hasn't come back to life), then show
3340 if (self->not_responding)
3341 client_prompt_kill(self);
3345 #define OB_KILL_RESULT_NO 0
3346 #define OB_KILL_RESULT_YES 1
3348 static gboolean client_kill_requested(ObPrompt *p, gint result, gpointer data)
3350 ObClient *self = data;
3352 if (result == OB_KILL_RESULT_YES)
3354 return TRUE; /* call the cleanup func */
3357 static void client_kill_cleanup(ObPrompt *p, gpointer data)
3359 ObClient *self = data;
3361 g_assert(p == self->kill_prompt);
3363 prompt_unref(self->kill_prompt);
3364 self->kill_prompt = NULL;
3367 static void client_prompt_kill(ObClient *self)
3369 /* check if we're already prompting */
3370 if (!self->kill_prompt) {
3371 ObPromptAnswer answers[] = {
3372 { 0, OB_KILL_RESULT_NO },
3373 { 0, OB_KILL_RESULT_YES }
3376 const gchar *y, *title;
3378 title = self->original_title;
3379 if (title[0] == '\0') {
3380 /* empty string, so use its parent */
3381 ObClient *p = client_search_top_direct_parent(self);
3382 if (p) title = p->original_title;
3385 if (client_on_localhost(self)) {
3388 if (self->kill_level == 0)
3394 (_("The window \"%s\" does not seem to be responding. Do you want to force it to exit by sending the %s signal?"),
3396 y = _("End Process");
3400 (_("The window \"%s\" does not seem to be responding. Do you want to disconnect it from the X server?"),
3402 y = _("Disconnect");
3404 /* set the dialog buttons' text */
3405 answers[0].text = _("Cancel"); /* "no" */
3406 answers[1].text = y; /* "yes" */
3408 self->kill_prompt = prompt_new(m, NULL, answers,
3409 sizeof(answers)/sizeof(answers[0]),
3410 OB_KILL_RESULT_NO, /* default = no */
3411 OB_KILL_RESULT_NO, /* cancel = no */
3412 client_kill_requested,
3413 client_kill_cleanup,
3418 prompt_show(self->kill_prompt, self, TRUE);
3421 void client_kill(ObClient *self)
3423 /* don't kill our own windows */
3424 if (self->prompt) return;
3426 if (client_on_localhost(self) && self->pid) {
3427 /* running on the local host */
3428 if (self->kill_level == 0) {
3429 ob_debug("killing window 0x%x with pid %lu, with SIGTERM",
3430 self->window, self->pid);
3431 kill(self->pid, SIGTERM);
3434 /* show that we're trying to kill it */
3435 client_update_title(self);
3438 ob_debug("killing window 0x%x with pid %lu, with SIGKILL",
3439 self->window, self->pid);
3440 kill(self->pid, SIGKILL); /* kill -9 */
3444 /* running on a remote host */
3445 XKillClient(obt_display, self->window);
3449 void client_hilite(ObClient *self, gboolean hilite)
3451 if (self->demands_attention == hilite)
3452 return; /* no change */
3454 /* don't allow focused windows to hilite */
3455 self->demands_attention = hilite && !client_focused(self);
3456 if (self->frame != NULL) { /* if we're mapping, just set the state */
3457 if (self->demands_attention)
3458 frame_flash_start(self->frame);
3460 frame_flash_stop(self->frame);
3461 client_change_state(self);
3465 static void client_set_desktop_recursive(ObClient *self,
3473 if (target != self->desktop && self->type != OB_CLIENT_TYPE_DESKTOP) {
3475 ob_debug("Setting desktop %u", target+1);
3477 g_assert(target < screen_num_desktops || target == DESKTOP_ALL);
3479 old = self->desktop;
3480 self->desktop = target;
3481 OBT_PROP_SET32(self->window, NET_WM_DESKTOP, CARDINAL, target);
3482 /* the frame can display the current desktop state */
3483 frame_adjust_state(self->frame);
3484 /* 'move' the window to the new desktop */
3488 /* raise if it was not already on the desktop */
3489 if (old != DESKTOP_ALL && !dontraise)
3490 stacking_raise(CLIENT_AS_WINDOW(self));
3491 if (STRUT_EXISTS(self->strut))
3492 screen_update_areas();
3494 /* the new desktop's geometry may be different, so we may need to
3495 resize, for example if we are maximized */
3496 client_reconfigure(self, FALSE);
3498 if (old != self->desktop)
3499 hooks_queue(OB_HOOK_WIN_DESK_CHANGE, self);
3502 /* move all transients */
3503 for (it = self->transients; it; it = g_slist_next(it))
3504 if (it->data != self)
3505 if (client_is_direct_child(self, it->data))
3506 client_set_desktop_recursive(it->data, target,
3507 donthide, dontraise);
3510 void client_set_desktop(ObClient *self, guint target,
3511 gboolean donthide, gboolean dontraise)
3513 self = client_search_top_direct_parent(self);
3514 client_set_desktop_recursive(self, target, donthide, dontraise);
3517 gboolean client_is_direct_child(ObClient *parent, ObClient *child)
3519 while (child != parent && (child = client_direct_parent(child)));
3520 return child == parent;
3523 ObClient *client_search_modal_child(ObClient *self)
3528 for (it = self->transients; it; it = g_slist_next(it)) {
3529 ObClient *c = it->data;
3530 if ((ret = client_search_modal_child(c))) return ret;
3531 if (c->modal) return c;
3536 gboolean client_validate(ObClient *self)
3540 XSync(obt_display, FALSE); /* get all events on the server */
3542 if (XCheckTypedWindowEvent(obt_display, self->window, DestroyNotify, &e) ||
3543 XCheckTypedWindowEvent(obt_display, self->window, UnmapNotify, &e))
3545 XPutBackEvent(obt_display, &e);
3552 void client_set_wm_state(ObClient *self, glong state)
3554 if (state == self->wmstate) return; /* no change */
3558 client_iconify(self, TRUE, TRUE, FALSE);
3561 client_iconify(self, FALSE, TRUE, FALSE);
3566 void client_set_state(ObClient *self, Atom action, glong data1, glong data2)
3568 gboolean shaded = self->shaded;
3569 gboolean fullscreen = self->fullscreen;
3570 gboolean undecorated = self->undecorated;
3571 gboolean locked = self->locked;
3572 gboolean max_horz = self->max_horz;
3573 gboolean max_vert = self->max_vert;
3574 gboolean modal = self->modal;
3575 gboolean iconic = self->iconic;
3576 gboolean demands_attention = self->demands_attention;
3577 gboolean above = self->above;
3578 gboolean below = self->below;
3582 if (!(action == OBT_PROP_ATOM(NET_WM_STATE_ADD) ||
3583 action == OBT_PROP_ATOM(NET_WM_STATE_REMOVE) ||
3584 action == OBT_PROP_ATOM(NET_WM_STATE_TOGGLE)))
3585 /* an invalid action was passed to the client message, ignore it */
3588 for (i = 0; i < 2; ++i) {
3589 Atom state = i == 0 ? data1 : data2;
3591 if (!state) continue;
3593 /* if toggling, then pick whether we're adding or removing */
3594 if (action == OBT_PROP_ATOM(NET_WM_STATE_TOGGLE)) {
3595 if (state == OBT_PROP_ATOM(NET_WM_STATE_MODAL))
3597 else if (state == OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_VERT))
3598 value = self->max_vert;
3599 else if (state == OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_HORZ))
3600 value = self->max_horz;
3601 else if (state == OBT_PROP_ATOM(NET_WM_STATE_SHADED))
3603 else if (state == OBT_PROP_ATOM(NET_WM_STATE_SKIP_TASKBAR))
3604 value = self->skip_taskbar;
3605 else if (state == OBT_PROP_ATOM(NET_WM_STATE_SKIP_PAGER))
3606 value = self->skip_pager;
3607 else if (state == OBT_PROP_ATOM(NET_WM_STATE_HIDDEN))
3608 value = self->iconic;
3609 else if (state == OBT_PROP_ATOM(NET_WM_STATE_FULLSCREEN))
3611 else if (state == OBT_PROP_ATOM(NET_WM_STATE_ABOVE))
3612 value = self->above;
3613 else if (state == OBT_PROP_ATOM(NET_WM_STATE_BELOW))
3614 value = self->below;
3615 else if (state == OBT_PROP_ATOM(NET_WM_STATE_DEMANDS_ATTENTION))
3616 value = self->demands_attention;
3617 else if (state == OBT_PROP_ATOM(OB_WM_STATE_UNDECORATED))
3618 value = undecorated;
3619 else if (state == OBT_PROP_ATOM(OB_WM_STATE_LOCKED))
3621 action = value ? OBT_PROP_ATOM(NET_WM_STATE_REMOVE) :
3622 OBT_PROP_ATOM(NET_WM_STATE_ADD);
3625 value = action == OBT_PROP_ATOM(NET_WM_STATE_ADD);
3626 if (state == OBT_PROP_ATOM(NET_WM_STATE_MODAL)) {
3628 } else if (state == OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_VERT)) {
3630 } else if (state == OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_HORZ)) {
3632 } else if (state == OBT_PROP_ATOM(NET_WM_STATE_SHADED)) {
3634 } else if (state == OBT_PROP_ATOM(NET_WM_STATE_SKIP_TASKBAR)) {
3635 self->skip_taskbar = value;
3636 } else if (state == OBT_PROP_ATOM(NET_WM_STATE_SKIP_PAGER)) {
3637 self->skip_pager = value;
3638 } else if (state == OBT_PROP_ATOM(NET_WM_STATE_HIDDEN)) {
3640 } else if (state == OBT_PROP_ATOM(NET_WM_STATE_FULLSCREEN)) {
3642 } else if (state == OBT_PROP_ATOM(NET_WM_STATE_ABOVE)) {
3644 /* only unset below when setting above, otherwise you can't get to
3648 } else if (state == OBT_PROP_ATOM(NET_WM_STATE_BELOW)) {
3649 /* and vice versa */
3653 } else if (state == OBT_PROP_ATOM(NET_WM_STATE_DEMANDS_ATTENTION)){
3654 demands_attention = value;
3655 } else if (state == OBT_PROP_ATOM(OB_WM_STATE_UNDECORATED)) {
3656 undecorated = value;
3657 } else if (state == OBT_PROP_ATOM(OB_WM_STATE_LOCKED)) {
3662 if (max_horz != self->max_horz || max_vert != self->max_vert) {
3663 if (max_horz != self->max_horz && max_vert != self->max_vert) {
3665 if (max_horz == max_vert) { /* both going the same way */
3666 client_maximize(self, max_horz, 0);
3668 client_maximize(self, max_horz, 1);
3669 client_maximize(self, max_vert, 2);
3673 if (max_horz != self->max_horz)
3674 client_maximize(self, max_horz, 1);
3676 client_maximize(self, max_vert, 2);
3679 /* change fullscreen state before shading, as it will affect if the window
3681 if (fullscreen != self->fullscreen)
3682 client_fullscreen(self, fullscreen);
3683 if (shaded != self->shaded)
3684 client_shade(self, shaded);
3685 if (undecorated != self->undecorated)
3686 client_set_undecorated(self, undecorated);
3687 if (locked != self->locked)
3688 client_set_locked(self, locked);
3689 if (above != self->above || below != self->below) {
3690 self->above = above;
3691 self->below = below;
3692 client_calc_layer(self);
3695 if (modal != self->modal) {
3696 self->modal = modal;
3697 /* when a window changes modality, then its stacking order with its
3698 transients needs to change */
3699 stacking_raise(CLIENT_AS_WINDOW(self));
3701 /* it also may get focused. if something is focused that shouldn't
3702 be focused anymore, then move the focus */
3703 if (focus_client && client_focus_target(focus_client) != focus_client)
3704 client_focus(focus_client);
3707 if (iconic != self->iconic)
3708 client_iconify(self, iconic, FALSE, FALSE);
3710 if (demands_attention != self->demands_attention)
3711 client_hilite(self, demands_attention);
3713 client_change_state(self); /* change the hint to reflect these changes */
3716 ObClient *client_focus_target(ObClient *self)
3718 ObClient *child = NULL;
3720 child = client_search_modal_child(self);
3721 if (child) return child;
3725 gboolean client_can_focus(ObClient *self)
3727 /* choose the correct target */
3728 self = client_focus_target(self);
3730 if (!self->frame->visible)
3733 if (!(self->can_focus || self->focus_notify))
3739 gboolean client_focus(ObClient *self)
3743 XkbGetState(obt_display, XkbUseCoreKbd, &state);
3744 if (state.locked_mods & 128)
3748 /* we might not focus this window, so if we have modal children which would
3749 be focused instead, bring them to this desktop */
3750 client_bring_modal_windows(self);
3752 /* choose the correct target */
3753 self = client_focus_target(self);
3755 if (!client_can_focus(self)) {
3756 ob_debug_type(OB_DEBUG_FOCUS,
3757 "Client %s can't be focused", self->title);
3761 ob_debug_type(OB_DEBUG_FOCUS,
3762 "Focusing client \"%s\" (0x%x) at time %u",
3763 self->title, self->window, event_curtime);
3765 /* if using focus_delay, stop the timer now so that focus doesn't
3767 event_halt_focus_delay();
3769 event_cancel_all_key_grabs();
3771 obt_display_ignore_errors(TRUE);
3773 if (self->can_focus) {
3774 /* This can cause a BadMatch error with CurrentTime, or if an app
3775 passed in a bad time for _NET_WM_ACTIVE_WINDOW. */
3776 XSetInputFocus(obt_display, self->window, RevertToPointerRoot,
3780 if (self->focus_notify) {
3782 ce.xclient.type = ClientMessage;
3783 ce.xclient.message_type = OBT_PROP_ATOM(WM_PROTOCOLS);
3784 ce.xclient.display = obt_display;
3785 ce.xclient.window = self->window;
3786 ce.xclient.format = 32;
3787 ce.xclient.data.l[0] = OBT_PROP_ATOM(WM_TAKE_FOCUS);
3788 ce.xclient.data.l[1] = event_curtime;
3789 ce.xclient.data.l[2] = 0l;
3790 ce.xclient.data.l[3] = 0l;
3791 ce.xclient.data.l[4] = 0l;
3792 XSendEvent(obt_display, self->window, FALSE, NoEventMask, &ce);
3795 obt_display_ignore_errors(FALSE);
3797 ob_debug_type(OB_DEBUG_FOCUS, "Error focusing? %d",
3798 obt_display_error_occured);
3799 return !obt_display_error_occured;
3802 static void client_present(ObClient *self, gboolean here, gboolean raise,
3805 if (client_normal(self) && screen_showing_desktop)
3806 screen_show_desktop(FALSE, self);
3808 client_iconify(self, FALSE, here, FALSE);
3809 if (self->desktop != DESKTOP_ALL &&
3810 self->desktop != screen_desktop)
3813 client_set_desktop(self, screen_desktop, FALSE, TRUE);
3815 screen_set_desktop(self->desktop, FALSE);
3816 } else if (!self->frame->visible)
3817 /* if its not visible for other reasons, then don't mess
3820 if (self->shaded && unshade)
3821 client_shade(self, FALSE);
3823 stacking_raise(CLIENT_AS_WINDOW(self));
3828 /* this function exists to map to the client_activate message in the ewmh,
3829 the user arg is unused because nobody uses it correctly anyway. */
3830 void client_activate(ObClient *self, gboolean here, gboolean raise,
3831 gboolean unshade, gboolean user)
3833 client_present(self, here, raise, unshade);
3836 static void client_bring_windows_recursive(ObClient *self,
3844 for (it = self->transients; it; it = g_slist_next(it))
3845 client_bring_windows_recursive(it->data, desktop,
3846 helpers, modals, iconic);
3848 if (((helpers && client_helper(self)) ||
3849 (modals && self->modal)) &&
3850 ((self->desktop != desktop && self->desktop != DESKTOP_ALL) ||
3851 (iconic && self->iconic)))
3853 if (iconic && self->iconic)
3854 client_iconify(self, FALSE, TRUE, FALSE);
3856 client_set_desktop(self, desktop, FALSE, FALSE);
3860 void client_bring_helper_windows(ObClient *self)
3862 client_bring_windows_recursive(self, self->desktop, TRUE, FALSE, FALSE);
3865 void client_bring_modal_windows(ObClient *self)
3867 client_bring_windows_recursive(self, self->desktop, FALSE, TRUE, TRUE);
3870 gboolean client_focused(ObClient *self)
3872 return self == focus_client;
3875 RrImage* client_icon(ObClient *self)
3877 RrImage *ret = NULL;
3880 ret = self->icon_set;
3881 else if (self->parents) {
3883 for (it = self->parents; it && !ret; it = g_slist_next(it))
3884 ret = client_icon(it->data);
3887 ret = client_default_icon;
3891 void client_set_layer(ObClient *self, gint layer)
3895 self->above = FALSE;
3896 } else if (layer == 0) {
3897 self->below = self->above = FALSE;
3899 self->below = FALSE;
3902 client_calc_layer(self);
3903 client_change_state(self); /* reflect this in the state hints */
3906 void client_set_locked(ObClient *self, gboolean locked)
3908 if (self->locked != locked) {
3909 self->locked = locked;
3910 client_change_state(self);
3914 void client_set_undecorated(ObClient *self, gboolean undecorated)
3916 if (self->undecorated != undecorated &&
3917 /* don't let it undecorate if the function is missing, but let
3919 (self->functions & OB_CLIENT_FUNC_UNDECORATE || !undecorated))
3921 self->undecorated = undecorated;
3922 client_setup_decor_and_functions(self, TRUE);
3923 client_change_state(self); /* reflect this in the state hints */
3925 hooks_queue((undecorated ?
3926 OB_HOOK_WIN_UNDECORATED : OB_HOOK_WIN_DECORATED), self);
3930 guint client_monitor(ObClient *self)
3932 return screen_find_monitor(&self->frame->area);
3935 ObClient *client_direct_parent(ObClient *self)
3937 if (!self->parents) return NULL;
3938 if (self->transient_for_group) return NULL;
3939 return self->parents->data;
3942 ObClient *client_search_top_direct_parent(ObClient *self)
3945 while ((p = client_direct_parent(self))) self = p;
3949 static GSList *client_search_all_top_parents_internal(ObClient *self,
3951 ObStackingLayer layer)
3956 /* move up the direct transient chain as far as possible */
3957 while ((p = client_direct_parent(self)) &&
3958 (!bylayer || p->layer == layer))
3962 ret = g_slist_prepend(NULL, self);
3964 ret = g_slist_copy(self->parents);
3969 GSList *client_search_all_top_parents(ObClient *self)
3971 return client_search_all_top_parents_internal(self, FALSE, 0);
3974 GSList *client_search_all_top_parents_layer(ObClient *self)
3976 return client_search_all_top_parents_internal(self, TRUE, self->layer);
3979 ObClient *client_search_focus_parent(ObClient *self)
3983 for (it = self->parents; it; it = g_slist_next(it))
3984 if (client_focused(it->data)) return it->data;
3989 ObClient *client_search_focus_parent_full(ObClient *self)
3992 ObClient *ret = NULL;
3994 for (it = self->parents; it; it = g_slist_next(it)) {
3995 if (client_focused(it->data))
3998 ret = client_search_focus_parent_full(it->data);
4004 ObClient *client_search_parent(ObClient *self, ObClient *search)
4008 for (it = self->parents; it; it = g_slist_next(it))
4009 if (it->data == search) return search;
4014 ObClient *client_search_transient(ObClient *self, ObClient *search)
4018 for (sit = self->transients; sit; sit = g_slist_next(sit)) {
4019 if (sit->data == search)
4021 if (client_search_transient(sit->data, search))
4027 static void detect_edge(Rect area, ObDirection dir,
4028 gint my_head, gint my_size,
4029 gint my_edge_start, gint my_edge_size,
4030 gint *dest, gboolean *near_edge)
4032 gint edge_start, edge_size, head, tail;
4033 gboolean skip_head = FALSE, skip_tail = FALSE;
4036 case OB_DIRECTION_NORTH:
4037 case OB_DIRECTION_SOUTH:
4038 edge_start = area.x;
4039 edge_size = area.width;
4041 case OB_DIRECTION_EAST:
4042 case OB_DIRECTION_WEST:
4043 edge_start = area.y;
4044 edge_size = area.height;
4047 g_assert_not_reached();
4050 /* do we collide with this window? */
4051 if (!RANGES_INTERSECT(my_edge_start, my_edge_size,
4052 edge_start, edge_size))
4056 case OB_DIRECTION_NORTH:
4057 head = RECT_BOTTOM(area);
4058 tail = RECT_TOP(area);
4060 case OB_DIRECTION_SOUTH:
4061 head = RECT_TOP(area);
4062 tail = RECT_BOTTOM(area);
4064 case OB_DIRECTION_WEST:
4065 head = RECT_RIGHT(area);
4066 tail = RECT_LEFT(area);
4068 case OB_DIRECTION_EAST:
4069 head = RECT_LEFT(area);
4070 tail = RECT_RIGHT(area);
4073 g_assert_not_reached();
4076 case OB_DIRECTION_NORTH:
4077 case OB_DIRECTION_WEST:
4078 /* check if our window is past the head of this window */
4079 if (my_head <= head + 1)
4081 /* check if our window's tail is past the tail of this window */
4082 if (my_head + my_size - 1 <= tail)
4084 /* check if the head of this window is closer than the previously
4085 chosen edge (take into account that the previously chosen
4086 edge might have been a tail, not a head) */
4087 if (head + (*near_edge ? 0 : my_size) <= *dest)
4089 /* check if the tail of this window is closer than the previously
4090 chosen edge (take into account that the previously chosen
4091 edge might have been a head, not a tail) */
4092 if (tail - (!*near_edge ? 0 : my_size) <= *dest)
4095 case OB_DIRECTION_SOUTH:
4096 case OB_DIRECTION_EAST:
4097 /* check if our window is past the head of this window */
4098 if (my_head >= head - 1)
4100 /* check if our window's tail is past the tail of this window */
4101 if (my_head - my_size + 1 >= tail)
4103 /* check if the head of this window is closer than the previously
4104 chosen edge (take into account that the previously chosen
4105 edge might have been a tail, not a head) */
4106 if (head - (*near_edge ? 0 : my_size) >= *dest)
4108 /* check if the tail of this window is closer than the previously
4109 chosen edge (take into account that the previously chosen
4110 edge might have been a head, not a tail) */
4111 if (tail + (!*near_edge ? 0 : my_size) >= *dest)
4115 g_assert_not_reached();
4118 ob_debug("my head %d size %d", my_head, my_size);
4119 ob_debug("head %d tail %d dest %d", head, tail, *dest);
4121 ob_debug("using near edge %d", head);
4125 else if (!skip_tail) {
4126 ob_debug("using far edge %d", tail);
4132 void client_find_edge_directional(ObClient *self, ObDirection dir,
4133 gint my_head, gint my_size,
4134 gint my_edge_start, gint my_edge_size,
4135 gint *dest, gboolean *near_edge)
4143 a = screen_area(self->desktop, SCREEN_AREA_ALL_MONITORS,
4144 &self->frame->area);
4145 mon = screen_area(self->desktop, SCREEN_AREA_ONE_MONITOR,
4146 &self->frame->area);
4149 case OB_DIRECTION_NORTH:
4150 if (my_head >= RECT_TOP(*mon) + 1)
4151 edge = RECT_TOP(*mon) - 1;
4153 edge = RECT_TOP(*a) - 1;
4155 case OB_DIRECTION_SOUTH:
4156 if (my_head <= RECT_BOTTOM(*mon) - 1)
4157 edge = RECT_BOTTOM(*mon) + 1;
4159 edge = RECT_BOTTOM(*a) + 1;
4161 case OB_DIRECTION_EAST:
4162 if (my_head <= RECT_RIGHT(*mon) - 1)
4163 edge = RECT_RIGHT(*mon) + 1;
4165 edge = RECT_RIGHT(*a) + 1;
4167 case OB_DIRECTION_WEST:
4168 if (my_head >= RECT_LEFT(*mon) + 1)
4169 edge = RECT_LEFT(*mon) - 1;
4171 edge = RECT_LEFT(*a) - 1;
4174 g_assert_not_reached();
4176 /* default to the far edge, then narrow it down */
4180 for (it = client_list; it; it = g_list_next(it)) {
4181 ObClient *cur = it->data;
4183 /* skip windows to not bump into */
4188 if (self->desktop != cur->desktop && cur->desktop != DESKTOP_ALL &&
4189 cur->desktop != screen_desktop)
4192 ob_debug("trying window %s", cur->title);
4194 RECT_SET(expand, cur->frame->area.x - config_window_margin,
4195 cur->frame->area.y - config_window_margin,
4196 cur->frame->area.width + 2 * config_window_margin,
4197 cur->frame->area.height + 2 * config_window_margin);
4198 detect_edge(expand, dir, my_head, my_size, my_edge_start,
4199 my_edge_size, dest, near_edge);
4201 dock_get_area(&dock_area);
4202 detect_edge(dock_area, dir, my_head, my_size, my_edge_start,
4203 my_edge_size, dest, near_edge);
4208 void client_find_move_directional(ObClient *self, ObDirection dir,
4212 gint e, e_start, e_size;
4216 case OB_DIRECTION_EAST:
4217 head = RECT_RIGHT(self->frame->area);
4218 size = self->frame->area.width;
4219 e_start = RECT_TOP(self->frame->area);
4220 e_size = self->frame->area.height;
4222 case OB_DIRECTION_WEST:
4223 head = RECT_LEFT(self->frame->area);
4224 size = self->frame->area.width;
4225 e_start = RECT_TOP(self->frame->area);
4226 e_size = self->frame->area.height;
4228 case OB_DIRECTION_NORTH:
4229 head = RECT_TOP(self->frame->area);
4230 size = self->frame->area.height;
4231 e_start = RECT_LEFT(self->frame->area);
4232 e_size = self->frame->area.width;
4234 case OB_DIRECTION_SOUTH:
4235 head = RECT_BOTTOM(self->frame->area);
4236 size = self->frame->area.height;
4237 e_start = RECT_LEFT(self->frame->area);
4238 e_size = self->frame->area.width;
4241 g_assert_not_reached();
4244 client_find_edge_directional(self, dir, head, size,
4245 e_start, e_size, &e, &near);
4246 *x = self->frame->area.x;
4247 *y = self->frame->area.y;
4249 case OB_DIRECTION_EAST:
4250 if (near) e -= self->frame->area.width;
4254 case OB_DIRECTION_WEST:
4256 else e -= self->frame->area.width;
4259 case OB_DIRECTION_NORTH:
4261 else e -= self->frame->area.height;
4264 case OB_DIRECTION_SOUTH:
4265 if (near) e -= self->frame->area.height;
4270 g_assert_not_reached();
4272 frame_frame_gravity(self->frame, x, y);
4275 void client_find_resize_directional(ObClient *self, ObDirection side,
4277 gint *x, gint *y, gint *w, gint *h)
4280 gint e, e_start, e_size, delta;
4285 case OB_DIRECTION_EAST:
4286 head = RECT_RIGHT(self->frame->area) +
4287 (self->size_inc.width - 1) * (grow ? 1 : 0);
4288 e_start = RECT_TOP(self->frame->area);
4289 e_size = self->frame->area.height;
4290 dir = grow ? OB_DIRECTION_EAST : OB_DIRECTION_WEST;
4292 case OB_DIRECTION_WEST:
4293 head = RECT_LEFT(self->frame->area) -
4294 (self->size_inc.width - 1) * (grow ? 1 : 0);
4295 e_start = RECT_TOP(self->frame->area);
4296 e_size = self->frame->area.height;
4297 dir = grow ? OB_DIRECTION_WEST : OB_DIRECTION_EAST;
4299 case OB_DIRECTION_NORTH:
4300 head = RECT_TOP(self->frame->area) -
4301 (self->size_inc.height - 1) * (grow ? 1 : 0);
4302 e_start = RECT_LEFT(self->frame->area);
4303 e_size = self->frame->area.width;
4304 dir = grow ? OB_DIRECTION_NORTH : OB_DIRECTION_SOUTH;
4306 case OB_DIRECTION_SOUTH:
4307 head = RECT_BOTTOM(self->frame->area) +
4308 (self->size_inc.height - 1) * (grow ? 1 : 0);
4309 e_start = RECT_LEFT(self->frame->area);
4310 e_size = self->frame->area.width;
4311 dir = grow ? OB_DIRECTION_SOUTH : OB_DIRECTION_NORTH;
4314 g_assert_not_reached();
4317 ob_debug("head %d dir %d", head, dir);
4318 client_find_edge_directional(self, dir, head, 1,
4319 e_start, e_size, &e, &near);
4320 ob_debug("edge %d", e);
4321 *x = self->frame->area.x;
4322 *y = self->frame->area.y;
4323 *w = self->frame->area.width;
4324 *h = self->frame->area.height;
4326 case OB_DIRECTION_EAST:
4327 if (grow == near) --e;
4328 delta = e - RECT_RIGHT(self->frame->area);
4331 case OB_DIRECTION_WEST:
4332 if (grow == near) ++e;
4333 delta = RECT_LEFT(self->frame->area) - e;
4337 case OB_DIRECTION_NORTH:
4338 if (grow == near) ++e;
4339 delta = RECT_TOP(self->frame->area) - e;
4343 case OB_DIRECTION_SOUTH:
4344 if (grow == near) --e;
4345 delta = e - RECT_BOTTOM(self->frame->area);
4349 g_assert_not_reached();
4351 frame_frame_gravity(self->frame, x, y);
4352 *w -= self->frame->size.left + self->frame->size.right;
4353 *h -= self->frame->size.top + self->frame->size.bottom;
4356 ObClient* client_under_pointer(void)
4360 ObClient *ret = NULL;
4362 if (screen_pointer_pos(&x, &y)) {
4363 for (it = stacking_list; it; it = g_list_next(it)) {
4364 if (WINDOW_IS_CLIENT(it->data)) {
4365 ObClient *c = WINDOW_AS_CLIENT(it->data);
4366 if (c->frame->visible &&
4367 /* check the desktop, this is done during desktop
4368 switching and windows are shown/hidden status is not
4370 (c->desktop == screen_desktop ||
4371 c->desktop == DESKTOP_ALL) &&
4372 /* ignore all animating windows */
4373 !frame_iconify_animating(c->frame) &&
4374 RECT_CONTAINS(c->frame->area, x, y))
4385 gboolean client_has_group_siblings(ObClient *self)
4387 return self->group && self->group->members->next;
4390 /*! Returns TRUE if the client is running on the same machine as Openbox */
4391 gboolean client_on_localhost(ObClient *self)
4393 return self->client_machine == NULL;