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 ObClientCallback 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_session_ids(ObClient
*self
);
72 static void client_get_area(ObClient
*self
);
73 static void client_get_desktop(ObClient
*self
);
74 static void client_get_state(ObClient
*self
);
75 static void client_get_layer(ObClient
*self
);
76 static void client_get_shaped(ObClient
*self
);
77 static void client_get_mwm_hints(ObClient
*self
);
78 static void client_get_gravity(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(ObClientCallback func
, gpointer data
)
110 ClientCallback
*d
= g_new(ClientCallback
, 1);
113 client_destructors
= g_slist_prepend(client_destructors
, d
);
116 void client_remove_destructor(ObClientCallback func
)
120 for (it
= client_destructors
; it
; it
= g_slist_next(it
)) {
121 ClientCallback
*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 ClientCallback
*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
) {
677 if (settings
->desktop
== DESKTOP_ALL
)
678 self
->desktop
= settings
->desktop
;
679 else if (settings
->desktop
> 0 &&
680 settings
->desktop
<= screen_num_desktops
)
681 self
->desktop
= settings
->desktop
- 1;
684 if (settings
->layer
== -1) {
688 else if (settings
->layer
== 0) {
692 else if (settings
->layer
== 1) {
700 static void client_restore_session_state(ObClient
*self
)
704 ob_debug_type(OB_DEBUG_SM
,
705 "Restore session for client %s\n", self
->title
);
707 if (!(it
= session_state_find(self
))) {
708 ob_debug_type(OB_DEBUG_SM
,
709 "Session data not found for client %s\n", self
->title
);
713 self
->session
= it
->data
;
715 ob_debug_type(OB_DEBUG_SM
, "Session data loaded for client %s\n",
718 RECT_SET_POINT(self
->area
, self
->session
->x
, self
->session
->y
);
719 self
->positioned
= USPosition
;
720 if (self
->session
->w
> 0)
721 self
->area
.width
= self
->session
->w
;
722 if (self
->session
->h
> 0)
723 self
->area
.height
= self
->session
->h
;
724 XResizeWindow(ob_display
, self
->window
,
725 self
->area
.width
, self
->area
.height
);
727 self
->desktop
= (self
->session
->desktop
== DESKTOP_ALL
?
728 self
->session
->desktop
:
729 MIN(screen_num_desktops
- 1, self
->session
->desktop
));
730 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, self
->desktop
);
732 self
->shaded
= self
->session
->shaded
;
733 self
->iconic
= self
->session
->iconic
;
734 self
->skip_pager
= self
->session
->skip_pager
;
735 self
->skip_taskbar
= self
->session
->skip_taskbar
;
736 self
->fullscreen
= self
->session
->fullscreen
;
737 self
->above
= self
->session
->above
;
738 self
->below
= self
->session
->below
;
739 self
->max_horz
= self
->session
->max_horz
;
740 self
->max_vert
= self
->session
->max_vert
;
741 self
->undecorated
= self
->session
->undecorated
;
744 static gboolean
client_restore_session_stacking(ObClient
*self
)
748 if (!self
->session
) return FALSE
;
750 mypos
= g_list_find(session_saved_state
, self
->session
);
751 if (!mypos
) return FALSE
;
753 /* start above me and look for the first client */
754 for (it
= g_list_previous(mypos
); it
; it
= g_list_previous(it
)) {
757 for (cit
= client_list
; cit
; cit
= g_list_next(cit
)) {
758 ObClient
*c
= cit
->data
;
759 /* found a client that was in the session, so go below it */
760 if (c
->session
== it
->data
) {
761 stacking_below(CLIENT_AS_WINDOW(self
),
762 CLIENT_AS_WINDOW(cit
->data
));
770 void client_move_onscreen(ObClient
*self
, gboolean rude
)
772 gint x
= self
->area
.x
;
773 gint y
= self
->area
.y
;
774 if (client_find_onscreen(self
, &x
, &y
,
776 self
->area
.height
, rude
)) {
777 client_move(self
, x
, y
);
781 gboolean
client_find_onscreen(ObClient
*self
, gint
*x
, gint
*y
, gint w
, gint h
,
785 gint ox
= *x
, oy
= *y
;
786 gboolean rudel
= rude
, ruder
= rude
, rudet
= rude
, rudeb
= rude
;
789 all_a
= screen_area(self
->desktop
);
790 mon_a
= screen_area_monitor(self
->desktop
, client_monitor(self
));
792 /* get where the frame would be */
793 frame_client_gravity(self
->frame
, x
, y
, w
, h
);
795 /* get the requested size of the window with decorations */
796 fw
= self
->frame
->size
.left
+ w
+ self
->frame
->size
.right
;
797 fh
= self
->frame
->size
.top
+ h
+ self
->frame
->size
.bottom
;
799 /* This makes sure windows aren't entirely outside of the screen so you
800 can't see them at all.
801 It makes sure 10% of the window is on the screen at least. At don't let
802 it move itself off the top of the screen, which would hide the titlebar
803 on you. (The user can still do this if they want too, it's only limiting
806 XXX watch for xinerama dead areas...
808 if (client_normal(self
)) {
809 if (!self
->strut
.right
&& *x
+ fw
/10 >= all_a
->x
+ all_a
->width
- 1)
810 *x
= all_a
->x
+ all_a
->width
- fw
/10;
811 if (!self
->strut
.bottom
&& *y
+ fh
/10 >= all_a
->y
+ all_a
->height
- 1)
812 *y
= all_a
->y
+ all_a
->height
- fh
/10;
813 if (!self
->strut
.left
&& *x
+ fw
*9/10 - 1 < all_a
->x
)
814 *x
= all_a
->x
- fw
*9/10;
815 if (!self
->strut
.top
&& *y
+ fh
*9/10 - 1 < all_a
->y
)
816 *y
= all_a
->y
- fw
*9/10;
819 /* If rudeness wasn't requested, then figure out of the client is currently
820 entirely on the screen. If it is, and the position isn't changing by
821 request, and it is enlarging, then be rude even though it wasn't
824 Point oldtl
, oldtr
, oldbl
, oldbr
;
825 Point newtl
, newtr
, newbl
, newbr
;
826 gboolean stationary_l
, stationary_r
, stationary_t
, stationary_b
;
828 POINT_SET(oldtl
, self
->frame
->area
.x
, self
->frame
->area
.y
);
829 POINT_SET(oldbr
, self
->frame
->area
.x
+ self
->frame
->area
.width
- 1,
830 self
->frame
->area
.y
+ self
->frame
->area
.height
- 1);
831 POINT_SET(oldtr
, oldbr
.x
, oldtl
.y
);
832 POINT_SET(oldbl
, oldtl
.x
, oldbr
.y
);
834 POINT_SET(newtl
, *x
, *y
);
835 POINT_SET(newbr
, *x
+ fw
- 1, *y
+ fh
- 1);
836 POINT_SET(newtr
, newbr
.x
, newtl
.y
);
837 POINT_SET(newbl
, newtl
.x
, newbr
.y
);
839 /* is it moving or just resizing from some corner? */
840 stationary_l
= oldtl
.x
== oldtl
.x
;
841 stationary_r
= oldtr
.x
== oldtr
.x
;
842 stationary_t
= oldtl
.y
== oldtl
.y
;
843 stationary_b
= oldbl
.y
== oldbl
.y
;
845 /* if left edge is growing and didnt move right edge */
846 if (stationary_r
&& newtl
.x
< oldtl
.x
)
848 /* if right edge is growing and didnt move left edge */
849 if (stationary_l
&& newtr
.x
> oldtr
.x
)
851 /* if top edge is growing and didnt move bottom edge */
852 if (stationary_b
&& newtl
.y
< oldtl
.y
)
854 /* if bottom edge is growing and didnt move top edge */
855 if (stationary_t
&& newbl
.y
> oldbl
.y
)
859 /* This here doesn't let windows even a pixel outside the struts/screen.
860 * When called from client_manage, programs placing themselves are
861 * forced completely onscreen, while things like
862 * xterm -geometry resolution-width/2 will work fine. Trying to
863 * place it completely offscreen will be handled in the above code.
864 * Sorry for this confused comment, i am tired. */
865 if (fw
<= mon_a
->width
) {
866 if (rudel
&& !self
->strut
.left
&& *x
< mon_a
->x
) *x
= mon_a
->x
;
867 if (ruder
&& !self
->strut
.right
&& *x
+ fw
> mon_a
->x
+ mon_a
->width
)
868 *x
= mon_a
->x
+ mon_a
->width
- fw
;
870 if (fh
<= mon_a
->height
) {
871 if (rudet
&& !self
->strut
.top
&& *y
< mon_a
->y
) *y
= mon_a
->y
;
872 if (rudeb
&& !self
->strut
.bottom
&& *y
+ fh
> mon_a
->y
+ mon_a
->height
)
873 *y
= mon_a
->y
+ mon_a
->height
- fh
;
876 /* get where the client should be */
877 frame_frame_gravity(self
->frame
, x
, y
, w
, h
);
879 return ox
!= *x
|| oy
!= *y
;
882 static void client_toggle_border(ObClient
*self
, gboolean show
)
884 /* adjust our idea of where the client is, based on its border. When the
885 border is removed, the client should now be considered to be in a
887 when re-adding the border to the client, the same operation needs to be
889 gint oldx
= self
->area
.x
, oldy
= self
->area
.y
;
890 gint x
= oldx
, y
= oldy
;
891 switch(self
->gravity
) {
893 case NorthWestGravity
:
895 case SouthWestGravity
:
897 case NorthEastGravity
:
899 case SouthEastGravity
:
900 if (show
) x
-= self
->border_width
* 2;
901 else x
+= self
->border_width
* 2;
908 if (show
) x
-= self
->border_width
;
909 else x
+= self
->border_width
;
912 switch(self
->gravity
) {
914 case NorthWestGravity
:
916 case NorthEastGravity
:
918 case SouthWestGravity
:
920 case SouthEastGravity
:
921 if (show
) y
-= self
->border_width
* 2;
922 else y
+= self
->border_width
* 2;
929 if (show
) y
-= self
->border_width
;
930 else y
+= self
->border_width
;
937 XSetWindowBorderWidth(ob_display
, self
->window
, self
->border_width
);
939 /* set border_width to 0 because there is no border to add into
940 calculations anymore */
941 self
->border_width
= 0;
943 XSetWindowBorderWidth(ob_display
, self
->window
, 0);
947 static void client_get_all(ObClient
*self
)
949 client_get_area(self
);
950 client_get_mwm_hints(self
);
952 /* The transient-ness of a window is used to pick a type, but the type can
953 also affect transiency.
955 Dialogs are always made transients for their group if they have one.
957 I also have made non-application type windows be transients for their
958 group (eg utility windows).
960 client_get_transientness(self
);
961 client_get_type(self
);/* this can change the mwmhints for special cases */
962 client_get_state(self
);
964 client_update_wmhints(self
);
965 /* this may have already been called from client_update_wmhints */
966 if (self
->transient_for
== NULL
)
967 client_update_transient_for(self
);
968 client_get_startup_id(self
);
969 client_get_desktop(self
);/* uses transient data/group/startup id if a
970 desktop is not specified */
971 client_get_shaped(self
);
973 client_get_layer(self
); /* if layer hasn't been specified, get it from
974 other sources if possible */
977 /* a couple type-based defaults for new windows */
979 /* this makes sure that these windows appear on all desktops */
980 if (self
->type
== OB_CLIENT_TYPE_DESKTOP
)
981 self
->desktop
= DESKTOP_ALL
;
984 client_update_protocols(self
);
986 client_get_gravity(self
); /* get the attribute gravity */
987 client_update_normal_hints(self
); /* this may override the attribute
990 /* got the type, the mwmhints, the protocols, and the normal hints
991 (min/max sizes), so we're ready to set up the decorations/functions */
992 client_setup_decor_and_functions(self
);
995 client_update_sync_request_counter(self
);
998 /* get the session related properties */
999 client_get_session_ids(self
);
1001 client_get_colormap(self
);
1002 client_update_title(self
);
1003 client_update_strut(self
);
1004 client_update_icons(self
);
1005 client_update_user_time(self
);
1006 client_update_icon_geometry(self
);
1009 static void client_get_startup_id(ObClient
*self
)
1011 if (!(PROP_GETS(self
->window
, net_startup_id
, utf8
, &self
->startup_id
)))
1013 PROP_GETS(self
->group
->leader
,
1014 net_startup_id
, utf8
, &self
->startup_id
);
1017 static void client_get_area(ObClient
*self
)
1019 XWindowAttributes wattrib
;
1022 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
1023 g_assert(ret
!= BadWindow
);
1025 RECT_SET(self
->area
, wattrib
.x
, wattrib
.y
, wattrib
.width
, wattrib
.height
);
1026 POINT_SET(self
->root_pos
, wattrib
.x
, wattrib
.y
);
1027 self
->border_width
= wattrib
.border_width
;
1029 ob_debug("client area: %d %d %d %d\n", wattrib
.x
, wattrib
.y
,
1030 wattrib
.width
, wattrib
.height
);
1033 static void client_get_desktop(ObClient
*self
)
1035 guint32 d
= screen_num_desktops
; /* an always-invalid value */
1037 if (PROP_GET32(self
->window
, net_wm_desktop
, cardinal
, &d
)) {
1038 if (d
>= screen_num_desktops
&& d
!= DESKTOP_ALL
)
1039 self
->desktop
= screen_num_desktops
- 1;
1043 gboolean trdesk
= FALSE
;
1045 if (self
->transient_for
) {
1046 if (self
->transient_for
!= OB_TRAN_GROUP
) {
1047 self
->desktop
= self
->transient_for
->desktop
;
1052 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
))
1053 if (it
->data
!= self
&&
1054 !((ObClient
*)it
->data
)->transient_for
) {
1055 self
->desktop
= ((ObClient
*)it
->data
)->desktop
;
1062 /* try get from the startup-notification protocol */
1063 if (sn_get_desktop(self
->startup_id
, &self
->desktop
)) {
1064 if (self
->desktop
>= screen_num_desktops
&&
1065 self
->desktop
!= DESKTOP_ALL
)
1066 self
->desktop
= screen_num_desktops
- 1;
1068 /* defaults to the current desktop */
1069 self
->desktop
= screen_desktop
;
1074 static void client_get_layer(ObClient
*self
)
1076 if (!(self
->above
|| self
->below
)) {
1078 /* apply stuff from the group */
1082 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
1083 ObClient
*c
= it
->data
;
1084 if (c
!= self
&& !client_search_transient(self
, c
) &&
1085 client_normal(self
) && client_normal(c
))
1088 (c
->above
? 1 : (c
->below
? -1 : 0)));
1102 g_assert_not_reached();
1109 static void client_get_state(ObClient
*self
)
1114 if (PROP_GETA32(self
->window
, net_wm_state
, atom
, &state
, &num
)) {
1116 for (i
= 0; i
< num
; ++i
) {
1117 if (state
[i
] == prop_atoms
.net_wm_state_modal
)
1119 else if (state
[i
] == prop_atoms
.net_wm_state_shaded
)
1120 self
->shaded
= TRUE
;
1121 else if (state
[i
] == prop_atoms
.net_wm_state_hidden
)
1122 self
->iconic
= TRUE
;
1123 else if (state
[i
] == prop_atoms
.net_wm_state_skip_taskbar
)
1124 self
->skip_taskbar
= TRUE
;
1125 else if (state
[i
] == prop_atoms
.net_wm_state_skip_pager
)
1126 self
->skip_pager
= TRUE
;
1127 else if (state
[i
] == prop_atoms
.net_wm_state_fullscreen
)
1128 self
->fullscreen
= TRUE
;
1129 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_vert
)
1130 self
->max_vert
= TRUE
;
1131 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_horz
)
1132 self
->max_horz
= TRUE
;
1133 else if (state
[i
] == prop_atoms
.net_wm_state_above
)
1135 else if (state
[i
] == prop_atoms
.net_wm_state_below
)
1137 else if (state
[i
] == prop_atoms
.net_wm_state_demands_attention
)
1138 self
->demands_attention
= TRUE
;
1139 else if (state
[i
] == prop_atoms
.openbox_wm_state_undecorated
)
1140 self
->undecorated
= TRUE
;
1147 static void client_get_shaped(ObClient
*self
)
1149 self
->shaped
= FALSE
;
1151 if (extensions_shape
) {
1156 XShapeSelectInput(ob_display
, self
->window
, ShapeNotifyMask
);
1158 XShapeQueryExtents(ob_display
, self
->window
, &s
, &foo
,
1159 &foo
, &ufoo
, &ufoo
, &foo
, &foo
, &foo
, &ufoo
,
1161 self
->shaped
= (s
!= 0);
1166 void client_get_transientness(ObClient
*self
)
1169 if (XGetTransientForHint(ob_display
, self
->window
, &t
))
1170 self
->transient
= TRUE
;
1173 void client_update_transient_for(ObClient
*self
)
1176 ObClient
*target
= NULL
;
1178 if (XGetTransientForHint(ob_display
, self
->window
, &t
)) {
1179 self
->transient
= TRUE
;
1180 if (t
!= self
->window
) { /* cant be transient to itself! */
1181 target
= g_hash_table_lookup(window_map
, &t
);
1182 /* if this happens then we need to check for it*/
1183 g_assert(target
!= self
);
1184 if (target
&& !WINDOW_IS_CLIENT(target
)) {
1185 /* this can happen when a dialog is a child of
1186 a dockapp, for example */
1190 /* THIS IS SO ANNOYING ! ! ! ! Let me explain.... have a seat..
1192 Setting the transient_for to Root is actually illegal, however
1193 applications from time have done this to specify transient for
1196 Now you can do that by being a TYPE_DIALOG and not setting
1197 the transient_for hint at all on your window. But people still
1198 use Root, and Kwin is very strange in this regard.
1200 KWin 3.0 will not consider windows with transient_for set to
1201 Root as transient for their group *UNLESS* they are also modal.
1202 In that case, it will make them transient for the group. This
1203 leads to all sorts of weird behavior from KDE apps which are
1204 only tested in KWin. I'd like to follow their behavior just to
1205 make this work right with KDE stuff, but that seems wrong.
1207 if (!target
&& self
->group
) {
1208 /* not transient to a client, see if it is transient for a
1210 if (t
== RootWindow(ob_display
, ob_screen
)) {
1211 /* window is a transient for its group! */
1212 target
= OB_TRAN_GROUP
;
1216 } else if (self
->type
== OB_CLIENT_TYPE_DIALOG
||
1217 self
->type
== OB_CLIENT_TYPE_TOOLBAR
||
1218 self
->type
== OB_CLIENT_TYPE_MENU
||
1219 self
->type
== OB_CLIENT_TYPE_UTILITY
)
1221 self
->transient
= TRUE
;
1223 target
= OB_TRAN_GROUP
;
1225 self
->transient
= FALSE
;
1227 client_update_transient_tree(self
, self
->group
, self
->group
,
1228 self
->transient_for
, target
);
1229 self
->transient_for
= target
;
1233 static void client_update_transient_tree(ObClient
*self
,
1234 ObGroup
*oldgroup
, ObGroup
*newgroup
,
1235 ObClient
* oldparent
,
1236 ObClient
*newparent
)
1241 /* No change has occured */
1242 if (oldgroup
== newgroup
&& oldparent
== newparent
) return;
1244 /** Remove the client from the transient tree wherever it has changed **/
1246 /* If the window is becoming a direct transient for a window in its group
1247 then that window can't be a child of this window anymore */
1248 if (oldparent
!= newparent
&&
1249 newparent
!= NULL
&& newparent
!= OB_TRAN_GROUP
&&
1250 newparent
->transient_for
== OB_TRAN_GROUP
&&
1251 newgroup
!= NULL
&& newgroup
== oldgroup
)
1253 self
->transients
= g_slist_remove(self
->transients
, newparent
);
1257 /* If the group changed, or if we are just becoming transient for the
1258 group, then we need to remove any old group transient windows
1259 from our children. But if we were already transient for the group, then
1260 other group transients are not our children. */
1261 if ((oldgroup
!= newgroup
||
1262 (newparent
== OB_TRAN_GROUP
&& oldparent
!= newparent
)) &&
1263 oldgroup
!= NULL
&& oldparent
!= OB_TRAN_GROUP
)
1265 for (it
= self
->transients
; it
; it
= next
) {
1266 next
= g_slist_next(it
);
1268 if (c
->group
== oldgroup
)
1269 self
->transients
= g_slist_delete_link(self
->transients
, it
);
1273 /* If we used to be transient for a group and now we are not, or we're
1274 transient for a new group, then we need to remove ourselves from all
1276 if (oldparent
== OB_TRAN_GROUP
&& (oldgroup
!= newgroup
||
1277 oldparent
!= newparent
))
1279 for (it
= oldgroup
->members
; it
; it
= g_slist_next(it
)) {
1281 if (c
!= self
&& (!c
->transient_for
||
1282 c
->transient_for
!= OB_TRAN_GROUP
))
1283 c
->transients
= g_slist_remove(c
->transients
, self
);
1286 /* If we used to be transient for a single window and we are no longer
1287 transient for it, then we need to remove ourself from its children */
1288 else if (oldparent
!= NULL
&& oldparent
!= OB_TRAN_GROUP
&&
1289 oldparent
!= newparent
)
1290 oldparent
->transients
= g_slist_remove(oldparent
->transients
, self
);
1293 /** Re-add the client to the transient tree wherever it has changed **/
1295 /* If we're now transient for a group and we weren't transient for it
1296 before then we need to add ourselves to all our new parents */
1297 if (newparent
== OB_TRAN_GROUP
&& (oldgroup
!= newgroup
||
1298 oldparent
!= newparent
))
1300 for (it
= oldgroup
->members
; it
; it
= g_slist_next(it
)) {
1302 if (c
!= self
&& (!c
->transient_for
||
1303 c
->transient_for
!= OB_TRAN_GROUP
))
1304 c
->transients
= g_slist_prepend(c
->transients
, self
);
1307 /* If we are now transient for a single window which we weren't before,
1308 we need to add ourselves to its children
1310 WARNING: Cyclical transient ness is possible if two windows are
1311 transient for eachother.
1313 else if (newparent
!= NULL
&& newparent
!= OB_TRAN_GROUP
&&
1314 newparent
!= oldparent
&&
1315 /* don't make ourself its child if it is already our child */
1316 !client_is_direct_child(self
, newparent
))
1317 newparent
->transients
= g_slist_prepend(newparent
->transients
, self
);
1319 /* If the group changed then we need to add any new group transient
1320 windows to our children. But if we're transient for the group, then
1321 other group transients are not our children.
1323 WARNING: Cyclical transient-ness is possible. For e.g. if:
1324 A is transient for the group
1325 B is a member of the group and transient for A
1327 if (oldgroup
!= newgroup
&& newgroup
!= NULL
&&
1328 newparent
!= OB_TRAN_GROUP
)
1330 for (it
= newgroup
->members
; it
; it
= g_slist_next(it
)) {
1332 if (c
!= self
&& c
->transient_for
== OB_TRAN_GROUP
&&
1333 /* Don't make it our child if it is already our parent */
1334 !client_is_direct_child(c
, self
))
1336 self
->transients
= g_slist_prepend(self
->transients
, c
);
1342 static void client_get_mwm_hints(ObClient
*self
)
1347 self
->mwmhints
.flags
= 0; /* default to none */
1349 if (PROP_GETA32(self
->window
, motif_wm_hints
, motif_wm_hints
,
1351 if (num
>= OB_MWM_ELEMENTS
) {
1352 self
->mwmhints
.flags
= hints
[0];
1353 self
->mwmhints
.functions
= hints
[1];
1354 self
->mwmhints
.decorations
= hints
[2];
1360 void client_get_type(ObClient
*self
)
1367 if (PROP_GETA32(self
->window
, net_wm_window_type
, atom
, &val
, &num
)) {
1368 /* use the first value that we know about in the array */
1369 for (i
= 0; i
< num
; ++i
) {
1370 if (val
[i
] == prop_atoms
.net_wm_window_type_desktop
)
1371 self
->type
= OB_CLIENT_TYPE_DESKTOP
;
1372 else if (val
[i
] == prop_atoms
.net_wm_window_type_dock
)
1373 self
->type
= OB_CLIENT_TYPE_DOCK
;
1374 else if (val
[i
] == prop_atoms
.net_wm_window_type_toolbar
)
1375 self
->type
= OB_CLIENT_TYPE_TOOLBAR
;
1376 else if (val
[i
] == prop_atoms
.net_wm_window_type_menu
)
1377 self
->type
= OB_CLIENT_TYPE_MENU
;
1378 else if (val
[i
] == prop_atoms
.net_wm_window_type_utility
)
1379 self
->type
= OB_CLIENT_TYPE_UTILITY
;
1380 else if (val
[i
] == prop_atoms
.net_wm_window_type_splash
)
1381 self
->type
= OB_CLIENT_TYPE_SPLASH
;
1382 else if (val
[i
] == prop_atoms
.net_wm_window_type_dialog
)
1383 self
->type
= OB_CLIENT_TYPE_DIALOG
;
1384 else if (val
[i
] == prop_atoms
.net_wm_window_type_normal
)
1385 self
->type
= OB_CLIENT_TYPE_NORMAL
;
1386 else if (val
[i
] == prop_atoms
.kde_net_wm_window_type_override
) {
1387 /* prevent this window from getting any decor or
1389 self
->mwmhints
.flags
&= (OB_MWM_FLAG_FUNCTIONS
|
1390 OB_MWM_FLAG_DECORATIONS
);
1391 self
->mwmhints
.decorations
= 0;
1392 self
->mwmhints
.functions
= 0;
1394 if (self
->type
!= (ObClientType
) -1)
1395 break; /* grab the first legit type */
1400 if (self
->type
== (ObClientType
) -1) {
1401 /*the window type hint was not set, which means we either classify
1402 ourself as a normal window or a dialog, depending on if we are a
1404 if (self
->transient
)
1405 self
->type
= OB_CLIENT_TYPE_DIALOG
;
1407 self
->type
= OB_CLIENT_TYPE_NORMAL
;
1411 void client_update_protocols(ObClient
*self
)
1414 guint num_return
, i
;
1416 self
->focus_notify
= FALSE
;
1417 self
->delete_window
= FALSE
;
1419 if (PROP_GETA32(self
->window
, wm_protocols
, atom
, &proto
, &num_return
)) {
1420 for (i
= 0; i
< num_return
; ++i
) {
1421 if (proto
[i
] == prop_atoms
.wm_delete_window
)
1422 /* this means we can request the window to close */
1423 self
->delete_window
= TRUE
;
1424 else if (proto
[i
] == prop_atoms
.wm_take_focus
)
1425 /* if this protocol is requested, then the window will be
1426 notified whenever we want it to receive focus */
1427 self
->focus_notify
= TRUE
;
1429 else if (proto
[i
] == prop_atoms
.net_wm_sync_request
)
1430 /* if this protocol is requested, then resizing the
1431 window will be synchronized between the frame and the
1433 self
->sync_request
= TRUE
;
1441 void client_update_sync_request_counter(ObClient
*self
)
1445 if (PROP_GET32(self
->window
, net_wm_sync_request_counter
, cardinal
, &i
)) {
1446 self
->sync_counter
= i
;
1448 self
->sync_counter
= None
;
1452 static void client_get_gravity(ObClient
*self
)
1454 XWindowAttributes wattrib
;
1457 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
1458 g_assert(ret
!= BadWindow
);
1459 self
->gravity
= wattrib
.win_gravity
;
1462 void client_get_colormap(ObClient
*self
)
1464 XWindowAttributes wa
;
1466 if (XGetWindowAttributes(ob_display
, self
->window
, &wa
))
1467 client_update_colormap(self
, wa
.colormap
);
1470 void client_update_colormap(ObClient
*self
, Colormap colormap
)
1472 self
->colormap
= colormap
;
1475 void client_update_normal_hints(ObClient
*self
)
1479 gint oldgravity
= self
->gravity
;
1482 self
->min_ratio
= 0.0f
;
1483 self
->max_ratio
= 0.0f
;
1484 SIZE_SET(self
->size_inc
, 1, 1);
1485 SIZE_SET(self
->base_size
, 0, 0);
1486 SIZE_SET(self
->min_size
, 0, 0);
1487 SIZE_SET(self
->max_size
, G_MAXINT
, G_MAXINT
);
1489 /* get the hints from the window */
1490 if (XGetWMNormalHints(ob_display
, self
->window
, &size
, &ret
)) {
1491 /* normal windows can't request placement! har har
1492 if (!client_normal(self))
1494 self
->positioned
= (size
.flags
& (PPosition
|USPosition
));
1496 if (size
.flags
& PWinGravity
) {
1497 self
->gravity
= size
.win_gravity
;
1499 /* if the client has a frame, i.e. has already been mapped and
1500 is changing its gravity */
1501 if (self
->frame
&& self
->gravity
!= oldgravity
) {
1502 /* move our idea of the client's position based on its new
1504 client_convert_gravity(self
, oldgravity
,
1505 &self
->area
.x
, &self
->area
.y
,
1506 self
->area
.width
, self
->area
.height
);
1510 if (size
.flags
& PAspect
) {
1511 if (size
.min_aspect
.y
)
1513 (gfloat
) size
.min_aspect
.x
/ size
.min_aspect
.y
;
1514 if (size
.max_aspect
.y
)
1516 (gfloat
) size
.max_aspect
.x
/ size
.max_aspect
.y
;
1519 if (size
.flags
& PMinSize
)
1520 SIZE_SET(self
->min_size
, size
.min_width
, size
.min_height
);
1522 if (size
.flags
& PMaxSize
)
1523 SIZE_SET(self
->max_size
, size
.max_width
, size
.max_height
);
1525 if (size
.flags
& PBaseSize
)
1526 SIZE_SET(self
->base_size
, size
.base_width
, size
.base_height
);
1528 if (size
.flags
& PResizeInc
&& size
.width_inc
&& size
.height_inc
)
1529 SIZE_SET(self
->size_inc
, size
.width_inc
, size
.height_inc
);
1533 void client_setup_decor_and_functions(ObClient
*self
)
1535 /* start with everything (cept fullscreen) */
1537 (OB_FRAME_DECOR_TITLEBAR
|
1538 OB_FRAME_DECOR_HANDLE
|
1539 OB_FRAME_DECOR_GRIPS
|
1540 OB_FRAME_DECOR_BORDER
|
1541 OB_FRAME_DECOR_ICON
|
1542 OB_FRAME_DECOR_ALLDESKTOPS
|
1543 OB_FRAME_DECOR_ICONIFY
|
1544 OB_FRAME_DECOR_MAXIMIZE
|
1545 OB_FRAME_DECOR_SHADE
|
1546 OB_FRAME_DECOR_CLOSE
);
1548 (OB_CLIENT_FUNC_RESIZE
|
1549 OB_CLIENT_FUNC_MOVE
|
1550 OB_CLIENT_FUNC_ICONIFY
|
1551 OB_CLIENT_FUNC_MAXIMIZE
|
1552 OB_CLIENT_FUNC_SHADE
|
1553 OB_CLIENT_FUNC_CLOSE
);
1555 if (!(self
->min_size
.width
< self
->max_size
.width
||
1556 self
->min_size
.height
< self
->max_size
.height
))
1557 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
1559 switch (self
->type
) {
1560 case OB_CLIENT_TYPE_NORMAL
:
1561 /* normal windows retain all of the possible decorations and
1562 functionality, and are the only windows that you can fullscreen */
1563 self
->functions
|= OB_CLIENT_FUNC_FULLSCREEN
;
1566 case OB_CLIENT_TYPE_DIALOG
:
1567 case OB_CLIENT_TYPE_UTILITY
:
1568 /* these windows cannot be maximized */
1569 self
->functions
&= ~OB_CLIENT_FUNC_MAXIMIZE
;
1572 case OB_CLIENT_TYPE_MENU
:
1573 case OB_CLIENT_TYPE_TOOLBAR
:
1574 /* these windows get less functionality */
1575 self
->functions
&= ~(OB_CLIENT_FUNC_ICONIFY
| OB_CLIENT_FUNC_RESIZE
);
1578 case OB_CLIENT_TYPE_SPLASH
:
1579 /* these don't get get any decorations, and the only thing you can
1580 do with them is move them */
1581 self
->decorations
= 0;
1582 self
->functions
= OB_CLIENT_FUNC_MOVE
;
1584 case OB_CLIENT_TYPE_DESKTOP
:
1585 case OB_CLIENT_TYPE_DOCK
:
1586 /* these windows are not manipulated by the window manager */
1587 self
->decorations
= 0;
1588 self
->functions
= 0;
1592 /* Mwm Hints are applied subtractively to what has already been chosen for
1593 decor and functionality */
1594 if (self
->mwmhints
.flags
& OB_MWM_FLAG_DECORATIONS
) {
1595 if (! (self
->mwmhints
.decorations
& OB_MWM_DECOR_ALL
)) {
1596 if (! ((self
->mwmhints
.decorations
& OB_MWM_DECOR_HANDLE
) ||
1597 (self
->mwmhints
.decorations
& OB_MWM_DECOR_TITLE
)))
1599 /* if the mwm hints request no handle or title, then all
1600 decorations are disabled, but keep the border if that's
1602 if (self
->mwmhints
.decorations
& OB_MWM_DECOR_BORDER
)
1603 self
->decorations
= OB_FRAME_DECOR_BORDER
;
1605 self
->decorations
= 0;
1610 if (self
->mwmhints
.flags
& OB_MWM_FLAG_FUNCTIONS
) {
1611 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_ALL
)) {
1612 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_RESIZE
))
1613 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
1614 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_MOVE
))
1615 self
->functions
&= ~OB_CLIENT_FUNC_MOVE
;
1616 /* dont let mwm hints kill any buttons
1617 if (! (self->mwmhints.functions & OB_MWM_FUNC_ICONIFY))
1618 self->functions &= ~OB_CLIENT_FUNC_ICONIFY;
1619 if (! (self->mwmhints.functions & OB_MWM_FUNC_MAXIMIZE))
1620 self->functions &= ~OB_CLIENT_FUNC_MAXIMIZE;
1622 /* dont let mwm hints kill the close button
1623 if (! (self->mwmhints.functions & MwmFunc_Close))
1624 self->functions &= ~OB_CLIENT_FUNC_CLOSE; */
1628 if (!(self
->functions
& OB_CLIENT_FUNC_SHADE
))
1629 self
->decorations
&= ~OB_FRAME_DECOR_SHADE
;
1630 if (!(self
->functions
& OB_CLIENT_FUNC_ICONIFY
))
1631 self
->decorations
&= ~OB_FRAME_DECOR_ICONIFY
;
1632 if (!(self
->functions
& OB_CLIENT_FUNC_RESIZE
))
1633 self
->decorations
&= ~OB_FRAME_DECOR_GRIPS
;
1635 /* can't maximize without moving/resizing */
1636 if (!((self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) &&
1637 (self
->functions
& OB_CLIENT_FUNC_MOVE
) &&
1638 (self
->functions
& OB_CLIENT_FUNC_RESIZE
))) {
1639 self
->functions
&= ~OB_CLIENT_FUNC_MAXIMIZE
;
1640 self
->decorations
&= ~OB_FRAME_DECOR_MAXIMIZE
;
1643 /* kill the handle on fully maxed windows */
1644 if (self
->max_vert
&& self
->max_horz
)
1645 self
->decorations
&= ~OB_FRAME_DECOR_HANDLE
;
1647 /* finally, the user can have requested no decorations, which overrides
1648 everything (but doesnt give it a border if it doesnt have one) */
1649 if (self
->undecorated
) {
1650 if (config_theme_keepborder
)
1651 self
->decorations
&= OB_FRAME_DECOR_BORDER
;
1653 self
->decorations
= 0;
1656 /* if we don't have a titlebar, then we cannot shade! */
1657 if (!(self
->decorations
& OB_FRAME_DECOR_TITLEBAR
))
1658 self
->functions
&= ~OB_CLIENT_FUNC_SHADE
;
1660 /* now we need to check against rules for the client's current state */
1661 if (self
->fullscreen
) {
1662 self
->functions
&= (OB_CLIENT_FUNC_CLOSE
|
1663 OB_CLIENT_FUNC_FULLSCREEN
|
1664 OB_CLIENT_FUNC_ICONIFY
);
1665 self
->decorations
= 0;
1668 client_change_allowed_actions(self
);
1671 /* adjust the client's decorations, etc. */
1672 client_reconfigure(self
);
1676 static void client_change_allowed_actions(ObClient
*self
)
1681 /* desktop windows are kept on all desktops */
1682 if (self
->type
!= OB_CLIENT_TYPE_DESKTOP
)
1683 actions
[num
++] = prop_atoms
.net_wm_action_change_desktop
;
1685 if (self
->functions
& OB_CLIENT_FUNC_SHADE
)
1686 actions
[num
++] = prop_atoms
.net_wm_action_shade
;
1687 if (self
->functions
& OB_CLIENT_FUNC_CLOSE
)
1688 actions
[num
++] = prop_atoms
.net_wm_action_close
;
1689 if (self
->functions
& OB_CLIENT_FUNC_MOVE
)
1690 actions
[num
++] = prop_atoms
.net_wm_action_move
;
1691 if (self
->functions
& OB_CLIENT_FUNC_ICONIFY
)
1692 actions
[num
++] = prop_atoms
.net_wm_action_minimize
;
1693 if (self
->functions
& OB_CLIENT_FUNC_RESIZE
)
1694 actions
[num
++] = prop_atoms
.net_wm_action_resize
;
1695 if (self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
)
1696 actions
[num
++] = prop_atoms
.net_wm_action_fullscreen
;
1697 if (self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) {
1698 actions
[num
++] = prop_atoms
.net_wm_action_maximize_horz
;
1699 actions
[num
++] = prop_atoms
.net_wm_action_maximize_vert
;
1702 PROP_SETA32(self
->window
, net_wm_allowed_actions
, atom
, actions
, num
);
1704 /* make sure the window isn't breaking any rules now */
1706 if (!(self
->functions
& OB_CLIENT_FUNC_SHADE
) && self
->shaded
) {
1707 if (self
->frame
) client_shade(self
, FALSE
);
1708 else self
->shaded
= FALSE
;
1710 if (!(self
->functions
& OB_CLIENT_FUNC_ICONIFY
) && self
->iconic
) {
1711 if (self
->frame
) client_iconify(self
, FALSE
, TRUE
);
1712 else self
->iconic
= FALSE
;
1714 if (!(self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
) && self
->fullscreen
) {
1715 if (self
->frame
) client_fullscreen(self
, FALSE
);
1716 else self
->fullscreen
= FALSE
;
1718 if (!(self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) && (self
->max_horz
||
1720 if (self
->frame
) client_maximize(self
, FALSE
, 0);
1721 else self
->max_vert
= self
->max_horz
= FALSE
;
1725 void client_reconfigure(ObClient
*self
)
1727 /* by making this pass FALSE for user, we avoid the emacs event storm where
1728 every configurenotify causes an update in its normal hints, i think this
1729 is generally what we want anyways... */
1730 client_configure(self
, self
->area
.x
, self
->area
.y
,
1731 self
->area
.width
, self
->area
.height
, FALSE
, TRUE
);
1734 void client_update_wmhints(ObClient
*self
)
1738 /* assume a window takes input if it doesnt specify */
1739 self
->can_focus
= TRUE
;
1741 if ((hints
= XGetWMHints(ob_display
, self
->window
)) != NULL
) {
1744 if (hints
->flags
& InputHint
)
1745 self
->can_focus
= hints
->input
;
1747 /* only do this when first managing the window *AND* when we aren't
1749 if (ob_state() != OB_STATE_STARTING
&& self
->frame
== NULL
)
1750 if (hints
->flags
& StateHint
)
1751 self
->iconic
= hints
->initial_state
== IconicState
;
1754 self
->urgent
= (hints
->flags
& XUrgencyHint
);
1755 if (self
->urgent
&& !ur
)
1756 client_hilite(self
, TRUE
);
1757 else if (!self
->urgent
&& ur
&& self
->demands_attention
)
1758 client_hilite(self
, FALSE
);
1760 if (!(hints
->flags
& WindowGroupHint
))
1761 hints
->window_group
= None
;
1763 /* did the group state change? */
1764 if (hints
->window_group
!=
1765 (self
->group
? self
->group
->leader
: None
))
1767 ObGroup
*oldgroup
= self
->group
;
1769 /* remove from the old group if there was one */
1770 if (self
->group
!= NULL
) {
1771 group_remove(self
->group
, self
);
1775 /* add ourself to the group if we have one */
1776 if (hints
->window_group
!= None
) {
1777 self
->group
= group_add(hints
->window_group
, self
);
1780 /* Put ourselves into the new group's transient tree, and remove
1781 ourselves from the old group's */
1782 client_update_transient_tree(self
, oldgroup
, self
->group
,
1783 self
->transient_for
,
1784 self
->transient_for
);
1786 /* Lastly, being in a group, or not, can change if the window is
1787 transient for anything.
1789 The logic for this is:
1790 self->transient = TRUE always if the window wants to be
1791 transient for something, even if transient_for was NULL because
1792 it wasn't in a group before.
1794 If transient_for was NULL and oldgroup was NULL we can assume
1795 that when we add the new group, it will become transient for
1798 If transient_for was OB_TRAN_GROUP, then it must have already
1799 had a group. If it is getting a new group, the above call to
1800 client_update_transient_tree has already taken care of
1801 everything ! If it is losing all group status then it will
1802 no longer be transient for anything and that needs to be
1805 if (self
->transient
&&
1806 ((self
->transient_for
== NULL
&& oldgroup
== NULL
) ||
1807 (self
->transient_for
== OB_TRAN_GROUP
&& !self
->group
)))
1808 client_update_transient_for(self
);
1811 /* the WM_HINTS can contain an icon */
1812 client_update_icons(self
);
1818 void client_update_title(ObClient
*self
)
1821 gchar
*visible
= NULL
;
1823 g_free(self
->title
);
1826 if (!PROP_GETS(self
->window
, net_wm_name
, utf8
, &data
)) {
1827 /* try old x stuff */
1828 if (!(PROP_GETS(self
->window
, wm_name
, locale
, &data
)
1829 || PROP_GETS(self
->window
, wm_name
, utf8
, &data
))) {
1830 if (self
->transient
) {
1832 GNOME alert windows are not given titles:
1833 http://developer.gnome.org/projects/gup/hig/draft_hig_new/windows-alert.html
1835 data
= g_strdup("");
1837 data
= g_strdup("Unnamed Window");
1841 if (self
->client_machine
) {
1842 visible
= g_strdup_printf("%s (%s)", data
, self
->client_machine
);
1847 PROP_SETS(self
->window
, net_wm_visible_name
, visible
);
1848 self
->title
= visible
;
1851 frame_adjust_title(self
->frame
);
1853 /* update the icon title */
1855 g_free(self
->icon_title
);
1858 if (!PROP_GETS(self
->window
, net_wm_icon_name
, utf8
, &data
))
1859 /* try old x stuff */
1860 if (!(PROP_GETS(self
->window
, wm_icon_name
, locale
, &data
) ||
1861 PROP_GETS(self
->window
, wm_icon_name
, utf8
, &data
)))
1862 data
= g_strdup(self
->title
);
1864 PROP_SETS(self
->window
, net_wm_visible_icon_name
, data
);
1865 self
->icon_title
= data
;
1868 void client_update_strut(ObClient
*self
)
1872 gboolean got
= FALSE
;
1875 if (PROP_GETA32(self
->window
, net_wm_strut_partial
, cardinal
,
1879 STRUT_PARTIAL_SET(strut
,
1880 data
[0], data
[2], data
[1], data
[3],
1881 data
[4], data
[5], data
[8], data
[9],
1882 data
[6], data
[7], data
[10], data
[11]);
1888 PROP_GETA32(self
->window
, net_wm_strut
, cardinal
, &data
, &num
)) {
1894 /* use the screen's width/height */
1895 a
= screen_physical_area();
1897 STRUT_PARTIAL_SET(strut
,
1898 data
[0], data
[2], data
[1], data
[3],
1899 a
->y
, a
->y
+ a
->height
- 1,
1900 a
->x
, a
->x
+ a
->width
- 1,
1901 a
->y
, a
->y
+ a
->height
- 1,
1902 a
->x
, a
->x
+ a
->width
- 1);
1908 STRUT_PARTIAL_SET(strut
, 0, 0, 0, 0,
1909 0, 0, 0, 0, 0, 0, 0, 0);
1911 if (!STRUT_EQUAL(strut
, self
->strut
)) {
1912 self
->strut
= strut
;
1914 /* updating here is pointless while we're being mapped cuz we're not in
1915 the client list yet */
1917 screen_update_areas();
1921 void client_update_icons(ObClient
*self
)
1927 for (i
= 0; i
< self
->nicons
; ++i
)
1928 g_free(self
->icons
[i
].data
);
1929 if (self
->nicons
> 0)
1930 g_free(self
->icons
);
1933 if (PROP_GETA32(self
->window
, net_wm_icon
, cardinal
, &data
, &num
)) {
1934 /* figure out how many valid icons are in here */
1936 while (num
- i
> 2) {
1940 if (i
> num
|| w
*h
== 0) break;
1944 self
->icons
= g_new(ObClientIcon
, self
->nicons
);
1946 /* store the icons */
1948 for (j
= 0; j
< self
->nicons
; ++j
) {
1951 w
= self
->icons
[j
].width
= data
[i
++];
1952 h
= self
->icons
[j
].height
= data
[i
++];
1954 if (w
*h
== 0) continue;
1956 self
->icons
[j
].data
= g_new(RrPixel32
, w
* h
);
1957 for (x
= 0, y
= 0, t
= 0; t
< w
* h
; ++t
, ++x
, ++i
) {
1962 self
->icons
[j
].data
[t
] =
1963 (((data
[i
] >> 24) & 0xff) << RrDefaultAlphaOffset
) +
1964 (((data
[i
] >> 16) & 0xff) << RrDefaultRedOffset
) +
1965 (((data
[i
] >> 8) & 0xff) << RrDefaultGreenOffset
) +
1966 (((data
[i
] >> 0) & 0xff) << RrDefaultBlueOffset
);
1975 if ((hints
= XGetWMHints(ob_display
, self
->window
))) {
1976 if (hints
->flags
& IconPixmapHint
) {
1978 self
->icons
= g_new(ObClientIcon
, self
->nicons
);
1979 xerror_set_ignore(TRUE
);
1980 if (!RrPixmapToRGBA(ob_rr_inst
,
1982 (hints
->flags
& IconMaskHint
?
1983 hints
->icon_mask
: None
),
1984 &self
->icons
[self
->nicons
-1].width
,
1985 &self
->icons
[self
->nicons
-1].height
,
1986 &self
->icons
[self
->nicons
-1].data
)){
1987 g_free(&self
->icons
[self
->nicons
-1]);
1990 xerror_set_ignore(FALSE
);
1996 /* set the default icon onto the window
1997 in theory, this could be a race, but if a window doesn't set an icon
1998 or removes it entirely, it's not very likely it is going to set one
1999 right away afterwards */
2000 if (self
->nicons
== 0) {
2001 RrPixel32
*icon
= ob_rr_theme
->def_win_icon
;
2004 data
= g_new(gulong
, 48*48+2);
2005 data
[0] = data
[1] = 48;
2006 for (i
= 0; i
< 48*48; ++i
)
2007 data
[i
+2] = (((icon
[i
] >> RrDefaultAlphaOffset
) & 0xff) << 24) +
2008 (((icon
[i
] >> RrDefaultRedOffset
) & 0xff) << 16) +
2009 (((icon
[i
] >> RrDefaultGreenOffset
) & 0xff) << 8) +
2010 (((icon
[i
] >> RrDefaultBlueOffset
) & 0xff) << 0);
2011 PROP_SETA32(self
->window
, net_wm_icon
, cardinal
, data
, 48*48+2);
2013 } else if (self
->frame
)
2014 /* don't draw the icon empty if we're just setting one now anyways,
2015 we'll get the property change any second */
2016 frame_adjust_icon(self
->frame
);
2019 void client_update_user_time(ObClient
*self
)
2023 if (PROP_GET32(self
->window
, net_wm_user_time
, cardinal
, &time
)) {
2024 /* we set this every time, not just when it grows, because in practice
2025 sometimes time goes backwards! (ntpdate.. yay....) so.. if it goes
2026 backward we don't want all windows to stop focusing. we'll just
2027 assume noone is setting times older than the last one, cuz that
2028 would be pretty stupid anyways
2030 self
->user_time
= time
;
2033 ob_debug("window %s user time %u\n", self->title, time);
2038 void client_update_icon_geometry(ObClient
*self
)
2043 RECT_SET(self
->icon_geometry
, 0, 0, 0, 0);
2045 if (PROP_GETA32(self
->window
, net_wm_icon_geometry
, cardinal
, &data
, &num
)
2048 /* don't let them set it with an area < 0 */
2049 RECT_SET(self
->icon_geometry
, data
[0], data
[1],
2050 MAX(data
[2],0), MAX(data
[3],0));
2054 static void client_get_session_ids(ObClient
*self
)
2061 if (!PROP_GET32(self
->window
, wm_client_leader
, window
, &leader
))
2064 /* get the SM_CLIENT_ID */
2067 got
= PROP_GETS(leader
, sm_client_id
, locale
, &self
->sm_client_id
);
2069 PROP_GETS(self
->window
, sm_client_id
, locale
, &self
->sm_client_id
);
2071 /* get the WM_CLASS (name and class). make them "" if they are not
2075 got
= PROP_GETSS(leader
, wm_class
, locale
, &ss
);
2077 got
= PROP_GETSS(self
->window
, wm_class
, locale
, &ss
);
2081 self
->name
= g_strdup(ss
[0]);
2083 self
->class = g_strdup(ss
[1]);
2088 if (self
->name
== NULL
) self
->name
= g_strdup("");
2089 if (self
->class == NULL
) self
->class = g_strdup("");
2091 /* get the WM_WINDOW_ROLE. make it "" if it is not provided */
2094 got
= PROP_GETS(leader
, wm_window_role
, locale
, &s
);
2096 got
= PROP_GETS(self
->window
, wm_window_role
, locale
, &s
);
2101 self
->role
= g_strdup("");
2103 /* get the WM_COMMAND */
2107 got
= PROP_GETSS(leader
, wm_command
, locale
, &ss
);
2109 got
= PROP_GETSS(self
->window
, wm_command
, locale
, &ss
);
2112 /* merge/mash them all together */
2113 gchar
*merge
= NULL
;
2116 for (i
= 0; ss
[i
]; ++i
) {
2119 merge
= g_strconcat(merge
, ss
[i
], NULL
);
2121 merge
= g_strconcat(ss
[i
], NULL
);
2126 self
->wm_command
= merge
;
2129 /* get the WM_CLIENT_MACHINE */
2132 got
= PROP_GETS(leader
, wm_client_machine
, locale
, &s
);
2134 got
= PROP_GETS(self
->window
, wm_client_machine
, locale
, &s
);
2137 gchar localhost
[128];
2139 gethostname(localhost
, 127);
2140 localhost
[127] = '\0';
2141 if (strcmp(localhost
, s
) != 0)
2142 self
->client_machine
= s
;
2146 static void client_change_wm_state(ObClient
*self
)
2151 old
= self
->wmstate
;
2153 if (self
->shaded
|| self
->iconic
||
2154 (self
->desktop
!= DESKTOP_ALL
&& self
->desktop
!= screen_desktop
))
2156 self
->wmstate
= IconicState
;
2158 self
->wmstate
= NormalState
;
2160 if (old
!= self
->wmstate
) {
2161 PROP_MSG(self
->window
, kde_wm_change_state
,
2162 self
->wmstate
, 1, 0, 0);
2164 state
[0] = self
->wmstate
;
2166 PROP_SETA32(self
->window
, wm_state
, wm_state
, state
, 2);
2170 static void client_change_state(ObClient
*self
)
2172 gulong netstate
[11];
2177 netstate
[num
++] = prop_atoms
.net_wm_state_modal
;
2179 netstate
[num
++] = prop_atoms
.net_wm_state_shaded
;
2181 netstate
[num
++] = prop_atoms
.net_wm_state_hidden
;
2182 if (self
->skip_taskbar
)
2183 netstate
[num
++] = prop_atoms
.net_wm_state_skip_taskbar
;
2184 if (self
->skip_pager
)
2185 netstate
[num
++] = prop_atoms
.net_wm_state_skip_pager
;
2186 if (self
->fullscreen
)
2187 netstate
[num
++] = prop_atoms
.net_wm_state_fullscreen
;
2189 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_vert
;
2191 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_horz
;
2193 netstate
[num
++] = prop_atoms
.net_wm_state_above
;
2195 netstate
[num
++] = prop_atoms
.net_wm_state_below
;
2196 if (self
->demands_attention
)
2197 netstate
[num
++] = prop_atoms
.net_wm_state_demands_attention
;
2198 if (self
->undecorated
)
2199 netstate
[num
++] = prop_atoms
.openbox_wm_state_undecorated
;
2200 PROP_SETA32(self
->window
, net_wm_state
, atom
, netstate
, num
);
2203 frame_adjust_state(self
->frame
);
2206 ObClient
*client_search_focus_tree(ObClient
*self
)
2211 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
2212 if (client_focused(it
->data
)) return it
->data
;
2213 if ((ret
= client_search_focus_tree(it
->data
))) return ret
;
2218 ObClient
*client_search_focus_tree_full(ObClient
*self
)
2220 if (self
->transient_for
) {
2221 if (self
->transient_for
!= OB_TRAN_GROUP
) {
2222 return client_search_focus_tree_full(self
->transient_for
);
2225 gboolean recursed
= FALSE
;
2227 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
))
2228 if (!((ObClient
*)it
->data
)->transient_for
) {
2230 if ((c
= client_search_focus_tree_full(it
->data
)))
2239 /* this function checks the whole tree, the client_search_focus_tree~
2240 does not, so we need to check this window */
2241 if (client_focused(self
))
2243 return client_search_focus_tree(self
);
2246 static ObStackingLayer
calc_layer(ObClient
*self
)
2250 if (self
->type
== OB_CLIENT_TYPE_DESKTOP
)
2251 l
= OB_STACKING_LAYER_DESKTOP
;
2252 else if (self
->type
== OB_CLIENT_TYPE_DOCK
) {
2253 if (self
->below
) l
= OB_STACKING_LAYER_NORMAL
;
2254 else l
= OB_STACKING_LAYER_ABOVE
;
2256 else if ((self
->fullscreen
||
2257 /* no decorations and fills the monitor = oldskool fullscreen */
2258 (self
->frame
!= NULL
&&
2259 (self
->frame
->size
.right
== 0 && self
->frame
->size
.left
== 0 &&
2260 self
->frame
->size
.bottom
== 0 && self
->frame
->size
.top
== 0 &&
2261 RECT_EQUAL(self
->area
,
2262 *screen_physical_area_monitor
2263 (client_monitor(self
)))))) &&
2264 (client_focused(self
) || client_search_focus_tree(self
)))
2265 l
= OB_STACKING_LAYER_FULLSCREEN
;
2266 else if (self
->above
) l
= OB_STACKING_LAYER_ABOVE
;
2267 else if (self
->below
) l
= OB_STACKING_LAYER_BELOW
;
2268 else l
= OB_STACKING_LAYER_NORMAL
;
2273 static void client_calc_layer_recursive(ObClient
*self
, ObClient
*orig
,
2274 ObStackingLayer min
, gboolean raised
)
2276 ObStackingLayer old
, own
;
2280 own
= calc_layer(self
);
2281 self
->layer
= MAX(own
, min
);
2283 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
2284 client_calc_layer_recursive(it
->data
, orig
,
2286 raised
? raised
: self
->layer
!= old
);
2288 if (!raised
&& self
->layer
!= old
)
2289 if (orig
->frame
) { /* only restack if the original window is managed */
2290 stacking_remove(CLIENT_AS_WINDOW(self
));
2291 stacking_add(CLIENT_AS_WINDOW(self
));
2295 void client_calc_layer(ObClient
*self
)
2302 /* transients take on the layer of their parents */
2303 it
= client_search_all_top_parents(self
);
2305 for (; it
; it
= g_slist_next(it
))
2306 client_calc_layer_recursive(it
->data
, orig
, 0, FALSE
);
2309 gboolean
client_should_show(ObClient
*self
)
2313 if (client_normal(self
) && screen_showing_desktop
)
2315 if (self
->desktop
== screen_desktop
|| self
->desktop
== DESKTOP_ALL
)
2321 void client_show(ObClient
*self
)
2324 if (client_should_show(self
)) {
2325 frame_show(self
->frame
);
2328 /* According to the ICCCM (sec 4.1.3.1) when a window is not visible, it
2329 needs to be in IconicState. This includes when it is on another
2332 client_change_wm_state(self
);
2335 void client_hide(ObClient
*self
)
2337 if (!client_should_show(self
)) {
2338 frame_hide(self
->frame
);
2341 /* According to the ICCCM (sec 4.1.3.1) when a window is not visible, it
2342 needs to be in IconicState. This includes when it is on another
2345 client_change_wm_state(self
);
2348 void client_showhide(ObClient
*self
)
2351 if (client_should_show(self
)) {
2352 frame_show(self
->frame
);
2355 frame_hide(self
->frame
);
2358 /* According to the ICCCM (sec 4.1.3.1) when a window is not visible, it
2359 needs to be in IconicState. This includes when it is on another
2362 client_change_wm_state(self
);
2365 gboolean
client_normal(ObClient
*self
) {
2366 return ! (self
->type
== OB_CLIENT_TYPE_DESKTOP
||
2367 self
->type
== OB_CLIENT_TYPE_DOCK
||
2368 self
->type
== OB_CLIENT_TYPE_SPLASH
);
2371 gboolean
client_helper(ObClient
*self
)
2373 return (self
->type
== OB_CLIENT_TYPE_UTILITY
||
2374 self
->type
== OB_CLIENT_TYPE_MENU
||
2375 self
->type
== OB_CLIENT_TYPE_TOOLBAR
);
2378 gboolean
client_mouse_focusable(ObClient
*self
)
2380 return !(self
->type
== OB_CLIENT_TYPE_MENU
||
2381 self
->type
== OB_CLIENT_TYPE_TOOLBAR
||
2382 self
->type
== OB_CLIENT_TYPE_SPLASH
||
2383 self
->type
== OB_CLIENT_TYPE_DOCK
);
2386 gboolean
client_enter_focusable(ObClient
*self
)
2388 /* you can focus desktops but it shouldn't on enter */
2389 return (client_mouse_focusable(self
) &&
2390 self
->type
!= OB_CLIENT_TYPE_DESKTOP
);
2394 static void client_apply_startup_state(ObClient
*self
, gint x
, gint y
)
2396 gboolean pos
= FALSE
; /* has the window's position been configured? */
2399 /* save the position, and set self->area for these to use */
2405 /* set the desktop hint, to make sure that it always exists */
2406 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, self
->desktop
);
2408 /* these are in a carefully crafted order.. */
2411 self
->iconic
= FALSE
;
2412 client_iconify(self
, TRUE
, FALSE
);
2414 if (self
->fullscreen
) {
2415 self
->fullscreen
= FALSE
;
2416 client_fullscreen(self
, TRUE
);
2419 if (self
->undecorated
) {
2420 self
->undecorated
= FALSE
;
2421 client_set_undecorated(self
, TRUE
);
2424 self
->shaded
= FALSE
;
2425 client_shade(self
, TRUE
);
2427 if (self
->demands_attention
) {
2428 self
->demands_attention
= FALSE
;
2429 client_hilite(self
, TRUE
);
2432 if (self
->max_vert
&& self
->max_horz
) {
2433 self
->max_vert
= self
->max_horz
= FALSE
;
2434 client_maximize(self
, TRUE
, 0);
2436 } else if (self
->max_vert
) {
2437 self
->max_vert
= FALSE
;
2438 client_maximize(self
, TRUE
, 2);
2440 } else if (self
->max_horz
) {
2441 self
->max_horz
= FALSE
;
2442 client_maximize(self
, TRUE
, 1);
2446 /* if the client didn't get positioned yet, then do so now.
2447 call client_move even if the window is not being moved anywhere, because
2448 when we reparent it and decorate it, it is getting moved and we need to
2449 be telling it so with a ConfigureNotify event.
2452 /* use the saved position */
2455 client_move(self
, x
, y
);
2458 /* nothing to do for the other states:
2467 void client_convert_gravity(ObClient
*self
, gint gravity
, gint
*x
, gint
*y
,
2470 gint oldg
= self
->gravity
;
2472 /* get the frame's position from the requested stuff */
2473 self
->gravity
= gravity
;
2474 frame_client_gravity(self
->frame
, x
, y
, w
, h
);
2475 self
->gravity
= oldg
;
2477 /* get the client's position in its true gravity from that */
2478 frame_frame_gravity(self
->frame
, x
, y
, w
, h
);
2481 void client_try_configure(ObClient
*self
, gint
*x
, gint
*y
, gint
*w
, gint
*h
,
2482 gint
*logicalw
, gint
*logicalh
,
2485 Rect desired_area
= {*x
, *y
, *w
, *h
};
2487 /* make the frame recalculate its dimentions n shit without changing
2488 anything visible for real, this way the constraints below can work with
2489 the updated frame dimensions. */
2490 frame_adjust_area(self
->frame
, TRUE
, TRUE
, TRUE
);
2492 /* work within the prefered sizes given by the window */
2493 if (!(*w
== self
->area
.width
&& *h
== self
->area
.height
)) {
2494 gint basew
, baseh
, minw
, minh
;
2496 /* base size is substituted with min size if not specified */
2497 if (self
->base_size
.width
|| self
->base_size
.height
) {
2498 basew
= self
->base_size
.width
;
2499 baseh
= self
->base_size
.height
;
2501 basew
= self
->min_size
.width
;
2502 baseh
= self
->min_size
.height
;
2504 /* min size is substituted with base size if not specified */
2505 if (self
->min_size
.width
|| self
->min_size
.height
) {
2506 minw
= self
->min_size
.width
;
2507 minh
= self
->min_size
.height
;
2509 minw
= self
->base_size
.width
;
2510 minh
= self
->base_size
.height
;
2513 /* if this is a user-requested resize, then check against min/max
2516 /* smaller than min size or bigger than max size? */
2517 if (*w
> self
->max_size
.width
) *w
= self
->max_size
.width
;
2518 if (*w
< minw
) *w
= minw
;
2519 if (*h
> self
->max_size
.height
) *h
= self
->max_size
.height
;
2520 if (*h
< minh
) *h
= minh
;
2525 /* keep to the increments */
2526 *w
/= self
->size_inc
.width
;
2527 *h
/= self
->size_inc
.height
;
2529 /* you cannot resize to nothing */
2530 if (basew
+ *w
< 1) *w
= 1 - basew
;
2531 if (baseh
+ *h
< 1) *h
= 1 - baseh
;
2533 /* save the logical size */
2534 *logicalw
= self
->size_inc
.width
> 1 ? *w
: *w
+ basew
;
2535 *logicalh
= self
->size_inc
.height
> 1 ? *h
: *h
+ baseh
;
2537 *w
*= self
->size_inc
.width
;
2538 *h
*= self
->size_inc
.height
;
2543 /* adjust the height to match the width for the aspect ratios.
2544 for this, min size is not substituted for base size ever. */
2545 *w
-= self
->base_size
.width
;
2546 *h
-= self
->base_size
.height
;
2548 if (!self
->fullscreen
) {
2549 if (self
->min_ratio
)
2550 if (*h
* self
->min_ratio
> *w
) {
2551 *h
= (gint
)(*w
/ self
->min_ratio
);
2553 /* you cannot resize to nothing */
2556 *w
= (gint
)(*h
* self
->min_ratio
);
2559 if (self
->max_ratio
)
2560 if (*h
* self
->max_ratio
< *w
) {
2561 *h
= (gint
)(*w
/ self
->max_ratio
);
2563 /* you cannot resize to nothing */
2566 *w
= (gint
)(*h
* self
->min_ratio
);
2571 *w
+= self
->base_size
.width
;
2572 *h
+= self
->base_size
.height
;
2575 /* gets the frame's position */
2576 frame_client_gravity(self
->frame
, x
, y
, *w
, *h
);
2578 /* these positions are frame positions, not client positions */
2580 /* set the size and position if fullscreen */
2581 if (self
->fullscreen
) {
2585 i
= screen_find_monitor(&desired_area
);
2586 a
= screen_physical_area_monitor(i
);
2593 user
= FALSE
; /* ignore if the client can't be moved/resized when it
2594 is entering fullscreen */
2595 } else if (self
->max_horz
|| self
->max_vert
) {
2599 i
= screen_find_monitor(&desired_area
);
2600 a
= screen_area_monitor(self
->desktop
, i
);
2602 /* set the size and position if maximized */
2603 if (self
->max_horz
) {
2605 *w
= a
->width
- self
->frame
->size
.left
- self
->frame
->size
.right
;
2607 if (self
->max_vert
) {
2609 *h
= a
->height
- self
->frame
->size
.top
- self
->frame
->size
.bottom
;
2612 /* maximizing is not allowed if the user can't move+resize the window
2616 /* gets the client's position */
2617 frame_frame_gravity(self
->frame
, x
, y
, *w
, *h
);
2619 /* these override the above states! if you cant move you can't move! */
2621 if (!(self
->functions
& OB_CLIENT_FUNC_MOVE
)) {
2625 if (!(self
->functions
& OB_CLIENT_FUNC_RESIZE
)) {
2626 *w
= self
->area
.width
;
2627 *h
= self
->area
.height
;
2636 void client_configure_full(ObClient
*self
, gint x
, gint y
, gint w
, gint h
,
2637 gboolean user
, gboolean final
,
2638 gboolean force_reply
)
2640 gint oldw
, oldh
, oldrx
, oldry
;
2641 gboolean send_resize_client
;
2642 gboolean moved
= FALSE
, resized
= FALSE
, rootmoved
= FALSE
;
2643 guint fdecor
= self
->frame
->decorations
;
2644 gboolean fhorz
= self
->frame
->max_horz
;
2645 gint logicalw
, logicalh
;
2647 /* find the new x, y, width, and height (and logical size) */
2648 client_try_configure(self
, &x
, &y
, &w
, &h
, &logicalw
, &logicalh
, user
);
2650 /* set the logical size if things changed */
2651 if (!(w
== self
->area
.width
&& h
== self
->area
.height
))
2652 SIZE_SET(self
->logical_size
, logicalw
, logicalh
);
2654 /* figure out if we moved or resized or what */
2655 moved
= x
!= self
->area
.x
|| y
!= self
->area
.y
;
2656 resized
= w
!= self
->area
.width
|| h
!= self
->area
.height
;
2658 oldw
= self
->area
.width
;
2659 oldh
= self
->area
.height
;
2660 RECT_SET(self
->area
, x
, y
, w
, h
);
2662 /* for app-requested resizes, always resize if 'resized' is true.
2663 for user-requested ones, only resize if final is true, or when
2664 resizing in redraw mode */
2665 send_resize_client
= ((!user
&& resized
) ||
2667 (resized
&& config_resize_redraw
))));
2669 /* if the client is enlarging, then resize the client before the frame */
2670 if (send_resize_client
&& user
&& (w
> oldw
|| h
> oldh
)) {
2671 XResizeWindow(ob_display
, self
->window
, MAX(w
, oldw
), MAX(h
, oldh
));
2672 /* resize the plate to show the client padding color underneath */
2673 frame_adjust_client_area(self
->frame
);
2676 /* find the frame's dimensions and move/resize it */
2677 if (self
->decorations
!= fdecor
|| self
->max_horz
!= fhorz
)
2678 moved
= resized
= TRUE
;
2679 if (moved
|| resized
)
2680 frame_adjust_area(self
->frame
, moved
, resized
, FALSE
);
2682 /* find the client's position relative to the root window */
2683 oldrx
= self
->root_pos
.x
;
2684 oldry
= self
->root_pos
.y
;
2685 rootmoved
= (oldrx
!= (signed)(self
->frame
->area
.x
+
2686 self
->frame
->size
.left
-
2687 self
->border_width
) ||
2688 oldry
!= (signed)(self
->frame
->area
.y
+
2689 self
->frame
->size
.top
-
2690 self
->border_width
));
2692 if (force_reply
|| ((!user
|| (user
&& final
)) && rootmoved
))
2696 POINT_SET(self
->root_pos
,
2697 self
->frame
->area
.x
+ self
->frame
->size
.left
-
2699 self
->frame
->area
.y
+ self
->frame
->size
.top
-
2700 self
->border_width
);
2702 event
.type
= ConfigureNotify
;
2703 event
.xconfigure
.display
= ob_display
;
2704 event
.xconfigure
.event
= self
->window
;
2705 event
.xconfigure
.window
= self
->window
;
2707 /* root window real coords */
2708 event
.xconfigure
.x
= self
->root_pos
.x
;
2709 event
.xconfigure
.y
= self
->root_pos
.y
;
2710 event
.xconfigure
.width
= w
;
2711 event
.xconfigure
.height
= h
;
2712 event
.xconfigure
.border_width
= 0;
2713 event
.xconfigure
.above
= self
->frame
->plate
;
2714 event
.xconfigure
.override_redirect
= FALSE
;
2715 XSendEvent(event
.xconfigure
.display
, event
.xconfigure
.window
,
2716 FALSE
, StructureNotifyMask
, &event
);
2719 /* if the client is shrinking, then resize the frame before the client */
2720 if (send_resize_client
&& (!user
|| (w
<= oldw
|| h
<= oldh
))) {
2721 /* resize the plate to show the client padding color underneath */
2722 frame_adjust_client_area(self
->frame
);
2724 XResizeWindow(ob_display
, self
->window
, w
, h
);
2730 void client_fullscreen(ObClient
*self
, gboolean fs
)
2734 if (!(self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
) || /* can't */
2735 self
->fullscreen
== fs
) return; /* already done */
2737 self
->fullscreen
= fs
;
2738 client_change_state(self
); /* change the state hints on the client */
2739 client_calc_layer(self
); /* and adjust out layer/stacking */
2742 self
->pre_fullscreen_area
= self
->area
;
2743 /* if the window is maximized, its area isn't all that meaningful.
2744 save it's premax area instead. */
2745 if (self
->max_horz
) {
2746 self
->pre_fullscreen_area
.x
= self
->pre_max_area
.x
;
2747 self
->pre_fullscreen_area
.width
= self
->pre_max_area
.width
;
2749 if (self
->max_vert
) {
2750 self
->pre_fullscreen_area
.y
= self
->pre_max_area
.y
;
2751 self
->pre_fullscreen_area
.height
= self
->pre_max_area
.height
;
2754 /* these are not actually used cuz client_configure will set them
2755 as appropriate when the window is fullscreened */
2760 if (self
->pre_fullscreen_area
.width
> 0 &&
2761 self
->pre_fullscreen_area
.height
> 0)
2763 x
= self
->pre_fullscreen_area
.x
;
2764 y
= self
->pre_fullscreen_area
.y
;
2765 w
= self
->pre_fullscreen_area
.width
;
2766 h
= self
->pre_fullscreen_area
.height
;
2767 RECT_SET(self
->pre_fullscreen_area
, 0, 0, 0, 0);
2769 /* pick some fallbacks... */
2770 a
= screen_area_monitor(self
->desktop
, 0);
2771 x
= a
->x
+ a
->width
/ 4;
2772 y
= a
->y
+ a
->height
/ 4;
2778 client_setup_decor_and_functions(self
);
2780 client_move_resize(self
, x
, y
, w
, h
);
2782 /* try focus us when we go into fullscreen mode */
2786 static void client_iconify_recursive(ObClient
*self
,
2787 gboolean iconic
, gboolean curdesk
)
2790 gboolean changed
= FALSE
;
2793 if (self
->iconic
!= iconic
) {
2794 ob_debug("%sconifying window: 0x%lx\n", (iconic
? "I" : "Uni"),
2798 /* don't let non-normal windows iconify along with their parents
2800 if (client_normal(self
)) {
2801 self
->iconic
= iconic
;
2803 /* update the focus lists.. iconic windows go to the bottom of
2804 the list, put the new iconic window at the 'top of the
2806 focus_order_to_top(self
);
2811 self
->iconic
= iconic
;
2813 if (curdesk
&& self
->desktop
!= screen_desktop
&&
2814 self
->desktop
!= DESKTOP_ALL
)
2815 client_set_desktop(self
, screen_desktop
, FALSE
);
2817 /* this puts it after the current focused window */
2818 focus_order_remove(self
);
2819 focus_order_add_new(self
);
2826 client_change_state(self
);
2827 if (ob_state() != OB_STATE_STARTING
&& config_animate_iconify
)
2828 frame_begin_iconify_animation(self
->frame
, iconic
);
2829 /* do this after starting the animation so it doesn't flash */
2830 client_showhide(self
);
2833 /* iconify all direct transients, and deiconify all transients
2835 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
2836 if (it
->data
!= self
)
2837 if (client_is_direct_child(self
, it
->data
) || !iconic
)
2838 client_iconify_recursive(it
->data
, iconic
, curdesk
);
2841 void client_iconify(ObClient
*self
, gboolean iconic
, gboolean curdesk
)
2843 if (self
->functions
& OB_CLIENT_FUNC_ICONIFY
|| !iconic
) {
2844 /* move up the transient chain as far as possible first */
2845 self
= client_search_top_normal_parent(self
);
2846 client_iconify_recursive(self
, iconic
, curdesk
);
2850 void client_maximize(ObClient
*self
, gboolean max
, gint dir
)
2854 g_assert(dir
== 0 || dir
== 1 || dir
== 2);
2855 if (!(self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
)) return; /* can't */
2857 /* check if already done */
2859 if (dir
== 0 && self
->max_horz
&& self
->max_vert
) return;
2860 if (dir
== 1 && self
->max_horz
) return;
2861 if (dir
== 2 && self
->max_vert
) return;
2863 if (dir
== 0 && !self
->max_horz
&& !self
->max_vert
) return;
2864 if (dir
== 1 && !self
->max_horz
) return;
2865 if (dir
== 2 && !self
->max_vert
) return;
2868 /* we just tell it to configure in the same place and client_configure
2869 worries about filling the screen with the window */
2872 w
= self
->area
.width
;
2873 h
= self
->area
.height
;
2876 if ((dir
== 0 || dir
== 1) && !self
->max_horz
) { /* horz */
2877 RECT_SET(self
->pre_max_area
,
2878 self
->area
.x
, self
->pre_max_area
.y
,
2879 self
->area
.width
, self
->pre_max_area
.height
);
2881 if ((dir
== 0 || dir
== 2) && !self
->max_vert
) { /* vert */
2882 RECT_SET(self
->pre_max_area
,
2883 self
->pre_max_area
.x
, self
->area
.y
,
2884 self
->pre_max_area
.width
, self
->area
.height
);
2889 a
= screen_area_monitor(self
->desktop
, 0);
2890 if ((dir
== 0 || dir
== 1) && self
->max_horz
) { /* horz */
2891 if (self
->pre_max_area
.width
> 0) {
2892 x
= self
->pre_max_area
.x
;
2893 w
= self
->pre_max_area
.width
;
2895 RECT_SET(self
->pre_max_area
, 0, self
->pre_max_area
.y
,
2896 0, self
->pre_max_area
.height
);
2898 /* pick some fallbacks... */
2899 x
= a
->x
+ a
->width
/ 4;
2903 if ((dir
== 0 || dir
== 2) && self
->max_vert
) { /* vert */
2904 if (self
->pre_max_area
.height
> 0) {
2905 y
= self
->pre_max_area
.y
;
2906 h
= self
->pre_max_area
.height
;
2908 RECT_SET(self
->pre_max_area
, self
->pre_max_area
.x
, 0,
2909 self
->pre_max_area
.width
, 0);
2911 /* pick some fallbacks... */
2912 y
= a
->y
+ a
->height
/ 4;
2918 if (dir
== 0 || dir
== 1) /* horz */
2919 self
->max_horz
= max
;
2920 if (dir
== 0 || dir
== 2) /* vert */
2921 self
->max_vert
= max
;
2923 client_change_state(self
); /* change the state hints on the client */
2925 client_setup_decor_and_functions(self
);
2927 client_move_resize(self
, x
, y
, w
, h
);
2930 void client_shade(ObClient
*self
, gboolean shade
)
2932 if ((!(self
->functions
& OB_CLIENT_FUNC_SHADE
) &&
2933 shade
) || /* can't shade */
2934 self
->shaded
== shade
) return; /* already done */
2936 self
->shaded
= shade
;
2937 client_change_state(self
);
2938 client_change_wm_state(self
); /* the window is being hidden/shown */
2939 /* resize the frame to just the titlebar */
2940 frame_adjust_area(self
->frame
, FALSE
, FALSE
, FALSE
);
2943 void client_close(ObClient
*self
)
2947 if (!(self
->functions
& OB_CLIENT_FUNC_CLOSE
)) return;
2949 /* in the case that the client provides no means to requesting that it
2950 close, we just kill it */
2951 if (!self
->delete_window
)
2955 XXX: itd be cool to do timeouts and shit here for killing the client's
2957 like... if the window is around after 5 seconds, then the close button
2958 turns a nice red, and if this function is called again, the client is
2962 ce
.xclient
.type
= ClientMessage
;
2963 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
2964 ce
.xclient
.display
= ob_display
;
2965 ce
.xclient
.window
= self
->window
;
2966 ce
.xclient
.format
= 32;
2967 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_delete_window
;
2968 ce
.xclient
.data
.l
[1] = event_curtime
;
2969 ce
.xclient
.data
.l
[2] = 0l;
2970 ce
.xclient
.data
.l
[3] = 0l;
2971 ce
.xclient
.data
.l
[4] = 0l;
2972 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
2975 void client_kill(ObClient
*self
)
2977 XKillClient(ob_display
, self
->window
);
2980 void client_hilite(ObClient
*self
, gboolean hilite
)
2982 if (self
->demands_attention
== hilite
)
2983 return; /* no change */
2985 /* don't allow focused windows to hilite */
2986 self
->demands_attention
= hilite
&& !client_focused(self
);
2987 if (self
->frame
!= NULL
) { /* if we're mapping, just set the state */
2988 if (self
->demands_attention
)
2989 frame_flash_start(self
->frame
);
2991 frame_flash_stop(self
->frame
);
2992 client_change_state(self
);
2996 void client_set_desktop_recursive(ObClient
*self
,
3003 if (target
!= self
->desktop
) {
3005 ob_debug("Setting desktop %u\n", target
+1);
3007 g_assert(target
< screen_num_desktops
|| target
== DESKTOP_ALL
);
3009 old
= self
->desktop
;
3010 self
->desktop
= target
;
3011 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, target
);
3012 /* the frame can display the current desktop state */
3013 frame_adjust_state(self
->frame
);
3014 /* 'move' the window to the new desktop */
3016 client_showhide(self
);
3017 /* raise if it was not already on the desktop */
3018 if (old
!= DESKTOP_ALL
)
3020 if (STRUT_EXISTS(self
->strut
))
3021 screen_update_areas();
3024 /* move all transients */
3025 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
3026 if (it
->data
!= self
)
3027 if (client_is_direct_child(self
, it
->data
))
3028 client_set_desktop_recursive(it
->data
, target
, donthide
);
3031 void client_set_desktop(ObClient
*self
, guint target
,
3034 self
= client_search_top_normal_parent(self
);
3035 client_set_desktop_recursive(self
, target
, donthide
);
3038 gboolean
client_is_direct_child(ObClient
*parent
, ObClient
*child
)
3040 while (child
!= parent
&&
3041 child
->transient_for
&& child
->transient_for
!= OB_TRAN_GROUP
)
3042 child
= child
->transient_for
;
3043 return child
== parent
;
3046 ObClient
*client_search_modal_child(ObClient
*self
)
3051 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
3052 ObClient
*c
= it
->data
;
3053 if ((ret
= client_search_modal_child(c
))) return ret
;
3054 if (c
->modal
) return c
;
3059 gboolean
client_validate(ObClient
*self
)
3063 XSync(ob_display
, FALSE
); /* get all events on the server */
3065 if (XCheckTypedWindowEvent(ob_display
, self
->window
, DestroyNotify
, &e
) ||
3066 XCheckTypedWindowEvent(ob_display
, self
->window
, UnmapNotify
, &e
)) {
3067 XPutBackEvent(ob_display
, &e
);
3074 void client_set_wm_state(ObClient
*self
, glong state
)
3076 if (state
== self
->wmstate
) return; /* no change */
3080 client_iconify(self
, TRUE
, TRUE
);
3083 client_iconify(self
, FALSE
, TRUE
);
3088 void client_set_state(ObClient
*self
, Atom action
, glong data1
, glong data2
)
3090 gboolean shaded
= self
->shaded
;
3091 gboolean fullscreen
= self
->fullscreen
;
3092 gboolean undecorated
= self
->undecorated
;
3093 gboolean max_horz
= self
->max_horz
;
3094 gboolean max_vert
= self
->max_vert
;
3095 gboolean modal
= self
->modal
;
3096 gboolean iconic
= self
->iconic
;
3097 gboolean demands_attention
= self
->demands_attention
;
3098 gboolean above
= self
->above
;
3099 gboolean below
= self
->below
;
3102 if (!(action
== prop_atoms
.net_wm_state_add
||
3103 action
== prop_atoms
.net_wm_state_remove
||
3104 action
== prop_atoms
.net_wm_state_toggle
))
3105 /* an invalid action was passed to the client message, ignore it */
3108 for (i
= 0; i
< 2; ++i
) {
3109 Atom state
= i
== 0 ? data1
: data2
;
3111 if (!state
) continue;
3113 /* if toggling, then pick whether we're adding or removing */
3114 if (action
== prop_atoms
.net_wm_state_toggle
) {
3115 if (state
== prop_atoms
.net_wm_state_modal
)
3116 action
= modal
? prop_atoms
.net_wm_state_remove
:
3117 prop_atoms
.net_wm_state_add
;
3118 else if (state
== prop_atoms
.net_wm_state_maximized_vert
)
3119 action
= self
->max_vert
? prop_atoms
.net_wm_state_remove
:
3120 prop_atoms
.net_wm_state_add
;
3121 else if (state
== prop_atoms
.net_wm_state_maximized_horz
)
3122 action
= self
->max_horz
? prop_atoms
.net_wm_state_remove
:
3123 prop_atoms
.net_wm_state_add
;
3124 else if (state
== prop_atoms
.net_wm_state_shaded
)
3125 action
= shaded
? prop_atoms
.net_wm_state_remove
:
3126 prop_atoms
.net_wm_state_add
;
3127 else if (state
== prop_atoms
.net_wm_state_skip_taskbar
)
3128 action
= self
->skip_taskbar
?
3129 prop_atoms
.net_wm_state_remove
:
3130 prop_atoms
.net_wm_state_add
;
3131 else if (state
== prop_atoms
.net_wm_state_skip_pager
)
3132 action
= self
->skip_pager
?
3133 prop_atoms
.net_wm_state_remove
:
3134 prop_atoms
.net_wm_state_add
;
3135 else if (state
== prop_atoms
.net_wm_state_hidden
)
3136 action
= self
->iconic
?
3137 prop_atoms
.net_wm_state_remove
:
3138 prop_atoms
.net_wm_state_add
;
3139 else if (state
== prop_atoms
.net_wm_state_fullscreen
)
3140 action
= fullscreen
?
3141 prop_atoms
.net_wm_state_remove
:
3142 prop_atoms
.net_wm_state_add
;
3143 else if (state
== prop_atoms
.net_wm_state_above
)
3144 action
= self
->above
? prop_atoms
.net_wm_state_remove
:
3145 prop_atoms
.net_wm_state_add
;
3146 else if (state
== prop_atoms
.net_wm_state_below
)
3147 action
= self
->below
? prop_atoms
.net_wm_state_remove
:
3148 prop_atoms
.net_wm_state_add
;
3149 else if (state
== prop_atoms
.net_wm_state_demands_attention
)
3150 action
= self
->demands_attention
?
3151 prop_atoms
.net_wm_state_remove
:
3152 prop_atoms
.net_wm_state_add
;
3153 else if (state
== prop_atoms
.openbox_wm_state_undecorated
)
3154 action
= undecorated
? prop_atoms
.net_wm_state_remove
:
3155 prop_atoms
.net_wm_state_add
;
3158 if (action
== prop_atoms
.net_wm_state_add
) {
3159 if (state
== prop_atoms
.net_wm_state_modal
) {
3161 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
3163 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
3165 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
3167 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
3168 self
->skip_taskbar
= TRUE
;
3169 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
3170 self
->skip_pager
= TRUE
;
3171 } else if (state
== prop_atoms
.net_wm_state_hidden
) {
3173 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
3175 } else if (state
== prop_atoms
.net_wm_state_above
) {
3178 } else if (state
== prop_atoms
.net_wm_state_below
) {
3181 } else if (state
== prop_atoms
.net_wm_state_demands_attention
) {
3182 demands_attention
= TRUE
;
3183 } else if (state
== prop_atoms
.openbox_wm_state_undecorated
) {
3187 } else { /* action == prop_atoms.net_wm_state_remove */
3188 if (state
== prop_atoms
.net_wm_state_modal
) {
3190 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
3192 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
3194 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
3196 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
3197 self
->skip_taskbar
= FALSE
;
3198 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
3199 self
->skip_pager
= FALSE
;
3200 } else if (state
== prop_atoms
.net_wm_state_hidden
) {
3202 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
3204 } else if (state
== prop_atoms
.net_wm_state_above
) {
3206 } else if (state
== prop_atoms
.net_wm_state_below
) {
3208 } else if (state
== prop_atoms
.net_wm_state_demands_attention
) {
3209 demands_attention
= FALSE
;
3210 } else if (state
== prop_atoms
.openbox_wm_state_undecorated
) {
3211 undecorated
= FALSE
;
3215 if (max_horz
!= self
->max_horz
|| max_vert
!= self
->max_vert
) {
3216 if (max_horz
!= self
->max_horz
&& max_vert
!= self
->max_vert
) {
3218 if (max_horz
== max_vert
) { /* both going the same way */
3219 client_maximize(self
, max_horz
, 0);
3221 client_maximize(self
, max_horz
, 1);
3222 client_maximize(self
, max_vert
, 2);
3226 if (max_horz
!= self
->max_horz
)
3227 client_maximize(self
, max_horz
, 1);
3229 client_maximize(self
, max_vert
, 2);
3232 /* change fullscreen state before shading, as it will affect if the window
3234 if (fullscreen
!= self
->fullscreen
)
3235 client_fullscreen(self
, fullscreen
);
3236 if (shaded
!= self
->shaded
)
3237 client_shade(self
, shaded
);
3238 if (undecorated
!= self
->undecorated
)
3239 client_set_undecorated(self
, undecorated
);
3240 if (modal
!= self
->modal
) {
3241 self
->modal
= modal
;
3242 /* when a window changes modality, then its stacking order with its
3243 transients needs to change */
3246 if (iconic
!= self
->iconic
)
3247 client_iconify(self
, iconic
, FALSE
);
3249 if (demands_attention
!= self
->demands_attention
)
3250 client_hilite(self
, demands_attention
);
3252 if (above
!= self
->above
|| below
!= self
->below
) {
3253 self
->above
= above
;
3254 self
->below
= below
;
3255 client_calc_layer(self
);
3258 client_change_state(self
); /* change the hint to reflect these changes */
3261 ObClient
*client_focus_target(ObClient
*self
)
3263 ObClient
*child
= NULL
;
3265 child
= client_search_modal_child(self
);
3266 if (child
) return child
;
3270 gboolean
client_can_focus(ObClient
*self
)
3274 /* choose the correct target */
3275 self
= client_focus_target(self
);
3277 if (!self
->frame
->visible
)
3280 if (!(self
->can_focus
|| self
->focus_notify
))
3283 /* do a check to see if the window has already been unmapped or destroyed
3284 do this intelligently while watching out for unmaps we've generated
3285 (ignore_unmaps > 0) */
3286 if (XCheckTypedWindowEvent(ob_display
, self
->window
,
3287 DestroyNotify
, &ev
)) {
3288 XPutBackEvent(ob_display
, &ev
);
3291 while (XCheckTypedWindowEvent(ob_display
, self
->window
,
3292 UnmapNotify
, &ev
)) {
3293 if (self
->ignore_unmaps
) {
3294 self
->ignore_unmaps
--;
3296 XPutBackEvent(ob_display
, &ev
);
3304 gboolean
client_focus(ObClient
*self
)
3306 /* choose the correct target */
3307 self
= client_focus_target(self
);
3309 if (!client_can_focus(self
)) {
3310 if (!self
->frame
->visible
) {
3311 /* update the focus lists */
3312 focus_order_to_top(self
);
3317 ob_debug_type(OB_DEBUG_FOCUS
,
3318 "Focusing client \"%s\" at time %u\n",
3319 self
->title
, event_curtime
);
3321 if (self
->can_focus
) {
3322 /* This can cause a BadMatch error with CurrentTime, or if an app
3323 passed in a bad time for _NET_WM_ACTIVE_WINDOW. */
3324 xerror_set_ignore(TRUE
);
3325 XSetInputFocus(ob_display
, self
->window
, RevertToPointerRoot
,
3327 xerror_set_ignore(FALSE
);
3330 if (self
->focus_notify
) {
3332 ce
.xclient
.type
= ClientMessage
;
3333 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
3334 ce
.xclient
.display
= ob_display
;
3335 ce
.xclient
.window
= self
->window
;
3336 ce
.xclient
.format
= 32;
3337 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_take_focus
;
3338 ce
.xclient
.data
.l
[1] = event_curtime
;
3339 ce
.xclient
.data
.l
[2] = 0l;
3340 ce
.xclient
.data
.l
[3] = 0l;
3341 ce
.xclient
.data
.l
[4] = 0l;
3342 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
3346 ob_debug("%sively focusing %lx at %d\n",
3347 (self
->can_focus
? "act" : "pass"),
3348 self
->window
, (gint
) event_curtime
);
3351 /* Cause the FocusIn to come back to us. Important for desktop switches,
3352 since otherwise we'll have no FocusIn on the queue and send it off to
3353 the focus_backup. */
3354 XSync(ob_display
, FALSE
);
3358 /*! Present the client to the user.
3359 @param raise If the client should be raised or not. You should only set
3360 raise to false if you don't care if the window is completely
3363 static void client_present(ObClient
*self
, gboolean here
, gboolean raise
)
3365 /* if using focus_delay, stop the timer now so that focus doesn't
3367 event_halt_focus_delay();
3369 if (client_normal(self
) && screen_showing_desktop
)
3370 screen_show_desktop(FALSE
, FALSE
);
3372 client_iconify(self
, FALSE
, here
);
3373 if (self
->desktop
!= DESKTOP_ALL
&&
3374 self
->desktop
!= screen_desktop
)
3377 client_set_desktop(self
, screen_desktop
, FALSE
);
3379 screen_set_desktop(self
->desktop
, FALSE
);
3380 } else if (!self
->frame
->visible
)
3381 /* if its not visible for other reasons, then don't mess
3385 client_shade(self
, FALSE
);
3390 /* we do this as an action here. this is rather important. this is
3391 because we want the results from the focus change to take place
3392 BEFORE we go about raising the window. when a fullscreen window
3393 loses focus, we need this or else the raise wont be able to raise
3394 above the to-lose-focus fullscreen window. */
3399 void client_activate(ObClient
*self
, gboolean here
, gboolean user
)
3401 guint32 last_time
= focus_client
? focus_client
->user_time
: CurrentTime
;
3402 gboolean allow
= FALSE
;
3404 /* if the request came from the user, or if nothing is focused, then grant
3406 if the currently focused app doesn't set a user_time, then it can't
3407 benefit from any focus stealing prevention.
3409 if (user
|| !focus_client
|| !last_time
)
3411 /* otherwise, if they didn't give a time stamp or if it is too old, they
3414 allow
= event_curtime
&& event_time_after(event_curtime
, last_time
);
3416 ob_debug_type(OB_DEBUG_FOCUS
,
3417 "Want to activate window 0x%x with time %u (last time %u), "
3418 "source=%s allowing? %d\n",
3419 self
->window
, event_curtime
, last_time
,
3420 (user
? "user" : "application"), allow
);
3423 if (event_curtime
!= CurrentTime
)
3424 self
->user_time
= event_curtime
;
3426 client_present(self
, here
, TRUE
);
3428 /* don't focus it but tell the user it wants attention */
3429 client_hilite(self
, TRUE
);
3432 static void client_bring_helper_windows_recursive(ObClient
*self
,
3437 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
3438 client_bring_helper_windows_recursive(it
->data
, desktop
);
3440 if (client_helper(self
) &&
3441 self
->desktop
!= desktop
&& self
->desktop
!= DESKTOP_ALL
)
3443 client_set_desktop(self
, desktop
, FALSE
);
3447 void client_bring_helper_windows(ObClient
*self
)
3449 client_bring_helper_windows_recursive(self
, self
->desktop
);
3452 void client_raise(ObClient
*self
)
3454 action_run_string("Raise", self
, CurrentTime
);
3457 void client_lower(ObClient
*self
)
3459 action_run_string("Lower", self
, CurrentTime
);
3462 gboolean
client_focused(ObClient
*self
)
3464 return self
== focus_client
;
3467 static ObClientIcon
* client_icon_recursive(ObClient
*self
, gint w
, gint h
)
3470 /* si is the smallest image >= req */
3471 /* li is the largest image < req */
3472 gulong size
, smallest
= 0xffffffff, largest
= 0, si
= 0, li
= 0;
3474 if (!self
->nicons
) {
3475 ObClientIcon
*parent
= NULL
;
3477 if (self
->transient_for
) {
3478 if (self
->transient_for
!= OB_TRAN_GROUP
)
3479 parent
= client_icon_recursive(self
->transient_for
, w
, h
);
3482 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
3483 ObClient
*c
= it
->data
;
3484 if (c
!= self
&& !c
->transient_for
) {
3485 if ((parent
= client_icon_recursive(c
, w
, h
)))
3495 for (i
= 0; i
< self
->nicons
; ++i
) {
3496 size
= self
->icons
[i
].width
* self
->icons
[i
].height
;
3497 if (size
< smallest
&& size
>= (unsigned)(w
* h
)) {
3501 if (size
> largest
&& size
<= (unsigned)(w
* h
)) {
3506 if (largest
== 0) /* didnt find one smaller than the requested size */
3507 return &self
->icons
[si
];
3508 return &self
->icons
[li
];
3511 const ObClientIcon
* client_icon(ObClient
*self
, gint w
, gint h
)
3514 static ObClientIcon deficon
;
3516 if (!(ret
= client_icon_recursive(self
, w
, h
))) {
3517 deficon
.width
= deficon
.height
= 48;
3518 deficon
.data
= ob_rr_theme
->def_win_icon
;
3524 void client_set_layer(ObClient
*self
, gint layer
)
3528 self
->above
= FALSE
;
3529 } else if (layer
== 0) {
3530 self
->below
= self
->above
= FALSE
;
3532 self
->below
= FALSE
;
3535 client_calc_layer(self
);
3536 client_change_state(self
); /* reflect this in the state hints */
3539 void client_set_undecorated(ObClient
*self
, gboolean undecorated
)
3541 if (self
->undecorated
!= undecorated
) {
3542 self
->undecorated
= undecorated
;
3543 client_setup_decor_and_functions(self
);
3544 /* Make sure the client knows it might have moved. Maybe there is a
3545 * better way of doing this so only one client_configure is sent, but
3546 * since 125 of these are sent per second when moving the window (with
3547 * user = FALSE) i doubt it matters much.
3549 client_configure(self
, self
->area
.x
, self
->area
.y
,
3550 self
->area
.width
, self
->area
.height
, TRUE
, TRUE
);
3551 client_change_state(self
); /* reflect this in the state hints */
3555 guint
client_monitor(ObClient
*self
)
3557 return screen_find_monitor(&self
->frame
->area
);
3560 ObClient
*client_search_top_normal_parent(ObClient
*self
)
3562 while (self
->transient_for
&& self
->transient_for
!= OB_TRAN_GROUP
&&
3563 client_normal(self
->transient_for
))
3564 self
= self
->transient_for
;
3568 static GSList
*client_search_all_top_parents_internal(ObClient
*self
,
3570 ObStackingLayer layer
)
3574 /* move up the direct transient chain as far as possible */
3575 while (self
->transient_for
&& self
->transient_for
!= OB_TRAN_GROUP
&&
3576 (!bylayer
|| self
->transient_for
->layer
== layer
) &&
3577 client_normal(self
->transient_for
))
3578 self
= self
->transient_for
;
3580 if (!self
->transient_for
)
3581 ret
= g_slist_prepend(ret
, self
);
3585 g_assert(self
->group
);
3587 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
3588 ObClient
*c
= it
->data
;
3590 if (!c
->transient_for
&& client_normal(c
) &&
3591 (!bylayer
|| c
->layer
== layer
))
3593 ret
= g_slist_prepend(ret
, c
);
3597 if (ret
== NULL
) /* no group parents */
3598 ret
= g_slist_prepend(ret
, self
);
3604 GSList
*client_search_all_top_parents(ObClient
*self
)
3606 return client_search_all_top_parents_internal(self
, FALSE
, 0);
3609 GSList
*client_search_all_top_parents_layer(ObClient
*self
)
3611 return client_search_all_top_parents_internal(self
, TRUE
, self
->layer
);
3614 ObClient
*client_search_focus_parent(ObClient
*self
)
3616 if (self
->transient_for
) {
3617 if (self
->transient_for
!= OB_TRAN_GROUP
) {
3618 if (client_focused(self
->transient_for
))
3619 return self
->transient_for
;
3623 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
3624 ObClient
*c
= it
->data
;
3626 /* checking transient_for prevents infinate loops! */
3627 if (c
!= self
&& !c
->transient_for
)
3628 if (client_focused(c
))
3637 ObClient
*client_search_parent(ObClient
*self
, ObClient
*search
)
3639 if (self
->transient_for
) {
3640 if (self
->transient_for
!= OB_TRAN_GROUP
) {
3641 if (self
->transient_for
== search
)
3646 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
3647 ObClient
*c
= it
->data
;
3649 /* checking transient_for prevents infinate loops! */
3650 if (c
!= self
&& !c
->transient_for
)
3660 ObClient
*client_search_transient(ObClient
*self
, ObClient
*search
)
3664 for (sit
= self
->transients
; sit
; sit
= g_slist_next(sit
)) {
3665 if (sit
->data
== search
)
3667 if (client_search_transient(sit
->data
, search
))
3673 #define WANT_EDGE(cur, c) \
3676 if(!client_normal(cur)) \
3678 if(screen_desktop != cur->desktop && cur->desktop != DESKTOP_ALL) \
3682 if(cur->layer < c->layer && !config_resist_layers_below) \
3685 #define HIT_EDGE(my_edge_start, my_edge_end, his_edge_start, his_edge_end) \
3686 if ((his_edge_start >= my_edge_start && \
3687 his_edge_start <= my_edge_end) || \
3688 (my_edge_start >= his_edge_start && \
3689 my_edge_start <= his_edge_end)) \
3692 /* finds the nearest edge in the given direction from the current client
3693 * note to self: the edge is the -frame- edge (the actual one), not the
3696 gint
client_directional_edge_search(ObClient
*c
, ObDirection dir
, gboolean hang
)
3698 gint dest
, monitor_dest
;
3699 gint my_edge_start
, my_edge_end
, my_offset
;
3706 a
= screen_area(c
->desktop
);
3707 monitor
= screen_area_monitor(c
->desktop
, client_monitor(c
));
3710 case OB_DIRECTION_NORTH
:
3711 my_edge_start
= c
->frame
->area
.x
;
3712 my_edge_end
= c
->frame
->area
.x
+ c
->frame
->area
.width
;
3713 my_offset
= c
->frame
->area
.y
+ (hang
? c
->frame
->area
.height
: 0);
3715 /* default: top of screen */
3716 dest
= a
->y
+ (hang
? c
->frame
->area
.height
: 0);
3717 monitor_dest
= monitor
->y
+ (hang
? c
->frame
->area
.height
: 0);
3718 /* if the monitor edge comes before the screen edge, */
3719 /* use that as the destination instead. (For xinerama) */
3720 if (monitor_dest
!= dest
&& my_offset
> monitor_dest
)
3721 dest
= monitor_dest
;
3723 for(it
= client_list
; it
&& my_offset
!= dest
; it
= g_list_next(it
)) {
3724 gint his_edge_start
, his_edge_end
, his_offset
;
3725 ObClient
*cur
= it
->data
;
3729 his_edge_start
= cur
->frame
->area
.x
;
3730 his_edge_end
= cur
->frame
->area
.x
+ cur
->frame
->area
.width
;
3731 his_offset
= cur
->frame
->area
.y
+
3732 (hang
? 0 : cur
->frame
->area
.height
);
3734 if(his_offset
+ 1 > my_offset
)
3737 if(his_offset
< dest
)
3740 HIT_EDGE(my_edge_start
, my_edge_end
, his_edge_start
, his_edge_end
)
3743 case OB_DIRECTION_SOUTH
:
3744 my_edge_start
= c
->frame
->area
.x
;
3745 my_edge_end
= c
->frame
->area
.x
+ c
->frame
->area
.width
;
3746 my_offset
= c
->frame
->area
.y
+ (hang
? 0 : c
->frame
->area
.height
);
3748 /* default: bottom of screen */
3749 dest
= a
->y
+ a
->height
- (hang
? c
->frame
->area
.height
: 0);
3750 monitor_dest
= monitor
->y
+ monitor
->height
-
3751 (hang
? c
->frame
->area
.height
: 0);
3752 /* if the monitor edge comes before the screen edge, */
3753 /* use that as the destination instead. (For xinerama) */
3754 if (monitor_dest
!= dest
&& my_offset
< monitor_dest
)
3755 dest
= monitor_dest
;
3757 for(it
= client_list
; it
&& my_offset
!= dest
; it
= g_list_next(it
)) {
3758 gint his_edge_start
, his_edge_end
, his_offset
;
3759 ObClient
*cur
= it
->data
;
3763 his_edge_start
= cur
->frame
->area
.x
;
3764 his_edge_end
= cur
->frame
->area
.x
+ cur
->frame
->area
.width
;
3765 his_offset
= cur
->frame
->area
.y
+
3766 (hang
? cur
->frame
->area
.height
: 0);
3769 if(his_offset
- 1 < my_offset
)
3772 if(his_offset
> dest
)
3775 HIT_EDGE(my_edge_start
, my_edge_end
, his_edge_start
, his_edge_end
)
3778 case OB_DIRECTION_WEST
:
3779 my_edge_start
= c
->frame
->area
.y
;
3780 my_edge_end
= c
->frame
->area
.y
+ c
->frame
->area
.height
;
3781 my_offset
= c
->frame
->area
.x
+ (hang
? c
->frame
->area
.width
: 0);
3783 /* default: leftmost egde of screen */
3784 dest
= a
->x
+ (hang
? c
->frame
->area
.width
: 0);
3785 monitor_dest
= monitor
->x
+ (hang
? c
->frame
->area
.width
: 0);
3786 /* if the monitor edge comes before the screen edge, */
3787 /* use that as the destination instead. (For xinerama) */
3788 if (monitor_dest
!= dest
&& my_offset
> monitor_dest
)
3789 dest
= monitor_dest
;
3791 for(it
= client_list
; it
&& my_offset
!= dest
; it
= g_list_next(it
)) {
3792 gint his_edge_start
, his_edge_end
, his_offset
;
3793 ObClient
*cur
= it
->data
;
3797 his_edge_start
= cur
->frame
->area
.y
;
3798 his_edge_end
= cur
->frame
->area
.y
+ cur
->frame
->area
.height
;
3799 his_offset
= cur
->frame
->area
.x
+
3800 (hang
? 0 : cur
->frame
->area
.width
);
3802 if(his_offset
+ 1 > my_offset
)
3805 if(his_offset
< dest
)
3808 HIT_EDGE(my_edge_start
, my_edge_end
, his_edge_start
, his_edge_end
)
3811 case OB_DIRECTION_EAST
:
3812 my_edge_start
= c
->frame
->area
.y
;
3813 my_edge_end
= c
->frame
->area
.y
+ c
->frame
->area
.height
;
3814 my_offset
= c
->frame
->area
.x
+ (hang
? 0 : c
->frame
->area
.width
);
3816 /* default: rightmost edge of screen */
3817 dest
= a
->x
+ a
->width
- (hang
? c
->frame
->area
.width
: 0);
3818 monitor_dest
= monitor
->x
+ monitor
->width
-
3819 (hang
? c
->frame
->area
.width
: 0);
3820 /* if the monitor edge comes before the screen edge, */
3821 /* use that as the destination instead. (For xinerama) */
3822 if (monitor_dest
!= dest
&& my_offset
< monitor_dest
)
3823 dest
= monitor_dest
;
3825 for(it
= client_list
; it
&& my_offset
!= dest
; it
= g_list_next(it
)) {
3826 gint his_edge_start
, his_edge_end
, his_offset
;
3827 ObClient
*cur
= it
->data
;
3831 his_edge_start
= cur
->frame
->area
.y
;
3832 his_edge_end
= cur
->frame
->area
.y
+ cur
->frame
->area
.height
;
3833 his_offset
= cur
->frame
->area
.x
+
3834 (hang
? cur
->frame
->area
.width
: 0);
3836 if(his_offset
- 1 < my_offset
)
3839 if(his_offset
> dest
)
3842 HIT_EDGE(my_edge_start
, my_edge_end
, his_edge_start
, his_edge_end
)
3845 case OB_DIRECTION_NORTHEAST
:
3846 case OB_DIRECTION_SOUTHEAST
:
3847 case OB_DIRECTION_NORTHWEST
:
3848 case OB_DIRECTION_SOUTHWEST
:
3849 /* not implemented */
3851 g_assert_not_reached();
3852 dest
= 0; /* suppress warning */
3857 ObClient
* client_under_pointer()
3861 ObClient
*ret
= NULL
;
3863 if (screen_pointer_pos(&x
, &y
)) {
3864 for (it
= stacking_list
; it
; it
= g_list_next(it
)) {
3865 if (WINDOW_IS_CLIENT(it
->data
)) {
3866 ObClient
*c
= WINDOW_AS_CLIENT(it
->data
);
3867 if (c
->frame
->visible
&&
3868 /* ignore all animating windows */
3869 !frame_iconify_animating(c
->frame
) &&
3870 RECT_CONTAINS(c
->frame
->area
, x
, y
))
3881 gboolean
client_has_group_siblings(ObClient
*self
)
3883 return self
->group
&& self
->group
->members
->next
;