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_remove_destroy_notify_data(ObClientCallback func
, gpointer data
)
174 for (it
= client_destroy_notifies
; it
; it
= g_slist_next(it
)) {
175 ClientCallback
*d
= it
->data
;
176 if (d
->func
== func
&& d
->data
== data
) {
177 g_slice_free(ClientCallback
, d
);
178 client_destroy_notifies
=
179 g_slist_delete_link(client_destroy_notifies
, it
);
185 void client_set_list(void)
187 Window
*windows
, *win_it
;
189 guint size
= g_list_length(client_list
);
191 /* create an array of the window ids */
193 windows
= g_new(Window
, size
);
195 for (it
= client_list
; it
; it
= g_list_next(it
), ++win_it
)
196 *win_it
= ((ObClient
*)it
->data
)->window
;
200 OBT_PROP_SETA32(obt_root(ob_screen
), NET_CLIENT_LIST
, WINDOW
,
201 (gulong
*)windows
, size
);
209 void client_manage(Window window
, ObPrompt
*prompt
)
212 XSetWindowAttributes attrib_set
;
213 gboolean try_activate
= FALSE
;
214 gboolean do_activate
;
215 ObAppSettings
*settings
;
216 gboolean transient
= FALSE
;
223 ob_debug("Managing window: 0x%lx", window
);
225 /* choose the events we want to receive on the CLIENT window
226 (ObPrompt windows can request events too) */
227 attrib_set
.event_mask
= CLIENT_EVENTMASK
|
228 (prompt
? prompt
->event_mask
: 0);
229 attrib_set
.do_not_propagate_mask
= CLIENT_NOPROPAGATEMASK
;
230 XChangeWindowAttributes(obt_display
, window
,
231 CWEventMask
|CWDontPropagate
, &attrib_set
);
233 /* create the ObClient struct, and populate it from the hints on the
235 self
= g_slice_new0(ObClient
);
236 self
->obwin
.type
= OB_WINDOW_CLASS_CLIENT
;
237 self
->window
= window
;
238 self
->prompt
= prompt
;
239 self
->managed
= TRUE
;
241 /* non-zero defaults */
242 self
->wmstate
= WithdrawnState
; /* make sure it gets updated first time */
243 self
->gravity
= NorthWestGravity
;
244 self
->desktop
= screen_num_desktops
; /* always an invalid value */
246 /* get all the stuff off the window */
247 client_get_all(self
, TRUE
);
249 ob_debug("Window type: %d", self
->type
);
250 ob_debug("Window group: 0x%x", self
->group
?self
->group
->leader
:0);
251 ob_debug("Window name: %s class: %s role: %s title: %s",
252 self
->name
, self
->class, self
->role
, self
->title
);
253 ob_debug("Window group name: %s group class: %s",
254 self
->group_name
, self
->group_class
);
256 /* per-app settings override stuff from client_get_all, and return the
257 settings for other uses too. the returned settings is a shallow copy,
258 that needs to be freed with g_free(). */
259 settings
= client_get_settings_state(self
);
261 /* the session should get the last say though */
262 client_restore_session_state(self
);
264 /* the per-app settings/session may have changed the decorations for
265 the window, so we setup decorations for that here. this is a special
266 case because we want to place the window according to these decoration
268 we do this before setting up the frame so that it will reflect the
269 decorations of the window as it will be placed on screen.
271 client_setup_decor_undecorated(self
);
273 /* specify that if we exit, the window should not be destroyed and
274 should be reparented back to root automatically, unless we are managing
275 an internal ObPrompt window */
277 XChangeSaveSet(obt_display
, window
, SetModeInsert
);
279 /* create the decoration frame for the client window */
280 self
->frame
= frame_new(self
);
282 frame_grab_client(self
->frame
);
284 /* we've grabbed everything and set everything that we need to at mapping
288 /* this needs to occur once we have a frame, since it sets a property on
290 client_update_opacity(self
);
292 /* don't put helper/modal windows on a different desktop if they are
293 related to the focused window. */
294 if (!screen_compare_desktops(self
->desktop
, screen_desktop
) &&
295 focus_client
&& client_search_transient(focus_client
, self
) &&
296 (client_helper(self
) || self
->modal
))
298 self
->desktop
= screen_desktop
;
301 /* tell startup notification that this app started */
302 launch_time
= sn_app_started(self
->startup_id
, self
->class, self
->name
);
304 if (!OBT_PROP_GET32(self
->window
, NET_WM_USER_TIME
, CARDINAL
, &user_time
))
305 user_time
= event_time();
307 /* do this after we have a frame.. it uses the frame to help determine the
308 WM_STATE to apply. */
309 client_change_state(self
);
311 /* add ourselves to the focus order */
312 focus_order_add_new(self
);
314 /* do this to add ourselves to the stacking list in a non-intrusive way */
315 client_calc_layer(self
);
317 /* focus the new window? */
318 if (ob_state() != OB_STATE_STARTING
&&
319 (!self
->session
|| self
->session
->focused
) &&
320 /* this means focus=true for window is same as config_focus_new=true */
321 ((config_focus_new
|| settings
->focus
== 1) ||
322 client_search_focus_tree_full(self
)) &&
323 /* NET_WM_USER_TIME 0 when mapping means don't focus */
325 /* this checks for focus=false for the window */
326 settings
->focus
!= 0 &&
327 focus_valid_target(self
, self
->desktop
,
328 FALSE
, FALSE
, TRUE
, TRUE
, FALSE
, FALSE
,
329 settings
->focus
== 1))
334 /* remove the client's border */
335 XSetWindowBorderWidth(obt_display
, self
->window
, 0);
337 /* adjust the frame to the client's size before showing or placing
339 frame_adjust_area(self
->frame
, FALSE
, TRUE
, FALSE
);
340 frame_adjust_client_area(self
->frame
);
342 /* where the frame was placed is where the window was originally */
345 ob_debug("Going to try activate new window? %s",
346 try_activate
? "yes" : "no");
348 do_activate
= client_can_steal_focus(
349 self
, settings
->focus
== 1,
350 (!!launch_time
|| settings
->focus
== 1),
351 event_time(), launch_time
);
355 /* figure out placement for the window if the window is new */
356 if (ob_state() == OB_STATE_RUNNING
) {
357 ob_debug("Positioned: %s @ %d %d",
358 (!self
->positioned
? "no" :
359 (self
->positioned
== PPosition
? "program specified" :
360 (self
->positioned
== USPosition
? "user specified" :
361 (self
->positioned
== (PPosition
| USPosition
) ?
362 "program + user specified" :
363 "BADNESS !?")))), place
.x
, place
.y
);
365 ob_debug("Sized: %s @ %d %d",
366 (!self
->sized
? "no" :
367 (self
->sized
== PSize
? "program specified" :
368 (self
->sized
== USSize
? "user specified" :
369 (self
->sized
== (PSize
| USSize
) ?
370 "program + user specified" :
371 "BADNESS !?")))), place
.width
, place
.height
);
373 obplaced
= place_client(self
, do_activate
, &place
.x
, &place
.y
,
376 /* watch for buggy apps that ask to be placed at (0,0) when there is
378 if (!obplaced
&& place
.x
== 0 && place
.y
== 0 &&
379 /* non-normal windows are allowed */
380 client_normal(self
) &&
381 /* oldschool fullscreen windows are allowed */
382 !client_is_oldfullscreen(self
, &place
))
386 r
= screen_area(self
->desktop
, SCREEN_AREA_ALL_MONITORS
, NULL
);
390 ob_debug("Moving buggy app from (0,0) to (%d,%d)", r
->x
, r
->y
);
392 g_slice_free(Rect
, r
);
395 /* make sure the window is visible. */
396 client_find_onscreen(self
, &place
.x
, &place
.y
,
397 place
.width
, place
.height
,
398 /* non-normal clients has less rules, and
399 windows that are being restored from a
400 session do also. we can assume you want
401 it back where you saved it. Clients saying
402 they placed themselves are subjected to
403 harder rules, ones that are placed by
404 place.c or by the user are allowed partially
405 off-screen and on xinerama divides (ie,
406 it is up to the placement routines to avoid
407 the xinerama divides)
409 children and splash screens are forced on
410 screen, but i don't remember why i decided to
413 ob_state() == OB_STATE_RUNNING
&&
414 (self
->type
== OB_CLIENT_TYPE_DIALOG
||
415 self
->type
== OB_CLIENT_TYPE_SPLASH
||
416 (!((self
->positioned
& USPosition
) ||
417 settings
->pos_given
) &&
418 client_normal(self
) &&
420 /* don't move oldschool fullscreen windows to
421 fit inside the struts (fixes Acroread, which
422 makes its fullscreen window fit the screen
423 but it is not USSize'd or USPosition'd) */
424 !client_is_oldfullscreen(self
, &place
))));
427 /* if the window isn't user-sized, then make it fit inside
428 the visible screen area on its monitor. Use basically the same rules
429 for forcing the window on screen in the client_find_onscreen call.
431 do this after place_client, it chooses the monitor!
433 splash screens get "transient" set to TRUE by
434 the place_client call
436 if (ob_state() == OB_STATE_RUNNING
&&
438 (!(self
->sized
& USSize
|| self
->positioned
& USPosition
) &&
439 client_normal(self
) &&
441 /* don't shrink oldschool fullscreen windows to fit inside the
442 struts (fixes Acroread, which makes its fullscreen window
443 fit the screen but it is not USSize'd or USPosition'd) */
444 !client_is_oldfullscreen(self
, &place
))))
446 Rect
*a
= screen_area(self
->desktop
, SCREEN_AREA_ONE_MONITOR
, &place
);
448 /* get the size of the frame */
449 place
.width
+= self
->frame
->size
.left
+ self
->frame
->size
.right
;
450 place
.height
+= self
->frame
->size
.top
+ self
->frame
->size
.bottom
;
452 /* fit the window inside the area */
453 place
.width
= MIN(place
.width
, a
->width
);
454 place
.height
= MIN(place
.height
, a
->height
);
456 ob_debug("setting window size to %dx%d", place
.width
, place
.height
);
458 /* get the size of the client back */
459 place
.width
-= self
->frame
->size
.left
+ self
->frame
->size
.right
;
460 place
.height
-= self
->frame
->size
.top
+ self
->frame
->size
.bottom
;
462 g_slice_free(Rect
, a
);
465 ob_debug("placing window 0x%x at %d, %d with size %d x %d. "
466 "some restrictions may apply",
467 self
->window
, place
.x
, place
.y
, place
.width
, place
.height
);
469 ob_debug(" but session requested %d, %d %d x %d instead, "
471 self
->session
->x
, self
->session
->y
,
472 self
->session
->w
, self
->session
->h
);
474 /* do this after the window is placed, so the premax/prefullscreen numbers
477 this also places the window
479 client_apply_startup_state(self
, place
.x
, place
.y
,
480 place
.width
, place
.height
);
482 /* set the initial value of the desktop hint, when one wasn't requested
484 OBT_PROP_SET32(self
->window
, NET_WM_DESKTOP
, CARDINAL
, self
->desktop
);
486 /* grab mouse bindings before showing the window */
487 mouse_grab_for_client(self
, TRUE
);
489 if (!config_focus_under_mouse
)
490 ignore_start
= event_start_ignore_all_enters();
492 /* this has to happen before we try focus the window, but we want it to
493 happen after the client's stacking has been determined or it looks bad
497 /* activate/hilight/raise the window */
500 gboolean stacked
= client_restore_session_stacking(self
);
501 client_present(self
, FALSE
, !stacked
, TRUE
);
504 /* if the client isn't stealing focus, then hilite it so the user
505 knows it is there, but don't do this if we're restoring from a
507 if (!client_restore_session_stacking(self
))
508 client_hilite(self
, TRUE
);
512 /* This may look rather odd. Well it's because new windows are added
513 to the stacking order non-intrusively. If we're not going to focus
514 the new window or hilite it, then we raise it to the top. This will
515 take affect for things that don't get focused like splash screens.
516 Also if you don't have focus_new enabled, then it's going to get
517 raised to the top. Legacy begets legacy I guess?
519 if (!client_restore_session_stacking(self
))
520 stacking_raise(CLIENT_AS_WINDOW(self
));
523 if (!config_focus_under_mouse
)
524 event_end_ignore_all_enters(ignore_start
);
526 /* add to client list/map */
527 client_list
= g_list_append(client_list
, self
);
528 window_add(&self
->window
, CLIENT_AS_WINDOW(self
));
530 /* this has to happen after we're in the client_list */
531 if (STRUT_EXISTS(self
->strut
))
532 screen_update_areas();
534 /* update the list hints */
537 /* free the ObAppSettings shallow copy */
538 g_slice_free(ObAppSettings
, settings
);
540 ob_debug("Managed window 0x%lx plate 0x%x (%s)",
541 window
, self
->frame
->window
, self
->class);
544 ObClient
*client_fake_manage(Window window
)
547 ObAppSettings
*settings
;
549 ob_debug("Pretend-managing window: %lx", window
);
551 /* do this minimal stuff to figure out the client's decorations */
553 self
= g_slice_new0(ObClient
);
554 self
->window
= window
;
556 client_get_all(self
, FALSE
);
557 /* per-app settings override stuff, and return the settings for other
558 uses too. this returns a shallow copy that needs to be freed */
559 settings
= client_get_settings_state(self
);
561 /* create the decoration frame for the client window and adjust its size */
562 self
->frame
= frame_new(self
);
564 client_apply_startup_state(self
, self
->area
.x
, self
->area
.y
,
565 self
->area
.width
, self
->area
.height
);
567 ob_debug("gave extents left %d right %d top %d bottom %d",
568 self
->frame
->size
.left
, self
->frame
->size
.right
,
569 self
->frame
->size
.top
, self
->frame
->size
.bottom
);
571 /* free the ObAppSettings shallow copy */
572 g_slice_free(ObAppSettings
, settings
);
577 void client_unmanage_all(void)
580 client_unmanage(client_list
->data
);
583 void client_unmanage(ObClient
*self
)
588 ob_debug("Unmanaging window: 0x%x plate 0x%x (%s) (%s)",
589 self
->window
, self
->frame
->window
,
590 self
->class, self
->title
? self
->title
: "");
592 g_assert(self
!= NULL
);
594 /* we dont want events no more. do this before hiding the frame so we
595 don't generate more events */
596 XSelectInput(obt_display
, self
->window
, NoEventMask
);
598 /* ignore enter events from the unmap so it doesnt mess with the focus */
599 if (!config_focus_under_mouse
)
600 ignore_start
= event_start_ignore_all_enters();
602 frame_hide(self
->frame
);
603 /* flush to send the hide to the server quickly */
606 if (!config_focus_under_mouse
)
607 event_end_ignore_all_enters(ignore_start
);
609 mouse_grab_for_client(self
, FALSE
);
611 self
->managed
= FALSE
;
613 /* remove the window from our save set, unless we are managing an internal
616 XChangeSaveSet(obt_display
, self
->window
, SetModeDelete
);
618 /* update the focus lists */
619 focus_order_remove(self
);
620 if (client_focused(self
)) {
621 /* don't leave an invalid focus_client */
625 /* if we're prompting to kill the client, close that */
626 prompt_unref(self
->kill_prompt
);
627 self
->kill_prompt
= NULL
;
629 client_list
= g_list_remove(client_list
, self
);
630 stacking_remove(self
);
631 window_remove(self
->window
);
633 /* once the client is out of the list, update the struts to remove its
635 if (STRUT_EXISTS(self
->strut
))
636 screen_update_areas();
638 client_call_notifies(self
, client_destroy_notifies
);
640 /* tell our parent(s) that we're gone */
641 for (it
= self
->parents
; it
; it
= g_slist_next(it
))
642 ((ObClient
*)it
->data
)->transients
=
643 g_slist_remove(((ObClient
*)it
->data
)->transients
,self
);
645 /* tell our transients that we're gone */
646 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
647 ((ObClient
*)it
->data
)->parents
=
648 g_slist_remove(((ObClient
*)it
->data
)->parents
, self
);
649 /* we could be keeping our children in a higher layer */
650 client_calc_layer(it
->data
);
653 /* remove from its group */
655 group_remove(self
->group
, self
);
659 /* restore the window's original geometry so it is not lost */
665 if (self
->fullscreen
)
666 a
= self
->pre_fullscreen_area
;
667 else if (self
->max_horz
|| self
->max_vert
) {
668 if (self
->max_horz
) {
669 a
.x
= self
->pre_max_area
.x
;
670 a
.width
= self
->pre_max_area
.width
;
672 if (self
->max_vert
) {
673 a
.y
= self
->pre_max_area
.y
;
674 a
.height
= self
->pre_max_area
.height
;
678 self
->fullscreen
= self
->max_horz
= self
->max_vert
= FALSE
;
679 /* let it be moved and resized no matter what */
680 self
->functions
= OB_CLIENT_FUNC_MOVE
| OB_CLIENT_FUNC_RESIZE
;
681 self
->decorations
= 0; /* unmanaged windows have no decor */
683 /* give the client its border back */
684 XSetWindowBorderWidth(obt_display
, self
->window
, self
->border_width
);
686 client_move_resize(self
, a
.x
, a
.y
, a
.width
, a
.height
);
689 /* reparent the window out of the frame, and free the frame */
690 frame_release_client(self
->frame
);
691 frame_free(self
->frame
);
694 if (ob_state() != OB_STATE_EXITING
) {
695 /* these values should not be persisted across a window
697 OBT_PROP_ERASE(self
->window
, NET_WM_DESKTOP
);
698 OBT_PROP_ERASE(self
->window
, NET_WM_STATE
);
699 OBT_PROP_ERASE(self
->window
, WM_STATE
);
701 /* if we're left in an unmapped state, the client wont be mapped.
702 this is bad, since we will no longer be managing the window on
704 XMapWindow(obt_display
, self
->window
);
707 /* these should not be left on the window ever. other window managers
708 don't necessarily use them and it will mess them up (like compiz) */
709 OBT_PROP_ERASE(self
->window
, NET_WM_VISIBLE_NAME
);
710 OBT_PROP_ERASE(self
->window
, NET_WM_VISIBLE_ICON_NAME
);
712 /* update the list hints */
715 ob_debug("Unmanaged window 0x%lx", self
->window
);
717 /* free all data allocated in the client struct */
718 RrImageUnref(self
->icon_set
);
719 g_slist_free(self
->transients
);
720 g_free(self
->startup_id
);
721 g_free(self
->wm_command
);
723 g_free(self
->icon_title
);
724 g_free(self
->original_title
);
728 g_free(self
->group_name
);
729 g_free(self
->group_class
);
730 g_free(self
->client_machine
);
731 g_free(self
->sm_client_id
);
732 g_slice_free(ObClient
, self
);
735 void client_fake_unmanage(ObClient
*self
)
737 /* this is all that got allocated to get the decorations */
739 frame_free(self
->frame
);
740 g_slice_free(ObClient
, self
);
743 static gboolean
client_can_steal_focus(ObClient
*self
,
744 gboolean allow_other_desktop
,
745 gboolean request_from_user
,
750 gboolean relative_focused
;
754 relative_focused
= (focus_client
!= NULL
&&
755 (client_search_focus_tree_full(self
) != NULL
||
756 client_search_focus_group_full(self
) != NULL
));
758 /* This is focus stealing prevention */
759 ob_debug("Want to focus window 0x%x at time %u "
760 "launched at %u (last user interaction time %u) "
761 "request from %s, allow other desktop: %s, "
762 "desktop switch time %u",
763 self
->window
, steal_time
, launch_time
,
764 event_last_user_time
,
765 (request_from_user
? "user" : "other"),
766 (allow_other_desktop
? "yes" : "no"),
767 screen_desktop_user_time
);
770 if no launch time is provided for an application, make one up.
772 if the window is related to other existing windows
773 and one of those windows was the last used
774 then we will give it a launch time equal to the last user time,
775 which will end up giving the window focus probably.
777 the window is related to other windows, but you are not working in
779 seems suspicious, so we will give it a launch time of
780 NOW - STEAL_INTERVAL,
781 so it will be given focus only if we didn't use something else
782 during the steal interval.
784 the window is all on its own, so we can't judge it. give it a launch
785 time equal to the last user time, so it will probably take focus.
787 this way running things from a terminal will give them focus, but popups
788 without a launch time shouldn't steal focus so easily.
792 if (client_has_relative(self
)) {
793 if (event_last_user_time
&& client_search_focus_group_full(self
)) {
794 /* our relative is focused */
795 launch_time
= event_last_user_time
;
796 ob_debug("Unknown launch time, using %u - window in active "
797 "group", launch_time
);
799 else if (!request_from_user
) {
800 /* has relatives which are not being used. suspicious */
801 launch_time
= event_time() - OB_EVENT_USER_TIME_DELAY
;
802 ob_debug("Unknown launch time, using %u - window in inactive "
803 "group", launch_time
);
806 /* has relatives which are not being used, but the user seems
807 to want to go there! */
808 launch_time
= event_last_user_time
;
809 ob_debug("Unknown launch time, using %u - user request",
814 /* the window is on its own, probably the user knows it is going
816 launch_time
= event_last_user_time
;
817 ob_debug("Unknown launch time, using %u - independent window",
822 /* if it's on another desktop
823 and if allow_other_desktop is true, we generally let it steal focus.
824 but if it didn't come from the user, don't let it steal unless it was
825 launched before the user switched desktops.
826 focus, unless it was launched after we changed desktops and the request
829 if (!screen_compare_desktops(screen_desktop
, self
->desktop
)) {
830 /* must be allowed */
831 if (!allow_other_desktop
) {
833 ob_debug("Not focusing the window because its on another desktop");
835 /* if we don't know when the desktop changed, but request is from an
836 application, don't let it change desktop on you */
837 else if (!request_from_user
) {
839 ob_debug("Not focusing the window because non-user request");
842 /* If something is focused... */
843 else if (focus_client
) {
844 /* If the user is working in another window right now, then don't
846 if (!relative_focused
&&
847 event_last_user_time
&&
848 /* last user time must be strictly > launch_time to block focus */
849 (event_time_after(event_last_user_time
, launch_time
) &&
850 event_last_user_time
!= launch_time
) &&
851 event_time_after(event_last_user_time
,
852 steal_time
- OB_EVENT_USER_TIME_DELAY
))
855 ob_debug("Not focusing the window because the user is "
856 "working in another window that is not its relative");
858 /* Don't move focus if it's not going to go to this window
860 else if (client_focus_target(self
) != self
) {
862 ob_debug("Not focusing the window because another window "
863 "would get the focus anyway");
865 /* For requests that don't come from the user */
866 else if (!request_from_user
) {
867 /* If the new window is a transient (and its relatives aren't
869 if (client_has_parent(self
) && !relative_focused
) {
871 ob_debug("Not focusing the window because it is a "
872 "transient, and its relatives aren't focused");
874 /* Don't steal focus from globally active clients.
875 I stole this idea from KWin. It seems nice.
877 else if (!(focus_client
->can_focus
|| focus_client
->focus_notify
))
880 ob_debug("Not focusing the window because a globally "
881 "active client has focus");
883 /* Don't move focus if the window is not visible on the current
884 desktop and none of its relatives are focused */
885 else if (!allow_other_desktop
&&
886 !screen_compare_desktops(self
->desktop
, screen_desktop
) &&
890 ob_debug("Not focusing the window because it is on "
891 "another desktop and no relatives are focused ");
897 ob_debug("Focus stealing prevention activated for %s at "
898 "time %u (last user interaction time %u)",
899 self
->title
, steal_time
, event_last_user_time
);
901 ob_debug("Allowing focus stealing for %s at time %u (last user "
902 "interaction time %u)",
903 self
->title
, steal_time
, event_last_user_time
);
907 /*! Returns a new structure containing the per-app settings for this client.
908 The returned structure needs to be freed with g_free. */
909 static ObAppSettings
*client_get_settings_state(ObClient
*self
)
911 ObAppSettings
*settings
;
914 settings
= config_create_app_settings();
916 for (it
= config_per_app_settings
; it
; it
= g_slist_next(it
)) {
917 ObAppSettings
*app
= it
->data
;
918 gboolean match
= TRUE
;
920 g_assert(app
->name
!= NULL
|| app
->class != NULL
||
921 app
->role
!= NULL
|| app
->title
!= NULL
||
922 app
->group_name
!= NULL
|| app
->group_class
!= NULL
||
923 (signed)app
->type
>= 0);
926 !g_pattern_match(app
->name
, strlen(self
->name
), self
->name
, NULL
))
928 else if (app
->group_name
&&
929 !g_pattern_match(app
->group_name
,
930 strlen(self
->group_name
), self
->group_name
, NULL
))
932 else if (app
->class &&
933 !g_pattern_match(app
->class,
934 strlen(self
->class), self
->class, NULL
))
936 else if (app
->group_class
&&
937 !g_pattern_match(app
->group_class
,
938 strlen(self
->group_class
), self
->group_class
,
941 else if (app
->role
&&
942 !g_pattern_match(app
->role
,
943 strlen(self
->role
), self
->role
, NULL
))
945 else if (app
->title
&&
946 !g_pattern_match(app
->title
,
947 strlen(self
->title
), self
->title
, NULL
))
949 else if ((signed)app
->type
>= 0 && app
->type
!= self
->type
) {
954 ob_debug("Window matching: %s", app
->name
);
956 /* copy the settings to our struct, overriding the existing
957 settings if they are not defaults */
958 config_app_settings_copy_non_defaults(app
, settings
);
962 if (settings
->shade
!= -1)
963 self
->shaded
= !!settings
->shade
;
964 if (settings
->decor
!= -1)
965 self
->undecorated
= !settings
->decor
;
966 if (settings
->iconic
!= -1)
967 self
->iconic
= !!settings
->iconic
;
968 if (settings
->skip_pager
!= -1)
969 self
->skip_pager
= !!settings
->skip_pager
;
970 if (settings
->skip_taskbar
!= -1)
971 self
->skip_taskbar
= !!settings
->skip_taskbar
;
973 if (settings
->max_vert
!= -1)
974 self
->max_vert
= !!settings
->max_vert
;
975 if (settings
->max_horz
!= -1)
976 self
->max_horz
= !!settings
->max_horz
;
978 if (settings
->fullscreen
!= -1)
979 self
->fullscreen
= !!settings
->fullscreen
;
981 if (settings
->desktop
) {
982 if (settings
->desktop
== DESKTOP_ALL
)
983 self
->desktop
= settings
->desktop
;
984 else if (settings
->desktop
> 0 &&
985 settings
->desktop
<= screen_num_desktops
)
986 self
->desktop
= settings
->desktop
- 1;
989 if (settings
->layer
== -1) {
993 else if (settings
->layer
== 0) {
997 else if (settings
->layer
== 1) {
1004 static void client_restore_session_state(ObClient
*self
)
1008 ob_debug_type(OB_DEBUG_SM
,
1009 "Restore session for client %s", self
->title
);
1011 if (!(it
= session_state_find(self
))) {
1012 ob_debug_type(OB_DEBUG_SM
,
1013 "Session data not found for client %s", self
->title
);
1017 self
->session
= it
->data
;
1019 ob_debug_type(OB_DEBUG_SM
, "Session data loaded for client %s",
1022 RECT_SET_POINT(self
->area
, self
->session
->x
, self
->session
->y
);
1023 self
->positioned
= USPosition
;
1024 self
->sized
= USSize
;
1025 if (self
->session
->w
> 0)
1026 self
->area
.width
= self
->session
->w
;
1027 if (self
->session
->h
> 0)
1028 self
->area
.height
= self
->session
->h
;
1029 XResizeWindow(obt_display
, self
->window
,
1030 self
->area
.width
, self
->area
.height
);
1032 self
->desktop
= (self
->session
->desktop
== DESKTOP_ALL
?
1033 self
->session
->desktop
:
1034 MIN(screen_num_desktops
- 1, self
->session
->desktop
));
1035 OBT_PROP_SET32(self
->window
, NET_WM_DESKTOP
, CARDINAL
, self
->desktop
);
1037 self
->shaded
= self
->session
->shaded
;
1038 self
->iconic
= self
->session
->iconic
;
1039 self
->skip_pager
= self
->session
->skip_pager
;
1040 self
->skip_taskbar
= self
->session
->skip_taskbar
;
1041 self
->fullscreen
= self
->session
->fullscreen
;
1042 self
->above
= self
->session
->above
;
1043 self
->below
= self
->session
->below
;
1044 self
->max_horz
= self
->session
->max_horz
;
1045 self
->max_vert
= self
->session
->max_vert
;
1046 self
->undecorated
= self
->session
->undecorated
;
1049 static gboolean
client_restore_session_stacking(ObClient
*self
)
1053 if (!self
->session
) return FALSE
;
1055 mypos
= g_list_find(session_saved_state
, self
->session
);
1056 if (!mypos
) return FALSE
;
1058 /* start above me and look for the first client */
1059 for (it
= g_list_previous(mypos
); it
; it
= g_list_previous(it
)) {
1062 for (cit
= client_list
; cit
; cit
= g_list_next(cit
)) {
1063 ObClient
*c
= cit
->data
;
1064 /* found a client that was in the session, so go below it */
1065 if (c
->session
== it
->data
) {
1066 stacking_below(CLIENT_AS_WINDOW(self
),
1067 CLIENT_AS_WINDOW(cit
->data
));
1075 void client_move_onscreen(ObClient
*self
, gboolean rude
)
1077 gint x
= self
->area
.x
;
1078 gint y
= self
->area
.y
;
1079 if (client_find_onscreen(self
, &x
, &y
,
1081 self
->area
.height
, rude
)) {
1082 client_move(self
, x
, y
);
1086 gboolean
client_find_onscreen(ObClient
*self
, gint
*x
, gint
*y
, gint w
, gint h
,
1089 gint ox
= *x
, oy
= *y
;
1090 gboolean rudel
= rude
, ruder
= rude
, rudet
= rude
, rudeb
= rude
;
1096 RECT_SET(desired
, *x
, *y
, w
, h
);
1097 frame_rect_to_frame(self
->frame
, &desired
);
1099 /* get where the frame would be */
1100 frame_client_gravity(self
->frame
, x
, y
);
1102 /* get the requested size of the window with decorations */
1103 fw
= self
->frame
->size
.left
+ w
+ self
->frame
->size
.right
;
1104 fh
= self
->frame
->size
.top
+ h
+ self
->frame
->size
.bottom
;
1106 /* If rudeness wasn't requested, then still be rude in a given direction
1107 if the client is not moving, only resizing in that direction */
1109 Point oldtl
, oldtr
, oldbl
, oldbr
;
1110 Point newtl
, newtr
, newbl
, newbr
;
1111 gboolean stationary_l
, stationary_r
, stationary_t
, stationary_b
;
1113 POINT_SET(oldtl
, self
->frame
->area
.x
, self
->frame
->area
.y
);
1114 POINT_SET(oldbr
, self
->frame
->area
.x
+ self
->frame
->area
.width
- 1,
1115 self
->frame
->area
.y
+ self
->frame
->area
.height
- 1);
1116 POINT_SET(oldtr
, oldbr
.x
, oldtl
.y
);
1117 POINT_SET(oldbl
, oldtl
.x
, oldbr
.y
);
1119 POINT_SET(newtl
, *x
, *y
);
1120 POINT_SET(newbr
, *x
+ fw
- 1, *y
+ fh
- 1);
1121 POINT_SET(newtr
, newbr
.x
, newtl
.y
);
1122 POINT_SET(newbl
, newtl
.x
, newbr
.y
);
1124 /* is it moving or just resizing from some corner? */
1125 stationary_l
= oldtl
.x
== newtl
.x
;
1126 stationary_r
= oldtr
.x
== newtr
.x
;
1127 stationary_t
= oldtl
.y
== newtl
.y
;
1128 stationary_b
= oldbl
.y
== newbl
.y
;
1130 /* if left edge is growing and didnt move right edge */
1131 if (stationary_r
&& newtl
.x
< oldtl
.x
)
1133 /* if right edge is growing and didnt move left edge */
1134 if (stationary_l
&& newtr
.x
> oldtr
.x
)
1136 /* if top edge is growing and didnt move bottom edge */
1137 if (stationary_b
&& newtl
.y
< oldtl
.y
)
1139 /* if bottom edge is growing and didnt move top edge */
1140 if (stationary_t
&& newbl
.y
> oldbl
.y
)
1144 /* we iterate through every monitor that the window is at least partially
1145 on, to make sure it is obeying the rules on them all
1147 if the window does not appear on any monitors, then use the first one
1150 for (i
= 0; i
< screen_num_monitors
; ++i
) {
1153 if (!screen_physical_area_monitor_contains(i
, &desired
)) {
1154 if (i
< screen_num_monitors
- 1 || found_mon
)
1157 /* the window is not inside any monitor! so just use the first
1159 a
= screen_area(self
->desktop
, 0, NULL
);
1162 a
= screen_area(self
->desktop
, SCREEN_AREA_ONE_MONITOR
, &desired
);
1165 /* This makes sure windows aren't entirely outside of the screen so you
1166 can't see them at all.
1167 It makes sure 10% of the window is on the screen at least. And don't
1168 let it move itself off the top of the screen, which would hide the
1169 titlebar on you. (The user can still do this if they want too, it's
1170 only limiting the application.
1172 if (client_normal(self
)) {
1173 if (!self
->strut
.right
&& *x
+ fw
/10 >= a
->x
+ a
->width
- 1)
1174 *x
= a
->x
+ a
->width
- fw
/10;
1175 if (!self
->strut
.bottom
&& *y
+ fh
/10 >= a
->y
+ a
->height
- 1)
1176 *y
= a
->y
+ a
->height
- fh
/10;
1177 if (!self
->strut
.left
&& *x
+ fw
*9/10 - 1 < a
->x
)
1178 *x
= a
->x
- fw
*9/10;
1179 if (!self
->strut
.top
&& *y
+ fh
*9/10 - 1 < a
->y
)
1180 *y
= a
->y
- fh
*9/10;
1183 /* This here doesn't let windows even a pixel outside the
1184 struts/screen. When called from client_manage, programs placing
1185 themselves are forced completely onscreen, while things like
1186 xterm -geometry resolution-width/2 will work fine. Trying to
1187 place it completely offscreen will be handled in the above code.
1188 Sorry for this confused comment, i am tired. */
1189 if (rudel
&& !self
->strut
.left
&& *x
< a
->x
) *x
= a
->x
;
1190 if (ruder
&& !self
->strut
.right
&& *x
+ fw
> a
->x
+ a
->width
)
1191 *x
= a
->x
+ MAX(0, a
->width
- fw
);
1193 if (rudet
&& !self
->strut
.top
&& *y
< a
->y
) *y
= a
->y
;
1194 if (rudeb
&& !self
->strut
.bottom
&& *y
+ fh
> a
->y
+ a
->height
)
1195 *y
= a
->y
+ MAX(0, a
->height
- fh
);
1197 g_slice_free(Rect
, a
);
1200 /* get where the client should be */
1201 frame_frame_gravity(self
->frame
, x
, y
);
1203 return ox
!= *x
|| oy
!= *y
;
1206 static void client_get_all(ObClient
*self
, gboolean real
)
1208 /* this is needed for the frame to set itself up */
1209 client_get_area(self
);
1211 /* these things can change the decor and functions of the window */
1213 client_get_mwm_hints(self
);
1214 /* this can change the mwmhints for special cases */
1215 client_get_type_and_transientness(self
);
1216 client_update_normal_hints(self
);
1218 /* set up the maximum possible decor/functions */
1219 client_setup_default_decor_and_functions(self
);
1221 client_get_state(self
);
1223 /* get the session related properties, these can change decorations
1224 from per-app settings */
1225 client_get_session_ids(self
);
1227 /* get this early so we have it for debugging, also this can be used
1228 by app rule matching */
1229 client_update_title(self
);
1231 /* now we got everything that can affect the decorations or app rule
1236 /* save the values of the variables used for app rule matching */
1237 client_save_app_rule_values(self
);
1239 client_update_protocols(self
);
1241 client_update_wmhints(self
);
1242 /* this may have already been called from client_update_wmhints */
1243 if (!self
->parents
&& !self
->transient_for_group
)
1244 client_update_transient_for(self
);
1246 client_get_startup_id(self
);
1247 client_get_desktop(self
);/* uses transient data/group/startup id if a
1248 desktop is not specified */
1249 client_get_shaped(self
);
1252 /* a couple type-based defaults for new windows */
1254 /* this makes sure that these windows appear on all desktops */
1255 if (self
->type
== OB_CLIENT_TYPE_DESKTOP
)
1256 self
->desktop
= DESKTOP_ALL
;
1260 client_update_sync_request_counter(self
);
1263 client_get_colormap(self
);
1264 client_update_strut(self
);
1265 client_update_icons(self
);
1266 client_update_icon_geometry(self
);
1269 static void client_get_startup_id(ObClient
*self
)
1271 if (!(OBT_PROP_GETS_UTF8(self
->window
, NET_STARTUP_ID
, &self
->startup_id
)))
1273 OBT_PROP_GETS_UTF8(self
->group
->leader
, NET_STARTUP_ID
,
1277 static void client_get_area(ObClient
*self
)
1279 XWindowAttributes wattrib
;
1282 ret
= XGetWindowAttributes(obt_display
, self
->window
, &wattrib
);
1283 g_assert(ret
!= BadWindow
);
1285 RECT_SET(self
->area
, wattrib
.x
, wattrib
.y
, wattrib
.width
, wattrib
.height
);
1286 POINT_SET(self
->root_pos
, wattrib
.x
, wattrib
.y
);
1287 self
->border_width
= wattrib
.border_width
;
1289 ob_debug("client area: %d %d %d %d bw %d", wattrib
.x
, wattrib
.y
,
1290 wattrib
.width
, wattrib
.height
, wattrib
.border_width
);
1293 static void client_get_desktop(ObClient
*self
)
1295 guint32 d
= screen_num_desktops
; /* an always-invalid value */
1297 if (OBT_PROP_GET32(self
->window
, NET_WM_DESKTOP
, CARDINAL
, &d
)) {
1298 if (d
>= screen_num_desktops
&& d
!= DESKTOP_ALL
)
1299 self
->desktop
= screen_num_desktops
- 1;
1302 ob_debug("client requested desktop 0x%x", self
->desktop
);
1305 gboolean first
= TRUE
;
1306 guint all
= screen_num_desktops
; /* not a valid value */
1308 /* if they are all on one desktop, then open it on the
1310 for (it
= self
->parents
; it
; it
= g_slist_next(it
)) {
1311 ObClient
*c
= it
->data
;
1313 if (c
->desktop
== DESKTOP_ALL
) continue;
1319 else if (all
!= c
->desktop
)
1320 all
= screen_num_desktops
; /* make it invalid */
1322 if (all
!= screen_num_desktops
) {
1323 self
->desktop
= all
;
1325 ob_debug("client desktop set from parents: 0x%x",
1328 /* try get from the startup-notification protocol */
1329 else if (sn_get_desktop(self
->startup_id
, &self
->desktop
)) {
1330 if (self
->desktop
>= screen_num_desktops
&&
1331 self
->desktop
!= DESKTOP_ALL
)
1332 self
->desktop
= screen_num_desktops
- 1;
1333 ob_debug("client desktop set from startup-notification: 0x%x",
1336 /* defaults to the current desktop */
1338 self
->desktop
= screen_desktop
;
1339 ob_debug("client desktop set to the current desktop: %d",
1345 static void client_get_state(ObClient
*self
)
1350 if (OBT_PROP_GETA32(self
->window
, NET_WM_STATE
, ATOM
, &state
, &num
)) {
1352 for (i
= 0; i
< num
; ++i
) {
1353 if (state
[i
] == OBT_PROP_ATOM(NET_WM_STATE_MODAL
))
1355 else if (state
[i
] == OBT_PROP_ATOM(NET_WM_STATE_SHADED
))
1356 self
->shaded
= TRUE
;
1357 else if (state
[i
] == OBT_PROP_ATOM(NET_WM_STATE_HIDDEN
))
1358 self
->iconic
= TRUE
;
1359 else if (state
[i
] == OBT_PROP_ATOM(NET_WM_STATE_SKIP_TASKBAR
))
1360 self
->skip_taskbar
= TRUE
;
1361 else if (state
[i
] == OBT_PROP_ATOM(NET_WM_STATE_SKIP_PAGER
))
1362 self
->skip_pager
= TRUE
;
1363 else if (state
[i
] == OBT_PROP_ATOM(NET_WM_STATE_FULLSCREEN
))
1364 self
->fullscreen
= TRUE
;
1365 else if (state
[i
] == OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_VERT
))
1366 self
->max_vert
= TRUE
;
1367 else if (state
[i
] == OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_HORZ
))
1368 self
->max_horz
= TRUE
;
1369 else if (state
[i
] == OBT_PROP_ATOM(NET_WM_STATE_ABOVE
))
1371 else if (state
[i
] == OBT_PROP_ATOM(NET_WM_STATE_BELOW
))
1373 else if (state
[i
] == OBT_PROP_ATOM(NET_WM_STATE_DEMANDS_ATTENTION
))
1374 self
->demands_attention
= TRUE
;
1375 else if (state
[i
] == OBT_PROP_ATOM(OB_WM_STATE_UNDECORATED
))
1376 self
->undecorated
= TRUE
;
1383 static void client_get_shaped(ObClient
*self
)
1385 self
->shaped
= FALSE
;
1387 if (obt_display_extension_shape
) {
1392 XShapeSelectInput(obt_display
, self
->window
, ShapeNotifyMask
);
1394 XShapeQueryExtents(obt_display
, self
->window
, &s
, &foo
,
1395 &foo
, &ufoo
, &ufoo
, &foo
, &foo
, &foo
, &ufoo
,
1402 void client_update_transient_for(ObClient
*self
)
1405 ObClient
*target
= NULL
;
1406 gboolean trangroup
= FALSE
;
1408 if (XGetTransientForHint(obt_display
, self
->window
, &t
)) {
1409 if (t
!= self
->window
) { /* can't be transient to itself! */
1410 ObWindow
*tw
= window_find(t
);
1411 /* if this happens then we need to check for it */
1412 g_assert(tw
!= CLIENT_AS_WINDOW(self
));
1413 if (tw
&& WINDOW_IS_CLIENT(tw
)) {
1414 /* watch out for windows with a parent that is something
1415 different, like a dockapp for example */
1416 target
= WINDOW_AS_CLIENT(tw
);
1420 /* Setting the transient_for to Root is actually illegal, however
1421 applications from time have done this to specify transient for
1423 if (!target
&& self
->group
&& t
== obt_root(ob_screen
))
1425 } else if (self
->group
&& self
->transient
)
1428 client_update_transient_tree(self
, self
->group
, self
->group
,
1429 self
->transient_for_group
, trangroup
,
1430 client_direct_parent(self
), target
);
1431 self
->transient_for_group
= trangroup
;
1435 static void client_update_transient_tree(ObClient
*self
,
1436 ObGroup
*oldgroup
, ObGroup
*newgroup
,
1437 gboolean oldgtran
, gboolean newgtran
,
1438 ObClient
* oldparent
,
1439 ObClient
*newparent
)
1444 g_assert(!oldgtran
|| oldgroup
);
1445 g_assert(!newgtran
|| newgroup
);
1446 g_assert((!oldgtran
&& !oldparent
) ||
1447 (oldgtran
&& !oldparent
) ||
1448 (!oldgtran
&& oldparent
));
1449 g_assert((!newgtran
&& !newparent
) ||
1450 (newgtran
&& !newparent
) ||
1451 (!newgtran
&& newparent
));
1454 Group transient windows are not allowed to have other group
1455 transient windows as their children.
1458 /* No change has occured */
1459 if (oldgroup
== newgroup
&&
1460 oldgtran
== newgtran
&&
1461 oldparent
== newparent
) return;
1463 /** Remove the client from the transient tree **/
1465 for (it
= self
->transients
; it
; it
= next
) {
1466 next
= g_slist_next(it
);
1468 self
->transients
= g_slist_delete_link(self
->transients
, it
);
1469 c
->parents
= g_slist_remove(c
->parents
, self
);
1471 for (it
= self
->parents
; it
; it
= next
) {
1472 next
= g_slist_next(it
);
1474 self
->parents
= g_slist_delete_link(self
->parents
, it
);
1475 c
->transients
= g_slist_remove(c
->transients
, self
);
1478 /** Re-add the client to the transient tree **/
1480 /* If we're transient for a group then we need to add ourselves to all our
1483 for (it
= newgroup
->members
; it
; it
= g_slist_next(it
)) {
1486 !client_search_top_direct_parent(c
)->transient_for_group
&&
1489 c
->transients
= g_slist_prepend(c
->transients
, self
);
1490 self
->parents
= g_slist_prepend(self
->parents
, c
);
1495 /* If we are now transient for a single window we need to add ourselves to
1498 WARNING: Cyclical transient-ness is possible if two windows are
1499 transient for eachother.
1501 else if (newparent
&&
1502 /* don't make ourself its child if it is already our child */
1503 !client_is_direct_child(self
, newparent
) &&
1504 client_normal(newparent
))
1506 newparent
->transients
= g_slist_prepend(newparent
->transients
, self
);
1507 self
->parents
= g_slist_prepend(self
->parents
, newparent
);
1510 /* Add any group transient windows to our children. But if we're transient
1511 for the group, then other group transients are not our children.
1513 WARNING: Cyclical transient-ness is possible. For e.g. if:
1514 A is transient for the group
1515 B is transient for A
1516 C is transient for B
1517 A can't be transient for C or we have a cycle
1519 if (!newgtran
&& newgroup
&&
1521 !client_search_top_direct_parent(newparent
)->transient_for_group
) &&
1522 client_normal(self
))
1524 for (it
= newgroup
->members
; it
; it
= g_slist_next(it
)) {
1526 if (c
!= self
&& c
->transient_for_group
&&
1527 /* Don't make it our child if it is already our parent */
1528 !client_is_direct_child(c
, self
))
1530 self
->transients
= g_slist_prepend(self
->transients
, c
);
1531 c
->parents
= g_slist_prepend(c
->parents
, self
);
1536 /** If we change our group transient-ness, our children change their
1537 effective group transient-ness, which affects how they relate to other
1540 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
1542 if (!c
->transient_for_group
)
1543 client_update_transient_tree(c
, c
->group
, c
->group
,
1544 c
->transient_for_group
,
1545 c
->transient_for_group
,
1546 client_direct_parent(c
),
1547 client_direct_parent(c
));
1551 void client_get_mwm_hints(ObClient
*self
)
1556 self
->mwmhints
.flags
= 0; /* default to none */
1558 if (OBT_PROP_GETA32(self
->window
, MOTIF_WM_HINTS
, MOTIF_WM_HINTS
,
1560 if (num
>= OB_MWM_ELEMENTS
) {
1561 self
->mwmhints
.flags
= hints
[0];
1562 self
->mwmhints
.functions
= hints
[1];
1563 self
->mwmhints
.decorations
= hints
[2];
1569 void client_get_type_and_transientness(ObClient
*self
)
1576 self
->transient
= FALSE
;
1578 if (OBT_PROP_GETA32(self
->window
, NET_WM_WINDOW_TYPE
, ATOM
, &val
, &num
)) {
1579 /* use the first value that we know about in the array */
1580 for (i
= 0; i
< num
; ++i
) {
1581 if (val
[i
] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_DESKTOP
))
1582 self
->type
= OB_CLIENT_TYPE_DESKTOP
;
1583 else if (val
[i
] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_DOCK
))
1584 self
->type
= OB_CLIENT_TYPE_DOCK
;
1585 else if (val
[i
] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_TOOLBAR
))
1586 self
->type
= OB_CLIENT_TYPE_TOOLBAR
;
1587 else if (val
[i
] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_MENU
))
1588 self
->type
= OB_CLIENT_TYPE_MENU
;
1589 else if (val
[i
] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_UTILITY
))
1590 self
->type
= OB_CLIENT_TYPE_UTILITY
;
1591 else if (val
[i
] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_SPLASH
))
1592 self
->type
= OB_CLIENT_TYPE_SPLASH
;
1593 else if (val
[i
] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_DIALOG
))
1594 self
->type
= OB_CLIENT_TYPE_DIALOG
;
1595 else if (val
[i
] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_NORMAL
))
1596 self
->type
= OB_CLIENT_TYPE_NORMAL
;
1597 else if (val
[i
] == OBT_PROP_ATOM(KDE_NET_WM_WINDOW_TYPE_OVERRIDE
))
1599 /* prevent this window from getting any decor or
1601 self
->mwmhints
.flags
&= (OB_MWM_FLAG_FUNCTIONS
|
1602 OB_MWM_FLAG_DECORATIONS
);
1603 self
->mwmhints
.decorations
= 0;
1604 self
->mwmhints
.functions
= 0;
1606 if (self
->type
!= (ObClientType
) -1)
1607 break; /* grab the first legit type */
1612 if (XGetTransientForHint(obt_display
, self
->window
, &t
))
1613 self
->transient
= TRUE
;
1615 if (self
->type
== (ObClientType
) -1) {
1616 /*the window type hint was not set, which means we either classify
1617 ourself as a normal window or a dialog, depending on if we are a
1619 if (self
->transient
)
1620 self
->type
= OB_CLIENT_TYPE_DIALOG
;
1622 self
->type
= OB_CLIENT_TYPE_NORMAL
;
1625 /* then, based on our type, we can update our transientness.. */
1626 if (self
->type
== OB_CLIENT_TYPE_DIALOG
||
1627 self
->type
== OB_CLIENT_TYPE_TOOLBAR
||
1628 self
->type
== OB_CLIENT_TYPE_MENU
||
1629 self
->type
== OB_CLIENT_TYPE_UTILITY
)
1631 self
->transient
= TRUE
;
1635 void client_update_protocols(ObClient
*self
)
1640 self
->focus_notify
= FALSE
;
1641 self
->delete_window
= FALSE
;
1643 if (OBT_PROP_GETA32(self
->window
, WM_PROTOCOLS
, ATOM
, &proto
, &num_ret
)) {
1644 for (i
= 0; i
< num_ret
; ++i
) {
1645 if (proto
[i
] == OBT_PROP_ATOM(WM_DELETE_WINDOW
))
1646 /* this means we can request the window to close */
1647 self
->delete_window
= TRUE
;
1648 else if (proto
[i
] == OBT_PROP_ATOM(WM_TAKE_FOCUS
))
1649 /* if this protocol is requested, then the window will be
1650 notified whenever we want it to receive focus */
1651 self
->focus_notify
= TRUE
;
1652 else if (proto
[i
] == OBT_PROP_ATOM(NET_WM_PING
))
1653 /* if this protocol is requested, then the window will allow
1654 pings to determine if it is still alive */
1657 else if (proto
[i
] == OBT_PROP_ATOM(NET_WM_SYNC_REQUEST
))
1658 /* if this protocol is requested, then resizing the
1659 window will be synchronized between the frame and the
1661 self
->sync_request
= TRUE
;
1669 void client_update_sync_request_counter(ObClient
*self
)
1673 if (OBT_PROP_GET32(self
->window
, NET_WM_SYNC_REQUEST_COUNTER
, CARDINAL
,&i
))
1677 self
->sync_counter
= i
;
1679 /* this must be set when managing a new window according to EWMH */
1680 XSyncIntToValue(&val
, 0);
1681 XSyncSetCounter(obt_display
, self
->sync_counter
, val
);
1683 self
->sync_counter
= None
;
1687 static void client_get_colormap(ObClient
*self
)
1689 XWindowAttributes wa
;
1691 if (XGetWindowAttributes(obt_display
, self
->window
, &wa
))
1692 client_update_colormap(self
, wa
.colormap
);
1695 void client_update_colormap(ObClient
*self
, Colormap colormap
)
1697 if (colormap
== self
->colormap
) return;
1699 ob_debug("Setting client %s colormap: 0x%x", self
->title
, colormap
);
1701 if (client_focused(self
)) {
1702 screen_install_colormap(self
, FALSE
); /* uninstall old one */
1703 self
->colormap
= colormap
;
1704 screen_install_colormap(self
, TRUE
); /* install new one */
1706 self
->colormap
= colormap
;
1709 void client_update_opacity(ObClient
*self
)
1713 if (OBT_PROP_GET32(self
->window
, NET_WM_WINDOW_OPACITY
, CARDINAL
, &o
))
1714 OBT_PROP_SET32(self
->frame
->window
, NET_WM_WINDOW_OPACITY
, CARDINAL
, o
);
1716 OBT_PROP_ERASE(self
->frame
->window
, NET_WM_WINDOW_OPACITY
);
1719 void client_update_normal_hints(ObClient
*self
)
1725 self
->min_ratio
= 0.0f
;
1726 self
->max_ratio
= 0.0f
;
1727 SIZE_SET(self
->size_inc
, 1, 1);
1728 SIZE_SET(self
->base_size
, -1, -1);
1729 SIZE_SET(self
->min_size
, 0, 0);
1730 SIZE_SET(self
->max_size
, G_MAXINT
, G_MAXINT
);
1732 /* get the hints from the window */
1733 if (XGetWMNormalHints(obt_display
, self
->window
, &size
, &ret
)) {
1734 /* normal windows can't request placement! har har
1735 if (!client_normal(self))
1737 self
->positioned
= (size
.flags
& (PPosition
|USPosition
));
1738 self
->sized
= (size
.flags
& (PSize
|USSize
));
1740 if (size
.flags
& PWinGravity
)
1741 self
->gravity
= size
.win_gravity
;
1743 if (size
.flags
& PAspect
) {
1744 if (size
.min_aspect
.y
)
1746 (gfloat
) size
.min_aspect
.x
/ size
.min_aspect
.y
;
1747 if (size
.max_aspect
.y
)
1749 (gfloat
) size
.max_aspect
.x
/ size
.max_aspect
.y
;
1752 if (size
.flags
& PMinSize
)
1753 SIZE_SET(self
->min_size
, size
.min_width
, size
.min_height
);
1755 if (size
.flags
& PMaxSize
)
1756 SIZE_SET(self
->max_size
, size
.max_width
, size
.max_height
);
1758 if (size
.flags
& PBaseSize
)
1759 SIZE_SET(self
->base_size
, size
.base_width
, size
.base_height
);
1761 if (size
.flags
& PResizeInc
&& size
.width_inc
&& size
.height_inc
)
1762 SIZE_SET(self
->size_inc
, size
.width_inc
, size
.height_inc
);
1764 ob_debug("Normal hints: min size (%d %d) max size (%d %d)",
1765 self
->min_size
.width
, self
->min_size
.height
,
1766 self
->max_size
.width
, self
->max_size
.height
);
1767 ob_debug("size inc (%d %d) base size (%d %d)",
1768 self
->size_inc
.width
, self
->size_inc
.height
,
1769 self
->base_size
.width
, self
->base_size
.height
);
1772 ob_debug("Normal hints: not set");
1775 static void client_setup_default_decor_and_functions(ObClient
*self
)
1777 /* start with everything (cept fullscreen) */
1779 (OB_FRAME_DECOR_TITLEBAR
|
1780 OB_FRAME_DECOR_HANDLE
|
1781 OB_FRAME_DECOR_GRIPS
|
1782 OB_FRAME_DECOR_BORDER
|
1783 OB_FRAME_DECOR_ICON
|
1784 OB_FRAME_DECOR_ALLDESKTOPS
|
1785 OB_FRAME_DECOR_ICONIFY
|
1786 OB_FRAME_DECOR_MAXIMIZE
|
1787 OB_FRAME_DECOR_SHADE
|
1788 OB_FRAME_DECOR_CLOSE
);
1790 (OB_CLIENT_FUNC_RESIZE
|
1791 OB_CLIENT_FUNC_MOVE
|
1792 OB_CLIENT_FUNC_ICONIFY
|
1793 OB_CLIENT_FUNC_MAXIMIZE
|
1794 OB_CLIENT_FUNC_SHADE
|
1795 OB_CLIENT_FUNC_CLOSE
|
1796 OB_CLIENT_FUNC_BELOW
|
1797 OB_CLIENT_FUNC_ABOVE
|
1798 OB_CLIENT_FUNC_UNDECORATE
);
1800 if (!(self
->min_size
.width
< self
->max_size
.width
||
1801 self
->min_size
.height
< self
->max_size
.height
))
1802 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
1804 switch (self
->type
) {
1805 case OB_CLIENT_TYPE_NORMAL
:
1806 /* normal windows retain all of the possible decorations and
1807 functionality, and can be fullscreen */
1808 self
->functions
|= OB_CLIENT_FUNC_FULLSCREEN
;
1811 case OB_CLIENT_TYPE_DIALOG
:
1812 /* sometimes apps make dialog windows fullscreen for some reason (for
1813 e.g. kpdf does this..) */
1814 self
->functions
|= OB_CLIENT_FUNC_FULLSCREEN
;
1817 case OB_CLIENT_TYPE_UTILITY
:
1818 /* these windows don't have anything added or removed by default */
1821 case OB_CLIENT_TYPE_MENU
:
1822 case OB_CLIENT_TYPE_TOOLBAR
:
1823 /* these windows can't iconify or maximize */
1824 self
->decorations
&= ~(OB_FRAME_DECOR_ICONIFY
|
1825 OB_FRAME_DECOR_MAXIMIZE
);
1826 self
->functions
&= ~(OB_CLIENT_FUNC_ICONIFY
|
1827 OB_CLIENT_FUNC_MAXIMIZE
);
1830 case OB_CLIENT_TYPE_SPLASH
:
1831 /* these don't get get any decorations, and the only thing you can
1832 do with them is move them */
1833 self
->decorations
= 0;
1834 self
->functions
= OB_CLIENT_FUNC_MOVE
;
1837 case OB_CLIENT_TYPE_DESKTOP
:
1838 /* these windows are not manipulated by the window manager */
1839 self
->decorations
= 0;
1840 self
->functions
= 0;
1843 case OB_CLIENT_TYPE_DOCK
:
1844 /* these windows are not manipulated by the window manager, but they
1845 can set below layer which has a special meaning */
1846 self
->decorations
= 0;
1847 self
->functions
= OB_CLIENT_FUNC_BELOW
;
1851 /* If the client has no decor from its type (which never changes) then
1852 don't allow the user to "undecorate" the window. Otherwise, allow them
1853 to, even if there are motif hints removing the decor, because those
1854 may change these days (e.g. chromium) */
1855 if (self
->decorations
== 0)
1856 self
->functions
&= ~OB_CLIENT_FUNC_UNDECORATE
;
1858 /* Mwm Hints are applied subtractively to what has already been chosen for
1859 decor and functionality */
1860 if (self
->mwmhints
.flags
& OB_MWM_FLAG_DECORATIONS
) {
1861 if (! (self
->mwmhints
.decorations
& OB_MWM_DECOR_ALL
)) {
1862 if (! ((self
->mwmhints
.decorations
& OB_MWM_DECOR_HANDLE
) ||
1863 (self
->mwmhints
.decorations
& OB_MWM_DECOR_TITLE
)))
1865 /* if the mwm hints request no handle or title, then all
1866 decorations are disabled, but keep the border if that's
1868 if (self
->mwmhints
.decorations
& OB_MWM_DECOR_BORDER
)
1869 self
->decorations
= OB_FRAME_DECOR_BORDER
;
1871 self
->decorations
= 0;
1876 if (self
->mwmhints
.flags
& OB_MWM_FLAG_FUNCTIONS
) {
1877 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_ALL
)) {
1878 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_RESIZE
))
1879 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
1880 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_MOVE
))
1881 self
->functions
&= ~OB_CLIENT_FUNC_MOVE
;
1882 /* dont let mwm hints kill any buttons
1883 if (! (self->mwmhints.functions & OB_MWM_FUNC_ICONIFY))
1884 self->functions &= ~OB_CLIENT_FUNC_ICONIFY;
1885 if (! (self->mwmhints.functions & OB_MWM_FUNC_MAXIMIZE))
1886 self->functions &= ~OB_CLIENT_FUNC_MAXIMIZE;
1888 /* dont let mwm hints kill the close button
1889 if (! (self->mwmhints.functions & MwmFunc_Close))
1890 self->functions &= ~OB_CLIENT_FUNC_CLOSE; */
1894 if (!(self
->functions
& OB_CLIENT_FUNC_SHADE
))
1895 self
->decorations
&= ~OB_FRAME_DECOR_SHADE
;
1896 if (!(self
->functions
& OB_CLIENT_FUNC_ICONIFY
))
1897 self
->decorations
&= ~OB_FRAME_DECOR_ICONIFY
;
1898 if (!(self
->functions
& OB_CLIENT_FUNC_RESIZE
))
1899 self
->decorations
&= ~(OB_FRAME_DECOR_GRIPS
| OB_FRAME_DECOR_HANDLE
);
1901 /* can't maximize without moving/resizing */
1902 if (!((self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) &&
1903 (self
->functions
& OB_CLIENT_FUNC_MOVE
) &&
1904 (self
->functions
& OB_CLIENT_FUNC_RESIZE
))) {
1905 self
->functions
&= ~OB_CLIENT_FUNC_MAXIMIZE
;
1906 self
->decorations
&= ~OB_FRAME_DECOR_MAXIMIZE
;
1910 /*! Set up decor for a client based on its undecorated state. */
1911 static void client_setup_decor_undecorated(ObClient
*self
)
1913 /* If the user requested no decorations, then remove all the decorations,
1914 except the border. But don't add a border if there wasn't one. */
1915 if (self
->undecorated
)
1916 self
->decorations
&= (config_theme_keepborder
?
1917 OB_FRAME_DECOR_BORDER
: 0);
1920 void client_setup_decor_and_functions(ObClient
*self
, gboolean reconfig
)
1922 client_setup_default_decor_and_functions(self
);
1924 client_setup_decor_undecorated(self
);
1926 if (self
->max_horz
&& self
->max_vert
) {
1927 /* once upon a time you couldn't resize maximized windows, that is not
1928 the case any more though !
1930 but do kill the handle on fully maxed windows */
1931 self
->decorations
&= ~(OB_FRAME_DECOR_HANDLE
| OB_FRAME_DECOR_GRIPS
);
1934 /* if we don't have a titlebar, then we cannot shade! */
1935 if (!(self
->decorations
& OB_FRAME_DECOR_TITLEBAR
))
1936 self
->functions
&= ~OB_CLIENT_FUNC_SHADE
;
1938 /* now we need to check against rules for the client's current state */
1939 if (self
->fullscreen
) {
1940 self
->functions
&= (OB_CLIENT_FUNC_CLOSE
|
1941 OB_CLIENT_FUNC_FULLSCREEN
|
1942 OB_CLIENT_FUNC_ICONIFY
);
1943 self
->decorations
= 0;
1946 client_change_allowed_actions(self
);
1949 /* reconfigure to make sure decorations are updated */
1950 client_reconfigure(self
, FALSE
);
1953 static void client_change_allowed_actions(ObClient
*self
)
1958 /* desktop windows are kept on all desktops */
1959 if (self
->type
!= OB_CLIENT_TYPE_DESKTOP
)
1960 actions
[num
++] = OBT_PROP_ATOM(NET_WM_ACTION_CHANGE_DESKTOP
);
1962 if (self
->functions
& OB_CLIENT_FUNC_SHADE
)
1963 actions
[num
++] = OBT_PROP_ATOM(NET_WM_ACTION_SHADE
);
1964 if (self
->functions
& OB_CLIENT_FUNC_CLOSE
)
1965 actions
[num
++] = OBT_PROP_ATOM(NET_WM_ACTION_CLOSE
);
1966 if (self
->functions
& OB_CLIENT_FUNC_MOVE
)
1967 actions
[num
++] = OBT_PROP_ATOM(NET_WM_ACTION_MOVE
);
1968 if (self
->functions
& OB_CLIENT_FUNC_ICONIFY
)
1969 actions
[num
++] = OBT_PROP_ATOM(NET_WM_ACTION_MINIMIZE
);
1970 if (self
->functions
& OB_CLIENT_FUNC_RESIZE
)
1971 actions
[num
++] = OBT_PROP_ATOM(NET_WM_ACTION_RESIZE
);
1972 if (self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
)
1973 actions
[num
++] = OBT_PROP_ATOM(NET_WM_ACTION_FULLSCREEN
);
1974 if (self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) {
1975 actions
[num
++] = OBT_PROP_ATOM(NET_WM_ACTION_MAXIMIZE_HORZ
);
1976 actions
[num
++] = OBT_PROP_ATOM(NET_WM_ACTION_MAXIMIZE_VERT
);
1978 if (self
->functions
& OB_CLIENT_FUNC_ABOVE
)
1979 actions
[num
++] = OBT_PROP_ATOM(NET_WM_ACTION_ABOVE
);
1980 if (self
->functions
& OB_CLIENT_FUNC_BELOW
)
1981 actions
[num
++] = OBT_PROP_ATOM(NET_WM_ACTION_BELOW
);
1982 if (self
->functions
& OB_CLIENT_FUNC_UNDECORATE
)
1983 actions
[num
++] = OBT_PROP_ATOM(OB_WM_ACTION_UNDECORATE
);
1985 OBT_PROP_SETA32(self
->window
, NET_WM_ALLOWED_ACTIONS
, ATOM
, actions
, num
);
1987 /* make sure the window isn't breaking any rules now
1989 don't check ICONIFY here. just cuz a window can't iconify doesnt mean
1990 it can't be iconified with its parent
1993 if (!(self
->functions
& OB_CLIENT_FUNC_SHADE
) && self
->shaded
) {
1994 if (self
->frame
) client_shade(self
, FALSE
);
1995 else self
->shaded
= FALSE
;
1997 if (!(self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
) && self
->fullscreen
) {
1998 if (self
->frame
) client_fullscreen(self
, FALSE
);
1999 else self
->fullscreen
= FALSE
;
2001 if (!(self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) && (self
->max_horz
||
2003 if (self
->frame
) client_maximize(self
, FALSE
, 0);
2004 else self
->max_vert
= self
->max_horz
= FALSE
;
2008 void client_update_wmhints(ObClient
*self
)
2012 /* assume a window takes input if it doesn't specify */
2013 self
->can_focus
= TRUE
;
2015 if ((hints
= XGetWMHints(obt_display
, self
->window
)) != NULL
) {
2018 if (hints
->flags
& InputHint
)
2019 self
->can_focus
= hints
->input
;
2021 /* only do this when first managing the window *AND* when we aren't
2023 if (ob_state() != OB_STATE_STARTING
&& self
->frame
== NULL
)
2024 if (hints
->flags
& StateHint
)
2025 self
->iconic
= hints
->initial_state
== IconicState
;
2028 self
->urgent
= (hints
->flags
& XUrgencyHint
);
2029 if (self
->urgent
&& !ur
)
2030 client_hilite(self
, TRUE
);
2031 else if (!self
->urgent
&& ur
&& self
->demands_attention
)
2032 client_hilite(self
, FALSE
);
2034 if (!(hints
->flags
& WindowGroupHint
))
2035 hints
->window_group
= None
;
2037 /* did the group state change? */
2038 if (hints
->window_group
!=
2039 (self
->group
? self
->group
->leader
: None
))
2041 ObGroup
*oldgroup
= self
->group
;
2043 /* remove from the old group if there was one */
2045 group_remove(self
->group
, self
);
2049 /* add ourself to the group if we have one */
2050 if (hints
->window_group
!= None
) {
2051 self
->group
= group_add(hints
->window_group
, self
);
2054 /* Put ourselves into the new group's transient tree, and remove
2055 ourselves from the old group's */
2056 client_update_transient_tree(self
, oldgroup
, self
->group
,
2057 self
->transient_for_group
,
2058 self
->transient_for_group
,
2059 client_direct_parent(self
),
2060 client_direct_parent(self
));
2062 /* Lastly, being in a group, or not, can change if the window is
2063 transient for anything.
2065 The logic for this is:
2066 self->transient = TRUE always if the window wants to be
2067 transient for something, even if transient_for was NULL because
2068 it wasn't in a group before.
2070 If parents was NULL and oldgroup was NULL we can assume
2071 that when we add the new group, it will become transient for
2074 If transient_for_group is TRUE, then it must have already
2075 had a group. If it is getting a new group, the above call to
2076 client_update_transient_tree has already taken care of
2077 everything ! If it is losing all group status then it will
2078 no longer be transient for anything and that needs to be
2081 if (self
->transient
&&
2082 ((self
->parents
== NULL
&& oldgroup
== NULL
) ||
2083 (self
->transient_for_group
&& !self
->group
)))
2084 client_update_transient_for(self
);
2087 /* the WM_HINTS can contain an icon */
2088 if (hints
->flags
& IconPixmapHint
)
2089 client_update_icons(self
);
2094 focus_cycle_addremove(self
, TRUE
);
2097 void client_update_title(ObClient
*self
)
2100 gchar
*visible
= NULL
;
2102 g_free(self
->title
);
2103 g_free(self
->original_title
);
2106 if (!OBT_PROP_GETS_UTF8(self
->window
, NET_WM_NAME
, &data
)) {
2107 /* try old x stuff */
2108 if (!OBT_PROP_GETS(self
->window
, WM_NAME
, &data
)) {
2109 if (self
->transient
) {
2111 GNOME alert windows are not given titles:
2112 http://developer.gnome.org/projects/gup/hig/draft_hig_new/windows-alert.html
2114 data
= g_strdup("");
2116 data
= g_strdup(_("Unnamed Window"));
2119 self
->original_title
= g_strdup(data
);
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_NAME
, visible
);
2137 self
->title
= visible
;
2140 frame_adjust_title(self
->frame
);
2142 /* update the icon title */
2144 g_free(self
->icon_title
);
2147 if (!OBT_PROP_GETS_UTF8(self
->window
, NET_WM_ICON_NAME
, &data
))
2148 /* try old x stuff */
2149 if (!OBT_PROP_GETS(self
->window
, WM_ICON_NAME
, &data
))
2150 data
= g_strdup(self
->title
);
2152 if (self
->client_machine
) {
2153 visible
= g_strdup_printf("%s (%s)", data
, self
->client_machine
);
2158 if (self
->not_responding
) {
2160 if (self
->kill_level
> 0)
2161 visible
= g_strdup_printf("%s - [%s]", data
, _("Killing..."));
2163 visible
= g_strdup_printf("%s - [%s]", data
, _("Not Responding"));
2167 OBT_PROP_SETS(self
->window
, NET_WM_VISIBLE_ICON_NAME
, visible
);
2168 self
->icon_title
= visible
;
2171 void client_update_strut(ObClient
*self
)
2175 gboolean got
= FALSE
;
2178 if (OBT_PROP_GETA32(self
->window
, NET_WM_STRUT_PARTIAL
, CARDINAL
,
2183 STRUT_PARTIAL_SET(strut
,
2184 data
[0], data
[2], data
[1], data
[3],
2185 data
[4], data
[5], data
[8], data
[9],
2186 data
[6], data
[7], data
[10], data
[11]);
2192 OBT_PROP_GETA32(self
->window
, NET_WM_STRUT
, CARDINAL
, &data
, &num
)) {
2198 /* use the screen's width/height */
2199 a
= screen_physical_area_all_monitors();
2201 STRUT_PARTIAL_SET(strut
,
2202 data
[0], data
[2], data
[1], data
[3],
2203 a
->y
, a
->y
+ a
->height
- 1,
2204 a
->x
, a
->x
+ a
->width
- 1,
2205 a
->y
, a
->y
+ a
->height
- 1,
2206 a
->x
, a
->x
+ a
->width
- 1);
2212 STRUT_PARTIAL_SET(strut
, 0, 0, 0, 0,
2213 0, 0, 0, 0, 0, 0, 0, 0);
2215 if (!PARTIAL_STRUT_EQUAL(strut
, self
->strut
)) {
2216 self
->strut
= strut
;
2218 /* updating here is pointless while we're being mapped cuz we're not in
2219 the client list yet */
2221 screen_update_areas();
2225 void client_update_icons(ObClient
*self
)
2234 /* grab the server, because we might be setting the window's icon and
2235 we don't want them to set it in between and we overwrite their own
2239 if (OBT_PROP_GETA32(self
->window
, NET_WM_ICON
, CARDINAL
, &data
, &num
)) {
2240 /* figure out how many valid icons are in here */
2242 while (i
+ 2 < num
) { /* +2 is to make sure there is a w and h */
2245 /* watch for the data being too small for the specified size,
2246 or for zero sized icons. */
2247 if (i
+ w
*h
> num
|| w
== 0 || h
== 0) {
2252 /* convert it to the right bit order for ObRender */
2253 for (j
= 0; j
< w
*h
; ++j
)
2255 (((data
[i
+j
] >> 24) & 0xff) << RrDefaultAlphaOffset
) +
2256 (((data
[i
+j
] >> 16) & 0xff) << RrDefaultRedOffset
) +
2257 (((data
[i
+j
] >> 8) & 0xff) << RrDefaultGreenOffset
) +
2258 (((data
[i
+j
] >> 0) & 0xff) << RrDefaultBlueOffset
);
2260 /* add it to the image cache as an original */
2262 img
= RrImageNewFromData(ob_rr_icons
, &data
[i
], w
, h
);
2264 RrImageAddFromData(img
, &data
[i
], w
, h
);
2272 /* if we didn't find an image from the NET_WM_ICON stuff, then try the
2277 if ((hints
= XGetWMHints(obt_display
, self
->window
))) {
2278 if (hints
->flags
& IconPixmapHint
) {
2280 obt_display_ignore_errors(TRUE
);
2281 xicon
= RrPixmapToRGBA(ob_rr_inst
,
2283 (hints
->flags
& IconMaskHint
?
2284 hints
->icon_mask
: None
),
2285 (gint
*)&w
, (gint
*)&h
, &data
);
2286 obt_display_ignore_errors(FALSE
);
2289 if (w
> 0 && h
> 0) {
2291 img
= RrImageNewFromData(ob_rr_icons
, data
, w
, h
);
2293 RrImageAddFromData(img
, data
, w
, h
);
2303 /* set the client's icons to be whatever we found */
2304 RrImageUnref(self
->icon_set
);
2305 self
->icon_set
= img
;
2307 /* if the client has no icon at all, then we set a default icon onto it.
2308 but, if it has parents, then one of them will have an icon already
2310 if (!self
->icon_set
&& !self
->parents
) {
2311 RrPixel32
*icon
= ob_rr_theme
->def_win_icon
;
2312 gulong
*ldata
; /* use a long here to satisfy OBT_PROP_SETA32 */
2314 w
= ob_rr_theme
->def_win_icon_w
;
2315 h
= ob_rr_theme
->def_win_icon_h
;
2316 ldata
= g_new(gulong
, w
*h
+2);
2319 for (i
= 0; i
< w
*h
; ++i
)
2320 ldata
[i
+2] = (((icon
[i
] >> RrDefaultAlphaOffset
) & 0xff) << 24) +
2321 (((icon
[i
] >> RrDefaultRedOffset
) & 0xff) << 16) +
2322 (((icon
[i
] >> RrDefaultGreenOffset
) & 0xff) << 8) +
2323 (((icon
[i
] >> RrDefaultBlueOffset
) & 0xff) << 0);
2324 OBT_PROP_SETA32(self
->window
, NET_WM_ICON
, CARDINAL
, ldata
, w
*h
+2);
2326 } else if (self
->frame
)
2327 /* don't draw the icon empty if we're just setting one now anyways,
2328 we'll get the property change any second */
2329 frame_adjust_icon(self
->frame
);
2334 void client_update_icon_geometry(ObClient
*self
)
2339 RECT_SET(self
->icon_geometry
, 0, 0, 0, 0);
2341 if (OBT_PROP_GETA32(self
->window
, NET_WM_ICON_GEOMETRY
, CARDINAL
,
2345 /* don't let them set it with an area < 0 */
2346 RECT_SET(self
->icon_geometry
, data
[0], data
[1],
2347 MAX(data
[2],0), MAX(data
[3],0));
2352 static void client_get_session_ids(ObClient
*self
)
2359 if (!OBT_PROP_GET32(self
->window
, WM_CLIENT_LEADER
, WINDOW
, &leader
))
2362 /* get the SM_CLIENT_ID */
2363 if (leader
&& leader
!= self
->window
)
2364 OBT_PROP_GETS_XPCS(leader
, SM_CLIENT_ID
, &self
->sm_client_id
);
2366 OBT_PROP_GETS_XPCS(self
->window
, SM_CLIENT_ID
, &self
->sm_client_id
);
2368 /* get the WM_CLASS (name and class). make them "" if they are not
2370 got
= OBT_PROP_GETSS_TYPE(self
->window
, WM_CLASS
, STRING_NO_CC
, &ss
);
2374 self
->name
= g_strdup(ss
[0]);
2376 self
->class = g_strdup(ss
[1]);
2381 if (self
->name
== NULL
) self
->name
= g_strdup("");
2382 if (self
->class == NULL
) self
->class = g_strdup("");
2384 /* get the WM_CLASS (name and class) from the group leader. make them "" if
2385 they are not provided */
2387 got
= OBT_PROP_GETSS_TYPE(leader
, WM_CLASS
, STRING_NO_CC
, &ss
);
2393 self
->group_name
= g_strdup(ss
[0]);
2395 self
->group_class
= g_strdup(ss
[1]);
2400 if (self
->group_name
== NULL
) self
->group_name
= g_strdup("");
2401 if (self
->group_class
== NULL
) self
->group_class
= g_strdup("");
2403 /* get the WM_WINDOW_ROLE. make it "" if it is not provided */
2404 got
= OBT_PROP_GETS_XPCS(self
->window
, WM_WINDOW_ROLE
, &s
);
2409 self
->role
= g_strdup("");
2411 /* get the WM_COMMAND */
2415 got
= OBT_PROP_GETSS(leader
, WM_COMMAND
, &ss
);
2417 got
= OBT_PROP_GETSS(self
->window
, WM_COMMAND
, &ss
);
2420 /* merge/mash them all together */
2421 gchar
*merge
= NULL
;
2424 for (i
= 0; ss
[i
]; ++i
) {
2427 merge
= g_strconcat(merge
, ss
[i
], NULL
);
2429 merge
= g_strconcat(ss
[i
], NULL
);
2434 self
->wm_command
= merge
;
2437 /* get the WM_CLIENT_MACHINE */
2440 got
= OBT_PROP_GETS(leader
, WM_CLIENT_MACHINE
, &s
);
2442 got
= OBT_PROP_GETS(self
->window
, WM_CLIENT_MACHINE
, &s
);
2445 gchar localhost
[128];
2448 gethostname(localhost
, 127);
2449 localhost
[127] = '\0';
2450 if (strcmp(localhost
, s
) != 0)
2451 self
->client_machine
= s
;
2455 /* see if it has the PID set too (the PID requires that the
2456 WM_CLIENT_MACHINE be set) */
2457 if (OBT_PROP_GET32(self
->window
, NET_WM_PID
, CARDINAL
, &pid
))
2462 /*! Save the properties used for app matching rules, as seen by Openbox when
2463 the window mapped, so that users can still access them later if the app
2465 static void client_save_app_rule_values(ObClient
*self
)
2469 OBT_PROP_SETS(self
->window
, OB_APP_ROLE
, self
->role
);
2470 OBT_PROP_SETS(self
->window
, OB_APP_NAME
, self
->name
);
2471 OBT_PROP_SETS(self
->window
, OB_APP_CLASS
, self
->class);
2472 OBT_PROP_SETS(self
->window
, OB_APP_GROUP_NAME
, self
->group_name
);
2473 OBT_PROP_SETS(self
->window
, OB_APP_GROUP_CLASS
, self
->group_class
);
2474 OBT_PROP_SETS(self
->window
, OB_APP_TITLE
, self
->original_title
);
2476 switch (self
->type
) {
2477 case OB_CLIENT_TYPE_NORMAL
:
2478 type
= "normal"; break;
2479 case OB_CLIENT_TYPE_DIALOG
:
2480 type
= "dialog"; break;
2481 case OB_CLIENT_TYPE_UTILITY
:
2482 type
= "utility"; break;
2483 case OB_CLIENT_TYPE_MENU
:
2484 type
= "menu"; break;
2485 case OB_CLIENT_TYPE_TOOLBAR
:
2486 type
= "toolbar"; break;
2487 case OB_CLIENT_TYPE_SPLASH
:
2488 type
= "splash"; break;
2489 case OB_CLIENT_TYPE_DESKTOP
:
2490 type
= "desktop"; break;
2491 case OB_CLIENT_TYPE_DOCK
:
2492 type
= "dock"; break;
2494 OBT_PROP_SETS(self
->window
, OB_APP_TYPE
, type
);
2497 static void client_change_wm_state(ObClient
*self
)
2502 old
= self
->wmstate
;
2504 if (self
->shaded
|| self
->iconic
||
2505 (self
->desktop
!= DESKTOP_ALL
&& self
->desktop
!= screen_desktop
))
2507 self
->wmstate
= IconicState
;
2509 self
->wmstate
= NormalState
;
2511 if (old
!= self
->wmstate
) {
2512 OBT_PROP_MSG(ob_screen
, self
->window
, KDE_WM_CHANGE_STATE
,
2513 self
->wmstate
, 1, 0, 0, 0);
2515 state
[0] = self
->wmstate
;
2517 OBT_PROP_SETA32(self
->window
, WM_STATE
, WM_STATE
, state
, 2);
2521 static void client_change_state(ObClient
*self
)
2523 gulong netstate
[12];
2528 netstate
[num
++] = OBT_PROP_ATOM(NET_WM_STATE_MODAL
);
2530 netstate
[num
++] = OBT_PROP_ATOM(NET_WM_STATE_SHADED
);
2532 netstate
[num
++] = OBT_PROP_ATOM(NET_WM_STATE_HIDDEN
);
2533 if (self
->skip_taskbar
)
2534 netstate
[num
++] = OBT_PROP_ATOM(NET_WM_STATE_SKIP_TASKBAR
);
2535 if (self
->skip_pager
)
2536 netstate
[num
++] = OBT_PROP_ATOM(NET_WM_STATE_SKIP_PAGER
);
2537 if (self
->fullscreen
)
2538 netstate
[num
++] = OBT_PROP_ATOM(NET_WM_STATE_FULLSCREEN
);
2540 netstate
[num
++] = OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_VERT
);
2542 netstate
[num
++] = OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_HORZ
);
2544 netstate
[num
++] = OBT_PROP_ATOM(NET_WM_STATE_ABOVE
);
2546 netstate
[num
++] = OBT_PROP_ATOM(NET_WM_STATE_BELOW
);
2547 if (self
->demands_attention
)
2548 netstate
[num
++] = OBT_PROP_ATOM(NET_WM_STATE_DEMANDS_ATTENTION
);
2549 if (self
->undecorated
)
2550 netstate
[num
++] = OBT_PROP_ATOM(OB_WM_STATE_UNDECORATED
);
2551 OBT_PROP_SETA32(self
->window
, NET_WM_STATE
, ATOM
, netstate
, num
);
2554 frame_adjust_state(self
->frame
);
2557 ObClient
*client_search_focus_tree(ObClient
*self
)
2562 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
2563 if (client_focused(it
->data
)) return it
->data
;
2564 if ((ret
= client_search_focus_tree(it
->data
))) return ret
;
2569 ObClient
*client_search_focus_tree_full(ObClient
*self
)
2571 if (self
->parents
) {
2574 for (it
= self
->parents
; it
; it
= g_slist_next(it
)) {
2575 ObClient
*c
= it
->data
;
2576 if ((c
= client_search_focus_tree_full(c
))) return c
;
2582 /* this function checks the whole tree, the client_search_focus_tree
2583 does not, so we need to check this window */
2584 if (client_focused(self
))
2586 return client_search_focus_tree(self
);
2590 ObClient
*client_search_focus_group_full(ObClient
*self
)
2595 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
2596 ObClient
*c
= it
->data
;
2598 if (client_focused(c
)) return c
;
2599 if ((c
= client_search_focus_tree(it
->data
))) return c
;
2602 if (client_focused(self
)) return self
;
2606 gboolean
client_has_parent(ObClient
*self
)
2608 return self
->parents
!= NULL
;
2611 gboolean
client_has_children(ObClient
*self
)
2613 return self
->transients
!= NULL
;
2616 gboolean
client_is_oldfullscreen(const ObClient
*self
,
2619 const Rect
*monitor
, *allmonitors
;
2621 /* No decorations and fills the monitor = oldskool fullscreen.
2622 But not for maximized windows.
2625 if (self
->decorations
|| self
->max_horz
|| self
->max_vert
) return FALSE
;
2627 monitor
= screen_physical_area_monitor(screen_find_monitor(area
));
2628 allmonitors
= screen_physical_area_all_monitors();
2630 return (RECT_EQUAL(*area
, *monitor
) ||
2631 RECT_EQUAL(*area
, *allmonitors
));
2634 static ObStackingLayer
calc_layer(ObClient
*self
)
2638 if (self
->type
== OB_CLIENT_TYPE_DESKTOP
)
2639 l
= OB_STACKING_LAYER_DESKTOP
;
2640 else if (self
->type
== OB_CLIENT_TYPE_DOCK
) {
2641 if (self
->below
) l
= OB_STACKING_LAYER_NORMAL
;
2642 else l
= OB_STACKING_LAYER_ABOVE
;
2644 else if ((self
->fullscreen
||
2645 client_is_oldfullscreen(self
, &self
->area
)) &&
2646 /* you are fullscreen while you or your children are focused.. */
2647 (client_focused(self
) || client_search_focus_tree(self
) ||
2648 /* you can be fullscreen if you're on another desktop */
2649 (self
->desktop
!= screen_desktop
&&
2650 self
->desktop
!= DESKTOP_ALL
) ||
2651 /* and you can also be fullscreen if the focused client is on
2652 another monitor, or nothing else is focused */
2654 client_monitor(focus_client
) != client_monitor(self
))))
2655 l
= OB_STACKING_LAYER_FULLSCREEN
;
2656 else if (self
->above
) l
= OB_STACKING_LAYER_ABOVE
;
2657 else if (self
->below
) l
= OB_STACKING_LAYER_BELOW
;
2658 else l
= OB_STACKING_LAYER_NORMAL
;
2663 static void client_calc_layer_recursive(ObClient
*self
, ObClient
*orig
,
2664 ObStackingLayer min
)
2666 ObStackingLayer old
, own
;
2670 own
= calc_layer(self
);
2671 self
->layer
= MAX(own
, min
);
2673 if (self
->layer
!= old
) {
2674 stacking_remove(CLIENT_AS_WINDOW(self
));
2675 stacking_add_nonintrusive(CLIENT_AS_WINDOW(self
));
2678 /* we've been restacked */
2679 self
->visited
= TRUE
;
2681 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
2682 client_calc_layer_recursive(it
->data
, orig
,
2686 static void client_calc_layer_internal(ObClient
*self
)
2690 /* transients take on the layer of their parents */
2691 sit
= client_search_all_top_parents(self
);
2693 for (; sit
; sit
= g_slist_next(sit
))
2694 client_calc_layer_recursive(sit
->data
, self
, 0);
2697 void client_calc_layer(ObClient
*self
)
2701 /* skip over stuff above fullscreen layer */
2702 for (it
= stacking_list
; it
; it
= g_list_next(it
))
2703 if (window_layer(it
->data
) <= OB_STACKING_LAYER_FULLSCREEN
) break;
2705 /* find the windows in the fullscreen layer, and mark them not-visited */
2706 for (; it
; it
= g_list_next(it
)) {
2707 if (window_layer(it
->data
) < OB_STACKING_LAYER_FULLSCREEN
) break;
2708 else if (WINDOW_IS_CLIENT(it
->data
))
2709 WINDOW_AS_CLIENT(it
->data
)->visited
= FALSE
;
2712 client_calc_layer_internal(self
);
2714 /* skip over stuff above fullscreen layer */
2715 for (it
= stacking_list
; it
; it
= g_list_next(it
))
2716 if (window_layer(it
->data
) <= OB_STACKING_LAYER_FULLSCREEN
) break;
2718 /* now recalc any windows in the fullscreen layer which have not
2719 had their layer recalced already */
2720 for (; it
; it
= g_list_next(it
)) {
2721 if (window_layer(it
->data
) < OB_STACKING_LAYER_FULLSCREEN
) break;
2722 else if (WINDOW_IS_CLIENT(it
->data
) &&
2723 !WINDOW_AS_CLIENT(it
->data
)->visited
)
2724 client_calc_layer_internal(it
->data
);
2728 gboolean
client_should_show(ObClient
*self
)
2732 if (client_normal(self
) && screen_showing_desktop
)
2734 if (self
->desktop
== screen_desktop
|| self
->desktop
== DESKTOP_ALL
)
2740 gboolean
client_show(ObClient
*self
)
2742 gboolean show
= FALSE
;
2744 if (client_should_show(self
)) {
2745 /* replay pending pointer event before showing the window, in case it
2746 should be going to something under the window */
2747 mouse_replay_pointer();
2749 frame_show(self
->frame
);
2752 /* According to the ICCCM (sec 4.1.3.1) when a window is not visible,
2753 it needs to be in IconicState. This includes when it is on another
2756 client_change_wm_state(self
);
2761 gboolean
client_hide(ObClient
*self
)
2763 gboolean hide
= FALSE
;
2765 if (!client_should_show(self
)) {
2766 /* We don't need to ignore enter events here.
2767 The window can hide/iconify in 3 different ways:
2768 1 - through an x message. in this case we ignore all enter events
2769 caused by responding to the x message (unless underMouse)
2770 2 - by a keyboard action. in this case we ignore all enter events
2771 caused by the action
2772 3 - by a mouse action. in this case they are doing stuff with the
2773 mouse and focus _should_ move.
2775 Also in action_end, we simulate an enter event that can't be ignored
2776 so trying to ignore them is futile in case 3 anyways
2779 /* replay pending pointer event before hiding the window, in case it
2780 should be going to the window */
2781 mouse_replay_pointer();
2783 frame_hide(self
->frame
);
2786 /* According to the ICCCM (sec 4.1.3.1) when a window is not visible,
2787 it needs to be in IconicState. This includes when it is on another
2790 client_change_wm_state(self
);
2795 void client_showhide(ObClient
*self
)
2797 if (!client_show(self
))
2801 gboolean
client_normal(ObClient
*self
) {
2802 return ! (self
->type
== OB_CLIENT_TYPE_DESKTOP
||
2803 self
->type
== OB_CLIENT_TYPE_DOCK
||
2804 self
->type
== OB_CLIENT_TYPE_SPLASH
);
2807 gboolean
client_helper(ObClient
*self
)
2809 return (self
->type
== OB_CLIENT_TYPE_UTILITY
||
2810 self
->type
== OB_CLIENT_TYPE_MENU
||
2811 self
->type
== OB_CLIENT_TYPE_TOOLBAR
);
2814 gboolean
client_occupies_space(ObClient
*self
)
2816 return !(self
->type
== OB_CLIENT_TYPE_DESKTOP
||
2817 self
->type
== OB_CLIENT_TYPE_SPLASH
);
2820 gboolean
client_mouse_focusable(ObClient
*self
)
2822 return !(self
->type
== OB_CLIENT_TYPE_MENU
||
2823 self
->type
== OB_CLIENT_TYPE_TOOLBAR
||
2824 self
->type
== OB_CLIENT_TYPE_SPLASH
||
2825 self
->type
== OB_CLIENT_TYPE_DOCK
);
2828 gboolean
client_enter_focusable(ObClient
*self
)
2830 /* you can focus desktops but it shouldn't on enter */
2831 return (client_mouse_focusable(self
) &&
2832 self
->type
!= OB_CLIENT_TYPE_DESKTOP
);
2835 static void client_apply_startup_state(ObClient
*self
,
2836 gint x
, gint y
, gint w
, gint h
)
2838 /* save the states that we are going to apply */
2839 gboolean iconic
= self
->iconic
;
2840 gboolean fullscreen
= self
->fullscreen
;
2841 gboolean undecorated
= self
->undecorated
;
2842 gboolean shaded
= self
->shaded
;
2843 gboolean demands_attention
= self
->demands_attention
;
2844 gboolean max_horz
= self
->max_horz
;
2845 gboolean max_vert
= self
->max_vert
;
2849 /* turn them all off in the client, so they won't affect the window
2851 self
->iconic
= self
->fullscreen
= self
->undecorated
= self
->shaded
=
2852 self
->demands_attention
= self
->max_horz
= self
->max_vert
= FALSE
;
2854 /* move the client to its placed position, or it it's already there,
2855 generate a ConfigureNotify telling the client where it is.
2857 do this after adjusting the frame. otherwise it gets all weird and
2858 clients don't work right
2860 do this before applying the states so they have the correct
2861 pre-max/pre-fullscreen values
2863 client_try_configure(self
, &x
, &y
, &w
, &h
, &l
, &l
, FALSE
);
2864 ob_debug("placed window 0x%x at %d, %d with size %d x %d",
2865 self
->window
, x
, y
, w
, h
);
2866 /* save the area, and make it where it should be for the premax stuff */
2867 oldarea
= self
->area
;
2868 RECT_SET(self
->area
, x
, y
, w
, h
);
2870 /* apply the states. these are in a carefully crafted order.. */
2873 client_iconify(self
, TRUE
, FALSE
, TRUE
);
2875 client_set_undecorated(self
, TRUE
);
2877 client_shade(self
, TRUE
);
2878 if (demands_attention
)
2879 client_hilite(self
, TRUE
);
2881 if (max_vert
&& max_horz
)
2882 client_maximize(self
, TRUE
, 0);
2884 client_maximize(self
, TRUE
, 2);
2886 client_maximize(self
, TRUE
, 1);
2888 /* fullscreen removes the ability to apply other states */
2890 client_fullscreen(self
, TRUE
);
2892 /* make sure client_setup_decor_and_functions() is called at least once */
2893 client_setup_decor_and_functions(self
, FALSE
);
2895 /* if the window hasn't been configured yet, then do so now, in fact the
2896 x,y,w,h may _not_ be the same as the area rect, which can end up
2897 meaning that the client isn't properly moved/resized by the fullscreen
2899 pho can cause this because it maps at size of the screen but not 0,0
2900 so openbox moves it on screen to 0,0 (thus x,y=0,0 and area.x,y don't).
2901 then fullscreen'ing makes it go to 0,0 which it thinks it already is at
2902 cuz thats where the pre-fullscreen will be. however the actual area is
2903 not, so this needs to be called even if we have fullscreened/maxed
2905 self
->area
= oldarea
;
2906 client_configure(self
, x
, y
, w
, h
, FALSE
, TRUE
, FALSE
);
2908 /* nothing to do for the other states:
2917 void client_gravity_resize_w(ObClient
*self
, gint
*x
, gint oldw
, gint neww
)
2919 /* these should be the current values. this is for when you're not moving,
2921 g_assert(*x
== self
->area
.x
);
2922 g_assert(oldw
== self
->area
.width
);
2925 switch (self
->gravity
) {
2927 case NorthWestGravity
:
2929 case SouthWestGravity
:
2936 *x
-= (neww
- oldw
) / 2;
2938 case NorthEastGravity
:
2940 case SouthEastGravity
:
2946 void client_gravity_resize_h(ObClient
*self
, gint
*y
, gint oldh
, gint newh
)
2948 /* these should be the current values. this is for when you're not moving,
2950 g_assert(*y
== self
->area
.y
);
2951 g_assert(oldh
== self
->area
.height
);
2954 switch (self
->gravity
) {
2956 case NorthWestGravity
:
2958 case NorthEastGravity
:
2965 *y
-= (newh
- oldh
) / 2;
2967 case SouthWestGravity
:
2969 case SouthEastGravity
:
2975 void client_try_configure(ObClient
*self
, gint
*x
, gint
*y
, gint
*w
, gint
*h
,
2976 gint
*logicalw
, gint
*logicalh
,
2979 Rect desired
= {*x
, *y
, *w
, *h
};
2980 frame_rect_to_frame(self
->frame
, &desired
);
2982 /* make the frame recalculate its dimensions n shit without changing
2983 anything visible for real, this way the constraints below can work with
2984 the updated frame dimensions. */
2985 frame_adjust_area(self
->frame
, FALSE
, TRUE
, TRUE
);
2987 /* cap any X windows at the size of an unsigned short */
2990 - self
->frame
->size
.left
- self
->frame
->size
.right
);
2993 - self
->frame
->size
.top
- self
->frame
->size
.bottom
);
2995 /* gets the frame's position */
2996 frame_client_gravity(self
->frame
, x
, y
);
2998 /* these positions are frame positions, not client positions */
3000 /* set the size and position if fullscreen */
3001 if (self
->fullscreen
) {
3005 i
= screen_find_monitor(&desired
);
3006 a
= screen_physical_area_monitor(i
);
3013 user
= FALSE
; /* ignore if the client can't be moved/resized when it
3015 } else if (self
->max_horz
|| self
->max_vert
) {
3019 /* use all possible struts when maximizing to the full screen */
3020 i
= screen_find_monitor(&desired
);
3021 a
= screen_area(self
->desktop
, i
,
3022 (self
->max_horz
&& self
->max_vert
? NULL
: &desired
));
3024 /* set the size and position if maximized */
3025 if (self
->max_horz
) {
3027 *w
= a
->width
- self
->frame
->size
.left
- self
->frame
->size
.right
;
3029 if (self
->max_vert
) {
3031 *h
= a
->height
- self
->frame
->size
.top
- self
->frame
->size
.bottom
;
3034 user
= FALSE
; /* ignore if the client can't be moved/resized when it
3037 g_slice_free(Rect
, a
);
3040 /* gets the client's position */
3041 frame_frame_gravity(self
->frame
, x
, y
);
3043 /* work within the preferred sizes given by the window, these may have
3044 changed rather than it's requested width and height, so always run
3045 through this code */
3047 gint basew
, baseh
, minw
, minh
;
3048 gint incw
, inch
, maxw
, maxh
;
3049 gfloat minratio
, maxratio
;
3051 incw
= self
->size_inc
.width
;
3052 inch
= self
->size_inc
.height
;
3053 minratio
= self
->fullscreen
|| (self
->max_horz
&& self
->max_vert
) ?
3054 0 : self
->min_ratio
;
3055 maxratio
= self
->fullscreen
|| (self
->max_horz
&& self
->max_vert
) ?
3056 0 : self
->max_ratio
;
3058 /* base size is substituted with min size if not specified */
3059 if (self
->base_size
.width
>= 0 || self
->base_size
.height
>= 0) {
3060 basew
= self
->base_size
.width
;
3061 baseh
= self
->base_size
.height
;
3063 basew
= self
->min_size
.width
;
3064 baseh
= self
->min_size
.height
;
3066 /* min size is substituted with base size if not specified */
3067 if (self
->min_size
.width
|| self
->min_size
.height
) {
3068 minw
= self
->min_size
.width
;
3069 minh
= self
->min_size
.height
;
3071 minw
= self
->base_size
.width
;
3072 minh
= self
->base_size
.height
;
3075 /* This comment is no longer true */
3076 /* if this is a user-requested resize, then check against min/max
3079 /* smaller than min size or bigger than max size? */
3080 if (*w
> self
->max_size
.width
) *w
= self
->max_size
.width
;
3081 if (*w
< minw
) *w
= minw
;
3082 if (*h
> self
->max_size
.height
) *h
= self
->max_size
.height
;
3083 if (*h
< minh
) *h
= minh
;
3088 /* the sizes to used for maximized */
3092 /* keep to the increments */
3096 /* you cannot resize to nothing */
3097 if (basew
+ *w
< 1) *w
= 1 - basew
;
3098 if (baseh
+ *h
< 1) *h
= 1 - baseh
;
3100 /* save the logical size */
3101 *logicalw
= incw
> 1 ? *w
: *w
+ basew
;
3102 *logicalh
= inch
> 1 ? *h
: *h
+ baseh
;
3107 /* if maximized/fs then don't use the size increments */
3108 if (self
->fullscreen
|| self
->max_horz
) *w
= maxw
;
3109 if (self
->fullscreen
|| self
->max_vert
) *h
= maxh
;
3114 /* adjust the height to match the width for the aspect ratios.
3115 for this, min size is not substituted for base size ever. */
3116 *w
-= self
->base_size
.width
;
3117 *h
-= self
->base_size
.height
;
3120 if (*h
* minratio
> *w
) {
3121 *h
= (gint
)(*w
/ minratio
);
3123 /* you cannot resize to nothing */
3126 *w
= (gint
)(*h
* minratio
);
3130 if (*h
* maxratio
< *w
) {
3131 *h
= (gint
)(*w
/ maxratio
);
3133 /* you cannot resize to nothing */
3136 *w
= (gint
)(*h
* minratio
);
3140 *w
+= self
->base_size
.width
;
3141 *h
+= self
->base_size
.height
;
3144 /* these override the above states! if you cant move you can't move! */
3146 if (!(self
->functions
& OB_CLIENT_FUNC_MOVE
)) {
3150 if (!(self
->functions
& OB_CLIENT_FUNC_RESIZE
)) {
3151 *w
= self
->area
.width
;
3152 *h
= self
->area
.height
;
3160 void client_configure(ObClient
*self
, gint x
, gint y
, gint w
, gint h
,
3161 gboolean user
, gboolean final
, gboolean force_reply
)
3163 Rect oldframe
, oldclient
;
3164 gboolean send_resize_client
;
3165 gboolean moved
= FALSE
, resized
= FALSE
, rootmoved
= FALSE
;
3166 gboolean fmoved
, fresized
;
3167 guint fdecor
= self
->frame
->decorations
;
3168 gboolean fhorz
= self
->frame
->max_horz
;
3169 gboolean fvert
= self
->frame
->max_vert
;
3170 gint logicalw
, logicalh
;
3172 /* find the new x, y, width, and height (and logical size) */
3173 client_try_configure(self
, &x
, &y
, &w
, &h
, &logicalw
, &logicalh
, user
);
3175 /* set the logical size if things changed */
3176 if (!(w
== self
->area
.width
&& h
== self
->area
.height
))
3177 SIZE_SET(self
->logical_size
, logicalw
, logicalh
);
3179 /* figure out if we moved or resized or what */
3180 moved
= (x
!= self
->area
.x
|| y
!= self
->area
.y
);
3181 resized
= (w
!= self
->area
.width
|| h
!= self
->area
.height
);
3183 oldframe
= self
->frame
->area
;
3184 oldclient
= self
->area
;
3185 RECT_SET(self
->area
, x
, y
, w
, h
);
3187 /* for app-requested resizes, always resize if 'resized' is true.
3188 for user-requested ones, only resize if final is true, or when
3189 resizing in redraw mode */
3190 send_resize_client
= ((!user
&& resized
) ||
3192 (resized
&& config_resize_redraw
))));
3194 /* if the client is enlarging, then resize the client before the frame */
3195 if (send_resize_client
&& (w
> oldclient
.width
|| h
> oldclient
.height
)) {
3196 XMoveResizeWindow(obt_display
, self
->window
,
3197 self
->frame
->size
.left
, self
->frame
->size
.top
,
3198 MAX(w
, oldclient
.width
), MAX(h
, oldclient
.height
));
3199 frame_adjust_client_area(self
->frame
);
3202 /* find the frame's dimensions and move/resize it */
3206 /* if decorations changed, then readjust everything for the frame */
3207 if (self
->decorations
!= fdecor
||
3208 self
->max_horz
!= fhorz
|| self
->max_vert
!= fvert
)
3210 fmoved
= fresized
= TRUE
;
3213 /* adjust the frame */
3214 if (fmoved
|| fresized
) {
3215 gulong ignore_start
;
3217 ignore_start
= event_start_ignore_all_enters();
3219 /* replay pending pointer event before move the window, in case it
3220 would change what window gets the event */
3221 mouse_replay_pointer();
3223 frame_adjust_area(self
->frame
, fmoved
, fresized
, FALSE
);
3226 event_end_ignore_all_enters(ignore_start
);
3229 if (!user
|| final
) {
3230 gint oldrx
= self
->root_pos
.x
;
3231 gint oldry
= self
->root_pos
.y
;
3232 /* we have reset the client to 0 border width, so don't include
3233 it in these coords */
3234 POINT_SET(self
->root_pos
,
3235 self
->frame
->area
.x
+ self
->frame
->size
.left
-
3237 self
->frame
->area
.y
+ self
->frame
->size
.top
-
3238 self
->border_width
);
3239 if (self
->root_pos
.x
!= oldrx
|| self
->root_pos
.y
!= oldry
)
3243 /* This is kinda tricky and should not be changed.. let me explain!
3245 When user = FALSE, then the request is coming from the application
3246 itself, and we are more strict about when to send a synthetic
3247 ConfigureNotify. We strictly follow the rules of the ICCCM sec 4.1.5
3248 in this case (or send one if force_reply is true)
3250 When user = TRUE, then the request is coming from "us", like when we
3251 maximize a window or something. In this case we are more lenient. We
3252 used to follow the same rules as above, but _Java_ Swing can't handle
3253 this. So just to appease Swing, when user = TRUE, we always send
3254 a synthetic ConfigureNotify to give the window its root coordinates.
3255 Lastly, if force_reply is TRUE, we always send a
3256 ConfigureNotify, which is needed during a resize with XSYNCronization.
3258 if ((!user
&& !resized
&& (rootmoved
|| force_reply
)) ||
3259 (user
&& ((!resized
&& force_reply
) || (final
&& rootmoved
))))
3263 event
.type
= ConfigureNotify
;
3264 event
.xconfigure
.display
= obt_display
;
3265 event
.xconfigure
.event
= self
->window
;
3266 event
.xconfigure
.window
= self
->window
;
3268 ob_debug("Sending ConfigureNotify to %s for %d,%d %dx%d",
3269 self
->title
, self
->root_pos
.x
, self
->root_pos
.y
, w
, h
);
3271 /* root window real coords */
3272 event
.xconfigure
.x
= self
->root_pos
.x
;
3273 event
.xconfigure
.y
= self
->root_pos
.y
;
3274 event
.xconfigure
.width
= w
;
3275 event
.xconfigure
.height
= h
;
3276 event
.xconfigure
.border_width
= self
->border_width
;
3277 event
.xconfigure
.above
= None
;
3278 event
.xconfigure
.override_redirect
= FALSE
;
3279 XSendEvent(event
.xconfigure
.display
, event
.xconfigure
.window
,
3280 FALSE
, StructureNotifyMask
, &event
);
3283 /* if the client is shrinking, then resize the frame before the client.
3285 both of these resize sections may run, because the top one only resizes
3286 in the direction that is growing
3288 if (send_resize_client
&& (w
<= oldclient
.width
|| h
<= oldclient
.height
))
3290 frame_adjust_client_area(self
->frame
);
3291 XMoveResizeWindow(obt_display
, self
->window
,
3292 self
->frame
->size
.left
, self
->frame
->size
.top
, w
, h
);
3295 XFlush(obt_display
);
3297 /* if it moved between monitors, then this can affect the stacking
3298 layer of this window or others - for fullscreen windows.
3299 also if it changed to/from oldschool fullscreen then its layer may
3302 watch out tho, don't try change stacking stuff if the window is no
3303 longer being managed !
3305 if (self
->managed
&&
3306 (screen_find_monitor(&self
->frame
->area
) !=
3307 screen_find_monitor(&oldframe
) ||
3308 (final
&& (client_is_oldfullscreen(self
, &oldclient
) !=
3309 client_is_oldfullscreen(self
, &self
->area
)))))
3311 client_calc_layer(self
);
3315 void client_fullscreen(ObClient
*self
, gboolean fs
)
3319 if (!(self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
) || /* can't */
3320 self
->fullscreen
== fs
) return; /* already done */
3322 self
->fullscreen
= fs
;
3323 client_change_state(self
); /* change the state hints on the client */
3326 self
->pre_fullscreen_area
= self
->area
;
3327 self
->pre_fullscreen_max_horz
= self
->max_horz
;
3328 self
->pre_fullscreen_max_vert
= self
->max_vert
;
3330 /* if the window is maximized, its area isn't all that meaningful.
3331 save its premax area instead. */
3332 if (self
->max_horz
) {
3333 self
->pre_fullscreen_area
.x
= self
->pre_max_area
.x
;
3334 self
->pre_fullscreen_area
.width
= self
->pre_max_area
.width
;
3336 if (self
->max_vert
) {
3337 self
->pre_fullscreen_area
.y
= self
->pre_max_area
.y
;
3338 self
->pre_fullscreen_area
.height
= self
->pre_max_area
.height
;
3341 /* these will help configure_full figure out where to fullscreen
3345 w
= self
->area
.width
;
3346 h
= self
->area
.height
;
3348 g_assert(self
->pre_fullscreen_area
.width
> 0 &&
3349 self
->pre_fullscreen_area
.height
> 0);
3351 self
->max_horz
= self
->pre_fullscreen_max_horz
;
3352 self
->max_vert
= self
->pre_fullscreen_max_vert
;
3353 if (self
->max_horz
) {
3354 self
->pre_max_area
.x
= self
->pre_fullscreen_area
.x
;
3355 self
->pre_max_area
.width
= self
->pre_fullscreen_area
.width
;
3357 if (self
->max_vert
) {
3358 self
->pre_max_area
.y
= self
->pre_fullscreen_area
.y
;
3359 self
->pre_max_area
.height
= self
->pre_fullscreen_area
.height
;
3362 x
= self
->pre_fullscreen_area
.x
;
3363 y
= self
->pre_fullscreen_area
.y
;
3364 w
= self
->pre_fullscreen_area
.width
;
3365 h
= self
->pre_fullscreen_area
.height
;
3366 RECT_SET(self
->pre_fullscreen_area
, 0, 0, 0, 0);
3369 ob_debug("Window %s going fullscreen (%d)",
3370 self
->title
, self
->fullscreen
);
3373 /* make sure the window is on some monitor */
3374 client_find_onscreen(self
, &x
, &y
, w
, h
, FALSE
);
3377 client_setup_decor_and_functions(self
, FALSE
);
3378 client_move_resize(self
, x
, y
, w
, h
);
3380 /* and adjust our layer/stacking. do this after resizing the window,
3381 and applying decorations, because windows which fill the screen are
3382 considered "fullscreen" and it affects their layer */
3383 client_calc_layer(self
);
3386 /* try focus us when we go into fullscreen mode */
3391 static void client_iconify_recursive(ObClient
*self
,
3392 gboolean iconic
, gboolean curdesk
,
3393 gboolean hide_animation
)
3396 gboolean changed
= FALSE
;
3398 if (self
->iconic
!= iconic
) {
3399 ob_debug("%sconifying window: 0x%lx", (iconic
? "I" : "Uni"),
3403 /* don't let non-normal windows iconify along with their parents
3405 if (client_normal(self
)) {
3406 self
->iconic
= iconic
;
3408 /* update the focus lists.. iconic windows go to the bottom of
3409 the list. this will also call focus_cycle_addremove(). */
3410 focus_order_to_bottom(self
);
3415 self
->iconic
= iconic
;
3417 if (curdesk
&& self
->desktop
!= screen_desktop
&&
3418 self
->desktop
!= DESKTOP_ALL
)
3419 client_set_desktop(self
, screen_desktop
, FALSE
, FALSE
);
3421 /* this puts it after the current focused window, this will
3422 also cause focus_cycle_addremove() to be called for the
3424 focus_order_like_new(self
);
3431 client_change_state(self
);
3432 if (config_animate_iconify
&& !hide_animation
)
3433 frame_begin_iconify_animation(self
->frame
, iconic
);
3434 /* do this after starting the animation so it doesn't flash */
3435 client_showhide(self
);
3438 /* iconify all direct transients, and deiconify all transients
3440 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
3441 if (it
->data
!= self
)
3442 if (client_is_direct_child(self
, it
->data
) || !iconic
)
3443 client_iconify_recursive(it
->data
, iconic
, curdesk
,
3447 void client_iconify(ObClient
*self
, gboolean iconic
, gboolean curdesk
,
3448 gboolean hide_animation
)
3450 if (self
->functions
& OB_CLIENT_FUNC_ICONIFY
|| !iconic
) {
3451 /* move up the transient chain as far as possible first */
3452 self
= client_search_top_direct_parent(self
);
3453 client_iconify_recursive(self
, iconic
, curdesk
, hide_animation
);
3457 void client_maximize(ObClient
*self
, gboolean max
, gint dir
)
3461 g_assert(dir
== 0 || dir
== 1 || dir
== 2);
3462 if (!(self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) && max
) return;/* can't */
3464 /* check if already done */
3466 if (dir
== 0 && self
->max_horz
&& self
->max_vert
) return;
3467 if (dir
== 1 && self
->max_horz
) return;
3468 if (dir
== 2 && self
->max_vert
) return;
3470 if (dir
== 0 && !self
->max_horz
&& !self
->max_vert
) return;
3471 if (dir
== 1 && !self
->max_horz
) return;
3472 if (dir
== 2 && !self
->max_vert
) return;
3475 /* these will help configure_full figure out which screen to fill with
3479 w
= self
->area
.width
;
3480 h
= self
->area
.height
;
3483 if ((dir
== 0 || dir
== 1) && !self
->max_horz
) { /* horz */
3484 RECT_SET(self
->pre_max_area
,
3485 self
->area
.x
, self
->pre_max_area
.y
,
3486 self
->area
.width
, self
->pre_max_area
.height
);
3488 if ((dir
== 0 || dir
== 2) && !self
->max_vert
) { /* vert */
3489 RECT_SET(self
->pre_max_area
,
3490 self
->pre_max_area
.x
, self
->area
.y
,
3491 self
->pre_max_area
.width
, self
->area
.height
);
3494 if ((dir
== 0 || dir
== 1) && self
->max_horz
) { /* horz */
3495 g_assert(self
->pre_max_area
.width
> 0);
3497 x
= self
->pre_max_area
.x
;
3498 w
= self
->pre_max_area
.width
;
3500 RECT_SET(self
->pre_max_area
, 0, self
->pre_max_area
.y
,
3501 0, self
->pre_max_area
.height
);
3503 if ((dir
== 0 || dir
== 2) && self
->max_vert
) { /* vert */
3504 g_assert(self
->pre_max_area
.height
> 0);
3506 y
= self
->pre_max_area
.y
;
3507 h
= self
->pre_max_area
.height
;
3509 RECT_SET(self
->pre_max_area
, self
->pre_max_area
.x
, 0,
3510 self
->pre_max_area
.width
, 0);
3514 if (dir
== 0 || dir
== 1) /* horz */
3515 self
->max_horz
= max
;
3516 if (dir
== 0 || dir
== 2) /* vert */
3517 self
->max_vert
= max
;
3520 /* make sure the window is on some monitor */
3521 client_find_onscreen(self
, &x
, &y
, w
, h
, FALSE
);
3524 client_change_state(self
); /* change the state hints on the client */
3526 client_setup_decor_and_functions(self
, FALSE
);
3527 client_move_resize(self
, x
, y
, w
, h
);
3530 void client_shade(ObClient
*self
, gboolean shade
)
3532 if ((!(self
->functions
& OB_CLIENT_FUNC_SHADE
) &&
3533 shade
) || /* can't shade */
3534 self
->shaded
== shade
) return; /* already done */
3536 self
->shaded
= shade
;
3537 client_change_state(self
);
3538 client_change_wm_state(self
); /* the window is being hidden/shown */
3539 /* resize the frame to just the titlebar */
3540 frame_adjust_area(self
->frame
, FALSE
, TRUE
, FALSE
);
3543 static void client_ping_event(ObClient
*self
, gboolean dead
)
3545 if (self
->not_responding
!= dead
) {
3546 self
->not_responding
= dead
;
3547 client_update_title(self
);
3550 /* the client isn't responding, so ask to kill it */
3551 client_prompt_kill(self
);
3553 /* it came back to life ! */
3555 if (self
->kill_prompt
) {
3556 prompt_unref(self
->kill_prompt
);
3557 self
->kill_prompt
= NULL
;
3560 self
->kill_level
= 0;
3565 void client_close(ObClient
*self
)
3567 if (!(self
->functions
& OB_CLIENT_FUNC_CLOSE
)) return;
3569 /* if closing an internal obprompt, that is just cancelling it */
3571 prompt_cancel(self
->prompt
);
3575 /* in the case that the client provides no means to requesting that it
3576 close, we just kill it */
3577 if (!self
->delete_window
)
3578 /* don't use client_kill(), we should only kill based on PID in
3579 response to a lack of PING replies */
3580 XKillClient(obt_display
, self
->window
);
3582 /* request the client to close with WM_DELETE_WINDOW */
3583 OBT_PROP_MSG_TO(self
->window
, self
->window
, WM_PROTOCOLS
,
3584 OBT_PROP_ATOM(WM_DELETE_WINDOW
), event_time(),
3585 0, 0, 0, NoEventMask
);
3587 /* we're trying to close the window, so see if it is responding. if it
3588 is not, then we will let them kill the window */
3590 ping_start(self
, client_ping_event
);
3592 /* if we already know the window isn't responding (maybe they clicked
3593 no in the kill dialog but it hasn't come back to life), then show
3595 if (self
->not_responding
)
3596 client_prompt_kill(self
);
3600 #define OB_KILL_RESULT_NO 0
3601 #define OB_KILL_RESULT_YES 1
3603 static gboolean
client_kill_requested(ObPrompt
*p
, gint result
, gpointer data
)
3605 ObClient
*self
= data
;
3607 if (result
== OB_KILL_RESULT_YES
)
3609 return TRUE
; /* call the cleanup func */
3612 static void client_kill_cleanup(ObPrompt
*p
, gpointer data
)
3614 ObClient
*self
= data
;
3616 g_assert(p
== self
->kill_prompt
);
3618 prompt_unref(self
->kill_prompt
);
3619 self
->kill_prompt
= NULL
;
3622 static void client_prompt_kill(ObClient
*self
)
3624 /* check if we're already prompting */
3625 if (!self
->kill_prompt
) {
3626 ObPromptAnswer answers
[] = {
3627 { 0, OB_KILL_RESULT_NO
},
3628 { 0, OB_KILL_RESULT_YES
}
3631 const gchar
*y
, *title
;
3633 title
= self
->original_title
;
3634 if (title
[0] == '\0') {
3635 /* empty string, so use its parent */
3636 ObClient
*p
= client_search_top_direct_parent(self
);
3637 if (p
) title
= p
->original_title
;
3640 if (client_on_localhost(self
)) {
3643 if (self
->kill_level
== 0)
3649 (_("The window \"%s\" does not seem to be responding. Do you want to force it to exit by sending the %s signal?"),
3651 y
= _("End Process");
3655 (_("The window \"%s\" does not seem to be responding. Do you want to disconnect it from the X server?"),
3657 y
= _("Disconnect");
3659 /* set the dialog buttons' text */
3660 answers
[0].text
= _("Cancel"); /* "no" */
3661 answers
[1].text
= y
; /* "yes" */
3663 self
->kill_prompt
= prompt_new(m
, NULL
, answers
,
3664 sizeof(answers
)/sizeof(answers
[0]),
3665 OB_KILL_RESULT_NO
, /* default = no */
3666 OB_KILL_RESULT_NO
, /* cancel = no */
3667 client_kill_requested
,
3668 client_kill_cleanup
,
3673 prompt_show(self
->kill_prompt
, self
, TRUE
);
3676 void client_kill(ObClient
*self
)
3678 /* don't kill our own windows */
3679 if (self
->prompt
) return;
3681 if (client_on_localhost(self
) && self
->pid
) {
3682 /* running on the local host */
3683 if (self
->kill_level
== 0) {
3684 ob_debug("killing window 0x%x with pid %lu, with SIGTERM",
3685 self
->window
, self
->pid
);
3686 kill(self
->pid
, SIGTERM
);
3689 /* show that we're trying to kill it */
3690 client_update_title(self
);
3693 ob_debug("killing window 0x%x with pid %lu, with SIGKILL",
3694 self
->window
, self
->pid
);
3695 kill(self
->pid
, SIGKILL
); /* kill -9 */
3699 /* running on a remote host */
3700 XKillClient(obt_display
, self
->window
);
3704 void client_hilite(ObClient
*self
, gboolean hilite
)
3706 if (self
->demands_attention
== hilite
)
3707 return; /* no change */
3709 /* don't allow focused windows to hilite */
3710 self
->demands_attention
= hilite
&& !client_focused(self
);
3711 if (self
->frame
!= NULL
) { /* if we're mapping, just set the state */
3712 if (self
->demands_attention
) {
3713 frame_flash_start(self
->frame
);
3715 /* if the window is on another desktop then raise it and make it
3716 the most recently used window */
3717 if (self
->desktop
!= screen_desktop
&&
3718 self
->desktop
!= DESKTOP_ALL
)
3720 stacking_raise(CLIENT_AS_WINDOW(self
));
3721 focus_order_to_top(self
);
3725 frame_flash_stop(self
->frame
);
3726 client_change_state(self
);
3730 static void client_set_desktop_recursive(ObClient
*self
,
3738 if (target
!= self
->desktop
&& self
->type
!= OB_CLIENT_TYPE_DESKTOP
) {
3740 ob_debug("Setting desktop %u", target
+1);
3742 g_assert(target
< screen_num_desktops
|| target
== DESKTOP_ALL
);
3744 old
= self
->desktop
;
3745 self
->desktop
= target
;
3746 OBT_PROP_SET32(self
->window
, NET_WM_DESKTOP
, CARDINAL
, target
);
3747 /* the frame can display the current desktop state */
3748 frame_adjust_state(self
->frame
);
3749 /* 'move' the window to the new desktop */
3753 /* raise if it was not already on the desktop */
3754 if (old
!= DESKTOP_ALL
&& !dontraise
)
3755 stacking_raise(CLIENT_AS_WINDOW(self
));
3756 if (STRUT_EXISTS(self
->strut
))
3757 screen_update_areas();
3759 /* the new desktop's geometry may be different, so we may need to
3760 resize, for example if we are maximized */
3761 client_reconfigure(self
, FALSE
);
3763 focus_cycle_addremove(self
, FALSE
);
3766 /* move all transients */
3767 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
3768 if (it
->data
!= self
)
3769 if (client_is_direct_child(self
, it
->data
))
3770 client_set_desktop_recursive(it
->data
, target
,
3771 donthide
, dontraise
);
3774 void client_set_desktop(ObClient
*self
, guint target
,
3775 gboolean donthide
, gboolean dontraise
)
3777 self
= client_search_top_direct_parent(self
);
3778 client_set_desktop_recursive(self
, target
, donthide
, dontraise
);
3780 focus_cycle_addremove(NULL
, TRUE
);
3783 gboolean
client_is_direct_child(ObClient
*parent
, ObClient
*child
)
3785 while (child
!= parent
&& (child
= client_direct_parent(child
)));
3786 return child
== parent
;
3789 ObClient
*client_search_modal_child(ObClient
*self
)
3794 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
3795 ObClient
*c
= it
->data
;
3796 if ((ret
= client_search_modal_child(c
))) return ret
;
3797 if (c
->modal
) return c
;
3802 struct ObClientFindDestroyUnmap
{
3807 static gboolean
find_destroy_unmap(XEvent
*e
, gpointer data
)
3809 struct ObClientFindDestroyUnmap
*find
= data
;
3810 if (e
->type
== DestroyNotify
)
3811 return e
->xdestroywindow
.window
== find
->window
;
3812 if (e
->type
== UnmapNotify
&& e
->xunmap
.window
== find
->window
)
3813 /* ignore the first $find->ignore_unmaps$ many unmap events */
3814 return --find
->ignore_unmaps
< 0;
3818 gboolean
client_validate(ObClient
*self
)
3820 struct ObClientFindDestroyUnmap find
;
3822 XSync(obt_display
, FALSE
); /* get all events on the server */
3824 find
.window
= self
->window
;
3825 find
.ignore_unmaps
= self
->ignore_unmaps
;
3826 if (xqueue_exists_local(find_destroy_unmap
, &find
))
3832 void client_set_wm_state(ObClient
*self
, glong state
)
3834 if (state
== self
->wmstate
) return; /* no change */
3838 client_iconify(self
, TRUE
, TRUE
, FALSE
);
3841 client_iconify(self
, FALSE
, TRUE
, FALSE
);
3846 void client_set_state(ObClient
*self
, Atom action
, glong data1
, glong data2
)
3848 gboolean shaded
= self
->shaded
;
3849 gboolean fullscreen
= self
->fullscreen
;
3850 gboolean undecorated
= self
->undecorated
;
3851 gboolean max_horz
= self
->max_horz
;
3852 gboolean max_vert
= self
->max_vert
;
3853 gboolean modal
= self
->modal
;
3854 gboolean iconic
= self
->iconic
;
3855 gboolean demands_attention
= self
->demands_attention
;
3856 gboolean above
= self
->above
;
3857 gboolean below
= self
->below
;
3861 if (!(action
== OBT_PROP_ATOM(NET_WM_STATE_ADD
) ||
3862 action
== OBT_PROP_ATOM(NET_WM_STATE_REMOVE
) ||
3863 action
== OBT_PROP_ATOM(NET_WM_STATE_TOGGLE
)))
3864 /* an invalid action was passed to the client message, ignore it */
3867 for (i
= 0; i
< 2; ++i
) {
3868 Atom state
= i
== 0 ? data1
: data2
;
3870 if (!state
) continue;
3872 /* if toggling, then pick whether we're adding or removing */
3873 if (action
== OBT_PROP_ATOM(NET_WM_STATE_TOGGLE
)) {
3874 if (state
== OBT_PROP_ATOM(NET_WM_STATE_MODAL
))
3876 else if (state
== OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_VERT
))
3877 value
= self
->max_vert
;
3878 else if (state
== OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_HORZ
))
3879 value
= self
->max_horz
;
3880 else if (state
== OBT_PROP_ATOM(NET_WM_STATE_SHADED
))
3882 else if (state
== OBT_PROP_ATOM(NET_WM_STATE_SKIP_TASKBAR
))
3883 value
= self
->skip_taskbar
;
3884 else if (state
== OBT_PROP_ATOM(NET_WM_STATE_SKIP_PAGER
))
3885 value
= self
->skip_pager
;
3886 else if (state
== OBT_PROP_ATOM(NET_WM_STATE_HIDDEN
))
3887 value
= self
->iconic
;
3888 else if (state
== OBT_PROP_ATOM(NET_WM_STATE_FULLSCREEN
))
3890 else if (state
== OBT_PROP_ATOM(NET_WM_STATE_ABOVE
))
3891 value
= self
->above
;
3892 else if (state
== OBT_PROP_ATOM(NET_WM_STATE_BELOW
))
3893 value
= self
->below
;
3894 else if (state
== OBT_PROP_ATOM(NET_WM_STATE_DEMANDS_ATTENTION
))
3895 value
= self
->demands_attention
;
3896 else if (state
== OBT_PROP_ATOM(OB_WM_STATE_UNDECORATED
))
3897 value
= undecorated
;
3899 g_assert_not_reached();
3900 action
= value
? OBT_PROP_ATOM(NET_WM_STATE_REMOVE
) :
3901 OBT_PROP_ATOM(NET_WM_STATE_ADD
);
3904 value
= action
== OBT_PROP_ATOM(NET_WM_STATE_ADD
);
3905 if (state
== OBT_PROP_ATOM(NET_WM_STATE_MODAL
)) {
3907 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_VERT
)) {
3909 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_HORZ
)) {
3911 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_SHADED
)) {
3913 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_SKIP_TASKBAR
)) {
3914 self
->skip_taskbar
= value
;
3915 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_SKIP_PAGER
)) {
3916 self
->skip_pager
= value
;
3917 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_HIDDEN
)) {
3919 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_FULLSCREEN
)) {
3921 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_ABOVE
)) {
3923 /* only unset below when setting above, otherwise you can't get to
3927 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_BELOW
)) {
3928 /* and vice versa */
3932 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_DEMANDS_ATTENTION
)){
3933 demands_attention
= value
;
3934 } else if (state
== OBT_PROP_ATOM(OB_WM_STATE_UNDECORATED
)) {
3935 undecorated
= value
;
3939 if (max_horz
!= self
->max_horz
|| max_vert
!= self
->max_vert
) {
3940 if (max_horz
!= self
->max_horz
&& max_vert
!= self
->max_vert
) {
3942 if (max_horz
== max_vert
) { /* both going the same way */
3943 client_maximize(self
, max_horz
, 0);
3945 client_maximize(self
, max_horz
, 1);
3946 client_maximize(self
, max_vert
, 2);
3950 if (max_horz
!= self
->max_horz
)
3951 client_maximize(self
, max_horz
, 1);
3953 client_maximize(self
, max_vert
, 2);
3956 /* change fullscreen state before shading, as it will affect if the window
3958 if (fullscreen
!= self
->fullscreen
)
3959 client_fullscreen(self
, fullscreen
);
3960 if (shaded
!= self
->shaded
)
3961 client_shade(self
, shaded
);
3962 if (undecorated
!= self
->undecorated
)
3963 client_set_undecorated(self
, undecorated
);
3964 if (above
!= self
->above
|| below
!= self
->below
) {
3965 self
->above
= above
;
3966 self
->below
= below
;
3967 client_calc_layer(self
);
3970 if (modal
!= self
->modal
) {
3971 self
->modal
= modal
;
3972 /* when a window changes modality, then its stacking order with its
3973 transients needs to change */
3974 stacking_raise(CLIENT_AS_WINDOW(self
));
3976 /* it also may get focused. if something is focused that shouldn't
3977 be focused anymore, then move the focus */
3978 if (focus_client
&& client_focus_target(focus_client
) != focus_client
)
3979 client_focus(focus_client
);
3982 if (iconic
!= self
->iconic
)
3983 client_iconify(self
, iconic
, FALSE
, FALSE
);
3985 if (demands_attention
!= self
->demands_attention
)
3986 client_hilite(self
, demands_attention
);
3988 client_change_state(self
); /* change the hint to reflect these changes */
3990 focus_cycle_addremove(self
, TRUE
);
3993 ObClient
*client_focus_target(ObClient
*self
)
3995 ObClient
*child
= NULL
;
3997 child
= client_search_modal_child(self
);
3998 if (child
) return child
;
4002 gboolean
client_can_focus(ObClient
*self
)
4004 /* choose the correct target */
4005 self
= client_focus_target(self
);
4007 if (!self
->frame
->visible
)
4010 if (!(self
->can_focus
|| self
->focus_notify
))
4016 gboolean
client_focus(ObClient
*self
)
4018 if (!client_validate(self
)) return FALSE
;
4020 /* we might not focus this window, so if we have modal children which would
4021 be focused instead, bring them to this desktop */
4022 client_bring_modal_windows(self
);
4024 /* choose the correct target */
4025 self
= client_focus_target(self
);
4027 if (!client_can_focus(self
)) {
4028 ob_debug_type(OB_DEBUG_FOCUS
,
4029 "Client %s can't be focused", self
->title
);
4033 /* if we have helper windows they should be there with the window */
4034 client_bring_helper_windows(self
);
4036 ob_debug_type(OB_DEBUG_FOCUS
,
4037 "Focusing client \"%s\" (0x%x) at time %u",
4038 self
->title
, self
->window
, event_time());
4040 /* if using focus_delay, stop the timer now so that focus doesn't
4042 event_halt_focus_delay();
4044 obt_display_ignore_errors(TRUE
);
4046 if (self
->can_focus
) {
4047 /* This can cause a BadMatch error with CurrentTime, or if an app
4048 passed in a bad time for _NET_WM_ACTIVE_WINDOW. */
4049 XSetInputFocus(obt_display
, self
->window
, RevertToPointerRoot
,
4053 if (self
->focus_notify
) {
4055 ce
.xclient
.type
= ClientMessage
;
4056 ce
.xclient
.message_type
= OBT_PROP_ATOM(WM_PROTOCOLS
);
4057 ce
.xclient
.display
= obt_display
;
4058 ce
.xclient
.window
= self
->window
;
4059 ce
.xclient
.format
= 32;
4060 ce
.xclient
.data
.l
[0] = OBT_PROP_ATOM(WM_TAKE_FOCUS
);
4061 ce
.xclient
.data
.l
[1] = event_time();
4062 ce
.xclient
.data
.l
[2] = 0l;
4063 ce
.xclient
.data
.l
[3] = 0l;
4064 ce
.xclient
.data
.l
[4] = 0l;
4065 XSendEvent(obt_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
4068 obt_display_ignore_errors(FALSE
);
4070 ob_debug_type(OB_DEBUG_FOCUS
, "Error focusing? %d",
4071 obt_display_error_occured
);
4072 return !obt_display_error_occured
;
4075 static void client_present(ObClient
*self
, gboolean here
, gboolean raise
,
4078 if (client_normal(self
) && screen_showing_desktop
)
4079 screen_show_desktop(FALSE
, self
);
4081 client_iconify(self
, FALSE
, here
, FALSE
);
4082 if (self
->desktop
!= DESKTOP_ALL
&&
4083 self
->desktop
!= screen_desktop
)
4086 client_set_desktop(self
, screen_desktop
, FALSE
, TRUE
);
4088 screen_set_desktop(self
->desktop
, FALSE
);
4089 } else if (!self
->frame
->visible
)
4090 /* if its not visible for other reasons, then don't mess
4093 if (self
->shaded
&& unshade
)
4094 client_shade(self
, FALSE
);
4096 stacking_raise(CLIENT_AS_WINDOW(self
));
4101 /* this function exists to map to the net_active_window message in the ewmh */
4102 void client_activate(ObClient
*self
, gboolean desktop
,
4103 gboolean here
, gboolean raise
,
4104 gboolean unshade
, gboolean user
)
4106 self
= client_focus_target(self
);
4108 if (client_can_steal_focus(self
, desktop
, user
, event_time(), CurrentTime
))
4109 client_present(self
, here
, raise
, unshade
);
4111 client_hilite(self
, TRUE
);
4114 static void client_bring_windows_recursive(ObClient
*self
,
4122 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
4123 client_bring_windows_recursive(it
->data
, desktop
,
4124 helpers
, modals
, iconic
);
4126 if (((helpers
&& client_helper(self
)) ||
4127 (modals
&& self
->modal
)) &&
4128 (!screen_compare_desktops(self
->desktop
, desktop
) ||
4129 (iconic
&& self
->iconic
)))
4131 if (iconic
&& self
->iconic
)
4132 client_iconify(self
, FALSE
, TRUE
, FALSE
);
4134 client_set_desktop(self
, desktop
, FALSE
, FALSE
);
4138 void client_bring_helper_windows(ObClient
*self
)
4140 client_bring_windows_recursive(self
, self
->desktop
, TRUE
, FALSE
, FALSE
);
4143 void client_bring_modal_windows(ObClient
*self
)
4145 client_bring_windows_recursive(self
, self
->desktop
, FALSE
, TRUE
, TRUE
);
4148 gboolean
client_focused(ObClient
*self
)
4150 return self
== focus_client
;
4153 RrImage
* client_icon(ObClient
*self
)
4155 RrImage
*ret
= NULL
;
4158 ret
= self
->icon_set
;
4159 else if (self
->parents
) {
4161 for (it
= self
->parents
; it
&& !ret
; it
= g_slist_next(it
))
4162 ret
= client_icon(it
->data
);
4165 ret
= client_default_icon
;
4169 void client_set_layer(ObClient
*self
, gint layer
)
4173 self
->above
= FALSE
;
4174 } else if (layer
== 0) {
4175 self
->below
= self
->above
= FALSE
;
4177 self
->below
= FALSE
;
4180 client_calc_layer(self
);
4181 client_change_state(self
); /* reflect this in the state hints */
4184 void client_set_undecorated(ObClient
*self
, gboolean undecorated
)
4186 if (self
->undecorated
!= undecorated
&&
4187 /* don't let it undecorate if the function is missing, but let
4189 (self
->functions
& OB_CLIENT_FUNC_UNDECORATE
|| !undecorated
))
4191 self
->undecorated
= undecorated
;
4192 client_setup_decor_and_functions(self
, TRUE
);
4193 client_change_state(self
); /* reflect this in the state hints */
4197 guint
client_monitor(ObClient
*self
)
4199 return screen_find_monitor(&self
->frame
->area
);
4202 ObClient
*client_direct_parent(ObClient
*self
)
4204 if (!self
->parents
) return NULL
;
4205 if (self
->transient_for_group
) return NULL
;
4206 return self
->parents
->data
;
4209 ObClient
*client_search_top_direct_parent(ObClient
*self
)
4212 while ((p
= client_direct_parent(self
))) self
= p
;
4216 static GSList
*client_search_all_top_parents_internal(ObClient
*self
,
4218 ObStackingLayer layer
)
4223 /* move up the direct transient chain as far as possible */
4224 while ((p
= client_direct_parent(self
)) &&
4225 (!bylayer
|| p
->layer
== layer
))
4229 ret
= g_slist_prepend(NULL
, self
);
4231 ret
= g_slist_copy(self
->parents
);
4236 GSList
*client_search_all_top_parents(ObClient
*self
)
4238 return client_search_all_top_parents_internal(self
, FALSE
, 0);
4241 GSList
*client_search_all_top_parents_layer(ObClient
*self
)
4243 return client_search_all_top_parents_internal(self
, TRUE
, self
->layer
);
4246 ObClient
*client_search_focus_parent(ObClient
*self
)
4250 for (it
= self
->parents
; it
; it
= g_slist_next(it
))
4251 if (client_focused(it
->data
)) return it
->data
;
4256 ObClient
*client_search_focus_parent_full(ObClient
*self
)
4259 ObClient
*ret
= NULL
;
4261 for (it
= self
->parents
; it
; it
= g_slist_next(it
)) {
4262 if (client_focused(it
->data
))
4265 ret
= client_search_focus_parent_full(it
->data
);
4271 ObClient
*client_search_parent(ObClient
*self
, ObClient
*search
)
4275 for (it
= self
->parents
; it
; it
= g_slist_next(it
))
4276 if (it
->data
== search
) return search
;
4281 ObClient
*client_search_transient(ObClient
*self
, ObClient
*search
)
4285 for (sit
= self
->transients
; sit
; sit
= g_slist_next(sit
)) {
4286 if (sit
->data
== search
)
4288 if (client_search_transient(sit
->data
, search
))
4294 static void detect_edge(Rect area
, ObDirection dir
,
4295 gint my_head
, gint my_size
,
4296 gint my_edge_start
, gint my_edge_size
,
4297 gint
*dest
, gboolean
*near_edge
)
4299 gint edge_start
, edge_size
, head
, tail
;
4300 gboolean skip_head
= FALSE
, skip_tail
= FALSE
;
4303 case OB_DIRECTION_NORTH
:
4304 case OB_DIRECTION_SOUTH
:
4305 edge_start
= area
.x
;
4306 edge_size
= area
.width
;
4308 case OB_DIRECTION_EAST
:
4309 case OB_DIRECTION_WEST
:
4310 edge_start
= area
.y
;
4311 edge_size
= area
.height
;
4314 g_assert_not_reached();
4317 /* do we collide with this window? */
4318 if (!RANGES_INTERSECT(my_edge_start
, my_edge_size
,
4319 edge_start
, edge_size
))
4323 case OB_DIRECTION_NORTH
:
4324 head
= RECT_BOTTOM(area
);
4325 tail
= RECT_TOP(area
);
4327 case OB_DIRECTION_SOUTH
:
4328 head
= RECT_TOP(area
);
4329 tail
= RECT_BOTTOM(area
);
4331 case OB_DIRECTION_WEST
:
4332 head
= RECT_RIGHT(area
);
4333 tail
= RECT_LEFT(area
);
4335 case OB_DIRECTION_EAST
:
4336 head
= RECT_LEFT(area
);
4337 tail
= RECT_RIGHT(area
);
4340 g_assert_not_reached();
4343 case OB_DIRECTION_NORTH
:
4344 case OB_DIRECTION_WEST
:
4345 /* check if our window is past the head of this window */
4346 if (my_head
<= head
+ 1)
4348 /* check if our window's tail is past the tail of this window */
4349 if (my_head
+ my_size
- 1 <= tail
)
4351 /* check if the head of this window is closer than the previously
4352 chosen edge (take into account that the previously chosen
4353 edge might have been a tail, not a head) */
4354 if (head
+ (*near_edge
? 0 : my_size
) <= *dest
)
4356 /* check if the tail of this window is closer than the previously
4357 chosen edge (take into account that the previously chosen
4358 edge might have been a head, not a tail) */
4359 if (tail
- (!*near_edge
? 0 : my_size
) <= *dest
)
4362 case OB_DIRECTION_SOUTH
:
4363 case OB_DIRECTION_EAST
:
4364 /* check if our window is past the head of this window */
4365 if (my_head
>= head
- 1)
4367 /* check if our window's tail is past the tail of this window */
4368 if (my_head
- my_size
+ 1 >= tail
)
4370 /* check if the head of this window is closer than the previously
4371 chosen edge (take into account that the previously chosen
4372 edge might have been a tail, not a head) */
4373 if (head
- (*near_edge
? 0 : my_size
) >= *dest
)
4375 /* check if the tail of this window is closer than the previously
4376 chosen edge (take into account that the previously chosen
4377 edge might have been a head, not a tail) */
4378 if (tail
+ (!*near_edge
? 0 : my_size
) >= *dest
)
4382 g_assert_not_reached();
4385 ob_debug("my head %d size %d", my_head
, my_size
);
4386 ob_debug("head %d tail %d dest %d", head
, tail
, *dest
);
4388 ob_debug("using near edge %d", head
);
4392 else if (!skip_tail
) {
4393 ob_debug("using far edge %d", tail
);
4399 void client_find_edge_directional(ObClient
*self
, ObDirection dir
,
4400 gint my_head
, gint my_size
,
4401 gint my_edge_start
, gint my_edge_size
,
4402 gint
*dest
, gboolean
*near_edge
)
4410 a
= screen_area(self
->desktop
, SCREEN_AREA_ALL_MONITORS
,
4411 &self
->frame
->area
);
4414 case OB_DIRECTION_NORTH
:
4415 edge
= RECT_TOP(*a
) - 1;
4417 case OB_DIRECTION_SOUTH
:
4418 edge
= RECT_BOTTOM(*a
) + 1;
4420 case OB_DIRECTION_EAST
:
4421 edge
= RECT_RIGHT(*a
) + 1;
4423 case OB_DIRECTION_WEST
:
4424 edge
= RECT_LEFT(*a
) - 1;
4427 g_assert_not_reached();
4429 /* default to the far edge, then narrow it down */
4433 /* search for edges of monitors */
4434 for (i
= 0; i
< screen_num_monitors
; ++i
) {
4435 Rect
*area
= screen_area(self
->desktop
, i
, NULL
);
4436 detect_edge(*area
, dir
, my_head
, my_size
, my_edge_start
,
4437 my_edge_size
, dest
, near_edge
);
4438 g_slice_free(Rect
, area
);
4441 /* search for edges of clients */
4442 for (it
= client_list
; it
; it
= g_list_next(it
)) {
4443 ObClient
*cur
= it
->data
;
4445 /* skip windows to not bump into */
4450 if (self
->desktop
!= cur
->desktop
&& cur
->desktop
!= DESKTOP_ALL
&&
4451 cur
->desktop
!= screen_desktop
)
4454 ob_debug("trying window %s", cur
->title
);
4456 detect_edge(cur
->frame
->area
, dir
, my_head
, my_size
, my_edge_start
,
4457 my_edge_size
, dest
, near_edge
);
4459 dock_get_area(&dock_area
);
4460 detect_edge(dock_area
, dir
, my_head
, my_size
, my_edge_start
,
4461 my_edge_size
, dest
, near_edge
);
4463 g_slice_free(Rect
, a
);
4466 void client_find_move_directional(ObClient
*self
, ObDirection dir
,
4470 gint e
, e_start
, e_size
;
4474 case OB_DIRECTION_EAST
:
4475 head
= RECT_RIGHT(self
->frame
->area
);
4476 size
= self
->frame
->area
.width
;
4477 e_start
= RECT_TOP(self
->frame
->area
);
4478 e_size
= self
->frame
->area
.height
;
4480 case OB_DIRECTION_WEST
:
4481 head
= RECT_LEFT(self
->frame
->area
);
4482 size
= self
->frame
->area
.width
;
4483 e_start
= RECT_TOP(self
->frame
->area
);
4484 e_size
= self
->frame
->area
.height
;
4486 case OB_DIRECTION_NORTH
:
4487 head
= RECT_TOP(self
->frame
->area
);
4488 size
= self
->frame
->area
.height
;
4489 e_start
= RECT_LEFT(self
->frame
->area
);
4490 e_size
= self
->frame
->area
.width
;
4492 case OB_DIRECTION_SOUTH
:
4493 head
= RECT_BOTTOM(self
->frame
->area
);
4494 size
= self
->frame
->area
.height
;
4495 e_start
= RECT_LEFT(self
->frame
->area
);
4496 e_size
= self
->frame
->area
.width
;
4499 g_assert_not_reached();
4502 client_find_edge_directional(self
, dir
, head
, size
,
4503 e_start
, e_size
, &e
, &near
);
4504 *x
= self
->frame
->area
.x
;
4505 *y
= self
->frame
->area
.y
;
4507 case OB_DIRECTION_EAST
:
4508 if (near
) e
-= self
->frame
->area
.width
;
4512 case OB_DIRECTION_WEST
:
4514 else e
-= self
->frame
->area
.width
;
4517 case OB_DIRECTION_NORTH
:
4519 else e
-= self
->frame
->area
.height
;
4522 case OB_DIRECTION_SOUTH
:
4523 if (near
) e
-= self
->frame
->area
.height
;
4528 g_assert_not_reached();
4530 frame_frame_gravity(self
->frame
, x
, y
);
4533 void client_find_resize_directional(ObClient
*self
, ObDirection side
,
4535 gint
*x
, gint
*y
, gint
*w
, gint
*h
)
4538 gint e
, e_start
, e_size
, delta
;
4543 case OB_DIRECTION_EAST
:
4544 head
= RECT_RIGHT(self
->frame
->area
) +
4545 (self
->size_inc
.width
- 1) * (grow
? 1 : 0);
4546 e_start
= RECT_TOP(self
->frame
->area
);
4547 e_size
= self
->frame
->area
.height
;
4548 dir
= grow
? OB_DIRECTION_EAST
: OB_DIRECTION_WEST
;
4550 case OB_DIRECTION_WEST
:
4551 head
= RECT_LEFT(self
->frame
->area
) -
4552 (self
->size_inc
.width
- 1) * (grow
? 1 : 0);
4553 e_start
= RECT_TOP(self
->frame
->area
);
4554 e_size
= self
->frame
->area
.height
;
4555 dir
= grow
? OB_DIRECTION_WEST
: OB_DIRECTION_EAST
;
4557 case OB_DIRECTION_NORTH
:
4558 head
= RECT_TOP(self
->frame
->area
) -
4559 (self
->size_inc
.height
- 1) * (grow
? 1 : 0);
4560 e_start
= RECT_LEFT(self
->frame
->area
);
4561 e_size
= self
->frame
->area
.width
;
4562 dir
= grow
? OB_DIRECTION_NORTH
: OB_DIRECTION_SOUTH
;
4564 case OB_DIRECTION_SOUTH
:
4565 head
= RECT_BOTTOM(self
->frame
->area
) +
4566 (self
->size_inc
.height
- 1) * (grow
? 1 : 0);
4567 e_start
= RECT_LEFT(self
->frame
->area
);
4568 e_size
= self
->frame
->area
.width
;
4569 dir
= grow
? OB_DIRECTION_SOUTH
: OB_DIRECTION_NORTH
;
4572 g_assert_not_reached();
4575 ob_debug("head %d dir %d", head
, dir
);
4576 client_find_edge_directional(self
, dir
, head
, 1,
4577 e_start
, e_size
, &e
, &near
);
4578 ob_debug("edge %d", e
);
4579 *x
= self
->frame
->area
.x
;
4580 *y
= self
->frame
->area
.y
;
4581 *w
= self
->frame
->area
.width
;
4582 *h
= self
->frame
->area
.height
;
4584 case OB_DIRECTION_EAST
:
4585 if (grow
== near
) --e
;
4586 delta
= e
- RECT_RIGHT(self
->frame
->area
);
4589 case OB_DIRECTION_WEST
:
4590 if (grow
== near
) ++e
;
4591 delta
= RECT_LEFT(self
->frame
->area
) - e
;
4595 case OB_DIRECTION_NORTH
:
4596 if (grow
== near
) ++e
;
4597 delta
= RECT_TOP(self
->frame
->area
) - e
;
4601 case OB_DIRECTION_SOUTH
:
4602 if (grow
== near
) --e
;
4603 delta
= e
- RECT_BOTTOM(self
->frame
->area
);
4607 g_assert_not_reached();
4609 frame_frame_gravity(self
->frame
, x
, y
);
4610 *w
-= self
->frame
->size
.left
+ self
->frame
->size
.right
;
4611 *h
-= self
->frame
->size
.top
+ self
->frame
->size
.bottom
;
4614 ObClient
* client_under_pointer(void)
4618 ObClient
*ret
= NULL
;
4620 if (screen_pointer_pos(&x
, &y
)) {
4621 for (it
= stacking_list
; it
; it
= g_list_next(it
)) {
4622 if (WINDOW_IS_CLIENT(it
->data
)) {
4623 ObClient
*c
= WINDOW_AS_CLIENT(it
->data
);
4624 if (c
->frame
->visible
&&
4625 /* check the desktop, this is done during desktop
4626 switching and windows are shown/hidden status is not
4628 (c
->desktop
== screen_desktop
||
4629 c
->desktop
== DESKTOP_ALL
) &&
4630 /* ignore all animating windows */
4631 !frame_iconify_animating(c
->frame
) &&
4632 RECT_CONTAINS(c
->frame
->area
, x
, y
))
4643 gboolean
client_has_group_siblings(ObClient
*self
)
4645 return self
->group
&& self
->group
->members
->next
;
4648 gboolean
client_has_relative(ObClient
*self
)
4650 return client_has_parent(self
) ||
4651 client_has_group_siblings(self
) ||
4652 client_has_children(self
);
4655 /*! Returns TRUE if the client is running on the same machine as Openbox */
4656 gboolean
client_on_localhost(ObClient
*self
)
4658 return self
->client_machine
== NULL
;