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"
49 #include <X11/Xutil.h>
51 /*! The event mask to grab on client windows */
52 #define CLIENT_EVENTMASK (PropertyChangeMask | StructureNotifyMask | \
55 #define CLIENT_NOPROPAGATEMASK (ButtonPressMask | ButtonReleaseMask | \
60 ObClientDestructor func
;
64 GList
*client_list
= NULL
;
66 static GSList
*client_destructors
= NULL
;
68 static void client_get_all(ObClient
*self
);
69 static void client_toggle_border(ObClient
*self
, gboolean show
);
70 static void client_get_startup_id(ObClient
*self
);
71 static void client_get_area(ObClient
*self
);
72 static void client_get_desktop(ObClient
*self
);
73 static void client_get_state(ObClient
*self
);
74 static void client_get_layer(ObClient
*self
);
75 static void client_get_shaped(ObClient
*self
);
76 static void client_get_mwm_hints(ObClient
*self
);
77 static void client_get_gravity(ObClient
*self
);
78 static void client_get_client_machine(ObClient
*self
);
79 static void client_get_colormap(ObClient
*self
);
80 static void client_change_allowed_actions(ObClient
*self
);
81 static void client_change_state(ObClient
*self
);
82 static void client_change_wm_state(ObClient
*self
);
83 static void client_apply_startup_state(ObClient
*self
, gint x
, gint y
);
84 static void client_restore_session_state(ObClient
*self
);
85 static void client_restore_session_stacking(ObClient
*self
);
86 static ObAppSettings
*client_get_settings_state(ObClient
*self
);
88 void client_startup(gboolean reconfig
)
95 void client_shutdown(gboolean reconfig
)
99 void client_add_destructor(ObClientDestructor func
, gpointer data
)
101 Destructor
*d
= g_new(Destructor
, 1);
104 client_destructors
= g_slist_prepend(client_destructors
, d
);
107 void client_remove_destructor(ObClientDestructor func
)
111 for (it
= client_destructors
; it
; it
= g_slist_next(it
)) {
112 Destructor
*d
= it
->data
;
113 if (d
->func
== func
) {
115 client_destructors
= g_slist_delete_link(client_destructors
, it
);
121 void client_set_list()
123 Window
*windows
, *win_it
;
125 guint size
= g_list_length(client_list
);
127 /* create an array of the window ids */
129 windows
= g_new(Window
, size
);
131 for (it
= client_list
; it
; it
= g_list_next(it
), ++win_it
)
132 *win_it
= ((ObClient
*)it
->data
)->window
;
136 PROP_SETA32(RootWindow(ob_display
, ob_screen
),
137 net_client_list
, window
, (gulong
*)windows
, size
);
146 void client_foreach_transient(ObClient *self, ObClientForeachFunc func, gpointer data)
150 for (it = self->transients; it; it = g_slist_next(it)) {
151 if (!func(it->data, data)) return;
152 client_foreach_transient(it->data, func, data);
156 void client_foreach_ancestor(ObClient *self, ObClientForeachFunc func, gpointer data)
158 if (self->transient_for) {
159 if (self->transient_for != OB_TRAN_GROUP) {
160 if (!func(self->transient_for, data)) return;
161 client_foreach_ancestor(self->transient_for, func, data);
165 for (it = self->group->members; it; it = g_slist_next(it))
166 if (it->data != self &&
167 !((ObClient*)it->data)->transient_for) {
168 if (!func(it->data, data)) return;
169 client_foreach_ancestor(it->data, func, data);
176 void client_manage_all()
181 XWindowAttributes attrib
;
183 XQueryTree(ob_display
, RootWindow(ob_display
, ob_screen
),
184 &w
, &w
, &children
, &nchild
);
186 /* remove all icon windows from the list */
187 for (i
= 0; i
< nchild
; i
++) {
188 if (children
[i
] == None
) continue;
189 wmhints
= XGetWMHints(ob_display
, children
[i
]);
191 if ((wmhints
->flags
& IconWindowHint
) &&
192 (wmhints
->icon_window
!= children
[i
]))
193 for (j
= 0; j
< nchild
; j
++)
194 if (children
[j
] == wmhints
->icon_window
) {
202 for (i
= 0; i
< nchild
; ++i
) {
203 if (children
[i
] == None
)
205 if (XGetWindowAttributes(ob_display
, children
[i
], &attrib
)) {
206 if (attrib
.override_redirect
) continue;
208 if (attrib
.map_state
!= IsUnmapped
)
209 client_manage(children
[i
]);
215 void client_manage(Window window
)
219 XWindowAttributes attrib
;
220 XSetWindowAttributes attrib_set
;
222 gboolean activate
= FALSE
;
223 ObAppSettings
*settings
;
228 /* check if it has already been unmapped by the time we started mapping.
229 the grab does a sync so we don't have to here */
230 if (XCheckTypedWindowEvent(ob_display
, window
, DestroyNotify
, &e
) ||
231 XCheckTypedWindowEvent(ob_display
, window
, UnmapNotify
, &e
))
233 XPutBackEvent(ob_display
, &e
);
235 ob_debug("Trying to manage unmapped window. Aborting that.\n");
237 return; /* don't manage it */
240 /* make sure it isn't an override-redirect window */
241 if (!XGetWindowAttributes(ob_display
, window
, &attrib
) ||
242 attrib
.override_redirect
)
245 return; /* don't manage it */
248 /* is the window a docking app */
249 if ((wmhint
= XGetWMHints(ob_display
, window
))) {
250 if ((wmhint
->flags
& StateHint
) &&
251 wmhint
->initial_state
== WithdrawnState
)
253 dock_add(window
, wmhint
);
261 ob_debug("Managing window: %lx\n", window
);
263 /* choose the events we want to receive on the CLIENT window */
264 attrib_set
.event_mask
= CLIENT_EVENTMASK
;
265 attrib_set
.do_not_propagate_mask
= CLIENT_NOPROPAGATEMASK
;
266 XChangeWindowAttributes(ob_display
, window
,
267 CWEventMask
|CWDontPropagate
, &attrib_set
);
270 /* create the ObClient struct, and populate it from the hints on the
272 self
= g_new0(ObClient
, 1);
273 self
->obwin
.type
= Window_Client
;
274 self
->window
= window
;
276 /* non-zero defaults */
277 self
->wmstate
= WithdrawnState
; /* make sure it gets updated first time */
279 self
->desktop
= screen_num_desktops
; /* always an invalid value */
280 self
->user_time
= CurrentTime
;
282 client_get_all(self
);
283 /* per-app settings override stuff, and return the settings for other
285 settings
= client_get_settings_state(self
);
286 /* the session should get the last say */
287 client_restore_session_state(self
);
289 client_calc_layer(self
);
292 Time t
= sn_app_started(self
->startup_id
, self
->class);
293 if (t
) self
->user_time
= t
;
296 /* update the focus lists, do this before the call to change_state or
297 it can end up in the list twice! */
298 focus_order_add_new(self
);
300 /* remove the client's border (and adjust re gravity) */
301 client_toggle_border(self
, FALSE
);
303 /* specify that if we exit, the window should not be destroyed and should
304 be reparented back to root automatically */
305 XChangeSaveSet(ob_display
, window
, SetModeInsert
);
307 /* create the decoration frame for the client window */
308 self
->frame
= frame_new(self
);
310 frame_grab_client(self
->frame
, self
);
312 /* do this after we have a frame.. it uses the frame to help determine the
313 WM_STATE to apply. */
314 client_change_state(self
);
318 stacking_add_nonintrusive(CLIENT_AS_WINDOW(self
));
319 client_restore_session_stacking(self
);
321 /* focus the new window? */
322 if (ob_state() != OB_STATE_STARTING
&&
323 /* this means focus=true for window is same as config_focus_new=true */
324 ((config_focus_new
|| (settings
&& settings
->focus
== 1)) ||
325 client_search_focus_parent(self
)) &&
326 /* this checks for focus=false for the window */
327 (!settings
|| settings
->focus
!= 0) &&
328 /* note the check against Type_Normal/Dialog, not client_normal(self),
329 which would also include other types. in this case we want more
330 strict rules for focus */
331 (self
->type
== OB_CLIENT_TYPE_NORMAL
||
332 self
->type
== OB_CLIENT_TYPE_DIALOG
))
336 if (self
->desktop
!= screen_desktop
) {
337 /* activate the window */
340 gboolean group_foc
= FALSE
;
345 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
))
347 if (client_focused(it
->data
))
355 (!self
->transient_for
&& (!self
->group
||
356 !self
->group
->members
->next
))) ||
357 client_search_focus_tree_full(self
) ||
359 !client_normal(focus_client
))
361 /* activate the window */
368 /* get the current position */
372 /* figure out placement for the window */
373 if (ob_state() == OB_STATE_RUNNING
) {
376 transient
= place_client(self
, &newx
, &newy
, settings
);
378 /* make sure the window is visible. */
379 client_find_onscreen(self
, &newx
, &newy
,
380 self
->frame
->area
.width
,
381 self
->frame
->area
.height
,
382 /* non-normal clients has less rules, and
383 windows that are being restored from a
384 session do also. we can assume you want
385 it back where you saved it. Clients saying
386 they placed themselves are subjected to
387 harder rules, ones that are placed by
388 place.c or by the user are allowed partially
389 off-screen and on xinerama divides (ie,
390 it is up to the placement routines to avoid
391 the xinerama divides) */
393 (((self
->positioned
& PPosition
) &&
394 !(self
->positioned
& USPosition
)) &&
395 client_normal(self
) &&
399 /* do this after the window is placed, so the premax/prefullscreen numbers
401 also, this moves the window to the position where it has been placed
403 ob_debug("placing window 0x%x at %d, %d with size %d x %d\n",
404 self
->window
, newx
, newy
, self
->area
.width
, self
->area
.height
);
405 client_apply_startup_state(self
, newx
, newy
);
407 keyboard_grab_for_client(self
, TRUE
);
408 mouse_grab_for_client(self
, TRUE
);
411 guint32 last_time
= focus_client
?
412 focus_client
->user_time
: CurrentTime
;
414 /* This is focus stealing prevention */
415 ob_debug("Want to focus new window 0x%x with time %u (last time %u)\n",
416 self
->window
, self
->user_time
, last_time
);
418 /* If a nothing at all, or a parent was focused, then focus this
421 if (!focus_client
|| client_search_focus_parent(self
) != NULL
)
425 /* If time stamp is old, don't steal focus */
426 if (self
->user_time
&& last_time
&&
427 !event_time_after(self
->user_time
, last_time
))
431 /* Don't steal focus from globally active clients.
432 I stole this idea from KWin. It seems nice.
434 if (!(focus_client
->can_focus
|| focus_client
->focus_notify
))
440 /* since focus can change the stacking orders, if we focus the
441 window then the standard raise it gets is not enough, we need
442 to queue one for after the focus change takes place */
445 ob_debug("Focus stealing prevention activated for %s with time %u "
447 self
->title
, self
->user_time
, last_time
);
448 /* if the client isn't focused, then hilite it so the user
450 client_hilite(self
, TRUE
);
454 /* This may look rather odd. Well it's because new windows are added
455 to the stacking order non-intrusively. If we're not going to focus
456 the new window or hilite it, then we raise it to the top. This will
457 take affect for things that don't get focused like splash screens.
458 Also if you don't have focus_new enabled, then it's going to get
459 raised to the top. Legacy begets legacy I guess?
464 /* this has to happen before we try focus the window, but we want it to
465 happen after the client's stacking has been determined or it looks bad
469 /* use client_focus instead of client_activate cuz client_activate does
470 stuff like switch desktops etc and I'm not interested in all that when
471 a window maps since its not based on an action from the user like
472 clicking a window to activate it. so keep the new window out of the way
475 /* if using focus_delay, stop the timer now so that focus doesn't
477 event_halt_focus_delay();
481 /* client_activate does this but we aren't using it so we have to do it
483 if (screen_showing_desktop
)
484 screen_show_desktop(FALSE
);
486 /* add to client list/map */
487 client_list
= g_list_append(client_list
, self
);
488 g_hash_table_insert(window_map
, &self
->window
, self
);
490 /* this has to happen after we're in the client_list */
491 if (STRUT_EXISTS(self
->strut
))
492 screen_update_areas();
494 /* update the list hints */
497 ob_debug("Managed window 0x%lx (%s)\n", window
, self
->class);
500 void client_unmanage_all()
502 while (client_list
!= NULL
)
503 client_unmanage(client_list
->data
);
506 void client_unmanage(ObClient
*self
)
511 ob_debug("Unmanaging window: %lx (%s) (%s)\n", self
->window
, self
->class,
512 self
->title
? self
->title
: "");
514 g_assert(self
!= NULL
);
516 /* we dont want events no more. do this before hiding the frame so we
517 don't generate more events */
518 XSelectInput(ob_display
, self
->window
, NoEventMask
);
520 frame_hide(self
->frame
);
521 /* flush to send the hide to the server quickly */
524 if (focus_client
== self
) {
525 /* ignore enter events from the unmap so it doesnt mess with the focus
527 event_ignore_queued_enters();
530 keyboard_grab_for_client(self
, FALSE
);
531 mouse_grab_for_client(self
, FALSE
);
533 /* remove the window from our save set */
534 XChangeSaveSet(ob_display
, self
->window
, SetModeDelete
);
536 /* update the focus lists */
537 focus_order_remove(self
);
538 /* don't leave an invalid focus_client */
539 if (self
== focus_client
)
542 client_list
= g_list_remove(client_list
, self
);
543 stacking_remove(self
);
544 g_hash_table_remove(window_map
, &self
->window
);
546 /* once the client is out of the list, update the struts to remove its
548 if (STRUT_EXISTS(self
->strut
))
549 screen_update_areas();
551 for (it
= client_destructors
; it
; it
= g_slist_next(it
)) {
552 Destructor
*d
= it
->data
;
553 d
->func(self
, d
->data
);
556 /* tell our parent(s) that we're gone */
557 if (self
->transient_for
== OB_TRAN_GROUP
) { /* transient of group */
558 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
))
559 if (it
->data
!= self
)
560 ((ObClient
*)it
->data
)->transients
=
561 g_slist_remove(((ObClient
*)it
->data
)->transients
, self
);
562 } else if (self
->transient_for
) { /* transient of window */
563 self
->transient_for
->transients
=
564 g_slist_remove(self
->transient_for
->transients
, self
);
567 /* tell our transients that we're gone */
568 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
569 if (((ObClient
*)it
->data
)->transient_for
!= OB_TRAN_GROUP
) {
570 ((ObClient
*)it
->data
)->transient_for
= NULL
;
571 client_calc_layer(it
->data
);
575 /* remove from its group */
577 group_remove(self
->group
, self
);
581 /* restore the window's original geometry so it is not lost */
585 if (self
->fullscreen
)
586 a
= self
->pre_fullscreen_area
;
587 else if (self
->max_horz
|| self
->max_vert
) {
588 if (self
->max_horz
) {
589 a
.x
= self
->pre_max_area
.x
;
590 a
.width
= self
->pre_max_area
.width
;
592 if (self
->max_vert
) {
593 a
.y
= self
->pre_max_area
.y
;
594 a
.height
= self
->pre_max_area
.height
;
598 /* give the client its border back */
599 client_toggle_border(self
, TRUE
);
601 self
->fullscreen
= self
->max_horz
= self
->max_vert
= FALSE
;
602 self
->decorations
= 0; /* unmanaged windows have no decor */
604 client_move_resize(self
, a
.x
, a
.y
, a
.width
, a
.height
);
607 /* reparent the window out of the frame, and free the frame */
608 frame_release_client(self
->frame
, self
);
611 if (ob_state() != OB_STATE_EXITING
) {
612 /* these values should not be persisted across a window
614 PROP_ERASE(self
->window
, net_wm_desktop
);
615 PROP_ERASE(self
->window
, net_wm_state
);
616 PROP_ERASE(self
->window
, wm_state
);
618 /* if we're left in an unmapped state, the client wont be mapped. this
619 is bad, since we will no longer be managing the window on restart */
620 XMapWindow(ob_display
, self
->window
);
623 ob_debug("Unmanaged window 0x%lx\n", self
->window
);
625 /* free all data allocated in the client struct */
626 g_slist_free(self
->transients
);
627 for (j
= 0; j
< self
->nicons
; ++j
)
628 g_free(self
->icons
[j
].data
);
629 if (self
->nicons
> 0)
632 g_free(self
->icon_title
);
636 g_free(self
->client_machine
);
637 g_free(self
->sm_client_id
);
640 /* update the list hints */
644 static ObAppSettings
*client_get_settings_state(ObClient
*self
)
646 ObAppSettings
*settings
= NULL
;
649 for (it
= config_per_app_settings
; it
; it
= g_slist_next(it
)) {
650 ObAppSettings
*app
= it
->data
;
652 if ((app
->name
&& !app
->class && !strcmp(app
->name
, self
->name
))
653 || (app
->class && !app
->name
&& !strcmp(app
->class, self
->class))
654 || (app
->class && app
->name
&& !strcmp(app
->class, self
->class)
655 && !strcmp(app
->name
, self
->name
)))
657 ob_debug("Window matching: %s\n", app
->name
);
658 /* Match if no role was specified in the per app setting, or if the
659 * string matches the beginning of the role, since apps like to set
660 * the role to things like browser-window-23c4b2f */
662 || !strncmp(app
->role
, self
->role
, strlen(app
->role
)))
672 if (settings
->shade
!= -1)
673 self
->shaded
= !!settings
->shade
;
674 if (settings
->decor
!= -1)
675 self
->undecorated
= !settings
->decor
;
676 if (settings
->iconic
!= -1)
677 self
->iconic
= !!settings
->iconic
;
678 if (settings
->skip_pager
!= -1)
679 self
->skip_pager
= !!settings
->skip_pager
;
680 if (settings
->skip_taskbar
!= -1)
681 self
->skip_taskbar
= !!settings
->skip_taskbar
;
683 if (settings
->max_vert
!= -1)
684 self
->max_vert
= !!settings
->max_vert
;
685 if (settings
->max_horz
!= -1)
686 self
->max_horz
= !!settings
->max_horz
;
688 if (settings
->fullscreen
!= -1)
689 self
->fullscreen
= !!settings
->fullscreen
;
691 if (settings
->desktop
< screen_num_desktops
692 || settings
->desktop
== DESKTOP_ALL
)
693 self
->desktop
= settings
->desktop
;
695 if (settings
->layer
== -1) {
699 else if (settings
->layer
== 0) {
703 else if (settings
->layer
== 1) {
711 static void client_restore_session_state(ObClient
*self
)
715 if (!(it
= session_state_find(self
)))
718 self
->session
= it
->data
;
720 RECT_SET_POINT(self
->area
, self
->session
->x
, self
->session
->y
);
721 self
->positioned
= PPosition
;
722 if (self
->session
->w
> 0)
723 self
->area
.width
= self
->session
->w
;
724 if (self
->session
->h
> 0)
725 self
->area
.height
= self
->session
->h
;
726 XResizeWindow(ob_display
, self
->window
,
727 self
->area
.width
, self
->area
.height
);
729 self
->desktop
= (self
->session
->desktop
== DESKTOP_ALL
?
730 self
->session
->desktop
:
731 MIN(screen_num_desktops
- 1, self
->session
->desktop
));
732 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, self
->desktop
);
734 self
->shaded
= self
->session
->shaded
;
735 self
->iconic
= self
->session
->iconic
;
736 self
->skip_pager
= self
->session
->skip_pager
;
737 self
->skip_taskbar
= self
->session
->skip_taskbar
;
738 self
->fullscreen
= self
->session
->fullscreen
;
739 self
->above
= self
->session
->above
;
740 self
->below
= self
->session
->below
;
741 self
->max_horz
= self
->session
->max_horz
;
742 self
->max_vert
= self
->session
->max_vert
;
745 static void client_restore_session_stacking(ObClient
*self
)
749 if (!self
->session
) return;
751 it
= g_list_find(session_saved_state
, self
->session
);
752 for (it
= g_list_previous(it
); it
; it
= g_list_previous(it
)) {
755 for (cit
= client_list
; cit
; cit
= g_list_next(cit
))
756 if (session_state_cmp(it
->data
, cit
->data
))
759 client_calc_layer(self
);
760 stacking_below(CLIENT_AS_WINDOW(self
),
761 CLIENT_AS_WINDOW(cit
->data
));
767 void client_move_onscreen(ObClient
*self
, gboolean rude
)
769 gint x
= self
->area
.x
;
770 gint y
= self
->area
.y
;
771 if (client_find_onscreen(self
, &x
, &y
,
772 self
->frame
->area
.width
,
773 self
->frame
->area
.height
, rude
)) {
774 client_move(self
, x
, y
);
778 gboolean
client_find_onscreen(ObClient
*self
, gint
*x
, gint
*y
, gint w
, gint h
,
782 gint ox
= *x
, oy
= *y
;
784 frame_client_gravity(self
->frame
, x
, y
); /* get where the frame
787 /* XXX watch for xinerama dead areas */
788 /* This makes sure windows aren't entirely outside of the screen so you
789 can't see them at all.
790 It makes sure 10% of the window is on the screen at least. At don't let
791 it move itself off the top of the screen, which would hide the titlebar
792 on you. (The user can still do this if they want too, it's only limiting
795 if (client_normal(self
)) {
796 a
= screen_area(self
->desktop
);
797 if (!self
->strut
.right
&&
798 *x
+ self
->frame
->area
.width
/10 >= a
->x
+ a
->width
- 1)
799 *x
= a
->x
+ a
->width
- self
->frame
->area
.width
/10;
800 if (!self
->strut
.bottom
&&
801 *y
+ self
->frame
->area
.height
/10 >= a
->y
+ a
->height
- 1)
802 *y
= a
->y
+ a
->height
- self
->frame
->area
.height
/10;
803 if (!self
->strut
.left
&& *x
+ self
->frame
->area
.width
*9/10 - 1 < a
->x
)
804 *x
= a
->x
- self
->frame
->area
.width
*9/10;
805 if (!self
->strut
.top
&& *y
+ self
->frame
->area
.height
*9/10 - 1 < a
->y
)
806 *y
= a
->y
- self
->frame
->area
.width
*9/10;
809 /* This here doesn't let windows even a pixel outside the screen,
810 * when called from client_manage, programs placing themselves are
811 * forced completely onscreen, while things like
812 * xterm -geometry resolution-width/2 will work fine. Trying to
813 * place it completely offscreen will be handled in the above code.
814 * Sorry for this confused comment, i am tired. */
816 /* avoid the xinerama monitor divide while we're at it,
817 * remember to fix the placement stuff to avoid it also and
818 * then remove this XXX */
819 a
= screen_area_monitor(self
->desktop
, client_monitor(self
));
820 /* dont let windows map into the strut unless they
821 are bigger than the available area */
823 if (!self
->strut
.left
&& *x
< a
->x
) *x
= a
->x
;
824 if (!self
->strut
.right
&& *x
+ w
> a
->x
+ a
->width
)
825 *x
= a
->x
+ a
->width
- w
;
827 if (h
<= a
->height
) {
828 if (!self
->strut
.top
&& *y
< a
->y
) *y
= a
->y
;
829 if (!self
->strut
.bottom
&& *y
+ h
> a
->y
+ a
->height
)
830 *y
= a
->y
+ a
->height
- h
;
834 frame_frame_gravity(self
->frame
, x
, y
); /* get where the client
837 return ox
!= *x
|| oy
!= *y
;
840 static void client_toggle_border(ObClient
*self
, gboolean show
)
842 /* adjust our idea of where the client is, based on its border. When the
843 border is removed, the client should now be considered to be in a
845 when re-adding the border to the client, the same operation needs to be
847 gint oldx
= self
->area
.x
, oldy
= self
->area
.y
;
848 gint x
= oldx
, y
= oldy
;
849 switch(self
->gravity
) {
851 case NorthWestGravity
:
853 case SouthWestGravity
:
855 case NorthEastGravity
:
857 case SouthEastGravity
:
858 if (show
) x
-= self
->border_width
* 2;
859 else x
+= self
->border_width
* 2;
866 if (show
) x
-= self
->border_width
;
867 else x
+= self
->border_width
;
870 switch(self
->gravity
) {
872 case NorthWestGravity
:
874 case NorthEastGravity
:
876 case SouthWestGravity
:
878 case SouthEastGravity
:
879 if (show
) y
-= self
->border_width
* 2;
880 else y
+= self
->border_width
* 2;
887 if (show
) y
-= self
->border_width
;
888 else y
+= self
->border_width
;
895 XSetWindowBorderWidth(ob_display
, self
->window
, self
->border_width
);
897 /* set border_width to 0 because there is no border to add into
898 calculations anymore */
899 self
->border_width
= 0;
901 XSetWindowBorderWidth(ob_display
, self
->window
, 0);
905 static void client_get_all(ObClient
*self
)
907 client_get_area(self
);
908 client_get_mwm_hints(self
);
910 /* The transient hint is used to pick a type, but the type can also affect
911 transiency (dialogs are always made transients of their group if they
912 have one). This is Havoc's idea, but it is needed to make some apps
913 work right (eg tsclient). */
914 client_update_transient_for(self
);
915 client_get_type(self
);/* this can change the mwmhints for special cases */
916 client_get_state(self
);
917 client_update_transient_for(self
);
919 client_update_wmhints(self
);
920 client_get_startup_id(self
);
921 client_get_desktop(self
);/* uses transient data/group/startup id if a
922 desktop is not specified */
923 client_get_shaped(self
);
925 client_get_layer(self
); /* if layer hasn't been specified, get it from
926 other sources if possible */
929 /* a couple type-based defaults for new windows */
931 /* this makes sure that these windows appear on all desktops */
932 if (self
->type
== OB_CLIENT_TYPE_DESKTOP
)
933 self
->desktop
= DESKTOP_ALL
;
936 client_update_protocols(self
);
938 client_get_gravity(self
); /* get the attribute gravity */
939 client_update_normal_hints(self
); /* this may override the attribute
942 /* got the type, the mwmhints, the protocols, and the normal hints
943 (min/max sizes), so we're ready to set up the decorations/functions */
944 client_setup_decor_and_functions(self
);
947 client_update_sync_request_counter(self
);
949 client_get_client_machine(self
);
950 client_get_colormap(self
);
951 client_update_title(self
);
952 client_update_class(self
);
953 client_update_sm_client_id(self
);
954 client_update_strut(self
);
955 client_update_icons(self
);
956 client_update_user_time(self
);
959 static void client_get_startup_id(ObClient
*self
)
961 if (!(PROP_GETS(self
->window
, net_startup_id
, utf8
, &self
->startup_id
)))
963 PROP_GETS(self
->group
->leader
,
964 net_startup_id
, utf8
, &self
->startup_id
);
967 static void client_get_area(ObClient
*self
)
969 XWindowAttributes wattrib
;
972 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
973 g_assert(ret
!= BadWindow
);
975 RECT_SET(self
->area
, wattrib
.x
, wattrib
.y
, wattrib
.width
, wattrib
.height
);
976 POINT_SET(self
->root_pos
, wattrib
.x
, wattrib
.y
);
977 self
->border_width
= wattrib
.border_width
;
979 ob_debug("client area: %d %d %d %d\n", wattrib
.x
, wattrib
.y
,
980 wattrib
.width
, wattrib
.height
);
983 static void client_get_desktop(ObClient
*self
)
985 guint32 d
= screen_num_desktops
; /* an always-invalid value */
987 if (PROP_GET32(self
->window
, net_wm_desktop
, cardinal
, &d
)) {
988 if (d
>= screen_num_desktops
&& d
!= DESKTOP_ALL
)
989 self
->desktop
= screen_num_desktops
- 1;
993 gboolean trdesk
= FALSE
;
995 if (self
->transient_for
) {
996 if (self
->transient_for
!= OB_TRAN_GROUP
) {
997 self
->desktop
= self
->transient_for
->desktop
;
1002 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
))
1003 if (it
->data
!= self
&&
1004 !((ObClient
*)it
->data
)->transient_for
) {
1005 self
->desktop
= ((ObClient
*)it
->data
)->desktop
;
1012 /* try get from the startup-notification protocol */
1013 if (sn_get_desktop(self
->startup_id
, &self
->desktop
)) {
1014 if (self
->desktop
>= screen_num_desktops
&&
1015 self
->desktop
!= DESKTOP_ALL
)
1016 self
->desktop
= screen_num_desktops
- 1;
1018 /* defaults to the current desktop */
1019 self
->desktop
= screen_desktop
;
1024 static void client_get_layer(ObClient
*self
)
1026 if (!(self
->above
|| self
->below
)) {
1028 /* apply stuff from the group */
1032 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
1033 ObClient
*c
= it
->data
;
1034 if (c
!= self
&& !client_search_transient(self
, c
) &&
1035 client_normal(self
) && client_normal(c
))
1038 (c
->above
? 1 : (c
->below
? -1 : 0)));
1052 g_assert_not_reached();
1059 static void client_get_state(ObClient
*self
)
1064 if (PROP_GETA32(self
->window
, net_wm_state
, atom
, &state
, &num
)) {
1066 for (i
= 0; i
< num
; ++i
) {
1067 if (state
[i
] == prop_atoms
.net_wm_state_modal
)
1069 else if (state
[i
] == prop_atoms
.net_wm_state_shaded
)
1070 self
->shaded
= TRUE
;
1071 else if (state
[i
] == prop_atoms
.net_wm_state_hidden
)
1072 self
->iconic
= TRUE
;
1073 else if (state
[i
] == prop_atoms
.net_wm_state_skip_taskbar
)
1074 self
->skip_taskbar
= TRUE
;
1075 else if (state
[i
] == prop_atoms
.net_wm_state_skip_pager
)
1076 self
->skip_pager
= TRUE
;
1077 else if (state
[i
] == prop_atoms
.net_wm_state_fullscreen
)
1078 self
->fullscreen
= TRUE
;
1079 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_vert
)
1080 self
->max_vert
= TRUE
;
1081 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_horz
)
1082 self
->max_horz
= TRUE
;
1083 else if (state
[i
] == prop_atoms
.net_wm_state_above
)
1085 else if (state
[i
] == prop_atoms
.net_wm_state_below
)
1087 else if (state
[i
] == prop_atoms
.net_wm_state_demands_attention
)
1088 self
->demands_attention
= TRUE
;
1089 else if (state
[i
] == prop_atoms
.ob_wm_state_undecorated
)
1090 self
->undecorated
= TRUE
;
1097 static void client_get_shaped(ObClient
*self
)
1099 self
->shaped
= FALSE
;
1101 if (extensions_shape
) {
1106 XShapeSelectInput(ob_display
, self
->window
, ShapeNotifyMask
);
1108 XShapeQueryExtents(ob_display
, self
->window
, &s
, &foo
,
1109 &foo
, &ufoo
, &ufoo
, &foo
, &foo
, &foo
, &ufoo
,
1111 self
->shaped
= (s
!= 0);
1116 void client_update_transient_for(ObClient
*self
)
1119 ObClient
*target
= NULL
;
1121 if (XGetTransientForHint(ob_display
, self
->window
, &t
)) {
1122 self
->transient
= TRUE
;
1123 if (t
!= self
->window
) { /* cant be transient to itself! */
1124 target
= g_hash_table_lookup(window_map
, &t
);
1125 /* if this happens then we need to check for it*/
1126 g_assert(target
!= self
);
1127 if (target
&& !WINDOW_IS_CLIENT(target
)) {
1128 /* this can happen when a dialog is a child of
1129 a dockapp, for example */
1133 /* THIS IS SO ANNOYING ! ! ! ! Let me explain.... have a seat..
1135 Setting the transient_for to Root is actually illegal, however
1136 applications from time have done this to specify transient for
1139 Now you can do that by being a TYPE_DIALOG and not setting
1140 the transient_for hint at all on your window. But people still
1141 use Root, and Kwin is very strange in this regard.
1143 KWin 3.0 will not consider windows with transient_for set to
1144 Root as transient for their group *UNLESS* they are also modal.
1145 In that case, it will make them transient for the group. This
1146 leads to all sorts of weird behavior from KDE apps which are
1147 only tested in KWin. I'd like to follow their behavior just to
1148 make this work right with KDE stuff, but that seems wrong.
1150 if (!target
&& self
->group
) {
1151 /* not transient to a client, see if it is transient for a
1153 if (t
== RootWindow(ob_display
, ob_screen
)) {
1154 /* window is a transient for its group! */
1155 target
= OB_TRAN_GROUP
;
1159 } else if (self
->group
) {
1160 if (self
->type
== OB_CLIENT_TYPE_DIALOG
||
1161 self
->type
== OB_CLIENT_TYPE_TOOLBAR
||
1162 self
->type
== OB_CLIENT_TYPE_MENU
||
1163 self
->type
== OB_CLIENT_TYPE_UTILITY
)
1165 self
->transient
= TRUE
;
1166 target
= OB_TRAN_GROUP
;
1169 self
->transient
= FALSE
;
1171 /* if anything has changed... */
1172 if (target
!= self
->transient_for
) {
1173 if (self
->transient_for
== OB_TRAN_GROUP
) { /* transient of group */
1176 /* remove from old parents */
1177 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
1178 ObClient
*c
= it
->data
;
1179 if (c
!= self
&& !c
->transient_for
)
1180 c
->transients
= g_slist_remove(c
->transients
, self
);
1182 } else if (self
->transient_for
!= NULL
) { /* transient of window */
1183 /* remove from old parent */
1184 self
->transient_for
->transients
=
1185 g_slist_remove(self
->transient_for
->transients
, self
);
1187 self
->transient_for
= target
;
1188 if (self
->transient_for
== OB_TRAN_GROUP
) { /* transient of group */
1191 /* add to new parents */
1192 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
1193 ObClient
*c
= it
->data
;
1194 if (c
!= self
&& !c
->transient_for
)
1195 c
->transients
= g_slist_append(c
->transients
, self
);
1198 /* remove all transients which are in the group, that causes
1199 circlular pointer hell of doom */
1200 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
1202 for (sit
= self
->transients
; sit
; sit
= next
) {
1203 next
= g_slist_next(sit
);
1204 if (sit
->data
== it
->data
)
1206 g_slist_delete_link(self
->transients
, sit
);
1209 } else if (self
->transient_for
!= NULL
) { /* transient of window */
1210 /* add to new parent */
1211 self
->transient_for
->transients
=
1212 g_slist_append(self
->transient_for
->transients
, self
);
1217 static void client_get_mwm_hints(ObClient
*self
)
1222 self
->mwmhints
.flags
= 0; /* default to none */
1224 if (PROP_GETA32(self
->window
, motif_wm_hints
, motif_wm_hints
,
1226 if (num
>= OB_MWM_ELEMENTS
) {
1227 self
->mwmhints
.flags
= hints
[0];
1228 self
->mwmhints
.functions
= hints
[1];
1229 self
->mwmhints
.decorations
= hints
[2];
1235 void client_get_type(ObClient
*self
)
1242 if (PROP_GETA32(self
->window
, net_wm_window_type
, atom
, &val
, &num
)) {
1243 /* use the first value that we know about in the array */
1244 for (i
= 0; i
< num
; ++i
) {
1245 if (val
[i
] == prop_atoms
.net_wm_window_type_desktop
)
1246 self
->type
= OB_CLIENT_TYPE_DESKTOP
;
1247 else if (val
[i
] == prop_atoms
.net_wm_window_type_dock
)
1248 self
->type
= OB_CLIENT_TYPE_DOCK
;
1249 else if (val
[i
] == prop_atoms
.net_wm_window_type_toolbar
)
1250 self
->type
= OB_CLIENT_TYPE_TOOLBAR
;
1251 else if (val
[i
] == prop_atoms
.net_wm_window_type_menu
)
1252 self
->type
= OB_CLIENT_TYPE_MENU
;
1253 else if (val
[i
] == prop_atoms
.net_wm_window_type_utility
)
1254 self
->type
= OB_CLIENT_TYPE_UTILITY
;
1255 else if (val
[i
] == prop_atoms
.net_wm_window_type_splash
)
1256 self
->type
= OB_CLIENT_TYPE_SPLASH
;
1257 else if (val
[i
] == prop_atoms
.net_wm_window_type_dialog
)
1258 self
->type
= OB_CLIENT_TYPE_DIALOG
;
1259 else if (val
[i
] == prop_atoms
.net_wm_window_type_normal
)
1260 self
->type
= OB_CLIENT_TYPE_NORMAL
;
1261 else if (val
[i
] == prop_atoms
.kde_net_wm_window_type_override
) {
1262 /* prevent this window from getting any decor or
1264 self
->mwmhints
.flags
&= (OB_MWM_FLAG_FUNCTIONS
|
1265 OB_MWM_FLAG_DECORATIONS
);
1266 self
->mwmhints
.decorations
= 0;
1267 self
->mwmhints
.functions
= 0;
1269 if (self
->type
!= (ObClientType
) -1)
1270 break; /* grab the first legit type */
1275 if (self
->type
== (ObClientType
) -1) {
1276 /*the window type hint was not set, which means we either classify
1277 ourself as a normal window or a dialog, depending on if we are a
1279 if (self
->transient
)
1280 self
->type
= OB_CLIENT_TYPE_DIALOG
;
1282 self
->type
= OB_CLIENT_TYPE_NORMAL
;
1286 void client_update_protocols(ObClient
*self
)
1289 guint num_return
, i
;
1291 self
->focus_notify
= FALSE
;
1292 self
->delete_window
= FALSE
;
1294 if (PROP_GETA32(self
->window
, wm_protocols
, atom
, &proto
, &num_return
)) {
1295 for (i
= 0; i
< num_return
; ++i
) {
1296 if (proto
[i
] == prop_atoms
.wm_delete_window
)
1297 /* this means we can request the window to close */
1298 self
->delete_window
= TRUE
;
1299 else if (proto
[i
] == prop_atoms
.wm_take_focus
)
1300 /* if this protocol is requested, then the window will be
1301 notified whenever we want it to receive focus */
1302 self
->focus_notify
= TRUE
;
1304 else if (proto
[i
] == prop_atoms
.net_wm_sync_request
)
1305 /* if this protocol is requested, then resizing the
1306 window will be synchronized between the frame and the
1308 self
->sync_request
= TRUE
;
1316 void client_update_sync_request_counter(ObClient
*self
)
1320 if (PROP_GET32(self
->window
, net_wm_sync_request_counter
, cardinal
, &i
)) {
1321 self
->sync_counter
= i
;
1323 self
->sync_counter
= None
;
1327 static void client_get_gravity(ObClient
*self
)
1329 XWindowAttributes wattrib
;
1332 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
1333 g_assert(ret
!= BadWindow
);
1334 self
->gravity
= wattrib
.win_gravity
;
1337 void client_get_colormap(ObClient
*self
)
1339 XWindowAttributes wa
;
1341 if (XGetWindowAttributes(ob_display
, self
->window
, &wa
))
1342 client_update_colormap(self
, wa
.colormap
);
1345 void client_update_colormap(ObClient
*self
, Colormap colormap
)
1347 self
->colormap
= colormap
;
1350 void client_update_normal_hints(ObClient
*self
)
1354 gint oldgravity
= self
->gravity
;
1357 self
->min_ratio
= 0.0f
;
1358 self
->max_ratio
= 0.0f
;
1359 SIZE_SET(self
->size_inc
, 1, 1);
1360 SIZE_SET(self
->base_size
, 0, 0);
1361 SIZE_SET(self
->min_size
, 0, 0);
1362 SIZE_SET(self
->max_size
, G_MAXINT
, G_MAXINT
);
1364 /* get the hints from the window */
1365 if (XGetWMNormalHints(ob_display
, self
->window
, &size
, &ret
)) {
1366 /* normal windows can't request placement! har har
1367 if (!client_normal(self))
1369 self
->positioned
= (size
.flags
& (PPosition
|USPosition
));
1371 if (size
.flags
& PWinGravity
) {
1372 self
->gravity
= size
.win_gravity
;
1374 /* if the client has a frame, i.e. has already been mapped and
1375 is changing its gravity */
1376 if (self
->frame
&& self
->gravity
!= oldgravity
) {
1377 /* move our idea of the client's position based on its new
1379 self
->area
.x
= self
->frame
->area
.x
;
1380 self
->area
.y
= self
->frame
->area
.y
;
1381 frame_frame_gravity(self
->frame
, &self
->area
.x
, &self
->area
.y
);
1385 if (size
.flags
& PAspect
) {
1386 if (size
.min_aspect
.y
)
1388 (gfloat
) size
.min_aspect
.x
/ size
.min_aspect
.y
;
1389 if (size
.max_aspect
.y
)
1391 (gfloat
) size
.max_aspect
.x
/ size
.max_aspect
.y
;
1394 if (size
.flags
& PMinSize
)
1395 SIZE_SET(self
->min_size
, size
.min_width
, size
.min_height
);
1397 if (size
.flags
& PMaxSize
)
1398 SIZE_SET(self
->max_size
, size
.max_width
, size
.max_height
);
1400 if (size
.flags
& PBaseSize
)
1401 SIZE_SET(self
->base_size
, size
.base_width
, size
.base_height
);
1403 if (size
.flags
& PResizeInc
&& size
.width_inc
&& size
.height_inc
)
1404 SIZE_SET(self
->size_inc
, size
.width_inc
, size
.height_inc
);
1408 void client_setup_decor_and_functions(ObClient
*self
)
1410 /* start with everything (cept fullscreen) */
1412 (OB_FRAME_DECOR_TITLEBAR
|
1413 OB_FRAME_DECOR_HANDLE
|
1414 OB_FRAME_DECOR_GRIPS
|
1415 OB_FRAME_DECOR_BORDER
|
1416 OB_FRAME_DECOR_ICON
|
1417 OB_FRAME_DECOR_ALLDESKTOPS
|
1418 OB_FRAME_DECOR_ICONIFY
|
1419 OB_FRAME_DECOR_MAXIMIZE
|
1420 OB_FRAME_DECOR_SHADE
|
1421 OB_FRAME_DECOR_CLOSE
);
1423 (OB_CLIENT_FUNC_RESIZE
|
1424 OB_CLIENT_FUNC_MOVE
|
1425 OB_CLIENT_FUNC_ICONIFY
|
1426 OB_CLIENT_FUNC_MAXIMIZE
|
1427 OB_CLIENT_FUNC_SHADE
|
1428 OB_CLIENT_FUNC_CLOSE
);
1430 if (!(self
->min_size
.width
< self
->max_size
.width
||
1431 self
->min_size
.height
< self
->max_size
.height
))
1432 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
1434 switch (self
->type
) {
1435 case OB_CLIENT_TYPE_NORMAL
:
1436 /* normal windows retain all of the possible decorations and
1437 functionality, and are the only windows that you can fullscreen */
1438 self
->functions
|= OB_CLIENT_FUNC_FULLSCREEN
;
1441 case OB_CLIENT_TYPE_DIALOG
:
1442 case OB_CLIENT_TYPE_UTILITY
:
1443 /* these windows cannot be maximized */
1444 self
->functions
&= ~OB_CLIENT_FUNC_MAXIMIZE
;
1447 case OB_CLIENT_TYPE_MENU
:
1448 case OB_CLIENT_TYPE_TOOLBAR
:
1449 /* these windows get less functionality */
1450 self
->functions
&= ~(OB_CLIENT_FUNC_ICONIFY
| OB_CLIENT_FUNC_RESIZE
);
1453 case OB_CLIENT_TYPE_DESKTOP
:
1454 case OB_CLIENT_TYPE_DOCK
:
1455 case OB_CLIENT_TYPE_SPLASH
:
1456 /* none of these windows are manipulated by the window manager */
1457 self
->decorations
= 0;
1458 self
->functions
= 0;
1462 /* Mwm Hints are applied subtractively to what has already been chosen for
1463 decor and functionality */
1464 if (self
->mwmhints
.flags
& OB_MWM_FLAG_DECORATIONS
) {
1465 if (! (self
->mwmhints
.decorations
& OB_MWM_DECOR_ALL
)) {
1466 if (! ((self
->mwmhints
.decorations
& OB_MWM_DECOR_HANDLE
) ||
1467 (self
->mwmhints
.decorations
& OB_MWM_DECOR_TITLE
)))
1469 /* if the mwm hints request no handle or title, then all
1470 decorations are disabled, but keep the border if that's
1472 if (self
->mwmhints
.decorations
& OB_MWM_DECOR_BORDER
)
1473 self
->decorations
= OB_FRAME_DECOR_BORDER
;
1475 self
->decorations
= 0;
1480 if (self
->mwmhints
.flags
& OB_MWM_FLAG_FUNCTIONS
) {
1481 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_ALL
)) {
1482 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_RESIZE
))
1483 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
1484 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_MOVE
))
1485 self
->functions
&= ~OB_CLIENT_FUNC_MOVE
;
1486 /* dont let mwm hints kill any buttons
1487 if (! (self->mwmhints.functions & OB_MWM_FUNC_ICONIFY))
1488 self->functions &= ~OB_CLIENT_FUNC_ICONIFY;
1489 if (! (self->mwmhints.functions & OB_MWM_FUNC_MAXIMIZE))
1490 self->functions &= ~OB_CLIENT_FUNC_MAXIMIZE;
1492 /* dont let mwm hints kill the close button
1493 if (! (self->mwmhints.functions & MwmFunc_Close))
1494 self->functions &= ~OB_CLIENT_FUNC_CLOSE; */
1498 if (!(self
->functions
& OB_CLIENT_FUNC_SHADE
))
1499 self
->decorations
&= ~OB_FRAME_DECOR_SHADE
;
1500 if (!(self
->functions
& OB_CLIENT_FUNC_ICONIFY
))
1501 self
->decorations
&= ~OB_FRAME_DECOR_ICONIFY
;
1502 if (!(self
->functions
& OB_CLIENT_FUNC_RESIZE
))
1503 self
->decorations
&= ~OB_FRAME_DECOR_GRIPS
;
1505 /* can't maximize without moving/resizing */
1506 if (!((self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) &&
1507 (self
->functions
& OB_CLIENT_FUNC_MOVE
) &&
1508 (self
->functions
& OB_CLIENT_FUNC_RESIZE
))) {
1509 self
->functions
&= ~OB_CLIENT_FUNC_MAXIMIZE
;
1510 self
->decorations
&= ~OB_FRAME_DECOR_MAXIMIZE
;
1513 /* kill the handle on fully maxed windows */
1514 if (self
->max_vert
&& self
->max_horz
)
1515 self
->decorations
&= ~OB_FRAME_DECOR_HANDLE
;
1517 /* finally, the user can have requested no decorations, which overrides
1518 everything (but doesnt give it a border if it doesnt have one) */
1519 if (self
->undecorated
) {
1520 if (config_theme_keepborder
)
1521 self
->decorations
&= OB_FRAME_DECOR_BORDER
;
1523 self
->decorations
= 0;
1526 /* if we don't have a titlebar, then we cannot shade! */
1527 if (!(self
->decorations
& OB_FRAME_DECOR_TITLEBAR
))
1528 self
->functions
&= ~OB_CLIENT_FUNC_SHADE
;
1530 /* now we need to check against rules for the client's current state */
1531 if (self
->fullscreen
) {
1532 self
->functions
&= (OB_CLIENT_FUNC_CLOSE
|
1533 OB_CLIENT_FUNC_FULLSCREEN
|
1534 OB_CLIENT_FUNC_ICONIFY
);
1535 self
->decorations
= 0;
1538 client_change_allowed_actions(self
);
1541 /* adjust the client's decorations, etc. */
1542 client_reconfigure(self
);
1546 static void client_change_allowed_actions(ObClient
*self
)
1551 /* desktop windows are kept on all desktops */
1552 if (self
->type
!= OB_CLIENT_TYPE_DESKTOP
)
1553 actions
[num
++] = prop_atoms
.net_wm_action_change_desktop
;
1555 if (self
->functions
& OB_CLIENT_FUNC_SHADE
)
1556 actions
[num
++] = prop_atoms
.net_wm_action_shade
;
1557 if (self
->functions
& OB_CLIENT_FUNC_CLOSE
)
1558 actions
[num
++] = prop_atoms
.net_wm_action_close
;
1559 if (self
->functions
& OB_CLIENT_FUNC_MOVE
)
1560 actions
[num
++] = prop_atoms
.net_wm_action_move
;
1561 if (self
->functions
& OB_CLIENT_FUNC_ICONIFY
)
1562 actions
[num
++] = prop_atoms
.net_wm_action_minimize
;
1563 if (self
->functions
& OB_CLIENT_FUNC_RESIZE
)
1564 actions
[num
++] = prop_atoms
.net_wm_action_resize
;
1565 if (self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
)
1566 actions
[num
++] = prop_atoms
.net_wm_action_fullscreen
;
1567 if (self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) {
1568 actions
[num
++] = prop_atoms
.net_wm_action_maximize_horz
;
1569 actions
[num
++] = prop_atoms
.net_wm_action_maximize_vert
;
1572 PROP_SETA32(self
->window
, net_wm_allowed_actions
, atom
, actions
, num
);
1574 /* make sure the window isn't breaking any rules now */
1576 if (!(self
->functions
& OB_CLIENT_FUNC_SHADE
) && self
->shaded
) {
1577 if (self
->frame
) client_shade(self
, FALSE
);
1578 else self
->shaded
= FALSE
;
1580 if (!(self
->functions
& OB_CLIENT_FUNC_ICONIFY
) && self
->iconic
) {
1581 if (self
->frame
) client_iconify(self
, FALSE
, TRUE
);
1582 else self
->iconic
= FALSE
;
1584 if (!(self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
) && self
->fullscreen
) {
1585 if (self
->frame
) client_fullscreen(self
, FALSE
);
1586 else self
->fullscreen
= FALSE
;
1588 if (!(self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) && (self
->max_horz
||
1590 if (self
->frame
) client_maximize(self
, FALSE
, 0);
1591 else self
->max_vert
= self
->max_horz
= FALSE
;
1595 void client_reconfigure(ObClient
*self
)
1597 /* by making this pass FALSE for user, we avoid the emacs event storm where
1598 every configurenotify causes an update in its normal hints, i think this
1599 is generally what we want anyways... */
1600 client_configure(self
, OB_CORNER_TOPLEFT
, self
->area
.x
, self
->area
.y
,
1601 self
->area
.width
, self
->area
.height
, FALSE
, TRUE
);
1604 void client_update_wmhints(ObClient
*self
)
1609 /* assume a window takes input if it doesnt specify */
1610 self
->can_focus
= TRUE
;
1612 if ((hints
= XGetWMHints(ob_display
, self
->window
)) != NULL
) {
1613 if (hints
->flags
& InputHint
)
1614 self
->can_focus
= hints
->input
;
1616 /* only do this when first managing the window *AND* when we aren't
1618 if (ob_state() != OB_STATE_STARTING
&& self
->frame
== NULL
)
1619 if (hints
->flags
& StateHint
)
1620 self
->iconic
= hints
->initial_state
== IconicState
;
1622 if (!(hints
->flags
& WindowGroupHint
))
1623 hints
->window_group
= None
;
1625 /* did the group state change? */
1626 if (hints
->window_group
!=
1627 (self
->group
? self
->group
->leader
: None
)) {
1628 /* remove from the old group if there was one */
1629 if (self
->group
!= NULL
) {
1630 /* remove transients of the group */
1631 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
))
1632 self
->transients
= g_slist_remove(self
->transients
,
1635 /* remove myself from parents in the group */
1636 if (self
->transient_for
== OB_TRAN_GROUP
) {
1637 for (it
= self
->group
->members
; it
;
1638 it
= g_slist_next(it
))
1640 ObClient
*c
= it
->data
;
1642 if (c
!= self
&& !c
->transient_for
)
1643 c
->transients
= g_slist_remove(c
->transients
,
1648 group_remove(self
->group
, self
);
1651 if (hints
->window_group
!= None
) {
1652 self
->group
= group_add(hints
->window_group
, self
);
1654 /* i can only have transients from the group if i am not
1656 if (!self
->transient_for
) {
1657 /* add other transients of the group that are already
1659 for (it
= self
->group
->members
; it
;
1660 it
= g_slist_next(it
))
1662 ObClient
*c
= it
->data
;
1663 if (c
!= self
&& c
->transient_for
== OB_TRAN_GROUP
)
1665 g_slist_append(self
->transients
, c
);
1670 /* because the self->transient flag wont change from this call,
1671 we don't need to update the window's type and such, only its
1672 transient_for, and the transients lists of other windows in
1673 the group may be affected */
1674 client_update_transient_for(self
);
1677 /* the WM_HINTS can contain an icon */
1678 client_update_icons(self
);
1684 void client_update_title(ObClient
*self
)
1687 gchar
*visible
= NULL
;
1689 g_free(self
->title
);
1692 if (!PROP_GETS(self
->window
, net_wm_name
, utf8
, &data
)) {
1693 /* try old x stuff */
1694 if (!(PROP_GETS(self
->window
, wm_name
, locale
, &data
)
1695 || PROP_GETS(self
->window
, wm_name
, utf8
, &data
))) {
1696 if (self
->transient
) {
1698 GNOME alert windows are not given titles:
1699 http://developer.gnome.org/projects/gup/hig/draft_hig_new/windows-alert.html
1701 data
= g_strdup("");
1703 data
= g_strdup("Unnamed Window");
1707 if (self
->client_machine
) {
1708 visible
= g_strdup_printf("%s (%s)", data
, self
->client_machine
);
1713 PROP_SETS(self
->window
, net_wm_visible_name
, visible
);
1714 self
->title
= visible
;
1717 frame_adjust_title(self
->frame
);
1719 /* update the icon title */
1721 g_free(self
->icon_title
);
1724 if (!PROP_GETS(self
->window
, net_wm_icon_name
, utf8
, &data
))
1725 /* try old x stuff */
1726 if (!(PROP_GETS(self
->window
, wm_icon_name
, locale
, &data
) ||
1727 PROP_GETS(self
->window
, wm_icon_name
, utf8
, &data
)))
1728 data
= g_strdup(self
->title
);
1730 PROP_SETS(self
->window
, net_wm_visible_icon_name
, data
);
1731 self
->icon_title
= data
;
1734 void client_update_class(ObClient
*self
)
1739 if (self
->name
) g_free(self
->name
);
1740 if (self
->class) g_free(self
->class);
1741 if (self
->role
) g_free(self
->role
);
1743 self
->name
= self
->class = self
->role
= NULL
;
1745 if (PROP_GETSS(self
->window
, wm_class
, locale
, &data
)) {
1747 self
->name
= g_strdup(data
[0]);
1749 self
->class = g_strdup(data
[1]);
1754 if (PROP_GETS(self
->window
, wm_window_role
, locale
, &s
))
1757 if (self
->name
== NULL
) self
->name
= g_strdup("");
1758 if (self
->class == NULL
) self
->class = g_strdup("");
1759 if (self
->role
== NULL
) self
->role
= g_strdup("");
1762 void client_update_strut(ObClient
*self
)
1766 gboolean got
= FALSE
;
1769 if (PROP_GETA32(self
->window
, net_wm_strut_partial
, cardinal
,
1773 STRUT_PARTIAL_SET(strut
,
1774 data
[0], data
[2], data
[1], data
[3],
1775 data
[4], data
[5], data
[8], data
[9],
1776 data
[6], data
[7], data
[10], data
[11]);
1782 PROP_GETA32(self
->window
, net_wm_strut
, cardinal
, &data
, &num
)) {
1788 /* use the screen's width/height */
1789 a
= screen_physical_area();
1791 STRUT_PARTIAL_SET(strut
,
1792 data
[0], data
[2], data
[1], data
[3],
1793 a
->y
, a
->y
+ a
->height
- 1,
1794 a
->x
, a
->x
+ a
->width
- 1,
1795 a
->y
, a
->y
+ a
->height
- 1,
1796 a
->x
, a
->x
+ a
->width
- 1);
1802 STRUT_PARTIAL_SET(strut
, 0, 0, 0, 0,
1803 0, 0, 0, 0, 0, 0, 0, 0);
1805 if (!STRUT_EQUAL(strut
, self
->strut
)) {
1806 self
->strut
= strut
;
1808 /* updating here is pointless while we're being mapped cuz we're not in
1809 the client list yet */
1811 screen_update_areas();
1815 void client_update_icons(ObClient
*self
)
1821 for (i
= 0; i
< self
->nicons
; ++i
)
1822 g_free(self
->icons
[i
].data
);
1823 if (self
->nicons
> 0)
1824 g_free(self
->icons
);
1827 if (PROP_GETA32(self
->window
, net_wm_icon
, cardinal
, &data
, &num
)) {
1828 /* figure out how many valid icons are in here */
1830 while (num
- i
> 2) {
1834 if (i
> num
|| w
*h
== 0) break;
1838 self
->icons
= g_new(ObClientIcon
, self
->nicons
);
1840 /* store the icons */
1842 for (j
= 0; j
< self
->nicons
; ++j
) {
1845 w
= self
->icons
[j
].width
= data
[i
++];
1846 h
= self
->icons
[j
].height
= data
[i
++];
1848 if (w
*h
== 0) continue;
1850 self
->icons
[j
].data
= g_new(RrPixel32
, w
* h
);
1851 for (x
= 0, y
= 0, t
= 0; t
< w
* h
; ++t
, ++x
, ++i
) {
1856 self
->icons
[j
].data
[t
] =
1857 (((data
[i
] >> 24) & 0xff) << RrDefaultAlphaOffset
) +
1858 (((data
[i
] >> 16) & 0xff) << RrDefaultRedOffset
) +
1859 (((data
[i
] >> 8) & 0xff) << RrDefaultGreenOffset
) +
1860 (((data
[i
] >> 0) & 0xff) << RrDefaultBlueOffset
);
1869 if ((hints
= XGetWMHints(ob_display
, self
->window
))) {
1870 if (hints
->flags
& IconPixmapHint
) {
1872 self
->icons
= g_new(ObClientIcon
, self
->nicons
);
1873 xerror_set_ignore(TRUE
);
1874 if (!RrPixmapToRGBA(ob_rr_inst
,
1876 (hints
->flags
& IconMaskHint
?
1877 hints
->icon_mask
: None
),
1878 &self
->icons
[self
->nicons
-1].width
,
1879 &self
->icons
[self
->nicons
-1].height
,
1880 &self
->icons
[self
->nicons
-1].data
)){
1881 g_free(&self
->icons
[self
->nicons
-1]);
1884 xerror_set_ignore(FALSE
);
1890 /* set the default icon onto the window
1891 in theory, this could be a race, but if a window doesn't set an icon
1892 or removes it entirely, it's not very likely it is going to set one
1893 right away afterwards */
1894 if (self
->nicons
== 0) {
1895 RrPixel32
*icon
= ob_rr_theme
->def_win_icon
;
1897 data
= g_new(guint32
, 48*48+2);
1898 data
[0] = data
[1] = 48;
1899 for (i
= 0; i
< 48*48; ++i
)
1900 data
[i
+2] = (((icon
[i
] >> RrDefaultAlphaOffset
) & 0xff) << 24) +
1901 (((icon
[i
] >> RrDefaultRedOffset
) & 0xff) << 16) +
1902 (((icon
[i
] >> RrDefaultGreenOffset
) & 0xff) << 8) +
1903 (((icon
[i
] >> RrDefaultBlueOffset
) & 0xff) << 0);
1904 PROP_SETA32(self
->window
, net_wm_icon
, cardinal
, data
, 48*48+2);
1906 } else if (self
->frame
)
1907 /* don't draw the icon empty if we're just setting one now anyways,
1908 we'll get the property change any second */
1909 frame_adjust_icon(self
->frame
);
1912 void client_update_user_time(ObClient
*self
)
1916 if (PROP_GET32(self
->window
, net_wm_user_time
, cardinal
, &time
)) {
1917 /* we set this every time, not just when it grows, because in practice
1918 sometimes time goes backwards! (ntpdate.. yay....) so.. if it goes
1919 backward we don't want all windows to stop focusing. we'll just
1920 assume noone is setting times older than the last one, cuz that
1921 would be pretty stupid anyways
1923 self
->user_time
= time
;
1926 ob_debug("window %s user time %u\n", self->title, time);
1931 static void client_get_client_machine(ObClient
*self
)
1934 gchar localhost
[128];
1936 g_free(self
->client_machine
);
1938 if (PROP_GETS(self
->window
, wm_client_machine
, locale
, &data
)) {
1939 gethostname(localhost
, 127);
1940 localhost
[127] = '\0';
1941 if (strcmp(localhost
, data
))
1942 self
->client_machine
= data
;
1946 static void client_change_wm_state(ObClient
*self
)
1951 old
= self
->wmstate
;
1953 if (self
->shaded
|| self
->iconic
|| !self
->frame
->visible
)
1954 self
->wmstate
= IconicState
;
1956 self
->wmstate
= NormalState
;
1958 if (old
!= self
->wmstate
) {
1959 PROP_MSG(self
->window
, kde_wm_change_state
,
1960 self
->wmstate
, 1, 0, 0);
1962 state
[0] = self
->wmstate
;
1964 PROP_SETA32(self
->window
, wm_state
, wm_state
, state
, 2);
1968 static void client_change_state(ObClient
*self
)
1970 gulong netstate
[11];
1975 netstate
[num
++] = prop_atoms
.net_wm_state_modal
;
1977 netstate
[num
++] = prop_atoms
.net_wm_state_shaded
;
1979 netstate
[num
++] = prop_atoms
.net_wm_state_hidden
;
1980 if (self
->skip_taskbar
)
1981 netstate
[num
++] = prop_atoms
.net_wm_state_skip_taskbar
;
1982 if (self
->skip_pager
)
1983 netstate
[num
++] = prop_atoms
.net_wm_state_skip_pager
;
1984 if (self
->fullscreen
)
1985 netstate
[num
++] = prop_atoms
.net_wm_state_fullscreen
;
1987 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_vert
;
1989 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_horz
;
1991 netstate
[num
++] = prop_atoms
.net_wm_state_above
;
1993 netstate
[num
++] = prop_atoms
.net_wm_state_below
;
1994 if (self
->demands_attention
)
1995 netstate
[num
++] = prop_atoms
.net_wm_state_demands_attention
;
1996 if (self
->undecorated
)
1997 netstate
[num
++] = prop_atoms
.ob_wm_state_undecorated
;
1998 PROP_SETA32(self
->window
, net_wm_state
, atom
, netstate
, num
);
2001 frame_adjust_state(self
->frame
);
2004 ObClient
*client_search_focus_tree(ObClient
*self
)
2009 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
2010 if (client_focused(it
->data
)) return it
->data
;
2011 if ((ret
= client_search_focus_tree(it
->data
))) return ret
;
2016 ObClient
*client_search_focus_tree_full(ObClient
*self
)
2018 if (self
->transient_for
) {
2019 if (self
->transient_for
!= OB_TRAN_GROUP
) {
2020 return client_search_focus_tree_full(self
->transient_for
);
2023 gboolean recursed
= FALSE
;
2025 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
))
2026 if (!((ObClient
*)it
->data
)->transient_for
) {
2028 if ((c
= client_search_focus_tree_full(it
->data
)))
2037 /* this function checks the whole tree, the client_search_focus_tree~
2038 does not, so we need to check this window */
2039 if (client_focused(self
))
2041 return client_search_focus_tree(self
);
2044 static ObStackingLayer
calc_layer(ObClient
*self
)
2048 if (self
->fullscreen
&&
2049 (client_focused(self
) || client_search_focus_tree(self
)))
2050 l
= OB_STACKING_LAYER_FULLSCREEN
;
2051 else if (self
->type
== OB_CLIENT_TYPE_DESKTOP
)
2052 l
= OB_STACKING_LAYER_DESKTOP
;
2053 else if (self
->type
== OB_CLIENT_TYPE_DOCK
) {
2054 if (self
->below
) l
= OB_STACKING_LAYER_NORMAL
;
2055 else l
= OB_STACKING_LAYER_ABOVE
;
2057 else if (self
->above
) l
= OB_STACKING_LAYER_ABOVE
;
2058 else if (self
->below
) l
= OB_STACKING_LAYER_BELOW
;
2059 else l
= OB_STACKING_LAYER_NORMAL
;
2064 static void client_calc_layer_recursive(ObClient
*self
, ObClient
*orig
,
2065 ObStackingLayer min
, gboolean raised
)
2067 ObStackingLayer old
, own
;
2071 own
= calc_layer(self
);
2072 self
->layer
= MAX(own
, min
);
2074 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
2075 client_calc_layer_recursive(it
->data
, orig
,
2077 raised
? raised
: self
->layer
!= old
);
2079 if (!raised
&& self
->layer
!= old
)
2080 if (orig
->frame
) { /* only restack if the original window is managed */
2081 stacking_remove(CLIENT_AS_WINDOW(self
));
2082 stacking_add(CLIENT_AS_WINDOW(self
));
2086 void client_calc_layer(ObClient
*self
)
2093 /* transients take on the layer of their parents */
2094 it
= client_search_all_top_parents(self
);
2096 for (; it
; it
= g_slist_next(it
))
2097 client_calc_layer_recursive(it
->data
, orig
, 0, FALSE
);
2100 gboolean
client_should_show(ObClient
*self
)
2104 if (client_normal(self
) && screen_showing_desktop
)
2107 if (self->transient_for) {
2108 if (self->transient_for != OB_TRAN_GROUP)
2109 return client_should_show(self->transient_for);
2113 for (it = self->group->members; it; it = g_slist_next(it)) {
2114 ObClient *c = it->data;
2115 if (c != self && !c->transient_for) {
2116 if (client_should_show(c))
2123 if (self
->desktop
== screen_desktop
|| self
->desktop
== DESKTOP_ALL
)
2129 void client_show(ObClient
*self
)
2132 if (client_should_show(self
)) {
2133 frame_show(self
->frame
);
2136 /* According to the ICCCM (sec 4.1.3.1) when a window is not visible, it
2137 needs to be in IconicState. This includes when it is on another
2140 client_change_wm_state(self
);
2143 void client_hide(ObClient
*self
)
2145 if (!client_should_show(self
)) {
2146 frame_hide(self
->frame
);
2149 /* According to the ICCCM (sec 4.1.3.1) when a window is not visible, it
2150 needs to be in IconicState. This includes when it is on another
2153 client_change_wm_state(self
);
2156 void client_showhide(ObClient
*self
)
2159 if (client_should_show(self
)) {
2160 frame_show(self
->frame
);
2163 frame_hide(self
->frame
);
2166 /* According to the ICCCM (sec 4.1.3.1) when a window is not visible, it
2167 needs to be in IconicState. This includes when it is on another
2170 client_change_wm_state(self
);
2173 gboolean
client_normal(ObClient
*self
) {
2174 return ! (self
->type
== OB_CLIENT_TYPE_DESKTOP
||
2175 self
->type
== OB_CLIENT_TYPE_DOCK
||
2176 self
->type
== OB_CLIENT_TYPE_SPLASH
);
2179 static void client_apply_startup_state(ObClient
*self
, gint x
, gint y
)
2181 gboolean pos
= FALSE
; /* has the window's position been configured? */
2184 /* save the position, and set self->area for these to use */
2190 /* set the desktop hint, to make sure that it always exists */
2191 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, self
->desktop
);
2193 /* these are in a carefully crafted order.. */
2196 self
->iconic
= FALSE
;
2197 client_iconify(self
, TRUE
, FALSE
);
2199 if (self
->fullscreen
) {
2200 self
->fullscreen
= FALSE
;
2201 client_fullscreen(self
, TRUE
);
2204 if (self
->undecorated
) {
2205 self
->undecorated
= FALSE
;
2206 client_set_undecorated(self
, TRUE
);
2209 self
->shaded
= FALSE
;
2210 client_shade(self
, TRUE
);
2212 if (self
->demands_attention
) {
2213 self
->demands_attention
= FALSE
;
2214 client_hilite(self
, TRUE
);
2217 if (self
->max_vert
&& self
->max_horz
) {
2218 self
->max_vert
= self
->max_horz
= FALSE
;
2219 client_maximize(self
, TRUE
, 0);
2221 } else if (self
->max_vert
) {
2222 self
->max_vert
= FALSE
;
2223 client_maximize(self
, TRUE
, 2);
2225 } else if (self
->max_horz
) {
2226 self
->max_horz
= FALSE
;
2227 client_maximize(self
, TRUE
, 1);
2231 /* if the client didn't get positioned yet, then do so now
2232 call client_move even if the window is not being moved anywhere, because
2233 when we reparent it and decorate it, it is getting moved and we need to
2234 be telling it so with a ConfigureNotify event.
2237 /* use the saved position */
2240 client_move(self
, x
, y
);
2243 /* nothing to do for the other states:
2252 void client_try_configure(ObClient
*self
, ObCorner anchor
,
2253 gint
*x
, gint
*y
, gint
*w
, gint
*h
,
2254 gint
*logicalw
, gint
*logicalh
,
2257 Rect desired_area
= {*x
, *y
, *w
, *h
};
2259 /* make the frame recalculate its dimentions n shit without changing
2260 anything visible for real, this way the constraints below can work with
2261 the updated frame dimensions. */
2262 frame_adjust_area(self
->frame
, TRUE
, TRUE
, TRUE
);
2264 /* work within the prefered sizes given by the window */
2265 if (!(*w
== self
->area
.width
&& *h
== self
->area
.height
)) {
2266 gint basew
, baseh
, minw
, minh
;
2268 /* base size is substituted with min size if not specified */
2269 if (self
->base_size
.width
|| self
->base_size
.height
) {
2270 basew
= self
->base_size
.width
;
2271 baseh
= self
->base_size
.height
;
2273 basew
= self
->min_size
.width
;
2274 baseh
= self
->min_size
.height
;
2276 /* min size is substituted with base size if not specified */
2277 if (self
->min_size
.width
|| self
->min_size
.height
) {
2278 minw
= self
->min_size
.width
;
2279 minh
= self
->min_size
.height
;
2281 minw
= self
->base_size
.width
;
2282 minh
= self
->base_size
.height
;
2285 /* if this is a user-requested resize, then check against min/max
2288 /* smaller than min size or bigger than max size? */
2289 if (*w
> self
->max_size
.width
) *w
= self
->max_size
.width
;
2290 if (*w
< minw
) *w
= minw
;
2291 if (*h
> self
->max_size
.height
) *h
= self
->max_size
.height
;
2292 if (*h
< minh
) *h
= minh
;
2297 /* keep to the increments */
2298 *w
/= self
->size_inc
.width
;
2299 *h
/= self
->size_inc
.height
;
2301 /* you cannot resize to nothing */
2302 if (basew
+ *w
< 1) *w
= 1 - basew
;
2303 if (baseh
+ *h
< 1) *h
= 1 - baseh
;
2305 /* save the logical size */
2306 *logicalw
= self
->size_inc
.width
> 1 ? *w
: *w
+ basew
;
2307 *logicalh
= self
->size_inc
.height
> 1 ? *h
: *h
+ baseh
;
2309 *w
*= self
->size_inc
.width
;
2310 *h
*= self
->size_inc
.height
;
2315 /* adjust the height to match the width for the aspect ratios.
2316 for this, min size is not substituted for base size ever. */
2317 *w
-= self
->base_size
.width
;
2318 *h
-= self
->base_size
.height
;
2320 if (!self
->fullscreen
) {
2321 if (self
->min_ratio
)
2322 if (*h
* self
->min_ratio
> *w
) {
2323 *h
= (gint
)(*w
/ self
->min_ratio
);
2325 /* you cannot resize to nothing */
2328 *w
= (gint
)(*h
* self
->min_ratio
);
2331 if (self
->max_ratio
)
2332 if (*h
* self
->max_ratio
< *w
) {
2333 *h
= (gint
)(*w
/ self
->max_ratio
);
2335 /* you cannot resize to nothing */
2338 *w
= (gint
)(*h
* self
->min_ratio
);
2343 *w
+= self
->base_size
.width
;
2344 *h
+= self
->base_size
.height
;
2347 /* gets the frame's position */
2348 frame_client_gravity(self
->frame
, x
, y
);
2350 /* these positions are frame positions, not client positions */
2352 /* set the size and position if fullscreen */
2353 if (self
->fullscreen
) {
2357 i
= screen_find_monitor(&desired_area
);
2358 a
= screen_physical_area_monitor(i
);
2365 user
= FALSE
; /* ignore if the client can't be moved/resized when it
2366 is entering fullscreen */
2367 } else if (self
->max_horz
|| self
->max_vert
) {
2371 i
= screen_find_monitor(&desired_area
);
2372 a
= screen_area_monitor(self
->desktop
, i
);
2374 /* set the size and position if maximized */
2375 if (self
->max_horz
) {
2377 *w
= a
->width
- self
->frame
->size
.left
- self
->frame
->size
.right
;
2379 if (self
->max_vert
) {
2381 *h
= a
->height
- self
->frame
->size
.top
- self
->frame
->size
.bottom
;
2384 /* maximizing is not allowed if the user can't move+resize the window
2388 /* gets the client's position */
2389 frame_frame_gravity(self
->frame
, x
, y
);
2391 /* these override the above states! if you cant move you can't move! */
2393 if (!(self
->functions
& OB_CLIENT_FUNC_MOVE
)) {
2397 if (!(self
->functions
& OB_CLIENT_FUNC_RESIZE
)) {
2398 *w
= self
->area
.width
;
2399 *h
= self
->area
.height
;
2407 case OB_CORNER_TOPLEFT
:
2409 case OB_CORNER_TOPRIGHT
:
2410 *x
-= *w
- self
->area
.width
;
2412 case OB_CORNER_BOTTOMLEFT
:
2413 *y
-= *h
- self
->area
.height
;
2415 case OB_CORNER_BOTTOMRIGHT
:
2416 *x
-= *w
- self
->area
.width
;
2417 *y
-= *h
- self
->area
.height
;
2423 void client_configure_full(ObClient
*self
, ObCorner anchor
,
2424 gint x
, gint y
, gint w
, gint h
,
2425 gboolean user
, gboolean final
,
2426 gboolean force_reply
)
2428 gint oldw
, oldh
, oldrx
, oldry
;
2429 gboolean send_resize_client
;
2430 gboolean moved
= FALSE
, resized
= FALSE
, rootmoved
= FALSE
;
2431 guint fdecor
= self
->frame
->decorations
;
2432 gboolean fhorz
= self
->frame
->max_horz
;
2433 gint logicalw
, logicalh
;
2435 /* find the new x, y, width, and height (and logical size) */
2436 client_try_configure(self
, anchor
, &x
, &y
, &w
, &h
,
2437 &logicalw
, &logicalh
, user
);
2439 /* set the logical size if things changed */
2440 if (!(w
== self
->area
.width
&& h
== self
->area
.height
))
2441 SIZE_SET(self
->logical_size
, logicalw
, logicalh
);
2443 /* figure out if we moved or resized or what */
2444 moved
= x
!= self
->area
.x
|| y
!= self
->area
.y
;
2445 resized
= w
!= self
->area
.width
|| h
!= self
->area
.height
;
2447 oldw
= self
->area
.width
;
2448 oldh
= self
->area
.height
;
2449 RECT_SET(self
->area
, x
, y
, w
, h
);
2451 /* for app-requested resizes, always resize if 'resized' is true.
2452 for user-requested ones, only resize if final is true, or when
2453 resizing in redraw mode */
2454 send_resize_client
= ((!user
&& resized
) ||
2456 (resized
&& config_resize_redraw
))));
2458 /* if the client is enlarging, then resize the client before the frame */
2459 if (send_resize_client
&& user
&& (w
> oldw
|| h
> oldh
)) {
2460 XResizeWindow(ob_display
, self
->window
, MAX(w
, oldw
), MAX(h
, oldh
));
2461 frame_adjust_client_area(self
->frame
);
2464 /* find the frame's dimensions and move/resize it */
2465 if (self
->decorations
!= fdecor
|| self
->max_horz
!= fhorz
)
2466 moved
= resized
= TRUE
;
2467 if (moved
|| resized
)
2468 frame_adjust_area(self
->frame
, moved
, resized
, FALSE
);
2470 /* find the client's position relative to the root window */
2471 oldrx
= self
->root_pos
.x
;
2472 oldry
= self
->root_pos
.y
;
2473 rootmoved
= (oldrx
!= (signed)(self
->frame
->area
.x
+
2474 self
->frame
->size
.left
-
2475 self
->border_width
) ||
2476 oldry
!= (signed)(self
->frame
->area
.y
+
2477 self
->frame
->size
.top
-
2478 self
->border_width
));
2480 if (force_reply
|| ((!user
|| (user
&& final
)) && rootmoved
))
2484 POINT_SET(self
->root_pos
,
2485 self
->frame
->area
.x
+ self
->frame
->size
.left
-
2487 self
->frame
->area
.y
+ self
->frame
->size
.top
-
2488 self
->border_width
);
2490 event
.type
= ConfigureNotify
;
2491 event
.xconfigure
.display
= ob_display
;
2492 event
.xconfigure
.event
= self
->window
;
2493 event
.xconfigure
.window
= self
->window
;
2495 /* root window real coords */
2496 event
.xconfigure
.x
= self
->root_pos
.x
;
2497 event
.xconfigure
.y
= self
->root_pos
.y
;
2498 event
.xconfigure
.width
= w
;
2499 event
.xconfigure
.height
= h
;
2500 event
.xconfigure
.border_width
= 0;
2501 event
.xconfigure
.above
= self
->frame
->plate
;
2502 event
.xconfigure
.override_redirect
= FALSE
;
2503 XSendEvent(event
.xconfigure
.display
, event
.xconfigure
.window
,
2504 FALSE
, StructureNotifyMask
, &event
);
2507 /* if the client is shrinking, then resize the frame before the client */
2508 if (send_resize_client
&& (!user
|| (w
<= oldw
|| h
<= oldh
))) {
2509 frame_adjust_client_area(self
->frame
);
2510 XResizeWindow(ob_display
, self
->window
, w
, h
);
2516 void client_fullscreen(ObClient
*self
, gboolean fs
)
2520 if (!(self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
) || /* can't */
2521 self
->fullscreen
== fs
) return; /* already done */
2523 self
->fullscreen
= fs
;
2524 client_change_state(self
); /* change the state hints on the client */
2525 client_calc_layer(self
); /* and adjust out layer/stacking */
2528 self
->pre_fullscreen_area
= self
->area
;
2529 /* if the window is maximized, its area isn't all that meaningful.
2530 save it's premax area instead. */
2531 if (self
->max_horz
) {
2532 self
->pre_fullscreen_area
.x
= self
->pre_max_area
.x
;
2533 self
->pre_fullscreen_area
.width
= self
->pre_max_area
.width
;
2535 if (self
->max_vert
) {
2536 self
->pre_fullscreen_area
.y
= self
->pre_max_area
.y
;
2537 self
->pre_fullscreen_area
.height
= self
->pre_max_area
.height
;
2540 /* these are not actually used cuz client_configure will set them
2541 as appropriate when the window is fullscreened */
2546 if (self
->pre_fullscreen_area
.width
> 0 &&
2547 self
->pre_fullscreen_area
.height
> 0)
2549 x
= self
->pre_fullscreen_area
.x
;
2550 y
= self
->pre_fullscreen_area
.y
;
2551 w
= self
->pre_fullscreen_area
.width
;
2552 h
= self
->pre_fullscreen_area
.height
;
2553 RECT_SET(self
->pre_fullscreen_area
, 0, 0, 0, 0);
2555 /* pick some fallbacks... */
2556 a
= screen_area_monitor(self
->desktop
, 0);
2557 x
= a
->x
+ a
->width
/ 4;
2558 y
= a
->y
+ a
->height
/ 4;
2564 client_setup_decor_and_functions(self
);
2566 client_move_resize(self
, x
, y
, w
, h
);
2568 /* try focus us when we go into fullscreen mode */
2572 static void client_iconify_recursive(ObClient
*self
,
2573 gboolean iconic
, gboolean curdesk
)
2576 gboolean changed
= FALSE
;
2579 if (self
->iconic
!= iconic
) {
2580 ob_debug("%sconifying window: 0x%lx\n", (iconic
? "I" : "Uni"),
2584 if (self
->functions
& OB_CLIENT_FUNC_ICONIFY
) {
2585 self
->iconic
= iconic
;
2587 /* update the focus lists.. iconic windows go to the bottom of
2588 the list, put the new iconic window at the 'top of the
2590 focus_order_to_top(self
);
2595 self
->iconic
= iconic
;
2598 client_set_desktop(self
, screen_desktop
, FALSE
);
2600 /* this puts it after the current focused window */
2601 focus_order_remove(self
);
2602 focus_order_add_new(self
);
2609 client_change_state(self
);
2610 client_showhide(self
);
2611 if (STRUT_EXISTS(self
->strut
))
2612 screen_update_areas();
2615 /* iconify all direct transients */
2616 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
2617 if (it
->data
!= self
)
2618 if (client_is_direct_child(self
, it
->data
))
2619 client_iconify_recursive(it
->data
, iconic
, curdesk
);
2622 void client_iconify(ObClient
*self
, gboolean iconic
, gboolean curdesk
)
2624 /* move up the transient chain as far as possible first */
2625 self
= client_search_top_parent(self
);
2626 client_iconify_recursive(self
, iconic
, curdesk
);
2629 void client_maximize(ObClient
*self
, gboolean max
, gint dir
)
2633 g_assert(dir
== 0 || dir
== 1 || dir
== 2);
2634 if (!(self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
)) return; /* can't */
2636 /* check if already done */
2638 if (dir
== 0 && self
->max_horz
&& self
->max_vert
) return;
2639 if (dir
== 1 && self
->max_horz
) return;
2640 if (dir
== 2 && self
->max_vert
) return;
2642 if (dir
== 0 && !self
->max_horz
&& !self
->max_vert
) return;
2643 if (dir
== 1 && !self
->max_horz
) return;
2644 if (dir
== 2 && !self
->max_vert
) return;
2647 /* we just tell it to configure in the same place and client_configure
2648 worries about filling the screen with the window */
2651 w
= self
->area
.width
;
2652 h
= self
->area
.height
;
2655 if ((dir
== 0 || dir
== 1) && !self
->max_horz
) { /* horz */
2656 RECT_SET(self
->pre_max_area
,
2657 self
->area
.x
, self
->pre_max_area
.y
,
2658 self
->area
.width
, self
->pre_max_area
.height
);
2660 if ((dir
== 0 || dir
== 2) && !self
->max_vert
) { /* vert */
2661 RECT_SET(self
->pre_max_area
,
2662 self
->pre_max_area
.x
, self
->area
.y
,
2663 self
->pre_max_area
.width
, self
->area
.height
);
2668 a
= screen_area_monitor(self
->desktop
, 0);
2669 if ((dir
== 0 || dir
== 1) && self
->max_horz
) { /* horz */
2670 if (self
->pre_max_area
.width
> 0) {
2671 x
= self
->pre_max_area
.x
;
2672 w
= self
->pre_max_area
.width
;
2674 RECT_SET(self
->pre_max_area
, 0, self
->pre_max_area
.y
,
2675 0, self
->pre_max_area
.height
);
2677 /* pick some fallbacks... */
2678 x
= a
->x
+ a
->width
/ 4;
2682 if ((dir
== 0 || dir
== 2) && self
->max_vert
) { /* vert */
2683 if (self
->pre_max_area
.height
> 0) {
2684 y
= self
->pre_max_area
.y
;
2685 h
= self
->pre_max_area
.height
;
2687 RECT_SET(self
->pre_max_area
, self
->pre_max_area
.x
, 0,
2688 self
->pre_max_area
.width
, 0);
2690 /* pick some fallbacks... */
2691 y
= a
->y
+ a
->height
/ 4;
2697 if (dir
== 0 || dir
== 1) /* horz */
2698 self
->max_horz
= max
;
2699 if (dir
== 0 || dir
== 2) /* vert */
2700 self
->max_vert
= max
;
2702 client_change_state(self
); /* change the state hints on the client */
2704 client_setup_decor_and_functions(self
);
2706 client_move_resize(self
, x
, y
, w
, h
);
2709 void client_shade(ObClient
*self
, gboolean shade
)
2711 if ((!(self
->functions
& OB_CLIENT_FUNC_SHADE
) &&
2712 shade
) || /* can't shade */
2713 self
->shaded
== shade
) return; /* already done */
2715 self
->shaded
= shade
;
2716 client_change_state(self
);
2717 client_change_wm_state(self
); /* the window is being hidden/shown */
2718 /* resize the frame to just the titlebar */
2719 frame_adjust_area(self
->frame
, FALSE
, FALSE
, FALSE
);
2722 void client_close(ObClient
*self
)
2726 if (!(self
->functions
& OB_CLIENT_FUNC_CLOSE
)) return;
2728 /* in the case that the client provides no means to requesting that it
2729 close, we just kill it */
2730 if (!self
->delete_window
)
2734 XXX: itd be cool to do timeouts and shit here for killing the client's
2736 like... if the window is around after 5 seconds, then the close button
2737 turns a nice red, and if this function is called again, the client is
2741 ce
.xclient
.type
= ClientMessage
;
2742 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
2743 ce
.xclient
.display
= ob_display
;
2744 ce
.xclient
.window
= self
->window
;
2745 ce
.xclient
.format
= 32;
2746 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_delete_window
;
2747 ce
.xclient
.data
.l
[1] = event_curtime
;
2748 ce
.xclient
.data
.l
[2] = 0l;
2749 ce
.xclient
.data
.l
[3] = 0l;
2750 ce
.xclient
.data
.l
[4] = 0l;
2751 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
2754 void client_kill(ObClient
*self
)
2756 XKillClient(ob_display
, self
->window
);
2759 void client_hilite(ObClient
*self
, gboolean hilite
)
2761 if (self
->demands_attention
== hilite
)
2762 return; /* no change */
2764 /* don't allow focused windows to hilite */
2765 self
->demands_attention
= hilite
&& !client_focused(self
);
2766 if (self
->demands_attention
)
2767 frame_flash_start(self
->frame
);
2769 frame_flash_stop(self
->frame
);
2770 client_change_state(self
);
2773 void client_set_desktop_recursive(ObClient
*self
,
2774 guint target
, gboolean donthide
)
2779 if (target
!= self
->desktop
) {
2781 ob_debug("Setting desktop %u\n", target
+1);
2783 g_assert(target
< screen_num_desktops
|| target
== DESKTOP_ALL
);
2785 /* remove from the old desktop(s) */
2786 focus_order_remove(self
);
2788 old
= self
->desktop
;
2789 self
->desktop
= target
;
2790 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, target
);
2791 /* the frame can display the current desktop state */
2792 frame_adjust_state(self
->frame
);
2793 /* 'move' the window to the new desktop */
2795 client_showhide(self
);
2796 /* raise if it was not already on the desktop */
2797 if (old
!= DESKTOP_ALL
)
2799 if (STRUT_EXISTS(self
->strut
))
2800 screen_update_areas();
2802 /* add to the new desktop(s) */
2803 if (config_focus_new
)
2804 focus_order_to_top(self
);
2806 focus_order_to_bottom(self
);
2809 /* move all transients */
2810 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
2811 if (it
->data
!= self
)
2812 if (client_is_direct_child(self
, it
->data
))
2813 client_set_desktop_recursive(it
->data
, target
, donthide
);
2816 void client_set_desktop(ObClient
*self
, guint target
, gboolean donthide
)
2818 self
= client_search_top_parent(self
);
2819 client_set_desktop_recursive(self
, target
, donthide
);
2822 gboolean
client_is_direct_child(ObClient
*parent
, ObClient
*child
)
2824 while (child
!= parent
&&
2825 child
->transient_for
&& child
->transient_for
!= OB_TRAN_GROUP
)
2826 child
= child
->transient_for
;
2827 return child
== parent
;
2830 ObClient
*client_search_modal_child(ObClient
*self
)
2835 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
2836 ObClient
*c
= it
->data
;
2837 if ((ret
= client_search_modal_child(c
))) return ret
;
2838 if (c
->modal
) return c
;
2843 gboolean
client_validate(ObClient
*self
)
2847 XSync(ob_display
, FALSE
); /* get all events on the server */
2849 if (XCheckTypedWindowEvent(ob_display
, self
->window
, DestroyNotify
, &e
) ||
2850 XCheckTypedWindowEvent(ob_display
, self
->window
, UnmapNotify
, &e
)) {
2851 XPutBackEvent(ob_display
, &e
);
2858 void client_set_wm_state(ObClient
*self
, glong state
)
2860 if (state
== self
->wmstate
) return; /* no change */
2864 client_iconify(self
, TRUE
, TRUE
);
2867 client_iconify(self
, FALSE
, TRUE
);
2872 void client_set_state(ObClient
*self
, Atom action
, glong data1
, glong data2
)
2874 gboolean shaded
= self
->shaded
;
2875 gboolean fullscreen
= self
->fullscreen
;
2876 gboolean undecorated
= self
->undecorated
;
2877 gboolean max_horz
= self
->max_horz
;
2878 gboolean max_vert
= self
->max_vert
;
2879 gboolean modal
= self
->modal
;
2880 gboolean iconic
= self
->iconic
;
2881 gboolean demands_attention
= self
->demands_attention
;
2884 if (!(action
== prop_atoms
.net_wm_state_add
||
2885 action
== prop_atoms
.net_wm_state_remove
||
2886 action
== prop_atoms
.net_wm_state_toggle
))
2887 /* an invalid action was passed to the client message, ignore it */
2890 for (i
= 0; i
< 2; ++i
) {
2891 Atom state
= i
== 0 ? data1
: data2
;
2893 if (!state
) continue;
2895 /* if toggling, then pick whether we're adding or removing */
2896 if (action
== prop_atoms
.net_wm_state_toggle
) {
2897 if (state
== prop_atoms
.net_wm_state_modal
)
2898 action
= modal
? prop_atoms
.net_wm_state_remove
:
2899 prop_atoms
.net_wm_state_add
;
2900 else if (state
== prop_atoms
.net_wm_state_maximized_vert
)
2901 action
= self
->max_vert
? prop_atoms
.net_wm_state_remove
:
2902 prop_atoms
.net_wm_state_add
;
2903 else if (state
== prop_atoms
.net_wm_state_maximized_horz
)
2904 action
= self
->max_horz
? prop_atoms
.net_wm_state_remove
:
2905 prop_atoms
.net_wm_state_add
;
2906 else if (state
== prop_atoms
.net_wm_state_shaded
)
2907 action
= shaded
? prop_atoms
.net_wm_state_remove
:
2908 prop_atoms
.net_wm_state_add
;
2909 else if (state
== prop_atoms
.net_wm_state_skip_taskbar
)
2910 action
= self
->skip_taskbar
?
2911 prop_atoms
.net_wm_state_remove
:
2912 prop_atoms
.net_wm_state_add
;
2913 else if (state
== prop_atoms
.net_wm_state_skip_pager
)
2914 action
= self
->skip_pager
?
2915 prop_atoms
.net_wm_state_remove
:
2916 prop_atoms
.net_wm_state_add
;
2917 else if (state
== prop_atoms
.net_wm_state_hidden
)
2918 action
= self
->iconic
?
2919 prop_atoms
.net_wm_state_remove
:
2920 prop_atoms
.net_wm_state_add
;
2921 else if (state
== prop_atoms
.net_wm_state_fullscreen
)
2922 action
= fullscreen
?
2923 prop_atoms
.net_wm_state_remove
:
2924 prop_atoms
.net_wm_state_add
;
2925 else if (state
== prop_atoms
.net_wm_state_above
)
2926 action
= self
->above
? prop_atoms
.net_wm_state_remove
:
2927 prop_atoms
.net_wm_state_add
;
2928 else if (state
== prop_atoms
.net_wm_state_below
)
2929 action
= self
->below
? prop_atoms
.net_wm_state_remove
:
2930 prop_atoms
.net_wm_state_add
;
2931 else if (state
== prop_atoms
.net_wm_state_demands_attention
)
2932 action
= self
->demands_attention
?
2933 prop_atoms
.net_wm_state_remove
:
2934 prop_atoms
.net_wm_state_add
;
2935 else if (state
== prop_atoms
.ob_wm_state_undecorated
)
2936 action
= undecorated
? prop_atoms
.net_wm_state_remove
:
2937 prop_atoms
.net_wm_state_add
;
2940 if (action
== prop_atoms
.net_wm_state_add
) {
2941 if (state
== prop_atoms
.net_wm_state_modal
) {
2943 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
2945 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
2947 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
2949 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
2950 self
->skip_taskbar
= TRUE
;
2951 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
2952 self
->skip_pager
= TRUE
;
2953 } else if (state
== prop_atoms
.net_wm_state_hidden
) {
2955 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
2957 } else if (state
== prop_atoms
.net_wm_state_above
) {
2959 self
->below
= FALSE
;
2960 } else if (state
== prop_atoms
.net_wm_state_below
) {
2961 self
->above
= FALSE
;
2963 } else if (state
== prop_atoms
.net_wm_state_demands_attention
) {
2964 demands_attention
= TRUE
;
2965 } else if (state
== prop_atoms
.ob_wm_state_undecorated
) {
2969 } else { /* action == prop_atoms.net_wm_state_remove */
2970 if (state
== prop_atoms
.net_wm_state_modal
) {
2972 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
2974 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
2976 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
2978 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
2979 self
->skip_taskbar
= FALSE
;
2980 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
2981 self
->skip_pager
= FALSE
;
2982 } else if (state
== prop_atoms
.net_wm_state_hidden
) {
2984 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
2986 } else if (state
== prop_atoms
.net_wm_state_above
) {
2987 self
->above
= FALSE
;
2988 } else if (state
== prop_atoms
.net_wm_state_below
) {
2989 self
->below
= FALSE
;
2990 } else if (state
== prop_atoms
.net_wm_state_demands_attention
) {
2991 demands_attention
= FALSE
;
2992 } else if (state
== prop_atoms
.ob_wm_state_undecorated
) {
2993 undecorated
= FALSE
;
2997 if (max_horz
!= self
->max_horz
|| max_vert
!= self
->max_vert
) {
2998 if (max_horz
!= self
->max_horz
&& max_vert
!= self
->max_vert
) {
3000 if (max_horz
== max_vert
) { /* both going the same way */
3001 client_maximize(self
, max_horz
, 0);
3003 client_maximize(self
, max_horz
, 1);
3004 client_maximize(self
, max_vert
, 2);
3008 if (max_horz
!= self
->max_horz
)
3009 client_maximize(self
, max_horz
, 1);
3011 client_maximize(self
, max_vert
, 2);
3014 /* change fullscreen state before shading, as it will affect if the window
3016 if (fullscreen
!= self
->fullscreen
)
3017 client_fullscreen(self
, fullscreen
);
3018 if (shaded
!= self
->shaded
)
3019 client_shade(self
, shaded
);
3020 if (undecorated
!= self
->undecorated
)
3021 client_set_undecorated(self
, undecorated
);
3022 if (modal
!= self
->modal
) {
3023 self
->modal
= modal
;
3024 /* when a window changes modality, then its stacking order with its
3025 transients needs to change */
3028 if (iconic
!= self
->iconic
)
3029 client_iconify(self
, iconic
, FALSE
);
3031 if (demands_attention
!= self
->demands_attention
)
3032 client_hilite(self
, demands_attention
);
3034 client_change_state(self
); /* change the hint to reflect these changes */
3037 ObClient
*client_focus_target(ObClient
*self
)
3039 ObClient
*child
= NULL
;
3041 child
= client_search_modal_child(self
);
3042 if (child
) return child
;
3046 gboolean
client_can_focus(ObClient
*self
)
3050 /* choose the correct target */
3051 self
= client_focus_target(self
);
3053 if (!self
->frame
->visible
)
3056 if (!(self
->can_focus
|| self
->focus_notify
))
3059 /* do a check to see if the window has already been unmapped or destroyed
3060 do this intelligently while watching out for unmaps we've generated
3061 (ignore_unmaps > 0) */
3062 if (XCheckTypedWindowEvent(ob_display
, self
->window
,
3063 DestroyNotify
, &ev
)) {
3064 XPutBackEvent(ob_display
, &ev
);
3067 while (XCheckTypedWindowEvent(ob_display
, self
->window
,
3068 UnmapNotify
, &ev
)) {
3069 if (self
->ignore_unmaps
) {
3070 self
->ignore_unmaps
--;
3072 XPutBackEvent(ob_display
, &ev
);
3080 gboolean
client_focus(ObClient
*self
)
3082 /* choose the correct target */
3083 self
= client_focus_target(self
);
3085 if (!client_can_focus(self
)) {
3086 if (!self
->frame
->visible
) {
3087 /* update the focus lists */
3088 focus_order_to_top(self
);
3093 ob_debug_type(OB_DEBUG_FOCUS
,
3094 "Focusing client \"%s\" at time %u\n",
3095 self
->title
, event_curtime
);
3097 if (self
->can_focus
) {
3098 /* This can cause a BadMatch error with CurrentTime, or if an app
3099 passed in a bad time for _NET_WM_ACTIVE_WINDOW. */
3100 xerror_set_ignore(TRUE
);
3101 XSetInputFocus(ob_display
, self
->window
, RevertToPointerRoot
,
3103 xerror_set_ignore(FALSE
);
3106 if (self
->focus_notify
) {
3108 ce
.xclient
.type
= ClientMessage
;
3109 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
3110 ce
.xclient
.display
= ob_display
;
3111 ce
.xclient
.window
= self
->window
;
3112 ce
.xclient
.format
= 32;
3113 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_take_focus
;
3114 ce
.xclient
.data
.l
[1] = event_curtime
;
3115 ce
.xclient
.data
.l
[2] = 0l;
3116 ce
.xclient
.data
.l
[3] = 0l;
3117 ce
.xclient
.data
.l
[4] = 0l;
3118 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
3122 ob_debug("%sively focusing %lx at %d\n",
3123 (self
->can_focus
? "act" : "pass"),
3124 self
->window
, (gint
) event_curtime
);
3127 /* Cause the FocusIn to come back to us. Important for desktop switches,
3128 since otherwise we'll have no FocusIn on the queue and send it off to
3129 the focus_backup. */
3130 XSync(ob_display
, FALSE
);
3134 void client_activate(ObClient
*self
, gboolean here
, gboolean user
)
3136 guint32 last_time
= focus_client
? focus_client
->user_time
: CurrentTime
;
3138 /* XXX do some stuff here if user is false to determine if we really want
3139 to activate it or not (a parent or group member is currently
3142 ob_debug_type(OB_DEBUG_FOCUS
,
3143 "Want to activate window 0x%x with time %u (last time %u), "
3145 self
->window
, event_curtime
, last_time
,
3146 (user
? "user" : "application"));
3148 if (!user
&& event_curtime
&& last_time
&&
3149 !event_time_after(event_curtime
, last_time
))
3151 client_hilite(self
, TRUE
);
3153 if (client_normal(self
) && screen_showing_desktop
)
3154 screen_show_desktop(FALSE
);
3156 client_iconify(self
, FALSE
, here
);
3157 if (self
->desktop
!= DESKTOP_ALL
&&
3158 self
->desktop
!= screen_desktop
) {
3160 client_set_desktop(self
, screen_desktop
, FALSE
);
3162 screen_set_desktop(self
->desktop
);
3163 } else if (!self
->frame
->visible
)
3164 /* if its not visible for other reasons, then don't mess
3168 client_shade(self
, FALSE
);
3172 /* we do this an action here. this is rather important. this is because
3173 we want the results from the focus change to take place BEFORE we go
3174 about raising the window. when a fullscreen window loses focus, we
3175 need this or else the raise wont be able to raise above the
3176 to-lose-focus fullscreen window. */
3181 void client_raise(ObClient
*self
)
3183 action_run_string("Raise", self
, CurrentTime
);
3186 void client_lower(ObClient
*self
)
3188 action_run_string("Lower", self
, CurrentTime
);
3191 gboolean
client_focused(ObClient
*self
)
3193 return self
== focus_client
;
3196 static ObClientIcon
* client_icon_recursive(ObClient
*self
, gint w
, gint h
)
3199 /* si is the smallest image >= req */
3200 /* li is the largest image < req */
3201 gulong size
, smallest
= 0xffffffff, largest
= 0, si
= 0, li
= 0;
3203 if (!self
->nicons
) {
3204 ObClientIcon
*parent
= NULL
;
3206 if (self
->transient_for
) {
3207 if (self
->transient_for
!= OB_TRAN_GROUP
)
3208 parent
= client_icon_recursive(self
->transient_for
, w
, h
);
3211 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
3212 ObClient
*c
= it
->data
;
3213 if (c
!= self
&& !c
->transient_for
) {
3214 if ((parent
= client_icon_recursive(c
, w
, h
)))
3224 for (i
= 0; i
< self
->nicons
; ++i
) {
3225 size
= self
->icons
[i
].width
* self
->icons
[i
].height
;
3226 if (size
< smallest
&& size
>= (unsigned)(w
* h
)) {
3230 if (size
> largest
&& size
<= (unsigned)(w
* h
)) {
3235 if (largest
== 0) /* didnt find one smaller than the requested size */
3236 return &self
->icons
[si
];
3237 return &self
->icons
[li
];
3240 const ObClientIcon
* client_icon(ObClient
*self
, gint w
, gint h
)
3243 static ObClientIcon deficon
;
3245 if (!(ret
= client_icon_recursive(self
, w
, h
))) {
3246 deficon
.width
= deficon
.height
= 48;
3247 deficon
.data
= ob_rr_theme
->def_win_icon
;
3253 void client_set_layer(ObClient
*self
, gint layer
)
3257 self
->above
= FALSE
;
3258 } else if (layer
== 0) {
3259 self
->below
= self
->above
= FALSE
;
3261 self
->below
= FALSE
;
3264 client_calc_layer(self
);
3265 client_change_state(self
); /* reflect this in the state hints */
3268 void client_set_undecorated(ObClient
*self
, gboolean undecorated
)
3270 if (self
->undecorated
!= undecorated
) {
3271 self
->undecorated
= undecorated
;
3272 client_setup_decor_and_functions(self
);
3273 /* Make sure the client knows it might have moved. Maybe there is a
3274 * better way of doing this so only one client_configure is sent, but
3275 * since 125 of these are sent per second when moving the window (with
3276 * user = FALSE) i doubt it matters much.
3278 client_configure(self
, OB_CORNER_TOPLEFT
, self
->area
.x
, self
->area
.y
,
3279 self
->area
.width
, self
->area
.height
, TRUE
, TRUE
);
3280 client_change_state(self
); /* reflect this in the state hints */
3284 guint
client_monitor(ObClient
*self
)
3286 return screen_find_monitor(&self
->frame
->area
);
3289 ObClient
*client_search_top_parent(ObClient
*self
)
3291 while (self
->transient_for
&& self
->transient_for
!= OB_TRAN_GROUP
&&
3292 client_normal(self
))
3293 self
= self
->transient_for
;
3297 GSList
*client_search_all_top_parents(ObClient
*self
)
3301 /* move up the direct transient chain as far as possible */
3302 while (self
->transient_for
&& self
->transient_for
!= OB_TRAN_GROUP
)
3303 self
= self
->transient_for
;
3305 if (!self
->transient_for
)
3306 ret
= g_slist_prepend(ret
, self
);
3310 g_assert(self
->group
);
3312 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
3313 ObClient
*c
= it
->data
;
3315 if (!c
->transient_for
&& client_normal(c
))
3316 ret
= g_slist_prepend(ret
, c
);
3319 if (ret
== NULL
) /* no group parents */
3320 ret
= g_slist_prepend(ret
, self
);
3326 ObClient
*client_search_focus_parent(ObClient
*self
)
3328 if (self
->transient_for
) {
3329 if (self
->transient_for
!= OB_TRAN_GROUP
) {
3330 if (client_focused(self
->transient_for
))
3331 return self
->transient_for
;
3335 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
3336 ObClient
*c
= it
->data
;
3338 /* checking transient_for prevents infinate loops! */
3339 if (c
!= self
&& !c
->transient_for
)
3340 if (client_focused(c
))
3349 ObClient
*client_search_parent(ObClient
*self
, ObClient
*search
)
3351 if (self
->transient_for
) {
3352 if (self
->transient_for
!= OB_TRAN_GROUP
) {
3353 if (self
->transient_for
== search
)
3358 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
3359 ObClient
*c
= it
->data
;
3361 /* checking transient_for prevents infinate loops! */
3362 if (c
!= self
&& !c
->transient_for
)
3372 ObClient
*client_search_transient(ObClient
*self
, ObClient
*search
)
3376 for (sit
= self
->transients
; sit
; sit
= g_slist_next(sit
)) {
3377 if (sit
->data
== search
)
3379 if (client_search_transient(sit
->data
, search
))
3385 void client_update_sm_client_id(ObClient
*self
)
3387 g_free(self
->sm_client_id
);
3388 self
->sm_client_id
= NULL
;
3390 if (!PROP_GETS(self
->window
, sm_client_id
, locale
, &self
->sm_client_id
) &&
3392 PROP_GETS(self
->group
->leader
, sm_client_id
, locale
,
3393 &self
->sm_client_id
);
3396 #define WANT_EDGE(cur, c) \
3399 if(!client_normal(cur)) \
3401 if(screen_desktop != cur->desktop && cur->desktop != DESKTOP_ALL) \
3405 if(cur->layer < c->layer && !config_resist_layers_below) \
3408 #define HIT_EDGE(my_edge_start, my_edge_end, his_edge_start, his_edge_end) \
3409 if ((his_edge_start >= my_edge_start && \
3410 his_edge_start <= my_edge_end) || \
3411 (my_edge_start >= his_edge_start && \
3412 my_edge_start <= his_edge_end)) \
3415 /* finds the nearest edge in the given direction from the current client
3416 * note to self: the edge is the -frame- edge (the actual one), not the
3419 gint
client_directional_edge_search(ObClient
*c
, ObDirection dir
, gboolean hang
)
3421 gint dest
, monitor_dest
;
3422 gint my_edge_start
, my_edge_end
, my_offset
;
3429 a
= screen_area(c
->desktop
);
3430 monitor
= screen_area_monitor(c
->desktop
, client_monitor(c
));
3433 case OB_DIRECTION_NORTH
:
3434 my_edge_start
= c
->frame
->area
.x
;
3435 my_edge_end
= c
->frame
->area
.x
+ c
->frame
->area
.width
;
3436 my_offset
= c
->frame
->area
.y
+ (hang
? c
->frame
->area
.height
: 0);
3438 /* default: top of screen */
3439 dest
= a
->y
+ (hang
? c
->frame
->area
.height
: 0);
3440 monitor_dest
= monitor
->y
+ (hang
? c
->frame
->area
.height
: 0);
3441 /* if the monitor edge comes before the screen edge, */
3442 /* use that as the destination instead. (For xinerama) */
3443 if (monitor_dest
!= dest
&& my_offset
> monitor_dest
)
3444 dest
= monitor_dest
;
3446 for(it
= client_list
; it
&& my_offset
!= dest
; it
= g_list_next(it
)) {
3447 gint his_edge_start
, his_edge_end
, his_offset
;
3448 ObClient
*cur
= it
->data
;
3452 his_edge_start
= cur
->frame
->area
.x
;
3453 his_edge_end
= cur
->frame
->area
.x
+ cur
->frame
->area
.width
;
3454 his_offset
= cur
->frame
->area
.y
+
3455 (hang
? 0 : cur
->frame
->area
.height
);
3457 if(his_offset
+ 1 > my_offset
)
3460 if(his_offset
< dest
)
3463 HIT_EDGE(my_edge_start
, my_edge_end
, his_edge_start
, his_edge_end
)
3466 case OB_DIRECTION_SOUTH
:
3467 my_edge_start
= c
->frame
->area
.x
;
3468 my_edge_end
= c
->frame
->area
.x
+ c
->frame
->area
.width
;
3469 my_offset
= c
->frame
->area
.y
+ (hang
? 0 : c
->frame
->area
.height
);
3471 /* default: bottom of screen */
3472 dest
= a
->y
+ a
->height
- (hang
? c
->frame
->area
.height
: 0);
3473 monitor_dest
= monitor
->y
+ monitor
->height
-
3474 (hang
? c
->frame
->area
.height
: 0);
3475 /* if the monitor edge comes before the screen edge, */
3476 /* use that as the destination instead. (For xinerama) */
3477 if (monitor_dest
!= dest
&& my_offset
< monitor_dest
)
3478 dest
= monitor_dest
;
3480 for(it
= client_list
; it
&& my_offset
!= dest
; it
= g_list_next(it
)) {
3481 gint his_edge_start
, his_edge_end
, his_offset
;
3482 ObClient
*cur
= it
->data
;
3486 his_edge_start
= cur
->frame
->area
.x
;
3487 his_edge_end
= cur
->frame
->area
.x
+ cur
->frame
->area
.width
;
3488 his_offset
= cur
->frame
->area
.y
+
3489 (hang
? cur
->frame
->area
.height
: 0);
3492 if(his_offset
- 1 < my_offset
)
3495 if(his_offset
> dest
)
3498 HIT_EDGE(my_edge_start
, my_edge_end
, his_edge_start
, his_edge_end
)
3501 case OB_DIRECTION_WEST
:
3502 my_edge_start
= c
->frame
->area
.y
;
3503 my_edge_end
= c
->frame
->area
.y
+ c
->frame
->area
.height
;
3504 my_offset
= c
->frame
->area
.x
+ (hang
? c
->frame
->area
.width
: 0);
3506 /* default: leftmost egde of screen */
3507 dest
= a
->x
+ (hang
? c
->frame
->area
.width
: 0);
3508 monitor_dest
= monitor
->x
+ (hang
? c
->frame
->area
.width
: 0);
3509 /* if the monitor edge comes before the screen edge, */
3510 /* use that as the destination instead. (For xinerama) */
3511 if (monitor_dest
!= dest
&& my_offset
> monitor_dest
)
3512 dest
= monitor_dest
;
3514 for(it
= client_list
; it
&& my_offset
!= dest
; it
= g_list_next(it
)) {
3515 gint his_edge_start
, his_edge_end
, his_offset
;
3516 ObClient
*cur
= it
->data
;
3520 his_edge_start
= cur
->frame
->area
.y
;
3521 his_edge_end
= cur
->frame
->area
.y
+ cur
->frame
->area
.height
;
3522 his_offset
= cur
->frame
->area
.x
+
3523 (hang
? 0 : cur
->frame
->area
.width
);
3525 if(his_offset
+ 1 > my_offset
)
3528 if(his_offset
< dest
)
3531 HIT_EDGE(my_edge_start
, my_edge_end
, his_edge_start
, his_edge_end
)
3534 case OB_DIRECTION_EAST
:
3535 my_edge_start
= c
->frame
->area
.y
;
3536 my_edge_end
= c
->frame
->area
.y
+ c
->frame
->area
.height
;
3537 my_offset
= c
->frame
->area
.x
+ (hang
? 0 : c
->frame
->area
.width
);
3539 /* default: rightmost edge of screen */
3540 dest
= a
->x
+ a
->width
- (hang
? c
->frame
->area
.width
: 0);
3541 monitor_dest
= monitor
->x
+ monitor
->width
-
3542 (hang
? c
->frame
->area
.width
: 0);
3543 /* if the monitor edge comes before the screen edge, */
3544 /* use that as the destination instead. (For xinerama) */
3545 if (monitor_dest
!= dest
&& my_offset
< monitor_dest
)
3546 dest
= monitor_dest
;
3548 for(it
= client_list
; it
&& my_offset
!= dest
; it
= g_list_next(it
)) {
3549 gint his_edge_start
, his_edge_end
, his_offset
;
3550 ObClient
*cur
= it
->data
;
3554 his_edge_start
= cur
->frame
->area
.y
;
3555 his_edge_end
= cur
->frame
->area
.y
+ cur
->frame
->area
.height
;
3556 his_offset
= cur
->frame
->area
.x
+
3557 (hang
? cur
->frame
->area
.width
: 0);
3559 if(his_offset
- 1 < my_offset
)
3562 if(his_offset
> dest
)
3565 HIT_EDGE(my_edge_start
, my_edge_end
, his_edge_start
, his_edge_end
)
3568 case OB_DIRECTION_NORTHEAST
:
3569 case OB_DIRECTION_SOUTHEAST
:
3570 case OB_DIRECTION_NORTHWEST
:
3571 case OB_DIRECTION_SOUTHWEST
:
3572 /* not implemented */
3574 g_assert_not_reached();
3575 dest
= 0; /* suppress warning */
3580 ObClient
* client_under_pointer()
3584 ObClient
*ret
= NULL
;
3586 if (screen_pointer_pos(&x
, &y
)) {
3587 for (it
= stacking_list
; it
; it
= g_list_next(it
)) {
3588 if (WINDOW_IS_CLIENT(it
->data
)) {
3589 ObClient
*c
= WINDOW_AS_CLIENT(it
->data
);
3590 if (c
->frame
->visible
&&
3591 RECT_CONTAINS(c
->frame
->area
, x
, y
)) {
3601 gboolean
client_has_group_siblings(ObClient
*self
)
3603 return self
->group
&& self
->group
->members
->next
;