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-2007 Dana 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 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
2008 client_calc_layer_recursive(it
->data
, orig
,
2010 raised
? raised
: self
->layer
!= old
);
2012 if (!raised
&& self
->layer
!= old
)
2013 if (orig
->frame
) { /* only restack if the original window is managed */
2014 stacking_remove(CLIENT_AS_WINDOW(self
));
2015 stacking_add(CLIENT_AS_WINDOW(self
));
2019 void client_calc_layer(ObClient
*self
)
2026 /* transients take on the layer of their parents */
2027 it
= client_search_top_transients(self
);
2029 for (; it
; it
= g_slist_next(it
))
2030 client_calc_layer_recursive(it
->data
, orig
, 0, FALSE
);
2033 gboolean
client_should_show(ObClient
*self
)
2037 if (client_normal(self
) && screen_showing_desktop
)
2040 if (self->transient_for) {
2041 if (self->transient_for != OB_TRAN_GROUP)
2042 return client_should_show(self->transient_for);
2046 for (it = self->group->members; it; it = g_slist_next(it)) {
2047 ObClient *c = it->data;
2048 if (c != self && !c->transient_for) {
2049 if (client_should_show(c))
2056 if (self
->desktop
== screen_desktop
|| self
->desktop
== DESKTOP_ALL
)
2062 static void client_showhide(ObClient
*self
)
2065 if (client_should_show(self
))
2066 frame_show(self
->frame
);
2068 frame_hide(self
->frame
);
2071 gboolean
client_normal(ObClient
*self
) {
2072 return ! (self
->type
== OB_CLIENT_TYPE_DESKTOP
||
2073 self
->type
== OB_CLIENT_TYPE_DOCK
||
2074 self
->type
== OB_CLIENT_TYPE_SPLASH
);
2077 static void client_apply_startup_state(ObClient
*self
)
2079 /* these are in a carefully crafted order.. */
2082 self
->iconic
= FALSE
;
2083 client_iconify(self
, TRUE
, FALSE
);
2085 if (self
->fullscreen
) {
2086 self
->fullscreen
= FALSE
;
2087 client_fullscreen(self
, TRUE
, FALSE
);
2089 if (self
->undecorated
) {
2090 self
->undecorated
= FALSE
;
2091 client_set_undecorated(self
, TRUE
);
2094 self
->shaded
= FALSE
;
2095 client_shade(self
, TRUE
);
2097 if (self
->demands_attention
) {
2098 self
->demands_attention
= FALSE
;
2099 client_hilite(self
, TRUE
);
2102 if (self
->max_vert
&& self
->max_horz
) {
2103 self
->max_vert
= self
->max_horz
= FALSE
;
2104 client_maximize(self
, TRUE
, 0, FALSE
);
2105 } else if (self
->max_vert
) {
2106 self
->max_vert
= FALSE
;
2107 client_maximize(self
, TRUE
, 2, FALSE
);
2108 } else if (self
->max_horz
) {
2109 self
->max_horz
= FALSE
;
2110 client_maximize(self
, TRUE
, 1, FALSE
);
2113 /* nothing to do for the other states:
2122 void client_configure_full(ObClient
*self
, ObCorner anchor
,
2123 gint x
, gint y
, gint w
, gint h
,
2124 gboolean user
, gboolean final
,
2125 gboolean force_reply
)
2128 gboolean send_resize_client
;
2129 gboolean moved
= FALSE
, resized
= FALSE
;
2130 guint fdecor
= self
->frame
->decorations
;
2131 gboolean fhorz
= self
->frame
->max_horz
;
2132 Rect desired_area
= {x
, y
, w
, h
};
2134 /* make the frame recalculate its dimentions n shit without changing
2135 anything visible for real, this way the constraints below can work with
2136 the updated frame dimensions. */
2137 frame_adjust_area(self
->frame
, TRUE
, TRUE
, TRUE
);
2139 /* gets the frame's position */
2140 frame_client_gravity(self
->frame
, &x
, &y
);
2142 /* these positions are frame positions, not client positions */
2144 /* set the size and position if fullscreen */
2145 if (self
->fullscreen
) {
2149 i
= screen_find_monitor(&desired_area
);
2150 a
= screen_physical_area_monitor(i
);
2157 user
= FALSE
; /* ignore that increment etc shit when in fullscreen */
2162 i
= screen_find_monitor(&desired_area
);
2163 a
= screen_area_monitor(self
->desktop
, i
);
2165 /* set the size and position if maximized */
2166 if (self
->max_horz
) {
2168 w
= a
->width
- self
->frame
->size
.left
- self
->frame
->size
.right
;
2170 if (self
->max_vert
) {
2172 h
= a
->height
- self
->frame
->size
.top
- self
->frame
->size
.bottom
;
2176 /* gets the client's position */
2177 frame_frame_gravity(self
->frame
, &x
, &y
);
2179 /* these override the above states! if you cant move you can't move! */
2181 if (!(self
->functions
& OB_CLIENT_FUNC_MOVE
)) {
2185 if (!(self
->functions
& OB_CLIENT_FUNC_RESIZE
)) {
2186 w
= self
->area
.width
;
2187 h
= self
->area
.height
;
2191 if (!(w
== self
->area
.width
&& h
== self
->area
.height
)) {
2192 gint basew
, baseh
, minw
, minh
;
2194 /* base size is substituted with min size if not specified */
2195 if (self
->base_size
.width
|| self
->base_size
.height
) {
2196 basew
= self
->base_size
.width
;
2197 baseh
= self
->base_size
.height
;
2199 basew
= self
->min_size
.width
;
2200 baseh
= self
->min_size
.height
;
2202 /* min size is substituted with base size if not specified */
2203 if (self
->min_size
.width
|| self
->min_size
.height
) {
2204 minw
= self
->min_size
.width
;
2205 minh
= self
->min_size
.height
;
2207 minw
= self
->base_size
.width
;
2208 minh
= self
->base_size
.height
;
2211 /* if this is a user-requested resize, then check against min/max
2214 /* smaller than min size or bigger than max size? */
2215 if (w
> self
->max_size
.width
) w
= self
->max_size
.width
;
2216 if (w
< minw
) w
= minw
;
2217 if (h
> self
->max_size
.height
) h
= self
->max_size
.height
;
2218 if (h
< minh
) h
= minh
;
2223 /* keep to the increments */
2224 w
/= self
->size_inc
.width
;
2225 h
/= self
->size_inc
.height
;
2227 /* you cannot resize to nothing */
2228 if (basew
+ w
< 1) w
= 1 - basew
;
2229 if (baseh
+ h
< 1) h
= 1 - baseh
;
2231 /* store the logical size */
2232 SIZE_SET(self
->logical_size
,
2233 self
->size_inc
.width
> 1 ? w
: w
+ basew
,
2234 self
->size_inc
.height
> 1 ? h
: h
+ baseh
);
2236 w
*= self
->size_inc
.width
;
2237 h
*= self
->size_inc
.height
;
2242 /* adjust the height to match the width for the aspect ratios.
2243 for this, min size is not substituted for base size ever. */
2244 w
-= self
->base_size
.width
;
2245 h
-= self
->base_size
.height
;
2247 if (!self
->fullscreen
) {
2248 if (self
->min_ratio
)
2249 if (h
* self
->min_ratio
> w
) {
2250 h
= (gint
)(w
/ self
->min_ratio
);
2252 /* you cannot resize to nothing */
2255 w
= (gint
)(h
* self
->min_ratio
);
2258 if (self
->max_ratio
)
2259 if (h
* self
->max_ratio
< w
) {
2260 h
= (gint
)(w
/ self
->max_ratio
);
2262 /* you cannot resize to nothing */
2265 w
= (gint
)(h
* self
->min_ratio
);
2270 w
+= self
->base_size
.width
;
2271 h
+= self
->base_size
.height
;
2278 case OB_CORNER_TOPLEFT
:
2280 case OB_CORNER_TOPRIGHT
:
2281 x
-= w
- self
->area
.width
;
2283 case OB_CORNER_BOTTOMLEFT
:
2284 y
-= h
- self
->area
.height
;
2286 case OB_CORNER_BOTTOMRIGHT
:
2287 x
-= w
- self
->area
.width
;
2288 y
-= h
- self
->area
.height
;
2292 moved
= x
!= self
->area
.x
|| y
!= self
->area
.y
;
2293 resized
= w
!= self
->area
.width
|| h
!= self
->area
.height
;
2295 oldw
= self
->area
.width
;
2296 oldh
= self
->area
.height
;
2297 RECT_SET(self
->area
, x
, y
, w
, h
);
2299 /* for app-requested resizes, always resize if 'resized' is true.
2300 for user-requested ones, only resize if final is true, or when
2301 resizing in redraw mode */
2302 send_resize_client
= ((!user
&& resized
) ||
2304 (resized
&& config_resize_redraw
))));
2306 /* if the client is enlarging, then resize the client before the frame */
2307 if (send_resize_client
&& user
&& (w
> oldw
|| h
> oldh
))
2308 XResizeWindow(ob_display
, self
->window
, MAX(w
, oldw
), MAX(h
, oldh
));
2310 /* move/resize the frame to match the request */
2312 if (self
->decorations
!= fdecor
|| self
->max_horz
!= fhorz
)
2313 moved
= resized
= TRUE
;
2315 if (moved
|| resized
)
2316 frame_adjust_area(self
->frame
, moved
, resized
, FALSE
);
2318 if (!resized
&& (force_reply
|| ((!user
&& moved
) || (user
&& final
))))
2321 event
.type
= ConfigureNotify
;
2322 event
.xconfigure
.display
= ob_display
;
2323 event
.xconfigure
.event
= self
->window
;
2324 event
.xconfigure
.window
= self
->window
;
2326 /* root window real coords */
2327 event
.xconfigure
.x
= self
->frame
->area
.x
+ self
->frame
->size
.left
-
2329 event
.xconfigure
.y
= self
->frame
->area
.y
+ self
->frame
->size
.top
-
2331 event
.xconfigure
.width
= w
;
2332 event
.xconfigure
.height
= h
;
2333 event
.xconfigure
.border_width
= 0;
2334 event
.xconfigure
.above
= self
->frame
->plate
;
2335 event
.xconfigure
.override_redirect
= FALSE
;
2336 XSendEvent(event
.xconfigure
.display
, event
.xconfigure
.window
,
2337 FALSE
, StructureNotifyMask
, &event
);
2341 /* if the client is shrinking, then resize the frame before the client */
2342 if (send_resize_client
&& (!user
|| (w
<= oldw
|| h
<= oldh
)))
2343 XResizeWindow(ob_display
, self
->window
, w
, h
);
2348 void client_fullscreen(ObClient
*self
, gboolean fs
, gboolean savearea
)
2352 if (!(self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
) || /* can't */
2353 self
->fullscreen
== fs
) return; /* already done */
2355 self
->fullscreen
= fs
;
2356 client_change_state(self
); /* change the state hints on the client */
2357 client_calc_layer(self
); /* and adjust out layer/stacking */
2361 self
->pre_fullscreen_area
= self
->area
;
2363 /* these are not actually used cuz client_configure will set them
2364 as appropriate when the window is fullscreened */
2369 if (self
->pre_fullscreen_area
.width
> 0 &&
2370 self
->pre_fullscreen_area
.height
> 0)
2372 x
= self
->pre_fullscreen_area
.x
;
2373 y
= self
->pre_fullscreen_area
.y
;
2374 w
= self
->pre_fullscreen_area
.width
;
2375 h
= self
->pre_fullscreen_area
.height
;
2376 RECT_SET(self
->pre_fullscreen_area
, 0, 0, 0, 0);
2378 /* pick some fallbacks... */
2379 a
= screen_area_monitor(self
->desktop
, 0);
2380 x
= a
->x
+ a
->width
/ 4;
2381 y
= a
->y
+ a
->height
/ 4;
2387 client_setup_decor_and_functions(self
);
2389 client_move_resize(self
, x
, y
, w
, h
);
2391 /* try focus us when we go into fullscreen mode */
2395 static void client_iconify_recursive(ObClient
*self
,
2396 gboolean iconic
, gboolean curdesk
)
2399 gboolean changed
= FALSE
;
2402 if (self
->iconic
!= iconic
) {
2403 ob_debug("%sconifying window: 0x%lx\n", (iconic
? "I" : "Uni"),
2406 self
->iconic
= iconic
;
2409 if (self
->functions
& OB_CLIENT_FUNC_ICONIFY
) {
2412 old
= self
->wmstate
;
2413 self
->wmstate
= IconicState
;
2414 if (old
!= self
->wmstate
)
2415 PROP_MSG(self
->window
, kde_wm_change_state
,
2416 self
->wmstate
, 1, 0, 0);
2418 /* update the focus lists.. iconic windows go to the bottom of
2419 the list, put the new iconic window at the 'top of the
2421 focus_order_to_top(self
);
2429 client_set_desktop(self
, screen_desktop
, FALSE
);
2431 old
= self
->wmstate
;
2432 self
->wmstate
= self
->shaded
? IconicState
: NormalState
;
2433 if (old
!= self
->wmstate
)
2434 PROP_MSG(self
->window
, kde_wm_change_state
,
2435 self
->wmstate
, 1, 0, 0);
2437 /* this puts it after the current focused window */
2438 focus_order_remove(self
);
2439 focus_order_add_new(self
);
2446 client_change_state(self
);
2447 client_showhide(self
);
2448 if (STRUT_EXISTS(self
->strut
))
2449 screen_update_areas();
2452 /* iconify all transients */
2453 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
2454 if (it
->data
!= self
) client_iconify_recursive(it
->data
,
2458 void client_iconify(ObClient
*self
, gboolean iconic
, gboolean curdesk
)
2462 /* move up the transient chain as far as possible first */
2463 it
= client_search_top_transients(self
);
2465 for (; it
; it
= g_slist_next(it
))
2466 client_iconify_recursive(it
->data
, iconic
, curdesk
);
2469 void client_maximize(ObClient
*self
, gboolean max
, gint dir
, gboolean savearea
)
2473 g_assert(dir
== 0 || dir
== 1 || dir
== 2);
2474 if (!(self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
)) return; /* can't */
2476 /* check if already done */
2478 if (dir
== 0 && self
->max_horz
&& self
->max_vert
) return;
2479 if (dir
== 1 && self
->max_horz
) return;
2480 if (dir
== 2 && self
->max_vert
) return;
2482 if (dir
== 0 && !self
->max_horz
&& !self
->max_vert
) return;
2483 if (dir
== 1 && !self
->max_horz
) return;
2484 if (dir
== 2 && !self
->max_vert
) return;
2487 /* we just tell it to configure in the same place and client_configure
2488 worries about filling the screen with the window */
2491 w
= self
->area
.width
;
2492 h
= self
->area
.height
;
2496 if ((dir
== 0 || dir
== 1) && !self
->max_horz
) { /* horz */
2497 RECT_SET(self
->pre_max_area
,
2498 self
->area
.x
, self
->pre_max_area
.y
,
2499 self
->area
.width
, self
->pre_max_area
.height
);
2501 if ((dir
== 0 || dir
== 2) && !self
->max_vert
) { /* vert */
2502 RECT_SET(self
->pre_max_area
,
2503 self
->pre_max_area
.x
, self
->area
.y
,
2504 self
->pre_max_area
.width
, self
->area
.height
);
2510 a
= screen_area_monitor(self
->desktop
, 0);
2511 if ((dir
== 0 || dir
== 1) && self
->max_horz
) { /* horz */
2512 if (self
->pre_max_area
.width
> 0) {
2513 x
= self
->pre_max_area
.x
;
2514 w
= self
->pre_max_area
.width
;
2516 RECT_SET(self
->pre_max_area
, 0, self
->pre_max_area
.y
,
2517 0, self
->pre_max_area
.height
);
2519 /* pick some fallbacks... */
2520 x
= a
->x
+ a
->width
/ 4;
2524 if ((dir
== 0 || dir
== 2) && self
->max_vert
) { /* vert */
2525 if (self
->pre_max_area
.height
> 0) {
2526 y
= self
->pre_max_area
.y
;
2527 h
= self
->pre_max_area
.height
;
2529 RECT_SET(self
->pre_max_area
, self
->pre_max_area
.x
, 0,
2530 self
->pre_max_area
.width
, 0);
2532 /* pick some fallbacks... */
2533 y
= a
->y
+ a
->height
/ 4;
2539 if (dir
== 0 || dir
== 1) /* horz */
2540 self
->max_horz
= max
;
2541 if (dir
== 0 || dir
== 2) /* vert */
2542 self
->max_vert
= max
;
2544 client_change_state(self
); /* change the state hints on the client */
2546 client_setup_decor_and_functions(self
);
2548 client_move_resize(self
, x
, y
, w
, h
);
2551 void client_shade(ObClient
*self
, gboolean shade
)
2553 if ((!(self
->functions
& OB_CLIENT_FUNC_SHADE
) &&
2554 shade
) || /* can't shade */
2555 self
->shaded
== shade
) return; /* already done */
2557 /* when we're iconic, don't change the wmstate */
2558 if (!self
->iconic
) {
2561 old
= self
->wmstate
;
2562 self
->wmstate
= shade
? IconicState
: NormalState
;
2563 if (old
!= self
->wmstate
)
2564 PROP_MSG(self
->window
, kde_wm_change_state
,
2565 self
->wmstate
, 1, 0, 0);
2568 self
->shaded
= shade
;
2569 client_change_state(self
);
2570 /* resize the frame to just the titlebar */
2571 frame_adjust_area(self
->frame
, FALSE
, FALSE
, FALSE
);
2574 void client_close(ObClient
*self
)
2578 if (!(self
->functions
& OB_CLIENT_FUNC_CLOSE
)) return;
2580 /* in the case that the client provides no means to requesting that it
2581 close, we just kill it */
2582 if (!self
->delete_window
)
2586 XXX: itd be cool to do timeouts and shit here for killing the client's
2588 like... if the window is around after 5 seconds, then the close button
2589 turns a nice red, and if this function is called again, the client is
2593 ce
.xclient
.type
= ClientMessage
;
2594 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
2595 ce
.xclient
.display
= ob_display
;
2596 ce
.xclient
.window
= self
->window
;
2597 ce
.xclient
.format
= 32;
2598 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_delete_window
;
2599 ce
.xclient
.data
.l
[1] = event_curtime
;
2600 ce
.xclient
.data
.l
[2] = 0l;
2601 ce
.xclient
.data
.l
[3] = 0l;
2602 ce
.xclient
.data
.l
[4] = 0l;
2603 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
2606 void client_kill(ObClient
*self
)
2608 XKillClient(ob_display
, self
->window
);
2611 void client_hilite(ObClient
*self
, gboolean hilite
)
2613 /* don't allow focused windows to hilite */
2614 self
->demands_attention
= hilite
&& !client_focused(self
);
2615 if (self
->demands_attention
)
2616 frame_flash_start(self
->frame
);
2618 frame_flash_stop(self
->frame
);
2619 client_change_state(self
);
2622 void client_set_desktop_recursive(ObClient
*self
,
2623 guint target
, gboolean donthide
)
2628 if (target
!= self
->desktop
) {
2630 ob_debug("Setting desktop %u\n", target
+1);
2632 g_assert(target
< screen_num_desktops
|| target
== DESKTOP_ALL
);
2634 /* remove from the old desktop(s) */
2635 focus_order_remove(self
);
2637 old
= self
->desktop
;
2638 self
->desktop
= target
;
2639 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, target
);
2640 /* the frame can display the current desktop state */
2641 frame_adjust_state(self
->frame
);
2642 /* 'move' the window to the new desktop */
2644 client_showhide(self
);
2645 /* raise if it was not already on the desktop */
2646 if (old
!= DESKTOP_ALL
)
2648 if (STRUT_EXISTS(self
->strut
))
2649 screen_update_areas();
2651 /* add to the new desktop(s) */
2652 if (config_focus_new
)
2653 focus_order_to_top(self
);
2655 focus_order_to_bottom(self
);
2658 /* move all transients */
2659 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
2660 if (it
->data
!= self
) client_set_desktop_recursive(it
->data
,
2664 void client_set_desktop(ObClient
*self
, guint target
, gboolean donthide
)
2668 it
= client_search_top_transients(self
);
2670 for(; it
; it
= g_slist_next(it
))
2671 client_set_desktop_recursive(it
->data
, target
, donthide
);
2674 ObClient
*client_search_modal_child(ObClient
*self
)
2679 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
2680 ObClient
*c
= it
->data
;
2681 if ((ret
= client_search_modal_child(c
))) return ret
;
2682 if (c
->modal
) return c
;
2687 gboolean
client_validate(ObClient
*self
)
2691 XSync(ob_display
, FALSE
); /* get all events on the server */
2693 if (XCheckTypedWindowEvent(ob_display
, self
->window
, DestroyNotify
, &e
) ||
2694 XCheckTypedWindowEvent(ob_display
, self
->window
, UnmapNotify
, &e
)) {
2695 XPutBackEvent(ob_display
, &e
);
2702 void client_set_wm_state(ObClient
*self
, glong state
)
2704 if (state
== self
->wmstate
) return; /* no change */
2708 client_iconify(self
, TRUE
, TRUE
);
2711 client_iconify(self
, FALSE
, TRUE
);
2716 void client_set_state(ObClient
*self
, Atom action
, glong data1
, glong data2
)
2718 gboolean shaded
= self
->shaded
;
2719 gboolean fullscreen
= self
->fullscreen
;
2720 gboolean undecorated
= self
->undecorated
;
2721 gboolean max_horz
= self
->max_horz
;
2722 gboolean max_vert
= self
->max_vert
;
2723 gboolean modal
= self
->modal
;
2724 gboolean iconic
= self
->iconic
;
2725 gboolean demands_attention
= self
->demands_attention
;
2728 if (!(action
== prop_atoms
.net_wm_state_add
||
2729 action
== prop_atoms
.net_wm_state_remove
||
2730 action
== prop_atoms
.net_wm_state_toggle
))
2731 /* an invalid action was passed to the client message, ignore it */
2734 for (i
= 0; i
< 2; ++i
) {
2735 Atom state
= i
== 0 ? data1
: data2
;
2737 if (!state
) continue;
2739 /* if toggling, then pick whether we're adding or removing */
2740 if (action
== prop_atoms
.net_wm_state_toggle
) {
2741 if (state
== prop_atoms
.net_wm_state_modal
)
2742 action
= modal
? prop_atoms
.net_wm_state_remove
:
2743 prop_atoms
.net_wm_state_add
;
2744 else if (state
== prop_atoms
.net_wm_state_maximized_vert
)
2745 action
= self
->max_vert
? prop_atoms
.net_wm_state_remove
:
2746 prop_atoms
.net_wm_state_add
;
2747 else if (state
== prop_atoms
.net_wm_state_maximized_horz
)
2748 action
= self
->max_horz
? prop_atoms
.net_wm_state_remove
:
2749 prop_atoms
.net_wm_state_add
;
2750 else if (state
== prop_atoms
.net_wm_state_shaded
)
2751 action
= shaded
? prop_atoms
.net_wm_state_remove
:
2752 prop_atoms
.net_wm_state_add
;
2753 else if (state
== prop_atoms
.net_wm_state_skip_taskbar
)
2754 action
= self
->skip_taskbar
?
2755 prop_atoms
.net_wm_state_remove
:
2756 prop_atoms
.net_wm_state_add
;
2757 else if (state
== prop_atoms
.net_wm_state_skip_pager
)
2758 action
= self
->skip_pager
?
2759 prop_atoms
.net_wm_state_remove
:
2760 prop_atoms
.net_wm_state_add
;
2761 else if (state
== prop_atoms
.net_wm_state_hidden
)
2762 action
= self
->iconic
?
2763 prop_atoms
.net_wm_state_remove
:
2764 prop_atoms
.net_wm_state_add
;
2765 else if (state
== prop_atoms
.net_wm_state_fullscreen
)
2766 action
= fullscreen
?
2767 prop_atoms
.net_wm_state_remove
:
2768 prop_atoms
.net_wm_state_add
;
2769 else if (state
== prop_atoms
.net_wm_state_above
)
2770 action
= self
->above
? prop_atoms
.net_wm_state_remove
:
2771 prop_atoms
.net_wm_state_add
;
2772 else if (state
== prop_atoms
.net_wm_state_below
)
2773 action
= self
->below
? prop_atoms
.net_wm_state_remove
:
2774 prop_atoms
.net_wm_state_add
;
2775 else if (state
== prop_atoms
.net_wm_state_demands_attention
)
2776 action
= self
->demands_attention
?
2777 prop_atoms
.net_wm_state_remove
:
2778 prop_atoms
.net_wm_state_add
;
2779 else if (state
== prop_atoms
.ob_wm_state_undecorated
)
2780 action
= undecorated
? prop_atoms
.net_wm_state_remove
:
2781 prop_atoms
.net_wm_state_add
;
2784 if (action
== prop_atoms
.net_wm_state_add
) {
2785 if (state
== prop_atoms
.net_wm_state_modal
) {
2787 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
2789 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
2791 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
2793 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
2794 self
->skip_taskbar
= TRUE
;
2795 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
2796 self
->skip_pager
= TRUE
;
2797 } else if (state
== prop_atoms
.net_wm_state_hidden
) {
2799 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
2801 } else if (state
== prop_atoms
.net_wm_state_above
) {
2803 self
->below
= FALSE
;
2804 } else if (state
== prop_atoms
.net_wm_state_below
) {
2805 self
->above
= FALSE
;
2807 } else if (state
== prop_atoms
.net_wm_state_demands_attention
) {
2808 demands_attention
= TRUE
;
2809 } else if (state
== prop_atoms
.ob_wm_state_undecorated
) {
2813 } else { /* action == prop_atoms.net_wm_state_remove */
2814 if (state
== prop_atoms
.net_wm_state_modal
) {
2816 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
2818 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
2820 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
2822 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
2823 self
->skip_taskbar
= FALSE
;
2824 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
2825 self
->skip_pager
= FALSE
;
2826 } else if (state
== prop_atoms
.net_wm_state_hidden
) {
2828 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
2830 } else if (state
== prop_atoms
.net_wm_state_above
) {
2831 self
->above
= FALSE
;
2832 } else if (state
== prop_atoms
.net_wm_state_below
) {
2833 self
->below
= FALSE
;
2834 } else if (state
== prop_atoms
.net_wm_state_demands_attention
) {
2835 demands_attention
= FALSE
;
2836 } else if (state
== prop_atoms
.ob_wm_state_undecorated
) {
2837 undecorated
= FALSE
;
2841 if (max_horz
!= self
->max_horz
|| max_vert
!= self
->max_vert
) {
2842 if (max_horz
!= self
->max_horz
&& max_vert
!= self
->max_vert
) {
2844 if (max_horz
== max_vert
) { /* both going the same way */
2845 client_maximize(self
, max_horz
, 0, TRUE
);
2847 client_maximize(self
, max_horz
, 1, TRUE
);
2848 client_maximize(self
, max_vert
, 2, TRUE
);
2852 if (max_horz
!= self
->max_horz
)
2853 client_maximize(self
, max_horz
, 1, TRUE
);
2855 client_maximize(self
, max_vert
, 2, TRUE
);
2858 /* change fullscreen state before shading, as it will affect if the window
2860 if (fullscreen
!= self
->fullscreen
)
2861 client_fullscreen(self
, fullscreen
, TRUE
);
2862 if (shaded
!= self
->shaded
)
2863 client_shade(self
, shaded
);
2864 if (undecorated
!= self
->undecorated
)
2865 client_set_undecorated(self
, undecorated
);
2866 if (modal
!= self
->modal
) {
2867 self
->modal
= modal
;
2868 /* when a window changes modality, then its stacking order with its
2869 transients needs to change */
2872 if (iconic
!= self
->iconic
)
2873 client_iconify(self
, iconic
, FALSE
);
2875 if (demands_attention
!= self
->demands_attention
)
2876 client_hilite(self
, demands_attention
);
2878 client_change_state(self
); /* change the hint to reflect these changes */
2881 ObClient
*client_focus_target(ObClient
*self
)
2883 ObClient
*child
= NULL
;
2885 child
= client_search_modal_child(self
);
2886 if (child
) return child
;
2890 gboolean
client_can_focus(ObClient
*self
)
2894 /* choose the correct target */
2895 self
= client_focus_target(self
);
2897 if (!self
->frame
->visible
)
2900 if (!(self
->can_focus
|| self
->focus_notify
))
2903 /* do a check to see if the window has already been unmapped or destroyed
2904 do this intelligently while watching out for unmaps we've generated
2905 (ignore_unmaps > 0) */
2906 if (XCheckTypedWindowEvent(ob_display
, self
->window
,
2907 DestroyNotify
, &ev
)) {
2908 XPutBackEvent(ob_display
, &ev
);
2911 while (XCheckTypedWindowEvent(ob_display
, self
->window
,
2912 UnmapNotify
, &ev
)) {
2913 if (self
->ignore_unmaps
) {
2914 self
->ignore_unmaps
--;
2916 XPutBackEvent(ob_display
, &ev
);
2924 gboolean
client_focus(ObClient
*self
)
2926 /* choose the correct target */
2927 self
= client_focus_target(self
);
2929 if (!client_can_focus(self
)) {
2930 if (!self
->frame
->visible
) {
2931 /* update the focus lists */
2932 focus_order_to_top(self
);
2937 if (self
->can_focus
) {
2938 /* RevertToPointerRoot causes much more headache than RevertToNone, so
2939 I choose to use it always, hopefully to find errors quicker, if any
2940 are left. (I hate X. I hate focus events.)
2942 Update: Changing this to RevertToNone fixed a bug with mozilla (bug
2943 #799. So now it is RevertToNone again.
2945 XSetInputFocus(ob_display
, self
->window
, RevertToNone
,
2949 if (self
->focus_notify
) {
2951 ce
.xclient
.type
= ClientMessage
;
2952 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
2953 ce
.xclient
.display
= ob_display
;
2954 ce
.xclient
.window
= self
->window
;
2955 ce
.xclient
.format
= 32;
2956 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_take_focus
;
2957 ce
.xclient
.data
.l
[1] = event_curtime
;
2958 ce
.xclient
.data
.l
[2] = 0l;
2959 ce
.xclient
.data
.l
[3] = 0l;
2960 ce
.xclient
.data
.l
[4] = 0l;
2961 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
2965 ob_debug("%sively focusing %lx at %d\n",
2966 (self
->can_focus
? "act" : "pass"),
2967 self
->window
, (gint
) event_curtime
);
2970 /* Cause the FocusIn to come back to us. Important for desktop switches,
2971 since otherwise we'll have no FocusIn on the queue and send it off to
2972 the focus_backup. */
2973 XSync(ob_display
, FALSE
);
2977 /* Used when the current client is closed, focus_last will then prevent
2978 * focus from going to the mouse pointer */
2979 void client_unfocus(ObClient
*self
)
2981 if (focus_client
== self
) {
2983 ob_debug("client_unfocus for %lx\n", self
->window
);
2985 focus_fallback(OB_FOCUS_FALLBACK_CLOSED
);
2989 void client_activate(ObClient
*self
, gboolean here
, gboolean user
, Time time
)
2991 /* XXX do some stuff here if user is false to determine if we really want
2992 to activate it or not (a parent or group member is currently
2995 ob_debug("Want to activate window 0x%x with time %u (last time %u), "
2997 self
->window
, time
, client_last_user_time
,
2998 (user
? "user" : "application"));
2999 if (!user
&& time
&& time
< client_last_user_time
)
3000 client_hilite(self
, TRUE
);
3002 if (client_normal(self
) && screen_showing_desktop
)
3003 screen_show_desktop(FALSE
);
3005 client_iconify(self
, FALSE
, here
);
3006 if (self
->desktop
!= DESKTOP_ALL
&&
3007 self
->desktop
!= screen_desktop
) {
3009 client_set_desktop(self
, screen_desktop
, FALSE
);
3011 screen_set_desktop(self
->desktop
);
3012 } else if (!self
->frame
->visible
)
3013 /* if its not visible for other reasons, then don't mess
3017 client_shade(self
, FALSE
);
3021 /* we do this an action here. this is rather important. this is because
3022 we want the results from the focus change to take place BEFORE we go
3023 about raising the window. when a fullscreen window loses focus, we
3024 need this or else the raise wont be able to raise above the
3025 to-lose-focus fullscreen window. */
3030 void client_raise(ObClient
*self
)
3032 action_run_string("Raise", self
, CurrentTime
);
3035 void client_lower(ObClient
*self
)
3037 action_run_string("Lower", self
, CurrentTime
);
3040 gboolean
client_focused(ObClient
*self
)
3042 return self
== focus_client
;
3045 static ObClientIcon
* client_icon_recursive(ObClient
*self
, gint w
, gint h
)
3048 /* si is the smallest image >= req */
3049 /* li is the largest image < req */
3050 gulong size
, smallest
= 0xffffffff, largest
= 0, si
= 0, li
= 0;
3052 if (!self
->nicons
) {
3053 ObClientIcon
*parent
= NULL
;
3055 if (self
->transient_for
) {
3056 if (self
->transient_for
!= OB_TRAN_GROUP
)
3057 parent
= client_icon_recursive(self
->transient_for
, w
, h
);
3060 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
3061 ObClient
*c
= it
->data
;
3062 if (c
!= self
&& !c
->transient_for
) {
3063 if ((parent
= client_icon_recursive(c
, w
, h
)))
3073 for (i
= 0; i
< self
->nicons
; ++i
) {
3074 size
= self
->icons
[i
].width
* self
->icons
[i
].height
;
3075 if (size
< smallest
&& size
>= (unsigned)(w
* h
)) {
3079 if (size
> largest
&& size
<= (unsigned)(w
* h
)) {
3084 if (largest
== 0) /* didnt find one smaller than the requested size */
3085 return &self
->icons
[si
];
3086 return &self
->icons
[li
];
3089 const ObClientIcon
* client_icon(ObClient
*self
, gint w
, gint h
)
3092 static ObClientIcon deficon
;
3094 if (!(ret
= client_icon_recursive(self
, w
, h
))) {
3095 deficon
.width
= deficon
.height
= 48;
3096 deficon
.data
= ob_rr_theme
->def_win_icon
;
3102 /* this be mostly ripped from fvwm */
3103 ObClient
*client_find_directional(ObClient
*c
, ObDirection dir
)
3105 gint my_cx
, my_cy
, his_cx
, his_cy
;
3108 gint score
, best_score
;
3109 ObClient
*best_client
, *cur
;
3115 /* first, find the centre coords of the currently focused window */
3116 my_cx
= c
->frame
->area
.x
+ c
->frame
->area
.width
/ 2;
3117 my_cy
= c
->frame
->area
.y
+ c
->frame
->area
.height
/ 2;
3122 for(it
= g_list_first(client_list
); it
; it
= g_list_next(it
)) {
3125 /* the currently selected window isn't interesting */
3128 if (!client_normal(cur
))
3130 /* using c->desktop instead of screen_desktop doesn't work if the
3131 * current window was omnipresent, hope this doesn't have any other
3133 if(screen_desktop
!= cur
->desktop
&& cur
->desktop
!= DESKTOP_ALL
)
3137 if(!(client_focus_target(cur
) == cur
&&
3138 client_can_focus(cur
)))
3141 /* find the centre coords of this window, from the
3142 * currently focused window's point of view */
3143 his_cx
= (cur
->frame
->area
.x
- my_cx
)
3144 + cur
->frame
->area
.width
/ 2;
3145 his_cy
= (cur
->frame
->area
.y
- my_cy
)
3146 + cur
->frame
->area
.height
/ 2;
3148 if(dir
== OB_DIRECTION_NORTHEAST
|| dir
== OB_DIRECTION_SOUTHEAST
||
3149 dir
== OB_DIRECTION_SOUTHWEST
|| dir
== OB_DIRECTION_NORTHWEST
) {
3151 /* Rotate the diagonals 45 degrees counterclockwise.
3152 * To do this, multiply the matrix /+h +h\ with the
3153 * vector (x y). \-h +h/
3154 * h = sqrt(0.5). We can set h := 1 since absolute
3155 * distance doesn't matter here. */
3156 tx
= his_cx
+ his_cy
;
3157 his_cy
= -his_cx
+ his_cy
;
3162 case OB_DIRECTION_NORTH
:
3163 case OB_DIRECTION_SOUTH
:
3164 case OB_DIRECTION_NORTHEAST
:
3165 case OB_DIRECTION_SOUTHWEST
:
3166 offset
= (his_cx
< 0) ? -his_cx
: his_cx
;
3167 distance
= ((dir
== OB_DIRECTION_NORTH
||
3168 dir
== OB_DIRECTION_NORTHEAST
) ?
3171 case OB_DIRECTION_EAST
:
3172 case OB_DIRECTION_WEST
:
3173 case OB_DIRECTION_SOUTHEAST
:
3174 case OB_DIRECTION_NORTHWEST
:
3175 offset
= (his_cy
< 0) ? -his_cy
: his_cy
;
3176 distance
= ((dir
== OB_DIRECTION_WEST
||
3177 dir
== OB_DIRECTION_NORTHWEST
) ?
3182 /* the target must be in the requested direction */
3186 /* Calculate score for this window. The smaller the better. */
3187 score
= distance
+ offset
;
3189 /* windows more than 45 degrees off the direction are
3190 * heavily penalized and will only be chosen if nothing
3191 * else within a million pixels */
3192 if(offset
> distance
)
3195 if(best_score
== -1 || score
< best_score
)
3203 void client_set_layer(ObClient
*self
, gint layer
)
3207 self
->above
= FALSE
;
3208 } else if (layer
== 0) {
3209 self
->below
= self
->above
= FALSE
;
3211 self
->below
= FALSE
;
3214 client_calc_layer(self
);
3215 client_change_state(self
); /* reflect this in the state hints */
3218 void client_set_undecorated(ObClient
*self
, gboolean undecorated
)
3220 if (self
->undecorated
!= undecorated
) {
3221 self
->undecorated
= undecorated
;
3222 client_setup_decor_and_functions(self
);
3223 /* Make sure the client knows it might have moved. Maybe there is a
3224 * better way of doing this so only one client_configure is sent, but
3225 * since 125 of these are sent per second when moving the window (with
3226 * user = FALSE) i doubt it matters much.
3228 client_configure(self
, OB_CORNER_TOPLEFT
, self
->area
.x
, self
->area
.y
,
3229 self
->area
.width
, self
->area
.height
, TRUE
, TRUE
);
3230 client_change_state(self
); /* reflect this in the state hints */
3234 guint
client_monitor(ObClient
*self
)
3236 return screen_find_monitor(&self
->frame
->area
);
3239 GSList
*client_search_top_transients(ObClient
*self
)
3243 /* move up the direct transient chain as far as possible */
3244 while (self
->transient_for
&& self
->transient_for
!= OB_TRAN_GROUP
)
3245 self
= self
->transient_for
;
3247 if (!self
->transient_for
)
3248 ret
= g_slist_prepend(ret
, self
);
3252 g_assert(self
->group
);
3254 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
3255 ObClient
*c
= it
->data
;
3257 if (!c
->transient_for
)
3258 ret
= g_slist_prepend(ret
, c
);
3261 if (ret
== NULL
) /* no group parents */
3262 ret
= g_slist_prepend(ret
, self
);
3268 ObClient
*client_search_focus_parent(ObClient
*self
)
3270 if (self
->transient_for
) {
3271 if (self
->transient_for
!= OB_TRAN_GROUP
) {
3272 if (client_focused(self
->transient_for
))
3273 return self
->transient_for
;
3277 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
3278 ObClient
*c
= it
->data
;
3280 /* checking transient_for prevents infinate loops! */
3281 if (c
!= self
&& !c
->transient_for
)
3282 if (client_focused(c
))
3291 ObClient
*client_search_parent(ObClient
*self
, ObClient
*search
)
3293 if (self
->transient_for
) {
3294 if (self
->transient_for
!= OB_TRAN_GROUP
) {
3295 if (self
->transient_for
== search
)
3300 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
3301 ObClient
*c
= it
->data
;
3303 /* checking transient_for prevents infinate loops! */
3304 if (c
!= self
&& !c
->transient_for
)
3314 ObClient
*client_search_transient(ObClient
*self
, ObClient
*search
)
3318 for (sit
= self
->transients
; sit
; sit
= g_slist_next(sit
)) {
3319 if (sit
->data
== search
)
3321 if (client_search_transient(sit
->data
, search
))
3327 void client_update_sm_client_id(ObClient
*self
)
3329 g_free(self
->sm_client_id
);
3330 self
->sm_client_id
= NULL
;
3332 if (!PROP_GETS(self
->window
, sm_client_id
, locale
, &self
->sm_client_id
) &&
3334 PROP_GETS(self
->group
->leader
, sm_client_id
, locale
,
3335 &self
->sm_client_id
);
3338 #define WANT_EDGE(cur, c) \
3341 if(!client_normal(cur)) \
3343 if(screen_desktop != cur->desktop && cur->desktop != DESKTOP_ALL) \
3347 if(cur->layer < c->layer && !config_resist_layers_below) \
3350 #define HIT_EDGE(my_edge_start, my_edge_end, his_edge_start, his_edge_end) \
3351 if ((his_edge_start >= my_edge_start && \
3352 his_edge_start <= my_edge_end) || \
3353 (my_edge_start >= his_edge_start && \
3354 my_edge_start <= his_edge_end)) \
3357 /* finds the nearest edge in the given direction from the current client
3358 * note to self: the edge is the -frame- edge (the actual one), not the
3361 gint
client_directional_edge_search(ObClient
*c
, ObDirection dir
, gboolean hang
)
3363 gint dest
, monitor_dest
;
3364 gint my_edge_start
, my_edge_end
, my_offset
;
3371 a
= screen_area(c
->desktop
);
3372 monitor
= screen_area_monitor(c
->desktop
, client_monitor(c
));
3375 case OB_DIRECTION_NORTH
:
3376 my_edge_start
= c
->frame
->area
.x
;
3377 my_edge_end
= c
->frame
->area
.x
+ c
->frame
->area
.width
;
3378 my_offset
= c
->frame
->area
.y
+ (hang
? c
->frame
->area
.height
: 0);
3380 /* default: top of screen */
3381 dest
= a
->y
+ (hang
? c
->frame
->area
.height
: 0);
3382 monitor_dest
= monitor
->y
+ (hang
? c
->frame
->area
.height
: 0);
3383 /* if the monitor edge comes before the screen edge, */
3384 /* use that as the destination instead. (For xinerama) */
3385 if (monitor_dest
!= dest
&& my_offset
> monitor_dest
)
3386 dest
= monitor_dest
;
3388 for(it
= client_list
; it
&& my_offset
!= dest
; it
= g_list_next(it
)) {
3389 gint his_edge_start
, his_edge_end
, his_offset
;
3390 ObClient
*cur
= it
->data
;
3394 his_edge_start
= cur
->frame
->area
.x
;
3395 his_edge_end
= cur
->frame
->area
.x
+ cur
->frame
->area
.width
;
3396 his_offset
= cur
->frame
->area
.y
+
3397 (hang
? 0 : cur
->frame
->area
.height
);
3399 if(his_offset
+ 1 > my_offset
)
3402 if(his_offset
< dest
)
3405 HIT_EDGE(my_edge_start
, my_edge_end
, his_edge_start
, his_edge_end
)
3408 case OB_DIRECTION_SOUTH
:
3409 my_edge_start
= c
->frame
->area
.x
;
3410 my_edge_end
= c
->frame
->area
.x
+ c
->frame
->area
.width
;
3411 my_offset
= c
->frame
->area
.y
+ (hang
? 0 : c
->frame
->area
.height
);
3413 /* default: bottom of screen */
3414 dest
= a
->y
+ a
->height
- (hang
? c
->frame
->area
.height
: 0);
3415 monitor_dest
= monitor
->y
+ monitor
->height
-
3416 (hang
? c
->frame
->area
.height
: 0);
3417 /* if the monitor edge comes before the screen edge, */
3418 /* use that as the destination instead. (For xinerama) */
3419 if (monitor_dest
!= dest
&& my_offset
< monitor_dest
)
3420 dest
= monitor_dest
;
3422 for(it
= client_list
; it
&& my_offset
!= dest
; it
= g_list_next(it
)) {
3423 gint his_edge_start
, his_edge_end
, his_offset
;
3424 ObClient
*cur
= it
->data
;
3428 his_edge_start
= cur
->frame
->area
.x
;
3429 his_edge_end
= cur
->frame
->area
.x
+ cur
->frame
->area
.width
;
3430 his_offset
= cur
->frame
->area
.y
+
3431 (hang
? cur
->frame
->area
.height
: 0);
3434 if(his_offset
- 1 < my_offset
)
3437 if(his_offset
> dest
)
3440 HIT_EDGE(my_edge_start
, my_edge_end
, his_edge_start
, his_edge_end
)
3443 case OB_DIRECTION_WEST
:
3444 my_edge_start
= c
->frame
->area
.y
;
3445 my_edge_end
= c
->frame
->area
.y
+ c
->frame
->area
.height
;
3446 my_offset
= c
->frame
->area
.x
+ (hang
? c
->frame
->area
.width
: 0);
3448 /* default: leftmost egde of screen */
3449 dest
= a
->x
+ (hang
? c
->frame
->area
.width
: 0);
3450 monitor_dest
= monitor
->x
+ (hang
? c
->frame
->area
.width
: 0);
3451 /* if the monitor edge comes before the screen edge, */
3452 /* use that as the destination instead. (For xinerama) */
3453 if (monitor_dest
!= dest
&& my_offset
> monitor_dest
)
3454 dest
= monitor_dest
;
3456 for(it
= client_list
; it
&& my_offset
!= dest
; it
= g_list_next(it
)) {
3457 gint his_edge_start
, his_edge_end
, his_offset
;
3458 ObClient
*cur
= it
->data
;
3462 his_edge_start
= cur
->frame
->area
.y
;
3463 his_edge_end
= cur
->frame
->area
.y
+ cur
->frame
->area
.height
;
3464 his_offset
= cur
->frame
->area
.x
+
3465 (hang
? 0 : cur
->frame
->area
.width
);
3467 if(his_offset
+ 1 > my_offset
)
3470 if(his_offset
< dest
)
3473 HIT_EDGE(my_edge_start
, my_edge_end
, his_edge_start
, his_edge_end
)
3476 case OB_DIRECTION_EAST
:
3477 my_edge_start
= c
->frame
->area
.y
;
3478 my_edge_end
= c
->frame
->area
.y
+ c
->frame
->area
.height
;
3479 my_offset
= c
->frame
->area
.x
+ (hang
? 0 : c
->frame
->area
.width
);
3481 /* default: rightmost edge of screen */
3482 dest
= a
->x
+ a
->width
- (hang
? c
->frame
->area
.width
: 0);
3483 monitor_dest
= monitor
->x
+ monitor
->width
-
3484 (hang
? c
->frame
->area
.width
: 0);
3485 /* if the monitor edge comes before the screen edge, */
3486 /* use that as the destination instead. (For xinerama) */
3487 if (monitor_dest
!= dest
&& my_offset
< monitor_dest
)
3488 dest
= monitor_dest
;
3490 for(it
= client_list
; it
&& my_offset
!= dest
; it
= g_list_next(it
)) {
3491 gint his_edge_start
, his_edge_end
, his_offset
;
3492 ObClient
*cur
= it
->data
;
3496 his_edge_start
= cur
->frame
->area
.y
;
3497 his_edge_end
= cur
->frame
->area
.y
+ cur
->frame
->area
.height
;
3498 his_offset
= cur
->frame
->area
.x
+
3499 (hang
? cur
->frame
->area
.width
: 0);
3501 if(his_offset
- 1 < my_offset
)
3504 if(his_offset
> dest
)
3507 HIT_EDGE(my_edge_start
, my_edge_end
, his_edge_start
, his_edge_end
)
3510 case OB_DIRECTION_NORTHEAST
:
3511 case OB_DIRECTION_SOUTHEAST
:
3512 case OB_DIRECTION_NORTHWEST
:
3513 case OB_DIRECTION_SOUTHWEST
:
3514 /* not implemented */
3516 g_assert_not_reached();
3517 dest
= 0; /* suppress warning */
3522 ObClient
* client_under_pointer()
3526 ObClient
*ret
= NULL
;
3528 if (screen_pointer_pos(&x
, &y
)) {
3529 for (it
= stacking_list
; it
; it
= g_list_next(it
)) {
3530 if (WINDOW_IS_CLIENT(it
->data
)) {
3531 ObClient
*c
= WINDOW_AS_CLIENT(it
->data
);
3532 if (c
->frame
->visible
&&
3533 RECT_CONTAINS(c
->frame
->area
, x
, y
)) {
3543 gboolean
client_has_group_siblings(ObClient
*self
)
3545 return self
->group
&& self
->group
->members
->next
;