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 Ben 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"
26 #include "moveresize.h"
29 #include "extensions.h"
39 #include "menuframe.h"
42 #include "render/render.h"
45 #include <X11/Xutil.h>
47 /*! The event mask to grab on client windows */
48 #define CLIENT_EVENTMASK (PropertyChangeMask | FocusChangeMask | \
51 #define CLIENT_NOPROPAGATEMASK (ButtonPressMask | ButtonReleaseMask | \
56 ObClientDestructor func
;
60 GList
*client_list
= NULL
;
61 GSList
*client_destructors
= NULL
;
63 static void client_get_all(ObClient
*self
);
64 static void client_toggle_border(ObClient
*self
, gboolean show
);
65 static void client_get_startup_id(ObClient
*self
);
66 static void client_get_area(ObClient
*self
);
67 static void client_get_desktop(ObClient
*self
);
68 static void client_get_state(ObClient
*self
);
69 static void client_get_shaped(ObClient
*self
);
70 static void client_get_mwm_hints(ObClient
*self
);
71 static void client_get_gravity(ObClient
*self
);
72 static void client_showhide(ObClient
*self
);
73 static void client_change_allowed_actions(ObClient
*self
);
74 static void client_change_state(ObClient
*self
);
75 static void client_apply_startup_state(ObClient
*self
);
76 static void client_restore_session_state(ObClient
*self
);
77 static void client_restore_session_stacking(ObClient
*self
);
78 static void client_urgent_notify(ObClient
*self
);
80 void client_startup(gboolean reconfig
)
87 void client_shutdown(gboolean reconfig
)
91 void client_add_destructor(ObClientDestructor func
, gpointer data
)
93 Destructor
*d
= g_new(Destructor
, 1);
96 client_destructors
= g_slist_prepend(client_destructors
, d
);
99 void client_remove_destructor(ObClientDestructor func
)
103 for (it
= client_destructors
; it
; it
= g_slist_next(it
)) {
104 Destructor
*d
= it
->data
;
105 if (d
->func
== func
) {
107 client_destructors
= g_slist_delete_link(client_destructors
, it
);
113 void client_set_list()
115 Window
*windows
, *win_it
;
117 guint size
= g_list_length(client_list
);
119 /* create an array of the window ids */
121 windows
= g_new(Window
, size
);
123 for (it
= client_list
; it
; it
= g_list_next(it
), ++win_it
)
124 *win_it
= ((ObClient
*)it
->data
)->window
;
128 PROP_SETA32(RootWindow(ob_display
, ob_screen
),
129 net_client_list
, window
, (gulong
*)windows
, size
);
138 void client_foreach_transient(ObClient *self, ObClientForeachFunc func, gpointer data)
142 for (it = self->transients; it; it = g_slist_next(it)) {
143 if (!func(it->data, data)) return;
144 client_foreach_transient(it->data, func, data);
148 void client_foreach_ancestor(ObClient *self, ObClientForeachFunc func, gpointer data)
150 if (self->transient_for) {
151 if (self->transient_for != OB_TRAN_GROUP) {
152 if (!func(self->transient_for, data)) return;
153 client_foreach_ancestor(self->transient_for, func, data);
157 for (it = self->group->members; it; it = g_slist_next(it))
158 if (it->data != self &&
159 !((ObClient*)it->data)->transient_for) {
160 if (!func(it->data, data)) return;
161 client_foreach_ancestor(it->data, func, data);
168 void client_manage_all()
173 XWindowAttributes attrib
;
175 XQueryTree(ob_display
, RootWindow(ob_display
, ob_screen
),
176 &w
, &w
, &children
, &nchild
);
178 /* remove all icon windows from the list */
179 for (i
= 0; i
< nchild
; i
++) {
180 if (children
[i
] == None
) continue;
181 wmhints
= XGetWMHints(ob_display
, children
[i
]);
183 if ((wmhints
->flags
& IconWindowHint
) &&
184 (wmhints
->icon_window
!= children
[i
]))
185 for (j
= 0; j
< nchild
; j
++)
186 if (children
[j
] == wmhints
->icon_window
) {
194 for (i
= 0; i
< nchild
; ++i
) {
195 if (children
[i
] == None
)
197 if (XGetWindowAttributes(ob_display
, children
[i
], &attrib
)) {
198 if (attrib
.override_redirect
) continue;
200 if (attrib
.map_state
!= IsUnmapped
)
201 client_manage(children
[i
]);
207 static ObAppSettings
*get_settings(ObClient
*client
)
209 GSList
*a
= config_per_app_settings
;
212 ObAppSettings
*app
= (ObAppSettings
*) a
->data
;
215 (app
->name
&& !app
->class && !strcmp(app
->name
, client
->name
))
216 || (app
->class && !app
->name
&& !strcmp(app
->class, client
->class))
217 || (app
->class && app
->name
&& !strcmp(app
->class, client
->class)
218 && !strcmp(app
->name
, client
->name
))
220 ob_debug("Window matching: %s\n", app
->name
);
221 /* Match if no role was specified in the per app setting, or if the
222 * string matches the beginning of the role, since apps like to set
223 * the role to things like browser-window-23c4b2f */
225 || !strncmp(app
->role
, client
->role
, strlen(app
->role
)))
234 void client_manage(Window window
)
238 XWindowAttributes attrib
;
239 XSetWindowAttributes attrib_set
;
241 gboolean activate
= FALSE
;
242 ObAppSettings
*settings
;
246 /* check if it has already been unmapped by the time we started mapping
247 the grab does a sync so we don't have to here */
248 if (XCheckTypedWindowEvent(ob_display
, window
, DestroyNotify
, &e
) ||
249 XCheckTypedWindowEvent(ob_display
, window
, UnmapNotify
, &e
)) {
250 XPutBackEvent(ob_display
, &e
);
253 return; /* don't manage it */
256 /* make sure it isn't an override-redirect window */
257 if (!XGetWindowAttributes(ob_display
, window
, &attrib
) ||
258 attrib
.override_redirect
) {
260 return; /* don't manage it */
263 /* is the window a docking app */
264 if ((wmhint
= XGetWMHints(ob_display
, window
))) {
265 if ((wmhint
->flags
& StateHint
) &&
266 wmhint
->initial_state
== WithdrawnState
) {
267 dock_add(window
, wmhint
);
275 ob_debug("Managing window: %lx\n", window
);
277 /* choose the events we want to receive on the CLIENT window */
278 attrib_set
.event_mask
= CLIENT_EVENTMASK
;
279 attrib_set
.do_not_propagate_mask
= CLIENT_NOPROPAGATEMASK
;
280 XChangeWindowAttributes(ob_display
, window
,
281 CWEventMask
|CWDontPropagate
, &attrib_set
);
284 /* create the ObClient struct, and populate it from the hints on the
286 self
= g_new0(ObClient
, 1);
287 self
->obwin
.type
= Window_Client
;
288 self
->window
= window
;
290 /* non-zero defaults */
291 self
->title_count
= 1;
292 self
->wmstate
= NormalState
;
294 self
->desktop
= screen_num_desktops
; /* always an invalid value */
296 client_get_all(self
);
297 client_restore_session_state(self
);
299 sn_app_started(self
->class);
301 /* update the focus lists, do this before the call to change_state or
302 it can end up in the list twice! */
303 focus_order_add_new(self
);
305 client_change_state(self
);
307 /* remove the client's border (and adjust re gravity) */
308 client_toggle_border(self
, FALSE
);
310 /* specify that if we exit, the window should not be destroyed and should
311 be reparented back to root automatically */
312 XChangeSaveSet(ob_display
, window
, SetModeInsert
);
314 /* create the decoration frame for the client window */
315 self
->frame
= frame_new(self
);
317 frame_grab_client(self
->frame
, self
);
321 client_apply_startup_state(self
);
323 /* get and set application level settings */
324 settings
= get_settings(self
);
326 stacking_add(CLIENT_AS_WINDOW(self
));
327 client_restore_session_stacking(self
);
330 /* Don't worry, we won't actually both shade and undecorate the
331 * window when push comes to shove. */
332 if (settings
->shade
!= -1)
333 client_shade(self
, !!settings
->shade
);
334 if (settings
->decor
!= -1)
335 client_set_undecorated(self
, !settings
->decor
);
336 if (settings
->iconic
!= -1)
337 client_iconify(self
, !!settings
->iconic
, FALSE
);
338 if (settings
->skip_pager
!= -1) {
339 self
->skip_pager
= !!settings
->skip_pager
;
340 client_change_state(self
);
342 if (settings
->skip_taskbar
!= -1) {
343 self
->skip_taskbar
= !!settings
->skip_taskbar
;
344 client_change_state(self
);
347 /* 1 && -1 shouldn't be possible by the code in config.c */
348 if (settings
->max_vert
== 1 && settings
->max_horz
== 1)
349 client_maximize(self
, TRUE
, 0, TRUE
);
350 else if (settings
->max_vert
== 0 && settings
->max_horz
== 0)
351 client_maximize(self
, FALSE
, 0, TRUE
);
352 else if (settings
->max_vert
== 1 && settings
->max_horz
== 0) {
353 client_maximize(self
, TRUE
, 2, TRUE
);
354 client_maximize(self
, FALSE
, 1, TRUE
);
355 } else if (settings
->max_vert
== 0 && settings
->max_horz
== 1) {
356 client_maximize(self
, TRUE
, 1, TRUE
);
357 client_maximize(self
, FALSE
, 2, TRUE
);
360 if (settings
->fullscreen
!= -1)
361 client_fullscreen(self
, !!settings
->fullscreen
, TRUE
);
363 if (settings
->desktop
< screen_num_desktops
364 || settings
->desktop
== DESKTOP_ALL
)
365 client_set_desktop(self
, settings
->desktop
, TRUE
);
367 if (settings
->layer
> -2 && settings
->layer
< 2)
368 client_set_layer(self
, settings
->layer
);
372 /* focus the new window? */
373 if (ob_state() != OB_STATE_STARTING
&&
374 /* this means focus=true for window is same as config_focus_new=true */
375 ((config_focus_new
|| (settings
&& settings
->focus
== 1)) ||
376 client_search_focus_parent(self
)) &&
377 /* this checks for focus=false for the window */
378 (!settings
|| settings
->focus
!= 0) &&
379 /* note the check against Type_Normal/Dialog, not client_normal(self),
380 which would also include other types. in this case we want more
381 strict rules for focus */
382 (self
->type
== OB_CLIENT_TYPE_NORMAL
||
383 self
->type
== OB_CLIENT_TYPE_DIALOG
))
387 if (self
->desktop
!= screen_desktop
) {
388 /* activate the window */
391 gboolean group_foc
= FALSE
;
396 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
))
398 if (client_focused(it
->data
))
406 (!self
->transient_for
&& (!self
->group
||
407 !self
->group
->members
->next
))) ||
408 client_search_focus_tree_full(self
) ||
410 !client_normal(focus_client
))
412 /* activate the window */
419 if (ob_state() == OB_STATE_RUNNING
) {
420 gint x
= self
->area
.x
, ox
= x
;
421 gint y
= self
->area
.y
, oy
= y
;
424 transient
= place_client(self
, &x
, &y
, settings
);
426 /* make sure the window is visible. */
427 client_find_onscreen(self
, &x
, &y
,
428 self
->frame
->area
.width
,
429 self
->frame
->area
.height
,
430 /* non-normal clients has less rules, and
431 windows that are being restored from a
432 session do also. we can assume you want
433 it back where you saved it. Clients saying
434 they placed themselves are subjected to
435 harder rules, ones that are placed by
436 place.c or by the user are allowed partially
437 off-screen and on xinerama divides (ie,
438 it is up to the placement routines to avoid
439 the xinerama divides) */
441 (((self
->positioned
& PPosition
) &&
442 !(self
->positioned
& USPosition
)) &&
443 client_normal(self
) &&
445 if (x
!= ox
|| y
!= oy
)
446 client_move(self
, x
, y
);
449 keyboard_grab_for_client(self
, TRUE
);
450 mouse_grab_for_client(self
, TRUE
);
452 client_showhide(self
);
454 /* use client_focus instead of client_activate cuz client_activate does
455 stuff like switch desktops etc and I'm not interested in all that when
456 a window maps since its not based on an action from the user like
457 clicking a window to activate is. so keep the new window out of the way
460 /* if using focus_delay, stop the timer now so that focus doesn't go
462 event_halt_focus_delay();
465 /* since focus can change the stacking orders, if we focus the window
466 then the standard raise it gets is not enough, we need to queue one
467 for after the focus change takes place */
471 /* client_activate does this but we aret using it so we have to do it
473 if (screen_showing_desktop
)
474 screen_show_desktop(FALSE
);
476 /* add to client list/map */
477 client_list
= g_list_append(client_list
, self
);
478 g_hash_table_insert(window_map
, &self
->window
, self
);
480 /* this has to happen after we're in the client_list */
481 if (STRUT_EXISTS(self
->strut
))
482 screen_update_areas();
484 /* update the list hints */
487 ob_debug("Managed window 0x%lx (%s)\n", window
, self
->class);
490 void client_unmanage_all()
492 while (client_list
!= NULL
)
493 client_unmanage(client_list
->data
);
496 void client_unmanage(ObClient
*self
)
501 ob_debug("Unmanaging window: %lx (%s)\n", self
->window
, self
->class);
503 g_assert(self
!= NULL
);
505 keyboard_grab_for_client(self
, FALSE
);
506 mouse_grab_for_client(self
, FALSE
);
508 /* potentially fix focusLast */
509 if (config_focus_last
)
510 grab_pointer(TRUE
, OB_CURSOR_NONE
);
512 /* remove the window from our save set */
513 XChangeSaveSet(ob_display
, self
->window
, SetModeDelete
);
515 /* we dont want events no more */
516 XSelectInput(ob_display
, self
->window
, NoEventMask
);
518 frame_hide(self
->frame
);
520 client_list
= g_list_remove(client_list
, self
);
521 stacking_remove(self
);
522 g_hash_table_remove(window_map
, &self
->window
);
524 /* update the focus lists */
525 focus_order_remove(self
);
527 /* once the client is out of the list, update the struts to remove it's
529 if (STRUT_EXISTS(self
->strut
))
530 screen_update_areas();
532 for (it
= client_destructors
; it
; it
= g_slist_next(it
)) {
533 Destructor
*d
= it
->data
;
534 d
->func(self
, d
->data
);
537 if (focus_client
== self
) {
540 /* focus the last focused window on the desktop, and ignore enter
541 events from the unmap so it doesnt mess with the focus */
542 while (XCheckTypedEvent(ob_display
, EnterNotify
, &e
));
543 /* remove these flags so we don't end up getting focused in the
545 self
->can_focus
= FALSE
;
546 self
->focus_notify
= FALSE
;
548 client_unfocus(self
);
551 /* tell our parent(s) that we're gone */
552 if (self
->transient_for
== OB_TRAN_GROUP
) { /* transient of group */
553 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
))
554 if (it
->data
!= self
)
555 ((ObClient
*)it
->data
)->transients
=
556 g_slist_remove(((ObClient
*)it
->data
)->transients
, self
);
557 } else if (self
->transient_for
) { /* transient of window */
558 self
->transient_for
->transients
=
559 g_slist_remove(self
->transient_for
->transients
, self
);
562 /* tell our transients that we're gone */
563 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
564 if (((ObClient
*)it
->data
)->transient_for
!= OB_TRAN_GROUP
) {
565 ((ObClient
*)it
->data
)->transient_for
= NULL
;
566 client_calc_layer(it
->data
);
570 /* remove from its group */
572 group_remove(self
->group
, self
);
576 /* give the client its border back */
577 client_toggle_border(self
, TRUE
);
579 /* reparent the window out of the frame, and free the frame */
580 frame_release_client(self
->frame
, self
);
583 if (ob_state() != OB_STATE_EXITING
) {
584 /* these values should not be persisted across a window
586 PROP_ERASE(self
->window
, net_wm_desktop
);
587 PROP_ERASE(self
->window
, net_wm_state
);
588 PROP_ERASE(self
->window
, wm_state
);
590 /* if we're left in an unmapped state, the client wont be mapped. this
591 is bad, since we will no longer be managing the window on restart */
592 XMapWindow(ob_display
, self
->window
);
596 ob_debug("Unmanaged window 0x%lx\n", self
->window
);
598 /* free all data allocated in the client struct */
599 g_slist_free(self
->transients
);
600 for (j
= 0; j
< self
->nicons
; ++j
)
601 g_free(self
->icons
[j
].data
);
602 if (self
->nicons
> 0)
605 g_free(self
->icon_title
);
609 g_free(self
->sm_client_id
);
612 /* update the list hints */
615 if (config_focus_last
)
616 grab_pointer(FALSE
, OB_CURSOR_NONE
);
619 static void client_urgent_notify(ObClient
*self
)
622 frame_flash_start(self
->frame
);
624 frame_flash_stop(self
->frame
);
627 static void client_restore_session_state(ObClient
*self
)
631 if (!(it
= session_state_find(self
)))
634 self
->session
= it
->data
;
636 RECT_SET_POINT(self
->area
, self
->session
->x
, self
->session
->y
);
637 self
->positioned
= PPosition
;
638 if (self
->session
->w
> 0)
639 self
->area
.width
= self
->session
->w
;
640 if (self
->session
->h
> 0)
641 self
->area
.height
= self
->session
->h
;
642 XResizeWindow(ob_display
, self
->window
,
643 self
->area
.width
, self
->area
.height
);
645 self
->desktop
= (self
->session
->desktop
== DESKTOP_ALL
?
646 self
->session
->desktop
:
647 MIN(screen_num_desktops
- 1, self
->session
->desktop
));
648 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, self
->desktop
);
650 self
->shaded
= self
->session
->shaded
;
651 self
->iconic
= self
->session
->iconic
;
652 self
->skip_pager
= self
->session
->skip_pager
;
653 self
->skip_taskbar
= self
->session
->skip_taskbar
;
654 self
->fullscreen
= self
->session
->fullscreen
;
655 self
->above
= self
->session
->above
;
656 self
->below
= self
->session
->below
;
657 self
->max_horz
= self
->session
->max_horz
;
658 self
->max_vert
= self
->session
->max_vert
;
661 static void client_restore_session_stacking(ObClient
*self
)
665 if (!self
->session
) return;
667 it
= g_list_find(session_saved_state
, self
->session
);
668 for (it
= g_list_previous(it
); it
; it
= g_list_previous(it
)) {
671 for (cit
= client_list
; cit
; cit
= g_list_next(cit
))
672 if (session_state_cmp(it
->data
, cit
->data
))
675 client_calc_layer(self
);
676 stacking_below(CLIENT_AS_WINDOW(self
),
677 CLIENT_AS_WINDOW(cit
->data
));
683 void client_move_onscreen(ObClient
*self
, gboolean rude
)
685 gint x
= self
->area
.x
;
686 gint y
= self
->area
.y
;
687 if (client_find_onscreen(self
, &x
, &y
,
688 self
->frame
->area
.width
,
689 self
->frame
->area
.height
, rude
)) {
690 client_move(self
, x
, y
);
694 gboolean
client_find_onscreen(ObClient
*self
, gint
*x
, gint
*y
, gint w
, gint h
,
698 gint ox
= *x
, oy
= *y
;
700 frame_client_gravity(self
->frame
, x
, y
); /* get where the frame
703 /* XXX watch for xinerama dead areas */
704 /* This makes sure windows aren't entirely outside of the screen so you
705 * can't see them at all */
706 if (client_normal(self
)) {
707 a
= screen_area(self
->desktop
);
708 if (!self
->strut
.right
&& *x
>= a
->x
+ a
->width
- 1)
709 *x
= a
->x
+ a
->width
- self
->frame
->area
.width
;
710 if (!self
->strut
.bottom
&& *y
>= a
->y
+ a
->height
- 1)
711 *y
= a
->y
+ a
->height
- self
->frame
->area
.height
;
712 if (!self
->strut
.left
&& *x
+ self
->frame
->area
.width
- 1 < a
->x
)
714 if (!self
->strut
.top
&& *y
+ self
->frame
->area
.height
- 1 < a
->y
)
718 /* This here doesn't let windows even a pixel outside the screen,
719 * when called from client_manage, programs placing themselves are
720 * forced completely onscreen, while things like
721 * xterm -geometry resolution-width/2 will work fine. Trying to
722 * place it completely offscreen will be handled in the above code.
723 * Sorry for this confused comment, i am tired. */
725 /* avoid the xinerama monitor divide while we're at it,
726 * remember to fix the placement stuff to avoid it also and
727 * then remove this XXX */
728 a
= screen_physical_area_monitor(client_monitor(self
));
729 /* dont let windows map/move into the strut unless they
730 are bigger than the available area */
732 if (!self
->strut
.left
&& *x
< a
->x
) *x
= a
->x
;
733 if (!self
->strut
.right
&& *x
+ w
> a
->x
+ a
->width
)
734 *x
= a
->x
+ a
->width
- w
;
736 if (h
<= a
->height
) {
737 if (!self
->strut
.top
&& *y
< a
->y
) *y
= a
->y
;
738 if (!self
->strut
.bottom
&& *y
+ h
> a
->y
+ a
->height
)
739 *y
= a
->y
+ a
->height
- h
;
743 frame_frame_gravity(self
->frame
, x
, y
); /* get where the client
746 return ox
!= *x
|| oy
!= *y
;
749 static void client_toggle_border(ObClient
*self
, gboolean show
)
751 /* adjust our idea of where the client is, based on its border. When the
752 border is removed, the client should now be considered to be in a
754 when re-adding the border to the client, the same operation needs to be
756 gint oldx
= self
->area
.x
, oldy
= self
->area
.y
;
757 gint x
= oldx
, y
= oldy
;
758 switch(self
->gravity
) {
760 case NorthWestGravity
:
762 case SouthWestGravity
:
764 case NorthEastGravity
:
766 case SouthEastGravity
:
767 if (show
) x
-= self
->border_width
* 2;
768 else x
+= self
->border_width
* 2;
775 if (show
) x
-= self
->border_width
;
776 else x
+= self
->border_width
;
779 switch(self
->gravity
) {
781 case NorthWestGravity
:
783 case NorthEastGravity
:
785 case SouthWestGravity
:
787 case SouthEastGravity
:
788 if (show
) y
-= self
->border_width
* 2;
789 else y
+= self
->border_width
* 2;
796 if (show
) y
-= self
->border_width
;
797 else y
+= self
->border_width
;
804 XSetWindowBorderWidth(ob_display
, self
->window
, self
->border_width
);
806 /* move the client so it is back it the right spot _with_ its
808 if (x
!= oldx
|| y
!= oldy
)
809 XMoveWindow(ob_display
, self
->window
, x
, y
);
811 XSetWindowBorderWidth(ob_display
, self
->window
, 0);
815 static void client_get_all(ObClient
*self
)
817 client_get_area(self
);
818 client_get_mwm_hints(self
);
820 /* The transient hint is used to pick a type, but the type can also affect
821 transiency (dialogs are always made transients of their group if they
822 have one). This is Havoc's idea, but it is needed to make some apps
823 work right (eg tsclient). */
824 client_update_transient_for(self
);
825 client_get_type(self
);/* this can change the mwmhints for special cases */
826 client_update_transient_for(self
);
828 client_update_wmhints(self
);
829 client_get_startup_id(self
);
830 client_get_desktop(self
);/* uses transient data/group/startup id if a
831 desktop is not specified */
832 client_get_shaped(self
);
834 client_get_state(self
);
837 /* a couple type-based defaults for new windows */
839 /* this makes sure that these windows appear on all desktops */
840 if (self
->type
== OB_CLIENT_TYPE_DESKTOP
)
841 self
->desktop
= DESKTOP_ALL
;
844 client_update_protocols(self
);
846 client_get_gravity(self
); /* get the attribute gravity */
847 client_update_normal_hints(self
); /* this may override the attribute
850 /* got the type, the mwmhints, the protocols, and the normal hints
851 (min/max sizes), so we're ready to set up the decorations/functions */
852 client_setup_decor_and_functions(self
);
854 client_update_title(self
);
855 client_update_class(self
);
856 client_update_sm_client_id(self
);
857 client_update_strut(self
);
858 client_update_icons(self
);
861 static void client_get_startup_id(ObClient
*self
)
863 if (!(PROP_GETS(self
->window
, net_startup_id
, utf8
, &self
->startup_id
)))
865 PROP_GETS(self
->group
->leader
,
866 net_startup_id
, utf8
, &self
->startup_id
);
869 static void client_get_area(ObClient
*self
)
871 XWindowAttributes wattrib
;
874 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
875 g_assert(ret
!= BadWindow
);
877 RECT_SET(self
->area
, wattrib
.x
, wattrib
.y
, wattrib
.width
, wattrib
.height
);
878 self
->border_width
= wattrib
.border_width
;
881 static void client_get_desktop(ObClient
*self
)
883 guint32 d
= screen_num_desktops
; /* an always-invalid value */
885 if (PROP_GET32(self
->window
, net_wm_desktop
, cardinal
, &d
)) {
886 if (d
>= screen_num_desktops
&& d
!= DESKTOP_ALL
)
887 self
->desktop
= screen_num_desktops
- 1;
891 gboolean trdesk
= FALSE
;
893 if (self
->transient_for
) {
894 if (self
->transient_for
!= OB_TRAN_GROUP
) {
895 self
->desktop
= self
->transient_for
->desktop
;
900 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
))
901 if (it
->data
!= self
&&
902 !((ObClient
*)it
->data
)->transient_for
) {
903 self
->desktop
= ((ObClient
*)it
->data
)->desktop
;
910 /* try get from the startup-notification protocol */
911 if (sn_get_desktop(self
->startup_id
, &self
->desktop
)) {
912 if (self
->desktop
>= screen_num_desktops
&&
913 self
->desktop
!= DESKTOP_ALL
)
914 self
->desktop
= screen_num_desktops
- 1;
916 /* defaults to the current desktop */
917 self
->desktop
= screen_desktop
;
920 if (self
->desktop
!= d
) {
921 /* set the desktop hint, to make sure that it always exists */
922 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, self
->desktop
);
926 static void client_get_state(ObClient
*self
)
931 if (PROP_GETA32(self
->window
, net_wm_state
, atom
, &state
, &num
)) {
933 for (i
= 0; i
< num
; ++i
) {
934 if (state
[i
] == prop_atoms
.net_wm_state_modal
)
936 else if (state
[i
] == prop_atoms
.net_wm_state_shaded
)
938 else if (state
[i
] == prop_atoms
.net_wm_state_hidden
)
940 else if (state
[i
] == prop_atoms
.net_wm_state_skip_taskbar
)
941 self
->skip_taskbar
= TRUE
;
942 else if (state
[i
] == prop_atoms
.net_wm_state_skip_pager
)
943 self
->skip_pager
= TRUE
;
944 else if (state
[i
] == prop_atoms
.net_wm_state_fullscreen
)
945 self
->fullscreen
= TRUE
;
946 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_vert
)
947 self
->max_vert
= TRUE
;
948 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_horz
)
949 self
->max_horz
= TRUE
;
950 else if (state
[i
] == prop_atoms
.net_wm_state_above
)
952 else if (state
[i
] == prop_atoms
.net_wm_state_below
)
954 else if (state
[i
] == prop_atoms
.ob_wm_state_undecorated
)
955 self
->undecorated
= TRUE
;
961 if (!(self
->above
|| self
->below
)) {
963 /* apply stuff from the group */
967 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
968 ObClient
*c
= it
->data
;
969 if (c
!= self
&& !client_search_transient(self
, c
) &&
970 client_normal(self
) && client_normal(c
))
973 (c
->above
? 1 : (c
->below
? -1 : 0)));
987 g_assert_not_reached();
994 static void client_get_shaped(ObClient
*self
)
996 self
->shaped
= FALSE
;
998 if (extensions_shape
) {
1003 XShapeSelectInput(ob_display
, self
->window
, ShapeNotifyMask
);
1005 XShapeQueryExtents(ob_display
, self
->window
, &s
, &foo
,
1006 &foo
, &ufoo
, &ufoo
, &foo
, &foo
, &foo
, &ufoo
,
1008 self
->shaped
= (s
!= 0);
1013 void client_update_transient_for(ObClient
*self
)
1016 ObClient
*target
= NULL
;
1018 if (XGetTransientForHint(ob_display
, self
->window
, &t
)) {
1019 self
->transient
= TRUE
;
1020 if (t
!= self
->window
) { /* cant be transient to itself! */
1021 target
= g_hash_table_lookup(window_map
, &t
);
1022 /* if this happens then we need to check for it*/
1023 g_assert(target
!= self
);
1024 if (target
&& !WINDOW_IS_CLIENT(target
)) {
1025 /* this can happen when a dialog is a child of
1026 a dockapp, for example */
1030 if (!target
&& self
->group
) {
1031 /* not transient to a client, see if it is transient for a
1033 if (t
== self
->group
->leader
||
1035 t
== RootWindow(ob_display
, ob_screen
))
1037 /* window is a transient for its group! */
1038 target
= OB_TRAN_GROUP
;
1042 } else if (self
->type
== OB_CLIENT_TYPE_DIALOG
&& self
->group
) {
1043 self
->transient
= TRUE
;
1044 target
= OB_TRAN_GROUP
;
1046 self
->transient
= FALSE
;
1048 /* if anything has changed... */
1049 if (target
!= self
->transient_for
) {
1050 if (self
->transient_for
== OB_TRAN_GROUP
) { /* transient of group */
1053 /* remove from old parents */
1054 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
1055 ObClient
*c
= it
->data
;
1056 if (c
!= self
&& !c
->transient_for
)
1057 c
->transients
= g_slist_remove(c
->transients
, self
);
1059 } else if (self
->transient_for
!= NULL
) { /* transient of window */
1060 /* remove from old parent */
1061 self
->transient_for
->transients
=
1062 g_slist_remove(self
->transient_for
->transients
, self
);
1064 self
->transient_for
= target
;
1065 if (self
->transient_for
== OB_TRAN_GROUP
) { /* transient of group */
1068 /* add to new parents */
1069 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
1070 ObClient
*c
= it
->data
;
1071 if (c
!= self
&& !c
->transient_for
)
1072 c
->transients
= g_slist_append(c
->transients
, self
);
1075 /* remove all transients which are in the group, that causes
1076 circlular pointer hell of doom */
1077 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
1079 for (sit
= self
->transients
; sit
; sit
= next
) {
1080 next
= g_slist_next(sit
);
1081 if (sit
->data
== it
->data
)
1083 g_slist_delete_link(self
->transients
, sit
);
1086 } else if (self
->transient_for
!= NULL
) { /* transient of window */
1087 /* add to new parent */
1088 self
->transient_for
->transients
=
1089 g_slist_append(self
->transient_for
->transients
, self
);
1094 static void client_get_mwm_hints(ObClient
*self
)
1099 self
->mwmhints
.flags
= 0; /* default to none */
1101 if (PROP_GETA32(self
->window
, motif_wm_hints
, motif_wm_hints
,
1103 if (num
>= OB_MWM_ELEMENTS
) {
1104 self
->mwmhints
.flags
= hints
[0];
1105 self
->mwmhints
.functions
= hints
[1];
1106 self
->mwmhints
.decorations
= hints
[2];
1112 void client_get_type(ObClient
*self
)
1119 if (PROP_GETA32(self
->window
, net_wm_window_type
, atom
, &val
, &num
)) {
1120 /* use the first value that we know about in the array */
1121 for (i
= 0; i
< num
; ++i
) {
1122 if (val
[i
] == prop_atoms
.net_wm_window_type_desktop
)
1123 self
->type
= OB_CLIENT_TYPE_DESKTOP
;
1124 else if (val
[i
] == prop_atoms
.net_wm_window_type_dock
)
1125 self
->type
= OB_CLIENT_TYPE_DOCK
;
1126 else if (val
[i
] == prop_atoms
.net_wm_window_type_toolbar
)
1127 self
->type
= OB_CLIENT_TYPE_TOOLBAR
;
1128 else if (val
[i
] == prop_atoms
.net_wm_window_type_menu
)
1129 self
->type
= OB_CLIENT_TYPE_MENU
;
1130 else if (val
[i
] == prop_atoms
.net_wm_window_type_utility
)
1131 self
->type
= OB_CLIENT_TYPE_UTILITY
;
1132 else if (val
[i
] == prop_atoms
.net_wm_window_type_splash
)
1133 self
->type
= OB_CLIENT_TYPE_SPLASH
;
1134 else if (val
[i
] == prop_atoms
.net_wm_window_type_dialog
)
1135 self
->type
= OB_CLIENT_TYPE_DIALOG
;
1136 else if (val
[i
] == prop_atoms
.net_wm_window_type_normal
)
1137 self
->type
= OB_CLIENT_TYPE_NORMAL
;
1138 else if (val
[i
] == prop_atoms
.kde_net_wm_window_type_override
) {
1139 /* prevent this window from getting any decor or
1141 self
->mwmhints
.flags
&= (OB_MWM_FLAG_FUNCTIONS
|
1142 OB_MWM_FLAG_DECORATIONS
);
1143 self
->mwmhints
.decorations
= 0;
1144 self
->mwmhints
.functions
= 0;
1146 if (self
->type
!= (ObClientType
) -1)
1147 break; /* grab the first legit type */
1152 if (self
->type
== (ObClientType
) -1) {
1153 /*the window type hint was not set, which means we either classify
1154 ourself as a normal window or a dialog, depending on if we are a
1156 if (self
->transient
)
1157 self
->type
= OB_CLIENT_TYPE_DIALOG
;
1159 self
->type
= OB_CLIENT_TYPE_NORMAL
;
1163 void client_update_protocols(ObClient
*self
)
1166 guint num_return
, i
;
1168 self
->focus_notify
= FALSE
;
1169 self
->delete_window
= FALSE
;
1171 if (PROP_GETA32(self
->window
, wm_protocols
, atom
, &proto
, &num_return
)) {
1172 for (i
= 0; i
< num_return
; ++i
) {
1173 if (proto
[i
] == prop_atoms
.wm_delete_window
) {
1174 /* this means we can request the window to close */
1175 self
->delete_window
= TRUE
;
1176 } else if (proto
[i
] == prop_atoms
.wm_take_focus
)
1177 /* if this protocol is requested, then the window will be
1178 notified whenever we want it to receive focus */
1179 self
->focus_notify
= TRUE
;
1185 static void client_get_gravity(ObClient
*self
)
1187 XWindowAttributes wattrib
;
1190 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
1191 g_assert(ret
!= BadWindow
);
1192 self
->gravity
= wattrib
.win_gravity
;
1195 void client_update_normal_hints(ObClient
*self
)
1199 gint oldgravity
= self
->gravity
;
1202 self
->min_ratio
= 0.0f
;
1203 self
->max_ratio
= 0.0f
;
1204 SIZE_SET(self
->size_inc
, 1, 1);
1205 SIZE_SET(self
->base_size
, 0, 0);
1206 SIZE_SET(self
->min_size
, 0, 0);
1207 SIZE_SET(self
->max_size
, G_MAXINT
, G_MAXINT
);
1209 /* get the hints from the window */
1210 if (XGetWMNormalHints(ob_display
, self
->window
, &size
, &ret
)) {
1211 /* normal windows can't request placement! har har
1212 if (!client_normal(self))
1214 self
->positioned
= (size
.flags
& (PPosition
|USPosition
));
1216 if (size
.flags
& PWinGravity
) {
1217 self
->gravity
= size
.win_gravity
;
1219 /* if the client has a frame, i.e. has already been mapped and
1220 is changing its gravity */
1221 if (self
->frame
&& self
->gravity
!= oldgravity
) {
1222 /* move our idea of the client's position based on its new
1224 self
->area
.x
= self
->frame
->area
.x
;
1225 self
->area
.y
= self
->frame
->area
.y
;
1226 frame_frame_gravity(self
->frame
, &self
->area
.x
, &self
->area
.y
);
1230 if (size
.flags
& PAspect
) {
1231 if (size
.min_aspect
.y
)
1233 (gfloat
) size
.min_aspect
.x
/ size
.min_aspect
.y
;
1234 if (size
.max_aspect
.y
)
1236 (gfloat
) size
.max_aspect
.x
/ size
.max_aspect
.y
;
1239 if (size
.flags
& PMinSize
)
1240 SIZE_SET(self
->min_size
, size
.min_width
, size
.min_height
);
1242 if (size
.flags
& PMaxSize
)
1243 SIZE_SET(self
->max_size
, size
.max_width
, size
.max_height
);
1245 if (size
.flags
& PBaseSize
)
1246 SIZE_SET(self
->base_size
, size
.base_width
, size
.base_height
);
1248 if (size
.flags
& PResizeInc
&& size
.width_inc
&& size
.height_inc
)
1249 SIZE_SET(self
->size_inc
, size
.width_inc
, size
.height_inc
);
1253 void client_setup_decor_and_functions(ObClient
*self
)
1255 /* start with everything (cept fullscreen) */
1257 (OB_FRAME_DECOR_TITLEBAR
|
1258 OB_FRAME_DECOR_HANDLE
|
1259 OB_FRAME_DECOR_GRIPS
|
1260 OB_FRAME_DECOR_BORDER
|
1261 OB_FRAME_DECOR_ICON
|
1262 OB_FRAME_DECOR_ALLDESKTOPS
|
1263 OB_FRAME_DECOR_ICONIFY
|
1264 OB_FRAME_DECOR_MAXIMIZE
|
1265 OB_FRAME_DECOR_SHADE
|
1266 OB_FRAME_DECOR_CLOSE
);
1268 (OB_CLIENT_FUNC_RESIZE
|
1269 OB_CLIENT_FUNC_MOVE
|
1270 OB_CLIENT_FUNC_ICONIFY
|
1271 OB_CLIENT_FUNC_MAXIMIZE
|
1272 OB_CLIENT_FUNC_SHADE
|
1273 OB_CLIENT_FUNC_CLOSE
);
1275 if (!(self
->min_size
.width
< self
->max_size
.width
||
1276 self
->min_size
.height
< self
->max_size
.height
))
1277 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
1279 switch (self
->type
) {
1280 case OB_CLIENT_TYPE_NORMAL
:
1281 /* normal windows retain all of the possible decorations and
1282 functionality, and are the only windows that you can fullscreen */
1283 self
->functions
|= OB_CLIENT_FUNC_FULLSCREEN
;
1286 case OB_CLIENT_TYPE_DIALOG
:
1287 case OB_CLIENT_TYPE_UTILITY
:
1288 /* these windows cannot be maximized */
1289 self
->functions
&= ~OB_CLIENT_FUNC_MAXIMIZE
;
1292 case OB_CLIENT_TYPE_MENU
:
1293 case OB_CLIENT_TYPE_TOOLBAR
:
1294 /* these windows get less functionality */
1295 self
->functions
&= ~(OB_CLIENT_FUNC_ICONIFY
| OB_CLIENT_FUNC_RESIZE
);
1298 case OB_CLIENT_TYPE_DESKTOP
:
1299 case OB_CLIENT_TYPE_DOCK
:
1300 case OB_CLIENT_TYPE_SPLASH
:
1301 /* none of these windows are manipulated by the window manager */
1302 self
->decorations
= 0;
1303 self
->functions
= 0;
1307 /* Mwm Hints are applied subtractively to what has already been chosen for
1308 decor and functionality */
1309 if (self
->mwmhints
.flags
& OB_MWM_FLAG_DECORATIONS
) {
1310 if (! (self
->mwmhints
.decorations
& OB_MWM_DECOR_ALL
)) {
1311 if (! ((self
->mwmhints
.decorations
& OB_MWM_DECOR_HANDLE
) ||
1312 (self
->mwmhints
.decorations
& OB_MWM_DECOR_TITLE
)))
1314 /* if the mwm hints request no handle or title, then all
1315 decorations are disabled, but keep the border if that's
1317 if (self
->mwmhints
.decorations
& OB_MWM_DECOR_BORDER
)
1318 self
->decorations
= OB_FRAME_DECOR_BORDER
;
1320 self
->decorations
= 0;
1325 if (self
->mwmhints
.flags
& OB_MWM_FLAG_FUNCTIONS
) {
1326 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_ALL
)) {
1327 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_RESIZE
))
1328 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
1329 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_MOVE
))
1330 self
->functions
&= ~OB_CLIENT_FUNC_MOVE
;
1331 /* dont let mwm hints kill any buttons
1332 if (! (self->mwmhints.functions & OB_MWM_FUNC_ICONIFY))
1333 self->functions &= ~OB_CLIENT_FUNC_ICONIFY;
1334 if (! (self->mwmhints.functions & OB_MWM_FUNC_MAXIMIZE))
1335 self->functions &= ~OB_CLIENT_FUNC_MAXIMIZE;
1337 /* dont let mwm hints kill the close button
1338 if (! (self->mwmhints.functions & MwmFunc_Close))
1339 self->functions &= ~OB_CLIENT_FUNC_CLOSE; */
1343 if (!(self
->functions
& OB_CLIENT_FUNC_SHADE
))
1344 self
->decorations
&= ~OB_FRAME_DECOR_SHADE
;
1345 if (!(self
->functions
& OB_CLIENT_FUNC_ICONIFY
))
1346 self
->decorations
&= ~OB_FRAME_DECOR_ICONIFY
;
1347 if (!(self
->functions
& OB_CLIENT_FUNC_RESIZE
))
1348 self
->decorations
&= ~OB_FRAME_DECOR_GRIPS
;
1350 /* can't maximize without moving/resizing */
1351 if (!((self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) &&
1352 (self
->functions
& OB_CLIENT_FUNC_MOVE
) &&
1353 (self
->functions
& OB_CLIENT_FUNC_RESIZE
))) {
1354 self
->functions
&= ~OB_CLIENT_FUNC_MAXIMIZE
;
1355 self
->decorations
&= ~OB_FRAME_DECOR_MAXIMIZE
;
1358 /* kill the handle on fully maxed windows */
1359 if (self
->max_vert
&& self
->max_horz
)
1360 self
->decorations
&= ~OB_FRAME_DECOR_HANDLE
;
1362 /* finally, the user can have requested no decorations, which overrides
1363 everything (but doesnt give it a border if it doesnt have one) */
1364 if (self
->undecorated
) {
1365 if (config_theme_keepborder
)
1366 self
->decorations
&= OB_FRAME_DECOR_BORDER
;
1368 self
->decorations
= 0;
1371 /* if we don't have a titlebar, then we cannot shade! */
1372 if (!(self
->decorations
& OB_FRAME_DECOR_TITLEBAR
))
1373 self
->functions
&= ~OB_CLIENT_FUNC_SHADE
;
1375 /* now we need to check against rules for the client's current state */
1376 if (self
->fullscreen
) {
1377 self
->functions
&= (OB_CLIENT_FUNC_CLOSE
|
1378 OB_CLIENT_FUNC_FULLSCREEN
|
1379 OB_CLIENT_FUNC_ICONIFY
);
1380 self
->decorations
= 0;
1383 client_change_allowed_actions(self
);
1386 /* adjust the client's decorations, etc. */
1387 client_reconfigure(self
);
1391 static void client_change_allowed_actions(ObClient
*self
)
1396 /* desktop windows are kept on all desktops */
1397 if (self
->type
!= OB_CLIENT_TYPE_DESKTOP
)
1398 actions
[num
++] = prop_atoms
.net_wm_action_change_desktop
;
1400 if (self
->functions
& OB_CLIENT_FUNC_SHADE
)
1401 actions
[num
++] = prop_atoms
.net_wm_action_shade
;
1402 if (self
->functions
& OB_CLIENT_FUNC_CLOSE
)
1403 actions
[num
++] = prop_atoms
.net_wm_action_close
;
1404 if (self
->functions
& OB_CLIENT_FUNC_MOVE
)
1405 actions
[num
++] = prop_atoms
.net_wm_action_move
;
1406 if (self
->functions
& OB_CLIENT_FUNC_ICONIFY
)
1407 actions
[num
++] = prop_atoms
.net_wm_action_minimize
;
1408 if (self
->functions
& OB_CLIENT_FUNC_RESIZE
)
1409 actions
[num
++] = prop_atoms
.net_wm_action_resize
;
1410 if (self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
)
1411 actions
[num
++] = prop_atoms
.net_wm_action_fullscreen
;
1412 if (self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) {
1413 actions
[num
++] = prop_atoms
.net_wm_action_maximize_horz
;
1414 actions
[num
++] = prop_atoms
.net_wm_action_maximize_vert
;
1417 PROP_SETA32(self
->window
, net_wm_allowed_actions
, atom
, actions
, num
);
1419 /* make sure the window isn't breaking any rules now */
1421 if (!(self
->functions
& OB_CLIENT_FUNC_SHADE
) && self
->shaded
) {
1422 if (self
->frame
) client_shade(self
, FALSE
);
1423 else self
->shaded
= FALSE
;
1425 if (!(self
->functions
& OB_CLIENT_FUNC_ICONIFY
) && self
->iconic
) {
1426 if (self
->frame
) client_iconify(self
, FALSE
, TRUE
);
1427 else self
->iconic
= FALSE
;
1429 if (!(self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
) && self
->fullscreen
) {
1430 if (self
->frame
) client_fullscreen(self
, FALSE
, TRUE
);
1431 else self
->fullscreen
= FALSE
;
1433 if (!(self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) && (self
->max_horz
||
1435 if (self
->frame
) client_maximize(self
, FALSE
, 0, TRUE
);
1436 else self
->max_vert
= self
->max_horz
= FALSE
;
1440 void client_reconfigure(ObClient
*self
)
1442 /* by making this pass FALSE for user, we avoid the emacs event storm where
1443 every configurenotify causes an update in its normal hints, i think this
1444 is generally what we want anyways... */
1445 client_configure(self
, OB_CORNER_TOPLEFT
, self
->area
.x
, self
->area
.y
,
1446 self
->area
.width
, self
->area
.height
, FALSE
, TRUE
);
1449 void client_update_wmhints(ObClient
*self
)
1452 gboolean ur
= FALSE
;
1455 /* assume a window takes input if it doesnt specify */
1456 self
->can_focus
= TRUE
;
1458 if ((hints
= XGetWMHints(ob_display
, self
->window
)) != NULL
) {
1459 if (hints
->flags
& InputHint
)
1460 self
->can_focus
= hints
->input
;
1462 /* only do this when first managing the window *AND* when we aren't
1464 if (ob_state() != OB_STATE_STARTING
&& self
->frame
== NULL
)
1465 if (hints
->flags
& StateHint
)
1466 self
->iconic
= hints
->initial_state
== IconicState
;
1468 if (hints
->flags
& XUrgencyHint
)
1471 if (!(hints
->flags
& WindowGroupHint
))
1472 hints
->window_group
= None
;
1474 /* did the group state change? */
1475 if (hints
->window_group
!=
1476 (self
->group
? self
->group
->leader
: None
)) {
1477 /* remove from the old group if there was one */
1478 if (self
->group
!= NULL
) {
1479 /* remove transients of the group */
1480 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
))
1481 self
->transients
= g_slist_remove(self
->transients
,
1484 /* remove myself from parents in the group */
1485 if (self
->transient_for
== OB_TRAN_GROUP
) {
1486 for (it
= self
->group
->members
; it
;
1487 it
= g_slist_next(it
))
1489 ObClient
*c
= it
->data
;
1491 if (c
!= self
&& !c
->transient_for
)
1492 c
->transients
= g_slist_remove(c
->transients
,
1497 group_remove(self
->group
, self
);
1500 if (hints
->window_group
!= None
) {
1501 self
->group
= group_add(hints
->window_group
, self
);
1503 /* i can only have transients from the group if i am not
1505 if (!self
->transient_for
) {
1506 /* add other transients of the group that are already
1508 for (it
= self
->group
->members
; it
;
1509 it
= g_slist_next(it
))
1511 ObClient
*c
= it
->data
;
1512 if (c
!= self
&& c
->transient_for
== OB_TRAN_GROUP
)
1514 g_slist_append(self
->transients
, c
);
1519 /* because the self->transient flag wont change from this call,
1520 we don't need to update the window's type and such, only its
1521 transient_for, and the transients lists of other windows in
1522 the group may be affected */
1523 client_update_transient_for(self
);
1526 /* the WM_HINTS can contain an icon */
1527 client_update_icons(self
);
1532 if (ur
!= self
->urgent
) {
1534 /* fire the urgent callback if we're mapped, otherwise, wait until
1535 after we're mapped */
1537 client_urgent_notify(self
);
1541 void client_update_title(ObClient
*self
)
1547 gboolean read_title
;
1550 old_title
= self
->title
;
1553 if (!PROP_GETS(self
->window
, net_wm_name
, utf8
, &data
)) {
1554 /* try old x stuff */
1555 if (!(PROP_GETS(self
->window
, wm_name
, locale
, &data
)
1556 || PROP_GETS(self
->window
, wm_name
, utf8
, &data
))) {
1557 // http://developer.gnome.org/projects/gup/hig/draft_hig_new/windows-alert.html
1558 if (self
->transient
) {
1559 data
= g_strdup("");
1562 data
= g_strdup("Unnamed Window");
1566 if (config_title_number
) {
1568 /* did the title change? then reset the title_count */
1569 if (old_title
&& 0 != strncmp(old_title
, data
, strlen(data
)))
1570 self
->title_count
= 1;
1572 /* look for duplicates and append a number */
1574 for (it
= client_list
; it
; it
= g_list_next(it
))
1575 if (it
->data
!= self
) {
1576 ObClient
*c
= it
->data
;
1577 if (0 == strncmp(c
->title
, data
, strlen(data
)))
1578 nums
|= 1 << c
->title_count
;
1580 /* find first free number */
1581 for (i
= 1; i
<= 32; ++i
)
1582 if (!(nums
& (1 << i
))) {
1583 if (self
->title_count
== 1 || i
== 1)
1584 self
->title_count
= i
;
1587 /* dont display the number for the first window */
1588 if (self
->title_count
> 1) {
1590 ndata
= g_strdup_printf("%s - [%u]", data
, self
->title_count
);
1595 self
->title_count
= 1;
1598 PROP_SETS(self
->window
, net_wm_visible_name
, data
);
1602 frame_adjust_title(self
->frame
);
1606 /* update the icon title */
1608 g_free(self
->icon_title
);
1612 if (!PROP_GETS(self
->window
, net_wm_icon_name
, utf8
, &data
))
1613 /* try old x stuff */
1614 if (!(PROP_GETS(self
->window
, wm_icon_name
, locale
, &data
)
1615 || PROP_GETS(self
->window
, wm_icon_name
, utf8
, &data
))) {
1616 data
= g_strdup(self
->title
);
1620 /* append the title count, dont display the number for the first window.
1621 * We don't need to check for config_title_number here since title_count
1622 * is not set above 1 then. */
1623 if (read_title
&& self
->title_count
> 1) {
1624 gchar
*vdata
, *ndata
;
1625 ndata
= g_strdup_printf(" - [%u]", self
->title_count
);
1626 vdata
= g_strconcat(data
, ndata
, NULL
);
1632 PROP_SETS(self
->window
, net_wm_visible_icon_name
, data
);
1634 self
->icon_title
= data
;
1637 void client_update_class(ObClient
*self
)
1642 if (self
->name
) g_free(self
->name
);
1643 if (self
->class) g_free(self
->class);
1644 if (self
->role
) g_free(self
->role
);
1646 self
->name
= self
->class = self
->role
= NULL
;
1648 if (PROP_GETSS(self
->window
, wm_class
, locale
, &data
)) {
1650 self
->name
= g_strdup(data
[0]);
1652 self
->class = g_strdup(data
[1]);
1657 if (PROP_GETS(self
->window
, wm_window_role
, locale
, &s
))
1660 if (self
->name
== NULL
) self
->name
= g_strdup("");
1661 if (self
->class == NULL
) self
->class = g_strdup("");
1662 if (self
->role
== NULL
) self
->role
= g_strdup("");
1665 void client_update_strut(ObClient
*self
)
1669 gboolean got
= FALSE
;
1672 if (PROP_GETA32(self
->window
, net_wm_strut_partial
, cardinal
,
1676 STRUT_PARTIAL_SET(strut
,
1677 data
[0], data
[2], data
[1], data
[3],
1678 data
[4], data
[5], data
[8], data
[9],
1679 data
[6], data
[7], data
[10], data
[11]);
1685 PROP_GETA32(self
->window
, net_wm_strut
, cardinal
, &data
, &num
)) {
1691 /* use the screen's width/height */
1692 a
= screen_physical_area();
1694 STRUT_PARTIAL_SET(strut
,
1695 data
[0], data
[2], data
[1], data
[3],
1696 a
->y
, a
->y
+ a
->height
- 1,
1697 a
->x
, a
->x
+ a
->width
- 1,
1698 a
->y
, a
->y
+ a
->height
- 1,
1699 a
->x
, a
->x
+ a
->width
- 1);
1705 STRUT_PARTIAL_SET(strut
, 0, 0, 0, 0,
1706 0, 0, 0, 0, 0, 0, 0, 0);
1708 if (!STRUT_EQUAL(strut
, self
->strut
)) {
1709 self
->strut
= strut
;
1711 /* updating here is pointless while we're being mapped cuz we're not in
1712 the client list yet */
1714 screen_update_areas();
1718 void client_update_icons(ObClient
*self
)
1724 for (i
= 0; i
< self
->nicons
; ++i
)
1725 g_free(self
->icons
[i
].data
);
1726 if (self
->nicons
> 0)
1727 g_free(self
->icons
);
1730 if (PROP_GETA32(self
->window
, net_wm_icon
, cardinal
, &data
, &num
)) {
1731 /* figure out how many valid icons are in here */
1733 while (num
- i
> 2) {
1737 if (i
> num
|| w
*h
== 0) break;
1741 self
->icons
= g_new(ObClientIcon
, self
->nicons
);
1743 /* store the icons */
1745 for (j
= 0; j
< self
->nicons
; ++j
) {
1748 w
= self
->icons
[j
].width
= data
[i
++];
1749 h
= self
->icons
[j
].height
= data
[i
++];
1751 if (w
*h
== 0) continue;
1753 self
->icons
[j
].data
= g_new(RrPixel32
, w
* h
);
1754 for (x
= 0, y
= 0, t
= 0; t
< w
* h
; ++t
, ++x
, ++i
) {
1759 self
->icons
[j
].data
[t
] =
1760 (((data
[i
] >> 24) & 0xff) << RrDefaultAlphaOffset
) +
1761 (((data
[i
] >> 16) & 0xff) << RrDefaultRedOffset
) +
1762 (((data
[i
] >> 8) & 0xff) << RrDefaultGreenOffset
) +
1763 (((data
[i
] >> 0) & 0xff) << RrDefaultBlueOffset
);
1769 } else if (PROP_GETA32(self
->window
, kwm_win_icon
,
1770 kwm_win_icon
, &data
, &num
)) {
1773 self
->icons
= g_new(ObClientIcon
, self
->nicons
);
1774 xerror_set_ignore(TRUE
);
1775 if (!RrPixmapToRGBA(ob_rr_inst
,
1777 &self
->icons
[self
->nicons
-1].width
,
1778 &self
->icons
[self
->nicons
-1].height
,
1779 &self
->icons
[self
->nicons
-1].data
)) {
1780 g_free(&self
->icons
[self
->nicons
-1]);
1783 xerror_set_ignore(FALSE
);
1789 if ((hints
= XGetWMHints(ob_display
, self
->window
))) {
1790 if (hints
->flags
& IconPixmapHint
) {
1792 self
->icons
= g_new(ObClientIcon
, self
->nicons
);
1793 xerror_set_ignore(TRUE
);
1794 if (!RrPixmapToRGBA(ob_rr_inst
,
1796 (hints
->flags
& IconMaskHint
?
1797 hints
->icon_mask
: None
),
1798 &self
->icons
[self
->nicons
-1].width
,
1799 &self
->icons
[self
->nicons
-1].height
,
1800 &self
->icons
[self
->nicons
-1].data
)){
1801 g_free(&self
->icons
[self
->nicons
-1]);
1804 xerror_set_ignore(FALSE
);
1811 frame_adjust_icon(self
->frame
);
1814 static void client_change_state(ObClient
*self
)
1817 gulong netstate
[11];
1820 state
[0] = self
->wmstate
;
1822 PROP_SETA32(self
->window
, wm_state
, wm_state
, state
, 2);
1826 netstate
[num
++] = prop_atoms
.net_wm_state_modal
;
1828 netstate
[num
++] = prop_atoms
.net_wm_state_shaded
;
1830 netstate
[num
++] = prop_atoms
.net_wm_state_hidden
;
1831 if (self
->skip_taskbar
)
1832 netstate
[num
++] = prop_atoms
.net_wm_state_skip_taskbar
;
1833 if (self
->skip_pager
)
1834 netstate
[num
++] = prop_atoms
.net_wm_state_skip_pager
;
1835 if (self
->fullscreen
)
1836 netstate
[num
++] = prop_atoms
.net_wm_state_fullscreen
;
1838 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_vert
;
1840 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_horz
;
1842 netstate
[num
++] = prop_atoms
.net_wm_state_above
;
1844 netstate
[num
++] = prop_atoms
.net_wm_state_below
;
1845 if (self
->undecorated
)
1846 netstate
[num
++] = prop_atoms
.ob_wm_state_undecorated
;
1847 PROP_SETA32(self
->window
, net_wm_state
, atom
, netstate
, num
);
1849 client_calc_layer(self
);
1852 frame_adjust_state(self
->frame
);
1855 ObClient
*client_search_focus_tree(ObClient
*self
)
1860 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
1861 if (client_focused(it
->data
)) return it
->data
;
1862 if ((ret
= client_search_focus_tree(it
->data
))) return ret
;
1867 ObClient
*client_search_focus_tree_full(ObClient
*self
)
1869 if (self
->transient_for
) {
1870 if (self
->transient_for
!= OB_TRAN_GROUP
) {
1871 return client_search_focus_tree_full(self
->transient_for
);
1874 gboolean recursed
= FALSE
;
1876 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
))
1877 if (!((ObClient
*)it
->data
)->transient_for
) {
1879 if ((c
= client_search_focus_tree_full(it
->data
)))
1888 /* this function checks the whole tree, the client_search_focus_tree~
1889 does not, so we need to check this window */
1890 if (client_focused(self
))
1892 return client_search_focus_tree(self
);
1895 static ObStackingLayer
calc_layer(ObClient
*self
)
1899 if (self
->fullscreen
&&
1900 (client_focused(self
) || client_search_focus_tree(self
)))
1901 l
= OB_STACKING_LAYER_FULLSCREEN
;
1902 else if (self
->type
== OB_CLIENT_TYPE_DESKTOP
)
1903 l
= OB_STACKING_LAYER_DESKTOP
;
1904 else if (self
->type
== OB_CLIENT_TYPE_DOCK
) {
1905 if (self
->below
) l
= OB_STACKING_LAYER_NORMAL
;
1906 else l
= OB_STACKING_LAYER_ABOVE
;
1908 else if (self
->above
) l
= OB_STACKING_LAYER_ABOVE
;
1909 else if (self
->below
) l
= OB_STACKING_LAYER_BELOW
;
1910 else l
= OB_STACKING_LAYER_NORMAL
;
1915 static void client_calc_layer_recursive(ObClient
*self
, ObClient
*orig
,
1916 ObStackingLayer l
, gboolean raised
)
1918 ObStackingLayer old
, own
;
1922 own
= calc_layer(self
);
1923 self
->layer
= l
> own
? l
: own
;
1925 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
1926 client_calc_layer_recursive(it
->data
, orig
,
1927 l
, raised
? raised
: l
!= old
);
1929 if (!raised
&& l
!= old
)
1930 if (orig
->frame
) { /* only restack if the original window is managed */
1931 stacking_remove(CLIENT_AS_WINDOW(self
));
1932 stacking_add(CLIENT_AS_WINDOW(self
));
1936 void client_calc_layer(ObClient
*self
)
1943 /* transients take on the layer of their parents */
1944 self
= client_search_top_transient(self
);
1946 l
= calc_layer(self
);
1948 client_calc_layer_recursive(self
, orig
, l
, FALSE
);
1951 gboolean
client_should_show(ObClient
*self
)
1955 if (client_normal(self
) && screen_showing_desktop
)
1958 if (self->transient_for) {
1959 if (self->transient_for != OB_TRAN_GROUP)
1960 return client_should_show(self->transient_for);
1964 for (it = self->group->members; it; it = g_slist_next(it)) {
1965 ObClient *c = it->data;
1966 if (c != self && !c->transient_for) {
1967 if (client_should_show(c))
1974 if (self
->desktop
== screen_desktop
|| self
->desktop
== DESKTOP_ALL
)
1980 static void client_showhide(ObClient
*self
)
1983 if (client_should_show(self
))
1984 frame_show(self
->frame
);
1986 frame_hide(self
->frame
);
1989 gboolean
client_normal(ObClient
*self
) {
1990 return ! (self
->type
== OB_CLIENT_TYPE_DESKTOP
||
1991 self
->type
== OB_CLIENT_TYPE_DOCK
||
1992 self
->type
== OB_CLIENT_TYPE_SPLASH
);
1995 static void client_apply_startup_state(ObClient
*self
)
1997 /* these are in a carefully crafted order.. */
2000 self
->iconic
= FALSE
;
2001 client_iconify(self
, TRUE
, FALSE
);
2003 if (self
->fullscreen
) {
2004 self
->fullscreen
= FALSE
;
2005 client_fullscreen(self
, TRUE
, FALSE
);
2007 if (self
->undecorated
) {
2008 self
->undecorated
= FALSE
;
2009 client_set_undecorated(self
, TRUE
);
2012 self
->shaded
= FALSE
;
2013 client_shade(self
, TRUE
);
2016 client_urgent_notify(self
);
2018 if (self
->max_vert
&& self
->max_horz
) {
2019 self
->max_vert
= self
->max_horz
= FALSE
;
2020 client_maximize(self
, TRUE
, 0, FALSE
);
2021 } else if (self
->max_vert
) {
2022 self
->max_vert
= FALSE
;
2023 client_maximize(self
, TRUE
, 2, FALSE
);
2024 } else if (self
->max_horz
) {
2025 self
->max_horz
= FALSE
;
2026 client_maximize(self
, TRUE
, 1, FALSE
);
2029 /* nothing to do for the other states:
2038 void client_configure_full(ObClient
*self
, ObCorner anchor
,
2039 gint x
, gint y
, gint w
, gint h
,
2040 gboolean user
, gboolean final
,
2041 gboolean force_reply
)
2044 gboolean send_resize_client
;
2045 gboolean moved
= FALSE
, resized
= FALSE
;
2046 guint fdecor
= self
->frame
->decorations
;
2047 gboolean fhorz
= self
->frame
->max_horz
;
2049 /* make the frame recalculate its dimentions n shit without changing
2050 anything visible for real, this way the constraints below can work with
2051 the updated frame dimensions. */
2052 frame_adjust_area(self
->frame
, TRUE
, TRUE
, TRUE
);
2054 /* gets the frame's position */
2055 frame_client_gravity(self
->frame
, &x
, &y
);
2057 /* these positions are frame positions, not client positions */
2059 /* set the size and position if fullscreen */
2060 if (self
->fullscreen
) {
2064 i
= client_monitor(self
);
2065 a
= screen_physical_area_monitor(i
);
2072 user
= FALSE
; /* ignore that increment etc shit when in fullscreen */
2076 a
= screen_area_monitor(self
->desktop
, client_monitor(self
));
2078 /* set the size and position if maximized */
2079 if (self
->max_horz
) {
2081 w
= a
->width
- self
->frame
->size
.left
- self
->frame
->size
.right
;
2083 if (self
->max_vert
) {
2085 h
= a
->height
- self
->frame
->size
.top
- self
->frame
->size
.bottom
;
2089 /* gets the client's position */
2090 frame_frame_gravity(self
->frame
, &x
, &y
);
2092 /* these override the above states! if you cant move you can't move! */
2094 if (!(self
->functions
& OB_CLIENT_FUNC_MOVE
)) {
2098 if (!(self
->functions
& OB_CLIENT_FUNC_RESIZE
)) {
2099 w
= self
->area
.width
;
2100 h
= self
->area
.height
;
2104 if (!(w
== self
->area
.width
&& h
== self
->area
.height
)) {
2105 gint basew
, baseh
, minw
, minh
;
2107 /* base size is substituted with min size if not specified */
2108 if (self
->base_size
.width
|| self
->base_size
.height
) {
2109 basew
= self
->base_size
.width
;
2110 baseh
= self
->base_size
.height
;
2112 basew
= self
->min_size
.width
;
2113 baseh
= self
->min_size
.height
;
2115 /* min size is substituted with base size if not specified */
2116 if (self
->min_size
.width
|| self
->min_size
.height
) {
2117 minw
= self
->min_size
.width
;
2118 minh
= self
->min_size
.height
;
2120 minw
= self
->base_size
.width
;
2121 minh
= self
->base_size
.height
;
2124 /* if this is a user-requested resize, then check against min/max
2127 /* smaller than min size or bigger than max size? */
2128 if (w
> self
->max_size
.width
) w
= self
->max_size
.width
;
2129 if (w
< minw
) w
= minw
;
2130 if (h
> self
->max_size
.height
) h
= self
->max_size
.height
;
2131 if (h
< minh
) h
= minh
;
2136 /* keep to the increments */
2137 w
/= self
->size_inc
.width
;
2138 h
/= self
->size_inc
.height
;
2140 /* you cannot resize to nothing */
2141 if (basew
+ w
< 1) w
= 1 - basew
;
2142 if (baseh
+ h
< 1) h
= 1 - baseh
;
2144 /* store the logical size */
2145 SIZE_SET(self
->logical_size
,
2146 self
->size_inc
.width
> 1 ? w
: w
+ basew
,
2147 self
->size_inc
.height
> 1 ? h
: h
+ baseh
);
2149 w
*= self
->size_inc
.width
;
2150 h
*= self
->size_inc
.height
;
2155 /* adjust the height to match the width for the aspect ratios.
2156 for this, min size is not substituted for base size ever. */
2157 w
-= self
->base_size
.width
;
2158 h
-= self
->base_size
.height
;
2160 if (!self
->fullscreen
) {
2161 if (self
->min_ratio
)
2162 if (h
* self
->min_ratio
> w
) {
2163 h
= (gint
)(w
/ self
->min_ratio
);
2165 /* you cannot resize to nothing */
2168 w
= (gint
)(h
* self
->min_ratio
);
2171 if (self
->max_ratio
)
2172 if (h
* self
->max_ratio
< w
) {
2173 h
= (gint
)(w
/ self
->max_ratio
);
2175 /* you cannot resize to nothing */
2178 w
= (gint
)(h
* self
->min_ratio
);
2183 w
+= self
->base_size
.width
;
2184 h
+= self
->base_size
.height
;
2191 case OB_CORNER_TOPLEFT
:
2193 case OB_CORNER_TOPRIGHT
:
2194 x
-= w
- self
->area
.width
;
2196 case OB_CORNER_BOTTOMLEFT
:
2197 y
-= h
- self
->area
.height
;
2199 case OB_CORNER_BOTTOMRIGHT
:
2200 x
-= w
- self
->area
.width
;
2201 y
-= h
- self
->area
.height
;
2205 moved
= x
!= self
->area
.x
|| y
!= self
->area
.y
;
2206 resized
= w
!= self
->area
.width
|| h
!= self
->area
.height
;
2208 oldw
= self
->area
.width
;
2209 oldh
= self
->area
.height
;
2210 RECT_SET(self
->area
, x
, y
, w
, h
);
2212 /* for app-requested resizes, always resize if 'resized' is true.
2213 for user-requested ones, only resize if final is true, or when
2214 resizing in redraw mode */
2215 send_resize_client
= ((!user
&& resized
) ||
2217 (resized
&& config_resize_redraw
))));
2219 /* if the client is enlarging, then resize the client before the frame */
2220 if (send_resize_client
&& user
&& (w
> oldw
|| h
> oldh
))
2221 XResizeWindow(ob_display
, self
->window
, MAX(w
, oldw
), MAX(h
, oldh
));
2223 /* move/resize the frame to match the request */
2225 if (self
->decorations
!= fdecor
|| self
->max_horz
!= fhorz
)
2226 moved
= resized
= TRUE
;
2228 if (moved
|| resized
)
2229 frame_adjust_area(self
->frame
, moved
, resized
, FALSE
);
2231 if (!resized
&& (force_reply
|| ((!user
&& moved
) || (user
&& final
))))
2234 event
.type
= ConfigureNotify
;
2235 event
.xconfigure
.display
= ob_display
;
2236 event
.xconfigure
.event
= self
->window
;
2237 event
.xconfigure
.window
= self
->window
;
2239 /* root window real coords */
2240 event
.xconfigure
.x
= self
->frame
->area
.x
+ self
->frame
->size
.left
-
2242 event
.xconfigure
.y
= self
->frame
->area
.y
+ self
->frame
->size
.top
-
2244 event
.xconfigure
.width
= w
;
2245 event
.xconfigure
.height
= h
;
2246 event
.xconfigure
.border_width
= 0;
2247 event
.xconfigure
.above
= self
->frame
->plate
;
2248 event
.xconfigure
.override_redirect
= FALSE
;
2249 XSendEvent(event
.xconfigure
.display
, event
.xconfigure
.window
,
2250 FALSE
, StructureNotifyMask
, &event
);
2254 /* if the client is shrinking, then resize the frame before the client */
2255 if (send_resize_client
&& (!user
|| (w
<= oldw
|| h
<= oldh
)))
2256 XResizeWindow(ob_display
, self
->window
, w
, h
);
2261 void client_fullscreen(ObClient
*self
, gboolean fs
, gboolean savearea
)
2265 if (!(self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
) || /* can't */
2266 self
->fullscreen
== fs
) return; /* already done */
2268 self
->fullscreen
= fs
;
2269 client_change_state(self
); /* change the state hints on the client,
2270 and adjust out layer/stacking */
2274 self
->pre_fullscreen_area
= self
->area
;
2276 /* these are not actually used cuz client_configure will set them
2277 as appropriate when the window is fullscreened */
2282 if (self
->pre_fullscreen_area
.width
> 0 &&
2283 self
->pre_fullscreen_area
.height
> 0)
2285 x
= self
->pre_fullscreen_area
.x
;
2286 y
= self
->pre_fullscreen_area
.y
;
2287 w
= self
->pre_fullscreen_area
.width
;
2288 h
= self
->pre_fullscreen_area
.height
;
2289 RECT_SET(self
->pre_fullscreen_area
, 0, 0, 0, 0);
2291 /* pick some fallbacks... */
2292 a
= screen_area_monitor(self
->desktop
, 0);
2293 x
= a
->x
+ a
->width
/ 4;
2294 y
= a
->y
+ a
->height
/ 4;
2300 client_setup_decor_and_functions(self
);
2302 client_move_resize(self
, x
, y
, w
, h
);
2304 /* try focus us when we go into fullscreen mode */
2308 static void client_iconify_recursive(ObClient
*self
,
2309 gboolean iconic
, gboolean curdesk
)
2312 gboolean changed
= FALSE
;
2315 if (self
->iconic
!= iconic
) {
2316 ob_debug("%sconifying window: 0x%lx\n", (iconic
? "I" : "Uni"),
2319 self
->iconic
= iconic
;
2322 if (self
->functions
& OB_CLIENT_FUNC_ICONIFY
) {
2325 old
= self
->wmstate
;
2326 self
->wmstate
= IconicState
;
2327 if (old
!= self
->wmstate
)
2328 PROP_MSG(self
->window
, kde_wm_change_state
,
2329 self
->wmstate
, 1, 0, 0);
2331 /* update the focus lists.. iconic windows go to the bottom of
2332 the list, put the new iconic window at the 'top of the
2334 focus_order_to_top(self
);
2342 client_set_desktop(self
, screen_desktop
, FALSE
);
2344 old
= self
->wmstate
;
2345 self
->wmstate
= self
->shaded
? IconicState
: NormalState
;
2346 if (old
!= self
->wmstate
)
2347 PROP_MSG(self
->window
, kde_wm_change_state
,
2348 self
->wmstate
, 1, 0, 0);
2350 /* this puts it after the current focused window */
2351 focus_order_remove(self
);
2352 focus_order_add_new(self
);
2359 client_change_state(self
);
2360 client_showhide(self
);
2361 if (STRUT_EXISTS(self
->strut
))
2362 screen_update_areas();
2365 /* iconify all transients */
2366 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
2367 if (it
->data
!= self
) client_iconify_recursive(it
->data
,
2371 void client_iconify(ObClient
*self
, gboolean iconic
, gboolean curdesk
)
2373 /* move up the transient chain as far as possible first */
2374 self
= client_search_top_transient(self
);
2376 client_iconify_recursive(client_search_top_transient(self
),
2380 void client_maximize(ObClient
*self
, gboolean max
, gint dir
, gboolean savearea
)
2384 g_assert(dir
== 0 || dir
== 1 || dir
== 2);
2385 if (!(self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
)) return; /* can't */
2387 /* check if already done */
2389 if (dir
== 0 && self
->max_horz
&& self
->max_vert
) return;
2390 if (dir
== 1 && self
->max_horz
) return;
2391 if (dir
== 2 && self
->max_vert
) return;
2393 if (dir
== 0 && !self
->max_horz
&& !self
->max_vert
) return;
2394 if (dir
== 1 && !self
->max_horz
) return;
2395 if (dir
== 2 && !self
->max_vert
) return;
2398 /* we just tell it to configure in the same place and client_configure
2399 worries about filling the screen with the window */
2402 w
= self
->area
.width
;
2403 h
= self
->area
.height
;
2407 if ((dir
== 0 || dir
== 1) && !self
->max_horz
) { /* horz */
2408 RECT_SET(self
->pre_max_area
,
2409 self
->area
.x
, self
->pre_max_area
.y
,
2410 self
->area
.width
, self
->pre_max_area
.height
);
2412 if ((dir
== 0 || dir
== 2) && !self
->max_vert
) { /* vert */
2413 RECT_SET(self
->pre_max_area
,
2414 self
->pre_max_area
.x
, self
->area
.y
,
2415 self
->pre_max_area
.width
, self
->area
.height
);
2421 a
= screen_area_monitor(self
->desktop
, 0);
2422 if ((dir
== 0 || dir
== 1) && self
->max_horz
) { /* horz */
2423 if (self
->pre_max_area
.width
> 0) {
2424 x
= self
->pre_max_area
.x
;
2425 w
= self
->pre_max_area
.width
;
2427 RECT_SET(self
->pre_max_area
, 0, self
->pre_max_area
.y
,
2428 0, self
->pre_max_area
.height
);
2430 /* pick some fallbacks... */
2431 x
= a
->x
+ a
->width
/ 4;
2435 if ((dir
== 0 || dir
== 2) && self
->max_vert
) { /* vert */
2436 if (self
->pre_max_area
.height
> 0) {
2437 y
= self
->pre_max_area
.y
;
2438 h
= self
->pre_max_area
.height
;
2440 RECT_SET(self
->pre_max_area
, self
->pre_max_area
.x
, 0,
2441 self
->pre_max_area
.width
, 0);
2443 /* pick some fallbacks... */
2444 y
= a
->y
+ a
->height
/ 4;
2450 if (dir
== 0 || dir
== 1) /* horz */
2451 self
->max_horz
= max
;
2452 if (dir
== 0 || dir
== 2) /* vert */
2453 self
->max_vert
= max
;
2455 client_change_state(self
); /* change the state hints on the client */
2457 client_setup_decor_and_functions(self
);
2459 client_move_resize(self
, x
, y
, w
, h
);
2462 void client_shade(ObClient
*self
, gboolean shade
)
2464 if ((!(self
->functions
& OB_CLIENT_FUNC_SHADE
) &&
2465 shade
) || /* can't shade */
2466 self
->shaded
== shade
) return; /* already done */
2468 /* when we're iconic, don't change the wmstate */
2469 if (!self
->iconic
) {
2472 old
= self
->wmstate
;
2473 self
->wmstate
= shade
? IconicState
: NormalState
;
2474 if (old
!= self
->wmstate
)
2475 PROP_MSG(self
->window
, kde_wm_change_state
,
2476 self
->wmstate
, 1, 0, 0);
2479 self
->shaded
= shade
;
2480 client_change_state(self
);
2481 /* resize the frame to just the titlebar */
2482 frame_adjust_area(self
->frame
, FALSE
, FALSE
, FALSE
);
2485 void client_close(ObClient
*self
)
2489 if (!(self
->functions
& OB_CLIENT_FUNC_CLOSE
)) return;
2491 /* in the case that the client provides no means to requesting that it
2492 close, we just kill it */
2493 if (!self
->delete_window
)
2497 XXX: itd be cool to do timeouts and shit here for killing the client's
2499 like... if the window is around after 5 seconds, then the close button
2500 turns a nice red, and if this function is called again, the client is
2504 ce
.xclient
.type
= ClientMessage
;
2505 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
2506 ce
.xclient
.display
= ob_display
;
2507 ce
.xclient
.window
= self
->window
;
2508 ce
.xclient
.format
= 32;
2509 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_delete_window
;
2510 ce
.xclient
.data
.l
[1] = event_curtime
;
2511 ce
.xclient
.data
.l
[2] = 0l;
2512 ce
.xclient
.data
.l
[3] = 0l;
2513 ce
.xclient
.data
.l
[4] = 0l;
2514 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
2517 void client_kill(ObClient
*self
)
2519 XKillClient(ob_display
, self
->window
);
2522 void client_set_desktop_recursive(ObClient
*self
,
2523 guint target
, gboolean donthide
)
2528 if (target
!= self
->desktop
) {
2530 ob_debug("Setting desktop %u\n", target
+1);
2532 g_assert(target
< screen_num_desktops
|| target
== DESKTOP_ALL
);
2534 /* remove from the old desktop(s) */
2535 focus_order_remove(self
);
2537 old
= self
->desktop
;
2538 self
->desktop
= target
;
2539 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, target
);
2540 /* the frame can display the current desktop state */
2541 frame_adjust_state(self
->frame
);
2542 /* 'move' the window to the new desktop */
2544 client_showhide(self
);
2545 /* raise if it was not already on the desktop */
2546 if (old
!= DESKTOP_ALL
)
2548 if (STRUT_EXISTS(self
->strut
))
2549 screen_update_areas();
2551 /* add to the new desktop(s) */
2552 if (config_focus_new
)
2553 focus_order_to_top(self
);
2555 focus_order_to_bottom(self
);
2558 /* move all transients */
2559 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
2560 if (it
->data
!= self
) client_set_desktop_recursive(it
->data
,
2564 void client_set_desktop(ObClient
*self
, guint target
, gboolean donthide
)
2566 client_set_desktop_recursive(client_search_top_transient(self
),
2570 ObClient
*client_search_modal_child(ObClient
*self
)
2575 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
2576 ObClient
*c
= it
->data
;
2577 if ((ret
= client_search_modal_child(c
))) return ret
;
2578 if (c
->modal
) return c
;
2583 gboolean
client_validate(ObClient
*self
)
2587 XSync(ob_display
, FALSE
); /* get all events on the server */
2589 if (XCheckTypedWindowEvent(ob_display
, self
->window
, DestroyNotify
, &e
) ||
2590 XCheckTypedWindowEvent(ob_display
, self
->window
, UnmapNotify
, &e
)) {
2591 XPutBackEvent(ob_display
, &e
);
2598 void client_set_wm_state(ObClient
*self
, glong state
)
2600 if (state
== self
->wmstate
) return; /* no change */
2604 client_iconify(self
, TRUE
, TRUE
);
2607 client_iconify(self
, FALSE
, TRUE
);
2612 void client_set_state(ObClient
*self
, Atom action
, glong data1
, glong data2
)
2614 gboolean shaded
= self
->shaded
;
2615 gboolean fullscreen
= self
->fullscreen
;
2616 gboolean undecorated
= self
->undecorated
;
2617 gboolean max_horz
= self
->max_horz
;
2618 gboolean max_vert
= self
->max_vert
;
2619 gboolean modal
= self
->modal
;
2620 gboolean iconic
= self
->iconic
;
2623 if (!(action
== prop_atoms
.net_wm_state_add
||
2624 action
== prop_atoms
.net_wm_state_remove
||
2625 action
== prop_atoms
.net_wm_state_toggle
))
2626 /* an invalid action was passed to the client message, ignore it */
2629 for (i
= 0; i
< 2; ++i
) {
2630 Atom state
= i
== 0 ? data1
: data2
;
2632 if (!state
) continue;
2634 /* if toggling, then pick whether we're adding or removing */
2635 if (action
== prop_atoms
.net_wm_state_toggle
) {
2636 if (state
== prop_atoms
.net_wm_state_modal
)
2637 action
= modal
? prop_atoms
.net_wm_state_remove
:
2638 prop_atoms
.net_wm_state_add
;
2639 else if (state
== prop_atoms
.net_wm_state_maximized_vert
)
2640 action
= self
->max_vert
? prop_atoms
.net_wm_state_remove
:
2641 prop_atoms
.net_wm_state_add
;
2642 else if (state
== prop_atoms
.net_wm_state_maximized_horz
)
2643 action
= self
->max_horz
? prop_atoms
.net_wm_state_remove
:
2644 prop_atoms
.net_wm_state_add
;
2645 else if (state
== prop_atoms
.net_wm_state_shaded
)
2646 action
= shaded
? prop_atoms
.net_wm_state_remove
:
2647 prop_atoms
.net_wm_state_add
;
2648 else if (state
== prop_atoms
.net_wm_state_skip_taskbar
)
2649 action
= self
->skip_taskbar
?
2650 prop_atoms
.net_wm_state_remove
:
2651 prop_atoms
.net_wm_state_add
;
2652 else if (state
== prop_atoms
.net_wm_state_skip_pager
)
2653 action
= self
->skip_pager
?
2654 prop_atoms
.net_wm_state_remove
:
2655 prop_atoms
.net_wm_state_add
;
2656 else if (state
== prop_atoms
.net_wm_state_hidden
)
2657 action
= self
->iconic
?
2658 prop_atoms
.net_wm_state_remove
:
2659 prop_atoms
.net_wm_state_add
;
2660 else if (state
== prop_atoms
.net_wm_state_fullscreen
)
2661 action
= fullscreen
?
2662 prop_atoms
.net_wm_state_remove
:
2663 prop_atoms
.net_wm_state_add
;
2664 else if (state
== prop_atoms
.net_wm_state_above
)
2665 action
= self
->above
? prop_atoms
.net_wm_state_remove
:
2666 prop_atoms
.net_wm_state_add
;
2667 else if (state
== prop_atoms
.net_wm_state_below
)
2668 action
= self
->below
? prop_atoms
.net_wm_state_remove
:
2669 prop_atoms
.net_wm_state_add
;
2670 else if (state
== prop_atoms
.ob_wm_state_undecorated
)
2671 action
= undecorated
? prop_atoms
.net_wm_state_remove
:
2672 prop_atoms
.net_wm_state_add
;
2675 if (action
== prop_atoms
.net_wm_state_add
) {
2676 if (state
== prop_atoms
.net_wm_state_modal
) {
2678 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
2680 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
2682 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
2684 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
2685 self
->skip_taskbar
= TRUE
;
2686 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
2687 self
->skip_pager
= TRUE
;
2688 } else if (state
== prop_atoms
.net_wm_state_hidden
) {
2690 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
2692 } else if (state
== prop_atoms
.net_wm_state_above
) {
2694 self
->below
= FALSE
;
2695 } else if (state
== prop_atoms
.net_wm_state_below
) {
2696 self
->above
= FALSE
;
2698 } else if (state
== prop_atoms
.ob_wm_state_undecorated
) {
2702 } else { /* action == prop_atoms.net_wm_state_remove */
2703 if (state
== prop_atoms
.net_wm_state_modal
) {
2705 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
2707 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
2709 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
2711 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
2712 self
->skip_taskbar
= FALSE
;
2713 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
2714 self
->skip_pager
= FALSE
;
2715 } else if (state
== prop_atoms
.net_wm_state_hidden
) {
2717 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
2719 } else if (state
== prop_atoms
.net_wm_state_above
) {
2720 self
->above
= FALSE
;
2721 } else if (state
== prop_atoms
.net_wm_state_below
) {
2722 self
->below
= FALSE
;
2723 } else if (state
== prop_atoms
.ob_wm_state_undecorated
) {
2724 undecorated
= FALSE
;
2728 if (max_horz
!= self
->max_horz
|| max_vert
!= self
->max_vert
) {
2729 if (max_horz
!= self
->max_horz
&& max_vert
!= self
->max_vert
) {
2731 if (max_horz
== max_vert
) { /* both going the same way */
2732 client_maximize(self
, max_horz
, 0, TRUE
);
2734 client_maximize(self
, max_horz
, 1, TRUE
);
2735 client_maximize(self
, max_vert
, 2, TRUE
);
2739 if (max_horz
!= self
->max_horz
)
2740 client_maximize(self
, max_horz
, 1, TRUE
);
2742 client_maximize(self
, max_vert
, 2, TRUE
);
2745 /* change fullscreen state before shading, as it will affect if the window
2747 if (fullscreen
!= self
->fullscreen
)
2748 client_fullscreen(self
, fullscreen
, TRUE
);
2749 if (shaded
!= self
->shaded
)
2750 client_shade(self
, shaded
);
2751 if (undecorated
!= self
->undecorated
)
2752 client_set_undecorated(self
, undecorated
);
2753 if (modal
!= self
->modal
) {
2754 self
->modal
= modal
;
2755 /* when a window changes modality, then its stacking order with its
2756 transients needs to change */
2759 if (iconic
!= self
->iconic
)
2760 client_iconify(self
, iconic
, FALSE
);
2762 client_calc_layer(self
);
2763 client_change_state(self
); /* change the hint to reflect these changes */
2766 ObClient
*client_focus_target(ObClient
*self
)
2770 /* if we have a modal child, then focus it, not us */
2771 child
= client_search_modal_child(client_search_top_transient(self
));
2772 if (child
) return child
;
2776 gboolean
client_can_focus(ObClient
*self
)
2780 /* choose the correct target */
2781 self
= client_focus_target(self
);
2783 if (!self
->frame
->visible
)
2786 if (!(self
->can_focus
|| self
->focus_notify
))
2789 /* do a check to see if the window has already been unmapped or destroyed
2790 do this intelligently while watching out for unmaps we've generated
2791 (ignore_unmaps > 0) */
2792 if (XCheckTypedWindowEvent(ob_display
, self
->window
,
2793 DestroyNotify
, &ev
)) {
2794 XPutBackEvent(ob_display
, &ev
);
2797 while (XCheckTypedWindowEvent(ob_display
, self
->window
,
2798 UnmapNotify
, &ev
)) {
2799 if (self
->ignore_unmaps
) {
2800 self
->ignore_unmaps
--;
2802 XPutBackEvent(ob_display
, &ev
);
2810 gboolean
client_focus(ObClient
*self
)
2812 /* choose the correct target */
2813 self
= client_focus_target(self
);
2815 if (!client_can_focus(self
)) {
2816 if (!self
->frame
->visible
) {
2817 /* update the focus lists */
2818 focus_order_to_top(self
);
2823 if (self
->can_focus
) {
2824 /* RevertToPointerRoot causes much more headache than RevertToNone, so
2825 I choose to use it always, hopefully to find errors quicker, if any
2826 are left. (I hate X. I hate focus events.)
2828 Update: Changing this to RevertToNone fixed a bug with mozilla (bug
2829 #799. So now it is RevertToNone again.
2831 XSetInputFocus(ob_display
, self
->window
, RevertToNone
,
2835 if (self
->focus_notify
) {
2837 ce
.xclient
.type
= ClientMessage
;
2838 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
2839 ce
.xclient
.display
= ob_display
;
2840 ce
.xclient
.window
= self
->window
;
2841 ce
.xclient
.format
= 32;
2842 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_take_focus
;
2843 ce
.xclient
.data
.l
[1] = event_curtime
;
2844 ce
.xclient
.data
.l
[2] = 0l;
2845 ce
.xclient
.data
.l
[3] = 0l;
2846 ce
.xclient
.data
.l
[4] = 0l;
2847 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
2851 ob_debug("%sively focusing %lx at %d\n",
2852 (self
->can_focus
? "act" : "pass"),
2853 self
->window
, (gint
) event_curtime
);
2856 /* Cause the FocusIn to come back to us. Important for desktop switches,
2857 since otherwise we'll have no FocusIn on the queue and send it off to
2858 the focus_backup. */
2859 XSync(ob_display
, FALSE
);
2863 /* Used when the current client is closed, focus_last will then prevent
2864 * focus from going to the mouse pointer */
2865 void client_unfocus(ObClient
*self
)
2867 if (focus_client
== self
) {
2869 ob_debug("client_unfocus for %lx\n", self
->window
);
2871 focus_fallback(OB_FOCUS_FALLBACK_CLOSED
);
2875 void client_activate(ObClient
*self
, gboolean here
, gboolean user
)
2877 /* XXX do some stuff here if user is false to determine if we really want
2878 to activate it or not (a parent or group member is currently active) */
2880 if (client_normal(self
) && screen_showing_desktop
)
2881 screen_show_desktop(FALSE
);
2883 client_iconify(self
, FALSE
, here
);
2884 if (self
->desktop
!= DESKTOP_ALL
&&
2885 self
->desktop
!= screen_desktop
) {
2887 client_set_desktop(self
, screen_desktop
, FALSE
);
2889 screen_set_desktop(self
->desktop
);
2890 } else if (!self
->frame
->visible
)
2891 /* if its not visible for other reasons, then don't mess
2895 client_shade(self
, FALSE
);
2899 /* we do this an action here. this is rather important. this is because
2900 we want the results from the focus change to take place BEFORE we go
2901 about raising the window. when a fullscreen window loses focus, we need
2902 this or else the raise wont be able to raise above the to-lose-focus
2903 fullscreen window. */
2907 void client_raise(ObClient
*self
)
2909 action_run_string("Raise", self
);
2912 void client_lower(ObClient
*self
)
2914 action_run_string("Lower", self
);
2917 gboolean
client_focused(ObClient
*self
)
2919 return self
== focus_client
;
2922 static ObClientIcon
* client_icon_recursive(ObClient
*self
, gint w
, gint h
)
2925 /* si is the smallest image >= req */
2926 /* li is the largest image < req */
2927 gulong size
, smallest
= 0xffffffff, largest
= 0, si
= 0, li
= 0;
2929 if (!self
->nicons
) {
2930 ObClientIcon
*parent
= NULL
;
2932 if (self
->transient_for
) {
2933 if (self
->transient_for
!= OB_TRAN_GROUP
)
2934 parent
= client_icon_recursive(self
->transient_for
, w
, h
);
2937 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
2938 ObClient
*c
= it
->data
;
2939 if (c
!= self
&& !c
->transient_for
) {
2940 if ((parent
= client_icon_recursive(c
, w
, h
)))
2950 for (i
= 0; i
< self
->nicons
; ++i
) {
2951 size
= self
->icons
[i
].width
* self
->icons
[i
].height
;
2952 if (size
< smallest
&& size
>= (unsigned)(w
* h
)) {
2956 if (size
> largest
&& size
<= (unsigned)(w
* h
)) {
2961 if (largest
== 0) /* didnt find one smaller than the requested size */
2962 return &self
->icons
[si
];
2963 return &self
->icons
[li
];
2966 const ObClientIcon
* client_icon(ObClient
*self
, gint w
, gint h
)
2969 static ObClientIcon deficon
;
2971 if (!(ret
= client_icon_recursive(self
, w
, h
))) {
2972 deficon
.width
= deficon
.height
= 48;
2973 deficon
.data
= ob_rr_theme
->def_win_icon
;
2979 /* this be mostly ripped from fvwm */
2980 ObClient
*client_find_directional(ObClient
*c
, ObDirection dir
)
2982 gint my_cx
, my_cy
, his_cx
, his_cy
;
2985 gint score
, best_score
;
2986 ObClient
*best_client
, *cur
;
2992 /* first, find the centre coords of the currently focused window */
2993 my_cx
= c
->frame
->area
.x
+ c
->frame
->area
.width
/ 2;
2994 my_cy
= c
->frame
->area
.y
+ c
->frame
->area
.height
/ 2;
2999 for(it
= g_list_first(client_list
); it
; it
= g_list_next(it
)) {
3002 /* the currently selected window isn't interesting */
3005 if (!client_normal(cur
))
3007 /* using c->desktop instead of screen_desktop doesn't work if the
3008 * current window was omnipresent, hope this doesn't have any other
3010 if(screen_desktop
!= cur
->desktop
&& cur
->desktop
!= DESKTOP_ALL
)
3014 if(!(client_focus_target(cur
) == cur
&&
3015 client_can_focus(cur
)))
3018 /* find the centre coords of this window, from the
3019 * currently focused window's point of view */
3020 his_cx
= (cur
->frame
->area
.x
- my_cx
)
3021 + cur
->frame
->area
.width
/ 2;
3022 his_cy
= (cur
->frame
->area
.y
- my_cy
)
3023 + cur
->frame
->area
.height
/ 2;
3025 if(dir
== OB_DIRECTION_NORTHEAST
|| dir
== OB_DIRECTION_SOUTHEAST
||
3026 dir
== OB_DIRECTION_SOUTHWEST
|| dir
== OB_DIRECTION_NORTHWEST
) {
3028 /* Rotate the diagonals 45 degrees counterclockwise.
3029 * To do this, multiply the matrix /+h +h\ with the
3030 * vector (x y). \-h +h/
3031 * h = sqrt(0.5). We can set h := 1 since absolute
3032 * distance doesn't matter here. */
3033 tx
= his_cx
+ his_cy
;
3034 his_cy
= -his_cx
+ his_cy
;
3039 case OB_DIRECTION_NORTH
:
3040 case OB_DIRECTION_SOUTH
:
3041 case OB_DIRECTION_NORTHEAST
:
3042 case OB_DIRECTION_SOUTHWEST
:
3043 offset
= (his_cx
< 0) ? -his_cx
: his_cx
;
3044 distance
= ((dir
== OB_DIRECTION_NORTH
||
3045 dir
== OB_DIRECTION_NORTHEAST
) ?
3048 case OB_DIRECTION_EAST
:
3049 case OB_DIRECTION_WEST
:
3050 case OB_DIRECTION_SOUTHEAST
:
3051 case OB_DIRECTION_NORTHWEST
:
3052 offset
= (his_cy
< 0) ? -his_cy
: his_cy
;
3053 distance
= ((dir
== OB_DIRECTION_WEST
||
3054 dir
== OB_DIRECTION_NORTHWEST
) ?
3059 /* the target must be in the requested direction */
3063 /* Calculate score for this window. The smaller the better. */
3064 score
= distance
+ offset
;
3066 /* windows more than 45 degrees off the direction are
3067 * heavily penalized and will only be chosen if nothing
3068 * else within a million pixels */
3069 if(offset
> distance
)
3072 if(best_score
== -1 || score
< best_score
)
3080 void client_set_layer(ObClient
*self
, gint layer
)
3084 self
->above
= FALSE
;
3085 } else if (layer
== 0) {
3086 self
->below
= self
->above
= FALSE
;
3088 self
->below
= FALSE
;
3091 client_calc_layer(self
);
3092 client_change_state(self
); /* reflect this in the state hints */
3095 void client_set_undecorated(ObClient
*self
, gboolean undecorated
)
3097 if (self
->undecorated
!= undecorated
) {
3098 self
->undecorated
= undecorated
;
3099 client_setup_decor_and_functions(self
);
3100 /* Make sure the client knows it might have moved. Maybe there is a
3101 * better way of doing this so only one client_configure is sent, but
3102 * since 125 of these are sent per second when moving the window (with
3103 * user = FALSE) i doubt it matters much.
3105 client_configure(self
, OB_CORNER_TOPLEFT
, self
->area
.x
, self
->area
.y
,
3106 self
->area
.width
, self
->area
.height
, TRUE
, TRUE
);
3107 client_change_state(self
); /* reflect this in the state hints */
3111 /* Determines which physical monitor a client is on by calculating the
3112 area of the part of the client on each monitor. The number of the
3113 monitor containing the greatest area of the client is returned.*/
3114 guint
client_monitor(ObClient
*self
)
3120 for (i
= 0; i
< screen_num_monitors
; ++i
) {
3121 Rect
*area
= screen_physical_area_monitor(i
);
3122 if (RECT_INTERSECTS_RECT(*area
, self
->frame
->area
)) {
3126 RECT_SET_INTERSECTION(r
, *area
, self
->frame
->area
);
3127 v
= r
.width
* r
.height
;
3138 ObClient
*client_search_top_transient(ObClient
*self
)
3140 /* move up the transient chain as far as possible */
3141 if (self
->transient_for
) {
3142 if (self
->transient_for
!= OB_TRAN_GROUP
) {
3143 return client_search_top_transient(self
->transient_for
);
3147 g_assert(self
->group
);
3149 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
3150 ObClient
*c
= it
->data
;
3152 /* checking transient_for prevents infinate loops! */
3153 if (c
!= self
&& !c
->transient_for
)
3164 ObClient
*client_search_focus_parent(ObClient
*self
)
3166 if (self
->transient_for
) {
3167 if (self
->transient_for
!= OB_TRAN_GROUP
) {
3168 if (client_focused(self
->transient_for
))
3169 return self
->transient_for
;
3173 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
3174 ObClient
*c
= it
->data
;
3176 /* checking transient_for prevents infinate loops! */
3177 if (c
!= self
&& !c
->transient_for
)
3178 if (client_focused(c
))
3187 ObClient
*client_search_parent(ObClient
*self
, ObClient
*search
)
3189 if (self
->transient_for
) {
3190 if (self
->transient_for
!= OB_TRAN_GROUP
) {
3191 if (self
->transient_for
== search
)
3196 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
3197 ObClient
*c
= it
->data
;
3199 /* checking transient_for prevents infinate loops! */
3200 if (c
!= self
&& !c
->transient_for
)
3210 ObClient
*client_search_transient(ObClient
*self
, ObClient
*search
)
3214 for (sit
= self
->transients
; sit
; sit
= g_slist_next(sit
)) {
3215 if (sit
->data
== search
)
3217 if (client_search_transient(sit
->data
, search
))
3223 void client_update_sm_client_id(ObClient
*self
)
3225 g_free(self
->sm_client_id
);
3226 self
->sm_client_id
= NULL
;
3228 if (!PROP_GETS(self
->window
, sm_client_id
, locale
, &self
->sm_client_id
) &&
3230 PROP_GETS(self
->group
->leader
, sm_client_id
, locale
,
3231 &self
->sm_client_id
);
3234 #define WANT_EDGE(cur, c) \
3237 if(!client_normal(cur)) \
3239 if(screen_desktop != cur->desktop && cur->desktop != DESKTOP_ALL) \
3243 if(cur->layer < c->layer && !config_resist_layers_below) \
3246 #define HIT_EDGE(my_edge_start, my_edge_end, his_edge_start, his_edge_end) \
3247 if ((his_edge_start >= my_edge_start && \
3248 his_edge_start <= my_edge_end) || \
3249 (my_edge_start >= his_edge_start && \
3250 my_edge_start <= his_edge_end)) \
3253 /* finds the nearest edge in the given direction from the current client
3254 * note to self: the edge is the -frame- edge (the actual one), not the
3257 gint
client_directional_edge_search(ObClient
*c
, ObDirection dir
, gboolean hang
)
3259 gint dest
, monitor_dest
;
3260 gint my_edge_start
, my_edge_end
, my_offset
;
3267 a
= screen_area(c
->desktop
);
3268 monitor
= screen_area_monitor(c
->desktop
, client_monitor(c
));
3271 case OB_DIRECTION_NORTH
:
3272 my_edge_start
= c
->frame
->area
.x
;
3273 my_edge_end
= c
->frame
->area
.x
+ c
->frame
->area
.width
;
3274 my_offset
= c
->frame
->area
.y
+ (hang
? c
->frame
->area
.height
: 0);
3276 /* default: top of screen */
3277 dest
= a
->y
+ (hang
? c
->frame
->area
.height
: 0);
3278 monitor_dest
= monitor
->y
+ (hang
? c
->frame
->area
.height
: 0);
3279 /* if the monitor edge comes before the screen edge, */
3280 /* use that as the destination instead. (For xinerama) */
3281 if (monitor_dest
!= dest
&& my_offset
> monitor_dest
)
3282 dest
= monitor_dest
;
3284 for(it
= client_list
; it
&& my_offset
!= dest
; it
= g_list_next(it
)) {
3285 gint his_edge_start
, his_edge_end
, his_offset
;
3286 ObClient
*cur
= it
->data
;
3290 his_edge_start
= cur
->frame
->area
.x
;
3291 his_edge_end
= cur
->frame
->area
.x
+ cur
->frame
->area
.width
;
3292 his_offset
= cur
->frame
->area
.y
+
3293 (hang
? 0 : cur
->frame
->area
.height
);
3295 if(his_offset
+ 1 > my_offset
)
3298 if(his_offset
< dest
)
3301 HIT_EDGE(my_edge_start
, my_edge_end
, his_edge_start
, his_edge_end
)
3304 case OB_DIRECTION_SOUTH
:
3305 my_edge_start
= c
->frame
->area
.x
;
3306 my_edge_end
= c
->frame
->area
.x
+ c
->frame
->area
.width
;
3307 my_offset
= c
->frame
->area
.y
+ (hang
? 0 : c
->frame
->area
.height
);
3309 /* default: bottom of screen */
3310 dest
= a
->y
+ a
->height
- (hang
? c
->frame
->area
.height
: 0);
3311 monitor_dest
= monitor
->y
+ monitor
->height
-
3312 (hang
? c
->frame
->area
.height
: 0);
3313 /* if the monitor edge comes before the screen edge, */
3314 /* use that as the destination instead. (For xinerama) */
3315 if (monitor_dest
!= dest
&& my_offset
< monitor_dest
)
3316 dest
= monitor_dest
;
3318 for(it
= client_list
; it
&& my_offset
!= dest
; it
= g_list_next(it
)) {
3319 gint his_edge_start
, his_edge_end
, his_offset
;
3320 ObClient
*cur
= it
->data
;
3324 his_edge_start
= cur
->frame
->area
.x
;
3325 his_edge_end
= cur
->frame
->area
.x
+ cur
->frame
->area
.width
;
3326 his_offset
= cur
->frame
->area
.y
+
3327 (hang
? cur
->frame
->area
.height
: 0);
3330 if(his_offset
- 1 < my_offset
)
3333 if(his_offset
> dest
)
3336 HIT_EDGE(my_edge_start
, my_edge_end
, his_edge_start
, his_edge_end
)
3339 case OB_DIRECTION_WEST
:
3340 my_edge_start
= c
->frame
->area
.y
;
3341 my_edge_end
= c
->frame
->area
.y
+ c
->frame
->area
.height
;
3342 my_offset
= c
->frame
->area
.x
+ (hang
? c
->frame
->area
.width
: 0);
3344 /* default: leftmost egde of screen */
3345 dest
= a
->x
+ (hang
? c
->frame
->area
.width
: 0);
3346 monitor_dest
= monitor
->x
+ (hang
? c
->frame
->area
.width
: 0);
3347 /* if the monitor edge comes before the screen edge, */
3348 /* use that as the destination instead. (For xinerama) */
3349 if (monitor_dest
!= dest
&& my_offset
> monitor_dest
)
3350 dest
= monitor_dest
;
3352 for(it
= client_list
; it
&& my_offset
!= dest
; it
= g_list_next(it
)) {
3353 gint his_edge_start
, his_edge_end
, his_offset
;
3354 ObClient
*cur
= it
->data
;
3358 his_edge_start
= cur
->frame
->area
.y
;
3359 his_edge_end
= cur
->frame
->area
.y
+ cur
->frame
->area
.height
;
3360 his_offset
= cur
->frame
->area
.x
+
3361 (hang
? 0 : cur
->frame
->area
.width
);
3363 if(his_offset
+ 1 > my_offset
)
3366 if(his_offset
< dest
)
3369 HIT_EDGE(my_edge_start
, my_edge_end
, his_edge_start
, his_edge_end
)
3372 case OB_DIRECTION_EAST
:
3373 my_edge_start
= c
->frame
->area
.y
;
3374 my_edge_end
= c
->frame
->area
.y
+ c
->frame
->area
.height
;
3375 my_offset
= c
->frame
->area
.x
+ (hang
? 0 : c
->frame
->area
.width
);
3377 /* default: rightmost edge of screen */
3378 dest
= a
->x
+ a
->width
- (hang
? c
->frame
->area
.width
: 0);
3379 monitor_dest
= monitor
->x
+ monitor
->width
-
3380 (hang
? c
->frame
->area
.width
: 0);
3381 /* if the monitor edge comes before the screen edge, */
3382 /* use that as the destination instead. (For xinerama) */
3383 if (monitor_dest
!= dest
&& my_offset
< monitor_dest
)
3384 dest
= monitor_dest
;
3386 for(it
= client_list
; it
&& my_offset
!= dest
; it
= g_list_next(it
)) {
3387 gint his_edge_start
, his_edge_end
, his_offset
;
3388 ObClient
*cur
= it
->data
;
3392 his_edge_start
= cur
->frame
->area
.y
;
3393 his_edge_end
= cur
->frame
->area
.y
+ cur
->frame
->area
.height
;
3394 his_offset
= cur
->frame
->area
.x
+
3395 (hang
? cur
->frame
->area
.width
: 0);
3397 if(his_offset
- 1 < my_offset
)
3400 if(his_offset
> dest
)
3403 HIT_EDGE(my_edge_start
, my_edge_end
, his_edge_start
, his_edge_end
)
3406 case OB_DIRECTION_NORTHEAST
:
3407 case OB_DIRECTION_SOUTHEAST
:
3408 case OB_DIRECTION_NORTHWEST
:
3409 case OB_DIRECTION_SOUTHWEST
:
3410 /* not implemented */
3412 g_assert_not_reached();
3413 dest
= 0; /* suppress warning */
3418 ObClient
* client_under_pointer()
3422 ObClient
*ret
= NULL
;
3424 if (screen_pointer_pos(&x
, &y
)) {
3425 for (it
= stacking_list
; it
; it
= g_list_next(it
)) {
3426 if (WINDOW_IS_CLIENT(it
->data
)) {
3427 ObClient
*c
= WINDOW_AS_CLIENT(it
->data
);
3428 if (c
->frame
->visible
&&
3429 RECT_CONTAINS(c
->frame
->area
, x
, y
)) {
3439 gboolean
client_has_group_siblings(ObClient
*self
)
3441 return self
->group
&& self
->group
->members
->next
;