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
= focus_client
? focus_client
->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
,
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 mouse_grab_for_client(self
, TRUE
);
380 guint32 last_time
= focus_client
?
381 focus_client
->user_time
: CurrentTime
;
383 /* This is focus stealing prevention */
384 ob_debug_type(OB_DEBUG_FOCUS
,
385 "Want to focus new window 0x%x with time %u "
387 self
->window
, self
->user_time
, last_time
);
389 /* if it's on another desktop */
390 if (!(self
->desktop
== screen_desktop
|| self
->desktop
== DESKTOP_ALL
)
391 && /* the timestamp is from before you changed desktops */
392 self
->user_time
&& screen_desktop_user_time
&&
393 !event_time_after(self
->user_time
, screen_desktop_user_time
))
396 ob_debug_type(OB_DEBUG_FOCUS
,
397 "Not focusing the window because its on another "
400 /* If something is focused, and it's not our parent... */
401 else if (focus_client
&& client_search_focus_parent(self
) == NULL
)
403 /* If time stamp is old, don't steal focus */
404 if (self
->user_time
&& last_time
&&
405 !event_time_after(self
->user_time
, last_time
))
408 ob_debug_type(OB_DEBUG_FOCUS
,
409 "Not focusing the window because the time is "
412 /* Don't steal focus from globally active clients.
413 I stole this idea from KWin. It seems nice.
415 if (!(focus_client
->can_focus
|| focus_client
->focus_notify
)) {
417 ob_debug_type(OB_DEBUG_FOCUS
,
418 "Not focusing the window because a globally "
419 "active client has focus\n");
424 ob_debug_type(OB_DEBUG_FOCUS
,
425 "Focus stealing prevention activated for %s with "
426 "time %u (last time %u)\n",
427 self
->title
, self
->user_time
, last_time
);
428 /* if the client isn't focused, then hilite it so the user
430 client_hilite(self
, TRUE
);
434 /* This may look rather odd. Well it's because new windows are added
435 to the stacking order non-intrusively. If we're not going to focus
436 the new window or hilite it, then we raise it to the top. This will
437 take affect for things that don't get focused like splash screens.
438 Also if you don't have focus_new enabled, then it's going to get
439 raised to the top. Legacy begets legacy I guess?
444 /* this has to happen before we try focus the window, but we want it to
445 happen after the client's stacking has been determined or it looks bad
449 /* use client_focus instead of client_activate cuz client_activate does
450 stuff like switch desktops etc and I'm not interested in all that when
451 a window maps since its not based on an action from the user like
452 clicking a window to activate it. so keep the new window out of the way
455 client_activate(self
, FALSE
, TRUE
);
457 /* add to client list/map */
458 client_list
= g_list_append(client_list
, self
);
459 g_hash_table_insert(window_map
, &self
->window
, self
);
461 /* this has to happen after we're in the client_list */
462 if (STRUT_EXISTS(self
->strut
))
463 screen_update_areas();
465 /* update the list hints */
468 ob_debug("Managed window 0x%lx (%s)\n", window
, self
->class);
471 void client_unmanage_all()
473 while (client_list
!= NULL
)
474 client_unmanage(client_list
->data
);
477 void client_unmanage(ObClient
*self
)
482 ob_debug("Unmanaging window: %lx (%s) (%s)\n", self
->window
, self
->class,
483 self
->title
? self
->title
: "");
485 g_assert(self
!= NULL
);
487 /* we dont want events no more. do this before hiding the frame so we
488 don't generate more events */
489 XSelectInput(ob_display
, self
->window
, NoEventMask
);
491 frame_hide(self
->frame
);
492 /* flush to send the hide to the server quickly */
495 /* ignore enter events from the unmap so it doesnt mess with the focus */
496 event_ignore_queued_enters();
498 mouse_grab_for_client(self
, FALSE
);
500 /* remove the window from our save set */
501 XChangeSaveSet(ob_display
, self
->window
, SetModeDelete
);
503 /* update the focus lists */
504 focus_order_remove(self
);
505 if (client_focused(self
)) {
506 /* don't leave an invalid focus_client */
510 client_list
= g_list_remove(client_list
, self
);
511 stacking_remove(self
);
512 g_hash_table_remove(window_map
, &self
->window
);
514 /* once the client is out of the list, update the struts to remove its
516 if (STRUT_EXISTS(self
->strut
))
517 screen_update_areas();
519 for (it
= client_destructors
; it
; it
= g_slist_next(it
)) {
520 Destructor
*d
= it
->data
;
521 d
->func(self
, d
->data
);
524 /* tell our parent(s) that we're gone */
525 if (self
->transient_for
== OB_TRAN_GROUP
) { /* transient of group */
526 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
))
527 if (it
->data
!= self
)
528 ((ObClient
*)it
->data
)->transients
=
529 g_slist_remove(((ObClient
*)it
->data
)->transients
, self
);
530 } else if (self
->transient_for
) { /* transient of window */
531 self
->transient_for
->transients
=
532 g_slist_remove(self
->transient_for
->transients
, self
);
535 /* tell our transients that we're gone */
536 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
537 if (((ObClient
*)it
->data
)->transient_for
!= OB_TRAN_GROUP
) {
538 ((ObClient
*)it
->data
)->transient_for
= NULL
;
539 client_calc_layer(it
->data
);
543 /* remove from its group */
545 group_remove(self
->group
, self
);
549 /* restore the window's original geometry so it is not lost */
553 if (self
->fullscreen
)
554 a
= self
->pre_fullscreen_area
;
555 else if (self
->max_horz
|| self
->max_vert
) {
556 if (self
->max_horz
) {
557 a
.x
= self
->pre_max_area
.x
;
558 a
.width
= self
->pre_max_area
.width
;
560 if (self
->max_vert
) {
561 a
.y
= self
->pre_max_area
.y
;
562 a
.height
= self
->pre_max_area
.height
;
566 /* give the client its border back */
567 client_toggle_border(self
, TRUE
);
569 self
->fullscreen
= self
->max_horz
= self
->max_vert
= FALSE
;
570 self
->decorations
= 0; /* unmanaged windows have no decor */
572 client_move_resize(self
, a
.x
, a
.y
, a
.width
, a
.height
);
575 /* reparent the window out of the frame, and free the frame */
576 frame_release_client(self
->frame
, self
);
579 if (ob_state() != OB_STATE_EXITING
) {
580 /* these values should not be persisted across a window
582 PROP_ERASE(self
->window
, net_wm_desktop
);
583 PROP_ERASE(self
->window
, net_wm_state
);
584 PROP_ERASE(self
->window
, wm_state
);
586 /* if we're left in an unmapped state, the client wont be mapped. this
587 is bad, since we will no longer be managing the window on restart */
588 XMapWindow(ob_display
, self
->window
);
591 ob_debug("Unmanaged window 0x%lx\n", self
->window
);
593 /* free all data allocated in the client struct */
594 g_slist_free(self
->transients
);
595 for (j
= 0; j
< self
->nicons
; ++j
)
596 g_free(self
->icons
[j
].data
);
597 if (self
->nicons
> 0)
600 g_free(self
->icon_title
);
604 g_free(self
->client_machine
);
605 g_free(self
->sm_client_id
);
608 /* update the list hints */
612 static ObAppSettings
*client_get_settings_state(ObClient
*self
)
614 ObAppSettings
*settings
= NULL
;
617 for (it
= config_per_app_settings
; it
; it
= g_slist_next(it
)) {
618 ObAppSettings
*app
= it
->data
;
620 if ((app
->name
&& !app
->class && !strcmp(app
->name
, self
->name
))
621 || (app
->class && !app
->name
&& !strcmp(app
->class, self
->class))
622 || (app
->class && app
->name
&& !strcmp(app
->class, self
->class)
623 && !strcmp(app
->name
, self
->name
)))
625 ob_debug("Window matching: %s\n", app
->name
);
626 /* Match if no role was specified in the per app setting, or if the
627 * string matches the beginning of the role, since apps like to set
628 * the role to things like browser-window-23c4b2f */
630 || !strncmp(app
->role
, self
->role
, strlen(app
->role
)))
640 if (settings
->shade
!= -1)
641 self
->shaded
= !!settings
->shade
;
642 if (settings
->decor
!= -1)
643 self
->undecorated
= !settings
->decor
;
644 if (settings
->iconic
!= -1)
645 self
->iconic
= !!settings
->iconic
;
646 if (settings
->skip_pager
!= -1)
647 self
->skip_pager
= !!settings
->skip_pager
;
648 if (settings
->skip_taskbar
!= -1)
649 self
->skip_taskbar
= !!settings
->skip_taskbar
;
651 if (settings
->max_vert
!= -1)
652 self
->max_vert
= !!settings
->max_vert
;
653 if (settings
->max_horz
!= -1)
654 self
->max_horz
= !!settings
->max_horz
;
656 if (settings
->fullscreen
!= -1)
657 self
->fullscreen
= !!settings
->fullscreen
;
659 if (settings
->desktop
< screen_num_desktops
660 || settings
->desktop
== DESKTOP_ALL
)
661 self
->desktop
= settings
->desktop
;
663 if (settings
->layer
== -1) {
667 else if (settings
->layer
== 0) {
671 else if (settings
->layer
== 1) {
679 static void client_restore_session_state(ObClient
*self
)
683 if (!(it
= session_state_find(self
)))
686 self
->session
= it
->data
;
688 RECT_SET_POINT(self
->area
, self
->session
->x
, self
->session
->y
);
689 self
->positioned
= PPosition
;
690 if (self
->session
->w
> 0)
691 self
->area
.width
= self
->session
->w
;
692 if (self
->session
->h
> 0)
693 self
->area
.height
= self
->session
->h
;
694 XResizeWindow(ob_display
, self
->window
,
695 self
->area
.width
, self
->area
.height
);
697 self
->desktop
= (self
->session
->desktop
== DESKTOP_ALL
?
698 self
->session
->desktop
:
699 MIN(screen_num_desktops
- 1, self
->session
->desktop
));
700 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, self
->desktop
);
702 self
->shaded
= self
->session
->shaded
;
703 self
->iconic
= self
->session
->iconic
;
704 self
->skip_pager
= self
->session
->skip_pager
;
705 self
->skip_taskbar
= self
->session
->skip_taskbar
;
706 self
->fullscreen
= self
->session
->fullscreen
;
707 self
->above
= self
->session
->above
;
708 self
->below
= self
->session
->below
;
709 self
->max_horz
= self
->session
->max_horz
;
710 self
->max_vert
= self
->session
->max_vert
;
713 static void client_restore_session_stacking(ObClient
*self
)
717 if (!self
->session
) return;
719 it
= g_list_find(session_saved_state
, self
->session
);
720 for (it
= g_list_previous(it
); it
; it
= g_list_previous(it
)) {
723 for (cit
= client_list
; cit
; cit
= g_list_next(cit
))
724 if (session_state_cmp(it
->data
, cit
->data
))
727 client_calc_layer(self
);
728 stacking_below(CLIENT_AS_WINDOW(self
),
729 CLIENT_AS_WINDOW(cit
->data
));
735 void client_move_onscreen(ObClient
*self
, gboolean rude
)
737 gint x
= self
->area
.x
;
738 gint y
= self
->area
.y
;
739 if (client_find_onscreen(self
, &x
, &y
,
741 self
->area
.height
, rude
)) {
742 client_move(self
, x
, y
);
746 gboolean
client_find_onscreen(ObClient
*self
, gint
*x
, gint
*y
, gint w
, gint h
,
750 gint ox
= *x
, oy
= *y
;
751 gboolean rudel
= rude
, ruder
= rude
, rudet
= rude
, rudeb
= rude
;
754 all_a
= screen_area(self
->desktop
);
755 mon_a
= screen_area_monitor(self
->desktop
, client_monitor(self
));
757 /* get where the frame would be */
758 frame_client_gravity(self
->frame
, x
, y
, w
, h
);
760 /* get the requested size of the window with decorations */
761 fw
= self
->frame
->size
.left
+ w
+ self
->frame
->size
.right
;
762 fh
= self
->frame
->size
.top
+ h
+ self
->frame
->size
.bottom
;
764 /* This makes sure windows aren't entirely outside of the screen so you
765 can't see them at all.
766 It makes sure 10% of the window is on the screen at least. At don't let
767 it move itself off the top of the screen, which would hide the titlebar
768 on you. (The user can still do this if they want too, it's only limiting
771 XXX watch for xinerama dead areas...
773 if (client_normal(self
)) {
774 if (!self
->strut
.right
&& *x
+ fw
/10 >= all_a
->x
+ all_a
->width
- 1)
775 *x
= all_a
->x
+ all_a
->width
- fw
/10;
776 if (!self
->strut
.bottom
&& *y
+ fh
/10 >= all_a
->y
+ all_a
->height
- 1)
777 *y
= all_a
->y
+ all_a
->height
- fh
/10;
778 if (!self
->strut
.left
&& *x
+ fw
*9/10 - 1 < all_a
->x
)
779 *x
= all_a
->x
- fw
*9/10;
780 if (!self
->strut
.top
&& *y
+ fh
*9/10 - 1 < all_a
->y
)
781 *y
= all_a
->y
- fw
*9/10;
784 /* If rudeness wasn't requested, then figure out of the client is currently
785 entirely on the screen. If it is, and the position isn't changing by
786 request, and it is enlarging, then be rude even though it wasn't
789 Point oldtl
, oldtr
, oldbl
, oldbr
;
790 Point newtl
, newtr
, newbl
, newbr
;
793 POINT_SET(oldtl
, self
->frame
->area
.x
, self
->frame
->area
.y
);
794 POINT_SET(oldbr
, self
->frame
->area
.x
+ self
->frame
->area
.width
- 1,
795 self
->frame
->area
.y
+ self
->frame
->area
.height
- 1);
796 POINT_SET(oldtr
, oldbr
.x
, oldtl
.y
);
797 POINT_SET(oldbl
, oldtl
.x
, oldbr
.y
);
799 POINT_SET(newtl
, *x
, *y
);
800 POINT_SET(newbr
, *x
+ fw
- 1, *y
+ fh
- 1);
801 POINT_SET(newtr
, newbr
.x
, newtl
.y
);
802 POINT_SET(newbl
, newtl
.x
, newbr
.y
);
804 /* is it moving or just resizing from some corner? */
805 stationary
= (POINT_EQUAL(oldtl
, newtl
) || POINT_EQUAL(oldtr
, newtr
) ||
806 POINT_EQUAL(oldbl
, newbl
) || POINT_EQUAL(oldbr
, newbr
));
808 /* if left edge is growing */
809 if (stationary
&& newtl
.x
< oldtl
.x
)
811 /* if right edge is growing */
812 if (stationary
&& newtr
.x
> oldtr
.x
)
814 /* if top edge is growing */
815 if (stationary
&& newtl
.y
< oldtl
.y
)
817 /* if bottom edge is growing */
818 if (stationary
&& newbl
.y
> oldbl
.y
)
822 /* This here doesn't let windows even a pixel outside the struts/screen.
823 * When called from client_manage, programs placing themselves are
824 * forced completely onscreen, while things like
825 * xterm -geometry resolution-width/2 will work fine. Trying to
826 * place it completely offscreen will be handled in the above code.
827 * Sorry for this confused comment, i am tired. */
828 if (fw
<= mon_a
->width
) {
829 if (rudel
&& !self
->strut
.left
&& *x
< mon_a
->x
) *x
= mon_a
->x
;
830 if (ruder
&& !self
->strut
.right
&& *x
+ fw
> mon_a
->x
+ mon_a
->width
)
831 *x
= mon_a
->x
+ mon_a
->width
- fw
;
833 if (fh
<= mon_a
->height
) {
834 if (rudet
&& !self
->strut
.top
&& *y
< mon_a
->y
) *y
= mon_a
->y
;
835 if (rudeb
&& !self
->strut
.bottom
&& *y
+ fh
> mon_a
->y
+ mon_a
->height
)
836 *y
= mon_a
->y
+ mon_a
->height
- fh
;
839 /* get where the client should be */
840 frame_frame_gravity(self
->frame
, x
, y
, w
, h
);
842 return ox
!= *x
|| oy
!= *y
;
845 static void client_toggle_border(ObClient
*self
, gboolean show
)
847 /* adjust our idea of where the client is, based on its border. When the
848 border is removed, the client should now be considered to be in a
850 when re-adding the border to the client, the same operation needs to be
852 gint oldx
= self
->area
.x
, oldy
= self
->area
.y
;
853 gint x
= oldx
, y
= oldy
;
854 switch(self
->gravity
) {
856 case NorthWestGravity
:
858 case SouthWestGravity
:
860 case NorthEastGravity
:
862 case SouthEastGravity
:
863 if (show
) x
-= self
->border_width
* 2;
864 else x
+= self
->border_width
* 2;
871 if (show
) x
-= self
->border_width
;
872 else x
+= self
->border_width
;
875 switch(self
->gravity
) {
877 case NorthWestGravity
:
879 case NorthEastGravity
:
881 case SouthWestGravity
:
883 case SouthEastGravity
:
884 if (show
) y
-= self
->border_width
* 2;
885 else y
+= self
->border_width
* 2;
892 if (show
) y
-= self
->border_width
;
893 else y
+= self
->border_width
;
900 XSetWindowBorderWidth(ob_display
, self
->window
, self
->border_width
);
902 /* set border_width to 0 because there is no border to add into
903 calculations anymore */
904 self
->border_width
= 0;
906 XSetWindowBorderWidth(ob_display
, self
->window
, 0);
910 static void client_get_all(ObClient
*self
)
912 client_get_area(self
);
913 client_get_mwm_hints(self
);
915 /* The transient hint is used to pick a type, but the type can also affect
916 transiency (dialogs are always made transients of their group if they
917 have one). This is Havoc's idea, but it is needed to make some apps
918 work right (eg tsclient). */
919 client_update_transient_for(self
);
920 client_get_type(self
);/* this can change the mwmhints for special cases */
921 client_get_state(self
);
922 client_update_transient_for(self
);
924 client_update_wmhints(self
);
925 client_get_startup_id(self
);
926 client_get_desktop(self
);/* uses transient data/group/startup id if a
927 desktop is not specified */
928 client_get_shaped(self
);
930 client_get_layer(self
); /* if layer hasn't been specified, get it from
931 other sources if possible */
934 /* a couple type-based defaults for new windows */
936 /* this makes sure that these windows appear on all desktops */
937 if (self
->type
== OB_CLIENT_TYPE_DESKTOP
)
938 self
->desktop
= DESKTOP_ALL
;
941 client_update_protocols(self
);
943 client_get_gravity(self
); /* get the attribute gravity */
944 client_update_normal_hints(self
); /* this may override the attribute
947 /* got the type, the mwmhints, the protocols, and the normal hints
948 (min/max sizes), so we're ready to set up the decorations/functions */
949 client_setup_decor_and_functions(self
);
952 client_update_sync_request_counter(self
);
954 client_get_client_machine(self
);
955 client_get_colormap(self
);
956 client_update_title(self
);
957 client_update_class(self
);
958 client_update_sm_client_id(self
);
959 client_update_strut(self
);
960 client_update_icons(self
);
961 client_update_user_time(self
);
964 static void client_get_startup_id(ObClient
*self
)
966 if (!(PROP_GETS(self
->window
, net_startup_id
, utf8
, &self
->startup_id
)))
968 PROP_GETS(self
->group
->leader
,
969 net_startup_id
, utf8
, &self
->startup_id
);
972 static void client_get_area(ObClient
*self
)
974 XWindowAttributes wattrib
;
977 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
978 g_assert(ret
!= BadWindow
);
980 RECT_SET(self
->area
, wattrib
.x
, wattrib
.y
, wattrib
.width
, wattrib
.height
);
981 POINT_SET(self
->root_pos
, wattrib
.x
, wattrib
.y
);
982 self
->border_width
= wattrib
.border_width
;
984 ob_debug("client area: %d %d %d %d\n", wattrib
.x
, wattrib
.y
,
985 wattrib
.width
, wattrib
.height
);
988 static void client_get_desktop(ObClient
*self
)
990 guint32 d
= screen_num_desktops
; /* an always-invalid value */
992 if (PROP_GET32(self
->window
, net_wm_desktop
, cardinal
, &d
)) {
993 if (d
>= screen_num_desktops
&& d
!= DESKTOP_ALL
)
994 self
->desktop
= screen_num_desktops
- 1;
998 gboolean trdesk
= FALSE
;
1000 if (self
->transient_for
) {
1001 if (self
->transient_for
!= OB_TRAN_GROUP
) {
1002 self
->desktop
= self
->transient_for
->desktop
;
1007 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
))
1008 if (it
->data
!= self
&&
1009 !((ObClient
*)it
->data
)->transient_for
) {
1010 self
->desktop
= ((ObClient
*)it
->data
)->desktop
;
1017 /* try get from the startup-notification protocol */
1018 if (sn_get_desktop(self
->startup_id
, &self
->desktop
)) {
1019 if (self
->desktop
>= screen_num_desktops
&&
1020 self
->desktop
!= DESKTOP_ALL
)
1021 self
->desktop
= screen_num_desktops
- 1;
1023 /* defaults to the current desktop */
1024 self
->desktop
= screen_desktop
;
1029 static void client_get_layer(ObClient
*self
)
1031 if (!(self
->above
|| self
->below
)) {
1033 /* apply stuff from the group */
1037 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
1038 ObClient
*c
= it
->data
;
1039 if (c
!= self
&& !client_search_transient(self
, c
) &&
1040 client_normal(self
) && client_normal(c
))
1043 (c
->above
? 1 : (c
->below
? -1 : 0)));
1057 g_assert_not_reached();
1064 static void client_get_state(ObClient
*self
)
1069 if (PROP_GETA32(self
->window
, net_wm_state
, atom
, &state
, &num
)) {
1071 for (i
= 0; i
< num
; ++i
) {
1072 if (state
[i
] == prop_atoms
.net_wm_state_modal
)
1074 else if (state
[i
] == prop_atoms
.net_wm_state_shaded
)
1075 self
->shaded
= TRUE
;
1076 else if (state
[i
] == prop_atoms
.net_wm_state_hidden
)
1077 self
->iconic
= TRUE
;
1078 else if (state
[i
] == prop_atoms
.net_wm_state_skip_taskbar
)
1079 self
->skip_taskbar
= TRUE
;
1080 else if (state
[i
] == prop_atoms
.net_wm_state_skip_pager
)
1081 self
->skip_pager
= TRUE
;
1082 else if (state
[i
] == prop_atoms
.net_wm_state_fullscreen
)
1083 self
->fullscreen
= TRUE
;
1084 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_vert
)
1085 self
->max_vert
= TRUE
;
1086 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_horz
)
1087 self
->max_horz
= TRUE
;
1088 else if (state
[i
] == prop_atoms
.net_wm_state_above
)
1090 else if (state
[i
] == prop_atoms
.net_wm_state_below
)
1092 else if (state
[i
] == prop_atoms
.net_wm_state_demands_attention
)
1093 self
->demands_attention
= TRUE
;
1094 else if (state
[i
] == prop_atoms
.ob_wm_state_undecorated
)
1095 self
->undecorated
= TRUE
;
1102 static void client_get_shaped(ObClient
*self
)
1104 self
->shaped
= FALSE
;
1106 if (extensions_shape
) {
1111 XShapeSelectInput(ob_display
, self
->window
, ShapeNotifyMask
);
1113 XShapeQueryExtents(ob_display
, self
->window
, &s
, &foo
,
1114 &foo
, &ufoo
, &ufoo
, &foo
, &foo
, &foo
, &ufoo
,
1116 self
->shaped
= (s
!= 0);
1121 void client_update_transient_for(ObClient
*self
)
1124 ObClient
*target
= NULL
;
1126 if (XGetTransientForHint(ob_display
, self
->window
, &t
)) {
1127 self
->transient
= TRUE
;
1128 if (t
!= self
->window
) { /* cant be transient to itself! */
1129 target
= g_hash_table_lookup(window_map
, &t
);
1130 /* if this happens then we need to check for it*/
1131 g_assert(target
!= self
);
1132 if (target
&& !WINDOW_IS_CLIENT(target
)) {
1133 /* this can happen when a dialog is a child of
1134 a dockapp, for example */
1138 /* THIS IS SO ANNOYING ! ! ! ! Let me explain.... have a seat..
1140 Setting the transient_for to Root is actually illegal, however
1141 applications from time have done this to specify transient for
1144 Now you can do that by being a TYPE_DIALOG and not setting
1145 the transient_for hint at all on your window. But people still
1146 use Root, and Kwin is very strange in this regard.
1148 KWin 3.0 will not consider windows with transient_for set to
1149 Root as transient for their group *UNLESS* they are also modal.
1150 In that case, it will make them transient for the group. This
1151 leads to all sorts of weird behavior from KDE apps which are
1152 only tested in KWin. I'd like to follow their behavior just to
1153 make this work right with KDE stuff, but that seems wrong.
1155 if (!target
&& self
->group
) {
1156 /* not transient to a client, see if it is transient for a
1158 if (t
== RootWindow(ob_display
, ob_screen
)) {
1159 /* window is a transient for its group! */
1160 target
= OB_TRAN_GROUP
;
1164 } else if (self
->group
) {
1165 if (self
->type
== OB_CLIENT_TYPE_DIALOG
||
1166 self
->type
== OB_CLIENT_TYPE_TOOLBAR
||
1167 self
->type
== OB_CLIENT_TYPE_MENU
||
1168 self
->type
== OB_CLIENT_TYPE_UTILITY
)
1170 self
->transient
= TRUE
;
1171 target
= OB_TRAN_GROUP
;
1174 self
->transient
= FALSE
;
1176 /* if anything has changed... */
1177 if (target
!= self
->transient_for
) {
1178 if (self
->transient_for
== OB_TRAN_GROUP
) { /* transient of group */
1181 /* remove from old parents */
1182 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
1183 ObClient
*c
= it
->data
;
1184 if (c
!= self
&& (!c
->transient_for
||
1185 c
->transient_for
!= OB_TRAN_GROUP
))
1186 c
->transients
= g_slist_remove(c
->transients
, self
);
1188 } else if (self
->transient_for
!= NULL
) { /* transient of window */
1189 /* remove from old parent */
1190 self
->transient_for
->transients
=
1191 g_slist_remove(self
->transient_for
->transients
, self
);
1193 self
->transient_for
= target
;
1194 if (self
->transient_for
== OB_TRAN_GROUP
) { /* transient of group */
1197 /* add to new parents */
1198 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
1199 ObClient
*c
= it
->data
;
1200 if (c
!= self
&& (!c
->transient_for
||
1201 c
->transient_for
!= OB_TRAN_GROUP
))
1202 c
->transients
= g_slist_append(c
->transients
, self
);
1205 /* XXX can i remove this ?? */
1207 /* remove all transients which are in the group, that causes
1208 circlular pointer hell of doom */
1209 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
1211 for (sit
= self
->transients
; sit
; sit
= next
) {
1212 next
= g_slist_next(sit
);
1213 if (sit
->data
== it
->data
)
1215 g_slist_delete_link(self
->transients
, sit
);
1218 } else if (self
->transient_for
!= NULL
) { /* transient of window */
1219 /* add to new parent */
1220 self
->transient_for
->transients
=
1221 g_slist_append(self
->transient_for
->transients
, self
);
1226 static void client_get_mwm_hints(ObClient
*self
)
1231 self
->mwmhints
.flags
= 0; /* default to none */
1233 if (PROP_GETA32(self
->window
, motif_wm_hints
, motif_wm_hints
,
1235 if (num
>= OB_MWM_ELEMENTS
) {
1236 self
->mwmhints
.flags
= hints
[0];
1237 self
->mwmhints
.functions
= hints
[1];
1238 self
->mwmhints
.decorations
= hints
[2];
1244 void client_get_type(ObClient
*self
)
1251 if (PROP_GETA32(self
->window
, net_wm_window_type
, atom
, &val
, &num
)) {
1252 /* use the first value that we know about in the array */
1253 for (i
= 0; i
< num
; ++i
) {
1254 if (val
[i
] == prop_atoms
.net_wm_window_type_desktop
)
1255 self
->type
= OB_CLIENT_TYPE_DESKTOP
;
1256 else if (val
[i
] == prop_atoms
.net_wm_window_type_dock
)
1257 self
->type
= OB_CLIENT_TYPE_DOCK
;
1258 else if (val
[i
] == prop_atoms
.net_wm_window_type_toolbar
)
1259 self
->type
= OB_CLIENT_TYPE_TOOLBAR
;
1260 else if (val
[i
] == prop_atoms
.net_wm_window_type_menu
)
1261 self
->type
= OB_CLIENT_TYPE_MENU
;
1262 else if (val
[i
] == prop_atoms
.net_wm_window_type_utility
)
1263 self
->type
= OB_CLIENT_TYPE_UTILITY
;
1264 else if (val
[i
] == prop_atoms
.net_wm_window_type_splash
)
1265 self
->type
= OB_CLIENT_TYPE_SPLASH
;
1266 else if (val
[i
] == prop_atoms
.net_wm_window_type_dialog
)
1267 self
->type
= OB_CLIENT_TYPE_DIALOG
;
1268 else if (val
[i
] == prop_atoms
.net_wm_window_type_normal
)
1269 self
->type
= OB_CLIENT_TYPE_NORMAL
;
1270 else if (val
[i
] == prop_atoms
.kde_net_wm_window_type_override
) {
1271 /* prevent this window from getting any decor or
1273 self
->mwmhints
.flags
&= (OB_MWM_FLAG_FUNCTIONS
|
1274 OB_MWM_FLAG_DECORATIONS
);
1275 self
->mwmhints
.decorations
= 0;
1276 self
->mwmhints
.functions
= 0;
1278 if (self
->type
!= (ObClientType
) -1)
1279 break; /* grab the first legit type */
1284 if (self
->type
== (ObClientType
) -1) {
1285 /*the window type hint was not set, which means we either classify
1286 ourself as a normal window or a dialog, depending on if we are a
1288 if (self
->transient
)
1289 self
->type
= OB_CLIENT_TYPE_DIALOG
;
1291 self
->type
= OB_CLIENT_TYPE_NORMAL
;
1295 void client_update_protocols(ObClient
*self
)
1298 guint num_return
, i
;
1300 self
->focus_notify
= FALSE
;
1301 self
->delete_window
= FALSE
;
1303 if (PROP_GETA32(self
->window
, wm_protocols
, atom
, &proto
, &num_return
)) {
1304 for (i
= 0; i
< num_return
; ++i
) {
1305 if (proto
[i
] == prop_atoms
.wm_delete_window
)
1306 /* this means we can request the window to close */
1307 self
->delete_window
= TRUE
;
1308 else if (proto
[i
] == prop_atoms
.wm_take_focus
)
1309 /* if this protocol is requested, then the window will be
1310 notified whenever we want it to receive focus */
1311 self
->focus_notify
= TRUE
;
1313 else if (proto
[i
] == prop_atoms
.net_wm_sync_request
)
1314 /* if this protocol is requested, then resizing the
1315 window will be synchronized between the frame and the
1317 self
->sync_request
= TRUE
;
1325 void client_update_sync_request_counter(ObClient
*self
)
1329 if (PROP_GET32(self
->window
, net_wm_sync_request_counter
, cardinal
, &i
)) {
1330 self
->sync_counter
= i
;
1332 self
->sync_counter
= None
;
1336 static void client_get_gravity(ObClient
*self
)
1338 XWindowAttributes wattrib
;
1341 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
1342 g_assert(ret
!= BadWindow
);
1343 self
->gravity
= wattrib
.win_gravity
;
1346 void client_get_colormap(ObClient
*self
)
1348 XWindowAttributes wa
;
1350 if (XGetWindowAttributes(ob_display
, self
->window
, &wa
))
1351 client_update_colormap(self
, wa
.colormap
);
1354 void client_update_colormap(ObClient
*self
, Colormap colormap
)
1356 self
->colormap
= colormap
;
1359 void client_update_normal_hints(ObClient
*self
)
1363 gint oldgravity
= self
->gravity
;
1366 self
->min_ratio
= 0.0f
;
1367 self
->max_ratio
= 0.0f
;
1368 SIZE_SET(self
->size_inc
, 1, 1);
1369 SIZE_SET(self
->base_size
, 0, 0);
1370 SIZE_SET(self
->min_size
, 0, 0);
1371 SIZE_SET(self
->max_size
, G_MAXINT
, G_MAXINT
);
1373 /* get the hints from the window */
1374 if (XGetWMNormalHints(ob_display
, self
->window
, &size
, &ret
)) {
1375 /* normal windows can't request placement! har har
1376 if (!client_normal(self))
1378 self
->positioned
= (size
.flags
& (PPosition
|USPosition
));
1380 if (size
.flags
& PWinGravity
) {
1381 self
->gravity
= size
.win_gravity
;
1383 /* if the client has a frame, i.e. has already been mapped and
1384 is changing its gravity */
1385 if (self
->frame
&& self
->gravity
!= oldgravity
) {
1386 /* move our idea of the client's position based on its new
1388 client_convert_gravity(self
, oldgravity
,
1389 &self
->area
.x
, &self
->area
.y
,
1390 self
->area
.width
, self
->area
.height
);
1394 if (size
.flags
& PAspect
) {
1395 if (size
.min_aspect
.y
)
1397 (gfloat
) size
.min_aspect
.x
/ size
.min_aspect
.y
;
1398 if (size
.max_aspect
.y
)
1400 (gfloat
) size
.max_aspect
.x
/ size
.max_aspect
.y
;
1403 if (size
.flags
& PMinSize
)
1404 SIZE_SET(self
->min_size
, size
.min_width
, size
.min_height
);
1406 if (size
.flags
& PMaxSize
)
1407 SIZE_SET(self
->max_size
, size
.max_width
, size
.max_height
);
1409 if (size
.flags
& PBaseSize
)
1410 SIZE_SET(self
->base_size
, size
.base_width
, size
.base_height
);
1412 if (size
.flags
& PResizeInc
&& size
.width_inc
&& size
.height_inc
)
1413 SIZE_SET(self
->size_inc
, size
.width_inc
, size
.height_inc
);
1417 void client_setup_decor_and_functions(ObClient
*self
)
1419 /* start with everything (cept fullscreen) */
1421 (OB_FRAME_DECOR_TITLEBAR
|
1422 OB_FRAME_DECOR_HANDLE
|
1423 OB_FRAME_DECOR_GRIPS
|
1424 OB_FRAME_DECOR_BORDER
|
1425 OB_FRAME_DECOR_ICON
|
1426 OB_FRAME_DECOR_ALLDESKTOPS
|
1427 OB_FRAME_DECOR_ICONIFY
|
1428 OB_FRAME_DECOR_MAXIMIZE
|
1429 OB_FRAME_DECOR_SHADE
|
1430 OB_FRAME_DECOR_CLOSE
);
1432 (OB_CLIENT_FUNC_RESIZE
|
1433 OB_CLIENT_FUNC_MOVE
|
1434 OB_CLIENT_FUNC_ICONIFY
|
1435 OB_CLIENT_FUNC_MAXIMIZE
|
1436 OB_CLIENT_FUNC_SHADE
|
1437 OB_CLIENT_FUNC_CLOSE
);
1439 if (!(self
->min_size
.width
< self
->max_size
.width
||
1440 self
->min_size
.height
< self
->max_size
.height
))
1441 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
1443 switch (self
->type
) {
1444 case OB_CLIENT_TYPE_NORMAL
:
1445 /* normal windows retain all of the possible decorations and
1446 functionality, and are the only windows that you can fullscreen */
1447 self
->functions
|= OB_CLIENT_FUNC_FULLSCREEN
;
1450 case OB_CLIENT_TYPE_DIALOG
:
1451 case OB_CLIENT_TYPE_UTILITY
:
1452 /* these windows cannot be maximized */
1453 self
->functions
&= ~OB_CLIENT_FUNC_MAXIMIZE
;
1456 case OB_CLIENT_TYPE_MENU
:
1457 case OB_CLIENT_TYPE_TOOLBAR
:
1458 /* these windows get less functionality */
1459 self
->functions
&= ~(OB_CLIENT_FUNC_ICONIFY
| OB_CLIENT_FUNC_RESIZE
);
1462 case OB_CLIENT_TYPE_DESKTOP
:
1463 case OB_CLIENT_TYPE_DOCK
:
1464 case OB_CLIENT_TYPE_SPLASH
:
1465 /* none of these windows are manipulated by the window manager */
1466 self
->decorations
= 0;
1467 self
->functions
= 0;
1471 /* Mwm Hints are applied subtractively to what has already been chosen for
1472 decor and functionality */
1473 if (self
->mwmhints
.flags
& OB_MWM_FLAG_DECORATIONS
) {
1474 if (! (self
->mwmhints
.decorations
& OB_MWM_DECOR_ALL
)) {
1475 if (! ((self
->mwmhints
.decorations
& OB_MWM_DECOR_HANDLE
) ||
1476 (self
->mwmhints
.decorations
& OB_MWM_DECOR_TITLE
)))
1478 /* if the mwm hints request no handle or title, then all
1479 decorations are disabled, but keep the border if that's
1481 if (self
->mwmhints
.decorations
& OB_MWM_DECOR_BORDER
)
1482 self
->decorations
= OB_FRAME_DECOR_BORDER
;
1484 self
->decorations
= 0;
1489 if (self
->mwmhints
.flags
& OB_MWM_FLAG_FUNCTIONS
) {
1490 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_ALL
)) {
1491 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_RESIZE
))
1492 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
1493 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_MOVE
))
1494 self
->functions
&= ~OB_CLIENT_FUNC_MOVE
;
1495 /* dont let mwm hints kill any buttons
1496 if (! (self->mwmhints.functions & OB_MWM_FUNC_ICONIFY))
1497 self->functions &= ~OB_CLIENT_FUNC_ICONIFY;
1498 if (! (self->mwmhints.functions & OB_MWM_FUNC_MAXIMIZE))
1499 self->functions &= ~OB_CLIENT_FUNC_MAXIMIZE;
1501 /* dont let mwm hints kill the close button
1502 if (! (self->mwmhints.functions & MwmFunc_Close))
1503 self->functions &= ~OB_CLIENT_FUNC_CLOSE; */
1507 if (!(self
->functions
& OB_CLIENT_FUNC_SHADE
))
1508 self
->decorations
&= ~OB_FRAME_DECOR_SHADE
;
1509 if (!(self
->functions
& OB_CLIENT_FUNC_ICONIFY
))
1510 self
->decorations
&= ~OB_FRAME_DECOR_ICONIFY
;
1511 if (!(self
->functions
& OB_CLIENT_FUNC_RESIZE
))
1512 self
->decorations
&= ~OB_FRAME_DECOR_GRIPS
;
1514 /* can't maximize without moving/resizing */
1515 if (!((self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) &&
1516 (self
->functions
& OB_CLIENT_FUNC_MOVE
) &&
1517 (self
->functions
& OB_CLIENT_FUNC_RESIZE
))) {
1518 self
->functions
&= ~OB_CLIENT_FUNC_MAXIMIZE
;
1519 self
->decorations
&= ~OB_FRAME_DECOR_MAXIMIZE
;
1522 /* kill the handle on fully maxed windows */
1523 if (self
->max_vert
&& self
->max_horz
)
1524 self
->decorations
&= ~OB_FRAME_DECOR_HANDLE
;
1526 /* finally, the user can have requested no decorations, which overrides
1527 everything (but doesnt give it a border if it doesnt have one) */
1528 if (self
->undecorated
) {
1529 if (config_theme_keepborder
)
1530 self
->decorations
&= OB_FRAME_DECOR_BORDER
;
1532 self
->decorations
= 0;
1535 /* if we don't have a titlebar, then we cannot shade! */
1536 if (!(self
->decorations
& OB_FRAME_DECOR_TITLEBAR
))
1537 self
->functions
&= ~OB_CLIENT_FUNC_SHADE
;
1539 /* now we need to check against rules for the client's current state */
1540 if (self
->fullscreen
) {
1541 self
->functions
&= (OB_CLIENT_FUNC_CLOSE
|
1542 OB_CLIENT_FUNC_FULLSCREEN
|
1543 OB_CLIENT_FUNC_ICONIFY
);
1544 self
->decorations
= 0;
1547 client_change_allowed_actions(self
);
1550 /* adjust the client's decorations, etc. */
1551 client_reconfigure(self
);
1555 static void client_change_allowed_actions(ObClient
*self
)
1560 /* desktop windows are kept on all desktops */
1561 if (self
->type
!= OB_CLIENT_TYPE_DESKTOP
)
1562 actions
[num
++] = prop_atoms
.net_wm_action_change_desktop
;
1564 if (self
->functions
& OB_CLIENT_FUNC_SHADE
)
1565 actions
[num
++] = prop_atoms
.net_wm_action_shade
;
1566 if (self
->functions
& OB_CLIENT_FUNC_CLOSE
)
1567 actions
[num
++] = prop_atoms
.net_wm_action_close
;
1568 if (self
->functions
& OB_CLIENT_FUNC_MOVE
)
1569 actions
[num
++] = prop_atoms
.net_wm_action_move
;
1570 if (self
->functions
& OB_CLIENT_FUNC_ICONIFY
)
1571 actions
[num
++] = prop_atoms
.net_wm_action_minimize
;
1572 if (self
->functions
& OB_CLIENT_FUNC_RESIZE
)
1573 actions
[num
++] = prop_atoms
.net_wm_action_resize
;
1574 if (self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
)
1575 actions
[num
++] = prop_atoms
.net_wm_action_fullscreen
;
1576 if (self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) {
1577 actions
[num
++] = prop_atoms
.net_wm_action_maximize_horz
;
1578 actions
[num
++] = prop_atoms
.net_wm_action_maximize_vert
;
1581 PROP_SETA32(self
->window
, net_wm_allowed_actions
, atom
, actions
, num
);
1583 /* make sure the window isn't breaking any rules now */
1585 if (!(self
->functions
& OB_CLIENT_FUNC_SHADE
) && self
->shaded
) {
1586 if (self
->frame
) client_shade(self
, FALSE
);
1587 else self
->shaded
= FALSE
;
1589 if (!(self
->functions
& OB_CLIENT_FUNC_ICONIFY
) && self
->iconic
) {
1590 if (self
->frame
) client_iconify(self
, FALSE
, TRUE
);
1591 else self
->iconic
= FALSE
;
1593 if (!(self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
) && self
->fullscreen
) {
1594 if (self
->frame
) client_fullscreen(self
, FALSE
);
1595 else self
->fullscreen
= FALSE
;
1597 if (!(self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) && (self
->max_horz
||
1599 if (self
->frame
) client_maximize(self
, FALSE
, 0);
1600 else self
->max_vert
= self
->max_horz
= FALSE
;
1604 void client_reconfigure(ObClient
*self
)
1606 /* by making this pass FALSE for user, we avoid the emacs event storm where
1607 every configurenotify causes an update in its normal hints, i think this
1608 is generally what we want anyways... */
1609 client_configure(self
, self
->area
.x
, self
->area
.y
,
1610 self
->area
.width
, self
->area
.height
, FALSE
, TRUE
);
1613 void client_update_wmhints(ObClient
*self
)
1618 /* assume a window takes input if it doesnt specify */
1619 self
->can_focus
= TRUE
;
1621 if ((hints
= XGetWMHints(ob_display
, self
->window
)) != NULL
) {
1624 if (hints
->flags
& InputHint
)
1625 self
->can_focus
= hints
->input
;
1627 /* only do this when first managing the window *AND* when we aren't
1629 if (ob_state() != OB_STATE_STARTING
&& self
->frame
== NULL
)
1630 if (hints
->flags
& StateHint
)
1631 self
->iconic
= hints
->initial_state
== IconicState
;
1634 self
->urgent
= (hints
->flags
& XUrgencyHint
);
1635 if (self
->urgent
&& !ur
)
1636 client_hilite(self
, TRUE
);
1637 else if (!self
->urgent
&& ur
&& self
->demands_attention
)
1638 client_hilite(self
, FALSE
);
1640 if (!(hints
->flags
& WindowGroupHint
))
1641 hints
->window_group
= None
;
1643 /* did the group state change? */
1644 if (hints
->window_group
!=
1645 (self
->group
? self
->group
->leader
: None
)) {
1646 /* remove from the old group if there was one */
1647 if (self
->group
!= NULL
) {
1648 /* remove transients of the group */
1649 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
))
1650 self
->transients
= g_slist_remove(self
->transients
,
1653 /* remove myself from parents in the group */
1654 if (self
->transient_for
== OB_TRAN_GROUP
) {
1655 for (it
= self
->group
->members
; it
;
1656 it
= g_slist_next(it
))
1658 ObClient
*c
= it
->data
;
1660 if (c
!= self
&& !c
->transient_for
)
1661 c
->transients
= g_slist_remove(c
->transients
,
1666 group_remove(self
->group
, self
);
1669 if (hints
->window_group
!= None
) {
1670 self
->group
= group_add(hints
->window_group
, self
);
1672 /* i can only have transients from the group if i am not
1674 if (!self
->transient_for
) {
1675 /* add other transients of the group that are already
1677 for (it
= self
->group
->members
; it
;
1678 it
= g_slist_next(it
))
1680 ObClient
*c
= it
->data
;
1681 if (c
!= self
&& c
->transient_for
== OB_TRAN_GROUP
)
1683 g_slist_append(self
->transients
, c
);
1688 /* because the self->transient flag wont change from this call,
1689 we don't need to update the window's type and such, only its
1690 transient_for, and the transients lists of other windows in
1691 the group may be affected */
1692 client_update_transient_for(self
);
1695 /* the WM_HINTS can contain an icon */
1696 client_update_icons(self
);
1702 void client_update_title(ObClient
*self
)
1705 gchar
*visible
= NULL
;
1707 g_free(self
->title
);
1710 if (!PROP_GETS(self
->window
, net_wm_name
, utf8
, &data
)) {
1711 /* try old x stuff */
1712 if (!(PROP_GETS(self
->window
, wm_name
, locale
, &data
)
1713 || PROP_GETS(self
->window
, wm_name
, utf8
, &data
))) {
1714 if (self
->transient
) {
1716 GNOME alert windows are not given titles:
1717 http://developer.gnome.org/projects/gup/hig/draft_hig_new/windows-alert.html
1719 data
= g_strdup("");
1721 data
= g_strdup("Unnamed Window");
1725 if (self
->client_machine
) {
1726 visible
= g_strdup_printf("%s (%s)", data
, self
->client_machine
);
1731 PROP_SETS(self
->window
, net_wm_visible_name
, visible
);
1732 self
->title
= visible
;
1735 frame_adjust_title(self
->frame
);
1737 /* update the icon title */
1739 g_free(self
->icon_title
);
1742 if (!PROP_GETS(self
->window
, net_wm_icon_name
, utf8
, &data
))
1743 /* try old x stuff */
1744 if (!(PROP_GETS(self
->window
, wm_icon_name
, locale
, &data
) ||
1745 PROP_GETS(self
->window
, wm_icon_name
, utf8
, &data
)))
1746 data
= g_strdup(self
->title
);
1748 PROP_SETS(self
->window
, net_wm_visible_icon_name
, data
);
1749 self
->icon_title
= data
;
1752 void client_update_class(ObClient
*self
)
1757 if (self
->name
) g_free(self
->name
);
1758 if (self
->class) g_free(self
->class);
1759 if (self
->role
) g_free(self
->role
);
1761 self
->name
= self
->class = self
->role
= NULL
;
1763 if (PROP_GETSS(self
->window
, wm_class
, locale
, &data
)) {
1765 self
->name
= g_strdup(data
[0]);
1767 self
->class = g_strdup(data
[1]);
1772 if (PROP_GETS(self
->window
, wm_window_role
, locale
, &s
))
1775 if (self
->name
== NULL
) self
->name
= g_strdup("");
1776 if (self
->class == NULL
) self
->class = g_strdup("");
1777 if (self
->role
== NULL
) self
->role
= g_strdup("");
1780 void client_update_strut(ObClient
*self
)
1784 gboolean got
= FALSE
;
1787 if (PROP_GETA32(self
->window
, net_wm_strut_partial
, cardinal
,
1791 STRUT_PARTIAL_SET(strut
,
1792 data
[0], data
[2], data
[1], data
[3],
1793 data
[4], data
[5], data
[8], data
[9],
1794 data
[6], data
[7], data
[10], data
[11]);
1800 PROP_GETA32(self
->window
, net_wm_strut
, cardinal
, &data
, &num
)) {
1806 /* use the screen's width/height */
1807 a
= screen_physical_area();
1809 STRUT_PARTIAL_SET(strut
,
1810 data
[0], data
[2], data
[1], data
[3],
1811 a
->y
, a
->y
+ a
->height
- 1,
1812 a
->x
, a
->x
+ a
->width
- 1,
1813 a
->y
, a
->y
+ a
->height
- 1,
1814 a
->x
, a
->x
+ a
->width
- 1);
1820 STRUT_PARTIAL_SET(strut
, 0, 0, 0, 0,
1821 0, 0, 0, 0, 0, 0, 0, 0);
1823 if (!STRUT_EQUAL(strut
, self
->strut
)) {
1824 self
->strut
= strut
;
1826 /* updating here is pointless while we're being mapped cuz we're not in
1827 the client list yet */
1829 screen_update_areas();
1833 void client_update_icons(ObClient
*self
)
1839 for (i
= 0; i
< self
->nicons
; ++i
)
1840 g_free(self
->icons
[i
].data
);
1841 if (self
->nicons
> 0)
1842 g_free(self
->icons
);
1845 if (PROP_GETA32(self
->window
, net_wm_icon
, cardinal
, &data
, &num
)) {
1846 /* figure out how many valid icons are in here */
1848 while (num
- i
> 2) {
1852 if (i
> num
|| w
*h
== 0) break;
1856 self
->icons
= g_new(ObClientIcon
, self
->nicons
);
1858 /* store the icons */
1860 for (j
= 0; j
< self
->nicons
; ++j
) {
1863 w
= self
->icons
[j
].width
= data
[i
++];
1864 h
= self
->icons
[j
].height
= data
[i
++];
1866 if (w
*h
== 0) continue;
1868 self
->icons
[j
].data
= g_new(RrPixel32
, w
* h
);
1869 for (x
= 0, y
= 0, t
= 0; t
< w
* h
; ++t
, ++x
, ++i
) {
1874 self
->icons
[j
].data
[t
] =
1875 (((data
[i
] >> 24) & 0xff) << RrDefaultAlphaOffset
) +
1876 (((data
[i
] >> 16) & 0xff) << RrDefaultRedOffset
) +
1877 (((data
[i
] >> 8) & 0xff) << RrDefaultGreenOffset
) +
1878 (((data
[i
] >> 0) & 0xff) << RrDefaultBlueOffset
);
1887 if ((hints
= XGetWMHints(ob_display
, self
->window
))) {
1888 if (hints
->flags
& IconPixmapHint
) {
1890 self
->icons
= g_new(ObClientIcon
, self
->nicons
);
1891 xerror_set_ignore(TRUE
);
1892 if (!RrPixmapToRGBA(ob_rr_inst
,
1894 (hints
->flags
& IconMaskHint
?
1895 hints
->icon_mask
: None
),
1896 &self
->icons
[self
->nicons
-1].width
,
1897 &self
->icons
[self
->nicons
-1].height
,
1898 &self
->icons
[self
->nicons
-1].data
)){
1899 g_free(&self
->icons
[self
->nicons
-1]);
1902 xerror_set_ignore(FALSE
);
1908 /* set the default icon onto the window
1909 in theory, this could be a race, but if a window doesn't set an icon
1910 or removes it entirely, it's not very likely it is going to set one
1911 right away afterwards */
1912 if (self
->nicons
== 0) {
1913 RrPixel32
*icon
= ob_rr_theme
->def_win_icon
;
1916 data
= g_new(gulong
, 48*48+2);
1917 data
[0] = data
[1] = 48;
1918 for (i
= 0; i
< 48*48; ++i
)
1919 data
[i
+2] = (((icon
[i
] >> RrDefaultAlphaOffset
) & 0xff) << 24) +
1920 (((icon
[i
] >> RrDefaultRedOffset
) & 0xff) << 16) +
1921 (((icon
[i
] >> RrDefaultGreenOffset
) & 0xff) << 8) +
1922 (((icon
[i
] >> RrDefaultBlueOffset
) & 0xff) << 0);
1923 PROP_SETA32(self
->window
, net_wm_icon
, cardinal
, data
, 48*48+2);
1925 } else if (self
->frame
)
1926 /* don't draw the icon empty if we're just setting one now anyways,
1927 we'll get the property change any second */
1928 frame_adjust_icon(self
->frame
);
1931 void client_update_user_time(ObClient
*self
)
1935 if (PROP_GET32(self
->window
, net_wm_user_time
, cardinal
, &time
)) {
1936 /* we set this every time, not just when it grows, because in practice
1937 sometimes time goes backwards! (ntpdate.. yay....) so.. if it goes
1938 backward we don't want all windows to stop focusing. we'll just
1939 assume noone is setting times older than the last one, cuz that
1940 would be pretty stupid anyways
1942 self
->user_time
= time
;
1945 ob_debug("window %s user time %u\n", self->title, time);
1950 static void client_get_client_machine(ObClient
*self
)
1953 gchar localhost
[128];
1955 g_free(self
->client_machine
);
1957 if (PROP_GETS(self
->window
, wm_client_machine
, locale
, &data
)) {
1958 gethostname(localhost
, 127);
1959 localhost
[127] = '\0';
1960 if (strcmp(localhost
, data
))
1961 self
->client_machine
= data
;
1965 static void client_change_wm_state(ObClient
*self
)
1970 old
= self
->wmstate
;
1972 if (self
->shaded
|| self
->iconic
|| !self
->frame
->visible
)
1973 self
->wmstate
= IconicState
;
1975 self
->wmstate
= NormalState
;
1977 if (old
!= self
->wmstate
) {
1978 PROP_MSG(self
->window
, kde_wm_change_state
,
1979 self
->wmstate
, 1, 0, 0);
1981 state
[0] = self
->wmstate
;
1983 PROP_SETA32(self
->window
, wm_state
, wm_state
, state
, 2);
1987 static void client_change_state(ObClient
*self
)
1989 gulong netstate
[11];
1994 netstate
[num
++] = prop_atoms
.net_wm_state_modal
;
1996 netstate
[num
++] = prop_atoms
.net_wm_state_shaded
;
1998 netstate
[num
++] = prop_atoms
.net_wm_state_hidden
;
1999 if (self
->skip_taskbar
)
2000 netstate
[num
++] = prop_atoms
.net_wm_state_skip_taskbar
;
2001 if (self
->skip_pager
)
2002 netstate
[num
++] = prop_atoms
.net_wm_state_skip_pager
;
2003 if (self
->fullscreen
)
2004 netstate
[num
++] = prop_atoms
.net_wm_state_fullscreen
;
2006 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_vert
;
2008 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_horz
;
2010 netstate
[num
++] = prop_atoms
.net_wm_state_above
;
2012 netstate
[num
++] = prop_atoms
.net_wm_state_below
;
2013 if (self
->demands_attention
)
2014 netstate
[num
++] = prop_atoms
.net_wm_state_demands_attention
;
2015 if (self
->undecorated
)
2016 netstate
[num
++] = prop_atoms
.ob_wm_state_undecorated
;
2017 PROP_SETA32(self
->window
, net_wm_state
, atom
, netstate
, num
);
2020 frame_adjust_state(self
->frame
);
2023 ObClient
*client_search_focus_tree(ObClient
*self
)
2028 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
2029 if (client_focused(it
->data
)) return it
->data
;
2030 if ((ret
= client_search_focus_tree(it
->data
))) return ret
;
2035 ObClient
*client_search_focus_tree_full(ObClient
*self
)
2037 if (self
->transient_for
) {
2038 if (self
->transient_for
!= OB_TRAN_GROUP
) {
2039 return client_search_focus_tree_full(self
->transient_for
);
2042 gboolean recursed
= FALSE
;
2044 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
))
2045 if (!((ObClient
*)it
->data
)->transient_for
) {
2047 if ((c
= client_search_focus_tree_full(it
->data
)))
2056 /* this function checks the whole tree, the client_search_focus_tree~
2057 does not, so we need to check this window */
2058 if (client_focused(self
))
2060 return client_search_focus_tree(self
);
2063 static ObStackingLayer
calc_layer(ObClient
*self
)
2067 if (self
->fullscreen
&&
2068 (client_focused(self
) || client_search_focus_tree(self
)))
2069 l
= OB_STACKING_LAYER_FULLSCREEN
;
2070 else if (self
->type
== OB_CLIENT_TYPE_DESKTOP
)
2071 l
= OB_STACKING_LAYER_DESKTOP
;
2072 else if (self
->type
== OB_CLIENT_TYPE_DOCK
) {
2073 if (self
->below
) l
= OB_STACKING_LAYER_NORMAL
;
2074 else l
= OB_STACKING_LAYER_ABOVE
;
2076 else if (self
->above
) l
= OB_STACKING_LAYER_ABOVE
;
2077 else if (self
->below
) l
= OB_STACKING_LAYER_BELOW
;
2078 else l
= OB_STACKING_LAYER_NORMAL
;
2083 static void client_calc_layer_recursive(ObClient
*self
, ObClient
*orig
,
2084 ObStackingLayer min
, gboolean raised
)
2086 ObStackingLayer old
, own
;
2090 own
= calc_layer(self
);
2091 self
->layer
= MAX(own
, min
);
2093 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
2094 client_calc_layer_recursive(it
->data
, orig
,
2096 raised
? raised
: self
->layer
!= old
);
2098 if (!raised
&& self
->layer
!= old
)
2099 if (orig
->frame
) { /* only restack if the original window is managed */
2100 stacking_remove(CLIENT_AS_WINDOW(self
));
2101 stacking_add(CLIENT_AS_WINDOW(self
));
2105 void client_calc_layer(ObClient
*self
)
2112 /* transients take on the layer of their parents */
2113 it
= client_search_all_top_parents(self
);
2115 for (; it
; it
= g_slist_next(it
))
2116 client_calc_layer_recursive(it
->data
, orig
, 0, FALSE
);
2119 gboolean
client_should_show(ObClient
*self
)
2123 if (client_normal(self
) && screen_showing_desktop
)
2126 if (self->transient_for) {
2127 if (self->transient_for != OB_TRAN_GROUP)
2128 return client_should_show(self->transient_for);
2132 for (it = self->group->members; it; it = g_slist_next(it)) {
2133 ObClient *c = it->data;
2134 if (c != self && !c->transient_for) {
2135 if (client_should_show(c))
2142 if (self
->desktop
== screen_desktop
|| self
->desktop
== DESKTOP_ALL
)
2148 void client_show(ObClient
*self
)
2151 if (client_should_show(self
)) {
2152 frame_show(self
->frame
);
2155 /* According to the ICCCM (sec 4.1.3.1) when a window is not visible, it
2156 needs to be in IconicState. This includes when it is on another
2159 client_change_wm_state(self
);
2162 void client_hide(ObClient
*self
)
2164 if (!client_should_show(self
)) {
2165 frame_hide(self
->frame
);
2168 /* According to the ICCCM (sec 4.1.3.1) when a window is not visible, it
2169 needs to be in IconicState. This includes when it is on another
2172 client_change_wm_state(self
);
2175 void client_showhide(ObClient
*self
)
2178 if (client_should_show(self
)) {
2179 frame_show(self
->frame
);
2182 frame_hide(self
->frame
);
2185 /* According to the ICCCM (sec 4.1.3.1) when a window is not visible, it
2186 needs to be in IconicState. This includes when it is on another
2189 client_change_wm_state(self
);
2192 gboolean
client_normal(ObClient
*self
) {
2193 return ! (self
->type
== OB_CLIENT_TYPE_DESKTOP
||
2194 self
->type
== OB_CLIENT_TYPE_DOCK
||
2195 self
->type
== OB_CLIENT_TYPE_SPLASH
);
2198 gboolean
client_application(ObClient
*self
)
2200 return (self
->type
== OB_CLIENT_TYPE_NORMAL
||
2201 self
->type
== OB_CLIENT_TYPE_DIALOG
);
2204 static void client_apply_startup_state(ObClient
*self
, gint x
, gint y
)
2206 gboolean pos
= FALSE
; /* has the window's position been configured? */
2209 /* save the position, and set self->area for these to use */
2215 /* set the desktop hint, to make sure that it always exists */
2216 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, self
->desktop
);
2218 /* these are in a carefully crafted order.. */
2221 self
->iconic
= FALSE
;
2222 client_iconify(self
, TRUE
, FALSE
);
2224 if (self
->fullscreen
) {
2225 self
->fullscreen
= FALSE
;
2226 client_fullscreen(self
, TRUE
);
2229 if (self
->undecorated
) {
2230 self
->undecorated
= FALSE
;
2231 client_set_undecorated(self
, TRUE
);
2234 self
->shaded
= FALSE
;
2235 client_shade(self
, TRUE
);
2237 if (self
->demands_attention
) {
2238 self
->demands_attention
= FALSE
;
2239 client_hilite(self
, TRUE
);
2242 if (self
->max_vert
&& self
->max_horz
) {
2243 self
->max_vert
= self
->max_horz
= FALSE
;
2244 client_maximize(self
, TRUE
, 0);
2246 } else if (self
->max_vert
) {
2247 self
->max_vert
= FALSE
;
2248 client_maximize(self
, TRUE
, 2);
2250 } else if (self
->max_horz
) {
2251 self
->max_horz
= FALSE
;
2252 client_maximize(self
, TRUE
, 1);
2256 /* if the client didn't get positioned yet, then do so now
2257 call client_move even if the window is not being moved anywhere, because
2258 when we reparent it and decorate it, it is getting moved and we need to
2259 be telling it so with a ConfigureNotify event.
2262 /* use the saved position */
2265 client_move(self
, x
, y
);
2268 /* nothing to do for the other states:
2277 void client_convert_gravity(ObClient
*self
, gint gravity
, gint
*x
, gint
*y
,
2280 gint oldg
= self
->gravity
;
2282 /* get the frame's position from the requested stuff */
2283 self
->gravity
= gravity
;
2284 frame_client_gravity(self
->frame
, x
, y
, w
, h
);
2285 self
->gravity
= oldg
;
2287 /* get the client's position in its true gravity from that */
2288 frame_frame_gravity(self
->frame
, x
, y
, w
, h
);
2291 void client_try_configure(ObClient
*self
, gint
*x
, gint
*y
, gint
*w
, gint
*h
,
2292 gint
*logicalw
, gint
*logicalh
,
2295 Rect desired_area
= {*x
, *y
, *w
, *h
};
2297 /* make the frame recalculate its dimentions n shit without changing
2298 anything visible for real, this way the constraints below can work with
2299 the updated frame dimensions. */
2300 frame_adjust_area(self
->frame
, TRUE
, TRUE
, TRUE
);
2302 /* work within the prefered sizes given by the window */
2303 if (!(*w
== self
->area
.width
&& *h
== self
->area
.height
)) {
2304 gint basew
, baseh
, minw
, minh
;
2306 /* base size is substituted with min size if not specified */
2307 if (self
->base_size
.width
|| self
->base_size
.height
) {
2308 basew
= self
->base_size
.width
;
2309 baseh
= self
->base_size
.height
;
2311 basew
= self
->min_size
.width
;
2312 baseh
= self
->min_size
.height
;
2314 /* min size is substituted with base size if not specified */
2315 if (self
->min_size
.width
|| self
->min_size
.height
) {
2316 minw
= self
->min_size
.width
;
2317 minh
= self
->min_size
.height
;
2319 minw
= self
->base_size
.width
;
2320 minh
= self
->base_size
.height
;
2323 /* if this is a user-requested resize, then check against min/max
2326 /* smaller than min size or bigger than max size? */
2327 if (*w
> self
->max_size
.width
) *w
= self
->max_size
.width
;
2328 if (*w
< minw
) *w
= minw
;
2329 if (*h
> self
->max_size
.height
) *h
= self
->max_size
.height
;
2330 if (*h
< minh
) *h
= minh
;
2335 /* keep to the increments */
2336 *w
/= self
->size_inc
.width
;
2337 *h
/= self
->size_inc
.height
;
2339 /* you cannot resize to nothing */
2340 if (basew
+ *w
< 1) *w
= 1 - basew
;
2341 if (baseh
+ *h
< 1) *h
= 1 - baseh
;
2343 /* save the logical size */
2344 *logicalw
= self
->size_inc
.width
> 1 ? *w
: *w
+ basew
;
2345 *logicalh
= self
->size_inc
.height
> 1 ? *h
: *h
+ baseh
;
2347 *w
*= self
->size_inc
.width
;
2348 *h
*= self
->size_inc
.height
;
2353 /* adjust the height to match the width for the aspect ratios.
2354 for this, min size is not substituted for base size ever. */
2355 *w
-= self
->base_size
.width
;
2356 *h
-= self
->base_size
.height
;
2358 if (!self
->fullscreen
) {
2359 if (self
->min_ratio
)
2360 if (*h
* self
->min_ratio
> *w
) {
2361 *h
= (gint
)(*w
/ self
->min_ratio
);
2363 /* you cannot resize to nothing */
2366 *w
= (gint
)(*h
* self
->min_ratio
);
2369 if (self
->max_ratio
)
2370 if (*h
* self
->max_ratio
< *w
) {
2371 *h
= (gint
)(*w
/ self
->max_ratio
);
2373 /* you cannot resize to nothing */
2376 *w
= (gint
)(*h
* self
->min_ratio
);
2381 *w
+= self
->base_size
.width
;
2382 *h
+= self
->base_size
.height
;
2385 /* gets the frame's position */
2386 frame_client_gravity(self
->frame
, x
, y
, *w
, *h
);
2388 /* these positions are frame positions, not client positions */
2390 /* set the size and position if fullscreen */
2391 if (self
->fullscreen
) {
2395 i
= screen_find_monitor(&desired_area
);
2396 a
= screen_physical_area_monitor(i
);
2403 user
= FALSE
; /* ignore if the client can't be moved/resized when it
2404 is entering fullscreen */
2405 } else if (self
->max_horz
|| self
->max_vert
) {
2409 i
= screen_find_monitor(&desired_area
);
2410 a
= screen_area_monitor(self
->desktop
, i
);
2412 /* set the size and position if maximized */
2413 if (self
->max_horz
) {
2415 *w
= a
->width
- self
->frame
->size
.left
- self
->frame
->size
.right
;
2417 if (self
->max_vert
) {
2419 *h
= a
->height
- self
->frame
->size
.top
- self
->frame
->size
.bottom
;
2422 /* maximizing is not allowed if the user can't move+resize the window
2426 /* gets the client's position */
2427 frame_frame_gravity(self
->frame
, x
, y
, *w
, *h
);
2429 /* these override the above states! if you cant move you can't move! */
2431 if (!(self
->functions
& OB_CLIENT_FUNC_MOVE
)) {
2435 if (!(self
->functions
& OB_CLIENT_FUNC_RESIZE
)) {
2436 *w
= self
->area
.width
;
2437 *h
= self
->area
.height
;
2446 void client_configure_full(ObClient
*self
, gint x
, gint y
, gint w
, gint h
,
2447 gboolean user
, gboolean final
,
2448 gboolean force_reply
)
2450 gint oldw
, oldh
, oldrx
, oldry
;
2451 gboolean send_resize_client
;
2452 gboolean moved
= FALSE
, resized
= FALSE
, rootmoved
= FALSE
;
2453 guint fdecor
= self
->frame
->decorations
;
2454 gboolean fhorz
= self
->frame
->max_horz
;
2455 gint logicalw
, logicalh
;
2457 /* find the new x, y, width, and height (and logical size) */
2458 client_try_configure(self
, &x
, &y
, &w
, &h
, &logicalw
, &logicalh
, user
);
2460 /* set the logical size if things changed */
2461 if (!(w
== self
->area
.width
&& h
== self
->area
.height
))
2462 SIZE_SET(self
->logical_size
, logicalw
, logicalh
);
2464 /* figure out if we moved or resized or what */
2465 moved
= x
!= self
->area
.x
|| y
!= self
->area
.y
;
2466 resized
= w
!= self
->area
.width
|| h
!= self
->area
.height
;
2468 oldw
= self
->area
.width
;
2469 oldh
= self
->area
.height
;
2470 RECT_SET(self
->area
, x
, y
, w
, h
);
2472 /* for app-requested resizes, always resize if 'resized' is true.
2473 for user-requested ones, only resize if final is true, or when
2474 resizing in redraw mode */
2475 send_resize_client
= ((!user
&& resized
) ||
2477 (resized
&& config_resize_redraw
))));
2479 /* if the client is enlarging, then resize the client before the frame */
2480 if (send_resize_client
&& user
&& (w
> oldw
|| h
> oldh
)) {
2481 XResizeWindow(ob_display
, self
->window
, MAX(w
, oldw
), MAX(h
, oldh
));
2482 /* resize the plate to show the client padding color underneath */
2483 frame_adjust_client_area(self
->frame
);
2486 /* find the frame's dimensions and move/resize it */
2487 if (self
->decorations
!= fdecor
|| self
->max_horz
!= fhorz
)
2488 moved
= resized
= TRUE
;
2489 if (moved
|| resized
)
2490 frame_adjust_area(self
->frame
, moved
, resized
, FALSE
);
2492 /* find the client's position relative to the root window */
2493 oldrx
= self
->root_pos
.x
;
2494 oldry
= self
->root_pos
.y
;
2495 rootmoved
= (oldrx
!= (signed)(self
->frame
->area
.x
+
2496 self
->frame
->size
.left
-
2497 self
->border_width
) ||
2498 oldry
!= (signed)(self
->frame
->area
.y
+
2499 self
->frame
->size
.top
-
2500 self
->border_width
));
2502 if (force_reply
|| ((!user
|| (user
&& final
)) && rootmoved
))
2506 POINT_SET(self
->root_pos
,
2507 self
->frame
->area
.x
+ self
->frame
->size
.left
-
2509 self
->frame
->area
.y
+ self
->frame
->size
.top
-
2510 self
->border_width
);
2512 event
.type
= ConfigureNotify
;
2513 event
.xconfigure
.display
= ob_display
;
2514 event
.xconfigure
.event
= self
->window
;
2515 event
.xconfigure
.window
= self
->window
;
2517 /* root window real coords */
2518 event
.xconfigure
.x
= self
->root_pos
.x
;
2519 event
.xconfigure
.y
= self
->root_pos
.y
;
2520 event
.xconfigure
.width
= w
;
2521 event
.xconfigure
.height
= h
;
2522 event
.xconfigure
.border_width
= 0;
2523 event
.xconfigure
.above
= self
->frame
->plate
;
2524 event
.xconfigure
.override_redirect
= FALSE
;
2525 XSendEvent(event
.xconfigure
.display
, event
.xconfigure
.window
,
2526 FALSE
, StructureNotifyMask
, &event
);
2529 /* if the client is shrinking, then resize the frame before the client */
2530 if (send_resize_client
&& (!user
|| (w
<= oldw
|| h
<= oldh
))) {
2531 /* resize the plate to show the client padding color underneath */
2532 frame_adjust_client_area(self
->frame
);
2534 XResizeWindow(ob_display
, self
->window
, w
, h
);
2540 void client_fullscreen(ObClient
*self
, gboolean fs
)
2544 if (!(self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
) || /* can't */
2545 self
->fullscreen
== fs
) return; /* already done */
2547 self
->fullscreen
= fs
;
2548 client_change_state(self
); /* change the state hints on the client */
2549 client_calc_layer(self
); /* and adjust out layer/stacking */
2552 self
->pre_fullscreen_area
= self
->area
;
2553 /* if the window is maximized, its area isn't all that meaningful.
2554 save it's premax area instead. */
2555 if (self
->max_horz
) {
2556 self
->pre_fullscreen_area
.x
= self
->pre_max_area
.x
;
2557 self
->pre_fullscreen_area
.width
= self
->pre_max_area
.width
;
2559 if (self
->max_vert
) {
2560 self
->pre_fullscreen_area
.y
= self
->pre_max_area
.y
;
2561 self
->pre_fullscreen_area
.height
= self
->pre_max_area
.height
;
2564 /* these are not actually used cuz client_configure will set them
2565 as appropriate when the window is fullscreened */
2570 if (self
->pre_fullscreen_area
.width
> 0 &&
2571 self
->pre_fullscreen_area
.height
> 0)
2573 x
= self
->pre_fullscreen_area
.x
;
2574 y
= self
->pre_fullscreen_area
.y
;
2575 w
= self
->pre_fullscreen_area
.width
;
2576 h
= self
->pre_fullscreen_area
.height
;
2577 RECT_SET(self
->pre_fullscreen_area
, 0, 0, 0, 0);
2579 /* pick some fallbacks... */
2580 a
= screen_area_monitor(self
->desktop
, 0);
2581 x
= a
->x
+ a
->width
/ 4;
2582 y
= a
->y
+ a
->height
/ 4;
2588 client_setup_decor_and_functions(self
);
2590 client_move_resize(self
, x
, y
, w
, h
);
2592 /* try focus us when we go into fullscreen mode */
2596 static void client_iconify_recursive(ObClient
*self
,
2597 gboolean iconic
, gboolean curdesk
)
2600 gboolean changed
= FALSE
;
2603 if (self
->iconic
!= iconic
) {
2604 ob_debug("%sconifying window: 0x%lx\n", (iconic
? "I" : "Uni"),
2608 if (self
->functions
& OB_CLIENT_FUNC_ICONIFY
) {
2609 self
->iconic
= iconic
;
2611 /* update the focus lists.. iconic windows go to the bottom of
2612 the list, put the new iconic window at the 'top of the
2614 focus_order_to_top(self
);
2619 self
->iconic
= iconic
;
2622 client_set_desktop(self
, screen_desktop
, FALSE
);
2624 /* this puts it after the current focused window */
2625 focus_order_remove(self
);
2626 focus_order_add_new(self
);
2633 client_change_state(self
);
2634 client_showhide(self
);
2635 if (STRUT_EXISTS(self
->strut
))
2636 screen_update_areas();
2639 /* iconify all direct transients, and deiconify all transients
2641 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
2642 if (it
->data
!= self
)
2643 if (client_is_direct_child(self
, it
->data
) || !iconic
)
2644 client_iconify_recursive(it
->data
, iconic
, curdesk
);
2647 void client_iconify(ObClient
*self
, gboolean iconic
, gboolean curdesk
)
2649 /* move up the transient chain as far as possible first */
2650 self
= client_search_top_parent(self
);
2651 client_iconify_recursive(self
, iconic
, curdesk
);
2654 void client_maximize(ObClient
*self
, gboolean max
, gint dir
)
2658 g_assert(dir
== 0 || dir
== 1 || dir
== 2);
2659 if (!(self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
)) return; /* can't */
2661 /* check if already done */
2663 if (dir
== 0 && self
->max_horz
&& self
->max_vert
) return;
2664 if (dir
== 1 && self
->max_horz
) return;
2665 if (dir
== 2 && self
->max_vert
) return;
2667 if (dir
== 0 && !self
->max_horz
&& !self
->max_vert
) return;
2668 if (dir
== 1 && !self
->max_horz
) return;
2669 if (dir
== 2 && !self
->max_vert
) return;
2672 /* we just tell it to configure in the same place and client_configure
2673 worries about filling the screen with the window */
2676 w
= self
->area
.width
;
2677 h
= self
->area
.height
;
2680 if ((dir
== 0 || dir
== 1) && !self
->max_horz
) { /* horz */
2681 RECT_SET(self
->pre_max_area
,
2682 self
->area
.x
, self
->pre_max_area
.y
,
2683 self
->area
.width
, self
->pre_max_area
.height
);
2685 if ((dir
== 0 || dir
== 2) && !self
->max_vert
) { /* vert */
2686 RECT_SET(self
->pre_max_area
,
2687 self
->pre_max_area
.x
, self
->area
.y
,
2688 self
->pre_max_area
.width
, self
->area
.height
);
2693 a
= screen_area_monitor(self
->desktop
, 0);
2694 if ((dir
== 0 || dir
== 1) && self
->max_horz
) { /* horz */
2695 if (self
->pre_max_area
.width
> 0) {
2696 x
= self
->pre_max_area
.x
;
2697 w
= self
->pre_max_area
.width
;
2699 RECT_SET(self
->pre_max_area
, 0, self
->pre_max_area
.y
,
2700 0, self
->pre_max_area
.height
);
2702 /* pick some fallbacks... */
2703 x
= a
->x
+ a
->width
/ 4;
2707 if ((dir
== 0 || dir
== 2) && self
->max_vert
) { /* vert */
2708 if (self
->pre_max_area
.height
> 0) {
2709 y
= self
->pre_max_area
.y
;
2710 h
= self
->pre_max_area
.height
;
2712 RECT_SET(self
->pre_max_area
, self
->pre_max_area
.x
, 0,
2713 self
->pre_max_area
.width
, 0);
2715 /* pick some fallbacks... */
2716 y
= a
->y
+ a
->height
/ 4;
2722 if (dir
== 0 || dir
== 1) /* horz */
2723 self
->max_horz
= max
;
2724 if (dir
== 0 || dir
== 2) /* vert */
2725 self
->max_vert
= max
;
2727 client_change_state(self
); /* change the state hints on the client */
2729 client_setup_decor_and_functions(self
);
2731 client_move_resize(self
, x
, y
, w
, h
);
2734 void client_shade(ObClient
*self
, gboolean shade
)
2736 if ((!(self
->functions
& OB_CLIENT_FUNC_SHADE
) &&
2737 shade
) || /* can't shade */
2738 self
->shaded
== shade
) return; /* already done */
2740 self
->shaded
= shade
;
2741 client_change_state(self
);
2742 client_change_wm_state(self
); /* the window is being hidden/shown */
2743 /* resize the frame to just the titlebar */
2744 frame_adjust_area(self
->frame
, FALSE
, FALSE
, FALSE
);
2747 void client_close(ObClient
*self
)
2751 if (!(self
->functions
& OB_CLIENT_FUNC_CLOSE
)) return;
2753 /* in the case that the client provides no means to requesting that it
2754 close, we just kill it */
2755 if (!self
->delete_window
)
2759 XXX: itd be cool to do timeouts and shit here for killing the client's
2761 like... if the window is around after 5 seconds, then the close button
2762 turns a nice red, and if this function is called again, the client is
2766 ce
.xclient
.type
= ClientMessage
;
2767 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
2768 ce
.xclient
.display
= ob_display
;
2769 ce
.xclient
.window
= self
->window
;
2770 ce
.xclient
.format
= 32;
2771 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_delete_window
;
2772 ce
.xclient
.data
.l
[1] = event_curtime
;
2773 ce
.xclient
.data
.l
[2] = 0l;
2774 ce
.xclient
.data
.l
[3] = 0l;
2775 ce
.xclient
.data
.l
[4] = 0l;
2776 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
2779 void client_kill(ObClient
*self
)
2781 XKillClient(ob_display
, self
->window
);
2784 void client_hilite(ObClient
*self
, gboolean hilite
)
2786 if (self
->demands_attention
== hilite
)
2787 return; /* no change */
2789 /* don't allow focused windows to hilite */
2790 self
->demands_attention
= hilite
&& !client_focused(self
);
2791 if (self
->frame
!= NULL
) { /* if we're mapping, just set the state */
2792 if (self
->demands_attention
)
2793 frame_flash_start(self
->frame
);
2795 frame_flash_stop(self
->frame
);
2796 client_change_state(self
);
2800 void client_set_desktop_recursive(ObClient
*self
,
2801 guint target
, gboolean donthide
)
2806 if (target
!= self
->desktop
) {
2808 ob_debug("Setting desktop %u\n", target
+1);
2810 g_assert(target
< screen_num_desktops
|| target
== DESKTOP_ALL
);
2812 /* remove from the old desktop(s) */
2813 focus_order_remove(self
);
2815 old
= self
->desktop
;
2816 self
->desktop
= target
;
2817 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, target
);
2818 /* the frame can display the current desktop state */
2819 frame_adjust_state(self
->frame
);
2820 /* 'move' the window to the new desktop */
2822 client_showhide(self
);
2823 /* raise if it was not already on the desktop */
2824 if (old
!= DESKTOP_ALL
)
2826 if (STRUT_EXISTS(self
->strut
))
2827 screen_update_areas();
2829 /* add to the new desktop(s) */
2830 if (config_focus_new
)
2831 focus_order_to_top(self
);
2833 focus_order_to_bottom(self
);
2836 /* move all transients */
2837 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
2838 if (it
->data
!= self
)
2839 if (client_is_direct_child(self
, it
->data
))
2840 client_set_desktop_recursive(it
->data
, target
, donthide
);
2843 void client_set_desktop(ObClient
*self
, guint target
, gboolean donthide
)
2845 self
= client_search_top_parent(self
);
2846 client_set_desktop_recursive(self
, target
, donthide
);
2849 gboolean
client_is_direct_child(ObClient
*parent
, ObClient
*child
)
2851 while (child
!= parent
&&
2852 child
->transient_for
&& child
->transient_for
!= OB_TRAN_GROUP
)
2853 child
= child
->transient_for
;
2854 return child
== parent
;
2857 ObClient
*client_search_modal_child(ObClient
*self
)
2862 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
2863 ObClient
*c
= it
->data
;
2864 if ((ret
= client_search_modal_child(c
))) return ret
;
2865 if (c
->modal
) return c
;
2870 gboolean
client_validate(ObClient
*self
)
2874 XSync(ob_display
, FALSE
); /* get all events on the server */
2876 if (XCheckTypedWindowEvent(ob_display
, self
->window
, DestroyNotify
, &e
) ||
2877 XCheckTypedWindowEvent(ob_display
, self
->window
, UnmapNotify
, &e
)) {
2878 XPutBackEvent(ob_display
, &e
);
2885 void client_set_wm_state(ObClient
*self
, glong state
)
2887 if (state
== self
->wmstate
) return; /* no change */
2891 client_iconify(self
, TRUE
, TRUE
);
2894 client_iconify(self
, FALSE
, TRUE
);
2899 void client_set_state(ObClient
*self
, Atom action
, glong data1
, glong data2
)
2901 gboolean shaded
= self
->shaded
;
2902 gboolean fullscreen
= self
->fullscreen
;
2903 gboolean undecorated
= self
->undecorated
;
2904 gboolean max_horz
= self
->max_horz
;
2905 gboolean max_vert
= self
->max_vert
;
2906 gboolean modal
= self
->modal
;
2907 gboolean iconic
= self
->iconic
;
2908 gboolean demands_attention
= self
->demands_attention
;
2911 if (!(action
== prop_atoms
.net_wm_state_add
||
2912 action
== prop_atoms
.net_wm_state_remove
||
2913 action
== prop_atoms
.net_wm_state_toggle
))
2914 /* an invalid action was passed to the client message, ignore it */
2917 for (i
= 0; i
< 2; ++i
) {
2918 Atom state
= i
== 0 ? data1
: data2
;
2920 if (!state
) continue;
2922 /* if toggling, then pick whether we're adding or removing */
2923 if (action
== prop_atoms
.net_wm_state_toggle
) {
2924 if (state
== prop_atoms
.net_wm_state_modal
)
2925 action
= modal
? prop_atoms
.net_wm_state_remove
:
2926 prop_atoms
.net_wm_state_add
;
2927 else if (state
== prop_atoms
.net_wm_state_maximized_vert
)
2928 action
= self
->max_vert
? prop_atoms
.net_wm_state_remove
:
2929 prop_atoms
.net_wm_state_add
;
2930 else if (state
== prop_atoms
.net_wm_state_maximized_horz
)
2931 action
= self
->max_horz
? prop_atoms
.net_wm_state_remove
:
2932 prop_atoms
.net_wm_state_add
;
2933 else if (state
== prop_atoms
.net_wm_state_shaded
)
2934 action
= shaded
? prop_atoms
.net_wm_state_remove
:
2935 prop_atoms
.net_wm_state_add
;
2936 else if (state
== prop_atoms
.net_wm_state_skip_taskbar
)
2937 action
= self
->skip_taskbar
?
2938 prop_atoms
.net_wm_state_remove
:
2939 prop_atoms
.net_wm_state_add
;
2940 else if (state
== prop_atoms
.net_wm_state_skip_pager
)
2941 action
= self
->skip_pager
?
2942 prop_atoms
.net_wm_state_remove
:
2943 prop_atoms
.net_wm_state_add
;
2944 else if (state
== prop_atoms
.net_wm_state_hidden
)
2945 action
= self
->iconic
?
2946 prop_atoms
.net_wm_state_remove
:
2947 prop_atoms
.net_wm_state_add
;
2948 else if (state
== prop_atoms
.net_wm_state_fullscreen
)
2949 action
= fullscreen
?
2950 prop_atoms
.net_wm_state_remove
:
2951 prop_atoms
.net_wm_state_add
;
2952 else if (state
== prop_atoms
.net_wm_state_above
)
2953 action
= self
->above
? prop_atoms
.net_wm_state_remove
:
2954 prop_atoms
.net_wm_state_add
;
2955 else if (state
== prop_atoms
.net_wm_state_below
)
2956 action
= self
->below
? prop_atoms
.net_wm_state_remove
:
2957 prop_atoms
.net_wm_state_add
;
2958 else if (state
== prop_atoms
.net_wm_state_demands_attention
)
2959 action
= self
->demands_attention
?
2960 prop_atoms
.net_wm_state_remove
:
2961 prop_atoms
.net_wm_state_add
;
2962 else if (state
== prop_atoms
.ob_wm_state_undecorated
)
2963 action
= undecorated
? prop_atoms
.net_wm_state_remove
:
2964 prop_atoms
.net_wm_state_add
;
2967 if (action
== prop_atoms
.net_wm_state_add
) {
2968 if (state
== prop_atoms
.net_wm_state_modal
) {
2970 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
2972 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
2974 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
2976 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
2977 self
->skip_taskbar
= TRUE
;
2978 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
2979 self
->skip_pager
= TRUE
;
2980 } else if (state
== prop_atoms
.net_wm_state_hidden
) {
2982 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
2984 } else if (state
== prop_atoms
.net_wm_state_above
) {
2986 self
->below
= FALSE
;
2987 } else if (state
== prop_atoms
.net_wm_state_below
) {
2988 self
->above
= FALSE
;
2990 } else if (state
== prop_atoms
.net_wm_state_demands_attention
) {
2991 demands_attention
= TRUE
;
2992 } else if (state
== prop_atoms
.ob_wm_state_undecorated
) {
2996 } else { /* action == prop_atoms.net_wm_state_remove */
2997 if (state
== prop_atoms
.net_wm_state_modal
) {
2999 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
3001 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
3003 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
3005 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
3006 self
->skip_taskbar
= FALSE
;
3007 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
3008 self
->skip_pager
= FALSE
;
3009 } else if (state
== prop_atoms
.net_wm_state_hidden
) {
3011 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
3013 } else if (state
== prop_atoms
.net_wm_state_above
) {
3014 self
->above
= FALSE
;
3015 } else if (state
== prop_atoms
.net_wm_state_below
) {
3016 self
->below
= FALSE
;
3017 } else if (state
== prop_atoms
.net_wm_state_demands_attention
) {
3018 demands_attention
= FALSE
;
3019 } else if (state
== prop_atoms
.ob_wm_state_undecorated
) {
3020 undecorated
= FALSE
;
3024 if (max_horz
!= self
->max_horz
|| max_vert
!= self
->max_vert
) {
3025 if (max_horz
!= self
->max_horz
&& max_vert
!= self
->max_vert
) {
3027 if (max_horz
== max_vert
) { /* both going the same way */
3028 client_maximize(self
, max_horz
, 0);
3030 client_maximize(self
, max_horz
, 1);
3031 client_maximize(self
, max_vert
, 2);
3035 if (max_horz
!= self
->max_horz
)
3036 client_maximize(self
, max_horz
, 1);
3038 client_maximize(self
, max_vert
, 2);
3041 /* change fullscreen state before shading, as it will affect if the window
3043 if (fullscreen
!= self
->fullscreen
)
3044 client_fullscreen(self
, fullscreen
);
3045 if (shaded
!= self
->shaded
)
3046 client_shade(self
, shaded
);
3047 if (undecorated
!= self
->undecorated
)
3048 client_set_undecorated(self
, undecorated
);
3049 if (modal
!= self
->modal
) {
3050 self
->modal
= modal
;
3051 /* when a window changes modality, then its stacking order with its
3052 transients needs to change */
3055 if (iconic
!= self
->iconic
)
3056 client_iconify(self
, iconic
, FALSE
);
3058 if (demands_attention
!= self
->demands_attention
)
3059 client_hilite(self
, demands_attention
);
3061 client_change_state(self
); /* change the hint to reflect these changes */
3064 ObClient
*client_focus_target(ObClient
*self
)
3066 ObClient
*child
= NULL
;
3068 child
= client_search_modal_child(self
);
3069 if (child
) return child
;
3073 gboolean
client_can_focus(ObClient
*self
)
3077 /* choose the correct target */
3078 self
= client_focus_target(self
);
3080 if (!self
->frame
->visible
)
3083 if (!(self
->can_focus
|| self
->focus_notify
))
3086 /* do a check to see if the window has already been unmapped or destroyed
3087 do this intelligently while watching out for unmaps we've generated
3088 (ignore_unmaps > 0) */
3089 if (XCheckTypedWindowEvent(ob_display
, self
->window
,
3090 DestroyNotify
, &ev
)) {
3091 XPutBackEvent(ob_display
, &ev
);
3094 while (XCheckTypedWindowEvent(ob_display
, self
->window
,
3095 UnmapNotify
, &ev
)) {
3096 if (self
->ignore_unmaps
) {
3097 self
->ignore_unmaps
--;
3099 XPutBackEvent(ob_display
, &ev
);
3107 gboolean
client_focus(ObClient
*self
)
3109 /* choose the correct target */
3110 self
= client_focus_target(self
);
3112 if (!client_can_focus(self
)) {
3113 if (!self
->frame
->visible
) {
3114 /* update the focus lists */
3115 focus_order_to_top(self
);
3120 ob_debug_type(OB_DEBUG_FOCUS
,
3121 "Focusing client \"%s\" at time %u\n",
3122 self
->title
, event_curtime
);
3124 if (self
->can_focus
) {
3125 /* This can cause a BadMatch error with CurrentTime, or if an app
3126 passed in a bad time for _NET_WM_ACTIVE_WINDOW. */
3127 xerror_set_ignore(TRUE
);
3128 XSetInputFocus(ob_display
, self
->window
, RevertToPointerRoot
,
3130 xerror_set_ignore(FALSE
);
3133 if (self
->focus_notify
) {
3135 ce
.xclient
.type
= ClientMessage
;
3136 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
3137 ce
.xclient
.display
= ob_display
;
3138 ce
.xclient
.window
= self
->window
;
3139 ce
.xclient
.format
= 32;
3140 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_take_focus
;
3141 ce
.xclient
.data
.l
[1] = event_curtime
;
3142 ce
.xclient
.data
.l
[2] = 0l;
3143 ce
.xclient
.data
.l
[3] = 0l;
3144 ce
.xclient
.data
.l
[4] = 0l;
3145 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
3149 ob_debug("%sively focusing %lx at %d\n",
3150 (self
->can_focus
? "act" : "pass"),
3151 self
->window
, (gint
) event_curtime
);
3154 /* Cause the FocusIn to come back to us. Important for desktop switches,
3155 since otherwise we'll have no FocusIn on the queue and send it off to
3156 the focus_backup. */
3157 XSync(ob_display
, FALSE
);
3161 void client_activate(ObClient
*self
, gboolean here
, gboolean user
)
3163 guint32 last_time
= focus_client
? focus_client
->user_time
: CurrentTime
;
3165 /* XXX do some stuff here if user is false to determine if we really want
3166 to activate it or not (a parent or group member is currently
3169 ob_debug_type(OB_DEBUG_FOCUS
,
3170 "Want to activate window 0x%x with time %u (last time %u), "
3172 self
->window
, event_curtime
, last_time
,
3173 (user
? "user" : "application"));
3175 if (!user
&& event_curtime
&& last_time
&&
3176 !event_time_after(event_curtime
, last_time
))
3178 client_hilite(self
, TRUE
);
3180 if (event_curtime
!= CurrentTime
)
3181 self
->user_time
= event_curtime
;
3183 /* if using focus_delay, stop the timer now so that focus doesn't
3185 event_halt_focus_delay();
3187 if (client_normal(self
) && screen_showing_desktop
)
3188 screen_show_desktop(FALSE
);
3190 client_iconify(self
, FALSE
, here
);
3191 if (self
->desktop
!= DESKTOP_ALL
&&
3192 self
->desktop
!= screen_desktop
) {
3194 client_set_desktop(self
, screen_desktop
, FALSE
);
3196 screen_set_desktop(self
->desktop
);
3197 } else if (!self
->frame
->visible
)
3198 /* if its not visible for other reasons, then don't mess
3202 client_shade(self
, FALSE
);
3206 /* we do this as an action here. this is rather important. this is
3207 because we want the results from the focus change to take place
3208 BEFORE we go about raising the window. when a fullscreen window
3209 loses focus, we need this or else the raise wont be able to raise
3210 above the to-lose-focus fullscreen window. */
3215 void client_raise(ObClient
*self
)
3217 action_run_string("Raise", self
, CurrentTime
);
3220 void client_lower(ObClient
*self
)
3222 action_run_string("Lower", self
, CurrentTime
);
3225 gboolean
client_focused(ObClient
*self
)
3227 return self
== focus_client
;
3230 static ObClientIcon
* client_icon_recursive(ObClient
*self
, gint w
, gint h
)
3233 /* si is the smallest image >= req */
3234 /* li is the largest image < req */
3235 gulong size
, smallest
= 0xffffffff, largest
= 0, si
= 0, li
= 0;
3237 if (!self
->nicons
) {
3238 ObClientIcon
*parent
= NULL
;
3240 if (self
->transient_for
) {
3241 if (self
->transient_for
!= OB_TRAN_GROUP
)
3242 parent
= client_icon_recursive(self
->transient_for
, w
, h
);
3245 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
3246 ObClient
*c
= it
->data
;
3247 if (c
!= self
&& !c
->transient_for
) {
3248 if ((parent
= client_icon_recursive(c
, w
, h
)))
3258 for (i
= 0; i
< self
->nicons
; ++i
) {
3259 size
= self
->icons
[i
].width
* self
->icons
[i
].height
;
3260 if (size
< smallest
&& size
>= (unsigned)(w
* h
)) {
3264 if (size
> largest
&& size
<= (unsigned)(w
* h
)) {
3269 if (largest
== 0) /* didnt find one smaller than the requested size */
3270 return &self
->icons
[si
];
3271 return &self
->icons
[li
];
3274 const ObClientIcon
* client_icon(ObClient
*self
, gint w
, gint h
)
3277 static ObClientIcon deficon
;
3279 if (!(ret
= client_icon_recursive(self
, w
, h
))) {
3280 deficon
.width
= deficon
.height
= 48;
3281 deficon
.data
= ob_rr_theme
->def_win_icon
;
3287 void client_set_layer(ObClient
*self
, gint layer
)
3291 self
->above
= FALSE
;
3292 } else if (layer
== 0) {
3293 self
->below
= self
->above
= FALSE
;
3295 self
->below
= FALSE
;
3298 client_calc_layer(self
);
3299 client_change_state(self
); /* reflect this in the state hints */
3302 void client_set_undecorated(ObClient
*self
, gboolean undecorated
)
3304 if (self
->undecorated
!= undecorated
) {
3305 self
->undecorated
= undecorated
;
3306 client_setup_decor_and_functions(self
);
3307 /* Make sure the client knows it might have moved. Maybe there is a
3308 * better way of doing this so only one client_configure is sent, but
3309 * since 125 of these are sent per second when moving the window (with
3310 * user = FALSE) i doubt it matters much.
3312 client_configure(self
, self
->area
.x
, self
->area
.y
,
3313 self
->area
.width
, self
->area
.height
, TRUE
, TRUE
);
3314 client_change_state(self
); /* reflect this in the state hints */
3318 guint
client_monitor(ObClient
*self
)
3320 return screen_find_monitor(&self
->frame
->area
);
3323 ObClient
*client_search_top_parent(ObClient
*self
)
3325 while (self
->transient_for
&& self
->transient_for
!= OB_TRAN_GROUP
&&
3326 client_normal(self
))
3327 self
= self
->transient_for
;
3331 GSList
*client_search_all_top_parents(ObClient
*self
)
3335 /* move up the direct transient chain as far as possible */
3336 while (self
->transient_for
&& self
->transient_for
!= OB_TRAN_GROUP
)
3337 self
= self
->transient_for
;
3339 if (!self
->transient_for
)
3340 ret
= g_slist_prepend(ret
, self
);
3344 g_assert(self
->group
);
3346 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
3347 ObClient
*c
= it
->data
;
3349 if (!c
->transient_for
&& client_normal(c
))
3350 ret
= g_slist_prepend(ret
, c
);
3353 if (ret
== NULL
) /* no group parents */
3354 ret
= g_slist_prepend(ret
, self
);
3360 ObClient
*client_search_focus_parent(ObClient
*self
)
3362 if (self
->transient_for
) {
3363 if (self
->transient_for
!= OB_TRAN_GROUP
) {
3364 if (client_focused(self
->transient_for
))
3365 return self
->transient_for
;
3369 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
3370 ObClient
*c
= it
->data
;
3372 /* checking transient_for prevents infinate loops! */
3373 if (c
!= self
&& !c
->transient_for
)
3374 if (client_focused(c
))
3383 ObClient
*client_search_parent(ObClient
*self
, ObClient
*search
)
3385 if (self
->transient_for
) {
3386 if (self
->transient_for
!= OB_TRAN_GROUP
) {
3387 if (self
->transient_for
== search
)
3392 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
3393 ObClient
*c
= it
->data
;
3395 /* checking transient_for prevents infinate loops! */
3396 if (c
!= self
&& !c
->transient_for
)
3406 ObClient
*client_search_transient(ObClient
*self
, ObClient
*search
)
3410 for (sit
= self
->transients
; sit
; sit
= g_slist_next(sit
)) {
3411 if (sit
->data
== search
)
3413 if (client_search_transient(sit
->data
, search
))
3419 void client_update_sm_client_id(ObClient
*self
)
3421 g_free(self
->sm_client_id
);
3422 self
->sm_client_id
= NULL
;
3424 if (!PROP_GETS(self
->window
, sm_client_id
, locale
, &self
->sm_client_id
) &&
3426 PROP_GETS(self
->group
->leader
, sm_client_id
, locale
,
3427 &self
->sm_client_id
);
3430 #define WANT_EDGE(cur, c) \
3433 if(!client_normal(cur)) \
3435 if(screen_desktop != cur->desktop && cur->desktop != DESKTOP_ALL) \
3439 if(cur->layer < c->layer && !config_resist_layers_below) \
3442 #define HIT_EDGE(my_edge_start, my_edge_end, his_edge_start, his_edge_end) \
3443 if ((his_edge_start >= my_edge_start && \
3444 his_edge_start <= my_edge_end) || \
3445 (my_edge_start >= his_edge_start && \
3446 my_edge_start <= his_edge_end)) \
3449 /* finds the nearest edge in the given direction from the current client
3450 * note to self: the edge is the -frame- edge (the actual one), not the
3453 gint
client_directional_edge_search(ObClient
*c
, ObDirection dir
, gboolean hang
)
3455 gint dest
, monitor_dest
;
3456 gint my_edge_start
, my_edge_end
, my_offset
;
3463 a
= screen_area(c
->desktop
);
3464 monitor
= screen_area_monitor(c
->desktop
, client_monitor(c
));
3467 case OB_DIRECTION_NORTH
:
3468 my_edge_start
= c
->frame
->area
.x
;
3469 my_edge_end
= c
->frame
->area
.x
+ c
->frame
->area
.width
;
3470 my_offset
= c
->frame
->area
.y
+ (hang
? c
->frame
->area
.height
: 0);
3472 /* default: top of screen */
3473 dest
= a
->y
+ (hang
? c
->frame
->area
.height
: 0);
3474 monitor_dest
= monitor
->y
+ (hang
? c
->frame
->area
.height
: 0);
3475 /* if the monitor edge comes before the screen edge, */
3476 /* use that as the destination instead. (For xinerama) */
3477 if (monitor_dest
!= dest
&& my_offset
> monitor_dest
)
3478 dest
= monitor_dest
;
3480 for(it
= client_list
; it
&& my_offset
!= dest
; it
= g_list_next(it
)) {
3481 gint his_edge_start
, his_edge_end
, his_offset
;
3482 ObClient
*cur
= it
->data
;
3486 his_edge_start
= cur
->frame
->area
.x
;
3487 his_edge_end
= cur
->frame
->area
.x
+ cur
->frame
->area
.width
;
3488 his_offset
= cur
->frame
->area
.y
+
3489 (hang
? 0 : cur
->frame
->area
.height
);
3491 if(his_offset
+ 1 > my_offset
)
3494 if(his_offset
< dest
)
3497 HIT_EDGE(my_edge_start
, my_edge_end
, his_edge_start
, his_edge_end
)
3500 case OB_DIRECTION_SOUTH
:
3501 my_edge_start
= c
->frame
->area
.x
;
3502 my_edge_end
= c
->frame
->area
.x
+ c
->frame
->area
.width
;
3503 my_offset
= c
->frame
->area
.y
+ (hang
? 0 : c
->frame
->area
.height
);
3505 /* default: bottom of screen */
3506 dest
= a
->y
+ a
->height
- (hang
? c
->frame
->area
.height
: 0);
3507 monitor_dest
= monitor
->y
+ monitor
->height
-
3508 (hang
? c
->frame
->area
.height
: 0);
3509 /* if the monitor edge comes before the screen edge, */
3510 /* use that as the destination instead. (For xinerama) */
3511 if (monitor_dest
!= dest
&& my_offset
< monitor_dest
)
3512 dest
= monitor_dest
;
3514 for(it
= client_list
; it
&& my_offset
!= dest
; it
= g_list_next(it
)) {
3515 gint his_edge_start
, his_edge_end
, his_offset
;
3516 ObClient
*cur
= it
->data
;
3520 his_edge_start
= cur
->frame
->area
.x
;
3521 his_edge_end
= cur
->frame
->area
.x
+ cur
->frame
->area
.width
;
3522 his_offset
= cur
->frame
->area
.y
+
3523 (hang
? cur
->frame
->area
.height
: 0);
3526 if(his_offset
- 1 < my_offset
)
3529 if(his_offset
> dest
)
3532 HIT_EDGE(my_edge_start
, my_edge_end
, his_edge_start
, his_edge_end
)
3535 case OB_DIRECTION_WEST
:
3536 my_edge_start
= c
->frame
->area
.y
;
3537 my_edge_end
= c
->frame
->area
.y
+ c
->frame
->area
.height
;
3538 my_offset
= c
->frame
->area
.x
+ (hang
? c
->frame
->area
.width
: 0);
3540 /* default: leftmost egde of screen */
3541 dest
= a
->x
+ (hang
? c
->frame
->area
.width
: 0);
3542 monitor_dest
= monitor
->x
+ (hang
? c
->frame
->area
.width
: 0);
3543 /* if the monitor edge comes before the screen edge, */
3544 /* use that as the destination instead. (For xinerama) */
3545 if (monitor_dest
!= dest
&& my_offset
> monitor_dest
)
3546 dest
= monitor_dest
;
3548 for(it
= client_list
; it
&& my_offset
!= dest
; it
= g_list_next(it
)) {
3549 gint his_edge_start
, his_edge_end
, his_offset
;
3550 ObClient
*cur
= it
->data
;
3554 his_edge_start
= cur
->frame
->area
.y
;
3555 his_edge_end
= cur
->frame
->area
.y
+ cur
->frame
->area
.height
;
3556 his_offset
= cur
->frame
->area
.x
+
3557 (hang
? 0 : cur
->frame
->area
.width
);
3559 if(his_offset
+ 1 > my_offset
)
3562 if(his_offset
< dest
)
3565 HIT_EDGE(my_edge_start
, my_edge_end
, his_edge_start
, his_edge_end
)
3568 case OB_DIRECTION_EAST
:
3569 my_edge_start
= c
->frame
->area
.y
;
3570 my_edge_end
= c
->frame
->area
.y
+ c
->frame
->area
.height
;
3571 my_offset
= c
->frame
->area
.x
+ (hang
? 0 : c
->frame
->area
.width
);
3573 /* default: rightmost edge of screen */
3574 dest
= a
->x
+ a
->width
- (hang
? c
->frame
->area
.width
: 0);
3575 monitor_dest
= monitor
->x
+ monitor
->width
-
3576 (hang
? c
->frame
->area
.width
: 0);
3577 /* if the monitor edge comes before the screen edge, */
3578 /* use that as the destination instead. (For xinerama) */
3579 if (monitor_dest
!= dest
&& my_offset
< monitor_dest
)
3580 dest
= monitor_dest
;
3582 for(it
= client_list
; it
&& my_offset
!= dest
; it
= g_list_next(it
)) {
3583 gint his_edge_start
, his_edge_end
, his_offset
;
3584 ObClient
*cur
= it
->data
;
3588 his_edge_start
= cur
->frame
->area
.y
;
3589 his_edge_end
= cur
->frame
->area
.y
+ cur
->frame
->area
.height
;
3590 his_offset
= cur
->frame
->area
.x
+
3591 (hang
? cur
->frame
->area
.width
: 0);
3593 if(his_offset
- 1 < my_offset
)
3596 if(his_offset
> dest
)
3599 HIT_EDGE(my_edge_start
, my_edge_end
, his_edge_start
, his_edge_end
)
3602 case OB_DIRECTION_NORTHEAST
:
3603 case OB_DIRECTION_SOUTHEAST
:
3604 case OB_DIRECTION_NORTHWEST
:
3605 case OB_DIRECTION_SOUTHWEST
:
3606 /* not implemented */
3608 g_assert_not_reached();
3609 dest
= 0; /* suppress warning */
3614 ObClient
* client_under_pointer()
3618 ObClient
*ret
= NULL
;
3620 if (screen_pointer_pos(&x
, &y
)) {
3621 for (it
= stacking_list
; it
; it
= g_list_next(it
)) {
3622 if (WINDOW_IS_CLIENT(it
->data
)) {
3623 ObClient
*c
= WINDOW_AS_CLIENT(it
->data
);
3624 if (c
->frame
->visible
&&
3625 RECT_CONTAINS(c
->frame
->area
, x
, y
)) {
3635 gboolean
client_has_group_siblings(ObClient
*self
)
3637 return self
->group
&& self
->group
->members
->next
;
3640 gboolean
client_has_application_group_siblings(ObClient
*self
)
3644 if (!self
->group
) return FALSE
;
3646 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
3647 ObClient
*c
= it
->data
;
3648 if (c
!= self
&& client_application(c
))