1 /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
3 client.c for the Openbox window manager
4 Copyright (c) 2006 Mikael Magnusson
5 Copyright (c) 2003-2007 Dana Jansens
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 See the COPYING file for a copy of the GNU General Public License.
22 #include "startupnotify.h"
25 #include "moveresize.h"
28 #include "engine_interface.h"
38 #include "menuframe.h"
41 #include "render/render.h"
43 #include "obt/display.h"
52 # include <signal.h> /* for kill() */
56 #include <X11/Xutil.h>
58 /*! The event mask to grab on client windows */
59 #define CLIENT_EVENTMASK (PropertyChangeMask | StructureNotifyMask | \
62 #define CLIENT_NOPROPAGATEMASK (ButtonPressMask | ButtonReleaseMask | \
67 ObClientCallback func;
71 GList *client_list = NULL;
73 static GSList *client_destroy_notifies = NULL;
75 static void client_get_all(ObClient *self, gboolean real);
76 static void client_get_startup_id(ObClient *self);
77 static void client_get_session_ids(ObClient *self);
78 static void client_get_area(ObClient *self);
79 static void client_get_desktop(ObClient *self);
80 static void client_get_state(ObClient *self);
81 static void client_get_shaped(ObClient *self);
82 static void client_get_mwm_hints(ObClient *self);
83 static void client_get_colormap(ObClient *self);
84 static void client_set_desktop_recursive(ObClient *self,
88 static void client_change_allowed_actions(ObClient *self);
89 static void client_change_state(ObClient *self);
90 static void client_change_wm_state(ObClient *self);
91 static void client_apply_startup_state(ObClient *self,
92 gint x, gint y, gint w, gint h);
93 static void client_restore_session_state(ObClient *self);
94 static gboolean client_restore_session_stacking(ObClient *self);
95 static ObAppSettings *client_get_settings_state(ObClient *self);
96 static void client_update_transient_tree(ObClient *self,
97 ObGroup *oldgroup, ObGroup *newgroup,
98 gboolean oldgtran, gboolean newgtran,
100 ObClient *newparent);
101 static void client_present(ObClient *self, gboolean here, gboolean raise,
103 static GSList *client_search_all_top_parents_internal(ObClient *self,
105 ObStackingLayer layer);
106 static void client_call_notifies(ObClient *self, GSList *list);
107 static void client_ping_event(ObClient *self, gboolean dead);
108 static void client_prompt_kill(ObClient *self);
110 Window createWindow(Window parent, Visual *visual, gulong mask,
111 XSetWindowAttributes *attrib)
113 return XCreateWindow(obt_display, parent, 0, 0, 1, 1, 0, (visual ? 32
114 : RrDepth(ob_rr_inst)), InputOutput, (visual ? visual
115 : RrVisual(ob_rr_inst)), mask, attrib);
119 Visual *check_32bit_client(ObClient *c)
121 XWindowAttributes wattrib;
124 /* we're already running at 32 bit depth, yay. we don't need to use their
126 if (RrDepth(ob_rr_inst) == 32)
129 ret = XGetWindowAttributes(obt_display, c->w_client, &wattrib);
130 g_assert(ret != BadDrawable);
131 g_assert(ret != BadWindow);
133 if (wattrib.depth == 32)
134 return wattrib.visual;
138 void client_startup(gboolean reconfig)
140 if (reconfig) return;
145 void client_shutdown(gboolean reconfig)
147 if (reconfig) return;
150 static void client_call_notifies(ObClient *self, GSList *list)
154 for (it = list; it; it = g_slist_next(it)) {
155 ClientCallback *d = it->data;
156 d->func(self, d->data);
160 void client_add_destroy_notify(ObClientCallback func, gpointer data)
162 ClientCallback *d = g_new(ClientCallback, 1);
165 client_destroy_notifies = g_slist_prepend(client_destroy_notifies, d);
168 void client_remove_destroy_notify(ObClientCallback func)
172 for (it = client_destroy_notifies; it; it = g_slist_next(it)) {
173 ClientCallback *d = it->data;
174 if (d->func == func) {
176 client_destroy_notifies =
177 g_slist_delete_link(client_destroy_notifies, it);
183 void client_set_list(void)
185 Window *windows, *win_it;
187 guint size = g_list_length(client_list);
189 /* create an array of the window ids */
191 windows = g_new(Window, size);
193 for (it = client_list; it; it = g_list_next(it), ++win_it)
194 *win_it = ((ObClient*)it->data)->w_client;
198 OBT_PROP_SETA32(obt_root(ob_screen), NET_CLIENT_LIST, WINDOW,
199 (gulong*)windows, size);
207 void client_manage(Window window, ObPrompt *prompt)
210 XSetWindowAttributes attrib_set;
211 gboolean activate = FALSE;
212 ObAppSettings *settings;
213 gboolean transient = FALSE;
214 Rect place, *monitor;
215 Time launch_time, map_time;
217 ob_debug("Managing window: 0x%lx", window);
219 map_time = event_get_server_time();
221 /* choose the events we want to receive on the CLIENT window
222 (ObPrompt windows can request events too) */
223 attrib_set.event_mask = CLIENT_EVENTMASK |
224 (prompt ? prompt->event_mask : 0);
225 attrib_set.do_not_propagate_mask = CLIENT_NOPROPAGATEMASK;
226 XChangeWindowAttributes(obt_display, window,
227 CWEventMask|CWDontPropagate, &attrib_set);
229 /* create the ObClient struct, and populate it from the hints on the
231 self = g_new0(ObClient, 1);
232 self->obwin.type = OB_WINDOW_CLASS_CLIENT;
233 self->w_client = window;
234 self->prompt = prompt;
236 /* non-zero defaults */
237 self->wmstate = WithdrawnState; /* make sure it gets updated first time */
238 self->gravity = NorthWestGravity;
239 self->desktop = screen_num_desktops; /* always an invalid value */
241 /* get all the stuff off the window */
242 client_get_all(self, TRUE);
244 ob_debug("Window type: %d", self->type);
245 ob_debug("Window group: 0x%x", self->group?self->group->leader:0);
247 /* now we have all of the window's information so we can set this up.
248 do this before creating the frame, so it can tell that we are still
249 mapping and doesn't go applying things right away */
250 client_setup_decor_and_functions(self, FALSE);
252 /* specify that if we exit, the window should not be destroyed and
253 should be reparented back to root automatically, unless we are managing
254 an internal ObPrompt window */
256 XChangeSaveSet(obt_display, window, SetModeInsert);
258 /* create the decoration frame for the client window */
259 Visual *visual = check_32bit_client(self);
261 XSetWindowAttributes attrib;
263 /* client has a 32-bit visual */
264 mask |= CWColormap | CWBackPixel | CWBorderPixel;
265 /* create a colormap with the visual */
266 attrib.colormap = XCreateColormap(
267 obt_display, RootWindow(obt_display, ob_screen), visual,
269 attrib.background_pixel = BlackPixel(obt_display, ob_screen);
270 attrib.border_pixel = BlackPixel(obt_display, ob_screen);
272 self->w_frame = createWindow(RootWindow(obt_display, ob_screen), visual,
274 self->frame = frame_engine->frame_new(self, self->w_client, self->w_frame);
275 frame_engine->frame_grab(self->frame, window_map);
277 /* we've grabbed everything and set everything that we need to at mapping
281 /* per-app settings override stuff from client_get_all, and return the
282 settings for other uses too. the returned settings is a shallow copy,
283 that needs to be freed with g_free(). */
284 settings = client_get_settings_state(self);
285 /* the session should get the last say though */
286 client_restore_session_state(self);
288 /* tell startup notification that this app started */
289 launch_time = sn_app_started(self->startup_id, self->class, self->name);
291 /* do this after we have a frame.. it uses the frame to help determine the
292 WM_STATE to apply. */
293 client_change_state(self);
295 /* add ourselves to the focus order */
296 focus_order_add_new(self);
298 /* do this to add ourselves to the stacking list in a non-intrusive way */
299 client_calc_layer(self);
301 /* focus the new window? */
302 if (ob_state() != OB_STATE_STARTING &&
303 (!self->session || self->session->focused) &&
304 /* this means focus=true for window is same as config_focus_new=true */
305 ((config_focus_new || (settings && settings->focus == 1)) ||
306 client_search_focus_tree_full(self)) &&
307 /* this checks for focus=false for the window */
308 (!settings || settings->focus != 0) &&
309 focus_valid_target(self, FALSE, FALSE, TRUE, FALSE, FALSE))
314 /* remove the client's border */
315 XSetWindowBorderWidth(obt_display, self->w_client, 0);
317 /* adjust the frame to the client's size before showing or placing
319 frame_engine->frame_set_hover_flag (self->frame, OB_BUTTON_NONE);
320 frame_engine->frame_set_press_flag (self->frame, OB_BUTTON_NONE);
321 frame_engine->frame_set_is_focus (self->frame, FALSE);
322 frame_engine->frame_set_decorations (self->frame, self->decorations);
323 frame_engine->frame_update_title (self->frame, self->title);
324 frame_engine->frame_update_layout (self->frame, self->area, FALSE, TRUE);
325 frame_engine->frame_update_skin (self->frame);
327 /* where the frame was placed is where the window was originally */
329 monitor = screen_physical_area_monitor(screen_find_monitor(&place));
331 /* figure out placement for the window if the window is new */
332 if (ob_state() == OB_STATE_RUNNING) {
333 ob_debug("Positioned: %s @ %d %d",
334 (!self->positioned ? "no" :
335 (self->positioned == PPosition ? "program specified" :
336 (self->positioned == USPosition ? "user specified" :
337 (self->positioned == (PPosition | USPosition) ?
338 "program + user specified" :
339 "BADNESS !?")))), place.x, place.y);
341 ob_debug("Sized: %s @ %d %d",
342 (!self->sized ? "no" :
343 (self->sized == PSize ? "program specified" :
344 (self->sized == USSize ? "user specified" :
345 (self->sized == (PSize | USSize) ?
346 "program + user specified" :
347 "BADNESS !?")))), place.width, place.height);
349 /* splash screens are also returned as TRUE for transient,
350 and so will be forced on screen below */
351 transient = place_client(self, &place.x, &place.y, settings);
353 /* make sure the window is visible. */
354 client_find_onscreen(self, &place.x, &place.y,
355 place.width, place.height,
356 /* non-normal clients has less rules, and
357 windows that are being restored from a
358 session do also. we can assume you want
359 it back where you saved it. Clients saying
360 they placed themselves are subjected to
361 harder rules, ones that are placed by
362 place.c or by the user are allowed partially
363 off-screen and on xinerama divides (ie,
364 it is up to the placement routines to avoid
365 the xinerama divides)
367 splash screens get "transient" set to TRUE by
368 the place_client call
370 ob_state() == OB_STATE_RUNNING &&
372 (!((self->positioned & USPosition) ||
373 (settings && settings->pos_given)) &&
374 client_normal(self) &&
376 /* don't move oldschool fullscreen windows to
377 fit inside the struts (fixes Acroread, which
378 makes its fullscreen window fit the screen
379 but it is not USSize'd or USPosition'd) */
380 !(self->decorations == 0 &&
381 RECT_EQUAL(place, *monitor)))));
384 /* if the window isn't user-sized, then make it fit inside
385 the visible screen area on its monitor. Use basically the same rules
386 for forcing the window on screen in the client_find_onscreen call.
388 do this after place_client, it chooses the monitor!
390 splash screens get "transient" set to TRUE by
391 the place_client call
393 if (ob_state() == OB_STATE_RUNNING &&
395 (!(self->sized & USSize || self->positioned & USPosition) &&
396 client_normal(self) &&
398 /* don't shrink oldschool fullscreen windows to fit inside the
399 struts (fixes Acroread, which makes its fullscreen window
400 fit the screen but it is not USSize'd or USPosition'd) */
401 !(self->decorations == 0 && RECT_EQUAL(place, *monitor)))))
403 Rect *a = screen_area(self->desktop, SCREEN_AREA_ONE_MONITOR, &place);
406 frame_engine->frame_get_size(self->frame, &size);
407 /* get the size of the frame */
408 place.width += size.left + size.right;
409 place.height += size.top + size.bottom;
411 /* fit the window inside the area */
412 place.width = MIN(place.width, a->width);
413 place.height = MIN(place.height, a->height);
415 ob_debug("setting window size to %dx%d", place.width, place.height);
417 /* get the size of the client back */
418 place.width -= size.left + size.right;
419 place.height -= size.top + size.bottom;
424 ob_debug("placing window 0x%x at %d, %d with size %d x %d. "
425 "some restrictions may apply",
426 self->w_client, place.x, place.y, place.width, place.height);
428 ob_debug(" but session requested %d, %d %d x %d instead, "
430 self->session->x, self->session->y,
431 self->session->w, self->session->h);
433 /* do this after the window is placed, so the premax/prefullscreen numbers
436 this also places the window
438 client_apply_startup_state(self, place.x, place.y,
439 place.width, place.height);
444 ob_debug_type(OB_DEBUG_FOCUS, "Going to try activate new window? %s",
445 activate ? "yes" : "no");
447 gboolean raise = FALSE;
449 /* This is focus stealing prevention */
450 ob_debug_type(OB_DEBUG_FOCUS,
451 "Want to focus new window 0x%x at time %u "
452 "launched at %u (last user interaction time %u)",
453 self->w_client, map_time, launch_time,
454 event_last_user_time);
456 if (menu_frame_visible || frame_engine->moveresize_in_progress) {
459 ob_debug_type(OB_DEBUG_FOCUS,
460 "Not focusing the window because the user is inside "
461 "an Openbox menu or is move/resizing a window and "
462 "we don't want to interrupt them");
465 /* if it's on another desktop */
466 else if (!(self->desktop == screen_desktop ||
467 self->desktop == DESKTOP_ALL) &&
468 /* the timestamp is from before you changed desktops */
469 launch_time && screen_desktop_user_time &&
470 !event_time_after(launch_time, screen_desktop_user_time))
474 ob_debug_type(OB_DEBUG_FOCUS,
475 "Not focusing the window because its on another "
478 /* If something is focused, and it's not our relative... */
479 else if (focus_client && client_search_focus_tree_full(self) == NULL &&
480 client_search_focus_group_full(self) == NULL)
482 /* If the user is working in another window right now, then don't
484 if (event_last_user_time && launch_time &&
485 event_time_after(event_last_user_time, launch_time) &&
486 event_last_user_time != launch_time &&
487 event_time_after(event_last_user_time,
488 map_time - OB_EVENT_USER_TIME_DELAY))
491 ob_debug_type(OB_DEBUG_FOCUS,
492 "Not focusing the window because the user is "
493 "working in another window");
495 /* If its a transient (and its parents aren't focused) */
496 else if (client_has_parent(self)) {
498 ob_debug_type(OB_DEBUG_FOCUS,
499 "Not focusing the window because it is a "
500 "transient, and its relatives aren't focused");
502 /* Don't steal focus from globally active clients.
503 I stole this idea from KWin. It seems nice.
505 else if (!(focus_client->can_focus ||
506 focus_client->focus_notify))
509 ob_debug_type(OB_DEBUG_FOCUS,
510 "Not focusing the window because a globally "
511 "active client has focus");
513 /* Don't move focus if it's not going to go to this window
515 else if (client_focus_target(self) != self) {
518 ob_debug_type(OB_DEBUG_FOCUS,
519 "Not focusing the window because another window "
520 "would get the focus anyway");
522 else if (!(self->desktop == screen_desktop ||
523 self->desktop == DESKTOP_ALL))
527 ob_debug_type(OB_DEBUG_FOCUS,
528 "Not focusing the window because it is on "
529 "another desktop and no relatives are focused ");
534 ob_debug_type(OB_DEBUG_FOCUS,
535 "Focus stealing prevention activated for %s at "
536 "time %u (last user interactioon time %u)",
537 self->title, map_time, event_last_user_time);
538 /* if the client isn't focused, then hilite it so the user
540 client_hilite(self, TRUE);
541 /* we may want to raise it even tho we're not activating it */
542 if (raise && !client_restore_session_stacking(self))
543 stacking_raise(CLIENT_AS_WINDOW(self));
547 /* This may look rather odd. Well it's because new windows are added
548 to the stacking order non-intrusively. If we're not going to focus
549 the new window or hilite it, then we raise it to the top. This will
550 take affect for things that don't get focused like splash screens.
551 Also if you don't have focus_new enabled, then it's going to get
552 raised to the top. Legacy begets legacy I guess?
554 if (!client_restore_session_stacking(self))
555 stacking_raise(CLIENT_AS_WINDOW(self));
558 mouse_grab_for_client(self, TRUE);
560 /* this has to happen before we try focus the window, but we want it to
561 happen after the client's stacking has been determined or it looks bad
565 if (!config_focus_under_mouse)
566 ignore_start = event_start_ignore_all_enters();
570 if (!config_focus_under_mouse)
571 event_end_ignore_all_enters(ignore_start);
575 gboolean stacked = client_restore_session_stacking(self);
576 client_present(self, FALSE, !stacked, TRUE);
579 /* add to client list/map */
580 client_list = g_list_append(client_list, self);
581 window_add(&self->w_client, CLIENT_AS_WINDOW(self));
583 /* this has to happen after we're in the client_list */
584 if (STRUT_EXISTS(self->strut))
585 screen_update_areas();
587 /* update the list hints */
590 /* watch for when the application stops responding. only do this for
591 normal windows, i.e. windows which have titlebars and close buttons
592 and things like that.
593 we don't need to stop pinging on unmanage, because it will be handled
594 automatically by the destroy callback!
596 if (self->ping && client_normal(self))
597 ping_start(self, client_ping_event);
599 /* free the ObAppSettings shallow copy */
602 ob_debug("Managed window 0x%lx plate 0x%x (%s)",
603 window, self->w_frame, self->class);
607 ObClient *client_fake_manage(Window window)
610 ObAppSettings *settings;
612 ob_debug("Pretend-managing window: %lx", window);
614 /* do this minimal stuff to figure out the client's decorations */
616 self = g_new0(ObClient, 1);
617 self->w_client = window;
619 client_get_all(self, FALSE);
620 /* per-app settings override stuff, and return the settings for other
621 uses too. this returns a shallow copy that needs to be freed */
622 settings = client_get_settings_state(self);
624 client_setup_decor_and_functions(self, FALSE);
626 /* create the decoration frame for the client window and adjust its size */
627 Visual *visual = check_32bit_client(self);
629 XSetWindowAttributes attrib;
631 /* client has a 32-bit visual */
632 mask |= CWColormap | CWBackPixel | CWBorderPixel;
633 /* create a colormap with the visual */
634 attrib.colormap = XCreateColormap(
635 obt_display, RootWindow(obt_display, ob_screen), visual,
637 attrib.background_pixel = BlackPixel(obt_display, ob_screen);
638 attrib.border_pixel = BlackPixel(obt_display, ob_screen);
640 self->w_frame = createWindow(RootWindow(obt_display, ob_screen), visual,
642 self->frame = frame_engine->frame_new(self, self->w_client, self->w_frame);
643 frame_engine->frame_set_decorations (self->frame, self->decorations);
644 frame_engine->frame_update_title (self->frame, self->title);
645 frame_engine->frame_update_layout (self->frame, self->area, FALSE, FALSE);
646 frame_engine->frame_update_skin (self->frame);
649 frame_engine->frame_get_size(self->frame, &size);
650 ob_debug("gave extents left %d right %d top %d bottom %d",
651 size.left, size.right,
652 size.top, size.bottom);
654 /* free the ObAppSettings shallow copy */
660 void client_unmanage_all(void)
662 while (client_list != NULL)
663 client_unmanage(client_list->data);
666 void client_unmanage(ObClient *self)
672 ob_debug("Unmanaging window: 0x%x plate 0x%x (%s) (%s)",
673 self->w_client, self->w_frame,
674 self->class, self->title ? self->title : "");
676 g_assert(self != NULL);
678 /* we dont want events no more. do this before hiding the frame so we
679 don't generate more events */
680 XSelectInput(obt_display, self->w_client, NoEventMask);
682 /* ignore enter events from the unmap so it doesnt mess with the focus */
683 if (!config_focus_under_mouse)
684 ignore_start = event_start_ignore_all_enters();
686 client_hide_frame(self);
687 /* flush to send the hide to the server quickly */
690 if (!config_focus_under_mouse)
691 event_end_ignore_all_enters(ignore_start);
693 mouse_grab_for_client(self, FALSE);
695 /* remove the window from our save set, unless we are managing an internal
698 XChangeSaveSet(obt_display, self->w_client, SetModeDelete);
700 /* update the focus lists */
701 focus_order_remove(self);
702 if (client_focused(self)) {
703 /* don't leave an invalid focus_client */
707 /* if we're prompting to kill the client, close that */
708 prompt_unref(self->kill_prompt);
709 self->kill_prompt = NULL;
711 client_list = g_list_remove(client_list, self);
712 stacking_remove(self);
713 window_remove(self->w_client);
715 /* once the client is out of the list, update the struts to remove its
717 if (STRUT_EXISTS(self->strut))
718 screen_update_areas();
720 client_call_notifies(self, client_destroy_notifies);
722 /* tell our parent(s) that we're gone */
723 for (it = self->parents; it; it = g_slist_next(it))
724 ((ObClient*)it->data)->transients =
725 g_slist_remove(((ObClient*)it->data)->transients,self);
727 /* tell our transients that we're gone */
728 for (it = self->transients; it; it = g_slist_next(it)) {
729 ((ObClient*)it->data)->parents =
730 g_slist_remove(((ObClient*)it->data)->parents, self);
731 /* we could be keeping our children in a higher layer */
732 client_calc_layer(it->data);
735 /* remove from its group */
737 group_remove(self->group, self);
741 /* restore the window's original geometry so it is not lost */
747 if (self->fullscreen)
748 a = self->pre_fullscreen_area;
749 else if (self->max_horz || self->max_vert) {
750 if (self->max_horz) {
751 a.x = self->pre_max_area.x;
752 a.width = self->pre_max_area.width;
754 if (self->max_vert) {
755 a.y = self->pre_max_area.y;
756 a.height = self->pre_max_area.height;
760 self->fullscreen = self->max_horz = self->max_vert = FALSE;
761 frame_engine->frame_trigger(self, OB_TRIGGER_UNMAX_VERT);
762 frame_engine->frame_trigger(self, OB_TRIGGER_UNMAX_HORZ);
763 /* let it be moved and resized no matter what */
764 self->functions = OB_CLIENT_FUNC_MOVE | OB_CLIENT_FUNC_RESIZE;
765 self->decorations = 0; /* unmanaged windows have no decor */
767 /* give the client its border back */
768 XSetWindowBorderWidth(obt_display, self->w_client, self->border_width);
770 client_move_resize(self, a.x, a.y, a.width, a.height);
773 /* reparent the window out of the frame, and free the frame */
774 frame_engine->frame_ungrab(self->frame, window_map);
775 frame_engine->frame_free(self->frame);
778 if (ob_state() != OB_STATE_EXITING) {
779 /* these values should not be persisted across a window
781 OBT_PROP_ERASE(self->w_client, NET_WM_DESKTOP);
782 OBT_PROP_ERASE(self->w_client, NET_WM_STATE);
783 OBT_PROP_ERASE(self->w_client, WM_STATE);
785 /* if we're left in an unmapped state, the client wont be mapped.
786 this is bad, since we will no longer be managing the window on
788 XMapWindow(obt_display, self->w_client);
791 /* these should not be left on the window ever. other window managers
792 don't necessarily use them and it will mess them up (like compiz) */
793 OBT_PROP_ERASE(self->w_client, NET_WM_VISIBLE_NAME);
794 OBT_PROP_ERASE(self->w_client, NET_WM_VISIBLE_ICON_NAME);
796 /* update the list hints */
799 ob_debug("Unmanaged window 0x%lx", self->w_client);
801 /* free all data allocated in the client struct */
802 g_slist_free(self->transients);
803 for (j = 0; j < self->nicons; ++j)
804 g_free(self->icons[j].data);
805 if (self->nicons > 0)
807 g_free(self->startup_id);
808 g_free(self->wm_command);
810 g_free(self->icon_title);
811 g_free(self->original_title);
815 g_free(self->client_machine);
816 g_free(self->sm_client_id);
820 void client_fake_unmanage(ObClient *self)
822 /* this is all that got allocated to get the decorations */
824 frame_engine->frame_free(self->frame);
828 /*! Returns a new structure containing the per-app settings for this client.
829 The returned structure needs to be freed with g_free. */
830 static ObAppSettings *client_get_settings_state(ObClient *self)
832 ObAppSettings *settings;
835 settings = config_create_app_settings();
837 for (it = config_per_app_settings; it; it = g_slist_next(it)) {
838 ObAppSettings *app = it->data;
839 gboolean match = TRUE;
841 g_assert(app->name != NULL || app->class != NULL);
843 /* we know that either name or class is not NULL so it will have to
844 match to use the rule */
846 !g_pattern_match(app->name, strlen(self->name), self->name, NULL))
848 else if (app->class &&
849 !g_pattern_match(app->class,
850 strlen(self->class), self->class, NULL))
852 else if (app->role &&
853 !g_pattern_match(app->role,
854 strlen(self->role), self->role, NULL))
858 ob_debug("Window matching: %s", app->name);
860 /* copy the settings to our struct, overriding the existing
861 settings if they are not defaults */
862 config_app_settings_copy_non_defaults(app, settings);
866 if (settings->shade != -1)
867 self->shaded = !!settings->shade;
868 if (settings->decor != -1)
869 self->undecorated = !settings->decor;
870 if (settings->iconic != -1)
871 self->iconic = !!settings->iconic;
872 if (settings->skip_pager != -1)
873 self->skip_pager = !!settings->skip_pager;
874 if (settings->skip_taskbar != -1)
875 self->skip_taskbar = !!settings->skip_taskbar;
877 if (settings->max_vert != -1)
878 self->max_vert = !!settings->max_vert;
879 if (settings->max_horz != -1)
880 self->max_horz = !!settings->max_horz;
882 if (settings->fullscreen != -1)
883 self->fullscreen = !!settings->fullscreen;
885 if (settings->desktop) {
886 if (settings->desktop == DESKTOP_ALL)
887 self->desktop = settings->desktop;
888 else if (settings->desktop > 0 &&
889 settings->desktop <= screen_num_desktops)
890 self->desktop = settings->desktop - 1;
893 if (settings->layer == -1) {
897 else if (settings->layer == 0) {
901 else if (settings->layer == 1) {
908 static void client_restore_session_state(ObClient *self)
912 ob_debug_type(OB_DEBUG_SM,
913 "Restore session for client %s", self->title);
915 if (!(it = session_state_find(self))) {
916 ob_debug_type(OB_DEBUG_SM,
917 "Session data not found for client %s", self->title);
921 self->session = it->data;
923 ob_debug_type(OB_DEBUG_SM, "Session data loaded for client %s",
926 RECT_SET_POINT(self->area, self->session->x, self->session->y);
927 self->positioned = USPosition;
928 self->sized = USSize;
929 if (self->session->w > 0)
930 self->area.width = self->session->w;
931 if (self->session->h > 0)
932 self->area.height = self->session->h;
933 XResizeWindow(obt_display, self->w_client,
934 self->area.width, self->area.height);
936 self->desktop = (self->session->desktop == DESKTOP_ALL ?
937 self->session->desktop :
938 MIN(screen_num_desktops - 1, self->session->desktop));
939 OBT_PROP_SET32(self->w_client, NET_WM_DESKTOP, CARDINAL, self->desktop);
941 self->shaded = self->session->shaded;
942 self->iconic = self->session->iconic;
943 self->skip_pager = self->session->skip_pager;
944 self->skip_taskbar = self->session->skip_taskbar;
945 self->fullscreen = self->session->fullscreen;
946 self->above = self->session->above;
947 self->below = self->session->below;
948 self->max_horz = self->session->max_horz;
949 self->max_vert = self->session->max_vert;
950 self->undecorated = self->session->undecorated;
952 if (self->session->max_horz) {
953 frame_engine->frame_trigger(self->frame, OB_TRIGGER_MAX_HORZ);
956 frame_engine->frame_trigger(self->frame, OB_TRIGGER_UNMAX_HORZ);
959 if (self->session->max_vert) {
960 frame_engine->frame_trigger(self->frame, OB_TRIGGER_MAX_VERT);
963 frame_engine->frame_trigger(self->frame, OB_TRIGGER_UNMAX_VERT);
967 static gboolean client_restore_session_stacking(ObClient *self)
971 if (!self->session) return FALSE;
973 mypos = g_list_find(session_saved_state, self->session);
974 if (!mypos) return FALSE;
976 /* start above me and look for the first client */
977 for (it = g_list_previous(mypos); it; it = g_list_previous(it)) {
980 for (cit = client_list; cit; cit = g_list_next(cit)) {
981 ObClient *c = cit->data;
982 /* found a client that was in the session, so go below it */
983 if (c->session == it->data) {
984 stacking_below(CLIENT_AS_WINDOW(self),
985 CLIENT_AS_WINDOW(cit->data));
993 void client_move_onscreen(ObClient *self, gboolean rude)
995 gint x = self->area.x;
996 gint y = self->area.y;
997 if (client_find_onscreen(self, &x, &y,
999 self->area.height, rude)) {
1000 client_move(self, x, y);
1004 gboolean client_find_onscreen(ObClient *self, gint *x, gint *y, gint w, gint h,
1007 gint ox = *x, oy = *y;
1008 gboolean rudel = rude, ruder = rude, rudet = rude, rudeb = rude;
1014 RECT_SET(desired, *x, *y, w, h);
1015 frame_rect_to_frame(self, &desired);
1017 /* get where the frame would be */
1018 frame_client_gravity(self, x, y);
1021 frame_engine->frame_get_size(self->frame, &size);
1023 /* get the requested size of the window with decorations */
1024 fw = size.left + w + size.right;
1025 fh = size.top + h + size.bottom;
1027 /* If rudeness wasn't requested, then still be rude in a given direction
1028 if the client is not moving, only resizing in that direction */
1030 Point oldtl, oldtr, oldbl, oldbr;
1031 Point newtl, newtr, newbl, newbr;
1032 gboolean stationary_l, stationary_r, stationary_t, stationary_b;
1035 frame_engine->frame_get_window_area(self->frame, &area);
1036 POINT_SET(oldtl, area.x, area.y);
1037 POINT_SET(oldbr, area.x + area.width - 1,
1038 area.y + area.height - 1);
1039 POINT_SET(oldtr, oldbr.x, oldtl.y);
1040 POINT_SET(oldbl, oldtl.x, oldbr.y);
1042 POINT_SET(newtl, *x, *y);
1043 POINT_SET(newbr, *x + fw - 1, *y + fh - 1);
1044 POINT_SET(newtr, newbr.x, newtl.y);
1045 POINT_SET(newbl, newtl.x, newbr.y);
1047 /* is it moving or just resizing from some corner? */
1048 stationary_l = oldtl.x == newtl.x;
1049 stationary_r = oldtr.x == newtr.x;
1050 stationary_t = oldtl.y == newtl.y;
1051 stationary_b = oldbl.y == newbl.y;
1053 /* if left edge is growing and didnt move right edge */
1054 if (stationary_r && newtl.x < oldtl.x)
1056 /* if right edge is growing and didnt move left edge */
1057 if (stationary_l && newtr.x > oldtr.x)
1059 /* if top edge is growing and didnt move bottom edge */
1060 if (stationary_b && newtl.y < oldtl.y)
1062 /* if bottom edge is growing and didnt move top edge */
1063 if (stationary_t && newbl.y > oldbl.y)
1067 /* we iterate through every monitor that the window is at least partially
1068 on, to make sure it is obeying the rules on them all
1070 if the window does not appear on any monitors, then use the first one
1073 for (i = 0; i < screen_num_monitors; ++i) {
1076 if (!screen_physical_area_monitor_contains(i, &desired)) {
1077 if (i < screen_num_monitors - 1 || found_mon)
1080 /* the window is not inside any monitor! so just use the first
1082 a = screen_area(self->desktop, 0, NULL);
1085 a = screen_area(self->desktop, SCREEN_AREA_ONE_MONITOR, &desired);
1088 /* This makes sure windows aren't entirely outside of the screen so you
1089 can't see them at all.
1090 It makes sure 10% of the window is on the screen at least. At don't
1091 let it move itself off the top of the screen, which would hide the
1092 titlebar on you. (The user can still do this if they want too, it's
1093 only limiting the application.
1095 if (client_normal(self)) {
1096 if (!self->strut.right && *x + fw/10 >= a->x + a->width - 1)
1097 *x = a->x + a->width - fw/10;
1098 if (!self->strut.bottom && *y + fh/10 >= a->y + a->height - 1)
1099 *y = a->y + a->height - fh/10;
1100 if (!self->strut.left && *x + fw*9/10 - 1 < a->x)
1101 *x = a->x - fw*9/10;
1102 if (!self->strut.top && *y + fh*9/10 - 1 < a->y)
1103 *y = a->y - fh*9/10;
1106 /* This here doesn't let windows even a pixel outside the
1107 struts/screen. When called from client_manage, programs placing
1108 themselves are forced completely onscreen, while things like
1109 xterm -geometry resolution-width/2 will work fine. Trying to
1110 place it completely offscreen will be handled in the above code.
1111 Sorry for this confused comment, i am tired. */
1112 if (rudel && !self->strut.left && *x < a->x) *x = a->x;
1113 if (ruder && !self->strut.right && *x + fw > a->x + a->width)
1114 *x = a->x + MAX(0, a->width - fw);
1116 if (rudet && !self->strut.top && *y < a->y) *y = a->y;
1117 if (rudeb && !self->strut.bottom && *y + fh > a->y + a->height)
1118 *y = a->y + MAX(0, a->height - fh);
1123 /* get where the client should be */
1124 frame_frame_gravity(self, x, y);
1126 return ox != *x || oy != *y;
1129 static void client_get_all(ObClient *self, gboolean real)
1131 /* this is needed for the frame to set itself up */
1132 client_get_area(self);
1134 /* these things can change the decor and functions of the window */
1136 client_get_mwm_hints(self);
1137 /* this can change the mwmhints for special cases */
1138 client_get_type_and_transientness(self);
1139 client_get_state(self);
1140 client_update_normal_hints(self);
1142 /* get the session related properties, these can change decorations
1143 from per-app settings */
1144 client_get_session_ids(self);
1146 /* now we got everything that can affect the decorations */
1150 /* get this early so we have it for debugging */
1151 client_update_title(self);
1153 client_update_protocols(self);
1155 client_update_wmhints(self);
1156 /* this may have already been called from client_update_wmhints */
1157 if (!self->parents && !self->transient_for_group)
1158 client_update_transient_for(self);
1160 client_get_startup_id(self);
1161 client_get_desktop(self);/* uses transient data/group/startup id if a
1162 desktop is not specified */
1163 client_get_shaped(self);
1166 /* a couple type-based defaults for new windows */
1168 /* this makes sure that these windows appear on all desktops */
1169 if (self->type == OB_CLIENT_TYPE_DESKTOP)
1170 self->desktop = DESKTOP_ALL;
1174 client_update_sync_request_counter(self);
1177 client_get_colormap(self);
1178 client_update_strut(self);
1179 client_update_icons(self);
1180 client_update_icon_geometry(self);
1183 static void client_get_startup_id(ObClient *self)
1185 if (!(OBT_PROP_GETS(self->w_client, NET_STARTUP_ID, utf8,
1186 &self->startup_id)))
1188 OBT_PROP_GETS(self->group->leader,
1189 NET_STARTUP_ID, utf8, &self->startup_id);
1192 static void client_get_area(ObClient *self)
1194 XWindowAttributes wattrib;
1197 ret = XGetWindowAttributes(obt_display, self->w_client, &wattrib);
1198 g_assert(ret != BadWindow);
1200 RECT_SET(self->area, wattrib.x, wattrib.y, wattrib.width, wattrib.height);
1201 POINT_SET(self->root_pos, wattrib.x, wattrib.y);
1202 self->border_width = wattrib.border_width;
1204 ob_debug("client area: %d %d %d %d bw %d", wattrib.x, wattrib.y,
1205 wattrib.width, wattrib.height, wattrib.border_width);
1208 static void client_get_desktop(ObClient *self)
1210 guint32 d = screen_num_desktops; /* an always-invalid value */
1212 if (OBT_PROP_GET32(self->w_client, NET_WM_DESKTOP, CARDINAL, &d)) {
1213 if (d >= screen_num_desktops && d != DESKTOP_ALL)
1214 self->desktop = screen_num_desktops - 1;
1217 ob_debug("client requested desktop 0x%x", self->desktop);
1220 gboolean first = TRUE;
1221 guint all = screen_num_desktops; /* not a valid value */
1223 /* if they are all on one desktop, then open it on the
1225 for (it = self->parents; it; it = g_slist_next(it)) {
1226 ObClient *c = it->data;
1228 if (c->desktop == DESKTOP_ALL) continue;
1234 else if (all != c->desktop)
1235 all = screen_num_desktops; /* make it invalid */
1237 if (all != screen_num_desktops) {
1238 self->desktop = all;
1240 ob_debug("client desktop set from parents: 0x%x",
1243 /* try get from the startup-notification protocol */
1244 else if (sn_get_desktop(self->startup_id, &self->desktop)) {
1245 if (self->desktop >= screen_num_desktops &&
1246 self->desktop != DESKTOP_ALL)
1247 self->desktop = screen_num_desktops - 1;
1248 ob_debug("client desktop set from startup-notification: 0x%x",
1251 /* defaults to the current desktop */
1253 self->desktop = screen_desktop;
1254 ob_debug("client desktop set to the current desktop: %d",
1260 static void client_get_state(ObClient *self)
1265 if (OBT_PROP_GETA32(self->w_client, NET_WM_STATE, ATOM, &state, &num)) {
1267 for (i = 0; i < num; ++i) {
1268 if (state[i] == OBT_PROP_ATOM(NET_WM_STATE_MODAL))
1270 else if (state[i] == OBT_PROP_ATOM(NET_WM_STATE_SHADED))
1271 self->shaded = TRUE;
1272 else if (state[i] == OBT_PROP_ATOM(NET_WM_STATE_HIDDEN))
1273 self->iconic = TRUE;
1274 else if (state[i] == OBT_PROP_ATOM(NET_WM_STATE_SKIP_TASKBAR))
1275 self->skip_taskbar = TRUE;
1276 else if (state[i] == OBT_PROP_ATOM(NET_WM_STATE_SKIP_PAGER))
1277 self->skip_pager = TRUE;
1278 else if (state[i] == OBT_PROP_ATOM(NET_WM_STATE_FULLSCREEN))
1279 self->fullscreen = TRUE;
1280 else if (state[i] == OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_VERT)) {
1281 self->max_vert = TRUE;
1282 frame_engine->frame_trigger(self->frame, OB_TRIGGER_MAX_VERT);
1284 else if (state[i] == OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_HORZ)) {
1285 self->max_horz = TRUE;
1286 frame_engine->frame_trigger(self->frame, OB_TRIGGER_MAX_HORZ);
1288 else if (state[i] == OBT_PROP_ATOM(NET_WM_STATE_ABOVE))
1290 else if (state[i] == OBT_PROP_ATOM(NET_WM_STATE_BELOW))
1292 else if (state[i] == OBT_PROP_ATOM(NET_WM_STATE_DEMANDS_ATTENTION))
1293 self->demands_attention = TRUE;
1294 else if (state[i] == OBT_PROP_ATOM(OB_WM_STATE_UNDECORATED))
1295 self->undecorated = TRUE;
1302 static void client_get_shaped(ObClient *self)
1304 self->shaped = FALSE;
1306 if (obt_display_extension_shape) {
1311 XShapeSelectInput(obt_display, self->w_client, ShapeNotifyMask);
1313 XShapeQueryExtents(obt_display, self->w_client, &s, &foo,
1314 &foo, &ufoo, &ufoo, &foo, &foo, &foo, &ufoo,
1316 self->shaped = (s != 0);
1321 void client_update_transient_for(ObClient *self)
1324 ObClient *target = NULL;
1325 gboolean trangroup = FALSE;
1327 if (XGetTransientForHint(obt_display, self->w_client, &t)) {
1328 if (t != self->w_client) { /* cant be transient to itself! */
1329 ObWindow *tw = window_find(t);
1330 /* if this happens then we need to check for it*/
1331 g_assert(tw != CLIENT_AS_WINDOW(self));
1332 if (tw && WINDOW_IS_CLIENT(tw)) {
1333 /* watch out for windows with a parent that is something
1334 different, like a dockapp for example */
1335 target = WINDOW_AS_CLIENT(tw);
1339 /* Setting the transient_for to Root is actually illegal, however
1340 applications from time have done this to specify transient for
1342 if (!target && self->group && t == obt_root(ob_screen))
1344 } else if (self->group && self->transient)
1347 client_update_transient_tree(self, self->group, self->group,
1348 self->transient_for_group, trangroup,
1349 client_direct_parent(self), target);
1350 self->transient_for_group = trangroup;
1354 static void client_update_transient_tree(ObClient *self,
1355 ObGroup *oldgroup, ObGroup *newgroup,
1356 gboolean oldgtran, gboolean newgtran,
1357 ObClient* oldparent,
1358 ObClient *newparent)
1363 g_assert(!oldgtran || oldgroup);
1364 g_assert(!newgtran || newgroup);
1365 g_assert((!oldgtran && !oldparent) ||
1366 (oldgtran && !oldparent) ||
1367 (!oldgtran && oldparent));
1368 g_assert((!newgtran && !newparent) ||
1369 (newgtran && !newparent) ||
1370 (!newgtran && newparent));
1373 Group transient windows are not allowed to have other group
1374 transient windows as their children.
1378 /* No change has occured */
1379 if (oldgroup == newgroup &&
1380 oldgtran == newgtran &&
1381 oldparent == newparent) return;
1383 /** Remove the client from the transient tree **/
1385 for (it = self->transients; it; it = next) {
1386 next = g_slist_next(it);
1388 self->transients = g_slist_delete_link(self->transients, it);
1389 c->parents = g_slist_remove(c->parents, self);
1391 for (it = self->parents; it; it = next) {
1392 next = g_slist_next(it);
1394 self->parents = g_slist_delete_link(self->parents, it);
1395 c->transients = g_slist_remove(c->transients, self);
1398 /** Re-add the client to the transient tree **/
1400 /* If we're transient for a group then we need to add ourselves to all our
1403 for (it = newgroup->members; it; it = g_slist_next(it)) {
1406 !client_search_top_direct_parent(c)->transient_for_group &&
1409 c->transients = g_slist_prepend(c->transients, self);
1410 self->parents = g_slist_prepend(self->parents, c);
1415 /* If we are now transient for a single window we need to add ourselves to
1418 WARNING: Cyclical transient ness is possible if two windows are
1419 transient for eachother.
1421 else if (newparent &&
1422 /* don't make ourself its child if it is already our child */
1423 !client_is_direct_child(self, newparent) &&
1424 client_normal(newparent))
1426 newparent->transients = g_slist_prepend(newparent->transients, self);
1427 self->parents = g_slist_prepend(self->parents, newparent);
1430 /* Add any group transient windows to our children. But if we're transient
1431 for the group, then other group transients are not our children.
1433 WARNING: Cyclical transient-ness is possible. For e.g. if:
1434 A is transient for the group
1435 B is transient for A
1436 C is transient for B
1437 A can't be transient for C or we have a cycle
1439 if (!newgtran && newgroup &&
1441 !client_search_top_direct_parent(newparent)->transient_for_group) &&
1442 client_normal(self))
1444 for (it = newgroup->members; it; it = g_slist_next(it)) {
1446 if (c != self && c->transient_for_group &&
1447 /* Don't make it our child if it is already our parent */
1448 !client_is_direct_child(c, self))
1450 self->transients = g_slist_prepend(self->transients, c);
1451 c->parents = g_slist_prepend(c->parents, self);
1456 /** If we change our group transient-ness, our children change their
1457 effect group transient-ness, which affects how they relate to other
1460 for (it = self->transients; it; it = g_slist_next(it)) {
1462 if (!c->transient_for_group)
1463 client_update_transient_tree(c, c->group, c->group,
1464 c->transient_for_group,
1465 c->transient_for_group,
1466 client_direct_parent(c),
1467 client_direct_parent(c));
1471 static void client_get_mwm_hints(ObClient *self)
1476 self->mwmhints.flags = 0; /* default to none */
1478 if (OBT_PROP_GETA32(self->w_client, MOTIF_WM_HINTS, MOTIF_WM_HINTS,
1480 if (num >= OB_MWM_ELEMENTS) {
1481 self->mwmhints.flags = hints[0];
1482 self->mwmhints.functions = hints[1];
1483 self->mwmhints.decorations = hints[2];
1489 void client_get_type_and_transientness(ObClient *self)
1496 self->transient = FALSE;
1498 if (OBT_PROP_GETA32(self->w_client, NET_WM_WINDOW_TYPE, ATOM, &val, &num)) {
1499 /* use the first value that we know about in the array */
1500 for (i = 0; i < num; ++i) {
1501 if (val[i] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_DESKTOP))
1502 self->type = OB_CLIENT_TYPE_DESKTOP;
1503 else if (val[i] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_DOCK))
1504 self->type = OB_CLIENT_TYPE_DOCK;
1505 else if (val[i] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_TOOLBAR))
1506 self->type = OB_CLIENT_TYPE_TOOLBAR;
1507 else if (val[i] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_MENU))
1508 self->type = OB_CLIENT_TYPE_MENU;
1509 else if (val[i] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_UTILITY))
1510 self->type = OB_CLIENT_TYPE_UTILITY;
1511 else if (val[i] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_SPLASH))
1512 self->type = OB_CLIENT_TYPE_SPLASH;
1513 else if (val[i] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_DIALOG))
1514 self->type = OB_CLIENT_TYPE_DIALOG;
1515 else if (val[i] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_NORMAL))
1516 self->type = OB_CLIENT_TYPE_NORMAL;
1517 else if (val[i] == OBT_PROP_ATOM(KDE_NET_WM_WINDOW_TYPE_OVERRIDE))
1519 /* prevent this window from getting any decor or
1521 self->mwmhints.flags &= (OB_MWM_FLAG_FUNCTIONS |
1522 OB_MWM_FLAG_DECORATIONS);
1523 self->mwmhints.decorations = 0;
1524 self->mwmhints.functions = 0;
1526 if (self->type != (ObClientType) -1)
1527 break; /* grab the first legit type */
1532 if (XGetTransientForHint(obt_display, self->w_client, &t))
1533 self->transient = TRUE;
1535 if (self->type == (ObClientType) -1) {
1536 /*the window type hint was not set, which means we either classify
1537 ourself as a normal window or a dialog, depending on if we are a
1539 if (self->transient)
1540 self->type = OB_CLIENT_TYPE_DIALOG;
1542 self->type = OB_CLIENT_TYPE_NORMAL;
1545 /* then, based on our type, we can update our transientness.. */
1546 if (self->type == OB_CLIENT_TYPE_DIALOG ||
1547 self->type == OB_CLIENT_TYPE_TOOLBAR ||
1548 self->type == OB_CLIENT_TYPE_MENU ||
1549 self->type == OB_CLIENT_TYPE_UTILITY)
1551 self->transient = TRUE;
1555 void client_update_protocols(ObClient *self)
1560 self->focus_notify = FALSE;
1561 self->delete_window = FALSE;
1563 if (OBT_PROP_GETA32(self->w_client, WM_PROTOCOLS, ATOM, &proto, &num_ret)) {
1564 for (i = 0; i < num_ret; ++i) {
1565 if (proto[i] == OBT_PROP_ATOM(WM_DELETE_WINDOW))
1566 /* this means we can request the window to close */
1567 self->delete_window = TRUE;
1568 else if (proto[i] == OBT_PROP_ATOM(WM_TAKE_FOCUS))
1569 /* if this protocol is requested, then the window will be
1570 notified whenever we want it to receive focus */
1571 self->focus_notify = TRUE;
1572 else if (proto[i] == OBT_PROP_ATOM(NET_WM_PING))
1573 /* if this protocol is requested, then the window will allow
1574 pings to determine if it is still alive */
1577 else if (proto[i] == OBT_PROP_ATOM(NET_WM_SYNC_REQUEST))
1578 /* if this protocol is requested, then resizing the
1579 window will be synchronized between the frame and the
1581 self->sync_request = TRUE;
1589 void client_update_sync_request_counter(ObClient *self)
1593 if (OBT_PROP_GET32(self->w_client, NET_WM_SYNC_REQUEST_COUNTER, CARDINAL,&i))
1595 self->sync_counter = i;
1597 self->sync_counter = None;
1601 static void client_get_colormap(ObClient *self)
1603 XWindowAttributes wa;
1605 if (XGetWindowAttributes(obt_display, self->w_client, &wa))
1606 client_update_colormap(self, wa.colormap);
1609 void client_update_colormap(ObClient *self, Colormap colormap)
1611 if (colormap == self->colormap) return;
1613 ob_debug("Setting client %s colormap: 0x%x", self->title, colormap);
1615 if (client_focused(self)) {
1616 screen_install_colormap(self, FALSE); /* uninstall old one */
1617 self->colormap = colormap;
1618 screen_install_colormap(self, FALSE); /* install new one */
1620 self->colormap = colormap;
1623 void client_update_normal_hints(ObClient *self)
1629 self->min_ratio = 0.0f;
1630 self->max_ratio = 0.0f;
1631 SIZE_SET(self->size_inc, 1, 1);
1632 SIZE_SET(self->base_size, 0, 0);
1633 SIZE_SET(self->min_size, 0, 0);
1634 SIZE_SET(self->max_size, G_MAXINT, G_MAXINT);
1636 /* get the hints from the window */
1637 if (XGetWMNormalHints(obt_display, self->w_client, &size, &ret)) {
1638 /* normal windows can't request placement! har har
1639 if (!client_normal(self))
1641 self->positioned = (size.flags & (PPosition|USPosition));
1642 self->sized = (size.flags & (PSize|USSize));
1644 if (size.flags & PWinGravity)
1645 self->gravity = size.win_gravity;
1647 if (size.flags & PAspect) {
1648 if (size.min_aspect.y)
1650 (gfloat) size.min_aspect.x / size.min_aspect.y;
1651 if (size.max_aspect.y)
1653 (gfloat) size.max_aspect.x / size.max_aspect.y;
1656 if (size.flags & PMinSize)
1657 SIZE_SET(self->min_size, size.min_width, size.min_height);
1659 if (size.flags & PMaxSize)
1660 SIZE_SET(self->max_size, size.max_width, size.max_height);
1662 if (size.flags & PBaseSize)
1663 SIZE_SET(self->base_size, size.base_width, size.base_height);
1665 if (size.flags & PResizeInc && size.width_inc && size.height_inc)
1666 SIZE_SET(self->size_inc, size.width_inc, size.height_inc);
1668 ob_debug("Normal hints: min size (%d %d) max size (%d %d)",
1669 self->min_size.width, self->min_size.height,
1670 self->max_size.width, self->max_size.height);
1671 ob_debug("size inc (%d %d) base size (%d %d)",
1672 self->size_inc.width, self->size_inc.height,
1673 self->base_size.width, self->base_size.height);
1676 ob_debug("Normal hints: not set");
1679 void client_setup_decor_and_functions(ObClient *self, gboolean reconfig)
1681 /* start with everything (cept fullscreen) */
1683 (OB_FRAME_DECOR_TITLEBAR |
1684 OB_FRAME_DECOR_HANDLE |
1685 OB_FRAME_DECOR_GRIPS |
1686 OB_FRAME_DECOR_BORDER |
1687 OB_FRAME_DECOR_ICON |
1688 OB_FRAME_DECOR_ALLDESKTOPS |
1689 OB_FRAME_DECOR_ICONIFY |
1690 OB_FRAME_DECOR_MAXIMIZE |
1691 OB_FRAME_DECOR_SHADE |
1692 OB_FRAME_DECOR_CLOSE);
1694 (OB_CLIENT_FUNC_RESIZE |
1695 OB_CLIENT_FUNC_MOVE |
1696 OB_CLIENT_FUNC_ICONIFY |
1697 OB_CLIENT_FUNC_MAXIMIZE |
1698 OB_CLIENT_FUNC_SHADE |
1699 OB_CLIENT_FUNC_CLOSE |
1700 OB_CLIENT_FUNC_BELOW |
1701 OB_CLIENT_FUNC_ABOVE |
1702 OB_CLIENT_FUNC_UNDECORATE);
1704 if (!(self->min_size.width < self->max_size.width ||
1705 self->min_size.height < self->max_size.height))
1706 self->functions &= ~OB_CLIENT_FUNC_RESIZE;
1708 switch (self->type) {
1709 case OB_CLIENT_TYPE_NORMAL:
1710 /* normal windows retain all of the possible decorations and
1711 functionality, and can be fullscreen */
1712 self->functions |= OB_CLIENT_FUNC_FULLSCREEN;
1715 case OB_CLIENT_TYPE_DIALOG:
1716 /* sometimes apps make dialog windows fullscreen for some reason (for
1717 e.g. kpdf does this..) */
1718 self->functions |= OB_CLIENT_FUNC_FULLSCREEN;
1721 case OB_CLIENT_TYPE_UTILITY:
1722 /* these windows don't have anything added or removed by default */
1725 case OB_CLIENT_TYPE_MENU:
1726 case OB_CLIENT_TYPE_TOOLBAR:
1727 /* these windows can't iconify or maximize */
1728 self->decorations &= ~(OB_FRAME_DECOR_ICONIFY |
1729 OB_FRAME_DECOR_MAXIMIZE);
1730 self->functions &= ~(OB_CLIENT_FUNC_ICONIFY |
1731 OB_CLIENT_FUNC_MAXIMIZE);
1734 case OB_CLIENT_TYPE_SPLASH:
1735 /* these don't get get any decorations, and the only thing you can
1736 do with them is move them */
1737 self->decorations = 0;
1738 self->functions = OB_CLIENT_FUNC_MOVE;
1741 case OB_CLIENT_TYPE_DESKTOP:
1742 /* these windows are not manipulated by the window manager */
1743 self->decorations = 0;
1744 self->functions = 0;
1747 case OB_CLIENT_TYPE_DOCK:
1748 /* these windows are not manipulated by the window manager, but they
1749 can set below layer which has a special meaning */
1750 self->decorations = 0;
1751 self->functions = OB_CLIENT_FUNC_BELOW;
1755 /* Mwm Hints are applied subtractively to what has already been chosen for
1756 decor and functionality */
1757 if (self->mwmhints.flags & OB_MWM_FLAG_DECORATIONS) {
1758 if (! (self->mwmhints.decorations & OB_MWM_DECOR_ALL)) {
1759 if (! ((self->mwmhints.decorations & OB_MWM_DECOR_HANDLE) ||
1760 (self->mwmhints.decorations & OB_MWM_DECOR_TITLE)))
1762 /* if the mwm hints request no handle or title, then all
1763 decorations are disabled, but keep the border if that's
1765 if (self->mwmhints.decorations & OB_MWM_DECOR_BORDER)
1766 self->decorations = OB_FRAME_DECOR_BORDER;
1768 self->decorations = 0;
1773 if (self->mwmhints.flags & OB_MWM_FLAG_FUNCTIONS) {
1774 if (! (self->mwmhints.functions & OB_MWM_FUNC_ALL)) {
1775 if (! (self->mwmhints.functions & OB_MWM_FUNC_RESIZE))
1776 self->functions &= ~OB_CLIENT_FUNC_RESIZE;
1777 if (! (self->mwmhints.functions & OB_MWM_FUNC_MOVE))
1778 self->functions &= ~OB_CLIENT_FUNC_MOVE;
1779 /* dont let mwm hints kill any buttons
1780 if (! (self->mwmhints.functions & OB_MWM_FUNC_ICONIFY))
1781 self->functions &= ~OB_CLIENT_FUNC_ICONIFY;
1782 if (! (self->mwmhints.functions & OB_MWM_FUNC_MAXIMIZE))
1783 self->functions &= ~OB_CLIENT_FUNC_MAXIMIZE;
1785 /* dont let mwm hints kill the close button
1786 if (! (self->mwmhints.functions & MwmFunc_Close))
1787 self->functions &= ~OB_CLIENT_FUNC_CLOSE; */
1791 if (!(self->functions & OB_CLIENT_FUNC_SHADE))
1792 self->decorations &= ~OB_FRAME_DECOR_SHADE;
1793 if (!(self->functions & OB_CLIENT_FUNC_ICONIFY))
1794 self->decorations &= ~OB_FRAME_DECOR_ICONIFY;
1795 if (!(self->functions & OB_CLIENT_FUNC_RESIZE))
1796 self->decorations &= ~(OB_FRAME_DECOR_GRIPS | OB_FRAME_DECOR_HANDLE);
1798 /* can't maximize without moving/resizing */
1799 if (!((self->functions & OB_CLIENT_FUNC_MAXIMIZE) &&
1800 (self->functions & OB_CLIENT_FUNC_MOVE) &&
1801 (self->functions & OB_CLIENT_FUNC_RESIZE))) {
1802 self->functions &= ~OB_CLIENT_FUNC_MAXIMIZE;
1803 self->decorations &= ~OB_FRAME_DECOR_MAXIMIZE;
1806 if (self->max_horz && self->max_vert) {
1807 /* you can't resize fully maximized windows */
1808 self->functions &= ~OB_CLIENT_FUNC_RESIZE;
1809 /* kill the handle on fully maxed windows */
1810 self->decorations &= ~(OB_FRAME_DECOR_HANDLE | OB_FRAME_DECOR_GRIPS);
1813 /* If there are no decorations to remove, don't allow the user to try
1815 if (self->decorations == 0)
1816 self->functions &= ~OB_CLIENT_FUNC_UNDECORATE;
1818 /* finally, the user can have requested no decorations, which overrides
1819 everything (but doesnt give it a border if it doesnt have one) */
1820 if (self->undecorated)
1821 self->decorations = 0;
1823 /* if we don't have a titlebar, then we cannot shade! */
1824 if (!(self->decorations & OB_FRAME_DECOR_TITLEBAR))
1825 self->functions &= ~OB_CLIENT_FUNC_SHADE;
1827 /* now we need to check against rules for the client's current state */
1828 if (self->fullscreen) {
1829 self->functions &= (OB_CLIENT_FUNC_CLOSE |
1830 OB_CLIENT_FUNC_FULLSCREEN |
1831 OB_CLIENT_FUNC_ICONIFY);
1832 self->decorations = 0;
1835 client_change_allowed_actions(self);
1838 /* force reconfigure to make sure decorations are updated */
1839 client_reconfigure(self, TRUE);
1842 static void client_change_allowed_actions(ObClient *self)
1847 /* desktop windows are kept on all desktops */
1848 if (self->type != OB_CLIENT_TYPE_DESKTOP)
1849 actions[num++] = OBT_PROP_ATOM(NET_WM_ACTION_CHANGE_DESKTOP);
1851 if (self->functions & OB_CLIENT_FUNC_SHADE)
1852 actions[num++] = OBT_PROP_ATOM(NET_WM_ACTION_SHADE);
1853 if (self->functions & OB_CLIENT_FUNC_CLOSE)
1854 actions[num++] = OBT_PROP_ATOM(NET_WM_ACTION_CLOSE);
1855 if (self->functions & OB_CLIENT_FUNC_MOVE)
1856 actions[num++] = OBT_PROP_ATOM(NET_WM_ACTION_MOVE);
1857 if (self->functions & OB_CLIENT_FUNC_ICONIFY)
1858 actions[num++] = OBT_PROP_ATOM(NET_WM_ACTION_MINIMIZE);
1859 if (self->functions & OB_CLIENT_FUNC_RESIZE)
1860 actions[num++] = OBT_PROP_ATOM(NET_WM_ACTION_RESIZE);
1861 if (self->functions & OB_CLIENT_FUNC_FULLSCREEN)
1862 actions[num++] = OBT_PROP_ATOM(NET_WM_ACTION_FULLSCREEN);
1863 if (self->functions & OB_CLIENT_FUNC_MAXIMIZE) {
1864 actions[num++] = OBT_PROP_ATOM(NET_WM_ACTION_MAXIMIZE_HORZ);
1865 actions[num++] = OBT_PROP_ATOM(NET_WM_ACTION_MAXIMIZE_VERT);
1867 if (self->functions & OB_CLIENT_FUNC_ABOVE)
1868 actions[num++] = OBT_PROP_ATOM(NET_WM_ACTION_ABOVE);
1869 if (self->functions & OB_CLIENT_FUNC_BELOW)
1870 actions[num++] = OBT_PROP_ATOM(NET_WM_ACTION_BELOW);
1871 if (self->functions & OB_CLIENT_FUNC_UNDECORATE)
1872 actions[num++] = OBT_PROP_ATOM(OB_WM_ACTION_UNDECORATE);
1874 OBT_PROP_SETA32(self->w_client, NET_WM_ALLOWED_ACTIONS, ATOM, actions, num);
1876 /* make sure the window isn't breaking any rules now
1878 don't check ICONIFY here. just cuz a window can't iconify doesnt mean
1879 it can't be iconified with its parent
1882 if (!(self->functions & OB_CLIENT_FUNC_SHADE) && self->shaded) {
1883 if (self->frame) client_shade(self, FALSE);
1884 else self->shaded = FALSE;
1886 if (!(self->functions & OB_CLIENT_FUNC_FULLSCREEN) && self->fullscreen) {
1887 if (self->frame) client_fullscreen(self, FALSE);
1888 else self->fullscreen = FALSE;
1890 if (!(self->functions & OB_CLIENT_FUNC_MAXIMIZE) && (self->max_horz ||
1892 if (self->frame) client_maximize(self, FALSE, 0);
1894 self->max_vert = self->max_horz = FALSE;
1895 frame_engine->frame_trigger (self->frame, OB_TRIGGER_UNMAX_VERT);
1896 frame_engine->frame_trigger (self->frame, OB_TRIGGER_UNMAX_HORZ);
1902 void client_update_wmhints(ObClient *self)
1906 /* assume a window takes input if it doesnt specify */
1907 self->can_focus = TRUE;
1909 if ((hints = XGetWMHints(obt_display, self->w_client)) != NULL) {
1912 if (hints->flags & InputHint)
1913 self->can_focus = hints->input;
1915 /* only do this when first managing the window *AND* when we aren't
1917 if (ob_state() != OB_STATE_STARTING && self->frame == NULL)
1918 if (hints->flags & StateHint)
1919 self->iconic = hints->initial_state == IconicState;
1922 self->urgent = (hints->flags & XUrgencyHint);
1923 if (self->urgent && !ur)
1924 client_hilite(self, TRUE);
1925 else if (!self->urgent && ur && self->demands_attention)
1926 client_hilite(self, FALSE);
1928 if (!(hints->flags & WindowGroupHint))
1929 hints->window_group = None;
1931 /* did the group state change? */
1932 if (hints->window_group !=
1933 (self->group ? self->group->leader : None))
1935 ObGroup *oldgroup = self->group;
1937 /* remove from the old group if there was one */
1938 if (self->group != NULL) {
1939 group_remove(self->group, self);
1943 /* add ourself to the group if we have one */
1944 if (hints->window_group != None) {
1945 self->group = group_add(hints->window_group, self);
1948 /* Put ourselves into the new group's transient tree, and remove
1949 ourselves from the old group's */
1950 client_update_transient_tree(self, oldgroup, self->group,
1951 self->transient_for_group,
1952 self->transient_for_group,
1953 client_direct_parent(self),
1954 client_direct_parent(self));
1956 /* Lastly, being in a group, or not, can change if the window is
1957 transient for anything.
1959 The logic for this is:
1960 self->transient = TRUE always if the window wants to be
1961 transient for something, even if transient_for was NULL because
1962 it wasn't in a group before.
1964 If parents was NULL and oldgroup was NULL we can assume
1965 that when we add the new group, it will become transient for
1968 If transient_for_group is TRUE, then it must have already
1969 had a group. If it is getting a new group, the above call to
1970 client_update_transient_tree has already taken care of
1971 everything ! If it is losing all group status then it will
1972 no longer be transient for anything and that needs to be
1975 if (self->transient &&
1976 ((self->parents == NULL && oldgroup == NULL) ||
1977 (self->transient_for_group && !self->group)))
1978 client_update_transient_for(self);
1981 /* the WM_HINTS can contain an icon */
1982 if (hints->flags & IconPixmapHint)
1983 client_update_icons(self);
1989 void client_update_title(ObClient *self)
1992 gchar *visible = NULL;
1994 g_free(self->title);
1995 g_free(self->original_title);
1998 if (!OBT_PROP_GETS(self->w_client, NET_WM_NAME, utf8, &data)) {
1999 /* try old x stuff */
2000 if (!(OBT_PROP_GETS(self->w_client, WM_NAME, locale, &data)
2001 || OBT_PROP_GETS(self->w_client, WM_NAME, utf8, &data))) {
2002 if (self->transient) {
2004 GNOME alert windows are not given titles:
2005 http://developer.gnome.org/projects/gup/hig/draft_hig_new/windows-alert.html
2007 data = g_strdup("");
2009 data = g_strdup("Unnamed Window");
2012 self->original_title = g_strdup(data);
2014 if (self->client_machine) {
2015 visible = g_strdup_printf("%s (%s)", data, self->client_machine);
2020 if (self->not_responding) {
2022 if (self->kill_level > 0)
2023 visible = g_strdup_printf("%s - [%s]", data, _("Killing..."));
2025 visible = g_strdup_printf("%s - [%s]", data, _("Not Responding"));
2029 OBT_PROP_SETS(self->w_client, NET_WM_VISIBLE_NAME, utf8, visible);
2030 self->title = visible;
2033 /* update title render */
2034 frame_engine->frame_update_title (self->frame, self->title);
2035 frame_engine->frame_update_skin (self->frame);
2038 /* update the icon title */
2040 g_free(self->icon_title);
2043 if (!OBT_PROP_GETS(self->w_client, NET_WM_ICON_NAME, utf8, &data))
2044 /* try old x stuff */
2045 if (!(OBT_PROP_GETS(self->w_client, WM_ICON_NAME, locale, &data) ||
2046 OBT_PROP_GETS(self->w_client, WM_ICON_NAME, utf8, &data)))
2047 data = g_strdup(self->title);
2049 if (self->client_machine) {
2050 visible = g_strdup_printf("%s (%s)", data, self->client_machine);
2055 if (self->not_responding) {
2057 if (self->kill_level > 0)
2058 visible = g_strdup_printf("%s - [%s]", data, _("Killing..."));
2060 visible = g_strdup_printf("%s - [%s]", data, _("Not Responding"));
2064 OBT_PROP_SETS(self->w_client, NET_WM_VISIBLE_ICON_NAME, utf8, visible);
2065 self->icon_title = visible;
2068 void client_update_strut(ObClient *self)
2072 gboolean got = FALSE;
2075 if (OBT_PROP_GETA32(self->w_client, NET_WM_STRUT_PARTIAL, CARDINAL,
2080 STRUT_PARTIAL_SET(strut,
2081 data[0], data[2], data[1], data[3],
2082 data[4], data[5], data[8], data[9],
2083 data[6], data[7], data[10], data[11]);
2089 OBT_PROP_GETA32(self->w_client, NET_WM_STRUT, CARDINAL, &data, &num)) {
2095 /* use the screen's width/height */
2096 a = screen_physical_area_all_monitors();
2098 STRUT_PARTIAL_SET(strut,
2099 data[0], data[2], data[1], data[3],
2100 a->y, a->y + a->height - 1,
2101 a->x, a->x + a->width - 1,
2102 a->y, a->y + a->height - 1,
2103 a->x, a->x + a->width - 1);
2110 STRUT_PARTIAL_SET(strut, 0, 0, 0, 0,
2111 0, 0, 0, 0, 0, 0, 0, 0);
2113 if (!STRUT_EQUAL(strut, self->strut)) {
2114 self->strut = strut;
2116 /* updating here is pointless while we're being mapped cuz we're not in
2117 the client list yet */
2119 screen_update_areas();
2123 /* Avoid storing icons above this size if possible */
2124 #define AVOID_ABOVE 64
2126 void client_update_icons(ObClient *self)
2131 guint num_seen; /* number of icons present */
2132 guint num_small_seen; /* number of icons small enough present */
2133 guint smallest, smallest_area;
2135 for (i = 0; i < self->nicons; ++i)
2136 g_free(self->icons[i].data);
2137 if (self->nicons > 0)
2138 g_free(self->icons);
2141 if (OBT_PROP_GETA32(self->w_client, NET_WM_ICON, CARDINAL, &data, &num)) {
2142 /* figure out how many valid icons are in here */
2144 num_seen = num_small_seen = 0;
2145 smallest = smallest_area = 0;
2151 /* watch for it being too small for the specified size, or for
2152 zero sized icons. */
2153 if (i > num || w == 0 || h == 0) break;
2155 if (!smallest_area || w*h < smallest_area) {
2156 smallest = num_seen;
2157 smallest_area = w*h;
2160 if (w <= AVOID_ABOVE && h <= AVOID_ABOVE)
2163 if (num_small_seen > 0)
2164 self->nicons = num_small_seen;
2168 self->icons = g_new(ObClientIcon, self->nicons);
2170 /* store the icons */
2172 for (j = 0; j < self->nicons;) {
2175 w = self->icons[j].width = data[i++];
2176 h = self->icons[j].height = data[i++];
2178 /* if there are some icons smaller than the threshold, we're
2179 skipping all the ones above */
2180 if (num_small_seen > 0) {
2181 if (w > AVOID_ABOVE || h > AVOID_ABOVE) {
2186 /* if there were no icons smaller than the threshold, then we are
2187 only taking the smallest available one we saw */
2188 else if (j != smallest) {
2193 self->icons[j].data = g_new(RrPixel32, w * h);
2194 for (x = 0, y = 0, t = 0; t < w * h; ++t, ++x, ++i) {
2199 self->icons[j].data[t] =
2200 (((data[i] >> 24) & 0xff) << RrDefaultAlphaOffset) +
2201 (((data[i] >> 16) & 0xff) << RrDefaultRedOffset) +
2202 (((data[i] >> 8) & 0xff) << RrDefaultGreenOffset) +
2203 (((data[i] >> 0) & 0xff) << RrDefaultBlueOffset);
2214 if ((hints = XGetWMHints(obt_display, self->w_client))) {
2215 if (hints->flags & IconPixmapHint) {
2217 self->icons = g_new(ObClientIcon, self->nicons);
2218 obt_display_ignore_errors(TRUE);
2219 if (!RrPixmapToRGBA(ob_rr_inst,
2221 (hints->flags & IconMaskHint ?
2222 hints->icon_mask : None),
2223 &self->icons[0].width,
2224 &self->icons[0].height,
2225 &self->icons[0].data))
2227 g_free(self->icons);
2230 obt_display_ignore_errors(FALSE);
2236 /* set the default icon onto the window
2237 in theory, this could be a race, but if a window doesn't set an icon
2238 or removes it entirely, it's not very likely it is going to set one
2239 right away afterwards
2241 if it has parents, then one of them will have an icon already
2243 if (self->nicons == 0 && !self->parents) {
2244 RrPixel32 *icon = ob_rr_theme->def_win_icon;
2247 data = g_new(gulong, 48*48+2);
2248 data[0] = data[1] = 48;
2249 for (i = 0; i < 48*48; ++i)
2250 data[i+2] = (((icon[i] >> RrDefaultAlphaOffset) & 0xff) << 24) +
2251 (((icon[i] >> RrDefaultRedOffset) & 0xff) << 16) +
2252 (((icon[i] >> RrDefaultGreenOffset) & 0xff) << 8) +
2253 (((icon[i] >> RrDefaultBlueOffset) & 0xff) << 0);
2254 OBT_PROP_SETA32(self->w_client, NET_WM_ICON, CARDINAL, data, 48*48+2);
2256 } else if (self->frame)
2257 frame_engine->frame_update_skin (self->frame);
2258 /* don't draw the icon empty if we're just setting one now anyways,
2259 we'll get the property change any second */
2260 //frame_adjust_icon(self->frame);
2263 void client_update_icon_geometry(ObClient *self)
2268 RECT_SET(self->icon_geometry, 0, 0, 0, 0);
2270 if (OBT_PROP_GETA32(self->w_client, NET_WM_ICON_GEOMETRY, CARDINAL,
2274 /* don't let them set it with an area < 0 */
2275 RECT_SET(self->icon_geometry, data[0], data[1],
2276 MAX(data[2],0), MAX(data[3],0));
2281 static void client_get_session_ids(ObClient *self)
2288 if (!OBT_PROP_GET32(self->w_client, WM_CLIENT_LEADER, WINDOW, &leader))
2291 /* get the SM_CLIENT_ID */
2294 got = OBT_PROP_GETS(leader, SM_CLIENT_ID, locale, &self->sm_client_id);
2296 OBT_PROP_GETS(self->w_client, SM_CLIENT_ID, locale, &self->sm_client_id);
2298 /* get the WM_CLASS (name and class). make them "" if they are not
2302 got = OBT_PROP_GETSS(leader, WM_CLASS, locale, &ss);
2304 got = OBT_PROP_GETSS(self->w_client, WM_CLASS, locale, &ss);
2308 self->name = g_strdup(ss[0]);
2310 self->class = g_strdup(ss[1]);
2315 if (self->name == NULL) self->name = g_strdup("");
2316 if (self->class == NULL) self->class = g_strdup("");
2318 /* get the WM_WINDOW_ROLE. make it "" if it is not provided */
2321 got = OBT_PROP_GETS(leader, WM_WINDOW_ROLE, locale, &s);
2323 got = OBT_PROP_GETS(self->w_client, WM_WINDOW_ROLE, locale, &s);
2328 self->role = g_strdup("");
2330 /* get the WM_COMMAND */
2334 got = OBT_PROP_GETSS(leader, WM_COMMAND, locale, &ss);
2336 got = OBT_PROP_GETSS(self->w_client, WM_COMMAND, locale, &ss);
2339 /* merge/mash them all together */
2340 gchar *merge = NULL;
2343 for (i = 0; ss[i]; ++i) {
2346 merge = g_strconcat(merge, ss[i], NULL);
2348 merge = g_strconcat(ss[i], NULL);
2353 self->wm_command = merge;
2356 /* get the WM_CLIENT_MACHINE */
2359 got = OBT_PROP_GETS(leader, WM_CLIENT_MACHINE, locale, &s);
2361 got = OBT_PROP_GETS(self->w_client, WM_CLIENT_MACHINE, locale, &s);
2364 gchar localhost[128];
2367 gethostname(localhost, 127);
2368 localhost[127] = '\0';
2369 if (strcmp(localhost, s) != 0)
2370 self->client_machine = s;
2374 /* see if it has the PID set too (the PID requires that the
2375 WM_CLIENT_MACHINE be set) */
2376 if (OBT_PROP_GET32(self->w_client, NET_WM_PID, CARDINAL, &pid))
2381 static void client_change_wm_state(ObClient *self)
2386 old = self->wmstate;
2388 if (self->shaded || self->iconic ||
2389 (self->desktop != DESKTOP_ALL && self->desktop != screen_desktop))
2391 self->wmstate = IconicState;
2393 self->wmstate = NormalState;
2395 if (old != self->wmstate) {
2396 OBT_PROP_MSG(ob_screen, self->w_client, KDE_WM_CHANGE_STATE,
2397 self->wmstate, 1, 0, 0, 0);
2399 state[0] = self->wmstate;
2401 OBT_PROP_SETA32(self->w_client, WM_STATE, WM_STATE, state, 2);
2405 static void client_change_state(ObClient *self)
2407 gulong netstate[12];
2412 netstate[num++] = OBT_PROP_ATOM(NET_WM_STATE_MODAL);
2414 netstate[num++] = OBT_PROP_ATOM(NET_WM_STATE_SHADED);
2416 netstate[num++] = OBT_PROP_ATOM(NET_WM_STATE_HIDDEN);
2417 if (self->skip_taskbar)
2418 netstate[num++] = OBT_PROP_ATOM(NET_WM_STATE_SKIP_TASKBAR);
2419 if (self->skip_pager)
2420 netstate[num++] = OBT_PROP_ATOM(NET_WM_STATE_SKIP_PAGER);
2421 if (self->fullscreen)
2422 netstate[num++] = OBT_PROP_ATOM(NET_WM_STATE_FULLSCREEN);
2424 netstate[num++] = OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_VERT);
2426 netstate[num++] = OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_HORZ);
2428 netstate[num++] = OBT_PROP_ATOM(NET_WM_STATE_ABOVE);
2430 netstate[num++] = OBT_PROP_ATOM(NET_WM_STATE_BELOW);
2431 if (self->demands_attention)
2432 netstate[num++] = OBT_PROP_ATOM(NET_WM_STATE_DEMANDS_ATTENTION);
2433 if (self->undecorated)
2434 netstate[num++] = OBT_PROP_ATOM(OB_WM_STATE_UNDECORATED);
2435 OBT_PROP_SETA32(self->w_client, NET_WM_STATE, ATOM, netstate, num);
2438 frame_engine->frame_update_layout (self->frame, self->area, FALSE, FALSE);
2441 ObClient *client_search_focus_tree(ObClient *self)
2446 for (it = self->transients; it; it = g_slist_next(it)) {
2447 if (client_focused(it->data)) return it->data;
2448 if ((ret = client_search_focus_tree(it->data))) return ret;
2453 ObClient *client_search_focus_tree_full(ObClient *self)
2455 if (self->parents) {
2458 for (it = self->parents; it; it = g_slist_next(it)) {
2459 ObClient *c = it->data;
2460 if ((c = client_search_focus_tree_full(it->data))) return c;
2466 /* this function checks the whole tree, the client_search_focus_tree
2467 does not, so we need to check this window */
2468 if (client_focused(self))
2470 return client_search_focus_tree(self);
2474 ObClient *client_search_focus_group_full(ObClient *self)
2479 for (it = self->group->members; it; it = g_slist_next(it)) {
2480 ObClient *c = it->data;
2482 if (client_focused(c)) return c;
2483 if ((c = client_search_focus_tree(it->data))) return c;
2486 if (client_focused(self)) return self;
2490 gboolean client_has_parent(ObClient *self)
2492 return self->parents != NULL;
2495 static ObStackingLayer calc_layer(ObClient *self)
2500 monitor = screen_physical_area_monitor(client_monitor(self));
2502 if (self->type == OB_CLIENT_TYPE_DESKTOP)
2503 l = OB_STACKING_LAYER_DESKTOP;
2504 else if (self->type == OB_CLIENT_TYPE_DOCK) {
2505 if (self->below) l = OB_STACKING_LAYER_NORMAL;
2506 else l = OB_STACKING_LAYER_ABOVE;
2508 else if ((self->fullscreen ||
2509 /* No decorations and fills the monitor = oldskool fullscreen.
2510 But not for maximized windows.
2512 (self->decorations == 0 &&
2513 !(self->max_horz && self->max_vert) &&
2514 RECT_EQUAL(self->area, *monitor))) &&
2515 /* you are fullscreen while you or your children are focused.. */
2516 (client_focused(self) || client_search_focus_tree(self) ||
2517 /* you can be fullscreen if you're on another desktop */
2518 (self->desktop != screen_desktop &&
2519 self->desktop != DESKTOP_ALL) ||
2520 /* and you can also be fullscreen if the focused client is on
2521 another monitor, or nothing else is focused */
2523 client_monitor(focus_client) != client_monitor(self))))
2524 l = OB_STACKING_LAYER_FULLSCREEN;
2525 else if (self->above) l = OB_STACKING_LAYER_ABOVE;
2526 else if (self->below) l = OB_STACKING_LAYER_BELOW;
2527 else l = OB_STACKING_LAYER_NORMAL;
2534 static void client_calc_layer_recursive(ObClient *self, ObClient *orig,
2535 ObStackingLayer min)
2537 ObStackingLayer old, own;
2541 own = calc_layer(self);
2542 self->layer = MAX(own, min);
2544 if (self->layer != old) {
2545 stacking_remove(CLIENT_AS_WINDOW(self));
2546 stacking_add_nonintrusive(CLIENT_AS_WINDOW(self));
2549 /* we've been restacked */
2550 self->visited = TRUE;
2552 for (it = self->transients; it; it = g_slist_next(it))
2553 client_calc_layer_recursive(it->data, orig,
2557 static void client_calc_layer_internal(ObClient *self)
2561 /* transients take on the layer of their parents */
2562 sit = client_search_all_top_parents(self);
2564 for (; sit; sit = g_slist_next(sit))
2565 client_calc_layer_recursive(sit->data, self, 0);
2568 void client_calc_layer(ObClient *self)
2572 /* skip over stuff above fullscreen layer */
2573 for (it = stacking_list; it; it = g_list_next(it))
2574 if (window_layer(it->data) <= OB_STACKING_LAYER_FULLSCREEN) break;
2576 /* find the windows in the fullscreen layer, and mark them not-visited */
2577 for (; it; it = g_list_next(it)) {
2578 if (window_layer(it->data) < OB_STACKING_LAYER_FULLSCREEN) break;
2579 else if (WINDOW_IS_CLIENT(it->data))
2580 WINDOW_AS_CLIENT(it->data)->visited = FALSE;
2583 client_calc_layer_internal(self);
2585 /* skip over stuff above fullscreen layer */
2586 for (it = stacking_list; it; it = g_list_next(it))
2587 if (window_layer(it->data) <= OB_STACKING_LAYER_FULLSCREEN) break;
2589 /* now recalc any windows in the fullscreen layer which have not
2590 had their layer recalced already */
2591 for (; it; it = g_list_next(it)) {
2592 if (window_layer(it->data) < OB_STACKING_LAYER_FULLSCREEN) break;
2593 else if (WINDOW_IS_CLIENT(it->data) &&
2594 !WINDOW_AS_CLIENT(it->data)->visited)
2595 client_calc_layer_internal(it->data);
2599 gboolean client_should_show(ObClient *self)
2603 if (client_normal(self) && screen_showing_desktop)
2605 if (self->desktop == screen_desktop || self->desktop == DESKTOP_ALL)
2611 gboolean client_show(ObClient *self)
2613 gboolean show = FALSE;
2615 if (client_should_show(self)) {
2616 /* replay pending pointer event before showing the window, in case it
2617 should be going to something under the window */
2618 mouse_replay_pointer();
2620 client_show_frame(self);
2623 /* According to the ICCCM (sec 4.1.3.1) when a window is not visible,
2624 it needs to be in IconicState. This includes when it is on another
2627 client_change_wm_state(self);
2632 gboolean client_hide(ObClient *self)
2634 gboolean hide = FALSE;
2636 if (!client_should_show(self)) {
2637 if (self == focus_client) {
2638 /* if there is a grab going on, then we need to cancel it. if we
2639 move focus during the grab, applications will get
2640 NotifyWhileGrabbed events and ignore them !
2642 actions should not rely on being able to move focus during an
2645 event_cancel_all_key_grabs();
2648 /* We don't need to ignore enter events here.
2649 The window can hide/iconify in 3 different ways:
2650 1 - through an x message. in this case we ignore all enter events
2651 caused by responding to the x message (unless underMouse)
2652 2 - by a keyboard action. in this case we ignore all enter events
2653 caused by the action
2654 3 - by a mouse action. in this case they are doing stuff with the
2655 mouse and focus _should_ move.
2657 Also in action_end, we simulate an enter event that can't be ignored
2658 so trying to ignore them is futile in case 3 anyways
2661 /* replay pending pointer event before hiding the window, in case it
2662 should be going to the window */
2663 mouse_replay_pointer();
2665 client_hide_frame(self);
2668 /* According to the ICCCM (sec 4.1.3.1) when a window is not visible,
2669 it needs to be in IconicState. This includes when it is on another
2672 client_change_wm_state(self);
2677 void client_showhide(ObClient *self)
2679 if (!client_show(self))
2683 gboolean client_normal(ObClient *self) {
2684 return ! (self->type == OB_CLIENT_TYPE_DESKTOP ||
2685 self->type == OB_CLIENT_TYPE_DOCK ||
2686 self->type == OB_CLIENT_TYPE_SPLASH);
2689 gboolean client_helper(ObClient *self)
2691 return (self->type == OB_CLIENT_TYPE_UTILITY ||
2692 self->type == OB_CLIENT_TYPE_MENU ||
2693 self->type == OB_CLIENT_TYPE_TOOLBAR);
2696 gboolean client_mouse_focusable(ObClient *self)
2698 return !(self->type == OB_CLIENT_TYPE_MENU ||
2699 self->type == OB_CLIENT_TYPE_TOOLBAR ||
2700 self->type == OB_CLIENT_TYPE_SPLASH ||
2701 self->type == OB_CLIENT_TYPE_DOCK);
2704 gboolean client_enter_focusable(ObClient *self)
2706 /* you can focus desktops but it shouldn't on enter */
2707 return (client_mouse_focusable(self) &&
2708 self->type != OB_CLIENT_TYPE_DESKTOP);
2712 static void client_apply_startup_state(ObClient *self,
2713 gint x, gint y, gint w, gint h)
2715 /* save the states that we are going to apply */
2716 gboolean iconic = self->iconic;
2717 gboolean fullscreen = self->fullscreen;
2718 gboolean undecorated = self->undecorated;
2719 gboolean shaded = self->shaded;
2720 gboolean demands_attention = self->demands_attention;
2721 gboolean max_horz = self->max_horz;
2722 gboolean max_vert = self->max_vert;
2726 /* turn them all off in the client, so they won't affect the window
2728 self->iconic = self->fullscreen = self->undecorated = self->shaded =
2729 self->demands_attention = self->max_horz = self->max_vert = FALSE;
2731 /* move the client to its placed position, or it it's already there,
2732 generate a ConfigureNotify telling the client where it is.
2734 do this after adjusting the frame. otherwise it gets all weird and
2735 clients don't work right
2737 do this before applying the states so they have the correct
2738 pre-max/pre-fullscreen values
2740 client_try_configure(self, &x, &y, &w, &h, &l, &l, FALSE);
2741 ob_debug("placed window 0x%x at %d, %d with size %d x %d",
2742 self->w_client, x, y, w, h);
2743 /* save the area, and make it where it should be for the premax stuff */
2744 oldarea = self->area;
2745 RECT_SET(self->area, x, y, w, h);
2746 frame_engine->frame_set_client_area (self->frame, self->area);
2748 /* apply the states. these are in a carefully crafted order.. */
2751 client_iconify(self, TRUE, FALSE, TRUE);
2753 client_fullscreen(self, TRUE);
2755 client_set_undecorated(self, TRUE);
2757 client_shade(self, TRUE);
2758 if (demands_attention)
2759 client_hilite(self, TRUE);
2761 if (max_vert && max_horz)
2762 client_maximize(self, TRUE, 0);
2764 client_maximize(self, TRUE, 2);
2766 client_maximize(self, TRUE, 1);
2768 /* if the window hasn't been configured yet, then do so now, in fact the
2769 x,y,w,h may _not_ be the same as the area rect, which can end up
2770 meaning that the client isn't properly moved/resized by the fullscreen
2772 pho can cause this because it maps at size of the screen but not 0,0
2773 so openbox moves it on screen to 0,0 (thus x,y=0,0 and area.x,y don't).
2774 then fullscreen'ing makes it go to 0,0 which it thinks it already is at
2775 cuz thats where the pre-fullscreen will be. however the actual area is
2776 not, so this needs to be called even if we have fullscreened/maxed
2778 self->area = oldarea;
2779 frame_engine->frame_set_decorations (self->frame, self->decorations);
2780 frame_engine->frame_update_layout (self->frame, self->area, FALSE, FALSE);
2781 client_configure(self, x, y, w, h, FALSE, TRUE, FALSE);
2783 /* set the desktop hint, to make sure that it always exists */
2784 OBT_PROP_SET32(self->w_client, NET_WM_DESKTOP, CARDINAL, self->desktop);
2786 /* nothing to do for the other states:
2795 void client_gravity_resize_w(ObClient *self, gint *x, gint oldw, gint neww)
2797 /* these should be the current values. this is for when you're not moving,
2799 g_assert(*x == self->area.x);
2800 g_assert(oldw == self->area.width);
2803 switch (self->gravity) {
2805 case NorthWestGravity:
2807 case SouthWestGravity:
2814 *x -= (neww - oldw) / 2;
2816 case NorthEastGravity:
2818 case SouthEastGravity:
2824 void client_gravity_resize_h(ObClient *self, gint *y, gint oldh, gint newh)
2826 /* these should be the current values. this is for when you're not moving,
2828 g_assert(*y == self->area.y);
2829 g_assert(oldh == self->area.height);
2832 switch (self->gravity) {
2834 case NorthWestGravity:
2836 case NorthEastGravity:
2843 *y -= (newh - oldh) / 2;
2845 case SouthWestGravity:
2847 case SouthEastGravity:
2853 void client_try_configure(ObClient *self, gint *x, gint *y, gint *w, gint *h,
2854 gint *logicalw, gint *logicalh,
2857 Rect desired = {*x, *y, *w, *h};
2858 frame_rect_to_frame(self, &desired);
2860 /* make the frame recalculate its dimentions n shit without changing
2861 anything visible for real, this way the constraints below can work with
2862 the updated frame dimensions. */
2863 frame_engine->frame_set_decorations (self->frame, self->decorations);
2864 frame_engine->frame_update_layout (self->frame, self->area, FALSE, TRUE);
2866 /* gets the frame's position */
2867 frame_client_gravity(self, x, y);
2869 /* these positions are frame positions, not client positions */
2871 /* set the size and position if fullscreen */
2872 if (self->fullscreen) {
2876 i = screen_find_monitor(&desired);
2877 a = screen_physical_area_monitor(i);
2884 user = FALSE; /* ignore if the client can't be moved/resized when it
2888 } else if (self->max_horz || self->max_vert) {
2892 /* use all possible struts when maximizing to the full screen */
2893 i = screen_find_monitor(&desired);
2894 a = screen_area(self->desktop, i,
2895 (self->max_horz && self->max_vert ? NULL : &desired));
2898 frame_engine->frame_get_size(self->frame, &size);
2899 /* set the size and position if maximized */
2900 if (self->max_horz) {
2902 *w = a->width - size.left - size.right;
2904 if (self->max_vert) {
2906 *h = a->height - size.top - size.bottom;
2909 user = FALSE; /* ignore if the client can't be moved/resized when it
2915 /* gets the client's position */
2916 frame_frame_gravity(self, x, y);
2918 /* work within the prefered sizes given by the window */
2919 if (!(*w == self->area.width && *h == self->area.height)) {
2920 gint basew, baseh, minw, minh;
2922 gfloat minratio, maxratio;
2924 incw = self->fullscreen || self->max_horz ? 1 : self->size_inc.width;
2925 inch = self->fullscreen || self->max_vert ? 1 : self->size_inc.height;
2926 minratio = self->fullscreen || (self->max_horz && self->max_vert) ?
2927 0 : self->min_ratio;
2928 maxratio = self->fullscreen || (self->max_horz && self->max_vert) ?
2929 0 : self->max_ratio;
2931 /* base size is substituted with min size if not specified */
2932 if (self->base_size.width || self->base_size.height) {
2933 basew = self->base_size.width;
2934 baseh = self->base_size.height;
2936 basew = self->min_size.width;
2937 baseh = self->min_size.height;
2939 /* min size is substituted with base size if not specified */
2940 if (self->min_size.width || self->min_size.height) {
2941 minw = self->min_size.width;
2942 minh = self->min_size.height;
2944 minw = self->base_size.width;
2945 minh = self->base_size.height;
2948 /* if this is a user-requested resize, then check against min/max
2951 /* smaller than min size or bigger than max size? */
2952 if (*w > self->max_size.width) *w = self->max_size.width;
2953 if (*w < minw) *w = minw;
2954 if (*h > self->max_size.height) *h = self->max_size.height;
2955 if (*h < minh) *h = minh;
2960 /* keep to the increments */
2964 /* you cannot resize to nothing */
2965 if (basew + *w < 1) *w = 1 - basew;
2966 if (baseh + *h < 1) *h = 1 - baseh;
2968 /* save the logical size */
2969 *logicalw = incw > 1 ? *w : *w + basew;
2970 *logicalh = inch > 1 ? *h : *h + baseh;
2978 /* adjust the height to match the width for the aspect ratios.
2979 for this, min size is not substituted for base size ever. */
2980 *w -= self->base_size.width;
2981 *h -= self->base_size.height;
2984 if (*h * minratio > *w) {
2985 *h = (gint)(*w / minratio);
2987 /* you cannot resize to nothing */
2990 *w = (gint)(*h * minratio);
2994 if (*h * maxratio < *w) {
2995 *h = (gint)(*w / maxratio);
2997 /* you cannot resize to nothing */
3000 *w = (gint)(*h * minratio);
3004 *w += self->base_size.width;
3005 *h += self->base_size.height;
3008 /* these override the above states! if you cant move you can't move! */
3010 if (!(self->functions & OB_CLIENT_FUNC_MOVE)) {
3014 if (!(self->functions & OB_CLIENT_FUNC_RESIZE)) {
3015 *w = self->area.width;
3016 *h = self->area.height;
3025 void client_configure(ObClient *self, gint x, gint y, gint w, gint h,
3026 gboolean user, gboolean final, gboolean force_reply)
3030 gboolean send_resize_client;
3031 gboolean moved = FALSE, resized = FALSE, rootmoved = FALSE;
3032 gboolean fmoved, fresized;
3033 guint fdecor = frame_engine->frame_get_decorations(self->frame);
3034 gboolean fhorz = frame_engine->frame_is_max_horz(self->frame);
3035 gboolean fvert = frame_engine->frame_is_max_vert(self->frame);
3036 gint logicalw, logicalh;
3039 frame_engine->frame_get_size(self->frame, &size);
3041 frame_engine->frame_get_window_area(self->frame, &area);
3043 /* find the new x, y, width, and height (and logical size) */
3044 client_try_configure(self, &x, &y, &w, &h, &logicalw, &logicalh, user);
3046 /* set the logical size if things changed */
3047 if (!(w == self->area.width && h == self->area.height))
3048 SIZE_SET(self->logical_size, logicalw, logicalh);
3050 /* figure out if we moved or resized or what */
3051 moved = (x != self->area.x || y != self->area.y);
3052 resized = (w != self->area.width || h != self->area.height);
3054 oldw = self->area.width;
3055 oldh = self->area.height;
3056 frame_engine->frame_get_window_area(self->frame, &oldframe);
3057 RECT_SET(self->area, x, y, w, h);
3059 frame_engine->frame_set_client_area (self->frame, self->area);
3061 /* for app-requested resizes, always resize if 'resized' is true.
3062 for user-requested ones, only resize if final is true, or when
3063 resizing in redraw mode */
3064 send_resize_client = ((!user && resized) ||
3066 (resized && config_resize_redraw))));
3068 /* if the client is enlarging, then resize the client before the frame */
3069 if (send_resize_client && (w > oldw || h > oldh)) {
3070 frame_engine->frame_set_decorations (self->frame, self->decorations);
3071 frame_engine->frame_update_layout (self->frame, self->area, FALSE, FALSE);
3074 /* find the frame's dimensions and move/resize it */
3078 /* if decorations changed, then readjust everything for the frame */
3079 if (self->decorations != fdecor ||
3080 self->max_horz != fhorz || self->max_vert != fvert)
3082 fmoved = fresized = TRUE;
3085 /* adjust the frame */
3086 if (fmoved || fresized) {
3087 gulong ignore_start;
3089 ignore_start = event_start_ignore_all_enters();
3091 /* replay pending pointer event before move the window, in case it
3092 would change what window gets the event */
3093 mouse_replay_pointer();
3095 frame_engine->frame_set_decorations (self->frame, self->decorations);
3096 frame_engine->frame_update_layout (self->frame, self->area, TRUE, FALSE);
3099 event_end_ignore_all_enters(ignore_start);
3102 if (!user || final) {
3103 gint oldrx = self->root_pos.x;
3104 gint oldry = self->root_pos.y;
3105 /* we have reset the client to 0 border width, so don't include
3106 it in these coords */
3107 POINT_SET(self->root_pos,
3108 area.x + size.left -
3111 self->border_width);
3112 if (self->root_pos.x != oldrx || self->root_pos.y != oldry)
3116 /* This is kinda tricky and should not be changed.. let me explain!
3118 When user = FALSE, then the request is coming from the application
3119 itself, and we are more strict about when to send a synthetic
3120 ConfigureNotify. We strictly follow the rules of the ICCCM sec 4.1.5
3121 in this case (if force_reply is true)
3123 When user = TRUE, then the request is coming from "us", like when we
3124 maximize a window or something. In this case we are more lenient. We
3125 used to follow the same rules as above, but _Java_ Swing can't handle
3126 this. So just to appease Swing, when user = TRUE, we always send
3127 a synthetic ConfigureNotify to give the window its root coordinates.
3129 if ((!user && !resized && (rootmoved || force_reply)) ||
3130 (user && final && rootmoved))
3134 event.type = ConfigureNotify;
3135 event.xconfigure.display = obt_display;
3136 event.xconfigure.event = self->w_client;
3137 event.xconfigure.window = self->w_client;
3139 ob_debug("Sending ConfigureNotify to %s for %d,%d %dx%d",
3140 self->title, self->root_pos.x, self->root_pos.y, w, h);
3142 /* root window real coords */
3143 event.xconfigure.x = self->root_pos.x;
3144 event.xconfigure.y = self->root_pos.y;
3145 event.xconfigure.width = w;
3146 event.xconfigure.height = h;
3147 event.xconfigure.border_width = self->border_width;
3148 event.xconfigure.above = None;
3149 event.xconfigure.override_redirect = FALSE;
3150 XSendEvent(event.xconfigure.display, event.xconfigure.window,
3151 FALSE, StructureNotifyMask, &event);
3154 /* if the client is shrinking, then resize the frame before the client.
3156 both of these resize sections may run, because the top one only resizes
3157 in the direction that is growing
3159 if (send_resize_client && (w <= oldw || h <= oldh)) {
3160 frame_engine->frame_set_decorations (self->frame, self->decorations);
3161 frame_engine->frame_update_layout (self->frame, self->area, FALSE, FALSE);
3164 XFlush(obt_display);
3166 /* if it moved between monitors, then this can affect the stacking
3167 layer of this window or others - for fullscreen windows */
3169 frame_engine->frame_get_window_area(self->frame, ¤t_frame);
3170 if (screen_find_monitor(¤t_frame) !=
3171 screen_find_monitor(&oldframe))
3173 client_calc_layer(self);
3177 void client_fullscreen(ObClient *self, gboolean fs)
3181 if (!(self->functions & OB_CLIENT_FUNC_FULLSCREEN) || /* can't */
3182 self->fullscreen == fs) return; /* already done */
3184 self->fullscreen = fs;
3185 client_change_state(self); /* change the state hints on the client */
3188 self->pre_fullscreen_area = self->area;
3189 /* if the window is maximized, its area isn't all that meaningful.
3190 save it's premax area instead. */
3191 if (self->max_horz) {
3192 self->pre_fullscreen_area.x = self->pre_max_area.x;
3193 self->pre_fullscreen_area.width = self->pre_max_area.width;
3195 if (self->max_vert) {
3196 self->pre_fullscreen_area.y = self->pre_max_area.y;
3197 self->pre_fullscreen_area.height = self->pre_max_area.height;
3200 /* these will help configure_full figure out where to fullscreen
3204 w = self->area.width;
3205 h = self->area.height;
3207 g_assert(self->pre_fullscreen_area.width > 0 &&
3208 self->pre_fullscreen_area.height > 0);
3210 x = self->pre_fullscreen_area.x;
3211 y = self->pre_fullscreen_area.y;
3212 w = self->pre_fullscreen_area.width;
3213 h = self->pre_fullscreen_area.height;
3214 RECT_SET(self->pre_fullscreen_area, 0, 0, 0, 0);
3217 ob_debug("Window %s going fullscreen (%d)",
3218 self->title, self->fullscreen);
3220 client_setup_decor_and_functions(self, FALSE);
3221 client_move_resize(self, x, y, w, h);
3223 /* and adjust our layer/stacking. do this after resizing the window,
3224 and applying decorations, because windows which fill the screen are
3225 considered "fullscreen" and it affects their layer */
3226 client_calc_layer(self);
3229 /* try focus us when we go into fullscreen mode */
3234 static void client_iconify_recursive(ObClient *self,
3235 gboolean iconic, gboolean curdesk,
3236 gboolean hide_animation)
3239 gboolean changed = FALSE;
3242 if (self->iconic != iconic) {
3243 ob_debug("%sconifying window: 0x%lx", (iconic ? "I" : "Uni"),
3247 /* don't let non-normal windows iconify along with their parents
3249 if (client_normal(self)) {
3250 self->iconic = iconic;
3252 /* update the focus lists.. iconic windows go to the bottom of
3254 focus_order_to_bottom(self);
3259 self->iconic = iconic;
3261 if (curdesk && self->desktop != screen_desktop &&
3262 self->desktop != DESKTOP_ALL)
3263 client_set_desktop(self, screen_desktop, FALSE, FALSE);
3265 /* this puts it after the current focused window */
3266 focus_order_remove(self);
3267 focus_order_add_new(self);
3274 client_change_state(self);
3275 /* do this after starting the animation so it doesn't flash */
3276 client_showhide(self);
3279 /* iconify all direct transients, and deiconify all transients
3281 for (it = self->transients; it; it = g_slist_next(it))
3282 if (it->data != self)
3283 if (client_is_direct_child(self, it->data) || !iconic)
3284 client_iconify_recursive(it->data, iconic, curdesk,
3288 void client_iconify(ObClient *self, gboolean iconic, gboolean curdesk,
3289 gboolean hide_animation)
3291 if (self->functions & OB_CLIENT_FUNC_ICONIFY || !iconic) {
3292 /* move up the transient chain as far as possible first */
3293 self = client_search_top_direct_parent(self);
3294 client_iconify_recursive(self, iconic, curdesk, hide_animation);
3298 void client_maximize(ObClient *self, gboolean max, gint dir)
3302 g_assert(dir == 0 || dir == 1 || dir == 2);
3303 if (!(self->functions & OB_CLIENT_FUNC_MAXIMIZE)) return; /* can't */
3305 /* check if already done */
3307 if (dir == 0 && self->max_horz && self->max_vert) return;
3308 if (dir == 1 && self->max_horz) return;
3309 if (dir == 2 && self->max_vert) return;
3311 if (dir == 0 && !self->max_horz && !self->max_vert) return;
3312 if (dir == 1 && !self->max_horz) return;
3313 if (dir == 2 && !self->max_vert) return;
3316 /* these will help configure_full figure out which screen to fill with
3320 w = self->area.width;
3321 h = self->area.height;
3324 if ((dir == 0 || dir == 1) && !self->max_horz) { /* horz */
3325 RECT_SET(self->pre_max_area,
3326 self->area.x, self->pre_max_area.y,
3327 self->area.width, self->pre_max_area.height);
3329 if ((dir == 0 || dir == 2) && !self->max_vert) { /* vert */
3330 RECT_SET(self->pre_max_area,
3331 self->pre_max_area.x, self->area.y,
3332 self->pre_max_area.width, self->area.height);
3335 if ((dir == 0 || dir == 1) && self->max_horz) { /* horz */
3336 g_assert(self->pre_max_area.width > 0);
3338 x = self->pre_max_area.x;
3339 w = self->pre_max_area.width;
3341 RECT_SET(self->pre_max_area, 0, self->pre_max_area.y,
3342 0, self->pre_max_area.height);
3344 if ((dir == 0 || dir == 2) && self->max_vert) { /* vert */
3345 g_assert(self->pre_max_area.height > 0);
3347 y = self->pre_max_area.y;
3348 h = self->pre_max_area.height;
3350 RECT_SET(self->pre_max_area, self->pre_max_area.x, 0,
3351 self->pre_max_area.width, 0);
3355 if (dir == 0 || dir == 1) {
3356 self->max_horz = max; /* horz */
3357 frame_engine->frame_trigger(self->frame, max? OB_TRIGGER_MAX_HORZ : OB_TRIGGER_UNMAX_HORZ);
3360 if (dir == 0 || dir == 2){
3361 self->max_vert = max; /* vert */
3362 frame_engine->frame_trigger(self->frame, max? OB_TRIGGER_MAX_VERT : OB_TRIGGER_UNMAX_VERT);
3365 client_change_state(self); /* change the state hints on the client */
3367 client_setup_decor_and_functions(self, FALSE);
3368 client_move_resize(self, x, y, w, h);
3371 void client_shade(ObClient *self, gboolean shade)
3373 if ((!(self->functions & OB_CLIENT_FUNC_SHADE) &&
3374 shade) || /* can't shade */
3375 self->shaded == shade) return; /* already done */
3377 self->shaded = shade;
3378 client_change_state(self);
3379 client_change_wm_state(self); /* the window is being hidden/shown */
3380 /* resize the frame to just the titlebar */
3381 frame_engine->frame_set_is_shaded (self->frame, self->shaded);
3382 frame_engine->frame_update_layout(self->frame, self->area, FALSE, FALSE);
3385 static void client_ping_event(ObClient *self, gboolean dead)
3387 self->not_responding = dead;
3388 client_update_title(self);
3391 /* it came back to life ! */
3393 if (self->kill_prompt) {
3394 prompt_unref(self->kill_prompt);
3395 self->kill_prompt = NULL;
3398 self->kill_level = 0;
3402 void client_close(ObClient *self)
3404 if (!(self->functions & OB_CLIENT_FUNC_CLOSE)) return;
3407 prompt_cancel(self->prompt);
3411 /* in the case that the client provides no means to requesting that it
3412 close, we just kill it */
3413 if (!self->delete_window)
3414 /* don't use client_kill(), we should only kill based on PID in
3415 response to a lack of PING replies */
3416 XKillClient(obt_display, self->w_client);
3418 /* request the client to close with WM_DELETE_WINDOW */
3419 OBT_PROP_MSG_TO(self->w_client, self->w_client, WM_PROTOCOLS,
3420 OBT_PROP_ATOM(WM_DELETE_WINDOW), event_curtime,
3421 0, 0, 0, NoEventMask);
3423 if (self->not_responding)
3424 client_prompt_kill(self);
3428 #define OB_KILL_RESULT_NO 0
3429 #define OB_KILL_RESULT_YES 1
3431 static void client_kill_requested(ObPrompt *p, gint result, gpointer data)
3433 ObClient *self = data;
3435 if (result == OB_KILL_RESULT_YES)
3438 prompt_unref(self->kill_prompt);
3439 self->kill_prompt = NULL;
3442 static void client_prompt_kill(ObClient *self)
3444 /* check if we're already prompting */
3445 if (!self->kill_prompt) {
3446 ObPromptAnswer answers[] = {
3447 { _("No"), OB_KILL_RESULT_NO },
3448 { _("Yes"), OB_KILL_RESULT_YES }
3453 if (self->kill_level == 0)
3459 (_("The window \"%s\" does not seem to be responding. Do you want to force it to exit by sending the %s signal?"), self->original_title, sig);
3461 self->kill_prompt = prompt_new(m, answers,
3462 sizeof(answers)/sizeof(answers[0]),
3463 OB_KILL_RESULT_NO, /* default = no */
3464 OB_KILL_RESULT_NO, /* cancel = no */
3465 client_kill_requested, self);
3469 prompt_show(self->kill_prompt, self);
3472 void client_kill(ObClient *self)
3474 /* don't kill our own windows */
3475 if (self->prompt) return;
3477 if (!self->client_machine && self->pid) {
3478 /* running on the local host */
3479 if (self->kill_level == 0) {
3480 ob_debug("killing window 0x%x with pid %lu, with SIGTERM",
3481 self->w_client, self->pid);
3482 kill(self->pid, SIGTERM);
3485 /* show that we're trying to kill it */
3486 client_update_title(self);
3489 ob_debug("killing window 0x%x with pid %lu, with SIGKILL",
3490 self->w_client, self->pid);
3491 kill(self->pid, SIGKILL); /* kill -9 */
3495 /* running on a remote host */
3496 XKillClient(obt_display, self->w_client);
3500 void client_hilite(ObClient *self, gboolean hilite)
3502 if (self->demands_attention == hilite)
3503 return; /* no change */
3505 /* don't allow focused windows to hilite */
3506 self->demands_attention = hilite && !client_focused(self);
3507 if (self->frame != NULL) { /* if we're mapping, just set the state */
3508 if (self->demands_attention)
3509 frame_engine->frame_flash_start(self->frame);
3511 frame_engine->frame_flash_stop(self->frame);
3512 client_change_state(self);
3516 static void client_set_desktop_recursive(ObClient *self,
3524 if (target != self->desktop && self->type != OB_CLIENT_TYPE_DESKTOP) {
3526 ob_debug("Setting desktop %u", target+1);
3528 g_assert(target < screen_num_desktops || target == DESKTOP_ALL);
3530 old = self->desktop;
3531 self->desktop = target;
3532 OBT_PROP_SET32(self->w_client, NET_WM_DESKTOP, CARDINAL, target);
3533 /* the frame can display the current desktop state */
3534 frame_engine->frame_set_decorations (self->frame, self->decorations);
3535 frame_engine->frame_update_layout(self->frame, self->area, FALSE, FALSE);
3536 /* 'move' the window to the new desktop */
3540 /* raise if it was not already on the desktop */
3541 if (old != DESKTOP_ALL && !dontraise)
3542 stacking_raise(CLIENT_AS_WINDOW(self));
3543 if (STRUT_EXISTS(self->strut))
3544 screen_update_areas();
3546 /* the new desktop's geometry may be different, so we may need to
3547 resize, for example if we are maximized */
3548 client_reconfigure(self, FALSE);
3551 /* move all transients */
3552 for (it = self->transients; it; it = g_slist_next(it))
3553 if (it->data != self)
3554 if (client_is_direct_child(self, it->data))
3555 client_set_desktop_recursive(it->data, target,
3556 donthide, dontraise);
3559 void client_set_desktop(ObClient *self, guint target,
3560 gboolean donthide, gboolean dontraise)
3562 self = client_search_top_direct_parent(self);
3563 client_set_desktop_recursive(self, target, donthide, dontraise);
3566 gboolean client_is_direct_child(ObClient *parent, ObClient *child)
3568 while (child != parent && (child = client_direct_parent(child)));
3569 return child == parent;
3572 ObClient *client_search_modal_child(ObClient *self)
3577 for (it = self->transients; it; it = g_slist_next(it)) {
3578 ObClient *c = it->data;
3579 if ((ret = client_search_modal_child(c))) return ret;
3580 if (c->modal) return c;
3585 gboolean client_validate(ObClient *self)
3589 XSync(obt_display, FALSE); /* get all events on the server */
3591 if (XCheckTypedWindowEvent(obt_display, self->w_client, DestroyNotify, &e) ||
3592 XCheckTypedWindowEvent(obt_display, self->w_client, UnmapNotify, &e))
3594 XPutBackEvent(obt_display, &e);
3601 void client_set_wm_state(ObClient *self, glong state)
3603 if (state == self->wmstate) return; /* no change */
3607 client_iconify(self, TRUE, TRUE, FALSE);
3610 client_iconify(self, FALSE, TRUE, FALSE);
3615 void client_set_state(ObClient *self, Atom action, glong data1, glong data2)
3617 gboolean shaded = self->shaded;
3618 gboolean fullscreen = self->fullscreen;
3619 gboolean undecorated = self->undecorated;
3620 gboolean max_horz = self->max_horz;
3621 gboolean max_vert = self->max_vert;
3622 gboolean modal = self->modal;
3623 gboolean iconic = self->iconic;
3624 gboolean demands_attention = self->demands_attention;
3625 gboolean above = self->above;
3626 gboolean below = self->below;
3629 if (!(action == OBT_PROP_ATOM(NET_WM_STATE_ADD) ||
3630 action == OBT_PROP_ATOM(NET_WM_STATE_REMOVE) ||
3631 action == OBT_PROP_ATOM(NET_WM_STATE_TOGGLE)))
3632 /* an invalid action was passed to the client message, ignore it */
3635 for (i = 0; i < 2; ++i) {
3636 Atom state = i == 0 ? data1 : data2;
3638 if (!state) continue;
3640 /* if toggling, then pick whether we're adding or removing */
3641 if (action == OBT_PROP_ATOM(NET_WM_STATE_TOGGLE)) {
3642 if (state == OBT_PROP_ATOM(NET_WM_STATE_MODAL))
3643 action = modal ? OBT_PROP_ATOM(NET_WM_STATE_REMOVE) :
3644 OBT_PROP_ATOM(NET_WM_STATE_ADD);
3645 else if (state == OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_VERT))
3646 action = self->max_vert ? OBT_PROP_ATOM(NET_WM_STATE_REMOVE) :
3647 OBT_PROP_ATOM(NET_WM_STATE_ADD);
3648 else if (state == OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_HORZ))
3649 action = self->max_horz ? OBT_PROP_ATOM(NET_WM_STATE_REMOVE) :
3650 OBT_PROP_ATOM(NET_WM_STATE_ADD);
3651 else if (state == OBT_PROP_ATOM(NET_WM_STATE_SHADED))
3652 action = shaded ? OBT_PROP_ATOM(NET_WM_STATE_REMOVE) :
3653 OBT_PROP_ATOM(NET_WM_STATE_ADD);
3654 else if (state == OBT_PROP_ATOM(NET_WM_STATE_SKIP_TASKBAR))
3655 action = self->skip_taskbar ?
3656 OBT_PROP_ATOM(NET_WM_STATE_REMOVE) :
3657 OBT_PROP_ATOM(NET_WM_STATE_ADD);
3658 else if (state == OBT_PROP_ATOM(NET_WM_STATE_SKIP_PAGER))
3659 action = self->skip_pager ?
3660 OBT_PROP_ATOM(NET_WM_STATE_REMOVE) :
3661 OBT_PROP_ATOM(NET_WM_STATE_ADD);
3662 else if (state == OBT_PROP_ATOM(NET_WM_STATE_HIDDEN))
3663 action = self->iconic ?
3664 OBT_PROP_ATOM(NET_WM_STATE_REMOVE) :
3665 OBT_PROP_ATOM(NET_WM_STATE_ADD);
3666 else if (state == OBT_PROP_ATOM(NET_WM_STATE_FULLSCREEN))
3667 action = fullscreen ?
3668 OBT_PROP_ATOM(NET_WM_STATE_REMOVE) :
3669 OBT_PROP_ATOM(NET_WM_STATE_ADD);
3670 else if (state == OBT_PROP_ATOM(NET_WM_STATE_ABOVE))
3671 action = self->above ? OBT_PROP_ATOM(NET_WM_STATE_REMOVE) :
3672 OBT_PROP_ATOM(NET_WM_STATE_ADD);
3673 else if (state == OBT_PROP_ATOM(NET_WM_STATE_BELOW))
3674 action = self->below ? OBT_PROP_ATOM(NET_WM_STATE_REMOVE) :
3675 OBT_PROP_ATOM(NET_WM_STATE_ADD);
3676 else if (state == OBT_PROP_ATOM(NET_WM_STATE_DEMANDS_ATTENTION))
3677 action = self->demands_attention ?
3678 OBT_PROP_ATOM(NET_WM_STATE_REMOVE) :
3679 OBT_PROP_ATOM(NET_WM_STATE_ADD);
3680 else if (state == OBT_PROP_ATOM(OB_WM_STATE_UNDECORATED))
3681 action = undecorated ? OBT_PROP_ATOM(NET_WM_STATE_REMOVE) :
3682 OBT_PROP_ATOM(NET_WM_STATE_ADD);
3685 if (action == OBT_PROP_ATOM(NET_WM_STATE_ADD)) {
3686 if (state == OBT_PROP_ATOM(NET_WM_STATE_MODAL)) {
3688 } else if (state == OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_VERT)) {
3690 } else if (state == OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_HORZ)) {
3692 } else if (state == OBT_PROP_ATOM(NET_WM_STATE_SHADED)) {
3694 } else if (state == OBT_PROP_ATOM(NET_WM_STATE_SKIP_TASKBAR)) {
3695 self->skip_taskbar = TRUE;
3696 } else if (state == OBT_PROP_ATOM(NET_WM_STATE_SKIP_PAGER)) {
3697 self->skip_pager = TRUE;
3698 } else if (state == OBT_PROP_ATOM(NET_WM_STATE_HIDDEN)) {
3700 } else if (state == OBT_PROP_ATOM(NET_WM_STATE_FULLSCREEN)) {
3702 } else if (state == OBT_PROP_ATOM(NET_WM_STATE_ABOVE)) {
3705 } else if (state == OBT_PROP_ATOM(NET_WM_STATE_BELOW)) {
3708 } else if (state == OBT_PROP_ATOM(NET_WM_STATE_DEMANDS_ATTENTION)){
3709 demands_attention = TRUE;
3710 } else if (state == OBT_PROP_ATOM(OB_WM_STATE_UNDECORATED)) {
3714 } else { /* action == OBT_PROP_ATOM(NET_WM_STATE_REMOVE) */
3715 if (state == OBT_PROP_ATOM(NET_WM_STATE_MODAL)) {
3717 } else if (state == OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_VERT)) {
3719 } else if (state == OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_HORZ)) {
3721 } else if (state == OBT_PROP_ATOM(NET_WM_STATE_SHADED)) {
3723 } else if (state == OBT_PROP_ATOM(NET_WM_STATE_SKIP_TASKBAR)) {
3724 self->skip_taskbar = FALSE;
3725 } else if (state == OBT_PROP_ATOM(NET_WM_STATE_SKIP_PAGER)) {
3726 self->skip_pager = FALSE;
3727 } else if (state == OBT_PROP_ATOM(NET_WM_STATE_HIDDEN)) {
3729 } else if (state == OBT_PROP_ATOM(NET_WM_STATE_FULLSCREEN)) {
3731 } else if (state == OBT_PROP_ATOM(NET_WM_STATE_ABOVE)) {
3733 } else if (state == OBT_PROP_ATOM(NET_WM_STATE_BELOW)) {
3735 } else if (state == OBT_PROP_ATOM(NET_WM_STATE_DEMANDS_ATTENTION)){
3736 demands_attention = FALSE;
3737 } else if (state == OBT_PROP_ATOM(OB_WM_STATE_UNDECORATED)) {
3738 undecorated = FALSE;
3743 if (max_horz != self->max_horz || max_vert != self->max_vert) {
3744 if (max_horz != self->max_horz && max_vert != self->max_vert) {
3746 if (max_horz == max_vert) { /* both going the same way */
3747 client_maximize(self, max_horz, 0);
3749 client_maximize(self, max_horz, 1);
3750 client_maximize(self, max_vert, 2);
3754 if (max_horz != self->max_horz)
3755 client_maximize(self, max_horz, 1);
3757 client_maximize(self, max_vert, 2);
3760 /* change fullscreen state before shading, as it will affect if the window
3762 if (fullscreen != self->fullscreen)
3763 client_fullscreen(self, fullscreen);
3764 if (shaded != self->shaded)
3765 client_shade(self, shaded);
3766 if (undecorated != self->undecorated)
3767 client_set_undecorated(self, undecorated);
3768 if (above != self->above || below != self->below) {
3769 self->above = above;
3770 self->below = below;
3771 client_calc_layer(self);
3774 if (modal != self->modal) {
3775 self->modal = modal;
3776 /* when a window changes modality, then its stacking order with its
3777 transients needs to change */
3778 stacking_raise(CLIENT_AS_WINDOW(self));
3780 /* it also may get focused. if something is focused that shouldn't
3781 be focused anymore, then move the focus */
3782 if (focus_client && client_focus_target(focus_client) != focus_client)
3783 client_focus(focus_client);
3786 if (iconic != self->iconic)
3787 client_iconify(self, iconic, FALSE, FALSE);
3789 if (demands_attention != self->demands_attention)
3790 client_hilite(self, demands_attention);
3792 client_change_state(self); /* change the hint to reflect these changes */
3795 ObClient *client_focus_target(ObClient *self)
3797 ObClient *child = NULL;
3799 child = client_search_modal_child(self);
3800 if (child) return child;
3804 gboolean client_can_focus(ObClient *self)
3806 /* choose the correct target */
3807 self = client_focus_target(self);
3809 if (!frame_engine->frame_is_visible(self->frame))
3812 if (!(self->can_focus || self->focus_notify))
3818 gboolean client_focus(ObClient *self)
3820 /* we might not focus this window, so if we have modal children which would
3821 be focused instead, bring them to this desktop */
3822 client_bring_modal_windows(self);
3824 /* choose the correct target */
3825 self = client_focus_target(self);
3827 if (!client_can_focus(self)) {
3828 ob_debug_type(OB_DEBUG_FOCUS,
3829 "Client %s can't be focused", self->title);
3833 ob_debug_type(OB_DEBUG_FOCUS,
3834 "Focusing client \"%s\" (0x%x) at time %u",
3835 self->title, self->w_client, event_curtime);
3837 /* if using focus_delay, stop the timer now so that focus doesn't
3839 event_halt_focus_delay();
3841 /* if there is a grab going on, then we need to cancel it. if we move
3842 focus during the grab, applications will get NotifyWhileGrabbed events
3845 actions should not rely on being able to move focus during an
3848 event_cancel_all_key_grabs();
3850 obt_display_ignore_errors(TRUE);
3852 if (self->can_focus) {
3853 /* This can cause a BadMatch error with CurrentTime, or if an app
3854 passed in a bad time for _NET_WM_ACTIVE_WINDOW. */
3855 XSetInputFocus(obt_display, self->w_client, RevertToPointerRoot,
3859 if (self->focus_notify) {
3861 ce.xclient.type = ClientMessage;
3862 ce.xclient.message_type = OBT_PROP_ATOM(WM_PROTOCOLS);
3863 ce.xclient.display = obt_display;
3864 ce.xclient.window = self->w_client;
3865 ce.xclient.format = 32;
3866 ce.xclient.data.l[0] = OBT_PROP_ATOM(WM_TAKE_FOCUS);
3867 ce.xclient.data.l[1] = event_curtime;
3868 ce.xclient.data.l[2] = 0l;
3869 ce.xclient.data.l[3] = 0l;
3870 ce.xclient.data.l[4] = 0l;
3871 XSendEvent(obt_display, self->w_client, FALSE, NoEventMask, &ce);
3874 obt_display_ignore_errors(FALSE);
3876 ob_debug_type(OB_DEBUG_FOCUS, "Error focusing? %d",
3877 obt_display_error_occured);
3878 return !obt_display_error_occured;
3881 static void client_present(ObClient *self, gboolean here, gboolean raise,
3884 if (client_normal(self) && screen_showing_desktop)
3885 screen_show_desktop(FALSE, self);
3887 client_iconify(self, FALSE, here, FALSE);
3888 if (self->desktop != DESKTOP_ALL &&
3889 self->desktop != screen_desktop)
3892 client_set_desktop(self, screen_desktop, FALSE, TRUE);
3894 screen_set_desktop(self->desktop, FALSE);
3895 } else if (!frame_engine->frame_is_visible(self->frame))
3896 /* if its not visible for other reasons, then don't mess
3899 if (self->shaded && unshade)
3900 client_shade(self, FALSE);
3902 stacking_raise(CLIENT_AS_WINDOW(self));
3907 void client_activate(ObClient *self, gboolean here, gboolean raise,
3908 gboolean unshade, gboolean user)
3910 client_present(self, here, raise, unshade);
3913 static void client_bring_windows_recursive(ObClient *self,
3921 for (it = self->transients; it; it = g_slist_next(it))
3922 client_bring_windows_recursive(it->data, desktop,
3923 helpers, modals, iconic);
3925 if (((helpers && client_helper(self)) ||
3926 (modals && self->modal)) &&
3927 ((self->desktop != desktop && self->desktop != DESKTOP_ALL) ||
3928 (iconic && self->iconic)))
3930 if (iconic && self->iconic)
3931 client_iconify(self, FALSE, TRUE, FALSE);
3933 client_set_desktop(self, desktop, FALSE, FALSE);
3937 void client_bring_helper_windows(ObClient *self)
3939 client_bring_windows_recursive(self, self->desktop, TRUE, FALSE, FALSE);
3942 void client_bring_modal_windows(ObClient *self)
3944 client_bring_windows_recursive(self, self->desktop, FALSE, TRUE, TRUE);
3947 gboolean client_focused(ObClient *self)
3949 return self == focus_client;
3952 static ObClientIcon* client_icon_recursive(ObClient *self, gint w, gint h)
3955 gulong min_diff, min_i;
3957 if (!self->nicons) {
3958 ObClientIcon *parent = NULL;
3961 for (it = self->parents; it; it = g_slist_next(it)) {
3962 ObClient *c = it->data;
3963 if ((parent = client_icon_recursive(c, w, h)))
3970 /* some kind of crappy approximation to find the icon closest in size to
3971 what we requested, but icons are generally all the same ratio as
3972 eachother so it's good enough. */
3974 min_diff = ABS(self->icons[0].width - w) + ABS(self->icons[0].height - h);
3977 for (i = 1; i < self->nicons; ++i) {
3980 diff = ABS(self->icons[i].width - w) + ABS(self->icons[i].height - h);
3981 if (diff < min_diff) {
3986 return &self->icons[min_i];
3989 const ObClientIcon* client_icon(ObClient *self, gint w, gint h)
3992 static ObClientIcon deficon;
3994 if (!(ret = client_icon_recursive(self, w, h))) {
3995 deficon.width = deficon.height = 48;
3996 deficon.data = ob_rr_theme->def_win_icon;
4002 void client_set_layer(ObClient *self, gint layer)
4006 self->above = FALSE;
4007 } else if (layer == 0) {
4008 self->below = self->above = FALSE;
4010 self->below = FALSE;
4013 client_calc_layer(self);
4014 client_change_state(self); /* reflect this in the state hints */
4017 void client_set_undecorated(ObClient *self, gboolean undecorated)
4019 if (self->undecorated != undecorated &&
4020 /* don't let it undecorate if the function is missing, but let
4022 (self->functions & OB_CLIENT_FUNC_UNDECORATE || !undecorated))
4024 self->undecorated = undecorated;
4025 client_setup_decor_and_functions(self, TRUE);
4026 client_change_state(self); /* reflect this in the state hints */
4030 guint client_monitor(ObClient *self)
4033 frame_engine->frame_get_window_area(self->frame, &area);
4034 return screen_find_monitor(&area);
4037 ObClient *client_direct_parent(ObClient *self)
4039 if (!self->parents) return NULL;
4040 if (self->transient_for_group) return NULL;
4041 return self->parents->data;
4044 ObClient *client_search_top_direct_parent(ObClient *self)
4047 while ((p = client_direct_parent(self))) self = p;
4051 static GSList *client_search_all_top_parents_internal(ObClient *self,
4053 ObStackingLayer layer)
4058 /* move up the direct transient chain as far as possible */
4059 while ((p = client_direct_parent(self)) &&
4060 (!bylayer || p->layer == layer))
4064 ret = g_slist_prepend(NULL, self);
4066 ret = g_slist_copy(self->parents);
4071 GSList *client_search_all_top_parents(ObClient *self)
4073 return client_search_all_top_parents_internal(self, FALSE, 0);
4076 GSList *client_search_all_top_parents_layer(ObClient *self)
4078 return client_search_all_top_parents_internal(self, TRUE, self->layer);
4081 ObClient *client_search_focus_parent(ObClient *self)
4085 for (it = self->parents; it; it = g_slist_next(it))
4086 if (client_focused(it->data)) return it->data;
4091 ObClient *client_search_parent(ObClient *self, ObClient *search)
4095 for (it = self->parents; it; it = g_slist_next(it))
4096 if (it->data == search) return search;
4101 ObClient *client_search_transient(ObClient *self, ObClient *search)
4105 for (sit = self->transients; sit; sit = g_slist_next(sit)) {
4106 if (sit->data == search)
4108 if (client_search_transient(sit->data, search))
4114 static void detect_edge(Rect area, ObDirection dir,
4115 gint my_head, gint my_size,
4116 gint my_edge_start, gint my_edge_size,
4117 gint *dest, gboolean *near_edge)
4119 gint edge_start, edge_size, head, tail;
4120 gboolean skip_head = FALSE, skip_tail = FALSE;
4123 case OB_DIRECTION_NORTH:
4124 case OB_DIRECTION_SOUTH:
4125 edge_start = area.x;
4126 edge_size = area.width;
4128 case OB_DIRECTION_EAST:
4129 case OB_DIRECTION_WEST:
4130 edge_start = area.y;
4131 edge_size = area.height;
4134 g_assert_not_reached();
4137 /* do we collide with this window? */
4138 if (!RANGES_INTERSECT(my_edge_start, my_edge_size,
4139 edge_start, edge_size))
4143 case OB_DIRECTION_NORTH:
4144 head = RECT_BOTTOM(area);
4145 tail = RECT_TOP(area);
4147 case OB_DIRECTION_SOUTH:
4148 head = RECT_TOP(area);
4149 tail = RECT_BOTTOM(area);
4151 case OB_DIRECTION_WEST:
4152 head = RECT_RIGHT(area);
4153 tail = RECT_LEFT(area);
4155 case OB_DIRECTION_EAST:
4156 head = RECT_LEFT(area);
4157 tail = RECT_RIGHT(area);
4160 g_assert_not_reached();
4163 case OB_DIRECTION_NORTH:
4164 case OB_DIRECTION_WEST:
4165 /* check if our window is past the head of this window */
4166 if (my_head <= head + 1)
4168 /* check if our window's tail is past the tail of this window */
4169 if (my_head + my_size - 1 <= tail)
4171 /* check if the head of this window is closer than the previously
4172 chosen edge (take into account that the previously chosen
4173 edge might have been a tail, not a head) */
4174 if (head + (*near_edge ? 0 : my_size) < *dest)
4176 /* check if the tail of this window is closer than the previously
4177 chosen edge (take into account that the previously chosen
4178 edge might have been a head, not a tail) */
4179 if (tail - (!*near_edge ? 0 : my_size) < *dest)
4182 case OB_DIRECTION_SOUTH:
4183 case OB_DIRECTION_EAST:
4184 /* check if our window is past the head of this window */
4185 if (my_head >= head - 1)
4187 /* check if our window's tail is past the tail of this window */
4188 if (my_head - my_size + 1 >= tail)
4190 /* check if the head of this window is closer than the previously
4191 chosen edge (take into account that the previously chosen
4192 edge might have been a tail, not a head) */
4193 if (head - (*near_edge ? 0 : my_size) > *dest)
4195 /* check if the tail of this window is closer than the previously
4196 chosen edge (take into account that the previously chosen
4197 edge might have been a head, not a tail) */
4198 if (tail + (!*near_edge ? 0 : my_size) > *dest)
4202 g_assert_not_reached();
4205 ob_debug("my head %d size %d", my_head, my_size);
4206 ob_debug("head %d tail %d deest %d", head, tail, *dest);
4208 ob_debug("using near edge %d", head);
4212 else if (!skip_tail) {
4213 ob_debug("using far edge %d", tail);
4219 void client_find_edge_directional(ObClient *self, ObDirection dir,
4220 gint my_head, gint my_size,
4221 gint my_edge_start, gint my_edge_size,
4222 gint *dest, gboolean *near_edge)
4230 frame_engine->frame_get_size(self->frame, &size);
4232 frame_engine->frame_get_window_area(self->frame, &area);
4234 a = screen_area(self->desktop, SCREEN_AREA_ALL_MONITORS,
4236 mon = screen_area(self->desktop, SCREEN_AREA_ONE_MONITOR,
4240 case OB_DIRECTION_NORTH:
4241 if (my_head >= RECT_TOP(*mon) + 1)
4242 edge = RECT_TOP(*mon) - 1;
4244 edge = RECT_TOP(*a) - 1;
4246 case OB_DIRECTION_SOUTH:
4247 if (my_head <= RECT_BOTTOM(*mon) - 1)
4248 edge = RECT_BOTTOM(*mon) + 1;
4250 edge = RECT_BOTTOM(*a) + 1;
4252 case OB_DIRECTION_EAST:
4253 if (my_head <= RECT_RIGHT(*mon) - 1)
4254 edge = RECT_RIGHT(*mon) + 1;
4256 edge = RECT_RIGHT(*a) + 1;
4258 case OB_DIRECTION_WEST:
4259 if (my_head >= RECT_LEFT(*mon) + 1)
4260 edge = RECT_LEFT(*mon) - 1;
4262 edge = RECT_LEFT(*a) - 1;
4265 g_assert_not_reached();
4267 /* default to the far edge, then narrow it down */
4271 for (it = client_list; it; it = g_list_next(it)) {
4272 ObClient *cur = it->data;
4274 /* skip windows to not bump into */
4279 if (self->desktop != cur->desktop && cur->desktop != DESKTOP_ALL &&
4280 cur->desktop != screen_desktop)
4283 ob_debug("trying window %s", cur->title);
4286 frame_engine->frame_get_window_area(self->frame, &area);
4287 detect_edge(area, dir, my_head, my_size, my_edge_start,
4288 my_edge_size, dest, near_edge);
4290 dock_get_area(&dock_area);
4291 detect_edge(dock_area, dir, my_head, my_size, my_edge_start,
4292 my_edge_size, dest, near_edge);
4297 void client_find_move_directional(ObClient *self, ObDirection dir,
4301 gint e, e_start, e_size;
4306 frame_engine->frame_get_window_area(self->frame, &area);
4309 case OB_DIRECTION_EAST:
4310 head = RECT_RIGHT(area);
4312 e_start = RECT_TOP(area);
4313 e_size = area.height;
4315 case OB_DIRECTION_WEST:
4316 head = RECT_LEFT(area);
4318 e_start = RECT_TOP(area);
4319 e_size = area.height;
4321 case OB_DIRECTION_NORTH:
4322 head = RECT_TOP(area);
4324 e_start = RECT_LEFT(area);
4325 e_size = area.width;
4327 case OB_DIRECTION_SOUTH:
4328 head = RECT_BOTTOM(area);
4330 e_start = RECT_LEFT(area);
4331 e_size = area.width;
4334 g_assert_not_reached();
4337 client_find_edge_directional(self, dir, head, size,
4338 e_start, e_size, &e, &near);
4342 case OB_DIRECTION_EAST:
4343 if (near) e -= area.width;
4347 case OB_DIRECTION_WEST:
4349 else e -= area.width;
4352 case OB_DIRECTION_NORTH:
4354 else e -= area.height;
4357 case OB_DIRECTION_SOUTH:
4358 if (near) e -= area.height;
4363 g_assert_not_reached();
4365 frame_frame_gravity(self, x, y);
4368 void client_find_resize_directional(ObClient *self, ObDirection side,
4370 gint *x, gint *y, gint *w, gint *h)
4373 gint e, e_start, e_size, delta;
4378 frame_engine->frame_get_window_area(self->frame, &area);
4380 frame_engine->frame_get_size(self->frame, &size);
4383 case OB_DIRECTION_EAST:
4384 head = RECT_RIGHT(area) +
4385 (self->size_inc.width - 1) * (grow ? 1 : -1);
4386 e_start = RECT_TOP(area);
4387 e_size = area.height;
4388 dir = grow ? OB_DIRECTION_EAST : OB_DIRECTION_WEST;
4390 case OB_DIRECTION_WEST:
4391 head = RECT_LEFT(area) -
4392 (self->size_inc.width - 1) * (grow ? 1 : -1);
4393 e_start = RECT_TOP(area);
4394 e_size = area.height;
4395 dir = grow ? OB_DIRECTION_WEST : OB_DIRECTION_EAST;
4397 case OB_DIRECTION_NORTH:
4398 head = RECT_TOP(area) -
4399 (self->size_inc.height - 1) * (grow ? 1 : -1);
4400 e_start = RECT_LEFT(area);
4401 e_size = area.width;
4402 dir = grow ? OB_DIRECTION_NORTH : OB_DIRECTION_SOUTH;
4404 case OB_DIRECTION_SOUTH:
4405 head = RECT_BOTTOM(area) +
4406 (self->size_inc.height - 1) * (grow ? 1 : -1);
4407 e_start = RECT_LEFT(area);
4408 e_size = area.width;
4409 dir = grow ? OB_DIRECTION_SOUTH : OB_DIRECTION_NORTH;
4412 g_assert_not_reached();
4415 ob_debug("head %d dir %d", head, dir);
4416 client_find_edge_directional(self, dir, head, 1,
4417 e_start, e_size, &e, &near);
4418 ob_debug("edge %d", e);
4424 case OB_DIRECTION_EAST:
4425 if (grow == near) --e;
4426 delta = e - RECT_RIGHT(area);
4429 case OB_DIRECTION_WEST:
4430 if (grow == near) ++e;
4431 delta = RECT_LEFT(area) - e;
4435 case OB_DIRECTION_NORTH:
4436 if (grow == near) ++e;
4437 delta = RECT_TOP(area) - e;
4441 case OB_DIRECTION_SOUTH:
4442 if (grow == near) --e;
4443 delta = e - RECT_BOTTOM(area);
4447 g_assert_not_reached();
4449 frame_frame_gravity(self, x, y);
4450 *w -= size.left + size.right;
4451 *h -= size.top + size.bottom;
4454 ObClient* client_under_pointer(void)
4458 ObClient *ret = NULL;
4460 if (screen_pointer_pos(&x, &y)) {
4461 for (it = stacking_list; it; it = g_list_next(it)) {
4462 if (WINDOW_IS_CLIENT(it->data)) {
4463 ObClient *c = WINDOW_AS_CLIENT(it->data);
4465 frame_engine->frame_get_window_area(c->frame, &area);
4466 if (frame_engine->frame_is_visible(c->frame) &&
4467 /* check the desktop, this is done during desktop
4468 switching and windows are shown/hidden status is not
4470 (c->desktop == screen_desktop ||
4471 c->desktop == DESKTOP_ALL) &&
4472 RECT_CONTAINS(area, x, y))
4483 gboolean client_has_group_siblings(ObClient *self)
4485 return self->group && self->group->members->next;
4488 void client_show_frame(ObClient * self)
4490 frame_engine->frame_set_is_visible(self->frame, TRUE);
4491 frame_engine->frame_update_layout(self->frame, self->area, FALSE, FALSE);
4492 frame_engine->frame_update_skin(self->frame);
4493 /* Grab the server to make sure that the frame window is mapped before
4494 the client gets its MapNotify, i.e. to make sure the client is
4495 _visible_ when it gets MapNotify. */
4497 XMapWindow(obt_display, self->w_client);
4498 XMapWindow(obt_display, self->w_frame);
4502 void client_hide_frame(ObClient * self)
4504 frame_engine->frame_set_is_visible(self->frame, FALSE);
4505 XUnmapWindow(obt_display, self->w_frame);
4506 /* we unmap the client itself so that we can get MapRequest
4507 events, and because the ICCCM tells us to! */
4508 XUnmapWindow(obt_display, self->w_client);
4509 self->ignore_unmaps++;