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 /* add to client list/map */
253 client_list
= g_list_append(client_list
, self
);
254 g_hash_table_insert(window_map
, &self
->window
, self
);
256 /* update the focus lists */
257 focus_order_add_new(self
);
259 stacking_add(CLIENT_AS_WINDOW(self
));
261 /* focus the new window? */
262 if (ob_state() != OB_STATE_STARTING
&& config_focus_new
&&
263 /* note the check against Type_Normal/Dialog, not client_normal(self),
264 which would also include other types. in this case we want more
265 strict rules for focus */
266 (self
->type
== OB_CLIENT_TYPE_NORMAL
||
267 self
->type
== OB_CLIENT_TYPE_DIALOG
))
269 if (self
->desktop
!= screen_desktop
) {
270 /* activate the window */
273 gboolean group_foc
= FALSE
;
278 for (it
= self
->group
->members
; it
; it
= it
->next
)
280 if (client_focused(it
->data
))
288 (!self
->transient_for
&& (!self
->group
||
289 !self
->group
->members
->next
))) ||
290 client_search_focus_tree_full(self
) ||
292 !client_normal(focus_client
))
294 /* activate the window */
300 dispatch_client(Event_Client_New
, self
, 0, 0);
302 /* make sure the window is visible */
303 client_move_onscreen(self
, TRUE
);
305 screen_update_areas();
307 client_showhide(self
);
309 /* use client_focus instead of client_activate cuz client_activate does
310 stuff like switch desktops etc and I'm not interested in all that when
311 a window maps since its not based on an action from the user like
312 clicking a window to activate is. so keep the new window out of the way
314 if (activate
) client_focus(self
);
316 /* client_activate does this but we aret using it so we have to do it
318 if (screen_showing_desktop
)
319 screen_show_desktop(FALSE
);
321 /* update the list hints */
324 dispatch_client(Event_Client_Mapped
, self
, 0, 0);
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
);
431 /* if we're left in an iconic state, the client wont be mapped. this is
432 bad, since we will no longer be managing the window on restart */
434 XMapWindow(ob_display
, self
->window
);
438 ob_debug("Unmanaged window 0x%lx\n", self
->window
);
440 /* free all data allocated in the client struct */
441 g_slist_free(self
->transients
);
442 for (j
= 0; j
< self
->nicons
; ++j
)
443 g_free(self
->icons
[j
].data
);
444 if (self
->nicons
> 0)
447 g_free(self
->icon_title
);
453 /* update the list hints */
457 void client_move_onscreen(ObClient
*self
, gboolean rude
)
459 int x
= self
->area
.x
;
460 int y
= self
->area
.y
;
461 if (client_find_onscreen(self
, &x
, &y
,
462 self
->area
.width
, self
->area
.height
, rude
)) {
463 client_configure(self
, OB_CORNER_TOPLEFT
, x
, y
,
464 self
->area
.width
, self
->area
.height
,
469 gboolean
client_find_onscreen(ObClient
*self
, int *x
, int *y
, int w
, int h
,
473 int ox
= *x
, oy
= *y
;
475 frame_client_gravity(self
->frame
, x
, y
); /* get where the frame
478 /* XXX watch for xinerama dead areas */
480 a
= screen_area(self
->desktop
);
481 if (!self
->strut
.right
&& *x
>= a
->x
+ a
->width
- 1)
482 *x
= a
->x
+ a
->width
- self
->frame
->area
.width
;
483 if (!self
->strut
.bottom
&& *y
>= a
->y
+ a
->height
- 1)
484 *y
= a
->y
+ a
->height
- self
->frame
->area
.height
;
485 if (!self
->strut
.left
&& *x
+ self
->frame
->area
.width
- 1 < a
->x
)
487 if (!self
->strut
.top
&& *y
+ self
->frame
->area
.height
- 1 < a
->y
)
491 /* this is my MOZILLA BITCHSLAP. oh ya it fucking feels good.
492 Java can suck it too. */
494 /* dont let windows map/move into the strut unless they
495 are bigger than the available area */
497 if (!self
->strut
.left
&& *x
< a
->x
) *x
= a
->x
;
498 if (!self
->strut
.right
&& *x
+ w
> a
->x
+ a
->width
)
499 *x
= a
->x
+ a
->width
- w
;
501 if (h
<= a
->height
) {
502 if (!self
->strut
.top
&& *y
< a
->y
) *y
= a
->y
;
503 if (!self
->strut
.bottom
&& *y
+ h
> a
->y
+ a
->height
)
504 *y
= a
->y
+ a
->height
- h
;
508 frame_frame_gravity(self
->frame
, x
, y
); /* get where the client
511 return ox
!= *x
|| oy
!= *y
;
514 static void client_toggle_border(ObClient
*self
, gboolean show
)
516 /* adjust our idea of where the client is, based on its border. When the
517 border is removed, the client should now be considered to be in a
519 when re-adding the border to the client, the same operation needs to be
521 int oldx
= self
->area
.x
, oldy
= self
->area
.y
;
522 int x
= oldx
, y
= oldy
;
523 switch(self
->gravity
) {
525 case NorthWestGravity
:
527 case SouthWestGravity
:
529 case NorthEastGravity
:
531 case SouthEastGravity
:
532 if (show
) x
-= self
->border_width
* 2;
533 else x
+= self
->border_width
* 2;
540 if (show
) x
-= self
->border_width
;
541 else x
+= self
->border_width
;
544 switch(self
->gravity
) {
546 case NorthWestGravity
:
548 case NorthEastGravity
:
550 case SouthWestGravity
:
552 case SouthEastGravity
:
553 if (show
) y
-= self
->border_width
* 2;
554 else y
+= self
->border_width
* 2;
561 if (show
) y
-= self
->border_width
;
562 else y
+= self
->border_width
;
569 XSetWindowBorderWidth(ob_display
, self
->window
, self
->border_width
);
571 /* move the client so it is back it the right spot _with_ its
573 if (x
!= oldx
|| y
!= oldy
)
574 XMoveWindow(ob_display
, self
->window
, x
, y
);
576 XSetWindowBorderWidth(ob_display
, self
->window
, 0);
580 static void client_get_all(ObClient
*self
)
582 /* update EVERYTHING!! */
584 self
->ignore_unmaps
= 0;
588 self
->title
= self
->icon_title
= NULL
;
589 self
->title_count
= 1;
590 self
->name
= self
->class = self
->role
= NULL
;
591 self
->wmstate
= NormalState
;
592 self
->transient
= FALSE
;
593 self
->transients
= NULL
;
594 self
->transient_for
= NULL
;
596 self
->urgent
= FALSE
;
597 self
->positioned
= FALSE
;
598 self
->decorate
= TRUE
;
602 client_get_area(self
);
603 client_update_transient_for(self
);
604 client_update_wmhints(self
);
605 client_get_desktop(self
);
606 client_get_state(self
);
607 client_get_shaped(self
);
609 client_get_mwm_hints(self
);
610 client_get_type(self
);/* this can change the mwmhints for special cases */
612 client_update_protocols(self
);
614 client_get_gravity(self
); /* get the attribute gravity */
615 client_update_normal_hints(self
); /* this may override the attribute
618 /* got the type, the mwmhints, the protocols, and the normal hints
619 (min/max sizes), so we're ready to set up the decorations/functions */
620 client_setup_decor_and_functions(self
);
622 client_update_title(self
);
623 client_update_class(self
);
624 client_update_strut(self
);
625 client_update_icons(self
);
627 client_change_state(self
);
630 static void client_get_area(ObClient
*self
)
632 XWindowAttributes wattrib
;
635 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
636 g_assert(ret
!= BadWindow
);
638 RECT_SET(self
->area
, wattrib
.x
, wattrib
.y
, wattrib
.width
, wattrib
.height
);
639 self
->border_width
= wattrib
.border_width
;
642 static void client_get_desktop(ObClient
*self
)
644 guint32 d
= screen_num_desktops
; /* an always-invalid value */
646 if (PROP_GET32(self
->window
, net_wm_desktop
, cardinal
, &d
)) {
647 if (d
>= screen_num_desktops
&& d
!= DESKTOP_ALL
)
648 self
->desktop
= screen_num_desktops
- 1;
652 gboolean trdesk
= FALSE
;
654 if (self
->transient_for
) {
655 if (self
->transient_for
!= OB_TRAN_GROUP
) {
656 self
->desktop
= self
->transient_for
->desktop
;
661 for (it
= self
->group
->members
; it
; it
= it
->next
)
662 if (it
->data
!= self
&&
663 !((ObClient
*)it
->data
)->transient_for
) {
664 self
->desktop
= ((ObClient
*)it
->data
)->desktop
;
671 /* defaults to the current desktop */
672 self
->desktop
= screen_desktop
;
675 if (self
->desktop
!= d
) {
676 /* set the desktop hint, to make sure that it always exists */
677 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, self
->desktop
);
681 static void client_get_state(ObClient
*self
)
686 self
->modal
= self
->shaded
= self
->max_horz
= self
->max_vert
=
687 self
->fullscreen
= self
->above
= self
->below
= self
->iconic
=
688 self
->skip_taskbar
= self
->skip_pager
= FALSE
;
690 if (PROP_GETA32(self
->window
, net_wm_state
, atom
, &state
, &num
)) {
692 for (i
= 0; i
< num
; ++i
) {
693 if (state
[i
] == prop_atoms
.net_wm_state_modal
)
695 else if (state
[i
] == prop_atoms
.net_wm_state_shaded
)
697 else if (state
[i
] == prop_atoms
.net_wm_state_hidden
)
699 else if (state
[i
] == prop_atoms
.net_wm_state_skip_taskbar
)
700 self
->skip_taskbar
= TRUE
;
701 else if (state
[i
] == prop_atoms
.net_wm_state_skip_pager
)
702 self
->skip_pager
= TRUE
;
703 else if (state
[i
] == prop_atoms
.net_wm_state_fullscreen
)
704 self
->fullscreen
= TRUE
;
705 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_vert
)
706 self
->max_vert
= TRUE
;
707 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_horz
)
708 self
->max_horz
= TRUE
;
709 else if (state
[i
] == prop_atoms
.net_wm_state_above
)
711 else if (state
[i
] == prop_atoms
.net_wm_state_below
)
719 static void client_get_shaped(ObClient
*self
)
721 self
->shaped
= FALSE
;
723 if (extensions_shape
) {
728 XShapeSelectInput(ob_display
, self
->window
, ShapeNotifyMask
);
730 XShapeQueryExtents(ob_display
, self
->window
, &s
, &foo
,
731 &foo
, &ufoo
, &ufoo
, &foo
, &foo
, &foo
, &ufoo
,
733 self
->shaped
= (s
!= 0);
738 void client_update_transient_for(ObClient
*self
)
741 ObClient
*target
= NULL
;
743 if (XGetTransientForHint(ob_display
, self
->window
, &t
)) {
744 self
->transient
= TRUE
;
745 if (t
!= self
->window
) { /* cant be transient to itself! */
746 target
= g_hash_table_lookup(window_map
, &t
);
747 /* if this happens then we need to check for it*/
748 g_assert(target
!= self
);
749 g_assert(!target
|| WINDOW_IS_CLIENT(target
));
751 if (!target
&& self
->group
) {
752 /* not transient to a client, see if it is transient for a
754 if (t
== self
->group
->leader
||
756 t
== RootWindow(ob_display
, ob_screen
)) {
757 /* window is a transient for its group! */
758 target
= OB_TRAN_GROUP
;
763 self
->transient
= FALSE
;
765 /* if anything has changed... */
766 if (target
!= self
->transient_for
) {
767 if (self
->transient_for
== OB_TRAN_GROUP
) { /* transient of group */
770 /* remove from old parents */
771 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
772 ObClient
*c
= it
->data
;
773 if (c
!= self
&& !c
->transient_for
)
774 c
->transients
= g_slist_remove(c
->transients
, self
);
776 } else if (self
->transient_for
!= NULL
) { /* transient of window */
777 /* remove from old parent */
778 self
->transient_for
->transients
=
779 g_slist_remove(self
->transient_for
->transients
, self
);
781 self
->transient_for
= target
;
782 if (self
->transient_for
== OB_TRAN_GROUP
) { /* transient of group */
785 /* add to new parents */
786 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
787 ObClient
*c
= it
->data
;
788 if (c
!= self
&& !c
->transient_for
)
789 c
->transients
= g_slist_append(c
->transients
, self
);
792 /* remove all transients which are in the group, that causes
793 circlular pointer hell of doom */
794 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
796 for (sit
= self
->transients
; sit
; sit
= next
) {
797 next
= g_slist_next(sit
);
798 if (sit
->data
== it
->data
)
800 g_slist_delete_link(self
->transients
, sit
);
803 } else if (self
->transient_for
!= NULL
) { /* transient of window */
804 /* add to new parent */
805 self
->transient_for
->transients
=
806 g_slist_append(self
->transient_for
->transients
, self
);
811 static void client_get_mwm_hints(ObClient
*self
)
816 self
->mwmhints
.flags
= 0; /* default to none */
818 if (PROP_GETA32(self
->window
, motif_wm_hints
, motif_wm_hints
,
820 if (num
>= OB_MWM_ELEMENTS
) {
821 self
->mwmhints
.flags
= hints
[0];
822 self
->mwmhints
.functions
= hints
[1];
823 self
->mwmhints
.decorations
= hints
[2];
829 void client_get_type(ObClient
*self
)
836 if (PROP_GETA32(self
->window
, net_wm_window_type
, atom
, &val
, &num
)) {
837 /* use the first value that we know about in the array */
838 for (i
= 0; i
< num
; ++i
) {
839 if (val
[i
] == prop_atoms
.net_wm_window_type_desktop
)
840 self
->type
= OB_CLIENT_TYPE_DESKTOP
;
841 else if (val
[i
] == prop_atoms
.net_wm_window_type_dock
)
842 self
->type
= OB_CLIENT_TYPE_DOCK
;
843 else if (val
[i
] == prop_atoms
.net_wm_window_type_toolbar
)
844 self
->type
= OB_CLIENT_TYPE_TOOLBAR
;
845 else if (val
[i
] == prop_atoms
.net_wm_window_type_menu
)
846 self
->type
= OB_CLIENT_TYPE_MENU
;
847 else if (val
[i
] == prop_atoms
.net_wm_window_type_utility
)
848 self
->type
= OB_CLIENT_TYPE_UTILITY
;
849 else if (val
[i
] == prop_atoms
.net_wm_window_type_splash
)
850 self
->type
= OB_CLIENT_TYPE_SPLASH
;
851 else if (val
[i
] == prop_atoms
.net_wm_window_type_dialog
)
852 self
->type
= OB_CLIENT_TYPE_DIALOG
;
853 else if (val
[i
] == prop_atoms
.net_wm_window_type_normal
)
854 self
->type
= OB_CLIENT_TYPE_NORMAL
;
855 else if (val
[i
] == prop_atoms
.kde_net_wm_window_type_override
) {
856 /* prevent this window from getting any decor or
858 self
->mwmhints
.flags
&= (OB_MWM_FLAG_FUNCTIONS
|
859 OB_MWM_FLAG_DECORATIONS
);
860 self
->mwmhints
.decorations
= 0;
861 self
->mwmhints
.functions
= 0;
863 if (self
->type
!= (ObClientType
) -1)
864 break; /* grab the first legit type */
869 if (self
->type
== (ObClientType
) -1) {
870 /*the window type hint was not set, which means we either classify
871 ourself as a normal window or a dialog, depending on if we are a
874 self
->type
= OB_CLIENT_TYPE_DIALOG
;
876 self
->type
= OB_CLIENT_TYPE_NORMAL
;
880 void client_update_protocols(ObClient
*self
)
885 self
->focus_notify
= FALSE
;
886 self
->delete_window
= FALSE
;
888 if (PROP_GETA32(self
->window
, wm_protocols
, atom
, &proto
, &num_return
)) {
889 for (i
= 0; i
< num_return
; ++i
) {
890 if (proto
[i
] == prop_atoms
.wm_delete_window
) {
891 /* this means we can request the window to close */
892 self
->delete_window
= TRUE
;
893 } else if (proto
[i
] == prop_atoms
.wm_take_focus
)
894 /* if this protocol is requested, then the window will be
895 notified whenever we want it to receive focus */
896 self
->focus_notify
= TRUE
;
902 static void client_get_gravity(ObClient
*self
)
904 XWindowAttributes wattrib
;
907 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
908 g_assert(ret
!= BadWindow
);
909 self
->gravity
= wattrib
.win_gravity
;
912 void client_update_normal_hints(ObClient
*self
)
916 int oldgravity
= self
->gravity
;
919 self
->min_ratio
= 0.0f
;
920 self
->max_ratio
= 0.0f
;
921 SIZE_SET(self
->size_inc
, 1, 1);
922 SIZE_SET(self
->base_size
, 0, 0);
923 SIZE_SET(self
->min_size
, 0, 0);
924 SIZE_SET(self
->max_size
, G_MAXINT
, G_MAXINT
);
926 /* get the hints from the window */
927 if (XGetWMNormalHints(ob_display
, self
->window
, &size
, &ret
)) {
928 self
->positioned
= !!(size
.flags
& (PPosition
|USPosition
));
930 if (size
.flags
& PWinGravity
) {
931 self
->gravity
= size
.win_gravity
;
933 /* if the client has a frame, i.e. has already been mapped and
934 is changing its gravity */
935 if (self
->frame
&& self
->gravity
!= oldgravity
) {
936 /* move our idea of the client's position based on its new
938 self
->area
.x
= self
->frame
->area
.x
;
939 self
->area
.y
= self
->frame
->area
.y
;
940 frame_frame_gravity(self
->frame
, &self
->area
.x
, &self
->area
.y
);
944 if (size
.flags
& PAspect
) {
945 if (size
.min_aspect
.y
)
946 self
->min_ratio
= (float)size
.min_aspect
.x
/ size
.min_aspect
.y
;
947 if (size
.max_aspect
.y
)
948 self
->max_ratio
= (float)size
.max_aspect
.x
/ size
.max_aspect
.y
;
951 if (size
.flags
& PMinSize
)
952 SIZE_SET(self
->min_size
, size
.min_width
, size
.min_height
);
954 if (size
.flags
& PMaxSize
)
955 SIZE_SET(self
->max_size
, size
.max_width
, size
.max_height
);
957 if (size
.flags
& PBaseSize
)
958 SIZE_SET(self
->base_size
, size
.base_width
, size
.base_height
);
960 if (size
.flags
& PResizeInc
)
961 SIZE_SET(self
->size_inc
, size
.width_inc
, size
.height_inc
);
965 void client_setup_decor_and_functions(ObClient
*self
)
967 /* start with everything (cept fullscreen) */
968 self
->decorations
= (OB_FRAME_DECOR_TITLEBAR
|
969 OB_FRAME_DECOR_HANDLE
|
970 OB_FRAME_DECOR_GRIPS
|
971 OB_FRAME_DECOR_BORDER
|
972 OB_FRAME_DECOR_ICON
|
973 OB_FRAME_DECOR_ALLDESKTOPS
|
974 OB_FRAME_DECOR_ICONIFY
|
975 OB_FRAME_DECOR_MAXIMIZE
|
976 OB_FRAME_DECOR_SHADE
);
977 self
->functions
= (OB_CLIENT_FUNC_RESIZE
|
978 OB_CLIENT_FUNC_MOVE
|
979 OB_CLIENT_FUNC_ICONIFY
|
980 OB_CLIENT_FUNC_MAXIMIZE
|
981 OB_CLIENT_FUNC_SHADE
);
982 if (self
->delete_window
) {
983 self
->functions
|= OB_CLIENT_FUNC_CLOSE
;
984 self
->decorations
|= OB_FRAME_DECOR_CLOSE
;
987 if (!(self
->min_size
.width
< self
->max_size
.width
||
988 self
->min_size
.height
< self
->max_size
.height
))
989 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
991 switch (self
->type
) {
992 case OB_CLIENT_TYPE_NORMAL
:
993 /* normal windows retain all of the possible decorations and
994 functionality, and are the only windows that you can fullscreen */
995 self
->functions
|= OB_CLIENT_FUNC_FULLSCREEN
;
998 case OB_CLIENT_TYPE_DIALOG
:
999 case OB_CLIENT_TYPE_UTILITY
:
1000 /* these windows cannot be maximized */
1001 self
->functions
&= ~OB_CLIENT_FUNC_MAXIMIZE
;
1004 case OB_CLIENT_TYPE_MENU
:
1005 case OB_CLIENT_TYPE_TOOLBAR
:
1006 /* these windows get less functionality */
1007 self
->functions
&= ~(OB_CLIENT_FUNC_ICONIFY
| OB_CLIENT_FUNC_RESIZE
);
1010 case OB_CLIENT_TYPE_DESKTOP
:
1011 case OB_CLIENT_TYPE_DOCK
:
1012 case OB_CLIENT_TYPE_SPLASH
:
1013 /* none of these windows are manipulated by the window manager */
1014 self
->decorations
= 0;
1015 self
->functions
= 0;
1019 /* Mwm Hints are applied subtractively to what has already been chosen for
1020 decor and functionality */
1021 if (self
->mwmhints
.flags
& OB_MWM_FLAG_DECORATIONS
) {
1022 if (! (self
->mwmhints
.decorations
& OB_MWM_DECOR_ALL
)) {
1023 if (! ((self
->mwmhints
.decorations
& OB_MWM_DECOR_HANDLE
) ||
1024 (self
->mwmhints
.decorations
& OB_MWM_DECOR_TITLE
)))
1025 /* if the mwm hints request no handle or title, then all
1026 decorations are disabled */
1027 self
->decorations
= 0;
1031 if (self
->mwmhints
.flags
& OB_MWM_FLAG_FUNCTIONS
) {
1032 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_ALL
)) {
1033 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_RESIZE
))
1034 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
1035 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_MOVE
))
1036 self
->functions
&= ~OB_CLIENT_FUNC_MOVE
;
1037 /* dont let mwm hints kill any buttons
1038 if (! (self->mwmhints.functions & OB_MWM_FUNC_ICONIFY))
1039 self->functions &= ~OB_CLIENT_FUNC_ICONIFY;
1040 if (! (self->mwmhints.functions & OB_MWM_FUNC_MAXIMIZE))
1041 self->functions &= ~OB_CLIENT_FUNC_MAXIMIZE;
1043 /* dont let mwm hints kill the close button
1044 if (! (self->mwmhints.functions & MwmFunc_Close))
1045 self->functions &= ~OB_CLIENT_FUNC_CLOSE; */
1049 if (!(self
->functions
& OB_CLIENT_FUNC_SHADE
))
1050 self
->decorations
&= ~OB_FRAME_DECOR_SHADE
;
1051 if (!(self
->functions
& OB_CLIENT_FUNC_ICONIFY
))
1052 self
->decorations
&= ~OB_FRAME_DECOR_ICONIFY
;
1053 if (!(self
->functions
& OB_CLIENT_FUNC_RESIZE
))
1054 self
->decorations
&= ~OB_FRAME_DECOR_GRIPS
;
1056 /* can't maximize without moving/resizing */
1057 if (!((self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) &&
1058 (self
->functions
& OB_CLIENT_FUNC_MOVE
) &&
1059 (self
->functions
& OB_CLIENT_FUNC_RESIZE
))) {
1060 self
->functions
&= ~OB_CLIENT_FUNC_MAXIMIZE
;
1061 self
->decorations
&= ~OB_FRAME_DECOR_MAXIMIZE
;
1064 /* finally, the user can have requested no decorations, which overrides
1066 if (!self
->decorate
)
1067 self
->decorations
= 0;
1069 /* if we don't have a titlebar, then we cannot shade! */
1070 if (!(self
->decorations
& OB_FRAME_DECOR_TITLEBAR
))
1071 self
->functions
&= ~OB_CLIENT_FUNC_SHADE
;
1073 /* now we need to check against rules for the client's current state */
1074 if (self
->fullscreen
) {
1075 self
->functions
&= (OB_CLIENT_FUNC_CLOSE
|
1076 OB_CLIENT_FUNC_FULLSCREEN
|
1077 OB_CLIENT_FUNC_ICONIFY
);
1078 self
->decorations
= 0;
1081 client_change_allowed_actions(self
);
1084 /* this makes sure that these windows appear on all desktops */
1085 if (self
->type
== OB_CLIENT_TYPE_DESKTOP
&&
1086 self
->desktop
!= DESKTOP_ALL
)
1087 client_set_desktop(self
, DESKTOP_ALL
, FALSE
);
1089 /* adjust the client's decorations, etc. */
1090 client_reconfigure(self
);
1092 /* this makes sure that these windows appear on all desktops */
1093 if (self
->type
== OB_CLIENT_TYPE_DESKTOP
&&
1094 self
->desktop
!= DESKTOP_ALL
)
1096 self
->desktop
= DESKTOP_ALL
;
1101 static void client_change_allowed_actions(ObClient
*self
)
1106 /* desktop windows are kept on all desktops */
1107 if (self
->type
!= OB_CLIENT_TYPE_DESKTOP
)
1108 actions
[num
++] = prop_atoms
.net_wm_action_change_desktop
;
1110 if (self
->functions
& OB_CLIENT_FUNC_SHADE
)
1111 actions
[num
++] = prop_atoms
.net_wm_action_shade
;
1112 if (self
->functions
& OB_CLIENT_FUNC_CLOSE
)
1113 actions
[num
++] = prop_atoms
.net_wm_action_close
;
1114 if (self
->functions
& OB_CLIENT_FUNC_MOVE
)
1115 actions
[num
++] = prop_atoms
.net_wm_action_move
;
1116 if (self
->functions
& OB_CLIENT_FUNC_ICONIFY
)
1117 actions
[num
++] = prop_atoms
.net_wm_action_minimize
;
1118 if (self
->functions
& OB_CLIENT_FUNC_RESIZE
)
1119 actions
[num
++] = prop_atoms
.net_wm_action_resize
;
1120 if (self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
)
1121 actions
[num
++] = prop_atoms
.net_wm_action_fullscreen
;
1122 if (self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) {
1123 actions
[num
++] = prop_atoms
.net_wm_action_maximize_horz
;
1124 actions
[num
++] = prop_atoms
.net_wm_action_maximize_vert
;
1127 PROP_SETA32(self
->window
, net_wm_allowed_actions
, atom
, actions
, num
);
1129 /* make sure the window isn't breaking any rules now */
1131 if (!(self
->functions
& OB_CLIENT_FUNC_SHADE
) && self
->shaded
) {
1132 if (self
->frame
) client_shade(self
, FALSE
);
1133 else self
->shaded
= FALSE
;
1135 if (!(self
->functions
& OB_CLIENT_FUNC_ICONIFY
) && self
->iconic
) {
1136 if (self
->frame
) client_iconify(self
, FALSE
, TRUE
);
1137 else self
->iconic
= FALSE
;
1139 if (!(self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
) && self
->fullscreen
) {
1140 if (self
->frame
) client_fullscreen(self
, FALSE
, TRUE
);
1141 else self
->fullscreen
= FALSE
;
1143 if (!(self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) && (self
->max_horz
||
1145 if (self
->frame
) client_maximize(self
, FALSE
, 0, TRUE
);
1146 else self
->max_vert
= self
->max_horz
= FALSE
;
1150 void client_reconfigure(ObClient
*self
)
1152 /* by making this pass FALSE for user, we avoid the emacs event storm where
1153 every configurenotify causes an update in its normal hints, i think this
1154 is generally what we want anyways... */
1155 client_configure(self
, OB_CORNER_TOPLEFT
, self
->area
.x
, self
->area
.y
,
1156 self
->area
.width
, self
->area
.height
, FALSE
, TRUE
);
1159 void client_update_wmhints(ObClient
*self
)
1162 gboolean ur
= FALSE
;
1165 /* assume a window takes input if it doesnt specify */
1166 self
->can_focus
= TRUE
;
1168 if ((hints
= XGetWMHints(ob_display
, self
->window
)) != NULL
) {
1169 if (hints
->flags
& InputHint
)
1170 self
->can_focus
= hints
->input
;
1172 /* only do this when first managing the window *AND* when we aren't
1174 if (ob_state() != OB_STATE_STARTING
&& self
->frame
== NULL
)
1175 if (hints
->flags
& StateHint
)
1176 self
->iconic
= hints
->initial_state
== IconicState
;
1178 if (hints
->flags
& XUrgencyHint
)
1181 if (!(hints
->flags
& WindowGroupHint
))
1182 hints
->window_group
= None
;
1184 /* did the group state change? */
1185 if (hints
->window_group
!=
1186 (self
->group
? self
->group
->leader
: None
)) {
1187 /* remove from the old group if there was one */
1188 if (self
->group
!= NULL
) {
1189 /* remove transients of the group */
1190 for (it
= self
->group
->members
; it
; it
= it
->next
)
1191 self
->transients
= g_slist_remove(self
->transients
,
1193 group_remove(self
->group
, self
);
1196 if (hints
->window_group
!= None
) {
1197 self
->group
= group_add(hints
->window_group
, self
);
1199 /* i can only have transients from the group if i am not
1201 if (!self
->transient_for
) {
1202 /* add other transients of the group that are already
1204 for (it
= self
->group
->members
; it
; it
= it
->next
) {
1205 ObClient
*c
= it
->data
;
1206 if (c
!= self
&& c
->transient_for
== OB_TRAN_GROUP
)
1208 g_slist_append(self
->transients
, c
);
1213 /* the WM_HINTS can contain an icon */
1214 client_update_icons(self
);
1216 /* because the self->transient flag wont change from this call,
1217 we don't need to update the window's type and such, only its
1218 transient_for, and the transients lists of other windows in
1219 the group may be affected */
1220 client_update_transient_for(self
);
1226 if (ur
!= self
->urgent
) {
1228 ob_debug("Urgent Hint for 0x%lx: %s\n", self
->window
,
1230 /* fire the urgent callback if we're mapped, otherwise, wait until
1231 after we're mapped */
1233 dispatch_client(Event_Client_Urgent
, self
, self
->urgent
, 0);
1237 void client_update_title(ObClient
*self
)
1243 gboolean read_title
;
1245 g_free(self
->title
);
1248 if (!PROP_GETS(self
->window
, net_wm_name
, utf8
, &data
))
1249 /* try old x stuff */
1250 if (!PROP_GETS(self
->window
, wm_name
, locale
, &data
))
1251 data
= g_strdup("Unnamed Window");
1253 /* look for duplicates and append a number */
1255 for (it
= client_list
; it
; it
= it
->next
)
1256 if (it
->data
!= self
) {
1257 ObClient
*c
= it
->data
;
1258 if (0 == strncmp(c
->title
, data
, strlen(data
)))
1259 nums
|= 1 << c
->title_count
;
1261 /* find first free number */
1262 for (i
= 1; i
<= 32; ++i
)
1263 if (!(nums
& (1 << i
))) {
1264 if (self
->title_count
== 1 || i
== 1)
1265 self
->title_count
= i
;
1268 /* dont display the number for the first window */
1269 if (self
->title_count
> 1) {
1270 char *vdata
, *ndata
;
1271 ndata
= g_strdup_printf(" - [%u]", self
->title_count
);
1272 vdata
= g_strconcat(data
, ndata
, NULL
);
1278 PROP_SETS(self
->window
, net_wm_visible_name
, data
);
1283 frame_adjust_title(self
->frame
);
1285 /* update the icon title */
1287 g_free(self
->icon_title
);
1291 if (!PROP_GETS(self
->window
, net_wm_icon_name
, utf8
, &data
))
1292 /* try old x stuff */
1293 if (!PROP_GETS(self
->window
, wm_icon_name
, locale
, &data
)) {
1294 data
= g_strdup(self
->title
);
1298 /* append the title count, dont display the number for the first window */
1299 if (read_title
&& self
->title_count
> 1) {
1300 char *vdata
, *ndata
;
1301 ndata
= g_strdup_printf(" - [%u]", self
->title_count
);
1302 vdata
= g_strconcat(data
, ndata
, NULL
);
1308 PROP_SETS(self
->window
, net_wm_visible_icon_name
, data
);
1310 self
->icon_title
= data
;
1313 void client_update_class(ObClient
*self
)
1318 if (self
->name
) g_free(self
->name
);
1319 if (self
->class) g_free(self
->class);
1320 if (self
->role
) g_free(self
->role
);
1322 self
->name
= self
->class = self
->role
= NULL
;
1324 if (PROP_GETSS(self
->window
, wm_class
, locale
, &data
)) {
1326 self
->name
= g_strdup(data
[0]);
1328 self
->class = g_strdup(data
[1]);
1333 if (PROP_GETS(self
->window
, wm_window_role
, locale
, &s
))
1334 self
->role
= g_strdup(s
);
1336 if (self
->name
== NULL
) self
->name
= g_strdup("");
1337 if (self
->class == NULL
) self
->class = g_strdup("");
1338 if (self
->role
== NULL
) self
->role
= g_strdup("");
1341 void client_update_strut(ObClient
*self
)
1346 if (!PROP_GETA32(self
->window
, net_wm_strut
, cardinal
, &data
, &num
)) {
1347 STRUT_SET(self
->strut
, 0, 0, 0, 0);
1350 g_message("new strut: %d %d %d %d",
1351 data
[0], data
[2], data
[1], data
[3]);
1352 STRUT_SET(self
->strut
, data
[0], data
[2], data
[1], data
[3]);
1355 STRUT_SET(self
->strut
, 0, 0, 0, 0);
1359 /* updating here is pointless while we're being mapped cuz we're not in
1360 the client list yet */
1362 screen_update_areas();
1365 void client_update_icons(ObClient
*self
)
1371 for (i
= 0; i
< self
->nicons
; ++i
)
1372 g_free(self
->icons
[i
].data
);
1373 if (self
->nicons
> 0)
1374 g_free(self
->icons
);
1377 if (PROP_GETA32(self
->window
, net_wm_icon
, cardinal
, &data
, &num
)) {
1378 /* figure out how many valid icons are in here */
1380 while (num
- i
> 2) {
1384 if (i
> num
|| w
*h
== 0) break;
1388 self
->icons
= g_new(ObClientIcon
, self
->nicons
);
1390 /* store the icons */
1392 for (j
= 0; j
< self
->nicons
; ++j
) {
1395 w
= self
->icons
[j
].width
= data
[i
++];
1396 h
= self
->icons
[j
].height
= data
[i
++];
1398 if (w
*h
== 0) continue;
1400 self
->icons
[j
].data
= g_new(RrPixel32
, w
* h
);
1401 for (x
= 0, y
= 0, t
= 0; t
< w
* h
; ++t
, ++x
, ++i
) {
1406 self
->icons
[j
].data
[t
] =
1407 (((data
[i
] >> 24) & 0xff) << RrDefaultAlphaOffset
) +
1408 (((data
[i
] >> 16) & 0xff) << RrDefaultRedOffset
) +
1409 (((data
[i
] >> 8) & 0xff) << RrDefaultGreenOffset
) +
1410 (((data
[i
] >> 0) & 0xff) << RrDefaultBlueOffset
);
1416 } else if (PROP_GETA32(self
->window
, kwm_win_icon
,
1417 kwm_win_icon
, &data
, &num
)) {
1420 self
->icons
= g_new(ObClientIcon
, self
->nicons
);
1421 xerror_set_ignore(TRUE
);
1422 if (!RrPixmapToRGBA(ob_rr_inst
,
1424 &self
->icons
[self
->nicons
-1].width
,
1425 &self
->icons
[self
->nicons
-1].height
,
1426 &self
->icons
[self
->nicons
-1].data
)) {
1427 g_free(&self
->icons
[self
->nicons
-1]);
1430 xerror_set_ignore(FALSE
);
1436 if ((hints
= XGetWMHints(ob_display
, self
->window
))) {
1437 if (hints
->flags
& IconPixmapHint
) {
1439 self
->icons
= g_new(ObClientIcon
, self
->nicons
);
1440 xerror_set_ignore(TRUE
);
1441 if (!RrPixmapToRGBA(ob_rr_inst
,
1443 (hints
->flags
& IconMaskHint
?
1444 hints
->icon_mask
: None
),
1445 &self
->icons
[self
->nicons
-1].width
,
1446 &self
->icons
[self
->nicons
-1].height
,
1447 &self
->icons
[self
->nicons
-1].data
)){
1448 g_free(&self
->icons
[self
->nicons
-1]);
1451 xerror_set_ignore(FALSE
);
1458 frame_adjust_icon(self
->frame
);
1461 static void client_change_state(ObClient
*self
)
1464 guint32 netstate
[10];
1467 state
[0] = self
->wmstate
;
1469 PROP_SETA32(self
->window
, wm_state
, wm_state
, state
, 2);
1473 netstate
[num
++] = prop_atoms
.net_wm_state_modal
;
1475 netstate
[num
++] = prop_atoms
.net_wm_state_shaded
;
1477 netstate
[num
++] = prop_atoms
.net_wm_state_hidden
;
1478 if (self
->skip_taskbar
)
1479 netstate
[num
++] = prop_atoms
.net_wm_state_skip_taskbar
;
1480 if (self
->skip_pager
)
1481 netstate
[num
++] = prop_atoms
.net_wm_state_skip_pager
;
1482 if (self
->fullscreen
)
1483 netstate
[num
++] = prop_atoms
.net_wm_state_fullscreen
;
1485 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_vert
;
1487 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_horz
;
1489 netstate
[num
++] = prop_atoms
.net_wm_state_above
;
1491 netstate
[num
++] = prop_atoms
.net_wm_state_below
;
1492 PROP_SETA32(self
->window
, net_wm_state
, atom
, netstate
, num
);
1494 client_calc_layer(self
);
1497 frame_adjust_state(self
->frame
);
1500 ObClient
*client_search_focus_tree(ObClient
*self
)
1505 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
) {
1506 if (client_focused(it
->data
)) return it
->data
;
1507 if ((ret
= client_search_focus_tree(it
->data
))) return ret
;
1512 ObClient
*client_search_focus_tree_full(ObClient
*self
)
1514 if (self
->transient_for
) {
1515 if (self
->transient_for
!= OB_TRAN_GROUP
) {
1516 return client_search_focus_tree_full(self
->transient_for
);
1519 gboolean recursed
= FALSE
;
1521 for (it
= self
->group
->members
; it
; it
= it
->next
)
1522 if (!((ObClient
*)it
->data
)->transient_for
) {
1524 if ((c
= client_search_focus_tree_full(it
->data
)))
1533 /* this function checks the whole tree, the client_search_focus_tree~
1534 does not, so we need to check this window */
1535 if (client_focused(self
))
1537 return client_search_focus_tree(self
);
1540 static ObStackingLayer
calc_layer(ObClient
*self
)
1544 if (self
->fullscreen
) l
= OB_STACKING_LAYER_FULLSCREEN
;
1545 else if (self
->type
== OB_CLIENT_TYPE_DESKTOP
)
1546 l
= OB_STACKING_LAYER_DESKTOP
;
1547 else if (self
->type
== OB_CLIENT_TYPE_DOCK
) {
1548 if (!self
->below
) l
= OB_STACKING_LAYER_TOP
;
1549 else l
= OB_STACKING_LAYER_NORMAL
;
1551 else if (self
->above
) l
= OB_STACKING_LAYER_ABOVE
;
1552 else if (self
->below
) l
= OB_STACKING_LAYER_BELOW
;
1553 else l
= OB_STACKING_LAYER_NORMAL
;
1558 static void client_calc_layer_recursive(ObClient
*self
, ObClient
*orig
,
1559 ObStackingLayer l
, gboolean raised
)
1561 ObStackingLayer old
, own
;
1565 own
= calc_layer(self
);
1566 self
->layer
= l
> own
? l
: own
;
1568 for (it
= self
->transients
; it
; it
= it
->next
)
1569 client_calc_layer_recursive(it
->data
, orig
,
1570 l
, raised
? raised
: l
!= old
);
1572 if (!raised
&& l
!= old
)
1573 if (orig
->frame
) { /* only restack if the original window is managed */
1574 /* XXX add_non_intrusive ever? */
1575 stacking_remove(CLIENT_AS_WINDOW(self
));
1576 stacking_add(CLIENT_AS_WINDOW(self
));
1580 void client_calc_layer(ObClient
*self
)
1587 /* transients take on the layer of their parents */
1588 self
= client_search_top_transient(self
);
1590 l
= calc_layer(self
);
1592 client_calc_layer_recursive(self
, orig
, l
, FALSE
);
1595 gboolean
client_should_show(ObClient
*self
)
1597 if (self
->iconic
) return FALSE
;
1598 else if (!(self
->desktop
== screen_desktop
||
1599 self
->desktop
== DESKTOP_ALL
)) return FALSE
;
1600 else if (client_normal(self
) && screen_showing_desktop
) return FALSE
;
1605 static void client_showhide(ObClient
*self
)
1608 if (client_should_show(self
))
1609 frame_show(self
->frame
);
1611 frame_hide(self
->frame
);
1614 gboolean
client_normal(ObClient
*self
) {
1615 return ! (self
->type
== OB_CLIENT_TYPE_DESKTOP
||
1616 self
->type
== OB_CLIENT_TYPE_DOCK
||
1617 self
->type
== OB_CLIENT_TYPE_SPLASH
);
1620 static void client_apply_startup_state(ObClient
*self
)
1622 /* these are in a carefully crafted order.. */
1625 self
->iconic
= FALSE
;
1626 client_iconify(self
, TRUE
, FALSE
);
1628 if (self
->fullscreen
) {
1629 self
->fullscreen
= FALSE
;
1630 client_fullscreen(self
, TRUE
, FALSE
);
1633 self
->shaded
= FALSE
;
1634 client_shade(self
, TRUE
);
1637 dispatch_client(Event_Client_Urgent
, self
, self
->urgent
, 0);
1639 if (self
->max_vert
&& self
->max_horz
) {
1640 self
->max_vert
= self
->max_horz
= FALSE
;
1641 client_maximize(self
, TRUE
, 0, FALSE
);
1642 } else if (self
->max_vert
) {
1643 self
->max_vert
= FALSE
;
1644 client_maximize(self
, TRUE
, 2, FALSE
);
1645 } else if (self
->max_horz
) {
1646 self
->max_horz
= FALSE
;
1647 client_maximize(self
, TRUE
, 1, FALSE
);
1650 /* nothing to do for the other states:
1659 void client_configure(ObClient
*self
, ObCorner anchor
,
1660 int x
, int y
, int w
, int h
,
1661 gboolean user
, gboolean final
)
1663 gboolean moved
= FALSE
, resized
= FALSE
;
1665 /* gets the frame's position */
1666 frame_client_gravity(self
->frame
, &x
, &y
);
1668 /* these positions are frame positions, not client positions */
1670 /* set the size and position if fullscreen */
1671 if (self
->fullscreen
) {
1674 XF86VidModeModeLine mode
;
1679 i
= client_monitor(self
);
1680 a
= screen_physical_area_monitor(i
);
1683 if (i
== 0 && /* primary head */
1684 extensions_vidmode
&&
1685 XF86VidModeGetViewPort(ob_display
, ob_screen
, &x
, &y
) &&
1686 /* get the mode last so the mode.privsize isnt freed incorrectly */
1687 XF86VidModeGetModeLine(ob_display
, ob_screen
, &dot
, &mode
)) {
1692 if (mode
.privsize
) XFree(mode
.private);
1702 user
= FALSE
; /* ignore that increment etc shit when in fullscreen */
1706 a
= screen_area_monitor(self
->desktop
, client_monitor(self
));
1708 /* set the size and position if maximized */
1709 if (self
->max_horz
) {
1710 x
= a
->x
- self
->frame
->size
.left
;
1713 if (self
->max_vert
) {
1715 h
= a
->height
- self
->frame
->size
.top
- self
->frame
->size
.bottom
;
1719 /* gets the client's position */
1720 frame_frame_gravity(self
->frame
, &x
, &y
);
1722 /* these override the above states! if you cant move you can't move! */
1724 if (!(self
->functions
& OB_CLIENT_FUNC_MOVE
)) {
1728 if (!(self
->functions
& OB_CLIENT_FUNC_RESIZE
)) {
1729 w
= self
->area
.width
;
1730 h
= self
->area
.height
;
1734 if (!(w
== self
->area
.width
&& h
== self
->area
.height
)) {
1735 int basew
, baseh
, minw
, minh
;
1737 /* base size is substituted with min size if not specified */
1738 if (self
->base_size
.width
|| self
->base_size
.height
) {
1739 basew
= self
->base_size
.width
;
1740 baseh
= self
->base_size
.height
;
1742 basew
= self
->min_size
.width
;
1743 baseh
= self
->min_size
.height
;
1745 /* min size is substituted with base size if not specified */
1746 if (self
->min_size
.width
|| self
->min_size
.height
) {
1747 minw
= self
->min_size
.width
;
1748 minh
= self
->min_size
.height
;
1750 minw
= self
->base_size
.width
;
1751 minh
= self
->base_size
.height
;
1755 /* for interactive resizing. have to move half an increment in each
1758 /* how far we are towards the next size inc */
1759 int mw
= (w
- basew
) % self
->size_inc
.width
;
1760 int mh
= (h
- baseh
) % self
->size_inc
.height
;
1762 int aw
= self
->size_inc
.width
/ 2;
1763 int ah
= self
->size_inc
.height
/ 2;
1764 /* don't let us move into a new size increment */
1765 if (mw
+ aw
>= self
->size_inc
.width
)
1766 aw
= self
->size_inc
.width
- mw
- 1;
1767 if (mh
+ ah
>= self
->size_inc
.height
)
1768 ah
= self
->size_inc
.height
- mh
- 1;
1772 /* if this is a user-requested resize, then check against min/max
1775 /* smaller than min size or bigger than max size? */
1776 if (w
> self
->max_size
.width
) w
= self
->max_size
.width
;
1777 if (w
< minw
) w
= minw
;
1778 if (h
> self
->max_size
.height
) h
= self
->max_size
.height
;
1779 if (h
< minh
) h
= minh
;
1785 /* keep to the increments */
1786 w
/= self
->size_inc
.width
;
1787 h
/= self
->size_inc
.height
;
1789 /* you cannot resize to nothing */
1793 /* store the logical size */
1794 SIZE_SET(self
->logical_size
, w
, h
);
1796 w
*= self
->size_inc
.width
;
1797 h
*= self
->size_inc
.height
;
1803 /* adjust the height to match the width for the aspect ratios.
1804 for this, min size is not substituted for base size ever. */
1805 w
-= self
->base_size
.width
;
1806 h
-= self
->base_size
.height
;
1808 if (self
->min_ratio
)
1809 if (h
* self
->min_ratio
> w
) h
= (int)(w
/ self
->min_ratio
);
1810 if (self
->max_ratio
)
1811 if (h
* self
->max_ratio
< w
) h
= (int)(w
/ self
->max_ratio
);
1813 w
+= self
->base_size
.width
;
1814 h
+= self
->base_size
.height
;
1819 case OB_CORNER_TOPLEFT
:
1821 case OB_CORNER_TOPRIGHT
:
1822 x
-= w
- self
->area
.width
;
1824 case OB_CORNER_BOTTOMLEFT
:
1825 y
-= h
- self
->area
.height
;
1827 case OB_CORNER_BOTTOMRIGHT
:
1828 x
-= w
- self
->area
.width
;
1829 y
-= h
- self
->area
.height
;
1833 moved
= x
!= self
->area
.x
|| y
!= self
->area
.y
;
1834 resized
= w
!= self
->area
.width
|| h
!= self
->area
.height
;
1836 RECT_SET(self
->area
, x
, y
, w
, h
);
1838 /* for app-requested resizes, always resize if 'resized' is true.
1839 for user-requested ones, only resize if final is true, or when
1840 resizing in opaque mode */
1841 if ((!user
&& resized
) ||
1842 (user
&& (final
|| (resized
&& config_opaque_resize
))))
1843 XResizeWindow(ob_display
, self
->window
, w
, h
);
1845 /* move/resize the frame to match the request */
1847 if (self
->decorations
!= self
->frame
->decorations
)
1848 moved
= resized
= TRUE
;
1850 if (moved
|| resized
)
1851 frame_adjust_area(self
->frame
, moved
, resized
);
1853 /* If you send this and the client hasn't changed you end up with buggy
1854 clients (emacs) freaking out, cuz they send back a configure every
1855 time they receive this event, which resends them this event... etc.
1857 if ((!user
&& moved
) || (user
&& final
)) {
1859 event
.type
= ConfigureNotify
;
1860 event
.xconfigure
.display
= ob_display
;
1861 event
.xconfigure
.event
= self
->window
;
1862 event
.xconfigure
.window
= self
->window
;
1864 /* root window real coords */
1865 event
.xconfigure
.x
= self
->frame
->area
.x
+ self
->frame
->size
.left
;
1866 event
.xconfigure
.y
= self
->frame
->area
.y
+ self
->frame
->size
.top
;
1868 event
.xconfigure
.width
= w
;
1869 event
.xconfigure
.height
= h
;
1870 event
.xconfigure
.border_width
= 0;
1871 event
.xconfigure
.above
= self
->frame
->plate
;
1872 event
.xconfigure
.override_redirect
= FALSE
;
1873 XSendEvent(event
.xconfigure
.display
, event
.xconfigure
.window
,
1874 FALSE
, StructureNotifyMask
, &event
);
1879 void client_fullscreen(ObClient
*self
, gboolean fs
, gboolean savearea
)
1883 if (!(self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
) || /* can't */
1884 self
->fullscreen
== fs
) return; /* already done */
1886 self
->fullscreen
= fs
;
1887 client_change_state(self
); /* change the state hints on the client,
1888 and adjust out layer/stacking */
1892 guint32 dimensions
[4];
1893 dimensions
[0] = self
->area
.x
;
1894 dimensions
[1] = self
->area
.y
;
1895 dimensions
[2] = self
->area
.width
;
1896 dimensions
[3] = self
->area
.height
;
1898 PROP_SETA32(self
->window
, openbox_premax
, cardinal
,
1902 /* these are not actually used cuz client_configure will set them
1903 as appropriate when the window is fullscreened */
1910 /* pick some fallbacks... */
1911 a
= screen_area_monitor(self
->desktop
, 0);
1912 x
= a
->x
+ a
->width
/ 4;
1913 y
= a
->y
+ a
->height
/ 4;
1917 if (PROP_GETA32(self
->window
, openbox_premax
, cardinal
,
1918 (guint32
**)&dimensions
, &num
)) {
1929 client_setup_decor_and_functions(self
);
1931 client_configure(self
, OB_CORNER_TOPLEFT
, x
, y
, w
, h
, TRUE
, TRUE
);
1933 /* try focus us when we go into fullscreen mode */
1937 static void client_iconify_recursive(ObClient
*self
,
1938 gboolean iconic
, gboolean curdesk
)
1941 gboolean changed
= FALSE
;
1944 if (self
->iconic
!= iconic
) {
1945 ob_debug("%sconifying window: 0x%lx\n", (iconic
? "I" : "Uni"),
1948 self
->iconic
= iconic
;
1951 if (self
->functions
& OB_CLIENT_FUNC_ICONIFY
) {
1952 self
->wmstate
= IconicState
;
1953 self
->ignore_unmaps
++;
1954 /* we unmap the client itself so that we can get MapRequest
1955 events, and because the ICCCM tells us to! */
1956 XUnmapWindow(ob_display
, self
->window
);
1958 /* update the focus lists.. iconic windows go to the bottom of
1959 the list, put the new iconic window at the 'top of the
1961 focus_order_to_top(self
);
1967 client_set_desktop(self
, screen_desktop
, FALSE
);
1968 self
->wmstate
= self
->shaded
? IconicState
: NormalState
;
1969 XMapWindow(ob_display
, self
->window
);
1971 /* this puts it after the current focused window */
1972 focus_order_remove(self
);
1973 focus_order_add_new(self
);
1975 /* this is here cuz with the VIDMODE extension, the viewport can
1976 change while a fullscreen window is iconic, and when it
1977 uniconifies, it would be nice if it did so to the new position
1979 client_reconfigure(self
);
1986 client_change_state(self
);
1987 client_showhide(self
);
1988 screen_update_areas();
1990 dispatch_client(iconic
? Event_Client_Unmapped
: Event_Client_Mapped
,
1994 /* iconify all transients */
1995 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
)
1996 if (it
->data
!= self
) client_iconify_recursive(it
->data
,
2000 void client_iconify(ObClient
*self
, gboolean iconic
, gboolean curdesk
)
2002 /* move up the transient chain as far as possible first */
2003 self
= client_search_top_transient(self
);
2005 client_iconify_recursive(client_search_top_transient(self
),
2009 void client_maximize(ObClient
*self
, gboolean max
, int dir
, gboolean savearea
)
2013 g_assert(dir
== 0 || dir
== 1 || dir
== 2);
2014 if (!(self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
)) return; /* can't */
2016 /* check if already done */
2018 if (dir
== 0 && self
->max_horz
&& self
->max_vert
) return;
2019 if (dir
== 1 && self
->max_horz
) return;
2020 if (dir
== 2 && self
->max_vert
) return;
2022 if (dir
== 0 && !self
->max_horz
&& !self
->max_vert
) return;
2023 if (dir
== 1 && !self
->max_horz
) return;
2024 if (dir
== 2 && !self
->max_vert
) return;
2027 /* work with the frame's coords */
2028 x
= self
->frame
->area
.x
;
2029 y
= self
->frame
->area
.y
;
2030 w
= self
->area
.width
;
2031 h
= self
->area
.height
;
2035 gint32 dimensions
[4];
2044 /* get the property off the window and use it for the dimensions
2045 we are already maxed on */
2046 if (PROP_GETA32(self
->window
, openbox_premax
, cardinal
,
2047 (guint32
**)&readdim
, &num
)) {
2049 if (self
->max_horz
) {
2050 dimensions
[0] = readdim
[0];
2051 dimensions
[2] = readdim
[2];
2053 if (self
->max_vert
) {
2054 dimensions
[1] = readdim
[1];
2055 dimensions
[3] = readdim
[3];
2061 PROP_SETA32(self
->window
, openbox_premax
, cardinal
,
2062 (guint32
*)dimensions
, 4);
2069 /* pick some fallbacks... */
2070 a
= screen_area_monitor(self
->desktop
, 0);
2071 if (dir
== 0 || dir
== 1) { /* horz */
2072 x
= a
->x
+ a
->width
/ 4;
2075 if (dir
== 0 || dir
== 2) { /* vert */
2076 y
= a
->y
+ a
->height
/ 4;
2080 if (PROP_GETA32(self
->window
, openbox_premax
, cardinal
,
2081 (guint32
**)&dimensions
, &num
)) {
2083 if (dir
== 0 || dir
== 1) { /* horz */
2087 if (dir
== 0 || dir
== 2) { /* vert */
2096 if (dir
== 0 || dir
== 1) /* horz */
2097 self
->max_horz
= max
;
2098 if (dir
== 0 || dir
== 2) /* vert */
2099 self
->max_vert
= max
;
2101 if (!self
->max_horz
&& !self
->max_vert
)
2102 PROP_ERASE(self
->window
, openbox_premax
);
2104 client_change_state(self
); /* change the state hints on the client */
2106 /* figure out where the client should be going */
2107 frame_frame_gravity(self
->frame
, &x
, &y
);
2108 client_configure(self
, OB_CORNER_TOPLEFT
, x
, y
, w
, h
, TRUE
, TRUE
);
2111 void client_shade(ObClient
*self
, gboolean shade
)
2113 if ((!(self
->functions
& OB_CLIENT_FUNC_SHADE
) &&
2114 shade
) || /* can't shade */
2115 self
->shaded
== shade
) return; /* already done */
2117 /* when we're iconic, don't change the wmstate */
2119 self
->wmstate
= shade
? IconicState
: NormalState
;
2120 self
->shaded
= shade
;
2121 client_change_state(self
);
2122 /* resize the frame to just the titlebar */
2123 frame_adjust_area(self
->frame
, FALSE
, FALSE
);
2126 void client_close(ObClient
*self
)
2130 if (!(self
->functions
& OB_CLIENT_FUNC_CLOSE
)) return;
2133 XXX: itd be cool to do timeouts and shit here for killing the client's
2135 like... if the window is around after 5 seconds, then the close button
2136 turns a nice red, and if this function is called again, the client is
2140 ce
.xclient
.type
= ClientMessage
;
2141 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
2142 ce
.xclient
.display
= ob_display
;
2143 ce
.xclient
.window
= self
->window
;
2144 ce
.xclient
.format
= 32;
2145 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_delete_window
;
2146 ce
.xclient
.data
.l
[1] = event_lasttime
;
2147 ce
.xclient
.data
.l
[2] = 0l;
2148 ce
.xclient
.data
.l
[3] = 0l;
2149 ce
.xclient
.data
.l
[4] = 0l;
2150 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
2153 void client_kill(ObClient
*self
)
2155 XKillClient(ob_display
, self
->window
);
2158 void client_set_desktop_recursive(ObClient
*self
,
2159 guint target
, gboolean donthide
)
2164 if (target
!= self
->desktop
) {
2166 ob_debug("Setting desktop %u\n", target
+1);
2168 g_assert(target
< screen_num_desktops
|| target
== DESKTOP_ALL
);
2170 /* remove from the old desktop(s) */
2171 focus_order_remove(self
);
2173 old
= self
->desktop
;
2174 self
->desktop
= target
;
2175 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, target
);
2176 /* the frame can display the current desktop state */
2177 frame_adjust_state(self
->frame
);
2178 /* 'move' the window to the new desktop */
2180 client_showhide(self
);
2181 /* raise if it was not already on the desktop */
2182 if (old
!= DESKTOP_ALL
)
2183 stacking_raise(CLIENT_AS_WINDOW(self
));
2184 screen_update_areas();
2186 /* add to the new desktop(s) */
2187 if (config_focus_new
)
2188 focus_order_to_top(self
);
2190 focus_order_to_bottom(self
);
2192 dispatch_client(Event_Client_Desktop
, self
, target
, old
);
2195 /* move all transients */
2196 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
)
2197 if (it
->data
!= self
) client_set_desktop_recursive(it
->data
,
2201 void client_set_desktop(ObClient
*self
, guint target
, gboolean donthide
)
2203 client_set_desktop_recursive(client_search_top_transient(self
),
2207 ObClient
*client_search_modal_child(ObClient
*self
)
2212 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
) {
2213 ObClient
*c
= it
->data
;
2214 if ((ret
= client_search_modal_child(c
))) return ret
;
2215 if (c
->modal
) return c
;
2220 gboolean
client_validate(ObClient
*self
)
2224 XSync(ob_display
, FALSE
); /* get all events on the server */
2226 if (XCheckTypedWindowEvent(ob_display
, self
->window
, DestroyNotify
, &e
) ||
2227 XCheckTypedWindowEvent(ob_display
, self
->window
, UnmapNotify
, &e
)) {
2228 XPutBackEvent(ob_display
, &e
);
2235 void client_set_wm_state(ObClient
*self
, long state
)
2237 if (state
== self
->wmstate
) return; /* no change */
2241 client_iconify(self
, TRUE
, TRUE
);
2244 client_iconify(self
, FALSE
, TRUE
);
2249 void client_set_state(ObClient
*self
, Atom action
, long data1
, long data2
)
2251 gboolean shaded
= self
->shaded
;
2252 gboolean fullscreen
= self
->fullscreen
;
2253 gboolean max_horz
= self
->max_horz
;
2254 gboolean max_vert
= self
->max_vert
;
2257 if (!(action
== prop_atoms
.net_wm_state_add
||
2258 action
== prop_atoms
.net_wm_state_remove
||
2259 action
== prop_atoms
.net_wm_state_toggle
))
2260 /* an invalid action was passed to the client message, ignore it */
2263 for (i
= 0; i
< 2; ++i
) {
2264 Atom state
= i
== 0 ? data1
: data2
;
2266 if (!state
) continue;
2268 /* if toggling, then pick whether we're adding or removing */
2269 if (action
== prop_atoms
.net_wm_state_toggle
) {
2270 if (state
== prop_atoms
.net_wm_state_modal
)
2271 action
= self
->modal
? prop_atoms
.net_wm_state_remove
:
2272 prop_atoms
.net_wm_state_add
;
2273 else if (state
== prop_atoms
.net_wm_state_maximized_vert
)
2274 action
= self
->max_vert
? prop_atoms
.net_wm_state_remove
:
2275 prop_atoms
.net_wm_state_add
;
2276 else if (state
== prop_atoms
.net_wm_state_maximized_horz
)
2277 action
= self
->max_horz
? prop_atoms
.net_wm_state_remove
:
2278 prop_atoms
.net_wm_state_add
;
2279 else if (state
== prop_atoms
.net_wm_state_shaded
)
2280 action
= self
->shaded
? prop_atoms
.net_wm_state_remove
:
2281 prop_atoms
.net_wm_state_add
;
2282 else if (state
== prop_atoms
.net_wm_state_skip_taskbar
)
2283 action
= self
->skip_taskbar
?
2284 prop_atoms
.net_wm_state_remove
:
2285 prop_atoms
.net_wm_state_add
;
2286 else if (state
== prop_atoms
.net_wm_state_skip_pager
)
2287 action
= self
->skip_pager
?
2288 prop_atoms
.net_wm_state_remove
:
2289 prop_atoms
.net_wm_state_add
;
2290 else if (state
== prop_atoms
.net_wm_state_fullscreen
)
2291 action
= self
->fullscreen
?
2292 prop_atoms
.net_wm_state_remove
:
2293 prop_atoms
.net_wm_state_add
;
2294 else if (state
== prop_atoms
.net_wm_state_above
)
2295 action
= self
->above
? prop_atoms
.net_wm_state_remove
:
2296 prop_atoms
.net_wm_state_add
;
2297 else if (state
== prop_atoms
.net_wm_state_below
)
2298 action
= self
->below
? prop_atoms
.net_wm_state_remove
:
2299 prop_atoms
.net_wm_state_add
;
2302 if (action
== prop_atoms
.net_wm_state_add
) {
2303 if (state
== prop_atoms
.net_wm_state_modal
) {
2304 /* XXX raise here or something? */
2306 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
2308 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
2310 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
2312 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
2313 self
->skip_taskbar
= TRUE
;
2314 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
2315 self
->skip_pager
= TRUE
;
2316 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
2318 } else if (state
== prop_atoms
.net_wm_state_above
) {
2320 } else if (state
== prop_atoms
.net_wm_state_below
) {
2324 } else { /* action == prop_atoms.net_wm_state_remove */
2325 if (state
== prop_atoms
.net_wm_state_modal
) {
2326 self
->modal
= FALSE
;
2327 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
2329 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
2331 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
2333 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
2334 self
->skip_taskbar
= FALSE
;
2335 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
2336 self
->skip_pager
= FALSE
;
2337 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
2339 } else if (state
== prop_atoms
.net_wm_state_above
) {
2340 self
->above
= FALSE
;
2341 } else if (state
== prop_atoms
.net_wm_state_below
) {
2342 self
->below
= FALSE
;
2346 if (max_horz
!= self
->max_horz
|| max_vert
!= self
->max_vert
) {
2347 if (max_horz
!= self
->max_horz
&& max_vert
!= self
->max_vert
) {
2349 if (max_horz
== max_vert
) { /* both going the same way */
2350 client_maximize(self
, max_horz
, 0, TRUE
);
2352 client_maximize(self
, max_horz
, 1, TRUE
);
2353 client_maximize(self
, max_vert
, 2, TRUE
);
2357 if (max_horz
!= self
->max_horz
)
2358 client_maximize(self
, max_horz
, 1, TRUE
);
2360 client_maximize(self
, max_vert
, 2, TRUE
);
2363 /* change fullscreen state before shading, as it will affect if the window
2365 if (fullscreen
!= self
->fullscreen
)
2366 client_fullscreen(self
, fullscreen
, TRUE
);
2367 if (shaded
!= self
->shaded
)
2368 client_shade(self
, shaded
);
2369 client_calc_layer(self
);
2370 client_change_state(self
); /* change the hint to reflect these changes */
2373 ObClient
*client_focus_target(ObClient
*self
)
2377 /* if we have a modal child, then focus it, not us */
2378 child
= client_search_modal_child(self
);
2379 if (child
) return child
;
2383 gboolean
client_can_focus(ObClient
*self
)
2387 /* choose the correct target */
2388 self
= client_focus_target(self
);
2390 if (!self
->frame
->visible
)
2393 if (!((self
->can_focus
|| self
->focus_notify
) &&
2394 (self
->desktop
== screen_desktop
||
2395 self
->desktop
== DESKTOP_ALL
) &&
2399 /* do a check to see if the window has already been unmapped or destroyed
2400 do this intelligently while watching out for unmaps we've generated
2401 (ignore_unmaps > 0) */
2402 if (XCheckTypedWindowEvent(ob_display
, self
->window
,
2403 DestroyNotify
, &ev
)) {
2404 XPutBackEvent(ob_display
, &ev
);
2407 while (XCheckTypedWindowEvent(ob_display
, self
->window
,
2408 UnmapNotify
, &ev
)) {
2409 if (self
->ignore_unmaps
) {
2410 self
->ignore_unmaps
--;
2412 XPutBackEvent(ob_display
, &ev
);
2420 gboolean
client_focus(ObClient
*self
)
2422 /* choose the correct target */
2423 self
= client_focus_target(self
);
2425 if (!client_can_focus(self
)) {
2426 if (!self
->frame
->visible
) {
2427 /* update the focus lists */
2428 focus_order_to_top(self
);
2433 if (self
->can_focus
)
2434 /* RevertToPointerRoot causes much more headache than RevertToNone, so
2435 I choose to use it always, hopefully to find errors quicker, if any
2436 are left. (I hate X. I hate focus events.) */
2437 XSetInputFocus(ob_display
, self
->window
, RevertToPointerRoot
,
2440 if (self
->focus_notify
) {
2442 ce
.xclient
.type
= ClientMessage
;
2443 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
2444 ce
.xclient
.display
= ob_display
;
2445 ce
.xclient
.window
= self
->window
;
2446 ce
.xclient
.format
= 32;
2447 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_take_focus
;
2448 ce
.xclient
.data
.l
[1] = event_lasttime
;
2449 ce
.xclient
.data
.l
[2] = 0l;
2450 ce
.xclient
.data
.l
[3] = 0l;
2451 ce
.xclient
.data
.l
[4] = 0l;
2452 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
2456 ob_debug("%sively focusing %lx at %d\n",
2457 (self
->can_focus
? "act" : "pass"),
2458 self
->window
, (int) event_lasttime
);
2461 /* Cause the FocusIn to come back to us. Important for desktop switches,
2462 since otherwise we'll have no FocusIn on the queue and send it off to
2463 the focus_backup. */
2464 XSync(ob_display
, FALSE
);
2468 void client_unfocus(ObClient
*self
)
2470 g_assert(focus_client
== self
);
2472 ob_debug("client_unfocus for %lx\n", self
->window
);
2474 focus_fallback(OB_FOCUS_FALLBACK_UNFOCUSING
);
2477 void client_activate(ObClient
*self
)
2479 if (client_normal(self
) && screen_showing_desktop
)
2480 screen_show_desktop(FALSE
);
2482 client_iconify(self
, FALSE
, FALSE
);
2483 if (self
->desktop
!= DESKTOP_ALL
&&
2484 self
->desktop
!= screen_desktop
)
2485 screen_set_desktop(self
->desktop
);
2486 else if (!self
->frame
->visible
)
2487 /* if its not visible for other reasons, then don't mess
2491 client_shade(self
, FALSE
);
2493 stacking_raise(CLIENT_AS_WINDOW(self
));
2496 gboolean
client_focused(ObClient
*self
)
2498 return self
== focus_client
;
2501 ObClientIcon
*client_icon(ObClient
*self
, int w
, int h
)
2504 /* si is the smallest image >= req */
2505 /* li is the largest image < req */
2506 unsigned long size
, smallest
= 0xffffffff, largest
= 0, si
= 0, li
= 0;
2508 if (!self
->nicons
) return NULL
;
2510 for (i
= 0; i
< self
->nicons
; ++i
) {
2511 size
= self
->icons
[i
].width
* self
->icons
[i
].height
;
2512 if (size
< smallest
&& size
>= (unsigned)(w
* h
)) {
2516 if (size
> largest
&& size
<= (unsigned)(w
* h
)) {
2521 if (largest
== 0) /* didnt find one smaller than the requested size */
2522 return &self
->icons
[si
];
2523 return &self
->icons
[li
];
2526 /* this be mostly ripped from fvwm */
2527 ObClient
*client_find_directional(ObClient
*c
, ObDirection dir
)
2529 int my_cx
, my_cy
, his_cx
, his_cy
;
2532 int score
, best_score
;
2533 ObClient
*best_client
, *cur
;
2539 /* first, find the centre coords of the currently focused window */
2540 my_cx
= c
->frame
->area
.x
+ c
->frame
->area
.width
/ 2;
2541 my_cy
= c
->frame
->area
.y
+ c
->frame
->area
.height
/ 2;
2546 for(it
= g_list_first(client_list
); it
; it
= it
->next
) {
2549 /* the currently selected window isn't interesting */
2552 if (!client_normal(cur
))
2554 if(c
->desktop
!= cur
->desktop
&& cur
->desktop
!= DESKTOP_ALL
)
2558 if(client_focus_target(cur
) == cur
&&
2559 !(cur
->can_focus
|| cur
->focus_notify
))
2562 /* find the centre coords of this window, from the
2563 * currently focused window's point of view */
2564 his_cx
= (cur
->frame
->area
.x
- my_cx
)
2565 + cur
->frame
->area
.width
/ 2;
2566 his_cy
= (cur
->frame
->area
.y
- my_cy
)
2567 + cur
->frame
->area
.height
/ 2;
2571 /* Rotate the diagonals 45 degrees counterclockwise.
2572 * To do this, multiply the matrix /+h +h\ with the
2573 * vector (x y). \-h +h/
2574 * h = sqrt(0.5). We can set h := 1 since absolute
2575 * distance doesn't matter here. */
2576 tx
= his_cx
+ his_cy
;
2577 his_cy
= -his_cx
+ his_cy
;
2582 case OB_DIRECTION_NORTH
:
2583 case OB_DIRECTION_SOUTH
:
2584 case OB_DIRECTION_NORTHEAST
:
2585 case OB_DIRECTION_SOUTHWEST
:
2586 offset
= (his_cx
< 0) ? -his_cx
: his_cx
;
2587 distance
= ((dir
== OB_DIRECTION_NORTH
||
2588 dir
== OB_DIRECTION_NORTHEAST
) ?
2591 case OB_DIRECTION_EAST
:
2592 case OB_DIRECTION_WEST
:
2593 case OB_DIRECTION_SOUTHEAST
:
2594 case OB_DIRECTION_NORTHWEST
:
2595 offset
= (his_cy
< 0) ? -his_cy
: his_cy
;
2596 distance
= ((dir
== OB_DIRECTION_WEST
||
2597 dir
== OB_DIRECTION_NORTHWEST
) ?
2602 /* the target must be in the requested direction */
2606 /* Calculate score for this window. The smaller the better. */
2607 score
= distance
+ offset
;
2609 /* windows more than 45 degrees off the direction are
2610 * heavily penalized and will only be chosen if nothing
2611 * else within a million pixels */
2612 if(offset
> distance
)
2615 if(best_score
== -1 || score
< best_score
)
2623 void client_set_layer(ObClient
*self
, int layer
)
2627 self
->above
= FALSE
;
2628 } else if (layer
== 0) {
2629 self
->below
= self
->above
= FALSE
;
2631 self
->below
= FALSE
;
2634 client_calc_layer(self
);
2635 client_change_state(self
); /* reflect this in the state hints */
2638 guint
client_monitor(ObClient
*self
)
2642 for (i
= 0; i
< screen_num_monitors
; ++i
) {
2643 Rect
*area
= screen_physical_area_monitor(i
);
2644 if (RECT_INTERSECTS_RECT(*area
, self
->frame
->area
))
2647 if (i
== screen_num_monitors
) i
= 0;
2648 g_assert(i
< screen_num_monitors
);
2652 ObClient
*client_search_top_transient(ObClient
*self
)
2654 /* move up the transient chain as far as possible */
2655 if (self
->transient_for
) {
2656 if (self
->transient_for
!= OB_TRAN_GROUP
) {
2657 return client_search_top_transient(self
->transient_for
);
2661 for (it
= self
->group
->members
; it
; it
= it
->next
) {
2662 ObClient
*c
= it
->data
;
2664 /* checking transient_for prevents infinate loops! */
2665 if (c
!= self
&& !c
->transient_for
)
2676 ObClient
*client_search_transient(ObClient
*self
, ObClient
*search
)
2680 for (sit
= self
->transients
; sit
; sit
= g_slist_next(sit
)) {
2681 if (sit
->data
== search
)
2683 if (client_search_transient(sit
->data
, search
))