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 I also have made non-application type windows be transients based on
920 their type, like dialogs.
922 client_update_transient_for(self
);
923 client_get_type(self
);/* this can change the mwmhints for special cases */
924 client_get_state(self
);
925 client_update_transient_for(self
);
927 client_update_wmhints(self
);
928 client_get_startup_id(self
);
929 client_get_desktop(self
);/* uses transient data/group/startup id if a
930 desktop is not specified */
931 client_get_shaped(self
);
933 client_get_layer(self
); /* if layer hasn't been specified, get it from
934 other sources if possible */
937 /* a couple type-based defaults for new windows */
939 /* this makes sure that these windows appear on all desktops */
940 if (self
->type
== OB_CLIENT_TYPE_DESKTOP
)
941 self
->desktop
= DESKTOP_ALL
;
944 client_update_protocols(self
);
946 client_get_gravity(self
); /* get the attribute gravity */
947 client_update_normal_hints(self
); /* this may override the attribute
950 /* got the type, the mwmhints, the protocols, and the normal hints
951 (min/max sizes), so we're ready to set up the decorations/functions */
952 client_setup_decor_and_functions(self
);
955 client_update_sync_request_counter(self
);
957 client_get_client_machine(self
);
958 client_get_colormap(self
);
959 client_update_title(self
);
960 client_update_class(self
);
961 client_update_sm_client_id(self
);
962 client_update_strut(self
);
963 client_update_icons(self
);
964 client_update_user_time(self
);
967 static void client_get_startup_id(ObClient
*self
)
969 if (!(PROP_GETS(self
->window
, net_startup_id
, utf8
, &self
->startup_id
)))
971 PROP_GETS(self
->group
->leader
,
972 net_startup_id
, utf8
, &self
->startup_id
);
975 static void client_get_area(ObClient
*self
)
977 XWindowAttributes wattrib
;
980 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
981 g_assert(ret
!= BadWindow
);
983 RECT_SET(self
->area
, wattrib
.x
, wattrib
.y
, wattrib
.width
, wattrib
.height
);
984 POINT_SET(self
->root_pos
, wattrib
.x
, wattrib
.y
);
985 self
->border_width
= wattrib
.border_width
;
987 ob_debug("client area: %d %d %d %d\n", wattrib
.x
, wattrib
.y
,
988 wattrib
.width
, wattrib
.height
);
991 static void client_get_desktop(ObClient
*self
)
993 guint32 d
= screen_num_desktops
; /* an always-invalid value */
995 if (PROP_GET32(self
->window
, net_wm_desktop
, cardinal
, &d
)) {
996 if (d
>= screen_num_desktops
&& d
!= DESKTOP_ALL
)
997 self
->desktop
= screen_num_desktops
- 1;
1001 gboolean trdesk
= FALSE
;
1003 if (self
->transient_for
) {
1004 if (self
->transient_for
!= OB_TRAN_GROUP
) {
1005 self
->desktop
= self
->transient_for
->desktop
;
1010 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
))
1011 if (it
->data
!= self
&&
1012 !((ObClient
*)it
->data
)->transient_for
) {
1013 self
->desktop
= ((ObClient
*)it
->data
)->desktop
;
1020 /* try get from the startup-notification protocol */
1021 if (sn_get_desktop(self
->startup_id
, &self
->desktop
)) {
1022 if (self
->desktop
>= screen_num_desktops
&&
1023 self
->desktop
!= DESKTOP_ALL
)
1024 self
->desktop
= screen_num_desktops
- 1;
1026 /* defaults to the current desktop */
1027 self
->desktop
= screen_desktop
;
1032 static void client_get_layer(ObClient
*self
)
1034 if (!(self
->above
|| self
->below
)) {
1036 /* apply stuff from the group */
1040 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
1041 ObClient
*c
= it
->data
;
1042 if (c
!= self
&& !client_search_transient(self
, c
) &&
1043 client_normal(self
) && client_normal(c
))
1046 (c
->above
? 1 : (c
->below
? -1 : 0)));
1060 g_assert_not_reached();
1067 static void client_get_state(ObClient
*self
)
1072 if (PROP_GETA32(self
->window
, net_wm_state
, atom
, &state
, &num
)) {
1074 for (i
= 0; i
< num
; ++i
) {
1075 if (state
[i
] == prop_atoms
.net_wm_state_modal
)
1077 else if (state
[i
] == prop_atoms
.net_wm_state_shaded
)
1078 self
->shaded
= TRUE
;
1079 else if (state
[i
] == prop_atoms
.net_wm_state_hidden
)
1080 self
->iconic
= TRUE
;
1081 else if (state
[i
] == prop_atoms
.net_wm_state_skip_taskbar
)
1082 self
->skip_taskbar
= TRUE
;
1083 else if (state
[i
] == prop_atoms
.net_wm_state_skip_pager
)
1084 self
->skip_pager
= TRUE
;
1085 else if (state
[i
] == prop_atoms
.net_wm_state_fullscreen
)
1086 self
->fullscreen
= TRUE
;
1087 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_vert
)
1088 self
->max_vert
= TRUE
;
1089 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_horz
)
1090 self
->max_horz
= TRUE
;
1091 else if (state
[i
] == prop_atoms
.net_wm_state_above
)
1093 else if (state
[i
] == prop_atoms
.net_wm_state_below
)
1095 else if (state
[i
] == prop_atoms
.net_wm_state_demands_attention
)
1096 self
->demands_attention
= TRUE
;
1097 else if (state
[i
] == prop_atoms
.ob_wm_state_undecorated
)
1098 self
->undecorated
= TRUE
;
1105 static void client_get_shaped(ObClient
*self
)
1107 self
->shaped
= FALSE
;
1109 if (extensions_shape
) {
1114 XShapeSelectInput(ob_display
, self
->window
, ShapeNotifyMask
);
1116 XShapeQueryExtents(ob_display
, self
->window
, &s
, &foo
,
1117 &foo
, &ufoo
, &ufoo
, &foo
, &foo
, &foo
, &ufoo
,
1119 self
->shaped
= (s
!= 0);
1124 void client_update_transient_for(ObClient
*self
)
1127 ObClient
*target
= NULL
;
1129 if (XGetTransientForHint(ob_display
, self
->window
, &t
)) {
1130 self
->transient
= TRUE
;
1131 if (t
!= self
->window
) { /* cant be transient to itself! */
1132 target
= g_hash_table_lookup(window_map
, &t
);
1133 /* if this happens then we need to check for it*/
1134 g_assert(target
!= self
);
1135 if (target
&& !WINDOW_IS_CLIENT(target
)) {
1136 /* this can happen when a dialog is a child of
1137 a dockapp, for example */
1141 /* THIS IS SO ANNOYING ! ! ! ! Let me explain.... have a seat..
1143 Setting the transient_for to Root is actually illegal, however
1144 applications from time have done this to specify transient for
1147 Now you can do that by being a TYPE_DIALOG and not setting
1148 the transient_for hint at all on your window. But people still
1149 use Root, and Kwin is very strange in this regard.
1151 KWin 3.0 will not consider windows with transient_for set to
1152 Root as transient for their group *UNLESS* they are also modal.
1153 In that case, it will make them transient for the group. This
1154 leads to all sorts of weird behavior from KDE apps which are
1155 only tested in KWin. I'd like to follow their behavior just to
1156 make this work right with KDE stuff, but that seems wrong.
1158 if (!target
&& self
->group
) {
1159 /* not transient to a client, see if it is transient for a
1161 if (t
== RootWindow(ob_display
, ob_screen
)) {
1162 /* window is a transient for its group! */
1163 target
= OB_TRAN_GROUP
;
1167 } else if (self
->group
) {
1168 if (self
->type
== OB_CLIENT_TYPE_DIALOG
||
1169 self
->type
== OB_CLIENT_TYPE_TOOLBAR
||
1170 self
->type
== OB_CLIENT_TYPE_MENU
||
1171 self
->type
== OB_CLIENT_TYPE_UTILITY
)
1173 self
->transient
= TRUE
;
1174 target
= OB_TRAN_GROUP
;
1177 self
->transient
= FALSE
;
1179 /* if anything has changed... */
1180 if (target
!= self
->transient_for
) {
1181 if (self
->transient_for
== OB_TRAN_GROUP
) { /* transient of group */
1184 /* remove from old parents */
1185 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
1186 ObClient
*c
= it
->data
;
1187 if (c
!= self
&& (!c
->transient_for
||
1188 c
->transient_for
!= OB_TRAN_GROUP
))
1189 c
->transients
= g_slist_remove(c
->transients
, self
);
1191 } else if (self
->transient_for
!= NULL
) { /* transient of window */
1192 /* remove from old parent */
1193 self
->transient_for
->transients
=
1194 g_slist_remove(self
->transient_for
->transients
, self
);
1196 self
->transient_for
= target
;
1197 if (self
->transient_for
== OB_TRAN_GROUP
) { /* transient of group */
1200 /* add to new parents */
1201 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
1202 ObClient
*c
= it
->data
;
1203 if (c
!= self
&& (!c
->transient_for
||
1204 c
->transient_for
!= OB_TRAN_GROUP
))
1205 c
->transients
= g_slist_append(c
->transients
, self
);
1207 } else if (self
->transient_for
!= NULL
) { /* transient of window */
1208 /* add to new parent */
1209 self
->transient_for
->transients
=
1210 g_slist_append(self
->transient_for
->transients
, self
);
1215 static void client_get_mwm_hints(ObClient
*self
)
1220 self
->mwmhints
.flags
= 0; /* default to none */
1222 if (PROP_GETA32(self
->window
, motif_wm_hints
, motif_wm_hints
,
1224 if (num
>= OB_MWM_ELEMENTS
) {
1225 self
->mwmhints
.flags
= hints
[0];
1226 self
->mwmhints
.functions
= hints
[1];
1227 self
->mwmhints
.decorations
= hints
[2];
1233 void client_get_type(ObClient
*self
)
1240 if (PROP_GETA32(self
->window
, net_wm_window_type
, atom
, &val
, &num
)) {
1241 /* use the first value that we know about in the array */
1242 for (i
= 0; i
< num
; ++i
) {
1243 if (val
[i
] == prop_atoms
.net_wm_window_type_desktop
)
1244 self
->type
= OB_CLIENT_TYPE_DESKTOP
;
1245 else if (val
[i
] == prop_atoms
.net_wm_window_type_dock
)
1246 self
->type
= OB_CLIENT_TYPE_DOCK
;
1247 else if (val
[i
] == prop_atoms
.net_wm_window_type_toolbar
)
1248 self
->type
= OB_CLIENT_TYPE_TOOLBAR
;
1249 else if (val
[i
] == prop_atoms
.net_wm_window_type_menu
)
1250 self
->type
= OB_CLIENT_TYPE_MENU
;
1251 else if (val
[i
] == prop_atoms
.net_wm_window_type_utility
)
1252 self
->type
= OB_CLIENT_TYPE_UTILITY
;
1253 else if (val
[i
] == prop_atoms
.net_wm_window_type_splash
)
1254 self
->type
= OB_CLIENT_TYPE_SPLASH
;
1255 else if (val
[i
] == prop_atoms
.net_wm_window_type_dialog
)
1256 self
->type
= OB_CLIENT_TYPE_DIALOG
;
1257 else if (val
[i
] == prop_atoms
.net_wm_window_type_normal
)
1258 self
->type
= OB_CLIENT_TYPE_NORMAL
;
1259 else if (val
[i
] == prop_atoms
.kde_net_wm_window_type_override
) {
1260 /* prevent this window from getting any decor or
1262 self
->mwmhints
.flags
&= (OB_MWM_FLAG_FUNCTIONS
|
1263 OB_MWM_FLAG_DECORATIONS
);
1264 self
->mwmhints
.decorations
= 0;
1265 self
->mwmhints
.functions
= 0;
1267 if (self
->type
!= (ObClientType
) -1)
1268 break; /* grab the first legit type */
1273 if (self
->type
== (ObClientType
) -1) {
1274 /*the window type hint was not set, which means we either classify
1275 ourself as a normal window or a dialog, depending on if we are a
1277 if (self
->transient
)
1278 self
->type
= OB_CLIENT_TYPE_DIALOG
;
1280 self
->type
= OB_CLIENT_TYPE_NORMAL
;
1284 void client_update_protocols(ObClient
*self
)
1287 guint num_return
, i
;
1289 self
->focus_notify
= FALSE
;
1290 self
->delete_window
= FALSE
;
1292 if (PROP_GETA32(self
->window
, wm_protocols
, atom
, &proto
, &num_return
)) {
1293 for (i
= 0; i
< num_return
; ++i
) {
1294 if (proto
[i
] == prop_atoms
.wm_delete_window
)
1295 /* this means we can request the window to close */
1296 self
->delete_window
= TRUE
;
1297 else if (proto
[i
] == prop_atoms
.wm_take_focus
)
1298 /* if this protocol is requested, then the window will be
1299 notified whenever we want it to receive focus */
1300 self
->focus_notify
= TRUE
;
1302 else if (proto
[i
] == prop_atoms
.net_wm_sync_request
)
1303 /* if this protocol is requested, then resizing the
1304 window will be synchronized between the frame and the
1306 self
->sync_request
= TRUE
;
1314 void client_update_sync_request_counter(ObClient
*self
)
1318 if (PROP_GET32(self
->window
, net_wm_sync_request_counter
, cardinal
, &i
)) {
1319 self
->sync_counter
= i
;
1321 self
->sync_counter
= None
;
1325 static void client_get_gravity(ObClient
*self
)
1327 XWindowAttributes wattrib
;
1330 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
1331 g_assert(ret
!= BadWindow
);
1332 self
->gravity
= wattrib
.win_gravity
;
1335 void client_get_colormap(ObClient
*self
)
1337 XWindowAttributes wa
;
1339 if (XGetWindowAttributes(ob_display
, self
->window
, &wa
))
1340 client_update_colormap(self
, wa
.colormap
);
1343 void client_update_colormap(ObClient
*self
, Colormap colormap
)
1345 self
->colormap
= colormap
;
1348 void client_update_normal_hints(ObClient
*self
)
1352 gint oldgravity
= self
->gravity
;
1355 self
->min_ratio
= 0.0f
;
1356 self
->max_ratio
= 0.0f
;
1357 SIZE_SET(self
->size_inc
, 1, 1);
1358 SIZE_SET(self
->base_size
, 0, 0);
1359 SIZE_SET(self
->min_size
, 0, 0);
1360 SIZE_SET(self
->max_size
, G_MAXINT
, G_MAXINT
);
1362 /* get the hints from the window */
1363 if (XGetWMNormalHints(ob_display
, self
->window
, &size
, &ret
)) {
1364 /* normal windows can't request placement! har har
1365 if (!client_normal(self))
1367 self
->positioned
= (size
.flags
& (PPosition
|USPosition
));
1369 if (size
.flags
& PWinGravity
) {
1370 self
->gravity
= size
.win_gravity
;
1372 /* if the client has a frame, i.e. has already been mapped and
1373 is changing its gravity */
1374 if (self
->frame
&& self
->gravity
!= oldgravity
) {
1375 /* move our idea of the client's position based on its new
1377 client_convert_gravity(self
, oldgravity
,
1378 &self
->area
.x
, &self
->area
.y
,
1379 self
->area
.width
, self
->area
.height
);
1383 if (size
.flags
& PAspect
) {
1384 if (size
.min_aspect
.y
)
1386 (gfloat
) size
.min_aspect
.x
/ size
.min_aspect
.y
;
1387 if (size
.max_aspect
.y
)
1389 (gfloat
) size
.max_aspect
.x
/ size
.max_aspect
.y
;
1392 if (size
.flags
& PMinSize
)
1393 SIZE_SET(self
->min_size
, size
.min_width
, size
.min_height
);
1395 if (size
.flags
& PMaxSize
)
1396 SIZE_SET(self
->max_size
, size
.max_width
, size
.max_height
);
1398 if (size
.flags
& PBaseSize
)
1399 SIZE_SET(self
->base_size
, size
.base_width
, size
.base_height
);
1401 if (size
.flags
& PResizeInc
&& size
.width_inc
&& size
.height_inc
)
1402 SIZE_SET(self
->size_inc
, size
.width_inc
, size
.height_inc
);
1406 void client_setup_decor_and_functions(ObClient
*self
)
1408 /* start with everything (cept fullscreen) */
1410 (OB_FRAME_DECOR_TITLEBAR
|
1411 OB_FRAME_DECOR_HANDLE
|
1412 OB_FRAME_DECOR_GRIPS
|
1413 OB_FRAME_DECOR_BORDER
|
1414 OB_FRAME_DECOR_ICON
|
1415 OB_FRAME_DECOR_ALLDESKTOPS
|
1416 OB_FRAME_DECOR_ICONIFY
|
1417 OB_FRAME_DECOR_MAXIMIZE
|
1418 OB_FRAME_DECOR_SHADE
|
1419 OB_FRAME_DECOR_CLOSE
);
1421 (OB_CLIENT_FUNC_RESIZE
|
1422 OB_CLIENT_FUNC_MOVE
|
1423 OB_CLIENT_FUNC_ICONIFY
|
1424 OB_CLIENT_FUNC_MAXIMIZE
|
1425 OB_CLIENT_FUNC_SHADE
|
1426 OB_CLIENT_FUNC_CLOSE
);
1428 if (!(self
->min_size
.width
< self
->max_size
.width
||
1429 self
->min_size
.height
< self
->max_size
.height
))
1430 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
1432 switch (self
->type
) {
1433 case OB_CLIENT_TYPE_NORMAL
:
1434 /* normal windows retain all of the possible decorations and
1435 functionality, and are the only windows that you can fullscreen */
1436 self
->functions
|= OB_CLIENT_FUNC_FULLSCREEN
;
1439 case OB_CLIENT_TYPE_DIALOG
:
1440 case OB_CLIENT_TYPE_UTILITY
:
1441 /* these windows cannot be maximized */
1442 self
->functions
&= ~OB_CLIENT_FUNC_MAXIMIZE
;
1445 case OB_CLIENT_TYPE_MENU
:
1446 case OB_CLIENT_TYPE_TOOLBAR
:
1447 /* these windows get less functionality */
1448 self
->functions
&= ~(OB_CLIENT_FUNC_ICONIFY
| OB_CLIENT_FUNC_RESIZE
);
1451 case OB_CLIENT_TYPE_DESKTOP
:
1452 case OB_CLIENT_TYPE_DOCK
:
1453 case OB_CLIENT_TYPE_SPLASH
:
1454 /* none of these windows are manipulated by the window manager */
1455 self
->decorations
= 0;
1456 self
->functions
= 0;
1460 /* Mwm Hints are applied subtractively to what has already been chosen for
1461 decor and functionality */
1462 if (self
->mwmhints
.flags
& OB_MWM_FLAG_DECORATIONS
) {
1463 if (! (self
->mwmhints
.decorations
& OB_MWM_DECOR_ALL
)) {
1464 if (! ((self
->mwmhints
.decorations
& OB_MWM_DECOR_HANDLE
) ||
1465 (self
->mwmhints
.decorations
& OB_MWM_DECOR_TITLE
)))
1467 /* if the mwm hints request no handle or title, then all
1468 decorations are disabled, but keep the border if that's
1470 if (self
->mwmhints
.decorations
& OB_MWM_DECOR_BORDER
)
1471 self
->decorations
= OB_FRAME_DECOR_BORDER
;
1473 self
->decorations
= 0;
1478 if (self
->mwmhints
.flags
& OB_MWM_FLAG_FUNCTIONS
) {
1479 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_ALL
)) {
1480 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_RESIZE
))
1481 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
1482 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_MOVE
))
1483 self
->functions
&= ~OB_CLIENT_FUNC_MOVE
;
1484 /* dont let mwm hints kill any buttons
1485 if (! (self->mwmhints.functions & OB_MWM_FUNC_ICONIFY))
1486 self->functions &= ~OB_CLIENT_FUNC_ICONIFY;
1487 if (! (self->mwmhints.functions & OB_MWM_FUNC_MAXIMIZE))
1488 self->functions &= ~OB_CLIENT_FUNC_MAXIMIZE;
1490 /* dont let mwm hints kill the close button
1491 if (! (self->mwmhints.functions & MwmFunc_Close))
1492 self->functions &= ~OB_CLIENT_FUNC_CLOSE; */
1496 if (!(self
->functions
& OB_CLIENT_FUNC_SHADE
))
1497 self
->decorations
&= ~OB_FRAME_DECOR_SHADE
;
1498 if (!(self
->functions
& OB_CLIENT_FUNC_ICONIFY
))
1499 self
->decorations
&= ~OB_FRAME_DECOR_ICONIFY
;
1500 if (!(self
->functions
& OB_CLIENT_FUNC_RESIZE
))
1501 self
->decorations
&= ~OB_FRAME_DECOR_GRIPS
;
1503 /* can't maximize without moving/resizing */
1504 if (!((self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) &&
1505 (self
->functions
& OB_CLIENT_FUNC_MOVE
) &&
1506 (self
->functions
& OB_CLIENT_FUNC_RESIZE
))) {
1507 self
->functions
&= ~OB_CLIENT_FUNC_MAXIMIZE
;
1508 self
->decorations
&= ~OB_FRAME_DECOR_MAXIMIZE
;
1511 /* kill the handle on fully maxed windows */
1512 if (self
->max_vert
&& self
->max_horz
)
1513 self
->decorations
&= ~OB_FRAME_DECOR_HANDLE
;
1515 /* finally, the user can have requested no decorations, which overrides
1516 everything (but doesnt give it a border if it doesnt have one) */
1517 if (self
->undecorated
) {
1518 if (config_theme_keepborder
)
1519 self
->decorations
&= OB_FRAME_DECOR_BORDER
;
1521 self
->decorations
= 0;
1524 /* if we don't have a titlebar, then we cannot shade! */
1525 if (!(self
->decorations
& OB_FRAME_DECOR_TITLEBAR
))
1526 self
->functions
&= ~OB_CLIENT_FUNC_SHADE
;
1528 /* now we need to check against rules for the client's current state */
1529 if (self
->fullscreen
) {
1530 self
->functions
&= (OB_CLIENT_FUNC_CLOSE
|
1531 OB_CLIENT_FUNC_FULLSCREEN
|
1532 OB_CLIENT_FUNC_ICONIFY
);
1533 self
->decorations
= 0;
1536 client_change_allowed_actions(self
);
1539 /* adjust the client's decorations, etc. */
1540 client_reconfigure(self
);
1544 static void client_change_allowed_actions(ObClient
*self
)
1549 /* desktop windows are kept on all desktops */
1550 if (self
->type
!= OB_CLIENT_TYPE_DESKTOP
)
1551 actions
[num
++] = prop_atoms
.net_wm_action_change_desktop
;
1553 if (self
->functions
& OB_CLIENT_FUNC_SHADE
)
1554 actions
[num
++] = prop_atoms
.net_wm_action_shade
;
1555 if (self
->functions
& OB_CLIENT_FUNC_CLOSE
)
1556 actions
[num
++] = prop_atoms
.net_wm_action_close
;
1557 if (self
->functions
& OB_CLIENT_FUNC_MOVE
)
1558 actions
[num
++] = prop_atoms
.net_wm_action_move
;
1559 if (self
->functions
& OB_CLIENT_FUNC_ICONIFY
)
1560 actions
[num
++] = prop_atoms
.net_wm_action_minimize
;
1561 if (self
->functions
& OB_CLIENT_FUNC_RESIZE
)
1562 actions
[num
++] = prop_atoms
.net_wm_action_resize
;
1563 if (self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
)
1564 actions
[num
++] = prop_atoms
.net_wm_action_fullscreen
;
1565 if (self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) {
1566 actions
[num
++] = prop_atoms
.net_wm_action_maximize_horz
;
1567 actions
[num
++] = prop_atoms
.net_wm_action_maximize_vert
;
1570 PROP_SETA32(self
->window
, net_wm_allowed_actions
, atom
, actions
, num
);
1572 /* make sure the window isn't breaking any rules now */
1574 if (!(self
->functions
& OB_CLIENT_FUNC_SHADE
) && self
->shaded
) {
1575 if (self
->frame
) client_shade(self
, FALSE
);
1576 else self
->shaded
= FALSE
;
1578 if (!(self
->functions
& OB_CLIENT_FUNC_ICONIFY
) && self
->iconic
) {
1579 if (self
->frame
) client_iconify(self
, FALSE
, TRUE
);
1580 else self
->iconic
= FALSE
;
1582 if (!(self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
) && self
->fullscreen
) {
1583 if (self
->frame
) client_fullscreen(self
, FALSE
);
1584 else self
->fullscreen
= FALSE
;
1586 if (!(self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) && (self
->max_horz
||
1588 if (self
->frame
) client_maximize(self
, FALSE
, 0);
1589 else self
->max_vert
= self
->max_horz
= FALSE
;
1593 void client_reconfigure(ObClient
*self
)
1595 /* by making this pass FALSE for user, we avoid the emacs event storm where
1596 every configurenotify causes an update in its normal hints, i think this
1597 is generally what we want anyways... */
1598 client_configure(self
, self
->area
.x
, self
->area
.y
,
1599 self
->area
.width
, self
->area
.height
, FALSE
, TRUE
);
1602 void client_update_wmhints(ObClient
*self
)
1607 /* assume a window takes input if it doesnt specify */
1608 self
->can_focus
= TRUE
;
1610 if ((hints
= XGetWMHints(ob_display
, self
->window
)) != NULL
) {
1613 if (hints
->flags
& InputHint
)
1614 self
->can_focus
= hints
->input
;
1616 /* only do this when first managing the window *AND* when we aren't
1618 if (ob_state() != OB_STATE_STARTING
&& self
->frame
== NULL
)
1619 if (hints
->flags
& StateHint
)
1620 self
->iconic
= hints
->initial_state
== IconicState
;
1623 self
->urgent
= (hints
->flags
& XUrgencyHint
);
1624 if (self
->urgent
&& !ur
)
1625 client_hilite(self
, TRUE
);
1626 else if (!self
->urgent
&& ur
&& self
->demands_attention
)
1627 client_hilite(self
, FALSE
);
1629 if (!(hints
->flags
& WindowGroupHint
))
1630 hints
->window_group
= None
;
1632 /* did the group state change? */
1633 if (hints
->window_group
!=
1634 (self
->group
? self
->group
->leader
: None
)) {
1635 /* remove from the old group if there was one */
1636 if (self
->group
!= NULL
) {
1637 /* remove transients of the group */
1638 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
))
1639 self
->transients
= g_slist_remove(self
->transients
,
1642 /* remove myself from parents in the group */
1643 if (self
->transient_for
== OB_TRAN_GROUP
) {
1644 for (it
= self
->group
->members
; it
;
1645 it
= g_slist_next(it
))
1647 ObClient
*c
= it
->data
;
1649 if (c
!= self
&& (!c
->transient_for
||
1650 c
->transient_for
!= OB_TRAN_GROUP
))
1651 c
->transients
= g_slist_remove(c
->transients
,
1656 group_remove(self
->group
, self
);
1660 /* add ourself to the group */
1661 if (hints
->window_group
!= None
)
1662 self
->group
= group_add(hints
->window_group
, self
);
1665 /* because the self->transient flag wont change from this call,
1666 we don't need to update the window's type and such, only its
1669 do this before adding transients from the group so we know if
1670 we are actually transient for the group or not.
1672 client_update_transient_for(self
);
1674 /* i can only have transients from the group if i am not
1675 transient for the group myself */
1676 if (self
->group
&& (self
->transient_for
== NULL
||
1677 self
->transient_for
!= OB_TRAN_GROUP
))
1679 /* add other transients of the group that are already
1681 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
))
1683 ObClient
*c
= it
->data
;
1684 if (c
!= self
&& c
->transient_for
== OB_TRAN_GROUP
)
1685 self
->transients
= g_slist_append(self
->transients
, c
);
1690 /* the WM_HINTS can contain an icon */
1691 client_update_icons(self
);
1697 void client_update_title(ObClient
*self
)
1700 gchar
*visible
= NULL
;
1702 g_free(self
->title
);
1705 if (!PROP_GETS(self
->window
, net_wm_name
, utf8
, &data
)) {
1706 /* try old x stuff */
1707 if (!(PROP_GETS(self
->window
, wm_name
, locale
, &data
)
1708 || PROP_GETS(self
->window
, wm_name
, utf8
, &data
))) {
1709 if (self
->transient
) {
1711 GNOME alert windows are not given titles:
1712 http://developer.gnome.org/projects/gup/hig/draft_hig_new/windows-alert.html
1714 data
= g_strdup("");
1716 data
= g_strdup("Unnamed Window");
1720 if (self
->client_machine
) {
1721 visible
= g_strdup_printf("%s (%s)", data
, self
->client_machine
);
1726 PROP_SETS(self
->window
, net_wm_visible_name
, visible
);
1727 self
->title
= visible
;
1730 frame_adjust_title(self
->frame
);
1732 /* update the icon title */
1734 g_free(self
->icon_title
);
1737 if (!PROP_GETS(self
->window
, net_wm_icon_name
, utf8
, &data
))
1738 /* try old x stuff */
1739 if (!(PROP_GETS(self
->window
, wm_icon_name
, locale
, &data
) ||
1740 PROP_GETS(self
->window
, wm_icon_name
, utf8
, &data
)))
1741 data
= g_strdup(self
->title
);
1743 PROP_SETS(self
->window
, net_wm_visible_icon_name
, data
);
1744 self
->icon_title
= data
;
1747 void client_update_class(ObClient
*self
)
1752 if (self
->name
) g_free(self
->name
);
1753 if (self
->class) g_free(self
->class);
1754 if (self
->role
) g_free(self
->role
);
1756 self
->name
= self
->class = self
->role
= NULL
;
1758 if (PROP_GETSS(self
->window
, wm_class
, locale
, &data
)) {
1760 self
->name
= g_strdup(data
[0]);
1762 self
->class = g_strdup(data
[1]);
1767 if (PROP_GETS(self
->window
, wm_window_role
, locale
, &s
))
1770 if (self
->name
== NULL
) self
->name
= g_strdup("");
1771 if (self
->class == NULL
) self
->class = g_strdup("");
1772 if (self
->role
== NULL
) self
->role
= g_strdup("");
1775 void client_update_strut(ObClient
*self
)
1779 gboolean got
= FALSE
;
1782 if (PROP_GETA32(self
->window
, net_wm_strut_partial
, cardinal
,
1786 STRUT_PARTIAL_SET(strut
,
1787 data
[0], data
[2], data
[1], data
[3],
1788 data
[4], data
[5], data
[8], data
[9],
1789 data
[6], data
[7], data
[10], data
[11]);
1795 PROP_GETA32(self
->window
, net_wm_strut
, cardinal
, &data
, &num
)) {
1801 /* use the screen's width/height */
1802 a
= screen_physical_area();
1804 STRUT_PARTIAL_SET(strut
,
1805 data
[0], data
[2], data
[1], data
[3],
1806 a
->y
, a
->y
+ a
->height
- 1,
1807 a
->x
, a
->x
+ a
->width
- 1,
1808 a
->y
, a
->y
+ a
->height
- 1,
1809 a
->x
, a
->x
+ a
->width
- 1);
1815 STRUT_PARTIAL_SET(strut
, 0, 0, 0, 0,
1816 0, 0, 0, 0, 0, 0, 0, 0);
1818 if (!STRUT_EQUAL(strut
, self
->strut
)) {
1819 self
->strut
= strut
;
1821 /* updating here is pointless while we're being mapped cuz we're not in
1822 the client list yet */
1824 screen_update_areas();
1828 void client_update_icons(ObClient
*self
)
1834 for (i
= 0; i
< self
->nicons
; ++i
)
1835 g_free(self
->icons
[i
].data
);
1836 if (self
->nicons
> 0)
1837 g_free(self
->icons
);
1840 if (PROP_GETA32(self
->window
, net_wm_icon
, cardinal
, &data
, &num
)) {
1841 /* figure out how many valid icons are in here */
1843 while (num
- i
> 2) {
1847 if (i
> num
|| w
*h
== 0) break;
1851 self
->icons
= g_new(ObClientIcon
, self
->nicons
);
1853 /* store the icons */
1855 for (j
= 0; j
< self
->nicons
; ++j
) {
1858 w
= self
->icons
[j
].width
= data
[i
++];
1859 h
= self
->icons
[j
].height
= data
[i
++];
1861 if (w
*h
== 0) continue;
1863 self
->icons
[j
].data
= g_new(RrPixel32
, w
* h
);
1864 for (x
= 0, y
= 0, t
= 0; t
< w
* h
; ++t
, ++x
, ++i
) {
1869 self
->icons
[j
].data
[t
] =
1870 (((data
[i
] >> 24) & 0xff) << RrDefaultAlphaOffset
) +
1871 (((data
[i
] >> 16) & 0xff) << RrDefaultRedOffset
) +
1872 (((data
[i
] >> 8) & 0xff) << RrDefaultGreenOffset
) +
1873 (((data
[i
] >> 0) & 0xff) << RrDefaultBlueOffset
);
1882 if ((hints
= XGetWMHints(ob_display
, self
->window
))) {
1883 if (hints
->flags
& IconPixmapHint
) {
1885 self
->icons
= g_new(ObClientIcon
, self
->nicons
);
1886 xerror_set_ignore(TRUE
);
1887 if (!RrPixmapToRGBA(ob_rr_inst
,
1889 (hints
->flags
& IconMaskHint
?
1890 hints
->icon_mask
: None
),
1891 &self
->icons
[self
->nicons
-1].width
,
1892 &self
->icons
[self
->nicons
-1].height
,
1893 &self
->icons
[self
->nicons
-1].data
)){
1894 g_free(&self
->icons
[self
->nicons
-1]);
1897 xerror_set_ignore(FALSE
);
1903 /* set the default icon onto the window
1904 in theory, this could be a race, but if a window doesn't set an icon
1905 or removes it entirely, it's not very likely it is going to set one
1906 right away afterwards */
1907 if (self
->nicons
== 0) {
1908 RrPixel32
*icon
= ob_rr_theme
->def_win_icon
;
1911 data
= g_new(gulong
, 48*48+2);
1912 data
[0] = data
[1] = 48;
1913 for (i
= 0; i
< 48*48; ++i
)
1914 data
[i
+2] = (((icon
[i
] >> RrDefaultAlphaOffset
) & 0xff) << 24) +
1915 (((icon
[i
] >> RrDefaultRedOffset
) & 0xff) << 16) +
1916 (((icon
[i
] >> RrDefaultGreenOffset
) & 0xff) << 8) +
1917 (((icon
[i
] >> RrDefaultBlueOffset
) & 0xff) << 0);
1918 PROP_SETA32(self
->window
, net_wm_icon
, cardinal
, data
, 48*48+2);
1920 } else if (self
->frame
)
1921 /* don't draw the icon empty if we're just setting one now anyways,
1922 we'll get the property change any second */
1923 frame_adjust_icon(self
->frame
);
1926 void client_update_user_time(ObClient
*self
)
1930 if (PROP_GET32(self
->window
, net_wm_user_time
, cardinal
, &time
)) {
1931 /* we set this every time, not just when it grows, because in practice
1932 sometimes time goes backwards! (ntpdate.. yay....) so.. if it goes
1933 backward we don't want all windows to stop focusing. we'll just
1934 assume noone is setting times older than the last one, cuz that
1935 would be pretty stupid anyways
1937 self
->user_time
= time
;
1940 ob_debug("window %s user time %u\n", self->title, time);
1945 static void client_get_client_machine(ObClient
*self
)
1948 gchar localhost
[128];
1950 g_free(self
->client_machine
);
1952 if (PROP_GETS(self
->window
, wm_client_machine
, locale
, &data
)) {
1953 gethostname(localhost
, 127);
1954 localhost
[127] = '\0';
1955 if (strcmp(localhost
, data
))
1956 self
->client_machine
= data
;
1960 static void client_change_wm_state(ObClient
*self
)
1965 old
= self
->wmstate
;
1967 if (self
->shaded
|| self
->iconic
|| !self
->frame
->visible
)
1968 self
->wmstate
= IconicState
;
1970 self
->wmstate
= NormalState
;
1972 if (old
!= self
->wmstate
) {
1973 PROP_MSG(self
->window
, kde_wm_change_state
,
1974 self
->wmstate
, 1, 0, 0);
1976 state
[0] = self
->wmstate
;
1978 PROP_SETA32(self
->window
, wm_state
, wm_state
, state
, 2);
1982 static void client_change_state(ObClient
*self
)
1984 gulong netstate
[11];
1989 netstate
[num
++] = prop_atoms
.net_wm_state_modal
;
1991 netstate
[num
++] = prop_atoms
.net_wm_state_shaded
;
1993 netstate
[num
++] = prop_atoms
.net_wm_state_hidden
;
1994 if (self
->skip_taskbar
)
1995 netstate
[num
++] = prop_atoms
.net_wm_state_skip_taskbar
;
1996 if (self
->skip_pager
)
1997 netstate
[num
++] = prop_atoms
.net_wm_state_skip_pager
;
1998 if (self
->fullscreen
)
1999 netstate
[num
++] = prop_atoms
.net_wm_state_fullscreen
;
2001 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_vert
;
2003 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_horz
;
2005 netstate
[num
++] = prop_atoms
.net_wm_state_above
;
2007 netstate
[num
++] = prop_atoms
.net_wm_state_below
;
2008 if (self
->demands_attention
)
2009 netstate
[num
++] = prop_atoms
.net_wm_state_demands_attention
;
2010 if (self
->undecorated
)
2011 netstate
[num
++] = prop_atoms
.ob_wm_state_undecorated
;
2012 PROP_SETA32(self
->window
, net_wm_state
, atom
, netstate
, num
);
2015 frame_adjust_state(self
->frame
);
2018 ObClient
*client_search_focus_tree(ObClient
*self
)
2023 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
2024 if (client_focused(it
->data
)) return it
->data
;
2025 if ((ret
= client_search_focus_tree(it
->data
))) return ret
;
2030 ObClient
*client_search_focus_tree_full(ObClient
*self
)
2032 if (self
->transient_for
) {
2033 if (self
->transient_for
!= OB_TRAN_GROUP
) {
2034 return client_search_focus_tree_full(self
->transient_for
);
2037 gboolean recursed
= FALSE
;
2039 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
))
2040 if (!((ObClient
*)it
->data
)->transient_for
) {
2042 if ((c
= client_search_focus_tree_full(it
->data
)))
2051 /* this function checks the whole tree, the client_search_focus_tree~
2052 does not, so we need to check this window */
2053 if (client_focused(self
))
2055 return client_search_focus_tree(self
);
2058 static ObStackingLayer
calc_layer(ObClient
*self
)
2062 if (self
->fullscreen
&&
2063 (client_focused(self
) || client_search_focus_tree(self
)))
2064 l
= OB_STACKING_LAYER_FULLSCREEN
;
2065 else if (self
->type
== OB_CLIENT_TYPE_DESKTOP
)
2066 l
= OB_STACKING_LAYER_DESKTOP
;
2067 else if (self
->type
== OB_CLIENT_TYPE_DOCK
) {
2068 if (self
->below
) l
= OB_STACKING_LAYER_NORMAL
;
2069 else l
= OB_STACKING_LAYER_ABOVE
;
2071 else if (self
->above
) l
= OB_STACKING_LAYER_ABOVE
;
2072 else if (self
->below
) l
= OB_STACKING_LAYER_BELOW
;
2073 else l
= OB_STACKING_LAYER_NORMAL
;
2078 static void client_calc_layer_recursive(ObClient
*self
, ObClient
*orig
,
2079 ObStackingLayer min
, gboolean raised
)
2081 ObStackingLayer old
, own
;
2085 own
= calc_layer(self
);
2086 self
->layer
= MAX(own
, min
);
2088 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
2089 client_calc_layer_recursive(it
->data
, orig
,
2091 raised
? raised
: self
->layer
!= old
);
2093 if (!raised
&& self
->layer
!= old
)
2094 if (orig
->frame
) { /* only restack if the original window is managed */
2095 stacking_remove(CLIENT_AS_WINDOW(self
));
2096 stacking_add(CLIENT_AS_WINDOW(self
));
2100 void client_calc_layer(ObClient
*self
)
2107 /* transients take on the layer of their parents */
2108 it
= client_search_all_top_parents(self
);
2110 for (; it
; it
= g_slist_next(it
))
2111 client_calc_layer_recursive(it
->data
, orig
, 0, FALSE
);
2114 gboolean
client_should_show(ObClient
*self
)
2118 if (client_normal(self
) && screen_showing_desktop
)
2121 if (self->transient_for) {
2122 if (self->transient_for != OB_TRAN_GROUP)
2123 return client_should_show(self->transient_for);
2127 for (it = self->group->members; it; it = g_slist_next(it)) {
2128 ObClient *c = it->data;
2129 if (c != self && !c->transient_for) {
2130 if (client_should_show(c))
2137 if (self
->desktop
== screen_desktop
|| self
->desktop
== DESKTOP_ALL
)
2143 void client_show(ObClient
*self
)
2146 if (client_should_show(self
)) {
2147 frame_show(self
->frame
);
2150 /* According to the ICCCM (sec 4.1.3.1) when a window is not visible, it
2151 needs to be in IconicState. This includes when it is on another
2154 client_change_wm_state(self
);
2157 void client_hide(ObClient
*self
)
2159 if (!client_should_show(self
)) {
2160 frame_hide(self
->frame
);
2163 /* According to the ICCCM (sec 4.1.3.1) when a window is not visible, it
2164 needs to be in IconicState. This includes when it is on another
2167 client_change_wm_state(self
);
2170 void client_showhide(ObClient
*self
)
2173 if (client_should_show(self
)) {
2174 frame_show(self
->frame
);
2177 frame_hide(self
->frame
);
2180 /* According to the ICCCM (sec 4.1.3.1) when a window is not visible, it
2181 needs to be in IconicState. This includes when it is on another
2184 client_change_wm_state(self
);
2187 gboolean
client_normal(ObClient
*self
) {
2188 return ! (self
->type
== OB_CLIENT_TYPE_DESKTOP
||
2189 self
->type
== OB_CLIENT_TYPE_DOCK
||
2190 self
->type
== OB_CLIENT_TYPE_SPLASH
);
2193 gboolean
client_application(ObClient
*self
)
2195 return (self
->type
== OB_CLIENT_TYPE_NORMAL
||
2196 self
->type
== OB_CLIENT_TYPE_DIALOG
);
2199 static void client_apply_startup_state(ObClient
*self
, gint x
, gint y
)
2201 gboolean pos
= FALSE
; /* has the window's position been configured? */
2204 /* save the position, and set self->area for these to use */
2210 /* set the desktop hint, to make sure that it always exists */
2211 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, self
->desktop
);
2213 /* these are in a carefully crafted order.. */
2216 self
->iconic
= FALSE
;
2217 client_iconify(self
, TRUE
, FALSE
);
2219 if (self
->fullscreen
) {
2220 self
->fullscreen
= FALSE
;
2221 client_fullscreen(self
, TRUE
);
2224 if (self
->undecorated
) {
2225 self
->undecorated
= FALSE
;
2226 client_set_undecorated(self
, TRUE
);
2229 self
->shaded
= FALSE
;
2230 client_shade(self
, TRUE
);
2232 if (self
->demands_attention
) {
2233 self
->demands_attention
= FALSE
;
2234 client_hilite(self
, TRUE
);
2237 if (self
->max_vert
&& self
->max_horz
) {
2238 self
->max_vert
= self
->max_horz
= FALSE
;
2239 client_maximize(self
, TRUE
, 0);
2241 } else if (self
->max_vert
) {
2242 self
->max_vert
= FALSE
;
2243 client_maximize(self
, TRUE
, 2);
2245 } else if (self
->max_horz
) {
2246 self
->max_horz
= FALSE
;
2247 client_maximize(self
, TRUE
, 1);
2251 /* if the client didn't get positioned yet, then do so now
2252 call client_move even if the window is not being moved anywhere, because
2253 when we reparent it and decorate it, it is getting moved and we need to
2254 be telling it so with a ConfigureNotify event.
2257 /* use the saved position */
2260 client_move(self
, x
, y
);
2263 /* nothing to do for the other states:
2272 void client_convert_gravity(ObClient
*self
, gint gravity
, gint
*x
, gint
*y
,
2275 gint oldg
= self
->gravity
;
2277 /* get the frame's position from the requested stuff */
2278 self
->gravity
= gravity
;
2279 frame_client_gravity(self
->frame
, x
, y
, w
, h
);
2280 self
->gravity
= oldg
;
2282 /* get the client's position in its true gravity from that */
2283 frame_frame_gravity(self
->frame
, x
, y
, w
, h
);
2286 void client_try_configure(ObClient
*self
, gint
*x
, gint
*y
, gint
*w
, gint
*h
,
2287 gint
*logicalw
, gint
*logicalh
,
2290 Rect desired_area
= {*x
, *y
, *w
, *h
};
2292 /* make the frame recalculate its dimentions n shit without changing
2293 anything visible for real, this way the constraints below can work with
2294 the updated frame dimensions. */
2295 frame_adjust_area(self
->frame
, TRUE
, TRUE
, TRUE
);
2297 /* work within the prefered sizes given by the window */
2298 if (!(*w
== self
->area
.width
&& *h
== self
->area
.height
)) {
2299 gint basew
, baseh
, minw
, minh
;
2301 /* base size is substituted with min size if not specified */
2302 if (self
->base_size
.width
|| self
->base_size
.height
) {
2303 basew
= self
->base_size
.width
;
2304 baseh
= self
->base_size
.height
;
2306 basew
= self
->min_size
.width
;
2307 baseh
= self
->min_size
.height
;
2309 /* min size is substituted with base size if not specified */
2310 if (self
->min_size
.width
|| self
->min_size
.height
) {
2311 minw
= self
->min_size
.width
;
2312 minh
= self
->min_size
.height
;
2314 minw
= self
->base_size
.width
;
2315 minh
= self
->base_size
.height
;
2318 /* if this is a user-requested resize, then check against min/max
2321 /* smaller than min size or bigger than max size? */
2322 if (*w
> self
->max_size
.width
) *w
= self
->max_size
.width
;
2323 if (*w
< minw
) *w
= minw
;
2324 if (*h
> self
->max_size
.height
) *h
= self
->max_size
.height
;
2325 if (*h
< minh
) *h
= minh
;
2330 /* keep to the increments */
2331 *w
/= self
->size_inc
.width
;
2332 *h
/= self
->size_inc
.height
;
2334 /* you cannot resize to nothing */
2335 if (basew
+ *w
< 1) *w
= 1 - basew
;
2336 if (baseh
+ *h
< 1) *h
= 1 - baseh
;
2338 /* save the logical size */
2339 *logicalw
= self
->size_inc
.width
> 1 ? *w
: *w
+ basew
;
2340 *logicalh
= self
->size_inc
.height
> 1 ? *h
: *h
+ baseh
;
2342 *w
*= self
->size_inc
.width
;
2343 *h
*= self
->size_inc
.height
;
2348 /* adjust the height to match the width for the aspect ratios.
2349 for this, min size is not substituted for base size ever. */
2350 *w
-= self
->base_size
.width
;
2351 *h
-= self
->base_size
.height
;
2353 if (!self
->fullscreen
) {
2354 if (self
->min_ratio
)
2355 if (*h
* self
->min_ratio
> *w
) {
2356 *h
= (gint
)(*w
/ self
->min_ratio
);
2358 /* you cannot resize to nothing */
2361 *w
= (gint
)(*h
* self
->min_ratio
);
2364 if (self
->max_ratio
)
2365 if (*h
* self
->max_ratio
< *w
) {
2366 *h
= (gint
)(*w
/ self
->max_ratio
);
2368 /* you cannot resize to nothing */
2371 *w
= (gint
)(*h
* self
->min_ratio
);
2376 *w
+= self
->base_size
.width
;
2377 *h
+= self
->base_size
.height
;
2380 /* gets the frame's position */
2381 frame_client_gravity(self
->frame
, x
, y
, *w
, *h
);
2383 /* these positions are frame positions, not client positions */
2385 /* set the size and position if fullscreen */
2386 if (self
->fullscreen
) {
2390 i
= screen_find_monitor(&desired_area
);
2391 a
= screen_physical_area_monitor(i
);
2398 user
= FALSE
; /* ignore if the client can't be moved/resized when it
2399 is entering fullscreen */
2400 } else if (self
->max_horz
|| self
->max_vert
) {
2404 i
= screen_find_monitor(&desired_area
);
2405 a
= screen_area_monitor(self
->desktop
, i
);
2407 /* set the size and position if maximized */
2408 if (self
->max_horz
) {
2410 *w
= a
->width
- self
->frame
->size
.left
- self
->frame
->size
.right
;
2412 if (self
->max_vert
) {
2414 *h
= a
->height
- self
->frame
->size
.top
- self
->frame
->size
.bottom
;
2417 /* maximizing is not allowed if the user can't move+resize the window
2421 /* gets the client's position */
2422 frame_frame_gravity(self
->frame
, x
, y
, *w
, *h
);
2424 /* these override the above states! if you cant move you can't move! */
2426 if (!(self
->functions
& OB_CLIENT_FUNC_MOVE
)) {
2430 if (!(self
->functions
& OB_CLIENT_FUNC_RESIZE
)) {
2431 *w
= self
->area
.width
;
2432 *h
= self
->area
.height
;
2441 void client_configure_full(ObClient
*self
, gint x
, gint y
, gint w
, gint h
,
2442 gboolean user
, gboolean final
,
2443 gboolean force_reply
)
2445 gint oldw
, oldh
, oldrx
, oldry
;
2446 gboolean send_resize_client
;
2447 gboolean moved
= FALSE
, resized
= FALSE
, rootmoved
= FALSE
;
2448 guint fdecor
= self
->frame
->decorations
;
2449 gboolean fhorz
= self
->frame
->max_horz
;
2450 gint logicalw
, logicalh
;
2452 /* find the new x, y, width, and height (and logical size) */
2453 client_try_configure(self
, &x
, &y
, &w
, &h
, &logicalw
, &logicalh
, user
);
2455 /* set the logical size if things changed */
2456 if (!(w
== self
->area
.width
&& h
== self
->area
.height
))
2457 SIZE_SET(self
->logical_size
, logicalw
, logicalh
);
2459 /* figure out if we moved or resized or what */
2460 moved
= x
!= self
->area
.x
|| y
!= self
->area
.y
;
2461 resized
= w
!= self
->area
.width
|| h
!= self
->area
.height
;
2463 oldw
= self
->area
.width
;
2464 oldh
= self
->area
.height
;
2465 RECT_SET(self
->area
, x
, y
, w
, h
);
2467 /* for app-requested resizes, always resize if 'resized' is true.
2468 for user-requested ones, only resize if final is true, or when
2469 resizing in redraw mode */
2470 send_resize_client
= ((!user
&& resized
) ||
2472 (resized
&& config_resize_redraw
))));
2474 /* if the client is enlarging, then resize the client before the frame */
2475 if (send_resize_client
&& user
&& (w
> oldw
|| h
> oldh
)) {
2476 XResizeWindow(ob_display
, self
->window
, MAX(w
, oldw
), MAX(h
, oldh
));
2477 /* resize the plate to show the client padding color underneath */
2478 frame_adjust_client_area(self
->frame
);
2481 /* find the frame's dimensions and move/resize it */
2482 if (self
->decorations
!= fdecor
|| self
->max_horz
!= fhorz
)
2483 moved
= resized
= TRUE
;
2484 if (moved
|| resized
)
2485 frame_adjust_area(self
->frame
, moved
, resized
, FALSE
);
2487 /* find the client's position relative to the root window */
2488 oldrx
= self
->root_pos
.x
;
2489 oldry
= self
->root_pos
.y
;
2490 rootmoved
= (oldrx
!= (signed)(self
->frame
->area
.x
+
2491 self
->frame
->size
.left
-
2492 self
->border_width
) ||
2493 oldry
!= (signed)(self
->frame
->area
.y
+
2494 self
->frame
->size
.top
-
2495 self
->border_width
));
2497 if (force_reply
|| ((!user
|| (user
&& final
)) && rootmoved
))
2501 POINT_SET(self
->root_pos
,
2502 self
->frame
->area
.x
+ self
->frame
->size
.left
-
2504 self
->frame
->area
.y
+ self
->frame
->size
.top
-
2505 self
->border_width
);
2507 event
.type
= ConfigureNotify
;
2508 event
.xconfigure
.display
= ob_display
;
2509 event
.xconfigure
.event
= self
->window
;
2510 event
.xconfigure
.window
= self
->window
;
2512 /* root window real coords */
2513 event
.xconfigure
.x
= self
->root_pos
.x
;
2514 event
.xconfigure
.y
= self
->root_pos
.y
;
2515 event
.xconfigure
.width
= w
;
2516 event
.xconfigure
.height
= h
;
2517 event
.xconfigure
.border_width
= 0;
2518 event
.xconfigure
.above
= self
->frame
->plate
;
2519 event
.xconfigure
.override_redirect
= FALSE
;
2520 XSendEvent(event
.xconfigure
.display
, event
.xconfigure
.window
,
2521 FALSE
, StructureNotifyMask
, &event
);
2524 /* if the client is shrinking, then resize the frame before the client */
2525 if (send_resize_client
&& (!user
|| (w
<= oldw
|| h
<= oldh
))) {
2526 /* resize the plate to show the client padding color underneath */
2527 frame_adjust_client_area(self
->frame
);
2529 XResizeWindow(ob_display
, self
->window
, w
, h
);
2535 void client_fullscreen(ObClient
*self
, gboolean fs
)
2539 if (!(self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
) || /* can't */
2540 self
->fullscreen
== fs
) return; /* already done */
2542 self
->fullscreen
= fs
;
2543 client_change_state(self
); /* change the state hints on the client */
2544 client_calc_layer(self
); /* and adjust out layer/stacking */
2547 self
->pre_fullscreen_area
= self
->area
;
2548 /* if the window is maximized, its area isn't all that meaningful.
2549 save it's premax area instead. */
2550 if (self
->max_horz
) {
2551 self
->pre_fullscreen_area
.x
= self
->pre_max_area
.x
;
2552 self
->pre_fullscreen_area
.width
= self
->pre_max_area
.width
;
2554 if (self
->max_vert
) {
2555 self
->pre_fullscreen_area
.y
= self
->pre_max_area
.y
;
2556 self
->pre_fullscreen_area
.height
= self
->pre_max_area
.height
;
2559 /* these are not actually used cuz client_configure will set them
2560 as appropriate when the window is fullscreened */
2565 if (self
->pre_fullscreen_area
.width
> 0 &&
2566 self
->pre_fullscreen_area
.height
> 0)
2568 x
= self
->pre_fullscreen_area
.x
;
2569 y
= self
->pre_fullscreen_area
.y
;
2570 w
= self
->pre_fullscreen_area
.width
;
2571 h
= self
->pre_fullscreen_area
.height
;
2572 RECT_SET(self
->pre_fullscreen_area
, 0, 0, 0, 0);
2574 /* pick some fallbacks... */
2575 a
= screen_area_monitor(self
->desktop
, 0);
2576 x
= a
->x
+ a
->width
/ 4;
2577 y
= a
->y
+ a
->height
/ 4;
2583 client_setup_decor_and_functions(self
);
2585 client_move_resize(self
, x
, y
, w
, h
);
2587 /* try focus us when we go into fullscreen mode */
2591 static void client_iconify_recursive(ObClient
*self
,
2592 gboolean iconic
, gboolean curdesk
)
2595 gboolean changed
= FALSE
;
2598 if (self
->iconic
!= iconic
) {
2599 ob_debug("%sconifying window: 0x%lx\n", (iconic
? "I" : "Uni"),
2603 if (self
->functions
& OB_CLIENT_FUNC_ICONIFY
) {
2604 self
->iconic
= iconic
;
2606 /* update the focus lists.. iconic windows go to the bottom of
2607 the list, put the new iconic window at the 'top of the
2609 focus_order_to_top(self
);
2614 self
->iconic
= iconic
;
2616 if (curdesk
&& self
->desktop
!= screen_desktop
&&
2617 self
->desktop
!= DESKTOP_ALL
)
2618 client_set_desktop(self
, screen_desktop
, FALSE
);
2620 /* this puts it after the current focused window */
2621 focus_order_remove(self
);
2622 focus_order_add_new(self
);
2629 client_change_state(self
);
2630 client_showhide(self
);
2631 if (STRUT_EXISTS(self
->strut
))
2632 screen_update_areas();
2635 /* iconify all direct transients, and deiconify all transients
2637 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
2638 if (it
->data
!= self
)
2639 if (client_is_direct_child(self
, it
->data
) || !iconic
)
2640 client_iconify_recursive(it
->data
, iconic
, curdesk
);
2643 void client_iconify(ObClient
*self
, gboolean iconic
, gboolean curdesk
)
2645 /* move up the transient chain as far as possible first */
2646 self
= client_search_top_parent(self
);
2647 client_iconify_recursive(self
, iconic
, curdesk
);
2650 void client_maximize(ObClient
*self
, gboolean max
, gint dir
)
2654 g_assert(dir
== 0 || dir
== 1 || dir
== 2);
2655 if (!(self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
)) return; /* can't */
2657 /* check if already done */
2659 if (dir
== 0 && self
->max_horz
&& self
->max_vert
) return;
2660 if (dir
== 1 && self
->max_horz
) return;
2661 if (dir
== 2 && self
->max_vert
) return;
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;
2668 /* we just tell it to configure in the same place and client_configure
2669 worries about filling the screen with the window */
2672 w
= self
->area
.width
;
2673 h
= self
->area
.height
;
2676 if ((dir
== 0 || dir
== 1) && !self
->max_horz
) { /* horz */
2677 RECT_SET(self
->pre_max_area
,
2678 self
->area
.x
, self
->pre_max_area
.y
,
2679 self
->area
.width
, self
->pre_max_area
.height
);
2681 if ((dir
== 0 || dir
== 2) && !self
->max_vert
) { /* vert */
2682 RECT_SET(self
->pre_max_area
,
2683 self
->pre_max_area
.x
, self
->area
.y
,
2684 self
->pre_max_area
.width
, self
->area
.height
);
2689 a
= screen_area_monitor(self
->desktop
, 0);
2690 if ((dir
== 0 || dir
== 1) && self
->max_horz
) { /* horz */
2691 if (self
->pre_max_area
.width
> 0) {
2692 x
= self
->pre_max_area
.x
;
2693 w
= self
->pre_max_area
.width
;
2695 RECT_SET(self
->pre_max_area
, 0, self
->pre_max_area
.y
,
2696 0, self
->pre_max_area
.height
);
2698 /* pick some fallbacks... */
2699 x
= a
->x
+ a
->width
/ 4;
2703 if ((dir
== 0 || dir
== 2) && self
->max_vert
) { /* vert */
2704 if (self
->pre_max_area
.height
> 0) {
2705 y
= self
->pre_max_area
.y
;
2706 h
= self
->pre_max_area
.height
;
2708 RECT_SET(self
->pre_max_area
, self
->pre_max_area
.x
, 0,
2709 self
->pre_max_area
.width
, 0);
2711 /* pick some fallbacks... */
2712 y
= a
->y
+ a
->height
/ 4;
2718 if (dir
== 0 || dir
== 1) /* horz */
2719 self
->max_horz
= max
;
2720 if (dir
== 0 || dir
== 2) /* vert */
2721 self
->max_vert
= max
;
2723 client_change_state(self
); /* change the state hints on the client */
2725 client_setup_decor_and_functions(self
);
2727 client_move_resize(self
, x
, y
, w
, h
);
2730 void client_shade(ObClient
*self
, gboolean shade
)
2732 if ((!(self
->functions
& OB_CLIENT_FUNC_SHADE
) &&
2733 shade
) || /* can't shade */
2734 self
->shaded
== shade
) return; /* already done */
2736 self
->shaded
= shade
;
2737 client_change_state(self
);
2738 client_change_wm_state(self
); /* the window is being hidden/shown */
2739 /* resize the frame to just the titlebar */
2740 frame_adjust_area(self
->frame
, FALSE
, FALSE
, FALSE
);
2743 void client_close(ObClient
*self
)
2747 if (!(self
->functions
& OB_CLIENT_FUNC_CLOSE
)) return;
2749 /* in the case that the client provides no means to requesting that it
2750 close, we just kill it */
2751 if (!self
->delete_window
)
2755 XXX: itd be cool to do timeouts and shit here for killing the client's
2757 like... if the window is around after 5 seconds, then the close button
2758 turns a nice red, and if this function is called again, the client is
2762 ce
.xclient
.type
= ClientMessage
;
2763 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
2764 ce
.xclient
.display
= ob_display
;
2765 ce
.xclient
.window
= self
->window
;
2766 ce
.xclient
.format
= 32;
2767 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_delete_window
;
2768 ce
.xclient
.data
.l
[1] = event_curtime
;
2769 ce
.xclient
.data
.l
[2] = 0l;
2770 ce
.xclient
.data
.l
[3] = 0l;
2771 ce
.xclient
.data
.l
[4] = 0l;
2772 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
2775 void client_kill(ObClient
*self
)
2777 XKillClient(ob_display
, self
->window
);
2780 void client_hilite(ObClient
*self
, gboolean hilite
)
2782 if (self
->demands_attention
== hilite
)
2783 return; /* no change */
2785 /* don't allow focused windows to hilite */
2786 self
->demands_attention
= hilite
&& !client_focused(self
);
2787 if (self
->frame
!= NULL
) { /* if we're mapping, just set the state */
2788 if (self
->demands_attention
)
2789 frame_flash_start(self
->frame
);
2791 frame_flash_stop(self
->frame
);
2792 client_change_state(self
);
2796 void client_set_desktop_recursive(ObClient
*self
,
2797 guint target
, gboolean donthide
)
2802 if (target
!= self
->desktop
) {
2804 ob_debug("Setting desktop %u\n", target
+1);
2806 g_assert(target
< screen_num_desktops
|| target
== DESKTOP_ALL
);
2808 /* remove from the old desktop(s) */
2809 focus_order_remove(self
);
2811 old
= self
->desktop
;
2812 self
->desktop
= target
;
2813 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, target
);
2814 /* the frame can display the current desktop state */
2815 frame_adjust_state(self
->frame
);
2816 /* 'move' the window to the new desktop */
2818 client_showhide(self
);
2819 /* raise if it was not already on the desktop */
2820 if (old
!= DESKTOP_ALL
)
2822 if (STRUT_EXISTS(self
->strut
))
2823 screen_update_areas();
2825 /* add to the new desktop(s) */
2826 if (config_focus_new
)
2827 focus_order_to_top(self
);
2829 focus_order_to_bottom(self
);
2832 /* move all transients */
2833 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
2834 if (it
->data
!= self
)
2835 if (client_is_direct_child(self
, it
->data
))
2836 client_set_desktop_recursive(it
->data
, target
, donthide
);
2839 void client_set_desktop(ObClient
*self
, guint target
, gboolean donthide
)
2841 self
= client_search_top_parent(self
);
2842 client_set_desktop_recursive(self
, target
, donthide
);
2845 gboolean
client_is_direct_child(ObClient
*parent
, ObClient
*child
)
2847 while (child
!= parent
&&
2848 child
->transient_for
&& child
->transient_for
!= OB_TRAN_GROUP
)
2849 child
= child
->transient_for
;
2850 return child
== parent
;
2853 ObClient
*client_search_modal_child(ObClient
*self
)
2858 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
2859 ObClient
*c
= it
->data
;
2860 if ((ret
= client_search_modal_child(c
))) return ret
;
2861 if (c
->modal
) return c
;
2866 gboolean
client_validate(ObClient
*self
)
2870 XSync(ob_display
, FALSE
); /* get all events on the server */
2872 if (XCheckTypedWindowEvent(ob_display
, self
->window
, DestroyNotify
, &e
) ||
2873 XCheckTypedWindowEvent(ob_display
, self
->window
, UnmapNotify
, &e
)) {
2874 XPutBackEvent(ob_display
, &e
);
2881 void client_set_wm_state(ObClient
*self
, glong state
)
2883 if (state
== self
->wmstate
) return; /* no change */
2887 client_iconify(self
, TRUE
, TRUE
);
2890 client_iconify(self
, FALSE
, TRUE
);
2895 void client_set_state(ObClient
*self
, Atom action
, glong data1
, glong data2
)
2897 gboolean shaded
= self
->shaded
;
2898 gboolean fullscreen
= self
->fullscreen
;
2899 gboolean undecorated
= self
->undecorated
;
2900 gboolean max_horz
= self
->max_horz
;
2901 gboolean max_vert
= self
->max_vert
;
2902 gboolean modal
= self
->modal
;
2903 gboolean iconic
= self
->iconic
;
2904 gboolean demands_attention
= self
->demands_attention
;
2907 if (!(action
== prop_atoms
.net_wm_state_add
||
2908 action
== prop_atoms
.net_wm_state_remove
||
2909 action
== prop_atoms
.net_wm_state_toggle
))
2910 /* an invalid action was passed to the client message, ignore it */
2913 for (i
= 0; i
< 2; ++i
) {
2914 Atom state
= i
== 0 ? data1
: data2
;
2916 if (!state
) continue;
2918 /* if toggling, then pick whether we're adding or removing */
2919 if (action
== prop_atoms
.net_wm_state_toggle
) {
2920 if (state
== prop_atoms
.net_wm_state_modal
)
2921 action
= modal
? prop_atoms
.net_wm_state_remove
:
2922 prop_atoms
.net_wm_state_add
;
2923 else if (state
== prop_atoms
.net_wm_state_maximized_vert
)
2924 action
= self
->max_vert
? prop_atoms
.net_wm_state_remove
:
2925 prop_atoms
.net_wm_state_add
;
2926 else if (state
== prop_atoms
.net_wm_state_maximized_horz
)
2927 action
= self
->max_horz
? prop_atoms
.net_wm_state_remove
:
2928 prop_atoms
.net_wm_state_add
;
2929 else if (state
== prop_atoms
.net_wm_state_shaded
)
2930 action
= shaded
? prop_atoms
.net_wm_state_remove
:
2931 prop_atoms
.net_wm_state_add
;
2932 else if (state
== prop_atoms
.net_wm_state_skip_taskbar
)
2933 action
= self
->skip_taskbar
?
2934 prop_atoms
.net_wm_state_remove
:
2935 prop_atoms
.net_wm_state_add
;
2936 else if (state
== prop_atoms
.net_wm_state_skip_pager
)
2937 action
= self
->skip_pager
?
2938 prop_atoms
.net_wm_state_remove
:
2939 prop_atoms
.net_wm_state_add
;
2940 else if (state
== prop_atoms
.net_wm_state_hidden
)
2941 action
= self
->iconic
?
2942 prop_atoms
.net_wm_state_remove
:
2943 prop_atoms
.net_wm_state_add
;
2944 else if (state
== prop_atoms
.net_wm_state_fullscreen
)
2945 action
= fullscreen
?
2946 prop_atoms
.net_wm_state_remove
:
2947 prop_atoms
.net_wm_state_add
;
2948 else if (state
== prop_atoms
.net_wm_state_above
)
2949 action
= self
->above
? prop_atoms
.net_wm_state_remove
:
2950 prop_atoms
.net_wm_state_add
;
2951 else if (state
== prop_atoms
.net_wm_state_below
)
2952 action
= self
->below
? prop_atoms
.net_wm_state_remove
:
2953 prop_atoms
.net_wm_state_add
;
2954 else if (state
== prop_atoms
.net_wm_state_demands_attention
)
2955 action
= self
->demands_attention
?
2956 prop_atoms
.net_wm_state_remove
:
2957 prop_atoms
.net_wm_state_add
;
2958 else if (state
== prop_atoms
.ob_wm_state_undecorated
)
2959 action
= undecorated
? prop_atoms
.net_wm_state_remove
:
2960 prop_atoms
.net_wm_state_add
;
2963 if (action
== prop_atoms
.net_wm_state_add
) {
2964 if (state
== prop_atoms
.net_wm_state_modal
) {
2966 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
2968 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
2970 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
2972 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
2973 self
->skip_taskbar
= TRUE
;
2974 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
2975 self
->skip_pager
= TRUE
;
2976 } else if (state
== prop_atoms
.net_wm_state_hidden
) {
2978 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
2980 } else if (state
== prop_atoms
.net_wm_state_above
) {
2982 self
->below
= FALSE
;
2983 } else if (state
== prop_atoms
.net_wm_state_below
) {
2984 self
->above
= FALSE
;
2986 } else if (state
== prop_atoms
.net_wm_state_demands_attention
) {
2987 demands_attention
= TRUE
;
2988 } else if (state
== prop_atoms
.ob_wm_state_undecorated
) {
2992 } else { /* action == prop_atoms.net_wm_state_remove */
2993 if (state
== prop_atoms
.net_wm_state_modal
) {
2995 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
2997 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
2999 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
3001 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
3002 self
->skip_taskbar
= FALSE
;
3003 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
3004 self
->skip_pager
= FALSE
;
3005 } else if (state
== prop_atoms
.net_wm_state_hidden
) {
3007 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
3009 } else if (state
== prop_atoms
.net_wm_state_above
) {
3010 self
->above
= FALSE
;
3011 } else if (state
== prop_atoms
.net_wm_state_below
) {
3012 self
->below
= FALSE
;
3013 } else if (state
== prop_atoms
.net_wm_state_demands_attention
) {
3014 demands_attention
= FALSE
;
3015 } else if (state
== prop_atoms
.ob_wm_state_undecorated
) {
3016 undecorated
= FALSE
;
3020 if (max_horz
!= self
->max_horz
|| max_vert
!= self
->max_vert
) {
3021 if (max_horz
!= self
->max_horz
&& max_vert
!= self
->max_vert
) {
3023 if (max_horz
== max_vert
) { /* both going the same way */
3024 client_maximize(self
, max_horz
, 0);
3026 client_maximize(self
, max_horz
, 1);
3027 client_maximize(self
, max_vert
, 2);
3031 if (max_horz
!= self
->max_horz
)
3032 client_maximize(self
, max_horz
, 1);
3034 client_maximize(self
, max_vert
, 2);
3037 /* change fullscreen state before shading, as it will affect if the window
3039 if (fullscreen
!= self
->fullscreen
)
3040 client_fullscreen(self
, fullscreen
);
3041 if (shaded
!= self
->shaded
)
3042 client_shade(self
, shaded
);
3043 if (undecorated
!= self
->undecorated
)
3044 client_set_undecorated(self
, undecorated
);
3045 if (modal
!= self
->modal
) {
3046 self
->modal
= modal
;
3047 /* when a window changes modality, then its stacking order with its
3048 transients needs to change */
3051 if (iconic
!= self
->iconic
)
3052 client_iconify(self
, iconic
, FALSE
);
3054 if (demands_attention
!= self
->demands_attention
)
3055 client_hilite(self
, demands_attention
);
3057 client_change_state(self
); /* change the hint to reflect these changes */
3060 ObClient
*client_focus_target(ObClient
*self
)
3062 ObClient
*child
= NULL
;
3064 child
= client_search_modal_child(self
);
3065 if (child
) return child
;
3069 gboolean
client_can_focus(ObClient
*self
)
3073 /* choose the correct target */
3074 self
= client_focus_target(self
);
3076 if (!self
->frame
->visible
)
3079 if (!(self
->can_focus
|| self
->focus_notify
))
3082 /* do a check to see if the window has already been unmapped or destroyed
3083 do this intelligently while watching out for unmaps we've generated
3084 (ignore_unmaps > 0) */
3085 if (XCheckTypedWindowEvent(ob_display
, self
->window
,
3086 DestroyNotify
, &ev
)) {
3087 XPutBackEvent(ob_display
, &ev
);
3090 while (XCheckTypedWindowEvent(ob_display
, self
->window
,
3091 UnmapNotify
, &ev
)) {
3092 if (self
->ignore_unmaps
) {
3093 self
->ignore_unmaps
--;
3095 XPutBackEvent(ob_display
, &ev
);
3103 gboolean
client_focus(ObClient
*self
)
3105 /* choose the correct target */
3106 self
= client_focus_target(self
);
3108 if (!client_can_focus(self
)) {
3109 if (!self
->frame
->visible
) {
3110 /* update the focus lists */
3111 focus_order_to_top(self
);
3116 ob_debug_type(OB_DEBUG_FOCUS
,
3117 "Focusing client \"%s\" at time %u\n",
3118 self
->title
, event_curtime
);
3120 if (self
->can_focus
) {
3121 /* This can cause a BadMatch error with CurrentTime, or if an app
3122 passed in a bad time for _NET_WM_ACTIVE_WINDOW. */
3123 xerror_set_ignore(TRUE
);
3124 XSetInputFocus(ob_display
, self
->window
, RevertToPointerRoot
,
3126 xerror_set_ignore(FALSE
);
3129 if (self
->focus_notify
) {
3131 ce
.xclient
.type
= ClientMessage
;
3132 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
3133 ce
.xclient
.display
= ob_display
;
3134 ce
.xclient
.window
= self
->window
;
3135 ce
.xclient
.format
= 32;
3136 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_take_focus
;
3137 ce
.xclient
.data
.l
[1] = event_curtime
;
3138 ce
.xclient
.data
.l
[2] = 0l;
3139 ce
.xclient
.data
.l
[3] = 0l;
3140 ce
.xclient
.data
.l
[4] = 0l;
3141 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
3145 ob_debug("%sively focusing %lx at %d\n",
3146 (self
->can_focus
? "act" : "pass"),
3147 self
->window
, (gint
) event_curtime
);
3150 /* Cause the FocusIn to come back to us. Important for desktop switches,
3151 since otherwise we'll have no FocusIn on the queue and send it off to
3152 the focus_backup. */
3153 XSync(ob_display
, FALSE
);
3157 void client_activate(ObClient
*self
, gboolean here
, gboolean user
)
3159 guint32 last_time
= focus_client
? focus_client
->user_time
: CurrentTime
;
3161 /* XXX do some stuff here if user is false to determine if we really want
3162 to activate it or not (a parent or group member is currently
3165 ob_debug_type(OB_DEBUG_FOCUS
,
3166 "Want to activate window 0x%x with time %u (last time %u), "
3168 self
->window
, event_curtime
, last_time
,
3169 (user
? "user" : "application"));
3171 if (!user
&& event_curtime
&& last_time
&&
3172 !event_time_after(event_curtime
, last_time
))
3174 client_hilite(self
, TRUE
);
3176 if (event_curtime
!= CurrentTime
)
3177 self
->user_time
= event_curtime
;
3179 /* if using focus_delay, stop the timer now so that focus doesn't
3181 event_halt_focus_delay();
3183 if (client_normal(self
) && screen_showing_desktop
)
3184 screen_show_desktop(FALSE
);
3186 client_iconify(self
, FALSE
, here
);
3187 if (self
->desktop
!= DESKTOP_ALL
&&
3188 self
->desktop
!= screen_desktop
)
3191 client_set_desktop(self
, screen_desktop
, FALSE
);
3193 screen_set_desktop(self
->desktop
);
3194 } else if (!self
->frame
->visible
)
3195 /* if its not visible for other reasons, then don't mess
3199 client_shade(self
, FALSE
);
3203 /* we do this as an action here. this is rather important. this is
3204 because we want the results from the focus change to take place
3205 BEFORE we go about raising the window. when a fullscreen window
3206 loses focus, we need this or else the raise wont be able to raise
3207 above the to-lose-focus fullscreen window. */
3212 void client_raise(ObClient
*self
)
3214 action_run_string("Raise", self
, CurrentTime
);
3217 void client_lower(ObClient
*self
)
3219 action_run_string("Lower", self
, CurrentTime
);
3222 gboolean
client_focused(ObClient
*self
)
3224 return self
== focus_client
;
3227 static ObClientIcon
* client_icon_recursive(ObClient
*self
, gint w
, gint h
)
3230 /* si is the smallest image >= req */
3231 /* li is the largest image < req */
3232 gulong size
, smallest
= 0xffffffff, largest
= 0, si
= 0, li
= 0;
3234 if (!self
->nicons
) {
3235 ObClientIcon
*parent
= NULL
;
3237 if (self
->transient_for
) {
3238 if (self
->transient_for
!= OB_TRAN_GROUP
)
3239 parent
= client_icon_recursive(self
->transient_for
, w
, h
);
3242 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
3243 ObClient
*c
= it
->data
;
3244 if (c
!= self
&& !c
->transient_for
) {
3245 if ((parent
= client_icon_recursive(c
, w
, h
)))
3255 for (i
= 0; i
< self
->nicons
; ++i
) {
3256 size
= self
->icons
[i
].width
* self
->icons
[i
].height
;
3257 if (size
< smallest
&& size
>= (unsigned)(w
* h
)) {
3261 if (size
> largest
&& size
<= (unsigned)(w
* h
)) {
3266 if (largest
== 0) /* didnt find one smaller than the requested size */
3267 return &self
->icons
[si
];
3268 return &self
->icons
[li
];
3271 const ObClientIcon
* client_icon(ObClient
*self
, gint w
, gint h
)
3274 static ObClientIcon deficon
;
3276 if (!(ret
= client_icon_recursive(self
, w
, h
))) {
3277 deficon
.width
= deficon
.height
= 48;
3278 deficon
.data
= ob_rr_theme
->def_win_icon
;
3284 void client_set_layer(ObClient
*self
, gint layer
)
3288 self
->above
= FALSE
;
3289 } else if (layer
== 0) {
3290 self
->below
= self
->above
= FALSE
;
3292 self
->below
= FALSE
;
3295 client_calc_layer(self
);
3296 client_change_state(self
); /* reflect this in the state hints */
3299 void client_set_undecorated(ObClient
*self
, gboolean undecorated
)
3301 if (self
->undecorated
!= undecorated
) {
3302 self
->undecorated
= undecorated
;
3303 client_setup_decor_and_functions(self
);
3304 /* Make sure the client knows it might have moved. Maybe there is a
3305 * better way of doing this so only one client_configure is sent, but
3306 * since 125 of these are sent per second when moving the window (with
3307 * user = FALSE) i doubt it matters much.
3309 client_configure(self
, self
->area
.x
, self
->area
.y
,
3310 self
->area
.width
, self
->area
.height
, TRUE
, TRUE
);
3311 client_change_state(self
); /* reflect this in the state hints */
3315 guint
client_monitor(ObClient
*self
)
3317 return screen_find_monitor(&self
->frame
->area
);
3320 ObClient
*client_search_top_parent(ObClient
*self
)
3322 while (self
->transient_for
&& self
->transient_for
!= OB_TRAN_GROUP
&&
3323 client_normal(self
))
3324 self
= self
->transient_for
;
3328 GSList
*client_search_all_top_parents(ObClient
*self
)
3332 /* move up the direct transient chain as far as possible */
3333 while (self
->transient_for
&& self
->transient_for
!= OB_TRAN_GROUP
)
3334 self
= self
->transient_for
;
3336 if (!self
->transient_for
)
3337 ret
= g_slist_prepend(ret
, self
);
3341 g_assert(self
->group
);
3343 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
3344 ObClient
*c
= it
->data
;
3346 if (!c
->transient_for
&& client_normal(c
))
3347 ret
= g_slist_prepend(ret
, c
);
3350 if (ret
== NULL
) /* no group parents */
3351 ret
= g_slist_prepend(ret
, self
);
3357 ObClient
*client_search_focus_parent(ObClient
*self
)
3359 if (self
->transient_for
) {
3360 if (self
->transient_for
!= OB_TRAN_GROUP
) {
3361 if (client_focused(self
->transient_for
))
3362 return self
->transient_for
;
3366 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
3367 ObClient
*c
= it
->data
;
3369 /* checking transient_for prevents infinate loops! */
3370 if (c
!= self
&& !c
->transient_for
)
3371 if (client_focused(c
))
3380 ObClient
*client_search_parent(ObClient
*self
, ObClient
*search
)
3382 if (self
->transient_for
) {
3383 if (self
->transient_for
!= OB_TRAN_GROUP
) {
3384 if (self
->transient_for
== search
)
3389 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
3390 ObClient
*c
= it
->data
;
3392 /* checking transient_for prevents infinate loops! */
3393 if (c
!= self
&& !c
->transient_for
)
3403 ObClient
*client_search_transient(ObClient
*self
, ObClient
*search
)
3407 for (sit
= self
->transients
; sit
; sit
= g_slist_next(sit
)) {
3408 if (sit
->data
== search
)
3410 if (client_search_transient(sit
->data
, search
))
3416 void client_update_sm_client_id(ObClient
*self
)
3418 g_free(self
->sm_client_id
);
3419 self
->sm_client_id
= NULL
;
3421 if (!PROP_GETS(self
->window
, sm_client_id
, locale
, &self
->sm_client_id
) &&
3423 PROP_GETS(self
->group
->leader
, sm_client_id
, locale
,
3424 &self
->sm_client_id
);
3427 #define WANT_EDGE(cur, c) \
3430 if(!client_normal(cur)) \
3432 if(screen_desktop != cur->desktop && cur->desktop != DESKTOP_ALL) \
3436 if(cur->layer < c->layer && !config_resist_layers_below) \
3439 #define HIT_EDGE(my_edge_start, my_edge_end, his_edge_start, his_edge_end) \
3440 if ((his_edge_start >= my_edge_start && \
3441 his_edge_start <= my_edge_end) || \
3442 (my_edge_start >= his_edge_start && \
3443 my_edge_start <= his_edge_end)) \
3446 /* finds the nearest edge in the given direction from the current client
3447 * note to self: the edge is the -frame- edge (the actual one), not the
3450 gint
client_directional_edge_search(ObClient
*c
, ObDirection dir
, gboolean hang
)
3452 gint dest
, monitor_dest
;
3453 gint my_edge_start
, my_edge_end
, my_offset
;
3460 a
= screen_area(c
->desktop
);
3461 monitor
= screen_area_monitor(c
->desktop
, client_monitor(c
));
3464 case OB_DIRECTION_NORTH
:
3465 my_edge_start
= c
->frame
->area
.x
;
3466 my_edge_end
= c
->frame
->area
.x
+ c
->frame
->area
.width
;
3467 my_offset
= c
->frame
->area
.y
+ (hang
? c
->frame
->area
.height
: 0);
3469 /* default: top of screen */
3470 dest
= a
->y
+ (hang
? c
->frame
->area
.height
: 0);
3471 monitor_dest
= monitor
->y
+ (hang
? c
->frame
->area
.height
: 0);
3472 /* if the monitor edge comes before the screen edge, */
3473 /* use that as the destination instead. (For xinerama) */
3474 if (monitor_dest
!= dest
&& my_offset
> monitor_dest
)
3475 dest
= monitor_dest
;
3477 for(it
= client_list
; it
&& my_offset
!= dest
; it
= g_list_next(it
)) {
3478 gint his_edge_start
, his_edge_end
, his_offset
;
3479 ObClient
*cur
= it
->data
;
3483 his_edge_start
= cur
->frame
->area
.x
;
3484 his_edge_end
= cur
->frame
->area
.x
+ cur
->frame
->area
.width
;
3485 his_offset
= cur
->frame
->area
.y
+
3486 (hang
? 0 : cur
->frame
->area
.height
);
3488 if(his_offset
+ 1 > my_offset
)
3491 if(his_offset
< dest
)
3494 HIT_EDGE(my_edge_start
, my_edge_end
, his_edge_start
, his_edge_end
)
3497 case OB_DIRECTION_SOUTH
:
3498 my_edge_start
= c
->frame
->area
.x
;
3499 my_edge_end
= c
->frame
->area
.x
+ c
->frame
->area
.width
;
3500 my_offset
= c
->frame
->area
.y
+ (hang
? 0 : c
->frame
->area
.height
);
3502 /* default: bottom of screen */
3503 dest
= a
->y
+ a
->height
- (hang
? c
->frame
->area
.height
: 0);
3504 monitor_dest
= monitor
->y
+ monitor
->height
-
3505 (hang
? c
->frame
->area
.height
: 0);
3506 /* if the monitor edge comes before the screen edge, */
3507 /* use that as the destination instead. (For xinerama) */
3508 if (monitor_dest
!= dest
&& my_offset
< monitor_dest
)
3509 dest
= monitor_dest
;
3511 for(it
= client_list
; it
&& my_offset
!= dest
; it
= g_list_next(it
)) {
3512 gint his_edge_start
, his_edge_end
, his_offset
;
3513 ObClient
*cur
= it
->data
;
3517 his_edge_start
= cur
->frame
->area
.x
;
3518 his_edge_end
= cur
->frame
->area
.x
+ cur
->frame
->area
.width
;
3519 his_offset
= cur
->frame
->area
.y
+
3520 (hang
? cur
->frame
->area
.height
: 0);
3523 if(his_offset
- 1 < my_offset
)
3526 if(his_offset
> dest
)
3529 HIT_EDGE(my_edge_start
, my_edge_end
, his_edge_start
, his_edge_end
)
3532 case OB_DIRECTION_WEST
:
3533 my_edge_start
= c
->frame
->area
.y
;
3534 my_edge_end
= c
->frame
->area
.y
+ c
->frame
->area
.height
;
3535 my_offset
= c
->frame
->area
.x
+ (hang
? c
->frame
->area
.width
: 0);
3537 /* default: leftmost egde of screen */
3538 dest
= a
->x
+ (hang
? c
->frame
->area
.width
: 0);
3539 monitor_dest
= monitor
->x
+ (hang
? c
->frame
->area
.width
: 0);
3540 /* if the monitor edge comes before the screen edge, */
3541 /* use that as the destination instead. (For xinerama) */
3542 if (monitor_dest
!= dest
&& my_offset
> monitor_dest
)
3543 dest
= monitor_dest
;
3545 for(it
= client_list
; it
&& my_offset
!= dest
; it
= g_list_next(it
)) {
3546 gint his_edge_start
, his_edge_end
, his_offset
;
3547 ObClient
*cur
= it
->data
;
3551 his_edge_start
= cur
->frame
->area
.y
;
3552 his_edge_end
= cur
->frame
->area
.y
+ cur
->frame
->area
.height
;
3553 his_offset
= cur
->frame
->area
.x
+
3554 (hang
? 0 : cur
->frame
->area
.width
);
3556 if(his_offset
+ 1 > my_offset
)
3559 if(his_offset
< dest
)
3562 HIT_EDGE(my_edge_start
, my_edge_end
, his_edge_start
, his_edge_end
)
3565 case OB_DIRECTION_EAST
:
3566 my_edge_start
= c
->frame
->area
.y
;
3567 my_edge_end
= c
->frame
->area
.y
+ c
->frame
->area
.height
;
3568 my_offset
= c
->frame
->area
.x
+ (hang
? 0 : c
->frame
->area
.width
);
3570 /* default: rightmost edge of screen */
3571 dest
= a
->x
+ a
->width
- (hang
? c
->frame
->area
.width
: 0);
3572 monitor_dest
= monitor
->x
+ monitor
->width
-
3573 (hang
? c
->frame
->area
.width
: 0);
3574 /* if the monitor edge comes before the screen edge, */
3575 /* use that as the destination instead. (For xinerama) */
3576 if (monitor_dest
!= dest
&& my_offset
< monitor_dest
)
3577 dest
= monitor_dest
;
3579 for(it
= client_list
; it
&& my_offset
!= dest
; it
= g_list_next(it
)) {
3580 gint his_edge_start
, his_edge_end
, his_offset
;
3581 ObClient
*cur
= it
->data
;
3585 his_edge_start
= cur
->frame
->area
.y
;
3586 his_edge_end
= cur
->frame
->area
.y
+ cur
->frame
->area
.height
;
3587 his_offset
= cur
->frame
->area
.x
+
3588 (hang
? cur
->frame
->area
.width
: 0);
3590 if(his_offset
- 1 < my_offset
)
3593 if(his_offset
> dest
)
3596 HIT_EDGE(my_edge_start
, my_edge_end
, his_edge_start
, his_edge_end
)
3599 case OB_DIRECTION_NORTHEAST
:
3600 case OB_DIRECTION_SOUTHEAST
:
3601 case OB_DIRECTION_NORTHWEST
:
3602 case OB_DIRECTION_SOUTHWEST
:
3603 /* not implemented */
3605 g_assert_not_reached();
3606 dest
= 0; /* suppress warning */
3611 ObClient
* client_under_pointer()
3615 ObClient
*ret
= NULL
;
3617 if (screen_pointer_pos(&x
, &y
)) {
3618 for (it
= stacking_list
; it
; it
= g_list_next(it
)) {
3619 if (WINDOW_IS_CLIENT(it
->data
)) {
3620 ObClient
*c
= WINDOW_AS_CLIENT(it
->data
);
3621 if (c
->frame
->visible
&&
3622 RECT_CONTAINS(c
->frame
->area
, x
, y
)) {
3632 gboolean
client_has_group_siblings(ObClient
*self
)
3634 return self
->group
&& self
->group
->members
->next
;
3637 gboolean
client_has_application_group_siblings(ObClient
*self
)
3641 if (!self
->group
) return FALSE
;
3643 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
3644 ObClient
*c
= it
->data
;
3645 if (c
!= self
&& client_application(c
))