7 #include "moveresize.h"
9 #include "extensions.h"
20 #include "render/render.h"
23 #include <X11/Xutil.h>
25 /*! The event mask to grab on client windows */
26 #define CLIENT_EVENTMASK (PropertyChangeMask | FocusChangeMask | \
29 #define CLIENT_NOPROPAGATEMASK (ButtonPressMask | ButtonReleaseMask | \
32 GList
*client_list
= NULL
;
34 static void client_get_all(ObClient
*self
);
35 static void client_toggle_border(ObClient
*self
, gboolean show
);
36 static void client_get_area(ObClient
*self
);
37 static void client_get_desktop(ObClient
*self
);
38 static void client_get_state(ObClient
*self
);
39 static void client_get_shaped(ObClient
*self
);
40 static void client_get_mwm_hints(ObClient
*self
);
41 static void client_get_gravity(ObClient
*self
);
42 static void client_showhide(ObClient
*self
);
43 static void client_change_allowed_actions(ObClient
*self
);
44 static void client_change_state(ObClient
*self
);
45 static void client_apply_startup_state(ObClient
*self
);
52 void client_shutdown()
56 void client_set_list()
58 Window
*windows
, *win_it
;
60 guint size
= g_list_length(client_list
);
62 /* create an array of the window ids */
64 windows
= g_new(Window
, size
);
66 for (it
= client_list
; it
!= NULL
; it
= it
->next
, ++win_it
)
67 *win_it
= ((ObClient
*)it
->data
)->window
;
71 PROP_SETA32(RootWindow(ob_display
, ob_screen
),
72 net_client_list
, window
, (guint32
*)windows
, size
);
81 void client_foreach_transient(ObClient *self, ObClientForeachFunc func, void *data)
85 for (it = self->transients; it; it = it->next) {
86 if (!func(it->data, data)) return;
87 client_foreach_transient(it->data, func, data);
91 void client_foreach_ancestor(ObClient *self, ObClientForeachFunc func, void *data)
93 if (self->transient_for) {
94 if (self->transient_for != OB_TRAN_GROUP) {
95 if (!func(self->transient_for, data)) return;
96 client_foreach_ancestor(self->transient_for, func, data);
100 for (it = self->group->members; it; it = it->next)
101 if (it->data != self &&
102 !((ObClient*)it->data)->transient_for) {
103 if (!func(it->data, data)) return;
104 client_foreach_ancestor(it->data, func, data);
111 void client_manage_all()
113 unsigned int i
, j
, nchild
;
116 XWindowAttributes attrib
;
118 XQueryTree(ob_display
, RootWindow(ob_display
, ob_screen
),
119 &w
, &w
, &children
, &nchild
);
121 /* remove all icon windows from the list */
122 for (i
= 0; i
< nchild
; i
++) {
123 if (children
[i
] == None
) continue;
124 wmhints
= XGetWMHints(ob_display
, children
[i
]);
126 if ((wmhints
->flags
& IconWindowHint
) &&
127 (wmhints
->icon_window
!= children
[i
]))
128 for (j
= 0; j
< nchild
; j
++)
129 if (children
[j
] == wmhints
->icon_window
) {
137 for (i
= 0; i
< nchild
; ++i
) {
138 if (children
[i
] == None
)
140 if (XGetWindowAttributes(ob_display
, children
[i
], &attrib
)) {
141 if (attrib
.override_redirect
) continue;
143 if (attrib
.map_state
!= IsUnmapped
)
144 client_manage(children
[i
]);
149 /* stack them as they were on startup!
150 why with stacking_lower? Why, because then windows who aren't in the
151 stacking list are on the top where you can see them instead of buried
153 for (i
= startup_stack_size
; i
> 0; --i
) {
156 w
= startup_stack_order
[i
-1];
157 obw
= g_hash_table_lookup(window_map
, &w
);
159 g_assert(WINDOW_IS_CLIENT(obw
));
160 stacking_lower(CLIENT_AS_WINDOW(obw
));
163 g_free(startup_stack_order
);
164 startup_stack_order
= NULL
;
165 startup_stack_size
= 0;
167 if (config_focus_new
) {
170 active
= g_hash_table_lookup(window_map
, &startup_active
);
172 g_assert(WINDOW_IS_CLIENT(active
));
173 if (!client_focus(WINDOW_AS_CLIENT(active
)))
174 focus_fallback(OB_FOCUS_FALLBACK_NOFOCUS
);
176 focus_fallback(OB_FOCUS_FALLBACK_NOFOCUS
);
180 void client_manage(Window window
)
184 XWindowAttributes attrib
;
185 XSetWindowAttributes attrib_set
;
187 gboolean activate
= FALSE
;
191 /* check if it has already been unmapped by the time we started mapping
192 the grab does a sync so we don't have to here */
193 if (XCheckTypedWindowEvent(ob_display
, window
, DestroyNotify
, &e
) ||
194 XCheckTypedWindowEvent(ob_display
, window
, UnmapNotify
, &e
)) {
195 XPutBackEvent(ob_display
, &e
);
198 return; /* don't manage it */
201 /* make sure it isn't an override-redirect window */
202 if (!XGetWindowAttributes(ob_display
, window
, &attrib
) ||
203 attrib
.override_redirect
) {
205 return; /* don't manage it */
208 /* is the window a docking app */
209 if ((wmhint
= XGetWMHints(ob_display
, window
))) {
210 if ((wmhint
->flags
& StateHint
) &&
211 wmhint
->initial_state
== WithdrawnState
) {
212 dock_add(window
, wmhint
);
220 ob_debug("Managing window: %lx\n", window
);
222 /* choose the events we want to receive on the CLIENT window */
223 attrib_set
.event_mask
= CLIENT_EVENTMASK
;
224 attrib_set
.do_not_propagate_mask
= CLIENT_NOPROPAGATEMASK
;
225 XChangeWindowAttributes(ob_display
, window
,
226 CWEventMask
|CWDontPropagate
, &attrib_set
);
229 /* create the ObClient struct, and populate it from the hints on the
231 self
= g_new(ObClient
, 1);
232 self
->obwin
.type
= Window_Client
;
233 self
->window
= window
;
234 client_get_all(self
);
236 /* remove the client's border (and adjust re gravity) */
237 client_toggle_border(self
, FALSE
);
239 /* specify that if we exit, the window should not be destroyed and should
240 be reparented back to root automatically */
241 XChangeSaveSet(ob_display
, window
, SetModeInsert
);
243 /* create the decoration frame for the client window */
244 self
->frame
= frame_new();
246 frame_grab_client(self
->frame
, self
);
248 client_apply_startup_state(self
);
252 /* update the focus lists */
253 focus_order_add_new(self
);
255 stacking_add(CLIENT_AS_WINDOW(self
));
257 /* focus the new window? */
258 if (ob_state() != OB_STATE_STARTING
&& config_focus_new
&&
259 /* note the check against Type_Normal/Dialog, not client_normal(self),
260 which would also include other types. in this case we want more
261 strict rules for focus */
262 (self
->type
== OB_CLIENT_TYPE_NORMAL
||
263 self
->type
== OB_CLIENT_TYPE_DIALOG
))
265 if (self
->desktop
!= screen_desktop
) {
266 /* activate the window */
269 gboolean group_foc
= FALSE
;
274 for (it
= self
->group
->members
; it
; it
= it
->next
)
276 if (client_focused(it
->data
))
284 (!self
->transient_for
&& (!self
->group
||
285 !self
->group
->members
->next
))) ||
286 client_search_focus_tree_full(self
) ||
288 !client_normal(focus_client
))
290 /* activate the window */
296 dispatch_client(Event_Client_New
, self
, 0, 0);
298 /* make sure the window is visible */
299 client_move_onscreen(self
, TRUE
);
301 screen_update_areas();
303 client_showhide(self
);
305 /* use client_focus instead of client_activate cuz client_activate does
306 stuff like switch desktops etc and I'm not interested in all that when
307 a window maps since its not based on an action from the user like
308 clicking a window to activate is. so keep the new window out of the way
310 if (activate
) client_focus(self
);
312 /* client_activate does this but we aret using it so we have to do it
314 if (screen_showing_desktop
)
315 screen_show_desktop(FALSE
);
317 /* update the list hints */
320 dispatch_client(Event_Client_Mapped
, self
, 0, 0);
322 /* add to client list/map */
323 client_list
= g_list_append(client_list
, self
);
324 g_hash_table_insert(window_map
, &self
->window
, self
);
326 ob_debug("Managed window 0x%lx (%s)\n", window
, self
->class);
329 void client_unmanage_all()
331 while (client_list
!= NULL
)
332 client_unmanage(client_list
->data
);
335 /* called by client_unmanage() to close any menus referencing this client */
336 void client_close_menus(gpointer key
, gpointer value
, gpointer self
)
338 if (((ObMenu
*)value
)->client
== (ObClient
*)self
)
339 menu_hide((ObMenu
*)value
);
342 void client_unmanage(ObClient
*self
)
347 ob_debug("Unmanaging window: %lx (%s)\n", self
->window
, self
->class);
349 dispatch_client(Event_Client_Destroy
, self
, 0, 0);
350 g_assert(self
!= NULL
);
352 /* remove the window from our save set */
353 XChangeSaveSet(ob_display
, self
->window
, SetModeDelete
);
355 /* we dont want events no more */
356 XSelectInput(ob_display
, self
->window
, NoEventMask
);
358 frame_hide(self
->frame
);
360 client_list
= g_list_remove(client_list
, self
);
361 stacking_remove(self
);
362 g_hash_table_remove(window_map
, &self
->window
);
364 /* update the focus lists */
365 focus_order_remove(self
);
367 /* once the client is out of the list, update the struts to remove it's
369 screen_update_areas();
371 /* tell our parent(s) that we're gone */
372 if (self
->transient_for
== OB_TRAN_GROUP
) { /* transient of group */
375 for (it
= self
->group
->members
; it
; it
= it
->next
)
376 if (it
->data
!= self
)
377 ((ObClient
*)it
->data
)->transients
=
378 g_slist_remove(((ObClient
*)it
->data
)->transients
, self
);
379 } else if (self
->transient_for
) { /* transient of window */
380 self
->transient_for
->transients
=
381 g_slist_remove(self
->transient_for
->transients
, self
);
384 /* tell our transients that we're gone */
385 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
) {
386 if (((ObClient
*)it
->data
)->transient_for
!= OB_TRAN_GROUP
) {
387 ((ObClient
*)it
->data
)->transient_for
= NULL
;
388 client_calc_layer(it
->data
);
392 if (moveresize_client
== self
)
393 moveresize_end(TRUE
);
395 /* close any windows that are attached to this window */
396 g_hash_table_foreach(menu_hash
, client_close_menus
, self
);
399 if (focus_client
== self
) {
402 /* focus the last focused window on the desktop, and ignore enter
403 events from the unmap so it doesnt mess with the focus */
404 while (XCheckTypedEvent(ob_display
, EnterNotify
, &e
));
405 client_unfocus(self
);
408 /* remove from its group */
410 group_remove(self
->group
, self
);
414 /* dispatch the unmapped event */
415 dispatch_client(Event_Client_Unmapped
, self
, 0, 0);
416 g_assert(self
!= NULL
);
418 /* give the client its border back */
419 client_toggle_border(self
, TRUE
);
421 /* reparent the window out of the frame, and free the frame */
422 frame_release_client(self
->frame
, self
);
425 if (ob_state() != OB_STATE_EXITING
) {
426 /* these values should not be persisted across a window
428 PROP_ERASE(self
->window
, net_wm_desktop
);
429 PROP_ERASE(self
->window
, net_wm_state
);
430 PROP_ERASE(self
->window
, wm_state
);
432 /* if we're left in an iconic state, the client wont be mapped. this is
433 bad, since we will no longer be managing the window on restart */
435 XMapWindow(ob_display
, self
->window
);
439 ob_debug("Unmanaged window 0x%lx\n", self
->window
);
441 /* free all data allocated in the client struct */
442 g_slist_free(self
->transients
);
443 for (j
= 0; j
< self
->nicons
; ++j
)
444 g_free(self
->icons
[j
].data
);
445 if (self
->nicons
> 0)
448 g_free(self
->icon_title
);
454 /* update the list hints */
458 void client_move_onscreen(ObClient
*self
, gboolean rude
)
460 int x
= self
->area
.x
;
461 int y
= self
->area
.y
;
462 if (client_find_onscreen(self
, &x
, &y
,
463 self
->area
.width
, self
->area
.height
, rude
)) {
464 client_configure(self
, OB_CORNER_TOPLEFT
, x
, y
,
465 self
->area
.width
, self
->area
.height
,
470 gboolean
client_find_onscreen(ObClient
*self
, int *x
, int *y
, int w
, int h
,
474 int ox
= *x
, oy
= *y
;
476 frame_client_gravity(self
->frame
, x
, y
); /* get where the frame
479 /* XXX watch for xinerama dead areas */
481 a
= screen_area(self
->desktop
);
482 if (!self
->strut
.right
&& *x
>= a
->x
+ a
->width
- 1)
483 *x
= a
->x
+ a
->width
- self
->frame
->area
.width
;
484 if (!self
->strut
.bottom
&& *y
>= a
->y
+ a
->height
- 1)
485 *y
= a
->y
+ a
->height
- self
->frame
->area
.height
;
486 if (!self
->strut
.left
&& *x
+ self
->frame
->area
.width
- 1 < a
->x
)
488 if (!self
->strut
.top
&& *y
+ self
->frame
->area
.height
- 1 < a
->y
)
492 /* this is my MOZILLA BITCHSLAP. oh ya it fucking feels good.
493 Java can suck it too. */
495 /* dont let windows map/move into the strut unless they
496 are bigger than the available area */
498 if (!self
->strut
.left
&& *x
< a
->x
) *x
= a
->x
;
499 if (!self
->strut
.right
&& *x
+ w
> a
->x
+ a
->width
)
500 *x
= a
->x
+ a
->width
- w
;
502 if (h
<= a
->height
) {
503 if (!self
->strut
.top
&& *y
< a
->y
) *y
= a
->y
;
504 if (!self
->strut
.bottom
&& *y
+ h
> a
->y
+ a
->height
)
505 *y
= a
->y
+ a
->height
- h
;
509 frame_frame_gravity(self
->frame
, x
, y
); /* get where the client
512 return ox
!= *x
|| oy
!= *y
;
515 static void client_toggle_border(ObClient
*self
, gboolean show
)
517 /* adjust our idea of where the client is, based on its border. When the
518 border is removed, the client should now be considered to be in a
520 when re-adding the border to the client, the same operation needs to be
522 int oldx
= self
->area
.x
, oldy
= self
->area
.y
;
523 int x
= oldx
, y
= oldy
;
524 switch(self
->gravity
) {
526 case NorthWestGravity
:
528 case SouthWestGravity
:
530 case NorthEastGravity
:
532 case SouthEastGravity
:
533 if (show
) x
-= self
->border_width
* 2;
534 else x
+= self
->border_width
* 2;
541 if (show
) x
-= self
->border_width
;
542 else x
+= self
->border_width
;
545 switch(self
->gravity
) {
547 case NorthWestGravity
:
549 case NorthEastGravity
:
551 case SouthWestGravity
:
553 case SouthEastGravity
:
554 if (show
) y
-= self
->border_width
* 2;
555 else y
+= self
->border_width
* 2;
562 if (show
) y
-= self
->border_width
;
563 else y
+= self
->border_width
;
570 XSetWindowBorderWidth(ob_display
, self
->window
, self
->border_width
);
572 /* move the client so it is back it the right spot _with_ its
574 if (x
!= oldx
|| y
!= oldy
)
575 XMoveWindow(ob_display
, self
->window
, x
, y
);
577 XSetWindowBorderWidth(ob_display
, self
->window
, 0);
581 static void client_get_all(ObClient
*self
)
583 /* update EVERYTHING!! */
585 self
->ignore_unmaps
= 0;
589 self
->title
= self
->icon_title
= NULL
;
590 self
->title_count
= 1;
591 self
->name
= self
->class = self
->role
= NULL
;
592 self
->wmstate
= NormalState
;
593 self
->transient
= FALSE
;
594 self
->transients
= NULL
;
595 self
->transient_for
= NULL
;
597 self
->urgent
= FALSE
;
598 self
->positioned
= FALSE
;
599 self
->decorate
= TRUE
;
603 client_get_area(self
);
604 client_update_transient_for(self
);
605 client_update_wmhints(self
);
606 client_get_desktop(self
);
607 client_get_state(self
);
608 client_get_shaped(self
);
610 client_get_mwm_hints(self
);
611 client_get_type(self
);/* this can change the mwmhints for special cases */
613 client_update_protocols(self
);
615 client_get_gravity(self
); /* get the attribute gravity */
616 client_update_normal_hints(self
); /* this may override the attribute
619 /* got the type, the mwmhints, the protocols, and the normal hints
620 (min/max sizes), so we're ready to set up the decorations/functions */
621 client_setup_decor_and_functions(self
);
623 client_update_title(self
);
624 client_update_class(self
);
625 client_update_strut(self
);
626 client_update_icons(self
);
628 client_change_state(self
);
631 static void client_get_area(ObClient
*self
)
633 XWindowAttributes wattrib
;
636 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
637 g_assert(ret
!= BadWindow
);
639 RECT_SET(self
->area
, wattrib
.x
, wattrib
.y
, wattrib
.width
, wattrib
.height
);
640 self
->border_width
= wattrib
.border_width
;
643 static void client_get_desktop(ObClient
*self
)
645 guint32 d
= screen_num_desktops
; /* an always-invalid value */
647 if (PROP_GET32(self
->window
, net_wm_desktop
, cardinal
, &d
)) {
648 if (d
>= screen_num_desktops
&& d
!= DESKTOP_ALL
)
649 self
->desktop
= screen_num_desktops
- 1;
653 gboolean trdesk
= FALSE
;
655 if (self
->transient_for
) {
656 if (self
->transient_for
!= OB_TRAN_GROUP
) {
657 self
->desktop
= self
->transient_for
->desktop
;
662 for (it
= self
->group
->members
; it
; it
= it
->next
)
663 if (it
->data
!= self
&&
664 !((ObClient
*)it
->data
)->transient_for
) {
665 self
->desktop
= ((ObClient
*)it
->data
)->desktop
;
672 /* defaults to the current desktop */
673 self
->desktop
= screen_desktop
;
676 if (self
->desktop
!= d
) {
677 /* set the desktop hint, to make sure that it always exists */
678 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, self
->desktop
);
682 static void client_get_state(ObClient
*self
)
687 self
->modal
= self
->shaded
= self
->max_horz
= self
->max_vert
=
688 self
->fullscreen
= self
->above
= self
->below
= self
->iconic
=
689 self
->skip_taskbar
= self
->skip_pager
= FALSE
;
691 if (PROP_GETA32(self
->window
, net_wm_state
, atom
, &state
, &num
)) {
693 for (i
= 0; i
< num
; ++i
) {
694 if (state
[i
] == prop_atoms
.net_wm_state_modal
)
696 else if (state
[i
] == prop_atoms
.net_wm_state_shaded
)
698 else if (state
[i
] == prop_atoms
.net_wm_state_hidden
)
700 else if (state
[i
] == prop_atoms
.net_wm_state_skip_taskbar
)
701 self
->skip_taskbar
= TRUE
;
702 else if (state
[i
] == prop_atoms
.net_wm_state_skip_pager
)
703 self
->skip_pager
= TRUE
;
704 else if (state
[i
] == prop_atoms
.net_wm_state_fullscreen
)
705 self
->fullscreen
= TRUE
;
706 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_vert
)
707 self
->max_vert
= TRUE
;
708 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_horz
)
709 self
->max_horz
= TRUE
;
710 else if (state
[i
] == prop_atoms
.net_wm_state_above
)
712 else if (state
[i
] == prop_atoms
.net_wm_state_below
)
720 static void client_get_shaped(ObClient
*self
)
722 self
->shaped
= FALSE
;
724 if (extensions_shape
) {
729 XShapeSelectInput(ob_display
, self
->window
, ShapeNotifyMask
);
731 XShapeQueryExtents(ob_display
, self
->window
, &s
, &foo
,
732 &foo
, &ufoo
, &ufoo
, &foo
, &foo
, &foo
, &ufoo
,
734 self
->shaped
= (s
!= 0);
739 void client_update_transient_for(ObClient
*self
)
742 ObClient
*target
= NULL
;
744 if (XGetTransientForHint(ob_display
, self
->window
, &t
)) {
745 self
->transient
= TRUE
;
746 if (t
!= self
->window
) { /* cant be transient to itself! */
747 target
= g_hash_table_lookup(window_map
, &t
);
748 /* if this happens then we need to check for it*/
749 g_assert(target
!= self
);
750 g_assert(!target
|| WINDOW_IS_CLIENT(target
));
752 if (!target
&& self
->group
) {
753 /* not transient to a client, see if it is transient for a
755 if (t
== self
->group
->leader
||
757 t
== RootWindow(ob_display
, ob_screen
)) {
758 /* window is a transient for its group! */
759 target
= OB_TRAN_GROUP
;
764 self
->transient
= FALSE
;
766 /* if anything has changed... */
767 if (target
!= self
->transient_for
) {
768 if (self
->transient_for
== OB_TRAN_GROUP
) { /* transient of group */
771 /* remove from old parents */
772 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
773 ObClient
*c
= it
->data
;
774 if (c
!= self
&& !c
->transient_for
)
775 c
->transients
= g_slist_remove(c
->transients
, self
);
777 } else if (self
->transient_for
!= NULL
) { /* transient of window */
778 /* remove from old parent */
779 self
->transient_for
->transients
=
780 g_slist_remove(self
->transient_for
->transients
, self
);
782 self
->transient_for
= target
;
783 if (self
->transient_for
== OB_TRAN_GROUP
) { /* transient of group */
786 /* add to new parents */
787 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
788 ObClient
*c
= it
->data
;
789 if (c
!= self
&& !c
->transient_for
)
790 c
->transients
= g_slist_append(c
->transients
, self
);
793 /* remove all transients which are in the group, that causes
794 circlular pointer hell of doom */
795 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
797 for (sit
= self
->transients
; sit
; sit
= next
) {
798 next
= g_slist_next(sit
);
799 if (sit
->data
== it
->data
)
801 g_slist_delete_link(self
->transients
, sit
);
804 } else if (self
->transient_for
!= NULL
) { /* transient of window */
805 /* add to new parent */
806 self
->transient_for
->transients
=
807 g_slist_append(self
->transient_for
->transients
, self
);
812 static void client_get_mwm_hints(ObClient
*self
)
817 self
->mwmhints
.flags
= 0; /* default to none */
819 if (PROP_GETA32(self
->window
, motif_wm_hints
, motif_wm_hints
,
821 if (num
>= OB_MWM_ELEMENTS
) {
822 self
->mwmhints
.flags
= hints
[0];
823 self
->mwmhints
.functions
= hints
[1];
824 self
->mwmhints
.decorations
= hints
[2];
830 void client_get_type(ObClient
*self
)
837 if (PROP_GETA32(self
->window
, net_wm_window_type
, atom
, &val
, &num
)) {
838 /* use the first value that we know about in the array */
839 for (i
= 0; i
< num
; ++i
) {
840 if (val
[i
] == prop_atoms
.net_wm_window_type_desktop
)
841 self
->type
= OB_CLIENT_TYPE_DESKTOP
;
842 else if (val
[i
] == prop_atoms
.net_wm_window_type_dock
)
843 self
->type
= OB_CLIENT_TYPE_DOCK
;
844 else if (val
[i
] == prop_atoms
.net_wm_window_type_toolbar
)
845 self
->type
= OB_CLIENT_TYPE_TOOLBAR
;
846 else if (val
[i
] == prop_atoms
.net_wm_window_type_menu
)
847 self
->type
= OB_CLIENT_TYPE_MENU
;
848 else if (val
[i
] == prop_atoms
.net_wm_window_type_utility
)
849 self
->type
= OB_CLIENT_TYPE_UTILITY
;
850 else if (val
[i
] == prop_atoms
.net_wm_window_type_splash
)
851 self
->type
= OB_CLIENT_TYPE_SPLASH
;
852 else if (val
[i
] == prop_atoms
.net_wm_window_type_dialog
)
853 self
->type
= OB_CLIENT_TYPE_DIALOG
;
854 else if (val
[i
] == prop_atoms
.net_wm_window_type_normal
)
855 self
->type
= OB_CLIENT_TYPE_NORMAL
;
856 else if (val
[i
] == prop_atoms
.kde_net_wm_window_type_override
) {
857 /* prevent this window from getting any decor or
859 self
->mwmhints
.flags
&= (OB_MWM_FLAG_FUNCTIONS
|
860 OB_MWM_FLAG_DECORATIONS
);
861 self
->mwmhints
.decorations
= 0;
862 self
->mwmhints
.functions
= 0;
864 if (self
->type
!= (ObClientType
) -1)
865 break; /* grab the first legit type */
870 if (self
->type
== (ObClientType
) -1) {
871 /*the window type hint was not set, which means we either classify
872 ourself as a normal window or a dialog, depending on if we are a
875 self
->type
= OB_CLIENT_TYPE_DIALOG
;
877 self
->type
= OB_CLIENT_TYPE_NORMAL
;
881 void client_update_protocols(ObClient
*self
)
886 self
->focus_notify
= FALSE
;
887 self
->delete_window
= FALSE
;
889 if (PROP_GETA32(self
->window
, wm_protocols
, atom
, &proto
, &num_return
)) {
890 for (i
= 0; i
< num_return
; ++i
) {
891 if (proto
[i
] == prop_atoms
.wm_delete_window
) {
892 /* this means we can request the window to close */
893 self
->delete_window
= TRUE
;
894 } else if (proto
[i
] == prop_atoms
.wm_take_focus
)
895 /* if this protocol is requested, then the window will be
896 notified whenever we want it to receive focus */
897 self
->focus_notify
= TRUE
;
903 static void client_get_gravity(ObClient
*self
)
905 XWindowAttributes wattrib
;
908 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
909 g_assert(ret
!= BadWindow
);
910 self
->gravity
= wattrib
.win_gravity
;
913 void client_update_normal_hints(ObClient
*self
)
917 int oldgravity
= self
->gravity
;
920 self
->min_ratio
= 0.0f
;
921 self
->max_ratio
= 0.0f
;
922 SIZE_SET(self
->size_inc
, 1, 1);
923 SIZE_SET(self
->base_size
, 0, 0);
924 SIZE_SET(self
->min_size
, 0, 0);
925 SIZE_SET(self
->max_size
, G_MAXINT
, G_MAXINT
);
927 /* get the hints from the window */
928 if (XGetWMNormalHints(ob_display
, self
->window
, &size
, &ret
)) {
929 self
->positioned
= !!(size
.flags
& (PPosition
|USPosition
));
931 if (size
.flags
& PWinGravity
) {
932 self
->gravity
= size
.win_gravity
;
934 /* if the client has a frame, i.e. has already been mapped and
935 is changing its gravity */
936 if (self
->frame
&& self
->gravity
!= oldgravity
) {
937 /* move our idea of the client's position based on its new
939 self
->area
.x
= self
->frame
->area
.x
;
940 self
->area
.y
= self
->frame
->area
.y
;
941 frame_frame_gravity(self
->frame
, &self
->area
.x
, &self
->area
.y
);
945 if (size
.flags
& PAspect
) {
946 if (size
.min_aspect
.y
)
947 self
->min_ratio
= (float)size
.min_aspect
.x
/ size
.min_aspect
.y
;
948 if (size
.max_aspect
.y
)
949 self
->max_ratio
= (float)size
.max_aspect
.x
/ size
.max_aspect
.y
;
952 if (size
.flags
& PMinSize
)
953 SIZE_SET(self
->min_size
, size
.min_width
, size
.min_height
);
955 if (size
.flags
& PMaxSize
)
956 SIZE_SET(self
->max_size
, size
.max_width
, size
.max_height
);
958 if (size
.flags
& PBaseSize
)
959 SIZE_SET(self
->base_size
, size
.base_width
, size
.base_height
);
961 if (size
.flags
& PResizeInc
)
962 SIZE_SET(self
->size_inc
, size
.width_inc
, size
.height_inc
);
966 void client_setup_decor_and_functions(ObClient
*self
)
968 /* start with everything (cept fullscreen) */
969 self
->decorations
= (OB_FRAME_DECOR_TITLEBAR
|
970 OB_FRAME_DECOR_HANDLE
|
971 OB_FRAME_DECOR_GRIPS
|
972 OB_FRAME_DECOR_BORDER
|
973 OB_FRAME_DECOR_ICON
|
974 OB_FRAME_DECOR_ALLDESKTOPS
|
975 OB_FRAME_DECOR_ICONIFY
|
976 OB_FRAME_DECOR_MAXIMIZE
|
977 OB_FRAME_DECOR_SHADE
);
978 self
->functions
= (OB_CLIENT_FUNC_RESIZE
|
979 OB_CLIENT_FUNC_MOVE
|
980 OB_CLIENT_FUNC_ICONIFY
|
981 OB_CLIENT_FUNC_MAXIMIZE
|
982 OB_CLIENT_FUNC_SHADE
);
983 if (self
->delete_window
) {
984 self
->functions
|= OB_CLIENT_FUNC_CLOSE
;
985 self
->decorations
|= OB_FRAME_DECOR_CLOSE
;
988 if (!(self
->min_size
.width
< self
->max_size
.width
||
989 self
->min_size
.height
< self
->max_size
.height
))
990 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
992 switch (self
->type
) {
993 case OB_CLIENT_TYPE_NORMAL
:
994 /* normal windows retain all of the possible decorations and
995 functionality, and are the only windows that you can fullscreen */
996 self
->functions
|= OB_CLIENT_FUNC_FULLSCREEN
;
999 case OB_CLIENT_TYPE_DIALOG
:
1000 case OB_CLIENT_TYPE_UTILITY
:
1001 /* these windows cannot be maximized */
1002 self
->functions
&= ~OB_CLIENT_FUNC_MAXIMIZE
;
1005 case OB_CLIENT_TYPE_MENU
:
1006 case OB_CLIENT_TYPE_TOOLBAR
:
1007 /* these windows get less functionality */
1008 self
->functions
&= ~(OB_CLIENT_FUNC_ICONIFY
| OB_CLIENT_FUNC_RESIZE
);
1011 case OB_CLIENT_TYPE_DESKTOP
:
1012 case OB_CLIENT_TYPE_DOCK
:
1013 case OB_CLIENT_TYPE_SPLASH
:
1014 /* none of these windows are manipulated by the window manager */
1015 self
->decorations
= 0;
1016 self
->functions
= 0;
1020 /* Mwm Hints are applied subtractively to what has already been chosen for
1021 decor and functionality */
1022 if (self
->mwmhints
.flags
& OB_MWM_FLAG_DECORATIONS
) {
1023 if (! (self
->mwmhints
.decorations
& OB_MWM_DECOR_ALL
)) {
1024 if (! ((self
->mwmhints
.decorations
& OB_MWM_DECOR_HANDLE
) ||
1025 (self
->mwmhints
.decorations
& OB_MWM_DECOR_TITLE
)))
1026 /* if the mwm hints request no handle or title, then all
1027 decorations are disabled */
1028 self
->decorations
= 0;
1032 if (self
->mwmhints
.flags
& OB_MWM_FLAG_FUNCTIONS
) {
1033 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_ALL
)) {
1034 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_RESIZE
))
1035 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
1036 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_MOVE
))
1037 self
->functions
&= ~OB_CLIENT_FUNC_MOVE
;
1038 /* dont let mwm hints kill any buttons
1039 if (! (self->mwmhints.functions & OB_MWM_FUNC_ICONIFY))
1040 self->functions &= ~OB_CLIENT_FUNC_ICONIFY;
1041 if (! (self->mwmhints.functions & OB_MWM_FUNC_MAXIMIZE))
1042 self->functions &= ~OB_CLIENT_FUNC_MAXIMIZE;
1044 /* dont let mwm hints kill the close button
1045 if (! (self->mwmhints.functions & MwmFunc_Close))
1046 self->functions &= ~OB_CLIENT_FUNC_CLOSE; */
1050 if (!(self
->functions
& OB_CLIENT_FUNC_SHADE
))
1051 self
->decorations
&= ~OB_FRAME_DECOR_SHADE
;
1052 if (!(self
->functions
& OB_CLIENT_FUNC_ICONIFY
))
1053 self
->decorations
&= ~OB_FRAME_DECOR_ICONIFY
;
1054 if (!(self
->functions
& OB_CLIENT_FUNC_RESIZE
))
1055 self
->decorations
&= ~OB_FRAME_DECOR_GRIPS
;
1057 /* can't maximize without moving/resizing */
1058 if (!((self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) &&
1059 (self
->functions
& OB_CLIENT_FUNC_MOVE
) &&
1060 (self
->functions
& OB_CLIENT_FUNC_RESIZE
))) {
1061 self
->functions
&= ~OB_CLIENT_FUNC_MAXIMIZE
;
1062 self
->decorations
&= ~OB_FRAME_DECOR_MAXIMIZE
;
1065 /* finally, the user can have requested no decorations, which overrides
1067 if (!self
->decorate
)
1068 self
->decorations
= 0;
1070 /* if we don't have a titlebar, then we cannot shade! */
1071 if (!(self
->decorations
& OB_FRAME_DECOR_TITLEBAR
))
1072 self
->functions
&= ~OB_CLIENT_FUNC_SHADE
;
1074 /* now we need to check against rules for the client's current state */
1075 if (self
->fullscreen
) {
1076 self
->functions
&= (OB_CLIENT_FUNC_CLOSE
|
1077 OB_CLIENT_FUNC_FULLSCREEN
|
1078 OB_CLIENT_FUNC_ICONIFY
);
1079 self
->decorations
= 0;
1082 client_change_allowed_actions(self
);
1085 /* this makes sure that these windows appear on all desktops */
1086 if (self
->type
== OB_CLIENT_TYPE_DESKTOP
&&
1087 self
->desktop
!= DESKTOP_ALL
)
1088 client_set_desktop(self
, DESKTOP_ALL
, FALSE
);
1090 /* adjust the client's decorations, etc. */
1091 client_reconfigure(self
);
1093 /* this makes sure that these windows appear on all desktops */
1094 if (self
->type
== OB_CLIENT_TYPE_DESKTOP
&&
1095 self
->desktop
!= DESKTOP_ALL
)
1097 self
->desktop
= DESKTOP_ALL
;
1102 static void client_change_allowed_actions(ObClient
*self
)
1107 /* desktop windows are kept on all desktops */
1108 if (self
->type
!= OB_CLIENT_TYPE_DESKTOP
)
1109 actions
[num
++] = prop_atoms
.net_wm_action_change_desktop
;
1111 if (self
->functions
& OB_CLIENT_FUNC_SHADE
)
1112 actions
[num
++] = prop_atoms
.net_wm_action_shade
;
1113 if (self
->functions
& OB_CLIENT_FUNC_CLOSE
)
1114 actions
[num
++] = prop_atoms
.net_wm_action_close
;
1115 if (self
->functions
& OB_CLIENT_FUNC_MOVE
)
1116 actions
[num
++] = prop_atoms
.net_wm_action_move
;
1117 if (self
->functions
& OB_CLIENT_FUNC_ICONIFY
)
1118 actions
[num
++] = prop_atoms
.net_wm_action_minimize
;
1119 if (self
->functions
& OB_CLIENT_FUNC_RESIZE
)
1120 actions
[num
++] = prop_atoms
.net_wm_action_resize
;
1121 if (self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
)
1122 actions
[num
++] = prop_atoms
.net_wm_action_fullscreen
;
1123 if (self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) {
1124 actions
[num
++] = prop_atoms
.net_wm_action_maximize_horz
;
1125 actions
[num
++] = prop_atoms
.net_wm_action_maximize_vert
;
1128 PROP_SETA32(self
->window
, net_wm_allowed_actions
, atom
, actions
, num
);
1130 /* make sure the window isn't breaking any rules now */
1132 if (!(self
->functions
& OB_CLIENT_FUNC_SHADE
) && self
->shaded
) {
1133 if (self
->frame
) client_shade(self
, FALSE
);
1134 else self
->shaded
= FALSE
;
1136 if (!(self
->functions
& OB_CLIENT_FUNC_ICONIFY
) && self
->iconic
) {
1137 if (self
->frame
) client_iconify(self
, FALSE
, TRUE
);
1138 else self
->iconic
= FALSE
;
1140 if (!(self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
) && self
->fullscreen
) {
1141 if (self
->frame
) client_fullscreen(self
, FALSE
, TRUE
);
1142 else self
->fullscreen
= FALSE
;
1144 if (!(self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) && (self
->max_horz
||
1146 if (self
->frame
) client_maximize(self
, FALSE
, 0, TRUE
);
1147 else self
->max_vert
= self
->max_horz
= FALSE
;
1151 void client_reconfigure(ObClient
*self
)
1153 /* by making this pass FALSE for user, we avoid the emacs event storm where
1154 every configurenotify causes an update in its normal hints, i think this
1155 is generally what we want anyways... */
1156 client_configure(self
, OB_CORNER_TOPLEFT
, self
->area
.x
, self
->area
.y
,
1157 self
->area
.width
, self
->area
.height
, FALSE
, TRUE
);
1160 void client_update_wmhints(ObClient
*self
)
1163 gboolean ur
= FALSE
;
1166 /* assume a window takes input if it doesnt specify */
1167 self
->can_focus
= TRUE
;
1169 if ((hints
= XGetWMHints(ob_display
, self
->window
)) != NULL
) {
1170 if (hints
->flags
& InputHint
)
1171 self
->can_focus
= hints
->input
;
1173 /* only do this when first managing the window *AND* when we aren't
1175 if (ob_state() != OB_STATE_STARTING
&& self
->frame
== NULL
)
1176 if (hints
->flags
& StateHint
)
1177 self
->iconic
= hints
->initial_state
== IconicState
;
1179 if (hints
->flags
& XUrgencyHint
)
1182 if (!(hints
->flags
& WindowGroupHint
))
1183 hints
->window_group
= None
;
1185 /* did the group state change? */
1186 if (hints
->window_group
!=
1187 (self
->group
? self
->group
->leader
: None
)) {
1188 /* remove from the old group if there was one */
1189 if (self
->group
!= NULL
) {
1190 /* remove transients of the group */
1191 for (it
= self
->group
->members
; it
; it
= it
->next
)
1192 self
->transients
= g_slist_remove(self
->transients
,
1194 group_remove(self
->group
, self
);
1197 if (hints
->window_group
!= None
) {
1198 self
->group
= group_add(hints
->window_group
, self
);
1200 /* i can only have transients from the group if i am not
1202 if (!self
->transient_for
) {
1203 /* add other transients of the group that are already
1205 for (it
= self
->group
->members
; it
; it
= it
->next
) {
1206 ObClient
*c
= it
->data
;
1207 if (c
!= self
&& c
->transient_for
== OB_TRAN_GROUP
)
1209 g_slist_append(self
->transients
, c
);
1214 /* the WM_HINTS can contain an icon */
1215 client_update_icons(self
);
1217 /* because the self->transient flag wont change from this call,
1218 we don't need to update the window's type and such, only its
1219 transient_for, and the transients lists of other windows in
1220 the group may be affected */
1221 client_update_transient_for(self
);
1227 if (ur
!= self
->urgent
) {
1229 ob_debug("Urgent Hint for 0x%lx: %s\n", self
->window
,
1231 /* fire the urgent callback if we're mapped, otherwise, wait until
1232 after we're mapped */
1234 dispatch_client(Event_Client_Urgent
, self
, self
->urgent
, 0);
1238 void client_update_title(ObClient
*self
)
1244 gboolean read_title
;
1246 g_free(self
->title
);
1249 if (!PROP_GETS(self
->window
, net_wm_name
, utf8
, &data
))
1250 /* try old x stuff */
1251 if (!PROP_GETS(self
->window
, wm_name
, locale
, &data
))
1252 data
= g_strdup("Unnamed Window");
1254 /* look for duplicates and append a number */
1256 for (it
= client_list
; it
; it
= it
->next
)
1257 if (it
->data
!= self
) {
1258 ObClient
*c
= it
->data
;
1259 if (0 == strncmp(c
->title
, data
, strlen(data
)))
1260 nums
|= 1 << c
->title_count
;
1262 /* find first free number */
1263 for (i
= 1; i
<= 32; ++i
)
1264 if (!(nums
& (1 << i
))) {
1265 if (self
->title_count
== 1 || i
== 1)
1266 self
->title_count
= i
;
1269 /* dont display the number for the first window */
1270 if (self
->title_count
> 1) {
1271 char *vdata
, *ndata
;
1272 ndata
= g_strdup_printf(" - [%u]", self
->title_count
);
1273 vdata
= g_strconcat(data
, ndata
, NULL
);
1279 PROP_SETS(self
->window
, net_wm_visible_name
, data
);
1284 frame_adjust_title(self
->frame
);
1286 /* update the icon title */
1288 g_free(self
->icon_title
);
1292 if (!PROP_GETS(self
->window
, net_wm_icon_name
, utf8
, &data
))
1293 /* try old x stuff */
1294 if (!PROP_GETS(self
->window
, wm_icon_name
, locale
, &data
)) {
1295 data
= g_strdup(self
->title
);
1299 /* append the title count, dont display the number for the first window */
1300 if (read_title
&& self
->title_count
> 1) {
1301 char *vdata
, *ndata
;
1302 ndata
= g_strdup_printf(" - [%u]", self
->title_count
);
1303 vdata
= g_strconcat(data
, ndata
, NULL
);
1309 PROP_SETS(self
->window
, net_wm_visible_icon_name
, data
);
1311 self
->icon_title
= data
;
1314 void client_update_class(ObClient
*self
)
1319 if (self
->name
) g_free(self
->name
);
1320 if (self
->class) g_free(self
->class);
1321 if (self
->role
) g_free(self
->role
);
1323 self
->name
= self
->class = self
->role
= NULL
;
1325 if (PROP_GETSS(self
->window
, wm_class
, locale
, &data
)) {
1327 self
->name
= g_strdup(data
[0]);
1329 self
->class = g_strdup(data
[1]);
1334 if (PROP_GETS(self
->window
, wm_window_role
, locale
, &s
))
1335 self
->role
= g_strdup(s
);
1337 if (self
->name
== NULL
) self
->name
= g_strdup("");
1338 if (self
->class == NULL
) self
->class = g_strdup("");
1339 if (self
->role
== NULL
) self
->role
= g_strdup("");
1342 void client_update_strut(ObClient
*self
)
1347 if (!PROP_GETA32(self
->window
, net_wm_strut
, cardinal
, &data
, &num
)) {
1348 STRUT_SET(self
->strut
, 0, 0, 0, 0);
1351 STRUT_SET(self
->strut
, data
[0], data
[2], data
[1], data
[3]);
1353 STRUT_SET(self
->strut
, 0, 0, 0, 0);
1357 /* updating here is pointless while we're being mapped cuz we're not in
1358 the client list yet */
1360 screen_update_areas();
1363 void client_update_icons(ObClient
*self
)
1369 for (i
= 0; i
< self
->nicons
; ++i
)
1370 g_free(self
->icons
[i
].data
);
1371 if (self
->nicons
> 0)
1372 g_free(self
->icons
);
1375 if (PROP_GETA32(self
->window
, net_wm_icon
, cardinal
, &data
, &num
)) {
1376 /* figure out how many valid icons are in here */
1378 while (num
- i
> 2) {
1382 if (i
> num
|| w
*h
== 0) break;
1386 self
->icons
= g_new(ObClientIcon
, self
->nicons
);
1388 /* store the icons */
1390 for (j
= 0; j
< self
->nicons
; ++j
) {
1393 w
= self
->icons
[j
].width
= data
[i
++];
1394 h
= self
->icons
[j
].height
= data
[i
++];
1396 if (w
*h
== 0) continue;
1398 self
->icons
[j
].data
= g_new(RrPixel32
, w
* h
);
1399 for (x
= 0, y
= 0, t
= 0; t
< w
* h
; ++t
, ++x
, ++i
) {
1404 self
->icons
[j
].data
[t
] =
1405 (((data
[i
] >> 24) & 0xff) << RrDefaultAlphaOffset
) +
1406 (((data
[i
] >> 16) & 0xff) << RrDefaultRedOffset
) +
1407 (((data
[i
] >> 8) & 0xff) << RrDefaultGreenOffset
) +
1408 (((data
[i
] >> 0) & 0xff) << RrDefaultBlueOffset
);
1414 } else if (PROP_GETA32(self
->window
, kwm_win_icon
,
1415 kwm_win_icon
, &data
, &num
)) {
1418 self
->icons
= g_new(ObClientIcon
, self
->nicons
);
1419 xerror_set_ignore(TRUE
);
1420 if (!RrPixmapToRGBA(ob_rr_inst
,
1422 &self
->icons
[self
->nicons
-1].width
,
1423 &self
->icons
[self
->nicons
-1].height
,
1424 &self
->icons
[self
->nicons
-1].data
)) {
1425 g_free(&self
->icons
[self
->nicons
-1]);
1428 xerror_set_ignore(FALSE
);
1434 if ((hints
= XGetWMHints(ob_display
, self
->window
))) {
1435 if (hints
->flags
& IconPixmapHint
) {
1437 self
->icons
= g_new(ObClientIcon
, self
->nicons
);
1438 xerror_set_ignore(TRUE
);
1439 if (!RrPixmapToRGBA(ob_rr_inst
,
1441 (hints
->flags
& IconMaskHint
?
1442 hints
->icon_mask
: None
),
1443 &self
->icons
[self
->nicons
-1].width
,
1444 &self
->icons
[self
->nicons
-1].height
,
1445 &self
->icons
[self
->nicons
-1].data
)){
1446 g_free(&self
->icons
[self
->nicons
-1]);
1449 xerror_set_ignore(FALSE
);
1456 frame_adjust_icon(self
->frame
);
1459 static void client_change_state(ObClient
*self
)
1462 guint32 netstate
[10];
1465 state
[0] = self
->wmstate
;
1467 PROP_SETA32(self
->window
, wm_state
, wm_state
, state
, 2);
1471 netstate
[num
++] = prop_atoms
.net_wm_state_modal
;
1473 netstate
[num
++] = prop_atoms
.net_wm_state_shaded
;
1475 netstate
[num
++] = prop_atoms
.net_wm_state_hidden
;
1476 if (self
->skip_taskbar
)
1477 netstate
[num
++] = prop_atoms
.net_wm_state_skip_taskbar
;
1478 if (self
->skip_pager
)
1479 netstate
[num
++] = prop_atoms
.net_wm_state_skip_pager
;
1480 if (self
->fullscreen
)
1481 netstate
[num
++] = prop_atoms
.net_wm_state_fullscreen
;
1483 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_vert
;
1485 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_horz
;
1487 netstate
[num
++] = prop_atoms
.net_wm_state_above
;
1489 netstate
[num
++] = prop_atoms
.net_wm_state_below
;
1490 PROP_SETA32(self
->window
, net_wm_state
, atom
, netstate
, num
);
1492 client_calc_layer(self
);
1495 frame_adjust_state(self
->frame
);
1498 ObClient
*client_search_focus_tree(ObClient
*self
)
1503 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
) {
1504 if (client_focused(it
->data
)) return it
->data
;
1505 if ((ret
= client_search_focus_tree(it
->data
))) return ret
;
1510 ObClient
*client_search_focus_tree_full(ObClient
*self
)
1512 if (self
->transient_for
) {
1513 if (self
->transient_for
!= OB_TRAN_GROUP
) {
1514 return client_search_focus_tree_full(self
->transient_for
);
1517 gboolean recursed
= FALSE
;
1519 for (it
= self
->group
->members
; it
; it
= it
->next
)
1520 if (!((ObClient
*)it
->data
)->transient_for
) {
1522 if ((c
= client_search_focus_tree_full(it
->data
)))
1531 /* this function checks the whole tree, the client_search_focus_tree~
1532 does not, so we need to check this window */
1533 if (client_focused(self
))
1535 return client_search_focus_tree(self
);
1538 static ObStackingLayer
calc_layer(ObClient
*self
)
1542 if (self
->fullscreen
) l
= OB_STACKING_LAYER_FULLSCREEN
;
1543 else if (self
->type
== OB_CLIENT_TYPE_DESKTOP
)
1544 l
= OB_STACKING_LAYER_DESKTOP
;
1545 else if (self
->type
== OB_CLIENT_TYPE_DOCK
) {
1546 if (!self
->below
) l
= OB_STACKING_LAYER_TOP
;
1547 else l
= OB_STACKING_LAYER_NORMAL
;
1549 else if (self
->above
) l
= OB_STACKING_LAYER_ABOVE
;
1550 else if (self
->below
) l
= OB_STACKING_LAYER_BELOW
;
1551 else l
= OB_STACKING_LAYER_NORMAL
;
1556 static void client_calc_layer_recursive(ObClient
*self
, ObClient
*orig
,
1557 ObStackingLayer l
, gboolean raised
)
1559 ObStackingLayer old
, own
;
1563 own
= calc_layer(self
);
1564 self
->layer
= l
> own
? l
: own
;
1566 for (it
= self
->transients
; it
; it
= it
->next
)
1567 client_calc_layer_recursive(it
->data
, orig
,
1568 l
, raised
? raised
: l
!= old
);
1570 if (!raised
&& l
!= old
)
1571 if (orig
->frame
) { /* only restack if the original window is managed */
1572 /* XXX add_non_intrusive ever? */
1573 stacking_remove(CLIENT_AS_WINDOW(self
));
1574 stacking_add(CLIENT_AS_WINDOW(self
));
1578 void client_calc_layer(ObClient
*self
)
1585 /* transients take on the layer of their parents */
1586 self
= client_search_top_transient(self
);
1588 l
= calc_layer(self
);
1590 client_calc_layer_recursive(self
, orig
, l
, FALSE
);
1593 gboolean
client_should_show(ObClient
*self
)
1595 if (self
->iconic
) return FALSE
;
1596 else if (!(self
->desktop
== screen_desktop
||
1597 self
->desktop
== DESKTOP_ALL
)) return FALSE
;
1598 else if (client_normal(self
) && screen_showing_desktop
) return FALSE
;
1603 static void client_showhide(ObClient
*self
)
1606 if (client_should_show(self
))
1607 frame_show(self
->frame
);
1609 frame_hide(self
->frame
);
1612 gboolean
client_normal(ObClient
*self
) {
1613 return ! (self
->type
== OB_CLIENT_TYPE_DESKTOP
||
1614 self
->type
== OB_CLIENT_TYPE_DOCK
||
1615 self
->type
== OB_CLIENT_TYPE_SPLASH
);
1618 static void client_apply_startup_state(ObClient
*self
)
1620 /* these are in a carefully crafted order.. */
1623 self
->iconic
= FALSE
;
1624 client_iconify(self
, TRUE
, FALSE
);
1626 if (self
->fullscreen
) {
1627 self
->fullscreen
= FALSE
;
1628 client_fullscreen(self
, TRUE
, FALSE
);
1631 self
->shaded
= FALSE
;
1632 client_shade(self
, TRUE
);
1635 dispatch_client(Event_Client_Urgent
, self
, self
->urgent
, 0);
1637 if (self
->max_vert
&& self
->max_horz
) {
1638 self
->max_vert
= self
->max_horz
= FALSE
;
1639 client_maximize(self
, TRUE
, 0, FALSE
);
1640 } else if (self
->max_vert
) {
1641 self
->max_vert
= FALSE
;
1642 client_maximize(self
, TRUE
, 2, FALSE
);
1643 } else if (self
->max_horz
) {
1644 self
->max_horz
= FALSE
;
1645 client_maximize(self
, TRUE
, 1, FALSE
);
1648 /* nothing to do for the other states:
1657 void client_configure_full(ObClient
*self
, ObCorner anchor
,
1658 int x
, int y
, int w
, int h
,
1659 gboolean user
, gboolean final
,
1660 gboolean force_reply
)
1662 gboolean moved
= FALSE
, resized
= FALSE
;
1664 /* gets the frame's position */
1665 frame_client_gravity(self
->frame
, &x
, &y
);
1667 /* these positions are frame positions, not client positions */
1669 /* set the size and position if fullscreen */
1670 if (self
->fullscreen
) {
1673 XF86VidModeModeLine mode
;
1678 i
= client_monitor(self
);
1679 a
= screen_physical_area_monitor(i
);
1682 if (i
== 0 && /* primary head */
1683 extensions_vidmode
&&
1684 XF86VidModeGetViewPort(ob_display
, ob_screen
, &x
, &y
) &&
1685 /* get the mode last so the mode.privsize isnt freed incorrectly */
1686 XF86VidModeGetModeLine(ob_display
, ob_screen
, &dot
, &mode
)) {
1691 if (mode
.privsize
) XFree(mode
.private);
1701 user
= FALSE
; /* ignore that increment etc shit when in fullscreen */
1705 a
= screen_area_monitor(self
->desktop
, client_monitor(self
));
1707 /* set the size and position if maximized */
1708 if (self
->max_horz
) {
1709 x
= a
->x
- self
->frame
->size
.left
;
1712 if (self
->max_vert
) {
1714 h
= a
->height
- self
->frame
->size
.top
- self
->frame
->size
.bottom
;
1718 /* gets the client's position */
1719 frame_frame_gravity(self
->frame
, &x
, &y
);
1721 /* these override the above states! if you cant move you can't move! */
1723 if (!(self
->functions
& OB_CLIENT_FUNC_MOVE
)) {
1727 if (!(self
->functions
& OB_CLIENT_FUNC_RESIZE
)) {
1728 w
= self
->area
.width
;
1729 h
= self
->area
.height
;
1733 if (!(w
== self
->area
.width
&& h
== self
->area
.height
)) {
1734 int basew
, baseh
, minw
, minh
;
1736 /* base size is substituted with min size if not specified */
1737 if (self
->base_size
.width
|| self
->base_size
.height
) {
1738 basew
= self
->base_size
.width
;
1739 baseh
= self
->base_size
.height
;
1741 basew
= self
->min_size
.width
;
1742 baseh
= self
->min_size
.height
;
1744 /* min size is substituted with base size if not specified */
1745 if (self
->min_size
.width
|| self
->min_size
.height
) {
1746 minw
= self
->min_size
.width
;
1747 minh
= self
->min_size
.height
;
1749 minw
= self
->base_size
.width
;
1750 minh
= self
->base_size
.height
;
1754 /* for interactive resizing. have to move half an increment in each
1757 /* how far we are towards the next size inc */
1758 int mw
= (w
- basew
) % self
->size_inc
.width
;
1759 int mh
= (h
- baseh
) % self
->size_inc
.height
;
1761 int aw
= self
->size_inc
.width
/ 2;
1762 int ah
= self
->size_inc
.height
/ 2;
1763 /* don't let us move into a new size increment */
1764 if (mw
+ aw
>= self
->size_inc
.width
)
1765 aw
= self
->size_inc
.width
- mw
- 1;
1766 if (mh
+ ah
>= self
->size_inc
.height
)
1767 ah
= self
->size_inc
.height
- mh
- 1;
1771 /* if this is a user-requested resize, then check against min/max
1774 /* smaller than min size or bigger than max size? */
1775 if (w
> self
->max_size
.width
) w
= self
->max_size
.width
;
1776 if (w
< minw
) w
= minw
;
1777 if (h
> self
->max_size
.height
) h
= self
->max_size
.height
;
1778 if (h
< minh
) h
= minh
;
1784 /* keep to the increments */
1785 w
/= self
->size_inc
.width
;
1786 h
/= self
->size_inc
.height
;
1788 /* you cannot resize to nothing */
1792 /* store the logical size */
1793 SIZE_SET(self
->logical_size
, w
, h
);
1795 w
*= self
->size_inc
.width
;
1796 h
*= self
->size_inc
.height
;
1802 /* adjust the height to match the width for the aspect ratios.
1803 for this, min size is not substituted for base size ever. */
1804 w
-= self
->base_size
.width
;
1805 h
-= self
->base_size
.height
;
1807 if (self
->min_ratio
)
1808 if (h
* self
->min_ratio
> w
) h
= (int)(w
/ self
->min_ratio
);
1809 if (self
->max_ratio
)
1810 if (h
* self
->max_ratio
< w
) h
= (int)(w
/ self
->max_ratio
);
1812 w
+= self
->base_size
.width
;
1813 h
+= self
->base_size
.height
;
1818 case OB_CORNER_TOPLEFT
:
1820 case OB_CORNER_TOPRIGHT
:
1821 x
-= w
- self
->area
.width
;
1823 case OB_CORNER_BOTTOMLEFT
:
1824 y
-= h
- self
->area
.height
;
1826 case OB_CORNER_BOTTOMRIGHT
:
1827 x
-= w
- self
->area
.width
;
1828 y
-= h
- self
->area
.height
;
1832 moved
= x
!= self
->area
.x
|| y
!= self
->area
.y
;
1833 resized
= w
!= self
->area
.width
|| h
!= self
->area
.height
;
1835 RECT_SET(self
->area
, x
, y
, w
, h
);
1837 /* for app-requested resizes, always resize if 'resized' is true.
1838 for user-requested ones, only resize if final is true, or when
1839 resizing in opaque mode */
1840 if ((!user
&& resized
) ||
1841 (user
&& (final
|| (resized
&& config_opaque_resize
))))
1842 XResizeWindow(ob_display
, self
->window
, w
, h
);
1844 /* move/resize the frame to match the request */
1846 if (self
->decorations
!= self
->frame
->decorations
)
1847 moved
= resized
= TRUE
;
1849 if (moved
|| resized
)
1850 frame_adjust_area(self
->frame
, moved
, resized
);
1852 if (force_reply
|| (!resized
&& ((!user
&& moved
) || (user
&& final
))))
1855 event
.type
= ConfigureNotify
;
1856 event
.xconfigure
.display
= ob_display
;
1857 event
.xconfigure
.event
= self
->window
;
1858 event
.xconfigure
.window
= self
->window
;
1860 /* root window real coords */
1861 event
.xconfigure
.x
= self
->frame
->area
.x
+ self
->frame
->size
.left
-
1863 event
.xconfigure
.y
= self
->frame
->area
.y
+ self
->frame
->size
.top
-
1866 event
.xconfigure
.width
= w
;
1867 event
.xconfigure
.height
= h
;
1868 event
.xconfigure
.border_width
= 0;
1869 event
.xconfigure
.above
= self
->frame
->plate
;
1870 event
.xconfigure
.override_redirect
= FALSE
;
1871 XSendEvent(event
.xconfigure
.display
, event
.xconfigure
.window
,
1872 FALSE
, StructureNotifyMask
, &event
);
1877 void client_fullscreen(ObClient
*self
, gboolean fs
, gboolean savearea
)
1881 if (!(self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
) || /* can't */
1882 self
->fullscreen
== fs
) return; /* already done */
1884 self
->fullscreen
= fs
;
1885 client_change_state(self
); /* change the state hints on the client,
1886 and adjust out layer/stacking */
1890 guint32 dimensions
[4];
1891 dimensions
[0] = self
->area
.x
;
1892 dimensions
[1] = self
->area
.y
;
1893 dimensions
[2] = self
->area
.width
;
1894 dimensions
[3] = self
->area
.height
;
1896 PROP_SETA32(self
->window
, openbox_premax
, cardinal
,
1900 /* these are not actually used cuz client_configure will set them
1901 as appropriate when the window is fullscreened */
1908 /* pick some fallbacks... */
1909 a
= screen_area_monitor(self
->desktop
, 0);
1910 x
= a
->x
+ a
->width
/ 4;
1911 y
= a
->y
+ a
->height
/ 4;
1915 if (PROP_GETA32(self
->window
, openbox_premax
, cardinal
,
1916 (guint32
**)&dimensions
, &num
)) {
1927 client_setup_decor_and_functions(self
);
1929 client_configure(self
, OB_CORNER_TOPLEFT
, x
, y
, w
, h
, TRUE
, TRUE
);
1931 /* try focus us when we go into fullscreen mode */
1935 static void client_iconify_recursive(ObClient
*self
,
1936 gboolean iconic
, gboolean curdesk
)
1939 gboolean changed
= FALSE
;
1942 if (self
->iconic
!= iconic
) {
1943 ob_debug("%sconifying window: 0x%lx\n", (iconic
? "I" : "Uni"),
1946 self
->iconic
= iconic
;
1949 if (self
->functions
& OB_CLIENT_FUNC_ICONIFY
) {
1950 self
->wmstate
= IconicState
;
1951 self
->ignore_unmaps
++;
1952 /* we unmap the client itself so that we can get MapRequest
1953 events, and because the ICCCM tells us to! */
1954 XUnmapWindow(ob_display
, self
->window
);
1956 /* update the focus lists.. iconic windows go to the bottom of
1957 the list, put the new iconic window at the 'top of the
1959 focus_order_to_top(self
);
1965 client_set_desktop(self
, screen_desktop
, FALSE
);
1966 self
->wmstate
= self
->shaded
? IconicState
: NormalState
;
1967 XMapWindow(ob_display
, self
->window
);
1969 /* this puts it after the current focused window */
1970 focus_order_remove(self
);
1971 focus_order_add_new(self
);
1973 /* this is here cuz with the VIDMODE extension, the viewport can
1974 change while a fullscreen window is iconic, and when it
1975 uniconifies, it would be nice if it did so to the new position
1977 client_reconfigure(self
);
1984 client_change_state(self
);
1985 client_showhide(self
);
1986 screen_update_areas();
1988 dispatch_client(iconic
? Event_Client_Unmapped
: Event_Client_Mapped
,
1992 /* iconify all transients */
1993 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
)
1994 if (it
->data
!= self
) client_iconify_recursive(it
->data
,
1998 void client_iconify(ObClient
*self
, gboolean iconic
, gboolean curdesk
)
2000 /* move up the transient chain as far as possible first */
2001 self
= client_search_top_transient(self
);
2003 client_iconify_recursive(client_search_top_transient(self
),
2007 void client_maximize(ObClient
*self
, gboolean max
, int dir
, gboolean savearea
)
2011 g_assert(dir
== 0 || dir
== 1 || dir
== 2);
2012 if (!(self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
)) return; /* can't */
2014 /* check if already done */
2016 if (dir
== 0 && self
->max_horz
&& self
->max_vert
) return;
2017 if (dir
== 1 && self
->max_horz
) return;
2018 if (dir
== 2 && self
->max_vert
) return;
2020 if (dir
== 0 && !self
->max_horz
&& !self
->max_vert
) return;
2021 if (dir
== 1 && !self
->max_horz
) return;
2022 if (dir
== 2 && !self
->max_vert
) return;
2025 /* work with the frame's coords */
2026 x
= self
->frame
->area
.x
;
2027 y
= self
->frame
->area
.y
;
2028 w
= self
->area
.width
;
2029 h
= self
->area
.height
;
2033 gint32 dimensions
[4];
2042 /* get the property off the window and use it for the dimensions
2043 we are already maxed on */
2044 if (PROP_GETA32(self
->window
, openbox_premax
, cardinal
,
2045 (guint32
**)&readdim
, &num
)) {
2047 if (self
->max_horz
) {
2048 dimensions
[0] = readdim
[0];
2049 dimensions
[2] = readdim
[2];
2051 if (self
->max_vert
) {
2052 dimensions
[1] = readdim
[1];
2053 dimensions
[3] = readdim
[3];
2059 PROP_SETA32(self
->window
, openbox_premax
, cardinal
,
2060 (guint32
*)dimensions
, 4);
2067 /* pick some fallbacks... */
2068 a
= screen_area_monitor(self
->desktop
, 0);
2069 if (dir
== 0 || dir
== 1) { /* horz */
2070 x
= a
->x
+ a
->width
/ 4;
2073 if (dir
== 0 || dir
== 2) { /* vert */
2074 y
= a
->y
+ a
->height
/ 4;
2078 if (PROP_GETA32(self
->window
, openbox_premax
, cardinal
,
2079 (guint32
**)&dimensions
, &num
)) {
2081 if (dir
== 0 || dir
== 1) { /* horz */
2085 if (dir
== 0 || dir
== 2) { /* vert */
2094 if (dir
== 0 || dir
== 1) /* horz */
2095 self
->max_horz
= max
;
2096 if (dir
== 0 || dir
== 2) /* vert */
2097 self
->max_vert
= max
;
2099 if (!self
->max_horz
&& !self
->max_vert
)
2100 PROP_ERASE(self
->window
, openbox_premax
);
2102 client_change_state(self
); /* change the state hints on the client */
2104 /* figure out where the client should be going */
2105 frame_frame_gravity(self
->frame
, &x
, &y
);
2106 client_configure(self
, OB_CORNER_TOPLEFT
, x
, y
, w
, h
, TRUE
, TRUE
);
2109 void client_shade(ObClient
*self
, gboolean shade
)
2111 if ((!(self
->functions
& OB_CLIENT_FUNC_SHADE
) &&
2112 shade
) || /* can't shade */
2113 self
->shaded
== shade
) return; /* already done */
2115 /* when we're iconic, don't change the wmstate */
2117 self
->wmstate
= shade
? IconicState
: NormalState
;
2118 self
->shaded
= shade
;
2119 client_change_state(self
);
2120 /* resize the frame to just the titlebar */
2121 frame_adjust_area(self
->frame
, FALSE
, FALSE
);
2124 void client_close(ObClient
*self
)
2128 if (!(self
->functions
& OB_CLIENT_FUNC_CLOSE
)) return;
2131 XXX: itd be cool to do timeouts and shit here for killing the client's
2133 like... if the window is around after 5 seconds, then the close button
2134 turns a nice red, and if this function is called again, the client is
2138 ce
.xclient
.type
= ClientMessage
;
2139 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
2140 ce
.xclient
.display
= ob_display
;
2141 ce
.xclient
.window
= self
->window
;
2142 ce
.xclient
.format
= 32;
2143 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_delete_window
;
2144 ce
.xclient
.data
.l
[1] = event_lasttime
;
2145 ce
.xclient
.data
.l
[2] = 0l;
2146 ce
.xclient
.data
.l
[3] = 0l;
2147 ce
.xclient
.data
.l
[4] = 0l;
2148 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
2151 void client_kill(ObClient
*self
)
2153 XKillClient(ob_display
, self
->window
);
2156 void client_set_desktop_recursive(ObClient
*self
,
2157 guint target
, gboolean donthide
)
2162 if (target
!= self
->desktop
) {
2164 ob_debug("Setting desktop %u\n", target
+1);
2166 g_assert(target
< screen_num_desktops
|| target
== DESKTOP_ALL
);
2168 /* remove from the old desktop(s) */
2169 focus_order_remove(self
);
2171 old
= self
->desktop
;
2172 self
->desktop
= target
;
2173 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, target
);
2174 /* the frame can display the current desktop state */
2175 frame_adjust_state(self
->frame
);
2176 /* 'move' the window to the new desktop */
2178 client_showhide(self
);
2179 /* raise if it was not already on the desktop */
2180 if (old
!= DESKTOP_ALL
)
2181 stacking_raise(CLIENT_AS_WINDOW(self
));
2182 screen_update_areas();
2184 /* add to the new desktop(s) */
2185 if (config_focus_new
)
2186 focus_order_to_top(self
);
2188 focus_order_to_bottom(self
);
2190 dispatch_client(Event_Client_Desktop
, self
, target
, old
);
2193 /* move all transients */
2194 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
)
2195 if (it
->data
!= self
) client_set_desktop_recursive(it
->data
,
2199 void client_set_desktop(ObClient
*self
, guint target
, gboolean donthide
)
2201 client_set_desktop_recursive(client_search_top_transient(self
),
2205 ObClient
*client_search_modal_child(ObClient
*self
)
2210 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
) {
2211 ObClient
*c
= it
->data
;
2212 if ((ret
= client_search_modal_child(c
))) return ret
;
2213 if (c
->modal
) return c
;
2218 gboolean
client_validate(ObClient
*self
)
2222 XSync(ob_display
, FALSE
); /* get all events on the server */
2224 if (XCheckTypedWindowEvent(ob_display
, self
->window
, DestroyNotify
, &e
) ||
2225 XCheckTypedWindowEvent(ob_display
, self
->window
, UnmapNotify
, &e
)) {
2226 XPutBackEvent(ob_display
, &e
);
2233 void client_set_wm_state(ObClient
*self
, long state
)
2235 if (state
== self
->wmstate
) return; /* no change */
2239 client_iconify(self
, TRUE
, TRUE
);
2242 client_iconify(self
, FALSE
, TRUE
);
2247 void client_set_state(ObClient
*self
, Atom action
, long data1
, long data2
)
2249 gboolean shaded
= self
->shaded
;
2250 gboolean fullscreen
= self
->fullscreen
;
2251 gboolean max_horz
= self
->max_horz
;
2252 gboolean max_vert
= self
->max_vert
;
2255 if (!(action
== prop_atoms
.net_wm_state_add
||
2256 action
== prop_atoms
.net_wm_state_remove
||
2257 action
== prop_atoms
.net_wm_state_toggle
))
2258 /* an invalid action was passed to the client message, ignore it */
2261 for (i
= 0; i
< 2; ++i
) {
2262 Atom state
= i
== 0 ? data1
: data2
;
2264 if (!state
) continue;
2266 /* if toggling, then pick whether we're adding or removing */
2267 if (action
== prop_atoms
.net_wm_state_toggle
) {
2268 if (state
== prop_atoms
.net_wm_state_modal
)
2269 action
= self
->modal
? prop_atoms
.net_wm_state_remove
:
2270 prop_atoms
.net_wm_state_add
;
2271 else if (state
== prop_atoms
.net_wm_state_maximized_vert
)
2272 action
= self
->max_vert
? prop_atoms
.net_wm_state_remove
:
2273 prop_atoms
.net_wm_state_add
;
2274 else if (state
== prop_atoms
.net_wm_state_maximized_horz
)
2275 action
= self
->max_horz
? prop_atoms
.net_wm_state_remove
:
2276 prop_atoms
.net_wm_state_add
;
2277 else if (state
== prop_atoms
.net_wm_state_shaded
)
2278 action
= self
->shaded
? prop_atoms
.net_wm_state_remove
:
2279 prop_atoms
.net_wm_state_add
;
2280 else if (state
== prop_atoms
.net_wm_state_skip_taskbar
)
2281 action
= self
->skip_taskbar
?
2282 prop_atoms
.net_wm_state_remove
:
2283 prop_atoms
.net_wm_state_add
;
2284 else if (state
== prop_atoms
.net_wm_state_skip_pager
)
2285 action
= self
->skip_pager
?
2286 prop_atoms
.net_wm_state_remove
:
2287 prop_atoms
.net_wm_state_add
;
2288 else if (state
== prop_atoms
.net_wm_state_fullscreen
)
2289 action
= self
->fullscreen
?
2290 prop_atoms
.net_wm_state_remove
:
2291 prop_atoms
.net_wm_state_add
;
2292 else if (state
== prop_atoms
.net_wm_state_above
)
2293 action
= self
->above
? prop_atoms
.net_wm_state_remove
:
2294 prop_atoms
.net_wm_state_add
;
2295 else if (state
== prop_atoms
.net_wm_state_below
)
2296 action
= self
->below
? prop_atoms
.net_wm_state_remove
:
2297 prop_atoms
.net_wm_state_add
;
2300 if (action
== prop_atoms
.net_wm_state_add
) {
2301 if (state
== prop_atoms
.net_wm_state_modal
) {
2302 /* XXX raise here or something? */
2304 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
2306 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
2308 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
2310 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
2311 self
->skip_taskbar
= TRUE
;
2312 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
2313 self
->skip_pager
= TRUE
;
2314 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
2316 } else if (state
== prop_atoms
.net_wm_state_above
) {
2318 } else if (state
== prop_atoms
.net_wm_state_below
) {
2322 } else { /* action == prop_atoms.net_wm_state_remove */
2323 if (state
== prop_atoms
.net_wm_state_modal
) {
2324 self
->modal
= FALSE
;
2325 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
2327 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
2329 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
2331 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
2332 self
->skip_taskbar
= FALSE
;
2333 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
2334 self
->skip_pager
= FALSE
;
2335 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
2337 } else if (state
== prop_atoms
.net_wm_state_above
) {
2338 self
->above
= FALSE
;
2339 } else if (state
== prop_atoms
.net_wm_state_below
) {
2340 self
->below
= FALSE
;
2344 if (max_horz
!= self
->max_horz
|| max_vert
!= self
->max_vert
) {
2345 if (max_horz
!= self
->max_horz
&& max_vert
!= self
->max_vert
) {
2347 if (max_horz
== max_vert
) { /* both going the same way */
2348 client_maximize(self
, max_horz
, 0, TRUE
);
2350 client_maximize(self
, max_horz
, 1, TRUE
);
2351 client_maximize(self
, max_vert
, 2, TRUE
);
2355 if (max_horz
!= self
->max_horz
)
2356 client_maximize(self
, max_horz
, 1, TRUE
);
2358 client_maximize(self
, max_vert
, 2, TRUE
);
2361 /* change fullscreen state before shading, as it will affect if the window
2363 if (fullscreen
!= self
->fullscreen
)
2364 client_fullscreen(self
, fullscreen
, TRUE
);
2365 if (shaded
!= self
->shaded
)
2366 client_shade(self
, shaded
);
2367 client_calc_layer(self
);
2368 client_change_state(self
); /* change the hint to reflect these changes */
2371 ObClient
*client_focus_target(ObClient
*self
)
2375 /* if we have a modal child, then focus it, not us */
2376 child
= client_search_modal_child(self
);
2377 if (child
) return child
;
2381 gboolean
client_can_focus(ObClient
*self
)
2385 /* choose the correct target */
2386 self
= client_focus_target(self
);
2388 if (!self
->frame
->visible
)
2391 if (!((self
->can_focus
|| self
->focus_notify
) &&
2392 (self
->desktop
== screen_desktop
||
2393 self
->desktop
== DESKTOP_ALL
) &&
2397 /* do a check to see if the window has already been unmapped or destroyed
2398 do this intelligently while watching out for unmaps we've generated
2399 (ignore_unmaps > 0) */
2400 if (XCheckTypedWindowEvent(ob_display
, self
->window
,
2401 DestroyNotify
, &ev
)) {
2402 XPutBackEvent(ob_display
, &ev
);
2405 while (XCheckTypedWindowEvent(ob_display
, self
->window
,
2406 UnmapNotify
, &ev
)) {
2407 if (self
->ignore_unmaps
) {
2408 self
->ignore_unmaps
--;
2410 XPutBackEvent(ob_display
, &ev
);
2418 gboolean
client_focus(ObClient
*self
)
2420 /* choose the correct target */
2421 self
= client_focus_target(self
);
2423 if (!client_can_focus(self
)) {
2424 if (!self
->frame
->visible
) {
2425 /* update the focus lists */
2426 focus_order_to_top(self
);
2431 if (self
->can_focus
)
2432 /* RevertToPointerRoot causes much more headache than RevertToNone, so
2433 I choose to use it always, hopefully to find errors quicker, if any
2434 are left. (I hate X. I hate focus events.) */
2435 XSetInputFocus(ob_display
, self
->window
, RevertToPointerRoot
,
2438 if (self
->focus_notify
) {
2440 ce
.xclient
.type
= ClientMessage
;
2441 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
2442 ce
.xclient
.display
= ob_display
;
2443 ce
.xclient
.window
= self
->window
;
2444 ce
.xclient
.format
= 32;
2445 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_take_focus
;
2446 ce
.xclient
.data
.l
[1] = event_lasttime
;
2447 ce
.xclient
.data
.l
[2] = 0l;
2448 ce
.xclient
.data
.l
[3] = 0l;
2449 ce
.xclient
.data
.l
[4] = 0l;
2450 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
2454 ob_debug("%sively focusing %lx at %d\n",
2455 (self
->can_focus
? "act" : "pass"),
2456 self
->window
, (int) event_lasttime
);
2459 /* Cause the FocusIn to come back to us. Important for desktop switches,
2460 since otherwise we'll have no FocusIn on the queue and send it off to
2461 the focus_backup. */
2462 XSync(ob_display
, FALSE
);
2466 void client_unfocus(ObClient
*self
)
2468 g_assert(focus_client
== self
);
2470 ob_debug("client_unfocus for %lx\n", self
->window
);
2472 focus_fallback(OB_FOCUS_FALLBACK_UNFOCUSING
);
2475 void client_activate(ObClient
*self
)
2477 if (client_normal(self
) && screen_showing_desktop
)
2478 screen_show_desktop(FALSE
);
2480 client_iconify(self
, FALSE
, FALSE
);
2481 if (self
->desktop
!= DESKTOP_ALL
&&
2482 self
->desktop
!= screen_desktop
)
2483 screen_set_desktop(self
->desktop
);
2484 else if (!self
->frame
->visible
)
2485 /* if its not visible for other reasons, then don't mess
2489 client_shade(self
, FALSE
);
2491 stacking_raise(CLIENT_AS_WINDOW(self
));
2494 gboolean
client_focused(ObClient
*self
)
2496 return self
== focus_client
;
2499 ObClientIcon
*client_icon(ObClient
*self
, int w
, int h
)
2502 /* si is the smallest image >= req */
2503 /* li is the largest image < req */
2504 unsigned long size
, smallest
= 0xffffffff, largest
= 0, si
= 0, li
= 0;
2506 if (!self
->nicons
) return NULL
;
2508 for (i
= 0; i
< self
->nicons
; ++i
) {
2509 size
= self
->icons
[i
].width
* self
->icons
[i
].height
;
2510 if (size
< smallest
&& size
>= (unsigned)(w
* h
)) {
2514 if (size
> largest
&& size
<= (unsigned)(w
* h
)) {
2519 if (largest
== 0) /* didnt find one smaller than the requested size */
2520 return &self
->icons
[si
];
2521 return &self
->icons
[li
];
2524 /* this be mostly ripped from fvwm */
2525 ObClient
*client_find_directional(ObClient
*c
, ObDirection dir
)
2527 int my_cx
, my_cy
, his_cx
, his_cy
;
2530 int score
, best_score
;
2531 ObClient
*best_client
, *cur
;
2537 /* first, find the centre coords of the currently focused window */
2538 my_cx
= c
->frame
->area
.x
+ c
->frame
->area
.width
/ 2;
2539 my_cy
= c
->frame
->area
.y
+ c
->frame
->area
.height
/ 2;
2544 for(it
= g_list_first(client_list
); it
; it
= it
->next
) {
2547 /* the currently selected window isn't interesting */
2550 if (!client_normal(cur
))
2552 if(c
->desktop
!= cur
->desktop
&& cur
->desktop
!= DESKTOP_ALL
)
2556 if(client_focus_target(cur
) == cur
&&
2557 !(cur
->can_focus
|| cur
->focus_notify
))
2560 /* find the centre coords of this window, from the
2561 * currently focused window's point of view */
2562 his_cx
= (cur
->frame
->area
.x
- my_cx
)
2563 + cur
->frame
->area
.width
/ 2;
2564 his_cy
= (cur
->frame
->area
.y
- my_cy
)
2565 + cur
->frame
->area
.height
/ 2;
2569 /* Rotate the diagonals 45 degrees counterclockwise.
2570 * To do this, multiply the matrix /+h +h\ with the
2571 * vector (x y). \-h +h/
2572 * h = sqrt(0.5). We can set h := 1 since absolute
2573 * distance doesn't matter here. */
2574 tx
= his_cx
+ his_cy
;
2575 his_cy
= -his_cx
+ his_cy
;
2580 case OB_DIRECTION_NORTH
:
2581 case OB_DIRECTION_SOUTH
:
2582 case OB_DIRECTION_NORTHEAST
:
2583 case OB_DIRECTION_SOUTHWEST
:
2584 offset
= (his_cx
< 0) ? -his_cx
: his_cx
;
2585 distance
= ((dir
== OB_DIRECTION_NORTH
||
2586 dir
== OB_DIRECTION_NORTHEAST
) ?
2589 case OB_DIRECTION_EAST
:
2590 case OB_DIRECTION_WEST
:
2591 case OB_DIRECTION_SOUTHEAST
:
2592 case OB_DIRECTION_NORTHWEST
:
2593 offset
= (his_cy
< 0) ? -his_cy
: his_cy
;
2594 distance
= ((dir
== OB_DIRECTION_WEST
||
2595 dir
== OB_DIRECTION_NORTHWEST
) ?
2600 /* the target must be in the requested direction */
2604 /* Calculate score for this window. The smaller the better. */
2605 score
= distance
+ offset
;
2607 /* windows more than 45 degrees off the direction are
2608 * heavily penalized and will only be chosen if nothing
2609 * else within a million pixels */
2610 if(offset
> distance
)
2613 if(best_score
== -1 || score
< best_score
)
2621 void client_set_layer(ObClient
*self
, int layer
)
2625 self
->above
= FALSE
;
2626 } else if (layer
== 0) {
2627 self
->below
= self
->above
= FALSE
;
2629 self
->below
= FALSE
;
2632 client_calc_layer(self
);
2633 client_change_state(self
); /* reflect this in the state hints */
2636 guint
client_monitor(ObClient
*self
)
2640 for (i
= 0; i
< screen_num_monitors
; ++i
) {
2641 Rect
*area
= screen_physical_area_monitor(i
);
2642 if (RECT_INTERSECTS_RECT(*area
, self
->frame
->area
))
2645 if (i
== screen_num_monitors
) i
= 0;
2646 g_assert(i
< screen_num_monitors
);
2650 ObClient
*client_search_top_transient(ObClient
*self
)
2652 /* move up the transient chain as far as possible */
2653 if (self
->transient_for
) {
2654 if (self
->transient_for
!= OB_TRAN_GROUP
) {
2655 return client_search_top_transient(self
->transient_for
);
2659 for (it
= self
->group
->members
; it
; it
= it
->next
) {
2660 ObClient
*c
= it
->data
;
2662 /* checking transient_for prevents infinate loops! */
2663 if (c
!= self
&& !c
->transient_for
)
2674 ObClient
*client_search_transient(ObClient
*self
, ObClient
*search
)
2678 for (sit
= self
->transients
; sit
; sit
= g_slist_next(sit
)) {
2679 if (sit
->data
== search
)
2681 if (client_search_transient(sit
->data
, search
))