1 /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
3 client.c for the Openbox window manager
4 Copyright (c) 2006 Mikael Magnusson
5 Copyright (c) 2003 Ben Jansens
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 See the COPYING file for a copy of the GNU General Public License.
22 #include "startupnotify.h"
26 #include "moveresize.h"
29 #include "extensions.h"
39 #include "menuframe.h"
42 #include "render/render.h"
45 #include <X11/Xutil.h>
47 /*! The event mask to grab on client windows */
48 #define CLIENT_EVENTMASK (PropertyChangeMask | FocusChangeMask | \
51 #define CLIENT_NOPROPAGATEMASK (ButtonPressMask | ButtonReleaseMask | \
56 ObClientDestructor func
;
60 GList
*client_list
= NULL
;
62 static GSList
*client_destructors
= NULL
;
63 static Time client_last_user_time
= CurrentTime
;
65 static void client_get_all(ObClient
*self
);
66 static void client_toggle_border(ObClient
*self
, gboolean show
);
67 static void client_get_startup_id(ObClient
*self
);
68 static void client_get_area(ObClient
*self
);
69 static void client_get_desktop(ObClient
*self
);
70 static void client_get_state(ObClient
*self
);
71 static void client_get_layer(ObClient
*self
);
72 static void client_get_shaped(ObClient
*self
);
73 static void client_get_mwm_hints(ObClient
*self
);
74 static void client_get_gravity(ObClient
*self
);
75 static void client_showhide(ObClient
*self
);
76 static void client_change_allowed_actions(ObClient
*self
);
77 static void client_change_state(ObClient
*self
);
78 static void client_apply_startup_state(ObClient
*self
);
79 static void client_restore_session_state(ObClient
*self
);
80 static void client_restore_session_stacking(ObClient
*self
);
82 void client_startup(gboolean reconfig
)
89 void client_shutdown(gboolean reconfig
)
93 void client_add_destructor(ObClientDestructor func
, gpointer data
)
95 Destructor
*d
= g_new(Destructor
, 1);
98 client_destructors
= g_slist_prepend(client_destructors
, d
);
101 void client_remove_destructor(ObClientDestructor func
)
105 for (it
= client_destructors
; it
; it
= g_slist_next(it
)) {
106 Destructor
*d
= it
->data
;
107 if (d
->func
== func
) {
109 client_destructors
= g_slist_delete_link(client_destructors
, it
);
115 void client_set_list()
117 Window
*windows
, *win_it
;
119 guint size
= g_list_length(client_list
);
121 /* create an array of the window ids */
123 windows
= g_new(Window
, size
);
125 for (it
= client_list
; it
; it
= g_list_next(it
), ++win_it
)
126 *win_it
= ((ObClient
*)it
->data
)->window
;
130 PROP_SETA32(RootWindow(ob_display
, ob_screen
),
131 net_client_list
, window
, (gulong
*)windows
, size
);
140 void client_foreach_transient(ObClient *self, ObClientForeachFunc func, gpointer data)
144 for (it = self->transients; it; it = g_slist_next(it)) {
145 if (!func(it->data, data)) return;
146 client_foreach_transient(it->data, func, data);
150 void client_foreach_ancestor(ObClient *self, ObClientForeachFunc func, gpointer data)
152 if (self->transient_for) {
153 if (self->transient_for != OB_TRAN_GROUP) {
154 if (!func(self->transient_for, data)) return;
155 client_foreach_ancestor(self->transient_for, func, data);
159 for (it = self->group->members; it; it = g_slist_next(it))
160 if (it->data != self &&
161 !((ObClient*)it->data)->transient_for) {
162 if (!func(it->data, data)) return;
163 client_foreach_ancestor(it->data, func, data);
170 void client_manage_all()
175 XWindowAttributes attrib
;
177 XQueryTree(ob_display
, RootWindow(ob_display
, ob_screen
),
178 &w
, &w
, &children
, &nchild
);
180 /* remove all icon windows from the list */
181 for (i
= 0; i
< nchild
; i
++) {
182 if (children
[i
] == None
) continue;
183 wmhints
= XGetWMHints(ob_display
, children
[i
]);
185 if ((wmhints
->flags
& IconWindowHint
) &&
186 (wmhints
->icon_window
!= children
[i
]))
187 for (j
= 0; j
< nchild
; j
++)
188 if (children
[j
] == wmhints
->icon_window
) {
196 for (i
= 0; i
< nchild
; ++i
) {
197 if (children
[i
] == None
)
199 if (XGetWindowAttributes(ob_display
, children
[i
], &attrib
)) {
200 if (attrib
.override_redirect
) continue;
202 if (attrib
.map_state
!= IsUnmapped
)
203 client_manage(children
[i
]);
209 static ObAppSettings
*get_settings(ObClient
*client
)
211 GSList
*a
= config_per_app_settings
;
214 ObAppSettings
*app
= (ObAppSettings
*) a
->data
;
217 (app
->name
&& !app
->class && !strcmp(app
->name
, client
->name
))
218 || (app
->class && !app
->name
&& !strcmp(app
->class, client
->class))
219 || (app
->class && app
->name
&& !strcmp(app
->class, client
->class)
220 && !strcmp(app
->name
, client
->name
))
222 ob_debug("Window matching: %s\n", app
->name
);
223 /* Match if no role was specified in the per app setting, or if the
224 * string matches the beginning of the role, since apps like to set
225 * the role to things like browser-window-23c4b2f */
227 || !strncmp(app
->role
, client
->role
, strlen(app
->role
)))
236 void client_manage(Window window
)
240 XWindowAttributes attrib
;
241 XSetWindowAttributes attrib_set
;
243 gboolean activate
= FALSE
;
244 ObAppSettings
*settings
;
248 /* check if it has already been unmapped by the time we started mapping
249 the grab does a sync so we don't have to here */
250 if (XCheckTypedWindowEvent(ob_display
, window
, DestroyNotify
, &e
) ||
251 XCheckTypedWindowEvent(ob_display
, window
, UnmapNotify
, &e
))
253 XPutBackEvent(ob_display
, &e
);
256 return; /* don't manage it */
259 /* make sure it isn't an override-redirect window */
260 if (!XGetWindowAttributes(ob_display
, window
, &attrib
) ||
261 attrib
.override_redirect
)
264 return; /* don't manage it */
267 /* is the window a docking app */
268 if ((wmhint
= XGetWMHints(ob_display
, window
))) {
269 if ((wmhint
->flags
& StateHint
) &&
270 wmhint
->initial_state
== WithdrawnState
)
272 dock_add(window
, wmhint
);
280 ob_debug("Managing window: %lx\n", window
);
282 /* choose the events we want to receive on the CLIENT window */
283 attrib_set
.event_mask
= CLIENT_EVENTMASK
;
284 attrib_set
.do_not_propagate_mask
= CLIENT_NOPROPAGATEMASK
;
285 XChangeWindowAttributes(ob_display
, window
,
286 CWEventMask
|CWDontPropagate
, &attrib_set
);
289 /* create the ObClient struct, and populate it from the hints on the
291 self
= g_new0(ObClient
, 1);
292 self
->obwin
.type
= Window_Client
;
293 self
->window
= window
;
295 /* non-zero defaults */
296 self
->title_count
= 1;
297 self
->wmstate
= NormalState
;
299 self
->desktop
= screen_num_desktops
; /* always an invalid value */
300 self
->user_time
= ~0; /* maximum value, always newer than the real time */
302 client_get_all(self
);
303 client_restore_session_state(self
);
305 client_calc_layer(self
);
308 Time t
= sn_app_started(self
->startup_id
, self
->class);
309 if (t
) self
->user_time
= t
;
312 /* update the focus lists, do this before the call to change_state or
313 it can end up in the list twice! */
314 focus_order_add_new(self
);
316 client_change_state(self
);
318 /* remove the client's border (and adjust re gravity) */
319 client_toggle_border(self
, FALSE
);
321 /* specify that if we exit, the window should not be destroyed and should
322 be reparented back to root automatically */
323 XChangeSaveSet(ob_display
, window
, SetModeInsert
);
325 /* create the decoration frame for the client window */
326 self
->frame
= frame_new(self
);
328 frame_grab_client(self
->frame
, self
);
332 client_apply_startup_state(self
);
334 /* get and set application level settings */
335 settings
= get_settings(self
);
337 stacking_add_nonintrusive(CLIENT_AS_WINDOW(self
));
338 client_restore_session_stacking(self
);
341 /* Don't worry, we won't actually both shade and undecorate the
342 * window when push comes to shove. */
343 if (settings
->shade
!= -1)
344 client_shade(self
, !!settings
->shade
);
345 if (settings
->decor
!= -1)
346 client_set_undecorated(self
, !settings
->decor
);
347 if (settings
->iconic
!= -1)
348 client_iconify(self
, !!settings
->iconic
, FALSE
);
349 if (settings
->skip_pager
!= -1) {
350 self
->skip_pager
= !!settings
->skip_pager
;
351 client_change_state(self
);
353 if (settings
->skip_taskbar
!= -1) {
354 self
->skip_taskbar
= !!settings
->skip_taskbar
;
355 client_change_state(self
);
358 /* 1 && -1 shouldn't be possible by the code in config.c */
359 if (settings
->max_vert
== 1 && settings
->max_horz
== 1)
360 client_maximize(self
, TRUE
, 0, TRUE
);
361 else if (settings
->max_vert
== 0 && settings
->max_horz
== 0)
362 client_maximize(self
, FALSE
, 0, TRUE
);
363 else if (settings
->max_vert
== 1 && settings
->max_horz
== 0) {
364 client_maximize(self
, TRUE
, 2, TRUE
);
365 client_maximize(self
, FALSE
, 1, TRUE
);
366 } else if (settings
->max_vert
== 0 && settings
->max_horz
== 1) {
367 client_maximize(self
, TRUE
, 1, TRUE
);
368 client_maximize(self
, FALSE
, 2, TRUE
);
371 if (settings
->fullscreen
!= -1)
372 client_fullscreen(self
, !!settings
->fullscreen
, TRUE
);
374 if (settings
->desktop
< screen_num_desktops
375 || settings
->desktop
== DESKTOP_ALL
)
376 client_set_desktop(self
, settings
->desktop
, TRUE
);
378 if (settings
->layer
> -2 && settings
->layer
< 2)
379 client_set_layer(self
, settings
->layer
);
383 /* focus the new window? */
384 if (ob_state() != OB_STATE_STARTING
&&
385 /* this means focus=true for window is same as config_focus_new=true */
386 ((config_focus_new
|| (settings
&& settings
->focus
== 1)) ||
387 client_search_focus_parent(self
)) &&
388 /* this checks for focus=false for the window */
389 (!settings
|| settings
->focus
!= 0) &&
390 /* note the check against Type_Normal/Dialog, not client_normal(self),
391 which would also include other types. in this case we want more
392 strict rules for focus */
393 (self
->type
== OB_CLIENT_TYPE_NORMAL
||
394 self
->type
== OB_CLIENT_TYPE_DIALOG
))
398 if (self
->desktop
!= screen_desktop
) {
399 /* activate the window */
402 gboolean group_foc
= FALSE
;
407 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
))
409 if (client_focused(it
->data
))
417 (!self
->transient_for
&& (!self
->group
||
418 !self
->group
->members
->next
))) ||
419 client_search_focus_tree_full(self
) ||
421 !client_normal(focus_client
))
423 /* activate the window */
430 if (ob_state() == OB_STATE_RUNNING
) {
431 gint x
= self
->area
.x
, ox
= x
;
432 gint y
= self
->area
.y
, oy
= y
;
435 transient
= place_client(self
, &x
, &y
, settings
);
437 /* make sure the window is visible. */
438 client_find_onscreen(self
, &x
, &y
,
439 self
->frame
->area
.width
,
440 self
->frame
->area
.height
,
441 /* non-normal clients has less rules, and
442 windows that are being restored from a
443 session do also. we can assume you want
444 it back where you saved it. Clients saying
445 they placed themselves are subjected to
446 harder rules, ones that are placed by
447 place.c or by the user are allowed partially
448 off-screen and on xinerama divides (ie,
449 it is up to the placement routines to avoid
450 the xinerama divides) */
452 (((self
->positioned
& PPosition
) &&
453 !(self
->positioned
& USPosition
)) &&
454 client_normal(self
) &&
456 if (x
!= ox
|| y
!= oy
)
457 client_move(self
, x
, y
);
460 keyboard_grab_for_client(self
, TRUE
);
461 mouse_grab_for_client(self
, TRUE
);
464 /* This is focus stealing prevention */
465 ob_debug("Want to focus new window 0x%x with time %u (last time %u)\n",
466 self
->window
, self
->user_time
, client_last_user_time
);
468 /* If a nothing at all, or a parent was focused, then focus this
471 if (!focus_client
|| client_search_focus_parent(self
) != NULL
)
475 /* If time stamp is old, don't steal focus */
476 if (self
->user_time
&& self
->user_time
< client_last_user_time
)
478 /* Don't steal focus from globally active clients.
479 I stole this idea from KWin. It seems nice.
481 if (!focus_client
->can_focus
&& focus_client
->focus_notify
)
487 /* since focus can change the stacking orders, if we focus the
488 window then the standard raise it gets is not enough, we need
489 to queue one for after the focus change takes place */
492 ob_debug("Focus stealing prevention activated for %s with time %u "
494 self
->title
, self
->user_time
, client_last_user_time
);
495 /* if the client isn't focused, then hilite it so the user
497 client_hilite(self
, TRUE
);
501 /* This may look rather odd. Well it's because new windows are added
502 to the stacking order non-intrusively. If we're not going to focus
503 the new window or hilite it, then we raise it to the top. This will
504 take affect for things that don't get focused like splash screens.
505 Also if you don't have focus_new enabled, then it's going to get
506 raised to the top. Legacy begets legacy I guess?
511 /* this has to happen before we try focus the window, but we want it to
512 happen after the client's stacking has been determined or it looks bad
514 client_showhide(self
);
516 /* use client_focus instead of client_activate cuz client_activate does
517 stuff like switch desktops etc and I'm not interested in all that when
518 a window maps since its not based on an action from the user like
519 clicking a window to activate it. so keep the new window out of the way
522 /* if using focus_delay, stop the timer now so that focus doesn't
524 event_halt_focus_delay();
528 /* client_activate does this but we aret using it so we have to do it
530 if (screen_showing_desktop
)
531 screen_show_desktop(FALSE
);
533 /* add to client list/map */
534 client_list
= g_list_append(client_list
, self
);
535 g_hash_table_insert(window_map
, &self
->window
, self
);
537 /* this has to happen after we're in the client_list */
538 if (STRUT_EXISTS(self
->strut
))
539 screen_update_areas();
541 /* update the list hints */
544 ob_debug("Managed window 0x%lx (%s)\n", window
, self
->class);
547 void client_unmanage_all()
549 while (client_list
!= NULL
)
550 client_unmanage(client_list
->data
);
553 void client_unmanage(ObClient
*self
)
558 ob_debug("Unmanaging window: %lx (%s)\n", self
->window
, self
->class);
560 g_assert(self
!= NULL
);
562 keyboard_grab_for_client(self
, FALSE
);
563 mouse_grab_for_client(self
, FALSE
);
565 /* potentially fix focusLast */
566 if (config_focus_last
)
567 grab_pointer(TRUE
, OB_CURSOR_NONE
);
569 /* remove the window from our save set */
570 XChangeSaveSet(ob_display
, self
->window
, SetModeDelete
);
572 /* we dont want events no more */
573 XSelectInput(ob_display
, self
->window
, NoEventMask
);
575 frame_hide(self
->frame
);
577 client_list
= g_list_remove(client_list
, self
);
578 stacking_remove(self
);
579 g_hash_table_remove(window_map
, &self
->window
);
581 /* update the focus lists */
582 focus_order_remove(self
);
584 /* once the client is out of the list, update the struts to remove it's
586 if (STRUT_EXISTS(self
->strut
))
587 screen_update_areas();
589 for (it
= client_destructors
; it
; it
= g_slist_next(it
)) {
590 Destructor
*d
= it
->data
;
591 d
->func(self
, d
->data
);
594 if (focus_client
== self
) {
597 /* focus the last focused window on the desktop, and ignore enter
598 events from the unmap so it doesnt mess with the focus */
599 while (XCheckTypedEvent(ob_display
, EnterNotify
, &e
));
600 /* remove these flags so we don't end up getting focused in the
602 self
->can_focus
= FALSE
;
603 self
->focus_notify
= FALSE
;
605 client_unfocus(self
);
608 /* tell our parent(s) that we're gone */
609 if (self
->transient_for
== OB_TRAN_GROUP
) { /* transient of group */
610 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
))
611 if (it
->data
!= self
)
612 ((ObClient
*)it
->data
)->transients
=
613 g_slist_remove(((ObClient
*)it
->data
)->transients
, self
);
614 } else if (self
->transient_for
) { /* transient of window */
615 self
->transient_for
->transients
=
616 g_slist_remove(self
->transient_for
->transients
, self
);
619 /* tell our transients that we're gone */
620 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
621 if (((ObClient
*)it
->data
)->transient_for
!= OB_TRAN_GROUP
) {
622 ((ObClient
*)it
->data
)->transient_for
= NULL
;
623 client_calc_layer(it
->data
);
627 /* remove from its group */
629 group_remove(self
->group
, self
);
633 /* give the client its border back */
634 client_toggle_border(self
, TRUE
);
636 /* reparent the window out of the frame, and free the frame */
637 frame_release_client(self
->frame
, self
);
640 if (ob_state() != OB_STATE_EXITING
) {
641 /* these values should not be persisted across a window
643 PROP_ERASE(self
->window
, net_wm_desktop
);
644 PROP_ERASE(self
->window
, net_wm_state
);
645 PROP_ERASE(self
->window
, wm_state
);
647 /* if we're left in an unmapped state, the client wont be mapped. this
648 is bad, since we will no longer be managing the window on restart */
649 XMapWindow(ob_display
, self
->window
);
653 ob_debug("Unmanaged window 0x%lx\n", self
->window
);
655 /* free all data allocated in the client struct */
656 g_slist_free(self
->transients
);
657 for (j
= 0; j
< self
->nicons
; ++j
)
658 g_free(self
->icons
[j
].data
);
659 if (self
->nicons
> 0)
662 g_free(self
->icon_title
);
666 g_free(self
->sm_client_id
);
669 /* update the list hints */
672 if (config_focus_last
)
673 grab_pointer(FALSE
, OB_CURSOR_NONE
);
676 static void client_restore_session_state(ObClient
*self
)
680 if (!(it
= session_state_find(self
)))
683 self
->session
= it
->data
;
685 RECT_SET_POINT(self
->area
, self
->session
->x
, self
->session
->y
);
686 self
->positioned
= PPosition
;
687 if (self
->session
->w
> 0)
688 self
->area
.width
= self
->session
->w
;
689 if (self
->session
->h
> 0)
690 self
->area
.height
= self
->session
->h
;
691 XResizeWindow(ob_display
, self
->window
,
692 self
->area
.width
, self
->area
.height
);
694 self
->desktop
= (self
->session
->desktop
== DESKTOP_ALL
?
695 self
->session
->desktop
:
696 MIN(screen_num_desktops
- 1, self
->session
->desktop
));
697 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, self
->desktop
);
699 self
->shaded
= self
->session
->shaded
;
700 self
->iconic
= self
->session
->iconic
;
701 self
->skip_pager
= self
->session
->skip_pager
;
702 self
->skip_taskbar
= self
->session
->skip_taskbar
;
703 self
->fullscreen
= self
->session
->fullscreen
;
704 self
->above
= self
->session
->above
;
705 self
->below
= self
->session
->below
;
706 self
->max_horz
= self
->session
->max_horz
;
707 self
->max_vert
= self
->session
->max_vert
;
710 static void client_restore_session_stacking(ObClient
*self
)
714 if (!self
->session
) return;
716 it
= g_list_find(session_saved_state
, self
->session
);
717 for (it
= g_list_previous(it
); it
; it
= g_list_previous(it
)) {
720 for (cit
= client_list
; cit
; cit
= g_list_next(cit
))
721 if (session_state_cmp(it
->data
, cit
->data
))
724 client_calc_layer(self
);
725 stacking_below(CLIENT_AS_WINDOW(self
),
726 CLIENT_AS_WINDOW(cit
->data
));
732 void client_move_onscreen(ObClient
*self
, gboolean rude
)
734 gint x
= self
->area
.x
;
735 gint y
= self
->area
.y
;
736 if (client_find_onscreen(self
, &x
, &y
,
737 self
->frame
->area
.width
,
738 self
->frame
->area
.height
, rude
)) {
739 client_move(self
, x
, y
);
743 gboolean
client_find_onscreen(ObClient
*self
, gint
*x
, gint
*y
, gint w
, gint h
,
747 gint ox
= *x
, oy
= *y
;
749 frame_client_gravity(self
->frame
, x
, y
); /* get where the frame
752 /* XXX watch for xinerama dead areas */
753 /* This makes sure windows aren't entirely outside of the screen so you
754 can't see them at all.
755 It makes sure 10% of the window is on the screen at least. At don't let
756 it move itself off the top of the screen, which would hide the titlebar
757 on you. (The user can still do this if they want too, it's only limiting
760 if (client_normal(self
)) {
761 a
= screen_area(self
->desktop
);
762 if (!self
->strut
.right
&&
763 *x
+ self
->frame
->area
.width
/10 >= a
->x
+ a
->width
- 1)
764 *x
= a
->x
+ a
->width
- self
->frame
->area
.width
/10;
765 if (!self
->strut
.bottom
&&
766 *y
+ self
->frame
->area
.height
/10 >= a
->y
+ a
->height
- 1)
767 *y
= a
->y
+ a
->height
- self
->frame
->area
.height
/10;
768 if (!self
->strut
.left
&& *x
+ self
->frame
->area
.width
*9/10 - 1 < a
->x
)
769 *x
= a
->x
- self
->frame
->area
.width
*9/10;
770 if (!self
->strut
.top
&& *y
+ self
->frame
->area
.height
*9/10 - 1 < a
->y
)
771 *y
= a
->y
- self
->frame
->area
.width
*9/10;
774 /* This here doesn't let windows even a pixel outside the screen,
775 * when called from client_manage, programs placing themselves are
776 * forced completely onscreen, while things like
777 * xterm -geometry resolution-width/2 will work fine. Trying to
778 * place it completely offscreen will be handled in the above code.
779 * Sorry for this confused comment, i am tired. */
781 /* avoid the xinerama monitor divide while we're at it,
782 * remember to fix the placement stuff to avoid it also and
783 * then remove this XXX */
784 a
= screen_area_monitor(self
->desktop
, client_monitor(self
));
785 /* dont let windows map into the strut unless they
786 are bigger than the available area */
788 if (!self
->strut
.left
&& *x
< a
->x
) *x
= a
->x
;
789 if (!self
->strut
.right
&& *x
+ w
> a
->x
+ a
->width
)
790 *x
= a
->x
+ a
->width
- w
;
792 if (h
<= a
->height
) {
793 if (!self
->strut
.top
&& *y
< a
->y
) *y
= a
->y
;
794 if (!self
->strut
.bottom
&& *y
+ h
> a
->y
+ a
->height
)
795 *y
= a
->y
+ a
->height
- h
;
799 frame_frame_gravity(self
->frame
, x
, y
); /* get where the client
802 return ox
!= *x
|| oy
!= *y
;
805 static void client_toggle_border(ObClient
*self
, gboolean show
)
807 /* adjust our idea of where the client is, based on its border. When the
808 border is removed, the client should now be considered to be in a
810 when re-adding the border to the client, the same operation needs to be
812 gint oldx
= self
->area
.x
, oldy
= self
->area
.y
;
813 gint x
= oldx
, y
= oldy
;
814 switch(self
->gravity
) {
816 case NorthWestGravity
:
818 case SouthWestGravity
:
820 case NorthEastGravity
:
822 case SouthEastGravity
:
823 if (show
) x
-= self
->border_width
* 2;
824 else x
+= self
->border_width
* 2;
831 if (show
) x
-= self
->border_width
;
832 else x
+= self
->border_width
;
835 switch(self
->gravity
) {
837 case NorthWestGravity
:
839 case NorthEastGravity
:
841 case SouthWestGravity
:
843 case SouthEastGravity
:
844 if (show
) y
-= self
->border_width
* 2;
845 else y
+= self
->border_width
* 2;
852 if (show
) y
-= self
->border_width
;
853 else y
+= self
->border_width
;
860 XSetWindowBorderWidth(ob_display
, self
->window
, self
->border_width
);
862 /* move the client so it is back it the right spot _with_ its
864 if (x
!= oldx
|| y
!= oldy
)
865 XMoveWindow(ob_display
, self
->window
, x
, y
);
867 XSetWindowBorderWidth(ob_display
, self
->window
, 0);
871 static void client_get_all(ObClient
*self
)
873 client_get_area(self
);
874 client_get_mwm_hints(self
);
876 /* The transient hint is used to pick a type, but the type can also affect
877 transiency (dialogs are always made transients of their group if they
878 have one). This is Havoc's idea, but it is needed to make some apps
879 work right (eg tsclient). */
880 client_update_transient_for(self
);
881 client_get_type(self
);/* this can change the mwmhints for special cases */
882 client_get_state(self
);
883 client_update_transient_for(self
);
885 client_update_wmhints(self
);
886 client_get_startup_id(self
);
887 client_get_desktop(self
);/* uses transient data/group/startup id if a
888 desktop is not specified */
889 client_get_shaped(self
);
891 client_get_layer(self
); /* if layer hasn't been specified, get it from
892 other sources if possible */
895 /* a couple type-based defaults for new windows */
897 /* this makes sure that these windows appear on all desktops */
898 if (self
->type
== OB_CLIENT_TYPE_DESKTOP
)
899 self
->desktop
= DESKTOP_ALL
;
902 client_update_protocols(self
);
904 client_get_gravity(self
); /* get the attribute gravity */
905 client_update_normal_hints(self
); /* this may override the attribute
908 /* got the type, the mwmhints, the protocols, and the normal hints
909 (min/max sizes), so we're ready to set up the decorations/functions */
910 client_setup_decor_and_functions(self
);
912 client_update_title(self
);
913 client_update_class(self
);
914 client_update_sm_client_id(self
);
915 client_update_strut(self
);
916 client_update_icons(self
);
917 client_update_user_time(self
, FALSE
);
920 static void client_get_startup_id(ObClient
*self
)
922 if (!(PROP_GETS(self
->window
, net_startup_id
, utf8
, &self
->startup_id
)))
924 PROP_GETS(self
->group
->leader
,
925 net_startup_id
, utf8
, &self
->startup_id
);
928 static void client_get_area(ObClient
*self
)
930 XWindowAttributes wattrib
;
933 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
934 g_assert(ret
!= BadWindow
);
936 RECT_SET(self
->area
, wattrib
.x
, wattrib
.y
, wattrib
.width
, wattrib
.height
);
937 self
->border_width
= wattrib
.border_width
;
940 static void client_get_desktop(ObClient
*self
)
942 guint32 d
= screen_num_desktops
; /* an always-invalid value */
944 if (PROP_GET32(self
->window
, net_wm_desktop
, cardinal
, &d
)) {
945 if (d
>= screen_num_desktops
&& d
!= DESKTOP_ALL
)
946 self
->desktop
= screen_num_desktops
- 1;
950 gboolean trdesk
= FALSE
;
952 if (self
->transient_for
) {
953 if (self
->transient_for
!= OB_TRAN_GROUP
) {
954 self
->desktop
= self
->transient_for
->desktop
;
959 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
))
960 if (it
->data
!= self
&&
961 !((ObClient
*)it
->data
)->transient_for
) {
962 self
->desktop
= ((ObClient
*)it
->data
)->desktop
;
969 /* try get from the startup-notification protocol */
970 if (sn_get_desktop(self
->startup_id
, &self
->desktop
)) {
971 if (self
->desktop
>= screen_num_desktops
&&
972 self
->desktop
!= DESKTOP_ALL
)
973 self
->desktop
= screen_num_desktops
- 1;
975 /* defaults to the current desktop */
976 self
->desktop
= screen_desktop
;
979 if (self
->desktop
!= d
) {
980 /* set the desktop hint, to make sure that it always exists */
981 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, self
->desktop
);
985 static void client_get_layer(ObClient
*self
)
987 if (!(self
->above
|| self
->below
)) {
989 /* apply stuff from the group */
993 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
994 ObClient
*c
= it
->data
;
995 if (c
!= self
&& !client_search_transient(self
, c
) &&
996 client_normal(self
) && client_normal(c
))
999 (c
->above
? 1 : (c
->below
? -1 : 0)));
1013 g_assert_not_reached();
1020 static void client_get_state(ObClient
*self
)
1025 if (PROP_GETA32(self
->window
, net_wm_state
, atom
, &state
, &num
)) {
1027 for (i
= 0; i
< num
; ++i
) {
1028 if (state
[i
] == prop_atoms
.net_wm_state_modal
)
1030 else if (state
[i
] == prop_atoms
.net_wm_state_shaded
)
1031 self
->shaded
= TRUE
;
1032 else if (state
[i
] == prop_atoms
.net_wm_state_hidden
)
1033 self
->iconic
= TRUE
;
1034 else if (state
[i
] == prop_atoms
.net_wm_state_skip_taskbar
)
1035 self
->skip_taskbar
= TRUE
;
1036 else if (state
[i
] == prop_atoms
.net_wm_state_skip_pager
)
1037 self
->skip_pager
= TRUE
;
1038 else if (state
[i
] == prop_atoms
.net_wm_state_fullscreen
)
1039 self
->fullscreen
= TRUE
;
1040 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_vert
)
1041 self
->max_vert
= TRUE
;
1042 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_horz
)
1043 self
->max_horz
= TRUE
;
1044 else if (state
[i
] == prop_atoms
.net_wm_state_above
)
1046 else if (state
[i
] == prop_atoms
.net_wm_state_below
)
1048 else if (state
[i
] == prop_atoms
.net_wm_state_demands_attention
)
1049 self
->demands_attention
= TRUE
;
1050 else if (state
[i
] == prop_atoms
.ob_wm_state_undecorated
)
1051 self
->undecorated
= TRUE
;
1058 static void client_get_shaped(ObClient
*self
)
1060 self
->shaped
= FALSE
;
1062 if (extensions_shape
) {
1067 XShapeSelectInput(ob_display
, self
->window
, ShapeNotifyMask
);
1069 XShapeQueryExtents(ob_display
, self
->window
, &s
, &foo
,
1070 &foo
, &ufoo
, &ufoo
, &foo
, &foo
, &foo
, &ufoo
,
1072 self
->shaped
= (s
!= 0);
1077 void client_update_transient_for(ObClient
*self
)
1080 ObClient
*target
= NULL
;
1082 if (XGetTransientForHint(ob_display
, self
->window
, &t
)) {
1083 self
->transient
= TRUE
;
1084 if (t
!= self
->window
) { /* cant be transient to itself! */
1085 target
= g_hash_table_lookup(window_map
, &t
);
1086 /* if this happens then we need to check for it*/
1087 g_assert(target
!= self
);
1088 if (target
&& !WINDOW_IS_CLIENT(target
)) {
1089 /* this can happen when a dialog is a child of
1090 a dockapp, for example */
1094 /* THIS IS SO ANNOYING ! ! ! ! Let me explain.... have a seat..
1096 Setting the transient_for to Root is actually illegal, however
1097 applications from time have done this to specify transient for
1100 Now you can do that by being a TYPE_DIALOG and not setting
1101 the transient_for hint at all on your window. But people still
1102 use Root, and Kwin is very strange in this regard.
1104 KWin 3.0 will not consider windows with transient_for set to
1105 Root as transient for their group *UNLESS* they are also modal.
1106 In that case, it will make them transient for the group. This
1107 leads to all sorts of weird behavior from KDE apps which are
1108 only tested in KWin. I'd like to follow their behavior just to
1109 make this work right with KDE stuff, but that seems wrong.
1111 if (!target
&& self
->group
) {
1112 /* not transient to a client, see if it is transient for a
1114 if (t
== RootWindow(ob_display
, ob_screen
)) {
1115 /* window is a transient for its group! */
1116 target
= OB_TRAN_GROUP
;
1120 } else if (self
->type
== OB_CLIENT_TYPE_DIALOG
&& self
->group
) {
1121 self
->transient
= TRUE
;
1122 target
= OB_TRAN_GROUP
;
1124 self
->transient
= FALSE
;
1126 /* if anything has changed... */
1127 if (target
!= self
->transient_for
) {
1128 if (self
->transient_for
== OB_TRAN_GROUP
) { /* transient of group */
1131 /* remove from old parents */
1132 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
1133 ObClient
*c
= it
->data
;
1134 if (c
!= self
&& !c
->transient_for
)
1135 c
->transients
= g_slist_remove(c
->transients
, self
);
1137 } else if (self
->transient_for
!= NULL
) { /* transient of window */
1138 /* remove from old parent */
1139 self
->transient_for
->transients
=
1140 g_slist_remove(self
->transient_for
->transients
, self
);
1142 self
->transient_for
= target
;
1143 if (self
->transient_for
== OB_TRAN_GROUP
) { /* transient of group */
1146 /* add to new parents */
1147 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
1148 ObClient
*c
= it
->data
;
1149 if (c
!= self
&& !c
->transient_for
)
1150 c
->transients
= g_slist_append(c
->transients
, self
);
1153 /* remove all transients which are in the group, that causes
1154 circlular pointer hell of doom */
1155 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
1157 for (sit
= self
->transients
; sit
; sit
= next
) {
1158 next
= g_slist_next(sit
);
1159 if (sit
->data
== it
->data
)
1161 g_slist_delete_link(self
->transients
, sit
);
1164 } else if (self
->transient_for
!= NULL
) { /* transient of window */
1165 /* add to new parent */
1166 self
->transient_for
->transients
=
1167 g_slist_append(self
->transient_for
->transients
, self
);
1172 static void client_get_mwm_hints(ObClient
*self
)
1177 self
->mwmhints
.flags
= 0; /* default to none */
1179 if (PROP_GETA32(self
->window
, motif_wm_hints
, motif_wm_hints
,
1181 if (num
>= OB_MWM_ELEMENTS
) {
1182 self
->mwmhints
.flags
= hints
[0];
1183 self
->mwmhints
.functions
= hints
[1];
1184 self
->mwmhints
.decorations
= hints
[2];
1190 void client_get_type(ObClient
*self
)
1197 if (PROP_GETA32(self
->window
, net_wm_window_type
, atom
, &val
, &num
)) {
1198 /* use the first value that we know about in the array */
1199 for (i
= 0; i
< num
; ++i
) {
1200 if (val
[i
] == prop_atoms
.net_wm_window_type_desktop
)
1201 self
->type
= OB_CLIENT_TYPE_DESKTOP
;
1202 else if (val
[i
] == prop_atoms
.net_wm_window_type_dock
)
1203 self
->type
= OB_CLIENT_TYPE_DOCK
;
1204 else if (val
[i
] == prop_atoms
.net_wm_window_type_toolbar
)
1205 self
->type
= OB_CLIENT_TYPE_TOOLBAR
;
1206 else if (val
[i
] == prop_atoms
.net_wm_window_type_menu
)
1207 self
->type
= OB_CLIENT_TYPE_MENU
;
1208 else if (val
[i
] == prop_atoms
.net_wm_window_type_utility
)
1209 self
->type
= OB_CLIENT_TYPE_UTILITY
;
1210 else if (val
[i
] == prop_atoms
.net_wm_window_type_splash
)
1211 self
->type
= OB_CLIENT_TYPE_SPLASH
;
1212 else if (val
[i
] == prop_atoms
.net_wm_window_type_dialog
)
1213 self
->type
= OB_CLIENT_TYPE_DIALOG
;
1214 else if (val
[i
] == prop_atoms
.net_wm_window_type_normal
)
1215 self
->type
= OB_CLIENT_TYPE_NORMAL
;
1216 else if (val
[i
] == prop_atoms
.kde_net_wm_window_type_override
) {
1217 /* prevent this window from getting any decor or
1219 self
->mwmhints
.flags
&= (OB_MWM_FLAG_FUNCTIONS
|
1220 OB_MWM_FLAG_DECORATIONS
);
1221 self
->mwmhints
.decorations
= 0;
1222 self
->mwmhints
.functions
= 0;
1224 if (self
->type
!= (ObClientType
) -1)
1225 break; /* grab the first legit type */
1230 if (self
->type
== (ObClientType
) -1) {
1231 /*the window type hint was not set, which means we either classify
1232 ourself as a normal window or a dialog, depending on if we are a
1234 if (self
->transient
)
1235 self
->type
= OB_CLIENT_TYPE_DIALOG
;
1237 self
->type
= OB_CLIENT_TYPE_NORMAL
;
1241 void client_update_protocols(ObClient
*self
)
1244 guint num_return
, i
;
1246 self
->focus_notify
= FALSE
;
1247 self
->delete_window
= FALSE
;
1249 if (PROP_GETA32(self
->window
, wm_protocols
, atom
, &proto
, &num_return
)) {
1250 for (i
= 0; i
< num_return
; ++i
) {
1251 if (proto
[i
] == prop_atoms
.wm_delete_window
) {
1252 /* this means we can request the window to close */
1253 self
->delete_window
= TRUE
;
1254 } else if (proto
[i
] == prop_atoms
.wm_take_focus
)
1255 /* if this protocol is requested, then the window will be
1256 notified whenever we want it to receive focus */
1257 self
->focus_notify
= TRUE
;
1263 static void client_get_gravity(ObClient
*self
)
1265 XWindowAttributes wattrib
;
1268 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
1269 g_assert(ret
!= BadWindow
);
1270 self
->gravity
= wattrib
.win_gravity
;
1273 void client_update_normal_hints(ObClient
*self
)
1277 gint oldgravity
= self
->gravity
;
1280 self
->min_ratio
= 0.0f
;
1281 self
->max_ratio
= 0.0f
;
1282 SIZE_SET(self
->size_inc
, 1, 1);
1283 SIZE_SET(self
->base_size
, 0, 0);
1284 SIZE_SET(self
->min_size
, 0, 0);
1285 SIZE_SET(self
->max_size
, G_MAXINT
, G_MAXINT
);
1287 /* get the hints from the window */
1288 if (XGetWMNormalHints(ob_display
, self
->window
, &size
, &ret
)) {
1289 /* normal windows can't request placement! har har
1290 if (!client_normal(self))
1292 self
->positioned
= (size
.flags
& (PPosition
|USPosition
));
1294 if (size
.flags
& PWinGravity
) {
1295 self
->gravity
= size
.win_gravity
;
1297 /* if the client has a frame, i.e. has already been mapped and
1298 is changing its gravity */
1299 if (self
->frame
&& self
->gravity
!= oldgravity
) {
1300 /* move our idea of the client's position based on its new
1302 self
->area
.x
= self
->frame
->area
.x
;
1303 self
->area
.y
= self
->frame
->area
.y
;
1304 frame_frame_gravity(self
->frame
, &self
->area
.x
, &self
->area
.y
);
1308 if (size
.flags
& PAspect
) {
1309 if (size
.min_aspect
.y
)
1311 (gfloat
) size
.min_aspect
.x
/ size
.min_aspect
.y
;
1312 if (size
.max_aspect
.y
)
1314 (gfloat
) size
.max_aspect
.x
/ size
.max_aspect
.y
;
1317 if (size
.flags
& PMinSize
)
1318 SIZE_SET(self
->min_size
, size
.min_width
, size
.min_height
);
1320 if (size
.flags
& PMaxSize
)
1321 SIZE_SET(self
->max_size
, size
.max_width
, size
.max_height
);
1323 if (size
.flags
& PBaseSize
)
1324 SIZE_SET(self
->base_size
, size
.base_width
, size
.base_height
);
1326 if (size
.flags
& PResizeInc
&& size
.width_inc
&& size
.height_inc
)
1327 SIZE_SET(self
->size_inc
, size
.width_inc
, size
.height_inc
);
1331 void client_setup_decor_and_functions(ObClient
*self
)
1333 /* start with everything (cept fullscreen) */
1335 (OB_FRAME_DECOR_TITLEBAR
|
1336 OB_FRAME_DECOR_HANDLE
|
1337 OB_FRAME_DECOR_GRIPS
|
1338 OB_FRAME_DECOR_BORDER
|
1339 OB_FRAME_DECOR_ICON
|
1340 OB_FRAME_DECOR_ALLDESKTOPS
|
1341 OB_FRAME_DECOR_ICONIFY
|
1342 OB_FRAME_DECOR_MAXIMIZE
|
1343 OB_FRAME_DECOR_SHADE
|
1344 OB_FRAME_DECOR_CLOSE
);
1346 (OB_CLIENT_FUNC_RESIZE
|
1347 OB_CLIENT_FUNC_MOVE
|
1348 OB_CLIENT_FUNC_ICONIFY
|
1349 OB_CLIENT_FUNC_MAXIMIZE
|
1350 OB_CLIENT_FUNC_SHADE
|
1351 OB_CLIENT_FUNC_CLOSE
);
1353 if (!(self
->min_size
.width
< self
->max_size
.width
||
1354 self
->min_size
.height
< self
->max_size
.height
))
1355 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
1357 switch (self
->type
) {
1358 case OB_CLIENT_TYPE_NORMAL
:
1359 /* normal windows retain all of the possible decorations and
1360 functionality, and are the only windows that you can fullscreen */
1361 self
->functions
|= OB_CLIENT_FUNC_FULLSCREEN
;
1364 case OB_CLIENT_TYPE_DIALOG
:
1365 case OB_CLIENT_TYPE_UTILITY
:
1366 /* these windows cannot be maximized */
1367 self
->functions
&= ~OB_CLIENT_FUNC_MAXIMIZE
;
1370 case OB_CLIENT_TYPE_MENU
:
1371 case OB_CLIENT_TYPE_TOOLBAR
:
1372 /* these windows get less functionality */
1373 self
->functions
&= ~(OB_CLIENT_FUNC_ICONIFY
| OB_CLIENT_FUNC_RESIZE
);
1376 case OB_CLIENT_TYPE_DESKTOP
:
1377 case OB_CLIENT_TYPE_DOCK
:
1378 case OB_CLIENT_TYPE_SPLASH
:
1379 /* none of these windows are manipulated by the window manager */
1380 self
->decorations
= 0;
1381 self
->functions
= 0;
1385 /* Mwm Hints are applied subtractively to what has already been chosen for
1386 decor and functionality */
1387 if (self
->mwmhints
.flags
& OB_MWM_FLAG_DECORATIONS
) {
1388 if (! (self
->mwmhints
.decorations
& OB_MWM_DECOR_ALL
)) {
1389 if (! ((self
->mwmhints
.decorations
& OB_MWM_DECOR_HANDLE
) ||
1390 (self
->mwmhints
.decorations
& OB_MWM_DECOR_TITLE
)))
1392 /* if the mwm hints request no handle or title, then all
1393 decorations are disabled, but keep the border if that's
1395 if (self
->mwmhints
.decorations
& OB_MWM_DECOR_BORDER
)
1396 self
->decorations
= OB_FRAME_DECOR_BORDER
;
1398 self
->decorations
= 0;
1403 if (self
->mwmhints
.flags
& OB_MWM_FLAG_FUNCTIONS
) {
1404 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_ALL
)) {
1405 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_RESIZE
))
1406 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
1407 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_MOVE
))
1408 self
->functions
&= ~OB_CLIENT_FUNC_MOVE
;
1409 /* dont let mwm hints kill any buttons
1410 if (! (self->mwmhints.functions & OB_MWM_FUNC_ICONIFY))
1411 self->functions &= ~OB_CLIENT_FUNC_ICONIFY;
1412 if (! (self->mwmhints.functions & OB_MWM_FUNC_MAXIMIZE))
1413 self->functions &= ~OB_CLIENT_FUNC_MAXIMIZE;
1415 /* dont let mwm hints kill the close button
1416 if (! (self->mwmhints.functions & MwmFunc_Close))
1417 self->functions &= ~OB_CLIENT_FUNC_CLOSE; */
1421 if (!(self
->functions
& OB_CLIENT_FUNC_SHADE
))
1422 self
->decorations
&= ~OB_FRAME_DECOR_SHADE
;
1423 if (!(self
->functions
& OB_CLIENT_FUNC_ICONIFY
))
1424 self
->decorations
&= ~OB_FRAME_DECOR_ICONIFY
;
1425 if (!(self
->functions
& OB_CLIENT_FUNC_RESIZE
))
1426 self
->decorations
&= ~OB_FRAME_DECOR_GRIPS
;
1428 /* can't maximize without moving/resizing */
1429 if (!((self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) &&
1430 (self
->functions
& OB_CLIENT_FUNC_MOVE
) &&
1431 (self
->functions
& OB_CLIENT_FUNC_RESIZE
))) {
1432 self
->functions
&= ~OB_CLIENT_FUNC_MAXIMIZE
;
1433 self
->decorations
&= ~OB_FRAME_DECOR_MAXIMIZE
;
1436 /* kill the handle on fully maxed windows */
1437 if (self
->max_vert
&& self
->max_horz
)
1438 self
->decorations
&= ~OB_FRAME_DECOR_HANDLE
;
1440 /* finally, the user can have requested no decorations, which overrides
1441 everything (but doesnt give it a border if it doesnt have one) */
1442 if (self
->undecorated
) {
1443 if (config_theme_keepborder
)
1444 self
->decorations
&= OB_FRAME_DECOR_BORDER
;
1446 self
->decorations
= 0;
1449 /* if we don't have a titlebar, then we cannot shade! */
1450 if (!(self
->decorations
& OB_FRAME_DECOR_TITLEBAR
))
1451 self
->functions
&= ~OB_CLIENT_FUNC_SHADE
;
1453 /* now we need to check against rules for the client's current state */
1454 if (self
->fullscreen
) {
1455 self
->functions
&= (OB_CLIENT_FUNC_CLOSE
|
1456 OB_CLIENT_FUNC_FULLSCREEN
|
1457 OB_CLIENT_FUNC_ICONIFY
);
1458 self
->decorations
= 0;
1461 client_change_allowed_actions(self
);
1464 /* adjust the client's decorations, etc. */
1465 client_reconfigure(self
);
1469 static void client_change_allowed_actions(ObClient
*self
)
1474 /* desktop windows are kept on all desktops */
1475 if (self
->type
!= OB_CLIENT_TYPE_DESKTOP
)
1476 actions
[num
++] = prop_atoms
.net_wm_action_change_desktop
;
1478 if (self
->functions
& OB_CLIENT_FUNC_SHADE
)
1479 actions
[num
++] = prop_atoms
.net_wm_action_shade
;
1480 if (self
->functions
& OB_CLIENT_FUNC_CLOSE
)
1481 actions
[num
++] = prop_atoms
.net_wm_action_close
;
1482 if (self
->functions
& OB_CLIENT_FUNC_MOVE
)
1483 actions
[num
++] = prop_atoms
.net_wm_action_move
;
1484 if (self
->functions
& OB_CLIENT_FUNC_ICONIFY
)
1485 actions
[num
++] = prop_atoms
.net_wm_action_minimize
;
1486 if (self
->functions
& OB_CLIENT_FUNC_RESIZE
)
1487 actions
[num
++] = prop_atoms
.net_wm_action_resize
;
1488 if (self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
)
1489 actions
[num
++] = prop_atoms
.net_wm_action_fullscreen
;
1490 if (self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) {
1491 actions
[num
++] = prop_atoms
.net_wm_action_maximize_horz
;
1492 actions
[num
++] = prop_atoms
.net_wm_action_maximize_vert
;
1495 PROP_SETA32(self
->window
, net_wm_allowed_actions
, atom
, actions
, num
);
1497 /* make sure the window isn't breaking any rules now */
1499 if (!(self
->functions
& OB_CLIENT_FUNC_SHADE
) && self
->shaded
) {
1500 if (self
->frame
) client_shade(self
, FALSE
);
1501 else self
->shaded
= FALSE
;
1503 if (!(self
->functions
& OB_CLIENT_FUNC_ICONIFY
) && self
->iconic
) {
1504 if (self
->frame
) client_iconify(self
, FALSE
, TRUE
);
1505 else self
->iconic
= FALSE
;
1507 if (!(self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
) && self
->fullscreen
) {
1508 if (self
->frame
) client_fullscreen(self
, FALSE
, TRUE
);
1509 else self
->fullscreen
= FALSE
;
1511 if (!(self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) && (self
->max_horz
||
1513 if (self
->frame
) client_maximize(self
, FALSE
, 0, TRUE
);
1514 else self
->max_vert
= self
->max_horz
= FALSE
;
1518 void client_reconfigure(ObClient
*self
)
1520 /* by making this pass FALSE for user, we avoid the emacs event storm where
1521 every configurenotify causes an update in its normal hints, i think this
1522 is generally what we want anyways... */
1523 client_configure(self
, OB_CORNER_TOPLEFT
, self
->area
.x
, self
->area
.y
,
1524 self
->area
.width
, self
->area
.height
, FALSE
, TRUE
);
1527 void client_update_wmhints(ObClient
*self
)
1532 /* assume a window takes input if it doesnt specify */
1533 self
->can_focus
= TRUE
;
1535 if ((hints
= XGetWMHints(ob_display
, self
->window
)) != NULL
) {
1536 if (hints
->flags
& InputHint
)
1537 self
->can_focus
= hints
->input
;
1539 /* only do this when first managing the window *AND* when we aren't
1541 if (ob_state() != OB_STATE_STARTING
&& self
->frame
== NULL
)
1542 if (hints
->flags
& StateHint
)
1543 self
->iconic
= hints
->initial_state
== IconicState
;
1545 if (!(hints
->flags
& WindowGroupHint
))
1546 hints
->window_group
= None
;
1548 /* did the group state change? */
1549 if (hints
->window_group
!=
1550 (self
->group
? self
->group
->leader
: None
)) {
1551 /* remove from the old group if there was one */
1552 if (self
->group
!= NULL
) {
1553 /* remove transients of the group */
1554 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
))
1555 self
->transients
= g_slist_remove(self
->transients
,
1558 /* remove myself from parents in the group */
1559 if (self
->transient_for
== OB_TRAN_GROUP
) {
1560 for (it
= self
->group
->members
; it
;
1561 it
= g_slist_next(it
))
1563 ObClient
*c
= it
->data
;
1565 if (c
!= self
&& !c
->transient_for
)
1566 c
->transients
= g_slist_remove(c
->transients
,
1571 group_remove(self
->group
, self
);
1574 if (hints
->window_group
!= None
) {
1575 self
->group
= group_add(hints
->window_group
, self
);
1577 /* i can only have transients from the group if i am not
1579 if (!self
->transient_for
) {
1580 /* add other transients of the group that are already
1582 for (it
= self
->group
->members
; it
;
1583 it
= g_slist_next(it
))
1585 ObClient
*c
= it
->data
;
1586 if (c
!= self
&& c
->transient_for
== OB_TRAN_GROUP
)
1588 g_slist_append(self
->transients
, c
);
1593 /* because the self->transient flag wont change from this call,
1594 we don't need to update the window's type and such, only its
1595 transient_for, and the transients lists of other windows in
1596 the group may be affected */
1597 client_update_transient_for(self
);
1600 /* the WM_HINTS can contain an icon */
1601 client_update_icons(self
);
1607 void client_update_title(ObClient
*self
)
1613 gboolean read_title
;
1616 old_title
= self
->title
;
1619 if (!PROP_GETS(self
->window
, net_wm_name
, utf8
, &data
)) {
1620 /* try old x stuff */
1621 if (!(PROP_GETS(self
->window
, wm_name
, locale
, &data
)
1622 || PROP_GETS(self
->window
, wm_name
, utf8
, &data
))) {
1623 // http://developer.gnome.org/projects/gup/hig/draft_hig_new/windows-alert.html
1624 if (self
->transient
) {
1625 data
= g_strdup("");
1628 data
= g_strdup("Unnamed Window");
1632 if (config_title_number
) {
1634 /* did the title change? then reset the title_count */
1635 if (old_title
&& 0 != strncmp(old_title
, data
, strlen(data
)))
1636 self
->title_count
= 1;
1638 /* look for duplicates and append a number */
1640 for (it
= client_list
; it
; it
= g_list_next(it
))
1641 if (it
->data
!= self
) {
1642 ObClient
*c
= it
->data
;
1644 if (c
->title_count
== 1) {
1645 if (!strcmp(c
->title
, data
))
1646 nums
|= 1 << c
->title_count
;
1651 /* find the beginning of our " - [%u]", this relies on
1652 that syntax being used */
1653 end
= strrchr(c
->title
, '-') - 1;
1654 len
= end
- c
->title
;
1655 if (!strncmp(c
->title
, data
, len
))
1656 nums
|= 1 << c
->title_count
;
1659 /* find first free number */
1660 for (i
= 1; i
<= 32; ++i
)
1661 if (!(nums
& (1 << i
))) {
1662 if (self
->title_count
== 1 || i
== 1)
1663 self
->title_count
= i
;
1666 /* dont display the number for the first window */
1667 if (self
->title_count
> 1) {
1669 ndata
= g_strdup_printf("%s - [%u]", data
, self
->title_count
);
1674 self
->title_count
= 1;
1677 PROP_SETS(self
->window
, net_wm_visible_name
, data
);
1681 frame_adjust_title(self
->frame
);
1685 /* update the icon title */
1687 g_free(self
->icon_title
);
1691 if (!PROP_GETS(self
->window
, net_wm_icon_name
, utf8
, &data
))
1692 /* try old x stuff */
1693 if (!(PROP_GETS(self
->window
, wm_icon_name
, locale
, &data
)
1694 || PROP_GETS(self
->window
, wm_icon_name
, utf8
, &data
))) {
1695 data
= g_strdup(self
->title
);
1699 /* append the title count, dont display the number for the first window.
1700 * We don't need to check for config_title_number here since title_count
1701 * is not set above 1 then. */
1702 if (read_title
&& self
->title_count
> 1) {
1704 newdata
= g_strdup_printf("%s - [%u]", data
, self
->title_count
);
1709 PROP_SETS(self
->window
, net_wm_visible_icon_name
, data
);
1711 self
->icon_title
= data
;
1714 void client_update_class(ObClient
*self
)
1719 if (self
->name
) g_free(self
->name
);
1720 if (self
->class) g_free(self
->class);
1721 if (self
->role
) g_free(self
->role
);
1723 self
->name
= self
->class = self
->role
= NULL
;
1725 if (PROP_GETSS(self
->window
, wm_class
, locale
, &data
)) {
1727 self
->name
= g_strdup(data
[0]);
1729 self
->class = g_strdup(data
[1]);
1734 if (PROP_GETS(self
->window
, wm_window_role
, locale
, &s
))
1737 if (self
->name
== NULL
) self
->name
= g_strdup("");
1738 if (self
->class == NULL
) self
->class = g_strdup("");
1739 if (self
->role
== NULL
) self
->role
= g_strdup("");
1742 void client_update_strut(ObClient
*self
)
1746 gboolean got
= FALSE
;
1749 if (PROP_GETA32(self
->window
, net_wm_strut_partial
, cardinal
,
1753 STRUT_PARTIAL_SET(strut
,
1754 data
[0], data
[2], data
[1], data
[3],
1755 data
[4], data
[5], data
[8], data
[9],
1756 data
[6], data
[7], data
[10], data
[11]);
1762 PROP_GETA32(self
->window
, net_wm_strut
, cardinal
, &data
, &num
)) {
1768 /* use the screen's width/height */
1769 a
= screen_physical_area();
1771 STRUT_PARTIAL_SET(strut
,
1772 data
[0], data
[2], data
[1], data
[3],
1773 a
->y
, a
->y
+ a
->height
- 1,
1774 a
->x
, a
->x
+ a
->width
- 1,
1775 a
->y
, a
->y
+ a
->height
- 1,
1776 a
->x
, a
->x
+ a
->width
- 1);
1782 STRUT_PARTIAL_SET(strut
, 0, 0, 0, 0,
1783 0, 0, 0, 0, 0, 0, 0, 0);
1785 if (!STRUT_EQUAL(strut
, self
->strut
)) {
1786 self
->strut
= strut
;
1788 /* updating here is pointless while we're being mapped cuz we're not in
1789 the client list yet */
1791 screen_update_areas();
1795 void client_update_icons(ObClient
*self
)
1801 for (i
= 0; i
< self
->nicons
; ++i
)
1802 g_free(self
->icons
[i
].data
);
1803 if (self
->nicons
> 0)
1804 g_free(self
->icons
);
1807 if (PROP_GETA32(self
->window
, net_wm_icon
, cardinal
, &data
, &num
)) {
1808 /* figure out how many valid icons are in here */
1810 while (num
- i
> 2) {
1814 if (i
> num
|| w
*h
== 0) break;
1818 self
->icons
= g_new(ObClientIcon
, self
->nicons
);
1820 /* store the icons */
1822 for (j
= 0; j
< self
->nicons
; ++j
) {
1825 w
= self
->icons
[j
].width
= data
[i
++];
1826 h
= self
->icons
[j
].height
= data
[i
++];
1828 if (w
*h
== 0) continue;
1830 self
->icons
[j
].data
= g_new(RrPixel32
, w
* h
);
1831 for (x
= 0, y
= 0, t
= 0; t
< w
* h
; ++t
, ++x
, ++i
) {
1836 self
->icons
[j
].data
[t
] =
1837 (((data
[i
] >> 24) & 0xff) << RrDefaultAlphaOffset
) +
1838 (((data
[i
] >> 16) & 0xff) << RrDefaultRedOffset
) +
1839 (((data
[i
] >> 8) & 0xff) << RrDefaultGreenOffset
) +
1840 (((data
[i
] >> 0) & 0xff) << RrDefaultBlueOffset
);
1849 if ((hints
= XGetWMHints(ob_display
, self
->window
))) {
1850 if (hints
->flags
& IconPixmapHint
) {
1852 self
->icons
= g_new(ObClientIcon
, self
->nicons
);
1853 xerror_set_ignore(TRUE
);
1854 if (!RrPixmapToRGBA(ob_rr_inst
,
1856 (hints
->flags
& IconMaskHint
?
1857 hints
->icon_mask
: None
),
1858 &self
->icons
[self
->nicons
-1].width
,
1859 &self
->icons
[self
->nicons
-1].height
,
1860 &self
->icons
[self
->nicons
-1].data
)){
1861 g_free(&self
->icons
[self
->nicons
-1]);
1864 xerror_set_ignore(FALSE
);
1871 frame_adjust_icon(self
->frame
);
1874 void client_update_user_time(ObClient
*self
, gboolean new_event
)
1878 if (PROP_GET32(self
->window
, net_wm_user_time
, cardinal
, &time
)) {
1879 self
->user_time
= time
;
1880 /* we set this every time, not just when it grows, because in practice
1881 sometimes time goes backwards! (ntpdate.. yay....) so.. if it goes
1882 backward we don't want all windows to stop focusing. we'll just
1883 assume noone is setting times older than the last one, cuz that
1884 would be pretty stupid anyways
1885 However! This is called when a window is mapped to get its user time
1886 but it's an old number, it's not changing it from new user
1887 interaction, so in that case, don't change the last user time.
1890 client_last_user_time
= time
;
1892 /*ob_debug("window 0x%x user time %u\n", self->window, time);*/
1896 static void client_change_state(ObClient
*self
)
1899 gulong netstate
[11];
1902 state
[0] = self
->wmstate
;
1904 PROP_SETA32(self
->window
, wm_state
, wm_state
, state
, 2);
1908 netstate
[num
++] = prop_atoms
.net_wm_state_modal
;
1910 netstate
[num
++] = prop_atoms
.net_wm_state_shaded
;
1912 netstate
[num
++] = prop_atoms
.net_wm_state_hidden
;
1913 if (self
->skip_taskbar
)
1914 netstate
[num
++] = prop_atoms
.net_wm_state_skip_taskbar
;
1915 if (self
->skip_pager
)
1916 netstate
[num
++] = prop_atoms
.net_wm_state_skip_pager
;
1917 if (self
->fullscreen
)
1918 netstate
[num
++] = prop_atoms
.net_wm_state_fullscreen
;
1920 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_vert
;
1922 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_horz
;
1924 netstate
[num
++] = prop_atoms
.net_wm_state_above
;
1926 netstate
[num
++] = prop_atoms
.net_wm_state_below
;
1927 if (self
->demands_attention
)
1928 netstate
[num
++] = prop_atoms
.net_wm_state_demands_attention
;
1929 if (self
->undecorated
)
1930 netstate
[num
++] = prop_atoms
.ob_wm_state_undecorated
;
1931 PROP_SETA32(self
->window
, net_wm_state
, atom
, netstate
, num
);
1934 frame_adjust_state(self
->frame
);
1937 ObClient
*client_search_focus_tree(ObClient
*self
)
1942 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
1943 if (client_focused(it
->data
)) return it
->data
;
1944 if ((ret
= client_search_focus_tree(it
->data
))) return ret
;
1949 ObClient
*client_search_focus_tree_full(ObClient
*self
)
1951 if (self
->transient_for
) {
1952 if (self
->transient_for
!= OB_TRAN_GROUP
) {
1953 return client_search_focus_tree_full(self
->transient_for
);
1956 gboolean recursed
= FALSE
;
1958 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
))
1959 if (!((ObClient
*)it
->data
)->transient_for
) {
1961 if ((c
= client_search_focus_tree_full(it
->data
)))
1970 /* this function checks the whole tree, the client_search_focus_tree~
1971 does not, so we need to check this window */
1972 if (client_focused(self
))
1974 return client_search_focus_tree(self
);
1977 static ObStackingLayer
calc_layer(ObClient
*self
)
1981 if (self
->fullscreen
&&
1982 (client_focused(self
) || client_search_focus_tree(self
)))
1983 l
= OB_STACKING_LAYER_FULLSCREEN
;
1984 else if (self
->type
== OB_CLIENT_TYPE_DESKTOP
)
1985 l
= OB_STACKING_LAYER_DESKTOP
;
1986 else if (self
->type
== OB_CLIENT_TYPE_DOCK
) {
1987 if (self
->below
) l
= OB_STACKING_LAYER_NORMAL
;
1988 else l
= OB_STACKING_LAYER_ABOVE
;
1990 else if (self
->above
) l
= OB_STACKING_LAYER_ABOVE
;
1991 else if (self
->below
) l
= OB_STACKING_LAYER_BELOW
;
1992 else l
= OB_STACKING_LAYER_NORMAL
;
1997 static void client_calc_layer_recursive(ObClient
*self
, ObClient
*orig
,
1998 ObStackingLayer min
, gboolean raised
)
2000 ObStackingLayer old
, own
;
2004 own
= calc_layer(self
);
2005 self
->layer
= MAX(own
, min
);
2007 ob_debug("layer for %s: %d\n", self
->title
, self
->layer
);
2009 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
2010 client_calc_layer_recursive(it
->data
, orig
,
2012 raised
? raised
: self
->layer
!= old
);
2014 if (!raised
&& self
->layer
!= old
)
2015 if (orig
->frame
) { /* only restack if the original window is managed */
2016 stacking_remove(CLIENT_AS_WINDOW(self
));
2017 stacking_add(CLIENT_AS_WINDOW(self
));
2021 void client_calc_layer(ObClient
*self
)
2028 /* transients take on the layer of their parents */
2029 it
= client_search_top_transients(self
);
2031 for (; it
; it
= g_slist_next(it
))
2032 client_calc_layer_recursive(it
->data
, orig
, 0, FALSE
);
2035 gboolean
client_should_show(ObClient
*self
)
2039 if (client_normal(self
) && screen_showing_desktop
)
2042 if (self->transient_for) {
2043 if (self->transient_for != OB_TRAN_GROUP)
2044 return client_should_show(self->transient_for);
2048 for (it = self->group->members; it; it = g_slist_next(it)) {
2049 ObClient *c = it->data;
2050 if (c != self && !c->transient_for) {
2051 if (client_should_show(c))
2058 if (self
->desktop
== screen_desktop
|| self
->desktop
== DESKTOP_ALL
)
2064 static void client_showhide(ObClient
*self
)
2067 if (client_should_show(self
))
2068 frame_show(self
->frame
);
2070 frame_hide(self
->frame
);
2073 gboolean
client_normal(ObClient
*self
) {
2074 return ! (self
->type
== OB_CLIENT_TYPE_DESKTOP
||
2075 self
->type
== OB_CLIENT_TYPE_DOCK
||
2076 self
->type
== OB_CLIENT_TYPE_SPLASH
);
2079 static void client_apply_startup_state(ObClient
*self
)
2081 /* these are in a carefully crafted order.. */
2084 self
->iconic
= FALSE
;
2085 client_iconify(self
, TRUE
, FALSE
);
2087 if (self
->fullscreen
) {
2088 self
->fullscreen
= FALSE
;
2089 client_fullscreen(self
, TRUE
, FALSE
);
2091 if (self
->undecorated
) {
2092 self
->undecorated
= FALSE
;
2093 client_set_undecorated(self
, TRUE
);
2096 self
->shaded
= FALSE
;
2097 client_shade(self
, TRUE
);
2099 if (self
->demands_attention
) {
2100 self
->demands_attention
= FALSE
;
2101 client_hilite(self
, TRUE
);
2104 if (self
->max_vert
&& self
->max_horz
) {
2105 self
->max_vert
= self
->max_horz
= FALSE
;
2106 client_maximize(self
, TRUE
, 0, FALSE
);
2107 } else if (self
->max_vert
) {
2108 self
->max_vert
= FALSE
;
2109 client_maximize(self
, TRUE
, 2, FALSE
);
2110 } else if (self
->max_horz
) {
2111 self
->max_horz
= FALSE
;
2112 client_maximize(self
, TRUE
, 1, FALSE
);
2115 /* nothing to do for the other states:
2124 void client_configure_full(ObClient
*self
, ObCorner anchor
,
2125 gint x
, gint y
, gint w
, gint h
,
2126 gboolean user
, gboolean final
,
2127 gboolean force_reply
)
2130 gboolean send_resize_client
;
2131 gboolean moved
= FALSE
, resized
= FALSE
;
2132 guint fdecor
= self
->frame
->decorations
;
2133 gboolean fhorz
= self
->frame
->max_horz
;
2134 Rect desired_area
= {x
, y
, w
, h
};
2136 /* make the frame recalculate its dimentions n shit without changing
2137 anything visible for real, this way the constraints below can work with
2138 the updated frame dimensions. */
2139 frame_adjust_area(self
->frame
, TRUE
, TRUE
, TRUE
);
2141 /* gets the frame's position */
2142 frame_client_gravity(self
->frame
, &x
, &y
);
2144 /* these positions are frame positions, not client positions */
2146 /* set the size and position if fullscreen */
2147 if (self
->fullscreen
) {
2151 i
= screen_find_monitor(&desired_area
);
2152 a
= screen_physical_area_monitor(i
);
2159 user
= FALSE
; /* ignore that increment etc shit when in fullscreen */
2164 i
= screen_find_monitor(&desired_area
);
2165 a
= screen_area_monitor(self
->desktop
, i
);
2167 /* set the size and position if maximized */
2168 if (self
->max_horz
) {
2170 w
= a
->width
- self
->frame
->size
.left
- self
->frame
->size
.right
;
2172 if (self
->max_vert
) {
2174 h
= a
->height
- self
->frame
->size
.top
- self
->frame
->size
.bottom
;
2178 /* gets the client's position */
2179 frame_frame_gravity(self
->frame
, &x
, &y
);
2181 /* these override the above states! if you cant move you can't move! */
2183 if (!(self
->functions
& OB_CLIENT_FUNC_MOVE
)) {
2187 if (!(self
->functions
& OB_CLIENT_FUNC_RESIZE
)) {
2188 w
= self
->area
.width
;
2189 h
= self
->area
.height
;
2193 if (!(w
== self
->area
.width
&& h
== self
->area
.height
)) {
2194 gint basew
, baseh
, minw
, minh
;
2196 /* base size is substituted with min size if not specified */
2197 if (self
->base_size
.width
|| self
->base_size
.height
) {
2198 basew
= self
->base_size
.width
;
2199 baseh
= self
->base_size
.height
;
2201 basew
= self
->min_size
.width
;
2202 baseh
= self
->min_size
.height
;
2204 /* min size is substituted with base size if not specified */
2205 if (self
->min_size
.width
|| self
->min_size
.height
) {
2206 minw
= self
->min_size
.width
;
2207 minh
= self
->min_size
.height
;
2209 minw
= self
->base_size
.width
;
2210 minh
= self
->base_size
.height
;
2213 /* if this is a user-requested resize, then check against min/max
2216 /* smaller than min size or bigger than max size? */
2217 if (w
> self
->max_size
.width
) w
= self
->max_size
.width
;
2218 if (w
< minw
) w
= minw
;
2219 if (h
> self
->max_size
.height
) h
= self
->max_size
.height
;
2220 if (h
< minh
) h
= minh
;
2225 /* keep to the increments */
2226 w
/= self
->size_inc
.width
;
2227 h
/= self
->size_inc
.height
;
2229 /* you cannot resize to nothing */
2230 if (basew
+ w
< 1) w
= 1 - basew
;
2231 if (baseh
+ h
< 1) h
= 1 - baseh
;
2233 /* store the logical size */
2234 SIZE_SET(self
->logical_size
,
2235 self
->size_inc
.width
> 1 ? w
: w
+ basew
,
2236 self
->size_inc
.height
> 1 ? h
: h
+ baseh
);
2238 w
*= self
->size_inc
.width
;
2239 h
*= self
->size_inc
.height
;
2244 /* adjust the height to match the width for the aspect ratios.
2245 for this, min size is not substituted for base size ever. */
2246 w
-= self
->base_size
.width
;
2247 h
-= self
->base_size
.height
;
2249 if (!self
->fullscreen
) {
2250 if (self
->min_ratio
)
2251 if (h
* self
->min_ratio
> w
) {
2252 h
= (gint
)(w
/ self
->min_ratio
);
2254 /* you cannot resize to nothing */
2257 w
= (gint
)(h
* self
->min_ratio
);
2260 if (self
->max_ratio
)
2261 if (h
* self
->max_ratio
< w
) {
2262 h
= (gint
)(w
/ self
->max_ratio
);
2264 /* you cannot resize to nothing */
2267 w
= (gint
)(h
* self
->min_ratio
);
2272 w
+= self
->base_size
.width
;
2273 h
+= self
->base_size
.height
;
2280 case OB_CORNER_TOPLEFT
:
2282 case OB_CORNER_TOPRIGHT
:
2283 x
-= w
- self
->area
.width
;
2285 case OB_CORNER_BOTTOMLEFT
:
2286 y
-= h
- self
->area
.height
;
2288 case OB_CORNER_BOTTOMRIGHT
:
2289 x
-= w
- self
->area
.width
;
2290 y
-= h
- self
->area
.height
;
2294 moved
= x
!= self
->area
.x
|| y
!= self
->area
.y
;
2295 resized
= w
!= self
->area
.width
|| h
!= self
->area
.height
;
2297 oldw
= self
->area
.width
;
2298 oldh
= self
->area
.height
;
2299 RECT_SET(self
->area
, x
, y
, w
, h
);
2301 /* for app-requested resizes, always resize if 'resized' is true.
2302 for user-requested ones, only resize if final is true, or when
2303 resizing in redraw mode */
2304 send_resize_client
= ((!user
&& resized
) ||
2306 (resized
&& config_resize_redraw
))));
2308 /* if the client is enlarging, then resize the client before the frame */
2309 if (send_resize_client
&& user
&& (w
> oldw
|| h
> oldh
))
2310 XResizeWindow(ob_display
, self
->window
, MAX(w
, oldw
), MAX(h
, oldh
));
2312 /* move/resize the frame to match the request */
2314 if (self
->decorations
!= fdecor
|| self
->max_horz
!= fhorz
)
2315 moved
= resized
= TRUE
;
2317 if (moved
|| resized
)
2318 frame_adjust_area(self
->frame
, moved
, resized
, FALSE
);
2320 if (!resized
&& (force_reply
|| ((!user
&& moved
) || (user
&& final
))))
2323 event
.type
= ConfigureNotify
;
2324 event
.xconfigure
.display
= ob_display
;
2325 event
.xconfigure
.event
= self
->window
;
2326 event
.xconfigure
.window
= self
->window
;
2328 /* root window real coords */
2329 event
.xconfigure
.x
= self
->frame
->area
.x
+ self
->frame
->size
.left
-
2331 event
.xconfigure
.y
= self
->frame
->area
.y
+ self
->frame
->size
.top
-
2333 event
.xconfigure
.width
= w
;
2334 event
.xconfigure
.height
= h
;
2335 event
.xconfigure
.border_width
= 0;
2336 event
.xconfigure
.above
= self
->frame
->plate
;
2337 event
.xconfigure
.override_redirect
= FALSE
;
2338 XSendEvent(event
.xconfigure
.display
, event
.xconfigure
.window
,
2339 FALSE
, StructureNotifyMask
, &event
);
2343 /* if the client is shrinking, then resize the frame before the client */
2344 if (send_resize_client
&& (!user
|| (w
<= oldw
|| h
<= oldh
)))
2345 XResizeWindow(ob_display
, self
->window
, w
, h
);
2350 void client_fullscreen(ObClient
*self
, gboolean fs
, gboolean savearea
)
2354 if (!(self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
) || /* can't */
2355 self
->fullscreen
== fs
) return; /* already done */
2357 self
->fullscreen
= fs
;
2358 client_change_state(self
); /* change the state hints on the client */
2359 client_calc_layer(self
); /* and adjust out layer/stacking */
2363 self
->pre_fullscreen_area
= self
->area
;
2365 /* these are not actually used cuz client_configure will set them
2366 as appropriate when the window is fullscreened */
2371 if (self
->pre_fullscreen_area
.width
> 0 &&
2372 self
->pre_fullscreen_area
.height
> 0)
2374 x
= self
->pre_fullscreen_area
.x
;
2375 y
= self
->pre_fullscreen_area
.y
;
2376 w
= self
->pre_fullscreen_area
.width
;
2377 h
= self
->pre_fullscreen_area
.height
;
2378 RECT_SET(self
->pre_fullscreen_area
, 0, 0, 0, 0);
2380 /* pick some fallbacks... */
2381 a
= screen_area_monitor(self
->desktop
, 0);
2382 x
= a
->x
+ a
->width
/ 4;
2383 y
= a
->y
+ a
->height
/ 4;
2389 client_setup_decor_and_functions(self
);
2391 client_move_resize(self
, x
, y
, w
, h
);
2393 /* try focus us when we go into fullscreen mode */
2397 static void client_iconify_recursive(ObClient
*self
,
2398 gboolean iconic
, gboolean curdesk
)
2401 gboolean changed
= FALSE
;
2404 if (self
->iconic
!= iconic
) {
2405 ob_debug("%sconifying window: 0x%lx\n", (iconic
? "I" : "Uni"),
2408 self
->iconic
= iconic
;
2411 if (self
->functions
& OB_CLIENT_FUNC_ICONIFY
) {
2414 old
= self
->wmstate
;
2415 self
->wmstate
= IconicState
;
2416 if (old
!= self
->wmstate
)
2417 PROP_MSG(self
->window
, kde_wm_change_state
,
2418 self
->wmstate
, 1, 0, 0);
2420 /* update the focus lists.. iconic windows go to the bottom of
2421 the list, put the new iconic window at the 'top of the
2423 focus_order_to_top(self
);
2431 client_set_desktop(self
, screen_desktop
, FALSE
);
2433 old
= self
->wmstate
;
2434 self
->wmstate
= self
->shaded
? IconicState
: NormalState
;
2435 if (old
!= self
->wmstate
)
2436 PROP_MSG(self
->window
, kde_wm_change_state
,
2437 self
->wmstate
, 1, 0, 0);
2439 /* this puts it after the current focused window */
2440 focus_order_remove(self
);
2441 focus_order_add_new(self
);
2448 client_change_state(self
);
2449 client_showhide(self
);
2450 if (STRUT_EXISTS(self
->strut
))
2451 screen_update_areas();
2454 /* iconify all transients */
2455 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
2456 if (it
->data
!= self
) client_iconify_recursive(it
->data
,
2460 void client_iconify(ObClient
*self
, gboolean iconic
, gboolean curdesk
)
2464 /* move up the transient chain as far as possible first */
2465 it
= client_search_top_transients(self
);
2467 for (; it
; it
= g_slist_next(it
))
2468 client_iconify_recursive(it
->data
, iconic
, curdesk
);
2471 void client_maximize(ObClient
*self
, gboolean max
, gint dir
, gboolean savearea
)
2475 g_assert(dir
== 0 || dir
== 1 || dir
== 2);
2476 if (!(self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
)) return; /* can't */
2478 /* check if already done */
2480 if (dir
== 0 && self
->max_horz
&& self
->max_vert
) return;
2481 if (dir
== 1 && self
->max_horz
) return;
2482 if (dir
== 2 && self
->max_vert
) return;
2484 if (dir
== 0 && !self
->max_horz
&& !self
->max_vert
) return;
2485 if (dir
== 1 && !self
->max_horz
) return;
2486 if (dir
== 2 && !self
->max_vert
) return;
2489 /* we just tell it to configure in the same place and client_configure
2490 worries about filling the screen with the window */
2493 w
= self
->area
.width
;
2494 h
= self
->area
.height
;
2498 if ((dir
== 0 || dir
== 1) && !self
->max_horz
) { /* horz */
2499 RECT_SET(self
->pre_max_area
,
2500 self
->area
.x
, self
->pre_max_area
.y
,
2501 self
->area
.width
, self
->pre_max_area
.height
);
2503 if ((dir
== 0 || dir
== 2) && !self
->max_vert
) { /* vert */
2504 RECT_SET(self
->pre_max_area
,
2505 self
->pre_max_area
.x
, self
->area
.y
,
2506 self
->pre_max_area
.width
, self
->area
.height
);
2512 a
= screen_area_monitor(self
->desktop
, 0);
2513 if ((dir
== 0 || dir
== 1) && self
->max_horz
) { /* horz */
2514 if (self
->pre_max_area
.width
> 0) {
2515 x
= self
->pre_max_area
.x
;
2516 w
= self
->pre_max_area
.width
;
2518 RECT_SET(self
->pre_max_area
, 0, self
->pre_max_area
.y
,
2519 0, self
->pre_max_area
.height
);
2521 /* pick some fallbacks... */
2522 x
= a
->x
+ a
->width
/ 4;
2526 if ((dir
== 0 || dir
== 2) && self
->max_vert
) { /* vert */
2527 if (self
->pre_max_area
.height
> 0) {
2528 y
= self
->pre_max_area
.y
;
2529 h
= self
->pre_max_area
.height
;
2531 RECT_SET(self
->pre_max_area
, self
->pre_max_area
.x
, 0,
2532 self
->pre_max_area
.width
, 0);
2534 /* pick some fallbacks... */
2535 y
= a
->y
+ a
->height
/ 4;
2541 if (dir
== 0 || dir
== 1) /* horz */
2542 self
->max_horz
= max
;
2543 if (dir
== 0 || dir
== 2) /* vert */
2544 self
->max_vert
= max
;
2546 client_change_state(self
); /* change the state hints on the client */
2548 client_setup_decor_and_functions(self
);
2550 client_move_resize(self
, x
, y
, w
, h
);
2553 void client_shade(ObClient
*self
, gboolean shade
)
2555 if ((!(self
->functions
& OB_CLIENT_FUNC_SHADE
) &&
2556 shade
) || /* can't shade */
2557 self
->shaded
== shade
) return; /* already done */
2559 /* when we're iconic, don't change the wmstate */
2560 if (!self
->iconic
) {
2563 old
= self
->wmstate
;
2564 self
->wmstate
= shade
? IconicState
: NormalState
;
2565 if (old
!= self
->wmstate
)
2566 PROP_MSG(self
->window
, kde_wm_change_state
,
2567 self
->wmstate
, 1, 0, 0);
2570 self
->shaded
= shade
;
2571 client_change_state(self
);
2572 /* resize the frame to just the titlebar */
2573 frame_adjust_area(self
->frame
, FALSE
, FALSE
, FALSE
);
2576 void client_close(ObClient
*self
)
2580 if (!(self
->functions
& OB_CLIENT_FUNC_CLOSE
)) return;
2582 /* in the case that the client provides no means to requesting that it
2583 close, we just kill it */
2584 if (!self
->delete_window
)
2588 XXX: itd be cool to do timeouts and shit here for killing the client's
2590 like... if the window is around after 5 seconds, then the close button
2591 turns a nice red, and if this function is called again, the client is
2595 ce
.xclient
.type
= ClientMessage
;
2596 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
2597 ce
.xclient
.display
= ob_display
;
2598 ce
.xclient
.window
= self
->window
;
2599 ce
.xclient
.format
= 32;
2600 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_delete_window
;
2601 ce
.xclient
.data
.l
[1] = event_curtime
;
2602 ce
.xclient
.data
.l
[2] = 0l;
2603 ce
.xclient
.data
.l
[3] = 0l;
2604 ce
.xclient
.data
.l
[4] = 0l;
2605 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
2608 void client_kill(ObClient
*self
)
2610 XKillClient(ob_display
, self
->window
);
2613 void client_hilite(ObClient
*self
, gboolean hilite
)
2615 /* don't allow focused windows to hilite */
2616 self
->demands_attention
= hilite
&& !client_focused(self
);
2617 if (self
->demands_attention
)
2618 frame_flash_start(self
->frame
);
2620 frame_flash_stop(self
->frame
);
2621 client_change_state(self
);
2624 void client_set_desktop_recursive(ObClient
*self
,
2625 guint target
, gboolean donthide
)
2630 if (target
!= self
->desktop
) {
2632 ob_debug("Setting desktop %u\n", target
+1);
2634 g_assert(target
< screen_num_desktops
|| target
== DESKTOP_ALL
);
2636 /* remove from the old desktop(s) */
2637 focus_order_remove(self
);
2639 old
= self
->desktop
;
2640 self
->desktop
= target
;
2641 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, target
);
2642 /* the frame can display the current desktop state */
2643 frame_adjust_state(self
->frame
);
2644 /* 'move' the window to the new desktop */
2646 client_showhide(self
);
2647 /* raise if it was not already on the desktop */
2648 if (old
!= DESKTOP_ALL
)
2650 if (STRUT_EXISTS(self
->strut
))
2651 screen_update_areas();
2653 /* add to the new desktop(s) */
2654 if (config_focus_new
)
2655 focus_order_to_top(self
);
2657 focus_order_to_bottom(self
);
2660 /* move all transients */
2661 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
2662 if (it
->data
!= self
) client_set_desktop_recursive(it
->data
,
2666 void client_set_desktop(ObClient
*self
, guint target
, gboolean donthide
)
2670 it
= client_search_top_transients(self
);
2672 for(; it
; it
= g_slist_next(it
))
2673 client_set_desktop_recursive(it
->data
, target
, donthide
);
2676 ObClient
*client_search_modal_child(ObClient
*self
)
2681 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
2682 ObClient
*c
= it
->data
;
2683 if ((ret
= client_search_modal_child(c
))) return ret
;
2684 if (c
->modal
) return c
;
2689 gboolean
client_validate(ObClient
*self
)
2693 XSync(ob_display
, FALSE
); /* get all events on the server */
2695 if (XCheckTypedWindowEvent(ob_display
, self
->window
, DestroyNotify
, &e
) ||
2696 XCheckTypedWindowEvent(ob_display
, self
->window
, UnmapNotify
, &e
)) {
2697 XPutBackEvent(ob_display
, &e
);
2704 void client_set_wm_state(ObClient
*self
, glong state
)
2706 if (state
== self
->wmstate
) return; /* no change */
2710 client_iconify(self
, TRUE
, TRUE
);
2713 client_iconify(self
, FALSE
, TRUE
);
2718 void client_set_state(ObClient
*self
, Atom action
, glong data1
, glong data2
)
2720 gboolean shaded
= self
->shaded
;
2721 gboolean fullscreen
= self
->fullscreen
;
2722 gboolean undecorated
= self
->undecorated
;
2723 gboolean max_horz
= self
->max_horz
;
2724 gboolean max_vert
= self
->max_vert
;
2725 gboolean modal
= self
->modal
;
2726 gboolean iconic
= self
->iconic
;
2727 gboolean demands_attention
= self
->demands_attention
;
2730 if (!(action
== prop_atoms
.net_wm_state_add
||
2731 action
== prop_atoms
.net_wm_state_remove
||
2732 action
== prop_atoms
.net_wm_state_toggle
))
2733 /* an invalid action was passed to the client message, ignore it */
2736 for (i
= 0; i
< 2; ++i
) {
2737 Atom state
= i
== 0 ? data1
: data2
;
2739 if (!state
) continue;
2741 /* if toggling, then pick whether we're adding or removing */
2742 if (action
== prop_atoms
.net_wm_state_toggle
) {
2743 if (state
== prop_atoms
.net_wm_state_modal
)
2744 action
= modal
? prop_atoms
.net_wm_state_remove
:
2745 prop_atoms
.net_wm_state_add
;
2746 else if (state
== prop_atoms
.net_wm_state_maximized_vert
)
2747 action
= self
->max_vert
? prop_atoms
.net_wm_state_remove
:
2748 prop_atoms
.net_wm_state_add
;
2749 else if (state
== prop_atoms
.net_wm_state_maximized_horz
)
2750 action
= self
->max_horz
? prop_atoms
.net_wm_state_remove
:
2751 prop_atoms
.net_wm_state_add
;
2752 else if (state
== prop_atoms
.net_wm_state_shaded
)
2753 action
= shaded
? prop_atoms
.net_wm_state_remove
:
2754 prop_atoms
.net_wm_state_add
;
2755 else if (state
== prop_atoms
.net_wm_state_skip_taskbar
)
2756 action
= self
->skip_taskbar
?
2757 prop_atoms
.net_wm_state_remove
:
2758 prop_atoms
.net_wm_state_add
;
2759 else if (state
== prop_atoms
.net_wm_state_skip_pager
)
2760 action
= self
->skip_pager
?
2761 prop_atoms
.net_wm_state_remove
:
2762 prop_atoms
.net_wm_state_add
;
2763 else if (state
== prop_atoms
.net_wm_state_hidden
)
2764 action
= self
->iconic
?
2765 prop_atoms
.net_wm_state_remove
:
2766 prop_atoms
.net_wm_state_add
;
2767 else if (state
== prop_atoms
.net_wm_state_fullscreen
)
2768 action
= fullscreen
?
2769 prop_atoms
.net_wm_state_remove
:
2770 prop_atoms
.net_wm_state_add
;
2771 else if (state
== prop_atoms
.net_wm_state_above
)
2772 action
= self
->above
? prop_atoms
.net_wm_state_remove
:
2773 prop_atoms
.net_wm_state_add
;
2774 else if (state
== prop_atoms
.net_wm_state_below
)
2775 action
= self
->below
? prop_atoms
.net_wm_state_remove
:
2776 prop_atoms
.net_wm_state_add
;
2777 else if (state
== prop_atoms
.net_wm_state_demands_attention
)
2778 action
= self
->demands_attention
?
2779 prop_atoms
.net_wm_state_remove
:
2780 prop_atoms
.net_wm_state_add
;
2781 else if (state
== prop_atoms
.ob_wm_state_undecorated
)
2782 action
= undecorated
? prop_atoms
.net_wm_state_remove
:
2783 prop_atoms
.net_wm_state_add
;
2786 if (action
== prop_atoms
.net_wm_state_add
) {
2787 if (state
== prop_atoms
.net_wm_state_modal
) {
2789 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
2791 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
2793 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
2795 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
2796 self
->skip_taskbar
= TRUE
;
2797 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
2798 self
->skip_pager
= TRUE
;
2799 } else if (state
== prop_atoms
.net_wm_state_hidden
) {
2801 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
2803 } else if (state
== prop_atoms
.net_wm_state_above
) {
2805 self
->below
= FALSE
;
2806 } else if (state
== prop_atoms
.net_wm_state_below
) {
2807 self
->above
= FALSE
;
2809 } else if (state
== prop_atoms
.net_wm_state_demands_attention
) {
2810 demands_attention
= TRUE
;
2811 } else if (state
== prop_atoms
.ob_wm_state_undecorated
) {
2815 } else { /* action == prop_atoms.net_wm_state_remove */
2816 if (state
== prop_atoms
.net_wm_state_modal
) {
2818 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
2820 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
2822 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
2824 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
2825 self
->skip_taskbar
= FALSE
;
2826 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
2827 self
->skip_pager
= FALSE
;
2828 } else if (state
== prop_atoms
.net_wm_state_hidden
) {
2830 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
2832 } else if (state
== prop_atoms
.net_wm_state_above
) {
2833 self
->above
= FALSE
;
2834 } else if (state
== prop_atoms
.net_wm_state_below
) {
2835 self
->below
= FALSE
;
2836 } else if (state
== prop_atoms
.net_wm_state_demands_attention
) {
2837 demands_attention
= FALSE
;
2838 } else if (state
== prop_atoms
.ob_wm_state_undecorated
) {
2839 undecorated
= FALSE
;
2843 if (max_horz
!= self
->max_horz
|| max_vert
!= self
->max_vert
) {
2844 if (max_horz
!= self
->max_horz
&& max_vert
!= self
->max_vert
) {
2846 if (max_horz
== max_vert
) { /* both going the same way */
2847 client_maximize(self
, max_horz
, 0, TRUE
);
2849 client_maximize(self
, max_horz
, 1, TRUE
);
2850 client_maximize(self
, max_vert
, 2, TRUE
);
2854 if (max_horz
!= self
->max_horz
)
2855 client_maximize(self
, max_horz
, 1, TRUE
);
2857 client_maximize(self
, max_vert
, 2, TRUE
);
2860 /* change fullscreen state before shading, as it will affect if the window
2862 if (fullscreen
!= self
->fullscreen
)
2863 client_fullscreen(self
, fullscreen
, TRUE
);
2864 if (shaded
!= self
->shaded
)
2865 client_shade(self
, shaded
);
2866 if (undecorated
!= self
->undecorated
)
2867 client_set_undecorated(self
, undecorated
);
2868 if (modal
!= self
->modal
) {
2869 self
->modal
= modal
;
2870 /* when a window changes modality, then its stacking order with its
2871 transients needs to change */
2874 if (iconic
!= self
->iconic
)
2875 client_iconify(self
, iconic
, FALSE
);
2877 if (demands_attention
!= self
->demands_attention
)
2878 client_hilite(self
, demands_attention
);
2880 client_change_state(self
); /* change the hint to reflect these changes */
2883 ObClient
*client_focus_target(ObClient
*self
)
2885 ObClient
*child
= NULL
;
2887 child
= client_search_modal_child(self
);
2888 if (child
) return child
;
2892 gboolean
client_can_focus(ObClient
*self
)
2896 /* choose the correct target */
2897 self
= client_focus_target(self
);
2899 if (!self
->frame
->visible
)
2902 if (!(self
->can_focus
|| self
->focus_notify
))
2905 /* do a check to see if the window has already been unmapped or destroyed
2906 do this intelligently while watching out for unmaps we've generated
2907 (ignore_unmaps > 0) */
2908 if (XCheckTypedWindowEvent(ob_display
, self
->window
,
2909 DestroyNotify
, &ev
)) {
2910 XPutBackEvent(ob_display
, &ev
);
2913 while (XCheckTypedWindowEvent(ob_display
, self
->window
,
2914 UnmapNotify
, &ev
)) {
2915 if (self
->ignore_unmaps
) {
2916 self
->ignore_unmaps
--;
2918 XPutBackEvent(ob_display
, &ev
);
2926 gboolean
client_focus(ObClient
*self
)
2928 /* choose the correct target */
2929 self
= client_focus_target(self
);
2931 if (!client_can_focus(self
)) {
2932 if (!self
->frame
->visible
) {
2933 /* update the focus lists */
2934 focus_order_to_top(self
);
2939 if (self
->can_focus
) {
2940 /* RevertToPointerRoot causes much more headache than RevertToNone, so
2941 I choose to use it always, hopefully to find errors quicker, if any
2942 are left. (I hate X. I hate focus events.)
2944 Update: Changing this to RevertToNone fixed a bug with mozilla (bug
2945 #799. So now it is RevertToNone again.
2947 XSetInputFocus(ob_display
, self
->window
, RevertToNone
,
2951 if (self
->focus_notify
) {
2953 ce
.xclient
.type
= ClientMessage
;
2954 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
2955 ce
.xclient
.display
= ob_display
;
2956 ce
.xclient
.window
= self
->window
;
2957 ce
.xclient
.format
= 32;
2958 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_take_focus
;
2959 ce
.xclient
.data
.l
[1] = event_curtime
;
2960 ce
.xclient
.data
.l
[2] = 0l;
2961 ce
.xclient
.data
.l
[3] = 0l;
2962 ce
.xclient
.data
.l
[4] = 0l;
2963 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
2967 ob_debug("%sively focusing %lx at %d\n",
2968 (self
->can_focus
? "act" : "pass"),
2969 self
->window
, (gint
) event_curtime
);
2972 /* Cause the FocusIn to come back to us. Important for desktop switches,
2973 since otherwise we'll have no FocusIn on the queue and send it off to
2974 the focus_backup. */
2975 XSync(ob_display
, FALSE
);
2979 /* Used when the current client is closed, focus_last will then prevent
2980 * focus from going to the mouse pointer */
2981 void client_unfocus(ObClient
*self
)
2983 if (focus_client
== self
) {
2985 ob_debug("client_unfocus for %lx\n", self
->window
);
2987 focus_fallback(OB_FOCUS_FALLBACK_CLOSED
);
2991 void client_activate(ObClient
*self
, gboolean here
, gboolean user
, Time time
)
2993 /* XXX do some stuff here if user is false to determine if we really want
2994 to activate it or not (a parent or group member is currently
2997 ob_debug("Want to activate window 0x%x with time %u (last time %u), "
2999 self
->window
, time
, client_last_user_time
,
3000 (user
? "user" : "application"));
3001 if (!user
&& time
&& time
< client_last_user_time
)
3002 client_hilite(self
, TRUE
);
3004 if (client_normal(self
) && screen_showing_desktop
)
3005 screen_show_desktop(FALSE
);
3007 client_iconify(self
, FALSE
, here
);
3008 if (self
->desktop
!= DESKTOP_ALL
&&
3009 self
->desktop
!= screen_desktop
) {
3011 client_set_desktop(self
, screen_desktop
, FALSE
);
3013 screen_set_desktop(self
->desktop
);
3014 } else if (!self
->frame
->visible
)
3015 /* if its not visible for other reasons, then don't mess
3019 client_shade(self
, FALSE
);
3023 /* we do this an action here. this is rather important. this is because
3024 we want the results from the focus change to take place BEFORE we go
3025 about raising the window. when a fullscreen window loses focus, we
3026 need this or else the raise wont be able to raise above the
3027 to-lose-focus fullscreen window. */
3032 void client_raise(ObClient
*self
)
3034 action_run_string("Raise", self
, CurrentTime
);
3037 void client_lower(ObClient
*self
)
3039 action_run_string("Lower", self
, CurrentTime
);
3042 gboolean
client_focused(ObClient
*self
)
3044 return self
== focus_client
;
3047 static ObClientIcon
* client_icon_recursive(ObClient
*self
, gint w
, gint h
)
3050 /* si is the smallest image >= req */
3051 /* li is the largest image < req */
3052 gulong size
, smallest
= 0xffffffff, largest
= 0, si
= 0, li
= 0;
3054 if (!self
->nicons
) {
3055 ObClientIcon
*parent
= NULL
;
3057 if (self
->transient_for
) {
3058 if (self
->transient_for
!= OB_TRAN_GROUP
)
3059 parent
= client_icon_recursive(self
->transient_for
, w
, h
);
3062 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
3063 ObClient
*c
= it
->data
;
3064 if (c
!= self
&& !c
->transient_for
) {
3065 if ((parent
= client_icon_recursive(c
, w
, h
)))
3075 for (i
= 0; i
< self
->nicons
; ++i
) {
3076 size
= self
->icons
[i
].width
* self
->icons
[i
].height
;
3077 if (size
< smallest
&& size
>= (unsigned)(w
* h
)) {
3081 if (size
> largest
&& size
<= (unsigned)(w
* h
)) {
3086 if (largest
== 0) /* didnt find one smaller than the requested size */
3087 return &self
->icons
[si
];
3088 return &self
->icons
[li
];
3091 const ObClientIcon
* client_icon(ObClient
*self
, gint w
, gint h
)
3094 static ObClientIcon deficon
;
3096 if (!(ret
= client_icon_recursive(self
, w
, h
))) {
3097 deficon
.width
= deficon
.height
= 48;
3098 deficon
.data
= ob_rr_theme
->def_win_icon
;
3104 /* this be mostly ripped from fvwm */
3105 ObClient
*client_find_directional(ObClient
*c
, ObDirection dir
)
3107 gint my_cx
, my_cy
, his_cx
, his_cy
;
3110 gint score
, best_score
;
3111 ObClient
*best_client
, *cur
;
3117 /* first, find the centre coords of the currently focused window */
3118 my_cx
= c
->frame
->area
.x
+ c
->frame
->area
.width
/ 2;
3119 my_cy
= c
->frame
->area
.y
+ c
->frame
->area
.height
/ 2;
3124 for(it
= g_list_first(client_list
); it
; it
= g_list_next(it
)) {
3127 /* the currently selected window isn't interesting */
3130 if (!client_normal(cur
))
3132 /* using c->desktop instead of screen_desktop doesn't work if the
3133 * current window was omnipresent, hope this doesn't have any other
3135 if(screen_desktop
!= cur
->desktop
&& cur
->desktop
!= DESKTOP_ALL
)
3139 if(!(client_focus_target(cur
) == cur
&&
3140 client_can_focus(cur
)))
3143 /* find the centre coords of this window, from the
3144 * currently focused window's point of view */
3145 his_cx
= (cur
->frame
->area
.x
- my_cx
)
3146 + cur
->frame
->area
.width
/ 2;
3147 his_cy
= (cur
->frame
->area
.y
- my_cy
)
3148 + cur
->frame
->area
.height
/ 2;
3150 if(dir
== OB_DIRECTION_NORTHEAST
|| dir
== OB_DIRECTION_SOUTHEAST
||
3151 dir
== OB_DIRECTION_SOUTHWEST
|| dir
== OB_DIRECTION_NORTHWEST
) {
3153 /* Rotate the diagonals 45 degrees counterclockwise.
3154 * To do this, multiply the matrix /+h +h\ with the
3155 * vector (x y). \-h +h/
3156 * h = sqrt(0.5). We can set h := 1 since absolute
3157 * distance doesn't matter here. */
3158 tx
= his_cx
+ his_cy
;
3159 his_cy
= -his_cx
+ his_cy
;
3164 case OB_DIRECTION_NORTH
:
3165 case OB_DIRECTION_SOUTH
:
3166 case OB_DIRECTION_NORTHEAST
:
3167 case OB_DIRECTION_SOUTHWEST
:
3168 offset
= (his_cx
< 0) ? -his_cx
: his_cx
;
3169 distance
= ((dir
== OB_DIRECTION_NORTH
||
3170 dir
== OB_DIRECTION_NORTHEAST
) ?
3173 case OB_DIRECTION_EAST
:
3174 case OB_DIRECTION_WEST
:
3175 case OB_DIRECTION_SOUTHEAST
:
3176 case OB_DIRECTION_NORTHWEST
:
3177 offset
= (his_cy
< 0) ? -his_cy
: his_cy
;
3178 distance
= ((dir
== OB_DIRECTION_WEST
||
3179 dir
== OB_DIRECTION_NORTHWEST
) ?
3184 /* the target must be in the requested direction */
3188 /* Calculate score for this window. The smaller the better. */
3189 score
= distance
+ offset
;
3191 /* windows more than 45 degrees off the direction are
3192 * heavily penalized and will only be chosen if nothing
3193 * else within a million pixels */
3194 if(offset
> distance
)
3197 if(best_score
== -1 || score
< best_score
)
3205 void client_set_layer(ObClient
*self
, gint layer
)
3209 self
->above
= FALSE
;
3210 } else if (layer
== 0) {
3211 self
->below
= self
->above
= FALSE
;
3213 self
->below
= FALSE
;
3216 client_calc_layer(self
);
3217 client_change_state(self
); /* reflect this in the state hints */
3220 void client_set_undecorated(ObClient
*self
, gboolean undecorated
)
3222 if (self
->undecorated
!= undecorated
) {
3223 self
->undecorated
= undecorated
;
3224 client_setup_decor_and_functions(self
);
3225 /* Make sure the client knows it might have moved. Maybe there is a
3226 * better way of doing this so only one client_configure is sent, but
3227 * since 125 of these are sent per second when moving the window (with
3228 * user = FALSE) i doubt it matters much.
3230 client_configure(self
, OB_CORNER_TOPLEFT
, self
->area
.x
, self
->area
.y
,
3231 self
->area
.width
, self
->area
.height
, TRUE
, TRUE
);
3232 client_change_state(self
); /* reflect this in the state hints */
3236 guint
client_monitor(ObClient
*self
)
3238 return screen_find_monitor(&self
->frame
->area
);
3241 GSList
*client_search_top_transients(ObClient
*self
)
3245 /* move up the direct transient chain as far as possible */
3246 while (self
->transient_for
&& self
->transient_for
!= OB_TRAN_GROUP
)
3247 self
= self
->transient_for
;
3249 if (!self
->transient_for
)
3250 ret
= g_slist_prepend(ret
, self
);
3254 g_assert(self
->group
);
3256 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
3257 ObClient
*c
= it
->data
;
3259 if (!c
->transient_for
)
3260 ret
= g_slist_prepend(ret
, c
);
3263 if (ret
== NULL
) /* no group parents */
3264 ret
= g_slist_prepend(ret
, self
);
3270 ObClient
*client_search_focus_parent(ObClient
*self
)
3272 if (self
->transient_for
) {
3273 if (self
->transient_for
!= OB_TRAN_GROUP
) {
3274 if (client_focused(self
->transient_for
))
3275 return self
->transient_for
;
3279 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
3280 ObClient
*c
= it
->data
;
3282 /* checking transient_for prevents infinate loops! */
3283 if (c
!= self
&& !c
->transient_for
)
3284 if (client_focused(c
))
3293 ObClient
*client_search_parent(ObClient
*self
, ObClient
*search
)
3295 if (self
->transient_for
) {
3296 if (self
->transient_for
!= OB_TRAN_GROUP
) {
3297 if (self
->transient_for
== search
)
3302 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
3303 ObClient
*c
= it
->data
;
3305 /* checking transient_for prevents infinate loops! */
3306 if (c
!= self
&& !c
->transient_for
)
3316 ObClient
*client_search_transient(ObClient
*self
, ObClient
*search
)
3320 for (sit
= self
->transients
; sit
; sit
= g_slist_next(sit
)) {
3321 if (sit
->data
== search
)
3323 if (client_search_transient(sit
->data
, search
))
3329 void client_update_sm_client_id(ObClient
*self
)
3331 g_free(self
->sm_client_id
);
3332 self
->sm_client_id
= NULL
;
3334 if (!PROP_GETS(self
->window
, sm_client_id
, locale
, &self
->sm_client_id
) &&
3336 PROP_GETS(self
->group
->leader
, sm_client_id
, locale
,
3337 &self
->sm_client_id
);
3340 #define WANT_EDGE(cur, c) \
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 #define HIT_EDGE(my_edge_start, my_edge_end, his_edge_start, his_edge_end) \
3353 if ((his_edge_start >= my_edge_start && \
3354 his_edge_start <= my_edge_end) || \
3355 (my_edge_start >= his_edge_start && \
3356 my_edge_start <= his_edge_end)) \
3359 /* finds the nearest edge in the given direction from the current client
3360 * note to self: the edge is the -frame- edge (the actual one), not the
3363 gint
client_directional_edge_search(ObClient
*c
, ObDirection dir
, gboolean hang
)
3365 gint dest
, monitor_dest
;
3366 gint my_edge_start
, my_edge_end
, my_offset
;
3373 a
= screen_area(c
->desktop
);
3374 monitor
= screen_area_monitor(c
->desktop
, client_monitor(c
));
3377 case OB_DIRECTION_NORTH
:
3378 my_edge_start
= c
->frame
->area
.x
;
3379 my_edge_end
= c
->frame
->area
.x
+ c
->frame
->area
.width
;
3380 my_offset
= c
->frame
->area
.y
+ (hang
? c
->frame
->area
.height
: 0);
3382 /* default: top of screen */
3383 dest
= a
->y
+ (hang
? c
->frame
->area
.height
: 0);
3384 monitor_dest
= monitor
->y
+ (hang
? c
->frame
->area
.height
: 0);
3385 /* if the monitor edge comes before the screen edge, */
3386 /* use that as the destination instead. (For xinerama) */
3387 if (monitor_dest
!= dest
&& my_offset
> monitor_dest
)
3388 dest
= monitor_dest
;
3390 for(it
= client_list
; it
&& my_offset
!= dest
; it
= g_list_next(it
)) {
3391 gint his_edge_start
, his_edge_end
, his_offset
;
3392 ObClient
*cur
= it
->data
;
3396 his_edge_start
= cur
->frame
->area
.x
;
3397 his_edge_end
= cur
->frame
->area
.x
+ cur
->frame
->area
.width
;
3398 his_offset
= cur
->frame
->area
.y
+
3399 (hang
? 0 : cur
->frame
->area
.height
);
3401 if(his_offset
+ 1 > my_offset
)
3404 if(his_offset
< dest
)
3407 HIT_EDGE(my_edge_start
, my_edge_end
, his_edge_start
, his_edge_end
)
3410 case OB_DIRECTION_SOUTH
:
3411 my_edge_start
= c
->frame
->area
.x
;
3412 my_edge_end
= c
->frame
->area
.x
+ c
->frame
->area
.width
;
3413 my_offset
= c
->frame
->area
.y
+ (hang
? 0 : c
->frame
->area
.height
);
3415 /* default: bottom of screen */
3416 dest
= a
->y
+ a
->height
- (hang
? c
->frame
->area
.height
: 0);
3417 monitor_dest
= monitor
->y
+ monitor
->height
-
3418 (hang
? c
->frame
->area
.height
: 0);
3419 /* if the monitor edge comes before the screen edge, */
3420 /* use that as the destination instead. (For xinerama) */
3421 if (monitor_dest
!= dest
&& my_offset
< monitor_dest
)
3422 dest
= monitor_dest
;
3424 for(it
= client_list
; it
&& my_offset
!= dest
; it
= g_list_next(it
)) {
3425 gint his_edge_start
, his_edge_end
, his_offset
;
3426 ObClient
*cur
= it
->data
;
3430 his_edge_start
= cur
->frame
->area
.x
;
3431 his_edge_end
= cur
->frame
->area
.x
+ cur
->frame
->area
.width
;
3432 his_offset
= cur
->frame
->area
.y
+
3433 (hang
? cur
->frame
->area
.height
: 0);
3436 if(his_offset
- 1 < my_offset
)
3439 if(his_offset
> dest
)
3442 HIT_EDGE(my_edge_start
, my_edge_end
, his_edge_start
, his_edge_end
)
3445 case OB_DIRECTION_WEST
:
3446 my_edge_start
= c
->frame
->area
.y
;
3447 my_edge_end
= c
->frame
->area
.y
+ c
->frame
->area
.height
;
3448 my_offset
= c
->frame
->area
.x
+ (hang
? c
->frame
->area
.width
: 0);
3450 /* default: leftmost egde of screen */
3451 dest
= a
->x
+ (hang
? c
->frame
->area
.width
: 0);
3452 monitor_dest
= monitor
->x
+ (hang
? c
->frame
->area
.width
: 0);
3453 /* if the monitor edge comes before the screen edge, */
3454 /* use that as the destination instead. (For xinerama) */
3455 if (monitor_dest
!= dest
&& my_offset
> monitor_dest
)
3456 dest
= monitor_dest
;
3458 for(it
= client_list
; it
&& my_offset
!= dest
; it
= g_list_next(it
)) {
3459 gint his_edge_start
, his_edge_end
, his_offset
;
3460 ObClient
*cur
= it
->data
;
3464 his_edge_start
= cur
->frame
->area
.y
;
3465 his_edge_end
= cur
->frame
->area
.y
+ cur
->frame
->area
.height
;
3466 his_offset
= cur
->frame
->area
.x
+
3467 (hang
? 0 : cur
->frame
->area
.width
);
3469 if(his_offset
+ 1 > my_offset
)
3472 if(his_offset
< dest
)
3475 HIT_EDGE(my_edge_start
, my_edge_end
, his_edge_start
, his_edge_end
)
3478 case OB_DIRECTION_EAST
:
3479 my_edge_start
= c
->frame
->area
.y
;
3480 my_edge_end
= c
->frame
->area
.y
+ c
->frame
->area
.height
;
3481 my_offset
= c
->frame
->area
.x
+ (hang
? 0 : c
->frame
->area
.width
);
3483 /* default: rightmost edge of screen */
3484 dest
= a
->x
+ a
->width
- (hang
? c
->frame
->area
.width
: 0);
3485 monitor_dest
= monitor
->x
+ monitor
->width
-
3486 (hang
? c
->frame
->area
.width
: 0);
3487 /* if the monitor edge comes before the screen edge, */
3488 /* use that as the destination instead. (For xinerama) */
3489 if (monitor_dest
!= dest
&& my_offset
< monitor_dest
)
3490 dest
= monitor_dest
;
3492 for(it
= client_list
; it
&& my_offset
!= dest
; it
= g_list_next(it
)) {
3493 gint his_edge_start
, his_edge_end
, his_offset
;
3494 ObClient
*cur
= it
->data
;
3498 his_edge_start
= cur
->frame
->area
.y
;
3499 his_edge_end
= cur
->frame
->area
.y
+ cur
->frame
->area
.height
;
3500 his_offset
= cur
->frame
->area
.x
+
3501 (hang
? cur
->frame
->area
.width
: 0);
3503 if(his_offset
- 1 < my_offset
)
3506 if(his_offset
> dest
)
3509 HIT_EDGE(my_edge_start
, my_edge_end
, his_edge_start
, his_edge_end
)
3512 case OB_DIRECTION_NORTHEAST
:
3513 case OB_DIRECTION_SOUTHEAST
:
3514 case OB_DIRECTION_NORTHWEST
:
3515 case OB_DIRECTION_SOUTHWEST
:
3516 /* not implemented */
3518 g_assert_not_reached();
3519 dest
= 0; /* suppress warning */
3524 ObClient
* client_under_pointer()
3528 ObClient
*ret
= NULL
;
3530 if (screen_pointer_pos(&x
, &y
)) {
3531 for (it
= stacking_list
; it
; it
= g_list_next(it
)) {
3532 if (WINDOW_IS_CLIENT(it
->data
)) {
3533 ObClient
*c
= WINDOW_AS_CLIENT(it
->data
);
3534 if (c
->frame
->visible
&&
3535 RECT_CONTAINS(c
->frame
->area
, x
, y
)) {
3545 gboolean
client_has_group_siblings(ObClient
*self
)
3547 return self
->group
&& self
->group
->members
->next
;