1 /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
3 client.c for the Openbox window manager
4 Copyright (c) 2004 Mikael Magnusson
5 Copyright (c) 2003 Ben Jansens
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 See the COPYING file for a copy of the GNU General Public License.
22 #include "startupnotify.h"
26 #include "moveresize.h"
29 #include "extensions.h"
39 #include "menuframe.h"
42 #include "render/render.h"
45 #include <X11/Xutil.h>
47 /*! The event mask to grab on client windows */
48 #define CLIENT_EVENTMASK (PropertyChangeMask | FocusChangeMask | \
51 #define CLIENT_NOPROPAGATEMASK (ButtonPressMask | ButtonReleaseMask | \
56 ObClientDestructor func
;
60 GList
*client_list
= NULL
;
61 GSList
*client_destructors
= NULL
;
63 static void client_get_all(ObClient
*self
);
64 static void client_toggle_border(ObClient
*self
, gboolean show
);
65 static void client_get_startup_id(ObClient
*self
);
66 static void client_get_area(ObClient
*self
);
67 static void client_get_desktop(ObClient
*self
);
68 static void client_get_state(ObClient
*self
);
69 static void client_get_shaped(ObClient
*self
);
70 static void client_get_mwm_hints(ObClient
*self
);
71 static void client_get_gravity(ObClient
*self
);
72 static void client_showhide(ObClient
*self
);
73 static void client_change_allowed_actions(ObClient
*self
);
74 static void client_change_state(ObClient
*self
);
75 static void client_apply_startup_state(ObClient
*self
);
76 static void client_restore_session_state(ObClient
*self
);
77 static void client_restore_session_stacking(ObClient
*self
);
78 static void client_urgent_notify(ObClient
*self
);
80 void client_startup(gboolean reconfig
)
87 void client_shutdown(gboolean reconfig
)
91 void client_add_destructor(ObClientDestructor func
, gpointer data
)
93 Destructor
*d
= g_new(Destructor
, 1);
96 client_destructors
= g_slist_prepend(client_destructors
, d
);
99 void client_remove_destructor(ObClientDestructor func
)
103 for (it
= client_destructors
; it
; it
= g_slist_next(it
)) {
104 Destructor
*d
= it
->data
;
105 if (d
->func
== func
) {
107 client_destructors
= g_slist_delete_link(client_destructors
, it
);
113 void client_set_list()
115 Window
*windows
, *win_it
;
117 guint size
= g_list_length(client_list
);
119 /* create an array of the window ids */
121 windows
= g_new(Window
, size
);
123 for (it
= client_list
; it
; it
= g_list_next(it
), ++win_it
)
124 *win_it
= ((ObClient
*)it
->data
)->window
;
128 PROP_SETA32(RootWindow(ob_display
, ob_screen
),
129 net_client_list
, window
, (gulong
*)windows
, size
);
138 void client_foreach_transient(ObClient *self, ObClientForeachFunc func, gpointer data)
142 for (it = self->transients; it; it = g_slist_next(it)) {
143 if (!func(it->data, data)) return;
144 client_foreach_transient(it->data, func, data);
148 void client_foreach_ancestor(ObClient *self, ObClientForeachFunc func, gpointer data)
150 if (self->transient_for) {
151 if (self->transient_for != OB_TRAN_GROUP) {
152 if (!func(self->transient_for, data)) return;
153 client_foreach_ancestor(self->transient_for, func, data);
157 for (it = self->group->members; it; it = g_slist_next(it))
158 if (it->data != self &&
159 !((ObClient*)it->data)->transient_for) {
160 if (!func(it->data, data)) return;
161 client_foreach_ancestor(it->data, func, data);
168 void client_manage_all()
173 XWindowAttributes attrib
;
175 XQueryTree(ob_display
, RootWindow(ob_display
, ob_screen
),
176 &w
, &w
, &children
, &nchild
);
178 /* remove all icon windows from the list */
179 for (i
= 0; i
< nchild
; i
++) {
180 if (children
[i
] == None
) continue;
181 wmhints
= XGetWMHints(ob_display
, children
[i
]);
183 if ((wmhints
->flags
& IconWindowHint
) &&
184 (wmhints
->icon_window
!= children
[i
]))
185 for (j
= 0; j
< nchild
; j
++)
186 if (children
[j
] == wmhints
->icon_window
) {
194 for (i
= 0; i
< nchild
; ++i
) {
195 if (children
[i
] == None
)
197 if (XGetWindowAttributes(ob_display
, children
[i
], &attrib
)) {
198 if (attrib
.override_redirect
) continue;
200 if (attrib
.map_state
!= IsUnmapped
)
201 client_manage(children
[i
]);
207 static ObAppSettings
*get_settings(ObClient
*client
)
209 GSList
*a
= config_per_app_settings
;
212 ObAppSettings
*app
= (ObAppSettings
*) a
->data
;
215 (app
->name
&& !app
->class && !strcmp(app
->name
, client
->name
))
216 || (app
->class && !app
->name
&& !strcmp(app
->class, client
->class))
217 || (app
->class && app
->name
&& !strcmp(app
->class, client
->class)
218 && !strcmp(app
->name
, client
->name
))
220 ob_debug("Window matching: %s\n", app
->name
);
221 /* Match if no role was specified in the per app setting, or if the string
222 * matches the beginning of the role, since apps like to set the role to
223 * things like browser-window-23c4b2f */
224 if (!app
->role
|| !strncmp(app
->role
, client
->role
, strlen(app
->role
)))
233 void client_manage(Window window
)
237 XWindowAttributes attrib
;
238 XSetWindowAttributes attrib_set
;
240 gboolean activate
= FALSE
;
241 ObAppSettings
*settings
;
245 /* check if it has already been unmapped by the time we started mapping
246 the grab does a sync so we don't have to here */
247 if (XCheckTypedWindowEvent(ob_display
, window
, DestroyNotify
, &e
) ||
248 XCheckTypedWindowEvent(ob_display
, window
, UnmapNotify
, &e
)) {
249 XPutBackEvent(ob_display
, &e
);
252 return; /* don't manage it */
255 /* make sure it isn't an override-redirect window */
256 if (!XGetWindowAttributes(ob_display
, window
, &attrib
) ||
257 attrib
.override_redirect
) {
259 return; /* don't manage it */
262 /* is the window a docking app */
263 if ((wmhint
= XGetWMHints(ob_display
, window
))) {
264 if ((wmhint
->flags
& StateHint
) &&
265 wmhint
->initial_state
== WithdrawnState
) {
266 dock_add(window
, wmhint
);
274 ob_debug("Managing window: %lx\n", window
);
276 /* choose the events we want to receive on the CLIENT window */
277 attrib_set
.event_mask
= CLIENT_EVENTMASK
;
278 attrib_set
.do_not_propagate_mask
= CLIENT_NOPROPAGATEMASK
;
279 XChangeWindowAttributes(ob_display
, window
,
280 CWEventMask
|CWDontPropagate
, &attrib_set
);
283 /* create the ObClient struct, and populate it from the hints on the
285 self
= g_new0(ObClient
, 1);
286 self
->obwin
.type
= Window_Client
;
287 self
->window
= window
;
289 /* non-zero defaults */
290 self
->title_count
= 1;
291 self
->wmstate
= NormalState
;
293 self
->desktop
= screen_num_desktops
; /* always an invalid value */
295 client_get_all(self
);
296 client_restore_session_state(self
);
298 sn_app_started(self
->class);
300 /* update the focus lists, do this before the call to change_state or
301 it can end up in the list twice! */
302 focus_order_add_new(self
);
304 client_change_state(self
);
306 /* remove the client's border (and adjust re gravity) */
307 client_toggle_border(self
, FALSE
);
309 /* specify that if we exit, the window should not be destroyed and should
310 be reparented back to root automatically */
311 XChangeSaveSet(ob_display
, window
, SetModeInsert
);
313 /* create the decoration frame for the client window */
314 self
->frame
= frame_new();
316 frame_grab_client(self
->frame
, self
);
320 client_apply_startup_state(self
);
322 /* get and set application level settings */
323 settings
= get_settings(self
);
326 /* Don't worry, we won't actually both shade and undecorate the
327 * window when push comes to shove. */
328 if (settings
->shade
!= -1)
329 client_shade(self
, settings
->shade
);
330 if (settings
->decor
!= -1)
331 client_set_undecorated(self
, !settings
->decor
);
332 if (settings
->iconic
!= -1)
333 client_iconify(self
, settings
->iconic
, FALSE
);
334 if (settings
->skip_pager
!= -1) {
335 self
->skip_pager
= !!settings
->skip_pager
;
336 client_change_state(self
);
338 if (settings
->skip_taskbar
!= -1) {
339 self
->skip_taskbar
= !!settings
->skip_taskbar
;
340 client_change_state(self
);
343 /* 1 && -1 shouldn't be possible by the code in config.c */
344 if (settings
->max_vert
== 1 && settings
->max_horz
== 1)
345 client_maximize(self
, TRUE
, 0, TRUE
);
346 else if (settings
->max_vert
== 0 && settings
->max_horz
== 0)
347 client_maximize(self
, FALSE
, 0, TRUE
);
348 else if (settings
->max_vert
== 1 && settings
->max_horz
== 0) {
349 client_maximize(self
, TRUE
, 2, TRUE
);
350 client_maximize(self
, FALSE
, 1, TRUE
);
351 } else if (settings
->max_vert
== 0 && settings
->max_horz
== 1) {
352 client_maximize(self
, TRUE
, 1, TRUE
);
353 client_maximize(self
, FALSE
, 2, TRUE
);
356 if (settings
->fullscreen
!= -1)
357 client_fullscreen(self
, !!settings
->fullscreen
, TRUE
);
359 if (settings
->desktop
< screen_num_desktops
)
360 client_set_desktop(self
, settings
->desktop
, FALSE
);
362 if (settings
->layer
> -2 && settings
->layer
< 2)
363 client_set_layer(self
, settings
->layer
);
367 stacking_add(CLIENT_AS_WINDOW(self
));
368 client_restore_session_stacking(self
);
370 /* focus the new window? */
371 if (ob_state() != OB_STATE_STARTING
&&
372 (config_focus_new
|| client_search_focus_parent(self
)) ||
373 (settings
&& settings
->focus
== TRUE
) &&
374 /* note the check against Type_Normal/Dialog, not client_normal(self),
375 which would also include other types. in this case we want more
376 strict rules for focus */
377 (self
->type
== OB_CLIENT_TYPE_NORMAL
||
378 self
->type
== OB_CLIENT_TYPE_DIALOG
))
382 if (self
->desktop
!= screen_desktop
) {
383 /* activate the window */
386 gboolean group_foc
= FALSE
;
391 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
))
393 if (client_focused(it
->data
))
401 (!self
->transient_for
&& (!self
->group
||
402 !self
->group
->members
->next
))) ||
403 client_search_focus_tree_full(self
) ||
405 !client_normal(focus_client
))
407 /* activate the window */
414 if (ob_state() == OB_STATE_RUNNING
) {
415 gint x
= self
->area
.x
, ox
= x
;
416 gint y
= self
->area
.y
, oy
= y
;
418 place_client(self
, &x
, &y
, settings
);
420 /* make sure the window is visible. */
421 client_find_onscreen(self
, &x
, &y
,
422 self
->frame
->area
.width
,
423 self
->frame
->area
.height
,
424 /* non-normal clients has less rules, and
425 windows that are being restored from a
426 session do also. we can assume you want
427 it back where you saved it. Clients saying
428 they placed themselves are subjected to
429 harder rules, ones that are placed by
430 place.c or by the user are allowed partially
431 off-screen and on xinerama divides (ie,
432 it is up to the placement routines to avoid
433 the xinerama divides) */
434 ((self
->positioned
& PPosition
) &&
435 !(self
->positioned
& USPosition
)) &&
436 client_normal(self
) &&
438 if (x
!= ox
|| y
!= oy
)
439 client_move(self
, x
, y
);
442 keyboard_grab_for_client(self
, TRUE
);
443 mouse_grab_for_client(self
, TRUE
);
445 client_showhide(self
);
447 /* use client_focus instead of client_activate cuz client_activate does
448 stuff like switch desktops etc and I'm not interested in all that when
449 a window maps since its not based on an action from the user like
450 clicking a window to activate is. so keep the new window out of the way
453 /* if using focus_delay, stop the timer now so that focus doesn't go
455 event_halt_focus_delay();
458 /* since focus can change the stacking orders, if we focus the window
459 then the standard raise it gets is not enough, we need to queue one
460 for after the focus change takes place */
464 /* client_activate does this but we aret using it so we have to do it
466 if (screen_showing_desktop
)
467 screen_show_desktop(FALSE
);
469 /* add to client list/map */
470 client_list
= g_list_append(client_list
, self
);
471 g_hash_table_insert(window_map
, &self
->window
, self
);
473 /* this has to happen after we're in the client_list */
474 screen_update_areas();
476 /* update the list hints */
479 ob_debug("Managed window 0x%lx (%s)\n", window
, self
->class);
482 void client_unmanage_all()
484 while (client_list
!= NULL
)
485 client_unmanage(client_list
->data
);
488 void client_unmanage(ObClient
*self
)
493 ob_debug("Unmanaging window: %lx (%s)\n", self
->window
, self
->class);
495 g_assert(self
!= NULL
);
497 keyboard_grab_for_client(self
, FALSE
);
498 mouse_grab_for_client(self
, FALSE
);
500 /* potentially fix focusLast */
501 if (config_focus_last
)
502 grab_pointer(TRUE
, OB_CURSOR_NONE
);
504 /* remove the window from our save set */
505 XChangeSaveSet(ob_display
, self
->window
, SetModeDelete
);
507 /* we dont want events no more */
508 XSelectInput(ob_display
, self
->window
, NoEventMask
);
510 frame_hide(self
->frame
);
512 client_list
= g_list_remove(client_list
, self
);
513 stacking_remove(self
);
514 g_hash_table_remove(window_map
, &self
->window
);
516 /* update the focus lists */
517 focus_order_remove(self
);
519 /* once the client is out of the list, update the struts to remove it's
521 screen_update_areas();
523 for (it
= client_destructors
; it
; it
= g_slist_next(it
)) {
524 Destructor
*d
= it
->data
;
525 d
->func(self
, d
->data
);
528 if (focus_client
== self
) {
531 /* focus the last focused window on the desktop, and ignore enter
532 events from the unmap so it doesnt mess with the focus */
533 while (XCheckTypedEvent(ob_display
, EnterNotify
, &e
));
534 /* remove these flags so we don't end up getting focused in the
536 self
->can_focus
= FALSE
;
537 self
->focus_notify
= FALSE
;
539 client_unfocus(self
);
542 /* tell our parent(s) that we're gone */
543 if (self
->transient_for
== OB_TRAN_GROUP
) { /* transient of group */
544 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
))
545 if (it
->data
!= self
)
546 ((ObClient
*)it
->data
)->transients
=
547 g_slist_remove(((ObClient
*)it
->data
)->transients
, self
);
548 } else if (self
->transient_for
) { /* transient of window */
549 self
->transient_for
->transients
=
550 g_slist_remove(self
->transient_for
->transients
, self
);
553 /* tell our transients that we're gone */
554 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
555 if (((ObClient
*)it
->data
)->transient_for
!= OB_TRAN_GROUP
) {
556 ((ObClient
*)it
->data
)->transient_for
= NULL
;
557 client_calc_layer(it
->data
);
561 /* remove from its group */
563 group_remove(self
->group
, self
);
567 /* give the client its border back */
568 client_toggle_border(self
, TRUE
);
570 /* reparent the window out of the frame, and free the frame */
571 frame_release_client(self
->frame
, self
);
574 if (ob_state() != OB_STATE_EXITING
) {
575 /* these values should not be persisted across a window
577 PROP_ERASE(self
->window
, net_wm_desktop
);
578 PROP_ERASE(self
->window
, net_wm_state
);
579 PROP_ERASE(self
->window
, wm_state
);
581 /* if we're left in an unmapped state, the client wont be mapped. this
582 is bad, since we will no longer be managing the window on restart */
583 XMapWindow(ob_display
, self
->window
);
587 ob_debug("Unmanaged window 0x%lx\n", self
->window
);
589 /* free all data allocated in the client struct */
590 g_slist_free(self
->transients
);
591 for (j
= 0; j
< self
->nicons
; ++j
)
592 g_free(self
->icons
[j
].data
);
593 if (self
->nicons
> 0)
596 g_free(self
->icon_title
);
600 g_free(self
->sm_client_id
);
603 /* update the list hints */
606 if (config_focus_last
)
607 grab_pointer(FALSE
, OB_CURSOR_NONE
);
610 static void client_urgent_notify(ObClient
*self
)
613 frame_flash_start(self
->frame
);
615 frame_flash_stop(self
->frame
);
618 static void client_restore_session_state(ObClient
*self
)
622 if (!(it
= session_state_find(self
)))
625 self
->session
= it
->data
;
627 RECT_SET_POINT(self
->area
, self
->session
->x
, self
->session
->y
);
628 self
->positioned
= PPosition
;
629 if (self
->session
->w
> 0)
630 self
->area
.width
= self
->session
->w
;
631 if (self
->session
->h
> 0)
632 self
->area
.height
= self
->session
->h
;
633 XResizeWindow(ob_display
, self
->window
,
634 self
->area
.width
, self
->area
.height
);
636 self
->desktop
= (self
->session
->desktop
== DESKTOP_ALL
?
637 self
->session
->desktop
:
638 MIN(screen_num_desktops
- 1, self
->session
->desktop
));
639 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, self
->desktop
);
641 self
->shaded
= self
->session
->shaded
;
642 self
->iconic
= self
->session
->iconic
;
643 self
->skip_pager
= self
->session
->skip_pager
;
644 self
->skip_taskbar
= self
->session
->skip_taskbar
;
645 self
->fullscreen
= self
->session
->fullscreen
;
646 self
->above
= self
->session
->above
;
647 self
->below
= self
->session
->below
;
648 self
->max_horz
= self
->session
->max_horz
;
649 self
->max_vert
= self
->session
->max_vert
;
652 static void client_restore_session_stacking(ObClient
*self
)
656 if (!self
->session
) return;
658 it
= g_list_find(session_saved_state
, self
->session
);
659 for (it
= g_list_previous(it
); it
; it
= g_list_previous(it
)) {
662 for (cit
= client_list
; cit
; cit
= g_list_next(cit
))
663 if (session_state_cmp(it
->data
, cit
->data
))
666 client_calc_layer(self
);
667 stacking_below(CLIENT_AS_WINDOW(self
),
668 CLIENT_AS_WINDOW(cit
->data
));
674 void client_move_onscreen(ObClient
*self
, gboolean rude
)
676 gint x
= self
->area
.x
;
677 gint y
= self
->area
.y
;
678 if (client_find_onscreen(self
, &x
, &y
,
679 self
->frame
->area
.width
,
680 self
->frame
->area
.height
, rude
)) {
681 client_move(self
, x
, y
);
685 gboolean
client_find_onscreen(ObClient
*self
, gint
*x
, gint
*y
, gint w
, gint h
,
689 gint ox
= *x
, oy
= *y
;
691 frame_client_gravity(self
->frame
, x
, y
); /* get where the frame
694 /* XXX watch for xinerama dead areas */
695 /* This makes sure windows aren't entirely outside of the screen so you
696 * can't see them at all */
697 if (client_normal(self
)) {
698 a
= screen_area(self
->desktop
);
699 if (!self
->strut
.right
&& *x
>= a
->x
+ a
->width
- 1)
700 *x
= a
->x
+ a
->width
- self
->frame
->area
.width
;
701 if (!self
->strut
.bottom
&& *y
>= a
->y
+ a
->height
- 1)
702 *y
= a
->y
+ a
->height
- self
->frame
->area
.height
;
703 if (!self
->strut
.left
&& *x
+ self
->frame
->area
.width
- 1 < a
->x
)
705 if (!self
->strut
.top
&& *y
+ self
->frame
->area
.height
- 1 < a
->y
)
709 /* This here doesn't let windows even a pixel outside the screen,
710 * when called from client_manage, programs placing themselves are
711 * forced completely onscreen, while things like
712 * xterm -geometry resolution-width/2 will work fine. Trying to
713 * place it completely offscreen will be handled in the above code.
714 * Sorry for this confused comment, i am tired. */
716 /* avoid the xinerama monitor divide while we're at it,
717 * remember to fix the placement stuff to avoid it also and
718 * then remove this XXX */
719 a
= screen_physical_area_monitor(client_monitor(self
));
720 /* dont let windows map/move into the strut unless they
721 are bigger than the available area */
723 if (!self
->strut
.left
&& *x
< a
->x
) *x
= a
->x
;
724 if (!self
->strut
.right
&& *x
+ w
> a
->x
+ a
->width
)
725 *x
= a
->x
+ a
->width
- w
;
727 if (h
<= a
->height
) {
728 if (!self
->strut
.top
&& *y
< a
->y
) *y
= a
->y
;
729 if (!self
->strut
.bottom
&& *y
+ h
> a
->y
+ a
->height
)
730 *y
= a
->y
+ a
->height
- h
;
734 frame_frame_gravity(self
->frame
, x
, y
); /* get where the client
737 return ox
!= *x
|| oy
!= *y
;
740 static void client_toggle_border(ObClient
*self
, gboolean show
)
742 /* adjust our idea of where the client is, based on its border. When the
743 border is removed, the client should now be considered to be in a
745 when re-adding the border to the client, the same operation needs to be
747 gint oldx
= self
->area
.x
, oldy
= self
->area
.y
;
748 gint x
= oldx
, y
= oldy
;
749 switch(self
->gravity
) {
751 case NorthWestGravity
:
753 case SouthWestGravity
:
755 case NorthEastGravity
:
757 case SouthEastGravity
:
758 if (show
) x
-= self
->border_width
* 2;
759 else x
+= self
->border_width
* 2;
766 if (show
) x
-= self
->border_width
;
767 else x
+= self
->border_width
;
770 switch(self
->gravity
) {
772 case NorthWestGravity
:
774 case NorthEastGravity
:
776 case SouthWestGravity
:
778 case SouthEastGravity
:
779 if (show
) y
-= self
->border_width
* 2;
780 else y
+= self
->border_width
* 2;
787 if (show
) y
-= self
->border_width
;
788 else y
+= self
->border_width
;
795 XSetWindowBorderWidth(ob_display
, self
->window
, self
->border_width
);
797 /* move the client so it is back it the right spot _with_ its
799 if (x
!= oldx
|| y
!= oldy
)
800 XMoveWindow(ob_display
, self
->window
, x
, y
);
802 XSetWindowBorderWidth(ob_display
, self
->window
, 0);
806 static void client_get_all(ObClient
*self
)
808 client_get_area(self
);
809 client_update_transient_for(self
);
810 client_update_wmhints(self
);
811 client_get_startup_id(self
);
812 client_get_desktop(self
);
813 client_get_shaped(self
);
815 client_get_mwm_hints(self
);
816 client_get_type(self
);/* this can change the mwmhints for special cases */
818 /* The transient hint is used to pick a type, but the type can also affect
819 transiency (dialogs are always made transients). This is Havoc's idea,
820 but it is needed to make some apps work right (eg tsclient). */
821 client_update_transient_for(self
);
823 client_get_state(self
);
826 /* a couple type-based defaults for new windows */
828 /* this makes sure that these windows appear on all desktops */
829 if (self
->type
== OB_CLIENT_TYPE_DESKTOP
)
830 self
->desktop
= DESKTOP_ALL
;
833 client_update_protocols(self
);
835 client_get_gravity(self
); /* get the attribute gravity */
836 client_update_normal_hints(self
); /* this may override the attribute
839 /* got the type, the mwmhints, the protocols, and the normal hints
840 (min/max sizes), so we're ready to set up the decorations/functions */
841 client_setup_decor_and_functions(self
);
843 client_update_title(self
);
844 client_update_class(self
);
845 client_update_sm_client_id(self
);
846 client_update_strut(self
);
847 client_update_icons(self
);
850 static void client_get_startup_id(ObClient
*self
)
852 if (!(PROP_GETS(self
->window
, net_startup_id
, utf8
, &self
->startup_id
)))
854 PROP_GETS(self
->group
->leader
,
855 net_startup_id
, utf8
, &self
->startup_id
);
858 static void client_get_area(ObClient
*self
)
860 XWindowAttributes wattrib
;
863 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
864 g_assert(ret
!= BadWindow
);
866 RECT_SET(self
->area
, wattrib
.x
, wattrib
.y
, wattrib
.width
, wattrib
.height
);
867 self
->border_width
= wattrib
.border_width
;
870 static void client_get_desktop(ObClient
*self
)
872 guint32 d
= screen_num_desktops
; /* an always-invalid value */
874 if (PROP_GET32(self
->window
, net_wm_desktop
, cardinal
, &d
)) {
875 if (d
>= screen_num_desktops
&& d
!= DESKTOP_ALL
)
876 self
->desktop
= screen_num_desktops
- 1;
880 gboolean trdesk
= FALSE
;
882 if (self
->transient_for
) {
883 if (self
->transient_for
!= OB_TRAN_GROUP
) {
884 self
->desktop
= self
->transient_for
->desktop
;
889 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
))
890 if (it
->data
!= self
&&
891 !((ObClient
*)it
->data
)->transient_for
) {
892 self
->desktop
= ((ObClient
*)it
->data
)->desktop
;
899 /* try get from the startup-notification protocol */
900 if (sn_get_desktop(self
->startup_id
, &self
->desktop
)) {
901 if (self
->desktop
>= screen_num_desktops
&&
902 self
->desktop
!= DESKTOP_ALL
)
903 self
->desktop
= screen_num_desktops
- 1;
905 /* defaults to the current desktop */
906 self
->desktop
= screen_desktop
;
909 if (self
->desktop
!= d
) {
910 /* set the desktop hint, to make sure that it always exists */
911 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, self
->desktop
);
915 static void client_get_state(ObClient
*self
)
920 if (PROP_GETA32(self
->window
, net_wm_state
, atom
, &state
, &num
)) {
922 for (i
= 0; i
< num
; ++i
) {
923 if (state
[i
] == prop_atoms
.net_wm_state_modal
)
925 else if (state
[i
] == prop_atoms
.net_wm_state_shaded
)
927 else if (state
[i
] == prop_atoms
.net_wm_state_hidden
)
929 else if (state
[i
] == prop_atoms
.net_wm_state_skip_taskbar
)
930 self
->skip_taskbar
= TRUE
;
931 else if (state
[i
] == prop_atoms
.net_wm_state_skip_pager
)
932 self
->skip_pager
= TRUE
;
933 else if (state
[i
] == prop_atoms
.net_wm_state_fullscreen
)
934 self
->fullscreen
= TRUE
;
935 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_vert
)
936 self
->max_vert
= TRUE
;
937 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_horz
)
938 self
->max_horz
= TRUE
;
939 else if (state
[i
] == prop_atoms
.net_wm_state_above
)
941 else if (state
[i
] == prop_atoms
.net_wm_state_below
)
943 else if (state
[i
] == prop_atoms
.ob_wm_state_undecorated
)
944 self
->undecorated
= TRUE
;
950 if (!(self
->above
|| self
->below
)) {
952 /* apply stuff from the group */
956 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
957 ObClient
*c
= it
->data
;
958 if (c
!= self
&& !client_search_transient(self
, c
) &&
959 client_normal(self
) && client_normal(c
))
962 (c
->above
? 1 : (c
->below
? -1 : 0)));
976 g_assert_not_reached();
983 static void client_get_shaped(ObClient
*self
)
985 self
->shaped
= FALSE
;
987 if (extensions_shape
) {
992 XShapeSelectInput(ob_display
, self
->window
, ShapeNotifyMask
);
994 XShapeQueryExtents(ob_display
, self
->window
, &s
, &foo
,
995 &foo
, &ufoo
, &ufoo
, &foo
, &foo
, &foo
, &ufoo
,
997 self
->shaped
= (s
!= 0);
1002 void client_update_transient_for(ObClient
*self
)
1005 ObClient
*target
= NULL
;
1007 if (XGetTransientForHint(ob_display
, self
->window
, &t
)) {
1008 self
->transient
= TRUE
;
1009 if (t
!= self
->window
) { /* cant be transient to itself! */
1010 target
= g_hash_table_lookup(window_map
, &t
);
1011 /* if this happens then we need to check for it*/
1012 g_assert(target
!= self
);
1013 if (target
&& !WINDOW_IS_CLIENT(target
)) {
1014 /* this can happen when a dialog is a child of
1015 a dockapp, for example */
1019 if (!target
&& self
->group
) {
1020 /* not transient to a client, see if it is transient for a
1022 if (t
== self
->group
->leader
||
1024 t
== RootWindow(ob_display
, ob_screen
))
1026 /* window is a transient for its group! */
1027 target
= OB_TRAN_GROUP
;
1031 } else if (self
->type
== OB_CLIENT_TYPE_DIALOG
&& self
->group
) {
1032 self
->transient
= TRUE
;
1033 target
= OB_TRAN_GROUP
;
1035 self
->transient
= FALSE
;
1037 /* if anything has changed... */
1038 if (target
!= self
->transient_for
) {
1039 if (self
->transient_for
== OB_TRAN_GROUP
) { /* transient of group */
1042 /* remove from old parents */
1043 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
1044 ObClient
*c
= it
->data
;
1045 if (c
!= self
&& !c
->transient_for
)
1046 c
->transients
= g_slist_remove(c
->transients
, self
);
1048 } else if (self
->transient_for
!= NULL
) { /* transient of window */
1049 /* remove from old parent */
1050 self
->transient_for
->transients
=
1051 g_slist_remove(self
->transient_for
->transients
, self
);
1053 self
->transient_for
= target
;
1054 if (self
->transient_for
== OB_TRAN_GROUP
) { /* transient of group */
1057 /* add to new parents */
1058 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
1059 ObClient
*c
= it
->data
;
1060 if (c
!= self
&& !c
->transient_for
)
1061 c
->transients
= g_slist_append(c
->transients
, self
);
1064 /* remove all transients which are in the group, that causes
1065 circlular pointer hell of doom */
1066 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
1068 for (sit
= self
->transients
; sit
; sit
= next
) {
1069 next
= g_slist_next(sit
);
1070 if (sit
->data
== it
->data
)
1072 g_slist_delete_link(self
->transients
, sit
);
1075 } else if (self
->transient_for
!= NULL
) { /* transient of window */
1076 /* add to new parent */
1077 self
->transient_for
->transients
=
1078 g_slist_append(self
->transient_for
->transients
, self
);
1083 static void client_get_mwm_hints(ObClient
*self
)
1088 self
->mwmhints
.flags
= 0; /* default to none */
1090 if (PROP_GETA32(self
->window
, motif_wm_hints
, motif_wm_hints
,
1092 if (num
>= OB_MWM_ELEMENTS
) {
1093 self
->mwmhints
.flags
= hints
[0];
1094 self
->mwmhints
.functions
= hints
[1];
1095 self
->mwmhints
.decorations
= hints
[2];
1101 void client_get_type(ObClient
*self
)
1108 if (PROP_GETA32(self
->window
, net_wm_window_type
, atom
, &val
, &num
)) {
1109 /* use the first value that we know about in the array */
1110 for (i
= 0; i
< num
; ++i
) {
1111 if (val
[i
] == prop_atoms
.net_wm_window_type_desktop
)
1112 self
->type
= OB_CLIENT_TYPE_DESKTOP
;
1113 else if (val
[i
] == prop_atoms
.net_wm_window_type_dock
)
1114 self
->type
= OB_CLIENT_TYPE_DOCK
;
1115 else if (val
[i
] == prop_atoms
.net_wm_window_type_toolbar
)
1116 self
->type
= OB_CLIENT_TYPE_TOOLBAR
;
1117 else if (val
[i
] == prop_atoms
.net_wm_window_type_menu
)
1118 self
->type
= OB_CLIENT_TYPE_MENU
;
1119 else if (val
[i
] == prop_atoms
.net_wm_window_type_utility
)
1120 self
->type
= OB_CLIENT_TYPE_UTILITY
;
1121 else if (val
[i
] == prop_atoms
.net_wm_window_type_splash
)
1122 self
->type
= OB_CLIENT_TYPE_SPLASH
;
1123 else if (val
[i
] == prop_atoms
.net_wm_window_type_dialog
)
1124 self
->type
= OB_CLIENT_TYPE_DIALOG
;
1125 else if (val
[i
] == prop_atoms
.net_wm_window_type_normal
)
1126 self
->type
= OB_CLIENT_TYPE_NORMAL
;
1127 else if (val
[i
] == prop_atoms
.kde_net_wm_window_type_override
) {
1128 /* prevent this window from getting any decor or
1130 self
->mwmhints
.flags
&= (OB_MWM_FLAG_FUNCTIONS
|
1131 OB_MWM_FLAG_DECORATIONS
);
1132 self
->mwmhints
.decorations
= 0;
1133 self
->mwmhints
.functions
= 0;
1135 if (self
->type
!= (ObClientType
) -1)
1136 break; /* grab the first legit type */
1141 if (self
->type
== (ObClientType
) -1) {
1142 /*the window type hint was not set, which means we either classify
1143 ourself as a normal window or a dialog, depending on if we are a
1145 if (self
->transient
)
1146 self
->type
= OB_CLIENT_TYPE_DIALOG
;
1148 self
->type
= OB_CLIENT_TYPE_NORMAL
;
1152 void client_update_protocols(ObClient
*self
)
1155 guint num_return
, i
;
1157 self
->focus_notify
= FALSE
;
1158 self
->delete_window
= FALSE
;
1160 if (PROP_GETA32(self
->window
, wm_protocols
, atom
, &proto
, &num_return
)) {
1161 for (i
= 0; i
< num_return
; ++i
) {
1162 if (proto
[i
] == prop_atoms
.wm_delete_window
) {
1163 /* this means we can request the window to close */
1164 self
->delete_window
= TRUE
;
1165 } else if (proto
[i
] == prop_atoms
.wm_take_focus
)
1166 /* if this protocol is requested, then the window will be
1167 notified whenever we want it to receive focus */
1168 self
->focus_notify
= TRUE
;
1174 static void client_get_gravity(ObClient
*self
)
1176 XWindowAttributes wattrib
;
1179 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
1180 g_assert(ret
!= BadWindow
);
1181 self
->gravity
= wattrib
.win_gravity
;
1184 void client_update_normal_hints(ObClient
*self
)
1188 gint oldgravity
= self
->gravity
;
1191 self
->min_ratio
= 0.0f
;
1192 self
->max_ratio
= 0.0f
;
1193 SIZE_SET(self
->size_inc
, 1, 1);
1194 SIZE_SET(self
->base_size
, 0, 0);
1195 SIZE_SET(self
->min_size
, 0, 0);
1196 SIZE_SET(self
->max_size
, G_MAXINT
, G_MAXINT
);
1198 /* get the hints from the window */
1199 if (XGetWMNormalHints(ob_display
, self
->window
, &size
, &ret
)) {
1200 /* normal windows can't request placement! har har
1201 if (!client_normal(self))
1203 self
->positioned
= (size
.flags
& (PPosition
|USPosition
));
1205 if (size
.flags
& PWinGravity
) {
1206 self
->gravity
= size
.win_gravity
;
1208 /* if the client has a frame, i.e. has already been mapped and
1209 is changing its gravity */
1210 if (self
->frame
&& self
->gravity
!= oldgravity
) {
1211 /* move our idea of the client's position based on its new
1213 self
->area
.x
= self
->frame
->area
.x
;
1214 self
->area
.y
= self
->frame
->area
.y
;
1215 frame_frame_gravity(self
->frame
, &self
->area
.x
, &self
->area
.y
);
1219 if (size
.flags
& PAspect
) {
1220 if (size
.min_aspect
.y
)
1222 (gfloat
) size
.min_aspect
.x
/ size
.min_aspect
.y
;
1223 if (size
.max_aspect
.y
)
1225 (gfloat
) size
.max_aspect
.x
/ size
.max_aspect
.y
;
1228 if (size
.flags
& PMinSize
)
1229 SIZE_SET(self
->min_size
, size
.min_width
, size
.min_height
);
1231 if (size
.flags
& PMaxSize
)
1232 SIZE_SET(self
->max_size
, size
.max_width
, size
.max_height
);
1234 if (size
.flags
& PBaseSize
)
1235 SIZE_SET(self
->base_size
, size
.base_width
, size
.base_height
);
1237 if (size
.flags
& PResizeInc
&& size
.width_inc
&& size
.height_inc
)
1238 SIZE_SET(self
->size_inc
, size
.width_inc
, size
.height_inc
);
1242 void client_setup_decor_and_functions(ObClient
*self
)
1244 /* start with everything (cept fullscreen) */
1246 (OB_FRAME_DECOR_TITLEBAR
|
1247 OB_FRAME_DECOR_HANDLE
|
1248 OB_FRAME_DECOR_GRIPS
|
1249 OB_FRAME_DECOR_BORDER
|
1250 OB_FRAME_DECOR_ICON
|
1251 OB_FRAME_DECOR_ALLDESKTOPS
|
1252 OB_FRAME_DECOR_ICONIFY
|
1253 OB_FRAME_DECOR_MAXIMIZE
|
1254 OB_FRAME_DECOR_SHADE
|
1255 OB_FRAME_DECOR_CLOSE
);
1257 (OB_CLIENT_FUNC_RESIZE
|
1258 OB_CLIENT_FUNC_MOVE
|
1259 OB_CLIENT_FUNC_ICONIFY
|
1260 OB_CLIENT_FUNC_MAXIMIZE
|
1261 OB_CLIENT_FUNC_SHADE
|
1262 OB_CLIENT_FUNC_CLOSE
);
1264 if (!(self
->min_size
.width
< self
->max_size
.width
||
1265 self
->min_size
.height
< self
->max_size
.height
))
1266 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
1268 switch (self
->type
) {
1269 case OB_CLIENT_TYPE_NORMAL
:
1270 /* normal windows retain all of the possible decorations and
1271 functionality, and are the only windows that you can fullscreen */
1272 self
->functions
|= OB_CLIENT_FUNC_FULLSCREEN
;
1275 case OB_CLIENT_TYPE_DIALOG
:
1276 case OB_CLIENT_TYPE_UTILITY
:
1277 /* these windows cannot be maximized */
1278 self
->functions
&= ~OB_CLIENT_FUNC_MAXIMIZE
;
1281 case OB_CLIENT_TYPE_MENU
:
1282 case OB_CLIENT_TYPE_TOOLBAR
:
1283 /* these windows get less functionality */
1284 self
->functions
&= ~(OB_CLIENT_FUNC_ICONIFY
| OB_CLIENT_FUNC_RESIZE
);
1287 case OB_CLIENT_TYPE_DESKTOP
:
1288 case OB_CLIENT_TYPE_DOCK
:
1289 case OB_CLIENT_TYPE_SPLASH
:
1290 /* none of these windows are manipulated by the window manager */
1291 self
->decorations
= 0;
1292 self
->functions
= 0;
1296 /* Mwm Hints are applied subtractively to what has already been chosen for
1297 decor and functionality */
1298 if (self
->mwmhints
.flags
& OB_MWM_FLAG_DECORATIONS
) {
1299 if (! (self
->mwmhints
.decorations
& OB_MWM_DECOR_ALL
)) {
1300 if (! ((self
->mwmhints
.decorations
& OB_MWM_DECOR_HANDLE
) ||
1301 (self
->mwmhints
.decorations
& OB_MWM_DECOR_TITLE
)))
1302 /* if the mwm hints request no handle or title, then all
1303 decorations are disabled */
1304 self
->decorations
= config_theme_keepborder
? OB_FRAME_DECOR_BORDER
: 0;
1308 if (self
->mwmhints
.flags
& OB_MWM_FLAG_FUNCTIONS
) {
1309 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_ALL
)) {
1310 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_RESIZE
))
1311 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
1312 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_MOVE
))
1313 self
->functions
&= ~OB_CLIENT_FUNC_MOVE
;
1314 /* dont let mwm hints kill any buttons
1315 if (! (self->mwmhints.functions & OB_MWM_FUNC_ICONIFY))
1316 self->functions &= ~OB_CLIENT_FUNC_ICONIFY;
1317 if (! (self->mwmhints.functions & OB_MWM_FUNC_MAXIMIZE))
1318 self->functions &= ~OB_CLIENT_FUNC_MAXIMIZE;
1320 /* dont let mwm hints kill the close button
1321 if (! (self->mwmhints.functions & MwmFunc_Close))
1322 self->functions &= ~OB_CLIENT_FUNC_CLOSE; */
1326 if (!(self
->functions
& OB_CLIENT_FUNC_SHADE
))
1327 self
->decorations
&= ~OB_FRAME_DECOR_SHADE
;
1328 if (!(self
->functions
& OB_CLIENT_FUNC_ICONIFY
))
1329 self
->decorations
&= ~OB_FRAME_DECOR_ICONIFY
;
1330 if (!(self
->functions
& OB_CLIENT_FUNC_RESIZE
))
1331 self
->decorations
&= ~OB_FRAME_DECOR_GRIPS
;
1333 /* can't maximize without moving/resizing */
1334 if (!((self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) &&
1335 (self
->functions
& OB_CLIENT_FUNC_MOVE
) &&
1336 (self
->functions
& OB_CLIENT_FUNC_RESIZE
))) {
1337 self
->functions
&= ~OB_CLIENT_FUNC_MAXIMIZE
;
1338 self
->decorations
&= ~OB_FRAME_DECOR_MAXIMIZE
;
1341 /* kill the handle on fully maxed windows */
1342 if (self
->max_vert
&& self
->max_horz
)
1343 self
->decorations
&= ~OB_FRAME_DECOR_HANDLE
;
1345 /* finally, the user can have requested no decorations, which overrides
1346 everything (but doesnt give it a border if it doesnt have one) */
1347 if (self
->undecorated
) {
1348 if (config_theme_keepborder
)
1349 self
->decorations
&= OB_FRAME_DECOR_BORDER
;
1351 self
->decorations
= 0;
1354 /* if we don't have a titlebar, then we cannot shade! */
1355 if (!(self
->decorations
& OB_FRAME_DECOR_TITLEBAR
))
1356 self
->functions
&= ~OB_CLIENT_FUNC_SHADE
;
1358 /* now we need to check against rules for the client's current state */
1359 if (self
->fullscreen
) {
1360 self
->functions
&= (OB_CLIENT_FUNC_CLOSE
|
1361 OB_CLIENT_FUNC_FULLSCREEN
|
1362 OB_CLIENT_FUNC_ICONIFY
);
1363 self
->decorations
= 0;
1366 client_change_allowed_actions(self
);
1369 /* adjust the client's decorations, etc. */
1370 client_reconfigure(self
);
1374 static void client_change_allowed_actions(ObClient
*self
)
1379 /* desktop windows are kept on all desktops */
1380 if (self
->type
!= OB_CLIENT_TYPE_DESKTOP
)
1381 actions
[num
++] = prop_atoms
.net_wm_action_change_desktop
;
1383 if (self
->functions
& OB_CLIENT_FUNC_SHADE
)
1384 actions
[num
++] = prop_atoms
.net_wm_action_shade
;
1385 if (self
->functions
& OB_CLIENT_FUNC_CLOSE
)
1386 actions
[num
++] = prop_atoms
.net_wm_action_close
;
1387 if (self
->functions
& OB_CLIENT_FUNC_MOVE
)
1388 actions
[num
++] = prop_atoms
.net_wm_action_move
;
1389 if (self
->functions
& OB_CLIENT_FUNC_ICONIFY
)
1390 actions
[num
++] = prop_atoms
.net_wm_action_minimize
;
1391 if (self
->functions
& OB_CLIENT_FUNC_RESIZE
)
1392 actions
[num
++] = prop_atoms
.net_wm_action_resize
;
1393 if (self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
)
1394 actions
[num
++] = prop_atoms
.net_wm_action_fullscreen
;
1395 if (self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) {
1396 actions
[num
++] = prop_atoms
.net_wm_action_maximize_horz
;
1397 actions
[num
++] = prop_atoms
.net_wm_action_maximize_vert
;
1400 PROP_SETA32(self
->window
, net_wm_allowed_actions
, atom
, actions
, num
);
1402 /* make sure the window isn't breaking any rules now */
1404 if (!(self
->functions
& OB_CLIENT_FUNC_SHADE
) && self
->shaded
) {
1405 if (self
->frame
) client_shade(self
, FALSE
);
1406 else self
->shaded
= FALSE
;
1408 if (!(self
->functions
& OB_CLIENT_FUNC_ICONIFY
) && self
->iconic
) {
1409 if (self
->frame
) client_iconify(self
, FALSE
, TRUE
);
1410 else self
->iconic
= FALSE
;
1412 if (!(self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
) && self
->fullscreen
) {
1413 if (self
->frame
) client_fullscreen(self
, FALSE
, TRUE
);
1414 else self
->fullscreen
= FALSE
;
1416 if (!(self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) && (self
->max_horz
||
1418 if (self
->frame
) client_maximize(self
, FALSE
, 0, TRUE
);
1419 else self
->max_vert
= self
->max_horz
= FALSE
;
1423 void client_reconfigure(ObClient
*self
)
1425 /* by making this pass FALSE for user, we avoid the emacs event storm where
1426 every configurenotify causes an update in its normal hints, i think this
1427 is generally what we want anyways... */
1428 client_configure(self
, OB_CORNER_TOPLEFT
, self
->area
.x
, self
->area
.y
,
1429 self
->area
.width
, self
->area
.height
, FALSE
, TRUE
);
1432 void client_update_wmhints(ObClient
*self
)
1435 gboolean ur
= FALSE
;
1438 /* assume a window takes input if it doesnt specify */
1439 self
->can_focus
= TRUE
;
1441 if ((hints
= XGetWMHints(ob_display
, self
->window
)) != NULL
) {
1442 if (hints
->flags
& InputHint
)
1443 self
->can_focus
= hints
->input
;
1445 /* only do this when first managing the window *AND* when we aren't
1447 if (ob_state() != OB_STATE_STARTING
&& self
->frame
== NULL
)
1448 if (hints
->flags
& StateHint
)
1449 self
->iconic
= hints
->initial_state
== IconicState
;
1451 if (hints
->flags
& XUrgencyHint
)
1454 if (!(hints
->flags
& WindowGroupHint
))
1455 hints
->window_group
= None
;
1457 /* did the group state change? */
1458 if (hints
->window_group
!=
1459 (self
->group
? self
->group
->leader
: None
)) {
1460 /* remove from the old group if there was one */
1461 if (self
->group
!= NULL
) {
1462 /* remove transients of the group */
1463 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
))
1464 self
->transients
= g_slist_remove(self
->transients
,
1467 /* remove myself from parents in the group */
1468 if (self
->transient_for
== OB_TRAN_GROUP
) {
1469 for (it
= self
->group
->members
; it
;
1470 it
= g_slist_next(it
))
1472 ObClient
*c
= it
->data
;
1474 if (c
!= self
&& !c
->transient_for
)
1475 c
->transients
= g_slist_remove(c
->transients
,
1480 group_remove(self
->group
, self
);
1483 if (hints
->window_group
!= None
) {
1484 self
->group
= group_add(hints
->window_group
, self
);
1486 /* i can only have transients from the group if i am not
1488 if (!self
->transient_for
) {
1489 /* add other transients of the group that are already
1491 for (it
= self
->group
->members
; it
;
1492 it
= g_slist_next(it
))
1494 ObClient
*c
= it
->data
;
1495 if (c
!= self
&& c
->transient_for
== OB_TRAN_GROUP
)
1497 g_slist_append(self
->transients
, c
);
1502 /* because the self->transient flag wont change from this call,
1503 we don't need to update the window's type and such, only its
1504 transient_for, and the transients lists of other windows in
1505 the group may be affected */
1506 client_update_transient_for(self
);
1509 /* the WM_HINTS can contain an icon */
1510 client_update_icons(self
);
1515 if (ur
!= self
->urgent
) {
1517 /* fire the urgent callback if we're mapped, otherwise, wait until
1518 after we're mapped */
1520 client_urgent_notify(self
);
1524 void client_update_title(ObClient
*self
)
1530 gboolean read_title
;
1533 old_title
= self
->title
;
1536 if (!PROP_GETS(self
->window
, net_wm_name
, utf8
, &data
)) {
1537 /* try old x stuff */
1538 if (!(PROP_GETS(self
->window
, wm_name
, locale
, &data
)
1539 || PROP_GETS(self
->window
, wm_name
, utf8
, &data
))) {
1540 // http://developer.gnome.org/projects/gup/hig/draft_hig_new/windows-alert.html
1541 if (self
->transient
) {
1542 data
= g_strdup("");
1545 data
= g_strdup("Unnamed Window");
1549 /* did the title change? then reset the title_count */
1550 if (old_title
&& 0 != strncmp(old_title
, data
, strlen(data
)))
1551 self
->title_count
= 1;
1553 /* look for duplicates and append a number */
1555 for (it
= client_list
; it
; it
= g_list_next(it
))
1556 if (it
->data
!= self
) {
1557 ObClient
*c
= it
->data
;
1558 if (0 == strncmp(c
->title
, data
, strlen(data
)))
1559 nums
|= 1 << c
->title_count
;
1561 /* find first free number */
1562 for (i
= 1; i
<= 32; ++i
)
1563 if (!(nums
& (1 << i
))) {
1564 if (self
->title_count
== 1 || i
== 1)
1565 self
->title_count
= i
;
1568 /* dont display the number for the first window */
1569 if (self
->title_count
> 1) {
1571 ndata
= g_strdup_printf("%s - [%u]", data
, self
->title_count
);
1577 PROP_SETS(self
->window
, net_wm_visible_name
, data
);
1581 frame_adjust_title(self
->frame
);
1585 /* update the icon title */
1587 g_free(self
->icon_title
);
1591 if (!PROP_GETS(self
->window
, net_wm_icon_name
, utf8
, &data
))
1592 /* try old x stuff */
1593 if (!(PROP_GETS(self
->window
, wm_icon_name
, locale
, &data
)
1594 || PROP_GETS(self
->window
, wm_icon_name
, utf8
, &data
))) {
1595 data
= g_strdup(self
->title
);
1599 /* append the title count, dont display the number for the first window */
1600 if (read_title
&& self
->title_count
> 1) {
1601 gchar
*vdata
, *ndata
;
1602 ndata
= g_strdup_printf(" - [%u]", self
->title_count
);
1603 vdata
= g_strconcat(data
, ndata
, NULL
);
1609 PROP_SETS(self
->window
, net_wm_visible_icon_name
, data
);
1611 self
->icon_title
= data
;
1614 void client_update_class(ObClient
*self
)
1619 if (self
->name
) g_free(self
->name
);
1620 if (self
->class) g_free(self
->class);
1621 if (self
->role
) g_free(self
->role
);
1623 self
->name
= self
->class = self
->role
= NULL
;
1625 if (PROP_GETSS(self
->window
, wm_class
, locale
, &data
)) {
1627 self
->name
= g_strdup(data
[0]);
1629 self
->class = g_strdup(data
[1]);
1634 if (PROP_GETS(self
->window
, wm_window_role
, locale
, &s
))
1637 if (self
->name
== NULL
) self
->name
= g_strdup("");
1638 if (self
->class == NULL
) self
->class = g_strdup("");
1639 if (self
->role
== NULL
) self
->role
= g_strdup("");
1642 void client_update_strut(ObClient
*self
)
1646 gboolean got
= FALSE
;
1649 if (PROP_GETA32(self
->window
, net_wm_strut_partial
, cardinal
,
1653 STRUT_PARTIAL_SET(strut
,
1654 data
[0], data
[2], data
[1], data
[3],
1655 data
[4], data
[5], data
[8], data
[9],
1656 data
[6], data
[7], data
[10], data
[11]);
1662 PROP_GETA32(self
->window
, net_wm_strut
, cardinal
, &data
, &num
)) {
1668 /* use the screen's width/height */
1669 a
= screen_physical_area();
1671 STRUT_PARTIAL_SET(strut
,
1672 data
[0], data
[2], data
[1], data
[3],
1673 a
->y
, a
->y
+ a
->height
- 1,
1674 a
->x
, a
->x
+ a
->width
- 1,
1675 a
->y
, a
->y
+ a
->height
- 1,
1676 a
->x
, a
->x
+ a
->width
- 1);
1682 STRUT_PARTIAL_SET(strut
, 0, 0, 0, 0,
1683 0, 0, 0, 0, 0, 0, 0, 0);
1685 if (!STRUT_EQUAL(strut
, self
->strut
)) {
1686 self
->strut
= strut
;
1688 /* updating here is pointless while we're being mapped cuz we're not in
1689 the client list yet */
1691 screen_update_areas();
1695 void client_update_icons(ObClient
*self
)
1701 for (i
= 0; i
< self
->nicons
; ++i
)
1702 g_free(self
->icons
[i
].data
);
1703 if (self
->nicons
> 0)
1704 g_free(self
->icons
);
1707 if (PROP_GETA32(self
->window
, net_wm_icon
, cardinal
, &data
, &num
)) {
1708 /* figure out how many valid icons are in here */
1710 while (num
- i
> 2) {
1714 if (i
> num
|| w
*h
== 0) break;
1718 self
->icons
= g_new(ObClientIcon
, self
->nicons
);
1720 /* store the icons */
1722 for (j
= 0; j
< self
->nicons
; ++j
) {
1725 w
= self
->icons
[j
].width
= data
[i
++];
1726 h
= self
->icons
[j
].height
= data
[i
++];
1728 if (w
*h
== 0) continue;
1730 self
->icons
[j
].data
= g_new(RrPixel32
, w
* h
);
1731 for (x
= 0, y
= 0, t
= 0; t
< w
* h
; ++t
, ++x
, ++i
) {
1736 self
->icons
[j
].data
[t
] =
1737 (((data
[i
] >> 24) & 0xff) << RrDefaultAlphaOffset
) +
1738 (((data
[i
] >> 16) & 0xff) << RrDefaultRedOffset
) +
1739 (((data
[i
] >> 8) & 0xff) << RrDefaultGreenOffset
) +
1740 (((data
[i
] >> 0) & 0xff) << RrDefaultBlueOffset
);
1746 } else if (PROP_GETA32(self
->window
, kwm_win_icon
,
1747 kwm_win_icon
, &data
, &num
)) {
1750 self
->icons
= g_new(ObClientIcon
, self
->nicons
);
1751 xerror_set_ignore(TRUE
);
1752 if (!RrPixmapToRGBA(ob_rr_inst
,
1754 &self
->icons
[self
->nicons
-1].width
,
1755 &self
->icons
[self
->nicons
-1].height
,
1756 &self
->icons
[self
->nicons
-1].data
)) {
1757 g_free(&self
->icons
[self
->nicons
-1]);
1760 xerror_set_ignore(FALSE
);
1766 if ((hints
= XGetWMHints(ob_display
, self
->window
))) {
1767 if (hints
->flags
& IconPixmapHint
) {
1769 self
->icons
= g_new(ObClientIcon
, self
->nicons
);
1770 xerror_set_ignore(TRUE
);
1771 if (!RrPixmapToRGBA(ob_rr_inst
,
1773 (hints
->flags
& IconMaskHint
?
1774 hints
->icon_mask
: None
),
1775 &self
->icons
[self
->nicons
-1].width
,
1776 &self
->icons
[self
->nicons
-1].height
,
1777 &self
->icons
[self
->nicons
-1].data
)){
1778 g_free(&self
->icons
[self
->nicons
-1]);
1781 xerror_set_ignore(FALSE
);
1788 frame_adjust_icon(self
->frame
);
1791 static void client_change_state(ObClient
*self
)
1794 gulong netstate
[11];
1797 state
[0] = self
->wmstate
;
1799 PROP_SETA32(self
->window
, wm_state
, wm_state
, state
, 2);
1803 netstate
[num
++] = prop_atoms
.net_wm_state_modal
;
1805 netstate
[num
++] = prop_atoms
.net_wm_state_shaded
;
1807 netstate
[num
++] = prop_atoms
.net_wm_state_hidden
;
1808 if (self
->skip_taskbar
)
1809 netstate
[num
++] = prop_atoms
.net_wm_state_skip_taskbar
;
1810 if (self
->skip_pager
)
1811 netstate
[num
++] = prop_atoms
.net_wm_state_skip_pager
;
1812 if (self
->fullscreen
)
1813 netstate
[num
++] = prop_atoms
.net_wm_state_fullscreen
;
1815 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_vert
;
1817 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_horz
;
1819 netstate
[num
++] = prop_atoms
.net_wm_state_above
;
1821 netstate
[num
++] = prop_atoms
.net_wm_state_below
;
1822 if (self
->undecorated
)
1823 netstate
[num
++] = prop_atoms
.ob_wm_state_undecorated
;
1824 PROP_SETA32(self
->window
, net_wm_state
, atom
, netstate
, num
);
1826 client_calc_layer(self
);
1829 frame_adjust_state(self
->frame
);
1832 ObClient
*client_search_focus_tree(ObClient
*self
)
1837 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
1838 if (client_focused(it
->data
)) return it
->data
;
1839 if ((ret
= client_search_focus_tree(it
->data
))) return ret
;
1844 ObClient
*client_search_focus_tree_full(ObClient
*self
)
1846 if (self
->transient_for
) {
1847 if (self
->transient_for
!= OB_TRAN_GROUP
) {
1848 return client_search_focus_tree_full(self
->transient_for
);
1851 gboolean recursed
= FALSE
;
1853 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
))
1854 if (!((ObClient
*)it
->data
)->transient_for
) {
1856 if ((c
= client_search_focus_tree_full(it
->data
)))
1865 /* this function checks the whole tree, the client_search_focus_tree~
1866 does not, so we need to check this window */
1867 if (client_focused(self
))
1869 return client_search_focus_tree(self
);
1872 static ObStackingLayer
calc_layer(ObClient
*self
)
1876 if (self
->fullscreen
&&
1877 (client_focused(self
) || client_search_focus_tree(self
)))
1878 l
= OB_STACKING_LAYER_FULLSCREEN
;
1879 else if (self
->type
== OB_CLIENT_TYPE_DESKTOP
)
1880 l
= OB_STACKING_LAYER_DESKTOP
;
1881 else if (self
->type
== OB_CLIENT_TYPE_DOCK
) {
1882 if (self
->below
) l
= OB_STACKING_LAYER_NORMAL
;
1883 else l
= OB_STACKING_LAYER_ABOVE
;
1885 else if (self
->above
) l
= OB_STACKING_LAYER_ABOVE
;
1886 else if (self
->below
) l
= OB_STACKING_LAYER_BELOW
;
1887 else l
= OB_STACKING_LAYER_NORMAL
;
1892 static void client_calc_layer_recursive(ObClient
*self
, ObClient
*orig
,
1893 ObStackingLayer l
, gboolean raised
)
1895 ObStackingLayer old
, own
;
1899 own
= calc_layer(self
);
1900 self
->layer
= l
> own
? l
: own
;
1902 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
1903 client_calc_layer_recursive(it
->data
, orig
,
1904 l
, raised
? raised
: l
!= old
);
1906 if (!raised
&& l
!= old
)
1907 if (orig
->frame
) { /* only restack if the original window is managed */
1908 stacking_remove(CLIENT_AS_WINDOW(self
));
1909 stacking_add(CLIENT_AS_WINDOW(self
));
1913 void client_calc_layer(ObClient
*self
)
1920 /* transients take on the layer of their parents */
1921 self
= client_search_top_transient(self
);
1923 l
= calc_layer(self
);
1925 client_calc_layer_recursive(self
, orig
, l
, FALSE
);
1928 gboolean
client_should_show(ObClient
*self
)
1932 if (client_normal(self
) && screen_showing_desktop
)
1935 if (self->transient_for) {
1936 if (self->transient_for != OB_TRAN_GROUP)
1937 return client_should_show(self->transient_for);
1941 for (it = self->group->members; it; it = g_slist_next(it)) {
1942 ObClient *c = it->data;
1943 if (c != self && !c->transient_for) {
1944 if (client_should_show(c))
1951 if (self
->desktop
== screen_desktop
|| self
->desktop
== DESKTOP_ALL
)
1957 static void client_showhide(ObClient
*self
)
1960 if (client_should_show(self
))
1961 frame_show(self
->frame
);
1963 frame_hide(self
->frame
);
1966 gboolean
client_normal(ObClient
*self
) {
1967 return ! (self
->type
== OB_CLIENT_TYPE_DESKTOP
||
1968 self
->type
== OB_CLIENT_TYPE_DOCK
||
1969 self
->type
== OB_CLIENT_TYPE_SPLASH
);
1972 static void client_apply_startup_state(ObClient
*self
)
1974 /* these are in a carefully crafted order.. */
1977 self
->iconic
= FALSE
;
1978 client_iconify(self
, TRUE
, FALSE
);
1980 if (self
->fullscreen
) {
1981 self
->fullscreen
= FALSE
;
1982 client_fullscreen(self
, TRUE
, FALSE
);
1984 if (self
->undecorated
) {
1985 self
->undecorated
= FALSE
;
1986 client_set_undecorated(self
, TRUE
);
1989 self
->shaded
= FALSE
;
1990 client_shade(self
, TRUE
);
1993 client_urgent_notify(self
);
1995 if (self
->max_vert
&& self
->max_horz
) {
1996 self
->max_vert
= self
->max_horz
= FALSE
;
1997 client_maximize(self
, TRUE
, 0, FALSE
);
1998 } else if (self
->max_vert
) {
1999 self
->max_vert
= FALSE
;
2000 client_maximize(self
, TRUE
, 2, FALSE
);
2001 } else if (self
->max_horz
) {
2002 self
->max_horz
= FALSE
;
2003 client_maximize(self
, TRUE
, 1, FALSE
);
2006 /* nothing to do for the other states:
2015 void client_configure_full(ObClient
*self
, ObCorner anchor
,
2016 gint x
, gint y
, gint w
, gint h
,
2017 gboolean user
, gboolean final
,
2018 gboolean force_reply
)
2021 gboolean send_resize_client
;
2022 gboolean moved
= FALSE
, resized
= FALSE
;
2023 guint fdecor
= self
->frame
->decorations
;
2024 gboolean fhorz
= self
->frame
->max_horz
;
2026 /* make the frame recalculate its dimentions n shit without changing
2027 anything visible for real, this way the constraints below can work with
2028 the updated frame dimensions. */
2029 frame_adjust_area(self
->frame
, TRUE
, TRUE
, TRUE
);
2031 /* gets the frame's position */
2032 frame_client_gravity(self
->frame
, &x
, &y
);
2034 /* these positions are frame positions, not client positions */
2036 /* set the size and position if fullscreen */
2037 if (self
->fullscreen
) {
2041 i
= client_monitor(self
);
2042 a
= screen_physical_area_monitor(i
);
2049 user
= FALSE
; /* ignore that increment etc shit when in fullscreen */
2053 a
= screen_area_monitor(self
->desktop
, client_monitor(self
));
2055 /* set the size and position if maximized */
2056 if (self
->max_horz
) {
2058 w
= a
->width
- self
->frame
->size
.left
- self
->frame
->size
.right
;
2060 if (self
->max_vert
) {
2062 h
= a
->height
- self
->frame
->size
.top
- self
->frame
->size
.bottom
;
2066 /* gets the client's position */
2067 frame_frame_gravity(self
->frame
, &x
, &y
);
2069 /* these override the above states! if you cant move you can't move! */
2071 if (!(self
->functions
& OB_CLIENT_FUNC_MOVE
)) {
2075 if (!(self
->functions
& OB_CLIENT_FUNC_RESIZE
)) {
2076 w
= self
->area
.width
;
2077 h
= self
->area
.height
;
2081 if (!(w
== self
->area
.width
&& h
== self
->area
.height
)) {
2082 gint basew
, baseh
, minw
, minh
;
2084 /* base size is substituted with min size if not specified */
2085 if (self
->base_size
.width
|| self
->base_size
.height
) {
2086 basew
= self
->base_size
.width
;
2087 baseh
= self
->base_size
.height
;
2089 basew
= self
->min_size
.width
;
2090 baseh
= self
->min_size
.height
;
2092 /* min size is substituted with base size if not specified */
2093 if (self
->min_size
.width
|| self
->min_size
.height
) {
2094 minw
= self
->min_size
.width
;
2095 minh
= self
->min_size
.height
;
2097 minw
= self
->base_size
.width
;
2098 minh
= self
->base_size
.height
;
2101 /* if this is a user-requested resize, then check against min/max
2104 /* smaller than min size or bigger than max size? */
2105 if (w
> self
->max_size
.width
) w
= self
->max_size
.width
;
2106 if (w
< minw
) w
= minw
;
2107 if (h
> self
->max_size
.height
) h
= self
->max_size
.height
;
2108 if (h
< minh
) h
= minh
;
2113 /* keep to the increments */
2114 w
/= self
->size_inc
.width
;
2115 h
/= self
->size_inc
.height
;
2117 /* you cannot resize to nothing */
2118 if (basew
+ w
< 1) w
= 1 - basew
;
2119 if (baseh
+ h
< 1) h
= 1 - baseh
;
2121 /* store the logical size */
2122 SIZE_SET(self
->logical_size
,
2123 self
->size_inc
.width
> 1 ? w
: w
+ basew
,
2124 self
->size_inc
.height
> 1 ? h
: h
+ baseh
);
2126 w
*= self
->size_inc
.width
;
2127 h
*= self
->size_inc
.height
;
2132 /* adjust the height to match the width for the aspect ratios.
2133 for this, min size is not substituted for base size ever. */
2134 w
-= self
->base_size
.width
;
2135 h
-= self
->base_size
.height
;
2137 if (!self
->fullscreen
) {
2138 if (self
->min_ratio
)
2139 if (h
* self
->min_ratio
> w
) {
2140 h
= (gint
)(w
/ self
->min_ratio
);
2142 /* you cannot resize to nothing */
2145 w
= (gint
)(h
* self
->min_ratio
);
2148 if (self
->max_ratio
)
2149 if (h
* self
->max_ratio
< w
) {
2150 h
= (gint
)(w
/ self
->max_ratio
);
2152 /* you cannot resize to nothing */
2155 w
= (gint
)(h
* self
->min_ratio
);
2160 w
+= self
->base_size
.width
;
2161 h
+= self
->base_size
.height
;
2168 case OB_CORNER_TOPLEFT
:
2170 case OB_CORNER_TOPRIGHT
:
2171 x
-= w
- self
->area
.width
;
2173 case OB_CORNER_BOTTOMLEFT
:
2174 y
-= h
- self
->area
.height
;
2176 case OB_CORNER_BOTTOMRIGHT
:
2177 x
-= w
- self
->area
.width
;
2178 y
-= h
- self
->area
.height
;
2182 moved
= x
!= self
->area
.x
|| y
!= self
->area
.y
;
2183 resized
= w
!= self
->area
.width
|| h
!= self
->area
.height
;
2185 oldw
= self
->area
.width
;
2186 oldh
= self
->area
.height
;
2187 RECT_SET(self
->area
, x
, y
, w
, h
);
2189 /* for app-requested resizes, always resize if 'resized' is true.
2190 for user-requested ones, only resize if final is true, or when
2191 resizing in redraw mode */
2192 send_resize_client
= ((!user
&& resized
) ||
2194 (resized
&& config_resize_redraw
))));
2196 /* if the client is enlarging, then resize the client before the frame */
2197 if (send_resize_client
&& user
&& (w
> oldw
|| h
> oldh
))
2198 XResizeWindow(ob_display
, self
->window
, MAX(w
, oldw
), MAX(h
, oldh
));
2200 /* move/resize the frame to match the request */
2202 if (self
->decorations
!= fdecor
|| self
->max_horz
!= fhorz
)
2203 moved
= resized
= TRUE
;
2205 if (moved
|| resized
)
2206 frame_adjust_area(self
->frame
, moved
, resized
, FALSE
);
2208 if (!resized
&& (force_reply
|| ((!user
&& moved
) || (user
&& final
))))
2211 event
.type
= ConfigureNotify
;
2212 event
.xconfigure
.display
= ob_display
;
2213 event
.xconfigure
.event
= self
->window
;
2214 event
.xconfigure
.window
= self
->window
;
2216 /* root window real coords */
2217 event
.xconfigure
.x
= self
->frame
->area
.x
+ self
->frame
->size
.left
-
2219 event
.xconfigure
.y
= self
->frame
->area
.y
+ self
->frame
->size
.top
-
2221 event
.xconfigure
.width
= w
;
2222 event
.xconfigure
.height
= h
;
2223 event
.xconfigure
.border_width
= 0;
2224 event
.xconfigure
.above
= self
->frame
->plate
;
2225 event
.xconfigure
.override_redirect
= FALSE
;
2226 XSendEvent(event
.xconfigure
.display
, event
.xconfigure
.window
,
2227 FALSE
, StructureNotifyMask
, &event
);
2231 /* if the client is shrinking, then resize the frame before the client */
2232 if (send_resize_client
&& (!user
|| (w
<= oldw
|| h
<= oldh
)))
2233 XResizeWindow(ob_display
, self
->window
, w
, h
);
2238 void client_fullscreen(ObClient
*self
, gboolean fs
, gboolean savearea
)
2242 if (!(self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
) || /* can't */
2243 self
->fullscreen
== fs
) return; /* already done */
2245 self
->fullscreen
= fs
;
2246 client_change_state(self
); /* change the state hints on the client,
2247 and adjust out layer/stacking */
2251 self
->pre_fullscreen_area
= self
->area
;
2253 /* these are not actually used cuz client_configure will set them
2254 as appropriate when the window is fullscreened */
2259 if (self
->pre_fullscreen_area
.width
> 0 &&
2260 self
->pre_fullscreen_area
.height
> 0)
2262 x
= self
->pre_fullscreen_area
.x
;
2263 y
= self
->pre_fullscreen_area
.y
;
2264 w
= self
->pre_fullscreen_area
.width
;
2265 h
= self
->pre_fullscreen_area
.height
;
2266 RECT_SET(self
->pre_fullscreen_area
, 0, 0, 0, 0);
2268 /* pick some fallbacks... */
2269 a
= screen_area_monitor(self
->desktop
, 0);
2270 x
= a
->x
+ a
->width
/ 4;
2271 y
= a
->y
+ a
->height
/ 4;
2277 client_setup_decor_and_functions(self
);
2279 client_move_resize(self
, x
, y
, w
, h
);
2281 /* try focus us when we go into fullscreen mode */
2285 static void client_iconify_recursive(ObClient
*self
,
2286 gboolean iconic
, gboolean curdesk
)
2289 gboolean changed
= FALSE
;
2292 if (self
->iconic
!= iconic
) {
2293 ob_debug("%sconifying window: 0x%lx\n", (iconic
? "I" : "Uni"),
2296 self
->iconic
= iconic
;
2299 if (self
->functions
& OB_CLIENT_FUNC_ICONIFY
) {
2302 old
= self
->wmstate
;
2303 self
->wmstate
= IconicState
;
2304 if (old
!= self
->wmstate
)
2305 PROP_MSG(self
->window
, kde_wm_change_state
,
2306 self
->wmstate
, 1, 0, 0);
2308 /* update the focus lists.. iconic windows go to the bottom of
2309 the list, put the new iconic window at the 'top of the
2311 focus_order_to_top(self
);
2319 client_set_desktop(self
, screen_desktop
, FALSE
);
2321 old
= self
->wmstate
;
2322 self
->wmstate
= self
->shaded
? IconicState
: NormalState
;
2323 if (old
!= self
->wmstate
)
2324 PROP_MSG(self
->window
, kde_wm_change_state
,
2325 self
->wmstate
, 1, 0, 0);
2327 /* this puts it after the current focused window */
2328 focus_order_remove(self
);
2329 focus_order_add_new(self
);
2336 client_change_state(self
);
2337 client_showhide(self
);
2338 screen_update_areas();
2341 /* iconify all transients */
2342 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
2343 if (it
->data
!= self
) client_iconify_recursive(it
->data
,
2347 void client_iconify(ObClient
*self
, gboolean iconic
, gboolean curdesk
)
2349 /* move up the transient chain as far as possible first */
2350 self
= client_search_top_transient(self
);
2352 client_iconify_recursive(client_search_top_transient(self
),
2356 void client_maximize(ObClient
*self
, gboolean max
, gint dir
, gboolean savearea
)
2360 g_assert(dir
== 0 || dir
== 1 || dir
== 2);
2361 if (!(self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
)) return; /* can't */
2363 /* check if already done */
2365 if (dir
== 0 && self
->max_horz
&& self
->max_vert
) return;
2366 if (dir
== 1 && self
->max_horz
) return;
2367 if (dir
== 2 && self
->max_vert
) return;
2369 if (dir
== 0 && !self
->max_horz
&& !self
->max_vert
) return;
2370 if (dir
== 1 && !self
->max_horz
) return;
2371 if (dir
== 2 && !self
->max_vert
) return;
2374 /* we just tell it to configure in the same place and client_configure
2375 worries about filling the screen with the window */
2378 w
= self
->area
.width
;
2379 h
= self
->area
.height
;
2383 if ((dir
== 0 || dir
== 1) && !self
->max_horz
) { /* horz */
2384 RECT_SET(self
->pre_max_area
,
2385 self
->area
.x
, self
->pre_max_area
.y
,
2386 self
->area
.width
, self
->pre_max_area
.height
);
2388 if ((dir
== 0 || dir
== 2) && !self
->max_vert
) { /* vert */
2389 RECT_SET(self
->pre_max_area
,
2390 self
->pre_max_area
.x
, self
->area
.y
,
2391 self
->pre_max_area
.width
, self
->area
.height
);
2397 a
= screen_area_monitor(self
->desktop
, 0);
2398 if ((dir
== 0 || dir
== 1) && self
->max_horz
) { /* horz */
2399 if (self
->pre_max_area
.width
> 0) {
2400 x
= self
->pre_max_area
.x
;
2401 w
= self
->pre_max_area
.width
;
2403 RECT_SET(self
->pre_max_area
, 0, self
->pre_max_area
.y
,
2404 0, self
->pre_max_area
.height
);
2406 /* pick some fallbacks... */
2407 x
= a
->x
+ a
->width
/ 4;
2411 if ((dir
== 0 || dir
== 2) && self
->max_vert
) { /* vert */
2412 if (self
->pre_max_area
.height
> 0) {
2413 y
= self
->pre_max_area
.y
;
2414 h
= self
->pre_max_area
.height
;
2416 RECT_SET(self
->pre_max_area
, self
->pre_max_area
.x
, 0,
2417 self
->pre_max_area
.width
, 0);
2419 /* pick some fallbacks... */
2420 y
= a
->y
+ a
->height
/ 4;
2426 if (dir
== 0 || dir
== 1) /* horz */
2427 self
->max_horz
= max
;
2428 if (dir
== 0 || dir
== 2) /* vert */
2429 self
->max_vert
= max
;
2431 client_change_state(self
); /* change the state hints on the client */
2433 client_setup_decor_and_functions(self
);
2435 client_move_resize(self
, x
, y
, w
, h
);
2438 void client_shade(ObClient
*self
, gboolean shade
)
2440 if ((!(self
->functions
& OB_CLIENT_FUNC_SHADE
) &&
2441 shade
) || /* can't shade */
2442 self
->shaded
== shade
) return; /* already done */
2444 /* when we're iconic, don't change the wmstate */
2445 if (!self
->iconic
) {
2448 old
= self
->wmstate
;
2449 self
->wmstate
= shade
? IconicState
: NormalState
;
2450 if (old
!= self
->wmstate
)
2451 PROP_MSG(self
->window
, kde_wm_change_state
,
2452 self
->wmstate
, 1, 0, 0);
2455 self
->shaded
= shade
;
2456 client_change_state(self
);
2457 /* resize the frame to just the titlebar */
2458 frame_adjust_area(self
->frame
, FALSE
, FALSE
, FALSE
);
2461 void client_close(ObClient
*self
)
2465 if (!(self
->functions
& OB_CLIENT_FUNC_CLOSE
)) return;
2467 /* in the case that the client provides no means to requesting that it
2468 close, we just kill it */
2469 if (!self
->delete_window
)
2473 XXX: itd be cool to do timeouts and shit here for killing the client's
2475 like... if the window is around after 5 seconds, then the close button
2476 turns a nice red, and if this function is called again, the client is
2480 ce
.xclient
.type
= ClientMessage
;
2481 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
2482 ce
.xclient
.display
= ob_display
;
2483 ce
.xclient
.window
= self
->window
;
2484 ce
.xclient
.format
= 32;
2485 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_delete_window
;
2486 ce
.xclient
.data
.l
[1] = event_lasttime
;
2487 ce
.xclient
.data
.l
[2] = 0l;
2488 ce
.xclient
.data
.l
[3] = 0l;
2489 ce
.xclient
.data
.l
[4] = 0l;
2490 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
2493 void client_kill(ObClient
*self
)
2495 XKillClient(ob_display
, self
->window
);
2498 void client_set_desktop_recursive(ObClient
*self
,
2499 guint target
, gboolean donthide
)
2504 if (target
!= self
->desktop
) {
2506 ob_debug("Setting desktop %u\n", target
+1);
2508 g_assert(target
< screen_num_desktops
|| target
== DESKTOP_ALL
);
2510 /* remove from the old desktop(s) */
2511 focus_order_remove(self
);
2513 old
= self
->desktop
;
2514 self
->desktop
= target
;
2515 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, target
);
2516 /* the frame can display the current desktop state */
2517 frame_adjust_state(self
->frame
);
2518 /* 'move' the window to the new desktop */
2520 client_showhide(self
);
2521 /* raise if it was not already on the desktop */
2522 if (old
!= DESKTOP_ALL
)
2524 screen_update_areas();
2526 /* add to the new desktop(s) */
2527 if (config_focus_new
)
2528 focus_order_to_top(self
);
2530 focus_order_to_bottom(self
);
2533 /* move all transients */
2534 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
2535 if (it
->data
!= self
) client_set_desktop_recursive(it
->data
,
2539 void client_set_desktop(ObClient
*self
, guint target
, gboolean donthide
)
2541 client_set_desktop_recursive(client_search_top_transient(self
),
2545 ObClient
*client_search_modal_child(ObClient
*self
)
2550 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
2551 ObClient
*c
= it
->data
;
2552 if ((ret
= client_search_modal_child(c
))) return ret
;
2553 if (c
->modal
) return c
;
2558 gboolean
client_validate(ObClient
*self
)
2562 XSync(ob_display
, FALSE
); /* get all events on the server */
2564 if (XCheckTypedWindowEvent(ob_display
, self
->window
, DestroyNotify
, &e
) ||
2565 XCheckTypedWindowEvent(ob_display
, self
->window
, UnmapNotify
, &e
)) {
2566 XPutBackEvent(ob_display
, &e
);
2573 void client_set_wm_state(ObClient
*self
, glong state
)
2575 if (state
== self
->wmstate
) return; /* no change */
2579 client_iconify(self
, TRUE
, TRUE
);
2582 client_iconify(self
, FALSE
, TRUE
);
2587 void client_set_state(ObClient
*self
, Atom action
, glong data1
, glong data2
)
2589 gboolean shaded
= self
->shaded
;
2590 gboolean fullscreen
= self
->fullscreen
;
2591 gboolean undecorated
= self
->undecorated
;
2592 gboolean max_horz
= self
->max_horz
;
2593 gboolean max_vert
= self
->max_vert
;
2594 gboolean modal
= self
->modal
;
2595 gboolean iconic
= self
->iconic
;
2598 if (!(action
== prop_atoms
.net_wm_state_add
||
2599 action
== prop_atoms
.net_wm_state_remove
||
2600 action
== prop_atoms
.net_wm_state_toggle
))
2601 /* an invalid action was passed to the client message, ignore it */
2604 for (i
= 0; i
< 2; ++i
) {
2605 Atom state
= i
== 0 ? data1
: data2
;
2607 if (!state
) continue;
2609 /* if toggling, then pick whether we're adding or removing */
2610 if (action
== prop_atoms
.net_wm_state_toggle
) {
2611 if (state
== prop_atoms
.net_wm_state_modal
)
2612 action
= modal
? prop_atoms
.net_wm_state_remove
:
2613 prop_atoms
.net_wm_state_add
;
2614 else if (state
== prop_atoms
.net_wm_state_maximized_vert
)
2615 action
= self
->max_vert
? prop_atoms
.net_wm_state_remove
:
2616 prop_atoms
.net_wm_state_add
;
2617 else if (state
== prop_atoms
.net_wm_state_maximized_horz
)
2618 action
= self
->max_horz
? prop_atoms
.net_wm_state_remove
:
2619 prop_atoms
.net_wm_state_add
;
2620 else if (state
== prop_atoms
.net_wm_state_shaded
)
2621 action
= shaded
? prop_atoms
.net_wm_state_remove
:
2622 prop_atoms
.net_wm_state_add
;
2623 else if (state
== prop_atoms
.net_wm_state_skip_taskbar
)
2624 action
= self
->skip_taskbar
?
2625 prop_atoms
.net_wm_state_remove
:
2626 prop_atoms
.net_wm_state_add
;
2627 else if (state
== prop_atoms
.net_wm_state_skip_pager
)
2628 action
= self
->skip_pager
?
2629 prop_atoms
.net_wm_state_remove
:
2630 prop_atoms
.net_wm_state_add
;
2631 else if (state
== prop_atoms
.net_wm_state_hidden
)
2632 action
= self
->iconic
?
2633 prop_atoms
.net_wm_state_remove
:
2634 prop_atoms
.net_wm_state_add
;
2635 else if (state
== prop_atoms
.net_wm_state_fullscreen
)
2636 action
= fullscreen
?
2637 prop_atoms
.net_wm_state_remove
:
2638 prop_atoms
.net_wm_state_add
;
2639 else if (state
== prop_atoms
.net_wm_state_above
)
2640 action
= self
->above
? prop_atoms
.net_wm_state_remove
:
2641 prop_atoms
.net_wm_state_add
;
2642 else if (state
== prop_atoms
.net_wm_state_below
)
2643 action
= self
->below
? prop_atoms
.net_wm_state_remove
:
2644 prop_atoms
.net_wm_state_add
;
2645 else if (state
== prop_atoms
.ob_wm_state_undecorated
)
2646 action
= undecorated
? prop_atoms
.net_wm_state_remove
:
2647 prop_atoms
.net_wm_state_add
;
2650 if (action
== prop_atoms
.net_wm_state_add
) {
2651 if (state
== prop_atoms
.net_wm_state_modal
) {
2653 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
2655 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
2657 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
2659 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
2660 self
->skip_taskbar
= TRUE
;
2661 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
2662 self
->skip_pager
= TRUE
;
2663 } else if (state
== prop_atoms
.net_wm_state_hidden
) {
2665 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
2667 } else if (state
== prop_atoms
.net_wm_state_above
) {
2669 self
->below
= FALSE
;
2670 } else if (state
== prop_atoms
.net_wm_state_below
) {
2671 self
->above
= FALSE
;
2673 } else if (state
== prop_atoms
.ob_wm_state_undecorated
) {
2677 } else { /* action == prop_atoms.net_wm_state_remove */
2678 if (state
== prop_atoms
.net_wm_state_modal
) {
2680 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
2682 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
2684 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
2686 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
2687 self
->skip_taskbar
= FALSE
;
2688 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
2689 self
->skip_pager
= FALSE
;
2690 } else if (state
== prop_atoms
.net_wm_state_hidden
) {
2692 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
2694 } else if (state
== prop_atoms
.net_wm_state_above
) {
2695 self
->above
= FALSE
;
2696 } else if (state
== prop_atoms
.net_wm_state_below
) {
2697 self
->below
= FALSE
;
2698 } else if (state
== prop_atoms
.ob_wm_state_undecorated
) {
2699 undecorated
= FALSE
;
2703 if (max_horz
!= self
->max_horz
|| max_vert
!= self
->max_vert
) {
2704 if (max_horz
!= self
->max_horz
&& max_vert
!= self
->max_vert
) {
2706 if (max_horz
== max_vert
) { /* both going the same way */
2707 client_maximize(self
, max_horz
, 0, TRUE
);
2709 client_maximize(self
, max_horz
, 1, TRUE
);
2710 client_maximize(self
, max_vert
, 2, TRUE
);
2714 if (max_horz
!= self
->max_horz
)
2715 client_maximize(self
, max_horz
, 1, TRUE
);
2717 client_maximize(self
, max_vert
, 2, TRUE
);
2720 /* change fullscreen state before shading, as it will affect if the window
2722 if (fullscreen
!= self
->fullscreen
)
2723 client_fullscreen(self
, fullscreen
, TRUE
);
2724 if (shaded
!= self
->shaded
)
2725 client_shade(self
, shaded
);
2726 if (undecorated
!= self
->undecorated
)
2727 client_set_undecorated(self
, undecorated
);
2728 if (modal
!= self
->modal
) {
2729 self
->modal
= modal
;
2730 /* when a window changes modality, then its stacking order with its
2731 transients needs to change */
2734 if (iconic
!= self
->iconic
)
2735 client_iconify(self
, iconic
, FALSE
);
2737 client_calc_layer(self
);
2738 client_change_state(self
); /* change the hint to reflect these changes */
2741 ObClient
*client_focus_target(ObClient
*self
)
2745 /* if we have a modal child, then focus it, not us */
2746 child
= client_search_modal_child(client_search_top_transient(self
));
2747 if (child
) return child
;
2751 gboolean
client_can_focus(ObClient
*self
)
2755 /* choose the correct target */
2756 self
= client_focus_target(self
);
2758 if (!self
->frame
->visible
)
2761 if (!(self
->can_focus
|| self
->focus_notify
))
2764 /* do a check to see if the window has already been unmapped or destroyed
2765 do this intelligently while watching out for unmaps we've generated
2766 (ignore_unmaps > 0) */
2767 if (XCheckTypedWindowEvent(ob_display
, self
->window
,
2768 DestroyNotify
, &ev
)) {
2769 XPutBackEvent(ob_display
, &ev
);
2772 while (XCheckTypedWindowEvent(ob_display
, self
->window
,
2773 UnmapNotify
, &ev
)) {
2774 if (self
->ignore_unmaps
) {
2775 self
->ignore_unmaps
--;
2777 XPutBackEvent(ob_display
, &ev
);
2785 gboolean
client_focus(ObClient
*self
)
2787 /* choose the correct target */
2788 self
= client_focus_target(self
);
2790 if (!client_can_focus(self
)) {
2791 if (!self
->frame
->visible
) {
2792 /* update the focus lists */
2793 focus_order_to_top(self
);
2798 if (self
->can_focus
) {
2799 /* RevertToPointerRoot causes much more headache than RevertToNone, so
2800 I choose to use it always, hopefully to find errors quicker, if any
2801 are left. (I hate X. I hate focus events.)
2803 Update: Changing this to RevertToNone fixed a bug with mozilla (bug
2804 #799. So now it is RevertToNone again.
2806 XSetInputFocus(ob_display
, self
->window
, RevertToNone
,
2810 if (self
->focus_notify
) {
2812 ce
.xclient
.type
= ClientMessage
;
2813 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
2814 ce
.xclient
.display
= ob_display
;
2815 ce
.xclient
.window
= self
->window
;
2816 ce
.xclient
.format
= 32;
2817 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_take_focus
;
2818 ce
.xclient
.data
.l
[1] = event_lasttime
;
2819 ce
.xclient
.data
.l
[2] = 0l;
2820 ce
.xclient
.data
.l
[3] = 0l;
2821 ce
.xclient
.data
.l
[4] = 0l;
2822 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
2826 ob_debug("%sively focusing %lx at %d\n",
2827 (self
->can_focus
? "act" : "pass"),
2828 self
->window
, (gint
) event_lasttime
);
2831 /* Cause the FocusIn to come back to us. Important for desktop switches,
2832 since otherwise we'll have no FocusIn on the queue and send it off to
2833 the focus_backup. */
2834 XSync(ob_display
, FALSE
);
2838 /* Used when the current client is closed, focus_last will then prevent
2839 * focus from going to the mouse pointer */
2840 void client_unfocus(ObClient
*self
)
2842 if (focus_client
== self
) {
2844 ob_debug("client_unfocus for %lx\n", self
->window
);
2846 focus_fallback(OB_FOCUS_FALLBACK_CLOSED
);
2850 void client_activate(ObClient
*self
, gboolean here
)
2852 /* This check is for the client_list_menu trying to activate
2853 * a closed client. */
2854 if (!g_list_find(client_list
, self
)) return;
2855 if (client_normal(self
) && screen_showing_desktop
)
2856 screen_show_desktop(FALSE
);
2858 client_iconify(self
, FALSE
, here
);
2859 if (self
->desktop
!= DESKTOP_ALL
&&
2860 self
->desktop
!= screen_desktop
) {
2862 client_set_desktop(self
, screen_desktop
, FALSE
);
2864 screen_set_desktop(self
->desktop
);
2865 } else if (!self
->frame
->visible
)
2866 /* if its not visible for other reasons, then don't mess
2870 client_shade(self
, FALSE
);
2874 /* we do this an action here. this is rather important. this is because
2875 we want the results from the focus change to take place BEFORE we go
2876 about raising the window. when a fullscreen window loses focus, we need
2877 this or else the raise wont be able to raise above the to-lose-focus
2878 fullscreen window. */
2882 void client_raise(ObClient
*self
)
2884 action_run_string("Raise", self
);
2887 void client_lower(ObClient
*self
)
2889 action_run_string("Lower", self
);
2892 gboolean
client_focused(ObClient
*self
)
2894 return self
== focus_client
;
2897 static ObClientIcon
* client_icon_recursive(ObClient
*self
, gint w
, gint h
)
2900 /* si is the smallest image >= req */
2901 /* li is the largest image < req */
2902 gulong size
, smallest
= 0xffffffff, largest
= 0, si
= 0, li
= 0;
2904 if (!self
->nicons
) {
2905 ObClientIcon
*parent
= NULL
;
2907 if (self
->transient_for
) {
2908 if (self
->transient_for
!= OB_TRAN_GROUP
)
2909 parent
= client_icon_recursive(self
->transient_for
, w
, h
);
2912 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
2913 ObClient
*c
= it
->data
;
2914 if (c
!= self
&& !c
->transient_for
) {
2915 if ((parent
= client_icon_recursive(c
, w
, h
)))
2925 for (i
= 0; i
< self
->nicons
; ++i
) {
2926 size
= self
->icons
[i
].width
* self
->icons
[i
].height
;
2927 if (size
< smallest
&& size
>= (unsigned)(w
* h
)) {
2931 if (size
> largest
&& size
<= (unsigned)(w
* h
)) {
2936 if (largest
== 0) /* didnt find one smaller than the requested size */
2937 return &self
->icons
[si
];
2938 return &self
->icons
[li
];
2941 const ObClientIcon
* client_icon(ObClient
*self
, gint w
, gint h
)
2944 static ObClientIcon deficon
;
2946 if (!(ret
= client_icon_recursive(self
, w
, h
))) {
2947 deficon
.width
= deficon
.height
= 48;
2948 deficon
.data
= ob_rr_theme
->def_win_icon
;
2954 /* this be mostly ripped from fvwm */
2955 ObClient
*client_find_directional(ObClient
*c
, ObDirection dir
)
2957 gint my_cx
, my_cy
, his_cx
, his_cy
;
2960 gint score
, best_score
;
2961 ObClient
*best_client
, *cur
;
2967 /* first, find the centre coords of the currently focused window */
2968 my_cx
= c
->frame
->area
.x
+ c
->frame
->area
.width
/ 2;
2969 my_cy
= c
->frame
->area
.y
+ c
->frame
->area
.height
/ 2;
2974 for(it
= g_list_first(client_list
); it
; it
= g_list_next(it
)) {
2977 /* the currently selected window isn't interesting */
2980 if (!client_normal(cur
))
2982 /* using c->desktop instead of screen_desktop doesn't work if the
2983 * current window was omnipresent, hope this doesn't have any other
2985 if(screen_desktop
!= cur
->desktop
&& cur
->desktop
!= DESKTOP_ALL
)
2989 if(client_focus_target(cur
) == cur
&&
2990 !(cur
->can_focus
|| cur
->focus_notify
))
2993 /* find the centre coords of this window, from the
2994 * currently focused window's point of view */
2995 his_cx
= (cur
->frame
->area
.x
- my_cx
)
2996 + cur
->frame
->area
.width
/ 2;
2997 his_cy
= (cur
->frame
->area
.y
- my_cy
)
2998 + cur
->frame
->area
.height
/ 2;
3000 if(dir
== OB_DIRECTION_NORTHEAST
|| dir
== OB_DIRECTION_SOUTHEAST
||
3001 dir
== OB_DIRECTION_SOUTHWEST
|| dir
== OB_DIRECTION_NORTHWEST
) {
3003 /* Rotate the diagonals 45 degrees counterclockwise.
3004 * To do this, multiply the matrix /+h +h\ with the
3005 * vector (x y). \-h +h/
3006 * h = sqrt(0.5). We can set h := 1 since absolute
3007 * distance doesn't matter here. */
3008 tx
= his_cx
+ his_cy
;
3009 his_cy
= -his_cx
+ his_cy
;
3014 case OB_DIRECTION_NORTH
:
3015 case OB_DIRECTION_SOUTH
:
3016 case OB_DIRECTION_NORTHEAST
:
3017 case OB_DIRECTION_SOUTHWEST
:
3018 offset
= (his_cx
< 0) ? -his_cx
: his_cx
;
3019 distance
= ((dir
== OB_DIRECTION_NORTH
||
3020 dir
== OB_DIRECTION_NORTHEAST
) ?
3023 case OB_DIRECTION_EAST
:
3024 case OB_DIRECTION_WEST
:
3025 case OB_DIRECTION_SOUTHEAST
:
3026 case OB_DIRECTION_NORTHWEST
:
3027 offset
= (his_cy
< 0) ? -his_cy
: his_cy
;
3028 distance
= ((dir
== OB_DIRECTION_WEST
||
3029 dir
== OB_DIRECTION_NORTHWEST
) ?
3034 /* the target must be in the requested direction */
3038 /* Calculate score for this window. The smaller the better. */
3039 score
= distance
+ offset
;
3041 /* windows more than 45 degrees off the direction are
3042 * heavily penalized and will only be chosen if nothing
3043 * else within a million pixels */
3044 if(offset
> distance
)
3047 if(best_score
== -1 || score
< best_score
)
3055 void client_set_layer(ObClient
*self
, gint layer
)
3059 self
->above
= FALSE
;
3060 } else if (layer
== 0) {
3061 self
->below
= self
->above
= FALSE
;
3063 self
->below
= FALSE
;
3066 client_calc_layer(self
);
3067 client_change_state(self
); /* reflect this in the state hints */
3070 void client_set_undecorated(ObClient
*self
, gboolean undecorated
)
3072 if (self
->undecorated
!= undecorated
) {
3073 self
->undecorated
= undecorated
;
3074 client_setup_decor_and_functions(self
);
3075 /* Make sure the client knows it might have moved. Maybe there is a
3076 * better way of doing this so only one client_configure is sent, but
3077 * since 125 of these are sent per second when moving the window (with
3078 * user = FALSE) i doubt it matters much.
3080 client_configure(self
, OB_CORNER_TOPLEFT
, self
->area
.x
, self
->area
.y
,
3081 self
->area
.width
, self
->area
.height
, TRUE
, TRUE
);
3082 client_change_state(self
); /* reflect this in the state hints */
3086 /* Determines which physical monitor a client is on by calculating the
3087 area of the part of the client on each monitor. The number of the
3088 monitor containing the greatest area of the client is returned.*/
3089 guint
client_monitor(ObClient
*self
)
3095 for (i
= 0; i
< screen_num_monitors
; ++i
) {
3096 Rect
*area
= screen_physical_area_monitor(i
);
3097 if (RECT_INTERSECTS_RECT(*area
, self
->frame
->area
)) {
3101 RECT_SET_INTERSECTION(r
, *area
, self
->frame
->area
);
3102 v
= r
.width
* r
.height
;
3113 ObClient
*client_search_top_transient(ObClient
*self
)
3115 /* move up the transient chain as far as possible */
3116 if (self
->transient_for
) {
3117 if (self
->transient_for
!= OB_TRAN_GROUP
) {
3118 return client_search_top_transient(self
->transient_for
);
3122 g_assert(self
->group
);
3124 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
3125 ObClient
*c
= it
->data
;
3127 /* checking transient_for prevents infinate loops! */
3128 if (c
!= self
&& !c
->transient_for
)
3139 ObClient
*client_search_focus_parent(ObClient
*self
)
3141 if (self
->transient_for
) {
3142 if (self
->transient_for
!= OB_TRAN_GROUP
) {
3143 if (client_focused(self
->transient_for
))
3144 return self
->transient_for
;
3148 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
3149 ObClient
*c
= it
->data
;
3151 /* checking transient_for prevents infinate loops! */
3152 if (c
!= self
&& !c
->transient_for
)
3153 if (client_focused(c
))
3162 ObClient
*client_search_parent(ObClient
*self
, ObClient
*search
)
3164 if (self
->transient_for
) {
3165 if (self
->transient_for
!= OB_TRAN_GROUP
) {
3166 if (self
->transient_for
== search
)
3171 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
3172 ObClient
*c
= it
->data
;
3174 /* checking transient_for prevents infinate loops! */
3175 if (c
!= self
&& !c
->transient_for
)
3185 ObClient
*client_search_transient(ObClient
*self
, ObClient
*search
)
3189 for (sit
= self
->transients
; sit
; sit
= g_slist_next(sit
)) {
3190 if (sit
->data
== search
)
3192 if (client_search_transient(sit
->data
, search
))
3198 void client_update_sm_client_id(ObClient
*self
)
3200 g_free(self
->sm_client_id
);
3201 self
->sm_client_id
= NULL
;
3203 if (!PROP_GETS(self
->window
, sm_client_id
, locale
, &self
->sm_client_id
) &&
3205 PROP_GETS(self
->group
->leader
, sm_client_id
, locale
,
3206 &self
->sm_client_id
);
3209 /* finds the nearest edge in the given direction from the current client
3210 * note to self: the edge is the -frame- edge (the actual one), not the
3213 gint
client_directional_edge_search(ObClient
*c
, ObDirection dir
)
3215 gint dest
, monitor_dest
;
3216 gint my_edge_start
, my_edge_end
, my_offset
;
3223 a
= screen_area(c
->desktop
);
3224 monitor
= screen_area_monitor(c
->desktop
, client_monitor(c
));
3227 case OB_DIRECTION_NORTH
:
3228 my_edge_start
= c
->frame
->area
.x
;
3229 my_edge_end
= c
->frame
->area
.x
+ c
->frame
->area
.width
;
3230 my_offset
= c
->frame
->area
.y
;
3232 /* default: top of screen */
3234 monitor_dest
= monitor
->y
;
3235 /* if the monitor edge comes before the screen edge, */
3236 /* use that as the destination instead. (For xinerama) */
3237 if (monitor_dest
!= dest
&& my_offset
> monitor_dest
)
3238 dest
= monitor_dest
;
3240 for(it
= client_list
; it
&& my_offset
!= dest
; it
= g_list_next(it
)) {
3241 gint his_edge_start
, his_edge_end
, his_offset
;
3242 ObClient
*cur
= it
->data
;
3246 if(!client_normal(cur
))
3248 if(screen_desktop
!= cur
->desktop
&& cur
->desktop
!= DESKTOP_ALL
)
3252 if(cur
->layer
< c
->layer
&& !config_resist_layers_below
)
3255 his_edge_start
= cur
->frame
->area
.x
;
3256 his_edge_end
= cur
->frame
->area
.x
+ cur
->frame
->area
.width
;
3257 his_offset
= cur
->frame
->area
.y
+ cur
->frame
->area
.height
;
3259 if(his_offset
+ 1 > my_offset
)
3262 if(his_offset
< dest
)
3265 if(his_edge_start
>= my_edge_start
&&
3266 his_edge_start
<= my_edge_end
)
3269 if(my_edge_start
>= his_edge_start
&&
3270 my_edge_start
<= his_edge_end
)
3275 case OB_DIRECTION_SOUTH
:
3276 my_edge_start
= c
->frame
->area
.x
;
3277 my_edge_end
= c
->frame
->area
.x
+ c
->frame
->area
.width
;
3278 my_offset
= c
->frame
->area
.y
+ c
->frame
->area
.height
;
3280 /* default: bottom of screen */
3281 dest
= a
->y
+ a
->height
;
3282 monitor_dest
= monitor
->y
+ monitor
->height
;
3283 /* if the monitor edge comes before the screen edge, */
3284 /* use that as the destination instead. (For xinerama) */
3285 if (monitor_dest
!= dest
&& my_offset
< monitor_dest
)
3286 dest
= monitor_dest
;
3288 for(it
= client_list
; it
&& my_offset
!= dest
; it
= g_list_next(it
)) {
3289 gint his_edge_start
, his_edge_end
, his_offset
;
3290 ObClient
*cur
= it
->data
;
3294 if(!client_normal(cur
))
3296 if(screen_desktop
!= cur
->desktop
&& cur
->desktop
!= DESKTOP_ALL
)
3300 if(cur
->layer
< c
->layer
&& !config_resist_layers_below
)
3303 his_edge_start
= cur
->frame
->area
.x
;
3304 his_edge_end
= cur
->frame
->area
.x
+ cur
->frame
->area
.width
;
3305 his_offset
= cur
->frame
->area
.y
;
3308 if(his_offset
- 1 < my_offset
)
3311 if(his_offset
> dest
)
3314 if(his_edge_start
>= my_edge_start
&&
3315 his_edge_start
<= my_edge_end
)
3318 if(my_edge_start
>= his_edge_start
&&
3319 my_edge_start
<= his_edge_end
)
3324 case OB_DIRECTION_WEST
:
3325 my_edge_start
= c
->frame
->area
.y
;
3326 my_edge_end
= c
->frame
->area
.y
+ c
->frame
->area
.height
;
3327 my_offset
= c
->frame
->area
.x
;
3329 /* default: leftmost egde of screen */
3331 monitor_dest
= monitor
->x
;
3332 /* if the monitor edge comes before the screen edge, */
3333 /* use that as the destination instead. (For xinerama) */
3334 if (monitor_dest
!= dest
&& my_offset
> monitor_dest
)
3335 dest
= monitor_dest
;
3337 for(it
= client_list
; it
&& my_offset
!= dest
; it
= g_list_next(it
)) {
3338 gint his_edge_start
, his_edge_end
, his_offset
;
3339 ObClient
*cur
= it
->data
;
3343 if(!client_normal(cur
))
3345 if(screen_desktop
!= cur
->desktop
&& cur
->desktop
!= DESKTOP_ALL
)
3349 if(cur
->layer
< c
->layer
&& !config_resist_layers_below
)
3352 his_edge_start
= cur
->frame
->area
.y
;
3353 his_edge_end
= cur
->frame
->area
.y
+ cur
->frame
->area
.height
;
3354 his_offset
= cur
->frame
->area
.x
+ cur
->frame
->area
.width
;
3356 if(his_offset
+ 1 > my_offset
)
3359 if(his_offset
< dest
)
3362 if(his_edge_start
>= my_edge_start
&&
3363 his_edge_start
<= my_edge_end
)
3366 if(my_edge_start
>= his_edge_start
&&
3367 my_edge_start
<= his_edge_end
)
3373 case OB_DIRECTION_EAST
:
3374 my_edge_start
= c
->frame
->area
.y
;
3375 my_edge_end
= c
->frame
->area
.y
+ c
->frame
->area
.height
;
3376 my_offset
= c
->frame
->area
.x
+ c
->frame
->area
.width
;
3378 /* default: rightmost edge of screen */
3379 dest
= a
->x
+ a
->width
;
3380 monitor_dest
= monitor
->x
+ monitor
->width
;
3381 /* if the monitor edge comes before the screen edge, */
3382 /* use that as the destination instead. (For xinerama) */
3383 if (monitor_dest
!= dest
&& my_offset
< monitor_dest
)
3384 dest
= monitor_dest
;
3386 for(it
= client_list
; it
&& my_offset
!= dest
; it
= g_list_next(it
)) {
3387 gint his_edge_start
, his_edge_end
, his_offset
;
3388 ObClient
*cur
= it
->data
;
3392 if(!client_normal(cur
))
3394 if(screen_desktop
!= cur
->desktop
&& cur
->desktop
!= DESKTOP_ALL
)
3398 if(cur
->layer
< c
->layer
&& !config_resist_layers_below
)
3401 his_edge_start
= cur
->frame
->area
.y
;
3402 his_edge_end
= cur
->frame
->area
.y
+ cur
->frame
->area
.height
;
3403 his_offset
= cur
->frame
->area
.x
;
3405 if(his_offset
- 1 < my_offset
)
3408 if(his_offset
> dest
)
3411 if(his_edge_start
>= my_edge_start
&&
3412 his_edge_start
<= my_edge_end
)
3415 if(my_edge_start
>= his_edge_start
&&
3416 my_edge_start
<= his_edge_end
)
3421 case OB_DIRECTION_NORTHEAST
:
3422 case OB_DIRECTION_SOUTHEAST
:
3423 case OB_DIRECTION_NORTHWEST
:
3424 case OB_DIRECTION_SOUTHWEST
:
3425 /* not implemented */
3427 g_assert_not_reached();
3428 dest
= 0; /* suppress warning */
3433 ObClient
* client_under_pointer()
3437 ObClient
*ret
= NULL
;
3439 if (screen_pointer_pos(&x
, &y
)) {
3440 for (it
= stacking_list
; it
; it
= g_list_next(it
)) {
3441 if (WINDOW_IS_CLIENT(it
->data
)) {
3442 ObClient
*c
= WINDOW_AS_CLIENT(it
->data
);
3443 if (c
->frame
->visible
&&
3444 RECT_CONTAINS(c
->frame
->area
, x
, y
)) {
3454 gboolean
client_has_group_siblings(ObClient
*self
)
3456 return self
->group
&& self
->group
->members
->next
;