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_get_transientness(ObClient
*self
);
81 static void client_change_allowed_actions(ObClient
*self
);
82 static void client_change_state(ObClient
*self
);
83 static void client_change_wm_state(ObClient
*self
);
84 static void client_apply_startup_state(ObClient
*self
, gint x
, gint y
);
85 static void client_restore_session_state(ObClient
*self
);
86 static gboolean
client_restore_session_stacking(ObClient
*self
);
87 static ObAppSettings
*client_get_settings_state(ObClient
*self
);
88 static void client_update_transient_tree(ObClient
*self
,
89 ObGroup
*oldgroup
, ObGroup
*newgroup
,
92 static void client_present(ObClient
*self
, gboolean here
, gboolean raise
);
93 static GSList
*client_search_all_top_parents_internal(ObClient
*self
,
95 ObStackingLayer layer
);
97 void client_startup(gboolean reconfig
)
104 void client_shutdown(gboolean reconfig
)
108 void client_add_destructor(ObClientDestructor func
, gpointer data
)
110 Destructor
*d
= g_new(Destructor
, 1);
113 client_destructors
= g_slist_prepend(client_destructors
, d
);
116 void client_remove_destructor(ObClientDestructor func
)
120 for (it
= client_destructors
; it
; it
= g_slist_next(it
)) {
121 Destructor
*d
= it
->data
;
122 if (d
->func
== func
) {
124 client_destructors
= g_slist_delete_link(client_destructors
, it
);
130 void client_set_list()
132 Window
*windows
, *win_it
;
134 guint size
= g_list_length(client_list
);
136 /* create an array of the window ids */
138 windows
= g_new(Window
, size
);
140 for (it
= client_list
; it
; it
= g_list_next(it
), ++win_it
)
141 *win_it
= ((ObClient
*)it
->data
)->window
;
145 PROP_SETA32(RootWindow(ob_display
, ob_screen
),
146 net_client_list
, window
, (gulong
*)windows
, size
);
155 void client_foreach_transient(ObClient *self, ObClientForeachFunc func, gpointer data)
159 for (it = self->transients; it; it = g_slist_next(it)) {
160 if (!func(it->data, data)) return;
161 client_foreach_transient(it->data, func, data);
165 void client_foreach_ancestor(ObClient *self, ObClientForeachFunc func, gpointer data)
167 if (self->transient_for) {
168 if (self->transient_for != OB_TRAN_GROUP) {
169 if (!func(self->transient_for, data)) return;
170 client_foreach_ancestor(self->transient_for, func, data);
174 for (it = self->group->members; it; it = g_slist_next(it))
175 if (it->data != self &&
176 !((ObClient*)it->data)->transient_for) {
177 if (!func(it->data, data)) return;
178 client_foreach_ancestor(it->data, func, data);
185 void client_manage_all()
190 XWindowAttributes attrib
;
192 XQueryTree(ob_display
, RootWindow(ob_display
, ob_screen
),
193 &w
, &w
, &children
, &nchild
);
195 /* remove all icon windows from the list */
196 for (i
= 0; i
< nchild
; i
++) {
197 if (children
[i
] == None
) continue;
198 wmhints
= XGetWMHints(ob_display
, children
[i
]);
200 if ((wmhints
->flags
& IconWindowHint
) &&
201 (wmhints
->icon_window
!= children
[i
]))
202 for (j
= 0; j
< nchild
; j
++)
203 if (children
[j
] == wmhints
->icon_window
) {
211 for (i
= 0; i
< nchild
; ++i
) {
212 if (children
[i
] == None
)
214 if (XGetWindowAttributes(ob_display
, children
[i
], &attrib
)) {
215 if (attrib
.override_redirect
) continue;
217 if (attrib
.map_state
!= IsUnmapped
)
218 client_manage(children
[i
]);
224 void client_manage(Window window
)
228 XWindowAttributes attrib
;
229 XSetWindowAttributes attrib_set
;
231 gboolean activate
= FALSE
;
232 ObAppSettings
*settings
;
237 /* check if it has already been unmapped by the time we started mapping.
238 the grab does a sync so we don't have to here */
239 if (XCheckTypedWindowEvent(ob_display
, window
, DestroyNotify
, &e
) ||
240 XCheckTypedWindowEvent(ob_display
, window
, UnmapNotify
, &e
))
242 XPutBackEvent(ob_display
, &e
);
244 ob_debug("Trying to manage unmapped window. Aborting that.\n");
246 return; /* don't manage it */
249 /* make sure it isn't an override-redirect window */
250 if (!XGetWindowAttributes(ob_display
, window
, &attrib
) ||
251 attrib
.override_redirect
)
254 return; /* don't manage it */
257 /* is the window a docking app */
258 if ((wmhint
= XGetWMHints(ob_display
, window
))) {
259 if ((wmhint
->flags
& StateHint
) &&
260 wmhint
->initial_state
== WithdrawnState
)
262 dock_add(window
, wmhint
);
270 ob_debug("Managing window: %lx\n", window
);
272 /* choose the events we want to receive on the CLIENT window */
273 attrib_set
.event_mask
= CLIENT_EVENTMASK
;
274 attrib_set
.do_not_propagate_mask
= CLIENT_NOPROPAGATEMASK
;
275 XChangeWindowAttributes(ob_display
, window
,
276 CWEventMask
|CWDontPropagate
, &attrib_set
);
279 /* create the ObClient struct, and populate it from the hints on the
281 self
= g_new0(ObClient
, 1);
282 self
->obwin
.type
= Window_Client
;
283 self
->window
= window
;
285 /* non-zero defaults */
286 self
->wmstate
= WithdrawnState
; /* make sure it gets updated first time */
288 self
->desktop
= screen_num_desktops
; /* always an invalid value */
289 self
->user_time
= focus_client
? focus_client
->user_time
: CurrentTime
;
291 client_get_all(self
);
292 /* per-app settings override stuff, and return the settings for other
294 settings
= client_get_settings_state(self
);
295 /* the session should get the last say */
296 client_restore_session_state(self
);
298 client_calc_layer(self
);
301 Time t
= sn_app_started(self
->startup_id
, self
->class);
302 if (t
) self
->user_time
= t
;
305 /* update the focus lists, do this before the call to change_state or
306 it can end up in the list twice! */
307 focus_order_add_new(self
);
309 /* remove the client's border (and adjust re gravity) */
310 client_toggle_border(self
, FALSE
);
312 /* specify that if we exit, the window should not be destroyed and should
313 be reparented back to root automatically */
314 XChangeSaveSet(ob_display
, window
, SetModeInsert
);
316 /* create the decoration frame for the client window */
317 self
->frame
= frame_new(self
);
319 frame_grab_client(self
->frame
, self
);
321 /* do this after we have a frame.. it uses the frame to help determine the
322 WM_STATE to apply. */
323 client_change_state(self
);
327 stacking_add_nonintrusive(CLIENT_AS_WINDOW(self
));
329 /* focus the new window? */
330 if (ob_state() != OB_STATE_STARTING
&&
331 (!self
->session
|| self
->session
->focused
) &&
333 /* this means focus=true for window is same as config_focus_new=true */
334 ((config_focus_new
|| (settings
&& settings
->focus
== 1)) ||
335 client_search_focus_parent(self
)) &&
336 /* this checks for focus=false for the window */
337 (!settings
|| settings
->focus
!= 0) &&
338 /* note the check against Type_Normal/Dialog, not client_normal(self),
339 which would also include other types. in this case we want more
340 strict rules for focus */
341 (self
->type
== OB_CLIENT_TYPE_NORMAL
||
342 self
->type
== OB_CLIENT_TYPE_DIALOG
))
347 /* get the current position */
351 /* figure out placement for the window */
352 if (ob_state() == OB_STATE_RUNNING
) {
355 transient
= place_client(self
, &newx
, &newy
, settings
);
357 /* make sure the window is visible. */
358 client_find_onscreen(self
, &newx
, &newy
,
361 /* non-normal clients has less rules, and
362 windows that are being restored from a
363 session do also. we can assume you want
364 it back where you saved it. Clients saying
365 they placed themselves are subjected to
366 harder rules, ones that are placed by
367 place.c or by the user are allowed partially
368 off-screen and on xinerama divides (ie,
369 it is up to the placement routines to avoid
370 the xinerama divides) */
372 (((self
->positioned
& PPosition
) &&
373 !(self
->positioned
& USPosition
)) &&
374 client_normal(self
) &&
378 /* do this after the window is placed, so the premax/prefullscreen numbers
380 also, this moves the window to the position where it has been placed
382 ob_debug("placing window 0x%x at %d, %d with size %d x %d\n",
383 self
->window
, newx
, newy
, self
->area
.width
, self
->area
.height
);
385 ob_debug("session requested %d %d\n",
386 self
->session
->x
, self
->session
->y
);
388 client_apply_startup_state(self
, newx
, newy
);
390 mouse_grab_for_client(self
, TRUE
);
393 guint32 last_time
= focus_client
?
394 focus_client
->user_time
: CurrentTime
;
396 /* This is focus stealing prevention */
397 ob_debug_type(OB_DEBUG_FOCUS
,
398 "Want to focus new window 0x%x with time %u "
400 self
->window
, self
->user_time
, last_time
);
402 /* if it's on another desktop */
403 if (!(self
->desktop
== screen_desktop
|| self
->desktop
== DESKTOP_ALL
)
404 && /* the timestamp is from before you changed desktops */
405 self
->user_time
&& screen_desktop_user_time
&&
406 !event_time_after(self
->user_time
, screen_desktop_user_time
))
409 ob_debug_type(OB_DEBUG_FOCUS
,
410 "Not focusing the window because its on another "
413 /* If something is focused, and it's not our parent... */
414 else if (focus_client
&& client_search_focus_parent(self
) == NULL
)
416 /* If time stamp is old, don't steal focus */
417 if (self
->user_time
&& last_time
&&
418 !event_time_after(self
->user_time
, last_time
))
421 ob_debug_type(OB_DEBUG_FOCUS
,
422 "Not focusing the window because the time is "
425 /* Don't steal focus from globally active clients.
426 I stole this idea from KWin. It seems nice.
428 if (!(focus_client
->can_focus
|| focus_client
->focus_notify
)) {
430 ob_debug_type(OB_DEBUG_FOCUS
,
431 "Not focusing the window because a globally "
432 "active client has focus\n");
437 ob_debug_type(OB_DEBUG_FOCUS
,
438 "Focus stealing prevention activated for %s with "
439 "time %u (last time %u)\n",
440 self
->title
, self
->user_time
, last_time
);
441 /* if the client isn't focused, then hilite it so the user
443 client_hilite(self
, TRUE
);
447 /* This may look rather odd. Well it's because new windows are added
448 to the stacking order non-intrusively. If we're not going to focus
449 the new window or hilite it, then we raise it to the top. This will
450 take affect for things that don't get focused like splash screens.
451 Also if you don't have focus_new enabled, then it's going to get
452 raised to the top. Legacy begets legacy I guess?
454 if (!client_restore_session_stacking(self
))
458 /* this has to happen before we try focus the window, but we want it to
459 happen after the client's stacking has been determined or it looks bad
463 /* use client_focus instead of client_activate cuz client_activate does
464 stuff like switch desktops etc and I'm not interested in all that when
465 a window maps since its not based on an action from the user like
466 clicking a window to activate it. so keep the new window out of the way
469 gboolean stacked
= client_restore_session_stacking(self
);
470 client_present(self
, FALSE
, !stacked
);
473 /* add to client list/map */
474 client_list
= g_list_append(client_list
, self
);
475 g_hash_table_insert(window_map
, &self
->window
, self
);
477 /* this has to happen after we're in the client_list */
478 if (STRUT_EXISTS(self
->strut
))
479 screen_update_areas();
481 /* update the list hints */
484 ob_debug("Managed window 0x%lx (%s)\n", window
, self
->class);
487 void client_unmanage_all()
489 while (client_list
!= NULL
)
490 client_unmanage(client_list
->data
);
493 void client_unmanage(ObClient
*self
)
498 ob_debug("Unmanaging window: %lx (%s) (%s)\n", self
->window
, self
->class,
499 self
->title
? self
->title
: "");
501 g_assert(self
!= NULL
);
503 /* we dont want events no more. do this before hiding the frame so we
504 don't generate more events */
505 XSelectInput(ob_display
, self
->window
, NoEventMask
);
507 frame_hide(self
->frame
);
508 /* flush to send the hide to the server quickly */
511 /* ignore enter events from the unmap so it doesnt mess with the focus */
512 event_ignore_queued_enters();
514 mouse_grab_for_client(self
, FALSE
);
516 /* remove the window from our save set */
517 XChangeSaveSet(ob_display
, self
->window
, SetModeDelete
);
519 /* update the focus lists */
520 focus_order_remove(self
);
521 if (client_focused(self
)) {
522 /* don't leave an invalid focus_client */
526 client_list
= g_list_remove(client_list
, self
);
527 stacking_remove(self
);
528 g_hash_table_remove(window_map
, &self
->window
);
530 /* once the client is out of the list, update the struts to remove its
532 if (STRUT_EXISTS(self
->strut
))
533 screen_update_areas();
535 for (it
= client_destructors
; it
; it
= g_slist_next(it
)) {
536 Destructor
*d
= it
->data
;
537 d
->func(self
, d
->data
);
540 /* tell our parent(s) that we're gone */
541 if (self
->transient_for
== OB_TRAN_GROUP
) { /* transient of group */
542 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
))
543 if (it
->data
!= self
)
544 ((ObClient
*)it
->data
)->transients
=
545 g_slist_remove(((ObClient
*)it
->data
)->transients
, self
);
546 } else if (self
->transient_for
) { /* transient of window */
547 self
->transient_for
->transients
=
548 g_slist_remove(self
->transient_for
->transients
, self
);
551 /* tell our transients that we're gone */
552 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
553 if (((ObClient
*)it
->data
)->transient_for
!= OB_TRAN_GROUP
) {
554 ((ObClient
*)it
->data
)->transient_for
= NULL
;
555 client_calc_layer(it
->data
);
559 /* remove from its group */
561 group_remove(self
->group
, self
);
565 /* restore the window's original geometry so it is not lost */
569 if (self
->fullscreen
)
570 a
= self
->pre_fullscreen_area
;
571 else if (self
->max_horz
|| self
->max_vert
) {
572 if (self
->max_horz
) {
573 a
.x
= self
->pre_max_area
.x
;
574 a
.width
= self
->pre_max_area
.width
;
576 if (self
->max_vert
) {
577 a
.y
= self
->pre_max_area
.y
;
578 a
.height
= self
->pre_max_area
.height
;
582 /* give the client its border back */
583 client_toggle_border(self
, TRUE
);
585 self
->fullscreen
= self
->max_horz
= self
->max_vert
= FALSE
;
586 self
->decorations
= 0; /* unmanaged windows have no decor */
588 client_move_resize(self
, a
.x
, a
.y
, a
.width
, a
.height
);
591 /* reparent the window out of the frame, and free the frame */
592 frame_release_client(self
->frame
, self
);
595 if (ob_state() != OB_STATE_EXITING
) {
596 /* these values should not be persisted across a window
598 PROP_ERASE(self
->window
, net_wm_desktop
);
599 PROP_ERASE(self
->window
, net_wm_state
);
600 PROP_ERASE(self
->window
, wm_state
);
602 /* if we're left in an unmapped state, the client wont be mapped. this
603 is bad, since we will no longer be managing the window on restart */
604 XMapWindow(ob_display
, self
->window
);
607 ob_debug("Unmanaged window 0x%lx\n", self
->window
);
609 /* free all data allocated in the client struct */
610 g_slist_free(self
->transients
);
611 for (j
= 0; j
< self
->nicons
; ++j
)
612 g_free(self
->icons
[j
].data
);
613 if (self
->nicons
> 0)
615 g_free(self
->wm_command
);
617 g_free(self
->icon_title
);
621 g_free(self
->client_machine
);
622 g_free(self
->sm_client_id
);
625 /* update the list hints */
629 static ObAppSettings
*client_get_settings_state(ObClient
*self
)
631 ObAppSettings
*settings
= NULL
;
634 for (it
= config_per_app_settings
; it
; it
= g_slist_next(it
)) {
635 ObAppSettings
*app
= it
->data
;
637 if ((app
->name
&& !app
->class && !strcmp(app
->name
, self
->name
))
638 || (app
->class && !app
->name
&& !strcmp(app
->class, self
->class))
639 || (app
->class && app
->name
&& !strcmp(app
->class, self
->class)
640 && !strcmp(app
->name
, self
->name
)))
642 /* Match if no role was specified in the per app setting, or if the
643 * string matches the beginning of the role, since apps like to set
644 * the role to things like browser-window-23c4b2f */
646 || !strncmp(app
->role
, self
->role
, strlen(app
->role
)))
648 ob_debug("Window matching: %s\n", app
->name
);
657 if (settings
->shade
!= -1)
658 self
->shaded
= !!settings
->shade
;
659 if (settings
->decor
!= -1)
660 self
->undecorated
= !settings
->decor
;
661 if (settings
->iconic
!= -1)
662 self
->iconic
= !!settings
->iconic
;
663 if (settings
->skip_pager
!= -1)
664 self
->skip_pager
= !!settings
->skip_pager
;
665 if (settings
->skip_taskbar
!= -1)
666 self
->skip_taskbar
= !!settings
->skip_taskbar
;
668 if (settings
->max_vert
!= -1)
669 self
->max_vert
= !!settings
->max_vert
;
670 if (settings
->max_horz
!= -1)
671 self
->max_horz
= !!settings
->max_horz
;
673 if (settings
->fullscreen
!= -1)
674 self
->fullscreen
= !!settings
->fullscreen
;
676 if (settings
->desktop
< screen_num_desktops
677 || settings
->desktop
== DESKTOP_ALL
)
678 self
->desktop
= settings
->desktop
;
680 if (settings
->layer
== -1) {
684 else if (settings
->layer
== 0) {
688 else if (settings
->layer
== 1) {
696 static void client_restore_session_state(ObClient
*self
)
700 ob_debug_type(OB_DEBUG_SM
,
701 "Restore session for client %s\n", self
->title
);
703 if (!(it
= session_state_find(self
))) {
704 ob_debug_type(OB_DEBUG_SM
,
705 "Session data not found for client %s\n", self
->title
);
709 self
->session
= it
->data
;
711 ob_debug_type(OB_DEBUG_SM
, "Session data loaded for client %s\n",
714 RECT_SET_POINT(self
->area
, self
->session
->x
, self
->session
->y
);
715 self
->positioned
= USPosition
;
716 if (self
->session
->w
> 0)
717 self
->area
.width
= self
->session
->w
;
718 if (self
->session
->h
> 0)
719 self
->area
.height
= self
->session
->h
;
720 XResizeWindow(ob_display
, self
->window
,
721 self
->area
.width
, self
->area
.height
);
723 self
->desktop
= (self
->session
->desktop
== DESKTOP_ALL
?
724 self
->session
->desktop
:
725 MIN(screen_num_desktops
- 1, self
->session
->desktop
));
726 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, self
->desktop
);
728 self
->shaded
= self
->session
->shaded
;
729 self
->iconic
= self
->session
->iconic
;
730 self
->skip_pager
= self
->session
->skip_pager
;
731 self
->skip_taskbar
= self
->session
->skip_taskbar
;
732 self
->fullscreen
= self
->session
->fullscreen
;
733 self
->above
= self
->session
->above
;
734 self
->below
= self
->session
->below
;
735 self
->max_horz
= self
->session
->max_horz
;
736 self
->max_vert
= self
->session
->max_vert
;
737 self
->undecorated
= self
->session
->undecorated
;
740 static gboolean
client_restore_session_stacking(ObClient
*self
)
744 if (!self
->session
) return FALSE
;
746 mypos
= g_list_find(session_saved_state
, self
->session
);
747 if (!mypos
) return FALSE
;
749 /* start above me and look for the first client */
750 for (it
= g_list_previous(mypos
); it
; it
= g_list_previous(it
)) {
753 for (cit
= client_list
; cit
; cit
= g_list_next(cit
)) {
754 ObClient
*c
= cit
->data
;
755 /* found a client that was in the session, so go below it */
756 if (c
->session
== it
->data
) {
757 stacking_below(CLIENT_AS_WINDOW(self
),
758 CLIENT_AS_WINDOW(cit
->data
));
766 void client_move_onscreen(ObClient
*self
, gboolean rude
)
768 gint x
= self
->area
.x
;
769 gint y
= self
->area
.y
;
770 if (client_find_onscreen(self
, &x
, &y
,
772 self
->area
.height
, rude
)) {
773 client_move(self
, x
, y
);
777 gboolean
client_find_onscreen(ObClient
*self
, gint
*x
, gint
*y
, gint w
, gint h
,
781 gint ox
= *x
, oy
= *y
;
782 gboolean rudel
= rude
, ruder
= rude
, rudet
= rude
, rudeb
= rude
;
785 all_a
= screen_area(self
->desktop
);
786 mon_a
= screen_area_monitor(self
->desktop
, client_monitor(self
));
788 /* get where the frame would be */
789 frame_client_gravity(self
->frame
, x
, y
, w
, h
);
791 /* get the requested size of the window with decorations */
792 fw
= self
->frame
->size
.left
+ w
+ self
->frame
->size
.right
;
793 fh
= self
->frame
->size
.top
+ h
+ self
->frame
->size
.bottom
;
795 /* This makes sure windows aren't entirely outside of the screen so you
796 can't see them at all.
797 It makes sure 10% of the window is on the screen at least. At don't let
798 it move itself off the top of the screen, which would hide the titlebar
799 on you. (The user can still do this if they want too, it's only limiting
802 XXX watch for xinerama dead areas...
804 if (client_normal(self
)) {
805 if (!self
->strut
.right
&& *x
+ fw
/10 >= all_a
->x
+ all_a
->width
- 1)
806 *x
= all_a
->x
+ all_a
->width
- fw
/10;
807 if (!self
->strut
.bottom
&& *y
+ fh
/10 >= all_a
->y
+ all_a
->height
- 1)
808 *y
= all_a
->y
+ all_a
->height
- fh
/10;
809 if (!self
->strut
.left
&& *x
+ fw
*9/10 - 1 < all_a
->x
)
810 *x
= all_a
->x
- fw
*9/10;
811 if (!self
->strut
.top
&& *y
+ fh
*9/10 - 1 < all_a
->y
)
812 *y
= all_a
->y
- fw
*9/10;
815 /* If rudeness wasn't requested, then figure out of the client is currently
816 entirely on the screen. If it is, and the position isn't changing by
817 request, and it is enlarging, then be rude even though it wasn't
820 Point oldtl
, oldtr
, oldbl
, oldbr
;
821 Point newtl
, newtr
, newbl
, newbr
;
822 gboolean stationary_l
, stationary_r
, stationary_t
, stationary_b
;
824 POINT_SET(oldtl
, self
->frame
->area
.x
, self
->frame
->area
.y
);
825 POINT_SET(oldbr
, self
->frame
->area
.x
+ self
->frame
->area
.width
- 1,
826 self
->frame
->area
.y
+ self
->frame
->area
.height
- 1);
827 POINT_SET(oldtr
, oldbr
.x
, oldtl
.y
);
828 POINT_SET(oldbl
, oldtl
.x
, oldbr
.y
);
830 POINT_SET(newtl
, *x
, *y
);
831 POINT_SET(newbr
, *x
+ fw
- 1, *y
+ fh
- 1);
832 POINT_SET(newtr
, newbr
.x
, newtl
.y
);
833 POINT_SET(newbl
, newtl
.x
, newbr
.y
);
835 /* is it moving or just resizing from some corner? */
836 stationary_l
= oldtl
.x
== oldtl
.x
;
837 stationary_r
= oldtr
.x
== oldtr
.x
;
838 stationary_t
= oldtl
.y
== oldtl
.y
;
839 stationary_b
= oldbl
.y
== oldbl
.y
;
841 /* if left edge is growing and didnt move right edge */
842 if (stationary_r
&& newtl
.x
< oldtl
.x
)
844 /* if right edge is growing and didnt move left edge */
845 if (stationary_l
&& newtr
.x
> oldtr
.x
)
847 /* if top edge is growing and didnt move bottom edge */
848 if (stationary_b
&& newtl
.y
< oldtl
.y
)
850 /* if bottom edge is growing and didnt move top edge */
851 if (stationary_t
&& newbl
.y
> oldbl
.y
)
855 /* This here doesn't let windows even a pixel outside the struts/screen.
856 * When called from client_manage, programs placing themselves are
857 * forced completely onscreen, while things like
858 * xterm -geometry resolution-width/2 will work fine. Trying to
859 * place it completely offscreen will be handled in the above code.
860 * Sorry for this confused comment, i am tired. */
861 if (fw
<= mon_a
->width
) {
862 if (rudel
&& !self
->strut
.left
&& *x
< mon_a
->x
) *x
= mon_a
->x
;
863 if (ruder
&& !self
->strut
.right
&& *x
+ fw
> mon_a
->x
+ mon_a
->width
)
864 *x
= mon_a
->x
+ mon_a
->width
- fw
;
866 if (fh
<= mon_a
->height
) {
867 if (rudet
&& !self
->strut
.top
&& *y
< mon_a
->y
) *y
= mon_a
->y
;
868 if (rudeb
&& !self
->strut
.bottom
&& *y
+ fh
> mon_a
->y
+ mon_a
->height
)
869 *y
= mon_a
->y
+ mon_a
->height
- fh
;
872 /* get where the client should be */
873 frame_frame_gravity(self
->frame
, x
, y
, w
, h
);
875 return ox
!= *x
|| oy
!= *y
;
878 static void client_toggle_border(ObClient
*self
, gboolean show
)
880 /* adjust our idea of where the client is, based on its border. When the
881 border is removed, the client should now be considered to be in a
883 when re-adding the border to the client, the same operation needs to be
885 gint oldx
= self
->area
.x
, oldy
= self
->area
.y
;
886 gint x
= oldx
, y
= oldy
;
887 switch(self
->gravity
) {
889 case NorthWestGravity
:
891 case SouthWestGravity
:
893 case NorthEastGravity
:
895 case SouthEastGravity
:
896 if (show
) x
-= self
->border_width
* 2;
897 else x
+= self
->border_width
* 2;
904 if (show
) x
-= self
->border_width
;
905 else x
+= self
->border_width
;
908 switch(self
->gravity
) {
910 case NorthWestGravity
:
912 case NorthEastGravity
:
914 case SouthWestGravity
:
916 case SouthEastGravity
:
917 if (show
) y
-= self
->border_width
* 2;
918 else y
+= self
->border_width
* 2;
925 if (show
) y
-= self
->border_width
;
926 else y
+= self
->border_width
;
933 XSetWindowBorderWidth(ob_display
, self
->window
, self
->border_width
);
935 /* set border_width to 0 because there is no border to add into
936 calculations anymore */
937 self
->border_width
= 0;
939 XSetWindowBorderWidth(ob_display
, self
->window
, 0);
943 static void client_get_all(ObClient
*self
)
945 client_get_area(self
);
946 client_get_mwm_hints(self
);
948 /* The transient-ness of a window is used to pick a type, but the type can
949 also affect transiency.
951 Dialogs are always made transients for their group if they have one.
953 I also have made non-application type windows be transients for their
954 group (eg utility windows).
956 client_get_transientness(self
);
957 client_get_type(self
);/* this can change the mwmhints for special cases */
958 client_get_state(self
);
960 client_update_wmhints(self
);
961 /* this may have already been called from client_update_wmhints */
962 if (self
->transient_for
== NULL
)
963 client_update_transient_for(self
);
964 client_get_startup_id(self
);
965 client_get_desktop(self
);/* uses transient data/group/startup id if a
966 desktop is not specified */
967 client_get_shaped(self
);
969 client_get_layer(self
); /* if layer hasn't been specified, get it from
970 other sources if possible */
973 /* a couple type-based defaults for new windows */
975 /* this makes sure that these windows appear on all desktops */
976 if (self
->type
== OB_CLIENT_TYPE_DESKTOP
)
977 self
->desktop
= DESKTOP_ALL
;
980 client_update_protocols(self
);
982 client_get_gravity(self
); /* get the attribute gravity */
983 client_update_normal_hints(self
); /* this may override the attribute
986 /* got the type, the mwmhints, the protocols, and the normal hints
987 (min/max sizes), so we're ready to set up the decorations/functions */
988 client_setup_decor_and_functions(self
);
991 client_update_sync_request_counter(self
);
993 client_get_client_machine(self
);
994 client_get_colormap(self
);
995 client_update_title(self
);
996 client_update_class(self
);
997 client_update_sm_client_id(self
);
998 client_update_command(self
);
999 client_update_strut(self
);
1000 client_update_icons(self
);
1001 client_update_user_time(self
);
1002 client_update_icon_geometry(self
);
1005 static void client_get_startup_id(ObClient
*self
)
1007 if (!(PROP_GETS(self
->window
, net_startup_id
, utf8
, &self
->startup_id
)))
1009 PROP_GETS(self
->group
->leader
,
1010 net_startup_id
, utf8
, &self
->startup_id
);
1013 static void client_get_area(ObClient
*self
)
1015 XWindowAttributes wattrib
;
1018 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
1019 g_assert(ret
!= BadWindow
);
1021 RECT_SET(self
->area
, wattrib
.x
, wattrib
.y
, wattrib
.width
, wattrib
.height
);
1022 POINT_SET(self
->root_pos
, wattrib
.x
, wattrib
.y
);
1023 self
->border_width
= wattrib
.border_width
;
1025 ob_debug("client area: %d %d %d %d\n", wattrib
.x
, wattrib
.y
,
1026 wattrib
.width
, wattrib
.height
);
1029 static void client_get_desktop(ObClient
*self
)
1031 guint32 d
= screen_num_desktops
; /* an always-invalid value */
1033 if (PROP_GET32(self
->window
, net_wm_desktop
, cardinal
, &d
)) {
1034 if (d
>= screen_num_desktops
&& d
!= DESKTOP_ALL
)
1035 self
->desktop
= screen_num_desktops
- 1;
1039 gboolean trdesk
= FALSE
;
1041 if (self
->transient_for
) {
1042 if (self
->transient_for
!= OB_TRAN_GROUP
) {
1043 self
->desktop
= self
->transient_for
->desktop
;
1048 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
))
1049 if (it
->data
!= self
&&
1050 !((ObClient
*)it
->data
)->transient_for
) {
1051 self
->desktop
= ((ObClient
*)it
->data
)->desktop
;
1058 /* try get from the startup-notification protocol */
1059 if (sn_get_desktop(self
->startup_id
, &self
->desktop
)) {
1060 if (self
->desktop
>= screen_num_desktops
&&
1061 self
->desktop
!= DESKTOP_ALL
)
1062 self
->desktop
= screen_num_desktops
- 1;
1064 /* defaults to the current desktop */
1065 self
->desktop
= screen_desktop
;
1070 static void client_get_layer(ObClient
*self
)
1072 if (!(self
->above
|| self
->below
)) {
1074 /* apply stuff from the group */
1078 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
1079 ObClient
*c
= it
->data
;
1080 if (c
!= self
&& !client_search_transient(self
, c
) &&
1081 client_normal(self
) && client_normal(c
))
1084 (c
->above
? 1 : (c
->below
? -1 : 0)));
1098 g_assert_not_reached();
1105 static void client_get_state(ObClient
*self
)
1110 if (PROP_GETA32(self
->window
, net_wm_state
, atom
, &state
, &num
)) {
1112 for (i
= 0; i
< num
; ++i
) {
1113 if (state
[i
] == prop_atoms
.net_wm_state_modal
)
1115 else if (state
[i
] == prop_atoms
.net_wm_state_shaded
)
1116 self
->shaded
= TRUE
;
1117 else if (state
[i
] == prop_atoms
.net_wm_state_hidden
)
1118 self
->iconic
= TRUE
;
1119 else if (state
[i
] == prop_atoms
.net_wm_state_skip_taskbar
)
1120 self
->skip_taskbar
= TRUE
;
1121 else if (state
[i
] == prop_atoms
.net_wm_state_skip_pager
)
1122 self
->skip_pager
= TRUE
;
1123 else if (state
[i
] == prop_atoms
.net_wm_state_fullscreen
)
1124 self
->fullscreen
= TRUE
;
1125 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_vert
)
1126 self
->max_vert
= TRUE
;
1127 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_horz
)
1128 self
->max_horz
= TRUE
;
1129 else if (state
[i
] == prop_atoms
.net_wm_state_above
)
1131 else if (state
[i
] == prop_atoms
.net_wm_state_below
)
1133 else if (state
[i
] == prop_atoms
.net_wm_state_demands_attention
)
1134 self
->demands_attention
= TRUE
;
1135 else if (state
[i
] == prop_atoms
.openbox_wm_state_undecorated
)
1136 self
->undecorated
= TRUE
;
1143 static void client_get_shaped(ObClient
*self
)
1145 self
->shaped
= FALSE
;
1147 if (extensions_shape
) {
1152 XShapeSelectInput(ob_display
, self
->window
, ShapeNotifyMask
);
1154 XShapeQueryExtents(ob_display
, self
->window
, &s
, &foo
,
1155 &foo
, &ufoo
, &ufoo
, &foo
, &foo
, &foo
, &ufoo
,
1157 self
->shaped
= (s
!= 0);
1162 void client_get_transientness(ObClient
*self
)
1165 if (XGetTransientForHint(ob_display
, self
->window
, &t
))
1166 self
->transient
= TRUE
;
1169 void client_update_transient_for(ObClient
*self
)
1172 ObClient
*target
= NULL
;
1174 if (XGetTransientForHint(ob_display
, self
->window
, &t
)) {
1175 self
->transient
= TRUE
;
1176 if (t
!= self
->window
) { /* cant be transient to itself! */
1177 target
= g_hash_table_lookup(window_map
, &t
);
1178 /* if this happens then we need to check for it*/
1179 g_assert(target
!= self
);
1180 if (target
&& !WINDOW_IS_CLIENT(target
)) {
1181 /* this can happen when a dialog is a child of
1182 a dockapp, for example */
1186 /* THIS IS SO ANNOYING ! ! ! ! Let me explain.... have a seat..
1188 Setting the transient_for to Root is actually illegal, however
1189 applications from time have done this to specify transient for
1192 Now you can do that by being a TYPE_DIALOG and not setting
1193 the transient_for hint at all on your window. But people still
1194 use Root, and Kwin is very strange in this regard.
1196 KWin 3.0 will not consider windows with transient_for set to
1197 Root as transient for their group *UNLESS* they are also modal.
1198 In that case, it will make them transient for the group. This
1199 leads to all sorts of weird behavior from KDE apps which are
1200 only tested in KWin. I'd like to follow their behavior just to
1201 make this work right with KDE stuff, but that seems wrong.
1203 if (!target
&& self
->group
) {
1204 /* not transient to a client, see if it is transient for a
1206 if (t
== RootWindow(ob_display
, ob_screen
)) {
1207 /* window is a transient for its group! */
1208 target
= OB_TRAN_GROUP
;
1212 } else if (self
->type
== OB_CLIENT_TYPE_DIALOG
||
1213 self
->type
== OB_CLIENT_TYPE_TOOLBAR
||
1214 self
->type
== OB_CLIENT_TYPE_MENU
||
1215 self
->type
== OB_CLIENT_TYPE_UTILITY
)
1217 self
->transient
= TRUE
;
1219 target
= OB_TRAN_GROUP
;
1221 self
->transient
= FALSE
;
1223 client_update_transient_tree(self
, self
->group
, self
->group
,
1224 self
->transient_for
, target
);
1225 self
->transient_for
= target
;
1229 static void client_update_transient_tree(ObClient
*self
,
1230 ObGroup
*oldgroup
, ObGroup
*newgroup
,
1231 ObClient
* oldparent
,
1232 ObClient
*newparent
)
1237 /* No change has occured */
1238 if (oldgroup
== newgroup
&& oldparent
== newparent
) return;
1240 /** Remove the client from the transient tree wherever it has changed **/
1242 /* If the window is becoming a direct transient for a window in its group
1243 then that window can't be a child of this window anymore */
1244 if (oldparent
!= newparent
&&
1245 newparent
!= NULL
&& newparent
!= OB_TRAN_GROUP
&&
1246 newparent
->transient_for
== OB_TRAN_GROUP
&&
1247 newgroup
!= NULL
&& newgroup
== oldgroup
)
1249 self
->transients
= g_slist_remove(self
->transients
, newparent
);
1253 /* If the group changed then we need to remove any old group transient
1254 windows from our children. But if we're transient for the group, then
1255 other group transients are not our children. */
1256 if (oldgroup
!= newgroup
&& oldgroup
!= NULL
&&
1257 oldparent
!= OB_TRAN_GROUP
)
1259 for (it
= self
->transients
; it
; it
= next
) {
1260 next
= g_slist_next(it
);
1262 if (c
->group
== oldgroup
)
1263 self
->transients
= g_slist_delete_link(self
->transients
, it
);
1267 /* If we used to be transient for a group and now we are not, or we're
1268 transient for a new group, then we need to remove ourselves from all
1270 if (oldparent
== OB_TRAN_GROUP
&& (oldgroup
!= newgroup
||
1271 oldparent
!= newparent
))
1273 for (it
= oldgroup
->members
; it
; it
= g_slist_next(it
)) {
1275 if (c
!= self
&& (!c
->transient_for
||
1276 c
->transient_for
!= OB_TRAN_GROUP
))
1277 c
->transients
= g_slist_remove(c
->transients
, self
);
1280 /* If we used to be transient for a single window and we are no longer
1281 transient for it, then we need to remove ourself from its children */
1282 else if (oldparent
!= NULL
&& oldparent
!= OB_TRAN_GROUP
&&
1283 oldparent
!= newparent
)
1284 oldparent
->transients
= g_slist_remove(oldparent
->transients
, self
);
1287 /** Re-add the client to the transient tree wherever it has changed **/
1289 /* If we're now transient for a group and we weren't transient for it
1290 before then we need to add ourselves to all our new parents */
1291 if (newparent
== OB_TRAN_GROUP
&& (oldgroup
!= newgroup
||
1292 oldparent
!= newparent
))
1294 for (it
= oldgroup
->members
; it
; it
= g_slist_next(it
)) {
1296 if (c
!= self
&& (!c
->transient_for
||
1297 c
->transient_for
!= OB_TRAN_GROUP
))
1298 c
->transients
= g_slist_prepend(c
->transients
, self
);
1301 /* If we are now transient for a single window which we weren't before,
1302 we need to add ourselves to its children
1304 WARNING: Cyclical transient ness is possible if two windows are
1305 transient for eachother.
1307 else if (newparent
!= NULL
&& newparent
!= OB_TRAN_GROUP
&&
1308 newparent
!= oldparent
&&
1309 /* don't make ourself its child if it is already our child */
1310 !client_is_direct_child(self
, newparent
))
1311 newparent
->transients
= g_slist_prepend(newparent
->transients
, self
);
1313 /* If the group changed then we need to add any new group transient
1314 windows to our children. But if we're transient for the group, then
1315 other group transients are not our children.
1317 WARNING: Cyclical transient-ness is possible. For e.g. if:
1318 A is transient for the group
1319 B is a member of the group and transient for A
1321 if (oldgroup
!= newgroup
&& newgroup
!= NULL
&&
1322 newparent
!= OB_TRAN_GROUP
)
1324 for (it
= newgroup
->members
; it
; it
= g_slist_next(it
)) {
1326 if (c
!= self
&& c
->transient_for
== OB_TRAN_GROUP
&&
1327 /* Don't make it our child if it is already our parent */
1328 !client_is_direct_child(c
, self
))
1330 self
->transients
= g_slist_prepend(self
->transients
, c
);
1336 static void client_get_mwm_hints(ObClient
*self
)
1341 self
->mwmhints
.flags
= 0; /* default to none */
1343 if (PROP_GETA32(self
->window
, motif_wm_hints
, motif_wm_hints
,
1345 if (num
>= OB_MWM_ELEMENTS
) {
1346 self
->mwmhints
.flags
= hints
[0];
1347 self
->mwmhints
.functions
= hints
[1];
1348 self
->mwmhints
.decorations
= hints
[2];
1354 void client_get_type(ObClient
*self
)
1361 if (PROP_GETA32(self
->window
, net_wm_window_type
, atom
, &val
, &num
)) {
1362 /* use the first value that we know about in the array */
1363 for (i
= 0; i
< num
; ++i
) {
1364 if (val
[i
] == prop_atoms
.net_wm_window_type_desktop
)
1365 self
->type
= OB_CLIENT_TYPE_DESKTOP
;
1366 else if (val
[i
] == prop_atoms
.net_wm_window_type_dock
)
1367 self
->type
= OB_CLIENT_TYPE_DOCK
;
1368 else if (val
[i
] == prop_atoms
.net_wm_window_type_toolbar
)
1369 self
->type
= OB_CLIENT_TYPE_TOOLBAR
;
1370 else if (val
[i
] == prop_atoms
.net_wm_window_type_menu
)
1371 self
->type
= OB_CLIENT_TYPE_MENU
;
1372 else if (val
[i
] == prop_atoms
.net_wm_window_type_utility
)
1373 self
->type
= OB_CLIENT_TYPE_UTILITY
;
1374 else if (val
[i
] == prop_atoms
.net_wm_window_type_splash
)
1375 self
->type
= OB_CLIENT_TYPE_SPLASH
;
1376 else if (val
[i
] == prop_atoms
.net_wm_window_type_dialog
)
1377 self
->type
= OB_CLIENT_TYPE_DIALOG
;
1378 else if (val
[i
] == prop_atoms
.net_wm_window_type_normal
)
1379 self
->type
= OB_CLIENT_TYPE_NORMAL
;
1380 else if (val
[i
] == prop_atoms
.kde_net_wm_window_type_override
) {
1381 /* prevent this window from getting any decor or
1383 self
->mwmhints
.flags
&= (OB_MWM_FLAG_FUNCTIONS
|
1384 OB_MWM_FLAG_DECORATIONS
);
1385 self
->mwmhints
.decorations
= 0;
1386 self
->mwmhints
.functions
= 0;
1388 if (self
->type
!= (ObClientType
) -1)
1389 break; /* grab the first legit type */
1394 if (self
->type
== (ObClientType
) -1) {
1395 /*the window type hint was not set, which means we either classify
1396 ourself as a normal window or a dialog, depending on if we are a
1398 if (self
->transient
)
1399 self
->type
= OB_CLIENT_TYPE_DIALOG
;
1401 self
->type
= OB_CLIENT_TYPE_NORMAL
;
1405 void client_update_protocols(ObClient
*self
)
1408 guint num_return
, i
;
1410 self
->focus_notify
= FALSE
;
1411 self
->delete_window
= FALSE
;
1413 if (PROP_GETA32(self
->window
, wm_protocols
, atom
, &proto
, &num_return
)) {
1414 for (i
= 0; i
< num_return
; ++i
) {
1415 if (proto
[i
] == prop_atoms
.wm_delete_window
)
1416 /* this means we can request the window to close */
1417 self
->delete_window
= TRUE
;
1418 else if (proto
[i
] == prop_atoms
.wm_take_focus
)
1419 /* if this protocol is requested, then the window will be
1420 notified whenever we want it to receive focus */
1421 self
->focus_notify
= TRUE
;
1423 else if (proto
[i
] == prop_atoms
.net_wm_sync_request
)
1424 /* if this protocol is requested, then resizing the
1425 window will be synchronized between the frame and the
1427 self
->sync_request
= TRUE
;
1435 void client_update_sync_request_counter(ObClient
*self
)
1439 if (PROP_GET32(self
->window
, net_wm_sync_request_counter
, cardinal
, &i
)) {
1440 self
->sync_counter
= i
;
1442 self
->sync_counter
= None
;
1446 static void client_get_gravity(ObClient
*self
)
1448 XWindowAttributes wattrib
;
1451 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
1452 g_assert(ret
!= BadWindow
);
1453 self
->gravity
= wattrib
.win_gravity
;
1456 void client_get_colormap(ObClient
*self
)
1458 XWindowAttributes wa
;
1460 if (XGetWindowAttributes(ob_display
, self
->window
, &wa
))
1461 client_update_colormap(self
, wa
.colormap
);
1464 void client_update_colormap(ObClient
*self
, Colormap colormap
)
1466 self
->colormap
= colormap
;
1469 void client_update_normal_hints(ObClient
*self
)
1473 gint oldgravity
= self
->gravity
;
1476 self
->min_ratio
= 0.0f
;
1477 self
->max_ratio
= 0.0f
;
1478 SIZE_SET(self
->size_inc
, 1, 1);
1479 SIZE_SET(self
->base_size
, 0, 0);
1480 SIZE_SET(self
->min_size
, 0, 0);
1481 SIZE_SET(self
->max_size
, G_MAXINT
, G_MAXINT
);
1483 /* get the hints from the window */
1484 if (XGetWMNormalHints(ob_display
, self
->window
, &size
, &ret
)) {
1485 /* normal windows can't request placement! har har
1486 if (!client_normal(self))
1488 self
->positioned
= (size
.flags
& (PPosition
|USPosition
));
1490 if (size
.flags
& PWinGravity
) {
1491 self
->gravity
= size
.win_gravity
;
1493 /* if the client has a frame, i.e. has already been mapped and
1494 is changing its gravity */
1495 if (self
->frame
&& self
->gravity
!= oldgravity
) {
1496 /* move our idea of the client's position based on its new
1498 client_convert_gravity(self
, oldgravity
,
1499 &self
->area
.x
, &self
->area
.y
,
1500 self
->area
.width
, self
->area
.height
);
1504 if (size
.flags
& PAspect
) {
1505 if (size
.min_aspect
.y
)
1507 (gfloat
) size
.min_aspect
.x
/ size
.min_aspect
.y
;
1508 if (size
.max_aspect
.y
)
1510 (gfloat
) size
.max_aspect
.x
/ size
.max_aspect
.y
;
1513 if (size
.flags
& PMinSize
)
1514 SIZE_SET(self
->min_size
, size
.min_width
, size
.min_height
);
1516 if (size
.flags
& PMaxSize
)
1517 SIZE_SET(self
->max_size
, size
.max_width
, size
.max_height
);
1519 if (size
.flags
& PBaseSize
)
1520 SIZE_SET(self
->base_size
, size
.base_width
, size
.base_height
);
1522 if (size
.flags
& PResizeInc
&& size
.width_inc
&& size
.height_inc
)
1523 SIZE_SET(self
->size_inc
, size
.width_inc
, size
.height_inc
);
1527 void client_setup_decor_and_functions(ObClient
*self
)
1529 /* start with everything (cept fullscreen) */
1531 (OB_FRAME_DECOR_TITLEBAR
|
1532 OB_FRAME_DECOR_HANDLE
|
1533 OB_FRAME_DECOR_GRIPS
|
1534 OB_FRAME_DECOR_BORDER
|
1535 OB_FRAME_DECOR_ICON
|
1536 OB_FRAME_DECOR_ALLDESKTOPS
|
1537 OB_FRAME_DECOR_ICONIFY
|
1538 OB_FRAME_DECOR_MAXIMIZE
|
1539 OB_FRAME_DECOR_SHADE
|
1540 OB_FRAME_DECOR_CLOSE
);
1542 (OB_CLIENT_FUNC_RESIZE
|
1543 OB_CLIENT_FUNC_MOVE
|
1544 OB_CLIENT_FUNC_ICONIFY
|
1545 OB_CLIENT_FUNC_MAXIMIZE
|
1546 OB_CLIENT_FUNC_SHADE
|
1547 OB_CLIENT_FUNC_CLOSE
);
1549 if (!(self
->min_size
.width
< self
->max_size
.width
||
1550 self
->min_size
.height
< self
->max_size
.height
))
1551 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
1553 switch (self
->type
) {
1554 case OB_CLIENT_TYPE_NORMAL
:
1555 /* normal windows retain all of the possible decorations and
1556 functionality, and are the only windows that you can fullscreen */
1557 self
->functions
|= OB_CLIENT_FUNC_FULLSCREEN
;
1560 case OB_CLIENT_TYPE_DIALOG
:
1561 case OB_CLIENT_TYPE_UTILITY
:
1562 /* these windows cannot be maximized */
1563 self
->functions
&= ~OB_CLIENT_FUNC_MAXIMIZE
;
1566 case OB_CLIENT_TYPE_MENU
:
1567 case OB_CLIENT_TYPE_TOOLBAR
:
1568 /* these windows get less functionality */
1569 self
->functions
&= ~(OB_CLIENT_FUNC_ICONIFY
| OB_CLIENT_FUNC_RESIZE
);
1572 case OB_CLIENT_TYPE_DESKTOP
:
1573 case OB_CLIENT_TYPE_DOCK
:
1574 case OB_CLIENT_TYPE_SPLASH
:
1575 /* none of these windows are manipulated by the window manager */
1576 self
->decorations
= 0;
1577 self
->functions
= 0;
1581 /* Mwm Hints are applied subtractively to what has already been chosen for
1582 decor and functionality */
1583 if (self
->mwmhints
.flags
& OB_MWM_FLAG_DECORATIONS
) {
1584 if (! (self
->mwmhints
.decorations
& OB_MWM_DECOR_ALL
)) {
1585 if (! ((self
->mwmhints
.decorations
& OB_MWM_DECOR_HANDLE
) ||
1586 (self
->mwmhints
.decorations
& OB_MWM_DECOR_TITLE
)))
1588 /* if the mwm hints request no handle or title, then all
1589 decorations are disabled, but keep the border if that's
1591 if (self
->mwmhints
.decorations
& OB_MWM_DECOR_BORDER
)
1592 self
->decorations
= OB_FRAME_DECOR_BORDER
;
1594 self
->decorations
= 0;
1599 if (self
->mwmhints
.flags
& OB_MWM_FLAG_FUNCTIONS
) {
1600 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_ALL
)) {
1601 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_RESIZE
))
1602 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
1603 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_MOVE
))
1604 self
->functions
&= ~OB_CLIENT_FUNC_MOVE
;
1605 /* dont let mwm hints kill any buttons
1606 if (! (self->mwmhints.functions & OB_MWM_FUNC_ICONIFY))
1607 self->functions &= ~OB_CLIENT_FUNC_ICONIFY;
1608 if (! (self->mwmhints.functions & OB_MWM_FUNC_MAXIMIZE))
1609 self->functions &= ~OB_CLIENT_FUNC_MAXIMIZE;
1611 /* dont let mwm hints kill the close button
1612 if (! (self->mwmhints.functions & MwmFunc_Close))
1613 self->functions &= ~OB_CLIENT_FUNC_CLOSE; */
1617 if (!(self
->functions
& OB_CLIENT_FUNC_SHADE
))
1618 self
->decorations
&= ~OB_FRAME_DECOR_SHADE
;
1619 if (!(self
->functions
& OB_CLIENT_FUNC_ICONIFY
))
1620 self
->decorations
&= ~OB_FRAME_DECOR_ICONIFY
;
1621 if (!(self
->functions
& OB_CLIENT_FUNC_RESIZE
))
1622 self
->decorations
&= ~OB_FRAME_DECOR_GRIPS
;
1624 /* can't maximize without moving/resizing */
1625 if (!((self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) &&
1626 (self
->functions
& OB_CLIENT_FUNC_MOVE
) &&
1627 (self
->functions
& OB_CLIENT_FUNC_RESIZE
))) {
1628 self
->functions
&= ~OB_CLIENT_FUNC_MAXIMIZE
;
1629 self
->decorations
&= ~OB_FRAME_DECOR_MAXIMIZE
;
1632 /* kill the handle on fully maxed windows */
1633 if (self
->max_vert
&& self
->max_horz
)
1634 self
->decorations
&= ~OB_FRAME_DECOR_HANDLE
;
1636 /* finally, the user can have requested no decorations, which overrides
1637 everything (but doesnt give it a border if it doesnt have one) */
1638 if (self
->undecorated
) {
1639 if (config_theme_keepborder
)
1640 self
->decorations
&= OB_FRAME_DECOR_BORDER
;
1642 self
->decorations
= 0;
1645 /* if we don't have a titlebar, then we cannot shade! */
1646 if (!(self
->decorations
& OB_FRAME_DECOR_TITLEBAR
))
1647 self
->functions
&= ~OB_CLIENT_FUNC_SHADE
;
1649 /* now we need to check against rules for the client's current state */
1650 if (self
->fullscreen
) {
1651 self
->functions
&= (OB_CLIENT_FUNC_CLOSE
|
1652 OB_CLIENT_FUNC_FULLSCREEN
|
1653 OB_CLIENT_FUNC_ICONIFY
);
1654 self
->decorations
= 0;
1657 client_change_allowed_actions(self
);
1660 /* adjust the client's decorations, etc. */
1661 client_reconfigure(self
);
1665 static void client_change_allowed_actions(ObClient
*self
)
1670 /* desktop windows are kept on all desktops */
1671 if (self
->type
!= OB_CLIENT_TYPE_DESKTOP
)
1672 actions
[num
++] = prop_atoms
.net_wm_action_change_desktop
;
1674 if (self
->functions
& OB_CLIENT_FUNC_SHADE
)
1675 actions
[num
++] = prop_atoms
.net_wm_action_shade
;
1676 if (self
->functions
& OB_CLIENT_FUNC_CLOSE
)
1677 actions
[num
++] = prop_atoms
.net_wm_action_close
;
1678 if (self
->functions
& OB_CLIENT_FUNC_MOVE
)
1679 actions
[num
++] = prop_atoms
.net_wm_action_move
;
1680 if (self
->functions
& OB_CLIENT_FUNC_ICONIFY
)
1681 actions
[num
++] = prop_atoms
.net_wm_action_minimize
;
1682 if (self
->functions
& OB_CLIENT_FUNC_RESIZE
)
1683 actions
[num
++] = prop_atoms
.net_wm_action_resize
;
1684 if (self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
)
1685 actions
[num
++] = prop_atoms
.net_wm_action_fullscreen
;
1686 if (self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) {
1687 actions
[num
++] = prop_atoms
.net_wm_action_maximize_horz
;
1688 actions
[num
++] = prop_atoms
.net_wm_action_maximize_vert
;
1691 PROP_SETA32(self
->window
, net_wm_allowed_actions
, atom
, actions
, num
);
1693 /* make sure the window isn't breaking any rules now */
1695 if (!(self
->functions
& OB_CLIENT_FUNC_SHADE
) && self
->shaded
) {
1696 if (self
->frame
) client_shade(self
, FALSE
);
1697 else self
->shaded
= FALSE
;
1699 if (!(self
->functions
& OB_CLIENT_FUNC_ICONIFY
) && self
->iconic
) {
1700 if (self
->frame
) client_iconify(self
, FALSE
, TRUE
);
1701 else self
->iconic
= FALSE
;
1703 if (!(self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
) && self
->fullscreen
) {
1704 if (self
->frame
) client_fullscreen(self
, FALSE
);
1705 else self
->fullscreen
= FALSE
;
1707 if (!(self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) && (self
->max_horz
||
1709 if (self
->frame
) client_maximize(self
, FALSE
, 0);
1710 else self
->max_vert
= self
->max_horz
= FALSE
;
1714 void client_reconfigure(ObClient
*self
)
1716 /* by making this pass FALSE for user, we avoid the emacs event storm where
1717 every configurenotify causes an update in its normal hints, i think this
1718 is generally what we want anyways... */
1719 client_configure(self
, self
->area
.x
, self
->area
.y
,
1720 self
->area
.width
, self
->area
.height
, FALSE
, TRUE
);
1723 void client_update_wmhints(ObClient
*self
)
1727 /* assume a window takes input if it doesnt specify */
1728 self
->can_focus
= TRUE
;
1730 if ((hints
= XGetWMHints(ob_display
, self
->window
)) != NULL
) {
1733 if (hints
->flags
& InputHint
)
1734 self
->can_focus
= hints
->input
;
1736 /* only do this when first managing the window *AND* when we aren't
1738 if (ob_state() != OB_STATE_STARTING
&& self
->frame
== NULL
)
1739 if (hints
->flags
& StateHint
)
1740 self
->iconic
= hints
->initial_state
== IconicState
;
1743 self
->urgent
= (hints
->flags
& XUrgencyHint
);
1744 if (self
->urgent
&& !ur
)
1745 client_hilite(self
, TRUE
);
1746 else if (!self
->urgent
&& ur
&& self
->demands_attention
)
1747 client_hilite(self
, FALSE
);
1749 if (!(hints
->flags
& WindowGroupHint
))
1750 hints
->window_group
= None
;
1752 /* did the group state change? */
1753 if (hints
->window_group
!=
1754 (self
->group
? self
->group
->leader
: None
))
1756 ObGroup
*oldgroup
= self
->group
;
1758 /* remove from the old group if there was one */
1759 if (self
->group
!= NULL
) {
1760 group_remove(self
->group
, self
);
1764 /* add ourself to the group if we have one */
1765 if (hints
->window_group
!= None
) {
1766 self
->group
= group_add(hints
->window_group
, self
);
1769 /* Put ourselves into the new group's transient tree, and remove
1770 ourselves from the old group's */
1771 client_update_transient_tree(self
, oldgroup
, self
->group
,
1772 self
->transient_for
,
1773 self
->transient_for
);
1775 /* Lastly, being in a group, or not, can change if the window is
1776 transient for anything.
1778 The logic for this is:
1779 self->transient = TRUE always if the window wants to be
1780 transient for something, even if transient_for was NULL because
1781 it wasn't in a group before.
1783 If transient_for was NULL and oldgroup was NULL we can assume
1784 that when we add the new group, it will become transient for
1787 If transient_for was OB_TRAN_GROUP, then it must have already
1788 had a group. If it is getting a new group, the above call to
1789 client_update_transient_tree has already taken care of
1790 everything ! If it is losing all group status then it will
1791 no longer be transient for anything and that needs to be
1794 if (self
->transient
&&
1795 ((self
->transient_for
== NULL
&& oldgroup
== NULL
) ||
1796 (self
->transient_for
== OB_TRAN_GROUP
&& !self
->group
)))
1797 client_update_transient_for(self
);
1800 /* the WM_HINTS can contain an icon */
1801 client_update_icons(self
);
1807 void client_update_title(ObClient
*self
)
1810 gchar
*visible
= NULL
;
1812 g_free(self
->title
);
1815 if (!PROP_GETS(self
->window
, net_wm_name
, utf8
, &data
)) {
1816 /* try old x stuff */
1817 if (!(PROP_GETS(self
->window
, wm_name
, locale
, &data
)
1818 || PROP_GETS(self
->window
, wm_name
, utf8
, &data
))) {
1819 if (self
->transient
) {
1821 GNOME alert windows are not given titles:
1822 http://developer.gnome.org/projects/gup/hig/draft_hig_new/windows-alert.html
1824 data
= g_strdup("");
1826 data
= g_strdup("Unnamed Window");
1830 if (self
->client_machine
) {
1831 visible
= g_strdup_printf("%s (%s)", data
, self
->client_machine
);
1836 PROP_SETS(self
->window
, net_wm_visible_name
, visible
);
1837 self
->title
= visible
;
1840 frame_adjust_title(self
->frame
);
1842 /* update the icon title */
1844 g_free(self
->icon_title
);
1847 if (!PROP_GETS(self
->window
, net_wm_icon_name
, utf8
, &data
))
1848 /* try old x stuff */
1849 if (!(PROP_GETS(self
->window
, wm_icon_name
, locale
, &data
) ||
1850 PROP_GETS(self
->window
, wm_icon_name
, utf8
, &data
)))
1851 data
= g_strdup(self
->title
);
1853 PROP_SETS(self
->window
, net_wm_visible_icon_name
, data
);
1854 self
->icon_title
= data
;
1857 void client_update_class(ObClient
*self
)
1862 if (self
->name
) g_free(self
->name
);
1863 if (self
->class) g_free(self
->class);
1864 if (self
->role
) g_free(self
->role
);
1866 self
->name
= self
->class = self
->role
= NULL
;
1868 if (PROP_GETSS(self
->window
, wm_class
, locale
, &data
)) {
1870 self
->name
= g_strdup(data
[0]);
1872 self
->class = g_strdup(data
[1]);
1877 if (PROP_GETS(self
->window
, wm_window_role
, locale
, &s
))
1880 if (self
->name
== NULL
) self
->name
= g_strdup("");
1881 if (self
->class == NULL
) self
->class = g_strdup("");
1882 if (self
->role
== NULL
) self
->role
= g_strdup("");
1885 void client_update_strut(ObClient
*self
)
1889 gboolean got
= FALSE
;
1892 if (PROP_GETA32(self
->window
, net_wm_strut_partial
, cardinal
,
1896 STRUT_PARTIAL_SET(strut
,
1897 data
[0], data
[2], data
[1], data
[3],
1898 data
[4], data
[5], data
[8], data
[9],
1899 data
[6], data
[7], data
[10], data
[11]);
1905 PROP_GETA32(self
->window
, net_wm_strut
, cardinal
, &data
, &num
)) {
1911 /* use the screen's width/height */
1912 a
= screen_physical_area();
1914 STRUT_PARTIAL_SET(strut
,
1915 data
[0], data
[2], data
[1], data
[3],
1916 a
->y
, a
->y
+ a
->height
- 1,
1917 a
->x
, a
->x
+ a
->width
- 1,
1918 a
->y
, a
->y
+ a
->height
- 1,
1919 a
->x
, a
->x
+ a
->width
- 1);
1925 STRUT_PARTIAL_SET(strut
, 0, 0, 0, 0,
1926 0, 0, 0, 0, 0, 0, 0, 0);
1928 if (!STRUT_EQUAL(strut
, self
->strut
)) {
1929 self
->strut
= strut
;
1931 /* updating here is pointless while we're being mapped cuz we're not in
1932 the client list yet */
1934 screen_update_areas();
1938 void client_update_icons(ObClient
*self
)
1944 for (i
= 0; i
< self
->nicons
; ++i
)
1945 g_free(self
->icons
[i
].data
);
1946 if (self
->nicons
> 0)
1947 g_free(self
->icons
);
1950 if (PROP_GETA32(self
->window
, net_wm_icon
, cardinal
, &data
, &num
)) {
1951 /* figure out how many valid icons are in here */
1953 while (num
- i
> 2) {
1957 if (i
> num
|| w
*h
== 0) break;
1961 self
->icons
= g_new(ObClientIcon
, self
->nicons
);
1963 /* store the icons */
1965 for (j
= 0; j
< self
->nicons
; ++j
) {
1968 w
= self
->icons
[j
].width
= data
[i
++];
1969 h
= self
->icons
[j
].height
= data
[i
++];
1971 if (w
*h
== 0) continue;
1973 self
->icons
[j
].data
= g_new(RrPixel32
, w
* h
);
1974 for (x
= 0, y
= 0, t
= 0; t
< w
* h
; ++t
, ++x
, ++i
) {
1979 self
->icons
[j
].data
[t
] =
1980 (((data
[i
] >> 24) & 0xff) << RrDefaultAlphaOffset
) +
1981 (((data
[i
] >> 16) & 0xff) << RrDefaultRedOffset
) +
1982 (((data
[i
] >> 8) & 0xff) << RrDefaultGreenOffset
) +
1983 (((data
[i
] >> 0) & 0xff) << RrDefaultBlueOffset
);
1992 if ((hints
= XGetWMHints(ob_display
, self
->window
))) {
1993 if (hints
->flags
& IconPixmapHint
) {
1995 self
->icons
= g_new(ObClientIcon
, self
->nicons
);
1996 xerror_set_ignore(TRUE
);
1997 if (!RrPixmapToRGBA(ob_rr_inst
,
1999 (hints
->flags
& IconMaskHint
?
2000 hints
->icon_mask
: None
),
2001 &self
->icons
[self
->nicons
-1].width
,
2002 &self
->icons
[self
->nicons
-1].height
,
2003 &self
->icons
[self
->nicons
-1].data
)){
2004 g_free(&self
->icons
[self
->nicons
-1]);
2007 xerror_set_ignore(FALSE
);
2013 /* set the default icon onto the window
2014 in theory, this could be a race, but if a window doesn't set an icon
2015 or removes it entirely, it's not very likely it is going to set one
2016 right away afterwards */
2017 if (self
->nicons
== 0) {
2018 RrPixel32
*icon
= ob_rr_theme
->def_win_icon
;
2021 data
= g_new(gulong
, 48*48+2);
2022 data
[0] = data
[1] = 48;
2023 for (i
= 0; i
< 48*48; ++i
)
2024 data
[i
+2] = (((icon
[i
] >> RrDefaultAlphaOffset
) & 0xff) << 24) +
2025 (((icon
[i
] >> RrDefaultRedOffset
) & 0xff) << 16) +
2026 (((icon
[i
] >> RrDefaultGreenOffset
) & 0xff) << 8) +
2027 (((icon
[i
] >> RrDefaultBlueOffset
) & 0xff) << 0);
2028 PROP_SETA32(self
->window
, net_wm_icon
, cardinal
, data
, 48*48+2);
2030 } else if (self
->frame
)
2031 /* don't draw the icon empty if we're just setting one now anyways,
2032 we'll get the property change any second */
2033 frame_adjust_icon(self
->frame
);
2036 void client_update_user_time(ObClient
*self
)
2040 if (PROP_GET32(self
->window
, net_wm_user_time
, cardinal
, &time
)) {
2041 /* we set this every time, not just when it grows, because in practice
2042 sometimes time goes backwards! (ntpdate.. yay....) so.. if it goes
2043 backward we don't want all windows to stop focusing. we'll just
2044 assume noone is setting times older than the last one, cuz that
2045 would be pretty stupid anyways
2047 self
->user_time
= time
;
2050 ob_debug("window %s user time %u\n", self->title, time);
2055 void client_update_icon_geometry(ObClient
*self
)
2060 RECT_SET(self
->icon_geometry
, 0, 0, 0, 0);
2062 if (PROP_GETA32(self
->window
, net_wm_icon_geometry
, cardinal
, &data
, &num
)
2065 /* don't let them set it with an area < 0 */
2066 RECT_SET(self
->icon_geometry
, data
[0], data
[1],
2067 MAX(data
[2],0), MAX(data
[3],0));
2071 static void client_get_client_machine(ObClient
*self
)
2074 gchar localhost
[128];
2076 g_free(self
->client_machine
);
2078 if (PROP_GETS(self
->window
, wm_client_machine
, locale
, &data
)) {
2079 gethostname(localhost
, 127);
2080 localhost
[127] = '\0';
2081 if (strcmp(localhost
, data
))
2082 self
->client_machine
= data
;
2086 static void client_change_wm_state(ObClient
*self
)
2091 old
= self
->wmstate
;
2093 if (self
->shaded
|| !self
->frame
->visible
)
2094 self
->wmstate
= IconicState
;
2096 self
->wmstate
= NormalState
;
2098 if (old
!= self
->wmstate
) {
2099 PROP_MSG(self
->window
, kde_wm_change_state
,
2100 self
->wmstate
, 1, 0, 0);
2102 state
[0] = self
->wmstate
;
2104 PROP_SETA32(self
->window
, wm_state
, wm_state
, state
, 2);
2108 static void client_change_state(ObClient
*self
)
2110 gulong netstate
[11];
2115 netstate
[num
++] = prop_atoms
.net_wm_state_modal
;
2117 netstate
[num
++] = prop_atoms
.net_wm_state_shaded
;
2119 netstate
[num
++] = prop_atoms
.net_wm_state_hidden
;
2120 if (self
->skip_taskbar
)
2121 netstate
[num
++] = prop_atoms
.net_wm_state_skip_taskbar
;
2122 if (self
->skip_pager
)
2123 netstate
[num
++] = prop_atoms
.net_wm_state_skip_pager
;
2124 if (self
->fullscreen
)
2125 netstate
[num
++] = prop_atoms
.net_wm_state_fullscreen
;
2127 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_vert
;
2129 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_horz
;
2131 netstate
[num
++] = prop_atoms
.net_wm_state_above
;
2133 netstate
[num
++] = prop_atoms
.net_wm_state_below
;
2134 if (self
->demands_attention
)
2135 netstate
[num
++] = prop_atoms
.net_wm_state_demands_attention
;
2136 if (self
->undecorated
)
2137 netstate
[num
++] = prop_atoms
.openbox_wm_state_undecorated
;
2138 PROP_SETA32(self
->window
, net_wm_state
, atom
, netstate
, num
);
2141 frame_adjust_state(self
->frame
);
2144 ObClient
*client_search_focus_tree(ObClient
*self
)
2149 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
2150 if (client_focused(it
->data
)) return it
->data
;
2151 if ((ret
= client_search_focus_tree(it
->data
))) return ret
;
2156 ObClient
*client_search_focus_tree_full(ObClient
*self
)
2158 if (self
->transient_for
) {
2159 if (self
->transient_for
!= OB_TRAN_GROUP
) {
2160 return client_search_focus_tree_full(self
->transient_for
);
2163 gboolean recursed
= FALSE
;
2165 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
))
2166 if (!((ObClient
*)it
->data
)->transient_for
) {
2168 if ((c
= client_search_focus_tree_full(it
->data
)))
2177 /* this function checks the whole tree, the client_search_focus_tree~
2178 does not, so we need to check this window */
2179 if (client_focused(self
))
2181 return client_search_focus_tree(self
);
2184 static ObStackingLayer
calc_layer(ObClient
*self
)
2188 if (self
->type
== OB_CLIENT_TYPE_DESKTOP
)
2189 l
= OB_STACKING_LAYER_DESKTOP
;
2190 else if (self
->type
== OB_CLIENT_TYPE_DOCK
) {
2191 if (self
->below
) l
= OB_STACKING_LAYER_NORMAL
;
2192 else l
= OB_STACKING_LAYER_ABOVE
;
2194 else if ((self
->fullscreen
||
2195 /* no decorations and fills the monitor = oldskool fullscreen */
2196 (self
->frame
!= NULL
&&
2197 (self
->frame
->size
.right
== 0 && self
->frame
->size
.left
== 0 &&
2198 self
->frame
->size
.bottom
== 0 && self
->frame
->size
.top
== 0 &&
2199 RECT_EQUAL(self
->area
,
2200 *screen_physical_area_monitor
2201 (client_monitor(self
)))))) &&
2202 (client_focused(self
) || client_search_focus_tree(self
)))
2203 l
= OB_STACKING_LAYER_FULLSCREEN
;
2204 else if (self
->above
) l
= OB_STACKING_LAYER_ABOVE
;
2205 else if (self
->below
) l
= OB_STACKING_LAYER_BELOW
;
2206 else l
= OB_STACKING_LAYER_NORMAL
;
2211 static void client_calc_layer_recursive(ObClient
*self
, ObClient
*orig
,
2212 ObStackingLayer min
, gboolean raised
)
2214 ObStackingLayer old
, own
;
2218 own
= calc_layer(self
);
2219 self
->layer
= MAX(own
, min
);
2221 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
2222 client_calc_layer_recursive(it
->data
, orig
,
2224 raised
? raised
: self
->layer
!= old
);
2226 if (!raised
&& self
->layer
!= old
)
2227 if (orig
->frame
) { /* only restack if the original window is managed */
2228 stacking_remove(CLIENT_AS_WINDOW(self
));
2229 stacking_add(CLIENT_AS_WINDOW(self
));
2233 void client_calc_layer(ObClient
*self
)
2240 /* transients take on the layer of their parents */
2241 it
= client_search_all_top_parents(self
);
2243 for (; it
; it
= g_slist_next(it
))
2244 client_calc_layer_recursive(it
->data
, orig
, 0, FALSE
);
2247 gboolean
client_should_show(ObClient
*self
)
2251 if (client_normal(self
) && screen_showing_desktop
)
2254 if (self->transient_for) {
2255 if (self->transient_for != OB_TRAN_GROUP)
2256 return client_should_show(self->transient_for);
2260 for (it = self->group->members; it; it = g_slist_next(it)) {
2261 ObClient *c = it->data;
2262 if (c != self && !c->transient_for) {
2263 if (client_should_show(c))
2270 if (self
->desktop
== screen_desktop
|| self
->desktop
== DESKTOP_ALL
)
2276 void client_show(ObClient
*self
)
2279 if (client_should_show(self
)) {
2280 frame_show(self
->frame
);
2283 /* According to the ICCCM (sec 4.1.3.1) when a window is not visible, it
2284 needs to be in IconicState. This includes when it is on another
2287 client_change_wm_state(self
);
2290 void client_hide(ObClient
*self
)
2292 if (!client_should_show(self
)) {
2293 frame_hide(self
->frame
);
2296 /* According to the ICCCM (sec 4.1.3.1) when a window is not visible, it
2297 needs to be in IconicState. This includes when it is on another
2300 client_change_wm_state(self
);
2303 void client_showhide(ObClient
*self
)
2306 if (client_should_show(self
)) {
2307 frame_show(self
->frame
);
2310 frame_hide(self
->frame
);
2313 /* According to the ICCCM (sec 4.1.3.1) when a window is not visible, it
2314 needs to be in IconicState. This includes when it is on another
2317 client_change_wm_state(self
);
2320 gboolean
client_normal(ObClient
*self
) {
2321 return ! (self
->type
== OB_CLIENT_TYPE_DESKTOP
||
2322 self
->type
== OB_CLIENT_TYPE_DOCK
||
2323 self
->type
== OB_CLIENT_TYPE_SPLASH
);
2326 gboolean
client_application(ObClient
*self
)
2328 return (self
->type
== OB_CLIENT_TYPE_NORMAL
||
2329 self
->type
== OB_CLIENT_TYPE_DIALOG
);
2332 static void client_apply_startup_state(ObClient
*self
, gint x
, gint y
)
2334 gboolean pos
= FALSE
; /* has the window's position been configured? */
2337 /* save the position, and set self->area for these to use */
2343 /* set the desktop hint, to make sure that it always exists */
2344 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, self
->desktop
);
2346 /* these are in a carefully crafted order.. */
2349 self
->iconic
= FALSE
;
2350 client_iconify(self
, TRUE
, FALSE
);
2352 if (self
->fullscreen
) {
2353 self
->fullscreen
= FALSE
;
2354 client_fullscreen(self
, TRUE
);
2357 if (self
->undecorated
) {
2358 self
->undecorated
= FALSE
;
2359 client_set_undecorated(self
, TRUE
);
2362 self
->shaded
= FALSE
;
2363 client_shade(self
, TRUE
);
2365 if (self
->demands_attention
) {
2366 self
->demands_attention
= FALSE
;
2367 client_hilite(self
, TRUE
);
2370 if (self
->max_vert
&& self
->max_horz
) {
2371 self
->max_vert
= self
->max_horz
= FALSE
;
2372 client_maximize(self
, TRUE
, 0);
2374 } else if (self
->max_vert
) {
2375 self
->max_vert
= FALSE
;
2376 client_maximize(self
, TRUE
, 2);
2378 } else if (self
->max_horz
) {
2379 self
->max_horz
= FALSE
;
2380 client_maximize(self
, TRUE
, 1);
2384 /* if the client didn't get positioned yet, then do so now
2385 call client_move even if the window is not being moved anywhere, because
2386 when we reparent it and decorate it, it is getting moved and we need to
2387 be telling it so with a ConfigureNotify event.
2390 /* use the saved position */
2393 client_move(self
, x
, y
);
2396 /* nothing to do for the other states:
2405 void client_convert_gravity(ObClient
*self
, gint gravity
, gint
*x
, gint
*y
,
2408 gint oldg
= self
->gravity
;
2410 /* get the frame's position from the requested stuff */
2411 self
->gravity
= gravity
;
2412 frame_client_gravity(self
->frame
, x
, y
, w
, h
);
2413 self
->gravity
= oldg
;
2415 /* get the client's position in its true gravity from that */
2416 frame_frame_gravity(self
->frame
, x
, y
, w
, h
);
2419 void client_try_configure(ObClient
*self
, gint
*x
, gint
*y
, gint
*w
, gint
*h
,
2420 gint
*logicalw
, gint
*logicalh
,
2423 Rect desired_area
= {*x
, *y
, *w
, *h
};
2425 /* make the frame recalculate its dimentions n shit without changing
2426 anything visible for real, this way the constraints below can work with
2427 the updated frame dimensions. */
2428 frame_adjust_area(self
->frame
, TRUE
, TRUE
, TRUE
);
2430 /* work within the prefered sizes given by the window */
2431 if (!(*w
== self
->area
.width
&& *h
== self
->area
.height
)) {
2432 gint basew
, baseh
, minw
, minh
;
2434 /* base size is substituted with min size if not specified */
2435 if (self
->base_size
.width
|| self
->base_size
.height
) {
2436 basew
= self
->base_size
.width
;
2437 baseh
= self
->base_size
.height
;
2439 basew
= self
->min_size
.width
;
2440 baseh
= self
->min_size
.height
;
2442 /* min size is substituted with base size if not specified */
2443 if (self
->min_size
.width
|| self
->min_size
.height
) {
2444 minw
= self
->min_size
.width
;
2445 minh
= self
->min_size
.height
;
2447 minw
= self
->base_size
.width
;
2448 minh
= self
->base_size
.height
;
2451 /* if this is a user-requested resize, then check against min/max
2454 /* smaller than min size or bigger than max size? */
2455 if (*w
> self
->max_size
.width
) *w
= self
->max_size
.width
;
2456 if (*w
< minw
) *w
= minw
;
2457 if (*h
> self
->max_size
.height
) *h
= self
->max_size
.height
;
2458 if (*h
< minh
) *h
= minh
;
2463 /* keep to the increments */
2464 *w
/= self
->size_inc
.width
;
2465 *h
/= self
->size_inc
.height
;
2467 /* you cannot resize to nothing */
2468 if (basew
+ *w
< 1) *w
= 1 - basew
;
2469 if (baseh
+ *h
< 1) *h
= 1 - baseh
;
2471 /* save the logical size */
2472 *logicalw
= self
->size_inc
.width
> 1 ? *w
: *w
+ basew
;
2473 *logicalh
= self
->size_inc
.height
> 1 ? *h
: *h
+ baseh
;
2475 *w
*= self
->size_inc
.width
;
2476 *h
*= self
->size_inc
.height
;
2481 /* adjust the height to match the width for the aspect ratios.
2482 for this, min size is not substituted for base size ever. */
2483 *w
-= self
->base_size
.width
;
2484 *h
-= self
->base_size
.height
;
2486 if (!self
->fullscreen
) {
2487 if (self
->min_ratio
)
2488 if (*h
* self
->min_ratio
> *w
) {
2489 *h
= (gint
)(*w
/ self
->min_ratio
);
2491 /* you cannot resize to nothing */
2494 *w
= (gint
)(*h
* self
->min_ratio
);
2497 if (self
->max_ratio
)
2498 if (*h
* self
->max_ratio
< *w
) {
2499 *h
= (gint
)(*w
/ self
->max_ratio
);
2501 /* you cannot resize to nothing */
2504 *w
= (gint
)(*h
* self
->min_ratio
);
2509 *w
+= self
->base_size
.width
;
2510 *h
+= self
->base_size
.height
;
2513 /* gets the frame's position */
2514 frame_client_gravity(self
->frame
, x
, y
, *w
, *h
);
2516 /* these positions are frame positions, not client positions */
2518 /* set the size and position if fullscreen */
2519 if (self
->fullscreen
) {
2523 i
= screen_find_monitor(&desired_area
);
2524 a
= screen_physical_area_monitor(i
);
2531 user
= FALSE
; /* ignore if the client can't be moved/resized when it
2532 is entering fullscreen */
2533 } else if (self
->max_horz
|| self
->max_vert
) {
2537 i
= screen_find_monitor(&desired_area
);
2538 a
= screen_area_monitor(self
->desktop
, i
);
2540 /* set the size and position if maximized */
2541 if (self
->max_horz
) {
2543 *w
= a
->width
- self
->frame
->size
.left
- self
->frame
->size
.right
;
2545 if (self
->max_vert
) {
2547 *h
= a
->height
- self
->frame
->size
.top
- self
->frame
->size
.bottom
;
2550 /* maximizing is not allowed if the user can't move+resize the window
2554 /* gets the client's position */
2555 frame_frame_gravity(self
->frame
, x
, y
, *w
, *h
);
2557 /* these override the above states! if you cant move you can't move! */
2559 if (!(self
->functions
& OB_CLIENT_FUNC_MOVE
)) {
2563 if (!(self
->functions
& OB_CLIENT_FUNC_RESIZE
)) {
2564 *w
= self
->area
.width
;
2565 *h
= self
->area
.height
;
2574 void client_configure_full(ObClient
*self
, gint x
, gint y
, gint w
, gint h
,
2575 gboolean user
, gboolean final
,
2576 gboolean force_reply
)
2578 gint oldw
, oldh
, oldrx
, oldry
;
2579 gboolean send_resize_client
;
2580 gboolean moved
= FALSE
, resized
= FALSE
, rootmoved
= FALSE
;
2581 guint fdecor
= self
->frame
->decorations
;
2582 gboolean fhorz
= self
->frame
->max_horz
;
2583 gint logicalw
, logicalh
;
2585 /* find the new x, y, width, and height (and logical size) */
2586 client_try_configure(self
, &x
, &y
, &w
, &h
, &logicalw
, &logicalh
, user
);
2588 /* set the logical size if things changed */
2589 if (!(w
== self
->area
.width
&& h
== self
->area
.height
))
2590 SIZE_SET(self
->logical_size
, logicalw
, logicalh
);
2592 /* figure out if we moved or resized or what */
2593 moved
= x
!= self
->area
.x
|| y
!= self
->area
.y
;
2594 resized
= w
!= self
->area
.width
|| h
!= self
->area
.height
;
2596 oldw
= self
->area
.width
;
2597 oldh
= self
->area
.height
;
2598 RECT_SET(self
->area
, x
, y
, w
, h
);
2600 /* for app-requested resizes, always resize if 'resized' is true.
2601 for user-requested ones, only resize if final is true, or when
2602 resizing in redraw mode */
2603 send_resize_client
= ((!user
&& resized
) ||
2605 (resized
&& config_resize_redraw
))));
2607 /* if the client is enlarging, then resize the client before the frame */
2608 if (send_resize_client
&& user
&& (w
> oldw
|| h
> oldh
)) {
2609 XResizeWindow(ob_display
, self
->window
, MAX(w
, oldw
), MAX(h
, oldh
));
2610 /* resize the plate to show the client padding color underneath */
2611 frame_adjust_client_area(self
->frame
);
2614 /* find the frame's dimensions and move/resize it */
2615 if (self
->decorations
!= fdecor
|| self
->max_horz
!= fhorz
)
2616 moved
= resized
= TRUE
;
2617 if (moved
|| resized
)
2618 frame_adjust_area(self
->frame
, moved
, resized
, FALSE
);
2620 /* find the client's position relative to the root window */
2621 oldrx
= self
->root_pos
.x
;
2622 oldry
= self
->root_pos
.y
;
2623 rootmoved
= (oldrx
!= (signed)(self
->frame
->area
.x
+
2624 self
->frame
->size
.left
-
2625 self
->border_width
) ||
2626 oldry
!= (signed)(self
->frame
->area
.y
+
2627 self
->frame
->size
.top
-
2628 self
->border_width
));
2630 if (force_reply
|| ((!user
|| (user
&& final
)) && rootmoved
))
2634 POINT_SET(self
->root_pos
,
2635 self
->frame
->area
.x
+ self
->frame
->size
.left
-
2637 self
->frame
->area
.y
+ self
->frame
->size
.top
-
2638 self
->border_width
);
2640 event
.type
= ConfigureNotify
;
2641 event
.xconfigure
.display
= ob_display
;
2642 event
.xconfigure
.event
= self
->window
;
2643 event
.xconfigure
.window
= self
->window
;
2645 /* root window real coords */
2646 event
.xconfigure
.x
= self
->root_pos
.x
;
2647 event
.xconfigure
.y
= self
->root_pos
.y
;
2648 event
.xconfigure
.width
= w
;
2649 event
.xconfigure
.height
= h
;
2650 event
.xconfigure
.border_width
= 0;
2651 event
.xconfigure
.above
= self
->frame
->plate
;
2652 event
.xconfigure
.override_redirect
= FALSE
;
2653 XSendEvent(event
.xconfigure
.display
, event
.xconfigure
.window
,
2654 FALSE
, StructureNotifyMask
, &event
);
2657 /* if the client is shrinking, then resize the frame before the client */
2658 if (send_resize_client
&& (!user
|| (w
<= oldw
|| h
<= oldh
))) {
2659 /* resize the plate to show the client padding color underneath */
2660 frame_adjust_client_area(self
->frame
);
2662 XResizeWindow(ob_display
, self
->window
, w
, h
);
2668 void client_fullscreen(ObClient
*self
, gboolean fs
)
2672 if (!(self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
) || /* can't */
2673 self
->fullscreen
== fs
) return; /* already done */
2675 self
->fullscreen
= fs
;
2676 client_change_state(self
); /* change the state hints on the client */
2677 client_calc_layer(self
); /* and adjust out layer/stacking */
2680 self
->pre_fullscreen_area
= self
->area
;
2681 /* if the window is maximized, its area isn't all that meaningful.
2682 save it's premax area instead. */
2683 if (self
->max_horz
) {
2684 self
->pre_fullscreen_area
.x
= self
->pre_max_area
.x
;
2685 self
->pre_fullscreen_area
.width
= self
->pre_max_area
.width
;
2687 if (self
->max_vert
) {
2688 self
->pre_fullscreen_area
.y
= self
->pre_max_area
.y
;
2689 self
->pre_fullscreen_area
.height
= self
->pre_max_area
.height
;
2692 /* these are not actually used cuz client_configure will set them
2693 as appropriate when the window is fullscreened */
2698 if (self
->pre_fullscreen_area
.width
> 0 &&
2699 self
->pre_fullscreen_area
.height
> 0)
2701 x
= self
->pre_fullscreen_area
.x
;
2702 y
= self
->pre_fullscreen_area
.y
;
2703 w
= self
->pre_fullscreen_area
.width
;
2704 h
= self
->pre_fullscreen_area
.height
;
2705 RECT_SET(self
->pre_fullscreen_area
, 0, 0, 0, 0);
2707 /* pick some fallbacks... */
2708 a
= screen_area_monitor(self
->desktop
, 0);
2709 x
= a
->x
+ a
->width
/ 4;
2710 y
= a
->y
+ a
->height
/ 4;
2716 client_setup_decor_and_functions(self
);
2718 client_move_resize(self
, x
, y
, w
, h
);
2720 /* try focus us when we go into fullscreen mode */
2724 static void client_iconify_recursive(ObClient
*self
,
2725 gboolean iconic
, gboolean curdesk
)
2728 gboolean changed
= FALSE
;
2731 if (self
->iconic
!= iconic
) {
2732 ob_debug("%sconifying window: 0x%lx\n", (iconic
? "I" : "Uni"),
2736 if (self
->functions
& OB_CLIENT_FUNC_ICONIFY
) {
2737 self
->iconic
= iconic
;
2739 /* update the focus lists.. iconic windows go to the bottom of
2740 the list, put the new iconic window at the 'top of the
2742 focus_order_to_top(self
);
2747 self
->iconic
= iconic
;
2749 if (curdesk
&& self
->desktop
!= screen_desktop
&&
2750 self
->desktop
!= DESKTOP_ALL
)
2751 client_set_desktop(self
, screen_desktop
, FALSE
);
2753 /* this puts it after the current focused window */
2754 focus_order_remove(self
);
2755 focus_order_add_new(self
);
2762 client_change_state(self
);
2763 if (ob_state() != OB_STATE_STARTING
&& config_animate_iconify
)
2764 frame_begin_iconify_animation(self
->frame
, iconic
);
2765 /* do this after starting the animation so it doesn't flash */
2766 client_showhide(self
);
2769 /* iconify all direct transients, and deiconify all transients
2771 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
2772 if (it
->data
!= self
)
2773 if (client_is_direct_child(self
, it
->data
) || !iconic
)
2774 client_iconify_recursive(it
->data
, iconic
, curdesk
);
2777 void client_iconify(ObClient
*self
, gboolean iconic
, gboolean curdesk
)
2779 /* move up the transient chain as far as possible first */
2780 self
= client_search_top_normal_parent(self
);
2781 client_iconify_recursive(self
, iconic
, curdesk
);
2784 void client_maximize(ObClient
*self
, gboolean max
, gint dir
)
2788 g_assert(dir
== 0 || dir
== 1 || dir
== 2);
2789 if (!(self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
)) return; /* can't */
2791 /* check if already done */
2793 if (dir
== 0 && self
->max_horz
&& self
->max_vert
) return;
2794 if (dir
== 1 && self
->max_horz
) return;
2795 if (dir
== 2 && self
->max_vert
) return;
2797 if (dir
== 0 && !self
->max_horz
&& !self
->max_vert
) return;
2798 if (dir
== 1 && !self
->max_horz
) return;
2799 if (dir
== 2 && !self
->max_vert
) return;
2802 /* we just tell it to configure in the same place and client_configure
2803 worries about filling the screen with the window */
2806 w
= self
->area
.width
;
2807 h
= self
->area
.height
;
2810 if ((dir
== 0 || dir
== 1) && !self
->max_horz
) { /* horz */
2811 RECT_SET(self
->pre_max_area
,
2812 self
->area
.x
, self
->pre_max_area
.y
,
2813 self
->area
.width
, self
->pre_max_area
.height
);
2815 if ((dir
== 0 || dir
== 2) && !self
->max_vert
) { /* vert */
2816 RECT_SET(self
->pre_max_area
,
2817 self
->pre_max_area
.x
, self
->area
.y
,
2818 self
->pre_max_area
.width
, self
->area
.height
);
2823 a
= screen_area_monitor(self
->desktop
, 0);
2824 if ((dir
== 0 || dir
== 1) && self
->max_horz
) { /* horz */
2825 if (self
->pre_max_area
.width
> 0) {
2826 x
= self
->pre_max_area
.x
;
2827 w
= self
->pre_max_area
.width
;
2829 RECT_SET(self
->pre_max_area
, 0, self
->pre_max_area
.y
,
2830 0, self
->pre_max_area
.height
);
2832 /* pick some fallbacks... */
2833 x
= a
->x
+ a
->width
/ 4;
2837 if ((dir
== 0 || dir
== 2) && self
->max_vert
) { /* vert */
2838 if (self
->pre_max_area
.height
> 0) {
2839 y
= self
->pre_max_area
.y
;
2840 h
= self
->pre_max_area
.height
;
2842 RECT_SET(self
->pre_max_area
, self
->pre_max_area
.x
, 0,
2843 self
->pre_max_area
.width
, 0);
2845 /* pick some fallbacks... */
2846 y
= a
->y
+ a
->height
/ 4;
2852 if (dir
== 0 || dir
== 1) /* horz */
2853 self
->max_horz
= max
;
2854 if (dir
== 0 || dir
== 2) /* vert */
2855 self
->max_vert
= max
;
2857 client_change_state(self
); /* change the state hints on the client */
2859 client_setup_decor_and_functions(self
);
2861 client_move_resize(self
, x
, y
, w
, h
);
2864 void client_shade(ObClient
*self
, gboolean shade
)
2866 if ((!(self
->functions
& OB_CLIENT_FUNC_SHADE
) &&
2867 shade
) || /* can't shade */
2868 self
->shaded
== shade
) return; /* already done */
2870 self
->shaded
= shade
;
2871 client_change_state(self
);
2872 client_change_wm_state(self
); /* the window is being hidden/shown */
2873 /* resize the frame to just the titlebar */
2874 frame_adjust_area(self
->frame
, FALSE
, FALSE
, FALSE
);
2877 void client_close(ObClient
*self
)
2881 if (!(self
->functions
& OB_CLIENT_FUNC_CLOSE
)) return;
2883 /* in the case that the client provides no means to requesting that it
2884 close, we just kill it */
2885 if (!self
->delete_window
)
2889 XXX: itd be cool to do timeouts and shit here for killing the client's
2891 like... if the window is around after 5 seconds, then the close button
2892 turns a nice red, and if this function is called again, the client is
2896 ce
.xclient
.type
= ClientMessage
;
2897 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
2898 ce
.xclient
.display
= ob_display
;
2899 ce
.xclient
.window
= self
->window
;
2900 ce
.xclient
.format
= 32;
2901 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_delete_window
;
2902 ce
.xclient
.data
.l
[1] = event_curtime
;
2903 ce
.xclient
.data
.l
[2] = 0l;
2904 ce
.xclient
.data
.l
[3] = 0l;
2905 ce
.xclient
.data
.l
[4] = 0l;
2906 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
2909 void client_kill(ObClient
*self
)
2911 XKillClient(ob_display
, self
->window
);
2914 void client_hilite(ObClient
*self
, gboolean hilite
)
2916 if (self
->demands_attention
== hilite
)
2917 return; /* no change */
2919 /* don't allow focused windows to hilite */
2920 self
->demands_attention
= hilite
&& !client_focused(self
);
2921 if (self
->frame
!= NULL
) { /* if we're mapping, just set the state */
2922 if (self
->demands_attention
)
2923 frame_flash_start(self
->frame
);
2925 frame_flash_stop(self
->frame
);
2926 client_change_state(self
);
2930 void client_set_desktop_recursive(ObClient
*self
,
2931 guint target
, gboolean donthide
)
2936 if (target
!= self
->desktop
) {
2938 ob_debug("Setting desktop %u\n", target
+1);
2940 g_assert(target
< screen_num_desktops
|| target
== DESKTOP_ALL
);
2942 /* remove from the old desktop(s) */
2943 focus_order_remove(self
);
2945 old
= self
->desktop
;
2946 self
->desktop
= target
;
2947 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, target
);
2948 /* the frame can display the current desktop state */
2949 frame_adjust_state(self
->frame
);
2950 /* 'move' the window to the new desktop */
2952 client_showhide(self
);
2953 /* raise if it was not already on the desktop */
2954 if (old
!= DESKTOP_ALL
)
2956 if (STRUT_EXISTS(self
->strut
))
2957 screen_update_areas();
2959 /* add to the new desktop(s) */
2960 if (config_focus_new
)
2961 focus_order_to_top(self
);
2963 focus_order_to_bottom(self
);
2966 /* move all transients */
2967 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
2968 if (it
->data
!= self
)
2969 if (client_is_direct_child(self
, it
->data
))
2970 client_set_desktop_recursive(it
->data
, target
, donthide
);
2973 void client_set_desktop(ObClient
*self
, guint target
, gboolean donthide
)
2975 self
= client_search_top_normal_parent(self
);
2976 client_set_desktop_recursive(self
, target
, donthide
);
2979 gboolean
client_is_direct_child(ObClient
*parent
, ObClient
*child
)
2981 while (child
!= parent
&&
2982 child
->transient_for
&& child
->transient_for
!= OB_TRAN_GROUP
)
2983 child
= child
->transient_for
;
2984 return child
== parent
;
2987 ObClient
*client_search_modal_child(ObClient
*self
)
2992 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
2993 ObClient
*c
= it
->data
;
2994 if ((ret
= client_search_modal_child(c
))) return ret
;
2995 if (c
->modal
) return c
;
3000 gboolean
client_validate(ObClient
*self
)
3004 XSync(ob_display
, FALSE
); /* get all events on the server */
3006 if (XCheckTypedWindowEvent(ob_display
, self
->window
, DestroyNotify
, &e
) ||
3007 XCheckTypedWindowEvent(ob_display
, self
->window
, UnmapNotify
, &e
)) {
3008 XPutBackEvent(ob_display
, &e
);
3015 void client_set_wm_state(ObClient
*self
, glong state
)
3017 if (state
== self
->wmstate
) return; /* no change */
3021 client_iconify(self
, TRUE
, TRUE
);
3024 client_iconify(self
, FALSE
, TRUE
);
3029 void client_set_state(ObClient
*self
, Atom action
, glong data1
, glong data2
)
3031 gboolean shaded
= self
->shaded
;
3032 gboolean fullscreen
= self
->fullscreen
;
3033 gboolean undecorated
= self
->undecorated
;
3034 gboolean max_horz
= self
->max_horz
;
3035 gboolean max_vert
= self
->max_vert
;
3036 gboolean modal
= self
->modal
;
3037 gboolean iconic
= self
->iconic
;
3038 gboolean demands_attention
= self
->demands_attention
;
3041 if (!(action
== prop_atoms
.net_wm_state_add
||
3042 action
== prop_atoms
.net_wm_state_remove
||
3043 action
== prop_atoms
.net_wm_state_toggle
))
3044 /* an invalid action was passed to the client message, ignore it */
3047 for (i
= 0; i
< 2; ++i
) {
3048 Atom state
= i
== 0 ? data1
: data2
;
3050 if (!state
) continue;
3052 /* if toggling, then pick whether we're adding or removing */
3053 if (action
== prop_atoms
.net_wm_state_toggle
) {
3054 if (state
== prop_atoms
.net_wm_state_modal
)
3055 action
= modal
? prop_atoms
.net_wm_state_remove
:
3056 prop_atoms
.net_wm_state_add
;
3057 else if (state
== prop_atoms
.net_wm_state_maximized_vert
)
3058 action
= self
->max_vert
? prop_atoms
.net_wm_state_remove
:
3059 prop_atoms
.net_wm_state_add
;
3060 else if (state
== prop_atoms
.net_wm_state_maximized_horz
)
3061 action
= self
->max_horz
? prop_atoms
.net_wm_state_remove
:
3062 prop_atoms
.net_wm_state_add
;
3063 else if (state
== prop_atoms
.net_wm_state_shaded
)
3064 action
= shaded
? prop_atoms
.net_wm_state_remove
:
3065 prop_atoms
.net_wm_state_add
;
3066 else if (state
== prop_atoms
.net_wm_state_skip_taskbar
)
3067 action
= self
->skip_taskbar
?
3068 prop_atoms
.net_wm_state_remove
:
3069 prop_atoms
.net_wm_state_add
;
3070 else if (state
== prop_atoms
.net_wm_state_skip_pager
)
3071 action
= self
->skip_pager
?
3072 prop_atoms
.net_wm_state_remove
:
3073 prop_atoms
.net_wm_state_add
;
3074 else if (state
== prop_atoms
.net_wm_state_hidden
)
3075 action
= self
->iconic
?
3076 prop_atoms
.net_wm_state_remove
:
3077 prop_atoms
.net_wm_state_add
;
3078 else if (state
== prop_atoms
.net_wm_state_fullscreen
)
3079 action
= fullscreen
?
3080 prop_atoms
.net_wm_state_remove
:
3081 prop_atoms
.net_wm_state_add
;
3082 else if (state
== prop_atoms
.net_wm_state_above
)
3083 action
= self
->above
? prop_atoms
.net_wm_state_remove
:
3084 prop_atoms
.net_wm_state_add
;
3085 else if (state
== prop_atoms
.net_wm_state_below
)
3086 action
= self
->below
? prop_atoms
.net_wm_state_remove
:
3087 prop_atoms
.net_wm_state_add
;
3088 else if (state
== prop_atoms
.net_wm_state_demands_attention
)
3089 action
= self
->demands_attention
?
3090 prop_atoms
.net_wm_state_remove
:
3091 prop_atoms
.net_wm_state_add
;
3092 else if (state
== prop_atoms
.openbox_wm_state_undecorated
)
3093 action
= undecorated
? prop_atoms
.net_wm_state_remove
:
3094 prop_atoms
.net_wm_state_add
;
3097 if (action
== prop_atoms
.net_wm_state_add
) {
3098 if (state
== prop_atoms
.net_wm_state_modal
) {
3100 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
3102 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
3104 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
3106 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
3107 self
->skip_taskbar
= TRUE
;
3108 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
3109 self
->skip_pager
= TRUE
;
3110 } else if (state
== prop_atoms
.net_wm_state_hidden
) {
3112 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
3114 } else if (state
== prop_atoms
.net_wm_state_above
) {
3116 self
->below
= FALSE
;
3117 } else if (state
== prop_atoms
.net_wm_state_below
) {
3118 self
->above
= FALSE
;
3120 } else if (state
== prop_atoms
.net_wm_state_demands_attention
) {
3121 demands_attention
= TRUE
;
3122 } else if (state
== prop_atoms
.openbox_wm_state_undecorated
) {
3126 } else { /* action == prop_atoms.net_wm_state_remove */
3127 if (state
== prop_atoms
.net_wm_state_modal
) {
3129 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
3131 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
3133 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
3135 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
3136 self
->skip_taskbar
= FALSE
;
3137 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
3138 self
->skip_pager
= FALSE
;
3139 } else if (state
== prop_atoms
.net_wm_state_hidden
) {
3141 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
3143 } else if (state
== prop_atoms
.net_wm_state_above
) {
3144 self
->above
= FALSE
;
3145 } else if (state
== prop_atoms
.net_wm_state_below
) {
3146 self
->below
= FALSE
;
3147 } else if (state
== prop_atoms
.net_wm_state_demands_attention
) {
3148 demands_attention
= FALSE
;
3149 } else if (state
== prop_atoms
.openbox_wm_state_undecorated
) {
3150 undecorated
= FALSE
;
3154 if (max_horz
!= self
->max_horz
|| max_vert
!= self
->max_vert
) {
3155 if (max_horz
!= self
->max_horz
&& max_vert
!= self
->max_vert
) {
3157 if (max_horz
== max_vert
) { /* both going the same way */
3158 client_maximize(self
, max_horz
, 0);
3160 client_maximize(self
, max_horz
, 1);
3161 client_maximize(self
, max_vert
, 2);
3165 if (max_horz
!= self
->max_horz
)
3166 client_maximize(self
, max_horz
, 1);
3168 client_maximize(self
, max_vert
, 2);
3171 /* change fullscreen state before shading, as it will affect if the window
3173 if (fullscreen
!= self
->fullscreen
)
3174 client_fullscreen(self
, fullscreen
);
3175 if (shaded
!= self
->shaded
)
3176 client_shade(self
, shaded
);
3177 if (undecorated
!= self
->undecorated
)
3178 client_set_undecorated(self
, undecorated
);
3179 if (modal
!= self
->modal
) {
3180 self
->modal
= modal
;
3181 /* when a window changes modality, then its stacking order with its
3182 transients needs to change */
3185 if (iconic
!= self
->iconic
)
3186 client_iconify(self
, iconic
, FALSE
);
3188 if (demands_attention
!= self
->demands_attention
)
3189 client_hilite(self
, demands_attention
);
3191 client_change_state(self
); /* change the hint to reflect these changes */
3194 ObClient
*client_focus_target(ObClient
*self
)
3196 ObClient
*child
= NULL
;
3198 child
= client_search_modal_child(self
);
3199 if (child
) return child
;
3203 gboolean
client_can_focus(ObClient
*self
)
3207 /* choose the correct target */
3208 self
= client_focus_target(self
);
3210 if (!self
->frame
->visible
)
3213 if (!(self
->can_focus
|| self
->focus_notify
))
3216 /* do a check to see if the window has already been unmapped or destroyed
3217 do this intelligently while watching out for unmaps we've generated
3218 (ignore_unmaps > 0) */
3219 if (XCheckTypedWindowEvent(ob_display
, self
->window
,
3220 DestroyNotify
, &ev
)) {
3221 XPutBackEvent(ob_display
, &ev
);
3224 while (XCheckTypedWindowEvent(ob_display
, self
->window
,
3225 UnmapNotify
, &ev
)) {
3226 if (self
->ignore_unmaps
) {
3227 self
->ignore_unmaps
--;
3229 XPutBackEvent(ob_display
, &ev
);
3237 gboolean
client_focus(ObClient
*self
)
3239 /* choose the correct target */
3240 self
= client_focus_target(self
);
3242 if (!client_can_focus(self
)) {
3243 if (!self
->frame
->visible
) {
3244 /* update the focus lists */
3245 focus_order_to_top(self
);
3250 ob_debug_type(OB_DEBUG_FOCUS
,
3251 "Focusing client \"%s\" at time %u\n",
3252 self
->title
, event_curtime
);
3254 if (self
->can_focus
) {
3255 /* This can cause a BadMatch error with CurrentTime, or if an app
3256 passed in a bad time for _NET_WM_ACTIVE_WINDOW. */
3257 xerror_set_ignore(TRUE
);
3258 XSetInputFocus(ob_display
, self
->window
, RevertToPointerRoot
,
3260 xerror_set_ignore(FALSE
);
3263 if (self
->focus_notify
) {
3265 ce
.xclient
.type
= ClientMessage
;
3266 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
3267 ce
.xclient
.display
= ob_display
;
3268 ce
.xclient
.window
= self
->window
;
3269 ce
.xclient
.format
= 32;
3270 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_take_focus
;
3271 ce
.xclient
.data
.l
[1] = event_curtime
;
3272 ce
.xclient
.data
.l
[2] = 0l;
3273 ce
.xclient
.data
.l
[3] = 0l;
3274 ce
.xclient
.data
.l
[4] = 0l;
3275 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
3279 ob_debug("%sively focusing %lx at %d\n",
3280 (self
->can_focus
? "act" : "pass"),
3281 self
->window
, (gint
) event_curtime
);
3284 /* Cause the FocusIn to come back to us. Important for desktop switches,
3285 since otherwise we'll have no FocusIn on the queue and send it off to
3286 the focus_backup. */
3287 XSync(ob_display
, FALSE
);
3291 /*! Present the client to the user.
3292 @param raise If the client should be raised or not. You should only set
3293 raise to false if you don't care if the window is completely
3296 static void client_present(ObClient
*self
, gboolean here
, gboolean raise
)
3298 /* if using focus_delay, stop the timer now so that focus doesn't
3300 event_halt_focus_delay();
3302 if (client_normal(self
) && screen_showing_desktop
)
3303 screen_show_desktop(FALSE
, FALSE
);
3305 client_iconify(self
, FALSE
, here
);
3306 if (self
->desktop
!= DESKTOP_ALL
&&
3307 self
->desktop
!= screen_desktop
)
3310 client_set_desktop(self
, screen_desktop
, FALSE
);
3312 screen_set_desktop(self
->desktop
, FALSE
);
3313 } else if (!self
->frame
->visible
)
3314 /* if its not visible for other reasons, then don't mess
3318 client_shade(self
, FALSE
);
3323 /* we do this as an action here. this is rather important. this is
3324 because we want the results from the focus change to take place
3325 BEFORE we go about raising the window. when a fullscreen window
3326 loses focus, we need this or else the raise wont be able to raise
3327 above the to-lose-focus fullscreen window. */
3332 void client_activate(ObClient
*self
, gboolean here
, gboolean user
)
3334 guint32 last_time
= focus_client
? focus_client
->user_time
: CurrentTime
;
3336 /* XXX do some stuff here if user is false to determine if we really want
3337 to activate it or not (a parent or group member is currently
3340 ob_debug_type(OB_DEBUG_FOCUS
,
3341 "Want to activate window 0x%x with time %u (last time %u), "
3343 self
->window
, event_curtime
, last_time
,
3344 (user
? "user" : "application"));
3346 if (!user
&& event_curtime
&& last_time
&&
3347 !event_time_after(event_curtime
, last_time
))
3349 client_hilite(self
, TRUE
);
3351 if (event_curtime
!= CurrentTime
)
3352 self
->user_time
= event_curtime
;
3354 client_present(self
, here
, TRUE
);
3358 void client_raise(ObClient
*self
)
3360 action_run_string("Raise", self
, CurrentTime
);
3363 void client_lower(ObClient
*self
)
3365 action_run_string("Lower", self
, CurrentTime
);
3368 gboolean
client_focused(ObClient
*self
)
3370 return self
== focus_client
;
3373 static ObClientIcon
* client_icon_recursive(ObClient
*self
, gint w
, gint h
)
3376 /* si is the smallest image >= req */
3377 /* li is the largest image < req */
3378 gulong size
, smallest
= 0xffffffff, largest
= 0, si
= 0, li
= 0;
3380 if (!self
->nicons
) {
3381 ObClientIcon
*parent
= NULL
;
3383 if (self
->transient_for
) {
3384 if (self
->transient_for
!= OB_TRAN_GROUP
)
3385 parent
= client_icon_recursive(self
->transient_for
, w
, h
);
3388 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
3389 ObClient
*c
= it
->data
;
3390 if (c
!= self
&& !c
->transient_for
) {
3391 if ((parent
= client_icon_recursive(c
, w
, h
)))
3401 for (i
= 0; i
< self
->nicons
; ++i
) {
3402 size
= self
->icons
[i
].width
* self
->icons
[i
].height
;
3403 if (size
< smallest
&& size
>= (unsigned)(w
* h
)) {
3407 if (size
> largest
&& size
<= (unsigned)(w
* h
)) {
3412 if (largest
== 0) /* didnt find one smaller than the requested size */
3413 return &self
->icons
[si
];
3414 return &self
->icons
[li
];
3417 const ObClientIcon
* client_icon(ObClient
*self
, gint w
, gint h
)
3420 static ObClientIcon deficon
;
3422 if (!(ret
= client_icon_recursive(self
, w
, h
))) {
3423 deficon
.width
= deficon
.height
= 48;
3424 deficon
.data
= ob_rr_theme
->def_win_icon
;
3430 void client_set_layer(ObClient
*self
, gint layer
)
3434 self
->above
= FALSE
;
3435 } else if (layer
== 0) {
3436 self
->below
= self
->above
= FALSE
;
3438 self
->below
= FALSE
;
3441 client_calc_layer(self
);
3442 client_change_state(self
); /* reflect this in the state hints */
3445 void client_set_undecorated(ObClient
*self
, gboolean undecorated
)
3447 if (self
->undecorated
!= undecorated
) {
3448 self
->undecorated
= undecorated
;
3449 client_setup_decor_and_functions(self
);
3450 /* Make sure the client knows it might have moved. Maybe there is a
3451 * better way of doing this so only one client_configure is sent, but
3452 * since 125 of these are sent per second when moving the window (with
3453 * user = FALSE) i doubt it matters much.
3455 client_configure(self
, self
->area
.x
, self
->area
.y
,
3456 self
->area
.width
, self
->area
.height
, TRUE
, TRUE
);
3457 client_change_state(self
); /* reflect this in the state hints */
3461 guint
client_monitor(ObClient
*self
)
3463 return screen_find_monitor(&self
->frame
->area
);
3466 ObClient
*client_search_top_normal_parent(ObClient
*self
)
3468 while (self
->transient_for
&& self
->transient_for
!= OB_TRAN_GROUP
&&
3469 client_normal(self
->transient_for
))
3470 self
= self
->transient_for
;
3474 static GSList
*client_search_all_top_parents_internal(ObClient
*self
,
3476 ObStackingLayer layer
)
3480 /* move up the direct transient chain as far as possible */
3481 while (self
->transient_for
&& self
->transient_for
!= OB_TRAN_GROUP
&&
3482 (!bylayer
|| self
->transient_for
->layer
== layer
) &&
3483 client_normal(self
->transient_for
))
3484 self
= self
->transient_for
;
3486 if (!self
->transient_for
)
3487 ret
= g_slist_prepend(ret
, self
);
3491 g_assert(self
->group
);
3493 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
3494 ObClient
*c
= it
->data
;
3496 if (!c
->transient_for
&& client_normal(c
) &&
3497 (!bylayer
|| c
->layer
== layer
))
3499 ret
= g_slist_prepend(ret
, c
);
3503 if (ret
== NULL
) /* no group parents */
3504 ret
= g_slist_prepend(ret
, self
);
3510 GSList
*client_search_all_top_parents(ObClient
*self
)
3512 return client_search_all_top_parents_internal(self
, FALSE
, 0);
3515 GSList
*client_search_all_top_parents_layer(ObClient
*self
)
3517 return client_search_all_top_parents_internal(self
, TRUE
, self
->layer
);
3520 ObClient
*client_search_focus_parent(ObClient
*self
)
3522 if (self
->transient_for
) {
3523 if (self
->transient_for
!= OB_TRAN_GROUP
) {
3524 if (client_focused(self
->transient_for
))
3525 return self
->transient_for
;
3529 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
3530 ObClient
*c
= it
->data
;
3532 /* checking transient_for prevents infinate loops! */
3533 if (c
!= self
&& !c
->transient_for
)
3534 if (client_focused(c
))
3543 ObClient
*client_search_parent(ObClient
*self
, ObClient
*search
)
3545 if (self
->transient_for
) {
3546 if (self
->transient_for
!= OB_TRAN_GROUP
) {
3547 if (self
->transient_for
== search
)
3552 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
3553 ObClient
*c
= it
->data
;
3555 /* checking transient_for prevents infinate loops! */
3556 if (c
!= self
&& !c
->transient_for
)
3566 ObClient
*client_search_transient(ObClient
*self
, ObClient
*search
)
3570 for (sit
= self
->transients
; sit
; sit
= g_slist_next(sit
)) {
3571 if (sit
->data
== search
)
3573 if (client_search_transient(sit
->data
, search
))
3579 void client_update_sm_client_id(ObClient
*self
)
3581 g_free(self
->sm_client_id
);
3582 self
->sm_client_id
= NULL
;
3584 if (!PROP_GETS(self
->window
, sm_client_id
, locale
, &self
->sm_client_id
))
3586 PROP_GETS(self
->group
->leader
, sm_client_id
, locale
,
3587 &self
->sm_client_id
);
3590 void client_update_command(ObClient
*self
)
3594 g_free(self
->wm_command
);
3595 self
->wm_command
= NULL
;
3597 if (PROP_GETSS(self
->window
, wm_command
, locale
, &data
)) {
3598 /* merge/mash them all together */
3599 gchar
*merge
= NULL
;
3602 for (i
= 0; data
[i
]; ++i
) {
3605 merge
= g_strconcat(merge
, data
[i
], NULL
);
3607 merge
= g_strconcat(data
[i
], NULL
);
3612 self
->wm_command
= merge
;
3616 #define WANT_EDGE(cur, c) \
3619 if(!client_normal(cur)) \
3621 if(screen_desktop != cur->desktop && cur->desktop != DESKTOP_ALL) \
3625 if(cur->layer < c->layer && !config_resist_layers_below) \
3628 #define HIT_EDGE(my_edge_start, my_edge_end, his_edge_start, his_edge_end) \
3629 if ((his_edge_start >= my_edge_start && \
3630 his_edge_start <= my_edge_end) || \
3631 (my_edge_start >= his_edge_start && \
3632 my_edge_start <= his_edge_end)) \
3635 /* finds the nearest edge in the given direction from the current client
3636 * note to self: the edge is the -frame- edge (the actual one), not the
3639 gint
client_directional_edge_search(ObClient
*c
, ObDirection dir
, gboolean hang
)
3641 gint dest
, monitor_dest
;
3642 gint my_edge_start
, my_edge_end
, my_offset
;
3649 a
= screen_area(c
->desktop
);
3650 monitor
= screen_area_monitor(c
->desktop
, client_monitor(c
));
3653 case OB_DIRECTION_NORTH
:
3654 my_edge_start
= c
->frame
->area
.x
;
3655 my_edge_end
= c
->frame
->area
.x
+ c
->frame
->area
.width
;
3656 my_offset
= c
->frame
->area
.y
+ (hang
? c
->frame
->area
.height
: 0);
3658 /* default: top of screen */
3659 dest
= a
->y
+ (hang
? c
->frame
->area
.height
: 0);
3660 monitor_dest
= monitor
->y
+ (hang
? c
->frame
->area
.height
: 0);
3661 /* if the monitor edge comes before the screen edge, */
3662 /* use that as the destination instead. (For xinerama) */
3663 if (monitor_dest
!= dest
&& my_offset
> monitor_dest
)
3664 dest
= monitor_dest
;
3666 for(it
= client_list
; it
&& my_offset
!= dest
; it
= g_list_next(it
)) {
3667 gint his_edge_start
, his_edge_end
, his_offset
;
3668 ObClient
*cur
= it
->data
;
3672 his_edge_start
= cur
->frame
->area
.x
;
3673 his_edge_end
= cur
->frame
->area
.x
+ cur
->frame
->area
.width
;
3674 his_offset
= cur
->frame
->area
.y
+
3675 (hang
? 0 : cur
->frame
->area
.height
);
3677 if(his_offset
+ 1 > my_offset
)
3680 if(his_offset
< dest
)
3683 HIT_EDGE(my_edge_start
, my_edge_end
, his_edge_start
, his_edge_end
)
3686 case OB_DIRECTION_SOUTH
:
3687 my_edge_start
= c
->frame
->area
.x
;
3688 my_edge_end
= c
->frame
->area
.x
+ c
->frame
->area
.width
;
3689 my_offset
= c
->frame
->area
.y
+ (hang
? 0 : c
->frame
->area
.height
);
3691 /* default: bottom of screen */
3692 dest
= a
->y
+ a
->height
- (hang
? c
->frame
->area
.height
: 0);
3693 monitor_dest
= monitor
->y
+ monitor
->height
-
3694 (hang
? c
->frame
->area
.height
: 0);
3695 /* if the monitor edge comes before the screen edge, */
3696 /* use that as the destination instead. (For xinerama) */
3697 if (monitor_dest
!= dest
&& my_offset
< monitor_dest
)
3698 dest
= monitor_dest
;
3700 for(it
= client_list
; it
&& my_offset
!= dest
; it
= g_list_next(it
)) {
3701 gint his_edge_start
, his_edge_end
, his_offset
;
3702 ObClient
*cur
= it
->data
;
3706 his_edge_start
= cur
->frame
->area
.x
;
3707 his_edge_end
= cur
->frame
->area
.x
+ cur
->frame
->area
.width
;
3708 his_offset
= cur
->frame
->area
.y
+
3709 (hang
? cur
->frame
->area
.height
: 0);
3712 if(his_offset
- 1 < my_offset
)
3715 if(his_offset
> dest
)
3718 HIT_EDGE(my_edge_start
, my_edge_end
, his_edge_start
, his_edge_end
)
3721 case OB_DIRECTION_WEST
:
3722 my_edge_start
= c
->frame
->area
.y
;
3723 my_edge_end
= c
->frame
->area
.y
+ c
->frame
->area
.height
;
3724 my_offset
= c
->frame
->area
.x
+ (hang
? c
->frame
->area
.width
: 0);
3726 /* default: leftmost egde of screen */
3727 dest
= a
->x
+ (hang
? c
->frame
->area
.width
: 0);
3728 monitor_dest
= monitor
->x
+ (hang
? c
->frame
->area
.width
: 0);
3729 /* if the monitor edge comes before the screen edge, */
3730 /* use that as the destination instead. (For xinerama) */
3731 if (monitor_dest
!= dest
&& my_offset
> monitor_dest
)
3732 dest
= monitor_dest
;
3734 for(it
= client_list
; it
&& my_offset
!= dest
; it
= g_list_next(it
)) {
3735 gint his_edge_start
, his_edge_end
, his_offset
;
3736 ObClient
*cur
= it
->data
;
3740 his_edge_start
= cur
->frame
->area
.y
;
3741 his_edge_end
= cur
->frame
->area
.y
+ cur
->frame
->area
.height
;
3742 his_offset
= cur
->frame
->area
.x
+
3743 (hang
? 0 : cur
->frame
->area
.width
);
3745 if(his_offset
+ 1 > my_offset
)
3748 if(his_offset
< dest
)
3751 HIT_EDGE(my_edge_start
, my_edge_end
, his_edge_start
, his_edge_end
)
3754 case OB_DIRECTION_EAST
:
3755 my_edge_start
= c
->frame
->area
.y
;
3756 my_edge_end
= c
->frame
->area
.y
+ c
->frame
->area
.height
;
3757 my_offset
= c
->frame
->area
.x
+ (hang
? 0 : c
->frame
->area
.width
);
3759 /* default: rightmost edge of screen */
3760 dest
= a
->x
+ a
->width
- (hang
? c
->frame
->area
.width
: 0);
3761 monitor_dest
= monitor
->x
+ monitor
->width
-
3762 (hang
? c
->frame
->area
.width
: 0);
3763 /* if the monitor edge comes before the screen edge, */
3764 /* use that as the destination instead. (For xinerama) */
3765 if (monitor_dest
!= dest
&& my_offset
< monitor_dest
)
3766 dest
= monitor_dest
;
3768 for(it
= client_list
; it
&& my_offset
!= dest
; it
= g_list_next(it
)) {
3769 gint his_edge_start
, his_edge_end
, his_offset
;
3770 ObClient
*cur
= it
->data
;
3774 his_edge_start
= cur
->frame
->area
.y
;
3775 his_edge_end
= cur
->frame
->area
.y
+ cur
->frame
->area
.height
;
3776 his_offset
= cur
->frame
->area
.x
+
3777 (hang
? cur
->frame
->area
.width
: 0);
3779 if(his_offset
- 1 < my_offset
)
3782 if(his_offset
> dest
)
3785 HIT_EDGE(my_edge_start
, my_edge_end
, his_edge_start
, his_edge_end
)
3788 case OB_DIRECTION_NORTHEAST
:
3789 case OB_DIRECTION_SOUTHEAST
:
3790 case OB_DIRECTION_NORTHWEST
:
3791 case OB_DIRECTION_SOUTHWEST
:
3792 /* not implemented */
3794 g_assert_not_reached();
3795 dest
= 0; /* suppress warning */
3800 ObClient
* client_under_pointer()
3804 ObClient
*ret
= NULL
;
3806 if (screen_pointer_pos(&x
, &y
)) {
3807 for (it
= stacking_list
; it
; it
= g_list_next(it
)) {
3808 if (WINDOW_IS_CLIENT(it
->data
)) {
3809 ObClient
*c
= WINDOW_AS_CLIENT(it
->data
);
3810 if (c
->frame
->visible
&&
3811 /* ignore all animating windows */
3812 !frame_iconify_animating(c
->frame
) &&
3813 RECT_CONTAINS(c
->frame
->area
, x
, y
))
3824 gboolean
client_has_group_siblings(ObClient
*self
)
3826 return self
->group
&& self
->group
->members
->next
;
3829 gboolean
client_has_application_group_siblings(ObClient
*self
)
3833 if (!self
->group
) return FALSE
;
3835 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
3836 ObClient
*c
= it
->data
;
3837 if (c
!= self
&& client_application(c
))