1 /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
3 client.c for the Openbox window manager
4 Copyright (c) 2003 Ben Jansens
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 See the COPYING file for a copy of the GNU General Public License.
21 #include "startupnotify.h"
25 #include "moveresize.h"
28 #include "extensions.h"
38 #include "menuframe.h"
41 #include "render/render.h"
44 #include <X11/Xutil.h>
46 /*! The event mask to grab on client windows */
47 #define CLIENT_EVENTMASK (PropertyChangeMask | FocusChangeMask | \
50 #define CLIENT_NOPROPAGATEMASK (ButtonPressMask | ButtonReleaseMask | \
55 ObClientDestructor func
;
59 GList
*client_list
= NULL
;
60 GSList
*client_destructors
= NULL
;
62 static void client_get_all(ObClient
*self
);
63 static void client_toggle_border(ObClient
*self
, gboolean show
);
64 static void client_get_startup_id(ObClient
*self
);
65 static void client_get_area(ObClient
*self
);
66 static void client_get_desktop(ObClient
*self
);
67 static void client_get_state(ObClient
*self
);
68 static void client_get_shaped(ObClient
*self
);
69 static void client_get_mwm_hints(ObClient
*self
);
70 static void client_get_gravity(ObClient
*self
);
71 static void client_showhide(ObClient
*self
);
72 static void client_change_allowed_actions(ObClient
*self
);
73 static void client_change_state(ObClient
*self
);
74 static void client_apply_startup_state(ObClient
*self
);
75 static void client_restore_session_state(ObClient
*self
);
76 static void client_restore_session_stacking(ObClient
*self
);
77 static void client_urgent_notify(ObClient
*self
);
79 void client_startup(gboolean reconfig
)
86 void client_shutdown(gboolean reconfig
)
90 void client_add_destructor(ObClientDestructor func
, gpointer data
)
92 Destructor
*d
= g_new(Destructor
, 1);
95 client_destructors
= g_slist_prepend(client_destructors
, d
);
98 void client_remove_destructor(ObClientDestructor func
)
102 for (it
= client_destructors
; it
; it
= g_slist_next(it
)) {
103 Destructor
*d
= it
->data
;
104 if (d
->func
== func
) {
106 client_destructors
= g_slist_delete_link(client_destructors
, it
);
112 void client_set_list()
114 Window
*windows
, *win_it
;
116 guint size
= g_list_length(client_list
);
118 /* create an array of the window ids */
120 windows
= g_new(Window
, size
);
122 for (it
= client_list
; it
!= NULL
; it
= it
->next
, ++win_it
)
123 *win_it
= ((ObClient
*)it
->data
)->window
;
127 PROP_SETA32(RootWindow(ob_display
, ob_screen
),
128 net_client_list
, window
, (guint32
*)windows
, size
);
137 void client_foreach_transient(ObClient *self, ObClientForeachFunc func, void *data)
141 for (it = self->transients; it; it = it->next) {
142 if (!func(it->data, data)) return;
143 client_foreach_transient(it->data, func, data);
147 void client_foreach_ancestor(ObClient *self, ObClientForeachFunc func, void *data)
149 if (self->transient_for) {
150 if (self->transient_for != OB_TRAN_GROUP) {
151 if (!func(self->transient_for, data)) return;
152 client_foreach_ancestor(self->transient_for, func, data);
156 for (it = self->group->members; it; it = it->next)
157 if (it->data != self &&
158 !((ObClient*)it->data)->transient_for) {
159 if (!func(it->data, data)) return;
160 client_foreach_ancestor(it->data, func, data);
167 void client_manage_all()
169 unsigned int i
, j
, nchild
;
172 XWindowAttributes attrib
;
174 XQueryTree(ob_display
, RootWindow(ob_display
, ob_screen
),
175 &w
, &w
, &children
, &nchild
);
177 /* remove all icon windows from the list */
178 for (i
= 0; i
< nchild
; i
++) {
179 if (children
[i
] == None
) continue;
180 wmhints
= XGetWMHints(ob_display
, children
[i
]);
182 if ((wmhints
->flags
& IconWindowHint
) &&
183 (wmhints
->icon_window
!= children
[i
]))
184 for (j
= 0; j
< nchild
; j
++)
185 if (children
[j
] == wmhints
->icon_window
) {
193 for (i
= 0; i
< nchild
; ++i
) {
194 if (children
[i
] == None
)
196 if (XGetWindowAttributes(ob_display
, children
[i
], &attrib
)) {
197 if (attrib
.override_redirect
) continue;
199 if (attrib
.map_state
!= IsUnmapped
)
200 client_manage(children
[i
]);
206 void client_manage(Window window
)
210 XWindowAttributes attrib
;
211 XSetWindowAttributes attrib_set
;
213 gboolean activate
= FALSE
;
217 /* check if it has already been unmapped by the time we started mapping
218 the grab does a sync so we don't have to here */
219 if (XCheckTypedWindowEvent(ob_display
, window
, DestroyNotify
, &e
) ||
220 XCheckTypedWindowEvent(ob_display
, window
, UnmapNotify
, &e
)) {
221 XPutBackEvent(ob_display
, &e
);
224 return; /* don't manage it */
227 /* make sure it isn't an override-redirect window */
228 if (!XGetWindowAttributes(ob_display
, window
, &attrib
) ||
229 attrib
.override_redirect
) {
231 return; /* don't manage it */
234 /* is the window a docking app */
235 if ((wmhint
= XGetWMHints(ob_display
, window
))) {
236 if ((wmhint
->flags
& StateHint
) &&
237 wmhint
->initial_state
== WithdrawnState
) {
238 dock_add(window
, wmhint
);
246 ob_debug("Managing window: %lx\n", window
);
248 /* choose the events we want to receive on the CLIENT window */
249 attrib_set
.event_mask
= CLIENT_EVENTMASK
;
250 attrib_set
.do_not_propagate_mask
= CLIENT_NOPROPAGATEMASK
;
251 XChangeWindowAttributes(ob_display
, window
,
252 CWEventMask
|CWDontPropagate
, &attrib_set
);
255 /* create the ObClient struct, and populate it from the hints on the
257 self
= g_new0(ObClient
, 1);
258 self
->obwin
.type
= Window_Client
;
259 self
->window
= window
;
261 /* non-zero defaults */
262 self
->title_count
= 1;
263 self
->wmstate
= NormalState
;
265 self
->desktop
= screen_num_desktops
; /* always an invalid value */
267 client_get_all(self
);
268 client_restore_session_state(self
);
270 sn_app_started(self
->class);
272 client_change_state(self
);
274 /* remove the client's border (and adjust re gravity) */
275 client_toggle_border(self
, FALSE
);
277 /* specify that if we exit, the window should not be destroyed and should
278 be reparented back to root automatically */
279 XChangeSaveSet(ob_display
, window
, SetModeInsert
);
281 /* create the decoration frame for the client window */
282 self
->frame
= frame_new();
284 frame_grab_client(self
->frame
, self
);
288 client_apply_startup_state(self
);
290 /* update the focus lists */
291 focus_order_add_new(self
);
293 stacking_add(CLIENT_AS_WINDOW(self
));
294 client_restore_session_stacking(self
);
296 /* focus the new window? */
297 if (ob_state() != OB_STATE_STARTING
&&
298 (config_focus_new
|| client_search_focus_parent(self
)) &&
299 /* note the check against Type_Normal/Dialog, not client_normal(self),
300 which would also include other types. in this case we want more
301 strict rules for focus */
302 (self
->type
== OB_CLIENT_TYPE_NORMAL
||
303 self
->type
== OB_CLIENT_TYPE_DIALOG
))
307 if (self
->desktop
!= screen_desktop
) {
308 /* activate the window */
311 gboolean group_foc
= FALSE
;
316 for (it
= self
->group
->members
; it
; it
= it
->next
)
318 if (client_focused(it
->data
))
326 (!self
->transient_for
&& (!self
->group
||
327 !self
->group
->members
->next
))) ||
328 client_search_focus_tree_full(self
) ||
330 !client_normal(focus_client
))
332 /* activate the window */
339 if (ob_state() == OB_STATE_RUNNING
) {
340 int x
= self
->area
.x
, ox
= x
;
341 int y
= self
->area
.y
, oy
= y
;
343 place_client(self
, &x
, &y
);
345 /* make sure the window is visible */
346 client_find_onscreen(self
, &x
, &y
,
347 self
->frame
->area
.width
,
348 self
->frame
->area
.height
,
349 client_normal(self
));
351 if (x
!= ox
|| y
!= oy
)
352 client_move(self
, x
, y
);
355 client_showhide(self
);
357 /* use client_focus instead of client_activate cuz client_activate does
358 stuff like switch desktops etc and I'm not interested in all that when
359 a window maps since its not based on an action from the user like
360 clicking a window to activate is. so keep the new window out of the way
363 /* if using focus_delay, stop the timer now so that focus doesn't go
365 event_halt_focus_delay();
368 /* since focus can change the stacking orders, if we focus the window
369 then the standard raise it gets is not enough, we need to queue one
370 for after the focus change takes place */
374 /* client_activate does this but we aret using it so we have to do it
376 if (screen_showing_desktop
)
377 screen_show_desktop(FALSE
);
379 /* add to client list/map */
380 client_list
= g_list_append(client_list
, self
);
381 g_hash_table_insert(window_map
, &self
->window
, self
);
383 /* this has to happen after we're in the client_list */
384 screen_update_areas();
386 /* update the list hints */
389 keyboard_grab_for_client(self
, TRUE
);
390 mouse_grab_for_client(self
, TRUE
);
392 ob_debug("Managed window 0x%lx (%s)\n", window
, self
->class);
395 void client_unmanage_all()
397 while (client_list
!= NULL
)
398 client_unmanage(client_list
->data
);
401 void client_unmanage(ObClient
*self
)
406 ob_debug("Unmanaging window: %lx (%s)\n", self
->window
, self
->class);
408 g_assert(self
!= NULL
);
410 keyboard_grab_for_client(self
, FALSE
);
411 mouse_grab_for_client(self
, FALSE
);
413 /* remove the window from our save set */
414 XChangeSaveSet(ob_display
, self
->window
, SetModeDelete
);
416 /* we dont want events no more */
417 XSelectInput(ob_display
, self
->window
, NoEventMask
);
419 frame_hide(self
->frame
);
421 client_list
= g_list_remove(client_list
, self
);
422 stacking_remove(self
);
423 g_hash_table_remove(window_map
, &self
->window
);
425 /* update the focus lists */
426 focus_order_remove(self
);
428 /* once the client is out of the list, update the struts to remove it's
430 screen_update_areas();
432 for (it
= client_destructors
; it
; it
= g_slist_next(it
)) {
433 Destructor
*d
= it
->data
;
434 d
->func(self
, d
->data
);
437 if (focus_client
== self
) {
440 /* focus the last focused window on the desktop, and ignore enter
441 events from the unmap so it doesnt mess with the focus */
442 while (XCheckTypedEvent(ob_display
, EnterNotify
, &e
));
443 /* remove these flags so we don't end up getting focused in the
445 self
->can_focus
= FALSE
;
446 self
->focus_notify
= FALSE
;
448 client_unfocus(self
);
451 /* tell our parent(s) that we're gone */
452 if (self
->transient_for
== OB_TRAN_GROUP
) { /* transient of group */
455 for (it
= self
->group
->members
; it
; it
= it
->next
)
456 if (it
->data
!= self
)
457 ((ObClient
*)it
->data
)->transients
=
458 g_slist_remove(((ObClient
*)it
->data
)->transients
, self
);
459 } else if (self
->transient_for
) { /* transient of window */
460 self
->transient_for
->transients
=
461 g_slist_remove(self
->transient_for
->transients
, self
);
464 /* tell our transients that we're gone */
465 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
) {
466 if (((ObClient
*)it
->data
)->transient_for
!= OB_TRAN_GROUP
) {
467 ((ObClient
*)it
->data
)->transient_for
= NULL
;
468 client_calc_layer(it
->data
);
472 /* remove from its group */
474 group_remove(self
->group
, self
);
478 /* give the client its border back */
479 client_toggle_border(self
, TRUE
);
481 /* reparent the window out of the frame, and free the frame */
482 frame_release_client(self
->frame
, self
);
485 if (ob_state() != OB_STATE_EXITING
) {
486 /* these values should not be persisted across a window
488 PROP_ERASE(self
->window
, net_wm_desktop
);
489 PROP_ERASE(self
->window
, net_wm_state
);
490 PROP_ERASE(self
->window
, wm_state
);
492 /* if we're left in an iconic state, the client wont be mapped. this is
493 bad, since we will no longer be managing the window on restart */
495 XMapWindow(ob_display
, self
->window
);
499 ob_debug("Unmanaged window 0x%lx\n", self
->window
);
501 /* free all data allocated in the client struct */
502 g_slist_free(self
->transients
);
503 for (j
= 0; j
< self
->nicons
; ++j
)
504 g_free(self
->icons
[j
].data
);
505 if (self
->nicons
> 0)
508 g_free(self
->icon_title
);
512 g_free(self
->sm_client_id
);
515 /* update the list hints */
519 static void client_urgent_notify(ObClient
*self
)
522 frame_flash_start(self
->frame
);
524 frame_flash_stop(self
->frame
);
527 static void client_restore_session_state(ObClient
*self
)
531 if (!(it
= session_state_find(self
)))
534 self
->session
= it
->data
;
536 RECT_SET_POINT(self
->area
, self
->session
->x
, self
->session
->y
);
537 self
->positioned
= TRUE
;
538 if (self
->session
->w
> 0)
539 self
->area
.width
= self
->session
->w
;
540 if (self
->session
->h
> 0)
541 self
->area
.height
= self
->session
->h
;
542 XResizeWindow(ob_display
, self
->window
,
543 self
->area
.width
, self
->area
.height
);
545 self
->desktop
= (self
->session
->desktop
== DESKTOP_ALL
?
546 self
->session
->desktop
:
547 MIN(screen_num_desktops
- 1, self
->session
->desktop
));
548 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, self
->desktop
);
550 self
->shaded
= self
->session
->shaded
;
551 self
->iconic
= self
->session
->iconic
;
552 self
->skip_pager
= self
->session
->skip_pager
;
553 self
->skip_taskbar
= self
->session
->skip_taskbar
;
554 self
->fullscreen
= self
->session
->fullscreen
;
555 self
->above
= self
->session
->above
;
556 self
->below
= self
->session
->below
;
557 self
->max_horz
= self
->session
->max_horz
;
558 self
->max_vert
= self
->session
->max_vert
;
561 static void client_restore_session_stacking(ObClient
*self
)
565 if (!self
->session
) return;
567 it
= g_list_find(session_saved_state
, self
->session
);
568 for (it
= g_list_previous(it
); it
; it
= g_list_previous(it
)) {
571 for (cit
= client_list
; cit
; cit
= g_list_next(cit
))
572 if (session_state_cmp(it
->data
, cit
->data
))
575 client_calc_layer(self
);
576 stacking_below(CLIENT_AS_WINDOW(self
),
577 CLIENT_AS_WINDOW(cit
->data
));
583 void client_move_onscreen(ObClient
*self
, gboolean rude
)
585 int x
= self
->area
.x
;
586 int y
= self
->area
.y
;
587 if (client_find_onscreen(self
, &x
, &y
,
588 self
->frame
->area
.width
,
589 self
->frame
->area
.height
, rude
)) {
590 client_move(self
, x
, y
);
594 gboolean
client_find_onscreen(ObClient
*self
, int *x
, int *y
, int w
, int h
,
598 int ox
= *x
, oy
= *y
;
600 frame_client_gravity(self
->frame
, x
, y
); /* get where the frame
603 /* XXX watch for xinerama dead areas */
605 a
= screen_area(self
->desktop
);
606 if (client_normal(self
)) {
607 if (!self
->strut
.right
&& *x
>= a
->x
+ a
->width
- 1)
608 *x
= a
->x
+ a
->width
- self
->frame
->area
.width
;
609 if (!self
->strut
.bottom
&& *y
>= a
->y
+ a
->height
- 1)
610 *y
= a
->y
+ a
->height
- self
->frame
->area
.height
;
611 if (!self
->strut
.left
&& *x
+ self
->frame
->area
.width
- 1 < a
->x
)
613 if (!self
->strut
.top
&& *y
+ self
->frame
->area
.height
- 1 < a
->y
)
618 /* this is my MOZILLA BITCHSLAP. oh ya it fucking feels good.
619 Java can suck it too. */
621 /* dont let windows map/move into the strut unless they
622 are bigger than the available area */
624 if (!self
->strut
.left
&& *x
< a
->x
) *x
= a
->x
;
625 if (!self
->strut
.right
&& *x
+ w
> a
->x
+ a
->width
)
626 *x
= a
->x
+ a
->width
- w
;
628 if (h
<= a
->height
) {
629 if (!self
->strut
.top
&& *y
< a
->y
) *y
= a
->y
;
630 if (!self
->strut
.bottom
&& *y
+ h
> a
->y
+ a
->height
)
631 *y
= a
->y
+ a
->height
- h
;
635 frame_frame_gravity(self
->frame
, x
, y
); /* get where the client
638 return ox
!= *x
|| oy
!= *y
;
641 static void client_toggle_border(ObClient
*self
, gboolean show
)
643 /* adjust our idea of where the client is, based on its border. When the
644 border is removed, the client should now be considered to be in a
646 when re-adding the border to the client, the same operation needs to be
648 int oldx
= self
->area
.x
, oldy
= self
->area
.y
;
649 int x
= oldx
, y
= oldy
;
650 switch(self
->gravity
) {
652 case NorthWestGravity
:
654 case SouthWestGravity
:
656 case NorthEastGravity
:
658 case SouthEastGravity
:
659 if (show
) x
-= self
->border_width
* 2;
660 else x
+= self
->border_width
* 2;
667 if (show
) x
-= self
->border_width
;
668 else x
+= self
->border_width
;
671 switch(self
->gravity
) {
673 case NorthWestGravity
:
675 case NorthEastGravity
:
677 case SouthWestGravity
:
679 case SouthEastGravity
:
680 if (show
) y
-= self
->border_width
* 2;
681 else y
+= self
->border_width
* 2;
688 if (show
) y
-= self
->border_width
;
689 else y
+= self
->border_width
;
696 XSetWindowBorderWidth(ob_display
, self
->window
, self
->border_width
);
698 /* move the client so it is back it the right spot _with_ its
700 if (x
!= oldx
|| y
!= oldy
)
701 XMoveWindow(ob_display
, self
->window
, x
, y
);
703 XSetWindowBorderWidth(ob_display
, self
->window
, 0);
707 static void client_get_all(ObClient
*self
)
709 client_get_area(self
);
710 client_update_transient_for(self
);
711 client_update_wmhints(self
);
712 client_get_startup_id(self
);
713 client_get_desktop(self
);
714 client_get_state(self
);
715 client_get_shaped(self
);
717 client_get_mwm_hints(self
);
718 client_get_type(self
);/* this can change the mwmhints for special cases */
721 /* a couple type-based defaults for new windows */
723 /* this makes sure that these windows appear on all desktops */
724 if (self
->type
== OB_CLIENT_TYPE_DESKTOP
)
725 self
->desktop
= DESKTOP_ALL
;
727 /* dock windows default to ABOVE */
728 if (self
->type
== OB_CLIENT_TYPE_DOCK
&& !self
->below
)
732 client_update_protocols(self
);
734 client_get_gravity(self
); /* get the attribute gravity */
735 client_update_normal_hints(self
); /* this may override the attribute
738 /* got the type, the mwmhints, the protocols, and the normal hints
739 (min/max sizes), so we're ready to set up the decorations/functions */
740 client_setup_decor_and_functions(self
);
742 client_update_title(self
);
743 client_update_class(self
);
744 client_update_sm_client_id(self
);
745 client_update_strut(self
);
746 client_update_icons(self
);
749 static void client_get_startup_id(ObClient
*self
)
751 if (!(PROP_GETS(self
->window
, net_startup_id
, utf8
, &self
->startup_id
)))
753 PROP_GETS(self
->group
->leader
,
754 net_startup_id
, utf8
, &self
->startup_id
);
757 static void client_get_area(ObClient
*self
)
759 XWindowAttributes wattrib
;
762 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
763 g_assert(ret
!= BadWindow
);
765 RECT_SET(self
->area
, wattrib
.x
, wattrib
.y
, wattrib
.width
, wattrib
.height
);
766 self
->border_width
= wattrib
.border_width
;
769 static void client_get_desktop(ObClient
*self
)
771 guint32 d
= screen_num_desktops
; /* an always-invalid value */
773 if (PROP_GET32(self
->window
, net_wm_desktop
, cardinal
, &d
)) {
774 if (d
>= screen_num_desktops
&& d
!= DESKTOP_ALL
)
775 self
->desktop
= screen_num_desktops
- 1;
779 gboolean trdesk
= FALSE
;
781 if (self
->transient_for
) {
782 if (self
->transient_for
!= OB_TRAN_GROUP
) {
783 self
->desktop
= self
->transient_for
->desktop
;
788 for (it
= self
->group
->members
; it
; it
= it
->next
)
789 if (it
->data
!= self
&&
790 !((ObClient
*)it
->data
)->transient_for
) {
791 self
->desktop
= ((ObClient
*)it
->data
)->desktop
;
798 /* try get from the startup-notification protocol */
799 if (sn_get_desktop(self
->startup_id
, &self
->desktop
)) {
800 if (self
->desktop
>= screen_num_desktops
&&
801 self
->desktop
!= DESKTOP_ALL
)
802 self
->desktop
= screen_num_desktops
- 1;
804 /* defaults to the current desktop */
805 self
->desktop
= screen_desktop
;
808 if (self
->desktop
!= d
) {
809 /* set the desktop hint, to make sure that it always exists */
810 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, self
->desktop
);
814 static void client_get_state(ObClient
*self
)
819 if (PROP_GETA32(self
->window
, net_wm_state
, atom
, &state
, &num
)) {
821 for (i
= 0; i
< num
; ++i
) {
822 if (state
[i
] == prop_atoms
.net_wm_state_modal
)
824 else if (state
[i
] == prop_atoms
.net_wm_state_shaded
)
826 else if (state
[i
] == prop_atoms
.net_wm_state_hidden
)
828 else if (state
[i
] == prop_atoms
.net_wm_state_skip_taskbar
)
829 self
->skip_taskbar
= TRUE
;
830 else if (state
[i
] == prop_atoms
.net_wm_state_skip_pager
)
831 self
->skip_pager
= TRUE
;
832 else if (state
[i
] == prop_atoms
.net_wm_state_fullscreen
)
833 self
->fullscreen
= TRUE
;
834 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_vert
)
835 self
->max_vert
= TRUE
;
836 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_horz
)
837 self
->max_horz
= TRUE
;
838 else if (state
[i
] == prop_atoms
.net_wm_state_above
)
840 else if (state
[i
] == prop_atoms
.net_wm_state_below
)
842 else if (state
[i
] == prop_atoms
.ob_wm_state_undecorated
)
843 self
->undecorated
= TRUE
;
850 static void client_get_shaped(ObClient
*self
)
852 self
->shaped
= FALSE
;
854 if (extensions_shape
) {
859 XShapeSelectInput(ob_display
, self
->window
, ShapeNotifyMask
);
861 XShapeQueryExtents(ob_display
, self
->window
, &s
, &foo
,
862 &foo
, &ufoo
, &ufoo
, &foo
, &foo
, &foo
, &ufoo
,
864 self
->shaped
= (s
!= 0);
869 void client_update_transient_for(ObClient
*self
)
872 ObClient
*target
= NULL
;
874 if (XGetTransientForHint(ob_display
, self
->window
, &t
)) {
875 self
->transient
= TRUE
;
876 if (t
!= self
->window
) { /* cant be transient to itself! */
877 target
= g_hash_table_lookup(window_map
, &t
);
878 /* if this happens then we need to check for it*/
879 g_assert(target
!= self
);
880 if (target
&& !WINDOW_IS_CLIENT(target
)) {
881 /* this can happen when a dialog is a child of
882 a dockapp, for example */
886 if (!target
&& self
->group
) {
887 /* not transient to a client, see if it is transient for a
889 if (t
== self
->group
->leader
||
891 t
== RootWindow(ob_display
, ob_screen
))
893 /* window is a transient for its group! */
894 target
= OB_TRAN_GROUP
;
899 self
->transient
= FALSE
;
901 /* if anything has changed... */
902 if (target
!= self
->transient_for
) {
903 if (self
->transient_for
== OB_TRAN_GROUP
) { /* transient of group */
906 /* remove from old parents */
907 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
908 ObClient
*c
= it
->data
;
909 if (c
!= self
&& !c
->transient_for
)
910 c
->transients
= g_slist_remove(c
->transients
, self
);
912 } else if (self
->transient_for
!= NULL
) { /* transient of window */
913 /* remove from old parent */
914 self
->transient_for
->transients
=
915 g_slist_remove(self
->transient_for
->transients
, self
);
917 self
->transient_for
= target
;
918 if (self
->transient_for
== OB_TRAN_GROUP
) { /* transient of group */
921 /* add to new parents */
922 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
923 ObClient
*c
= it
->data
;
924 if (c
!= self
&& !c
->transient_for
)
925 c
->transients
= g_slist_append(c
->transients
, self
);
928 /* remove all transients which are in the group, that causes
929 circlular pointer hell of doom */
930 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
932 for (sit
= self
->transients
; sit
; sit
= next
) {
933 next
= g_slist_next(sit
);
934 if (sit
->data
== it
->data
)
936 g_slist_delete_link(self
->transients
, sit
);
939 } else if (self
->transient_for
!= NULL
) { /* transient of window */
940 /* add to new parent */
941 self
->transient_for
->transients
=
942 g_slist_append(self
->transient_for
->transients
, self
);
947 static void client_get_mwm_hints(ObClient
*self
)
952 self
->mwmhints
.flags
= 0; /* default to none */
954 if (PROP_GETA32(self
->window
, motif_wm_hints
, motif_wm_hints
,
956 if (num
>= OB_MWM_ELEMENTS
) {
957 self
->mwmhints
.flags
= hints
[0];
958 self
->mwmhints
.functions
= hints
[1];
959 self
->mwmhints
.decorations
= hints
[2];
965 void client_get_type(ObClient
*self
)
972 if (PROP_GETA32(self
->window
, net_wm_window_type
, atom
, &val
, &num
)) {
973 /* use the first value that we know about in the array */
974 for (i
= 0; i
< num
; ++i
) {
975 if (val
[i
] == prop_atoms
.net_wm_window_type_desktop
)
976 self
->type
= OB_CLIENT_TYPE_DESKTOP
;
977 else if (val
[i
] == prop_atoms
.net_wm_window_type_dock
)
978 self
->type
= OB_CLIENT_TYPE_DOCK
;
979 else if (val
[i
] == prop_atoms
.net_wm_window_type_toolbar
)
980 self
->type
= OB_CLIENT_TYPE_TOOLBAR
;
981 else if (val
[i
] == prop_atoms
.net_wm_window_type_menu
)
982 self
->type
= OB_CLIENT_TYPE_MENU
;
983 else if (val
[i
] == prop_atoms
.net_wm_window_type_utility
)
984 self
->type
= OB_CLIENT_TYPE_UTILITY
;
985 else if (val
[i
] == prop_atoms
.net_wm_window_type_splash
)
986 self
->type
= OB_CLIENT_TYPE_SPLASH
;
987 else if (val
[i
] == prop_atoms
.net_wm_window_type_dialog
)
988 self
->type
= OB_CLIENT_TYPE_DIALOG
;
989 else if (val
[i
] == prop_atoms
.net_wm_window_type_normal
)
990 self
->type
= OB_CLIENT_TYPE_NORMAL
;
991 else if (val
[i
] == prop_atoms
.kde_net_wm_window_type_override
) {
992 /* prevent this window from getting any decor or
994 self
->mwmhints
.flags
&= (OB_MWM_FLAG_FUNCTIONS
|
995 OB_MWM_FLAG_DECORATIONS
);
996 self
->mwmhints
.decorations
= 0;
997 self
->mwmhints
.functions
= 0;
999 if (self
->type
!= (ObClientType
) -1)
1000 break; /* grab the first legit type */
1005 if (self
->type
== (ObClientType
) -1) {
1006 /*the window type hint was not set, which means we either classify
1007 ourself as a normal window or a dialog, depending on if we are a
1009 if (self
->transient
)
1010 self
->type
= OB_CLIENT_TYPE_DIALOG
;
1012 self
->type
= OB_CLIENT_TYPE_NORMAL
;
1016 void client_update_protocols(ObClient
*self
)
1019 guint num_return
, i
;
1021 self
->focus_notify
= FALSE
;
1022 self
->delete_window
= FALSE
;
1024 if (PROP_GETA32(self
->window
, wm_protocols
, atom
, &proto
, &num_return
)) {
1025 for (i
= 0; i
< num_return
; ++i
) {
1026 if (proto
[i
] == prop_atoms
.wm_delete_window
) {
1027 /* this means we can request the window to close */
1028 self
->delete_window
= TRUE
;
1029 } else if (proto
[i
] == prop_atoms
.wm_take_focus
)
1030 /* if this protocol is requested, then the window will be
1031 notified whenever we want it to receive focus */
1032 self
->focus_notify
= TRUE
;
1038 static void client_get_gravity(ObClient
*self
)
1040 XWindowAttributes wattrib
;
1043 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
1044 g_assert(ret
!= BadWindow
);
1045 self
->gravity
= wattrib
.win_gravity
;
1048 void client_update_normal_hints(ObClient
*self
)
1052 int oldgravity
= self
->gravity
;
1055 self
->min_ratio
= 0.0f
;
1056 self
->max_ratio
= 0.0f
;
1057 SIZE_SET(self
->size_inc
, 1, 1);
1058 SIZE_SET(self
->base_size
, 0, 0);
1059 SIZE_SET(self
->min_size
, 0, 0);
1060 SIZE_SET(self
->max_size
, G_MAXINT
, G_MAXINT
);
1062 /* get the hints from the window */
1063 if (XGetWMNormalHints(ob_display
, self
->window
, &size
, &ret
)) {
1064 self
->positioned
= !!(size
.flags
& (PPosition
|USPosition
));
1066 if (size
.flags
& PWinGravity
) {
1067 self
->gravity
= size
.win_gravity
;
1069 /* if the client has a frame, i.e. has already been mapped and
1070 is changing its gravity */
1071 if (self
->frame
&& self
->gravity
!= oldgravity
) {
1072 /* move our idea of the client's position based on its new
1074 self
->area
.x
= self
->frame
->area
.x
;
1075 self
->area
.y
= self
->frame
->area
.y
;
1076 frame_frame_gravity(self
->frame
, &self
->area
.x
, &self
->area
.y
);
1080 if (size
.flags
& PAspect
) {
1081 if (size
.min_aspect
.y
)
1082 self
->min_ratio
= (float)size
.min_aspect
.x
/ size
.min_aspect
.y
;
1083 if (size
.max_aspect
.y
)
1084 self
->max_ratio
= (float)size
.max_aspect
.x
/ size
.max_aspect
.y
;
1087 if (size
.flags
& PMinSize
)
1088 SIZE_SET(self
->min_size
, size
.min_width
, size
.min_height
);
1090 if (size
.flags
& PMaxSize
)
1091 SIZE_SET(self
->max_size
, size
.max_width
, size
.max_height
);
1093 if (size
.flags
& PBaseSize
)
1094 SIZE_SET(self
->base_size
, size
.base_width
, size
.base_height
);
1096 if (size
.flags
& PResizeInc
)
1097 SIZE_SET(self
->size_inc
, size
.width_inc
, size
.height_inc
);
1101 void client_setup_decor_and_functions(ObClient
*self
)
1103 /* start with everything (cept fullscreen) */
1105 (OB_FRAME_DECOR_TITLEBAR
|
1106 (ob_rr_theme
->show_handle
? OB_FRAME_DECOR_HANDLE
: 0) |
1107 OB_FRAME_DECOR_GRIPS
|
1108 OB_FRAME_DECOR_BORDER
|
1109 OB_FRAME_DECOR_ICON
|
1110 OB_FRAME_DECOR_ALLDESKTOPS
|
1111 OB_FRAME_DECOR_ICONIFY
|
1112 OB_FRAME_DECOR_MAXIMIZE
|
1113 OB_FRAME_DECOR_SHADE
|
1114 OB_FRAME_DECOR_CLOSE
);
1116 (OB_CLIENT_FUNC_RESIZE
|
1117 OB_CLIENT_FUNC_MOVE
|
1118 OB_CLIENT_FUNC_ICONIFY
|
1119 OB_CLIENT_FUNC_MAXIMIZE
|
1120 OB_CLIENT_FUNC_SHADE
|
1121 OB_CLIENT_FUNC_CLOSE
);
1123 if (!(self
->min_size
.width
< self
->max_size
.width
||
1124 self
->min_size
.height
< self
->max_size
.height
))
1125 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
1127 switch (self
->type
) {
1128 case OB_CLIENT_TYPE_NORMAL
:
1129 /* normal windows retain all of the possible decorations and
1130 functionality, and are the only windows that you can fullscreen */
1131 self
->functions
|= OB_CLIENT_FUNC_FULLSCREEN
;
1134 case OB_CLIENT_TYPE_DIALOG
:
1135 case OB_CLIENT_TYPE_UTILITY
:
1136 /* these windows cannot be maximized */
1137 self
->functions
&= ~OB_CLIENT_FUNC_MAXIMIZE
;
1140 case OB_CLIENT_TYPE_MENU
:
1141 case OB_CLIENT_TYPE_TOOLBAR
:
1142 /* these windows get less functionality */
1143 self
->functions
&= ~(OB_CLIENT_FUNC_ICONIFY
| OB_CLIENT_FUNC_RESIZE
);
1146 case OB_CLIENT_TYPE_DESKTOP
:
1147 case OB_CLIENT_TYPE_DOCK
:
1148 case OB_CLIENT_TYPE_SPLASH
:
1149 /* none of these windows are manipulated by the window manager */
1150 self
->decorations
= 0;
1151 self
->functions
= 0;
1155 /* Mwm Hints are applied subtractively to what has already been chosen for
1156 decor and functionality */
1157 if (self
->mwmhints
.flags
& OB_MWM_FLAG_DECORATIONS
) {
1158 if (! (self
->mwmhints
.decorations
& OB_MWM_DECOR_ALL
)) {
1159 if (! ((self
->mwmhints
.decorations
& OB_MWM_DECOR_HANDLE
) ||
1160 (self
->mwmhints
.decorations
& OB_MWM_DECOR_TITLE
)))
1161 /* if the mwm hints request no handle or title, then all
1162 decorations are disabled */
1163 self
->decorations
= 0;
1167 if (self
->mwmhints
.flags
& OB_MWM_FLAG_FUNCTIONS
) {
1168 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_ALL
)) {
1169 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_RESIZE
))
1170 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
1171 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_MOVE
))
1172 self
->functions
&= ~OB_CLIENT_FUNC_MOVE
;
1173 /* dont let mwm hints kill any buttons
1174 if (! (self->mwmhints.functions & OB_MWM_FUNC_ICONIFY))
1175 self->functions &= ~OB_CLIENT_FUNC_ICONIFY;
1176 if (! (self->mwmhints.functions & OB_MWM_FUNC_MAXIMIZE))
1177 self->functions &= ~OB_CLIENT_FUNC_MAXIMIZE;
1179 /* dont let mwm hints kill the close button
1180 if (! (self->mwmhints.functions & MwmFunc_Close))
1181 self->functions &= ~OB_CLIENT_FUNC_CLOSE; */
1185 if (!(self
->functions
& OB_CLIENT_FUNC_SHADE
))
1186 self
->decorations
&= ~OB_FRAME_DECOR_SHADE
;
1187 if (!(self
->functions
& OB_CLIENT_FUNC_ICONIFY
))
1188 self
->decorations
&= ~OB_FRAME_DECOR_ICONIFY
;
1189 if (!(self
->functions
& OB_CLIENT_FUNC_RESIZE
))
1190 self
->decorations
&= ~OB_FRAME_DECOR_GRIPS
;
1192 /* can't maximize without moving/resizing */
1193 if (!((self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) &&
1194 (self
->functions
& OB_CLIENT_FUNC_MOVE
) &&
1195 (self
->functions
& OB_CLIENT_FUNC_RESIZE
))) {
1196 self
->functions
&= ~OB_CLIENT_FUNC_MAXIMIZE
;
1197 self
->decorations
&= ~OB_FRAME_DECOR_MAXIMIZE
;
1200 /* kill the handle on fully maxed windows */
1201 if (self
->max_vert
&& self
->max_horz
)
1202 self
->decorations
&= ~OB_FRAME_DECOR_HANDLE
;
1204 /* finally, the user can have requested no decorations, which overrides
1205 everything (but doesnt give it a border if it doesnt have one) */
1206 if (self
->undecorated
)
1207 self
->decorations
&= OB_FRAME_DECOR_BORDER
;
1209 /* if we don't have a titlebar, then we cannot shade! */
1210 if (!(self
->decorations
& OB_FRAME_DECOR_TITLEBAR
))
1211 self
->functions
&= ~OB_CLIENT_FUNC_SHADE
;
1213 /* now we need to check against rules for the client's current state */
1214 if (self
->fullscreen
) {
1215 self
->functions
&= (OB_CLIENT_FUNC_CLOSE
|
1216 OB_CLIENT_FUNC_FULLSCREEN
|
1217 OB_CLIENT_FUNC_ICONIFY
);
1218 self
->decorations
= 0;
1221 client_change_allowed_actions(self
);
1224 /* adjust the client's decorations, etc. */
1225 client_reconfigure(self
);
1229 static void client_change_allowed_actions(ObClient
*self
)
1234 /* desktop windows are kept on all desktops */
1235 if (self
->type
!= OB_CLIENT_TYPE_DESKTOP
)
1236 actions
[num
++] = prop_atoms
.net_wm_action_change_desktop
;
1238 if (self
->functions
& OB_CLIENT_FUNC_SHADE
)
1239 actions
[num
++] = prop_atoms
.net_wm_action_shade
;
1240 if (self
->functions
& OB_CLIENT_FUNC_CLOSE
)
1241 actions
[num
++] = prop_atoms
.net_wm_action_close
;
1242 if (self
->functions
& OB_CLIENT_FUNC_MOVE
)
1243 actions
[num
++] = prop_atoms
.net_wm_action_move
;
1244 if (self
->functions
& OB_CLIENT_FUNC_ICONIFY
)
1245 actions
[num
++] = prop_atoms
.net_wm_action_minimize
;
1246 if (self
->functions
& OB_CLIENT_FUNC_RESIZE
)
1247 actions
[num
++] = prop_atoms
.net_wm_action_resize
;
1248 if (self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
)
1249 actions
[num
++] = prop_atoms
.net_wm_action_fullscreen
;
1250 if (self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) {
1251 actions
[num
++] = prop_atoms
.net_wm_action_maximize_horz
;
1252 actions
[num
++] = prop_atoms
.net_wm_action_maximize_vert
;
1255 PROP_SETA32(self
->window
, net_wm_allowed_actions
, atom
, actions
, num
);
1257 /* make sure the window isn't breaking any rules now */
1259 if (!(self
->functions
& OB_CLIENT_FUNC_SHADE
) && self
->shaded
) {
1260 if (self
->frame
) client_shade(self
, FALSE
);
1261 else self
->shaded
= FALSE
;
1263 if (!(self
->functions
& OB_CLIENT_FUNC_ICONIFY
) && self
->iconic
) {
1264 if (self
->frame
) client_iconify(self
, FALSE
, TRUE
);
1265 else self
->iconic
= FALSE
;
1267 if (!(self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
) && self
->fullscreen
) {
1268 if (self
->frame
) client_fullscreen(self
, FALSE
, TRUE
);
1269 else self
->fullscreen
= FALSE
;
1271 if (!(self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) && (self
->max_horz
||
1273 if (self
->frame
) client_maximize(self
, FALSE
, 0, TRUE
);
1274 else self
->max_vert
= self
->max_horz
= FALSE
;
1278 void client_reconfigure(ObClient
*self
)
1280 /* by making this pass FALSE for user, we avoid the emacs event storm where
1281 every configurenotify causes an update in its normal hints, i think this
1282 is generally what we want anyways... */
1283 client_configure(self
, OB_CORNER_TOPLEFT
, self
->area
.x
, self
->area
.y
,
1284 self
->area
.width
, self
->area
.height
, FALSE
, TRUE
);
1287 void client_update_wmhints(ObClient
*self
)
1290 gboolean ur
= FALSE
;
1293 /* assume a window takes input if it doesnt specify */
1294 self
->can_focus
= TRUE
;
1296 if ((hints
= XGetWMHints(ob_display
, self
->window
)) != NULL
) {
1297 if (hints
->flags
& InputHint
)
1298 self
->can_focus
= hints
->input
;
1300 /* only do this when first managing the window *AND* when we aren't
1302 if (ob_state() != OB_STATE_STARTING
&& self
->frame
== NULL
)
1303 if (hints
->flags
& StateHint
)
1304 self
->iconic
= hints
->initial_state
== IconicState
;
1306 if (hints
->flags
& XUrgencyHint
)
1309 if (!(hints
->flags
& WindowGroupHint
))
1310 hints
->window_group
= None
;
1312 /* did the group state change? */
1313 if (hints
->window_group
!=
1314 (self
->group
? self
->group
->leader
: None
)) {
1315 /* remove from the old group if there was one */
1316 if (self
->group
!= NULL
) {
1317 /* remove transients of the group */
1318 for (it
= self
->group
->members
; it
; it
= it
->next
)
1319 self
->transients
= g_slist_remove(self
->transients
,
1322 /* remove myself from parents in the group */
1323 if (self
->transient_for
== OB_TRAN_GROUP
) {
1324 for (it
= self
->group
->members
; it
; it
= it
->next
) {
1325 ObClient
*c
= it
->data
;
1327 if (c
!= self
&& !c
->transient_for
)
1328 c
->transients
= g_slist_remove(c
->transients
,
1333 group_remove(self
->group
, self
);
1336 if (hints
->window_group
!= None
) {
1337 self
->group
= group_add(hints
->window_group
, self
);
1339 /* i can only have transients from the group if i am not
1341 if (!self
->transient_for
) {
1342 /* add other transients of the group that are already
1344 for (it
= self
->group
->members
; it
; it
= it
->next
) {
1345 ObClient
*c
= it
->data
;
1346 if (c
!= self
&& c
->transient_for
== OB_TRAN_GROUP
)
1348 g_slist_append(self
->transients
, c
);
1353 /* because the self->transient flag wont change from this call,
1354 we don't need to update the window's type and such, only its
1355 transient_for, and the transients lists of other windows in
1356 the group may be affected */
1357 client_update_transient_for(self
);
1360 /* the WM_HINTS can contain an icon */
1361 client_update_icons(self
);
1366 if (ur
!= self
->urgent
) {
1368 /* fire the urgent callback if we're mapped, otherwise, wait until
1369 after we're mapped */
1371 client_urgent_notify(self
);
1375 void client_update_title(ObClient
*self
)
1381 gboolean read_title
;
1384 old_title
= self
->title
;
1387 if (!PROP_GETS(self
->window
, net_wm_name
, utf8
, &data
))
1388 /* try old x stuff */
1389 if (!PROP_GETS(self
->window
, wm_name
, locale
, &data
))
1390 data
= g_strdup("Unnamed Window");
1392 /* did the title change? then reset the title_count */
1393 if (old_title
&& 0 != strncmp(old_title
, data
, strlen(data
)))
1394 self
->title_count
= 1;
1396 /* look for duplicates and append a number */
1398 for (it
= client_list
; it
; it
= it
->next
)
1399 if (it
->data
!= self
) {
1400 ObClient
*c
= it
->data
;
1401 if (0 == strncmp(c
->title
, data
, strlen(data
)))
1402 nums
|= 1 << c
->title_count
;
1404 /* find first free number */
1405 for (i
= 1; i
<= 32; ++i
)
1406 if (!(nums
& (1 << i
))) {
1407 if (self
->title_count
== 1 || i
== 1)
1408 self
->title_count
= i
;
1411 /* dont display the number for the first window */
1412 if (self
->title_count
> 1) {
1414 ndata
= g_strdup_printf("%s - [%u]", data
, self
->title_count
);
1419 PROP_SETS(self
->window
, net_wm_visible_name
, data
);
1424 frame_adjust_title(self
->frame
);
1428 /* update the icon title */
1430 g_free(self
->icon_title
);
1434 if (!PROP_GETS(self
->window
, net_wm_icon_name
, utf8
, &data
))
1435 /* try old x stuff */
1436 if (!PROP_GETS(self
->window
, wm_icon_name
, locale
, &data
)) {
1437 data
= g_strdup(self
->title
);
1441 /* append the title count, dont display the number for the first window */
1442 if (read_title
&& self
->title_count
> 1) {
1443 char *vdata
, *ndata
;
1444 ndata
= g_strdup_printf(" - [%u]", self
->title_count
);
1445 vdata
= g_strconcat(data
, ndata
, NULL
);
1451 PROP_SETS(self
->window
, net_wm_visible_icon_name
, data
);
1453 self
->icon_title
= data
;
1456 void client_update_class(ObClient
*self
)
1461 if (self
->name
) g_free(self
->name
);
1462 if (self
->class) g_free(self
->class);
1463 if (self
->role
) g_free(self
->role
);
1465 self
->name
= self
->class = self
->role
= NULL
;
1467 if (PROP_GETSS(self
->window
, wm_class
, locale
, &data
)) {
1469 self
->name
= g_strdup(data
[0]);
1471 self
->class = g_strdup(data
[1]);
1476 if (PROP_GETS(self
->window
, wm_window_role
, locale
, &s
))
1479 if (self
->name
== NULL
) self
->name
= g_strdup("");
1480 if (self
->class == NULL
) self
->class = g_strdup("");
1481 if (self
->role
== NULL
) self
->role
= g_strdup("");
1484 void client_update_strut(ObClient
*self
)
1488 gboolean got
= FALSE
;
1491 if (PROP_GETA32(self
->window
, net_wm_strut_partial
, cardinal
,
1495 STRUT_PARTIAL_SET(strut
,
1496 data
[0], data
[2], data
[1], data
[3],
1497 data
[4], data
[5], data
[8], data
[9],
1498 data
[6], data
[7], data
[10], data
[11]);
1504 PROP_GETA32(self
->window
, net_wm_strut
, cardinal
, &data
, &num
)) {
1507 STRUT_PARTIAL_SET(strut
,
1508 data
[0], data
[2], data
[1], data
[3],
1509 0, 0, 0, 0, 0, 0, 0, 0);
1515 STRUT_PARTIAL_SET(strut
, 0, 0, 0, 0,
1516 0, 0, 0, 0, 0, 0, 0, 0);
1518 if (!STRUT_EQUAL(strut
, self
->strut
)) {
1519 self
->strut
= strut
;
1521 /* updating here is pointless while we're being mapped cuz we're not in
1522 the client list yet */
1524 screen_update_areas();
1528 void client_update_icons(ObClient
*self
)
1534 for (i
= 0; i
< self
->nicons
; ++i
)
1535 g_free(self
->icons
[i
].data
);
1536 if (self
->nicons
> 0)
1537 g_free(self
->icons
);
1540 if (PROP_GETA32(self
->window
, net_wm_icon
, cardinal
, &data
, &num
)) {
1541 /* figure out how many valid icons are in here */
1543 while (num
- i
> 2) {
1547 if (i
> num
|| w
*h
== 0) break;
1551 self
->icons
= g_new(ObClientIcon
, self
->nicons
);
1553 /* store the icons */
1555 for (j
= 0; j
< self
->nicons
; ++j
) {
1558 w
= self
->icons
[j
].width
= data
[i
++];
1559 h
= self
->icons
[j
].height
= data
[i
++];
1561 if (w
*h
== 0) continue;
1563 self
->icons
[j
].data
= g_new(RrPixel32
, w
* h
);
1564 for (x
= 0, y
= 0, t
= 0; t
< w
* h
; ++t
, ++x
, ++i
) {
1569 self
->icons
[j
].data
[t
] =
1570 (((data
[i
] >> 24) & 0xff) << RrDefaultAlphaOffset
) +
1571 (((data
[i
] >> 16) & 0xff) << RrDefaultRedOffset
) +
1572 (((data
[i
] >> 8) & 0xff) << RrDefaultGreenOffset
) +
1573 (((data
[i
] >> 0) & 0xff) << RrDefaultBlueOffset
);
1579 } else if (PROP_GETA32(self
->window
, kwm_win_icon
,
1580 kwm_win_icon
, &data
, &num
)) {
1583 self
->icons
= g_new(ObClientIcon
, self
->nicons
);
1584 xerror_set_ignore(TRUE
);
1585 if (!RrPixmapToRGBA(ob_rr_inst
,
1587 &self
->icons
[self
->nicons
-1].width
,
1588 &self
->icons
[self
->nicons
-1].height
,
1589 &self
->icons
[self
->nicons
-1].data
)) {
1590 g_free(&self
->icons
[self
->nicons
-1]);
1593 xerror_set_ignore(FALSE
);
1599 if ((hints
= XGetWMHints(ob_display
, self
->window
))) {
1600 if (hints
->flags
& IconPixmapHint
) {
1602 self
->icons
= g_new(ObClientIcon
, self
->nicons
);
1603 xerror_set_ignore(TRUE
);
1604 if (!RrPixmapToRGBA(ob_rr_inst
,
1606 (hints
->flags
& IconMaskHint
?
1607 hints
->icon_mask
: None
),
1608 &self
->icons
[self
->nicons
-1].width
,
1609 &self
->icons
[self
->nicons
-1].height
,
1610 &self
->icons
[self
->nicons
-1].data
)){
1611 g_free(&self
->icons
[self
->nicons
-1]);
1614 xerror_set_ignore(FALSE
);
1621 frame_adjust_icon(self
->frame
);
1624 static void client_change_state(ObClient
*self
)
1627 guint32 netstate
[11];
1630 state
[0] = self
->wmstate
;
1632 PROP_SETA32(self
->window
, wm_state
, wm_state
, state
, 2);
1636 netstate
[num
++] = prop_atoms
.net_wm_state_modal
;
1638 netstate
[num
++] = prop_atoms
.net_wm_state_shaded
;
1640 netstate
[num
++] = prop_atoms
.net_wm_state_hidden
;
1641 if (self
->skip_taskbar
)
1642 netstate
[num
++] = prop_atoms
.net_wm_state_skip_taskbar
;
1643 if (self
->skip_pager
)
1644 netstate
[num
++] = prop_atoms
.net_wm_state_skip_pager
;
1645 if (self
->fullscreen
)
1646 netstate
[num
++] = prop_atoms
.net_wm_state_fullscreen
;
1648 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_vert
;
1650 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_horz
;
1652 netstate
[num
++] = prop_atoms
.net_wm_state_above
;
1654 netstate
[num
++] = prop_atoms
.net_wm_state_below
;
1655 if (self
->undecorated
)
1656 netstate
[num
++] = prop_atoms
.ob_wm_state_undecorated
;
1657 PROP_SETA32(self
->window
, net_wm_state
, atom
, netstate
, num
);
1659 client_calc_layer(self
);
1662 frame_adjust_state(self
->frame
);
1665 ObClient
*client_search_focus_tree(ObClient
*self
)
1670 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
) {
1671 if (client_focused(it
->data
)) return it
->data
;
1672 if ((ret
= client_search_focus_tree(it
->data
))) return ret
;
1677 ObClient
*client_search_focus_tree_full(ObClient
*self
)
1679 if (self
->transient_for
) {
1680 if (self
->transient_for
!= OB_TRAN_GROUP
) {
1681 return client_search_focus_tree_full(self
->transient_for
);
1684 gboolean recursed
= FALSE
;
1686 for (it
= self
->group
->members
; it
; it
= it
->next
)
1687 if (!((ObClient
*)it
->data
)->transient_for
) {
1689 if ((c
= client_search_focus_tree_full(it
->data
)))
1698 /* this function checks the whole tree, the client_search_focus_tree~
1699 does not, so we need to check this window */
1700 if (client_focused(self
))
1702 return client_search_focus_tree(self
);
1705 static ObStackingLayer
calc_layer(ObClient
*self
)
1709 if (self
->fullscreen
&&
1710 (client_focused(self
) || client_search_focus_tree(self
)))
1711 l
= OB_STACKING_LAYER_FULLSCREEN
;
1712 else if (self
->type
== OB_CLIENT_TYPE_DESKTOP
)
1713 l
= OB_STACKING_LAYER_DESKTOP
;
1714 else if (self
->type
== OB_CLIENT_TYPE_DOCK
) {
1715 if (self
->above
) l
= OB_STACKING_LAYER_DOCK_ABOVE
;
1716 else if (self
->below
) l
= OB_STACKING_LAYER_DOCK_BELOW
;
1717 else l
= OB_STACKING_LAYER_NORMAL
;
1719 else if (self
->above
) l
= OB_STACKING_LAYER_ABOVE
;
1720 else if (self
->below
) l
= OB_STACKING_LAYER_BELOW
;
1721 else l
= OB_STACKING_LAYER_NORMAL
;
1726 static void client_calc_layer_recursive(ObClient
*self
, ObClient
*orig
,
1727 ObStackingLayer l
, gboolean raised
)
1729 ObStackingLayer old
, own
;
1733 own
= calc_layer(self
);
1734 self
->layer
= l
> own
? l
: own
;
1736 for (it
= self
->transients
; it
; it
= it
->next
)
1737 client_calc_layer_recursive(it
->data
, orig
,
1738 l
, raised
? raised
: l
!= old
);
1740 if (!raised
&& l
!= old
)
1741 if (orig
->frame
) { /* only restack if the original window is managed */
1742 /* XXX add_non_intrusive ever? */
1743 stacking_remove(CLIENT_AS_WINDOW(self
));
1744 stacking_add(CLIENT_AS_WINDOW(self
));
1748 void client_calc_layer(ObClient
*self
)
1755 /* transients take on the layer of their parents */
1756 self
= client_search_top_transient(self
);
1758 l
= calc_layer(self
);
1760 client_calc_layer_recursive(self
, orig
, l
, FALSE
);
1763 gboolean
client_should_show(ObClient
*self
)
1765 if (self
->iconic
) return FALSE
;
1766 else if (!(self
->desktop
== screen_desktop
||
1767 self
->desktop
== DESKTOP_ALL
)) return FALSE
;
1768 else if (client_normal(self
) && screen_showing_desktop
) return FALSE
;
1773 static void client_showhide(ObClient
*self
)
1776 if (client_should_show(self
))
1777 frame_show(self
->frame
);
1779 frame_hide(self
->frame
);
1782 gboolean
client_normal(ObClient
*self
) {
1783 return ! (self
->type
== OB_CLIENT_TYPE_DESKTOP
||
1784 self
->type
== OB_CLIENT_TYPE_DOCK
||
1785 self
->type
== OB_CLIENT_TYPE_SPLASH
);
1788 static void client_apply_startup_state(ObClient
*self
)
1790 /* these are in a carefully crafted order.. */
1793 self
->iconic
= FALSE
;
1794 client_iconify(self
, TRUE
, FALSE
);
1796 if (self
->fullscreen
) {
1797 self
->fullscreen
= FALSE
;
1798 client_fullscreen(self
, TRUE
, FALSE
);
1800 if (self
->undecorated
) {
1801 self
->undecorated
= FALSE
;
1802 client_set_undecorated(self
, TRUE
);
1805 self
->shaded
= FALSE
;
1806 client_shade(self
, TRUE
);
1809 client_urgent_notify(self
);
1811 if (self
->max_vert
&& self
->max_horz
) {
1812 self
->max_vert
= self
->max_horz
= FALSE
;
1813 client_maximize(self
, TRUE
, 0, FALSE
);
1814 } else if (self
->max_vert
) {
1815 self
->max_vert
= FALSE
;
1816 client_maximize(self
, TRUE
, 2, FALSE
);
1817 } else if (self
->max_horz
) {
1818 self
->max_horz
= FALSE
;
1819 client_maximize(self
, TRUE
, 1, FALSE
);
1822 /* nothing to do for the other states:
1831 void client_configure_full(ObClient
*self
, ObCorner anchor
,
1832 int x
, int y
, int w
, int h
,
1833 gboolean user
, gboolean final
,
1834 gboolean force_reply
)
1837 gboolean send_resize_client
;
1838 gboolean moved
= FALSE
, resized
= FALSE
;
1839 guint fdecor
= self
->frame
->decorations
;
1840 gboolean fhorz
= self
->frame
->max_horz
;
1842 /* make the frame recalculate its dimentions n shit without changing
1843 anything visible for real, this way the constraints below can work with
1844 the updated frame dimensions. */
1845 frame_adjust_area(self
->frame
, TRUE
, TRUE
, TRUE
);
1847 /* gets the frame's position */
1848 frame_client_gravity(self
->frame
, &x
, &y
);
1850 /* these positions are frame positions, not client positions */
1852 /* set the size and position if fullscreen */
1853 if (self
->fullscreen
) {
1856 XF86VidModeModeLine mode
;
1861 i
= client_monitor(self
);
1862 a
= screen_physical_area_monitor(i
);
1865 if (i
== 0 && /* primary head */
1866 extensions_vidmode
&&
1867 XF86VidModeGetViewPort(ob_display
, ob_screen
, &x
, &y
) &&
1868 /* get the mode last so the mode.privsize isnt freed incorrectly */
1869 XF86VidModeGetModeLine(ob_display
, ob_screen
, &dot
, &mode
)) {
1874 if (mode
.privsize
) XFree(mode
.private);
1884 user
= FALSE
; /* ignore that increment etc shit when in fullscreen */
1888 a
= screen_area_monitor(self
->desktop
, client_monitor(self
));
1890 /* set the size and position if maximized */
1891 if (self
->max_horz
) {
1893 w
= a
->width
- self
->frame
->size
.left
- self
->frame
->size
.right
;
1895 if (self
->max_vert
) {
1897 h
= a
->height
- self
->frame
->size
.top
- self
->frame
->size
.bottom
;
1901 /* gets the client's position */
1902 frame_frame_gravity(self
->frame
, &x
, &y
);
1904 /* these override the above states! if you cant move you can't move! */
1906 if (!(self
->functions
& OB_CLIENT_FUNC_MOVE
)) {
1910 if (!(self
->functions
& OB_CLIENT_FUNC_RESIZE
)) {
1911 w
= self
->area
.width
;
1912 h
= self
->area
.height
;
1916 if (!(w
== self
->area
.width
&& h
== self
->area
.height
)) {
1917 int basew
, baseh
, minw
, minh
;
1919 /* base size is substituted with min size if not specified */
1920 if (self
->base_size
.width
|| self
->base_size
.height
) {
1921 basew
= self
->base_size
.width
;
1922 baseh
= self
->base_size
.height
;
1924 basew
= self
->min_size
.width
;
1925 baseh
= self
->min_size
.height
;
1927 /* min size is substituted with base size if not specified */
1928 if (self
->min_size
.width
|| self
->min_size
.height
) {
1929 minw
= self
->min_size
.width
;
1930 minh
= self
->min_size
.height
;
1932 minw
= self
->base_size
.width
;
1933 minh
= self
->base_size
.height
;
1936 /* if this is a user-requested resize, then check against min/max
1939 /* smaller than min size or bigger than max size? */
1940 if (w
> self
->max_size
.width
) w
= self
->max_size
.width
;
1941 if (w
< minw
) w
= minw
;
1942 if (h
> self
->max_size
.height
) h
= self
->max_size
.height
;
1943 if (h
< minh
) h
= minh
;
1948 /* keep to the increments */
1949 w
/= self
->size_inc
.width
;
1950 h
/= self
->size_inc
.height
;
1952 /* you cannot resize to nothing */
1953 if (basew
+ w
< 1) w
= 1 - basew
;
1954 if (baseh
+ h
< 1) h
= 1 - baseh
;
1956 /* store the logical size */
1957 SIZE_SET(self
->logical_size
,
1958 self
->size_inc
.width
> 1 ? w
: w
+ basew
,
1959 self
->size_inc
.height
> 1 ? h
: h
+ baseh
);
1961 w
*= self
->size_inc
.width
;
1962 h
*= self
->size_inc
.height
;
1967 /* adjust the height to match the width for the aspect ratios.
1968 for this, min size is not substituted for base size ever. */
1969 w
-= self
->base_size
.width
;
1970 h
-= self
->base_size
.height
;
1972 if (self
->min_ratio
)
1973 if (h
* self
->min_ratio
> w
) {
1974 h
= (int)(w
/ self
->min_ratio
);
1976 /* you cannot resize to nothing */
1979 w
= (int)(h
* self
->min_ratio
);
1982 if (self
->max_ratio
)
1983 if (h
* self
->max_ratio
< w
) {
1984 h
= (int)(w
/ self
->max_ratio
);
1986 /* you cannot resize to nothing */
1989 w
= (int)(h
* self
->min_ratio
);
1993 w
+= self
->base_size
.width
;
1994 h
+= self
->base_size
.height
;
2001 case OB_CORNER_TOPLEFT
:
2003 case OB_CORNER_TOPRIGHT
:
2004 x
-= w
- self
->area
.width
;
2006 case OB_CORNER_BOTTOMLEFT
:
2007 y
-= h
- self
->area
.height
;
2009 case OB_CORNER_BOTTOMRIGHT
:
2010 x
-= w
- self
->area
.width
;
2011 y
-= h
- self
->area
.height
;
2015 moved
= x
!= self
->area
.x
|| y
!= self
->area
.y
;
2016 resized
= w
!= self
->area
.width
|| h
!= self
->area
.height
;
2018 oldw
= self
->area
.width
;
2019 oldh
= self
->area
.height
;
2020 RECT_SET(self
->area
, x
, y
, w
, h
);
2022 /* for app-requested resizes, always resize if 'resized' is true.
2023 for user-requested ones, only resize if final is true, or when
2024 resizing in redraw mode */
2025 send_resize_client
= ((!user
&& resized
) ||
2027 (resized
&& config_redraw_resize
))));
2029 /* if the client is enlarging, the resize the client before the frame */
2030 if (send_resize_client
&& user
&& (w
> oldw
|| h
> oldh
))
2031 XResizeWindow(ob_display
, self
->window
, MAX(w
, oldw
), MAX(h
, oldh
));
2033 /* move/resize the frame to match the request */
2035 if (self
->decorations
!= fdecor
|| self
->max_horz
!= fhorz
)
2036 moved
= resized
= TRUE
;
2038 if (moved
|| resized
)
2039 frame_adjust_area(self
->frame
, moved
, resized
, FALSE
);
2041 if (!resized
&& (force_reply
|| ((!user
&& moved
) || (user
&& final
))))
2044 event
.type
= ConfigureNotify
;
2045 event
.xconfigure
.display
= ob_display
;
2046 event
.xconfigure
.event
= self
->window
;
2047 event
.xconfigure
.window
= self
->window
;
2049 /* root window real coords */
2050 event
.xconfigure
.x
= self
->frame
->area
.x
+ self
->frame
->size
.left
-
2052 event
.xconfigure
.y
= self
->frame
->area
.y
+ self
->frame
->size
.top
-
2054 event
.xconfigure
.width
= w
;
2055 event
.xconfigure
.height
= h
;
2056 event
.xconfigure
.border_width
= 0;
2057 event
.xconfigure
.above
= self
->frame
->plate
;
2058 event
.xconfigure
.override_redirect
= FALSE
;
2059 XSendEvent(event
.xconfigure
.display
, event
.xconfigure
.window
,
2060 FALSE
, StructureNotifyMask
, &event
);
2064 /* if the client is shrinking, then resize the frame before the client */
2065 if (send_resize_client
&& (!user
|| (w
<= oldw
|| h
<= oldh
)))
2066 XResizeWindow(ob_display
, self
->window
, w
, h
);
2071 void client_fullscreen(ObClient
*self
, gboolean fs
, gboolean savearea
)
2075 if (!(self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
) || /* can't */
2076 self
->fullscreen
== fs
) return; /* already done */
2078 self
->fullscreen
= fs
;
2079 client_change_state(self
); /* change the state hints on the client,
2080 and adjust out layer/stacking */
2084 self
->pre_fullscreen_area
= self
->area
;
2086 /* these are not actually used cuz client_configure will set them
2087 as appropriate when the window is fullscreened */
2092 if (self
->pre_fullscreen_area
.width
> 0 &&
2093 self
->pre_fullscreen_area
.height
> 0)
2095 x
= self
->pre_fullscreen_area
.x
;
2096 y
= self
->pre_fullscreen_area
.y
;
2097 w
= self
->pre_fullscreen_area
.width
;
2098 h
= self
->pre_fullscreen_area
.height
;
2099 RECT_SET(self
->pre_fullscreen_area
, 0, 0, 0, 0);
2101 /* pick some fallbacks... */
2102 a
= screen_area_monitor(self
->desktop
, 0);
2103 x
= a
->x
+ a
->width
/ 4;
2104 y
= a
->y
+ a
->height
/ 4;
2110 client_setup_decor_and_functions(self
);
2112 client_move_resize(self
, x
, y
, w
, h
);
2114 /* try focus us when we go into fullscreen mode */
2118 static void client_iconify_recursive(ObClient
*self
,
2119 gboolean iconic
, gboolean curdesk
)
2122 gboolean changed
= FALSE
;
2125 if (self
->iconic
!= iconic
) {
2126 ob_debug("%sconifying window: 0x%lx\n", (iconic
? "I" : "Uni"),
2129 self
->iconic
= iconic
;
2132 if (self
->functions
& OB_CLIENT_FUNC_ICONIFY
) {
2135 old
= self
->wmstate
;
2136 self
->wmstate
= IconicState
;
2137 if (old
!= self
->wmstate
)
2138 PROP_MSG(self
->window
, kde_wm_change_state
,
2139 self
->wmstate
, 1, 0, 0);
2141 self
->ignore_unmaps
++;
2142 /* we unmap the client itself so that we can get MapRequest
2143 events, and because the ICCCM tells us to! */
2144 XUnmapWindow(ob_display
, self
->window
);
2146 /* update the focus lists.. iconic windows go to the bottom of
2147 the list, put the new iconic window at the 'top of the
2149 focus_order_to_top(self
);
2157 client_set_desktop(self
, screen_desktop
, FALSE
);
2159 old
= self
->wmstate
;
2160 self
->wmstate
= self
->shaded
? IconicState
: NormalState
;
2161 if (old
!= self
->wmstate
)
2162 PROP_MSG(self
->window
, kde_wm_change_state
,
2163 self
->wmstate
, 1, 0, 0);
2165 XMapWindow(ob_display
, self
->window
);
2167 /* this puts it after the current focused window */
2168 focus_order_remove(self
);
2169 focus_order_add_new(self
);
2171 /* this is here cuz with the VIDMODE extension, the viewport can
2172 change while a fullscreen window is iconic, and when it
2173 uniconifies, it would be nice if it did so to the new position
2175 client_reconfigure(self
);
2182 client_change_state(self
);
2183 client_showhide(self
);
2184 screen_update_areas();
2187 /* iconify all transients */
2188 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
)
2189 if (it
->data
!= self
) client_iconify_recursive(it
->data
,
2193 void client_iconify(ObClient
*self
, gboolean iconic
, gboolean curdesk
)
2195 /* move up the transient chain as far as possible first */
2196 self
= client_search_top_transient(self
);
2198 client_iconify_recursive(client_search_top_transient(self
),
2202 void client_maximize(ObClient
*self
, gboolean max
, int dir
, gboolean savearea
)
2206 g_assert(dir
== 0 || dir
== 1 || dir
== 2);
2207 if (!(self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
)) return; /* can't */
2209 /* check if already done */
2211 if (dir
== 0 && self
->max_horz
&& self
->max_vert
) return;
2212 if (dir
== 1 && self
->max_horz
) return;
2213 if (dir
== 2 && self
->max_vert
) return;
2215 if (dir
== 0 && !self
->max_horz
&& !self
->max_vert
) return;
2216 if (dir
== 1 && !self
->max_horz
) return;
2217 if (dir
== 2 && !self
->max_vert
) return;
2220 /* we just tell it to configure in the same place and client_configure
2221 worries about filling the screen with the window */
2224 w
= self
->area
.width
;
2225 h
= self
->area
.height
;
2229 if ((dir
== 0 || dir
== 1) && !self
->max_horz
) { /* horz */
2230 RECT_SET(self
->pre_max_area
,
2231 self
->area
.x
, self
->pre_max_area
.y
,
2232 self
->area
.width
, self
->pre_max_area
.height
);
2234 if ((dir
== 0 || dir
== 2) && !self
->max_vert
) { /* vert */
2235 RECT_SET(self
->pre_max_area
,
2236 self
->pre_max_area
.x
, self
->area
.y
,
2237 self
->pre_max_area
.width
, self
->area
.height
);
2243 a
= screen_area_monitor(self
->desktop
, 0);
2244 if ((dir
== 0 || dir
== 1) && self
->max_horz
) { /* horz */
2245 if (self
->pre_max_area
.width
> 0) {
2246 x
= self
->pre_max_area
.x
;
2247 w
= self
->pre_max_area
.width
;
2249 RECT_SET(self
->pre_max_area
, 0, self
->pre_max_area
.y
,
2250 0, self
->pre_max_area
.height
);
2252 /* pick some fallbacks... */
2253 x
= a
->x
+ a
->width
/ 4;
2257 if ((dir
== 0 || dir
== 2) && self
->max_vert
) { /* vert */
2258 if (self
->pre_max_area
.height
> 0) {
2259 y
= self
->pre_max_area
.y
;
2260 h
= self
->pre_max_area
.height
;
2262 RECT_SET(self
->pre_max_area
, self
->pre_max_area
.x
, 0,
2263 self
->pre_max_area
.width
, 0);
2265 /* pick some fallbacks... */
2266 y
= a
->y
+ a
->height
/ 4;
2272 if (dir
== 0 || dir
== 1) /* horz */
2273 self
->max_horz
= max
;
2274 if (dir
== 0 || dir
== 2) /* vert */
2275 self
->max_vert
= max
;
2277 client_change_state(self
); /* change the state hints on the client */
2279 client_setup_decor_and_functions(self
);
2281 client_move_resize(self
, x
, y
, w
, h
);
2284 void client_shade(ObClient
*self
, gboolean shade
)
2286 if ((!(self
->functions
& OB_CLIENT_FUNC_SHADE
) &&
2287 shade
) || /* can't shade */
2288 self
->shaded
== shade
) return; /* already done */
2290 /* when we're iconic, don't change the wmstate */
2291 if (!self
->iconic
) {
2294 old
= self
->wmstate
;
2295 self
->wmstate
= shade
? IconicState
: NormalState
;
2296 if (old
!= self
->wmstate
)
2297 PROP_MSG(self
->window
, kde_wm_change_state
,
2298 self
->wmstate
, 1, 0, 0);
2301 self
->shaded
= shade
;
2302 client_change_state(self
);
2303 /* resize the frame to just the titlebar */
2304 frame_adjust_area(self
->frame
, FALSE
, FALSE
, FALSE
);
2307 void client_close(ObClient
*self
)
2311 if (!(self
->functions
& OB_CLIENT_FUNC_CLOSE
)) return;
2313 /* in the case that the client provides no means to requesting that it
2314 close, we just kill it */
2315 if (!self
->delete_window
)
2319 XXX: itd be cool to do timeouts and shit here for killing the client's
2321 like... if the window is around after 5 seconds, then the close button
2322 turns a nice red, and if this function is called again, the client is
2326 ce
.xclient
.type
= ClientMessage
;
2327 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
2328 ce
.xclient
.display
= ob_display
;
2329 ce
.xclient
.window
= self
->window
;
2330 ce
.xclient
.format
= 32;
2331 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_delete_window
;
2332 ce
.xclient
.data
.l
[1] = event_lasttime
;
2333 ce
.xclient
.data
.l
[2] = 0l;
2334 ce
.xclient
.data
.l
[3] = 0l;
2335 ce
.xclient
.data
.l
[4] = 0l;
2336 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
2339 void client_kill(ObClient
*self
)
2341 XKillClient(ob_display
, self
->window
);
2344 void client_set_desktop_recursive(ObClient
*self
,
2345 guint target
, gboolean donthide
)
2350 if (target
!= self
->desktop
) {
2352 ob_debug("Setting desktop %u\n", target
+1);
2354 g_assert(target
< screen_num_desktops
|| target
== DESKTOP_ALL
);
2356 /* remove from the old desktop(s) */
2357 focus_order_remove(self
);
2359 old
= self
->desktop
;
2360 self
->desktop
= target
;
2361 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, target
);
2362 /* the frame can display the current desktop state */
2363 frame_adjust_state(self
->frame
);
2364 /* 'move' the window to the new desktop */
2366 client_showhide(self
);
2367 /* raise if it was not already on the desktop */
2368 if (old
!= DESKTOP_ALL
)
2370 screen_update_areas();
2372 /* add to the new desktop(s) */
2373 if (config_focus_new
)
2374 focus_order_to_top(self
);
2376 focus_order_to_bottom(self
);
2379 /* move all transients */
2380 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
)
2381 if (it
->data
!= self
) client_set_desktop_recursive(it
->data
,
2385 void client_set_desktop(ObClient
*self
, guint target
, gboolean donthide
)
2387 client_set_desktop_recursive(client_search_top_transient(self
),
2391 ObClient
*client_search_modal_child(ObClient
*self
)
2396 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
) {
2397 ObClient
*c
= it
->data
;
2398 if ((ret
= client_search_modal_child(c
))) return ret
;
2399 if (c
->modal
) return c
;
2404 gboolean
client_validate(ObClient
*self
)
2408 XSync(ob_display
, FALSE
); /* get all events on the server */
2410 if (XCheckTypedWindowEvent(ob_display
, self
->window
, DestroyNotify
, &e
) ||
2411 XCheckTypedWindowEvent(ob_display
, self
->window
, UnmapNotify
, &e
)) {
2412 XPutBackEvent(ob_display
, &e
);
2419 void client_set_wm_state(ObClient
*self
, long state
)
2421 if (state
== self
->wmstate
) return; /* no change */
2425 client_iconify(self
, TRUE
, TRUE
);
2428 client_iconify(self
, FALSE
, TRUE
);
2433 void client_set_state(ObClient
*self
, Atom action
, long data1
, long data2
)
2435 gboolean shaded
= self
->shaded
;
2436 gboolean fullscreen
= self
->fullscreen
;
2437 gboolean undecorated
= self
->undecorated
;
2438 gboolean max_horz
= self
->max_horz
;
2439 gboolean max_vert
= self
->max_vert
;
2442 if (!(action
== prop_atoms
.net_wm_state_add
||
2443 action
== prop_atoms
.net_wm_state_remove
||
2444 action
== prop_atoms
.net_wm_state_toggle
))
2445 /* an invalid action was passed to the client message, ignore it */
2448 for (i
= 0; i
< 2; ++i
) {
2449 Atom state
= i
== 0 ? data1
: data2
;
2451 if (!state
) continue;
2453 /* if toggling, then pick whether we're adding or removing */
2454 if (action
== prop_atoms
.net_wm_state_toggle
) {
2455 if (state
== prop_atoms
.net_wm_state_modal
)
2456 action
= self
->modal
? prop_atoms
.net_wm_state_remove
:
2457 prop_atoms
.net_wm_state_add
;
2458 else if (state
== prop_atoms
.net_wm_state_maximized_vert
)
2459 action
= self
->max_vert
? prop_atoms
.net_wm_state_remove
:
2460 prop_atoms
.net_wm_state_add
;
2461 else if (state
== prop_atoms
.net_wm_state_maximized_horz
)
2462 action
= self
->max_horz
? prop_atoms
.net_wm_state_remove
:
2463 prop_atoms
.net_wm_state_add
;
2464 else if (state
== prop_atoms
.net_wm_state_shaded
)
2465 action
= shaded
? prop_atoms
.net_wm_state_remove
:
2466 prop_atoms
.net_wm_state_add
;
2467 else if (state
== prop_atoms
.net_wm_state_skip_taskbar
)
2468 action
= self
->skip_taskbar
?
2469 prop_atoms
.net_wm_state_remove
:
2470 prop_atoms
.net_wm_state_add
;
2471 else if (state
== prop_atoms
.net_wm_state_skip_pager
)
2472 action
= self
->skip_pager
?
2473 prop_atoms
.net_wm_state_remove
:
2474 prop_atoms
.net_wm_state_add
;
2475 else if (state
== prop_atoms
.net_wm_state_fullscreen
)
2476 action
= fullscreen
?
2477 prop_atoms
.net_wm_state_remove
:
2478 prop_atoms
.net_wm_state_add
;
2479 else if (state
== prop_atoms
.net_wm_state_above
)
2480 action
= self
->above
? prop_atoms
.net_wm_state_remove
:
2481 prop_atoms
.net_wm_state_add
;
2482 else if (state
== prop_atoms
.net_wm_state_below
)
2483 action
= self
->below
? prop_atoms
.net_wm_state_remove
:
2484 prop_atoms
.net_wm_state_add
;
2485 else if (state
== prop_atoms
.ob_wm_state_undecorated
)
2486 action
= undecorated
? prop_atoms
.net_wm_state_remove
:
2487 prop_atoms
.net_wm_state_add
;
2490 if (action
== prop_atoms
.net_wm_state_add
) {
2491 if (state
== prop_atoms
.net_wm_state_modal
) {
2492 /* XXX raise here or something? */
2494 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
2496 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
2498 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
2500 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
2501 self
->skip_taskbar
= TRUE
;
2502 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
2503 self
->skip_pager
= TRUE
;
2504 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
2506 } else if (state
== prop_atoms
.net_wm_state_above
) {
2508 } else if (state
== prop_atoms
.net_wm_state_below
) {
2510 } else if (state
== prop_atoms
.ob_wm_state_undecorated
) {
2514 } else { /* action == prop_atoms.net_wm_state_remove */
2515 if (state
== prop_atoms
.net_wm_state_modal
) {
2516 self
->modal
= FALSE
;
2517 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
2519 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
2521 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
2523 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
2524 self
->skip_taskbar
= FALSE
;
2525 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
2526 self
->skip_pager
= FALSE
;
2527 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
2529 } else if (state
== prop_atoms
.net_wm_state_above
) {
2530 self
->above
= FALSE
;
2531 } else if (state
== prop_atoms
.net_wm_state_below
) {
2532 self
->below
= FALSE
;
2533 } else if (state
== prop_atoms
.ob_wm_state_undecorated
) {
2534 undecorated
= FALSE
;
2538 if (max_horz
!= self
->max_horz
|| max_vert
!= self
->max_vert
) {
2539 if (max_horz
!= self
->max_horz
&& max_vert
!= self
->max_vert
) {
2541 if (max_horz
== max_vert
) { /* both going the same way */
2542 client_maximize(self
, max_horz
, 0, TRUE
);
2544 client_maximize(self
, max_horz
, 1, TRUE
);
2545 client_maximize(self
, max_vert
, 2, TRUE
);
2549 if (max_horz
!= self
->max_horz
)
2550 client_maximize(self
, max_horz
, 1, TRUE
);
2552 client_maximize(self
, max_vert
, 2, TRUE
);
2555 /* change fullscreen state before shading, as it will affect if the window
2557 if (fullscreen
!= self
->fullscreen
)
2558 client_fullscreen(self
, fullscreen
, TRUE
);
2559 if (shaded
!= self
->shaded
)
2560 client_shade(self
, shaded
);
2561 if (undecorated
!= self
->undecorated
)
2562 client_set_undecorated(self
, undecorated
);
2563 client_calc_layer(self
);
2564 client_change_state(self
); /* change the hint to reflect these changes */
2567 ObClient
*client_focus_target(ObClient
*self
)
2571 /* if we have a modal child, then focus it, not us */
2572 child
= client_search_modal_child(client_search_top_transient(self
));
2573 if (child
) return child
;
2577 gboolean
client_can_focus(ObClient
*self
)
2581 /* choose the correct target */
2582 self
= client_focus_target(self
);
2584 if (!self
->frame
->visible
)
2587 if (!(self
->can_focus
|| self
->focus_notify
))
2590 /* do a check to see if the window has already been unmapped or destroyed
2591 do this intelligently while watching out for unmaps we've generated
2592 (ignore_unmaps > 0) */
2593 if (XCheckTypedWindowEvent(ob_display
, self
->window
,
2594 DestroyNotify
, &ev
)) {
2595 XPutBackEvent(ob_display
, &ev
);
2598 while (XCheckTypedWindowEvent(ob_display
, self
->window
,
2599 UnmapNotify
, &ev
)) {
2600 if (self
->ignore_unmaps
) {
2601 self
->ignore_unmaps
--;
2603 XPutBackEvent(ob_display
, &ev
);
2611 gboolean
client_focus(ObClient
*self
)
2613 /* choose the correct target */
2614 self
= client_focus_target(self
);
2616 if (!client_can_focus(self
)) {
2617 if (!self
->frame
->visible
) {
2618 /* update the focus lists */
2619 focus_order_to_top(self
);
2624 if (self
->can_focus
) {
2625 /* RevertToPointerRoot causes much more headache than RevertToNone, so
2626 I choose to use it always, hopefully to find errors quicker, if any
2627 are left. (I hate X. I hate focus events.)
2629 Update: Changing this to RevertToNone fixed a bug with mozilla (bug
2630 #799. So now it is RevertToNone again.
2632 XSetInputFocus(ob_display
, self
->window
, RevertToNone
,
2636 if (self
->focus_notify
) {
2638 ce
.xclient
.type
= ClientMessage
;
2639 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
2640 ce
.xclient
.display
= ob_display
;
2641 ce
.xclient
.window
= self
->window
;
2642 ce
.xclient
.format
= 32;
2643 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_take_focus
;
2644 ce
.xclient
.data
.l
[1] = event_lasttime
;
2645 ce
.xclient
.data
.l
[2] = 0l;
2646 ce
.xclient
.data
.l
[3] = 0l;
2647 ce
.xclient
.data
.l
[4] = 0l;
2648 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
2652 ob_debug("%sively focusing %lx at %d\n",
2653 (self
->can_focus
? "act" : "pass"),
2654 self
->window
, (int) event_lasttime
);
2657 /* Cause the FocusIn to come back to us. Important for desktop switches,
2658 since otherwise we'll have no FocusIn on the queue and send it off to
2659 the focus_backup. */
2660 XSync(ob_display
, FALSE
);
2664 void client_unfocus(ObClient
*self
)
2666 if (focus_client
== self
) {
2668 ob_debug("client_unfocus for %lx\n", self
->window
);
2670 focus_fallback(OB_FOCUS_FALLBACK_UNFOCUSING
);
2674 void client_activate(ObClient
*self
, gboolean here
)
2676 if (client_normal(self
) && screen_showing_desktop
)
2677 screen_show_desktop(FALSE
);
2679 client_iconify(self
, FALSE
, here
);
2680 if (self
->desktop
!= DESKTOP_ALL
&&
2681 self
->desktop
!= screen_desktop
) {
2683 client_set_desktop(self
, screen_desktop
, FALSE
);
2685 screen_set_desktop(self
->desktop
);
2686 } else if (!self
->frame
->visible
)
2687 /* if its not visible for other reasons, then don't mess
2691 client_shade(self
, FALSE
);
2695 /* we do this an action here. this is rather important. this is because
2696 we want the results from the focus change to take place BEFORE we go
2697 about raising the window. when a fullscreen window loses focus, we need
2698 this or else the raise wont be able to raise above the to-lose-focus
2699 fullscreen window. */
2703 void client_raise(ObClient
*self
)
2705 action_run_string("Raise", self
);
2708 void client_lower(ObClient
*self
)
2710 action_run_string("Raise", self
);
2713 gboolean
client_focused(ObClient
*self
)
2715 return self
== focus_client
;
2718 static ObClientIcon
* client_icon_recursive(ObClient
*self
, int w
, int h
)
2721 /* si is the smallest image >= req */
2722 /* li is the largest image < req */
2723 unsigned long size
, smallest
= 0xffffffff, largest
= 0, si
= 0, li
= 0;
2725 if (!self
->nicons
) {
2726 ObClientIcon
*parent
= NULL
;
2728 if (self
->transient_for
) {
2729 if (self
->transient_for
!= OB_TRAN_GROUP
)
2730 parent
= client_icon_recursive(self
->transient_for
, w
, h
);
2733 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
2734 ObClient
*c
= it
->data
;
2735 if (c
!= self
&& !c
->transient_for
) {
2736 if ((parent
= client_icon_recursive(c
, w
, h
)))
2746 for (i
= 0; i
< self
->nicons
; ++i
) {
2747 size
= self
->icons
[i
].width
* self
->icons
[i
].height
;
2748 if (size
< smallest
&& size
>= (unsigned)(w
* h
)) {
2752 if (size
> largest
&& size
<= (unsigned)(w
* h
)) {
2757 if (largest
== 0) /* didnt find one smaller than the requested size */
2758 return &self
->icons
[si
];
2759 return &self
->icons
[li
];
2762 const ObClientIcon
* client_icon(ObClient
*self
, int w
, int h
)
2765 static ObClientIcon deficon
;
2767 if (!(ret
= client_icon_recursive(self
, w
, h
))) {
2768 deficon
.width
= deficon
.height
= 48;
2769 deficon
.data
= ob_rr_theme
->def_win_icon
;
2775 /* this be mostly ripped from fvwm */
2776 ObClient
*client_find_directional(ObClient
*c
, ObDirection dir
)
2778 int my_cx
, my_cy
, his_cx
, his_cy
;
2781 int score
, best_score
;
2782 ObClient
*best_client
, *cur
;
2788 /* first, find the centre coords of the currently focused window */
2789 my_cx
= c
->frame
->area
.x
+ c
->frame
->area
.width
/ 2;
2790 my_cy
= c
->frame
->area
.y
+ c
->frame
->area
.height
/ 2;
2795 for(it
= g_list_first(client_list
); it
; it
= it
->next
) {
2798 /* the currently selected window isn't interesting */
2801 if (!client_normal(cur
))
2803 if(c
->desktop
!= cur
->desktop
&& cur
->desktop
!= DESKTOP_ALL
)
2807 if(client_focus_target(cur
) == cur
&&
2808 !(cur
->can_focus
|| cur
->focus_notify
))
2811 /* find the centre coords of this window, from the
2812 * currently focused window's point of view */
2813 his_cx
= (cur
->frame
->area
.x
- my_cx
)
2814 + cur
->frame
->area
.width
/ 2;
2815 his_cy
= (cur
->frame
->area
.y
- my_cy
)
2816 + cur
->frame
->area
.height
/ 2;
2818 if(dir
== OB_DIRECTION_NORTHEAST
|| dir
== OB_DIRECTION_SOUTHEAST
||
2819 dir
== OB_DIRECTION_SOUTHWEST
|| dir
== OB_DIRECTION_NORTHWEST
) {
2821 /* Rotate the diagonals 45 degrees counterclockwise.
2822 * To do this, multiply the matrix /+h +h\ with the
2823 * vector (x y). \-h +h/
2824 * h = sqrt(0.5). We can set h := 1 since absolute
2825 * distance doesn't matter here. */
2826 tx
= his_cx
+ his_cy
;
2827 his_cy
= -his_cx
+ his_cy
;
2832 case OB_DIRECTION_NORTH
:
2833 case OB_DIRECTION_SOUTH
:
2834 case OB_DIRECTION_NORTHEAST
:
2835 case OB_DIRECTION_SOUTHWEST
:
2836 offset
= (his_cx
< 0) ? -his_cx
: his_cx
;
2837 distance
= ((dir
== OB_DIRECTION_NORTH
||
2838 dir
== OB_DIRECTION_NORTHEAST
) ?
2841 case OB_DIRECTION_EAST
:
2842 case OB_DIRECTION_WEST
:
2843 case OB_DIRECTION_SOUTHEAST
:
2844 case OB_DIRECTION_NORTHWEST
:
2845 offset
= (his_cy
< 0) ? -his_cy
: his_cy
;
2846 distance
= ((dir
== OB_DIRECTION_WEST
||
2847 dir
== OB_DIRECTION_NORTHWEST
) ?
2852 /* the target must be in the requested direction */
2856 /* Calculate score for this window. The smaller the better. */
2857 score
= distance
+ offset
;
2859 /* windows more than 45 degrees off the direction are
2860 * heavily penalized and will only be chosen if nothing
2861 * else within a million pixels */
2862 if(offset
> distance
)
2865 if(best_score
== -1 || score
< best_score
)
2873 void client_set_layer(ObClient
*self
, int layer
)
2877 self
->above
= FALSE
;
2878 } else if (layer
== 0) {
2879 self
->below
= self
->above
= FALSE
;
2881 self
->below
= FALSE
;
2884 client_calc_layer(self
);
2885 client_change_state(self
); /* reflect this in the state hints */
2888 void client_set_undecorated(ObClient
*self
, gboolean undecorated
)
2890 if (self
->undecorated
!= undecorated
) {
2891 self
->undecorated
= undecorated
;
2892 client_setup_decor_and_functions(self
);
2893 client_change_state(self
); /* reflect this in the state hints */
2897 guint
client_monitor(ObClient
*self
)
2901 for (i
= 0; i
< screen_num_monitors
; ++i
) {
2902 Rect
*area
= screen_physical_area_monitor(i
);
2903 if (RECT_INTERSECTS_RECT(*area
, self
->frame
->area
))
2906 if (i
== screen_num_monitors
) i
= 0;
2907 g_assert(i
< screen_num_monitors
);
2911 ObClient
*client_search_top_transient(ObClient
*self
)
2913 /* move up the transient chain as far as possible */
2914 if (self
->transient_for
) {
2915 if (self
->transient_for
!= OB_TRAN_GROUP
) {
2916 return client_search_top_transient(self
->transient_for
);
2920 g_assert(self
->group
);
2922 for (it
= self
->group
->members
; it
; it
= it
->next
) {
2923 ObClient
*c
= it
->data
;
2925 /* checking transient_for prevents infinate loops! */
2926 if (c
!= self
&& !c
->transient_for
)
2937 ObClient
*client_search_focus_parent(ObClient
*self
)
2939 if (self
->transient_for
) {
2940 if (self
->transient_for
!= OB_TRAN_GROUP
) {
2941 if (client_focused(self
->transient_for
))
2942 return self
->transient_for
;
2946 for (it
= self
->group
->members
; it
; it
= it
->next
) {
2947 ObClient
*c
= it
->data
;
2949 /* checking transient_for prevents infinate loops! */
2950 if (c
!= self
&& !c
->transient_for
)
2951 if (client_focused(c
))
2960 ObClient
*client_search_parent(ObClient
*self
, ObClient
*search
)
2962 if (self
->transient_for
) {
2963 if (self
->transient_for
!= OB_TRAN_GROUP
) {
2964 if (self
->transient_for
== search
)
2969 for (it
= self
->group
->members
; it
; it
= it
->next
) {
2970 ObClient
*c
= it
->data
;
2972 /* checking transient_for prevents infinate loops! */
2973 if (c
!= self
&& !c
->transient_for
)
2983 ObClient
*client_search_transient(ObClient
*self
, ObClient
*search
)
2987 for (sit
= self
->transients
; sit
; sit
= g_slist_next(sit
)) {
2988 if (sit
->data
== search
)
2990 if (client_search_transient(sit
->data
, search
))
2996 void client_update_sm_client_id(ObClient
*self
)
2998 g_free(self
->sm_client_id
);
2999 self
->sm_client_id
= NULL
;
3001 if (!PROP_GETS(self
->window
, sm_client_id
, locale
, &self
->sm_client_id
) &&
3003 PROP_GETS(self
->group
->leader
, sm_client_id
, locale
,
3004 &self
->sm_client_id
);
3007 /* finds the nearest edge in the given direction from the current client
3008 * note to self: the edge is the -frame- edge (the actual one), not the
3011 int client_directional_edge_search(ObClient
*c
, ObDirection dir
)
3014 int my_edge_start
, my_edge_end
, my_offset
;
3021 a
= screen_area(c
->desktop
);
3024 case OB_DIRECTION_NORTH
:
3025 my_edge_start
= c
->frame
->area
.x
;
3026 my_edge_end
= c
->frame
->area
.x
+ c
->frame
->area
.width
;
3027 my_offset
= c
->frame
->area
.y
;
3029 /* default: top of screen */
3032 for(it
= g_list_first(client_list
); it
; it
= it
->next
) {
3033 int his_edge_start
, his_edge_end
, his_offset
;
3034 ObClient
*cur
= it
->data
;
3038 if(!client_normal(cur
))
3040 if(c
->desktop
!= cur
->desktop
&& cur
->desktop
!= DESKTOP_ALL
)
3045 his_edge_start
= cur
->frame
->area
.x
;
3046 his_edge_end
= cur
->frame
->area
.x
+ cur
->frame
->area
.width
;
3047 his_offset
= cur
->frame
->area
.y
+ cur
->frame
->area
.height
;
3049 if(his_offset
+ 1 > my_offset
)
3052 if(his_offset
< dest
)
3055 if(his_edge_start
>= my_edge_start
&&
3056 his_edge_start
<= my_edge_end
)
3059 if(my_edge_start
>= his_edge_start
&&
3060 my_edge_start
<= his_edge_end
)
3065 case OB_DIRECTION_SOUTH
:
3066 my_edge_start
= c
->frame
->area
.x
;
3067 my_edge_end
= c
->frame
->area
.x
+ c
->frame
->area
.width
;
3068 my_offset
= c
->frame
->area
.y
+ c
->frame
->area
.height
;
3070 /* default: bottom of screen */
3071 dest
= a
->y
+ a
->height
;
3073 for(it
= g_list_first(client_list
); it
; it
= it
->next
) {
3074 int his_edge_start
, his_edge_end
, his_offset
;
3075 ObClient
*cur
= it
->data
;
3079 if(!client_normal(cur
))
3081 if(c
->desktop
!= cur
->desktop
&& cur
->desktop
!= DESKTOP_ALL
)
3086 his_edge_start
= cur
->frame
->area
.x
;
3087 his_edge_end
= cur
->frame
->area
.x
+ cur
->frame
->area
.width
;
3088 his_offset
= cur
->frame
->area
.y
;
3091 if(his_offset
- 1 < my_offset
)
3094 if(his_offset
> dest
)
3097 if(his_edge_start
>= my_edge_start
&&
3098 his_edge_start
<= my_edge_end
)
3101 if(my_edge_start
>= his_edge_start
&&
3102 my_edge_start
<= his_edge_end
)
3107 case OB_DIRECTION_WEST
:
3108 my_edge_start
= c
->frame
->area
.y
;
3109 my_edge_end
= c
->frame
->area
.y
+ c
->frame
->area
.height
;
3110 my_offset
= c
->frame
->area
.x
;
3112 /* default: leftmost egde of screen */
3115 for(it
= g_list_first(client_list
); it
; it
= it
->next
) {
3116 int his_edge_start
, his_edge_end
, his_offset
;
3117 ObClient
*cur
= it
->data
;
3121 if(!client_normal(cur
))
3123 if(c
->desktop
!= cur
->desktop
&& cur
->desktop
!= DESKTOP_ALL
)
3128 his_edge_start
= cur
->frame
->area
.y
;
3129 his_edge_end
= cur
->frame
->area
.y
+ cur
->frame
->area
.height
;
3130 his_offset
= cur
->frame
->area
.x
+ cur
->frame
->area
.width
;
3132 if(his_offset
+ 1 > my_offset
)
3135 if(his_offset
< dest
)
3138 if(his_edge_start
>= my_edge_start
&&
3139 his_edge_start
<= my_edge_end
)
3142 if(my_edge_start
>= his_edge_start
&&
3143 my_edge_start
<= his_edge_end
)
3149 case OB_DIRECTION_EAST
:
3150 my_edge_start
= c
->frame
->area
.y
;
3151 my_edge_end
= c
->frame
->area
.y
+ c
->frame
->area
.height
;
3152 my_offset
= c
->frame
->area
.x
+ c
->frame
->area
.width
;
3154 /* default: rightmost edge of screen */
3155 dest
= a
->x
+ a
->width
;
3157 for(it
= g_list_first(client_list
); it
; it
= it
->next
) {
3158 int his_edge_start
, his_edge_end
, his_offset
;
3159 ObClient
*cur
= it
->data
;
3163 if(!client_normal(cur
))
3165 if(c
->desktop
!= cur
->desktop
&& cur
->desktop
!= DESKTOP_ALL
)
3170 his_edge_start
= cur
->frame
->area
.y
;
3171 his_edge_end
= cur
->frame
->area
.y
+ cur
->frame
->area
.height
;
3172 his_offset
= cur
->frame
->area
.x
;
3174 if(his_offset
- 1 < my_offset
)
3177 if(his_offset
> dest
)
3180 if(his_edge_start
>= my_edge_start
&&
3181 his_edge_start
<= my_edge_end
)
3184 if(my_edge_start
>= his_edge_start
&&
3185 my_edge_start
<= his_edge_end
)
3190 case OB_DIRECTION_NORTHEAST
:
3191 case OB_DIRECTION_SOUTHEAST
:
3192 case OB_DIRECTION_NORTHWEST
:
3193 case OB_DIRECTION_SOUTHWEST
:
3194 /* not implemented */
3196 g_assert_not_reached();
3201 ObClient
* client_under_pointer()
3205 ObClient
*ret
= NULL
;
3207 if (screen_pointer_pos(&x
, &y
)) {
3208 for (it
= stacking_list
; it
!= NULL
; it
= it
->next
) {
3209 if (WINDOW_IS_CLIENT(it
->data
)) {
3210 ObClient
*c
= WINDOW_AS_CLIENT(it
->data
);
3211 if (c
->frame
->visible
&&
3212 RECT_CONTAINS(c
->frame
->area
, x
, y
)) {
3222 gboolean
client_has_group_siblings(ObClient
*self
)
3224 return self
->group
&& self
->group
->members
->next
;