1 /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
3 client.c for the Openbox window manager
4 Copyright (c) 2004 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
, (guint32
*)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 void client_manage(Window window
)
211 XWindowAttributes attrib
;
212 XSetWindowAttributes attrib_set
;
214 gboolean activate
= FALSE
;
218 /* check if it has already been unmapped by the time we started mapping
219 the grab does a sync so we don't have to here */
220 if (XCheckTypedWindowEvent(ob_display
, window
, DestroyNotify
, &e
) ||
221 XCheckTypedWindowEvent(ob_display
, window
, UnmapNotify
, &e
)) {
222 XPutBackEvent(ob_display
, &e
);
225 return; /* don't manage it */
228 /* make sure it isn't an override-redirect window */
229 if (!XGetWindowAttributes(ob_display
, window
, &attrib
) ||
230 attrib
.override_redirect
) {
232 return; /* don't manage it */
235 /* is the window a docking app */
236 if ((wmhint
= XGetWMHints(ob_display
, window
))) {
237 if ((wmhint
->flags
& StateHint
) &&
238 wmhint
->initial_state
== WithdrawnState
) {
239 dock_add(window
, wmhint
);
247 ob_debug("Managing window: %lx\n", window
);
249 /* choose the events we want to receive on the CLIENT window */
250 attrib_set
.event_mask
= CLIENT_EVENTMASK
;
251 attrib_set
.do_not_propagate_mask
= CLIENT_NOPROPAGATEMASK
;
252 XChangeWindowAttributes(ob_display
, window
,
253 CWEventMask
|CWDontPropagate
, &attrib_set
);
256 /* create the ObClient struct, and populate it from the hints on the
258 self
= g_new0(ObClient
, 1);
259 self
->obwin
.type
= Window_Client
;
260 self
->window
= window
;
262 /* non-zero defaults */
263 self
->title_count
= 1;
264 self
->wmstate
= NormalState
;
266 self
->desktop
= screen_num_desktops
; /* always an invalid value */
268 client_get_all(self
);
269 client_restore_session_state(self
);
271 sn_app_started(self
->class);
273 /* update the focus lists, do this before the call to change_state or
274 it can end up in the list twice! */
275 focus_order_add_new(self
);
277 client_change_state(self
);
279 /* remove the client's border (and adjust re gravity) */
280 client_toggle_border(self
, FALSE
);
282 /* specify that if we exit, the window should not be destroyed and should
283 be reparented back to root automatically */
284 XChangeSaveSet(ob_display
, window
, SetModeInsert
);
286 /* create the decoration frame for the client window */
287 self
->frame
= frame_new();
289 frame_grab_client(self
->frame
, self
);
293 client_apply_startup_state(self
);
295 stacking_add(CLIENT_AS_WINDOW(self
));
296 client_restore_session_stacking(self
);
298 /* focus the new window? */
299 if (ob_state() != OB_STATE_STARTING
&&
300 (config_focus_new
|| client_search_focus_parent(self
)) &&
301 /* note the check against Type_Normal/Dialog, not client_normal(self),
302 which would also include other types. in this case we want more
303 strict rules for focus */
304 (self
->type
== OB_CLIENT_TYPE_NORMAL
||
305 self
->type
== OB_CLIENT_TYPE_DIALOG
))
309 if (self
->desktop
!= screen_desktop
) {
310 /* activate the window */
313 gboolean group_foc
= FALSE
;
318 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
))
320 if (client_focused(it
->data
))
328 (!self
->transient_for
&& (!self
->group
||
329 !self
->group
->members
->next
))) ||
330 client_search_focus_tree_full(self
) ||
332 !client_normal(focus_client
))
334 /* activate the window */
341 if (ob_state() == OB_STATE_RUNNING
) {
342 gint x
= self
->area
.x
, ox
= x
;
343 gint y
= self
->area
.y
, oy
= y
;
345 place_client(self
, &x
, &y
);
347 /* make sure the window is visible */
348 client_find_onscreen(self
, &x
, &y
,
349 self
->frame
->area
.width
,
350 self
->frame
->area
.height
,
351 /* non-normal clients has less rules, and
352 windows that are being restored from a session
353 do also. we can assume you want it back where
355 client_normal(self
) && !self
->session
);
357 if (x
!= ox
|| y
!= oy
)
358 client_move(self
, x
, y
);
361 client_showhide(self
);
363 /* use client_focus instead of client_activate cuz client_activate does
364 stuff like switch desktops etc and I'm not interested in all that when
365 a window maps since its not based on an action from the user like
366 clicking a window to activate is. so keep the new window out of the way
369 /* if using focus_delay, stop the timer now so that focus doesn't go
371 event_halt_focus_delay();
374 /* since focus can change the stacking orders, if we focus the window
375 then the standard raise it gets is not enough, we need to queue one
376 for after the focus change takes place */
380 /* client_activate does this but we aret using it so we have to do it
382 if (screen_showing_desktop
)
383 screen_show_desktop(FALSE
);
385 /* add to client list/map */
386 client_list
= g_list_append(client_list
, self
);
387 g_hash_table_insert(window_map
, &self
->window
, self
);
389 /* this has to happen after we're in the client_list */
390 screen_update_areas();
392 /* update the list hints */
395 keyboard_grab_for_client(self
, TRUE
);
396 mouse_grab_for_client(self
, TRUE
);
398 ob_debug("Managed window 0x%lx (%s)\n", window
, self
->class);
401 void client_unmanage_all()
403 while (client_list
!= NULL
)
404 client_unmanage(client_list
->data
);
407 void client_unmanage(ObClient
*self
)
412 ob_debug("Unmanaging window: %lx (%s)\n", self
->window
, self
->class);
414 g_assert(self
!= NULL
);
416 keyboard_grab_for_client(self
, FALSE
);
417 mouse_grab_for_client(self
, FALSE
);
419 /* potentially fix focusLast */
420 if (config_focus_last
)
421 grab_pointer(TRUE
, OB_CURSOR_NONE
);
423 /* remove the window from our save set */
424 XChangeSaveSet(ob_display
, self
->window
, SetModeDelete
);
426 /* we dont want events no more */
427 XSelectInput(ob_display
, self
->window
, NoEventMask
);
429 frame_hide(self
->frame
);
431 client_list
= g_list_remove(client_list
, self
);
432 stacking_remove(self
);
433 g_hash_table_remove(window_map
, &self
->window
);
435 /* update the focus lists */
436 focus_order_remove(self
);
438 /* once the client is out of the list, update the struts to remove it's
440 screen_update_areas();
442 for (it
= client_destructors
; it
; it
= g_slist_next(it
)) {
443 Destructor
*d
= it
->data
;
444 d
->func(self
, d
->data
);
447 if (focus_client
== self
) {
450 /* focus the last focused window on the desktop, and ignore enter
451 events from the unmap so it doesnt mess with the focus */
452 while (XCheckTypedEvent(ob_display
, EnterNotify
, &e
));
453 /* remove these flags so we don't end up getting focused in the
455 self
->can_focus
= FALSE
;
456 self
->focus_notify
= FALSE
;
458 client_unfocus(self
);
461 /* tell our parent(s) that we're gone */
462 if (self
->transient_for
== OB_TRAN_GROUP
) { /* transient of group */
465 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
))
466 if (it
->data
!= self
)
467 ((ObClient
*)it
->data
)->transients
=
468 g_slist_remove(((ObClient
*)it
->data
)->transients
, self
);
469 } else if (self
->transient_for
) { /* transient of window */
470 self
->transient_for
->transients
=
471 g_slist_remove(self
->transient_for
->transients
, self
);
474 /* tell our transients that we're gone */
475 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
476 if (((ObClient
*)it
->data
)->transient_for
!= OB_TRAN_GROUP
) {
477 ((ObClient
*)it
->data
)->transient_for
= NULL
;
478 client_calc_layer(it
->data
);
482 /* remove from its group */
484 group_remove(self
->group
, self
);
488 /* give the client its border back */
489 client_toggle_border(self
, TRUE
);
491 /* reparent the window out of the frame, and free the frame */
492 frame_release_client(self
->frame
, self
);
495 if (ob_state() != OB_STATE_EXITING
) {
496 /* these values should not be persisted across a window
498 PROP_ERASE(self
->window
, net_wm_desktop
);
499 PROP_ERASE(self
->window
, net_wm_state
);
500 PROP_ERASE(self
->window
, wm_state
);
502 /* if we're left in an unmapped state, the client wont be mapped. this
503 is bad, since we will no longer be managing the window on restart */
504 XMapWindow(ob_display
, self
->window
);
508 ob_debug("Unmanaged window 0x%lx\n", self
->window
);
510 /* free all data allocated in the client struct */
511 g_slist_free(self
->transients
);
512 for (j
= 0; j
< self
->nicons
; ++j
)
513 g_free(self
->icons
[j
].data
);
514 if (self
->nicons
> 0)
517 g_free(self
->icon_title
);
521 g_free(self
->sm_client_id
);
524 /* update the list hints */
527 if (config_focus_last
)
528 grab_pointer(FALSE
, OB_CURSOR_NONE
);
531 static void client_urgent_notify(ObClient
*self
)
534 frame_flash_start(self
->frame
);
536 frame_flash_stop(self
->frame
);
539 static void client_restore_session_state(ObClient
*self
)
543 if (!(it
= session_state_find(self
)))
546 self
->session
= it
->data
;
548 RECT_SET_POINT(self
->area
, self
->session
->x
, self
->session
->y
);
549 self
->positioned
= TRUE
;
550 if (self
->session
->w
> 0)
551 self
->area
.width
= self
->session
->w
;
552 if (self
->session
->h
> 0)
553 self
->area
.height
= self
->session
->h
;
554 XResizeWindow(ob_display
, self
->window
,
555 self
->area
.width
, self
->area
.height
);
557 self
->desktop
= (self
->session
->desktop
== DESKTOP_ALL
?
558 self
->session
->desktop
:
559 MIN(screen_num_desktops
- 1, self
->session
->desktop
));
560 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, self
->desktop
);
562 self
->shaded
= self
->session
->shaded
;
563 self
->iconic
= self
->session
->iconic
;
564 self
->skip_pager
= self
->session
->skip_pager
;
565 self
->skip_taskbar
= self
->session
->skip_taskbar
;
566 self
->fullscreen
= self
->session
->fullscreen
;
567 self
->above
= self
->session
->above
;
568 self
->below
= self
->session
->below
;
569 self
->max_horz
= self
->session
->max_horz
;
570 self
->max_vert
= self
->session
->max_vert
;
573 static void client_restore_session_stacking(ObClient
*self
)
577 if (!self
->session
) return;
579 it
= g_list_find(session_saved_state
, self
->session
);
580 for (it
= g_list_previous(it
); it
; it
= g_list_previous(it
)) {
583 for (cit
= client_list
; cit
; cit
= g_list_next(cit
))
584 if (session_state_cmp(it
->data
, cit
->data
))
587 client_calc_layer(self
);
588 stacking_below(CLIENT_AS_WINDOW(self
),
589 CLIENT_AS_WINDOW(cit
->data
));
595 void client_move_onscreen(ObClient
*self
, gboolean rude
)
597 gint x
= self
->area
.x
;
598 gint y
= self
->area
.y
;
599 if (client_find_onscreen(self
, &x
, &y
,
600 self
->frame
->area
.width
,
601 self
->frame
->area
.height
, rude
)) {
602 client_move(self
, x
, y
);
606 gboolean
client_find_onscreen(ObClient
*self
, gint
*x
, gint
*y
, gint w
, gint h
,
610 gint ox
= *x
, oy
= *y
;
612 frame_client_gravity(self
->frame
, x
, y
); /* get where the frame
615 /* XXX watch for xinerama dead areas */
617 a
= screen_area(self
->desktop
);
618 if (client_normal(self
)) {
619 if (!self
->strut
.right
&& *x
>= a
->x
+ a
->width
- 1)
620 *x
= a
->x
+ a
->width
- self
->frame
->area
.width
;
621 if (!self
->strut
.bottom
&& *y
>= a
->y
+ a
->height
- 1)
622 *y
= a
->y
+ a
->height
- self
->frame
->area
.height
;
623 if (!self
->strut
.left
&& *x
+ self
->frame
->area
.width
- 1 < a
->x
)
625 if (!self
->strut
.top
&& *y
+ self
->frame
->area
.height
- 1 < a
->y
)
630 /* this is my MOZILLA BITCHSLAP. oh ya it fucking feels good.
631 Java can suck it too. */
633 /* dont let windows map/move into the strut unless they
634 are bigger than the available area */
636 if (!self
->strut
.left
&& *x
< a
->x
) *x
= a
->x
;
637 if (!self
->strut
.right
&& *x
+ w
> a
->x
+ a
->width
)
638 *x
= a
->x
+ a
->width
- w
;
640 if (h
<= a
->height
) {
641 if (!self
->strut
.top
&& *y
< a
->y
) *y
= a
->y
;
642 if (!self
->strut
.bottom
&& *y
+ h
> a
->y
+ a
->height
)
643 *y
= a
->y
+ a
->height
- h
;
647 frame_frame_gravity(self
->frame
, x
, y
); /* get where the client
650 return ox
!= *x
|| oy
!= *y
;
653 static void client_toggle_border(ObClient
*self
, gboolean show
)
655 /* adjust our idea of where the client is, based on its border. When the
656 border is removed, the client should now be considered to be in a
658 when re-adding the border to the client, the same operation needs to be
660 gint oldx
= self
->area
.x
, oldy
= self
->area
.y
;
661 gint x
= oldx
, y
= oldy
;
662 switch(self
->gravity
) {
664 case NorthWestGravity
:
666 case SouthWestGravity
:
668 case NorthEastGravity
:
670 case SouthEastGravity
:
671 if (show
) x
-= self
->border_width
* 2;
672 else x
+= self
->border_width
* 2;
679 if (show
) x
-= self
->border_width
;
680 else x
+= self
->border_width
;
683 switch(self
->gravity
) {
685 case NorthWestGravity
:
687 case NorthEastGravity
:
689 case SouthWestGravity
:
691 case SouthEastGravity
:
692 if (show
) y
-= self
->border_width
* 2;
693 else y
+= self
->border_width
* 2;
700 if (show
) y
-= self
->border_width
;
701 else y
+= self
->border_width
;
708 XSetWindowBorderWidth(ob_display
, self
->window
, self
->border_width
);
710 /* move the client so it is back it the right spot _with_ its
712 if (x
!= oldx
|| y
!= oldy
)
713 XMoveWindow(ob_display
, self
->window
, x
, y
);
715 XSetWindowBorderWidth(ob_display
, self
->window
, 0);
719 static void client_get_all(ObClient
*self
)
721 client_get_area(self
);
722 client_update_transient_for(self
);
723 client_update_wmhints(self
);
724 client_get_startup_id(self
);
725 client_get_desktop(self
);
726 client_get_shaped(self
);
728 client_get_mwm_hints(self
);
729 client_get_type(self
);/* this can change the mwmhints for special cases */
731 /* The transient hint is used to pick a type, but the type can also affect
732 transiency (dialogs are always made transients). This is Havoc's idea,
733 but it is needed to make some apps work right (eg tsclient). */
734 client_update_transient_for(self
);
736 client_get_state(self
);
739 /* a couple type-based defaults for new windows */
741 /* this makes sure that these windows appear on all desktops */
742 if (self
->type
== OB_CLIENT_TYPE_DESKTOP
)
743 self
->desktop
= DESKTOP_ALL
;
746 client_update_protocols(self
);
748 client_get_gravity(self
); /* get the attribute gravity */
749 client_update_normal_hints(self
); /* this may override the attribute
752 /* got the type, the mwmhints, the protocols, and the normal hints
753 (min/max sizes), so we're ready to set up the decorations/functions */
754 client_setup_decor_and_functions(self
);
756 client_update_title(self
);
757 client_update_class(self
);
758 client_update_sm_client_id(self
);
759 client_update_strut(self
);
760 client_update_icons(self
);
763 static void client_get_startup_id(ObClient
*self
)
765 if (!(PROP_GETS(self
->window
, net_startup_id
, utf8
, &self
->startup_id
)))
767 PROP_GETS(self
->group
->leader
,
768 net_startup_id
, utf8
, &self
->startup_id
);
771 static void client_get_area(ObClient
*self
)
773 XWindowAttributes wattrib
;
776 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
777 g_assert(ret
!= BadWindow
);
779 RECT_SET(self
->area
, wattrib
.x
, wattrib
.y
, wattrib
.width
, wattrib
.height
);
780 self
->border_width
= wattrib
.border_width
;
783 static void client_get_desktop(ObClient
*self
)
785 guint32 d
= screen_num_desktops
; /* an always-invalid value */
787 if (PROP_GET32(self
->window
, net_wm_desktop
, cardinal
, &d
)) {
788 if (d
>= screen_num_desktops
&& d
!= DESKTOP_ALL
)
789 self
->desktop
= screen_num_desktops
- 1;
793 gboolean trdesk
= FALSE
;
795 if (self
->transient_for
) {
796 if (self
->transient_for
!= OB_TRAN_GROUP
) {
797 self
->desktop
= self
->transient_for
->desktop
;
802 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
))
803 if (it
->data
!= self
&&
804 !((ObClient
*)it
->data
)->transient_for
) {
805 self
->desktop
= ((ObClient
*)it
->data
)->desktop
;
812 /* try get from the startup-notification protocol */
813 if (sn_get_desktop(self
->startup_id
, &self
->desktop
)) {
814 if (self
->desktop
>= screen_num_desktops
&&
815 self
->desktop
!= DESKTOP_ALL
)
816 self
->desktop
= screen_num_desktops
- 1;
818 /* defaults to the current desktop */
819 self
->desktop
= screen_desktop
;
822 if (self
->desktop
!= d
) {
823 /* set the desktop hint, to make sure that it always exists */
824 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, self
->desktop
);
828 static void client_get_state(ObClient
*self
)
833 if (PROP_GETA32(self
->window
, net_wm_state
, atom
, &state
, &num
)) {
835 for (i
= 0; i
< num
; ++i
) {
836 if (state
[i
] == prop_atoms
.net_wm_state_modal
)
838 else if (state
[i
] == prop_atoms
.net_wm_state_shaded
)
840 else if (state
[i
] == prop_atoms
.net_wm_state_hidden
)
842 else if (state
[i
] == prop_atoms
.net_wm_state_skip_taskbar
)
843 self
->skip_taskbar
= TRUE
;
844 else if (state
[i
] == prop_atoms
.net_wm_state_skip_pager
)
845 self
->skip_pager
= TRUE
;
846 else if (state
[i
] == prop_atoms
.net_wm_state_fullscreen
)
847 self
->fullscreen
= TRUE
;
848 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_vert
)
849 self
->max_vert
= TRUE
;
850 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_horz
)
851 self
->max_horz
= TRUE
;
852 else if (state
[i
] == prop_atoms
.net_wm_state_above
)
854 else if (state
[i
] == prop_atoms
.net_wm_state_below
)
856 else if (state
[i
] == prop_atoms
.ob_wm_state_undecorated
)
857 self
->undecorated
= TRUE
;
863 if (!(self
->above
|| self
->below
)) {
865 /* apply stuff from the group */
869 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
870 ObClient
*c
= it
->data
;
871 if (c
!= self
&& !client_search_transient(self
, c
) &&
872 client_normal(self
) && client_normal(c
))
875 (c
->above
? 1 : (c
->below
? -1 : 0)));
889 g_assert_not_reached();
896 static void client_get_shaped(ObClient
*self
)
898 self
->shaped
= FALSE
;
900 if (extensions_shape
) {
905 XShapeSelectInput(ob_display
, self
->window
, ShapeNotifyMask
);
907 XShapeQueryExtents(ob_display
, self
->window
, &s
, &foo
,
908 &foo
, &ufoo
, &ufoo
, &foo
, &foo
, &foo
, &ufoo
,
910 self
->shaped
= (s
!= 0);
915 void client_update_transient_for(ObClient
*self
)
918 ObClient
*target
= NULL
;
920 if (XGetTransientForHint(ob_display
, self
->window
, &t
)) {
921 self
->transient
= TRUE
;
922 if (t
!= self
->window
) { /* cant be transient to itself! */
923 target
= g_hash_table_lookup(window_map
, &t
);
924 /* if this happens then we need to check for it*/
925 g_assert(target
!= self
);
926 if (target
&& !WINDOW_IS_CLIENT(target
)) {
927 /* this can happen when a dialog is a child of
928 a dockapp, for example */
932 if (!target
&& self
->group
) {
933 /* not transient to a client, see if it is transient for a
935 if (t
== self
->group
->leader
||
937 t
== RootWindow(ob_display
, ob_screen
))
939 /* window is a transient for its group! */
940 target
= OB_TRAN_GROUP
;
944 } else if (self
->type
== OB_CLIENT_TYPE_DIALOG
&& self
->group
) {
945 self
->transient
= TRUE
;
946 target
= OB_TRAN_GROUP
;
948 self
->transient
= FALSE
;
950 /* if anything has changed... */
951 if (target
!= self
->transient_for
) {
952 if (self
->transient_for
== OB_TRAN_GROUP
) { /* transient of group */
955 /* remove from old parents */
956 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
957 ObClient
*c
= it
->data
;
958 if (c
!= self
&& !c
->transient_for
)
959 c
->transients
= g_slist_remove(c
->transients
, self
);
961 } else if (self
->transient_for
!= NULL
) { /* transient of window */
962 /* remove from old parent */
963 self
->transient_for
->transients
=
964 g_slist_remove(self
->transient_for
->transients
, self
);
966 self
->transient_for
= target
;
967 if (self
->transient_for
== OB_TRAN_GROUP
) { /* transient of group */
970 /* add to new parents */
971 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
972 ObClient
*c
= it
->data
;
973 if (c
!= self
&& !c
->transient_for
)
974 c
->transients
= g_slist_append(c
->transients
, self
);
977 /* remove all transients which are in the group, that causes
978 circlular pointer hell of doom */
979 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
981 for (sit
= self
->transients
; sit
; sit
= next
) {
982 next
= g_slist_next(sit
);
983 if (sit
->data
== it
->data
)
985 g_slist_delete_link(self
->transients
, sit
);
988 } else if (self
->transient_for
!= NULL
) { /* transient of window */
989 /* add to new parent */
990 self
->transient_for
->transients
=
991 g_slist_append(self
->transient_for
->transients
, self
);
996 static void client_get_mwm_hints(ObClient
*self
)
1001 self
->mwmhints
.flags
= 0; /* default to none */
1003 if (PROP_GETA32(self
->window
, motif_wm_hints
, motif_wm_hints
,
1005 if (num
>= OB_MWM_ELEMENTS
) {
1006 self
->mwmhints
.flags
= hints
[0];
1007 self
->mwmhints
.functions
= hints
[1];
1008 self
->mwmhints
.decorations
= hints
[2];
1014 void client_get_type(ObClient
*self
)
1021 if (PROP_GETA32(self
->window
, net_wm_window_type
, atom
, &val
, &num
)) {
1022 /* use the first value that we know about in the array */
1023 for (i
= 0; i
< num
; ++i
) {
1024 if (val
[i
] == prop_atoms
.net_wm_window_type_desktop
)
1025 self
->type
= OB_CLIENT_TYPE_DESKTOP
;
1026 else if (val
[i
] == prop_atoms
.net_wm_window_type_dock
)
1027 self
->type
= OB_CLIENT_TYPE_DOCK
;
1028 else if (val
[i
] == prop_atoms
.net_wm_window_type_toolbar
)
1029 self
->type
= OB_CLIENT_TYPE_TOOLBAR
;
1030 else if (val
[i
] == prop_atoms
.net_wm_window_type_menu
)
1031 self
->type
= OB_CLIENT_TYPE_MENU
;
1032 else if (val
[i
] == prop_atoms
.net_wm_window_type_utility
)
1033 self
->type
= OB_CLIENT_TYPE_UTILITY
;
1034 else if (val
[i
] == prop_atoms
.net_wm_window_type_splash
)
1035 self
->type
= OB_CLIENT_TYPE_SPLASH
;
1036 else if (val
[i
] == prop_atoms
.net_wm_window_type_dialog
)
1037 self
->type
= OB_CLIENT_TYPE_DIALOG
;
1038 else if (val
[i
] == prop_atoms
.net_wm_window_type_normal
)
1039 self
->type
= OB_CLIENT_TYPE_NORMAL
;
1040 else if (val
[i
] == prop_atoms
.kde_net_wm_window_type_override
) {
1041 /* prevent this window from getting any decor or
1043 self
->mwmhints
.flags
&= (OB_MWM_FLAG_FUNCTIONS
|
1044 OB_MWM_FLAG_DECORATIONS
);
1045 self
->mwmhints
.decorations
= 0;
1046 self
->mwmhints
.functions
= 0;
1048 if (self
->type
!= (ObClientType
) -1)
1049 break; /* grab the first legit type */
1054 if (self
->type
== (ObClientType
) -1) {
1055 /*the window type hint was not set, which means we either classify
1056 ourself as a normal window or a dialog, depending on if we are a
1058 if (self
->transient
)
1059 self
->type
= OB_CLIENT_TYPE_DIALOG
;
1061 self
->type
= OB_CLIENT_TYPE_NORMAL
;
1065 void client_update_protocols(ObClient
*self
)
1068 guint num_return
, i
;
1070 self
->focus_notify
= FALSE
;
1071 self
->delete_window
= FALSE
;
1073 if (PROP_GETA32(self
->window
, wm_protocols
, atom
, &proto
, &num_return
)) {
1074 for (i
= 0; i
< num_return
; ++i
) {
1075 if (proto
[i
] == prop_atoms
.wm_delete_window
) {
1076 /* this means we can request the window to close */
1077 self
->delete_window
= TRUE
;
1078 } else if (proto
[i
] == prop_atoms
.wm_take_focus
)
1079 /* if this protocol is requested, then the window will be
1080 notified whenever we want it to receive focus */
1081 self
->focus_notify
= TRUE
;
1087 static void client_get_gravity(ObClient
*self
)
1089 XWindowAttributes wattrib
;
1092 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
1093 g_assert(ret
!= BadWindow
);
1094 self
->gravity
= wattrib
.win_gravity
;
1097 void client_update_normal_hints(ObClient
*self
)
1101 gint oldgravity
= self
->gravity
;
1104 self
->min_ratio
= 0.0f
;
1105 self
->max_ratio
= 0.0f
;
1106 SIZE_SET(self
->size_inc
, 1, 1);
1107 SIZE_SET(self
->base_size
, 0, 0);
1108 SIZE_SET(self
->min_size
, 0, 0);
1109 SIZE_SET(self
->max_size
, G_MAXINT
, G_MAXINT
);
1111 /* get the hints from the window */
1112 if (XGetWMNormalHints(ob_display
, self
->window
, &size
, &ret
)) {
1113 /* normal windows can't request placement! har har
1114 if (!client_normal(self))
1116 self
->positioned
= !!(size
.flags
& (PPosition
|USPosition
));
1118 if (size
.flags
& PWinGravity
) {
1119 self
->gravity
= size
.win_gravity
;
1121 /* if the client has a frame, i.e. has already been mapped and
1122 is changing its gravity */
1123 if (self
->frame
&& self
->gravity
!= oldgravity
) {
1124 /* move our idea of the client's position based on its new
1126 self
->area
.x
= self
->frame
->area
.x
;
1127 self
->area
.y
= self
->frame
->area
.y
;
1128 frame_frame_gravity(self
->frame
, &self
->area
.x
, &self
->area
.y
);
1132 if (size
.flags
& PAspect
) {
1133 if (size
.min_aspect
.y
)
1135 (gfloat
) size
.min_aspect
.x
/ size
.min_aspect
.y
;
1136 if (size
.max_aspect
.y
)
1138 (gfloat
) size
.max_aspect
.x
/ size
.max_aspect
.y
;
1141 if (size
.flags
& PMinSize
)
1142 SIZE_SET(self
->min_size
, size
.min_width
, size
.min_height
);
1144 if (size
.flags
& PMaxSize
)
1145 SIZE_SET(self
->max_size
, size
.max_width
, size
.max_height
);
1147 if (size
.flags
& PBaseSize
)
1148 SIZE_SET(self
->base_size
, size
.base_width
, size
.base_height
);
1150 if (size
.flags
& PResizeInc
)
1151 SIZE_SET(self
->size_inc
, size
.width_inc
, size
.height_inc
);
1155 void client_setup_decor_and_functions(ObClient
*self
)
1157 /* start with everything (cept fullscreen) */
1159 (OB_FRAME_DECOR_TITLEBAR
|
1160 (ob_rr_theme
->show_handle
? OB_FRAME_DECOR_HANDLE
: 0) |
1161 OB_FRAME_DECOR_GRIPS
|
1162 OB_FRAME_DECOR_BORDER
|
1163 OB_FRAME_DECOR_ICON
|
1164 OB_FRAME_DECOR_ALLDESKTOPS
|
1165 OB_FRAME_DECOR_ICONIFY
|
1166 OB_FRAME_DECOR_MAXIMIZE
|
1167 OB_FRAME_DECOR_SHADE
|
1168 OB_FRAME_DECOR_CLOSE
);
1170 (OB_CLIENT_FUNC_RESIZE
|
1171 OB_CLIENT_FUNC_MOVE
|
1172 OB_CLIENT_FUNC_ICONIFY
|
1173 OB_CLIENT_FUNC_MAXIMIZE
|
1174 OB_CLIENT_FUNC_SHADE
|
1175 OB_CLIENT_FUNC_CLOSE
);
1177 if (!(self
->min_size
.width
< self
->max_size
.width
||
1178 self
->min_size
.height
< self
->max_size
.height
))
1179 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
1181 switch (self
->type
) {
1182 case OB_CLIENT_TYPE_NORMAL
:
1183 /* normal windows retain all of the possible decorations and
1184 functionality, and are the only windows that you can fullscreen */
1185 self
->functions
|= OB_CLIENT_FUNC_FULLSCREEN
;
1188 case OB_CLIENT_TYPE_DIALOG
:
1189 case OB_CLIENT_TYPE_UTILITY
:
1190 /* these windows cannot be maximized */
1191 self
->functions
&= ~OB_CLIENT_FUNC_MAXIMIZE
;
1194 case OB_CLIENT_TYPE_MENU
:
1195 case OB_CLIENT_TYPE_TOOLBAR
:
1196 /* these windows get less functionality */
1197 self
->functions
&= ~(OB_CLIENT_FUNC_ICONIFY
| OB_CLIENT_FUNC_RESIZE
);
1200 case OB_CLIENT_TYPE_DESKTOP
:
1201 case OB_CLIENT_TYPE_DOCK
:
1202 case OB_CLIENT_TYPE_SPLASH
:
1203 /* none of these windows are manipulated by the window manager */
1204 self
->decorations
= 0;
1205 self
->functions
= 0;
1209 /* Mwm Hints are applied subtractively to what has already been chosen for
1210 decor and functionality */
1211 if (self
->mwmhints
.flags
& OB_MWM_FLAG_DECORATIONS
) {
1212 if (! (self
->mwmhints
.decorations
& OB_MWM_DECOR_ALL
)) {
1213 if (! ((self
->mwmhints
.decorations
& OB_MWM_DECOR_HANDLE
) ||
1214 (self
->mwmhints
.decorations
& OB_MWM_DECOR_TITLE
)))
1215 /* if the mwm hints request no handle or title, then all
1216 decorations are disabled */
1217 self
->decorations
= 0;
1221 if (self
->mwmhints
.flags
& OB_MWM_FLAG_FUNCTIONS
) {
1222 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_ALL
)) {
1223 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_RESIZE
))
1224 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
1225 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_MOVE
))
1226 self
->functions
&= ~OB_CLIENT_FUNC_MOVE
;
1227 /* dont let mwm hints kill any buttons
1228 if (! (self->mwmhints.functions & OB_MWM_FUNC_ICONIFY))
1229 self->functions &= ~OB_CLIENT_FUNC_ICONIFY;
1230 if (! (self->mwmhints.functions & OB_MWM_FUNC_MAXIMIZE))
1231 self->functions &= ~OB_CLIENT_FUNC_MAXIMIZE;
1233 /* dont let mwm hints kill the close button
1234 if (! (self->mwmhints.functions & MwmFunc_Close))
1235 self->functions &= ~OB_CLIENT_FUNC_CLOSE; */
1239 if (!(self
->functions
& OB_CLIENT_FUNC_SHADE
))
1240 self
->decorations
&= ~OB_FRAME_DECOR_SHADE
;
1241 if (!(self
->functions
& OB_CLIENT_FUNC_ICONIFY
))
1242 self
->decorations
&= ~OB_FRAME_DECOR_ICONIFY
;
1243 if (!(self
->functions
& OB_CLIENT_FUNC_RESIZE
))
1244 self
->decorations
&= ~OB_FRAME_DECOR_GRIPS
;
1246 /* can't maximize without moving/resizing */
1247 if (!((self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) &&
1248 (self
->functions
& OB_CLIENT_FUNC_MOVE
) &&
1249 (self
->functions
& OB_CLIENT_FUNC_RESIZE
))) {
1250 self
->functions
&= ~OB_CLIENT_FUNC_MAXIMIZE
;
1251 self
->decorations
&= ~OB_FRAME_DECOR_MAXIMIZE
;
1254 /* kill the handle on fully maxed windows */
1255 if (self
->max_vert
&& self
->max_horz
)
1256 self
->decorations
&= ~OB_FRAME_DECOR_HANDLE
;
1258 /* finally, the user can have requested no decorations, which overrides
1259 everything (but doesnt give it a border if it doesnt have one) */
1260 if (self
->undecorated
) {
1261 if (config_theme_keepborder
)
1262 self
->decorations
&= OB_FRAME_DECOR_BORDER
;
1264 self
->decorations
= 0;
1267 /* if we don't have a titlebar, then we cannot shade! */
1268 if (!(self
->decorations
& OB_FRAME_DECOR_TITLEBAR
))
1269 self
->functions
&= ~OB_CLIENT_FUNC_SHADE
;
1271 /* now we need to check against rules for the client's current state */
1272 if (self
->fullscreen
) {
1273 self
->functions
&= (OB_CLIENT_FUNC_CLOSE
|
1274 OB_CLIENT_FUNC_FULLSCREEN
|
1275 OB_CLIENT_FUNC_ICONIFY
);
1276 self
->decorations
= 0;
1279 client_change_allowed_actions(self
);
1282 /* adjust the client's decorations, etc. */
1283 client_reconfigure(self
);
1287 static void client_change_allowed_actions(ObClient
*self
)
1292 /* desktop windows are kept on all desktops */
1293 if (self
->type
!= OB_CLIENT_TYPE_DESKTOP
)
1294 actions
[num
++] = prop_atoms
.net_wm_action_change_desktop
;
1296 if (self
->functions
& OB_CLIENT_FUNC_SHADE
)
1297 actions
[num
++] = prop_atoms
.net_wm_action_shade
;
1298 if (self
->functions
& OB_CLIENT_FUNC_CLOSE
)
1299 actions
[num
++] = prop_atoms
.net_wm_action_close
;
1300 if (self
->functions
& OB_CLIENT_FUNC_MOVE
)
1301 actions
[num
++] = prop_atoms
.net_wm_action_move
;
1302 if (self
->functions
& OB_CLIENT_FUNC_ICONIFY
)
1303 actions
[num
++] = prop_atoms
.net_wm_action_minimize
;
1304 if (self
->functions
& OB_CLIENT_FUNC_RESIZE
)
1305 actions
[num
++] = prop_atoms
.net_wm_action_resize
;
1306 if (self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
)
1307 actions
[num
++] = prop_atoms
.net_wm_action_fullscreen
;
1308 if (self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) {
1309 actions
[num
++] = prop_atoms
.net_wm_action_maximize_horz
;
1310 actions
[num
++] = prop_atoms
.net_wm_action_maximize_vert
;
1313 PROP_SETA32(self
->window
, net_wm_allowed_actions
, atom
, actions
, num
);
1315 /* make sure the window isn't breaking any rules now */
1317 if (!(self
->functions
& OB_CLIENT_FUNC_SHADE
) && self
->shaded
) {
1318 if (self
->frame
) client_shade(self
, FALSE
);
1319 else self
->shaded
= FALSE
;
1321 if (!(self
->functions
& OB_CLIENT_FUNC_ICONIFY
) && self
->iconic
) {
1322 if (self
->frame
) client_iconify(self
, FALSE
, TRUE
);
1323 else self
->iconic
= FALSE
;
1325 if (!(self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
) && self
->fullscreen
) {
1326 if (self
->frame
) client_fullscreen(self
, FALSE
, TRUE
);
1327 else self
->fullscreen
= FALSE
;
1329 if (!(self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) && (self
->max_horz
||
1331 if (self
->frame
) client_maximize(self
, FALSE
, 0, TRUE
);
1332 else self
->max_vert
= self
->max_horz
= FALSE
;
1336 void client_reconfigure(ObClient
*self
)
1338 /* by making this pass FALSE for user, we avoid the emacs event storm where
1339 every configurenotify causes an update in its normal hints, i think this
1340 is generally what we want anyways... */
1341 client_configure(self
, OB_CORNER_TOPLEFT
, self
->area
.x
, self
->area
.y
,
1342 self
->area
.width
, self
->area
.height
, FALSE
, TRUE
);
1345 void client_update_wmhints(ObClient
*self
)
1348 gboolean ur
= FALSE
;
1351 /* assume a window takes input if it doesnt specify */
1352 self
->can_focus
= TRUE
;
1354 if ((hints
= XGetWMHints(ob_display
, self
->window
)) != NULL
) {
1355 if (hints
->flags
& InputHint
)
1356 self
->can_focus
= hints
->input
;
1358 /* only do this when first managing the window *AND* when we aren't
1360 if (ob_state() != OB_STATE_STARTING
&& self
->frame
== NULL
)
1361 if (hints
->flags
& StateHint
)
1362 self
->iconic
= hints
->initial_state
== IconicState
;
1364 if (hints
->flags
& XUrgencyHint
)
1367 if (!(hints
->flags
& WindowGroupHint
))
1368 hints
->window_group
= None
;
1370 /* did the group state change? */
1371 if (hints
->window_group
!=
1372 (self
->group
? self
->group
->leader
: None
)) {
1373 /* remove from the old group if there was one */
1374 if (self
->group
!= NULL
) {
1375 /* remove transients of the group */
1376 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
))
1377 self
->transients
= g_slist_remove(self
->transients
,
1380 /* remove myself from parents in the group */
1381 if (self
->transient_for
== OB_TRAN_GROUP
) {
1382 for (it
= self
->group
->members
; it
;
1383 it
= g_slist_next(it
))
1385 ObClient
*c
= it
->data
;
1387 if (c
!= self
&& !c
->transient_for
)
1388 c
->transients
= g_slist_remove(c
->transients
,
1393 group_remove(self
->group
, self
);
1396 if (hints
->window_group
!= None
) {
1397 self
->group
= group_add(hints
->window_group
, self
);
1399 /* i can only have transients from the group if i am not
1401 if (!self
->transient_for
) {
1402 /* add other transients of the group that are already
1404 for (it
= self
->group
->members
; it
;
1405 it
= g_slist_next(it
))
1407 ObClient
*c
= it
->data
;
1408 if (c
!= self
&& c
->transient_for
== OB_TRAN_GROUP
)
1410 g_slist_append(self
->transients
, c
);
1415 /* because the self->transient flag wont change from this call,
1416 we don't need to update the window's type and such, only its
1417 transient_for, and the transients lists of other windows in
1418 the group may be affected */
1419 client_update_transient_for(self
);
1422 /* the WM_HINTS can contain an icon */
1423 client_update_icons(self
);
1428 if (ur
!= self
->urgent
) {
1430 /* fire the urgent callback if we're mapped, otherwise, wait until
1431 after we're mapped */
1433 client_urgent_notify(self
);
1437 void client_update_title(ObClient
*self
)
1443 gboolean read_title
;
1446 old_title
= self
->title
;
1449 if (!PROP_GETS(self
->window
, net_wm_name
, utf8
, &data
))
1450 /* try old x stuff */
1451 if (!PROP_GETS(self
->window
, wm_name
, locale
, &data
))
1452 // http://developer.gnome.org/projects/gup/hig/draft_hig_new/windows-alert.html
1453 if (self
->transient
)
1454 data
= g_strdup("");
1456 data
= g_strdup("Unnamed Window");
1458 /* did the title change? then reset the title_count */
1459 if (old_title
&& 0 != strncmp(old_title
, data
, strlen(data
)))
1460 self
->title_count
= 1;
1462 /* look for duplicates and append a number */
1464 for (it
= client_list
; it
; it
= g_list_next(it
))
1465 if (it
->data
!= self
) {
1466 ObClient
*c
= it
->data
;
1467 if (0 == strncmp(c
->title
, data
, strlen(data
)))
1468 nums
|= 1 << c
->title_count
;
1470 /* find first free number */
1471 for (i
= 1; i
<= 32; ++i
)
1472 if (!(nums
& (1 << i
))) {
1473 if (self
->title_count
== 1 || i
== 1)
1474 self
->title_count
= i
;
1477 /* dont display the number for the first window */
1478 if (self
->title_count
> 1) {
1480 ndata
= g_strdup_printf("%s - [%u]", data
, self
->title_count
);
1485 PROP_SETS(self
->window
, net_wm_visible_name
, data
);
1490 frame_adjust_title(self
->frame
);
1494 /* update the icon title */
1496 g_free(self
->icon_title
);
1500 if (!PROP_GETS(self
->window
, net_wm_icon_name
, utf8
, &data
))
1501 /* try old x stuff */
1502 if (!PROP_GETS(self
->window
, wm_icon_name
, locale
, &data
)) {
1503 data
= g_strdup(self
->title
);
1507 /* append the title count, dont display the number for the first window */
1508 if (read_title
&& self
->title_count
> 1) {
1509 gchar
*vdata
, *ndata
;
1510 ndata
= g_strdup_printf(" - [%u]", self
->title_count
);
1511 vdata
= g_strconcat(data
, ndata
, NULL
);
1517 PROP_SETS(self
->window
, net_wm_visible_icon_name
, data
);
1519 self
->icon_title
= data
;
1522 void client_update_class(ObClient
*self
)
1527 if (self
->name
) g_free(self
->name
);
1528 if (self
->class) g_free(self
->class);
1529 if (self
->role
) g_free(self
->role
);
1531 self
->name
= self
->class = self
->role
= NULL
;
1533 if (PROP_GETSS(self
->window
, wm_class
, locale
, &data
)) {
1535 self
->name
= g_strdup(data
[0]);
1537 self
->class = g_strdup(data
[1]);
1542 if (PROP_GETS(self
->window
, wm_window_role
, locale
, &s
))
1545 if (self
->name
== NULL
) self
->name
= g_strdup("");
1546 if (self
->class == NULL
) self
->class = g_strdup("");
1547 if (self
->role
== NULL
) self
->role
= g_strdup("");
1550 void client_update_strut(ObClient
*self
)
1554 gboolean got
= FALSE
;
1557 if (PROP_GETA32(self
->window
, net_wm_strut_partial
, cardinal
,
1561 STRUT_PARTIAL_SET(strut
,
1562 data
[0], data
[2], data
[1], data
[3],
1563 data
[4], data
[5], data
[8], data
[9],
1564 data
[6], data
[7], data
[10], data
[11]);
1570 PROP_GETA32(self
->window
, net_wm_strut
, cardinal
, &data
, &num
)) {
1576 /* use the screen's width/height */
1577 a
= screen_physical_area();
1579 STRUT_PARTIAL_SET(strut
,
1580 data
[0], data
[2], data
[1], data
[3],
1581 a
->y
, a
->y
+ a
->height
- 1,
1582 a
->x
, a
->x
+ a
->width
- 1,
1583 a
->y
, a
->y
+ a
->height
- 1,
1584 a
->x
, a
->x
+ a
->width
- 1);
1590 STRUT_PARTIAL_SET(strut
, 0, 0, 0, 0,
1591 0, 0, 0, 0, 0, 0, 0, 0);
1593 if (!STRUT_EQUAL(strut
, self
->strut
)) {
1594 self
->strut
= strut
;
1596 /* updating here is pointless while we're being mapped cuz we're not in
1597 the client list yet */
1599 screen_update_areas();
1603 void client_update_icons(ObClient
*self
)
1609 for (i
= 0; i
< self
->nicons
; ++i
)
1610 g_free(self
->icons
[i
].data
);
1611 if (self
->nicons
> 0)
1612 g_free(self
->icons
);
1615 if (PROP_GETA32(self
->window
, net_wm_icon
, cardinal
, &data
, &num
)) {
1616 /* figure out how many valid icons are in here */
1618 while (num
- i
> 2) {
1622 if (i
> num
|| w
*h
== 0) break;
1626 self
->icons
= g_new(ObClientIcon
, self
->nicons
);
1628 /* store the icons */
1630 for (j
= 0; j
< self
->nicons
; ++j
) {
1633 w
= self
->icons
[j
].width
= data
[i
++];
1634 h
= self
->icons
[j
].height
= data
[i
++];
1636 if (w
*h
== 0) continue;
1638 self
->icons
[j
].data
= g_new(RrPixel32
, w
* h
);
1639 for (x
= 0, y
= 0, t
= 0; t
< w
* h
; ++t
, ++x
, ++i
) {
1644 self
->icons
[j
].data
[t
] =
1645 (((data
[i
] >> 24) & 0xff) << RrDefaultAlphaOffset
) +
1646 (((data
[i
] >> 16) & 0xff) << RrDefaultRedOffset
) +
1647 (((data
[i
] >> 8) & 0xff) << RrDefaultGreenOffset
) +
1648 (((data
[i
] >> 0) & 0xff) << RrDefaultBlueOffset
);
1654 } else if (PROP_GETA32(self
->window
, kwm_win_icon
,
1655 kwm_win_icon
, &data
, &num
)) {
1658 self
->icons
= g_new(ObClientIcon
, self
->nicons
);
1659 xerror_set_ignore(TRUE
);
1660 if (!RrPixmapToRGBA(ob_rr_inst
,
1662 &self
->icons
[self
->nicons
-1].width
,
1663 &self
->icons
[self
->nicons
-1].height
,
1664 &self
->icons
[self
->nicons
-1].data
)) {
1665 g_free(&self
->icons
[self
->nicons
-1]);
1668 xerror_set_ignore(FALSE
);
1674 if ((hints
= XGetWMHints(ob_display
, self
->window
))) {
1675 if (hints
->flags
& IconPixmapHint
) {
1677 self
->icons
= g_new(ObClientIcon
, self
->nicons
);
1678 xerror_set_ignore(TRUE
);
1679 if (!RrPixmapToRGBA(ob_rr_inst
,
1681 (hints
->flags
& IconMaskHint
?
1682 hints
->icon_mask
: None
),
1683 &self
->icons
[self
->nicons
-1].width
,
1684 &self
->icons
[self
->nicons
-1].height
,
1685 &self
->icons
[self
->nicons
-1].data
)){
1686 g_free(&self
->icons
[self
->nicons
-1]);
1689 xerror_set_ignore(FALSE
);
1696 frame_adjust_icon(self
->frame
);
1699 static void client_change_state(ObClient
*self
)
1702 guint32 netstate
[11];
1705 state
[0] = self
->wmstate
;
1707 PROP_SETA32(self
->window
, wm_state
, wm_state
, state
, 2);
1711 netstate
[num
++] = prop_atoms
.net_wm_state_modal
;
1713 netstate
[num
++] = prop_atoms
.net_wm_state_shaded
;
1715 netstate
[num
++] = prop_atoms
.net_wm_state_hidden
;
1716 if (self
->skip_taskbar
)
1717 netstate
[num
++] = prop_atoms
.net_wm_state_skip_taskbar
;
1718 if (self
->skip_pager
)
1719 netstate
[num
++] = prop_atoms
.net_wm_state_skip_pager
;
1720 if (self
->fullscreen
)
1721 netstate
[num
++] = prop_atoms
.net_wm_state_fullscreen
;
1723 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_vert
;
1725 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_horz
;
1727 netstate
[num
++] = prop_atoms
.net_wm_state_above
;
1729 netstate
[num
++] = prop_atoms
.net_wm_state_below
;
1730 if (self
->undecorated
)
1731 netstate
[num
++] = prop_atoms
.ob_wm_state_undecorated
;
1732 PROP_SETA32(self
->window
, net_wm_state
, atom
, netstate
, num
);
1734 client_calc_layer(self
);
1737 frame_adjust_state(self
->frame
);
1740 ObClient
*client_search_focus_tree(ObClient
*self
)
1745 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
1746 if (client_focused(it
->data
)) return it
->data
;
1747 if ((ret
= client_search_focus_tree(it
->data
))) return ret
;
1752 ObClient
*client_search_focus_tree_full(ObClient
*self
)
1754 if (self
->transient_for
) {
1755 if (self
->transient_for
!= OB_TRAN_GROUP
) {
1756 return client_search_focus_tree_full(self
->transient_for
);
1759 gboolean recursed
= FALSE
;
1761 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
))
1762 if (!((ObClient
*)it
->data
)->transient_for
) {
1764 if ((c
= client_search_focus_tree_full(it
->data
)))
1773 /* this function checks the whole tree, the client_search_focus_tree~
1774 does not, so we need to check this window */
1775 if (client_focused(self
))
1777 return client_search_focus_tree(self
);
1780 static ObStackingLayer
calc_layer(ObClient
*self
)
1784 if (self
->fullscreen
&&
1785 (client_focused(self
) || client_search_focus_tree(self
)))
1786 l
= OB_STACKING_LAYER_FULLSCREEN
;
1787 else if (self
->type
== OB_CLIENT_TYPE_DESKTOP
)
1788 l
= OB_STACKING_LAYER_DESKTOP
;
1789 else if (self
->type
== OB_CLIENT_TYPE_DOCK
) {
1790 if (self
->above
) l
= OB_STACKING_LAYER_DOCK_ABOVE
;
1791 else if (self
->below
) l
= OB_STACKING_LAYER_DOCK_BELOW
;
1792 else l
= OB_STACKING_LAYER_DOCK_NORMAL
;
1794 else if (self
->above
) l
= OB_STACKING_LAYER_ABOVE
;
1795 else if (self
->below
) l
= OB_STACKING_LAYER_BELOW
;
1796 else l
= OB_STACKING_LAYER_NORMAL
;
1801 static void client_calc_layer_recursive(ObClient
*self
, ObClient
*orig
,
1802 ObStackingLayer l
, gboolean raised
)
1804 ObStackingLayer old
, own
;
1808 own
= calc_layer(self
);
1809 self
->layer
= l
> own
? l
: own
;
1811 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
1812 client_calc_layer_recursive(it
->data
, orig
,
1813 l
, raised
? raised
: l
!= old
);
1815 if (!raised
&& l
!= old
)
1816 if (orig
->frame
) { /* only restack if the original window is managed */
1817 stacking_remove(CLIENT_AS_WINDOW(self
));
1818 stacking_add(CLIENT_AS_WINDOW(self
));
1822 void client_calc_layer(ObClient
*self
)
1829 /* transients take on the layer of their parents */
1830 self
= client_search_top_transient(self
);
1832 l
= calc_layer(self
);
1834 client_calc_layer_recursive(self
, orig
, l
, FALSE
);
1837 gboolean
client_should_show(ObClient
*self
)
1841 if (client_normal(self
) && screen_showing_desktop
)
1844 if (self->transient_for) {
1845 if (self->transient_for != OB_TRAN_GROUP)
1846 return client_should_show(self->transient_for);
1850 for (it = self->group->members; it; it = g_slist_next(it)) {
1851 ObClient *c = it->data;
1852 if (c != self && !c->transient_for) {
1853 if (client_should_show(c))
1860 if (self
->desktop
== screen_desktop
|| self
->desktop
== DESKTOP_ALL
)
1866 static void client_showhide(ObClient
*self
)
1869 if (client_should_show(self
))
1870 frame_show(self
->frame
);
1872 frame_hide(self
->frame
);
1875 gboolean
client_normal(ObClient
*self
) {
1876 return ! (self
->type
== OB_CLIENT_TYPE_DESKTOP
||
1877 self
->type
== OB_CLIENT_TYPE_DOCK
||
1878 self
->type
== OB_CLIENT_TYPE_SPLASH
);
1881 static void client_apply_startup_state(ObClient
*self
)
1883 /* these are in a carefully crafted order.. */
1886 self
->iconic
= FALSE
;
1887 client_iconify(self
, TRUE
, FALSE
);
1889 if (self
->fullscreen
) {
1890 self
->fullscreen
= FALSE
;
1891 client_fullscreen(self
, TRUE
, FALSE
);
1893 if (self
->undecorated
) {
1894 self
->undecorated
= FALSE
;
1895 client_set_undecorated(self
, TRUE
);
1898 self
->shaded
= FALSE
;
1899 client_shade(self
, TRUE
);
1902 client_urgent_notify(self
);
1904 if (self
->max_vert
&& self
->max_horz
) {
1905 self
->max_vert
= self
->max_horz
= FALSE
;
1906 client_maximize(self
, TRUE
, 0, FALSE
);
1907 } else if (self
->max_vert
) {
1908 self
->max_vert
= FALSE
;
1909 client_maximize(self
, TRUE
, 2, FALSE
);
1910 } else if (self
->max_horz
) {
1911 self
->max_horz
= FALSE
;
1912 client_maximize(self
, TRUE
, 1, FALSE
);
1915 /* nothing to do for the other states:
1924 void client_configure_full(ObClient
*self
, ObCorner anchor
,
1925 gint x
, gint y
, gint w
, gint h
,
1926 gboolean user
, gboolean final
,
1927 gboolean force_reply
)
1930 gboolean send_resize_client
;
1931 gboolean moved
= FALSE
, resized
= FALSE
;
1932 guint fdecor
= self
->frame
->decorations
;
1933 gboolean fhorz
= self
->frame
->max_horz
;
1935 /* make the frame recalculate its dimentions n shit without changing
1936 anything visible for real, this way the constraints below can work with
1937 the updated frame dimensions. */
1938 frame_adjust_area(self
->frame
, TRUE
, TRUE
, TRUE
);
1940 /* gets the frame's position */
1941 frame_client_gravity(self
->frame
, &x
, &y
);
1943 /* these positions are frame positions, not client positions */
1945 /* set the size and position if fullscreen */
1946 if (self
->fullscreen
) {
1949 XF86VidModeModeLine mode
;
1954 i
= client_monitor(self
);
1955 a
= screen_physical_area_monitor(i
);
1958 if (i
== 0 && /* primary head */
1959 extensions_vidmode
&&
1960 XF86VidModeGetViewPort(ob_display
, ob_screen
, &x
, &y
) &&
1961 /* get the mode last so the mode.privsize isnt freed incorrectly */
1962 XF86VidModeGetModeLine(ob_display
, ob_screen
, &dot
, &mode
)) {
1967 if (mode
.privsize
) XFree(mode
.private);
1977 user
= FALSE
; /* ignore that increment etc shit when in fullscreen */
1981 a
= screen_area_monitor(self
->desktop
, client_monitor(self
));
1983 /* set the size and position if maximized */
1984 if (self
->max_horz
) {
1986 w
= a
->width
- self
->frame
->size
.left
- self
->frame
->size
.right
;
1988 if (self
->max_vert
) {
1990 h
= a
->height
- self
->frame
->size
.top
- self
->frame
->size
.bottom
;
1994 /* gets the client's position */
1995 frame_frame_gravity(self
->frame
, &x
, &y
);
1997 /* these override the above states! if you cant move you can't move! */
1999 if (!(self
->functions
& OB_CLIENT_FUNC_MOVE
)) {
2003 if (!(self
->functions
& OB_CLIENT_FUNC_RESIZE
)) {
2004 w
= self
->area
.width
;
2005 h
= self
->area
.height
;
2009 if (!(w
== self
->area
.width
&& h
== self
->area
.height
)) {
2010 gint basew
, baseh
, minw
, minh
;
2012 /* base size is substituted with min size if not specified */
2013 if (self
->base_size
.width
|| self
->base_size
.height
) {
2014 basew
= self
->base_size
.width
;
2015 baseh
= self
->base_size
.height
;
2017 basew
= self
->min_size
.width
;
2018 baseh
= self
->min_size
.height
;
2020 /* min size is substituted with base size if not specified */
2021 if (self
->min_size
.width
|| self
->min_size
.height
) {
2022 minw
= self
->min_size
.width
;
2023 minh
= self
->min_size
.height
;
2025 minw
= self
->base_size
.width
;
2026 minh
= self
->base_size
.height
;
2029 /* if this is a user-requested resize, then check against min/max
2032 /* smaller than min size or bigger than max size? */
2033 if (w
> self
->max_size
.width
) w
= self
->max_size
.width
;
2034 if (w
< minw
) w
= minw
;
2035 if (h
> self
->max_size
.height
) h
= self
->max_size
.height
;
2036 if (h
< minh
) h
= minh
;
2041 /* keep to the increments */
2042 w
/= self
->size_inc
.width
;
2043 h
/= self
->size_inc
.height
;
2045 /* you cannot resize to nothing */
2046 if (basew
+ w
< 1) w
= 1 - basew
;
2047 if (baseh
+ h
< 1) h
= 1 - baseh
;
2049 /* store the logical size */
2050 SIZE_SET(self
->logical_size
,
2051 self
->size_inc
.width
> 1 ? w
: w
+ basew
,
2052 self
->size_inc
.height
> 1 ? h
: h
+ baseh
);
2054 w
*= self
->size_inc
.width
;
2055 h
*= self
->size_inc
.height
;
2060 /* adjust the height to match the width for the aspect ratios.
2061 for this, min size is not substituted for base size ever. */
2062 w
-= self
->base_size
.width
;
2063 h
-= self
->base_size
.height
;
2065 if (!self
->fullscreen
) {
2066 if (self
->min_ratio
)
2067 if (h
* self
->min_ratio
> w
) {
2068 h
= (gint
)(w
/ self
->min_ratio
);
2070 /* you cannot resize to nothing */
2073 w
= (gint
)(h
* self
->min_ratio
);
2076 if (self
->max_ratio
)
2077 if (h
* self
->max_ratio
< w
) {
2078 h
= (gint
)(w
/ self
->max_ratio
);
2080 /* you cannot resize to nothing */
2083 w
= (gint
)(h
* self
->min_ratio
);
2088 w
+= self
->base_size
.width
;
2089 h
+= self
->base_size
.height
;
2096 case OB_CORNER_TOPLEFT
:
2098 case OB_CORNER_TOPRIGHT
:
2099 x
-= w
- self
->area
.width
;
2101 case OB_CORNER_BOTTOMLEFT
:
2102 y
-= h
- self
->area
.height
;
2104 case OB_CORNER_BOTTOMRIGHT
:
2105 x
-= w
- self
->area
.width
;
2106 y
-= h
- self
->area
.height
;
2110 moved
= x
!= self
->area
.x
|| y
!= self
->area
.y
;
2111 resized
= w
!= self
->area
.width
|| h
!= self
->area
.height
;
2113 oldw
= self
->area
.width
;
2114 oldh
= self
->area
.height
;
2115 RECT_SET(self
->area
, x
, y
, w
, h
);
2117 /* for app-requested resizes, always resize if 'resized' is true.
2118 for user-requested ones, only resize if final is true, or when
2119 resizing in redraw mode */
2120 send_resize_client
= ((!user
&& resized
) ||
2122 (resized
&& config_resize_redraw
))));
2124 /* if the client is enlarging, then resize the client before the frame */
2125 if (send_resize_client
&& user
&& (w
> oldw
|| h
> oldh
))
2126 XResizeWindow(ob_display
, self
->window
, MAX(w
, oldw
), MAX(h
, oldh
));
2128 /* move/resize the frame to match the request */
2130 if (self
->decorations
!= fdecor
|| self
->max_horz
!= fhorz
)
2131 moved
= resized
= TRUE
;
2133 if (moved
|| resized
)
2134 frame_adjust_area(self
->frame
, moved
, resized
, FALSE
);
2136 if (!resized
&& (force_reply
|| ((!user
&& moved
) || (user
&& final
))))
2139 event
.type
= ConfigureNotify
;
2140 event
.xconfigure
.display
= ob_display
;
2141 event
.xconfigure
.event
= self
->window
;
2142 event
.xconfigure
.window
= self
->window
;
2144 /* root window real coords */
2145 event
.xconfigure
.x
= self
->frame
->area
.x
+ self
->frame
->size
.left
-
2147 event
.xconfigure
.y
= self
->frame
->area
.y
+ self
->frame
->size
.top
-
2149 event
.xconfigure
.width
= w
;
2150 event
.xconfigure
.height
= h
;
2151 event
.xconfigure
.border_width
= 0;
2152 event
.xconfigure
.above
= self
->frame
->plate
;
2153 event
.xconfigure
.override_redirect
= FALSE
;
2154 XSendEvent(event
.xconfigure
.display
, event
.xconfigure
.window
,
2155 FALSE
, StructureNotifyMask
, &event
);
2159 /* if the client is shrinking, then resize the frame before the client */
2160 if (send_resize_client
&& (!user
|| (w
<= oldw
|| h
<= oldh
)))
2161 XResizeWindow(ob_display
, self
->window
, w
, h
);
2166 void client_fullscreen(ObClient
*self
, gboolean fs
, gboolean savearea
)
2170 if (!(self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
) || /* can't */
2171 self
->fullscreen
== fs
) return; /* already done */
2173 self
->fullscreen
= fs
;
2174 client_change_state(self
); /* change the state hints on the client,
2175 and adjust out layer/stacking */
2179 self
->pre_fullscreen_area
= self
->area
;
2181 /* these are not actually used cuz client_configure will set them
2182 as appropriate when the window is fullscreened */
2187 if (self
->pre_fullscreen_area
.width
> 0 &&
2188 self
->pre_fullscreen_area
.height
> 0)
2190 x
= self
->pre_fullscreen_area
.x
;
2191 y
= self
->pre_fullscreen_area
.y
;
2192 w
= self
->pre_fullscreen_area
.width
;
2193 h
= self
->pre_fullscreen_area
.height
;
2194 RECT_SET(self
->pre_fullscreen_area
, 0, 0, 0, 0);
2196 /* pick some fallbacks... */
2197 a
= screen_area_monitor(self
->desktop
, 0);
2198 x
= a
->x
+ a
->width
/ 4;
2199 y
= a
->y
+ a
->height
/ 4;
2205 client_setup_decor_and_functions(self
);
2207 client_move_resize(self
, x
, y
, w
, h
);
2209 /* try focus us when we go into fullscreen mode */
2213 static void client_iconify_recursive(ObClient
*self
,
2214 gboolean iconic
, gboolean curdesk
)
2217 gboolean changed
= FALSE
;
2220 if (self
->iconic
!= iconic
) {
2221 ob_debug("%sconifying window: 0x%lx\n", (iconic
? "I" : "Uni"),
2224 self
->iconic
= iconic
;
2227 if (self
->functions
& OB_CLIENT_FUNC_ICONIFY
) {
2230 old
= self
->wmstate
;
2231 self
->wmstate
= IconicState
;
2232 if (old
!= self
->wmstate
)
2233 PROP_MSG(self
->window
, kde_wm_change_state
,
2234 self
->wmstate
, 1, 0, 0);
2236 /* update the focus lists.. iconic windows go to the bottom of
2237 the list, put the new iconic window at the 'top of the
2239 focus_order_to_top(self
);
2247 client_set_desktop(self
, screen_desktop
, FALSE
);
2249 old
= self
->wmstate
;
2250 self
->wmstate
= self
->shaded
? IconicState
: NormalState
;
2251 if (old
!= self
->wmstate
)
2252 PROP_MSG(self
->window
, kde_wm_change_state
,
2253 self
->wmstate
, 1, 0, 0);
2255 /* this puts it after the current focused window */
2256 focus_order_remove(self
);
2257 focus_order_add_new(self
);
2259 /* this is here cuz with the VIDMODE extension, the viewport can
2260 change while a fullscreen window is iconic, and when it
2261 uniconifies, it would be nice if it did so to the new position
2263 client_reconfigure(self
);
2270 client_change_state(self
);
2271 client_showhide(self
);
2272 screen_update_areas();
2275 /* iconify all transients */
2276 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
2277 if (it
->data
!= self
) client_iconify_recursive(it
->data
,
2281 void client_iconify(ObClient
*self
, gboolean iconic
, gboolean curdesk
)
2283 /* move up the transient chain as far as possible first */
2284 self
= client_search_top_transient(self
);
2286 client_iconify_recursive(client_search_top_transient(self
),
2290 void client_maximize(ObClient
*self
, gboolean max
, gint dir
, gboolean savearea
)
2294 g_assert(dir
== 0 || dir
== 1 || dir
== 2);
2295 if (!(self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
)) return; /* can't */
2297 /* check if already done */
2299 if (dir
== 0 && self
->max_horz
&& self
->max_vert
) return;
2300 if (dir
== 1 && self
->max_horz
) return;
2301 if (dir
== 2 && self
->max_vert
) return;
2303 if (dir
== 0 && !self
->max_horz
&& !self
->max_vert
) return;
2304 if (dir
== 1 && !self
->max_horz
) return;
2305 if (dir
== 2 && !self
->max_vert
) return;
2308 /* we just tell it to configure in the same place and client_configure
2309 worries about filling the screen with the window */
2312 w
= self
->area
.width
;
2313 h
= self
->area
.height
;
2317 if ((dir
== 0 || dir
== 1) && !self
->max_horz
) { /* horz */
2318 RECT_SET(self
->pre_max_area
,
2319 self
->area
.x
, self
->pre_max_area
.y
,
2320 self
->area
.width
, self
->pre_max_area
.height
);
2322 if ((dir
== 0 || dir
== 2) && !self
->max_vert
) { /* vert */
2323 RECT_SET(self
->pre_max_area
,
2324 self
->pre_max_area
.x
, self
->area
.y
,
2325 self
->pre_max_area
.width
, self
->area
.height
);
2331 a
= screen_area_monitor(self
->desktop
, 0);
2332 if ((dir
== 0 || dir
== 1) && self
->max_horz
) { /* horz */
2333 if (self
->pre_max_area
.width
> 0) {
2334 x
= self
->pre_max_area
.x
;
2335 w
= self
->pre_max_area
.width
;
2337 RECT_SET(self
->pre_max_area
, 0, self
->pre_max_area
.y
,
2338 0, self
->pre_max_area
.height
);
2340 /* pick some fallbacks... */
2341 x
= a
->x
+ a
->width
/ 4;
2345 if ((dir
== 0 || dir
== 2) && self
->max_vert
) { /* vert */
2346 if (self
->pre_max_area
.height
> 0) {
2347 y
= self
->pre_max_area
.y
;
2348 h
= self
->pre_max_area
.height
;
2350 RECT_SET(self
->pre_max_area
, self
->pre_max_area
.x
, 0,
2351 self
->pre_max_area
.width
, 0);
2353 /* pick some fallbacks... */
2354 y
= a
->y
+ a
->height
/ 4;
2360 if (dir
== 0 || dir
== 1) /* horz */
2361 self
->max_horz
= max
;
2362 if (dir
== 0 || dir
== 2) /* vert */
2363 self
->max_vert
= max
;
2365 client_change_state(self
); /* change the state hints on the client */
2367 client_setup_decor_and_functions(self
);
2369 client_move_resize(self
, x
, y
, w
, h
);
2372 void client_shade(ObClient
*self
, gboolean shade
)
2374 if ((!(self
->functions
& OB_CLIENT_FUNC_SHADE
) &&
2375 shade
) || /* can't shade */
2376 self
->shaded
== shade
) return; /* already done */
2378 /* when we're iconic, don't change the wmstate */
2379 if (!self
->iconic
) {
2382 old
= self
->wmstate
;
2383 self
->wmstate
= shade
? IconicState
: NormalState
;
2384 if (old
!= self
->wmstate
)
2385 PROP_MSG(self
->window
, kde_wm_change_state
,
2386 self
->wmstate
, 1, 0, 0);
2389 self
->shaded
= shade
;
2390 client_change_state(self
);
2391 /* resize the frame to just the titlebar */
2392 frame_adjust_area(self
->frame
, FALSE
, FALSE
, FALSE
);
2395 void client_close(ObClient
*self
)
2399 if (!(self
->functions
& OB_CLIENT_FUNC_CLOSE
)) return;
2401 /* in the case that the client provides no means to requesting that it
2402 close, we just kill it */
2403 if (!self
->delete_window
)
2407 XXX: itd be cool to do timeouts and shit here for killing the client's
2409 like... if the window is around after 5 seconds, then the close button
2410 turns a nice red, and if this function is called again, the client is
2414 ce
.xclient
.type
= ClientMessage
;
2415 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
2416 ce
.xclient
.display
= ob_display
;
2417 ce
.xclient
.window
= self
->window
;
2418 ce
.xclient
.format
= 32;
2419 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_delete_window
;
2420 ce
.xclient
.data
.l
[1] = event_lasttime
;
2421 ce
.xclient
.data
.l
[2] = 0l;
2422 ce
.xclient
.data
.l
[3] = 0l;
2423 ce
.xclient
.data
.l
[4] = 0l;
2424 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
2427 void client_kill(ObClient
*self
)
2429 XKillClient(ob_display
, self
->window
);
2432 void client_set_desktop_recursive(ObClient
*self
,
2433 guint target
, gboolean donthide
)
2438 if (target
!= self
->desktop
) {
2440 ob_debug("Setting desktop %u\n", target
+1);
2442 g_assert(target
< screen_num_desktops
|| target
== DESKTOP_ALL
);
2444 /* remove from the old desktop(s) */
2445 focus_order_remove(self
);
2447 old
= self
->desktop
;
2448 self
->desktop
= target
;
2449 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, target
);
2450 /* the frame can display the current desktop state */
2451 frame_adjust_state(self
->frame
);
2452 /* 'move' the window to the new desktop */
2454 client_showhide(self
);
2455 /* raise if it was not already on the desktop */
2456 if (old
!= DESKTOP_ALL
)
2458 screen_update_areas();
2460 /* add to the new desktop(s) */
2461 if (config_focus_new
)
2462 focus_order_to_top(self
);
2464 focus_order_to_bottom(self
);
2467 /* move all transients */
2468 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
2469 if (it
->data
!= self
) client_set_desktop_recursive(it
->data
,
2473 void client_set_desktop(ObClient
*self
, guint target
, gboolean donthide
)
2475 client_set_desktop_recursive(client_search_top_transient(self
),
2479 ObClient
*client_search_modal_child(ObClient
*self
)
2484 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
2485 ObClient
*c
= it
->data
;
2486 if ((ret
= client_search_modal_child(c
))) return ret
;
2487 if (c
->modal
) return c
;
2492 gboolean
client_validate(ObClient
*self
)
2496 XSync(ob_display
, FALSE
); /* get all events on the server */
2498 if (XCheckTypedWindowEvent(ob_display
, self
->window
, DestroyNotify
, &e
) ||
2499 XCheckTypedWindowEvent(ob_display
, self
->window
, UnmapNotify
, &e
)) {
2500 XPutBackEvent(ob_display
, &e
);
2507 void client_set_wm_state(ObClient
*self
, glong state
)
2509 if (state
== self
->wmstate
) return; /* no change */
2513 client_iconify(self
, TRUE
, TRUE
);
2516 client_iconify(self
, FALSE
, TRUE
);
2521 void client_set_state(ObClient
*self
, Atom action
, glong data1
, glong data2
)
2523 gboolean shaded
= self
->shaded
;
2524 gboolean fullscreen
= self
->fullscreen
;
2525 gboolean undecorated
= self
->undecorated
;
2526 gboolean max_horz
= self
->max_horz
;
2527 gboolean max_vert
= self
->max_vert
;
2528 gboolean modal
= self
->modal
;
2531 if (!(action
== prop_atoms
.net_wm_state_add
||
2532 action
== prop_atoms
.net_wm_state_remove
||
2533 action
== prop_atoms
.net_wm_state_toggle
))
2534 /* an invalid action was passed to the client message, ignore it */
2537 for (i
= 0; i
< 2; ++i
) {
2538 Atom state
= i
== 0 ? data1
: data2
;
2540 if (!state
) continue;
2542 /* if toggling, then pick whether we're adding or removing */
2543 if (action
== prop_atoms
.net_wm_state_toggle
) {
2544 if (state
== prop_atoms
.net_wm_state_modal
)
2545 action
= modal
? prop_atoms
.net_wm_state_remove
:
2546 prop_atoms
.net_wm_state_add
;
2547 else if (state
== prop_atoms
.net_wm_state_maximized_vert
)
2548 action
= self
->max_vert
? prop_atoms
.net_wm_state_remove
:
2549 prop_atoms
.net_wm_state_add
;
2550 else if (state
== prop_atoms
.net_wm_state_maximized_horz
)
2551 action
= self
->max_horz
? prop_atoms
.net_wm_state_remove
:
2552 prop_atoms
.net_wm_state_add
;
2553 else if (state
== prop_atoms
.net_wm_state_shaded
)
2554 action
= shaded
? prop_atoms
.net_wm_state_remove
:
2555 prop_atoms
.net_wm_state_add
;
2556 else if (state
== prop_atoms
.net_wm_state_skip_taskbar
)
2557 action
= self
->skip_taskbar
?
2558 prop_atoms
.net_wm_state_remove
:
2559 prop_atoms
.net_wm_state_add
;
2560 else if (state
== prop_atoms
.net_wm_state_skip_pager
)
2561 action
= self
->skip_pager
?
2562 prop_atoms
.net_wm_state_remove
:
2563 prop_atoms
.net_wm_state_add
;
2564 else if (state
== prop_atoms
.net_wm_state_fullscreen
)
2565 action
= fullscreen
?
2566 prop_atoms
.net_wm_state_remove
:
2567 prop_atoms
.net_wm_state_add
;
2568 else if (state
== prop_atoms
.net_wm_state_above
)
2569 action
= self
->above
? prop_atoms
.net_wm_state_remove
:
2570 prop_atoms
.net_wm_state_add
;
2571 else if (state
== prop_atoms
.net_wm_state_below
)
2572 action
= self
->below
? prop_atoms
.net_wm_state_remove
:
2573 prop_atoms
.net_wm_state_add
;
2574 else if (state
== prop_atoms
.ob_wm_state_undecorated
)
2575 action
= undecorated
? prop_atoms
.net_wm_state_remove
:
2576 prop_atoms
.net_wm_state_add
;
2579 if (action
== prop_atoms
.net_wm_state_add
) {
2580 if (state
== prop_atoms
.net_wm_state_modal
) {
2582 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
2584 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
2586 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
2588 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
2589 self
->skip_taskbar
= TRUE
;
2590 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
2591 self
->skip_pager
= TRUE
;
2592 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
2594 } else if (state
== prop_atoms
.net_wm_state_above
) {
2596 self
->below
= FALSE
;
2597 } else if (state
== prop_atoms
.net_wm_state_below
) {
2598 self
->above
= FALSE
;
2600 } else if (state
== prop_atoms
.ob_wm_state_undecorated
) {
2604 } else { /* action == prop_atoms.net_wm_state_remove */
2605 if (state
== prop_atoms
.net_wm_state_modal
) {
2607 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
2609 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
2611 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
2613 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
2614 self
->skip_taskbar
= FALSE
;
2615 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
2616 self
->skip_pager
= FALSE
;
2617 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
2619 } else if (state
== prop_atoms
.net_wm_state_above
) {
2620 self
->above
= FALSE
;
2621 } else if (state
== prop_atoms
.net_wm_state_below
) {
2622 self
->below
= FALSE
;
2623 } else if (state
== prop_atoms
.ob_wm_state_undecorated
) {
2624 undecorated
= FALSE
;
2628 if (max_horz
!= self
->max_horz
|| max_vert
!= self
->max_vert
) {
2629 if (max_horz
!= self
->max_horz
&& max_vert
!= self
->max_vert
) {
2631 if (max_horz
== max_vert
) { /* both going the same way */
2632 client_maximize(self
, max_horz
, 0, TRUE
);
2634 client_maximize(self
, max_horz
, 1, TRUE
);
2635 client_maximize(self
, max_vert
, 2, TRUE
);
2639 if (max_horz
!= self
->max_horz
)
2640 client_maximize(self
, max_horz
, 1, TRUE
);
2642 client_maximize(self
, max_vert
, 2, TRUE
);
2645 /* change fullscreen state before shading, as it will affect if the window
2647 if (fullscreen
!= self
->fullscreen
)
2648 client_fullscreen(self
, fullscreen
, TRUE
);
2649 if (shaded
!= self
->shaded
)
2650 client_shade(self
, shaded
);
2651 if (undecorated
!= self
->undecorated
)
2652 client_set_undecorated(self
, undecorated
);
2653 if (modal
!= self
->modal
) {
2654 self
->modal
= modal
;
2655 /* when a window changes modality, then its stacking order with its
2656 transients needs to change */
2659 client_calc_layer(self
);
2660 client_change_state(self
); /* change the hint to reflect these changes */
2663 ObClient
*client_focus_target(ObClient
*self
)
2667 /* if we have a modal child, then focus it, not us */
2668 child
= client_search_modal_child(client_search_top_transient(self
));
2669 if (child
) return child
;
2673 gboolean
client_can_focus(ObClient
*self
)
2677 /* choose the correct target */
2678 self
= client_focus_target(self
);
2680 if (!self
->frame
->visible
)
2683 if (!(self
->can_focus
|| self
->focus_notify
))
2686 /* do a check to see if the window has already been unmapped or destroyed
2687 do this intelligently while watching out for unmaps we've generated
2688 (ignore_unmaps > 0) */
2689 if (XCheckTypedWindowEvent(ob_display
, self
->window
,
2690 DestroyNotify
, &ev
)) {
2691 XPutBackEvent(ob_display
, &ev
);
2694 while (XCheckTypedWindowEvent(ob_display
, self
->window
,
2695 UnmapNotify
, &ev
)) {
2696 if (self
->ignore_unmaps
) {
2697 self
->ignore_unmaps
--;
2699 XPutBackEvent(ob_display
, &ev
);
2707 gboolean
client_focus(ObClient
*self
)
2709 /* choose the correct target */
2710 self
= client_focus_target(self
);
2712 if (!client_can_focus(self
)) {
2713 if (!self
->frame
->visible
) {
2714 /* update the focus lists */
2715 focus_order_to_top(self
);
2720 if (self
->can_focus
) {
2721 /* RevertToPointerRoot causes much more headache than RevertToNone, so
2722 I choose to use it always, hopefully to find errors quicker, if any
2723 are left. (I hate X. I hate focus events.)
2725 Update: Changing this to RevertToNone fixed a bug with mozilla (bug
2726 #799. So now it is RevertToNone again.
2728 XSetInputFocus(ob_display
, self
->window
, RevertToNone
,
2732 if (self
->focus_notify
) {
2734 ce
.xclient
.type
= ClientMessage
;
2735 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
2736 ce
.xclient
.display
= ob_display
;
2737 ce
.xclient
.window
= self
->window
;
2738 ce
.xclient
.format
= 32;
2739 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_take_focus
;
2740 ce
.xclient
.data
.l
[1] = event_lasttime
;
2741 ce
.xclient
.data
.l
[2] = 0l;
2742 ce
.xclient
.data
.l
[3] = 0l;
2743 ce
.xclient
.data
.l
[4] = 0l;
2744 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
2748 ob_debug("%sively focusing %lx at %d\n",
2749 (self
->can_focus
? "act" : "pass"),
2750 self
->window
, (gint
) event_lasttime
);
2753 /* Cause the FocusIn to come back to us. Important for desktop switches,
2754 since otherwise we'll have no FocusIn on the queue and send it off to
2755 the focus_backup. */
2756 XSync(ob_display
, FALSE
);
2760 void client_unfocus(ObClient
*self
)
2762 if (focus_client
== self
) {
2764 ob_debug("client_unfocus for %lx\n", self
->window
);
2766 focus_fallback(OB_FOCUS_FALLBACK_UNFOCUSING
);
2770 void client_activate(ObClient
*self
, gboolean here
)
2772 if (client_normal(self
) && screen_showing_desktop
)
2773 screen_show_desktop(FALSE
);
2775 client_iconify(self
, FALSE
, here
);
2776 if (self
->desktop
!= DESKTOP_ALL
&&
2777 self
->desktop
!= screen_desktop
) {
2779 client_set_desktop(self
, screen_desktop
, FALSE
);
2781 screen_set_desktop(self
->desktop
);
2782 } else if (!self
->frame
->visible
)
2783 /* if its not visible for other reasons, then don't mess
2787 client_shade(self
, FALSE
);
2791 /* we do this an action here. this is rather important. this is because
2792 we want the results from the focus change to take place BEFORE we go
2793 about raising the window. when a fullscreen window loses focus, we need
2794 this or else the raise wont be able to raise above the to-lose-focus
2795 fullscreen window. */
2799 void client_raise(ObClient
*self
)
2801 action_run_string("Raise", self
);
2804 void client_lower(ObClient
*self
)
2806 action_run_string("Lower", self
);
2809 gboolean
client_focused(ObClient
*self
)
2811 return self
== focus_client
;
2814 static ObClientIcon
* client_icon_recursive(ObClient
*self
, gint w
, gint h
)
2817 /* si is the smallest image >= req */
2818 /* li is the largest image < req */
2819 gulong size
, smallest
= 0xffffffff, largest
= 0, si
= 0, li
= 0;
2821 if (!self
->nicons
) {
2822 ObClientIcon
*parent
= NULL
;
2824 if (self
->transient_for
) {
2825 if (self
->transient_for
!= OB_TRAN_GROUP
)
2826 parent
= client_icon_recursive(self
->transient_for
, w
, h
);
2829 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
2830 ObClient
*c
= it
->data
;
2831 if (c
!= self
&& !c
->transient_for
) {
2832 if ((parent
= client_icon_recursive(c
, w
, h
)))
2842 for (i
= 0; i
< self
->nicons
; ++i
) {
2843 size
= self
->icons
[i
].width
* self
->icons
[i
].height
;
2844 if (size
< smallest
&& size
>= (unsigned)(w
* h
)) {
2848 if (size
> largest
&& size
<= (unsigned)(w
* h
)) {
2853 if (largest
== 0) /* didnt find one smaller than the requested size */
2854 return &self
->icons
[si
];
2855 return &self
->icons
[li
];
2858 const ObClientIcon
* client_icon(ObClient
*self
, gint w
, gint h
)
2861 static ObClientIcon deficon
;
2863 if (!(ret
= client_icon_recursive(self
, w
, h
))) {
2864 deficon
.width
= deficon
.height
= 48;
2865 deficon
.data
= ob_rr_theme
->def_win_icon
;
2871 /* this be mostly ripped from fvwm */
2872 ObClient
*client_find_directional(ObClient
*c
, ObDirection dir
)
2874 gint my_cx
, my_cy
, his_cx
, his_cy
;
2877 gint score
, best_score
;
2878 ObClient
*best_client
, *cur
;
2884 /* first, find the centre coords of the currently focused window */
2885 my_cx
= c
->frame
->area
.x
+ c
->frame
->area
.width
/ 2;
2886 my_cy
= c
->frame
->area
.y
+ c
->frame
->area
.height
/ 2;
2891 for(it
= g_list_first(client_list
); it
; it
= g_list_next(it
)) {
2894 /* the currently selected window isn't interesting */
2897 if (!client_normal(cur
))
2899 if(c
->desktop
!= cur
->desktop
&& cur
->desktop
!= DESKTOP_ALL
)
2903 if(client_focus_target(cur
) == cur
&&
2904 !(cur
->can_focus
|| cur
->focus_notify
))
2907 /* find the centre coords of this window, from the
2908 * currently focused window's point of view */
2909 his_cx
= (cur
->frame
->area
.x
- my_cx
)
2910 + cur
->frame
->area
.width
/ 2;
2911 his_cy
= (cur
->frame
->area
.y
- my_cy
)
2912 + cur
->frame
->area
.height
/ 2;
2914 if(dir
== OB_DIRECTION_NORTHEAST
|| dir
== OB_DIRECTION_SOUTHEAST
||
2915 dir
== OB_DIRECTION_SOUTHWEST
|| dir
== OB_DIRECTION_NORTHWEST
) {
2917 /* Rotate the diagonals 45 degrees counterclockwise.
2918 * To do this, multiply the matrix /+h +h\ with the
2919 * vector (x y). \-h +h/
2920 * h = sqrt(0.5). We can set h := 1 since absolute
2921 * distance doesn't matter here. */
2922 tx
= his_cx
+ his_cy
;
2923 his_cy
= -his_cx
+ his_cy
;
2928 case OB_DIRECTION_NORTH
:
2929 case OB_DIRECTION_SOUTH
:
2930 case OB_DIRECTION_NORTHEAST
:
2931 case OB_DIRECTION_SOUTHWEST
:
2932 offset
= (his_cx
< 0) ? -his_cx
: his_cx
;
2933 distance
= ((dir
== OB_DIRECTION_NORTH
||
2934 dir
== OB_DIRECTION_NORTHEAST
) ?
2937 case OB_DIRECTION_EAST
:
2938 case OB_DIRECTION_WEST
:
2939 case OB_DIRECTION_SOUTHEAST
:
2940 case OB_DIRECTION_NORTHWEST
:
2941 offset
= (his_cy
< 0) ? -his_cy
: his_cy
;
2942 distance
= ((dir
== OB_DIRECTION_WEST
||
2943 dir
== OB_DIRECTION_NORTHWEST
) ?
2948 /* the target must be in the requested direction */
2952 /* Calculate score for this window. The smaller the better. */
2953 score
= distance
+ offset
;
2955 /* windows more than 45 degrees off the direction are
2956 * heavily penalized and will only be chosen if nothing
2957 * else within a million pixels */
2958 if(offset
> distance
)
2961 if(best_score
== -1 || score
< best_score
)
2969 void client_set_layer(ObClient
*self
, gint layer
)
2973 self
->above
= FALSE
;
2974 } else if (layer
== 0) {
2975 self
->below
= self
->above
= FALSE
;
2977 self
->below
= FALSE
;
2980 client_calc_layer(self
);
2981 client_change_state(self
); /* reflect this in the state hints */
2984 void client_set_undecorated(ObClient
*self
, gboolean undecorated
)
2986 if (self
->undecorated
!= undecorated
) {
2987 self
->undecorated
= undecorated
;
2988 client_setup_decor_and_functions(self
);
2989 client_change_state(self
); /* reflect this in the state hints */
2993 guint
client_monitor(ObClient
*self
)
2999 for (i
= 0; i
< screen_num_monitors
; ++i
) {
3000 Rect
*area
= screen_physical_area_monitor(i
);
3001 if (RECT_INTERSECTS_RECT(*area
, self
->frame
->area
)) {
3005 RECT_SET_INTERSECTION(r
, *area
, self
->frame
->area
);
3006 v
= r
.width
* r
.height
;
3017 ObClient
*client_search_top_transient(ObClient
*self
)
3019 /* move up the transient chain as far as possible */
3020 if (self
->transient_for
) {
3021 if (self
->transient_for
!= OB_TRAN_GROUP
) {
3022 return client_search_top_transient(self
->transient_for
);
3026 g_assert(self
->group
);
3028 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
3029 ObClient
*c
= it
->data
;
3031 /* checking transient_for prevents infinate loops! */
3032 if (c
!= self
&& !c
->transient_for
)
3043 ObClient
*client_search_focus_parent(ObClient
*self
)
3045 if (self
->transient_for
) {
3046 if (self
->transient_for
!= OB_TRAN_GROUP
) {
3047 if (client_focused(self
->transient_for
))
3048 return self
->transient_for
;
3052 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
3053 ObClient
*c
= it
->data
;
3055 /* checking transient_for prevents infinate loops! */
3056 if (c
!= self
&& !c
->transient_for
)
3057 if (client_focused(c
))
3066 ObClient
*client_search_parent(ObClient
*self
, ObClient
*search
)
3068 if (self
->transient_for
) {
3069 if (self
->transient_for
!= OB_TRAN_GROUP
) {
3070 if (self
->transient_for
== search
)
3075 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
3076 ObClient
*c
= it
->data
;
3078 /* checking transient_for prevents infinate loops! */
3079 if (c
!= self
&& !c
->transient_for
)
3089 ObClient
*client_search_transient(ObClient
*self
, ObClient
*search
)
3093 for (sit
= self
->transients
; sit
; sit
= g_slist_next(sit
)) {
3094 if (sit
->data
== search
)
3096 if (client_search_transient(sit
->data
, search
))
3102 void client_update_sm_client_id(ObClient
*self
)
3104 g_free(self
->sm_client_id
);
3105 self
->sm_client_id
= NULL
;
3107 if (!PROP_GETS(self
->window
, sm_client_id
, locale
, &self
->sm_client_id
) &&
3109 PROP_GETS(self
->group
->leader
, sm_client_id
, locale
,
3110 &self
->sm_client_id
);
3113 /* finds the nearest edge in the given direction from the current client
3114 * note to self: the edge is the -frame- edge (the actual one), not the
3117 gint
client_directional_edge_search(ObClient
*c
, ObDirection dir
)
3120 gint my_edge_start
, my_edge_end
, my_offset
;
3127 a
= screen_area(c
->desktop
);
3130 case OB_DIRECTION_NORTH
:
3131 my_edge_start
= c
->frame
->area
.x
;
3132 my_edge_end
= c
->frame
->area
.x
+ c
->frame
->area
.width
;
3133 my_offset
= c
->frame
->area
.y
;
3135 /* default: top of screen */
3138 for(it
= client_list
; it
; it
= g_list_next(it
)) {
3139 gint his_edge_start
, his_edge_end
, his_offset
;
3140 ObClient
*cur
= it
->data
;
3144 if(!client_normal(cur
))
3146 if(c
->desktop
!= cur
->desktop
&& cur
->desktop
!= DESKTOP_ALL
)
3151 his_edge_start
= cur
->frame
->area
.x
;
3152 his_edge_end
= cur
->frame
->area
.x
+ cur
->frame
->area
.width
;
3153 his_offset
= cur
->frame
->area
.y
+ cur
->frame
->area
.height
;
3155 if(his_offset
+ 1 > my_offset
)
3158 if(his_offset
< dest
)
3161 if(his_edge_start
>= my_edge_start
&&
3162 his_edge_start
<= my_edge_end
)
3165 if(my_edge_start
>= his_edge_start
&&
3166 my_edge_start
<= his_edge_end
)
3171 case OB_DIRECTION_SOUTH
:
3172 my_edge_start
= c
->frame
->area
.x
;
3173 my_edge_end
= c
->frame
->area
.x
+ c
->frame
->area
.width
;
3174 my_offset
= c
->frame
->area
.y
+ c
->frame
->area
.height
;
3176 /* default: bottom of screen */
3177 dest
= a
->y
+ a
->height
;
3179 for(it
= client_list
; it
; it
= g_list_next(it
)) {
3180 gint his_edge_start
, his_edge_end
, his_offset
;
3181 ObClient
*cur
= it
->data
;
3185 if(!client_normal(cur
))
3187 if(c
->desktop
!= cur
->desktop
&& cur
->desktop
!= DESKTOP_ALL
)
3192 his_edge_start
= cur
->frame
->area
.x
;
3193 his_edge_end
= cur
->frame
->area
.x
+ cur
->frame
->area
.width
;
3194 his_offset
= cur
->frame
->area
.y
;
3197 if(his_offset
- 1 < my_offset
)
3200 if(his_offset
> dest
)
3203 if(his_edge_start
>= my_edge_start
&&
3204 his_edge_start
<= my_edge_end
)
3207 if(my_edge_start
>= his_edge_start
&&
3208 my_edge_start
<= his_edge_end
)
3213 case OB_DIRECTION_WEST
:
3214 my_edge_start
= c
->frame
->area
.y
;
3215 my_edge_end
= c
->frame
->area
.y
+ c
->frame
->area
.height
;
3216 my_offset
= c
->frame
->area
.x
;
3218 /* default: leftmost egde of screen */
3221 for(it
= client_list
; it
; it
= g_list_next(it
)) {
3222 gint his_edge_start
, his_edge_end
, his_offset
;
3223 ObClient
*cur
= it
->data
;
3227 if(!client_normal(cur
))
3229 if(c
->desktop
!= cur
->desktop
&& cur
->desktop
!= DESKTOP_ALL
)
3234 his_edge_start
= cur
->frame
->area
.y
;
3235 his_edge_end
= cur
->frame
->area
.y
+ cur
->frame
->area
.height
;
3236 his_offset
= cur
->frame
->area
.x
+ cur
->frame
->area
.width
;
3238 if(his_offset
+ 1 > my_offset
)
3241 if(his_offset
< dest
)
3244 if(his_edge_start
>= my_edge_start
&&
3245 his_edge_start
<= my_edge_end
)
3248 if(my_edge_start
>= his_edge_start
&&
3249 my_edge_start
<= his_edge_end
)
3255 case OB_DIRECTION_EAST
:
3256 my_edge_start
= c
->frame
->area
.y
;
3257 my_edge_end
= c
->frame
->area
.y
+ c
->frame
->area
.height
;
3258 my_offset
= c
->frame
->area
.x
+ c
->frame
->area
.width
;
3260 /* default: rightmost edge of screen */
3261 dest
= a
->x
+ a
->width
;
3263 for(it
= client_list
; it
; it
= g_list_next(it
)) {
3264 gint his_edge_start
, his_edge_end
, his_offset
;
3265 ObClient
*cur
= it
->data
;
3269 if(!client_normal(cur
))
3271 if(c
->desktop
!= cur
->desktop
&& cur
->desktop
!= DESKTOP_ALL
)
3276 his_edge_start
= cur
->frame
->area
.y
;
3277 his_edge_end
= cur
->frame
->area
.y
+ cur
->frame
->area
.height
;
3278 his_offset
= cur
->frame
->area
.x
;
3280 if(his_offset
- 1 < my_offset
)
3283 if(his_offset
> dest
)
3286 if(his_edge_start
>= my_edge_start
&&
3287 his_edge_start
<= my_edge_end
)
3290 if(my_edge_start
>= his_edge_start
&&
3291 my_edge_start
<= his_edge_end
)
3296 case OB_DIRECTION_NORTHEAST
:
3297 case OB_DIRECTION_SOUTHEAST
:
3298 case OB_DIRECTION_NORTHWEST
:
3299 case OB_DIRECTION_SOUTHWEST
:
3300 /* not implemented */
3302 g_assert_not_reached();
3307 ObClient
* client_under_pointer()
3311 ObClient
*ret
= NULL
;
3313 if (screen_pointer_pos(&x
, &y
)) {
3314 for (it
= stacking_list
; it
; it
= g_list_next(it
)) {
3315 if (WINDOW_IS_CLIENT(it
->data
)) {
3316 ObClient
*c
= WINDOW_AS_CLIENT(it
->data
);
3317 if (c
->frame
->visible
&&
3318 RECT_CONTAINS(c
->frame
->area
, x
, y
)) {
3328 gboolean
client_has_group_siblings(ObClient
*self
)
3330 return self
->group
&& self
->group
->members
->next
;