1 /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
3 client.c for the Openbox window manager
4 Copyright (c) 2006 Mikael Magnusson
5 Copyright (c) 2003-2007 Dana Jansens
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 See the COPYING file for a copy of the GNU General Public License.
22 #include "startupnotify.h"
25 #include "moveresize.h"
34 #include "focus_cycle.h"
39 #include "menuframe.h"
42 #include "obrender/render.h"
44 #include "obt/display.h"
45 #include "obt/xqueue.h"
53 # include <signal.h> /* for kill() */
57 #include <X11/Xutil.h>
59 /*! The event mask to grab on client windows */
60 #define CLIENT_EVENTMASK (PropertyChangeMask | StructureNotifyMask | \
63 #define CLIENT_NOPROPAGATEMASK (ButtonPressMask | ButtonReleaseMask | \
68 ObClientCallback func
;
72 GList
*client_list
= NULL
;
74 static GSList
*client_destroy_notifies
= NULL
;
75 static RrImage
*client_default_icon
= NULL
;
77 static void client_get_all(ObClient
*self
, gboolean real
);
78 static void client_get_startup_id(ObClient
*self
);
79 static void client_get_session_ids(ObClient
*self
);
80 static void client_save_app_rule_values(ObClient
*self
);
81 static void client_get_area(ObClient
*self
);
82 static void client_get_desktop(ObClient
*self
);
83 static void client_get_state(ObClient
*self
);
84 static void client_get_shaped(ObClient
*self
);
85 static void client_get_colormap(ObClient
*self
);
86 static void client_set_desktop_recursive(ObClient
*self
,
90 static void client_change_allowed_actions(ObClient
*self
);
91 static void client_change_state(ObClient
*self
);
92 static void client_change_wm_state(ObClient
*self
);
93 static void client_apply_startup_state(ObClient
*self
,
94 gint x
, gint y
, gint w
, gint h
);
95 static void client_restore_session_state(ObClient
*self
);
96 static gboolean
client_restore_session_stacking(ObClient
*self
);
97 static ObAppSettings
*client_get_settings_state(ObClient
*self
);
98 static void client_update_transient_tree(ObClient
*self
,
99 ObGroup
*oldgroup
, ObGroup
*newgroup
,
100 gboolean oldgtran
, gboolean newgtran
,
102 ObClient
*newparent
);
103 static void client_present(ObClient
*self
, gboolean here
, gboolean raise
,
105 static GSList
*client_search_all_top_parents_internal(ObClient
*self
,
107 ObStackingLayer layer
);
108 static void client_call_notifies(ObClient
*self
, GSList
*list
);
109 static void client_ping_event(ObClient
*self
, gboolean dead
);
110 static void client_prompt_kill(ObClient
*self
);
111 static gboolean
client_can_steal_focus(ObClient
*self
,
112 gboolean allow_other_desktop
,
113 gboolean request_from_user
,
114 Time steal_time
, Time launch_time
);
115 static void client_setup_default_decor_and_functions(ObClient
*self
);
116 static void client_setup_decor_undecorated(ObClient
*self
);
118 void client_startup(gboolean reconfig
)
120 client_default_icon
= RrImageNewFromData(
121 ob_rr_icons
, ob_rr_theme
->def_win_icon
,
122 ob_rr_theme
->def_win_icon_w
, ob_rr_theme
->def_win_icon_h
);
124 if (reconfig
) return;
129 void client_shutdown(gboolean reconfig
)
131 RrImageUnref(client_default_icon
);
132 client_default_icon
= NULL
;
134 if (reconfig
) return;
137 static void client_call_notifies(ObClient
*self
, GSList
*list
)
141 for (it
= list
; it
; it
= g_slist_next(it
)) {
142 ClientCallback
*d
= it
->data
;
143 d
->func(self
, d
->data
);
147 void client_add_destroy_notify(ObClientCallback func
, gpointer data
)
149 ClientCallback
*d
= g_slice_new(ClientCallback
);
152 client_destroy_notifies
= g_slist_prepend(client_destroy_notifies
, d
);
155 void client_remove_destroy_notify(ObClientCallback func
)
159 for (it
= client_destroy_notifies
; it
; it
= g_slist_next(it
)) {
160 ClientCallback
*d
= it
->data
;
161 if (d
->func
== func
) {
162 g_slice_free(ClientCallback
, d
);
163 client_destroy_notifies
=
164 g_slist_delete_link(client_destroy_notifies
, it
);
170 void client_set_list(void)
172 Window
*windows
, *win_it
;
174 guint size
= g_list_length(client_list
);
176 /* create an array of the window ids */
178 windows
= g_new(Window
, size
);
180 for (it
= client_list
; it
; it
= g_list_next(it
), ++win_it
)
181 *win_it
= ((ObClient
*)it
->data
)->window
;
185 OBT_PROP_SETA32(obt_root(ob_screen
), NET_CLIENT_LIST
, WINDOW
,
186 (gulong
*)windows
, size
);
194 void client_manage(Window window
, ObPrompt
*prompt
)
197 XSetWindowAttributes attrib_set
;
198 gboolean try_activate
= FALSE
;
199 gboolean do_activate
;
200 ObAppSettings
*settings
;
201 gboolean transient
= FALSE
;
208 ob_debug("Managing window: 0x%lx", window
);
210 /* choose the events we want to receive on the CLIENT window
211 (ObPrompt windows can request events too) */
212 attrib_set
.event_mask
= CLIENT_EVENTMASK
|
213 (prompt
? prompt
->event_mask
: 0);
214 attrib_set
.do_not_propagate_mask
= CLIENT_NOPROPAGATEMASK
;
215 XChangeWindowAttributes(obt_display
, window
,
216 CWEventMask
|CWDontPropagate
, &attrib_set
);
218 /* create the ObClient struct, and populate it from the hints on the
220 self
= g_slice_new0(ObClient
);
221 self
->obwin
.type
= OB_WINDOW_CLASS_CLIENT
;
222 self
->window
= window
;
223 self
->prompt
= prompt
;
224 self
->managed
= TRUE
;
226 /* non-zero defaults */
227 self
->wmstate
= WithdrawnState
; /* make sure it gets updated first time */
228 self
->gravity
= NorthWestGravity
;
229 self
->desktop
= screen_num_desktops
; /* always an invalid value */
231 /* get all the stuff off the window */
232 client_get_all(self
, TRUE
);
234 ob_debug("Window type: %d", self
->type
);
235 ob_debug("Window group: 0x%x", self
->group
?self
->group
->leader
:0);
236 ob_debug("Window name: %s class: %s role: %s title: %s",
237 self
->name
, self
->class, self
->role
, self
->title
);
239 /* per-app settings override stuff from client_get_all, and return the
240 settings for other uses too. the returned settings is a shallow copy,
241 that needs to be freed with g_free(). */
242 settings
= client_get_settings_state(self
);
244 /* the session should get the last say though */
245 client_restore_session_state(self
);
247 /* the per-app settings/session may have changed the decorations for
248 the window, so we setup decorations for that here. this is a special
249 case because we want to place the window according to these decoration
251 we do this before setting up the frame so that it will reflect the
252 decorations of the window as it will be placed on screen.
254 client_setup_decor_undecorated(self
);
256 /* specify that if we exit, the window should not be destroyed and
257 should be reparented back to root automatically, unless we are managing
258 an internal ObPrompt window */
260 XChangeSaveSet(obt_display
, window
, SetModeInsert
);
262 /* create the decoration frame for the client window */
263 self
->frame
= frame_new(self
);
265 frame_grab_client(self
->frame
);
267 /* we've grabbed everything and set everything that we need to at mapping
271 /* this needs to occur once we have a frame, since it sets a property on
273 client_update_opacity(self
);
275 /* don't put helper/modal windows on a different desktop if they are
276 related to the focused window. */
277 if (!screen_compare_desktops(self
->desktop
, screen_desktop
) &&
278 focus_client
&& client_search_transient(focus_client
, self
) &&
279 (client_helper(self
) || self
->modal
))
281 self
->desktop
= screen_desktop
;
284 /* tell startup notification that this app started */
285 launch_time
= sn_app_started(self
->startup_id
, self
->class, self
->name
);
287 if (!OBT_PROP_GET32(self
->window
, NET_WM_USER_TIME
, CARDINAL
, &user_time
))
288 user_time
= event_time();
290 /* do this after we have a frame.. it uses the frame to help determine the
291 WM_STATE to apply. */
292 client_change_state(self
);
294 /* add ourselves to the focus order */
295 focus_order_add_new(self
);
297 /* do this to add ourselves to the stacking list in a non-intrusive way */
298 client_calc_layer(self
);
300 /* focus the new window? */
301 if (ob_state() != OB_STATE_STARTING
&&
302 (!self
->session
|| self
->session
->focused
) &&
303 /* this means focus=true for window is same as config_focus_new=true */
304 ((config_focus_new
|| settings
->focus
== 1) ||
305 client_search_focus_tree_full(self
)) &&
306 /* NET_WM_USER_TIME 0 when mapping means don't focus */
308 /* this checks for focus=false for the window */
309 settings
->focus
!= 0 &&
310 focus_valid_target(self
, self
->desktop
,
311 FALSE
, FALSE
, TRUE
, TRUE
, FALSE
, FALSE
,
312 settings
->focus
== 1))
317 /* remove the client's border */
318 XSetWindowBorderWidth(obt_display
, self
->window
, 0);
320 /* adjust the frame to the client's size before showing or placing
322 frame_adjust_area(self
->frame
, FALSE
, TRUE
, FALSE
);
323 frame_adjust_client_area(self
->frame
);
325 /* where the frame was placed is where the window was originally */
328 ob_debug("Going to try activate new window? %s",
329 try_activate
? "yes" : "no");
331 do_activate
= client_can_steal_focus(
332 self
, settings
->focus
== 1,
333 (!!launch_time
|| settings
->focus
== 1),
334 event_time(), launch_time
);
338 /* figure out placement for the window if the window is new */
339 if (ob_state() == OB_STATE_RUNNING
) {
340 ob_debug("Positioned: %s @ %d %d",
341 (!self
->positioned
? "no" :
342 (self
->positioned
== PPosition
? "program specified" :
343 (self
->positioned
== USPosition
? "user specified" :
344 (self
->positioned
== (PPosition
| USPosition
) ?
345 "program + user specified" :
346 "BADNESS !?")))), place
.x
, place
.y
);
348 ob_debug("Sized: %s @ %d %d",
349 (!self
->sized
? "no" :
350 (self
->sized
== PSize
? "program specified" :
351 (self
->sized
== USSize
? "user specified" :
352 (self
->sized
== (PSize
| USSize
) ?
353 "program + user specified" :
354 "BADNESS !?")))), place
.width
, place
.height
);
356 obplaced
= place_client(self
, do_activate
, &place
.x
, &place
.y
,
359 /* watch for buggy apps that ask to be placed at (0,0) when there is
361 if (!obplaced
&& place
.x
== 0 && place
.y
== 0 &&
362 /* non-normal windows are allowed */
363 client_normal(self
) &&
364 /* oldschool fullscreen windows are allowed */
365 !client_is_oldfullscreen(self
, &place
))
369 r
= screen_area(self
->desktop
, SCREEN_AREA_ALL_MONITORS
, NULL
);
373 ob_debug("Moving buggy app from (0,0) to (%d,%d)", r
->x
, r
->y
);
375 g_slice_free(Rect
, r
);
378 /* make sure the window is visible. */
379 client_find_onscreen(self
, &place
.x
, &place
.y
,
380 place
.width
, place
.height
,
381 /* non-normal clients has less rules, and
382 windows that are being restored from a
383 session do also. we can assume you want
384 it back where you saved it. Clients saying
385 they placed themselves are subjected to
386 harder rules, ones that are placed by
387 place.c or by the user are allowed partially
388 off-screen and on xinerama divides (ie,
389 it is up to the placement routines to avoid
390 the xinerama divides)
392 children and splash screens are forced on
393 screen, but i don't remember why i decided to
396 ob_state() == OB_STATE_RUNNING
&&
397 (self
->type
== OB_CLIENT_TYPE_DIALOG
||
398 self
->type
== OB_CLIENT_TYPE_SPLASH
||
399 (!((self
->positioned
& USPosition
) ||
400 settings
->pos_given
) &&
401 client_normal(self
) &&
403 /* don't move oldschool fullscreen windows to
404 fit inside the struts (fixes Acroread, which
405 makes its fullscreen window fit the screen
406 but it is not USSize'd or USPosition'd) */
407 !client_is_oldfullscreen(self
, &place
))));
410 /* if the window isn't user-sized, then make it fit inside
411 the visible screen area on its monitor. Use basically the same rules
412 for forcing the window on screen in the client_find_onscreen call.
414 do this after place_client, it chooses the monitor!
416 splash screens get "transient" set to TRUE by
417 the place_client call
419 if (ob_state() == OB_STATE_RUNNING
&&
421 (!(self
->sized
& USSize
|| self
->positioned
& USPosition
) &&
422 client_normal(self
) &&
424 /* don't shrink oldschool fullscreen windows to fit inside the
425 struts (fixes Acroread, which makes its fullscreen window
426 fit the screen but it is not USSize'd or USPosition'd) */
427 !client_is_oldfullscreen(self
, &place
))))
429 Rect
*a
= screen_area(self
->desktop
, SCREEN_AREA_ONE_MONITOR
, &place
);
431 /* get the size of the frame */
432 place
.width
+= self
->frame
->size
.left
+ self
->frame
->size
.right
;
433 place
.height
+= self
->frame
->size
.top
+ self
->frame
->size
.bottom
;
435 /* fit the window inside the area */
436 place
.width
= MIN(place
.width
, a
->width
);
437 place
.height
= MIN(place
.height
, a
->height
);
439 ob_debug("setting window size to %dx%d", place
.width
, place
.height
);
441 /* get the size of the client back */
442 place
.width
-= self
->frame
->size
.left
+ self
->frame
->size
.right
;
443 place
.height
-= self
->frame
->size
.top
+ self
->frame
->size
.bottom
;
445 g_slice_free(Rect
, a
);
448 ob_debug("placing window 0x%x at %d, %d with size %d x %d. "
449 "some restrictions may apply",
450 self
->window
, place
.x
, place
.y
, place
.width
, place
.height
);
452 ob_debug(" but session requested %d, %d %d x %d instead, "
454 self
->session
->x
, self
->session
->y
,
455 self
->session
->w
, self
->session
->h
);
457 /* do this after the window is placed, so the premax/prefullscreen numbers
460 this also places the window
462 client_apply_startup_state(self
, place
.x
, place
.y
,
463 place
.width
, place
.height
);
465 /* set the initial value of the desktop hint, when one wasn't requested
467 OBT_PROP_SET32(self
->window
, NET_WM_DESKTOP
, CARDINAL
, self
->desktop
);
469 /* grab mouse bindings before showing the window */
470 mouse_grab_for_client(self
, TRUE
);
472 if (!config_focus_under_mouse
)
473 ignore_start
= event_start_ignore_all_enters();
475 /* this has to happen before we try focus the window, but we want it to
476 happen after the client's stacking has been determined or it looks bad
480 /* activate/hilight/raise the window */
483 gboolean stacked
= client_restore_session_stacking(self
);
484 client_present(self
, FALSE
, !stacked
, TRUE
);
487 /* if the client isn't stealing focus, then hilite it so the user
488 knows it is there, but don't do this if we're restoring from a
490 if (!client_restore_session_stacking(self
))
491 client_hilite(self
, TRUE
);
495 /* This may look rather odd. Well it's because new windows are added
496 to the stacking order non-intrusively. If we're not going to focus
497 the new window or hilite it, then we raise it to the top. This will
498 take affect for things that don't get focused like splash screens.
499 Also if you don't have focus_new enabled, then it's going to get
500 raised to the top. Legacy begets legacy I guess?
502 if (!client_restore_session_stacking(self
))
503 stacking_raise(CLIENT_AS_WINDOW(self
));
506 if (!config_focus_under_mouse
)
507 event_end_ignore_all_enters(ignore_start
);
509 /* add to client list/map */
510 client_list
= g_list_append(client_list
, self
);
511 window_add(&self
->window
, CLIENT_AS_WINDOW(self
));
513 /* this has to happen after we're in the client_list */
514 if (STRUT_EXISTS(self
->strut
))
515 screen_update_areas();
517 /* update the list hints */
520 /* free the ObAppSettings shallow copy */
521 g_slice_free(ObAppSettings
, settings
);
523 ob_debug("Managed window 0x%lx plate 0x%x (%s)",
524 window
, self
->frame
->window
, self
->class);
527 ObClient
*client_fake_manage(Window window
)
530 ObAppSettings
*settings
;
532 ob_debug("Pretend-managing window: %lx", window
);
534 /* do this minimal stuff to figure out the client's decorations */
536 self
= g_slice_new0(ObClient
);
537 self
->window
= window
;
539 client_get_all(self
, FALSE
);
540 /* per-app settings override stuff, and return the settings for other
541 uses too. this returns a shallow copy that needs to be freed */
542 settings
= client_get_settings_state(self
);
544 /* create the decoration frame for the client window and adjust its size */
545 self
->frame
= frame_new(self
);
547 client_apply_startup_state(self
, self
->area
.x
, self
->area
.y
,
548 self
->area
.width
, self
->area
.height
);
550 ob_debug("gave extents left %d right %d top %d bottom %d",
551 self
->frame
->size
.left
, self
->frame
->size
.right
,
552 self
->frame
->size
.top
, self
->frame
->size
.bottom
);
554 /* free the ObAppSettings shallow copy */
555 g_slice_free(ObAppSettings
, settings
);
560 void client_unmanage_all(void)
563 client_unmanage(client_list
->data
);
566 void client_unmanage(ObClient
*self
)
571 ob_debug("Unmanaging window: 0x%x plate 0x%x (%s) (%s)",
572 self
->window
, self
->frame
->window
,
573 self
->class, self
->title
? self
->title
: "");
575 g_assert(self
!= NULL
);
577 /* we dont want events no more. do this before hiding the frame so we
578 don't generate more events */
579 XSelectInput(obt_display
, self
->window
, NoEventMask
);
581 /* ignore enter events from the unmap so it doesnt mess with the focus */
582 if (!config_focus_under_mouse
)
583 ignore_start
= event_start_ignore_all_enters();
585 frame_hide(self
->frame
);
586 /* flush to send the hide to the server quickly */
589 if (!config_focus_under_mouse
)
590 event_end_ignore_all_enters(ignore_start
);
592 mouse_grab_for_client(self
, FALSE
);
594 self
->managed
= FALSE
;
596 /* remove the window from our save set, unless we are managing an internal
599 XChangeSaveSet(obt_display
, self
->window
, SetModeDelete
);
601 /* update the focus lists */
602 focus_order_remove(self
);
603 if (client_focused(self
)) {
604 /* don't leave an invalid focus_client */
608 /* if we're prompting to kill the client, close that */
609 prompt_unref(self
->kill_prompt
);
610 self
->kill_prompt
= NULL
;
612 client_list
= g_list_remove(client_list
, self
);
613 stacking_remove(self
);
614 window_remove(self
->window
);
616 /* once the client is out of the list, update the struts to remove its
618 if (STRUT_EXISTS(self
->strut
))
619 screen_update_areas();
621 client_call_notifies(self
, client_destroy_notifies
);
623 /* tell our parent(s) that we're gone */
624 for (it
= self
->parents
; it
; it
= g_slist_next(it
))
625 ((ObClient
*)it
->data
)->transients
=
626 g_slist_remove(((ObClient
*)it
->data
)->transients
,self
);
628 /* tell our transients that we're gone */
629 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
630 ((ObClient
*)it
->data
)->parents
=
631 g_slist_remove(((ObClient
*)it
->data
)->parents
, self
);
632 /* we could be keeping our children in a higher layer */
633 client_calc_layer(it
->data
);
636 /* remove from its group */
638 group_remove(self
->group
, self
);
642 /* restore the window's original geometry so it is not lost */
648 if (self
->fullscreen
)
649 a
= self
->pre_fullscreen_area
;
650 else if (self
->max_horz
|| self
->max_vert
) {
651 if (self
->max_horz
) {
652 a
.x
= self
->pre_max_area
.x
;
653 a
.width
= self
->pre_max_area
.width
;
655 if (self
->max_vert
) {
656 a
.y
= self
->pre_max_area
.y
;
657 a
.height
= self
->pre_max_area
.height
;
661 self
->fullscreen
= self
->max_horz
= self
->max_vert
= FALSE
;
662 /* let it be moved and resized no matter what */
663 self
->functions
= OB_CLIENT_FUNC_MOVE
| OB_CLIENT_FUNC_RESIZE
;
664 self
->decorations
= 0; /* unmanaged windows have no decor */
666 /* give the client its border back */
667 XSetWindowBorderWidth(obt_display
, self
->window
, self
->border_width
);
669 client_move_resize(self
, a
.x
, a
.y
, a
.width
, a
.height
);
672 /* reparent the window out of the frame, and free the frame */
673 frame_release_client(self
->frame
);
674 frame_free(self
->frame
);
677 if (ob_state() != OB_STATE_EXITING
) {
678 /* these values should not be persisted across a window
680 OBT_PROP_ERASE(self
->window
, NET_WM_DESKTOP
);
681 OBT_PROP_ERASE(self
->window
, NET_WM_STATE
);
682 OBT_PROP_ERASE(self
->window
, WM_STATE
);
684 /* if we're left in an unmapped state, the client wont be mapped.
685 this is bad, since we will no longer be managing the window on
687 XMapWindow(obt_display
, self
->window
);
690 /* these should not be left on the window ever. other window managers
691 don't necessarily use them and it will mess them up (like compiz) */
692 OBT_PROP_ERASE(self
->window
, NET_WM_VISIBLE_NAME
);
693 OBT_PROP_ERASE(self
->window
, NET_WM_VISIBLE_ICON_NAME
);
695 /* update the list hints */
698 ob_debug("Unmanaged window 0x%lx", self
->window
);
700 /* free all data allocated in the client struct */
701 RrImageUnref(self
->icon_set
);
702 g_slist_free(self
->transients
);
703 g_free(self
->startup_id
);
704 g_free(self
->wm_command
);
706 g_free(self
->icon_title
);
707 g_free(self
->original_title
);
711 g_free(self
->client_machine
);
712 g_free(self
->sm_client_id
);
713 g_slice_free(ObClient
, self
);
716 void client_fake_unmanage(ObClient
*self
)
718 /* this is all that got allocated to get the decorations */
720 frame_free(self
->frame
);
721 g_slice_free(ObClient
, self
);
724 static gboolean
client_can_steal_focus(ObClient
*self
,
725 gboolean allow_other_desktop
,
726 gboolean request_from_user
,
731 gboolean relative_focused
;
735 relative_focused
= (focus_client
!= NULL
&&
736 (client_search_focus_tree_full(self
) != NULL
||
737 client_search_focus_group_full(self
) != NULL
));
739 /* This is focus stealing prevention */
740 ob_debug("Want to focus window 0x%x at time %u "
741 "launched at %u (last user interaction time %u) "
742 "request from %s, allow other desktop: %s, "
743 "desktop switch time %u",
744 self
->window
, steal_time
, launch_time
,
745 event_last_user_time
,
746 (request_from_user
? "user" : "other"),
747 (allow_other_desktop
? "yes" : "no"),
748 screen_desktop_user_time
);
751 if no launch time is provided for an application, make one up.
753 if the window is related to other existing windows
754 and one of those windows was the last used
755 then we will give it a launch time equal to the last user time,
756 which will end up giving the window focus probably.
758 the window is related to other windows, but you are not working in
760 seems suspicious, so we will give it a launch time of
761 NOW - STEAL_INTERVAL,
762 so it will be given focus only if we didn't use something else
763 during the steal interval.
765 the window is all on its own, so we can't judge it. give it a launch
766 time equal to the last user time, so it will probably take focus.
768 this way running things from a terminal will give them focus, but popups
769 without a launch time shouldn't steal focus so easily.
773 if (client_has_relative(self
)) {
774 if (event_last_user_time
&& client_search_focus_group_full(self
)) {
775 /* our relative is focused */
776 launch_time
= event_last_user_time
;
777 ob_debug("Unknown launch time, using %u - window in active "
778 "group", launch_time
);
780 else if (!request_from_user
) {
781 /* has relatives which are not being used. suspicious */
782 launch_time
= event_time() - OB_EVENT_USER_TIME_DELAY
;
783 ob_debug("Unknown launch time, using %u - window in inactive "
784 "group", launch_time
);
787 /* has relatives which are not being used, but the user seems
788 to want to go there! */
789 launch_time
= event_last_user_time
;
790 ob_debug("Unknown launch time, using %u - user request",
795 /* the window is on its own, probably the user knows it is going
797 launch_time
= event_last_user_time
;
798 ob_debug("Unknown launch time, using %u - independent window",
803 /* if it's on another desktop
804 and if allow_other_desktop is true, we generally let it steal focus.
805 but if it didn't come from the user, don't let it steal unless it was
806 launched before the user switched desktops.
807 focus, unless it was launched after we changed desktops and the request
810 if (!screen_compare_desktops(screen_desktop
, self
->desktop
)) {
811 /* must be allowed */
812 if (!allow_other_desktop
) {
814 ob_debug("Not focusing the window because its on another desktop");
816 /* if we don't know when the desktop changed, but request is from an
817 application, don't let it change desktop on you */
818 else if (!request_from_user
) {
820 ob_debug("Not focusing the window because non-user request");
823 /* If something is focused... */
824 else if (focus_client
) {
825 /* If the user is working in another window right now, then don't
827 if (!relative_focused
&&
828 event_last_user_time
&&
829 /* last user time must be strictly > launch_time to block focus */
830 (event_time_after(event_last_user_time
, launch_time
) &&
831 event_last_user_time
!= launch_time
) &&
832 event_time_after(event_last_user_time
,
833 steal_time
- OB_EVENT_USER_TIME_DELAY
))
836 ob_debug("Not focusing the window because the user is "
837 "working in another window that is not its relative");
839 /* Don't move focus if it's not going to go to this window
841 else if (client_focus_target(self
) != self
) {
843 ob_debug("Not focusing the window because another window "
844 "would get the focus anyway");
846 /* For requests that don't come from the user */
847 else if (!request_from_user
) {
848 /* If the new window is a transient (and its relatives aren't
850 if (client_has_parent(self
) && !relative_focused
) {
852 ob_debug("Not focusing the window because it is a "
853 "transient, and its relatives aren't focused");
855 /* Don't steal focus from globally active clients.
856 I stole this idea from KWin. It seems nice.
858 else if (!(focus_client
->can_focus
|| focus_client
->focus_notify
))
861 ob_debug("Not focusing the window because a globally "
862 "active client has focus");
864 /* Don't move focus if the window is not visible on the current
865 desktop and none of its relatives are focused */
866 else if (!allow_other_desktop
&&
867 !screen_compare_desktops(self
->desktop
, screen_desktop
) &&
871 ob_debug("Not focusing the window because it is on "
872 "another desktop and no relatives are focused ");
878 ob_debug("Focus stealing prevention activated for %s at "
879 "time %u (last user interaction time %u)",
880 self
->title
, steal_time
, event_last_user_time
);
882 ob_debug("Allowing focus stealing for %s at time %u (last user "
883 "interaction time %u)",
884 self
->title
, steal_time
, event_last_user_time
);
888 /*! Returns a new structure containing the per-app settings for this client.
889 The returned structure needs to be freed with g_free. */
890 static ObAppSettings
*client_get_settings_state(ObClient
*self
)
892 ObAppSettings
*settings
;
895 settings
= config_create_app_settings();
897 for (it
= config_per_app_settings
; it
; it
= g_slist_next(it
)) {
898 ObAppSettings
*app
= it
->data
;
899 gboolean match
= TRUE
;
901 g_assert(app
->name
!= NULL
|| app
->class != NULL
||
902 app
->role
!= NULL
|| app
->title
!= NULL
||
903 (signed)app
->type
>= 0);
906 !g_pattern_match(app
->name
, strlen(self
->name
), self
->name
, NULL
))
908 else if (app
->class &&
909 !g_pattern_match(app
->class,
910 strlen(self
->class), self
->class, NULL
))
912 else if (app
->role
&&
913 !g_pattern_match(app
->role
,
914 strlen(self
->role
), self
->role
, NULL
))
916 else if (app
->title
&&
917 !g_pattern_match(app
->title
,
918 strlen(self
->title
), self
->title
, NULL
))
920 else if ((signed)app
->type
>= 0 && app
->type
!= self
->type
) {
925 ob_debug("Window matching: %s", app
->name
);
927 /* copy the settings to our struct, overriding the existing
928 settings if they are not defaults */
929 config_app_settings_copy_non_defaults(app
, settings
);
933 if (settings
->shade
!= -1)
934 self
->shaded
= !!settings
->shade
;
935 if (settings
->decor
!= -1)
936 self
->undecorated
= !settings
->decor
;
937 if (settings
->iconic
!= -1)
938 self
->iconic
= !!settings
->iconic
;
939 if (settings
->skip_pager
!= -1)
940 self
->skip_pager
= !!settings
->skip_pager
;
941 if (settings
->skip_taskbar
!= -1)
942 self
->skip_taskbar
= !!settings
->skip_taskbar
;
944 if (settings
->max_vert
!= -1)
945 self
->max_vert
= !!settings
->max_vert
;
946 if (settings
->max_horz
!= -1)
947 self
->max_horz
= !!settings
->max_horz
;
949 if (settings
->fullscreen
!= -1)
950 self
->fullscreen
= !!settings
->fullscreen
;
952 if (settings
->desktop
) {
953 if (settings
->desktop
== DESKTOP_ALL
)
954 self
->desktop
= settings
->desktop
;
955 else if (settings
->desktop
> 0 &&
956 settings
->desktop
<= screen_num_desktops
)
957 self
->desktop
= settings
->desktop
- 1;
960 if (settings
->layer
== -1) {
964 else if (settings
->layer
== 0) {
968 else if (settings
->layer
== 1) {
975 static void client_restore_session_state(ObClient
*self
)
979 ob_debug_type(OB_DEBUG_SM
,
980 "Restore session for client %s", self
->title
);
982 if (!(it
= session_state_find(self
))) {
983 ob_debug_type(OB_DEBUG_SM
,
984 "Session data not found for client %s", self
->title
);
988 self
->session
= it
->data
;
990 ob_debug_type(OB_DEBUG_SM
, "Session data loaded for client %s",
993 RECT_SET_POINT(self
->area
, self
->session
->x
, self
->session
->y
);
994 self
->positioned
= USPosition
;
995 self
->sized
= USSize
;
996 if (self
->session
->w
> 0)
997 self
->area
.width
= self
->session
->w
;
998 if (self
->session
->h
> 0)
999 self
->area
.height
= self
->session
->h
;
1000 XResizeWindow(obt_display
, self
->window
,
1001 self
->area
.width
, self
->area
.height
);
1003 self
->desktop
= (self
->session
->desktop
== DESKTOP_ALL
?
1004 self
->session
->desktop
:
1005 MIN(screen_num_desktops
- 1, self
->session
->desktop
));
1006 OBT_PROP_SET32(self
->window
, NET_WM_DESKTOP
, CARDINAL
, self
->desktop
);
1008 self
->shaded
= self
->session
->shaded
;
1009 self
->iconic
= self
->session
->iconic
;
1010 self
->skip_pager
= self
->session
->skip_pager
;
1011 self
->skip_taskbar
= self
->session
->skip_taskbar
;
1012 self
->fullscreen
= self
->session
->fullscreen
;
1013 self
->above
= self
->session
->above
;
1014 self
->below
= self
->session
->below
;
1015 self
->max_horz
= self
->session
->max_horz
;
1016 self
->max_vert
= self
->session
->max_vert
;
1017 self
->undecorated
= self
->session
->undecorated
;
1020 static gboolean
client_restore_session_stacking(ObClient
*self
)
1024 if (!self
->session
) return FALSE
;
1026 mypos
= g_list_find(session_saved_state
, self
->session
);
1027 if (!mypos
) return FALSE
;
1029 /* start above me and look for the first client */
1030 for (it
= g_list_previous(mypos
); it
; it
= g_list_previous(it
)) {
1033 for (cit
= client_list
; cit
; cit
= g_list_next(cit
)) {
1034 ObClient
*c
= cit
->data
;
1035 /* found a client that was in the session, so go below it */
1036 if (c
->session
== it
->data
) {
1037 stacking_below(CLIENT_AS_WINDOW(self
),
1038 CLIENT_AS_WINDOW(cit
->data
));
1046 void client_move_onscreen(ObClient
*self
, gboolean rude
)
1048 gint x
= self
->area
.x
;
1049 gint y
= self
->area
.y
;
1050 if (client_find_onscreen(self
, &x
, &y
,
1052 self
->area
.height
, rude
)) {
1053 client_move(self
, x
, y
);
1057 gboolean
client_find_onscreen(ObClient
*self
, gint
*x
, gint
*y
, gint w
, gint h
,
1060 gint ox
= *x
, oy
= *y
;
1061 gboolean rudel
= rude
, ruder
= rude
, rudet
= rude
, rudeb
= rude
;
1067 RECT_SET(desired
, *x
, *y
, w
, h
);
1068 frame_rect_to_frame(self
->frame
, &desired
);
1070 /* get where the frame would be */
1071 frame_client_gravity(self
->frame
, x
, y
);
1073 /* get the requested size of the window with decorations */
1074 fw
= self
->frame
->size
.left
+ w
+ self
->frame
->size
.right
;
1075 fh
= self
->frame
->size
.top
+ h
+ self
->frame
->size
.bottom
;
1077 /* If rudeness wasn't requested, then still be rude in a given direction
1078 if the client is not moving, only resizing in that direction */
1080 Point oldtl
, oldtr
, oldbl
, oldbr
;
1081 Point newtl
, newtr
, newbl
, newbr
;
1082 gboolean stationary_l
, stationary_r
, stationary_t
, stationary_b
;
1084 POINT_SET(oldtl
, self
->frame
->area
.x
, self
->frame
->area
.y
);
1085 POINT_SET(oldbr
, self
->frame
->area
.x
+ self
->frame
->area
.width
- 1,
1086 self
->frame
->area
.y
+ self
->frame
->area
.height
- 1);
1087 POINT_SET(oldtr
, oldbr
.x
, oldtl
.y
);
1088 POINT_SET(oldbl
, oldtl
.x
, oldbr
.y
);
1090 POINT_SET(newtl
, *x
, *y
);
1091 POINT_SET(newbr
, *x
+ fw
- 1, *y
+ fh
- 1);
1092 POINT_SET(newtr
, newbr
.x
, newtl
.y
);
1093 POINT_SET(newbl
, newtl
.x
, newbr
.y
);
1095 /* is it moving or just resizing from some corner? */
1096 stationary_l
= oldtl
.x
== newtl
.x
;
1097 stationary_r
= oldtr
.x
== newtr
.x
;
1098 stationary_t
= oldtl
.y
== newtl
.y
;
1099 stationary_b
= oldbl
.y
== newbl
.y
;
1101 /* if left edge is growing and didnt move right edge */
1102 if (stationary_r
&& newtl
.x
< oldtl
.x
)
1104 /* if right edge is growing and didnt move left edge */
1105 if (stationary_l
&& newtr
.x
> oldtr
.x
)
1107 /* if top edge is growing and didnt move bottom edge */
1108 if (stationary_b
&& newtl
.y
< oldtl
.y
)
1110 /* if bottom edge is growing and didnt move top edge */
1111 if (stationary_t
&& newbl
.y
> oldbl
.y
)
1115 /* we iterate through every monitor that the window is at least partially
1116 on, to make sure it is obeying the rules on them all
1118 if the window does not appear on any monitors, then use the first one
1121 for (i
= 0; i
< screen_num_monitors
; ++i
) {
1124 if (!screen_physical_area_monitor_contains(i
, &desired
)) {
1125 if (i
< screen_num_monitors
- 1 || found_mon
)
1128 /* the window is not inside any monitor! so just use the first
1130 a
= screen_area(self
->desktop
, 0, NULL
);
1133 a
= screen_area(self
->desktop
, SCREEN_AREA_ONE_MONITOR
, &desired
);
1136 /* This makes sure windows aren't entirely outside of the screen so you
1137 can't see them at all.
1138 It makes sure 10% of the window is on the screen at least. And don't
1139 let it move itself off the top of the screen, which would hide the
1140 titlebar on you. (The user can still do this if they want too, it's
1141 only limiting the application.
1143 if (client_normal(self
)) {
1144 if (!self
->strut
.right
&& *x
+ fw
/10 >= a
->x
+ a
->width
- 1)
1145 *x
= a
->x
+ a
->width
- fw
/10;
1146 if (!self
->strut
.bottom
&& *y
+ fh
/10 >= a
->y
+ a
->height
- 1)
1147 *y
= a
->y
+ a
->height
- fh
/10;
1148 if (!self
->strut
.left
&& *x
+ fw
*9/10 - 1 < a
->x
)
1149 *x
= a
->x
- fw
*9/10;
1150 if (!self
->strut
.top
&& *y
+ fh
*9/10 - 1 < a
->y
)
1151 *y
= a
->y
- fh
*9/10;
1154 /* This here doesn't let windows even a pixel outside the
1155 struts/screen. When called from client_manage, programs placing
1156 themselves are forced completely onscreen, while things like
1157 xterm -geometry resolution-width/2 will work fine. Trying to
1158 place it completely offscreen will be handled in the above code.
1159 Sorry for this confused comment, i am tired. */
1160 if (rudel
&& !self
->strut
.left
&& *x
< a
->x
) *x
= a
->x
;
1161 if (ruder
&& !self
->strut
.right
&& *x
+ fw
> a
->x
+ a
->width
)
1162 *x
= a
->x
+ MAX(0, a
->width
- fw
);
1164 if (rudet
&& !self
->strut
.top
&& *y
< a
->y
) *y
= a
->y
;
1165 if (rudeb
&& !self
->strut
.bottom
&& *y
+ fh
> a
->y
+ a
->height
)
1166 *y
= a
->y
+ MAX(0, a
->height
- fh
);
1168 g_slice_free(Rect
, a
);
1171 /* get where the client should be */
1172 frame_frame_gravity(self
->frame
, x
, y
);
1174 return ox
!= *x
|| oy
!= *y
;
1177 static void client_get_all(ObClient
*self
, gboolean real
)
1179 /* this is needed for the frame to set itself up */
1180 client_get_area(self
);
1182 /* these things can change the decor and functions of the window */
1184 client_get_mwm_hints(self
);
1185 /* this can change the mwmhints for special cases */
1186 client_get_type_and_transientness(self
);
1187 client_update_normal_hints(self
);
1189 /* set up the maximum possible decor/functions */
1190 client_setup_default_decor_and_functions(self
);
1192 client_get_state(self
);
1194 /* get the session related properties, these can change decorations
1195 from per-app settings */
1196 client_get_session_ids(self
);
1198 /* now we got everything that can affect the decorations */
1202 /* get this early so we have it for debugging */
1203 client_update_title(self
);
1205 /* save the values of the variables used for app rule matching */
1206 client_save_app_rule_values(self
);
1208 client_update_protocols(self
);
1210 client_update_wmhints(self
);
1211 /* this may have already been called from client_update_wmhints */
1212 if (!self
->parents
&& !self
->transient_for_group
)
1213 client_update_transient_for(self
);
1215 client_get_startup_id(self
);
1216 client_get_desktop(self
);/* uses transient data/group/startup id if a
1217 desktop is not specified */
1218 client_get_shaped(self
);
1221 /* a couple type-based defaults for new windows */
1223 /* this makes sure that these windows appear on all desktops */
1224 if (self
->type
== OB_CLIENT_TYPE_DESKTOP
)
1225 self
->desktop
= DESKTOP_ALL
;
1229 client_update_sync_request_counter(self
);
1232 client_get_colormap(self
);
1233 client_update_strut(self
);
1234 client_update_icons(self
);
1235 client_update_icon_geometry(self
);
1238 static void client_get_startup_id(ObClient
*self
)
1240 if (!(OBT_PROP_GETS_UTF8(self
->window
, NET_STARTUP_ID
, &self
->startup_id
)))
1242 OBT_PROP_GETS_UTF8(self
->group
->leader
, NET_STARTUP_ID
,
1246 static void client_get_area(ObClient
*self
)
1248 XWindowAttributes wattrib
;
1251 ret
= XGetWindowAttributes(obt_display
, self
->window
, &wattrib
);
1252 g_assert(ret
!= BadWindow
);
1254 RECT_SET(self
->area
, wattrib
.x
, wattrib
.y
, wattrib
.width
, wattrib
.height
);
1255 POINT_SET(self
->root_pos
, wattrib
.x
, wattrib
.y
);
1256 self
->border_width
= wattrib
.border_width
;
1258 ob_debug("client area: %d %d %d %d bw %d", wattrib
.x
, wattrib
.y
,
1259 wattrib
.width
, wattrib
.height
, wattrib
.border_width
);
1262 static void client_get_desktop(ObClient
*self
)
1264 guint32 d
= screen_num_desktops
; /* an always-invalid value */
1266 if (OBT_PROP_GET32(self
->window
, NET_WM_DESKTOP
, CARDINAL
, &d
)) {
1267 if (d
>= screen_num_desktops
&& d
!= DESKTOP_ALL
)
1268 self
->desktop
= screen_num_desktops
- 1;
1271 ob_debug("client requested desktop 0x%x", self
->desktop
);
1274 gboolean first
= TRUE
;
1275 guint all
= screen_num_desktops
; /* not a valid value */
1277 /* if they are all on one desktop, then open it on the
1279 for (it
= self
->parents
; it
; it
= g_slist_next(it
)) {
1280 ObClient
*c
= it
->data
;
1282 if (c
->desktop
== DESKTOP_ALL
) continue;
1288 else if (all
!= c
->desktop
)
1289 all
= screen_num_desktops
; /* make it invalid */
1291 if (all
!= screen_num_desktops
) {
1292 self
->desktop
= all
;
1294 ob_debug("client desktop set from parents: 0x%x",
1297 /* try get from the startup-notification protocol */
1298 else if (sn_get_desktop(self
->startup_id
, &self
->desktop
)) {
1299 if (self
->desktop
>= screen_num_desktops
&&
1300 self
->desktop
!= DESKTOP_ALL
)
1301 self
->desktop
= screen_num_desktops
- 1;
1302 ob_debug("client desktop set from startup-notification: 0x%x",
1305 /* defaults to the current desktop */
1307 self
->desktop
= screen_desktop
;
1308 ob_debug("client desktop set to the current desktop: %d",
1314 static void client_get_state(ObClient
*self
)
1319 if (OBT_PROP_GETA32(self
->window
, NET_WM_STATE
, ATOM
, &state
, &num
)) {
1321 for (i
= 0; i
< num
; ++i
) {
1322 if (state
[i
] == OBT_PROP_ATOM(NET_WM_STATE_MODAL
))
1324 else if (state
[i
] == OBT_PROP_ATOM(NET_WM_STATE_SHADED
))
1325 self
->shaded
= TRUE
;
1326 else if (state
[i
] == OBT_PROP_ATOM(NET_WM_STATE_HIDDEN
))
1327 self
->iconic
= TRUE
;
1328 else if (state
[i
] == OBT_PROP_ATOM(NET_WM_STATE_SKIP_TASKBAR
))
1329 self
->skip_taskbar
= TRUE
;
1330 else if (state
[i
] == OBT_PROP_ATOM(NET_WM_STATE_SKIP_PAGER
))
1331 self
->skip_pager
= TRUE
;
1332 else if (state
[i
] == OBT_PROP_ATOM(NET_WM_STATE_FULLSCREEN
))
1333 self
->fullscreen
= TRUE
;
1334 else if (state
[i
] == OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_VERT
))
1335 self
->max_vert
= TRUE
;
1336 else if (state
[i
] == OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_HORZ
))
1337 self
->max_horz
= TRUE
;
1338 else if (state
[i
] == OBT_PROP_ATOM(NET_WM_STATE_ABOVE
))
1340 else if (state
[i
] == OBT_PROP_ATOM(NET_WM_STATE_BELOW
))
1342 else if (state
[i
] == OBT_PROP_ATOM(NET_WM_STATE_DEMANDS_ATTENTION
))
1343 self
->demands_attention
= TRUE
;
1344 else if (state
[i
] == OBT_PROP_ATOM(OB_WM_STATE_UNDECORATED
))
1345 self
->undecorated
= TRUE
;
1352 static void client_get_shaped(ObClient
*self
)
1354 self
->shaped
= FALSE
;
1356 if (obt_display_extension_shape
) {
1361 XShapeSelectInput(obt_display
, self
->window
, ShapeNotifyMask
);
1363 XShapeQueryExtents(obt_display
, self
->window
, &s
, &foo
,
1364 &foo
, &ufoo
, &ufoo
, &foo
, &foo
, &foo
, &ufoo
,
1371 void client_update_transient_for(ObClient
*self
)
1374 ObClient
*target
= NULL
;
1375 gboolean trangroup
= FALSE
;
1377 if (XGetTransientForHint(obt_display
, self
->window
, &t
)) {
1378 if (t
!= self
->window
) { /* can't be transient to itself! */
1379 ObWindow
*tw
= window_find(t
);
1380 /* if this happens then we need to check for it */
1381 g_assert(tw
!= CLIENT_AS_WINDOW(self
));
1382 if (tw
&& WINDOW_IS_CLIENT(tw
)) {
1383 /* watch out for windows with a parent that is something
1384 different, like a dockapp for example */
1385 target
= WINDOW_AS_CLIENT(tw
);
1389 /* Setting the transient_for to Root is actually illegal, however
1390 applications from time have done this to specify transient for
1392 if (!target
&& self
->group
&& t
== obt_root(ob_screen
))
1394 } else if (self
->group
&& self
->transient
)
1397 client_update_transient_tree(self
, self
->group
, self
->group
,
1398 self
->transient_for_group
, trangroup
,
1399 client_direct_parent(self
), target
);
1400 self
->transient_for_group
= trangroup
;
1404 static void client_update_transient_tree(ObClient
*self
,
1405 ObGroup
*oldgroup
, ObGroup
*newgroup
,
1406 gboolean oldgtran
, gboolean newgtran
,
1407 ObClient
* oldparent
,
1408 ObClient
*newparent
)
1413 g_assert(!oldgtran
|| oldgroup
);
1414 g_assert(!newgtran
|| newgroup
);
1415 g_assert((!oldgtran
&& !oldparent
) ||
1416 (oldgtran
&& !oldparent
) ||
1417 (!oldgtran
&& oldparent
));
1418 g_assert((!newgtran
&& !newparent
) ||
1419 (newgtran
&& !newparent
) ||
1420 (!newgtran
&& newparent
));
1423 Group transient windows are not allowed to have other group
1424 transient windows as their children.
1427 /* No change has occured */
1428 if (oldgroup
== newgroup
&&
1429 oldgtran
== newgtran
&&
1430 oldparent
== newparent
) return;
1432 /** Remove the client from the transient tree **/
1434 for (it
= self
->transients
; it
; it
= next
) {
1435 next
= g_slist_next(it
);
1437 self
->transients
= g_slist_delete_link(self
->transients
, it
);
1438 c
->parents
= g_slist_remove(c
->parents
, self
);
1440 for (it
= self
->parents
; it
; it
= next
) {
1441 next
= g_slist_next(it
);
1443 self
->parents
= g_slist_delete_link(self
->parents
, it
);
1444 c
->transients
= g_slist_remove(c
->transients
, self
);
1447 /** Re-add the client to the transient tree **/
1449 /* If we're transient for a group then we need to add ourselves to all our
1452 for (it
= newgroup
->members
; it
; it
= g_slist_next(it
)) {
1455 !client_search_top_direct_parent(c
)->transient_for_group
&&
1458 c
->transients
= g_slist_prepend(c
->transients
, self
);
1459 self
->parents
= g_slist_prepend(self
->parents
, c
);
1464 /* If we are now transient for a single window we need to add ourselves to
1467 WARNING: Cyclical transient-ness is possible if two windows are
1468 transient for eachother.
1470 else if (newparent
&&
1471 /* don't make ourself its child if it is already our child */
1472 !client_is_direct_child(self
, newparent
) &&
1473 client_normal(newparent
))
1475 newparent
->transients
= g_slist_prepend(newparent
->transients
, self
);
1476 self
->parents
= g_slist_prepend(self
->parents
, newparent
);
1479 /* Add any group transient windows to our children. But if we're transient
1480 for the group, then other group transients are not our children.
1482 WARNING: Cyclical transient-ness is possible. For e.g. if:
1483 A is transient for the group
1484 B is transient for A
1485 C is transient for B
1486 A can't be transient for C or we have a cycle
1488 if (!newgtran
&& newgroup
&&
1490 !client_search_top_direct_parent(newparent
)->transient_for_group
) &&
1491 client_normal(self
))
1493 for (it
= newgroup
->members
; it
; it
= g_slist_next(it
)) {
1495 if (c
!= self
&& c
->transient_for_group
&&
1496 /* Don't make it our child if it is already our parent */
1497 !client_is_direct_child(c
, self
))
1499 self
->transients
= g_slist_prepend(self
->transients
, c
);
1500 c
->parents
= g_slist_prepend(c
->parents
, self
);
1505 /** If we change our group transient-ness, our children change their
1506 effective group transient-ness, which affects how they relate to other
1509 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
1511 if (!c
->transient_for_group
)
1512 client_update_transient_tree(c
, c
->group
, c
->group
,
1513 c
->transient_for_group
,
1514 c
->transient_for_group
,
1515 client_direct_parent(c
),
1516 client_direct_parent(c
));
1520 void client_get_mwm_hints(ObClient
*self
)
1525 self
->mwmhints
.flags
= 0; /* default to none */
1527 if (OBT_PROP_GETA32(self
->window
, MOTIF_WM_HINTS
, MOTIF_WM_HINTS
,
1529 if (num
>= OB_MWM_ELEMENTS
) {
1530 self
->mwmhints
.flags
= hints
[0];
1531 self
->mwmhints
.functions
= hints
[1];
1532 self
->mwmhints
.decorations
= hints
[2];
1538 void client_get_type_and_transientness(ObClient
*self
)
1545 self
->transient
= FALSE
;
1547 if (OBT_PROP_GETA32(self
->window
, NET_WM_WINDOW_TYPE
, ATOM
, &val
, &num
)) {
1548 /* use the first value that we know about in the array */
1549 for (i
= 0; i
< num
; ++i
) {
1550 if (val
[i
] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_DESKTOP
))
1551 self
->type
= OB_CLIENT_TYPE_DESKTOP
;
1552 else if (val
[i
] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_DOCK
))
1553 self
->type
= OB_CLIENT_TYPE_DOCK
;
1554 else if (val
[i
] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_TOOLBAR
))
1555 self
->type
= OB_CLIENT_TYPE_TOOLBAR
;
1556 else if (val
[i
] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_MENU
))
1557 self
->type
= OB_CLIENT_TYPE_MENU
;
1558 else if (val
[i
] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_UTILITY
))
1559 self
->type
= OB_CLIENT_TYPE_UTILITY
;
1560 else if (val
[i
] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_SPLASH
))
1561 self
->type
= OB_CLIENT_TYPE_SPLASH
;
1562 else if (val
[i
] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_DIALOG
))
1563 self
->type
= OB_CLIENT_TYPE_DIALOG
;
1564 else if (val
[i
] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_NORMAL
))
1565 self
->type
= OB_CLIENT_TYPE_NORMAL
;
1566 else if (val
[i
] == OBT_PROP_ATOM(KDE_NET_WM_WINDOW_TYPE_OVERRIDE
))
1568 /* prevent this window from getting any decor or
1570 self
->mwmhints
.flags
&= (OB_MWM_FLAG_FUNCTIONS
|
1571 OB_MWM_FLAG_DECORATIONS
);
1572 self
->mwmhints
.decorations
= 0;
1573 self
->mwmhints
.functions
= 0;
1575 if (self
->type
!= (ObClientType
) -1)
1576 break; /* grab the first legit type */
1581 if (XGetTransientForHint(obt_display
, self
->window
, &t
))
1582 self
->transient
= TRUE
;
1584 if (self
->type
== (ObClientType
) -1) {
1585 /*the window type hint was not set, which means we either classify
1586 ourself as a normal window or a dialog, depending on if we are a
1588 if (self
->transient
)
1589 self
->type
= OB_CLIENT_TYPE_DIALOG
;
1591 self
->type
= OB_CLIENT_TYPE_NORMAL
;
1594 /* then, based on our type, we can update our transientness.. */
1595 if (self
->type
== OB_CLIENT_TYPE_DIALOG
||
1596 self
->type
== OB_CLIENT_TYPE_TOOLBAR
||
1597 self
->type
== OB_CLIENT_TYPE_MENU
||
1598 self
->type
== OB_CLIENT_TYPE_UTILITY
)
1600 self
->transient
= TRUE
;
1604 void client_update_protocols(ObClient
*self
)
1609 self
->focus_notify
= FALSE
;
1610 self
->delete_window
= FALSE
;
1612 if (OBT_PROP_GETA32(self
->window
, WM_PROTOCOLS
, ATOM
, &proto
, &num_ret
)) {
1613 for (i
= 0; i
< num_ret
; ++i
) {
1614 if (proto
[i
] == OBT_PROP_ATOM(WM_DELETE_WINDOW
))
1615 /* this means we can request the window to close */
1616 self
->delete_window
= TRUE
;
1617 else if (proto
[i
] == OBT_PROP_ATOM(WM_TAKE_FOCUS
))
1618 /* if this protocol is requested, then the window will be
1619 notified whenever we want it to receive focus */
1620 self
->focus_notify
= TRUE
;
1621 else if (proto
[i
] == OBT_PROP_ATOM(NET_WM_PING
))
1622 /* if this protocol is requested, then the window will allow
1623 pings to determine if it is still alive */
1626 else if (proto
[i
] == OBT_PROP_ATOM(NET_WM_SYNC_REQUEST
))
1627 /* if this protocol is requested, then resizing the
1628 window will be synchronized between the frame and the
1630 self
->sync_request
= TRUE
;
1638 void client_update_sync_request_counter(ObClient
*self
)
1642 if (OBT_PROP_GET32(self
->window
, NET_WM_SYNC_REQUEST_COUNTER
, CARDINAL
,&i
))
1646 self
->sync_counter
= i
;
1648 /* this must be set when managing a new window according to EWMH */
1649 XSyncIntToValue(&val
, 0);
1650 XSyncSetCounter(obt_display
, self
->sync_counter
, val
);
1652 self
->sync_counter
= None
;
1656 static void client_get_colormap(ObClient
*self
)
1658 XWindowAttributes wa
;
1660 if (XGetWindowAttributes(obt_display
, self
->window
, &wa
))
1661 client_update_colormap(self
, wa
.colormap
);
1664 void client_update_colormap(ObClient
*self
, Colormap colormap
)
1666 if (colormap
== self
->colormap
) return;
1668 ob_debug("Setting client %s colormap: 0x%x", self
->title
, colormap
);
1670 if (client_focused(self
)) {
1671 screen_install_colormap(self
, FALSE
); /* uninstall old one */
1672 self
->colormap
= colormap
;
1673 screen_install_colormap(self
, TRUE
); /* install new one */
1675 self
->colormap
= colormap
;
1678 void client_update_opacity(ObClient
*self
)
1682 if (OBT_PROP_GET32(self
->window
, NET_WM_WINDOW_OPACITY
, CARDINAL
, &o
))
1683 OBT_PROP_SET32(self
->frame
->window
, NET_WM_WINDOW_OPACITY
, CARDINAL
, o
);
1685 OBT_PROP_ERASE(self
->frame
->window
, NET_WM_WINDOW_OPACITY
);
1688 void client_update_normal_hints(ObClient
*self
)
1694 self
->min_ratio
= 0.0f
;
1695 self
->max_ratio
= 0.0f
;
1696 SIZE_SET(self
->size_inc
, 1, 1);
1697 SIZE_SET(self
->base_size
, -1, -1);
1698 SIZE_SET(self
->min_size
, 0, 0);
1699 SIZE_SET(self
->max_size
, G_MAXINT
, G_MAXINT
);
1701 /* get the hints from the window */
1702 if (XGetWMNormalHints(obt_display
, self
->window
, &size
, &ret
)) {
1703 /* normal windows can't request placement! har har
1704 if (!client_normal(self))
1706 self
->positioned
= (size
.flags
& (PPosition
|USPosition
));
1707 self
->sized
= (size
.flags
& (PSize
|USSize
));
1709 if (size
.flags
& PWinGravity
)
1710 self
->gravity
= size
.win_gravity
;
1712 if (size
.flags
& PAspect
) {
1713 if (size
.min_aspect
.y
)
1715 (gfloat
) size
.min_aspect
.x
/ size
.min_aspect
.y
;
1716 if (size
.max_aspect
.y
)
1718 (gfloat
) size
.max_aspect
.x
/ size
.max_aspect
.y
;
1721 if (size
.flags
& PMinSize
)
1722 SIZE_SET(self
->min_size
, size
.min_width
, size
.min_height
);
1724 if (size
.flags
& PMaxSize
)
1725 SIZE_SET(self
->max_size
, size
.max_width
, size
.max_height
);
1727 if (size
.flags
& PBaseSize
)
1728 SIZE_SET(self
->base_size
, size
.base_width
, size
.base_height
);
1730 if (size
.flags
& PResizeInc
&& size
.width_inc
&& size
.height_inc
)
1731 SIZE_SET(self
->size_inc
, size
.width_inc
, size
.height_inc
);
1733 ob_debug("Normal hints: min size (%d %d) max size (%d %d)",
1734 self
->min_size
.width
, self
->min_size
.height
,
1735 self
->max_size
.width
, self
->max_size
.height
);
1736 ob_debug("size inc (%d %d) base size (%d %d)",
1737 self
->size_inc
.width
, self
->size_inc
.height
,
1738 self
->base_size
.width
, self
->base_size
.height
);
1741 ob_debug("Normal hints: not set");
1744 static void client_setup_default_decor_and_functions(ObClient
*self
)
1746 /* start with everything (cept fullscreen) */
1748 (OB_FRAME_DECOR_TITLEBAR
|
1749 OB_FRAME_DECOR_HANDLE
|
1750 OB_FRAME_DECOR_GRIPS
|
1751 OB_FRAME_DECOR_BORDER
|
1752 OB_FRAME_DECOR_ICON
|
1753 OB_FRAME_DECOR_ALLDESKTOPS
|
1754 OB_FRAME_DECOR_ICONIFY
|
1755 OB_FRAME_DECOR_MAXIMIZE
|
1756 OB_FRAME_DECOR_SHADE
|
1757 OB_FRAME_DECOR_CLOSE
);
1759 (OB_CLIENT_FUNC_RESIZE
|
1760 OB_CLIENT_FUNC_MOVE
|
1761 OB_CLIENT_FUNC_ICONIFY
|
1762 OB_CLIENT_FUNC_MAXIMIZE
|
1763 OB_CLIENT_FUNC_SHADE
|
1764 OB_CLIENT_FUNC_CLOSE
|
1765 OB_CLIENT_FUNC_BELOW
|
1766 OB_CLIENT_FUNC_ABOVE
|
1767 OB_CLIENT_FUNC_UNDECORATE
);
1769 if (!(self
->min_size
.width
< self
->max_size
.width
||
1770 self
->min_size
.height
< self
->max_size
.height
))
1771 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
1773 switch (self
->type
) {
1774 case OB_CLIENT_TYPE_NORMAL
:
1775 /* normal windows retain all of the possible decorations and
1776 functionality, and can be fullscreen */
1777 self
->functions
|= OB_CLIENT_FUNC_FULLSCREEN
;
1780 case OB_CLIENT_TYPE_DIALOG
:
1781 /* sometimes apps make dialog windows fullscreen for some reason (for
1782 e.g. kpdf does this..) */
1783 self
->functions
|= OB_CLIENT_FUNC_FULLSCREEN
;
1786 case OB_CLIENT_TYPE_UTILITY
:
1787 /* these windows don't have anything added or removed by default */
1790 case OB_CLIENT_TYPE_MENU
:
1791 case OB_CLIENT_TYPE_TOOLBAR
:
1792 /* these windows can't iconify or maximize */
1793 self
->decorations
&= ~(OB_FRAME_DECOR_ICONIFY
|
1794 OB_FRAME_DECOR_MAXIMIZE
);
1795 self
->functions
&= ~(OB_CLIENT_FUNC_ICONIFY
|
1796 OB_CLIENT_FUNC_MAXIMIZE
);
1799 case OB_CLIENT_TYPE_SPLASH
:
1800 /* these don't get get any decorations, and the only thing you can
1801 do with them is move them */
1802 self
->decorations
= 0;
1803 self
->functions
= OB_CLIENT_FUNC_MOVE
;
1806 case OB_CLIENT_TYPE_DESKTOP
:
1807 /* these windows are not manipulated by the window manager */
1808 self
->decorations
= 0;
1809 self
->functions
= 0;
1812 case OB_CLIENT_TYPE_DOCK
:
1813 /* these windows are not manipulated by the window manager, but they
1814 can set below layer which has a special meaning */
1815 self
->decorations
= 0;
1816 self
->functions
= OB_CLIENT_FUNC_BELOW
;
1820 /* If the client has no decor from its type (which never changes) then
1821 don't allow the user to "undecorate" the window. Otherwise, allow them
1822 to, even if there are motif hints removing the decor, because those
1823 may change these days (e.g. chromium) */
1824 if (self
->decorations
== 0)
1825 self
->functions
&= ~OB_CLIENT_FUNC_UNDECORATE
;
1827 /* Mwm Hints are applied subtractively to what has already been chosen for
1828 decor and functionality */
1829 if (self
->mwmhints
.flags
& OB_MWM_FLAG_DECORATIONS
) {
1830 if (! (self
->mwmhints
.decorations
& OB_MWM_DECOR_ALL
)) {
1831 if (! ((self
->mwmhints
.decorations
& OB_MWM_DECOR_HANDLE
) ||
1832 (self
->mwmhints
.decorations
& OB_MWM_DECOR_TITLE
)))
1834 /* if the mwm hints request no handle or title, then all
1835 decorations are disabled, but keep the border if that's
1837 if (self
->mwmhints
.decorations
& OB_MWM_DECOR_BORDER
)
1838 self
->decorations
= OB_FRAME_DECOR_BORDER
;
1840 self
->decorations
= 0;
1845 if (self
->mwmhints
.flags
& OB_MWM_FLAG_FUNCTIONS
) {
1846 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_ALL
)) {
1847 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_RESIZE
))
1848 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
1849 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_MOVE
))
1850 self
->functions
&= ~OB_CLIENT_FUNC_MOVE
;
1851 /* dont let mwm hints kill any buttons
1852 if (! (self->mwmhints.functions & OB_MWM_FUNC_ICONIFY))
1853 self->functions &= ~OB_CLIENT_FUNC_ICONIFY;
1854 if (! (self->mwmhints.functions & OB_MWM_FUNC_MAXIMIZE))
1855 self->functions &= ~OB_CLIENT_FUNC_MAXIMIZE;
1857 /* dont let mwm hints kill the close button
1858 if (! (self->mwmhints.functions & MwmFunc_Close))
1859 self->functions &= ~OB_CLIENT_FUNC_CLOSE; */
1863 if (!(self
->functions
& OB_CLIENT_FUNC_SHADE
))
1864 self
->decorations
&= ~OB_FRAME_DECOR_SHADE
;
1865 if (!(self
->functions
& OB_CLIENT_FUNC_ICONIFY
))
1866 self
->decorations
&= ~OB_FRAME_DECOR_ICONIFY
;
1867 if (!(self
->functions
& OB_CLIENT_FUNC_RESIZE
))
1868 self
->decorations
&= ~(OB_FRAME_DECOR_GRIPS
| OB_FRAME_DECOR_HANDLE
);
1870 /* can't maximize without moving/resizing */
1871 if (!((self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) &&
1872 (self
->functions
& OB_CLIENT_FUNC_MOVE
) &&
1873 (self
->functions
& OB_CLIENT_FUNC_RESIZE
))) {
1874 self
->functions
&= ~OB_CLIENT_FUNC_MAXIMIZE
;
1875 self
->decorations
&= ~OB_FRAME_DECOR_MAXIMIZE
;
1879 /*! Set up decor for a client based on its undecorated state. */
1880 static void client_setup_decor_undecorated(ObClient
*self
)
1882 /* If the user requested no decorations, then remove all the decorations,
1883 except the border. But don't add a border if there wasn't one. */
1884 if (self
->undecorated
)
1885 self
->decorations
&= (config_theme_keepborder
?
1886 OB_FRAME_DECOR_BORDER
: 0);
1889 void client_setup_decor_and_functions(ObClient
*self
, gboolean reconfig
)
1891 client_setup_default_decor_and_functions(self
);
1893 client_setup_decor_undecorated(self
);
1895 if (self
->max_horz
&& self
->max_vert
) {
1896 /* once upon a time you couldn't resize maximized windows, that is not
1897 the case any more though !
1899 but do kill the handle on fully maxed windows */
1900 self
->decorations
&= ~(OB_FRAME_DECOR_HANDLE
| OB_FRAME_DECOR_GRIPS
);
1903 /* if we don't have a titlebar, then we cannot shade! */
1904 if (!(self
->decorations
& OB_FRAME_DECOR_TITLEBAR
))
1905 self
->functions
&= ~OB_CLIENT_FUNC_SHADE
;
1907 /* now we need to check against rules for the client's current state */
1908 if (self
->fullscreen
) {
1909 self
->functions
&= (OB_CLIENT_FUNC_CLOSE
|
1910 OB_CLIENT_FUNC_FULLSCREEN
|
1911 OB_CLIENT_FUNC_ICONIFY
);
1912 self
->decorations
= 0;
1915 client_change_allowed_actions(self
);
1918 /* reconfigure to make sure decorations are updated */
1919 client_reconfigure(self
, FALSE
);
1922 static void client_change_allowed_actions(ObClient
*self
)
1927 /* desktop windows are kept on all desktops */
1928 if (self
->type
!= OB_CLIENT_TYPE_DESKTOP
)
1929 actions
[num
++] = OBT_PROP_ATOM(NET_WM_ACTION_CHANGE_DESKTOP
);
1931 if (self
->functions
& OB_CLIENT_FUNC_SHADE
)
1932 actions
[num
++] = OBT_PROP_ATOM(NET_WM_ACTION_SHADE
);
1933 if (self
->functions
& OB_CLIENT_FUNC_CLOSE
)
1934 actions
[num
++] = OBT_PROP_ATOM(NET_WM_ACTION_CLOSE
);
1935 if (self
->functions
& OB_CLIENT_FUNC_MOVE
)
1936 actions
[num
++] = OBT_PROP_ATOM(NET_WM_ACTION_MOVE
);
1937 if (self
->functions
& OB_CLIENT_FUNC_ICONIFY
)
1938 actions
[num
++] = OBT_PROP_ATOM(NET_WM_ACTION_MINIMIZE
);
1939 if (self
->functions
& OB_CLIENT_FUNC_RESIZE
)
1940 actions
[num
++] = OBT_PROP_ATOM(NET_WM_ACTION_RESIZE
);
1941 if (self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
)
1942 actions
[num
++] = OBT_PROP_ATOM(NET_WM_ACTION_FULLSCREEN
);
1943 if (self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) {
1944 actions
[num
++] = OBT_PROP_ATOM(NET_WM_ACTION_MAXIMIZE_HORZ
);
1945 actions
[num
++] = OBT_PROP_ATOM(NET_WM_ACTION_MAXIMIZE_VERT
);
1947 if (self
->functions
& OB_CLIENT_FUNC_ABOVE
)
1948 actions
[num
++] = OBT_PROP_ATOM(NET_WM_ACTION_ABOVE
);
1949 if (self
->functions
& OB_CLIENT_FUNC_BELOW
)
1950 actions
[num
++] = OBT_PROP_ATOM(NET_WM_ACTION_BELOW
);
1951 if (self
->functions
& OB_CLIENT_FUNC_UNDECORATE
)
1952 actions
[num
++] = OBT_PROP_ATOM(OB_WM_ACTION_UNDECORATE
);
1954 OBT_PROP_SETA32(self
->window
, NET_WM_ALLOWED_ACTIONS
, ATOM
, actions
, num
);
1956 /* make sure the window isn't breaking any rules now
1958 don't check ICONIFY here. just cuz a window can't iconify doesnt mean
1959 it can't be iconified with its parent
1962 if (!(self
->functions
& OB_CLIENT_FUNC_SHADE
) && self
->shaded
) {
1963 if (self
->frame
) client_shade(self
, FALSE
);
1964 else self
->shaded
= FALSE
;
1966 if (!(self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
) && self
->fullscreen
) {
1967 if (self
->frame
) client_fullscreen(self
, FALSE
);
1968 else self
->fullscreen
= FALSE
;
1970 if (!(self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) && (self
->max_horz
||
1972 if (self
->frame
) client_maximize(self
, FALSE
, 0);
1973 else self
->max_vert
= self
->max_horz
= FALSE
;
1977 void client_update_wmhints(ObClient
*self
)
1981 /* assume a window takes input if it doesn't specify */
1982 self
->can_focus
= TRUE
;
1984 if ((hints
= XGetWMHints(obt_display
, self
->window
)) != NULL
) {
1987 if (hints
->flags
& InputHint
)
1988 self
->can_focus
= hints
->input
;
1990 /* only do this when first managing the window *AND* when we aren't
1992 if (ob_state() != OB_STATE_STARTING
&& self
->frame
== NULL
)
1993 if (hints
->flags
& StateHint
)
1994 self
->iconic
= hints
->initial_state
== IconicState
;
1997 self
->urgent
= (hints
->flags
& XUrgencyHint
);
1998 if (self
->urgent
&& !ur
)
1999 client_hilite(self
, TRUE
);
2000 else if (!self
->urgent
&& ur
&& self
->demands_attention
)
2001 client_hilite(self
, FALSE
);
2003 if (!(hints
->flags
& WindowGroupHint
))
2004 hints
->window_group
= None
;
2006 /* did the group state change? */
2007 if (hints
->window_group
!=
2008 (self
->group
? self
->group
->leader
: None
))
2010 ObGroup
*oldgroup
= self
->group
;
2012 /* remove from the old group if there was one */
2014 group_remove(self
->group
, self
);
2018 /* add ourself to the group if we have one */
2019 if (hints
->window_group
!= None
) {
2020 self
->group
= group_add(hints
->window_group
, self
);
2023 /* Put ourselves into the new group's transient tree, and remove
2024 ourselves from the old group's */
2025 client_update_transient_tree(self
, oldgroup
, self
->group
,
2026 self
->transient_for_group
,
2027 self
->transient_for_group
,
2028 client_direct_parent(self
),
2029 client_direct_parent(self
));
2031 /* Lastly, being in a group, or not, can change if the window is
2032 transient for anything.
2034 The logic for this is:
2035 self->transient = TRUE always if the window wants to be
2036 transient for something, even if transient_for was NULL because
2037 it wasn't in a group before.
2039 If parents was NULL and oldgroup was NULL we can assume
2040 that when we add the new group, it will become transient for
2043 If transient_for_group is TRUE, then it must have already
2044 had a group. If it is getting a new group, the above call to
2045 client_update_transient_tree has already taken care of
2046 everything ! If it is losing all group status then it will
2047 no longer be transient for anything and that needs to be
2050 if (self
->transient
&&
2051 ((self
->parents
== NULL
&& oldgroup
== NULL
) ||
2052 (self
->transient_for_group
&& !self
->group
)))
2053 client_update_transient_for(self
);
2056 /* the WM_HINTS can contain an icon */
2057 if (hints
->flags
& IconPixmapHint
)
2058 client_update_icons(self
);
2063 focus_cycle_addremove(self
, TRUE
);
2066 void client_update_title(ObClient
*self
)
2069 gchar
*visible
= NULL
;
2071 g_free(self
->title
);
2072 g_free(self
->original_title
);
2075 if (!OBT_PROP_GETS_UTF8(self
->window
, NET_WM_NAME
, &data
)) {
2076 /* try old x stuff */
2077 if (!OBT_PROP_GETS(self
->window
, WM_NAME
, &data
)) {
2078 if (self
->transient
) {
2080 GNOME alert windows are not given titles:
2081 http://developer.gnome.org/projects/gup/hig/draft_hig_new/windows-alert.html
2083 data
= g_strdup("");
2085 data
= g_strdup(_("Unnamed Window"));
2088 self
->original_title
= g_strdup(data
);
2090 if (self
->client_machine
) {
2091 visible
= g_strdup_printf("%s (%s)", data
, self
->client_machine
);
2096 if (self
->not_responding
) {
2098 if (self
->kill_level
> 0)
2099 visible
= g_strdup_printf("%s - [%s]", data
, _("Killing..."));
2101 visible
= g_strdup_printf("%s - [%s]", data
, _("Not Responding"));
2105 OBT_PROP_SETS(self
->window
, NET_WM_VISIBLE_NAME
, visible
);
2106 self
->title
= visible
;
2109 frame_adjust_title(self
->frame
);
2111 /* update the icon title */
2113 g_free(self
->icon_title
);
2116 if (!OBT_PROP_GETS_UTF8(self
->window
, NET_WM_ICON_NAME
, &data
))
2117 /* try old x stuff */
2118 if (!OBT_PROP_GETS(self
->window
, WM_ICON_NAME
, &data
))
2119 data
= g_strdup(self
->title
);
2121 if (self
->client_machine
) {
2122 visible
= g_strdup_printf("%s (%s)", data
, self
->client_machine
);
2127 if (self
->not_responding
) {
2129 if (self
->kill_level
> 0)
2130 visible
= g_strdup_printf("%s - [%s]", data
, _("Killing..."));
2132 visible
= g_strdup_printf("%s - [%s]", data
, _("Not Responding"));
2136 OBT_PROP_SETS(self
->window
, NET_WM_VISIBLE_ICON_NAME
, visible
);
2137 self
->icon_title
= visible
;
2140 void client_update_strut(ObClient
*self
)
2144 gboolean got
= FALSE
;
2147 if (OBT_PROP_GETA32(self
->window
, NET_WM_STRUT_PARTIAL
, CARDINAL
,
2152 STRUT_PARTIAL_SET(strut
,
2153 data
[0], data
[2], data
[1], data
[3],
2154 data
[4], data
[5], data
[8], data
[9],
2155 data
[6], data
[7], data
[10], data
[11]);
2161 OBT_PROP_GETA32(self
->window
, NET_WM_STRUT
, CARDINAL
, &data
, &num
)) {
2167 /* use the screen's width/height */
2168 a
= screen_physical_area_all_monitors();
2170 STRUT_PARTIAL_SET(strut
,
2171 data
[0], data
[2], data
[1], data
[3],
2172 a
->y
, a
->y
+ a
->height
- 1,
2173 a
->x
, a
->x
+ a
->width
- 1,
2174 a
->y
, a
->y
+ a
->height
- 1,
2175 a
->x
, a
->x
+ a
->width
- 1);
2181 STRUT_PARTIAL_SET(strut
, 0, 0, 0, 0,
2182 0, 0, 0, 0, 0, 0, 0, 0);
2184 if (!PARTIAL_STRUT_EQUAL(strut
, self
->strut
)) {
2185 self
->strut
= strut
;
2187 /* updating here is pointless while we're being mapped cuz we're not in
2188 the client list yet */
2190 screen_update_areas();
2194 void client_update_icons(ObClient
*self
)
2203 /* grab the server, because we might be setting the window's icon and
2204 we don't want them to set it in between and we overwrite their own
2208 if (OBT_PROP_GETA32(self
->window
, NET_WM_ICON
, CARDINAL
, &data
, &num
)) {
2209 /* figure out how many valid icons are in here */
2211 while (i
+ 2 < num
) { /* +2 is to make sure there is a w and h */
2214 /* watch for the data being too small for the specified size,
2215 or for zero sized icons. */
2216 if (i
+ w
*h
> num
|| w
== 0 || h
== 0) {
2221 /* convert it to the right bit order for ObRender */
2222 for (j
= 0; j
< w
*h
; ++j
)
2224 (((data
[i
+j
] >> 24) & 0xff) << RrDefaultAlphaOffset
) +
2225 (((data
[i
+j
] >> 16) & 0xff) << RrDefaultRedOffset
) +
2226 (((data
[i
+j
] >> 8) & 0xff) << RrDefaultGreenOffset
) +
2227 (((data
[i
+j
] >> 0) & 0xff) << RrDefaultBlueOffset
);
2229 /* add it to the image cache as an original */
2231 img
= RrImageNewFromData(ob_rr_icons
, &data
[i
], w
, h
);
2233 RrImageAddFromData(img
, &data
[i
], w
, h
);
2241 /* if we didn't find an image from the NET_WM_ICON stuff, then try the
2246 if ((hints
= XGetWMHints(obt_display
, self
->window
))) {
2247 if (hints
->flags
& IconPixmapHint
) {
2249 obt_display_ignore_errors(TRUE
);
2250 xicon
= RrPixmapToRGBA(ob_rr_inst
,
2252 (hints
->flags
& IconMaskHint
?
2253 hints
->icon_mask
: None
),
2254 (gint
*)&w
, (gint
*)&h
, &data
);
2255 obt_display_ignore_errors(FALSE
);
2258 if (w
> 0 && h
> 0) {
2260 img
= RrImageNewFromData(ob_rr_icons
, data
, w
, h
);
2262 RrImageAddFromData(img
, data
, w
, h
);
2272 /* set the client's icons to be whatever we found */
2273 RrImageUnref(self
->icon_set
);
2274 self
->icon_set
= img
;
2276 /* if the client has no icon at all, then we set a default icon onto it.
2277 but, if it has parents, then one of them will have an icon already
2279 if (!self
->icon_set
&& !self
->parents
) {
2280 RrPixel32
*icon
= ob_rr_theme
->def_win_icon
;
2281 gulong
*ldata
; /* use a long here to satisfy OBT_PROP_SETA32 */
2283 w
= ob_rr_theme
->def_win_icon_w
;
2284 h
= ob_rr_theme
->def_win_icon_h
;
2285 ldata
= g_new(gulong
, w
*h
+2);
2288 for (i
= 0; i
< w
*h
; ++i
)
2289 ldata
[i
+2] = (((icon
[i
] >> RrDefaultAlphaOffset
) & 0xff) << 24) +
2290 (((icon
[i
] >> RrDefaultRedOffset
) & 0xff) << 16) +
2291 (((icon
[i
] >> RrDefaultGreenOffset
) & 0xff) << 8) +
2292 (((icon
[i
] >> RrDefaultBlueOffset
) & 0xff) << 0);
2293 OBT_PROP_SETA32(self
->window
, NET_WM_ICON
, CARDINAL
, ldata
, w
*h
+2);
2295 } else if (self
->frame
)
2296 /* don't draw the icon empty if we're just setting one now anyways,
2297 we'll get the property change any second */
2298 frame_adjust_icon(self
->frame
);
2303 void client_update_icon_geometry(ObClient
*self
)
2308 RECT_SET(self
->icon_geometry
, 0, 0, 0, 0);
2310 if (OBT_PROP_GETA32(self
->window
, NET_WM_ICON_GEOMETRY
, CARDINAL
,
2314 /* don't let them set it with an area < 0 */
2315 RECT_SET(self
->icon_geometry
, data
[0], data
[1],
2316 MAX(data
[2],0), MAX(data
[3],0));
2321 static void client_get_session_ids(ObClient
*self
)
2328 if (!OBT_PROP_GET32(self
->window
, WM_CLIENT_LEADER
, WINDOW
, &leader
))
2331 /* get the SM_CLIENT_ID */
2332 if (leader
&& leader
!= self
->window
)
2333 OBT_PROP_GETS_XPCS(leader
, SM_CLIENT_ID
, &self
->sm_client_id
);
2335 OBT_PROP_GETS_XPCS(self
->window
, SM_CLIENT_ID
, &self
->sm_client_id
);
2337 /* get the WM_CLASS (name and class). make them "" if they are not
2339 got
= OBT_PROP_GETSS_TYPE(self
->window
, WM_CLASS
, STRING_NO_CC
, &ss
);
2343 self
->name
= g_strdup(ss
[0]);
2345 self
->class = g_strdup(ss
[1]);
2350 if (self
->name
== NULL
) self
->name
= g_strdup("");
2351 if (self
->class == NULL
) self
->class = g_strdup("");
2353 /* get the WM_WINDOW_ROLE. make it "" if it is not provided */
2354 got
= OBT_PROP_GETS_XPCS(self
->window
, WM_WINDOW_ROLE
, &s
);
2359 self
->role
= g_strdup("");
2361 /* get the WM_COMMAND */
2365 got
= OBT_PROP_GETSS(leader
, WM_COMMAND
, &ss
);
2367 got
= OBT_PROP_GETSS(self
->window
, WM_COMMAND
, &ss
);
2370 /* merge/mash them all together */
2371 gchar
*merge
= NULL
;
2374 for (i
= 0; ss
[i
]; ++i
) {
2377 merge
= g_strconcat(merge
, ss
[i
], NULL
);
2379 merge
= g_strconcat(ss
[i
], NULL
);
2384 self
->wm_command
= merge
;
2387 /* get the WM_CLIENT_MACHINE */
2390 got
= OBT_PROP_GETS(leader
, WM_CLIENT_MACHINE
, &s
);
2392 got
= OBT_PROP_GETS(self
->window
, WM_CLIENT_MACHINE
, &s
);
2395 gchar localhost
[128];
2398 gethostname(localhost
, 127);
2399 localhost
[127] = '\0';
2400 if (strcmp(localhost
, s
) != 0)
2401 self
->client_machine
= s
;
2405 /* see if it has the PID set too (the PID requires that the
2406 WM_CLIENT_MACHINE be set) */
2407 if (OBT_PROP_GET32(self
->window
, NET_WM_PID
, CARDINAL
, &pid
))
2412 /*! Save the properties used for app matching rules, as seen by Openbox when
2413 the window mapped, so that users can still access them later if the app
2415 static void client_save_app_rule_values(ObClient
*self
)
2419 OBT_PROP_SETS(self
->window
, OB_APP_ROLE
, self
->role
);
2420 OBT_PROP_SETS(self
->window
, OB_APP_NAME
, self
->name
);
2421 OBT_PROP_SETS(self
->window
, OB_APP_CLASS
, self
->class);
2422 OBT_PROP_SETS(self
->window
, OB_APP_TITLE
, self
->original_title
);
2424 switch (self
->type
) {
2425 case OB_CLIENT_TYPE_NORMAL
:
2426 type
= "normal"; break;
2427 case OB_CLIENT_TYPE_DIALOG
:
2428 type
= "dialog"; break;
2429 case OB_CLIENT_TYPE_UTILITY
:
2430 type
= "utility"; break;
2431 case OB_CLIENT_TYPE_MENU
:
2432 type
= "menu"; break;
2433 case OB_CLIENT_TYPE_TOOLBAR
:
2434 type
= "toolbar"; break;
2435 case OB_CLIENT_TYPE_SPLASH
:
2436 type
= "splash"; break;
2437 case OB_CLIENT_TYPE_DESKTOP
:
2438 type
= "desktop"; break;
2439 case OB_CLIENT_TYPE_DOCK
:
2440 type
= "dock"; break;
2442 OBT_PROP_SETS(self
->window
, OB_APP_TYPE
, type
);
2445 static void client_change_wm_state(ObClient
*self
)
2450 old
= self
->wmstate
;
2452 if (self
->shaded
|| self
->iconic
||
2453 (self
->desktop
!= DESKTOP_ALL
&& self
->desktop
!= screen_desktop
))
2455 self
->wmstate
= IconicState
;
2457 self
->wmstate
= NormalState
;
2459 if (old
!= self
->wmstate
) {
2460 OBT_PROP_MSG(ob_screen
, self
->window
, KDE_WM_CHANGE_STATE
,
2461 self
->wmstate
, 1, 0, 0, 0);
2463 state
[0] = self
->wmstate
;
2465 OBT_PROP_SETA32(self
->window
, WM_STATE
, WM_STATE
, state
, 2);
2469 static void client_change_state(ObClient
*self
)
2471 gulong netstate
[12];
2476 netstate
[num
++] = OBT_PROP_ATOM(NET_WM_STATE_MODAL
);
2478 netstate
[num
++] = OBT_PROP_ATOM(NET_WM_STATE_SHADED
);
2480 netstate
[num
++] = OBT_PROP_ATOM(NET_WM_STATE_HIDDEN
);
2481 if (self
->skip_taskbar
)
2482 netstate
[num
++] = OBT_PROP_ATOM(NET_WM_STATE_SKIP_TASKBAR
);
2483 if (self
->skip_pager
)
2484 netstate
[num
++] = OBT_PROP_ATOM(NET_WM_STATE_SKIP_PAGER
);
2485 if (self
->fullscreen
)
2486 netstate
[num
++] = OBT_PROP_ATOM(NET_WM_STATE_FULLSCREEN
);
2488 netstate
[num
++] = OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_VERT
);
2490 netstate
[num
++] = OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_HORZ
);
2492 netstate
[num
++] = OBT_PROP_ATOM(NET_WM_STATE_ABOVE
);
2494 netstate
[num
++] = OBT_PROP_ATOM(NET_WM_STATE_BELOW
);
2495 if (self
->demands_attention
)
2496 netstate
[num
++] = OBT_PROP_ATOM(NET_WM_STATE_DEMANDS_ATTENTION
);
2497 if (self
->undecorated
)
2498 netstate
[num
++] = OBT_PROP_ATOM(OB_WM_STATE_UNDECORATED
);
2499 OBT_PROP_SETA32(self
->window
, NET_WM_STATE
, ATOM
, netstate
, num
);
2502 frame_adjust_state(self
->frame
);
2505 ObClient
*client_search_focus_tree(ObClient
*self
)
2510 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
2511 if (client_focused(it
->data
)) return it
->data
;
2512 if ((ret
= client_search_focus_tree(it
->data
))) return ret
;
2517 ObClient
*client_search_focus_tree_full(ObClient
*self
)
2519 if (self
->parents
) {
2522 for (it
= self
->parents
; it
; it
= g_slist_next(it
)) {
2523 ObClient
*c
= it
->data
;
2524 if ((c
= client_search_focus_tree_full(c
))) return c
;
2530 /* this function checks the whole tree, the client_search_focus_tree
2531 does not, so we need to check this window */
2532 if (client_focused(self
))
2534 return client_search_focus_tree(self
);
2538 ObClient
*client_search_focus_group_full(ObClient
*self
)
2543 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
2544 ObClient
*c
= it
->data
;
2546 if (client_focused(c
)) return c
;
2547 if ((c
= client_search_focus_tree(it
->data
))) return c
;
2550 if (client_focused(self
)) return self
;
2554 gboolean
client_has_parent(ObClient
*self
)
2556 return self
->parents
!= NULL
;
2559 gboolean
client_has_children(ObClient
*self
)
2561 return self
->transients
!= NULL
;
2564 gboolean
client_is_oldfullscreen(const ObClient
*self
,
2567 const Rect
*monitor
, *allmonitors
;
2569 /* No decorations and fills the monitor = oldskool fullscreen.
2570 But not for maximized windows.
2573 if (self
->decorations
|| self
->max_horz
|| self
->max_vert
) return FALSE
;
2575 monitor
= screen_physical_area_monitor(screen_find_monitor(area
));
2576 allmonitors
= screen_physical_area_all_monitors();
2578 return (RECT_EQUAL(*area
, *monitor
) ||
2579 RECT_EQUAL(*area
, *allmonitors
));
2582 static ObStackingLayer
calc_layer(ObClient
*self
)
2586 if (self
->type
== OB_CLIENT_TYPE_DESKTOP
)
2587 l
= OB_STACKING_LAYER_DESKTOP
;
2588 else if (self
->type
== OB_CLIENT_TYPE_DOCK
) {
2589 if (self
->below
) l
= OB_STACKING_LAYER_NORMAL
;
2590 else l
= OB_STACKING_LAYER_ABOVE
;
2592 else if ((self
->fullscreen
||
2593 client_is_oldfullscreen(self
, &self
->area
)) &&
2594 /* you are fullscreen while you or your children are focused.. */
2595 (client_focused(self
) || client_search_focus_tree(self
) ||
2596 /* you can be fullscreen if you're on another desktop */
2597 (self
->desktop
!= screen_desktop
&&
2598 self
->desktop
!= DESKTOP_ALL
) ||
2599 /* and you can also be fullscreen if the focused client is on
2600 another monitor, or nothing else is focused */
2602 client_monitor(focus_client
) != client_monitor(self
))))
2603 l
= OB_STACKING_LAYER_FULLSCREEN
;
2604 else if (self
->above
) l
= OB_STACKING_LAYER_ABOVE
;
2605 else if (self
->below
) l
= OB_STACKING_LAYER_BELOW
;
2606 else l
= OB_STACKING_LAYER_NORMAL
;
2611 static void client_calc_layer_recursive(ObClient
*self
, ObClient
*orig
,
2612 ObStackingLayer min
)
2614 ObStackingLayer old
, own
;
2618 own
= calc_layer(self
);
2619 self
->layer
= MAX(own
, min
);
2621 if (self
->layer
!= old
) {
2622 stacking_remove(CLIENT_AS_WINDOW(self
));
2623 stacking_add_nonintrusive(CLIENT_AS_WINDOW(self
));
2626 /* we've been restacked */
2627 self
->visited
= TRUE
;
2629 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
2630 client_calc_layer_recursive(it
->data
, orig
,
2634 static void client_calc_layer_internal(ObClient
*self
)
2638 /* transients take on the layer of their parents */
2639 sit
= client_search_all_top_parents(self
);
2641 for (; sit
; sit
= g_slist_next(sit
))
2642 client_calc_layer_recursive(sit
->data
, self
, 0);
2645 void client_calc_layer(ObClient
*self
)
2649 /* skip over stuff above fullscreen layer */
2650 for (it
= stacking_list
; it
; it
= g_list_next(it
))
2651 if (window_layer(it
->data
) <= OB_STACKING_LAYER_FULLSCREEN
) break;
2653 /* find the windows in the fullscreen layer, and mark them not-visited */
2654 for (; it
; it
= g_list_next(it
)) {
2655 if (window_layer(it
->data
) < OB_STACKING_LAYER_FULLSCREEN
) break;
2656 else if (WINDOW_IS_CLIENT(it
->data
))
2657 WINDOW_AS_CLIENT(it
->data
)->visited
= FALSE
;
2660 client_calc_layer_internal(self
);
2662 /* skip over stuff above fullscreen layer */
2663 for (it
= stacking_list
; it
; it
= g_list_next(it
))
2664 if (window_layer(it
->data
) <= OB_STACKING_LAYER_FULLSCREEN
) break;
2666 /* now recalc any windows in the fullscreen layer which have not
2667 had their layer recalced already */
2668 for (; it
; it
= g_list_next(it
)) {
2669 if (window_layer(it
->data
) < OB_STACKING_LAYER_FULLSCREEN
) break;
2670 else if (WINDOW_IS_CLIENT(it
->data
) &&
2671 !WINDOW_AS_CLIENT(it
->data
)->visited
)
2672 client_calc_layer_internal(it
->data
);
2676 gboolean
client_should_show(ObClient
*self
)
2680 if (client_normal(self
) && screen_showing_desktop
)
2682 if (self
->desktop
== screen_desktop
|| self
->desktop
== DESKTOP_ALL
)
2688 gboolean
client_show(ObClient
*self
)
2690 gboolean show
= FALSE
;
2692 if (client_should_show(self
)) {
2693 /* replay pending pointer event before showing the window, in case it
2694 should be going to something under the window */
2695 mouse_replay_pointer();
2697 frame_show(self
->frame
);
2700 /* According to the ICCCM (sec 4.1.3.1) when a window is not visible,
2701 it needs to be in IconicState. This includes when it is on another
2704 client_change_wm_state(self
);
2709 gboolean
client_hide(ObClient
*self
)
2711 gboolean hide
= FALSE
;
2713 if (!client_should_show(self
)) {
2714 /* We don't need to ignore enter events here.
2715 The window can hide/iconify in 3 different ways:
2716 1 - through an x message. in this case we ignore all enter events
2717 caused by responding to the x message (unless underMouse)
2718 2 - by a keyboard action. in this case we ignore all enter events
2719 caused by the action
2720 3 - by a mouse action. in this case they are doing stuff with the
2721 mouse and focus _should_ move.
2723 Also in action_end, we simulate an enter event that can't be ignored
2724 so trying to ignore them is futile in case 3 anyways
2727 /* replay pending pointer event before hiding the window, in case it
2728 should be going to the window */
2729 mouse_replay_pointer();
2731 frame_hide(self
->frame
);
2734 /* According to the ICCCM (sec 4.1.3.1) when a window is not visible,
2735 it needs to be in IconicState. This includes when it is on another
2738 client_change_wm_state(self
);
2743 void client_showhide(ObClient
*self
)
2745 if (!client_show(self
))
2749 gboolean
client_normal(ObClient
*self
) {
2750 return ! (self
->type
== OB_CLIENT_TYPE_DESKTOP
||
2751 self
->type
== OB_CLIENT_TYPE_DOCK
||
2752 self
->type
== OB_CLIENT_TYPE_SPLASH
);
2755 gboolean
client_helper(ObClient
*self
)
2757 return (self
->type
== OB_CLIENT_TYPE_UTILITY
||
2758 self
->type
== OB_CLIENT_TYPE_MENU
||
2759 self
->type
== OB_CLIENT_TYPE_TOOLBAR
);
2762 gboolean
client_mouse_focusable(ObClient
*self
)
2764 return !(self
->type
== OB_CLIENT_TYPE_MENU
||
2765 self
->type
== OB_CLIENT_TYPE_TOOLBAR
||
2766 self
->type
== OB_CLIENT_TYPE_SPLASH
||
2767 self
->type
== OB_CLIENT_TYPE_DOCK
);
2770 gboolean
client_enter_focusable(ObClient
*self
)
2772 /* you can focus desktops but it shouldn't on enter */
2773 return (client_mouse_focusable(self
) &&
2774 self
->type
!= OB_CLIENT_TYPE_DESKTOP
);
2777 static void client_apply_startup_state(ObClient
*self
,
2778 gint x
, gint y
, gint w
, gint h
)
2780 /* save the states that we are going to apply */
2781 gboolean iconic
= self
->iconic
;
2782 gboolean fullscreen
= self
->fullscreen
;
2783 gboolean undecorated
= self
->undecorated
;
2784 gboolean shaded
= self
->shaded
;
2785 gboolean demands_attention
= self
->demands_attention
;
2786 gboolean max_horz
= self
->max_horz
;
2787 gboolean max_vert
= self
->max_vert
;
2791 /* turn them all off in the client, so they won't affect the window
2793 self
->iconic
= self
->fullscreen
= self
->undecorated
= self
->shaded
=
2794 self
->demands_attention
= self
->max_horz
= self
->max_vert
= FALSE
;
2796 /* move the client to its placed position, or it it's already there,
2797 generate a ConfigureNotify telling the client where it is.
2799 do this after adjusting the frame. otherwise it gets all weird and
2800 clients don't work right
2802 do this before applying the states so they have the correct
2803 pre-max/pre-fullscreen values
2805 client_try_configure(self
, &x
, &y
, &w
, &h
, &l
, &l
, FALSE
);
2806 ob_debug("placed window 0x%x at %d, %d with size %d x %d",
2807 self
->window
, x
, y
, w
, h
);
2808 /* save the area, and make it where it should be for the premax stuff */
2809 oldarea
= self
->area
;
2810 RECT_SET(self
->area
, x
, y
, w
, h
);
2812 /* apply the states. these are in a carefully crafted order.. */
2815 client_iconify(self
, TRUE
, FALSE
, TRUE
);
2817 client_set_undecorated(self
, TRUE
);
2819 client_shade(self
, TRUE
);
2820 if (demands_attention
)
2821 client_hilite(self
, TRUE
);
2823 if (max_vert
&& max_horz
)
2824 client_maximize(self
, TRUE
, 0);
2826 client_maximize(self
, TRUE
, 2);
2828 client_maximize(self
, TRUE
, 1);
2830 /* fullscreen removes the ability to apply other states */
2832 client_fullscreen(self
, TRUE
);
2834 /* make sure client_setup_decor_and_functions() is called at least once */
2835 client_setup_decor_and_functions(self
, FALSE
);
2837 /* if the window hasn't been configured yet, then do so now, in fact the
2838 x,y,w,h may _not_ be the same as the area rect, which can end up
2839 meaning that the client isn't properly moved/resized by the fullscreen
2841 pho can cause this because it maps at size of the screen but not 0,0
2842 so openbox moves it on screen to 0,0 (thus x,y=0,0 and area.x,y don't).
2843 then fullscreen'ing makes it go to 0,0 which it thinks it already is at
2844 cuz thats where the pre-fullscreen will be. however the actual area is
2845 not, so this needs to be called even if we have fullscreened/maxed
2847 self
->area
= oldarea
;
2848 client_configure(self
, x
, y
, w
, h
, FALSE
, TRUE
, FALSE
);
2850 /* nothing to do for the other states:
2859 void client_gravity_resize_w(ObClient
*self
, gint
*x
, gint oldw
, gint neww
)
2861 /* these should be the current values. this is for when you're not moving,
2863 g_assert(*x
== self
->area
.x
);
2864 g_assert(oldw
== self
->area
.width
);
2867 switch (self
->gravity
) {
2869 case NorthWestGravity
:
2871 case SouthWestGravity
:
2878 *x
-= (neww
- oldw
) / 2;
2880 case NorthEastGravity
:
2882 case SouthEastGravity
:
2888 void client_gravity_resize_h(ObClient
*self
, gint
*y
, gint oldh
, gint newh
)
2890 /* these should be the current values. this is for when you're not moving,
2892 g_assert(*y
== self
->area
.y
);
2893 g_assert(oldh
== self
->area
.height
);
2896 switch (self
->gravity
) {
2898 case NorthWestGravity
:
2900 case NorthEastGravity
:
2907 *y
-= (newh
- oldh
) / 2;
2909 case SouthWestGravity
:
2911 case SouthEastGravity
:
2917 void client_try_configure(ObClient
*self
, gint
*x
, gint
*y
, gint
*w
, gint
*h
,
2918 gint
*logicalw
, gint
*logicalh
,
2921 Rect desired
= {*x
, *y
, *w
, *h
};
2922 frame_rect_to_frame(self
->frame
, &desired
);
2924 /* make the frame recalculate its dimensions n shit without changing
2925 anything visible for real, this way the constraints below can work with
2926 the updated frame dimensions. */
2927 frame_adjust_area(self
->frame
, FALSE
, TRUE
, TRUE
);
2929 /* cap any X windows at the size of an unsigned short */
2932 - self
->frame
->size
.left
- self
->frame
->size
.right
);
2935 - self
->frame
->size
.top
- self
->frame
->size
.bottom
);
2937 /* gets the frame's position */
2938 frame_client_gravity(self
->frame
, x
, y
);
2940 /* these positions are frame positions, not client positions */
2942 /* set the size and position if fullscreen */
2943 if (self
->fullscreen
) {
2947 i
= screen_find_monitor(&desired
);
2948 a
= screen_physical_area_monitor(i
);
2955 user
= FALSE
; /* ignore if the client can't be moved/resized when it
2957 } else if (self
->max_horz
|| self
->max_vert
) {
2961 /* use all possible struts when maximizing to the full screen */
2962 i
= screen_find_monitor(&desired
);
2963 a
= screen_area(self
->desktop
, i
,
2964 (self
->max_horz
&& self
->max_vert
? NULL
: &desired
));
2966 /* set the size and position if maximized */
2967 if (self
->max_horz
) {
2969 *w
= a
->width
- self
->frame
->size
.left
- self
->frame
->size
.right
;
2971 if (self
->max_vert
) {
2973 *h
= a
->height
- self
->frame
->size
.top
- self
->frame
->size
.bottom
;
2976 user
= FALSE
; /* ignore if the client can't be moved/resized when it
2979 g_slice_free(Rect
, a
);
2982 /* gets the client's position */
2983 frame_frame_gravity(self
->frame
, x
, y
);
2985 /* work within the preferred sizes given by the window, these may have
2986 changed rather than it's requested width and height, so always run
2987 through this code */
2989 gint basew
, baseh
, minw
, minh
;
2990 gint incw
, inch
, maxw
, maxh
;
2991 gfloat minratio
, maxratio
;
2993 incw
= self
->size_inc
.width
;
2994 inch
= self
->size_inc
.height
;
2995 minratio
= self
->fullscreen
|| (self
->max_horz
&& self
->max_vert
) ?
2996 0 : self
->min_ratio
;
2997 maxratio
= self
->fullscreen
|| (self
->max_horz
&& self
->max_vert
) ?
2998 0 : self
->max_ratio
;
3000 /* base size is substituted with min size if not specified */
3001 if (self
->base_size
.width
>= 0 || self
->base_size
.height
>= 0) {
3002 basew
= self
->base_size
.width
;
3003 baseh
= self
->base_size
.height
;
3005 basew
= self
->min_size
.width
;
3006 baseh
= self
->min_size
.height
;
3008 /* min size is substituted with base size if not specified */
3009 if (self
->min_size
.width
|| self
->min_size
.height
) {
3010 minw
= self
->min_size
.width
;
3011 minh
= self
->min_size
.height
;
3013 minw
= self
->base_size
.width
;
3014 minh
= self
->base_size
.height
;
3017 /* This comment is no longer true */
3018 /* if this is a user-requested resize, then check against min/max
3021 /* smaller than min size or bigger than max size? */
3022 if (*w
> self
->max_size
.width
) *w
= self
->max_size
.width
;
3023 if (*w
< minw
) *w
= minw
;
3024 if (*h
> self
->max_size
.height
) *h
= self
->max_size
.height
;
3025 if (*h
< minh
) *h
= minh
;
3030 /* the sizes to used for maximized */
3034 /* keep to the increments */
3038 /* you cannot resize to nothing */
3039 if (basew
+ *w
< 1) *w
= 1 - basew
;
3040 if (baseh
+ *h
< 1) *h
= 1 - baseh
;
3042 /* save the logical size */
3043 *logicalw
= incw
> 1 ? *w
: *w
+ basew
;
3044 *logicalh
= inch
> 1 ? *h
: *h
+ baseh
;
3049 /* if maximized/fs then don't use the size increments */
3050 if (self
->fullscreen
|| self
->max_horz
) *w
= maxw
;
3051 if (self
->fullscreen
|| self
->max_vert
) *h
= maxh
;
3056 /* adjust the height to match the width for the aspect ratios.
3057 for this, min size is not substituted for base size ever. */
3058 *w
-= self
->base_size
.width
;
3059 *h
-= self
->base_size
.height
;
3062 if (*h
* minratio
> *w
) {
3063 *h
= (gint
)(*w
/ minratio
);
3065 /* you cannot resize to nothing */
3068 *w
= (gint
)(*h
* minratio
);
3072 if (*h
* maxratio
< *w
) {
3073 *h
= (gint
)(*w
/ maxratio
);
3075 /* you cannot resize to nothing */
3078 *w
= (gint
)(*h
* minratio
);
3082 *w
+= self
->base_size
.width
;
3083 *h
+= self
->base_size
.height
;
3086 /* these override the above states! if you cant move you can't move! */
3088 if (!(self
->functions
& OB_CLIENT_FUNC_MOVE
)) {
3092 if (!(self
->functions
& OB_CLIENT_FUNC_RESIZE
)) {
3093 *w
= self
->area
.width
;
3094 *h
= self
->area
.height
;
3102 void client_configure(ObClient
*self
, gint x
, gint y
, gint w
, gint h
,
3103 gboolean user
, gboolean final
, gboolean force_reply
)
3105 Rect oldframe
, oldclient
;
3106 gboolean send_resize_client
;
3107 gboolean moved
= FALSE
, resized
= FALSE
, rootmoved
= FALSE
;
3108 gboolean fmoved
, fresized
;
3109 guint fdecor
= self
->frame
->decorations
;
3110 gboolean fhorz
= self
->frame
->max_horz
;
3111 gboolean fvert
= self
->frame
->max_vert
;
3112 gint logicalw
, logicalh
;
3114 /* find the new x, y, width, and height (and logical size) */
3115 client_try_configure(self
, &x
, &y
, &w
, &h
, &logicalw
, &logicalh
, user
);
3117 /* set the logical size if things changed */
3118 if (!(w
== self
->area
.width
&& h
== self
->area
.height
))
3119 SIZE_SET(self
->logical_size
, logicalw
, logicalh
);
3121 /* figure out if we moved or resized or what */
3122 moved
= (x
!= self
->area
.x
|| y
!= self
->area
.y
);
3123 resized
= (w
!= self
->area
.width
|| h
!= self
->area
.height
);
3125 oldframe
= self
->frame
->area
;
3126 oldclient
= self
->area
;
3127 RECT_SET(self
->area
, x
, y
, w
, h
);
3129 /* for app-requested resizes, always resize if 'resized' is true.
3130 for user-requested ones, only resize if final is true, or when
3131 resizing in redraw mode */
3132 send_resize_client
= ((!user
&& resized
) ||
3134 (resized
&& config_resize_redraw
))));
3136 /* if the client is enlarging, then resize the client before the frame */
3137 if (send_resize_client
&& (w
> oldclient
.width
|| h
> oldclient
.height
)) {
3138 XMoveResizeWindow(obt_display
, self
->window
,
3139 self
->frame
->size
.left
, self
->frame
->size
.top
,
3140 MAX(w
, oldclient
.width
), MAX(h
, oldclient
.height
));
3141 frame_adjust_client_area(self
->frame
);
3144 /* find the frame's dimensions and move/resize it */
3148 /* if decorations changed, then readjust everything for the frame */
3149 if (self
->decorations
!= fdecor
||
3150 self
->max_horz
!= fhorz
|| self
->max_vert
!= fvert
)
3152 fmoved
= fresized
= TRUE
;
3155 /* adjust the frame */
3156 if (fmoved
|| fresized
) {
3157 gulong ignore_start
;
3159 ignore_start
= event_start_ignore_all_enters();
3161 /* replay pending pointer event before move the window, in case it
3162 would change what window gets the event */
3163 mouse_replay_pointer();
3165 frame_adjust_area(self
->frame
, fmoved
, fresized
, FALSE
);
3168 event_end_ignore_all_enters(ignore_start
);
3171 if (!user
|| final
) {
3172 gint oldrx
= self
->root_pos
.x
;
3173 gint oldry
= self
->root_pos
.y
;
3174 /* we have reset the client to 0 border width, so don't include
3175 it in these coords */
3176 POINT_SET(self
->root_pos
,
3177 self
->frame
->area
.x
+ self
->frame
->size
.left
-
3179 self
->frame
->area
.y
+ self
->frame
->size
.top
-
3180 self
->border_width
);
3181 if (self
->root_pos
.x
!= oldrx
|| self
->root_pos
.y
!= oldry
)
3185 /* This is kinda tricky and should not be changed.. let me explain!
3187 When user = FALSE, then the request is coming from the application
3188 itself, and we are more strict about when to send a synthetic
3189 ConfigureNotify. We strictly follow the rules of the ICCCM sec 4.1.5
3190 in this case (or send one if force_reply is true)
3192 When user = TRUE, then the request is coming from "us", like when we
3193 maximize a window or something. In this case we are more lenient. We
3194 used to follow the same rules as above, but _Java_ Swing can't handle
3195 this. So just to appease Swing, when user = TRUE, we always send
3196 a synthetic ConfigureNotify to give the window its root coordinates.
3197 Lastly, if force_reply is TRUE, we always send a
3198 ConfigureNotify, which is needed during a resize with XSYNCronization.
3200 if ((!user
&& !resized
&& (rootmoved
|| force_reply
)) ||
3201 (user
&& ((!resized
&& force_reply
) || (final
&& rootmoved
))))
3205 event
.type
= ConfigureNotify
;
3206 event
.xconfigure
.display
= obt_display
;
3207 event
.xconfigure
.event
= self
->window
;
3208 event
.xconfigure
.window
= self
->window
;
3210 ob_debug("Sending ConfigureNotify to %s for %d,%d %dx%d",
3211 self
->title
, self
->root_pos
.x
, self
->root_pos
.y
, w
, h
);
3213 /* root window real coords */
3214 event
.xconfigure
.x
= self
->root_pos
.x
;
3215 event
.xconfigure
.y
= self
->root_pos
.y
;
3216 event
.xconfigure
.width
= w
;
3217 event
.xconfigure
.height
= h
;
3218 event
.xconfigure
.border_width
= self
->border_width
;
3219 event
.xconfigure
.above
= None
;
3220 event
.xconfigure
.override_redirect
= FALSE
;
3221 XSendEvent(event
.xconfigure
.display
, event
.xconfigure
.window
,
3222 FALSE
, StructureNotifyMask
, &event
);
3225 /* if the client is shrinking, then resize the frame before the client.
3227 both of these resize sections may run, because the top one only resizes
3228 in the direction that is growing
3230 if (send_resize_client
&& (w
<= oldclient
.width
|| h
<= oldclient
.height
))
3232 frame_adjust_client_area(self
->frame
);
3233 XMoveResizeWindow(obt_display
, self
->window
,
3234 self
->frame
->size
.left
, self
->frame
->size
.top
, w
, h
);
3237 XFlush(obt_display
);
3239 /* if it moved between monitors, then this can affect the stacking
3240 layer of this window or others - for fullscreen windows.
3241 also if it changed to/from oldschool fullscreen then its layer may
3244 watch out tho, don't try change stacking stuff if the window is no
3245 longer being managed !
3247 if (self
->managed
&&
3248 (screen_find_monitor(&self
->frame
->area
) !=
3249 screen_find_monitor(&oldframe
) ||
3250 (final
&& (client_is_oldfullscreen(self
, &oldclient
) !=
3251 client_is_oldfullscreen(self
, &self
->area
)))))
3253 client_calc_layer(self
);
3257 void client_fullscreen(ObClient
*self
, gboolean fs
)
3261 if (!(self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
) || /* can't */
3262 self
->fullscreen
== fs
) return; /* already done */
3264 self
->fullscreen
= fs
;
3265 client_change_state(self
); /* change the state hints on the client */
3268 self
->pre_fullscreen_area
= self
->area
;
3269 self
->pre_fullscreen_max_horz
= self
->max_horz
;
3270 self
->pre_fullscreen_max_vert
= self
->max_vert
;
3272 /* if the window is maximized, its area isn't all that meaningful.
3273 save its premax area instead. */
3274 if (self
->max_horz
) {
3275 self
->pre_fullscreen_area
.x
= self
->pre_max_area
.x
;
3276 self
->pre_fullscreen_area
.width
= self
->pre_max_area
.width
;
3278 if (self
->max_vert
) {
3279 self
->pre_fullscreen_area
.y
= self
->pre_max_area
.y
;
3280 self
->pre_fullscreen_area
.height
= self
->pre_max_area
.height
;
3283 /* these will help configure_full figure out where to fullscreen
3287 w
= self
->area
.width
;
3288 h
= self
->area
.height
;
3290 g_assert(self
->pre_fullscreen_area
.width
> 0 &&
3291 self
->pre_fullscreen_area
.height
> 0);
3293 self
->max_horz
= self
->pre_fullscreen_max_horz
;
3294 self
->max_vert
= self
->pre_fullscreen_max_vert
;
3295 if (self
->max_horz
) {
3296 self
->pre_max_area
.x
= self
->pre_fullscreen_area
.x
;
3297 self
->pre_max_area
.width
= self
->pre_fullscreen_area
.width
;
3299 if (self
->max_vert
) {
3300 self
->pre_max_area
.y
= self
->pre_fullscreen_area
.y
;
3301 self
->pre_max_area
.height
= self
->pre_fullscreen_area
.height
;
3304 x
= self
->pre_fullscreen_area
.x
;
3305 y
= self
->pre_fullscreen_area
.y
;
3306 w
= self
->pre_fullscreen_area
.width
;
3307 h
= self
->pre_fullscreen_area
.height
;
3308 RECT_SET(self
->pre_fullscreen_area
, 0, 0, 0, 0);
3311 ob_debug("Window %s going fullscreen (%d)",
3312 self
->title
, self
->fullscreen
);
3315 /* make sure the window is on some monitor */
3316 client_find_onscreen(self
, &x
, &y
, w
, h
, FALSE
);
3319 client_setup_decor_and_functions(self
, FALSE
);
3320 client_move_resize(self
, x
, y
, w
, h
);
3322 /* and adjust our layer/stacking. do this after resizing the window,
3323 and applying decorations, because windows which fill the screen are
3324 considered "fullscreen" and it affects their layer */
3325 client_calc_layer(self
);
3328 /* try focus us when we go into fullscreen mode */
3333 static void client_iconify_recursive(ObClient
*self
,
3334 gboolean iconic
, gboolean curdesk
,
3335 gboolean hide_animation
)
3338 gboolean changed
= FALSE
;
3340 if (self
->iconic
!= iconic
) {
3341 ob_debug("%sconifying window: 0x%lx", (iconic
? "I" : "Uni"),
3345 /* don't let non-normal windows iconify along with their parents
3347 if (client_normal(self
)) {
3348 self
->iconic
= iconic
;
3350 /* update the focus lists.. iconic windows go to the bottom of
3351 the list. this will also call focus_cycle_addremove(). */
3352 focus_order_to_bottom(self
);
3357 self
->iconic
= iconic
;
3359 if (curdesk
&& self
->desktop
!= screen_desktop
&&
3360 self
->desktop
!= DESKTOP_ALL
)
3361 client_set_desktop(self
, screen_desktop
, FALSE
, FALSE
);
3363 /* this puts it after the current focused window, this will
3364 also cause focus_cycle_addremove() to be called for the
3366 focus_order_like_new(self
);
3373 client_change_state(self
);
3374 if (config_animate_iconify
&& !hide_animation
)
3375 frame_begin_iconify_animation(self
->frame
, iconic
);
3376 /* do this after starting the animation so it doesn't flash */
3377 client_showhide(self
);
3380 /* iconify all direct transients, and deiconify all transients
3382 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
3383 if (it
->data
!= self
)
3384 if (client_is_direct_child(self
, it
->data
) || !iconic
)
3385 client_iconify_recursive(it
->data
, iconic
, curdesk
,
3389 void client_iconify(ObClient
*self
, gboolean iconic
, gboolean curdesk
,
3390 gboolean hide_animation
)
3392 if (self
->functions
& OB_CLIENT_FUNC_ICONIFY
|| !iconic
) {
3393 /* move up the transient chain as far as possible first */
3394 self
= client_search_top_direct_parent(self
);
3395 client_iconify_recursive(self
, iconic
, curdesk
, hide_animation
);
3399 void client_maximize(ObClient
*self
, gboolean max
, gint dir
)
3403 g_assert(dir
== 0 || dir
== 1 || dir
== 2);
3404 if (!(self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) && max
) return;/* can't */
3406 /* check if already done */
3408 if (dir
== 0 && self
->max_horz
&& self
->max_vert
) return;
3409 if (dir
== 1 && self
->max_horz
) return;
3410 if (dir
== 2 && self
->max_vert
) return;
3412 if (dir
== 0 && !self
->max_horz
&& !self
->max_vert
) return;
3413 if (dir
== 1 && !self
->max_horz
) return;
3414 if (dir
== 2 && !self
->max_vert
) return;
3417 /* these will help configure_full figure out which screen to fill with
3421 w
= self
->area
.width
;
3422 h
= self
->area
.height
;
3425 if ((dir
== 0 || dir
== 1) && !self
->max_horz
) { /* horz */
3426 RECT_SET(self
->pre_max_area
,
3427 self
->area
.x
, self
->pre_max_area
.y
,
3428 self
->area
.width
, self
->pre_max_area
.height
);
3430 if ((dir
== 0 || dir
== 2) && !self
->max_vert
) { /* vert */
3431 RECT_SET(self
->pre_max_area
,
3432 self
->pre_max_area
.x
, self
->area
.y
,
3433 self
->pre_max_area
.width
, self
->area
.height
);
3436 if ((dir
== 0 || dir
== 1) && self
->max_horz
) { /* horz */
3437 g_assert(self
->pre_max_area
.width
> 0);
3439 x
= self
->pre_max_area
.x
;
3440 w
= self
->pre_max_area
.width
;
3442 RECT_SET(self
->pre_max_area
, 0, self
->pre_max_area
.y
,
3443 0, self
->pre_max_area
.height
);
3445 if ((dir
== 0 || dir
== 2) && self
->max_vert
) { /* vert */
3446 g_assert(self
->pre_max_area
.height
> 0);
3448 y
= self
->pre_max_area
.y
;
3449 h
= self
->pre_max_area
.height
;
3451 RECT_SET(self
->pre_max_area
, self
->pre_max_area
.x
, 0,
3452 self
->pre_max_area
.width
, 0);
3456 if (dir
== 0 || dir
== 1) /* horz */
3457 self
->max_horz
= max
;
3458 if (dir
== 0 || dir
== 2) /* vert */
3459 self
->max_vert
= max
;
3462 /* make sure the window is on some monitor */
3463 client_find_onscreen(self
, &x
, &y
, w
, h
, FALSE
);
3466 client_change_state(self
); /* change the state hints on the client */
3468 client_setup_decor_and_functions(self
, FALSE
);
3469 client_move_resize(self
, x
, y
, w
, h
);
3472 void client_shade(ObClient
*self
, gboolean shade
)
3474 if ((!(self
->functions
& OB_CLIENT_FUNC_SHADE
) &&
3475 shade
) || /* can't shade */
3476 self
->shaded
== shade
) return; /* already done */
3478 self
->shaded
= shade
;
3479 client_change_state(self
);
3480 client_change_wm_state(self
); /* the window is being hidden/shown */
3481 /* resize the frame to just the titlebar */
3482 frame_adjust_area(self
->frame
, FALSE
, TRUE
, FALSE
);
3485 static void client_ping_event(ObClient
*self
, gboolean dead
)
3487 if (self
->not_responding
!= dead
) {
3488 self
->not_responding
= dead
;
3489 client_update_title(self
);
3492 /* the client isn't responding, so ask to kill it */
3493 client_prompt_kill(self
);
3495 /* it came back to life ! */
3497 if (self
->kill_prompt
) {
3498 prompt_unref(self
->kill_prompt
);
3499 self
->kill_prompt
= NULL
;
3502 self
->kill_level
= 0;
3507 void client_close(ObClient
*self
)
3509 if (!(self
->functions
& OB_CLIENT_FUNC_CLOSE
)) return;
3511 /* if closing an internal obprompt, that is just cancelling it */
3513 prompt_cancel(self
->prompt
);
3517 /* in the case that the client provides no means to requesting that it
3518 close, we just kill it */
3519 if (!self
->delete_window
)
3520 /* don't use client_kill(), we should only kill based on PID in
3521 response to a lack of PING replies */
3522 XKillClient(obt_display
, self
->window
);
3524 /* request the client to close with WM_DELETE_WINDOW */
3525 OBT_PROP_MSG_TO(self
->window
, self
->window
, WM_PROTOCOLS
,
3526 OBT_PROP_ATOM(WM_DELETE_WINDOW
), event_time(),
3527 0, 0, 0, NoEventMask
);
3529 /* we're trying to close the window, so see if it is responding. if it
3530 is not, then we will let them kill the window */
3532 ping_start(self
, client_ping_event
);
3534 /* if we already know the window isn't responding (maybe they clicked
3535 no in the kill dialog but it hasn't come back to life), then show
3537 if (self
->not_responding
)
3538 client_prompt_kill(self
);
3542 #define OB_KILL_RESULT_NO 0
3543 #define OB_KILL_RESULT_YES 1
3545 static gboolean
client_kill_requested(ObPrompt
*p
, gint result
, gpointer data
)
3547 ObClient
*self
= data
;
3549 if (result
== OB_KILL_RESULT_YES
)
3551 return TRUE
; /* call the cleanup func */
3554 static void client_kill_cleanup(ObPrompt
*p
, gpointer data
)
3556 ObClient
*self
= data
;
3558 g_assert(p
== self
->kill_prompt
);
3560 prompt_unref(self
->kill_prompt
);
3561 self
->kill_prompt
= NULL
;
3564 static void client_prompt_kill(ObClient
*self
)
3566 /* check if we're already prompting */
3567 if (!self
->kill_prompt
) {
3568 ObPromptAnswer answers
[] = {
3569 { 0, OB_KILL_RESULT_NO
},
3570 { 0, OB_KILL_RESULT_YES
}
3573 const gchar
*y
, *title
;
3575 title
= self
->original_title
;
3576 if (title
[0] == '\0') {
3577 /* empty string, so use its parent */
3578 ObClient
*p
= client_search_top_direct_parent(self
);
3579 if (p
) title
= p
->original_title
;
3582 if (client_on_localhost(self
)) {
3585 if (self
->kill_level
== 0)
3591 (_("The window \"%s\" does not seem to be responding. Do you want to force it to exit by sending the %s signal?"),
3593 y
= _("End Process");
3597 (_("The window \"%s\" does not seem to be responding. Do you want to disconnect it from the X server?"),
3599 y
= _("Disconnect");
3601 /* set the dialog buttons' text */
3602 answers
[0].text
= _("Cancel"); /* "no" */
3603 answers
[1].text
= y
; /* "yes" */
3605 self
->kill_prompt
= prompt_new(m
, NULL
, answers
,
3606 sizeof(answers
)/sizeof(answers
[0]),
3607 OB_KILL_RESULT_NO
, /* default = no */
3608 OB_KILL_RESULT_NO
, /* cancel = no */
3609 client_kill_requested
,
3610 client_kill_cleanup
,
3615 prompt_show(self
->kill_prompt
, self
, TRUE
);
3618 void client_kill(ObClient
*self
)
3620 /* don't kill our own windows */
3621 if (self
->prompt
) return;
3623 if (client_on_localhost(self
) && self
->pid
) {
3624 /* running on the local host */
3625 if (self
->kill_level
== 0) {
3626 ob_debug("killing window 0x%x with pid %lu, with SIGTERM",
3627 self
->window
, self
->pid
);
3628 kill(self
->pid
, SIGTERM
);
3631 /* show that we're trying to kill it */
3632 client_update_title(self
);
3635 ob_debug("killing window 0x%x with pid %lu, with SIGKILL",
3636 self
->window
, self
->pid
);
3637 kill(self
->pid
, SIGKILL
); /* kill -9 */
3641 /* running on a remote host */
3642 XKillClient(obt_display
, self
->window
);
3646 void client_hilite(ObClient
*self
, gboolean hilite
)
3648 if (self
->demands_attention
== hilite
)
3649 return; /* no change */
3651 /* don't allow focused windows to hilite */
3652 self
->demands_attention
= hilite
&& !client_focused(self
);
3653 if (self
->frame
!= NULL
) { /* if we're mapping, just set the state */
3654 if (self
->demands_attention
) {
3655 frame_flash_start(self
->frame
);
3657 /* if the window is on another desktop then raise it and make it
3658 the most recently used window */
3659 if (self
->desktop
!= screen_desktop
&&
3660 self
->desktop
!= DESKTOP_ALL
)
3662 stacking_raise(CLIENT_AS_WINDOW(self
));
3663 focus_order_to_top(self
);
3667 frame_flash_stop(self
->frame
);
3668 client_change_state(self
);
3672 static void client_set_desktop_recursive(ObClient
*self
,
3680 if (target
!= self
->desktop
&& self
->type
!= OB_CLIENT_TYPE_DESKTOP
) {
3682 ob_debug("Setting desktop %u", target
+1);
3684 g_assert(target
< screen_num_desktops
|| target
== DESKTOP_ALL
);
3686 old
= self
->desktop
;
3687 self
->desktop
= target
;
3688 OBT_PROP_SET32(self
->window
, NET_WM_DESKTOP
, CARDINAL
, target
);
3689 /* the frame can display the current desktop state */
3690 frame_adjust_state(self
->frame
);
3691 /* 'move' the window to the new desktop */
3695 /* raise if it was not already on the desktop */
3696 if (old
!= DESKTOP_ALL
&& !dontraise
)
3697 stacking_raise(CLIENT_AS_WINDOW(self
));
3698 if (STRUT_EXISTS(self
->strut
))
3699 screen_update_areas();
3701 /* the new desktop's geometry may be different, so we may need to
3702 resize, for example if we are maximized */
3703 client_reconfigure(self
, FALSE
);
3705 focus_cycle_addremove(self
, FALSE
);
3708 /* move all transients */
3709 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
3710 if (it
->data
!= self
)
3711 if (client_is_direct_child(self
, it
->data
))
3712 client_set_desktop_recursive(it
->data
, target
,
3713 donthide
, dontraise
);
3716 void client_set_desktop(ObClient
*self
, guint target
,
3717 gboolean donthide
, gboolean dontraise
)
3719 self
= client_search_top_direct_parent(self
);
3720 client_set_desktop_recursive(self
, target
, donthide
, dontraise
);
3722 focus_cycle_addremove(NULL
, TRUE
);
3725 gboolean
client_is_direct_child(ObClient
*parent
, ObClient
*child
)
3727 while (child
!= parent
&& (child
= client_direct_parent(child
)));
3728 return child
== parent
;
3731 ObClient
*client_search_modal_child(ObClient
*self
)
3736 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
3737 ObClient
*c
= it
->data
;
3738 if ((ret
= client_search_modal_child(c
))) return ret
;
3739 if (c
->modal
) return c
;
3744 struct ObClientFindDestroyUnmap
{
3749 static gboolean
find_destroy_unmap(XEvent
*e
, gpointer data
)
3751 struct ObClientFindDestroyUnmap
*find
= data
;
3752 if (e
->type
== DestroyNotify
)
3753 return e
->xdestroywindow
.window
== find
->window
;
3754 if (e
->type
== UnmapNotify
&& e
->xunmap
.window
== find
->window
)
3755 /* ignore the first $find->ignore_unmaps$ many unmap events */
3756 return --find
->ignore_unmaps
< 0;
3760 gboolean
client_validate(ObClient
*self
)
3762 struct ObClientFindDestroyUnmap find
;
3764 XSync(obt_display
, FALSE
); /* get all events on the server */
3766 find
.window
= self
->window
;
3767 find
.ignore_unmaps
= self
->ignore_unmaps
;
3768 if (xqueue_exists_local(find_destroy_unmap
, &find
))
3774 void client_set_wm_state(ObClient
*self
, glong state
)
3776 if (state
== self
->wmstate
) return; /* no change */
3780 client_iconify(self
, TRUE
, TRUE
, FALSE
);
3783 client_iconify(self
, FALSE
, TRUE
, FALSE
);
3788 void client_set_state(ObClient
*self
, Atom action
, glong data1
, glong data2
)
3790 gboolean shaded
= self
->shaded
;
3791 gboolean fullscreen
= self
->fullscreen
;
3792 gboolean undecorated
= self
->undecorated
;
3793 gboolean max_horz
= self
->max_horz
;
3794 gboolean max_vert
= self
->max_vert
;
3795 gboolean modal
= self
->modal
;
3796 gboolean iconic
= self
->iconic
;
3797 gboolean demands_attention
= self
->demands_attention
;
3798 gboolean above
= self
->above
;
3799 gboolean below
= self
->below
;
3803 if (!(action
== OBT_PROP_ATOM(NET_WM_STATE_ADD
) ||
3804 action
== OBT_PROP_ATOM(NET_WM_STATE_REMOVE
) ||
3805 action
== OBT_PROP_ATOM(NET_WM_STATE_TOGGLE
)))
3806 /* an invalid action was passed to the client message, ignore it */
3809 for (i
= 0; i
< 2; ++i
) {
3810 Atom state
= i
== 0 ? data1
: data2
;
3812 if (!state
) continue;
3814 /* if toggling, then pick whether we're adding or removing */
3815 if (action
== OBT_PROP_ATOM(NET_WM_STATE_TOGGLE
)) {
3816 if (state
== OBT_PROP_ATOM(NET_WM_STATE_MODAL
))
3818 else if (state
== OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_VERT
))
3819 value
= self
->max_vert
;
3820 else if (state
== OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_HORZ
))
3821 value
= self
->max_horz
;
3822 else if (state
== OBT_PROP_ATOM(NET_WM_STATE_SHADED
))
3824 else if (state
== OBT_PROP_ATOM(NET_WM_STATE_SKIP_TASKBAR
))
3825 value
= self
->skip_taskbar
;
3826 else if (state
== OBT_PROP_ATOM(NET_WM_STATE_SKIP_PAGER
))
3827 value
= self
->skip_pager
;
3828 else if (state
== OBT_PROP_ATOM(NET_WM_STATE_HIDDEN
))
3829 value
= self
->iconic
;
3830 else if (state
== OBT_PROP_ATOM(NET_WM_STATE_FULLSCREEN
))
3832 else if (state
== OBT_PROP_ATOM(NET_WM_STATE_ABOVE
))
3833 value
= self
->above
;
3834 else if (state
== OBT_PROP_ATOM(NET_WM_STATE_BELOW
))
3835 value
= self
->below
;
3836 else if (state
== OBT_PROP_ATOM(NET_WM_STATE_DEMANDS_ATTENTION
))
3837 value
= self
->demands_attention
;
3838 else if (state
== OBT_PROP_ATOM(OB_WM_STATE_UNDECORATED
))
3839 value
= undecorated
;
3841 g_assert_not_reached();
3842 action
= value
? OBT_PROP_ATOM(NET_WM_STATE_REMOVE
) :
3843 OBT_PROP_ATOM(NET_WM_STATE_ADD
);
3846 value
= action
== OBT_PROP_ATOM(NET_WM_STATE_ADD
);
3847 if (state
== OBT_PROP_ATOM(NET_WM_STATE_MODAL
)) {
3849 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_VERT
)) {
3851 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_HORZ
)) {
3853 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_SHADED
)) {
3855 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_SKIP_TASKBAR
)) {
3856 self
->skip_taskbar
= value
;
3857 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_SKIP_PAGER
)) {
3858 self
->skip_pager
= value
;
3859 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_HIDDEN
)) {
3861 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_FULLSCREEN
)) {
3863 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_ABOVE
)) {
3865 /* only unset below when setting above, otherwise you can't get to
3869 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_BELOW
)) {
3870 /* and vice versa */
3874 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_DEMANDS_ATTENTION
)){
3875 demands_attention
= value
;
3876 } else if (state
== OBT_PROP_ATOM(OB_WM_STATE_UNDECORATED
)) {
3877 undecorated
= value
;
3881 if (max_horz
!= self
->max_horz
|| max_vert
!= self
->max_vert
) {
3882 if (max_horz
!= self
->max_horz
&& max_vert
!= self
->max_vert
) {
3884 if (max_horz
== max_vert
) { /* both going the same way */
3885 client_maximize(self
, max_horz
, 0);
3887 client_maximize(self
, max_horz
, 1);
3888 client_maximize(self
, max_vert
, 2);
3892 if (max_horz
!= self
->max_horz
)
3893 client_maximize(self
, max_horz
, 1);
3895 client_maximize(self
, max_vert
, 2);
3898 /* change fullscreen state before shading, as it will affect if the window
3900 if (fullscreen
!= self
->fullscreen
)
3901 client_fullscreen(self
, fullscreen
);
3902 if (shaded
!= self
->shaded
)
3903 client_shade(self
, shaded
);
3904 if (undecorated
!= self
->undecorated
)
3905 client_set_undecorated(self
, undecorated
);
3906 if (above
!= self
->above
|| below
!= self
->below
) {
3907 self
->above
= above
;
3908 self
->below
= below
;
3909 client_calc_layer(self
);
3912 if (modal
!= self
->modal
) {
3913 self
->modal
= modal
;
3914 /* when a window changes modality, then its stacking order with its
3915 transients needs to change */
3916 stacking_raise(CLIENT_AS_WINDOW(self
));
3918 /* it also may get focused. if something is focused that shouldn't
3919 be focused anymore, then move the focus */
3920 if (focus_client
&& client_focus_target(focus_client
) != focus_client
)
3921 client_focus(focus_client
);
3924 if (iconic
!= self
->iconic
)
3925 client_iconify(self
, iconic
, FALSE
, FALSE
);
3927 if (demands_attention
!= self
->demands_attention
)
3928 client_hilite(self
, demands_attention
);
3930 client_change_state(self
); /* change the hint to reflect these changes */
3932 focus_cycle_addremove(self
, TRUE
);
3935 ObClient
*client_focus_target(ObClient
*self
)
3937 ObClient
*child
= NULL
;
3939 child
= client_search_modal_child(self
);
3940 if (child
) return child
;
3944 gboolean
client_can_focus(ObClient
*self
)
3946 /* choose the correct target */
3947 self
= client_focus_target(self
);
3949 if (!self
->frame
->visible
)
3952 if (!(self
->can_focus
|| self
->focus_notify
))
3958 gboolean
client_focus(ObClient
*self
)
3960 if (!client_validate(self
)) return FALSE
;
3962 /* we might not focus this window, so if we have modal children which would
3963 be focused instead, bring them to this desktop */
3964 client_bring_modal_windows(self
);
3966 /* choose the correct target */
3967 self
= client_focus_target(self
);
3969 if (!client_can_focus(self
)) {
3970 ob_debug_type(OB_DEBUG_FOCUS
,
3971 "Client %s can't be focused", self
->title
);
3975 /* if we have helper windows they should be there with the window */
3976 client_bring_helper_windows(self
);
3978 ob_debug_type(OB_DEBUG_FOCUS
,
3979 "Focusing client \"%s\" (0x%x) at time %u",
3980 self
->title
, self
->window
, event_time());
3982 /* if using focus_delay, stop the timer now so that focus doesn't
3984 event_halt_focus_delay();
3986 obt_display_ignore_errors(TRUE
);
3988 if (self
->can_focus
) {
3989 /* This can cause a BadMatch error with CurrentTime, or if an app
3990 passed in a bad time for _NET_WM_ACTIVE_WINDOW. */
3991 XSetInputFocus(obt_display
, self
->window
, RevertToPointerRoot
,
3995 if (self
->focus_notify
) {
3997 ce
.xclient
.type
= ClientMessage
;
3998 ce
.xclient
.message_type
= OBT_PROP_ATOM(WM_PROTOCOLS
);
3999 ce
.xclient
.display
= obt_display
;
4000 ce
.xclient
.window
= self
->window
;
4001 ce
.xclient
.format
= 32;
4002 ce
.xclient
.data
.l
[0] = OBT_PROP_ATOM(WM_TAKE_FOCUS
);
4003 ce
.xclient
.data
.l
[1] = event_time();
4004 ce
.xclient
.data
.l
[2] = 0l;
4005 ce
.xclient
.data
.l
[3] = 0l;
4006 ce
.xclient
.data
.l
[4] = 0l;
4007 XSendEvent(obt_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
4010 obt_display_ignore_errors(FALSE
);
4012 ob_debug_type(OB_DEBUG_FOCUS
, "Error focusing? %d",
4013 obt_display_error_occured
);
4014 return !obt_display_error_occured
;
4017 static void client_present(ObClient
*self
, gboolean here
, gboolean raise
,
4020 if (client_normal(self
) && screen_showing_desktop
)
4021 screen_show_desktop(FALSE
, self
);
4023 client_iconify(self
, FALSE
, here
, FALSE
);
4024 if (self
->desktop
!= DESKTOP_ALL
&&
4025 self
->desktop
!= screen_desktop
)
4028 client_set_desktop(self
, screen_desktop
, FALSE
, TRUE
);
4030 screen_set_desktop(self
->desktop
, FALSE
);
4031 } else if (!self
->frame
->visible
)
4032 /* if its not visible for other reasons, then don't mess
4035 if (self
->shaded
&& unshade
)
4036 client_shade(self
, FALSE
);
4038 stacking_raise(CLIENT_AS_WINDOW(self
));
4043 /* this function exists to map to the net_active_window message in the ewmh */
4044 void client_activate(ObClient
*self
, gboolean desktop
,
4045 gboolean here
, gboolean raise
,
4046 gboolean unshade
, gboolean user
)
4048 self
= client_focus_target(self
);
4050 if (client_can_steal_focus(self
, desktop
, user
, event_time(), CurrentTime
))
4051 client_present(self
, here
, raise
, unshade
);
4053 client_hilite(self
, TRUE
);
4056 static void client_bring_windows_recursive(ObClient
*self
,
4064 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
4065 client_bring_windows_recursive(it
->data
, desktop
,
4066 helpers
, modals
, iconic
);
4068 if (((helpers
&& client_helper(self
)) ||
4069 (modals
&& self
->modal
)) &&
4070 (!screen_compare_desktops(self
->desktop
, desktop
) ||
4071 (iconic
&& self
->iconic
)))
4073 if (iconic
&& self
->iconic
)
4074 client_iconify(self
, FALSE
, TRUE
, FALSE
);
4076 client_set_desktop(self
, desktop
, FALSE
, FALSE
);
4080 void client_bring_helper_windows(ObClient
*self
)
4082 client_bring_windows_recursive(self
, self
->desktop
, TRUE
, FALSE
, FALSE
);
4085 void client_bring_modal_windows(ObClient
*self
)
4087 client_bring_windows_recursive(self
, self
->desktop
, FALSE
, TRUE
, TRUE
);
4090 gboolean
client_focused(ObClient
*self
)
4092 return self
== focus_client
;
4095 RrImage
* client_icon(ObClient
*self
)
4097 RrImage
*ret
= NULL
;
4100 ret
= self
->icon_set
;
4101 else if (self
->parents
) {
4103 for (it
= self
->parents
; it
&& !ret
; it
= g_slist_next(it
))
4104 ret
= client_icon(it
->data
);
4107 ret
= client_default_icon
;
4111 void client_set_layer(ObClient
*self
, gint layer
)
4115 self
->above
= FALSE
;
4116 } else if (layer
== 0) {
4117 self
->below
= self
->above
= FALSE
;
4119 self
->below
= FALSE
;
4122 client_calc_layer(self
);
4123 client_change_state(self
); /* reflect this in the state hints */
4126 void client_set_undecorated(ObClient
*self
, gboolean undecorated
)
4128 if (self
->undecorated
!= undecorated
&&
4129 /* don't let it undecorate if the function is missing, but let
4131 (self
->functions
& OB_CLIENT_FUNC_UNDECORATE
|| !undecorated
))
4133 self
->undecorated
= undecorated
;
4134 client_setup_decor_and_functions(self
, TRUE
);
4135 client_change_state(self
); /* reflect this in the state hints */
4139 guint
client_monitor(ObClient
*self
)
4141 return screen_find_monitor(&self
->frame
->area
);
4144 ObClient
*client_direct_parent(ObClient
*self
)
4146 if (!self
->parents
) return NULL
;
4147 if (self
->transient_for_group
) return NULL
;
4148 return self
->parents
->data
;
4151 ObClient
*client_search_top_direct_parent(ObClient
*self
)
4154 while ((p
= client_direct_parent(self
))) self
= p
;
4158 static GSList
*client_search_all_top_parents_internal(ObClient
*self
,
4160 ObStackingLayer layer
)
4165 /* move up the direct transient chain as far as possible */
4166 while ((p
= client_direct_parent(self
)) &&
4167 (!bylayer
|| p
->layer
== layer
))
4171 ret
= g_slist_prepend(NULL
, self
);
4173 ret
= g_slist_copy(self
->parents
);
4178 GSList
*client_search_all_top_parents(ObClient
*self
)
4180 return client_search_all_top_parents_internal(self
, FALSE
, 0);
4183 GSList
*client_search_all_top_parents_layer(ObClient
*self
)
4185 return client_search_all_top_parents_internal(self
, TRUE
, self
->layer
);
4188 ObClient
*client_search_focus_parent(ObClient
*self
)
4192 for (it
= self
->parents
; it
; it
= g_slist_next(it
))
4193 if (client_focused(it
->data
)) return it
->data
;
4198 ObClient
*client_search_focus_parent_full(ObClient
*self
)
4201 ObClient
*ret
= NULL
;
4203 for (it
= self
->parents
; it
; it
= g_slist_next(it
)) {
4204 if (client_focused(it
->data
))
4207 ret
= client_search_focus_parent_full(it
->data
);
4213 ObClient
*client_search_parent(ObClient
*self
, ObClient
*search
)
4217 for (it
= self
->parents
; it
; it
= g_slist_next(it
))
4218 if (it
->data
== search
) return search
;
4223 ObClient
*client_search_transient(ObClient
*self
, ObClient
*search
)
4227 for (sit
= self
->transients
; sit
; sit
= g_slist_next(sit
)) {
4228 if (sit
->data
== search
)
4230 if (client_search_transient(sit
->data
, search
))
4236 static void detect_edge(Rect area
, ObDirection dir
,
4237 gint my_head
, gint my_size
,
4238 gint my_edge_start
, gint my_edge_size
,
4239 gint
*dest
, gboolean
*near_edge
)
4241 gint edge_start
, edge_size
, head
, tail
;
4242 gboolean skip_head
= FALSE
, skip_tail
= FALSE
;
4245 case OB_DIRECTION_NORTH
:
4246 case OB_DIRECTION_SOUTH
:
4247 edge_start
= area
.x
;
4248 edge_size
= area
.width
;
4250 case OB_DIRECTION_EAST
:
4251 case OB_DIRECTION_WEST
:
4252 edge_start
= area
.y
;
4253 edge_size
= area
.height
;
4256 g_assert_not_reached();
4259 /* do we collide with this window? */
4260 if (!RANGES_INTERSECT(my_edge_start
, my_edge_size
,
4261 edge_start
, edge_size
))
4265 case OB_DIRECTION_NORTH
:
4266 head
= RECT_BOTTOM(area
);
4267 tail
= RECT_TOP(area
);
4269 case OB_DIRECTION_SOUTH
:
4270 head
= RECT_TOP(area
);
4271 tail
= RECT_BOTTOM(area
);
4273 case OB_DIRECTION_WEST
:
4274 head
= RECT_RIGHT(area
);
4275 tail
= RECT_LEFT(area
);
4277 case OB_DIRECTION_EAST
:
4278 head
= RECT_LEFT(area
);
4279 tail
= RECT_RIGHT(area
);
4282 g_assert_not_reached();
4285 case OB_DIRECTION_NORTH
:
4286 case OB_DIRECTION_WEST
:
4287 /* check if our window is past the head of this window */
4288 if (my_head
<= head
+ 1)
4290 /* check if our window's tail is past the tail of this window */
4291 if (my_head
+ my_size
- 1 <= tail
)
4293 /* check if the head of this window is closer than the previously
4294 chosen edge (take into account that the previously chosen
4295 edge might have been a tail, not a head) */
4296 if (head
+ (*near_edge
? 0 : my_size
) <= *dest
)
4298 /* check if the tail of this window is closer than the previously
4299 chosen edge (take into account that the previously chosen
4300 edge might have been a head, not a tail) */
4301 if (tail
- (!*near_edge
? 0 : my_size
) <= *dest
)
4304 case OB_DIRECTION_SOUTH
:
4305 case OB_DIRECTION_EAST
:
4306 /* check if our window is past the head of this window */
4307 if (my_head
>= head
- 1)
4309 /* check if our window's tail is past the tail of this window */
4310 if (my_head
- my_size
+ 1 >= tail
)
4312 /* check if the head of this window is closer than the previously
4313 chosen edge (take into account that the previously chosen
4314 edge might have been a tail, not a head) */
4315 if (head
- (*near_edge
? 0 : my_size
) >= *dest
)
4317 /* check if the tail of this window is closer than the previously
4318 chosen edge (take into account that the previously chosen
4319 edge might have been a head, not a tail) */
4320 if (tail
+ (!*near_edge
? 0 : my_size
) >= *dest
)
4324 g_assert_not_reached();
4327 ob_debug("my head %d size %d", my_head
, my_size
);
4328 ob_debug("head %d tail %d dest %d", head
, tail
, *dest
);
4330 ob_debug("using near edge %d", head
);
4334 else if (!skip_tail
) {
4335 ob_debug("using far edge %d", tail
);
4341 void client_find_edge_directional(ObClient
*self
, ObDirection dir
,
4342 gint my_head
, gint my_size
,
4343 gint my_edge_start
, gint my_edge_size
,
4344 gint
*dest
, gboolean
*near_edge
)
4352 a
= screen_area(self
->desktop
, SCREEN_AREA_ALL_MONITORS
,
4353 &self
->frame
->area
);
4356 case OB_DIRECTION_NORTH
:
4357 edge
= RECT_TOP(*a
) - 1;
4359 case OB_DIRECTION_SOUTH
:
4360 edge
= RECT_BOTTOM(*a
) + 1;
4362 case OB_DIRECTION_EAST
:
4363 edge
= RECT_RIGHT(*a
) + 1;
4365 case OB_DIRECTION_WEST
:
4366 edge
= RECT_LEFT(*a
) - 1;
4369 g_assert_not_reached();
4371 /* default to the far edge, then narrow it down */
4375 /* search for edges of monitors */
4376 for (i
= 0; i
< screen_num_monitors
; ++i
) {
4377 Rect
*area
= screen_area(self
->desktop
, i
, NULL
);
4378 detect_edge(*area
, dir
, my_head
, my_size
, my_edge_start
,
4379 my_edge_size
, dest
, near_edge
);
4380 g_slice_free(Rect
, area
);
4383 /* search for edges of clients */
4384 for (it
= client_list
; it
; it
= g_list_next(it
)) {
4385 ObClient
*cur
= it
->data
;
4387 /* skip windows to not bump into */
4392 if (self
->desktop
!= cur
->desktop
&& cur
->desktop
!= DESKTOP_ALL
&&
4393 cur
->desktop
!= screen_desktop
)
4396 ob_debug("trying window %s", cur
->title
);
4398 detect_edge(cur
->frame
->area
, dir
, my_head
, my_size
, my_edge_start
,
4399 my_edge_size
, dest
, near_edge
);
4401 dock_get_area(&dock_area
);
4402 detect_edge(dock_area
, dir
, my_head
, my_size
, my_edge_start
,
4403 my_edge_size
, dest
, near_edge
);
4405 g_slice_free(Rect
, a
);
4408 void client_find_move_directional(ObClient
*self
, ObDirection dir
,
4412 gint e
, e_start
, e_size
;
4416 case OB_DIRECTION_EAST
:
4417 head
= RECT_RIGHT(self
->frame
->area
);
4418 size
= self
->frame
->area
.width
;
4419 e_start
= RECT_TOP(self
->frame
->area
);
4420 e_size
= self
->frame
->area
.height
;
4422 case OB_DIRECTION_WEST
:
4423 head
= RECT_LEFT(self
->frame
->area
);
4424 size
= self
->frame
->area
.width
;
4425 e_start
= RECT_TOP(self
->frame
->area
);
4426 e_size
= self
->frame
->area
.height
;
4428 case OB_DIRECTION_NORTH
:
4429 head
= RECT_TOP(self
->frame
->area
);
4430 size
= self
->frame
->area
.height
;
4431 e_start
= RECT_LEFT(self
->frame
->area
);
4432 e_size
= self
->frame
->area
.width
;
4434 case OB_DIRECTION_SOUTH
:
4435 head
= RECT_BOTTOM(self
->frame
->area
);
4436 size
= self
->frame
->area
.height
;
4437 e_start
= RECT_LEFT(self
->frame
->area
);
4438 e_size
= self
->frame
->area
.width
;
4441 g_assert_not_reached();
4444 client_find_edge_directional(self
, dir
, head
, size
,
4445 e_start
, e_size
, &e
, &near
);
4446 *x
= self
->frame
->area
.x
;
4447 *y
= self
->frame
->area
.y
;
4449 case OB_DIRECTION_EAST
:
4450 if (near
) e
-= self
->frame
->area
.width
;
4454 case OB_DIRECTION_WEST
:
4456 else e
-= self
->frame
->area
.width
;
4459 case OB_DIRECTION_NORTH
:
4461 else e
-= self
->frame
->area
.height
;
4464 case OB_DIRECTION_SOUTH
:
4465 if (near
) e
-= self
->frame
->area
.height
;
4470 g_assert_not_reached();
4472 frame_frame_gravity(self
->frame
, x
, y
);
4475 void client_find_resize_directional(ObClient
*self
, ObDirection side
,
4477 gint
*x
, gint
*y
, gint
*w
, gint
*h
)
4480 gint e
, e_start
, e_size
, delta
;
4485 case OB_DIRECTION_EAST
:
4486 head
= RECT_RIGHT(self
->frame
->area
) +
4487 (self
->size_inc
.width
- 1) * (grow
? 1 : 0);
4488 e_start
= RECT_TOP(self
->frame
->area
);
4489 e_size
= self
->frame
->area
.height
;
4490 dir
= grow
? OB_DIRECTION_EAST
: OB_DIRECTION_WEST
;
4492 case OB_DIRECTION_WEST
:
4493 head
= RECT_LEFT(self
->frame
->area
) -
4494 (self
->size_inc
.width
- 1) * (grow
? 1 : 0);
4495 e_start
= RECT_TOP(self
->frame
->area
);
4496 e_size
= self
->frame
->area
.height
;
4497 dir
= grow
? OB_DIRECTION_WEST
: OB_DIRECTION_EAST
;
4499 case OB_DIRECTION_NORTH
:
4500 head
= RECT_TOP(self
->frame
->area
) -
4501 (self
->size_inc
.height
- 1) * (grow
? 1 : 0);
4502 e_start
= RECT_LEFT(self
->frame
->area
);
4503 e_size
= self
->frame
->area
.width
;
4504 dir
= grow
? OB_DIRECTION_NORTH
: OB_DIRECTION_SOUTH
;
4506 case OB_DIRECTION_SOUTH
:
4507 head
= RECT_BOTTOM(self
->frame
->area
) +
4508 (self
->size_inc
.height
- 1) * (grow
? 1 : 0);
4509 e_start
= RECT_LEFT(self
->frame
->area
);
4510 e_size
= self
->frame
->area
.width
;
4511 dir
= grow
? OB_DIRECTION_SOUTH
: OB_DIRECTION_NORTH
;
4514 g_assert_not_reached();
4517 ob_debug("head %d dir %d", head
, dir
);
4518 client_find_edge_directional(self
, dir
, head
, 1,
4519 e_start
, e_size
, &e
, &near
);
4520 ob_debug("edge %d", e
);
4521 *x
= self
->frame
->area
.x
;
4522 *y
= self
->frame
->area
.y
;
4523 *w
= self
->frame
->area
.width
;
4524 *h
= self
->frame
->area
.height
;
4526 case OB_DIRECTION_EAST
:
4527 if (grow
== near
) --e
;
4528 delta
= e
- RECT_RIGHT(self
->frame
->area
);
4531 case OB_DIRECTION_WEST
:
4532 if (grow
== near
) ++e
;
4533 delta
= RECT_LEFT(self
->frame
->area
) - e
;
4537 case OB_DIRECTION_NORTH
:
4538 if (grow
== near
) ++e
;
4539 delta
= RECT_TOP(self
->frame
->area
) - e
;
4543 case OB_DIRECTION_SOUTH
:
4544 if (grow
== near
) --e
;
4545 delta
= e
- RECT_BOTTOM(self
->frame
->area
);
4549 g_assert_not_reached();
4551 frame_frame_gravity(self
->frame
, x
, y
);
4552 *w
-= self
->frame
->size
.left
+ self
->frame
->size
.right
;
4553 *h
-= self
->frame
->size
.top
+ self
->frame
->size
.bottom
;
4556 ObClient
* client_under_pointer(void)
4560 ObClient
*ret
= NULL
;
4562 if (screen_pointer_pos(&x
, &y
)) {
4563 for (it
= stacking_list
; it
; it
= g_list_next(it
)) {
4564 if (WINDOW_IS_CLIENT(it
->data
)) {
4565 ObClient
*c
= WINDOW_AS_CLIENT(it
->data
);
4566 if (c
->frame
->visible
&&
4567 /* check the desktop, this is done during desktop
4568 switching and windows are shown/hidden status is not
4570 (c
->desktop
== screen_desktop
||
4571 c
->desktop
== DESKTOP_ALL
) &&
4572 /* ignore all animating windows */
4573 !frame_iconify_animating(c
->frame
) &&
4574 RECT_CONTAINS(c
->frame
->area
, x
, y
))
4585 gboolean
client_has_group_siblings(ObClient
*self
)
4587 return self
->group
&& self
->group
->members
->next
;
4590 gboolean
client_has_relative(ObClient
*self
)
4592 return client_has_parent(self
) ||
4593 client_has_group_siblings(self
) ||
4594 client_has_children(self
);
4597 /*! Returns TRUE if the client is running on the same machine as Openbox */
4598 gboolean
client_on_localhost(ObClient
*self
)
4600 return self
->client_machine
== NULL
;