1 /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
3 client.c for the Openbox window manager
4 Copyright (c) 2006 Mikael Magnusson
5 Copyright (c) 2003-2007 Dana Jansens
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 See the COPYING file for a copy of the GNU General Public License.
22 #include "startupnotify.h"
25 #include "moveresize.h"
34 #include "focus_cycle.h"
40 #include "menuframe.h"
43 #include "render/render.h"
45 #include "obt/display.h"
53 # include <signal.h> /* for kill() */
57 #include <X11/Xutil.h>
59 /*! The event mask to grab on client windows */
60 #define CLIENT_EVENTMASK (PropertyChangeMask | StructureNotifyMask | \
63 #define CLIENT_NOPROPAGATEMASK (ButtonPressMask | ButtonReleaseMask | \
68 ObClientCallback func;
72 GList *client_list = NULL;
74 static GSList *client_destroy_notifies = NULL;
75 static RrImage *client_default_icon = NULL;
77 static void client_get_all(ObClient *self, gboolean real);
78 static void client_get_startup_id(ObClient *self);
79 static void client_get_session_ids(ObClient *self);
80 static void client_get_area(ObClient *self);
81 static void client_get_desktop(ObClient *self);
82 static void client_get_state(ObClient *self);
83 static void client_get_shaped(ObClient *self);
84 static void client_get_mwm_hints(ObClient *self);
85 static void client_get_colormap(ObClient *self);
86 static void client_set_desktop_recursive(ObClient *self,
90 static void client_change_allowed_actions(ObClient *self);
91 static void client_change_state(ObClient *self);
92 static void client_change_wm_state(ObClient *self);
93 static void client_apply_startup_state(ObClient *self,
94 gint x, gint y, gint w, gint h);
95 static void client_restore_session_state(ObClient *self);
96 static gboolean client_restore_session_stacking(ObClient *self);
97 static ObAppSettings *client_get_settings_state(ObClient *self);
98 static void client_update_transient_tree(ObClient *self,
99 ObGroup *oldgroup, ObGroup *newgroup,
100 gboolean oldgtran, gboolean newgtran,
102 ObClient *newparent);
103 static void client_present(ObClient *self, gboolean here, gboolean raise,
105 static GSList *client_search_all_top_parents_internal(ObClient *self,
107 ObStackingLayer layer);
108 static void client_call_notifies(ObClient *self, GSList *list);
109 static void client_ping_event(ObClient *self, gboolean dead);
110 static void client_prompt_kill(ObClient *self);
112 void client_startup(gboolean reconfig)
114 if ((client_default_icon = RrImageCacheFind(ob_rr_icons,
115 ob_rr_theme->def_win_icon,
116 ob_rr_theme->def_win_icon_w,
117 ob_rr_theme->def_win_icon_h)))
118 RrImageRef(client_default_icon);
120 client_default_icon = RrImageNew(ob_rr_icons);
121 RrImageAddPicture(client_default_icon,
122 ob_rr_theme->def_win_icon,
123 ob_rr_theme->def_win_icon_w,
124 ob_rr_theme->def_win_icon_h);
127 if (reconfig) return;
132 void client_shutdown(gboolean reconfig)
134 RrImageUnref(client_default_icon);
135 client_default_icon = NULL;
137 if (reconfig) return;
140 static void client_call_notifies(ObClient *self, GSList *list)
144 for (it = list; it; it = g_slist_next(it)) {
145 ClientCallback *d = it->data;
146 d->func(self, d->data);
150 void client_add_destroy_notify(ObClientCallback func, gpointer data)
152 ClientCallback *d = g_new(ClientCallback, 1);
155 client_destroy_notifies = g_slist_prepend(client_destroy_notifies, d);
158 void client_remove_destroy_notify(ObClientCallback func)
162 for (it = client_destroy_notifies; it; it = g_slist_next(it)) {
163 ClientCallback *d = it->data;
164 if (d->func == func) {
166 client_destroy_notifies =
167 g_slist_delete_link(client_destroy_notifies, it);
173 void client_set_list(void)
175 Window *windows, *win_it;
177 guint size = g_list_length(client_list);
179 /* create an array of the window ids */
181 windows = g_new(Window, size);
183 for (it = client_list; it; it = g_list_next(it), ++win_it)
184 *win_it = ((ObClient*)it->data)->window;
188 OBT_PROP_SETA32(obt_root(ob_screen), NET_CLIENT_LIST, WINDOW,
189 (gulong*)windows, size);
197 void client_manage(Window window, ObPrompt *prompt)
200 XSetWindowAttributes attrib_set;
201 gboolean activate = FALSE;
202 ObAppSettings *settings;
203 gboolean transient = FALSE;
204 Rect place, *monitor;
205 Time launch_time, map_time;
207 ob_debug("Managing window: 0x%lx", window);
209 map_time = event_get_server_time();
211 /* choose the events we want to receive on the CLIENT window
212 (ObPrompt windows can request events too) */
213 attrib_set.event_mask = CLIENT_EVENTMASK |
214 (prompt ? prompt->event_mask : 0);
215 attrib_set.do_not_propagate_mask = CLIENT_NOPROPAGATEMASK;
216 XChangeWindowAttributes(obt_display, window,
217 CWEventMask|CWDontPropagate, &attrib_set);
219 /* create the ObClient struct, and populate it from the hints on the
221 self = g_new0(ObClient, 1);
222 self->obwin.type = OB_WINDOW_CLASS_CLIENT;
223 self->window = window;
224 self->prompt = prompt;
226 /* non-zero defaults */
227 self->wmstate = WithdrawnState; /* make sure it gets updated first time */
228 self->gravity = NorthWestGravity;
229 self->desktop = screen_num_desktops; /* always an invalid value */
231 /* get all the stuff off the window */
232 client_get_all(self, TRUE);
234 ob_debug("Window type: %d", self->type);
235 ob_debug("Window group: 0x%x", self->group?self->group->leader:0);
237 /* now we have all of the window's information so we can set this up.
238 do this before creating the frame, so it can tell that we are still
239 mapping and doesn't go applying things right away */
240 client_setup_decor_and_functions(self, FALSE);
242 /* specify that if we exit, the window should not be destroyed and
243 should be reparented back to root automatically, unless we are managing
244 an internal ObPrompt window */
246 XChangeSaveSet(obt_display, window, SetModeInsert);
248 /* create the decoration frame for the client window */
249 self->frame = frame_new(self);
251 frame_grab_client(self->frame);
253 /* we've grabbed everything and set everything that we need to at mapping
257 /* per-app settings override stuff from client_get_all, and return the
258 settings for other uses too. the returned settings is a shallow copy,
259 that needs to be freed with g_free(). */
260 settings = client_get_settings_state(self);
261 /* the session should get the last say though */
262 client_restore_session_state(self);
264 /* tell startup notification that this app started */
265 launch_time = sn_app_started(self->startup_id, self->class, self->name);
267 /* do this after we have a frame.. it uses the frame to help determine the
268 WM_STATE to apply. */
269 client_change_state(self);
271 /* add ourselves to the focus order */
272 focus_order_add_new(self);
274 /* do this to add ourselves to the stacking list in a non-intrusive way */
275 client_calc_layer(self);
277 /* focus the new window? */
278 if (ob_state() != OB_STATE_STARTING &&
279 (!self->session || self->session->focused) &&
280 /* this means focus=true for window is same as config_focus_new=true */
281 ((config_focus_new || (settings && settings->focus == 1)) ||
282 client_search_focus_tree_full(self)) &&
283 /* this checks for focus=false for the window */
284 (!settings || settings->focus != 0) &&
285 focus_valid_target(self, FALSE, FALSE, TRUE, FALSE, FALSE) &&
286 (!focus_cycle_target || !config_focus_dontstop))
291 /* remove the client's border */
292 XSetWindowBorderWidth(obt_display, self->window, 0);
294 /* adjust the frame to the client's size before showing or placing
296 frame_adjust_area(self->frame, FALSE, TRUE, FALSE);
297 frame_adjust_client_area(self->frame);
299 /* where the frame was placed is where the window was originally */
301 monitor = screen_physical_area_monitor(screen_find_monitor(&place));
303 /* figure out placement for the window if the window is new */
304 if (ob_state() == OB_STATE_RUNNING) {
305 ob_debug("Positioned: %s @ %d %d",
306 (!self->positioned ? "no" :
307 (self->positioned == PPosition ? "program specified" :
308 (self->positioned == USPosition ? "user specified" :
309 (self->positioned == (PPosition | USPosition) ?
310 "program + user specified" :
311 "BADNESS !?")))), place.x, place.y);
313 ob_debug("Sized: %s @ %d %d",
314 (!self->sized ? "no" :
315 (self->sized == PSize ? "program specified" :
316 (self->sized == USSize ? "user specified" :
317 (self->sized == (PSize | USSize) ?
318 "program + user specified" :
319 "BADNESS !?")))), place.width, place.height);
321 /* splash screens are also returned as TRUE for transient,
322 and so will be forced on screen below */
323 transient = place_client(self, &place.x, &place.y, settings);
325 /* make sure the window is visible. */
326 client_find_onscreen(self, &place.x, &place.y,
327 place.width, place.height,
328 /* non-normal clients has less rules, and
329 windows that are being restored from a
330 session do also. we can assume you want
331 it back where you saved it. Clients saying
332 they placed themselves are subjected to
333 harder rules, ones that are placed by
334 place.c or by the user are allowed partially
335 off-screen and on xinerama divides (ie,
336 it is up to the placement routines to avoid
337 the xinerama divides)
339 splash screens get "transient" set to TRUE by
340 the place_client call
342 ob_state() == OB_STATE_RUNNING &&
344 (!((self->positioned & USPosition) ||
345 (settings && settings->pos_given)) &&
346 client_normal(self) &&
348 /* don't move oldschool fullscreen windows to
349 fit inside the struts (fixes Acroread, which
350 makes its fullscreen window fit the screen
351 but it is not USSize'd or USPosition'd) */
352 !(self->decorations == 0 &&
353 RECT_EQUAL(place, *monitor)))));
356 /* if the window isn't user-sized, then make it fit inside
357 the visible screen area on its monitor. Use basically the same rules
358 for forcing the window on screen in the client_find_onscreen call.
360 do this after place_client, it chooses the monitor!
362 splash screens get "transient" set to TRUE by
363 the place_client call
365 if (ob_state() == OB_STATE_RUNNING &&
367 (!(self->sized & USSize || self->positioned & USPosition) &&
368 client_normal(self) &&
370 /* don't shrink oldschool fullscreen windows to fit inside the
371 struts (fixes Acroread, which makes its fullscreen window
372 fit the screen but it is not USSize'd or USPosition'd) */
373 !(self->decorations == 0 && RECT_EQUAL(place, *monitor)))))
375 Rect *a = screen_area(self->desktop, SCREEN_AREA_ONE_MONITOR, &place);
377 /* get the size of the frame */
378 place.width += self->frame->size.left + self->frame->size.right;
379 place.height += self->frame->size.top + self->frame->size.bottom;
381 /* fit the window inside the area */
382 place.width = MIN(place.width, a->width);
383 place.height = MIN(place.height, a->height);
385 ob_debug("setting window size to %dx%d", place.width, place.height);
387 /* get the size of the client back */
388 place.width -= self->frame->size.left + self->frame->size.right;
389 place.height -= self->frame->size.top + self->frame->size.bottom;
394 ob_debug("placing window 0x%x at %d, %d with size %d x %d. "
395 "some restrictions may apply",
396 self->window, place.x, place.y, place.width, place.height);
398 ob_debug(" but session requested %d, %d %d x %d instead, "
400 self->session->x, self->session->y,
401 self->session->w, self->session->h);
403 /* do this after the window is placed, so the premax/prefullscreen numbers
406 this also places the window
408 client_apply_startup_state(self, place.x, place.y,
409 place.width, place.height);
414 ob_debug_type(OB_DEBUG_FOCUS, "Going to try activate new window? %s",
415 activate ? "yes" : "no");
417 gboolean raise = FALSE;
418 gboolean relative_focused = FALSE;
420 relative_focused = (focus_client != NULL &&
421 client_search_focus_tree_full(self) != NULL &&
422 client_search_focus_group_full(self) != NULL);
424 /* This is focus stealing prevention */
425 ob_debug_type(OB_DEBUG_FOCUS,
426 "Want to focus new window 0x%x at time %u "
427 "launched at %u (last user interaction time %u)",
428 self->window, map_time, launch_time,
429 event_last_user_time);
431 /* if it's on another desktop */
432 if (!(self->desktop == screen_desktop ||
433 self->desktop == DESKTOP_ALL) &&
434 /* the timestamp is from before you changed desktops */
435 launch_time && screen_desktop_user_time &&
436 !event_time_after(launch_time, screen_desktop_user_time))
440 ob_debug_type(OB_DEBUG_FOCUS,
441 "Not focusing the window because its on another "
444 /* If something is focused... */
445 else if (focus_client) {
446 /* If the user is working in another window right now, then don't
448 if (event_last_user_time && launch_time &&
449 event_time_after(event_last_user_time, launch_time) &&
450 event_last_user_time != launch_time &&
451 event_time_after(event_last_user_time,
452 map_time - OB_EVENT_USER_TIME_DELAY))
455 ob_debug_type(OB_DEBUG_FOCUS,
456 "Not focusing the window because the user is "
457 "working in another window");
459 /* If the new window is a transient (and its relatives aren't
461 else if (client_has_parent(self) && !relative_focused) {
463 ob_debug_type(OB_DEBUG_FOCUS,
464 "Not focusing the window because it is a "
465 "transient, and its relatives aren't focused");
467 /* Don't steal focus from globally active clients.
468 I stole this idea from KWin. It seems nice.
470 else if (!(focus_client->can_focus ||
471 focus_client->focus_notify))
474 ob_debug_type(OB_DEBUG_FOCUS,
475 "Not focusing the window because a globally "
476 "active client has focus");
478 /* Don't move focus if it's not going to go to this window
480 else if (client_focus_target(self) != self) {
483 ob_debug_type(OB_DEBUG_FOCUS,
484 "Not focusing the window because another window "
485 "would get the focus anyway");
487 /* Don't move focus if the window is not visible on the current
488 desktop and none of its relatives are focused */
489 else if (!(self->desktop == screen_desktop ||
490 self->desktop == DESKTOP_ALL) &&
495 ob_debug_type(OB_DEBUG_FOCUS,
496 "Not focusing the window because it is on "
497 "another desktop and no relatives are focused ");
502 ob_debug_type(OB_DEBUG_FOCUS,
503 "Focus stealing prevention activated for %s at "
504 "time %u (last user interaction time %u)",
505 self->title, map_time, event_last_user_time);
506 /* if the client isn't focused, then hilite it so the user
508 client_hilite(self, TRUE);
509 /* we may want to raise it even tho we're not activating it */
510 if (raise && !client_restore_session_stacking(self))
511 stacking_raise(CLIENT_AS_WINDOW(self));
515 /* This may look rather odd. Well it's because new windows are added
516 to the stacking order non-intrusively. If we're not going to focus
517 the new window or hilite it, then we raise it to the top. This will
518 take affect for things that don't get focused like splash screens.
519 Also if you don't have focus_new enabled, then it's going to get
520 raised to the top. Legacy begets legacy I guess?
522 if (!client_restore_session_stacking(self))
523 stacking_raise(CLIENT_AS_WINDOW(self));
526 mouse_grab_for_client(self, TRUE);
528 /* this has to happen before we try focus the window, but we want it to
529 happen after the client's stacking has been determined or it looks bad
533 if (!config_focus_under_mouse)
534 ignore_start = event_start_ignore_all_enters();
538 if (!config_focus_under_mouse)
539 event_end_ignore_all_enters(ignore_start);
543 gboolean stacked = client_restore_session_stacking(self);
544 client_present(self, FALSE, !stacked, TRUE);
547 /* add to client list/map */
548 client_list = g_list_append(client_list, self);
549 window_add(&self->window, CLIENT_AS_WINDOW(self));
551 /* this has to happen after we're in the client_list */
552 if (STRUT_EXISTS(self->strut))
553 screen_update_areas();
555 /* update the list hints */
558 /* free the ObAppSettings shallow copy */
561 ob_debug("Managed window 0x%lx plate 0x%x (%s)",
562 window, self->frame->window, self->class);
564 hooks_queue(OB_HOOK_WIN_NEW, self);
567 ObClient *client_fake_manage(Window window)
570 ObAppSettings *settings;
572 ob_debug("Pretend-managing window: %lx", window);
574 /* do this minimal stuff to figure out the client's decorations */
576 self = g_new0(ObClient, 1);
577 self->window = window;
579 client_get_all(self, FALSE);
580 /* per-app settings override stuff, and return the settings for other
581 uses too. this returns a shallow copy that needs to be freed */
582 settings = client_get_settings_state(self);
584 client_setup_decor_and_functions(self, FALSE);
586 /* create the decoration frame for the client window and adjust its size */
587 self->frame = frame_new(self);
588 frame_adjust_area(self->frame, FALSE, TRUE, TRUE);
590 ob_debug("gave extents left %d right %d top %d bottom %d",
591 self->frame->size.left, self->frame->size.right,
592 self->frame->size.top, self->frame->size.bottom);
594 /* free the ObAppSettings shallow copy */
600 void client_unmanage_all(void)
603 client_unmanage(client_list->data);
606 void client_unmanage(ObClient *self)
611 ob_debug("Unmanaging window: 0x%x plate 0x%x (%s) (%s)",
612 self->window, self->frame->window,
613 self->class, self->title ? self->title : "");
615 g_assert(self != NULL);
617 /* we dont want events no more. do this before hiding the frame so we
618 don't generate more events */
619 XSelectInput(obt_display, self->window, NoEventMask);
621 /* ignore enter events from the unmap so it doesnt mess with the focus */
622 if (!config_focus_under_mouse)
623 ignore_start = event_start_ignore_all_enters();
625 frame_hide(self->frame);
626 /* flush to send the hide to the server quickly */
629 if (!config_focus_under_mouse)
630 event_end_ignore_all_enters(ignore_start);
632 mouse_grab_for_client(self, FALSE);
634 /* remove the window from our save set, unless we are managing an internal
637 XChangeSaveSet(obt_display, self->window, SetModeDelete);
639 /* this can't be queued to run later */
640 hooks_run(OB_HOOK_WIN_CLOSE, self);
642 /* update the focus lists */
643 focus_order_remove(self);
644 if (client_focused(self)) {
645 /* don't leave an invalid focus_client */
649 /* if we're prompting to kill the client, close that */
650 prompt_unref(self->kill_prompt);
651 self->kill_prompt = NULL;
653 client_list = g_list_remove(client_list, self);
654 stacking_remove(self);
655 window_remove(self->window);
657 /* once the client is out of the list, update the struts to remove its
659 if (STRUT_EXISTS(self->strut))
660 screen_update_areas();
662 client_call_notifies(self, client_destroy_notifies);
664 /* tell our parent(s) that we're gone */
665 for (it = self->parents; it; it = g_slist_next(it))
666 ((ObClient*)it->data)->transients =
667 g_slist_remove(((ObClient*)it->data)->transients,self);
669 /* tell our transients that we're gone */
670 for (it = self->transients; it; it = g_slist_next(it)) {
671 ((ObClient*)it->data)->parents =
672 g_slist_remove(((ObClient*)it->data)->parents, self);
673 /* we could be keeping our children in a higher layer */
674 client_calc_layer(it->data);
677 /* remove from its group */
679 group_remove(self->group, self);
683 /* restore the window's original geometry so it is not lost */
689 if (self->fullscreen)
690 a = self->pre_fullscreen_area;
691 else if (self->max_horz || self->max_vert) {
692 if (self->max_horz) {
693 a.x = self->pre_max_area.x;
694 a.width = self->pre_max_area.width;
696 if (self->max_vert) {
697 a.y = self->pre_max_area.y;
698 a.height = self->pre_max_area.height;
702 self->fullscreen = self->max_horz = self->max_vert = FALSE;
703 /* let it be moved and resized no matter what */
704 self->functions = OB_CLIENT_FUNC_MOVE | OB_CLIENT_FUNC_RESIZE;
705 self->decorations = 0; /* unmanaged windows have no decor */
707 /* give the client its border back */
708 XSetWindowBorderWidth(obt_display, self->window, self->border_width);
710 client_move_resize(self, a.x, a.y, a.width, a.height);
713 /* reparent the window out of the frame, and free the frame */
714 frame_release_client(self->frame);
715 frame_free(self->frame);
718 if (ob_state() != OB_STATE_EXITING) {
719 /* these values should not be persisted across a window
721 OBT_PROP_ERASE(self->window, NET_WM_DESKTOP);
722 OBT_PROP_ERASE(self->window, NET_WM_STATE);
723 OBT_PROP_ERASE(self->window, WM_STATE);
725 /* if we're left in an unmapped state, the client wont be mapped.
726 this is bad, since we will no longer be managing the window on
728 XMapWindow(obt_display, self->window);
731 /* these should not be left on the window ever. other window managers
732 don't necessarily use them and it will mess them up (like compiz) */
733 OBT_PROP_ERASE(self->window, NET_WM_VISIBLE_NAME);
734 OBT_PROP_ERASE(self->window, NET_WM_VISIBLE_ICON_NAME);
736 /* update the list hints */
739 ob_debug("Unmanaged window 0x%lx", self->window);
741 /* free all data allocated in the client struct */
742 RrImageUnref(self->icon_set);
743 g_slist_free(self->transients);
744 g_free(self->startup_id);
745 g_free(self->wm_command);
747 g_free(self->icon_title);
748 g_free(self->original_title);
752 g_free(self->client_machine);
753 g_free(self->sm_client_id);
757 void client_fake_unmanage(ObClient *self)
759 /* this is all that got allocated to get the decorations */
761 frame_free(self->frame);
765 /*! Returns a new structure containing the per-app settings for this client.
766 The returned structure needs to be freed with g_free. */
767 static ObAppSettings *client_get_settings_state(ObClient *self)
769 ObAppSettings *settings;
772 settings = config_create_app_settings();
774 for (it = config_per_app_settings; it; it = g_slist_next(it)) {
775 ObAppSettings *app = it->data;
776 gboolean match = TRUE;
778 g_assert(app->name != NULL || app->class != NULL);
780 /* we know that either name or class is not NULL so it will have to
781 match to use the rule */
783 !g_pattern_match(app->name, strlen(self->name), self->name, NULL))
785 else if (app->class &&
786 !g_pattern_match(app->class,
787 strlen(self->class), self->class, NULL))
789 else if (app->role &&
790 !g_pattern_match(app->role,
791 strlen(self->role), self->role, NULL))
793 else if ((signed)app->type >= 0 && app->type != self->type)
797 ob_debug("Window matching: %s", app->name);
799 /* copy the settings to our struct, overriding the existing
800 settings if they are not defaults */
801 config_app_settings_copy_non_defaults(app, settings);
805 if (settings->shade != -1)
806 self->shaded = !!settings->shade;
807 if (settings->decor != -1)
808 self->undecorated = !settings->decor;
809 if (settings->iconic != -1)
810 self->iconic = !!settings->iconic;
811 if (settings->skip_pager != -1)
812 self->skip_pager = !!settings->skip_pager;
813 if (settings->skip_taskbar != -1)
814 self->skip_taskbar = !!settings->skip_taskbar;
816 if (settings->max_vert != -1)
817 self->max_vert = !!settings->max_vert;
818 if (settings->max_horz != -1)
819 self->max_horz = !!settings->max_horz;
821 if (settings->fullscreen != -1)
822 self->fullscreen = !!settings->fullscreen;
824 if (settings->desktop) {
825 if (settings->desktop == DESKTOP_ALL)
826 self->desktop = settings->desktop;
827 else if (settings->desktop > 0 &&
828 settings->desktop <= screen_num_desktops)
829 self->desktop = settings->desktop - 1;
832 if (settings->layer == -1) {
836 else if (settings->layer == 0) {
840 else if (settings->layer == 1) {
847 static void client_restore_session_state(ObClient *self)
851 ob_debug_type(OB_DEBUG_SM,
852 "Restore session for client %s", self->title);
854 if (!(it = session_state_find(self))) {
855 ob_debug_type(OB_DEBUG_SM,
856 "Session data not found for client %s", self->title);
860 self->session = it->data;
862 ob_debug_type(OB_DEBUG_SM, "Session data loaded for client %s",
865 RECT_SET_POINT(self->area, self->session->x, self->session->y);
866 self->positioned = USPosition;
867 self->sized = USSize;
868 if (self->session->w > 0)
869 self->area.width = self->session->w;
870 if (self->session->h > 0)
871 self->area.height = self->session->h;
872 XResizeWindow(obt_display, self->window,
873 self->area.width, self->area.height);
875 self->desktop = (self->session->desktop == DESKTOP_ALL ?
876 self->session->desktop :
877 MIN(screen_num_desktops - 1, self->session->desktop));
878 OBT_PROP_SET32(self->window, NET_WM_DESKTOP, CARDINAL, self->desktop);
880 self->shaded = self->session->shaded;
881 self->iconic = self->session->iconic;
882 self->skip_pager = self->session->skip_pager;
883 self->skip_taskbar = self->session->skip_taskbar;
884 self->fullscreen = self->session->fullscreen;
885 self->above = self->session->above;
886 self->below = self->session->below;
887 self->max_horz = self->session->max_horz;
888 self->max_vert = self->session->max_vert;
889 self->undecorated = self->session->undecorated;
892 static gboolean client_restore_session_stacking(ObClient *self)
896 if (!self->session) return FALSE;
898 mypos = g_list_find(session_saved_state, self->session);
899 if (!mypos) return FALSE;
901 /* start above me and look for the first client */
902 for (it = g_list_previous(mypos); it; it = g_list_previous(it)) {
905 for (cit = client_list; cit; cit = g_list_next(cit)) {
906 ObClient *c = cit->data;
907 /* found a client that was in the session, so go below it */
908 if (c->session == it->data) {
909 stacking_below(CLIENT_AS_WINDOW(self),
910 CLIENT_AS_WINDOW(cit->data));
918 void client_move_onscreen(ObClient *self, gboolean rude)
920 gint x = self->area.x;
921 gint y = self->area.y;
922 if (client_find_onscreen(self, &x, &y,
924 self->area.height, rude)) {
925 client_move(self, x, y);
929 gboolean client_find_onscreen(ObClient *self, gint *x, gint *y, gint w, gint h,
932 gint ox = *x, oy = *y;
933 gboolean rudel = rude, ruder = rude, rudet = rude, rudeb = rude;
939 RECT_SET(desired, *x, *y, w, h);
940 frame_rect_to_frame(self->frame, &desired);
942 /* get where the frame would be */
943 frame_client_gravity(self->frame, x, y);
945 /* get the requested size of the window with decorations */
946 fw = self->frame->size.left + w + self->frame->size.right;
947 fh = self->frame->size.top + h + self->frame->size.bottom;
949 /* If rudeness wasn't requested, then still be rude in a given direction
950 if the client is not moving, only resizing in that direction */
952 Point oldtl, oldtr, oldbl, oldbr;
953 Point newtl, newtr, newbl, newbr;
954 gboolean stationary_l, stationary_r, stationary_t, stationary_b;
956 POINT_SET(oldtl, self->frame->area.x, self->frame->area.y);
957 POINT_SET(oldbr, self->frame->area.x + self->frame->area.width - 1,
958 self->frame->area.y + self->frame->area.height - 1);
959 POINT_SET(oldtr, oldbr.x, oldtl.y);
960 POINT_SET(oldbl, oldtl.x, oldbr.y);
962 POINT_SET(newtl, *x, *y);
963 POINT_SET(newbr, *x + fw - 1, *y + fh - 1);
964 POINT_SET(newtr, newbr.x, newtl.y);
965 POINT_SET(newbl, newtl.x, newbr.y);
967 /* is it moving or just resizing from some corner? */
968 stationary_l = oldtl.x == newtl.x;
969 stationary_r = oldtr.x == newtr.x;
970 stationary_t = oldtl.y == newtl.y;
971 stationary_b = oldbl.y == newbl.y;
973 /* if left edge is growing and didnt move right edge */
974 if (stationary_r && newtl.x < oldtl.x)
976 /* if right edge is growing and didnt move left edge */
977 if (stationary_l && newtr.x > oldtr.x)
979 /* if top edge is growing and didnt move bottom edge */
980 if (stationary_b && newtl.y < oldtl.y)
982 /* if bottom edge is growing and didnt move top edge */
983 if (stationary_t && newbl.y > oldbl.y)
987 /* we iterate through every monitor that the window is at least partially
988 on, to make sure it is obeying the rules on them all
990 if the window does not appear on any monitors, then use the first one
993 for (i = 0; i < screen_num_monitors; ++i) {
996 if (!screen_physical_area_monitor_contains(i, &desired)) {
997 if (i < screen_num_monitors - 1 || found_mon)
1000 /* the window is not inside any monitor! so just use the first
1002 a = screen_area(self->desktop, 0, NULL);
1005 a = screen_area(self->desktop, SCREEN_AREA_ONE_MONITOR, &desired);
1008 /* This makes sure windows aren't entirely outside of the screen so you
1009 can't see them at all.
1010 It makes sure 10% of the window is on the screen at least. And don't
1011 let it move itself off the top of the screen, which would hide the
1012 titlebar on you. (The user can still do this if they want too, it's
1013 only limiting the application.
1015 if (client_normal(self)) {
1016 if (!self->strut.right && *x + fw/10 >= a->x + a->width - 1)
1017 *x = a->x + a->width - fw/10;
1018 if (!self->strut.bottom && *y + fh/10 >= a->y + a->height - 1)
1019 *y = a->y + a->height - fh/10;
1020 if (!self->strut.left && *x + fw*9/10 - 1 < a->x)
1021 *x = a->x - fw*9/10;
1022 if (!self->strut.top && *y + fh*9/10 - 1 < a->y)
1023 *y = a->y - fh*9/10;
1026 /* This here doesn't let windows even a pixel outside the
1027 struts/screen. When called from client_manage, programs placing
1028 themselves are forced completely onscreen, while things like
1029 xterm -geometry resolution-width/2 will work fine. Trying to
1030 place it completely offscreen will be handled in the above code.
1031 Sorry for this confused comment, i am tired. */
1032 if (rudel && !self->strut.left && *x < a->x) *x = a->x;
1033 if (ruder && !self->strut.right && *x + fw > a->x + a->width)
1034 *x = a->x + MAX(0, a->width - fw);
1036 if (rudet && !self->strut.top && *y < a->y) *y = a->y;
1037 if (rudeb && !self->strut.bottom && *y + fh > a->y + a->height)
1038 *y = a->y + MAX(0, a->height - fh);
1043 /* get where the client should be */
1044 frame_frame_gravity(self->frame, x, y);
1046 return ox != *x || oy != *y;
1049 static void client_get_all(ObClient *self, gboolean real)
1051 /* this is needed for the frame to set itself up */
1052 client_get_area(self);
1054 /* these things can change the decor and functions of the window */
1056 client_get_mwm_hints(self);
1057 /* this can change the mwmhints for special cases */
1058 client_get_type_and_transientness(self);
1059 client_get_state(self);
1060 client_update_normal_hints(self);
1062 /* get the session related properties, these can change decorations
1063 from per-app settings */
1064 client_get_session_ids(self);
1066 /* now we got everything that can affect the decorations */
1070 /* get this early so we have it for debugging */
1071 client_update_title(self);
1073 client_update_protocols(self);
1075 client_update_wmhints(self);
1076 /* this may have already been called from client_update_wmhints */
1077 if (!self->parents && !self->transient_for_group)
1078 client_update_transient_for(self);
1080 client_get_startup_id(self);
1081 client_get_desktop(self);/* uses transient data/group/startup id if a
1082 desktop is not specified */
1083 client_get_shaped(self);
1086 /* a couple type-based defaults for new windows */
1088 /* this makes sure that these windows appear on all desktops */
1089 if (self->type == OB_CLIENT_TYPE_DESKTOP)
1090 self->desktop = DESKTOP_ALL;
1094 client_update_sync_request_counter(self);
1097 client_get_colormap(self);
1098 client_update_strut(self);
1099 client_update_icons(self);
1100 client_update_icon_geometry(self);
1103 static void client_get_startup_id(ObClient *self)
1105 if (!(OBT_PROP_GETS(self->window, NET_STARTUP_ID, utf8,
1106 &self->startup_id)))
1108 OBT_PROP_GETS(self->group->leader,
1109 NET_STARTUP_ID, utf8, &self->startup_id);
1112 static void client_get_area(ObClient *self)
1114 XWindowAttributes wattrib;
1117 ret = XGetWindowAttributes(obt_display, self->window, &wattrib);
1118 g_assert(ret != BadWindow);
1120 RECT_SET(self->area, wattrib.x, wattrib.y, wattrib.width, wattrib.height);
1121 POINT_SET(self->root_pos, wattrib.x, wattrib.y);
1122 self->border_width = wattrib.border_width;
1124 ob_debug("client area: %d %d %d %d bw %d", wattrib.x, wattrib.y,
1125 wattrib.width, wattrib.height, wattrib.border_width);
1128 static void client_get_desktop(ObClient *self)
1130 guint32 d = screen_num_desktops; /* an always-invalid value */
1132 if (OBT_PROP_GET32(self->window, NET_WM_DESKTOP, CARDINAL, &d)) {
1133 if (d >= screen_num_desktops && d != DESKTOP_ALL)
1134 self->desktop = screen_num_desktops - 1;
1137 ob_debug("client requested desktop 0x%x", self->desktop);
1140 gboolean first = TRUE;
1141 guint all = screen_num_desktops; /* not a valid value */
1143 /* if they are all on one desktop, then open it on the
1145 for (it = self->parents; it; it = g_slist_next(it)) {
1146 ObClient *c = it->data;
1148 if (c->desktop == DESKTOP_ALL) continue;
1154 else if (all != c->desktop)
1155 all = screen_num_desktops; /* make it invalid */
1157 if (all != screen_num_desktops) {
1158 self->desktop = all;
1160 ob_debug("client desktop set from parents: 0x%x",
1163 /* try get from the startup-notification protocol */
1164 else if (sn_get_desktop(self->startup_id, &self->desktop)) {
1165 if (self->desktop >= screen_num_desktops &&
1166 self->desktop != DESKTOP_ALL)
1167 self->desktop = screen_num_desktops - 1;
1168 ob_debug("client desktop set from startup-notification: 0x%x",
1171 /* defaults to the current desktop */
1173 self->desktop = screen_desktop;
1174 ob_debug("client desktop set to the current desktop: %d",
1180 static void client_get_state(ObClient *self)
1185 if (OBT_PROP_GETA32(self->window, NET_WM_STATE, ATOM, &state, &num)) {
1187 for (i = 0; i < num; ++i) {
1188 if (state[i] == OBT_PROP_ATOM(NET_WM_STATE_MODAL))
1190 else if (state[i] == OBT_PROP_ATOM(NET_WM_STATE_SHADED))
1191 self->shaded = TRUE;
1192 else if (state[i] == OBT_PROP_ATOM(NET_WM_STATE_HIDDEN))
1193 self->iconic = TRUE;
1194 else if (state[i] == OBT_PROP_ATOM(NET_WM_STATE_SKIP_TASKBAR))
1195 self->skip_taskbar = TRUE;
1196 else if (state[i] == OBT_PROP_ATOM(NET_WM_STATE_SKIP_PAGER))
1197 self->skip_pager = TRUE;
1198 else if (state[i] == OBT_PROP_ATOM(NET_WM_STATE_FULLSCREEN))
1199 self->fullscreen = TRUE;
1200 else if (state[i] == OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_VERT))
1201 self->max_vert = TRUE;
1202 else if (state[i] == OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_HORZ))
1203 self->max_horz = TRUE;
1204 else if (state[i] == OBT_PROP_ATOM(NET_WM_STATE_ABOVE))
1206 else if (state[i] == OBT_PROP_ATOM(NET_WM_STATE_BELOW))
1208 else if (state[i] == OBT_PROP_ATOM(NET_WM_STATE_DEMANDS_ATTENTION))
1209 self->demands_attention = TRUE;
1210 else if (state[i] == OBT_PROP_ATOM(OB_WM_STATE_UNDECORATED))
1211 self->undecorated = TRUE;
1212 else if (state[i] == OBT_PROP_ATOM(OB_WM_STATE_LOCKED))
1213 self->locked = TRUE;
1220 static void client_get_shaped(ObClient *self)
1222 self->shaped = FALSE;
1224 if (obt_display_extension_shape) {
1229 XShapeSelectInput(obt_display, self->window, ShapeNotifyMask);
1231 XShapeQueryExtents(obt_display, self->window, &s, &foo,
1232 &foo, &ufoo, &ufoo, &foo, &foo, &foo, &ufoo,
1239 void client_update_transient_for(ObClient *self)
1242 ObClient *target = NULL;
1243 gboolean trangroup = FALSE;
1245 if (XGetTransientForHint(obt_display, self->window, &t)) {
1246 if (t != self->window) { /* can't be transient to itself! */
1247 ObWindow *tw = window_find(t);
1248 /* if this happens then we need to check for it */
1249 g_assert(tw != CLIENT_AS_WINDOW(self));
1250 if (tw && WINDOW_IS_CLIENT(tw)) {
1251 /* watch out for windows with a parent that is something
1252 different, like a dockapp for example */
1253 target = WINDOW_AS_CLIENT(tw);
1257 /* Setting the transient_for to Root is actually illegal, however
1258 applications from time have done this to specify transient for
1260 if (!target && self->group && t == obt_root(ob_screen))
1262 } else if (self->group && self->transient)
1265 client_update_transient_tree(self, self->group, self->group,
1266 self->transient_for_group, trangroup,
1267 client_direct_parent(self), target);
1268 self->transient_for_group = trangroup;
1272 static void client_update_transient_tree(ObClient *self,
1273 ObGroup *oldgroup, ObGroup *newgroup,
1274 gboolean oldgtran, gboolean newgtran,
1275 ObClient* oldparent,
1276 ObClient *newparent)
1281 g_assert(!oldgtran || oldgroup);
1282 g_assert(!newgtran || newgroup);
1283 g_assert((!oldgtran && !oldparent) ||
1284 (oldgtran && !oldparent) ||
1285 (!oldgtran && oldparent));
1286 g_assert((!newgtran && !newparent) ||
1287 (newgtran && !newparent) ||
1288 (!newgtran && newparent));
1291 Group transient windows are not allowed to have other group
1292 transient windows as their children.
1295 /* No change has occured */
1296 if (oldgroup == newgroup &&
1297 oldgtran == newgtran &&
1298 oldparent == newparent) return;
1300 /** Remove the client from the transient tree **/
1302 for (it = self->transients; it; it = next) {
1303 next = g_slist_next(it);
1305 self->transients = g_slist_delete_link(self->transients, it);
1306 c->parents = g_slist_remove(c->parents, self);
1308 for (it = self->parents; it; it = next) {
1309 next = g_slist_next(it);
1311 self->parents = g_slist_delete_link(self->parents, it);
1312 c->transients = g_slist_remove(c->transients, self);
1315 /** Re-add the client to the transient tree **/
1317 /* If we're transient for a group then we need to add ourselves to all our
1320 for (it = newgroup->members; it; it = g_slist_next(it)) {
1323 !client_search_top_direct_parent(c)->transient_for_group &&
1326 c->transients = g_slist_prepend(c->transients, self);
1327 self->parents = g_slist_prepend(self->parents, c);
1332 /* If we are now transient for a single window we need to add ourselves to
1335 WARNING: Cyclical transient-ness is possible if two windows are
1336 transient for eachother.
1338 else if (newparent &&
1339 /* don't make ourself its child if it is already our child */
1340 !client_is_direct_child(self, newparent) &&
1341 client_normal(newparent))
1343 newparent->transients = g_slist_prepend(newparent->transients, self);
1344 self->parents = g_slist_prepend(self->parents, newparent);
1347 /* Add any group transient windows to our children. But if we're transient
1348 for the group, then other group transients are not our children.
1350 WARNING: Cyclical transient-ness is possible. For e.g. if:
1351 A is transient for the group
1352 B is transient for A
1353 C is transient for B
1354 A can't be transient for C or we have a cycle
1356 if (!newgtran && newgroup &&
1358 !client_search_top_direct_parent(newparent)->transient_for_group) &&
1359 client_normal(self))
1361 for (it = newgroup->members; it; it = g_slist_next(it)) {
1363 if (c != self && c->transient_for_group &&
1364 /* Don't make it our child if it is already our parent */
1365 !client_is_direct_child(c, self))
1367 self->transients = g_slist_prepend(self->transients, c);
1368 c->parents = g_slist_prepend(c->parents, self);
1373 /** If we change our group transient-ness, our children change their
1374 effective group transient-ness, which affects how they relate to other
1377 for (it = self->transients; it; it = g_slist_next(it)) {
1379 if (!c->transient_for_group)
1380 client_update_transient_tree(c, c->group, c->group,
1381 c->transient_for_group,
1382 c->transient_for_group,
1383 client_direct_parent(c),
1384 client_direct_parent(c));
1388 static void client_get_mwm_hints(ObClient *self)
1393 self->mwmhints.flags = 0; /* default to none */
1395 if (OBT_PROP_GETA32(self->window, MOTIF_WM_HINTS, MOTIF_WM_HINTS,
1397 if (num >= OB_MWM_ELEMENTS) {
1398 self->mwmhints.flags = hints[0];
1399 self->mwmhints.functions = hints[1];
1400 self->mwmhints.decorations = hints[2];
1406 void client_get_type_and_transientness(ObClient *self)
1413 self->transient = FALSE;
1415 if (OBT_PROP_GETA32(self->window, NET_WM_WINDOW_TYPE, ATOM, &val, &num)) {
1416 /* use the first value that we know about in the array */
1417 for (i = 0; i < num; ++i) {
1418 if (val[i] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_DESKTOP))
1419 self->type = OB_CLIENT_TYPE_DESKTOP;
1420 else if (val[i] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_DOCK))
1421 self->type = OB_CLIENT_TYPE_DOCK;
1422 else if (val[i] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_TOOLBAR))
1423 self->type = OB_CLIENT_TYPE_TOOLBAR;
1424 else if (val[i] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_MENU))
1425 self->type = OB_CLIENT_TYPE_MENU;
1426 else if (val[i] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_UTILITY))
1427 self->type = OB_CLIENT_TYPE_UTILITY;
1428 else if (val[i] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_SPLASH))
1429 self->type = OB_CLIENT_TYPE_SPLASH;
1430 else if (val[i] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_DIALOG))
1431 self->type = OB_CLIENT_TYPE_DIALOG;
1432 else if (val[i] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_NORMAL))
1433 self->type = OB_CLIENT_TYPE_NORMAL;
1434 else if (val[i] == OBT_PROP_ATOM(KDE_NET_WM_WINDOW_TYPE_OVERRIDE))
1436 /* prevent this window from getting any decor or
1438 self->mwmhints.flags &= (OB_MWM_FLAG_FUNCTIONS |
1439 OB_MWM_FLAG_DECORATIONS);
1440 self->mwmhints.decorations = 0;
1441 self->mwmhints.functions = 0;
1443 if (self->type != (ObClientType) -1)
1444 break; /* grab the first legit type */
1449 if (XGetTransientForHint(obt_display, self->window, &t))
1450 self->transient = TRUE;
1452 if (self->type == (ObClientType) -1) {
1453 /*the window type hint was not set, which means we either classify
1454 ourself as a normal window or a dialog, depending on if we are a
1456 if (self->transient)
1457 self->type = OB_CLIENT_TYPE_DIALOG;
1459 self->type = OB_CLIENT_TYPE_NORMAL;
1462 /* then, based on our type, we can update our transientness.. */
1463 if (self->type == OB_CLIENT_TYPE_DIALOG ||
1464 self->type == OB_CLIENT_TYPE_TOOLBAR ||
1465 self->type == OB_CLIENT_TYPE_MENU ||
1466 self->type == OB_CLIENT_TYPE_UTILITY)
1468 self->transient = TRUE;
1472 void client_update_protocols(ObClient *self)
1477 self->focus_notify = FALSE;
1478 self->delete_window = FALSE;
1480 if (OBT_PROP_GETA32(self->window, WM_PROTOCOLS, ATOM, &proto, &num_ret)) {
1481 for (i = 0; i < num_ret; ++i) {
1482 if (proto[i] == OBT_PROP_ATOM(WM_DELETE_WINDOW))
1483 /* this means we can request the window to close */
1484 self->delete_window = TRUE;
1485 else if (proto[i] == OBT_PROP_ATOM(WM_TAKE_FOCUS))
1486 /* if this protocol is requested, then the window will be
1487 notified whenever we want it to receive focus */
1488 self->focus_notify = TRUE;
1489 else if (proto[i] == OBT_PROP_ATOM(NET_WM_PING))
1490 /* if this protocol is requested, then the window will allow
1491 pings to determine if it is still alive */
1494 else if (proto[i] == OBT_PROP_ATOM(NET_WM_SYNC_REQUEST))
1495 /* if this protocol is requested, then resizing the
1496 window will be synchronized between the frame and the
1498 self->sync_request = TRUE;
1506 void client_update_sync_request_counter(ObClient *self)
1510 if (OBT_PROP_GET32(self->window, NET_WM_SYNC_REQUEST_COUNTER, CARDINAL,&i))
1512 self->sync_counter = i;
1514 self->sync_counter = None;
1518 static void client_get_colormap(ObClient *self)
1520 XWindowAttributes wa;
1522 if (XGetWindowAttributes(obt_display, self->window, &wa))
1523 client_update_colormap(self, wa.colormap);
1526 void client_update_colormap(ObClient *self, Colormap colormap)
1528 if (colormap == self->colormap) return;
1530 ob_debug("Setting client %s colormap: 0x%x", self->title, colormap);
1532 if (client_focused(self)) {
1533 screen_install_colormap(self, FALSE); /* uninstall old one */
1534 self->colormap = colormap;
1535 screen_install_colormap(self, TRUE); /* install new one */
1537 self->colormap = colormap;
1540 void client_update_normal_hints(ObClient *self)
1546 self->min_ratio = 0.0f;
1547 self->max_ratio = 0.0f;
1548 SIZE_SET(self->size_inc, 1, 1);
1549 SIZE_SET(self->base_size, -1, -1);
1550 SIZE_SET(self->min_size, 0, 0);
1551 SIZE_SET(self->max_size, G_MAXINT, G_MAXINT);
1553 /* get the hints from the window */
1554 if (XGetWMNormalHints(obt_display, self->window, &size, &ret)) {
1555 /* normal windows can't request placement! har har
1556 if (!client_normal(self))
1558 self->positioned = (size.flags & (PPosition|USPosition));
1559 self->sized = (size.flags & (PSize|USSize));
1561 if (size.flags & PWinGravity)
1562 self->gravity = size.win_gravity;
1564 if (size.flags & PAspect) {
1565 if (size.min_aspect.y)
1567 (gfloat) size.min_aspect.x / size.min_aspect.y;
1568 if (size.max_aspect.y)
1570 (gfloat) size.max_aspect.x / size.max_aspect.y;
1573 if (size.flags & PMinSize)
1574 SIZE_SET(self->min_size, size.min_width, size.min_height);
1576 if (size.flags & PMaxSize)
1577 SIZE_SET(self->max_size, size.max_width, size.max_height);
1579 if (size.flags & PBaseSize)
1580 SIZE_SET(self->base_size, size.base_width, size.base_height);
1582 if (size.flags & PResizeInc && size.width_inc && size.height_inc)
1583 SIZE_SET(self->size_inc, size.width_inc, size.height_inc);
1585 ob_debug("Normal hints: min size (%d %d) max size (%d %d)",
1586 self->min_size.width, self->min_size.height,
1587 self->max_size.width, self->max_size.height);
1588 ob_debug("size inc (%d %d) base size (%d %d)",
1589 self->size_inc.width, self->size_inc.height,
1590 self->base_size.width, self->base_size.height);
1593 ob_debug("Normal hints: not set");
1596 void client_setup_decor_and_functions(ObClient *self, gboolean reconfig)
1598 /* start with everything (cept fullscreen) */
1600 (OB_FRAME_DECOR_TITLEBAR |
1601 OB_FRAME_DECOR_HANDLE |
1602 OB_FRAME_DECOR_GRIPS |
1603 OB_FRAME_DECOR_BORDER |
1604 OB_FRAME_DECOR_ICON |
1605 OB_FRAME_DECOR_ALLDESKTOPS |
1606 OB_FRAME_DECOR_ICONIFY |
1607 OB_FRAME_DECOR_MAXIMIZE |
1608 OB_FRAME_DECOR_SHADE |
1609 OB_FRAME_DECOR_CLOSE);
1611 (OB_CLIENT_FUNC_RESIZE |
1612 OB_CLIENT_FUNC_MOVE |
1613 OB_CLIENT_FUNC_ICONIFY |
1614 OB_CLIENT_FUNC_MAXIMIZE |
1615 OB_CLIENT_FUNC_SHADE |
1616 OB_CLIENT_FUNC_CLOSE |
1617 OB_CLIENT_FUNC_BELOW |
1618 OB_CLIENT_FUNC_ABOVE |
1619 OB_CLIENT_FUNC_UNDECORATE);
1621 if (!(self->min_size.width < self->max_size.width ||
1622 self->min_size.height < self->max_size.height))
1623 self->functions &= ~OB_CLIENT_FUNC_RESIZE;
1625 switch (self->type) {
1626 case OB_CLIENT_TYPE_NORMAL:
1627 /* normal windows retain all of the possible decorations and
1628 functionality, and can be fullscreen */
1629 self->functions |= OB_CLIENT_FUNC_FULLSCREEN;
1632 case OB_CLIENT_TYPE_DIALOG:
1633 /* sometimes apps make dialog windows fullscreen for some reason (for
1634 e.g. kpdf does this..) */
1635 self->functions |= OB_CLIENT_FUNC_FULLSCREEN;
1638 case OB_CLIENT_TYPE_UTILITY:
1639 /* these windows don't have anything added or removed by default */
1642 case OB_CLIENT_TYPE_MENU:
1643 case OB_CLIENT_TYPE_TOOLBAR:
1644 /* these windows can't iconify or maximize */
1645 self->decorations &= ~(OB_FRAME_DECOR_ICONIFY |
1646 OB_FRAME_DECOR_MAXIMIZE);
1647 self->functions &= ~(OB_CLIENT_FUNC_ICONIFY |
1648 OB_CLIENT_FUNC_MAXIMIZE);
1651 case OB_CLIENT_TYPE_SPLASH:
1652 /* these don't get get any decorations, and the only thing you can
1653 do with them is move them */
1654 self->decorations = 0;
1655 self->functions = OB_CLIENT_FUNC_MOVE;
1658 case OB_CLIENT_TYPE_DESKTOP:
1659 /* these windows are not manipulated by the window manager */
1660 self->decorations = 0;
1661 self->functions = 0;
1664 case OB_CLIENT_TYPE_DOCK:
1665 /* these windows are not manipulated by the window manager, but they
1666 can set below layer which has a special meaning */
1667 self->decorations = 0;
1668 self->functions = OB_CLIENT_FUNC_BELOW;
1672 /* Mwm Hints are applied subtractively to what has already been chosen for
1673 decor and functionality */
1674 if (self->mwmhints.flags & OB_MWM_FLAG_DECORATIONS) {
1675 if (! (self->mwmhints.decorations & OB_MWM_DECOR_ALL)) {
1676 if (! ((self->mwmhints.decorations & OB_MWM_DECOR_HANDLE) ||
1677 (self->mwmhints.decorations & OB_MWM_DECOR_TITLE)))
1679 /* if the mwm hints request no handle or title, then all
1680 decorations are disabled, but keep the border if that's
1682 if (self->mwmhints.decorations & OB_MWM_DECOR_BORDER)
1683 self->decorations = OB_FRAME_DECOR_BORDER;
1685 self->decorations = 0;
1690 if (self->mwmhints.flags & OB_MWM_FLAG_FUNCTIONS) {
1691 if (! (self->mwmhints.functions & OB_MWM_FUNC_ALL)) {
1692 if (! (self->mwmhints.functions & OB_MWM_FUNC_RESIZE))
1693 self->functions &= ~OB_CLIENT_FUNC_RESIZE;
1694 if (! (self->mwmhints.functions & OB_MWM_FUNC_MOVE))
1695 self->functions &= ~OB_CLIENT_FUNC_MOVE;
1696 /* dont let mwm hints kill any buttons
1697 if (! (self->mwmhints.functions & OB_MWM_FUNC_ICONIFY))
1698 self->functions &= ~OB_CLIENT_FUNC_ICONIFY;
1699 if (! (self->mwmhints.functions & OB_MWM_FUNC_MAXIMIZE))
1700 self->functions &= ~OB_CLIENT_FUNC_MAXIMIZE;
1702 /* dont let mwm hints kill the close button
1703 if (! (self->mwmhints.functions & MwmFunc_Close))
1704 self->functions &= ~OB_CLIENT_FUNC_CLOSE; */
1708 if (!(self->functions & OB_CLIENT_FUNC_SHADE))
1709 self->decorations &= ~OB_FRAME_DECOR_SHADE;
1710 if (!(self->functions & OB_CLIENT_FUNC_ICONIFY))
1711 self->decorations &= ~OB_FRAME_DECOR_ICONIFY;
1712 if (!(self->functions & OB_CLIENT_FUNC_RESIZE))
1713 self->decorations &= ~(OB_FRAME_DECOR_GRIPS | OB_FRAME_DECOR_HANDLE);
1715 /* can't maximize without moving/resizing */
1716 if (!((self->functions & OB_CLIENT_FUNC_MAXIMIZE) &&
1717 (self->functions & OB_CLIENT_FUNC_MOVE) &&
1718 (self->functions & OB_CLIENT_FUNC_RESIZE))) {
1719 self->functions &= ~OB_CLIENT_FUNC_MAXIMIZE;
1720 self->decorations &= ~OB_FRAME_DECOR_MAXIMIZE;
1723 if (self->max_horz && self->max_vert) {
1724 /* you can't resize fully maximized windows */
1725 self->functions &= ~OB_CLIENT_FUNC_RESIZE;
1726 /* kill the handle on fully maxed windows */
1727 self->decorations &= ~(OB_FRAME_DECOR_HANDLE | OB_FRAME_DECOR_GRIPS);
1730 /* If there are no decorations to remove, don't allow the user to try
1732 if (self->decorations == 0)
1733 self->functions &= ~OB_CLIENT_FUNC_UNDECORATE;
1735 /* finally, the user can have requested no decorations, which overrides
1736 everything (but doesnt give it a border if it doesnt have one) */
1737 if (self->undecorated)
1738 self->decorations = 0;
1740 /* if we don't have a titlebar, then we cannot shade! */
1741 if (!(self->decorations & OB_FRAME_DECOR_TITLEBAR))
1742 self->functions &= ~OB_CLIENT_FUNC_SHADE;
1744 /* now we need to check against rules for the client's current state */
1745 if (self->fullscreen) {
1746 self->functions &= (OB_CLIENT_FUNC_CLOSE |
1747 OB_CLIENT_FUNC_FULLSCREEN |
1748 OB_CLIENT_FUNC_ICONIFY);
1749 self->decorations = 0;
1752 client_change_allowed_actions(self);
1755 /* force reconfigure to make sure decorations are updated */
1756 client_reconfigure(self, TRUE);
1759 static void client_change_allowed_actions(ObClient *self)
1764 /* desktop windows are kept on all desktops */
1765 if (self->type != OB_CLIENT_TYPE_DESKTOP)
1766 actions[num++] = OBT_PROP_ATOM(NET_WM_ACTION_CHANGE_DESKTOP);
1768 if (self->functions & OB_CLIENT_FUNC_SHADE)
1769 actions[num++] = OBT_PROP_ATOM(NET_WM_ACTION_SHADE);
1770 if (self->functions & OB_CLIENT_FUNC_CLOSE)
1771 actions[num++] = OBT_PROP_ATOM(NET_WM_ACTION_CLOSE);
1772 if (self->functions & OB_CLIENT_FUNC_MOVE)
1773 actions[num++] = OBT_PROP_ATOM(NET_WM_ACTION_MOVE);
1774 if (self->functions & OB_CLIENT_FUNC_ICONIFY)
1775 actions[num++] = OBT_PROP_ATOM(NET_WM_ACTION_MINIMIZE);
1776 if (self->functions & OB_CLIENT_FUNC_RESIZE)
1777 actions[num++] = OBT_PROP_ATOM(NET_WM_ACTION_RESIZE);
1778 if (self->functions & OB_CLIENT_FUNC_FULLSCREEN)
1779 actions[num++] = OBT_PROP_ATOM(NET_WM_ACTION_FULLSCREEN);
1780 if (self->functions & OB_CLIENT_FUNC_MAXIMIZE) {
1781 actions[num++] = OBT_PROP_ATOM(NET_WM_ACTION_MAXIMIZE_HORZ);
1782 actions[num++] = OBT_PROP_ATOM(NET_WM_ACTION_MAXIMIZE_VERT);
1784 if (self->functions & OB_CLIENT_FUNC_ABOVE)
1785 actions[num++] = OBT_PROP_ATOM(NET_WM_ACTION_ABOVE);
1786 if (self->functions & OB_CLIENT_FUNC_BELOW)
1787 actions[num++] = OBT_PROP_ATOM(NET_WM_ACTION_BELOW);
1788 if (self->functions & OB_CLIENT_FUNC_UNDECORATE)
1789 actions[num++] = OBT_PROP_ATOM(OB_WM_ACTION_UNDECORATE);
1791 OBT_PROP_SETA32(self->window, NET_WM_ALLOWED_ACTIONS, ATOM, actions, num);
1793 /* make sure the window isn't breaking any rules now
1795 don't check ICONIFY here. just cuz a window can't iconify doesnt mean
1796 it can't be iconified with its parent
1799 if (!(self->functions & OB_CLIENT_FUNC_SHADE) && self->shaded) {
1800 if (self->frame) client_shade(self, FALSE);
1801 else self->shaded = FALSE;
1803 if (!(self->functions & OB_CLIENT_FUNC_FULLSCREEN) && self->fullscreen) {
1804 if (self->frame) client_fullscreen(self, FALSE);
1805 else self->fullscreen = FALSE;
1807 if (!(self->functions & OB_CLIENT_FUNC_MAXIMIZE) && (self->max_horz ||
1809 if (self->frame) client_maximize(self, FALSE, 0);
1810 else self->max_vert = self->max_horz = FALSE;
1814 void client_update_wmhints(ObClient *self)
1818 /* assume a window takes input if it doesn't specify */
1819 self->can_focus = TRUE;
1821 if ((hints = XGetWMHints(obt_display, self->window)) != NULL) {
1824 if (hints->flags & InputHint)
1825 self->can_focus = hints->input;
1827 /* only do this when first managing the window *AND* when we aren't
1829 if (ob_state() != OB_STATE_STARTING && self->frame == NULL)
1830 if (hints->flags & StateHint)
1831 self->iconic = hints->initial_state == IconicState;
1834 self->urgent = (hints->flags & XUrgencyHint);
1835 if (self->urgent && !ur)
1836 client_hilite(self, TRUE);
1837 else if (!self->urgent && ur && self->demands_attention)
1838 client_hilite(self, FALSE);
1840 if (!(hints->flags & WindowGroupHint))
1841 hints->window_group = None;
1843 /* did the group state change? */
1844 if (hints->window_group !=
1845 (self->group ? self->group->leader : None))
1847 ObGroup *oldgroup = self->group;
1849 /* remove from the old group if there was one */
1851 group_remove(self->group, self);
1855 /* add ourself to the group if we have one */
1856 if (hints->window_group != None) {
1857 self->group = group_add(hints->window_group, self);
1860 /* Put ourselves into the new group's transient tree, and remove
1861 ourselves from the old group's */
1862 client_update_transient_tree(self, oldgroup, self->group,
1863 self->transient_for_group,
1864 self->transient_for_group,
1865 client_direct_parent(self),
1866 client_direct_parent(self));
1868 /* Lastly, being in a group, or not, can change if the window is
1869 transient for anything.
1871 The logic for this is:
1872 self->transient = TRUE always if the window wants to be
1873 transient for something, even if transient_for was NULL because
1874 it wasn't in a group before.
1876 If parents was NULL and oldgroup was NULL we can assume
1877 that when we add the new group, it will become transient for
1880 If transient_for_group is TRUE, then it must have already
1881 had a group. If it is getting a new group, the above call to
1882 client_update_transient_tree has already taken care of
1883 everything ! If it is losing all group status then it will
1884 no longer be transient for anything and that needs to be
1887 if (self->transient &&
1888 ((self->parents == NULL && oldgroup == NULL) ||
1889 (self->transient_for_group && !self->group)))
1890 client_update_transient_for(self);
1893 /* the WM_HINTS can contain an icon */
1894 if (hints->flags & IconPixmapHint)
1895 client_update_icons(self);
1901 void client_update_title(ObClient *self)
1904 gchar *visible = NULL;
1906 g_free(self->title);
1907 g_free(self->original_title);
1910 if (!OBT_PROP_GETS(self->window, NET_WM_NAME, utf8, &data)) {
1911 /* try old x stuff */
1912 if (!(OBT_PROP_GETS(self->window, WM_NAME, locale, &data)
1913 || OBT_PROP_GETS(self->window, WM_NAME, utf8, &data))) {
1914 if (self->transient) {
1916 GNOME alert windows are not given titles:
1917 http://developer.gnome.org/projects/gup/hig/draft_hig_new/windows-alert.html
1919 data = g_strdup("");
1921 data = g_strdup(_("Unnamed Window"));
1924 self->original_title = g_strdup(data);
1926 if (self->client_machine) {
1927 visible = g_strdup_printf("%s (%s)", data, self->client_machine);
1932 if (self->not_responding) {
1934 if (self->kill_level > 0)
1935 visible = g_strdup_printf("%s - [%s]", data, _("Killing..."));
1937 visible = g_strdup_printf("%s - [%s]", data, _("Not Responding"));
1941 OBT_PROP_SETS(self->window, NET_WM_VISIBLE_NAME, utf8, visible);
1942 self->title = visible;
1945 frame_adjust_title(self->frame);
1947 /* update the icon title */
1949 g_free(self->icon_title);
1952 if (!OBT_PROP_GETS(self->window, NET_WM_ICON_NAME, utf8, &data))
1953 /* try old x stuff */
1954 if (!(OBT_PROP_GETS(self->window, WM_ICON_NAME, locale, &data) ||
1955 OBT_PROP_GETS(self->window, WM_ICON_NAME, utf8, &data)))
1956 data = g_strdup(self->title);
1958 if (self->client_machine) {
1959 visible = g_strdup_printf("%s (%s)", data, self->client_machine);
1964 if (self->not_responding) {
1966 if (self->kill_level > 0)
1967 visible = g_strdup_printf("%s - [%s]", data, _("Killing..."));
1969 visible = g_strdup_printf("%s - [%s]", data, _("Not Responding"));
1973 OBT_PROP_SETS(self->window, NET_WM_VISIBLE_ICON_NAME, utf8, visible);
1974 self->icon_title = visible;
1977 void client_update_strut(ObClient *self)
1981 gboolean got = FALSE;
1984 if (OBT_PROP_GETA32(self->window, NET_WM_STRUT_PARTIAL, CARDINAL,
1989 STRUT_PARTIAL_SET(strut,
1990 data[0], data[2], data[1], data[3],
1991 data[4], data[5], data[8], data[9],
1992 data[6], data[7], data[10], data[11]);
1998 OBT_PROP_GETA32(self->window, NET_WM_STRUT, CARDINAL, &data, &num)) {
2004 /* use the screen's width/height */
2005 a = screen_physical_area_all_monitors();
2007 STRUT_PARTIAL_SET(strut,
2008 data[0], data[2], data[1], data[3],
2009 a->y, a->y + a->height - 1,
2010 a->x, a->x + a->width - 1,
2011 a->y, a->y + a->height - 1,
2012 a->x, a->x + a->width - 1);
2019 STRUT_PARTIAL_SET(strut, 0, 0, 0, 0,
2020 0, 0, 0, 0, 0, 0, 0, 0);
2022 if (!STRUT_EQUAL(strut, self->strut)) {
2023 self->strut = strut;
2025 /* updating here is pointless while we're being mapped cuz we're not in
2026 the client list yet */
2028 screen_update_areas();
2032 void client_update_icons(ObClient *self)
2037 guint num_seen; /* number of icons present */
2042 /* grab the server, because we might be setting the window's icon and
2043 we don't want them to set it in between and we overwrite their own
2047 if (OBT_PROP_GETA32(self->window, NET_WM_ICON, CARDINAL, &data, &num)) {
2048 /* figure out how many valid icons are in here */
2051 while (i + 2 < num) { /* +2 is to make sure there is a w and h */
2054 /* watch for the data being too small for the specified size,
2055 or for zero sized icons. */
2056 if (i + w*h > num || w == 0 || h == 0) break;
2058 /* convert it to the right bit order for ObRender */
2059 for (j = 0; j < w*h; ++j)
2061 (((data[i+j] >> 24) & 0xff) << RrDefaultAlphaOffset) +
2062 (((data[i+j] >> 16) & 0xff) << RrDefaultRedOffset) +
2063 (((data[i+j] >> 8) & 0xff) << RrDefaultGreenOffset) +
2064 (((data[i+j] >> 0) & 0xff) << RrDefaultBlueOffset);
2066 /* is it in the cache? */
2067 img = RrImageCacheFind(ob_rr_icons, &data[i], w, h);
2068 if (img) RrImageRef(img); /* own it */
2073 /* don't bother looping anymore if we already found it in the cache
2074 since we'll just use that! */
2078 /* if it's not in the cache yet, then add it to the cache now.
2079 we have already converted it to the correct bit order above */
2080 if (!img && num_seen > 0) {
2081 img = RrImageNew(ob_rr_icons);
2083 for (j = 0; j < num_seen; ++j) {
2086 RrImageAddPicture(img, &data[i], w, h);
2094 /* if we didn't find an image from the NET_WM_ICON stuff, then try the
2099 if ((hints = XGetWMHints(obt_display, self->window))) {
2100 if (hints->flags & IconPixmapHint) {
2102 obt_display_ignore_errors(TRUE);
2103 xicon = RrPixmapToRGBA(ob_rr_inst,
2105 (hints->flags & IconMaskHint ?
2106 hints->icon_mask : None),
2107 (gint*)&w, (gint*)&h, &data);
2108 obt_display_ignore_errors(FALSE);
2111 if (w > 0 && h > 0) {
2112 /* is this icon in the cache yet? */
2113 img = RrImageCacheFind(ob_rr_icons, data, w, h);
2114 if (img) RrImageRef(img); /* own it */
2116 /* if not, then add it */
2118 img = RrImageNew(ob_rr_icons);
2119 RrImageAddPicture(img, data, w, h);
2130 /* set the client's icons to be whatever we found */
2131 RrImageUnref(self->icon_set);
2132 self->icon_set = img;
2134 /* if the client has no icon at all, then we set a default icon onto it.
2135 but, if it has parents, then one of them will have an icon already
2137 if (!self->icon_set && !self->parents) {
2138 RrPixel32 *icon = ob_rr_theme->def_win_icon;
2139 gulong *ldata; /* use a long here to satisfy OBT_PROP_SETA32 */
2141 r = g_random_int_range(0,255);
2142 g = g_random_int_range(0,255);
2143 b = g_random_int_range(0,255);
2145 w = ob_rr_theme->def_win_icon_w;
2146 h = ob_rr_theme->def_win_icon_h;
2147 ldata = g_new(gulong, w*h+2);
2150 for (i = 0; i < w*h; ++i)
2151 ldata[i+2] = (((icon[i] >> RrDefaultAlphaOffset) & 0xff) << 24) +
2152 ((((icon[i] >> RrDefaultRedOffset) & 0xff)*r/255) << 16) +
2153 ((((icon[i] >> RrDefaultGreenOffset) & 0xff)*g/255) << 8) +
2154 ((((icon[i] >> RrDefaultBlueOffset) & 0xff)*b/255) << 0);
2155 OBT_PROP_SETA32(self->window, NET_WM_ICON, CARDINAL, ldata, w*h+2);
2157 } else if (self->frame)
2158 /* don't draw the icon empty if we're just setting one now anyways,
2159 we'll get the property change any second */
2160 frame_adjust_icon(self->frame);
2165 void client_update_icon_geometry(ObClient *self)
2170 RECT_SET(self->icon_geometry, 0, 0, 0, 0);
2172 if (OBT_PROP_GETA32(self->window, NET_WM_ICON_GEOMETRY, CARDINAL,
2176 /* don't let them set it with an area < 0 */
2177 RECT_SET(self->icon_geometry, data[0], data[1],
2178 MAX(data[2],0), MAX(data[3],0));
2183 static void client_get_session_ids(ObClient *self)
2190 if (!OBT_PROP_GET32(self->window, WM_CLIENT_LEADER, WINDOW, &leader))
2193 /* get the SM_CLIENT_ID */
2196 got = OBT_PROP_GETS(leader, SM_CLIENT_ID, locale, &self->sm_client_id);
2198 OBT_PROP_GETS(self->window, SM_CLIENT_ID, locale, &self->sm_client_id);
2200 /* get the WM_CLASS (name and class). make them "" if they are not
2204 got = OBT_PROP_GETSS(leader, WM_CLASS, locale, &ss);
2206 got = OBT_PROP_GETSS(self->window, WM_CLASS, locale, &ss);
2210 self->name = g_strdup(ss[0]);
2212 self->class = g_strdup(ss[1]);
2217 if (self->name == NULL) self->name = g_strdup("");
2218 if (self->class == NULL) self->class = g_strdup("");
2220 /* get the WM_WINDOW_ROLE. make it "" if it is not provided */
2223 got = OBT_PROP_GETS(leader, WM_WINDOW_ROLE, locale, &s);
2225 got = OBT_PROP_GETS(self->window, WM_WINDOW_ROLE, locale, &s);
2230 self->role = g_strdup("");
2232 /* get the WM_COMMAND */
2236 got = OBT_PROP_GETSS(leader, WM_COMMAND, locale, &ss);
2238 got = OBT_PROP_GETSS(self->window, WM_COMMAND, locale, &ss);
2241 /* merge/mash them all together */
2242 gchar *merge = NULL;
2245 for (i = 0; ss[i]; ++i) {
2248 merge = g_strconcat(merge, ss[i], NULL);
2250 merge = g_strconcat(ss[i], NULL);
2255 self->wm_command = merge;
2258 /* get the WM_CLIENT_MACHINE */
2261 got = OBT_PROP_GETS(leader, WM_CLIENT_MACHINE, locale, &s);
2263 got = OBT_PROP_GETS(self->window, WM_CLIENT_MACHINE, locale, &s);
2266 gchar localhost[128];
2269 gethostname(localhost, 127);
2270 localhost[127] = '\0';
2271 if (strcmp(localhost, s) != 0)
2272 self->client_machine = s;
2276 /* see if it has the PID set too (the PID requires that the
2277 WM_CLIENT_MACHINE be set) */
2278 if (OBT_PROP_GET32(self->window, NET_WM_PID, CARDINAL, &pid))
2283 static void client_change_wm_state(ObClient *self)
2288 old = self->wmstate;
2290 if (self->shaded || self->iconic ||
2291 (self->desktop != DESKTOP_ALL && self->desktop != screen_desktop))
2293 self->wmstate = IconicState;
2295 self->wmstate = NormalState;
2297 if (old != self->wmstate) {
2298 OBT_PROP_MSG(ob_screen, self->window, KDE_WM_CHANGE_STATE,
2299 self->wmstate, 1, 0, 0, 0);
2301 state[0] = self->wmstate;
2303 OBT_PROP_SETA32(self->window, WM_STATE, WM_STATE, state, 2);
2307 static void client_change_state(ObClient *self)
2309 gulong netstate[13];
2314 netstate[num++] = OBT_PROP_ATOM(NET_WM_STATE_MODAL);
2316 netstate[num++] = OBT_PROP_ATOM(NET_WM_STATE_SHADED);
2318 netstate[num++] = OBT_PROP_ATOM(NET_WM_STATE_HIDDEN);
2319 if (self->skip_taskbar)
2320 netstate[num++] = OBT_PROP_ATOM(NET_WM_STATE_SKIP_TASKBAR);
2321 if (self->skip_pager)
2322 netstate[num++] = OBT_PROP_ATOM(NET_WM_STATE_SKIP_PAGER);
2323 if (self->fullscreen)
2324 netstate[num++] = OBT_PROP_ATOM(NET_WM_STATE_FULLSCREEN);
2326 netstate[num++] = OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_VERT);
2328 netstate[num++] = OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_HORZ);
2330 netstate[num++] = OBT_PROP_ATOM(NET_WM_STATE_ABOVE);
2332 netstate[num++] = OBT_PROP_ATOM(NET_WM_STATE_BELOW);
2333 if (self->demands_attention)
2334 netstate[num++] = OBT_PROP_ATOM(NET_WM_STATE_DEMANDS_ATTENTION);
2335 if (self->undecorated)
2336 netstate[num++] = OBT_PROP_ATOM(OB_WM_STATE_UNDECORATED);
2338 netstate[num++] = OBT_PROP_ATOM(OB_WM_STATE_LOCKED);
2339 OBT_PROP_SETA32(self->window, NET_WM_STATE, ATOM, netstate, num);
2342 frame_adjust_state(self->frame);
2345 ObClient *client_search_focus_tree(ObClient *self)
2350 for (it = self->transients; it; it = g_slist_next(it)) {
2351 if (client_focused(it->data)) return it->data;
2352 if ((ret = client_search_focus_tree(it->data))) return ret;
2357 ObClient *client_search_focus_tree_full(ObClient *self)
2359 if (self->parents) {
2362 for (it = self->parents; it; it = g_slist_next(it)) {
2363 ObClient *c = it->data;
2364 if ((c = client_search_focus_tree_full(it->data))) return c;
2370 /* this function checks the whole tree, the client_search_focus_tree
2371 does not, so we need to check this window */
2372 if (client_focused(self))
2374 return client_search_focus_tree(self);
2378 ObClient *client_search_focus_group_full(ObClient *self)
2383 for (it = self->group->members; it; it = g_slist_next(it)) {
2384 ObClient *c = it->data;
2386 if (client_focused(c)) return c;
2387 if ((c = client_search_focus_tree(it->data))) return c;
2390 if (client_focused(self)) return self;
2394 gboolean client_has_parent(ObClient *self)
2396 return self->parents != NULL;
2399 static ObStackingLayer calc_layer(ObClient *self)
2404 monitor = screen_physical_area_monitor(client_monitor(self));
2406 if (self->type == OB_CLIENT_TYPE_DESKTOP)
2407 l = OB_STACKING_LAYER_DESKTOP;
2408 else if (self->type == OB_CLIENT_TYPE_DOCK) {
2409 if (self->below) l = OB_STACKING_LAYER_NORMAL;
2410 else l = OB_STACKING_LAYER_ABOVE;
2412 else if ((self->fullscreen ||
2413 /* No decorations and fills the monitor = oldskool fullscreen.
2414 But not for maximized windows.
2416 (self->decorations == 0 &&
2417 !(self->max_horz && self->max_vert) &&
2418 RECT_EQUAL(self->area, *monitor))) &&
2419 /* you are fullscreen while you or your children are focused.. */
2420 (client_focused(self) || client_search_focus_tree(self) ||
2421 /* you can be fullscreen if you're on another desktop */
2422 (self->desktop != screen_desktop &&
2423 self->desktop != DESKTOP_ALL) ||
2424 /* and you can also be fullscreen if the focused client is on
2425 another monitor, or nothing else is focused */
2427 client_monitor(focus_client) != client_monitor(self))))
2428 l = OB_STACKING_LAYER_FULLSCREEN;
2429 else if (self->above) l = OB_STACKING_LAYER_ABOVE;
2430 else if (self->below) l = OB_STACKING_LAYER_BELOW;
2431 else l = OB_STACKING_LAYER_NORMAL;
2438 static void client_calc_layer_recursive(ObClient *self, ObClient *orig,
2439 ObStackingLayer min)
2441 ObStackingLayer old, own;
2445 own = calc_layer(self);
2446 self->layer = MAX(own, min);
2448 if (self->layer != old) {
2449 stacking_remove(CLIENT_AS_WINDOW(self));
2450 stacking_add_nonintrusive(CLIENT_AS_WINDOW(self));
2453 /* we've been restacked */
2454 self->visited = TRUE;
2456 for (it = self->transients; it; it = g_slist_next(it))
2457 client_calc_layer_recursive(it->data, orig,
2461 static void client_calc_layer_internal(ObClient *self)
2465 /* transients take on the layer of their parents */
2466 sit = client_search_all_top_parents(self);
2468 for (; sit; sit = g_slist_next(sit))
2469 client_calc_layer_recursive(sit->data, self, 0);
2472 void client_calc_layer(ObClient *self)
2476 /* skip over stuff above fullscreen layer */
2477 for (it = stacking_list; it; it = g_list_next(it))
2478 if (window_layer(it->data) <= OB_STACKING_LAYER_FULLSCREEN) break;
2480 /* find the windows in the fullscreen layer, and mark them not-visited */
2481 for (; it; it = g_list_next(it)) {
2482 if (window_layer(it->data) < OB_STACKING_LAYER_FULLSCREEN) break;
2483 else if (WINDOW_IS_CLIENT(it->data))
2484 WINDOW_AS_CLIENT(it->data)->visited = FALSE;
2487 client_calc_layer_internal(self);
2489 /* skip over stuff above fullscreen layer */
2490 for (it = stacking_list; it; it = g_list_next(it))
2491 if (window_layer(it->data) <= OB_STACKING_LAYER_FULLSCREEN) break;
2493 /* now recalc any windows in the fullscreen layer which have not
2494 had their layer recalced already */
2495 for (; it; it = g_list_next(it)) {
2496 if (window_layer(it->data) < OB_STACKING_LAYER_FULLSCREEN) break;
2497 else if (WINDOW_IS_CLIENT(it->data) &&
2498 !WINDOW_AS_CLIENT(it->data)->visited)
2499 client_calc_layer_internal(it->data);
2503 gboolean client_should_show(ObClient *self)
2507 if (client_normal(self) && screen_showing_desktop)
2509 if (self->desktop == screen_desktop || self->desktop == DESKTOP_ALL)
2515 gboolean client_show(ObClient *self)
2517 gboolean show = FALSE;
2519 if (client_should_show(self)) {
2520 /* replay pending pointer event before showing the window, in case it
2521 should be going to something under the window */
2522 mouse_replay_pointer();
2524 frame_show(self->frame);
2527 /* According to the ICCCM (sec 4.1.3.1) when a window is not visible,
2528 it needs to be in IconicState. This includes when it is on another
2531 client_change_wm_state(self);
2533 hooks_queue(OB_HOOK_WIN_VISIBLE, self);
2538 gboolean client_hide(ObClient *self)
2540 gboolean hide = FALSE;
2542 if (!client_should_show(self)) {
2543 if (self == focus_client) {
2544 event_cancel_all_key_grabs();
2547 /* We don't need to ignore enter events here.
2548 The window can hide/iconify in 3 different ways:
2549 1 - through an x message. in this case we ignore all enter events
2550 caused by responding to the x message (unless underMouse)
2551 2 - by a keyboard action. in this case we ignore all enter events
2552 caused by the action
2553 3 - by a mouse action. in this case they are doing stuff with the
2554 mouse and focus _should_ move.
2556 Also in action_end, we simulate an enter event that can't be ignored
2557 so trying to ignore them is futile in case 3 anyways
2560 /* replay pending pointer event before hiding the window, in case it
2561 should be going to the window */
2562 mouse_replay_pointer();
2564 frame_hide(self->frame);
2567 /* According to the ICCCM (sec 4.1.3.1) when a window is not visible,
2568 it needs to be in IconicState. This includes when it is on another
2571 client_change_wm_state(self);
2573 hooks_queue(OB_HOOK_WIN_INVISIBLE, self);
2578 void client_showhide(ObClient *self)
2580 if (!client_show(self))
2584 gboolean client_normal(ObClient *self) {
2585 return ! (self->type == OB_CLIENT_TYPE_DESKTOP ||
2586 self->type == OB_CLIENT_TYPE_DOCK ||
2587 self->type == OB_CLIENT_TYPE_SPLASH);
2590 gboolean client_helper(ObClient *self)
2592 return (self->type == OB_CLIENT_TYPE_UTILITY ||
2593 self->type == OB_CLIENT_TYPE_MENU ||
2594 self->type == OB_CLIENT_TYPE_TOOLBAR);
2597 gboolean client_mouse_focusable(ObClient *self)
2599 return !(self->type == OB_CLIENT_TYPE_MENU ||
2600 self->type == OB_CLIENT_TYPE_TOOLBAR ||
2601 self->type == OB_CLIENT_TYPE_SPLASH ||
2602 self->type == OB_CLIENT_TYPE_DOCK);
2605 gboolean client_enter_focusable(ObClient *self)
2607 /* you can focus desktops but it shouldn't on enter */
2608 return (client_mouse_focusable(self) &&
2609 self->type != OB_CLIENT_TYPE_DESKTOP);
2612 static void client_apply_startup_state(ObClient *self,
2613 gint x, gint y, gint w, gint h)
2615 /* save the states that we are going to apply */
2616 gboolean iconic = self->iconic;
2617 gboolean fullscreen = self->fullscreen;
2618 gboolean undecorated = self->undecorated;
2619 gboolean shaded = self->shaded;
2620 gboolean demands_attention = self->demands_attention;
2621 gboolean max_horz = self->max_horz;
2622 gboolean max_vert = self->max_vert;
2626 /* turn them all off in the client, so they won't affect the window
2628 self->iconic = self->fullscreen = self->undecorated = self->shaded =
2629 self->demands_attention = self->max_horz = self->max_vert = FALSE;
2631 /* move the client to its placed position, or it it's already there,
2632 generate a ConfigureNotify telling the client where it is.
2634 do this after adjusting the frame. otherwise it gets all weird and
2635 clients don't work right
2637 do this before applying the states so they have the correct
2638 pre-max/pre-fullscreen values
2640 client_try_configure(self, &x, &y, &w, &h, &l, &l, FALSE);
2641 ob_debug("placed window 0x%x at %d, %d with size %d x %d",
2642 self->window, x, y, w, h);
2643 /* save the area, and make it where it should be for the premax stuff */
2644 oldarea = self->area;
2645 RECT_SET(self->area, x, y, w, h);
2647 /* apply the states. these are in a carefully crafted order.. */
2650 client_iconify(self, TRUE, FALSE, TRUE);
2652 client_fullscreen(self, TRUE);
2654 client_set_undecorated(self, TRUE);
2656 client_shade(self, TRUE);
2657 if (demands_attention)
2658 client_hilite(self, TRUE);
2660 if (max_vert && max_horz)
2661 client_maximize(self, TRUE, 0);
2663 client_maximize(self, TRUE, 2);
2665 client_maximize(self, TRUE, 1);
2667 /* if the window hasn't been configured yet, then do so now, in fact the
2668 x,y,w,h may _not_ be the same as the area rect, which can end up
2669 meaning that the client isn't properly moved/resized by the fullscreen
2671 pho can cause this because it maps at size of the screen but not 0,0
2672 so openbox moves it on screen to 0,0 (thus x,y=0,0 and area.x,y don't).
2673 then fullscreen'ing makes it go to 0,0 which it thinks it already is at
2674 cuz thats where the pre-fullscreen will be. however the actual area is
2675 not, so this needs to be called even if we have fullscreened/maxed
2677 self->area = oldarea;
2678 client_configure(self, x, y, w, h, FALSE, TRUE, FALSE);
2680 /* set the desktop hint, to make sure that it always exists */
2681 OBT_PROP_SET32(self->window, NET_WM_DESKTOP, CARDINAL, self->desktop);
2683 /* nothing to do for the other states:
2692 void client_gravity_resize_w(ObClient *self, gint *x, gint oldw, gint neww)
2694 /* these should be the current values. this is for when you're not moving,
2696 g_assert(*x == self->area.x);
2697 g_assert(oldw == self->area.width);
2700 switch (self->gravity) {
2702 case NorthWestGravity:
2704 case SouthWestGravity:
2711 *x -= (neww - oldw) / 2;
2713 case NorthEastGravity:
2715 case SouthEastGravity:
2721 void client_gravity_resize_h(ObClient *self, gint *y, gint oldh, gint newh)
2723 /* these should be the current values. this is for when you're not moving,
2725 g_assert(*y == self->area.y);
2726 g_assert(oldh == self->area.height);
2729 switch (self->gravity) {
2731 case NorthWestGravity:
2733 case NorthEastGravity:
2740 *y -= (newh - oldh) / 2;
2742 case SouthWestGravity:
2744 case SouthEastGravity:
2750 void client_try_configure(ObClient *self, gint *x, gint *y, gint *w, gint *h,
2751 gint *logicalw, gint *logicalh,
2754 Rect desired = {*x, *y, *w, *h};
2755 frame_rect_to_frame(self->frame, &desired);
2757 /* make the frame recalculate its dimensions n shit without changing
2758 anything visible for real, this way the constraints below can work with
2759 the updated frame dimensions. */
2760 frame_adjust_area(self->frame, FALSE, TRUE, TRUE);
2762 /* gets the frame's position */
2763 frame_client_gravity(self->frame, x, y);
2765 /* these positions are frame positions, not client positions */
2767 /* set the size and position if fullscreen */
2768 if (self->fullscreen) {
2772 i = screen_find_monitor(&desired);
2773 a = screen_physical_area_monitor(i);
2780 user = FALSE; /* ignore if the client can't be moved/resized when it
2784 } else if (self->max_horz || self->max_vert) {
2788 /* use all possible struts when maximizing to the full screen */
2789 i = screen_find_monitor(&desired);
2790 a = screen_area(self->desktop, i,
2791 (self->max_horz && self->max_vert ? NULL : &desired));
2793 /* set the size and position if maximized */
2794 if (self->max_horz) {
2796 *w = a->width - self->frame->size.left - self->frame->size.right;
2798 if (self->max_vert) {
2800 *h = a->height - self->frame->size.top - self->frame->size.bottom;
2803 user = FALSE; /* ignore if the client can't be moved/resized when it
2809 /* gets the client's position */
2810 frame_frame_gravity(self->frame, x, y);
2812 /* work within the preferred sizes given by the window, these may have
2813 changed rather than it's requested width and height, so always run
2814 through this code */
2816 gint basew, baseh, minw, minh;
2818 gfloat minratio, maxratio;
2820 incw = self->fullscreen || self->max_horz ? 1 : self->size_inc.width;
2821 inch = self->fullscreen || self->max_vert ? 1 : self->size_inc.height;
2822 minratio = self->fullscreen || (self->max_horz && self->max_vert) ?
2823 0 : self->min_ratio;
2824 maxratio = self->fullscreen || (self->max_horz && self->max_vert) ?
2825 0 : self->max_ratio;
2827 /* base size is substituted with min size if not specified */
2828 if (self->base_size.width >= 0 || self->base_size.height >= 0) {
2829 basew = self->base_size.width;
2830 baseh = self->base_size.height;
2832 basew = self->min_size.width;
2833 baseh = self->min_size.height;
2835 /* min size is substituted with base size if not specified */
2836 if (self->min_size.width || self->min_size.height) {
2837 minw = self->min_size.width;
2838 minh = self->min_size.height;
2840 minw = self->base_size.width;
2841 minh = self->base_size.height;
2844 /* This comment is no longer true */
2845 /* if this is a user-requested resize, then check against min/max
2848 /* smaller than min size or bigger than max size? */
2849 if (*w > self->max_size.width) *w = self->max_size.width;
2850 if (*w < minw) *w = minw;
2851 if (*h > self->max_size.height) *h = self->max_size.height;
2852 if (*h < minh) *h = minh;
2857 /* keep to the increments */
2861 /* you cannot resize to nothing */
2862 if (basew + *w < 1) *w = 1 - basew;
2863 if (baseh + *h < 1) *h = 1 - baseh;
2865 /* save the logical size */
2866 *logicalw = incw > 1 ? *w : *w + basew;
2867 *logicalh = inch > 1 ? *h : *h + baseh;
2875 /* adjust the height to match the width for the aspect ratios.
2876 for this, min size is not substituted for base size ever. */
2877 *w -= self->base_size.width;
2878 *h -= self->base_size.height;
2881 if (*h * minratio > *w) {
2882 *h = (gint)(*w / minratio);
2884 /* you cannot resize to nothing */
2887 *w = (gint)(*h * minratio);
2891 if (*h * maxratio < *w) {
2892 *h = (gint)(*w / maxratio);
2894 /* you cannot resize to nothing */
2897 *w = (gint)(*h * minratio);
2901 *w += self->base_size.width;
2902 *h += self->base_size.height;
2905 /* these override the above states! if you cant move you can't move! */
2907 if (!(self->functions & OB_CLIENT_FUNC_MOVE)) {
2911 if (!(self->functions & OB_CLIENT_FUNC_RESIZE)) {
2912 *w = self->area.width;
2913 *h = self->area.height;
2921 void client_configure(ObClient *self, gint x, gint y, gint w, gint h,
2922 gboolean user, gboolean final, gboolean force_reply)
2926 gboolean send_resize_client;
2927 gboolean moved = FALSE, resized = FALSE, rootmoved = FALSE;
2928 gboolean fmoved, fresized;
2929 guint fdecor = self->frame->decorations;
2930 gboolean fhorz = self->frame->max_horz;
2931 gboolean fvert = self->frame->max_vert;
2932 gint logicalw, logicalh;
2934 /* find the new x, y, width, and height (and logical size) */
2935 client_try_configure(self, &x, &y, &w, &h, &logicalw, &logicalh, user);
2937 /* set the logical size if things changed */
2938 if (!(w == self->area.width && h == self->area.height))
2939 SIZE_SET(self->logical_size, logicalw, logicalh);
2941 /* figure out if we moved or resized or what */
2942 moved = (x != self->area.x || y != self->area.y);
2943 resized = (w != self->area.width || h != self->area.height);
2945 oldw = self->area.width;
2946 oldh = self->area.height;
2947 oldframe = self->frame->area;
2948 RECT_SET(self->area, x, y, w, h);
2950 /* for app-requested resizes, always resize if 'resized' is true.
2951 for user-requested ones, only resize if final is true, or when
2952 resizing in redraw mode */
2953 send_resize_client = ((!user && resized) ||
2955 (resized && config_resize_redraw))));
2957 /* if the client is enlarging, then resize the client before the frame */
2958 if (send_resize_client && (w > oldw || h > oldh)) {
2959 XMoveResizeWindow(obt_display, self->window,
2960 self->frame->size.left, self->frame->size.top,
2961 MAX(w, oldw), MAX(h, oldh));
2962 frame_adjust_client_area(self->frame);
2965 /* find the frame's dimensions and move/resize it */
2969 /* if decorations changed, then readjust everything for the frame */
2970 if (self->decorations != fdecor ||
2971 self->max_horz != fhorz || self->max_vert != fvert)
2973 fmoved = fresized = TRUE;
2976 /* adjust the frame */
2977 if (fmoved || fresized) {
2978 gulong ignore_start;
2980 ignore_start = event_start_ignore_all_enters();
2982 /* replay pending pointer event before move the window, in case it
2983 would change what window gets the event */
2984 mouse_replay_pointer();
2986 frame_adjust_area(self->frame, fmoved, fresized, FALSE);
2989 event_end_ignore_all_enters(ignore_start);
2992 if (!user || final) {
2993 gint oldrx = self->root_pos.x;
2994 gint oldry = self->root_pos.y;
2995 /* we have reset the client to 0 border width, so don't include
2996 it in these coords */
2997 POINT_SET(self->root_pos,
2998 self->frame->area.x + self->frame->size.left -
3000 self->frame->area.y + self->frame->size.top -
3001 self->border_width);
3002 if (self->root_pos.x != oldrx || self->root_pos.y != oldry)
3006 /* This is kinda tricky and should not be changed.. let me explain!
3008 When user = FALSE, then the request is coming from the application
3009 itself, and we are more strict about when to send a synthetic
3010 ConfigureNotify. We strictly follow the rules of the ICCCM sec 4.1.5
3011 in this case (if force_reply is true)
3013 When user = TRUE, then the request is coming from "us", like when we
3014 maximize a window or something. In this case we are more lenient. We
3015 used to follow the same rules as above, but _Java_ Swing can't handle
3016 this. So just to appease Swing, when user = TRUE, we always send
3017 a synthetic ConfigureNotify to give the window its root coordinates.
3019 if ((!user && !resized && (rootmoved || force_reply)) ||
3020 (user && final && rootmoved))
3024 event.type = ConfigureNotify;
3025 event.xconfigure.display = obt_display;
3026 event.xconfigure.event = self->window;
3027 event.xconfigure.window = self->window;
3029 ob_debug("Sending ConfigureNotify to %s for %d,%d %dx%d",
3030 self->title, self->root_pos.x, self->root_pos.y, w, h);
3032 /* root window real coords */
3033 event.xconfigure.x = self->root_pos.x;
3034 event.xconfigure.y = self->root_pos.y;
3035 event.xconfigure.width = w;
3036 event.xconfigure.height = h;
3037 event.xconfigure.border_width = self->border_width;
3038 event.xconfigure.above = None;
3039 event.xconfigure.override_redirect = FALSE;
3040 XSendEvent(event.xconfigure.display, event.xconfigure.window,
3041 FALSE, StructureNotifyMask, &event);
3044 /* if the client is shrinking, then resize the frame before the client.
3046 both of these resize sections may run, because the top one only resizes
3047 in the direction that is growing
3049 if (send_resize_client && (w <= oldw || h <= oldh)) {
3050 frame_adjust_client_area(self->frame);
3051 XMoveResizeWindow(obt_display, self->window,
3052 self->frame->size.left, self->frame->size.top, w, h);
3055 XFlush(obt_display);
3057 /* if it moved between monitors, then this can affect the stacking
3058 layer of this window or others - for fullscreen windows */
3059 if (screen_find_monitor(&self->frame->area) !=
3060 screen_find_monitor(&oldframe))
3062 client_calc_layer(self);
3066 void client_fullscreen(ObClient *self, gboolean fs)
3070 if (!(self->functions & OB_CLIENT_FUNC_FULLSCREEN) || /* can't */
3071 self->fullscreen == fs) return; /* already done */
3073 self->fullscreen = fs;
3074 client_change_state(self); /* change the state hints on the client */
3077 self->pre_fullscreen_area = self->area;
3078 /* if the window is maximized, its area isn't all that meaningful.
3079 save its premax area instead. */
3080 if (self->max_horz) {
3081 self->pre_fullscreen_area.x = self->pre_max_area.x;
3082 self->pre_fullscreen_area.width = self->pre_max_area.width;
3084 if (self->max_vert) {
3085 self->pre_fullscreen_area.y = self->pre_max_area.y;
3086 self->pre_fullscreen_area.height = self->pre_max_area.height;
3089 /* these will help configure_full figure out where to fullscreen
3093 w = self->area.width;
3094 h = self->area.height;
3096 g_assert(self->pre_fullscreen_area.width > 0 &&
3097 self->pre_fullscreen_area.height > 0);
3099 x = self->pre_fullscreen_area.x;
3100 y = self->pre_fullscreen_area.y;
3101 w = self->pre_fullscreen_area.width;
3102 h = self->pre_fullscreen_area.height;
3103 RECT_SET(self->pre_fullscreen_area, 0, 0, 0, 0);
3106 ob_debug("Window %s going fullscreen (%d)",
3107 self->title, self->fullscreen);
3109 client_setup_decor_and_functions(self, FALSE);
3110 client_move_resize(self, x, y, w, h);
3112 /* and adjust our layer/stacking. do this after resizing the window,
3113 and applying decorations, because windows which fill the screen are
3114 considered "fullscreen" and it affects their layer */
3115 client_calc_layer(self);
3118 /* try focus us when we go into fullscreen mode */
3123 static void client_iconify_recursive(ObClient *self,
3124 gboolean iconic, gboolean curdesk,
3125 gboolean hide_animation)
3128 gboolean changed = FALSE;
3130 if (self->iconic != iconic) {
3131 ob_debug("%sconifying window: 0x%lx", (iconic ? "I" : "Uni"),
3135 /* don't let non-normal windows iconify along with their parents
3137 if (client_normal(self)) {
3138 self->iconic = iconic;
3140 /* update the focus lists.. iconic windows go to the bottom of
3142 focus_order_to_bottom(self);
3147 self->iconic = iconic;
3149 if (curdesk && self->desktop != screen_desktop &&
3150 self->desktop != DESKTOP_ALL)
3151 client_set_desktop(self, screen_desktop, FALSE, FALSE);
3153 /* this puts it after the current focused window */
3154 focus_order_remove(self);
3155 focus_order_add_new(self);
3162 client_change_state(self);
3163 if (config_animate_iconify && !hide_animation)
3164 frame_begin_iconify_animation(self->frame, iconic);
3165 /* do this after starting the animation so it doesn't flash */
3166 client_showhide(self);
3168 hooks_queue((iconic ? OB_HOOK_WIN_ICONIC : OB_HOOK_WIN_UNICONIC),
3172 /* iconify all direct transients, and deiconify all transients
3174 for (it = self->transients; it; it = g_slist_next(it))
3175 if (it->data != self)
3176 if (client_is_direct_child(self, it->data) || !iconic)
3177 client_iconify_recursive(it->data, iconic, curdesk,
3181 void client_iconify(ObClient *self, gboolean iconic, gboolean curdesk,
3182 gboolean hide_animation)
3184 if (self->functions & OB_CLIENT_FUNC_ICONIFY || !iconic) {
3185 /* move up the transient chain as far as possible first */
3186 self = client_search_top_direct_parent(self);
3187 client_iconify_recursive(self, iconic, curdesk, hide_animation);
3191 void client_maximize(ObClient *self, gboolean max, gint dir)
3195 g_assert(dir == 0 || dir == 1 || dir == 2);
3196 if (!(self->functions & OB_CLIENT_FUNC_MAXIMIZE) && max) return;/* can't */
3198 /* check if already done */
3200 if (dir == 0 && self->max_horz && self->max_vert) return;
3201 if (dir == 1 && self->max_horz) return;
3202 if (dir == 2 && self->max_vert) return;
3204 if (dir == 0 && !self->max_horz && !self->max_vert) return;
3205 if (dir == 1 && !self->max_horz) return;
3206 if (dir == 2 && !self->max_vert) return;
3209 /* these will help configure_full figure out which screen to fill with
3213 w = self->area.width;
3214 h = self->area.height;
3217 if ((dir == 0 || dir == 1) && !self->max_horz) { /* horz */
3218 RECT_SET(self->pre_max_area,
3219 self->area.x, self->pre_max_area.y,
3220 self->area.width, self->pre_max_area.height);
3222 if ((dir == 0 || dir == 2) && !self->max_vert) { /* vert */
3223 RECT_SET(self->pre_max_area,
3224 self->pre_max_area.x, self->area.y,
3225 self->pre_max_area.width, self->area.height);
3228 if ((dir == 0 || dir == 1) && self->max_horz) { /* horz */
3229 g_assert(self->pre_max_area.width > 0);
3231 x = self->pre_max_area.x;
3232 w = self->pre_max_area.width;
3234 RECT_SET(self->pre_max_area, 0, self->pre_max_area.y,
3235 0, self->pre_max_area.height);
3237 if ((dir == 0 || dir == 2) && self->max_vert) { /* vert */
3238 g_assert(self->pre_max_area.height > 0);
3240 y = self->pre_max_area.y;
3241 h = self->pre_max_area.height;
3243 RECT_SET(self->pre_max_area, self->pre_max_area.x, 0,
3244 self->pre_max_area.width, 0);
3248 if (dir == 0 || dir == 1) /* horz */
3249 self->max_horz = max;
3250 if (dir == 0 || dir == 2) /* vert */
3251 self->max_vert = max;
3253 client_change_state(self); /* change the state hints on the client */
3255 client_setup_decor_and_functions(self, FALSE);
3256 client_move_resize(self, x, y, w, h);
3258 hooks_queue((max ? OB_HOOK_WIN_MAX : OB_HOOK_WIN_UNMAX), self);
3261 void client_shade(ObClient *self, gboolean shade)
3263 if ((!(self->functions & OB_CLIENT_FUNC_SHADE) &&
3264 shade) || /* can't shade */
3265 self->shaded == shade) return; /* already done */
3267 self->shaded = shade;
3268 client_change_state(self);
3269 client_change_wm_state(self); /* the window is being hidden/shown */
3270 /* resize the frame to just the titlebar */
3271 frame_adjust_area(self->frame, FALSE, TRUE, FALSE);
3273 hooks_queue((shade ? OB_HOOK_WIN_SHADE : OB_HOOK_WIN_UNSHADE), self);
3276 static void client_ping_event(ObClient *self, gboolean dead)
3278 if (self->not_responding != dead) {
3279 self->not_responding = dead;
3280 client_update_title(self);
3283 /* the client isn't responding, so ask to kill it */
3284 client_prompt_kill(self);
3286 /* it came back to life ! */
3288 if (self->kill_prompt) {
3289 prompt_unref(self->kill_prompt);
3290 self->kill_prompt = NULL;
3293 self->kill_level = 0;
3298 void client_close(ObClient *self)
3300 if (!(self->functions & OB_CLIENT_FUNC_CLOSE)) return;
3302 /* if closing an internal obprompt, that is just cancelling it */
3304 prompt_cancel(self->prompt);
3308 /* in the case that the client provides no means to requesting that it
3309 close, we just kill it */
3310 if (!self->delete_window)
3311 /* don't use client_kill(), we should only kill based on PID in
3312 response to a lack of PING replies */
3313 XKillClient(obt_display, self->window);
3315 /* request the client to close with WM_DELETE_WINDOW */
3316 OBT_PROP_MSG_TO(self->window, self->window, WM_PROTOCOLS,
3317 OBT_PROP_ATOM(WM_DELETE_WINDOW), event_curtime,
3318 0, 0, 0, NoEventMask);
3320 /* we're trying to close the window, so see if it is responding. if it
3321 is not, then we will let them kill the window */
3323 ping_start(self, client_ping_event);
3325 /* if we already know the window isn't responding (maybe they clicked
3326 no in the kill dialog but it hasn't come back to life), then show
3328 if (self->not_responding)
3329 client_prompt_kill(self);
3333 #define OB_KILL_RESULT_NO 0
3334 #define OB_KILL_RESULT_YES 1
3336 static gboolean client_kill_requested(ObPrompt *p, gint result, gpointer data)
3338 ObClient *self = data;
3340 if (result == OB_KILL_RESULT_YES)
3342 return TRUE; /* call the cleanup func */
3345 static void client_kill_cleanup(ObPrompt *p, gpointer data)
3347 ObClient *self = data;
3349 g_assert(p == self->kill_prompt);
3351 prompt_unref(self->kill_prompt);
3352 self->kill_prompt = NULL;
3355 static void client_prompt_kill(ObClient *self)
3357 /* check if we're already prompting */
3358 if (!self->kill_prompt) {
3359 ObPromptAnswer answers[] = {
3360 { 0, OB_KILL_RESULT_NO },
3361 { 0, OB_KILL_RESULT_YES }
3364 const gchar *y, *title;
3366 title = self->original_title;
3367 if (title[0] == '\0') {
3368 /* empty string, so use its parent */
3369 ObClient *p = client_search_top_direct_parent(self);
3370 if (p) title = p->original_title;
3373 if (client_on_localhost(self)) {
3376 if (self->kill_level == 0)
3382 (_("The window \"%s\" does not seem to be responding. Do you want to force it to exit by sending the %s signal?"),
3384 y = _("End Process");
3388 (_("The window \"%s\" does not seem to be responding. Do you want to disconnect it from the X server?"),
3390 y = _("Disconnect");
3392 /* set the dialog buttons' text */
3393 answers[0].text = _("Cancel"); /* "no" */
3394 answers[1].text = y; /* "yes" */
3396 self->kill_prompt = prompt_new(m, NULL, answers,
3397 sizeof(answers)/sizeof(answers[0]),
3398 OB_KILL_RESULT_NO, /* default = no */
3399 OB_KILL_RESULT_NO, /* cancel = no */
3400 client_kill_requested,
3401 client_kill_cleanup,
3406 prompt_show(self->kill_prompt, self, TRUE);
3409 void client_kill(ObClient *self)
3411 /* don't kill our own windows */
3412 if (self->prompt) return;
3414 if (client_on_localhost(self) && self->pid) {
3415 /* running on the local host */
3416 if (self->kill_level == 0) {
3417 ob_debug("killing window 0x%x with pid %lu, with SIGTERM",
3418 self->window, self->pid);
3419 kill(self->pid, SIGTERM);
3422 /* show that we're trying to kill it */
3423 client_update_title(self);
3426 ob_debug("killing window 0x%x with pid %lu, with SIGKILL",
3427 self->window, self->pid);
3428 kill(self->pid, SIGKILL); /* kill -9 */
3432 /* running on a remote host */
3433 XKillClient(obt_display, self->window);
3437 void client_hilite(ObClient *self, gboolean hilite)
3439 if (self->demands_attention == hilite)
3440 return; /* no change */
3442 /* don't allow focused windows to hilite */
3443 self->demands_attention = hilite && !client_focused(self);
3444 if (self->frame != NULL) { /* if we're mapping, just set the state */
3445 if (self->demands_attention)
3446 frame_flash_start(self->frame);
3448 frame_flash_stop(self->frame);
3449 client_change_state(self);
3453 static void client_set_desktop_recursive(ObClient *self,
3461 if (target != self->desktop && self->type != OB_CLIENT_TYPE_DESKTOP) {
3463 ob_debug("Setting desktop %u", target+1);
3465 g_assert(target < screen_num_desktops || target == DESKTOP_ALL);
3467 old = self->desktop;
3468 self->desktop = target;
3469 OBT_PROP_SET32(self->window, NET_WM_DESKTOP, CARDINAL, target);
3470 /* the frame can display the current desktop state */
3471 frame_adjust_state(self->frame);
3472 /* 'move' the window to the new desktop */
3476 /* raise if it was not already on the desktop */
3477 if (old != DESKTOP_ALL && !dontraise)
3478 stacking_raise(CLIENT_AS_WINDOW(self));
3479 if (STRUT_EXISTS(self->strut))
3480 screen_update_areas();
3482 /* the new desktop's geometry may be different, so we may need to
3483 resize, for example if we are maximized */
3484 client_reconfigure(self, FALSE);
3486 if (old != self->desktop)
3487 hooks_queue(OB_HOOK_WIN_DESK_CHANGE, self);
3490 /* move all transients */
3491 for (it = self->transients; it; it = g_slist_next(it))
3492 if (it->data != self)
3493 if (client_is_direct_child(self, it->data))
3494 client_set_desktop_recursive(it->data, target,
3495 donthide, dontraise);
3498 void client_set_desktop(ObClient *self, guint target,
3499 gboolean donthide, gboolean dontraise)
3501 self = client_search_top_direct_parent(self);
3502 client_set_desktop_recursive(self, target, donthide, dontraise);
3505 gboolean client_is_direct_child(ObClient *parent, ObClient *child)
3507 while (child != parent && (child = client_direct_parent(child)));
3508 return child == parent;
3511 ObClient *client_search_modal_child(ObClient *self)
3516 for (it = self->transients; it; it = g_slist_next(it)) {
3517 ObClient *c = it->data;
3518 if ((ret = client_search_modal_child(c))) return ret;
3519 if (c->modal) return c;
3524 gboolean client_validate(ObClient *self)
3528 XSync(obt_display, FALSE); /* get all events on the server */
3530 if (XCheckTypedWindowEvent(obt_display, self->window, DestroyNotify, &e) ||
3531 XCheckTypedWindowEvent(obt_display, self->window, UnmapNotify, &e))
3533 XPutBackEvent(obt_display, &e);
3540 void client_set_wm_state(ObClient *self, glong state)
3542 if (state == self->wmstate) return; /* no change */
3546 client_iconify(self, TRUE, TRUE, FALSE);
3549 client_iconify(self, FALSE, TRUE, FALSE);
3554 void client_set_state(ObClient *self, Atom action, glong data1, glong data2)
3556 gboolean shaded = self->shaded;
3557 gboolean fullscreen = self->fullscreen;
3558 gboolean undecorated = self->undecorated;
3559 gboolean locked = self->locked;
3560 gboolean max_horz = self->max_horz;
3561 gboolean max_vert = self->max_vert;
3562 gboolean modal = self->modal;
3563 gboolean iconic = self->iconic;
3564 gboolean demands_attention = self->demands_attention;
3565 gboolean above = self->above;
3566 gboolean below = self->below;
3570 if (!(action == OBT_PROP_ATOM(NET_WM_STATE_ADD) ||
3571 action == OBT_PROP_ATOM(NET_WM_STATE_REMOVE) ||
3572 action == OBT_PROP_ATOM(NET_WM_STATE_TOGGLE)))
3573 /* an invalid action was passed to the client message, ignore it */
3576 for (i = 0; i < 2; ++i) {
3577 Atom state = i == 0 ? data1 : data2;
3579 if (!state) continue;
3581 /* if toggling, then pick whether we're adding or removing */
3582 if (action == OBT_PROP_ATOM(NET_WM_STATE_TOGGLE)) {
3583 if (state == OBT_PROP_ATOM(NET_WM_STATE_MODAL))
3585 else if (state == OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_VERT))
3586 value = self->max_vert;
3587 else if (state == OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_HORZ))
3588 value = self->max_horz;
3589 else if (state == OBT_PROP_ATOM(NET_WM_STATE_SHADED))
3591 else if (state == OBT_PROP_ATOM(NET_WM_STATE_SKIP_TASKBAR))
3592 value = self->skip_taskbar;
3593 else if (state == OBT_PROP_ATOM(NET_WM_STATE_SKIP_PAGER))
3594 value = self->skip_pager;
3595 else if (state == OBT_PROP_ATOM(NET_WM_STATE_HIDDEN))
3596 value = self->iconic;
3597 else if (state == OBT_PROP_ATOM(NET_WM_STATE_FULLSCREEN))
3599 else if (state == OBT_PROP_ATOM(NET_WM_STATE_ABOVE))
3600 value = self->above;
3601 else if (state == OBT_PROP_ATOM(NET_WM_STATE_BELOW))
3602 value = self->below;
3603 else if (state == OBT_PROP_ATOM(NET_WM_STATE_DEMANDS_ATTENTION))
3604 value = self->demands_attention;
3605 else if (state == OBT_PROP_ATOM(OB_WM_STATE_UNDECORATED))
3606 value = undecorated;
3607 else if (state == OBT_PROP_ATOM(OB_WM_STATE_LOCKED))
3609 action = value ? OBT_PROP_ATOM(NET_WM_STATE_REMOVE) :
3610 OBT_PROP_ATOM(NET_WM_STATE_ADD);
3613 value = action == OBT_PROP_ATOM(NET_WM_STATE_ADD);
3614 if (state == OBT_PROP_ATOM(NET_WM_STATE_MODAL)) {
3616 } else if (state == OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_VERT)) {
3618 } else if (state == OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_HORZ)) {
3620 } else if (state == OBT_PROP_ATOM(NET_WM_STATE_SHADED)) {
3622 } else if (state == OBT_PROP_ATOM(NET_WM_STATE_SKIP_TASKBAR)) {
3623 self->skip_taskbar = value;
3624 } else if (state == OBT_PROP_ATOM(NET_WM_STATE_SKIP_PAGER)) {
3625 self->skip_pager = value;
3626 } else if (state == OBT_PROP_ATOM(NET_WM_STATE_HIDDEN)) {
3628 } else if (state == OBT_PROP_ATOM(NET_WM_STATE_FULLSCREEN)) {
3630 } else if (state == OBT_PROP_ATOM(NET_WM_STATE_ABOVE)) {
3632 /* only unset below when setting above, otherwise you can't get to
3636 } else if (state == OBT_PROP_ATOM(NET_WM_STATE_BELOW)) {
3637 /* and vice versa */
3641 } else if (state == OBT_PROP_ATOM(NET_WM_STATE_DEMANDS_ATTENTION)){
3642 demands_attention = value;
3643 } else if (state == OBT_PROP_ATOM(OB_WM_STATE_UNDECORATED)) {
3644 undecorated = value;
3645 } else if (state == OBT_PROP_ATOM(OB_WM_STATE_LOCKED)) {
3650 if (max_horz != self->max_horz || max_vert != self->max_vert) {
3651 if (max_horz != self->max_horz && max_vert != self->max_vert) {
3653 if (max_horz == max_vert) { /* both going the same way */
3654 client_maximize(self, max_horz, 0);
3656 client_maximize(self, max_horz, 1);
3657 client_maximize(self, max_vert, 2);
3661 if (max_horz != self->max_horz)
3662 client_maximize(self, max_horz, 1);
3664 client_maximize(self, max_vert, 2);
3667 /* change fullscreen state before shading, as it will affect if the window
3669 if (fullscreen != self->fullscreen)
3670 client_fullscreen(self, fullscreen);
3671 if (shaded != self->shaded)
3672 client_shade(self, shaded);
3673 if (undecorated != self->undecorated)
3674 client_set_undecorated(self, undecorated);
3675 if (locked != self->locked)
3676 client_set_locked(self, locked);
3677 if (above != self->above || below != self->below) {
3678 self->above = above;
3679 self->below = below;
3680 client_calc_layer(self);
3683 if (modal != self->modal) {
3684 self->modal = modal;
3685 /* when a window changes modality, then its stacking order with its
3686 transients needs to change */
3687 stacking_raise(CLIENT_AS_WINDOW(self));
3689 /* it also may get focused. if something is focused that shouldn't
3690 be focused anymore, then move the focus */
3691 if (focus_client && client_focus_target(focus_client) != focus_client)
3692 client_focus(focus_client);
3695 if (iconic != self->iconic)
3696 client_iconify(self, iconic, FALSE, FALSE);
3698 if (demands_attention != self->demands_attention)
3699 client_hilite(self, demands_attention);
3701 client_change_state(self); /* change the hint to reflect these changes */
3704 ObClient *client_focus_target(ObClient *self)
3706 ObClient *child = NULL;
3708 child = client_search_modal_child(self);
3709 if (child) return child;
3713 gboolean client_can_focus(ObClient *self)
3715 /* choose the correct target */
3716 self = client_focus_target(self);
3718 if (!self->frame->visible)
3721 if (!(self->can_focus || self->focus_notify))
3727 gboolean client_focus(ObClient *self)
3731 XkbGetState(obt_display, XkbUseCoreKbd, &state);
3732 if (state.locked_mods & 128)
3736 /* we might not focus this window, so if we have modal children which would
3737 be focused instead, bring them to this desktop */
3738 client_bring_modal_windows(self);
3740 /* choose the correct target */
3741 self = client_focus_target(self);
3743 if (!client_can_focus(self)) {
3744 ob_debug_type(OB_DEBUG_FOCUS,
3745 "Client %s can't be focused", self->title);
3749 ob_debug_type(OB_DEBUG_FOCUS,
3750 "Focusing client \"%s\" (0x%x) at time %u",
3751 self->title, self->window, event_curtime);
3753 /* if using focus_delay, stop the timer now so that focus doesn't
3755 event_halt_focus_delay();
3757 event_cancel_all_key_grabs();
3759 obt_display_ignore_errors(TRUE);
3761 if (self->can_focus) {
3762 /* This can cause a BadMatch error with CurrentTime, or if an app
3763 passed in a bad time for _NET_WM_ACTIVE_WINDOW. */
3764 XSetInputFocus(obt_display, self->window, RevertToPointerRoot,
3768 if (self->focus_notify) {
3770 ce.xclient.type = ClientMessage;
3771 ce.xclient.message_type = OBT_PROP_ATOM(WM_PROTOCOLS);
3772 ce.xclient.display = obt_display;
3773 ce.xclient.window = self->window;
3774 ce.xclient.format = 32;
3775 ce.xclient.data.l[0] = OBT_PROP_ATOM(WM_TAKE_FOCUS);
3776 ce.xclient.data.l[1] = event_curtime;
3777 ce.xclient.data.l[2] = 0l;
3778 ce.xclient.data.l[3] = 0l;
3779 ce.xclient.data.l[4] = 0l;
3780 XSendEvent(obt_display, self->window, FALSE, NoEventMask, &ce);
3783 obt_display_ignore_errors(FALSE);
3785 ob_debug_type(OB_DEBUG_FOCUS, "Error focusing? %d",
3786 obt_display_error_occured);
3787 return !obt_display_error_occured;
3790 static void client_present(ObClient *self, gboolean here, gboolean raise,
3793 if (client_normal(self) && screen_showing_desktop)
3794 screen_show_desktop(FALSE, self);
3796 client_iconify(self, FALSE, here, FALSE);
3797 if (self->desktop != DESKTOP_ALL &&
3798 self->desktop != screen_desktop)
3801 client_set_desktop(self, screen_desktop, FALSE, TRUE);
3803 screen_set_desktop(self->desktop, FALSE);
3804 } else if (!self->frame->visible)
3805 /* if its not visible for other reasons, then don't mess
3808 if (self->shaded && unshade)
3809 client_shade(self, FALSE);
3811 stacking_raise(CLIENT_AS_WINDOW(self));
3816 /* this function exists to map to the client_activate message in the ewmh,
3817 the user arg is unused because nobody uses it correctly anyway. */
3818 void client_activate(ObClient *self, gboolean here, gboolean raise,
3819 gboolean unshade, gboolean user)
3821 client_present(self, here, raise, unshade);
3824 static void client_bring_windows_recursive(ObClient *self,
3832 for (it = self->transients; it; it = g_slist_next(it))
3833 client_bring_windows_recursive(it->data, desktop,
3834 helpers, modals, iconic);
3836 if (((helpers && client_helper(self)) ||
3837 (modals && self->modal)) &&
3838 ((self->desktop != desktop && self->desktop != DESKTOP_ALL) ||
3839 (iconic && self->iconic)))
3841 if (iconic && self->iconic)
3842 client_iconify(self, FALSE, TRUE, FALSE);
3844 client_set_desktop(self, desktop, FALSE, FALSE);
3848 void client_bring_helper_windows(ObClient *self)
3850 client_bring_windows_recursive(self, self->desktop, TRUE, FALSE, FALSE);
3853 void client_bring_modal_windows(ObClient *self)
3855 client_bring_windows_recursive(self, self->desktop, FALSE, TRUE, TRUE);
3858 gboolean client_focused(ObClient *self)
3860 return self == focus_client;
3863 RrImage* client_icon(ObClient *self)
3865 RrImage *ret = NULL;
3868 ret = self->icon_set;
3869 else if (self->parents) {
3871 for (it = self->parents; it && !ret; it = g_slist_next(it))
3872 ret = client_icon(it->data);
3875 ret = client_default_icon;
3879 void client_set_layer(ObClient *self, gint layer)
3883 self->above = FALSE;
3884 } else if (layer == 0) {
3885 self->below = self->above = FALSE;
3887 self->below = FALSE;
3890 client_calc_layer(self);
3891 client_change_state(self); /* reflect this in the state hints */
3894 void client_set_locked(ObClient *self, gboolean locked)
3896 if (self->locked != locked) {
3897 self->locked = locked;
3898 client_change_state(self);
3902 void client_set_undecorated(ObClient *self, gboolean undecorated)
3904 if (self->undecorated != undecorated &&
3905 /* don't let it undecorate if the function is missing, but let
3907 (self->functions & OB_CLIENT_FUNC_UNDECORATE || !undecorated))
3909 self->undecorated = undecorated;
3910 client_setup_decor_and_functions(self, TRUE);
3911 client_change_state(self); /* reflect this in the state hints */
3913 hooks_queue((undecorated ?
3914 OB_HOOK_WIN_UNDECORATED : OB_HOOK_WIN_DECORATED), self);
3918 guint client_monitor(ObClient *self)
3920 return screen_find_monitor(&self->frame->area);
3923 ObClient *client_direct_parent(ObClient *self)
3925 if (!self->parents) return NULL;
3926 if (self->transient_for_group) return NULL;
3927 return self->parents->data;
3930 ObClient *client_search_top_direct_parent(ObClient *self)
3933 while ((p = client_direct_parent(self))) self = p;
3937 static GSList *client_search_all_top_parents_internal(ObClient *self,
3939 ObStackingLayer layer)
3944 /* move up the direct transient chain as far as possible */
3945 while ((p = client_direct_parent(self)) &&
3946 (!bylayer || p->layer == layer))
3950 ret = g_slist_prepend(NULL, self);
3952 ret = g_slist_copy(self->parents);
3957 GSList *client_search_all_top_parents(ObClient *self)
3959 return client_search_all_top_parents_internal(self, FALSE, 0);
3962 GSList *client_search_all_top_parents_layer(ObClient *self)
3964 return client_search_all_top_parents_internal(self, TRUE, self->layer);
3967 ObClient *client_search_focus_parent(ObClient *self)
3971 for (it = self->parents; it; it = g_slist_next(it))
3972 if (client_focused(it->data)) return it->data;
3977 ObClient *client_search_parent(ObClient *self, ObClient *search)
3981 for (it = self->parents; it; it = g_slist_next(it))
3982 if (it->data == search) return search;
3987 ObClient *client_search_transient(ObClient *self, ObClient *search)
3991 for (sit = self->transients; sit; sit = g_slist_next(sit)) {
3992 if (sit->data == search)
3994 if (client_search_transient(sit->data, search))
4000 static void detect_edge(Rect area, ObDirection dir,
4001 gint my_head, gint my_size,
4002 gint my_edge_start, gint my_edge_size,
4003 gint *dest, gboolean *near_edge)
4005 gint edge_start, edge_size, head, tail;
4006 gboolean skip_head = FALSE, skip_tail = FALSE;
4009 case OB_DIRECTION_NORTH:
4010 case OB_DIRECTION_SOUTH:
4011 edge_start = area.x;
4012 edge_size = area.width;
4014 case OB_DIRECTION_EAST:
4015 case OB_DIRECTION_WEST:
4016 edge_start = area.y;
4017 edge_size = area.height;
4020 g_assert_not_reached();
4023 /* do we collide with this window? */
4024 if (!RANGES_INTERSECT(my_edge_start, my_edge_size,
4025 edge_start, edge_size))
4029 case OB_DIRECTION_NORTH:
4030 head = RECT_BOTTOM(area);
4031 tail = RECT_TOP(area);
4033 case OB_DIRECTION_SOUTH:
4034 head = RECT_TOP(area);
4035 tail = RECT_BOTTOM(area);
4037 case OB_DIRECTION_WEST:
4038 head = RECT_RIGHT(area);
4039 tail = RECT_LEFT(area);
4041 case OB_DIRECTION_EAST:
4042 head = RECT_LEFT(area);
4043 tail = RECT_RIGHT(area);
4046 g_assert_not_reached();
4049 case OB_DIRECTION_NORTH:
4050 case OB_DIRECTION_WEST:
4051 /* check if our window is past the head of this window */
4052 if (my_head <= head + 1)
4054 /* check if our window's tail is past the tail of this window */
4055 if (my_head + my_size - 1 <= tail)
4057 /* check if the head of this window is closer than the previously
4058 chosen edge (take into account that the previously chosen
4059 edge might have been a tail, not a head) */
4060 if (head + (*near_edge ? 0 : my_size) <= *dest)
4062 /* check if the tail of this window is closer than the previously
4063 chosen edge (take into account that the previously chosen
4064 edge might have been a head, not a tail) */
4065 if (tail - (!*near_edge ? 0 : my_size) <= *dest)
4068 case OB_DIRECTION_SOUTH:
4069 case OB_DIRECTION_EAST:
4070 /* check if our window is past the head of this window */
4071 if (my_head >= head - 1)
4073 /* check if our window's tail is past the tail of this window */
4074 if (my_head - my_size + 1 >= tail)
4076 /* check if the head of this window is closer than the previously
4077 chosen edge (take into account that the previously chosen
4078 edge might have been a tail, not a head) */
4079 if (head - (*near_edge ? 0 : my_size) >= *dest)
4081 /* check if the tail of this window is closer than the previously
4082 chosen edge (take into account that the previously chosen
4083 edge might have been a head, not a tail) */
4084 if (tail + (!*near_edge ? 0 : my_size) >= *dest)
4088 g_assert_not_reached();
4091 ob_debug("my head %d size %d", my_head, my_size);
4092 ob_debug("head %d tail %d dest %d", head, tail, *dest);
4094 ob_debug("using near edge %d", head);
4098 else if (!skip_tail) {
4099 ob_debug("using far edge %d", tail);
4105 void client_find_edge_directional(ObClient *self, ObDirection dir,
4106 gint my_head, gint my_size,
4107 gint my_edge_start, gint my_edge_size,
4108 gint *dest, gboolean *near_edge)
4115 a = screen_area(self->desktop, SCREEN_AREA_ALL_MONITORS,
4116 &self->frame->area);
4117 mon = screen_area(self->desktop, SCREEN_AREA_ONE_MONITOR,
4118 &self->frame->area);
4121 case OB_DIRECTION_NORTH:
4122 if (my_head >= RECT_TOP(*mon) + 1)
4123 edge = RECT_TOP(*mon) - 1;
4125 edge = RECT_TOP(*a) - 1;
4127 case OB_DIRECTION_SOUTH:
4128 if (my_head <= RECT_BOTTOM(*mon) - 1)
4129 edge = RECT_BOTTOM(*mon) + 1;
4131 edge = RECT_BOTTOM(*a) + 1;
4133 case OB_DIRECTION_EAST:
4134 if (my_head <= RECT_RIGHT(*mon) - 1)
4135 edge = RECT_RIGHT(*mon) + 1;
4137 edge = RECT_RIGHT(*a) + 1;
4139 case OB_DIRECTION_WEST:
4140 if (my_head >= RECT_LEFT(*mon) + 1)
4141 edge = RECT_LEFT(*mon) - 1;
4143 edge = RECT_LEFT(*a) - 1;
4146 g_assert_not_reached();
4148 /* default to the far edge, then narrow it down */
4152 for (it = client_list; it; it = g_list_next(it)) {
4153 ObClient *cur = it->data;
4155 /* skip windows to not bump into */
4160 if (self->desktop != cur->desktop && cur->desktop != DESKTOP_ALL &&
4161 cur->desktop != screen_desktop)
4164 ob_debug("trying window %s", cur->title);
4166 detect_edge(cur->frame->area, dir, my_head, my_size, my_edge_start,
4167 my_edge_size, dest, near_edge);
4169 dock_get_area(&dock_area);
4170 detect_edge(dock_area, dir, my_head, my_size, my_edge_start,
4171 my_edge_size, dest, near_edge);
4176 void client_find_move_directional(ObClient *self, ObDirection dir,
4180 gint e, e_start, e_size;
4184 case OB_DIRECTION_EAST:
4185 head = RECT_RIGHT(self->frame->area);
4186 size = self->frame->area.width;
4187 e_start = RECT_TOP(self->frame->area);
4188 e_size = self->frame->area.height;
4190 case OB_DIRECTION_WEST:
4191 head = RECT_LEFT(self->frame->area);
4192 size = self->frame->area.width;
4193 e_start = RECT_TOP(self->frame->area);
4194 e_size = self->frame->area.height;
4196 case OB_DIRECTION_NORTH:
4197 head = RECT_TOP(self->frame->area);
4198 size = self->frame->area.height;
4199 e_start = RECT_LEFT(self->frame->area);
4200 e_size = self->frame->area.width;
4202 case OB_DIRECTION_SOUTH:
4203 head = RECT_BOTTOM(self->frame->area);
4204 size = self->frame->area.height;
4205 e_start = RECT_LEFT(self->frame->area);
4206 e_size = self->frame->area.width;
4209 g_assert_not_reached();
4212 client_find_edge_directional(self, dir, head, size,
4213 e_start, e_size, &e, &near);
4214 *x = self->frame->area.x;
4215 *y = self->frame->area.y;
4217 case OB_DIRECTION_EAST:
4218 if (near) e -= self->frame->area.width;
4222 case OB_DIRECTION_WEST:
4224 else e -= self->frame->area.width;
4227 case OB_DIRECTION_NORTH:
4229 else e -= self->frame->area.height;
4232 case OB_DIRECTION_SOUTH:
4233 if (near) e -= self->frame->area.height;
4238 g_assert_not_reached();
4240 frame_frame_gravity(self->frame, x, y);
4243 void client_find_resize_directional(ObClient *self, ObDirection side,
4245 gint *x, gint *y, gint *w, gint *h)
4248 gint e, e_start, e_size, delta;
4253 case OB_DIRECTION_EAST:
4254 head = RECT_RIGHT(self->frame->area) +
4255 (self->size_inc.width - 1) * (grow ? 1 : 0);
4256 e_start = RECT_TOP(self->frame->area);
4257 e_size = self->frame->area.height;
4258 dir = grow ? OB_DIRECTION_EAST : OB_DIRECTION_WEST;
4260 case OB_DIRECTION_WEST:
4261 head = RECT_LEFT(self->frame->area) -
4262 (self->size_inc.width - 1) * (grow ? 1 : 0);
4263 e_start = RECT_TOP(self->frame->area);
4264 e_size = self->frame->area.height;
4265 dir = grow ? OB_DIRECTION_WEST : OB_DIRECTION_EAST;
4267 case OB_DIRECTION_NORTH:
4268 head = RECT_TOP(self->frame->area) -
4269 (self->size_inc.height - 1) * (grow ? 1 : 0);
4270 e_start = RECT_LEFT(self->frame->area);
4271 e_size = self->frame->area.width;
4272 dir = grow ? OB_DIRECTION_NORTH : OB_DIRECTION_SOUTH;
4274 case OB_DIRECTION_SOUTH:
4275 head = RECT_BOTTOM(self->frame->area) +
4276 (self->size_inc.height - 1) * (grow ? 1 : 0);
4277 e_start = RECT_LEFT(self->frame->area);
4278 e_size = self->frame->area.width;
4279 dir = grow ? OB_DIRECTION_SOUTH : OB_DIRECTION_NORTH;
4282 g_assert_not_reached();
4285 ob_debug("head %d dir %d", head, dir);
4286 client_find_edge_directional(self, dir, head, 1,
4287 e_start, e_size, &e, &near);
4288 ob_debug("edge %d", e);
4289 *x = self->frame->area.x;
4290 *y = self->frame->area.y;
4291 *w = self->frame->area.width;
4292 *h = self->frame->area.height;
4294 case OB_DIRECTION_EAST:
4295 if (grow == near) --e;
4296 delta = e - RECT_RIGHT(self->frame->area);
4299 case OB_DIRECTION_WEST:
4300 if (grow == near) ++e;
4301 delta = RECT_LEFT(self->frame->area) - e;
4305 case OB_DIRECTION_NORTH:
4306 if (grow == near) ++e;
4307 delta = RECT_TOP(self->frame->area) - e;
4311 case OB_DIRECTION_SOUTH:
4312 if (grow == near) --e;
4313 delta = e - RECT_BOTTOM(self->frame->area);
4317 g_assert_not_reached();
4319 frame_frame_gravity(self->frame, x, y);
4320 *w -= self->frame->size.left + self->frame->size.right;
4321 *h -= self->frame->size.top + self->frame->size.bottom;
4324 ObClient* client_under_pointer(void)
4328 ObClient *ret = NULL;
4330 if (screen_pointer_pos(&x, &y)) {
4331 for (it = stacking_list; it; it = g_list_next(it)) {
4332 if (WINDOW_IS_CLIENT(it->data)) {
4333 ObClient *c = WINDOW_AS_CLIENT(it->data);
4334 if (c->frame->visible &&
4335 /* check the desktop, this is done during desktop
4336 switching and windows are shown/hidden status is not
4338 (c->desktop == screen_desktop ||
4339 c->desktop == DESKTOP_ALL) &&
4340 /* ignore all animating windows */
4341 !frame_iconify_animating(c->frame) &&
4342 RECT_CONTAINS(c->frame->area, x, y))
4353 gboolean client_has_group_siblings(ObClient *self)
4355 return self->group && self->group->members->next;
4358 /*! Returns TRUE if the client is running on the same machine as Openbox */
4359 gboolean client_on_localhost(ObClient *self)
4361 return self->client_machine == NULL;