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"
28 #include "engine_interface.h"
38 #include "menuframe.h"
41 #include "render/render.h"
43 #include "obt/display.h"
52 # include <signal.h> /* for kill() */
56 #include <X11/Xutil.h>
58 /*! The event mask to grab on client windows */
59 #define CLIENT_EVENTMASK (PropertyChangeMask | StructureNotifyMask | \
62 #define CLIENT_NOPROPAGATEMASK (ButtonPressMask | ButtonReleaseMask | \
67 ObClientCallback func;
71 GList *client_list = NULL;
73 static GSList *client_destroy_notifies = NULL;
75 static void client_get_all(ObClient *self, gboolean real);
76 static void client_get_startup_id(ObClient *self);
77 static void client_get_session_ids(ObClient *self);
78 static void client_get_area(ObClient *self);
79 static void client_get_desktop(ObClient *self);
80 static void client_get_state(ObClient *self);
81 static void client_get_shaped(ObClient *self);
82 static void client_get_mwm_hints(ObClient *self);
83 static void client_get_colormap(ObClient *self);
84 static void client_set_desktop_recursive(ObClient *self,
88 static void client_change_allowed_actions(ObClient *self);
89 static void client_change_state(ObClient *self);
90 static void client_change_wm_state(ObClient *self);
91 static void client_apply_startup_state(ObClient *self,
92 gint x, gint y, gint w, gint h);
93 static void client_restore_session_state(ObClient *self);
94 static gboolean client_restore_session_stacking(ObClient *self);
95 static ObAppSettings *client_get_settings_state(ObClient *self);
96 static void client_update_transient_tree(ObClient *self,
97 ObGroup *oldgroup, ObGroup *newgroup,
98 gboolean oldgtran, gboolean newgtran,
100 ObClient *newparent);
101 static void client_present(ObClient *self, gboolean here, gboolean raise,
103 static GSList *client_search_all_top_parents_internal(ObClient *self,
105 ObStackingLayer layer);
106 static void client_call_notifies(ObClient *self, GSList *list);
107 static void client_ping_event(ObClient *self, gboolean dead);
108 static void client_prompt_kill(ObClient *self);
111 void client_startup(gboolean reconfig)
113 if (reconfig) return;
118 void client_shutdown(gboolean reconfig)
120 if (reconfig) return;
123 static void client_call_notifies(ObClient *self, GSList *list)
127 for (it = list; it; it = g_slist_next(it)) {
128 ClientCallback *d = it->data;
129 d->func(self, d->data);
133 void client_add_destroy_notify(ObClientCallback func, gpointer data)
135 ClientCallback *d = g_new(ClientCallback, 1);
138 client_destroy_notifies = g_slist_prepend(client_destroy_notifies, d);
141 void client_remove_destroy_notify(ObClientCallback func)
145 for (it = client_destroy_notifies; it; it = g_slist_next(it)) {
146 ClientCallback *d = it->data;
147 if (d->func == func) {
149 client_destroy_notifies =
150 g_slist_delete_link(client_destroy_notifies, it);
156 void client_set_list(void)
158 Window *windows, *win_it;
160 guint size = g_list_length(client_list);
162 /* create an array of the window ids */
164 windows = g_new(Window, size);
166 for (it = client_list; it; it = g_list_next(it), ++win_it)
167 *win_it = ((ObClient*)it->data)->window;
171 OBT_PROP_SETA32(obt_root(ob_screen), NET_CLIENT_LIST, WINDOW,
172 (gulong*)windows, size);
180 void client_manage(Window window, ObPrompt *prompt)
183 XSetWindowAttributes attrib_set;
184 gboolean activate = FALSE;
185 ObAppSettings *settings;
186 gboolean transient = FALSE;
187 Rect place, *monitor;
188 Time launch_time, map_time;
190 ob_debug("Managing window: 0x%lx", window);
192 map_time = event_get_server_time();
194 /* choose the events we want to receive on the CLIENT window
195 (ObPrompt windows can request events too) */
196 attrib_set.event_mask = CLIENT_EVENTMASK |
197 (prompt ? prompt->event_mask : 0);
198 attrib_set.do_not_propagate_mask = CLIENT_NOPROPAGATEMASK;
199 XChangeWindowAttributes(obt_display, window,
200 CWEventMask|CWDontPropagate, &attrib_set);
202 /* create the ObClient struct, and populate it from the hints on the
204 self = g_new0(ObClient, 1);
205 self->obwin.type = OB_WINDOW_CLASS_CLIENT;
206 self->window = window;
207 self->prompt = prompt;
209 /* non-zero defaults */
210 self->wmstate = WithdrawnState; /* make sure it gets updated first time */
211 self->gravity = NorthWestGravity;
212 self->desktop = screen_num_desktops; /* always an invalid value */
214 /* get all the stuff off the window */
215 client_get_all(self, TRUE);
217 ob_debug("Window type: %d", self->type);
218 ob_debug("Window group: 0x%x", self->group?self->group->leader:0);
220 /* now we have all of the window's information so we can set this up.
221 do this before creating the frame, so it can tell that we are still
222 mapping and doesn't go applying things right away */
223 client_setup_decor_and_functions(self, FALSE);
225 /* specify that if we exit, the window should not be destroyed and
226 should be reparented back to root automatically, unless we are managing
227 an internal ObPrompt window */
229 XChangeSaveSet(obt_display, window, SetModeInsert);
231 /* create the decoration frame for the client window */
232 self->frame = render_plugin->frame_new(self);
233 render_plugin->frame_grab(self->frame, window_map);
235 /* we've grabbed everything and set everything that we need to at mapping
239 /* per-app settings override stuff from client_get_all, and return the
240 settings for other uses too. the returned settings is a shallow copy,
241 that needs to be freed with g_free(). */
242 settings = client_get_settings_state(self);
243 /* the session should get the last say though */
244 client_restore_session_state(self);
246 /* tell startup notification that this app started */
247 launch_time = sn_app_started(self->startup_id, self->class, self->name);
249 /* do this after we have a frame.. it uses the frame to help determine the
250 WM_STATE to apply. */
251 client_change_state(self);
253 /* add ourselves to the focus order */
254 focus_order_add_new(self);
256 /* do this to add ourselves to the stacking list in a non-intrusive way */
257 client_calc_layer(self);
259 /* focus the new window? */
260 if (ob_state() != OB_STATE_STARTING &&
261 (!self->session || self->session->focused) &&
262 /* this means focus=true for window is same as config_focus_new=true */
263 ((config_focus_new || (settings && settings->focus == 1)) ||
264 client_search_focus_tree_full(self)) &&
265 /* this checks for focus=false for the window */
266 (!settings || settings->focus != 0) &&
267 focus_valid_target(self, FALSE, FALSE, TRUE, FALSE, FALSE))
272 /* remove the client's border */
273 XSetWindowBorderWidth(obt_display, self->window, 0);
275 /* adjust the frame to the client's size before showing or placing
277 render_plugin->frame_set_client_area (self->frame, self->area);
278 render_plugin->frame_set_hover_flag (self->frame, OB_BUTTON_NONE);
279 render_plugin->frame_set_press_flag (self->frame, OB_BUTTON_NONE);
280 render_plugin->frame_set_is_focus (self->frame, FALSE);
281 render_plugin->frame_set_decorations (self->frame, self->decorations);
282 render_plugin->frame_update_layout (self->frame, FALSE, TRUE);
283 render_plugin->frame_update_skin (self->frame);
285 /* where the frame was placed is where the window was originally */
287 monitor = screen_physical_area_monitor(screen_find_monitor(&place));
289 /* figure out placement for the window if the window is new */
290 if (ob_state() == OB_STATE_RUNNING) {
291 ob_debug("Positioned: %s @ %d %d",
292 (!self->positioned ? "no" :
293 (self->positioned == PPosition ? "program specified" :
294 (self->positioned == USPosition ? "user specified" :
295 (self->positioned == (PPosition | USPosition) ?
296 "program + user specified" :
297 "BADNESS !?")))), place.x, place.y);
299 ob_debug("Sized: %s @ %d %d",
300 (!self->sized ? "no" :
301 (self->sized == PSize ? "program specified" :
302 (self->sized == USSize ? "user specified" :
303 (self->sized == (PSize | USSize) ?
304 "program + user specified" :
305 "BADNESS !?")))), place.width, place.height);
307 /* splash screens are also returned as TRUE for transient,
308 and so will be forced on screen below */
309 transient = place_client(self, &place.x, &place.y, settings);
311 /* make sure the window is visible. */
312 client_find_onscreen(self, &place.x, &place.y,
313 place.width, place.height,
314 /* non-normal clients has less rules, and
315 windows that are being restored from a
316 session do also. we can assume you want
317 it back where you saved it. Clients saying
318 they placed themselves are subjected to
319 harder rules, ones that are placed by
320 place.c or by the user are allowed partially
321 off-screen and on xinerama divides (ie,
322 it is up to the placement routines to avoid
323 the xinerama divides)
325 splash screens get "transient" set to TRUE by
326 the place_client call
328 ob_state() == OB_STATE_RUNNING &&
330 (!((self->positioned & USPosition) ||
331 (settings && settings->pos_given)) &&
332 client_normal(self) &&
334 /* don't move oldschool fullscreen windows to
335 fit inside the struts (fixes Acroread, which
336 makes its fullscreen window fit the screen
337 but it is not USSize'd or USPosition'd) */
338 !(self->decorations == 0 &&
339 RECT_EQUAL(place, *monitor)))));
342 /* if the window isn't user-sized, then make it fit inside
343 the visible screen area on its monitor. Use basically the same rules
344 for forcing the window on screen in the client_find_onscreen call.
346 do this after place_client, it chooses the monitor!
348 splash screens get "transient" set to TRUE by
349 the place_client call
351 if (ob_state() == OB_STATE_RUNNING &&
353 (!(self->sized & USSize || self->positioned & USPosition) &&
354 client_normal(self) &&
356 /* don't shrink oldschool fullscreen windows to fit inside the
357 struts (fixes Acroread, which makes its fullscreen window
358 fit the screen but it is not USSize'd or USPosition'd) */
359 !(self->decorations == 0 && RECT_EQUAL(place, *monitor)))))
361 Rect *a = screen_area(self->desktop, SCREEN_AREA_ONE_MONITOR, &place);
363 Strut size = render_plugin->frame_get_size(self->frame);
364 /* get the size of the frame */
365 place.width += size.left + size.right;
366 place.height += size.top + size.bottom;
368 /* fit the window inside the area */
369 place.width = MIN(place.width, a->width);
370 place.height = MIN(place.height, a->height);
372 ob_debug("setting window size to %dx%d", place.width, place.height);
374 /* get the size of the client back */
375 place.width -= size.left + size.right;
376 place.height -= size.top + size.bottom;
381 ob_debug("placing window 0x%x at %d, %d with size %d x %d. "
382 "some restrictions may apply",
383 self->window, place.x, place.y, place.width, place.height);
385 ob_debug(" but session requested %d, %d %d x %d instead, "
387 self->session->x, self->session->y,
388 self->session->w, self->session->h);
390 /* do this after the window is placed, so the premax/prefullscreen numbers
393 this also places the window
395 client_apply_startup_state(self, place.x, place.y,
396 place.width, place.height);
401 ob_debug_type(OB_DEBUG_FOCUS, "Going to try activate new window? %s",
402 activate ? "yes" : "no");
404 gboolean raise = FALSE;
406 /* This is focus stealing prevention */
407 ob_debug_type(OB_DEBUG_FOCUS,
408 "Want to focus new window 0x%x at time %u "
409 "launched at %u (last user interaction time %u)",
410 self->window, map_time, launch_time,
411 event_last_user_time);
413 if (menu_frame_visible || render_plugin->moveresize_in_progress) {
416 ob_debug_type(OB_DEBUG_FOCUS,
417 "Not focusing the window because the user is inside "
418 "an Openbox menu or is move/resizing a window and "
419 "we don't want to interrupt them");
422 /* if it's on another desktop */
423 else if (!(self->desktop == screen_desktop ||
424 self->desktop == DESKTOP_ALL) &&
425 /* the timestamp is from before you changed desktops */
426 launch_time && screen_desktop_user_time &&
427 !event_time_after(launch_time, screen_desktop_user_time))
431 ob_debug_type(OB_DEBUG_FOCUS,
432 "Not focusing the window because its on another "
435 /* If something is focused, and it's not our relative... */
436 else if (focus_client && client_search_focus_tree_full(self) == NULL &&
437 client_search_focus_group_full(self) == NULL)
439 /* If the user is working in another window right now, then don't
441 if (event_last_user_time && launch_time &&
442 event_time_after(event_last_user_time, launch_time) &&
443 event_last_user_time != launch_time &&
444 event_time_after(event_last_user_time,
445 map_time - OB_EVENT_USER_TIME_DELAY))
448 ob_debug_type(OB_DEBUG_FOCUS,
449 "Not focusing the window because the user is "
450 "working in another window");
452 /* If its a transient (and its parents aren't focused) */
453 else if (client_has_parent(self)) {
455 ob_debug_type(OB_DEBUG_FOCUS,
456 "Not focusing the window because it is a "
457 "transient, and its relatives aren't focused");
459 /* Don't steal focus from globally active clients.
460 I stole this idea from KWin. It seems nice.
462 else if (!(focus_client->can_focus ||
463 focus_client->focus_notify))
466 ob_debug_type(OB_DEBUG_FOCUS,
467 "Not focusing the window because a globally "
468 "active client has focus");
470 /* Don't move focus if it's not going to go to this window
472 else if (client_focus_target(self) != self) {
475 ob_debug_type(OB_DEBUG_FOCUS,
476 "Not focusing the window because another window "
477 "would get the focus anyway");
479 else if (!(self->desktop == screen_desktop ||
480 self->desktop == DESKTOP_ALL))
484 ob_debug_type(OB_DEBUG_FOCUS,
485 "Not focusing the window because it is on "
486 "another desktop and no relatives are focused ");
491 ob_debug_type(OB_DEBUG_FOCUS,
492 "Focus stealing prevention activated for %s at "
493 "time %u (last user interactioon time %u)",
494 self->title, map_time, event_last_user_time);
495 /* if the client isn't focused, then hilite it so the user
497 client_hilite(self, TRUE);
498 /* we may want to raise it even tho we're not activating it */
499 if (raise && !client_restore_session_stacking(self))
500 stacking_raise(CLIENT_AS_WINDOW(self));
504 /* This may look rather odd. Well it's because new windows are added
505 to the stacking order non-intrusively. If we're not going to focus
506 the new window or hilite it, then we raise it to the top. This will
507 take affect for things that don't get focused like splash screens.
508 Also if you don't have focus_new enabled, then it's going to get
509 raised to the top. Legacy begets legacy I guess?
511 if (!client_restore_session_stacking(self))
512 stacking_raise(CLIENT_AS_WINDOW(self));
515 mouse_grab_for_client(self, TRUE);
517 /* this has to happen before we try focus the window, but we want it to
518 happen after the client's stacking has been determined or it looks bad
522 if (!config_focus_under_mouse)
523 ignore_start = event_start_ignore_all_enters();
527 if (!config_focus_under_mouse)
528 event_end_ignore_all_enters(ignore_start);
532 gboolean stacked = client_restore_session_stacking(self);
533 client_present(self, FALSE, !stacked, TRUE);
536 /* add to client list/map */
537 client_list = g_list_append(client_list, self);
538 window_add(&self->window, CLIENT_AS_WINDOW(self));
540 /* this has to happen after we're in the client_list */
541 if (STRUT_EXISTS(self->strut))
542 screen_update_areas();
544 /* update the list hints */
547 /* watch for when the application stops responding. only do this for
548 normal windows, i.e. windows which have titlebars and close buttons
549 and things like that.
550 we don't need to stop pinging on unmanage, because it will be handled
551 automatically by the destroy callback!
553 if (self->ping && client_normal(self))
554 ping_start(self, client_ping_event);
556 /* free the ObAppSettings shallow copy */
559 ob_debug("Managed window 0x%lx plate 0x%x (%s)",
560 window, render_plugin->frame_get_window(self->frame), self->class);
564 ObClient *client_fake_manage(Window window)
567 ObAppSettings *settings;
569 ob_debug("Pretend-managing window: %lx", window);
571 /* do this minimal stuff to figure out the client's decorations */
573 self = g_new0(ObClient, 1);
574 self->window = window;
576 client_get_all(self, FALSE);
577 /* per-app settings override stuff, and return the settings for other
578 uses too. this returns a shallow copy that needs to be freed */
579 settings = client_get_settings_state(self);
581 client_setup_decor_and_functions(self, FALSE);
583 /* create the decoration frame for the client window and adjust its size */
584 self->frame = render_plugin->frame_new(self);
585 render_plugin->frame_set_decorations (self->frame, self->decorations);
586 render_plugin->frame_update_layout (self->frame, FALSE, FALSE);
588 ob_debug("gave extents left %d right %d top %d bottom %d",
589 render_plugin->frame_get_size(self->frame).left, render_plugin->frame_get_size(self->frame).right,
590 render_plugin->frame_get_size(self->frame).top, render_plugin->frame_get_size(self->frame).bottom);
592 /* free the ObAppSettings shallow copy */
598 void client_unmanage_all(void)
600 while (client_list != NULL)
601 client_unmanage(client_list->data);
604 void client_unmanage(ObClient *self)
610 ob_debug("Unmanaging window: 0x%x plate 0x%x (%s) (%s)",
611 self->window, render_plugin->frame_get_window(self->frame),
612 self->class, self->title ? self->title : "");
614 g_assert(self != NULL);
616 /* we dont want events no more. do this before hiding the frame so we
617 don't generate more events */
618 XSelectInput(obt_display, self->window, NoEventMask);
620 /* ignore enter events from the unmap so it doesnt mess with the focus */
621 if (!config_focus_under_mouse)
622 ignore_start = event_start_ignore_all_enters();
624 self->ignore_unmaps += render_plugin->frame_hide(self->frame);
625 /* flush to send the hide to the server quickly */
628 if (!config_focus_under_mouse)
629 event_end_ignore_all_enters(ignore_start);
631 mouse_grab_for_client(self, FALSE);
633 /* remove the window from our save set, unless we are managing an internal
636 XChangeSaveSet(obt_display, self->window, SetModeDelete);
638 /* update the focus lists */
639 focus_order_remove(self);
640 if (client_focused(self)) {
641 /* don't leave an invalid focus_client */
645 /* if we're prompting to kill the client, close that */
646 prompt_unref(self->kill_prompt);
647 self->kill_prompt = NULL;
649 client_list = g_list_remove(client_list, self);
650 stacking_remove(self);
651 window_remove(self->window);
653 /* once the client is out of the list, update the struts to remove its
655 if (STRUT_EXISTS(self->strut))
656 screen_update_areas();
658 client_call_notifies(self, client_destroy_notifies);
660 /* tell our parent(s) that we're gone */
661 for (it = self->parents; it; it = g_slist_next(it))
662 ((ObClient*)it->data)->transients =
663 g_slist_remove(((ObClient*)it->data)->transients,self);
665 /* tell our transients that we're gone */
666 for (it = self->transients; it; it = g_slist_next(it)) {
667 ((ObClient*)it->data)->parents =
668 g_slist_remove(((ObClient*)it->data)->parents, self);
669 /* we could be keeping our children in a higher layer */
670 client_calc_layer(it->data);
673 /* remove from its group */
675 group_remove(self->group, self);
679 /* restore the window's original geometry so it is not lost */
685 if (self->fullscreen)
686 a = self->pre_fullscreen_area;
687 else if (self->max_horz || self->max_vert) {
688 if (self->max_horz) {
689 a.x = self->pre_max_area.x;
690 a.width = self->pre_max_area.width;
692 if (self->max_vert) {
693 a.y = self->pre_max_area.y;
694 a.height = self->pre_max_area.height;
698 self->fullscreen = self->max_horz = self->max_vert = FALSE;
699 render_plugin->frame_trigger(self, OB_TRIGGER_UNMAX_VERT);
700 render_plugin->frame_trigger(self, OB_TRIGGER_UNMAX_HORZ);
701 /* let it be moved and resized no matter what */
702 self->functions = OB_CLIENT_FUNC_MOVE | OB_CLIENT_FUNC_RESIZE;
703 self->decorations = 0; /* unmanaged windows have no decor */
705 /* give the client its border back */
706 XSetWindowBorderWidth(obt_display, self->window, self->border_width);
708 client_move_resize(self, a.x, a.y, a.width, a.height);
711 /* reparent the window out of the frame, and free the frame */
712 render_plugin->frame_ungrab(self->frame, window_map);
713 render_plugin->frame_free(self->frame);
716 if (ob_state() != OB_STATE_EXITING) {
717 /* these values should not be persisted across a window
719 OBT_PROP_ERASE(self->window, NET_WM_DESKTOP);
720 OBT_PROP_ERASE(self->window, NET_WM_STATE);
721 OBT_PROP_ERASE(self->window, WM_STATE);
723 /* if we're left in an unmapped state, the client wont be mapped.
724 this is bad, since we will no longer be managing the window on
726 XMapWindow(obt_display, self->window);
729 /* these should not be left on the window ever. other window managers
730 don't necessarily use them and it will mess them up (like compiz) */
731 OBT_PROP_ERASE(self->window, NET_WM_VISIBLE_NAME);
732 OBT_PROP_ERASE(self->window, NET_WM_VISIBLE_ICON_NAME);
734 /* update the list hints */
737 ob_debug("Unmanaged window 0x%lx", self->window);
739 /* free all data allocated in the client struct */
740 g_slist_free(self->transients);
741 for (j = 0; j < self->nicons; ++j)
742 g_free(self->icons[j].data);
743 if (self->nicons > 0)
745 g_free(self->startup_id);
746 g_free(self->wm_command);
748 g_free(self->icon_title);
749 g_free(self->original_title);
753 g_free(self->client_machine);
754 g_free(self->sm_client_id);
758 void client_fake_unmanage(ObClient *self)
760 /* this is all that got allocated to get the decorations */
762 render_plugin->frame_free(self->frame);
766 /*! Returns a new structure containing the per-app settings for this client.
767 The returned structure needs to be freed with g_free. */
768 static ObAppSettings *client_get_settings_state(ObClient *self)
770 ObAppSettings *settings;
773 settings = config_create_app_settings();
775 for (it = config_per_app_settings; it; it = g_slist_next(it)) {
776 ObAppSettings *app = it->data;
777 gboolean match = TRUE;
779 g_assert(app->name != NULL || app->class != NULL);
781 /* we know that either name or class is not NULL so it will have to
782 match to use the rule */
784 !g_pattern_match(app->name, strlen(self->name), self->name, NULL))
786 else if (app->class &&
787 !g_pattern_match(app->class,
788 strlen(self->class), self->class, NULL))
790 else if (app->role &&
791 !g_pattern_match(app->role,
792 strlen(self->role), self->role, NULL))
796 ob_debug("Window matching: %s", app->name);
798 /* copy the settings to our struct, overriding the existing
799 settings if they are not defaults */
800 config_app_settings_copy_non_defaults(app, settings);
804 if (settings->shade != -1)
805 self->shaded = !!settings->shade;
806 if (settings->decor != -1)
807 self->undecorated = !settings->decor;
808 if (settings->iconic != -1)
809 self->iconic = !!settings->iconic;
810 if (settings->skip_pager != -1)
811 self->skip_pager = !!settings->skip_pager;
812 if (settings->skip_taskbar != -1)
813 self->skip_taskbar = !!settings->skip_taskbar;
815 if (settings->max_vert != -1)
816 self->max_vert = !!settings->max_vert;
817 if (settings->max_horz != -1)
818 self->max_horz = !!settings->max_horz;
820 if (settings->fullscreen != -1)
821 self->fullscreen = !!settings->fullscreen;
823 if (settings->desktop) {
824 if (settings->desktop == DESKTOP_ALL)
825 self->desktop = settings->desktop;
826 else if (settings->desktop > 0 &&
827 settings->desktop <= screen_num_desktops)
828 self->desktop = settings->desktop - 1;
831 if (settings->layer == -1) {
835 else if (settings->layer == 0) {
839 else if (settings->layer == 1) {
846 static void client_restore_session_state(ObClient *self)
850 ob_debug_type(OB_DEBUG_SM,
851 "Restore session for client %s", self->title);
853 if (!(it = session_state_find(self))) {
854 ob_debug_type(OB_DEBUG_SM,
855 "Session data not found for client %s", self->title);
859 self->session = it->data;
861 ob_debug_type(OB_DEBUG_SM, "Session data loaded for client %s",
864 RECT_SET_POINT(self->area, self->session->x, self->session->y);
865 self->positioned = USPosition;
866 self->sized = USSize;
867 if (self->session->w > 0)
868 self->area.width = self->session->w;
869 if (self->session->h > 0)
870 self->area.height = self->session->h;
871 XResizeWindow(obt_display, self->window,
872 self->area.width, self->area.height);
874 self->desktop = (self->session->desktop == DESKTOP_ALL ?
875 self->session->desktop :
876 MIN(screen_num_desktops - 1, self->session->desktop));
877 OBT_PROP_SET32(self->window, NET_WM_DESKTOP, CARDINAL, self->desktop);
879 self->shaded = self->session->shaded;
880 self->iconic = self->session->iconic;
881 self->skip_pager = self->session->skip_pager;
882 self->skip_taskbar = self->session->skip_taskbar;
883 self->fullscreen = self->session->fullscreen;
884 self->above = self->session->above;
885 self->below = self->session->below;
886 self->max_horz = self->session->max_horz;
887 self->max_vert = self->session->max_vert;
888 self->undecorated = self->session->undecorated;
890 if (self->session->max_horz) {
891 render_plugin->frame_trigger(self->frame, OB_TRIGGER_MAX_HORZ);
894 render_plugin->frame_trigger(self->frame, OB_TRIGGER_UNMAX_HORZ);
897 if (self->session->max_vert) {
898 render_plugin->frame_trigger(self->frame, OB_TRIGGER_MAX_VERT);
901 render_plugin->frame_trigger(self->frame, OB_TRIGGER_UNMAX_VERT);
905 static gboolean client_restore_session_stacking(ObClient *self)
909 if (!self->session) return FALSE;
911 mypos = g_list_find(session_saved_state, self->session);
912 if (!mypos) return FALSE;
914 /* start above me and look for the first client */
915 for (it = g_list_previous(mypos); it; it = g_list_previous(it)) {
918 for (cit = client_list; cit; cit = g_list_next(cit)) {
919 ObClient *c = cit->data;
920 /* found a client that was in the session, so go below it */
921 if (c->session == it->data) {
922 stacking_below(CLIENT_AS_WINDOW(self),
923 CLIENT_AS_WINDOW(cit->data));
931 void client_move_onscreen(ObClient *self, gboolean rude)
933 gint x = self->area.x;
934 gint y = self->area.y;
935 if (client_find_onscreen(self, &x, &y,
937 self->area.height, rude)) {
938 client_move(self, x, y);
942 gboolean client_find_onscreen(ObClient *self, gint *x, gint *y, gint w, gint h,
945 gint ox = *x, oy = *y;
946 gboolean rudel = rude, ruder = rude, rudet = rude, rudeb = rude;
952 RECT_SET(desired, *x, *y, w, h);
953 frame_rect_to_frame(self, &desired);
955 /* get where the frame would be */
956 frame_client_gravity(self, x, y);
958 Strut size = render_plugin->frame_get_size(self->frame);
960 /* get the requested size of the window with decorations */
961 fw = size.left + w + size.right;
962 fh = size.top + h + size.bottom;
964 /* If rudeness wasn't requested, then still be rude in a given direction
965 if the client is not moving, only resizing in that direction */
967 Point oldtl, oldtr, oldbl, oldbr;
968 Point newtl, newtr, newbl, newbr;
969 gboolean stationary_l, stationary_r, stationary_t, stationary_b;
971 Rect area = render_plugin->frame_get_window_area(self->frame);
972 POINT_SET(oldtl, area.x, area.y);
973 POINT_SET(oldbr, area.x + area.width - 1,
974 area.y + area.height - 1);
975 POINT_SET(oldtr, oldbr.x, oldtl.y);
976 POINT_SET(oldbl, oldtl.x, oldbr.y);
978 POINT_SET(newtl, *x, *y);
979 POINT_SET(newbr, *x + fw - 1, *y + fh - 1);
980 POINT_SET(newtr, newbr.x, newtl.y);
981 POINT_SET(newbl, newtl.x, newbr.y);
983 /* is it moving or just resizing from some corner? */
984 stationary_l = oldtl.x == newtl.x;
985 stationary_r = oldtr.x == newtr.x;
986 stationary_t = oldtl.y == newtl.y;
987 stationary_b = oldbl.y == newbl.y;
989 /* if left edge is growing and didnt move right edge */
990 if (stationary_r && newtl.x < oldtl.x)
992 /* if right edge is growing and didnt move left edge */
993 if (stationary_l && newtr.x > oldtr.x)
995 /* if top edge is growing and didnt move bottom edge */
996 if (stationary_b && newtl.y < oldtl.y)
998 /* if bottom edge is growing and didnt move top edge */
999 if (stationary_t && newbl.y > oldbl.y)
1003 /* we iterate through every monitor that the window is at least partially
1004 on, to make sure it is obeying the rules on them all
1006 if the window does not appear on any monitors, then use the first one
1009 for (i = 0; i < screen_num_monitors; ++i) {
1012 if (!screen_physical_area_monitor_contains(i, &desired)) {
1013 if (i < screen_num_monitors - 1 || found_mon)
1016 /* the window is not inside any monitor! so just use the first
1018 a = screen_area(self->desktop, 0, NULL);
1021 a = screen_area(self->desktop, SCREEN_AREA_ONE_MONITOR, &desired);
1024 /* This makes sure windows aren't entirely outside of the screen so you
1025 can't see them at all.
1026 It makes sure 10% of the window is on the screen at least. At don't
1027 let it move itself off the top of the screen, which would hide the
1028 titlebar on you. (The user can still do this if they want too, it's
1029 only limiting the application.
1031 if (client_normal(self)) {
1032 if (!self->strut.right && *x + fw/10 >= a->x + a->width - 1)
1033 *x = a->x + a->width - fw/10;
1034 if (!self->strut.bottom && *y + fh/10 >= a->y + a->height - 1)
1035 *y = a->y + a->height - fh/10;
1036 if (!self->strut.left && *x + fw*9/10 - 1 < a->x)
1037 *x = a->x - fw*9/10;
1038 if (!self->strut.top && *y + fh*9/10 - 1 < a->y)
1039 *y = a->y - fh*9/10;
1042 /* This here doesn't let windows even a pixel outside the
1043 struts/screen. When called from client_manage, programs placing
1044 themselves are forced completely onscreen, while things like
1045 xterm -geometry resolution-width/2 will work fine. Trying to
1046 place it completely offscreen will be handled in the above code.
1047 Sorry for this confused comment, i am tired. */
1048 if (rudel && !self->strut.left && *x < a->x) *x = a->x;
1049 if (ruder && !self->strut.right && *x + fw > a->x + a->width)
1050 *x = a->x + MAX(0, a->width - fw);
1052 if (rudet && !self->strut.top && *y < a->y) *y = a->y;
1053 if (rudeb && !self->strut.bottom && *y + fh > a->y + a->height)
1054 *y = a->y + MAX(0, a->height - fh);
1059 /* get where the client should be */
1060 frame_frame_gravity(self, x, y);
1062 return ox != *x || oy != *y;
1065 static void client_get_all(ObClient *self, gboolean real)
1067 /* this is needed for the frame to set itself up */
1068 client_get_area(self);
1070 /* these things can change the decor and functions of the window */
1072 client_get_mwm_hints(self);
1073 /* this can change the mwmhints for special cases */
1074 client_get_type_and_transientness(self);
1075 client_get_state(self);
1076 client_update_normal_hints(self);
1078 /* get the session related properties, these can change decorations
1079 from per-app settings */
1080 client_get_session_ids(self);
1082 /* now we got everything that can affect the decorations */
1086 /* get this early so we have it for debugging */
1087 client_update_title(self);
1089 client_update_protocols(self);
1091 client_update_wmhints(self);
1092 /* this may have already been called from client_update_wmhints */
1093 if (!self->parents && !self->transient_for_group)
1094 client_update_transient_for(self);
1096 client_get_startup_id(self);
1097 client_get_desktop(self);/* uses transient data/group/startup id if a
1098 desktop is not specified */
1099 client_get_shaped(self);
1102 /* a couple type-based defaults for new windows */
1104 /* this makes sure that these windows appear on all desktops */
1105 if (self->type == OB_CLIENT_TYPE_DESKTOP)
1106 self->desktop = DESKTOP_ALL;
1110 client_update_sync_request_counter(self);
1113 client_get_colormap(self);
1114 client_update_strut(self);
1115 client_update_icons(self);
1116 client_update_icon_geometry(self);
1119 static void client_get_startup_id(ObClient *self)
1121 if (!(OBT_PROP_GETS(self->window, NET_STARTUP_ID, utf8,
1122 &self->startup_id)))
1124 OBT_PROP_GETS(self->group->leader,
1125 NET_STARTUP_ID, utf8, &self->startup_id);
1128 static void client_get_area(ObClient *self)
1130 XWindowAttributes wattrib;
1133 ret = XGetWindowAttributes(obt_display, self->window, &wattrib);
1134 g_assert(ret != BadWindow);
1136 RECT_SET(self->area, wattrib.x, wattrib.y, wattrib.width, wattrib.height);
1137 POINT_SET(self->root_pos, wattrib.x, wattrib.y);
1138 self->border_width = wattrib.border_width;
1140 ob_debug("client area: %d %d %d %d bw %d", wattrib.x, wattrib.y,
1141 wattrib.width, wattrib.height, wattrib.border_width);
1144 static void client_get_desktop(ObClient *self)
1146 guint32 d = screen_num_desktops; /* an always-invalid value */
1148 if (OBT_PROP_GET32(self->window, NET_WM_DESKTOP, CARDINAL, &d)) {
1149 if (d >= screen_num_desktops && d != DESKTOP_ALL)
1150 self->desktop = screen_num_desktops - 1;
1153 ob_debug("client requested desktop 0x%x", self->desktop);
1156 gboolean first = TRUE;
1157 guint all = screen_num_desktops; /* not a valid value */
1159 /* if they are all on one desktop, then open it on the
1161 for (it = self->parents; it; it = g_slist_next(it)) {
1162 ObClient *c = it->data;
1164 if (c->desktop == DESKTOP_ALL) continue;
1170 else if (all != c->desktop)
1171 all = screen_num_desktops; /* make it invalid */
1173 if (all != screen_num_desktops) {
1174 self->desktop = all;
1176 ob_debug("client desktop set from parents: 0x%x",
1179 /* try get from the startup-notification protocol */
1180 else if (sn_get_desktop(self->startup_id, &self->desktop)) {
1181 if (self->desktop >= screen_num_desktops &&
1182 self->desktop != DESKTOP_ALL)
1183 self->desktop = screen_num_desktops - 1;
1184 ob_debug("client desktop set from startup-notification: 0x%x",
1187 /* defaults to the current desktop */
1189 self->desktop = screen_desktop;
1190 ob_debug("client desktop set to the current desktop: %d",
1196 static void client_get_state(ObClient *self)
1201 if (OBT_PROP_GETA32(self->window, NET_WM_STATE, ATOM, &state, &num)) {
1203 for (i = 0; i < num; ++i) {
1204 if (state[i] == OBT_PROP_ATOM(NET_WM_STATE_MODAL))
1206 else if (state[i] == OBT_PROP_ATOM(NET_WM_STATE_SHADED))
1207 self->shaded = TRUE;
1208 else if (state[i] == OBT_PROP_ATOM(NET_WM_STATE_HIDDEN))
1209 self->iconic = TRUE;
1210 else if (state[i] == OBT_PROP_ATOM(NET_WM_STATE_SKIP_TASKBAR))
1211 self->skip_taskbar = TRUE;
1212 else if (state[i] == OBT_PROP_ATOM(NET_WM_STATE_SKIP_PAGER))
1213 self->skip_pager = TRUE;
1214 else if (state[i] == OBT_PROP_ATOM(NET_WM_STATE_FULLSCREEN))
1215 self->fullscreen = TRUE;
1216 else if (state[i] == OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_VERT)) {
1217 self->max_vert = TRUE;
1218 render_plugin->frame_trigger(self->frame, OB_TRIGGER_MAX_VERT);
1220 else if (state[i] == OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_HORZ)) {
1221 self->max_horz = TRUE;
1222 render_plugin->frame_trigger(self->frame, OB_TRIGGER_MAX_HORZ);
1224 else if (state[i] == OBT_PROP_ATOM(NET_WM_STATE_ABOVE))
1226 else if (state[i] == OBT_PROP_ATOM(NET_WM_STATE_BELOW))
1228 else if (state[i] == OBT_PROP_ATOM(NET_WM_STATE_DEMANDS_ATTENTION))
1229 self->demands_attention = TRUE;
1230 else if (state[i] == OBT_PROP_ATOM(OB_WM_STATE_UNDECORATED))
1231 self->undecorated = TRUE;
1238 static void client_get_shaped(ObClient *self)
1240 self->shaped = FALSE;
1242 if (obt_display_extension_shape) {
1247 XShapeSelectInput(obt_display, self->window, ShapeNotifyMask);
1249 XShapeQueryExtents(obt_display, self->window, &s, &foo,
1250 &foo, &ufoo, &ufoo, &foo, &foo, &foo, &ufoo,
1252 self->shaped = (s != 0);
1257 void client_update_transient_for(ObClient *self)
1260 ObClient *target = NULL;
1261 gboolean trangroup = FALSE;
1263 if (XGetTransientForHint(obt_display, self->window, &t)) {
1264 if (t != self->window) { /* cant be transient to itself! */
1265 ObWindow *tw = window_find(t);
1266 /* if this happens then we need to check for it*/
1267 g_assert(tw != CLIENT_AS_WINDOW(self));
1268 if (tw && WINDOW_IS_CLIENT(tw)) {
1269 /* watch out for windows with a parent that is something
1270 different, like a dockapp for example */
1271 target = WINDOW_AS_CLIENT(tw);
1275 /* Setting the transient_for to Root is actually illegal, however
1276 applications from time have done this to specify transient for
1278 if (!target && self->group && t == obt_root(ob_screen))
1280 } else if (self->group && self->transient)
1283 client_update_transient_tree(self, self->group, self->group,
1284 self->transient_for_group, trangroup,
1285 client_direct_parent(self), target);
1286 self->transient_for_group = trangroup;
1290 static void client_update_transient_tree(ObClient *self,
1291 ObGroup *oldgroup, ObGroup *newgroup,
1292 gboolean oldgtran, gboolean newgtran,
1293 ObClient* oldparent,
1294 ObClient *newparent)
1299 g_assert(!oldgtran || oldgroup);
1300 g_assert(!newgtran || newgroup);
1301 g_assert((!oldgtran && !oldparent) ||
1302 (oldgtran && !oldparent) ||
1303 (!oldgtran && oldparent));
1304 g_assert((!newgtran && !newparent) ||
1305 (newgtran && !newparent) ||
1306 (!newgtran && newparent));
1309 Group transient windows are not allowed to have other group
1310 transient windows as their children.
1314 /* No change has occured */
1315 if (oldgroup == newgroup &&
1316 oldgtran == newgtran &&
1317 oldparent == newparent) return;
1319 /** Remove the client from the transient tree **/
1321 for (it = self->transients; it; it = next) {
1322 next = g_slist_next(it);
1324 self->transients = g_slist_delete_link(self->transients, it);
1325 c->parents = g_slist_remove(c->parents, self);
1327 for (it = self->parents; it; it = next) {
1328 next = g_slist_next(it);
1330 self->parents = g_slist_delete_link(self->parents, it);
1331 c->transients = g_slist_remove(c->transients, self);
1334 /** Re-add the client to the transient tree **/
1336 /* If we're transient for a group then we need to add ourselves to all our
1339 for (it = newgroup->members; it; it = g_slist_next(it)) {
1342 !client_search_top_direct_parent(c)->transient_for_group &&
1345 c->transients = g_slist_prepend(c->transients, self);
1346 self->parents = g_slist_prepend(self->parents, c);
1351 /* If we are now transient for a single window we need to add ourselves to
1354 WARNING: Cyclical transient ness is possible if two windows are
1355 transient for eachother.
1357 else if (newparent &&
1358 /* don't make ourself its child if it is already our child */
1359 !client_is_direct_child(self, newparent) &&
1360 client_normal(newparent))
1362 newparent->transients = g_slist_prepend(newparent->transients, self);
1363 self->parents = g_slist_prepend(self->parents, newparent);
1366 /* Add any group transient windows to our children. But if we're transient
1367 for the group, then other group transients are not our children.
1369 WARNING: Cyclical transient-ness is possible. For e.g. if:
1370 A is transient for the group
1371 B is transient for A
1372 C is transient for B
1373 A can't be transient for C or we have a cycle
1375 if (!newgtran && newgroup &&
1377 !client_search_top_direct_parent(newparent)->transient_for_group) &&
1378 client_normal(self))
1380 for (it = newgroup->members; it; it = g_slist_next(it)) {
1382 if (c != self && c->transient_for_group &&
1383 /* Don't make it our child if it is already our parent */
1384 !client_is_direct_child(c, self))
1386 self->transients = g_slist_prepend(self->transients, c);
1387 c->parents = g_slist_prepend(c->parents, self);
1392 /** If we change our group transient-ness, our children change their
1393 effect group transient-ness, which affects how they relate to other
1396 for (it = self->transients; it; it = g_slist_next(it)) {
1398 if (!c->transient_for_group)
1399 client_update_transient_tree(c, c->group, c->group,
1400 c->transient_for_group,
1401 c->transient_for_group,
1402 client_direct_parent(c),
1403 client_direct_parent(c));
1407 static void client_get_mwm_hints(ObClient *self)
1412 self->mwmhints.flags = 0; /* default to none */
1414 if (OBT_PROP_GETA32(self->window, MOTIF_WM_HINTS, MOTIF_WM_HINTS,
1416 if (num >= OB_MWM_ELEMENTS) {
1417 self->mwmhints.flags = hints[0];
1418 self->mwmhints.functions = hints[1];
1419 self->mwmhints.decorations = hints[2];
1425 void client_get_type_and_transientness(ObClient *self)
1432 self->transient = FALSE;
1434 if (OBT_PROP_GETA32(self->window, NET_WM_WINDOW_TYPE, ATOM, &val, &num)) {
1435 /* use the first value that we know about in the array */
1436 for (i = 0; i < num; ++i) {
1437 if (val[i] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_DESKTOP))
1438 self->type = OB_CLIENT_TYPE_DESKTOP;
1439 else if (val[i] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_DOCK))
1440 self->type = OB_CLIENT_TYPE_DOCK;
1441 else if (val[i] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_TOOLBAR))
1442 self->type = OB_CLIENT_TYPE_TOOLBAR;
1443 else if (val[i] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_MENU))
1444 self->type = OB_CLIENT_TYPE_MENU;
1445 else if (val[i] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_UTILITY))
1446 self->type = OB_CLIENT_TYPE_UTILITY;
1447 else if (val[i] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_SPLASH))
1448 self->type = OB_CLIENT_TYPE_SPLASH;
1449 else if (val[i] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_DIALOG))
1450 self->type = OB_CLIENT_TYPE_DIALOG;
1451 else if (val[i] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_NORMAL))
1452 self->type = OB_CLIENT_TYPE_NORMAL;
1453 else if (val[i] == OBT_PROP_ATOM(KDE_NET_WM_WINDOW_TYPE_OVERRIDE))
1455 /* prevent this window from getting any decor or
1457 self->mwmhints.flags &= (OB_MWM_FLAG_FUNCTIONS |
1458 OB_MWM_FLAG_DECORATIONS);
1459 self->mwmhints.decorations = 0;
1460 self->mwmhints.functions = 0;
1462 if (self->type != (ObClientType) -1)
1463 break; /* grab the first legit type */
1468 if (XGetTransientForHint(obt_display, self->window, &t))
1469 self->transient = TRUE;
1471 if (self->type == (ObClientType) -1) {
1472 /*the window type hint was not set, which means we either classify
1473 ourself as a normal window or a dialog, depending on if we are a
1475 if (self->transient)
1476 self->type = OB_CLIENT_TYPE_DIALOG;
1478 self->type = OB_CLIENT_TYPE_NORMAL;
1481 /* then, based on our type, we can update our transientness.. */
1482 if (self->type == OB_CLIENT_TYPE_DIALOG ||
1483 self->type == OB_CLIENT_TYPE_TOOLBAR ||
1484 self->type == OB_CLIENT_TYPE_MENU ||
1485 self->type == OB_CLIENT_TYPE_UTILITY)
1487 self->transient = TRUE;
1491 void client_update_protocols(ObClient *self)
1496 self->focus_notify = FALSE;
1497 self->delete_window = FALSE;
1499 if (OBT_PROP_GETA32(self->window, WM_PROTOCOLS, ATOM, &proto, &num_ret)) {
1500 for (i = 0; i < num_ret; ++i) {
1501 if (proto[i] == OBT_PROP_ATOM(WM_DELETE_WINDOW))
1502 /* this means we can request the window to close */
1503 self->delete_window = TRUE;
1504 else if (proto[i] == OBT_PROP_ATOM(WM_TAKE_FOCUS))
1505 /* if this protocol is requested, then the window will be
1506 notified whenever we want it to receive focus */
1507 self->focus_notify = TRUE;
1508 else if (proto[i] == OBT_PROP_ATOM(NET_WM_PING))
1509 /* if this protocol is requested, then the window will allow
1510 pings to determine if it is still alive */
1513 else if (proto[i] == OBT_PROP_ATOM(NET_WM_SYNC_REQUEST))
1514 /* if this protocol is requested, then resizing the
1515 window will be synchronized between the frame and the
1517 self->sync_request = TRUE;
1525 void client_update_sync_request_counter(ObClient *self)
1529 if (OBT_PROP_GET32(self->window, NET_WM_SYNC_REQUEST_COUNTER, CARDINAL,&i))
1531 self->sync_counter = i;
1533 self->sync_counter = None;
1537 static void client_get_colormap(ObClient *self)
1539 XWindowAttributes wa;
1541 if (XGetWindowAttributes(obt_display, self->window, &wa))
1542 client_update_colormap(self, wa.colormap);
1545 void client_update_colormap(ObClient *self, Colormap colormap)
1547 if (colormap == self->colormap) return;
1549 ob_debug("Setting client %s colormap: 0x%x", self->title, colormap);
1551 if (client_focused(self)) {
1552 screen_install_colormap(self, FALSE); /* uninstall old one */
1553 self->colormap = colormap;
1554 screen_install_colormap(self, FALSE); /* install new one */
1556 self->colormap = colormap;
1559 void client_update_normal_hints(ObClient *self)
1565 self->min_ratio = 0.0f;
1566 self->max_ratio = 0.0f;
1567 SIZE_SET(self->size_inc, 1, 1);
1568 SIZE_SET(self->base_size, 0, 0);
1569 SIZE_SET(self->min_size, 0, 0);
1570 SIZE_SET(self->max_size, G_MAXINT, G_MAXINT);
1572 /* get the hints from the window */
1573 if (XGetWMNormalHints(obt_display, self->window, &size, &ret)) {
1574 /* normal windows can't request placement! har har
1575 if (!client_normal(self))
1577 self->positioned = (size.flags & (PPosition|USPosition));
1578 self->sized = (size.flags & (PSize|USSize));
1580 if (size.flags & PWinGravity)
1581 self->gravity = size.win_gravity;
1583 if (size.flags & PAspect) {
1584 if (size.min_aspect.y)
1586 (gfloat) size.min_aspect.x / size.min_aspect.y;
1587 if (size.max_aspect.y)
1589 (gfloat) size.max_aspect.x / size.max_aspect.y;
1592 if (size.flags & PMinSize)
1593 SIZE_SET(self->min_size, size.min_width, size.min_height);
1595 if (size.flags & PMaxSize)
1596 SIZE_SET(self->max_size, size.max_width, size.max_height);
1598 if (size.flags & PBaseSize)
1599 SIZE_SET(self->base_size, size.base_width, size.base_height);
1601 if (size.flags & PResizeInc && size.width_inc && size.height_inc)
1602 SIZE_SET(self->size_inc, size.width_inc, size.height_inc);
1604 ob_debug("Normal hints: min size (%d %d) max size (%d %d)",
1605 self->min_size.width, self->min_size.height,
1606 self->max_size.width, self->max_size.height);
1607 ob_debug("size inc (%d %d) base size (%d %d)",
1608 self->size_inc.width, self->size_inc.height,
1609 self->base_size.width, self->base_size.height);
1612 ob_debug("Normal hints: not set");
1615 void client_setup_decor_and_functions(ObClient *self, gboolean reconfig)
1617 /* start with everything (cept fullscreen) */
1619 (OB_FRAME_DECOR_TITLEBAR |
1620 OB_FRAME_DECOR_HANDLE |
1621 OB_FRAME_DECOR_GRIPS |
1622 OB_FRAME_DECOR_BORDER |
1623 OB_FRAME_DECOR_ICON |
1624 OB_FRAME_DECOR_ALLDESKTOPS |
1625 OB_FRAME_DECOR_ICONIFY |
1626 OB_FRAME_DECOR_MAXIMIZE |
1627 OB_FRAME_DECOR_SHADE |
1628 OB_FRAME_DECOR_CLOSE);
1630 (OB_CLIENT_FUNC_RESIZE |
1631 OB_CLIENT_FUNC_MOVE |
1632 OB_CLIENT_FUNC_ICONIFY |
1633 OB_CLIENT_FUNC_MAXIMIZE |
1634 OB_CLIENT_FUNC_SHADE |
1635 OB_CLIENT_FUNC_CLOSE |
1636 OB_CLIENT_FUNC_BELOW |
1637 OB_CLIENT_FUNC_ABOVE |
1638 OB_CLIENT_FUNC_UNDECORATE);
1640 if (!(self->min_size.width < self->max_size.width ||
1641 self->min_size.height < self->max_size.height))
1642 self->functions &= ~OB_CLIENT_FUNC_RESIZE;
1644 switch (self->type) {
1645 case OB_CLIENT_TYPE_NORMAL:
1646 /* normal windows retain all of the possible decorations and
1647 functionality, and can be fullscreen */
1648 self->functions |= OB_CLIENT_FUNC_FULLSCREEN;
1651 case OB_CLIENT_TYPE_DIALOG:
1652 /* sometimes apps make dialog windows fullscreen for some reason (for
1653 e.g. kpdf does this..) */
1654 self->functions |= OB_CLIENT_FUNC_FULLSCREEN;
1657 case OB_CLIENT_TYPE_UTILITY:
1658 /* these windows don't have anything added or removed by default */
1661 case OB_CLIENT_TYPE_MENU:
1662 case OB_CLIENT_TYPE_TOOLBAR:
1663 /* these windows can't iconify or maximize */
1664 self->decorations &= ~(OB_FRAME_DECOR_ICONIFY |
1665 OB_FRAME_DECOR_MAXIMIZE);
1666 self->functions &= ~(OB_CLIENT_FUNC_ICONIFY |
1667 OB_CLIENT_FUNC_MAXIMIZE);
1670 case OB_CLIENT_TYPE_SPLASH:
1671 /* these don't get get any decorations, and the only thing you can
1672 do with them is move them */
1673 self->decorations = 0;
1674 self->functions = OB_CLIENT_FUNC_MOVE;
1677 case OB_CLIENT_TYPE_DESKTOP:
1678 /* these windows are not manipulated by the window manager */
1679 self->decorations = 0;
1680 self->functions = 0;
1683 case OB_CLIENT_TYPE_DOCK:
1684 /* these windows are not manipulated by the window manager, but they
1685 can set below layer which has a special meaning */
1686 self->decorations = 0;
1687 self->functions = OB_CLIENT_FUNC_BELOW;
1691 /* Mwm Hints are applied subtractively to what has already been chosen for
1692 decor and functionality */
1693 if (self->mwmhints.flags & OB_MWM_FLAG_DECORATIONS) {
1694 if (! (self->mwmhints.decorations & OB_MWM_DECOR_ALL)) {
1695 if (! ((self->mwmhints.decorations & OB_MWM_DECOR_HANDLE) ||
1696 (self->mwmhints.decorations & OB_MWM_DECOR_TITLE)))
1698 /* if the mwm hints request no handle or title, then all
1699 decorations are disabled, but keep the border if that's
1701 if (self->mwmhints.decorations & OB_MWM_DECOR_BORDER)
1702 self->decorations = OB_FRAME_DECOR_BORDER;
1704 self->decorations = 0;
1709 if (self->mwmhints.flags & OB_MWM_FLAG_FUNCTIONS) {
1710 if (! (self->mwmhints.functions & OB_MWM_FUNC_ALL)) {
1711 if (! (self->mwmhints.functions & OB_MWM_FUNC_RESIZE))
1712 self->functions &= ~OB_CLIENT_FUNC_RESIZE;
1713 if (! (self->mwmhints.functions & OB_MWM_FUNC_MOVE))
1714 self->functions &= ~OB_CLIENT_FUNC_MOVE;
1715 /* dont let mwm hints kill any buttons
1716 if (! (self->mwmhints.functions & OB_MWM_FUNC_ICONIFY))
1717 self->functions &= ~OB_CLIENT_FUNC_ICONIFY;
1718 if (! (self->mwmhints.functions & OB_MWM_FUNC_MAXIMIZE))
1719 self->functions &= ~OB_CLIENT_FUNC_MAXIMIZE;
1721 /* dont let mwm hints kill the close button
1722 if (! (self->mwmhints.functions & MwmFunc_Close))
1723 self->functions &= ~OB_CLIENT_FUNC_CLOSE; */
1727 if (!(self->functions & OB_CLIENT_FUNC_SHADE))
1728 self->decorations &= ~OB_FRAME_DECOR_SHADE;
1729 if (!(self->functions & OB_CLIENT_FUNC_ICONIFY))
1730 self->decorations &= ~OB_FRAME_DECOR_ICONIFY;
1731 if (!(self->functions & OB_CLIENT_FUNC_RESIZE))
1732 self->decorations &= ~(OB_FRAME_DECOR_GRIPS | OB_FRAME_DECOR_HANDLE);
1734 /* can't maximize without moving/resizing */
1735 if (!((self->functions & OB_CLIENT_FUNC_MAXIMIZE) &&
1736 (self->functions & OB_CLIENT_FUNC_MOVE) &&
1737 (self->functions & OB_CLIENT_FUNC_RESIZE))) {
1738 self->functions &= ~OB_CLIENT_FUNC_MAXIMIZE;
1739 self->decorations &= ~OB_FRAME_DECOR_MAXIMIZE;
1742 if (self->max_horz && self->max_vert) {
1743 /* you can't resize fully maximized windows */
1744 self->functions &= ~OB_CLIENT_FUNC_RESIZE;
1745 /* kill the handle on fully maxed windows */
1746 self->decorations &= ~(OB_FRAME_DECOR_HANDLE | OB_FRAME_DECOR_GRIPS);
1749 /* If there are no decorations to remove, don't allow the user to try
1751 if (self->decorations == 0)
1752 self->functions &= ~OB_CLIENT_FUNC_UNDECORATE;
1754 /* finally, the user can have requested no decorations, which overrides
1755 everything (but doesnt give it a border if it doesnt have one) */
1756 if (self->undecorated)
1757 self->decorations = 0;
1759 /* if we don't have a titlebar, then we cannot shade! */
1760 if (!(self->decorations & OB_FRAME_DECOR_TITLEBAR))
1761 self->functions &= ~OB_CLIENT_FUNC_SHADE;
1763 /* now we need to check against rules for the client's current state */
1764 if (self->fullscreen) {
1765 self->functions &= (OB_CLIENT_FUNC_CLOSE |
1766 OB_CLIENT_FUNC_FULLSCREEN |
1767 OB_CLIENT_FUNC_ICONIFY);
1768 self->decorations = 0;
1771 client_change_allowed_actions(self);
1774 /* force reconfigure to make sure decorations are updated */
1775 client_reconfigure(self, TRUE);
1778 static void client_change_allowed_actions(ObClient *self)
1783 /* desktop windows are kept on all desktops */
1784 if (self->type != OB_CLIENT_TYPE_DESKTOP)
1785 actions[num++] = OBT_PROP_ATOM(NET_WM_ACTION_CHANGE_DESKTOP);
1787 if (self->functions & OB_CLIENT_FUNC_SHADE)
1788 actions[num++] = OBT_PROP_ATOM(NET_WM_ACTION_SHADE);
1789 if (self->functions & OB_CLIENT_FUNC_CLOSE)
1790 actions[num++] = OBT_PROP_ATOM(NET_WM_ACTION_CLOSE);
1791 if (self->functions & OB_CLIENT_FUNC_MOVE)
1792 actions[num++] = OBT_PROP_ATOM(NET_WM_ACTION_MOVE);
1793 if (self->functions & OB_CLIENT_FUNC_ICONIFY)
1794 actions[num++] = OBT_PROP_ATOM(NET_WM_ACTION_MINIMIZE);
1795 if (self->functions & OB_CLIENT_FUNC_RESIZE)
1796 actions[num++] = OBT_PROP_ATOM(NET_WM_ACTION_RESIZE);
1797 if (self->functions & OB_CLIENT_FUNC_FULLSCREEN)
1798 actions[num++] = OBT_PROP_ATOM(NET_WM_ACTION_FULLSCREEN);
1799 if (self->functions & OB_CLIENT_FUNC_MAXIMIZE) {
1800 actions[num++] = OBT_PROP_ATOM(NET_WM_ACTION_MAXIMIZE_HORZ);
1801 actions[num++] = OBT_PROP_ATOM(NET_WM_ACTION_MAXIMIZE_VERT);
1803 if (self->functions & OB_CLIENT_FUNC_ABOVE)
1804 actions[num++] = OBT_PROP_ATOM(NET_WM_ACTION_ABOVE);
1805 if (self->functions & OB_CLIENT_FUNC_BELOW)
1806 actions[num++] = OBT_PROP_ATOM(NET_WM_ACTION_BELOW);
1807 if (self->functions & OB_CLIENT_FUNC_UNDECORATE)
1808 actions[num++] = OBT_PROP_ATOM(OB_WM_ACTION_UNDECORATE);
1810 OBT_PROP_SETA32(self->window, NET_WM_ALLOWED_ACTIONS, ATOM, actions, num);
1812 /* make sure the window isn't breaking any rules now
1814 don't check ICONIFY here. just cuz a window can't iconify doesnt mean
1815 it can't be iconified with its parent
1818 if (!(self->functions & OB_CLIENT_FUNC_SHADE) && self->shaded) {
1819 if (self->frame) client_shade(self, FALSE);
1820 else self->shaded = FALSE;
1822 if (!(self->functions & OB_CLIENT_FUNC_FULLSCREEN) && self->fullscreen) {
1823 if (self->frame) client_fullscreen(self, FALSE);
1824 else self->fullscreen = FALSE;
1826 if (!(self->functions & OB_CLIENT_FUNC_MAXIMIZE) && (self->max_horz ||
1828 if (self->frame) client_maximize(self, FALSE, 0);
1830 self->max_vert = self->max_horz = FALSE;
1831 render_plugin->frame_trigger (self->frame, OB_TRIGGER_UNMAX_VERT);
1832 render_plugin->frame_trigger (self->frame, OB_TRIGGER_UNMAX_HORZ);
1838 void client_update_wmhints(ObClient *self)
1842 /* assume a window takes input if it doesnt specify */
1843 self->can_focus = TRUE;
1845 if ((hints = XGetWMHints(obt_display, self->window)) != NULL) {
1848 if (hints->flags & InputHint)
1849 self->can_focus = hints->input;
1851 /* only do this when first managing the window *AND* when we aren't
1853 if (ob_state() != OB_STATE_STARTING && self->frame == NULL)
1854 if (hints->flags & StateHint)
1855 self->iconic = hints->initial_state == IconicState;
1858 self->urgent = (hints->flags & XUrgencyHint);
1859 if (self->urgent && !ur)
1860 client_hilite(self, TRUE);
1861 else if (!self->urgent && ur && self->demands_attention)
1862 client_hilite(self, FALSE);
1864 if (!(hints->flags & WindowGroupHint))
1865 hints->window_group = None;
1867 /* did the group state change? */
1868 if (hints->window_group !=
1869 (self->group ? self->group->leader : None))
1871 ObGroup *oldgroup = self->group;
1873 /* remove from the old group if there was one */
1874 if (self->group != NULL) {
1875 group_remove(self->group, self);
1879 /* add ourself to the group if we have one */
1880 if (hints->window_group != None) {
1881 self->group = group_add(hints->window_group, self);
1884 /* Put ourselves into the new group's transient tree, and remove
1885 ourselves from the old group's */
1886 client_update_transient_tree(self, oldgroup, self->group,
1887 self->transient_for_group,
1888 self->transient_for_group,
1889 client_direct_parent(self),
1890 client_direct_parent(self));
1892 /* Lastly, being in a group, or not, can change if the window is
1893 transient for anything.
1895 The logic for this is:
1896 self->transient = TRUE always if the window wants to be
1897 transient for something, even if transient_for was NULL because
1898 it wasn't in a group before.
1900 If parents was NULL and oldgroup was NULL we can assume
1901 that when we add the new group, it will become transient for
1904 If transient_for_group is TRUE, then it must have already
1905 had a group. If it is getting a new group, the above call to
1906 client_update_transient_tree has already taken care of
1907 everything ! If it is losing all group status then it will
1908 no longer be transient for anything and that needs to be
1911 if (self->transient &&
1912 ((self->parents == NULL && oldgroup == NULL) ||
1913 (self->transient_for_group && !self->group)))
1914 client_update_transient_for(self);
1917 /* the WM_HINTS can contain an icon */
1918 if (hints->flags & IconPixmapHint)
1919 client_update_icons(self);
1925 void client_update_title(ObClient *self)
1928 gchar *visible = NULL;
1930 g_free(self->title);
1931 g_free(self->original_title);
1934 if (!OBT_PROP_GETS(self->window, NET_WM_NAME, utf8, &data)) {
1935 /* try old x stuff */
1936 if (!(OBT_PROP_GETS(self->window, WM_NAME, locale, &data)
1937 || OBT_PROP_GETS(self->window, WM_NAME, utf8, &data))) {
1938 if (self->transient) {
1940 GNOME alert windows are not given titles:
1941 http://developer.gnome.org/projects/gup/hig/draft_hig_new/windows-alert.html
1943 data = g_strdup("");
1945 data = g_strdup("Unnamed Window");
1948 self->original_title = g_strdup(data);
1950 if (self->client_machine) {
1951 visible = g_strdup_printf("%s (%s)", data, self->client_machine);
1956 if (self->not_responding) {
1958 if (self->kill_level > 0)
1959 visible = g_strdup_printf("%s - [%s]", data, _("Killing..."));
1961 visible = g_strdup_printf("%s - [%s]", data, _("Not Responding"));
1965 OBT_PROP_SETS(self->window, NET_WM_VISIBLE_NAME, utf8, visible);
1966 self->title = visible;
1969 render_plugin->frame_update_layout (self->frame, FALSE, FALSE);
1971 /* update the icon title */
1973 g_free(self->icon_title);
1976 if (!OBT_PROP_GETS(self->window, NET_WM_ICON_NAME, utf8, &data))
1977 /* try old x stuff */
1978 if (!(OBT_PROP_GETS(self->window, WM_ICON_NAME, locale, &data) ||
1979 OBT_PROP_GETS(self->window, WM_ICON_NAME, utf8, &data)))
1980 data = g_strdup(self->title);
1982 if (self->client_machine) {
1983 visible = g_strdup_printf("%s (%s)", data, self->client_machine);
1988 if (self->not_responding) {
1990 if (self->kill_level > 0)
1991 visible = g_strdup_printf("%s - [%s]", data, _("Killing..."));
1993 visible = g_strdup_printf("%s - [%s]", data, _("Not Responding"));
1997 OBT_PROP_SETS(self->window, NET_WM_VISIBLE_ICON_NAME, utf8, visible);
1998 self->icon_title = visible;
2001 void client_update_strut(ObClient *self)
2005 gboolean got = FALSE;
2008 if (OBT_PROP_GETA32(self->window, NET_WM_STRUT_PARTIAL, CARDINAL,
2013 STRUT_PARTIAL_SET(strut,
2014 data[0], data[2], data[1], data[3],
2015 data[4], data[5], data[8], data[9],
2016 data[6], data[7], data[10], data[11]);
2022 OBT_PROP_GETA32(self->window, NET_WM_STRUT, CARDINAL, &data, &num)) {
2028 /* use the screen's width/height */
2029 a = screen_physical_area_all_monitors();
2031 STRUT_PARTIAL_SET(strut,
2032 data[0], data[2], data[1], data[3],
2033 a->y, a->y + a->height - 1,
2034 a->x, a->x + a->width - 1,
2035 a->y, a->y + a->height - 1,
2036 a->x, a->x + a->width - 1);
2043 STRUT_PARTIAL_SET(strut, 0, 0, 0, 0,
2044 0, 0, 0, 0, 0, 0, 0, 0);
2046 if (!STRUT_EQUAL(strut, self->strut)) {
2047 self->strut = strut;
2049 /* updating here is pointless while we're being mapped cuz we're not in
2050 the client list yet */
2052 screen_update_areas();
2056 /* Avoid storing icons above this size if possible */
2057 #define AVOID_ABOVE 64
2059 void client_update_icons(ObClient *self)
2064 guint num_seen; /* number of icons present */
2065 guint num_small_seen; /* number of icons small enough present */
2066 guint smallest, smallest_area;
2068 for (i = 0; i < self->nicons; ++i)
2069 g_free(self->icons[i].data);
2070 if (self->nicons > 0)
2071 g_free(self->icons);
2074 if (OBT_PROP_GETA32(self->window, NET_WM_ICON, CARDINAL, &data, &num)) {
2075 /* figure out how many valid icons are in here */
2077 num_seen = num_small_seen = 0;
2078 smallest = smallest_area = 0;
2084 /* watch for it being too small for the specified size, or for
2085 zero sized icons. */
2086 if (i > num || w == 0 || h == 0) break;
2088 if (!smallest_area || w*h < smallest_area) {
2089 smallest = num_seen;
2090 smallest_area = w*h;
2093 if (w <= AVOID_ABOVE && h <= AVOID_ABOVE)
2096 if (num_small_seen > 0)
2097 self->nicons = num_small_seen;
2101 self->icons = g_new(ObClientIcon, self->nicons);
2103 /* store the icons */
2105 for (j = 0; j < self->nicons;) {
2108 w = self->icons[j].width = data[i++];
2109 h = self->icons[j].height = data[i++];
2111 /* if there are some icons smaller than the threshold, we're
2112 skipping all the ones above */
2113 if (num_small_seen > 0) {
2114 if (w > AVOID_ABOVE || h > AVOID_ABOVE) {
2119 /* if there were no icons smaller than the threshold, then we are
2120 only taking the smallest available one we saw */
2121 else if (j != smallest) {
2126 self->icons[j].data = g_new(RrPixel32, w * h);
2127 for (x = 0, y = 0, t = 0; t < w * h; ++t, ++x, ++i) {
2132 self->icons[j].data[t] =
2133 (((data[i] >> 24) & 0xff) << RrDefaultAlphaOffset) +
2134 (((data[i] >> 16) & 0xff) << RrDefaultRedOffset) +
2135 (((data[i] >> 8) & 0xff) << RrDefaultGreenOffset) +
2136 (((data[i] >> 0) & 0xff) << RrDefaultBlueOffset);
2147 if ((hints = XGetWMHints(obt_display, self->window))) {
2148 if (hints->flags & IconPixmapHint) {
2150 self->icons = g_new(ObClientIcon, self->nicons);
2151 obt_display_ignore_errors(TRUE);
2152 if (!RrPixmapToRGBA(ob_rr_inst,
2154 (hints->flags & IconMaskHint ?
2155 hints->icon_mask : None),
2156 &self->icons[0].width,
2157 &self->icons[0].height,
2158 &self->icons[0].data))
2160 g_free(self->icons);
2163 obt_display_ignore_errors(FALSE);
2169 /* set the default icon onto the window
2170 in theory, this could be a race, but if a window doesn't set an icon
2171 or removes it entirely, it's not very likely it is going to set one
2172 right away afterwards
2174 if it has parents, then one of them will have an icon already
2176 if (self->nicons == 0 && !self->parents) {
2177 RrPixel32 *icon = ob_rr_theme->def_win_icon;
2180 data = g_new(gulong, 48*48+2);
2181 data[0] = data[1] = 48;
2182 for (i = 0; i < 48*48; ++i)
2183 data[i+2] = (((icon[i] >> RrDefaultAlphaOffset) & 0xff) << 24) +
2184 (((icon[i] >> RrDefaultRedOffset) & 0xff) << 16) +
2185 (((icon[i] >> RrDefaultGreenOffset) & 0xff) << 8) +
2186 (((icon[i] >> RrDefaultBlueOffset) & 0xff) << 0);
2187 OBT_PROP_SETA32(self->window, NET_WM_ICON, CARDINAL, data, 48*48+2);
2189 } else if (self->frame)
2190 render_plugin->frame_update_skin (self->frame);
2191 /* don't draw the icon empty if we're just setting one now anyways,
2192 we'll get the property change any second */
2193 //frame_adjust_icon(self->frame);
2196 void client_update_icon_geometry(ObClient *self)
2201 RECT_SET(self->icon_geometry, 0, 0, 0, 0);
2203 if (OBT_PROP_GETA32(self->window, NET_WM_ICON_GEOMETRY, CARDINAL,
2207 /* don't let them set it with an area < 0 */
2208 RECT_SET(self->icon_geometry, data[0], data[1],
2209 MAX(data[2],0), MAX(data[3],0));
2214 static void client_get_session_ids(ObClient *self)
2221 if (!OBT_PROP_GET32(self->window, WM_CLIENT_LEADER, WINDOW, &leader))
2224 /* get the SM_CLIENT_ID */
2227 got = OBT_PROP_GETS(leader, SM_CLIENT_ID, locale, &self->sm_client_id);
2229 OBT_PROP_GETS(self->window, SM_CLIENT_ID, locale, &self->sm_client_id);
2231 /* get the WM_CLASS (name and class). make them "" if they are not
2235 got = OBT_PROP_GETSS(leader, WM_CLASS, locale, &ss);
2237 got = OBT_PROP_GETSS(self->window, WM_CLASS, locale, &ss);
2241 self->name = g_strdup(ss[0]);
2243 self->class = g_strdup(ss[1]);
2248 if (self->name == NULL) self->name = g_strdup("");
2249 if (self->class == NULL) self->class = g_strdup("");
2251 /* get the WM_WINDOW_ROLE. make it "" if it is not provided */
2254 got = OBT_PROP_GETS(leader, WM_WINDOW_ROLE, locale, &s);
2256 got = OBT_PROP_GETS(self->window, WM_WINDOW_ROLE, locale, &s);
2261 self->role = g_strdup("");
2263 /* get the WM_COMMAND */
2267 got = OBT_PROP_GETSS(leader, WM_COMMAND, locale, &ss);
2269 got = OBT_PROP_GETSS(self->window, WM_COMMAND, locale, &ss);
2272 /* merge/mash them all together */
2273 gchar *merge = NULL;
2276 for (i = 0; ss[i]; ++i) {
2279 merge = g_strconcat(merge, ss[i], NULL);
2281 merge = g_strconcat(ss[i], NULL);
2286 self->wm_command = merge;
2289 /* get the WM_CLIENT_MACHINE */
2292 got = OBT_PROP_GETS(leader, WM_CLIENT_MACHINE, locale, &s);
2294 got = OBT_PROP_GETS(self->window, WM_CLIENT_MACHINE, locale, &s);
2297 gchar localhost[128];
2300 gethostname(localhost, 127);
2301 localhost[127] = '\0';
2302 if (strcmp(localhost, s) != 0)
2303 self->client_machine = s;
2307 /* see if it has the PID set too (the PID requires that the
2308 WM_CLIENT_MACHINE be set) */
2309 if (OBT_PROP_GET32(self->window, NET_WM_PID, CARDINAL, &pid))
2314 static void client_change_wm_state(ObClient *self)
2319 old = self->wmstate;
2321 if (self->shaded || self->iconic ||
2322 (self->desktop != DESKTOP_ALL && self->desktop != screen_desktop))
2324 self->wmstate = IconicState;
2326 self->wmstate = NormalState;
2328 if (old != self->wmstate) {
2329 OBT_PROP_MSG(ob_screen, self->window, KDE_WM_CHANGE_STATE,
2330 self->wmstate, 1, 0, 0, 0);
2332 state[0] = self->wmstate;
2334 OBT_PROP_SETA32(self->window, WM_STATE, WM_STATE, state, 2);
2338 static void client_change_state(ObClient *self)
2340 gulong netstate[12];
2345 netstate[num++] = OBT_PROP_ATOM(NET_WM_STATE_MODAL);
2347 netstate[num++] = OBT_PROP_ATOM(NET_WM_STATE_SHADED);
2349 netstate[num++] = OBT_PROP_ATOM(NET_WM_STATE_HIDDEN);
2350 if (self->skip_taskbar)
2351 netstate[num++] = OBT_PROP_ATOM(NET_WM_STATE_SKIP_TASKBAR);
2352 if (self->skip_pager)
2353 netstate[num++] = OBT_PROP_ATOM(NET_WM_STATE_SKIP_PAGER);
2354 if (self->fullscreen)
2355 netstate[num++] = OBT_PROP_ATOM(NET_WM_STATE_FULLSCREEN);
2357 netstate[num++] = OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_VERT);
2359 netstate[num++] = OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_HORZ);
2361 netstate[num++] = OBT_PROP_ATOM(NET_WM_STATE_ABOVE);
2363 netstate[num++] = OBT_PROP_ATOM(NET_WM_STATE_BELOW);
2364 if (self->demands_attention)
2365 netstate[num++] = OBT_PROP_ATOM(NET_WM_STATE_DEMANDS_ATTENTION);
2366 if (self->undecorated)
2367 netstate[num++] = OBT_PROP_ATOM(OB_WM_STATE_UNDECORATED);
2368 OBT_PROP_SETA32(self->window, NET_WM_STATE, ATOM, netstate, num);
2371 render_plugin->frame_update_layout (self->frame, FALSE, FALSE);
2374 ObClient *client_search_focus_tree(ObClient *self)
2379 for (it = self->transients; it; it = g_slist_next(it)) {
2380 if (client_focused(it->data)) return it->data;
2381 if ((ret = client_search_focus_tree(it->data))) return ret;
2386 ObClient *client_search_focus_tree_full(ObClient *self)
2388 if (self->parents) {
2391 for (it = self->parents; it; it = g_slist_next(it)) {
2392 ObClient *c = it->data;
2393 if ((c = client_search_focus_tree_full(it->data))) return c;
2399 /* this function checks the whole tree, the client_search_focus_tree
2400 does not, so we need to check this window */
2401 if (client_focused(self))
2403 return client_search_focus_tree(self);
2407 ObClient *client_search_focus_group_full(ObClient *self)
2412 for (it = self->group->members; it; it = g_slist_next(it)) {
2413 ObClient *c = it->data;
2415 if (client_focused(c)) return c;
2416 if ((c = client_search_focus_tree(it->data))) return c;
2419 if (client_focused(self)) return self;
2423 gboolean client_has_parent(ObClient *self)
2425 return self->parents != NULL;
2428 static ObStackingLayer calc_layer(ObClient *self)
2433 monitor = screen_physical_area_monitor(client_monitor(self));
2435 if (self->type == OB_CLIENT_TYPE_DESKTOP)
2436 l = OB_STACKING_LAYER_DESKTOP;
2437 else if (self->type == OB_CLIENT_TYPE_DOCK) {
2438 if (self->below) l = OB_STACKING_LAYER_NORMAL;
2439 else l = OB_STACKING_LAYER_ABOVE;
2441 else if ((self->fullscreen ||
2442 /* No decorations and fills the monitor = oldskool fullscreen.
2443 But not for maximized windows.
2445 (self->decorations == 0 &&
2446 !(self->max_horz && self->max_vert) &&
2447 RECT_EQUAL(self->area, *monitor))) &&
2448 /* you are fullscreen while you or your children are focused.. */
2449 (client_focused(self) || client_search_focus_tree(self) ||
2450 /* you can be fullscreen if you're on another desktop */
2451 (self->desktop != screen_desktop &&
2452 self->desktop != DESKTOP_ALL) ||
2453 /* and you can also be fullscreen if the focused client is on
2454 another monitor, or nothing else is focused */
2456 client_monitor(focus_client) != client_monitor(self))))
2457 l = OB_STACKING_LAYER_FULLSCREEN;
2458 else if (self->above) l = OB_STACKING_LAYER_ABOVE;
2459 else if (self->below) l = OB_STACKING_LAYER_BELOW;
2460 else l = OB_STACKING_LAYER_NORMAL;
2467 static void client_calc_layer_recursive(ObClient *self, ObClient *orig,
2468 ObStackingLayer min)
2470 ObStackingLayer old, own;
2474 own = calc_layer(self);
2475 self->layer = MAX(own, min);
2477 if (self->layer != old) {
2478 stacking_remove(CLIENT_AS_WINDOW(self));
2479 stacking_add_nonintrusive(CLIENT_AS_WINDOW(self));
2482 /* we've been restacked */
2483 self->visited = TRUE;
2485 for (it = self->transients; it; it = g_slist_next(it))
2486 client_calc_layer_recursive(it->data, orig,
2490 static void client_calc_layer_internal(ObClient *self)
2494 /* transients take on the layer of their parents */
2495 sit = client_search_all_top_parents(self);
2497 for (; sit; sit = g_slist_next(sit))
2498 client_calc_layer_recursive(sit->data, self, 0);
2501 void client_calc_layer(ObClient *self)
2505 /* skip over stuff above fullscreen layer */
2506 for (it = stacking_list; it; it = g_list_next(it))
2507 if (window_layer(it->data) <= OB_STACKING_LAYER_FULLSCREEN) break;
2509 /* find the windows in the fullscreen layer, and mark them not-visited */
2510 for (; it; it = g_list_next(it)) {
2511 if (window_layer(it->data) < OB_STACKING_LAYER_FULLSCREEN) break;
2512 else if (WINDOW_IS_CLIENT(it->data))
2513 WINDOW_AS_CLIENT(it->data)->visited = FALSE;
2516 client_calc_layer_internal(self);
2518 /* skip over stuff above fullscreen layer */
2519 for (it = stacking_list; it; it = g_list_next(it))
2520 if (window_layer(it->data) <= OB_STACKING_LAYER_FULLSCREEN) break;
2522 /* now recalc any windows in the fullscreen layer which have not
2523 had their layer recalced already */
2524 for (; it; it = g_list_next(it)) {
2525 if (window_layer(it->data) < OB_STACKING_LAYER_FULLSCREEN) break;
2526 else if (WINDOW_IS_CLIENT(it->data) &&
2527 !WINDOW_AS_CLIENT(it->data)->visited)
2528 client_calc_layer_internal(it->data);
2532 gboolean client_should_show(ObClient *self)
2536 if (client_normal(self) && screen_showing_desktop)
2538 if (self->desktop == screen_desktop || self->desktop == DESKTOP_ALL)
2544 gboolean client_show(ObClient *self)
2546 gboolean show = FALSE;
2548 if (client_should_show(self)) {
2549 /* replay pending pointer event before showing the window, in case it
2550 should be going to something under the window */
2551 mouse_replay_pointer();
2553 render_plugin->frame_show(self->frame);
2556 /* According to the ICCCM (sec 4.1.3.1) when a window is not visible,
2557 it needs to be in IconicState. This includes when it is on another
2560 client_change_wm_state(self);
2565 gboolean client_hide(ObClient *self)
2567 gboolean hide = FALSE;
2569 if (!client_should_show(self)) {
2570 if (self == focus_client) {
2571 /* if there is a grab going on, then we need to cancel it. if we
2572 move focus during the grab, applications will get
2573 NotifyWhileGrabbed events and ignore them !
2575 actions should not rely on being able to move focus during an
2578 event_cancel_all_key_grabs();
2581 /* We don't need to ignore enter events here.
2582 The window can hide/iconify in 3 different ways:
2583 1 - through an x message. in this case we ignore all enter events
2584 caused by responding to the x message (unless underMouse)
2585 2 - by a keyboard action. in this case we ignore all enter events
2586 caused by the action
2587 3 - by a mouse action. in this case they are doing stuff with the
2588 mouse and focus _should_ move.
2590 Also in action_end, we simulate an enter event that can't be ignored
2591 so trying to ignore them is futile in case 3 anyways
2594 /* replay pending pointer event before hiding the window, in case it
2595 should be going to the window */
2596 mouse_replay_pointer();
2598 self->ignore_unmaps += render_plugin->frame_hide(self->frame);
2601 /* According to the ICCCM (sec 4.1.3.1) when a window is not visible,
2602 it needs to be in IconicState. This includes when it is on another
2605 client_change_wm_state(self);
2610 void client_showhide(ObClient *self)
2612 if (!client_show(self))
2616 gboolean client_normal(ObClient *self) {
2617 return ! (self->type == OB_CLIENT_TYPE_DESKTOP ||
2618 self->type == OB_CLIENT_TYPE_DOCK ||
2619 self->type == OB_CLIENT_TYPE_SPLASH);
2622 gboolean client_helper(ObClient *self)
2624 return (self->type == OB_CLIENT_TYPE_UTILITY ||
2625 self->type == OB_CLIENT_TYPE_MENU ||
2626 self->type == OB_CLIENT_TYPE_TOOLBAR);
2629 gboolean client_mouse_focusable(ObClient *self)
2631 return !(self->type == OB_CLIENT_TYPE_MENU ||
2632 self->type == OB_CLIENT_TYPE_TOOLBAR ||
2633 self->type == OB_CLIENT_TYPE_SPLASH ||
2634 self->type == OB_CLIENT_TYPE_DOCK);
2637 gboolean client_enter_focusable(ObClient *self)
2639 /* you can focus desktops but it shouldn't on enter */
2640 return (client_mouse_focusable(self) &&
2641 self->type != OB_CLIENT_TYPE_DESKTOP);
2645 static void client_apply_startup_state(ObClient *self,
2646 gint x, gint y, gint w, gint h)
2648 /* save the states that we are going to apply */
2649 gboolean iconic = self->iconic;
2650 gboolean fullscreen = self->fullscreen;
2651 gboolean undecorated = self->undecorated;
2652 gboolean shaded = self->shaded;
2653 gboolean demands_attention = self->demands_attention;
2654 gboolean max_horz = self->max_horz;
2655 gboolean max_vert = self->max_vert;
2659 /* turn them all off in the client, so they won't affect the window
2661 self->iconic = self->fullscreen = self->undecorated = self->shaded =
2662 self->demands_attention = self->max_horz = self->max_vert = FALSE;
2664 /* move the client to its placed position, or it it's already there,
2665 generate a ConfigureNotify telling the client where it is.
2667 do this after adjusting the frame. otherwise it gets all weird and
2668 clients don't work right
2670 do this before applying the states so they have the correct
2671 pre-max/pre-fullscreen values
2673 client_try_configure(self, &x, &y, &w, &h, &l, &l, FALSE);
2674 ob_debug("placed window 0x%x at %d, %d with size %d x %d",
2675 self->window, x, y, w, h);
2676 /* save the area, and make it where it should be for the premax stuff */
2677 oldarea = self->area;
2678 RECT_SET(self->area, x, y, w, h);
2679 render_plugin->frame_set_client_area (self->frame, self->area);
2681 /* apply the states. these are in a carefully crafted order.. */
2684 client_iconify(self, TRUE, FALSE, TRUE);
2686 client_fullscreen(self, TRUE);
2688 client_set_undecorated(self, TRUE);
2690 client_shade(self, TRUE);
2691 if (demands_attention)
2692 client_hilite(self, TRUE);
2694 if (max_vert && max_horz)
2695 client_maximize(self, TRUE, 0);
2697 client_maximize(self, TRUE, 2);
2699 client_maximize(self, TRUE, 1);
2701 /* if the window hasn't been configured yet, then do so now, in fact the
2702 x,y,w,h may _not_ be the same as the area rect, which can end up
2703 meaning that the client isn't properly moved/resized by the fullscreen
2705 pho can cause this because it maps at size of the screen but not 0,0
2706 so openbox moves it on screen to 0,0 (thus x,y=0,0 and area.x,y don't).
2707 then fullscreen'ing makes it go to 0,0 which it thinks it already is at
2708 cuz thats where the pre-fullscreen will be. however the actual area is
2709 not, so this needs to be called even if we have fullscreened/maxed
2711 self->area = oldarea;
2712 render_plugin->frame_set_client_area (self->frame, self->area);
2713 render_plugin->frame_set_decorations (self->frame, self->decorations);
2714 render_plugin->frame_update_layout (self->frame, FALSE, FALSE);
2715 client_configure(self, x, y, w, h, FALSE, TRUE, FALSE);
2717 /* set the desktop hint, to make sure that it always exists */
2718 OBT_PROP_SET32(self->window, NET_WM_DESKTOP, CARDINAL, self->desktop);
2720 /* nothing to do for the other states:
2729 void client_gravity_resize_w(ObClient *self, gint *x, gint oldw, gint neww)
2731 /* these should be the current values. this is for when you're not moving,
2733 g_assert(*x == self->area.x);
2734 g_assert(oldw == self->area.width);
2737 switch (self->gravity) {
2739 case NorthWestGravity:
2741 case SouthWestGravity:
2748 *x -= (neww - oldw) / 2;
2750 case NorthEastGravity:
2752 case SouthEastGravity:
2758 void client_gravity_resize_h(ObClient *self, gint *y, gint oldh, gint newh)
2760 /* these should be the current values. this is for when you're not moving,
2762 g_assert(*y == self->area.y);
2763 g_assert(oldh == self->area.height);
2766 switch (self->gravity) {
2768 case NorthWestGravity:
2770 case NorthEastGravity:
2777 *y -= (newh - oldh) / 2;
2779 case SouthWestGravity:
2781 case SouthEastGravity:
2787 void client_try_configure(ObClient *self, gint *x, gint *y, gint *w, gint *h,
2788 gint *logicalw, gint *logicalh,
2791 Rect desired = {*x, *y, *w, *h};
2792 frame_rect_to_frame(self, &desired);
2794 /* make the frame recalculate its dimentions n shit without changing
2795 anything visible for real, this way the constraints below can work with
2796 the updated frame dimensions. */
2797 render_plugin->frame_set_decorations (self->frame, self->decorations);
2798 render_plugin->frame_update_layout (self->frame, FALSE, TRUE);
2800 /* gets the frame's position */
2801 frame_client_gravity(self, x, y);
2803 /* these positions are frame positions, not client positions */
2805 /* set the size and position if fullscreen */
2806 if (self->fullscreen) {
2810 i = screen_find_monitor(&desired);
2811 a = screen_physical_area_monitor(i);
2818 user = FALSE; /* ignore if the client can't be moved/resized when it
2822 } else if (self->max_horz || self->max_vert) {
2826 /* use all possible struts when maximizing to the full screen */
2827 i = screen_find_monitor(&desired);
2828 a = screen_area(self->desktop, i,
2829 (self->max_horz && self->max_vert ? NULL : &desired));
2831 Strut size = render_plugin->frame_get_size(self->frame);
2832 /* set the size and position if maximized */
2833 if (self->max_horz) {
2835 *w = a->width - size.left - size.right;
2837 if (self->max_vert) {
2839 *h = a->height - size.top - size.bottom;
2842 user = FALSE; /* ignore if the client can't be moved/resized when it
2848 /* gets the client's position */
2849 frame_frame_gravity(self, x, y);
2851 /* work within the prefered sizes given by the window */
2852 if (!(*w == self->area.width && *h == self->area.height)) {
2853 gint basew, baseh, minw, minh;
2855 gfloat minratio, maxratio;
2857 incw = self->fullscreen || self->max_horz ? 1 : self->size_inc.width;
2858 inch = self->fullscreen || self->max_vert ? 1 : self->size_inc.height;
2859 minratio = self->fullscreen || (self->max_horz && self->max_vert) ?
2860 0 : self->min_ratio;
2861 maxratio = self->fullscreen || (self->max_horz && self->max_vert) ?
2862 0 : self->max_ratio;
2864 /* base size is substituted with min size if not specified */
2865 if (self->base_size.width || self->base_size.height) {
2866 basew = self->base_size.width;
2867 baseh = self->base_size.height;
2869 basew = self->min_size.width;
2870 baseh = self->min_size.height;
2872 /* min size is substituted with base size if not specified */
2873 if (self->min_size.width || self->min_size.height) {
2874 minw = self->min_size.width;
2875 minh = self->min_size.height;
2877 minw = self->base_size.width;
2878 minh = self->base_size.height;
2881 /* if this is a user-requested resize, then check against min/max
2884 /* smaller than min size or bigger than max size? */
2885 if (*w > self->max_size.width) *w = self->max_size.width;
2886 if (*w < minw) *w = minw;
2887 if (*h > self->max_size.height) *h = self->max_size.height;
2888 if (*h < minh) *h = minh;
2893 /* keep to the increments */
2897 /* you cannot resize to nothing */
2898 if (basew + *w < 1) *w = 1 - basew;
2899 if (baseh + *h < 1) *h = 1 - baseh;
2901 /* save the logical size */
2902 *logicalw = incw > 1 ? *w : *w + basew;
2903 *logicalh = inch > 1 ? *h : *h + baseh;
2911 /* adjust the height to match the width for the aspect ratios.
2912 for this, min size is not substituted for base size ever. */
2913 *w -= self->base_size.width;
2914 *h -= self->base_size.height;
2917 if (*h * minratio > *w) {
2918 *h = (gint)(*w / minratio);
2920 /* you cannot resize to nothing */
2923 *w = (gint)(*h * minratio);
2927 if (*h * maxratio < *w) {
2928 *h = (gint)(*w / maxratio);
2930 /* you cannot resize to nothing */
2933 *w = (gint)(*h * minratio);
2937 *w += self->base_size.width;
2938 *h += self->base_size.height;
2941 /* these override the above states! if you cant move you can't move! */
2943 if (!(self->functions & OB_CLIENT_FUNC_MOVE)) {
2947 if (!(self->functions & OB_CLIENT_FUNC_RESIZE)) {
2948 *w = self->area.width;
2949 *h = self->area.height;
2958 void client_configure(ObClient *self, gint x, gint y, gint w, gint h,
2959 gboolean user, gboolean final, gboolean force_reply)
2963 gboolean send_resize_client;
2964 gboolean moved = FALSE, resized = FALSE, rootmoved = FALSE;
2965 gboolean fmoved, fresized;
2966 guint fdecor = render_plugin->frame_get_decorations(self->frame);
2967 gboolean fhorz = render_plugin->frame_is_max_horz(self->frame);
2968 gboolean fvert = render_plugin->frame_is_max_vert(self->frame);
2969 gint logicalw, logicalh;
2971 Strut size = render_plugin->frame_get_size(self->frame);
2972 Rect area = render_plugin->frame_get_window_area(self->frame);
2974 /* find the new x, y, width, and height (and logical size) */
2975 client_try_configure(self, &x, &y, &w, &h, &logicalw, &logicalh, user);
2977 /* set the logical size if things changed */
2978 if (!(w == self->area.width && h == self->area.height))
2979 SIZE_SET(self->logical_size, logicalw, logicalh);
2981 /* figure out if we moved or resized or what */
2982 moved = (x != self->area.x || y != self->area.y);
2983 resized = (w != self->area.width || h != self->area.height);
2985 oldw = self->area.width;
2986 oldh = self->area.height;
2987 oldframe = render_plugin->frame_get_window_area(self->frame);
2988 RECT_SET(self->area, x, y, w, h);
2990 render_plugin->frame_set_client_area (self->frame, self->area);
2992 /* for app-requested resizes, always resize if 'resized' is true.
2993 for user-requested ones, only resize if final is true, or when
2994 resizing in redraw mode */
2995 send_resize_client = ((!user && resized) ||
2997 (resized && config_resize_redraw))));
2999 /* if the client is enlarging, then resize the client before the frame */
3000 if (send_resize_client && (w > oldw || h > oldh)) {
3001 render_plugin->frame_set_decorations (self->frame, self->decorations);
3002 render_plugin->frame_update_layout (self->frame, FALSE, FALSE);
3005 /* find the frame's dimensions and move/resize it */
3009 /* if decorations changed, then readjust everything for the frame */
3010 if (self->decorations != fdecor ||
3011 self->max_horz != fhorz || self->max_vert != fvert)
3013 fmoved = fresized = TRUE;
3016 /* adjust the frame */
3017 if (fmoved || fresized) {
3018 gulong ignore_start;
3020 ignore_start = event_start_ignore_all_enters();
3022 /* replay pending pointer event before move the window, in case it
3023 would change what window gets the event */
3024 mouse_replay_pointer();
3026 render_plugin->frame_set_decorations (self->frame, self->decorations);
3027 render_plugin->frame_update_layout (self->frame, TRUE, FALSE);
3030 event_end_ignore_all_enters(ignore_start);
3033 if (!user || final) {
3034 gint oldrx = self->root_pos.x;
3035 gint oldry = self->root_pos.y;
3036 /* we have reset the client to 0 border width, so don't include
3037 it in these coords */
3038 POINT_SET(self->root_pos,
3039 area.x + size.left -
3042 self->border_width);
3043 if (self->root_pos.x != oldrx || self->root_pos.y != oldry)
3047 /* This is kinda tricky and should not be changed.. let me explain!
3049 When user = FALSE, then the request is coming from the application
3050 itself, and we are more strict about when to send a synthetic
3051 ConfigureNotify. We strictly follow the rules of the ICCCM sec 4.1.5
3052 in this case (if force_reply is true)
3054 When user = TRUE, then the request is coming from "us", like when we
3055 maximize a window or something. In this case we are more lenient. We
3056 used to follow the same rules as above, but _Java_ Swing can't handle
3057 this. So just to appease Swing, when user = TRUE, we always send
3058 a synthetic ConfigureNotify to give the window its root coordinates.
3060 if ((!user && !resized && (rootmoved || force_reply)) ||
3061 (user && final && rootmoved))
3065 event.type = ConfigureNotify;
3066 event.xconfigure.display = obt_display;
3067 event.xconfigure.event = self->window;
3068 event.xconfigure.window = self->window;
3070 ob_debug("Sending ConfigureNotify to %s for %d,%d %dx%d",
3071 self->title, self->root_pos.x, self->root_pos.y, w, h);
3073 /* root window real coords */
3074 event.xconfigure.x = self->root_pos.x;
3075 event.xconfigure.y = self->root_pos.y;
3076 event.xconfigure.width = w;
3077 event.xconfigure.height = h;
3078 event.xconfigure.border_width = self->border_width;
3079 event.xconfigure.above = None;
3080 event.xconfigure.override_redirect = FALSE;
3081 XSendEvent(event.xconfigure.display, event.xconfigure.window,
3082 FALSE, StructureNotifyMask, &event);
3085 /* if the client is shrinking, then resize the frame before the client.
3087 both of these resize sections may run, because the top one only resizes
3088 in the direction that is growing
3090 if (send_resize_client && (w <= oldw || h <= oldh)) {
3091 render_plugin->frame_set_decorations (self->frame, self->decorations);
3092 render_plugin->frame_update_layout (self->frame, FALSE, FALSE);
3095 XFlush(obt_display);
3097 /* if it moved between monitors, then this can affect the stacking
3098 layer of this window or others - for fullscreen windows */
3099 Rect current_frame = render_plugin->frame_get_window_area(self->frame);
3100 if (screen_find_monitor(¤t_frame) !=
3101 screen_find_monitor(&oldframe))
3103 client_calc_layer(self);
3107 void client_fullscreen(ObClient *self, gboolean fs)
3111 if (!(self->functions & OB_CLIENT_FUNC_FULLSCREEN) || /* can't */
3112 self->fullscreen == fs) return; /* already done */
3114 self->fullscreen = fs;
3115 client_change_state(self); /* change the state hints on the client */
3118 self->pre_fullscreen_area = self->area;
3119 /* if the window is maximized, its area isn't all that meaningful.
3120 save it's premax area instead. */
3121 if (self->max_horz) {
3122 self->pre_fullscreen_area.x = self->pre_max_area.x;
3123 self->pre_fullscreen_area.width = self->pre_max_area.width;
3125 if (self->max_vert) {
3126 self->pre_fullscreen_area.y = self->pre_max_area.y;
3127 self->pre_fullscreen_area.height = self->pre_max_area.height;
3130 /* these will help configure_full figure out where to fullscreen
3134 w = self->area.width;
3135 h = self->area.height;
3137 g_assert(self->pre_fullscreen_area.width > 0 &&
3138 self->pre_fullscreen_area.height > 0);
3140 x = self->pre_fullscreen_area.x;
3141 y = self->pre_fullscreen_area.y;
3142 w = self->pre_fullscreen_area.width;
3143 h = self->pre_fullscreen_area.height;
3144 RECT_SET(self->pre_fullscreen_area, 0, 0, 0, 0);
3147 ob_debug("Window %s going fullscreen (%d)",
3148 self->title, self->fullscreen);
3150 client_setup_decor_and_functions(self, FALSE);
3151 client_move_resize(self, x, y, w, h);
3153 /* and adjust our layer/stacking. do this after resizing the window,
3154 and applying decorations, because windows which fill the screen are
3155 considered "fullscreen" and it affects their layer */
3156 client_calc_layer(self);
3159 /* try focus us when we go into fullscreen mode */
3164 static void client_iconify_recursive(ObClient *self,
3165 gboolean iconic, gboolean curdesk,
3166 gboolean hide_animation)
3169 gboolean changed = FALSE;
3172 if (self->iconic != iconic) {
3173 ob_debug("%sconifying window: 0x%lx", (iconic ? "I" : "Uni"),
3177 /* don't let non-normal windows iconify along with their parents
3179 if (client_normal(self)) {
3180 self->iconic = iconic;
3182 /* update the focus lists.. iconic windows go to the bottom of
3184 focus_order_to_bottom(self);
3189 self->iconic = iconic;
3191 if (curdesk && self->desktop != screen_desktop &&
3192 self->desktop != DESKTOP_ALL)
3193 client_set_desktop(self, screen_desktop, FALSE, FALSE);
3195 /* this puts it after the current focused window */
3196 focus_order_remove(self);
3197 focus_order_add_new(self);
3204 client_change_state(self);
3205 if (config_animate_iconify && !hide_animation)
3206 render_plugin->frame_begin_iconify_animation(self->frame, iconic);
3207 /* do this after starting the animation so it doesn't flash */
3208 client_showhide(self);
3211 /* iconify all direct transients, and deiconify all transients
3213 for (it = self->transients; it; it = g_slist_next(it))
3214 if (it->data != self)
3215 if (client_is_direct_child(self, it->data) || !iconic)
3216 client_iconify_recursive(it->data, iconic, curdesk,
3220 void client_iconify(ObClient *self, gboolean iconic, gboolean curdesk,
3221 gboolean hide_animation)
3223 if (self->functions & OB_CLIENT_FUNC_ICONIFY || !iconic) {
3224 /* move up the transient chain as far as possible first */
3225 self = client_search_top_direct_parent(self);
3226 client_iconify_recursive(self, iconic, curdesk, hide_animation);
3230 void client_maximize(ObClient *self, gboolean max, gint dir)
3234 g_assert(dir == 0 || dir == 1 || dir == 2);
3235 if (!(self->functions & OB_CLIENT_FUNC_MAXIMIZE)) return; /* can't */
3237 /* check if already done */
3239 if (dir == 0 && self->max_horz && self->max_vert) return;
3240 if (dir == 1 && self->max_horz) return;
3241 if (dir == 2 && self->max_vert) return;
3243 if (dir == 0 && !self->max_horz && !self->max_vert) return;
3244 if (dir == 1 && !self->max_horz) return;
3245 if (dir == 2 && !self->max_vert) return;
3248 /* these will help configure_full figure out which screen to fill with
3252 w = self->area.width;
3253 h = self->area.height;
3256 if ((dir == 0 || dir == 1) && !self->max_horz) { /* horz */
3257 RECT_SET(self->pre_max_area,
3258 self->area.x, self->pre_max_area.y,
3259 self->area.width, self->pre_max_area.height);
3261 if ((dir == 0 || dir == 2) && !self->max_vert) { /* vert */
3262 RECT_SET(self->pre_max_area,
3263 self->pre_max_area.x, self->area.y,
3264 self->pre_max_area.width, self->area.height);
3267 if ((dir == 0 || dir == 1) && self->max_horz) { /* horz */
3268 g_assert(self->pre_max_area.width > 0);
3270 x = self->pre_max_area.x;
3271 w = self->pre_max_area.width;
3273 RECT_SET(self->pre_max_area, 0, self->pre_max_area.y,
3274 0, self->pre_max_area.height);
3276 if ((dir == 0 || dir == 2) && self->max_vert) { /* vert */
3277 g_assert(self->pre_max_area.height > 0);
3279 y = self->pre_max_area.y;
3280 h = self->pre_max_area.height;
3282 RECT_SET(self->pre_max_area, self->pre_max_area.x, 0,
3283 self->pre_max_area.width, 0);
3287 if (dir == 0 || dir == 1) {
3288 self->max_horz = max; /* horz */
3289 render_plugin->frame_trigger(self->frame, max? OB_TRIGGER_MAX_HORZ : OB_TRIGGER_UNMAX_HORZ);
3292 if (dir == 0 || dir == 2){
3293 self->max_vert = max; /* vert */
3294 render_plugin->frame_trigger(self->frame, max? OB_TRIGGER_MAX_VERT : OB_TRIGGER_UNMAX_VERT);
3297 client_change_state(self); /* change the state hints on the client */
3299 client_setup_decor_and_functions(self, FALSE);
3300 client_move_resize(self, x, y, w, h);
3303 void client_shade(ObClient *self, gboolean shade)
3305 if ((!(self->functions & OB_CLIENT_FUNC_SHADE) &&
3306 shade) || /* can't shade */
3307 self->shaded == shade) return; /* already done */
3309 self->shaded = shade;
3310 client_change_state(self);
3311 client_change_wm_state(self); /* the window is being hidden/shown */
3312 /* resize the frame to just the titlebar */
3313 render_plugin->frame_set_is_shaded (self->frame, self->shaded);
3314 render_plugin->frame_update_layout(self->frame, FALSE, FALSE);
3317 static void client_ping_event(ObClient *self, gboolean dead)
3319 self->not_responding = dead;
3320 client_update_title(self);
3323 /* it came back to life ! */
3325 if (self->kill_prompt) {
3326 prompt_unref(self->kill_prompt);
3327 self->kill_prompt = NULL;
3330 self->kill_level = 0;
3334 void client_close(ObClient *self)
3336 if (!(self->functions & OB_CLIENT_FUNC_CLOSE)) return;
3339 prompt_cancel(self->prompt);
3343 /* in the case that the client provides no means to requesting that it
3344 close, we just kill it */
3345 if (!self->delete_window)
3346 /* don't use client_kill(), we should only kill based on PID in
3347 response to a lack of PING replies */
3348 XKillClient(obt_display, self->window);
3350 /* request the client to close with WM_DELETE_WINDOW */
3351 OBT_PROP_MSG_TO(self->window, self->window, WM_PROTOCOLS,
3352 OBT_PROP_ATOM(WM_DELETE_WINDOW), event_curtime,
3353 0, 0, 0, NoEventMask);
3355 if (self->not_responding)
3356 client_prompt_kill(self);
3360 #define OB_KILL_RESULT_NO 0
3361 #define OB_KILL_RESULT_YES 1
3363 static void client_kill_requested(ObPrompt *p, gint result, gpointer data)
3365 ObClient *self = data;
3367 if (result == OB_KILL_RESULT_YES)
3370 prompt_unref(self->kill_prompt);
3371 self->kill_prompt = NULL;
3374 static void client_prompt_kill(ObClient *self)
3376 /* check if we're already prompting */
3377 if (!self->kill_prompt) {
3378 ObPromptAnswer answers[] = {
3379 { _("No"), OB_KILL_RESULT_NO },
3380 { _("Yes"), OB_KILL_RESULT_YES }
3385 if (self->kill_level == 0)
3391 (_("The window \"%s\" does not seem to be responding. Do you want to force it to exit by sending the %s signal?"), self->original_title, sig);
3393 self->kill_prompt = prompt_new(m, answers,
3394 sizeof(answers)/sizeof(answers[0]),
3395 OB_KILL_RESULT_NO, /* default = no */
3396 OB_KILL_RESULT_NO, /* cancel = no */
3397 client_kill_requested, self);
3401 prompt_show(self->kill_prompt, self);
3404 void client_kill(ObClient *self)
3406 /* don't kill our own windows */
3407 if (self->prompt) return;
3409 if (!self->client_machine && self->pid) {
3410 /* running on the local host */
3411 if (self->kill_level == 0) {
3412 ob_debug("killing window 0x%x with pid %lu, with SIGTERM",
3413 self->window, self->pid);
3414 kill(self->pid, SIGTERM);
3417 /* show that we're trying to kill it */
3418 client_update_title(self);
3421 ob_debug("killing window 0x%x with pid %lu, with SIGKILL",
3422 self->window, self->pid);
3423 kill(self->pid, SIGKILL); /* kill -9 */
3427 /* running on a remote host */
3428 XKillClient(obt_display, self->window);
3432 void client_hilite(ObClient *self, gboolean hilite)
3434 if (self->demands_attention == hilite)
3435 return; /* no change */
3437 /* don't allow focused windows to hilite */
3438 self->demands_attention = hilite && !client_focused(self);
3439 if (self->frame != NULL) { /* if we're mapping, just set the state */
3440 if (self->demands_attention)
3441 render_plugin->frame_flash_start(self->frame);
3443 render_plugin->frame_flash_stop(self->frame);
3444 client_change_state(self);
3448 static void client_set_desktop_recursive(ObClient *self,
3456 if (target != self->desktop && self->type != OB_CLIENT_TYPE_DESKTOP) {
3458 ob_debug("Setting desktop %u", target+1);
3460 g_assert(target < screen_num_desktops || target == DESKTOP_ALL);
3462 old = self->desktop;
3463 self->desktop = target;
3464 OBT_PROP_SET32(self->window, NET_WM_DESKTOP, CARDINAL, target);
3465 /* the frame can display the current desktop state */
3466 render_plugin->frame_set_decorations (self->frame, self->decorations);
3467 render_plugin->frame_update_layout(self->frame, FALSE, FALSE);
3468 /* 'move' the window to the new desktop */
3472 /* raise if it was not already on the desktop */
3473 if (old != DESKTOP_ALL && !dontraise)
3474 stacking_raise(CLIENT_AS_WINDOW(self));
3475 if (STRUT_EXISTS(self->strut))
3476 screen_update_areas();
3478 /* the new desktop's geometry may be different, so we may need to
3479 resize, for example if we are maximized */
3480 client_reconfigure(self, FALSE);
3483 /* move all transients */
3484 for (it = self->transients; it; it = g_slist_next(it))
3485 if (it->data != self)
3486 if (client_is_direct_child(self, it->data))
3487 client_set_desktop_recursive(it->data, target,
3488 donthide, dontraise);
3491 void client_set_desktop(ObClient *self, guint target,
3492 gboolean donthide, gboolean dontraise)
3494 self = client_search_top_direct_parent(self);
3495 client_set_desktop_recursive(self, target, donthide, dontraise);
3498 gboolean client_is_direct_child(ObClient *parent, ObClient *child)
3500 while (child != parent && (child = client_direct_parent(child)));
3501 return child == parent;
3504 ObClient *client_search_modal_child(ObClient *self)
3509 for (it = self->transients; it; it = g_slist_next(it)) {
3510 ObClient *c = it->data;
3511 if ((ret = client_search_modal_child(c))) return ret;
3512 if (c->modal) return c;
3517 gboolean client_validate(ObClient *self)
3521 XSync(obt_display, FALSE); /* get all events on the server */
3523 if (XCheckTypedWindowEvent(obt_display, self->window, DestroyNotify, &e) ||
3524 XCheckTypedWindowEvent(obt_display, self->window, UnmapNotify, &e))
3526 XPutBackEvent(obt_display, &e);
3533 void client_set_wm_state(ObClient *self, glong state)
3535 if (state == self->wmstate) return; /* no change */
3539 client_iconify(self, TRUE, TRUE, FALSE);
3542 client_iconify(self, FALSE, TRUE, FALSE);
3547 void client_set_state(ObClient *self, Atom action, glong data1, glong data2)
3549 gboolean shaded = self->shaded;
3550 gboolean fullscreen = self->fullscreen;
3551 gboolean undecorated = self->undecorated;
3552 gboolean max_horz = self->max_horz;
3553 gboolean max_vert = self->max_vert;
3554 gboolean modal = self->modal;
3555 gboolean iconic = self->iconic;
3556 gboolean demands_attention = self->demands_attention;
3557 gboolean above = self->above;
3558 gboolean below = self->below;
3561 if (!(action == OBT_PROP_ATOM(NET_WM_STATE_ADD) ||
3562 action == OBT_PROP_ATOM(NET_WM_STATE_REMOVE) ||
3563 action == OBT_PROP_ATOM(NET_WM_STATE_TOGGLE)))
3564 /* an invalid action was passed to the client message, ignore it */
3567 for (i = 0; i < 2; ++i) {
3568 Atom state = i == 0 ? data1 : data2;
3570 if (!state) continue;
3572 /* if toggling, then pick whether we're adding or removing */
3573 if (action == OBT_PROP_ATOM(NET_WM_STATE_TOGGLE)) {
3574 if (state == OBT_PROP_ATOM(NET_WM_STATE_MODAL))
3575 action = modal ? OBT_PROP_ATOM(NET_WM_STATE_REMOVE) :
3576 OBT_PROP_ATOM(NET_WM_STATE_ADD);
3577 else if (state == OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_VERT))
3578 action = self->max_vert ? OBT_PROP_ATOM(NET_WM_STATE_REMOVE) :
3579 OBT_PROP_ATOM(NET_WM_STATE_ADD);
3580 else if (state == OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_HORZ))
3581 action = self->max_horz ? OBT_PROP_ATOM(NET_WM_STATE_REMOVE) :
3582 OBT_PROP_ATOM(NET_WM_STATE_ADD);
3583 else if (state == OBT_PROP_ATOM(NET_WM_STATE_SHADED))
3584 action = shaded ? OBT_PROP_ATOM(NET_WM_STATE_REMOVE) :
3585 OBT_PROP_ATOM(NET_WM_STATE_ADD);
3586 else if (state == OBT_PROP_ATOM(NET_WM_STATE_SKIP_TASKBAR))
3587 action = self->skip_taskbar ?
3588 OBT_PROP_ATOM(NET_WM_STATE_REMOVE) :
3589 OBT_PROP_ATOM(NET_WM_STATE_ADD);
3590 else if (state == OBT_PROP_ATOM(NET_WM_STATE_SKIP_PAGER))
3591 action = self->skip_pager ?
3592 OBT_PROP_ATOM(NET_WM_STATE_REMOVE) :
3593 OBT_PROP_ATOM(NET_WM_STATE_ADD);
3594 else if (state == OBT_PROP_ATOM(NET_WM_STATE_HIDDEN))
3595 action = self->iconic ?
3596 OBT_PROP_ATOM(NET_WM_STATE_REMOVE) :
3597 OBT_PROP_ATOM(NET_WM_STATE_ADD);
3598 else if (state == OBT_PROP_ATOM(NET_WM_STATE_FULLSCREEN))
3599 action = fullscreen ?
3600 OBT_PROP_ATOM(NET_WM_STATE_REMOVE) :
3601 OBT_PROP_ATOM(NET_WM_STATE_ADD);
3602 else if (state == OBT_PROP_ATOM(NET_WM_STATE_ABOVE))
3603 action = self->above ? OBT_PROP_ATOM(NET_WM_STATE_REMOVE) :
3604 OBT_PROP_ATOM(NET_WM_STATE_ADD);
3605 else if (state == OBT_PROP_ATOM(NET_WM_STATE_BELOW))
3606 action = self->below ? OBT_PROP_ATOM(NET_WM_STATE_REMOVE) :
3607 OBT_PROP_ATOM(NET_WM_STATE_ADD);
3608 else if (state == OBT_PROP_ATOM(NET_WM_STATE_DEMANDS_ATTENTION))
3609 action = self->demands_attention ?
3610 OBT_PROP_ATOM(NET_WM_STATE_REMOVE) :
3611 OBT_PROP_ATOM(NET_WM_STATE_ADD);
3612 else if (state == OBT_PROP_ATOM(OB_WM_STATE_UNDECORATED))
3613 action = undecorated ? OBT_PROP_ATOM(NET_WM_STATE_REMOVE) :
3614 OBT_PROP_ATOM(NET_WM_STATE_ADD);
3617 if (action == OBT_PROP_ATOM(NET_WM_STATE_ADD)) {
3618 if (state == OBT_PROP_ATOM(NET_WM_STATE_MODAL)) {
3620 } else if (state == OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_VERT)) {
3622 } else if (state == OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_HORZ)) {
3624 } else if (state == OBT_PROP_ATOM(NET_WM_STATE_SHADED)) {
3626 } else if (state == OBT_PROP_ATOM(NET_WM_STATE_SKIP_TASKBAR)) {
3627 self->skip_taskbar = TRUE;
3628 } else if (state == OBT_PROP_ATOM(NET_WM_STATE_SKIP_PAGER)) {
3629 self->skip_pager = TRUE;
3630 } else if (state == OBT_PROP_ATOM(NET_WM_STATE_HIDDEN)) {
3632 } else if (state == OBT_PROP_ATOM(NET_WM_STATE_FULLSCREEN)) {
3634 } else if (state == OBT_PROP_ATOM(NET_WM_STATE_ABOVE)) {
3637 } else if (state == OBT_PROP_ATOM(NET_WM_STATE_BELOW)) {
3640 } else if (state == OBT_PROP_ATOM(NET_WM_STATE_DEMANDS_ATTENTION)){
3641 demands_attention = TRUE;
3642 } else if (state == OBT_PROP_ATOM(OB_WM_STATE_UNDECORATED)) {
3646 } else { /* action == OBT_PROP_ATOM(NET_WM_STATE_REMOVE) */
3647 if (state == OBT_PROP_ATOM(NET_WM_STATE_MODAL)) {
3649 } else if (state == OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_VERT)) {
3651 } else if (state == OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_HORZ)) {
3653 } else if (state == OBT_PROP_ATOM(NET_WM_STATE_SHADED)) {
3655 } else if (state == OBT_PROP_ATOM(NET_WM_STATE_SKIP_TASKBAR)) {
3656 self->skip_taskbar = FALSE;
3657 } else if (state == OBT_PROP_ATOM(NET_WM_STATE_SKIP_PAGER)) {
3658 self->skip_pager = FALSE;
3659 } else if (state == OBT_PROP_ATOM(NET_WM_STATE_HIDDEN)) {
3661 } else if (state == OBT_PROP_ATOM(NET_WM_STATE_FULLSCREEN)) {
3663 } else if (state == OBT_PROP_ATOM(NET_WM_STATE_ABOVE)) {
3665 } else if (state == OBT_PROP_ATOM(NET_WM_STATE_BELOW)) {
3667 } else if (state == OBT_PROP_ATOM(NET_WM_STATE_DEMANDS_ATTENTION)){
3668 demands_attention = FALSE;
3669 } else if (state == OBT_PROP_ATOM(OB_WM_STATE_UNDECORATED)) {
3670 undecorated = FALSE;
3675 if (max_horz != self->max_horz || max_vert != self->max_vert) {
3676 if (max_horz != self->max_horz && max_vert != self->max_vert) {
3678 if (max_horz == max_vert) { /* both going the same way */
3679 client_maximize(self, max_horz, 0);
3681 client_maximize(self, max_horz, 1);
3682 client_maximize(self, max_vert, 2);
3686 if (max_horz != self->max_horz)
3687 client_maximize(self, max_horz, 1);
3689 client_maximize(self, max_vert, 2);
3692 /* change fullscreen state before shading, as it will affect if the window
3694 if (fullscreen != self->fullscreen)
3695 client_fullscreen(self, fullscreen);
3696 if (shaded != self->shaded)
3697 client_shade(self, shaded);
3698 if (undecorated != self->undecorated)
3699 client_set_undecorated(self, undecorated);
3700 if (above != self->above || below != self->below) {
3701 self->above = above;
3702 self->below = below;
3703 client_calc_layer(self);
3706 if (modal != self->modal) {
3707 self->modal = modal;
3708 /* when a window changes modality, then its stacking order with its
3709 transients needs to change */
3710 stacking_raise(CLIENT_AS_WINDOW(self));
3712 /* it also may get focused. if something is focused that shouldn't
3713 be focused anymore, then move the focus */
3714 if (focus_client && client_focus_target(focus_client) != focus_client)
3715 client_focus(focus_client);
3718 if (iconic != self->iconic)
3719 client_iconify(self, iconic, FALSE, FALSE);
3721 if (demands_attention != self->demands_attention)
3722 client_hilite(self, demands_attention);
3724 client_change_state(self); /* change the hint to reflect these changes */
3727 ObClient *client_focus_target(ObClient *self)
3729 ObClient *child = NULL;
3731 child = client_search_modal_child(self);
3732 if (child) return child;
3736 gboolean client_can_focus(ObClient *self)
3738 /* choose the correct target */
3739 self = client_focus_target(self);
3741 if (!render_plugin->frame_is_visible(self->frame))
3744 if (!(self->can_focus || self->focus_notify))
3750 gboolean client_focus(ObClient *self)
3752 /* we might not focus this window, so if we have modal children which would
3753 be focused instead, bring them to this desktop */
3754 client_bring_modal_windows(self);
3756 /* choose the correct target */
3757 self = client_focus_target(self);
3759 if (!client_can_focus(self)) {
3760 ob_debug_type(OB_DEBUG_FOCUS,
3761 "Client %s can't be focused", self->title);
3765 ob_debug_type(OB_DEBUG_FOCUS,
3766 "Focusing client \"%s\" (0x%x) at time %u",
3767 self->title, self->window, event_curtime);
3769 /* if using focus_delay, stop the timer now so that focus doesn't
3771 event_halt_focus_delay();
3773 /* if there is a grab going on, then we need to cancel it. if we move
3774 focus during the grab, applications will get NotifyWhileGrabbed events
3777 actions should not rely on being able to move focus during an
3780 event_cancel_all_key_grabs();
3782 obt_display_ignore_errors(TRUE);
3784 if (self->can_focus) {
3785 /* This can cause a BadMatch error with CurrentTime, or if an app
3786 passed in a bad time for _NET_WM_ACTIVE_WINDOW. */
3787 XSetInputFocus(obt_display, self->window, RevertToPointerRoot,
3791 if (self->focus_notify) {
3793 ce.xclient.type = ClientMessage;
3794 ce.xclient.message_type = OBT_PROP_ATOM(WM_PROTOCOLS);
3795 ce.xclient.display = obt_display;
3796 ce.xclient.window = self->window;
3797 ce.xclient.format = 32;
3798 ce.xclient.data.l[0] = OBT_PROP_ATOM(WM_TAKE_FOCUS);
3799 ce.xclient.data.l[1] = event_curtime;
3800 ce.xclient.data.l[2] = 0l;
3801 ce.xclient.data.l[3] = 0l;
3802 ce.xclient.data.l[4] = 0l;
3803 XSendEvent(obt_display, self->window, FALSE, NoEventMask, &ce);
3806 obt_display_ignore_errors(FALSE);
3808 ob_debug_type(OB_DEBUG_FOCUS, "Error focusing? %d",
3809 obt_display_error_occured);
3810 return !obt_display_error_occured;
3813 static void client_present(ObClient *self, gboolean here, gboolean raise,
3816 if (client_normal(self) && screen_showing_desktop)
3817 screen_show_desktop(FALSE, self);
3819 client_iconify(self, FALSE, here, FALSE);
3820 if (self->desktop != DESKTOP_ALL &&
3821 self->desktop != screen_desktop)
3824 client_set_desktop(self, screen_desktop, FALSE, TRUE);
3826 screen_set_desktop(self->desktop, FALSE);
3827 } else if (!render_plugin->frame_is_visible(self->frame))
3828 /* if its not visible for other reasons, then don't mess
3831 if (self->shaded && unshade)
3832 client_shade(self, FALSE);
3834 stacking_raise(CLIENT_AS_WINDOW(self));
3839 void client_activate(ObClient *self, gboolean here, gboolean raise,
3840 gboolean unshade, gboolean user)
3842 client_present(self, here, raise, unshade);
3845 static void client_bring_windows_recursive(ObClient *self,
3853 for (it = self->transients; it; it = g_slist_next(it))
3854 client_bring_windows_recursive(it->data, desktop,
3855 helpers, modals, iconic);
3857 if (((helpers && client_helper(self)) ||
3858 (modals && self->modal)) &&
3859 ((self->desktop != desktop && self->desktop != DESKTOP_ALL) ||
3860 (iconic && self->iconic)))
3862 if (iconic && self->iconic)
3863 client_iconify(self, FALSE, TRUE, FALSE);
3865 client_set_desktop(self, desktop, FALSE, FALSE);
3869 void client_bring_helper_windows(ObClient *self)
3871 client_bring_windows_recursive(self, self->desktop, TRUE, FALSE, FALSE);
3874 void client_bring_modal_windows(ObClient *self)
3876 client_bring_windows_recursive(self, self->desktop, FALSE, TRUE, TRUE);
3879 gboolean client_focused(ObClient *self)
3881 return self == focus_client;
3884 static ObClientIcon* client_icon_recursive(ObClient *self, gint w, gint h)
3887 gulong min_diff, min_i;
3889 if (!self->nicons) {
3890 ObClientIcon *parent = NULL;
3893 for (it = self->parents; it; it = g_slist_next(it)) {
3894 ObClient *c = it->data;
3895 if ((parent = client_icon_recursive(c, w, h)))
3902 /* some kind of crappy approximation to find the icon closest in size to
3903 what we requested, but icons are generally all the same ratio as
3904 eachother so it's good enough. */
3906 min_diff = ABS(self->icons[0].width - w) + ABS(self->icons[0].height - h);
3909 for (i = 1; i < self->nicons; ++i) {
3912 diff = ABS(self->icons[i].width - w) + ABS(self->icons[i].height - h);
3913 if (diff < min_diff) {
3918 return &self->icons[min_i];
3921 const ObClientIcon* client_icon(ObClient *self, gint w, gint h)
3924 static ObClientIcon deficon;
3926 if (!(ret = client_icon_recursive(self, w, h))) {
3927 deficon.width = deficon.height = 48;
3928 deficon.data = ob_rr_theme->def_win_icon;
3934 void client_set_layer(ObClient *self, gint layer)
3938 self->above = FALSE;
3939 } else if (layer == 0) {
3940 self->below = self->above = FALSE;
3942 self->below = FALSE;
3945 client_calc_layer(self);
3946 client_change_state(self); /* reflect this in the state hints */
3949 void client_set_undecorated(ObClient *self, gboolean undecorated)
3951 if (self->undecorated != undecorated &&
3952 /* don't let it undecorate if the function is missing, but let
3954 (self->functions & OB_CLIENT_FUNC_UNDECORATE || !undecorated))
3956 self->undecorated = undecorated;
3957 client_setup_decor_and_functions(self, TRUE);
3958 client_change_state(self); /* reflect this in the state hints */
3962 guint client_monitor(ObClient *self)
3964 Rect area = render_plugin->frame_get_window_area(self->frame);
3965 return screen_find_monitor(&area);
3968 ObClient *client_direct_parent(ObClient *self)
3970 if (!self->parents) return NULL;
3971 if (self->transient_for_group) return NULL;
3972 return self->parents->data;
3975 ObClient *client_search_top_direct_parent(ObClient *self)
3978 while ((p = client_direct_parent(self))) self = p;
3982 static GSList *client_search_all_top_parents_internal(ObClient *self,
3984 ObStackingLayer layer)
3989 /* move up the direct transient chain as far as possible */
3990 while ((p = client_direct_parent(self)) &&
3991 (!bylayer || p->layer == layer))
3995 ret = g_slist_prepend(NULL, self);
3997 ret = g_slist_copy(self->parents);
4002 GSList *client_search_all_top_parents(ObClient *self)
4004 return client_search_all_top_parents_internal(self, FALSE, 0);
4007 GSList *client_search_all_top_parents_layer(ObClient *self)
4009 return client_search_all_top_parents_internal(self, TRUE, self->layer);
4012 ObClient *client_search_focus_parent(ObClient *self)
4016 for (it = self->parents; it; it = g_slist_next(it))
4017 if (client_focused(it->data)) return it->data;
4022 ObClient *client_search_parent(ObClient *self, ObClient *search)
4026 for (it = self->parents; it; it = g_slist_next(it))
4027 if (it->data == search) return search;
4032 ObClient *client_search_transient(ObClient *self, ObClient *search)
4036 for (sit = self->transients; sit; sit = g_slist_next(sit)) {
4037 if (sit->data == search)
4039 if (client_search_transient(sit->data, search))
4045 static void detect_edge(Rect area, ObDirection dir,
4046 gint my_head, gint my_size,
4047 gint my_edge_start, gint my_edge_size,
4048 gint *dest, gboolean *near_edge)
4050 gint edge_start, edge_size, head, tail;
4051 gboolean skip_head = FALSE, skip_tail = FALSE;
4054 case OB_DIRECTION_NORTH:
4055 case OB_DIRECTION_SOUTH:
4056 edge_start = area.x;
4057 edge_size = area.width;
4059 case OB_DIRECTION_EAST:
4060 case OB_DIRECTION_WEST:
4061 edge_start = area.y;
4062 edge_size = area.height;
4065 g_assert_not_reached();
4068 /* do we collide with this window? */
4069 if (!RANGES_INTERSECT(my_edge_start, my_edge_size,
4070 edge_start, edge_size))
4074 case OB_DIRECTION_NORTH:
4075 head = RECT_BOTTOM(area);
4076 tail = RECT_TOP(area);
4078 case OB_DIRECTION_SOUTH:
4079 head = RECT_TOP(area);
4080 tail = RECT_BOTTOM(area);
4082 case OB_DIRECTION_WEST:
4083 head = RECT_RIGHT(area);
4084 tail = RECT_LEFT(area);
4086 case OB_DIRECTION_EAST:
4087 head = RECT_LEFT(area);
4088 tail = RECT_RIGHT(area);
4091 g_assert_not_reached();
4094 case OB_DIRECTION_NORTH:
4095 case OB_DIRECTION_WEST:
4096 /* check if our window is past the head of this window */
4097 if (my_head <= head + 1)
4099 /* check if our window's tail is past the tail of this window */
4100 if (my_head + my_size - 1 <= tail)
4102 /* check if the head of this window is closer than the previously
4103 chosen edge (take into account that the previously chosen
4104 edge might have been a tail, not a head) */
4105 if (head + (*near_edge ? 0 : my_size) < *dest)
4107 /* check if the tail of this window is closer than the previously
4108 chosen edge (take into account that the previously chosen
4109 edge might have been a head, not a tail) */
4110 if (tail - (!*near_edge ? 0 : my_size) < *dest)
4113 case OB_DIRECTION_SOUTH:
4114 case OB_DIRECTION_EAST:
4115 /* check if our window is past the head of this window */
4116 if (my_head >= head - 1)
4118 /* check if our window's tail is past the tail of this window */
4119 if (my_head - my_size + 1 >= tail)
4121 /* check if the head of this window is closer than the previously
4122 chosen edge (take into account that the previously chosen
4123 edge might have been a tail, not a head) */
4124 if (head - (*near_edge ? 0 : my_size) > *dest)
4126 /* check if the tail of this window is closer than the previously
4127 chosen edge (take into account that the previously chosen
4128 edge might have been a head, not a tail) */
4129 if (tail + (!*near_edge ? 0 : my_size) > *dest)
4133 g_assert_not_reached();
4136 ob_debug("my head %d size %d", my_head, my_size);
4137 ob_debug("head %d tail %d deest %d", head, tail, *dest);
4139 ob_debug("using near edge %d", head);
4143 else if (!skip_tail) {
4144 ob_debug("using far edge %d", tail);
4150 void client_find_edge_directional(ObClient *self, ObDirection dir,
4151 gint my_head, gint my_size,
4152 gint my_edge_start, gint my_edge_size,
4153 gint *dest, gboolean *near_edge)
4160 Strut size = render_plugin->frame_get_size(self->frame);
4161 Rect area = render_plugin->frame_get_window_area(self->frame);
4163 a = screen_area(self->desktop, SCREEN_AREA_ALL_MONITORS,
4165 mon = screen_area(self->desktop, SCREEN_AREA_ONE_MONITOR,
4169 case OB_DIRECTION_NORTH:
4170 if (my_head >= RECT_TOP(*mon) + 1)
4171 edge = RECT_TOP(*mon) - 1;
4173 edge = RECT_TOP(*a) - 1;
4175 case OB_DIRECTION_SOUTH:
4176 if (my_head <= RECT_BOTTOM(*mon) - 1)
4177 edge = RECT_BOTTOM(*mon) + 1;
4179 edge = RECT_BOTTOM(*a) + 1;
4181 case OB_DIRECTION_EAST:
4182 if (my_head <= RECT_RIGHT(*mon) - 1)
4183 edge = RECT_RIGHT(*mon) + 1;
4185 edge = RECT_RIGHT(*a) + 1;
4187 case OB_DIRECTION_WEST:
4188 if (my_head >= RECT_LEFT(*mon) + 1)
4189 edge = RECT_LEFT(*mon) - 1;
4191 edge = RECT_LEFT(*a) - 1;
4194 g_assert_not_reached();
4196 /* default to the far edge, then narrow it down */
4200 for (it = client_list; it; it = g_list_next(it)) {
4201 ObClient *cur = it->data;
4203 /* skip windows to not bump into */
4208 if (self->desktop != cur->desktop && cur->desktop != DESKTOP_ALL &&
4209 cur->desktop != screen_desktop)
4212 ob_debug("trying window %s", cur->title);
4214 detect_edge(render_plugin->frame_get_window_area(cur->frame), dir, my_head, my_size, my_edge_start,
4215 my_edge_size, dest, near_edge);
4217 dock_get_area(&dock_area);
4218 detect_edge(dock_area, dir, my_head, my_size, my_edge_start,
4219 my_edge_size, dest, near_edge);
4224 void client_find_move_directional(ObClient *self, ObDirection dir,
4228 gint e, e_start, e_size;
4232 Rect area = render_plugin->frame_get_window_area(self->frame);
4235 case OB_DIRECTION_EAST:
4236 head = RECT_RIGHT(area);
4238 e_start = RECT_TOP(area);
4239 e_size = area.height;
4241 case OB_DIRECTION_WEST:
4242 head = RECT_LEFT(area);
4244 e_start = RECT_TOP(area);
4245 e_size = area.height;
4247 case OB_DIRECTION_NORTH:
4248 head = RECT_TOP(area);
4250 e_start = RECT_LEFT(area);
4251 e_size = area.width;
4253 case OB_DIRECTION_SOUTH:
4254 head = RECT_BOTTOM(area);
4256 e_start = RECT_LEFT(area);
4257 e_size = area.width;
4260 g_assert_not_reached();
4263 client_find_edge_directional(self, dir, head, size,
4264 e_start, e_size, &e, &near);
4268 case OB_DIRECTION_EAST:
4269 if (near) e -= area.width;
4273 case OB_DIRECTION_WEST:
4275 else e -= area.width;
4278 case OB_DIRECTION_NORTH:
4280 else e -= area.height;
4283 case OB_DIRECTION_SOUTH:
4284 if (near) e -= area.height;
4289 g_assert_not_reached();
4291 frame_frame_gravity(self, x, y);
4294 void client_find_resize_directional(ObClient *self, ObDirection side,
4296 gint *x, gint *y, gint *w, gint *h)
4299 gint e, e_start, e_size, delta;
4303 Rect area = render_plugin->frame_get_window_area(self->frame);
4304 Strut size = render_plugin->frame_get_size(self->frame);
4307 case OB_DIRECTION_EAST:
4308 head = RECT_RIGHT(area) +
4309 (self->size_inc.width - 1) * (grow ? 1 : -1);
4310 e_start = RECT_TOP(area);
4311 e_size = area.height;
4312 dir = grow ? OB_DIRECTION_EAST : OB_DIRECTION_WEST;
4314 case OB_DIRECTION_WEST:
4315 head = RECT_LEFT(area) -
4316 (self->size_inc.width - 1) * (grow ? 1 : -1);
4317 e_start = RECT_TOP(area);
4318 e_size = area.height;
4319 dir = grow ? OB_DIRECTION_WEST : OB_DIRECTION_EAST;
4321 case OB_DIRECTION_NORTH:
4322 head = RECT_TOP(area) -
4323 (self->size_inc.height - 1) * (grow ? 1 : -1);
4324 e_start = RECT_LEFT(area);
4325 e_size = area.width;
4326 dir = grow ? OB_DIRECTION_NORTH : OB_DIRECTION_SOUTH;
4328 case OB_DIRECTION_SOUTH:
4329 head = RECT_BOTTOM(area) +
4330 (self->size_inc.height - 1) * (grow ? 1 : -1);
4331 e_start = RECT_LEFT(area);
4332 e_size = area.width;
4333 dir = grow ? OB_DIRECTION_SOUTH : OB_DIRECTION_NORTH;
4336 g_assert_not_reached();
4339 ob_debug("head %d dir %d", head, dir);
4340 client_find_edge_directional(self, dir, head, 1,
4341 e_start, e_size, &e, &near);
4342 ob_debug("edge %d", e);
4348 case OB_DIRECTION_EAST:
4349 if (grow == near) --e;
4350 delta = e - RECT_RIGHT(area);
4353 case OB_DIRECTION_WEST:
4354 if (grow == near) ++e;
4355 delta = RECT_LEFT(area) - e;
4359 case OB_DIRECTION_NORTH:
4360 if (grow == near) ++e;
4361 delta = RECT_TOP(area) - e;
4365 case OB_DIRECTION_SOUTH:
4366 if (grow == near) --e;
4367 delta = e - RECT_BOTTOM(area);
4371 g_assert_not_reached();
4373 frame_frame_gravity(self, x, y);
4374 *w -= size.left + size.right;
4375 *h -= size.top + size.bottom;
4378 ObClient* client_under_pointer(void)
4382 ObClient *ret = NULL;
4384 if (screen_pointer_pos(&x, &y)) {
4385 for (it = stacking_list; it; it = g_list_next(it)) {
4386 if (WINDOW_IS_CLIENT(it->data)) {
4387 ObClient *c = WINDOW_AS_CLIENT(it->data);
4388 if (render_plugin->frame_is_visible(c->frame) &&
4389 /* check the desktop, this is done during desktop
4390 switching and windows are shown/hidden status is not
4392 (c->desktop == screen_desktop ||
4393 c->desktop == DESKTOP_ALL) &&
4394 /* ignore all animating windows */
4395 !(render_plugin->frame_iconify_animating(c->frame)) &&
4396 RECT_CONTAINS(render_plugin->frame_get_window_area(c->frame), x, y))
4407 gboolean client_has_group_siblings(ObClient *self)
4409 return self->group && self->group->members->next;