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
&&
324 /* this means focus=true for window is same as config_focus_new=true */
325 ((config_focus_new
|| (settings
&& settings
->focus
== 1)) ||
326 client_search_focus_parent(self
)) &&
327 /* this checks for focus=false for the window */
328 (!settings
|| settings
->focus
!= 0) &&
329 /* note the check against Type_Normal/Dialog, not client_normal(self),
330 which would also include other types. in this case we want more
331 strict rules for focus */
332 (self
->type
== OB_CLIENT_TYPE_NORMAL
||
333 self
->type
== OB_CLIENT_TYPE_DIALOG
))
338 /* get the current position */
342 /* figure out placement for the window */
343 if (ob_state() == OB_STATE_RUNNING
) {
346 transient
= place_client(self
, &newx
, &newy
, settings
);
348 /* make sure the window is visible. */
349 client_find_onscreen(self
, &newx
, &newy
,
350 self
->frame
->area
.width
,
351 self
->frame
->area
.height
,
352 /* non-normal clients has less rules, and
353 windows that are being restored from a
354 session do also. we can assume you want
355 it back where you saved it. Clients saying
356 they placed themselves are subjected to
357 harder rules, ones that are placed by
358 place.c or by the user are allowed partially
359 off-screen and on xinerama divides (ie,
360 it is up to the placement routines to avoid
361 the xinerama divides) */
363 (((self
->positioned
& PPosition
) &&
364 !(self
->positioned
& USPosition
)) &&
365 client_normal(self
) &&
369 /* do this after the window is placed, so the premax/prefullscreen numbers
371 also, this moves the window to the position where it has been placed
373 ob_debug("placing window 0x%x at %d, %d with size %d x %d\n",
374 self
->window
, newx
, newy
, self
->area
.width
, self
->area
.height
);
375 client_apply_startup_state(self
, newx
, newy
);
377 keyboard_grab_for_client(self
, TRUE
);
378 mouse_grab_for_client(self
, TRUE
);
381 guint32 last_time
= focus_client
?
382 focus_client
->user_time
: CurrentTime
;
384 /* This is focus stealing prevention */
385 ob_debug("Want to focus new window 0x%x with time %u (last time %u)\n",
386 self
->window
, self
->user_time
, last_time
);
388 /* If a nothing at all, or a parent was focused, then focus this
391 if (!focus_client
|| client_search_focus_parent(self
) != NULL
)
395 /* If time stamp is old, don't steal focus */
396 if (self
->user_time
&& last_time
&&
397 !event_time_after(self
->user_time
, last_time
))
401 /* Don't steal focus from globally active clients.
402 I stole this idea from KWin. It seems nice.
404 if (!(focus_client
->can_focus
|| focus_client
->focus_notify
))
409 ob_debug("Focus stealing prevention activated for %s with time %u "
411 self
->title
, self
->user_time
, last_time
);
412 /* if the client isn't focused, then hilite it so the user
414 client_hilite(self
, TRUE
);
418 /* This may look rather odd. Well it's because new windows are added
419 to the stacking order non-intrusively. If we're not going to focus
420 the new window or hilite it, then we raise it to the top. This will
421 take affect for things that don't get focused like splash screens.
422 Also if you don't have focus_new enabled, then it's going to get
423 raised to the top. Legacy begets legacy I guess?
428 /* this has to happen before we try focus the window, but we want it to
429 happen after the client's stacking has been determined or it looks bad
433 /* use client_focus instead of client_activate cuz client_activate does
434 stuff like switch desktops etc and I'm not interested in all that when
435 a window maps since its not based on an action from the user like
436 clicking a window to activate it. so keep the new window out of the way
439 client_activate(self
, FALSE
, TRUE
);
441 /* add to client list/map */
442 client_list
= g_list_append(client_list
, self
);
443 g_hash_table_insert(window_map
, &self
->window
, self
);
445 /* this has to happen after we're in the client_list */
446 if (STRUT_EXISTS(self
->strut
))
447 screen_update_areas();
449 /* update the list hints */
452 ob_debug("Managed window 0x%lx (%s)\n", window
, self
->class);
455 void client_unmanage_all()
457 while (client_list
!= NULL
)
458 client_unmanage(client_list
->data
);
461 void client_unmanage(ObClient
*self
)
466 ob_debug("Unmanaging window: %lx (%s) (%s)\n", self
->window
, self
->class,
467 self
->title
? self
->title
: "");
469 g_assert(self
!= NULL
);
471 /* we dont want events no more. do this before hiding the frame so we
472 don't generate more events */
473 XSelectInput(ob_display
, self
->window
, NoEventMask
);
475 frame_hide(self
->frame
);
476 /* flush to send the hide to the server quickly */
479 if (focus_client
== self
) {
480 /* ignore enter events from the unmap so it doesnt mess with the focus
482 event_ignore_queued_enters();
485 keyboard_grab_for_client(self
, FALSE
);
486 mouse_grab_for_client(self
, FALSE
);
488 /* remove the window from our save set */
489 XChangeSaveSet(ob_display
, self
->window
, SetModeDelete
);
491 /* update the focus lists */
492 focus_order_remove(self
);
493 /* don't leave an invalid focus_client */
494 if (self
== focus_client
)
497 client_list
= g_list_remove(client_list
, self
);
498 stacking_remove(self
);
499 g_hash_table_remove(window_map
, &self
->window
);
501 /* once the client is out of the list, update the struts to remove its
503 if (STRUT_EXISTS(self
->strut
))
504 screen_update_areas();
506 for (it
= client_destructors
; it
; it
= g_slist_next(it
)) {
507 Destructor
*d
= it
->data
;
508 d
->func(self
, d
->data
);
511 /* tell our parent(s) that we're gone */
512 if (self
->transient_for
== OB_TRAN_GROUP
) { /* transient of group */
513 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
))
514 if (it
->data
!= self
)
515 ((ObClient
*)it
->data
)->transients
=
516 g_slist_remove(((ObClient
*)it
->data
)->transients
, self
);
517 } else if (self
->transient_for
) { /* transient of window */
518 self
->transient_for
->transients
=
519 g_slist_remove(self
->transient_for
->transients
, self
);
522 /* tell our transients that we're gone */
523 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
524 if (((ObClient
*)it
->data
)->transient_for
!= OB_TRAN_GROUP
) {
525 ((ObClient
*)it
->data
)->transient_for
= NULL
;
526 client_calc_layer(it
->data
);
530 /* remove from its group */
532 group_remove(self
->group
, self
);
536 /* restore the window's original geometry so it is not lost */
540 if (self
->fullscreen
)
541 a
= self
->pre_fullscreen_area
;
542 else if (self
->max_horz
|| self
->max_vert
) {
543 if (self
->max_horz
) {
544 a
.x
= self
->pre_max_area
.x
;
545 a
.width
= self
->pre_max_area
.width
;
547 if (self
->max_vert
) {
548 a
.y
= self
->pre_max_area
.y
;
549 a
.height
= self
->pre_max_area
.height
;
553 /* give the client its border back */
554 client_toggle_border(self
, TRUE
);
556 self
->fullscreen
= self
->max_horz
= self
->max_vert
= FALSE
;
557 self
->decorations
= 0; /* unmanaged windows have no decor */
559 client_move_resize(self
, a
.x
, a
.y
, a
.width
, a
.height
);
562 /* reparent the window out of the frame, and free the frame */
563 frame_release_client(self
->frame
, self
);
566 if (ob_state() != OB_STATE_EXITING
) {
567 /* these values should not be persisted across a window
569 PROP_ERASE(self
->window
, net_wm_desktop
);
570 PROP_ERASE(self
->window
, net_wm_state
);
571 PROP_ERASE(self
->window
, wm_state
);
573 /* if we're left in an unmapped state, the client wont be mapped. this
574 is bad, since we will no longer be managing the window on restart */
575 XMapWindow(ob_display
, self
->window
);
578 ob_debug("Unmanaged window 0x%lx\n", self
->window
);
580 /* free all data allocated in the client struct */
581 g_slist_free(self
->transients
);
582 for (j
= 0; j
< self
->nicons
; ++j
)
583 g_free(self
->icons
[j
].data
);
584 if (self
->nicons
> 0)
587 g_free(self
->icon_title
);
591 g_free(self
->client_machine
);
592 g_free(self
->sm_client_id
);
595 /* update the list hints */
599 static ObAppSettings
*client_get_settings_state(ObClient
*self
)
601 ObAppSettings
*settings
= NULL
;
604 for (it
= config_per_app_settings
; it
; it
= g_slist_next(it
)) {
605 ObAppSettings
*app
= it
->data
;
607 if ((app
->name
&& !app
->class && !strcmp(app
->name
, self
->name
))
608 || (app
->class && !app
->name
&& !strcmp(app
->class, self
->class))
609 || (app
->class && app
->name
&& !strcmp(app
->class, self
->class)
610 && !strcmp(app
->name
, self
->name
)))
612 ob_debug("Window matching: %s\n", app
->name
);
613 /* Match if no role was specified in the per app setting, or if the
614 * string matches the beginning of the role, since apps like to set
615 * the role to things like browser-window-23c4b2f */
617 || !strncmp(app
->role
, self
->role
, strlen(app
->role
)))
627 if (settings
->shade
!= -1)
628 self
->shaded
= !!settings
->shade
;
629 if (settings
->decor
!= -1)
630 self
->undecorated
= !settings
->decor
;
631 if (settings
->iconic
!= -1)
632 self
->iconic
= !!settings
->iconic
;
633 if (settings
->skip_pager
!= -1)
634 self
->skip_pager
= !!settings
->skip_pager
;
635 if (settings
->skip_taskbar
!= -1)
636 self
->skip_taskbar
= !!settings
->skip_taskbar
;
638 if (settings
->max_vert
!= -1)
639 self
->max_vert
= !!settings
->max_vert
;
640 if (settings
->max_horz
!= -1)
641 self
->max_horz
= !!settings
->max_horz
;
643 if (settings
->fullscreen
!= -1)
644 self
->fullscreen
= !!settings
->fullscreen
;
646 if (settings
->desktop
< screen_num_desktops
647 || settings
->desktop
== DESKTOP_ALL
)
648 self
->desktop
= settings
->desktop
;
650 if (settings
->layer
== -1) {
654 else if (settings
->layer
== 0) {
658 else if (settings
->layer
== 1) {
666 static void client_restore_session_state(ObClient
*self
)
670 if (!(it
= session_state_find(self
)))
673 self
->session
= it
->data
;
675 RECT_SET_POINT(self
->area
, self
->session
->x
, self
->session
->y
);
676 self
->positioned
= PPosition
;
677 if (self
->session
->w
> 0)
678 self
->area
.width
= self
->session
->w
;
679 if (self
->session
->h
> 0)
680 self
->area
.height
= self
->session
->h
;
681 XResizeWindow(ob_display
, self
->window
,
682 self
->area
.width
, self
->area
.height
);
684 self
->desktop
= (self
->session
->desktop
== DESKTOP_ALL
?
685 self
->session
->desktop
:
686 MIN(screen_num_desktops
- 1, self
->session
->desktop
));
687 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, self
->desktop
);
689 self
->shaded
= self
->session
->shaded
;
690 self
->iconic
= self
->session
->iconic
;
691 self
->skip_pager
= self
->session
->skip_pager
;
692 self
->skip_taskbar
= self
->session
->skip_taskbar
;
693 self
->fullscreen
= self
->session
->fullscreen
;
694 self
->above
= self
->session
->above
;
695 self
->below
= self
->session
->below
;
696 self
->max_horz
= self
->session
->max_horz
;
697 self
->max_vert
= self
->session
->max_vert
;
700 static void client_restore_session_stacking(ObClient
*self
)
704 if (!self
->session
) return;
706 it
= g_list_find(session_saved_state
, self
->session
);
707 for (it
= g_list_previous(it
); it
; it
= g_list_previous(it
)) {
710 for (cit
= client_list
; cit
; cit
= g_list_next(cit
))
711 if (session_state_cmp(it
->data
, cit
->data
))
714 client_calc_layer(self
);
715 stacking_below(CLIENT_AS_WINDOW(self
),
716 CLIENT_AS_WINDOW(cit
->data
));
722 void client_move_onscreen(ObClient
*self
, gboolean rude
)
724 gint x
= self
->area
.x
;
725 gint y
= self
->area
.y
;
726 if (client_find_onscreen(self
, &x
, &y
,
727 self
->frame
->area
.width
,
728 self
->frame
->area
.height
, rude
)) {
729 client_move(self
, x
, y
);
733 gboolean
client_find_onscreen(ObClient
*self
, gint
*x
, gint
*y
, gint w
, gint h
,
737 gint ox
= *x
, oy
= *y
;
739 frame_client_gravity(self
->frame
, x
, y
); /* get where the frame
742 /* XXX watch for xinerama dead areas */
743 /* This makes sure windows aren't entirely outside of the screen so you
744 can't see them at all.
745 It makes sure 10% of the window is on the screen at least. At don't let
746 it move itself off the top of the screen, which would hide the titlebar
747 on you. (The user can still do this if they want too, it's only limiting
750 if (client_normal(self
)) {
751 a
= screen_area(self
->desktop
);
752 if (!self
->strut
.right
&&
753 *x
+ self
->frame
->area
.width
/10 >= a
->x
+ a
->width
- 1)
754 *x
= a
->x
+ a
->width
- self
->frame
->area
.width
/10;
755 if (!self
->strut
.bottom
&&
756 *y
+ self
->frame
->area
.height
/10 >= a
->y
+ a
->height
- 1)
757 *y
= a
->y
+ a
->height
- self
->frame
->area
.height
/10;
758 if (!self
->strut
.left
&& *x
+ self
->frame
->area
.width
*9/10 - 1 < a
->x
)
759 *x
= a
->x
- self
->frame
->area
.width
*9/10;
760 if (!self
->strut
.top
&& *y
+ self
->frame
->area
.height
*9/10 - 1 < a
->y
)
761 *y
= a
->y
- self
->frame
->area
.width
*9/10;
764 /* This here doesn't let windows even a pixel outside the screen,
765 * when called from client_manage, programs placing themselves are
766 * forced completely onscreen, while things like
767 * xterm -geometry resolution-width/2 will work fine. Trying to
768 * place it completely offscreen will be handled in the above code.
769 * Sorry for this confused comment, i am tired. */
771 /* avoid the xinerama monitor divide while we're at it,
772 * remember to fix the placement stuff to avoid it also and
773 * then remove this XXX */
774 a
= screen_area_monitor(self
->desktop
, client_monitor(self
));
775 /* dont let windows map into the strut unless they
776 are bigger than the available area */
778 if (!self
->strut
.left
&& *x
< a
->x
) *x
= a
->x
;
779 if (!self
->strut
.right
&& *x
+ w
> a
->x
+ a
->width
)
780 *x
= a
->x
+ a
->width
- w
;
782 if (h
<= a
->height
) {
783 if (!self
->strut
.top
&& *y
< a
->y
) *y
= a
->y
;
784 if (!self
->strut
.bottom
&& *y
+ h
> a
->y
+ a
->height
)
785 *y
= a
->y
+ a
->height
- h
;
789 frame_frame_gravity(self
->frame
, x
, y
); /* get where the client
792 return ox
!= *x
|| oy
!= *y
;
795 static void client_toggle_border(ObClient
*self
, gboolean show
)
797 /* adjust our idea of where the client is, based on its border. When the
798 border is removed, the client should now be considered to be in a
800 when re-adding the border to the client, the same operation needs to be
802 gint oldx
= self
->area
.x
, oldy
= self
->area
.y
;
803 gint x
= oldx
, y
= oldy
;
804 switch(self
->gravity
) {
806 case NorthWestGravity
:
808 case SouthWestGravity
:
810 case NorthEastGravity
:
812 case SouthEastGravity
:
813 if (show
) x
-= self
->border_width
* 2;
814 else x
+= self
->border_width
* 2;
821 if (show
) x
-= self
->border_width
;
822 else x
+= self
->border_width
;
825 switch(self
->gravity
) {
827 case NorthWestGravity
:
829 case NorthEastGravity
:
831 case SouthWestGravity
:
833 case SouthEastGravity
:
834 if (show
) y
-= self
->border_width
* 2;
835 else y
+= self
->border_width
* 2;
842 if (show
) y
-= self
->border_width
;
843 else y
+= self
->border_width
;
850 XSetWindowBorderWidth(ob_display
, self
->window
, self
->border_width
);
852 /* set border_width to 0 because there is no border to add into
853 calculations anymore */
854 self
->border_width
= 0;
856 XSetWindowBorderWidth(ob_display
, self
->window
, 0);
860 static void client_get_all(ObClient
*self
)
862 client_get_area(self
);
863 client_get_mwm_hints(self
);
865 /* The transient hint is used to pick a type, but the type can also affect
866 transiency (dialogs are always made transients of their group if they
867 have one). This is Havoc's idea, but it is needed to make some apps
868 work right (eg tsclient). */
869 client_update_transient_for(self
);
870 client_get_type(self
);/* this can change the mwmhints for special cases */
871 client_get_state(self
);
872 client_update_transient_for(self
);
874 client_update_wmhints(self
);
875 client_get_startup_id(self
);
876 client_get_desktop(self
);/* uses transient data/group/startup id if a
877 desktop is not specified */
878 client_get_shaped(self
);
880 client_get_layer(self
); /* if layer hasn't been specified, get it from
881 other sources if possible */
884 /* a couple type-based defaults for new windows */
886 /* this makes sure that these windows appear on all desktops */
887 if (self
->type
== OB_CLIENT_TYPE_DESKTOP
)
888 self
->desktop
= DESKTOP_ALL
;
891 client_update_protocols(self
);
893 client_get_gravity(self
); /* get the attribute gravity */
894 client_update_normal_hints(self
); /* this may override the attribute
897 /* got the type, the mwmhints, the protocols, and the normal hints
898 (min/max sizes), so we're ready to set up the decorations/functions */
899 client_setup_decor_and_functions(self
);
902 client_update_sync_request_counter(self
);
904 client_get_client_machine(self
);
905 client_get_colormap(self
);
906 client_update_title(self
);
907 client_update_class(self
);
908 client_update_sm_client_id(self
);
909 client_update_strut(self
);
910 client_update_icons(self
);
911 client_update_user_time(self
);
914 static void client_get_startup_id(ObClient
*self
)
916 if (!(PROP_GETS(self
->window
, net_startup_id
, utf8
, &self
->startup_id
)))
918 PROP_GETS(self
->group
->leader
,
919 net_startup_id
, utf8
, &self
->startup_id
);
922 static void client_get_area(ObClient
*self
)
924 XWindowAttributes wattrib
;
927 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
928 g_assert(ret
!= BadWindow
);
930 RECT_SET(self
->area
, wattrib
.x
, wattrib
.y
, wattrib
.width
, wattrib
.height
);
931 POINT_SET(self
->root_pos
, wattrib
.x
, wattrib
.y
);
932 self
->border_width
= wattrib
.border_width
;
934 ob_debug("client area: %d %d %d %d\n", wattrib
.x
, wattrib
.y
,
935 wattrib
.width
, wattrib
.height
);
938 static void client_get_desktop(ObClient
*self
)
940 guint32 d
= screen_num_desktops
; /* an always-invalid value */
942 if (PROP_GET32(self
->window
, net_wm_desktop
, cardinal
, &d
)) {
943 if (d
>= screen_num_desktops
&& d
!= DESKTOP_ALL
)
944 self
->desktop
= screen_num_desktops
- 1;
948 gboolean trdesk
= FALSE
;
950 if (self
->transient_for
) {
951 if (self
->transient_for
!= OB_TRAN_GROUP
) {
952 self
->desktop
= self
->transient_for
->desktop
;
957 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
))
958 if (it
->data
!= self
&&
959 !((ObClient
*)it
->data
)->transient_for
) {
960 self
->desktop
= ((ObClient
*)it
->data
)->desktop
;
967 /* try get from the startup-notification protocol */
968 if (sn_get_desktop(self
->startup_id
, &self
->desktop
)) {
969 if (self
->desktop
>= screen_num_desktops
&&
970 self
->desktop
!= DESKTOP_ALL
)
971 self
->desktop
= screen_num_desktops
- 1;
973 /* defaults to the current desktop */
974 self
->desktop
= screen_desktop
;
979 static void client_get_layer(ObClient
*self
)
981 if (!(self
->above
|| self
->below
)) {
983 /* apply stuff from the group */
987 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
988 ObClient
*c
= it
->data
;
989 if (c
!= self
&& !client_search_transient(self
, c
) &&
990 client_normal(self
) && client_normal(c
))
993 (c
->above
? 1 : (c
->below
? -1 : 0)));
1007 g_assert_not_reached();
1014 static void client_get_state(ObClient
*self
)
1019 if (PROP_GETA32(self
->window
, net_wm_state
, atom
, &state
, &num
)) {
1021 for (i
= 0; i
< num
; ++i
) {
1022 if (state
[i
] == prop_atoms
.net_wm_state_modal
)
1024 else if (state
[i
] == prop_atoms
.net_wm_state_shaded
)
1025 self
->shaded
= TRUE
;
1026 else if (state
[i
] == prop_atoms
.net_wm_state_hidden
)
1027 self
->iconic
= TRUE
;
1028 else if (state
[i
] == prop_atoms
.net_wm_state_skip_taskbar
)
1029 self
->skip_taskbar
= TRUE
;
1030 else if (state
[i
] == prop_atoms
.net_wm_state_skip_pager
)
1031 self
->skip_pager
= TRUE
;
1032 else if (state
[i
] == prop_atoms
.net_wm_state_fullscreen
)
1033 self
->fullscreen
= TRUE
;
1034 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_vert
)
1035 self
->max_vert
= TRUE
;
1036 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_horz
)
1037 self
->max_horz
= TRUE
;
1038 else if (state
[i
] == prop_atoms
.net_wm_state_above
)
1040 else if (state
[i
] == prop_atoms
.net_wm_state_below
)
1042 else if (state
[i
] == prop_atoms
.net_wm_state_demands_attention
)
1043 self
->demands_attention
= TRUE
;
1044 else if (state
[i
] == prop_atoms
.ob_wm_state_undecorated
)
1045 self
->undecorated
= TRUE
;
1052 static void client_get_shaped(ObClient
*self
)
1054 self
->shaped
= FALSE
;
1056 if (extensions_shape
) {
1061 XShapeSelectInput(ob_display
, self
->window
, ShapeNotifyMask
);
1063 XShapeQueryExtents(ob_display
, self
->window
, &s
, &foo
,
1064 &foo
, &ufoo
, &ufoo
, &foo
, &foo
, &foo
, &ufoo
,
1066 self
->shaped
= (s
!= 0);
1071 void client_update_transient_for(ObClient
*self
)
1074 ObClient
*target
= NULL
;
1076 if (XGetTransientForHint(ob_display
, self
->window
, &t
)) {
1077 self
->transient
= TRUE
;
1078 if (t
!= self
->window
) { /* cant be transient to itself! */
1079 target
= g_hash_table_lookup(window_map
, &t
);
1080 /* if this happens then we need to check for it*/
1081 g_assert(target
!= self
);
1082 if (target
&& !WINDOW_IS_CLIENT(target
)) {
1083 /* this can happen when a dialog is a child of
1084 a dockapp, for example */
1088 /* THIS IS SO ANNOYING ! ! ! ! Let me explain.... have a seat..
1090 Setting the transient_for to Root is actually illegal, however
1091 applications from time have done this to specify transient for
1094 Now you can do that by being a TYPE_DIALOG and not setting
1095 the transient_for hint at all on your window. But people still
1096 use Root, and Kwin is very strange in this regard.
1098 KWin 3.0 will not consider windows with transient_for set to
1099 Root as transient for their group *UNLESS* they are also modal.
1100 In that case, it will make them transient for the group. This
1101 leads to all sorts of weird behavior from KDE apps which are
1102 only tested in KWin. I'd like to follow their behavior just to
1103 make this work right with KDE stuff, but that seems wrong.
1105 if (!target
&& self
->group
) {
1106 /* not transient to a client, see if it is transient for a
1108 if (t
== RootWindow(ob_display
, ob_screen
)) {
1109 /* window is a transient for its group! */
1110 target
= OB_TRAN_GROUP
;
1114 } else if (self
->group
) {
1115 if (self
->type
== OB_CLIENT_TYPE_DIALOG
||
1116 self
->type
== OB_CLIENT_TYPE_TOOLBAR
||
1117 self
->type
== OB_CLIENT_TYPE_MENU
||
1118 self
->type
== OB_CLIENT_TYPE_UTILITY
)
1120 self
->transient
= TRUE
;
1121 target
= OB_TRAN_GROUP
;
1124 self
->transient
= FALSE
;
1126 /* if anything has changed... */
1127 if (target
!= self
->transient_for
) {
1128 if (self
->transient_for
== OB_TRAN_GROUP
) { /* transient of group */
1131 /* remove from old parents */
1132 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
1133 ObClient
*c
= it
->data
;
1134 if (c
!= self
&& !c
->transient_for
)
1135 c
->transients
= g_slist_remove(c
->transients
, self
);
1137 } else if (self
->transient_for
!= NULL
) { /* transient of window */
1138 /* remove from old parent */
1139 self
->transient_for
->transients
=
1140 g_slist_remove(self
->transient_for
->transients
, self
);
1142 self
->transient_for
= target
;
1143 if (self
->transient_for
== OB_TRAN_GROUP
) { /* transient of group */
1146 /* add to new parents */
1147 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
1148 ObClient
*c
= it
->data
;
1149 if (c
!= self
&& !c
->transient_for
)
1150 c
->transients
= g_slist_append(c
->transients
, self
);
1153 /* remove all transients which are in the group, that causes
1154 circlular pointer hell of doom */
1155 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
1157 for (sit
= self
->transients
; sit
; sit
= next
) {
1158 next
= g_slist_next(sit
);
1159 if (sit
->data
== it
->data
)
1161 g_slist_delete_link(self
->transients
, sit
);
1164 } else if (self
->transient_for
!= NULL
) { /* transient of window */
1165 /* add to new parent */
1166 self
->transient_for
->transients
=
1167 g_slist_append(self
->transient_for
->transients
, self
);
1172 static void client_get_mwm_hints(ObClient
*self
)
1177 self
->mwmhints
.flags
= 0; /* default to none */
1179 if (PROP_GETA32(self
->window
, motif_wm_hints
, motif_wm_hints
,
1181 if (num
>= OB_MWM_ELEMENTS
) {
1182 self
->mwmhints
.flags
= hints
[0];
1183 self
->mwmhints
.functions
= hints
[1];
1184 self
->mwmhints
.decorations
= hints
[2];
1190 void client_get_type(ObClient
*self
)
1197 if (PROP_GETA32(self
->window
, net_wm_window_type
, atom
, &val
, &num
)) {
1198 /* use the first value that we know about in the array */
1199 for (i
= 0; i
< num
; ++i
) {
1200 if (val
[i
] == prop_atoms
.net_wm_window_type_desktop
)
1201 self
->type
= OB_CLIENT_TYPE_DESKTOP
;
1202 else if (val
[i
] == prop_atoms
.net_wm_window_type_dock
)
1203 self
->type
= OB_CLIENT_TYPE_DOCK
;
1204 else if (val
[i
] == prop_atoms
.net_wm_window_type_toolbar
)
1205 self
->type
= OB_CLIENT_TYPE_TOOLBAR
;
1206 else if (val
[i
] == prop_atoms
.net_wm_window_type_menu
)
1207 self
->type
= OB_CLIENT_TYPE_MENU
;
1208 else if (val
[i
] == prop_atoms
.net_wm_window_type_utility
)
1209 self
->type
= OB_CLIENT_TYPE_UTILITY
;
1210 else if (val
[i
] == prop_atoms
.net_wm_window_type_splash
)
1211 self
->type
= OB_CLIENT_TYPE_SPLASH
;
1212 else if (val
[i
] == prop_atoms
.net_wm_window_type_dialog
)
1213 self
->type
= OB_CLIENT_TYPE_DIALOG
;
1214 else if (val
[i
] == prop_atoms
.net_wm_window_type_normal
)
1215 self
->type
= OB_CLIENT_TYPE_NORMAL
;
1216 else if (val
[i
] == prop_atoms
.kde_net_wm_window_type_override
) {
1217 /* prevent this window from getting any decor or
1219 self
->mwmhints
.flags
&= (OB_MWM_FLAG_FUNCTIONS
|
1220 OB_MWM_FLAG_DECORATIONS
);
1221 self
->mwmhints
.decorations
= 0;
1222 self
->mwmhints
.functions
= 0;
1224 if (self
->type
!= (ObClientType
) -1)
1225 break; /* grab the first legit type */
1230 if (self
->type
== (ObClientType
) -1) {
1231 /*the window type hint was not set, which means we either classify
1232 ourself as a normal window or a dialog, depending on if we are a
1234 if (self
->transient
)
1235 self
->type
= OB_CLIENT_TYPE_DIALOG
;
1237 self
->type
= OB_CLIENT_TYPE_NORMAL
;
1241 void client_update_protocols(ObClient
*self
)
1244 guint num_return
, i
;
1246 self
->focus_notify
= FALSE
;
1247 self
->delete_window
= FALSE
;
1249 if (PROP_GETA32(self
->window
, wm_protocols
, atom
, &proto
, &num_return
)) {
1250 for (i
= 0; i
< num_return
; ++i
) {
1251 if (proto
[i
] == prop_atoms
.wm_delete_window
)
1252 /* this means we can request the window to close */
1253 self
->delete_window
= TRUE
;
1254 else if (proto
[i
] == prop_atoms
.wm_take_focus
)
1255 /* if this protocol is requested, then the window will be
1256 notified whenever we want it to receive focus */
1257 self
->focus_notify
= TRUE
;
1259 else if (proto
[i
] == prop_atoms
.net_wm_sync_request
)
1260 /* if this protocol is requested, then resizing the
1261 window will be synchronized between the frame and the
1263 self
->sync_request
= TRUE
;
1271 void client_update_sync_request_counter(ObClient
*self
)
1275 if (PROP_GET32(self
->window
, net_wm_sync_request_counter
, cardinal
, &i
)) {
1276 self
->sync_counter
= i
;
1278 self
->sync_counter
= None
;
1282 static void client_get_gravity(ObClient
*self
)
1284 XWindowAttributes wattrib
;
1287 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
1288 g_assert(ret
!= BadWindow
);
1289 self
->gravity
= wattrib
.win_gravity
;
1292 void client_get_colormap(ObClient
*self
)
1294 XWindowAttributes wa
;
1296 if (XGetWindowAttributes(ob_display
, self
->window
, &wa
))
1297 client_update_colormap(self
, wa
.colormap
);
1300 void client_update_colormap(ObClient
*self
, Colormap colormap
)
1302 self
->colormap
= colormap
;
1305 void client_update_normal_hints(ObClient
*self
)
1309 gint oldgravity
= self
->gravity
;
1312 self
->min_ratio
= 0.0f
;
1313 self
->max_ratio
= 0.0f
;
1314 SIZE_SET(self
->size_inc
, 1, 1);
1315 SIZE_SET(self
->base_size
, 0, 0);
1316 SIZE_SET(self
->min_size
, 0, 0);
1317 SIZE_SET(self
->max_size
, G_MAXINT
, G_MAXINT
);
1319 /* get the hints from the window */
1320 if (XGetWMNormalHints(ob_display
, self
->window
, &size
, &ret
)) {
1321 /* normal windows can't request placement! har har
1322 if (!client_normal(self))
1324 self
->positioned
= (size
.flags
& (PPosition
|USPosition
));
1326 if (size
.flags
& PWinGravity
) {
1327 self
->gravity
= size
.win_gravity
;
1329 /* if the client has a frame, i.e. has already been mapped and
1330 is changing its gravity */
1331 if (self
->frame
&& self
->gravity
!= oldgravity
) {
1332 /* move our idea of the client's position based on its new
1334 self
->area
.x
= self
->frame
->area
.x
;
1335 self
->area
.y
= self
->frame
->area
.y
;
1336 frame_frame_gravity(self
->frame
, &self
->area
.x
, &self
->area
.y
);
1340 if (size
.flags
& PAspect
) {
1341 if (size
.min_aspect
.y
)
1343 (gfloat
) size
.min_aspect
.x
/ size
.min_aspect
.y
;
1344 if (size
.max_aspect
.y
)
1346 (gfloat
) size
.max_aspect
.x
/ size
.max_aspect
.y
;
1349 if (size
.flags
& PMinSize
)
1350 SIZE_SET(self
->min_size
, size
.min_width
, size
.min_height
);
1352 if (size
.flags
& PMaxSize
)
1353 SIZE_SET(self
->max_size
, size
.max_width
, size
.max_height
);
1355 if (size
.flags
& PBaseSize
)
1356 SIZE_SET(self
->base_size
, size
.base_width
, size
.base_height
);
1358 if (size
.flags
& PResizeInc
&& size
.width_inc
&& size
.height_inc
)
1359 SIZE_SET(self
->size_inc
, size
.width_inc
, size
.height_inc
);
1363 void client_setup_decor_and_functions(ObClient
*self
)
1365 /* start with everything (cept fullscreen) */
1367 (OB_FRAME_DECOR_TITLEBAR
|
1368 OB_FRAME_DECOR_HANDLE
|
1369 OB_FRAME_DECOR_GRIPS
|
1370 OB_FRAME_DECOR_BORDER
|
1371 OB_FRAME_DECOR_ICON
|
1372 OB_FRAME_DECOR_ALLDESKTOPS
|
1373 OB_FRAME_DECOR_ICONIFY
|
1374 OB_FRAME_DECOR_MAXIMIZE
|
1375 OB_FRAME_DECOR_SHADE
|
1376 OB_FRAME_DECOR_CLOSE
);
1378 (OB_CLIENT_FUNC_RESIZE
|
1379 OB_CLIENT_FUNC_MOVE
|
1380 OB_CLIENT_FUNC_ICONIFY
|
1381 OB_CLIENT_FUNC_MAXIMIZE
|
1382 OB_CLIENT_FUNC_SHADE
|
1383 OB_CLIENT_FUNC_CLOSE
);
1385 if (!(self
->min_size
.width
< self
->max_size
.width
||
1386 self
->min_size
.height
< self
->max_size
.height
))
1387 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
1389 switch (self
->type
) {
1390 case OB_CLIENT_TYPE_NORMAL
:
1391 /* normal windows retain all of the possible decorations and
1392 functionality, and are the only windows that you can fullscreen */
1393 self
->functions
|= OB_CLIENT_FUNC_FULLSCREEN
;
1396 case OB_CLIENT_TYPE_DIALOG
:
1397 case OB_CLIENT_TYPE_UTILITY
:
1398 /* these windows cannot be maximized */
1399 self
->functions
&= ~OB_CLIENT_FUNC_MAXIMIZE
;
1402 case OB_CLIENT_TYPE_MENU
:
1403 case OB_CLIENT_TYPE_TOOLBAR
:
1404 /* these windows get less functionality */
1405 self
->functions
&= ~(OB_CLIENT_FUNC_ICONIFY
| OB_CLIENT_FUNC_RESIZE
);
1408 case OB_CLIENT_TYPE_DESKTOP
:
1409 case OB_CLIENT_TYPE_DOCK
:
1410 case OB_CLIENT_TYPE_SPLASH
:
1411 /* none of these windows are manipulated by the window manager */
1412 self
->decorations
= 0;
1413 self
->functions
= 0;
1417 /* Mwm Hints are applied subtractively to what has already been chosen for
1418 decor and functionality */
1419 if (self
->mwmhints
.flags
& OB_MWM_FLAG_DECORATIONS
) {
1420 if (! (self
->mwmhints
.decorations
& OB_MWM_DECOR_ALL
)) {
1421 if (! ((self
->mwmhints
.decorations
& OB_MWM_DECOR_HANDLE
) ||
1422 (self
->mwmhints
.decorations
& OB_MWM_DECOR_TITLE
)))
1424 /* if the mwm hints request no handle or title, then all
1425 decorations are disabled, but keep the border if that's
1427 if (self
->mwmhints
.decorations
& OB_MWM_DECOR_BORDER
)
1428 self
->decorations
= OB_FRAME_DECOR_BORDER
;
1430 self
->decorations
= 0;
1435 if (self
->mwmhints
.flags
& OB_MWM_FLAG_FUNCTIONS
) {
1436 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_ALL
)) {
1437 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_RESIZE
))
1438 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
1439 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_MOVE
))
1440 self
->functions
&= ~OB_CLIENT_FUNC_MOVE
;
1441 /* dont let mwm hints kill any buttons
1442 if (! (self->mwmhints.functions & OB_MWM_FUNC_ICONIFY))
1443 self->functions &= ~OB_CLIENT_FUNC_ICONIFY;
1444 if (! (self->mwmhints.functions & OB_MWM_FUNC_MAXIMIZE))
1445 self->functions &= ~OB_CLIENT_FUNC_MAXIMIZE;
1447 /* dont let mwm hints kill the close button
1448 if (! (self->mwmhints.functions & MwmFunc_Close))
1449 self->functions &= ~OB_CLIENT_FUNC_CLOSE; */
1453 if (!(self
->functions
& OB_CLIENT_FUNC_SHADE
))
1454 self
->decorations
&= ~OB_FRAME_DECOR_SHADE
;
1455 if (!(self
->functions
& OB_CLIENT_FUNC_ICONIFY
))
1456 self
->decorations
&= ~OB_FRAME_DECOR_ICONIFY
;
1457 if (!(self
->functions
& OB_CLIENT_FUNC_RESIZE
))
1458 self
->decorations
&= ~OB_FRAME_DECOR_GRIPS
;
1460 /* can't maximize without moving/resizing */
1461 if (!((self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) &&
1462 (self
->functions
& OB_CLIENT_FUNC_MOVE
) &&
1463 (self
->functions
& OB_CLIENT_FUNC_RESIZE
))) {
1464 self
->functions
&= ~OB_CLIENT_FUNC_MAXIMIZE
;
1465 self
->decorations
&= ~OB_FRAME_DECOR_MAXIMIZE
;
1468 /* kill the handle on fully maxed windows */
1469 if (self
->max_vert
&& self
->max_horz
)
1470 self
->decorations
&= ~OB_FRAME_DECOR_HANDLE
;
1472 /* finally, the user can have requested no decorations, which overrides
1473 everything (but doesnt give it a border if it doesnt have one) */
1474 if (self
->undecorated
) {
1475 if (config_theme_keepborder
)
1476 self
->decorations
&= OB_FRAME_DECOR_BORDER
;
1478 self
->decorations
= 0;
1481 /* if we don't have a titlebar, then we cannot shade! */
1482 if (!(self
->decorations
& OB_FRAME_DECOR_TITLEBAR
))
1483 self
->functions
&= ~OB_CLIENT_FUNC_SHADE
;
1485 /* now we need to check against rules for the client's current state */
1486 if (self
->fullscreen
) {
1487 self
->functions
&= (OB_CLIENT_FUNC_CLOSE
|
1488 OB_CLIENT_FUNC_FULLSCREEN
|
1489 OB_CLIENT_FUNC_ICONIFY
);
1490 self
->decorations
= 0;
1493 client_change_allowed_actions(self
);
1496 /* adjust the client's decorations, etc. */
1497 client_reconfigure(self
);
1501 static void client_change_allowed_actions(ObClient
*self
)
1506 /* desktop windows are kept on all desktops */
1507 if (self
->type
!= OB_CLIENT_TYPE_DESKTOP
)
1508 actions
[num
++] = prop_atoms
.net_wm_action_change_desktop
;
1510 if (self
->functions
& OB_CLIENT_FUNC_SHADE
)
1511 actions
[num
++] = prop_atoms
.net_wm_action_shade
;
1512 if (self
->functions
& OB_CLIENT_FUNC_CLOSE
)
1513 actions
[num
++] = prop_atoms
.net_wm_action_close
;
1514 if (self
->functions
& OB_CLIENT_FUNC_MOVE
)
1515 actions
[num
++] = prop_atoms
.net_wm_action_move
;
1516 if (self
->functions
& OB_CLIENT_FUNC_ICONIFY
)
1517 actions
[num
++] = prop_atoms
.net_wm_action_minimize
;
1518 if (self
->functions
& OB_CLIENT_FUNC_RESIZE
)
1519 actions
[num
++] = prop_atoms
.net_wm_action_resize
;
1520 if (self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
)
1521 actions
[num
++] = prop_atoms
.net_wm_action_fullscreen
;
1522 if (self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) {
1523 actions
[num
++] = prop_atoms
.net_wm_action_maximize_horz
;
1524 actions
[num
++] = prop_atoms
.net_wm_action_maximize_vert
;
1527 PROP_SETA32(self
->window
, net_wm_allowed_actions
, atom
, actions
, num
);
1529 /* make sure the window isn't breaking any rules now */
1531 if (!(self
->functions
& OB_CLIENT_FUNC_SHADE
) && self
->shaded
) {
1532 if (self
->frame
) client_shade(self
, FALSE
);
1533 else self
->shaded
= FALSE
;
1535 if (!(self
->functions
& OB_CLIENT_FUNC_ICONIFY
) && self
->iconic
) {
1536 if (self
->frame
) client_iconify(self
, FALSE
, TRUE
);
1537 else self
->iconic
= FALSE
;
1539 if (!(self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
) && self
->fullscreen
) {
1540 if (self
->frame
) client_fullscreen(self
, FALSE
);
1541 else self
->fullscreen
= FALSE
;
1543 if (!(self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) && (self
->max_horz
||
1545 if (self
->frame
) client_maximize(self
, FALSE
, 0);
1546 else self
->max_vert
= self
->max_horz
= FALSE
;
1550 void client_reconfigure(ObClient
*self
)
1552 /* by making this pass FALSE for user, we avoid the emacs event storm where
1553 every configurenotify causes an update in its normal hints, i think this
1554 is generally what we want anyways... */
1555 client_configure(self
, OB_CORNER_TOPLEFT
, self
->area
.x
, self
->area
.y
,
1556 self
->area
.width
, self
->area
.height
, FALSE
, TRUE
);
1559 void client_update_wmhints(ObClient
*self
)
1564 /* assume a window takes input if it doesnt specify */
1565 self
->can_focus
= TRUE
;
1567 if ((hints
= XGetWMHints(ob_display
, self
->window
)) != NULL
) {
1568 if (hints
->flags
& InputHint
)
1569 self
->can_focus
= hints
->input
;
1571 /* only do this when first managing the window *AND* when we aren't
1573 if (ob_state() != OB_STATE_STARTING
&& self
->frame
== NULL
)
1574 if (hints
->flags
& StateHint
)
1575 self
->iconic
= hints
->initial_state
== IconicState
;
1577 if (!(hints
->flags
& WindowGroupHint
))
1578 hints
->window_group
= None
;
1580 /* did the group state change? */
1581 if (hints
->window_group
!=
1582 (self
->group
? self
->group
->leader
: None
)) {
1583 /* remove from the old group if there was one */
1584 if (self
->group
!= NULL
) {
1585 /* remove transients of the group */
1586 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
))
1587 self
->transients
= g_slist_remove(self
->transients
,
1590 /* remove myself from parents in the group */
1591 if (self
->transient_for
== OB_TRAN_GROUP
) {
1592 for (it
= self
->group
->members
; it
;
1593 it
= g_slist_next(it
))
1595 ObClient
*c
= it
->data
;
1597 if (c
!= self
&& !c
->transient_for
)
1598 c
->transients
= g_slist_remove(c
->transients
,
1603 group_remove(self
->group
, self
);
1606 if (hints
->window_group
!= None
) {
1607 self
->group
= group_add(hints
->window_group
, self
);
1609 /* i can only have transients from the group if i am not
1611 if (!self
->transient_for
) {
1612 /* add other transients of the group that are already
1614 for (it
= self
->group
->members
; it
;
1615 it
= g_slist_next(it
))
1617 ObClient
*c
= it
->data
;
1618 if (c
!= self
&& c
->transient_for
== OB_TRAN_GROUP
)
1620 g_slist_append(self
->transients
, c
);
1625 /* because the self->transient flag wont change from this call,
1626 we don't need to update the window's type and such, only its
1627 transient_for, and the transients lists of other windows in
1628 the group may be affected */
1629 client_update_transient_for(self
);
1632 /* the WM_HINTS can contain an icon */
1633 client_update_icons(self
);
1639 void client_update_title(ObClient
*self
)
1642 gchar
*visible
= NULL
;
1644 g_free(self
->title
);
1647 if (!PROP_GETS(self
->window
, net_wm_name
, utf8
, &data
)) {
1648 /* try old x stuff */
1649 if (!(PROP_GETS(self
->window
, wm_name
, locale
, &data
)
1650 || PROP_GETS(self
->window
, wm_name
, utf8
, &data
))) {
1651 if (self
->transient
) {
1653 GNOME alert windows are not given titles:
1654 http://developer.gnome.org/projects/gup/hig/draft_hig_new/windows-alert.html
1656 data
= g_strdup("");
1658 data
= g_strdup("Unnamed Window");
1662 if (self
->client_machine
) {
1663 visible
= g_strdup_printf("%s (%s)", data
, self
->client_machine
);
1668 PROP_SETS(self
->window
, net_wm_visible_name
, visible
);
1669 self
->title
= visible
;
1672 frame_adjust_title(self
->frame
);
1674 /* update the icon title */
1676 g_free(self
->icon_title
);
1679 if (!PROP_GETS(self
->window
, net_wm_icon_name
, utf8
, &data
))
1680 /* try old x stuff */
1681 if (!(PROP_GETS(self
->window
, wm_icon_name
, locale
, &data
) ||
1682 PROP_GETS(self
->window
, wm_icon_name
, utf8
, &data
)))
1683 data
= g_strdup(self
->title
);
1685 PROP_SETS(self
->window
, net_wm_visible_icon_name
, data
);
1686 self
->icon_title
= data
;
1689 void client_update_class(ObClient
*self
)
1694 if (self
->name
) g_free(self
->name
);
1695 if (self
->class) g_free(self
->class);
1696 if (self
->role
) g_free(self
->role
);
1698 self
->name
= self
->class = self
->role
= NULL
;
1700 if (PROP_GETSS(self
->window
, wm_class
, locale
, &data
)) {
1702 self
->name
= g_strdup(data
[0]);
1704 self
->class = g_strdup(data
[1]);
1709 if (PROP_GETS(self
->window
, wm_window_role
, locale
, &s
))
1712 if (self
->name
== NULL
) self
->name
= g_strdup("");
1713 if (self
->class == NULL
) self
->class = g_strdup("");
1714 if (self
->role
== NULL
) self
->role
= g_strdup("");
1717 void client_update_strut(ObClient
*self
)
1721 gboolean got
= FALSE
;
1724 if (PROP_GETA32(self
->window
, net_wm_strut_partial
, cardinal
,
1728 STRUT_PARTIAL_SET(strut
,
1729 data
[0], data
[2], data
[1], data
[3],
1730 data
[4], data
[5], data
[8], data
[9],
1731 data
[6], data
[7], data
[10], data
[11]);
1737 PROP_GETA32(self
->window
, net_wm_strut
, cardinal
, &data
, &num
)) {
1743 /* use the screen's width/height */
1744 a
= screen_physical_area();
1746 STRUT_PARTIAL_SET(strut
,
1747 data
[0], data
[2], data
[1], data
[3],
1748 a
->y
, a
->y
+ a
->height
- 1,
1749 a
->x
, a
->x
+ a
->width
- 1,
1750 a
->y
, a
->y
+ a
->height
- 1,
1751 a
->x
, a
->x
+ a
->width
- 1);
1757 STRUT_PARTIAL_SET(strut
, 0, 0, 0, 0,
1758 0, 0, 0, 0, 0, 0, 0, 0);
1760 if (!STRUT_EQUAL(strut
, self
->strut
)) {
1761 self
->strut
= strut
;
1763 /* updating here is pointless while we're being mapped cuz we're not in
1764 the client list yet */
1766 screen_update_areas();
1770 void client_update_icons(ObClient
*self
)
1776 for (i
= 0; i
< self
->nicons
; ++i
)
1777 g_free(self
->icons
[i
].data
);
1778 if (self
->nicons
> 0)
1779 g_free(self
->icons
);
1782 if (PROP_GETA32(self
->window
, net_wm_icon
, cardinal
, &data
, &num
)) {
1783 /* figure out how many valid icons are in here */
1785 while (num
- i
> 2) {
1789 if (i
> num
|| w
*h
== 0) break;
1793 self
->icons
= g_new(ObClientIcon
, self
->nicons
);
1795 /* store the icons */
1797 for (j
= 0; j
< self
->nicons
; ++j
) {
1800 w
= self
->icons
[j
].width
= data
[i
++];
1801 h
= self
->icons
[j
].height
= data
[i
++];
1803 if (w
*h
== 0) continue;
1805 self
->icons
[j
].data
= g_new(RrPixel32
, w
* h
);
1806 for (x
= 0, y
= 0, t
= 0; t
< w
* h
; ++t
, ++x
, ++i
) {
1811 self
->icons
[j
].data
[t
] =
1812 (((data
[i
] >> 24) & 0xff) << RrDefaultAlphaOffset
) +
1813 (((data
[i
] >> 16) & 0xff) << RrDefaultRedOffset
) +
1814 (((data
[i
] >> 8) & 0xff) << RrDefaultGreenOffset
) +
1815 (((data
[i
] >> 0) & 0xff) << RrDefaultBlueOffset
);
1824 if ((hints
= XGetWMHints(ob_display
, self
->window
))) {
1825 if (hints
->flags
& IconPixmapHint
) {
1827 self
->icons
= g_new(ObClientIcon
, self
->nicons
);
1828 xerror_set_ignore(TRUE
);
1829 if (!RrPixmapToRGBA(ob_rr_inst
,
1831 (hints
->flags
& IconMaskHint
?
1832 hints
->icon_mask
: None
),
1833 &self
->icons
[self
->nicons
-1].width
,
1834 &self
->icons
[self
->nicons
-1].height
,
1835 &self
->icons
[self
->nicons
-1].data
)){
1836 g_free(&self
->icons
[self
->nicons
-1]);
1839 xerror_set_ignore(FALSE
);
1845 /* set the default icon onto the window
1846 in theory, this could be a race, but if a window doesn't set an icon
1847 or removes it entirely, it's not very likely it is going to set one
1848 right away afterwards */
1849 if (self
->nicons
== 0) {
1850 RrPixel32
*icon
= ob_rr_theme
->def_win_icon
;
1853 data
= g_new(guint32
, 48*48+2);
1854 data
[0] = data
[1] = 48;
1855 for (i
= 0; i
< 48*48; ++i
)
1856 data
[i
+2] = (((icon
[i
] >> RrDefaultAlphaOffset
) & 0xff) << 24) +
1857 (((icon
[i
] >> RrDefaultRedOffset
) & 0xff) << 16) +
1858 (((icon
[i
] >> RrDefaultGreenOffset
) & 0xff) << 8) +
1859 (((icon
[i
] >> RrDefaultBlueOffset
) & 0xff) << 0);
1860 PROP_SETA32(self
->window
, net_wm_icon
, cardinal
, data
, 48*48+2);
1862 } else if (self
->frame
)
1863 /* don't draw the icon empty if we're just setting one now anyways,
1864 we'll get the property change any second */
1865 frame_adjust_icon(self
->frame
);
1868 void client_update_user_time(ObClient
*self
)
1872 if (PROP_GET32(self
->window
, net_wm_user_time
, cardinal
, &time
)) {
1873 /* we set this every time, not just when it grows, because in practice
1874 sometimes time goes backwards! (ntpdate.. yay....) so.. if it goes
1875 backward we don't want all windows to stop focusing. we'll just
1876 assume noone is setting times older than the last one, cuz that
1877 would be pretty stupid anyways
1879 self
->user_time
= time
;
1882 ob_debug("window %s user time %u\n", self->title, time);
1887 static void client_get_client_machine(ObClient
*self
)
1890 gchar localhost
[128];
1892 g_free(self
->client_machine
);
1894 if (PROP_GETS(self
->window
, wm_client_machine
, locale
, &data
)) {
1895 gethostname(localhost
, 127);
1896 localhost
[127] = '\0';
1897 if (strcmp(localhost
, data
))
1898 self
->client_machine
= data
;
1902 static void client_change_wm_state(ObClient
*self
)
1907 old
= self
->wmstate
;
1909 if (self
->shaded
|| self
->iconic
|| !self
->frame
->visible
)
1910 self
->wmstate
= IconicState
;
1912 self
->wmstate
= NormalState
;
1914 if (old
!= self
->wmstate
) {
1915 PROP_MSG(self
->window
, kde_wm_change_state
,
1916 self
->wmstate
, 1, 0, 0);
1918 state
[0] = self
->wmstate
;
1920 PROP_SETA32(self
->window
, wm_state
, wm_state
, state
, 2);
1924 static void client_change_state(ObClient
*self
)
1926 gulong netstate
[11];
1931 netstate
[num
++] = prop_atoms
.net_wm_state_modal
;
1933 netstate
[num
++] = prop_atoms
.net_wm_state_shaded
;
1935 netstate
[num
++] = prop_atoms
.net_wm_state_hidden
;
1936 if (self
->skip_taskbar
)
1937 netstate
[num
++] = prop_atoms
.net_wm_state_skip_taskbar
;
1938 if (self
->skip_pager
)
1939 netstate
[num
++] = prop_atoms
.net_wm_state_skip_pager
;
1940 if (self
->fullscreen
)
1941 netstate
[num
++] = prop_atoms
.net_wm_state_fullscreen
;
1943 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_vert
;
1945 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_horz
;
1947 netstate
[num
++] = prop_atoms
.net_wm_state_above
;
1949 netstate
[num
++] = prop_atoms
.net_wm_state_below
;
1950 if (self
->demands_attention
)
1951 netstate
[num
++] = prop_atoms
.net_wm_state_demands_attention
;
1952 if (self
->undecorated
)
1953 netstate
[num
++] = prop_atoms
.ob_wm_state_undecorated
;
1954 PROP_SETA32(self
->window
, net_wm_state
, atom
, netstate
, num
);
1957 frame_adjust_state(self
->frame
);
1960 ObClient
*client_search_focus_tree(ObClient
*self
)
1965 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
1966 if (client_focused(it
->data
)) return it
->data
;
1967 if ((ret
= client_search_focus_tree(it
->data
))) return ret
;
1972 ObClient
*client_search_focus_tree_full(ObClient
*self
)
1974 if (self
->transient_for
) {
1975 if (self
->transient_for
!= OB_TRAN_GROUP
) {
1976 return client_search_focus_tree_full(self
->transient_for
);
1979 gboolean recursed
= FALSE
;
1981 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
))
1982 if (!((ObClient
*)it
->data
)->transient_for
) {
1984 if ((c
= client_search_focus_tree_full(it
->data
)))
1993 /* this function checks the whole tree, the client_search_focus_tree~
1994 does not, so we need to check this window */
1995 if (client_focused(self
))
1997 return client_search_focus_tree(self
);
2000 static ObStackingLayer
calc_layer(ObClient
*self
)
2004 if (self
->fullscreen
&&
2005 (client_focused(self
) || client_search_focus_tree(self
)))
2006 l
= OB_STACKING_LAYER_FULLSCREEN
;
2007 else if (self
->type
== OB_CLIENT_TYPE_DESKTOP
)
2008 l
= OB_STACKING_LAYER_DESKTOP
;
2009 else if (self
->type
== OB_CLIENT_TYPE_DOCK
) {
2010 if (self
->below
) l
= OB_STACKING_LAYER_NORMAL
;
2011 else l
= OB_STACKING_LAYER_ABOVE
;
2013 else if (self
->above
) l
= OB_STACKING_LAYER_ABOVE
;
2014 else if (self
->below
) l
= OB_STACKING_LAYER_BELOW
;
2015 else l
= OB_STACKING_LAYER_NORMAL
;
2020 static void client_calc_layer_recursive(ObClient
*self
, ObClient
*orig
,
2021 ObStackingLayer min
, gboolean raised
)
2023 ObStackingLayer old
, own
;
2027 own
= calc_layer(self
);
2028 self
->layer
= MAX(own
, min
);
2030 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
2031 client_calc_layer_recursive(it
->data
, orig
,
2033 raised
? raised
: self
->layer
!= old
);
2035 if (!raised
&& self
->layer
!= old
)
2036 if (orig
->frame
) { /* only restack if the original window is managed */
2037 stacking_remove(CLIENT_AS_WINDOW(self
));
2038 stacking_add(CLIENT_AS_WINDOW(self
));
2042 void client_calc_layer(ObClient
*self
)
2049 /* transients take on the layer of their parents */
2050 it
= client_search_all_top_parents(self
);
2052 for (; it
; it
= g_slist_next(it
))
2053 client_calc_layer_recursive(it
->data
, orig
, 0, FALSE
);
2056 gboolean
client_should_show(ObClient
*self
)
2060 if (client_normal(self
) && screen_showing_desktop
)
2063 if (self->transient_for) {
2064 if (self->transient_for != OB_TRAN_GROUP)
2065 return client_should_show(self->transient_for);
2069 for (it = self->group->members; it; it = g_slist_next(it)) {
2070 ObClient *c = it->data;
2071 if (c != self && !c->transient_for) {
2072 if (client_should_show(c))
2079 if (self
->desktop
== screen_desktop
|| self
->desktop
== DESKTOP_ALL
)
2085 void client_show(ObClient
*self
)
2088 if (client_should_show(self
)) {
2089 frame_show(self
->frame
);
2092 /* According to the ICCCM (sec 4.1.3.1) when a window is not visible, it
2093 needs to be in IconicState. This includes when it is on another
2096 client_change_wm_state(self
);
2099 void client_hide(ObClient
*self
)
2101 if (!client_should_show(self
)) {
2102 frame_hide(self
->frame
);
2105 /* According to the ICCCM (sec 4.1.3.1) when a window is not visible, it
2106 needs to be in IconicState. This includes when it is on another
2109 client_change_wm_state(self
);
2112 void client_showhide(ObClient
*self
)
2115 if (client_should_show(self
)) {
2116 frame_show(self
->frame
);
2119 frame_hide(self
->frame
);
2122 /* According to the ICCCM (sec 4.1.3.1) when a window is not visible, it
2123 needs to be in IconicState. This includes when it is on another
2126 client_change_wm_state(self
);
2129 gboolean
client_normal(ObClient
*self
) {
2130 return ! (self
->type
== OB_CLIENT_TYPE_DESKTOP
||
2131 self
->type
== OB_CLIENT_TYPE_DOCK
||
2132 self
->type
== OB_CLIENT_TYPE_SPLASH
);
2135 static void client_apply_startup_state(ObClient
*self
, gint x
, gint y
)
2137 gboolean pos
= FALSE
; /* has the window's position been configured? */
2140 /* save the position, and set self->area for these to use */
2146 /* set the desktop hint, to make sure that it always exists */
2147 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, self
->desktop
);
2149 /* these are in a carefully crafted order.. */
2152 self
->iconic
= FALSE
;
2153 client_iconify(self
, TRUE
, FALSE
);
2155 if (self
->fullscreen
) {
2156 self
->fullscreen
= FALSE
;
2157 client_fullscreen(self
, TRUE
);
2160 if (self
->undecorated
) {
2161 self
->undecorated
= FALSE
;
2162 client_set_undecorated(self
, TRUE
);
2165 self
->shaded
= FALSE
;
2166 client_shade(self
, TRUE
);
2168 if (self
->demands_attention
) {
2169 self
->demands_attention
= FALSE
;
2170 client_hilite(self
, TRUE
);
2173 if (self
->max_vert
&& self
->max_horz
) {
2174 self
->max_vert
= self
->max_horz
= FALSE
;
2175 client_maximize(self
, TRUE
, 0);
2177 } else if (self
->max_vert
) {
2178 self
->max_vert
= FALSE
;
2179 client_maximize(self
, TRUE
, 2);
2181 } else if (self
->max_horz
) {
2182 self
->max_horz
= FALSE
;
2183 client_maximize(self
, TRUE
, 1);
2187 /* if the client didn't get positioned yet, then do so now
2188 call client_move even if the window is not being moved anywhere, because
2189 when we reparent it and decorate it, it is getting moved and we need to
2190 be telling it so with a ConfigureNotify event.
2193 /* use the saved position */
2196 client_move(self
, x
, y
);
2199 /* nothing to do for the other states:
2208 void client_try_configure(ObClient
*self
, ObCorner anchor
,
2209 gint
*x
, gint
*y
, gint
*w
, gint
*h
,
2210 gint
*logicalw
, gint
*logicalh
,
2213 Rect desired_area
= {*x
, *y
, *w
, *h
};
2215 /* make the frame recalculate its dimentions n shit without changing
2216 anything visible for real, this way the constraints below can work with
2217 the updated frame dimensions. */
2218 frame_adjust_area(self
->frame
, TRUE
, TRUE
, TRUE
);
2220 /* work within the prefered sizes given by the window */
2221 if (!(*w
== self
->area
.width
&& *h
== self
->area
.height
)) {
2222 gint basew
, baseh
, minw
, minh
;
2224 /* base size is substituted with min size if not specified */
2225 if (self
->base_size
.width
|| self
->base_size
.height
) {
2226 basew
= self
->base_size
.width
;
2227 baseh
= self
->base_size
.height
;
2229 basew
= self
->min_size
.width
;
2230 baseh
= self
->min_size
.height
;
2232 /* min size is substituted with base size if not specified */
2233 if (self
->min_size
.width
|| self
->min_size
.height
) {
2234 minw
= self
->min_size
.width
;
2235 minh
= self
->min_size
.height
;
2237 minw
= self
->base_size
.width
;
2238 minh
= self
->base_size
.height
;
2241 /* if this is a user-requested resize, then check against min/max
2244 /* smaller than min size or bigger than max size? */
2245 if (*w
> self
->max_size
.width
) *w
= self
->max_size
.width
;
2246 if (*w
< minw
) *w
= minw
;
2247 if (*h
> self
->max_size
.height
) *h
= self
->max_size
.height
;
2248 if (*h
< minh
) *h
= minh
;
2253 /* keep to the increments */
2254 *w
/= self
->size_inc
.width
;
2255 *h
/= self
->size_inc
.height
;
2257 /* you cannot resize to nothing */
2258 if (basew
+ *w
< 1) *w
= 1 - basew
;
2259 if (baseh
+ *h
< 1) *h
= 1 - baseh
;
2261 /* save the logical size */
2262 *logicalw
= self
->size_inc
.width
> 1 ? *w
: *w
+ basew
;
2263 *logicalh
= self
->size_inc
.height
> 1 ? *h
: *h
+ baseh
;
2265 *w
*= self
->size_inc
.width
;
2266 *h
*= self
->size_inc
.height
;
2271 /* adjust the height to match the width for the aspect ratios.
2272 for this, min size is not substituted for base size ever. */
2273 *w
-= self
->base_size
.width
;
2274 *h
-= self
->base_size
.height
;
2276 if (!self
->fullscreen
) {
2277 if (self
->min_ratio
)
2278 if (*h
* self
->min_ratio
> *w
) {
2279 *h
= (gint
)(*w
/ self
->min_ratio
);
2281 /* you cannot resize to nothing */
2284 *w
= (gint
)(*h
* self
->min_ratio
);
2287 if (self
->max_ratio
)
2288 if (*h
* self
->max_ratio
< *w
) {
2289 *h
= (gint
)(*w
/ self
->max_ratio
);
2291 /* you cannot resize to nothing */
2294 *w
= (gint
)(*h
* self
->min_ratio
);
2299 *w
+= self
->base_size
.width
;
2300 *h
+= self
->base_size
.height
;
2303 /* gets the frame's position */
2304 frame_client_gravity(self
->frame
, x
, y
);
2306 /* these positions are frame positions, not client positions */
2308 /* set the size and position if fullscreen */
2309 if (self
->fullscreen
) {
2313 i
= screen_find_monitor(&desired_area
);
2314 a
= screen_physical_area_monitor(i
);
2321 user
= FALSE
; /* ignore if the client can't be moved/resized when it
2322 is entering fullscreen */
2323 } else if (self
->max_horz
|| self
->max_vert
) {
2327 i
= screen_find_monitor(&desired_area
);
2328 a
= screen_area_monitor(self
->desktop
, i
);
2330 /* set the size and position if maximized */
2331 if (self
->max_horz
) {
2333 *w
= a
->width
- self
->frame
->size
.left
- self
->frame
->size
.right
;
2335 if (self
->max_vert
) {
2337 *h
= a
->height
- self
->frame
->size
.top
- self
->frame
->size
.bottom
;
2340 /* maximizing is not allowed if the user can't move+resize the window
2344 /* gets the client's position */
2345 frame_frame_gravity(self
->frame
, x
, y
);
2347 /* these override the above states! if you cant move you can't move! */
2349 if (!(self
->functions
& OB_CLIENT_FUNC_MOVE
)) {
2353 if (!(self
->functions
& OB_CLIENT_FUNC_RESIZE
)) {
2354 *w
= self
->area
.width
;
2355 *h
= self
->area
.height
;
2363 case OB_CORNER_TOPLEFT
:
2365 case OB_CORNER_TOPRIGHT
:
2366 *x
-= *w
- self
->area
.width
;
2368 case OB_CORNER_BOTTOMLEFT
:
2369 *y
-= *h
- self
->area
.height
;
2371 case OB_CORNER_BOTTOMRIGHT
:
2372 *x
-= *w
- self
->area
.width
;
2373 *y
-= *h
- self
->area
.height
;
2379 void client_configure_full(ObClient
*self
, ObCorner anchor
,
2380 gint x
, gint y
, gint w
, gint h
,
2381 gboolean user
, gboolean final
,
2382 gboolean force_reply
)
2384 gint oldw
, oldh
, oldrx
, oldry
;
2385 gboolean send_resize_client
;
2386 gboolean moved
= FALSE
, resized
= FALSE
, rootmoved
= FALSE
;
2387 guint fdecor
= self
->frame
->decorations
;
2388 gboolean fhorz
= self
->frame
->max_horz
;
2389 gint logicalw
, logicalh
;
2391 /* find the new x, y, width, and height (and logical size) */
2392 client_try_configure(self
, anchor
, &x
, &y
, &w
, &h
,
2393 &logicalw
, &logicalh
, user
);
2395 /* set the logical size if things changed */
2396 if (!(w
== self
->area
.width
&& h
== self
->area
.height
))
2397 SIZE_SET(self
->logical_size
, logicalw
, logicalh
);
2399 /* figure out if we moved or resized or what */
2400 moved
= x
!= self
->area
.x
|| y
!= self
->area
.y
;
2401 resized
= w
!= self
->area
.width
|| h
!= self
->area
.height
;
2403 oldw
= self
->area
.width
;
2404 oldh
= self
->area
.height
;
2405 RECT_SET(self
->area
, x
, y
, w
, h
);
2407 /* for app-requested resizes, always resize if 'resized' is true.
2408 for user-requested ones, only resize if final is true, or when
2409 resizing in redraw mode */
2410 send_resize_client
= ((!user
&& resized
) ||
2412 (resized
&& config_resize_redraw
))));
2414 /* if the client is enlarging, then resize the client before the frame */
2415 if (send_resize_client
&& user
&& (w
> oldw
|| h
> oldh
)) {
2416 XResizeWindow(ob_display
, self
->window
, MAX(w
, oldw
), MAX(h
, oldh
));
2417 frame_adjust_client_area(self
->frame
);
2420 /* find the frame's dimensions and move/resize it */
2421 if (self
->decorations
!= fdecor
|| self
->max_horz
!= fhorz
)
2422 moved
= resized
= TRUE
;
2423 if (moved
|| resized
)
2424 frame_adjust_area(self
->frame
, moved
, resized
, FALSE
);
2426 /* find the client's position relative to the root window */
2427 oldrx
= self
->root_pos
.x
;
2428 oldry
= self
->root_pos
.y
;
2429 rootmoved
= (oldrx
!= (signed)(self
->frame
->area
.x
+
2430 self
->frame
->size
.left
-
2431 self
->border_width
) ||
2432 oldry
!= (signed)(self
->frame
->area
.y
+
2433 self
->frame
->size
.top
-
2434 self
->border_width
));
2436 if (force_reply
|| ((!user
|| (user
&& final
)) && rootmoved
))
2440 POINT_SET(self
->root_pos
,
2441 self
->frame
->area
.x
+ self
->frame
->size
.left
-
2443 self
->frame
->area
.y
+ self
->frame
->size
.top
-
2444 self
->border_width
);
2446 event
.type
= ConfigureNotify
;
2447 event
.xconfigure
.display
= ob_display
;
2448 event
.xconfigure
.event
= self
->window
;
2449 event
.xconfigure
.window
= self
->window
;
2451 /* root window real coords */
2452 event
.xconfigure
.x
= self
->root_pos
.x
;
2453 event
.xconfigure
.y
= self
->root_pos
.y
;
2454 event
.xconfigure
.width
= w
;
2455 event
.xconfigure
.height
= h
;
2456 event
.xconfigure
.border_width
= 0;
2457 event
.xconfigure
.above
= self
->frame
->plate
;
2458 event
.xconfigure
.override_redirect
= FALSE
;
2459 XSendEvent(event
.xconfigure
.display
, event
.xconfigure
.window
,
2460 FALSE
, StructureNotifyMask
, &event
);
2463 /* if the client is shrinking, then resize the frame before the client */
2464 if (send_resize_client
&& (!user
|| (w
<= oldw
|| h
<= oldh
))) {
2465 frame_adjust_client_area(self
->frame
);
2466 XResizeWindow(ob_display
, self
->window
, w
, h
);
2472 void client_fullscreen(ObClient
*self
, gboolean fs
)
2476 if (!(self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
) || /* can't */
2477 self
->fullscreen
== fs
) return; /* already done */
2479 self
->fullscreen
= fs
;
2480 client_change_state(self
); /* change the state hints on the client */
2481 client_calc_layer(self
); /* and adjust out layer/stacking */
2484 self
->pre_fullscreen_area
= self
->area
;
2485 /* if the window is maximized, its area isn't all that meaningful.
2486 save it's premax area instead. */
2487 if (self
->max_horz
) {
2488 self
->pre_fullscreen_area
.x
= self
->pre_max_area
.x
;
2489 self
->pre_fullscreen_area
.width
= self
->pre_max_area
.width
;
2491 if (self
->max_vert
) {
2492 self
->pre_fullscreen_area
.y
= self
->pre_max_area
.y
;
2493 self
->pre_fullscreen_area
.height
= self
->pre_max_area
.height
;
2496 /* these are not actually used cuz client_configure will set them
2497 as appropriate when the window is fullscreened */
2502 if (self
->pre_fullscreen_area
.width
> 0 &&
2503 self
->pre_fullscreen_area
.height
> 0)
2505 x
= self
->pre_fullscreen_area
.x
;
2506 y
= self
->pre_fullscreen_area
.y
;
2507 w
= self
->pre_fullscreen_area
.width
;
2508 h
= self
->pre_fullscreen_area
.height
;
2509 RECT_SET(self
->pre_fullscreen_area
, 0, 0, 0, 0);
2511 /* pick some fallbacks... */
2512 a
= screen_area_monitor(self
->desktop
, 0);
2513 x
= a
->x
+ a
->width
/ 4;
2514 y
= a
->y
+ a
->height
/ 4;
2520 client_setup_decor_and_functions(self
);
2522 client_move_resize(self
, x
, y
, w
, h
);
2524 /* try focus us when we go into fullscreen mode */
2528 static void client_iconify_recursive(ObClient
*self
,
2529 gboolean iconic
, gboolean curdesk
)
2532 gboolean changed
= FALSE
;
2535 if (self
->iconic
!= iconic
) {
2536 ob_debug("%sconifying window: 0x%lx\n", (iconic
? "I" : "Uni"),
2540 if (self
->functions
& OB_CLIENT_FUNC_ICONIFY
) {
2541 self
->iconic
= iconic
;
2543 /* update the focus lists.. iconic windows go to the bottom of
2544 the list, put the new iconic window at the 'top of the
2546 focus_order_to_top(self
);
2551 self
->iconic
= iconic
;
2554 client_set_desktop(self
, screen_desktop
, FALSE
);
2556 /* this puts it after the current focused window */
2557 focus_order_remove(self
);
2558 focus_order_add_new(self
);
2565 client_change_state(self
);
2566 client_showhide(self
);
2567 if (STRUT_EXISTS(self
->strut
))
2568 screen_update_areas();
2571 /* iconify all direct transients */
2572 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
2573 if (it
->data
!= self
)
2574 if (client_is_direct_child(self
, it
->data
))
2575 client_iconify_recursive(it
->data
, iconic
, curdesk
);
2578 void client_iconify(ObClient
*self
, gboolean iconic
, gboolean curdesk
)
2580 /* move up the transient chain as far as possible first */
2581 self
= client_search_top_parent(self
);
2582 client_iconify_recursive(self
, iconic
, curdesk
);
2585 void client_maximize(ObClient
*self
, gboolean max
, gint dir
)
2589 g_assert(dir
== 0 || dir
== 1 || dir
== 2);
2590 if (!(self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
)) return; /* can't */
2592 /* check if already done */
2594 if (dir
== 0 && self
->max_horz
&& self
->max_vert
) return;
2595 if (dir
== 1 && self
->max_horz
) return;
2596 if (dir
== 2 && self
->max_vert
) return;
2598 if (dir
== 0 && !self
->max_horz
&& !self
->max_vert
) return;
2599 if (dir
== 1 && !self
->max_horz
) return;
2600 if (dir
== 2 && !self
->max_vert
) return;
2603 /* we just tell it to configure in the same place and client_configure
2604 worries about filling the screen with the window */
2607 w
= self
->area
.width
;
2608 h
= self
->area
.height
;
2611 if ((dir
== 0 || dir
== 1) && !self
->max_horz
) { /* horz */
2612 RECT_SET(self
->pre_max_area
,
2613 self
->area
.x
, self
->pre_max_area
.y
,
2614 self
->area
.width
, self
->pre_max_area
.height
);
2616 if ((dir
== 0 || dir
== 2) && !self
->max_vert
) { /* vert */
2617 RECT_SET(self
->pre_max_area
,
2618 self
->pre_max_area
.x
, self
->area
.y
,
2619 self
->pre_max_area
.width
, self
->area
.height
);
2624 a
= screen_area_monitor(self
->desktop
, 0);
2625 if ((dir
== 0 || dir
== 1) && self
->max_horz
) { /* horz */
2626 if (self
->pre_max_area
.width
> 0) {
2627 x
= self
->pre_max_area
.x
;
2628 w
= self
->pre_max_area
.width
;
2630 RECT_SET(self
->pre_max_area
, 0, self
->pre_max_area
.y
,
2631 0, self
->pre_max_area
.height
);
2633 /* pick some fallbacks... */
2634 x
= a
->x
+ a
->width
/ 4;
2638 if ((dir
== 0 || dir
== 2) && self
->max_vert
) { /* vert */
2639 if (self
->pre_max_area
.height
> 0) {
2640 y
= self
->pre_max_area
.y
;
2641 h
= self
->pre_max_area
.height
;
2643 RECT_SET(self
->pre_max_area
, self
->pre_max_area
.x
, 0,
2644 self
->pre_max_area
.width
, 0);
2646 /* pick some fallbacks... */
2647 y
= a
->y
+ a
->height
/ 4;
2653 if (dir
== 0 || dir
== 1) /* horz */
2654 self
->max_horz
= max
;
2655 if (dir
== 0 || dir
== 2) /* vert */
2656 self
->max_vert
= max
;
2658 client_change_state(self
); /* change the state hints on the client */
2660 client_setup_decor_and_functions(self
);
2662 client_move_resize(self
, x
, y
, w
, h
);
2665 void client_shade(ObClient
*self
, gboolean shade
)
2667 if ((!(self
->functions
& OB_CLIENT_FUNC_SHADE
) &&
2668 shade
) || /* can't shade */
2669 self
->shaded
== shade
) return; /* already done */
2671 self
->shaded
= shade
;
2672 client_change_state(self
);
2673 client_change_wm_state(self
); /* the window is being hidden/shown */
2674 /* resize the frame to just the titlebar */
2675 frame_adjust_area(self
->frame
, FALSE
, FALSE
, FALSE
);
2678 void client_close(ObClient
*self
)
2682 if (!(self
->functions
& OB_CLIENT_FUNC_CLOSE
)) return;
2684 /* in the case that the client provides no means to requesting that it
2685 close, we just kill it */
2686 if (!self
->delete_window
)
2690 XXX: itd be cool to do timeouts and shit here for killing the client's
2692 like... if the window is around after 5 seconds, then the close button
2693 turns a nice red, and if this function is called again, the client is
2697 ce
.xclient
.type
= ClientMessage
;
2698 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
2699 ce
.xclient
.display
= ob_display
;
2700 ce
.xclient
.window
= self
->window
;
2701 ce
.xclient
.format
= 32;
2702 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_delete_window
;
2703 ce
.xclient
.data
.l
[1] = event_curtime
;
2704 ce
.xclient
.data
.l
[2] = 0l;
2705 ce
.xclient
.data
.l
[3] = 0l;
2706 ce
.xclient
.data
.l
[4] = 0l;
2707 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
2710 void client_kill(ObClient
*self
)
2712 XKillClient(ob_display
, self
->window
);
2715 void client_hilite(ObClient
*self
, gboolean hilite
)
2717 if (self
->demands_attention
== hilite
)
2718 return; /* no change */
2720 /* don't allow focused windows to hilite */
2721 self
->demands_attention
= hilite
&& !client_focused(self
);
2722 if (self
->demands_attention
)
2723 frame_flash_start(self
->frame
);
2725 frame_flash_stop(self
->frame
);
2726 client_change_state(self
);
2729 void client_set_desktop_recursive(ObClient
*self
,
2730 guint target
, gboolean donthide
)
2735 if (target
!= self
->desktop
) {
2737 ob_debug("Setting desktop %u\n", target
+1);
2739 g_assert(target
< screen_num_desktops
|| target
== DESKTOP_ALL
);
2741 /* remove from the old desktop(s) */
2742 focus_order_remove(self
);
2744 old
= self
->desktop
;
2745 self
->desktop
= target
;
2746 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, target
);
2747 /* the frame can display the current desktop state */
2748 frame_adjust_state(self
->frame
);
2749 /* 'move' the window to the new desktop */
2751 client_showhide(self
);
2752 /* raise if it was not already on the desktop */
2753 if (old
!= DESKTOP_ALL
)
2755 if (STRUT_EXISTS(self
->strut
))
2756 screen_update_areas();
2758 /* add to the new desktop(s) */
2759 if (config_focus_new
)
2760 focus_order_to_top(self
);
2762 focus_order_to_bottom(self
);
2765 /* move all transients */
2766 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
2767 if (it
->data
!= self
)
2768 if (client_is_direct_child(self
, it
->data
))
2769 client_set_desktop_recursive(it
->data
, target
, donthide
);
2772 void client_set_desktop(ObClient
*self
, guint target
, gboolean donthide
)
2774 self
= client_search_top_parent(self
);
2775 client_set_desktop_recursive(self
, target
, donthide
);
2778 gboolean
client_is_direct_child(ObClient
*parent
, ObClient
*child
)
2780 while (child
!= parent
&&
2781 child
->transient_for
&& child
->transient_for
!= OB_TRAN_GROUP
)
2782 child
= child
->transient_for
;
2783 return child
== parent
;
2786 ObClient
*client_search_modal_child(ObClient
*self
)
2791 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
2792 ObClient
*c
= it
->data
;
2793 if ((ret
= client_search_modal_child(c
))) return ret
;
2794 if (c
->modal
) return c
;
2799 gboolean
client_validate(ObClient
*self
)
2803 XSync(ob_display
, FALSE
); /* get all events on the server */
2805 if (XCheckTypedWindowEvent(ob_display
, self
->window
, DestroyNotify
, &e
) ||
2806 XCheckTypedWindowEvent(ob_display
, self
->window
, UnmapNotify
, &e
)) {
2807 XPutBackEvent(ob_display
, &e
);
2814 void client_set_wm_state(ObClient
*self
, glong state
)
2816 if (state
== self
->wmstate
) return; /* no change */
2820 client_iconify(self
, TRUE
, TRUE
);
2823 client_iconify(self
, FALSE
, TRUE
);
2828 void client_set_state(ObClient
*self
, Atom action
, glong data1
, glong data2
)
2830 gboolean shaded
= self
->shaded
;
2831 gboolean fullscreen
= self
->fullscreen
;
2832 gboolean undecorated
= self
->undecorated
;
2833 gboolean max_horz
= self
->max_horz
;
2834 gboolean max_vert
= self
->max_vert
;
2835 gboolean modal
= self
->modal
;
2836 gboolean iconic
= self
->iconic
;
2837 gboolean demands_attention
= self
->demands_attention
;
2840 if (!(action
== prop_atoms
.net_wm_state_add
||
2841 action
== prop_atoms
.net_wm_state_remove
||
2842 action
== prop_atoms
.net_wm_state_toggle
))
2843 /* an invalid action was passed to the client message, ignore it */
2846 for (i
= 0; i
< 2; ++i
) {
2847 Atom state
= i
== 0 ? data1
: data2
;
2849 if (!state
) continue;
2851 /* if toggling, then pick whether we're adding or removing */
2852 if (action
== prop_atoms
.net_wm_state_toggle
) {
2853 if (state
== prop_atoms
.net_wm_state_modal
)
2854 action
= modal
? prop_atoms
.net_wm_state_remove
:
2855 prop_atoms
.net_wm_state_add
;
2856 else if (state
== prop_atoms
.net_wm_state_maximized_vert
)
2857 action
= self
->max_vert
? prop_atoms
.net_wm_state_remove
:
2858 prop_atoms
.net_wm_state_add
;
2859 else if (state
== prop_atoms
.net_wm_state_maximized_horz
)
2860 action
= self
->max_horz
? prop_atoms
.net_wm_state_remove
:
2861 prop_atoms
.net_wm_state_add
;
2862 else if (state
== prop_atoms
.net_wm_state_shaded
)
2863 action
= shaded
? prop_atoms
.net_wm_state_remove
:
2864 prop_atoms
.net_wm_state_add
;
2865 else if (state
== prop_atoms
.net_wm_state_skip_taskbar
)
2866 action
= self
->skip_taskbar
?
2867 prop_atoms
.net_wm_state_remove
:
2868 prop_atoms
.net_wm_state_add
;
2869 else if (state
== prop_atoms
.net_wm_state_skip_pager
)
2870 action
= self
->skip_pager
?
2871 prop_atoms
.net_wm_state_remove
:
2872 prop_atoms
.net_wm_state_add
;
2873 else if (state
== prop_atoms
.net_wm_state_hidden
)
2874 action
= self
->iconic
?
2875 prop_atoms
.net_wm_state_remove
:
2876 prop_atoms
.net_wm_state_add
;
2877 else if (state
== prop_atoms
.net_wm_state_fullscreen
)
2878 action
= fullscreen
?
2879 prop_atoms
.net_wm_state_remove
:
2880 prop_atoms
.net_wm_state_add
;
2881 else if (state
== prop_atoms
.net_wm_state_above
)
2882 action
= self
->above
? prop_atoms
.net_wm_state_remove
:
2883 prop_atoms
.net_wm_state_add
;
2884 else if (state
== prop_atoms
.net_wm_state_below
)
2885 action
= self
->below
? prop_atoms
.net_wm_state_remove
:
2886 prop_atoms
.net_wm_state_add
;
2887 else if (state
== prop_atoms
.net_wm_state_demands_attention
)
2888 action
= self
->demands_attention
?
2889 prop_atoms
.net_wm_state_remove
:
2890 prop_atoms
.net_wm_state_add
;
2891 else if (state
== prop_atoms
.ob_wm_state_undecorated
)
2892 action
= undecorated
? prop_atoms
.net_wm_state_remove
:
2893 prop_atoms
.net_wm_state_add
;
2896 if (action
== prop_atoms
.net_wm_state_add
) {
2897 if (state
== prop_atoms
.net_wm_state_modal
) {
2899 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
2901 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
2903 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
2905 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
2906 self
->skip_taskbar
= TRUE
;
2907 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
2908 self
->skip_pager
= TRUE
;
2909 } else if (state
== prop_atoms
.net_wm_state_hidden
) {
2911 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
2913 } else if (state
== prop_atoms
.net_wm_state_above
) {
2915 self
->below
= FALSE
;
2916 } else if (state
== prop_atoms
.net_wm_state_below
) {
2917 self
->above
= FALSE
;
2919 } else if (state
== prop_atoms
.net_wm_state_demands_attention
) {
2920 demands_attention
= TRUE
;
2921 } else if (state
== prop_atoms
.ob_wm_state_undecorated
) {
2925 } else { /* action == prop_atoms.net_wm_state_remove */
2926 if (state
== prop_atoms
.net_wm_state_modal
) {
2928 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
2930 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
2932 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
2934 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
2935 self
->skip_taskbar
= FALSE
;
2936 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
2937 self
->skip_pager
= FALSE
;
2938 } else if (state
== prop_atoms
.net_wm_state_hidden
) {
2940 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
2942 } else if (state
== prop_atoms
.net_wm_state_above
) {
2943 self
->above
= FALSE
;
2944 } else if (state
== prop_atoms
.net_wm_state_below
) {
2945 self
->below
= FALSE
;
2946 } else if (state
== prop_atoms
.net_wm_state_demands_attention
) {
2947 demands_attention
= FALSE
;
2948 } else if (state
== prop_atoms
.ob_wm_state_undecorated
) {
2949 undecorated
= FALSE
;
2953 if (max_horz
!= self
->max_horz
|| max_vert
!= self
->max_vert
) {
2954 if (max_horz
!= self
->max_horz
&& max_vert
!= self
->max_vert
) {
2956 if (max_horz
== max_vert
) { /* both going the same way */
2957 client_maximize(self
, max_horz
, 0);
2959 client_maximize(self
, max_horz
, 1);
2960 client_maximize(self
, max_vert
, 2);
2964 if (max_horz
!= self
->max_horz
)
2965 client_maximize(self
, max_horz
, 1);
2967 client_maximize(self
, max_vert
, 2);
2970 /* change fullscreen state before shading, as it will affect if the window
2972 if (fullscreen
!= self
->fullscreen
)
2973 client_fullscreen(self
, fullscreen
);
2974 if (shaded
!= self
->shaded
)
2975 client_shade(self
, shaded
);
2976 if (undecorated
!= self
->undecorated
)
2977 client_set_undecorated(self
, undecorated
);
2978 if (modal
!= self
->modal
) {
2979 self
->modal
= modal
;
2980 /* when a window changes modality, then its stacking order with its
2981 transients needs to change */
2984 if (iconic
!= self
->iconic
)
2985 client_iconify(self
, iconic
, FALSE
);
2987 if (demands_attention
!= self
->demands_attention
)
2988 client_hilite(self
, demands_attention
);
2990 client_change_state(self
); /* change the hint to reflect these changes */
2993 ObClient
*client_focus_target(ObClient
*self
)
2995 ObClient
*child
= NULL
;
2997 child
= client_search_modal_child(self
);
2998 if (child
) return child
;
3002 gboolean
client_can_focus(ObClient
*self
)
3006 /* choose the correct target */
3007 self
= client_focus_target(self
);
3009 if (!self
->frame
->visible
)
3012 if (!(self
->can_focus
|| self
->focus_notify
))
3015 /* do a check to see if the window has already been unmapped or destroyed
3016 do this intelligently while watching out for unmaps we've generated
3017 (ignore_unmaps > 0) */
3018 if (XCheckTypedWindowEvent(ob_display
, self
->window
,
3019 DestroyNotify
, &ev
)) {
3020 XPutBackEvent(ob_display
, &ev
);
3023 while (XCheckTypedWindowEvent(ob_display
, self
->window
,
3024 UnmapNotify
, &ev
)) {
3025 if (self
->ignore_unmaps
) {
3026 self
->ignore_unmaps
--;
3028 XPutBackEvent(ob_display
, &ev
);
3036 gboolean
client_focus(ObClient
*self
)
3038 /* choose the correct target */
3039 self
= client_focus_target(self
);
3041 if (!client_can_focus(self
)) {
3042 if (!self
->frame
->visible
) {
3043 /* update the focus lists */
3044 focus_order_to_top(self
);
3049 ob_debug_type(OB_DEBUG_FOCUS
,
3050 "Focusing client \"%s\" at time %u\n",
3051 self
->title
, event_curtime
);
3053 if (self
->can_focus
) {
3054 /* This can cause a BadMatch error with CurrentTime, or if an app
3055 passed in a bad time for _NET_WM_ACTIVE_WINDOW. */
3056 xerror_set_ignore(TRUE
);
3057 XSetInputFocus(ob_display
, self
->window
, RevertToPointerRoot
,
3059 xerror_set_ignore(FALSE
);
3062 if (self
->focus_notify
) {
3064 ce
.xclient
.type
= ClientMessage
;
3065 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
3066 ce
.xclient
.display
= ob_display
;
3067 ce
.xclient
.window
= self
->window
;
3068 ce
.xclient
.format
= 32;
3069 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_take_focus
;
3070 ce
.xclient
.data
.l
[1] = event_curtime
;
3071 ce
.xclient
.data
.l
[2] = 0l;
3072 ce
.xclient
.data
.l
[3] = 0l;
3073 ce
.xclient
.data
.l
[4] = 0l;
3074 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
3078 ob_debug("%sively focusing %lx at %d\n",
3079 (self
->can_focus
? "act" : "pass"),
3080 self
->window
, (gint
) event_curtime
);
3083 /* Cause the FocusIn to come back to us. Important for desktop switches,
3084 since otherwise we'll have no FocusIn on the queue and send it off to
3085 the focus_backup. */
3086 XSync(ob_display
, FALSE
);
3090 void client_activate(ObClient
*self
, gboolean here
, gboolean user
)
3092 guint32 last_time
= focus_client
? focus_client
->user_time
: CurrentTime
;
3094 /* XXX do some stuff here if user is false to determine if we really want
3095 to activate it or not (a parent or group member is currently
3098 ob_debug_type(OB_DEBUG_FOCUS
,
3099 "Want to activate window 0x%x with time %u (last time %u), "
3101 self
->window
, event_curtime
, last_time
,
3102 (user
? "user" : "application"));
3104 if (!user
&& event_curtime
&& last_time
&&
3105 !event_time_after(event_curtime
, last_time
))
3107 client_hilite(self
, TRUE
);
3109 /* if using focus_delay, stop the timer now so that focus doesn't
3111 event_halt_focus_delay();
3113 if (client_normal(self
) && screen_showing_desktop
)
3114 screen_show_desktop(FALSE
);
3116 client_iconify(self
, FALSE
, here
);
3117 if (self
->desktop
!= DESKTOP_ALL
&&
3118 self
->desktop
!= screen_desktop
) {
3120 client_set_desktop(self
, screen_desktop
, FALSE
);
3122 screen_set_desktop(self
->desktop
);
3123 } else if (!self
->frame
->visible
)
3124 /* if its not visible for other reasons, then don't mess
3128 client_shade(self
, FALSE
);
3132 /* we do this as an action here. this is rather important. this is
3133 because we want the results from the focus change to take place
3134 BEFORE we go about raising the window. when a fullscreen window
3135 loses focus, we need this or else the raise wont be able to raise
3136 above the to-lose-focus fullscreen window. */
3141 void client_raise(ObClient
*self
)
3143 action_run_string("Raise", self
, CurrentTime
);
3146 void client_lower(ObClient
*self
)
3148 action_run_string("Lower", self
, CurrentTime
);
3151 gboolean
client_focused(ObClient
*self
)
3153 return self
== focus_client
;
3156 static ObClientIcon
* client_icon_recursive(ObClient
*self
, gint w
, gint h
)
3159 /* si is the smallest image >= req */
3160 /* li is the largest image < req */
3161 gulong size
, smallest
= 0xffffffff, largest
= 0, si
= 0, li
= 0;
3163 if (!self
->nicons
) {
3164 ObClientIcon
*parent
= NULL
;
3166 if (self
->transient_for
) {
3167 if (self
->transient_for
!= OB_TRAN_GROUP
)
3168 parent
= client_icon_recursive(self
->transient_for
, w
, h
);
3171 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
3172 ObClient
*c
= it
->data
;
3173 if (c
!= self
&& !c
->transient_for
) {
3174 if ((parent
= client_icon_recursive(c
, w
, h
)))
3184 for (i
= 0; i
< self
->nicons
; ++i
) {
3185 size
= self
->icons
[i
].width
* self
->icons
[i
].height
;
3186 if (size
< smallest
&& size
>= (unsigned)(w
* h
)) {
3190 if (size
> largest
&& size
<= (unsigned)(w
* h
)) {
3195 if (largest
== 0) /* didnt find one smaller than the requested size */
3196 return &self
->icons
[si
];
3197 return &self
->icons
[li
];
3200 const ObClientIcon
* client_icon(ObClient
*self
, gint w
, gint h
)
3203 static ObClientIcon deficon
;
3205 if (!(ret
= client_icon_recursive(self
, w
, h
))) {
3206 deficon
.width
= deficon
.height
= 48;
3207 deficon
.data
= ob_rr_theme
->def_win_icon
;
3213 void client_set_layer(ObClient
*self
, gint layer
)
3217 self
->above
= FALSE
;
3218 } else if (layer
== 0) {
3219 self
->below
= self
->above
= FALSE
;
3221 self
->below
= FALSE
;
3224 client_calc_layer(self
);
3225 client_change_state(self
); /* reflect this in the state hints */
3228 void client_set_undecorated(ObClient
*self
, gboolean undecorated
)
3230 if (self
->undecorated
!= undecorated
) {
3231 self
->undecorated
= undecorated
;
3232 client_setup_decor_and_functions(self
);
3233 /* Make sure the client knows it might have moved. Maybe there is a
3234 * better way of doing this so only one client_configure is sent, but
3235 * since 125 of these are sent per second when moving the window (with
3236 * user = FALSE) i doubt it matters much.
3238 client_configure(self
, OB_CORNER_TOPLEFT
, self
->area
.x
, self
->area
.y
,
3239 self
->area
.width
, self
->area
.height
, TRUE
, TRUE
);
3240 client_change_state(self
); /* reflect this in the state hints */
3244 guint
client_monitor(ObClient
*self
)
3246 return screen_find_monitor(&self
->frame
->area
);
3249 ObClient
*client_search_top_parent(ObClient
*self
)
3251 while (self
->transient_for
&& self
->transient_for
!= OB_TRAN_GROUP
&&
3252 client_normal(self
))
3253 self
= self
->transient_for
;
3257 GSList
*client_search_all_top_parents(ObClient
*self
)
3261 /* move up the direct transient chain as far as possible */
3262 while (self
->transient_for
&& self
->transient_for
!= OB_TRAN_GROUP
)
3263 self
= self
->transient_for
;
3265 if (!self
->transient_for
)
3266 ret
= g_slist_prepend(ret
, self
);
3270 g_assert(self
->group
);
3272 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
3273 ObClient
*c
= it
->data
;
3275 if (!c
->transient_for
&& client_normal(c
))
3276 ret
= g_slist_prepend(ret
, c
);
3279 if (ret
== NULL
) /* no group parents */
3280 ret
= g_slist_prepend(ret
, self
);
3286 ObClient
*client_search_focus_parent(ObClient
*self
)
3288 if (self
->transient_for
) {
3289 if (self
->transient_for
!= OB_TRAN_GROUP
) {
3290 if (client_focused(self
->transient_for
))
3291 return self
->transient_for
;
3295 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
3296 ObClient
*c
= it
->data
;
3298 /* checking transient_for prevents infinate loops! */
3299 if (c
!= self
&& !c
->transient_for
)
3300 if (client_focused(c
))
3309 ObClient
*client_search_parent(ObClient
*self
, ObClient
*search
)
3311 if (self
->transient_for
) {
3312 if (self
->transient_for
!= OB_TRAN_GROUP
) {
3313 if (self
->transient_for
== search
)
3318 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
3319 ObClient
*c
= it
->data
;
3321 /* checking transient_for prevents infinate loops! */
3322 if (c
!= self
&& !c
->transient_for
)
3332 ObClient
*client_search_transient(ObClient
*self
, ObClient
*search
)
3336 for (sit
= self
->transients
; sit
; sit
= g_slist_next(sit
)) {
3337 if (sit
->data
== search
)
3339 if (client_search_transient(sit
->data
, search
))
3345 void client_update_sm_client_id(ObClient
*self
)
3347 g_free(self
->sm_client_id
);
3348 self
->sm_client_id
= NULL
;
3350 if (!PROP_GETS(self
->window
, sm_client_id
, locale
, &self
->sm_client_id
) &&
3352 PROP_GETS(self
->group
->leader
, sm_client_id
, locale
,
3353 &self
->sm_client_id
);
3356 #define WANT_EDGE(cur, c) \
3359 if(!client_normal(cur)) \
3361 if(screen_desktop != cur->desktop && cur->desktop != DESKTOP_ALL) \
3365 if(cur->layer < c->layer && !config_resist_layers_below) \
3368 #define HIT_EDGE(my_edge_start, my_edge_end, his_edge_start, his_edge_end) \
3369 if ((his_edge_start >= my_edge_start && \
3370 his_edge_start <= my_edge_end) || \
3371 (my_edge_start >= his_edge_start && \
3372 my_edge_start <= his_edge_end)) \
3375 /* finds the nearest edge in the given direction from the current client
3376 * note to self: the edge is the -frame- edge (the actual one), not the
3379 gint
client_directional_edge_search(ObClient
*c
, ObDirection dir
, gboolean hang
)
3381 gint dest
, monitor_dest
;
3382 gint my_edge_start
, my_edge_end
, my_offset
;
3389 a
= screen_area(c
->desktop
);
3390 monitor
= screen_area_monitor(c
->desktop
, client_monitor(c
));
3393 case OB_DIRECTION_NORTH
:
3394 my_edge_start
= c
->frame
->area
.x
;
3395 my_edge_end
= c
->frame
->area
.x
+ c
->frame
->area
.width
;
3396 my_offset
= c
->frame
->area
.y
+ (hang
? c
->frame
->area
.height
: 0);
3398 /* default: top of screen */
3399 dest
= a
->y
+ (hang
? c
->frame
->area
.height
: 0);
3400 monitor_dest
= monitor
->y
+ (hang
? c
->frame
->area
.height
: 0);
3401 /* if the monitor edge comes before the screen edge, */
3402 /* use that as the destination instead. (For xinerama) */
3403 if (monitor_dest
!= dest
&& my_offset
> monitor_dest
)
3404 dest
= monitor_dest
;
3406 for(it
= client_list
; it
&& my_offset
!= dest
; it
= g_list_next(it
)) {
3407 gint his_edge_start
, his_edge_end
, his_offset
;
3408 ObClient
*cur
= it
->data
;
3412 his_edge_start
= cur
->frame
->area
.x
;
3413 his_edge_end
= cur
->frame
->area
.x
+ cur
->frame
->area
.width
;
3414 his_offset
= cur
->frame
->area
.y
+
3415 (hang
? 0 : cur
->frame
->area
.height
);
3417 if(his_offset
+ 1 > my_offset
)
3420 if(his_offset
< dest
)
3423 HIT_EDGE(my_edge_start
, my_edge_end
, his_edge_start
, his_edge_end
)
3426 case OB_DIRECTION_SOUTH
:
3427 my_edge_start
= c
->frame
->area
.x
;
3428 my_edge_end
= c
->frame
->area
.x
+ c
->frame
->area
.width
;
3429 my_offset
= c
->frame
->area
.y
+ (hang
? 0 : c
->frame
->area
.height
);
3431 /* default: bottom of screen */
3432 dest
= a
->y
+ a
->height
- (hang
? c
->frame
->area
.height
: 0);
3433 monitor_dest
= monitor
->y
+ monitor
->height
-
3434 (hang
? c
->frame
->area
.height
: 0);
3435 /* if the monitor edge comes before the screen edge, */
3436 /* use that as the destination instead. (For xinerama) */
3437 if (monitor_dest
!= dest
&& my_offset
< monitor_dest
)
3438 dest
= monitor_dest
;
3440 for(it
= client_list
; it
&& my_offset
!= dest
; it
= g_list_next(it
)) {
3441 gint his_edge_start
, his_edge_end
, his_offset
;
3442 ObClient
*cur
= it
->data
;
3446 his_edge_start
= cur
->frame
->area
.x
;
3447 his_edge_end
= cur
->frame
->area
.x
+ cur
->frame
->area
.width
;
3448 his_offset
= cur
->frame
->area
.y
+
3449 (hang
? cur
->frame
->area
.height
: 0);
3452 if(his_offset
- 1 < my_offset
)
3455 if(his_offset
> dest
)
3458 HIT_EDGE(my_edge_start
, my_edge_end
, his_edge_start
, his_edge_end
)
3461 case OB_DIRECTION_WEST
:
3462 my_edge_start
= c
->frame
->area
.y
;
3463 my_edge_end
= c
->frame
->area
.y
+ c
->frame
->area
.height
;
3464 my_offset
= c
->frame
->area
.x
+ (hang
? c
->frame
->area
.width
: 0);
3466 /* default: leftmost egde of screen */
3467 dest
= a
->x
+ (hang
? c
->frame
->area
.width
: 0);
3468 monitor_dest
= monitor
->x
+ (hang
? c
->frame
->area
.width
: 0);
3469 /* if the monitor edge comes before the screen edge, */
3470 /* use that as the destination instead. (For xinerama) */
3471 if (monitor_dest
!= dest
&& my_offset
> monitor_dest
)
3472 dest
= monitor_dest
;
3474 for(it
= client_list
; it
&& my_offset
!= dest
; it
= g_list_next(it
)) {
3475 gint his_edge_start
, his_edge_end
, his_offset
;
3476 ObClient
*cur
= it
->data
;
3480 his_edge_start
= cur
->frame
->area
.y
;
3481 his_edge_end
= cur
->frame
->area
.y
+ cur
->frame
->area
.height
;
3482 his_offset
= cur
->frame
->area
.x
+
3483 (hang
? 0 : cur
->frame
->area
.width
);
3485 if(his_offset
+ 1 > my_offset
)
3488 if(his_offset
< dest
)
3491 HIT_EDGE(my_edge_start
, my_edge_end
, his_edge_start
, his_edge_end
)
3494 case OB_DIRECTION_EAST
:
3495 my_edge_start
= c
->frame
->area
.y
;
3496 my_edge_end
= c
->frame
->area
.y
+ c
->frame
->area
.height
;
3497 my_offset
= c
->frame
->area
.x
+ (hang
? 0 : c
->frame
->area
.width
);
3499 /* default: rightmost edge of screen */
3500 dest
= a
->x
+ a
->width
- (hang
? c
->frame
->area
.width
: 0);
3501 monitor_dest
= monitor
->x
+ monitor
->width
-
3502 (hang
? c
->frame
->area
.width
: 0);
3503 /* if the monitor edge comes before the screen edge, */
3504 /* use that as the destination instead. (For xinerama) */
3505 if (monitor_dest
!= dest
&& my_offset
< monitor_dest
)
3506 dest
= monitor_dest
;
3508 for(it
= client_list
; it
&& my_offset
!= dest
; it
= g_list_next(it
)) {
3509 gint his_edge_start
, his_edge_end
, his_offset
;
3510 ObClient
*cur
= it
->data
;
3514 his_edge_start
= cur
->frame
->area
.y
;
3515 his_edge_end
= cur
->frame
->area
.y
+ cur
->frame
->area
.height
;
3516 his_offset
= cur
->frame
->area
.x
+
3517 (hang
? cur
->frame
->area
.width
: 0);
3519 if(his_offset
- 1 < my_offset
)
3522 if(his_offset
> dest
)
3525 HIT_EDGE(my_edge_start
, my_edge_end
, his_edge_start
, his_edge_end
)
3528 case OB_DIRECTION_NORTHEAST
:
3529 case OB_DIRECTION_SOUTHEAST
:
3530 case OB_DIRECTION_NORTHWEST
:
3531 case OB_DIRECTION_SOUTHWEST
:
3532 /* not implemented */
3534 g_assert_not_reached();
3535 dest
= 0; /* suppress warning */
3540 ObClient
* client_under_pointer()
3544 ObClient
*ret
= NULL
;
3546 if (screen_pointer_pos(&x
, &y
)) {
3547 for (it
= stacking_list
; it
; it
= g_list_next(it
)) {
3548 if (WINDOW_IS_CLIENT(it
->data
)) {
3549 ObClient
*c
= WINDOW_AS_CLIENT(it
->data
);
3550 if (c
->frame
->visible
&&
3551 RECT_CONTAINS(c
->frame
->area
, x
, y
)) {
3561 gboolean
client_has_group_siblings(ObClient
*self
)
3563 return self
->group
&& self
->group
->members
->next
;