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"
40 #include "menuframe.h"
43 #include "render/render.h"
50 #include <X11/Xutil.h>
52 /*! The event mask to grab on client windows */
53 #define CLIENT_EVENTMASK (PropertyChangeMask | StructureNotifyMask | \
56 #define CLIENT_NOPROPAGATEMASK (ButtonPressMask | ButtonReleaseMask | \
61 ObClientCallback func
;
65 GList
*client_list
= NULL
;
67 static GSList
*client_destructors
= NULL
;
69 static void client_get_all(ObClient
*self
, gboolean real
);
70 static void client_toggle_border(ObClient
*self
, gboolean show
);
71 static void client_get_startup_id(ObClient
*self
);
72 static void client_get_session_ids(ObClient
*self
);
73 static void client_get_area(ObClient
*self
);
74 static void client_get_desktop(ObClient
*self
);
75 static void client_get_state(ObClient
*self
);
76 static void client_get_shaped(ObClient
*self
);
77 static void client_get_mwm_hints(ObClient
*self
);
78 static void client_get_colormap(ObClient
*self
);
79 static void client_change_allowed_actions(ObClient
*self
);
80 static void client_change_state(ObClient
*self
);
81 static void client_change_wm_state(ObClient
*self
);
82 static void client_apply_startup_state(ObClient
*self
, gint x
, gint y
);
83 static void client_restore_session_state(ObClient
*self
);
84 static gboolean
client_restore_session_stacking(ObClient
*self
);
85 static ObAppSettings
*client_get_settings_state(ObClient
*self
);
86 static void client_update_transient_tree(ObClient
*self
,
87 ObGroup
*oldgroup
, ObGroup
*newgroup
,
90 static void client_present(ObClient
*self
, gboolean here
, gboolean raise
);
91 static GSList
*client_search_all_top_parents_internal(ObClient
*self
,
93 ObStackingLayer layer
);
95 void client_startup(gboolean reconfig
)
102 void client_shutdown(gboolean reconfig
)
104 if (reconfig
) return;
107 void client_add_destructor(ObClientCallback func
, gpointer data
)
109 ClientCallback
*d
= g_new(ClientCallback
, 1);
112 client_destructors
= g_slist_prepend(client_destructors
, d
);
115 void client_remove_destructor(ObClientCallback func
)
119 for (it
= client_destructors
; it
; it
= g_slist_next(it
)) {
120 ClientCallback
*d
= it
->data
;
121 if (d
->func
== func
) {
123 client_destructors
= g_slist_delete_link(client_destructors
, it
);
129 void client_set_list()
131 Window
*windows
, *win_it
;
133 guint size
= g_list_length(client_list
);
135 /* create an array of the window ids */
137 windows
= g_new(Window
, size
);
139 for (it
= client_list
; it
; it
= g_list_next(it
), ++win_it
)
140 *win_it
= ((ObClient
*)it
->data
)->window
;
144 PROP_SETA32(RootWindow(ob_display
, ob_screen
),
145 net_client_list
, window
, (gulong
*)windows
, size
);
154 void client_foreach_transient(ObClient *self, ObClientForeachFunc func, gpointer data)
158 for (it = self->transients; it; it = g_slist_next(it)) {
159 if (!func(it->data, data)) return;
160 client_foreach_transient(it->data, func, data);
164 void client_foreach_ancestor(ObClient *self, ObClientForeachFunc func, gpointer data)
166 if (self->transient_for) {
167 if (self->transient_for != OB_TRAN_GROUP) {
168 if (!func(self->transient_for, data)) return;
169 client_foreach_ancestor(self->transient_for, func, data);
173 for (it = self->group->members; it; it = g_slist_next(it))
174 if (it->data != self &&
175 !((ObClient*)it->data)->transient_for) {
176 if (!func(it->data, data)) return;
177 client_foreach_ancestor(it->data, func, data);
184 void client_manage_all()
189 XWindowAttributes attrib
;
191 XQueryTree(ob_display
, RootWindow(ob_display
, ob_screen
),
192 &w
, &w
, &children
, &nchild
);
194 /* remove all icon windows from the list */
195 for (i
= 0; i
< nchild
; i
++) {
196 if (children
[i
] == None
) continue;
197 wmhints
= XGetWMHints(ob_display
, children
[i
]);
199 if ((wmhints
->flags
& IconWindowHint
) &&
200 (wmhints
->icon_window
!= children
[i
]))
201 for (j
= 0; j
< nchild
; j
++)
202 if (children
[j
] == wmhints
->icon_window
) {
210 for (i
= 0; i
< nchild
; ++i
) {
211 if (children
[i
] == None
)
213 if (XGetWindowAttributes(ob_display
, children
[i
], &attrib
)) {
214 if (attrib
.override_redirect
) continue;
216 if (attrib
.map_state
!= IsUnmapped
)
217 client_manage(children
[i
]);
223 void client_manage(Window window
)
227 XWindowAttributes attrib
;
228 XSetWindowAttributes attrib_set
;
230 gboolean activate
= FALSE
;
231 ObAppSettings
*settings
;
236 /* check if it has already been unmapped by the time we started
237 mapping. the grab does a sync so we don't have to here */
238 if (XCheckTypedWindowEvent(ob_display
, window
, DestroyNotify
, &e
) ||
239 XCheckTypedWindowEvent(ob_display
, window
, UnmapNotify
, &e
))
241 XPutBackEvent(ob_display
, &e
);
243 ob_debug("Trying to manage unmapped window. Aborting that.\n");
245 return; /* don't manage it */
248 /* make sure it isn't an override-redirect window */
249 if (!XGetWindowAttributes(ob_display
, window
, &attrib
) ||
250 attrib
.override_redirect
)
253 return; /* don't manage it */
256 /* is the window a docking app */
257 if ((wmhint
= XGetWMHints(ob_display
, window
))) {
258 if ((wmhint
->flags
& StateHint
) &&
259 wmhint
->initial_state
== WithdrawnState
)
261 dock_add(window
, wmhint
);
269 ob_debug("Managing window: %lx\n", window
);
271 /* choose the events we want to receive on the CLIENT window */
272 attrib_set
.event_mask
= CLIENT_EVENTMASK
;
273 attrib_set
.do_not_propagate_mask
= CLIENT_NOPROPAGATEMASK
;
274 XChangeWindowAttributes(ob_display
, window
,
275 CWEventMask
|CWDontPropagate
, &attrib_set
);
277 /* create the ObClient struct, and populate it from the hints on the
279 self
= g_new0(ObClient
, 1);
280 self
->obwin
.type
= Window_Client
;
281 self
->window
= window
;
283 /* non-zero defaults */
284 self
->wmstate
= WithdrawnState
; /* make sure it gets updated first time */
285 self
->desktop
= screen_num_desktops
; /* always an invalid value */
286 self
->user_time
= focus_client
? focus_client
->user_time
: CurrentTime
;
288 client_get_all(self
, TRUE
);
289 /* per-app settings override stuff, and return the settings for other
291 settings
= client_get_settings_state(self
);
292 /* the session should get the last say */
293 client_restore_session_state(self
);
295 client_setup_decor_and_functions(self
);
298 Time t
= sn_app_started(self
->startup_id
, self
->class);
299 if (t
) self
->user_time
= t
;
302 /* update the focus lists, do this before the call to change_state or
303 it can end up in the list twice! */
304 focus_order_add_new(self
);
306 /* remove the client's border (and adjust re gravity) */
307 client_toggle_border(self
, FALSE
);
309 /* specify that if we exit, the window should not be destroyed and
310 should be reparented back to root automatically */
311 XChangeSaveSet(ob_display
, window
, SetModeInsert
);
313 /* create the decoration frame for the client window */
314 self
->frame
= frame_new(self
);
316 frame_grab_client(self
->frame
);
318 /* do this after we have a frame.. it uses the frame to help determine the
319 WM_STATE to apply. */
320 client_change_state(self
);
324 /* do this to add ourselves to the stacking list in a non-intrusive way */
325 client_calc_layer(self
);
327 /* focus the new window? */
328 if (ob_state() != OB_STATE_STARTING
&&
329 (!self
->session
|| self
->session
->focused
) &&
331 /* this means focus=true for window is same as config_focus_new=true */
332 ((config_focus_new
|| (settings
&& settings
->focus
== 1)) ||
333 client_search_focus_parent(self
)) &&
334 /* this checks for focus=false for the window */
335 (!settings
|| settings
->focus
!= 0) &&
336 /* note the check against Type_Normal/Dialog, not client_normal(self),
337 which would also include other types. in this case we want more
338 strict rules for focus */
339 (self
->type
== OB_CLIENT_TYPE_NORMAL
||
340 self
->type
== OB_CLIENT_TYPE_DIALOG
))
345 /* get the current position */
349 /* figure out placement for the window */
350 if (ob_state() == OB_STATE_RUNNING
) {
353 transient
= place_client(self
, &newx
, &newy
, settings
);
355 /* make sure the window is visible. */
356 client_find_onscreen(self
, &newx
, &newy
,
359 /* non-normal clients has less rules, and
360 windows that are being restored from a
361 session do also. we can assume you want
362 it back where you saved it. Clients saying
363 they placed themselves are subjected to
364 harder rules, ones that are placed by
365 place.c or by the user are allowed partially
366 off-screen and on xinerama divides (ie,
367 it is up to the placement routines to avoid
368 the xinerama divides) */
370 (((self
->positioned
& PPosition
) &&
371 !(self
->positioned
& USPosition
)) &&
372 client_normal(self
) &&
376 /* do this after the window is placed, so the premax/prefullscreen numbers
378 also, this moves the window to the position where it has been placed
380 ob_debug("placing window 0x%x at %d, %d with size %d x %d\n",
381 self
->window
, newx
, newy
, self
->area
.width
, self
->area
.height
);
383 ob_debug("session requested %d %d\n",
384 self
->session
->x
, self
->session
->y
);
386 client_apply_startup_state(self
, newx
, newy
);
388 mouse_grab_for_client(self
, TRUE
);
391 guint32 last_time
= focus_client
?
392 focus_client
->user_time
: CurrentTime
;
394 /* This is focus stealing prevention */
395 ob_debug_type(OB_DEBUG_FOCUS
,
396 "Want to focus new window 0x%x with time %u "
398 self
->window
, self
->user_time
, last_time
);
400 /* if it's on another desktop */
401 if (!(self
->desktop
== screen_desktop
|| self
->desktop
== DESKTOP_ALL
)
402 && /* the timestamp is from before you changed desktops */
403 self
->user_time
&& screen_desktop_user_time
&&
404 !event_time_after(self
->user_time
, screen_desktop_user_time
))
407 ob_debug_type(OB_DEBUG_FOCUS
,
408 "Not focusing the window because its on another "
411 /* If something is focused, and it's not our parent... */
412 else if (focus_client
&& client_search_focus_parent(self
) == NULL
)
414 /* If time stamp is old, don't steal focus */
415 if (self
->user_time
&& last_time
&&
416 !event_time_after(self
->user_time
, last_time
))
419 ob_debug_type(OB_DEBUG_FOCUS
,
420 "Not focusing the window because the time is "
423 /* Don't steal focus from globally active clients.
424 I stole this idea from KWin. It seems nice.
426 if (!(focus_client
->can_focus
|| focus_client
->focus_notify
)) {
428 ob_debug_type(OB_DEBUG_FOCUS
,
429 "Not focusing the window because a globally "
430 "active client has focus\n");
435 ob_debug_type(OB_DEBUG_FOCUS
,
436 "Focus stealing prevention activated for %s with "
437 "time %u (last time %u)\n",
438 self
->title
, self
->user_time
, last_time
);
439 /* if the client isn't focused, then hilite it so the user
441 client_hilite(self
, TRUE
);
445 /* This may look rather odd. Well it's because new windows are added
446 to the stacking order non-intrusively. If we're not going to focus
447 the new window or hilite it, then we raise it to the top. This will
448 take affect for things that don't get focused like splash screens.
449 Also if you don't have focus_new enabled, then it's going to get
450 raised to the top. Legacy begets legacy I guess?
452 if (!client_restore_session_stacking(self
))
453 stacking_raise(CLIENT_AS_WINDOW(self
));
456 /* this has to happen before we try focus the window, but we want it to
457 happen after the client's stacking has been determined or it looks bad
461 /* use client_focus instead of client_activate cuz client_activate does
462 stuff like switch desktops etc and I'm not interested in all that when
463 a window maps since its not based on an action from the user like
464 clicking a window to activate it. so keep the new window out of the way
467 gboolean stacked
= client_restore_session_stacking(self
);
468 client_present(self
, FALSE
, !stacked
);
471 /* add to client list/map */
472 client_list
= g_list_append(client_list
, self
);
473 g_hash_table_insert(window_map
, &self
->window
, self
);
475 /* this has to happen after we're in the client_list */
476 if (STRUT_EXISTS(self
->strut
))
477 screen_update_areas();
479 /* update the list hints */
482 ob_debug("Managed window 0x%lx (%s)\n", window
, self
->class);
488 ObClient
*client_fake_manage(Window window
)
491 ObAppSettings
*settings
;
493 ob_debug("Pretend-managing window: %lx\n", window
);
495 /* do this minimal stuff to figure out the client's decorations */
497 self
= g_new0(ObClient
, 1);
498 self
->window
= window
;
500 client_get_all(self
, FALSE
);
501 /* per-app settings override stuff, and return the settings for other
503 settings
= client_get_settings_state(self
);
505 client_setup_decor_and_functions(self
);
507 /* create the decoration frame for the client window and adjust its size */
508 self
->frame
= frame_new(self
);
509 frame_adjust_area(self
->frame
, FALSE
, TRUE
, TRUE
);
513 void client_unmanage_all()
515 while (client_list
!= NULL
)
516 client_unmanage(client_list
->data
);
519 void client_unmanage(ObClient
*self
)
524 ob_debug("Unmanaging window: %lx (%s) (%s)\n", self
->window
,
525 self
->class, self
->title
? self
->title
: "");
527 g_assert(self
!= NULL
);
529 /* we dont want events no more. do this before hiding the frame so we
530 don't generate more events */
531 XSelectInput(ob_display
, self
->window
, NoEventMask
);
533 frame_hide(self
->frame
);
534 /* flush to send the hide to the server quickly */
537 /* ignore enter events from the unmap so it doesnt mess with the
539 event_ignore_queued_enters();
541 mouse_grab_for_client(self
, FALSE
);
543 /* remove the window from our save set */
544 XChangeSaveSet(ob_display
, self
->window
, SetModeDelete
);
546 /* kill the property windows */
547 propwin_remove(self
->user_time_window
, OB_PROPWIN_USER_TIME
, self
);
549 /* update the focus lists */
550 focus_order_remove(self
);
551 if (client_focused(self
)) {
552 /* don't leave an invalid focus_client */
556 client_list
= g_list_remove(client_list
, self
);
557 stacking_remove(self
);
558 g_hash_table_remove(window_map
, &self
->window
);
560 /* once the client is out of the list, update the struts to remove its
562 if (STRUT_EXISTS(self
->strut
))
563 screen_update_areas();
565 for (it
= client_destructors
; it
; it
= g_slist_next(it
)) {
566 ClientCallback
*d
= it
->data
;
567 d
->func(self
, d
->data
);
570 /* tell our parent(s) that we're gone */
571 if (self
->transient_for
== OB_TRAN_GROUP
) { /* transient of group */
572 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
))
573 if (it
->data
!= self
)
574 ((ObClient
*)it
->data
)->transients
=
575 g_slist_remove(((ObClient
*)it
->data
)->transients
,self
);
576 } else if (self
->transient_for
) { /* transient of window */
577 self
->transient_for
->transients
=
578 g_slist_remove(self
->transient_for
->transients
, self
);
581 /* tell our transients that we're gone */
582 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
583 if (((ObClient
*)it
->data
)->transient_for
!= OB_TRAN_GROUP
) {
584 ((ObClient
*)it
->data
)->transient_for
= NULL
;
585 client_calc_layer(it
->data
);
589 /* remove from its group */
591 group_remove(self
->group
, self
);
595 /* restore the window's original geometry so it is not lost */
599 if (self
->fullscreen
)
600 a
= self
->pre_fullscreen_area
;
601 else if (self
->max_horz
|| self
->max_vert
) {
602 if (self
->max_horz
) {
603 a
.x
= self
->pre_max_area
.x
;
604 a
.width
= self
->pre_max_area
.width
;
606 if (self
->max_vert
) {
607 a
.y
= self
->pre_max_area
.y
;
608 a
.height
= self
->pre_max_area
.height
;
612 /* give the client its border back */
613 client_toggle_border(self
, TRUE
);
615 self
->fullscreen
= self
->max_horz
= self
->max_vert
= FALSE
;
616 self
->decorations
= 0; /* unmanaged windows have no decor */
618 client_move_resize(self
, a
.x
, a
.y
, a
.width
, a
.height
);
621 /* reparent the window out of the frame, and free the frame */
622 frame_release_client(self
->frame
);
623 frame_free(self
->frame
);
626 if (ob_state() != OB_STATE_EXITING
) {
627 /* these values should not be persisted across a window
629 PROP_ERASE(self
->window
, net_wm_desktop
);
630 PROP_ERASE(self
->window
, net_wm_state
);
631 PROP_ERASE(self
->window
, wm_state
);
633 /* if we're left in an unmapped state, the client wont be mapped.
634 this is bad, since we will no longer be managing the window on
636 XMapWindow(ob_display
, self
->window
);
639 /* update the list hints */
642 ob_debug("Unmanaged window 0x%lx\n", self
->window
);
644 /* free all data allocated in the client struct */
645 g_slist_free(self
->transients
);
646 for (j
= 0; j
< self
->nicons
; ++j
)
647 g_free(self
->icons
[j
].data
);
648 if (self
->nicons
> 0)
650 g_free(self
->wm_command
);
652 g_free(self
->icon_title
);
656 g_free(self
->client_machine
);
657 g_free(self
->sm_client_id
);
661 void client_fake_unmanage(ObClient
*self
)
663 /* this is all that got allocated to get the decorations */
665 frame_free(self
->frame
);
669 static ObAppSettings
*client_get_settings_state(ObClient
*self
)
671 ObAppSettings
*settings
= NULL
;
674 for (it
= config_per_app_settings
; it
; it
= g_slist_next(it
)) {
675 ObAppSettings
*app
= it
->data
;
677 if ((app
->name
&& !app
->class && !strcmp(app
->name
, self
->name
))
678 || (app
->class && !app
->name
&& !strcmp(app
->class, self
->class))
679 || (app
->class && app
->name
&& !strcmp(app
->class, self
->class)
680 && !strcmp(app
->name
, self
->name
)))
682 /* Match if no role was specified in the per app setting, or if the
683 * string matches the beginning of the role, since apps like to set
684 * the role to things like browser-window-23c4b2f */
686 || !strncmp(app
->role
, self
->role
, strlen(app
->role
)))
688 ob_debug("Window matching: %s\n", app
->name
);
697 if (settings
->shade
!= -1)
698 self
->shaded
= !!settings
->shade
;
699 if (settings
->decor
!= -1)
700 self
->undecorated
= !settings
->decor
;
701 if (settings
->iconic
!= -1)
702 self
->iconic
= !!settings
->iconic
;
703 if (settings
->skip_pager
!= -1)
704 self
->skip_pager
= !!settings
->skip_pager
;
705 if (settings
->skip_taskbar
!= -1)
706 self
->skip_taskbar
= !!settings
->skip_taskbar
;
708 if (settings
->max_vert
!= -1)
709 self
->max_vert
= !!settings
->max_vert
;
710 if (settings
->max_horz
!= -1)
711 self
->max_horz
= !!settings
->max_horz
;
713 if (settings
->fullscreen
!= -1)
714 self
->fullscreen
= !!settings
->fullscreen
;
716 if (settings
->desktop
) {
717 if (settings
->desktop
== DESKTOP_ALL
)
718 self
->desktop
= settings
->desktop
;
719 else if (settings
->desktop
> 0 &&
720 settings
->desktop
<= screen_num_desktops
)
721 self
->desktop
= settings
->desktop
- 1;
724 if (settings
->layer
== -1) {
728 else if (settings
->layer
== 0) {
732 else if (settings
->layer
== 1) {
740 static void client_restore_session_state(ObClient
*self
)
744 ob_debug_type(OB_DEBUG_SM
,
745 "Restore session for client %s\n", self
->title
);
747 if (!(it
= session_state_find(self
))) {
748 ob_debug_type(OB_DEBUG_SM
,
749 "Session data not found for client %s\n", self
->title
);
753 self
->session
= it
->data
;
755 ob_debug_type(OB_DEBUG_SM
, "Session data loaded for client %s\n",
758 RECT_SET_POINT(self
->area
, self
->session
->x
, self
->session
->y
);
759 self
->positioned
= USPosition
;
760 if (self
->session
->w
> 0)
761 self
->area
.width
= self
->session
->w
;
762 if (self
->session
->h
> 0)
763 self
->area
.height
= self
->session
->h
;
764 XResizeWindow(ob_display
, self
->window
,
765 self
->area
.width
, self
->area
.height
);
767 self
->desktop
= (self
->session
->desktop
== DESKTOP_ALL
?
768 self
->session
->desktop
:
769 MIN(screen_num_desktops
- 1, self
->session
->desktop
));
770 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, self
->desktop
);
772 self
->shaded
= self
->session
->shaded
;
773 self
->iconic
= self
->session
->iconic
;
774 self
->skip_pager
= self
->session
->skip_pager
;
775 self
->skip_taskbar
= self
->session
->skip_taskbar
;
776 self
->fullscreen
= self
->session
->fullscreen
;
777 self
->above
= self
->session
->above
;
778 self
->below
= self
->session
->below
;
779 self
->max_horz
= self
->session
->max_horz
;
780 self
->max_vert
= self
->session
->max_vert
;
781 self
->undecorated
= self
->session
->undecorated
;
784 static gboolean
client_restore_session_stacking(ObClient
*self
)
788 if (!self
->session
) return FALSE
;
790 mypos
= g_list_find(session_saved_state
, self
->session
);
791 if (!mypos
) return FALSE
;
793 /* start above me and look for the first client */
794 for (it
= g_list_previous(mypos
); it
; it
= g_list_previous(it
)) {
797 for (cit
= client_list
; cit
; cit
= g_list_next(cit
)) {
798 ObClient
*c
= cit
->data
;
799 /* found a client that was in the session, so go below it */
800 if (c
->session
== it
->data
) {
801 stacking_below(CLIENT_AS_WINDOW(self
),
802 CLIENT_AS_WINDOW(cit
->data
));
810 void client_move_onscreen(ObClient
*self
, gboolean rude
)
812 gint x
= self
->area
.x
;
813 gint y
= self
->area
.y
;
814 if (client_find_onscreen(self
, &x
, &y
,
816 self
->area
.height
, rude
)) {
817 client_move(self
, x
, y
);
821 gboolean
client_find_onscreen(ObClient
*self
, gint
*x
, gint
*y
, gint w
, gint h
,
825 gint ox
= *x
, oy
= *y
;
826 gboolean rudel
= rude
, ruder
= rude
, rudet
= rude
, rudeb
= rude
;
829 all_a
= screen_area(self
->desktop
);
830 mon_a
= screen_area_monitor(self
->desktop
, client_monitor(self
));
832 /* get where the frame would be */
833 frame_client_gravity(self
->frame
, x
, y
, w
, h
);
835 /* get the requested size of the window with decorations */
836 fw
= self
->frame
->size
.left
+ w
+ self
->frame
->size
.right
;
837 fh
= self
->frame
->size
.top
+ h
+ self
->frame
->size
.bottom
;
839 /* This makes sure windows aren't entirely outside of the screen so you
840 can't see them at all.
841 It makes sure 10% of the window is on the screen at least. At don't let
842 it move itself off the top of the screen, which would hide the titlebar
843 on you. (The user can still do this if they want too, it's only limiting
846 XXX watch for xinerama dead areas...
848 if (client_normal(self
)) {
849 if (!self
->strut
.right
&& *x
+ fw
/10 >= all_a
->x
+ all_a
->width
- 1)
850 *x
= all_a
->x
+ all_a
->width
- fw
/10;
851 if (!self
->strut
.bottom
&& *y
+ fh
/10 >= all_a
->y
+ all_a
->height
- 1)
852 *y
= all_a
->y
+ all_a
->height
- fh
/10;
853 if (!self
->strut
.left
&& *x
+ fw
*9/10 - 1 < all_a
->x
)
854 *x
= all_a
->x
- fw
*9/10;
855 if (!self
->strut
.top
&& *y
+ fh
*9/10 - 1 < all_a
->y
)
856 *y
= all_a
->y
- fw
*9/10;
859 /* If rudeness wasn't requested, then figure out of the client is currently
860 entirely on the screen. If it is, and the position isn't changing by
861 request, and it is enlarging, then be rude even though it wasn't
864 Point oldtl
, oldtr
, oldbl
, oldbr
;
865 Point newtl
, newtr
, newbl
, newbr
;
866 gboolean stationary_l
, stationary_r
, stationary_t
, stationary_b
;
868 POINT_SET(oldtl
, self
->frame
->area
.x
, self
->frame
->area
.y
);
869 POINT_SET(oldbr
, self
->frame
->area
.x
+ self
->frame
->area
.width
- 1,
870 self
->frame
->area
.y
+ self
->frame
->area
.height
- 1);
871 POINT_SET(oldtr
, oldbr
.x
, oldtl
.y
);
872 POINT_SET(oldbl
, oldtl
.x
, oldbr
.y
);
874 POINT_SET(newtl
, *x
, *y
);
875 POINT_SET(newbr
, *x
+ fw
- 1, *y
+ fh
- 1);
876 POINT_SET(newtr
, newbr
.x
, newtl
.y
);
877 POINT_SET(newbl
, newtl
.x
, newbr
.y
);
879 /* is it moving or just resizing from some corner? */
880 stationary_l
= oldtl
.x
== oldtl
.x
;
881 stationary_r
= oldtr
.x
== oldtr
.x
;
882 stationary_t
= oldtl
.y
== oldtl
.y
;
883 stationary_b
= oldbl
.y
== oldbl
.y
;
885 /* if left edge is growing and didnt move right edge */
886 if (stationary_r
&& newtl
.x
< oldtl
.x
)
888 /* if right edge is growing and didnt move left edge */
889 if (stationary_l
&& newtr
.x
> oldtr
.x
)
891 /* if top edge is growing and didnt move bottom edge */
892 if (stationary_b
&& newtl
.y
< oldtl
.y
)
894 /* if bottom edge is growing and didnt move top edge */
895 if (stationary_t
&& newbl
.y
> oldbl
.y
)
899 /* This here doesn't let windows even a pixel outside the struts/screen.
900 * When called from client_manage, programs placing themselves are
901 * forced completely onscreen, while things like
902 * xterm -geometry resolution-width/2 will work fine. Trying to
903 * place it completely offscreen will be handled in the above code.
904 * Sorry for this confused comment, i am tired. */
905 if (fw
<= mon_a
->width
) {
906 if (rudel
&& !self
->strut
.left
&& *x
< mon_a
->x
) *x
= mon_a
->x
;
907 if (ruder
&& !self
->strut
.right
&& *x
+ fw
> mon_a
->x
+ mon_a
->width
)
908 *x
= mon_a
->x
+ mon_a
->width
- fw
;
910 if (fh
<= mon_a
->height
) {
911 if (rudet
&& !self
->strut
.top
&& *y
< mon_a
->y
) *y
= mon_a
->y
;
912 if (rudeb
&& !self
->strut
.bottom
&& *y
+ fh
> mon_a
->y
+ mon_a
->height
)
913 *y
= mon_a
->y
+ mon_a
->height
- fh
;
916 /* get where the client should be */
917 frame_frame_gravity(self
->frame
, x
, y
, w
, h
);
919 return ox
!= *x
|| oy
!= *y
;
922 static void client_toggle_border(ObClient
*self
, gboolean show
)
924 /* adjust our idea of where the client is, based on its border. When the
925 border is removed, the client should now be considered to be in a
927 when re-adding the border to the client, the same operation needs to be
929 gint oldx
= self
->area
.x
, oldy
= self
->area
.y
;
930 gint x
= oldx
, y
= oldy
;
931 switch(self
->gravity
) {
933 case NorthWestGravity
:
935 case SouthWestGravity
:
937 case NorthEastGravity
:
939 case SouthEastGravity
:
940 if (show
) x
-= self
->border_width
* 2;
941 else x
+= self
->border_width
* 2;
948 if (show
) x
-= self
->border_width
;
949 else x
+= self
->border_width
;
952 switch(self
->gravity
) {
954 case NorthWestGravity
:
956 case NorthEastGravity
:
958 case SouthWestGravity
:
960 case SouthEastGravity
:
961 if (show
) y
-= self
->border_width
* 2;
962 else y
+= self
->border_width
* 2;
969 if (show
) y
-= self
->border_width
;
970 else y
+= self
->border_width
;
977 XSetWindowBorderWidth(ob_display
, self
->window
, self
->border_width
);
979 /* set border_width to 0 because there is no border to add into
980 calculations anymore */
981 self
->border_width
= 0;
983 XSetWindowBorderWidth(ob_display
, self
->window
, 0);
987 static void client_get_all(ObClient
*self
, gboolean real
)
989 /* this is needed for the frame to set itself up */
990 client_get_area(self
);
992 /* these things can change the decor and functions of the window */
994 client_get_mwm_hints(self
);
995 /* this can change the mwmhints for special cases */
996 client_get_type_and_transientness(self
);
997 client_get_state(self
);
998 client_update_normal_hints(self
);
1000 /* get the session related properties, these can change decorations
1001 from per-app settings */
1002 client_get_session_ids(self
);
1004 /* now we got everything that can affect the decorations */
1008 client_update_protocols(self
);
1010 client_update_wmhints(self
);
1011 /* this may have already been called from client_update_wmhints */
1012 if (self
->transient_for
== NULL
)
1013 client_update_transient_for(self
);
1015 client_get_startup_id(self
);
1016 client_get_desktop(self
);/* uses transient data/group/startup id if a
1017 desktop is not specified */
1018 client_get_shaped(self
);
1021 /* a couple type-based defaults for new windows */
1023 /* this makes sure that these windows appear on all desktops */
1024 if (self
->type
== OB_CLIENT_TYPE_DESKTOP
)
1025 self
->desktop
= DESKTOP_ALL
;
1029 client_update_sync_request_counter(self
);
1032 client_get_colormap(self
);
1033 client_update_title(self
);
1034 client_update_strut(self
);
1035 client_update_icons(self
);
1036 client_update_user_time_window(self
);
1037 if (!self
->user_time_window
) /* check if this would have been called */
1038 client_update_user_time(self
);
1039 client_update_icon_geometry(self
);
1042 static void client_get_startup_id(ObClient
*self
)
1044 if (!(PROP_GETS(self
->window
, net_startup_id
, utf8
, &self
->startup_id
)))
1046 PROP_GETS(self
->group
->leader
,
1047 net_startup_id
, utf8
, &self
->startup_id
);
1050 static void client_get_area(ObClient
*self
)
1052 XWindowAttributes wattrib
;
1055 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
1056 g_assert(ret
!= BadWindow
);
1058 RECT_SET(self
->area
, wattrib
.x
, wattrib
.y
, wattrib
.width
, wattrib
.height
);
1059 POINT_SET(self
->root_pos
, wattrib
.x
, wattrib
.y
);
1060 self
->border_width
= wattrib
.border_width
;
1062 ob_debug("client area: %d %d %d %d\n", wattrib
.x
, wattrib
.y
,
1063 wattrib
.width
, wattrib
.height
);
1066 static void client_get_desktop(ObClient
*self
)
1068 guint32 d
= screen_num_desktops
; /* an always-invalid value */
1070 if (PROP_GET32(self
->window
, net_wm_desktop
, cardinal
, &d
)) {
1071 if (d
>= screen_num_desktops
&& d
!= DESKTOP_ALL
)
1072 self
->desktop
= screen_num_desktops
- 1;
1076 gboolean trdesk
= FALSE
;
1078 if (self
->transient_for
) {
1079 if (self
->transient_for
!= OB_TRAN_GROUP
) {
1080 self
->desktop
= self
->transient_for
->desktop
;
1085 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
))
1086 if (it
->data
!= self
&&
1087 !((ObClient
*)it
->data
)->transient_for
) {
1088 self
->desktop
= ((ObClient
*)it
->data
)->desktop
;
1095 /* try get from the startup-notification protocol */
1096 if (sn_get_desktop(self
->startup_id
, &self
->desktop
)) {
1097 if (self
->desktop
>= screen_num_desktops
&&
1098 self
->desktop
!= DESKTOP_ALL
)
1099 self
->desktop
= screen_num_desktops
- 1;
1101 /* defaults to the current desktop */
1102 self
->desktop
= screen_desktop
;
1107 static void client_get_state(ObClient
*self
)
1112 if (PROP_GETA32(self
->window
, net_wm_state
, atom
, &state
, &num
)) {
1114 for (i
= 0; i
< num
; ++i
) {
1115 if (state
[i
] == prop_atoms
.net_wm_state_modal
)
1117 else if (state
[i
] == prop_atoms
.net_wm_state_shaded
)
1118 self
->shaded
= TRUE
;
1119 else if (state
[i
] == prop_atoms
.net_wm_state_hidden
)
1120 self
->iconic
= TRUE
;
1121 else if (state
[i
] == prop_atoms
.net_wm_state_skip_taskbar
)
1122 self
->skip_taskbar
= TRUE
;
1123 else if (state
[i
] == prop_atoms
.net_wm_state_skip_pager
)
1124 self
->skip_pager
= TRUE
;
1125 else if (state
[i
] == prop_atoms
.net_wm_state_fullscreen
)
1126 self
->fullscreen
= TRUE
;
1127 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_vert
)
1128 self
->max_vert
= TRUE
;
1129 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_horz
)
1130 self
->max_horz
= TRUE
;
1131 else if (state
[i
] == prop_atoms
.net_wm_state_above
)
1133 else if (state
[i
] == prop_atoms
.net_wm_state_below
)
1135 else if (state
[i
] == prop_atoms
.net_wm_state_demands_attention
)
1136 self
->demands_attention
= TRUE
;
1137 else if (state
[i
] == prop_atoms
.openbox_wm_state_undecorated
)
1138 self
->undecorated
= TRUE
;
1145 static void client_get_shaped(ObClient
*self
)
1147 self
->shaped
= FALSE
;
1149 if (extensions_shape
) {
1154 XShapeSelectInput(ob_display
, self
->window
, ShapeNotifyMask
);
1156 XShapeQueryExtents(ob_display
, self
->window
, &s
, &foo
,
1157 &foo
, &ufoo
, &ufoo
, &foo
, &foo
, &foo
, &ufoo
,
1159 self
->shaped
= (s
!= 0);
1164 void client_update_transient_for(ObClient
*self
)
1167 ObClient
*target
= NULL
;
1169 if (XGetTransientForHint(ob_display
, self
->window
, &t
)) {
1170 if (t
!= self
->window
) { /* cant be transient to itself! */
1171 target
= g_hash_table_lookup(window_map
, &t
);
1172 /* if this happens then we need to check for it*/
1173 g_assert(target
!= self
);
1174 if (target
&& !WINDOW_IS_CLIENT(target
)) {
1175 /* this can happen when a dialog is a child of
1176 a dockapp, for example */
1180 /* THIS IS SO ANNOYING ! ! ! ! Let me explain.... have a seat..
1182 Setting the transient_for to Root is actually illegal, however
1183 applications from time have done this to specify transient for
1186 Now you can do that by being a TYPE_DIALOG and not setting
1187 the transient_for hint at all on your window. But people still
1188 use Root, and Kwin is very strange in this regard.
1190 KWin 3.0 will not consider windows with transient_for set to
1191 Root as transient for their group *UNLESS* they are also modal.
1192 In that case, it will make them transient for the group. This
1193 leads to all sorts of weird behavior from KDE apps which are
1194 only tested in KWin. I'd like to follow their behavior just to
1195 make this work right with KDE stuff, but that seems wrong.
1197 if (!target
&& self
->group
) {
1198 /* not transient to a client, see if it is transient for a
1200 if (t
== RootWindow(ob_display
, ob_screen
)) {
1201 /* window is a transient for its group! */
1202 target
= OB_TRAN_GROUP
;
1206 } else if (self
->transient
&& self
->group
)
1207 target
= OB_TRAN_GROUP
;
1209 client_update_transient_tree(self
, self
->group
, self
->group
,
1210 self
->transient_for
, target
);
1211 self
->transient_for
= target
;
1215 static void client_update_transient_tree(ObClient
*self
,
1216 ObGroup
*oldgroup
, ObGroup
*newgroup
,
1217 ObClient
* oldparent
,
1218 ObClient
*newparent
)
1223 /* No change has occured */
1224 if (oldgroup
== newgroup
&& oldparent
== newparent
) return;
1226 /** Remove the client from the transient tree wherever it has changed **/
1228 /* If the window is becoming a direct transient for a window in its group
1229 then that window can't be a child of this window anymore */
1230 if (oldparent
!= newparent
&&
1231 newparent
!= NULL
&& newparent
!= OB_TRAN_GROUP
&&
1232 newparent
->transient_for
== OB_TRAN_GROUP
&&
1233 newgroup
!= NULL
&& newgroup
== oldgroup
)
1235 self
->transients
= g_slist_remove(self
->transients
, newparent
);
1239 /* If the group changed, or if we are just becoming transient for the
1240 group, then we need to remove any old group transient windows
1241 from our children. But if we were already transient for the group, then
1242 other group transients are not our children. */
1243 if ((oldgroup
!= newgroup
||
1244 (newparent
== OB_TRAN_GROUP
&& oldparent
!= newparent
)) &&
1245 oldgroup
!= NULL
&& oldparent
!= OB_TRAN_GROUP
)
1247 for (it
= self
->transients
; it
; it
= next
) {
1248 next
= g_slist_next(it
);
1250 if (c
->group
== oldgroup
)
1251 self
->transients
= g_slist_delete_link(self
->transients
, it
);
1255 /* If we used to be transient for a group and now we are not, or we're
1256 transient for a new group, then we need to remove ourselves from all
1258 if (oldparent
== OB_TRAN_GROUP
&& (oldgroup
!= newgroup
||
1259 oldparent
!= newparent
))
1261 for (it
= oldgroup
->members
; it
; it
= g_slist_next(it
)) {
1263 if (c
!= self
&& (!c
->transient_for
||
1264 c
->transient_for
!= OB_TRAN_GROUP
))
1265 c
->transients
= g_slist_remove(c
->transients
, self
);
1268 /* If we used to be transient for a single window and we are no longer
1269 transient for it, then we need to remove ourself from its children */
1270 else if (oldparent
!= NULL
&& oldparent
!= OB_TRAN_GROUP
&&
1271 oldparent
!= newparent
)
1272 oldparent
->transients
= g_slist_remove(oldparent
->transients
, self
);
1275 /** Re-add the client to the transient tree wherever it has changed **/
1277 /* If we're now transient for a group and we weren't transient for it
1278 before then we need to add ourselves to all our new parents */
1279 if (newparent
== OB_TRAN_GROUP
&& (oldgroup
!= newgroup
||
1280 oldparent
!= newparent
))
1282 for (it
= oldgroup
->members
; it
; it
= g_slist_next(it
)) {
1284 if (c
!= self
&& (!c
->transient_for
||
1285 c
->transient_for
!= OB_TRAN_GROUP
))
1286 c
->transients
= g_slist_prepend(c
->transients
, self
);
1289 /* If we are now transient for a single window which we weren't before,
1290 we need to add ourselves to its children
1292 WARNING: Cyclical transient ness is possible if two windows are
1293 transient for eachother.
1295 else if (newparent
!= NULL
&& newparent
!= OB_TRAN_GROUP
&&
1296 newparent
!= oldparent
&&
1297 /* don't make ourself its child if it is already our child */
1298 !client_is_direct_child(self
, newparent
))
1299 newparent
->transients
= g_slist_prepend(newparent
->transients
, self
);
1301 /* If the group changed then we need to add any new group transient
1302 windows to our children. But if we're transient for the group, then
1303 other group transients are not our children.
1305 WARNING: Cyclical transient-ness is possible. For e.g. if:
1306 A is transient for the group
1307 B is a member of the group and transient for A
1309 if (oldgroup
!= newgroup
&& newgroup
!= NULL
&&
1310 newparent
!= OB_TRAN_GROUP
)
1312 for (it
= newgroup
->members
; it
; it
= g_slist_next(it
)) {
1314 if (c
!= self
&& c
->transient_for
== OB_TRAN_GROUP
&&
1315 /* Don't make it our child if it is already our parent */
1316 !client_is_direct_child(c
, self
))
1318 self
->transients
= g_slist_prepend(self
->transients
, c
);
1324 static void client_get_mwm_hints(ObClient
*self
)
1329 self
->mwmhints
.flags
= 0; /* default to none */
1331 if (PROP_GETA32(self
->window
, motif_wm_hints
, motif_wm_hints
,
1333 if (num
>= OB_MWM_ELEMENTS
) {
1334 self
->mwmhints
.flags
= hints
[0];
1335 self
->mwmhints
.functions
= hints
[1];
1336 self
->mwmhints
.decorations
= hints
[2];
1342 void client_get_type_and_transientness(ObClient
*self
)
1349 self
->transient
= FALSE
;
1351 if (PROP_GETA32(self
->window
, net_wm_window_type
, atom
, &val
, &num
)) {
1352 /* use the first value that we know about in the array */
1353 for (i
= 0; i
< num
; ++i
) {
1354 if (val
[i
] == prop_atoms
.net_wm_window_type_desktop
)
1355 self
->type
= OB_CLIENT_TYPE_DESKTOP
;
1356 else if (val
[i
] == prop_atoms
.net_wm_window_type_dock
)
1357 self
->type
= OB_CLIENT_TYPE_DOCK
;
1358 else if (val
[i
] == prop_atoms
.net_wm_window_type_toolbar
)
1359 self
->type
= OB_CLIENT_TYPE_TOOLBAR
;
1360 else if (val
[i
] == prop_atoms
.net_wm_window_type_menu
)
1361 self
->type
= OB_CLIENT_TYPE_MENU
;
1362 else if (val
[i
] == prop_atoms
.net_wm_window_type_utility
)
1363 self
->type
= OB_CLIENT_TYPE_UTILITY
;
1364 else if (val
[i
] == prop_atoms
.net_wm_window_type_splash
)
1365 self
->type
= OB_CLIENT_TYPE_SPLASH
;
1366 else if (val
[i
] == prop_atoms
.net_wm_window_type_dialog
)
1367 self
->type
= OB_CLIENT_TYPE_DIALOG
;
1368 else if (val
[i
] == prop_atoms
.net_wm_window_type_normal
)
1369 self
->type
= OB_CLIENT_TYPE_NORMAL
;
1370 else if (val
[i
] == prop_atoms
.kde_net_wm_window_type_override
) {
1371 /* prevent this window from getting any decor or
1373 self
->mwmhints
.flags
&= (OB_MWM_FLAG_FUNCTIONS
|
1374 OB_MWM_FLAG_DECORATIONS
);
1375 self
->mwmhints
.decorations
= 0;
1376 self
->mwmhints
.functions
= 0;
1378 if (self
->type
!= (ObClientType
) -1)
1379 break; /* grab the first legit type */
1384 if (XGetTransientForHint(ob_display
, self
->window
, &t
))
1385 self
->transient
= TRUE
;
1387 if (self
->type
== (ObClientType
) -1) {
1388 /*the window type hint was not set, which means we either classify
1389 ourself as a normal window or a dialog, depending on if we are a
1391 if (self
->transient
)
1392 self
->type
= OB_CLIENT_TYPE_DIALOG
;
1394 self
->type
= OB_CLIENT_TYPE_NORMAL
;
1397 /* then, based on our type, we can update our transientness.. */
1398 if (self
->type
== OB_CLIENT_TYPE_DIALOG
||
1399 self
->type
== OB_CLIENT_TYPE_TOOLBAR
||
1400 self
->type
== OB_CLIENT_TYPE_MENU
||
1401 self
->type
== OB_CLIENT_TYPE_UTILITY
)
1403 self
->transient
= TRUE
;
1407 void client_update_protocols(ObClient
*self
)
1410 guint num_return
, i
;
1412 self
->focus_notify
= FALSE
;
1413 self
->delete_window
= FALSE
;
1415 if (PROP_GETA32(self
->window
, wm_protocols
, atom
, &proto
, &num_return
)) {
1416 for (i
= 0; i
< num_return
; ++i
) {
1417 if (proto
[i
] == prop_atoms
.wm_delete_window
)
1418 /* this means we can request the window to close */
1419 self
->delete_window
= TRUE
;
1420 else if (proto
[i
] == prop_atoms
.wm_take_focus
)
1421 /* if this protocol is requested, then the window will be
1422 notified whenever we want it to receive focus */
1423 self
->focus_notify
= TRUE
;
1425 else if (proto
[i
] == prop_atoms
.net_wm_sync_request
)
1426 /* if this protocol is requested, then resizing the
1427 window will be synchronized between the frame and the
1429 self
->sync_request
= TRUE
;
1437 void client_update_sync_request_counter(ObClient
*self
)
1441 if (PROP_GET32(self
->window
, net_wm_sync_request_counter
, cardinal
, &i
)) {
1442 self
->sync_counter
= i
;
1444 self
->sync_counter
= None
;
1448 void client_get_colormap(ObClient
*self
)
1450 XWindowAttributes wa
;
1452 if (XGetWindowAttributes(ob_display
, self
->window
, &wa
))
1453 client_update_colormap(self
, wa
.colormap
);
1456 void client_update_colormap(ObClient
*self
, Colormap colormap
)
1458 self
->colormap
= colormap
;
1461 void client_update_normal_hints(ObClient
*self
)
1465 gint oldgravity
= self
->gravity
;
1468 self
->min_ratio
= 0.0f
;
1469 self
->max_ratio
= 0.0f
;
1470 SIZE_SET(self
->size_inc
, 1, 1);
1471 SIZE_SET(self
->base_size
, 0, 0);
1472 SIZE_SET(self
->min_size
, 0, 0);
1473 SIZE_SET(self
->max_size
, G_MAXINT
, G_MAXINT
);
1475 /* get the hints from the window */
1476 if (XGetWMNormalHints(ob_display
, self
->window
, &size
, &ret
)) {
1477 /* normal windows can't request placement! har har
1478 if (!client_normal(self))
1480 self
->positioned
= (size
.flags
& (PPosition
|USPosition
));
1482 if (size
.flags
& PWinGravity
) {
1483 self
->gravity
= size
.win_gravity
;
1485 /* if the client has a frame, i.e. has already been mapped and
1486 is changing its gravity */
1487 if (self
->frame
&& self
->gravity
!= oldgravity
) {
1488 /* move our idea of the client's position based on its new
1490 client_convert_gravity(self
, oldgravity
,
1491 &self
->area
.x
, &self
->area
.y
,
1492 self
->area
.width
, self
->area
.height
);
1496 if (size
.flags
& PAspect
) {
1497 if (size
.min_aspect
.y
)
1499 (gfloat
) size
.min_aspect
.x
/ size
.min_aspect
.y
;
1500 if (size
.max_aspect
.y
)
1502 (gfloat
) size
.max_aspect
.x
/ size
.max_aspect
.y
;
1505 if (size
.flags
& PMinSize
)
1506 SIZE_SET(self
->min_size
, size
.min_width
, size
.min_height
);
1508 if (size
.flags
& PMaxSize
)
1509 SIZE_SET(self
->max_size
, size
.max_width
, size
.max_height
);
1511 if (size
.flags
& PBaseSize
)
1512 SIZE_SET(self
->base_size
, size
.base_width
, size
.base_height
);
1514 if (size
.flags
& PResizeInc
&& size
.width_inc
&& size
.height_inc
)
1515 SIZE_SET(self
->size_inc
, size
.width_inc
, size
.height_inc
);
1519 void client_setup_decor_and_functions(ObClient
*self
)
1521 /* start with everything (cept fullscreen) */
1523 (OB_FRAME_DECOR_TITLEBAR
|
1524 OB_FRAME_DECOR_HANDLE
|
1525 OB_FRAME_DECOR_GRIPS
|
1526 OB_FRAME_DECOR_BORDER
|
1527 OB_FRAME_DECOR_ICON
|
1528 OB_FRAME_DECOR_ALLDESKTOPS
|
1529 OB_FRAME_DECOR_ICONIFY
|
1530 OB_FRAME_DECOR_MAXIMIZE
|
1531 OB_FRAME_DECOR_SHADE
|
1532 OB_FRAME_DECOR_CLOSE
);
1534 (OB_CLIENT_FUNC_RESIZE
|
1535 OB_CLIENT_FUNC_MOVE
|
1536 OB_CLIENT_FUNC_ICONIFY
|
1537 OB_CLIENT_FUNC_MAXIMIZE
|
1538 OB_CLIENT_FUNC_SHADE
|
1539 OB_CLIENT_FUNC_CLOSE
);
1541 if (!(self
->min_size
.width
< self
->max_size
.width
||
1542 self
->min_size
.height
< self
->max_size
.height
))
1543 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
1545 switch (self
->type
) {
1546 case OB_CLIENT_TYPE_NORMAL
:
1547 /* normal windows retain all of the possible decorations and
1548 functionality, and are the only windows that you can fullscreen */
1549 self
->functions
|= OB_CLIENT_FUNC_FULLSCREEN
;
1552 case OB_CLIENT_TYPE_DIALOG
:
1553 case OB_CLIENT_TYPE_UTILITY
:
1554 /* these windows cannot be maximized */
1555 self
->functions
&= ~OB_CLIENT_FUNC_MAXIMIZE
;
1558 case OB_CLIENT_TYPE_MENU
:
1559 case OB_CLIENT_TYPE_TOOLBAR
:
1560 /* these windows get less functionality */
1561 self
->functions
&= ~(OB_CLIENT_FUNC_ICONIFY
| OB_CLIENT_FUNC_RESIZE
);
1564 case OB_CLIENT_TYPE_SPLASH
:
1565 /* these don't get get any decorations, and the only thing you can
1566 do with them is move them */
1567 self
->decorations
= 0;
1568 self
->functions
= OB_CLIENT_FUNC_MOVE
;
1570 case OB_CLIENT_TYPE_DESKTOP
:
1571 case OB_CLIENT_TYPE_DOCK
:
1572 /* these windows are not manipulated by the window manager */
1573 self
->decorations
= 0;
1574 self
->functions
= 0;
1578 /* Mwm Hints are applied subtractively to what has already been chosen for
1579 decor and functionality */
1580 if (self
->mwmhints
.flags
& OB_MWM_FLAG_DECORATIONS
) {
1581 if (! (self
->mwmhints
.decorations
& OB_MWM_DECOR_ALL
)) {
1582 if (! ((self
->mwmhints
.decorations
& OB_MWM_DECOR_HANDLE
) ||
1583 (self
->mwmhints
.decorations
& OB_MWM_DECOR_TITLE
)))
1585 /* if the mwm hints request no handle or title, then all
1586 decorations are disabled, but keep the border if that's
1588 if (self
->mwmhints
.decorations
& OB_MWM_DECOR_BORDER
)
1589 self
->decorations
= OB_FRAME_DECOR_BORDER
;
1591 self
->decorations
= 0;
1596 if (self
->mwmhints
.flags
& OB_MWM_FLAG_FUNCTIONS
) {
1597 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_ALL
)) {
1598 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_RESIZE
))
1599 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
1600 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_MOVE
))
1601 self
->functions
&= ~OB_CLIENT_FUNC_MOVE
;
1602 /* dont let mwm hints kill any buttons
1603 if (! (self->mwmhints.functions & OB_MWM_FUNC_ICONIFY))
1604 self->functions &= ~OB_CLIENT_FUNC_ICONIFY;
1605 if (! (self->mwmhints.functions & OB_MWM_FUNC_MAXIMIZE))
1606 self->functions &= ~OB_CLIENT_FUNC_MAXIMIZE;
1608 /* dont let mwm hints kill the close button
1609 if (! (self->mwmhints.functions & MwmFunc_Close))
1610 self->functions &= ~OB_CLIENT_FUNC_CLOSE; */
1614 if (!(self
->functions
& OB_CLIENT_FUNC_SHADE
))
1615 self
->decorations
&= ~OB_FRAME_DECOR_SHADE
;
1616 if (!(self
->functions
& OB_CLIENT_FUNC_ICONIFY
))
1617 self
->decorations
&= ~OB_FRAME_DECOR_ICONIFY
;
1618 if (!(self
->functions
& OB_CLIENT_FUNC_RESIZE
))
1619 self
->decorations
&= ~OB_FRAME_DECOR_GRIPS
;
1621 /* can't maximize without moving/resizing */
1622 if (!((self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) &&
1623 (self
->functions
& OB_CLIENT_FUNC_MOVE
) &&
1624 (self
->functions
& OB_CLIENT_FUNC_RESIZE
))) {
1625 self
->functions
&= ~OB_CLIENT_FUNC_MAXIMIZE
;
1626 self
->decorations
&= ~OB_FRAME_DECOR_MAXIMIZE
;
1629 /* kill the handle on fully maxed windows */
1630 if (self
->max_vert
&& self
->max_horz
)
1631 self
->decorations
&= ~(OB_FRAME_DECOR_HANDLE
| OB_FRAME_DECOR_GRIPS
);
1633 /* finally, the user can have requested no decorations, which overrides
1634 everything (but doesnt give it a border if it doesnt have one) */
1635 if (self
->undecorated
) {
1636 if (config_theme_keepborder
)
1637 self
->decorations
&= OB_FRAME_DECOR_BORDER
;
1639 self
->decorations
= 0;
1642 /* if we don't have a titlebar, then we cannot shade! */
1643 if (!(self
->decorations
& OB_FRAME_DECOR_TITLEBAR
))
1644 self
->functions
&= ~OB_CLIENT_FUNC_SHADE
;
1646 /* now we need to check against rules for the client's current state */
1647 if (self
->fullscreen
) {
1648 self
->functions
&= (OB_CLIENT_FUNC_CLOSE
|
1649 OB_CLIENT_FUNC_FULLSCREEN
|
1650 OB_CLIENT_FUNC_ICONIFY
);
1651 self
->decorations
= 0;
1654 client_change_allowed_actions(self
);
1657 /* adjust the client's decorations, etc. */
1658 client_reconfigure(self
);
1662 static void client_change_allowed_actions(ObClient
*self
)
1667 /* desktop windows are kept on all desktops */
1668 if (self
->type
!= OB_CLIENT_TYPE_DESKTOP
)
1669 actions
[num
++] = prop_atoms
.net_wm_action_change_desktop
;
1671 if (self
->functions
& OB_CLIENT_FUNC_SHADE
)
1672 actions
[num
++] = prop_atoms
.net_wm_action_shade
;
1673 if (self
->functions
& OB_CLIENT_FUNC_CLOSE
)
1674 actions
[num
++] = prop_atoms
.net_wm_action_close
;
1675 if (self
->functions
& OB_CLIENT_FUNC_MOVE
)
1676 actions
[num
++] = prop_atoms
.net_wm_action_move
;
1677 if (self
->functions
& OB_CLIENT_FUNC_ICONIFY
)
1678 actions
[num
++] = prop_atoms
.net_wm_action_minimize
;
1679 if (self
->functions
& OB_CLIENT_FUNC_RESIZE
)
1680 actions
[num
++] = prop_atoms
.net_wm_action_resize
;
1681 if (self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
)
1682 actions
[num
++] = prop_atoms
.net_wm_action_fullscreen
;
1683 if (self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) {
1684 actions
[num
++] = prop_atoms
.net_wm_action_maximize_horz
;
1685 actions
[num
++] = prop_atoms
.net_wm_action_maximize_vert
;
1688 PROP_SETA32(self
->window
, net_wm_allowed_actions
, atom
, actions
, num
);
1690 /* make sure the window isn't breaking any rules now */
1692 if (!(self
->functions
& OB_CLIENT_FUNC_SHADE
) && self
->shaded
) {
1693 if (self
->frame
) client_shade(self
, FALSE
);
1694 else self
->shaded
= FALSE
;
1696 if (!(self
->functions
& OB_CLIENT_FUNC_ICONIFY
) && self
->iconic
) {
1697 if (self
->frame
) client_iconify(self
, FALSE
, TRUE
, FALSE
);
1698 else self
->iconic
= FALSE
;
1700 if (!(self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
) && self
->fullscreen
) {
1701 if (self
->frame
) client_fullscreen(self
, FALSE
);
1702 else self
->fullscreen
= FALSE
;
1704 if (!(self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) && (self
->max_horz
||
1706 if (self
->frame
) client_maximize(self
, FALSE
, 0);
1707 else self
->max_vert
= self
->max_horz
= FALSE
;
1711 void client_reconfigure(ObClient
*self
)
1713 /* by making this pass FALSE for user, we avoid the emacs event storm where
1714 every configurenotify causes an update in its normal hints, i think this
1715 is generally what we want anyways... */
1716 client_configure(self
, self
->area
.x
, self
->area
.y
,
1717 self
->area
.width
, self
->area
.height
, FALSE
, TRUE
);
1720 void client_update_wmhints(ObClient
*self
)
1724 /* assume a window takes input if it doesnt specify */
1725 self
->can_focus
= TRUE
;
1727 if ((hints
= XGetWMHints(ob_display
, self
->window
)) != NULL
) {
1730 if (hints
->flags
& InputHint
)
1731 self
->can_focus
= hints
->input
;
1733 /* only do this when first managing the window *AND* when we aren't
1735 if (ob_state() != OB_STATE_STARTING
&& self
->frame
== NULL
)
1736 if (hints
->flags
& StateHint
)
1737 self
->iconic
= hints
->initial_state
== IconicState
;
1740 self
->urgent
= (hints
->flags
& XUrgencyHint
);
1741 if (self
->urgent
&& !ur
)
1742 client_hilite(self
, TRUE
);
1743 else if (!self
->urgent
&& ur
&& self
->demands_attention
)
1744 client_hilite(self
, FALSE
);
1746 if (!(hints
->flags
& WindowGroupHint
))
1747 hints
->window_group
= None
;
1749 /* did the group state change? */
1750 if (hints
->window_group
!=
1751 (self
->group
? self
->group
->leader
: None
))
1753 ObGroup
*oldgroup
= self
->group
;
1755 /* remove from the old group if there was one */
1756 if (self
->group
!= NULL
) {
1757 group_remove(self
->group
, self
);
1761 /* add ourself to the group if we have one */
1762 if (hints
->window_group
!= None
) {
1763 self
->group
= group_add(hints
->window_group
, self
);
1766 /* Put ourselves into the new group's transient tree, and remove
1767 ourselves from the old group's */
1768 client_update_transient_tree(self
, oldgroup
, self
->group
,
1769 self
->transient_for
,
1770 self
->transient_for
);
1772 /* Lastly, being in a group, or not, can change if the window is
1773 transient for anything.
1775 The logic for this is:
1776 self->transient = TRUE always if the window wants to be
1777 transient for something, even if transient_for was NULL because
1778 it wasn't in a group before.
1780 If transient_for was NULL and oldgroup was NULL we can assume
1781 that when we add the new group, it will become transient for
1784 If transient_for was OB_TRAN_GROUP, then it must have already
1785 had a group. If it is getting a new group, the above call to
1786 client_update_transient_tree has already taken care of
1787 everything ! If it is losing all group status then it will
1788 no longer be transient for anything and that needs to be
1791 if (self
->transient
&&
1792 ((self
->transient_for
== NULL
&& oldgroup
== NULL
) ||
1793 (self
->transient_for
== OB_TRAN_GROUP
&& !self
->group
)))
1794 client_update_transient_for(self
);
1797 /* the WM_HINTS can contain an icon */
1798 client_update_icons(self
);
1804 void client_update_title(ObClient
*self
)
1807 gchar
*visible
= NULL
;
1809 g_free(self
->title
);
1812 if (!PROP_GETS(self
->window
, net_wm_name
, utf8
, &data
)) {
1813 /* try old x stuff */
1814 if (!(PROP_GETS(self
->window
, wm_name
, locale
, &data
)
1815 || PROP_GETS(self
->window
, wm_name
, utf8
, &data
))) {
1816 if (self
->transient
) {
1818 GNOME alert windows are not given titles:
1819 http://developer.gnome.org/projects/gup/hig/draft_hig_new/windows-alert.html
1821 data
= g_strdup("");
1823 data
= g_strdup("Unnamed Window");
1827 if (self
->client_machine
) {
1828 visible
= g_strdup_printf("%s (%s)", data
, self
->client_machine
);
1833 PROP_SETS(self
->window
, net_wm_visible_name
, visible
);
1834 self
->title
= visible
;
1837 frame_adjust_title(self
->frame
);
1839 /* update the icon title */
1841 g_free(self
->icon_title
);
1844 if (!PROP_GETS(self
->window
, net_wm_icon_name
, utf8
, &data
))
1845 /* try old x stuff */
1846 if (!(PROP_GETS(self
->window
, wm_icon_name
, locale
, &data
) ||
1847 PROP_GETS(self
->window
, wm_icon_name
, utf8
, &data
)))
1848 data
= g_strdup(self
->title
);
1850 PROP_SETS(self
->window
, net_wm_visible_icon_name
, data
);
1851 self
->icon_title
= data
;
1854 void client_update_strut(ObClient
*self
)
1858 gboolean got
= FALSE
;
1861 if (PROP_GETA32(self
->window
, net_wm_strut_partial
, cardinal
,
1865 STRUT_PARTIAL_SET(strut
,
1866 data
[0], data
[2], data
[1], data
[3],
1867 data
[4], data
[5], data
[8], data
[9],
1868 data
[6], data
[7], data
[10], data
[11]);
1874 PROP_GETA32(self
->window
, net_wm_strut
, cardinal
, &data
, &num
)) {
1880 /* use the screen's width/height */
1881 a
= screen_physical_area();
1883 STRUT_PARTIAL_SET(strut
,
1884 data
[0], data
[2], data
[1], data
[3],
1885 a
->y
, a
->y
+ a
->height
- 1,
1886 a
->x
, a
->x
+ a
->width
- 1,
1887 a
->y
, a
->y
+ a
->height
- 1,
1888 a
->x
, a
->x
+ a
->width
- 1);
1894 STRUT_PARTIAL_SET(strut
, 0, 0, 0, 0,
1895 0, 0, 0, 0, 0, 0, 0, 0);
1897 if (!STRUT_EQUAL(strut
, self
->strut
)) {
1898 self
->strut
= strut
;
1900 /* updating here is pointless while we're being mapped cuz we're not in
1901 the client list yet */
1903 screen_update_areas();
1907 void client_update_icons(ObClient
*self
)
1913 for (i
= 0; i
< self
->nicons
; ++i
)
1914 g_free(self
->icons
[i
].data
);
1915 if (self
->nicons
> 0)
1916 g_free(self
->icons
);
1919 if (PROP_GETA32(self
->window
, net_wm_icon
, cardinal
, &data
, &num
)) {
1920 /* figure out how many valid icons are in here */
1922 while (num
- i
> 2) {
1926 if (i
> num
|| w
*h
== 0) break;
1930 self
->icons
= g_new(ObClientIcon
, self
->nicons
);
1932 /* store the icons */
1934 for (j
= 0; j
< self
->nicons
; ++j
) {
1937 w
= self
->icons
[j
].width
= data
[i
++];
1938 h
= self
->icons
[j
].height
= data
[i
++];
1940 if (w
*h
== 0) continue;
1942 self
->icons
[j
].data
= g_new(RrPixel32
, w
* h
);
1943 for (x
= 0, y
= 0, t
= 0; t
< w
* h
; ++t
, ++x
, ++i
) {
1948 self
->icons
[j
].data
[t
] =
1949 (((data
[i
] >> 24) & 0xff) << RrDefaultAlphaOffset
) +
1950 (((data
[i
] >> 16) & 0xff) << RrDefaultRedOffset
) +
1951 (((data
[i
] >> 8) & 0xff) << RrDefaultGreenOffset
) +
1952 (((data
[i
] >> 0) & 0xff) << RrDefaultBlueOffset
);
1961 if ((hints
= XGetWMHints(ob_display
, self
->window
))) {
1962 if (hints
->flags
& IconPixmapHint
) {
1964 self
->icons
= g_new(ObClientIcon
, self
->nicons
);
1965 xerror_set_ignore(TRUE
);
1966 if (!RrPixmapToRGBA(ob_rr_inst
,
1968 (hints
->flags
& IconMaskHint
?
1969 hints
->icon_mask
: None
),
1970 &self
->icons
[self
->nicons
-1].width
,
1971 &self
->icons
[self
->nicons
-1].height
,
1972 &self
->icons
[self
->nicons
-1].data
)){
1973 g_free(&self
->icons
[self
->nicons
-1]);
1976 xerror_set_ignore(FALSE
);
1982 /* set the default icon onto the window
1983 in theory, this could be a race, but if a window doesn't set an icon
1984 or removes it entirely, it's not very likely it is going to set one
1985 right away afterwards */
1986 if (self
->nicons
== 0) {
1987 RrPixel32
*icon
= ob_rr_theme
->def_win_icon
;
1990 data
= g_new(gulong
, 48*48+2);
1991 data
[0] = data
[1] = 48;
1992 for (i
= 0; i
< 48*48; ++i
)
1993 data
[i
+2] = (((icon
[i
] >> RrDefaultAlphaOffset
) & 0xff) << 24) +
1994 (((icon
[i
] >> RrDefaultRedOffset
) & 0xff) << 16) +
1995 (((icon
[i
] >> RrDefaultGreenOffset
) & 0xff) << 8) +
1996 (((icon
[i
] >> RrDefaultBlueOffset
) & 0xff) << 0);
1997 PROP_SETA32(self
->window
, net_wm_icon
, cardinal
, data
, 48*48+2);
1999 } else if (self
->frame
)
2000 /* don't draw the icon empty if we're just setting one now anyways,
2001 we'll get the property change any second */
2002 frame_adjust_icon(self
->frame
);
2005 void client_update_user_time(ObClient
*self
)
2008 gboolean got
= FALSE
;
2010 if (self
->user_time_window
)
2011 got
= PROP_GET32(self
->user_time_window
,
2012 net_wm_user_time
, cardinal
, &time
);
2014 got
= PROP_GET32(self
->window
, net_wm_user_time
, cardinal
, &time
);
2017 /* we set this every time, not just when it grows, because in practice
2018 sometimes time goes backwards! (ntpdate.. yay....) so.. if it goes
2019 backward we don't want all windows to stop focusing. we'll just
2020 assume noone is setting times older than the last one, cuz that
2021 would be pretty stupid anyways
2023 self
->user_time
= time
;
2025 /*ob_debug("window %s user time %u\n", self->title, time);*/
2029 void client_update_user_time_window(ObClient
*self
)
2033 if (!PROP_GET32(self
->window
, net_wm_user_time_window
, window
, &w
))
2036 if (w
!= self
->user_time_window
) {
2037 /* remove the old window */
2038 propwin_remove(self
->user_time_window
, OB_PROPWIN_USER_TIME
, self
);
2039 self
->user_time_window
= None
;
2041 if (self
->group
&& self
->group
->leader
== w
) {
2042 ob_debug_type(OB_DEBUG_APP_BUGS
, "Window is setting its "
2043 "_NET_WM_USER_TYPE_WINDOW to its group leader\n");
2044 /* do it anyways..? */
2046 else if (w
== self
->window
) {
2047 ob_debug_type(OB_DEBUG_APP_BUGS
, "Window is setting its "
2048 "_NET_WM_USER_TIME_WINDOW to itself\n");
2049 w
= None
; /* don't do it */
2052 /* add the new window */
2053 propwin_add(w
, OB_PROPWIN_USER_TIME
, self
);
2054 self
->user_time_window
= w
;
2056 /* and update from it */
2057 client_update_user_time(self
);
2061 void client_update_icon_geometry(ObClient
*self
)
2066 RECT_SET(self
->icon_geometry
, 0, 0, 0, 0);
2068 if (PROP_GETA32(self
->window
, net_wm_icon_geometry
, cardinal
, &data
, &num
)
2071 /* don't let them set it with an area < 0 */
2072 RECT_SET(self
->icon_geometry
, data
[0], data
[1],
2073 MAX(data
[2],0), MAX(data
[3],0));
2077 static void client_get_session_ids(ObClient
*self
)
2084 if (!PROP_GET32(self
->window
, wm_client_leader
, window
, &leader
))
2087 /* get the SM_CLIENT_ID */
2090 got
= PROP_GETS(leader
, sm_client_id
, locale
, &self
->sm_client_id
);
2092 PROP_GETS(self
->window
, sm_client_id
, locale
, &self
->sm_client_id
);
2094 /* get the WM_CLASS (name and class). make them "" if they are not
2098 got
= PROP_GETSS(leader
, wm_class
, locale
, &ss
);
2100 got
= PROP_GETSS(self
->window
, wm_class
, locale
, &ss
);
2104 self
->name
= g_strdup(ss
[0]);
2106 self
->class = g_strdup(ss
[1]);
2111 if (self
->name
== NULL
) self
->name
= g_strdup("");
2112 if (self
->class == NULL
) self
->class = g_strdup("");
2114 /* get the WM_WINDOW_ROLE. make it "" if it is not provided */
2117 got
= PROP_GETS(leader
, wm_window_role
, locale
, &s
);
2119 got
= PROP_GETS(self
->window
, wm_window_role
, locale
, &s
);
2124 self
->role
= g_strdup("");
2126 /* get the WM_COMMAND */
2130 got
= PROP_GETSS(leader
, wm_command
, locale
, &ss
);
2132 got
= PROP_GETSS(self
->window
, wm_command
, locale
, &ss
);
2135 /* merge/mash them all together */
2136 gchar
*merge
= NULL
;
2139 for (i
= 0; ss
[i
]; ++i
) {
2142 merge
= g_strconcat(merge
, ss
[i
], NULL
);
2144 merge
= g_strconcat(ss
[i
], NULL
);
2149 self
->wm_command
= merge
;
2152 /* get the WM_CLIENT_MACHINE */
2155 got
= PROP_GETS(leader
, wm_client_machine
, locale
, &s
);
2157 got
= PROP_GETS(self
->window
, wm_client_machine
, locale
, &s
);
2160 gchar localhost
[128];
2162 gethostname(localhost
, 127);
2163 localhost
[127] = '\0';
2164 if (strcmp(localhost
, s
) != 0)
2165 self
->client_machine
= s
;
2171 static void client_change_wm_state(ObClient
*self
)
2176 old
= self
->wmstate
;
2178 if (self
->shaded
|| self
->iconic
||
2179 (self
->desktop
!= DESKTOP_ALL
&& self
->desktop
!= screen_desktop
))
2181 self
->wmstate
= IconicState
;
2183 self
->wmstate
= NormalState
;
2185 if (old
!= self
->wmstate
) {
2186 PROP_MSG(self
->window
, kde_wm_change_state
,
2187 self
->wmstate
, 1, 0, 0);
2189 state
[0] = self
->wmstate
;
2191 PROP_SETA32(self
->window
, wm_state
, wm_state
, state
, 2);
2195 static void client_change_state(ObClient
*self
)
2197 gulong netstate
[11];
2202 netstate
[num
++] = prop_atoms
.net_wm_state_modal
;
2204 netstate
[num
++] = prop_atoms
.net_wm_state_shaded
;
2206 netstate
[num
++] = prop_atoms
.net_wm_state_hidden
;
2207 if (self
->skip_taskbar
)
2208 netstate
[num
++] = prop_atoms
.net_wm_state_skip_taskbar
;
2209 if (self
->skip_pager
)
2210 netstate
[num
++] = prop_atoms
.net_wm_state_skip_pager
;
2211 if (self
->fullscreen
)
2212 netstate
[num
++] = prop_atoms
.net_wm_state_fullscreen
;
2214 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_vert
;
2216 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_horz
;
2218 netstate
[num
++] = prop_atoms
.net_wm_state_above
;
2220 netstate
[num
++] = prop_atoms
.net_wm_state_below
;
2221 if (self
->demands_attention
)
2222 netstate
[num
++] = prop_atoms
.net_wm_state_demands_attention
;
2223 if (self
->undecorated
)
2224 netstate
[num
++] = prop_atoms
.openbox_wm_state_undecorated
;
2225 PROP_SETA32(self
->window
, net_wm_state
, atom
, netstate
, num
);
2228 frame_adjust_state(self
->frame
);
2231 ObClient
*client_search_focus_tree(ObClient
*self
)
2236 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
2237 if (client_focused(it
->data
)) return it
->data
;
2238 if ((ret
= client_search_focus_tree(it
->data
))) return ret
;
2243 ObClient
*client_search_focus_tree_full(ObClient
*self
)
2245 if (self
->transient_for
) {
2246 if (self
->transient_for
!= OB_TRAN_GROUP
) {
2247 return client_search_focus_tree_full(self
->transient_for
);
2250 gboolean recursed
= FALSE
;
2252 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
))
2253 if (!((ObClient
*)it
->data
)->transient_for
) {
2255 if ((c
= client_search_focus_tree_full(it
->data
)))
2264 /* this function checks the whole tree, the client_search_focus_tree~
2265 does not, so we need to check this window */
2266 if (client_focused(self
))
2268 return client_search_focus_tree(self
);
2271 static ObStackingLayer
calc_layer(ObClient
*self
)
2275 if (self
->type
== OB_CLIENT_TYPE_DESKTOP
)
2276 l
= OB_STACKING_LAYER_DESKTOP
;
2277 else if (self
->type
== OB_CLIENT_TYPE_DOCK
) {
2278 if (self
->below
) l
= OB_STACKING_LAYER_NORMAL
;
2279 else l
= OB_STACKING_LAYER_ABOVE
;
2281 else if ((self
->fullscreen
||
2282 /* no decorations and fills the monitor = oldskool fullscreen */
2283 (self
->frame
!= NULL
&&
2284 (self
->frame
->size
.right
== 0 && self
->frame
->size
.left
== 0 &&
2285 self
->frame
->size
.bottom
== 0 && self
->frame
->size
.top
== 0 &&
2286 RECT_EQUAL(self
->area
,
2287 *screen_physical_area_monitor
2288 (client_monitor(self
)))))) &&
2289 (client_focused(self
) || client_search_focus_tree(self
)))
2290 l
= OB_STACKING_LAYER_FULLSCREEN
;
2291 else if (self
->above
) l
= OB_STACKING_LAYER_ABOVE
;
2292 else if (self
->below
) l
= OB_STACKING_LAYER_BELOW
;
2293 else l
= OB_STACKING_LAYER_NORMAL
;
2298 static void client_calc_layer_recursive(ObClient
*self
, ObClient
*orig
,
2299 ObStackingLayer min
)
2301 ObStackingLayer old
, own
;
2305 own
= calc_layer(self
);
2306 self
->layer
= MAX(own
, min
);
2308 if (self
->layer
!= old
) {
2309 stacking_remove(CLIENT_AS_WINDOW(self
));
2310 stacking_add_nonintrusive(CLIENT_AS_WINDOW(self
));
2313 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
2314 client_calc_layer_recursive(it
->data
, orig
,
2318 void client_calc_layer(ObClient
*self
)
2325 /* transients take on the layer of their parents */
2326 it
= client_search_all_top_parents(self
);
2328 for (; it
; it
= g_slist_next(it
))
2329 client_calc_layer_recursive(it
->data
, orig
, 0);
2332 gboolean
client_should_show(ObClient
*self
)
2336 if (client_normal(self
) && screen_showing_desktop
)
2338 if (self
->desktop
== screen_desktop
|| self
->desktop
== DESKTOP_ALL
)
2344 void client_show(ObClient
*self
)
2347 if (client_should_show(self
)) {
2348 frame_show(self
->frame
);
2351 /* According to the ICCCM (sec 4.1.3.1) when a window is not visible, it
2352 needs to be in IconicState. This includes when it is on another
2355 client_change_wm_state(self
);
2358 void client_hide(ObClient
*self
)
2360 if (!client_should_show(self
)) {
2361 frame_hide(self
->frame
);
2364 /* According to the ICCCM (sec 4.1.3.1) when a window is not visible, it
2365 needs to be in IconicState. This includes when it is on another
2368 client_change_wm_state(self
);
2371 void client_showhide(ObClient
*self
)
2374 if (client_should_show(self
)) {
2375 frame_show(self
->frame
);
2378 frame_hide(self
->frame
);
2381 /* According to the ICCCM (sec 4.1.3.1) when a window is not visible, it
2382 needs to be in IconicState. This includes when it is on another
2385 client_change_wm_state(self
);
2388 gboolean
client_normal(ObClient
*self
) {
2389 return ! (self
->type
== OB_CLIENT_TYPE_DESKTOP
||
2390 self
->type
== OB_CLIENT_TYPE_DOCK
||
2391 self
->type
== OB_CLIENT_TYPE_SPLASH
);
2394 gboolean
client_helper(ObClient
*self
)
2396 return (self
->type
== OB_CLIENT_TYPE_UTILITY
||
2397 self
->type
== OB_CLIENT_TYPE_MENU
||
2398 self
->type
== OB_CLIENT_TYPE_TOOLBAR
);
2401 gboolean
client_mouse_focusable(ObClient
*self
)
2403 return !(self
->type
== OB_CLIENT_TYPE_MENU
||
2404 self
->type
== OB_CLIENT_TYPE_TOOLBAR
||
2405 self
->type
== OB_CLIENT_TYPE_SPLASH
||
2406 self
->type
== OB_CLIENT_TYPE_DOCK
);
2409 gboolean
client_enter_focusable(ObClient
*self
)
2411 /* you can focus desktops but it shouldn't on enter */
2412 return (client_mouse_focusable(self
) &&
2413 self
->type
!= OB_CLIENT_TYPE_DESKTOP
);
2417 static void client_apply_startup_state(ObClient
*self
, gint x
, gint y
)
2419 gboolean pos
= FALSE
; /* has the window's position been configured? */
2422 /* save the position, and set self->area for these to use */
2428 /* set the desktop hint, to make sure that it always exists */
2429 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, self
->desktop
);
2431 /* these are in a carefully crafted order.. */
2434 self
->iconic
= FALSE
;
2435 client_iconify(self
, TRUE
, FALSE
, TRUE
);
2437 if (self
->fullscreen
) {
2438 self
->fullscreen
= FALSE
;
2439 client_fullscreen(self
, TRUE
);
2442 if (self
->undecorated
) {
2443 self
->undecorated
= FALSE
;
2444 client_set_undecorated(self
, TRUE
);
2447 self
->shaded
= FALSE
;
2448 client_shade(self
, TRUE
);
2450 if (self
->demands_attention
) {
2451 self
->demands_attention
= FALSE
;
2452 client_hilite(self
, TRUE
);
2455 if (self
->max_vert
&& self
->max_horz
) {
2456 self
->max_vert
= self
->max_horz
= FALSE
;
2457 client_maximize(self
, TRUE
, 0);
2459 } else if (self
->max_vert
) {
2460 self
->max_vert
= FALSE
;
2461 client_maximize(self
, TRUE
, 2);
2463 } else if (self
->max_horz
) {
2464 self
->max_horz
= FALSE
;
2465 client_maximize(self
, TRUE
, 1);
2469 /* if the client didn't get positioned yet, then do so now.
2470 call client_move even if the window is not being moved anywhere, because
2471 when we reparent it and decorate it, it is getting moved and we need to
2472 be telling it so with a ConfigureNotify event.
2475 /* use the saved position */
2478 client_move(self
, x
, y
);
2481 /* nothing to do for the other states:
2490 void client_convert_gravity(ObClient
*self
, gint gravity
, gint
*x
, gint
*y
,
2493 gint oldg
= self
->gravity
;
2495 /* get the frame's position from the requested stuff */
2496 self
->gravity
= gravity
;
2497 frame_client_gravity(self
->frame
, x
, y
, w
, h
);
2498 self
->gravity
= oldg
;
2500 /* get the client's position in its true gravity from that */
2501 frame_frame_gravity(self
->frame
, x
, y
, w
, h
);
2504 void client_try_configure(ObClient
*self
, gint
*x
, gint
*y
, gint
*w
, gint
*h
,
2505 gint
*logicalw
, gint
*logicalh
,
2508 Rect desired_area
= {*x
, *y
, *w
, *h
};
2510 /* make the frame recalculate its dimentions n shit without changing
2511 anything visible for real, this way the constraints below can work with
2512 the updated frame dimensions. */
2513 frame_adjust_area(self
->frame
, TRUE
, TRUE
, TRUE
);
2515 /* work within the prefered sizes given by the window */
2516 if (!(*w
== self
->area
.width
&& *h
== self
->area
.height
)) {
2517 gint basew
, baseh
, minw
, minh
;
2519 /* base size is substituted with min size if not specified */
2520 if (self
->base_size
.width
|| self
->base_size
.height
) {
2521 basew
= self
->base_size
.width
;
2522 baseh
= self
->base_size
.height
;
2524 basew
= self
->min_size
.width
;
2525 baseh
= self
->min_size
.height
;
2527 /* min size is substituted with base size if not specified */
2528 if (self
->min_size
.width
|| self
->min_size
.height
) {
2529 minw
= self
->min_size
.width
;
2530 minh
= self
->min_size
.height
;
2532 minw
= self
->base_size
.width
;
2533 minh
= self
->base_size
.height
;
2536 /* if this is a user-requested resize, then check against min/max
2539 /* smaller than min size or bigger than max size? */
2540 if (*w
> self
->max_size
.width
) *w
= self
->max_size
.width
;
2541 if (*w
< minw
) *w
= minw
;
2542 if (*h
> self
->max_size
.height
) *h
= self
->max_size
.height
;
2543 if (*h
< minh
) *h
= minh
;
2548 /* keep to the increments */
2549 *w
/= self
->size_inc
.width
;
2550 *h
/= self
->size_inc
.height
;
2552 /* you cannot resize to nothing */
2553 if (basew
+ *w
< 1) *w
= 1 - basew
;
2554 if (baseh
+ *h
< 1) *h
= 1 - baseh
;
2556 /* save the logical size */
2557 *logicalw
= self
->size_inc
.width
> 1 ? *w
: *w
+ basew
;
2558 *logicalh
= self
->size_inc
.height
> 1 ? *h
: *h
+ baseh
;
2560 *w
*= self
->size_inc
.width
;
2561 *h
*= self
->size_inc
.height
;
2566 /* adjust the height to match the width for the aspect ratios.
2567 for this, min size is not substituted for base size ever. */
2568 *w
-= self
->base_size
.width
;
2569 *h
-= self
->base_size
.height
;
2571 if (!self
->fullscreen
) {
2572 if (self
->min_ratio
)
2573 if (*h
* self
->min_ratio
> *w
) {
2574 *h
= (gint
)(*w
/ self
->min_ratio
);
2576 /* you cannot resize to nothing */
2579 *w
= (gint
)(*h
* self
->min_ratio
);
2582 if (self
->max_ratio
)
2583 if (*h
* self
->max_ratio
< *w
) {
2584 *h
= (gint
)(*w
/ self
->max_ratio
);
2586 /* you cannot resize to nothing */
2589 *w
= (gint
)(*h
* self
->min_ratio
);
2594 *w
+= self
->base_size
.width
;
2595 *h
+= self
->base_size
.height
;
2598 /* gets the frame's position */
2599 frame_client_gravity(self
->frame
, x
, y
, *w
, *h
);
2601 /* these positions are frame positions, not client positions */
2603 /* set the size and position if fullscreen */
2604 if (self
->fullscreen
) {
2608 i
= screen_find_monitor(&desired_area
);
2609 a
= screen_physical_area_monitor(i
);
2616 user
= FALSE
; /* ignore if the client can't be moved/resized when it
2617 is entering fullscreen */
2618 } else if (self
->max_horz
|| self
->max_vert
) {
2622 i
= screen_find_monitor(&desired_area
);
2623 a
= screen_area_monitor(self
->desktop
, i
);
2625 /* set the size and position if maximized */
2626 if (self
->max_horz
) {
2628 *w
= a
->width
- self
->frame
->size
.left
- self
->frame
->size
.right
;
2630 if (self
->max_vert
) {
2632 *h
= a
->height
- self
->frame
->size
.top
- self
->frame
->size
.bottom
;
2635 /* maximizing is not allowed if the user can't move+resize the window
2639 /* gets the client's position */
2640 frame_frame_gravity(self
->frame
, x
, y
, *w
, *h
);
2642 /* these override the above states! if you cant move you can't move! */
2644 if (!(self
->functions
& OB_CLIENT_FUNC_MOVE
)) {
2648 if (!(self
->functions
& OB_CLIENT_FUNC_RESIZE
)) {
2649 *w
= self
->area
.width
;
2650 *h
= self
->area
.height
;
2659 void client_configure_full(ObClient
*self
, gint x
, gint y
, gint w
, gint h
,
2660 gboolean user
, gboolean final
,
2661 gboolean force_reply
)
2663 gint oldw
, oldh
, oldrx
, oldry
;
2664 gboolean send_resize_client
;
2665 gboolean moved
= FALSE
, resized
= FALSE
, rootmoved
= FALSE
;
2666 guint fdecor
= self
->frame
->decorations
;
2667 gboolean fhorz
= self
->frame
->max_horz
;
2668 gint logicalw
, logicalh
;
2670 /* find the new x, y, width, and height (and logical size) */
2671 client_try_configure(self
, &x
, &y
, &w
, &h
, &logicalw
, &logicalh
, user
);
2673 /* set the logical size if things changed */
2674 if (!(w
== self
->area
.width
&& h
== self
->area
.height
))
2675 SIZE_SET(self
->logical_size
, logicalw
, logicalh
);
2677 /* figure out if we moved or resized or what */
2678 moved
= x
!= self
->area
.x
|| y
!= self
->area
.y
;
2679 resized
= w
!= self
->area
.width
|| h
!= self
->area
.height
;
2681 oldw
= self
->area
.width
;
2682 oldh
= self
->area
.height
;
2683 RECT_SET(self
->area
, x
, y
, w
, h
);
2685 /* for app-requested resizes, always resize if 'resized' is true.
2686 for user-requested ones, only resize if final is true, or when
2687 resizing in redraw mode */
2688 send_resize_client
= ((!user
&& resized
) ||
2690 (resized
&& config_resize_redraw
))));
2692 /* if the client is enlarging, then resize the client before the frame */
2693 if (send_resize_client
&& user
&& (w
> oldw
|| h
> oldh
)) {
2694 XResizeWindow(ob_display
, self
->window
, MAX(w
, oldw
), MAX(h
, oldh
));
2695 /* resize the plate to show the client padding color underneath */
2696 frame_adjust_client_area(self
->frame
);
2699 /* find the frame's dimensions and move/resize it */
2700 if (self
->decorations
!= fdecor
|| self
->max_horz
!= fhorz
)
2701 moved
= resized
= TRUE
;
2702 if (moved
|| resized
)
2703 frame_adjust_area(self
->frame
, moved
, resized
, FALSE
);
2705 /* find the client's position relative to the root window */
2706 oldrx
= self
->root_pos
.x
;
2707 oldry
= self
->root_pos
.y
;
2708 rootmoved
= (oldrx
!= (signed)(self
->frame
->area
.x
+
2709 self
->frame
->size
.left
-
2710 self
->border_width
) ||
2711 oldry
!= (signed)(self
->frame
->area
.y
+
2712 self
->frame
->size
.top
-
2713 self
->border_width
));
2715 if (force_reply
|| ((!user
|| (user
&& final
)) && rootmoved
))
2719 POINT_SET(self
->root_pos
,
2720 self
->frame
->area
.x
+ self
->frame
->size
.left
-
2722 self
->frame
->area
.y
+ self
->frame
->size
.top
-
2723 self
->border_width
);
2725 event
.type
= ConfigureNotify
;
2726 event
.xconfigure
.display
= ob_display
;
2727 event
.xconfigure
.event
= self
->window
;
2728 event
.xconfigure
.window
= self
->window
;
2730 /* root window real coords */
2731 event
.xconfigure
.x
= self
->root_pos
.x
;
2732 event
.xconfigure
.y
= self
->root_pos
.y
;
2733 event
.xconfigure
.width
= w
;
2734 event
.xconfigure
.height
= h
;
2735 event
.xconfigure
.border_width
= 0;
2736 event
.xconfigure
.above
= self
->frame
->plate
;
2737 event
.xconfigure
.override_redirect
= FALSE
;
2738 XSendEvent(event
.xconfigure
.display
, event
.xconfigure
.window
,
2739 FALSE
, StructureNotifyMask
, &event
);
2742 /* if the client is shrinking, then resize the frame before the client */
2743 if (send_resize_client
&& (!user
|| (w
<= oldw
|| h
<= oldh
))) {
2744 /* resize the plate to show the client padding color underneath */
2745 frame_adjust_client_area(self
->frame
);
2747 XResizeWindow(ob_display
, self
->window
, w
, h
);
2753 void client_fullscreen(ObClient
*self
, gboolean fs
)
2757 if (!(self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
) || /* can't */
2758 self
->fullscreen
== fs
) return; /* already done */
2760 self
->fullscreen
= fs
;
2761 client_change_state(self
); /* change the state hints on the client */
2762 client_calc_layer(self
); /* and adjust out layer/stacking */
2765 self
->pre_fullscreen_area
= self
->area
;
2766 /* if the window is maximized, its area isn't all that meaningful.
2767 save it's premax area instead. */
2768 if (self
->max_horz
) {
2769 self
->pre_fullscreen_area
.x
= self
->pre_max_area
.x
;
2770 self
->pre_fullscreen_area
.width
= self
->pre_max_area
.width
;
2772 if (self
->max_vert
) {
2773 self
->pre_fullscreen_area
.y
= self
->pre_max_area
.y
;
2774 self
->pre_fullscreen_area
.height
= self
->pre_max_area
.height
;
2777 /* these are not actually used cuz client_configure will set them
2778 as appropriate when the window is fullscreened */
2783 if (self
->pre_fullscreen_area
.width
> 0 &&
2784 self
->pre_fullscreen_area
.height
> 0)
2786 x
= self
->pre_fullscreen_area
.x
;
2787 y
= self
->pre_fullscreen_area
.y
;
2788 w
= self
->pre_fullscreen_area
.width
;
2789 h
= self
->pre_fullscreen_area
.height
;
2790 RECT_SET(self
->pre_fullscreen_area
, 0, 0, 0, 0);
2792 /* pick some fallbacks... */
2793 a
= screen_area_monitor(self
->desktop
, 0);
2794 x
= a
->x
+ a
->width
/ 4;
2795 y
= a
->y
+ a
->height
/ 4;
2801 client_setup_decor_and_functions(self
);
2803 client_move_resize(self
, x
, y
, w
, h
);
2805 /* try focus us when we go into fullscreen mode */
2809 static void client_iconify_recursive(ObClient
*self
,
2810 gboolean iconic
, gboolean curdesk
,
2811 gboolean hide_animation
)
2814 gboolean changed
= FALSE
;
2817 if (self
->iconic
!= iconic
) {
2818 ob_debug("%sconifying window: 0x%lx\n", (iconic
? "I" : "Uni"),
2822 /* don't let non-normal windows iconify along with their parents
2824 if (client_normal(self
)) {
2825 self
->iconic
= iconic
;
2827 /* update the focus lists.. iconic windows go to the bottom of
2828 the list, put the new iconic window at the 'top of the
2830 focus_order_to_top(self
);
2835 self
->iconic
= iconic
;
2837 if (curdesk
&& self
->desktop
!= screen_desktop
&&
2838 self
->desktop
!= DESKTOP_ALL
)
2839 client_set_desktop(self
, screen_desktop
, FALSE
);
2841 /* this puts it after the current focused window */
2842 focus_order_remove(self
);
2843 focus_order_add_new(self
);
2850 client_change_state(self
);
2851 if (config_animate_iconify
&& !hide_animation
)
2852 frame_begin_iconify_animation(self
->frame
, iconic
);
2853 /* do this after starting the animation so it doesn't flash */
2854 client_showhide(self
);
2857 /* iconify all direct transients, and deiconify all transients
2859 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
2860 if (it
->data
!= self
)
2861 if (client_is_direct_child(self
, it
->data
) || !iconic
)
2862 client_iconify_recursive(it
->data
, iconic
, curdesk
,
2866 void client_iconify(ObClient
*self
, gboolean iconic
, gboolean curdesk
,
2867 gboolean hide_animation
)
2869 if (self
->functions
& OB_CLIENT_FUNC_ICONIFY
|| !iconic
) {
2870 /* move up the transient chain as far as possible first */
2871 self
= client_search_top_normal_parent(self
);
2872 client_iconify_recursive(self
, iconic
, curdesk
, hide_animation
);
2876 void client_maximize(ObClient
*self
, gboolean max
, gint dir
)
2880 g_assert(dir
== 0 || dir
== 1 || dir
== 2);
2881 if (!(self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
)) return; /* can't */
2883 /* check if already done */
2885 if (dir
== 0 && self
->max_horz
&& self
->max_vert
) return;
2886 if (dir
== 1 && self
->max_horz
) return;
2887 if (dir
== 2 && self
->max_vert
) return;
2889 if (dir
== 0 && !self
->max_horz
&& !self
->max_vert
) return;
2890 if (dir
== 1 && !self
->max_horz
) return;
2891 if (dir
== 2 && !self
->max_vert
) return;
2894 /* we just tell it to configure in the same place and client_configure
2895 worries about filling the screen with the window */
2898 w
= self
->area
.width
;
2899 h
= self
->area
.height
;
2902 if ((dir
== 0 || dir
== 1) && !self
->max_horz
) { /* horz */
2903 RECT_SET(self
->pre_max_area
,
2904 self
->area
.x
, self
->pre_max_area
.y
,
2905 self
->area
.width
, self
->pre_max_area
.height
);
2907 if ((dir
== 0 || dir
== 2) && !self
->max_vert
) { /* vert */
2908 RECT_SET(self
->pre_max_area
,
2909 self
->pre_max_area
.x
, self
->area
.y
,
2910 self
->pre_max_area
.width
, self
->area
.height
);
2915 a
= screen_area_monitor(self
->desktop
, 0);
2916 if ((dir
== 0 || dir
== 1) && self
->max_horz
) { /* horz */
2917 if (self
->pre_max_area
.width
> 0) {
2918 x
= self
->pre_max_area
.x
;
2919 w
= self
->pre_max_area
.width
;
2921 RECT_SET(self
->pre_max_area
, 0, self
->pre_max_area
.y
,
2922 0, self
->pre_max_area
.height
);
2924 /* pick some fallbacks... */
2925 x
= a
->x
+ a
->width
/ 4;
2929 if ((dir
== 0 || dir
== 2) && self
->max_vert
) { /* vert */
2930 if (self
->pre_max_area
.height
> 0) {
2931 y
= self
->pre_max_area
.y
;
2932 h
= self
->pre_max_area
.height
;
2934 RECT_SET(self
->pre_max_area
, self
->pre_max_area
.x
, 0,
2935 self
->pre_max_area
.width
, 0);
2937 /* pick some fallbacks... */
2938 y
= a
->y
+ a
->height
/ 4;
2944 if (dir
== 0 || dir
== 1) /* horz */
2945 self
->max_horz
= max
;
2946 if (dir
== 0 || dir
== 2) /* vert */
2947 self
->max_vert
= max
;
2949 client_change_state(self
); /* change the state hints on the client */
2951 client_setup_decor_and_functions(self
);
2953 client_move_resize(self
, x
, y
, w
, h
);
2956 void client_shade(ObClient
*self
, gboolean shade
)
2958 if ((!(self
->functions
& OB_CLIENT_FUNC_SHADE
) &&
2959 shade
) || /* can't shade */
2960 self
->shaded
== shade
) return; /* already done */
2962 self
->shaded
= shade
;
2963 client_change_state(self
);
2964 client_change_wm_state(self
); /* the window is being hidden/shown */
2965 /* resize the frame to just the titlebar */
2966 frame_adjust_area(self
->frame
, FALSE
, FALSE
, FALSE
);
2969 void client_close(ObClient
*self
)
2973 if (!(self
->functions
& OB_CLIENT_FUNC_CLOSE
)) return;
2975 /* in the case that the client provides no means to requesting that it
2976 close, we just kill it */
2977 if (!self
->delete_window
)
2981 XXX: itd be cool to do timeouts and shit here for killing the client's
2983 like... if the window is around after 5 seconds, then the close button
2984 turns a nice red, and if this function is called again, the client is
2988 ce
.xclient
.type
= ClientMessage
;
2989 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
2990 ce
.xclient
.display
= ob_display
;
2991 ce
.xclient
.window
= self
->window
;
2992 ce
.xclient
.format
= 32;
2993 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_delete_window
;
2994 ce
.xclient
.data
.l
[1] = event_curtime
;
2995 ce
.xclient
.data
.l
[2] = 0l;
2996 ce
.xclient
.data
.l
[3] = 0l;
2997 ce
.xclient
.data
.l
[4] = 0l;
2998 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
3001 void client_kill(ObClient
*self
)
3003 XKillClient(ob_display
, self
->window
);
3006 void client_hilite(ObClient
*self
, gboolean hilite
)
3008 if (self
->demands_attention
== hilite
)
3009 return; /* no change */
3011 /* don't allow focused windows to hilite */
3012 self
->demands_attention
= hilite
&& !client_focused(self
);
3013 if (self
->frame
!= NULL
) { /* if we're mapping, just set the state */
3014 if (self
->demands_attention
)
3015 frame_flash_start(self
->frame
);
3017 frame_flash_stop(self
->frame
);
3018 client_change_state(self
);
3022 void client_set_desktop_recursive(ObClient
*self
,
3029 if (target
!= self
->desktop
) {
3031 ob_debug("Setting desktop %u\n", target
+1);
3033 g_assert(target
< screen_num_desktops
|| target
== DESKTOP_ALL
);
3035 old
= self
->desktop
;
3036 self
->desktop
= target
;
3037 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, target
);
3038 /* the frame can display the current desktop state */
3039 frame_adjust_state(self
->frame
);
3040 /* 'move' the window to the new desktop */
3042 client_showhide(self
);
3043 /* raise if it was not already on the desktop */
3044 if (old
!= DESKTOP_ALL
)
3045 stacking_raise(CLIENT_AS_WINDOW(self
));
3046 if (STRUT_EXISTS(self
->strut
))
3047 screen_update_areas();
3050 /* move all transients */
3051 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
3052 if (it
->data
!= self
)
3053 if (client_is_direct_child(self
, it
->data
))
3054 client_set_desktop_recursive(it
->data
, target
, donthide
);
3057 void client_set_desktop(ObClient
*self
, guint target
,
3060 self
= client_search_top_normal_parent(self
);
3061 client_set_desktop_recursive(self
, target
, donthide
);
3064 gboolean
client_is_direct_child(ObClient
*parent
, ObClient
*child
)
3066 while (child
!= parent
&&
3067 child
->transient_for
&& child
->transient_for
!= OB_TRAN_GROUP
)
3068 child
= child
->transient_for
;
3069 return child
== parent
;
3072 ObClient
*client_search_modal_child(ObClient
*self
)
3077 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
3078 ObClient
*c
= it
->data
;
3079 if ((ret
= client_search_modal_child(c
))) return ret
;
3080 if (c
->modal
) return c
;
3085 gboolean
client_validate(ObClient
*self
)
3089 XSync(ob_display
, FALSE
); /* get all events on the server */
3091 if (XCheckTypedWindowEvent(ob_display
, self
->window
, DestroyNotify
, &e
) ||
3092 XCheckTypedWindowEvent(ob_display
, self
->window
, UnmapNotify
, &e
)) {
3093 XPutBackEvent(ob_display
, &e
);
3100 void client_set_wm_state(ObClient
*self
, glong state
)
3102 if (state
== self
->wmstate
) return; /* no change */
3106 client_iconify(self
, TRUE
, TRUE
, FALSE
);
3109 client_iconify(self
, FALSE
, TRUE
, FALSE
);
3114 void client_set_state(ObClient
*self
, Atom action
, glong data1
, glong data2
)
3116 gboolean shaded
= self
->shaded
;
3117 gboolean fullscreen
= self
->fullscreen
;
3118 gboolean undecorated
= self
->undecorated
;
3119 gboolean max_horz
= self
->max_horz
;
3120 gboolean max_vert
= self
->max_vert
;
3121 gboolean modal
= self
->modal
;
3122 gboolean iconic
= self
->iconic
;
3123 gboolean demands_attention
= self
->demands_attention
;
3124 gboolean above
= self
->above
;
3125 gboolean below
= self
->below
;
3128 if (!(action
== prop_atoms
.net_wm_state_add
||
3129 action
== prop_atoms
.net_wm_state_remove
||
3130 action
== prop_atoms
.net_wm_state_toggle
))
3131 /* an invalid action was passed to the client message, ignore it */
3134 for (i
= 0; i
< 2; ++i
) {
3135 Atom state
= i
== 0 ? data1
: data2
;
3137 if (!state
) continue;
3139 /* if toggling, then pick whether we're adding or removing */
3140 if (action
== prop_atoms
.net_wm_state_toggle
) {
3141 if (state
== prop_atoms
.net_wm_state_modal
)
3142 action
= modal
? prop_atoms
.net_wm_state_remove
:
3143 prop_atoms
.net_wm_state_add
;
3144 else if (state
== prop_atoms
.net_wm_state_maximized_vert
)
3145 action
= self
->max_vert
? prop_atoms
.net_wm_state_remove
:
3146 prop_atoms
.net_wm_state_add
;
3147 else if (state
== prop_atoms
.net_wm_state_maximized_horz
)
3148 action
= self
->max_horz
? prop_atoms
.net_wm_state_remove
:
3149 prop_atoms
.net_wm_state_add
;
3150 else if (state
== prop_atoms
.net_wm_state_shaded
)
3151 action
= shaded
? prop_atoms
.net_wm_state_remove
:
3152 prop_atoms
.net_wm_state_add
;
3153 else if (state
== prop_atoms
.net_wm_state_skip_taskbar
)
3154 action
= self
->skip_taskbar
?
3155 prop_atoms
.net_wm_state_remove
:
3156 prop_atoms
.net_wm_state_add
;
3157 else if (state
== prop_atoms
.net_wm_state_skip_pager
)
3158 action
= self
->skip_pager
?
3159 prop_atoms
.net_wm_state_remove
:
3160 prop_atoms
.net_wm_state_add
;
3161 else if (state
== prop_atoms
.net_wm_state_hidden
)
3162 action
= self
->iconic
?
3163 prop_atoms
.net_wm_state_remove
:
3164 prop_atoms
.net_wm_state_add
;
3165 else if (state
== prop_atoms
.net_wm_state_fullscreen
)
3166 action
= fullscreen
?
3167 prop_atoms
.net_wm_state_remove
:
3168 prop_atoms
.net_wm_state_add
;
3169 else if (state
== prop_atoms
.net_wm_state_above
)
3170 action
= self
->above
? prop_atoms
.net_wm_state_remove
:
3171 prop_atoms
.net_wm_state_add
;
3172 else if (state
== prop_atoms
.net_wm_state_below
)
3173 action
= self
->below
? prop_atoms
.net_wm_state_remove
:
3174 prop_atoms
.net_wm_state_add
;
3175 else if (state
== prop_atoms
.net_wm_state_demands_attention
)
3176 action
= self
->demands_attention
?
3177 prop_atoms
.net_wm_state_remove
:
3178 prop_atoms
.net_wm_state_add
;
3179 else if (state
== prop_atoms
.openbox_wm_state_undecorated
)
3180 action
= undecorated
? prop_atoms
.net_wm_state_remove
:
3181 prop_atoms
.net_wm_state_add
;
3184 if (action
== prop_atoms
.net_wm_state_add
) {
3185 if (state
== prop_atoms
.net_wm_state_modal
) {
3187 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
3189 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
3191 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
3193 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
3194 self
->skip_taskbar
= TRUE
;
3195 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
3196 self
->skip_pager
= TRUE
;
3197 } else if (state
== prop_atoms
.net_wm_state_hidden
) {
3199 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
3201 } else if (state
== prop_atoms
.net_wm_state_above
) {
3204 } else if (state
== prop_atoms
.net_wm_state_below
) {
3207 } else if (state
== prop_atoms
.net_wm_state_demands_attention
) {
3208 demands_attention
= TRUE
;
3209 } else if (state
== prop_atoms
.openbox_wm_state_undecorated
) {
3213 } else { /* action == prop_atoms.net_wm_state_remove */
3214 if (state
== prop_atoms
.net_wm_state_modal
) {
3216 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
3218 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
3220 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
3222 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
3223 self
->skip_taskbar
= FALSE
;
3224 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
3225 self
->skip_pager
= FALSE
;
3226 } else if (state
== prop_atoms
.net_wm_state_hidden
) {
3228 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
3230 } else if (state
== prop_atoms
.net_wm_state_above
) {
3232 } else if (state
== prop_atoms
.net_wm_state_below
) {
3234 } else if (state
== prop_atoms
.net_wm_state_demands_attention
) {
3235 demands_attention
= FALSE
;
3236 } else if (state
== prop_atoms
.openbox_wm_state_undecorated
) {
3237 undecorated
= FALSE
;
3241 if (max_horz
!= self
->max_horz
|| max_vert
!= self
->max_vert
) {
3242 if (max_horz
!= self
->max_horz
&& max_vert
!= self
->max_vert
) {
3244 if (max_horz
== max_vert
) { /* both going the same way */
3245 client_maximize(self
, max_horz
, 0);
3247 client_maximize(self
, max_horz
, 1);
3248 client_maximize(self
, max_vert
, 2);
3252 if (max_horz
!= self
->max_horz
)
3253 client_maximize(self
, max_horz
, 1);
3255 client_maximize(self
, max_vert
, 2);
3258 /* change fullscreen state before shading, as it will affect if the window
3260 if (fullscreen
!= self
->fullscreen
)
3261 client_fullscreen(self
, fullscreen
);
3262 if (shaded
!= self
->shaded
)
3263 client_shade(self
, shaded
);
3264 if (undecorated
!= self
->undecorated
)
3265 client_set_undecorated(self
, undecorated
);
3266 if (modal
!= self
->modal
) {
3267 self
->modal
= modal
;
3268 /* when a window changes modality, then its stacking order with its
3269 transients needs to change */
3270 stacking_raise(CLIENT_AS_WINDOW(self
));
3272 if (iconic
!= self
->iconic
)
3273 client_iconify(self
, iconic
, FALSE
, FALSE
);
3275 if (demands_attention
!= self
->demands_attention
)
3276 client_hilite(self
, demands_attention
);
3278 if (above
!= self
->above
|| below
!= self
->below
) {
3279 self
->above
= above
;
3280 self
->below
= below
;
3281 client_calc_layer(self
);
3284 client_change_state(self
); /* change the hint to reflect these changes */
3287 ObClient
*client_focus_target(ObClient
*self
)
3289 ObClient
*child
= NULL
;
3291 child
= client_search_modal_child(self
);
3292 if (child
) return child
;
3296 gboolean
client_can_focus(ObClient
*self
)
3300 /* choose the correct target */
3301 self
= client_focus_target(self
);
3303 if (!self
->frame
->visible
)
3306 if (!(self
->can_focus
|| self
->focus_notify
))
3309 /* do a check to see if the window has already been unmapped or destroyed
3310 do this intelligently while watching out for unmaps we've generated
3311 (ignore_unmaps > 0) */
3312 if (XCheckTypedWindowEvent(ob_display
, self
->window
,
3313 DestroyNotify
, &ev
)) {
3314 XPutBackEvent(ob_display
, &ev
);
3317 while (XCheckTypedWindowEvent(ob_display
, self
->window
,
3318 UnmapNotify
, &ev
)) {
3319 if (self
->ignore_unmaps
) {
3320 self
->ignore_unmaps
--;
3322 XPutBackEvent(ob_display
, &ev
);
3330 gboolean
client_focus(ObClient
*self
)
3332 /* choose the correct target */
3333 self
= client_focus_target(self
);
3335 if (!client_can_focus(self
)) {
3336 if (!self
->frame
->visible
) {
3337 /* update the focus lists */
3338 focus_order_to_top(self
);
3343 ob_debug_type(OB_DEBUG_FOCUS
,
3344 "Focusing client \"%s\" at time %u\n",
3345 self
->title
, event_curtime
);
3347 if (self
->can_focus
) {
3348 /* This can cause a BadMatch error with CurrentTime, or if an app
3349 passed in a bad time for _NET_WM_ACTIVE_WINDOW. */
3350 xerror_set_ignore(TRUE
);
3351 XSetInputFocus(ob_display
, self
->window
, RevertToPointerRoot
,
3353 xerror_set_ignore(FALSE
);
3356 if (self
->focus_notify
) {
3358 ce
.xclient
.type
= ClientMessage
;
3359 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
3360 ce
.xclient
.display
= ob_display
;
3361 ce
.xclient
.window
= self
->window
;
3362 ce
.xclient
.format
= 32;
3363 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_take_focus
;
3364 ce
.xclient
.data
.l
[1] = event_curtime
;
3365 ce
.xclient
.data
.l
[2] = 0l;
3366 ce
.xclient
.data
.l
[3] = 0l;
3367 ce
.xclient
.data
.l
[4] = 0l;
3368 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
3372 ob_debug("%sively focusing %lx at %d\n",
3373 (self
->can_focus
? "act" : "pass"),
3374 self
->window
, (gint
) event_curtime
);
3377 /* Cause the FocusIn to come back to us. Important for desktop switches,
3378 since otherwise we'll have no FocusIn on the queue and send it off to
3379 the focus_backup. */
3380 XSync(ob_display
, FALSE
);
3384 /*! Present the client to the user.
3385 @param raise If the client should be raised or not. You should only set
3386 raise to false if you don't care if the window is completely
3389 static void client_present(ObClient
*self
, gboolean here
, gboolean raise
)
3391 /* if using focus_delay, stop the timer now so that focus doesn't
3393 event_halt_focus_delay();
3395 if (client_normal(self
) && screen_showing_desktop
)
3396 screen_show_desktop(FALSE
, self
);
3398 client_iconify(self
, FALSE
, here
, FALSE
);
3399 if (self
->desktop
!= DESKTOP_ALL
&&
3400 self
->desktop
!= screen_desktop
)
3403 client_set_desktop(self
, screen_desktop
, FALSE
);
3405 screen_set_desktop(self
->desktop
, FALSE
);
3406 } else if (!self
->frame
->visible
)
3407 /* if its not visible for other reasons, then don't mess
3411 client_shade(self
, FALSE
);
3413 stacking_raise(CLIENT_AS_WINDOW(self
));
3418 void client_activate(ObClient
*self
, gboolean here
, gboolean user
)
3420 guint32 last_time
= focus_client
? focus_client
->user_time
: CurrentTime
;
3421 gboolean allow
= FALSE
;
3423 /* if the request came from the user, or if nothing is focused, then grant
3425 if the currently focused app doesn't set a user_time, then it can't
3426 benefit from any focus stealing prevention.
3428 if (user
|| !focus_client
|| !last_time
)
3430 /* otherwise, if they didn't give a time stamp or if it is too old, they
3433 allow
= event_curtime
&& event_time_after(event_curtime
, last_time
);
3435 ob_debug_type(OB_DEBUG_FOCUS
,
3436 "Want to activate window 0x%x with time %u (last time %u), "
3437 "source=%s allowing? %d\n",
3438 self
->window
, event_curtime
, last_time
,
3439 (user
? "user" : "application"), allow
);
3442 if (event_curtime
!= CurrentTime
)
3443 self
->user_time
= event_curtime
;
3445 client_present(self
, here
, TRUE
);
3447 /* don't focus it but tell the user it wants attention */
3448 client_hilite(self
, TRUE
);
3451 static void client_bring_helper_windows_recursive(ObClient
*self
,
3456 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
3457 client_bring_helper_windows_recursive(it
->data
, desktop
);
3459 if (client_helper(self
) &&
3460 self
->desktop
!= desktop
&& self
->desktop
!= DESKTOP_ALL
)
3462 client_set_desktop(self
, desktop
, FALSE
);
3466 void client_bring_helper_windows(ObClient
*self
)
3468 client_bring_helper_windows_recursive(self
, self
->desktop
);
3471 gboolean
client_focused(ObClient
*self
)
3473 return self
== focus_client
;
3476 static ObClientIcon
* client_icon_recursive(ObClient
*self
, gint w
, gint h
)
3479 /* si is the smallest image >= req */
3480 /* li is the largest image < req */
3481 gulong size
, smallest
= 0xffffffff, largest
= 0, si
= 0, li
= 0;
3483 if (!self
->nicons
) {
3484 ObClientIcon
*parent
= NULL
;
3486 if (self
->transient_for
) {
3487 if (self
->transient_for
!= OB_TRAN_GROUP
)
3488 parent
= client_icon_recursive(self
->transient_for
, w
, h
);
3491 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
3492 ObClient
*c
= it
->data
;
3493 if (c
!= self
&& !c
->transient_for
) {
3494 if ((parent
= client_icon_recursive(c
, w
, h
)))
3504 for (i
= 0; i
< self
->nicons
; ++i
) {
3505 size
= self
->icons
[i
].width
* self
->icons
[i
].height
;
3506 if (size
< smallest
&& size
>= (unsigned)(w
* h
)) {
3510 if (size
> largest
&& size
<= (unsigned)(w
* h
)) {
3515 if (largest
== 0) /* didnt find one smaller than the requested size */
3516 return &self
->icons
[si
];
3517 return &self
->icons
[li
];
3520 const ObClientIcon
* client_icon(ObClient
*self
, gint w
, gint h
)
3523 static ObClientIcon deficon
;
3525 if (!(ret
= client_icon_recursive(self
, w
, h
))) {
3526 deficon
.width
= deficon
.height
= 48;
3527 deficon
.data
= ob_rr_theme
->def_win_icon
;
3533 void client_set_layer(ObClient
*self
, gint layer
)
3537 self
->above
= FALSE
;
3538 } else if (layer
== 0) {
3539 self
->below
= self
->above
= FALSE
;
3541 self
->below
= FALSE
;
3544 client_calc_layer(self
);
3545 client_change_state(self
); /* reflect this in the state hints */
3548 void client_set_undecorated(ObClient
*self
, gboolean undecorated
)
3550 if (self
->undecorated
!= undecorated
) {
3551 self
->undecorated
= undecorated
;
3552 client_setup_decor_and_functions(self
);
3553 /* Make sure the client knows it might have moved. Maybe there is a
3554 * better way of doing this so only one client_configure is sent, but
3555 * since 125 of these are sent per second when moving the window (with
3556 * user = FALSE) i doubt it matters much.
3558 client_configure(self
, self
->area
.x
, self
->area
.y
,
3559 self
->area
.width
, self
->area
.height
, TRUE
, TRUE
);
3560 client_change_state(self
); /* reflect this in the state hints */
3564 guint
client_monitor(ObClient
*self
)
3566 return screen_find_monitor(&self
->frame
->area
);
3569 ObClient
*client_search_top_normal_parent(ObClient
*self
)
3571 while (self
->transient_for
&& self
->transient_for
!= OB_TRAN_GROUP
&&
3572 client_normal(self
->transient_for
))
3573 self
= self
->transient_for
;
3577 static GSList
*client_search_all_top_parents_internal(ObClient
*self
,
3579 ObStackingLayer layer
)
3583 /* move up the direct transient chain as far as possible */
3584 while (self
->transient_for
&& self
->transient_for
!= OB_TRAN_GROUP
&&
3585 (!bylayer
|| self
->transient_for
->layer
== layer
) &&
3586 client_normal(self
->transient_for
))
3587 self
= self
->transient_for
;
3589 if (!self
->transient_for
)
3590 ret
= g_slist_prepend(ret
, self
);
3594 g_assert(self
->group
);
3596 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
3597 ObClient
*c
= it
->data
;
3599 if (!c
->transient_for
&& client_normal(c
) &&
3600 (!bylayer
|| c
->layer
== layer
))
3602 ret
= g_slist_prepend(ret
, c
);
3606 if (ret
== NULL
) /* no group parents */
3607 ret
= g_slist_prepend(ret
, self
);
3613 GSList
*client_search_all_top_parents(ObClient
*self
)
3615 return client_search_all_top_parents_internal(self
, FALSE
, 0);
3618 GSList
*client_search_all_top_parents_layer(ObClient
*self
)
3620 return client_search_all_top_parents_internal(self
, TRUE
, self
->layer
);
3623 ObClient
*client_search_focus_parent(ObClient
*self
)
3625 if (self
->transient_for
) {
3626 if (self
->transient_for
!= OB_TRAN_GROUP
) {
3627 if (client_focused(self
->transient_for
))
3628 return self
->transient_for
;
3632 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
3633 ObClient
*c
= it
->data
;
3635 /* checking transient_for prevents infinate loops! */
3636 if (c
!= self
&& !c
->transient_for
)
3637 if (client_focused(c
))
3646 ObClient
*client_search_parent(ObClient
*self
, ObClient
*search
)
3648 if (self
->transient_for
) {
3649 if (self
->transient_for
!= OB_TRAN_GROUP
) {
3650 if (self
->transient_for
== search
)
3655 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
3656 ObClient
*c
= it
->data
;
3658 /* checking transient_for prevents infinate loops! */
3659 if (c
!= self
&& !c
->transient_for
)
3669 ObClient
*client_search_transient(ObClient
*self
, ObClient
*search
)
3673 for (sit
= self
->transients
; sit
; sit
= g_slist_next(sit
)) {
3674 if (sit
->data
== search
)
3676 if (client_search_transient(sit
->data
, search
))
3682 #define WANT_EDGE(cur, c) \
3685 if(!client_normal(cur)) \
3687 if(screen_desktop != cur->desktop && cur->desktop != DESKTOP_ALL) \
3691 if(cur->layer < c->layer && !config_resist_layers_below) \
3694 #define HIT_EDGE(my_edge_start, my_edge_end, his_edge_start, his_edge_end) \
3695 if ((his_edge_start >= my_edge_start && \
3696 his_edge_start <= my_edge_end) || \
3697 (my_edge_start >= his_edge_start && \
3698 my_edge_start <= his_edge_end)) \
3701 /* finds the nearest edge in the given direction from the current client
3702 * note to self: the edge is the -frame- edge (the actual one), not the
3705 gint
client_directional_edge_search(ObClient
*c
, ObDirection dir
, gboolean hang
)
3707 gint dest
, monitor_dest
;
3708 gint my_edge_start
, my_edge_end
, my_offset
;
3715 a
= screen_area(c
->desktop
);
3716 monitor
= screen_area_monitor(c
->desktop
, client_monitor(c
));
3719 case OB_DIRECTION_NORTH
:
3720 my_edge_start
= c
->frame
->area
.x
;
3721 my_edge_end
= c
->frame
->area
.x
+ c
->frame
->area
.width
;
3722 my_offset
= c
->frame
->area
.y
+ (hang
? c
->frame
->area
.height
: 0);
3724 /* default: top of screen */
3725 dest
= a
->y
+ (hang
? c
->frame
->area
.height
: 0);
3726 monitor_dest
= monitor
->y
+ (hang
? c
->frame
->area
.height
: 0);
3727 /* if the monitor edge comes before the screen edge, */
3728 /* use that as the destination instead. (For xinerama) */
3729 if (monitor_dest
!= dest
&& my_offset
> monitor_dest
)
3730 dest
= monitor_dest
;
3732 for(it
= client_list
; it
&& my_offset
!= dest
; it
= g_list_next(it
)) {
3733 gint his_edge_start
, his_edge_end
, his_offset
;
3734 ObClient
*cur
= it
->data
;
3738 his_edge_start
= cur
->frame
->area
.x
;
3739 his_edge_end
= cur
->frame
->area
.x
+ cur
->frame
->area
.width
;
3740 his_offset
= cur
->frame
->area
.y
+
3741 (hang
? 0 : cur
->frame
->area
.height
);
3743 if(his_offset
+ 1 > my_offset
)
3746 if(his_offset
< dest
)
3749 HIT_EDGE(my_edge_start
, my_edge_end
, his_edge_start
, his_edge_end
)
3752 case OB_DIRECTION_SOUTH
:
3753 my_edge_start
= c
->frame
->area
.x
;
3754 my_edge_end
= c
->frame
->area
.x
+ c
->frame
->area
.width
;
3755 my_offset
= c
->frame
->area
.y
+ (hang
? 0 : c
->frame
->area
.height
);
3757 /* default: bottom of screen */
3758 dest
= a
->y
+ a
->height
- (hang
? c
->frame
->area
.height
: 0);
3759 monitor_dest
= monitor
->y
+ monitor
->height
-
3760 (hang
? c
->frame
->area
.height
: 0);
3761 /* if the monitor edge comes before the screen edge, */
3762 /* use that as the destination instead. (For xinerama) */
3763 if (monitor_dest
!= dest
&& my_offset
< monitor_dest
)
3764 dest
= monitor_dest
;
3766 for(it
= client_list
; it
&& my_offset
!= dest
; it
= g_list_next(it
)) {
3767 gint his_edge_start
, his_edge_end
, his_offset
;
3768 ObClient
*cur
= it
->data
;
3772 his_edge_start
= cur
->frame
->area
.x
;
3773 his_edge_end
= cur
->frame
->area
.x
+ cur
->frame
->area
.width
;
3774 his_offset
= cur
->frame
->area
.y
+
3775 (hang
? cur
->frame
->area
.height
: 0);
3778 if(his_offset
- 1 < my_offset
)
3781 if(his_offset
> dest
)
3784 HIT_EDGE(my_edge_start
, my_edge_end
, his_edge_start
, his_edge_end
)
3787 case OB_DIRECTION_WEST
:
3788 my_edge_start
= c
->frame
->area
.y
;
3789 my_edge_end
= c
->frame
->area
.y
+ c
->frame
->area
.height
;
3790 my_offset
= c
->frame
->area
.x
+ (hang
? c
->frame
->area
.width
: 0);
3792 /* default: leftmost egde of screen */
3793 dest
= a
->x
+ (hang
? c
->frame
->area
.width
: 0);
3794 monitor_dest
= monitor
->x
+ (hang
? c
->frame
->area
.width
: 0);
3795 /* if the monitor edge comes before the screen edge, */
3796 /* use that as the destination instead. (For xinerama) */
3797 if (monitor_dest
!= dest
&& my_offset
> monitor_dest
)
3798 dest
= monitor_dest
;
3800 for(it
= client_list
; it
&& my_offset
!= dest
; it
= g_list_next(it
)) {
3801 gint his_edge_start
, his_edge_end
, his_offset
;
3802 ObClient
*cur
= it
->data
;
3806 his_edge_start
= cur
->frame
->area
.y
;
3807 his_edge_end
= cur
->frame
->area
.y
+ cur
->frame
->area
.height
;
3808 his_offset
= cur
->frame
->area
.x
+
3809 (hang
? 0 : cur
->frame
->area
.width
);
3811 if(his_offset
+ 1 > my_offset
)
3814 if(his_offset
< dest
)
3817 HIT_EDGE(my_edge_start
, my_edge_end
, his_edge_start
, his_edge_end
)
3820 case OB_DIRECTION_EAST
:
3821 my_edge_start
= c
->frame
->area
.y
;
3822 my_edge_end
= c
->frame
->area
.y
+ c
->frame
->area
.height
;
3823 my_offset
= c
->frame
->area
.x
+ (hang
? 0 : c
->frame
->area
.width
);
3825 /* default: rightmost edge of screen */
3826 dest
= a
->x
+ a
->width
- (hang
? c
->frame
->area
.width
: 0);
3827 monitor_dest
= monitor
->x
+ monitor
->width
-
3828 (hang
? c
->frame
->area
.width
: 0);
3829 /* if the monitor edge comes before the screen edge, */
3830 /* use that as the destination instead. (For xinerama) */
3831 if (monitor_dest
!= dest
&& my_offset
< monitor_dest
)
3832 dest
= monitor_dest
;
3834 for(it
= client_list
; it
&& my_offset
!= dest
; it
= g_list_next(it
)) {
3835 gint his_edge_start
, his_edge_end
, his_offset
;
3836 ObClient
*cur
= it
->data
;
3840 his_edge_start
= cur
->frame
->area
.y
;
3841 his_edge_end
= cur
->frame
->area
.y
+ cur
->frame
->area
.height
;
3842 his_offset
= cur
->frame
->area
.x
+
3843 (hang
? cur
->frame
->area
.width
: 0);
3845 if(his_offset
- 1 < my_offset
)
3848 if(his_offset
> dest
)
3851 HIT_EDGE(my_edge_start
, my_edge_end
, his_edge_start
, his_edge_end
)
3854 case OB_DIRECTION_NORTHEAST
:
3855 case OB_DIRECTION_SOUTHEAST
:
3856 case OB_DIRECTION_NORTHWEST
:
3857 case OB_DIRECTION_SOUTHWEST
:
3858 /* not implemented */
3860 g_assert_not_reached();
3861 dest
= 0; /* suppress warning */
3866 ObClient
* client_under_pointer()
3870 ObClient
*ret
= NULL
;
3872 if (screen_pointer_pos(&x
, &y
)) {
3873 for (it
= stacking_list
; it
; it
= g_list_next(it
)) {
3874 if (WINDOW_IS_CLIENT(it
->data
)) {
3875 ObClient
*c
= WINDOW_AS_CLIENT(it
->data
);
3876 if (c
->frame
->visible
&&
3877 /* ignore all animating windows */
3878 !frame_iconify_animating(c
->frame
) &&
3879 RECT_CONTAINS(c
->frame
->area
, x
, y
))
3890 gboolean
client_has_group_siblings(ObClient
*self
)
3892 return self
->group
&& self
->group
->members
->next
;