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 (*x
>= a
->x
+ a
->width
- 1)
482 *x
= a
->x
+ a
->width
- self
->frame
->area
.width
;
483 if (*y
>= a
->y
+ a
->height
- 1)
484 *y
= a
->y
+ a
->height
- self
->frame
->area
.height
;
485 if (*x
+ self
->frame
->area
.width
- 1 < a
->x
)
487 if (*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 (*x
< a
->x
) *x
= a
->x
;
498 if (*x
+ w
> a
->x
+ a
->width
)
499 *x
= a
->x
+ a
->width
- w
;
501 if (h
<= a
->height
) {
502 if (*y
< a
->y
) *y
= a
->y
;
503 if (*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 STRUT_SET(self
->strut
, data
[0], data
[2], data
[1], data
[3]);
1352 STRUT_SET(self
->strut
, 0, 0, 0, 0);
1356 /* updating here is pointless while we're being mapped cuz we're not in
1357 the client list yet */
1359 screen_update_areas();
1362 void client_update_icons(ObClient
*self
)
1368 for (i
= 0; i
< self
->nicons
; ++i
)
1369 g_free(self
->icons
[i
].data
);
1370 if (self
->nicons
> 0)
1371 g_free(self
->icons
);
1374 if (PROP_GETA32(self
->window
, net_wm_icon
, cardinal
, &data
, &num
)) {
1375 /* figure out how many valid icons are in here */
1377 while (num
- i
> 2) {
1381 if (i
> num
|| w
*h
== 0) break;
1385 self
->icons
= g_new(ObClientIcon
, self
->nicons
);
1387 /* store the icons */
1389 for (j
= 0; j
< self
->nicons
; ++j
) {
1392 w
= self
->icons
[j
].width
= data
[i
++];
1393 h
= self
->icons
[j
].height
= data
[i
++];
1395 if (w
*h
== 0) continue;
1397 self
->icons
[j
].data
= g_new(RrPixel32
, w
* h
);
1398 for (x
= 0, y
= 0, t
= 0; t
< w
* h
; ++t
, ++x
, ++i
) {
1403 self
->icons
[j
].data
[t
] =
1404 (((data
[i
] >> 24) & 0xff) << RrDefaultAlphaOffset
) +
1405 (((data
[i
] >> 16) & 0xff) << RrDefaultRedOffset
) +
1406 (((data
[i
] >> 8) & 0xff) << RrDefaultGreenOffset
) +
1407 (((data
[i
] >> 0) & 0xff) << RrDefaultBlueOffset
);
1413 } else if (PROP_GETA32(self
->window
, kwm_win_icon
,
1414 kwm_win_icon
, &data
, &num
)) {
1417 self
->icons
= g_new(ObClientIcon
, self
->nicons
);
1418 xerror_set_ignore(TRUE
);
1419 if (!RrPixmapToRGBA(ob_rr_inst
,
1421 &self
->icons
[self
->nicons
-1].width
,
1422 &self
->icons
[self
->nicons
-1].height
,
1423 &self
->icons
[self
->nicons
-1].data
)) {
1424 g_free(&self
->icons
[self
->nicons
-1]);
1427 xerror_set_ignore(FALSE
);
1433 if ((hints
= XGetWMHints(ob_display
, self
->window
))) {
1434 if (hints
->flags
& IconPixmapHint
) {
1436 self
->icons
= g_new(ObClientIcon
, self
->nicons
);
1437 xerror_set_ignore(TRUE
);
1438 if (!RrPixmapToRGBA(ob_rr_inst
,
1440 (hints
->flags
& IconMaskHint
?
1441 hints
->icon_mask
: None
),
1442 &self
->icons
[self
->nicons
-1].width
,
1443 &self
->icons
[self
->nicons
-1].height
,
1444 &self
->icons
[self
->nicons
-1].data
)){
1445 g_free(&self
->icons
[self
->nicons
-1]);
1448 xerror_set_ignore(FALSE
);
1455 frame_adjust_icon(self
->frame
);
1458 static void client_change_state(ObClient
*self
)
1461 guint32 netstate
[10];
1464 state
[0] = self
->wmstate
;
1466 PROP_SETA32(self
->window
, wm_state
, wm_state
, state
, 2);
1470 netstate
[num
++] = prop_atoms
.net_wm_state_modal
;
1472 netstate
[num
++] = prop_atoms
.net_wm_state_shaded
;
1474 netstate
[num
++] = prop_atoms
.net_wm_state_hidden
;
1475 if (self
->skip_taskbar
)
1476 netstate
[num
++] = prop_atoms
.net_wm_state_skip_taskbar
;
1477 if (self
->skip_pager
)
1478 netstate
[num
++] = prop_atoms
.net_wm_state_skip_pager
;
1479 if (self
->fullscreen
)
1480 netstate
[num
++] = prop_atoms
.net_wm_state_fullscreen
;
1482 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_vert
;
1484 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_horz
;
1486 netstate
[num
++] = prop_atoms
.net_wm_state_above
;
1488 netstate
[num
++] = prop_atoms
.net_wm_state_below
;
1489 PROP_SETA32(self
->window
, net_wm_state
, atom
, netstate
, num
);
1491 client_calc_layer(self
);
1494 frame_adjust_state(self
->frame
);
1497 ObClient
*client_search_focus_tree(ObClient
*self
)
1502 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
) {
1503 if (client_focused(it
->data
)) return it
->data
;
1504 if ((ret
= client_search_focus_tree(it
->data
))) return ret
;
1509 ObClient
*client_search_focus_tree_full(ObClient
*self
)
1511 if (self
->transient_for
) {
1512 if (self
->transient_for
!= OB_TRAN_GROUP
) {
1513 return client_search_focus_tree_full(self
->transient_for
);
1516 gboolean recursed
= FALSE
;
1518 for (it
= self
->group
->members
; it
; it
= it
->next
)
1519 if (!((ObClient
*)it
->data
)->transient_for
) {
1521 if ((c
= client_search_focus_tree_full(it
->data
)))
1530 /* this function checks the whole tree, the client_search_focus_tree~
1531 does not, so we need to check this window */
1532 if (client_focused(self
))
1534 return client_search_focus_tree(self
);
1537 static ObStackingLayer
calc_layer(ObClient
*self
)
1541 if (self
->fullscreen
) l
= OB_STACKING_LAYER_FULLSCREEN
;
1542 else if (self
->type
== OB_CLIENT_TYPE_DESKTOP
)
1543 l
= OB_STACKING_LAYER_DESKTOP
;
1544 else if (self
->type
== OB_CLIENT_TYPE_DOCK
) {
1545 if (!self
->below
) l
= OB_STACKING_LAYER_TOP
;
1546 else l
= OB_STACKING_LAYER_NORMAL
;
1548 else if (self
->above
) l
= OB_STACKING_LAYER_ABOVE
;
1549 else if (self
->below
) l
= OB_STACKING_LAYER_BELOW
;
1550 else l
= OB_STACKING_LAYER_NORMAL
;
1555 static void client_calc_layer_recursive(ObClient
*self
, ObClient
*orig
,
1556 ObStackingLayer l
, gboolean raised
)
1558 ObStackingLayer old
, own
;
1562 own
= calc_layer(self
);
1563 self
->layer
= l
> own
? l
: own
;
1565 for (it
= self
->transients
; it
; it
= it
->next
)
1566 client_calc_layer_recursive(it
->data
, orig
,
1567 l
, raised
? raised
: l
!= old
);
1569 if (!raised
&& l
!= old
)
1570 if (orig
->frame
) { /* only restack if the original window is managed */
1571 /* XXX add_non_intrusive ever? */
1572 stacking_remove(CLIENT_AS_WINDOW(self
));
1573 stacking_add(CLIENT_AS_WINDOW(self
));
1577 void client_calc_layer(ObClient
*self
)
1584 /* transients take on the layer of their parents */
1585 self
= client_search_top_transient(self
);
1587 l
= calc_layer(self
);
1589 client_calc_layer_recursive(self
, orig
, l
, FALSE
);
1592 gboolean
client_should_show(ObClient
*self
)
1594 if (self
->iconic
) return FALSE
;
1595 else if (!(self
->desktop
== screen_desktop
||
1596 self
->desktop
== DESKTOP_ALL
)) return FALSE
;
1597 else if (client_normal(self
) && screen_showing_desktop
) return FALSE
;
1602 static void client_showhide(ObClient
*self
)
1605 if (client_should_show(self
))
1606 frame_show(self
->frame
);
1608 frame_hide(self
->frame
);
1611 gboolean
client_normal(ObClient
*self
) {
1612 return ! (self
->type
== OB_CLIENT_TYPE_DESKTOP
||
1613 self
->type
== OB_CLIENT_TYPE_DOCK
||
1614 self
->type
== OB_CLIENT_TYPE_SPLASH
);
1617 static void client_apply_startup_state(ObClient
*self
)
1619 /* these are in a carefully crafted order.. */
1622 self
->iconic
= FALSE
;
1623 client_iconify(self
, TRUE
, FALSE
);
1625 if (self
->fullscreen
) {
1626 self
->fullscreen
= FALSE
;
1627 client_fullscreen(self
, TRUE
, FALSE
);
1630 self
->shaded
= FALSE
;
1631 client_shade(self
, TRUE
);
1634 dispatch_client(Event_Client_Urgent
, self
, self
->urgent
, 0);
1636 if (self
->max_vert
&& self
->max_horz
) {
1637 self
->max_vert
= self
->max_horz
= FALSE
;
1638 client_maximize(self
, TRUE
, 0, FALSE
);
1639 } else if (self
->max_vert
) {
1640 self
->max_vert
= FALSE
;
1641 client_maximize(self
, TRUE
, 2, FALSE
);
1642 } else if (self
->max_horz
) {
1643 self
->max_horz
= FALSE
;
1644 client_maximize(self
, TRUE
, 1, FALSE
);
1647 /* nothing to do for the other states:
1656 void client_configure(ObClient
*self
, ObCorner anchor
,
1657 int x
, int y
, int w
, int h
,
1658 gboolean user
, gboolean final
)
1660 gboolean moved
= FALSE
, resized
= FALSE
;
1662 /* gets the frame's position */
1663 frame_client_gravity(self
->frame
, &x
, &y
);
1665 /* these positions are frame positions, not client positions */
1667 /* set the size and position if fullscreen */
1668 if (self
->fullscreen
) {
1671 XF86VidModeModeLine mode
;
1676 i
= client_monitor(self
);
1677 a
= screen_physical_area_monitor(i
);
1680 if (i
== 0 && /* primary head */
1681 extensions_vidmode
&&
1682 XF86VidModeGetViewPort(ob_display
, ob_screen
, &x
, &y
) &&
1683 /* get the mode last so the mode.privsize isnt freed incorrectly */
1684 XF86VidModeGetModeLine(ob_display
, ob_screen
, &dot
, &mode
)) {
1689 if (mode
.privsize
) XFree(mode
.private);
1699 user
= FALSE
; /* ignore that increment etc shit when in fullscreen */
1703 a
= screen_area_monitor(self
->desktop
, client_monitor(self
));
1705 /* set the size and position if maximized */
1706 if (self
->max_horz
) {
1707 x
= a
->x
- self
->frame
->size
.left
;
1710 if (self
->max_vert
) {
1712 h
= a
->height
- self
->frame
->size
.top
- self
->frame
->size
.bottom
;
1716 /* gets the client's position */
1717 frame_frame_gravity(self
->frame
, &x
, &y
);
1719 /* these override the above states! if you cant move you can't move! */
1721 if (!(self
->functions
& OB_CLIENT_FUNC_MOVE
)) {
1725 if (!(self
->functions
& OB_CLIENT_FUNC_RESIZE
)) {
1726 w
= self
->area
.width
;
1727 h
= self
->area
.height
;
1731 if (!(w
== self
->area
.width
&& h
== self
->area
.height
)) {
1732 int basew
, baseh
, minw
, minh
;
1734 /* base size is substituted with min size if not specified */
1735 if (self
->base_size
.width
|| self
->base_size
.height
) {
1736 basew
= self
->base_size
.width
;
1737 baseh
= self
->base_size
.height
;
1739 basew
= self
->min_size
.width
;
1740 baseh
= self
->min_size
.height
;
1742 /* min size is substituted with base size if not specified */
1743 if (self
->min_size
.width
|| self
->min_size
.height
) {
1744 minw
= self
->min_size
.width
;
1745 minh
= self
->min_size
.height
;
1747 minw
= self
->base_size
.width
;
1748 minh
= self
->base_size
.height
;
1752 /* for interactive resizing. have to move half an increment in each
1755 /* how far we are towards the next size inc */
1756 int mw
= (w
- basew
) % self
->size_inc
.width
;
1757 int mh
= (h
- baseh
) % self
->size_inc
.height
;
1759 int aw
= self
->size_inc
.width
/ 2;
1760 int ah
= self
->size_inc
.height
/ 2;
1761 /* don't let us move into a new size increment */
1762 if (mw
+ aw
>= self
->size_inc
.width
)
1763 aw
= self
->size_inc
.width
- mw
- 1;
1764 if (mh
+ ah
>= self
->size_inc
.height
)
1765 ah
= self
->size_inc
.height
- mh
- 1;
1769 /* if this is a user-requested resize, then check against min/max
1772 /* smaller than min size or bigger than max size? */
1773 if (w
> self
->max_size
.width
) w
= self
->max_size
.width
;
1774 if (w
< minw
) w
= minw
;
1775 if (h
> self
->max_size
.height
) h
= self
->max_size
.height
;
1776 if (h
< minh
) h
= minh
;
1782 /* keep to the increments */
1783 w
/= self
->size_inc
.width
;
1784 h
/= self
->size_inc
.height
;
1786 /* you cannot resize to nothing */
1790 /* store the logical size */
1791 SIZE_SET(self
->logical_size
, w
, h
);
1793 w
*= self
->size_inc
.width
;
1794 h
*= self
->size_inc
.height
;
1800 /* adjust the height to match the width for the aspect ratios.
1801 for this, min size is not substituted for base size ever. */
1802 w
-= self
->base_size
.width
;
1803 h
-= self
->base_size
.height
;
1805 if (self
->min_ratio
)
1806 if (h
* self
->min_ratio
> w
) h
= (int)(w
/ self
->min_ratio
);
1807 if (self
->max_ratio
)
1808 if (h
* self
->max_ratio
< w
) h
= (int)(w
/ self
->max_ratio
);
1810 w
+= self
->base_size
.width
;
1811 h
+= self
->base_size
.height
;
1816 case OB_CORNER_TOPLEFT
:
1818 case OB_CORNER_TOPRIGHT
:
1819 x
-= w
- self
->area
.width
;
1821 case OB_CORNER_BOTTOMLEFT
:
1822 y
-= h
- self
->area
.height
;
1824 case OB_CORNER_BOTTOMRIGHT
:
1825 x
-= w
- self
->area
.width
;
1826 y
-= h
- self
->area
.height
;
1830 moved
= x
!= self
->area
.x
|| y
!= self
->area
.y
;
1831 resized
= w
!= self
->area
.width
|| h
!= self
->area
.height
;
1833 RECT_SET(self
->area
, x
, y
, w
, h
);
1835 /* for app-requested resizes, always resize if 'resized' is true.
1836 for user-requested ones, only resize if final is true, or when
1837 resizing in opaque mode */
1838 if ((!user
&& resized
) ||
1839 (user
&& (final
|| (resized
&& config_opaque_resize
))))
1840 XResizeWindow(ob_display
, self
->window
, w
, h
);
1842 /* move/resize the frame to match the request */
1844 if (self
->decorations
!= self
->frame
->decorations
)
1845 moved
= resized
= TRUE
;
1847 if (moved
|| resized
)
1848 frame_adjust_area(self
->frame
, moved
, resized
);
1850 /* If you send this and the client hasn't changed you end up with buggy
1851 clients (emacs) freaking out, cuz they send back a configure every
1852 time they receive this event, which resends them this event... etc.
1854 if ((!user
&& moved
) || (user
&& final
)) {
1856 event
.type
= ConfigureNotify
;
1857 event
.xconfigure
.display
= ob_display
;
1858 event
.xconfigure
.event
= self
->window
;
1859 event
.xconfigure
.window
= self
->window
;
1861 /* root window real coords */
1862 event
.xconfigure
.x
= self
->frame
->area
.x
+ self
->frame
->size
.left
;
1863 event
.xconfigure
.y
= self
->frame
->area
.y
+ self
->frame
->size
.top
;
1865 event
.xconfigure
.width
= w
;
1866 event
.xconfigure
.height
= h
;
1867 event
.xconfigure
.border_width
= 0;
1868 event
.xconfigure
.above
= self
->frame
->plate
;
1869 event
.xconfigure
.override_redirect
= FALSE
;
1870 XSendEvent(event
.xconfigure
.display
, event
.xconfigure
.window
,
1871 FALSE
, StructureNotifyMask
, &event
);
1876 void client_fullscreen(ObClient
*self
, gboolean fs
, gboolean savearea
)
1880 if (!(self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
) || /* can't */
1881 self
->fullscreen
== fs
) return; /* already done */
1883 self
->fullscreen
= fs
;
1884 client_change_state(self
); /* change the state hints on the client,
1885 and adjust out layer/stacking */
1889 guint32 dimensions
[4];
1890 dimensions
[0] = self
->area
.x
;
1891 dimensions
[1] = self
->area
.y
;
1892 dimensions
[2] = self
->area
.width
;
1893 dimensions
[3] = self
->area
.height
;
1895 PROP_SETA32(self
->window
, openbox_premax
, cardinal
,
1899 /* these are not actually used cuz client_configure will set them
1900 as appropriate when the window is fullscreened */
1907 /* pick some fallbacks... */
1908 a
= screen_area_monitor(self
->desktop
, 0);
1909 x
= a
->x
+ a
->width
/ 4;
1910 y
= a
->y
+ a
->height
/ 4;
1914 if (PROP_GETA32(self
->window
, openbox_premax
, cardinal
,
1915 (guint32
**)&dimensions
, &num
)) {
1926 client_setup_decor_and_functions(self
);
1928 client_configure(self
, OB_CORNER_TOPLEFT
, x
, y
, w
, h
, TRUE
, TRUE
);
1930 /* try focus us when we go into fullscreen mode */
1934 static void client_iconify_recursive(ObClient
*self
,
1935 gboolean iconic
, gboolean curdesk
)
1938 gboolean changed
= FALSE
;
1941 if (self
->iconic
!= iconic
) {
1942 ob_debug("%sconifying window: 0x%lx\n", (iconic
? "I" : "Uni"),
1945 self
->iconic
= iconic
;
1948 if (self
->functions
& OB_CLIENT_FUNC_ICONIFY
) {
1949 self
->wmstate
= IconicState
;
1950 self
->ignore_unmaps
++;
1951 /* we unmap the client itself so that we can get MapRequest
1952 events, and because the ICCCM tells us to! */
1953 XUnmapWindow(ob_display
, self
->window
);
1955 /* update the focus lists.. iconic windows go to the bottom of
1956 the list, put the new iconic window at the 'top of the
1958 focus_order_to_top(self
);
1964 client_set_desktop(self
, screen_desktop
, FALSE
);
1965 self
->wmstate
= self
->shaded
? IconicState
: NormalState
;
1966 XMapWindow(ob_display
, self
->window
);
1968 /* this puts it after the current focused window */
1969 focus_order_remove(self
);
1970 focus_order_add_new(self
);
1972 /* this is here cuz with the VIDMODE extension, the viewport can
1973 change while a fullscreen window is iconic, and when it
1974 uniconifies, it would be nice if it did so to the new position
1976 client_reconfigure(self
);
1983 client_change_state(self
);
1984 client_showhide(self
);
1985 screen_update_areas();
1987 dispatch_client(iconic
? Event_Client_Unmapped
: Event_Client_Mapped
,
1991 /* iconify all transients */
1992 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
)
1993 if (it
->data
!= self
) client_iconify_recursive(it
->data
,
1997 void client_iconify(ObClient
*self
, gboolean iconic
, gboolean curdesk
)
1999 /* move up the transient chain as far as possible first */
2000 self
= client_search_top_transient(self
);
2002 client_iconify_recursive(client_search_top_transient(self
),
2006 void client_maximize(ObClient
*self
, gboolean max
, int dir
, gboolean savearea
)
2010 g_assert(dir
== 0 || dir
== 1 || dir
== 2);
2011 if (!(self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
)) return; /* can't */
2013 /* check if already done */
2015 if (dir
== 0 && self
->max_horz
&& self
->max_vert
) return;
2016 if (dir
== 1 && self
->max_horz
) return;
2017 if (dir
== 2 && self
->max_vert
) return;
2019 if (dir
== 0 && !self
->max_horz
&& !self
->max_vert
) return;
2020 if (dir
== 1 && !self
->max_horz
) return;
2021 if (dir
== 2 && !self
->max_vert
) return;
2024 /* work with the frame's coords */
2025 x
= self
->frame
->area
.x
;
2026 y
= self
->frame
->area
.y
;
2027 w
= self
->area
.width
;
2028 h
= self
->area
.height
;
2032 gint32 dimensions
[4];
2041 /* get the property off the window and use it for the dimensions
2042 we are already maxed on */
2043 if (PROP_GETA32(self
->window
, openbox_premax
, cardinal
,
2044 (guint32
**)&readdim
, &num
)) {
2046 if (self
->max_horz
) {
2047 dimensions
[0] = readdim
[0];
2048 dimensions
[2] = readdim
[2];
2050 if (self
->max_vert
) {
2051 dimensions
[1] = readdim
[1];
2052 dimensions
[3] = readdim
[3];
2058 PROP_SETA32(self
->window
, openbox_premax
, cardinal
,
2059 (guint32
*)dimensions
, 4);
2066 /* pick some fallbacks... */
2067 a
= screen_area_monitor(self
->desktop
, 0);
2068 if (dir
== 0 || dir
== 1) { /* horz */
2069 x
= a
->x
+ a
->width
/ 4;
2072 if (dir
== 0 || dir
== 2) { /* vert */
2073 y
= a
->y
+ a
->height
/ 4;
2077 if (PROP_GETA32(self
->window
, openbox_premax
, cardinal
,
2078 (guint32
**)&dimensions
, &num
)) {
2080 if (dir
== 0 || dir
== 1) { /* horz */
2084 if (dir
== 0 || dir
== 2) { /* vert */
2093 if (dir
== 0 || dir
== 1) /* horz */
2094 self
->max_horz
= max
;
2095 if (dir
== 0 || dir
== 2) /* vert */
2096 self
->max_vert
= max
;
2098 if (!self
->max_horz
&& !self
->max_vert
)
2099 PROP_ERASE(self
->window
, openbox_premax
);
2101 client_change_state(self
); /* change the state hints on the client */
2103 /* figure out where the client should be going */
2104 frame_frame_gravity(self
->frame
, &x
, &y
);
2105 client_configure(self
, OB_CORNER_TOPLEFT
, x
, y
, w
, h
, TRUE
, TRUE
);
2108 void client_shade(ObClient
*self
, gboolean shade
)
2110 if ((!(self
->functions
& OB_CLIENT_FUNC_SHADE
) &&
2111 shade
) || /* can't shade */
2112 self
->shaded
== shade
) return; /* already done */
2114 /* when we're iconic, don't change the wmstate */
2116 self
->wmstate
= shade
? IconicState
: NormalState
;
2117 self
->shaded
= shade
;
2118 client_change_state(self
);
2119 /* resize the frame to just the titlebar */
2120 frame_adjust_area(self
->frame
, FALSE
, FALSE
);
2123 void client_close(ObClient
*self
)
2127 if (!(self
->functions
& OB_CLIENT_FUNC_CLOSE
)) return;
2130 XXX: itd be cool to do timeouts and shit here for killing the client's
2132 like... if the window is around after 5 seconds, then the close button
2133 turns a nice red, and if this function is called again, the client is
2137 ce
.xclient
.type
= ClientMessage
;
2138 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
2139 ce
.xclient
.display
= ob_display
;
2140 ce
.xclient
.window
= self
->window
;
2141 ce
.xclient
.format
= 32;
2142 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_delete_window
;
2143 ce
.xclient
.data
.l
[1] = event_lasttime
;
2144 ce
.xclient
.data
.l
[2] = 0l;
2145 ce
.xclient
.data
.l
[3] = 0l;
2146 ce
.xclient
.data
.l
[4] = 0l;
2147 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
2150 void client_kill(ObClient
*self
)
2152 XKillClient(ob_display
, self
->window
);
2155 void client_set_desktop_recursive(ObClient
*self
,
2156 guint target
, gboolean donthide
)
2161 if (target
!= self
->desktop
) {
2163 ob_debug("Setting desktop %u\n", target
+1);
2165 g_assert(target
< screen_num_desktops
|| target
== DESKTOP_ALL
);
2167 /* remove from the old desktop(s) */
2168 focus_order_remove(self
);
2170 old
= self
->desktop
;
2171 self
->desktop
= target
;
2172 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, target
);
2173 /* the frame can display the current desktop state */
2174 frame_adjust_state(self
->frame
);
2175 /* 'move' the window to the new desktop */
2177 client_showhide(self
);
2178 /* raise if it was not already on the desktop */
2179 if (old
!= DESKTOP_ALL
)
2180 stacking_raise(CLIENT_AS_WINDOW(self
));
2181 screen_update_areas();
2183 /* add to the new desktop(s) */
2184 if (config_focus_new
)
2185 focus_order_to_top(self
);
2187 focus_order_to_bottom(self
);
2189 dispatch_client(Event_Client_Desktop
, self
, target
, old
);
2192 /* move all transients */
2193 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
)
2194 if (it
->data
!= self
) client_set_desktop_recursive(it
->data
,
2198 void client_set_desktop(ObClient
*self
, guint target
, gboolean donthide
)
2200 client_set_desktop_recursive(client_search_top_transient(self
),
2204 ObClient
*client_search_modal_child(ObClient
*self
)
2209 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
) {
2210 ObClient
*c
= it
->data
;
2211 if ((ret
= client_search_modal_child(c
))) return ret
;
2212 if (c
->modal
) return c
;
2217 gboolean
client_validate(ObClient
*self
)
2221 XSync(ob_display
, FALSE
); /* get all events on the server */
2223 if (XCheckTypedWindowEvent(ob_display
, self
->window
, DestroyNotify
, &e
) ||
2224 XCheckTypedWindowEvent(ob_display
, self
->window
, UnmapNotify
, &e
)) {
2225 XPutBackEvent(ob_display
, &e
);
2232 void client_set_wm_state(ObClient
*self
, long state
)
2234 if (state
== self
->wmstate
) return; /* no change */
2238 client_iconify(self
, TRUE
, TRUE
);
2241 client_iconify(self
, FALSE
, TRUE
);
2246 void client_set_state(ObClient
*self
, Atom action
, long data1
, long data2
)
2248 gboolean shaded
= self
->shaded
;
2249 gboolean fullscreen
= self
->fullscreen
;
2250 gboolean max_horz
= self
->max_horz
;
2251 gboolean max_vert
= self
->max_vert
;
2254 if (!(action
== prop_atoms
.net_wm_state_add
||
2255 action
== prop_atoms
.net_wm_state_remove
||
2256 action
== prop_atoms
.net_wm_state_toggle
))
2257 /* an invalid action was passed to the client message, ignore it */
2260 for (i
= 0; i
< 2; ++i
) {
2261 Atom state
= i
== 0 ? data1
: data2
;
2263 if (!state
) continue;
2265 /* if toggling, then pick whether we're adding or removing */
2266 if (action
== prop_atoms
.net_wm_state_toggle
) {
2267 if (state
== prop_atoms
.net_wm_state_modal
)
2268 action
= self
->modal
? prop_atoms
.net_wm_state_remove
:
2269 prop_atoms
.net_wm_state_add
;
2270 else if (state
== prop_atoms
.net_wm_state_maximized_vert
)
2271 action
= self
->max_vert
? prop_atoms
.net_wm_state_remove
:
2272 prop_atoms
.net_wm_state_add
;
2273 else if (state
== prop_atoms
.net_wm_state_maximized_horz
)
2274 action
= self
->max_horz
? prop_atoms
.net_wm_state_remove
:
2275 prop_atoms
.net_wm_state_add
;
2276 else if (state
== prop_atoms
.net_wm_state_shaded
)
2277 action
= self
->shaded
? prop_atoms
.net_wm_state_remove
:
2278 prop_atoms
.net_wm_state_add
;
2279 else if (state
== prop_atoms
.net_wm_state_skip_taskbar
)
2280 action
= self
->skip_taskbar
?
2281 prop_atoms
.net_wm_state_remove
:
2282 prop_atoms
.net_wm_state_add
;
2283 else if (state
== prop_atoms
.net_wm_state_skip_pager
)
2284 action
= self
->skip_pager
?
2285 prop_atoms
.net_wm_state_remove
:
2286 prop_atoms
.net_wm_state_add
;
2287 else if (state
== prop_atoms
.net_wm_state_fullscreen
)
2288 action
= self
->fullscreen
?
2289 prop_atoms
.net_wm_state_remove
:
2290 prop_atoms
.net_wm_state_add
;
2291 else if (state
== prop_atoms
.net_wm_state_above
)
2292 action
= self
->above
? prop_atoms
.net_wm_state_remove
:
2293 prop_atoms
.net_wm_state_add
;
2294 else if (state
== prop_atoms
.net_wm_state_below
)
2295 action
= self
->below
? prop_atoms
.net_wm_state_remove
:
2296 prop_atoms
.net_wm_state_add
;
2299 if (action
== prop_atoms
.net_wm_state_add
) {
2300 if (state
== prop_atoms
.net_wm_state_modal
) {
2301 /* XXX raise here or something? */
2303 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
2305 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
2307 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
2309 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
2310 self
->skip_taskbar
= TRUE
;
2311 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
2312 self
->skip_pager
= TRUE
;
2313 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
2315 } else if (state
== prop_atoms
.net_wm_state_above
) {
2317 } else if (state
== prop_atoms
.net_wm_state_below
) {
2321 } else { /* action == prop_atoms.net_wm_state_remove */
2322 if (state
== prop_atoms
.net_wm_state_modal
) {
2323 self
->modal
= FALSE
;
2324 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
2326 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
2328 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
2330 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
2331 self
->skip_taskbar
= FALSE
;
2332 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
2333 self
->skip_pager
= FALSE
;
2334 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
2336 } else if (state
== prop_atoms
.net_wm_state_above
) {
2337 self
->above
= FALSE
;
2338 } else if (state
== prop_atoms
.net_wm_state_below
) {
2339 self
->below
= FALSE
;
2343 if (max_horz
!= self
->max_horz
|| max_vert
!= self
->max_vert
) {
2344 if (max_horz
!= self
->max_horz
&& max_vert
!= self
->max_vert
) {
2346 if (max_horz
== max_vert
) { /* both going the same way */
2347 client_maximize(self
, max_horz
, 0, TRUE
);
2349 client_maximize(self
, max_horz
, 1, TRUE
);
2350 client_maximize(self
, max_vert
, 2, TRUE
);
2354 if (max_horz
!= self
->max_horz
)
2355 client_maximize(self
, max_horz
, 1, TRUE
);
2357 client_maximize(self
, max_vert
, 2, TRUE
);
2360 /* change fullscreen state before shading, as it will affect if the window
2362 if (fullscreen
!= self
->fullscreen
)
2363 client_fullscreen(self
, fullscreen
, TRUE
);
2364 if (shaded
!= self
->shaded
)
2365 client_shade(self
, shaded
);
2366 client_calc_layer(self
);
2367 client_change_state(self
); /* change the hint to reflect these changes */
2370 ObClient
*client_focus_target(ObClient
*self
)
2374 /* if we have a modal child, then focus it, not us */
2375 child
= client_search_modal_child(self
);
2376 if (child
) return child
;
2380 gboolean
client_can_focus(ObClient
*self
)
2384 /* choose the correct target */
2385 self
= client_focus_target(self
);
2387 if (!self
->frame
->visible
)
2390 if (!((self
->can_focus
|| self
->focus_notify
) &&
2391 (self
->desktop
== screen_desktop
||
2392 self
->desktop
== DESKTOP_ALL
) &&
2396 /* do a check to see if the window has already been unmapped or destroyed
2397 do this intelligently while watching out for unmaps we've generated
2398 (ignore_unmaps > 0) */
2399 if (XCheckTypedWindowEvent(ob_display
, self
->window
,
2400 DestroyNotify
, &ev
)) {
2401 XPutBackEvent(ob_display
, &ev
);
2404 while (XCheckTypedWindowEvent(ob_display
, self
->window
,
2405 UnmapNotify
, &ev
)) {
2406 if (self
->ignore_unmaps
) {
2407 self
->ignore_unmaps
--;
2409 XPutBackEvent(ob_display
, &ev
);
2417 gboolean
client_focus(ObClient
*self
)
2419 /* choose the correct target */
2420 self
= client_focus_target(self
);
2422 if (!client_can_focus(self
)) {
2423 if (!self
->frame
->visible
) {
2424 /* update the focus lists */
2425 focus_order_to_top(self
);
2430 if (self
->can_focus
)
2431 /* RevertToPointerRoot causes much more headache than RevertToNone, so
2432 I choose to use it always, hopefully to find errors quicker, if any
2433 are left. (I hate X. I hate focus events.) */
2434 XSetInputFocus(ob_display
, self
->window
, RevertToPointerRoot
,
2437 if (self
->focus_notify
) {
2439 ce
.xclient
.type
= ClientMessage
;
2440 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
2441 ce
.xclient
.display
= ob_display
;
2442 ce
.xclient
.window
= self
->window
;
2443 ce
.xclient
.format
= 32;
2444 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_take_focus
;
2445 ce
.xclient
.data
.l
[1] = event_lasttime
;
2446 ce
.xclient
.data
.l
[2] = 0l;
2447 ce
.xclient
.data
.l
[3] = 0l;
2448 ce
.xclient
.data
.l
[4] = 0l;
2449 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
2453 ob_debug("%sively focusing %lx at %d\n",
2454 (self
->can_focus
? "act" : "pass"),
2455 self
->window
, (int) event_lasttime
);
2458 /* Cause the FocusIn to come back to us. Important for desktop switches,
2459 since otherwise we'll have no FocusIn on the queue and send it off to
2460 the focus_backup. */
2461 XSync(ob_display
, FALSE
);
2465 void client_unfocus(ObClient
*self
)
2467 g_assert(focus_client
== self
);
2469 ob_debug("client_unfocus for %lx\n", self
->window
);
2471 focus_fallback(OB_FOCUS_FALLBACK_UNFOCUSING
);
2474 void client_activate(ObClient
*self
)
2476 if (client_normal(self
) && screen_showing_desktop
)
2477 screen_show_desktop(FALSE
);
2479 client_iconify(self
, FALSE
, FALSE
);
2480 if (self
->desktop
!= DESKTOP_ALL
&&
2481 self
->desktop
!= screen_desktop
)
2482 screen_set_desktop(self
->desktop
);
2483 else if (!self
->frame
->visible
)
2484 /* if its not visible for other reasons, then don't mess
2488 client_shade(self
, FALSE
);
2490 stacking_raise(CLIENT_AS_WINDOW(self
));
2493 gboolean
client_focused(ObClient
*self
)
2495 return self
== focus_client
;
2498 ObClientIcon
*client_icon(ObClient
*self
, int w
, int h
)
2501 /* si is the smallest image >= req */
2502 /* li is the largest image < req */
2503 unsigned long size
, smallest
= 0xffffffff, largest
= 0, si
= 0, li
= 0;
2505 if (!self
->nicons
) return NULL
;
2507 for (i
= 0; i
< self
->nicons
; ++i
) {
2508 size
= self
->icons
[i
].width
* self
->icons
[i
].height
;
2509 if (size
< smallest
&& size
>= (unsigned)(w
* h
)) {
2513 if (size
> largest
&& size
<= (unsigned)(w
* h
)) {
2518 if (largest
== 0) /* didnt find one smaller than the requested size */
2519 return &self
->icons
[si
];
2520 return &self
->icons
[li
];
2523 /* this be mostly ripped from fvwm */
2524 ObClient
*client_find_directional(ObClient
*c
, ObDirection dir
)
2526 int my_cx
, my_cy
, his_cx
, his_cy
;
2529 int score
, best_score
;
2530 ObClient
*best_client
, *cur
;
2536 /* first, find the centre coords of the currently focused window */
2537 my_cx
= c
->frame
->area
.x
+ c
->frame
->area
.width
/ 2;
2538 my_cy
= c
->frame
->area
.y
+ c
->frame
->area
.height
/ 2;
2543 for(it
= g_list_first(client_list
); it
; it
= it
->next
) {
2546 /* the currently selected window isn't interesting */
2549 if (!client_normal(cur
))
2551 if(c
->desktop
!= cur
->desktop
&& cur
->desktop
!= DESKTOP_ALL
)
2555 if(client_focus_target(cur
) == cur
&&
2556 !(cur
->can_focus
|| cur
->focus_notify
))
2559 /* find the centre coords of this window, from the
2560 * currently focused window's point of view */
2561 his_cx
= (cur
->frame
->area
.x
- my_cx
)
2562 + cur
->frame
->area
.width
/ 2;
2563 his_cy
= (cur
->frame
->area
.y
- my_cy
)
2564 + cur
->frame
->area
.height
/ 2;
2568 /* Rotate the diagonals 45 degrees counterclockwise.
2569 * To do this, multiply the matrix /+h +h\ with the
2570 * vector (x y). \-h +h/
2571 * h = sqrt(0.5). We can set h := 1 since absolute
2572 * distance doesn't matter here. */
2573 tx
= his_cx
+ his_cy
;
2574 his_cy
= -his_cx
+ his_cy
;
2579 case OB_DIRECTION_NORTH
:
2580 case OB_DIRECTION_SOUTH
:
2581 case OB_DIRECTION_NORTHEAST
:
2582 case OB_DIRECTION_SOUTHWEST
:
2583 offset
= (his_cx
< 0) ? -his_cx
: his_cx
;
2584 distance
= ((dir
== OB_DIRECTION_NORTH
||
2585 dir
== OB_DIRECTION_NORTHEAST
) ?
2588 case OB_DIRECTION_EAST
:
2589 case OB_DIRECTION_WEST
:
2590 case OB_DIRECTION_SOUTHEAST
:
2591 case OB_DIRECTION_NORTHWEST
:
2592 offset
= (his_cy
< 0) ? -his_cy
: his_cy
;
2593 distance
= ((dir
== OB_DIRECTION_WEST
||
2594 dir
== OB_DIRECTION_NORTHWEST
) ?
2599 /* the target must be in the requested direction */
2603 /* Calculate score for this window. The smaller the better. */
2604 score
= distance
+ offset
;
2606 /* windows more than 45 degrees off the direction are
2607 * heavily penalized and will only be chosen if nothing
2608 * else within a million pixels */
2609 if(offset
> distance
)
2612 if(best_score
== -1 || score
< best_score
)
2620 void client_set_layer(ObClient
*self
, int layer
)
2624 self
->above
= FALSE
;
2625 } else if (layer
== 0) {
2626 self
->below
= self
->above
= FALSE
;
2628 self
->below
= FALSE
;
2631 client_calc_layer(self
);
2632 client_change_state(self
); /* reflect this in the state hints */
2635 guint
client_monitor(ObClient
*self
)
2639 for (i
= 0; i
< screen_num_monitors
; ++i
) {
2640 Rect
*area
= screen_physical_area_monitor(i
);
2641 if (RECT_INTERSECTS_RECT(*area
, self
->frame
->area
))
2644 if (i
== screen_num_monitors
) i
= 0;
2645 g_assert(i
< screen_num_monitors
);
2649 ObClient
*client_search_top_transient(ObClient
*self
)
2651 /* move up the transient chain as far as possible */
2652 if (self
->transient_for
) {
2653 if (self
->transient_for
!= OB_TRAN_GROUP
) {
2654 return client_search_top_transient(self
->transient_for
);
2658 for (it
= self
->group
->members
; it
; it
= it
->next
) {
2659 ObClient
*c
= it
->data
;
2661 /* checking transient_for prevents infinate loops! */
2662 if (c
!= self
&& !c
->transient_for
)
2673 ObClient
*client_search_transient(ObClient
*self
, ObClient
*search
)
2677 for (sit
= self
->transients
; sit
; sit
= g_slist_next(sit
)) {
2678 if (sit
->data
== search
)
2680 if (client_search_transient(sit
->data
, search
))