7 #include "moveresize.h"
10 #include "extensions.h"
20 #include "menuframe.h"
23 #include "render/render.h"
26 #include <X11/Xutil.h>
28 /*! The event mask to grab on client windows */
29 #define CLIENT_EVENTMASK (PropertyChangeMask | FocusChangeMask | \
32 #define CLIENT_NOPROPAGATEMASK (ButtonPressMask | ButtonReleaseMask | \
35 GList
*client_list
= NULL
;
36 GSList
*client_destructors
= NULL
;
38 static void client_get_all(ObClient
*self
);
39 static void client_toggle_border(ObClient
*self
, gboolean show
);
40 static void client_get_area(ObClient
*self
);
41 static void client_get_desktop(ObClient
*self
);
42 static void client_get_state(ObClient
*self
);
43 static void client_get_shaped(ObClient
*self
);
44 static void client_get_mwm_hints(ObClient
*self
);
45 static void client_get_gravity(ObClient
*self
);
46 static void client_showhide(ObClient
*self
);
47 static void client_change_allowed_actions(ObClient
*self
);
48 static void client_change_state(ObClient
*self
);
49 static void client_apply_startup_state(ObClient
*self
);
50 static void client_restore_session_state(ObClient
*self
);
51 static void client_restore_session_stacking(ObClient
*self
);
58 void client_shutdown()
62 void client_add_destructor(ObClientDestructorFunc func
)
64 client_destructors
= g_slist_prepend(client_destructors
, (gpointer
)func
);
67 void client_remove_destructor(ObClientDestructorFunc func
)
69 client_destructors
= g_slist_remove(client_destructors
, (gpointer
)func
);
72 void client_set_list()
74 Window
*windows
, *win_it
;
76 guint size
= g_list_length(client_list
);
78 /* create an array of the window ids */
80 windows
= g_new(Window
, size
);
82 for (it
= client_list
; it
!= NULL
; it
= it
->next
, ++win_it
)
83 *win_it
= ((ObClient
*)it
->data
)->window
;
87 PROP_SETA32(RootWindow(ob_display
, ob_screen
),
88 net_client_list
, window
, (guint32
*)windows
, size
);
97 void client_foreach_transient(ObClient *self, ObClientForeachFunc func, void *data)
101 for (it = self->transients; it; it = it->next) {
102 if (!func(it->data, data)) return;
103 client_foreach_transient(it->data, func, data);
107 void client_foreach_ancestor(ObClient *self, ObClientForeachFunc func, void *data)
109 if (self->transient_for) {
110 if (self->transient_for != OB_TRAN_GROUP) {
111 if (!func(self->transient_for, data)) return;
112 client_foreach_ancestor(self->transient_for, func, data);
116 for (it = self->group->members; it; it = it->next)
117 if (it->data != self &&
118 !((ObClient*)it->data)->transient_for) {
119 if (!func(it->data, data)) return;
120 client_foreach_ancestor(it->data, func, data);
127 void client_manage_all()
129 unsigned int i
, j
, nchild
;
132 XWindowAttributes attrib
;
134 XQueryTree(ob_display
, RootWindow(ob_display
, ob_screen
),
135 &w
, &w
, &children
, &nchild
);
137 /* remove all icon windows from the list */
138 for (i
= 0; i
< nchild
; i
++) {
139 if (children
[i
] == None
) continue;
140 wmhints
= XGetWMHints(ob_display
, children
[i
]);
142 if ((wmhints
->flags
& IconWindowHint
) &&
143 (wmhints
->icon_window
!= children
[i
]))
144 for (j
= 0; j
< nchild
; j
++)
145 if (children
[j
] == wmhints
->icon_window
) {
153 for (i
= 0; i
< nchild
; ++i
) {
154 if (children
[i
] == None
)
156 if (XGetWindowAttributes(ob_display
, children
[i
], &attrib
)) {
157 if (attrib
.override_redirect
) continue;
159 if (attrib
.map_state
!= IsUnmapped
)
160 client_manage(children
[i
]);
165 /* stack them as they were on startup!
166 why with stacking_lower? Why, because then windows who aren't in the
167 stacking list are on the top where you can see them instead of buried
169 for (i
= startup_stack_size
; i
> 0; --i
) {
172 w
= startup_stack_order
[i
-1];
173 obw
= g_hash_table_lookup(window_map
, &w
);
175 g_assert(WINDOW_IS_CLIENT(obw
));
176 stacking_lower(CLIENT_AS_WINDOW(obw
));
179 g_free(startup_stack_order
);
180 startup_stack_order
= NULL
;
181 startup_stack_size
= 0;
183 if (config_focus_new
) {
186 active
= g_hash_table_lookup(window_map
, &startup_active
);
188 g_assert(WINDOW_IS_CLIENT(active
));
189 if (!client_focus(WINDOW_AS_CLIENT(active
)))
190 focus_fallback(OB_FOCUS_FALLBACK_NOFOCUS
);
192 focus_fallback(OB_FOCUS_FALLBACK_NOFOCUS
);
196 void client_manage(Window window
)
200 XWindowAttributes attrib
;
201 XSetWindowAttributes attrib_set
;
203 gboolean activate
= FALSE
;
207 /* check if it has already been unmapped by the time we started mapping
208 the grab does a sync so we don't have to here */
209 if (XCheckTypedWindowEvent(ob_display
, window
, DestroyNotify
, &e
) ||
210 XCheckTypedWindowEvent(ob_display
, window
, UnmapNotify
, &e
)) {
211 XPutBackEvent(ob_display
, &e
);
214 return; /* don't manage it */
217 /* make sure it isn't an override-redirect window */
218 if (!XGetWindowAttributes(ob_display
, window
, &attrib
) ||
219 attrib
.override_redirect
) {
221 return; /* don't manage it */
224 /* is the window a docking app */
225 if ((wmhint
= XGetWMHints(ob_display
, window
))) {
226 if ((wmhint
->flags
& StateHint
) &&
227 wmhint
->initial_state
== WithdrawnState
) {
228 dock_add(window
, wmhint
);
236 ob_debug("Managing window: %lx\n", window
);
238 /* choose the events we want to receive on the CLIENT window */
239 attrib_set
.event_mask
= CLIENT_EVENTMASK
;
240 attrib_set
.do_not_propagate_mask
= CLIENT_NOPROPAGATEMASK
;
241 XChangeWindowAttributes(ob_display
, window
,
242 CWEventMask
|CWDontPropagate
, &attrib_set
);
245 /* create the ObClient struct, and populate it from the hints on the
247 self
= g_new0(ObClient
, 1);
248 self
->obwin
.type
= Window_Client
;
249 self
->window
= window
;
251 client_get_all(self
);
252 client_restore_session_state(self
);
254 client_change_state(self
);
256 /* remove the client's border (and adjust re gravity) */
257 client_toggle_border(self
, FALSE
);
259 /* specify that if we exit, the window should not be destroyed and should
260 be reparented back to root automatically */
261 XChangeSaveSet(ob_display
, window
, SetModeInsert
);
263 /* create the decoration frame for the client window */
264 self
->frame
= frame_new();
266 frame_grab_client(self
->frame
, self
);
270 client_apply_startup_state(self
);
272 /* update the focus lists */
273 focus_order_add_new(self
);
275 stacking_add(CLIENT_AS_WINDOW(self
));
276 client_restore_session_stacking(self
);
278 /* focus the new window? */
279 if (ob_state() != OB_STATE_STARTING
&& config_focus_new
&&
280 /* note the check against Type_Normal/Dialog, not client_normal(self),
281 which would also include other types. in this case we want more
282 strict rules for focus */
283 (self
->type
== OB_CLIENT_TYPE_NORMAL
||
284 self
->type
== OB_CLIENT_TYPE_DIALOG
))
288 if (self
->desktop
!= screen_desktop
) {
289 /* activate the window */
292 gboolean group_foc
= FALSE
;
297 for (it
= self
->group
->members
; it
; it
= it
->next
)
299 if (client_focused(it
->data
))
307 (!self
->transient_for
&& (!self
->group
||
308 !self
->group
->members
->next
))) ||
309 client_search_focus_tree_full(self
) ||
311 !client_normal(focus_client
))
313 /* activate the window */
320 if (ob_state() == OB_STATE_RUNNING
) {
321 int x
= self
->area
.x
, ox
= x
;
322 int y
= self
->area
.y
, oy
= y
;
324 place_client(self
, &x
, &y
);
326 client_find_onscreen(self
, &x
, &y
,
327 self
->frame
->area
.width
,
328 self
->frame
->area
.height
,
329 client_normal(self
));
331 if (x
!= ox
|| y
!= oy
)
332 client_configure(self
, OB_CORNER_TOPLEFT
, x
, y
,
333 self
->area
.width
, self
->area
.height
,
337 /* make sure the window is visible */
338 client_move_onscreen(self
, client_normal(self
));
340 client_showhide(self
);
342 /* use client_focus instead of client_activate cuz client_activate does
343 stuff like switch desktops etc and I'm not interested in all that when
344 a window maps since its not based on an action from the user like
345 clicking a window to activate is. so keep the new window out of the way
347 if (activate
) client_focus(self
);
349 /* client_activate does this but we aret using it so we have to do it
351 if (screen_showing_desktop
)
352 screen_show_desktop(FALSE
);
354 /* add to client list/map */
355 client_list
= g_list_append(client_list
, self
);
356 g_hash_table_insert(window_map
, &self
->window
, self
);
358 /* this has to happen after we're in the client_list */
359 screen_update_areas();
361 /* update the list hints */
364 keyboard_grab_for_client(self
, TRUE
);
365 mouse_grab_for_client(self
, TRUE
);
367 ob_debug("Managed window 0x%lx (%s)\n", window
, self
->class);
370 void client_unmanage_all()
372 while (client_list
!= NULL
)
373 client_unmanage(client_list
->data
);
376 void client_unmanage(ObClient
*self
)
381 ob_debug("Unmanaging window: %lx (%s)\n", self
->window
, self
->class);
383 g_assert(self
!= NULL
);
385 keyboard_grab_for_client(self
, FALSE
);
386 mouse_grab_for_client(self
, FALSE
);
388 /* remove the window from our save set */
389 XChangeSaveSet(ob_display
, self
->window
, SetModeDelete
);
391 /* we dont want events no more */
392 XSelectInput(ob_display
, self
->window
, NoEventMask
);
394 frame_hide(self
->frame
);
396 client_list
= g_list_remove(client_list
, self
);
397 stacking_remove(self
);
398 g_hash_table_remove(window_map
, &self
->window
);
400 /* update the focus lists */
401 focus_order_remove(self
);
403 /* once the client is out of the list, update the struts to remove it's
405 screen_update_areas();
407 /* tell our parent(s) that we're gone */
408 if (self
->transient_for
== OB_TRAN_GROUP
) { /* transient of group */
411 for (it
= self
->group
->members
; it
; it
= it
->next
)
412 if (it
->data
!= self
)
413 ((ObClient
*)it
->data
)->transients
=
414 g_slist_remove(((ObClient
*)it
->data
)->transients
, self
);
415 } else if (self
->transient_for
) { /* transient of window */
416 self
->transient_for
->transients
=
417 g_slist_remove(self
->transient_for
->transients
, self
);
420 /* tell our transients that we're gone */
421 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
) {
422 if (((ObClient
*)it
->data
)->transient_for
!= OB_TRAN_GROUP
) {
423 ((ObClient
*)it
->data
)->transient_for
= NULL
;
424 client_calc_layer(it
->data
);
428 for (it
= client_destructors
; it
; it
= g_slist_next(it
)) {
429 ObClientDestructorFunc func
= (ObClientDestructorFunc
) it
->data
;
433 if (focus_client
== self
) {
436 /* focus the last focused window on the desktop, and ignore enter
437 events from the unmap so it doesnt mess with the focus */
438 while (XCheckTypedEvent(ob_display
, EnterNotify
, &e
));
439 client_unfocus(self
);
442 /* remove from its group */
444 group_remove(self
->group
, self
);
448 /* give the client its border back */
449 client_toggle_border(self
, TRUE
);
451 /* reparent the window out of the frame, and free the frame */
452 frame_release_client(self
->frame
, self
);
455 if (ob_state() != OB_STATE_EXITING
) {
456 /* these values should not be persisted across a window
458 PROP_ERASE(self
->window
, net_wm_desktop
);
459 PROP_ERASE(self
->window
, net_wm_state
);
460 PROP_ERASE(self
->window
, wm_state
);
462 /* if we're left in an iconic state, the client wont be mapped. this is
463 bad, since we will no longer be managing the window on restart */
465 XMapWindow(ob_display
, self
->window
);
469 ob_debug("Unmanaged window 0x%lx\n", self
->window
);
471 /* free all data allocated in the client struct */
472 g_slist_free(self
->transients
);
473 for (j
= 0; j
< self
->nicons
; ++j
)
474 g_free(self
->icons
[j
].data
);
475 if (self
->nicons
> 0)
478 g_free(self
->icon_title
);
484 /* update the list hints */
488 static void client_restore_session_state(ObClient
*self
)
492 if (!(it
= session_state_find(self
)))
495 self
->session
= it
->data
;
497 RECT_SET(self
->area
, self
->session
->x
, self
->session
->y
,
498 self
->session
->w
, self
->session
->h
);
499 self
->positioned
= TRUE
;
500 XResizeWindow(ob_display
, self
->window
,
501 self
->session
->w
, self
->session
->h
);
503 self
->desktop
= (self
->session
->desktop
== DESKTOP_ALL
?
504 self
->session
->desktop
:
505 MIN(screen_num_desktops
- 1, self
->session
->desktop
));
506 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, self
->desktop
);
508 self
->shaded
= self
->session
->shaded
;
509 self
->iconic
= self
->session
->iconic
;
510 self
->skip_pager
= self
->session
->skip_pager
;
511 self
->skip_taskbar
= self
->session
->skip_taskbar
;
512 self
->fullscreen
= self
->session
->fullscreen
;
513 self
->above
= self
->session
->above
;
514 self
->below
= self
->session
->below
;
515 self
->max_horz
= self
->session
->max_horz
;
516 self
->max_vert
= self
->session
->max_vert
;
519 static void client_restore_session_stacking(ObClient
*self
)
523 if (!self
->session
) return;
525 it
= g_list_find(session_saved_state
, self
->session
);
526 for (it
= g_list_previous(it
); it
; it
= g_list_previous(it
)) {
529 for (cit
= client_list
; cit
; cit
= g_list_next(cit
))
530 if (session_state_cmp(it
->data
, cit
->data
))
533 client_calc_layer(self
);
534 stacking_below(CLIENT_AS_WINDOW(self
),
535 CLIENT_AS_WINDOW(cit
->data
));
541 void client_move_onscreen(ObClient
*self
, gboolean rude
)
543 int x
= self
->area
.x
;
544 int y
= self
->area
.y
;
545 if (client_find_onscreen(self
, &x
, &y
,
546 self
->frame
->area
.width
,
547 self
->frame
->area
.height
, rude
)) {
548 client_configure(self
, OB_CORNER_TOPLEFT
, x
, y
,
549 self
->area
.width
, self
->area
.height
,
554 gboolean
client_find_onscreen(ObClient
*self
, int *x
, int *y
, int w
, int h
,
558 int ox
= *x
, oy
= *y
;
560 frame_client_gravity(self
->frame
, x
, y
); /* get where the frame
563 /* XXX watch for xinerama dead areas */
565 a
= screen_area(self
->desktop
);
566 if (!self
->strut
.right
&& *x
>= a
->x
+ a
->width
- 1)
567 *x
= a
->x
+ a
->width
- self
->frame
->area
.width
;
568 if (!self
->strut
.bottom
&& *y
>= a
->y
+ a
->height
- 1)
569 *y
= a
->y
+ a
->height
- self
->frame
->area
.height
;
570 if (!self
->strut
.left
&& *x
+ self
->frame
->area
.width
- 1 < a
->x
)
572 if (!self
->strut
.top
&& *y
+ self
->frame
->area
.height
- 1 < a
->y
)
576 /* this is my MOZILLA BITCHSLAP. oh ya it fucking feels good.
577 Java can suck it too. */
579 /* dont let windows map/move into the strut unless they
580 are bigger than the available area */
582 if (!self
->strut
.left
&& *x
< a
->x
) *x
= a
->x
;
583 if (!self
->strut
.right
&& *x
+ w
> a
->x
+ a
->width
)
584 *x
= a
->x
+ a
->width
- w
;
586 if (h
<= a
->height
) {
587 if (!self
->strut
.top
&& *y
< a
->y
) *y
= a
->y
;
588 if (!self
->strut
.bottom
&& *y
+ h
> a
->y
+ a
->height
)
589 *y
= a
->y
+ a
->height
- h
;
593 frame_frame_gravity(self
->frame
, x
, y
); /* get where the client
596 return ox
!= *x
|| oy
!= *y
;
599 static void client_toggle_border(ObClient
*self
, gboolean show
)
601 /* adjust our idea of where the client is, based on its border. When the
602 border is removed, the client should now be considered to be in a
604 when re-adding the border to the client, the same operation needs to be
606 int oldx
= self
->area
.x
, oldy
= self
->area
.y
;
607 int x
= oldx
, y
= oldy
;
608 switch(self
->gravity
) {
610 case NorthWestGravity
:
612 case SouthWestGravity
:
614 case NorthEastGravity
:
616 case SouthEastGravity
:
617 if (show
) x
-= self
->border_width
* 2;
618 else x
+= self
->border_width
* 2;
625 if (show
) x
-= self
->border_width
;
626 else x
+= self
->border_width
;
629 switch(self
->gravity
) {
631 case NorthWestGravity
:
633 case NorthEastGravity
:
635 case SouthWestGravity
:
637 case SouthEastGravity
:
638 if (show
) y
-= self
->border_width
* 2;
639 else y
+= self
->border_width
* 2;
646 if (show
) y
-= self
->border_width
;
647 else y
+= self
->border_width
;
654 XSetWindowBorderWidth(ob_display
, self
->window
, self
->border_width
);
656 /* move the client so it is back it the right spot _with_ its
658 if (x
!= oldx
|| y
!= oldy
)
659 XMoveWindow(ob_display
, self
->window
, x
, y
);
661 XSetWindowBorderWidth(ob_display
, self
->window
, 0);
665 static void client_get_all(ObClient
*self
)
667 /* non-zero defaults */
668 self
->title_count
= 1;
669 self
->wmstate
= NormalState
;
671 self
->decorate
= TRUE
;
673 client_get_area(self
);
674 client_update_transient_for(self
);
675 client_update_wmhints(self
);
676 client_get_desktop(self
);
677 client_get_state(self
);
678 client_get_shaped(self
);
680 client_get_mwm_hints(self
);
681 client_get_type(self
);/* this can change the mwmhints for special cases */
683 client_update_protocols(self
);
685 client_get_gravity(self
); /* get the attribute gravity */
686 client_update_normal_hints(self
); /* this may override the attribute
689 /* got the type, the mwmhints, the protocols, and the normal hints
690 (min/max sizes), so we're ready to set up the decorations/functions */
691 client_setup_decor_and_functions(self
);
693 client_update_title(self
);
694 client_update_class(self
);
695 client_update_strut(self
);
696 client_update_icons(self
);
699 static void client_get_area(ObClient
*self
)
701 XWindowAttributes wattrib
;
704 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
705 g_assert(ret
!= BadWindow
);
707 RECT_SET(self
->area
, wattrib
.x
, wattrib
.y
, wattrib
.width
, wattrib
.height
);
708 self
->border_width
= wattrib
.border_width
;
711 static void client_get_desktop(ObClient
*self
)
713 guint32 d
= screen_num_desktops
; /* an always-invalid value */
715 if (PROP_GET32(self
->window
, net_wm_desktop
, cardinal
, &d
)) {
716 if (d
>= screen_num_desktops
&& d
!= DESKTOP_ALL
)
717 self
->desktop
= screen_num_desktops
- 1;
721 gboolean trdesk
= FALSE
;
723 if (self
->transient_for
) {
724 if (self
->transient_for
!= OB_TRAN_GROUP
) {
725 self
->desktop
= self
->transient_for
->desktop
;
730 for (it
= self
->group
->members
; it
; it
= it
->next
)
731 if (it
->data
!= self
&&
732 !((ObClient
*)it
->data
)->transient_for
) {
733 self
->desktop
= ((ObClient
*)it
->data
)->desktop
;
740 /* defaults to the current desktop */
741 self
->desktop
= screen_desktop
;
743 if (self
->desktop
!= d
) {
744 /* set the desktop hint, to make sure that it always exists */
745 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, self
->desktop
);
749 static void client_get_state(ObClient
*self
)
754 self
->modal
= self
->shaded
= self
->max_horz
= self
->max_vert
=
755 self
->fullscreen
= self
->above
= self
->below
= self
->iconic
=
756 self
->skip_taskbar
= self
->skip_pager
= FALSE
;
758 if (PROP_GETA32(self
->window
, net_wm_state
, atom
, &state
, &num
)) {
760 for (i
= 0; i
< num
; ++i
) {
761 if (state
[i
] == prop_atoms
.net_wm_state_modal
)
763 else if (state
[i
] == prop_atoms
.net_wm_state_shaded
)
765 else if (state
[i
] == prop_atoms
.net_wm_state_hidden
)
767 else if (state
[i
] == prop_atoms
.net_wm_state_skip_taskbar
)
768 self
->skip_taskbar
= TRUE
;
769 else if (state
[i
] == prop_atoms
.net_wm_state_skip_pager
)
770 self
->skip_pager
= TRUE
;
771 else if (state
[i
] == prop_atoms
.net_wm_state_fullscreen
)
772 self
->fullscreen
= TRUE
;
773 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_vert
)
774 self
->max_vert
= TRUE
;
775 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_horz
)
776 self
->max_horz
= TRUE
;
777 else if (state
[i
] == prop_atoms
.net_wm_state_above
)
779 else if (state
[i
] == prop_atoms
.net_wm_state_below
)
787 static void client_get_shaped(ObClient
*self
)
789 self
->shaped
= FALSE
;
791 if (extensions_shape
) {
796 XShapeSelectInput(ob_display
, self
->window
, ShapeNotifyMask
);
798 XShapeQueryExtents(ob_display
, self
->window
, &s
, &foo
,
799 &foo
, &ufoo
, &ufoo
, &foo
, &foo
, &foo
, &ufoo
,
801 self
->shaped
= (s
!= 0);
806 void client_update_transient_for(ObClient
*self
)
809 ObClient
*target
= NULL
;
811 if (XGetTransientForHint(ob_display
, self
->window
, &t
)) {
812 self
->transient
= TRUE
;
813 if (t
!= self
->window
) { /* cant be transient to itself! */
814 target
= g_hash_table_lookup(window_map
, &t
);
815 /* if this happens then we need to check for it*/
816 g_assert(target
!= self
);
817 g_assert(!target
|| WINDOW_IS_CLIENT(target
));
819 if (!target
&& self
->group
) {
820 /* not transient to a client, see if it is transient for a
822 if (t
== self
->group
->leader
||
824 t
== RootWindow(ob_display
, ob_screen
)) {
825 /* window is a transient for its group! */
826 target
= OB_TRAN_GROUP
;
831 self
->transient
= FALSE
;
833 /* if anything has changed... */
834 if (target
!= self
->transient_for
) {
835 if (self
->transient_for
== OB_TRAN_GROUP
) { /* transient of group */
838 /* remove from old parents */
839 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
840 ObClient
*c
= it
->data
;
841 if (c
!= self
&& !c
->transient_for
)
842 c
->transients
= g_slist_remove(c
->transients
, self
);
844 } else if (self
->transient_for
!= NULL
) { /* transient of window */
845 /* remove from old parent */
846 self
->transient_for
->transients
=
847 g_slist_remove(self
->transient_for
->transients
, self
);
849 self
->transient_for
= target
;
850 if (self
->transient_for
== OB_TRAN_GROUP
) { /* transient of group */
853 /* add to new parents */
854 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
855 ObClient
*c
= it
->data
;
856 if (c
!= self
&& !c
->transient_for
)
857 c
->transients
= g_slist_append(c
->transients
, self
);
860 /* remove all transients which are in the group, that causes
861 circlular pointer hell of doom */
862 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
864 for (sit
= self
->transients
; sit
; sit
= next
) {
865 next
= g_slist_next(sit
);
866 if (sit
->data
== it
->data
)
868 g_slist_delete_link(self
->transients
, sit
);
871 } else if (self
->transient_for
!= NULL
) { /* transient of window */
872 /* add to new parent */
873 self
->transient_for
->transients
=
874 g_slist_append(self
->transient_for
->transients
, self
);
879 static void client_get_mwm_hints(ObClient
*self
)
884 self
->mwmhints
.flags
= 0; /* default to none */
886 if (PROP_GETA32(self
->window
, motif_wm_hints
, motif_wm_hints
,
888 if (num
>= OB_MWM_ELEMENTS
) {
889 self
->mwmhints
.flags
= hints
[0];
890 self
->mwmhints
.functions
= hints
[1];
891 self
->mwmhints
.decorations
= hints
[2];
897 void client_get_type(ObClient
*self
)
904 if (PROP_GETA32(self
->window
, net_wm_window_type
, atom
, &val
, &num
)) {
905 /* use the first value that we know about in the array */
906 for (i
= 0; i
< num
; ++i
) {
907 if (val
[i
] == prop_atoms
.net_wm_window_type_desktop
)
908 self
->type
= OB_CLIENT_TYPE_DESKTOP
;
909 else if (val
[i
] == prop_atoms
.net_wm_window_type_dock
)
910 self
->type
= OB_CLIENT_TYPE_DOCK
;
911 else if (val
[i
] == prop_atoms
.net_wm_window_type_toolbar
)
912 self
->type
= OB_CLIENT_TYPE_TOOLBAR
;
913 else if (val
[i
] == prop_atoms
.net_wm_window_type_menu
)
914 self
->type
= OB_CLIENT_TYPE_MENU
;
915 else if (val
[i
] == prop_atoms
.net_wm_window_type_utility
)
916 self
->type
= OB_CLIENT_TYPE_UTILITY
;
917 else if (val
[i
] == prop_atoms
.net_wm_window_type_splash
)
918 self
->type
= OB_CLIENT_TYPE_SPLASH
;
919 else if (val
[i
] == prop_atoms
.net_wm_window_type_dialog
)
920 self
->type
= OB_CLIENT_TYPE_DIALOG
;
921 else if (val
[i
] == prop_atoms
.net_wm_window_type_normal
)
922 self
->type
= OB_CLIENT_TYPE_NORMAL
;
923 else if (val
[i
] == prop_atoms
.kde_net_wm_window_type_override
) {
924 /* prevent this window from getting any decor or
926 self
->mwmhints
.flags
&= (OB_MWM_FLAG_FUNCTIONS
|
927 OB_MWM_FLAG_DECORATIONS
);
928 self
->mwmhints
.decorations
= 0;
929 self
->mwmhints
.functions
= 0;
931 if (self
->type
!= (ObClientType
) -1)
932 break; /* grab the first legit type */
937 if (self
->type
== (ObClientType
) -1) {
938 /*the window type hint was not set, which means we either classify
939 ourself as a normal window or a dialog, depending on if we are a
942 self
->type
= OB_CLIENT_TYPE_DIALOG
;
944 self
->type
= OB_CLIENT_TYPE_NORMAL
;
948 void client_update_protocols(ObClient
*self
)
953 self
->focus_notify
= FALSE
;
954 self
->delete_window
= FALSE
;
956 if (PROP_GETA32(self
->window
, wm_protocols
, atom
, &proto
, &num_return
)) {
957 for (i
= 0; i
< num_return
; ++i
) {
958 if (proto
[i
] == prop_atoms
.wm_delete_window
) {
959 /* this means we can request the window to close */
960 self
->delete_window
= TRUE
;
961 } else if (proto
[i
] == prop_atoms
.wm_take_focus
)
962 /* if this protocol is requested, then the window will be
963 notified whenever we want it to receive focus */
964 self
->focus_notify
= TRUE
;
970 static void client_get_gravity(ObClient
*self
)
972 XWindowAttributes wattrib
;
975 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
976 g_assert(ret
!= BadWindow
);
977 self
->gravity
= wattrib
.win_gravity
;
980 void client_update_normal_hints(ObClient
*self
)
984 int oldgravity
= self
->gravity
;
987 self
->min_ratio
= 0.0f
;
988 self
->max_ratio
= 0.0f
;
989 SIZE_SET(self
->size_inc
, 1, 1);
990 SIZE_SET(self
->base_size
, 0, 0);
991 SIZE_SET(self
->min_size
, 0, 0);
992 SIZE_SET(self
->max_size
, G_MAXINT
, G_MAXINT
);
994 /* get the hints from the window */
995 if (XGetWMNormalHints(ob_display
, self
->window
, &size
, &ret
)) {
996 self
->positioned
= !!(size
.flags
& (PPosition
|USPosition
));
998 if (size
.flags
& PWinGravity
) {
999 self
->gravity
= size
.win_gravity
;
1001 /* if the client has a frame, i.e. has already been mapped and
1002 is changing its gravity */
1003 if (self
->frame
&& self
->gravity
!= oldgravity
) {
1004 /* move our idea of the client's position based on its new
1006 self
->area
.x
= self
->frame
->area
.x
;
1007 self
->area
.y
= self
->frame
->area
.y
;
1008 frame_frame_gravity(self
->frame
, &self
->area
.x
, &self
->area
.y
);
1012 if (size
.flags
& PAspect
) {
1013 if (size
.min_aspect
.y
)
1014 self
->min_ratio
= (float)size
.min_aspect
.x
/ size
.min_aspect
.y
;
1015 if (size
.max_aspect
.y
)
1016 self
->max_ratio
= (float)size
.max_aspect
.x
/ size
.max_aspect
.y
;
1019 if (size
.flags
& PMinSize
)
1020 SIZE_SET(self
->min_size
, size
.min_width
, size
.min_height
);
1022 if (size
.flags
& PMaxSize
)
1023 SIZE_SET(self
->max_size
, size
.max_width
, size
.max_height
);
1025 if (size
.flags
& PBaseSize
)
1026 SIZE_SET(self
->base_size
, size
.base_width
, size
.base_height
);
1028 if (size
.flags
& PResizeInc
)
1029 SIZE_SET(self
->size_inc
, size
.width_inc
, size
.height_inc
);
1033 void client_setup_decor_and_functions(ObClient
*self
)
1035 /* start with everything (cept fullscreen) */
1037 (OB_FRAME_DECOR_TITLEBAR
|
1038 (ob_rr_theme
->show_handle
? OB_FRAME_DECOR_HANDLE
: 0) |
1039 OB_FRAME_DECOR_GRIPS
|
1040 OB_FRAME_DECOR_BORDER
|
1041 OB_FRAME_DECOR_ICON
|
1042 OB_FRAME_DECOR_ALLDESKTOPS
|
1043 OB_FRAME_DECOR_ICONIFY
|
1044 OB_FRAME_DECOR_MAXIMIZE
|
1045 OB_FRAME_DECOR_SHADE
);
1047 (OB_CLIENT_FUNC_RESIZE
|
1048 OB_CLIENT_FUNC_MOVE
|
1049 OB_CLIENT_FUNC_ICONIFY
|
1050 OB_CLIENT_FUNC_MAXIMIZE
|
1051 OB_CLIENT_FUNC_SHADE
);
1052 if (self
->delete_window
) {
1053 self
->functions
|= OB_CLIENT_FUNC_CLOSE
;
1054 self
->decorations
|= OB_FRAME_DECOR_CLOSE
;
1057 if (!(self
->min_size
.width
< self
->max_size
.width
||
1058 self
->min_size
.height
< self
->max_size
.height
))
1059 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
1061 switch (self
->type
) {
1062 case OB_CLIENT_TYPE_NORMAL
:
1063 /* normal windows retain all of the possible decorations and
1064 functionality, and are the only windows that you can fullscreen */
1065 self
->functions
|= OB_CLIENT_FUNC_FULLSCREEN
;
1068 case OB_CLIENT_TYPE_DIALOG
:
1069 case OB_CLIENT_TYPE_UTILITY
:
1070 /* these windows cannot be maximized */
1071 self
->functions
&= ~OB_CLIENT_FUNC_MAXIMIZE
;
1074 case OB_CLIENT_TYPE_MENU
:
1075 case OB_CLIENT_TYPE_TOOLBAR
:
1076 /* these windows get less functionality */
1077 self
->functions
&= ~(OB_CLIENT_FUNC_ICONIFY
| OB_CLIENT_FUNC_RESIZE
);
1080 case OB_CLIENT_TYPE_DESKTOP
:
1081 case OB_CLIENT_TYPE_DOCK
:
1082 case OB_CLIENT_TYPE_SPLASH
:
1083 /* none of these windows are manipulated by the window manager */
1084 self
->decorations
= 0;
1085 self
->functions
= 0;
1089 /* Mwm Hints are applied subtractively to what has already been chosen for
1090 decor and functionality */
1091 if (self
->mwmhints
.flags
& OB_MWM_FLAG_DECORATIONS
) {
1092 if (! (self
->mwmhints
.decorations
& OB_MWM_DECOR_ALL
)) {
1093 if (! ((self
->mwmhints
.decorations
& OB_MWM_DECOR_HANDLE
) ||
1094 (self
->mwmhints
.decorations
& OB_MWM_DECOR_TITLE
)))
1095 /* if the mwm hints request no handle or title, then all
1096 decorations are disabled */
1097 self
->decorations
= 0;
1101 if (self
->mwmhints
.flags
& OB_MWM_FLAG_FUNCTIONS
) {
1102 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_ALL
)) {
1103 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_RESIZE
))
1104 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
1105 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_MOVE
))
1106 self
->functions
&= ~OB_CLIENT_FUNC_MOVE
;
1107 /* dont let mwm hints kill any buttons
1108 if (! (self->mwmhints.functions & OB_MWM_FUNC_ICONIFY))
1109 self->functions &= ~OB_CLIENT_FUNC_ICONIFY;
1110 if (! (self->mwmhints.functions & OB_MWM_FUNC_MAXIMIZE))
1111 self->functions &= ~OB_CLIENT_FUNC_MAXIMIZE;
1113 /* dont let mwm hints kill the close button
1114 if (! (self->mwmhints.functions & MwmFunc_Close))
1115 self->functions &= ~OB_CLIENT_FUNC_CLOSE; */
1119 if (!(self
->functions
& OB_CLIENT_FUNC_SHADE
))
1120 self
->decorations
&= ~OB_FRAME_DECOR_SHADE
;
1121 if (!(self
->functions
& OB_CLIENT_FUNC_ICONIFY
))
1122 self
->decorations
&= ~OB_FRAME_DECOR_ICONIFY
;
1123 if (!(self
->functions
& OB_CLIENT_FUNC_RESIZE
))
1124 self
->decorations
&= ~OB_FRAME_DECOR_GRIPS
;
1126 /* can't maximize without moving/resizing */
1127 if (!((self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) &&
1128 (self
->functions
& OB_CLIENT_FUNC_MOVE
) &&
1129 (self
->functions
& OB_CLIENT_FUNC_RESIZE
))) {
1130 self
->functions
&= ~OB_CLIENT_FUNC_MAXIMIZE
;
1131 self
->decorations
&= ~OB_FRAME_DECOR_MAXIMIZE
;
1134 /* kill the handle on fully maxed windows */
1135 if (self
->max_vert
&& self
->max_horz
)
1136 self
->decorations
&= ~OB_FRAME_DECOR_HANDLE
;
1138 /* finally, the user can have requested no decorations, which overrides
1140 if (!self
->decorate
)
1141 self
->decorations
= OB_FRAME_DECOR_BORDER
;
1143 /* if we don't have a titlebar, then we cannot shade! */
1144 if (!(self
->decorations
& OB_FRAME_DECOR_TITLEBAR
))
1145 self
->functions
&= ~OB_CLIENT_FUNC_SHADE
;
1147 /* now we need to check against rules for the client's current state */
1148 if (self
->fullscreen
) {
1149 self
->functions
&= (OB_CLIENT_FUNC_CLOSE
|
1150 OB_CLIENT_FUNC_FULLSCREEN
|
1151 OB_CLIENT_FUNC_ICONIFY
);
1152 self
->decorations
= 0;
1155 client_change_allowed_actions(self
);
1158 /* adjust the client's decorations, etc. */
1159 client_reconfigure(self
);
1161 /* this makes sure that these windows appear on all desktops */
1162 if (self
->type
== OB_CLIENT_TYPE_DESKTOP
&&
1163 self
->desktop
!= DESKTOP_ALL
)
1165 self
->desktop
= DESKTOP_ALL
;
1170 static void client_change_allowed_actions(ObClient
*self
)
1175 /* desktop windows are kept on all desktops */
1176 if (self
->type
!= OB_CLIENT_TYPE_DESKTOP
)
1177 actions
[num
++] = prop_atoms
.net_wm_action_change_desktop
;
1179 if (self
->functions
& OB_CLIENT_FUNC_SHADE
)
1180 actions
[num
++] = prop_atoms
.net_wm_action_shade
;
1181 if (self
->functions
& OB_CLIENT_FUNC_CLOSE
)
1182 actions
[num
++] = prop_atoms
.net_wm_action_close
;
1183 if (self
->functions
& OB_CLIENT_FUNC_MOVE
)
1184 actions
[num
++] = prop_atoms
.net_wm_action_move
;
1185 if (self
->functions
& OB_CLIENT_FUNC_ICONIFY
)
1186 actions
[num
++] = prop_atoms
.net_wm_action_minimize
;
1187 if (self
->functions
& OB_CLIENT_FUNC_RESIZE
)
1188 actions
[num
++] = prop_atoms
.net_wm_action_resize
;
1189 if (self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
)
1190 actions
[num
++] = prop_atoms
.net_wm_action_fullscreen
;
1191 if (self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) {
1192 actions
[num
++] = prop_atoms
.net_wm_action_maximize_horz
;
1193 actions
[num
++] = prop_atoms
.net_wm_action_maximize_vert
;
1196 PROP_SETA32(self
->window
, net_wm_allowed_actions
, atom
, actions
, num
);
1198 /* make sure the window isn't breaking any rules now */
1200 if (!(self
->functions
& OB_CLIENT_FUNC_SHADE
) && self
->shaded
) {
1201 if (self
->frame
) client_shade(self
, FALSE
);
1202 else self
->shaded
= FALSE
;
1204 if (!(self
->functions
& OB_CLIENT_FUNC_ICONIFY
) && self
->iconic
) {
1205 if (self
->frame
) client_iconify(self
, FALSE
, TRUE
);
1206 else self
->iconic
= FALSE
;
1208 if (!(self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
) && self
->fullscreen
) {
1209 if (self
->frame
) client_fullscreen(self
, FALSE
, TRUE
);
1210 else self
->fullscreen
= FALSE
;
1212 if (!(self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) && (self
->max_horz
||
1214 if (self
->frame
) client_maximize(self
, FALSE
, 0, TRUE
);
1215 else self
->max_vert
= self
->max_horz
= FALSE
;
1219 void client_reconfigure(ObClient
*self
)
1221 /* by making this pass FALSE for user, we avoid the emacs event storm where
1222 every configurenotify causes an update in its normal hints, i think this
1223 is generally what we want anyways... */
1224 client_configure(self
, OB_CORNER_TOPLEFT
, self
->area
.x
, self
->area
.y
,
1225 self
->area
.width
, self
->area
.height
, FALSE
, TRUE
);
1228 void client_update_wmhints(ObClient
*self
)
1231 gboolean ur
= FALSE
;
1234 /* assume a window takes input if it doesnt specify */
1235 self
->can_focus
= TRUE
;
1237 if ((hints
= XGetWMHints(ob_display
, self
->window
)) != NULL
) {
1238 if (hints
->flags
& InputHint
)
1239 self
->can_focus
= hints
->input
;
1241 /* only do this when first managing the window *AND* when we aren't
1243 if (ob_state() != OB_STATE_STARTING
&& self
->frame
== NULL
)
1244 if (hints
->flags
& StateHint
)
1245 self
->iconic
= hints
->initial_state
== IconicState
;
1247 if (hints
->flags
& XUrgencyHint
)
1250 if (!(hints
->flags
& WindowGroupHint
))
1251 hints
->window_group
= None
;
1253 /* did the group state change? */
1254 if (hints
->window_group
!=
1255 (self
->group
? self
->group
->leader
: None
)) {
1256 /* remove from the old group if there was one */
1257 if (self
->group
!= NULL
) {
1258 /* remove transients of the group */
1259 for (it
= self
->group
->members
; it
; it
= it
->next
)
1260 self
->transients
= g_slist_remove(self
->transients
,
1262 group_remove(self
->group
, self
);
1265 if (hints
->window_group
!= None
) {
1266 self
->group
= group_add(hints
->window_group
, self
);
1268 /* i can only have transients from the group if i am not
1270 if (!self
->transient_for
) {
1271 /* add other transients of the group that are already
1273 for (it
= self
->group
->members
; it
; it
= it
->next
) {
1274 ObClient
*c
= it
->data
;
1275 if (c
!= self
&& c
->transient_for
== OB_TRAN_GROUP
)
1277 g_slist_append(self
->transients
, c
);
1282 /* because the self->transient flag wont change from this call,
1283 we don't need to update the window's type and such, only its
1284 transient_for, and the transients lists of other windows in
1285 the group may be affected */
1286 client_update_transient_for(self
);
1289 /* the WM_HINTS can contain an icon */
1290 client_update_icons(self
);
1295 if (ur
!= self
->urgent
) {
1297 ob_debug("Urgent Hint for 0x%lx: %s\n", self
->window
,
1299 /* fire the urgent callback if we're mapped, otherwise, wait until
1300 after we're mapped */
1307 void client_update_title(ObClient
*self
)
1313 gboolean read_title
;
1315 g_free(self
->title
);
1318 if (!PROP_GETS(self
->window
, net_wm_name
, utf8
, &data
))
1319 /* try old x stuff */
1320 if (!PROP_GETS(self
->window
, wm_name
, locale
, &data
))
1321 data
= g_strdup("Unnamed Window");
1323 /* look for duplicates and append a number */
1325 for (it
= client_list
; it
; it
= it
->next
)
1326 if (it
->data
!= self
) {
1327 ObClient
*c
= it
->data
;
1328 if (0 == strncmp(c
->title
, data
, strlen(data
)))
1329 nums
|= 1 << c
->title_count
;
1331 /* find first free number */
1332 for (i
= 1; i
<= 32; ++i
)
1333 if (!(nums
& (1 << i
))) {
1334 if (self
->title_count
== 1 || i
== 1)
1335 self
->title_count
= i
;
1338 /* dont display the number for the first window */
1339 if (self
->title_count
> 1) {
1340 char *vdata
, *ndata
;
1341 ndata
= g_strdup_printf(" - [%u]", self
->title_count
);
1342 vdata
= g_strconcat(data
, ndata
, NULL
);
1348 PROP_SETS(self
->window
, net_wm_visible_name
, data
);
1353 frame_adjust_title(self
->frame
);
1355 /* update the icon title */
1357 g_free(self
->icon_title
);
1361 if (!PROP_GETS(self
->window
, net_wm_icon_name
, utf8
, &data
))
1362 /* try old x stuff */
1363 if (!PROP_GETS(self
->window
, wm_icon_name
, locale
, &data
)) {
1364 data
= g_strdup(self
->title
);
1368 /* append the title count, dont display the number for the first window */
1369 if (read_title
&& self
->title_count
> 1) {
1370 char *vdata
, *ndata
;
1371 ndata
= g_strdup_printf(" - [%u]", self
->title_count
);
1372 vdata
= g_strconcat(data
, ndata
, NULL
);
1378 PROP_SETS(self
->window
, net_wm_visible_icon_name
, data
);
1380 self
->icon_title
= data
;
1383 void client_update_class(ObClient
*self
)
1388 if (self
->name
) g_free(self
->name
);
1389 if (self
->class) g_free(self
->class);
1390 if (self
->role
) g_free(self
->role
);
1392 self
->name
= self
->class = self
->role
= NULL
;
1394 if (PROP_GETSS(self
->window
, wm_class
, locale
, &data
)) {
1396 self
->name
= g_strdup(data
[0]);
1398 self
->class = g_strdup(data
[1]);
1403 if (PROP_GETS(self
->window
, wm_window_role
, locale
, &s
))
1404 self
->role
= g_strdup(s
);
1406 if (self
->name
== NULL
) self
->name
= g_strdup("");
1407 if (self
->class == NULL
) self
->class = g_strdup("");
1408 if (self
->role
== NULL
) self
->role
= g_strdup("");
1411 void client_update_strut(ObClient
*self
)
1415 gboolean got
= FALSE
;
1418 if (PROP_GETA32(self
->window
, net_wm_strut_partial
, cardinal
,
1422 STRUT_PARTIAL_SET(strut
,
1423 data
[0], data
[2], data
[1], data
[3],
1424 data
[4], data
[5], data
[8], data
[9],
1425 data
[6], data
[7], data
[10], data
[11]);
1431 PROP_GETA32(self
->window
, net_wm_strut
, cardinal
, &data
, &num
)) {
1434 STRUT_PARTIAL_SET(strut
,
1435 data
[0], data
[2], data
[1], data
[3],
1436 0, 0, 0, 0, 0, 0, 0, 0);
1442 STRUT_PARTIAL_SET(strut
, 0, 0, 0, 0,
1443 0, 0, 0, 0, 0, 0, 0, 0);
1445 if (!STRUT_EQUAL(strut
, self
->strut
)) {
1446 self
->strut
= strut
;
1448 /* updating here is pointless while we're being mapped cuz we're not in
1449 the client list yet */
1451 screen_update_areas();
1455 void client_update_icons(ObClient
*self
)
1461 for (i
= 0; i
< self
->nicons
; ++i
)
1462 g_free(self
->icons
[i
].data
);
1463 if (self
->nicons
> 0)
1464 g_free(self
->icons
);
1467 if (PROP_GETA32(self
->window
, net_wm_icon
, cardinal
, &data
, &num
)) {
1468 /* figure out how many valid icons are in here */
1470 while (num
- i
> 2) {
1474 if (i
> num
|| w
*h
== 0) break;
1478 self
->icons
= g_new(ObClientIcon
, self
->nicons
);
1480 /* store the icons */
1482 for (j
= 0; j
< self
->nicons
; ++j
) {
1485 w
= self
->icons
[j
].width
= data
[i
++];
1486 h
= self
->icons
[j
].height
= data
[i
++];
1488 if (w
*h
== 0) continue;
1490 self
->icons
[j
].data
= g_new(RrPixel32
, w
* h
);
1491 for (x
= 0, y
= 0, t
= 0; t
< w
* h
; ++t
, ++x
, ++i
) {
1496 self
->icons
[j
].data
[t
] =
1497 (((data
[i
] >> 24) & 0xff) << RrDefaultAlphaOffset
) +
1498 (((data
[i
] >> 16) & 0xff) << RrDefaultRedOffset
) +
1499 (((data
[i
] >> 8) & 0xff) << RrDefaultGreenOffset
) +
1500 (((data
[i
] >> 0) & 0xff) << RrDefaultBlueOffset
);
1506 } else if (PROP_GETA32(self
->window
, kwm_win_icon
,
1507 kwm_win_icon
, &data
, &num
)) {
1510 self
->icons
= g_new(ObClientIcon
, self
->nicons
);
1511 xerror_set_ignore(TRUE
);
1512 if (!RrPixmapToRGBA(ob_rr_inst
,
1514 &self
->icons
[self
->nicons
-1].width
,
1515 &self
->icons
[self
->nicons
-1].height
,
1516 &self
->icons
[self
->nicons
-1].data
)) {
1517 g_free(&self
->icons
[self
->nicons
-1]);
1520 xerror_set_ignore(FALSE
);
1526 if ((hints
= XGetWMHints(ob_display
, self
->window
))) {
1527 if (hints
->flags
& IconPixmapHint
) {
1529 self
->icons
= g_new(ObClientIcon
, self
->nicons
);
1530 xerror_set_ignore(TRUE
);
1531 if (!RrPixmapToRGBA(ob_rr_inst
,
1533 (hints
->flags
& IconMaskHint
?
1534 hints
->icon_mask
: None
),
1535 &self
->icons
[self
->nicons
-1].width
,
1536 &self
->icons
[self
->nicons
-1].height
,
1537 &self
->icons
[self
->nicons
-1].data
)){
1538 g_free(&self
->icons
[self
->nicons
-1]);
1541 xerror_set_ignore(FALSE
);
1548 frame_adjust_icon(self
->frame
);
1551 static void client_change_state(ObClient
*self
)
1554 guint32 netstate
[10];
1557 state
[0] = self
->wmstate
;
1559 PROP_SETA32(self
->window
, wm_state
, wm_state
, state
, 2);
1563 netstate
[num
++] = prop_atoms
.net_wm_state_modal
;
1565 netstate
[num
++] = prop_atoms
.net_wm_state_shaded
;
1567 netstate
[num
++] = prop_atoms
.net_wm_state_hidden
;
1568 if (self
->skip_taskbar
)
1569 netstate
[num
++] = prop_atoms
.net_wm_state_skip_taskbar
;
1570 if (self
->skip_pager
)
1571 netstate
[num
++] = prop_atoms
.net_wm_state_skip_pager
;
1572 if (self
->fullscreen
)
1573 netstate
[num
++] = prop_atoms
.net_wm_state_fullscreen
;
1575 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_vert
;
1577 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_horz
;
1579 netstate
[num
++] = prop_atoms
.net_wm_state_above
;
1581 netstate
[num
++] = prop_atoms
.net_wm_state_below
;
1582 PROP_SETA32(self
->window
, net_wm_state
, atom
, netstate
, num
);
1584 client_calc_layer(self
);
1587 frame_adjust_state(self
->frame
);
1590 ObClient
*client_search_focus_tree(ObClient
*self
)
1595 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
) {
1596 if (client_focused(it
->data
)) return it
->data
;
1597 if ((ret
= client_search_focus_tree(it
->data
))) return ret
;
1602 ObClient
*client_search_focus_tree_full(ObClient
*self
)
1604 if (self
->transient_for
) {
1605 if (self
->transient_for
!= OB_TRAN_GROUP
) {
1606 return client_search_focus_tree_full(self
->transient_for
);
1609 gboolean recursed
= FALSE
;
1611 for (it
= self
->group
->members
; it
; it
= it
->next
)
1612 if (!((ObClient
*)it
->data
)->transient_for
) {
1614 if ((c
= client_search_focus_tree_full(it
->data
)))
1623 /* this function checks the whole tree, the client_search_focus_tree~
1624 does not, so we need to check this window */
1625 if (client_focused(self
))
1627 return client_search_focus_tree(self
);
1630 static ObStackingLayer
calc_layer(ObClient
*self
)
1634 if (self
->fullscreen
) l
= OB_STACKING_LAYER_FULLSCREEN
;
1635 else if (self
->type
== OB_CLIENT_TYPE_DESKTOP
)
1636 l
= OB_STACKING_LAYER_DESKTOP
;
1637 else if (self
->type
== OB_CLIENT_TYPE_DOCK
) {
1638 if (!self
->below
) l
= OB_STACKING_LAYER_TOP
;
1639 else l
= OB_STACKING_LAYER_NORMAL
;
1641 else if (self
->above
) l
= OB_STACKING_LAYER_ABOVE
;
1642 else if (self
->below
) l
= OB_STACKING_LAYER_BELOW
;
1643 else l
= OB_STACKING_LAYER_NORMAL
;
1648 static void client_calc_layer_recursive(ObClient
*self
, ObClient
*orig
,
1649 ObStackingLayer l
, gboolean raised
)
1651 ObStackingLayer old
, own
;
1655 own
= calc_layer(self
);
1656 self
->layer
= l
> own
? l
: own
;
1658 for (it
= self
->transients
; it
; it
= it
->next
)
1659 client_calc_layer_recursive(it
->data
, orig
,
1660 l
, raised
? raised
: l
!= old
);
1662 if (!raised
&& l
!= old
)
1663 if (orig
->frame
) { /* only restack if the original window is managed */
1664 /* XXX add_non_intrusive ever? */
1665 stacking_remove(CLIENT_AS_WINDOW(self
));
1666 stacking_add(CLIENT_AS_WINDOW(self
));
1670 void client_calc_layer(ObClient
*self
)
1677 /* transients take on the layer of their parents */
1678 self
= client_search_top_transient(self
);
1680 l
= calc_layer(self
);
1682 client_calc_layer_recursive(self
, orig
, l
, FALSE
);
1685 gboolean
client_should_show(ObClient
*self
)
1687 if (self
->iconic
) return FALSE
;
1688 else if (!(self
->desktop
== screen_desktop
||
1689 self
->desktop
== DESKTOP_ALL
)) return FALSE
;
1690 else if (client_normal(self
) && screen_showing_desktop
) return FALSE
;
1695 static void client_showhide(ObClient
*self
)
1698 if (client_should_show(self
))
1699 frame_show(self
->frame
);
1701 frame_hide(self
->frame
);
1704 gboolean
client_normal(ObClient
*self
) {
1705 return ! (self
->type
== OB_CLIENT_TYPE_DESKTOP
||
1706 self
->type
== OB_CLIENT_TYPE_DOCK
||
1707 self
->type
== OB_CLIENT_TYPE_SPLASH
);
1710 static void client_apply_startup_state(ObClient
*self
)
1712 /* these are in a carefully crafted order.. */
1715 self
->iconic
= FALSE
;
1716 client_iconify(self
, TRUE
, FALSE
);
1718 if (self
->fullscreen
) {
1719 self
->fullscreen
= FALSE
;
1720 client_fullscreen(self
, TRUE
, FALSE
);
1723 self
->shaded
= FALSE
;
1724 client_shade(self
, TRUE
);
1729 if (self
->max_vert
&& self
->max_horz
) {
1730 self
->max_vert
= self
->max_horz
= FALSE
;
1731 client_maximize(self
, TRUE
, 0, FALSE
);
1732 } else if (self
->max_vert
) {
1733 self
->max_vert
= FALSE
;
1734 client_maximize(self
, TRUE
, 2, FALSE
);
1735 } else if (self
->max_horz
) {
1736 self
->max_horz
= FALSE
;
1737 client_maximize(self
, TRUE
, 1, FALSE
);
1740 /* nothing to do for the other states:
1749 void client_configure_full(ObClient
*self
, ObCorner anchor
,
1750 int x
, int y
, int w
, int h
,
1751 gboolean user
, gboolean final
,
1752 gboolean force_reply
)
1754 gboolean moved
= FALSE
, resized
= FALSE
;
1755 guint fdecor
= self
->frame
->decorations
;
1756 gboolean fhorz
= self
->frame
->max_horz
;
1758 /* make the frame recalculate its dimentions n shit without changing
1759 anything visible for real, this way the constraints below can work with
1760 the updated frame dimensions. */
1761 frame_adjust_area(self
->frame
, TRUE
, TRUE
, TRUE
);
1763 /* gets the frame's position */
1764 frame_client_gravity(self
->frame
, &x
, &y
);
1766 /* these positions are frame positions, not client positions */
1768 /* set the size and position if fullscreen */
1769 if (self
->fullscreen
) {
1772 XF86VidModeModeLine mode
;
1777 i
= client_monitor(self
);
1778 a
= screen_physical_area_monitor(i
);
1781 if (i
== 0 && /* primary head */
1782 extensions_vidmode
&&
1783 XF86VidModeGetViewPort(ob_display
, ob_screen
, &x
, &y
) &&
1784 /* get the mode last so the mode.privsize isnt freed incorrectly */
1785 XF86VidModeGetModeLine(ob_display
, ob_screen
, &dot
, &mode
)) {
1790 if (mode
.privsize
) XFree(mode
.private);
1800 user
= FALSE
; /* ignore that increment etc shit when in fullscreen */
1804 a
= screen_area_monitor(self
->desktop
, client_monitor(self
));
1806 /* set the size and position if maximized */
1807 if (self
->max_horz
) {
1809 w
= a
->width
- self
->frame
->size
.left
- self
->frame
->size
.right
;
1811 if (self
->max_vert
) {
1813 h
= a
->height
- self
->frame
->size
.top
- self
->frame
->size
.bottom
;
1817 /* gets the client's position */
1818 frame_frame_gravity(self
->frame
, &x
, &y
);
1820 /* these override the above states! if you cant move you can't move! */
1822 if (!(self
->functions
& OB_CLIENT_FUNC_MOVE
)) {
1826 if (!(self
->functions
& OB_CLIENT_FUNC_RESIZE
)) {
1827 w
= self
->area
.width
;
1828 h
= self
->area
.height
;
1832 if (!(w
== self
->area
.width
&& h
== self
->area
.height
)) {
1833 int basew
, baseh
, minw
, minh
;
1836 /* base size is substituted with min size if not specified */
1837 if (self
->base_size
.width
|| self
->base_size
.height
) {
1838 basew
= self
->base_size
.width
;
1839 baseh
= self
->base_size
.height
;
1841 basew
= self
->min_size
.width
;
1842 baseh
= self
->min_size
.height
;
1844 /* min size is substituted with base size if not specified */
1845 if (self
->min_size
.width
|| self
->min_size
.height
) {
1846 minw
= self
->min_size
.width
;
1847 minh
= self
->min_size
.height
;
1849 minw
= self
->base_size
.width
;
1850 minh
= self
->base_size
.height
;
1853 /* for interactive resizing. have to move half an increment in each
1856 /* how far we are towards the next size inc */
1857 mw
= (w
- basew
) % self
->size_inc
.width
;
1858 mh
= (h
- baseh
) % self
->size_inc
.height
;
1860 aw
= self
->size_inc
.width
/ 2;
1861 ah
= self
->size_inc
.height
/ 2;
1862 /* don't let us move into a new size increment */
1863 if (mw
+ aw
>= self
->size_inc
.width
)
1864 aw
= self
->size_inc
.width
- mw
- 1;
1865 if (mh
+ ah
>= self
->size_inc
.height
)
1866 ah
= self
->size_inc
.height
- mh
- 1;
1870 /* if this is a user-requested resize, then check against min/max
1873 /* smaller than min size or bigger than max size? */
1874 if (w
> self
->max_size
.width
) w
= self
->max_size
.width
;
1875 if (w
< minw
) w
= minw
;
1876 if (h
> self
->max_size
.height
) h
= self
->max_size
.height
;
1877 if (h
< minh
) h
= minh
;
1882 /* keep to the increments */
1883 w
/= self
->size_inc
.width
;
1884 h
/= self
->size_inc
.height
;
1886 /* you cannot resize to nothing */
1887 if (basew
+ w
< 1) w
= 1 - basew
;
1888 if (baseh
+ h
< 1) h
= 1 - baseh
;
1890 /* store the logical size */
1891 SIZE_SET(self
->logical_size
,
1892 self
->size_inc
.width
> 1 ? w
: w
+ basew
,
1893 self
->size_inc
.height
> 1 ? h
: h
+ baseh
);
1895 w
*= self
->size_inc
.width
;
1896 h
*= self
->size_inc
.height
;
1901 /* adjust the height to match the width for the aspect ratios.
1902 for this, min size is not substituted for base size ever. */
1903 w
-= self
->base_size
.width
;
1904 h
-= self
->base_size
.height
;
1906 if (self
->min_ratio
)
1907 if (h
* self
->min_ratio
> w
) h
= (int)(w
/ self
->min_ratio
);
1908 if (self
->max_ratio
)
1909 if (h
* self
->max_ratio
< w
) h
= (int)(w
/ self
->max_ratio
);
1911 w
+= self
->base_size
.width
;
1912 h
+= self
->base_size
.height
;
1916 case OB_CORNER_TOPLEFT
:
1918 case OB_CORNER_TOPRIGHT
:
1919 x
-= w
- self
->area
.width
;
1921 case OB_CORNER_BOTTOMLEFT
:
1922 y
-= h
- self
->area
.height
;
1924 case OB_CORNER_BOTTOMRIGHT
:
1925 x
-= w
- self
->area
.width
;
1926 y
-= h
- self
->area
.height
;
1930 moved
= x
!= self
->area
.x
|| y
!= self
->area
.y
;
1931 resized
= w
!= self
->area
.width
|| h
!= self
->area
.height
;
1933 RECT_SET(self
->area
, x
, y
, w
, h
);
1935 /* for app-requested resizes, always resize if 'resized' is true.
1936 for user-requested ones, only resize if final is true, or when
1937 resizing in redraw mode */
1938 if ((!user
&& resized
) ||
1939 (user
&& (final
|| (resized
&& config_redraw_resize
))))
1940 XResizeWindow(ob_display
, self
->window
, w
, h
);
1942 /* move/resize the frame to match the request */
1944 if (self
->decorations
!= fdecor
|| self
->max_horz
!= fhorz
)
1945 moved
= resized
= TRUE
;
1947 if (moved
|| resized
)
1948 frame_adjust_area(self
->frame
, moved
, resized
, FALSE
);
1950 if (!resized
&& (force_reply
|| ((!user
&& moved
) || (user
&& final
))))
1953 event
.type
= ConfigureNotify
;
1954 event
.xconfigure
.display
= ob_display
;
1955 event
.xconfigure
.event
= self
->window
;
1956 event
.xconfigure
.window
= self
->window
;
1958 /* root window real coords */
1959 event
.xconfigure
.x
= self
->frame
->area
.x
+ self
->frame
->size
.left
-
1961 event
.xconfigure
.y
= self
->frame
->area
.y
+ self
->frame
->size
.top
-
1963 event
.xconfigure
.width
= w
;
1964 event
.xconfigure
.height
= h
;
1965 event
.xconfigure
.border_width
= 0;
1966 event
.xconfigure
.above
= self
->frame
->plate
;
1967 event
.xconfigure
.override_redirect
= FALSE
;
1968 XSendEvent(event
.xconfigure
.display
, event
.xconfigure
.window
,
1969 FALSE
, StructureNotifyMask
, &event
);
1974 void client_fullscreen(ObClient
*self
, gboolean fs
, gboolean savearea
)
1978 if (!(self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
) || /* can't */
1979 self
->fullscreen
== fs
) return; /* already done */
1981 self
->fullscreen
= fs
;
1982 client_change_state(self
); /* change the state hints on the client,
1983 and adjust out layer/stacking */
1987 guint32 dimensions
[4];
1988 dimensions
[0] = self
->area
.x
;
1989 dimensions
[1] = self
->area
.y
;
1990 dimensions
[2] = self
->area
.width
;
1991 dimensions
[3] = self
->area
.height
;
1993 PROP_SETA32(self
->window
, openbox_premax
, cardinal
,
1997 /* these are not actually used cuz client_configure will set them
1998 as appropriate when the window is fullscreened */
2005 /* pick some fallbacks... */
2006 a
= screen_area_monitor(self
->desktop
, 0);
2007 x
= a
->x
+ a
->width
/ 4;
2008 y
= a
->y
+ a
->height
/ 4;
2012 if (PROP_GETA32(self
->window
, openbox_premax
, cardinal
,
2013 (guint32
**)&dimensions
, &num
)) {
2024 client_setup_decor_and_functions(self
);
2026 client_configure(self
, OB_CORNER_TOPLEFT
, x
, y
, w
, h
, TRUE
, TRUE
);
2028 /* try focus us when we go into fullscreen mode */
2032 static void client_iconify_recursive(ObClient
*self
,
2033 gboolean iconic
, gboolean curdesk
)
2036 gboolean changed
= FALSE
;
2039 if (self
->iconic
!= iconic
) {
2040 ob_debug("%sconifying window: 0x%lx\n", (iconic
? "I" : "Uni"),
2043 self
->iconic
= iconic
;
2046 if (self
->functions
& OB_CLIENT_FUNC_ICONIFY
) {
2047 self
->wmstate
= IconicState
;
2048 self
->ignore_unmaps
++;
2049 /* we unmap the client itself so that we can get MapRequest
2050 events, and because the ICCCM tells us to! */
2051 XUnmapWindow(ob_display
, self
->window
);
2053 /* update the focus lists.. iconic windows go to the bottom of
2054 the list, put the new iconic window at the 'top of the
2056 focus_order_to_top(self
);
2062 client_set_desktop(self
, screen_desktop
, FALSE
);
2063 self
->wmstate
= self
->shaded
? IconicState
: NormalState
;
2064 XMapWindow(ob_display
, self
->window
);
2066 /* this puts it after the current focused window */
2067 focus_order_remove(self
);
2068 focus_order_add_new(self
);
2070 /* this is here cuz with the VIDMODE extension, the viewport can
2071 change while a fullscreen window is iconic, and when it
2072 uniconifies, it would be nice if it did so to the new position
2074 client_reconfigure(self
);
2081 client_change_state(self
);
2082 client_showhide(self
);
2083 screen_update_areas();
2086 /* iconify all transients */
2087 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
)
2088 if (it
->data
!= self
) client_iconify_recursive(it
->data
,
2092 void client_iconify(ObClient
*self
, gboolean iconic
, gboolean curdesk
)
2094 /* move up the transient chain as far as possible first */
2095 self
= client_search_top_transient(self
);
2097 client_iconify_recursive(client_search_top_transient(self
),
2101 void client_maximize(ObClient
*self
, gboolean max
, int dir
, gboolean savearea
)
2105 g_assert(dir
== 0 || dir
== 1 || dir
== 2);
2106 if (!(self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
)) return; /* can't */
2108 /* check if already done */
2110 if (dir
== 0 && self
->max_horz
&& self
->max_vert
) return;
2111 if (dir
== 1 && self
->max_horz
) return;
2112 if (dir
== 2 && self
->max_vert
) return;
2114 if (dir
== 0 && !self
->max_horz
&& !self
->max_vert
) return;
2115 if (dir
== 1 && !self
->max_horz
) return;
2116 if (dir
== 2 && !self
->max_vert
) return;
2119 /* work with the frame's coords */
2120 x
= self
->frame
->area
.x
;
2121 y
= self
->frame
->area
.y
;
2122 w
= self
->area
.width
;
2123 h
= self
->area
.height
;
2127 gint32 dimensions
[4];
2136 /* get the property off the window and use it for the dimensions
2137 we are already maxed on */
2138 if (PROP_GETA32(self
->window
, openbox_premax
, cardinal
,
2139 (guint32
**)&readdim
, &num
)) {
2141 if (self
->max_horz
) {
2142 dimensions
[0] = readdim
[0];
2143 dimensions
[2] = readdim
[2];
2145 if (self
->max_vert
) {
2146 dimensions
[1] = readdim
[1];
2147 dimensions
[3] = readdim
[3];
2153 PROP_SETA32(self
->window
, openbox_premax
, cardinal
,
2154 (guint32
*)dimensions
, 4);
2161 /* pick some fallbacks... */
2162 a
= screen_area_monitor(self
->desktop
, 0);
2163 if (dir
== 0 || dir
== 1) { /* horz */
2164 x
= a
->x
+ a
->width
/ 4;
2167 if (dir
== 0 || dir
== 2) { /* vert */
2168 y
= a
->y
+ a
->height
/ 4;
2172 if (PROP_GETA32(self
->window
, openbox_premax
, cardinal
,
2173 (guint32
**)&dimensions
, &num
)) {
2175 if (dir
== 0 || dir
== 1) { /* horz */
2179 if (dir
== 0 || dir
== 2) { /* vert */
2188 if (dir
== 0 || dir
== 1) /* horz */
2189 self
->max_horz
= max
;
2190 if (dir
== 0 || dir
== 2) /* vert */
2191 self
->max_vert
= max
;
2193 if (!self
->max_horz
&& !self
->max_vert
)
2194 PROP_ERASE(self
->window
, openbox_premax
);
2196 client_change_state(self
); /* change the state hints on the client */
2198 client_setup_decor_and_functions(self
);
2200 /* figure out where the client should be going */
2201 frame_frame_gravity(self
->frame
, &x
, &y
);
2202 client_configure(self
, OB_CORNER_TOPLEFT
, x
, y
, w
, h
, TRUE
, TRUE
);
2205 void client_shade(ObClient
*self
, gboolean shade
)
2207 if ((!(self
->functions
& OB_CLIENT_FUNC_SHADE
) &&
2208 shade
) || /* can't shade */
2209 self
->shaded
== shade
) return; /* already done */
2211 /* when we're iconic, don't change the wmstate */
2213 self
->wmstate
= shade
? IconicState
: NormalState
;
2214 self
->shaded
= shade
;
2215 client_change_state(self
);
2216 /* resize the frame to just the titlebar */
2217 frame_adjust_area(self
->frame
, FALSE
, FALSE
, FALSE
);
2220 void client_close(ObClient
*self
)
2224 if (!(self
->functions
& OB_CLIENT_FUNC_CLOSE
)) return;
2227 XXX: itd be cool to do timeouts and shit here for killing the client's
2229 like... if the window is around after 5 seconds, then the close button
2230 turns a nice red, and if this function is called again, the client is
2234 ce
.xclient
.type
= ClientMessage
;
2235 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
2236 ce
.xclient
.display
= ob_display
;
2237 ce
.xclient
.window
= self
->window
;
2238 ce
.xclient
.format
= 32;
2239 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_delete_window
;
2240 ce
.xclient
.data
.l
[1] = event_lasttime
;
2241 ce
.xclient
.data
.l
[2] = 0l;
2242 ce
.xclient
.data
.l
[3] = 0l;
2243 ce
.xclient
.data
.l
[4] = 0l;
2244 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
2247 void client_kill(ObClient
*self
)
2249 XKillClient(ob_display
, self
->window
);
2252 void client_set_desktop_recursive(ObClient
*self
,
2253 guint target
, gboolean donthide
)
2258 if (target
!= self
->desktop
) {
2260 ob_debug("Setting desktop %u\n", target
+1);
2262 g_assert(target
< screen_num_desktops
|| target
== DESKTOP_ALL
);
2264 /* remove from the old desktop(s) */
2265 focus_order_remove(self
);
2267 old
= self
->desktop
;
2268 self
->desktop
= target
;
2269 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, target
);
2270 /* the frame can display the current desktop state */
2271 frame_adjust_state(self
->frame
);
2272 /* 'move' the window to the new desktop */
2274 client_showhide(self
);
2275 /* raise if it was not already on the desktop */
2276 if (old
!= DESKTOP_ALL
)
2277 stacking_raise(CLIENT_AS_WINDOW(self
));
2278 screen_update_areas();
2280 /* add to the new desktop(s) */
2281 if (config_focus_new
)
2282 focus_order_to_top(self
);
2284 focus_order_to_bottom(self
);
2287 /* move all transients */
2288 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
)
2289 if (it
->data
!= self
) client_set_desktop_recursive(it
->data
,
2293 void client_set_desktop(ObClient
*self
, guint target
, gboolean donthide
)
2295 client_set_desktop_recursive(client_search_top_transient(self
),
2299 ObClient
*client_search_modal_child(ObClient
*self
)
2304 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
) {
2305 ObClient
*c
= it
->data
;
2306 if ((ret
= client_search_modal_child(c
))) return ret
;
2307 if (c
->modal
) return c
;
2312 gboolean
client_validate(ObClient
*self
)
2316 XSync(ob_display
, FALSE
); /* get all events on the server */
2318 if (XCheckTypedWindowEvent(ob_display
, self
->window
, DestroyNotify
, &e
) ||
2319 XCheckTypedWindowEvent(ob_display
, self
->window
, UnmapNotify
, &e
)) {
2320 XPutBackEvent(ob_display
, &e
);
2327 void client_set_wm_state(ObClient
*self
, long state
)
2329 if (state
== self
->wmstate
) return; /* no change */
2333 client_iconify(self
, TRUE
, TRUE
);
2336 client_iconify(self
, FALSE
, TRUE
);
2341 void client_set_state(ObClient
*self
, Atom action
, long data1
, long data2
)
2343 gboolean shaded
= self
->shaded
;
2344 gboolean fullscreen
= self
->fullscreen
;
2345 gboolean max_horz
= self
->max_horz
;
2346 gboolean max_vert
= self
->max_vert
;
2349 if (!(action
== prop_atoms
.net_wm_state_add
||
2350 action
== prop_atoms
.net_wm_state_remove
||
2351 action
== prop_atoms
.net_wm_state_toggle
))
2352 /* an invalid action was passed to the client message, ignore it */
2355 for (i
= 0; i
< 2; ++i
) {
2356 Atom state
= i
== 0 ? data1
: data2
;
2358 if (!state
) continue;
2360 /* if toggling, then pick whether we're adding or removing */
2361 if (action
== prop_atoms
.net_wm_state_toggle
) {
2362 if (state
== prop_atoms
.net_wm_state_modal
)
2363 action
= self
->modal
? prop_atoms
.net_wm_state_remove
:
2364 prop_atoms
.net_wm_state_add
;
2365 else if (state
== prop_atoms
.net_wm_state_maximized_vert
)
2366 action
= self
->max_vert
? prop_atoms
.net_wm_state_remove
:
2367 prop_atoms
.net_wm_state_add
;
2368 else if (state
== prop_atoms
.net_wm_state_maximized_horz
)
2369 action
= self
->max_horz
? prop_atoms
.net_wm_state_remove
:
2370 prop_atoms
.net_wm_state_add
;
2371 else if (state
== prop_atoms
.net_wm_state_shaded
)
2372 action
= self
->shaded
? prop_atoms
.net_wm_state_remove
:
2373 prop_atoms
.net_wm_state_add
;
2374 else if (state
== prop_atoms
.net_wm_state_skip_taskbar
)
2375 action
= self
->skip_taskbar
?
2376 prop_atoms
.net_wm_state_remove
:
2377 prop_atoms
.net_wm_state_add
;
2378 else if (state
== prop_atoms
.net_wm_state_skip_pager
)
2379 action
= self
->skip_pager
?
2380 prop_atoms
.net_wm_state_remove
:
2381 prop_atoms
.net_wm_state_add
;
2382 else if (state
== prop_atoms
.net_wm_state_fullscreen
)
2383 action
= self
->fullscreen
?
2384 prop_atoms
.net_wm_state_remove
:
2385 prop_atoms
.net_wm_state_add
;
2386 else if (state
== prop_atoms
.net_wm_state_above
)
2387 action
= self
->above
? prop_atoms
.net_wm_state_remove
:
2388 prop_atoms
.net_wm_state_add
;
2389 else if (state
== prop_atoms
.net_wm_state_below
)
2390 action
= self
->below
? prop_atoms
.net_wm_state_remove
:
2391 prop_atoms
.net_wm_state_add
;
2394 if (action
== prop_atoms
.net_wm_state_add
) {
2395 if (state
== prop_atoms
.net_wm_state_modal
) {
2396 /* XXX raise here or something? */
2398 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
2400 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
2402 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
2404 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
2405 self
->skip_taskbar
= TRUE
;
2406 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
2407 self
->skip_pager
= TRUE
;
2408 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
2410 } else if (state
== prop_atoms
.net_wm_state_above
) {
2412 } else if (state
== prop_atoms
.net_wm_state_below
) {
2416 } else { /* action == prop_atoms.net_wm_state_remove */
2417 if (state
== prop_atoms
.net_wm_state_modal
) {
2418 self
->modal
= FALSE
;
2419 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
2421 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
2423 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
2425 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
2426 self
->skip_taskbar
= FALSE
;
2427 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
2428 self
->skip_pager
= FALSE
;
2429 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
2431 } else if (state
== prop_atoms
.net_wm_state_above
) {
2432 self
->above
= FALSE
;
2433 } else if (state
== prop_atoms
.net_wm_state_below
) {
2434 self
->below
= FALSE
;
2438 if (max_horz
!= self
->max_horz
|| max_vert
!= self
->max_vert
) {
2439 if (max_horz
!= self
->max_horz
&& max_vert
!= self
->max_vert
) {
2441 if (max_horz
== max_vert
) { /* both going the same way */
2442 client_maximize(self
, max_horz
, 0, TRUE
);
2444 client_maximize(self
, max_horz
, 1, TRUE
);
2445 client_maximize(self
, max_vert
, 2, TRUE
);
2449 if (max_horz
!= self
->max_horz
)
2450 client_maximize(self
, max_horz
, 1, TRUE
);
2452 client_maximize(self
, max_vert
, 2, TRUE
);
2455 /* change fullscreen state before shading, as it will affect if the window
2457 if (fullscreen
!= self
->fullscreen
)
2458 client_fullscreen(self
, fullscreen
, TRUE
);
2459 if (shaded
!= self
->shaded
)
2460 client_shade(self
, shaded
);
2461 client_calc_layer(self
);
2462 client_change_state(self
); /* change the hint to reflect these changes */
2465 ObClient
*client_focus_target(ObClient
*self
)
2469 /* if we have a modal child, then focus it, not us */
2470 child
= client_search_modal_child(self
);
2471 if (child
) return child
;
2475 gboolean
client_can_focus(ObClient
*self
)
2479 /* choose the correct target */
2480 self
= client_focus_target(self
);
2482 if (!self
->frame
->visible
)
2485 if (!((self
->can_focus
|| self
->focus_notify
) &&
2486 (self
->desktop
== screen_desktop
||
2487 self
->desktop
== DESKTOP_ALL
) &&
2491 /* do a check to see if the window has already been unmapped or destroyed
2492 do this intelligently while watching out for unmaps we've generated
2493 (ignore_unmaps > 0) */
2494 if (XCheckTypedWindowEvent(ob_display
, self
->window
,
2495 DestroyNotify
, &ev
)) {
2496 XPutBackEvent(ob_display
, &ev
);
2499 while (XCheckTypedWindowEvent(ob_display
, self
->window
,
2500 UnmapNotify
, &ev
)) {
2501 if (self
->ignore_unmaps
) {
2502 self
->ignore_unmaps
--;
2504 XPutBackEvent(ob_display
, &ev
);
2512 gboolean
client_focus(ObClient
*self
)
2514 /* choose the correct target */
2515 self
= client_focus_target(self
);
2517 if (!client_can_focus(self
)) {
2518 if (!self
->frame
->visible
) {
2519 /* update the focus lists */
2520 focus_order_to_top(self
);
2525 if (self
->can_focus
)
2526 /* RevertToPointerRoot causes much more headache than RevertToNone, so
2527 I choose to use it always, hopefully to find errors quicker, if any
2528 are left. (I hate X. I hate focus events.) */
2529 XSetInputFocus(ob_display
, self
->window
, RevertToPointerRoot
,
2532 if (self
->focus_notify
) {
2534 ce
.xclient
.type
= ClientMessage
;
2535 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
2536 ce
.xclient
.display
= ob_display
;
2537 ce
.xclient
.window
= self
->window
;
2538 ce
.xclient
.format
= 32;
2539 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_take_focus
;
2540 ce
.xclient
.data
.l
[1] = event_lasttime
;
2541 ce
.xclient
.data
.l
[2] = 0l;
2542 ce
.xclient
.data
.l
[3] = 0l;
2543 ce
.xclient
.data
.l
[4] = 0l;
2544 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
2548 ob_debug("%sively focusing %lx at %d\n",
2549 (self
->can_focus
? "act" : "pass"),
2550 self
->window
, (int) event_lasttime
);
2553 /* Cause the FocusIn to come back to us. Important for desktop switches,
2554 since otherwise we'll have no FocusIn on the queue and send it off to
2555 the focus_backup. */
2556 XSync(ob_display
, FALSE
);
2560 void client_unfocus(ObClient
*self
)
2562 g_assert(focus_client
== self
);
2564 ob_debug("client_unfocus for %lx\n", self
->window
);
2566 focus_fallback(OB_FOCUS_FALLBACK_UNFOCUSING
);
2569 void client_activate(ObClient
*self
, gboolean here
)
2571 if (client_normal(self
) && screen_showing_desktop
)
2572 screen_show_desktop(FALSE
);
2574 client_iconify(self
, FALSE
, FALSE
);
2575 if (self
->desktop
!= DESKTOP_ALL
&&
2576 self
->desktop
!= screen_desktop
) {
2578 client_set_desktop(self
, screen_desktop
, FALSE
);
2580 screen_set_desktop(self
->desktop
);
2581 } else if (!self
->frame
->visible
)
2582 /* if its not visible for other reasons, then don't mess
2586 client_shade(self
, FALSE
);
2588 stacking_raise(CLIENT_AS_WINDOW(self
));
2591 gboolean
client_focused(ObClient
*self
)
2593 return self
== focus_client
;
2596 ObClientIcon
*client_icon(ObClient
*self
, int w
, int h
)
2599 /* si is the smallest image >= req */
2600 /* li is the largest image < req */
2601 unsigned long size
, smallest
= 0xffffffff, largest
= 0, si
= 0, li
= 0;
2603 if (!self
->nicons
) return NULL
;
2605 for (i
= 0; i
< self
->nicons
; ++i
) {
2606 size
= self
->icons
[i
].width
* self
->icons
[i
].height
;
2607 if (size
< smallest
&& size
>= (unsigned)(w
* h
)) {
2611 if (size
> largest
&& size
<= (unsigned)(w
* h
)) {
2616 if (largest
== 0) /* didnt find one smaller than the requested size */
2617 return &self
->icons
[si
];
2618 return &self
->icons
[li
];
2621 /* this be mostly ripped from fvwm */
2622 ObClient
*client_find_directional(ObClient
*c
, ObDirection dir
)
2624 int my_cx
, my_cy
, his_cx
, his_cy
;
2627 int score
, best_score
;
2628 ObClient
*best_client
, *cur
;
2634 /* first, find the centre coords of the currently focused window */
2635 my_cx
= c
->frame
->area
.x
+ c
->frame
->area
.width
/ 2;
2636 my_cy
= c
->frame
->area
.y
+ c
->frame
->area
.height
/ 2;
2641 for(it
= g_list_first(client_list
); it
; it
= it
->next
) {
2644 /* the currently selected window isn't interesting */
2647 if (!client_normal(cur
))
2649 if(c
->desktop
!= cur
->desktop
&& cur
->desktop
!= DESKTOP_ALL
)
2653 if(client_focus_target(cur
) == cur
&&
2654 !(cur
->can_focus
|| cur
->focus_notify
))
2657 /* find the centre coords of this window, from the
2658 * currently focused window's point of view */
2659 his_cx
= (cur
->frame
->area
.x
- my_cx
)
2660 + cur
->frame
->area
.width
/ 2;
2661 his_cy
= (cur
->frame
->area
.y
- my_cy
)
2662 + cur
->frame
->area
.height
/ 2;
2664 if(dir
== OB_DIRECTION_NORTHEAST
|| dir
== OB_DIRECTION_SOUTHEAST
||
2665 dir
== OB_DIRECTION_SOUTHWEST
|| dir
== OB_DIRECTION_NORTHWEST
) {
2667 /* Rotate the diagonals 45 degrees counterclockwise.
2668 * To do this, multiply the matrix /+h +h\ with the
2669 * vector (x y). \-h +h/
2670 * h = sqrt(0.5). We can set h := 1 since absolute
2671 * distance doesn't matter here. */
2672 tx
= his_cx
+ his_cy
;
2673 his_cy
= -his_cx
+ his_cy
;
2678 case OB_DIRECTION_NORTH
:
2679 case OB_DIRECTION_SOUTH
:
2680 case OB_DIRECTION_NORTHEAST
:
2681 case OB_DIRECTION_SOUTHWEST
:
2682 offset
= (his_cx
< 0) ? -his_cx
: his_cx
;
2683 distance
= ((dir
== OB_DIRECTION_NORTH
||
2684 dir
== OB_DIRECTION_NORTHEAST
) ?
2687 case OB_DIRECTION_EAST
:
2688 case OB_DIRECTION_WEST
:
2689 case OB_DIRECTION_SOUTHEAST
:
2690 case OB_DIRECTION_NORTHWEST
:
2691 offset
= (his_cy
< 0) ? -his_cy
: his_cy
;
2692 distance
= ((dir
== OB_DIRECTION_WEST
||
2693 dir
== OB_DIRECTION_NORTHWEST
) ?
2698 /* the target must be in the requested direction */
2702 /* Calculate score for this window. The smaller the better. */
2703 score
= distance
+ offset
;
2705 /* windows more than 45 degrees off the direction are
2706 * heavily penalized and will only be chosen if nothing
2707 * else within a million pixels */
2708 if(offset
> distance
)
2711 if(best_score
== -1 || score
< best_score
)
2719 void client_set_layer(ObClient
*self
, int layer
)
2723 self
->above
= FALSE
;
2724 } else if (layer
== 0) {
2725 self
->below
= self
->above
= FALSE
;
2727 self
->below
= FALSE
;
2730 client_calc_layer(self
);
2731 client_change_state(self
); /* reflect this in the state hints */
2734 guint
client_monitor(ObClient
*self
)
2738 for (i
= 0; i
< screen_num_monitors
; ++i
) {
2739 Rect
*area
= screen_physical_area_monitor(i
);
2740 if (RECT_INTERSECTS_RECT(*area
, self
->frame
->area
))
2743 if (i
== screen_num_monitors
) i
= 0;
2744 g_assert(i
< screen_num_monitors
);
2748 ObClient
*client_search_top_transient(ObClient
*self
)
2750 /* move up the transient chain as far as possible */
2751 if (self
->transient_for
) {
2752 if (self
->transient_for
!= OB_TRAN_GROUP
) {
2753 return client_search_top_transient(self
->transient_for
);
2757 for (it
= self
->group
->members
; it
; it
= it
->next
) {
2758 ObClient
*c
= it
->data
;
2760 /* checking transient_for prevents infinate loops! */
2761 if (c
!= self
&& !c
->transient_for
)
2772 ObClient
*client_search_transient(ObClient
*self
, ObClient
*search
)
2776 for (sit
= self
->transients
; sit
; sit
= g_slist_next(sit
)) {
2777 if (sit
->data
== search
)
2779 if (client_search_transient(sit
->data
, search
))
2785 gchar
* client_get_sm_client_id(ObClient
*self
)
2789 if (!PROP_GETS(self
->window
, sm_client_id
, locale
, &id
) && self
->group
)
2790 PROP_GETS(self
->group
->leader
, sm_client_id
, locale
, &id
);
2794 /* finds the nearest edge in the given direction from the current client
2795 * note to self: the edge is the -frame- edge (the actual one), not the
2798 int client_directional_edge_search(ObClient
*c
, ObDirection dir
)
2801 int my_edge_start
, my_edge_end
, my_offset
;
2808 a
= screen_area(c
->desktop
);
2811 case OB_DIRECTION_NORTH
:
2812 my_edge_start
= c
->frame
->area
.x
;
2813 my_edge_end
= c
->frame
->area
.x
+ c
->frame
->area
.width
;
2814 my_offset
= c
->frame
->area
.y
;
2816 dest
= a
->y
; /* default: top of screen */
2818 for(it
= g_list_first(client_list
); it
; it
= it
->next
) {
2819 int his_edge_start
, his_edge_end
, his_offset
;
2820 ObClient
*cur
= it
->data
;
2824 if(!client_normal(cur
))
2826 if(c
->desktop
!= cur
->desktop
&& cur
->desktop
!= DESKTOP_ALL
)
2831 his_edge_start
= cur
->frame
->area
.x
;
2832 his_edge_end
= cur
->frame
->area
.x
+ cur
->frame
->area
.width
;
2833 his_offset
= cur
->frame
->area
.y
+ cur
->frame
->area
.height
;
2835 if(his_offset
+ 1 > my_offset
)
2838 if(his_offset
< dest
)
2841 if(his_edge_start
>= my_edge_start
&&
2842 his_edge_start
<= my_edge_end
)
2845 if(my_edge_start
>= his_edge_start
&&
2846 my_edge_start
<= his_edge_end
)
2851 case OB_DIRECTION_SOUTH
:
2852 my_edge_start
= c
->frame
->area
.x
;
2853 my_edge_end
= c
->frame
->area
.x
+ c
->frame
->area
.width
;
2854 my_offset
= c
->frame
->area
.y
+ c
->frame
->area
.height
;
2856 dest
= a
->y
+ a
->height
; /* default: bottom of screen */
2858 for(it
= g_list_first(client_list
); it
; it
= it
->next
) {
2859 int his_edge_start
, his_edge_end
, his_offset
;
2860 ObClient
*cur
= it
->data
;
2864 if(!client_normal(cur
))
2866 if(c
->desktop
!= cur
->desktop
&& cur
->desktop
!= DESKTOP_ALL
)
2871 his_edge_start
= cur
->frame
->area
.x
;
2872 his_edge_end
= cur
->frame
->area
.x
+ cur
->frame
->area
.width
;
2873 his_offset
= cur
->frame
->area
.y
;
2876 if(his_offset
- 1 < my_offset
)
2879 if(his_offset
> dest
)
2882 if(his_edge_start
>= my_edge_start
&&
2883 his_edge_start
<= my_edge_end
)
2886 if(my_edge_start
>= his_edge_start
&&
2887 my_edge_start
<= his_edge_end
)
2892 case OB_DIRECTION_WEST
:
2893 my_edge_start
= c
->frame
->area
.y
;
2894 my_edge_end
= c
->frame
->area
.y
+ c
->frame
->area
.height
;
2895 my_offset
= c
->frame
->area
.x
;
2897 dest
= a
->x
; /* default: leftmost egde of screen */
2899 for(it
= g_list_first(client_list
); it
; it
= it
->next
) {
2900 int his_edge_start
, his_edge_end
, his_offset
;
2901 ObClient
*cur
= it
->data
;
2905 if(!client_normal(cur
))
2907 if(c
->desktop
!= cur
->desktop
&& cur
->desktop
!= DESKTOP_ALL
)
2912 his_edge_start
= cur
->frame
->area
.y
;
2913 his_edge_end
= cur
->frame
->area
.y
+ cur
->frame
->area
.height
;
2914 his_offset
= cur
->frame
->area
.x
+ cur
->frame
->area
.width
;
2916 if(his_offset
+ 1 > my_offset
)
2919 if(his_offset
< dest
)
2922 if(his_edge_start
>= my_edge_start
&&
2923 his_edge_start
<= my_edge_end
)
2926 if(my_edge_start
>= his_edge_start
&&
2927 my_edge_start
<= his_edge_end
)
2933 case OB_DIRECTION_EAST
:
2934 my_edge_start
= c
->frame
->area
.y
;
2935 my_edge_end
= c
->frame
->area
.y
+ c
->frame
->area
.height
;
2936 my_offset
= c
->frame
->area
.x
+ c
->frame
->area
.width
;
2938 dest
= a
->x
+ a
->width
; /* default: rightmost edge of screen */
2940 for(it
= g_list_first(client_list
); it
; it
= it
->next
) {
2941 int his_edge_start
, his_edge_end
, his_offset
;
2942 ObClient
*cur
= it
->data
;
2946 if(!client_normal(cur
))
2948 if(c
->desktop
!= cur
->desktop
&& cur
->desktop
!= DESKTOP_ALL
)
2953 his_edge_start
= cur
->frame
->area
.y
;
2954 his_edge_end
= cur
->frame
->area
.y
+ cur
->frame
->area
.height
;
2955 his_offset
= cur
->frame
->area
.x
;
2957 if(his_offset
- 1 < my_offset
)
2960 if(his_offset
> dest
)
2963 if(his_edge_start
>= my_edge_start
&&
2964 his_edge_start
<= my_edge_end
)
2967 if(my_edge_start
>= his_edge_start
&&
2968 my_edge_start
<= his_edge_end
)
2973 case OB_DIRECTION_NORTHEAST
:
2974 case OB_DIRECTION_SOUTHEAST
:
2975 case OB_DIRECTION_NORTHWEST
:
2976 case OB_DIRECTION_SOUTHWEST
:
2977 /* not implemented */
2980 g_assert_not_reached();