4 #include "extensions.h"
14 #include <X11/Xutil.h>
16 /*! The event mask to grab on client windows */
17 #define CLIENT_EVENTMASK (PropertyChangeMask | FocusChangeMask | \
20 #define CLIENT_NOPROPAGATEMASK (ButtonPressMask | ButtonReleaseMask | \
23 GSList
*client_list
= NULL
;
24 GHashTable
*client_map
= NULL
;
26 static void client_get_all(Client
*self
);
27 static void client_toggle_border(Client
*self
, gboolean show
);
28 static void client_get_area(Client
*self
);
29 static void client_get_desktop(Client
*self
);
30 static void client_get_state(Client
*self
);
31 static void client_get_shaped(Client
*self
);
32 static void client_get_mwm_hints(Client
*self
);
33 static void client_get_gravity(Client
*self
);
34 static void client_showhide(Client
*self
);
35 static void client_change_allowed_actions(Client
*self
);
36 static void client_change_state(Client
*self
);
37 static Client
*search_focus_tree(Client
*node
, Client
*skip
);
38 static void client_apply_startup_state(Client
*self
);
39 static Client
*search_modal_tree(Client
*node
, Client
*skip
);
41 static guint
map_hash(Window w
) { return w
; }
42 static gboolean
map_key_comp(Window w1
, Window w2
) { return w1
== w2
; }
46 client_map
= g_hash_table_new((GHashFunc
)map_hash
,
47 (GEqualFunc
)map_key_comp
);
51 void client_shutdown()
53 g_hash_table_destroy(client_map
);
56 void client_set_list()
58 Window
*windows
, *win_it
;
60 guint size
= g_slist_length(client_list
);
62 /* create an array of the window ids */
64 windows
= g_new(Window
, size
);
66 for (it
= client_list
; it
!= NULL
; it
= it
->next
, ++win_it
)
67 *win_it
= ((Client
*)it
->data
)->window
;
71 PROP_SET32A(ob_root
, net_client_list
, window
, windows
, size
);
79 void client_manage_all()
81 unsigned int i
, j
, nchild
;
84 XWindowAttributes attrib
;
86 XQueryTree(ob_display
, ob_root
, &w
, &w
, &children
, &nchild
);
88 /* remove all icon windows from the list */
89 for (i
= 0; i
< nchild
; i
++) {
90 if (children
[i
] == None
) continue;
91 wmhints
= XGetWMHints(ob_display
, children
[i
]);
93 if ((wmhints
->flags
& IconWindowHint
) &&
94 (wmhints
->icon_window
!= children
[i
]))
95 for (j
= 0; j
< nchild
; j
++)
96 if (children
[j
] == wmhints
->icon_window
) {
104 for (i
= 0; i
< nchild
; ++i
) {
105 if (children
[i
] == None
)
107 if (XGetWindowAttributes(ob_display
, children
[i
], &attrib
)) {
108 if (attrib
.override_redirect
) continue;
110 if (attrib
.map_state
!= IsUnmapped
)
111 client_manage(children
[i
]);
117 void client_manage(Window window
)
121 XWindowAttributes attrib
;
122 XSetWindowAttributes attrib_set
;
123 /* XWMHints *wmhint; */
128 /* check if it has already been unmapped by the time we started mapping
129 the grab does a sync so we don't have to here */
130 if (XCheckTypedWindowEvent(ob_display
, window
, DestroyNotify
, &e
) ||
131 XCheckTypedWindowEvent(ob_display
, window
, UnmapNotify
, &e
)) {
132 XPutBackEvent(ob_display
, &e
);
135 return; /* don't manage it */
138 /* make sure it isn't an override-redirect window */
139 if (!XGetWindowAttributes(ob_display
, window
, &attrib
) ||
140 attrib
.override_redirect
) {
142 return; /* don't manage it */
145 /* /\* is the window a docking app *\/
146 if ((wmhint = XGetWMHints(ob_display, window))) {
147 if ((wmhint->flags & StateHint) &&
148 wmhint->initial_state == WithdrawnState) {
149 /\* XXX: make dock apps work! *\/
158 /* choose the events we want to receive on the CLIENT window */
159 attrib_set
.event_mask
= CLIENT_EVENTMASK
;
160 attrib_set
.do_not_propagate_mask
= CLIENT_NOPROPAGATEMASK
;
161 XChangeWindowAttributes(ob_display
, window
,
162 CWEventMask
|CWDontPropagate
, &attrib_set
);
165 /* create the Client struct, and populate it from the hints on the
167 client
= g_new(Client
, 1);
168 client
->window
= window
;
169 client_get_all(client
);
171 /* remove the client's border (and adjust re gravity) */
172 client_toggle_border(client
, FALSE
);
174 /* specify that if we exit, the window should not be destroyed and should
175 be reparented back to root automatically */
176 XChangeSaveSet(ob_display
, window
, SetModeInsert
);
178 /* create the decoration frame for the client window */
179 client
->frame
= engine_frame_new();
181 engine_frame_grab_client(client
->frame
, client
);
183 client_apply_startup_state(client
);
187 client_list
= g_slist_append(client_list
, client
);
188 stacking_list
= g_list_append(stacking_list
, client
);
189 g_hash_table_insert(client_map
, (gpointer
)window
, client
);
191 /* update the focus lists */
192 if (client
->desktop
== DESKTOP_ALL
) {
193 for (i
= 0; i
< screen_num_desktops
; ++i
)
194 focus_order
[i
] = g_list_append(focus_order
[i
], client
);
197 focus_order
[i
] = g_list_append(focus_order
[i
], client
);
200 stacking_raise(client
);
202 screen_update_struts();
204 dispatch_client(Event_Client_New
, client
, 0, 0);
206 client_showhide(client
);
208 dispatch_client(Event_Client_Mapped
, client
, 0, 0);
210 /* update the list hints */
213 g_message("Managed window 0x%lx", window
);
216 void client_unmanage_all()
218 while (client_list
!= NULL
)
219 client_unmanage(client_list
->data
);
222 void client_unmanage(Client
*client
)
228 g_message("Unmanaging window: %lx", client
->window
);
230 dispatch_client(Event_Client_Destroy
, client
, 0, 0);
232 /* remove the window from our save set */
233 XChangeSaveSet(ob_display
, client
->window
, SetModeDelete
);
235 /* we dont want events no more */
236 XSelectInput(ob_display
, client
->window
, NoEventMask
);
238 engine_frame_hide(client
->frame
);
240 /* dispatch the unmapped event */
241 dispatch_client(Event_Client_Unmapped
, client
, 0, 0);
243 /* give the client its border back */
244 client_toggle_border(client
, TRUE
);
246 /* reparent the window out of the frame, and free the frame */
247 engine_frame_release_client(client
->frame
, client
);
248 client
->frame
= NULL
;
250 client_list
= g_slist_remove(client_list
, client
);
251 stacking_list
= g_list_remove(stacking_list
, client
);
252 g_hash_table_remove(client_map
, (gpointer
)client
->window
);
254 /* update the focus lists */
255 if (client
->desktop
== DESKTOP_ALL
) {
256 for (i
= 0; i
< screen_num_desktops
; ++i
)
257 focus_order
[i
] = g_list_remove(focus_order
[i
], client
);
260 focus_order
[i
] = g_list_remove(focus_order
[i
], client
);
263 /* once the client is out of the list, update the struts to remove it's
265 screen_update_struts();
267 /* tell our parent that we're gone */
268 if (client
->transient_for
!= NULL
)
269 client
->transient_for
->transients
=
270 g_slist_remove(client
->transient_for
->transients
, client
);
272 /* tell our transients that we're gone */
273 for (it
= client
->transients
; it
!= NULL
; it
= it
->next
) {
274 ((Client
*)it
->data
)->transient_for
= NULL
;
275 client_calc_layer(it
->data
);
278 /* unfocus the client (dispatchs the focus event) (we're out of the
279 transient lists already, so being modal doesn't matter) */
280 if (client_focused(client
))
281 client_unfocus(client
);
283 if (ob_state
!= State_Exiting
) {
284 /* these values should not be persisted across a window
286 prop_erase(client
->window
, prop_atoms
.net_wm_desktop
);
287 prop_erase(client
->window
, prop_atoms
.net_wm_state
);
289 /* if we're left in an iconic state, the client wont be mapped. this is
290 bad, since we will no longer be managing the window on restart */
292 XMapWindow(ob_display
, client
->window
);
295 /* free all data allocated in the client struct */
296 g_slist_free(client
->transients
);
297 for (j
= 0; j
< client
->nicons
; ++j
)
298 g_free(client
->icons
[j
].data
);
299 if (client
->nicons
> 0)
300 g_free(client
->icons
);
301 g_free(client
->title
);
302 g_free(client
->icon_title
);
303 g_free(client
->res_name
);
304 g_free(client
->res_class
);
305 g_free(client
->role
);
308 /* update the list hints */
312 static void client_toggle_border(Client
*self
, gboolean show
)
314 /* adjust our idea of where the client is, based on its border. When the
315 border is removed, the client should now be considered to be in a
317 when re-adding the border to the client, the same operation needs to be
319 int oldx
= self
->area
.x
, oldy
= self
->area
.y
;
320 int x
= oldx
, y
= oldy
;
321 switch(self
->gravity
) {
323 case NorthWestGravity
:
325 case SouthWestGravity
:
327 case NorthEastGravity
:
329 case SouthEastGravity
:
330 if (show
) x
-= self
->border_width
* 2;
331 else x
+= self
->border_width
* 2;
338 if (show
) x
-= self
->border_width
;
339 else x
+= self
->border_width
;
342 switch(self
->gravity
) {
344 case NorthWestGravity
:
346 case NorthEastGravity
:
348 case SouthWestGravity
:
350 case SouthEastGravity
:
351 if (show
) y
-= self
->border_width
* 2;
352 else y
+= self
->border_width
* 2;
359 if (show
) y
-= self
->border_width
;
360 else y
+= self
->border_width
;
367 XSetWindowBorderWidth(ob_display
, self
->window
, self
->border_width
);
369 /* move the client so it is back it the right spot _with_ its
371 if (x
!= oldx
|| y
!= oldy
)
372 XMoveWindow(ob_display
, self
->window
, x
, y
);
374 XSetWindowBorderWidth(ob_display
, self
->window
, 0);
378 static void client_get_all(Client
*self
)
380 /* update EVERYTHING!! */
382 self
->ignore_unmaps
= 0;
386 self
->title
= self
->icon_title
= NULL
;
387 self
->res_name
= self
->res_class
= self
->role
= NULL
;
388 self
->wmstate
= NormalState
;
389 self
->transient
= FALSE
;
390 self
->transients
= NULL
;
391 self
->transient_for
= NULL
;
393 self
->urgent
= FALSE
;
394 self
->positioned
= FALSE
;
395 self
->disabled_decorations
= 0;
399 client_get_area(self
);
400 client_get_desktop(self
);
401 client_get_state(self
);
402 client_get_shaped(self
);
404 client_update_transient_for(self
);
405 client_get_mwm_hints(self
);
406 client_get_type(self
);/* this can change the mwmhints for special cases */
408 client_update_protocols(self
);
410 client_get_gravity(self
); /* get the attribute gravity */
411 client_update_normal_hints(self
); /* this may override the attribute
414 /* got the type, the mwmhints, the protocols, and the normal hints
415 (min/max sizes), so we're ready to set up the decorations/functions */
416 client_setup_decor_and_functions(self
);
418 client_update_wmhints(self
);
419 client_update_title(self
);
420 client_update_icon_title(self
);
421 client_update_class(self
);
422 client_update_strut(self
);
423 client_update_icons(self
);
424 client_update_kwm_icon(self
);
426 /* this makes sure that these windows appear on all desktops */
427 if (self
->type
== Type_Desktop
)
428 self
->desktop
= DESKTOP_ALL
;
430 /* set the desktop hint, to make sure that it always exists, and to
431 reflect any changes we've made here */
432 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, self
->desktop
);
434 client_change_state(self
);
437 static void client_get_area(Client
*self
)
439 XWindowAttributes wattrib
;
442 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
443 g_assert(ret
!= BadWindow
);
445 RECT_SET(self
->area
, wattrib
.x
, wattrib
.y
, wattrib
.width
, wattrib
.height
);
446 self
->border_width
= wattrib
.border_width
;
449 static void client_get_desktop(Client
*self
)
453 if (PROP_GET32(self
->window
, net_wm_desktop
, cardinal
, d
)) {
454 if (d
>= screen_num_desktops
&& d
!= DESKTOP_ALL
)
455 d
= screen_num_desktops
- 1;
458 /* defaults to the current desktop */
459 self
->desktop
= screen_desktop
;
463 static void client_get_state(Client
*self
)
468 self
->modal
= self
->shaded
= self
->max_horz
= self
->max_vert
=
469 self
->fullscreen
= self
->above
= self
->below
= self
->iconic
=
470 self
->skip_taskbar
= self
->skip_pager
= FALSE
;
472 if (PROP_GET32U(self
->window
, net_wm_state
, atom
, state
, num
)) {
474 for (i
= 0; i
< num
; ++i
) {
475 if (state
[i
] == prop_atoms
.net_wm_state_modal
)
477 else if (state
[i
] == prop_atoms
.net_wm_state_shaded
)
479 else if (state
[i
] == prop_atoms
.net_wm_state_hidden
)
481 else if (state
[i
] == prop_atoms
.net_wm_state_skip_taskbar
)
482 self
->skip_taskbar
= TRUE
;
483 else if (state
[i
] == prop_atoms
.net_wm_state_skip_pager
)
484 self
->skip_pager
= TRUE
;
485 else if (state
[i
] == prop_atoms
.net_wm_state_fullscreen
)
486 self
->fullscreen
= TRUE
;
487 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_vert
)
488 self
->max_vert
= TRUE
;
489 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_horz
)
490 self
->max_horz
= TRUE
;
491 else if (state
[i
] == prop_atoms
.net_wm_state_above
)
493 else if (state
[i
] == prop_atoms
.net_wm_state_below
)
501 static void client_get_shaped(Client
*self
)
503 self
->shaped
= FALSE
;
505 if (extensions_shape
) {
510 XShapeSelectInput(ob_display
, self
->window
, ShapeNotifyMask
);
512 XShapeQueryExtents(ob_display
, self
->window
, &s
, &foo
,
513 &foo
, &ufoo
, &ufoo
, &foo
, &foo
, &foo
, &ufoo
,
515 self
->shaped
= (s
!= 0);
520 void client_update_transient_for(Client
*self
)
525 if (XGetTransientForHint(ob_display
, self
->window
, &t
) &&
526 t
!= self
->window
) { /* cant be transient to itself! */
527 self
->transient
= TRUE
;
528 c
= g_hash_table_lookup(client_map
, (gpointer
)t
);
529 g_assert(c
!= self
);/* if this happens then we need to check for it*/
531 if (!c
/*XXX: && _group*/) {
532 /* not transient to a client, see if it is transient for a
534 if (/*t == _group->leader() || */
537 /* window is a transient for its group! */
538 /* XXX: for now this is treated as non-transient.
539 this needs to be fixed! */
543 self
->transient
= FALSE
;
545 /* if anything has changed... */
546 if (c
!= self
->transient_for
) {
547 if (self
->transient_for
)
548 /* remove from old parent */
549 g_slist_remove(self
->transient_for
->transients
, self
);
550 self
->transient_for
= c
;
551 if (self
->transient_for
)
552 /* add to new parent */
553 g_slist_append(self
->transient_for
->transients
, self
);
557 static void client_get_mwm_hints(Client
*self
)
560 unsigned long *hints
;
562 self
->mwmhints
.flags
= 0; /* default to none */
564 if (PROP_GET32U(self
->window
, motif_wm_hints
, motif_wm_hints
, hints
, num
)) {
565 if (num
>= MWM_ELEMENTS
) {
566 self
->mwmhints
.flags
= hints
[0];
567 self
->mwmhints
.functions
= hints
[1];
568 self
->mwmhints
.decorations
= hints
[2];
574 void client_get_type(Client
*self
)
580 if (PROP_GET32U(self
->window
, net_wm_window_type
, atom
, val
, num
)) {
581 /* use the first value that we know about in the array */
582 for (i
= 0; i
< num
; ++i
) {
583 if (val
[i
] == prop_atoms
.net_wm_window_type_desktop
)
584 self
->type
= Type_Desktop
;
585 else if (val
[i
] == prop_atoms
.net_wm_window_type_dock
)
586 self
->type
= Type_Dock
;
587 else if (val
[i
] == prop_atoms
.net_wm_window_type_toolbar
)
588 self
->type
= Type_Toolbar
;
589 else if (val
[i
] == prop_atoms
.net_wm_window_type_menu
)
590 self
->type
= Type_Menu
;
591 else if (val
[i
] == prop_atoms
.net_wm_window_type_utility
)
592 self
->type
= Type_Utility
;
593 else if (val
[i
] == prop_atoms
.net_wm_window_type_splash
)
594 self
->type
= Type_Splash
;
595 else if (val
[i
] == prop_atoms
.net_wm_window_type_dialog
)
596 self
->type
= Type_Dialog
;
597 else if (val
[i
] == prop_atoms
.net_wm_window_type_normal
)
598 self
->type
= Type_Normal
;
599 else if (val
[i
] == prop_atoms
.kde_net_wm_window_type_override
) {
600 /* prevent this window from getting any decor or
602 self
->mwmhints
.flags
&= (MwmFlag_Functions
|
603 MwmFlag_Decorations
);
604 self
->mwmhints
.decorations
= 0;
605 self
->mwmhints
.functions
= 0;
607 if (self
->type
!= (WindowType
) -1)
608 break; /* grab the first legit type */
613 if (self
->type
== (WindowType
) -1) {
614 /*the window type hint was not set, which means we either classify
615 ourself as a normal window or a dialog, depending on if we are a
618 self
->type
= Type_Dialog
;
620 self
->type
= Type_Normal
;
624 void client_update_protocols(Client
*self
)
627 gulong num_return
, i
;
629 self
->focus_notify
= FALSE
;
630 self
->delete_window
= FALSE
;
632 if (PROP_GET32U(self
->window
, wm_protocols
, atom
, proto
, num_return
)) {
633 for (i
= 0; i
< num_return
; ++i
) {
634 if (proto
[i
] == prop_atoms
.wm_delete_window
) {
635 /* this means we can request the window to close */
636 self
->delete_window
= TRUE
;
637 } else if (proto
[i
] == prop_atoms
.wm_take_focus
)
638 /* if this protocol is requested, then the window will be
639 notified whenever we want it to receive focus */
640 self
->focus_notify
= TRUE
;
646 static void client_get_gravity(Client
*self
)
648 XWindowAttributes wattrib
;
651 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
652 g_assert(ret
!= BadWindow
);
653 self
->gravity
= wattrib
.win_gravity
;
656 void client_update_normal_hints(Client
*self
)
660 int oldgravity
= self
->gravity
;
663 self
->min_ratio
= 0.0f
;
664 self
->max_ratio
= 0.0f
;
665 SIZE_SET(self
->size_inc
, 1, 1);
666 SIZE_SET(self
->base_size
, 0, 0);
667 SIZE_SET(self
->min_size
, 0, 0);
668 SIZE_SET(self
->max_size
, G_MAXINT
, G_MAXINT
);
670 /* get the hints from the window */
671 if (XGetWMNormalHints(ob_display
, self
->window
, &size
, &ret
)) {
672 self
->positioned
= (size
.flags
& (PPosition
|USPosition
));
674 if (size
.flags
& PWinGravity
) {
675 self
->gravity
= size
.win_gravity
;
677 /* if the client has a frame, i.e. has already been mapped and
678 is changing its gravity */
679 if (self
->frame
&& self
->gravity
!= oldgravity
) {
680 /* move our idea of the client's position based on its new
682 self
->area
.x
= self
->frame
->area
.x
;
683 self
->area
.y
= self
->frame
->area
.y
;
684 frame_frame_gravity(self
->frame
, &self
->area
.x
, &self
->area
.y
);
688 if (size
.flags
& PAspect
) {
689 if (size
.min_aspect
.y
)
690 self
->min_ratio
= (float)size
.min_aspect
.x
/ size
.min_aspect
.y
;
691 if (size
.max_aspect
.y
)
692 self
->max_ratio
= (float)size
.max_aspect
.x
/ size
.max_aspect
.y
;
695 if (size
.flags
& PMinSize
)
696 SIZE_SET(self
->min_size
, size
.min_width
, size
.min_height
);
698 if (size
.flags
& PMaxSize
)
699 SIZE_SET(self
->max_size
, size
.max_width
, size
.max_height
);
701 if (size
.flags
& PBaseSize
)
702 SIZE_SET(self
->base_size
, size
.base_width
, size
.base_height
);
704 if (size
.flags
& PResizeInc
)
705 SIZE_SET(self
->size_inc
, size
.width_inc
, size
.height_inc
);
709 void client_setup_decor_and_functions(Client
*self
)
711 /* start with everything (cept fullscreen) */
712 self
->decorations
= Decor_Titlebar
| Decor_Handle
| Decor_Border
|
713 Decor_Icon
| Decor_AllDesktops
| Decor_Iconify
| Decor_Maximize
;
714 self
->functions
= Func_Resize
| Func_Move
| Func_Iconify
| Func_Maximize
|
716 if (self
->delete_window
) {
717 self
->decorations
|= Decor_Close
;
718 self
->functions
|= Func_Close
;
721 if (!(self
->min_size
.width
< self
->max_size
.width
||
722 self
->min_size
.height
< self
->max_size
.height
)) {
723 self
->decorations
&= ~(Decor_Maximize
| Decor_Handle
);
724 self
->functions
&= ~(Func_Resize
| Func_Maximize
);
727 switch (self
->type
) {
729 /* normal windows retain all of the possible decorations and
730 functionality, and are the only windows that you can fullscreen */
731 self
->functions
|= Func_Fullscreen
;
735 /* dialogs cannot be maximized */
736 self
->decorations
&= ~Decor_Maximize
;
737 self
->functions
&= ~Func_Maximize
;
743 /* these windows get less functionality */
744 self
->decorations
&= ~(Decor_Iconify
| Decor_Handle
);
745 self
->functions
&= ~(Func_Iconify
| Func_Resize
);
751 /* none of these windows are manipulated by the window manager */
752 self
->decorations
= 0;
757 /* Mwm Hints are applied subtractively to what has already been chosen for
758 decor and functionality */
759 if (self
->mwmhints
.flags
& MwmFlag_Decorations
) {
760 if (! (self
->mwmhints
.decorations
& MwmDecor_All
)) {
761 if (! (self
->mwmhints
.decorations
& MwmDecor_Border
))
762 self
->decorations
&= ~Decor_Border
;
763 if (! (self
->mwmhints
.decorations
& MwmDecor_Handle
))
764 self
->decorations
&= ~Decor_Handle
;
765 if (! (self
->mwmhints
.decorations
& MwmDecor_Title
))
766 self
->decorations
&= ~Decor_Titlebar
;
767 if (! (self
->mwmhints
.decorations
& MwmDecor_Iconify
))
768 self
->decorations
&= ~Decor_Iconify
;
769 if (! (self
->mwmhints
.decorations
& MwmDecor_Maximize
))
770 self
->decorations
&= ~Decor_Maximize
;
774 if (self
->mwmhints
.flags
& MwmFlag_Functions
) {
775 if (! (self
->mwmhints
.functions
& MwmFunc_All
)) {
776 if (! (self
->mwmhints
.functions
& MwmFunc_Resize
))
777 self
->functions
&= ~Func_Resize
;
778 if (! (self
->mwmhints
.functions
& MwmFunc_Move
))
779 self
->functions
&= ~Func_Move
;
780 if (! (self
->mwmhints
.functions
& MwmFunc_Iconify
))
781 self
->functions
&= ~Func_Iconify
;
782 if (! (self
->mwmhints
.functions
& MwmFunc_Maximize
))
783 self
->functions
&= ~Func_Maximize
;
784 /* dont let mwm hints kill the close button
785 if (! (self->mwmhints.functions & MwmFunc_Close))
786 self->functions &= ~Func_Close; */
790 /* can't maximize without moving/resizing */
791 if (!((self
->functions
& Func_Move
) && (self
->functions
& Func_Resize
)))
792 self
->functions
&= ~Func_Maximize
;
794 /* finally, user specified disabled decorations are applied to subtract
796 if (self
->disabled_decorations
& Decor_Titlebar
)
797 self
->decorations
&= ~Decor_Titlebar
;
798 if (self
->disabled_decorations
& Decor_Handle
)
799 self
->decorations
&= ~Decor_Handle
;
800 if (self
->disabled_decorations
& Decor_Border
)
801 self
->decorations
&= ~Decor_Border
;
802 if (self
->disabled_decorations
& Decor_Iconify
)
803 self
->decorations
&= ~Decor_Iconify
;
804 if (self
->disabled_decorations
& Decor_Maximize
)
805 self
->decorations
&= ~Decor_Maximize
;
806 if (self
->disabled_decorations
& Decor_AllDesktops
)
807 self
->decorations
&= ~Decor_AllDesktops
;
808 if (self
->disabled_decorations
& Decor_Close
)
809 self
->decorations
&= ~Decor_Close
;
811 /* if we don't have a titlebar, then we cannot shade! */
812 if (!(self
->decorations
& Decor_Titlebar
))
813 self
->functions
&= ~Func_Shade
;
815 client_change_allowed_actions(self
);
818 /* change the decors on the frame */
819 engine_frame_adjust_size(self
->frame
);
820 /* with more/less decorations, we may need to be repositioned */
821 engine_frame_adjust_position(self
->frame
);
822 /* with new decor, the window's maximized size may change */
823 client_remaximize(self
);
827 static void client_change_allowed_actions(Client
*self
)
832 actions
[num
++] = prop_atoms
.net_wm_action_change_desktop
;
834 if (self
->functions
& Func_Shade
)
835 actions
[num
++] = prop_atoms
.net_wm_action_shade
;
836 if (self
->functions
& Func_Close
)
837 actions
[num
++] = prop_atoms
.net_wm_action_close
;
838 if (self
->functions
& Func_Move
)
839 actions
[num
++] = prop_atoms
.net_wm_action_move
;
840 if (self
->functions
& Func_Iconify
)
841 actions
[num
++] = prop_atoms
.net_wm_action_minimize
;
842 if (self
->functions
& Func_Resize
)
843 actions
[num
++] = prop_atoms
.net_wm_action_resize
;
844 if (self
->functions
& Func_Fullscreen
)
845 actions
[num
++] = prop_atoms
.net_wm_action_fullscreen
;
846 if (self
->functions
& Func_Maximize
) {
847 actions
[num
++] = prop_atoms
.net_wm_action_maximize_horz
;
848 actions
[num
++] = prop_atoms
.net_wm_action_maximize_vert
;
851 PROP_SET32A(self
->window
, net_wm_allowed_actions
, atom
, actions
, num
);
853 /* make sure the window isn't breaking any rules now */
855 if (!(self
->functions
& Func_Shade
) && self
->shaded
) {
856 if (self
->frame
) client_shade(self
, FALSE
);
857 else self
->shaded
= FALSE
;
859 if (!(self
->functions
& Func_Iconify
) && self
->iconic
) {
860 if (self
->frame
) client_iconify(self
, FALSE
, TRUE
);
861 else self
->iconic
= FALSE
;
863 if (!(self
->functions
& Func_Fullscreen
) && self
->fullscreen
) {
864 if (self
->frame
) client_fullscreen(self
, FALSE
, TRUE
);
865 else self
->fullscreen
= FALSE
;
867 if (!(self
->functions
& Func_Maximize
) && (self
->max_horz
||
869 if (self
->frame
) client_maximize(self
, FALSE
, 0, TRUE
);
870 else self
->max_vert
= self
->max_horz
= FALSE
;
874 void client_remaximize(Client
*self
)
877 if (self
->max_horz
&& self
->max_vert
)
879 else if (self
->max_horz
)
881 else if (self
->max_vert
)
884 return; /* not maximized */
885 self
->max_horz
= self
->max_vert
= FALSE
;
886 client_maximize(self
, TRUE
, dir
, FALSE
);
889 void client_update_wmhints(Client
*self
)
894 /* assume a window takes input if it doesnt specify */
895 self
->can_focus
= TRUE
;
897 if ((hints
= XGetWMHints(ob_display
, self
->window
)) != NULL
) {
898 if (hints
->flags
& InputHint
)
899 self
->can_focus
= hints
->input
;
901 /* only do this when starting! */
902 if (ob_state
== State_Starting
&& (hints
->flags
& StateHint
))
903 self
->iconic
= hints
->initial_state
== IconicState
;
905 if (hints
->flags
& XUrgencyHint
)
908 if (hints
->flags
& WindowGroupHint
) {
909 if (hints
->window_group
!= self
->group
) {
910 /* XXX: remove from the old group if there was one */
911 self
->group
= hints
->window_group
;
912 /* XXX: do stuff with the group */
914 } else /* no group! */
917 if (hints
->flags
& IconPixmapHint
) {
918 client_update_kwm_icon(self
);
919 /* try get the kwm icon first, this is a fallback only */
920 if (self
->pixmap_icon
== None
) {
921 self
->pixmap_icon
= hints
->icon_pixmap
;
922 if (hints
->flags
& IconMaskHint
)
923 self
->pixmap_icon_mask
= hints
->icon_mask
;
925 self
->pixmap_icon_mask
= None
;
928 engine_frame_adjust_icon(self
->frame
);
935 if (ur
!= self
->urgent
) {
937 g_message("Urgent Hint for 0x%lx: %s\n", self
->window
,
939 /* fire the urgent callback if we're mapped, otherwise, wait until
940 after we're mapped */
942 dispatch_client(Event_Client_Urgent
, self
, self
->urgent
, 0);
946 void client_update_title(Client
*self
)
953 if (!PROP_GETS(self
->window
, net_wm_name
, utf8
, data
)) {
954 /* try old x stuff */
955 if (PROP_GETS(self
->window
, wm_name
, string
, data
)) {
956 /* convert it to UTF-8 */
960 u
= g_locale_to_utf8(data
, -1, &r
, &w
, NULL
);
962 g_warning("Unable to convert string to UTF-8");
969 data
= g_strdup("Unnamed Window");
971 PROP_SETS(self
->window
, net_wm_visible_name
, utf8
, data
);
977 engine_frame_adjust_title(self
->frame
);
980 void client_update_icon_title(Client
*self
)
984 g_free(self
->icon_title
);
987 if (!PROP_GETS(self
->window
, net_wm_icon_name
, utf8
, data
)) {
988 /* try old x stuff */
989 if (PROP_GETS(self
->window
, wm_icon_name
, string
, data
)) {
990 /* convert it to UTF-8 */
994 u
= g_locale_to_utf8(data
, -1, &r
, &w
, NULL
);
996 g_warning("Unable to convert string to UTF-8");
1003 data
= g_strdup("Unnamed Window");
1005 PROP_SETS(self
->window
, net_wm_visible_icon_name
, utf8
, data
);
1008 self
->icon_title
= data
;
1011 void client_update_class(Client
*self
)
1017 if (self
->res_name
) g_free(self
->res_name
);
1018 if (self
->res_class
) g_free(self
->res_class
);
1019 if (self
->role
) g_free(self
->role
);
1021 self
->res_name
= self
->res_class
= self
->role
= NULL
;
1023 data
= g_ptr_array_new();
1025 if (PROP_GETSA(self
->window
, wm_class
, string
, data
)) {
1027 self
->res_name
= g_strdup(g_ptr_array_index(data
, 0));
1029 self
->res_class
= g_strdup(g_ptr_array_index(data
, 1));
1032 for (i
= 0; i
< data
->len
; ++i
)
1033 g_free(g_ptr_array_index(data
, i
));
1034 g_ptr_array_free(data
, TRUE
);
1036 if (PROP_GETS(self
->window
, wm_window_role
, string
, s
))
1037 self
->role
= g_strdup(s
);
1039 if (self
->res_name
== NULL
) self
->res_name
= g_strdup("");
1040 if (self
->res_class
== NULL
) self
->res_class
= g_strdup("");
1041 if (self
->role
== NULL
) self
->role
= g_strdup("");
1044 void client_update_strut(Client
*self
)
1048 if (PROP_GET32A(self
->window
, net_wm_strut
, cardinal
, data
, 4)) {
1049 STRUT_SET(self
->strut
, data
[0], data
[1], data
[2], data
[3]);
1052 STRUT_SET(self
->strut
, 0, 0, 0, 0);
1054 /* updating here is pointless while we're being mapped cuz we're not in
1055 the client list yet */
1057 screen_update_struts();
1060 void client_update_icons(Client
*self
)
1063 unsigned long *data
;
1064 unsigned long w
, h
, i
;
1067 for (j
= 0; j
< self
->nicons
; ++j
)
1068 g_free(self
->icons
[j
].data
);
1069 if (self
->nicons
> 0)
1070 g_free(self
->icons
);
1073 if (PROP_GET32U(self
->window
, net_wm_icon
, cardinal
, data
, num
)) {
1074 /* figure out how many valid icons are in here */
1076 while (num
- i
> 2) {
1084 self
->icons
= g_new(Icon
, self
->nicons
);
1086 /* store the icons */
1088 for (j
= 0; j
< self
->nicons
; ++j
) {
1089 w
= self
->icons
[j
].w
= data
[i
++];
1090 h
= self
->icons
[j
].h
= data
[i
++];
1091 self
->icons
[j
].data
=
1092 g_memdup(&data
[i
], w
* h
* sizeof(gulong
));
1100 if (self
->nicons
<= 0) {
1102 self
->icons
= g_new0(Icon
, 1);
1106 engine_frame_adjust_icon(self
->frame
);
1109 void client_update_kwm_icon(Client
*self
)
1113 if (PROP_GET32A(self
->window
, kwm_win_icon
, kwm_win_icon
, data
, 2)) {
1114 self
->pixmap_icon
= data
[0];
1115 self
->pixmap_icon_mask
= data
[1];
1118 self
->pixmap_icon
= self
->pixmap_icon_mask
= None
;
1121 engine_frame_adjust_icon(self
->frame
);
1124 static void client_change_state(Client
*self
)
1126 unsigned long state
[2];
1130 state
[0] = self
->wmstate
;
1132 PROP_SET32A(self
->window
, wm_state
, wm_state
, state
, 2);
1136 netstate
[num
++] = prop_atoms
.net_wm_state_modal
;
1138 netstate
[num
++] = prop_atoms
.net_wm_state_shaded
;
1140 netstate
[num
++] = prop_atoms
.net_wm_state_hidden
;
1141 if (self
->skip_taskbar
)
1142 netstate
[num
++] = prop_atoms
.net_wm_state_skip_taskbar
;
1143 if (self
->skip_pager
)
1144 netstate
[num
++] = prop_atoms
.net_wm_state_skip_pager
;
1145 if (self
->fullscreen
)
1146 netstate
[num
++] = prop_atoms
.net_wm_state_fullscreen
;
1148 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_vert
;
1150 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_horz
;
1152 netstate
[num
++] = prop_atoms
.net_wm_state_above
;
1154 netstate
[num
++] = prop_atoms
.net_wm_state_below
;
1155 PROP_SET32A(self
->window
, net_wm_state
, atom
, netstate
, num
);
1157 client_calc_layer(self
);
1160 engine_frame_adjust_state(self
->frame
);
1163 static Client
*search_focus_tree(Client
*node
, Client
*skip
)
1168 for (it
= node
->transients
; it
!= NULL
; it
= g_slist_next(it
)) {
1169 Client
*c
= it
->data
;
1170 if (c
== skip
) continue; /* circular? */
1171 if ((ret
= search_focus_tree(c
, skip
))) return ret
;
1172 if (client_focused(c
)) return c
;
1177 void client_calc_layer(Client
*self
)
1183 /* are we fullscreen, or do we have a fullscreen transient parent? */
1187 if (c
->fullscreen
) {
1191 c
= c
->transient_for
;
1193 if (!fs
&& self
->fullscreen
) {
1194 /* is one of our transients focused? */
1195 c
= search_focus_tree(self
, self
);
1196 if (c
!= NULL
) fs
= TRUE
;
1199 if (self
->iconic
) l
= Layer_Icon
;
1200 else if (fs
) l
= Layer_Fullscreen
;
1201 else if (self
->type
== Type_Desktop
) l
= Layer_Desktop
;
1202 else if (self
->type
== Type_Dock
) {
1203 if (!self
->below
) l
= Layer_Top
;
1204 else l
= Layer_Normal
;
1206 else if (self
->above
) l
= Layer_Above
;
1207 else if (self
->below
) l
= Layer_Below
;
1208 else l
= Layer_Normal
;
1210 if (l
!= self
->layer
) {
1213 stacking_raise(self
);
1217 gboolean
client_should_show(Client
*self
)
1219 if (self
->iconic
) return FALSE
;
1220 else if (!(self
->desktop
== screen_desktop
||
1221 self
->desktop
== DESKTOP_ALL
)) return FALSE
;
1222 else if (client_normal(self
) && screen_showing_desktop
) return FALSE
;
1227 static void client_showhide(Client
*self
)
1230 if (client_should_show(self
))
1231 engine_frame_show(self
->frame
);
1233 engine_frame_hide(self
->frame
);
1236 gboolean
client_normal(Client
*self
) {
1237 return ! (self
->type
== Type_Desktop
|| self
->type
== Type_Dock
||
1238 self
->type
== Type_Splash
);
1241 static void client_apply_startup_state(Client
*self
)
1243 /* these are in a carefully crafted order.. */
1246 self
->iconic
= FALSE
;
1247 client_iconify(self
, TRUE
, FALSE
);
1249 if (self
->fullscreen
) {
1250 self
->fullscreen
= FALSE
;
1251 client_fullscreen(self
, TRUE
, FALSE
);
1254 self
->shaded
= FALSE
;
1255 client_shade(self
, TRUE
);
1258 dispatch_client(Event_Client_Urgent
, self
, self
->urgent
, 0);
1260 if (self
->max_vert
&& self
->max_horz
) {
1261 self
->max_vert
= self
->max_horz
= FALSE
;
1262 client_maximize(self
, TRUE
, 0, FALSE
);
1263 } else if (self
->max_vert
) {
1264 self
->max_vert
= FALSE
;
1265 client_maximize(self
, TRUE
, 2, FALSE
);
1266 } else if (self
->max_horz
) {
1267 self
->max_horz
= FALSE
;
1268 client_maximize(self
, TRUE
, 1, FALSE
);
1271 /* nothing to do for the other states:
1280 void client_configure(Client
*self
, Corner anchor
, int x
, int y
, int w
, int h
,
1281 gboolean user
, gboolean final
)
1283 gboolean moved
= FALSE
, resized
= FALSE
;
1285 /* set the size and position if fullscreen */
1286 if (self
->fullscreen
) {
1289 w
= screen_physical_size
.width
;
1290 h
= screen_physical_size
.height
;
1292 /* set the size and position if maximized */
1293 if (self
->max_horz
) {
1294 x
= screen_area(self
->desktop
)->x
- self
->frame
->size
.left
;
1295 w
= screen_area(self
->desktop
)->x
+
1296 screen_area(self
->desktop
)->width
;
1298 if (self
->max_vert
) {
1299 y
= screen_area(self
->desktop
)->y
;
1300 h
= screen_area(self
->desktop
)->y
+
1301 screen_area(self
->desktop
)->height
-
1302 self
->frame
->size
.top
- self
->frame
->size
.bottom
;
1306 if (x
== self
->area
.x
&& y
== self
->area
.y
&& w
== self
->area
.width
&&
1307 h
== self
->area
.height
)
1308 return; /* no change */
1310 w
-= self
->base_size
.width
;
1311 h
-= self
->base_size
.height
;
1314 /* for interactive resizing. have to move half an increment in each
1317 /* how far we are towards the next size inc */
1318 int mw
= w
% self
->size_inc
.width
;
1319 int mh
= h
% self
->size_inc
.height
;
1321 int aw
= self
->size_inc
.width
/ 2;
1322 int ah
= self
->size_inc
.height
/ 2;
1323 /* don't let us move into a new size increment */
1324 if (mw
+ aw
>= self
->size_inc
.width
)
1325 aw
= self
->size_inc
.width
- mw
- 1;
1326 if (mh
+ ah
>= self
->size_inc
.height
)
1327 ah
= self
->size_inc
.height
- mh
- 1;
1331 /* if this is a user-requested resize, then check against min/max
1332 sizes and aspect ratios */
1334 /* smaller than min size or bigger than max size? */
1335 if (w
> self
->max_size
.width
) w
= self
->max_size
.width
;
1336 if (w
< self
->min_size
.width
) w
= self
->min_size
.width
;
1337 if (h
> self
->max_size
.height
) h
= self
->max_size
.height
;
1338 if (h
< self
->min_size
.height
) h
= self
->min_size
.height
;
1340 /* adjust the height ot match the width for the aspect ratios */
1341 if (self
->min_ratio
)
1342 if (h
* self
->min_ratio
> w
) h
= (int)(w
/ self
->min_ratio
);
1343 if (self
->max_ratio
)
1344 if (h
* self
->max_ratio
< w
) h
= (int)(w
/ self
->max_ratio
);
1347 /* keep to the increments */
1348 w
/= self
->size_inc
.width
;
1349 h
/= self
->size_inc
.height
;
1351 /* you cannot resize to nothing */
1355 /* store the logical size */
1356 SIZE_SET(self
->logical_size
, w
, h
);
1358 w
*= self
->size_inc
.width
;
1359 h
*= self
->size_inc
.height
;
1361 w
+= self
->base_size
.width
;
1362 h
+= self
->base_size
.height
;
1365 case Corner_TopLeft
:
1367 case Corner_TopRight
:
1368 x
-= w
- self
->area
.width
;
1370 case Corner_BottomLeft
:
1371 y
-= h
- self
->area
.height
;
1373 case Corner_BottomRight
:
1374 x
-= w
- self
->area
.width
;
1375 y
-= h
- self
->area
.height
;
1379 moved
= x
!= self
->area
.x
|| y
!= self
->area
.y
;
1380 resized
= w
!= self
->area
.width
|| h
!= self
->area
.height
;
1382 RECT_SET(self
->area
, x
, y
, w
, h
);
1385 XResizeWindow(ob_display
, self
->window
, w
, h
);
1387 /* move/resize the frame to match the request */
1389 /* Adjust the size and then the position, as required by the EWMH */
1391 engine_frame_adjust_size(self
->frame
);
1393 engine_frame_adjust_position(self
->frame
);
1395 if (!user
|| final
) {
1397 event
.type
= ConfigureNotify
;
1398 event
.xconfigure
.display
= ob_display
;
1399 event
.xconfigure
.event
= self
->window
;
1400 event
.xconfigure
.window
= self
->window
;
1402 /* root window coords with border in mind */
1403 event
.xconfigure
.x
= x
- self
->border_width
+
1404 self
->frame
->size
.left
;
1405 event
.xconfigure
.y
= y
- self
->border_width
+
1406 self
->frame
->size
.top
;
1408 event
.xconfigure
.width
= self
->area
.width
;
1409 event
.xconfigure
.height
= self
->area
.height
;
1410 event
.xconfigure
.border_width
= self
->border_width
;
1411 event
.xconfigure
.above
= self
->frame
->plate
;
1412 event
.xconfigure
.override_redirect
= FALSE
;
1413 XSendEvent(event
.xconfigure
.display
, event
.xconfigure
.window
,
1414 FALSE
, StructureNotifyMask
, &event
);
1420 void client_fullscreen(Client
*self
, gboolean fs
, gboolean savearea
)
1424 if (!(self
->functions
& Func_Fullscreen
) || /* can't */
1425 self
->fullscreen
== fs
) return; /* already done */
1427 self
->fullscreen
= fs
;
1428 client_change_state(self
); /* change the state hints on the client */
1431 /* save the functions and remove them */
1432 self
->pre_fs_func
= self
->functions
;
1433 self
->functions
&= (Func_Close
| Func_Fullscreen
|
1435 /* save the decorations and remove them */
1436 self
->pre_fs_decor
= self
->decorations
;
1437 self
->decorations
= 0;
1440 dimensions
[0] = self
->area
.x
;
1441 dimensions
[1] = self
->area
.y
;
1442 dimensions
[2] = self
->area
.width
;
1443 dimensions
[3] = self
->area
.height
;
1445 PROP_SET32A(self
->window
, openbox_premax
, cardinal
,
1449 /* these are not actually used cuz client_configure will set them
1450 as appropriate when the window is fullscreened */
1455 self
->functions
= self
->pre_fs_func
;
1456 self
->decorations
= self
->pre_fs_decor
;
1458 if (PROP_GET32A(self
->window
, openbox_premax
, cardinal
,
1466 /* pick some fallbacks... */
1467 x
= screen_area(self
->desktop
)->x
+
1468 screen_area(self
->desktop
)->width
/ 4;
1469 y
= screen_area(self
->desktop
)->y
+
1470 screen_area(self
->desktop
)->height
/ 4;
1471 w
= screen_area(self
->desktop
)->width
/ 2;
1472 h
= screen_area(self
->desktop
)->height
/ 2;
1476 client_change_allowed_actions(self
); /* based on the new _functions */
1478 /* when fullscreening, don't obey things like increments, fill the
1480 client_configure(self
, Corner_TopLeft
, x
, y
, w
, h
, !fs
, TRUE
);
1482 /* raise (back) into our stacking layer */
1483 stacking_raise(self
);
1485 /* try focus us when we go into fullscreen mode */
1489 void client_iconify(Client
*self
, gboolean iconic
, gboolean curdesk
)
1491 if (self
->iconic
== iconic
) return; /* nothing to do */
1493 g_message("%sconifying window: 0x%lx", (iconic
? "I" : "Uni"),
1496 self
->iconic
= iconic
;
1499 self
->wmstate
= IconicState
;
1500 self
->ignore_unmaps
++;
1501 /* we unmap the client itself so that we can get MapRequest events,
1502 and because the ICCCM tells us to! */
1503 XUnmapWindow(ob_display
, self
->window
);
1506 client_set_desktop(self
, screen_desktop
);
1507 self
->wmstate
= self
->shaded
? IconicState
: NormalState
;
1508 XMapWindow(ob_display
, self
->window
);
1510 client_change_state(self
);
1511 client_showhide(self
);
1512 screen_update_struts();
1515 void client_maximize(Client
*self
, gboolean max
, int dir
, gboolean savearea
)
1519 g_assert(dir
== 0 || dir
== 1 || dir
== 2);
1520 if (!(self
->functions
& Func_Maximize
)) return; /* can't */
1522 /* check if already done */
1524 if (dir
== 0 && self
->max_horz
&& self
->max_vert
) return;
1525 if (dir
== 1 && self
->max_horz
) return;
1526 if (dir
== 2 && self
->max_vert
) return;
1528 if (dir
== 0 && !self
->max_horz
&& !self
->max_vert
) return;
1529 if (dir
== 1 && !self
->max_horz
) return;
1530 if (dir
== 2 && !self
->max_vert
) return;
1533 /* work with the frame's coords */
1534 x
= self
->frame
->area
.x
;
1535 y
= self
->frame
->area
.y
;
1536 w
= self
->area
.width
;
1537 h
= self
->area
.height
;
1549 /* get the property off the window and use it for the dimensions
1550 we are already maxed on */
1551 if (PROP_GET32A(self
->window
, openbox_premax
, cardinal
,
1553 if (self
->max_horz
) {
1554 dimensions
[0] = readdim
[0];
1555 dimensions
[2] = readdim
[2];
1557 if (self
->max_vert
) {
1558 dimensions
[1] = readdim
[1];
1559 dimensions
[3] = readdim
[3];
1564 PROP_SET32A(self
->window
, openbox_premax
, cardinal
,
1568 /* pass the client's current position info. the client_configure
1569 will move/size stuff as appropriate for a maximized window */
1572 w
= self
->area
.width
;
1573 h
= self
->area
.height
;
1577 if (PROP_GET32A(self
->window
, openbox_premax
, cardinal
,
1579 if (dir
== 0 || dir
== 1) { /* horz */
1583 if (dir
== 0 || dir
== 2) { /* vert */
1589 /* pick some fallbacks... */
1590 if (dir
== 0 || dir
== 1) { /* horz */
1591 x
= screen_area(self
->desktop
)->x
+
1592 screen_area(self
->desktop
)->width
/ 4;
1593 w
= screen_area(self
->desktop
)->width
/ 2;
1595 if (dir
== 0 || dir
== 2) { /* vert */
1596 y
= screen_area(self
->desktop
)->y
+
1597 screen_area(self
->desktop
)->height
/ 4;
1598 h
= screen_area(self
->desktop
)->height
/ 2;
1603 if (dir
== 0 || dir
== 1) /* horz */
1604 self
->max_horz
= max
;
1605 if (dir
== 0 || dir
== 2) /* vert */
1606 self
->max_vert
= max
;
1608 if (!self
->max_horz
&& !self
->max_vert
)
1609 PROP_ERASE(self
->window
, openbox_premax
);
1611 client_change_state(self
); /* change the state hints on the client */
1613 /* figure out where the client should be going */
1614 frame_frame_gravity(self
->frame
, &x
, &y
);
1615 client_configure(self
, Corner_TopLeft
, x
, y
, w
, h
, TRUE
, TRUE
);
1618 void client_shade(Client
*self
, gboolean shade
)
1620 if (!(self
->functions
& Func_Shade
) || /* can't */
1621 self
->shaded
== shade
) return; /* already done */
1623 /* when we're iconic, don't change the wmstate */
1625 self
->wmstate
= shade
? IconicState
: NormalState
;
1626 self
->shaded
= shade
;
1627 client_change_state(self
);
1628 engine_frame_adjust_size(self
->frame
);
1631 void client_close(Client
*self
)
1635 if (!(self
->functions
& Func_Close
)) return;
1638 XXX: itd be cool to do timeouts and shit here for killing the client's
1640 like... if the window is around after 5 seconds, then the close button
1641 turns a nice red, and if this function is called again, the client is
1645 ce
.xclient
.type
= ClientMessage
;
1646 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
1647 ce
.xclient
.display
= ob_display
;
1648 ce
.xclient
.window
= self
->window
;
1649 ce
.xclient
.format
= 32;
1650 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_delete_window
;
1651 ce
.xclient
.data
.l
[1] = CurrentTime
;
1652 ce
.xclient
.data
.l
[2] = 0l;
1653 ce
.xclient
.data
.l
[3] = 0l;
1654 ce
.xclient
.data
.l
[4] = 0l;
1655 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
1658 void client_set_desktop(Client
*self
, guint target
)
1662 if (target
== self
->desktop
) return;
1664 g_message("Setting desktop %u\n", target
);
1666 g_assert(target
< screen_num_desktops
|| target
== DESKTOP_ALL
);
1668 old
= self
->desktop
;
1669 self
->desktop
= target
;
1670 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, target
);
1671 /* the frame can display the current desktop state */
1672 engine_frame_adjust_state(self
->frame
);
1673 /* 'move' the window to the new desktop */
1674 client_showhide(self
);
1675 screen_update_struts();
1677 /* update the focus lists */
1678 if (old
== DESKTOP_ALL
) {
1679 for (i
= 0; i
< screen_num_desktops
; ++i
)
1680 focus_order
[i
] = g_list_remove(focus_order
[i
], self
);
1682 focus_order
[old
] = g_list_remove(focus_order
[old
], self
);
1684 if (target
== DESKTOP_ALL
) {
1685 for (i
= 0; i
< screen_num_desktops
; ++i
)
1686 focus_order
[i
] = g_list_prepend(focus_order
[i
], self
);
1688 focus_order
[target
] = g_list_prepend(focus_order
[target
], self
);
1691 dispatch_client(Event_Client_Desktop
, self
, target
, old
);
1694 static Client
*search_modal_tree(Client
*node
, Client
*skip
)
1699 for (it
= node
->transients
; it
!= NULL
; it
= it
->next
) {
1700 Client
*c
= it
->data
;
1701 if (c
== skip
) continue; /* circular? */
1702 if ((ret
= search_modal_tree(c
, skip
))) return ret
;
1703 if (c
->modal
) return c
;
1708 Client
*client_find_modal_child(Client
*self
)
1710 return search_modal_tree(self
, self
);
1713 gboolean
client_validate(Client
*self
)
1717 XSync(ob_display
, FALSE
); /* get all events on the server */
1719 if (XCheckTypedWindowEvent(ob_display
, self
->window
, DestroyNotify
, &e
) ||
1720 XCheckTypedWindowEvent(ob_display
, self
->window
, UnmapNotify
, &e
)) {
1721 XPutBackEvent(ob_display
, &e
);
1728 void client_set_wm_state(Client
*self
, long state
)
1730 if (state
== self
->wmstate
) return; /* no change */
1734 client_iconify(self
, TRUE
, TRUE
);
1737 client_iconify(self
, FALSE
, TRUE
);
1742 void client_set_state(Client
*self
, Atom action
, long data1
, long data2
)
1744 gboolean shaded
= self
->shaded
;
1745 gboolean fullscreen
= self
->fullscreen
;
1746 gboolean max_horz
= self
->max_horz
;
1747 gboolean max_vert
= self
->max_vert
;
1750 if (!(action
== prop_atoms
.net_wm_state_add
||
1751 action
== prop_atoms
.net_wm_state_remove
||
1752 action
== prop_atoms
.net_wm_state_toggle
))
1753 /* an invalid action was passed to the client message, ignore it */
1756 for (i
= 0; i
< 2; ++i
) {
1757 Atom state
= i
== 0 ? data1
: data2
;
1759 if (!state
) continue;
1761 /* if toggling, then pick whether we're adding or removing */
1762 if (action
== prop_atoms
.net_wm_state_toggle
) {
1763 if (state
== prop_atoms
.net_wm_state_modal
)
1764 action
= self
->modal
? prop_atoms
.net_wm_state_remove
:
1765 prop_atoms
.net_wm_state_add
;
1766 else if (state
== prop_atoms
.net_wm_state_maximized_vert
)
1767 action
= self
->max_vert
? prop_atoms
.net_wm_state_remove
:
1768 prop_atoms
.net_wm_state_add
;
1769 else if (state
== prop_atoms
.net_wm_state_maximized_horz
)
1770 action
= self
->max_horz
? prop_atoms
.net_wm_state_remove
:
1771 prop_atoms
.net_wm_state_add
;
1772 else if (state
== prop_atoms
.net_wm_state_shaded
)
1773 action
= self
->shaded
? prop_atoms
.net_wm_state_remove
:
1774 prop_atoms
.net_wm_state_add
;
1775 else if (state
== prop_atoms
.net_wm_state_skip_taskbar
)
1776 action
= self
->skip_taskbar
?
1777 prop_atoms
.net_wm_state_remove
:
1778 prop_atoms
.net_wm_state_add
;
1779 else if (state
== prop_atoms
.net_wm_state_skip_pager
)
1780 action
= self
->skip_pager
?
1781 prop_atoms
.net_wm_state_remove
:
1782 prop_atoms
.net_wm_state_add
;
1783 else if (state
== prop_atoms
.net_wm_state_fullscreen
)
1784 action
= self
->fullscreen
?
1785 prop_atoms
.net_wm_state_remove
:
1786 prop_atoms
.net_wm_state_add
;
1787 else if (state
== prop_atoms
.net_wm_state_above
)
1788 action
= self
->above
? prop_atoms
.net_wm_state_remove
:
1789 prop_atoms
.net_wm_state_add
;
1790 else if (state
== prop_atoms
.net_wm_state_below
)
1791 action
= self
->below
? prop_atoms
.net_wm_state_remove
:
1792 prop_atoms
.net_wm_state_add
;
1795 if (action
== prop_atoms
.net_wm_state_add
) {
1796 if (state
== prop_atoms
.net_wm_state_modal
) {
1797 /* XXX raise here or something? */
1799 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
1801 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
1803 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
1805 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
1806 self
->skip_taskbar
= TRUE
;
1807 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
1808 self
->skip_pager
= TRUE
;
1809 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
1811 } else if (state
== prop_atoms
.net_wm_state_above
) {
1813 } else if (state
== prop_atoms
.net_wm_state_below
) {
1817 } else { /* action == prop_atoms.net_wm_state_remove */
1818 if (state
== prop_atoms
.net_wm_state_modal
) {
1819 self
->modal
= FALSE
;
1820 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
1822 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
1824 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
1826 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
1827 self
->skip_taskbar
= FALSE
;
1828 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
1829 self
->skip_pager
= FALSE
;
1830 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
1832 } else if (state
== prop_atoms
.net_wm_state_above
) {
1833 self
->above
= FALSE
;
1834 } else if (state
== prop_atoms
.net_wm_state_below
) {
1835 self
->below
= FALSE
;
1839 if (max_horz
!= self
->max_horz
|| max_vert
!= self
->max_vert
) {
1840 if (max_horz
!= self
->max_horz
&& max_vert
!= self
->max_vert
) {
1842 if (max_horz
== max_vert
) { /* both going the same way */
1843 client_maximize(self
, max_horz
, 0, TRUE
);
1845 client_maximize(self
, max_horz
, 1, TRUE
);
1846 client_maximize(self
, max_vert
, 2, TRUE
);
1850 if (max_horz
!= self
->max_horz
)
1851 client_maximize(self
, max_horz
, 1, TRUE
);
1853 client_maximize(self
, max_vert
, 2, TRUE
);
1856 /* change fullscreen state before shading, as it will affect if the window
1858 if (fullscreen
!= self
->fullscreen
)
1859 client_fullscreen(self
, fullscreen
, TRUE
);
1860 if (shaded
!= self
->shaded
)
1861 client_shade(self
, shaded
);
1862 client_calc_layer(self
);
1863 client_change_state(self
); /* change the hint to relect these changes */
1866 gboolean
client_focus(Client
*self
)
1871 /* if we have a modal child, then focus it, not us */
1872 child
= client_find_modal_child(self
);
1874 return client_focus(child
);
1876 /* won't try focus if the client doesn't want it, or if the window isn't
1877 visible on the screen */
1878 if (!(self
->frame
->visible
&&
1879 (self
->can_focus
|| self
->focus_notify
)))
1882 /* do a check to see if the window has already been unmapped or destroyed
1883 do this intelligently while watching out for unmaps we've generated
1884 (ignore_unmaps > 0) */
1885 if (XCheckTypedWindowEvent(ob_display
, self
->window
,
1886 DestroyNotify
, &ev
)) {
1887 XPutBackEvent(ob_display
, &ev
);
1890 while (XCheckTypedWindowEvent(ob_display
, self
->window
,
1891 UnmapNotify
, &ev
)) {
1892 if (self
->ignore_unmaps
) {
1893 self
->ignore_unmaps
--;
1895 XPutBackEvent(ob_display
, &ev
);
1900 if (client_focused(self
))
1903 if (self
->can_focus
)
1904 XSetInputFocus(ob_display
, self
->window
, RevertToNone
, CurrentTime
);
1906 if (self
->focus_notify
) {
1908 ce
.xclient
.type
= ClientMessage
;
1909 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
1910 ce
.xclient
.display
= ob_display
;
1911 ce
.xclient
.window
= self
->window
;
1912 ce
.xclient
.format
= 32;
1913 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_take_focus
;
1914 ce
.xclient
.data
.l
[1] = event_lasttime
;
1915 ce
.xclient
.data
.l
[2] = 0l;
1916 ce
.xclient
.data
.l
[3] = 0l;
1917 ce
.xclient
.data
.l
[4] = 0l;
1918 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
1921 client_set_focused(self
, TRUE
);
1923 /* XSync(ob_display, FALSE); XXX Why sync? */
1927 void client_unfocus(Client
*self
)
1929 g_assert(focus_client
== self
);
1930 client_set_focused(self
, FALSE
);
1933 void client_set_focused(Client
*self
, gboolean focused
)
1936 if (focus_client
!= self
) {
1937 focus_set_client(self
);
1939 /* focus state can affect the stacking layer */
1940 client_calc_layer(self
);
1942 engine_frame_adjust_focus(self
->frame
);
1945 if (focus_client
== self
)
1946 focus_set_client(NULL
);
1948 /* focus state can affect the stacking layer */
1949 client_calc_layer(self
);
1951 if (self
->frame
!= NULL
) /* unfocus can happen while being unmanaged */
1952 engine_frame_adjust_focus(self
->frame
);
1956 gboolean
client_focused(Client
*self
)
1958 return self
== focus_client
;