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
->wmstate
= WithdrawnState
; /* make sure it gets updated first time */
273 self
->desktop
= screen_num_desktops
; /* always an invalid value */
274 self
->user_time
= ~0; /* maximum value, always newer than the real time */
276 client_get_all(self
);
277 client_restore_session_state(self
);
278 /* per-app settings override stuff, and return the settings for other
280 settings
= client_get_settings_state(self
);
282 client_calc_layer(self
);
285 Time t
= sn_app_started(self
->startup_id
, self
->class);
286 if (t
) self
->user_time
= t
;
289 /* update the focus lists, do this before the call to change_state or
290 it can end up in the list twice! */
291 focus_order_add_new(self
);
293 /* remove the client's border (and adjust re gravity) */
294 client_toggle_border(self
, FALSE
);
296 /* specify that if we exit, the window should not be destroyed and should
297 be reparented back to root automatically */
298 XChangeSaveSet(ob_display
, window
, SetModeInsert
);
300 /* create the decoration frame for the client window */
301 self
->frame
= frame_new(self
);
303 frame_grab_client(self
->frame
, self
);
305 /* do this after we have a frame.. it uses the frame to help determine the
306 WM_STATE to apply. */
307 client_change_state(self
);
311 stacking_add_nonintrusive(CLIENT_AS_WINDOW(self
));
312 client_restore_session_stacking(self
);
314 /* focus the new window? */
315 if (ob_state() != OB_STATE_STARTING
&&
316 /* this means focus=true for window is same as config_focus_new=true */
317 ((config_focus_new
|| (settings
&& settings
->focus
== 1)) ||
318 client_search_focus_parent(self
)) &&
319 /* this checks for focus=false for the window */
320 (!settings
|| settings
->focus
!= 0) &&
321 /* note the check against Type_Normal/Dialog, not client_normal(self),
322 which would also include other types. in this case we want more
323 strict rules for focus */
324 (self
->type
== OB_CLIENT_TYPE_NORMAL
||
325 self
->type
== OB_CLIENT_TYPE_DIALOG
))
329 if (self
->desktop
!= screen_desktop
) {
330 /* activate the window */
333 gboolean group_foc
= FALSE
;
338 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
))
340 if (client_focused(it
->data
))
348 (!self
->transient_for
&& (!self
->group
||
349 !self
->group
->members
->next
))) ||
350 client_search_focus_tree_full(self
) ||
352 !client_normal(focus_client
))
354 /* activate the window */
361 /* get the current position */
365 /* figure out placement for the window */
366 if (ob_state() == OB_STATE_RUNNING
) {
369 transient
= place_client(self
, &newx
, &newy
, settings
);
371 /* make sure the window is visible. */
372 client_find_onscreen(self
, &newx
, &newy
,
373 self
->frame
->area
.width
,
374 self
->frame
->area
.height
,
375 /* non-normal clients has less rules, and
376 windows that are being restored from a
377 session do also. we can assume you want
378 it back where you saved it. Clients saying
379 they placed themselves are subjected to
380 harder rules, ones that are placed by
381 place.c or by the user are allowed partially
382 off-screen and on xinerama divides (ie,
383 it is up to the placement routines to avoid
384 the xinerama divides) */
386 (((self
->positioned
& PPosition
) &&
387 !(self
->positioned
& USPosition
)) &&
388 client_normal(self
) &&
392 /* do this after the window is placed, so the premax/prefullscreen numbers
394 also, this moves the window to the position where it has been placed
396 client_apply_startup_state(self
, newx
, newy
);
398 keyboard_grab_for_client(self
, TRUE
);
399 mouse_grab_for_client(self
, TRUE
);
402 /* This is focus stealing prevention */
403 ob_debug("Want to focus new window 0x%x with time %u (last time %u)\n",
404 self
->window
, self
->user_time
, client_last_user_time
);
406 /* If a nothing at all, or a parent was focused, then focus this
409 if (!focus_client
|| client_search_focus_parent(self
) != NULL
)
413 /* If time stamp is old, don't steal focus */
414 if (self
->user_time
&& self
->user_time
< client_last_user_time
)
416 /* Don't steal focus from globally active clients.
417 I stole this idea from KWin. It seems nice.
419 if (!(focus_client
->can_focus
|| focus_client
->focus_notify
))
425 /* since focus can change the stacking orders, if we focus the
426 window then the standard raise it gets is not enough, we need
427 to queue one for after the focus change takes place */
430 ob_debug("Focus stealing prevention activated for %s with time %u "
432 self
->title
, self
->user_time
, client_last_user_time
);
433 /* if the client isn't focused, then hilite it so the user
435 client_hilite(self
, TRUE
);
439 /* This may look rather odd. Well it's because new windows are added
440 to the stacking order non-intrusively. If we're not going to focus
441 the new window or hilite it, then we raise it to the top. This will
442 take affect for things that don't get focused like splash screens.
443 Also if you don't have focus_new enabled, then it's going to get
444 raised to the top. Legacy begets legacy I guess?
449 /* this has to happen before we try focus the window, but we want it to
450 happen after the client's stacking has been determined or it looks bad
452 client_showhide(self
);
454 /* use client_focus instead of client_activate cuz client_activate does
455 stuff like switch desktops etc and I'm not interested in all that when
456 a window maps since its not based on an action from the user like
457 clicking a window to activate it. so keep the new window out of the way
460 /* if using focus_delay, stop the timer now so that focus doesn't
462 event_halt_focus_delay();
466 /* client_activate does this but we aret using it so we have to do it
468 if (screen_showing_desktop
)
469 screen_show_desktop(FALSE
);
471 /* add to client list/map */
472 client_list
= g_list_append(client_list
, self
);
473 g_hash_table_insert(window_map
, &self
->window
, self
);
475 /* this has to happen after we're in the client_list */
476 if (STRUT_EXISTS(self
->strut
))
477 screen_update_areas();
479 /* update the list hints */
482 ob_debug("Managed window 0x%lx (%s)\n", window
, self
->class);
485 void client_unmanage_all()
487 while (client_list
!= NULL
)
488 client_unmanage(client_list
->data
);
491 void client_unmanage(ObClient
*self
)
496 ob_debug("Unmanaging window: %lx (%s) (%s)\n", self
->window
, self
->class,
497 self
->title
? self
->title
: "");
499 g_assert(self
!= NULL
);
501 /* update the focus lists */
502 focus_order_remove(self
);
504 if (focus_client
== self
) {
507 /* focus the last focused window on the desktop, and ignore enter
508 events from the unmap so it doesnt mess with the focus */
509 while (XCheckTypedEvent(ob_display
, EnterNotify
, &e
));
510 /* remove these flags so we don't end up getting focused in the
512 self
->can_focus
= FALSE
;
513 self
->focus_notify
= FALSE
;
515 client_unfocus(self
);
518 /* potentially fix focusLast */
519 if (config_focus_last
)
520 grab_pointer(TRUE
, OB_CURSOR_NONE
);
522 frame_hide(self
->frame
);
525 keyboard_grab_for_client(self
, FALSE
);
526 mouse_grab_for_client(self
, FALSE
);
528 /* remove the window from our save set */
529 XChangeSaveSet(ob_display
, self
->window
, SetModeDelete
);
531 /* we dont want events no more */
532 XSelectInput(ob_display
, self
->window
, NoEventMask
);
534 client_list
= g_list_remove(client_list
, self
);
535 stacking_remove(self
);
536 g_hash_table_remove(window_map
, &self
->window
);
538 /* once the client is out of the list, update the struts to remove its
540 if (STRUT_EXISTS(self
->strut
))
541 screen_update_areas();
543 for (it
= client_destructors
; it
; it
= g_slist_next(it
)) {
544 Destructor
*d
= it
->data
;
545 d
->func(self
, d
->data
);
548 /* tell our parent(s) that we're gone */
549 if (self
->transient_for
== OB_TRAN_GROUP
) { /* transient of group */
550 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
))
551 if (it
->data
!= self
)
552 ((ObClient
*)it
->data
)->transients
=
553 g_slist_remove(((ObClient
*)it
->data
)->transients
, self
);
554 } else if (self
->transient_for
) { /* transient of window */
555 self
->transient_for
->transients
=
556 g_slist_remove(self
->transient_for
->transients
, self
);
559 /* tell our transients that we're gone */
560 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
561 if (((ObClient
*)it
->data
)->transient_for
!= OB_TRAN_GROUP
) {
562 ((ObClient
*)it
->data
)->transient_for
= NULL
;
563 client_calc_layer(it
->data
);
567 /* remove from its group */
569 group_remove(self
->group
, self
);
573 /* give the client its border back */
574 client_toggle_border(self
, TRUE
);
576 /* reparent the window out of the frame, and free the frame */
577 frame_release_client(self
->frame
, self
);
580 /* restore the window's original geometry so it is not lost */
581 if (self
->fullscreen
)
582 XMoveResizeWindow(ob_display
, self
->window
,
583 self
->pre_fullscreen_area
.x
,
584 self
->pre_fullscreen_area
.y
,
585 self
->pre_fullscreen_area
.width
,
586 self
->pre_fullscreen_area
.height
);
587 else if (self
->max_horz
|| self
->max_vert
) {
589 if (self
->max_horz
) {
590 a
.x
= self
->pre_max_area
.x
;
591 a
.width
= self
->pre_max_area
.width
;
593 if (self
->max_vert
) {
594 a
.y
= self
->pre_max_area
.y
;
595 a
.height
= self
->pre_max_area
.height
;
597 XMoveResizeWindow(ob_display
, self
->window
,
598 a
.x
, a
.y
, a
.width
, a
.height
);
601 if (ob_state() != OB_STATE_EXITING
) {
602 /* these values should not be persisted across a window
604 PROP_ERASE(self
->window
, net_wm_desktop
);
605 PROP_ERASE(self
->window
, net_wm_state
);
606 PROP_ERASE(self
->window
, wm_state
);
608 /* if we're left in an unmapped state, the client wont be mapped. this
609 is bad, since we will no longer be managing the window on restart */
610 XMapWindow(ob_display
, self
->window
);
614 ob_debug("Unmanaged window 0x%lx\n", self
->window
);
616 /* free all data allocated in the client struct */
617 g_slist_free(self
->transients
);
618 for (j
= 0; j
< self
->nicons
; ++j
)
619 g_free(self
->icons
[j
].data
);
620 if (self
->nicons
> 0)
623 g_free(self
->icon_title
);
627 g_free(self
->sm_client_id
);
630 /* update the list hints */
633 if (config_focus_last
)
634 grab_pointer(FALSE
, OB_CURSOR_NONE
);
637 static ObAppSettings
*client_get_settings_state(ObClient
*self
)
639 ObAppSettings
*settings
= NULL
;
642 for (it
= config_per_app_settings
; it
; it
= g_slist_next(it
)) {
643 ObAppSettings
*app
= it
->data
;
645 if ((app
->name
&& !app
->class && !strcmp(app
->name
, self
->name
))
646 || (app
->class && !app
->name
&& !strcmp(app
->class, self
->class))
647 || (app
->class && app
->name
&& !strcmp(app
->class, self
->class)
648 && !strcmp(app
->name
, self
->name
)))
650 ob_debug("Window matching: %s\n", app
->name
);
651 /* Match if no role was specified in the per app setting, or if the
652 * string matches the beginning of the role, since apps like to set
653 * the role to things like browser-window-23c4b2f */
655 || !strncmp(app
->role
, self
->role
, strlen(app
->role
)))
665 if (settings
->shade
!= -1)
666 self
->shaded
= !!settings
->shade
;
667 if (settings
->decor
!= -1)
668 self
->undecorated
= !settings
->decor
;
669 if (settings
->iconic
!= -1)
670 self
->iconic
= !!settings
->iconic
;
671 if (settings
->skip_pager
!= -1)
672 self
->skip_pager
= !!settings
->skip_pager
;
673 if (settings
->skip_taskbar
!= -1)
674 self
->skip_taskbar
= !!settings
->skip_taskbar
;
676 if (settings
->max_vert
!= -1)
677 self
->max_vert
= !!settings
->max_vert
;
678 if (settings
->max_horz
!= -1)
679 self
->max_vert
= !!settings
->max_horz
;
681 if (settings
->fullscreen
!= -1)
682 self
->fullscreen
= !!settings
->fullscreen
;
684 if (settings
->desktop
< screen_num_desktops
685 || settings
->desktop
== DESKTOP_ALL
)
686 client_set_desktop(self
, settings
->desktop
, TRUE
);
688 if (settings
->layer
== -1) {
692 else if (settings
->layer
== 0) {
696 else if (settings
->layer
== 1) {
704 static void client_restore_session_state(ObClient
*self
)
708 if (!(it
= session_state_find(self
)))
711 self
->session
= it
->data
;
713 RECT_SET_POINT(self
->area
, self
->session
->x
, self
->session
->y
);
714 self
->positioned
= PPosition
;
715 if (self
->session
->w
> 0)
716 self
->area
.width
= self
->session
->w
;
717 if (self
->session
->h
> 0)
718 self
->area
.height
= self
->session
->h
;
719 XResizeWindow(ob_display
, self
->window
,
720 self
->area
.width
, self
->area
.height
);
722 self
->desktop
= (self
->session
->desktop
== DESKTOP_ALL
?
723 self
->session
->desktop
:
724 MIN(screen_num_desktops
- 1, self
->session
->desktop
));
725 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, self
->desktop
);
727 self
->shaded
= self
->session
->shaded
;
728 self
->iconic
= self
->session
->iconic
;
729 self
->skip_pager
= self
->session
->skip_pager
;
730 self
->skip_taskbar
= self
->session
->skip_taskbar
;
731 self
->fullscreen
= self
->session
->fullscreen
;
732 self
->above
= self
->session
->above
;
733 self
->below
= self
->session
->below
;
734 self
->max_horz
= self
->session
->max_horz
;
735 self
->max_vert
= self
->session
->max_vert
;
738 static void client_restore_session_stacking(ObClient
*self
)
742 if (!self
->session
) return;
744 it
= g_list_find(session_saved_state
, self
->session
);
745 for (it
= g_list_previous(it
); it
; it
= g_list_previous(it
)) {
748 for (cit
= client_list
; cit
; cit
= g_list_next(cit
))
749 if (session_state_cmp(it
->data
, cit
->data
))
752 client_calc_layer(self
);
753 stacking_below(CLIENT_AS_WINDOW(self
),
754 CLIENT_AS_WINDOW(cit
->data
));
760 void client_move_onscreen(ObClient
*self
, gboolean rude
)
762 gint x
= self
->area
.x
;
763 gint y
= self
->area
.y
;
764 if (client_find_onscreen(self
, &x
, &y
,
765 self
->frame
->area
.width
,
766 self
->frame
->area
.height
, rude
)) {
767 client_move(self
, x
, y
);
771 gboolean
client_find_onscreen(ObClient
*self
, gint
*x
, gint
*y
, gint w
, gint h
,
775 gint ox
= *x
, oy
= *y
;
777 frame_client_gravity(self
->frame
, x
, y
); /* get where the frame
780 /* XXX watch for xinerama dead areas */
781 /* This makes sure windows aren't entirely outside of the screen so you
782 can't see them at all.
783 It makes sure 10% of the window is on the screen at least. At don't let
784 it move itself off the top of the screen, which would hide the titlebar
785 on you. (The user can still do this if they want too, it's only limiting
788 if (client_normal(self
)) {
789 a
= screen_area(self
->desktop
);
790 if (!self
->strut
.right
&&
791 *x
+ self
->frame
->area
.width
/10 >= a
->x
+ a
->width
- 1)
792 *x
= a
->x
+ a
->width
- self
->frame
->area
.width
/10;
793 if (!self
->strut
.bottom
&&
794 *y
+ self
->frame
->area
.height
/10 >= a
->y
+ a
->height
- 1)
795 *y
= a
->y
+ a
->height
- self
->frame
->area
.height
/10;
796 if (!self
->strut
.left
&& *x
+ self
->frame
->area
.width
*9/10 - 1 < a
->x
)
797 *x
= a
->x
- self
->frame
->area
.width
*9/10;
798 if (!self
->strut
.top
&& *y
+ self
->frame
->area
.height
*9/10 - 1 < a
->y
)
799 *y
= a
->y
- self
->frame
->area
.width
*9/10;
802 /* This here doesn't let windows even a pixel outside the screen,
803 * when called from client_manage, programs placing themselves are
804 * forced completely onscreen, while things like
805 * xterm -geometry resolution-width/2 will work fine. Trying to
806 * place it completely offscreen will be handled in the above code.
807 * Sorry for this confused comment, i am tired. */
809 /* avoid the xinerama monitor divide while we're at it,
810 * remember to fix the placement stuff to avoid it also and
811 * then remove this XXX */
812 a
= screen_area_monitor(self
->desktop
, client_monitor(self
));
813 /* dont let windows map into the strut unless they
814 are bigger than the available area */
816 if (!self
->strut
.left
&& *x
< a
->x
) *x
= a
->x
;
817 if (!self
->strut
.right
&& *x
+ w
> a
->x
+ a
->width
)
818 *x
= a
->x
+ a
->width
- w
;
820 if (h
<= a
->height
) {
821 if (!self
->strut
.top
&& *y
< a
->y
) *y
= a
->y
;
822 if (!self
->strut
.bottom
&& *y
+ h
> a
->y
+ a
->height
)
823 *y
= a
->y
+ a
->height
- h
;
827 frame_frame_gravity(self
->frame
, x
, y
); /* get where the client
830 return ox
!= *x
|| oy
!= *y
;
833 static void client_toggle_border(ObClient
*self
, gboolean show
)
835 /* adjust our idea of where the client is, based on its border. When the
836 border is removed, the client should now be considered to be in a
838 when re-adding the border to the client, the same operation needs to be
840 gint oldx
= self
->area
.x
, oldy
= self
->area
.y
;
841 gint x
= oldx
, y
= oldy
;
842 switch(self
->gravity
) {
844 case NorthWestGravity
:
846 case SouthWestGravity
:
848 case NorthEastGravity
:
850 case SouthEastGravity
:
851 if (show
) x
-= self
->border_width
* 2;
852 else x
+= self
->border_width
* 2;
859 if (show
) x
-= self
->border_width
;
860 else x
+= self
->border_width
;
863 switch(self
->gravity
) {
865 case NorthWestGravity
:
867 case NorthEastGravity
:
869 case SouthWestGravity
:
871 case SouthEastGravity
:
872 if (show
) y
-= self
->border_width
* 2;
873 else y
+= self
->border_width
* 2;
880 if (show
) y
-= self
->border_width
;
881 else y
+= self
->border_width
;
888 XSetWindowBorderWidth(ob_display
, self
->window
, self
->border_width
);
890 /* move the client so it is back it the right spot _with_ its
892 if (x
!= oldx
|| y
!= oldy
)
893 XMoveWindow(ob_display
, self
->window
, x
, y
);
895 XSetWindowBorderWidth(ob_display
, self
->window
, 0);
899 static void client_get_all(ObClient
*self
)
901 client_get_area(self
);
902 client_get_mwm_hints(self
);
904 /* The transient hint is used to pick a type, but the type can also affect
905 transiency (dialogs are always made transients of their group if they
906 have one). This is Havoc's idea, but it is needed to make some apps
907 work right (eg tsclient). */
908 client_update_transient_for(self
);
909 client_get_type(self
);/* this can change the mwmhints for special cases */
910 client_get_state(self
);
911 client_update_transient_for(self
);
913 client_update_wmhints(self
);
914 client_get_startup_id(self
);
915 client_get_desktop(self
);/* uses transient data/group/startup id if a
916 desktop is not specified */
917 client_get_shaped(self
);
919 client_get_layer(self
); /* if layer hasn't been specified, get it from
920 other sources if possible */
923 /* a couple type-based defaults for new windows */
925 /* this makes sure that these windows appear on all desktops */
926 if (self
->type
== OB_CLIENT_TYPE_DESKTOP
)
927 self
->desktop
= DESKTOP_ALL
;
930 client_update_protocols(self
);
932 client_get_gravity(self
); /* get the attribute gravity */
933 client_update_normal_hints(self
); /* this may override the attribute
936 /* got the type, the mwmhints, the protocols, and the normal hints
937 (min/max sizes), so we're ready to set up the decorations/functions */
938 client_setup_decor_and_functions(self
);
940 client_update_title(self
);
941 client_update_class(self
);
942 client_update_sm_client_id(self
);
943 client_update_strut(self
);
944 client_update_icons(self
);
945 client_update_user_time(self
, FALSE
);
948 static void client_get_startup_id(ObClient
*self
)
950 if (!(PROP_GETS(self
->window
, net_startup_id
, utf8
, &self
->startup_id
)))
952 PROP_GETS(self
->group
->leader
,
953 net_startup_id
, utf8
, &self
->startup_id
);
956 static void client_get_area(ObClient
*self
)
958 XWindowAttributes wattrib
;
961 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
962 g_assert(ret
!= BadWindow
);
964 RECT_SET(self
->area
, wattrib
.x
, wattrib
.y
, wattrib
.width
, wattrib
.height
);
965 self
->border_width
= wattrib
.border_width
;
967 ob_debug("client area: %d %d %d %d\n", wattrib
.x
, wattrib
.y
,
968 wattrib
.width
, wattrib
.height
);
971 static void client_get_desktop(ObClient
*self
)
973 guint32 d
= screen_num_desktops
; /* an always-invalid value */
975 if (PROP_GET32(self
->window
, net_wm_desktop
, cardinal
, &d
)) {
976 if (d
>= screen_num_desktops
&& d
!= DESKTOP_ALL
)
977 self
->desktop
= screen_num_desktops
- 1;
981 gboolean trdesk
= FALSE
;
983 if (self
->transient_for
) {
984 if (self
->transient_for
!= OB_TRAN_GROUP
) {
985 self
->desktop
= self
->transient_for
->desktop
;
990 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
))
991 if (it
->data
!= self
&&
992 !((ObClient
*)it
->data
)->transient_for
) {
993 self
->desktop
= ((ObClient
*)it
->data
)->desktop
;
1000 /* try get from the startup-notification protocol */
1001 if (sn_get_desktop(self
->startup_id
, &self
->desktop
)) {
1002 if (self
->desktop
>= screen_num_desktops
&&
1003 self
->desktop
!= DESKTOP_ALL
)
1004 self
->desktop
= screen_num_desktops
- 1;
1006 /* defaults to the current desktop */
1007 self
->desktop
= screen_desktop
;
1010 if (self
->desktop
!= d
) {
1011 /* set the desktop hint, to make sure that it always exists */
1012 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, self
->desktop
);
1016 static void client_get_layer(ObClient
*self
)
1018 if (!(self
->above
|| self
->below
)) {
1020 /* apply stuff from the group */
1024 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
1025 ObClient
*c
= it
->data
;
1026 if (c
!= self
&& !client_search_transient(self
, c
) &&
1027 client_normal(self
) && client_normal(c
))
1030 (c
->above
? 1 : (c
->below
? -1 : 0)));
1044 g_assert_not_reached();
1051 static void client_get_state(ObClient
*self
)
1056 if (PROP_GETA32(self
->window
, net_wm_state
, atom
, &state
, &num
)) {
1058 for (i
= 0; i
< num
; ++i
) {
1059 if (state
[i
] == prop_atoms
.net_wm_state_modal
)
1061 else if (state
[i
] == prop_atoms
.net_wm_state_shaded
)
1062 self
->shaded
= TRUE
;
1063 else if (state
[i
] == prop_atoms
.net_wm_state_hidden
)
1064 self
->iconic
= TRUE
;
1065 else if (state
[i
] == prop_atoms
.net_wm_state_skip_taskbar
)
1066 self
->skip_taskbar
= TRUE
;
1067 else if (state
[i
] == prop_atoms
.net_wm_state_skip_pager
)
1068 self
->skip_pager
= TRUE
;
1069 else if (state
[i
] == prop_atoms
.net_wm_state_fullscreen
)
1070 self
->fullscreen
= TRUE
;
1071 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_vert
)
1072 self
->max_vert
= TRUE
;
1073 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_horz
)
1074 self
->max_horz
= TRUE
;
1075 else if (state
[i
] == prop_atoms
.net_wm_state_above
)
1077 else if (state
[i
] == prop_atoms
.net_wm_state_below
)
1079 else if (state
[i
] == prop_atoms
.net_wm_state_demands_attention
)
1080 self
->demands_attention
= TRUE
;
1081 else if (state
[i
] == prop_atoms
.ob_wm_state_undecorated
)
1082 self
->undecorated
= TRUE
;
1089 static void client_get_shaped(ObClient
*self
)
1091 self
->shaped
= FALSE
;
1093 if (extensions_shape
) {
1098 XShapeSelectInput(ob_display
, self
->window
, ShapeNotifyMask
);
1100 XShapeQueryExtents(ob_display
, self
->window
, &s
, &foo
,
1101 &foo
, &ufoo
, &ufoo
, &foo
, &foo
, &foo
, &ufoo
,
1103 self
->shaped
= (s
!= 0);
1108 void client_update_transient_for(ObClient
*self
)
1111 ObClient
*target
= NULL
;
1113 if (XGetTransientForHint(ob_display
, self
->window
, &t
)) {
1114 self
->transient
= TRUE
;
1115 if (t
!= self
->window
) { /* cant be transient to itself! */
1116 target
= g_hash_table_lookup(window_map
, &t
);
1117 /* if this happens then we need to check for it*/
1118 g_assert(target
!= self
);
1119 if (target
&& !WINDOW_IS_CLIENT(target
)) {
1120 /* this can happen when a dialog is a child of
1121 a dockapp, for example */
1125 /* THIS IS SO ANNOYING ! ! ! ! Let me explain.... have a seat..
1127 Setting the transient_for to Root is actually illegal, however
1128 applications from time have done this to specify transient for
1131 Now you can do that by being a TYPE_DIALOG and not setting
1132 the transient_for hint at all on your window. But people still
1133 use Root, and Kwin is very strange in this regard.
1135 KWin 3.0 will not consider windows with transient_for set to
1136 Root as transient for their group *UNLESS* they are also modal.
1137 In that case, it will make them transient for the group. This
1138 leads to all sorts of weird behavior from KDE apps which are
1139 only tested in KWin. I'd like to follow their behavior just to
1140 make this work right with KDE stuff, but that seems wrong.
1142 if (!target
&& self
->group
) {
1143 /* not transient to a client, see if it is transient for a
1145 if (t
== RootWindow(ob_display
, ob_screen
)) {
1146 /* window is a transient for its group! */
1147 target
= OB_TRAN_GROUP
;
1151 } else if (self
->group
) {
1152 if (self
->type
== OB_CLIENT_TYPE_DIALOG
||
1153 self
->type
== OB_CLIENT_TYPE_TOOLBAR
||
1154 self
->type
== OB_CLIENT_TYPE_MENU
||
1155 self
->type
== OB_CLIENT_TYPE_UTILITY
)
1157 self
->transient
= TRUE
;
1158 target
= OB_TRAN_GROUP
;
1161 self
->transient
= FALSE
;
1163 /* if anything has changed... */
1164 if (target
!= self
->transient_for
) {
1165 if (self
->transient_for
== OB_TRAN_GROUP
) { /* transient of group */
1168 /* remove from old parents */
1169 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
1170 ObClient
*c
= it
->data
;
1171 if (c
!= self
&& !c
->transient_for
)
1172 c
->transients
= g_slist_remove(c
->transients
, self
);
1174 } else if (self
->transient_for
!= NULL
) { /* transient of window */
1175 /* remove from old parent */
1176 self
->transient_for
->transients
=
1177 g_slist_remove(self
->transient_for
->transients
, self
);
1179 self
->transient_for
= target
;
1180 if (self
->transient_for
== OB_TRAN_GROUP
) { /* transient of group */
1183 /* add to new parents */
1184 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
1185 ObClient
*c
= it
->data
;
1186 if (c
!= self
&& !c
->transient_for
)
1187 c
->transients
= g_slist_append(c
->transients
, self
);
1190 /* remove all transients which are in the group, that causes
1191 circlular pointer hell of doom */
1192 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
1194 for (sit
= self
->transients
; sit
; sit
= next
) {
1195 next
= g_slist_next(sit
);
1196 if (sit
->data
== it
->data
)
1198 g_slist_delete_link(self
->transients
, sit
);
1201 } else if (self
->transient_for
!= NULL
) { /* transient of window */
1202 /* add to new parent */
1203 self
->transient_for
->transients
=
1204 g_slist_append(self
->transient_for
->transients
, self
);
1209 static void client_get_mwm_hints(ObClient
*self
)
1214 self
->mwmhints
.flags
= 0; /* default to none */
1216 if (PROP_GETA32(self
->window
, motif_wm_hints
, motif_wm_hints
,
1218 if (num
>= OB_MWM_ELEMENTS
) {
1219 self
->mwmhints
.flags
= hints
[0];
1220 self
->mwmhints
.functions
= hints
[1];
1221 self
->mwmhints
.decorations
= hints
[2];
1227 void client_get_type(ObClient
*self
)
1234 if (PROP_GETA32(self
->window
, net_wm_window_type
, atom
, &val
, &num
)) {
1235 /* use the first value that we know about in the array */
1236 for (i
= 0; i
< num
; ++i
) {
1237 if (val
[i
] == prop_atoms
.net_wm_window_type_desktop
)
1238 self
->type
= OB_CLIENT_TYPE_DESKTOP
;
1239 else if (val
[i
] == prop_atoms
.net_wm_window_type_dock
)
1240 self
->type
= OB_CLIENT_TYPE_DOCK
;
1241 else if (val
[i
] == prop_atoms
.net_wm_window_type_toolbar
)
1242 self
->type
= OB_CLIENT_TYPE_TOOLBAR
;
1243 else if (val
[i
] == prop_atoms
.net_wm_window_type_menu
)
1244 self
->type
= OB_CLIENT_TYPE_MENU
;
1245 else if (val
[i
] == prop_atoms
.net_wm_window_type_utility
)
1246 self
->type
= OB_CLIENT_TYPE_UTILITY
;
1247 else if (val
[i
] == prop_atoms
.net_wm_window_type_splash
)
1248 self
->type
= OB_CLIENT_TYPE_SPLASH
;
1249 else if (val
[i
] == prop_atoms
.net_wm_window_type_dialog
)
1250 self
->type
= OB_CLIENT_TYPE_DIALOG
;
1251 else if (val
[i
] == prop_atoms
.net_wm_window_type_normal
)
1252 self
->type
= OB_CLIENT_TYPE_NORMAL
;
1253 else if (val
[i
] == prop_atoms
.kde_net_wm_window_type_override
) {
1254 /* prevent this window from getting any decor or
1256 self
->mwmhints
.flags
&= (OB_MWM_FLAG_FUNCTIONS
|
1257 OB_MWM_FLAG_DECORATIONS
);
1258 self
->mwmhints
.decorations
= 0;
1259 self
->mwmhints
.functions
= 0;
1261 if (self
->type
!= (ObClientType
) -1)
1262 break; /* grab the first legit type */
1267 if (self
->type
== (ObClientType
) -1) {
1268 /*the window type hint was not set, which means we either classify
1269 ourself as a normal window or a dialog, depending on if we are a
1271 if (self
->transient
)
1272 self
->type
= OB_CLIENT_TYPE_DIALOG
;
1274 self
->type
= OB_CLIENT_TYPE_NORMAL
;
1278 void client_update_protocols(ObClient
*self
)
1281 guint num_return
, i
;
1283 self
->focus_notify
= FALSE
;
1284 self
->delete_window
= FALSE
;
1286 if (PROP_GETA32(self
->window
, wm_protocols
, atom
, &proto
, &num_return
)) {
1287 for (i
= 0; i
< num_return
; ++i
) {
1288 if (proto
[i
] == prop_atoms
.wm_delete_window
) {
1289 /* this means we can request the window to close */
1290 self
->delete_window
= TRUE
;
1291 } else if (proto
[i
] == prop_atoms
.wm_take_focus
)
1292 /* if this protocol is requested, then the window will be
1293 notified whenever we want it to receive focus */
1294 self
->focus_notify
= TRUE
;
1300 static void client_get_gravity(ObClient
*self
)
1302 XWindowAttributes wattrib
;
1305 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
1306 g_assert(ret
!= BadWindow
);
1307 self
->gravity
= wattrib
.win_gravity
;
1310 void client_update_normal_hints(ObClient
*self
)
1314 gint oldgravity
= self
->gravity
;
1317 self
->min_ratio
= 0.0f
;
1318 self
->max_ratio
= 0.0f
;
1319 SIZE_SET(self
->size_inc
, 1, 1);
1320 SIZE_SET(self
->base_size
, 0, 0);
1321 SIZE_SET(self
->min_size
, 0, 0);
1322 SIZE_SET(self
->max_size
, G_MAXINT
, G_MAXINT
);
1324 /* get the hints from the window */
1325 if (XGetWMNormalHints(ob_display
, self
->window
, &size
, &ret
)) {
1326 /* normal windows can't request placement! har har
1327 if (!client_normal(self))
1329 self
->positioned
= (size
.flags
& (PPosition
|USPosition
));
1331 if (size
.flags
& PWinGravity
) {
1332 self
->gravity
= size
.win_gravity
;
1334 /* if the client has a frame, i.e. has already been mapped and
1335 is changing its gravity */
1336 if (self
->frame
&& self
->gravity
!= oldgravity
) {
1337 /* move our idea of the client's position based on its new
1339 self
->area
.x
= self
->frame
->area
.x
;
1340 self
->area
.y
= self
->frame
->area
.y
;
1341 frame_frame_gravity(self
->frame
, &self
->area
.x
, &self
->area
.y
);
1345 if (size
.flags
& PAspect
) {
1346 if (size
.min_aspect
.y
)
1348 (gfloat
) size
.min_aspect
.x
/ size
.min_aspect
.y
;
1349 if (size
.max_aspect
.y
)
1351 (gfloat
) size
.max_aspect
.x
/ size
.max_aspect
.y
;
1354 if (size
.flags
& PMinSize
)
1355 SIZE_SET(self
->min_size
, size
.min_width
, size
.min_height
);
1357 if (size
.flags
& PMaxSize
)
1358 SIZE_SET(self
->max_size
, size
.max_width
, size
.max_height
);
1360 if (size
.flags
& PBaseSize
)
1361 SIZE_SET(self
->base_size
, size
.base_width
, size
.base_height
);
1363 if (size
.flags
& PResizeInc
&& size
.width_inc
&& size
.height_inc
)
1364 SIZE_SET(self
->size_inc
, size
.width_inc
, size
.height_inc
);
1368 void client_setup_decor_and_functions(ObClient
*self
)
1370 /* start with everything (cept fullscreen) */
1372 (OB_FRAME_DECOR_TITLEBAR
|
1373 OB_FRAME_DECOR_HANDLE
|
1374 OB_FRAME_DECOR_GRIPS
|
1375 OB_FRAME_DECOR_BORDER
|
1376 OB_FRAME_DECOR_ICON
|
1377 OB_FRAME_DECOR_ALLDESKTOPS
|
1378 OB_FRAME_DECOR_ICONIFY
|
1379 OB_FRAME_DECOR_MAXIMIZE
|
1380 OB_FRAME_DECOR_SHADE
|
1381 OB_FRAME_DECOR_CLOSE
);
1383 (OB_CLIENT_FUNC_RESIZE
|
1384 OB_CLIENT_FUNC_MOVE
|
1385 OB_CLIENT_FUNC_ICONIFY
|
1386 OB_CLIENT_FUNC_MAXIMIZE
|
1387 OB_CLIENT_FUNC_SHADE
|
1388 OB_CLIENT_FUNC_CLOSE
);
1390 if (!(self
->min_size
.width
< self
->max_size
.width
||
1391 self
->min_size
.height
< self
->max_size
.height
))
1392 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
1394 switch (self
->type
) {
1395 case OB_CLIENT_TYPE_NORMAL
:
1396 /* normal windows retain all of the possible decorations and
1397 functionality, and are the only windows that you can fullscreen */
1398 self
->functions
|= OB_CLIENT_FUNC_FULLSCREEN
;
1401 case OB_CLIENT_TYPE_DIALOG
:
1402 case OB_CLIENT_TYPE_UTILITY
:
1403 /* these windows cannot be maximized */
1404 self
->functions
&= ~OB_CLIENT_FUNC_MAXIMIZE
;
1407 case OB_CLIENT_TYPE_MENU
:
1408 case OB_CLIENT_TYPE_TOOLBAR
:
1409 /* these windows get less functionality */
1410 self
->functions
&= ~(OB_CLIENT_FUNC_ICONIFY
| OB_CLIENT_FUNC_RESIZE
);
1413 case OB_CLIENT_TYPE_DESKTOP
:
1414 case OB_CLIENT_TYPE_DOCK
:
1415 case OB_CLIENT_TYPE_SPLASH
:
1416 /* none of these windows are manipulated by the window manager */
1417 self
->decorations
= 0;
1418 self
->functions
= 0;
1422 /* Mwm Hints are applied subtractively to what has already been chosen for
1423 decor and functionality */
1424 if (self
->mwmhints
.flags
& OB_MWM_FLAG_DECORATIONS
) {
1425 if (! (self
->mwmhints
.decorations
& OB_MWM_DECOR_ALL
)) {
1426 if (! ((self
->mwmhints
.decorations
& OB_MWM_DECOR_HANDLE
) ||
1427 (self
->mwmhints
.decorations
& OB_MWM_DECOR_TITLE
)))
1429 /* if the mwm hints request no handle or title, then all
1430 decorations are disabled, but keep the border if that's
1432 if (self
->mwmhints
.decorations
& OB_MWM_DECOR_BORDER
)
1433 self
->decorations
= OB_FRAME_DECOR_BORDER
;
1435 self
->decorations
= 0;
1440 if (self
->mwmhints
.flags
& OB_MWM_FLAG_FUNCTIONS
) {
1441 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_ALL
)) {
1442 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_RESIZE
))
1443 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
1444 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_MOVE
))
1445 self
->functions
&= ~OB_CLIENT_FUNC_MOVE
;
1446 /* dont let mwm hints kill any buttons
1447 if (! (self->mwmhints.functions & OB_MWM_FUNC_ICONIFY))
1448 self->functions &= ~OB_CLIENT_FUNC_ICONIFY;
1449 if (! (self->mwmhints.functions & OB_MWM_FUNC_MAXIMIZE))
1450 self->functions &= ~OB_CLIENT_FUNC_MAXIMIZE;
1452 /* dont let mwm hints kill the close button
1453 if (! (self->mwmhints.functions & MwmFunc_Close))
1454 self->functions &= ~OB_CLIENT_FUNC_CLOSE; */
1458 if (!(self
->functions
& OB_CLIENT_FUNC_SHADE
))
1459 self
->decorations
&= ~OB_FRAME_DECOR_SHADE
;
1460 if (!(self
->functions
& OB_CLIENT_FUNC_ICONIFY
))
1461 self
->decorations
&= ~OB_FRAME_DECOR_ICONIFY
;
1462 if (!(self
->functions
& OB_CLIENT_FUNC_RESIZE
))
1463 self
->decorations
&= ~OB_FRAME_DECOR_GRIPS
;
1465 /* can't maximize without moving/resizing */
1466 if (!((self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) &&
1467 (self
->functions
& OB_CLIENT_FUNC_MOVE
) &&
1468 (self
->functions
& OB_CLIENT_FUNC_RESIZE
))) {
1469 self
->functions
&= ~OB_CLIENT_FUNC_MAXIMIZE
;
1470 self
->decorations
&= ~OB_FRAME_DECOR_MAXIMIZE
;
1473 /* kill the handle on fully maxed windows */
1474 if (self
->max_vert
&& self
->max_horz
)
1475 self
->decorations
&= ~OB_FRAME_DECOR_HANDLE
;
1477 /* finally, the user can have requested no decorations, which overrides
1478 everything (but doesnt give it a border if it doesnt have one) */
1479 if (self
->undecorated
) {
1480 if (config_theme_keepborder
)
1481 self
->decorations
&= OB_FRAME_DECOR_BORDER
;
1483 self
->decorations
= 0;
1486 /* if we don't have a titlebar, then we cannot shade! */
1487 if (!(self
->decorations
& OB_FRAME_DECOR_TITLEBAR
))
1488 self
->functions
&= ~OB_CLIENT_FUNC_SHADE
;
1490 /* now we need to check against rules for the client's current state */
1491 if (self
->fullscreen
) {
1492 self
->functions
&= (OB_CLIENT_FUNC_CLOSE
|
1493 OB_CLIENT_FUNC_FULLSCREEN
|
1494 OB_CLIENT_FUNC_ICONIFY
);
1495 self
->decorations
= 0;
1498 client_change_allowed_actions(self
);
1501 /* adjust the client's decorations, etc. */
1502 client_reconfigure(self
);
1506 static void client_change_allowed_actions(ObClient
*self
)
1511 /* desktop windows are kept on all desktops */
1512 if (self
->type
!= OB_CLIENT_TYPE_DESKTOP
)
1513 actions
[num
++] = prop_atoms
.net_wm_action_change_desktop
;
1515 if (self
->functions
& OB_CLIENT_FUNC_SHADE
)
1516 actions
[num
++] = prop_atoms
.net_wm_action_shade
;
1517 if (self
->functions
& OB_CLIENT_FUNC_CLOSE
)
1518 actions
[num
++] = prop_atoms
.net_wm_action_close
;
1519 if (self
->functions
& OB_CLIENT_FUNC_MOVE
)
1520 actions
[num
++] = prop_atoms
.net_wm_action_move
;
1521 if (self
->functions
& OB_CLIENT_FUNC_ICONIFY
)
1522 actions
[num
++] = prop_atoms
.net_wm_action_minimize
;
1523 if (self
->functions
& OB_CLIENT_FUNC_RESIZE
)
1524 actions
[num
++] = prop_atoms
.net_wm_action_resize
;
1525 if (self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
)
1526 actions
[num
++] = prop_atoms
.net_wm_action_fullscreen
;
1527 if (self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) {
1528 actions
[num
++] = prop_atoms
.net_wm_action_maximize_horz
;
1529 actions
[num
++] = prop_atoms
.net_wm_action_maximize_vert
;
1532 PROP_SETA32(self
->window
, net_wm_allowed_actions
, atom
, actions
, num
);
1534 /* make sure the window isn't breaking any rules now */
1536 if (!(self
->functions
& OB_CLIENT_FUNC_SHADE
) && self
->shaded
) {
1537 if (self
->frame
) client_shade(self
, FALSE
);
1538 else self
->shaded
= FALSE
;
1540 if (!(self
->functions
& OB_CLIENT_FUNC_ICONIFY
) && self
->iconic
) {
1541 if (self
->frame
) client_iconify(self
, FALSE
, TRUE
);
1542 else self
->iconic
= FALSE
;
1544 if (!(self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
) && self
->fullscreen
) {
1545 if (self
->frame
) client_fullscreen(self
, FALSE
);
1546 else self
->fullscreen
= FALSE
;
1548 if (!(self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) && (self
->max_horz
||
1550 if (self
->frame
) client_maximize(self
, FALSE
, 0);
1551 else self
->max_vert
= self
->max_horz
= FALSE
;
1555 void client_reconfigure(ObClient
*self
)
1557 /* by making this pass FALSE for user, we avoid the emacs event storm where
1558 every configurenotify causes an update in its normal hints, i think this
1559 is generally what we want anyways... */
1560 client_configure(self
, OB_CORNER_TOPLEFT
, self
->area
.x
, self
->area
.y
,
1561 self
->area
.width
, self
->area
.height
, FALSE
, TRUE
);
1564 void client_update_wmhints(ObClient
*self
)
1569 /* assume a window takes input if it doesnt specify */
1570 self
->can_focus
= TRUE
;
1572 if ((hints
= XGetWMHints(ob_display
, self
->window
)) != NULL
) {
1573 if (hints
->flags
& InputHint
)
1574 self
->can_focus
= hints
->input
;
1576 /* only do this when first managing the window *AND* when we aren't
1578 if (ob_state() != OB_STATE_STARTING
&& self
->frame
== NULL
)
1579 if (hints
->flags
& StateHint
)
1580 self
->iconic
= hints
->initial_state
== IconicState
;
1582 if (!(hints
->flags
& WindowGroupHint
))
1583 hints
->window_group
= None
;
1585 /* did the group state change? */
1586 if (hints
->window_group
!=
1587 (self
->group
? self
->group
->leader
: None
)) {
1588 /* remove from the old group if there was one */
1589 if (self
->group
!= NULL
) {
1590 /* remove transients of the group */
1591 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
))
1592 self
->transients
= g_slist_remove(self
->transients
,
1595 /* remove myself from parents in the group */
1596 if (self
->transient_for
== OB_TRAN_GROUP
) {
1597 for (it
= self
->group
->members
; it
;
1598 it
= g_slist_next(it
))
1600 ObClient
*c
= it
->data
;
1602 if (c
!= self
&& !c
->transient_for
)
1603 c
->transients
= g_slist_remove(c
->transients
,
1608 group_remove(self
->group
, self
);
1611 if (hints
->window_group
!= None
) {
1612 self
->group
= group_add(hints
->window_group
, self
);
1614 /* i can only have transients from the group if i am not
1616 if (!self
->transient_for
) {
1617 /* add other transients of the group that are already
1619 for (it
= self
->group
->members
; it
;
1620 it
= g_slist_next(it
))
1622 ObClient
*c
= it
->data
;
1623 if (c
!= self
&& c
->transient_for
== OB_TRAN_GROUP
)
1625 g_slist_append(self
->transients
, c
);
1630 /* because the self->transient flag wont change from this call,
1631 we don't need to update the window's type and such, only its
1632 transient_for, and the transients lists of other windows in
1633 the group may be affected */
1634 client_update_transient_for(self
);
1637 /* the WM_HINTS can contain an icon */
1638 client_update_icons(self
);
1644 void client_update_title(ObClient
*self
)
1648 g_free(self
->title
);
1651 if (!PROP_GETS(self
->window
, net_wm_name
, utf8
, &data
)) {
1652 /* try old x stuff */
1653 if (!(PROP_GETS(self
->window
, wm_name
, locale
, &data
)
1654 || PROP_GETS(self
->window
, wm_name
, utf8
, &data
))) {
1655 if (self
->transient
) {
1657 GNOME alert windows are not given titles:
1658 http://developer.gnome.org/projects/gup/hig/draft_hig_new/windows-alert.html
1660 data
= g_strdup("");
1662 data
= g_strdup("Unnamed Window");
1666 PROP_SETS(self
->window
, net_wm_visible_name
, data
);
1670 frame_adjust_title(self
->frame
);
1672 /* update the icon title */
1674 g_free(self
->icon_title
);
1677 if (!PROP_GETS(self
->window
, net_wm_icon_name
, utf8
, &data
))
1678 /* try old x stuff */
1679 if (!(PROP_GETS(self
->window
, wm_icon_name
, locale
, &data
) ||
1680 PROP_GETS(self
->window
, wm_icon_name
, utf8
, &data
)))
1681 data
= g_strdup(self
->title
);
1683 PROP_SETS(self
->window
, net_wm_visible_icon_name
, data
);
1684 self
->icon_title
= data
;
1687 void client_update_class(ObClient
*self
)
1692 if (self
->name
) g_free(self
->name
);
1693 if (self
->class) g_free(self
->class);
1694 if (self
->role
) g_free(self
->role
);
1696 self
->name
= self
->class = self
->role
= NULL
;
1698 if (PROP_GETSS(self
->window
, wm_class
, locale
, &data
)) {
1700 self
->name
= g_strdup(data
[0]);
1702 self
->class = g_strdup(data
[1]);
1707 if (PROP_GETS(self
->window
, wm_window_role
, locale
, &s
))
1710 if (self
->name
== NULL
) self
->name
= g_strdup("");
1711 if (self
->class == NULL
) self
->class = g_strdup("");
1712 if (self
->role
== NULL
) self
->role
= g_strdup("");
1715 void client_update_strut(ObClient
*self
)
1719 gboolean got
= FALSE
;
1722 if (PROP_GETA32(self
->window
, net_wm_strut_partial
, cardinal
,
1726 STRUT_PARTIAL_SET(strut
,
1727 data
[0], data
[2], data
[1], data
[3],
1728 data
[4], data
[5], data
[8], data
[9],
1729 data
[6], data
[7], data
[10], data
[11]);
1735 PROP_GETA32(self
->window
, net_wm_strut
, cardinal
, &data
, &num
)) {
1741 /* use the screen's width/height */
1742 a
= screen_physical_area();
1744 STRUT_PARTIAL_SET(strut
,
1745 data
[0], data
[2], data
[1], data
[3],
1746 a
->y
, a
->y
+ a
->height
- 1,
1747 a
->x
, a
->x
+ a
->width
- 1,
1748 a
->y
, a
->y
+ a
->height
- 1,
1749 a
->x
, a
->x
+ a
->width
- 1);
1755 STRUT_PARTIAL_SET(strut
, 0, 0, 0, 0,
1756 0, 0, 0, 0, 0, 0, 0, 0);
1758 if (!STRUT_EQUAL(strut
, self
->strut
)) {
1759 self
->strut
= strut
;
1761 /* updating here is pointless while we're being mapped cuz we're not in
1762 the client list yet */
1764 screen_update_areas();
1768 void client_update_icons(ObClient
*self
)
1774 for (i
= 0; i
< self
->nicons
; ++i
)
1775 g_free(self
->icons
[i
].data
);
1776 if (self
->nicons
> 0)
1777 g_free(self
->icons
);
1780 if (PROP_GETA32(self
->window
, net_wm_icon
, cardinal
, &data
, &num
)) {
1781 /* figure out how many valid icons are in here */
1783 while (num
- i
> 2) {
1787 if (i
> num
|| w
*h
== 0) break;
1791 self
->icons
= g_new(ObClientIcon
, self
->nicons
);
1793 /* store the icons */
1795 for (j
= 0; j
< self
->nicons
; ++j
) {
1798 w
= self
->icons
[j
].width
= data
[i
++];
1799 h
= self
->icons
[j
].height
= data
[i
++];
1801 if (w
*h
== 0) continue;
1803 self
->icons
[j
].data
= g_new(RrPixel32
, w
* h
);
1804 for (x
= 0, y
= 0, t
= 0; t
< w
* h
; ++t
, ++x
, ++i
) {
1809 self
->icons
[j
].data
[t
] =
1810 (((data
[i
] >> 24) & 0xff) << RrDefaultAlphaOffset
) +
1811 (((data
[i
] >> 16) & 0xff) << RrDefaultRedOffset
) +
1812 (((data
[i
] >> 8) & 0xff) << RrDefaultGreenOffset
) +
1813 (((data
[i
] >> 0) & 0xff) << RrDefaultBlueOffset
);
1822 if ((hints
= XGetWMHints(ob_display
, self
->window
))) {
1823 if (hints
->flags
& IconPixmapHint
) {
1825 self
->icons
= g_new(ObClientIcon
, self
->nicons
);
1826 xerror_set_ignore(TRUE
);
1827 if (!RrPixmapToRGBA(ob_rr_inst
,
1829 (hints
->flags
& IconMaskHint
?
1830 hints
->icon_mask
: None
),
1831 &self
->icons
[self
->nicons
-1].width
,
1832 &self
->icons
[self
->nicons
-1].height
,
1833 &self
->icons
[self
->nicons
-1].data
)){
1834 g_free(&self
->icons
[self
->nicons
-1]);
1837 xerror_set_ignore(FALSE
);
1844 frame_adjust_icon(self
->frame
);
1847 void client_update_user_time(ObClient
*self
, gboolean new_event
)
1851 if (PROP_GET32(self
->window
, net_wm_user_time
, cardinal
, &time
)) {
1852 self
->user_time
= time
;
1853 /* we set this every time, not just when it grows, because in practice
1854 sometimes time goes backwards! (ntpdate.. yay....) so.. if it goes
1855 backward we don't want all windows to stop focusing. we'll just
1856 assume noone is setting times older than the last one, cuz that
1857 would be pretty stupid anyways
1858 However! This is called when a window is mapped to get its user time
1859 but it's an old number, it's not changing it from new user
1860 interaction, so in that case, don't change the last user time.
1863 client_last_user_time
= time
;
1866 ob_debug("window %s user time %u\n", self->title, time);
1867 ob_debug("last user time %u\n", client_last_user_time);
1872 static void client_change_wm_state(ObClient
*self
)
1877 old
= self
->wmstate
;
1879 if (self
->shaded
|| self
->iconic
|| !self
->frame
->visible
)
1880 self
->wmstate
= IconicState
;
1882 self
->wmstate
= NormalState
;
1884 if (old
!= self
->wmstate
) {
1885 PROP_MSG(self
->window
, kde_wm_change_state
,
1886 self
->wmstate
, 1, 0, 0);
1888 state
[0] = self
->wmstate
;
1890 PROP_SETA32(self
->window
, wm_state
, wm_state
, state
, 2);
1894 static void client_change_state(ObClient
*self
)
1896 gulong netstate
[11];
1901 netstate
[num
++] = prop_atoms
.net_wm_state_modal
;
1903 netstate
[num
++] = prop_atoms
.net_wm_state_shaded
;
1905 netstate
[num
++] = prop_atoms
.net_wm_state_hidden
;
1906 if (self
->skip_taskbar
)
1907 netstate
[num
++] = prop_atoms
.net_wm_state_skip_taskbar
;
1908 if (self
->skip_pager
)
1909 netstate
[num
++] = prop_atoms
.net_wm_state_skip_pager
;
1910 if (self
->fullscreen
)
1911 netstate
[num
++] = prop_atoms
.net_wm_state_fullscreen
;
1913 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_vert
;
1915 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_horz
;
1917 netstate
[num
++] = prop_atoms
.net_wm_state_above
;
1919 netstate
[num
++] = prop_atoms
.net_wm_state_below
;
1920 if (self
->demands_attention
)
1921 netstate
[num
++] = prop_atoms
.net_wm_state_demands_attention
;
1922 if (self
->undecorated
)
1923 netstate
[num
++] = prop_atoms
.ob_wm_state_undecorated
;
1924 PROP_SETA32(self
->window
, net_wm_state
, atom
, netstate
, num
);
1927 frame_adjust_state(self
->frame
);
1930 ObClient
*client_search_focus_tree(ObClient
*self
)
1935 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
1936 if (client_focused(it
->data
)) return it
->data
;
1937 if ((ret
= client_search_focus_tree(it
->data
))) return ret
;
1942 ObClient
*client_search_focus_tree_full(ObClient
*self
)
1944 if (self
->transient_for
) {
1945 if (self
->transient_for
!= OB_TRAN_GROUP
) {
1946 return client_search_focus_tree_full(self
->transient_for
);
1949 gboolean recursed
= FALSE
;
1951 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
))
1952 if (!((ObClient
*)it
->data
)->transient_for
) {
1954 if ((c
= client_search_focus_tree_full(it
->data
)))
1963 /* this function checks the whole tree, the client_search_focus_tree~
1964 does not, so we need to check this window */
1965 if (client_focused(self
))
1967 return client_search_focus_tree(self
);
1970 static ObStackingLayer
calc_layer(ObClient
*self
)
1974 if (self
->fullscreen
&&
1975 (client_focused(self
) || client_search_focus_tree(self
)))
1976 l
= OB_STACKING_LAYER_FULLSCREEN
;
1977 else if (self
->type
== OB_CLIENT_TYPE_DESKTOP
)
1978 l
= OB_STACKING_LAYER_DESKTOP
;
1979 else if (self
->type
== OB_CLIENT_TYPE_DOCK
) {
1980 if (self
->below
) l
= OB_STACKING_LAYER_NORMAL
;
1981 else l
= OB_STACKING_LAYER_ABOVE
;
1983 else if (self
->above
) l
= OB_STACKING_LAYER_ABOVE
;
1984 else if (self
->below
) l
= OB_STACKING_LAYER_BELOW
;
1985 else l
= OB_STACKING_LAYER_NORMAL
;
1990 static void client_calc_layer_recursive(ObClient
*self
, ObClient
*orig
,
1991 ObStackingLayer min
, gboolean raised
)
1993 ObStackingLayer old
, own
;
1997 own
= calc_layer(self
);
1998 self
->layer
= MAX(own
, min
);
2000 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
2001 client_calc_layer_recursive(it
->data
, orig
,
2003 raised
? raised
: self
->layer
!= old
);
2005 if (!raised
&& self
->layer
!= old
)
2006 if (orig
->frame
) { /* only restack if the original window is managed */
2007 stacking_remove(CLIENT_AS_WINDOW(self
));
2008 stacking_add(CLIENT_AS_WINDOW(self
));
2012 void client_calc_layer(ObClient
*self
)
2019 /* transients take on the layer of their parents */
2020 it
= client_search_all_top_parents(self
);
2022 for (; it
; it
= g_slist_next(it
))
2023 client_calc_layer_recursive(it
->data
, orig
, 0, FALSE
);
2026 gboolean
client_should_show(ObClient
*self
)
2030 if (client_normal(self
) && screen_showing_desktop
)
2033 if (self->transient_for) {
2034 if (self->transient_for != OB_TRAN_GROUP)
2035 return client_should_show(self->transient_for);
2039 for (it = self->group->members; it; it = g_slist_next(it)) {
2040 ObClient *c = it->data;
2041 if (c != self && !c->transient_for) {
2042 if (client_should_show(c))
2049 if (self
->desktop
== screen_desktop
|| self
->desktop
== DESKTOP_ALL
)
2055 void client_showhide(ObClient
*self
)
2058 if (client_should_show(self
)) {
2059 frame_show(self
->frame
);
2062 frame_hide(self
->frame
);
2064 /* Fall back focus since we're disappearing */
2065 if (focus_client
== self
)
2066 client_unfocus(self
);
2069 /* According to the ICCCM (sec 4.1.3.1) when a window is not visible, it
2070 needs to be in IconicState. This includes when it is on another
2073 client_change_wm_state(self
);
2076 gboolean
client_normal(ObClient
*self
) {
2077 return ! (self
->type
== OB_CLIENT_TYPE_DESKTOP
||
2078 self
->type
== OB_CLIENT_TYPE_DOCK
||
2079 self
->type
== OB_CLIENT_TYPE_SPLASH
);
2082 static void client_apply_startup_state(ObClient
*self
, gint x
, gint y
)
2084 gboolean pos
= FALSE
; /* has the window's position been configured? */
2087 /* save the position, and set self->area for these to use */
2093 /* these are in a carefully crafted order.. */
2096 self
->iconic
= FALSE
;
2097 client_iconify(self
, TRUE
, FALSE
);
2099 if (self
->fullscreen
) {
2100 self
->fullscreen
= FALSE
;
2101 client_fullscreen(self
, TRUE
);
2104 if (self
->undecorated
) {
2105 self
->undecorated
= FALSE
;
2106 client_set_undecorated(self
, TRUE
);
2109 self
->shaded
= FALSE
;
2110 client_shade(self
, TRUE
);
2112 if (self
->demands_attention
) {
2113 self
->demands_attention
= FALSE
;
2114 client_hilite(self
, TRUE
);
2117 if (self
->max_vert
&& self
->max_horz
) {
2118 self
->max_vert
= self
->max_horz
= FALSE
;
2119 client_maximize(self
, TRUE
, 0);
2121 } else if (self
->max_vert
) {
2122 self
->max_vert
= FALSE
;
2123 client_maximize(self
, TRUE
, 2);
2125 } else if (self
->max_horz
) {
2126 self
->max_horz
= FALSE
;
2127 client_maximize(self
, TRUE
, 1);
2131 /* if the client didn't get positioned yet, then do so now */
2132 if (!pos
&& (ox
!= x
|| oy
!= y
)) {
2133 /* use the saved position */
2136 client_move(self
, x
, y
);
2139 /* nothing to do for the other states:
2148 void client_try_configure(ObClient
*self
, ObCorner anchor
,
2149 gint
*x
, gint
*y
, gint
*w
, gint
*h
,
2150 gint
*logicalw
, gint
*logicalh
,
2153 Rect desired_area
= {*x
, *y
, *w
, *h
};
2155 /* make the frame recalculate its dimentions n shit without changing
2156 anything visible for real, this way the constraints below can work with
2157 the updated frame dimensions. */
2158 frame_adjust_area(self
->frame
, TRUE
, TRUE
, TRUE
);
2160 /* gets the frame's position */
2161 frame_client_gravity(self
->frame
, x
, y
);
2163 /* these positions are frame positions, not client positions */
2165 /* set the size and position if fullscreen */
2166 if (self
->fullscreen
) {
2170 i
= screen_find_monitor(&desired_area
);
2171 a
= screen_physical_area_monitor(i
);
2178 user
= FALSE
; /* ignore that increment etc shit when in fullscreen */
2183 i
= screen_find_monitor(&desired_area
);
2184 a
= screen_area_monitor(self
->desktop
, i
);
2186 /* set the size and position if maximized */
2187 if (self
->max_horz
) {
2189 *w
= a
->width
- self
->frame
->size
.left
- self
->frame
->size
.right
;
2191 if (self
->max_vert
) {
2193 *h
= a
->height
- self
->frame
->size
.top
- self
->frame
->size
.bottom
;
2197 /* gets the client's position */
2198 frame_frame_gravity(self
->frame
, x
, y
);
2200 /* these override the above states! if you cant move you can't move! */
2202 if (!(self
->functions
& OB_CLIENT_FUNC_MOVE
)) {
2206 if (!(self
->functions
& OB_CLIENT_FUNC_RESIZE
)) {
2207 *w
= self
->area
.width
;
2208 *h
= self
->area
.height
;
2212 if (!(*w
== self
->area
.width
&& *h
== self
->area
.height
)) {
2213 gint basew
, baseh
, minw
, minh
;
2215 /* base size is substituted with min size if not specified */
2216 if (self
->base_size
.width
|| self
->base_size
.height
) {
2217 basew
= self
->base_size
.width
;
2218 baseh
= self
->base_size
.height
;
2220 basew
= self
->min_size
.width
;
2221 baseh
= self
->min_size
.height
;
2223 /* min size is substituted with base size if not specified */
2224 if (self
->min_size
.width
|| self
->min_size
.height
) {
2225 minw
= self
->min_size
.width
;
2226 minh
= self
->min_size
.height
;
2228 minw
= self
->base_size
.width
;
2229 minh
= self
->base_size
.height
;
2232 /* if this is a user-requested resize, then check against min/max
2235 /* smaller than min size or bigger than max size? */
2236 if (*w
> self
->max_size
.width
) *w
= self
->max_size
.width
;
2237 if (*w
< minw
) *w
= minw
;
2238 if (*h
> self
->max_size
.height
) *h
= self
->max_size
.height
;
2239 if (*h
< minh
) *h
= minh
;
2244 /* keep to the increments */
2245 *w
/= self
->size_inc
.width
;
2246 *h
/= self
->size_inc
.height
;
2248 /* you cannot resize to nothing */
2249 if (basew
+ *w
< 1) *w
= 1 - basew
;
2250 if (baseh
+ *h
< 1) *h
= 1 - baseh
;
2252 /* save the logical size */
2253 *logicalw
= self
->size_inc
.width
> 1 ? *w
: *w
+ basew
;
2254 *logicalh
= self
->size_inc
.height
> 1 ? *h
: *h
+ baseh
;
2256 *w
*= self
->size_inc
.width
;
2257 *h
*= self
->size_inc
.height
;
2262 /* adjust the height to match the width for the aspect ratios.
2263 for this, min size is not substituted for base size ever. */
2264 *w
-= self
->base_size
.width
;
2265 *h
-= self
->base_size
.height
;
2267 if (!self
->fullscreen
) {
2268 if (self
->min_ratio
)
2269 if (*h
* self
->min_ratio
> *w
) {
2270 *h
= (gint
)(*w
/ self
->min_ratio
);
2272 /* you cannot resize to nothing */
2275 *w
= (gint
)(*h
* self
->min_ratio
);
2278 if (self
->max_ratio
)
2279 if (*h
* self
->max_ratio
< *w
) {
2280 *h
= (gint
)(*w
/ self
->max_ratio
);
2282 /* you cannot resize to nothing */
2285 *w
= (gint
)(*h
* self
->min_ratio
);
2290 *w
+= self
->base_size
.width
;
2291 *h
+= self
->base_size
.height
;
2298 case OB_CORNER_TOPLEFT
:
2300 case OB_CORNER_TOPRIGHT
:
2301 *x
-= *w
- self
->area
.width
;
2303 case OB_CORNER_BOTTOMLEFT
:
2304 *y
-= *h
- self
->area
.height
;
2306 case OB_CORNER_BOTTOMRIGHT
:
2307 *x
-= *w
- self
->area
.width
;
2308 *y
-= *h
- self
->area
.height
;
2314 void client_configure_full(ObClient
*self
, ObCorner anchor
,
2315 gint x
, gint y
, gint w
, gint h
,
2316 gboolean user
, gboolean final
,
2317 gboolean force_reply
)
2320 gboolean send_resize_client
;
2321 gboolean moved
= FALSE
, resized
= FALSE
;
2322 guint fdecor
= self
->frame
->decorations
;
2323 gboolean fhorz
= self
->frame
->max_horz
;
2324 gint logicalw
, logicalh
;
2326 /* find the new x, y, width, and height (and logical size) */
2327 client_try_configure(self
, anchor
, &x
, &y
, &w
, &h
,
2328 &logicalw
, &logicalh
, user
);
2330 /* set the logical size if things changed */
2331 if (!(w
== self
->area
.width
&& h
== self
->area
.height
))
2332 SIZE_SET(self
->logical_size
, logicalw
, logicalh
);
2334 /* figure out if we moved or resized or what */
2335 moved
= x
!= self
->area
.x
|| y
!= self
->area
.y
;
2336 resized
= w
!= self
->area
.width
|| h
!= self
->area
.height
;
2338 oldw
= self
->area
.width
;
2339 oldh
= self
->area
.height
;
2340 RECT_SET(self
->area
, x
, y
, w
, h
);
2342 /* for app-requested resizes, always resize if 'resized' is true.
2343 for user-requested ones, only resize if final is true, or when
2344 resizing in redraw mode */
2345 send_resize_client
= ((!user
&& resized
) ||
2347 (resized
&& config_resize_redraw
))));
2349 /* if the client is enlarging, then resize the client before the frame */
2350 if (send_resize_client
&& user
&& (w
> oldw
|| h
> oldh
))
2351 XResizeWindow(ob_display
, self
->window
, MAX(w
, oldw
), MAX(h
, oldh
));
2353 /* move/resize the frame to match the request */
2355 if (self
->decorations
!= fdecor
|| self
->max_horz
!= fhorz
)
2356 moved
= resized
= TRUE
;
2358 if (moved
|| resized
)
2359 frame_adjust_area(self
->frame
, moved
, resized
, FALSE
);
2361 if (!resized
&& (force_reply
|| ((!user
&& moved
) || (user
&& final
))))
2364 event
.type
= ConfigureNotify
;
2365 event
.xconfigure
.display
= ob_display
;
2366 event
.xconfigure
.event
= self
->window
;
2367 event
.xconfigure
.window
= self
->window
;
2369 /* root window real coords */
2370 event
.xconfigure
.x
= self
->frame
->area
.x
+ self
->frame
->size
.left
-
2372 event
.xconfigure
.y
= self
->frame
->area
.y
+ self
->frame
->size
.top
-
2374 event
.xconfigure
.width
= w
;
2375 event
.xconfigure
.height
= h
;
2376 event
.xconfigure
.border_width
= 0;
2377 event
.xconfigure
.above
= self
->frame
->plate
;
2378 event
.xconfigure
.override_redirect
= FALSE
;
2379 XSendEvent(event
.xconfigure
.display
, event
.xconfigure
.window
,
2380 FALSE
, StructureNotifyMask
, &event
);
2384 /* if the client is shrinking, then resize the frame before the client */
2385 if (send_resize_client
&& (!user
|| (w
<= oldw
|| h
<= oldh
)))
2386 XResizeWindow(ob_display
, self
->window
, w
, h
);
2391 void client_fullscreen(ObClient
*self
, gboolean fs
)
2395 if (!(self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
) || /* can't */
2396 self
->fullscreen
== fs
) return; /* already done */
2398 self
->fullscreen
= fs
;
2399 client_change_state(self
); /* change the state hints on the client */
2400 client_calc_layer(self
); /* and adjust out layer/stacking */
2403 self
->pre_fullscreen_area
= self
->area
;
2404 /* if the window is maximized, its area isn't all that meaningful.
2405 save it's premax area instead. */
2406 if (self
->max_horz
) {
2407 self
->pre_fullscreen_area
.x
= self
->pre_max_area
.x
;
2408 self
->pre_fullscreen_area
.width
= self
->pre_max_area
.width
;
2410 if (self
->max_vert
) {
2411 self
->pre_fullscreen_area
.y
= self
->pre_max_area
.y
;
2412 self
->pre_fullscreen_area
.height
= self
->pre_max_area
.height
;
2415 /* these are not actually used cuz client_configure will set them
2416 as appropriate when the window is fullscreened */
2421 if (self
->pre_fullscreen_area
.width
> 0 &&
2422 self
->pre_fullscreen_area
.height
> 0)
2424 x
= self
->pre_fullscreen_area
.x
;
2425 y
= self
->pre_fullscreen_area
.y
;
2426 w
= self
->pre_fullscreen_area
.width
;
2427 h
= self
->pre_fullscreen_area
.height
;
2428 RECT_SET(self
->pre_fullscreen_area
, 0, 0, 0, 0);
2430 /* pick some fallbacks... */
2431 a
= screen_area_monitor(self
->desktop
, 0);
2432 x
= a
->x
+ a
->width
/ 4;
2433 y
= a
->y
+ a
->height
/ 4;
2439 client_setup_decor_and_functions(self
);
2441 client_move_resize(self
, x
, y
, w
, h
);
2443 /* try focus us when we go into fullscreen mode */
2447 static void client_iconify_recursive(ObClient
*self
,
2448 gboolean iconic
, gboolean curdesk
)
2451 gboolean changed
= FALSE
;
2454 if (self
->iconic
!= iconic
) {
2455 ob_debug("%sconifying window: 0x%lx\n", (iconic
? "I" : "Uni"),
2459 if (self
->functions
& OB_CLIENT_FUNC_ICONIFY
) {
2460 self
->iconic
= iconic
;
2462 /* update the focus lists.. iconic windows go to the bottom of
2463 the list, put the new iconic window at the 'top of the
2465 focus_order_to_top(self
);
2470 self
->iconic
= iconic
;
2473 client_set_desktop(self
, screen_desktop
, FALSE
);
2475 /* this puts it after the current focused window */
2476 focus_order_remove(self
);
2477 focus_order_add_new(self
);
2484 client_change_state(self
);
2485 client_showhide(self
);
2486 if (STRUT_EXISTS(self
->strut
))
2487 screen_update_areas();
2490 /* iconify all direct transients */
2491 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
2492 if (it
->data
!= self
)
2493 if (client_is_direct_child(self
, it
->data
))
2494 client_iconify_recursive(it
->data
, iconic
, curdesk
);
2497 void client_iconify(ObClient
*self
, gboolean iconic
, gboolean curdesk
)
2499 /* move up the transient chain as far as possible first */
2500 self
= client_search_top_parent(self
);
2501 client_iconify_recursive(self
, iconic
, curdesk
);
2504 void client_maximize(ObClient
*self
, gboolean max
, gint dir
)
2508 g_assert(dir
== 0 || dir
== 1 || dir
== 2);
2509 if (!(self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
)) return; /* can't */
2511 /* check if already done */
2513 if (dir
== 0 && self
->max_horz
&& self
->max_vert
) return;
2514 if (dir
== 1 && self
->max_horz
) return;
2515 if (dir
== 2 && self
->max_vert
) return;
2517 if (dir
== 0 && !self
->max_horz
&& !self
->max_vert
) return;
2518 if (dir
== 1 && !self
->max_horz
) return;
2519 if (dir
== 2 && !self
->max_vert
) return;
2522 /* we just tell it to configure in the same place and client_configure
2523 worries about filling the screen with the window */
2526 w
= self
->area
.width
;
2527 h
= self
->area
.height
;
2530 if ((dir
== 0 || dir
== 1) && !self
->max_horz
) { /* horz */
2531 RECT_SET(self
->pre_max_area
,
2532 self
->area
.x
, self
->pre_max_area
.y
,
2533 self
->area
.width
, self
->pre_max_area
.height
);
2535 if ((dir
== 0 || dir
== 2) && !self
->max_vert
) { /* vert */
2536 RECT_SET(self
->pre_max_area
,
2537 self
->pre_max_area
.x
, self
->area
.y
,
2538 self
->pre_max_area
.width
, self
->area
.height
);
2543 a
= screen_area_monitor(self
->desktop
, 0);
2544 if ((dir
== 0 || dir
== 1) && self
->max_horz
) { /* horz */
2545 if (self
->pre_max_area
.width
> 0) {
2546 x
= self
->pre_max_area
.x
;
2547 w
= self
->pre_max_area
.width
;
2549 RECT_SET(self
->pre_max_area
, 0, self
->pre_max_area
.y
,
2550 0, self
->pre_max_area
.height
);
2552 /* pick some fallbacks... */
2553 x
= a
->x
+ a
->width
/ 4;
2557 if ((dir
== 0 || dir
== 2) && self
->max_vert
) { /* vert */
2558 if (self
->pre_max_area
.height
> 0) {
2559 y
= self
->pre_max_area
.y
;
2560 h
= self
->pre_max_area
.height
;
2562 RECT_SET(self
->pre_max_area
, self
->pre_max_area
.x
, 0,
2563 self
->pre_max_area
.width
, 0);
2565 /* pick some fallbacks... */
2566 y
= a
->y
+ a
->height
/ 4;
2572 if (dir
== 0 || dir
== 1) /* horz */
2573 self
->max_horz
= max
;
2574 if (dir
== 0 || dir
== 2) /* vert */
2575 self
->max_vert
= max
;
2577 client_change_state(self
); /* change the state hints on the client */
2579 client_setup_decor_and_functions(self
);
2581 client_move_resize(self
, x
, y
, w
, h
);
2584 void client_shade(ObClient
*self
, gboolean shade
)
2586 if ((!(self
->functions
& OB_CLIENT_FUNC_SHADE
) &&
2587 shade
) || /* can't shade */
2588 self
->shaded
== shade
) return; /* already done */
2590 self
->shaded
= shade
;
2591 client_change_state(self
);
2592 client_change_wm_state(self
); /* the window is being hidden/shown */
2593 /* resize the frame to just the titlebar */
2594 frame_adjust_area(self
->frame
, FALSE
, FALSE
, FALSE
);
2597 void client_close(ObClient
*self
)
2601 if (!(self
->functions
& OB_CLIENT_FUNC_CLOSE
)) return;
2603 /* in the case that the client provides no means to requesting that it
2604 close, we just kill it */
2605 if (!self
->delete_window
)
2609 XXX: itd be cool to do timeouts and shit here for killing the client's
2611 like... if the window is around after 5 seconds, then the close button
2612 turns a nice red, and if this function is called again, the client is
2616 ce
.xclient
.type
= ClientMessage
;
2617 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
2618 ce
.xclient
.display
= ob_display
;
2619 ce
.xclient
.window
= self
->window
;
2620 ce
.xclient
.format
= 32;
2621 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_delete_window
;
2622 ce
.xclient
.data
.l
[1] = event_curtime
;
2623 ce
.xclient
.data
.l
[2] = 0l;
2624 ce
.xclient
.data
.l
[3] = 0l;
2625 ce
.xclient
.data
.l
[4] = 0l;
2626 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
2629 void client_kill(ObClient
*self
)
2631 XKillClient(ob_display
, self
->window
);
2634 void client_hilite(ObClient
*self
, gboolean hilite
)
2636 if (self
->demands_attention
== hilite
)
2637 return; /* no change */
2639 /* don't allow focused windows to hilite */
2640 self
->demands_attention
= hilite
&& !client_focused(self
);
2641 if (self
->demands_attention
)
2642 frame_flash_start(self
->frame
);
2644 frame_flash_stop(self
->frame
);
2645 client_change_state(self
);
2648 void client_set_desktop_recursive(ObClient
*self
,
2649 guint target
, gboolean donthide
)
2654 if (target
!= self
->desktop
) {
2656 ob_debug("Setting desktop %u\n", target
+1);
2658 g_assert(target
< screen_num_desktops
|| target
== DESKTOP_ALL
);
2660 /* remove from the old desktop(s) */
2661 focus_order_remove(self
);
2663 old
= self
->desktop
;
2664 self
->desktop
= target
;
2665 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, target
);
2666 /* the frame can display the current desktop state */
2667 frame_adjust_state(self
->frame
);
2668 /* 'move' the window to the new desktop */
2670 client_showhide(self
);
2671 /* raise if it was not already on the desktop */
2672 if (old
!= DESKTOP_ALL
)
2674 if (STRUT_EXISTS(self
->strut
))
2675 screen_update_areas();
2677 /* add to the new desktop(s) */
2678 if (config_focus_new
)
2679 focus_order_to_top(self
);
2681 focus_order_to_bottom(self
);
2684 /* move all transients */
2685 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
2686 if (it
->data
!= self
)
2687 if (client_is_direct_child(self
, it
->data
))
2688 client_set_desktop_recursive(it
->data
, target
, donthide
);
2691 void client_set_desktop(ObClient
*self
, guint target
, gboolean donthide
)
2693 self
= client_search_top_parent(self
);
2694 client_set_desktop_recursive(self
, target
, donthide
);
2697 gboolean
client_is_direct_child(ObClient
*parent
, ObClient
*child
)
2699 while (child
!= parent
&&
2700 child
->transient_for
&& child
->transient_for
!= OB_TRAN_GROUP
)
2701 child
= child
->transient_for
;
2702 return child
== parent
;
2705 ObClient
*client_search_modal_child(ObClient
*self
)
2710 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
2711 ObClient
*c
= it
->data
;
2712 if ((ret
= client_search_modal_child(c
))) return ret
;
2713 if (c
->modal
) return c
;
2718 gboolean
client_validate(ObClient
*self
)
2722 XSync(ob_display
, FALSE
); /* get all events on the server */
2724 if (XCheckTypedWindowEvent(ob_display
, self
->window
, DestroyNotify
, &e
) ||
2725 XCheckTypedWindowEvent(ob_display
, self
->window
, UnmapNotify
, &e
)) {
2726 XPutBackEvent(ob_display
, &e
);
2733 void client_set_wm_state(ObClient
*self
, glong state
)
2735 if (state
== self
->wmstate
) return; /* no change */
2739 client_iconify(self
, TRUE
, TRUE
);
2742 client_iconify(self
, FALSE
, TRUE
);
2747 void client_set_state(ObClient
*self
, Atom action
, glong data1
, glong data2
)
2749 gboolean shaded
= self
->shaded
;
2750 gboolean fullscreen
= self
->fullscreen
;
2751 gboolean undecorated
= self
->undecorated
;
2752 gboolean max_horz
= self
->max_horz
;
2753 gboolean max_vert
= self
->max_vert
;
2754 gboolean modal
= self
->modal
;
2755 gboolean iconic
= self
->iconic
;
2756 gboolean demands_attention
= self
->demands_attention
;
2759 if (!(action
== prop_atoms
.net_wm_state_add
||
2760 action
== prop_atoms
.net_wm_state_remove
||
2761 action
== prop_atoms
.net_wm_state_toggle
))
2762 /* an invalid action was passed to the client message, ignore it */
2765 for (i
= 0; i
< 2; ++i
) {
2766 Atom state
= i
== 0 ? data1
: data2
;
2768 if (!state
) continue;
2770 /* if toggling, then pick whether we're adding or removing */
2771 if (action
== prop_atoms
.net_wm_state_toggle
) {
2772 if (state
== prop_atoms
.net_wm_state_modal
)
2773 action
= modal
? prop_atoms
.net_wm_state_remove
:
2774 prop_atoms
.net_wm_state_add
;
2775 else if (state
== prop_atoms
.net_wm_state_maximized_vert
)
2776 action
= self
->max_vert
? prop_atoms
.net_wm_state_remove
:
2777 prop_atoms
.net_wm_state_add
;
2778 else if (state
== prop_atoms
.net_wm_state_maximized_horz
)
2779 action
= self
->max_horz
? prop_atoms
.net_wm_state_remove
:
2780 prop_atoms
.net_wm_state_add
;
2781 else if (state
== prop_atoms
.net_wm_state_shaded
)
2782 action
= shaded
? prop_atoms
.net_wm_state_remove
:
2783 prop_atoms
.net_wm_state_add
;
2784 else if (state
== prop_atoms
.net_wm_state_skip_taskbar
)
2785 action
= self
->skip_taskbar
?
2786 prop_atoms
.net_wm_state_remove
:
2787 prop_atoms
.net_wm_state_add
;
2788 else if (state
== prop_atoms
.net_wm_state_skip_pager
)
2789 action
= self
->skip_pager
?
2790 prop_atoms
.net_wm_state_remove
:
2791 prop_atoms
.net_wm_state_add
;
2792 else if (state
== prop_atoms
.net_wm_state_hidden
)
2793 action
= self
->iconic
?
2794 prop_atoms
.net_wm_state_remove
:
2795 prop_atoms
.net_wm_state_add
;
2796 else if (state
== prop_atoms
.net_wm_state_fullscreen
)
2797 action
= fullscreen
?
2798 prop_atoms
.net_wm_state_remove
:
2799 prop_atoms
.net_wm_state_add
;
2800 else if (state
== prop_atoms
.net_wm_state_above
)
2801 action
= self
->above
? prop_atoms
.net_wm_state_remove
:
2802 prop_atoms
.net_wm_state_add
;
2803 else if (state
== prop_atoms
.net_wm_state_below
)
2804 action
= self
->below
? prop_atoms
.net_wm_state_remove
:
2805 prop_atoms
.net_wm_state_add
;
2806 else if (state
== prop_atoms
.net_wm_state_demands_attention
)
2807 action
= self
->demands_attention
?
2808 prop_atoms
.net_wm_state_remove
:
2809 prop_atoms
.net_wm_state_add
;
2810 else if (state
== prop_atoms
.ob_wm_state_undecorated
)
2811 action
= undecorated
? prop_atoms
.net_wm_state_remove
:
2812 prop_atoms
.net_wm_state_add
;
2815 if (action
== prop_atoms
.net_wm_state_add
) {
2816 if (state
== prop_atoms
.net_wm_state_modal
) {
2818 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
2820 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
2822 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
2824 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
2825 self
->skip_taskbar
= TRUE
;
2826 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
2827 self
->skip_pager
= TRUE
;
2828 } else if (state
== prop_atoms
.net_wm_state_hidden
) {
2830 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
2832 } else if (state
== prop_atoms
.net_wm_state_above
) {
2834 self
->below
= FALSE
;
2835 } else if (state
== prop_atoms
.net_wm_state_below
) {
2836 self
->above
= FALSE
;
2838 } else if (state
== prop_atoms
.net_wm_state_demands_attention
) {
2839 demands_attention
= TRUE
;
2840 } else if (state
== prop_atoms
.ob_wm_state_undecorated
) {
2844 } else { /* action == prop_atoms.net_wm_state_remove */
2845 if (state
== prop_atoms
.net_wm_state_modal
) {
2847 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
2849 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
2851 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
2853 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
2854 self
->skip_taskbar
= FALSE
;
2855 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
2856 self
->skip_pager
= FALSE
;
2857 } else if (state
== prop_atoms
.net_wm_state_hidden
) {
2859 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
2861 } else if (state
== prop_atoms
.net_wm_state_above
) {
2862 self
->above
= FALSE
;
2863 } else if (state
== prop_atoms
.net_wm_state_below
) {
2864 self
->below
= FALSE
;
2865 } else if (state
== prop_atoms
.net_wm_state_demands_attention
) {
2866 demands_attention
= FALSE
;
2867 } else if (state
== prop_atoms
.ob_wm_state_undecorated
) {
2868 undecorated
= FALSE
;
2872 if (max_horz
!= self
->max_horz
|| max_vert
!= self
->max_vert
) {
2873 if (max_horz
!= self
->max_horz
&& max_vert
!= self
->max_vert
) {
2875 if (max_horz
== max_vert
) { /* both going the same way */
2876 client_maximize(self
, max_horz
, 0);
2878 client_maximize(self
, max_horz
, 1);
2879 client_maximize(self
, max_vert
, 2);
2883 if (max_horz
!= self
->max_horz
)
2884 client_maximize(self
, max_horz
, 1);
2886 client_maximize(self
, max_vert
, 2);
2889 /* change fullscreen state before shading, as it will affect if the window
2891 if (fullscreen
!= self
->fullscreen
)
2892 client_fullscreen(self
, fullscreen
);
2893 if (shaded
!= self
->shaded
)
2894 client_shade(self
, shaded
);
2895 if (undecorated
!= self
->undecorated
)
2896 client_set_undecorated(self
, undecorated
);
2897 if (modal
!= self
->modal
) {
2898 self
->modal
= modal
;
2899 /* when a window changes modality, then its stacking order with its
2900 transients needs to change */
2903 if (iconic
!= self
->iconic
)
2904 client_iconify(self
, iconic
, FALSE
);
2906 if (demands_attention
!= self
->demands_attention
)
2907 client_hilite(self
, demands_attention
);
2909 client_change_state(self
); /* change the hint to reflect these changes */
2912 ObClient
*client_focus_target(ObClient
*self
)
2914 ObClient
*child
= NULL
;
2916 child
= client_search_modal_child(self
);
2917 if (child
) return child
;
2921 gboolean
client_can_focus(ObClient
*self
)
2925 /* choose the correct target */
2926 self
= client_focus_target(self
);
2928 if (!self
->frame
->visible
)
2931 if (!(self
->can_focus
|| self
->focus_notify
))
2934 /* do a check to see if the window has already been unmapped or destroyed
2935 do this intelligently while watching out for unmaps we've generated
2936 (ignore_unmaps > 0) */
2937 if (XCheckTypedWindowEvent(ob_display
, self
->window
,
2938 DestroyNotify
, &ev
)) {
2939 XPutBackEvent(ob_display
, &ev
);
2942 while (XCheckTypedWindowEvent(ob_display
, self
->window
,
2943 UnmapNotify
, &ev
)) {
2944 if (self
->ignore_unmaps
) {
2945 self
->ignore_unmaps
--;
2947 XPutBackEvent(ob_display
, &ev
);
2955 gboolean
client_focus(ObClient
*self
)
2957 /* choose the correct target */
2958 self
= client_focus_target(self
);
2961 if (!client_validate(self
))
2965 if (!client_can_focus(self
)) {
2966 if (!self
->frame
->visible
) {
2967 /* update the focus lists */
2968 focus_order_to_top(self
);
2973 ob_debug("Focusing client \"%s\" at time %u\n", self
->title
, event_curtime
);
2975 if (self
->can_focus
) {
2976 XSetInputFocus(ob_display
, self
->window
, RevertToPointerRoot
,
2980 if (self
->focus_notify
) {
2982 ce
.xclient
.type
= ClientMessage
;
2983 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
2984 ce
.xclient
.display
= ob_display
;
2985 ce
.xclient
.window
= self
->window
;
2986 ce
.xclient
.format
= 32;
2987 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_take_focus
;
2988 ce
.xclient
.data
.l
[1] = event_curtime
;
2989 ce
.xclient
.data
.l
[2] = 0l;
2990 ce
.xclient
.data
.l
[3] = 0l;
2991 ce
.xclient
.data
.l
[4] = 0l;
2992 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
2996 ob_debug("%sively focusing %lx at %d\n",
2997 (self
->can_focus
? "act" : "pass"),
2998 self
->window
, (gint
) event_curtime
);
3001 /* Cause the FocusIn to come back to us. Important for desktop switches,
3002 since otherwise we'll have no FocusIn on the queue and send it off to
3003 the focus_backup. */
3004 XSync(ob_display
, FALSE
);
3008 /* Used when the current client is closed or otherwise hidden, focus_last will
3009 then prevent focus from going to the mouse pointer
3011 static void client_unfocus(ObClient
*self
)
3013 if (focus_client
== self
) {
3015 ob_debug("client_unfocus for %lx\n", self
->window
);
3017 focus_fallback(FALSE
);
3021 void client_activate(ObClient
*self
, gboolean here
, gboolean user
)
3023 /* XXX do some stuff here if user is false to determine if we really want
3024 to activate it or not (a parent or group member is currently
3027 ob_debug("Want to activate window 0x%x with time %u (last time %u), "
3029 self
->window
, event_curtime
, client_last_user_time
,
3030 (user
? "user" : "application"));
3031 if (!user
&& event_curtime
&& event_curtime
< client_last_user_time
)
3032 client_hilite(self
, TRUE
);
3034 if (client_normal(self
) && screen_showing_desktop
)
3035 screen_show_desktop(FALSE
);
3037 client_iconify(self
, FALSE
, here
);
3038 if (self
->desktop
!= DESKTOP_ALL
&&
3039 self
->desktop
!= screen_desktop
) {
3041 client_set_desktop(self
, screen_desktop
, FALSE
);
3043 screen_set_desktop(self
->desktop
);
3044 } else if (!self
->frame
->visible
)
3045 /* if its not visible for other reasons, then don't mess
3049 client_shade(self
, FALSE
);
3053 /* we do this an action here. this is rather important. this is because
3054 we want the results from the focus change to take place BEFORE we go
3055 about raising the window. when a fullscreen window loses focus, we
3056 need this or else the raise wont be able to raise above the
3057 to-lose-focus fullscreen window. */
3062 void client_raise(ObClient
*self
)
3064 action_run_string("Raise", self
, CurrentTime
);
3067 void client_lower(ObClient
*self
)
3069 action_run_string("Lower", self
, CurrentTime
);
3072 gboolean
client_focused(ObClient
*self
)
3074 return self
== focus_client
;
3077 static ObClientIcon
* client_icon_recursive(ObClient
*self
, gint w
, gint h
)
3080 /* si is the smallest image >= req */
3081 /* li is the largest image < req */
3082 gulong size
, smallest
= 0xffffffff, largest
= 0, si
= 0, li
= 0;
3084 if (!self
->nicons
) {
3085 ObClientIcon
*parent
= NULL
;
3087 if (self
->transient_for
) {
3088 if (self
->transient_for
!= OB_TRAN_GROUP
)
3089 parent
= client_icon_recursive(self
->transient_for
, w
, h
);
3092 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
3093 ObClient
*c
= it
->data
;
3094 if (c
!= self
&& !c
->transient_for
) {
3095 if ((parent
= client_icon_recursive(c
, w
, h
)))
3105 for (i
= 0; i
< self
->nicons
; ++i
) {
3106 size
= self
->icons
[i
].width
* self
->icons
[i
].height
;
3107 if (size
< smallest
&& size
>= (unsigned)(w
* h
)) {
3111 if (size
> largest
&& size
<= (unsigned)(w
* h
)) {
3116 if (largest
== 0) /* didnt find one smaller than the requested size */
3117 return &self
->icons
[si
];
3118 return &self
->icons
[li
];
3121 const ObClientIcon
* client_icon(ObClient
*self
, gint w
, gint h
)
3124 static ObClientIcon deficon
;
3126 if (!(ret
= client_icon_recursive(self
, w
, h
))) {
3127 deficon
.width
= deficon
.height
= 48;
3128 deficon
.data
= ob_rr_theme
->def_win_icon
;
3134 /* this be mostly ripped from fvwm */
3135 ObClient
*client_find_directional(ObClient
*c
, ObDirection dir
)
3137 gint my_cx
, my_cy
, his_cx
, his_cy
;
3140 gint score
, best_score
;
3141 ObClient
*best_client
, *cur
;
3147 /* first, find the centre coords of the currently focused window */
3148 my_cx
= c
->frame
->area
.x
+ c
->frame
->area
.width
/ 2;
3149 my_cy
= c
->frame
->area
.y
+ c
->frame
->area
.height
/ 2;
3154 for(it
= g_list_first(client_list
); it
; it
= g_list_next(it
)) {
3157 /* the currently selected window isn't interesting */
3160 if (!client_normal(cur
))
3162 /* using c->desktop instead of screen_desktop doesn't work if the
3163 * current window was omnipresent, hope this doesn't have any other
3165 if(screen_desktop
!= cur
->desktop
&& cur
->desktop
!= DESKTOP_ALL
)
3169 if(!(client_focus_target(cur
) == cur
&&
3170 client_can_focus(cur
)))
3173 /* find the centre coords of this window, from the
3174 * currently focused window's point of view */
3175 his_cx
= (cur
->frame
->area
.x
- my_cx
)
3176 + cur
->frame
->area
.width
/ 2;
3177 his_cy
= (cur
->frame
->area
.y
- my_cy
)
3178 + cur
->frame
->area
.height
/ 2;
3180 if(dir
== OB_DIRECTION_NORTHEAST
|| dir
== OB_DIRECTION_SOUTHEAST
||
3181 dir
== OB_DIRECTION_SOUTHWEST
|| dir
== OB_DIRECTION_NORTHWEST
) {
3183 /* Rotate the diagonals 45 degrees counterclockwise.
3184 * To do this, multiply the matrix /+h +h\ with the
3185 * vector (x y). \-h +h/
3186 * h = sqrt(0.5). We can set h := 1 since absolute
3187 * distance doesn't matter here. */
3188 tx
= his_cx
+ his_cy
;
3189 his_cy
= -his_cx
+ his_cy
;
3194 case OB_DIRECTION_NORTH
:
3195 case OB_DIRECTION_SOUTH
:
3196 case OB_DIRECTION_NORTHEAST
:
3197 case OB_DIRECTION_SOUTHWEST
:
3198 offset
= (his_cx
< 0) ? -his_cx
: his_cx
;
3199 distance
= ((dir
== OB_DIRECTION_NORTH
||
3200 dir
== OB_DIRECTION_NORTHEAST
) ?
3203 case OB_DIRECTION_EAST
:
3204 case OB_DIRECTION_WEST
:
3205 case OB_DIRECTION_SOUTHEAST
:
3206 case OB_DIRECTION_NORTHWEST
:
3207 offset
= (his_cy
< 0) ? -his_cy
: his_cy
;
3208 distance
= ((dir
== OB_DIRECTION_WEST
||
3209 dir
== OB_DIRECTION_NORTHWEST
) ?
3214 /* the target must be in the requested direction */
3218 /* Calculate score for this window. The smaller the better. */
3219 score
= distance
+ offset
;
3221 /* windows more than 45 degrees off the direction are
3222 * heavily penalized and will only be chosen if nothing
3223 * else within a million pixels */
3224 if(offset
> distance
)
3227 if(best_score
== -1 || score
< best_score
)
3235 void client_set_layer(ObClient
*self
, gint layer
)
3239 self
->above
= FALSE
;
3240 } else if (layer
== 0) {
3241 self
->below
= self
->above
= FALSE
;
3243 self
->below
= FALSE
;
3246 client_calc_layer(self
);
3247 client_change_state(self
); /* reflect this in the state hints */
3250 void client_set_undecorated(ObClient
*self
, gboolean undecorated
)
3252 if (self
->undecorated
!= undecorated
) {
3253 self
->undecorated
= undecorated
;
3254 client_setup_decor_and_functions(self
);
3255 /* Make sure the client knows it might have moved. Maybe there is a
3256 * better way of doing this so only one client_configure is sent, but
3257 * since 125 of these are sent per second when moving the window (with
3258 * user = FALSE) i doubt it matters much.
3260 client_configure(self
, OB_CORNER_TOPLEFT
, self
->area
.x
, self
->area
.y
,
3261 self
->area
.width
, self
->area
.height
, TRUE
, TRUE
);
3262 client_change_state(self
); /* reflect this in the state hints */
3266 guint
client_monitor(ObClient
*self
)
3268 return screen_find_monitor(&self
->frame
->area
);
3271 ObClient
*client_search_top_parent(ObClient
*self
)
3273 while (self
->transient_for
&& self
->transient_for
!= OB_TRAN_GROUP
)
3274 self
= self
->transient_for
;
3278 GSList
*client_search_all_top_parents(ObClient
*self
)
3282 /* move up the direct transient chain as far as possible */
3283 while (self
->transient_for
&& self
->transient_for
!= OB_TRAN_GROUP
)
3284 self
= self
->transient_for
;
3286 if (!self
->transient_for
)
3287 ret
= g_slist_prepend(ret
, self
);
3291 g_assert(self
->group
);
3293 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
3294 ObClient
*c
= it
->data
;
3296 if (!c
->transient_for
)
3297 ret
= g_slist_prepend(ret
, c
);
3300 if (ret
== NULL
) /* no group parents */
3301 ret
= g_slist_prepend(ret
, self
);
3307 ObClient
*client_search_focus_parent(ObClient
*self
)
3309 if (self
->transient_for
) {
3310 if (self
->transient_for
!= OB_TRAN_GROUP
) {
3311 if (client_focused(self
->transient_for
))
3312 return self
->transient_for
;
3316 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
3317 ObClient
*c
= it
->data
;
3319 /* checking transient_for prevents infinate loops! */
3320 if (c
!= self
&& !c
->transient_for
)
3321 if (client_focused(c
))
3330 ObClient
*client_search_parent(ObClient
*self
, ObClient
*search
)
3332 if (self
->transient_for
) {
3333 if (self
->transient_for
!= OB_TRAN_GROUP
) {
3334 if (self
->transient_for
== search
)
3339 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
3340 ObClient
*c
= it
->data
;
3342 /* checking transient_for prevents infinate loops! */
3343 if (c
!= self
&& !c
->transient_for
)
3353 ObClient
*client_search_transient(ObClient
*self
, ObClient
*search
)
3357 for (sit
= self
->transients
; sit
; sit
= g_slist_next(sit
)) {
3358 if (sit
->data
== search
)
3360 if (client_search_transient(sit
->data
, search
))
3366 void client_update_sm_client_id(ObClient
*self
)
3368 g_free(self
->sm_client_id
);
3369 self
->sm_client_id
= NULL
;
3371 if (!PROP_GETS(self
->window
, sm_client_id
, locale
, &self
->sm_client_id
) &&
3373 PROP_GETS(self
->group
->leader
, sm_client_id
, locale
,
3374 &self
->sm_client_id
);
3377 #define WANT_EDGE(cur, c) \
3380 if(!client_normal(cur)) \
3382 if(screen_desktop != cur->desktop && cur->desktop != DESKTOP_ALL) \
3386 if(cur->layer < c->layer && !config_resist_layers_below) \
3389 #define HIT_EDGE(my_edge_start, my_edge_end, his_edge_start, his_edge_end) \
3390 if ((his_edge_start >= my_edge_start && \
3391 his_edge_start <= my_edge_end) || \
3392 (my_edge_start >= his_edge_start && \
3393 my_edge_start <= his_edge_end)) \
3396 /* finds the nearest edge in the given direction from the current client
3397 * note to self: the edge is the -frame- edge (the actual one), not the
3400 gint
client_directional_edge_search(ObClient
*c
, ObDirection dir
, gboolean hang
)
3402 gint dest
, monitor_dest
;
3403 gint my_edge_start
, my_edge_end
, my_offset
;
3410 a
= screen_area(c
->desktop
);
3411 monitor
= screen_area_monitor(c
->desktop
, client_monitor(c
));
3414 case OB_DIRECTION_NORTH
:
3415 my_edge_start
= c
->frame
->area
.x
;
3416 my_edge_end
= c
->frame
->area
.x
+ c
->frame
->area
.width
;
3417 my_offset
= c
->frame
->area
.y
+ (hang
? c
->frame
->area
.height
: 0);
3419 /* default: top of screen */
3420 dest
= a
->y
+ (hang
? c
->frame
->area
.height
: 0);
3421 monitor_dest
= monitor
->y
+ (hang
? c
->frame
->area
.height
: 0);
3422 /* if the monitor edge comes before the screen edge, */
3423 /* use that as the destination instead. (For xinerama) */
3424 if (monitor_dest
!= dest
&& my_offset
> monitor_dest
)
3425 dest
= monitor_dest
;
3427 for(it
= client_list
; it
&& my_offset
!= dest
; it
= g_list_next(it
)) {
3428 gint his_edge_start
, his_edge_end
, his_offset
;
3429 ObClient
*cur
= it
->data
;
3433 his_edge_start
= cur
->frame
->area
.x
;
3434 his_edge_end
= cur
->frame
->area
.x
+ cur
->frame
->area
.width
;
3435 his_offset
= cur
->frame
->area
.y
+
3436 (hang
? 0 : cur
->frame
->area
.height
);
3438 if(his_offset
+ 1 > my_offset
)
3441 if(his_offset
< dest
)
3444 HIT_EDGE(my_edge_start
, my_edge_end
, his_edge_start
, his_edge_end
)
3447 case OB_DIRECTION_SOUTH
:
3448 my_edge_start
= c
->frame
->area
.x
;
3449 my_edge_end
= c
->frame
->area
.x
+ c
->frame
->area
.width
;
3450 my_offset
= c
->frame
->area
.y
+ (hang
? 0 : c
->frame
->area
.height
);
3452 /* default: bottom of screen */
3453 dest
= a
->y
+ a
->height
- (hang
? c
->frame
->area
.height
: 0);
3454 monitor_dest
= monitor
->y
+ monitor
->height
-
3455 (hang
? c
->frame
->area
.height
: 0);
3456 /* if the monitor edge comes before the screen edge, */
3457 /* use that as the destination instead. (For xinerama) */
3458 if (monitor_dest
!= dest
&& my_offset
< monitor_dest
)
3459 dest
= monitor_dest
;
3461 for(it
= client_list
; it
&& my_offset
!= dest
; it
= g_list_next(it
)) {
3462 gint his_edge_start
, his_edge_end
, his_offset
;
3463 ObClient
*cur
= it
->data
;
3467 his_edge_start
= cur
->frame
->area
.x
;
3468 his_edge_end
= cur
->frame
->area
.x
+ cur
->frame
->area
.width
;
3469 his_offset
= cur
->frame
->area
.y
+
3470 (hang
? cur
->frame
->area
.height
: 0);
3473 if(his_offset
- 1 < my_offset
)
3476 if(his_offset
> dest
)
3479 HIT_EDGE(my_edge_start
, my_edge_end
, his_edge_start
, his_edge_end
)
3482 case OB_DIRECTION_WEST
:
3483 my_edge_start
= c
->frame
->area
.y
;
3484 my_edge_end
= c
->frame
->area
.y
+ c
->frame
->area
.height
;
3485 my_offset
= c
->frame
->area
.x
+ (hang
? c
->frame
->area
.width
: 0);
3487 /* default: leftmost egde of screen */
3488 dest
= a
->x
+ (hang
? c
->frame
->area
.width
: 0);
3489 monitor_dest
= monitor
->x
+ (hang
? c
->frame
->area
.width
: 0);
3490 /* if the monitor edge comes before the screen edge, */
3491 /* use that as the destination instead. (For xinerama) */
3492 if (monitor_dest
!= dest
&& my_offset
> monitor_dest
)
3493 dest
= monitor_dest
;
3495 for(it
= client_list
; it
&& my_offset
!= dest
; it
= g_list_next(it
)) {
3496 gint his_edge_start
, his_edge_end
, his_offset
;
3497 ObClient
*cur
= it
->data
;
3501 his_edge_start
= cur
->frame
->area
.y
;
3502 his_edge_end
= cur
->frame
->area
.y
+ cur
->frame
->area
.height
;
3503 his_offset
= cur
->frame
->area
.x
+
3504 (hang
? 0 : cur
->frame
->area
.width
);
3506 if(his_offset
+ 1 > my_offset
)
3509 if(his_offset
< dest
)
3512 HIT_EDGE(my_edge_start
, my_edge_end
, his_edge_start
, his_edge_end
)
3515 case OB_DIRECTION_EAST
:
3516 my_edge_start
= c
->frame
->area
.y
;
3517 my_edge_end
= c
->frame
->area
.y
+ c
->frame
->area
.height
;
3518 my_offset
= c
->frame
->area
.x
+ (hang
? 0 : c
->frame
->area
.width
);
3520 /* default: rightmost edge of screen */
3521 dest
= a
->x
+ a
->width
- (hang
? c
->frame
->area
.width
: 0);
3522 monitor_dest
= monitor
->x
+ monitor
->width
-
3523 (hang
? c
->frame
->area
.width
: 0);
3524 /* if the monitor edge comes before the screen edge, */
3525 /* use that as the destination instead. (For xinerama) */
3526 if (monitor_dest
!= dest
&& my_offset
< monitor_dest
)
3527 dest
= monitor_dest
;
3529 for(it
= client_list
; it
&& my_offset
!= dest
; it
= g_list_next(it
)) {
3530 gint his_edge_start
, his_edge_end
, his_offset
;
3531 ObClient
*cur
= it
->data
;
3535 his_edge_start
= cur
->frame
->area
.y
;
3536 his_edge_end
= cur
->frame
->area
.y
+ cur
->frame
->area
.height
;
3537 his_offset
= cur
->frame
->area
.x
+
3538 (hang
? cur
->frame
->area
.width
: 0);
3540 if(his_offset
- 1 < my_offset
)
3543 if(his_offset
> dest
)
3546 HIT_EDGE(my_edge_start
, my_edge_end
, his_edge_start
, his_edge_end
)
3549 case OB_DIRECTION_NORTHEAST
:
3550 case OB_DIRECTION_SOUTHEAST
:
3551 case OB_DIRECTION_NORTHWEST
:
3552 case OB_DIRECTION_SOUTHWEST
:
3553 /* not implemented */
3555 g_assert_not_reached();
3556 dest
= 0; /* suppress warning */
3561 ObClient
* client_under_pointer()
3565 ObClient
*ret
= NULL
;
3567 if (screen_pointer_pos(&x
, &y
)) {
3568 for (it
= stacking_list
; it
; it
= g_list_next(it
)) {
3569 if (WINDOW_IS_CLIENT(it
->data
)) {
3570 ObClient
*c
= WINDOW_AS_CLIENT(it
->data
);
3571 if (c
->frame
->visible
&&
3572 RECT_CONTAINS(c
->frame
->area
, x
, y
)) {
3582 gboolean
client_has_group_siblings(ObClient
*self
)
3584 return self
->group
&& self
->group
->members
->next
;