4 #include "extensions.h"
15 #include <X11/Xutil.h>
17 /*! The event mask to grab on client windows */
18 #define CLIENT_EVENTMASK (PropertyChangeMask | FocusChangeMask | \
21 #define CLIENT_NOPROPAGATEMASK (ButtonPressMask | ButtonReleaseMask | \
24 GList
*client_list
= NULL
;
25 GHashTable
*client_map
= NULL
;
27 static Window
*client_startup_stack_order
= NULL
;
28 static gulong client_startup_stack_size
= 0;
30 static void client_get_all(Client
*self
);
31 static void client_toggle_border(Client
*self
, gboolean show
);
32 static void client_get_area(Client
*self
);
33 static void client_get_desktop(Client
*self
);
34 static void client_get_state(Client
*self
);
35 static void client_get_shaped(Client
*self
);
36 static void client_get_mwm_hints(Client
*self
);
37 static void client_get_gravity(Client
*self
);
38 static void client_showhide(Client
*self
);
39 static void client_change_allowed_actions(Client
*self
);
40 static void client_change_state(Client
*self
);
41 static void client_move_onscreen(Client
*self
);
42 static Client
*search_focus_tree(Client
*node
, Client
*skip
);
43 static void client_apply_startup_state(Client
*self
);
44 static Client
*search_modal_tree(Client
*node
, Client
*skip
);
46 static guint
map_hash(Window
*w
) { return *w
; }
47 static gboolean
map_key_comp(Window
*w1
, Window
*w2
) { return *w1
== *w2
; }
51 client_map
= g_hash_table_new((GHashFunc
)map_hash
,
52 (GEqualFunc
)map_key_comp
);
54 /* save the stacking order on startup! */
55 PROP_GET32U(ob_root
, net_client_list_stacking
, window
,
56 client_startup_stack_order
, client_startup_stack_size
);
61 void client_shutdown()
63 g_hash_table_destroy(client_map
);
66 void client_set_list()
68 Window
*windows
, *win_it
;
70 guint size
= g_list_length(client_list
);
72 /* create an array of the window ids */
74 windows
= g_new(Window
, size
);
76 for (it
= client_list
; it
!= NULL
; it
= it
->next
, ++win_it
)
77 *win_it
= ((Client
*)it
->data
)->window
;
81 PROP_SET32A(ob_root
, net_client_list
, window
, windows
, size
);
89 void client_manage_all()
91 unsigned int i
, j
, nchild
;
94 XWindowAttributes attrib
;
96 XQueryTree(ob_display
, ob_root
, &w
, &w
, &children
, &nchild
);
98 /* remove all icon windows from the list */
99 for (i
= 0; i
< nchild
; i
++) {
100 if (children
[i
] == None
) continue;
101 wmhints
= XGetWMHints(ob_display
, children
[i
]);
103 if ((wmhints
->flags
& IconWindowHint
) &&
104 (wmhints
->icon_window
!= children
[i
]))
105 for (j
= 0; j
< nchild
; j
++)
106 if (children
[j
] == wmhints
->icon_window
) {
114 for (i
= 0; i
< nchild
; ++i
) {
115 if (children
[i
] == None
)
117 if (XGetWindowAttributes(ob_display
, children
[i
], &attrib
)) {
118 if (attrib
.override_redirect
) continue;
120 if (attrib
.map_state
!= IsUnmapped
)
121 client_manage(children
[i
]);
126 /* stack them as they were on startup!
127 why with stacking_lower? Why, because then windows who aren't in the
128 stacking list are on the top where you can see them instead of buried
130 for (i
= client_startup_stack_size
; i
> 0; --i
) {
133 w
= client_startup_stack_order
[i
-1];
134 c
= g_hash_table_lookup(client_map
, &w
);
135 if (c
) stacking_lower(c
);
137 g_free(client_startup_stack_order
);
138 client_startup_stack_order
= NULL
;
139 client_startup_stack_size
= 0;
141 if (config_focus_new
)
142 focus_fallback(Fallback_NoFocus
);
145 void client_manage(Window window
)
149 XWindowAttributes attrib
;
150 XSetWindowAttributes attrib_set
;
151 /* XWMHints *wmhint; */
156 /* check if it has already been unmapped by the time we started mapping
157 the grab does a sync so we don't have to here */
158 if (XCheckTypedWindowEvent(ob_display
, window
, DestroyNotify
, &e
) ||
159 XCheckTypedWindowEvent(ob_display
, window
, UnmapNotify
, &e
)) {
160 XPutBackEvent(ob_display
, &e
);
163 return; /* don't manage it */
166 /* make sure it isn't an override-redirect window */
167 if (!XGetWindowAttributes(ob_display
, window
, &attrib
) ||
168 attrib
.override_redirect
) {
170 return; /* don't manage it */
173 /* /\* is the window a docking app *\/
174 if ((wmhint = XGetWMHints(ob_display, window))) {
175 if ((wmhint->flags & StateHint) &&
176 wmhint->initial_state == WithdrawnState) {
177 /\* XXX: make dock apps work! *\/
185 g_message("Managing window: %lx", window
);
187 /* choose the events we want to receive on the CLIENT window */
188 attrib_set
.event_mask
= CLIENT_EVENTMASK
;
189 attrib_set
.do_not_propagate_mask
= CLIENT_NOPROPAGATEMASK
;
190 XChangeWindowAttributes(ob_display
, window
,
191 CWEventMask
|CWDontPropagate
, &attrib_set
);
194 /* create the Client struct, and populate it from the hints on the
196 self
= g_new(Client
, 1);
197 self
->window
= window
;
198 client_get_all(self
);
200 /* remove the client's border (and adjust re gravity) */
201 client_toggle_border(self
, FALSE
);
203 /* specify that if we exit, the window should not be destroyed and should
204 be reparented back to root automatically */
205 XChangeSaveSet(ob_display
, window
, SetModeInsert
);
207 /* create the decoration frame for the client window */
208 self
->frame
= frame_new();
210 frame_grab_client(self
->frame
, self
);
212 client_apply_startup_state(self
);
216 client_list
= g_list_append(client_list
, self
);
217 stacking_list
= g_list_append(stacking_list
, self
);
218 g_assert(!g_hash_table_lookup(client_map
, &self
->window
));
219 g_hash_table_insert(client_map
, &self
->window
, self
);
221 /* update the focus lists */
222 if (self
->desktop
== DESKTOP_ALL
) {
223 for (i
= 0; i
< screen_num_desktops
; ++i
)
224 focus_order
[i
] = g_list_append(focus_order
[i
], self
);
227 focus_order
[i
] = g_list_append(focus_order
[i
], self
);
230 stacking_raise(self
);
232 screen_update_struts();
234 dispatch_client(Event_Client_New
, self
, 0, 0);
236 client_showhide(self
);
238 dispatch_client(Event_Client_Mapped
, self
, 0, 0);
240 /* focus the new window? */
241 if (ob_state
!= State_Starting
&& client_normal(self
)) {
242 if (config_focus_new
)
244 else if (self
->transient_for
) {
245 if (self
->transient_for
!= TRAN_GROUP
) {/* transient of a window */
246 if (focus_client
== self
->transient_for
)
248 } else { /* transient of a group */
251 for (it
= self
->group
->members
; it
; it
= it
->next
)
252 if (focus_client
== it
->data
) {
260 /* update the list hints */
263 /* make sure the window is visible */
264 client_move_onscreen(self
);
266 g_message("Managed window 0x%lx", window
);
269 void client_unmanage_all()
271 while (client_list
!= NULL
)
272 client_unmanage(client_list
->data
);
275 void client_unmanage(Client
*self
)
281 g_message("Unmanaging window: %lx", self
->window
);
283 dispatch_client(Event_Client_Destroy
, self
, 0, 0);
284 g_assert(self
!= NULL
);
286 /* remove the window from our save set */
287 XChangeSaveSet(ob_display
, self
->window
, SetModeDelete
);
289 /* we dont want events no more */
290 XSelectInput(ob_display
, self
->window
, NoEventMask
);
292 frame_hide(self
->frame
);
294 client_list
= g_list_remove(client_list
, self
);
295 stacking_list
= g_list_remove(stacking_list
, self
);
296 g_hash_table_remove(client_map
, &self
->window
);
298 /* update the focus lists */
299 if (self
->desktop
== DESKTOP_ALL
) {
300 for (i
= 0; i
< screen_num_desktops
; ++i
)
301 focus_order
[i
] = g_list_remove(focus_order
[i
], self
);
304 focus_order
[i
] = g_list_remove(focus_order
[i
], self
);
307 /* once the client is out of the list, update the struts to remove it's
309 screen_update_struts();
311 /* tell our parent(s) that we're gone */
312 if (self
->transient_for
== TRAN_GROUP
) { /* transient of group */
315 for (it
= self
->group
->members
; it
; it
= it
->next
)
316 if (it
->data
!= self
)
317 ((Client
*)it
->data
)->transients
=
318 g_slist_remove(((Client
*)it
->data
)->transients
, self
);
319 } else if (self
->transient_for
) { /* transient of window */
320 self
->transient_for
->transients
=
321 g_slist_remove(self
->transient_for
->transients
, self
);
324 /* tell our transients that we're gone */
325 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
) {
326 if (((Client
*)it
->data
)->transient_for
!= TRAN_GROUP
) {
327 ((Client
*)it
->data
)->transient_for
= NULL
;
328 client_calc_layer(it
->data
);
332 if (focus_client
== self
)
333 client_unfocus(self
);
335 /* remove from its group */
337 group_remove(self
->group
, self
);
341 /* dispatch the unmapped event */
342 dispatch_client(Event_Client_Unmapped
, self
, 0, 0);
343 g_assert(self
!= NULL
);
345 /* give the client its border back */
346 client_toggle_border(self
, TRUE
);
348 /* reparent the window out of the frame, and free the frame */
349 frame_release_client(self
->frame
, self
);
352 if (ob_state
!= State_Exiting
) {
353 /* these values should not be persisted across a window
355 prop_erase(self
->window
, prop_atoms
.net_wm_desktop
);
356 prop_erase(self
->window
, prop_atoms
.net_wm_state
);
358 /* if we're left in an iconic state, the client wont be mapped. this is
359 bad, since we will no longer be managing the window on restart */
361 XMapWindow(ob_display
, self
->window
);
364 g_message("Unmanaged window 0x%lx", self
->window
);
366 /* free all data allocated in the client struct */
367 g_slist_free(self
->transients
);
368 for (j
= 0; j
< self
->nicons
; ++j
)
369 g_free(self
->icons
[j
].data
);
370 if (self
->nicons
> 0)
373 g_free(self
->icon_title
);
379 /* update the list hints */
383 static void client_move_onscreen(Client
*self
)
386 int x
= self
->frame
->area
.x
, y
= self
->frame
->area
.y
;
388 a
= screen_area(self
->desktop
);
389 if (x
>= a
->x
+ a
->width
- 1)
390 x
= a
->x
+ a
->width
- self
->frame
->area
.width
;
391 if (y
>= a
->y
+ a
->height
- 1)
392 y
= a
->y
+ a
->height
- self
->frame
->area
.height
;
393 if (x
+ self
->frame
->area
.width
- 1 < a
->x
)
395 if (y
+ self
->frame
->area
.height
- 1< a
->y
)
398 frame_frame_gravity(self
->frame
, &x
, &y
); /* get where the client
400 client_configure(self
, Corner_TopLeft
, x
, y
,
401 self
->area
.width
, self
->area
.height
,
405 static void client_toggle_border(Client
*self
, gboolean show
)
407 /* adjust our idea of where the client is, based on its border. When the
408 border is removed, the client should now be considered to be in a
410 when re-adding the border to the client, the same operation needs to be
412 int oldx
= self
->area
.x
, oldy
= self
->area
.y
;
413 int x
= oldx
, y
= oldy
;
414 switch(self
->gravity
) {
416 case NorthWestGravity
:
418 case SouthWestGravity
:
420 case NorthEastGravity
:
422 case SouthEastGravity
:
423 if (show
) x
-= self
->border_width
* 2;
424 else x
+= self
->border_width
* 2;
431 if (show
) x
-= self
->border_width
;
432 else x
+= self
->border_width
;
435 switch(self
->gravity
) {
437 case NorthWestGravity
:
439 case NorthEastGravity
:
441 case SouthWestGravity
:
443 case SouthEastGravity
:
444 if (show
) y
-= self
->border_width
* 2;
445 else y
+= self
->border_width
* 2;
452 if (show
) y
-= self
->border_width
;
453 else y
+= self
->border_width
;
460 XSetWindowBorderWidth(ob_display
, self
->window
, self
->border_width
);
462 /* move the client so it is back it the right spot _with_ its
464 if (x
!= oldx
|| y
!= oldy
)
465 XMoveWindow(ob_display
, self
->window
, x
, y
);
467 XSetWindowBorderWidth(ob_display
, self
->window
, 0);
471 static void client_get_all(Client
*self
)
473 /* update EVERYTHING!! */
475 self
->ignore_unmaps
= 0;
479 self
->title
= self
->icon_title
= NULL
;
480 self
->name
= self
->class = self
->role
= NULL
;
481 self
->wmstate
= NormalState
;
482 self
->transient
= FALSE
;
483 self
->transients
= NULL
;
484 self
->transient_for
= NULL
;
486 self
->urgent
= FALSE
;
487 self
->positioned
= FALSE
;
488 self
->disabled_decorations
= 0;
492 client_get_area(self
);
493 client_get_desktop(self
);
494 client_get_state(self
);
495 client_get_shaped(self
);
497 client_update_transient_for(self
);
498 client_get_mwm_hints(self
);
499 client_get_type(self
);/* this can change the mwmhints for special cases */
501 client_update_protocols(self
);
503 client_get_gravity(self
); /* get the attribute gravity */
504 client_update_normal_hints(self
); /* this may override the attribute
507 /* got the type, the mwmhints, the protocols, and the normal hints
508 (min/max sizes), so we're ready to set up the decorations/functions */
509 client_setup_decor_and_functions(self
);
511 client_update_wmhints(self
);
512 client_update_title(self
);
513 client_update_icon_title(self
);
514 client_update_class(self
);
515 client_update_strut(self
);
516 client_update_icons(self
);
517 client_update_kwm_icon(self
);
519 /* this makes sure that these windows appear on all desktops */
520 if (self
->type
== Type_Desktop
)
521 self
->desktop
= DESKTOP_ALL
;
523 /* set the desktop hint, to make sure that it always exists, and to
524 reflect any changes we've made here */
525 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, self
->desktop
);
527 client_change_state(self
);
530 static void client_get_area(Client
*self
)
532 XWindowAttributes wattrib
;
535 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
536 g_assert(ret
!= BadWindow
);
538 RECT_SET(self
->area
, wattrib
.x
, wattrib
.y
, wattrib
.width
, wattrib
.height
);
539 self
->border_width
= wattrib
.border_width
;
542 static void client_get_desktop(Client
*self
)
546 if (PROP_GET32(self
->window
, net_wm_desktop
, cardinal
, d
)) {
547 if (d
>= screen_num_desktops
&& d
!= DESKTOP_ALL
)
548 d
= screen_num_desktops
- 1;
551 /* defaults to the current desktop */
552 self
->desktop
= screen_desktop
;
556 static void client_get_state(Client
*self
)
561 self
->modal
= self
->shaded
= self
->max_horz
= self
->max_vert
=
562 self
->fullscreen
= self
->above
= self
->below
= self
->iconic
=
563 self
->skip_taskbar
= self
->skip_pager
= FALSE
;
565 if (PROP_GET32U(self
->window
, net_wm_state
, atom
, state
, num
)) {
567 for (i
= 0; i
< num
; ++i
) {
568 if (state
[i
] == prop_atoms
.net_wm_state_modal
)
570 else if (state
[i
] == prop_atoms
.net_wm_state_shaded
)
572 else if (state
[i
] == prop_atoms
.net_wm_state_hidden
)
574 else if (state
[i
] == prop_atoms
.net_wm_state_skip_taskbar
)
575 self
->skip_taskbar
= TRUE
;
576 else if (state
[i
] == prop_atoms
.net_wm_state_skip_pager
)
577 self
->skip_pager
= TRUE
;
578 else if (state
[i
] == prop_atoms
.net_wm_state_fullscreen
)
579 self
->fullscreen
= TRUE
;
580 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_vert
)
581 self
->max_vert
= TRUE
;
582 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_horz
)
583 self
->max_horz
= TRUE
;
584 else if (state
[i
] == prop_atoms
.net_wm_state_above
)
586 else if (state
[i
] == prop_atoms
.net_wm_state_below
)
594 static void client_get_shaped(Client
*self
)
596 self
->shaped
= FALSE
;
598 if (extensions_shape
) {
603 XShapeSelectInput(ob_display
, self
->window
, ShapeNotifyMask
);
605 XShapeQueryExtents(ob_display
, self
->window
, &s
, &foo
,
606 &foo
, &ufoo
, &ufoo
, &foo
, &foo
, &foo
, &ufoo
,
608 self
->shaped
= (s
!= 0);
613 void client_update_transient_for(Client
*self
)
618 if (XGetTransientForHint(ob_display
, self
->window
, &t
) &&
619 t
!= self
->window
) { /* cant be transient to itself! */
620 self
->transient
= TRUE
;
621 c
= g_hash_table_lookup(client_map
, &t
);
622 g_assert(c
!= self
);/* if this happens then we need to check for it*/
624 if (!c
&& self
->group
) {
625 /* not transient to a client, see if it is transient for a
627 if (t
== self
->group
->leader
||
630 /* window is a transient for its group! */
635 self
->transient
= FALSE
;
637 /* if anything has changed... */
638 if (c
!= self
->transient_for
) {
639 if (self
->transient_for
== TRAN_GROUP
) { /* transient of group */
642 /* remove from old parents */
643 for (it
= self
->group
->members
; it
; it
= it
->next
)
644 if (it
->data
!= self
)
645 ((Client
*)it
->data
)->transients
=
646 g_slist_remove(((Client
*)it
->data
)->transients
, self
);
647 } else if (self
->transient_for
!= NULL
) { /* transient of window */
648 /* remove from old parent */
649 self
->transient_for
->transients
=
650 g_slist_remove(self
->transient_for
->transients
, self
);
652 self
->transient_for
= c
;
653 if (self
->transient_for
== TRAN_GROUP
) { /* transient of group */
656 /* add to new parents */
657 for (it
= self
->group
->members
; it
; it
= it
->next
)
658 if (it
->data
!= self
)
659 ((Client
*)it
->data
)->transients
=
660 g_slist_append(((Client
*)it
->data
)->transients
, self
);
661 } else if (self
->transient_for
!= NULL
) { /* transient of window */
662 /* add to new parent */
663 self
->transient_for
->transients
=
664 g_slist_append(self
->transient_for
->transients
, self
);
669 static void client_get_mwm_hints(Client
*self
)
672 unsigned long *hints
;
674 self
->mwmhints
.flags
= 0; /* default to none */
676 if (PROP_GET32U(self
->window
, motif_wm_hints
, motif_wm_hints
, hints
, num
)) {
677 if (num
>= MWM_ELEMENTS
) {
678 self
->mwmhints
.flags
= hints
[0];
679 self
->mwmhints
.functions
= hints
[1];
680 self
->mwmhints
.decorations
= hints
[2];
686 void client_get_type(Client
*self
)
692 if (PROP_GET32U(self
->window
, net_wm_window_type
, atom
, val
, num
)) {
693 /* use the first value that we know about in the array */
694 for (i
= 0; i
< num
; ++i
) {
695 if (val
[i
] == prop_atoms
.net_wm_window_type_desktop
)
696 self
->type
= Type_Desktop
;
697 else if (val
[i
] == prop_atoms
.net_wm_window_type_dock
)
698 self
->type
= Type_Dock
;
699 else if (val
[i
] == prop_atoms
.net_wm_window_type_toolbar
)
700 self
->type
= Type_Toolbar
;
701 else if (val
[i
] == prop_atoms
.net_wm_window_type_menu
)
702 self
->type
= Type_Menu
;
703 else if (val
[i
] == prop_atoms
.net_wm_window_type_utility
)
704 self
->type
= Type_Utility
;
705 else if (val
[i
] == prop_atoms
.net_wm_window_type_splash
)
706 self
->type
= Type_Splash
;
707 else if (val
[i
] == prop_atoms
.net_wm_window_type_dialog
)
708 self
->type
= Type_Dialog
;
709 else if (val
[i
] == prop_atoms
.net_wm_window_type_normal
)
710 self
->type
= Type_Normal
;
711 else if (val
[i
] == prop_atoms
.kde_net_wm_window_type_override
) {
712 /* prevent this window from getting any decor or
714 self
->mwmhints
.flags
&= (MwmFlag_Functions
|
715 MwmFlag_Decorations
);
716 self
->mwmhints
.decorations
= 0;
717 self
->mwmhints
.functions
= 0;
719 if (self
->type
!= (WindowType
) -1)
720 break; /* grab the first legit type */
725 if (self
->type
== (WindowType
) -1) {
726 /*the window type hint was not set, which means we either classify
727 ourself as a normal window or a dialog, depending on if we are a
730 self
->type
= Type_Dialog
;
732 self
->type
= Type_Normal
;
736 void client_update_protocols(Client
*self
)
739 gulong num_return
, i
;
741 self
->focus_notify
= FALSE
;
742 self
->delete_window
= FALSE
;
744 if (PROP_GET32U(self
->window
, wm_protocols
, atom
, proto
, num_return
)) {
745 for (i
= 0; i
< num_return
; ++i
) {
746 if (proto
[i
] == prop_atoms
.wm_delete_window
) {
747 /* this means we can request the window to close */
748 self
->delete_window
= TRUE
;
749 } else if (proto
[i
] == prop_atoms
.wm_take_focus
)
750 /* if this protocol is requested, then the window will be
751 notified whenever we want it to receive focus */
752 self
->focus_notify
= TRUE
;
758 static void client_get_gravity(Client
*self
)
760 XWindowAttributes wattrib
;
763 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
764 g_assert(ret
!= BadWindow
);
765 self
->gravity
= wattrib
.win_gravity
;
768 void client_update_normal_hints(Client
*self
)
772 int oldgravity
= self
->gravity
;
775 self
->min_ratio
= 0.0f
;
776 self
->max_ratio
= 0.0f
;
777 SIZE_SET(self
->size_inc
, 1, 1);
778 SIZE_SET(self
->base_size
, 0, 0);
779 SIZE_SET(self
->min_size
, 0, 0);
780 SIZE_SET(self
->max_size
, G_MAXINT
, G_MAXINT
);
782 /* get the hints from the window */
783 if (XGetWMNormalHints(ob_display
, self
->window
, &size
, &ret
)) {
784 self
->positioned
= !!(size
.flags
& (PPosition
|USPosition
));
786 if (size
.flags
& PWinGravity
) {
787 self
->gravity
= size
.win_gravity
;
789 /* if the client has a frame, i.e. has already been mapped and
790 is changing its gravity */
791 if (self
->frame
&& self
->gravity
!= oldgravity
) {
792 /* move our idea of the client's position based on its new
794 self
->area
.x
= self
->frame
->area
.x
;
795 self
->area
.y
= self
->frame
->area
.y
;
796 frame_frame_gravity(self
->frame
, &self
->area
.x
, &self
->area
.y
);
800 if (size
.flags
& PAspect
) {
801 if (size
.min_aspect
.y
)
802 self
->min_ratio
= (float)size
.min_aspect
.x
/ size
.min_aspect
.y
;
803 if (size
.max_aspect
.y
)
804 self
->max_ratio
= (float)size
.max_aspect
.x
/ size
.max_aspect
.y
;
807 if (size
.flags
& PMinSize
)
808 SIZE_SET(self
->min_size
, size
.min_width
, size
.min_height
);
810 if (size
.flags
& PMaxSize
)
811 SIZE_SET(self
->max_size
, size
.max_width
, size
.max_height
);
813 if (size
.flags
& PBaseSize
)
814 SIZE_SET(self
->base_size
, size
.base_width
, size
.base_height
);
816 if (size
.flags
& PResizeInc
)
817 SIZE_SET(self
->size_inc
, size
.width_inc
, size
.height_inc
);
821 void client_setup_decor_and_functions(Client
*self
)
823 /* start with everything (cept fullscreen) */
824 self
->decorations
= Decor_Titlebar
| Decor_Handle
| Decor_Border
|
825 Decor_Icon
| Decor_AllDesktops
| Decor_Iconify
| Decor_Maximize
|
827 self
->functions
= Func_Resize
| Func_Move
| Func_Iconify
| Func_Maximize
|
829 if (self
->delete_window
) {
830 self
->decorations
|= Decor_Close
;
831 self
->functions
|= Func_Close
;
834 if (!(self
->min_size
.width
< self
->max_size
.width
||
835 self
->min_size
.height
< self
->max_size
.height
)) {
836 self
->decorations
&= ~(Decor_Maximize
| Decor_Handle
);
837 self
->functions
&= ~(Func_Resize
| Func_Maximize
);
840 switch (self
->type
) {
842 /* normal windows retain all of the possible decorations and
843 functionality, and are the only windows that you can fullscreen */
844 self
->functions
|= Func_Fullscreen
;
849 /* these windows cannot be maximized */
850 self
->decorations
&= ~Decor_Maximize
;
851 self
->functions
&= ~Func_Maximize
;
856 /* these windows get less functionality */
857 self
->decorations
&= ~(Decor_Iconify
| Decor_Handle
);
858 self
->functions
&= ~(Func_Iconify
| Func_Resize
);
864 /* none of these windows are manipulated by the window manager */
865 self
->decorations
= 0;
870 /* Mwm Hints are applied subtractively to what has already been chosen for
871 decor and functionality */
872 if (self
->mwmhints
.flags
& MwmFlag_Decorations
) {
873 if (! (self
->mwmhints
.decorations
& MwmDecor_All
)) {
874 if (! (self
->mwmhints
.decorations
& MwmDecor_Border
))
875 self
->decorations
&= ~Decor_Border
;
876 if (! (self
->mwmhints
.decorations
& MwmDecor_Handle
))
877 self
->decorations
&= ~Decor_Handle
;
878 if (! (self
->mwmhints
.decorations
& MwmDecor_Title
))
879 self
->decorations
&= ~Decor_Titlebar
;
880 if (! (self
->mwmhints
.decorations
& MwmDecor_Iconify
))
881 self
->decorations
&= ~Decor_Iconify
;
882 if (! (self
->mwmhints
.decorations
& MwmDecor_Maximize
))
883 self
->decorations
&= ~Decor_Maximize
;
887 if (self
->mwmhints
.flags
& MwmFlag_Functions
) {
888 if (! (self
->mwmhints
.functions
& MwmFunc_All
)) {
889 if (! (self
->mwmhints
.functions
& MwmFunc_Resize
))
890 self
->functions
&= ~Func_Resize
;
891 if (! (self
->mwmhints
.functions
& MwmFunc_Move
))
892 self
->functions
&= ~Func_Move
;
893 if (! (self
->mwmhints
.functions
& MwmFunc_Iconify
))
894 self
->functions
&= ~Func_Iconify
;
895 if (! (self
->mwmhints
.functions
& MwmFunc_Maximize
))
896 self
->functions
&= ~Func_Maximize
;
897 /* dont let mwm hints kill the close button
898 if (! (self->mwmhints.functions & MwmFunc_Close))
899 self->functions &= ~Func_Close; */
903 /* can't maximize without moving/resizing */
904 if (!((self
->functions
& Func_Move
) && (self
->functions
& Func_Resize
)))
905 self
->functions
&= ~(Func_Maximize
| Func_Fullscreen
);
907 /* finally, user specified disabled decorations are applied to subtract
909 if (self
->disabled_decorations
& Decor_Titlebar
)
910 self
->decorations
&= ~Decor_Titlebar
;
911 if (self
->disabled_decorations
& Decor_Handle
)
912 self
->decorations
&= ~Decor_Handle
;
913 if (self
->disabled_decorations
& Decor_Border
)
914 self
->decorations
&= ~Decor_Border
;
915 if (self
->disabled_decorations
& Decor_Iconify
)
916 self
->decorations
&= ~Decor_Iconify
;
917 if (self
->disabled_decorations
& Decor_Maximize
)
918 self
->decorations
&= ~Decor_Maximize
;
919 if (self
->disabled_decorations
& Decor_AllDesktops
)
920 self
->decorations
&= ~Decor_AllDesktops
;
921 if (self
->disabled_decorations
& Decor_Shade
)
922 self
->decorations
&= ~Decor_Shade
;
923 if (self
->disabled_decorations
& Decor_Close
)
924 self
->decorations
&= ~Decor_Close
;
926 /* if we don't have a titlebar, then we cannot shade! */
927 if (!(self
->decorations
& Decor_Titlebar
))
928 self
->functions
&= ~Func_Shade
;
930 /* now we need to check against rules for the client's current state */
931 if (self
->fullscreen
) {
932 self
->functions
&= (Func_Close
| Func_Fullscreen
| Func_Iconify
);
933 self
->decorations
= 0;
936 client_change_allowed_actions(self
);
939 /* change the decors on the frame, and with more/less decorations,
940 we may also need to be repositioned */
941 frame_adjust_area(self
->frame
, TRUE
, TRUE
);
942 /* with new decor, the window's maximized size may change */
943 client_remaximize(self
);
947 static void client_change_allowed_actions(Client
*self
)
952 actions
[num
++] = prop_atoms
.net_wm_action_change_desktop
;
954 if (self
->functions
& Func_Shade
)
955 actions
[num
++] = prop_atoms
.net_wm_action_shade
;
956 if (self
->functions
& Func_Close
)
957 actions
[num
++] = prop_atoms
.net_wm_action_close
;
958 if (self
->functions
& Func_Move
)
959 actions
[num
++] = prop_atoms
.net_wm_action_move
;
960 if (self
->functions
& Func_Iconify
)
961 actions
[num
++] = prop_atoms
.net_wm_action_minimize
;
962 if (self
->functions
& Func_Resize
)
963 actions
[num
++] = prop_atoms
.net_wm_action_resize
;
964 if (self
->functions
& Func_Fullscreen
)
965 actions
[num
++] = prop_atoms
.net_wm_action_fullscreen
;
966 if (self
->functions
& Func_Maximize
) {
967 actions
[num
++] = prop_atoms
.net_wm_action_maximize_horz
;
968 actions
[num
++] = prop_atoms
.net_wm_action_maximize_vert
;
971 PROP_SET32A(self
->window
, net_wm_allowed_actions
, atom
, actions
, num
);
973 /* make sure the window isn't breaking any rules now */
975 if (!(self
->functions
& Func_Shade
) && self
->shaded
) {
976 if (self
->frame
) client_shade(self
, FALSE
);
977 else self
->shaded
= FALSE
;
979 if (!(self
->functions
& Func_Iconify
) && self
->iconic
) {
980 g_message("UNSETTING ICONIC");
981 if (self
->frame
) client_iconify(self
, FALSE
, TRUE
);
982 else self
->iconic
= FALSE
;
984 if (!(self
->functions
& Func_Fullscreen
) && self
->fullscreen
) {
985 if (self
->frame
) client_fullscreen(self
, FALSE
, TRUE
);
986 else self
->fullscreen
= FALSE
;
988 if (!(self
->functions
& Func_Maximize
) && (self
->max_horz
||
990 if (self
->frame
) client_maximize(self
, FALSE
, 0, TRUE
);
991 else self
->max_vert
= self
->max_horz
= FALSE
;
995 void client_remaximize(Client
*self
)
998 if (self
->max_horz
&& self
->max_vert
)
1000 else if (self
->max_horz
)
1002 else if (self
->max_vert
)
1005 return; /* not maximized */
1006 self
->max_horz
= self
->max_vert
= FALSE
;
1007 client_maximize(self
, TRUE
, dir
, FALSE
);
1010 void client_update_wmhints(Client
*self
)
1013 gboolean ur
= FALSE
;
1015 /* assume a window takes input if it doesnt specify */
1016 self
->can_focus
= TRUE
;
1018 if ((hints
= XGetWMHints(ob_display
, self
->window
)) != NULL
) {
1019 if (hints
->flags
& InputHint
)
1020 self
->can_focus
= hints
->input
;
1022 /* only do this when first managing the window *AND* when we aren't
1024 if (ob_state
!= State_Starting
&& self
->frame
== NULL
)
1025 if (hints
->flags
& StateHint
)
1026 self
->iconic
= hints
->initial_state
== IconicState
;
1028 if (hints
->flags
& XUrgencyHint
)
1031 if (!(hints
->flags
& WindowGroupHint
))
1032 hints
->window_group
= None
; /* no group */
1033 /* did the group state change? */
1034 if (hints
->window_group
!= (self
->group
? self
->group
->leader
: None
)){
1035 /* remove from the old group if there was one */
1036 if (self
->group
!= NULL
)
1037 group_remove(self
->group
, self
);
1038 if (hints
->window_group
!= None
)
1039 self
->group
= group_add(hints
->window_group
, self
);
1041 /* because the self->transient flag wont change from this call,
1042 we don't need to update the window's type and such, only its
1043 transient_for, and the transients lists of other windows in the
1044 group may be affected */
1045 client_update_transient_for(self
);
1048 if (hints
->flags
& IconPixmapHint
) {
1049 client_update_kwm_icon(self
);
1050 /* try get the kwm icon first, this is a fallback only */
1051 if (self
->pixmap_icon
== None
) {
1052 self
->pixmap_icon
= hints
->icon_pixmap
;
1053 if (hints
->flags
& IconMaskHint
)
1054 self
->pixmap_icon_mask
= hints
->icon_mask
;
1056 self
->pixmap_icon_mask
= None
;
1059 frame_adjust_icon(self
->frame
);
1066 if (ur
!= self
->urgent
) {
1068 g_message("Urgent Hint for 0x%lx: %s", self
->window
,
1070 /* fire the urgent callback if we're mapped, otherwise, wait until
1071 after we're mapped */
1073 dispatch_client(Event_Client_Urgent
, self
, self
->urgent
, 0);
1077 void client_update_title(Client
*self
)
1081 g_free(self
->title
);
1084 if (!PROP_GETS(self
->window
, net_wm_name
, utf8
, data
)) {
1085 /* try old x stuff */
1086 if (PROP_GETS(self
->window
, wm_name
, string
, data
)) {
1087 /* convert it to UTF-8 */
1091 u
= g_locale_to_utf8(data
, -1, &r
, &w
, NULL
);
1093 g_warning("Unable to convert string to UTF-8");
1100 data
= g_strdup("Unnamed Window");
1102 PROP_SETS(self
->window
, net_wm_visible_name
, utf8
, data
);
1108 frame_adjust_title(self
->frame
);
1111 void client_update_icon_title(Client
*self
)
1115 g_free(self
->icon_title
);
1118 if (!PROP_GETS(self
->window
, net_wm_icon_name
, utf8
, data
)) {
1119 /* try old x stuff */
1120 if (PROP_GETS(self
->window
, wm_icon_name
, string
, data
)) {
1121 /* convert it to UTF-8 */
1125 u
= g_locale_to_utf8(data
, -1, &r
, &w
, NULL
);
1127 g_warning("Unable to convert string to UTF-8");
1134 data
= g_strdup("Unnamed Window");
1136 PROP_SETS(self
->window
, net_wm_visible_icon_name
, utf8
, data
);
1139 self
->icon_title
= data
;
1142 void client_update_class(Client
*self
)
1148 if (self
->name
) g_free(self
->name
);
1149 if (self
->class) g_free(self
->class);
1150 if (self
->role
) g_free(self
->role
);
1152 self
->name
= self
->class = self
->role
= NULL
;
1154 data
= g_ptr_array_new();
1156 if (PROP_GETSA(self
->window
, wm_class
, string
, data
)) {
1158 self
->name
= g_strdup(g_ptr_array_index(data
, 0));
1160 self
->class = g_strdup(g_ptr_array_index(data
, 1));
1163 for (i
= 0; i
< data
->len
; ++i
)
1164 g_free(g_ptr_array_index(data
, i
));
1165 g_ptr_array_free(data
, TRUE
);
1167 if (PROP_GETS(self
->window
, wm_window_role
, string
, s
))
1168 self
->role
= g_strdup(s
);
1170 if (self
->name
== NULL
) self
->name
= g_strdup("");
1171 if (self
->class == NULL
) self
->class = g_strdup("");
1172 if (self
->role
== NULL
) self
->role
= g_strdup("");
1175 void client_update_strut(Client
*self
)
1179 if (PROP_GET32A(self
->window
, net_wm_strut
, cardinal
, data
, 4)) {
1180 STRUT_SET(self
->strut
, data
[0], data
[2], data
[1], data
[3]);
1183 STRUT_SET(self
->strut
, 0, 0, 0, 0);
1185 /* updating here is pointless while we're being mapped cuz we're not in
1186 the client list yet */
1188 screen_update_struts();
1191 void client_update_icons(Client
*self
)
1194 unsigned long *data
;
1195 unsigned long w
, h
, i
;
1198 for (j
= 0; j
< self
->nicons
; ++j
)
1199 g_free(self
->icons
[j
].data
);
1200 if (self
->nicons
> 0)
1201 g_free(self
->icons
);
1204 if (PROP_GET32U(self
->window
, net_wm_icon
, cardinal
, data
, num
)) {
1205 /* figure out how many valid icons are in here */
1207 while (num
- i
> 2) {
1215 self
->icons
= g_new(Icon
, self
->nicons
);
1217 /* store the icons */
1219 for (j
= 0; j
< self
->nicons
; ++j
) {
1220 w
= self
->icons
[j
].width
= data
[i
++];
1221 h
= self
->icons
[j
].height
= data
[i
++];
1222 self
->icons
[j
].data
=
1223 g_memdup(&data
[i
], w
* h
* sizeof(gulong
));
1232 frame_adjust_icon(self
->frame
);
1235 void client_update_kwm_icon(Client
*self
)
1239 if (PROP_GET32A(self
->window
, kwm_win_icon
, kwm_win_icon
, data
, 2)) {
1240 self
->pixmap_icon
= data
[0];
1241 self
->pixmap_icon_mask
= data
[1];
1244 self
->pixmap_icon
= self
->pixmap_icon_mask
= None
;
1247 frame_adjust_icon(self
->frame
);
1250 static void client_change_state(Client
*self
)
1252 unsigned long state
[2];
1256 state
[0] = self
->wmstate
;
1258 PROP_SET32A(self
->window
, wm_state
, wm_state
, state
, 2);
1262 netstate
[num
++] = prop_atoms
.net_wm_state_modal
;
1264 netstate
[num
++] = prop_atoms
.net_wm_state_shaded
;
1266 netstate
[num
++] = prop_atoms
.net_wm_state_hidden
;
1267 if (self
->skip_taskbar
)
1268 netstate
[num
++] = prop_atoms
.net_wm_state_skip_taskbar
;
1269 if (self
->skip_pager
)
1270 netstate
[num
++] = prop_atoms
.net_wm_state_skip_pager
;
1271 if (self
->fullscreen
)
1272 netstate
[num
++] = prop_atoms
.net_wm_state_fullscreen
;
1274 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_vert
;
1276 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_horz
;
1278 netstate
[num
++] = prop_atoms
.net_wm_state_above
;
1280 netstate
[num
++] = prop_atoms
.net_wm_state_below
;
1281 PROP_SET32A(self
->window
, net_wm_state
, atom
, netstate
, num
);
1283 client_calc_layer(self
);
1286 frame_adjust_state(self
->frame
);
1289 static Client
*search_focus_tree(Client
*node
, Client
*skip
)
1294 for (it
= node
->transients
; it
!= NULL
; it
= it
->next
) {
1295 Client
*c
= it
->data
;
1296 if (c
== skip
) continue; /* circular? */
1297 if ((ret
= search_focus_tree(c
, skip
))) return ret
;
1298 if (client_focused(c
)) return c
;
1303 static void calc_recursive(Client
*self
, StackLayer l
, gboolean raised
)
1311 for (it
= self
->transients
; it
; it
= it
->next
)
1312 calc_recursive(it
->data
, l
, raised
? raised
: l
!= old
);
1314 if (!raised
&& l
!= old
)
1316 stacking_raise(self
);
1319 void client_calc_layer(Client
*self
)
1324 /* transients take on the layer of their parents */
1325 if (self
->transient_for
) {
1326 if (self
->transient_for
!= TRAN_GROUP
) {
1327 self
= self
->transient_for
;
1331 for (it
= self
->group
->members
; it
; it
= it
->next
)
1332 if (it
->data
!= self
&&
1333 ((Client
*)it
->data
)->transient_for
!= TRAN_GROUP
) {
1334 self
= self
->transient_for
;
1340 /* is us or one of our transients focused? */
1341 if (client_focused(self
))
1343 else if (search_focus_tree(self
, self
))
1348 if (self
->iconic
) l
= Layer_Icon
;
1349 /* fullscreen windows are only in the fullscreen layer while focused */
1350 else if (self
->fullscreen
&& f
) l
= Layer_Fullscreen
;
1351 else if (self
->type
== Type_Desktop
) l
= Layer_Desktop
;
1352 else if (self
->type
== Type_Dock
) {
1353 if (!self
->below
) l
= Layer_Top
;
1354 else l
= Layer_Normal
;
1356 else if (self
->above
) l
= Layer_Above
;
1357 else if (self
->below
) l
= Layer_Below
;
1358 else l
= Layer_Normal
;
1360 calc_recursive(self
, l
, FALSE
);
1363 gboolean
client_should_show(Client
*self
)
1365 if (self
->iconic
) return FALSE
;
1366 else if (!(self
->desktop
== screen_desktop
||
1367 self
->desktop
== DESKTOP_ALL
)) return FALSE
;
1368 else if (client_normal(self
) && screen_showing_desktop
) return FALSE
;
1373 static void client_showhide(Client
*self
)
1376 if (client_should_show(self
))
1377 frame_show(self
->frame
);
1379 frame_hide(self
->frame
);
1382 gboolean
client_normal(Client
*self
) {
1383 return ! (self
->type
== Type_Desktop
|| self
->type
== Type_Dock
||
1384 self
->type
== Type_Splash
);
1387 static void client_apply_startup_state(Client
*self
)
1389 /* these are in a carefully crafted order.. */
1392 self
->iconic
= FALSE
;
1393 client_iconify(self
, TRUE
, FALSE
);
1395 if (self
->fullscreen
) {
1396 self
->fullscreen
= FALSE
;
1397 client_fullscreen(self
, TRUE
, FALSE
);
1400 self
->shaded
= FALSE
;
1401 client_shade(self
, TRUE
);
1404 dispatch_client(Event_Client_Urgent
, self
, self
->urgent
, 0);
1406 if (self
->max_vert
&& self
->max_horz
) {
1407 self
->max_vert
= self
->max_horz
= FALSE
;
1408 client_maximize(self
, TRUE
, 0, FALSE
);
1409 } else if (self
->max_vert
) {
1410 self
->max_vert
= FALSE
;
1411 client_maximize(self
, TRUE
, 2, FALSE
);
1412 } else if (self
->max_horz
) {
1413 self
->max_horz
= FALSE
;
1414 client_maximize(self
, TRUE
, 1, FALSE
);
1417 /* nothing to do for the other states:
1426 void client_configure(Client
*self
, Corner anchor
, int x
, int y
, int w
, int h
,
1427 gboolean user
, gboolean final
)
1429 gboolean moved
= FALSE
, resized
= FALSE
;
1431 /* gets the frame's position */
1432 frame_client_gravity(self
->frame
, &x
, &y
);
1434 /* these positions are frame positions, not client positions */
1436 /* set the size and position if fullscreen */
1437 if (self
->fullscreen
) {
1440 w
= screen_physical_size
.width
;
1441 h
= screen_physical_size
.height
;
1442 user
= FALSE
; /* ignore that increment etc shit when in fullscreen */
1444 /* set the size and position if maximized */
1445 if (self
->max_horz
) {
1446 x
= screen_area(self
->desktop
)->x
- self
->frame
->size
.left
;
1447 w
= screen_area(self
->desktop
)->width
;
1449 if (self
->max_vert
) {
1450 y
= screen_area(self
->desktop
)->y
;
1451 h
= screen_area(self
->desktop
)->height
-
1452 self
->frame
->size
.top
- self
->frame
->size
.bottom
;
1456 /* gets the client's position */
1457 frame_frame_gravity(self
->frame
, &x
, &y
);
1459 /* these override the above states! if you cant move you can't move! */
1461 if (!(self
->functions
& Func_Move
)) {
1465 if (!(self
->functions
& Func_Resize
)) {
1466 w
= self
->area
.width
;
1467 h
= self
->area
.height
;
1471 if (!(w
== self
->area
.width
&& h
== self
->area
.height
)) {
1472 w
-= self
->base_size
.width
;
1473 h
-= self
->base_size
.height
;
1476 /* for interactive resizing. have to move half an increment in each
1479 /* how far we are towards the next size inc */
1480 int mw
= w
% self
->size_inc
.width
;
1481 int mh
= h
% self
->size_inc
.height
;
1483 int aw
= self
->size_inc
.width
/ 2;
1484 int ah
= self
->size_inc
.height
/ 2;
1485 /* don't let us move into a new size increment */
1486 if (mw
+ aw
>= self
->size_inc
.width
)
1487 aw
= self
->size_inc
.width
- mw
- 1;
1488 if (mh
+ ah
>= self
->size_inc
.height
)
1489 ah
= self
->size_inc
.height
- mh
- 1;
1493 /* if this is a user-requested resize, then check against min/max
1494 sizes and aspect ratios */
1496 /* smaller than min size or bigger than max size? */
1497 if (w
> self
->max_size
.width
) w
= self
->max_size
.width
;
1498 if (w
< self
->min_size
.width
) w
= self
->min_size
.width
;
1499 if (h
> self
->max_size
.height
) h
= self
->max_size
.height
;
1500 if (h
< self
->min_size
.height
) h
= self
->min_size
.height
;
1502 /* adjust the height ot match the width for the aspect ratios */
1503 if (self
->min_ratio
)
1504 if (h
* self
->min_ratio
> w
) h
= (int)(w
/ self
->min_ratio
);
1505 if (self
->max_ratio
)
1506 if (h
* self
->max_ratio
< w
) h
= (int)(w
/ self
->max_ratio
);
1509 /* keep to the increments */
1510 w
/= self
->size_inc
.width
;
1511 h
/= self
->size_inc
.height
;
1513 /* you cannot resize to nothing */
1517 /* store the logical size */
1518 SIZE_SET(self
->logical_size
, w
, h
);
1520 w
*= self
->size_inc
.width
;
1521 h
*= self
->size_inc
.height
;
1523 w
+= self
->base_size
.width
;
1524 h
+= self
->base_size
.height
;
1528 case Corner_TopLeft
:
1530 case Corner_TopRight
:
1531 x
-= w
- self
->area
.width
;
1533 case Corner_BottomLeft
:
1534 y
-= h
- self
->area
.height
;
1536 case Corner_BottomRight
:
1537 x
-= w
- self
->area
.width
;
1538 y
-= h
- self
->area
.height
;
1542 moved
= x
!= self
->area
.x
|| y
!= self
->area
.y
;
1543 resized
= w
!= self
->area
.width
|| h
!= self
->area
.height
;
1545 RECT_SET(self
->area
, x
, y
, w
, h
);
1548 XResizeWindow(ob_display
, self
->window
, w
, h
);
1550 /* move/resize the frame to match the request */
1552 if (moved
|| resized
)
1553 frame_adjust_area(self
->frame
, moved
, resized
);
1555 if (!user
|| final
) {
1557 event
.type
= ConfigureNotify
;
1558 event
.xconfigure
.display
= ob_display
;
1559 event
.xconfigure
.event
= self
->window
;
1560 event
.xconfigure
.window
= self
->window
;
1562 /* root window coords with border in mind */
1563 event
.xconfigure
.x
= x
- self
->border_width
+
1564 self
->frame
->size
.left
;
1565 event
.xconfigure
.y
= y
- self
->border_width
+
1566 self
->frame
->size
.top
;
1568 event
.xconfigure
.width
= self
->area
.width
;
1569 event
.xconfigure
.height
= self
->area
.height
;
1570 event
.xconfigure
.border_width
= self
->border_width
;
1571 event
.xconfigure
.above
= self
->frame
->plate
;
1572 event
.xconfigure
.override_redirect
= FALSE
;
1573 XSendEvent(event
.xconfigure
.display
, event
.xconfigure
.window
,
1574 FALSE
, StructureNotifyMask
, &event
);
1579 void client_fullscreen(Client
*self
, gboolean fs
, gboolean savearea
)
1583 if (!(self
->functions
& Func_Fullscreen
) || /* can't */
1584 self
->fullscreen
== fs
) return; /* already done */
1586 self
->fullscreen
= fs
;
1587 client_change_state(self
); /* change the state hints on the client,
1588 and adjust out layer/stacking */
1593 dimensions
[0] = self
->area
.x
;
1594 dimensions
[1] = self
->area
.y
;
1595 dimensions
[2] = self
->area
.width
;
1596 dimensions
[3] = self
->area
.height
;
1598 PROP_SET32A(self
->window
, openbox_premax
, cardinal
,
1602 /* these are not actually used cuz client_configure will set them
1603 as appropriate when the window is fullscreened */
1608 if (PROP_GET32A(self
->window
, openbox_premax
, cardinal
,
1616 /* pick some fallbacks... */
1617 x
= screen_area(self
->desktop
)->x
+
1618 screen_area(self
->desktop
)->width
/ 4;
1619 y
= screen_area(self
->desktop
)->y
+
1620 screen_area(self
->desktop
)->height
/ 4;
1621 w
= screen_area(self
->desktop
)->width
/ 2;
1622 h
= screen_area(self
->desktop
)->height
/ 2;
1626 client_setup_decor_and_functions(self
);
1628 client_configure(self
, Corner_TopLeft
, x
, y
, w
, h
, TRUE
, TRUE
);
1630 /* try focus us when we go into fullscreen mode */
1634 void client_iconify(Client
*self
, gboolean iconic
, gboolean curdesk
)
1638 /* move up the transient chain as far as possible first if deiconifying */
1640 while (self
->transient_for
) {
1641 if (self
->transient_for
!= TRAN_GROUP
) {
1642 if (self
->transient_for
->iconic
== iconic
)
1644 self
= self
->transient_for
;
1648 /* the check for TRAN_GROUP is to prevent an infinate loop with
1649 2 transients of the same group at the head of the group's
1651 for (it
= self
->group
->members
; it
; it
= it
->next
) {
1652 Client
*c
= it
->data
;
1654 if (c
!= self
&& c
->transient_for
->iconic
!= iconic
&&
1655 c
->transient_for
!= TRAN_GROUP
) {
1660 if (it
== NULL
) break;
1664 if (self
->iconic
== iconic
) return; /* nothing to do */
1666 g_message("%sconifying window: 0x%lx", (iconic
? "I" : "Uni"),
1669 self
->iconic
= iconic
;
1672 self
->wmstate
= IconicState
;
1673 self
->ignore_unmaps
++;
1674 /* we unmap the client itself so that we can get MapRequest events,
1675 and because the ICCCM tells us to! */
1676 XUnmapWindow(ob_display
, self
->window
);
1679 client_set_desktop(self
, screen_desktop
, FALSE
);
1680 self
->wmstate
= self
->shaded
? IconicState
: NormalState
;
1681 XMapWindow(ob_display
, self
->window
);
1683 client_change_state(self
);
1684 client_showhide(self
);
1685 screen_update_struts();
1687 dispatch_client(iconic
? Event_Client_Unmapped
: Event_Client_Mapped
,
1690 /* iconify all transients */
1691 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
)
1692 if (it
->data
!= self
) client_iconify(it
->data
, iconic
, curdesk
);
1695 void client_maximize(Client
*self
, gboolean max
, int dir
, gboolean savearea
)
1699 g_assert(dir
== 0 || dir
== 1 || dir
== 2);
1700 if (!(self
->functions
& Func_Maximize
)) return; /* can't */
1702 /* check if already done */
1704 if (dir
== 0 && self
->max_horz
&& self
->max_vert
) return;
1705 if (dir
== 1 && self
->max_horz
) return;
1706 if (dir
== 2 && self
->max_vert
) return;
1708 if (dir
== 0 && !self
->max_horz
&& !self
->max_vert
) return;
1709 if (dir
== 1 && !self
->max_horz
) return;
1710 if (dir
== 2 && !self
->max_vert
) return;
1713 /* work with the frame's coords */
1714 x
= self
->frame
->area
.x
;
1715 y
= self
->frame
->area
.y
;
1716 w
= self
->area
.width
;
1717 h
= self
->area
.height
;
1729 /* get the property off the window and use it for the dimensions
1730 we are already maxed on */
1731 if (PROP_GET32A(self
->window
, openbox_premax
, cardinal
,
1733 if (self
->max_horz
) {
1734 dimensions
[0] = readdim
[0];
1735 dimensions
[2] = readdim
[2];
1737 if (self
->max_vert
) {
1738 dimensions
[1] = readdim
[1];
1739 dimensions
[3] = readdim
[3];
1744 PROP_SET32A(self
->window
, openbox_premax
, cardinal
,
1750 if (PROP_GET32A(self
->window
, openbox_premax
, cardinal
,
1752 if (dir
== 0 || dir
== 1) { /* horz */
1756 if (dir
== 0 || dir
== 2) { /* vert */
1762 /* pick some fallbacks... */
1763 if (dir
== 0 || dir
== 1) { /* horz */
1764 x
= screen_area(self
->desktop
)->x
+
1765 screen_area(self
->desktop
)->width
/ 4;
1766 w
= screen_area(self
->desktop
)->width
/ 2;
1768 if (dir
== 0 || dir
== 2) { /* vert */
1769 y
= screen_area(self
->desktop
)->y
+
1770 screen_area(self
->desktop
)->height
/ 4;
1771 h
= screen_area(self
->desktop
)->height
/ 2;
1776 if (dir
== 0 || dir
== 1) /* horz */
1777 self
->max_horz
= max
;
1778 if (dir
== 0 || dir
== 2) /* vert */
1779 self
->max_vert
= max
;
1781 if (!self
->max_horz
&& !self
->max_vert
)
1782 PROP_ERASE(self
->window
, openbox_premax
);
1784 client_change_state(self
); /* change the state hints on the client */
1786 /* figure out where the client should be going */
1787 frame_frame_gravity(self
->frame
, &x
, &y
);
1788 client_configure(self
, Corner_TopLeft
, x
, y
, w
, h
, TRUE
, TRUE
);
1791 void client_shade(Client
*self
, gboolean shade
)
1793 if ((!(self
->functions
& Func_Shade
) && shade
) || /* can't shade */
1794 self
->shaded
== shade
) return; /* already done */
1796 /* when we're iconic, don't change the wmstate */
1798 self
->wmstate
= shade
? IconicState
: NormalState
;
1799 self
->shaded
= shade
;
1800 client_change_state(self
);
1801 /* resize the frame to just the titlebar */
1802 frame_adjust_area(self
->frame
, FALSE
, FALSE
);
1805 void client_close(Client
*self
)
1809 if (!(self
->functions
& Func_Close
)) return;
1812 XXX: itd be cool to do timeouts and shit here for killing the client's
1814 like... if the window is around after 5 seconds, then the close button
1815 turns a nice red, and if this function is called again, the client is
1819 ce
.xclient
.type
= ClientMessage
;
1820 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
1821 ce
.xclient
.display
= ob_display
;
1822 ce
.xclient
.window
= self
->window
;
1823 ce
.xclient
.format
= 32;
1824 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_delete_window
;
1825 ce
.xclient
.data
.l
[1] = event_lasttime
;
1826 ce
.xclient
.data
.l
[2] = 0l;
1827 ce
.xclient
.data
.l
[3] = 0l;
1828 ce
.xclient
.data
.l
[4] = 0l;
1829 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
1832 void client_kill(Client
*self
)
1834 XKillClient(ob_display
, self
->window
);
1837 void client_set_desktop(Client
*self
, guint target
, gboolean donthide
)
1841 if (target
== self
->desktop
) return;
1843 g_message("Setting desktop %u", target
);
1845 g_assert(target
< screen_num_desktops
|| target
== DESKTOP_ALL
);
1847 old
= self
->desktop
;
1848 self
->desktop
= target
;
1849 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, target
);
1850 /* the frame can display the current desktop state */
1851 frame_adjust_state(self
->frame
);
1852 /* 'move' the window to the new desktop */
1854 client_showhide(self
);
1855 /* raise if it was not already on the desktop */
1856 if (old
!= DESKTOP_ALL
)
1857 stacking_raise(self
);
1858 screen_update_struts();
1860 /* update the focus lists */
1861 if (old
== DESKTOP_ALL
) {
1862 for (i
= 0; i
< screen_num_desktops
; ++i
)
1863 focus_order
[i
] = g_list_remove(focus_order
[i
], self
);
1865 focus_order
[old
] = g_list_remove(focus_order
[old
], self
);
1866 if (target
== DESKTOP_ALL
) {
1867 for (i
= 0; i
< screen_num_desktops
; ++i
) {
1868 if (config_focus_new
)
1869 focus_order
[i
] = g_list_prepend(focus_order
[i
], self
);
1871 focus_order
[i
] = g_list_append(focus_order
[i
], self
);
1874 if (config_focus_new
)
1875 focus_order
[target
] = g_list_prepend(focus_order
[target
], self
);
1877 focus_order
[target
] = g_list_append(focus_order
[target
], self
);
1880 dispatch_client(Event_Client_Desktop
, self
, target
, old
);
1883 static Client
*search_modal_tree(Client
*node
, Client
*skip
)
1888 for (it
= node
->transients
; it
!= NULL
; it
= it
->next
) {
1889 Client
*c
= it
->data
;
1890 if (c
== skip
) continue; /* circular? */
1891 if ((ret
= search_modal_tree(c
, skip
))) return ret
;
1892 if (c
->modal
) return c
;
1897 Client
*client_find_modal_child(Client
*self
)
1899 return search_modal_tree(self
, self
);
1902 gboolean
client_validate(Client
*self
)
1906 XSync(ob_display
, FALSE
); /* get all events on the server */
1908 if (XCheckTypedWindowEvent(ob_display
, self
->window
, DestroyNotify
, &e
) ||
1909 XCheckTypedWindowEvent(ob_display
, self
->window
, UnmapNotify
, &e
)) {
1910 XPutBackEvent(ob_display
, &e
);
1917 void client_set_wm_state(Client
*self
, long state
)
1919 if (state
== self
->wmstate
) return; /* no change */
1923 client_iconify(self
, TRUE
, TRUE
);
1926 client_iconify(self
, FALSE
, TRUE
);
1931 void client_set_state(Client
*self
, Atom action
, long data1
, long data2
)
1933 gboolean shaded
= self
->shaded
;
1934 gboolean fullscreen
= self
->fullscreen
;
1935 gboolean max_horz
= self
->max_horz
;
1936 gboolean max_vert
= self
->max_vert
;
1939 if (!(action
== prop_atoms
.net_wm_state_add
||
1940 action
== prop_atoms
.net_wm_state_remove
||
1941 action
== prop_atoms
.net_wm_state_toggle
))
1942 /* an invalid action was passed to the client message, ignore it */
1945 for (i
= 0; i
< 2; ++i
) {
1946 Atom state
= i
== 0 ? data1
: data2
;
1948 if (!state
) continue;
1950 /* if toggling, then pick whether we're adding or removing */
1951 if (action
== prop_atoms
.net_wm_state_toggle
) {
1952 if (state
== prop_atoms
.net_wm_state_modal
)
1953 action
= self
->modal
? prop_atoms
.net_wm_state_remove
:
1954 prop_atoms
.net_wm_state_add
;
1955 else if (state
== prop_atoms
.net_wm_state_maximized_vert
)
1956 action
= self
->max_vert
? prop_atoms
.net_wm_state_remove
:
1957 prop_atoms
.net_wm_state_add
;
1958 else if (state
== prop_atoms
.net_wm_state_maximized_horz
)
1959 action
= self
->max_horz
? prop_atoms
.net_wm_state_remove
:
1960 prop_atoms
.net_wm_state_add
;
1961 else if (state
== prop_atoms
.net_wm_state_shaded
)
1962 action
= self
->shaded
? prop_atoms
.net_wm_state_remove
:
1963 prop_atoms
.net_wm_state_add
;
1964 else if (state
== prop_atoms
.net_wm_state_skip_taskbar
)
1965 action
= self
->skip_taskbar
?
1966 prop_atoms
.net_wm_state_remove
:
1967 prop_atoms
.net_wm_state_add
;
1968 else if (state
== prop_atoms
.net_wm_state_skip_pager
)
1969 action
= self
->skip_pager
?
1970 prop_atoms
.net_wm_state_remove
:
1971 prop_atoms
.net_wm_state_add
;
1972 else if (state
== prop_atoms
.net_wm_state_fullscreen
)
1973 action
= self
->fullscreen
?
1974 prop_atoms
.net_wm_state_remove
:
1975 prop_atoms
.net_wm_state_add
;
1976 else if (state
== prop_atoms
.net_wm_state_above
)
1977 action
= self
->above
? prop_atoms
.net_wm_state_remove
:
1978 prop_atoms
.net_wm_state_add
;
1979 else if (state
== prop_atoms
.net_wm_state_below
)
1980 action
= self
->below
? prop_atoms
.net_wm_state_remove
:
1981 prop_atoms
.net_wm_state_add
;
1984 if (action
== prop_atoms
.net_wm_state_add
) {
1985 if (state
== prop_atoms
.net_wm_state_modal
) {
1986 /* XXX raise here or something? */
1988 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
1990 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
1992 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
1994 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
1995 self
->skip_taskbar
= TRUE
;
1996 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
1997 self
->skip_pager
= TRUE
;
1998 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
2000 } else if (state
== prop_atoms
.net_wm_state_above
) {
2002 } else if (state
== prop_atoms
.net_wm_state_below
) {
2006 } else { /* action == prop_atoms.net_wm_state_remove */
2007 if (state
== prop_atoms
.net_wm_state_modal
) {
2008 self
->modal
= FALSE
;
2009 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
2011 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
2013 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
2015 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
2016 self
->skip_taskbar
= FALSE
;
2017 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
2018 self
->skip_pager
= FALSE
;
2019 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
2021 } else if (state
== prop_atoms
.net_wm_state_above
) {
2022 self
->above
= FALSE
;
2023 } else if (state
== prop_atoms
.net_wm_state_below
) {
2024 self
->below
= FALSE
;
2028 if (max_horz
!= self
->max_horz
|| max_vert
!= self
->max_vert
) {
2029 if (max_horz
!= self
->max_horz
&& max_vert
!= self
->max_vert
) {
2031 if (max_horz
== max_vert
) { /* both going the same way */
2032 client_maximize(self
, max_horz
, 0, TRUE
);
2034 client_maximize(self
, max_horz
, 1, TRUE
);
2035 client_maximize(self
, max_vert
, 2, TRUE
);
2039 if (max_horz
!= self
->max_horz
)
2040 client_maximize(self
, max_horz
, 1, TRUE
);
2042 client_maximize(self
, max_vert
, 2, TRUE
);
2045 /* change fullscreen state before shading, as it will affect if the window
2047 if (fullscreen
!= self
->fullscreen
)
2048 client_fullscreen(self
, fullscreen
, TRUE
);
2049 if (shaded
!= self
->shaded
)
2050 client_shade(self
, shaded
);
2051 client_calc_layer(self
);
2052 client_change_state(self
); /* change the hint to relect these changes */
2055 Client
*client_focus_target(Client
*self
)
2059 /* if we have a modal child, then focus it, not us */
2060 child
= client_find_modal_child(self
);
2061 if (child
) return child
;
2065 gboolean
client_focusable(Client
*self
)
2067 /* won't try focus if the client doesn't want it, or if the window isn't
2068 visible on the screen */
2069 return self
->frame
->visible
&&
2070 (self
->can_focus
|| self
->focus_notify
);
2073 gboolean
client_focus(Client
*self
)
2077 /* choose the correct target */
2078 self
= client_focus_target(self
);
2080 if (!client_focusable(self
))
2083 /* do a check to see if the window has already been unmapped or destroyed
2084 do this intelligently while watching out for unmaps we've generated
2085 (ignore_unmaps > 0) */
2086 if (XCheckTypedWindowEvent(ob_display
, self
->window
,
2087 DestroyNotify
, &ev
)) {
2088 XPutBackEvent(ob_display
, &ev
);
2091 while (XCheckTypedWindowEvent(ob_display
, self
->window
,
2092 UnmapNotify
, &ev
)) {
2093 if (self
->ignore_unmaps
) {
2094 self
->ignore_unmaps
--;
2096 XPutBackEvent(ob_display
, &ev
);
2101 if (self
->can_focus
)
2102 /* RevertToPointerRoot causes much more headache than TevertToNone, so
2103 I choose to use it always, hopefully to find errors quicker, if any
2104 are left. (I hate X. I hate focus events.) */
2105 XSetInputFocus(ob_display
, self
->window
, RevertToPointerRoot
,
2108 if (self
->focus_notify
) {
2110 ce
.xclient
.type
= ClientMessage
;
2111 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
2112 ce
.xclient
.display
= ob_display
;
2113 ce
.xclient
.window
= self
->window
;
2114 ce
.xclient
.format
= 32;
2115 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_take_focus
;
2116 ce
.xclient
.data
.l
[1] = event_lasttime
;
2117 ce
.xclient
.data
.l
[2] = 0l;
2118 ce
.xclient
.data
.l
[3] = 0l;
2119 ce
.xclient
.data
.l
[4] = 0l;
2120 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
2124 g_message("focusing %lx", self
->window
);
2127 /* Cause the FocusIn to come back to us. Important for desktop switches,
2128 since otherwise we'll have no FocusIn on the queue and send it off to
2129 the focus_backup. */
2130 XSync(ob_display
, FALSE
);
2134 void client_unfocus(Client
*self
)
2136 g_assert(focus_client
== self
);
2138 g_message("client_unfocus");
2140 focus_fallback(Fallback_Unfocusing
);
2143 gboolean
client_focused(Client
*self
)
2145 return self
== focus_client
;
2148 Icon
*client_icon(Client
*self
, int w
, int h
)
2151 /* si is the smallest image >= req */
2152 /* li is the largest image < req */
2153 unsigned long size
, smallest
= 0xffffffff, largest
= 0, si
= 0, li
= 0;
2155 if (!self
->nicons
) return NULL
;
2157 for (i
= 0; i
< self
->nicons
; ++i
) {
2158 size
= self
->icons
[i
].width
* self
->icons
[i
].height
;
2159 if (size
< smallest
&& size
>= (unsigned)(w
* h
)) {
2163 if (size
> largest
&& size
<= (unsigned)(w
* h
)) {
2168 if (largest
== 0) /* didnt find one smaller than the requested size */
2169 return &self
->icons
[si
];
2170 return &self
->icons
[li
];