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 | StructureNotifyMask)
50 #define CLIENT_NOPROPAGATEMASK (ButtonPressMask | ButtonReleaseMask | \
55 ObClientDestructor func
;
59 GList
*client_list
= NULL
;
61 static GSList
*client_destructors
= NULL
;
62 static Time client_last_user_time
= CurrentTime
;
64 static void client_get_all(ObClient
*self
);
65 static void client_toggle_border(ObClient
*self
, gboolean show
);
66 static void client_get_startup_id(ObClient
*self
);
67 static void client_get_area(ObClient
*self
);
68 static void client_get_desktop(ObClient
*self
);
69 static void client_get_state(ObClient
*self
);
70 static void client_get_layer(ObClient
*self
);
71 static void client_get_shaped(ObClient
*self
);
72 static void client_get_mwm_hints(ObClient
*self
);
73 static void client_get_gravity(ObClient
*self
);
74 static void client_change_allowed_actions(ObClient
*self
);
75 static void client_change_state(ObClient
*self
);
76 static void client_change_wm_state(ObClient
*self
);
77 static void client_apply_startup_state(ObClient
*self
, gint x
, gint y
);
78 static void client_restore_session_state(ObClient
*self
);
79 static void client_restore_session_stacking(ObClient
*self
);
80 static ObAppSettings
*client_get_settings_state(ObClient
*self
);
81 static void client_unfocus(ObClient
*self
);
83 void client_startup(gboolean reconfig
)
90 void client_shutdown(gboolean reconfig
)
94 void client_add_destructor(ObClientDestructor func
, gpointer data
)
96 Destructor
*d
= g_new(Destructor
, 1);
99 client_destructors
= g_slist_prepend(client_destructors
, d
);
102 void client_remove_destructor(ObClientDestructor func
)
106 for (it
= client_destructors
; it
; it
= g_slist_next(it
)) {
107 Destructor
*d
= it
->data
;
108 if (d
->func
== func
) {
110 client_destructors
= g_slist_delete_link(client_destructors
, it
);
116 void client_set_list()
118 Window
*windows
, *win_it
;
120 guint size
= g_list_length(client_list
);
122 /* create an array of the window ids */
124 windows
= g_new(Window
, size
);
126 for (it
= client_list
; it
; it
= g_list_next(it
), ++win_it
)
127 *win_it
= ((ObClient
*)it
->data
)->window
;
131 PROP_SETA32(RootWindow(ob_display
, ob_screen
),
132 net_client_list
, window
, (gulong
*)windows
, size
);
141 void client_foreach_transient(ObClient *self, ObClientForeachFunc func, gpointer data)
145 for (it = self->transients; it; it = g_slist_next(it)) {
146 if (!func(it->data, data)) return;
147 client_foreach_transient(it->data, func, data);
151 void client_foreach_ancestor(ObClient *self, ObClientForeachFunc func, gpointer data)
153 if (self->transient_for) {
154 if (self->transient_for != OB_TRAN_GROUP) {
155 if (!func(self->transient_for, data)) return;
156 client_foreach_ancestor(self->transient_for, func, data);
160 for (it = self->group->members; it; it = g_slist_next(it))
161 if (it->data != self &&
162 !((ObClient*)it->data)->transient_for) {
163 if (!func(it->data, data)) return;
164 client_foreach_ancestor(it->data, func, data);
171 void client_manage_all()
176 XWindowAttributes attrib
;
178 XQueryTree(ob_display
, RootWindow(ob_display
, ob_screen
),
179 &w
, &w
, &children
, &nchild
);
181 /* remove all icon windows from the list */
182 for (i
= 0; i
< nchild
; i
++) {
183 if (children
[i
] == None
) continue;
184 wmhints
= XGetWMHints(ob_display
, children
[i
]);
186 if ((wmhints
->flags
& IconWindowHint
) &&
187 (wmhints
->icon_window
!= children
[i
]))
188 for (j
= 0; j
< nchild
; j
++)
189 if (children
[j
] == wmhints
->icon_window
) {
197 for (i
= 0; i
< nchild
; ++i
) {
198 if (children
[i
] == None
)
200 if (XGetWindowAttributes(ob_display
, children
[i
], &attrib
)) {
201 if (attrib
.override_redirect
) continue;
203 if (attrib
.map_state
!= IsUnmapped
)
204 client_manage(children
[i
]);
210 void client_manage(Window window
)
214 XWindowAttributes attrib
;
215 XSetWindowAttributes attrib_set
;
217 gboolean activate
= FALSE
;
218 ObAppSettings
*settings
;
223 /* check if it has already been unmapped by the time we started mapping
224 the grab does a sync so we don't have to here */
225 if (XCheckTypedWindowEvent(ob_display
, window
, DestroyNotify
, &e
) ||
226 XCheckTypedWindowEvent(ob_display
, window
, UnmapNotify
, &e
))
228 XPutBackEvent(ob_display
, &e
);
231 return; /* don't manage it */
234 /* make sure it isn't an override-redirect window */
235 if (!XGetWindowAttributes(ob_display
, window
, &attrib
) ||
236 attrib
.override_redirect
)
239 return; /* don't manage it */
242 /* is the window a docking app */
243 if ((wmhint
= XGetWMHints(ob_display
, window
))) {
244 if ((wmhint
->flags
& StateHint
) &&
245 wmhint
->initial_state
== WithdrawnState
)
247 dock_add(window
, wmhint
);
255 ob_debug("Managing window: %lx\n", window
);
257 /* choose the events we want to receive on the CLIENT window */
258 attrib_set
.event_mask
= CLIENT_EVENTMASK
;
259 attrib_set
.do_not_propagate_mask
= CLIENT_NOPROPAGATEMASK
;
260 XChangeWindowAttributes(ob_display
, window
,
261 CWEventMask
|CWDontPropagate
, &attrib_set
);
264 /* create the ObClient struct, and populate it from the hints on the
266 self
= g_new0(ObClient
, 1);
267 self
->obwin
.type
= Window_Client
;
268 self
->window
= window
;
270 /* non-zero defaults */
271 self
->title_count
= 1;
272 self
->wmstate
= WithdrawnState
; /* make sure it gets updated first time */
274 self
->desktop
= screen_num_desktops
; /* always an invalid value */
275 self
->user_time
= ~0; /* maximum value, always newer than the real time */
277 client_get_all(self
);
278 client_restore_session_state(self
);
279 /* per-app settings override stuff, and return the settings for other
281 settings
= client_get_settings_state(self
);
283 client_calc_layer(self
);
286 Time t
= sn_app_started(self
->startup_id
, self
->class);
287 if (t
) self
->user_time
= t
;
290 /* update the focus lists, do this before the call to change_state or
291 it can end up in the list twice! */
292 focus_order_add_new(self
);
294 /* remove the client's border (and adjust re gravity) */
295 client_toggle_border(self
, FALSE
);
297 /* specify that if we exit, the window should not be destroyed and should
298 be reparented back to root automatically */
299 XChangeSaveSet(ob_display
, window
, SetModeInsert
);
301 /* create the decoration frame for the client window */
302 self
->frame
= frame_new(self
);
304 frame_grab_client(self
->frame
, self
);
306 /* do this after we have a frame.. it uses the frame to help determine the
307 WM_STATE to apply. */
308 client_change_state(self
);
312 stacking_add_nonintrusive(CLIENT_AS_WINDOW(self
));
313 client_restore_session_stacking(self
);
315 /* focus the new window? */
316 if (ob_state() != OB_STATE_STARTING
&&
317 /* this means focus=true for window is same as config_focus_new=true */
318 ((config_focus_new
|| (settings
&& settings
->focus
== 1)) ||
319 client_search_focus_parent(self
)) &&
320 /* this checks for focus=false for the window */
321 (!settings
|| settings
->focus
!= 0) &&
322 /* note the check against Type_Normal/Dialog, not client_normal(self),
323 which would also include other types. in this case we want more
324 strict rules for focus */
325 (self
->type
== OB_CLIENT_TYPE_NORMAL
||
326 self
->type
== OB_CLIENT_TYPE_DIALOG
))
330 if (self
->desktop
!= screen_desktop
) {
331 /* activate the window */
334 gboolean group_foc
= FALSE
;
339 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
))
341 if (client_focused(it
->data
))
349 (!self
->transient_for
&& (!self
->group
||
350 !self
->group
->members
->next
))) ||
351 client_search_focus_tree_full(self
) ||
353 !client_normal(focus_client
))
355 /* activate the window */
362 /* get the current position */
366 /* figure out placement for the window */
367 if (ob_state() == OB_STATE_RUNNING
) {
370 transient
= place_client(self
, &newx
, &newy
, settings
);
372 /* make sure the window is visible. */
373 client_find_onscreen(self
, &newx
, &newy
,
374 self
->frame
->area
.width
,
375 self
->frame
->area
.height
,
376 /* non-normal clients has less rules, and
377 windows that are being restored from a
378 session do also. we can assume you want
379 it back where you saved it. Clients saying
380 they placed themselves are subjected to
381 harder rules, ones that are placed by
382 place.c or by the user are allowed partially
383 off-screen and on xinerama divides (ie,
384 it is up to the placement routines to avoid
385 the xinerama divides) */
387 (((self
->positioned
& PPosition
) &&
388 !(self
->positioned
& USPosition
)) &&
389 client_normal(self
) &&
393 /* do this after the window is placed, so the premax/prefullscreen numbers
395 also, this moves the window to the position where it has been placed
397 client_apply_startup_state(self
, newx
, newy
);
399 keyboard_grab_for_client(self
, TRUE
);
400 mouse_grab_for_client(self
, TRUE
);
403 /* This is focus stealing prevention */
404 ob_debug("Want to focus new window 0x%x with time %u (last time %u)\n",
405 self
->window
, self
->user_time
, client_last_user_time
);
407 /* If a nothing at all, or a parent was focused, then focus this
410 if (!focus_client
|| client_search_focus_parent(self
) != NULL
)
414 /* If time stamp is old, don't steal focus */
415 if (self
->user_time
&& self
->user_time
< client_last_user_time
)
417 /* Don't steal focus from globally active clients.
418 I stole this idea from KWin. It seems nice.
420 if (!focus_client
->can_focus
&& focus_client
->focus_notify
)
426 /* since focus can change the stacking orders, if we focus the
427 window then the standard raise it gets is not enough, we need
428 to queue one for after the focus change takes place */
431 ob_debug("Focus stealing prevention activated for %s with time %u "
433 self
->title
, self
->user_time
, client_last_user_time
);
434 /* if the client isn't focused, then hilite it so the user
436 client_hilite(self
, TRUE
);
440 /* This may look rather odd. Well it's because new windows are added
441 to the stacking order non-intrusively. If we're not going to focus
442 the new window or hilite it, then we raise it to the top. This will
443 take affect for things that don't get focused like splash screens.
444 Also if you don't have focus_new enabled, then it's going to get
445 raised to the top. Legacy begets legacy I guess?
450 /* this has to happen before we try focus the window, but we want it to
451 happen after the client's stacking has been determined or it looks bad
453 client_showhide(self
);
455 /* use client_focus instead of client_activate cuz client_activate does
456 stuff like switch desktops etc and I'm not interested in all that when
457 a window maps since its not based on an action from the user like
458 clicking a window to activate it. so keep the new window out of the way
461 /* if using focus_delay, stop the timer now so that focus doesn't
463 event_halt_focus_delay();
467 /* client_activate does this but we aret using it so we have to do it
469 if (screen_showing_desktop
)
470 screen_show_desktop(FALSE
);
472 /* add to client list/map */
473 client_list
= g_list_append(client_list
, self
);
474 g_hash_table_insert(window_map
, &self
->window
, self
);
476 /* this has to happen after we're in the client_list */
477 if (STRUT_EXISTS(self
->strut
))
478 screen_update_areas();
480 /* update the list hints */
483 ob_debug("Managed window 0x%lx (%s)\n", window
, self
->class);
486 void client_unmanage_all()
488 while (client_list
!= NULL
)
489 client_unmanage(client_list
->data
);
492 void client_unmanage(ObClient
*self
)
497 ob_debug("Unmanaging window: %lx (%s) (%s)\n", self
->window
, self
->class,
498 self
->title
? self
->title
: "");
500 g_assert(self
!= NULL
);
502 /* update the focus lists */
503 focus_order_remove(self
);
505 if (focus_client
== self
) {
508 /* focus the last focused window on the desktop, and ignore enter
509 events from the unmap so it doesnt mess with the focus */
510 while (XCheckTypedEvent(ob_display
, EnterNotify
, &e
));
511 /* remove these flags so we don't end up getting focused in the
513 self
->can_focus
= FALSE
;
514 self
->focus_notify
= FALSE
;
516 client_unfocus(self
);
519 /* potentially fix focusLast */
520 if (config_focus_last
)
521 grab_pointer(TRUE
, OB_CURSOR_NONE
);
523 frame_hide(self
->frame
);
526 keyboard_grab_for_client(self
, FALSE
);
527 mouse_grab_for_client(self
, FALSE
);
529 /* remove the window from our save set */
530 XChangeSaveSet(ob_display
, self
->window
, SetModeDelete
);
532 /* we dont want events no more */
533 XSelectInput(ob_display
, self
->window
, NoEventMask
);
535 client_list
= g_list_remove(client_list
, self
);
536 stacking_remove(self
);
537 g_hash_table_remove(window_map
, &self
->window
);
539 /* once the client is out of the list, update the struts to remove its
541 if (STRUT_EXISTS(self
->strut
))
542 screen_update_areas();
544 for (it
= client_destructors
; it
; it
= g_slist_next(it
)) {
545 Destructor
*d
= it
->data
;
546 d
->func(self
, d
->data
);
549 /* tell our parent(s) that we're gone */
550 if (self
->transient_for
== OB_TRAN_GROUP
) { /* transient of group */
551 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
))
552 if (it
->data
!= self
)
553 ((ObClient
*)it
->data
)->transients
=
554 g_slist_remove(((ObClient
*)it
->data
)->transients
, self
);
555 } else if (self
->transient_for
) { /* transient of window */
556 self
->transient_for
->transients
=
557 g_slist_remove(self
->transient_for
->transients
, self
);
560 /* tell our transients that we're gone */
561 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
562 if (((ObClient
*)it
->data
)->transient_for
!= OB_TRAN_GROUP
) {
563 ((ObClient
*)it
->data
)->transient_for
= NULL
;
564 client_calc_layer(it
->data
);
568 /* remove from its group */
570 group_remove(self
->group
, self
);
574 /* give the client its border back */
575 client_toggle_border(self
, TRUE
);
577 /* reparent the window out of the frame, and free the frame */
578 frame_release_client(self
->frame
, self
);
581 /* restore the window's original geometry so it is not lost */
582 if (self
->fullscreen
)
583 XMoveResizeWindow(ob_display
, self
->window
,
584 self
->pre_fullscreen_area
.x
,
585 self
->pre_fullscreen_area
.y
,
586 self
->pre_fullscreen_area
.width
,
587 self
->pre_fullscreen_area
.height
);
588 else if (self
->max_horz
|| self
->max_vert
) {
590 if (self
->max_horz
) {
591 a
.x
= self
->pre_max_area
.x
;
592 a
.width
= self
->pre_max_area
.width
;
594 if (self
->max_vert
) {
595 a
.y
= self
->pre_max_area
.y
;
596 a
.height
= self
->pre_max_area
.height
;
598 XMoveResizeWindow(ob_display
, self
->window
,
599 a
.x
, a
.y
, a
.width
, a
.height
);
602 if (ob_state() != OB_STATE_EXITING
) {
603 /* these values should not be persisted across a window
605 PROP_ERASE(self
->window
, net_wm_desktop
);
606 PROP_ERASE(self
->window
, net_wm_state
);
607 PROP_ERASE(self
->window
, wm_state
);
609 /* if we're left in an unmapped state, the client wont be mapped. this
610 is bad, since we will no longer be managing the window on restart */
611 XMapWindow(ob_display
, self
->window
);
615 ob_debug("Unmanaged window 0x%lx\n", self
->window
);
617 /* free all data allocated in the client struct */
618 g_slist_free(self
->transients
);
619 for (j
= 0; j
< self
->nicons
; ++j
)
620 g_free(self
->icons
[j
].data
);
621 if (self
->nicons
> 0)
624 g_free(self
->icon_title
);
628 g_free(self
->sm_client_id
);
631 /* update the list hints */
634 if (config_focus_last
)
635 grab_pointer(FALSE
, OB_CURSOR_NONE
);
638 static ObAppSettings
*client_get_settings_state(ObClient
*self
)
640 ObAppSettings
*settings
= NULL
;
643 for (it
= config_per_app_settings
; it
; it
= g_slist_next(it
)) {
644 ObAppSettings
*app
= it
->data
;
646 if ((app
->name
&& !app
->class && !strcmp(app
->name
, self
->name
))
647 || (app
->class && !app
->name
&& !strcmp(app
->class, self
->class))
648 || (app
->class && app
->name
&& !strcmp(app
->class, self
->class)
649 && !strcmp(app
->name
, self
->name
)))
651 ob_debug("Window matching: %s\n", app
->name
);
652 /* Match if no role was specified in the per app setting, or if the
653 * string matches the beginning of the role, since apps like to set
654 * the role to things like browser-window-23c4b2f */
656 || !strncmp(app
->role
, self
->role
, strlen(app
->role
)))
666 if (settings
->shade
!= -1)
667 self
->shaded
= !!settings
->shade
;
668 if (settings
->decor
!= -1)
669 self
->undecorated
= !settings
->decor
;
670 if (settings
->iconic
!= -1)
671 self
->iconic
= !!settings
->iconic
;
672 if (settings
->skip_pager
!= -1)
673 self
->skip_pager
= !!settings
->skip_pager
;
674 if (settings
->skip_taskbar
!= -1)
675 self
->skip_taskbar
= !!settings
->skip_taskbar
;
677 if (settings
->max_vert
!= -1)
678 self
->max_vert
= !!settings
->max_vert
;
679 if (settings
->max_horz
!= -1)
680 self
->max_vert
= !!settings
->max_horz
;
682 if (settings
->fullscreen
!= -1)
683 self
->fullscreen
= !!settings
->fullscreen
;
685 if (settings
->desktop
< screen_num_desktops
686 || settings
->desktop
== DESKTOP_ALL
)
687 client_set_desktop(self
, settings
->desktop
, TRUE
);
689 if (settings
->layer
== -1) {
693 else if (settings
->layer
== 0) {
697 else if (settings
->layer
== 1) {
705 static void client_restore_session_state(ObClient
*self
)
709 if (!(it
= session_state_find(self
)))
712 self
->session
= it
->data
;
714 RECT_SET_POINT(self
->area
, self
->session
->x
, self
->session
->y
);
715 self
->positioned
= PPosition
;
716 if (self
->session
->w
> 0)
717 self
->area
.width
= self
->session
->w
;
718 if (self
->session
->h
> 0)
719 self
->area
.height
= self
->session
->h
;
720 XResizeWindow(ob_display
, self
->window
,
721 self
->area
.width
, self
->area
.height
);
723 self
->desktop
= (self
->session
->desktop
== DESKTOP_ALL
?
724 self
->session
->desktop
:
725 MIN(screen_num_desktops
- 1, self
->session
->desktop
));
726 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, self
->desktop
);
728 self
->shaded
= self
->session
->shaded
;
729 self
->iconic
= self
->session
->iconic
;
730 self
->skip_pager
= self
->session
->skip_pager
;
731 self
->skip_taskbar
= self
->session
->skip_taskbar
;
732 self
->fullscreen
= self
->session
->fullscreen
;
733 self
->above
= self
->session
->above
;
734 self
->below
= self
->session
->below
;
735 self
->max_horz
= self
->session
->max_horz
;
736 self
->max_vert
= self
->session
->max_vert
;
739 static void client_restore_session_stacking(ObClient
*self
)
743 if (!self
->session
) return;
745 it
= g_list_find(session_saved_state
, self
->session
);
746 for (it
= g_list_previous(it
); it
; it
= g_list_previous(it
)) {
749 for (cit
= client_list
; cit
; cit
= g_list_next(cit
))
750 if (session_state_cmp(it
->data
, cit
->data
))
753 client_calc_layer(self
);
754 stacking_below(CLIENT_AS_WINDOW(self
),
755 CLIENT_AS_WINDOW(cit
->data
));
761 void client_move_onscreen(ObClient
*self
, gboolean rude
)
763 gint x
= self
->area
.x
;
764 gint y
= self
->area
.y
;
765 if (client_find_onscreen(self
, &x
, &y
,
766 self
->frame
->area
.width
,
767 self
->frame
->area
.height
, rude
)) {
768 client_move(self
, x
, y
);
772 gboolean
client_find_onscreen(ObClient
*self
, gint
*x
, gint
*y
, gint w
, gint h
,
776 gint ox
= *x
, oy
= *y
;
778 frame_client_gravity(self
->frame
, x
, y
); /* get where the frame
781 /* XXX watch for xinerama dead areas */
782 /* This makes sure windows aren't entirely outside of the screen so you
783 can't see them at all.
784 It makes sure 10% of the window is on the screen at least. At don't let
785 it move itself off the top of the screen, which would hide the titlebar
786 on you. (The user can still do this if they want too, it's only limiting
789 if (client_normal(self
)) {
790 a
= screen_area(self
->desktop
);
791 if (!self
->strut
.right
&&
792 *x
+ self
->frame
->area
.width
/10 >= a
->x
+ a
->width
- 1)
793 *x
= a
->x
+ a
->width
- self
->frame
->area
.width
/10;
794 if (!self
->strut
.bottom
&&
795 *y
+ self
->frame
->area
.height
/10 >= a
->y
+ a
->height
- 1)
796 *y
= a
->y
+ a
->height
- self
->frame
->area
.height
/10;
797 if (!self
->strut
.left
&& *x
+ self
->frame
->area
.width
*9/10 - 1 < a
->x
)
798 *x
= a
->x
- self
->frame
->area
.width
*9/10;
799 if (!self
->strut
.top
&& *y
+ self
->frame
->area
.height
*9/10 - 1 < a
->y
)
800 *y
= a
->y
- self
->frame
->area
.width
*9/10;
803 /* This here doesn't let windows even a pixel outside the screen,
804 * when called from client_manage, programs placing themselves are
805 * forced completely onscreen, while things like
806 * xterm -geometry resolution-width/2 will work fine. Trying to
807 * place it completely offscreen will be handled in the above code.
808 * Sorry for this confused comment, i am tired. */
810 /* avoid the xinerama monitor divide while we're at it,
811 * remember to fix the placement stuff to avoid it also and
812 * then remove this XXX */
813 a
= screen_area_monitor(self
->desktop
, client_monitor(self
));
814 /* dont let windows map into the strut unless they
815 are bigger than the available area */
817 if (!self
->strut
.left
&& *x
< a
->x
) *x
= a
->x
;
818 if (!self
->strut
.right
&& *x
+ w
> a
->x
+ a
->width
)
819 *x
= a
->x
+ a
->width
- w
;
821 if (h
<= a
->height
) {
822 if (!self
->strut
.top
&& *y
< a
->y
) *y
= a
->y
;
823 if (!self
->strut
.bottom
&& *y
+ h
> a
->y
+ a
->height
)
824 *y
= a
->y
+ a
->height
- h
;
828 frame_frame_gravity(self
->frame
, x
, y
); /* get where the client
831 return ox
!= *x
|| oy
!= *y
;
834 static void client_toggle_border(ObClient
*self
, gboolean show
)
836 /* adjust our idea of where the client is, based on its border. When the
837 border is removed, the client should now be considered to be in a
839 when re-adding the border to the client, the same operation needs to be
841 gint oldx
= self
->area
.x
, oldy
= self
->area
.y
;
842 gint x
= oldx
, y
= oldy
;
843 switch(self
->gravity
) {
845 case NorthWestGravity
:
847 case SouthWestGravity
:
849 case NorthEastGravity
:
851 case SouthEastGravity
:
852 if (show
) x
-= self
->border_width
* 2;
853 else x
+= self
->border_width
* 2;
860 if (show
) x
-= self
->border_width
;
861 else x
+= self
->border_width
;
864 switch(self
->gravity
) {
866 case NorthWestGravity
:
868 case NorthEastGravity
:
870 case SouthWestGravity
:
872 case SouthEastGravity
:
873 if (show
) y
-= self
->border_width
* 2;
874 else y
+= self
->border_width
* 2;
881 if (show
) y
-= self
->border_width
;
882 else y
+= self
->border_width
;
889 XSetWindowBorderWidth(ob_display
, self
->window
, self
->border_width
);
891 /* move the client so it is back it the right spot _with_ its
893 if (x
!= oldx
|| y
!= oldy
)
894 XMoveWindow(ob_display
, self
->window
, x
, y
);
896 XSetWindowBorderWidth(ob_display
, self
->window
, 0);
900 static void client_get_all(ObClient
*self
)
902 client_get_area(self
);
903 client_get_mwm_hints(self
);
905 /* The transient hint is used to pick a type, but the type can also affect
906 transiency (dialogs are always made transients of their group if they
907 have one). This is Havoc's idea, but it is needed to make some apps
908 work right (eg tsclient). */
909 client_update_transient_for(self
);
910 client_get_type(self
);/* this can change the mwmhints for special cases */
911 client_get_state(self
);
912 client_update_transient_for(self
);
914 client_update_wmhints(self
);
915 client_get_startup_id(self
);
916 client_get_desktop(self
);/* uses transient data/group/startup id if a
917 desktop is not specified */
918 client_get_shaped(self
);
920 client_get_layer(self
); /* if layer hasn't been specified, get it from
921 other sources if possible */
924 /* a couple type-based defaults for new windows */
926 /* this makes sure that these windows appear on all desktops */
927 if (self
->type
== OB_CLIENT_TYPE_DESKTOP
)
928 self
->desktop
= DESKTOP_ALL
;
931 client_update_protocols(self
);
933 client_get_gravity(self
); /* get the attribute gravity */
934 client_update_normal_hints(self
); /* this may override the attribute
937 /* got the type, the mwmhints, the protocols, and the normal hints
938 (min/max sizes), so we're ready to set up the decorations/functions */
939 client_setup_decor_and_functions(self
);
941 client_update_title(self
);
942 client_update_class(self
);
943 client_update_sm_client_id(self
);
944 client_update_strut(self
);
945 client_update_icons(self
);
946 client_update_user_time(self
, FALSE
);
949 static void client_get_startup_id(ObClient
*self
)
951 if (!(PROP_GETS(self
->window
, net_startup_id
, utf8
, &self
->startup_id
)))
953 PROP_GETS(self
->group
->leader
,
954 net_startup_id
, utf8
, &self
->startup_id
);
957 static void client_get_area(ObClient
*self
)
959 XWindowAttributes wattrib
;
962 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
963 g_assert(ret
!= BadWindow
);
965 RECT_SET(self
->area
, wattrib
.x
, wattrib
.y
, wattrib
.width
, wattrib
.height
);
966 self
->border_width
= wattrib
.border_width
;
968 ob_debug("client area: %d %d %d %d\n", wattrib
.x
, wattrib
.y
,
969 wattrib
.width
, wattrib
.height
);
972 static void client_get_desktop(ObClient
*self
)
974 guint32 d
= screen_num_desktops
; /* an always-invalid value */
976 if (PROP_GET32(self
->window
, net_wm_desktop
, cardinal
, &d
)) {
977 if (d
>= screen_num_desktops
&& d
!= DESKTOP_ALL
)
978 self
->desktop
= screen_num_desktops
- 1;
982 gboolean trdesk
= FALSE
;
984 if (self
->transient_for
) {
985 if (self
->transient_for
!= OB_TRAN_GROUP
) {
986 self
->desktop
= self
->transient_for
->desktop
;
991 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
))
992 if (it
->data
!= self
&&
993 !((ObClient
*)it
->data
)->transient_for
) {
994 self
->desktop
= ((ObClient
*)it
->data
)->desktop
;
1001 /* try get from the startup-notification protocol */
1002 if (sn_get_desktop(self
->startup_id
, &self
->desktop
)) {
1003 if (self
->desktop
>= screen_num_desktops
&&
1004 self
->desktop
!= DESKTOP_ALL
)
1005 self
->desktop
= screen_num_desktops
- 1;
1007 /* defaults to the current desktop */
1008 self
->desktop
= screen_desktop
;
1011 if (self
->desktop
!= d
) {
1012 /* set the desktop hint, to make sure that it always exists */
1013 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, self
->desktop
);
1017 static void client_get_layer(ObClient
*self
)
1019 if (!(self
->above
|| self
->below
)) {
1021 /* apply stuff from the group */
1025 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
1026 ObClient
*c
= it
->data
;
1027 if (c
!= self
&& !client_search_transient(self
, c
) &&
1028 client_normal(self
) && client_normal(c
))
1031 (c
->above
? 1 : (c
->below
? -1 : 0)));
1045 g_assert_not_reached();
1052 static void client_get_state(ObClient
*self
)
1057 if (PROP_GETA32(self
->window
, net_wm_state
, atom
, &state
, &num
)) {
1059 for (i
= 0; i
< num
; ++i
) {
1060 if (state
[i
] == prop_atoms
.net_wm_state_modal
)
1062 else if (state
[i
] == prop_atoms
.net_wm_state_shaded
)
1063 self
->shaded
= TRUE
;
1064 else if (state
[i
] == prop_atoms
.net_wm_state_hidden
)
1065 self
->iconic
= TRUE
;
1066 else if (state
[i
] == prop_atoms
.net_wm_state_skip_taskbar
)
1067 self
->skip_taskbar
= TRUE
;
1068 else if (state
[i
] == prop_atoms
.net_wm_state_skip_pager
)
1069 self
->skip_pager
= TRUE
;
1070 else if (state
[i
] == prop_atoms
.net_wm_state_fullscreen
)
1071 self
->fullscreen
= TRUE
;
1072 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_vert
)
1073 self
->max_vert
= TRUE
;
1074 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_horz
)
1075 self
->max_horz
= TRUE
;
1076 else if (state
[i
] == prop_atoms
.net_wm_state_above
)
1078 else if (state
[i
] == prop_atoms
.net_wm_state_below
)
1080 else if (state
[i
] == prop_atoms
.net_wm_state_demands_attention
)
1081 self
->demands_attention
= TRUE
;
1082 else if (state
[i
] == prop_atoms
.ob_wm_state_undecorated
)
1083 self
->undecorated
= TRUE
;
1090 static void client_get_shaped(ObClient
*self
)
1092 self
->shaped
= FALSE
;
1094 if (extensions_shape
) {
1099 XShapeSelectInput(ob_display
, self
->window
, ShapeNotifyMask
);
1101 XShapeQueryExtents(ob_display
, self
->window
, &s
, &foo
,
1102 &foo
, &ufoo
, &ufoo
, &foo
, &foo
, &foo
, &ufoo
,
1104 self
->shaped
= (s
!= 0);
1109 void client_update_transient_for(ObClient
*self
)
1112 ObClient
*target
= NULL
;
1114 if (XGetTransientForHint(ob_display
, self
->window
, &t
)) {
1115 self
->transient
= TRUE
;
1116 if (t
!= self
->window
) { /* cant be transient to itself! */
1117 target
= g_hash_table_lookup(window_map
, &t
);
1118 /* if this happens then we need to check for it*/
1119 g_assert(target
!= self
);
1120 if (target
&& !WINDOW_IS_CLIENT(target
)) {
1121 /* this can happen when a dialog is a child of
1122 a dockapp, for example */
1126 /* THIS IS SO ANNOYING ! ! ! ! Let me explain.... have a seat..
1128 Setting the transient_for to Root is actually illegal, however
1129 applications from time have done this to specify transient for
1132 Now you can do that by being a TYPE_DIALOG and not setting
1133 the transient_for hint at all on your window. But people still
1134 use Root, and Kwin is very strange in this regard.
1136 KWin 3.0 will not consider windows with transient_for set to
1137 Root as transient for their group *UNLESS* they are also modal.
1138 In that case, it will make them transient for the group. This
1139 leads to all sorts of weird behavior from KDE apps which are
1140 only tested in KWin. I'd like to follow their behavior just to
1141 make this work right with KDE stuff, but that seems wrong.
1143 if (!target
&& self
->group
) {
1144 /* not transient to a client, see if it is transient for a
1146 if (t
== RootWindow(ob_display
, ob_screen
)) {
1147 /* window is a transient for its group! */
1148 target
= OB_TRAN_GROUP
;
1152 } else if (self
->group
) {
1153 if (self
->type
== OB_CLIENT_TYPE_DIALOG
||
1154 self
->type
== OB_CLIENT_TYPE_TOOLBAR
||
1155 self
->type
== OB_CLIENT_TYPE_MENU
||
1156 self
->type
== OB_CLIENT_TYPE_UTILITY
)
1158 self
->transient
= TRUE
;
1159 target
= OB_TRAN_GROUP
;
1162 self
->transient
= FALSE
;
1164 /* if anything has changed... */
1165 if (target
!= self
->transient_for
) {
1166 if (self
->transient_for
== OB_TRAN_GROUP
) { /* transient of group */
1169 /* remove from old parents */
1170 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
1171 ObClient
*c
= it
->data
;
1172 if (c
!= self
&& !c
->transient_for
)
1173 c
->transients
= g_slist_remove(c
->transients
, self
);
1175 } else if (self
->transient_for
!= NULL
) { /* transient of window */
1176 /* remove from old parent */
1177 self
->transient_for
->transients
=
1178 g_slist_remove(self
->transient_for
->transients
, self
);
1180 self
->transient_for
= target
;
1181 if (self
->transient_for
== OB_TRAN_GROUP
) { /* transient of group */
1184 /* add to new parents */
1185 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
1186 ObClient
*c
= it
->data
;
1187 if (c
!= self
&& !c
->transient_for
)
1188 c
->transients
= g_slist_append(c
->transients
, self
);
1191 /* remove all transients which are in the group, that causes
1192 circlular pointer hell of doom */
1193 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
1195 for (sit
= self
->transients
; sit
; sit
= next
) {
1196 next
= g_slist_next(sit
);
1197 if (sit
->data
== it
->data
)
1199 g_slist_delete_link(self
->transients
, sit
);
1202 } else if (self
->transient_for
!= NULL
) { /* transient of window */
1203 /* add to new parent */
1204 self
->transient_for
->transients
=
1205 g_slist_append(self
->transient_for
->transients
, self
);
1210 static void client_get_mwm_hints(ObClient
*self
)
1215 self
->mwmhints
.flags
= 0; /* default to none */
1217 if (PROP_GETA32(self
->window
, motif_wm_hints
, motif_wm_hints
,
1219 if (num
>= OB_MWM_ELEMENTS
) {
1220 self
->mwmhints
.flags
= hints
[0];
1221 self
->mwmhints
.functions
= hints
[1];
1222 self
->mwmhints
.decorations
= hints
[2];
1228 void client_get_type(ObClient
*self
)
1235 if (PROP_GETA32(self
->window
, net_wm_window_type
, atom
, &val
, &num
)) {
1236 /* use the first value that we know about in the array */
1237 for (i
= 0; i
< num
; ++i
) {
1238 if (val
[i
] == prop_atoms
.net_wm_window_type_desktop
)
1239 self
->type
= OB_CLIENT_TYPE_DESKTOP
;
1240 else if (val
[i
] == prop_atoms
.net_wm_window_type_dock
)
1241 self
->type
= OB_CLIENT_TYPE_DOCK
;
1242 else if (val
[i
] == prop_atoms
.net_wm_window_type_toolbar
)
1243 self
->type
= OB_CLIENT_TYPE_TOOLBAR
;
1244 else if (val
[i
] == prop_atoms
.net_wm_window_type_menu
)
1245 self
->type
= OB_CLIENT_TYPE_MENU
;
1246 else if (val
[i
] == prop_atoms
.net_wm_window_type_utility
)
1247 self
->type
= OB_CLIENT_TYPE_UTILITY
;
1248 else if (val
[i
] == prop_atoms
.net_wm_window_type_splash
)
1249 self
->type
= OB_CLIENT_TYPE_SPLASH
;
1250 else if (val
[i
] == prop_atoms
.net_wm_window_type_dialog
)
1251 self
->type
= OB_CLIENT_TYPE_DIALOG
;
1252 else if (val
[i
] == prop_atoms
.net_wm_window_type_normal
)
1253 self
->type
= OB_CLIENT_TYPE_NORMAL
;
1254 else if (val
[i
] == prop_atoms
.kde_net_wm_window_type_override
) {
1255 /* prevent this window from getting any decor or
1257 self
->mwmhints
.flags
&= (OB_MWM_FLAG_FUNCTIONS
|
1258 OB_MWM_FLAG_DECORATIONS
);
1259 self
->mwmhints
.decorations
= 0;
1260 self
->mwmhints
.functions
= 0;
1262 if (self
->type
!= (ObClientType
) -1)
1263 break; /* grab the first legit type */
1268 if (self
->type
== (ObClientType
) -1) {
1269 /*the window type hint was not set, which means we either classify
1270 ourself as a normal window or a dialog, depending on if we are a
1272 if (self
->transient
)
1273 self
->type
= OB_CLIENT_TYPE_DIALOG
;
1275 self
->type
= OB_CLIENT_TYPE_NORMAL
;
1279 void client_update_protocols(ObClient
*self
)
1282 guint num_return
, i
;
1284 self
->focus_notify
= FALSE
;
1285 self
->delete_window
= FALSE
;
1287 if (PROP_GETA32(self
->window
, wm_protocols
, atom
, &proto
, &num_return
)) {
1288 for (i
= 0; i
< num_return
; ++i
) {
1289 if (proto
[i
] == prop_atoms
.wm_delete_window
) {
1290 /* this means we can request the window to close */
1291 self
->delete_window
= TRUE
;
1292 } else if (proto
[i
] == prop_atoms
.wm_take_focus
)
1293 /* if this protocol is requested, then the window will be
1294 notified whenever we want it to receive focus */
1295 self
->focus_notify
= TRUE
;
1301 static void client_get_gravity(ObClient
*self
)
1303 XWindowAttributes wattrib
;
1306 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
1307 g_assert(ret
!= BadWindow
);
1308 self
->gravity
= wattrib
.win_gravity
;
1311 void client_update_normal_hints(ObClient
*self
)
1315 gint oldgravity
= self
->gravity
;
1318 self
->min_ratio
= 0.0f
;
1319 self
->max_ratio
= 0.0f
;
1320 SIZE_SET(self
->size_inc
, 1, 1);
1321 SIZE_SET(self
->base_size
, 0, 0);
1322 SIZE_SET(self
->min_size
, 0, 0);
1323 SIZE_SET(self
->max_size
, G_MAXINT
, G_MAXINT
);
1325 /* get the hints from the window */
1326 if (XGetWMNormalHints(ob_display
, self
->window
, &size
, &ret
)) {
1327 /* normal windows can't request placement! har har
1328 if (!client_normal(self))
1330 self
->positioned
= (size
.flags
& (PPosition
|USPosition
));
1332 if (size
.flags
& PWinGravity
) {
1333 self
->gravity
= size
.win_gravity
;
1335 /* if the client has a frame, i.e. has already been mapped and
1336 is changing its gravity */
1337 if (self
->frame
&& self
->gravity
!= oldgravity
) {
1338 /* move our idea of the client's position based on its new
1340 self
->area
.x
= self
->frame
->area
.x
;
1341 self
->area
.y
= self
->frame
->area
.y
;
1342 frame_frame_gravity(self
->frame
, &self
->area
.x
, &self
->area
.y
);
1346 if (size
.flags
& PAspect
) {
1347 if (size
.min_aspect
.y
)
1349 (gfloat
) size
.min_aspect
.x
/ size
.min_aspect
.y
;
1350 if (size
.max_aspect
.y
)
1352 (gfloat
) size
.max_aspect
.x
/ size
.max_aspect
.y
;
1355 if (size
.flags
& PMinSize
)
1356 SIZE_SET(self
->min_size
, size
.min_width
, size
.min_height
);
1358 if (size
.flags
& PMaxSize
)
1359 SIZE_SET(self
->max_size
, size
.max_width
, size
.max_height
);
1361 if (size
.flags
& PBaseSize
)
1362 SIZE_SET(self
->base_size
, size
.base_width
, size
.base_height
);
1364 if (size
.flags
& PResizeInc
&& size
.width_inc
&& size
.height_inc
)
1365 SIZE_SET(self
->size_inc
, size
.width_inc
, size
.height_inc
);
1369 void client_setup_decor_and_functions(ObClient
*self
)
1371 /* start with everything (cept fullscreen) */
1373 (OB_FRAME_DECOR_TITLEBAR
|
1374 OB_FRAME_DECOR_HANDLE
|
1375 OB_FRAME_DECOR_GRIPS
|
1376 OB_FRAME_DECOR_BORDER
|
1377 OB_FRAME_DECOR_ICON
|
1378 OB_FRAME_DECOR_ALLDESKTOPS
|
1379 OB_FRAME_DECOR_ICONIFY
|
1380 OB_FRAME_DECOR_MAXIMIZE
|
1381 OB_FRAME_DECOR_SHADE
|
1382 OB_FRAME_DECOR_CLOSE
);
1384 (OB_CLIENT_FUNC_RESIZE
|
1385 OB_CLIENT_FUNC_MOVE
|
1386 OB_CLIENT_FUNC_ICONIFY
|
1387 OB_CLIENT_FUNC_MAXIMIZE
|
1388 OB_CLIENT_FUNC_SHADE
|
1389 OB_CLIENT_FUNC_CLOSE
);
1391 if (!(self
->min_size
.width
< self
->max_size
.width
||
1392 self
->min_size
.height
< self
->max_size
.height
))
1393 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
1395 switch (self
->type
) {
1396 case OB_CLIENT_TYPE_NORMAL
:
1397 /* normal windows retain all of the possible decorations and
1398 functionality, and are the only windows that you can fullscreen */
1399 self
->functions
|= OB_CLIENT_FUNC_FULLSCREEN
;
1402 case OB_CLIENT_TYPE_DIALOG
:
1403 case OB_CLIENT_TYPE_UTILITY
:
1404 /* these windows cannot be maximized */
1405 self
->functions
&= ~OB_CLIENT_FUNC_MAXIMIZE
;
1408 case OB_CLIENT_TYPE_MENU
:
1409 case OB_CLIENT_TYPE_TOOLBAR
:
1410 /* these windows get less functionality */
1411 self
->functions
&= ~(OB_CLIENT_FUNC_ICONIFY
| OB_CLIENT_FUNC_RESIZE
);
1414 case OB_CLIENT_TYPE_DESKTOP
:
1415 case OB_CLIENT_TYPE_DOCK
:
1416 case OB_CLIENT_TYPE_SPLASH
:
1417 /* none of these windows are manipulated by the window manager */
1418 self
->decorations
= 0;
1419 self
->functions
= 0;
1423 /* Mwm Hints are applied subtractively to what has already been chosen for
1424 decor and functionality */
1425 if (self
->mwmhints
.flags
& OB_MWM_FLAG_DECORATIONS
) {
1426 if (! (self
->mwmhints
.decorations
& OB_MWM_DECOR_ALL
)) {
1427 if (! ((self
->mwmhints
.decorations
& OB_MWM_DECOR_HANDLE
) ||
1428 (self
->mwmhints
.decorations
& OB_MWM_DECOR_TITLE
)))
1430 /* if the mwm hints request no handle or title, then all
1431 decorations are disabled, but keep the border if that's
1433 if (self
->mwmhints
.decorations
& OB_MWM_DECOR_BORDER
)
1434 self
->decorations
= OB_FRAME_DECOR_BORDER
;
1436 self
->decorations
= 0;
1441 if (self
->mwmhints
.flags
& OB_MWM_FLAG_FUNCTIONS
) {
1442 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_ALL
)) {
1443 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_RESIZE
))
1444 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
1445 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_MOVE
))
1446 self
->functions
&= ~OB_CLIENT_FUNC_MOVE
;
1447 /* dont let mwm hints kill any buttons
1448 if (! (self->mwmhints.functions & OB_MWM_FUNC_ICONIFY))
1449 self->functions &= ~OB_CLIENT_FUNC_ICONIFY;
1450 if (! (self->mwmhints.functions & OB_MWM_FUNC_MAXIMIZE))
1451 self->functions &= ~OB_CLIENT_FUNC_MAXIMIZE;
1453 /* dont let mwm hints kill the close button
1454 if (! (self->mwmhints.functions & MwmFunc_Close))
1455 self->functions &= ~OB_CLIENT_FUNC_CLOSE; */
1459 if (!(self
->functions
& OB_CLIENT_FUNC_SHADE
))
1460 self
->decorations
&= ~OB_FRAME_DECOR_SHADE
;
1461 if (!(self
->functions
& OB_CLIENT_FUNC_ICONIFY
))
1462 self
->decorations
&= ~OB_FRAME_DECOR_ICONIFY
;
1463 if (!(self
->functions
& OB_CLIENT_FUNC_RESIZE
))
1464 self
->decorations
&= ~OB_FRAME_DECOR_GRIPS
;
1466 /* can't maximize without moving/resizing */
1467 if (!((self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) &&
1468 (self
->functions
& OB_CLIENT_FUNC_MOVE
) &&
1469 (self
->functions
& OB_CLIENT_FUNC_RESIZE
))) {
1470 self
->functions
&= ~OB_CLIENT_FUNC_MAXIMIZE
;
1471 self
->decorations
&= ~OB_FRAME_DECOR_MAXIMIZE
;
1474 /* kill the handle on fully maxed windows */
1475 if (self
->max_vert
&& self
->max_horz
)
1476 self
->decorations
&= ~OB_FRAME_DECOR_HANDLE
;
1478 /* finally, the user can have requested no decorations, which overrides
1479 everything (but doesnt give it a border if it doesnt have one) */
1480 if (self
->undecorated
) {
1481 if (config_theme_keepborder
)
1482 self
->decorations
&= OB_FRAME_DECOR_BORDER
;
1484 self
->decorations
= 0;
1487 /* if we don't have a titlebar, then we cannot shade! */
1488 if (!(self
->decorations
& OB_FRAME_DECOR_TITLEBAR
))
1489 self
->functions
&= ~OB_CLIENT_FUNC_SHADE
;
1491 /* now we need to check against rules for the client's current state */
1492 if (self
->fullscreen
) {
1493 self
->functions
&= (OB_CLIENT_FUNC_CLOSE
|
1494 OB_CLIENT_FUNC_FULLSCREEN
|
1495 OB_CLIENT_FUNC_ICONIFY
);
1496 self
->decorations
= 0;
1499 client_change_allowed_actions(self
);
1502 /* adjust the client's decorations, etc. */
1503 client_reconfigure(self
);
1507 static void client_change_allowed_actions(ObClient
*self
)
1512 /* desktop windows are kept on all desktops */
1513 if (self
->type
!= OB_CLIENT_TYPE_DESKTOP
)
1514 actions
[num
++] = prop_atoms
.net_wm_action_change_desktop
;
1516 if (self
->functions
& OB_CLIENT_FUNC_SHADE
)
1517 actions
[num
++] = prop_atoms
.net_wm_action_shade
;
1518 if (self
->functions
& OB_CLIENT_FUNC_CLOSE
)
1519 actions
[num
++] = prop_atoms
.net_wm_action_close
;
1520 if (self
->functions
& OB_CLIENT_FUNC_MOVE
)
1521 actions
[num
++] = prop_atoms
.net_wm_action_move
;
1522 if (self
->functions
& OB_CLIENT_FUNC_ICONIFY
)
1523 actions
[num
++] = prop_atoms
.net_wm_action_minimize
;
1524 if (self
->functions
& OB_CLIENT_FUNC_RESIZE
)
1525 actions
[num
++] = prop_atoms
.net_wm_action_resize
;
1526 if (self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
)
1527 actions
[num
++] = prop_atoms
.net_wm_action_fullscreen
;
1528 if (self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) {
1529 actions
[num
++] = prop_atoms
.net_wm_action_maximize_horz
;
1530 actions
[num
++] = prop_atoms
.net_wm_action_maximize_vert
;
1533 PROP_SETA32(self
->window
, net_wm_allowed_actions
, atom
, actions
, num
);
1535 /* make sure the window isn't breaking any rules now */
1537 if (!(self
->functions
& OB_CLIENT_FUNC_SHADE
) && self
->shaded
) {
1538 if (self
->frame
) client_shade(self
, FALSE
);
1539 else self
->shaded
= FALSE
;
1541 if (!(self
->functions
& OB_CLIENT_FUNC_ICONIFY
) && self
->iconic
) {
1542 if (self
->frame
) client_iconify(self
, FALSE
, TRUE
);
1543 else self
->iconic
= FALSE
;
1545 if (!(self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
) && self
->fullscreen
) {
1546 if (self
->frame
) client_fullscreen(self
, FALSE
);
1547 else self
->fullscreen
= FALSE
;
1549 if (!(self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) && (self
->max_horz
||
1551 if (self
->frame
) client_maximize(self
, FALSE
, 0);
1552 else self
->max_vert
= self
->max_horz
= FALSE
;
1556 void client_reconfigure(ObClient
*self
)
1558 /* by making this pass FALSE for user, we avoid the emacs event storm where
1559 every configurenotify causes an update in its normal hints, i think this
1560 is generally what we want anyways... */
1561 client_configure(self
, OB_CORNER_TOPLEFT
, self
->area
.x
, self
->area
.y
,
1562 self
->area
.width
, self
->area
.height
, FALSE
, TRUE
);
1565 void client_update_wmhints(ObClient
*self
)
1570 /* assume a window takes input if it doesnt specify */
1571 self
->can_focus
= TRUE
;
1573 if ((hints
= XGetWMHints(ob_display
, self
->window
)) != NULL
) {
1574 if (hints
->flags
& InputHint
)
1575 self
->can_focus
= hints
->input
;
1577 /* only do this when first managing the window *AND* when we aren't
1579 if (ob_state() != OB_STATE_STARTING
&& self
->frame
== NULL
)
1580 if (hints
->flags
& StateHint
)
1581 self
->iconic
= hints
->initial_state
== IconicState
;
1583 if (!(hints
->flags
& WindowGroupHint
))
1584 hints
->window_group
= None
;
1586 /* did the group state change? */
1587 if (hints
->window_group
!=
1588 (self
->group
? self
->group
->leader
: None
)) {
1589 /* remove from the old group if there was one */
1590 if (self
->group
!= NULL
) {
1591 /* remove transients of the group */
1592 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
))
1593 self
->transients
= g_slist_remove(self
->transients
,
1596 /* remove myself from parents in the group */
1597 if (self
->transient_for
== OB_TRAN_GROUP
) {
1598 for (it
= self
->group
->members
; it
;
1599 it
= g_slist_next(it
))
1601 ObClient
*c
= it
->data
;
1603 if (c
!= self
&& !c
->transient_for
)
1604 c
->transients
= g_slist_remove(c
->transients
,
1609 group_remove(self
->group
, self
);
1612 if (hints
->window_group
!= None
) {
1613 self
->group
= group_add(hints
->window_group
, self
);
1615 /* i can only have transients from the group if i am not
1617 if (!self
->transient_for
) {
1618 /* add other transients of the group that are already
1620 for (it
= self
->group
->members
; it
;
1621 it
= g_slist_next(it
))
1623 ObClient
*c
= it
->data
;
1624 if (c
!= self
&& c
->transient_for
== OB_TRAN_GROUP
)
1626 g_slist_append(self
->transients
, c
);
1631 /* because the self->transient flag wont change from this call,
1632 we don't need to update the window's type and such, only its
1633 transient_for, and the transients lists of other windows in
1634 the group may be affected */
1635 client_update_transient_for(self
);
1638 /* the WM_HINTS can contain an icon */
1639 client_update_icons(self
);
1645 void client_update_title(ObClient
*self
)
1651 gboolean read_title
;
1654 old_title
= self
->title
;
1657 if (!PROP_GETS(self
->window
, net_wm_name
, utf8
, &data
)) {
1658 /* try old x stuff */
1659 if (!(PROP_GETS(self
->window
, wm_name
, locale
, &data
)
1660 || PROP_GETS(self
->window
, wm_name
, utf8
, &data
))) {
1661 // http://developer.gnome.org/projects/gup/hig/draft_hig_new/windows-alert.html
1662 if (self
->transient
) {
1663 data
= g_strdup("");
1666 data
= g_strdup("Unnamed Window");
1670 if (config_title_number
) {
1672 /* did the title change? then reset the title_count */
1673 if (old_title
&& 0 != strncmp(old_title
, data
, strlen(data
)))
1674 self
->title_count
= 1;
1676 /* look for duplicates and append a number */
1678 for (it
= client_list
; it
; it
= g_list_next(it
))
1679 if (it
->data
!= self
) {
1680 ObClient
*c
= it
->data
;
1682 if (c
->title_count
== 1) {
1683 if (!strcmp(c
->title
, data
))
1684 nums
|= 1 << c
->title_count
;
1689 /* find the beginning of our " - [%u]", this relies on
1690 that syntax being used */
1691 end
= strrchr(c
->title
, '-') - 1;
1692 len
= end
- c
->title
;
1693 if (!strncmp(c
->title
, data
, len
))
1694 nums
|= 1 << c
->title_count
;
1697 /* find first free number */
1698 for (i
= 1; i
<= 32; ++i
)
1699 if (!(nums
& (1 << i
))) {
1700 if (self
->title_count
== 1 || i
== 1)
1701 self
->title_count
= i
;
1704 /* dont display the number for the first window */
1705 if (self
->title_count
> 1) {
1707 ndata
= g_strdup_printf("%s - [%u]", data
, self
->title_count
);
1712 self
->title_count
= 1;
1715 PROP_SETS(self
->window
, net_wm_visible_name
, data
);
1719 frame_adjust_title(self
->frame
);
1723 /* update the icon title */
1725 g_free(self
->icon_title
);
1729 if (!PROP_GETS(self
->window
, net_wm_icon_name
, utf8
, &data
))
1730 /* try old x stuff */
1731 if (!(PROP_GETS(self
->window
, wm_icon_name
, locale
, &data
)
1732 || PROP_GETS(self
->window
, wm_icon_name
, utf8
, &data
))) {
1733 data
= g_strdup(self
->title
);
1737 /* append the title count, dont display the number for the first window.
1738 * We don't need to check for config_title_number here since title_count
1739 * is not set above 1 then. */
1740 if (read_title
&& self
->title_count
> 1) {
1742 newdata
= g_strdup_printf("%s - [%u]", data
, self
->title_count
);
1747 PROP_SETS(self
->window
, net_wm_visible_icon_name
, data
);
1749 self
->icon_title
= data
;
1752 void client_update_class(ObClient
*self
)
1757 if (self
->name
) g_free(self
->name
);
1758 if (self
->class) g_free(self
->class);
1759 if (self
->role
) g_free(self
->role
);
1761 self
->name
= self
->class = self
->role
= NULL
;
1763 if (PROP_GETSS(self
->window
, wm_class
, locale
, &data
)) {
1765 self
->name
= g_strdup(data
[0]);
1767 self
->class = g_strdup(data
[1]);
1772 if (PROP_GETS(self
->window
, wm_window_role
, locale
, &s
))
1775 if (self
->name
== NULL
) self
->name
= g_strdup("");
1776 if (self
->class == NULL
) self
->class = g_strdup("");
1777 if (self
->role
== NULL
) self
->role
= g_strdup("");
1780 void client_update_strut(ObClient
*self
)
1784 gboolean got
= FALSE
;
1787 if (PROP_GETA32(self
->window
, net_wm_strut_partial
, cardinal
,
1791 STRUT_PARTIAL_SET(strut
,
1792 data
[0], data
[2], data
[1], data
[3],
1793 data
[4], data
[5], data
[8], data
[9],
1794 data
[6], data
[7], data
[10], data
[11]);
1800 PROP_GETA32(self
->window
, net_wm_strut
, cardinal
, &data
, &num
)) {
1806 /* use the screen's width/height */
1807 a
= screen_physical_area();
1809 STRUT_PARTIAL_SET(strut
,
1810 data
[0], data
[2], data
[1], data
[3],
1811 a
->y
, a
->y
+ a
->height
- 1,
1812 a
->x
, a
->x
+ a
->width
- 1,
1813 a
->y
, a
->y
+ a
->height
- 1,
1814 a
->x
, a
->x
+ a
->width
- 1);
1820 STRUT_PARTIAL_SET(strut
, 0, 0, 0, 0,
1821 0, 0, 0, 0, 0, 0, 0, 0);
1823 if (!STRUT_EQUAL(strut
, self
->strut
)) {
1824 self
->strut
= strut
;
1826 /* updating here is pointless while we're being mapped cuz we're not in
1827 the client list yet */
1829 screen_update_areas();
1833 void client_update_icons(ObClient
*self
)
1839 for (i
= 0; i
< self
->nicons
; ++i
)
1840 g_free(self
->icons
[i
].data
);
1841 if (self
->nicons
> 0)
1842 g_free(self
->icons
);
1845 if (PROP_GETA32(self
->window
, net_wm_icon
, cardinal
, &data
, &num
)) {
1846 /* figure out how many valid icons are in here */
1848 while (num
- i
> 2) {
1852 if (i
> num
|| w
*h
== 0) break;
1856 self
->icons
= g_new(ObClientIcon
, self
->nicons
);
1858 /* store the icons */
1860 for (j
= 0; j
< self
->nicons
; ++j
) {
1863 w
= self
->icons
[j
].width
= data
[i
++];
1864 h
= self
->icons
[j
].height
= data
[i
++];
1866 if (w
*h
== 0) continue;
1868 self
->icons
[j
].data
= g_new(RrPixel32
, w
* h
);
1869 for (x
= 0, y
= 0, t
= 0; t
< w
* h
; ++t
, ++x
, ++i
) {
1874 self
->icons
[j
].data
[t
] =
1875 (((data
[i
] >> 24) & 0xff) << RrDefaultAlphaOffset
) +
1876 (((data
[i
] >> 16) & 0xff) << RrDefaultRedOffset
) +
1877 (((data
[i
] >> 8) & 0xff) << RrDefaultGreenOffset
) +
1878 (((data
[i
] >> 0) & 0xff) << RrDefaultBlueOffset
);
1887 if ((hints
= XGetWMHints(ob_display
, self
->window
))) {
1888 if (hints
->flags
& IconPixmapHint
) {
1890 self
->icons
= g_new(ObClientIcon
, self
->nicons
);
1891 xerror_set_ignore(TRUE
);
1892 if (!RrPixmapToRGBA(ob_rr_inst
,
1894 (hints
->flags
& IconMaskHint
?
1895 hints
->icon_mask
: None
),
1896 &self
->icons
[self
->nicons
-1].width
,
1897 &self
->icons
[self
->nicons
-1].height
,
1898 &self
->icons
[self
->nicons
-1].data
)){
1899 g_free(&self
->icons
[self
->nicons
-1]);
1902 xerror_set_ignore(FALSE
);
1909 frame_adjust_icon(self
->frame
);
1912 void client_update_user_time(ObClient
*self
, gboolean new_event
)
1916 if (PROP_GET32(self
->window
, net_wm_user_time
, cardinal
, &time
)) {
1917 self
->user_time
= time
;
1918 /* we set this every time, not just when it grows, because in practice
1919 sometimes time goes backwards! (ntpdate.. yay....) so.. if it goes
1920 backward we don't want all windows to stop focusing. we'll just
1921 assume noone is setting times older than the last one, cuz that
1922 would be pretty stupid anyways
1923 However! This is called when a window is mapped to get its user time
1924 but it's an old number, it's not changing it from new user
1925 interaction, so in that case, don't change the last user time.
1928 client_last_user_time
= time
;
1930 /*ob_debug("window 0x%x user time %u\n", self->window, time);*/
1934 static void client_change_wm_state(ObClient
*self
)
1939 old
= self
->wmstate
;
1941 if (self
->shaded
|| self
->iconic
|| !self
->frame
->visible
)
1942 self
->wmstate
= IconicState
;
1944 self
->wmstate
= NormalState
;
1946 if (old
!= self
->wmstate
) {
1947 PROP_MSG(self
->window
, kde_wm_change_state
,
1948 self
->wmstate
, 1, 0, 0);
1950 state
[0] = self
->wmstate
;
1952 PROP_SETA32(self
->window
, wm_state
, wm_state
, state
, 2);
1956 static void client_change_state(ObClient
*self
)
1958 gulong netstate
[11];
1963 netstate
[num
++] = prop_atoms
.net_wm_state_modal
;
1965 netstate
[num
++] = prop_atoms
.net_wm_state_shaded
;
1967 netstate
[num
++] = prop_atoms
.net_wm_state_hidden
;
1968 if (self
->skip_taskbar
)
1969 netstate
[num
++] = prop_atoms
.net_wm_state_skip_taskbar
;
1970 if (self
->skip_pager
)
1971 netstate
[num
++] = prop_atoms
.net_wm_state_skip_pager
;
1972 if (self
->fullscreen
)
1973 netstate
[num
++] = prop_atoms
.net_wm_state_fullscreen
;
1975 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_vert
;
1977 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_horz
;
1979 netstate
[num
++] = prop_atoms
.net_wm_state_above
;
1981 netstate
[num
++] = prop_atoms
.net_wm_state_below
;
1982 if (self
->demands_attention
)
1983 netstate
[num
++] = prop_atoms
.net_wm_state_demands_attention
;
1984 if (self
->undecorated
)
1985 netstate
[num
++] = prop_atoms
.ob_wm_state_undecorated
;
1986 PROP_SETA32(self
->window
, net_wm_state
, atom
, netstate
, num
);
1989 frame_adjust_state(self
->frame
);
1992 ObClient
*client_search_focus_tree(ObClient
*self
)
1997 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
1998 if (client_focused(it
->data
)) return it
->data
;
1999 if ((ret
= client_search_focus_tree(it
->data
))) return ret
;
2004 ObClient
*client_search_focus_tree_full(ObClient
*self
)
2006 if (self
->transient_for
) {
2007 if (self
->transient_for
!= OB_TRAN_GROUP
) {
2008 return client_search_focus_tree_full(self
->transient_for
);
2011 gboolean recursed
= FALSE
;
2013 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
))
2014 if (!((ObClient
*)it
->data
)->transient_for
) {
2016 if ((c
= client_search_focus_tree_full(it
->data
)))
2025 /* this function checks the whole tree, the client_search_focus_tree~
2026 does not, so we need to check this window */
2027 if (client_focused(self
))
2029 return client_search_focus_tree(self
);
2032 static ObStackingLayer
calc_layer(ObClient
*self
)
2036 if (self
->fullscreen
&&
2037 (client_focused(self
) || client_search_focus_tree(self
)))
2038 l
= OB_STACKING_LAYER_FULLSCREEN
;
2039 else if (self
->type
== OB_CLIENT_TYPE_DESKTOP
)
2040 l
= OB_STACKING_LAYER_DESKTOP
;
2041 else if (self
->type
== OB_CLIENT_TYPE_DOCK
) {
2042 if (self
->below
) l
= OB_STACKING_LAYER_NORMAL
;
2043 else l
= OB_STACKING_LAYER_ABOVE
;
2045 else if (self
->above
) l
= OB_STACKING_LAYER_ABOVE
;
2046 else if (self
->below
) l
= OB_STACKING_LAYER_BELOW
;
2047 else l
= OB_STACKING_LAYER_NORMAL
;
2052 static void client_calc_layer_recursive(ObClient
*self
, ObClient
*orig
,
2053 ObStackingLayer min
, gboolean raised
)
2055 ObStackingLayer old
, own
;
2059 own
= calc_layer(self
);
2060 self
->layer
= MAX(own
, min
);
2062 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
2063 client_calc_layer_recursive(it
->data
, orig
,
2065 raised
? raised
: self
->layer
!= old
);
2067 if (!raised
&& self
->layer
!= old
)
2068 if (orig
->frame
) { /* only restack if the original window is managed */
2069 stacking_remove(CLIENT_AS_WINDOW(self
));
2070 stacking_add(CLIENT_AS_WINDOW(self
));
2074 void client_calc_layer(ObClient
*self
)
2081 /* transients take on the layer of their parents */
2082 it
= client_search_all_top_parents(self
);
2084 for (; it
; it
= g_slist_next(it
))
2085 client_calc_layer_recursive(it
->data
, orig
, 0, FALSE
);
2088 gboolean
client_should_show(ObClient
*self
)
2092 if (client_normal(self
) && screen_showing_desktop
)
2095 if (self->transient_for) {
2096 if (self->transient_for != OB_TRAN_GROUP)
2097 return client_should_show(self->transient_for);
2101 for (it = self->group->members; it; it = g_slist_next(it)) {
2102 ObClient *c = it->data;
2103 if (c != self && !c->transient_for) {
2104 if (client_should_show(c))
2111 if (self
->desktop
== screen_desktop
|| self
->desktop
== DESKTOP_ALL
)
2117 void client_showhide(ObClient
*self
)
2120 if (client_should_show(self
)) {
2121 frame_show(self
->frame
);
2124 frame_hide(self
->frame
);
2126 /* Fall back focus since we're disappearing */
2127 if (focus_client
== self
)
2128 client_unfocus(self
);
2131 /* According to the ICCCM (sec 4.1.3.1) when a window is not visible, it
2132 needs to be in IconicState. This includes when it is on another
2135 client_change_wm_state(self
);
2138 gboolean
client_normal(ObClient
*self
) {
2139 return ! (self
->type
== OB_CLIENT_TYPE_DESKTOP
||
2140 self
->type
== OB_CLIENT_TYPE_DOCK
||
2141 self
->type
== OB_CLIENT_TYPE_SPLASH
);
2144 static void client_apply_startup_state(ObClient
*self
, gint x
, gint y
)
2146 gboolean pos
= FALSE
; /* has the window's position been configured? */
2149 /* save the position, and set self->area for these to use */
2155 /* these are in a carefully crafted order.. */
2158 self
->iconic
= FALSE
;
2159 client_iconify(self
, TRUE
, FALSE
);
2161 if (self
->fullscreen
) {
2162 self
->fullscreen
= FALSE
;
2163 client_fullscreen(self
, TRUE
);
2166 if (self
->undecorated
) {
2167 self
->undecorated
= FALSE
;
2168 client_set_undecorated(self
, TRUE
);
2171 self
->shaded
= FALSE
;
2172 client_shade(self
, TRUE
);
2174 if (self
->demands_attention
) {
2175 self
->demands_attention
= FALSE
;
2176 client_hilite(self
, TRUE
);
2179 if (self
->max_vert
&& self
->max_horz
) {
2180 self
->max_vert
= self
->max_horz
= FALSE
;
2181 client_maximize(self
, TRUE
, 0);
2183 } else if (self
->max_vert
) {
2184 self
->max_vert
= FALSE
;
2185 client_maximize(self
, TRUE
, 2);
2187 } else if (self
->max_horz
) {
2188 self
->max_horz
= FALSE
;
2189 client_maximize(self
, TRUE
, 1);
2193 /* if the client didn't get positioned yet, then do so now */
2194 if (!pos
&& (ox
!= x
|| oy
!= y
)) {
2195 /* use the saved position */
2198 client_move(self
, x
, y
);
2201 /* nothing to do for the other states:
2210 void client_try_configure(ObClient
*self
, ObCorner anchor
,
2211 gint
*x
, gint
*y
, gint
*w
, gint
*h
,
2212 gint
*logicalw
, gint
*logicalh
,
2215 Rect desired_area
= {*x
, *y
, *w
, *h
};
2217 /* make the frame recalculate its dimentions n shit without changing
2218 anything visible for real, this way the constraints below can work with
2219 the updated frame dimensions. */
2220 frame_adjust_area(self
->frame
, TRUE
, TRUE
, TRUE
);
2222 /* gets the frame's position */
2223 frame_client_gravity(self
->frame
, x
, y
);
2225 /* these positions are frame positions, not client positions */
2227 /* set the size and position if fullscreen */
2228 if (self
->fullscreen
) {
2232 i
= screen_find_monitor(&desired_area
);
2233 a
= screen_physical_area_monitor(i
);
2240 user
= FALSE
; /* ignore that increment etc shit when in fullscreen */
2245 i
= screen_find_monitor(&desired_area
);
2246 a
= screen_area_monitor(self
->desktop
, i
);
2248 /* set the size and position if maximized */
2249 if (self
->max_horz
) {
2251 *w
= a
->width
- self
->frame
->size
.left
- self
->frame
->size
.right
;
2253 if (self
->max_vert
) {
2255 *h
= a
->height
- self
->frame
->size
.top
- self
->frame
->size
.bottom
;
2259 /* gets the client's position */
2260 frame_frame_gravity(self
->frame
, x
, y
);
2262 /* these override the above states! if you cant move you can't move! */
2264 if (!(self
->functions
& OB_CLIENT_FUNC_MOVE
)) {
2268 if (!(self
->functions
& OB_CLIENT_FUNC_RESIZE
)) {
2269 *w
= self
->area
.width
;
2270 *h
= self
->area
.height
;
2274 if (!(*w
== self
->area
.width
&& *h
== self
->area
.height
)) {
2275 gint basew
, baseh
, minw
, minh
;
2277 /* base size is substituted with min size if not specified */
2278 if (self
->base_size
.width
|| self
->base_size
.height
) {
2279 basew
= self
->base_size
.width
;
2280 baseh
= self
->base_size
.height
;
2282 basew
= self
->min_size
.width
;
2283 baseh
= self
->min_size
.height
;
2285 /* min size is substituted with base size if not specified */
2286 if (self
->min_size
.width
|| self
->min_size
.height
) {
2287 minw
= self
->min_size
.width
;
2288 minh
= self
->min_size
.height
;
2290 minw
= self
->base_size
.width
;
2291 minh
= self
->base_size
.height
;
2294 /* if this is a user-requested resize, then check against min/max
2297 /* smaller than min size or bigger than max size? */
2298 if (*w
> self
->max_size
.width
) *w
= self
->max_size
.width
;
2299 if (*w
< minw
) *w
= minw
;
2300 if (*h
> self
->max_size
.height
) *h
= self
->max_size
.height
;
2301 if (*h
< minh
) *h
= minh
;
2306 /* keep to the increments */
2307 *w
/= self
->size_inc
.width
;
2308 *h
/= self
->size_inc
.height
;
2310 /* you cannot resize to nothing */
2311 if (basew
+ *w
< 1) *w
= 1 - basew
;
2312 if (baseh
+ *h
< 1) *h
= 1 - baseh
;
2314 /* save the logical size */
2315 *logicalw
= self
->size_inc
.width
> 1 ? *w
: *w
+ basew
;
2316 *logicalh
= self
->size_inc
.height
> 1 ? *h
: *h
+ baseh
;
2318 *w
*= self
->size_inc
.width
;
2319 *h
*= self
->size_inc
.height
;
2324 /* adjust the height to match the width for the aspect ratios.
2325 for this, min size is not substituted for base size ever. */
2326 *w
-= self
->base_size
.width
;
2327 *h
-= self
->base_size
.height
;
2329 if (!self
->fullscreen
) {
2330 if (self
->min_ratio
)
2331 if (*h
* self
->min_ratio
> *w
) {
2332 *h
= (gint
)(*w
/ self
->min_ratio
);
2334 /* you cannot resize to nothing */
2337 *w
= (gint
)(*h
* self
->min_ratio
);
2340 if (self
->max_ratio
)
2341 if (*h
* self
->max_ratio
< *w
) {
2342 *h
= (gint
)(*w
/ self
->max_ratio
);
2344 /* you cannot resize to nothing */
2347 *w
= (gint
)(*h
* self
->min_ratio
);
2352 *w
+= self
->base_size
.width
;
2353 *h
+= self
->base_size
.height
;
2360 case OB_CORNER_TOPLEFT
:
2362 case OB_CORNER_TOPRIGHT
:
2363 *x
-= *w
- self
->area
.width
;
2365 case OB_CORNER_BOTTOMLEFT
:
2366 *y
-= *h
- self
->area
.height
;
2368 case OB_CORNER_BOTTOMRIGHT
:
2369 *x
-= *w
- self
->area
.width
;
2370 *y
-= *h
- self
->area
.height
;
2376 void client_configure_full(ObClient
*self
, ObCorner anchor
,
2377 gint x
, gint y
, gint w
, gint h
,
2378 gboolean user
, gboolean final
,
2379 gboolean force_reply
)
2382 gboolean send_resize_client
;
2383 gboolean moved
= FALSE
, resized
= FALSE
;
2384 guint fdecor
= self
->frame
->decorations
;
2385 gboolean fhorz
= self
->frame
->max_horz
;
2386 gint logicalw
, logicalh
;
2388 /* find the new x, y, width, and height (and logical size) */
2389 client_try_configure(self
, anchor
, &x
, &y
, &w
, &h
,
2390 &logicalw
, &logicalh
, user
);
2392 /* set the logical size if things changed */
2393 if (!(w
== self
->area
.width
&& h
== self
->area
.height
))
2394 SIZE_SET(self
->logical_size
, logicalw
, logicalh
);
2396 /* figure out if we moved or resized or what */
2397 moved
= x
!= self
->area
.x
|| y
!= self
->area
.y
;
2398 resized
= w
!= self
->area
.width
|| h
!= self
->area
.height
;
2400 oldw
= self
->area
.width
;
2401 oldh
= self
->area
.height
;
2402 RECT_SET(self
->area
, x
, y
, w
, h
);
2404 /* for app-requested resizes, always resize if 'resized' is true.
2405 for user-requested ones, only resize if final is true, or when
2406 resizing in redraw mode */
2407 send_resize_client
= ((!user
&& resized
) ||
2409 (resized
&& config_resize_redraw
))));
2411 /* if the client is enlarging, then resize the client before the frame */
2412 if (send_resize_client
&& user
&& (w
> oldw
|| h
> oldh
))
2413 XResizeWindow(ob_display
, self
->window
, MAX(w
, oldw
), MAX(h
, oldh
));
2415 /* move/resize the frame to match the request */
2417 if (self
->decorations
!= fdecor
|| self
->max_horz
!= fhorz
)
2418 moved
= resized
= TRUE
;
2420 if (moved
|| resized
)
2421 frame_adjust_area(self
->frame
, moved
, resized
, FALSE
);
2423 if (!resized
&& (force_reply
|| ((!user
&& moved
) || (user
&& final
))))
2426 event
.type
= ConfigureNotify
;
2427 event
.xconfigure
.display
= ob_display
;
2428 event
.xconfigure
.event
= self
->window
;
2429 event
.xconfigure
.window
= self
->window
;
2431 /* root window real coords */
2432 event
.xconfigure
.x
= self
->frame
->area
.x
+ self
->frame
->size
.left
-
2434 event
.xconfigure
.y
= self
->frame
->area
.y
+ self
->frame
->size
.top
-
2436 event
.xconfigure
.width
= w
;
2437 event
.xconfigure
.height
= h
;
2438 event
.xconfigure
.border_width
= 0;
2439 event
.xconfigure
.above
= self
->frame
->plate
;
2440 event
.xconfigure
.override_redirect
= FALSE
;
2441 XSendEvent(event
.xconfigure
.display
, event
.xconfigure
.window
,
2442 FALSE
, StructureNotifyMask
, &event
);
2446 /* if the client is shrinking, then resize the frame before the client */
2447 if (send_resize_client
&& (!user
|| (w
<= oldw
|| h
<= oldh
)))
2448 XResizeWindow(ob_display
, self
->window
, w
, h
);
2453 void client_fullscreen(ObClient
*self
, gboolean fs
)
2457 if (!(self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
) || /* can't */
2458 self
->fullscreen
== fs
) return; /* already done */
2460 self
->fullscreen
= fs
;
2461 client_change_state(self
); /* change the state hints on the client */
2462 client_calc_layer(self
); /* and adjust out layer/stacking */
2465 self
->pre_fullscreen_area
= self
->area
;
2466 /* if the window is maximized, its area isn't all that meaningful.
2467 save it's premax area instead. */
2468 if (self
->max_horz
) {
2469 self
->pre_fullscreen_area
.x
= self
->pre_max_area
.x
;
2470 self
->pre_fullscreen_area
.width
= self
->pre_max_area
.width
;
2472 if (self
->max_vert
) {
2473 self
->pre_fullscreen_area
.y
= self
->pre_max_area
.y
;
2474 self
->pre_fullscreen_area
.height
= self
->pre_max_area
.height
;
2477 /* these are not actually used cuz client_configure will set them
2478 as appropriate when the window is fullscreened */
2483 if (self
->pre_fullscreen_area
.width
> 0 &&
2484 self
->pre_fullscreen_area
.height
> 0)
2486 x
= self
->pre_fullscreen_area
.x
;
2487 y
= self
->pre_fullscreen_area
.y
;
2488 w
= self
->pre_fullscreen_area
.width
;
2489 h
= self
->pre_fullscreen_area
.height
;
2490 RECT_SET(self
->pre_fullscreen_area
, 0, 0, 0, 0);
2492 /* pick some fallbacks... */
2493 a
= screen_area_monitor(self
->desktop
, 0);
2494 x
= a
->x
+ a
->width
/ 4;
2495 y
= a
->y
+ a
->height
/ 4;
2501 client_setup_decor_and_functions(self
);
2503 client_move_resize(self
, x
, y
, w
, h
);
2505 /* try focus us when we go into fullscreen mode */
2509 static void client_iconify_recursive(ObClient
*self
,
2510 gboolean iconic
, gboolean curdesk
)
2513 gboolean changed
= FALSE
;
2516 if (self
->iconic
!= iconic
) {
2517 ob_debug("%sconifying window: 0x%lx\n", (iconic
? "I" : "Uni"),
2521 if (self
->functions
& OB_CLIENT_FUNC_ICONIFY
) {
2522 self
->iconic
= iconic
;
2524 /* update the focus lists.. iconic windows go to the bottom of
2525 the list, put the new iconic window at the 'top of the
2527 focus_order_to_top(self
);
2532 self
->iconic
= iconic
;
2535 client_set_desktop(self
, screen_desktop
, FALSE
);
2537 /* this puts it after the current focused window */
2538 focus_order_remove(self
);
2539 focus_order_add_new(self
);
2546 client_change_state(self
);
2547 client_showhide(self
);
2548 if (STRUT_EXISTS(self
->strut
))
2549 screen_update_areas();
2552 /* iconify all direct transients */
2553 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
2554 if (it
->data
!= self
)
2555 if (client_is_direct_child(self
, it
->data
))
2556 client_iconify_recursive(it
->data
, iconic
, curdesk
);
2559 void client_iconify(ObClient
*self
, gboolean iconic
, gboolean curdesk
)
2561 /* move up the transient chain as far as possible first */
2562 self
= client_search_top_parent(self
);
2563 client_iconify_recursive(self
, iconic
, curdesk
);
2566 void client_maximize(ObClient
*self
, gboolean max
, gint dir
)
2570 g_assert(dir
== 0 || dir
== 1 || dir
== 2);
2571 if (!(self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
)) return; /* can't */
2573 /* check if already done */
2575 if (dir
== 0 && self
->max_horz
&& self
->max_vert
) return;
2576 if (dir
== 1 && self
->max_horz
) return;
2577 if (dir
== 2 && self
->max_vert
) return;
2579 if (dir
== 0 && !self
->max_horz
&& !self
->max_vert
) return;
2580 if (dir
== 1 && !self
->max_horz
) return;
2581 if (dir
== 2 && !self
->max_vert
) return;
2584 /* we just tell it to configure in the same place and client_configure
2585 worries about filling the screen with the window */
2588 w
= self
->area
.width
;
2589 h
= self
->area
.height
;
2592 if ((dir
== 0 || dir
== 1) && !self
->max_horz
) { /* horz */
2593 RECT_SET(self
->pre_max_area
,
2594 self
->area
.x
, self
->pre_max_area
.y
,
2595 self
->area
.width
, self
->pre_max_area
.height
);
2597 if ((dir
== 0 || dir
== 2) && !self
->max_vert
) { /* vert */
2598 RECT_SET(self
->pre_max_area
,
2599 self
->pre_max_area
.x
, self
->area
.y
,
2600 self
->pre_max_area
.width
, self
->area
.height
);
2605 a
= screen_area_monitor(self
->desktop
, 0);
2606 if ((dir
== 0 || dir
== 1) && self
->max_horz
) { /* horz */
2607 if (self
->pre_max_area
.width
> 0) {
2608 x
= self
->pre_max_area
.x
;
2609 w
= self
->pre_max_area
.width
;
2611 RECT_SET(self
->pre_max_area
, 0, self
->pre_max_area
.y
,
2612 0, self
->pre_max_area
.height
);
2614 /* pick some fallbacks... */
2615 x
= a
->x
+ a
->width
/ 4;
2619 if ((dir
== 0 || dir
== 2) && self
->max_vert
) { /* vert */
2620 if (self
->pre_max_area
.height
> 0) {
2621 y
= self
->pre_max_area
.y
;
2622 h
= self
->pre_max_area
.height
;
2624 RECT_SET(self
->pre_max_area
, self
->pre_max_area
.x
, 0,
2625 self
->pre_max_area
.width
, 0);
2627 /* pick some fallbacks... */
2628 y
= a
->y
+ a
->height
/ 4;
2634 if (dir
== 0 || dir
== 1) /* horz */
2635 self
->max_horz
= max
;
2636 if (dir
== 0 || dir
== 2) /* vert */
2637 self
->max_vert
= max
;
2639 client_change_state(self
); /* change the state hints on the client */
2641 client_setup_decor_and_functions(self
);
2643 client_move_resize(self
, x
, y
, w
, h
);
2646 void client_shade(ObClient
*self
, gboolean shade
)
2648 if ((!(self
->functions
& OB_CLIENT_FUNC_SHADE
) &&
2649 shade
) || /* can't shade */
2650 self
->shaded
== shade
) return; /* already done */
2652 self
->shaded
= shade
;
2653 client_change_state(self
);
2654 client_change_wm_state(self
); /* the window is being hidden/shown */
2655 /* resize the frame to just the titlebar */
2656 frame_adjust_area(self
->frame
, FALSE
, FALSE
, FALSE
);
2659 void client_close(ObClient
*self
)
2663 if (!(self
->functions
& OB_CLIENT_FUNC_CLOSE
)) return;
2665 /* in the case that the client provides no means to requesting that it
2666 close, we just kill it */
2667 if (!self
->delete_window
)
2671 XXX: itd be cool to do timeouts and shit here for killing the client's
2673 like... if the window is around after 5 seconds, then the close button
2674 turns a nice red, and if this function is called again, the client is
2678 ce
.xclient
.type
= ClientMessage
;
2679 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
2680 ce
.xclient
.display
= ob_display
;
2681 ce
.xclient
.window
= self
->window
;
2682 ce
.xclient
.format
= 32;
2683 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_delete_window
;
2684 ce
.xclient
.data
.l
[1] = event_curtime
;
2685 ce
.xclient
.data
.l
[2] = 0l;
2686 ce
.xclient
.data
.l
[3] = 0l;
2687 ce
.xclient
.data
.l
[4] = 0l;
2688 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
2691 void client_kill(ObClient
*self
)
2693 XKillClient(ob_display
, self
->window
);
2696 void client_hilite(ObClient
*self
, gboolean hilite
)
2698 if (self
->demands_attention
== hilite
)
2699 return; /* no change */
2701 /* don't allow focused windows to hilite */
2702 self
->demands_attention
= hilite
&& !client_focused(self
);
2703 if (self
->demands_attention
)
2704 frame_flash_start(self
->frame
);
2706 frame_flash_stop(self
->frame
);
2707 client_change_state(self
);
2710 void client_set_desktop_recursive(ObClient
*self
,
2711 guint target
, gboolean donthide
)
2716 if (target
!= self
->desktop
) {
2718 ob_debug("Setting desktop %u\n", target
+1);
2720 g_assert(target
< screen_num_desktops
|| target
== DESKTOP_ALL
);
2722 /* remove from the old desktop(s) */
2723 focus_order_remove(self
);
2725 old
= self
->desktop
;
2726 self
->desktop
= target
;
2727 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, target
);
2728 /* the frame can display the current desktop state */
2729 frame_adjust_state(self
->frame
);
2730 /* 'move' the window to the new desktop */
2732 client_showhide(self
);
2733 /* raise if it was not already on the desktop */
2734 if (old
!= DESKTOP_ALL
)
2736 if (STRUT_EXISTS(self
->strut
))
2737 screen_update_areas();
2739 /* add to the new desktop(s) */
2740 if (config_focus_new
)
2741 focus_order_to_top(self
);
2743 focus_order_to_bottom(self
);
2746 /* move all transients */
2747 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
2748 if (it
->data
!= self
)
2749 if (client_is_direct_child(self
, it
->data
))
2750 client_set_desktop_recursive(it
->data
, target
, donthide
);
2753 void client_set_desktop(ObClient
*self
, guint target
, gboolean donthide
)
2755 self
= client_search_top_parent(self
);
2756 client_set_desktop_recursive(self
, target
, donthide
);
2759 gboolean
client_is_direct_child(ObClient
*parent
, ObClient
*child
)
2761 while (child
!= parent
&&
2762 child
->transient_for
&& child
->transient_for
!= OB_TRAN_GROUP
)
2763 child
= child
->transient_for
;
2764 return child
== parent
;
2767 ObClient
*client_search_modal_child(ObClient
*self
)
2772 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
2773 ObClient
*c
= it
->data
;
2774 if ((ret
= client_search_modal_child(c
))) return ret
;
2775 if (c
->modal
) return c
;
2780 gboolean
client_validate(ObClient
*self
)
2784 XSync(ob_display
, FALSE
); /* get all events on the server */
2786 if (XCheckTypedWindowEvent(ob_display
, self
->window
, DestroyNotify
, &e
) ||
2787 XCheckTypedWindowEvent(ob_display
, self
->window
, UnmapNotify
, &e
)) {
2788 XPutBackEvent(ob_display
, &e
);
2795 void client_set_wm_state(ObClient
*self
, glong state
)
2797 if (state
== self
->wmstate
) return; /* no change */
2801 client_iconify(self
, TRUE
, TRUE
);
2804 client_iconify(self
, FALSE
, TRUE
);
2809 void client_set_state(ObClient
*self
, Atom action
, glong data1
, glong data2
)
2811 gboolean shaded
= self
->shaded
;
2812 gboolean fullscreen
= self
->fullscreen
;
2813 gboolean undecorated
= self
->undecorated
;
2814 gboolean max_horz
= self
->max_horz
;
2815 gboolean max_vert
= self
->max_vert
;
2816 gboolean modal
= self
->modal
;
2817 gboolean iconic
= self
->iconic
;
2818 gboolean demands_attention
= self
->demands_attention
;
2821 if (!(action
== prop_atoms
.net_wm_state_add
||
2822 action
== prop_atoms
.net_wm_state_remove
||
2823 action
== prop_atoms
.net_wm_state_toggle
))
2824 /* an invalid action was passed to the client message, ignore it */
2827 for (i
= 0; i
< 2; ++i
) {
2828 Atom state
= i
== 0 ? data1
: data2
;
2830 if (!state
) continue;
2832 /* if toggling, then pick whether we're adding or removing */
2833 if (action
== prop_atoms
.net_wm_state_toggle
) {
2834 if (state
== prop_atoms
.net_wm_state_modal
)
2835 action
= modal
? prop_atoms
.net_wm_state_remove
:
2836 prop_atoms
.net_wm_state_add
;
2837 else if (state
== prop_atoms
.net_wm_state_maximized_vert
)
2838 action
= self
->max_vert
? prop_atoms
.net_wm_state_remove
:
2839 prop_atoms
.net_wm_state_add
;
2840 else if (state
== prop_atoms
.net_wm_state_maximized_horz
)
2841 action
= self
->max_horz
? prop_atoms
.net_wm_state_remove
:
2842 prop_atoms
.net_wm_state_add
;
2843 else if (state
== prop_atoms
.net_wm_state_shaded
)
2844 action
= shaded
? prop_atoms
.net_wm_state_remove
:
2845 prop_atoms
.net_wm_state_add
;
2846 else if (state
== prop_atoms
.net_wm_state_skip_taskbar
)
2847 action
= self
->skip_taskbar
?
2848 prop_atoms
.net_wm_state_remove
:
2849 prop_atoms
.net_wm_state_add
;
2850 else if (state
== prop_atoms
.net_wm_state_skip_pager
)
2851 action
= self
->skip_pager
?
2852 prop_atoms
.net_wm_state_remove
:
2853 prop_atoms
.net_wm_state_add
;
2854 else if (state
== prop_atoms
.net_wm_state_hidden
)
2855 action
= self
->iconic
?
2856 prop_atoms
.net_wm_state_remove
:
2857 prop_atoms
.net_wm_state_add
;
2858 else if (state
== prop_atoms
.net_wm_state_fullscreen
)
2859 action
= fullscreen
?
2860 prop_atoms
.net_wm_state_remove
:
2861 prop_atoms
.net_wm_state_add
;
2862 else if (state
== prop_atoms
.net_wm_state_above
)
2863 action
= self
->above
? prop_atoms
.net_wm_state_remove
:
2864 prop_atoms
.net_wm_state_add
;
2865 else if (state
== prop_atoms
.net_wm_state_below
)
2866 action
= self
->below
? prop_atoms
.net_wm_state_remove
:
2867 prop_atoms
.net_wm_state_add
;
2868 else if (state
== prop_atoms
.net_wm_state_demands_attention
)
2869 action
= self
->demands_attention
?
2870 prop_atoms
.net_wm_state_remove
:
2871 prop_atoms
.net_wm_state_add
;
2872 else if (state
== prop_atoms
.ob_wm_state_undecorated
)
2873 action
= undecorated
? prop_atoms
.net_wm_state_remove
:
2874 prop_atoms
.net_wm_state_add
;
2877 if (action
== prop_atoms
.net_wm_state_add
) {
2878 if (state
== prop_atoms
.net_wm_state_modal
) {
2880 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
2882 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
2884 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
2886 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
2887 self
->skip_taskbar
= TRUE
;
2888 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
2889 self
->skip_pager
= TRUE
;
2890 } else if (state
== prop_atoms
.net_wm_state_hidden
) {
2892 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
2894 } else if (state
== prop_atoms
.net_wm_state_above
) {
2896 self
->below
= FALSE
;
2897 } else if (state
== prop_atoms
.net_wm_state_below
) {
2898 self
->above
= FALSE
;
2900 } else if (state
== prop_atoms
.net_wm_state_demands_attention
) {
2901 demands_attention
= TRUE
;
2902 } else if (state
== prop_atoms
.ob_wm_state_undecorated
) {
2906 } else { /* action == prop_atoms.net_wm_state_remove */
2907 if (state
== prop_atoms
.net_wm_state_modal
) {
2909 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
2911 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
2913 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
2915 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
2916 self
->skip_taskbar
= FALSE
;
2917 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
2918 self
->skip_pager
= FALSE
;
2919 } else if (state
== prop_atoms
.net_wm_state_hidden
) {
2921 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
2923 } else if (state
== prop_atoms
.net_wm_state_above
) {
2924 self
->above
= FALSE
;
2925 } else if (state
== prop_atoms
.net_wm_state_below
) {
2926 self
->below
= FALSE
;
2927 } else if (state
== prop_atoms
.net_wm_state_demands_attention
) {
2928 demands_attention
= FALSE
;
2929 } else if (state
== prop_atoms
.ob_wm_state_undecorated
) {
2930 undecorated
= FALSE
;
2934 if (max_horz
!= self
->max_horz
|| max_vert
!= self
->max_vert
) {
2935 if (max_horz
!= self
->max_horz
&& max_vert
!= self
->max_vert
) {
2937 if (max_horz
== max_vert
) { /* both going the same way */
2938 client_maximize(self
, max_horz
, 0);
2940 client_maximize(self
, max_horz
, 1);
2941 client_maximize(self
, max_vert
, 2);
2945 if (max_horz
!= self
->max_horz
)
2946 client_maximize(self
, max_horz
, 1);
2948 client_maximize(self
, max_vert
, 2);
2951 /* change fullscreen state before shading, as it will affect if the window
2953 if (fullscreen
!= self
->fullscreen
)
2954 client_fullscreen(self
, fullscreen
);
2955 if (shaded
!= self
->shaded
)
2956 client_shade(self
, shaded
);
2957 if (undecorated
!= self
->undecorated
)
2958 client_set_undecorated(self
, undecorated
);
2959 if (modal
!= self
->modal
) {
2960 self
->modal
= modal
;
2961 /* when a window changes modality, then its stacking order with its
2962 transients needs to change */
2965 if (iconic
!= self
->iconic
)
2966 client_iconify(self
, iconic
, FALSE
);
2968 if (demands_attention
!= self
->demands_attention
)
2969 client_hilite(self
, demands_attention
);
2971 client_change_state(self
); /* change the hint to reflect these changes */
2974 ObClient
*client_focus_target(ObClient
*self
)
2976 ObClient
*child
= NULL
;
2978 child
= client_search_modal_child(self
);
2979 if (child
) return child
;
2983 gboolean
client_can_focus(ObClient
*self
)
2987 /* choose the correct target */
2988 self
= client_focus_target(self
);
2990 if (!self
->frame
->visible
)
2993 if (!(self
->can_focus
|| self
->focus_notify
))
2996 /* do a check to see if the window has already been unmapped or destroyed
2997 do this intelligently while watching out for unmaps we've generated
2998 (ignore_unmaps > 0) */
2999 if (XCheckTypedWindowEvent(ob_display
, self
->window
,
3000 DestroyNotify
, &ev
)) {
3001 XPutBackEvent(ob_display
, &ev
);
3004 while (XCheckTypedWindowEvent(ob_display
, self
->window
,
3005 UnmapNotify
, &ev
)) {
3006 if (self
->ignore_unmaps
) {
3007 self
->ignore_unmaps
--;
3009 XPutBackEvent(ob_display
, &ev
);
3017 gboolean
client_focus(ObClient
*self
)
3019 /* choose the correct target */
3020 self
= client_focus_target(self
);
3023 if (!client_validate(self
))
3027 if (!client_can_focus(self
)) {
3028 if (!self
->frame
->visible
) {
3029 /* update the focus lists */
3030 focus_order_to_top(self
);
3035 ob_debug("Focusing client \"%s\" at time %u\n", self
->title
, event_curtime
);
3037 if (self
->can_focus
) {
3038 XSetInputFocus(ob_display
, self
->window
, RevertToPointerRoot
,
3042 if (self
->focus_notify
) {
3044 ce
.xclient
.type
= ClientMessage
;
3045 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
3046 ce
.xclient
.display
= ob_display
;
3047 ce
.xclient
.window
= self
->window
;
3048 ce
.xclient
.format
= 32;
3049 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_take_focus
;
3050 ce
.xclient
.data
.l
[1] = event_curtime
;
3051 ce
.xclient
.data
.l
[2] = 0l;
3052 ce
.xclient
.data
.l
[3] = 0l;
3053 ce
.xclient
.data
.l
[4] = 0l;
3054 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
3058 ob_debug("%sively focusing %lx at %d\n",
3059 (self
->can_focus
? "act" : "pass"),
3060 self
->window
, (gint
) event_curtime
);
3063 /* Cause the FocusIn to come back to us. Important for desktop switches,
3064 since otherwise we'll have no FocusIn on the queue and send it off to
3065 the focus_backup. */
3066 XSync(ob_display
, FALSE
);
3070 /* Used when the current client is closed or otherwise hidden, focus_last will
3071 then prevent focus from going to the mouse pointer
3073 static void client_unfocus(ObClient
*self
)
3075 if (focus_client
== self
) {
3077 ob_debug("client_unfocus for %lx\n", self
->window
);
3079 focus_fallback(FALSE
);
3083 void client_activate(ObClient
*self
, gboolean here
, gboolean user
, Time time
)
3085 /* XXX do some stuff here if user is false to determine if we really want
3086 to activate it or not (a parent or group member is currently
3089 ob_debug("Want to activate window 0x%x with time %u (last time %u), "
3091 self
->window
, time
, client_last_user_time
,
3092 (user
? "user" : "application"));
3093 if (!user
&& time
&& time
< client_last_user_time
)
3094 client_hilite(self
, TRUE
);
3096 if (client_normal(self
) && screen_showing_desktop
)
3097 screen_show_desktop(FALSE
);
3099 client_iconify(self
, FALSE
, here
);
3100 if (self
->desktop
!= DESKTOP_ALL
&&
3101 self
->desktop
!= screen_desktop
) {
3103 client_set_desktop(self
, screen_desktop
, FALSE
);
3105 screen_set_desktop(self
->desktop
);
3106 } else if (!self
->frame
->visible
)
3107 /* if its not visible for other reasons, then don't mess
3111 client_shade(self
, FALSE
);
3115 /* we do this an action here. this is rather important. this is because
3116 we want the results from the focus change to take place BEFORE we go
3117 about raising the window. when a fullscreen window loses focus, we
3118 need this or else the raise wont be able to raise above the
3119 to-lose-focus fullscreen window. */
3124 void client_raise(ObClient
*self
)
3126 action_run_string("Raise", self
, CurrentTime
);
3129 void client_lower(ObClient
*self
)
3131 action_run_string("Lower", self
, CurrentTime
);
3134 gboolean
client_focused(ObClient
*self
)
3136 return self
== focus_client
;
3139 static ObClientIcon
* client_icon_recursive(ObClient
*self
, gint w
, gint h
)
3142 /* si is the smallest image >= req */
3143 /* li is the largest image < req */
3144 gulong size
, smallest
= 0xffffffff, largest
= 0, si
= 0, li
= 0;
3146 if (!self
->nicons
) {
3147 ObClientIcon
*parent
= NULL
;
3149 if (self
->transient_for
) {
3150 if (self
->transient_for
!= OB_TRAN_GROUP
)
3151 parent
= client_icon_recursive(self
->transient_for
, w
, h
);
3154 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
3155 ObClient
*c
= it
->data
;
3156 if (c
!= self
&& !c
->transient_for
) {
3157 if ((parent
= client_icon_recursive(c
, w
, h
)))
3167 for (i
= 0; i
< self
->nicons
; ++i
) {
3168 size
= self
->icons
[i
].width
* self
->icons
[i
].height
;
3169 if (size
< smallest
&& size
>= (unsigned)(w
* h
)) {
3173 if (size
> largest
&& size
<= (unsigned)(w
* h
)) {
3178 if (largest
== 0) /* didnt find one smaller than the requested size */
3179 return &self
->icons
[si
];
3180 return &self
->icons
[li
];
3183 const ObClientIcon
* client_icon(ObClient
*self
, gint w
, gint h
)
3186 static ObClientIcon deficon
;
3188 if (!(ret
= client_icon_recursive(self
, w
, h
))) {
3189 deficon
.width
= deficon
.height
= 48;
3190 deficon
.data
= ob_rr_theme
->def_win_icon
;
3196 /* this be mostly ripped from fvwm */
3197 ObClient
*client_find_directional(ObClient
*c
, ObDirection dir
)
3199 gint my_cx
, my_cy
, his_cx
, his_cy
;
3202 gint score
, best_score
;
3203 ObClient
*best_client
, *cur
;
3209 /* first, find the centre coords of the currently focused window */
3210 my_cx
= c
->frame
->area
.x
+ c
->frame
->area
.width
/ 2;
3211 my_cy
= c
->frame
->area
.y
+ c
->frame
->area
.height
/ 2;
3216 for(it
= g_list_first(client_list
); it
; it
= g_list_next(it
)) {
3219 /* the currently selected window isn't interesting */
3222 if (!client_normal(cur
))
3224 /* using c->desktop instead of screen_desktop doesn't work if the
3225 * current window was omnipresent, hope this doesn't have any other
3227 if(screen_desktop
!= cur
->desktop
&& cur
->desktop
!= DESKTOP_ALL
)
3231 if(!(client_focus_target(cur
) == cur
&&
3232 client_can_focus(cur
)))
3235 /* find the centre coords of this window, from the
3236 * currently focused window's point of view */
3237 his_cx
= (cur
->frame
->area
.x
- my_cx
)
3238 + cur
->frame
->area
.width
/ 2;
3239 his_cy
= (cur
->frame
->area
.y
- my_cy
)
3240 + cur
->frame
->area
.height
/ 2;
3242 if(dir
== OB_DIRECTION_NORTHEAST
|| dir
== OB_DIRECTION_SOUTHEAST
||
3243 dir
== OB_DIRECTION_SOUTHWEST
|| dir
== OB_DIRECTION_NORTHWEST
) {
3245 /* Rotate the diagonals 45 degrees counterclockwise.
3246 * To do this, multiply the matrix /+h +h\ with the
3247 * vector (x y). \-h +h/
3248 * h = sqrt(0.5). We can set h := 1 since absolute
3249 * distance doesn't matter here. */
3250 tx
= his_cx
+ his_cy
;
3251 his_cy
= -his_cx
+ his_cy
;
3256 case OB_DIRECTION_NORTH
:
3257 case OB_DIRECTION_SOUTH
:
3258 case OB_DIRECTION_NORTHEAST
:
3259 case OB_DIRECTION_SOUTHWEST
:
3260 offset
= (his_cx
< 0) ? -his_cx
: his_cx
;
3261 distance
= ((dir
== OB_DIRECTION_NORTH
||
3262 dir
== OB_DIRECTION_NORTHEAST
) ?
3265 case OB_DIRECTION_EAST
:
3266 case OB_DIRECTION_WEST
:
3267 case OB_DIRECTION_SOUTHEAST
:
3268 case OB_DIRECTION_NORTHWEST
:
3269 offset
= (his_cy
< 0) ? -his_cy
: his_cy
;
3270 distance
= ((dir
== OB_DIRECTION_WEST
||
3271 dir
== OB_DIRECTION_NORTHWEST
) ?
3276 /* the target must be in the requested direction */
3280 /* Calculate score for this window. The smaller the better. */
3281 score
= distance
+ offset
;
3283 /* windows more than 45 degrees off the direction are
3284 * heavily penalized and will only be chosen if nothing
3285 * else within a million pixels */
3286 if(offset
> distance
)
3289 if(best_score
== -1 || score
< best_score
)
3297 void client_set_layer(ObClient
*self
, gint layer
)
3301 self
->above
= FALSE
;
3302 } else if (layer
== 0) {
3303 self
->below
= self
->above
= FALSE
;
3305 self
->below
= FALSE
;
3308 client_calc_layer(self
);
3309 client_change_state(self
); /* reflect this in the state hints */
3312 void client_set_undecorated(ObClient
*self
, gboolean undecorated
)
3314 if (self
->undecorated
!= undecorated
) {
3315 self
->undecorated
= undecorated
;
3316 client_setup_decor_and_functions(self
);
3317 /* Make sure the client knows it might have moved. Maybe there is a
3318 * better way of doing this so only one client_configure is sent, but
3319 * since 125 of these are sent per second when moving the window (with
3320 * user = FALSE) i doubt it matters much.
3322 client_configure(self
, OB_CORNER_TOPLEFT
, self
->area
.x
, self
->area
.y
,
3323 self
->area
.width
, self
->area
.height
, TRUE
, TRUE
);
3324 client_change_state(self
); /* reflect this in the state hints */
3328 guint
client_monitor(ObClient
*self
)
3330 return screen_find_monitor(&self
->frame
->area
);
3333 ObClient
*client_search_top_parent(ObClient
*self
)
3335 while (self
->transient_for
&& self
->transient_for
!= OB_TRAN_GROUP
)
3336 self
= self
->transient_for
;
3340 GSList
*client_search_all_top_parents(ObClient
*self
)
3344 /* move up the direct transient chain as far as possible */
3345 while (self
->transient_for
&& self
->transient_for
!= OB_TRAN_GROUP
)
3346 self
= self
->transient_for
;
3348 if (!self
->transient_for
)
3349 ret
= g_slist_prepend(ret
, self
);
3353 g_assert(self
->group
);
3355 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
3356 ObClient
*c
= it
->data
;
3358 if (!c
->transient_for
)
3359 ret
= g_slist_prepend(ret
, c
);
3362 if (ret
== NULL
) /* no group parents */
3363 ret
= g_slist_prepend(ret
, self
);
3369 ObClient
*client_search_focus_parent(ObClient
*self
)
3371 if (self
->transient_for
) {
3372 if (self
->transient_for
!= OB_TRAN_GROUP
) {
3373 if (client_focused(self
->transient_for
))
3374 return self
->transient_for
;
3378 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
3379 ObClient
*c
= it
->data
;
3381 /* checking transient_for prevents infinate loops! */
3382 if (c
!= self
&& !c
->transient_for
)
3383 if (client_focused(c
))
3392 ObClient
*client_search_parent(ObClient
*self
, ObClient
*search
)
3394 if (self
->transient_for
) {
3395 if (self
->transient_for
!= OB_TRAN_GROUP
) {
3396 if (self
->transient_for
== search
)
3401 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
3402 ObClient
*c
= it
->data
;
3404 /* checking transient_for prevents infinate loops! */
3405 if (c
!= self
&& !c
->transient_for
)
3415 ObClient
*client_search_transient(ObClient
*self
, ObClient
*search
)
3419 for (sit
= self
->transients
; sit
; sit
= g_slist_next(sit
)) {
3420 if (sit
->data
== search
)
3422 if (client_search_transient(sit
->data
, search
))
3428 void client_update_sm_client_id(ObClient
*self
)
3430 g_free(self
->sm_client_id
);
3431 self
->sm_client_id
= NULL
;
3433 if (!PROP_GETS(self
->window
, sm_client_id
, locale
, &self
->sm_client_id
) &&
3435 PROP_GETS(self
->group
->leader
, sm_client_id
, locale
,
3436 &self
->sm_client_id
);
3439 #define WANT_EDGE(cur, c) \
3442 if(!client_normal(cur)) \
3444 if(screen_desktop != cur->desktop && cur->desktop != DESKTOP_ALL) \
3448 if(cur->layer < c->layer && !config_resist_layers_below) \
3451 #define HIT_EDGE(my_edge_start, my_edge_end, his_edge_start, his_edge_end) \
3452 if ((his_edge_start >= my_edge_start && \
3453 his_edge_start <= my_edge_end) || \
3454 (my_edge_start >= his_edge_start && \
3455 my_edge_start <= his_edge_end)) \
3458 /* finds the nearest edge in the given direction from the current client
3459 * note to self: the edge is the -frame- edge (the actual one), not the
3462 gint
client_directional_edge_search(ObClient
*c
, ObDirection dir
, gboolean hang
)
3464 gint dest
, monitor_dest
;
3465 gint my_edge_start
, my_edge_end
, my_offset
;
3472 a
= screen_area(c
->desktop
);
3473 monitor
= screen_area_monitor(c
->desktop
, client_monitor(c
));
3476 case OB_DIRECTION_NORTH
:
3477 my_edge_start
= c
->frame
->area
.x
;
3478 my_edge_end
= c
->frame
->area
.x
+ c
->frame
->area
.width
;
3479 my_offset
= c
->frame
->area
.y
+ (hang
? c
->frame
->area
.height
: 0);
3481 /* default: top of screen */
3482 dest
= a
->y
+ (hang
? c
->frame
->area
.height
: 0);
3483 monitor_dest
= monitor
->y
+ (hang
? c
->frame
->area
.height
: 0);
3484 /* if the monitor edge comes before the screen edge, */
3485 /* use that as the destination instead. (For xinerama) */
3486 if (monitor_dest
!= dest
&& my_offset
> monitor_dest
)
3487 dest
= monitor_dest
;
3489 for(it
= client_list
; it
&& my_offset
!= dest
; it
= g_list_next(it
)) {
3490 gint his_edge_start
, his_edge_end
, his_offset
;
3491 ObClient
*cur
= it
->data
;
3495 his_edge_start
= cur
->frame
->area
.x
;
3496 his_edge_end
= cur
->frame
->area
.x
+ cur
->frame
->area
.width
;
3497 his_offset
= cur
->frame
->area
.y
+
3498 (hang
? 0 : cur
->frame
->area
.height
);
3500 if(his_offset
+ 1 > my_offset
)
3503 if(his_offset
< dest
)
3506 HIT_EDGE(my_edge_start
, my_edge_end
, his_edge_start
, his_edge_end
)
3509 case OB_DIRECTION_SOUTH
:
3510 my_edge_start
= c
->frame
->area
.x
;
3511 my_edge_end
= c
->frame
->area
.x
+ c
->frame
->area
.width
;
3512 my_offset
= c
->frame
->area
.y
+ (hang
? 0 : c
->frame
->area
.height
);
3514 /* default: bottom of screen */
3515 dest
= a
->y
+ a
->height
- (hang
? c
->frame
->area
.height
: 0);
3516 monitor_dest
= monitor
->y
+ monitor
->height
-
3517 (hang
? c
->frame
->area
.height
: 0);
3518 /* if the monitor edge comes before the screen edge, */
3519 /* use that as the destination instead. (For xinerama) */
3520 if (monitor_dest
!= dest
&& my_offset
< monitor_dest
)
3521 dest
= monitor_dest
;
3523 for(it
= client_list
; it
&& my_offset
!= dest
; it
= g_list_next(it
)) {
3524 gint his_edge_start
, his_edge_end
, his_offset
;
3525 ObClient
*cur
= it
->data
;
3529 his_edge_start
= cur
->frame
->area
.x
;
3530 his_edge_end
= cur
->frame
->area
.x
+ cur
->frame
->area
.width
;
3531 his_offset
= cur
->frame
->area
.y
+
3532 (hang
? cur
->frame
->area
.height
: 0);
3535 if(his_offset
- 1 < my_offset
)
3538 if(his_offset
> dest
)
3541 HIT_EDGE(my_edge_start
, my_edge_end
, his_edge_start
, his_edge_end
)
3544 case OB_DIRECTION_WEST
:
3545 my_edge_start
= c
->frame
->area
.y
;
3546 my_edge_end
= c
->frame
->area
.y
+ c
->frame
->area
.height
;
3547 my_offset
= c
->frame
->area
.x
+ (hang
? c
->frame
->area
.width
: 0);
3549 /* default: leftmost egde of screen */
3550 dest
= a
->x
+ (hang
? c
->frame
->area
.width
: 0);
3551 monitor_dest
= monitor
->x
+ (hang
? c
->frame
->area
.width
: 0);
3552 /* if the monitor edge comes before the screen edge, */
3553 /* use that as the destination instead. (For xinerama) */
3554 if (monitor_dest
!= dest
&& my_offset
> monitor_dest
)
3555 dest
= monitor_dest
;
3557 for(it
= client_list
; it
&& my_offset
!= dest
; it
= g_list_next(it
)) {
3558 gint his_edge_start
, his_edge_end
, his_offset
;
3559 ObClient
*cur
= it
->data
;
3563 his_edge_start
= cur
->frame
->area
.y
;
3564 his_edge_end
= cur
->frame
->area
.y
+ cur
->frame
->area
.height
;
3565 his_offset
= cur
->frame
->area
.x
+
3566 (hang
? 0 : cur
->frame
->area
.width
);
3568 if(his_offset
+ 1 > my_offset
)
3571 if(his_offset
< dest
)
3574 HIT_EDGE(my_edge_start
, my_edge_end
, his_edge_start
, his_edge_end
)
3577 case OB_DIRECTION_EAST
:
3578 my_edge_start
= c
->frame
->area
.y
;
3579 my_edge_end
= c
->frame
->area
.y
+ c
->frame
->area
.height
;
3580 my_offset
= c
->frame
->area
.x
+ (hang
? 0 : c
->frame
->area
.width
);
3582 /* default: rightmost edge of screen */
3583 dest
= a
->x
+ a
->width
- (hang
? c
->frame
->area
.width
: 0);
3584 monitor_dest
= monitor
->x
+ monitor
->width
-
3585 (hang
? c
->frame
->area
.width
: 0);
3586 /* if the monitor edge comes before the screen edge, */
3587 /* use that as the destination instead. (For xinerama) */
3588 if (monitor_dest
!= dest
&& my_offset
< monitor_dest
)
3589 dest
= monitor_dest
;
3591 for(it
= client_list
; it
&& my_offset
!= dest
; it
= g_list_next(it
)) {
3592 gint his_edge_start
, his_edge_end
, his_offset
;
3593 ObClient
*cur
= it
->data
;
3597 his_edge_start
= cur
->frame
->area
.y
;
3598 his_edge_end
= cur
->frame
->area
.y
+ cur
->frame
->area
.height
;
3599 his_offset
= cur
->frame
->area
.x
+
3600 (hang
? cur
->frame
->area
.width
: 0);
3602 if(his_offset
- 1 < my_offset
)
3605 if(his_offset
> dest
)
3608 HIT_EDGE(my_edge_start
, my_edge_end
, his_edge_start
, his_edge_end
)
3611 case OB_DIRECTION_NORTHEAST
:
3612 case OB_DIRECTION_SOUTHEAST
:
3613 case OB_DIRECTION_NORTHWEST
:
3614 case OB_DIRECTION_SOUTHWEST
:
3615 /* not implemented */
3617 g_assert_not_reached();
3618 dest
= 0; /* suppress warning */
3623 ObClient
* client_under_pointer()
3627 ObClient
*ret
= NULL
;
3629 if (screen_pointer_pos(&x
, &y
)) {
3630 for (it
= stacking_list
; it
; it
= g_list_next(it
)) {
3631 if (WINDOW_IS_CLIENT(it
->data
)) {
3632 ObClient
*c
= WINDOW_AS_CLIENT(it
->data
);
3633 if (c
->frame
->visible
&&
3634 RECT_CONTAINS(c
->frame
->area
, x
, y
)) {
3644 gboolean
client_has_group_siblings(ObClient
*self
)
3646 return self
->group
&& self
->group
->members
->next
;