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 /* set the desktop hint, to make sure that it always exists */
241 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, self
->desktop
);
243 client_change_state(self
);
245 /* remove the client's border (and adjust re gravity) */
246 client_toggle_border(self
, FALSE
);
248 /* specify that if we exit, the window should not be destroyed and should
249 be reparented back to root automatically */
250 XChangeSaveSet(ob_display
, window
, SetModeInsert
);
252 /* create the decoration frame for the client window */
253 self
->frame
= frame_new();
255 frame_grab_client(self
->frame
, self
);
257 client_apply_startup_state(self
);
261 /* update the focus lists */
262 focus_order_add_new(self
);
264 stacking_add(CLIENT_AS_WINDOW(self
));
266 /* focus the new window? */
267 if (ob_state() != OB_STATE_STARTING
&& config_focus_new
&&
268 /* note the check against Type_Normal/Dialog, not client_normal(self),
269 which would also include other types. in this case we want more
270 strict rules for focus */
271 (self
->type
== OB_CLIENT_TYPE_NORMAL
||
272 self
->type
== OB_CLIENT_TYPE_DIALOG
))
274 if (self
->desktop
!= screen_desktop
) {
275 /* activate the window */
278 gboolean group_foc
= FALSE
;
283 for (it
= self
->group
->members
; it
; it
= it
->next
)
285 if (client_focused(it
->data
))
293 (!self
->transient_for
&& (!self
->group
||
294 !self
->group
->members
->next
))) ||
295 client_search_focus_tree_full(self
) ||
297 !client_normal(focus_client
))
299 /* activate the window */
305 dispatch_client(Event_Client_New
, self
, 0, 0);
307 /* make sure the window is visible */
308 client_move_onscreen(self
, TRUE
);
310 screen_update_areas();
312 client_showhide(self
);
314 /* use client_focus instead of client_activate cuz client_activate does
315 stuff like switch desktops etc and I'm not interested in all that when
316 a window maps since its not based on an action from the user like
317 clicking a window to activate is. so keep the new window out of the way
319 if (activate
) client_focus(self
);
321 /* client_activate does this but we aret using it so we have to do it
323 if (screen_showing_desktop
)
324 screen_show_desktop(FALSE
);
326 /* add to client list/map */
327 client_list
= g_list_append(client_list
, self
);
328 g_hash_table_insert(window_map
, &self
->window
, self
);
330 /* update the list hints */
333 dispatch_client(Event_Client_Mapped
, self
, 0, 0);
335 ob_debug("Managed window 0x%lx (%s)\n", window
, self
->class);
338 void client_unmanage_all()
340 while (client_list
!= NULL
)
341 client_unmanage(client_list
->data
);
344 /* called by client_unmanage() to close any menus referencing this client */
345 void client_close_menus(gpointer key
, gpointer value
, gpointer self
)
347 if (((ObMenu
*)value
)->client
== (ObClient
*)self
)
348 menu_hide((ObMenu
*)value
);
351 void client_unmanage(ObClient
*self
)
356 ob_debug("Unmanaging window: %lx (%s)\n", self
->window
, self
->class);
358 dispatch_client(Event_Client_Destroy
, self
, 0, 0);
359 g_assert(self
!= NULL
);
361 /* remove the window from our save set */
362 XChangeSaveSet(ob_display
, self
->window
, SetModeDelete
);
364 /* we dont want events no more */
365 XSelectInput(ob_display
, self
->window
, NoEventMask
);
367 frame_hide(self
->frame
);
369 client_list
= g_list_remove(client_list
, self
);
370 stacking_remove(self
);
371 g_hash_table_remove(window_map
, &self
->window
);
373 /* update the focus lists */
374 focus_order_remove(self
);
376 /* once the client is out of the list, update the struts to remove it's
378 screen_update_areas();
380 /* tell our parent(s) that we're gone */
381 if (self
->transient_for
== OB_TRAN_GROUP
) { /* transient of group */
384 for (it
= self
->group
->members
; it
; it
= it
->next
)
385 if (it
->data
!= self
)
386 ((ObClient
*)it
->data
)->transients
=
387 g_slist_remove(((ObClient
*)it
->data
)->transients
, self
);
388 } else if (self
->transient_for
) { /* transient of window */
389 self
->transient_for
->transients
=
390 g_slist_remove(self
->transient_for
->transients
, self
);
393 /* tell our transients that we're gone */
394 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
) {
395 if (((ObClient
*)it
->data
)->transient_for
!= OB_TRAN_GROUP
) {
396 ((ObClient
*)it
->data
)->transient_for
= NULL
;
397 client_calc_layer(it
->data
);
401 if (moveresize_client
== self
)
402 moveresize_end(TRUE
);
404 /* close any windows that are attached to this window */
405 g_hash_table_foreach(menu_hash
, client_close_menus
, self
);
408 if (focus_client
== self
) {
411 /* focus the last focused window on the desktop, and ignore enter
412 events from the unmap so it doesnt mess with the focus */
413 while (XCheckTypedEvent(ob_display
, EnterNotify
, &e
));
414 client_unfocus(self
);
417 /* remove from its group */
419 group_remove(self
->group
, self
);
423 /* dispatch the unmapped event */
424 dispatch_client(Event_Client_Unmapped
, self
, 0, 0);
425 g_assert(self
!= NULL
);
427 /* give the client its border back */
428 client_toggle_border(self
, TRUE
);
430 /* reparent the window out of the frame, and free the frame */
431 frame_release_client(self
->frame
, self
);
434 if (ob_state() != OB_STATE_EXITING
) {
435 /* these values should not be persisted across a window
437 PROP_ERASE(self
->window
, net_wm_desktop
);
438 PROP_ERASE(self
->window
, net_wm_state
);
439 PROP_ERASE(self
->window
, wm_state
);
441 /* if we're left in an iconic state, the client wont be mapped. this is
442 bad, since we will no longer be managing the window on restart */
444 XMapWindow(ob_display
, self
->window
);
448 ob_debug("Unmanaged window 0x%lx\n", self
->window
);
450 /* free all data allocated in the client struct */
451 g_slist_free(self
->transients
);
452 for (j
= 0; j
< self
->nicons
; ++j
)
453 g_free(self
->icons
[j
].data
);
454 if (self
->nicons
> 0)
457 g_free(self
->icon_title
);
463 /* update the list hints */
467 static void client_restore_session_state(ObClient
*self
)
471 s
= session_state_find(self
);
474 RECT_SET(self
->area
, s
->x
, s
->y
, s
->w
, s
->h
);
475 XResizeWindow(ob_display
, self
->window
, s
->w
, s
->h
);
476 self
->positioned
= TRUE
;
477 self
->desktop
= s
->desktop
== DESKTOP_ALL
? s
->desktop
:
478 MIN(screen_num_desktops
- 1, s
->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
;
709 static void client_get_state(ObClient
*self
)
714 self
->modal
= self
->shaded
= self
->max_horz
= self
->max_vert
=
715 self
->fullscreen
= self
->above
= self
->below
= self
->iconic
=
716 self
->skip_taskbar
= self
->skip_pager
= FALSE
;
718 if (PROP_GETA32(self
->window
, net_wm_state
, atom
, &state
, &num
)) {
720 for (i
= 0; i
< num
; ++i
) {
721 if (state
[i
] == prop_atoms
.net_wm_state_modal
)
723 else if (state
[i
] == prop_atoms
.net_wm_state_shaded
)
725 else if (state
[i
] == prop_atoms
.net_wm_state_hidden
)
727 else if (state
[i
] == prop_atoms
.net_wm_state_skip_taskbar
)
728 self
->skip_taskbar
= TRUE
;
729 else if (state
[i
] == prop_atoms
.net_wm_state_skip_pager
)
730 self
->skip_pager
= TRUE
;
731 else if (state
[i
] == prop_atoms
.net_wm_state_fullscreen
)
732 self
->fullscreen
= TRUE
;
733 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_vert
)
734 self
->max_vert
= TRUE
;
735 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_horz
)
736 self
->max_horz
= TRUE
;
737 else if (state
[i
] == prop_atoms
.net_wm_state_above
)
739 else if (state
[i
] == prop_atoms
.net_wm_state_below
)
747 static void client_get_shaped(ObClient
*self
)
749 self
->shaped
= FALSE
;
751 if (extensions_shape
) {
756 XShapeSelectInput(ob_display
, self
->window
, ShapeNotifyMask
);
758 XShapeQueryExtents(ob_display
, self
->window
, &s
, &foo
,
759 &foo
, &ufoo
, &ufoo
, &foo
, &foo
, &foo
, &ufoo
,
761 self
->shaped
= (s
!= 0);
766 void client_update_transient_for(ObClient
*self
)
769 ObClient
*target
= NULL
;
771 if (XGetTransientForHint(ob_display
, self
->window
, &t
)) {
772 self
->transient
= TRUE
;
773 if (t
!= self
->window
) { /* cant be transient to itself! */
774 target
= g_hash_table_lookup(window_map
, &t
);
775 /* if this happens then we need to check for it*/
776 g_assert(target
!= self
);
777 g_assert(!target
|| WINDOW_IS_CLIENT(target
));
779 if (!target
&& self
->group
) {
780 /* not transient to a client, see if it is transient for a
782 if (t
== self
->group
->leader
||
784 t
== RootWindow(ob_display
, ob_screen
)) {
785 /* window is a transient for its group! */
786 target
= OB_TRAN_GROUP
;
791 self
->transient
= FALSE
;
793 /* if anything has changed... */
794 if (target
!= self
->transient_for
) {
795 if (self
->transient_for
== OB_TRAN_GROUP
) { /* transient of group */
798 /* remove from old parents */
799 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
800 ObClient
*c
= it
->data
;
801 if (c
!= self
&& !c
->transient_for
)
802 c
->transients
= g_slist_remove(c
->transients
, self
);
804 } else if (self
->transient_for
!= NULL
) { /* transient of window */
805 /* remove from old parent */
806 self
->transient_for
->transients
=
807 g_slist_remove(self
->transient_for
->transients
, self
);
809 self
->transient_for
= target
;
810 if (self
->transient_for
== OB_TRAN_GROUP
) { /* transient of group */
813 /* add to new parents */
814 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
815 ObClient
*c
= it
->data
;
816 if (c
!= self
&& !c
->transient_for
)
817 c
->transients
= g_slist_append(c
->transients
, self
);
820 /* remove all transients which are in the group, that causes
821 circlular pointer hell of doom */
822 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
824 for (sit
= self
->transients
; sit
; sit
= next
) {
825 next
= g_slist_next(sit
);
826 if (sit
->data
== it
->data
)
828 g_slist_delete_link(self
->transients
, sit
);
831 } else if (self
->transient_for
!= NULL
) { /* transient of window */
832 /* add to new parent */
833 self
->transient_for
->transients
=
834 g_slist_append(self
->transient_for
->transients
, self
);
839 static void client_get_mwm_hints(ObClient
*self
)
844 self
->mwmhints
.flags
= 0; /* default to none */
846 if (PROP_GETA32(self
->window
, motif_wm_hints
, motif_wm_hints
,
848 if (num
>= OB_MWM_ELEMENTS
) {
849 self
->mwmhints
.flags
= hints
[0];
850 self
->mwmhints
.functions
= hints
[1];
851 self
->mwmhints
.decorations
= hints
[2];
857 void client_get_type(ObClient
*self
)
864 if (PROP_GETA32(self
->window
, net_wm_window_type
, atom
, &val
, &num
)) {
865 /* use the first value that we know about in the array */
866 for (i
= 0; i
< num
; ++i
) {
867 if (val
[i
] == prop_atoms
.net_wm_window_type_desktop
)
868 self
->type
= OB_CLIENT_TYPE_DESKTOP
;
869 else if (val
[i
] == prop_atoms
.net_wm_window_type_dock
)
870 self
->type
= OB_CLIENT_TYPE_DOCK
;
871 else if (val
[i
] == prop_atoms
.net_wm_window_type_toolbar
)
872 self
->type
= OB_CLIENT_TYPE_TOOLBAR
;
873 else if (val
[i
] == prop_atoms
.net_wm_window_type_menu
)
874 self
->type
= OB_CLIENT_TYPE_MENU
;
875 else if (val
[i
] == prop_atoms
.net_wm_window_type_utility
)
876 self
->type
= OB_CLIENT_TYPE_UTILITY
;
877 else if (val
[i
] == prop_atoms
.net_wm_window_type_splash
)
878 self
->type
= OB_CLIENT_TYPE_SPLASH
;
879 else if (val
[i
] == prop_atoms
.net_wm_window_type_dialog
)
880 self
->type
= OB_CLIENT_TYPE_DIALOG
;
881 else if (val
[i
] == prop_atoms
.net_wm_window_type_normal
)
882 self
->type
= OB_CLIENT_TYPE_NORMAL
;
883 else if (val
[i
] == prop_atoms
.kde_net_wm_window_type_override
) {
884 /* prevent this window from getting any decor or
886 self
->mwmhints
.flags
&= (OB_MWM_FLAG_FUNCTIONS
|
887 OB_MWM_FLAG_DECORATIONS
);
888 self
->mwmhints
.decorations
= 0;
889 self
->mwmhints
.functions
= 0;
891 if (self
->type
!= (ObClientType
) -1)
892 break; /* grab the first legit type */
897 if (self
->type
== (ObClientType
) -1) {
898 /*the window type hint was not set, which means we either classify
899 ourself as a normal window or a dialog, depending on if we are a
902 self
->type
= OB_CLIENT_TYPE_DIALOG
;
904 self
->type
= OB_CLIENT_TYPE_NORMAL
;
908 void client_update_protocols(ObClient
*self
)
913 self
->focus_notify
= FALSE
;
914 self
->delete_window
= FALSE
;
916 if (PROP_GETA32(self
->window
, wm_protocols
, atom
, &proto
, &num_return
)) {
917 for (i
= 0; i
< num_return
; ++i
) {
918 if (proto
[i
] == prop_atoms
.wm_delete_window
) {
919 /* this means we can request the window to close */
920 self
->delete_window
= TRUE
;
921 } else if (proto
[i
] == prop_atoms
.wm_take_focus
)
922 /* if this protocol is requested, then the window will be
923 notified whenever we want it to receive focus */
924 self
->focus_notify
= TRUE
;
930 static void client_get_gravity(ObClient
*self
)
932 XWindowAttributes wattrib
;
935 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
936 g_assert(ret
!= BadWindow
);
937 self
->gravity
= wattrib
.win_gravity
;
940 void client_update_normal_hints(ObClient
*self
)
944 int oldgravity
= self
->gravity
;
947 self
->min_ratio
= 0.0f
;
948 self
->max_ratio
= 0.0f
;
949 SIZE_SET(self
->size_inc
, 1, 1);
950 SIZE_SET(self
->base_size
, 0, 0);
951 SIZE_SET(self
->min_size
, 0, 0);
952 SIZE_SET(self
->max_size
, G_MAXINT
, G_MAXINT
);
954 /* get the hints from the window */
955 if (XGetWMNormalHints(ob_display
, self
->window
, &size
, &ret
)) {
956 /* don't let apps tell me where to put transient windows, but only if
957 they have a valid parent */
958 self
->positioned
= !!(size
.flags
& (PPosition
|USPosition
)) &&
959 !self
->transient_for
;
961 if (size
.flags
& PWinGravity
) {
962 self
->gravity
= size
.win_gravity
;
964 /* if the client has a frame, i.e. has already been mapped and
965 is changing its gravity */
966 if (self
->frame
&& self
->gravity
!= oldgravity
) {
967 /* move our idea of the client's position based on its new
969 self
->area
.x
= self
->frame
->area
.x
;
970 self
->area
.y
= self
->frame
->area
.y
;
971 frame_frame_gravity(self
->frame
, &self
->area
.x
, &self
->area
.y
);
975 if (size
.flags
& PAspect
) {
976 if (size
.min_aspect
.y
)
977 self
->min_ratio
= (float)size
.min_aspect
.x
/ size
.min_aspect
.y
;
978 if (size
.max_aspect
.y
)
979 self
->max_ratio
= (float)size
.max_aspect
.x
/ size
.max_aspect
.y
;
982 if (size
.flags
& PMinSize
)
983 SIZE_SET(self
->min_size
, size
.min_width
, size
.min_height
);
985 if (size
.flags
& PMaxSize
)
986 SIZE_SET(self
->max_size
, size
.max_width
, size
.max_height
);
988 if (size
.flags
& PBaseSize
)
989 SIZE_SET(self
->base_size
, size
.base_width
, size
.base_height
);
991 if (size
.flags
& PResizeInc
)
992 SIZE_SET(self
->size_inc
, size
.width_inc
, size
.height_inc
);
996 void client_setup_decor_and_functions(ObClient
*self
)
998 /* start with everything (cept fullscreen) */
999 self
->decorations
= (OB_FRAME_DECOR_TITLEBAR
|
1000 OB_FRAME_DECOR_HANDLE
|
1001 OB_FRAME_DECOR_GRIPS
|
1002 OB_FRAME_DECOR_BORDER
|
1003 OB_FRAME_DECOR_ICON
|
1004 OB_FRAME_DECOR_ALLDESKTOPS
|
1005 OB_FRAME_DECOR_ICONIFY
|
1006 OB_FRAME_DECOR_MAXIMIZE
|
1007 OB_FRAME_DECOR_SHADE
);
1008 self
->functions
= (OB_CLIENT_FUNC_RESIZE
|
1009 OB_CLIENT_FUNC_MOVE
|
1010 OB_CLIENT_FUNC_ICONIFY
|
1011 OB_CLIENT_FUNC_MAXIMIZE
|
1012 OB_CLIENT_FUNC_SHADE
);
1013 if (self
->delete_window
) {
1014 self
->functions
|= OB_CLIENT_FUNC_CLOSE
;
1015 self
->decorations
|= OB_FRAME_DECOR_CLOSE
;
1018 if (!(self
->min_size
.width
< self
->max_size
.width
||
1019 self
->min_size
.height
< self
->max_size
.height
))
1020 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
1022 switch (self
->type
) {
1023 case OB_CLIENT_TYPE_NORMAL
:
1024 /* normal windows retain all of the possible decorations and
1025 functionality, and are the only windows that you can fullscreen */
1026 self
->functions
|= OB_CLIENT_FUNC_FULLSCREEN
;
1029 case OB_CLIENT_TYPE_DIALOG
:
1030 case OB_CLIENT_TYPE_UTILITY
:
1031 /* these windows cannot be maximized */
1032 self
->functions
&= ~OB_CLIENT_FUNC_MAXIMIZE
;
1035 case OB_CLIENT_TYPE_MENU
:
1036 case OB_CLIENT_TYPE_TOOLBAR
:
1037 /* these windows get less functionality */
1038 self
->functions
&= ~(OB_CLIENT_FUNC_ICONIFY
| OB_CLIENT_FUNC_RESIZE
);
1041 case OB_CLIENT_TYPE_DESKTOP
:
1042 case OB_CLIENT_TYPE_DOCK
:
1043 case OB_CLIENT_TYPE_SPLASH
:
1044 /* none of these windows are manipulated by the window manager */
1045 self
->decorations
= 0;
1046 self
->functions
= 0;
1050 /* Mwm Hints are applied subtractively to what has already been chosen for
1051 decor and functionality */
1052 if (self
->mwmhints
.flags
& OB_MWM_FLAG_DECORATIONS
) {
1053 if (! (self
->mwmhints
.decorations
& OB_MWM_DECOR_ALL
)) {
1054 if (! ((self
->mwmhints
.decorations
& OB_MWM_DECOR_HANDLE
) ||
1055 (self
->mwmhints
.decorations
& OB_MWM_DECOR_TITLE
)))
1056 /* if the mwm hints request no handle or title, then all
1057 decorations are disabled */
1058 self
->decorations
= 0;
1062 if (self
->mwmhints
.flags
& OB_MWM_FLAG_FUNCTIONS
) {
1063 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_ALL
)) {
1064 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_RESIZE
))
1065 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
1066 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_MOVE
))
1067 self
->functions
&= ~OB_CLIENT_FUNC_MOVE
;
1068 /* dont let mwm hints kill any buttons
1069 if (! (self->mwmhints.functions & OB_MWM_FUNC_ICONIFY))
1070 self->functions &= ~OB_CLIENT_FUNC_ICONIFY;
1071 if (! (self->mwmhints.functions & OB_MWM_FUNC_MAXIMIZE))
1072 self->functions &= ~OB_CLIENT_FUNC_MAXIMIZE;
1074 /* dont let mwm hints kill the close button
1075 if (! (self->mwmhints.functions & MwmFunc_Close))
1076 self->functions &= ~OB_CLIENT_FUNC_CLOSE; */
1080 if (!(self
->functions
& OB_CLIENT_FUNC_SHADE
))
1081 self
->decorations
&= ~OB_FRAME_DECOR_SHADE
;
1082 if (!(self
->functions
& OB_CLIENT_FUNC_ICONIFY
))
1083 self
->decorations
&= ~OB_FRAME_DECOR_ICONIFY
;
1084 if (!(self
->functions
& OB_CLIENT_FUNC_RESIZE
))
1085 self
->decorations
&= ~OB_FRAME_DECOR_GRIPS
;
1087 /* can't maximize without moving/resizing */
1088 if (!((self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) &&
1089 (self
->functions
& OB_CLIENT_FUNC_MOVE
) &&
1090 (self
->functions
& OB_CLIENT_FUNC_RESIZE
))) {
1091 self
->functions
&= ~OB_CLIENT_FUNC_MAXIMIZE
;
1092 self
->decorations
&= ~OB_FRAME_DECOR_MAXIMIZE
;
1095 /* finally, the user can have requested no decorations, which overrides
1097 if (!self
->decorate
)
1098 self
->decorations
= 0;
1100 /* if we don't have a titlebar, then we cannot shade! */
1101 if (!(self
->decorations
& OB_FRAME_DECOR_TITLEBAR
))
1102 self
->functions
&= ~OB_CLIENT_FUNC_SHADE
;
1104 /* now we need to check against rules for the client's current state */
1105 if (self
->fullscreen
) {
1106 self
->functions
&= (OB_CLIENT_FUNC_CLOSE
|
1107 OB_CLIENT_FUNC_FULLSCREEN
|
1108 OB_CLIENT_FUNC_ICONIFY
);
1109 self
->decorations
= 0;
1112 client_change_allowed_actions(self
);
1115 /* this makes sure that these windows appear on all desktops */
1116 if (self
->type
== OB_CLIENT_TYPE_DESKTOP
&&
1117 self
->desktop
!= DESKTOP_ALL
)
1118 client_set_desktop(self
, DESKTOP_ALL
, FALSE
);
1120 /* adjust the client's decorations, etc. */
1121 client_reconfigure(self
);
1123 /* this makes sure that these windows appear on all desktops */
1124 if (self
->type
== OB_CLIENT_TYPE_DESKTOP
&&
1125 self
->desktop
!= DESKTOP_ALL
)
1127 self
->desktop
= DESKTOP_ALL
;
1132 static void client_change_allowed_actions(ObClient
*self
)
1137 /* desktop windows are kept on all desktops */
1138 if (self
->type
!= OB_CLIENT_TYPE_DESKTOP
)
1139 actions
[num
++] = prop_atoms
.net_wm_action_change_desktop
;
1141 if (self
->functions
& OB_CLIENT_FUNC_SHADE
)
1142 actions
[num
++] = prop_atoms
.net_wm_action_shade
;
1143 if (self
->functions
& OB_CLIENT_FUNC_CLOSE
)
1144 actions
[num
++] = prop_atoms
.net_wm_action_close
;
1145 if (self
->functions
& OB_CLIENT_FUNC_MOVE
)
1146 actions
[num
++] = prop_atoms
.net_wm_action_move
;
1147 if (self
->functions
& OB_CLIENT_FUNC_ICONIFY
)
1148 actions
[num
++] = prop_atoms
.net_wm_action_minimize
;
1149 if (self
->functions
& OB_CLIENT_FUNC_RESIZE
)
1150 actions
[num
++] = prop_atoms
.net_wm_action_resize
;
1151 if (self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
)
1152 actions
[num
++] = prop_atoms
.net_wm_action_fullscreen
;
1153 if (self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) {
1154 actions
[num
++] = prop_atoms
.net_wm_action_maximize_horz
;
1155 actions
[num
++] = prop_atoms
.net_wm_action_maximize_vert
;
1158 PROP_SETA32(self
->window
, net_wm_allowed_actions
, atom
, actions
, num
);
1160 /* make sure the window isn't breaking any rules now */
1162 if (!(self
->functions
& OB_CLIENT_FUNC_SHADE
) && self
->shaded
) {
1163 if (self
->frame
) client_shade(self
, FALSE
);
1164 else self
->shaded
= FALSE
;
1166 if (!(self
->functions
& OB_CLIENT_FUNC_ICONIFY
) && self
->iconic
) {
1167 if (self
->frame
) client_iconify(self
, FALSE
, TRUE
);
1168 else self
->iconic
= FALSE
;
1170 if (!(self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
) && self
->fullscreen
) {
1171 if (self
->frame
) client_fullscreen(self
, FALSE
, TRUE
);
1172 else self
->fullscreen
= FALSE
;
1174 if (!(self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) && (self
->max_horz
||
1176 if (self
->frame
) client_maximize(self
, FALSE
, 0, TRUE
);
1177 else self
->max_vert
= self
->max_horz
= FALSE
;
1181 void client_reconfigure(ObClient
*self
)
1183 /* by making this pass FALSE for user, we avoid the emacs event storm where
1184 every configurenotify causes an update in its normal hints, i think this
1185 is generally what we want anyways... */
1186 client_configure(self
, OB_CORNER_TOPLEFT
, self
->area
.x
, self
->area
.y
,
1187 self
->area
.width
, self
->area
.height
, FALSE
, TRUE
);
1190 void client_update_wmhints(ObClient
*self
)
1193 gboolean ur
= FALSE
;
1196 /* assume a window takes input if it doesnt specify */
1197 self
->can_focus
= TRUE
;
1199 if ((hints
= XGetWMHints(ob_display
, self
->window
)) != NULL
) {
1200 if (hints
->flags
& InputHint
)
1201 self
->can_focus
= hints
->input
;
1203 /* only do this when first managing the window *AND* when we aren't
1205 if (ob_state() != OB_STATE_STARTING
&& self
->frame
== NULL
)
1206 if (hints
->flags
& StateHint
)
1207 self
->iconic
= hints
->initial_state
== IconicState
;
1209 if (hints
->flags
& XUrgencyHint
)
1212 if (!(hints
->flags
& WindowGroupHint
))
1213 hints
->window_group
= None
;
1215 /* did the group state change? */
1216 if (hints
->window_group
!=
1217 (self
->group
? self
->group
->leader
: None
)) {
1218 /* remove from the old group if there was one */
1219 if (self
->group
!= NULL
) {
1220 /* remove transients of the group */
1221 for (it
= self
->group
->members
; it
; it
= it
->next
)
1222 self
->transients
= g_slist_remove(self
->transients
,
1224 group_remove(self
->group
, self
);
1227 if (hints
->window_group
!= None
) {
1228 self
->group
= group_add(hints
->window_group
, self
);
1230 /* i can only have transients from the group if i am not
1232 if (!self
->transient_for
) {
1233 /* add other transients of the group that are already
1235 for (it
= self
->group
->members
; it
; it
= it
->next
) {
1236 ObClient
*c
= it
->data
;
1237 if (c
!= self
&& c
->transient_for
== OB_TRAN_GROUP
)
1239 g_slist_append(self
->transients
, c
);
1244 /* the WM_HINTS can contain an icon */
1245 client_update_icons(self
);
1247 /* because the self->transient flag wont change from this call,
1248 we don't need to update the window's type and such, only its
1249 transient_for, and the transients lists of other windows in
1250 the group may be affected */
1251 client_update_transient_for(self
);
1257 if (ur
!= self
->urgent
) {
1259 ob_debug("Urgent Hint for 0x%lx: %s\n", self
->window
,
1261 /* fire the urgent callback if we're mapped, otherwise, wait until
1262 after we're mapped */
1264 dispatch_client(Event_Client_Urgent
, self
, self
->urgent
, 0);
1268 void client_update_title(ObClient
*self
)
1274 gboolean read_title
;
1276 g_free(self
->title
);
1279 if (!PROP_GETS(self
->window
, net_wm_name
, utf8
, &data
))
1280 /* try old x stuff */
1281 if (!PROP_GETS(self
->window
, wm_name
, locale
, &data
))
1282 data
= g_strdup("Unnamed Window");
1284 /* look for duplicates and append a number */
1286 for (it
= client_list
; it
; it
= it
->next
)
1287 if (it
->data
!= self
) {
1288 ObClient
*c
= it
->data
;
1289 if (0 == strncmp(c
->title
, data
, strlen(data
)))
1290 nums
|= 1 << c
->title_count
;
1292 /* find first free number */
1293 for (i
= 1; i
<= 32; ++i
)
1294 if (!(nums
& (1 << i
))) {
1295 if (self
->title_count
== 1 || i
== 1)
1296 self
->title_count
= i
;
1299 /* dont display the number for the first window */
1300 if (self
->title_count
> 1) {
1301 char *vdata
, *ndata
;
1302 ndata
= g_strdup_printf(" - [%u]", self
->title_count
);
1303 vdata
= g_strconcat(data
, ndata
, NULL
);
1309 PROP_SETS(self
->window
, net_wm_visible_name
, data
);
1314 frame_adjust_title(self
->frame
);
1316 /* update the icon title */
1318 g_free(self
->icon_title
);
1322 if (!PROP_GETS(self
->window
, net_wm_icon_name
, utf8
, &data
))
1323 /* try old x stuff */
1324 if (!PROP_GETS(self
->window
, wm_icon_name
, locale
, &data
)) {
1325 data
= g_strdup(self
->title
);
1329 /* append the title count, dont display the number for the first window */
1330 if (read_title
&& self
->title_count
> 1) {
1331 char *vdata
, *ndata
;
1332 ndata
= g_strdup_printf(" - [%u]", self
->title_count
);
1333 vdata
= g_strconcat(data
, ndata
, NULL
);
1339 PROP_SETS(self
->window
, net_wm_visible_icon_name
, data
);
1341 self
->icon_title
= data
;
1344 void client_update_class(ObClient
*self
)
1349 if (self
->name
) g_free(self
->name
);
1350 if (self
->class) g_free(self
->class);
1351 if (self
->role
) g_free(self
->role
);
1353 self
->name
= self
->class = self
->role
= NULL
;
1355 if (PROP_GETSS(self
->window
, wm_class
, locale
, &data
)) {
1357 self
->name
= g_strdup(data
[0]);
1359 self
->class = g_strdup(data
[1]);
1364 if (PROP_GETS(self
->window
, wm_window_role
, locale
, &s
))
1365 self
->role
= g_strdup(s
);
1367 if (self
->name
== NULL
) self
->name
= g_strdup("");
1368 if (self
->class == NULL
) self
->class = g_strdup("");
1369 if (self
->role
== NULL
) self
->role
= g_strdup("");
1372 void client_update_strut(ObClient
*self
)
1377 if (!PROP_GETA32(self
->window
, net_wm_strut
, cardinal
, &data
, &num
)) {
1378 STRUT_SET(self
->strut
, 0, 0, 0, 0);
1381 STRUT_SET(self
->strut
, data
[0], data
[2], data
[1], data
[3]);
1383 STRUT_SET(self
->strut
, 0, 0, 0, 0);
1387 /* updating here is pointless while we're being mapped cuz we're not in
1388 the client list yet */
1390 screen_update_areas();
1393 void client_update_icons(ObClient
*self
)
1399 for (i
= 0; i
< self
->nicons
; ++i
)
1400 g_free(self
->icons
[i
].data
);
1401 if (self
->nicons
> 0)
1402 g_free(self
->icons
);
1405 if (PROP_GETA32(self
->window
, net_wm_icon
, cardinal
, &data
, &num
)) {
1406 /* figure out how many valid icons are in here */
1408 while (num
- i
> 2) {
1412 if (i
> num
|| w
*h
== 0) break;
1416 self
->icons
= g_new(ObClientIcon
, self
->nicons
);
1418 /* store the icons */
1420 for (j
= 0; j
< self
->nicons
; ++j
) {
1423 w
= self
->icons
[j
].width
= data
[i
++];
1424 h
= self
->icons
[j
].height
= data
[i
++];
1426 if (w
*h
== 0) continue;
1428 self
->icons
[j
].data
= g_new(RrPixel32
, w
* h
);
1429 for (x
= 0, y
= 0, t
= 0; t
< w
* h
; ++t
, ++x
, ++i
) {
1434 self
->icons
[j
].data
[t
] =
1435 (((data
[i
] >> 24) & 0xff) << RrDefaultAlphaOffset
) +
1436 (((data
[i
] >> 16) & 0xff) << RrDefaultRedOffset
) +
1437 (((data
[i
] >> 8) & 0xff) << RrDefaultGreenOffset
) +
1438 (((data
[i
] >> 0) & 0xff) << RrDefaultBlueOffset
);
1444 } else if (PROP_GETA32(self
->window
, kwm_win_icon
,
1445 kwm_win_icon
, &data
, &num
)) {
1448 self
->icons
= g_new(ObClientIcon
, self
->nicons
);
1449 xerror_set_ignore(TRUE
);
1450 if (!RrPixmapToRGBA(ob_rr_inst
,
1452 &self
->icons
[self
->nicons
-1].width
,
1453 &self
->icons
[self
->nicons
-1].height
,
1454 &self
->icons
[self
->nicons
-1].data
)) {
1455 g_free(&self
->icons
[self
->nicons
-1]);
1458 xerror_set_ignore(FALSE
);
1464 if ((hints
= XGetWMHints(ob_display
, self
->window
))) {
1465 if (hints
->flags
& IconPixmapHint
) {
1467 self
->icons
= g_new(ObClientIcon
, self
->nicons
);
1468 xerror_set_ignore(TRUE
);
1469 if (!RrPixmapToRGBA(ob_rr_inst
,
1471 (hints
->flags
& IconMaskHint
?
1472 hints
->icon_mask
: None
),
1473 &self
->icons
[self
->nicons
-1].width
,
1474 &self
->icons
[self
->nicons
-1].height
,
1475 &self
->icons
[self
->nicons
-1].data
)){
1476 g_free(&self
->icons
[self
->nicons
-1]);
1479 xerror_set_ignore(FALSE
);
1486 frame_adjust_icon(self
->frame
);
1489 static void client_change_state(ObClient
*self
)
1492 guint32 netstate
[10];
1495 state
[0] = self
->wmstate
;
1497 PROP_SETA32(self
->window
, wm_state
, wm_state
, state
, 2);
1501 netstate
[num
++] = prop_atoms
.net_wm_state_modal
;
1503 netstate
[num
++] = prop_atoms
.net_wm_state_shaded
;
1505 netstate
[num
++] = prop_atoms
.net_wm_state_hidden
;
1506 if (self
->skip_taskbar
)
1507 netstate
[num
++] = prop_atoms
.net_wm_state_skip_taskbar
;
1508 if (self
->skip_pager
)
1509 netstate
[num
++] = prop_atoms
.net_wm_state_skip_pager
;
1510 if (self
->fullscreen
)
1511 netstate
[num
++] = prop_atoms
.net_wm_state_fullscreen
;
1513 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_vert
;
1515 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_horz
;
1517 netstate
[num
++] = prop_atoms
.net_wm_state_above
;
1519 netstate
[num
++] = prop_atoms
.net_wm_state_below
;
1520 PROP_SETA32(self
->window
, net_wm_state
, atom
, netstate
, num
);
1522 client_calc_layer(self
);
1525 frame_adjust_state(self
->frame
);
1528 ObClient
*client_search_focus_tree(ObClient
*self
)
1533 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
) {
1534 if (client_focused(it
->data
)) return it
->data
;
1535 if ((ret
= client_search_focus_tree(it
->data
))) return ret
;
1540 ObClient
*client_search_focus_tree_full(ObClient
*self
)
1542 if (self
->transient_for
) {
1543 if (self
->transient_for
!= OB_TRAN_GROUP
) {
1544 return client_search_focus_tree_full(self
->transient_for
);
1547 gboolean recursed
= FALSE
;
1549 for (it
= self
->group
->members
; it
; it
= it
->next
)
1550 if (!((ObClient
*)it
->data
)->transient_for
) {
1552 if ((c
= client_search_focus_tree_full(it
->data
)))
1561 /* this function checks the whole tree, the client_search_focus_tree~
1562 does not, so we need to check this window */
1563 if (client_focused(self
))
1565 return client_search_focus_tree(self
);
1568 static ObStackingLayer
calc_layer(ObClient
*self
)
1572 if (self
->fullscreen
) l
= OB_STACKING_LAYER_FULLSCREEN
;
1573 else if (self
->type
== OB_CLIENT_TYPE_DESKTOP
)
1574 l
= OB_STACKING_LAYER_DESKTOP
;
1575 else if (self
->type
== OB_CLIENT_TYPE_DOCK
) {
1576 if (!self
->below
) l
= OB_STACKING_LAYER_TOP
;
1577 else l
= OB_STACKING_LAYER_NORMAL
;
1579 else if (self
->above
) l
= OB_STACKING_LAYER_ABOVE
;
1580 else if (self
->below
) l
= OB_STACKING_LAYER_BELOW
;
1581 else l
= OB_STACKING_LAYER_NORMAL
;
1586 static void client_calc_layer_recursive(ObClient
*self
, ObClient
*orig
,
1587 ObStackingLayer l
, gboolean raised
)
1589 ObStackingLayer old
, own
;
1593 own
= calc_layer(self
);
1594 self
->layer
= l
> own
? l
: own
;
1596 for (it
= self
->transients
; it
; it
= it
->next
)
1597 client_calc_layer_recursive(it
->data
, orig
,
1598 l
, raised
? raised
: l
!= old
);
1600 if (!raised
&& l
!= old
)
1601 if (orig
->frame
) { /* only restack if the original window is managed */
1602 /* XXX add_non_intrusive ever? */
1603 stacking_remove(CLIENT_AS_WINDOW(self
));
1604 stacking_add(CLIENT_AS_WINDOW(self
));
1608 void client_calc_layer(ObClient
*self
)
1615 /* transients take on the layer of their parents */
1616 self
= client_search_top_transient(self
);
1618 l
= calc_layer(self
);
1620 client_calc_layer_recursive(self
, orig
, l
, FALSE
);
1623 gboolean
client_should_show(ObClient
*self
)
1625 if (self
->iconic
) return FALSE
;
1626 else if (!(self
->desktop
== screen_desktop
||
1627 self
->desktop
== DESKTOP_ALL
)) return FALSE
;
1628 else if (client_normal(self
) && screen_showing_desktop
) return FALSE
;
1633 static void client_showhide(ObClient
*self
)
1636 if (client_should_show(self
))
1637 frame_show(self
->frame
);
1639 frame_hide(self
->frame
);
1642 gboolean
client_normal(ObClient
*self
) {
1643 return ! (self
->type
== OB_CLIENT_TYPE_DESKTOP
||
1644 self
->type
== OB_CLIENT_TYPE_DOCK
||
1645 self
->type
== OB_CLIENT_TYPE_SPLASH
);
1648 static void client_apply_startup_state(ObClient
*self
)
1650 /* these are in a carefully crafted order.. */
1653 self
->iconic
= FALSE
;
1654 client_iconify(self
, TRUE
, FALSE
);
1656 if (self
->fullscreen
) {
1657 self
->fullscreen
= FALSE
;
1658 client_fullscreen(self
, TRUE
, FALSE
);
1661 self
->shaded
= FALSE
;
1662 client_shade(self
, TRUE
);
1665 dispatch_client(Event_Client_Urgent
, self
, self
->urgent
, 0);
1667 if (self
->max_vert
&& self
->max_horz
) {
1668 self
->max_vert
= self
->max_horz
= FALSE
;
1669 client_maximize(self
, TRUE
, 0, FALSE
);
1670 } else if (self
->max_vert
) {
1671 self
->max_vert
= FALSE
;
1672 client_maximize(self
, TRUE
, 2, FALSE
);
1673 } else if (self
->max_horz
) {
1674 self
->max_horz
= FALSE
;
1675 client_maximize(self
, TRUE
, 1, FALSE
);
1678 /* nothing to do for the other states:
1687 void client_configure_full(ObClient
*self
, ObCorner anchor
,
1688 int x
, int y
, int w
, int h
,
1689 gboolean user
, gboolean final
,
1690 gboolean force_reply
)
1692 gboolean moved
= FALSE
, resized
= FALSE
;
1694 /* gets the frame's position */
1695 frame_client_gravity(self
->frame
, &x
, &y
);
1697 /* these positions are frame positions, not client positions */
1699 /* set the size and position if fullscreen */
1700 if (self
->fullscreen
) {
1703 XF86VidModeModeLine mode
;
1708 i
= client_monitor(self
);
1709 a
= screen_physical_area_monitor(i
);
1712 if (i
== 0 && /* primary head */
1713 extensions_vidmode
&&
1714 XF86VidModeGetViewPort(ob_display
, ob_screen
, &x
, &y
) &&
1715 /* get the mode last so the mode.privsize isnt freed incorrectly */
1716 XF86VidModeGetModeLine(ob_display
, ob_screen
, &dot
, &mode
)) {
1721 if (mode
.privsize
) XFree(mode
.private);
1731 user
= FALSE
; /* ignore that increment etc shit when in fullscreen */
1735 a
= screen_area_monitor(self
->desktop
, client_monitor(self
));
1737 /* set the size and position if maximized */
1738 if (self
->max_horz
) {
1739 x
= a
->x
- self
->frame
->size
.left
;
1742 if (self
->max_vert
) {
1744 h
= a
->height
- self
->frame
->size
.top
- self
->frame
->size
.bottom
;
1748 /* gets the client's position */
1749 frame_frame_gravity(self
->frame
, &x
, &y
);
1751 /* these override the above states! if you cant move you can't move! */
1753 if (!(self
->functions
& OB_CLIENT_FUNC_MOVE
)) {
1757 if (!(self
->functions
& OB_CLIENT_FUNC_RESIZE
)) {
1758 w
= self
->area
.width
;
1759 h
= self
->area
.height
;
1763 if (!(w
== self
->area
.width
&& h
== self
->area
.height
)) {
1764 int basew
, baseh
, minw
, minh
;
1766 /* base size is substituted with min size if not specified */
1767 if (self
->base_size
.width
|| self
->base_size
.height
) {
1768 basew
= self
->base_size
.width
;
1769 baseh
= self
->base_size
.height
;
1771 basew
= self
->min_size
.width
;
1772 baseh
= self
->min_size
.height
;
1774 /* min size is substituted with base size if not specified */
1775 if (self
->min_size
.width
|| self
->min_size
.height
) {
1776 minw
= self
->min_size
.width
;
1777 minh
= self
->min_size
.height
;
1779 minw
= self
->base_size
.width
;
1780 minh
= self
->base_size
.height
;
1784 /* for interactive resizing. have to move half an increment in each
1787 /* how far we are towards the next size inc */
1788 int mw
= (w
- basew
) % self
->size_inc
.width
;
1789 int mh
= (h
- baseh
) % self
->size_inc
.height
;
1791 int aw
= self
->size_inc
.width
/ 2;
1792 int ah
= self
->size_inc
.height
/ 2;
1793 /* don't let us move into a new size increment */
1794 if (mw
+ aw
>= self
->size_inc
.width
)
1795 aw
= self
->size_inc
.width
- mw
- 1;
1796 if (mh
+ ah
>= self
->size_inc
.height
)
1797 ah
= self
->size_inc
.height
- mh
- 1;
1801 /* if this is a user-requested resize, then check against min/max
1804 /* smaller than min size or bigger than max size? */
1805 if (w
> self
->max_size
.width
) w
= self
->max_size
.width
;
1806 if (w
< minw
) w
= minw
;
1807 if (h
> self
->max_size
.height
) h
= self
->max_size
.height
;
1808 if (h
< minh
) h
= minh
;
1814 /* keep to the increments */
1815 w
/= self
->size_inc
.width
;
1816 h
/= self
->size_inc
.height
;
1818 /* you cannot resize to nothing */
1819 if (basew
+ w
< 1) w
= 1 - basew
;
1820 if (baseh
+ h
< 1) h
= 1 - baseh
;
1822 /* store the logical size */
1823 SIZE_SET(self
->logical_size
,
1824 self
->size_inc
.width
> 1 ? w
: w
+ basew
,
1825 self
->size_inc
.height
> 1 ? h
: h
+ baseh
);
1827 w
*= self
->size_inc
.width
;
1828 h
*= self
->size_inc
.height
;
1834 /* adjust the height to match the width for the aspect ratios.
1835 for this, min size is not substituted for base size ever. */
1836 w
-= self
->base_size
.width
;
1837 h
-= self
->base_size
.height
;
1839 if (self
->min_ratio
)
1840 if (h
* self
->min_ratio
> w
) h
= (int)(w
/ self
->min_ratio
);
1841 if (self
->max_ratio
)
1842 if (h
* self
->max_ratio
< w
) h
= (int)(w
/ self
->max_ratio
);
1844 w
+= self
->base_size
.width
;
1845 h
+= self
->base_size
.height
;
1850 case OB_CORNER_TOPLEFT
:
1852 case OB_CORNER_TOPRIGHT
:
1853 x
-= w
- self
->area
.width
;
1855 case OB_CORNER_BOTTOMLEFT
:
1856 y
-= h
- self
->area
.height
;
1858 case OB_CORNER_BOTTOMRIGHT
:
1859 x
-= w
- self
->area
.width
;
1860 y
-= h
- self
->area
.height
;
1864 moved
= x
!= self
->area
.x
|| y
!= self
->area
.y
;
1865 resized
= w
!= self
->area
.width
|| h
!= self
->area
.height
;
1867 RECT_SET(self
->area
, x
, y
, w
, h
);
1869 /* for app-requested resizes, always resize if 'resized' is true.
1870 for user-requested ones, only resize if final is true, or when
1871 resizing in opaque mode */
1872 if ((!user
&& resized
) ||
1873 (user
&& (final
|| (resized
&& config_opaque_resize
))))
1874 XResizeWindow(ob_display
, self
->window
, w
, h
);
1876 /* move/resize the frame to match the request */
1878 if (self
->decorations
!= self
->frame
->decorations
)
1879 moved
= resized
= TRUE
;
1881 if (moved
|| resized
)
1882 frame_adjust_area(self
->frame
, moved
, resized
);
1884 if (!resized
&& (force_reply
|| ((!user
&& moved
) || (user
&& final
))))
1887 event
.type
= ConfigureNotify
;
1888 event
.xconfigure
.display
= ob_display
;
1889 event
.xconfigure
.event
= self
->window
;
1890 event
.xconfigure
.window
= self
->window
;
1892 /* root window real coords */
1893 event
.xconfigure
.x
= self
->frame
->area
.x
+ self
->frame
->size
.left
-
1895 event
.xconfigure
.y
= self
->frame
->area
.y
+ self
->frame
->size
.top
-
1897 event
.xconfigure
.width
= w
;
1898 event
.xconfigure
.height
= h
;
1899 event
.xconfigure
.border_width
= 0;
1900 event
.xconfigure
.above
= self
->frame
->plate
;
1901 event
.xconfigure
.override_redirect
= FALSE
;
1902 XSendEvent(event
.xconfigure
.display
, event
.xconfigure
.window
,
1903 FALSE
, StructureNotifyMask
, &event
);
1908 void client_fullscreen(ObClient
*self
, gboolean fs
, gboolean savearea
)
1912 if (!(self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
) || /* can't */
1913 self
->fullscreen
== fs
) return; /* already done */
1915 self
->fullscreen
= fs
;
1916 client_change_state(self
); /* change the state hints on the client,
1917 and adjust out layer/stacking */
1921 guint32 dimensions
[4];
1922 dimensions
[0] = self
->area
.x
;
1923 dimensions
[1] = self
->area
.y
;
1924 dimensions
[2] = self
->area
.width
;
1925 dimensions
[3] = self
->area
.height
;
1927 PROP_SETA32(self
->window
, openbox_premax
, cardinal
,
1931 /* these are not actually used cuz client_configure will set them
1932 as appropriate when the window is fullscreened */
1939 /* pick some fallbacks... */
1940 a
= screen_area_monitor(self
->desktop
, 0);
1941 x
= a
->x
+ a
->width
/ 4;
1942 y
= a
->y
+ a
->height
/ 4;
1946 if (PROP_GETA32(self
->window
, openbox_premax
, cardinal
,
1947 (guint32
**)&dimensions
, &num
)) {
1958 client_setup_decor_and_functions(self
);
1960 client_configure(self
, OB_CORNER_TOPLEFT
, x
, y
, w
, h
, TRUE
, TRUE
);
1962 /* try focus us when we go into fullscreen mode */
1966 static void client_iconify_recursive(ObClient
*self
,
1967 gboolean iconic
, gboolean curdesk
)
1970 gboolean changed
= FALSE
;
1973 if (self
->iconic
!= iconic
) {
1974 ob_debug("%sconifying window: 0x%lx\n", (iconic
? "I" : "Uni"),
1977 self
->iconic
= iconic
;
1980 if (self
->functions
& OB_CLIENT_FUNC_ICONIFY
) {
1981 self
->wmstate
= IconicState
;
1982 self
->ignore_unmaps
++;
1983 /* we unmap the client itself so that we can get MapRequest
1984 events, and because the ICCCM tells us to! */
1985 XUnmapWindow(ob_display
, self
->window
);
1987 /* update the focus lists.. iconic windows go to the bottom of
1988 the list, put the new iconic window at the 'top of the
1990 focus_order_to_top(self
);
1996 client_set_desktop(self
, screen_desktop
, FALSE
);
1997 self
->wmstate
= self
->shaded
? IconicState
: NormalState
;
1998 XMapWindow(ob_display
, self
->window
);
2000 /* this puts it after the current focused window */
2001 focus_order_remove(self
);
2002 focus_order_add_new(self
);
2004 /* this is here cuz with the VIDMODE extension, the viewport can
2005 change while a fullscreen window is iconic, and when it
2006 uniconifies, it would be nice if it did so to the new position
2008 client_reconfigure(self
);
2015 client_change_state(self
);
2016 client_showhide(self
);
2017 screen_update_areas();
2019 dispatch_client(iconic
? Event_Client_Unmapped
: Event_Client_Mapped
,
2023 /* iconify all transients */
2024 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
)
2025 if (it
->data
!= self
) client_iconify_recursive(it
->data
,
2029 void client_iconify(ObClient
*self
, gboolean iconic
, gboolean curdesk
)
2031 /* move up the transient chain as far as possible first */
2032 self
= client_search_top_transient(self
);
2034 client_iconify_recursive(client_search_top_transient(self
),
2038 void client_maximize(ObClient
*self
, gboolean max
, int dir
, gboolean savearea
)
2042 g_assert(dir
== 0 || dir
== 1 || dir
== 2);
2043 if (!(self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
)) return; /* can't */
2045 /* check if already done */
2047 if (dir
== 0 && self
->max_horz
&& self
->max_vert
) return;
2048 if (dir
== 1 && self
->max_horz
) return;
2049 if (dir
== 2 && self
->max_vert
) return;
2051 if (dir
== 0 && !self
->max_horz
&& !self
->max_vert
) return;
2052 if (dir
== 1 && !self
->max_horz
) return;
2053 if (dir
== 2 && !self
->max_vert
) return;
2056 /* work with the frame's coords */
2057 x
= self
->frame
->area
.x
;
2058 y
= self
->frame
->area
.y
;
2059 w
= self
->area
.width
;
2060 h
= self
->area
.height
;
2064 gint32 dimensions
[4];
2073 /* get the property off the window and use it for the dimensions
2074 we are already maxed on */
2075 if (PROP_GETA32(self
->window
, openbox_premax
, cardinal
,
2076 (guint32
**)&readdim
, &num
)) {
2078 if (self
->max_horz
) {
2079 dimensions
[0] = readdim
[0];
2080 dimensions
[2] = readdim
[2];
2082 if (self
->max_vert
) {
2083 dimensions
[1] = readdim
[1];
2084 dimensions
[3] = readdim
[3];
2090 PROP_SETA32(self
->window
, openbox_premax
, cardinal
,
2091 (guint32
*)dimensions
, 4);
2098 /* pick some fallbacks... */
2099 a
= screen_area_monitor(self
->desktop
, 0);
2100 if (dir
== 0 || dir
== 1) { /* horz */
2101 x
= a
->x
+ a
->width
/ 4;
2104 if (dir
== 0 || dir
== 2) { /* vert */
2105 y
= a
->y
+ a
->height
/ 4;
2109 if (PROP_GETA32(self
->window
, openbox_premax
, cardinal
,
2110 (guint32
**)&dimensions
, &num
)) {
2112 if (dir
== 0 || dir
== 1) { /* horz */
2116 if (dir
== 0 || dir
== 2) { /* vert */
2125 if (dir
== 0 || dir
== 1) /* horz */
2126 self
->max_horz
= max
;
2127 if (dir
== 0 || dir
== 2) /* vert */
2128 self
->max_vert
= max
;
2130 if (!self
->max_horz
&& !self
->max_vert
)
2131 PROP_ERASE(self
->window
, openbox_premax
);
2133 client_change_state(self
); /* change the state hints on the client */
2135 /* figure out where the client should be going */
2136 frame_frame_gravity(self
->frame
, &x
, &y
);
2137 client_configure(self
, OB_CORNER_TOPLEFT
, x
, y
, w
, h
, TRUE
, TRUE
);
2140 void client_shade(ObClient
*self
, gboolean shade
)
2142 if ((!(self
->functions
& OB_CLIENT_FUNC_SHADE
) &&
2143 shade
) || /* can't shade */
2144 self
->shaded
== shade
) return; /* already done */
2146 /* when we're iconic, don't change the wmstate */
2148 self
->wmstate
= shade
? IconicState
: NormalState
;
2149 self
->shaded
= shade
;
2150 client_change_state(self
);
2151 /* resize the frame to just the titlebar */
2152 frame_adjust_area(self
->frame
, FALSE
, FALSE
);
2155 void client_close(ObClient
*self
)
2159 if (!(self
->functions
& OB_CLIENT_FUNC_CLOSE
)) return;
2162 XXX: itd be cool to do timeouts and shit here for killing the client's
2164 like... if the window is around after 5 seconds, then the close button
2165 turns a nice red, and if this function is called again, the client is
2169 ce
.xclient
.type
= ClientMessage
;
2170 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
2171 ce
.xclient
.display
= ob_display
;
2172 ce
.xclient
.window
= self
->window
;
2173 ce
.xclient
.format
= 32;
2174 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_delete_window
;
2175 ce
.xclient
.data
.l
[1] = event_lasttime
;
2176 ce
.xclient
.data
.l
[2] = 0l;
2177 ce
.xclient
.data
.l
[3] = 0l;
2178 ce
.xclient
.data
.l
[4] = 0l;
2179 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
2182 void client_kill(ObClient
*self
)
2184 XKillClient(ob_display
, self
->window
);
2187 void client_set_desktop_recursive(ObClient
*self
,
2188 guint target
, gboolean donthide
)
2193 if (target
!= self
->desktop
) {
2195 ob_debug("Setting desktop %u\n", target
+1);
2197 g_assert(target
< screen_num_desktops
|| target
== DESKTOP_ALL
);
2199 /* remove from the old desktop(s) */
2200 focus_order_remove(self
);
2202 old
= self
->desktop
;
2203 self
->desktop
= target
;
2204 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, target
);
2205 /* the frame can display the current desktop state */
2206 frame_adjust_state(self
->frame
);
2207 /* 'move' the window to the new desktop */
2209 client_showhide(self
);
2210 /* raise if it was not already on the desktop */
2211 if (old
!= DESKTOP_ALL
)
2212 stacking_raise(CLIENT_AS_WINDOW(self
));
2213 screen_update_areas();
2215 /* add to the new desktop(s) */
2216 if (config_focus_new
)
2217 focus_order_to_top(self
);
2219 focus_order_to_bottom(self
);
2221 dispatch_client(Event_Client_Desktop
, self
, target
, old
);
2224 /* move all transients */
2225 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
)
2226 if (it
->data
!= self
) client_set_desktop_recursive(it
->data
,
2230 void client_set_desktop(ObClient
*self
, guint target
, gboolean donthide
)
2232 client_set_desktop_recursive(client_search_top_transient(self
),
2236 ObClient
*client_search_modal_child(ObClient
*self
)
2241 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
) {
2242 ObClient
*c
= it
->data
;
2243 if ((ret
= client_search_modal_child(c
))) return ret
;
2244 if (c
->modal
) return c
;
2249 gboolean
client_validate(ObClient
*self
)
2253 XSync(ob_display
, FALSE
); /* get all events on the server */
2255 if (XCheckTypedWindowEvent(ob_display
, self
->window
, DestroyNotify
, &e
) ||
2256 XCheckTypedWindowEvent(ob_display
, self
->window
, UnmapNotify
, &e
)) {
2257 XPutBackEvent(ob_display
, &e
);
2264 void client_set_wm_state(ObClient
*self
, long state
)
2266 if (state
== self
->wmstate
) return; /* no change */
2270 client_iconify(self
, TRUE
, TRUE
);
2273 client_iconify(self
, FALSE
, TRUE
);
2278 void client_set_state(ObClient
*self
, Atom action
, long data1
, long data2
)
2280 gboolean shaded
= self
->shaded
;
2281 gboolean fullscreen
= self
->fullscreen
;
2282 gboolean max_horz
= self
->max_horz
;
2283 gboolean max_vert
= self
->max_vert
;
2286 if (!(action
== prop_atoms
.net_wm_state_add
||
2287 action
== prop_atoms
.net_wm_state_remove
||
2288 action
== prop_atoms
.net_wm_state_toggle
))
2289 /* an invalid action was passed to the client message, ignore it */
2292 for (i
= 0; i
< 2; ++i
) {
2293 Atom state
= i
== 0 ? data1
: data2
;
2295 if (!state
) continue;
2297 /* if toggling, then pick whether we're adding or removing */
2298 if (action
== prop_atoms
.net_wm_state_toggle
) {
2299 if (state
== prop_atoms
.net_wm_state_modal
)
2300 action
= self
->modal
? prop_atoms
.net_wm_state_remove
:
2301 prop_atoms
.net_wm_state_add
;
2302 else if (state
== prop_atoms
.net_wm_state_maximized_vert
)
2303 action
= self
->max_vert
? prop_atoms
.net_wm_state_remove
:
2304 prop_atoms
.net_wm_state_add
;
2305 else if (state
== prop_atoms
.net_wm_state_maximized_horz
)
2306 action
= self
->max_horz
? prop_atoms
.net_wm_state_remove
:
2307 prop_atoms
.net_wm_state_add
;
2308 else if (state
== prop_atoms
.net_wm_state_shaded
)
2309 action
= self
->shaded
? prop_atoms
.net_wm_state_remove
:
2310 prop_atoms
.net_wm_state_add
;
2311 else if (state
== prop_atoms
.net_wm_state_skip_taskbar
)
2312 action
= self
->skip_taskbar
?
2313 prop_atoms
.net_wm_state_remove
:
2314 prop_atoms
.net_wm_state_add
;
2315 else if (state
== prop_atoms
.net_wm_state_skip_pager
)
2316 action
= self
->skip_pager
?
2317 prop_atoms
.net_wm_state_remove
:
2318 prop_atoms
.net_wm_state_add
;
2319 else if (state
== prop_atoms
.net_wm_state_fullscreen
)
2320 action
= self
->fullscreen
?
2321 prop_atoms
.net_wm_state_remove
:
2322 prop_atoms
.net_wm_state_add
;
2323 else if (state
== prop_atoms
.net_wm_state_above
)
2324 action
= self
->above
? prop_atoms
.net_wm_state_remove
:
2325 prop_atoms
.net_wm_state_add
;
2326 else if (state
== prop_atoms
.net_wm_state_below
)
2327 action
= self
->below
? prop_atoms
.net_wm_state_remove
:
2328 prop_atoms
.net_wm_state_add
;
2331 if (action
== prop_atoms
.net_wm_state_add
) {
2332 if (state
== prop_atoms
.net_wm_state_modal
) {
2333 /* XXX raise here or something? */
2335 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
2337 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
2339 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
2341 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
2342 self
->skip_taskbar
= TRUE
;
2343 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
2344 self
->skip_pager
= TRUE
;
2345 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
2347 } else if (state
== prop_atoms
.net_wm_state_above
) {
2349 } else if (state
== prop_atoms
.net_wm_state_below
) {
2353 } else { /* action == prop_atoms.net_wm_state_remove */
2354 if (state
== prop_atoms
.net_wm_state_modal
) {
2355 self
->modal
= FALSE
;
2356 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
2358 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
2360 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
2362 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
2363 self
->skip_taskbar
= FALSE
;
2364 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
2365 self
->skip_pager
= FALSE
;
2366 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
2368 } else if (state
== prop_atoms
.net_wm_state_above
) {
2369 self
->above
= FALSE
;
2370 } else if (state
== prop_atoms
.net_wm_state_below
) {
2371 self
->below
= FALSE
;
2375 if (max_horz
!= self
->max_horz
|| max_vert
!= self
->max_vert
) {
2376 if (max_horz
!= self
->max_horz
&& max_vert
!= self
->max_vert
) {
2378 if (max_horz
== max_vert
) { /* both going the same way */
2379 client_maximize(self
, max_horz
, 0, TRUE
);
2381 client_maximize(self
, max_horz
, 1, TRUE
);
2382 client_maximize(self
, max_vert
, 2, TRUE
);
2386 if (max_horz
!= self
->max_horz
)
2387 client_maximize(self
, max_horz
, 1, TRUE
);
2389 client_maximize(self
, max_vert
, 2, TRUE
);
2392 /* change fullscreen state before shading, as it will affect if the window
2394 if (fullscreen
!= self
->fullscreen
)
2395 client_fullscreen(self
, fullscreen
, TRUE
);
2396 if (shaded
!= self
->shaded
)
2397 client_shade(self
, shaded
);
2398 client_calc_layer(self
);
2399 client_change_state(self
); /* change the hint to reflect these changes */
2402 ObClient
*client_focus_target(ObClient
*self
)
2406 /* if we have a modal child, then focus it, not us */
2407 child
= client_search_modal_child(self
);
2408 if (child
) return child
;
2412 gboolean
client_can_focus(ObClient
*self
)
2416 /* choose the correct target */
2417 self
= client_focus_target(self
);
2419 if (!self
->frame
->visible
)
2422 if (!((self
->can_focus
|| self
->focus_notify
) &&
2423 (self
->desktop
== screen_desktop
||
2424 self
->desktop
== DESKTOP_ALL
) &&
2428 /* do a check to see if the window has already been unmapped or destroyed
2429 do this intelligently while watching out for unmaps we've generated
2430 (ignore_unmaps > 0) */
2431 if (XCheckTypedWindowEvent(ob_display
, self
->window
,
2432 DestroyNotify
, &ev
)) {
2433 XPutBackEvent(ob_display
, &ev
);
2436 while (XCheckTypedWindowEvent(ob_display
, self
->window
,
2437 UnmapNotify
, &ev
)) {
2438 if (self
->ignore_unmaps
) {
2439 self
->ignore_unmaps
--;
2441 XPutBackEvent(ob_display
, &ev
);
2449 gboolean
client_focus(ObClient
*self
)
2451 /* choose the correct target */
2452 self
= client_focus_target(self
);
2454 if (!client_can_focus(self
)) {
2455 if (!self
->frame
->visible
) {
2456 /* update the focus lists */
2457 focus_order_to_top(self
);
2462 if (self
->can_focus
)
2463 /* RevertToPointerRoot causes much more headache than RevertToNone, so
2464 I choose to use it always, hopefully to find errors quicker, if any
2465 are left. (I hate X. I hate focus events.) */
2466 XSetInputFocus(ob_display
, self
->window
, RevertToPointerRoot
,
2469 if (self
->focus_notify
) {
2471 ce
.xclient
.type
= ClientMessage
;
2472 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
2473 ce
.xclient
.display
= ob_display
;
2474 ce
.xclient
.window
= self
->window
;
2475 ce
.xclient
.format
= 32;
2476 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_take_focus
;
2477 ce
.xclient
.data
.l
[1] = event_lasttime
;
2478 ce
.xclient
.data
.l
[2] = 0l;
2479 ce
.xclient
.data
.l
[3] = 0l;
2480 ce
.xclient
.data
.l
[4] = 0l;
2481 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
2485 ob_debug("%sively focusing %lx at %d\n",
2486 (self
->can_focus
? "act" : "pass"),
2487 self
->window
, (int) event_lasttime
);
2490 /* Cause the FocusIn to come back to us. Important for desktop switches,
2491 since otherwise we'll have no FocusIn on the queue and send it off to
2492 the focus_backup. */
2493 XSync(ob_display
, FALSE
);
2497 void client_unfocus(ObClient
*self
)
2499 g_assert(focus_client
== self
);
2501 ob_debug("client_unfocus for %lx\n", self
->window
);
2503 focus_fallback(OB_FOCUS_FALLBACK_UNFOCUSING
);
2506 void client_activate(ObClient
*self
)
2508 if (client_normal(self
) && screen_showing_desktop
)
2509 screen_show_desktop(FALSE
);
2511 client_iconify(self
, FALSE
, FALSE
);
2512 if (self
->desktop
!= DESKTOP_ALL
&&
2513 self
->desktop
!= screen_desktop
)
2514 screen_set_desktop(self
->desktop
);
2515 else if (!self
->frame
->visible
)
2516 /* if its not visible for other reasons, then don't mess
2520 client_shade(self
, FALSE
);
2522 stacking_raise(CLIENT_AS_WINDOW(self
));
2525 gboolean
client_focused(ObClient
*self
)
2527 return self
== focus_client
;
2530 ObClientIcon
*client_icon(ObClient
*self
, int w
, int h
)
2533 /* si is the smallest image >= req */
2534 /* li is the largest image < req */
2535 unsigned long size
, smallest
= 0xffffffff, largest
= 0, si
= 0, li
= 0;
2537 if (!self
->nicons
) return NULL
;
2539 for (i
= 0; i
< self
->nicons
; ++i
) {
2540 size
= self
->icons
[i
].width
* self
->icons
[i
].height
;
2541 if (size
< smallest
&& size
>= (unsigned)(w
* h
)) {
2545 if (size
> largest
&& size
<= (unsigned)(w
* h
)) {
2550 if (largest
== 0) /* didnt find one smaller than the requested size */
2551 return &self
->icons
[si
];
2552 return &self
->icons
[li
];
2555 /* this be mostly ripped from fvwm */
2556 ObClient
*client_find_directional(ObClient
*c
, ObDirection dir
)
2558 int my_cx
, my_cy
, his_cx
, his_cy
;
2561 int score
, best_score
;
2562 ObClient
*best_client
, *cur
;
2568 /* first, find the centre coords of the currently focused window */
2569 my_cx
= c
->frame
->area
.x
+ c
->frame
->area
.width
/ 2;
2570 my_cy
= c
->frame
->area
.y
+ c
->frame
->area
.height
/ 2;
2575 for(it
= g_list_first(client_list
); it
; it
= it
->next
) {
2578 /* the currently selected window isn't interesting */
2581 if (!client_normal(cur
))
2583 if(c
->desktop
!= cur
->desktop
&& cur
->desktop
!= DESKTOP_ALL
)
2587 if(client_focus_target(cur
) == cur
&&
2588 !(cur
->can_focus
|| cur
->focus_notify
))
2591 /* find the centre coords of this window, from the
2592 * currently focused window's point of view */
2593 his_cx
= (cur
->frame
->area
.x
- my_cx
)
2594 + cur
->frame
->area
.width
/ 2;
2595 his_cy
= (cur
->frame
->area
.y
- my_cy
)
2596 + cur
->frame
->area
.height
/ 2;
2600 /* Rotate the diagonals 45 degrees counterclockwise.
2601 * To do this, multiply the matrix /+h +h\ with the
2602 * vector (x y). \-h +h/
2603 * h = sqrt(0.5). We can set h := 1 since absolute
2604 * distance doesn't matter here. */
2605 tx
= his_cx
+ his_cy
;
2606 his_cy
= -his_cx
+ his_cy
;
2611 case OB_DIRECTION_NORTH
:
2612 case OB_DIRECTION_SOUTH
:
2613 case OB_DIRECTION_NORTHEAST
:
2614 case OB_DIRECTION_SOUTHWEST
:
2615 offset
= (his_cx
< 0) ? -his_cx
: his_cx
;
2616 distance
= ((dir
== OB_DIRECTION_NORTH
||
2617 dir
== OB_DIRECTION_NORTHEAST
) ?
2620 case OB_DIRECTION_EAST
:
2621 case OB_DIRECTION_WEST
:
2622 case OB_DIRECTION_SOUTHEAST
:
2623 case OB_DIRECTION_NORTHWEST
:
2624 offset
= (his_cy
< 0) ? -his_cy
: his_cy
;
2625 distance
= ((dir
== OB_DIRECTION_WEST
||
2626 dir
== OB_DIRECTION_NORTHWEST
) ?
2631 /* the target must be in the requested direction */
2635 /* Calculate score for this window. The smaller the better. */
2636 score
= distance
+ offset
;
2638 /* windows more than 45 degrees off the direction are
2639 * heavily penalized and will only be chosen if nothing
2640 * else within a million pixels */
2641 if(offset
> distance
)
2644 if(best_score
== -1 || score
< best_score
)
2652 void client_set_layer(ObClient
*self
, int layer
)
2656 self
->above
= FALSE
;
2657 } else if (layer
== 0) {
2658 self
->below
= self
->above
= FALSE
;
2660 self
->below
= FALSE
;
2663 client_calc_layer(self
);
2664 client_change_state(self
); /* reflect this in the state hints */
2667 guint
client_monitor(ObClient
*self
)
2671 for (i
= 0; i
< screen_num_monitors
; ++i
) {
2672 Rect
*area
= screen_physical_area_monitor(i
);
2673 if (RECT_INTERSECTS_RECT(*area
, self
->frame
->area
))
2676 if (i
== screen_num_monitors
) i
= 0;
2677 g_assert(i
< screen_num_monitors
);
2681 ObClient
*client_search_top_transient(ObClient
*self
)
2683 /* move up the transient chain as far as possible */
2684 if (self
->transient_for
) {
2685 if (self
->transient_for
!= OB_TRAN_GROUP
) {
2686 return client_search_top_transient(self
->transient_for
);
2690 for (it
= self
->group
->members
; it
; it
= it
->next
) {
2691 ObClient
*c
= it
->data
;
2693 /* checking transient_for prevents infinate loops! */
2694 if (c
!= self
&& !c
->transient_for
)
2705 ObClient
*client_search_transient(ObClient
*self
, ObClient
*search
)
2709 for (sit
= self
->transients
; sit
; sit
= g_slist_next(sit
)) {
2710 if (sit
->data
== search
)
2712 if (client_search_transient(sit
->data
, search
))
2718 gchar
* client_get_sm_client_id(ObClient
*self
)
2722 if (!PROP_GETS(self
->window
, sm_client_id
, locale
, &id
) && self
->group
)
2723 PROP_GETS(self
->group
->leader
, sm_client_id
, locale
, &id
);