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_layer(ObClient
*self
);
77 static void client_get_shaped(ObClient
*self
);
78 static void client_get_mwm_hints(ObClient
*self
);
79 static void client_get_colormap(ObClient
*self
);
80 static void client_change_allowed_actions(ObClient
*self
);
81 static void client_change_state(ObClient
*self
);
82 static void client_change_wm_state(ObClient
*self
);
83 static void client_apply_startup_state(ObClient
*self
, gint x
, gint y
);
84 static void client_restore_session_state(ObClient
*self
);
85 static gboolean
client_restore_session_stacking(ObClient
*self
);
86 static ObAppSettings
*client_get_settings_state(ObClient
*self
);
87 static void client_update_transient_tree(ObClient
*self
,
88 ObGroup
*oldgroup
, ObGroup
*newgroup
,
91 static void client_present(ObClient
*self
, gboolean here
, gboolean raise
);
92 static GSList
*client_search_all_top_parents_internal(ObClient
*self
,
94 ObStackingLayer layer
);
96 void client_startup(gboolean reconfig
)
103 void client_shutdown(gboolean reconfig
)
105 if (reconfig
) return;
108 void client_add_destructor(ObClientCallback func
, gpointer data
)
110 ClientCallback
*d
= g_new(ClientCallback
, 1);
113 client_destructors
= g_slist_prepend(client_destructors
, d
);
116 void client_remove_destructor(ObClientCallback func
)
120 for (it
= client_destructors
; it
; it
= g_slist_next(it
)) {
121 ClientCallback
*d
= it
->data
;
122 if (d
->func
== func
) {
124 client_destructors
= g_slist_delete_link(client_destructors
, it
);
130 void client_set_list()
132 Window
*windows
, *win_it
;
134 guint size
= g_list_length(client_list
);
136 /* create an array of the window ids */
138 windows
= g_new(Window
, size
);
140 for (it
= client_list
; it
; it
= g_list_next(it
), ++win_it
)
141 *win_it
= ((ObClient
*)it
->data
)->window
;
145 PROP_SETA32(RootWindow(ob_display
, ob_screen
),
146 net_client_list
, window
, (gulong
*)windows
, size
);
155 void client_foreach_transient(ObClient *self, ObClientForeachFunc func, gpointer data)
159 for (it = self->transients; it; it = g_slist_next(it)) {
160 if (!func(it->data, data)) return;
161 client_foreach_transient(it->data, func, data);
165 void client_foreach_ancestor(ObClient *self, ObClientForeachFunc func, gpointer data)
167 if (self->transient_for) {
168 if (self->transient_for != OB_TRAN_GROUP) {
169 if (!func(self->transient_for, data)) return;
170 client_foreach_ancestor(self->transient_for, func, data);
174 for (it = self->group->members; it; it = g_slist_next(it))
175 if (it->data != self &&
176 !((ObClient*)it->data)->transient_for) {
177 if (!func(it->data, data)) return;
178 client_foreach_ancestor(it->data, func, data);
185 void client_manage_all()
190 XWindowAttributes attrib
;
192 XQueryTree(ob_display
, RootWindow(ob_display
, ob_screen
),
193 &w
, &w
, &children
, &nchild
);
195 /* remove all icon windows from the list */
196 for (i
= 0; i
< nchild
; i
++) {
197 if (children
[i
] == None
) continue;
198 wmhints
= XGetWMHints(ob_display
, children
[i
]);
200 if ((wmhints
->flags
& IconWindowHint
) &&
201 (wmhints
->icon_window
!= children
[i
]))
202 for (j
= 0; j
< nchild
; j
++)
203 if (children
[j
] == wmhints
->icon_window
) {
211 for (i
= 0; i
< nchild
; ++i
) {
212 if (children
[i
] == None
)
214 if (XGetWindowAttributes(ob_display
, children
[i
], &attrib
)) {
215 if (attrib
.override_redirect
) continue;
217 if (attrib
.map_state
!= IsUnmapped
)
218 client_manage(children
[i
]);
224 void client_manage(Window window
)
228 XWindowAttributes attrib
;
229 XSetWindowAttributes attrib_set
;
231 gboolean activate
= FALSE
;
232 ObAppSettings
*settings
;
237 /* check if it has already been unmapped by the time we started
238 mapping. the grab does a sync so we don't have to here */
239 if (XCheckTypedWindowEvent(ob_display
, window
, DestroyNotify
, &e
) ||
240 XCheckTypedWindowEvent(ob_display
, window
, UnmapNotify
, &e
))
242 XPutBackEvent(ob_display
, &e
);
244 ob_debug("Trying to manage unmapped window. Aborting that.\n");
246 return; /* don't manage it */
249 /* make sure it isn't an override-redirect window */
250 if (!XGetWindowAttributes(ob_display
, window
, &attrib
) ||
251 attrib
.override_redirect
)
254 return; /* don't manage it */
257 /* is the window a docking app */
258 if ((wmhint
= XGetWMHints(ob_display
, window
))) {
259 if ((wmhint
->flags
& StateHint
) &&
260 wmhint
->initial_state
== WithdrawnState
)
262 dock_add(window
, wmhint
);
270 ob_debug("Managing window: %lx\n", window
);
272 /* choose the events we want to receive on the CLIENT window */
273 attrib_set
.event_mask
= CLIENT_EVENTMASK
;
274 attrib_set
.do_not_propagate_mask
= CLIENT_NOPROPAGATEMASK
;
275 XChangeWindowAttributes(ob_display
, window
,
276 CWEventMask
|CWDontPropagate
, &attrib_set
);
278 /* create the ObClient struct, and populate it from the hints on the
280 self
= g_new0(ObClient
, 1);
281 self
->obwin
.type
= Window_Client
;
282 self
->window
= window
;
284 /* non-zero defaults */
285 self
->wmstate
= WithdrawnState
; /* make sure it gets updated first time */
287 self
->desktop
= screen_num_desktops
; /* always an invalid value */
288 self
->user_time
= focus_client
? focus_client
->user_time
: CurrentTime
;
290 client_get_all(self
, TRUE
);
291 /* per-app settings override stuff, and return the settings for other
293 settings
= client_get_settings_state(self
);
294 /* the session should get the last say */
295 client_restore_session_state(self
);
297 client_setup_decor_and_functions(self
);
299 client_calc_layer(self
);
302 Time t
= sn_app_started(self
->startup_id
, self
->class);
303 if (t
) self
->user_time
= t
;
306 /* update the focus lists, do this before the call to change_state or
307 it can end up in the list twice! */
308 focus_order_add_new(self
);
310 /* remove the client's border (and adjust re gravity) */
311 client_toggle_border(self
, FALSE
);
313 /* specify that if we exit, the window should not be destroyed and
314 should be reparented back to root automatically */
315 XChangeSaveSet(ob_display
, window
, SetModeInsert
);
317 /* create the decoration frame for the client window */
318 self
->frame
= frame_new(self
);
320 frame_grab_client(self
->frame
);
322 /* do this after we have a frame.. it uses the frame to help determine the
323 WM_STATE to apply. */
324 client_change_state(self
);
328 stacking_add_nonintrusive(CLIENT_AS_WINDOW(self
));
330 /* focus the new window? */
331 if (ob_state() != OB_STATE_STARTING
&&
332 (!self
->session
|| self
->session
->focused
) &&
334 /* this means focus=true for window is same as config_focus_new=true */
335 ((config_focus_new
|| (settings
&& settings
->focus
== 1)) ||
336 client_search_focus_parent(self
)) &&
337 /* this checks for focus=false for the window */
338 (!settings
|| settings
->focus
!= 0) &&
339 /* note the check against Type_Normal/Dialog, not client_normal(self),
340 which would also include other types. in this case we want more
341 strict rules for focus */
342 (self
->type
== OB_CLIENT_TYPE_NORMAL
||
343 self
->type
== OB_CLIENT_TYPE_DIALOG
))
348 /* get the current position */
352 /* figure out placement for the window */
353 if (ob_state() == OB_STATE_RUNNING
) {
356 transient
= place_client(self
, &newx
, &newy
, settings
);
358 /* make sure the window is visible. */
359 client_find_onscreen(self
, &newx
, &newy
,
362 /* non-normal clients has less rules, and
363 windows that are being restored from a
364 session do also. we can assume you want
365 it back where you saved it. Clients saying
366 they placed themselves are subjected to
367 harder rules, ones that are placed by
368 place.c or by the user are allowed partially
369 off-screen and on xinerama divides (ie,
370 it is up to the placement routines to avoid
371 the xinerama divides) */
373 (((self
->positioned
& PPosition
) &&
374 !(self
->positioned
& USPosition
)) &&
375 client_normal(self
) &&
379 /* do this after the window is placed, so the premax/prefullscreen numbers
381 also, this moves the window to the position where it has been placed
383 ob_debug("placing window 0x%x at %d, %d with size %d x %d\n",
384 self
->window
, newx
, newy
, self
->area
.width
, self
->area
.height
);
386 ob_debug("session requested %d %d\n",
387 self
->session
->x
, self
->session
->y
);
389 client_apply_startup_state(self
, newx
, newy
);
391 mouse_grab_for_client(self
, TRUE
);
394 guint32 last_time
= focus_client
?
395 focus_client
->user_time
: CurrentTime
;
397 /* This is focus stealing prevention */
398 ob_debug_type(OB_DEBUG_FOCUS
,
399 "Want to focus new window 0x%x with time %u "
401 self
->window
, self
->user_time
, last_time
);
403 /* if it's on another desktop */
404 if (!(self
->desktop
== screen_desktop
|| self
->desktop
== DESKTOP_ALL
)
405 && /* the timestamp is from before you changed desktops */
406 self
->user_time
&& screen_desktop_user_time
&&
407 !event_time_after(self
->user_time
, screen_desktop_user_time
))
410 ob_debug_type(OB_DEBUG_FOCUS
,
411 "Not focusing the window because its on another "
414 /* If something is focused, and it's not our parent... */
415 else if (focus_client
&& client_search_focus_parent(self
) == NULL
)
417 /* If time stamp is old, don't steal focus */
418 if (self
->user_time
&& last_time
&&
419 !event_time_after(self
->user_time
, last_time
))
422 ob_debug_type(OB_DEBUG_FOCUS
,
423 "Not focusing the window because the time is "
426 /* Don't steal focus from globally active clients.
427 I stole this idea from KWin. It seems nice.
429 if (!(focus_client
->can_focus
|| focus_client
->focus_notify
)) {
431 ob_debug_type(OB_DEBUG_FOCUS
,
432 "Not focusing the window because a globally "
433 "active client has focus\n");
438 ob_debug_type(OB_DEBUG_FOCUS
,
439 "Focus stealing prevention activated for %s with "
440 "time %u (last time %u)\n",
441 self
->title
, self
->user_time
, last_time
);
442 /* if the client isn't focused, then hilite it so the user
444 client_hilite(self
, TRUE
);
448 /* This may look rather odd. Well it's because new windows are added
449 to the stacking order non-intrusively. If we're not going to focus
450 the new window or hilite it, then we raise it to the top. This will
451 take affect for things that don't get focused like splash screens.
452 Also if you don't have focus_new enabled, then it's going to get
453 raised to the top. Legacy begets legacy I guess?
455 if (!client_restore_session_stacking(self
))
456 stacking_raise(CLIENT_AS_WINDOW(self
));
459 /* this has to happen before we try focus the window, but we want it to
460 happen after the client's stacking has been determined or it looks bad
464 /* use client_focus instead of client_activate cuz client_activate does
465 stuff like switch desktops etc and I'm not interested in all that when
466 a window maps since its not based on an action from the user like
467 clicking a window to activate it. so keep the new window out of the way
470 gboolean stacked
= client_restore_session_stacking(self
);
471 client_present(self
, FALSE
, !stacked
);
474 /* add to client list/map */
475 client_list
= g_list_append(client_list
, self
);
476 g_hash_table_insert(window_map
, &self
->window
, self
);
478 /* this has to happen after we're in the client_list */
479 if (STRUT_EXISTS(self
->strut
))
480 screen_update_areas();
482 /* update the list hints */
485 ob_debug("Managed window 0x%lx (%s)\n", window
, self
->class);
491 ObClient
*client_fake_manage(Window window
)
494 ObAppSettings
*settings
;
496 ob_debug("Pretend-managing window: %lx\n", window
);
498 /* do this minimal stuff to figure out the client's decorations */
500 self
= g_new0(ObClient
, 1);
501 self
->window
= window
;
503 client_get_all(self
, FALSE
);
504 /* per-app settings override stuff, and return the settings for other
506 settings
= client_get_settings_state(self
);
508 client_setup_decor_and_functions(self
);
509 /* adjust the decorations so we know the sizes */
510 frame_adjust_area(self
->frame
, FALSE
, TRUE
, TRUE
);
512 /* create the decoration frame for the client window */
513 self
->frame
= frame_new(self
);
517 void client_unmanage_all()
519 while (client_list
!= NULL
)
520 client_unmanage(client_list
->data
);
523 void client_unmanage(ObClient
*self
)
528 ob_debug("Unmanaging window: %lx (%s) (%s)\n", self
->window
,
529 self
->class, self
->title
? self
->title
: "");
531 g_assert(self
!= NULL
);
533 /* we dont want events no more. do this before hiding the frame so we
534 don't generate more events */
535 XSelectInput(ob_display
, self
->window
, NoEventMask
);
537 frame_hide(self
->frame
);
538 /* flush to send the hide to the server quickly */
541 /* ignore enter events from the unmap so it doesnt mess with the
543 event_ignore_queued_enters();
545 mouse_grab_for_client(self
, FALSE
);
547 /* remove the window from our save set */
548 XChangeSaveSet(ob_display
, self
->window
, SetModeDelete
);
550 /* kill the property windows */
551 propwin_remove(self
->user_time_window
, OB_PROPWIN_USER_TIME
, self
);
553 /* update the focus lists */
554 focus_order_remove(self
);
555 if (client_focused(self
)) {
556 /* don't leave an invalid focus_client */
560 client_list
= g_list_remove(client_list
, self
);
561 stacking_remove(self
);
562 g_hash_table_remove(window_map
, &self
->window
);
564 /* once the client is out of the list, update the struts to remove its
566 if (STRUT_EXISTS(self
->strut
))
567 screen_update_areas();
569 for (it
= client_destructors
; it
; it
= g_slist_next(it
)) {
570 ClientCallback
*d
= it
->data
;
571 d
->func(self
, d
->data
);
574 /* tell our parent(s) that we're gone */
575 if (self
->transient_for
== OB_TRAN_GROUP
) { /* transient of group */
576 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
))
577 if (it
->data
!= self
)
578 ((ObClient
*)it
->data
)->transients
=
579 g_slist_remove(((ObClient
*)it
->data
)->transients
,self
);
580 } else if (self
->transient_for
) { /* transient of window */
581 self
->transient_for
->transients
=
582 g_slist_remove(self
->transient_for
->transients
, self
);
585 /* tell our transients that we're gone */
586 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
587 if (((ObClient
*)it
->data
)->transient_for
!= OB_TRAN_GROUP
) {
588 ((ObClient
*)it
->data
)->transient_for
= NULL
;
589 client_calc_layer(it
->data
);
593 /* remove from its group */
595 group_remove(self
->group
, self
);
599 /* restore the window's original geometry so it is not lost */
603 if (self
->fullscreen
)
604 a
= self
->pre_fullscreen_area
;
605 else if (self
->max_horz
|| self
->max_vert
) {
606 if (self
->max_horz
) {
607 a
.x
= self
->pre_max_area
.x
;
608 a
.width
= self
->pre_max_area
.width
;
610 if (self
->max_vert
) {
611 a
.y
= self
->pre_max_area
.y
;
612 a
.height
= self
->pre_max_area
.height
;
616 /* give the client its border back */
617 client_toggle_border(self
, TRUE
);
619 self
->fullscreen
= self
->max_horz
= self
->max_vert
= FALSE
;
620 self
->decorations
= 0; /* unmanaged windows have no decor */
622 client_move_resize(self
, a
.x
, a
.y
, a
.width
, a
.height
);
625 /* reparent the window out of the frame, and free the frame */
626 frame_release_client(self
->frame
);
627 frame_free(self
->frame
);
630 if (ob_state() != OB_STATE_EXITING
) {
631 /* these values should not be persisted across a window
633 PROP_ERASE(self
->window
, net_wm_desktop
);
634 PROP_ERASE(self
->window
, net_wm_state
);
635 PROP_ERASE(self
->window
, wm_state
);
637 /* if we're left in an unmapped state, the client wont be mapped.
638 this is bad, since we will no longer be managing the window on
640 XMapWindow(ob_display
, self
->window
);
643 /* update the list hints */
646 ob_debug("Unmanaged window 0x%lx\n", self
->window
);
648 /* free all data allocated in the client struct */
649 g_slist_free(self
->transients
);
650 for (j
= 0; j
< self
->nicons
; ++j
)
651 g_free(self
->icons
[j
].data
);
652 if (self
->nicons
> 0)
654 g_free(self
->wm_command
);
656 g_free(self
->icon_title
);
660 g_free(self
->client_machine
);
661 g_free(self
->sm_client_id
);
665 void client_fake_unmanage(ObClient
*self
)
667 /* this is all that got allocated to get the decorations */
669 frame_free(self
->frame
);
673 static ObAppSettings
*client_get_settings_state(ObClient
*self
)
675 ObAppSettings
*settings
= NULL
;
678 for (it
= config_per_app_settings
; it
; it
= g_slist_next(it
)) {
679 ObAppSettings
*app
= it
->data
;
681 if ((app
->name
&& !app
->class && !strcmp(app
->name
, self
->name
))
682 || (app
->class && !app
->name
&& !strcmp(app
->class, self
->class))
683 || (app
->class && app
->name
&& !strcmp(app
->class, self
->class)
684 && !strcmp(app
->name
, self
->name
)))
686 /* Match if no role was specified in the per app setting, or if the
687 * string matches the beginning of the role, since apps like to set
688 * the role to things like browser-window-23c4b2f */
690 || !strncmp(app
->role
, self
->role
, strlen(app
->role
)))
692 ob_debug("Window matching: %s\n", app
->name
);
701 if (settings
->shade
!= -1)
702 self
->shaded
= !!settings
->shade
;
703 if (settings
->decor
!= -1)
704 self
->undecorated
= !settings
->decor
;
705 if (settings
->iconic
!= -1)
706 self
->iconic
= !!settings
->iconic
;
707 if (settings
->skip_pager
!= -1)
708 self
->skip_pager
= !!settings
->skip_pager
;
709 if (settings
->skip_taskbar
!= -1)
710 self
->skip_taskbar
= !!settings
->skip_taskbar
;
712 if (settings
->max_vert
!= -1)
713 self
->max_vert
= !!settings
->max_vert
;
714 if (settings
->max_horz
!= -1)
715 self
->max_horz
= !!settings
->max_horz
;
717 if (settings
->fullscreen
!= -1)
718 self
->fullscreen
= !!settings
->fullscreen
;
720 if (settings
->desktop
) {
721 if (settings
->desktop
== DESKTOP_ALL
)
722 self
->desktop
= settings
->desktop
;
723 else if (settings
->desktop
> 0 &&
724 settings
->desktop
<= screen_num_desktops
)
725 self
->desktop
= settings
->desktop
- 1;
728 if (settings
->layer
== -1) {
732 else if (settings
->layer
== 0) {
736 else if (settings
->layer
== 1) {
744 static void client_restore_session_state(ObClient
*self
)
748 ob_debug_type(OB_DEBUG_SM
,
749 "Restore session for client %s\n", self
->title
);
751 if (!(it
= session_state_find(self
))) {
752 ob_debug_type(OB_DEBUG_SM
,
753 "Session data not found for client %s\n", self
->title
);
757 self
->session
= it
->data
;
759 ob_debug_type(OB_DEBUG_SM
, "Session data loaded for client %s\n",
762 RECT_SET_POINT(self
->area
, self
->session
->x
, self
->session
->y
);
763 self
->positioned
= USPosition
;
764 if (self
->session
->w
> 0)
765 self
->area
.width
= self
->session
->w
;
766 if (self
->session
->h
> 0)
767 self
->area
.height
= self
->session
->h
;
768 XResizeWindow(ob_display
, self
->window
,
769 self
->area
.width
, self
->area
.height
);
771 self
->desktop
= (self
->session
->desktop
== DESKTOP_ALL
?
772 self
->session
->desktop
:
773 MIN(screen_num_desktops
- 1, self
->session
->desktop
));
774 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, self
->desktop
);
776 self
->shaded
= self
->session
->shaded
;
777 self
->iconic
= self
->session
->iconic
;
778 self
->skip_pager
= self
->session
->skip_pager
;
779 self
->skip_taskbar
= self
->session
->skip_taskbar
;
780 self
->fullscreen
= self
->session
->fullscreen
;
781 self
->above
= self
->session
->above
;
782 self
->below
= self
->session
->below
;
783 self
->max_horz
= self
->session
->max_horz
;
784 self
->max_vert
= self
->session
->max_vert
;
785 self
->undecorated
= self
->session
->undecorated
;
788 static gboolean
client_restore_session_stacking(ObClient
*self
)
792 if (!self
->session
) return FALSE
;
794 mypos
= g_list_find(session_saved_state
, self
->session
);
795 if (!mypos
) return FALSE
;
797 /* start above me and look for the first client */
798 for (it
= g_list_previous(mypos
); it
; it
= g_list_previous(it
)) {
801 for (cit
= client_list
; cit
; cit
= g_list_next(cit
)) {
802 ObClient
*c
= cit
->data
;
803 /* found a client that was in the session, so go below it */
804 if (c
->session
== it
->data
) {
805 stacking_below(CLIENT_AS_WINDOW(self
),
806 CLIENT_AS_WINDOW(cit
->data
));
814 void client_move_onscreen(ObClient
*self
, gboolean rude
)
816 gint x
= self
->area
.x
;
817 gint y
= self
->area
.y
;
818 if (client_find_onscreen(self
, &x
, &y
,
820 self
->area
.height
, rude
)) {
821 client_move(self
, x
, y
);
825 gboolean
client_find_onscreen(ObClient
*self
, gint
*x
, gint
*y
, gint w
, gint h
,
829 gint ox
= *x
, oy
= *y
;
830 gboolean rudel
= rude
, ruder
= rude
, rudet
= rude
, rudeb
= rude
;
833 all_a
= screen_area(self
->desktop
);
834 mon_a
= screen_area_monitor(self
->desktop
, client_monitor(self
));
836 /* get where the frame would be */
837 frame_client_gravity(self
->frame
, x
, y
, w
, h
);
839 /* get the requested size of the window with decorations */
840 fw
= self
->frame
->size
.left
+ w
+ self
->frame
->size
.right
;
841 fh
= self
->frame
->size
.top
+ h
+ self
->frame
->size
.bottom
;
843 /* This makes sure windows aren't entirely outside of the screen so you
844 can't see them at all.
845 It makes sure 10% of the window is on the screen at least. At don't let
846 it move itself off the top of the screen, which would hide the titlebar
847 on you. (The user can still do this if they want too, it's only limiting
850 XXX watch for xinerama dead areas...
852 if (client_normal(self
)) {
853 if (!self
->strut
.right
&& *x
+ fw
/10 >= all_a
->x
+ all_a
->width
- 1)
854 *x
= all_a
->x
+ all_a
->width
- fw
/10;
855 if (!self
->strut
.bottom
&& *y
+ fh
/10 >= all_a
->y
+ all_a
->height
- 1)
856 *y
= all_a
->y
+ all_a
->height
- fh
/10;
857 if (!self
->strut
.left
&& *x
+ fw
*9/10 - 1 < all_a
->x
)
858 *x
= all_a
->x
- fw
*9/10;
859 if (!self
->strut
.top
&& *y
+ fh
*9/10 - 1 < all_a
->y
)
860 *y
= all_a
->y
- fw
*9/10;
863 /* If rudeness wasn't requested, then figure out of the client is currently
864 entirely on the screen. If it is, and the position isn't changing by
865 request, and it is enlarging, then be rude even though it wasn't
868 Point oldtl
, oldtr
, oldbl
, oldbr
;
869 Point newtl
, newtr
, newbl
, newbr
;
870 gboolean stationary_l
, stationary_r
, stationary_t
, stationary_b
;
872 POINT_SET(oldtl
, self
->frame
->area
.x
, self
->frame
->area
.y
);
873 POINT_SET(oldbr
, self
->frame
->area
.x
+ self
->frame
->area
.width
- 1,
874 self
->frame
->area
.y
+ self
->frame
->area
.height
- 1);
875 POINT_SET(oldtr
, oldbr
.x
, oldtl
.y
);
876 POINT_SET(oldbl
, oldtl
.x
, oldbr
.y
);
878 POINT_SET(newtl
, *x
, *y
);
879 POINT_SET(newbr
, *x
+ fw
- 1, *y
+ fh
- 1);
880 POINT_SET(newtr
, newbr
.x
, newtl
.y
);
881 POINT_SET(newbl
, newtl
.x
, newbr
.y
);
883 /* is it moving or just resizing from some corner? */
884 stationary_l
= oldtl
.x
== oldtl
.x
;
885 stationary_r
= oldtr
.x
== oldtr
.x
;
886 stationary_t
= oldtl
.y
== oldtl
.y
;
887 stationary_b
= oldbl
.y
== oldbl
.y
;
889 /* if left edge is growing and didnt move right edge */
890 if (stationary_r
&& newtl
.x
< oldtl
.x
)
892 /* if right edge is growing and didnt move left edge */
893 if (stationary_l
&& newtr
.x
> oldtr
.x
)
895 /* if top edge is growing and didnt move bottom edge */
896 if (stationary_b
&& newtl
.y
< oldtl
.y
)
898 /* if bottom edge is growing and didnt move top edge */
899 if (stationary_t
&& newbl
.y
> oldbl
.y
)
903 /* This here doesn't let windows even a pixel outside the struts/screen.
904 * When called from client_manage, programs placing themselves are
905 * forced completely onscreen, while things like
906 * xterm -geometry resolution-width/2 will work fine. Trying to
907 * place it completely offscreen will be handled in the above code.
908 * Sorry for this confused comment, i am tired. */
909 if (fw
<= mon_a
->width
) {
910 if (rudel
&& !self
->strut
.left
&& *x
< mon_a
->x
) *x
= mon_a
->x
;
911 if (ruder
&& !self
->strut
.right
&& *x
+ fw
> mon_a
->x
+ mon_a
->width
)
912 *x
= mon_a
->x
+ mon_a
->width
- fw
;
914 if (fh
<= mon_a
->height
) {
915 if (rudet
&& !self
->strut
.top
&& *y
< mon_a
->y
) *y
= mon_a
->y
;
916 if (rudeb
&& !self
->strut
.bottom
&& *y
+ fh
> mon_a
->y
+ mon_a
->height
)
917 *y
= mon_a
->y
+ mon_a
->height
- fh
;
920 /* get where the client should be */
921 frame_frame_gravity(self
->frame
, x
, y
, w
, h
);
923 return ox
!= *x
|| oy
!= *y
;
926 static void client_toggle_border(ObClient
*self
, gboolean show
)
928 /* adjust our idea of where the client is, based on its border. When the
929 border is removed, the client should now be considered to be in a
931 when re-adding the border to the client, the same operation needs to be
933 gint oldx
= self
->area
.x
, oldy
= self
->area
.y
;
934 gint x
= oldx
, y
= oldy
;
935 switch(self
->gravity
) {
937 case NorthWestGravity
:
939 case SouthWestGravity
:
941 case NorthEastGravity
:
943 case SouthEastGravity
:
944 if (show
) x
-= self
->border_width
* 2;
945 else x
+= self
->border_width
* 2;
952 if (show
) x
-= self
->border_width
;
953 else x
+= self
->border_width
;
956 switch(self
->gravity
) {
958 case NorthWestGravity
:
960 case NorthEastGravity
:
962 case SouthWestGravity
:
964 case SouthEastGravity
:
965 if (show
) y
-= self
->border_width
* 2;
966 else y
+= self
->border_width
* 2;
973 if (show
) y
-= self
->border_width
;
974 else y
+= self
->border_width
;
981 XSetWindowBorderWidth(ob_display
, self
->window
, self
->border_width
);
983 /* set border_width to 0 because there is no border to add into
984 calculations anymore */
985 self
->border_width
= 0;
987 XSetWindowBorderWidth(ob_display
, self
->window
, 0);
991 static void client_get_all(ObClient
*self
, gboolean real
)
993 /* this is needed for the frame to set itself up */
994 client_get_area(self
);
996 /* these things can change the decor and functions of the window */
998 client_get_mwm_hints(self
);
999 /* this can change the mwmhints for special cases */
1000 client_get_type_and_transientness(self
);
1001 client_get_state(self
);
1002 client_update_normal_hints(self
);
1004 /* get the session related properties, these can change decorations
1005 from per-app settings */
1006 client_get_session_ids(self
);
1011 client_update_protocols(self
);
1013 client_update_wmhints(self
);
1014 /* this may have already been called from client_update_wmhints */
1015 if (self
->transient_for
== NULL
)
1016 client_update_transient_for(self
);
1018 client_get_startup_id(self
);
1019 client_get_desktop(self
);/* uses transient data/group/startup id if a
1020 desktop is not specified */
1021 client_get_shaped(self
);
1023 client_get_layer(self
); /* if layer hasn't been specified, get it from
1024 other sources if possible */
1027 /* a couple type-based defaults for new windows */
1029 /* this makes sure that these windows appear on all desktops */
1030 if (self
->type
== OB_CLIENT_TYPE_DESKTOP
)
1031 self
->desktop
= DESKTOP_ALL
;
1035 client_update_sync_request_counter(self
);
1038 client_get_colormap(self
);
1039 client_update_title(self
);
1040 client_update_strut(self
);
1041 client_update_icons(self
);
1042 client_update_user_time_window(self
);
1043 if (!self
->user_time_window
) /* check if this would have been called */
1044 client_update_user_time(self
);
1045 client_update_icon_geometry(self
);
1048 static void client_get_startup_id(ObClient
*self
)
1050 if (!(PROP_GETS(self
->window
, net_startup_id
, utf8
, &self
->startup_id
)))
1052 PROP_GETS(self
->group
->leader
,
1053 net_startup_id
, utf8
, &self
->startup_id
);
1056 static void client_get_area(ObClient
*self
)
1058 XWindowAttributes wattrib
;
1061 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
1062 g_assert(ret
!= BadWindow
);
1064 RECT_SET(self
->area
, wattrib
.x
, wattrib
.y
, wattrib
.width
, wattrib
.height
);
1065 POINT_SET(self
->root_pos
, wattrib
.x
, wattrib
.y
);
1066 self
->border_width
= wattrib
.border_width
;
1068 ob_debug("client area: %d %d %d %d\n", wattrib
.x
, wattrib
.y
,
1069 wattrib
.width
, wattrib
.height
);
1072 static void client_get_desktop(ObClient
*self
)
1074 guint32 d
= screen_num_desktops
; /* an always-invalid value */
1076 if (PROP_GET32(self
->window
, net_wm_desktop
, cardinal
, &d
)) {
1077 if (d
>= screen_num_desktops
&& d
!= DESKTOP_ALL
)
1078 self
->desktop
= screen_num_desktops
- 1;
1082 gboolean trdesk
= FALSE
;
1084 if (self
->transient_for
) {
1085 if (self
->transient_for
!= OB_TRAN_GROUP
) {
1086 self
->desktop
= self
->transient_for
->desktop
;
1091 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
))
1092 if (it
->data
!= self
&&
1093 !((ObClient
*)it
->data
)->transient_for
) {
1094 self
->desktop
= ((ObClient
*)it
->data
)->desktop
;
1101 /* try get from the startup-notification protocol */
1102 if (sn_get_desktop(self
->startup_id
, &self
->desktop
)) {
1103 if (self
->desktop
>= screen_num_desktops
&&
1104 self
->desktop
!= DESKTOP_ALL
)
1105 self
->desktop
= screen_num_desktops
- 1;
1107 /* defaults to the current desktop */
1108 self
->desktop
= screen_desktop
;
1113 static void client_get_layer(ObClient
*self
)
1115 if (!(self
->above
|| self
->below
)) {
1117 /* apply stuff from the group */
1121 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
1122 ObClient
*c
= it
->data
;
1123 if (c
!= self
&& !client_search_transient(self
, c
) &&
1124 client_normal(self
) && client_normal(c
))
1127 (c
->above
? 1 : (c
->below
? -1 : 0)));
1141 g_assert_not_reached();
1148 static void client_get_state(ObClient
*self
)
1153 if (PROP_GETA32(self
->window
, net_wm_state
, atom
, &state
, &num
)) {
1155 for (i
= 0; i
< num
; ++i
) {
1156 if (state
[i
] == prop_atoms
.net_wm_state_modal
)
1158 else if (state
[i
] == prop_atoms
.net_wm_state_shaded
)
1159 self
->shaded
= TRUE
;
1160 else if (state
[i
] == prop_atoms
.net_wm_state_hidden
)
1161 self
->iconic
= TRUE
;
1162 else if (state
[i
] == prop_atoms
.net_wm_state_skip_taskbar
)
1163 self
->skip_taskbar
= TRUE
;
1164 else if (state
[i
] == prop_atoms
.net_wm_state_skip_pager
)
1165 self
->skip_pager
= TRUE
;
1166 else if (state
[i
] == prop_atoms
.net_wm_state_fullscreen
)
1167 self
->fullscreen
= TRUE
;
1168 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_vert
)
1169 self
->max_vert
= TRUE
;
1170 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_horz
)
1171 self
->max_horz
= TRUE
;
1172 else if (state
[i
] == prop_atoms
.net_wm_state_above
)
1174 else if (state
[i
] == prop_atoms
.net_wm_state_below
)
1176 else if (state
[i
] == prop_atoms
.net_wm_state_demands_attention
)
1177 self
->demands_attention
= TRUE
;
1178 else if (state
[i
] == prop_atoms
.openbox_wm_state_undecorated
)
1179 self
->undecorated
= TRUE
;
1186 static void client_get_shaped(ObClient
*self
)
1188 self
->shaped
= FALSE
;
1190 if (extensions_shape
) {
1195 XShapeSelectInput(ob_display
, self
->window
, ShapeNotifyMask
);
1197 XShapeQueryExtents(ob_display
, self
->window
, &s
, &foo
,
1198 &foo
, &ufoo
, &ufoo
, &foo
, &foo
, &foo
, &ufoo
,
1200 self
->shaped
= (s
!= 0);
1205 void client_update_transient_for(ObClient
*self
)
1208 ObClient
*target
= NULL
;
1210 if (XGetTransientForHint(ob_display
, self
->window
, &t
)) {
1211 if (t
!= self
->window
) { /* cant be transient to itself! */
1212 target
= g_hash_table_lookup(window_map
, &t
);
1213 /* if this happens then we need to check for it*/
1214 g_assert(target
!= self
);
1215 if (target
&& !WINDOW_IS_CLIENT(target
)) {
1216 /* this can happen when a dialog is a child of
1217 a dockapp, for example */
1221 /* THIS IS SO ANNOYING ! ! ! ! Let me explain.... have a seat..
1223 Setting the transient_for to Root is actually illegal, however
1224 applications from time have done this to specify transient for
1227 Now you can do that by being a TYPE_DIALOG and not setting
1228 the transient_for hint at all on your window. But people still
1229 use Root, and Kwin is very strange in this regard.
1231 KWin 3.0 will not consider windows with transient_for set to
1232 Root as transient for their group *UNLESS* they are also modal.
1233 In that case, it will make them transient for the group. This
1234 leads to all sorts of weird behavior from KDE apps which are
1235 only tested in KWin. I'd like to follow their behavior just to
1236 make this work right with KDE stuff, but that seems wrong.
1238 if (!target
&& self
->group
) {
1239 /* not transient to a client, see if it is transient for a
1241 if (t
== RootWindow(ob_display
, ob_screen
)) {
1242 /* window is a transient for its group! */
1243 target
= OB_TRAN_GROUP
;
1247 } else if (self
->transient
&& self
->group
)
1248 target
= OB_TRAN_GROUP
;
1250 client_update_transient_tree(self
, self
->group
, self
->group
,
1251 self
->transient_for
, target
);
1252 self
->transient_for
= target
;
1256 static void client_update_transient_tree(ObClient
*self
,
1257 ObGroup
*oldgroup
, ObGroup
*newgroup
,
1258 ObClient
* oldparent
,
1259 ObClient
*newparent
)
1264 /* No change has occured */
1265 if (oldgroup
== newgroup
&& oldparent
== newparent
) return;
1267 /** Remove the client from the transient tree wherever it has changed **/
1269 /* If the window is becoming a direct transient for a window in its group
1270 then that window can't be a child of this window anymore */
1271 if (oldparent
!= newparent
&&
1272 newparent
!= NULL
&& newparent
!= OB_TRAN_GROUP
&&
1273 newparent
->transient_for
== OB_TRAN_GROUP
&&
1274 newgroup
!= NULL
&& newgroup
== oldgroup
)
1276 self
->transients
= g_slist_remove(self
->transients
, newparent
);
1280 /* If the group changed, or if we are just becoming transient for the
1281 group, then we need to remove any old group transient windows
1282 from our children. But if we were already transient for the group, then
1283 other group transients are not our children. */
1284 if ((oldgroup
!= newgroup
||
1285 (newparent
== OB_TRAN_GROUP
&& oldparent
!= newparent
)) &&
1286 oldgroup
!= NULL
&& oldparent
!= OB_TRAN_GROUP
)
1288 for (it
= self
->transients
; it
; it
= next
) {
1289 next
= g_slist_next(it
);
1291 if (c
->group
== oldgroup
)
1292 self
->transients
= g_slist_delete_link(self
->transients
, it
);
1296 /* If we used to be transient for a group and now we are not, or we're
1297 transient for a new group, then we need to remove ourselves from all
1299 if (oldparent
== OB_TRAN_GROUP
&& (oldgroup
!= newgroup
||
1300 oldparent
!= newparent
))
1302 for (it
= oldgroup
->members
; it
; it
= g_slist_next(it
)) {
1304 if (c
!= self
&& (!c
->transient_for
||
1305 c
->transient_for
!= OB_TRAN_GROUP
))
1306 c
->transients
= g_slist_remove(c
->transients
, self
);
1309 /* If we used to be transient for a single window and we are no longer
1310 transient for it, then we need to remove ourself from its children */
1311 else if (oldparent
!= NULL
&& oldparent
!= OB_TRAN_GROUP
&&
1312 oldparent
!= newparent
)
1313 oldparent
->transients
= g_slist_remove(oldparent
->transients
, self
);
1316 /** Re-add the client to the transient tree wherever it has changed **/
1318 /* If we're now transient for a group and we weren't transient for it
1319 before then we need to add ourselves to all our new parents */
1320 if (newparent
== OB_TRAN_GROUP
&& (oldgroup
!= newgroup
||
1321 oldparent
!= newparent
))
1323 for (it
= oldgroup
->members
; it
; it
= g_slist_next(it
)) {
1325 if (c
!= self
&& (!c
->transient_for
||
1326 c
->transient_for
!= OB_TRAN_GROUP
))
1327 c
->transients
= g_slist_prepend(c
->transients
, self
);
1330 /* If we are now transient for a single window which we weren't before,
1331 we need to add ourselves to its children
1333 WARNING: Cyclical transient ness is possible if two windows are
1334 transient for eachother.
1336 else if (newparent
!= NULL
&& newparent
!= OB_TRAN_GROUP
&&
1337 newparent
!= oldparent
&&
1338 /* don't make ourself its child if it is already our child */
1339 !client_is_direct_child(self
, newparent
))
1340 newparent
->transients
= g_slist_prepend(newparent
->transients
, self
);
1342 /* If the group changed then we need to add any new group transient
1343 windows to our children. But if we're transient for the group, then
1344 other group transients are not our children.
1346 WARNING: Cyclical transient-ness is possible. For e.g. if:
1347 A is transient for the group
1348 B is a member of the group and transient for A
1350 if (oldgroup
!= newgroup
&& newgroup
!= NULL
&&
1351 newparent
!= OB_TRAN_GROUP
)
1353 for (it
= newgroup
->members
; it
; it
= g_slist_next(it
)) {
1355 if (c
!= self
&& c
->transient_for
== OB_TRAN_GROUP
&&
1356 /* Don't make it our child if it is already our parent */
1357 !client_is_direct_child(c
, self
))
1359 self
->transients
= g_slist_prepend(self
->transients
, c
);
1365 static void client_get_mwm_hints(ObClient
*self
)
1370 self
->mwmhints
.flags
= 0; /* default to none */
1372 if (PROP_GETA32(self
->window
, motif_wm_hints
, motif_wm_hints
,
1374 if (num
>= OB_MWM_ELEMENTS
) {
1375 self
->mwmhints
.flags
= hints
[0];
1376 self
->mwmhints
.functions
= hints
[1];
1377 self
->mwmhints
.decorations
= hints
[2];
1383 void client_get_type_and_transientness(ObClient
*self
)
1390 self
->transient
= FALSE
;
1392 if (PROP_GETA32(self
->window
, net_wm_window_type
, atom
, &val
, &num
)) {
1393 /* use the first value that we know about in the array */
1394 for (i
= 0; i
< num
; ++i
) {
1395 if (val
[i
] == prop_atoms
.net_wm_window_type_desktop
)
1396 self
->type
= OB_CLIENT_TYPE_DESKTOP
;
1397 else if (val
[i
] == prop_atoms
.net_wm_window_type_dock
)
1398 self
->type
= OB_CLIENT_TYPE_DOCK
;
1399 else if (val
[i
] == prop_atoms
.net_wm_window_type_toolbar
)
1400 self
->type
= OB_CLIENT_TYPE_TOOLBAR
;
1401 else if (val
[i
] == prop_atoms
.net_wm_window_type_menu
)
1402 self
->type
= OB_CLIENT_TYPE_MENU
;
1403 else if (val
[i
] == prop_atoms
.net_wm_window_type_utility
)
1404 self
->type
= OB_CLIENT_TYPE_UTILITY
;
1405 else if (val
[i
] == prop_atoms
.net_wm_window_type_splash
)
1406 self
->type
= OB_CLIENT_TYPE_SPLASH
;
1407 else if (val
[i
] == prop_atoms
.net_wm_window_type_dialog
)
1408 self
->type
= OB_CLIENT_TYPE_DIALOG
;
1409 else if (val
[i
] == prop_atoms
.net_wm_window_type_normal
)
1410 self
->type
= OB_CLIENT_TYPE_NORMAL
;
1411 else if (val
[i
] == prop_atoms
.kde_net_wm_window_type_override
) {
1412 /* prevent this window from getting any decor or
1414 self
->mwmhints
.flags
&= (OB_MWM_FLAG_FUNCTIONS
|
1415 OB_MWM_FLAG_DECORATIONS
);
1416 self
->mwmhints
.decorations
= 0;
1417 self
->mwmhints
.functions
= 0;
1419 if (self
->type
!= (ObClientType
) -1)
1420 break; /* grab the first legit type */
1425 if (XGetTransientForHint(ob_display
, self
->window
, &t
))
1426 self
->transient
= TRUE
;
1428 if (self
->type
== (ObClientType
) -1) {
1429 /*the window type hint was not set, which means we either classify
1430 ourself as a normal window or a dialog, depending on if we are a
1432 if (self
->transient
)
1433 self
->type
= OB_CLIENT_TYPE_DIALOG
;
1435 self
->type
= OB_CLIENT_TYPE_NORMAL
;
1438 /* then, based on our type, we can update our transientness.. */
1439 if (self
->type
== OB_CLIENT_TYPE_DIALOG
||
1440 self
->type
== OB_CLIENT_TYPE_TOOLBAR
||
1441 self
->type
== OB_CLIENT_TYPE_MENU
||
1442 self
->type
== OB_CLIENT_TYPE_UTILITY
)
1444 self
->transient
= TRUE
;
1448 void client_update_protocols(ObClient
*self
)
1451 guint num_return
, i
;
1453 self
->focus_notify
= FALSE
;
1454 self
->delete_window
= FALSE
;
1456 if (PROP_GETA32(self
->window
, wm_protocols
, atom
, &proto
, &num_return
)) {
1457 for (i
= 0; i
< num_return
; ++i
) {
1458 if (proto
[i
] == prop_atoms
.wm_delete_window
)
1459 /* this means we can request the window to close */
1460 self
->delete_window
= TRUE
;
1461 else if (proto
[i
] == prop_atoms
.wm_take_focus
)
1462 /* if this protocol is requested, then the window will be
1463 notified whenever we want it to receive focus */
1464 self
->focus_notify
= TRUE
;
1466 else if (proto
[i
] == prop_atoms
.net_wm_sync_request
)
1467 /* if this protocol is requested, then resizing the
1468 window will be synchronized between the frame and the
1470 self
->sync_request
= TRUE
;
1478 void client_update_sync_request_counter(ObClient
*self
)
1482 if (PROP_GET32(self
->window
, net_wm_sync_request_counter
, cardinal
, &i
)) {
1483 self
->sync_counter
= i
;
1485 self
->sync_counter
= None
;
1489 void client_get_colormap(ObClient
*self
)
1491 XWindowAttributes wa
;
1493 if (XGetWindowAttributes(ob_display
, self
->window
, &wa
))
1494 client_update_colormap(self
, wa
.colormap
);
1497 void client_update_colormap(ObClient
*self
, Colormap colormap
)
1499 self
->colormap
= colormap
;
1502 void client_update_normal_hints(ObClient
*self
)
1506 gint oldgravity
= self
->gravity
;
1509 self
->min_ratio
= 0.0f
;
1510 self
->max_ratio
= 0.0f
;
1511 SIZE_SET(self
->size_inc
, 1, 1);
1512 SIZE_SET(self
->base_size
, 0, 0);
1513 SIZE_SET(self
->min_size
, 0, 0);
1514 SIZE_SET(self
->max_size
, G_MAXINT
, G_MAXINT
);
1516 /* get the hints from the window */
1517 if (XGetWMNormalHints(ob_display
, self
->window
, &size
, &ret
)) {
1518 /* normal windows can't request placement! har har
1519 if (!client_normal(self))
1521 self
->positioned
= (size
.flags
& (PPosition
|USPosition
));
1523 if (size
.flags
& PWinGravity
) {
1524 self
->gravity
= size
.win_gravity
;
1526 /* if the client has a frame, i.e. has already been mapped and
1527 is changing its gravity */
1528 if (self
->frame
&& self
->gravity
!= oldgravity
) {
1529 /* move our idea of the client's position based on its new
1531 client_convert_gravity(self
, oldgravity
,
1532 &self
->area
.x
, &self
->area
.y
,
1533 self
->area
.width
, self
->area
.height
);
1537 if (size
.flags
& PAspect
) {
1538 if (size
.min_aspect
.y
)
1540 (gfloat
) size
.min_aspect
.x
/ size
.min_aspect
.y
;
1541 if (size
.max_aspect
.y
)
1543 (gfloat
) size
.max_aspect
.x
/ size
.max_aspect
.y
;
1546 if (size
.flags
& PMinSize
)
1547 SIZE_SET(self
->min_size
, size
.min_width
, size
.min_height
);
1549 if (size
.flags
& PMaxSize
)
1550 SIZE_SET(self
->max_size
, size
.max_width
, size
.max_height
);
1552 if (size
.flags
& PBaseSize
)
1553 SIZE_SET(self
->base_size
, size
.base_width
, size
.base_height
);
1555 if (size
.flags
& PResizeInc
&& size
.width_inc
&& size
.height_inc
)
1556 SIZE_SET(self
->size_inc
, size
.width_inc
, size
.height_inc
);
1560 void client_setup_decor_and_functions(ObClient
*self
)
1562 /* start with everything (cept fullscreen) */
1564 (OB_FRAME_DECOR_TITLEBAR
|
1565 OB_FRAME_DECOR_HANDLE
|
1566 OB_FRAME_DECOR_GRIPS
|
1567 OB_FRAME_DECOR_BORDER
|
1568 OB_FRAME_DECOR_ICON
|
1569 OB_FRAME_DECOR_ALLDESKTOPS
|
1570 OB_FRAME_DECOR_ICONIFY
|
1571 OB_FRAME_DECOR_MAXIMIZE
|
1572 OB_FRAME_DECOR_SHADE
|
1573 OB_FRAME_DECOR_CLOSE
);
1575 (OB_CLIENT_FUNC_RESIZE
|
1576 OB_CLIENT_FUNC_MOVE
|
1577 OB_CLIENT_FUNC_ICONIFY
|
1578 OB_CLIENT_FUNC_MAXIMIZE
|
1579 OB_CLIENT_FUNC_SHADE
|
1580 OB_CLIENT_FUNC_CLOSE
);
1582 if (!(self
->min_size
.width
< self
->max_size
.width
||
1583 self
->min_size
.height
< self
->max_size
.height
))
1584 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
1586 switch (self
->type
) {
1587 case OB_CLIENT_TYPE_NORMAL
:
1588 /* normal windows retain all of the possible decorations and
1589 functionality, and are the only windows that you can fullscreen */
1590 self
->functions
|= OB_CLIENT_FUNC_FULLSCREEN
;
1593 case OB_CLIENT_TYPE_DIALOG
:
1594 case OB_CLIENT_TYPE_UTILITY
:
1595 /* these windows cannot be maximized */
1596 self
->functions
&= ~OB_CLIENT_FUNC_MAXIMIZE
;
1599 case OB_CLIENT_TYPE_MENU
:
1600 case OB_CLIENT_TYPE_TOOLBAR
:
1601 /* these windows get less functionality */
1602 self
->functions
&= ~(OB_CLIENT_FUNC_ICONIFY
| OB_CLIENT_FUNC_RESIZE
);
1605 case OB_CLIENT_TYPE_SPLASH
:
1606 /* these don't get get any decorations, and the only thing you can
1607 do with them is move them */
1608 self
->decorations
= 0;
1609 self
->functions
= OB_CLIENT_FUNC_MOVE
;
1611 case OB_CLIENT_TYPE_DESKTOP
:
1612 case OB_CLIENT_TYPE_DOCK
:
1613 /* these windows are not manipulated by the window manager */
1614 self
->decorations
= 0;
1615 self
->functions
= 0;
1619 /* Mwm Hints are applied subtractively to what has already been chosen for
1620 decor and functionality */
1621 if (self
->mwmhints
.flags
& OB_MWM_FLAG_DECORATIONS
) {
1622 if (! (self
->mwmhints
.decorations
& OB_MWM_DECOR_ALL
)) {
1623 if (! ((self
->mwmhints
.decorations
& OB_MWM_DECOR_HANDLE
) ||
1624 (self
->mwmhints
.decorations
& OB_MWM_DECOR_TITLE
)))
1626 /* if the mwm hints request no handle or title, then all
1627 decorations are disabled, but keep the border if that's
1629 if (self
->mwmhints
.decorations
& OB_MWM_DECOR_BORDER
)
1630 self
->decorations
= OB_FRAME_DECOR_BORDER
;
1632 self
->decorations
= 0;
1637 if (self
->mwmhints
.flags
& OB_MWM_FLAG_FUNCTIONS
) {
1638 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_ALL
)) {
1639 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_RESIZE
))
1640 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
1641 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_MOVE
))
1642 self
->functions
&= ~OB_CLIENT_FUNC_MOVE
;
1643 /* dont let mwm hints kill any buttons
1644 if (! (self->mwmhints.functions & OB_MWM_FUNC_ICONIFY))
1645 self->functions &= ~OB_CLIENT_FUNC_ICONIFY;
1646 if (! (self->mwmhints.functions & OB_MWM_FUNC_MAXIMIZE))
1647 self->functions &= ~OB_CLIENT_FUNC_MAXIMIZE;
1649 /* dont let mwm hints kill the close button
1650 if (! (self->mwmhints.functions & MwmFunc_Close))
1651 self->functions &= ~OB_CLIENT_FUNC_CLOSE; */
1655 if (!(self
->functions
& OB_CLIENT_FUNC_SHADE
))
1656 self
->decorations
&= ~OB_FRAME_DECOR_SHADE
;
1657 if (!(self
->functions
& OB_CLIENT_FUNC_ICONIFY
))
1658 self
->decorations
&= ~OB_FRAME_DECOR_ICONIFY
;
1659 if (!(self
->functions
& OB_CLIENT_FUNC_RESIZE
))
1660 self
->decorations
&= ~OB_FRAME_DECOR_GRIPS
;
1662 /* can't maximize without moving/resizing */
1663 if (!((self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) &&
1664 (self
->functions
& OB_CLIENT_FUNC_MOVE
) &&
1665 (self
->functions
& OB_CLIENT_FUNC_RESIZE
))) {
1666 self
->functions
&= ~OB_CLIENT_FUNC_MAXIMIZE
;
1667 self
->decorations
&= ~OB_FRAME_DECOR_MAXIMIZE
;
1670 /* kill the handle on fully maxed windows */
1671 if (self
->max_vert
&& self
->max_horz
)
1672 self
->decorations
&= ~(OB_FRAME_DECOR_HANDLE
| OB_FRAME_DECOR_GRIPS
);
1674 /* finally, the user can have requested no decorations, which overrides
1675 everything (but doesnt give it a border if it doesnt have one) */
1676 if (self
->undecorated
) {
1677 if (config_theme_keepborder
)
1678 self
->decorations
&= OB_FRAME_DECOR_BORDER
;
1680 self
->decorations
= 0;
1683 /* if we don't have a titlebar, then we cannot shade! */
1684 if (!(self
->decorations
& OB_FRAME_DECOR_TITLEBAR
))
1685 self
->functions
&= ~OB_CLIENT_FUNC_SHADE
;
1687 /* now we need to check against rules for the client's current state */
1688 if (self
->fullscreen
) {
1689 self
->functions
&= (OB_CLIENT_FUNC_CLOSE
|
1690 OB_CLIENT_FUNC_FULLSCREEN
|
1691 OB_CLIENT_FUNC_ICONIFY
);
1692 self
->decorations
= 0;
1695 client_change_allowed_actions(self
);
1698 /* adjust the client's decorations, etc. */
1699 client_reconfigure(self
);
1703 static void client_change_allowed_actions(ObClient
*self
)
1708 /* desktop windows are kept on all desktops */
1709 if (self
->type
!= OB_CLIENT_TYPE_DESKTOP
)
1710 actions
[num
++] = prop_atoms
.net_wm_action_change_desktop
;
1712 if (self
->functions
& OB_CLIENT_FUNC_SHADE
)
1713 actions
[num
++] = prop_atoms
.net_wm_action_shade
;
1714 if (self
->functions
& OB_CLIENT_FUNC_CLOSE
)
1715 actions
[num
++] = prop_atoms
.net_wm_action_close
;
1716 if (self
->functions
& OB_CLIENT_FUNC_MOVE
)
1717 actions
[num
++] = prop_atoms
.net_wm_action_move
;
1718 if (self
->functions
& OB_CLIENT_FUNC_ICONIFY
)
1719 actions
[num
++] = prop_atoms
.net_wm_action_minimize
;
1720 if (self
->functions
& OB_CLIENT_FUNC_RESIZE
)
1721 actions
[num
++] = prop_atoms
.net_wm_action_resize
;
1722 if (self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
)
1723 actions
[num
++] = prop_atoms
.net_wm_action_fullscreen
;
1724 if (self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) {
1725 actions
[num
++] = prop_atoms
.net_wm_action_maximize_horz
;
1726 actions
[num
++] = prop_atoms
.net_wm_action_maximize_vert
;
1729 PROP_SETA32(self
->window
, net_wm_allowed_actions
, atom
, actions
, num
);
1731 /* make sure the window isn't breaking any rules now */
1733 if (!(self
->functions
& OB_CLIENT_FUNC_SHADE
) && self
->shaded
) {
1734 if (self
->frame
) client_shade(self
, FALSE
);
1735 else self
->shaded
= FALSE
;
1737 if (!(self
->functions
& OB_CLIENT_FUNC_ICONIFY
) && self
->iconic
) {
1738 if (self
->frame
) client_iconify(self
, FALSE
, TRUE
);
1739 else self
->iconic
= FALSE
;
1741 if (!(self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
) && self
->fullscreen
) {
1742 if (self
->frame
) client_fullscreen(self
, FALSE
);
1743 else self
->fullscreen
= FALSE
;
1745 if (!(self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) && (self
->max_horz
||
1747 if (self
->frame
) client_maximize(self
, FALSE
, 0);
1748 else self
->max_vert
= self
->max_horz
= FALSE
;
1752 void client_reconfigure(ObClient
*self
)
1754 /* by making this pass FALSE for user, we avoid the emacs event storm where
1755 every configurenotify causes an update in its normal hints, i think this
1756 is generally what we want anyways... */
1757 client_configure(self
, self
->area
.x
, self
->area
.y
,
1758 self
->area
.width
, self
->area
.height
, FALSE
, TRUE
);
1761 void client_update_wmhints(ObClient
*self
)
1765 /* assume a window takes input if it doesnt specify */
1766 self
->can_focus
= TRUE
;
1768 if ((hints
= XGetWMHints(ob_display
, self
->window
)) != NULL
) {
1771 if (hints
->flags
& InputHint
)
1772 self
->can_focus
= hints
->input
;
1774 /* only do this when first managing the window *AND* when we aren't
1776 if (ob_state() != OB_STATE_STARTING
&& self
->frame
== NULL
)
1777 if (hints
->flags
& StateHint
)
1778 self
->iconic
= hints
->initial_state
== IconicState
;
1781 self
->urgent
= (hints
->flags
& XUrgencyHint
);
1782 if (self
->urgent
&& !ur
)
1783 client_hilite(self
, TRUE
);
1784 else if (!self
->urgent
&& ur
&& self
->demands_attention
)
1785 client_hilite(self
, FALSE
);
1787 if (!(hints
->flags
& WindowGroupHint
))
1788 hints
->window_group
= None
;
1790 /* did the group state change? */
1791 if (hints
->window_group
!=
1792 (self
->group
? self
->group
->leader
: None
))
1794 ObGroup
*oldgroup
= self
->group
;
1796 /* remove from the old group if there was one */
1797 if (self
->group
!= NULL
) {
1798 group_remove(self
->group
, self
);
1802 /* add ourself to the group if we have one */
1803 if (hints
->window_group
!= None
) {
1804 self
->group
= group_add(hints
->window_group
, self
);
1807 /* Put ourselves into the new group's transient tree, and remove
1808 ourselves from the old group's */
1809 client_update_transient_tree(self
, oldgroup
, self
->group
,
1810 self
->transient_for
,
1811 self
->transient_for
);
1813 /* Lastly, being in a group, or not, can change if the window is
1814 transient for anything.
1816 The logic for this is:
1817 self->transient = TRUE always if the window wants to be
1818 transient for something, even if transient_for was NULL because
1819 it wasn't in a group before.
1821 If transient_for was NULL and oldgroup was NULL we can assume
1822 that when we add the new group, it will become transient for
1825 If transient_for was OB_TRAN_GROUP, then it must have already
1826 had a group. If it is getting a new group, the above call to
1827 client_update_transient_tree has already taken care of
1828 everything ! If it is losing all group status then it will
1829 no longer be transient for anything and that needs to be
1832 if (self
->transient
&&
1833 ((self
->transient_for
== NULL
&& oldgroup
== NULL
) ||
1834 (self
->transient_for
== OB_TRAN_GROUP
&& !self
->group
)))
1835 client_update_transient_for(self
);
1838 /* the WM_HINTS can contain an icon */
1839 client_update_icons(self
);
1845 void client_update_title(ObClient
*self
)
1848 gchar
*visible
= NULL
;
1850 g_free(self
->title
);
1853 if (!PROP_GETS(self
->window
, net_wm_name
, utf8
, &data
)) {
1854 /* try old x stuff */
1855 if (!(PROP_GETS(self
->window
, wm_name
, locale
, &data
)
1856 || PROP_GETS(self
->window
, wm_name
, utf8
, &data
))) {
1857 if (self
->transient
) {
1859 GNOME alert windows are not given titles:
1860 http://developer.gnome.org/projects/gup/hig/draft_hig_new/windows-alert.html
1862 data
= g_strdup("");
1864 data
= g_strdup("Unnamed Window");
1868 if (self
->client_machine
) {
1869 visible
= g_strdup_printf("%s (%s)", data
, self
->client_machine
);
1874 PROP_SETS(self
->window
, net_wm_visible_name
, visible
);
1875 self
->title
= visible
;
1878 frame_adjust_title(self
->frame
);
1880 /* update the icon title */
1882 g_free(self
->icon_title
);
1885 if (!PROP_GETS(self
->window
, net_wm_icon_name
, utf8
, &data
))
1886 /* try old x stuff */
1887 if (!(PROP_GETS(self
->window
, wm_icon_name
, locale
, &data
) ||
1888 PROP_GETS(self
->window
, wm_icon_name
, utf8
, &data
)))
1889 data
= g_strdup(self
->title
);
1891 PROP_SETS(self
->window
, net_wm_visible_icon_name
, data
);
1892 self
->icon_title
= data
;
1895 void client_update_strut(ObClient
*self
)
1899 gboolean got
= FALSE
;
1902 if (PROP_GETA32(self
->window
, net_wm_strut_partial
, cardinal
,
1906 STRUT_PARTIAL_SET(strut
,
1907 data
[0], data
[2], data
[1], data
[3],
1908 data
[4], data
[5], data
[8], data
[9],
1909 data
[6], data
[7], data
[10], data
[11]);
1915 PROP_GETA32(self
->window
, net_wm_strut
, cardinal
, &data
, &num
)) {
1921 /* use the screen's width/height */
1922 a
= screen_physical_area();
1924 STRUT_PARTIAL_SET(strut
,
1925 data
[0], data
[2], data
[1], data
[3],
1926 a
->y
, a
->y
+ a
->height
- 1,
1927 a
->x
, a
->x
+ a
->width
- 1,
1928 a
->y
, a
->y
+ a
->height
- 1,
1929 a
->x
, a
->x
+ a
->width
- 1);
1935 STRUT_PARTIAL_SET(strut
, 0, 0, 0, 0,
1936 0, 0, 0, 0, 0, 0, 0, 0);
1938 if (!STRUT_EQUAL(strut
, self
->strut
)) {
1939 self
->strut
= strut
;
1941 /* updating here is pointless while we're being mapped cuz we're not in
1942 the client list yet */
1944 screen_update_areas();
1948 void client_update_icons(ObClient
*self
)
1954 for (i
= 0; i
< self
->nicons
; ++i
)
1955 g_free(self
->icons
[i
].data
);
1956 if (self
->nicons
> 0)
1957 g_free(self
->icons
);
1960 if (PROP_GETA32(self
->window
, net_wm_icon
, cardinal
, &data
, &num
)) {
1961 /* figure out how many valid icons are in here */
1963 while (num
- i
> 2) {
1967 if (i
> num
|| w
*h
== 0) break;
1971 self
->icons
= g_new(ObClientIcon
, self
->nicons
);
1973 /* store the icons */
1975 for (j
= 0; j
< self
->nicons
; ++j
) {
1978 w
= self
->icons
[j
].width
= data
[i
++];
1979 h
= self
->icons
[j
].height
= data
[i
++];
1981 if (w
*h
== 0) continue;
1983 self
->icons
[j
].data
= g_new(RrPixel32
, w
* h
);
1984 for (x
= 0, y
= 0, t
= 0; t
< w
* h
; ++t
, ++x
, ++i
) {
1989 self
->icons
[j
].data
[t
] =
1990 (((data
[i
] >> 24) & 0xff) << RrDefaultAlphaOffset
) +
1991 (((data
[i
] >> 16) & 0xff) << RrDefaultRedOffset
) +
1992 (((data
[i
] >> 8) & 0xff) << RrDefaultGreenOffset
) +
1993 (((data
[i
] >> 0) & 0xff) << RrDefaultBlueOffset
);
2002 if ((hints
= XGetWMHints(ob_display
, self
->window
))) {
2003 if (hints
->flags
& IconPixmapHint
) {
2005 self
->icons
= g_new(ObClientIcon
, self
->nicons
);
2006 xerror_set_ignore(TRUE
);
2007 if (!RrPixmapToRGBA(ob_rr_inst
,
2009 (hints
->flags
& IconMaskHint
?
2010 hints
->icon_mask
: None
),
2011 &self
->icons
[self
->nicons
-1].width
,
2012 &self
->icons
[self
->nicons
-1].height
,
2013 &self
->icons
[self
->nicons
-1].data
)){
2014 g_free(&self
->icons
[self
->nicons
-1]);
2017 xerror_set_ignore(FALSE
);
2023 /* set the default icon onto the window
2024 in theory, this could be a race, but if a window doesn't set an icon
2025 or removes it entirely, it's not very likely it is going to set one
2026 right away afterwards */
2027 if (self
->nicons
== 0) {
2028 RrPixel32
*icon
= ob_rr_theme
->def_win_icon
;
2031 data
= g_new(gulong
, 48*48+2);
2032 data
[0] = data
[1] = 48;
2033 for (i
= 0; i
< 48*48; ++i
)
2034 data
[i
+2] = (((icon
[i
] >> RrDefaultAlphaOffset
) & 0xff) << 24) +
2035 (((icon
[i
] >> RrDefaultRedOffset
) & 0xff) << 16) +
2036 (((icon
[i
] >> RrDefaultGreenOffset
) & 0xff) << 8) +
2037 (((icon
[i
] >> RrDefaultBlueOffset
) & 0xff) << 0);
2038 PROP_SETA32(self
->window
, net_wm_icon
, cardinal
, data
, 48*48+2);
2040 } else if (self
->frame
)
2041 /* don't draw the icon empty if we're just setting one now anyways,
2042 we'll get the property change any second */
2043 frame_adjust_icon(self
->frame
);
2046 void client_update_user_time(ObClient
*self
)
2049 gboolean got
= FALSE
;
2051 if (self
->user_time_window
)
2052 got
= PROP_GET32(self
->user_time_window
,
2053 net_wm_user_time
, cardinal
, &time
);
2055 got
= PROP_GET32(self
->window
, net_wm_user_time
, cardinal
, &time
);
2058 /* we set this every time, not just when it grows, because in practice
2059 sometimes time goes backwards! (ntpdate.. yay....) so.. if it goes
2060 backward we don't want all windows to stop focusing. we'll just
2061 assume noone is setting times older than the last one, cuz that
2062 would be pretty stupid anyways
2064 self
->user_time
= time
;
2066 /*ob_debug("window %s user time %u\n", self->title, time);*/
2070 void client_update_user_time_window(ObClient
*self
)
2074 if (!PROP_GET32(self
->window
, net_wm_user_time_window
, window
, &w
))
2077 if (w
!= self
->user_time_window
) {
2078 /* remove the old window */
2079 propwin_remove(self
->user_time_window
, OB_PROPWIN_USER_TIME
, self
);
2080 self
->user_time_window
= None
;
2082 if (self
->group
&& self
->group
->leader
== w
) {
2083 ob_debug_type(OB_DEBUG_APP_BUGS
, "Window is setting its "
2084 "_NET_WM_USER_TYPE_WINDOW to its group leader\n");
2085 /* do it anyways..? */
2087 else if (w
== self
->window
) {
2088 ob_debug_type(OB_DEBUG_APP_BUGS
, "Window is setting its "
2089 "_NET_WM_USER_TIME_WINDOW to itself\n");
2090 w
= None
; /* don't do it */
2093 /* add the new window */
2094 propwin_add(w
, OB_PROPWIN_USER_TIME
, self
);
2095 self
->user_time_window
= w
;
2097 /* and update from it */
2098 client_update_user_time(self
);
2102 void client_update_icon_geometry(ObClient
*self
)
2107 RECT_SET(self
->icon_geometry
, 0, 0, 0, 0);
2109 if (PROP_GETA32(self
->window
, net_wm_icon_geometry
, cardinal
, &data
, &num
)
2112 /* don't let them set it with an area < 0 */
2113 RECT_SET(self
->icon_geometry
, data
[0], data
[1],
2114 MAX(data
[2],0), MAX(data
[3],0));
2118 static void client_get_session_ids(ObClient
*self
)
2125 if (!PROP_GET32(self
->window
, wm_client_leader
, window
, &leader
))
2128 /* get the SM_CLIENT_ID */
2131 got
= PROP_GETS(leader
, sm_client_id
, locale
, &self
->sm_client_id
);
2133 PROP_GETS(self
->window
, sm_client_id
, locale
, &self
->sm_client_id
);
2135 /* get the WM_CLASS (name and class). make them "" if they are not
2139 got
= PROP_GETSS(leader
, wm_class
, locale
, &ss
);
2141 got
= PROP_GETSS(self
->window
, wm_class
, locale
, &ss
);
2145 self
->name
= g_strdup(ss
[0]);
2147 self
->class = g_strdup(ss
[1]);
2152 if (self
->name
== NULL
) self
->name
= g_strdup("");
2153 if (self
->class == NULL
) self
->class = g_strdup("");
2155 /* get the WM_WINDOW_ROLE. make it "" if it is not provided */
2158 got
= PROP_GETS(leader
, wm_window_role
, locale
, &s
);
2160 got
= PROP_GETS(self
->window
, wm_window_role
, locale
, &s
);
2165 self
->role
= g_strdup("");
2167 /* get the WM_COMMAND */
2171 got
= PROP_GETSS(leader
, wm_command
, locale
, &ss
);
2173 got
= PROP_GETSS(self
->window
, wm_command
, locale
, &ss
);
2176 /* merge/mash them all together */
2177 gchar
*merge
= NULL
;
2180 for (i
= 0; ss
[i
]; ++i
) {
2183 merge
= g_strconcat(merge
, ss
[i
], NULL
);
2185 merge
= g_strconcat(ss
[i
], NULL
);
2190 self
->wm_command
= merge
;
2193 /* get the WM_CLIENT_MACHINE */
2196 got
= PROP_GETS(leader
, wm_client_machine
, locale
, &s
);
2198 got
= PROP_GETS(self
->window
, wm_client_machine
, locale
, &s
);
2201 gchar localhost
[128];
2203 gethostname(localhost
, 127);
2204 localhost
[127] = '\0';
2205 if (strcmp(localhost
, s
) != 0)
2206 self
->client_machine
= s
;
2212 static void client_change_wm_state(ObClient
*self
)
2217 old
= self
->wmstate
;
2219 if (self
->shaded
|| self
->iconic
||
2220 (self
->desktop
!= DESKTOP_ALL
&& self
->desktop
!= screen_desktop
))
2222 self
->wmstate
= IconicState
;
2224 self
->wmstate
= NormalState
;
2226 if (old
!= self
->wmstate
) {
2227 PROP_MSG(self
->window
, kde_wm_change_state
,
2228 self
->wmstate
, 1, 0, 0);
2230 state
[0] = self
->wmstate
;
2232 PROP_SETA32(self
->window
, wm_state
, wm_state
, state
, 2);
2236 static void client_change_state(ObClient
*self
)
2238 gulong netstate
[11];
2243 netstate
[num
++] = prop_atoms
.net_wm_state_modal
;
2245 netstate
[num
++] = prop_atoms
.net_wm_state_shaded
;
2247 netstate
[num
++] = prop_atoms
.net_wm_state_hidden
;
2248 if (self
->skip_taskbar
)
2249 netstate
[num
++] = prop_atoms
.net_wm_state_skip_taskbar
;
2250 if (self
->skip_pager
)
2251 netstate
[num
++] = prop_atoms
.net_wm_state_skip_pager
;
2252 if (self
->fullscreen
)
2253 netstate
[num
++] = prop_atoms
.net_wm_state_fullscreen
;
2255 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_vert
;
2257 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_horz
;
2259 netstate
[num
++] = prop_atoms
.net_wm_state_above
;
2261 netstate
[num
++] = prop_atoms
.net_wm_state_below
;
2262 if (self
->demands_attention
)
2263 netstate
[num
++] = prop_atoms
.net_wm_state_demands_attention
;
2264 if (self
->undecorated
)
2265 netstate
[num
++] = prop_atoms
.openbox_wm_state_undecorated
;
2266 PROP_SETA32(self
->window
, net_wm_state
, atom
, netstate
, num
);
2269 frame_adjust_state(self
->frame
);
2272 ObClient
*client_search_focus_tree(ObClient
*self
)
2277 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
2278 if (client_focused(it
->data
)) return it
->data
;
2279 if ((ret
= client_search_focus_tree(it
->data
))) return ret
;
2284 ObClient
*client_search_focus_tree_full(ObClient
*self
)
2286 if (self
->transient_for
) {
2287 if (self
->transient_for
!= OB_TRAN_GROUP
) {
2288 return client_search_focus_tree_full(self
->transient_for
);
2291 gboolean recursed
= FALSE
;
2293 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
))
2294 if (!((ObClient
*)it
->data
)->transient_for
) {
2296 if ((c
= client_search_focus_tree_full(it
->data
)))
2305 /* this function checks the whole tree, the client_search_focus_tree~
2306 does not, so we need to check this window */
2307 if (client_focused(self
))
2309 return client_search_focus_tree(self
);
2312 static ObStackingLayer
calc_layer(ObClient
*self
)
2316 if (self
->type
== OB_CLIENT_TYPE_DESKTOP
)
2317 l
= OB_STACKING_LAYER_DESKTOP
;
2318 else if (self
->type
== OB_CLIENT_TYPE_DOCK
) {
2319 if (self
->below
) l
= OB_STACKING_LAYER_NORMAL
;
2320 else l
= OB_STACKING_LAYER_ABOVE
;
2322 else if ((self
->fullscreen
||
2323 /* no decorations and fills the monitor = oldskool fullscreen */
2324 (self
->frame
!= NULL
&&
2325 (self
->frame
->size
.right
== 0 && self
->frame
->size
.left
== 0 &&
2326 self
->frame
->size
.bottom
== 0 && self
->frame
->size
.top
== 0 &&
2327 RECT_EQUAL(self
->area
,
2328 *screen_physical_area_monitor
2329 (client_monitor(self
)))))) &&
2330 (client_focused(self
) || client_search_focus_tree(self
)))
2331 l
= OB_STACKING_LAYER_FULLSCREEN
;
2332 else if (self
->above
) l
= OB_STACKING_LAYER_ABOVE
;
2333 else if (self
->below
) l
= OB_STACKING_LAYER_BELOW
;
2334 else l
= OB_STACKING_LAYER_NORMAL
;
2339 static void client_calc_layer_recursive(ObClient
*self
, ObClient
*orig
,
2340 ObStackingLayer min
, gboolean raised
)
2342 ObStackingLayer old
, own
;
2346 own
= calc_layer(self
);
2347 self
->layer
= MAX(own
, min
);
2349 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
2350 client_calc_layer_recursive(it
->data
, orig
,
2352 raised
? raised
: self
->layer
> old
);
2354 /* restack. but only if the original window is managed.
2356 raised is used so that only the bottom-most window in the stacking
2357 order is raised, the others will automatically come with it.
2359 also only the highest windows in the stacking order (no transients)
2360 are lowered, cuz the rest come for free
2362 if (!raised
&& orig
->frame
) {
2363 if (self
->layer
> old
) {
2364 stacking_remove(CLIENT_AS_WINDOW(self
));
2365 stacking_add_nonintrusive(CLIENT_AS_WINDOW(self
));
2366 } else if (self
->layer
< old
&& self
->transients
== NULL
) {
2367 stacking_remove(CLIENT_AS_WINDOW(self
));
2368 stacking_add_nonintrusive(CLIENT_AS_WINDOW(self
));
2373 void client_calc_layer(ObClient
*self
)
2380 /* transients take on the layer of their parents */
2381 it
= client_search_all_top_parents(self
);
2383 for (; it
; it
= g_slist_next(it
))
2384 client_calc_layer_recursive(it
->data
, orig
, 0, FALSE
);
2387 gboolean
client_should_show(ObClient
*self
)
2391 if (client_normal(self
) && screen_showing_desktop
)
2393 if (self
->desktop
== screen_desktop
|| self
->desktop
== DESKTOP_ALL
)
2399 void client_show(ObClient
*self
)
2402 if (client_should_show(self
)) {
2403 frame_show(self
->frame
);
2406 /* According to the ICCCM (sec 4.1.3.1) when a window is not visible, it
2407 needs to be in IconicState. This includes when it is on another
2410 client_change_wm_state(self
);
2413 void client_hide(ObClient
*self
)
2415 if (!client_should_show(self
)) {
2416 frame_hide(self
->frame
);
2419 /* According to the ICCCM (sec 4.1.3.1) when a window is not visible, it
2420 needs to be in IconicState. This includes when it is on another
2423 client_change_wm_state(self
);
2426 void client_showhide(ObClient
*self
)
2429 if (client_should_show(self
)) {
2430 frame_show(self
->frame
);
2433 frame_hide(self
->frame
);
2436 /* According to the ICCCM (sec 4.1.3.1) when a window is not visible, it
2437 needs to be in IconicState. This includes when it is on another
2440 client_change_wm_state(self
);
2443 gboolean
client_normal(ObClient
*self
) {
2444 return ! (self
->type
== OB_CLIENT_TYPE_DESKTOP
||
2445 self
->type
== OB_CLIENT_TYPE_DOCK
||
2446 self
->type
== OB_CLIENT_TYPE_SPLASH
);
2449 gboolean
client_helper(ObClient
*self
)
2451 return (self
->type
== OB_CLIENT_TYPE_UTILITY
||
2452 self
->type
== OB_CLIENT_TYPE_MENU
||
2453 self
->type
== OB_CLIENT_TYPE_TOOLBAR
);
2456 gboolean
client_mouse_focusable(ObClient
*self
)
2458 return !(self
->type
== OB_CLIENT_TYPE_MENU
||
2459 self
->type
== OB_CLIENT_TYPE_TOOLBAR
||
2460 self
->type
== OB_CLIENT_TYPE_SPLASH
||
2461 self
->type
== OB_CLIENT_TYPE_DOCK
);
2464 gboolean
client_enter_focusable(ObClient
*self
)
2466 /* you can focus desktops but it shouldn't on enter */
2467 return (client_mouse_focusable(self
) &&
2468 self
->type
!= OB_CLIENT_TYPE_DESKTOP
);
2472 static void client_apply_startup_state(ObClient
*self
, gint x
, gint y
)
2474 gboolean pos
= FALSE
; /* has the window's position been configured? */
2477 /* save the position, and set self->area for these to use */
2483 /* set the desktop hint, to make sure that it always exists */
2484 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, self
->desktop
);
2486 /* these are in a carefully crafted order.. */
2489 self
->iconic
= FALSE
;
2490 client_iconify(self
, TRUE
, FALSE
);
2492 if (self
->fullscreen
) {
2493 self
->fullscreen
= FALSE
;
2494 client_fullscreen(self
, TRUE
);
2497 if (self
->undecorated
) {
2498 self
->undecorated
= FALSE
;
2499 client_set_undecorated(self
, TRUE
);
2502 self
->shaded
= FALSE
;
2503 client_shade(self
, TRUE
);
2505 if (self
->demands_attention
) {
2506 self
->demands_attention
= FALSE
;
2507 client_hilite(self
, TRUE
);
2510 if (self
->max_vert
&& self
->max_horz
) {
2511 self
->max_vert
= self
->max_horz
= FALSE
;
2512 client_maximize(self
, TRUE
, 0);
2514 } else if (self
->max_vert
) {
2515 self
->max_vert
= FALSE
;
2516 client_maximize(self
, TRUE
, 2);
2518 } else if (self
->max_horz
) {
2519 self
->max_horz
= FALSE
;
2520 client_maximize(self
, TRUE
, 1);
2524 /* if the client didn't get positioned yet, then do so now.
2525 call client_move even if the window is not being moved anywhere, because
2526 when we reparent it and decorate it, it is getting moved and we need to
2527 be telling it so with a ConfigureNotify event.
2530 /* use the saved position */
2533 client_move(self
, x
, y
);
2536 /* nothing to do for the other states:
2545 void client_convert_gravity(ObClient
*self
, gint gravity
, gint
*x
, gint
*y
,
2548 gint oldg
= self
->gravity
;
2550 /* get the frame's position from the requested stuff */
2551 self
->gravity
= gravity
;
2552 frame_client_gravity(self
->frame
, x
, y
, w
, h
);
2553 self
->gravity
= oldg
;
2555 /* get the client's position in its true gravity from that */
2556 frame_frame_gravity(self
->frame
, x
, y
, w
, h
);
2559 void client_try_configure(ObClient
*self
, gint
*x
, gint
*y
, gint
*w
, gint
*h
,
2560 gint
*logicalw
, gint
*logicalh
,
2563 Rect desired_area
= {*x
, *y
, *w
, *h
};
2565 /* make the frame recalculate its dimentions n shit without changing
2566 anything visible for real, this way the constraints below can work with
2567 the updated frame dimensions. */
2568 frame_adjust_area(self
->frame
, TRUE
, TRUE
, TRUE
);
2570 /* work within the prefered sizes given by the window */
2571 if (!(*w
== self
->area
.width
&& *h
== self
->area
.height
)) {
2572 gint basew
, baseh
, minw
, minh
;
2574 /* base size is substituted with min size if not specified */
2575 if (self
->base_size
.width
|| self
->base_size
.height
) {
2576 basew
= self
->base_size
.width
;
2577 baseh
= self
->base_size
.height
;
2579 basew
= self
->min_size
.width
;
2580 baseh
= self
->min_size
.height
;
2582 /* min size is substituted with base size if not specified */
2583 if (self
->min_size
.width
|| self
->min_size
.height
) {
2584 minw
= self
->min_size
.width
;
2585 minh
= self
->min_size
.height
;
2587 minw
= self
->base_size
.width
;
2588 minh
= self
->base_size
.height
;
2591 /* if this is a user-requested resize, then check against min/max
2594 /* smaller than min size or bigger than max size? */
2595 if (*w
> self
->max_size
.width
) *w
= self
->max_size
.width
;
2596 if (*w
< minw
) *w
= minw
;
2597 if (*h
> self
->max_size
.height
) *h
= self
->max_size
.height
;
2598 if (*h
< minh
) *h
= minh
;
2603 /* keep to the increments */
2604 *w
/= self
->size_inc
.width
;
2605 *h
/= self
->size_inc
.height
;
2607 /* you cannot resize to nothing */
2608 if (basew
+ *w
< 1) *w
= 1 - basew
;
2609 if (baseh
+ *h
< 1) *h
= 1 - baseh
;
2611 /* save the logical size */
2612 *logicalw
= self
->size_inc
.width
> 1 ? *w
: *w
+ basew
;
2613 *logicalh
= self
->size_inc
.height
> 1 ? *h
: *h
+ baseh
;
2615 *w
*= self
->size_inc
.width
;
2616 *h
*= self
->size_inc
.height
;
2621 /* adjust the height to match the width for the aspect ratios.
2622 for this, min size is not substituted for base size ever. */
2623 *w
-= self
->base_size
.width
;
2624 *h
-= self
->base_size
.height
;
2626 if (!self
->fullscreen
) {
2627 if (self
->min_ratio
)
2628 if (*h
* self
->min_ratio
> *w
) {
2629 *h
= (gint
)(*w
/ self
->min_ratio
);
2631 /* you cannot resize to nothing */
2634 *w
= (gint
)(*h
* self
->min_ratio
);
2637 if (self
->max_ratio
)
2638 if (*h
* self
->max_ratio
< *w
) {
2639 *h
= (gint
)(*w
/ self
->max_ratio
);
2641 /* you cannot resize to nothing */
2644 *w
= (gint
)(*h
* self
->min_ratio
);
2649 *w
+= self
->base_size
.width
;
2650 *h
+= self
->base_size
.height
;
2653 /* gets the frame's position */
2654 frame_client_gravity(self
->frame
, x
, y
, *w
, *h
);
2656 /* these positions are frame positions, not client positions */
2658 /* set the size and position if fullscreen */
2659 if (self
->fullscreen
) {
2663 i
= screen_find_monitor(&desired_area
);
2664 a
= screen_physical_area_monitor(i
);
2671 user
= FALSE
; /* ignore if the client can't be moved/resized when it
2672 is entering fullscreen */
2673 } else if (self
->max_horz
|| self
->max_vert
) {
2677 i
= screen_find_monitor(&desired_area
);
2678 a
= screen_area_monitor(self
->desktop
, i
);
2680 /* set the size and position if maximized */
2681 if (self
->max_horz
) {
2683 *w
= a
->width
- self
->frame
->size
.left
- self
->frame
->size
.right
;
2685 if (self
->max_vert
) {
2687 *h
= a
->height
- self
->frame
->size
.top
- self
->frame
->size
.bottom
;
2690 /* maximizing is not allowed if the user can't move+resize the window
2694 /* gets the client's position */
2695 frame_frame_gravity(self
->frame
, x
, y
, *w
, *h
);
2697 /* these override the above states! if you cant move you can't move! */
2699 if (!(self
->functions
& OB_CLIENT_FUNC_MOVE
)) {
2703 if (!(self
->functions
& OB_CLIENT_FUNC_RESIZE
)) {
2704 *w
= self
->area
.width
;
2705 *h
= self
->area
.height
;
2714 void client_configure_full(ObClient
*self
, gint x
, gint y
, gint w
, gint h
,
2715 gboolean user
, gboolean final
,
2716 gboolean force_reply
)
2718 gint oldw
, oldh
, oldrx
, oldry
;
2719 gboolean send_resize_client
;
2720 gboolean moved
= FALSE
, resized
= FALSE
, rootmoved
= FALSE
;
2721 guint fdecor
= self
->frame
->decorations
;
2722 gboolean fhorz
= self
->frame
->max_horz
;
2723 gint logicalw
, logicalh
;
2725 /* find the new x, y, width, and height (and logical size) */
2726 client_try_configure(self
, &x
, &y
, &w
, &h
, &logicalw
, &logicalh
, user
);
2728 /* set the logical size if things changed */
2729 if (!(w
== self
->area
.width
&& h
== self
->area
.height
))
2730 SIZE_SET(self
->logical_size
, logicalw
, logicalh
);
2732 /* figure out if we moved or resized or what */
2733 moved
= x
!= self
->area
.x
|| y
!= self
->area
.y
;
2734 resized
= w
!= self
->area
.width
|| h
!= self
->area
.height
;
2736 oldw
= self
->area
.width
;
2737 oldh
= self
->area
.height
;
2738 RECT_SET(self
->area
, x
, y
, w
, h
);
2740 /* for app-requested resizes, always resize if 'resized' is true.
2741 for user-requested ones, only resize if final is true, or when
2742 resizing in redraw mode */
2743 send_resize_client
= ((!user
&& resized
) ||
2745 (resized
&& config_resize_redraw
))));
2747 /* if the client is enlarging, then resize the client before the frame */
2748 if (send_resize_client
&& user
&& (w
> oldw
|| h
> oldh
)) {
2749 XResizeWindow(ob_display
, self
->window
, MAX(w
, oldw
), MAX(h
, oldh
));
2750 /* resize the plate to show the client padding color underneath */
2751 frame_adjust_client_area(self
->frame
);
2754 /* find the frame's dimensions and move/resize it */
2755 if (self
->decorations
!= fdecor
|| self
->max_horz
!= fhorz
)
2756 moved
= resized
= TRUE
;
2757 if (moved
|| resized
)
2758 frame_adjust_area(self
->frame
, moved
, resized
, FALSE
);
2760 /* find the client's position relative to the root window */
2761 oldrx
= self
->root_pos
.x
;
2762 oldry
= self
->root_pos
.y
;
2763 rootmoved
= (oldrx
!= (signed)(self
->frame
->area
.x
+
2764 self
->frame
->size
.left
-
2765 self
->border_width
) ||
2766 oldry
!= (signed)(self
->frame
->area
.y
+
2767 self
->frame
->size
.top
-
2768 self
->border_width
));
2770 if (force_reply
|| ((!user
|| (user
&& final
)) && rootmoved
))
2774 POINT_SET(self
->root_pos
,
2775 self
->frame
->area
.x
+ self
->frame
->size
.left
-
2777 self
->frame
->area
.y
+ self
->frame
->size
.top
-
2778 self
->border_width
);
2780 event
.type
= ConfigureNotify
;
2781 event
.xconfigure
.display
= ob_display
;
2782 event
.xconfigure
.event
= self
->window
;
2783 event
.xconfigure
.window
= self
->window
;
2785 /* root window real coords */
2786 event
.xconfigure
.x
= self
->root_pos
.x
;
2787 event
.xconfigure
.y
= self
->root_pos
.y
;
2788 event
.xconfigure
.width
= w
;
2789 event
.xconfigure
.height
= h
;
2790 event
.xconfigure
.border_width
= 0;
2791 event
.xconfigure
.above
= self
->frame
->plate
;
2792 event
.xconfigure
.override_redirect
= FALSE
;
2793 XSendEvent(event
.xconfigure
.display
, event
.xconfigure
.window
,
2794 FALSE
, StructureNotifyMask
, &event
);
2797 /* if the client is shrinking, then resize the frame before the client */
2798 if (send_resize_client
&& (!user
|| (w
<= oldw
|| h
<= oldh
))) {
2799 /* resize the plate to show the client padding color underneath */
2800 frame_adjust_client_area(self
->frame
);
2802 XResizeWindow(ob_display
, self
->window
, w
, h
);
2808 void client_fullscreen(ObClient
*self
, gboolean fs
)
2812 if (!(self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
) || /* can't */
2813 self
->fullscreen
== fs
) return; /* already done */
2815 self
->fullscreen
= fs
;
2816 client_change_state(self
); /* change the state hints on the client */
2817 client_calc_layer(self
); /* and adjust out layer/stacking */
2820 self
->pre_fullscreen_area
= self
->area
;
2821 /* if the window is maximized, its area isn't all that meaningful.
2822 save it's premax area instead. */
2823 if (self
->max_horz
) {
2824 self
->pre_fullscreen_area
.x
= self
->pre_max_area
.x
;
2825 self
->pre_fullscreen_area
.width
= self
->pre_max_area
.width
;
2827 if (self
->max_vert
) {
2828 self
->pre_fullscreen_area
.y
= self
->pre_max_area
.y
;
2829 self
->pre_fullscreen_area
.height
= self
->pre_max_area
.height
;
2832 /* these are not actually used cuz client_configure will set them
2833 as appropriate when the window is fullscreened */
2838 if (self
->pre_fullscreen_area
.width
> 0 &&
2839 self
->pre_fullscreen_area
.height
> 0)
2841 x
= self
->pre_fullscreen_area
.x
;
2842 y
= self
->pre_fullscreen_area
.y
;
2843 w
= self
->pre_fullscreen_area
.width
;
2844 h
= self
->pre_fullscreen_area
.height
;
2845 RECT_SET(self
->pre_fullscreen_area
, 0, 0, 0, 0);
2847 /* pick some fallbacks... */
2848 a
= screen_area_monitor(self
->desktop
, 0);
2849 x
= a
->x
+ a
->width
/ 4;
2850 y
= a
->y
+ a
->height
/ 4;
2856 client_setup_decor_and_functions(self
);
2858 client_move_resize(self
, x
, y
, w
, h
);
2860 /* try focus us when we go into fullscreen mode */
2864 static void client_iconify_recursive(ObClient
*self
,
2865 gboolean iconic
, gboolean curdesk
)
2868 gboolean changed
= FALSE
;
2871 if (self
->iconic
!= iconic
) {
2872 ob_debug("%sconifying window: 0x%lx\n", (iconic
? "I" : "Uni"),
2876 /* don't let non-normal windows iconify along with their parents
2878 if (client_normal(self
)) {
2879 self
->iconic
= iconic
;
2881 /* update the focus lists.. iconic windows go to the bottom of
2882 the list, put the new iconic window at the 'top of the
2884 focus_order_to_top(self
);
2889 self
->iconic
= iconic
;
2891 if (curdesk
&& self
->desktop
!= screen_desktop
&&
2892 self
->desktop
!= DESKTOP_ALL
)
2893 client_set_desktop(self
, screen_desktop
, FALSE
);
2895 /* this puts it after the current focused window */
2896 focus_order_remove(self
);
2897 focus_order_add_new(self
);
2904 client_change_state(self
);
2905 if (ob_state() != OB_STATE_STARTING
&& config_animate_iconify
)
2906 frame_begin_iconify_animation(self
->frame
, iconic
);
2907 /* do this after starting the animation so it doesn't flash */
2908 client_showhide(self
);
2911 /* iconify all direct transients, and deiconify all transients
2913 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
2914 if (it
->data
!= self
)
2915 if (client_is_direct_child(self
, it
->data
) || !iconic
)
2916 client_iconify_recursive(it
->data
, iconic
, curdesk
);
2919 void client_iconify(ObClient
*self
, gboolean iconic
, gboolean curdesk
)
2921 if (self
->functions
& OB_CLIENT_FUNC_ICONIFY
|| !iconic
) {
2922 /* move up the transient chain as far as possible first */
2923 self
= client_search_top_normal_parent(self
);
2924 client_iconify_recursive(self
, iconic
, curdesk
);
2928 void client_maximize(ObClient
*self
, gboolean max
, gint dir
)
2932 g_assert(dir
== 0 || dir
== 1 || dir
== 2);
2933 if (!(self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
)) return; /* can't */
2935 /* check if already done */
2937 if (dir
== 0 && self
->max_horz
&& self
->max_vert
) return;
2938 if (dir
== 1 && self
->max_horz
) return;
2939 if (dir
== 2 && self
->max_vert
) return;
2941 if (dir
== 0 && !self
->max_horz
&& !self
->max_vert
) return;
2942 if (dir
== 1 && !self
->max_horz
) return;
2943 if (dir
== 2 && !self
->max_vert
) return;
2946 /* we just tell it to configure in the same place and client_configure
2947 worries about filling the screen with the window */
2950 w
= self
->area
.width
;
2951 h
= self
->area
.height
;
2954 if ((dir
== 0 || dir
== 1) && !self
->max_horz
) { /* horz */
2955 RECT_SET(self
->pre_max_area
,
2956 self
->area
.x
, self
->pre_max_area
.y
,
2957 self
->area
.width
, self
->pre_max_area
.height
);
2959 if ((dir
== 0 || dir
== 2) && !self
->max_vert
) { /* vert */
2960 RECT_SET(self
->pre_max_area
,
2961 self
->pre_max_area
.x
, self
->area
.y
,
2962 self
->pre_max_area
.width
, self
->area
.height
);
2967 a
= screen_area_monitor(self
->desktop
, 0);
2968 if ((dir
== 0 || dir
== 1) && self
->max_horz
) { /* horz */
2969 if (self
->pre_max_area
.width
> 0) {
2970 x
= self
->pre_max_area
.x
;
2971 w
= self
->pre_max_area
.width
;
2973 RECT_SET(self
->pre_max_area
, 0, self
->pre_max_area
.y
,
2974 0, self
->pre_max_area
.height
);
2976 /* pick some fallbacks... */
2977 x
= a
->x
+ a
->width
/ 4;
2981 if ((dir
== 0 || dir
== 2) && self
->max_vert
) { /* vert */
2982 if (self
->pre_max_area
.height
> 0) {
2983 y
= self
->pre_max_area
.y
;
2984 h
= self
->pre_max_area
.height
;
2986 RECT_SET(self
->pre_max_area
, self
->pre_max_area
.x
, 0,
2987 self
->pre_max_area
.width
, 0);
2989 /* pick some fallbacks... */
2990 y
= a
->y
+ a
->height
/ 4;
2996 if (dir
== 0 || dir
== 1) /* horz */
2997 self
->max_horz
= max
;
2998 if (dir
== 0 || dir
== 2) /* vert */
2999 self
->max_vert
= max
;
3001 client_change_state(self
); /* change the state hints on the client */
3003 client_setup_decor_and_functions(self
);
3005 client_move_resize(self
, x
, y
, w
, h
);
3008 void client_shade(ObClient
*self
, gboolean shade
)
3010 if ((!(self
->functions
& OB_CLIENT_FUNC_SHADE
) &&
3011 shade
) || /* can't shade */
3012 self
->shaded
== shade
) return; /* already done */
3014 self
->shaded
= shade
;
3015 client_change_state(self
);
3016 client_change_wm_state(self
); /* the window is being hidden/shown */
3017 /* resize the frame to just the titlebar */
3018 frame_adjust_area(self
->frame
, FALSE
, FALSE
, FALSE
);
3021 void client_close(ObClient
*self
)
3025 if (!(self
->functions
& OB_CLIENT_FUNC_CLOSE
)) return;
3027 /* in the case that the client provides no means to requesting that it
3028 close, we just kill it */
3029 if (!self
->delete_window
)
3033 XXX: itd be cool to do timeouts and shit here for killing the client's
3035 like... if the window is around after 5 seconds, then the close button
3036 turns a nice red, and if this function is called again, the client is
3040 ce
.xclient
.type
= ClientMessage
;
3041 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
3042 ce
.xclient
.display
= ob_display
;
3043 ce
.xclient
.window
= self
->window
;
3044 ce
.xclient
.format
= 32;
3045 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_delete_window
;
3046 ce
.xclient
.data
.l
[1] = event_curtime
;
3047 ce
.xclient
.data
.l
[2] = 0l;
3048 ce
.xclient
.data
.l
[3] = 0l;
3049 ce
.xclient
.data
.l
[4] = 0l;
3050 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
3053 void client_kill(ObClient
*self
)
3055 XKillClient(ob_display
, self
->window
);
3058 void client_hilite(ObClient
*self
, gboolean hilite
)
3060 if (self
->demands_attention
== hilite
)
3061 return; /* no change */
3063 /* don't allow focused windows to hilite */
3064 self
->demands_attention
= hilite
&& !client_focused(self
);
3065 if (self
->frame
!= NULL
) { /* if we're mapping, just set the state */
3066 if (self
->demands_attention
)
3067 frame_flash_start(self
->frame
);
3069 frame_flash_stop(self
->frame
);
3070 client_change_state(self
);
3074 void client_set_desktop_recursive(ObClient
*self
,
3081 if (target
!= self
->desktop
) {
3083 ob_debug("Setting desktop %u\n", target
+1);
3085 g_assert(target
< screen_num_desktops
|| target
== DESKTOP_ALL
);
3087 old
= self
->desktop
;
3088 self
->desktop
= target
;
3089 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, target
);
3090 /* the frame can display the current desktop state */
3091 frame_adjust_state(self
->frame
);
3092 /* 'move' the window to the new desktop */
3094 client_showhide(self
);
3095 /* raise if it was not already on the desktop */
3096 if (old
!= DESKTOP_ALL
)
3097 stacking_raise(CLIENT_AS_WINDOW(self
));
3098 if (STRUT_EXISTS(self
->strut
))
3099 screen_update_areas();
3102 /* move all transients */
3103 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
3104 if (it
->data
!= self
)
3105 if (client_is_direct_child(self
, it
->data
))
3106 client_set_desktop_recursive(it
->data
, target
, donthide
);
3109 void client_set_desktop(ObClient
*self
, guint target
,
3112 self
= client_search_top_normal_parent(self
);
3113 client_set_desktop_recursive(self
, target
, donthide
);
3116 gboolean
client_is_direct_child(ObClient
*parent
, ObClient
*child
)
3118 while (child
!= parent
&&
3119 child
->transient_for
&& child
->transient_for
!= OB_TRAN_GROUP
)
3120 child
= child
->transient_for
;
3121 return child
== parent
;
3124 ObClient
*client_search_modal_child(ObClient
*self
)
3129 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
3130 ObClient
*c
= it
->data
;
3131 if ((ret
= client_search_modal_child(c
))) return ret
;
3132 if (c
->modal
) return c
;
3137 gboolean
client_validate(ObClient
*self
)
3141 XSync(ob_display
, FALSE
); /* get all events on the server */
3143 if (XCheckTypedWindowEvent(ob_display
, self
->window
, DestroyNotify
, &e
) ||
3144 XCheckTypedWindowEvent(ob_display
, self
->window
, UnmapNotify
, &e
)) {
3145 XPutBackEvent(ob_display
, &e
);
3152 void client_set_wm_state(ObClient
*self
, glong state
)
3154 if (state
== self
->wmstate
) return; /* no change */
3158 client_iconify(self
, TRUE
, TRUE
);
3161 client_iconify(self
, FALSE
, TRUE
);
3166 void client_set_state(ObClient
*self
, Atom action
, glong data1
, glong data2
)
3168 gboolean shaded
= self
->shaded
;
3169 gboolean fullscreen
= self
->fullscreen
;
3170 gboolean undecorated
= self
->undecorated
;
3171 gboolean max_horz
= self
->max_horz
;
3172 gboolean max_vert
= self
->max_vert
;
3173 gboolean modal
= self
->modal
;
3174 gboolean iconic
= self
->iconic
;
3175 gboolean demands_attention
= self
->demands_attention
;
3176 gboolean above
= self
->above
;
3177 gboolean below
= self
->below
;
3180 if (!(action
== prop_atoms
.net_wm_state_add
||
3181 action
== prop_atoms
.net_wm_state_remove
||
3182 action
== prop_atoms
.net_wm_state_toggle
))
3183 /* an invalid action was passed to the client message, ignore it */
3186 for (i
= 0; i
< 2; ++i
) {
3187 Atom state
= i
== 0 ? data1
: data2
;
3189 if (!state
) continue;
3191 /* if toggling, then pick whether we're adding or removing */
3192 if (action
== prop_atoms
.net_wm_state_toggle
) {
3193 if (state
== prop_atoms
.net_wm_state_modal
)
3194 action
= modal
? prop_atoms
.net_wm_state_remove
:
3195 prop_atoms
.net_wm_state_add
;
3196 else if (state
== prop_atoms
.net_wm_state_maximized_vert
)
3197 action
= self
->max_vert
? prop_atoms
.net_wm_state_remove
:
3198 prop_atoms
.net_wm_state_add
;
3199 else if (state
== prop_atoms
.net_wm_state_maximized_horz
)
3200 action
= self
->max_horz
? prop_atoms
.net_wm_state_remove
:
3201 prop_atoms
.net_wm_state_add
;
3202 else if (state
== prop_atoms
.net_wm_state_shaded
)
3203 action
= shaded
? prop_atoms
.net_wm_state_remove
:
3204 prop_atoms
.net_wm_state_add
;
3205 else if (state
== prop_atoms
.net_wm_state_skip_taskbar
)
3206 action
= self
->skip_taskbar
?
3207 prop_atoms
.net_wm_state_remove
:
3208 prop_atoms
.net_wm_state_add
;
3209 else if (state
== prop_atoms
.net_wm_state_skip_pager
)
3210 action
= self
->skip_pager
?
3211 prop_atoms
.net_wm_state_remove
:
3212 prop_atoms
.net_wm_state_add
;
3213 else if (state
== prop_atoms
.net_wm_state_hidden
)
3214 action
= self
->iconic
?
3215 prop_atoms
.net_wm_state_remove
:
3216 prop_atoms
.net_wm_state_add
;
3217 else if (state
== prop_atoms
.net_wm_state_fullscreen
)
3218 action
= fullscreen
?
3219 prop_atoms
.net_wm_state_remove
:
3220 prop_atoms
.net_wm_state_add
;
3221 else if (state
== prop_atoms
.net_wm_state_above
)
3222 action
= self
->above
? prop_atoms
.net_wm_state_remove
:
3223 prop_atoms
.net_wm_state_add
;
3224 else if (state
== prop_atoms
.net_wm_state_below
)
3225 action
= self
->below
? prop_atoms
.net_wm_state_remove
:
3226 prop_atoms
.net_wm_state_add
;
3227 else if (state
== prop_atoms
.net_wm_state_demands_attention
)
3228 action
= self
->demands_attention
?
3229 prop_atoms
.net_wm_state_remove
:
3230 prop_atoms
.net_wm_state_add
;
3231 else if (state
== prop_atoms
.openbox_wm_state_undecorated
)
3232 action
= undecorated
? prop_atoms
.net_wm_state_remove
:
3233 prop_atoms
.net_wm_state_add
;
3236 if (action
== prop_atoms
.net_wm_state_add
) {
3237 if (state
== prop_atoms
.net_wm_state_modal
) {
3239 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
3241 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
3243 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
3245 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
3246 self
->skip_taskbar
= TRUE
;
3247 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
3248 self
->skip_pager
= TRUE
;
3249 } else if (state
== prop_atoms
.net_wm_state_hidden
) {
3251 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
3253 } else if (state
== prop_atoms
.net_wm_state_above
) {
3256 } else if (state
== prop_atoms
.net_wm_state_below
) {
3259 } else if (state
== prop_atoms
.net_wm_state_demands_attention
) {
3260 demands_attention
= TRUE
;
3261 } else if (state
== prop_atoms
.openbox_wm_state_undecorated
) {
3265 } else { /* action == prop_atoms.net_wm_state_remove */
3266 if (state
== prop_atoms
.net_wm_state_modal
) {
3268 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
3270 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
3272 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
3274 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
3275 self
->skip_taskbar
= FALSE
;
3276 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
3277 self
->skip_pager
= FALSE
;
3278 } else if (state
== prop_atoms
.net_wm_state_hidden
) {
3280 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
3282 } else if (state
== prop_atoms
.net_wm_state_above
) {
3284 } else if (state
== prop_atoms
.net_wm_state_below
) {
3286 } else if (state
== prop_atoms
.net_wm_state_demands_attention
) {
3287 demands_attention
= FALSE
;
3288 } else if (state
== prop_atoms
.openbox_wm_state_undecorated
) {
3289 undecorated
= FALSE
;
3293 if (max_horz
!= self
->max_horz
|| max_vert
!= self
->max_vert
) {
3294 if (max_horz
!= self
->max_horz
&& max_vert
!= self
->max_vert
) {
3296 if (max_horz
== max_vert
) { /* both going the same way */
3297 client_maximize(self
, max_horz
, 0);
3299 client_maximize(self
, max_horz
, 1);
3300 client_maximize(self
, max_vert
, 2);
3304 if (max_horz
!= self
->max_horz
)
3305 client_maximize(self
, max_horz
, 1);
3307 client_maximize(self
, max_vert
, 2);
3310 /* change fullscreen state before shading, as it will affect if the window
3312 if (fullscreen
!= self
->fullscreen
)
3313 client_fullscreen(self
, fullscreen
);
3314 if (shaded
!= self
->shaded
)
3315 client_shade(self
, shaded
);
3316 if (undecorated
!= self
->undecorated
)
3317 client_set_undecorated(self
, undecorated
);
3318 if (modal
!= self
->modal
) {
3319 self
->modal
= modal
;
3320 /* when a window changes modality, then its stacking order with its
3321 transients needs to change */
3322 stacking_raise(CLIENT_AS_WINDOW(self
));
3324 if (iconic
!= self
->iconic
)
3325 client_iconify(self
, iconic
, FALSE
);
3327 if (demands_attention
!= self
->demands_attention
)
3328 client_hilite(self
, demands_attention
);
3330 if (above
!= self
->above
|| below
!= self
->below
) {
3331 self
->above
= above
;
3332 self
->below
= below
;
3333 client_calc_layer(self
);
3336 client_change_state(self
); /* change the hint to reflect these changes */
3339 ObClient
*client_focus_target(ObClient
*self
)
3341 ObClient
*child
= NULL
;
3343 child
= client_search_modal_child(self
);
3344 if (child
) return child
;
3348 gboolean
client_can_focus(ObClient
*self
)
3352 /* choose the correct target */
3353 self
= client_focus_target(self
);
3355 if (!self
->frame
->visible
)
3358 if (!(self
->can_focus
|| self
->focus_notify
))
3361 /* do a check to see if the window has already been unmapped or destroyed
3362 do this intelligently while watching out for unmaps we've generated
3363 (ignore_unmaps > 0) */
3364 if (XCheckTypedWindowEvent(ob_display
, self
->window
,
3365 DestroyNotify
, &ev
)) {
3366 XPutBackEvent(ob_display
, &ev
);
3369 while (XCheckTypedWindowEvent(ob_display
, self
->window
,
3370 UnmapNotify
, &ev
)) {
3371 if (self
->ignore_unmaps
) {
3372 self
->ignore_unmaps
--;
3374 XPutBackEvent(ob_display
, &ev
);
3382 gboolean
client_focus(ObClient
*self
)
3384 /* choose the correct target */
3385 self
= client_focus_target(self
);
3387 if (!client_can_focus(self
)) {
3388 if (!self
->frame
->visible
) {
3389 /* update the focus lists */
3390 focus_order_to_top(self
);
3395 ob_debug_type(OB_DEBUG_FOCUS
,
3396 "Focusing client \"%s\" at time %u\n",
3397 self
->title
, event_curtime
);
3399 if (self
->can_focus
) {
3400 /* This can cause a BadMatch error with CurrentTime, or if an app
3401 passed in a bad time for _NET_WM_ACTIVE_WINDOW. */
3402 xerror_set_ignore(TRUE
);
3403 XSetInputFocus(ob_display
, self
->window
, RevertToPointerRoot
,
3405 xerror_set_ignore(FALSE
);
3408 if (self
->focus_notify
) {
3410 ce
.xclient
.type
= ClientMessage
;
3411 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
3412 ce
.xclient
.display
= ob_display
;
3413 ce
.xclient
.window
= self
->window
;
3414 ce
.xclient
.format
= 32;
3415 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_take_focus
;
3416 ce
.xclient
.data
.l
[1] = event_curtime
;
3417 ce
.xclient
.data
.l
[2] = 0l;
3418 ce
.xclient
.data
.l
[3] = 0l;
3419 ce
.xclient
.data
.l
[4] = 0l;
3420 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
3424 ob_debug("%sively focusing %lx at %d\n",
3425 (self
->can_focus
? "act" : "pass"),
3426 self
->window
, (gint
) event_curtime
);
3429 /* Cause the FocusIn to come back to us. Important for desktop switches,
3430 since otherwise we'll have no FocusIn on the queue and send it off to
3431 the focus_backup. */
3432 XSync(ob_display
, FALSE
);
3436 /*! Present the client to the user.
3437 @param raise If the client should be raised or not. You should only set
3438 raise to false if you don't care if the window is completely
3441 static void client_present(ObClient
*self
, gboolean here
, gboolean raise
)
3443 /* if using focus_delay, stop the timer now so that focus doesn't
3445 event_halt_focus_delay();
3447 if (client_normal(self
) && screen_showing_desktop
)
3448 screen_show_desktop(FALSE
, FALSE
);
3450 client_iconify(self
, FALSE
, here
);
3451 if (self
->desktop
!= DESKTOP_ALL
&&
3452 self
->desktop
!= screen_desktop
)
3455 client_set_desktop(self
, screen_desktop
, FALSE
);
3457 screen_set_desktop(self
->desktop
, FALSE
);
3458 } else if (!self
->frame
->visible
)
3459 /* if its not visible for other reasons, then don't mess
3463 client_shade(self
, FALSE
);
3465 stacking_raise(CLIENT_AS_WINDOW(self
));
3470 void client_activate(ObClient
*self
, gboolean here
, gboolean user
)
3472 guint32 last_time
= focus_client
? focus_client
->user_time
: CurrentTime
;
3473 gboolean allow
= FALSE
;
3475 /* if the request came from the user, or if nothing is focused, then grant
3477 if the currently focused app doesn't set a user_time, then it can't
3478 benefit from any focus stealing prevention.
3480 if (user
|| !focus_client
|| !last_time
)
3482 /* otherwise, if they didn't give a time stamp or if it is too old, they
3485 allow
= event_curtime
&& event_time_after(event_curtime
, last_time
);
3487 ob_debug_type(OB_DEBUG_FOCUS
,
3488 "Want to activate window 0x%x with time %u (last time %u), "
3489 "source=%s allowing? %d\n",
3490 self
->window
, event_curtime
, last_time
,
3491 (user
? "user" : "application"), allow
);
3494 if (event_curtime
!= CurrentTime
)
3495 self
->user_time
= event_curtime
;
3497 client_present(self
, here
, TRUE
);
3499 /* don't focus it but tell the user it wants attention */
3500 client_hilite(self
, TRUE
);
3503 static void client_bring_helper_windows_recursive(ObClient
*self
,
3508 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
3509 client_bring_helper_windows_recursive(it
->data
, desktop
);
3511 if (client_helper(self
) &&
3512 self
->desktop
!= desktop
&& self
->desktop
!= DESKTOP_ALL
)
3514 client_set_desktop(self
, desktop
, FALSE
);
3518 void client_bring_helper_windows(ObClient
*self
)
3520 client_bring_helper_windows_recursive(self
, self
->desktop
);
3523 gboolean
client_focused(ObClient
*self
)
3525 return self
== focus_client
;
3528 static ObClientIcon
* client_icon_recursive(ObClient
*self
, gint w
, gint h
)
3531 /* si is the smallest image >= req */
3532 /* li is the largest image < req */
3533 gulong size
, smallest
= 0xffffffff, largest
= 0, si
= 0, li
= 0;
3535 if (!self
->nicons
) {
3536 ObClientIcon
*parent
= NULL
;
3538 if (self
->transient_for
) {
3539 if (self
->transient_for
!= OB_TRAN_GROUP
)
3540 parent
= client_icon_recursive(self
->transient_for
, w
, h
);
3543 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
3544 ObClient
*c
= it
->data
;
3545 if (c
!= self
&& !c
->transient_for
) {
3546 if ((parent
= client_icon_recursive(c
, w
, h
)))
3556 for (i
= 0; i
< self
->nicons
; ++i
) {
3557 size
= self
->icons
[i
].width
* self
->icons
[i
].height
;
3558 if (size
< smallest
&& size
>= (unsigned)(w
* h
)) {
3562 if (size
> largest
&& size
<= (unsigned)(w
* h
)) {
3567 if (largest
== 0) /* didnt find one smaller than the requested size */
3568 return &self
->icons
[si
];
3569 return &self
->icons
[li
];
3572 const ObClientIcon
* client_icon(ObClient
*self
, gint w
, gint h
)
3575 static ObClientIcon deficon
;
3577 if (!(ret
= client_icon_recursive(self
, w
, h
))) {
3578 deficon
.width
= deficon
.height
= 48;
3579 deficon
.data
= ob_rr_theme
->def_win_icon
;
3585 void client_set_layer(ObClient
*self
, gint layer
)
3589 self
->above
= FALSE
;
3590 } else if (layer
== 0) {
3591 self
->below
= self
->above
= FALSE
;
3593 self
->below
= FALSE
;
3596 client_calc_layer(self
);
3597 client_change_state(self
); /* reflect this in the state hints */
3600 void client_set_undecorated(ObClient
*self
, gboolean undecorated
)
3602 if (self
->undecorated
!= undecorated
) {
3603 self
->undecorated
= undecorated
;
3604 client_setup_decor_and_functions(self
);
3605 /* Make sure the client knows it might have moved. Maybe there is a
3606 * better way of doing this so only one client_configure is sent, but
3607 * since 125 of these are sent per second when moving the window (with
3608 * user = FALSE) i doubt it matters much.
3610 client_configure(self
, self
->area
.x
, self
->area
.y
,
3611 self
->area
.width
, self
->area
.height
, TRUE
, TRUE
);
3612 client_change_state(self
); /* reflect this in the state hints */
3616 guint
client_monitor(ObClient
*self
)
3618 return screen_find_monitor(&self
->frame
->area
);
3621 ObClient
*client_search_top_normal_parent(ObClient
*self
)
3623 while (self
->transient_for
&& self
->transient_for
!= OB_TRAN_GROUP
&&
3624 client_normal(self
->transient_for
))
3625 self
= self
->transient_for
;
3629 static GSList
*client_search_all_top_parents_internal(ObClient
*self
,
3631 ObStackingLayer layer
)
3635 /* move up the direct transient chain as far as possible */
3636 while (self
->transient_for
&& self
->transient_for
!= OB_TRAN_GROUP
&&
3637 (!bylayer
|| self
->transient_for
->layer
== layer
) &&
3638 client_normal(self
->transient_for
))
3639 self
= self
->transient_for
;
3641 if (!self
->transient_for
)
3642 ret
= g_slist_prepend(ret
, self
);
3646 g_assert(self
->group
);
3648 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
3649 ObClient
*c
= it
->data
;
3651 if (!c
->transient_for
&& client_normal(c
) &&
3652 (!bylayer
|| c
->layer
== layer
))
3654 ret
= g_slist_prepend(ret
, c
);
3658 if (ret
== NULL
) /* no group parents */
3659 ret
= g_slist_prepend(ret
, self
);
3665 GSList
*client_search_all_top_parents(ObClient
*self
)
3667 return client_search_all_top_parents_internal(self
, FALSE
, 0);
3670 GSList
*client_search_all_top_parents_layer(ObClient
*self
)
3672 return client_search_all_top_parents_internal(self
, TRUE
, self
->layer
);
3675 ObClient
*client_search_focus_parent(ObClient
*self
)
3677 if (self
->transient_for
) {
3678 if (self
->transient_for
!= OB_TRAN_GROUP
) {
3679 if (client_focused(self
->transient_for
))
3680 return self
->transient_for
;
3684 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
3685 ObClient
*c
= it
->data
;
3687 /* checking transient_for prevents infinate loops! */
3688 if (c
!= self
&& !c
->transient_for
)
3689 if (client_focused(c
))
3698 ObClient
*client_search_parent(ObClient
*self
, ObClient
*search
)
3700 if (self
->transient_for
) {
3701 if (self
->transient_for
!= OB_TRAN_GROUP
) {
3702 if (self
->transient_for
== search
)
3707 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
3708 ObClient
*c
= it
->data
;
3710 /* checking transient_for prevents infinate loops! */
3711 if (c
!= self
&& !c
->transient_for
)
3721 ObClient
*client_search_transient(ObClient
*self
, ObClient
*search
)
3725 for (sit
= self
->transients
; sit
; sit
= g_slist_next(sit
)) {
3726 if (sit
->data
== search
)
3728 if (client_search_transient(sit
->data
, search
))
3734 #define WANT_EDGE(cur, c) \
3737 if(!client_normal(cur)) \
3739 if(screen_desktop != cur->desktop && cur->desktop != DESKTOP_ALL) \
3743 if(cur->layer < c->layer && !config_resist_layers_below) \
3746 #define HIT_EDGE(my_edge_start, my_edge_end, his_edge_start, his_edge_end) \
3747 if ((his_edge_start >= my_edge_start && \
3748 his_edge_start <= my_edge_end) || \
3749 (my_edge_start >= his_edge_start && \
3750 my_edge_start <= his_edge_end)) \
3753 /* finds the nearest edge in the given direction from the current client
3754 * note to self: the edge is the -frame- edge (the actual one), not the
3757 gint
client_directional_edge_search(ObClient
*c
, ObDirection dir
, gboolean hang
)
3759 gint dest
, monitor_dest
;
3760 gint my_edge_start
, my_edge_end
, my_offset
;
3767 a
= screen_area(c
->desktop
);
3768 monitor
= screen_area_monitor(c
->desktop
, client_monitor(c
));
3771 case OB_DIRECTION_NORTH
:
3772 my_edge_start
= c
->frame
->area
.x
;
3773 my_edge_end
= c
->frame
->area
.x
+ c
->frame
->area
.width
;
3774 my_offset
= c
->frame
->area
.y
+ (hang
? c
->frame
->area
.height
: 0);
3776 /* default: top of screen */
3777 dest
= a
->y
+ (hang
? c
->frame
->area
.height
: 0);
3778 monitor_dest
= monitor
->y
+ (hang
? c
->frame
->area
.height
: 0);
3779 /* if the monitor edge comes before the screen edge, */
3780 /* use that as the destination instead. (For xinerama) */
3781 if (monitor_dest
!= dest
&& my_offset
> monitor_dest
)
3782 dest
= monitor_dest
;
3784 for(it
= client_list
; it
&& my_offset
!= dest
; it
= g_list_next(it
)) {
3785 gint his_edge_start
, his_edge_end
, his_offset
;
3786 ObClient
*cur
= it
->data
;
3790 his_edge_start
= cur
->frame
->area
.x
;
3791 his_edge_end
= cur
->frame
->area
.x
+ cur
->frame
->area
.width
;
3792 his_offset
= cur
->frame
->area
.y
+
3793 (hang
? 0 : cur
->frame
->area
.height
);
3795 if(his_offset
+ 1 > my_offset
)
3798 if(his_offset
< dest
)
3801 HIT_EDGE(my_edge_start
, my_edge_end
, his_edge_start
, his_edge_end
)
3804 case OB_DIRECTION_SOUTH
:
3805 my_edge_start
= c
->frame
->area
.x
;
3806 my_edge_end
= c
->frame
->area
.x
+ c
->frame
->area
.width
;
3807 my_offset
= c
->frame
->area
.y
+ (hang
? 0 : c
->frame
->area
.height
);
3809 /* default: bottom of screen */
3810 dest
= a
->y
+ a
->height
- (hang
? c
->frame
->area
.height
: 0);
3811 monitor_dest
= monitor
->y
+ monitor
->height
-
3812 (hang
? c
->frame
->area
.height
: 0);
3813 /* if the monitor edge comes before the screen edge, */
3814 /* use that as the destination instead. (For xinerama) */
3815 if (monitor_dest
!= dest
&& my_offset
< monitor_dest
)
3816 dest
= monitor_dest
;
3818 for(it
= client_list
; it
&& my_offset
!= dest
; it
= g_list_next(it
)) {
3819 gint his_edge_start
, his_edge_end
, his_offset
;
3820 ObClient
*cur
= it
->data
;
3824 his_edge_start
= cur
->frame
->area
.x
;
3825 his_edge_end
= cur
->frame
->area
.x
+ cur
->frame
->area
.width
;
3826 his_offset
= cur
->frame
->area
.y
+
3827 (hang
? cur
->frame
->area
.height
: 0);
3830 if(his_offset
- 1 < my_offset
)
3833 if(his_offset
> dest
)
3836 HIT_EDGE(my_edge_start
, my_edge_end
, his_edge_start
, his_edge_end
)
3839 case OB_DIRECTION_WEST
:
3840 my_edge_start
= c
->frame
->area
.y
;
3841 my_edge_end
= c
->frame
->area
.y
+ c
->frame
->area
.height
;
3842 my_offset
= c
->frame
->area
.x
+ (hang
? c
->frame
->area
.width
: 0);
3844 /* default: leftmost egde of screen */
3845 dest
= a
->x
+ (hang
? c
->frame
->area
.width
: 0);
3846 monitor_dest
= monitor
->x
+ (hang
? c
->frame
->area
.width
: 0);
3847 /* if the monitor edge comes before the screen edge, */
3848 /* use that as the destination instead. (For xinerama) */
3849 if (monitor_dest
!= dest
&& my_offset
> monitor_dest
)
3850 dest
= monitor_dest
;
3852 for(it
= client_list
; it
&& my_offset
!= dest
; it
= g_list_next(it
)) {
3853 gint his_edge_start
, his_edge_end
, his_offset
;
3854 ObClient
*cur
= it
->data
;
3858 his_edge_start
= cur
->frame
->area
.y
;
3859 his_edge_end
= cur
->frame
->area
.y
+ cur
->frame
->area
.height
;
3860 his_offset
= cur
->frame
->area
.x
+
3861 (hang
? 0 : cur
->frame
->area
.width
);
3863 if(his_offset
+ 1 > my_offset
)
3866 if(his_offset
< dest
)
3869 HIT_EDGE(my_edge_start
, my_edge_end
, his_edge_start
, his_edge_end
)
3872 case OB_DIRECTION_EAST
:
3873 my_edge_start
= c
->frame
->area
.y
;
3874 my_edge_end
= c
->frame
->area
.y
+ c
->frame
->area
.height
;
3875 my_offset
= c
->frame
->area
.x
+ (hang
? 0 : c
->frame
->area
.width
);
3877 /* default: rightmost edge of screen */
3878 dest
= a
->x
+ a
->width
- (hang
? c
->frame
->area
.width
: 0);
3879 monitor_dest
= monitor
->x
+ monitor
->width
-
3880 (hang
? c
->frame
->area
.width
: 0);
3881 /* if the monitor edge comes before the screen edge, */
3882 /* use that as the destination instead. (For xinerama) */
3883 if (monitor_dest
!= dest
&& my_offset
< monitor_dest
)
3884 dest
= monitor_dest
;
3886 for(it
= client_list
; it
&& my_offset
!= dest
; it
= g_list_next(it
)) {
3887 gint his_edge_start
, his_edge_end
, his_offset
;
3888 ObClient
*cur
= it
->data
;
3892 his_edge_start
= cur
->frame
->area
.y
;
3893 his_edge_end
= cur
->frame
->area
.y
+ cur
->frame
->area
.height
;
3894 his_offset
= cur
->frame
->area
.x
+
3895 (hang
? cur
->frame
->area
.width
: 0);
3897 if(his_offset
- 1 < my_offset
)
3900 if(his_offset
> dest
)
3903 HIT_EDGE(my_edge_start
, my_edge_end
, his_edge_start
, his_edge_end
)
3906 case OB_DIRECTION_NORTHEAST
:
3907 case OB_DIRECTION_SOUTHEAST
:
3908 case OB_DIRECTION_NORTHWEST
:
3909 case OB_DIRECTION_SOUTHWEST
:
3910 /* not implemented */
3912 g_assert_not_reached();
3913 dest
= 0; /* suppress warning */
3918 ObClient
* client_under_pointer()
3922 ObClient
*ret
= NULL
;
3924 if (screen_pointer_pos(&x
, &y
)) {
3925 for (it
= stacking_list
; it
; it
= g_list_next(it
)) {
3926 if (WINDOW_IS_CLIENT(it
->data
)) {
3927 ObClient
*c
= WINDOW_AS_CLIENT(it
->data
);
3928 if (c
->frame
->visible
&&
3929 /* ignore all animating windows */
3930 !frame_iconify_animating(c
->frame
) &&
3931 RECT_CONTAINS(c
->frame
->area
, x
, y
))
3942 gboolean
client_has_group_siblings(ObClient
*self
)
3944 return self
->group
&& self
->group
->members
->next
;