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();
370 /* client_activate does this but we aret using it so we have to do it
372 if (screen_showing_desktop
)
373 screen_show_desktop(FALSE
);
375 /* add to client list/map */
376 client_list
= g_list_append(client_list
, self
);
377 g_hash_table_insert(window_map
, &self
->window
, self
);
379 /* this has to happen after we're in the client_list */
380 screen_update_areas();
382 /* update the list hints */
385 keyboard_grab_for_client(self
, TRUE
);
386 mouse_grab_for_client(self
, TRUE
);
388 ob_debug("Managed window 0x%lx (%s)\n", window
, self
->class);
391 void client_unmanage_all()
393 while (client_list
!= NULL
)
394 client_unmanage(client_list
->data
);
397 void client_unmanage(ObClient
*self
)
402 ob_debug("Unmanaging window: %lx (%s)\n", self
->window
, self
->class);
404 g_assert(self
!= NULL
);
406 keyboard_grab_for_client(self
, FALSE
);
407 mouse_grab_for_client(self
, FALSE
);
409 /* remove the window from our save set */
410 XChangeSaveSet(ob_display
, self
->window
, SetModeDelete
);
412 /* we dont want events no more */
413 XSelectInput(ob_display
, self
->window
, NoEventMask
);
415 frame_hide(self
->frame
);
417 client_list
= g_list_remove(client_list
, self
);
418 stacking_remove(self
);
419 g_hash_table_remove(window_map
, &self
->window
);
421 /* update the focus lists */
422 focus_order_remove(self
);
424 /* once the client is out of the list, update the struts to remove it's
426 screen_update_areas();
428 for (it
= client_destructors
; it
; it
= g_slist_next(it
)) {
429 Destructor
*d
= it
->data
;
430 d
->func(self
, d
->data
);
433 if (focus_client
== self
) {
436 /* focus the last focused window on the desktop, and ignore enter
437 events from the unmap so it doesnt mess with the focus */
438 while (XCheckTypedEvent(ob_display
, EnterNotify
, &e
));
439 /* remove these flags so we don't end up getting focused in the
441 self
->can_focus
= FALSE
;
442 self
->focus_notify
= FALSE
;
444 client_unfocus(self
);
447 /* tell our parent(s) that we're gone */
448 if (self
->transient_for
== OB_TRAN_GROUP
) { /* transient of group */
451 for (it
= self
->group
->members
; it
; it
= it
->next
)
452 if (it
->data
!= self
)
453 ((ObClient
*)it
->data
)->transients
=
454 g_slist_remove(((ObClient
*)it
->data
)->transients
, self
);
455 } else if (self
->transient_for
) { /* transient of window */
456 self
->transient_for
->transients
=
457 g_slist_remove(self
->transient_for
->transients
, self
);
460 /* tell our transients that we're gone */
461 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
) {
462 if (((ObClient
*)it
->data
)->transient_for
!= OB_TRAN_GROUP
) {
463 ((ObClient
*)it
->data
)->transient_for
= NULL
;
464 client_calc_layer(it
->data
);
468 /* remove from its group */
470 group_remove(self
->group
, self
);
474 /* give the client its border back */
475 client_toggle_border(self
, TRUE
);
477 /* reparent the window out of the frame, and free the frame */
478 frame_release_client(self
->frame
, self
);
481 if (ob_state() != OB_STATE_EXITING
) {
482 /* these values should not be persisted across a window
484 PROP_ERASE(self
->window
, net_wm_desktop
);
485 PROP_ERASE(self
->window
, net_wm_state
);
486 PROP_ERASE(self
->window
, wm_state
);
488 /* if we're left in an iconic state, the client wont be mapped. this is
489 bad, since we will no longer be managing the window on restart */
491 XMapWindow(ob_display
, self
->window
);
495 ob_debug("Unmanaged window 0x%lx\n", self
->window
);
497 /* free all data allocated in the client struct */
498 g_slist_free(self
->transients
);
499 for (j
= 0; j
< self
->nicons
; ++j
)
500 g_free(self
->icons
[j
].data
);
501 if (self
->nicons
> 0)
504 g_free(self
->icon_title
);
508 g_free(self
->sm_client_id
);
511 /* update the list hints */
515 static void client_urgent_notify(ObClient
*self
)
518 frame_flash_start(self
->frame
);
520 frame_flash_stop(self
->frame
);
523 static void client_restore_session_state(ObClient
*self
)
527 if (!(it
= session_state_find(self
)))
530 self
->session
= it
->data
;
532 RECT_SET(self
->area
, self
->session
->x
, self
->session
->y
,
533 self
->session
->w
, self
->session
->h
);
534 self
->positioned
= TRUE
;
535 if (self
->session
->w
> 0 && self
->session
->h
> 0)
536 XResizeWindow(ob_display
, self
->window
,
537 self
->session
->w
, self
->session
->h
);
539 self
->desktop
= (self
->session
->desktop
== DESKTOP_ALL
?
540 self
->session
->desktop
:
541 MIN(screen_num_desktops
- 1, self
->session
->desktop
));
542 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, self
->desktop
);
544 self
->shaded
= self
->session
->shaded
;
545 self
->iconic
= self
->session
->iconic
;
546 self
->skip_pager
= self
->session
->skip_pager
;
547 self
->skip_taskbar
= self
->session
->skip_taskbar
;
548 self
->fullscreen
= self
->session
->fullscreen
;
549 self
->above
= self
->session
->above
;
550 self
->below
= self
->session
->below
;
551 self
->max_horz
= self
->session
->max_horz
;
552 self
->max_vert
= self
->session
->max_vert
;
555 static void client_restore_session_stacking(ObClient
*self
)
559 if (!self
->session
) return;
561 it
= g_list_find(session_saved_state
, self
->session
);
562 for (it
= g_list_previous(it
); it
; it
= g_list_previous(it
)) {
565 for (cit
= client_list
; cit
; cit
= g_list_next(cit
))
566 if (session_state_cmp(it
->data
, cit
->data
))
569 client_calc_layer(self
);
570 stacking_below(CLIENT_AS_WINDOW(self
),
571 CLIENT_AS_WINDOW(cit
->data
));
577 void client_move_onscreen(ObClient
*self
, gboolean rude
)
579 int x
= self
->area
.x
;
580 int y
= self
->area
.y
;
581 if (client_find_onscreen(self
, &x
, &y
,
582 self
->frame
->area
.width
,
583 self
->frame
->area
.height
, rude
)) {
584 client_move(self
, x
, y
);
588 gboolean
client_find_onscreen(ObClient
*self
, int *x
, int *y
, int w
, int h
,
592 int ox
= *x
, oy
= *y
;
594 frame_client_gravity(self
->frame
, x
, y
); /* get where the frame
597 /* XXX watch for xinerama dead areas */
599 a
= screen_area(self
->desktop
);
600 if (client_normal(self
)) {
601 if (!self
->strut
.right
&& *x
>= a
->x
+ a
->width
- 1)
602 *x
= a
->x
+ a
->width
- self
->frame
->area
.width
;
603 if (!self
->strut
.bottom
&& *y
>= a
->y
+ a
->height
- 1)
604 *y
= a
->y
+ a
->height
- self
->frame
->area
.height
;
605 if (!self
->strut
.left
&& *x
+ self
->frame
->area
.width
- 1 < a
->x
)
607 if (!self
->strut
.top
&& *y
+ self
->frame
->area
.height
- 1 < a
->y
)
612 /* this is my MOZILLA BITCHSLAP. oh ya it fucking feels good.
613 Java can suck it too. */
615 /* dont let windows map/move into the strut unless they
616 are bigger than the available area */
618 if (!self
->strut
.left
&& *x
< a
->x
) *x
= a
->x
;
619 if (!self
->strut
.right
&& *x
+ w
> a
->x
+ a
->width
)
620 *x
= a
->x
+ a
->width
- w
;
622 if (h
<= a
->height
) {
623 if (!self
->strut
.top
&& *y
< a
->y
) *y
= a
->y
;
624 if (!self
->strut
.bottom
&& *y
+ h
> a
->y
+ a
->height
)
625 *y
= a
->y
+ a
->height
- h
;
629 frame_frame_gravity(self
->frame
, x
, y
); /* get where the client
632 return ox
!= *x
|| oy
!= *y
;
635 static void client_toggle_border(ObClient
*self
, gboolean show
)
637 /* adjust our idea of where the client is, based on its border. When the
638 border is removed, the client should now be considered to be in a
640 when re-adding the border to the client, the same operation needs to be
642 int oldx
= self
->area
.x
, oldy
= self
->area
.y
;
643 int x
= oldx
, y
= oldy
;
644 switch(self
->gravity
) {
646 case NorthWestGravity
:
648 case SouthWestGravity
:
650 case NorthEastGravity
:
652 case SouthEastGravity
:
653 if (show
) x
-= self
->border_width
* 2;
654 else x
+= self
->border_width
* 2;
661 if (show
) x
-= self
->border_width
;
662 else x
+= self
->border_width
;
665 switch(self
->gravity
) {
667 case NorthWestGravity
:
669 case NorthEastGravity
:
671 case SouthWestGravity
:
673 case SouthEastGravity
:
674 if (show
) y
-= self
->border_width
* 2;
675 else y
+= self
->border_width
* 2;
682 if (show
) y
-= self
->border_width
;
683 else y
+= self
->border_width
;
690 XSetWindowBorderWidth(ob_display
, self
->window
, self
->border_width
);
692 /* move the client so it is back it the right spot _with_ its
694 if (x
!= oldx
|| y
!= oldy
)
695 XMoveWindow(ob_display
, self
->window
, x
, y
);
697 XSetWindowBorderWidth(ob_display
, self
->window
, 0);
701 static void client_get_all(ObClient
*self
)
703 client_get_area(self
);
704 client_update_transient_for(self
);
705 client_update_wmhints(self
);
706 client_get_startup_id(self
);
707 client_get_desktop(self
);
708 client_get_state(self
);
709 client_get_shaped(self
);
711 client_get_mwm_hints(self
);
712 client_get_type(self
);/* this can change the mwmhints for special cases */
714 client_update_protocols(self
);
716 client_get_gravity(self
); /* get the attribute gravity */
717 client_update_normal_hints(self
); /* this may override the attribute
720 /* got the type, the mwmhints, the protocols, and the normal hints
721 (min/max sizes), so we're ready to set up the decorations/functions */
722 client_setup_decor_and_functions(self
);
724 client_update_title(self
);
725 client_update_class(self
);
726 client_update_sm_client_id(self
);
727 client_update_strut(self
);
728 client_update_icons(self
);
731 static void client_get_startup_id(ObClient
*self
)
733 if (!(PROP_GETS(self
->window
, net_startup_id
, utf8
, &self
->startup_id
)))
735 PROP_GETS(self
->group
->leader
,
736 net_startup_id
, utf8
, &self
->startup_id
);
739 static void client_get_area(ObClient
*self
)
741 XWindowAttributes wattrib
;
744 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
745 g_assert(ret
!= BadWindow
);
747 RECT_SET(self
->area
, wattrib
.x
, wattrib
.y
, wattrib
.width
, wattrib
.height
);
748 self
->border_width
= wattrib
.border_width
;
751 static void client_get_desktop(ObClient
*self
)
753 guint32 d
= screen_num_desktops
; /* an always-invalid value */
755 if (PROP_GET32(self
->window
, net_wm_desktop
, cardinal
, &d
)) {
756 if (d
>= screen_num_desktops
&& d
!= DESKTOP_ALL
)
757 self
->desktop
= screen_num_desktops
- 1;
761 gboolean trdesk
= FALSE
;
763 if (self
->transient_for
) {
764 if (self
->transient_for
!= OB_TRAN_GROUP
) {
765 self
->desktop
= self
->transient_for
->desktop
;
770 for (it
= self
->group
->members
; it
; it
= it
->next
)
771 if (it
->data
!= self
&&
772 !((ObClient
*)it
->data
)->transient_for
) {
773 self
->desktop
= ((ObClient
*)it
->data
)->desktop
;
780 /* try get from the startup-notification protocol */
781 if (sn_get_desktop(self
->startup_id
, &self
->desktop
)) {
782 if (self
->desktop
>= screen_num_desktops
&&
783 self
->desktop
!= DESKTOP_ALL
)
784 self
->desktop
= screen_num_desktops
- 1;
786 /* defaults to the current desktop */
787 self
->desktop
= screen_desktop
;
790 if (self
->desktop
!= d
) {
791 /* set the desktop hint, to make sure that it always exists */
792 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, self
->desktop
);
796 static void client_get_state(ObClient
*self
)
801 if (PROP_GETA32(self
->window
, net_wm_state
, atom
, &state
, &num
)) {
803 for (i
= 0; i
< num
; ++i
) {
804 if (state
[i
] == prop_atoms
.net_wm_state_modal
)
806 else if (state
[i
] == prop_atoms
.net_wm_state_shaded
)
808 else if (state
[i
] == prop_atoms
.net_wm_state_hidden
)
810 else if (state
[i
] == prop_atoms
.net_wm_state_skip_taskbar
)
811 self
->skip_taskbar
= TRUE
;
812 else if (state
[i
] == prop_atoms
.net_wm_state_skip_pager
)
813 self
->skip_pager
= TRUE
;
814 else if (state
[i
] == prop_atoms
.net_wm_state_fullscreen
)
815 self
->fullscreen
= TRUE
;
816 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_vert
)
817 self
->max_vert
= TRUE
;
818 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_horz
)
819 self
->max_horz
= TRUE
;
820 else if (state
[i
] == prop_atoms
.net_wm_state_above
)
822 else if (state
[i
] == prop_atoms
.net_wm_state_below
)
824 else if (state
[i
] == prop_atoms
.ob_wm_state_undecorated
)
825 self
->undecorated
= TRUE
;
832 static void client_get_shaped(ObClient
*self
)
834 self
->shaped
= FALSE
;
836 if (extensions_shape
) {
841 XShapeSelectInput(ob_display
, self
->window
, ShapeNotifyMask
);
843 XShapeQueryExtents(ob_display
, self
->window
, &s
, &foo
,
844 &foo
, &ufoo
, &ufoo
, &foo
, &foo
, &foo
, &ufoo
,
846 self
->shaped
= (s
!= 0);
851 void client_update_transient_for(ObClient
*self
)
854 ObClient
*target
= NULL
;
856 if (XGetTransientForHint(ob_display
, self
->window
, &t
)) {
857 self
->transient
= TRUE
;
858 if (t
!= self
->window
) { /* cant be transient to itself! */
859 target
= g_hash_table_lookup(window_map
, &t
);
860 /* if this happens then we need to check for it*/
861 g_assert(target
!= self
);
862 if (target
&& !WINDOW_IS_CLIENT(target
)) {
863 /* this can happen when a dialog is a child of
864 a dockapp, for example */
868 if (!target
&& self
->group
) {
869 /* not transient to a client, see if it is transient for a
871 if (t
== self
->group
->leader
||
873 t
== RootWindow(ob_display
, ob_screen
))
875 /* window is a transient for its group! */
876 target
= OB_TRAN_GROUP
;
881 self
->transient
= FALSE
;
883 /* if anything has changed... */
884 if (target
!= self
->transient_for
) {
885 if (self
->transient_for
== OB_TRAN_GROUP
) { /* transient of group */
888 /* remove from old parents */
889 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
890 ObClient
*c
= it
->data
;
891 if (c
!= self
&& !c
->transient_for
)
892 c
->transients
= g_slist_remove(c
->transients
, self
);
894 } else if (self
->transient_for
!= NULL
) { /* transient of window */
895 /* remove from old parent */
896 self
->transient_for
->transients
=
897 g_slist_remove(self
->transient_for
->transients
, self
);
899 self
->transient_for
= target
;
900 if (self
->transient_for
== OB_TRAN_GROUP
) { /* transient of group */
903 /* add to new parents */
904 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
905 ObClient
*c
= it
->data
;
906 if (c
!= self
&& !c
->transient_for
)
907 c
->transients
= g_slist_append(c
->transients
, self
);
910 /* remove all transients which are in the group, that causes
911 circlular pointer hell of doom */
912 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
914 for (sit
= self
->transients
; sit
; sit
= next
) {
915 next
= g_slist_next(sit
);
916 if (sit
->data
== it
->data
)
918 g_slist_delete_link(self
->transients
, sit
);
921 } else if (self
->transient_for
!= NULL
) { /* transient of window */
922 /* add to new parent */
923 self
->transient_for
->transients
=
924 g_slist_append(self
->transient_for
->transients
, self
);
929 static void client_get_mwm_hints(ObClient
*self
)
934 self
->mwmhints
.flags
= 0; /* default to none */
936 if (PROP_GETA32(self
->window
, motif_wm_hints
, motif_wm_hints
,
938 if (num
>= OB_MWM_ELEMENTS
) {
939 self
->mwmhints
.flags
= hints
[0];
940 self
->mwmhints
.functions
= hints
[1];
941 self
->mwmhints
.decorations
= hints
[2];
947 void client_get_type(ObClient
*self
)
954 if (PROP_GETA32(self
->window
, net_wm_window_type
, atom
, &val
, &num
)) {
955 /* use the first value that we know about in the array */
956 for (i
= 0; i
< num
; ++i
) {
957 if (val
[i
] == prop_atoms
.net_wm_window_type_desktop
)
958 self
->type
= OB_CLIENT_TYPE_DESKTOP
;
959 else if (val
[i
] == prop_atoms
.net_wm_window_type_dock
)
960 self
->type
= OB_CLIENT_TYPE_DOCK
;
961 else if (val
[i
] == prop_atoms
.net_wm_window_type_toolbar
)
962 self
->type
= OB_CLIENT_TYPE_TOOLBAR
;
963 else if (val
[i
] == prop_atoms
.net_wm_window_type_menu
)
964 self
->type
= OB_CLIENT_TYPE_MENU
;
965 else if (val
[i
] == prop_atoms
.net_wm_window_type_utility
)
966 self
->type
= OB_CLIENT_TYPE_UTILITY
;
967 else if (val
[i
] == prop_atoms
.net_wm_window_type_splash
)
968 self
->type
= OB_CLIENT_TYPE_SPLASH
;
969 else if (val
[i
] == prop_atoms
.net_wm_window_type_dialog
)
970 self
->type
= OB_CLIENT_TYPE_DIALOG
;
971 else if (val
[i
] == prop_atoms
.net_wm_window_type_normal
)
972 self
->type
= OB_CLIENT_TYPE_NORMAL
;
973 else if (val
[i
] == prop_atoms
.kde_net_wm_window_type_override
) {
974 /* prevent this window from getting any decor or
976 self
->mwmhints
.flags
&= (OB_MWM_FLAG_FUNCTIONS
|
977 OB_MWM_FLAG_DECORATIONS
);
978 self
->mwmhints
.decorations
= 0;
979 self
->mwmhints
.functions
= 0;
981 if (self
->type
!= (ObClientType
) -1)
982 break; /* grab the first legit type */
987 if (self
->type
== (ObClientType
) -1) {
988 /*the window type hint was not set, which means we either classify
989 ourself as a normal window or a dialog, depending on if we are a
992 self
->type
= OB_CLIENT_TYPE_DIALOG
;
994 self
->type
= OB_CLIENT_TYPE_NORMAL
;
998 void client_update_protocols(ObClient
*self
)
1001 guint num_return
, i
;
1003 self
->focus_notify
= FALSE
;
1004 self
->delete_window
= FALSE
;
1006 if (PROP_GETA32(self
->window
, wm_protocols
, atom
, &proto
, &num_return
)) {
1007 for (i
= 0; i
< num_return
; ++i
) {
1008 if (proto
[i
] == prop_atoms
.wm_delete_window
) {
1009 /* this means we can request the window to close */
1010 self
->delete_window
= TRUE
;
1011 } else if (proto
[i
] == prop_atoms
.wm_take_focus
)
1012 /* if this protocol is requested, then the window will be
1013 notified whenever we want it to receive focus */
1014 self
->focus_notify
= TRUE
;
1020 static void client_get_gravity(ObClient
*self
)
1022 XWindowAttributes wattrib
;
1025 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
1026 g_assert(ret
!= BadWindow
);
1027 self
->gravity
= wattrib
.win_gravity
;
1030 void client_update_normal_hints(ObClient
*self
)
1034 int oldgravity
= self
->gravity
;
1037 self
->min_ratio
= 0.0f
;
1038 self
->max_ratio
= 0.0f
;
1039 SIZE_SET(self
->size_inc
, 1, 1);
1040 SIZE_SET(self
->base_size
, 0, 0);
1041 SIZE_SET(self
->min_size
, 0, 0);
1042 SIZE_SET(self
->max_size
, G_MAXINT
, G_MAXINT
);
1044 /* get the hints from the window */
1045 if (XGetWMNormalHints(ob_display
, self
->window
, &size
, &ret
)) {
1046 self
->positioned
= !!(size
.flags
& (PPosition
|USPosition
));
1048 if (size
.flags
& PWinGravity
) {
1049 self
->gravity
= size
.win_gravity
;
1051 /* if the client has a frame, i.e. has already been mapped and
1052 is changing its gravity */
1053 if (self
->frame
&& self
->gravity
!= oldgravity
) {
1054 /* move our idea of the client's position based on its new
1056 self
->area
.x
= self
->frame
->area
.x
;
1057 self
->area
.y
= self
->frame
->area
.y
;
1058 frame_frame_gravity(self
->frame
, &self
->area
.x
, &self
->area
.y
);
1062 if (size
.flags
& PAspect
) {
1063 if (size
.min_aspect
.y
)
1064 self
->min_ratio
= (float)size
.min_aspect
.x
/ size
.min_aspect
.y
;
1065 if (size
.max_aspect
.y
)
1066 self
->max_ratio
= (float)size
.max_aspect
.x
/ size
.max_aspect
.y
;
1069 if (size
.flags
& PMinSize
)
1070 SIZE_SET(self
->min_size
, size
.min_width
, size
.min_height
);
1072 if (size
.flags
& PMaxSize
)
1073 SIZE_SET(self
->max_size
, size
.max_width
, size
.max_height
);
1075 if (size
.flags
& PBaseSize
)
1076 SIZE_SET(self
->base_size
, size
.base_width
, size
.base_height
);
1078 if (size
.flags
& PResizeInc
)
1079 SIZE_SET(self
->size_inc
, size
.width_inc
, size
.height_inc
);
1083 void client_setup_decor_and_functions(ObClient
*self
)
1085 /* start with everything (cept fullscreen) */
1087 (OB_FRAME_DECOR_TITLEBAR
|
1088 (ob_rr_theme
->show_handle
? OB_FRAME_DECOR_HANDLE
: 0) |
1089 OB_FRAME_DECOR_GRIPS
|
1090 OB_FRAME_DECOR_BORDER
|
1091 OB_FRAME_DECOR_ICON
|
1092 OB_FRAME_DECOR_ALLDESKTOPS
|
1093 OB_FRAME_DECOR_ICONIFY
|
1094 OB_FRAME_DECOR_MAXIMIZE
|
1095 OB_FRAME_DECOR_SHADE
);
1097 (OB_CLIENT_FUNC_RESIZE
|
1098 OB_CLIENT_FUNC_MOVE
|
1099 OB_CLIENT_FUNC_ICONIFY
|
1100 OB_CLIENT_FUNC_MAXIMIZE
|
1101 OB_CLIENT_FUNC_SHADE
);
1102 if (self
->delete_window
) {
1103 self
->functions
|= OB_CLIENT_FUNC_CLOSE
;
1104 self
->decorations
|= OB_FRAME_DECOR_CLOSE
;
1107 if (!(self
->min_size
.width
< self
->max_size
.width
||
1108 self
->min_size
.height
< self
->max_size
.height
))
1109 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
1111 switch (self
->type
) {
1112 case OB_CLIENT_TYPE_NORMAL
:
1113 /* normal windows retain all of the possible decorations and
1114 functionality, and are the only windows that you can fullscreen */
1115 self
->functions
|= OB_CLIENT_FUNC_FULLSCREEN
;
1118 case OB_CLIENT_TYPE_DIALOG
:
1119 case OB_CLIENT_TYPE_UTILITY
:
1120 /* these windows cannot be maximized */
1121 self
->functions
&= ~OB_CLIENT_FUNC_MAXIMIZE
;
1124 case OB_CLIENT_TYPE_MENU
:
1125 case OB_CLIENT_TYPE_TOOLBAR
:
1126 /* these windows get less functionality */
1127 self
->functions
&= ~(OB_CLIENT_FUNC_ICONIFY
| OB_CLIENT_FUNC_RESIZE
);
1130 case OB_CLIENT_TYPE_DESKTOP
:
1131 case OB_CLIENT_TYPE_DOCK
:
1132 case OB_CLIENT_TYPE_SPLASH
:
1133 /* none of these windows are manipulated by the window manager */
1134 self
->decorations
= 0;
1135 self
->functions
= 0;
1139 /* Mwm Hints are applied subtractively to what has already been chosen for
1140 decor and functionality */
1141 if (self
->mwmhints
.flags
& OB_MWM_FLAG_DECORATIONS
) {
1142 if (! (self
->mwmhints
.decorations
& OB_MWM_DECOR_ALL
)) {
1143 if (! ((self
->mwmhints
.decorations
& OB_MWM_DECOR_HANDLE
) ||
1144 (self
->mwmhints
.decorations
& OB_MWM_DECOR_TITLE
)))
1145 /* if the mwm hints request no handle or title, then all
1146 decorations are disabled */
1147 self
->decorations
= 0;
1151 if (self
->mwmhints
.flags
& OB_MWM_FLAG_FUNCTIONS
) {
1152 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_ALL
)) {
1153 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_RESIZE
))
1154 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
1155 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_MOVE
))
1156 self
->functions
&= ~OB_CLIENT_FUNC_MOVE
;
1157 /* dont let mwm hints kill any buttons
1158 if (! (self->mwmhints.functions & OB_MWM_FUNC_ICONIFY))
1159 self->functions &= ~OB_CLIENT_FUNC_ICONIFY;
1160 if (! (self->mwmhints.functions & OB_MWM_FUNC_MAXIMIZE))
1161 self->functions &= ~OB_CLIENT_FUNC_MAXIMIZE;
1163 /* dont let mwm hints kill the close button
1164 if (! (self->mwmhints.functions & MwmFunc_Close))
1165 self->functions &= ~OB_CLIENT_FUNC_CLOSE; */
1169 if (!(self
->functions
& OB_CLIENT_FUNC_SHADE
))
1170 self
->decorations
&= ~OB_FRAME_DECOR_SHADE
;
1171 if (!(self
->functions
& OB_CLIENT_FUNC_ICONIFY
))
1172 self
->decorations
&= ~OB_FRAME_DECOR_ICONIFY
;
1173 if (!(self
->functions
& OB_CLIENT_FUNC_RESIZE
))
1174 self
->decorations
&= ~OB_FRAME_DECOR_GRIPS
;
1176 /* can't maximize without moving/resizing */
1177 if (!((self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) &&
1178 (self
->functions
& OB_CLIENT_FUNC_MOVE
) &&
1179 (self
->functions
& OB_CLIENT_FUNC_RESIZE
))) {
1180 self
->functions
&= ~OB_CLIENT_FUNC_MAXIMIZE
;
1181 self
->decorations
&= ~OB_FRAME_DECOR_MAXIMIZE
;
1184 /* kill the handle on fully maxed windows */
1185 if (self
->max_vert
&& self
->max_horz
)
1186 self
->decorations
&= ~OB_FRAME_DECOR_HANDLE
;
1188 /* finally, the user can have requested no decorations, which overrides
1189 everything (but doesnt give it a border if it doesnt have one) */
1190 if (self
->undecorated
)
1191 self
->decorations
&= OB_FRAME_DECOR_BORDER
;
1193 /* if we don't have a titlebar, then we cannot shade! */
1194 if (!(self
->decorations
& OB_FRAME_DECOR_TITLEBAR
))
1195 self
->functions
&= ~OB_CLIENT_FUNC_SHADE
;
1197 /* now we need to check against rules for the client's current state */
1198 if (self
->fullscreen
) {
1199 self
->functions
&= (OB_CLIENT_FUNC_CLOSE
|
1200 OB_CLIENT_FUNC_FULLSCREEN
|
1201 OB_CLIENT_FUNC_ICONIFY
);
1202 self
->decorations
= 0;
1205 client_change_allowed_actions(self
);
1208 /* adjust the client's decorations, etc. */
1209 client_reconfigure(self
);
1211 /* this makes sure that these windows appear on all desktops */
1212 if (self
->type
== OB_CLIENT_TYPE_DESKTOP
&&
1213 self
->desktop
!= DESKTOP_ALL
)
1215 self
->desktop
= DESKTOP_ALL
;
1220 static void client_change_allowed_actions(ObClient
*self
)
1225 /* desktop windows are kept on all desktops */
1226 if (self
->type
!= OB_CLIENT_TYPE_DESKTOP
)
1227 actions
[num
++] = prop_atoms
.net_wm_action_change_desktop
;
1229 if (self
->functions
& OB_CLIENT_FUNC_SHADE
)
1230 actions
[num
++] = prop_atoms
.net_wm_action_shade
;
1231 if (self
->functions
& OB_CLIENT_FUNC_CLOSE
)
1232 actions
[num
++] = prop_atoms
.net_wm_action_close
;
1233 if (self
->functions
& OB_CLIENT_FUNC_MOVE
)
1234 actions
[num
++] = prop_atoms
.net_wm_action_move
;
1235 if (self
->functions
& OB_CLIENT_FUNC_ICONIFY
)
1236 actions
[num
++] = prop_atoms
.net_wm_action_minimize
;
1237 if (self
->functions
& OB_CLIENT_FUNC_RESIZE
)
1238 actions
[num
++] = prop_atoms
.net_wm_action_resize
;
1239 if (self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
)
1240 actions
[num
++] = prop_atoms
.net_wm_action_fullscreen
;
1241 if (self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) {
1242 actions
[num
++] = prop_atoms
.net_wm_action_maximize_horz
;
1243 actions
[num
++] = prop_atoms
.net_wm_action_maximize_vert
;
1246 PROP_SETA32(self
->window
, net_wm_allowed_actions
, atom
, actions
, num
);
1248 /* make sure the window isn't breaking any rules now */
1250 if (!(self
->functions
& OB_CLIENT_FUNC_SHADE
) && self
->shaded
) {
1251 if (self
->frame
) client_shade(self
, FALSE
);
1252 else self
->shaded
= FALSE
;
1254 if (!(self
->functions
& OB_CLIENT_FUNC_ICONIFY
) && self
->iconic
) {
1255 if (self
->frame
) client_iconify(self
, FALSE
, TRUE
);
1256 else self
->iconic
= FALSE
;
1258 if (!(self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
) && self
->fullscreen
) {
1259 if (self
->frame
) client_fullscreen(self
, FALSE
, TRUE
);
1260 else self
->fullscreen
= FALSE
;
1262 if (!(self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) && (self
->max_horz
||
1264 if (self
->frame
) client_maximize(self
, FALSE
, 0, TRUE
);
1265 else self
->max_vert
= self
->max_horz
= FALSE
;
1269 void client_reconfigure(ObClient
*self
)
1271 /* by making this pass FALSE for user, we avoid the emacs event storm where
1272 every configurenotify causes an update in its normal hints, i think this
1273 is generally what we want anyways... */
1274 client_configure(self
, OB_CORNER_TOPLEFT
, self
->area
.x
, self
->area
.y
,
1275 self
->area
.width
, self
->area
.height
, FALSE
, TRUE
);
1278 void client_update_wmhints(ObClient
*self
)
1281 gboolean ur
= FALSE
;
1284 /* assume a window takes input if it doesnt specify */
1285 self
->can_focus
= TRUE
;
1287 if ((hints
= XGetWMHints(ob_display
, self
->window
)) != NULL
) {
1288 if (hints
->flags
& InputHint
)
1289 self
->can_focus
= hints
->input
;
1291 /* only do this when first managing the window *AND* when we aren't
1293 if (ob_state() != OB_STATE_STARTING
&& self
->frame
== NULL
)
1294 if (hints
->flags
& StateHint
)
1295 self
->iconic
= hints
->initial_state
== IconicState
;
1297 if (hints
->flags
& XUrgencyHint
)
1300 if (!(hints
->flags
& WindowGroupHint
))
1301 hints
->window_group
= None
;
1303 /* did the group state change? */
1304 if (hints
->window_group
!=
1305 (self
->group
? self
->group
->leader
: None
)) {
1306 /* remove from the old group if there was one */
1307 if (self
->group
!= NULL
) {
1308 /* remove transients of the group */
1309 for (it
= self
->group
->members
; it
; it
= it
->next
)
1310 self
->transients
= g_slist_remove(self
->transients
,
1313 /* remove myself from parents in the group */
1314 if (self
->transient_for
== OB_TRAN_GROUP
) {
1315 for (it
= self
->group
->members
; it
; it
= it
->next
) {
1316 ObClient
*c
= it
->data
;
1318 if (c
!= self
&& !c
->transient_for
)
1319 c
->transients
= g_slist_remove(c
->transients
,
1324 group_remove(self
->group
, self
);
1327 if (hints
->window_group
!= None
) {
1328 self
->group
= group_add(hints
->window_group
, self
);
1330 /* i can only have transients from the group if i am not
1332 if (!self
->transient_for
) {
1333 /* add other transients of the group that are already
1335 for (it
= self
->group
->members
; it
; it
= it
->next
) {
1336 ObClient
*c
= it
->data
;
1337 if (c
!= self
&& c
->transient_for
== OB_TRAN_GROUP
)
1339 g_slist_append(self
->transients
, c
);
1344 /* because the self->transient flag wont change from this call,
1345 we don't need to update the window's type and such, only its
1346 transient_for, and the transients lists of other windows in
1347 the group may be affected */
1348 client_update_transient_for(self
);
1351 /* the WM_HINTS can contain an icon */
1352 client_update_icons(self
);
1357 if (ur
!= self
->urgent
) {
1359 /* fire the urgent callback if we're mapped, otherwise, wait until
1360 after we're mapped */
1362 client_urgent_notify(self
);
1366 void client_update_title(ObClient
*self
)
1372 gboolean read_title
;
1375 old_title
= self
->title
;
1378 if (!PROP_GETS(self
->window
, net_wm_name
, utf8
, &data
))
1379 /* try old x stuff */
1380 if (!PROP_GETS(self
->window
, wm_name
, locale
, &data
))
1381 data
= g_strdup("Unnamed Window");
1383 /* did the title change? then reset the title_count */
1384 if (old_title
&& 0 != strncmp(old_title
, data
, strlen(data
)))
1385 self
->title_count
= 1;
1387 /* look for duplicates and append a number */
1389 for (it
= client_list
; it
; it
= it
->next
)
1390 if (it
->data
!= self
) {
1391 ObClient
*c
= it
->data
;
1392 if (0 == strncmp(c
->title
, data
, strlen(data
)))
1393 nums
|= 1 << c
->title_count
;
1395 /* find first free number */
1396 for (i
= 1; i
<= 32; ++i
)
1397 if (!(nums
& (1 << i
))) {
1398 if (self
->title_count
== 1 || i
== 1)
1399 self
->title_count
= i
;
1402 /* dont display the number for the first window */
1403 if (self
->title_count
> 1) {
1405 ndata
= g_strdup_printf("%s - [%u]", data
, self
->title_count
);
1410 PROP_SETS(self
->window
, net_wm_visible_name
, data
);
1415 frame_adjust_title(self
->frame
);
1419 /* update the icon title */
1421 g_free(self
->icon_title
);
1425 if (!PROP_GETS(self
->window
, net_wm_icon_name
, utf8
, &data
))
1426 /* try old x stuff */
1427 if (!PROP_GETS(self
->window
, wm_icon_name
, locale
, &data
)) {
1428 data
= g_strdup(self
->title
);
1432 /* append the title count, dont display the number for the first window */
1433 if (read_title
&& self
->title_count
> 1) {
1434 char *vdata
, *ndata
;
1435 ndata
= g_strdup_printf(" - [%u]", self
->title_count
);
1436 vdata
= g_strconcat(data
, ndata
, NULL
);
1442 PROP_SETS(self
->window
, net_wm_visible_icon_name
, data
);
1444 self
->icon_title
= data
;
1447 void client_update_class(ObClient
*self
)
1452 if (self
->name
) g_free(self
->name
);
1453 if (self
->class) g_free(self
->class);
1454 if (self
->role
) g_free(self
->role
);
1456 self
->name
= self
->class = self
->role
= NULL
;
1458 if (PROP_GETSS(self
->window
, wm_class
, locale
, &data
)) {
1460 self
->name
= g_strdup(data
[0]);
1462 self
->class = g_strdup(data
[1]);
1467 if (PROP_GETS(self
->window
, wm_window_role
, locale
, &s
))
1470 if (self
->name
== NULL
) self
->name
= g_strdup("");
1471 if (self
->class == NULL
) self
->class = g_strdup("");
1472 if (self
->role
== NULL
) self
->role
= g_strdup("");
1475 void client_update_strut(ObClient
*self
)
1479 gboolean got
= FALSE
;
1482 if (PROP_GETA32(self
->window
, net_wm_strut_partial
, cardinal
,
1486 STRUT_PARTIAL_SET(strut
,
1487 data
[0], data
[2], data
[1], data
[3],
1488 data
[4], data
[5], data
[8], data
[9],
1489 data
[6], data
[7], data
[10], data
[11]);
1495 PROP_GETA32(self
->window
, net_wm_strut
, cardinal
, &data
, &num
)) {
1498 STRUT_PARTIAL_SET(strut
,
1499 data
[0], data
[2], data
[1], data
[3],
1500 0, 0, 0, 0, 0, 0, 0, 0);
1506 STRUT_PARTIAL_SET(strut
, 0, 0, 0, 0,
1507 0, 0, 0, 0, 0, 0, 0, 0);
1509 if (!STRUT_EQUAL(strut
, self
->strut
)) {
1510 self
->strut
= strut
;
1512 /* updating here is pointless while we're being mapped cuz we're not in
1513 the client list yet */
1515 screen_update_areas();
1519 void client_update_icons(ObClient
*self
)
1525 for (i
= 0; i
< self
->nicons
; ++i
)
1526 g_free(self
->icons
[i
].data
);
1527 if (self
->nicons
> 0)
1528 g_free(self
->icons
);
1531 if (PROP_GETA32(self
->window
, net_wm_icon
, cardinal
, &data
, &num
)) {
1532 /* figure out how many valid icons are in here */
1534 while (num
- i
> 2) {
1538 if (i
> num
|| w
*h
== 0) break;
1542 self
->icons
= g_new(ObClientIcon
, self
->nicons
);
1544 /* store the icons */
1546 for (j
= 0; j
< self
->nicons
; ++j
) {
1549 w
= self
->icons
[j
].width
= data
[i
++];
1550 h
= self
->icons
[j
].height
= data
[i
++];
1552 if (w
*h
== 0) continue;
1554 self
->icons
[j
].data
= g_new(RrPixel32
, w
* h
);
1555 for (x
= 0, y
= 0, t
= 0; t
< w
* h
; ++t
, ++x
, ++i
) {
1560 self
->icons
[j
].data
[t
] =
1561 (((data
[i
] >> 24) & 0xff) << RrDefaultAlphaOffset
) +
1562 (((data
[i
] >> 16) & 0xff) << RrDefaultRedOffset
) +
1563 (((data
[i
] >> 8) & 0xff) << RrDefaultGreenOffset
) +
1564 (((data
[i
] >> 0) & 0xff) << RrDefaultBlueOffset
);
1570 } else if (PROP_GETA32(self
->window
, kwm_win_icon
,
1571 kwm_win_icon
, &data
, &num
)) {
1574 self
->icons
= g_new(ObClientIcon
, self
->nicons
);
1575 xerror_set_ignore(TRUE
);
1576 if (!RrPixmapToRGBA(ob_rr_inst
,
1578 &self
->icons
[self
->nicons
-1].width
,
1579 &self
->icons
[self
->nicons
-1].height
,
1580 &self
->icons
[self
->nicons
-1].data
)) {
1581 g_free(&self
->icons
[self
->nicons
-1]);
1584 xerror_set_ignore(FALSE
);
1590 if ((hints
= XGetWMHints(ob_display
, self
->window
))) {
1591 if (hints
->flags
& IconPixmapHint
) {
1593 self
->icons
= g_new(ObClientIcon
, self
->nicons
);
1594 xerror_set_ignore(TRUE
);
1595 if (!RrPixmapToRGBA(ob_rr_inst
,
1597 (hints
->flags
& IconMaskHint
?
1598 hints
->icon_mask
: None
),
1599 &self
->icons
[self
->nicons
-1].width
,
1600 &self
->icons
[self
->nicons
-1].height
,
1601 &self
->icons
[self
->nicons
-1].data
)){
1602 g_free(&self
->icons
[self
->nicons
-1]);
1605 xerror_set_ignore(FALSE
);
1612 frame_adjust_icon(self
->frame
);
1615 static void client_change_state(ObClient
*self
)
1618 guint32 netstate
[11];
1621 state
[0] = self
->wmstate
;
1623 PROP_SETA32(self
->window
, wm_state
, wm_state
, state
, 2);
1627 netstate
[num
++] = prop_atoms
.net_wm_state_modal
;
1629 netstate
[num
++] = prop_atoms
.net_wm_state_shaded
;
1631 netstate
[num
++] = prop_atoms
.net_wm_state_hidden
;
1632 if (self
->skip_taskbar
)
1633 netstate
[num
++] = prop_atoms
.net_wm_state_skip_taskbar
;
1634 if (self
->skip_pager
)
1635 netstate
[num
++] = prop_atoms
.net_wm_state_skip_pager
;
1636 if (self
->fullscreen
)
1637 netstate
[num
++] = prop_atoms
.net_wm_state_fullscreen
;
1639 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_vert
;
1641 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_horz
;
1643 netstate
[num
++] = prop_atoms
.net_wm_state_above
;
1645 netstate
[num
++] = prop_atoms
.net_wm_state_below
;
1646 if (self
->undecorated
)
1647 netstate
[num
++] = prop_atoms
.ob_wm_state_undecorated
;
1648 PROP_SETA32(self
->window
, net_wm_state
, atom
, netstate
, num
);
1650 client_calc_layer(self
);
1653 frame_adjust_state(self
->frame
);
1656 ObClient
*client_search_focus_tree(ObClient
*self
)
1661 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
) {
1662 if (client_focused(it
->data
)) return it
->data
;
1663 if ((ret
= client_search_focus_tree(it
->data
))) return ret
;
1668 ObClient
*client_search_focus_tree_full(ObClient
*self
)
1670 if (self
->transient_for
) {
1671 if (self
->transient_for
!= OB_TRAN_GROUP
) {
1672 return client_search_focus_tree_full(self
->transient_for
);
1675 gboolean recursed
= FALSE
;
1677 for (it
= self
->group
->members
; it
; it
= it
->next
)
1678 if (!((ObClient
*)it
->data
)->transient_for
) {
1680 if ((c
= client_search_focus_tree_full(it
->data
)))
1689 /* this function checks the whole tree, the client_search_focus_tree~
1690 does not, so we need to check this window */
1691 if (client_focused(self
))
1693 return client_search_focus_tree(self
);
1696 static ObStackingLayer
calc_layer(ObClient
*self
)
1700 if (self
->fullscreen
&&
1701 (client_focused(self
) || client_search_focus_tree(self
)))
1702 l
= OB_STACKING_LAYER_FULLSCREEN
;
1703 else if (self
->type
== OB_CLIENT_TYPE_DESKTOP
)
1704 l
= OB_STACKING_LAYER_DESKTOP
;
1705 else if (self
->type
== OB_CLIENT_TYPE_DOCK
) {
1706 if (self
->above
) l
= OB_STACKING_LAYER_DOCK_ABOVE
;
1707 else if (self
->below
) l
= OB_STACKING_LAYER_DOCK_BELOW
;
1708 else l
= OB_STACKING_LAYER_NORMAL
;
1710 else if (self
->above
) l
= OB_STACKING_LAYER_ABOVE
;
1711 else if (self
->below
) l
= OB_STACKING_LAYER_BELOW
;
1712 else l
= OB_STACKING_LAYER_NORMAL
;
1717 static void client_calc_layer_recursive(ObClient
*self
, ObClient
*orig
,
1718 ObStackingLayer l
, gboolean raised
)
1720 ObStackingLayer old
, own
;
1724 own
= calc_layer(self
);
1725 self
->layer
= l
> own
? l
: own
;
1727 for (it
= self
->transients
; it
; it
= it
->next
)
1728 client_calc_layer_recursive(it
->data
, orig
,
1729 l
, raised
? raised
: l
!= old
);
1731 if (!raised
&& l
!= old
)
1732 if (orig
->frame
) { /* only restack if the original window is managed */
1733 /* XXX add_non_intrusive ever? */
1734 stacking_remove(CLIENT_AS_WINDOW(self
));
1735 stacking_add(CLIENT_AS_WINDOW(self
));
1739 void client_calc_layer(ObClient
*self
)
1746 /* transients take on the layer of their parents */
1747 self
= client_search_top_transient(self
);
1749 l
= calc_layer(self
);
1751 client_calc_layer_recursive(self
, orig
, l
, FALSE
);
1754 gboolean
client_should_show(ObClient
*self
)
1756 if (self
->iconic
) return FALSE
;
1757 else if (!(self
->desktop
== screen_desktop
||
1758 self
->desktop
== DESKTOP_ALL
)) return FALSE
;
1759 else if (client_normal(self
) && screen_showing_desktop
) return FALSE
;
1764 static void client_showhide(ObClient
*self
)
1767 if (client_should_show(self
))
1768 frame_show(self
->frame
);
1770 frame_hide(self
->frame
);
1773 gboolean
client_normal(ObClient
*self
) {
1774 return ! (self
->type
== OB_CLIENT_TYPE_DESKTOP
||
1775 self
->type
== OB_CLIENT_TYPE_DOCK
||
1776 self
->type
== OB_CLIENT_TYPE_SPLASH
);
1779 static void client_apply_startup_state(ObClient
*self
)
1781 /* these are in a carefully crafted order.. */
1784 self
->iconic
= FALSE
;
1785 client_iconify(self
, TRUE
, FALSE
);
1787 if (self
->fullscreen
) {
1788 self
->fullscreen
= FALSE
;
1789 client_fullscreen(self
, TRUE
, FALSE
);
1791 if (self
->undecorated
) {
1792 self
->undecorated
= FALSE
;
1793 client_set_undecorated(self
, TRUE
);
1796 self
->shaded
= FALSE
;
1797 client_shade(self
, TRUE
);
1800 client_urgent_notify(self
);
1802 if (self
->max_vert
&& self
->max_horz
) {
1803 self
->max_vert
= self
->max_horz
= FALSE
;
1804 client_maximize(self
, TRUE
, 0, FALSE
);
1805 } else if (self
->max_vert
) {
1806 self
->max_vert
= FALSE
;
1807 client_maximize(self
, TRUE
, 2, FALSE
);
1808 } else if (self
->max_horz
) {
1809 self
->max_horz
= FALSE
;
1810 client_maximize(self
, TRUE
, 1, FALSE
);
1813 /* nothing to do for the other states:
1822 void client_configure_full(ObClient
*self
, ObCorner anchor
,
1823 int x
, int y
, int w
, int h
,
1824 gboolean user
, gboolean final
,
1825 gboolean force_reply
)
1828 gboolean send_resize_client
;
1829 gboolean moved
= FALSE
, resized
= FALSE
;
1830 guint fdecor
= self
->frame
->decorations
;
1831 gboolean fhorz
= self
->frame
->max_horz
;
1833 /* make the frame recalculate its dimentions n shit without changing
1834 anything visible for real, this way the constraints below can work with
1835 the updated frame dimensions. */
1836 frame_adjust_area(self
->frame
, TRUE
, TRUE
, TRUE
);
1838 /* gets the frame's position */
1839 frame_client_gravity(self
->frame
, &x
, &y
);
1841 /* these positions are frame positions, not client positions */
1843 /* set the size and position if fullscreen */
1844 if (self
->fullscreen
) {
1847 XF86VidModeModeLine mode
;
1852 i
= client_monitor(self
);
1853 a
= screen_physical_area_monitor(i
);
1856 if (i
== 0 && /* primary head */
1857 extensions_vidmode
&&
1858 XF86VidModeGetViewPort(ob_display
, ob_screen
, &x
, &y
) &&
1859 /* get the mode last so the mode.privsize isnt freed incorrectly */
1860 XF86VidModeGetModeLine(ob_display
, ob_screen
, &dot
, &mode
)) {
1865 if (mode
.privsize
) XFree(mode
.private);
1875 user
= FALSE
; /* ignore that increment etc shit when in fullscreen */
1879 a
= screen_area_monitor(self
->desktop
, client_monitor(self
));
1881 /* set the size and position if maximized */
1882 if (self
->max_horz
) {
1884 w
= a
->width
- self
->frame
->size
.left
- self
->frame
->size
.right
;
1886 if (self
->max_vert
) {
1888 h
= a
->height
- self
->frame
->size
.top
- self
->frame
->size
.bottom
;
1892 /* gets the client's position */
1893 frame_frame_gravity(self
->frame
, &x
, &y
);
1895 /* these override the above states! if you cant move you can't move! */
1897 if (!(self
->functions
& OB_CLIENT_FUNC_MOVE
)) {
1901 if (!(self
->functions
& OB_CLIENT_FUNC_RESIZE
)) {
1902 w
= self
->area
.width
;
1903 h
= self
->area
.height
;
1907 if (!(w
== self
->area
.width
&& h
== self
->area
.height
)) {
1908 int basew
, baseh
, minw
, minh
;
1910 /* base size is substituted with min size if not specified */
1911 if (self
->base_size
.width
|| self
->base_size
.height
) {
1912 basew
= self
->base_size
.width
;
1913 baseh
= self
->base_size
.height
;
1915 basew
= self
->min_size
.width
;
1916 baseh
= self
->min_size
.height
;
1918 /* min size is substituted with base size if not specified */
1919 if (self
->min_size
.width
|| self
->min_size
.height
) {
1920 minw
= self
->min_size
.width
;
1921 minh
= self
->min_size
.height
;
1923 minw
= self
->base_size
.width
;
1924 minh
= self
->base_size
.height
;
1927 /* if this is a user-requested resize, then check against min/max
1930 /* smaller than min size or bigger than max size? */
1931 if (w
> self
->max_size
.width
) w
= self
->max_size
.width
;
1932 if (w
< minw
) w
= minw
;
1933 if (h
> self
->max_size
.height
) h
= self
->max_size
.height
;
1934 if (h
< minh
) h
= minh
;
1939 /* keep to the increments */
1940 w
/= self
->size_inc
.width
;
1941 h
/= self
->size_inc
.height
;
1943 /* you cannot resize to nothing */
1944 if (basew
+ w
< 1) w
= 1 - basew
;
1945 if (baseh
+ h
< 1) h
= 1 - baseh
;
1947 /* store the logical size */
1948 SIZE_SET(self
->logical_size
,
1949 self
->size_inc
.width
> 1 ? w
: w
+ basew
,
1950 self
->size_inc
.height
> 1 ? h
: h
+ baseh
);
1952 w
*= self
->size_inc
.width
;
1953 h
*= self
->size_inc
.height
;
1958 /* adjust the height to match the width for the aspect ratios.
1959 for this, min size is not substituted for base size ever. */
1960 w
-= self
->base_size
.width
;
1961 h
-= self
->base_size
.height
;
1963 if (self
->min_ratio
)
1964 if (h
* self
->min_ratio
> w
) {
1965 h
= (int)(w
/ self
->min_ratio
);
1967 /* you cannot resize to nothing */
1970 w
= (int)(h
* self
->min_ratio
);
1973 if (self
->max_ratio
)
1974 if (h
* self
->max_ratio
< w
) {
1975 h
= (int)(w
/ self
->max_ratio
);
1977 /* you cannot resize to nothing */
1980 w
= (int)(h
* self
->min_ratio
);
1984 w
+= self
->base_size
.width
;
1985 h
+= self
->base_size
.height
;
1992 case OB_CORNER_TOPLEFT
:
1994 case OB_CORNER_TOPRIGHT
:
1995 x
-= w
- self
->area
.width
;
1997 case OB_CORNER_BOTTOMLEFT
:
1998 y
-= h
- self
->area
.height
;
2000 case OB_CORNER_BOTTOMRIGHT
:
2001 x
-= w
- self
->area
.width
;
2002 y
-= h
- self
->area
.height
;
2006 moved
= x
!= self
->area
.x
|| y
!= self
->area
.y
;
2007 resized
= w
!= self
->area
.width
|| h
!= self
->area
.height
;
2009 oldw
= self
->area
.width
;
2010 oldh
= self
->area
.height
;
2011 RECT_SET(self
->area
, x
, y
, w
, h
);
2013 /* for app-requested resizes, always resize if 'resized' is true.
2014 for user-requested ones, only resize if final is true, or when
2015 resizing in redraw mode */
2016 send_resize_client
= ((!user
&& resized
) ||
2018 (resized
&& config_redraw_resize
))));
2020 /* if the client is enlarging, the resize the client before the frame */
2021 if (send_resize_client
&& user
&& (w
> oldw
|| h
> oldh
))
2022 XResizeWindow(ob_display
, self
->window
, MAX(w
, oldw
), MAX(h
, oldh
));
2024 /* move/resize the frame to match the request */
2026 if (self
->decorations
!= fdecor
|| self
->max_horz
!= fhorz
)
2027 moved
= resized
= TRUE
;
2029 if (moved
|| resized
)
2030 frame_adjust_area(self
->frame
, moved
, resized
, FALSE
);
2032 if (!resized
&& (force_reply
|| ((!user
&& moved
) || (user
&& final
))))
2035 event
.type
= ConfigureNotify
;
2036 event
.xconfigure
.display
= ob_display
;
2037 event
.xconfigure
.event
= self
->window
;
2038 event
.xconfigure
.window
= self
->window
;
2040 /* root window real coords */
2041 event
.xconfigure
.x
= self
->frame
->area
.x
+ self
->frame
->size
.left
-
2043 event
.xconfigure
.y
= self
->frame
->area
.y
+ self
->frame
->size
.top
-
2045 event
.xconfigure
.width
= w
;
2046 event
.xconfigure
.height
= h
;
2047 event
.xconfigure
.border_width
= 0;
2048 event
.xconfigure
.above
= self
->frame
->plate
;
2049 event
.xconfigure
.override_redirect
= FALSE
;
2050 XSendEvent(event
.xconfigure
.display
, event
.xconfigure
.window
,
2051 FALSE
, StructureNotifyMask
, &event
);
2055 /* if the client is shrinking, then resize the frame before the client */
2056 if (send_resize_client
&& (!user
|| (w
<= oldw
|| h
<= oldh
)))
2057 XResizeWindow(ob_display
, self
->window
, w
, h
);
2062 void client_fullscreen(ObClient
*self
, gboolean fs
, gboolean savearea
)
2066 if (!(self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
) || /* can't */
2067 self
->fullscreen
== fs
) return; /* already done */
2069 self
->fullscreen
= fs
;
2070 client_change_state(self
); /* change the state hints on the client,
2071 and adjust out layer/stacking */
2075 self
->pre_fullscreen_area
= self
->area
;
2077 /* these are not actually used cuz client_configure will set them
2078 as appropriate when the window is fullscreened */
2083 if (self
->pre_fullscreen_area
.width
> 0 &&
2084 self
->pre_fullscreen_area
.height
> 0)
2086 x
= self
->pre_fullscreen_area
.x
;
2087 y
= self
->pre_fullscreen_area
.y
;
2088 w
= self
->pre_fullscreen_area
.width
;
2089 h
= self
->pre_fullscreen_area
.height
;
2090 RECT_SET(self
->pre_fullscreen_area
, 0, 0, 0, 0);
2092 /* pick some fallbacks... */
2093 a
= screen_area_monitor(self
->desktop
, 0);
2094 x
= a
->x
+ a
->width
/ 4;
2095 y
= a
->y
+ a
->height
/ 4;
2101 client_setup_decor_and_functions(self
);
2103 client_move_resize(self
, x
, y
, w
, h
);
2105 /* try focus us when we go into fullscreen mode */
2109 static void client_iconify_recursive(ObClient
*self
,
2110 gboolean iconic
, gboolean curdesk
)
2113 gboolean changed
= FALSE
;
2116 if (self
->iconic
!= iconic
) {
2117 ob_debug("%sconifying window: 0x%lx\n", (iconic
? "I" : "Uni"),
2120 self
->iconic
= iconic
;
2123 if (self
->functions
& OB_CLIENT_FUNC_ICONIFY
) {
2126 old
= self
->wmstate
;
2127 self
->wmstate
= IconicState
;
2128 if (old
!= self
->wmstate
)
2129 PROP_MSG(self
->window
, kde_wm_change_state
,
2130 self
->wmstate
, 1, 0, 0);
2132 self
->ignore_unmaps
++;
2133 /* we unmap the client itself so that we can get MapRequest
2134 events, and because the ICCCM tells us to! */
2135 XUnmapWindow(ob_display
, self
->window
);
2137 /* update the focus lists.. iconic windows go to the bottom of
2138 the list, put the new iconic window at the 'top of the
2140 focus_order_to_top(self
);
2148 client_set_desktop(self
, screen_desktop
, FALSE
);
2150 old
= self
->wmstate
;
2151 self
->wmstate
= self
->shaded
? IconicState
: NormalState
;
2152 if (old
!= self
->wmstate
)
2153 PROP_MSG(self
->window
, kde_wm_change_state
,
2154 self
->wmstate
, 1, 0, 0);
2156 XMapWindow(ob_display
, self
->window
);
2158 /* this puts it after the current focused window */
2159 focus_order_remove(self
);
2160 focus_order_add_new(self
);
2162 /* this is here cuz with the VIDMODE extension, the viewport can
2163 change while a fullscreen window is iconic, and when it
2164 uniconifies, it would be nice if it did so to the new position
2166 client_reconfigure(self
);
2173 client_change_state(self
);
2174 client_showhide(self
);
2175 screen_update_areas();
2178 /* iconify all transients */
2179 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
)
2180 if (it
->data
!= self
) client_iconify_recursive(it
->data
,
2184 void client_iconify(ObClient
*self
, gboolean iconic
, gboolean curdesk
)
2186 /* move up the transient chain as far as possible first */
2187 self
= client_search_top_transient(self
);
2189 client_iconify_recursive(client_search_top_transient(self
),
2193 void client_maximize(ObClient
*self
, gboolean max
, int dir
, gboolean savearea
)
2197 g_assert(dir
== 0 || dir
== 1 || dir
== 2);
2198 if (!(self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
)) return; /* can't */
2200 /* check if already done */
2202 if (dir
== 0 && self
->max_horz
&& self
->max_vert
) return;
2203 if (dir
== 1 && self
->max_horz
) return;
2204 if (dir
== 2 && self
->max_vert
) return;
2206 if (dir
== 0 && !self
->max_horz
&& !self
->max_vert
) return;
2207 if (dir
== 1 && !self
->max_horz
) return;
2208 if (dir
== 2 && !self
->max_vert
) return;
2211 /* we just tell it to configure in the same place and client_configure
2212 worries about filling the screen with the window */
2215 w
= self
->area
.width
;
2216 h
= self
->area
.height
;
2220 if ((dir
== 0 || dir
== 1) && !self
->max_horz
) { /* horz */
2221 RECT_SET(self
->pre_max_area
,
2222 self
->area
.x
, self
->pre_max_area
.y
,
2223 self
->area
.width
, self
->pre_max_area
.height
);
2225 if ((dir
== 0 || dir
== 2) && !self
->max_vert
) { /* vert */
2226 RECT_SET(self
->pre_max_area
,
2227 self
->pre_max_area
.x
, self
->area
.y
,
2228 self
->pre_max_area
.width
, self
->area
.height
);
2234 a
= screen_area_monitor(self
->desktop
, 0);
2235 if ((dir
== 0 || dir
== 1) && self
->max_horz
) { /* horz */
2236 if (self
->pre_max_area
.width
> 0) {
2237 x
= self
->pre_max_area
.x
;
2238 w
= self
->pre_max_area
.width
;
2240 RECT_SET(self
->pre_max_area
, 0, self
->pre_max_area
.y
,
2241 0, self
->pre_max_area
.height
);
2243 /* pick some fallbacks... */
2244 x
= a
->x
+ a
->width
/ 4;
2248 if ((dir
== 0 || dir
== 2) && self
->max_vert
) { /* vert */
2249 if (self
->pre_max_area
.height
> 0) {
2250 y
= self
->pre_max_area
.y
;
2251 h
= self
->pre_max_area
.height
;
2253 RECT_SET(self
->pre_max_area
, self
->pre_max_area
.x
, 0,
2254 self
->pre_max_area
.width
, 0);
2256 /* pick some fallbacks... */
2257 y
= a
->y
+ a
->height
/ 4;
2263 if (dir
== 0 || dir
== 1) /* horz */
2264 self
->max_horz
= max
;
2265 if (dir
== 0 || dir
== 2) /* vert */
2266 self
->max_vert
= max
;
2268 client_change_state(self
); /* change the state hints on the client */
2270 client_setup_decor_and_functions(self
);
2272 client_move_resize(self
, x
, y
, w
, h
);
2275 void client_shade(ObClient
*self
, gboolean shade
)
2277 if ((!(self
->functions
& OB_CLIENT_FUNC_SHADE
) &&
2278 shade
) || /* can't shade */
2279 self
->shaded
== shade
) return; /* already done */
2281 /* when we're iconic, don't change the wmstate */
2282 if (!self
->iconic
) {
2285 old
= self
->wmstate
;
2286 self
->wmstate
= shade
? IconicState
: NormalState
;
2287 if (old
!= self
->wmstate
)
2288 PROP_MSG(self
->window
, kde_wm_change_state
,
2289 self
->wmstate
, 1, 0, 0);
2292 self
->shaded
= shade
;
2293 client_change_state(self
);
2294 /* resize the frame to just the titlebar */
2295 frame_adjust_area(self
->frame
, FALSE
, FALSE
, FALSE
);
2298 void client_close(ObClient
*self
)
2302 if (!(self
->functions
& OB_CLIENT_FUNC_CLOSE
)) return;
2305 XXX: itd be cool to do timeouts and shit here for killing the client's
2307 like... if the window is around after 5 seconds, then the close button
2308 turns a nice red, and if this function is called again, the client is
2312 ce
.xclient
.type
= ClientMessage
;
2313 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
2314 ce
.xclient
.display
= ob_display
;
2315 ce
.xclient
.window
= self
->window
;
2316 ce
.xclient
.format
= 32;
2317 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_delete_window
;
2318 ce
.xclient
.data
.l
[1] = event_lasttime
;
2319 ce
.xclient
.data
.l
[2] = 0l;
2320 ce
.xclient
.data
.l
[3] = 0l;
2321 ce
.xclient
.data
.l
[4] = 0l;
2322 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
2325 void client_kill(ObClient
*self
)
2327 XKillClient(ob_display
, self
->window
);
2330 void client_set_desktop_recursive(ObClient
*self
,
2331 guint target
, gboolean donthide
)
2336 if (target
!= self
->desktop
) {
2338 ob_debug("Setting desktop %u\n", target
+1);
2340 g_assert(target
< screen_num_desktops
|| target
== DESKTOP_ALL
);
2342 /* remove from the old desktop(s) */
2343 focus_order_remove(self
);
2345 old
= self
->desktop
;
2346 self
->desktop
= target
;
2347 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, target
);
2348 /* the frame can display the current desktop state */
2349 frame_adjust_state(self
->frame
);
2350 /* 'move' the window to the new desktop */
2352 client_showhide(self
);
2353 /* raise if it was not already on the desktop */
2354 if (old
!= DESKTOP_ALL
)
2356 screen_update_areas();
2358 /* add to the new desktop(s) */
2359 if (config_focus_new
)
2360 focus_order_to_top(self
);
2362 focus_order_to_bottom(self
);
2365 /* move all transients */
2366 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
)
2367 if (it
->data
!= self
) client_set_desktop_recursive(it
->data
,
2371 void client_set_desktop(ObClient
*self
, guint target
, gboolean donthide
)
2373 client_set_desktop_recursive(client_search_top_transient(self
),
2377 ObClient
*client_search_modal_child(ObClient
*self
)
2382 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
) {
2383 ObClient
*c
= it
->data
;
2384 if ((ret
= client_search_modal_child(c
))) return ret
;
2385 if (c
->modal
) return c
;
2390 gboolean
client_validate(ObClient
*self
)
2394 XSync(ob_display
, FALSE
); /* get all events on the server */
2396 if (XCheckTypedWindowEvent(ob_display
, self
->window
, DestroyNotify
, &e
) ||
2397 XCheckTypedWindowEvent(ob_display
, self
->window
, UnmapNotify
, &e
)) {
2398 XPutBackEvent(ob_display
, &e
);
2405 void client_set_wm_state(ObClient
*self
, long state
)
2407 if (state
== self
->wmstate
) return; /* no change */
2411 client_iconify(self
, TRUE
, TRUE
);
2414 client_iconify(self
, FALSE
, TRUE
);
2419 void client_set_state(ObClient
*self
, Atom action
, long data1
, long data2
)
2421 gboolean shaded
= self
->shaded
;
2422 gboolean fullscreen
= self
->fullscreen
;
2423 gboolean undecorated
= self
->undecorated
;
2424 gboolean max_horz
= self
->max_horz
;
2425 gboolean max_vert
= self
->max_vert
;
2428 if (!(action
== prop_atoms
.net_wm_state_add
||
2429 action
== prop_atoms
.net_wm_state_remove
||
2430 action
== prop_atoms
.net_wm_state_toggle
))
2431 /* an invalid action was passed to the client message, ignore it */
2434 for (i
= 0; i
< 2; ++i
) {
2435 Atom state
= i
== 0 ? data1
: data2
;
2437 if (!state
) continue;
2439 /* if toggling, then pick whether we're adding or removing */
2440 if (action
== prop_atoms
.net_wm_state_toggle
) {
2441 if (state
== prop_atoms
.net_wm_state_modal
)
2442 action
= self
->modal
? prop_atoms
.net_wm_state_remove
:
2443 prop_atoms
.net_wm_state_add
;
2444 else if (state
== prop_atoms
.net_wm_state_maximized_vert
)
2445 action
= self
->max_vert
? prop_atoms
.net_wm_state_remove
:
2446 prop_atoms
.net_wm_state_add
;
2447 else if (state
== prop_atoms
.net_wm_state_maximized_horz
)
2448 action
= self
->max_horz
? prop_atoms
.net_wm_state_remove
:
2449 prop_atoms
.net_wm_state_add
;
2450 else if (state
== prop_atoms
.net_wm_state_shaded
)
2451 action
= shaded
? prop_atoms
.net_wm_state_remove
:
2452 prop_atoms
.net_wm_state_add
;
2453 else if (state
== prop_atoms
.net_wm_state_skip_taskbar
)
2454 action
= self
->skip_taskbar
?
2455 prop_atoms
.net_wm_state_remove
:
2456 prop_atoms
.net_wm_state_add
;
2457 else if (state
== prop_atoms
.net_wm_state_skip_pager
)
2458 action
= self
->skip_pager
?
2459 prop_atoms
.net_wm_state_remove
:
2460 prop_atoms
.net_wm_state_add
;
2461 else if (state
== prop_atoms
.net_wm_state_fullscreen
)
2462 action
= fullscreen
?
2463 prop_atoms
.net_wm_state_remove
:
2464 prop_atoms
.net_wm_state_add
;
2465 else if (state
== prop_atoms
.net_wm_state_above
)
2466 action
= self
->above
? prop_atoms
.net_wm_state_remove
:
2467 prop_atoms
.net_wm_state_add
;
2468 else if (state
== prop_atoms
.net_wm_state_below
)
2469 action
= self
->below
? prop_atoms
.net_wm_state_remove
:
2470 prop_atoms
.net_wm_state_add
;
2471 else if (state
== prop_atoms
.ob_wm_state_undecorated
)
2472 action
= undecorated
? prop_atoms
.net_wm_state_remove
:
2473 prop_atoms
.net_wm_state_add
;
2476 if (action
== prop_atoms
.net_wm_state_add
) {
2477 if (state
== prop_atoms
.net_wm_state_modal
) {
2478 /* XXX raise here or something? */
2480 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
2482 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
2484 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
2486 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
2487 self
->skip_taskbar
= TRUE
;
2488 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
2489 self
->skip_pager
= TRUE
;
2490 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
2492 } else if (state
== prop_atoms
.net_wm_state_above
) {
2494 } else if (state
== prop_atoms
.net_wm_state_below
) {
2496 } else if (state
== prop_atoms
.ob_wm_state_undecorated
) {
2500 } else { /* action == prop_atoms.net_wm_state_remove */
2501 if (state
== prop_atoms
.net_wm_state_modal
) {
2502 self
->modal
= FALSE
;
2503 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
2505 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
2507 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
2509 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
2510 self
->skip_taskbar
= FALSE
;
2511 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
2512 self
->skip_pager
= FALSE
;
2513 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
2515 } else if (state
== prop_atoms
.net_wm_state_above
) {
2516 self
->above
= FALSE
;
2517 } else if (state
== prop_atoms
.net_wm_state_below
) {
2518 self
->below
= FALSE
;
2519 } else if (state
== prop_atoms
.ob_wm_state_undecorated
) {
2520 undecorated
= FALSE
;
2524 if (max_horz
!= self
->max_horz
|| max_vert
!= self
->max_vert
) {
2525 if (max_horz
!= self
->max_horz
&& max_vert
!= self
->max_vert
) {
2527 if (max_horz
== max_vert
) { /* both going the same way */
2528 client_maximize(self
, max_horz
, 0, TRUE
);
2530 client_maximize(self
, max_horz
, 1, TRUE
);
2531 client_maximize(self
, max_vert
, 2, TRUE
);
2535 if (max_horz
!= self
->max_horz
)
2536 client_maximize(self
, max_horz
, 1, TRUE
);
2538 client_maximize(self
, max_vert
, 2, TRUE
);
2541 /* change fullscreen state before shading, as it will affect if the window
2543 if (fullscreen
!= self
->fullscreen
)
2544 client_fullscreen(self
, fullscreen
, TRUE
);
2545 if (shaded
!= self
->shaded
)
2546 client_shade(self
, shaded
);
2547 if (undecorated
!= self
->undecorated
)
2548 client_set_undecorated(self
, undecorated
);
2549 client_calc_layer(self
);
2550 client_change_state(self
); /* change the hint to reflect these changes */
2553 ObClient
*client_focus_target(ObClient
*self
)
2557 /* if we have a modal child, then focus it, not us */
2558 child
= client_search_modal_child(client_search_top_transient(self
));
2559 if (child
) return child
;
2563 gboolean
client_can_focus(ObClient
*self
)
2567 /* choose the correct target */
2568 self
= client_focus_target(self
);
2570 if (!self
->frame
->visible
)
2573 if (!(self
->can_focus
|| self
->focus_notify
))
2576 /* do a check to see if the window has already been unmapped or destroyed
2577 do this intelligently while watching out for unmaps we've generated
2578 (ignore_unmaps > 0) */
2579 if (XCheckTypedWindowEvent(ob_display
, self
->window
,
2580 DestroyNotify
, &ev
)) {
2581 XPutBackEvent(ob_display
, &ev
);
2584 while (XCheckTypedWindowEvent(ob_display
, self
->window
,
2585 UnmapNotify
, &ev
)) {
2586 if (self
->ignore_unmaps
) {
2587 self
->ignore_unmaps
--;
2589 XPutBackEvent(ob_display
, &ev
);
2597 gboolean
client_focus(ObClient
*self
)
2599 /* choose the correct target */
2600 self
= client_focus_target(self
);
2602 if (!client_can_focus(self
)) {
2603 if (!self
->frame
->visible
) {
2604 /* update the focus lists */
2605 focus_order_to_top(self
);
2610 if (self
->can_focus
) {
2611 /* RevertToPointerRoot causes much more headache than RevertToNone, so
2612 I choose to use it always, hopefully to find errors quicker, if any
2613 are left. (I hate X. I hate focus events.)
2615 Update: Changing this to RevertToNone fixed a bug with mozilla (bug
2616 #799. So now it is RevertToNone again.
2618 XSetInputFocus(ob_display
, self
->window
, RevertToNone
,
2622 if (self
->focus_notify
) {
2624 ce
.xclient
.type
= ClientMessage
;
2625 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
2626 ce
.xclient
.display
= ob_display
;
2627 ce
.xclient
.window
= self
->window
;
2628 ce
.xclient
.format
= 32;
2629 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_take_focus
;
2630 ce
.xclient
.data
.l
[1] = event_lasttime
;
2631 ce
.xclient
.data
.l
[2] = 0l;
2632 ce
.xclient
.data
.l
[3] = 0l;
2633 ce
.xclient
.data
.l
[4] = 0l;
2634 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
2638 ob_debug("%sively focusing %lx at %d\n",
2639 (self
->can_focus
? "act" : "pass"),
2640 self
->window
, (int) event_lasttime
);
2643 /* Cause the FocusIn to come back to us. Important for desktop switches,
2644 since otherwise we'll have no FocusIn on the queue and send it off to
2645 the focus_backup. */
2646 XSync(ob_display
, FALSE
);
2650 void client_unfocus(ObClient
*self
)
2652 if (focus_client
== self
) {
2654 ob_debug("client_unfocus for %lx\n", self
->window
);
2656 focus_fallback(OB_FOCUS_FALLBACK_UNFOCUSING
);
2660 void client_activate(ObClient
*self
, gboolean here
)
2662 if (client_normal(self
) && screen_showing_desktop
)
2663 screen_show_desktop(FALSE
);
2665 client_iconify(self
, FALSE
, here
);
2666 if (self
->desktop
!= DESKTOP_ALL
&&
2667 self
->desktop
!= screen_desktop
) {
2669 client_set_desktop(self
, screen_desktop
, FALSE
);
2671 screen_set_desktop(self
->desktop
);
2672 } else if (!self
->frame
->visible
)
2673 /* if its not visible for other reasons, then don't mess
2677 client_shade(self
, FALSE
);
2681 /* we do this an action here. this is rather important. this is because
2682 we want the results from the focus change to take place BEFORE we go
2683 about raising the window. when a fullscreen window loses focus, we need
2684 this or else the raise wont be able to raise above the to-lose-focus
2685 fullscreen window. */
2689 void client_raise(ObClient
*self
)
2691 action_run_string("Raise", self
);
2694 void client_lower(ObClient
*self
)
2696 action_run_string("Raise", self
);
2699 gboolean
client_focused(ObClient
*self
)
2701 return self
== focus_client
;
2704 static ObClientIcon
* client_icon_recursive(ObClient
*self
, int w
, int h
)
2707 /* si is the smallest image >= req */
2708 /* li is the largest image < req */
2709 unsigned long size
, smallest
= 0xffffffff, largest
= 0, si
= 0, li
= 0;
2711 if (!self
->nicons
) {
2712 ObClientIcon
*parent
= NULL
;
2714 if (self
->transient_for
) {
2715 if (self
->transient_for
!= OB_TRAN_GROUP
)
2716 parent
= client_icon_recursive(self
->transient_for
, w
, h
);
2719 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
2720 ObClient
*c
= it
->data
;
2721 if (c
!= self
&& !c
->transient_for
) {
2722 if ((parent
= client_icon_recursive(c
, w
, h
)))
2732 for (i
= 0; i
< self
->nicons
; ++i
) {
2733 size
= self
->icons
[i
].width
* self
->icons
[i
].height
;
2734 if (size
< smallest
&& size
>= (unsigned)(w
* h
)) {
2738 if (size
> largest
&& size
<= (unsigned)(w
* h
)) {
2743 if (largest
== 0) /* didnt find one smaller than the requested size */
2744 return &self
->icons
[si
];
2745 return &self
->icons
[li
];
2748 const ObClientIcon
* client_icon(ObClient
*self
, int w
, int h
)
2751 static ObClientIcon deficon
;
2753 if (!(ret
= client_icon_recursive(self
, w
, h
))) {
2754 deficon
.width
= deficon
.height
= 48;
2755 deficon
.data
= ob_rr_theme
->def_win_icon
;
2761 /* this be mostly ripped from fvwm */
2762 ObClient
*client_find_directional(ObClient
*c
, ObDirection dir
)
2764 int my_cx
, my_cy
, his_cx
, his_cy
;
2767 int score
, best_score
;
2768 ObClient
*best_client
, *cur
;
2774 /* first, find the centre coords of the currently focused window */
2775 my_cx
= c
->frame
->area
.x
+ c
->frame
->area
.width
/ 2;
2776 my_cy
= c
->frame
->area
.y
+ c
->frame
->area
.height
/ 2;
2781 for(it
= g_list_first(client_list
); it
; it
= it
->next
) {
2784 /* the currently selected window isn't interesting */
2787 if (!client_normal(cur
))
2789 if(c
->desktop
!= cur
->desktop
&& cur
->desktop
!= DESKTOP_ALL
)
2793 if(client_focus_target(cur
) == cur
&&
2794 !(cur
->can_focus
|| cur
->focus_notify
))
2797 /* find the centre coords of this window, from the
2798 * currently focused window's point of view */
2799 his_cx
= (cur
->frame
->area
.x
- my_cx
)
2800 + cur
->frame
->area
.width
/ 2;
2801 his_cy
= (cur
->frame
->area
.y
- my_cy
)
2802 + cur
->frame
->area
.height
/ 2;
2804 if(dir
== OB_DIRECTION_NORTHEAST
|| dir
== OB_DIRECTION_SOUTHEAST
||
2805 dir
== OB_DIRECTION_SOUTHWEST
|| dir
== OB_DIRECTION_NORTHWEST
) {
2807 /* Rotate the diagonals 45 degrees counterclockwise.
2808 * To do this, multiply the matrix /+h +h\ with the
2809 * vector (x y). \-h +h/
2810 * h = sqrt(0.5). We can set h := 1 since absolute
2811 * distance doesn't matter here. */
2812 tx
= his_cx
+ his_cy
;
2813 his_cy
= -his_cx
+ his_cy
;
2818 case OB_DIRECTION_NORTH
:
2819 case OB_DIRECTION_SOUTH
:
2820 case OB_DIRECTION_NORTHEAST
:
2821 case OB_DIRECTION_SOUTHWEST
:
2822 offset
= (his_cx
< 0) ? -his_cx
: his_cx
;
2823 distance
= ((dir
== OB_DIRECTION_NORTH
||
2824 dir
== OB_DIRECTION_NORTHEAST
) ?
2827 case OB_DIRECTION_EAST
:
2828 case OB_DIRECTION_WEST
:
2829 case OB_DIRECTION_SOUTHEAST
:
2830 case OB_DIRECTION_NORTHWEST
:
2831 offset
= (his_cy
< 0) ? -his_cy
: his_cy
;
2832 distance
= ((dir
== OB_DIRECTION_WEST
||
2833 dir
== OB_DIRECTION_NORTHWEST
) ?
2838 /* the target must be in the requested direction */
2842 /* Calculate score for this window. The smaller the better. */
2843 score
= distance
+ offset
;
2845 /* windows more than 45 degrees off the direction are
2846 * heavily penalized and will only be chosen if nothing
2847 * else within a million pixels */
2848 if(offset
> distance
)
2851 if(best_score
== -1 || score
< best_score
)
2859 void client_set_layer(ObClient
*self
, int layer
)
2863 self
->above
= FALSE
;
2864 } else if (layer
== 0) {
2865 self
->below
= self
->above
= FALSE
;
2867 self
->below
= FALSE
;
2870 client_calc_layer(self
);
2871 client_change_state(self
); /* reflect this in the state hints */
2874 void client_set_undecorated(ObClient
*self
, gboolean undecorated
)
2876 if (self
->undecorated
!= undecorated
) {
2877 self
->undecorated
= undecorated
;
2878 client_setup_decor_and_functions(self
);
2879 client_change_state(self
); /* reflect this in the state hints */
2883 guint
client_monitor(ObClient
*self
)
2887 for (i
= 0; i
< screen_num_monitors
; ++i
) {
2888 Rect
*area
= screen_physical_area_monitor(i
);
2889 if (RECT_INTERSECTS_RECT(*area
, self
->frame
->area
))
2892 if (i
== screen_num_monitors
) i
= 0;
2893 g_assert(i
< screen_num_monitors
);
2897 ObClient
*client_search_top_transient(ObClient
*self
)
2899 /* move up the transient chain as far as possible */
2900 if (self
->transient_for
) {
2901 if (self
->transient_for
!= OB_TRAN_GROUP
) {
2902 return client_search_top_transient(self
->transient_for
);
2906 g_assert(self
->group
);
2908 for (it
= self
->group
->members
; it
; it
= it
->next
) {
2909 ObClient
*c
= it
->data
;
2911 /* checking transient_for prevents infinate loops! */
2912 if (c
!= self
&& !c
->transient_for
)
2923 ObClient
*client_search_focus_parent(ObClient
*self
)
2925 if (self
->transient_for
) {
2926 if (self
->transient_for
!= OB_TRAN_GROUP
) {
2927 if (client_focused(self
->transient_for
))
2928 return self
->transient_for
;
2932 for (it
= self
->group
->members
; it
; it
= it
->next
) {
2933 ObClient
*c
= it
->data
;
2935 /* checking transient_for prevents infinate loops! */
2936 if (c
!= self
&& !c
->transient_for
)
2937 if (client_focused(c
))
2946 ObClient
*client_search_parent(ObClient
*self
, ObClient
*search
)
2948 if (self
->transient_for
) {
2949 if (self
->transient_for
!= OB_TRAN_GROUP
) {
2950 if (self
->transient_for
== search
)
2955 for (it
= self
->group
->members
; it
; it
= it
->next
) {
2956 ObClient
*c
= it
->data
;
2958 /* checking transient_for prevents infinate loops! */
2959 if (c
!= self
&& !c
->transient_for
)
2969 ObClient
*client_search_transient(ObClient
*self
, ObClient
*search
)
2973 for (sit
= self
->transients
; sit
; sit
= g_slist_next(sit
)) {
2974 if (sit
->data
== search
)
2976 if (client_search_transient(sit
->data
, search
))
2982 void client_update_sm_client_id(ObClient
*self
)
2984 g_free(self
->sm_client_id
);
2985 self
->sm_client_id
= NULL
;
2987 if (!PROP_GETS(self
->window
, sm_client_id
, locale
, &self
->sm_client_id
) &&
2989 PROP_GETS(self
->group
->leader
, sm_client_id
, locale
,
2990 &self
->sm_client_id
);
2993 /* finds the nearest edge in the given direction from the current client
2994 * note to self: the edge is the -frame- edge (the actual one), not the
2997 int client_directional_edge_search(ObClient
*c
, ObDirection dir
)
3000 int my_edge_start
, my_edge_end
, my_offset
;
3007 a
= screen_area(c
->desktop
);
3010 case OB_DIRECTION_NORTH
:
3011 my_edge_start
= c
->frame
->area
.x
;
3012 my_edge_end
= c
->frame
->area
.x
+ c
->frame
->area
.width
;
3013 my_offset
= c
->frame
->area
.y
;
3015 dest
= a
->y
; /* default: top of screen */
3017 for(it
= g_list_first(client_list
); it
; it
= it
->next
) {
3018 int his_edge_start
, his_edge_end
, his_offset
;
3019 ObClient
*cur
= it
->data
;
3023 if(!client_normal(cur
))
3025 if(c
->desktop
!= cur
->desktop
&& cur
->desktop
!= DESKTOP_ALL
)
3030 his_edge_start
= cur
->frame
->area
.x
;
3031 his_edge_end
= cur
->frame
->area
.x
+ cur
->frame
->area
.width
;
3032 his_offset
= cur
->frame
->area
.y
+ cur
->frame
->area
.height
;
3034 if(his_offset
+ 1 > my_offset
)
3037 if(his_offset
< dest
)
3040 if(his_edge_start
>= my_edge_start
&&
3041 his_edge_start
<= my_edge_end
)
3044 if(my_edge_start
>= his_edge_start
&&
3045 my_edge_start
<= his_edge_end
)
3050 case OB_DIRECTION_SOUTH
:
3051 my_edge_start
= c
->frame
->area
.x
;
3052 my_edge_end
= c
->frame
->area
.x
+ c
->frame
->area
.width
;
3053 my_offset
= c
->frame
->area
.y
+ c
->frame
->area
.height
;
3055 dest
= a
->y
+ a
->height
; /* default: bottom of screen */
3057 for(it
= g_list_first(client_list
); it
; it
= it
->next
) {
3058 int his_edge_start
, his_edge_end
, his_offset
;
3059 ObClient
*cur
= it
->data
;
3063 if(!client_normal(cur
))
3065 if(c
->desktop
!= cur
->desktop
&& cur
->desktop
!= DESKTOP_ALL
)
3070 his_edge_start
= cur
->frame
->area
.x
;
3071 his_edge_end
= cur
->frame
->area
.x
+ cur
->frame
->area
.width
;
3072 his_offset
= cur
->frame
->area
.y
;
3075 if(his_offset
- 1 < my_offset
)
3078 if(his_offset
> dest
)
3081 if(his_edge_start
>= my_edge_start
&&
3082 his_edge_start
<= my_edge_end
)
3085 if(my_edge_start
>= his_edge_start
&&
3086 my_edge_start
<= his_edge_end
)
3091 case OB_DIRECTION_WEST
:
3092 my_edge_start
= c
->frame
->area
.y
;
3093 my_edge_end
= c
->frame
->area
.y
+ c
->frame
->area
.height
;
3094 my_offset
= c
->frame
->area
.x
;
3096 dest
= a
->x
; /* default: leftmost egde of screen */
3098 for(it
= g_list_first(client_list
); it
; it
= it
->next
) {
3099 int his_edge_start
, his_edge_end
, his_offset
;
3100 ObClient
*cur
= it
->data
;
3104 if(!client_normal(cur
))
3106 if(c
->desktop
!= cur
->desktop
&& cur
->desktop
!= DESKTOP_ALL
)
3111 his_edge_start
= cur
->frame
->area
.y
;
3112 his_edge_end
= cur
->frame
->area
.y
+ cur
->frame
->area
.height
;
3113 his_offset
= cur
->frame
->area
.x
+ cur
->frame
->area
.width
;
3115 if(his_offset
+ 1 > my_offset
)
3118 if(his_offset
< dest
)
3121 if(his_edge_start
>= my_edge_start
&&
3122 his_edge_start
<= my_edge_end
)
3125 if(my_edge_start
>= his_edge_start
&&
3126 my_edge_start
<= his_edge_end
)
3132 case OB_DIRECTION_EAST
:
3133 my_edge_start
= c
->frame
->area
.y
;
3134 my_edge_end
= c
->frame
->area
.y
+ c
->frame
->area
.height
;
3135 my_offset
= c
->frame
->area
.x
+ c
->frame
->area
.width
;
3137 dest
= a
->x
+ a
->width
; /* default: rightmost edge of screen */
3139 for(it
= g_list_first(client_list
); it
; it
= it
->next
) {
3140 int his_edge_start
, his_edge_end
, his_offset
;
3141 ObClient
*cur
= it
->data
;
3145 if(!client_normal(cur
))
3147 if(c
->desktop
!= cur
->desktop
&& cur
->desktop
!= DESKTOP_ALL
)
3152 his_edge_start
= cur
->frame
->area
.y
;
3153 his_edge_end
= cur
->frame
->area
.y
+ cur
->frame
->area
.height
;
3154 his_offset
= cur
->frame
->area
.x
;
3156 if(his_offset
- 1 < my_offset
)
3159 if(his_offset
> dest
)
3162 if(his_edge_start
>= my_edge_start
&&
3163 his_edge_start
<= my_edge_end
)
3166 if(my_edge_start
>= his_edge_start
&&
3167 my_edge_start
<= his_edge_end
)
3172 case OB_DIRECTION_NORTHEAST
:
3173 case OB_DIRECTION_SOUTHEAST
:
3174 case OB_DIRECTION_NORTHWEST
:
3175 case OB_DIRECTION_SOUTHWEST
:
3176 /* not implemented */
3178 g_assert_not_reached();
3183 ObClient
* client_under_pointer()
3187 ObClient
*ret
= NULL
;
3189 if (screen_pointer_pos(&x
, &y
)) {
3190 for (it
= stacking_list
; it
!= NULL
; it
= it
->next
) {
3191 if (WINDOW_IS_CLIENT(it
->data
)) {
3192 ObClient
*c
= WINDOW_AS_CLIENT(it
->data
);
3193 if (c
->frame
->visible
&&
3194 RECT_CONTAINS(c
->frame
->area
, x
, y
)) {
3204 gboolean
client_has_group_siblings(ObClient
*self
)
3206 return self
->group
&& self
->group
->members
->next
;