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 Client
*search_focus_tree(Client
*node
, Client
*skip
);
42 static void client_apply_startup_state(Client
*self
);
43 static Client
*search_modal_tree(Client
*node
, Client
*skip
);
45 static guint
map_hash(Window
*w
) { return *w
; }
46 static gboolean
map_key_comp(Window
*w1
, Window
*w2
) { return *w1
== *w2
; }
50 client_map
= g_hash_table_new((GHashFunc
)map_hash
,
51 (GEqualFunc
)map_key_comp
);
53 /* save the stacking order on startup! */
54 PROP_GET32U(ob_root
, net_client_list_stacking
, window
,
55 client_startup_stack_order
, client_startup_stack_size
);
60 void client_shutdown()
62 g_hash_table_destroy(client_map
);
65 void client_set_list()
67 Window
*windows
, *win_it
;
69 guint size
= g_list_length(client_list
);
71 /* create an array of the window ids */
73 windows
= g_new(Window
, size
);
75 for (it
= client_list
; it
!= NULL
; it
= it
->next
, ++win_it
)
76 *win_it
= ((Client
*)it
->data
)->window
;
80 PROP_SET32A(ob_root
, net_client_list
, window
, windows
, size
);
88 void client_manage_all()
90 unsigned int i
, j
, nchild
;
93 XWindowAttributes attrib
;
95 XQueryTree(ob_display
, ob_root
, &w
, &w
, &children
, &nchild
);
97 /* remove all icon windows from the list */
98 for (i
= 0; i
< nchild
; i
++) {
99 if (children
[i
] == None
) continue;
100 wmhints
= XGetWMHints(ob_display
, children
[i
]);
102 if ((wmhints
->flags
& IconWindowHint
) &&
103 (wmhints
->icon_window
!= children
[i
]))
104 for (j
= 0; j
< nchild
; j
++)
105 if (children
[j
] == wmhints
->icon_window
) {
113 for (i
= 0; i
< nchild
; ++i
) {
114 if (children
[i
] == None
)
116 if (XGetWindowAttributes(ob_display
, children
[i
], &attrib
)) {
117 if (attrib
.override_redirect
) continue;
119 if (attrib
.map_state
!= IsUnmapped
)
120 client_manage(children
[i
]);
125 /* stack them as they were on startup!
126 why with stacking_lower? Why, because then windows who aren't in the
127 stacking list are on the top where you can see them instead of buried
129 for (i
= client_startup_stack_size
; i
> 0; --i
) {
132 w
= client_startup_stack_order
[i
-1];
133 c
= g_hash_table_lookup(client_map
, &w
);
134 if (c
) stacking_lower(c
);
136 g_free(client_startup_stack_order
);
137 client_startup_stack_order
= NULL
;
138 client_startup_stack_size
= 0;
141 focus_fallback(FALSE
);
144 void client_manage(Window window
)
148 XWindowAttributes attrib
;
149 XSetWindowAttributes attrib_set
;
150 /* XWMHints *wmhint; */
155 /* check if it has already been unmapped by the time we started mapping
156 the grab does a sync so we don't have to here */
157 if (XCheckTypedWindowEvent(ob_display
, window
, DestroyNotify
, &e
) ||
158 XCheckTypedWindowEvent(ob_display
, window
, UnmapNotify
, &e
)) {
159 XPutBackEvent(ob_display
, &e
);
162 return; /* don't manage it */
165 /* make sure it isn't an override-redirect window */
166 if (!XGetWindowAttributes(ob_display
, window
, &attrib
) ||
167 attrib
.override_redirect
) {
169 return; /* don't manage it */
172 /* /\* is the window a docking app *\/
173 if ((wmhint = XGetWMHints(ob_display, window))) {
174 if ((wmhint->flags & StateHint) &&
175 wmhint->initial_state == WithdrawnState) {
176 /\* XXX: make dock apps work! *\/
185 /* choose the events we want to receive on the CLIENT window */
186 attrib_set
.event_mask
= CLIENT_EVENTMASK
;
187 attrib_set
.do_not_propagate_mask
= CLIENT_NOPROPAGATEMASK
;
188 XChangeWindowAttributes(ob_display
, window
,
189 CWEventMask
|CWDontPropagate
, &attrib_set
);
192 /* create the Client struct, and populate it from the hints on the
194 client
= g_new(Client
, 1);
195 client
->window
= window
;
196 client_get_all(client
);
198 /* remove the client's border (and adjust re gravity) */
199 client_toggle_border(client
, FALSE
);
201 /* specify that if we exit, the window should not be destroyed and should
202 be reparented back to root automatically */
203 XChangeSaveSet(ob_display
, window
, SetModeInsert
);
205 /* create the decoration frame for the client window */
206 client
->frame
= engine_frame_new();
208 engine_frame_grab_client(client
->frame
, client
);
210 client_apply_startup_state(client
);
214 client_list
= g_list_append(client_list
, client
);
215 stacking_list
= g_list_append(stacking_list
, client
);
216 g_assert(!g_hash_table_lookup(client_map
, &client
->window
));
217 g_hash_table_insert(client_map
, &client
->window
, client
);
219 /* update the focus lists */
220 if (client
->desktop
== DESKTOP_ALL
) {
221 for (i
= 0; i
< screen_num_desktops
; ++i
)
222 focus_order
[i
] = g_list_append(focus_order
[i
], client
);
225 focus_order
[i
] = g_list_append(focus_order
[i
], client
);
228 stacking_raise(client
);
230 screen_update_struts();
232 dispatch_client(Event_Client_New
, client
, 0, 0);
234 client_showhide(client
);
236 dispatch_client(Event_Client_Mapped
, client
, 0, 0);
238 if (ob_state
!= State_Starting
&& focus_new
)
239 client_focus(client
);
241 /* update the list hints */
244 /* g_message("Managed window 0x%lx", window);*/
247 void client_unmanage_all()
249 while (client_list
!= NULL
)
250 client_unmanage(client_list
->data
);
253 void client_unmanage(Client
*client
)
259 /* g_message("Unmanaging window: %lx", client->window);*/
261 dispatch_client(Event_Client_Destroy
, client
, 0, 0);
262 g_assert(client
!= NULL
);
264 /* remove the window from our save set */
265 XChangeSaveSet(ob_display
, client
->window
, SetModeDelete
);
267 /* we dont want events no more */
268 XSelectInput(ob_display
, client
->window
, NoEventMask
);
270 engine_frame_hide(client
->frame
);
272 client_list
= g_list_remove(client_list
, client
);
273 stacking_list
= g_list_remove(stacking_list
, client
);
274 g_hash_table_remove(client_map
, &client
->window
);
276 /* update the focus lists */
277 if (client
->desktop
== DESKTOP_ALL
) {
278 for (i
= 0; i
< screen_num_desktops
; ++i
)
279 focus_order
[i
] = g_list_remove(focus_order
[i
], client
);
282 focus_order
[i
] = g_list_remove(focus_order
[i
], client
);
285 /* once the client is out of the list, update the struts to remove it's
287 screen_update_struts();
289 /* tell our parent(s) that we're gone */
290 if (client
->transient_for
== TRAN_GROUP
) { /* transient of group */
293 for (it
= client
->group
->members
; it
; it
= it
->next
)
294 if (it
->data
!= client
)
295 ((Client
*)it
->data
)->transients
=
296 g_slist_remove(((Client
*)it
->data
)->transients
, client
);
297 } else if (client
->transient_for
) { /* transient of window */
298 client
->transient_for
->transients
=
299 g_slist_remove(client
->transient_for
->transients
, client
);
302 /* tell our transients that we're gone */
303 for (it
= client
->transients
; it
!= NULL
; it
= it
->next
) {
304 if (((Client
*)it
->data
)->transient_for
!= TRAN_GROUP
) {
305 ((Client
*)it
->data
)->transient_for
= NULL
;
306 client_calc_layer(it
->data
);
310 /* remove from its group */
312 group_remove(client
->group
, client
);
314 /* dispatch the unmapped event */
315 dispatch_client(Event_Client_Unmapped
, client
, 0, 0);
316 g_assert(client
!= NULL
);
318 /* give the client its border back */
319 client_toggle_border(client
, TRUE
);
321 /* reparent the window out of the frame, and free the frame */
322 engine_frame_release_client(client
->frame
, client
);
323 client
->frame
= NULL
;
325 if (ob_state
!= State_Exiting
) {
326 /* these values should not be persisted across a window
328 prop_erase(client
->window
, prop_atoms
.net_wm_desktop
);
329 prop_erase(client
->window
, prop_atoms
.net_wm_state
);
331 /* if we're left in an iconic state, the client wont be mapped. this is
332 bad, since we will no longer be managing the window on restart */
334 XMapWindow(ob_display
, client
->window
);
337 /* free all data allocated in the client struct */
338 g_slist_free(client
->transients
);
339 for (j
= 0; j
< client
->nicons
; ++j
)
340 g_free(client
->icons
[j
].data
);
341 if (client
->nicons
> 0)
342 g_free(client
->icons
);
343 g_free(client
->title
);
344 g_free(client
->icon_title
);
345 g_free(client
->name
);
346 g_free(client
->class);
347 g_free(client
->role
);
350 /* update the list hints */
354 static void client_toggle_border(Client
*self
, gboolean show
)
356 /* adjust our idea of where the client is, based on its border. When the
357 border is removed, the client should now be considered to be in a
359 when re-adding the border to the client, the same operation needs to be
361 int oldx
= self
->area
.x
, oldy
= self
->area
.y
;
362 int x
= oldx
, y
= oldy
;
363 switch(self
->gravity
) {
365 case NorthWestGravity
:
367 case SouthWestGravity
:
369 case NorthEastGravity
:
371 case SouthEastGravity
:
372 if (show
) x
-= self
->border_width
* 2;
373 else x
+= self
->border_width
* 2;
380 if (show
) x
-= self
->border_width
;
381 else x
+= self
->border_width
;
384 switch(self
->gravity
) {
386 case NorthWestGravity
:
388 case NorthEastGravity
:
390 case SouthWestGravity
:
392 case SouthEastGravity
:
393 if (show
) y
-= self
->border_width
* 2;
394 else y
+= self
->border_width
* 2;
401 if (show
) y
-= self
->border_width
;
402 else y
+= self
->border_width
;
409 XSetWindowBorderWidth(ob_display
, self
->window
, self
->border_width
);
411 /* move the client so it is back it the right spot _with_ its
413 if (x
!= oldx
|| y
!= oldy
)
414 XMoveWindow(ob_display
, self
->window
, x
, y
);
416 XSetWindowBorderWidth(ob_display
, self
->window
, 0);
420 static void client_get_all(Client
*self
)
422 /* update EVERYTHING!! */
424 self
->ignore_unmaps
= 0;
428 self
->title
= self
->icon_title
= NULL
;
429 self
->name
= self
->class = self
->role
= NULL
;
430 self
->wmstate
= NormalState
;
431 self
->transient
= FALSE
;
432 self
->transients
= NULL
;
433 self
->transient_for
= NULL
;
435 self
->urgent
= FALSE
;
436 self
->positioned
= FALSE
;
437 self
->disabled_decorations
= 0;
441 client_get_area(self
);
442 client_get_desktop(self
);
443 client_get_state(self
);
444 client_get_shaped(self
);
446 client_update_transient_for(self
);
447 client_get_mwm_hints(self
);
448 client_get_type(self
);/* this can change the mwmhints for special cases */
450 client_update_protocols(self
);
452 client_get_gravity(self
); /* get the attribute gravity */
453 client_update_normal_hints(self
); /* this may override the attribute
456 /* got the type, the mwmhints, the protocols, and the normal hints
457 (min/max sizes), so we're ready to set up the decorations/functions */
458 client_setup_decor_and_functions(self
);
460 client_update_wmhints(self
);
461 client_update_title(self
);
462 client_update_icon_title(self
);
463 client_update_class(self
);
464 client_update_strut(self
);
465 client_update_icons(self
);
466 client_update_kwm_icon(self
);
468 /* this makes sure that these windows appear on all desktops */
469 if (self
->type
== Type_Desktop
)
470 self
->desktop
= DESKTOP_ALL
;
472 /* set the desktop hint, to make sure that it always exists, and to
473 reflect any changes we've made here */
474 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, self
->desktop
);
476 client_change_state(self
);
479 static void client_get_area(Client
*self
)
481 XWindowAttributes wattrib
;
484 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
485 g_assert(ret
!= BadWindow
);
487 RECT_SET(self
->area
, wattrib
.x
, wattrib
.y
, wattrib
.width
, wattrib
.height
);
488 self
->border_width
= wattrib
.border_width
;
491 static void client_get_desktop(Client
*self
)
495 if (PROP_GET32(self
->window
, net_wm_desktop
, cardinal
, d
)) {
496 if (d
>= screen_num_desktops
&& d
!= DESKTOP_ALL
)
497 d
= screen_num_desktops
- 1;
500 /* defaults to the current desktop */
501 self
->desktop
= screen_desktop
;
505 static void client_get_state(Client
*self
)
510 self
->modal
= self
->shaded
= self
->max_horz
= self
->max_vert
=
511 self
->fullscreen
= self
->above
= self
->below
= self
->iconic
=
512 self
->skip_taskbar
= self
->skip_pager
= FALSE
;
514 if (PROP_GET32U(self
->window
, net_wm_state
, atom
, state
, num
)) {
516 for (i
= 0; i
< num
; ++i
) {
517 if (state
[i
] == prop_atoms
.net_wm_state_modal
)
519 else if (state
[i
] == prop_atoms
.net_wm_state_shaded
)
521 else if (state
[i
] == prop_atoms
.net_wm_state_hidden
)
523 else if (state
[i
] == prop_atoms
.net_wm_state_skip_taskbar
)
524 self
->skip_taskbar
= TRUE
;
525 else if (state
[i
] == prop_atoms
.net_wm_state_skip_pager
)
526 self
->skip_pager
= TRUE
;
527 else if (state
[i
] == prop_atoms
.net_wm_state_fullscreen
)
528 self
->fullscreen
= TRUE
;
529 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_vert
)
530 self
->max_vert
= TRUE
;
531 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_horz
)
532 self
->max_horz
= TRUE
;
533 else if (state
[i
] == prop_atoms
.net_wm_state_above
)
535 else if (state
[i
] == prop_atoms
.net_wm_state_below
)
543 static void client_get_shaped(Client
*self
)
545 self
->shaped
= FALSE
;
547 if (extensions_shape
) {
552 XShapeSelectInput(ob_display
, self
->window
, ShapeNotifyMask
);
554 XShapeQueryExtents(ob_display
, self
->window
, &s
, &foo
,
555 &foo
, &ufoo
, &ufoo
, &foo
, &foo
, &foo
, &ufoo
,
557 self
->shaped
= (s
!= 0);
562 void client_update_transient_for(Client
*self
)
567 if (XGetTransientForHint(ob_display
, self
->window
, &t
) &&
568 t
!= self
->window
) { /* cant be transient to itself! */
569 self
->transient
= TRUE
;
570 c
= g_hash_table_lookup(client_map
, &t
);
571 g_assert(c
!= self
);/* if this happens then we need to check for it*/
573 if (!c
&& self
->group
) {
574 /* not transient to a client, see if it is transient for a
576 if (t
== self
->group
->leader
||
579 /* window is a transient for its group! */
584 self
->transient
= FALSE
;
586 /* if anything has changed... */
587 if (c
!= self
->transient_for
) {
588 if (self
->transient_for
== TRAN_GROUP
) { /* transient of group */
591 /* remove from old parents */
592 for (it
= self
->group
->members
; it
; it
= it
->next
)
593 if (it
->data
!= self
)
594 ((Client
*)it
->data
)->transients
=
595 g_slist_remove(((Client
*)it
->data
)->transients
, self
);
596 } else if (self
->transient_for
!= NULL
) { /* transient of window */
597 /* remove from old parent */
598 self
->transient_for
->transients
=
599 g_slist_remove(self
->transient_for
->transients
, self
);
601 self
->transient_for
= c
;
602 if (self
->transient_for
== TRAN_GROUP
) { /* transient of group */
605 /* add to new parents */
606 for (it
= self
->group
->members
; it
; it
= it
->next
)
607 if (it
->data
!= self
)
608 ((Client
*)it
->data
)->transients
=
609 g_slist_append(((Client
*)it
->data
)->transients
, self
);
610 } else if (self
->transient_for
!= NULL
) { /* transient of window */
611 /* add to new parent */
612 self
->transient_for
->transients
=
613 g_slist_append(self
->transient_for
->transients
, self
);
618 static void client_get_mwm_hints(Client
*self
)
621 unsigned long *hints
;
623 self
->mwmhints
.flags
= 0; /* default to none */
625 if (PROP_GET32U(self
->window
, motif_wm_hints
, motif_wm_hints
, hints
, num
)) {
626 if (num
>= MWM_ELEMENTS
) {
627 self
->mwmhints
.flags
= hints
[0];
628 self
->mwmhints
.functions
= hints
[1];
629 self
->mwmhints
.decorations
= hints
[2];
635 void client_get_type(Client
*self
)
641 if (PROP_GET32U(self
->window
, net_wm_window_type
, atom
, val
, num
)) {
642 /* use the first value that we know about in the array */
643 for (i
= 0; i
< num
; ++i
) {
644 if (val
[i
] == prop_atoms
.net_wm_window_type_desktop
)
645 self
->type
= Type_Desktop
;
646 else if (val
[i
] == prop_atoms
.net_wm_window_type_dock
)
647 self
->type
= Type_Dock
;
648 else if (val
[i
] == prop_atoms
.net_wm_window_type_toolbar
)
649 self
->type
= Type_Toolbar
;
650 else if (val
[i
] == prop_atoms
.net_wm_window_type_menu
)
651 self
->type
= Type_Menu
;
652 else if (val
[i
] == prop_atoms
.net_wm_window_type_utility
)
653 self
->type
= Type_Utility
;
654 else if (val
[i
] == prop_atoms
.net_wm_window_type_splash
)
655 self
->type
= Type_Splash
;
656 else if (val
[i
] == prop_atoms
.net_wm_window_type_dialog
)
657 self
->type
= Type_Dialog
;
658 else if (val
[i
] == prop_atoms
.net_wm_window_type_normal
)
659 self
->type
= Type_Normal
;
660 else if (val
[i
] == prop_atoms
.kde_net_wm_window_type_override
) {
661 /* prevent this window from getting any decor or
663 self
->mwmhints
.flags
&= (MwmFlag_Functions
|
664 MwmFlag_Decorations
);
665 self
->mwmhints
.decorations
= 0;
666 self
->mwmhints
.functions
= 0;
668 if (self
->type
!= (WindowType
) -1)
669 break; /* grab the first legit type */
674 if (self
->type
== (WindowType
) -1) {
675 /*the window type hint was not set, which means we either classify
676 ourself as a normal window or a dialog, depending on if we are a
679 self
->type
= Type_Dialog
;
681 self
->type
= Type_Normal
;
685 void client_update_protocols(Client
*self
)
688 gulong num_return
, i
;
690 self
->focus_notify
= FALSE
;
691 self
->delete_window
= FALSE
;
693 if (PROP_GET32U(self
->window
, wm_protocols
, atom
, proto
, num_return
)) {
694 for (i
= 0; i
< num_return
; ++i
) {
695 if (proto
[i
] == prop_atoms
.wm_delete_window
) {
696 /* this means we can request the window to close */
697 self
->delete_window
= TRUE
;
698 } else if (proto
[i
] == prop_atoms
.wm_take_focus
)
699 /* if this protocol is requested, then the window will be
700 notified whenever we want it to receive focus */
701 self
->focus_notify
= TRUE
;
707 static void client_get_gravity(Client
*self
)
709 XWindowAttributes wattrib
;
712 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
713 g_assert(ret
!= BadWindow
);
714 self
->gravity
= wattrib
.win_gravity
;
717 void client_update_normal_hints(Client
*self
)
721 int oldgravity
= self
->gravity
;
724 self
->min_ratio
= 0.0f
;
725 self
->max_ratio
= 0.0f
;
726 SIZE_SET(self
->size_inc
, 1, 1);
727 SIZE_SET(self
->base_size
, 0, 0);
728 SIZE_SET(self
->min_size
, 0, 0);
729 SIZE_SET(self
->max_size
, G_MAXINT
, G_MAXINT
);
731 /* get the hints from the window */
732 if (XGetWMNormalHints(ob_display
, self
->window
, &size
, &ret
)) {
733 self
->positioned
= !!(size
.flags
& (PPosition
|USPosition
));
735 if (size
.flags
& PWinGravity
) {
736 self
->gravity
= size
.win_gravity
;
738 /* if the client has a frame, i.e. has already been mapped and
739 is changing its gravity */
740 if (self
->frame
&& self
->gravity
!= oldgravity
) {
741 /* move our idea of the client's position based on its new
743 self
->area
.x
= self
->frame
->area
.x
;
744 self
->area
.y
= self
->frame
->area
.y
;
745 frame_frame_gravity(self
->frame
, &self
->area
.x
, &self
->area
.y
);
749 if (size
.flags
& PAspect
) {
750 if (size
.min_aspect
.y
)
751 self
->min_ratio
= (float)size
.min_aspect
.x
/ size
.min_aspect
.y
;
752 if (size
.max_aspect
.y
)
753 self
->max_ratio
= (float)size
.max_aspect
.x
/ size
.max_aspect
.y
;
756 if (size
.flags
& PMinSize
)
757 SIZE_SET(self
->min_size
, size
.min_width
, size
.min_height
);
759 if (size
.flags
& PMaxSize
)
760 SIZE_SET(self
->max_size
, size
.max_width
, size
.max_height
);
762 if (size
.flags
& PBaseSize
)
763 SIZE_SET(self
->base_size
, size
.base_width
, size
.base_height
);
765 if (size
.flags
& PResizeInc
)
766 SIZE_SET(self
->size_inc
, size
.width_inc
, size
.height_inc
);
770 void client_setup_decor_and_functions(Client
*self
)
772 /* start with everything (cept fullscreen) */
773 self
->decorations
= Decor_Titlebar
| Decor_Handle
| Decor_Border
|
774 Decor_Icon
| Decor_AllDesktops
| Decor_Iconify
| Decor_Maximize
|
776 self
->functions
= Func_Resize
| Func_Move
| Func_Iconify
| Func_Maximize
|
778 if (self
->delete_window
) {
779 self
->decorations
|= Decor_Close
;
780 self
->functions
|= Func_Close
;
783 if (!(self
->min_size
.width
< self
->max_size
.width
||
784 self
->min_size
.height
< self
->max_size
.height
)) {
785 self
->decorations
&= ~(Decor_Maximize
| Decor_Handle
);
786 self
->functions
&= ~(Func_Resize
| Func_Maximize
);
789 switch (self
->type
) {
791 /* normal windows retain all of the possible decorations and
792 functionality, and are the only windows that you can fullscreen */
793 self
->functions
|= Func_Fullscreen
;
797 /* dialogs cannot be maximized */
798 self
->decorations
&= ~Decor_Maximize
;
799 self
->functions
&= ~Func_Maximize
;
805 /* these windows get less functionality */
806 self
->decorations
&= ~(Decor_Iconify
| Decor_Handle
);
807 self
->functions
&= ~(Func_Iconify
| Func_Resize
);
813 /* none of these windows are manipulated by the window manager */
814 self
->decorations
= 0;
819 /* Mwm Hints are applied subtractively to what has already been chosen for
820 decor and functionality */
821 if (self
->mwmhints
.flags
& MwmFlag_Decorations
) {
822 if (! (self
->mwmhints
.decorations
& MwmDecor_All
)) {
823 if (! (self
->mwmhints
.decorations
& MwmDecor_Border
))
824 self
->decorations
&= ~Decor_Border
;
825 if (! (self
->mwmhints
.decorations
& MwmDecor_Handle
))
826 self
->decorations
&= ~Decor_Handle
;
827 if (! (self
->mwmhints
.decorations
& MwmDecor_Title
))
828 self
->decorations
&= ~Decor_Titlebar
;
829 if (! (self
->mwmhints
.decorations
& MwmDecor_Iconify
))
830 self
->decorations
&= ~Decor_Iconify
;
831 if (! (self
->mwmhints
.decorations
& MwmDecor_Maximize
))
832 self
->decorations
&= ~Decor_Maximize
;
836 if (self
->mwmhints
.flags
& MwmFlag_Functions
) {
837 if (! (self
->mwmhints
.functions
& MwmFunc_All
)) {
838 if (! (self
->mwmhints
.functions
& MwmFunc_Resize
))
839 self
->functions
&= ~Func_Resize
;
840 if (! (self
->mwmhints
.functions
& MwmFunc_Move
))
841 self
->functions
&= ~Func_Move
;
842 if (! (self
->mwmhints
.functions
& MwmFunc_Iconify
))
843 self
->functions
&= ~Func_Iconify
;
844 if (! (self
->mwmhints
.functions
& MwmFunc_Maximize
))
845 self
->functions
&= ~Func_Maximize
;
846 /* dont let mwm hints kill the close button
847 if (! (self->mwmhints.functions & MwmFunc_Close))
848 self->functions &= ~Func_Close; */
852 /* can't maximize without moving/resizing */
853 if (!((self
->functions
& Func_Move
) && (self
->functions
& Func_Resize
)))
854 self
->functions
&= ~(Func_Maximize
| Func_Fullscreen
);
856 /* finally, user specified disabled decorations are applied to subtract
858 if (self
->disabled_decorations
& Decor_Titlebar
)
859 self
->decorations
&= ~Decor_Titlebar
;
860 if (self
->disabled_decorations
& Decor_Handle
)
861 self
->decorations
&= ~Decor_Handle
;
862 if (self
->disabled_decorations
& Decor_Border
)
863 self
->decorations
&= ~Decor_Border
;
864 if (self
->disabled_decorations
& Decor_Iconify
)
865 self
->decorations
&= ~Decor_Iconify
;
866 if (self
->disabled_decorations
& Decor_Maximize
)
867 self
->decorations
&= ~Decor_Maximize
;
868 if (self
->disabled_decorations
& Decor_AllDesktops
)
869 self
->decorations
&= ~Decor_AllDesktops
;
870 if (self
->disabled_decorations
& Decor_Shade
)
871 self
->decorations
&= ~Decor_Shade
;
872 if (self
->disabled_decorations
& Decor_Close
)
873 self
->decorations
&= ~Decor_Close
;
875 /* if we don't have a titlebar, then we cannot shade! */
876 if (!(self
->decorations
& Decor_Titlebar
))
877 self
->functions
&= ~Func_Shade
;
879 client_change_allowed_actions(self
);
882 /* change the decors on the frame, and with more/less decorations,
883 we may also need to be repositioned */
884 engine_frame_adjust_area(self
->frame
, TRUE
, TRUE
);
885 /* with new decor, the window's maximized size may change */
886 client_remaximize(self
);
890 static void client_change_allowed_actions(Client
*self
)
895 actions
[num
++] = prop_atoms
.net_wm_action_change_desktop
;
897 if (self
->functions
& Func_Shade
)
898 actions
[num
++] = prop_atoms
.net_wm_action_shade
;
899 if (self
->functions
& Func_Close
)
900 actions
[num
++] = prop_atoms
.net_wm_action_close
;
901 if (self
->functions
& Func_Move
)
902 actions
[num
++] = prop_atoms
.net_wm_action_move
;
903 if (self
->functions
& Func_Iconify
)
904 actions
[num
++] = prop_atoms
.net_wm_action_minimize
;
905 if (self
->functions
& Func_Resize
)
906 actions
[num
++] = prop_atoms
.net_wm_action_resize
;
907 if (self
->functions
& Func_Fullscreen
)
908 actions
[num
++] = prop_atoms
.net_wm_action_fullscreen
;
909 if (self
->functions
& Func_Maximize
) {
910 actions
[num
++] = prop_atoms
.net_wm_action_maximize_horz
;
911 actions
[num
++] = prop_atoms
.net_wm_action_maximize_vert
;
914 PROP_SET32A(self
->window
, net_wm_allowed_actions
, atom
, actions
, num
);
916 /* make sure the window isn't breaking any rules now */
918 if (!(self
->functions
& Func_Shade
) && self
->shaded
) {
919 if (self
->frame
) client_shade(self
, FALSE
);
920 else self
->shaded
= FALSE
;
922 if (!(self
->functions
& Func_Iconify
) && self
->iconic
) {
923 g_message("UNSETTING ICONIC");
924 if (self
->frame
) client_iconify(self
, FALSE
, TRUE
);
925 else self
->iconic
= FALSE
;
927 if (!(self
->functions
& Func_Fullscreen
) && self
->fullscreen
) {
928 if (self
->frame
) client_fullscreen(self
, FALSE
, TRUE
);
929 else self
->fullscreen
= FALSE
;
931 if (!(self
->functions
& Func_Maximize
) && (self
->max_horz
||
933 if (self
->frame
) client_maximize(self
, FALSE
, 0, TRUE
);
934 else self
->max_vert
= self
->max_horz
= FALSE
;
938 void client_remaximize(Client
*self
)
941 if (self
->max_horz
&& self
->max_vert
)
943 else if (self
->max_horz
)
945 else if (self
->max_vert
)
948 return; /* not maximized */
949 self
->max_horz
= self
->max_vert
= FALSE
;
950 client_maximize(self
, TRUE
, dir
, FALSE
);
953 void client_update_wmhints(Client
*self
)
958 /* assume a window takes input if it doesnt specify */
959 self
->can_focus
= TRUE
;
961 if ((hints
= XGetWMHints(ob_display
, self
->window
)) != NULL
) {
962 if (hints
->flags
& InputHint
)
963 self
->can_focus
= hints
->input
;
965 /* only do this when first managing the window *AND* when we aren't
967 if (ob_state
!= State_Starting
&& self
->frame
== NULL
)
968 if (hints
->flags
& StateHint
)
969 self
->iconic
= hints
->initial_state
== IconicState
;
971 if (hints
->flags
& XUrgencyHint
)
974 if (!(hints
->flags
& WindowGroupHint
))
975 hints
->window_group
= None
; /* no group */
976 /* did the group state change? */
977 if (hints
->window_group
!= (self
->group
? self
->group
->leader
: None
)){
978 /* remove from the old group if there was one */
979 if (self
->group
!= NULL
)
980 group_remove(self
->group
, self
);
981 if (hints
->window_group
!= None
)
982 self
->group
= group_add(hints
->window_group
, self
);
984 /* because the self->transient flag wont change from this call,
985 we don't need to update the window's type and such, only its
986 transient_for, and the transients lists of other windows in the
987 group may be affected */
988 client_update_transient_for(self
);
991 if (hints
->flags
& IconPixmapHint
) {
992 client_update_kwm_icon(self
);
993 /* try get the kwm icon first, this is a fallback only */
994 if (self
->pixmap_icon
== None
) {
995 self
->pixmap_icon
= hints
->icon_pixmap
;
996 if (hints
->flags
& IconMaskHint
)
997 self
->pixmap_icon_mask
= hints
->icon_mask
;
999 self
->pixmap_icon_mask
= None
;
1002 engine_frame_adjust_icon(self
->frame
);
1009 if (ur
!= self
->urgent
) {
1011 g_message("Urgent Hint for 0x%lx: %s", self
->window
,
1013 /* fire the urgent callback if we're mapped, otherwise, wait until
1014 after we're mapped */
1016 dispatch_client(Event_Client_Urgent
, self
, self
->urgent
, 0);
1020 void client_update_title(Client
*self
)
1024 g_free(self
->title
);
1027 if (!PROP_GETS(self
->window
, net_wm_name
, utf8
, data
)) {
1028 /* try old x stuff */
1029 if (PROP_GETS(self
->window
, wm_name
, string
, data
)) {
1030 /* convert it to UTF-8 */
1034 u
= g_locale_to_utf8(data
, -1, &r
, &w
, NULL
);
1036 g_warning("Unable to convert string to UTF-8");
1043 data
= g_strdup("Unnamed Window");
1045 PROP_SETS(self
->window
, net_wm_visible_name
, utf8
, data
);
1051 engine_frame_adjust_title(self
->frame
);
1054 void client_update_icon_title(Client
*self
)
1058 g_free(self
->icon_title
);
1061 if (!PROP_GETS(self
->window
, net_wm_icon_name
, utf8
, data
)) {
1062 /* try old x stuff */
1063 if (PROP_GETS(self
->window
, wm_icon_name
, string
, data
)) {
1064 /* convert it to UTF-8 */
1068 u
= g_locale_to_utf8(data
, -1, &r
, &w
, NULL
);
1070 g_warning("Unable to convert string to UTF-8");
1077 data
= g_strdup("Unnamed Window");
1079 PROP_SETS(self
->window
, net_wm_visible_icon_name
, utf8
, data
);
1082 self
->icon_title
= data
;
1085 void client_update_class(Client
*self
)
1091 if (self
->name
) g_free(self
->name
);
1092 if (self
->class) g_free(self
->class);
1093 if (self
->role
) g_free(self
->role
);
1095 self
->name
= self
->class = self
->role
= NULL
;
1097 data
= g_ptr_array_new();
1099 if (PROP_GETSA(self
->window
, wm_class
, string
, data
)) {
1101 self
->name
= g_strdup(g_ptr_array_index(data
, 0));
1103 self
->class = g_strdup(g_ptr_array_index(data
, 1));
1106 for (i
= 0; i
< data
->len
; ++i
)
1107 g_free(g_ptr_array_index(data
, i
));
1108 g_ptr_array_free(data
, TRUE
);
1110 if (PROP_GETS(self
->window
, wm_window_role
, string
, s
))
1111 self
->role
= g_strdup(s
);
1113 if (self
->name
== NULL
) self
->name
= g_strdup("");
1114 if (self
->class == NULL
) self
->class = g_strdup("");
1115 if (self
->role
== NULL
) self
->role
= g_strdup("");
1118 void client_update_strut(Client
*self
)
1122 if (PROP_GET32A(self
->window
, net_wm_strut
, cardinal
, data
, 4)) {
1123 STRUT_SET(self
->strut
, data
[0], data
[2], data
[1], data
[3]);
1126 STRUT_SET(self
->strut
, 0, 0, 0, 0);
1128 /* updating here is pointless while we're being mapped cuz we're not in
1129 the client list yet */
1131 screen_update_struts();
1134 void client_update_icons(Client
*self
)
1137 unsigned long *data
;
1138 unsigned long w
, h
, i
;
1141 for (j
= 0; j
< self
->nicons
; ++j
)
1142 g_free(self
->icons
[j
].data
);
1143 if (self
->nicons
> 0)
1144 g_free(self
->icons
);
1147 if (PROP_GET32U(self
->window
, net_wm_icon
, cardinal
, data
, num
)) {
1148 /* figure out how many valid icons are in here */
1150 while (num
- i
> 2) {
1158 self
->icons
= g_new(Icon
, self
->nicons
);
1160 /* store the icons */
1162 for (j
= 0; j
< self
->nicons
; ++j
) {
1163 w
= self
->icons
[j
].width
= data
[i
++];
1164 h
= self
->icons
[j
].height
= data
[i
++];
1165 self
->icons
[j
].data
=
1166 g_memdup(&data
[i
], w
* h
* sizeof(gulong
));
1175 engine_frame_adjust_icon(self
->frame
);
1178 void client_update_kwm_icon(Client
*self
)
1182 if (PROP_GET32A(self
->window
, kwm_win_icon
, kwm_win_icon
, data
, 2)) {
1183 self
->pixmap_icon
= data
[0];
1184 self
->pixmap_icon_mask
= data
[1];
1187 self
->pixmap_icon
= self
->pixmap_icon_mask
= None
;
1190 engine_frame_adjust_icon(self
->frame
);
1193 static void client_change_state(Client
*self
)
1195 unsigned long state
[2];
1199 state
[0] = self
->wmstate
;
1201 PROP_SET32A(self
->window
, wm_state
, wm_state
, state
, 2);
1205 netstate
[num
++] = prop_atoms
.net_wm_state_modal
;
1207 netstate
[num
++] = prop_atoms
.net_wm_state_shaded
;
1209 netstate
[num
++] = prop_atoms
.net_wm_state_hidden
;
1210 if (self
->skip_taskbar
)
1211 netstate
[num
++] = prop_atoms
.net_wm_state_skip_taskbar
;
1212 if (self
->skip_pager
)
1213 netstate
[num
++] = prop_atoms
.net_wm_state_skip_pager
;
1214 if (self
->fullscreen
)
1215 netstate
[num
++] = prop_atoms
.net_wm_state_fullscreen
;
1217 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_vert
;
1219 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_horz
;
1221 netstate
[num
++] = prop_atoms
.net_wm_state_above
;
1223 netstate
[num
++] = prop_atoms
.net_wm_state_below
;
1224 PROP_SET32A(self
->window
, net_wm_state
, atom
, netstate
, num
);
1226 client_calc_layer(self
);
1229 engine_frame_adjust_state(self
->frame
);
1232 static Client
*search_focus_tree(Client
*node
, Client
*skip
)
1237 for (it
= node
->transients
; it
!= NULL
; it
= it
->next
) {
1238 Client
*c
= it
->data
;
1239 if (c
== skip
) continue; /* circular? */
1240 if ((ret
= search_focus_tree(c
, skip
))) return ret
;
1241 if (client_focused(c
)) return c
;
1246 void client_calc_layer(Client
*self
)
1252 /* are we fullscreen, or do we have a fullscreen transient parent? */
1255 while (c
&& c
!= TRAN_GROUP
) { /* XXX do smthng with the TRAN_GROUP case?*/
1256 if (c
->fullscreen
) {
1260 c
= c
->transient_for
;
1262 if (!fs
&& self
->fullscreen
) {
1263 /* is one of our transients focused? */
1264 c
= search_focus_tree(self
, self
);
1265 if (c
!= NULL
) fs
= TRUE
;
1268 if (self
->iconic
) l
= Layer_Icon
;
1269 else if (fs
) l
= Layer_Fullscreen
;
1270 else if (self
->type
== Type_Desktop
) l
= Layer_Desktop
;
1271 else if (self
->type
== Type_Dock
) {
1272 if (!self
->below
) l
= Layer_Top
;
1273 else l
= Layer_Normal
;
1275 else if (self
->above
) l
= Layer_Above
;
1276 else if (self
->below
) l
= Layer_Below
;
1277 else l
= Layer_Normal
;
1279 if (l
!= self
->layer
) {
1282 stacking_raise(self
);
1286 gboolean
client_should_show(Client
*self
)
1288 if (self
->iconic
) return FALSE
;
1289 else if (!(self
->desktop
== screen_desktop
||
1290 self
->desktop
== DESKTOP_ALL
)) return FALSE
;
1291 else if (client_normal(self
) && screen_showing_desktop
) return FALSE
;
1296 static void client_showhide(Client
*self
)
1299 if (client_should_show(self
))
1300 engine_frame_show(self
->frame
);
1302 engine_frame_hide(self
->frame
);
1305 gboolean
client_normal(Client
*self
) {
1306 return ! (self
->type
== Type_Desktop
|| self
->type
== Type_Dock
||
1307 self
->type
== Type_Splash
);
1310 static void client_apply_startup_state(Client
*self
)
1312 /* these are in a carefully crafted order.. */
1315 self
->iconic
= FALSE
;
1316 client_iconify(self
, TRUE
, FALSE
);
1318 if (self
->fullscreen
) {
1319 self
->fullscreen
= FALSE
;
1320 client_fullscreen(self
, TRUE
, FALSE
);
1323 self
->shaded
= FALSE
;
1324 client_shade(self
, TRUE
);
1327 dispatch_client(Event_Client_Urgent
, self
, self
->urgent
, 0);
1329 if (self
->max_vert
&& self
->max_horz
) {
1330 self
->max_vert
= self
->max_horz
= FALSE
;
1331 client_maximize(self
, TRUE
, 0, FALSE
);
1332 } else if (self
->max_vert
) {
1333 self
->max_vert
= FALSE
;
1334 client_maximize(self
, TRUE
, 2, FALSE
);
1335 } else if (self
->max_horz
) {
1336 self
->max_horz
= FALSE
;
1337 client_maximize(self
, TRUE
, 1, FALSE
);
1340 /* nothing to do for the other states:
1349 void client_configure(Client
*self
, Corner anchor
, int x
, int y
, int w
, int h
,
1350 gboolean user
, gboolean final
)
1352 gboolean moved
= FALSE
, resized
= FALSE
;
1354 /* gets the frame's position */
1355 frame_client_gravity(self
->frame
, &x
, &y
);
1357 /* these positions are frame positions, not client positions */
1359 /* set the size and position if fullscreen */
1360 if (self
->fullscreen
) {
1363 w
= screen_physical_size
.width
;
1364 h
= screen_physical_size
.height
;
1366 /* set the size and position if maximized */
1367 if (self
->max_horz
) {
1368 x
= screen_area(self
->desktop
)->x
- self
->frame
->size
.left
;
1369 w
= screen_area(self
->desktop
)->width
;
1371 if (self
->max_vert
) {
1372 y
= screen_area(self
->desktop
)->y
;
1373 h
= screen_area(self
->desktop
)->height
-
1374 self
->frame
->size
.top
- self
->frame
->size
.bottom
;
1378 /* gets the client's position */
1379 frame_frame_gravity(self
->frame
, &x
, &y
);
1381 /* these override the above states! if you cant move you can't move! */
1383 if (!(self
->functions
& Func_Move
)) {
1387 if (!(self
->functions
& Func_Resize
)) {
1388 w
= self
->area
.width
;
1389 h
= self
->area
.height
;
1393 if (!(w
== self
->area
.width
&& h
== self
->area
.height
)) {
1394 w
-= self
->base_size
.width
;
1395 h
-= self
->base_size
.height
;
1398 /* for interactive resizing. have to move half an increment in each
1401 /* how far we are towards the next size inc */
1402 int mw
= w
% self
->size_inc
.width
;
1403 int mh
= h
% self
->size_inc
.height
;
1405 int aw
= self
->size_inc
.width
/ 2;
1406 int ah
= self
->size_inc
.height
/ 2;
1407 /* don't let us move into a new size increment */
1408 if (mw
+ aw
>= self
->size_inc
.width
)
1409 aw
= self
->size_inc
.width
- mw
- 1;
1410 if (mh
+ ah
>= self
->size_inc
.height
)
1411 ah
= self
->size_inc
.height
- mh
- 1;
1415 /* if this is a user-requested resize, then check against min/max
1416 sizes and aspect ratios */
1418 /* smaller than min size or bigger than max size? */
1419 if (w
> self
->max_size
.width
) w
= self
->max_size
.width
;
1420 if (w
< self
->min_size
.width
) w
= self
->min_size
.width
;
1421 if (h
> self
->max_size
.height
) h
= self
->max_size
.height
;
1422 if (h
< self
->min_size
.height
) h
= self
->min_size
.height
;
1424 /* adjust the height ot match the width for the aspect ratios */
1425 if (self
->min_ratio
)
1426 if (h
* self
->min_ratio
> w
) h
= (int)(w
/ self
->min_ratio
);
1427 if (self
->max_ratio
)
1428 if (h
* self
->max_ratio
< w
) h
= (int)(w
/ self
->max_ratio
);
1431 /* keep to the increments */
1432 w
/= self
->size_inc
.width
;
1433 h
/= self
->size_inc
.height
;
1435 /* you cannot resize to nothing */
1439 /* store the logical size */
1440 SIZE_SET(self
->logical_size
, w
, h
);
1442 w
*= self
->size_inc
.width
;
1443 h
*= self
->size_inc
.height
;
1445 w
+= self
->base_size
.width
;
1446 h
+= self
->base_size
.height
;
1450 case Corner_TopLeft
:
1452 case Corner_TopRight
:
1453 x
-= w
- self
->area
.width
;
1455 case Corner_BottomLeft
:
1456 y
-= h
- self
->area
.height
;
1458 case Corner_BottomRight
:
1459 x
-= w
- self
->area
.width
;
1460 y
-= h
- self
->area
.height
;
1464 moved
= x
!= self
->area
.x
|| y
!= self
->area
.y
;
1465 resized
= w
!= self
->area
.width
|| h
!= self
->area
.height
;
1467 RECT_SET(self
->area
, x
, y
, w
, h
);
1470 XResizeWindow(ob_display
, self
->window
, w
, h
);
1472 /* move/resize the frame to match the request */
1474 if (moved
|| resized
)
1475 engine_frame_adjust_area(self
->frame
, moved
, resized
);
1477 if (!user
|| final
) {
1479 event
.type
= ConfigureNotify
;
1480 event
.xconfigure
.display
= ob_display
;
1481 event
.xconfigure
.event
= self
->window
;
1482 event
.xconfigure
.window
= self
->window
;
1484 /* root window coords with border in mind */
1485 event
.xconfigure
.x
= x
- self
->border_width
+
1486 self
->frame
->size
.left
;
1487 event
.xconfigure
.y
= y
- self
->border_width
+
1488 self
->frame
->size
.top
;
1490 event
.xconfigure
.width
= self
->area
.width
;
1491 event
.xconfigure
.height
= self
->area
.height
;
1492 event
.xconfigure
.border_width
= self
->border_width
;
1493 event
.xconfigure
.above
= self
->frame
->plate
;
1494 event
.xconfigure
.override_redirect
= FALSE
;
1495 XSendEvent(event
.xconfigure
.display
, event
.xconfigure
.window
,
1496 FALSE
, StructureNotifyMask
, &event
);
1501 void client_fullscreen(Client
*self
, gboolean fs
, gboolean savearea
)
1505 if (!(self
->functions
& Func_Fullscreen
) || /* can't */
1506 self
->fullscreen
== fs
) return; /* already done */
1508 self
->fullscreen
= fs
;
1509 client_change_state(self
); /* change the state hints on the client */
1512 /* save the functions and remove them */
1513 self
->pre_fs_func
= self
->functions
;
1514 self
->functions
&= (Func_Close
| Func_Fullscreen
|
1516 /* save the decorations and remove them */
1517 self
->pre_fs_decor
= self
->decorations
;
1518 self
->decorations
= 0;
1521 dimensions
[0] = self
->area
.x
;
1522 dimensions
[1] = self
->area
.y
;
1523 dimensions
[2] = self
->area
.width
;
1524 dimensions
[3] = self
->area
.height
;
1526 PROP_SET32A(self
->window
, openbox_premax
, cardinal
,
1530 /* these are not actually used cuz client_configure will set them
1531 as appropriate when the window is fullscreened */
1536 self
->functions
= self
->pre_fs_func
;
1537 self
->decorations
= self
->pre_fs_decor
;
1539 if (PROP_GET32A(self
->window
, openbox_premax
, cardinal
,
1547 /* pick some fallbacks... */
1548 x
= screen_area(self
->desktop
)->x
+
1549 screen_area(self
->desktop
)->width
/ 4;
1550 y
= screen_area(self
->desktop
)->y
+
1551 screen_area(self
->desktop
)->height
/ 4;
1552 w
= screen_area(self
->desktop
)->width
/ 2;
1553 h
= screen_area(self
->desktop
)->height
/ 2;
1557 client_change_allowed_actions(self
); /* based on the new _functions */
1559 /* when fullscreening, don't obey things like increments, fill the
1561 client_configure(self
, Corner_TopLeft
, x
, y
, w
, h
, !fs
, TRUE
);
1563 /* raise (back) into our stacking layer */
1564 stacking_raise(self
);
1566 /* try focus us when we go into fullscreen mode */
1570 void client_iconify(Client
*self
, gboolean iconic
, gboolean curdesk
)
1572 if (self
->iconic
== iconic
) return; /* nothing to do */
1574 g_message("%sconifying window: 0x%lx", (iconic
? "I" : "Uni"),
1577 self
->iconic
= iconic
;
1580 self
->wmstate
= IconicState
;
1581 self
->ignore_unmaps
++;
1582 /* we unmap the client itself so that we can get MapRequest events,
1583 and because the ICCCM tells us to! */
1584 XUnmapWindow(ob_display
, self
->window
);
1587 client_set_desktop(self
, screen_desktop
, FALSE
);
1588 self
->wmstate
= self
->shaded
? IconicState
: NormalState
;
1589 XMapWindow(ob_display
, self
->window
);
1591 client_change_state(self
);
1592 client_showhide(self
);
1593 screen_update_struts();
1595 dispatch_client(iconic
? Event_Client_Unmapped
: Event_Client_Mapped
,
1598 /* iconify all transients */
1599 if (self
->transients
) {
1602 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
)
1603 if (it
->data
!= self
) client_iconify(it
->data
, iconic
, curdesk
);
1607 void client_maximize(Client
*self
, gboolean max
, int dir
, gboolean savearea
)
1611 g_assert(dir
== 0 || dir
== 1 || dir
== 2);
1612 if (!(self
->functions
& Func_Maximize
)) return; /* can't */
1614 /* check if already done */
1616 if (dir
== 0 && self
->max_horz
&& self
->max_vert
) return;
1617 if (dir
== 1 && self
->max_horz
) return;
1618 if (dir
== 2 && self
->max_vert
) return;
1620 if (dir
== 0 && !self
->max_horz
&& !self
->max_vert
) return;
1621 if (dir
== 1 && !self
->max_horz
) return;
1622 if (dir
== 2 && !self
->max_vert
) return;
1625 /* work with the frame's coords */
1626 x
= self
->frame
->area
.x
;
1627 y
= self
->frame
->area
.y
;
1628 w
= self
->area
.width
;
1629 h
= self
->area
.height
;
1641 /* get the property off the window and use it for the dimensions
1642 we are already maxed on */
1643 if (PROP_GET32A(self
->window
, openbox_premax
, cardinal
,
1645 if (self
->max_horz
) {
1646 dimensions
[0] = readdim
[0];
1647 dimensions
[2] = readdim
[2];
1649 if (self
->max_vert
) {
1650 dimensions
[1] = readdim
[1];
1651 dimensions
[3] = readdim
[3];
1656 PROP_SET32A(self
->window
, openbox_premax
, cardinal
,
1662 if (PROP_GET32A(self
->window
, openbox_premax
, cardinal
,
1664 if (dir
== 0 || dir
== 1) { /* horz */
1668 if (dir
== 0 || dir
== 2) { /* vert */
1674 /* pick some fallbacks... */
1675 if (dir
== 0 || dir
== 1) { /* horz */
1676 x
= screen_area(self
->desktop
)->x
+
1677 screen_area(self
->desktop
)->width
/ 4;
1678 w
= screen_area(self
->desktop
)->width
/ 2;
1680 if (dir
== 0 || dir
== 2) { /* vert */
1681 y
= screen_area(self
->desktop
)->y
+
1682 screen_area(self
->desktop
)->height
/ 4;
1683 h
= screen_area(self
->desktop
)->height
/ 2;
1688 if (dir
== 0 || dir
== 1) /* horz */
1689 self
->max_horz
= max
;
1690 if (dir
== 0 || dir
== 2) /* vert */
1691 self
->max_vert
= max
;
1693 if (!self
->max_horz
&& !self
->max_vert
)
1694 PROP_ERASE(self
->window
, openbox_premax
);
1696 client_change_state(self
); /* change the state hints on the client */
1698 /* figure out where the client should be going */
1699 frame_frame_gravity(self
->frame
, &x
, &y
);
1700 client_configure(self
, Corner_TopLeft
, x
, y
, w
, h
, TRUE
, TRUE
);
1703 void client_shade(Client
*self
, gboolean shade
)
1705 if ((!(self
->functions
& Func_Shade
) && shade
) || /* can't shade */
1706 self
->shaded
== shade
) return; /* already done */
1708 /* when we're iconic, don't change the wmstate */
1710 self
->wmstate
= shade
? IconicState
: NormalState
;
1711 self
->shaded
= shade
;
1712 client_change_state(self
);
1713 /* resize the frame to just the titlebar */
1714 engine_frame_adjust_area(self
->frame
, FALSE
, FALSE
);
1717 void client_close(Client
*self
)
1721 if (!(self
->functions
& Func_Close
)) return;
1724 XXX: itd be cool to do timeouts and shit here for killing the client's
1726 like... if the window is around after 5 seconds, then the close button
1727 turns a nice red, and if this function is called again, the client is
1731 ce
.xclient
.type
= ClientMessage
;
1732 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
1733 ce
.xclient
.display
= ob_display
;
1734 ce
.xclient
.window
= self
->window
;
1735 ce
.xclient
.format
= 32;
1736 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_delete_window
;
1737 ce
.xclient
.data
.l
[1] = event_lasttime
;
1738 ce
.xclient
.data
.l
[2] = 0l;
1739 ce
.xclient
.data
.l
[3] = 0l;
1740 ce
.xclient
.data
.l
[4] = 0l;
1741 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
1744 void client_kill(Client
*self
)
1746 XKillClient(ob_display
, self
->window
);
1749 void client_set_desktop(Client
*self
, guint target
, gboolean donthide
)
1753 if (target
== self
->desktop
) return;
1755 g_message("Setting desktop %u", target
);
1757 g_assert(target
< screen_num_desktops
|| target
== DESKTOP_ALL
);
1759 old
= self
->desktop
;
1760 self
->desktop
= target
;
1761 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, target
);
1762 /* the frame can display the current desktop state */
1763 engine_frame_adjust_state(self
->frame
);
1764 /* 'move' the window to the new desktop */
1766 client_showhide(self
);
1767 /* raise if it was not already on the desktop */
1768 if (old
!= DESKTOP_ALL
)
1769 stacking_raise(self
);
1770 screen_update_struts();
1772 /* update the focus lists */
1773 if (old
== DESKTOP_ALL
) {
1774 for (i
= 0; i
< screen_num_desktops
; ++i
)
1775 focus_order
[i
] = g_list_remove(focus_order
[i
], self
);
1777 focus_order
[old
] = g_list_remove(focus_order
[old
], self
);
1778 if (target
== DESKTOP_ALL
) {
1779 for (i
= 0; i
< screen_num_desktops
; ++i
) {
1781 focus_order
[i
] = g_list_prepend(focus_order
[i
], self
);
1783 focus_order
[i
] = g_list_append(focus_order
[i
], self
);
1787 focus_order
[target
] = g_list_prepend(focus_order
[target
], self
);
1789 focus_order
[target
] = g_list_append(focus_order
[target
], self
);
1792 dispatch_client(Event_Client_Desktop
, self
, target
, old
);
1795 static Client
*search_modal_tree(Client
*node
, Client
*skip
)
1800 for (it
= node
->transients
; it
!= NULL
; it
= it
->next
) {
1801 Client
*c
= it
->data
;
1802 if (c
== skip
) continue; /* circular? */
1803 if ((ret
= search_modal_tree(c
, skip
))) return ret
;
1804 if (c
->modal
) return c
;
1809 Client
*client_find_modal_child(Client
*self
)
1811 return search_modal_tree(self
, self
);
1814 gboolean
client_validate(Client
*self
)
1818 XSync(ob_display
, FALSE
); /* get all events on the server */
1820 if (XCheckTypedWindowEvent(ob_display
, self
->window
, DestroyNotify
, &e
) ||
1821 XCheckTypedWindowEvent(ob_display
, self
->window
, UnmapNotify
, &e
)) {
1822 XPutBackEvent(ob_display
, &e
);
1829 void client_set_wm_state(Client
*self
, long state
)
1831 if (state
== self
->wmstate
) return; /* no change */
1835 client_iconify(self
, TRUE
, TRUE
);
1838 client_iconify(self
, FALSE
, TRUE
);
1843 void client_set_state(Client
*self
, Atom action
, long data1
, long data2
)
1845 gboolean shaded
= self
->shaded
;
1846 gboolean fullscreen
= self
->fullscreen
;
1847 gboolean max_horz
= self
->max_horz
;
1848 gboolean max_vert
= self
->max_vert
;
1851 if (!(action
== prop_atoms
.net_wm_state_add
||
1852 action
== prop_atoms
.net_wm_state_remove
||
1853 action
== prop_atoms
.net_wm_state_toggle
))
1854 /* an invalid action was passed to the client message, ignore it */
1857 for (i
= 0; i
< 2; ++i
) {
1858 Atom state
= i
== 0 ? data1
: data2
;
1860 if (!state
) continue;
1862 /* if toggling, then pick whether we're adding or removing */
1863 if (action
== prop_atoms
.net_wm_state_toggle
) {
1864 if (state
== prop_atoms
.net_wm_state_modal
)
1865 action
= self
->modal
? prop_atoms
.net_wm_state_remove
:
1866 prop_atoms
.net_wm_state_add
;
1867 else if (state
== prop_atoms
.net_wm_state_maximized_vert
)
1868 action
= self
->max_vert
? prop_atoms
.net_wm_state_remove
:
1869 prop_atoms
.net_wm_state_add
;
1870 else if (state
== prop_atoms
.net_wm_state_maximized_horz
)
1871 action
= self
->max_horz
? prop_atoms
.net_wm_state_remove
:
1872 prop_atoms
.net_wm_state_add
;
1873 else if (state
== prop_atoms
.net_wm_state_shaded
)
1874 action
= self
->shaded
? prop_atoms
.net_wm_state_remove
:
1875 prop_atoms
.net_wm_state_add
;
1876 else if (state
== prop_atoms
.net_wm_state_skip_taskbar
)
1877 action
= self
->skip_taskbar
?
1878 prop_atoms
.net_wm_state_remove
:
1879 prop_atoms
.net_wm_state_add
;
1880 else if (state
== prop_atoms
.net_wm_state_skip_pager
)
1881 action
= self
->skip_pager
?
1882 prop_atoms
.net_wm_state_remove
:
1883 prop_atoms
.net_wm_state_add
;
1884 else if (state
== prop_atoms
.net_wm_state_fullscreen
)
1885 action
= self
->fullscreen
?
1886 prop_atoms
.net_wm_state_remove
:
1887 prop_atoms
.net_wm_state_add
;
1888 else if (state
== prop_atoms
.net_wm_state_above
)
1889 action
= self
->above
? prop_atoms
.net_wm_state_remove
:
1890 prop_atoms
.net_wm_state_add
;
1891 else if (state
== prop_atoms
.net_wm_state_below
)
1892 action
= self
->below
? prop_atoms
.net_wm_state_remove
:
1893 prop_atoms
.net_wm_state_add
;
1896 if (action
== prop_atoms
.net_wm_state_add
) {
1897 if (state
== prop_atoms
.net_wm_state_modal
) {
1898 /* XXX raise here or something? */
1900 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
1902 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
1904 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
1906 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
1907 self
->skip_taskbar
= TRUE
;
1908 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
1909 self
->skip_pager
= TRUE
;
1910 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
1912 } else if (state
== prop_atoms
.net_wm_state_above
) {
1914 } else if (state
== prop_atoms
.net_wm_state_below
) {
1918 } else { /* action == prop_atoms.net_wm_state_remove */
1919 if (state
== prop_atoms
.net_wm_state_modal
) {
1920 self
->modal
= FALSE
;
1921 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
1923 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
1925 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
1927 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
1928 self
->skip_taskbar
= FALSE
;
1929 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
1930 self
->skip_pager
= FALSE
;
1931 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
1933 } else if (state
== prop_atoms
.net_wm_state_above
) {
1934 self
->above
= FALSE
;
1935 } else if (state
== prop_atoms
.net_wm_state_below
) {
1936 self
->below
= FALSE
;
1940 if (max_horz
!= self
->max_horz
|| max_vert
!= self
->max_vert
) {
1941 if (max_horz
!= self
->max_horz
&& max_vert
!= self
->max_vert
) {
1943 if (max_horz
== max_vert
) { /* both going the same way */
1944 client_maximize(self
, max_horz
, 0, TRUE
);
1946 client_maximize(self
, max_horz
, 1, TRUE
);
1947 client_maximize(self
, max_vert
, 2, TRUE
);
1951 if (max_horz
!= self
->max_horz
)
1952 client_maximize(self
, max_horz
, 1, TRUE
);
1954 client_maximize(self
, max_vert
, 2, TRUE
);
1957 /* change fullscreen state before shading, as it will affect if the window
1959 if (fullscreen
!= self
->fullscreen
)
1960 client_fullscreen(self
, fullscreen
, TRUE
);
1961 if (shaded
!= self
->shaded
)
1962 client_shade(self
, shaded
);
1963 client_calc_layer(self
);
1964 client_change_state(self
); /* change the hint to relect these changes */
1967 Client
*client_focus_target(Client
*self
)
1971 /* if we have a modal child, then focus it, not us */
1972 child
= client_find_modal_child(self
);
1973 if (child
) return child
;
1977 gboolean
client_focusable(Client
*self
)
1979 /* won't try focus if the client doesn't want it, or if the window isn't
1980 visible on the screen */
1981 return self
->frame
->visible
&&
1982 (self
->can_focus
|| self
->focus_notify
);
1985 gboolean
client_focus(Client
*self
)
1989 /* choose the correct target */
1990 self
= client_focus_target(self
);
1992 if (!client_focusable(self
))
1995 /* do a check to see if the window has already been unmapped or destroyed
1996 do this intelligently while watching out for unmaps we've generated
1997 (ignore_unmaps > 0) */
1998 if (XCheckTypedWindowEvent(ob_display
, self
->window
,
1999 DestroyNotify
, &ev
)) {
2000 XPutBackEvent(ob_display
, &ev
);
2003 while (XCheckTypedWindowEvent(ob_display
, self
->window
,
2004 UnmapNotify
, &ev
)) {
2005 if (self
->ignore_unmaps
) {
2006 self
->ignore_unmaps
--;
2008 XPutBackEvent(ob_display
, &ev
);
2013 if (self
->can_focus
)
2014 /* RevertToPointerRoot causes much more headache than TevertToNone, so
2015 I choose to use it always, hopefully to find errors quicker, if any
2016 are left. (I hate X. I hate focus events.) */
2017 XSetInputFocus(ob_display
, self
->window
, RevertToPointerRoot
,
2020 if (self
->focus_notify
) {
2022 ce
.xclient
.type
= ClientMessage
;
2023 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
2024 ce
.xclient
.display
= ob_display
;
2025 ce
.xclient
.window
= self
->window
;
2026 ce
.xclient
.format
= 32;
2027 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_take_focus
;
2028 ce
.xclient
.data
.l
[1] = event_lasttime
;
2029 ce
.xclient
.data
.l
[2] = 0l;
2030 ce
.xclient
.data
.l
[3] = 0l;
2031 ce
.xclient
.data
.l
[4] = 0l;
2032 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
2036 g_message("focusing %lx", self
->window
);
2039 /* Cause the FocusIn to come back to us. Important for desktop switches,
2040 since otherwise we'll have no FocusIn on the queue and send it off to
2041 the focus_backup. */
2042 XSync(ob_display
, FALSE
);
2046 void client_unfocus(Client
*self
)
2048 g_assert(focus_client
== self
);
2049 g_message("client_unfocus");
2050 focus_fallback(FALSE
);
2053 gboolean
client_focused(Client
*self
)
2055 return self
== focus_client
;
2058 Icon
*client_icon(Client
*self
, int w
, int h
)
2061 /* si is the smallest image >= req */
2062 /* li is the largest image < req */
2063 unsigned long size
, smallest
= 0xffffffff, largest
= 0, si
= 0, li
= 0;
2065 if (!self
->nicons
) return NULL
;
2067 for (i
= 0; i
< self
->nicons
; ++i
) {
2068 size
= self
->icons
[i
].width
* self
->icons
[i
].height
;
2069 if (size
< smallest
&& size
>= (unsigned)(w
* h
)) {
2073 if (size
> largest
&& size
<= (unsigned)(w
* h
)) {
2078 if (largest
== 0) /* didnt find one smaller than the requested size */
2079 return &self
->icons
[si
];
2080 return &self
->icons
[li
];