7 #include "moveresize.h"
9 #include "extensions.h"
21 #include "render/render.h"
24 #include <X11/Xutil.h>
26 /*! The event mask to grab on client windows */
27 #define CLIENT_EVENTMASK (PropertyChangeMask | FocusChangeMask | \
30 #define CLIENT_NOPROPAGATEMASK (ButtonPressMask | ButtonReleaseMask | \
33 GList
*client_list
= NULL
;
35 static void client_get_all(ObClient
*self
);
36 static void client_toggle_border(ObClient
*self
, gboolean show
);
37 static void client_get_area(ObClient
*self
);
38 static void client_get_desktop(ObClient
*self
);
39 static void client_get_state(ObClient
*self
);
40 static void client_get_shaped(ObClient
*self
);
41 static void client_get_mwm_hints(ObClient
*self
);
42 static void client_get_gravity(ObClient
*self
);
43 static void client_showhide(ObClient
*self
);
44 static void client_change_allowed_actions(ObClient
*self
);
45 static void client_change_state(ObClient
*self
);
46 static void client_apply_startup_state(ObClient
*self
);
47 static void client_restore_session_state(ObClient
*self
);
54 void client_shutdown()
58 void client_set_list()
60 Window
*windows
, *win_it
;
62 guint size
= g_list_length(client_list
);
64 /* create an array of the window ids */
66 windows
= g_new(Window
, size
);
68 for (it
= client_list
; it
!= NULL
; it
= it
->next
, ++win_it
)
69 *win_it
= ((ObClient
*)it
->data
)->window
;
73 PROP_SETA32(RootWindow(ob_display
, ob_screen
),
74 net_client_list
, window
, (guint32
*)windows
, size
);
83 void client_foreach_transient(ObClient *self, ObClientForeachFunc func, void *data)
87 for (it = self->transients; it; it = it->next) {
88 if (!func(it->data, data)) return;
89 client_foreach_transient(it->data, func, data);
93 void client_foreach_ancestor(ObClient *self, ObClientForeachFunc func, void *data)
95 if (self->transient_for) {
96 if (self->transient_for != OB_TRAN_GROUP) {
97 if (!func(self->transient_for, data)) return;
98 client_foreach_ancestor(self->transient_for, func, data);
102 for (it = self->group->members; it; it = it->next)
103 if (it->data != self &&
104 !((ObClient*)it->data)->transient_for) {
105 if (!func(it->data, data)) return;
106 client_foreach_ancestor(it->data, func, data);
113 void client_manage_all()
115 unsigned int i
, j
, nchild
;
118 XWindowAttributes attrib
;
120 XQueryTree(ob_display
, RootWindow(ob_display
, ob_screen
),
121 &w
, &w
, &children
, &nchild
);
123 /* remove all icon windows from the list */
124 for (i
= 0; i
< nchild
; i
++) {
125 if (children
[i
] == None
) continue;
126 wmhints
= XGetWMHints(ob_display
, children
[i
]);
128 if ((wmhints
->flags
& IconWindowHint
) &&
129 (wmhints
->icon_window
!= children
[i
]))
130 for (j
= 0; j
< nchild
; j
++)
131 if (children
[j
] == wmhints
->icon_window
) {
139 for (i
= 0; i
< nchild
; ++i
) {
140 if (children
[i
] == None
)
142 if (XGetWindowAttributes(ob_display
, children
[i
], &attrib
)) {
143 if (attrib
.override_redirect
) continue;
145 if (attrib
.map_state
!= IsUnmapped
)
146 client_manage(children
[i
]);
151 /* stack them as they were on startup!
152 why with stacking_lower? Why, because then windows who aren't in the
153 stacking list are on the top where you can see them instead of buried
155 for (i
= startup_stack_size
; i
> 0; --i
) {
158 w
= startup_stack_order
[i
-1];
159 obw
= g_hash_table_lookup(window_map
, &w
);
161 g_assert(WINDOW_IS_CLIENT(obw
));
162 stacking_lower(CLIENT_AS_WINDOW(obw
));
165 g_free(startup_stack_order
);
166 startup_stack_order
= NULL
;
167 startup_stack_size
= 0;
169 if (config_focus_new
) {
172 active
= g_hash_table_lookup(window_map
, &startup_active
);
174 g_assert(WINDOW_IS_CLIENT(active
));
175 if (!client_focus(WINDOW_AS_CLIENT(active
)))
176 focus_fallback(OB_FOCUS_FALLBACK_NOFOCUS
);
178 focus_fallback(OB_FOCUS_FALLBACK_NOFOCUS
);
182 void client_manage(Window window
)
186 XWindowAttributes attrib
;
187 XSetWindowAttributes attrib_set
;
189 gboolean activate
= FALSE
;
193 /* check if it has already been unmapped by the time we started mapping
194 the grab does a sync so we don't have to here */
195 if (XCheckTypedWindowEvent(ob_display
, window
, DestroyNotify
, &e
) ||
196 XCheckTypedWindowEvent(ob_display
, window
, UnmapNotify
, &e
)) {
197 XPutBackEvent(ob_display
, &e
);
200 return; /* don't manage it */
203 /* make sure it isn't an override-redirect window */
204 if (!XGetWindowAttributes(ob_display
, window
, &attrib
) ||
205 attrib
.override_redirect
) {
207 return; /* don't manage it */
210 /* is the window a docking app */
211 if ((wmhint
= XGetWMHints(ob_display
, window
))) {
212 if ((wmhint
->flags
& StateHint
) &&
213 wmhint
->initial_state
== WithdrawnState
) {
214 dock_add(window
, wmhint
);
222 ob_debug("Managing window: %lx\n", window
);
224 /* choose the events we want to receive on the CLIENT window */
225 attrib_set
.event_mask
= CLIENT_EVENTMASK
;
226 attrib_set
.do_not_propagate_mask
= CLIENT_NOPROPAGATEMASK
;
227 XChangeWindowAttributes(ob_display
, window
,
228 CWEventMask
|CWDontPropagate
, &attrib_set
);
231 /* create the ObClient struct, and populate it from the hints on the
233 self
= g_new(ObClient
, 1);
234 self
->obwin
.type
= Window_Client
;
235 self
->window
= window
;
237 client_get_all(self
);
238 client_restore_session_state(self
);
240 client_change_state(self
);
242 /* remove the client's border (and adjust re gravity) */
243 client_toggle_border(self
, FALSE
);
245 /* specify that if we exit, the window should not be destroyed and should
246 be reparented back to root automatically */
247 XChangeSaveSet(ob_display
, window
, SetModeInsert
);
249 /* create the decoration frame for the client window */
250 self
->frame
= frame_new();
252 frame_grab_client(self
->frame
, self
);
254 client_apply_startup_state(self
);
258 /* update the focus lists */
259 focus_order_add_new(self
);
261 stacking_add(CLIENT_AS_WINDOW(self
));
263 /* focus the new window? */
264 if (ob_state() != OB_STATE_STARTING
&& config_focus_new
&&
265 /* note the check against Type_Normal/Dialog, not client_normal(self),
266 which would also include other types. in this case we want more
267 strict rules for focus */
268 (self
->type
== OB_CLIENT_TYPE_NORMAL
||
269 self
->type
== OB_CLIENT_TYPE_DIALOG
))
271 if (self
->desktop
!= screen_desktop
) {
272 /* activate the window */
275 gboolean group_foc
= FALSE
;
280 for (it
= self
->group
->members
; it
; it
= it
->next
)
282 if (client_focused(it
->data
))
290 (!self
->transient_for
&& (!self
->group
||
291 !self
->group
->members
->next
))) ||
292 client_search_focus_tree_full(self
) ||
294 !client_normal(focus_client
))
296 /* activate the window */
302 dispatch_client(Event_Client_New
, self
, 0, 0);
304 /* make sure the window is visible */
305 client_move_onscreen(self
, TRUE
);
307 screen_update_areas();
309 client_showhide(self
);
311 /* use client_focus instead of client_activate cuz client_activate does
312 stuff like switch desktops etc and I'm not interested in all that when
313 a window maps since its not based on an action from the user like
314 clicking a window to activate is. so keep the new window out of the way
316 if (activate
) client_focus(self
);
318 /* client_activate does this but we aret using it so we have to do it
320 if (screen_showing_desktop
)
321 screen_show_desktop(FALSE
);
323 /* add to client list/map */
324 client_list
= g_list_append(client_list
, self
);
325 g_hash_table_insert(window_map
, &self
->window
, self
);
327 /* update the list hints */
330 dispatch_client(Event_Client_Mapped
, self
, 0, 0);
332 ob_debug("Managed window 0x%lx (%s)\n", window
, self
->class);
335 void client_unmanage_all()
337 while (client_list
!= NULL
)
338 client_unmanage(client_list
->data
);
341 /* called by client_unmanage() to close any menus referencing this client */
342 void client_close_menus(gpointer key
, gpointer value
, gpointer self
)
344 if (((ObMenu
*)value
)->client
== (ObClient
*)self
)
345 menu_hide((ObMenu
*)value
);
348 void client_unmanage(ObClient
*self
)
353 ob_debug("Unmanaging window: %lx (%s)\n", self
->window
, self
->class);
355 dispatch_client(Event_Client_Destroy
, self
, 0, 0);
356 g_assert(self
!= NULL
);
358 /* remove the window from our save set */
359 XChangeSaveSet(ob_display
, self
->window
, SetModeDelete
);
361 /* we dont want events no more */
362 XSelectInput(ob_display
, self
->window
, NoEventMask
);
364 frame_hide(self
->frame
);
366 client_list
= g_list_remove(client_list
, self
);
367 stacking_remove(self
);
368 g_hash_table_remove(window_map
, &self
->window
);
370 /* update the focus lists */
371 focus_order_remove(self
);
373 /* once the client is out of the list, update the struts to remove it's
375 screen_update_areas();
377 /* tell our parent(s) that we're gone */
378 if (self
->transient_for
== OB_TRAN_GROUP
) { /* transient of group */
381 for (it
= self
->group
->members
; it
; it
= it
->next
)
382 if (it
->data
!= self
)
383 ((ObClient
*)it
->data
)->transients
=
384 g_slist_remove(((ObClient
*)it
->data
)->transients
, self
);
385 } else if (self
->transient_for
) { /* transient of window */
386 self
->transient_for
->transients
=
387 g_slist_remove(self
->transient_for
->transients
, self
);
390 /* tell our transients that we're gone */
391 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
) {
392 if (((ObClient
*)it
->data
)->transient_for
!= OB_TRAN_GROUP
) {
393 ((ObClient
*)it
->data
)->transient_for
= NULL
;
394 client_calc_layer(it
->data
);
398 if (moveresize_client
== self
)
399 moveresize_end(TRUE
);
401 /* close any windows that are attached to this window */
402 g_hash_table_foreach(menu_hash
, client_close_menus
, self
);
405 if (focus_client
== self
) {
408 /* focus the last focused window on the desktop, and ignore enter
409 events from the unmap so it doesnt mess with the focus */
410 while (XCheckTypedEvent(ob_display
, EnterNotify
, &e
));
411 client_unfocus(self
);
414 /* remove from its group */
416 group_remove(self
->group
, self
);
420 /* dispatch the unmapped event */
421 dispatch_client(Event_Client_Unmapped
, self
, 0, 0);
422 g_assert(self
!= NULL
);
424 /* give the client its border back */
425 client_toggle_border(self
, TRUE
);
427 /* reparent the window out of the frame, and free the frame */
428 frame_release_client(self
->frame
, self
);
431 if (ob_state() != OB_STATE_EXITING
) {
432 /* these values should not be persisted across a window
434 PROP_ERASE(self
->window
, net_wm_desktop
);
435 PROP_ERASE(self
->window
, net_wm_state
);
436 PROP_ERASE(self
->window
, wm_state
);
438 /* if we're left in an iconic state, the client wont be mapped. this is
439 bad, since we will no longer be managing the window on restart */
441 XMapWindow(ob_display
, self
->window
);
445 ob_debug("Unmanaged window 0x%lx\n", self
->window
);
447 /* free all data allocated in the client struct */
448 g_slist_free(self
->transients
);
449 for (j
= 0; j
< self
->nicons
; ++j
)
450 g_free(self
->icons
[j
].data
);
451 if (self
->nicons
> 0)
454 g_free(self
->icon_title
);
460 /* update the list hints */
464 static void client_restore_session_state(ObClient
*self
)
468 s
= session_state_find(self
);
471 RECT_SET(self
->area
, s
->x
, s
->y
, s
->w
, s
->h
);
472 self
->positioned
= TRUE
;
473 XResizeWindow(ob_display
, self
->window
, s
->w
, s
->h
);
475 self
->desktop
= s
->desktop
== DESKTOP_ALL
? s
->desktop
:
476 MIN(screen_num_desktops
- 1, s
->desktop
);
477 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, self
->desktop
);
479 self
->shaded
= s
->shaded
;
480 self
->iconic
= s
->iconic
;
481 self
->skip_pager
= s
->skip_pager
;
482 self
->skip_taskbar
= s
->skip_taskbar
;
483 self
->fullscreen
= s
->fullscreen
;
484 self
->above
= s
->above
;
485 self
->below
= s
->below
;
486 self
->max_horz
= s
->max_horz
;
487 self
->max_vert
= s
->max_vert
;
489 session_state_free(s
);
492 void client_move_onscreen(ObClient
*self
, gboolean rude
)
494 int x
= self
->area
.x
;
495 int y
= self
->area
.y
;
496 if (client_find_onscreen(self
, &x
, &y
,
497 self
->area
.width
, self
->area
.height
, rude
)) {
498 client_configure(self
, OB_CORNER_TOPLEFT
, x
, y
,
499 self
->area
.width
, self
->area
.height
,
504 gboolean
client_find_onscreen(ObClient
*self
, int *x
, int *y
, int w
, int h
,
508 int ox
= *x
, oy
= *y
;
510 frame_client_gravity(self
->frame
, x
, y
); /* get where the frame
513 /* XXX watch for xinerama dead areas */
515 a
= screen_area(self
->desktop
);
516 if (!self
->strut
.right
&& *x
>= a
->x
+ a
->width
- 1)
517 *x
= a
->x
+ a
->width
- self
->frame
->area
.width
;
518 if (!self
->strut
.bottom
&& *y
>= a
->y
+ a
->height
- 1)
519 *y
= a
->y
+ a
->height
- self
->frame
->area
.height
;
520 if (!self
->strut
.left
&& *x
+ self
->frame
->area
.width
- 1 < a
->x
)
522 if (!self
->strut
.top
&& *y
+ self
->frame
->area
.height
- 1 < a
->y
)
526 /* this is my MOZILLA BITCHSLAP. oh ya it fucking feels good.
527 Java can suck it too. */
529 /* dont let windows map/move into the strut unless they
530 are bigger than the available area */
532 if (!self
->strut
.left
&& *x
< a
->x
) *x
= a
->x
;
533 if (!self
->strut
.right
&& *x
+ w
> a
->x
+ a
->width
)
534 *x
= a
->x
+ a
->width
- w
;
536 if (h
<= a
->height
) {
537 if (!self
->strut
.top
&& *y
< a
->y
) *y
= a
->y
;
538 if (!self
->strut
.bottom
&& *y
+ h
> a
->y
+ a
->height
)
539 *y
= a
->y
+ a
->height
- h
;
543 frame_frame_gravity(self
->frame
, x
, y
); /* get where the client
546 return ox
!= *x
|| oy
!= *y
;
549 static void client_toggle_border(ObClient
*self
, gboolean show
)
551 /* adjust our idea of where the client is, based on its border. When the
552 border is removed, the client should now be considered to be in a
554 when re-adding the border to the client, the same operation needs to be
556 int oldx
= self
->area
.x
, oldy
= self
->area
.y
;
557 int x
= oldx
, y
= oldy
;
558 switch(self
->gravity
) {
560 case NorthWestGravity
:
562 case SouthWestGravity
:
564 case NorthEastGravity
:
566 case SouthEastGravity
:
567 if (show
) x
-= self
->border_width
* 2;
568 else x
+= self
->border_width
* 2;
575 if (show
) x
-= self
->border_width
;
576 else x
+= self
->border_width
;
579 switch(self
->gravity
) {
581 case NorthWestGravity
:
583 case NorthEastGravity
:
585 case SouthWestGravity
:
587 case SouthEastGravity
:
588 if (show
) y
-= self
->border_width
* 2;
589 else y
+= self
->border_width
* 2;
596 if (show
) y
-= self
->border_width
;
597 else y
+= self
->border_width
;
604 XSetWindowBorderWidth(ob_display
, self
->window
, self
->border_width
);
606 /* move the client so it is back it the right spot _with_ its
608 if (x
!= oldx
|| y
!= oldy
)
609 XMoveWindow(ob_display
, self
->window
, x
, y
);
611 XSetWindowBorderWidth(ob_display
, self
->window
, 0);
615 static void client_get_all(ObClient
*self
)
617 /* update EVERYTHING!! */
619 self
->ignore_unmaps
= 0;
623 self
->title
= self
->icon_title
= NULL
;
624 self
->title_count
= 1;
625 self
->name
= self
->class = self
->role
= NULL
;
626 self
->wmstate
= NormalState
;
627 self
->transient
= FALSE
;
628 self
->transients
= NULL
;
629 self
->transient_for
= NULL
;
631 self
->urgent
= FALSE
;
632 self
->positioned
= FALSE
;
633 self
->decorate
= TRUE
;
637 client_get_area(self
);
638 client_update_transient_for(self
);
639 client_update_wmhints(self
);
640 client_get_desktop(self
);
641 client_get_state(self
);
642 client_get_shaped(self
);
644 client_get_mwm_hints(self
);
645 client_get_type(self
);/* this can change the mwmhints for special cases */
647 client_update_protocols(self
);
649 client_get_gravity(self
); /* get the attribute gravity */
650 client_update_normal_hints(self
); /* this may override the attribute
653 /* got the type, the mwmhints, the protocols, and the normal hints
654 (min/max sizes), so we're ready to set up the decorations/functions */
655 client_setup_decor_and_functions(self
);
657 client_update_title(self
);
658 client_update_class(self
);
659 client_update_strut(self
);
660 client_update_icons(self
);
663 static void client_get_area(ObClient
*self
)
665 XWindowAttributes wattrib
;
668 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
669 g_assert(ret
!= BadWindow
);
671 RECT_SET(self
->area
, wattrib
.x
, wattrib
.y
, wattrib
.width
, wattrib
.height
);
672 self
->border_width
= wattrib
.border_width
;
675 static void client_get_desktop(ObClient
*self
)
677 guint32 d
= screen_num_desktops
; /* an always-invalid value */
679 if (PROP_GET32(self
->window
, net_wm_desktop
, cardinal
, &d
)) {
680 if (d
>= screen_num_desktops
&& d
!= DESKTOP_ALL
)
681 self
->desktop
= screen_num_desktops
- 1;
685 gboolean trdesk
= FALSE
;
687 if (self
->transient_for
) {
688 if (self
->transient_for
!= OB_TRAN_GROUP
) {
689 self
->desktop
= self
->transient_for
->desktop
;
694 for (it
= self
->group
->members
; it
; it
= it
->next
)
695 if (it
->data
!= self
&&
696 !((ObClient
*)it
->data
)->transient_for
) {
697 self
->desktop
= ((ObClient
*)it
->data
)->desktop
;
704 /* defaults to the current desktop */
705 self
->desktop
= screen_desktop
;
707 if (self
->desktop
!= d
) {
708 /* set the desktop hint, to make sure that it always exists */
709 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, self
->desktop
);
713 static void client_get_state(ObClient
*self
)
718 self
->modal
= self
->shaded
= self
->max_horz
= self
->max_vert
=
719 self
->fullscreen
= self
->above
= self
->below
= self
->iconic
=
720 self
->skip_taskbar
= self
->skip_pager
= FALSE
;
722 if (PROP_GETA32(self
->window
, net_wm_state
, atom
, &state
, &num
)) {
724 for (i
= 0; i
< num
; ++i
) {
725 if (state
[i
] == prop_atoms
.net_wm_state_modal
)
727 else if (state
[i
] == prop_atoms
.net_wm_state_shaded
)
729 else if (state
[i
] == prop_atoms
.net_wm_state_hidden
)
731 else if (state
[i
] == prop_atoms
.net_wm_state_skip_taskbar
)
732 self
->skip_taskbar
= TRUE
;
733 else if (state
[i
] == prop_atoms
.net_wm_state_skip_pager
)
734 self
->skip_pager
= TRUE
;
735 else if (state
[i
] == prop_atoms
.net_wm_state_fullscreen
)
736 self
->fullscreen
= TRUE
;
737 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_vert
)
738 self
->max_vert
= TRUE
;
739 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_horz
)
740 self
->max_horz
= TRUE
;
741 else if (state
[i
] == prop_atoms
.net_wm_state_above
)
743 else if (state
[i
] == prop_atoms
.net_wm_state_below
)
751 static void client_get_shaped(ObClient
*self
)
753 self
->shaped
= FALSE
;
755 if (extensions_shape
) {
760 XShapeSelectInput(ob_display
, self
->window
, ShapeNotifyMask
);
762 XShapeQueryExtents(ob_display
, self
->window
, &s
, &foo
,
763 &foo
, &ufoo
, &ufoo
, &foo
, &foo
, &foo
, &ufoo
,
765 self
->shaped
= (s
!= 0);
770 void client_update_transient_for(ObClient
*self
)
773 ObClient
*target
= NULL
;
775 if (XGetTransientForHint(ob_display
, self
->window
, &t
)) {
776 self
->transient
= TRUE
;
777 if (t
!= self
->window
) { /* cant be transient to itself! */
778 target
= g_hash_table_lookup(window_map
, &t
);
779 /* if this happens then we need to check for it*/
780 g_assert(target
!= self
);
781 g_assert(!target
|| WINDOW_IS_CLIENT(target
));
783 if (!target
&& self
->group
) {
784 /* not transient to a client, see if it is transient for a
786 if (t
== self
->group
->leader
||
788 t
== RootWindow(ob_display
, ob_screen
)) {
789 /* window is a transient for its group! */
790 target
= OB_TRAN_GROUP
;
795 self
->transient
= FALSE
;
797 /* if anything has changed... */
798 if (target
!= self
->transient_for
) {
799 if (self
->transient_for
== OB_TRAN_GROUP
) { /* transient of group */
802 /* remove from old parents */
803 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
804 ObClient
*c
= it
->data
;
805 if (c
!= self
&& !c
->transient_for
)
806 c
->transients
= g_slist_remove(c
->transients
, self
);
808 } else if (self
->transient_for
!= NULL
) { /* transient of window */
809 /* remove from old parent */
810 self
->transient_for
->transients
=
811 g_slist_remove(self
->transient_for
->transients
, self
);
813 self
->transient_for
= target
;
814 if (self
->transient_for
== OB_TRAN_GROUP
) { /* transient of group */
817 /* add to new parents */
818 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
819 ObClient
*c
= it
->data
;
820 if (c
!= self
&& !c
->transient_for
)
821 c
->transients
= g_slist_append(c
->transients
, self
);
824 /* remove all transients which are in the group, that causes
825 circlular pointer hell of doom */
826 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
828 for (sit
= self
->transients
; sit
; sit
= next
) {
829 next
= g_slist_next(sit
);
830 if (sit
->data
== it
->data
)
832 g_slist_delete_link(self
->transients
, sit
);
835 } else if (self
->transient_for
!= NULL
) { /* transient of window */
836 /* add to new parent */
837 self
->transient_for
->transients
=
838 g_slist_append(self
->transient_for
->transients
, self
);
843 static void client_get_mwm_hints(ObClient
*self
)
848 self
->mwmhints
.flags
= 0; /* default to none */
850 if (PROP_GETA32(self
->window
, motif_wm_hints
, motif_wm_hints
,
852 if (num
>= OB_MWM_ELEMENTS
) {
853 self
->mwmhints
.flags
= hints
[0];
854 self
->mwmhints
.functions
= hints
[1];
855 self
->mwmhints
.decorations
= hints
[2];
861 void client_get_type(ObClient
*self
)
868 if (PROP_GETA32(self
->window
, net_wm_window_type
, atom
, &val
, &num
)) {
869 /* use the first value that we know about in the array */
870 for (i
= 0; i
< num
; ++i
) {
871 if (val
[i
] == prop_atoms
.net_wm_window_type_desktop
)
872 self
->type
= OB_CLIENT_TYPE_DESKTOP
;
873 else if (val
[i
] == prop_atoms
.net_wm_window_type_dock
)
874 self
->type
= OB_CLIENT_TYPE_DOCK
;
875 else if (val
[i
] == prop_atoms
.net_wm_window_type_toolbar
)
876 self
->type
= OB_CLIENT_TYPE_TOOLBAR
;
877 else if (val
[i
] == prop_atoms
.net_wm_window_type_menu
)
878 self
->type
= OB_CLIENT_TYPE_MENU
;
879 else if (val
[i
] == prop_atoms
.net_wm_window_type_utility
)
880 self
->type
= OB_CLIENT_TYPE_UTILITY
;
881 else if (val
[i
] == prop_atoms
.net_wm_window_type_splash
)
882 self
->type
= OB_CLIENT_TYPE_SPLASH
;
883 else if (val
[i
] == prop_atoms
.net_wm_window_type_dialog
)
884 self
->type
= OB_CLIENT_TYPE_DIALOG
;
885 else if (val
[i
] == prop_atoms
.net_wm_window_type_normal
)
886 self
->type
= OB_CLIENT_TYPE_NORMAL
;
887 else if (val
[i
] == prop_atoms
.kde_net_wm_window_type_override
) {
888 /* prevent this window from getting any decor or
890 self
->mwmhints
.flags
&= (OB_MWM_FLAG_FUNCTIONS
|
891 OB_MWM_FLAG_DECORATIONS
);
892 self
->mwmhints
.decorations
= 0;
893 self
->mwmhints
.functions
= 0;
895 if (self
->type
!= (ObClientType
) -1)
896 break; /* grab the first legit type */
901 if (self
->type
== (ObClientType
) -1) {
902 /*the window type hint was not set, which means we either classify
903 ourself as a normal window or a dialog, depending on if we are a
906 self
->type
= OB_CLIENT_TYPE_DIALOG
;
908 self
->type
= OB_CLIENT_TYPE_NORMAL
;
912 void client_update_protocols(ObClient
*self
)
917 self
->focus_notify
= FALSE
;
918 self
->delete_window
= FALSE
;
920 if (PROP_GETA32(self
->window
, wm_protocols
, atom
, &proto
, &num_return
)) {
921 for (i
= 0; i
< num_return
; ++i
) {
922 if (proto
[i
] == prop_atoms
.wm_delete_window
) {
923 /* this means we can request the window to close */
924 self
->delete_window
= TRUE
;
925 } else if (proto
[i
] == prop_atoms
.wm_take_focus
)
926 /* if this protocol is requested, then the window will be
927 notified whenever we want it to receive focus */
928 self
->focus_notify
= TRUE
;
934 static void client_get_gravity(ObClient
*self
)
936 XWindowAttributes wattrib
;
939 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
940 g_assert(ret
!= BadWindow
);
941 self
->gravity
= wattrib
.win_gravity
;
944 void client_update_normal_hints(ObClient
*self
)
948 int oldgravity
= self
->gravity
;
951 self
->min_ratio
= 0.0f
;
952 self
->max_ratio
= 0.0f
;
953 SIZE_SET(self
->size_inc
, 1, 1);
954 SIZE_SET(self
->base_size
, 0, 0);
955 SIZE_SET(self
->min_size
, 0, 0);
956 SIZE_SET(self
->max_size
, G_MAXINT
, G_MAXINT
);
958 /* get the hints from the window */
959 if (XGetWMNormalHints(ob_display
, self
->window
, &size
, &ret
)) {
960 self
->positioned
= !!(size
.flags
& (PPosition
|USPosition
));
962 if (size
.flags
& PWinGravity
) {
963 self
->gravity
= size
.win_gravity
;
965 /* if the client has a frame, i.e. has already been mapped and
966 is changing its gravity */
967 if (self
->frame
&& self
->gravity
!= oldgravity
) {
968 /* move our idea of the client's position based on its new
970 self
->area
.x
= self
->frame
->area
.x
;
971 self
->area
.y
= self
->frame
->area
.y
;
972 frame_frame_gravity(self
->frame
, &self
->area
.x
, &self
->area
.y
);
976 if (size
.flags
& PAspect
) {
977 if (size
.min_aspect
.y
)
978 self
->min_ratio
= (float)size
.min_aspect
.x
/ size
.min_aspect
.y
;
979 if (size
.max_aspect
.y
)
980 self
->max_ratio
= (float)size
.max_aspect
.x
/ size
.max_aspect
.y
;
983 if (size
.flags
& PMinSize
)
984 SIZE_SET(self
->min_size
, size
.min_width
, size
.min_height
);
986 if (size
.flags
& PMaxSize
)
987 SIZE_SET(self
->max_size
, size
.max_width
, size
.max_height
);
989 if (size
.flags
& PBaseSize
)
990 SIZE_SET(self
->base_size
, size
.base_width
, size
.base_height
);
992 if (size
.flags
& PResizeInc
)
993 SIZE_SET(self
->size_inc
, size
.width_inc
, size
.height_inc
);
997 void client_setup_decor_and_functions(ObClient
*self
)
999 /* start with everything (cept fullscreen) */
1000 self
->decorations
= (OB_FRAME_DECOR_TITLEBAR
|
1001 OB_FRAME_DECOR_HANDLE
|
1002 OB_FRAME_DECOR_GRIPS
|
1003 OB_FRAME_DECOR_BORDER
|
1004 OB_FRAME_DECOR_ICON
|
1005 OB_FRAME_DECOR_ALLDESKTOPS
|
1006 OB_FRAME_DECOR_ICONIFY
|
1007 OB_FRAME_DECOR_MAXIMIZE
|
1008 OB_FRAME_DECOR_SHADE
);
1009 self
->functions
= (OB_CLIENT_FUNC_RESIZE
|
1010 OB_CLIENT_FUNC_MOVE
|
1011 OB_CLIENT_FUNC_ICONIFY
|
1012 OB_CLIENT_FUNC_MAXIMIZE
|
1013 OB_CLIENT_FUNC_SHADE
);
1014 if (self
->delete_window
) {
1015 self
->functions
|= OB_CLIENT_FUNC_CLOSE
;
1016 self
->decorations
|= OB_FRAME_DECOR_CLOSE
;
1019 if (!(self
->min_size
.width
< self
->max_size
.width
||
1020 self
->min_size
.height
< self
->max_size
.height
))
1021 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
1023 switch (self
->type
) {
1024 case OB_CLIENT_TYPE_NORMAL
:
1025 /* normal windows retain all of the possible decorations and
1026 functionality, and are the only windows that you can fullscreen */
1027 self
->functions
|= OB_CLIENT_FUNC_FULLSCREEN
;
1030 case OB_CLIENT_TYPE_DIALOG
:
1031 case OB_CLIENT_TYPE_UTILITY
:
1032 /* these windows cannot be maximized */
1033 self
->functions
&= ~OB_CLIENT_FUNC_MAXIMIZE
;
1036 case OB_CLIENT_TYPE_MENU
:
1037 case OB_CLIENT_TYPE_TOOLBAR
:
1038 /* these windows get less functionality */
1039 self
->functions
&= ~(OB_CLIENT_FUNC_ICONIFY
| OB_CLIENT_FUNC_RESIZE
);
1042 case OB_CLIENT_TYPE_DESKTOP
:
1043 case OB_CLIENT_TYPE_DOCK
:
1044 case OB_CLIENT_TYPE_SPLASH
:
1045 /* none of these windows are manipulated by the window manager */
1046 self
->decorations
= 0;
1047 self
->functions
= 0;
1051 /* Mwm Hints are applied subtractively to what has already been chosen for
1052 decor and functionality */
1053 if (self
->mwmhints
.flags
& OB_MWM_FLAG_DECORATIONS
) {
1054 if (! (self
->mwmhints
.decorations
& OB_MWM_DECOR_ALL
)) {
1055 if (! ((self
->mwmhints
.decorations
& OB_MWM_DECOR_HANDLE
) ||
1056 (self
->mwmhints
.decorations
& OB_MWM_DECOR_TITLE
)))
1057 /* if the mwm hints request no handle or title, then all
1058 decorations are disabled */
1059 self
->decorations
= 0;
1063 if (self
->mwmhints
.flags
& OB_MWM_FLAG_FUNCTIONS
) {
1064 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_ALL
)) {
1065 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_RESIZE
))
1066 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
1067 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_MOVE
))
1068 self
->functions
&= ~OB_CLIENT_FUNC_MOVE
;
1069 /* dont let mwm hints kill any buttons
1070 if (! (self->mwmhints.functions & OB_MWM_FUNC_ICONIFY))
1071 self->functions &= ~OB_CLIENT_FUNC_ICONIFY;
1072 if (! (self->mwmhints.functions & OB_MWM_FUNC_MAXIMIZE))
1073 self->functions &= ~OB_CLIENT_FUNC_MAXIMIZE;
1075 /* dont let mwm hints kill the close button
1076 if (! (self->mwmhints.functions & MwmFunc_Close))
1077 self->functions &= ~OB_CLIENT_FUNC_CLOSE; */
1081 if (!(self
->functions
& OB_CLIENT_FUNC_SHADE
))
1082 self
->decorations
&= ~OB_FRAME_DECOR_SHADE
;
1083 if (!(self
->functions
& OB_CLIENT_FUNC_ICONIFY
))
1084 self
->decorations
&= ~OB_FRAME_DECOR_ICONIFY
;
1085 if (!(self
->functions
& OB_CLIENT_FUNC_RESIZE
))
1086 self
->decorations
&= ~OB_FRAME_DECOR_GRIPS
;
1088 /* can't maximize without moving/resizing */
1089 if (!((self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) &&
1090 (self
->functions
& OB_CLIENT_FUNC_MOVE
) &&
1091 (self
->functions
& OB_CLIENT_FUNC_RESIZE
))) {
1092 self
->functions
&= ~OB_CLIENT_FUNC_MAXIMIZE
;
1093 self
->decorations
&= ~OB_FRAME_DECOR_MAXIMIZE
;
1096 /* finally, the user can have requested no decorations, which overrides
1098 if (!self
->decorate
)
1099 self
->decorations
= 0;
1101 /* if we don't have a titlebar, then we cannot shade! */
1102 if (!(self
->decorations
& OB_FRAME_DECOR_TITLEBAR
))
1103 self
->functions
&= ~OB_CLIENT_FUNC_SHADE
;
1105 /* now we need to check against rules for the client's current state */
1106 if (self
->fullscreen
) {
1107 self
->functions
&= (OB_CLIENT_FUNC_CLOSE
|
1108 OB_CLIENT_FUNC_FULLSCREEN
|
1109 OB_CLIENT_FUNC_ICONIFY
);
1110 self
->decorations
= 0;
1113 client_change_allowed_actions(self
);
1116 /* this makes sure that these windows appear on all desktops */
1117 if (self
->type
== OB_CLIENT_TYPE_DESKTOP
&&
1118 self
->desktop
!= DESKTOP_ALL
)
1119 client_set_desktop(self
, DESKTOP_ALL
, FALSE
);
1121 /* adjust the client's decorations, etc. */
1122 client_reconfigure(self
);
1124 /* this makes sure that these windows appear on all desktops */
1125 if (self
->type
== OB_CLIENT_TYPE_DESKTOP
&&
1126 self
->desktop
!= DESKTOP_ALL
)
1128 self
->desktop
= DESKTOP_ALL
;
1133 static void client_change_allowed_actions(ObClient
*self
)
1138 /* desktop windows are kept on all desktops */
1139 if (self
->type
!= OB_CLIENT_TYPE_DESKTOP
)
1140 actions
[num
++] = prop_atoms
.net_wm_action_change_desktop
;
1142 if (self
->functions
& OB_CLIENT_FUNC_SHADE
)
1143 actions
[num
++] = prop_atoms
.net_wm_action_shade
;
1144 if (self
->functions
& OB_CLIENT_FUNC_CLOSE
)
1145 actions
[num
++] = prop_atoms
.net_wm_action_close
;
1146 if (self
->functions
& OB_CLIENT_FUNC_MOVE
)
1147 actions
[num
++] = prop_atoms
.net_wm_action_move
;
1148 if (self
->functions
& OB_CLIENT_FUNC_ICONIFY
)
1149 actions
[num
++] = prop_atoms
.net_wm_action_minimize
;
1150 if (self
->functions
& OB_CLIENT_FUNC_RESIZE
)
1151 actions
[num
++] = prop_atoms
.net_wm_action_resize
;
1152 if (self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
)
1153 actions
[num
++] = prop_atoms
.net_wm_action_fullscreen
;
1154 if (self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) {
1155 actions
[num
++] = prop_atoms
.net_wm_action_maximize_horz
;
1156 actions
[num
++] = prop_atoms
.net_wm_action_maximize_vert
;
1159 PROP_SETA32(self
->window
, net_wm_allowed_actions
, atom
, actions
, num
);
1161 /* make sure the window isn't breaking any rules now */
1163 if (!(self
->functions
& OB_CLIENT_FUNC_SHADE
) && self
->shaded
) {
1164 if (self
->frame
) client_shade(self
, FALSE
);
1165 else self
->shaded
= FALSE
;
1167 if (!(self
->functions
& OB_CLIENT_FUNC_ICONIFY
) && self
->iconic
) {
1168 if (self
->frame
) client_iconify(self
, FALSE
, TRUE
);
1169 else self
->iconic
= FALSE
;
1171 if (!(self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
) && self
->fullscreen
) {
1172 if (self
->frame
) client_fullscreen(self
, FALSE
, TRUE
);
1173 else self
->fullscreen
= FALSE
;
1175 if (!(self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) && (self
->max_horz
||
1177 if (self
->frame
) client_maximize(self
, FALSE
, 0, TRUE
);
1178 else self
->max_vert
= self
->max_horz
= FALSE
;
1182 void client_reconfigure(ObClient
*self
)
1184 /* by making this pass FALSE for user, we avoid the emacs event storm where
1185 every configurenotify causes an update in its normal hints, i think this
1186 is generally what we want anyways... */
1187 client_configure(self
, OB_CORNER_TOPLEFT
, self
->area
.x
, self
->area
.y
,
1188 self
->area
.width
, self
->area
.height
, FALSE
, TRUE
);
1191 void client_update_wmhints(ObClient
*self
)
1194 gboolean ur
= FALSE
;
1197 /* assume a window takes input if it doesnt specify */
1198 self
->can_focus
= TRUE
;
1200 if ((hints
= XGetWMHints(ob_display
, self
->window
)) != NULL
) {
1201 if (hints
->flags
& InputHint
)
1202 self
->can_focus
= hints
->input
;
1204 /* only do this when first managing the window *AND* when we aren't
1206 if (ob_state() != OB_STATE_STARTING
&& self
->frame
== NULL
)
1207 if (hints
->flags
& StateHint
)
1208 self
->iconic
= hints
->initial_state
== IconicState
;
1210 if (hints
->flags
& XUrgencyHint
)
1213 if (!(hints
->flags
& WindowGroupHint
))
1214 hints
->window_group
= None
;
1216 /* did the group state change? */
1217 if (hints
->window_group
!=
1218 (self
->group
? self
->group
->leader
: None
)) {
1219 /* remove from the old group if there was one */
1220 if (self
->group
!= NULL
) {
1221 /* remove transients of the group */
1222 for (it
= self
->group
->members
; it
; it
= it
->next
)
1223 self
->transients
= g_slist_remove(self
->transients
,
1225 group_remove(self
->group
, self
);
1228 if (hints
->window_group
!= None
) {
1229 self
->group
= group_add(hints
->window_group
, self
);
1231 /* i can only have transients from the group if i am not
1233 if (!self
->transient_for
) {
1234 /* add other transients of the group that are already
1236 for (it
= self
->group
->members
; it
; it
= it
->next
) {
1237 ObClient
*c
= it
->data
;
1238 if (c
!= self
&& c
->transient_for
== OB_TRAN_GROUP
)
1240 g_slist_append(self
->transients
, c
);
1245 /* because the self->transient flag wont change from this call,
1246 we don't need to update the window's type and such, only its
1247 transient_for, and the transients lists of other windows in
1248 the group may be affected */
1249 client_update_transient_for(self
);
1252 /* the WM_HINTS can contain an icon */
1253 client_update_icons(self
);
1258 if (ur
!= self
->urgent
) {
1260 ob_debug("Urgent Hint for 0x%lx: %s\n", self
->window
,
1262 /* fire the urgent callback if we're mapped, otherwise, wait until
1263 after we're mapped */
1265 dispatch_client(Event_Client_Urgent
, self
, self
->urgent
, 0);
1269 void client_update_title(ObClient
*self
)
1275 gboolean read_title
;
1277 g_free(self
->title
);
1280 if (!PROP_GETS(self
->window
, net_wm_name
, utf8
, &data
))
1281 /* try old x stuff */
1282 if (!PROP_GETS(self
->window
, wm_name
, locale
, &data
))
1283 data
= g_strdup("Unnamed Window");
1285 /* look for duplicates and append a number */
1287 for (it
= client_list
; it
; it
= it
->next
)
1288 if (it
->data
!= self
) {
1289 ObClient
*c
= it
->data
;
1290 if (0 == strncmp(c
->title
, data
, strlen(data
)))
1291 nums
|= 1 << c
->title_count
;
1293 /* find first free number */
1294 for (i
= 1; i
<= 32; ++i
)
1295 if (!(nums
& (1 << i
))) {
1296 if (self
->title_count
== 1 || i
== 1)
1297 self
->title_count
= i
;
1300 /* dont display the number for the first window */
1301 if (self
->title_count
> 1) {
1302 char *vdata
, *ndata
;
1303 ndata
= g_strdup_printf(" - [%u]", self
->title_count
);
1304 vdata
= g_strconcat(data
, ndata
, NULL
);
1310 PROP_SETS(self
->window
, net_wm_visible_name
, data
);
1315 frame_adjust_title(self
->frame
);
1317 /* update the icon title */
1319 g_free(self
->icon_title
);
1323 if (!PROP_GETS(self
->window
, net_wm_icon_name
, utf8
, &data
))
1324 /* try old x stuff */
1325 if (!PROP_GETS(self
->window
, wm_icon_name
, locale
, &data
)) {
1326 data
= g_strdup(self
->title
);
1330 /* append the title count, dont display the number for the first window */
1331 if (read_title
&& self
->title_count
> 1) {
1332 char *vdata
, *ndata
;
1333 ndata
= g_strdup_printf(" - [%u]", self
->title_count
);
1334 vdata
= g_strconcat(data
, ndata
, NULL
);
1340 PROP_SETS(self
->window
, net_wm_visible_icon_name
, data
);
1342 self
->icon_title
= data
;
1345 void client_update_class(ObClient
*self
)
1350 if (self
->name
) g_free(self
->name
);
1351 if (self
->class) g_free(self
->class);
1352 if (self
->role
) g_free(self
->role
);
1354 self
->name
= self
->class = self
->role
= NULL
;
1356 if (PROP_GETSS(self
->window
, wm_class
, locale
, &data
)) {
1358 self
->name
= g_strdup(data
[0]);
1360 self
->class = g_strdup(data
[1]);
1365 if (PROP_GETS(self
->window
, wm_window_role
, locale
, &s
))
1366 self
->role
= g_strdup(s
);
1368 if (self
->name
== NULL
) self
->name
= g_strdup("");
1369 if (self
->class == NULL
) self
->class = g_strdup("");
1370 if (self
->role
== NULL
) self
->role
= g_strdup("");
1373 void client_update_strut(ObClient
*self
)
1377 gboolean got
= FALSE
;
1379 if (PROP_GETA32(self
->window
, net_wm_strut_partial
, cardinal
,
1383 STRUT_PARTIAL_SET(self
->strut
,
1384 data
[0], data
[2], data
[1], data
[3],
1385 data
[4], data
[5], data
[8], data
[9],
1386 data
[6], data
[7], data
[10], data
[11]);
1392 PROP_GETA32(self
->window
, net_wm_strut
, cardinal
, &data
, &num
)) {
1395 STRUT_PARTIAL_SET(self
->strut
,
1396 data
[0], data
[2], data
[1], data
[3],
1397 0, 0, 0, 0, 0, 0, 0, 0);
1403 STRUT_PARTIAL_SET(self
->strut
, 0, 0, 0, 0,
1404 0, 0, 0, 0, 0, 0, 0, 0);
1406 /* updating here is pointless while we're being mapped cuz we're not in
1407 the client list yet */
1409 screen_update_areas();
1412 void client_update_icons(ObClient
*self
)
1418 for (i
= 0; i
< self
->nicons
; ++i
)
1419 g_free(self
->icons
[i
].data
);
1420 if (self
->nicons
> 0)
1421 g_free(self
->icons
);
1424 if (PROP_GETA32(self
->window
, net_wm_icon
, cardinal
, &data
, &num
)) {
1425 /* figure out how many valid icons are in here */
1427 while (num
- i
> 2) {
1431 if (i
> num
|| w
*h
== 0) break;
1435 self
->icons
= g_new(ObClientIcon
, self
->nicons
);
1437 /* store the icons */
1439 for (j
= 0; j
< self
->nicons
; ++j
) {
1442 w
= self
->icons
[j
].width
= data
[i
++];
1443 h
= self
->icons
[j
].height
= data
[i
++];
1445 if (w
*h
== 0) continue;
1447 self
->icons
[j
].data
= g_new(RrPixel32
, w
* h
);
1448 for (x
= 0, y
= 0, t
= 0; t
< w
* h
; ++t
, ++x
, ++i
) {
1453 self
->icons
[j
].data
[t
] =
1454 (((data
[i
] >> 24) & 0xff) << RrDefaultAlphaOffset
) +
1455 (((data
[i
] >> 16) & 0xff) << RrDefaultRedOffset
) +
1456 (((data
[i
] >> 8) & 0xff) << RrDefaultGreenOffset
) +
1457 (((data
[i
] >> 0) & 0xff) << RrDefaultBlueOffset
);
1463 } else if (PROP_GETA32(self
->window
, kwm_win_icon
,
1464 kwm_win_icon
, &data
, &num
)) {
1467 self
->icons
= g_new(ObClientIcon
, self
->nicons
);
1468 xerror_set_ignore(TRUE
);
1469 if (!RrPixmapToRGBA(ob_rr_inst
,
1471 &self
->icons
[self
->nicons
-1].width
,
1472 &self
->icons
[self
->nicons
-1].height
,
1473 &self
->icons
[self
->nicons
-1].data
)) {
1474 g_free(&self
->icons
[self
->nicons
-1]);
1477 xerror_set_ignore(FALSE
);
1483 if ((hints
= XGetWMHints(ob_display
, self
->window
))) {
1484 if (hints
->flags
& IconPixmapHint
) {
1486 self
->icons
= g_new(ObClientIcon
, self
->nicons
);
1487 xerror_set_ignore(TRUE
);
1488 if (!RrPixmapToRGBA(ob_rr_inst
,
1490 (hints
->flags
& IconMaskHint
?
1491 hints
->icon_mask
: None
),
1492 &self
->icons
[self
->nicons
-1].width
,
1493 &self
->icons
[self
->nicons
-1].height
,
1494 &self
->icons
[self
->nicons
-1].data
)){
1495 g_free(&self
->icons
[self
->nicons
-1]);
1498 xerror_set_ignore(FALSE
);
1505 frame_adjust_icon(self
->frame
);
1508 static void client_change_state(ObClient
*self
)
1511 guint32 netstate
[10];
1514 state
[0] = self
->wmstate
;
1516 PROP_SETA32(self
->window
, wm_state
, wm_state
, state
, 2);
1520 netstate
[num
++] = prop_atoms
.net_wm_state_modal
;
1522 netstate
[num
++] = prop_atoms
.net_wm_state_shaded
;
1524 netstate
[num
++] = prop_atoms
.net_wm_state_hidden
;
1525 if (self
->skip_taskbar
)
1526 netstate
[num
++] = prop_atoms
.net_wm_state_skip_taskbar
;
1527 if (self
->skip_pager
)
1528 netstate
[num
++] = prop_atoms
.net_wm_state_skip_pager
;
1529 if (self
->fullscreen
)
1530 netstate
[num
++] = prop_atoms
.net_wm_state_fullscreen
;
1532 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_vert
;
1534 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_horz
;
1536 netstate
[num
++] = prop_atoms
.net_wm_state_above
;
1538 netstate
[num
++] = prop_atoms
.net_wm_state_below
;
1539 PROP_SETA32(self
->window
, net_wm_state
, atom
, netstate
, num
);
1541 client_calc_layer(self
);
1544 frame_adjust_state(self
->frame
);
1547 ObClient
*client_search_focus_tree(ObClient
*self
)
1552 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
) {
1553 if (client_focused(it
->data
)) return it
->data
;
1554 if ((ret
= client_search_focus_tree(it
->data
))) return ret
;
1559 ObClient
*client_search_focus_tree_full(ObClient
*self
)
1561 if (self
->transient_for
) {
1562 if (self
->transient_for
!= OB_TRAN_GROUP
) {
1563 return client_search_focus_tree_full(self
->transient_for
);
1566 gboolean recursed
= FALSE
;
1568 for (it
= self
->group
->members
; it
; it
= it
->next
)
1569 if (!((ObClient
*)it
->data
)->transient_for
) {
1571 if ((c
= client_search_focus_tree_full(it
->data
)))
1580 /* this function checks the whole tree, the client_search_focus_tree~
1581 does not, so we need to check this window */
1582 if (client_focused(self
))
1584 return client_search_focus_tree(self
);
1587 static ObStackingLayer
calc_layer(ObClient
*self
)
1591 if (self
->fullscreen
) l
= OB_STACKING_LAYER_FULLSCREEN
;
1592 else if (self
->type
== OB_CLIENT_TYPE_DESKTOP
)
1593 l
= OB_STACKING_LAYER_DESKTOP
;
1594 else if (self
->type
== OB_CLIENT_TYPE_DOCK
) {
1595 if (!self
->below
) l
= OB_STACKING_LAYER_TOP
;
1596 else l
= OB_STACKING_LAYER_NORMAL
;
1598 else if (self
->above
) l
= OB_STACKING_LAYER_ABOVE
;
1599 else if (self
->below
) l
= OB_STACKING_LAYER_BELOW
;
1600 else l
= OB_STACKING_LAYER_NORMAL
;
1605 static void client_calc_layer_recursive(ObClient
*self
, ObClient
*orig
,
1606 ObStackingLayer l
, gboolean raised
)
1608 ObStackingLayer old
, own
;
1612 own
= calc_layer(self
);
1613 self
->layer
= l
> own
? l
: own
;
1615 for (it
= self
->transients
; it
; it
= it
->next
)
1616 client_calc_layer_recursive(it
->data
, orig
,
1617 l
, raised
? raised
: l
!= old
);
1619 if (!raised
&& l
!= old
)
1620 if (orig
->frame
) { /* only restack if the original window is managed */
1621 /* XXX add_non_intrusive ever? */
1622 stacking_remove(CLIENT_AS_WINDOW(self
));
1623 stacking_add(CLIENT_AS_WINDOW(self
));
1627 void client_calc_layer(ObClient
*self
)
1634 /* transients take on the layer of their parents */
1635 self
= client_search_top_transient(self
);
1637 l
= calc_layer(self
);
1639 client_calc_layer_recursive(self
, orig
, l
, FALSE
);
1642 gboolean
client_should_show(ObClient
*self
)
1644 if (self
->iconic
) return FALSE
;
1645 else if (!(self
->desktop
== screen_desktop
||
1646 self
->desktop
== DESKTOP_ALL
)) return FALSE
;
1647 else if (client_normal(self
) && screen_showing_desktop
) return FALSE
;
1652 static void client_showhide(ObClient
*self
)
1655 if (client_should_show(self
))
1656 frame_show(self
->frame
);
1658 frame_hide(self
->frame
);
1661 gboolean
client_normal(ObClient
*self
) {
1662 return ! (self
->type
== OB_CLIENT_TYPE_DESKTOP
||
1663 self
->type
== OB_CLIENT_TYPE_DOCK
||
1664 self
->type
== OB_CLIENT_TYPE_SPLASH
);
1667 static void client_apply_startup_state(ObClient
*self
)
1669 /* these are in a carefully crafted order.. */
1672 self
->iconic
= FALSE
;
1673 client_iconify(self
, TRUE
, FALSE
);
1675 if (self
->fullscreen
) {
1676 self
->fullscreen
= FALSE
;
1677 client_fullscreen(self
, TRUE
, FALSE
);
1680 self
->shaded
= FALSE
;
1681 client_shade(self
, TRUE
);
1684 dispatch_client(Event_Client_Urgent
, self
, self
->urgent
, 0);
1686 if (self
->max_vert
&& self
->max_horz
) {
1687 self
->max_vert
= self
->max_horz
= FALSE
;
1688 client_maximize(self
, TRUE
, 0, FALSE
);
1689 } else if (self
->max_vert
) {
1690 self
->max_vert
= FALSE
;
1691 client_maximize(self
, TRUE
, 2, FALSE
);
1692 } else if (self
->max_horz
) {
1693 self
->max_horz
= FALSE
;
1694 client_maximize(self
, TRUE
, 1, FALSE
);
1697 /* nothing to do for the other states:
1706 void client_configure_full(ObClient
*self
, ObCorner anchor
,
1707 int x
, int y
, int w
, int h
,
1708 gboolean user
, gboolean final
,
1709 gboolean force_reply
)
1711 gboolean moved
= FALSE
, resized
= FALSE
;
1713 /* gets the frame's position */
1714 frame_client_gravity(self
->frame
, &x
, &y
);
1716 /* these positions are frame positions, not client positions */
1718 /* set the size and position if fullscreen */
1719 if (self
->fullscreen
) {
1722 XF86VidModeModeLine mode
;
1727 i
= client_monitor(self
);
1728 a
= screen_physical_area_monitor(i
);
1731 if (i
== 0 && /* primary head */
1732 extensions_vidmode
&&
1733 XF86VidModeGetViewPort(ob_display
, ob_screen
, &x
, &y
) &&
1734 /* get the mode last so the mode.privsize isnt freed incorrectly */
1735 XF86VidModeGetModeLine(ob_display
, ob_screen
, &dot
, &mode
)) {
1740 if (mode
.privsize
) XFree(mode
.private);
1750 user
= FALSE
; /* ignore that increment etc shit when in fullscreen */
1754 a
= screen_area_monitor(self
->desktop
, client_monitor(self
));
1756 /* set the size and position if maximized */
1757 if (self
->max_horz
) {
1758 x
= a
->x
- self
->frame
->size
.left
;
1761 if (self
->max_vert
) {
1763 h
= a
->height
- self
->frame
->size
.top
- self
->frame
->size
.bottom
;
1767 /* gets the client's position */
1768 frame_frame_gravity(self
->frame
, &x
, &y
);
1770 /* these override the above states! if you cant move you can't move! */
1772 if (!(self
->functions
& OB_CLIENT_FUNC_MOVE
)) {
1776 if (!(self
->functions
& OB_CLIENT_FUNC_RESIZE
)) {
1777 w
= self
->area
.width
;
1778 h
= self
->area
.height
;
1782 if (!(w
== self
->area
.width
&& h
== self
->area
.height
)) {
1783 int basew
, baseh
, minw
, minh
;
1785 /* base size is substituted with min size if not specified */
1786 if (self
->base_size
.width
|| self
->base_size
.height
) {
1787 basew
= self
->base_size
.width
;
1788 baseh
= self
->base_size
.height
;
1790 basew
= self
->min_size
.width
;
1791 baseh
= self
->min_size
.height
;
1793 /* min size is substituted with base size if not specified */
1794 if (self
->min_size
.width
|| self
->min_size
.height
) {
1795 minw
= self
->min_size
.width
;
1796 minh
= self
->min_size
.height
;
1798 minw
= self
->base_size
.width
;
1799 minh
= self
->base_size
.height
;
1803 /* for interactive resizing. have to move half an increment in each
1806 /* how far we are towards the next size inc */
1807 int mw
= (w
- basew
) % self
->size_inc
.width
;
1808 int mh
= (h
- baseh
) % self
->size_inc
.height
;
1810 int aw
= self
->size_inc
.width
/ 2;
1811 int ah
= self
->size_inc
.height
/ 2;
1812 /* don't let us move into a new size increment */
1813 if (mw
+ aw
>= self
->size_inc
.width
)
1814 aw
= self
->size_inc
.width
- mw
- 1;
1815 if (mh
+ ah
>= self
->size_inc
.height
)
1816 ah
= self
->size_inc
.height
- mh
- 1;
1820 /* if this is a user-requested resize, then check against min/max
1823 /* smaller than min size or bigger than max size? */
1824 if (w
> self
->max_size
.width
) w
= self
->max_size
.width
;
1825 if (w
< minw
) w
= minw
;
1826 if (h
> self
->max_size
.height
) h
= self
->max_size
.height
;
1827 if (h
< minh
) h
= minh
;
1833 /* keep to the increments */
1834 w
/= self
->size_inc
.width
;
1835 h
/= self
->size_inc
.height
;
1837 /* you cannot resize to nothing */
1838 if (basew
+ w
< 1) w
= 1 - basew
;
1839 if (baseh
+ h
< 1) h
= 1 - baseh
;
1841 /* store the logical size */
1842 SIZE_SET(self
->logical_size
,
1843 self
->size_inc
.width
> 1 ? w
: w
+ basew
,
1844 self
->size_inc
.height
> 1 ? h
: h
+ baseh
);
1846 w
*= self
->size_inc
.width
;
1847 h
*= self
->size_inc
.height
;
1853 /* adjust the height to match the width for the aspect ratios.
1854 for this, min size is not substituted for base size ever. */
1855 w
-= self
->base_size
.width
;
1856 h
-= self
->base_size
.height
;
1858 if (self
->min_ratio
)
1859 if (h
* self
->min_ratio
> w
) h
= (int)(w
/ self
->min_ratio
);
1860 if (self
->max_ratio
)
1861 if (h
* self
->max_ratio
< w
) h
= (int)(w
/ self
->max_ratio
);
1863 w
+= self
->base_size
.width
;
1864 h
+= self
->base_size
.height
;
1869 case OB_CORNER_TOPLEFT
:
1871 case OB_CORNER_TOPRIGHT
:
1872 x
-= w
- self
->area
.width
;
1874 case OB_CORNER_BOTTOMLEFT
:
1875 y
-= h
- self
->area
.height
;
1877 case OB_CORNER_BOTTOMRIGHT
:
1878 x
-= w
- self
->area
.width
;
1879 y
-= h
- self
->area
.height
;
1883 moved
= x
!= self
->area
.x
|| y
!= self
->area
.y
;
1884 resized
= w
!= self
->area
.width
|| h
!= self
->area
.height
;
1886 RECT_SET(self
->area
, x
, y
, w
, h
);
1888 /* for app-requested resizes, always resize if 'resized' is true.
1889 for user-requested ones, only resize if final is true, or when
1890 resizing in opaque mode */
1891 if ((!user
&& resized
) ||
1892 (user
&& (final
|| (resized
&& config_opaque_resize
))))
1893 XResizeWindow(ob_display
, self
->window
, w
, h
);
1895 /* move/resize the frame to match the request */
1897 if (self
->decorations
!= self
->frame
->decorations
)
1898 moved
= resized
= TRUE
;
1900 if (moved
|| resized
)
1901 frame_adjust_area(self
->frame
, moved
, resized
);
1903 if (!resized
&& (force_reply
|| ((!user
&& moved
) || (user
&& final
))))
1906 event
.type
= ConfigureNotify
;
1907 event
.xconfigure
.display
= ob_display
;
1908 event
.xconfigure
.event
= self
->window
;
1909 event
.xconfigure
.window
= self
->window
;
1911 /* root window real coords */
1912 event
.xconfigure
.x
= self
->frame
->area
.x
+ self
->frame
->size
.left
-
1914 event
.xconfigure
.y
= self
->frame
->area
.y
+ self
->frame
->size
.top
-
1916 event
.xconfigure
.width
= w
;
1917 event
.xconfigure
.height
= h
;
1918 event
.xconfigure
.border_width
= 0;
1919 event
.xconfigure
.above
= self
->frame
->plate
;
1920 event
.xconfigure
.override_redirect
= FALSE
;
1921 XSendEvent(event
.xconfigure
.display
, event
.xconfigure
.window
,
1922 FALSE
, StructureNotifyMask
, &event
);
1927 void client_fullscreen(ObClient
*self
, gboolean fs
, gboolean savearea
)
1931 if (!(self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
) || /* can't */
1932 self
->fullscreen
== fs
) return; /* already done */
1934 self
->fullscreen
= fs
;
1935 client_change_state(self
); /* change the state hints on the client,
1936 and adjust out layer/stacking */
1940 guint32 dimensions
[4];
1941 dimensions
[0] = self
->area
.x
;
1942 dimensions
[1] = self
->area
.y
;
1943 dimensions
[2] = self
->area
.width
;
1944 dimensions
[3] = self
->area
.height
;
1946 PROP_SETA32(self
->window
, openbox_premax
, cardinal
,
1950 /* these are not actually used cuz client_configure will set them
1951 as appropriate when the window is fullscreened */
1958 /* pick some fallbacks... */
1959 a
= screen_area_monitor(self
->desktop
, 0);
1960 x
= a
->x
+ a
->width
/ 4;
1961 y
= a
->y
+ a
->height
/ 4;
1965 if (PROP_GETA32(self
->window
, openbox_premax
, cardinal
,
1966 (guint32
**)&dimensions
, &num
)) {
1977 client_setup_decor_and_functions(self
);
1979 client_configure(self
, OB_CORNER_TOPLEFT
, x
, y
, w
, h
, TRUE
, TRUE
);
1981 /* try focus us when we go into fullscreen mode */
1985 static void client_iconify_recursive(ObClient
*self
,
1986 gboolean iconic
, gboolean curdesk
)
1989 gboolean changed
= FALSE
;
1992 if (self
->iconic
!= iconic
) {
1993 ob_debug("%sconifying window: 0x%lx\n", (iconic
? "I" : "Uni"),
1996 self
->iconic
= iconic
;
1999 if (self
->functions
& OB_CLIENT_FUNC_ICONIFY
) {
2000 self
->wmstate
= IconicState
;
2001 self
->ignore_unmaps
++;
2002 /* we unmap the client itself so that we can get MapRequest
2003 events, and because the ICCCM tells us to! */
2004 XUnmapWindow(ob_display
, self
->window
);
2006 /* update the focus lists.. iconic windows go to the bottom of
2007 the list, put the new iconic window at the 'top of the
2009 focus_order_to_top(self
);
2015 client_set_desktop(self
, screen_desktop
, FALSE
);
2016 self
->wmstate
= self
->shaded
? IconicState
: NormalState
;
2017 XMapWindow(ob_display
, self
->window
);
2019 /* this puts it after the current focused window */
2020 focus_order_remove(self
);
2021 focus_order_add_new(self
);
2023 /* this is here cuz with the VIDMODE extension, the viewport can
2024 change while a fullscreen window is iconic, and when it
2025 uniconifies, it would be nice if it did so to the new position
2027 client_reconfigure(self
);
2034 client_change_state(self
);
2035 client_showhide(self
);
2036 screen_update_areas();
2038 dispatch_client(iconic
? Event_Client_Unmapped
: Event_Client_Mapped
,
2042 /* iconify all transients */
2043 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
)
2044 if (it
->data
!= self
) client_iconify_recursive(it
->data
,
2048 void client_iconify(ObClient
*self
, gboolean iconic
, gboolean curdesk
)
2050 /* move up the transient chain as far as possible first */
2051 self
= client_search_top_transient(self
);
2053 client_iconify_recursive(client_search_top_transient(self
),
2057 void client_maximize(ObClient
*self
, gboolean max
, int dir
, gboolean savearea
)
2061 g_assert(dir
== 0 || dir
== 1 || dir
== 2);
2062 if (!(self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
)) return; /* can't */
2064 /* check if already done */
2066 if (dir
== 0 && self
->max_horz
&& self
->max_vert
) return;
2067 if (dir
== 1 && self
->max_horz
) return;
2068 if (dir
== 2 && self
->max_vert
) return;
2070 if (dir
== 0 && !self
->max_horz
&& !self
->max_vert
) return;
2071 if (dir
== 1 && !self
->max_horz
) return;
2072 if (dir
== 2 && !self
->max_vert
) return;
2075 /* work with the frame's coords */
2076 x
= self
->frame
->area
.x
;
2077 y
= self
->frame
->area
.y
;
2078 w
= self
->area
.width
;
2079 h
= self
->area
.height
;
2083 gint32 dimensions
[4];
2092 /* get the property off the window and use it for the dimensions
2093 we are already maxed on */
2094 if (PROP_GETA32(self
->window
, openbox_premax
, cardinal
,
2095 (guint32
**)&readdim
, &num
)) {
2097 if (self
->max_horz
) {
2098 dimensions
[0] = readdim
[0];
2099 dimensions
[2] = readdim
[2];
2101 if (self
->max_vert
) {
2102 dimensions
[1] = readdim
[1];
2103 dimensions
[3] = readdim
[3];
2109 PROP_SETA32(self
->window
, openbox_premax
, cardinal
,
2110 (guint32
*)dimensions
, 4);
2117 /* pick some fallbacks... */
2118 a
= screen_area_monitor(self
->desktop
, 0);
2119 if (dir
== 0 || dir
== 1) { /* horz */
2120 x
= a
->x
+ a
->width
/ 4;
2123 if (dir
== 0 || dir
== 2) { /* vert */
2124 y
= a
->y
+ a
->height
/ 4;
2128 if (PROP_GETA32(self
->window
, openbox_premax
, cardinal
,
2129 (guint32
**)&dimensions
, &num
)) {
2131 if (dir
== 0 || dir
== 1) { /* horz */
2135 if (dir
== 0 || dir
== 2) { /* vert */
2144 if (dir
== 0 || dir
== 1) /* horz */
2145 self
->max_horz
= max
;
2146 if (dir
== 0 || dir
== 2) /* vert */
2147 self
->max_vert
= max
;
2149 if (!self
->max_horz
&& !self
->max_vert
)
2150 PROP_ERASE(self
->window
, openbox_premax
);
2152 client_change_state(self
); /* change the state hints on the client */
2154 /* figure out where the client should be going */
2155 frame_frame_gravity(self
->frame
, &x
, &y
);
2156 client_configure(self
, OB_CORNER_TOPLEFT
, x
, y
, w
, h
, TRUE
, TRUE
);
2159 void client_shade(ObClient
*self
, gboolean shade
)
2161 if ((!(self
->functions
& OB_CLIENT_FUNC_SHADE
) &&
2162 shade
) || /* can't shade */
2163 self
->shaded
== shade
) return; /* already done */
2165 /* when we're iconic, don't change the wmstate */
2167 self
->wmstate
= shade
? IconicState
: NormalState
;
2168 self
->shaded
= shade
;
2169 client_change_state(self
);
2170 /* resize the frame to just the titlebar */
2171 frame_adjust_area(self
->frame
, FALSE
, FALSE
);
2174 void client_close(ObClient
*self
)
2178 if (!(self
->functions
& OB_CLIENT_FUNC_CLOSE
)) return;
2181 XXX: itd be cool to do timeouts and shit here for killing the client's
2183 like... if the window is around after 5 seconds, then the close button
2184 turns a nice red, and if this function is called again, the client is
2188 ce
.xclient
.type
= ClientMessage
;
2189 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
2190 ce
.xclient
.display
= ob_display
;
2191 ce
.xclient
.window
= self
->window
;
2192 ce
.xclient
.format
= 32;
2193 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_delete_window
;
2194 ce
.xclient
.data
.l
[1] = event_lasttime
;
2195 ce
.xclient
.data
.l
[2] = 0l;
2196 ce
.xclient
.data
.l
[3] = 0l;
2197 ce
.xclient
.data
.l
[4] = 0l;
2198 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
2201 void client_kill(ObClient
*self
)
2203 XKillClient(ob_display
, self
->window
);
2206 void client_set_desktop_recursive(ObClient
*self
,
2207 guint target
, gboolean donthide
)
2212 if (target
!= self
->desktop
) {
2214 ob_debug("Setting desktop %u\n", target
+1);
2216 g_assert(target
< screen_num_desktops
|| target
== DESKTOP_ALL
);
2218 /* remove from the old desktop(s) */
2219 focus_order_remove(self
);
2221 old
= self
->desktop
;
2222 self
->desktop
= target
;
2223 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, target
);
2224 /* the frame can display the current desktop state */
2225 frame_adjust_state(self
->frame
);
2226 /* 'move' the window to the new desktop */
2228 client_showhide(self
);
2229 /* raise if it was not already on the desktop */
2230 if (old
!= DESKTOP_ALL
)
2231 stacking_raise(CLIENT_AS_WINDOW(self
));
2232 screen_update_areas();
2234 /* add to the new desktop(s) */
2235 if (config_focus_new
)
2236 focus_order_to_top(self
);
2238 focus_order_to_bottom(self
);
2240 dispatch_client(Event_Client_Desktop
, self
, target
, old
);
2243 /* move all transients */
2244 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
)
2245 if (it
->data
!= self
) client_set_desktop_recursive(it
->data
,
2249 void client_set_desktop(ObClient
*self
, guint target
, gboolean donthide
)
2251 client_set_desktop_recursive(client_search_top_transient(self
),
2255 ObClient
*client_search_modal_child(ObClient
*self
)
2260 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
) {
2261 ObClient
*c
= it
->data
;
2262 if ((ret
= client_search_modal_child(c
))) return ret
;
2263 if (c
->modal
) return c
;
2268 gboolean
client_validate(ObClient
*self
)
2272 XSync(ob_display
, FALSE
); /* get all events on the server */
2274 if (XCheckTypedWindowEvent(ob_display
, self
->window
, DestroyNotify
, &e
) ||
2275 XCheckTypedWindowEvent(ob_display
, self
->window
, UnmapNotify
, &e
)) {
2276 XPutBackEvent(ob_display
, &e
);
2283 void client_set_wm_state(ObClient
*self
, long state
)
2285 if (state
== self
->wmstate
) return; /* no change */
2289 client_iconify(self
, TRUE
, TRUE
);
2292 client_iconify(self
, FALSE
, TRUE
);
2297 void client_set_state(ObClient
*self
, Atom action
, long data1
, long data2
)
2299 gboolean shaded
= self
->shaded
;
2300 gboolean fullscreen
= self
->fullscreen
;
2301 gboolean max_horz
= self
->max_horz
;
2302 gboolean max_vert
= self
->max_vert
;
2305 if (!(action
== prop_atoms
.net_wm_state_add
||
2306 action
== prop_atoms
.net_wm_state_remove
||
2307 action
== prop_atoms
.net_wm_state_toggle
))
2308 /* an invalid action was passed to the client message, ignore it */
2311 for (i
= 0; i
< 2; ++i
) {
2312 Atom state
= i
== 0 ? data1
: data2
;
2314 if (!state
) continue;
2316 /* if toggling, then pick whether we're adding or removing */
2317 if (action
== prop_atoms
.net_wm_state_toggle
) {
2318 if (state
== prop_atoms
.net_wm_state_modal
)
2319 action
= self
->modal
? prop_atoms
.net_wm_state_remove
:
2320 prop_atoms
.net_wm_state_add
;
2321 else if (state
== prop_atoms
.net_wm_state_maximized_vert
)
2322 action
= self
->max_vert
? prop_atoms
.net_wm_state_remove
:
2323 prop_atoms
.net_wm_state_add
;
2324 else if (state
== prop_atoms
.net_wm_state_maximized_horz
)
2325 action
= self
->max_horz
? prop_atoms
.net_wm_state_remove
:
2326 prop_atoms
.net_wm_state_add
;
2327 else if (state
== prop_atoms
.net_wm_state_shaded
)
2328 action
= self
->shaded
? prop_atoms
.net_wm_state_remove
:
2329 prop_atoms
.net_wm_state_add
;
2330 else if (state
== prop_atoms
.net_wm_state_skip_taskbar
)
2331 action
= self
->skip_taskbar
?
2332 prop_atoms
.net_wm_state_remove
:
2333 prop_atoms
.net_wm_state_add
;
2334 else if (state
== prop_atoms
.net_wm_state_skip_pager
)
2335 action
= self
->skip_pager
?
2336 prop_atoms
.net_wm_state_remove
:
2337 prop_atoms
.net_wm_state_add
;
2338 else if (state
== prop_atoms
.net_wm_state_fullscreen
)
2339 action
= self
->fullscreen
?
2340 prop_atoms
.net_wm_state_remove
:
2341 prop_atoms
.net_wm_state_add
;
2342 else if (state
== prop_atoms
.net_wm_state_above
)
2343 action
= self
->above
? prop_atoms
.net_wm_state_remove
:
2344 prop_atoms
.net_wm_state_add
;
2345 else if (state
== prop_atoms
.net_wm_state_below
)
2346 action
= self
->below
? prop_atoms
.net_wm_state_remove
:
2347 prop_atoms
.net_wm_state_add
;
2350 if (action
== prop_atoms
.net_wm_state_add
) {
2351 if (state
== prop_atoms
.net_wm_state_modal
) {
2352 /* XXX raise here or something? */
2354 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
2356 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
2358 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
2360 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
2361 self
->skip_taskbar
= TRUE
;
2362 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
2363 self
->skip_pager
= TRUE
;
2364 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
2366 } else if (state
== prop_atoms
.net_wm_state_above
) {
2368 } else if (state
== prop_atoms
.net_wm_state_below
) {
2372 } else { /* action == prop_atoms.net_wm_state_remove */
2373 if (state
== prop_atoms
.net_wm_state_modal
) {
2374 self
->modal
= FALSE
;
2375 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
2377 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
2379 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
2381 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
2382 self
->skip_taskbar
= FALSE
;
2383 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
2384 self
->skip_pager
= FALSE
;
2385 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
2387 } else if (state
== prop_atoms
.net_wm_state_above
) {
2388 self
->above
= FALSE
;
2389 } else if (state
== prop_atoms
.net_wm_state_below
) {
2390 self
->below
= FALSE
;
2394 if (max_horz
!= self
->max_horz
|| max_vert
!= self
->max_vert
) {
2395 if (max_horz
!= self
->max_horz
&& max_vert
!= self
->max_vert
) {
2397 if (max_horz
== max_vert
) { /* both going the same way */
2398 client_maximize(self
, max_horz
, 0, TRUE
);
2400 client_maximize(self
, max_horz
, 1, TRUE
);
2401 client_maximize(self
, max_vert
, 2, TRUE
);
2405 if (max_horz
!= self
->max_horz
)
2406 client_maximize(self
, max_horz
, 1, TRUE
);
2408 client_maximize(self
, max_vert
, 2, TRUE
);
2411 /* change fullscreen state before shading, as it will affect if the window
2413 if (fullscreen
!= self
->fullscreen
)
2414 client_fullscreen(self
, fullscreen
, TRUE
);
2415 if (shaded
!= self
->shaded
)
2416 client_shade(self
, shaded
);
2417 client_calc_layer(self
);
2418 client_change_state(self
); /* change the hint to reflect these changes */
2421 ObClient
*client_focus_target(ObClient
*self
)
2425 /* if we have a modal child, then focus it, not us */
2426 child
= client_search_modal_child(self
);
2427 if (child
) return child
;
2431 gboolean
client_can_focus(ObClient
*self
)
2435 /* choose the correct target */
2436 self
= client_focus_target(self
);
2438 if (!self
->frame
->visible
)
2441 if (!((self
->can_focus
|| self
->focus_notify
) &&
2442 (self
->desktop
== screen_desktop
||
2443 self
->desktop
== DESKTOP_ALL
) &&
2447 /* do a check to see if the window has already been unmapped or destroyed
2448 do this intelligently while watching out for unmaps we've generated
2449 (ignore_unmaps > 0) */
2450 if (XCheckTypedWindowEvent(ob_display
, self
->window
,
2451 DestroyNotify
, &ev
)) {
2452 XPutBackEvent(ob_display
, &ev
);
2455 while (XCheckTypedWindowEvent(ob_display
, self
->window
,
2456 UnmapNotify
, &ev
)) {
2457 if (self
->ignore_unmaps
) {
2458 self
->ignore_unmaps
--;
2460 XPutBackEvent(ob_display
, &ev
);
2468 gboolean
client_focus(ObClient
*self
)
2470 /* choose the correct target */
2471 self
= client_focus_target(self
);
2473 if (!client_can_focus(self
)) {
2474 if (!self
->frame
->visible
) {
2475 /* update the focus lists */
2476 focus_order_to_top(self
);
2481 if (self
->can_focus
)
2482 /* RevertToPointerRoot causes much more headache than RevertToNone, so
2483 I choose to use it always, hopefully to find errors quicker, if any
2484 are left. (I hate X. I hate focus events.) */
2485 XSetInputFocus(ob_display
, self
->window
, RevertToPointerRoot
,
2488 if (self
->focus_notify
) {
2490 ce
.xclient
.type
= ClientMessage
;
2491 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
2492 ce
.xclient
.display
= ob_display
;
2493 ce
.xclient
.window
= self
->window
;
2494 ce
.xclient
.format
= 32;
2495 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_take_focus
;
2496 ce
.xclient
.data
.l
[1] = event_lasttime
;
2497 ce
.xclient
.data
.l
[2] = 0l;
2498 ce
.xclient
.data
.l
[3] = 0l;
2499 ce
.xclient
.data
.l
[4] = 0l;
2500 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
2504 ob_debug("%sively focusing %lx at %d\n",
2505 (self
->can_focus
? "act" : "pass"),
2506 self
->window
, (int) event_lasttime
);
2509 /* Cause the FocusIn to come back to us. Important for desktop switches,
2510 since otherwise we'll have no FocusIn on the queue and send it off to
2511 the focus_backup. */
2512 XSync(ob_display
, FALSE
);
2516 void client_unfocus(ObClient
*self
)
2518 g_assert(focus_client
== self
);
2520 ob_debug("client_unfocus for %lx\n", self
->window
);
2522 focus_fallback(OB_FOCUS_FALLBACK_UNFOCUSING
);
2525 void client_activate(ObClient
*self
)
2527 if (client_normal(self
) && screen_showing_desktop
)
2528 screen_show_desktop(FALSE
);
2530 client_iconify(self
, FALSE
, FALSE
);
2531 if (self
->desktop
!= DESKTOP_ALL
&&
2532 self
->desktop
!= screen_desktop
)
2533 screen_set_desktop(self
->desktop
);
2534 else if (!self
->frame
->visible
)
2535 /* if its not visible for other reasons, then don't mess
2539 client_shade(self
, FALSE
);
2541 stacking_raise(CLIENT_AS_WINDOW(self
));
2544 gboolean
client_focused(ObClient
*self
)
2546 return self
== focus_client
;
2549 ObClientIcon
*client_icon(ObClient
*self
, int w
, int h
)
2552 /* si is the smallest image >= req */
2553 /* li is the largest image < req */
2554 unsigned long size
, smallest
= 0xffffffff, largest
= 0, si
= 0, li
= 0;
2556 if (!self
->nicons
) return NULL
;
2558 for (i
= 0; i
< self
->nicons
; ++i
) {
2559 size
= self
->icons
[i
].width
* self
->icons
[i
].height
;
2560 if (size
< smallest
&& size
>= (unsigned)(w
* h
)) {
2564 if (size
> largest
&& size
<= (unsigned)(w
* h
)) {
2569 if (largest
== 0) /* didnt find one smaller than the requested size */
2570 return &self
->icons
[si
];
2571 return &self
->icons
[li
];
2574 /* this be mostly ripped from fvwm */
2575 ObClient
*client_find_directional(ObClient
*c
, ObDirection dir
)
2577 int my_cx
, my_cy
, his_cx
, his_cy
;
2580 int score
, best_score
;
2581 ObClient
*best_client
, *cur
;
2587 /* first, find the centre coords of the currently focused window */
2588 my_cx
= c
->frame
->area
.x
+ c
->frame
->area
.width
/ 2;
2589 my_cy
= c
->frame
->area
.y
+ c
->frame
->area
.height
/ 2;
2594 for(it
= g_list_first(client_list
); it
; it
= it
->next
) {
2597 /* the currently selected window isn't interesting */
2600 if (!client_normal(cur
))
2602 if(c
->desktop
!= cur
->desktop
&& cur
->desktop
!= DESKTOP_ALL
)
2606 if(client_focus_target(cur
) == cur
&&
2607 !(cur
->can_focus
|| cur
->focus_notify
))
2610 /* find the centre coords of this window, from the
2611 * currently focused window's point of view */
2612 his_cx
= (cur
->frame
->area
.x
- my_cx
)
2613 + cur
->frame
->area
.width
/ 2;
2614 his_cy
= (cur
->frame
->area
.y
- my_cy
)
2615 + cur
->frame
->area
.height
/ 2;
2619 /* Rotate the diagonals 45 degrees counterclockwise.
2620 * To do this, multiply the matrix /+h +h\ with the
2621 * vector (x y). \-h +h/
2622 * h = sqrt(0.5). We can set h := 1 since absolute
2623 * distance doesn't matter here. */
2624 tx
= his_cx
+ his_cy
;
2625 his_cy
= -his_cx
+ his_cy
;
2630 case OB_DIRECTION_NORTH
:
2631 case OB_DIRECTION_SOUTH
:
2632 case OB_DIRECTION_NORTHEAST
:
2633 case OB_DIRECTION_SOUTHWEST
:
2634 offset
= (his_cx
< 0) ? -his_cx
: his_cx
;
2635 distance
= ((dir
== OB_DIRECTION_NORTH
||
2636 dir
== OB_DIRECTION_NORTHEAST
) ?
2639 case OB_DIRECTION_EAST
:
2640 case OB_DIRECTION_WEST
:
2641 case OB_DIRECTION_SOUTHEAST
:
2642 case OB_DIRECTION_NORTHWEST
:
2643 offset
= (his_cy
< 0) ? -his_cy
: his_cy
;
2644 distance
= ((dir
== OB_DIRECTION_WEST
||
2645 dir
== OB_DIRECTION_NORTHWEST
) ?
2650 /* the target must be in the requested direction */
2654 /* Calculate score for this window. The smaller the better. */
2655 score
= distance
+ offset
;
2657 /* windows more than 45 degrees off the direction are
2658 * heavily penalized and will only be chosen if nothing
2659 * else within a million pixels */
2660 if(offset
> distance
)
2663 if(best_score
== -1 || score
< best_score
)
2671 void client_set_layer(ObClient
*self
, int layer
)
2675 self
->above
= FALSE
;
2676 } else if (layer
== 0) {
2677 self
->below
= self
->above
= FALSE
;
2679 self
->below
= FALSE
;
2682 client_calc_layer(self
);
2683 client_change_state(self
); /* reflect this in the state hints */
2686 guint
client_monitor(ObClient
*self
)
2690 for (i
= 0; i
< screen_num_monitors
; ++i
) {
2691 Rect
*area
= screen_physical_area_monitor(i
);
2692 if (RECT_INTERSECTS_RECT(*area
, self
->frame
->area
))
2695 if (i
== screen_num_monitors
) i
= 0;
2696 g_assert(i
< screen_num_monitors
);
2700 ObClient
*client_search_top_transient(ObClient
*self
)
2702 /* move up the transient chain as far as possible */
2703 if (self
->transient_for
) {
2704 if (self
->transient_for
!= OB_TRAN_GROUP
) {
2705 return client_search_top_transient(self
->transient_for
);
2709 for (it
= self
->group
->members
; it
; it
= it
->next
) {
2710 ObClient
*c
= it
->data
;
2712 /* checking transient_for prevents infinate loops! */
2713 if (c
!= self
&& !c
->transient_for
)
2724 ObClient
*client_search_transient(ObClient
*self
, ObClient
*search
)
2728 for (sit
= self
->transients
; sit
; sit
= g_slist_next(sit
)) {
2729 if (sit
->data
== search
)
2731 if (client_search_transient(sit
->data
, search
))
2737 gchar
* client_get_sm_client_id(ObClient
*self
)
2741 if (!PROP_GETS(self
->window
, sm_client_id
, locale
, &id
) && self
->group
)
2742 PROP_GETS(self
->group
->leader
, sm_client_id
, locale
, &id
);