6 #include "moveresize.h"
8 #include "extensions.h"
19 #include "render/render.h"
22 #include <X11/Xutil.h>
24 /*! The event mask to grab on client windows */
25 #define CLIENT_EVENTMASK (PropertyChangeMask | FocusChangeMask | \
28 #define CLIENT_NOPROPAGATEMASK (ButtonPressMask | ButtonReleaseMask | \
31 GList
*client_list
= NULL
;
33 static void client_get_all(ObClient
*self
);
34 static void client_toggle_border(ObClient
*self
, gboolean show
);
35 static void client_get_area(ObClient
*self
);
36 static void client_get_desktop(ObClient
*self
);
37 static void client_get_state(ObClient
*self
);
38 static void client_get_shaped(ObClient
*self
);
39 static void client_get_mwm_hints(ObClient
*self
);
40 static void client_get_gravity(ObClient
*self
);
41 static void client_showhide(ObClient
*self
);
42 static void client_change_allowed_actions(ObClient
*self
);
43 static void client_change_state(ObClient
*self
);
44 static void client_apply_startup_state(ObClient
*self
);
51 void client_shutdown()
55 void client_set_list()
57 Window
*windows
, *win_it
;
59 guint size
= g_list_length(client_list
);
61 /* create an array of the window ids */
63 windows
= g_new(Window
, size
);
65 for (it
= client_list
; it
!= NULL
; it
= it
->next
, ++win_it
)
66 *win_it
= ((ObClient
*)it
->data
)->window
;
70 PROP_SETA32(RootWindow(ob_display
, ob_screen
),
71 net_client_list
, window
, (guint32
*)windows
, size
);
80 void client_foreach_transient(ObClient *self, ObClientForeachFunc func, void *data)
84 for (it = self->transients; it; it = it->next) {
85 if (!func(it->data, data)) return;
86 client_foreach_transient(it->data, func, data);
90 void client_foreach_ancestor(ObClient *self, ObClientForeachFunc func, void *data)
92 if (self->transient_for) {
93 if (self->transient_for != OB_TRAN_GROUP) {
94 if (!func(self->transient_for, data)) return;
95 client_foreach_ancestor(self->transient_for, func, data);
99 for (it = self->group->members; it; it = it->next)
100 if (it->data != self &&
101 !((ObClient*)it->data)->transient_for) {
102 if (!func(it->data, data)) return;
103 client_foreach_ancestor(it->data, func, data);
110 void client_manage_all()
112 unsigned int i
, j
, nchild
;
115 XWindowAttributes attrib
;
117 XQueryTree(ob_display
, RootWindow(ob_display
, ob_screen
),
118 &w
, &w
, &children
, &nchild
);
120 /* remove all icon windows from the list */
121 for (i
= 0; i
< nchild
; i
++) {
122 if (children
[i
] == None
) continue;
123 wmhints
= XGetWMHints(ob_display
, children
[i
]);
125 if ((wmhints
->flags
& IconWindowHint
) &&
126 (wmhints
->icon_window
!= children
[i
]))
127 for (j
= 0; j
< nchild
; j
++)
128 if (children
[j
] == wmhints
->icon_window
) {
136 for (i
= 0; i
< nchild
; ++i
) {
137 if (children
[i
] == None
)
139 if (XGetWindowAttributes(ob_display
, children
[i
], &attrib
)) {
140 if (attrib
.override_redirect
) continue;
142 if (attrib
.map_state
!= IsUnmapped
)
143 client_manage(children
[i
]);
148 /* stack them as they were on startup!
149 why with stacking_lower? Why, because then windows who aren't in the
150 stacking list are on the top where you can see them instead of buried
152 for (i
= startup_stack_size
; i
> 0; --i
) {
155 w
= startup_stack_order
[i
-1];
156 obw
= g_hash_table_lookup(window_map
, &w
);
158 g_assert(WINDOW_IS_CLIENT(obw
));
159 stacking_lower(CLIENT_AS_WINDOW(obw
));
162 g_free(startup_stack_order
);
163 startup_stack_order
= NULL
;
164 startup_stack_size
= 0;
166 if (config_focus_new
) {
169 active
= g_hash_table_lookup(window_map
, &startup_active
);
171 g_assert(WINDOW_IS_CLIENT(active
));
172 if (!client_focus(WINDOW_AS_CLIENT(active
)))
173 focus_fallback(OB_FOCUS_FALLBACK_NOFOCUS
);
175 focus_fallback(OB_FOCUS_FALLBACK_NOFOCUS
);
179 void client_manage(Window window
)
183 XWindowAttributes attrib
;
184 XSetWindowAttributes attrib_set
;
186 gboolean activate
= FALSE
;
190 /* check if it has already been unmapped by the time we started mapping
191 the grab does a sync so we don't have to here */
192 if (XCheckTypedWindowEvent(ob_display
, window
, DestroyNotify
, &e
) ||
193 XCheckTypedWindowEvent(ob_display
, window
, UnmapNotify
, &e
)) {
194 XPutBackEvent(ob_display
, &e
);
197 return; /* don't manage it */
200 /* make sure it isn't an override-redirect window */
201 if (!XGetWindowAttributes(ob_display
, window
, &attrib
) ||
202 attrib
.override_redirect
) {
204 return; /* don't manage it */
207 /* is the window a docking app */
208 if ((wmhint
= XGetWMHints(ob_display
, window
))) {
209 if ((wmhint
->flags
& StateHint
) &&
210 wmhint
->initial_state
== WithdrawnState
) {
211 dock_add(window
, wmhint
);
219 g_message("Managing window: %lx", window
);
221 /* choose the events we want to receive on the CLIENT window */
222 attrib_set
.event_mask
= CLIENT_EVENTMASK
;
223 attrib_set
.do_not_propagate_mask
= CLIENT_NOPROPAGATEMASK
;
224 XChangeWindowAttributes(ob_display
, window
,
225 CWEventMask
|CWDontPropagate
, &attrib_set
);
228 /* create the ObClient struct, and populate it from the hints on the
230 self
= g_new(ObClient
, 1);
231 self
->obwin
.type
= Window_Client
;
232 self
->window
= window
;
233 client_get_all(self
);
235 /* remove the client's border (and adjust re gravity) */
236 client_toggle_border(self
, FALSE
);
238 /* specify that if we exit, the window should not be destroyed and should
239 be reparented back to root automatically */
240 XChangeSaveSet(ob_display
, window
, SetModeInsert
);
242 /* create the decoration frame for the client window */
243 self
->frame
= frame_new();
245 frame_grab_client(self
->frame
, self
);
247 client_apply_startup_state(self
);
251 /* add to client list/map */
252 client_list
= g_list_append(client_list
, self
);
253 g_hash_table_insert(window_map
, &self
->window
, self
);
255 /* update the focus lists */
256 focus_order_add_new(self
);
258 /* focus the new window? */
259 if (ob_state() != OB_STATE_STARTING
&& config_focus_new
&&
260 (self
->type
== OB_CLIENT_TYPE_NORMAL
|| self
->type
== OB_CLIENT_TYPE_DIALOG
)) {
261 gboolean group_foc
= FALSE
;
266 for (it
= self
->group
->members
; it
; it
= it
->next
) {
267 if (client_focused(it
->data
)) {
273 /* note the check against Type_Normal/Dialog, not client_normal(self),
274 which would also include other types. in this case we want more
275 strict rules for focus */
277 (!self
->transient_for
&& (!self
->group
||
278 !self
->group
->members
->next
))) ||
279 client_search_focus_tree_full(self
) ||
281 !client_normal(focus_client
)) {
282 /* activate the window */
283 stacking_add(CLIENT_AS_WINDOW(self
));
286 /* try to not get in the way */
287 stacking_add_nonintrusive(CLIENT_AS_WINDOW(self
));
290 stacking_add(CLIENT_AS_WINDOW(self
));
293 dispatch_client(Event_Client_New
, self
, 0, 0);
295 /* make sure the window is visible */
296 client_move_onscreen(self
);
298 screen_update_areas();
300 client_showhide(self
);
302 if (activate
) client_activate(self
);
304 /* update the list hints */
307 dispatch_client(Event_Client_Mapped
, self
, 0, 0);
309 g_message("Managed window 0x%lx (%s)", window
, self
->class);
312 void client_unmanage_all()
314 while (client_list
!= NULL
)
315 client_unmanage(client_list
->data
);
318 /* called by client_unmanage() to close any menus referencing this client */
319 void client_close_menus(gpointer key
, gpointer value
, gpointer self
)
321 if (((ObMenu
*)value
)->client
== (ObClient
*)self
)
322 menu_hide((ObMenu
*)value
);
325 void client_unmanage(ObClient
*self
)
330 g_message("Unmanaging window: %lx (%s)", self
->window
, self
->class);
332 dispatch_client(Event_Client_Destroy
, self
, 0, 0);
333 g_assert(self
!= NULL
);
335 /* remove the window from our save set */
336 XChangeSaveSet(ob_display
, self
->window
, SetModeDelete
);
338 /* we dont want events no more */
339 XSelectInput(ob_display
, self
->window
, NoEventMask
);
341 frame_hide(self
->frame
);
343 client_list
= g_list_remove(client_list
, self
);
344 stacking_remove(self
);
345 g_hash_table_remove(window_map
, &self
->window
);
347 /* update the focus lists */
348 focus_order_remove(self
);
350 /* once the client is out of the list, update the struts to remove it's
352 screen_update_areas();
354 /* tell our parent(s) that we're gone */
355 if (self
->transient_for
== OB_TRAN_GROUP
) { /* transient of group */
358 for (it
= self
->group
->members
; it
; it
= it
->next
)
359 if (it
->data
!= self
)
360 ((ObClient
*)it
->data
)->transients
=
361 g_slist_remove(((ObClient
*)it
->data
)->transients
, self
);
362 } else if (self
->transient_for
) { /* transient of window */
363 self
->transient_for
->transients
=
364 g_slist_remove(self
->transient_for
->transients
, self
);
367 /* tell our transients that we're gone */
368 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
) {
369 if (((ObClient
*)it
->data
)->transient_for
!= OB_TRAN_GROUP
) {
370 ((ObClient
*)it
->data
)->transient_for
= NULL
;
371 client_calc_layer(it
->data
);
375 if (moveresize_client
== self
)
376 moveresize_end(TRUE
);
378 /* close any windows that are attached to this window */
379 g_hash_table_foreach(menu_hash
, client_close_menus
, self
);
382 if (focus_client
== self
) {
385 /* focus the last focused window on the desktop, and ignore enter
386 events from the unmap so it doesnt mess with the focus */
387 while (XCheckTypedEvent(ob_display
, EnterNotify
, &e
));
388 client_unfocus(self
);
391 /* remove from its group */
393 group_remove(self
->group
, self
);
397 /* dispatch the unmapped event */
398 dispatch_client(Event_Client_Unmapped
, self
, 0, 0);
399 g_assert(self
!= NULL
);
401 /* give the client its border back */
402 client_toggle_border(self
, TRUE
);
404 /* reparent the window out of the frame, and free the frame */
405 frame_release_client(self
->frame
, self
);
408 if (ob_state() != OB_STATE_EXITING
) {
409 /* these values should not be persisted across a window
411 prop_erase(self
->window
, prop_atoms
.net_wm_desktop
);
412 prop_erase(self
->window
, prop_atoms
.net_wm_state
);
414 /* if we're left in an iconic state, the client wont be mapped. this is
415 bad, since we will no longer be managing the window on restart */
417 XMapWindow(ob_display
, self
->window
);
421 g_message("Unmanaged window 0x%lx", self
->window
);
423 /* free all data allocated in the client struct */
424 g_slist_free(self
->transients
);
425 for (j
= 0; j
< self
->nicons
; ++j
)
426 g_free(self
->icons
[j
].data
);
427 if (self
->nicons
> 0)
430 g_free(self
->icon_title
);
436 /* update the list hints */
440 void client_move_onscreen(ObClient
*self
)
443 int x
= self
->frame
->area
.x
, y
= self
->frame
->area
.y
;
445 /* XXX watch for xinerama dead areas */
446 a
= screen_area(self
->desktop
);
447 if (x
>= a
->x
+ a
->width
- 1)
448 x
= a
->x
+ a
->width
- self
->frame
->area
.width
;
449 if (y
>= a
->y
+ a
->height
- 1)
450 y
= a
->y
+ a
->height
- self
->frame
->area
.height
;
451 if (x
+ self
->frame
->area
.width
- 1 < a
->x
)
453 if (y
+ self
->frame
->area
.height
- 1< a
->y
)
456 frame_frame_gravity(self
->frame
, &x
, &y
); /* get where the client
458 client_configure(self
, OB_CORNER_TOPLEFT
, x
, y
,
459 self
->area
.width
, self
->area
.height
,
463 static void client_toggle_border(ObClient
*self
, gboolean show
)
465 /* adjust our idea of where the client is, based on its border. When the
466 border is removed, the client should now be considered to be in a
468 when re-adding the border to the client, the same operation needs to be
470 int oldx
= self
->area
.x
, oldy
= self
->area
.y
;
471 int x
= oldx
, y
= oldy
;
472 switch(self
->gravity
) {
474 case NorthWestGravity
:
476 case SouthWestGravity
:
478 case NorthEastGravity
:
480 case SouthEastGravity
:
481 if (show
) x
-= self
->border_width
* 2;
482 else x
+= self
->border_width
* 2;
489 if (show
) x
-= self
->border_width
;
490 else x
+= self
->border_width
;
493 switch(self
->gravity
) {
495 case NorthWestGravity
:
497 case NorthEastGravity
:
499 case SouthWestGravity
:
501 case SouthEastGravity
:
502 if (show
) y
-= self
->border_width
* 2;
503 else y
+= self
->border_width
* 2;
510 if (show
) y
-= self
->border_width
;
511 else y
+= self
->border_width
;
518 XSetWindowBorderWidth(ob_display
, self
->window
, self
->border_width
);
520 /* move the client so it is back it the right spot _with_ its
522 if (x
!= oldx
|| y
!= oldy
)
523 XMoveWindow(ob_display
, self
->window
, x
, y
);
525 XSetWindowBorderWidth(ob_display
, self
->window
, 0);
529 static void client_get_all(ObClient
*self
)
531 /* update EVERYTHING!! */
533 self
->ignore_unmaps
= 0;
537 self
->title
= self
->icon_title
= NULL
;
538 self
->title_count
= 1;
539 self
->name
= self
->class = self
->role
= NULL
;
540 self
->wmstate
= NormalState
;
541 self
->transient
= FALSE
;
542 self
->transients
= NULL
;
543 self
->transient_for
= NULL
;
545 self
->urgent
= FALSE
;
546 self
->positioned
= FALSE
;
547 self
->decorate
= TRUE
;
551 client_get_area(self
);
552 client_update_transient_for(self
);
553 client_update_wmhints(self
);
554 client_get_desktop(self
);
555 client_get_state(self
);
556 client_get_shaped(self
);
558 client_get_mwm_hints(self
);
559 client_get_type(self
);/* this can change the mwmhints for special cases */
561 client_update_protocols(self
);
563 client_get_gravity(self
); /* get the attribute gravity */
564 client_update_normal_hints(self
); /* this may override the attribute
567 /* got the type, the mwmhints, the protocols, and the normal hints
568 (min/max sizes), so we're ready to set up the decorations/functions */
569 client_setup_decor_and_functions(self
);
571 client_update_title(self
);
572 client_update_class(self
);
573 client_update_strut(self
);
574 client_update_icons(self
);
576 client_change_state(self
);
579 static void client_get_area(ObClient
*self
)
581 XWindowAttributes wattrib
;
584 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
585 g_assert(ret
!= BadWindow
);
587 RECT_SET(self
->area
, wattrib
.x
, wattrib
.y
, wattrib
.width
, wattrib
.height
);
588 self
->border_width
= wattrib
.border_width
;
591 static void client_get_desktop(ObClient
*self
)
593 guint32 d
= screen_num_desktops
; /* an always-invalid value */
595 if (PROP_GET32(self
->window
, net_wm_desktop
, cardinal
, &d
)) {
596 if (d
>= screen_num_desktops
&& d
!= DESKTOP_ALL
)
597 self
->desktop
= screen_num_desktops
- 1;
601 gboolean trdesk
= FALSE
;
603 if (self
->transient_for
) {
604 if (self
->transient_for
!= OB_TRAN_GROUP
) {
605 self
->desktop
= self
->transient_for
->desktop
;
610 for (it
= self
->group
->members
; it
; it
= it
->next
)
611 if (it
->data
!= self
&&
612 !((ObClient
*)it
->data
)->transient_for
) {
613 self
->desktop
= ((ObClient
*)it
->data
)->desktop
;
620 /* defaults to the current desktop */
621 self
->desktop
= screen_desktop
;
624 if (self
->desktop
!= d
) {
625 /* set the desktop hint, to make sure that it always exists */
626 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, self
->desktop
);
630 static void client_get_state(ObClient
*self
)
635 self
->modal
= self
->shaded
= self
->max_horz
= self
->max_vert
=
636 self
->fullscreen
= self
->above
= self
->below
= self
->iconic
=
637 self
->skip_taskbar
= self
->skip_pager
= FALSE
;
639 if (PROP_GETA32(self
->window
, net_wm_state
, atom
, &state
, &num
)) {
641 for (i
= 0; i
< num
; ++i
) {
642 if (state
[i
] == prop_atoms
.net_wm_state_modal
)
644 else if (state
[i
] == prop_atoms
.net_wm_state_shaded
)
646 else if (state
[i
] == prop_atoms
.net_wm_state_hidden
)
648 else if (state
[i
] == prop_atoms
.net_wm_state_skip_taskbar
)
649 self
->skip_taskbar
= TRUE
;
650 else if (state
[i
] == prop_atoms
.net_wm_state_skip_pager
)
651 self
->skip_pager
= TRUE
;
652 else if (state
[i
] == prop_atoms
.net_wm_state_fullscreen
)
653 self
->fullscreen
= TRUE
;
654 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_vert
)
655 self
->max_vert
= TRUE
;
656 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_horz
)
657 self
->max_horz
= TRUE
;
658 else if (state
[i
] == prop_atoms
.net_wm_state_above
)
660 else if (state
[i
] == prop_atoms
.net_wm_state_below
)
668 static void client_get_shaped(ObClient
*self
)
670 self
->shaped
= FALSE
;
672 if (extensions_shape
) {
677 XShapeSelectInput(ob_display
, self
->window
, ShapeNotifyMask
);
679 XShapeQueryExtents(ob_display
, self
->window
, &s
, &foo
,
680 &foo
, &ufoo
, &ufoo
, &foo
, &foo
, &foo
, &ufoo
,
682 self
->shaped
= (s
!= 0);
687 void client_update_transient_for(ObClient
*self
)
692 if (XGetTransientForHint(ob_display
, self
->window
, &t
)) {
693 self
->transient
= TRUE
;
694 if (t
!= self
->window
) { /* cant be transient to itself! */
695 c
= g_hash_table_lookup(window_map
, &t
);
696 /* if this happens then we need to check for it*/
698 g_assert(!c
|| WINDOW_IS_CLIENT(c
));
700 if (!c
&& self
->group
) {
701 /* not transient to a client, see if it is transient for a
703 if (t
== self
->group
->leader
||
705 t
== RootWindow(ob_display
, ob_screen
)) {
706 /* window is a transient for its group! */
712 self
->transient
= FALSE
;
714 /* if anything has changed... */
715 if (c
!= self
->transient_for
) {
716 if (self
->transient_for
== OB_TRAN_GROUP
) { /* transient of group */
719 /* remove from old parents */
720 for (it
= self
->group
->members
; it
; it
= it
->next
)
721 if (it
->data
!= self
&&
722 !((ObClient
*)it
->data
)->transient_for
)
723 ((ObClient
*)it
->data
)->transients
=
724 g_slist_remove(((ObClient
*)it
->data
)->transients
, self
);
725 } else if (self
->transient_for
!= NULL
) { /* transient of window */
726 /* remove from old parent */
727 self
->transient_for
->transients
=
728 g_slist_remove(self
->transient_for
->transients
, self
);
730 self
->transient_for
= c
;
731 if (self
->transient_for
== OB_TRAN_GROUP
) { /* transient of group */
734 /* add to new parents */
735 for (it
= self
->group
->members
; it
; it
= it
->next
)
736 if (it
->data
!= self
&&
737 !((ObClient
*)it
->data
)->transient_for
)
738 ((ObClient
*)it
->data
)->transients
=
739 g_slist_append(((ObClient
*)it
->data
)->transients
, self
);
741 /* remove all transients which are in the group, that causes
742 circlular pointer hell of doom */
743 for (it
= self
->group
->members
; it
; it
= it
->next
) {
745 for (sit
= self
->transients
; sit
; sit
= next
) {
747 if (sit
->data
== it
->data
)
748 self
->transients
= g_slist_remove(self
->transients
,
752 } else if (self
->transient_for
!= NULL
) { /* transient of window */
753 /* add to new parent */
754 self
->transient_for
->transients
=
755 g_slist_append(self
->transient_for
->transients
, self
);
760 static void client_get_mwm_hints(ObClient
*self
)
765 self
->mwmhints
.flags
= 0; /* default to none */
767 if (PROP_GETA32(self
->window
, motif_wm_hints
, motif_wm_hints
,
769 if (num
>= OB_MWM_ELEMENTS
) {
770 self
->mwmhints
.flags
= hints
[0];
771 self
->mwmhints
.functions
= hints
[1];
772 self
->mwmhints
.decorations
= hints
[2];
778 void client_get_type(ObClient
*self
)
785 if (PROP_GETA32(self
->window
, net_wm_window_type
, atom
, &val
, &num
)) {
786 /* use the first value that we know about in the array */
787 for (i
= 0; i
< num
; ++i
) {
788 if (val
[i
] == prop_atoms
.net_wm_window_type_desktop
)
789 self
->type
= OB_CLIENT_TYPE_DESKTOP
;
790 else if (val
[i
] == prop_atoms
.net_wm_window_type_dock
)
791 self
->type
= OB_CLIENT_TYPE_DOCK
;
792 else if (val
[i
] == prop_atoms
.net_wm_window_type_toolbar
)
793 self
->type
= OB_CLIENT_TYPE_TOOLBAR
;
794 else if (val
[i
] == prop_atoms
.net_wm_window_type_menu
)
795 self
->type
= OB_CLIENT_TYPE_MENU
;
796 else if (val
[i
] == prop_atoms
.net_wm_window_type_utility
)
797 self
->type
= OB_CLIENT_TYPE_UTILITY
;
798 else if (val
[i
] == prop_atoms
.net_wm_window_type_splash
)
799 self
->type
= OB_CLIENT_TYPE_SPLASH
;
800 else if (val
[i
] == prop_atoms
.net_wm_window_type_dialog
)
801 self
->type
= OB_CLIENT_TYPE_DIALOG
;
802 else if (val
[i
] == prop_atoms
.net_wm_window_type_normal
)
803 self
->type
= OB_CLIENT_TYPE_NORMAL
;
804 else if (val
[i
] == prop_atoms
.kde_net_wm_window_type_override
) {
805 /* prevent this window from getting any decor or
807 self
->mwmhints
.flags
&= (OB_MWM_FLAG_FUNCTIONS
|
808 OB_MWM_FLAG_DECORATIONS
);
809 self
->mwmhints
.decorations
= 0;
810 self
->mwmhints
.functions
= 0;
812 if (self
->type
!= (ObClientType
) -1)
813 break; /* grab the first legit type */
818 if (self
->type
== (ObClientType
) -1) {
819 /*the window type hint was not set, which means we either classify
820 ourself as a normal window or a dialog, depending on if we are a
823 self
->type
= OB_CLIENT_TYPE_DIALOG
;
825 self
->type
= OB_CLIENT_TYPE_NORMAL
;
829 void client_update_protocols(ObClient
*self
)
834 self
->focus_notify
= FALSE
;
835 self
->delete_window
= FALSE
;
837 if (PROP_GETA32(self
->window
, wm_protocols
, atom
, &proto
, &num_return
)) {
838 for (i
= 0; i
< num_return
; ++i
) {
839 if (proto
[i
] == prop_atoms
.wm_delete_window
) {
840 /* this means we can request the window to close */
841 self
->delete_window
= TRUE
;
842 } else if (proto
[i
] == prop_atoms
.wm_take_focus
)
843 /* if this protocol is requested, then the window will be
844 notified whenever we want it to receive focus */
845 self
->focus_notify
= TRUE
;
851 static void client_get_gravity(ObClient
*self
)
853 XWindowAttributes wattrib
;
856 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
857 g_assert(ret
!= BadWindow
);
858 self
->gravity
= wattrib
.win_gravity
;
861 void client_update_normal_hints(ObClient
*self
)
865 int oldgravity
= self
->gravity
;
868 self
->min_ratio
= 0.0f
;
869 self
->max_ratio
= 0.0f
;
870 SIZE_SET(self
->size_inc
, 1, 1);
871 SIZE_SET(self
->base_size
, 0, 0);
872 SIZE_SET(self
->min_size
, 0, 0);
873 SIZE_SET(self
->max_size
, G_MAXINT
, G_MAXINT
);
875 /* get the hints from the window */
876 if (XGetWMNormalHints(ob_display
, self
->window
, &size
, &ret
)) {
877 self
->positioned
= !!(size
.flags
& (PPosition
|USPosition
));
879 if (size
.flags
& PWinGravity
) {
880 self
->gravity
= size
.win_gravity
;
882 /* if the client has a frame, i.e. has already been mapped and
883 is changing its gravity */
884 if (self
->frame
&& self
->gravity
!= oldgravity
) {
885 /* move our idea of the client's position based on its new
887 self
->area
.x
= self
->frame
->area
.x
;
888 self
->area
.y
= self
->frame
->area
.y
;
889 frame_frame_gravity(self
->frame
, &self
->area
.x
, &self
->area
.y
);
893 if (size
.flags
& PAspect
) {
894 if (size
.min_aspect
.y
)
895 self
->min_ratio
= (float)size
.min_aspect
.x
/ size
.min_aspect
.y
;
896 if (size
.max_aspect
.y
)
897 self
->max_ratio
= (float)size
.max_aspect
.x
/ size
.max_aspect
.y
;
900 if (size
.flags
& PMinSize
)
901 SIZE_SET(self
->min_size
, size
.min_width
, size
.min_height
);
903 if (size
.flags
& PMaxSize
)
904 SIZE_SET(self
->max_size
, size
.max_width
, size
.max_height
);
906 if (size
.flags
& PBaseSize
)
907 SIZE_SET(self
->base_size
, size
.base_width
, size
.base_height
);
909 if (size
.flags
& PResizeInc
)
910 SIZE_SET(self
->size_inc
, size
.width_inc
, size
.height_inc
);
914 void client_setup_decor_and_functions(ObClient
*self
)
916 /* start with everything (cept fullscreen) */
917 self
->decorations
= (OB_FRAME_DECOR_TITLEBAR
|
918 OB_FRAME_DECOR_HANDLE
|
919 OB_FRAME_DECOR_GRIPS
|
920 OB_FRAME_DECOR_BORDER
|
921 OB_FRAME_DECOR_ICON
|
922 OB_FRAME_DECOR_ALLDESKTOPS
|
923 OB_FRAME_DECOR_ICONIFY
|
924 OB_FRAME_DECOR_MAXIMIZE
|
925 OB_FRAME_DECOR_SHADE
);
926 self
->functions
= (OB_CLIENT_FUNC_RESIZE
|
927 OB_CLIENT_FUNC_MOVE
|
928 OB_CLIENT_FUNC_ICONIFY
|
929 OB_CLIENT_FUNC_MAXIMIZE
|
930 OB_CLIENT_FUNC_SHADE
);
931 if (self
->delete_window
) {
932 self
->functions
|= OB_CLIENT_FUNC_CLOSE
;
933 self
->decorations
|= OB_FRAME_DECOR_CLOSE
;
936 if (!(self
->min_size
.width
< self
->max_size
.width
||
937 self
->min_size
.height
< self
->max_size
.height
))
938 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
940 switch (self
->type
) {
941 case OB_CLIENT_TYPE_NORMAL
:
942 /* normal windows retain all of the possible decorations and
943 functionality, and are the only windows that you can fullscreen */
944 self
->functions
|= OB_CLIENT_FUNC_FULLSCREEN
;
947 case OB_CLIENT_TYPE_DIALOG
:
948 case OB_CLIENT_TYPE_UTILITY
:
949 /* these windows cannot be maximized */
950 self
->functions
&= ~OB_CLIENT_FUNC_MAXIMIZE
;
953 case OB_CLIENT_TYPE_MENU
:
954 case OB_CLIENT_TYPE_TOOLBAR
:
955 /* these windows get less functionality */
956 self
->functions
&= ~(OB_CLIENT_FUNC_ICONIFY
| OB_CLIENT_FUNC_RESIZE
);
959 case OB_CLIENT_TYPE_DESKTOP
:
960 case OB_CLIENT_TYPE_DOCK
:
961 case OB_CLIENT_TYPE_SPLASH
:
962 /* none of these windows are manipulated by the window manager */
963 self
->decorations
= 0;
968 /* Mwm Hints are applied subtractively to what has already been chosen for
969 decor and functionality */
970 if (self
->mwmhints
.flags
& OB_MWM_FLAG_DECORATIONS
) {
971 if (! (self
->mwmhints
.decorations
& OB_MWM_DECOR_ALL
)) {
972 if (! ((self
->mwmhints
.decorations
& OB_MWM_DECOR_HANDLE
) ||
973 (self
->mwmhints
.decorations
& OB_MWM_DECOR_TITLE
)))
974 /* if the mwm hints request no handle or title, then all
975 decorations are disabled */
976 self
->decorations
= 0;
980 if (self
->mwmhints
.flags
& OB_MWM_FLAG_FUNCTIONS
) {
981 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_ALL
)) {
982 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_RESIZE
))
983 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
984 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_MOVE
))
985 self
->functions
&= ~OB_CLIENT_FUNC_MOVE
;
986 /* dont let mwm hints kill any buttons
987 if (! (self->mwmhints.functions & OB_MWM_FUNC_ICONIFY))
988 self->functions &= ~OB_CLIENT_FUNC_ICONIFY;
989 if (! (self->mwmhints.functions & OB_MWM_FUNC_MAXIMIZE))
990 self->functions &= ~OB_CLIENT_FUNC_MAXIMIZE;
992 /* dont let mwm hints kill the close button
993 if (! (self->mwmhints.functions & MwmFunc_Close))
994 self->functions &= ~OB_CLIENT_FUNC_CLOSE; */
998 if (!(self
->functions
& OB_CLIENT_FUNC_SHADE
))
999 self
->decorations
&= ~OB_FRAME_DECOR_SHADE
;
1000 if (!(self
->functions
& OB_CLIENT_FUNC_ICONIFY
))
1001 self
->decorations
&= ~OB_FRAME_DECOR_ICONIFY
;
1002 if (!(self
->functions
& OB_CLIENT_FUNC_RESIZE
))
1003 self
->decorations
&= ~OB_FRAME_DECOR_GRIPS
;
1005 /* can't maximize without moving/resizing */
1006 if (!((self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) &&
1007 (self
->functions
& OB_CLIENT_FUNC_MOVE
) &&
1008 (self
->functions
& OB_CLIENT_FUNC_RESIZE
))) {
1009 self
->functions
&= ~OB_CLIENT_FUNC_MAXIMIZE
;
1010 self
->decorations
&= ~OB_FRAME_DECOR_MAXIMIZE
;
1013 /* finally, the user can have requested no decorations, which overrides
1015 if (!self
->decorate
)
1016 self
->decorations
= 0;
1018 /* if we don't have a titlebar, then we cannot shade! */
1019 if (!(self
->decorations
& OB_FRAME_DECOR_TITLEBAR
))
1020 self
->functions
&= ~OB_CLIENT_FUNC_SHADE
;
1022 /* now we need to check against rules for the client's current state */
1023 if (self
->fullscreen
) {
1024 self
->functions
&= (OB_CLIENT_FUNC_CLOSE
|
1025 OB_CLIENT_FUNC_FULLSCREEN
|
1026 OB_CLIENT_FUNC_ICONIFY
);
1027 self
->decorations
= 0;
1030 client_change_allowed_actions(self
);
1033 /* this makes sure that these windows appear on all desktops */
1034 if (self
->type
== OB_CLIENT_TYPE_DESKTOP
&&
1035 self
->desktop
!= DESKTOP_ALL
)
1036 client_set_desktop(self
, DESKTOP_ALL
, FALSE
);
1038 /* adjust the client's decorations, etc. */
1039 client_reconfigure(self
);
1041 /* this makes sure that these windows appear on all desktops */
1042 if (self
->type
== OB_CLIENT_TYPE_DESKTOP
&&
1043 self
->desktop
!= DESKTOP_ALL
)
1045 self
->desktop
= DESKTOP_ALL
;
1050 static void client_change_allowed_actions(ObClient
*self
)
1055 /* desktop windows are kept on all desktops */
1056 if (self
->type
!= OB_CLIENT_TYPE_DESKTOP
)
1057 actions
[num
++] = prop_atoms
.net_wm_action_change_desktop
;
1059 if (self
->functions
& OB_CLIENT_FUNC_SHADE
)
1060 actions
[num
++] = prop_atoms
.net_wm_action_shade
;
1061 if (self
->functions
& OB_CLIENT_FUNC_CLOSE
)
1062 actions
[num
++] = prop_atoms
.net_wm_action_close
;
1063 if (self
->functions
& OB_CLIENT_FUNC_MOVE
)
1064 actions
[num
++] = prop_atoms
.net_wm_action_move
;
1065 if (self
->functions
& OB_CLIENT_FUNC_ICONIFY
)
1066 actions
[num
++] = prop_atoms
.net_wm_action_minimize
;
1067 if (self
->functions
& OB_CLIENT_FUNC_RESIZE
)
1068 actions
[num
++] = prop_atoms
.net_wm_action_resize
;
1069 if (self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
)
1070 actions
[num
++] = prop_atoms
.net_wm_action_fullscreen
;
1071 if (self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) {
1072 actions
[num
++] = prop_atoms
.net_wm_action_maximize_horz
;
1073 actions
[num
++] = prop_atoms
.net_wm_action_maximize_vert
;
1076 PROP_SETA32(self
->window
, net_wm_allowed_actions
, atom
, actions
, num
);
1078 /* make sure the window isn't breaking any rules now */
1080 if (!(self
->functions
& OB_CLIENT_FUNC_SHADE
) && self
->shaded
) {
1081 if (self
->frame
) client_shade(self
, FALSE
);
1082 else self
->shaded
= FALSE
;
1084 if (!(self
->functions
& OB_CLIENT_FUNC_ICONIFY
) && self
->iconic
) {
1085 g_message("UNSETTING ICONIC");
1086 if (self
->frame
) client_iconify(self
, FALSE
, TRUE
);
1087 else self
->iconic
= FALSE
;
1089 if (!(self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
) && self
->fullscreen
) {
1090 if (self
->frame
) client_fullscreen(self
, FALSE
, TRUE
);
1091 else self
->fullscreen
= FALSE
;
1093 if (!(self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) && (self
->max_horz
||
1095 if (self
->frame
) client_maximize(self
, FALSE
, 0, TRUE
);
1096 else self
->max_vert
= self
->max_horz
= FALSE
;
1100 void client_reconfigure(ObClient
*self
)
1102 /* by making this pass FALSE for user, we avoid the emacs event storm where
1103 every configurenotify causes an update in its normal hints, i think this
1104 is generally what we want anyways... */
1105 client_configure(self
, OB_CORNER_TOPLEFT
, self
->area
.x
, self
->area
.y
,
1106 self
->area
.width
, self
->area
.height
, FALSE
, TRUE
);
1109 void client_update_wmhints(ObClient
*self
)
1112 gboolean ur
= FALSE
;
1115 /* assume a window takes input if it doesnt specify */
1116 self
->can_focus
= TRUE
;
1118 if ((hints
= XGetWMHints(ob_display
, self
->window
)) != NULL
) {
1119 if (hints
->flags
& InputHint
)
1120 self
->can_focus
= hints
->input
;
1122 /* only do this when first managing the window *AND* when we aren't
1124 if (ob_state() != OB_STATE_STARTING
&& self
->frame
== NULL
)
1125 if (hints
->flags
& StateHint
)
1126 self
->iconic
= hints
->initial_state
== IconicState
;
1128 if (hints
->flags
& XUrgencyHint
)
1131 if (!(hints
->flags
& WindowGroupHint
))
1132 hints
->window_group
= None
;
1134 /* did the group state change? */
1135 if (hints
->window_group
!=
1136 (self
->group
? self
->group
->leader
: None
)) {
1137 /* remove from the old group if there was one */
1138 if (self
->group
!= NULL
) {
1139 /* remove transients of the group */
1140 for (it
= self
->group
->members
; it
; it
= it
->next
)
1141 self
->transients
= g_slist_remove(self
->transients
,
1143 group_remove(self
->group
, self
);
1146 if (hints
->window_group
!= None
) {
1147 self
->group
= group_add(hints
->window_group
, self
);
1149 /* i can only have transients from the group if i am not
1151 if (!self
->transient_for
) {
1152 /* add other transients of the group that are already
1154 for (it
= self
->group
->members
; it
; it
= it
->next
)
1155 if (it
->data
!= self
&&
1156 ((ObClient
*)it
->data
)->transient_for
== OB_TRAN_GROUP
)
1157 self
->transients
= g_slist_append(self
->transients
,
1162 /* the WM_HINTS can contain an icon */
1163 client_update_icons(self
);
1165 /* because the self->transient flag wont change from this call,
1166 we don't need to update the window's type and such, only its
1167 transient_for, and the transients lists of other windows in
1168 the group may be affected */
1169 client_update_transient_for(self
);
1175 if (ur
!= self
->urgent
) {
1177 g_message("Urgent Hint for 0x%lx: %s", self
->window
,
1179 /* fire the urgent callback if we're mapped, otherwise, wait until
1180 after we're mapped */
1182 dispatch_client(Event_Client_Urgent
, self
, self
->urgent
, 0);
1186 void client_update_title(ObClient
*self
)
1192 gboolean read_title
;
1194 g_free(self
->title
);
1197 if (!PROP_GETS(self
->window
, net_wm_name
, utf8
, &data
))
1198 /* try old x stuff */
1199 if (!PROP_GETS(self
->window
, wm_name
, locale
, &data
))
1200 data
= g_strdup("Unnamed Window");
1202 /* look for duplicates and append a number */
1204 for (it
= client_list
; it
; it
= it
->next
)
1205 if (it
->data
!= self
) {
1206 ObClient
*c
= it
->data
;
1207 if (0 == strncmp(c
->title
, data
, strlen(data
)))
1208 nums
|= 1 << c
->title_count
;
1210 /* find first free number */
1211 for (i
= 1; i
<= 32; ++i
)
1212 if (!(nums
& (1 << i
))) {
1213 if (self
->title_count
== 1 || i
== 1)
1214 self
->title_count
= i
;
1217 /* dont display the number for the first window */
1218 if (self
->title_count
> 1) {
1219 char *vdata
, *ndata
;
1220 ndata
= g_strdup_printf(" - [%u]", self
->title_count
);
1221 vdata
= g_strconcat(data
, ndata
, NULL
);
1227 PROP_SETS(self
->window
, net_wm_visible_name
, data
);
1232 frame_adjust_title(self
->frame
);
1234 /* update the icon title */
1236 g_free(self
->icon_title
);
1240 if (!PROP_GETS(self
->window
, net_wm_icon_name
, utf8
, &data
))
1241 /* try old x stuff */
1242 if (!PROP_GETS(self
->window
, wm_icon_name
, locale
, &data
)) {
1243 data
= g_strdup(self
->title
);
1247 /* append the title count, dont display the number for the first window */
1248 if (read_title
&& self
->title_count
> 1) {
1249 char *vdata
, *ndata
;
1250 ndata
= g_strdup_printf(" - [%u]", self
->title_count
);
1251 vdata
= g_strconcat(data
, ndata
, NULL
);
1257 PROP_SETS(self
->window
, net_wm_visible_icon_name
, data
);
1259 self
->icon_title
= data
;
1262 void client_update_class(ObClient
*self
)
1267 if (self
->name
) g_free(self
->name
);
1268 if (self
->class) g_free(self
->class);
1269 if (self
->role
) g_free(self
->role
);
1271 self
->name
= self
->class = self
->role
= NULL
;
1273 if (PROP_GETSS(self
->window
, wm_class
, locale
, &data
)) {
1275 self
->name
= g_strdup(data
[0]);
1277 self
->class = g_strdup(data
[1]);
1282 if (PROP_GETS(self
->window
, wm_window_role
, locale
, &s
))
1283 self
->role
= g_strdup(s
);
1285 if (self
->name
== NULL
) self
->name
= g_strdup("");
1286 if (self
->class == NULL
) self
->class = g_strdup("");
1287 if (self
->role
== NULL
) self
->role
= g_strdup("");
1290 void client_update_strut(ObClient
*self
)
1295 if (!PROP_GETA32(self
->window
, net_wm_strut
, cardinal
, &data
, &num
)) {
1296 STRUT_SET(self
->strut
, 0, 0, 0, 0);
1299 STRUT_SET(self
->strut
, data
[0], data
[2], data
[1], data
[3]);
1301 STRUT_SET(self
->strut
, 0, 0, 0, 0);
1305 /* updating here is pointless while we're being mapped cuz we're not in
1306 the client list yet */
1308 screen_update_areas();
1311 void client_update_icons(ObClient
*self
)
1317 for (i
= 0; i
< self
->nicons
; ++i
)
1318 g_free(self
->icons
[i
].data
);
1319 if (self
->nicons
> 0)
1320 g_free(self
->icons
);
1323 if (PROP_GETA32(self
->window
, net_wm_icon
, cardinal
, &data
, &num
)) {
1324 /* figure out how many valid icons are in here */
1326 while (num
- i
> 2) {
1330 if (i
> num
|| w
*h
== 0) break;
1334 self
->icons
= g_new(ObClientIcon
, self
->nicons
);
1336 /* store the icons */
1338 for (j
= 0; j
< self
->nicons
; ++j
) {
1341 w
= self
->icons
[j
].width
= data
[i
++];
1342 h
= self
->icons
[j
].height
= data
[i
++];
1344 if (w
*h
== 0) continue;
1346 self
->icons
[j
].data
= g_new(RrPixel32
, w
* h
);
1347 for (x
= 0, y
= 0, t
= 0; t
< w
* h
; ++t
, ++x
, ++i
) {
1352 self
->icons
[j
].data
[t
] =
1353 (((data
[i
] >> 24) & 0xff) << RrDefaultAlphaOffset
) +
1354 (((data
[i
] >> 16) & 0xff) << RrDefaultRedOffset
) +
1355 (((data
[i
] >> 8) & 0xff) << RrDefaultGreenOffset
) +
1356 (((data
[i
] >> 0) & 0xff) << RrDefaultBlueOffset
);
1362 } else if (PROP_GETA32(self
->window
, kwm_win_icon
,
1363 kwm_win_icon
, &data
, &num
)) {
1366 self
->icons
= g_new(ObClientIcon
, self
->nicons
);
1367 xerror_set_ignore(TRUE
);
1368 if (!RrPixmapToRGBA(ob_rr_inst
,
1370 &self
->icons
[self
->nicons
-1].width
,
1371 &self
->icons
[self
->nicons
-1].height
,
1372 &self
->icons
[self
->nicons
-1].data
)) {
1373 g_free(&self
->icons
[self
->nicons
-1]);
1376 xerror_set_ignore(FALSE
);
1382 if ((hints
= XGetWMHints(ob_display
, self
->window
))) {
1383 if (hints
->flags
& IconPixmapHint
) {
1385 self
->icons
= g_new(ObClientIcon
, self
->nicons
);
1386 xerror_set_ignore(TRUE
);
1387 if (!RrPixmapToRGBA(ob_rr_inst
,
1389 (hints
->flags
& IconMaskHint
?
1390 hints
->icon_mask
: None
),
1391 &self
->icons
[self
->nicons
-1].width
,
1392 &self
->icons
[self
->nicons
-1].height
,
1393 &self
->icons
[self
->nicons
-1].data
)){
1394 g_free(&self
->icons
[self
->nicons
-1]);
1397 xerror_set_ignore(FALSE
);
1404 frame_adjust_icon(self
->frame
);
1407 static void client_change_state(ObClient
*self
)
1410 guint32 netstate
[10];
1413 state
[0] = self
->wmstate
;
1415 PROP_SETA32(self
->window
, wm_state
, wm_state
, state
, 2);
1419 netstate
[num
++] = prop_atoms
.net_wm_state_modal
;
1421 netstate
[num
++] = prop_atoms
.net_wm_state_shaded
;
1423 netstate
[num
++] = prop_atoms
.net_wm_state_hidden
;
1424 if (self
->skip_taskbar
)
1425 netstate
[num
++] = prop_atoms
.net_wm_state_skip_taskbar
;
1426 if (self
->skip_pager
)
1427 netstate
[num
++] = prop_atoms
.net_wm_state_skip_pager
;
1428 if (self
->fullscreen
)
1429 netstate
[num
++] = prop_atoms
.net_wm_state_fullscreen
;
1431 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_vert
;
1433 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_horz
;
1435 netstate
[num
++] = prop_atoms
.net_wm_state_above
;
1437 netstate
[num
++] = prop_atoms
.net_wm_state_below
;
1438 PROP_SETA32(self
->window
, net_wm_state
, atom
, netstate
, num
);
1440 client_calc_layer(self
);
1443 frame_adjust_state(self
->frame
);
1446 ObClient
*client_search_focus_tree(ObClient
*self
)
1451 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
) {
1452 if (client_focused(it
->data
)) return it
->data
;
1453 if ((ret
= client_search_focus_tree(it
->data
))) return ret
;
1458 ObClient
*client_search_focus_tree_full(ObClient
*self
)
1460 if (self
->transient_for
) {
1461 if (self
->transient_for
!= OB_TRAN_GROUP
) {
1462 return client_search_focus_tree_full(self
->transient_for
);
1465 gboolean recursed
= FALSE
;
1467 for (it
= self
->group
->members
; it
; it
= it
->next
)
1468 if (!((ObClient
*)it
->data
)->transient_for
) {
1470 if ((c
= client_search_focus_tree_full(it
->data
)))
1479 /* this function checks the whole tree, the client_search_focus_tree~
1480 does not, so we need to check this window */
1481 if (client_focused(self
))
1483 return client_search_focus_tree(self
);
1486 static ObStackingLayer
calc_layer(ObClient
*self
)
1490 if (self
->fullscreen
) l
= OB_STACKING_LAYER_FULLSCREEN
;
1491 else if (self
->type
== OB_CLIENT_TYPE_DESKTOP
)
1492 l
= OB_STACKING_LAYER_DESKTOP
;
1493 else if (self
->type
== OB_CLIENT_TYPE_DOCK
) {
1494 if (!self
->below
) l
= OB_STACKING_LAYER_TOP
;
1495 else l
= OB_STACKING_LAYER_NORMAL
;
1497 else if (self
->above
) l
= OB_STACKING_LAYER_ABOVE
;
1498 else if (self
->below
) l
= OB_STACKING_LAYER_BELOW
;
1499 else l
= OB_STACKING_LAYER_NORMAL
;
1504 static void client_calc_layer_recursive(ObClient
*self
, ObClient
*orig
,
1505 ObStackingLayer l
, gboolean raised
)
1507 ObStackingLayer old
, own
;
1511 own
= calc_layer(self
);
1512 self
->layer
= l
> own
? l
: own
;
1514 for (it
= self
->transients
; it
; it
= it
->next
)
1515 client_calc_layer_recursive(it
->data
, orig
,
1516 l
, raised
? raised
: l
!= old
);
1518 if (!raised
&& l
!= old
)
1519 if (orig
->frame
) { /* only restack if the original window is managed */
1520 /* XXX add_non_intrusive ever? */
1521 stacking_remove(CLIENT_AS_WINDOW(self
));
1522 stacking_add(CLIENT_AS_WINDOW(self
));
1526 void client_calc_layer(ObClient
*self
)
1533 /* transients take on the layer of their parents */
1534 self
= client_search_top_transient(self
);
1536 l
= calc_layer(self
);
1538 client_calc_layer_recursive(self
, orig
, l
, FALSE
);
1541 gboolean
client_should_show(ObClient
*self
)
1543 if (self
->iconic
) return FALSE
;
1544 else if (!(self
->desktop
== screen_desktop
||
1545 self
->desktop
== DESKTOP_ALL
)) return FALSE
;
1546 else if (client_normal(self
) && screen_showing_desktop
) return FALSE
;
1551 static void client_showhide(ObClient
*self
)
1554 if (client_should_show(self
))
1555 frame_show(self
->frame
);
1557 frame_hide(self
->frame
);
1560 gboolean
client_normal(ObClient
*self
) {
1561 return ! (self
->type
== OB_CLIENT_TYPE_DESKTOP
||
1562 self
->type
== OB_CLIENT_TYPE_DOCK
||
1563 self
->type
== OB_CLIENT_TYPE_SPLASH
);
1566 static void client_apply_startup_state(ObClient
*self
)
1568 /* these are in a carefully crafted order.. */
1571 self
->iconic
= FALSE
;
1572 client_iconify(self
, TRUE
, FALSE
);
1574 if (self
->fullscreen
) {
1575 self
->fullscreen
= FALSE
;
1576 client_fullscreen(self
, TRUE
, FALSE
);
1579 self
->shaded
= FALSE
;
1580 client_shade(self
, TRUE
);
1583 dispatch_client(Event_Client_Urgent
, self
, self
->urgent
, 0);
1585 if (self
->max_vert
&& self
->max_horz
) {
1586 self
->max_vert
= self
->max_horz
= FALSE
;
1587 client_maximize(self
, TRUE
, 0, FALSE
);
1588 } else if (self
->max_vert
) {
1589 self
->max_vert
= FALSE
;
1590 client_maximize(self
, TRUE
, 2, FALSE
);
1591 } else if (self
->max_horz
) {
1592 self
->max_horz
= FALSE
;
1593 client_maximize(self
, TRUE
, 1, FALSE
);
1596 /* nothing to do for the other states:
1605 void client_configure(ObClient
*self
, ObCorner anchor
,
1606 int x
, int y
, int w
, int h
,
1607 gboolean user
, gboolean final
)
1609 gboolean moved
= FALSE
, resized
= FALSE
;
1611 /* gets the frame's position */
1612 frame_client_gravity(self
->frame
, &x
, &y
);
1614 /* these positions are frame positions, not client positions */
1616 /* set the size and position if fullscreen */
1617 if (self
->fullscreen
) {
1620 XF86VidModeModeLine mode
;
1625 i
= client_monitor(self
);
1626 a
= screen_physical_area_monitor(i
);
1629 if (i
== 0 && /* primary head */
1630 extensions_vidmode
&&
1631 XF86VidModeGetViewPort(ob_display
, ob_screen
, &x
, &y
) &&
1632 /* get the mode last so the mode.privsize isnt freed incorrectly */
1633 XF86VidModeGetModeLine(ob_display
, ob_screen
, &dot
, &mode
)) {
1638 if (mode
.privsize
) XFree(mode
.private);
1648 user
= FALSE
; /* ignore that increment etc shit when in fullscreen */
1652 a
= screen_area_monitor(self
->desktop
, client_monitor(self
));
1654 /* set the size and position if maximized */
1655 if (self
->max_horz
) {
1656 x
= a
->x
- self
->frame
->size
.left
;
1659 if (self
->max_vert
) {
1661 h
= a
->height
- self
->frame
->size
.top
- self
->frame
->size
.bottom
;
1665 /* gets the client's position */
1666 frame_frame_gravity(self
->frame
, &x
, &y
);
1668 /* these override the above states! if you cant move you can't move! */
1670 if (!(self
->functions
& OB_CLIENT_FUNC_MOVE
)) {
1674 if (!(self
->functions
& OB_CLIENT_FUNC_RESIZE
)) {
1675 w
= self
->area
.width
;
1676 h
= self
->area
.height
;
1680 if (!(w
== self
->area
.width
&& h
== self
->area
.height
)) {
1681 int basew
, baseh
, minw
, minh
;
1683 /* base size is substituted with min size if not specified */
1684 if (self
->base_size
.width
|| self
->base_size
.height
) {
1685 basew
= self
->base_size
.width
;
1686 baseh
= self
->base_size
.height
;
1688 basew
= self
->min_size
.width
;
1689 baseh
= self
->min_size
.height
;
1691 /* min size is substituted with base size if not specified */
1692 if (self
->min_size
.width
|| self
->min_size
.height
) {
1693 minw
= self
->min_size
.width
;
1694 minh
= self
->min_size
.height
;
1696 minw
= self
->base_size
.width
;
1697 minh
= self
->base_size
.height
;
1701 /* for interactive resizing. have to move half an increment in each
1704 /* how far we are towards the next size inc */
1705 int mw
= (w
- basew
) % self
->size_inc
.width
;
1706 int mh
= (h
- baseh
) % self
->size_inc
.height
;
1708 int aw
= self
->size_inc
.width
/ 2;
1709 int ah
= self
->size_inc
.height
/ 2;
1710 /* don't let us move into a new size increment */
1711 if (mw
+ aw
>= self
->size_inc
.width
)
1712 aw
= self
->size_inc
.width
- mw
- 1;
1713 if (mh
+ ah
>= self
->size_inc
.height
)
1714 ah
= self
->size_inc
.height
- mh
- 1;
1718 /* if this is a user-requested resize, then check against min/max
1721 /* smaller than min size or bigger than max size? */
1722 if (w
> self
->max_size
.width
) w
= self
->max_size
.width
;
1723 if (w
< minw
) w
= minw
;
1724 if (h
> self
->max_size
.height
) h
= self
->max_size
.height
;
1725 if (h
< minh
) h
= minh
;
1731 /* keep to the increments */
1732 w
/= self
->size_inc
.width
;
1733 h
/= self
->size_inc
.height
;
1735 /* you cannot resize to nothing */
1739 /* store the logical size */
1740 SIZE_SET(self
->logical_size
, w
, h
);
1742 w
*= self
->size_inc
.width
;
1743 h
*= self
->size_inc
.height
;
1749 /* adjust the height to match the width for the aspect ratios.
1750 for this, min size is not substituted for base size ever. */
1751 w
-= self
->base_size
.width
;
1752 h
-= self
->base_size
.height
;
1754 if (self
->min_ratio
)
1755 if (h
* self
->min_ratio
> w
) h
= (int)(w
/ self
->min_ratio
);
1756 if (self
->max_ratio
)
1757 if (h
* self
->max_ratio
< w
) h
= (int)(w
/ self
->max_ratio
);
1759 w
+= self
->base_size
.width
;
1760 h
+= self
->base_size
.height
;
1765 case OB_CORNER_TOPLEFT
:
1767 case OB_CORNER_TOPRIGHT
:
1768 x
-= w
- self
->area
.width
;
1770 case OB_CORNER_BOTTOMLEFT
:
1771 y
-= h
- self
->area
.height
;
1773 case OB_CORNER_BOTTOMRIGHT
:
1774 x
-= w
- self
->area
.width
;
1775 y
-= h
- self
->area
.height
;
1779 moved
= x
!= self
->area
.x
|| y
!= self
->area
.y
;
1780 resized
= w
!= self
->area
.width
|| h
!= self
->area
.height
;
1782 RECT_SET(self
->area
, x
, y
, w
, h
);
1784 /* for app-requested resizes, always resize if 'resized' is true.
1785 for user-requested ones, only resize if final is true, or when
1786 resizing in opaque mode */
1787 if ((!user
&& resized
) ||
1788 (user
&& (final
|| (resized
&& config_opaque_resize
))))
1789 XResizeWindow(ob_display
, self
->window
, w
, h
);
1791 /* move/resize the frame to match the request */
1793 if (self
->decorations
!= self
->frame
->decorations
)
1794 moved
= resized
= TRUE
;
1796 if (moved
|| resized
)
1797 frame_adjust_area(self
->frame
, moved
, resized
);
1799 /* If you send this and the client hasn't changed you end up with buggy
1800 clients (emacs) freaking out, cuz they send back a configure every
1801 time they receive this event, which resends them this event... etc.
1803 if ((!user
&& moved
) || (user
&& final
)) {
1805 event
.type
= ConfigureNotify
;
1806 event
.xconfigure
.display
= ob_display
;
1807 event
.xconfigure
.event
= self
->window
;
1808 event
.xconfigure
.window
= self
->window
;
1810 /* root window real coords */
1811 event
.xconfigure
.x
= self
->frame
->area
.x
+ self
->frame
->size
.left
;
1812 event
.xconfigure
.y
= self
->frame
->area
.y
+ self
->frame
->size
.top
;
1814 event
.xconfigure
.width
= w
;
1815 event
.xconfigure
.height
= h
;
1816 event
.xconfigure
.border_width
= 0;
1817 event
.xconfigure
.above
= self
->frame
->plate
;
1818 event
.xconfigure
.override_redirect
= FALSE
;
1819 XSendEvent(event
.xconfigure
.display
, event
.xconfigure
.window
,
1820 FALSE
, StructureNotifyMask
, &event
);
1825 void client_fullscreen(ObClient
*self
, gboolean fs
, gboolean savearea
)
1829 if (!(self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
) || /* can't */
1830 self
->fullscreen
== fs
) return; /* already done */
1832 self
->fullscreen
= fs
;
1833 client_change_state(self
); /* change the state hints on the client,
1834 and adjust out layer/stacking */
1838 guint32 dimensions
[4];
1839 dimensions
[0] = self
->area
.x
;
1840 dimensions
[1] = self
->area
.y
;
1841 dimensions
[2] = self
->area
.width
;
1842 dimensions
[3] = self
->area
.height
;
1844 PROP_SETA32(self
->window
, openbox_premax
, cardinal
,
1848 /* these are not actually used cuz client_configure will set them
1849 as appropriate when the window is fullscreened */
1856 /* pick some fallbacks... */
1857 a
= screen_area_monitor(self
->desktop
, 0);
1858 x
= a
->x
+ a
->width
/ 4;
1859 y
= a
->y
+ a
->height
/ 4;
1863 if (PROP_GETA32(self
->window
, openbox_premax
, cardinal
,
1864 (guint32
**)&dimensions
, &num
)) {
1875 client_setup_decor_and_functions(self
);
1877 client_configure(self
, OB_CORNER_TOPLEFT
, x
, y
, w
, h
, TRUE
, TRUE
);
1879 /* try focus us when we go into fullscreen mode */
1883 static void client_iconify_recursive(ObClient
*self
,
1884 gboolean iconic
, gboolean curdesk
)
1887 gboolean changed
= FALSE
;
1890 if (self
->iconic
!= iconic
) {
1891 g_message("%sconifying window: 0x%lx", (iconic
? "I" : "Uni"),
1894 self
->iconic
= iconic
;
1897 if (self
->functions
& OB_CLIENT_FUNC_ICONIFY
) {
1898 self
->wmstate
= IconicState
;
1899 self
->ignore_unmaps
++;
1900 /* we unmap the client itself so that we can get MapRequest
1901 events, and because the ICCCM tells us to! */
1902 XUnmapWindow(ob_display
, self
->window
);
1904 /* update the focus lists.. iconic windows go to the bottom of
1905 the list, put the new iconic window at the 'top of the
1907 focus_order_to_top(self
);
1913 client_set_desktop(self
, screen_desktop
, FALSE
);
1914 self
->wmstate
= self
->shaded
? IconicState
: NormalState
;
1915 XMapWindow(ob_display
, self
->window
);
1917 /* this puts it after the current focused window */
1918 focus_order_remove(self
);
1919 focus_order_add_new(self
);
1921 /* this is here cuz with the VIDMODE extension, the viewport can
1922 change while a fullscreen window is iconic, and when it
1923 uniconifies, it would be nice if it did so to the new position
1925 client_reconfigure(self
);
1932 client_change_state(self
);
1933 client_showhide(self
);
1934 screen_update_areas();
1936 dispatch_client(iconic
? Event_Client_Unmapped
: Event_Client_Mapped
,
1940 /* iconify all transients */
1941 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
)
1942 if (it
->data
!= self
) client_iconify_recursive(it
->data
,
1946 void client_iconify(ObClient
*self
, gboolean iconic
, gboolean curdesk
)
1948 /* move up the transient chain as far as possible first */
1949 self
= client_search_top_transient(self
);
1951 client_iconify_recursive(client_search_top_transient(self
),
1955 void client_maximize(ObClient
*self
, gboolean max
, int dir
, gboolean savearea
)
1959 g_assert(dir
== 0 || dir
== 1 || dir
== 2);
1960 if (!(self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
)) return; /* can't */
1962 /* check if already done */
1964 if (dir
== 0 && self
->max_horz
&& self
->max_vert
) return;
1965 if (dir
== 1 && self
->max_horz
) return;
1966 if (dir
== 2 && self
->max_vert
) return;
1968 if (dir
== 0 && !self
->max_horz
&& !self
->max_vert
) return;
1969 if (dir
== 1 && !self
->max_horz
) return;
1970 if (dir
== 2 && !self
->max_vert
) return;
1973 /* work with the frame's coords */
1974 x
= self
->frame
->area
.x
;
1975 y
= self
->frame
->area
.y
;
1976 w
= self
->area
.width
;
1977 h
= self
->area
.height
;
1981 gint32 dimensions
[4];
1990 /* get the property off the window and use it for the dimensions
1991 we are already maxed on */
1992 if (PROP_GETA32(self
->window
, openbox_premax
, cardinal
,
1993 (guint32
**)&readdim
, &num
)) {
1995 if (self
->max_horz
) {
1996 dimensions
[0] = readdim
[0];
1997 dimensions
[2] = readdim
[2];
1999 if (self
->max_vert
) {
2000 dimensions
[1] = readdim
[1];
2001 dimensions
[3] = readdim
[3];
2007 PROP_SETA32(self
->window
, openbox_premax
, cardinal
,
2008 (guint32
*)dimensions
, 4);
2015 /* pick some fallbacks... */
2016 a
= screen_area_monitor(self
->desktop
, 0);
2017 if (dir
== 0 || dir
== 1) { /* horz */
2018 x
= a
->x
+ a
->width
/ 4;
2021 if (dir
== 0 || dir
== 2) { /* vert */
2022 y
= a
->y
+ a
->height
/ 4;
2026 if (PROP_GETA32(self
->window
, openbox_premax
, cardinal
,
2027 (guint32
**)&dimensions
, &num
)) {
2029 if (dir
== 0 || dir
== 1) { /* horz */
2033 if (dir
== 0 || dir
== 2) { /* vert */
2042 if (dir
== 0 || dir
== 1) /* horz */
2043 self
->max_horz
= max
;
2044 if (dir
== 0 || dir
== 2) /* vert */
2045 self
->max_vert
= max
;
2047 if (!self
->max_horz
&& !self
->max_vert
)
2048 PROP_ERASE(self
->window
, openbox_premax
);
2050 client_change_state(self
); /* change the state hints on the client */
2052 /* figure out where the client should be going */
2053 frame_frame_gravity(self
->frame
, &x
, &y
);
2054 client_configure(self
, OB_CORNER_TOPLEFT
, x
, y
, w
, h
, TRUE
, TRUE
);
2057 void client_shade(ObClient
*self
, gboolean shade
)
2059 if ((!(self
->functions
& OB_CLIENT_FUNC_SHADE
) &&
2060 shade
) || /* can't shade */
2061 self
->shaded
== shade
) return; /* already done */
2063 /* when we're iconic, don't change the wmstate */
2065 self
->wmstate
= shade
? IconicState
: NormalState
;
2066 self
->shaded
= shade
;
2067 client_change_state(self
);
2068 /* resize the frame to just the titlebar */
2069 frame_adjust_area(self
->frame
, FALSE
, FALSE
);
2072 void client_close(ObClient
*self
)
2076 if (!(self
->functions
& OB_CLIENT_FUNC_CLOSE
)) return;
2079 XXX: itd be cool to do timeouts and shit here for killing the client's
2081 like... if the window is around after 5 seconds, then the close button
2082 turns a nice red, and if this function is called again, the client is
2086 ce
.xclient
.type
= ClientMessage
;
2087 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
2088 ce
.xclient
.display
= ob_display
;
2089 ce
.xclient
.window
= self
->window
;
2090 ce
.xclient
.format
= 32;
2091 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_delete_window
;
2092 ce
.xclient
.data
.l
[1] = event_lasttime
;
2093 ce
.xclient
.data
.l
[2] = 0l;
2094 ce
.xclient
.data
.l
[3] = 0l;
2095 ce
.xclient
.data
.l
[4] = 0l;
2096 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
2099 void client_kill(ObClient
*self
)
2101 XKillClient(ob_display
, self
->window
);
2104 void client_set_desktop_recursive(ObClient
*self
,
2105 guint target
, gboolean donthide
)
2110 if (target
!= self
->desktop
) {
2112 g_message("Setting desktop %u", target
+1);
2114 g_assert(target
< screen_num_desktops
|| target
== DESKTOP_ALL
);
2116 /* remove from the old desktop(s) */
2117 focus_order_remove(self
);
2119 old
= self
->desktop
;
2120 self
->desktop
= target
;
2121 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, target
);
2122 /* the frame can display the current desktop state */
2123 frame_adjust_state(self
->frame
);
2124 /* 'move' the window to the new desktop */
2126 client_showhide(self
);
2127 /* raise if it was not already on the desktop */
2128 if (old
!= DESKTOP_ALL
)
2129 stacking_raise(CLIENT_AS_WINDOW(self
));
2130 screen_update_areas();
2132 /* add to the new desktop(s) */
2133 if (config_focus_new
)
2134 focus_order_to_top(self
);
2136 focus_order_to_bottom(self
);
2138 dispatch_client(Event_Client_Desktop
, self
, target
, old
);
2141 /* move all transients */
2142 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
)
2143 if (it
->data
!= self
) client_set_desktop_recursive(it
->data
,
2147 void client_set_desktop(ObClient
*self
, guint target
, gboolean donthide
)
2149 client_set_desktop_recursive(client_search_top_transient(self
),
2153 ObClient
*client_search_modal_child(ObClient
*self
)
2158 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
) {
2159 ObClient
*c
= it
->data
;
2160 if ((ret
= client_search_modal_child(c
))) return ret
;
2161 if (c
->modal
) return c
;
2166 gboolean
client_validate(ObClient
*self
)
2170 XSync(ob_display
, FALSE
); /* get all events on the server */
2172 if (XCheckTypedWindowEvent(ob_display
, self
->window
, DestroyNotify
, &e
) ||
2173 XCheckTypedWindowEvent(ob_display
, self
->window
, UnmapNotify
, &e
)) {
2174 XPutBackEvent(ob_display
, &e
);
2181 void client_set_wm_state(ObClient
*self
, long state
)
2183 if (state
== self
->wmstate
) return; /* no change */
2187 client_iconify(self
, TRUE
, TRUE
);
2190 client_iconify(self
, FALSE
, TRUE
);
2195 void client_set_state(ObClient
*self
, Atom action
, long data1
, long data2
)
2197 gboolean shaded
= self
->shaded
;
2198 gboolean fullscreen
= self
->fullscreen
;
2199 gboolean max_horz
= self
->max_horz
;
2200 gboolean max_vert
= self
->max_vert
;
2203 if (!(action
== prop_atoms
.net_wm_state_add
||
2204 action
== prop_atoms
.net_wm_state_remove
||
2205 action
== prop_atoms
.net_wm_state_toggle
))
2206 /* an invalid action was passed to the client message, ignore it */
2209 for (i
= 0; i
< 2; ++i
) {
2210 Atom state
= i
== 0 ? data1
: data2
;
2212 if (!state
) continue;
2214 /* if toggling, then pick whether we're adding or removing */
2215 if (action
== prop_atoms
.net_wm_state_toggle
) {
2216 if (state
== prop_atoms
.net_wm_state_modal
)
2217 action
= self
->modal
? prop_atoms
.net_wm_state_remove
:
2218 prop_atoms
.net_wm_state_add
;
2219 else if (state
== prop_atoms
.net_wm_state_maximized_vert
)
2220 action
= self
->max_vert
? prop_atoms
.net_wm_state_remove
:
2221 prop_atoms
.net_wm_state_add
;
2222 else if (state
== prop_atoms
.net_wm_state_maximized_horz
)
2223 action
= self
->max_horz
? prop_atoms
.net_wm_state_remove
:
2224 prop_atoms
.net_wm_state_add
;
2225 else if (state
== prop_atoms
.net_wm_state_shaded
)
2226 action
= self
->shaded
? prop_atoms
.net_wm_state_remove
:
2227 prop_atoms
.net_wm_state_add
;
2228 else if (state
== prop_atoms
.net_wm_state_skip_taskbar
)
2229 action
= self
->skip_taskbar
?
2230 prop_atoms
.net_wm_state_remove
:
2231 prop_atoms
.net_wm_state_add
;
2232 else if (state
== prop_atoms
.net_wm_state_skip_pager
)
2233 action
= self
->skip_pager
?
2234 prop_atoms
.net_wm_state_remove
:
2235 prop_atoms
.net_wm_state_add
;
2236 else if (state
== prop_atoms
.net_wm_state_fullscreen
)
2237 action
= self
->fullscreen
?
2238 prop_atoms
.net_wm_state_remove
:
2239 prop_atoms
.net_wm_state_add
;
2240 else if (state
== prop_atoms
.net_wm_state_above
)
2241 action
= self
->above
? prop_atoms
.net_wm_state_remove
:
2242 prop_atoms
.net_wm_state_add
;
2243 else if (state
== prop_atoms
.net_wm_state_below
)
2244 action
= self
->below
? prop_atoms
.net_wm_state_remove
:
2245 prop_atoms
.net_wm_state_add
;
2248 if (action
== prop_atoms
.net_wm_state_add
) {
2249 if (state
== prop_atoms
.net_wm_state_modal
) {
2250 /* XXX raise here or something? */
2252 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
2254 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
2256 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
2258 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
2259 self
->skip_taskbar
= TRUE
;
2260 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
2261 self
->skip_pager
= TRUE
;
2262 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
2264 } else if (state
== prop_atoms
.net_wm_state_above
) {
2266 } else if (state
== prop_atoms
.net_wm_state_below
) {
2270 } else { /* action == prop_atoms.net_wm_state_remove */
2271 if (state
== prop_atoms
.net_wm_state_modal
) {
2272 self
->modal
= FALSE
;
2273 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
2275 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
2277 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
2279 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
2280 self
->skip_taskbar
= FALSE
;
2281 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
2282 self
->skip_pager
= FALSE
;
2283 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
2285 } else if (state
== prop_atoms
.net_wm_state_above
) {
2286 self
->above
= FALSE
;
2287 } else if (state
== prop_atoms
.net_wm_state_below
) {
2288 self
->below
= FALSE
;
2292 if (max_horz
!= self
->max_horz
|| max_vert
!= self
->max_vert
) {
2293 if (max_horz
!= self
->max_horz
&& max_vert
!= self
->max_vert
) {
2295 if (max_horz
== max_vert
) { /* both going the same way */
2296 client_maximize(self
, max_horz
, 0, TRUE
);
2298 client_maximize(self
, max_horz
, 1, TRUE
);
2299 client_maximize(self
, max_vert
, 2, TRUE
);
2303 if (max_horz
!= self
->max_horz
)
2304 client_maximize(self
, max_horz
, 1, TRUE
);
2306 client_maximize(self
, max_vert
, 2, TRUE
);
2309 /* change fullscreen state before shading, as it will affect if the window
2311 if (fullscreen
!= self
->fullscreen
)
2312 client_fullscreen(self
, fullscreen
, TRUE
);
2313 if (shaded
!= self
->shaded
)
2314 client_shade(self
, shaded
);
2315 client_calc_layer(self
);
2316 client_change_state(self
); /* change the hint to reflect these changes */
2319 ObClient
*client_focus_target(ObClient
*self
)
2323 /* if we have a modal child, then focus it, not us */
2324 child
= client_search_modal_child(self
);
2325 if (child
) return child
;
2329 gboolean
client_can_focus(ObClient
*self
)
2333 /* choose the correct target */
2334 self
= client_focus_target(self
);
2336 if (!self
->frame
->visible
)
2339 if (!((self
->can_focus
|| self
->focus_notify
) &&
2340 (self
->desktop
== screen_desktop
||
2341 self
->desktop
== DESKTOP_ALL
) &&
2345 /* do a check to see if the window has already been unmapped or destroyed
2346 do this intelligently while watching out for unmaps we've generated
2347 (ignore_unmaps > 0) */
2348 if (XCheckTypedWindowEvent(ob_display
, self
->window
,
2349 DestroyNotify
, &ev
)) {
2350 XPutBackEvent(ob_display
, &ev
);
2353 while (XCheckTypedWindowEvent(ob_display
, self
->window
,
2354 UnmapNotify
, &ev
)) {
2355 if (self
->ignore_unmaps
) {
2356 self
->ignore_unmaps
--;
2358 XPutBackEvent(ob_display
, &ev
);
2366 gboolean
client_focus(ObClient
*self
)
2368 /* choose the correct target */
2369 self
= client_focus_target(self
);
2371 if (!client_can_focus(self
)) {
2372 if (!self
->frame
->visible
) {
2373 /* update the focus lists */
2374 focus_order_to_top(self
);
2379 if (self
->can_focus
)
2380 /* RevertToPointerRoot causes much more headache than RevertToNone, so
2381 I choose to use it always, hopefully to find errors quicker, if any
2382 are left. (I hate X. I hate focus events.) */
2383 XSetInputFocus(ob_display
, self
->window
, RevertToPointerRoot
,
2386 if (self
->focus_notify
) {
2388 ce
.xclient
.type
= ClientMessage
;
2389 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
2390 ce
.xclient
.display
= ob_display
;
2391 ce
.xclient
.window
= self
->window
;
2392 ce
.xclient
.format
= 32;
2393 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_take_focus
;
2394 ce
.xclient
.data
.l
[1] = event_lasttime
;
2395 ce
.xclient
.data
.l
[2] = 0l;
2396 ce
.xclient
.data
.l
[3] = 0l;
2397 ce
.xclient
.data
.l
[4] = 0l;
2398 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
2402 g_message("%sively focusing %lx at %d", (self
->can_focus
? "act" : "pass"),
2407 /* Cause the FocusIn to come back to us. Important for desktop switches,
2408 since otherwise we'll have no FocusIn on the queue and send it off to
2409 the focus_backup. */
2410 XSync(ob_display
, FALSE
);
2414 void client_unfocus(ObClient
*self
)
2416 g_assert(focus_client
== self
);
2418 g_message("client_unfocus for %lx", self
->window
);
2420 focus_fallback(OB_FOCUS_FALLBACK_UNFOCUSING
);
2423 void client_activate(ObClient
*self
)
2425 if (client_normal(self
) && screen_showing_desktop
)
2426 screen_show_desktop(FALSE
);
2428 client_iconify(self
, FALSE
, FALSE
);
2429 if (self
->desktop
!= DESKTOP_ALL
&&
2430 self
->desktop
!= screen_desktop
)
2431 screen_set_desktop(self
->desktop
);
2432 else if (!self
->frame
->visible
)
2433 /* if its not visible for other reasons, then don't mess
2437 client_shade(self
, FALSE
);
2439 stacking_raise(CLIENT_AS_WINDOW(self
));
2442 gboolean
client_focused(ObClient
*self
)
2444 return self
== focus_client
;
2447 ObClientIcon
*client_icon(ObClient
*self
, int w
, int h
)
2450 /* si is the smallest image >= req */
2451 /* li is the largest image < req */
2452 unsigned long size
, smallest
= 0xffffffff, largest
= 0, si
= 0, li
= 0;
2454 if (!self
->nicons
) return NULL
;
2456 for (i
= 0; i
< self
->nicons
; ++i
) {
2457 size
= self
->icons
[i
].width
* self
->icons
[i
].height
;
2458 if (size
< smallest
&& size
>= (unsigned)(w
* h
)) {
2462 if (size
> largest
&& size
<= (unsigned)(w
* h
)) {
2467 if (largest
== 0) /* didnt find one smaller than the requested size */
2468 return &self
->icons
[si
];
2469 return &self
->icons
[li
];
2472 /* this be mostly ripped from fvwm */
2473 ObClient
*client_find_directional(ObClient
*c
, ObDirection dir
)
2475 int my_cx
, my_cy
, his_cx
, his_cy
;
2478 int score
, best_score
;
2479 ObClient
*best_client
, *cur
;
2485 /* first, find the centre coords of the currently focused window */
2486 my_cx
= c
->frame
->area
.x
+ c
->frame
->area
.width
/ 2;
2487 my_cy
= c
->frame
->area
.y
+ c
->frame
->area
.height
/ 2;
2492 for(it
= g_list_first(client_list
); it
; it
= it
->next
) {
2495 /* the currently selected window isn't interesting */
2498 if (!client_normal(cur
))
2500 if(c
->desktop
!= cur
->desktop
&& cur
->desktop
!= DESKTOP_ALL
)
2504 if(client_focus_target(cur
) == cur
&&
2505 !(cur
->can_focus
|| cur
->focus_notify
))
2508 /* find the centre coords of this window, from the
2509 * currently focused window's point of view */
2510 his_cx
= (cur
->frame
->area
.x
- my_cx
)
2511 + cur
->frame
->area
.width
/ 2;
2512 his_cy
= (cur
->frame
->area
.y
- my_cy
)
2513 + cur
->frame
->area
.height
/ 2;
2517 /* Rotate the diagonals 45 degrees counterclockwise.
2518 * To do this, multiply the matrix /+h +h\ with the
2519 * vector (x y). \-h +h/
2520 * h = sqrt(0.5). We can set h := 1 since absolute
2521 * distance doesn't matter here. */
2522 tx
= his_cx
+ his_cy
;
2523 his_cy
= -his_cx
+ his_cy
;
2528 case OB_DIRECTION_NORTH
:
2529 case OB_DIRECTION_SOUTH
:
2530 case OB_DIRECTION_NORTHEAST
:
2531 case OB_DIRECTION_SOUTHWEST
:
2532 offset
= (his_cx
< 0) ? -his_cx
: his_cx
;
2533 distance
= ((dir
== OB_DIRECTION_NORTH
||
2534 dir
== OB_DIRECTION_NORTHEAST
) ?
2537 case OB_DIRECTION_EAST
:
2538 case OB_DIRECTION_WEST
:
2539 case OB_DIRECTION_SOUTHEAST
:
2540 case OB_DIRECTION_NORTHWEST
:
2541 offset
= (his_cy
< 0) ? -his_cy
: his_cy
;
2542 distance
= ((dir
== OB_DIRECTION_WEST
||
2543 dir
== OB_DIRECTION_NORTHWEST
) ?
2548 /* the target must be in the requested direction */
2552 /* Calculate score for this window. The smaller the better. */
2553 score
= distance
+ offset
;
2555 /* windows more than 45 degrees off the direction are
2556 * heavily penalized and will only be chosen if nothing
2557 * else within a million pixels */
2558 if(offset
> distance
)
2561 if(best_score
== -1 || score
< best_score
)
2569 void client_set_layer(ObClient
*self
, int layer
)
2573 self
->above
= FALSE
;
2574 } else if (layer
== 0) {
2575 self
->below
= self
->above
= FALSE
;
2577 self
->below
= FALSE
;
2580 client_calc_layer(self
);
2581 client_change_state(self
); /* reflect this in the state hints */
2584 guint
client_monitor(ObClient
*self
)
2588 for (i
= 0; i
< screen_num_monitors
; ++i
) {
2589 Rect
*area
= screen_physical_area_monitor(i
);
2590 if (RECT_INTERSECTS_RECT(*area
, self
->frame
->area
))
2593 if (i
== screen_num_monitors
) i
= 0;
2594 g_assert(i
< screen_num_monitors
);
2598 ObClient
*client_search_top_transient(ObClient
*self
)
2600 /* move up the transient chain as far as possible */
2601 if (self
->transient_for
) {
2602 if (self
->transient_for
!= OB_TRAN_GROUP
) {
2603 return client_search_top_transient(self
->transient_for
);
2607 for (it
= self
->group
->members
; it
; it
= it
->next
) {
2608 ObClient
*c
= it
->data
;
2610 /* checking transient_for prevents infinate loops! */
2611 if (c
!= self
&& !c
->transient_for
)