4 #include "extensions.h"
13 #include <X11/Xutil.h>
15 /*! The event mask to grab on client windows */
16 #define CLIENT_EVENTMASK (PropertyChangeMask | FocusChangeMask | \
19 #define CLIENT_NOPROPAGATEMASK (ButtonPressMask | ButtonReleaseMask | \
22 GSList
*client_list
= NULL
;
23 GHashTable
*client_map
= NULL
;
25 static void client_get_all(Client
*self
);
26 static void client_toggle_border(Client
*self
, gboolean show
);
27 static void client_get_area(Client
*self
);
28 static void client_get_desktop(Client
*self
);
29 static void client_get_state(Client
*self
);
30 static void client_get_shaped(Client
*self
);
31 static void client_get_mwm_hints(Client
*self
);
32 static void client_get_gravity(Client
*self
);
33 static void client_showhide(Client
*self
);
34 static void client_change_allowed_actions(Client
*self
);
35 static void client_change_state(Client
*self
);
36 static Client
*search_focus_tree(Client
*node
, Client
*skip
);
37 static void client_apply_startup_state(Client
*self
);
38 static Client
*search_modal_tree(Client
*node
, Client
*skip
);
40 static guint
map_hash(Window w
) { return w
; }
41 static gboolean
map_key_comp(Window w1
, Window w2
) { return w1
== w2
; }
45 client_map
= g_hash_table_new((GHashFunc
)map_hash
,
46 (GEqualFunc
)map_key_comp
);
50 void client_shutdown()
52 g_hash_table_destroy(client_map
);
55 void client_set_list()
57 Window
*windows
, *win_it
;
59 guint size
= g_slist_length(client_list
);
61 /* create an array of the window ids */
63 windows
= g_new(Window
, size
);
65 for (it
= client_list
; it
!= NULL
; it
= it
->next
, ++win_it
)
66 *win_it
= ((Client
*)it
->data
)->window
;
70 PROP_SET32A(ob_root
, net_client_list
, window
, windows
, size
);
78 void client_manage_all()
80 unsigned int i
, j
, nchild
;
83 XWindowAttributes attrib
;
85 XQueryTree(ob_display
, ob_root
, &w
, &w
, &children
, &nchild
);
87 /* remove all icon windows from the list */
88 for (i
= 0; i
< nchild
; i
++) {
89 if (children
[i
] == None
) continue;
90 wmhints
= XGetWMHints(ob_display
, children
[i
]);
92 if ((wmhints
->flags
& IconWindowHint
) &&
93 (wmhints
->icon_window
!= children
[i
]))
94 for (j
= 0; j
< nchild
; j
++)
95 if (children
[j
] == wmhints
->icon_window
) {
103 for (i
= 0; i
< nchild
; ++i
) {
104 if (children
[i
] == None
)
106 if (XGetWindowAttributes(ob_display
, children
[i
], &attrib
)) {
107 if (attrib
.override_redirect
) continue;
109 if (attrib
.map_state
!= IsUnmapped
)
110 client_manage(children
[i
]);
116 void client_manage(Window window
)
120 XWindowAttributes attrib
;
121 XSetWindowAttributes attrib_set
;
122 /* XWMHints *wmhint; */
124 XGrabServer(ob_display
);
125 XSync(ob_display
, FALSE
);
127 /* check if it has already been unmapped by the time we started mapping
128 the grab does a sync so we don't have to here */
129 if (XCheckTypedWindowEvent(ob_display
, window
, DestroyNotify
, &e
) ||
130 XCheckTypedWindowEvent(ob_display
, window
, UnmapNotify
, &e
)) {
131 XPutBackEvent(ob_display
, &e
);
133 XUngrabServer(ob_display
);
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
) {
141 XUngrabServer(ob_display
);
143 return; /* don't manage it */
146 /* /\* is the window a docking app *\/
147 if ((wmhint = XGetWMHints(ob_display, window))) {
148 if ((wmhint->flags & StateHint) &&
149 wmhint->initial_state == WithdrawnState) {
150 /\* XXX: make dock apps work! *\/
151 XUngrabServer(ob_display);
160 /* choose the events we want to receive on the CLIENT window */
161 attrib_set
.event_mask
= CLIENT_EVENTMASK
;
162 attrib_set
.do_not_propagate_mask
= CLIENT_NOPROPAGATEMASK
;
163 XChangeWindowAttributes(ob_display
, window
,
164 CWEventMask
|CWDontPropagate
, &attrib_set
);
167 /* create the Client struct, and populate it from the hints on the
169 client
= g_new(Client
, 1);
170 client
->window
= window
;
171 client_get_all(client
);
173 /* remove the client's border (and adjust re gravity) */
174 client_toggle_border(client
, FALSE
);
176 /* specify that if we exit, the window should not be destroyed and should
177 be reparented back to root automatically */
178 XChangeSaveSet(ob_display
, window
, SetModeInsert
);
180 /* create the decoration frame for the client window */
181 client
->frame
= engine_frame_new();
183 engine_frame_grab_client(client
->frame
, client
);
185 client_apply_startup_state(client
);
187 XUngrabServer(ob_display
);
190 client_list
= g_slist_append(client_list
, client
);
191 stacking_list
= g_list_append(stacking_list
, client
);
192 g_hash_table_insert(client_map
, (gpointer
)window
, client
);
194 stacking_raise(client
);
196 screen_update_struts();
198 dispatch_client(Event_Client_New
, client
, 0, 0);
200 client_showhide(client
);
202 dispatch_client(Event_Client_Mapped
, client
, 0, 0);
204 /* grab all mouse bindings */
205 /*pointer_grab_all(client, TRUE);XXX*/
207 /* update the list hints */
210 g_message("Managed window 0x%lx", window
);
213 void client_unmanage_all()
215 while (client_list
!= NULL
)
216 client_unmanage(client_list
->data
);
219 void client_unmanage(Client
*client
)
224 g_message("Unmanaging window: %lx", client
->window
);
226 dispatch_client(Event_Client_Destroy
, client
, 0, 0);
228 /* remove the window from our save set */
229 XChangeSaveSet(ob_display
, client
->window
, SetModeDelete
);
231 /* we dont want events no more */
232 XSelectInput(ob_display
, client
->window
, NoEventMask
);
234 /* ungrab any mouse bindings */
235 /*pointer_grab_all(client, FALSE);XXX*/
237 engine_frame_hide(client
->frame
);
239 /* give the client its border back */
240 client_toggle_border(client
, TRUE
);
242 /* reparent the window out of the frame, and free the frame */
243 engine_frame_release_client(client
->frame
, client
);
245 client_list
= g_slist_remove(client_list
, client
);
246 stacking_list
= g_list_remove(stacking_list
, client
);
247 g_hash_table_remove(client_map
, (gpointer
)client
->window
);
249 /* once the client is out of the list, update the struts to remove it's
251 screen_update_struts();
253 /* tell our parent that we're gone */
254 if (client
->transient_for
!= NULL
)
255 client
->transient_for
->transients
=
256 g_slist_remove(client
->transient_for
->transients
, client
);
258 /* tell our transients that we're gone */
259 for (it
= client
->transients
; it
!= NULL
; it
= it
->next
) {
260 ((Client
*)it
->data
)->transient_for
= NULL
;
261 client_calc_layer(it
->data
);
264 /* unfocus the client (calls the focus callbacks) (we're out of the
265 transient lists already, so being modal doesn't matter) */
267 client_unfocus(client
);
269 if (ob_state
!= State_Exiting
) {
270 /* these values should not be persisted across a window
272 prop_erase(client
->window
, prop_atoms
.net_wm_desktop
);
273 prop_erase(client
->window
, prop_atoms
.net_wm_state
);
275 /* if we're left in an iconic state, the client wont be mapped. this is
276 bad, since we will no longer be managing the window on restart */
278 XMapWindow(ob_display
, client
->window
);
281 /* free all data allocated in the client struct */
282 g_slist_free(client
->transients
);
283 for (j
= 0; j
< client
->nicons
; ++j
)
284 g_free(client
->icons
[j
].data
);
285 if (client
->nicons
> 0)
286 g_free(client
->icons
);
287 g_free(client
->title
);
288 g_free(client
->icon_title
);
289 g_free(client
->res_name
);
290 g_free(client
->res_class
);
291 g_free(client
->role
);
294 /* update the list hints */
298 static void client_toggle_border(Client
*self
, gboolean show
)
300 /* adjust our idea of where the client is, based on its border. When the
301 border is removed, the client should now be considered to be in a
303 when re-adding the border to the client, the same operation needs to be
305 int oldx
= self
->area
.x
, oldy
= self
->area
.y
;
306 int x
= oldx
, y
= oldy
;
307 switch(self
->gravity
) {
309 case NorthWestGravity
:
311 case SouthWestGravity
:
313 case NorthEastGravity
:
315 case SouthEastGravity
:
316 if (show
) x
-= self
->border_width
* 2;
317 else x
+= self
->border_width
* 2;
324 if (show
) x
-= self
->border_width
;
325 else x
+= self
->border_width
;
328 switch(self
->gravity
) {
330 case NorthWestGravity
:
332 case NorthEastGravity
:
334 case SouthWestGravity
:
336 case SouthEastGravity
:
337 if (show
) y
-= self
->border_width
* 2;
338 else y
+= self
->border_width
* 2;
345 if (show
) y
-= self
->border_width
;
346 else y
+= self
->border_width
;
353 XSetWindowBorderWidth(ob_display
, self
->window
, self
->border_width
);
355 /* move the client so it is back it the right spot _with_ its
357 if (x
!= oldx
|| y
!= oldy
)
358 XMoveWindow(ob_display
, self
->window
, x
, y
);
360 XSetWindowBorderWidth(ob_display
, self
->window
, 0);
364 static void client_get_all(Client
*self
)
366 /* update EVERYTHING!! */
368 self
->ignore_unmaps
= 0;
372 self
->title
= self
->icon_title
= NULL
;
373 self
->res_name
= self
->res_class
= self
->role
= NULL
;
374 self
->wmstate
= NormalState
;
375 self
->focused
= FALSE
;
376 self
->transient
= FALSE
;
377 self
->transients
= NULL
;
378 self
->transient_for
= NULL
;
380 self
->urgent
= FALSE
;
381 self
->positioned
= FALSE
;
382 self
->disabled_decorations
= 0;
386 client_get_area(self
);
387 client_get_desktop(self
);
388 client_get_state(self
);
389 client_get_shaped(self
);
391 client_update_transient_for(self
);
392 client_get_mwm_hints(self
);
393 client_get_type(self
);/* this can change the mwmhints for special cases */
395 client_update_protocols(self
);
397 client_get_gravity(self
); /* get the attribute gravity */
398 client_update_normal_hints(self
); /* this may override the attribute
401 /* got the type, the mwmhints, the protocols, and the normal hints
402 (min/max sizes), so we're ready to set up the decorations/functions */
403 client_setup_decor_and_functions(self
);
405 client_update_wmhints(self
);
406 client_update_title(self
);
407 client_update_icon_title(self
);
408 client_update_class(self
);
409 client_update_strut(self
);
410 client_update_icons(self
);
411 client_update_kwm_icon(self
);
413 /* this makes sure that these windows appear on all desktops */
414 if (self
->type
== Type_Desktop
)
415 self
->desktop
= DESKTOP_ALL
;
417 /* set the desktop hint, to make sure that it always exists, and to
418 reflect any changes we've made here */
419 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, self
->desktop
);
421 client_change_state(self
);
424 static void client_get_area(Client
*self
)
426 XWindowAttributes wattrib
;
429 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
430 g_assert(ret
!= BadWindow
);
432 RECT_SET(self
->area
, wattrib
.x
, wattrib
.y
, wattrib
.width
, wattrib
.height
);
433 self
->border_width
= wattrib
.border_width
;
436 static void client_get_desktop(Client
*self
)
440 if (PROP_GET32(self
->window
, net_wm_desktop
, cardinal
, d
)) {
441 if (d
>= screen_num_desktops
&& d
!= DESKTOP_ALL
)
442 d
= screen_num_desktops
- 1;
445 /* defaults to the current desktop */
446 self
->desktop
= screen_desktop
;
450 static void client_get_state(Client
*self
)
455 self
->modal
= self
->shaded
= self
->max_horz
= self
->max_vert
=
456 self
->fullscreen
= self
->above
= self
->below
= self
->iconic
=
457 self
->skip_taskbar
= self
->skip_pager
= FALSE
;
459 if (PROP_GET32U(self
->window
, net_wm_state
, atom
, state
, num
)) {
461 for (i
= 0; i
< num
; ++i
) {
462 if (state
[i
] == prop_atoms
.net_wm_state_modal
)
464 else if (state
[i
] == prop_atoms
.net_wm_state_shaded
)
466 else if (state
[i
] == prop_atoms
.net_wm_state_hidden
)
468 else if (state
[i
] == prop_atoms
.net_wm_state_skip_taskbar
)
469 self
->skip_taskbar
= TRUE
;
470 else if (state
[i
] == prop_atoms
.net_wm_state_skip_pager
)
471 self
->skip_pager
= TRUE
;
472 else if (state
[i
] == prop_atoms
.net_wm_state_fullscreen
)
473 self
->fullscreen
= TRUE
;
474 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_vert
)
475 self
->max_vert
= TRUE
;
476 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_horz
)
477 self
->max_horz
= TRUE
;
478 else if (state
[i
] == prop_atoms
.net_wm_state_above
)
480 else if (state
[i
] == prop_atoms
.net_wm_state_below
)
488 static void client_get_shaped(Client
*self
)
490 self
->shaped
= FALSE
;
492 if (extensions_shape
) {
497 XShapeSelectInput(ob_display
, self
->window
, ShapeNotifyMask
);
499 XShapeQueryExtents(ob_display
, self
->window
, &s
, &foo
,
500 &foo
, &ufoo
, &ufoo
, &foo
, &foo
, &foo
, &ufoo
,
502 self
->shaped
= (s
!= 0);
507 void client_update_transient_for(Client
*self
)
512 if (XGetTransientForHint(ob_display
, self
->window
, &t
) &&
513 t
!= self
->window
) { /* cant be transient to itself! */
514 self
->transient
= TRUE
;
515 c
= g_hash_table_lookup(client_map
, (gpointer
)t
);
516 g_assert(c
!= self
);/* if this happens then we need to check for it*/
518 if (!c
/*XXX: && _group*/) {
519 /* not transient to a client, see if it is transient for a
521 if (/*t == _group->leader() || */
524 /* window is a transient for its group! */
525 /* XXX: for now this is treated as non-transient.
526 this needs to be fixed! */
530 self
->transient
= FALSE
;
532 /* if anything has changed... */
533 if (c
!= self
->transient_for
) {
534 if (self
->transient_for
)
535 /* remove from old parent */
536 g_slist_remove(self
->transient_for
->transients
, self
);
537 self
->transient_for
= c
;
538 if (self
->transient_for
)
539 /* add to new parent */
540 g_slist_append(self
->transient_for
->transients
, self
);
544 static void client_get_mwm_hints(Client
*self
)
547 unsigned long *hints
;
549 self
->mwmhints
.flags
= 0; /* default to none */
551 if (PROP_GET32U(self
->window
, motif_wm_hints
, motif_wm_hints
, hints
, num
)) {
552 if (num
>= MWM_ELEMENTS
) {
553 self
->mwmhints
.flags
= hints
[0];
554 self
->mwmhints
.functions
= hints
[1];
555 self
->mwmhints
.decorations
= hints
[2];
561 void client_get_type(Client
*self
)
567 if (PROP_GET32U(self
->window
, net_wm_window_type
, atom
, val
, num
)) {
568 /* use the first value that we know about in the array */
569 for (i
= 0; i
< num
; ++i
) {
570 if (val
[i
] == prop_atoms
.net_wm_window_type_desktop
)
571 self
->type
= Type_Desktop
;
572 else if (val
[i
] == prop_atoms
.net_wm_window_type_dock
)
573 self
->type
= Type_Dock
;
574 else if (val
[i
] == prop_atoms
.net_wm_window_type_toolbar
)
575 self
->type
= Type_Toolbar
;
576 else if (val
[i
] == prop_atoms
.net_wm_window_type_menu
)
577 self
->type
= Type_Menu
;
578 else if (val
[i
] == prop_atoms
.net_wm_window_type_utility
)
579 self
->type
= Type_Utility
;
580 else if (val
[i
] == prop_atoms
.net_wm_window_type_splash
)
581 self
->type
= Type_Splash
;
582 else if (val
[i
] == prop_atoms
.net_wm_window_type_dialog
)
583 self
->type
= Type_Dialog
;
584 else if (val
[i
] == prop_atoms
.net_wm_window_type_normal
)
585 self
->type
= Type_Normal
;
586 else if (val
[i
] == prop_atoms
.kde_net_wm_window_type_override
) {
587 /* prevent this window from getting any decor or
589 self
->mwmhints
.flags
&= (MwmFlag_Functions
|
590 MwmFlag_Decorations
);
591 self
->mwmhints
.decorations
= 0;
592 self
->mwmhints
.functions
= 0;
594 if (self
->type
!= (WindowType
) -1)
595 break; /* grab the first legit type */
600 if (self
->type
== (WindowType
) -1) {
601 /*the window type hint was not set, which means we either classify
602 ourself as a normal window or a dialog, depending on if we are a
605 self
->type
= Type_Dialog
;
607 self
->type
= Type_Normal
;
611 void client_update_protocols(Client
*self
)
614 gulong num_return
, i
;
616 self
->focus_notify
= FALSE
;
617 self
->delete_window
= FALSE
;
619 if (PROP_GET32U(self
->window
, wm_protocols
, atom
, proto
, num_return
)) {
620 for (i
= 0; i
< num_return
; ++i
) {
621 if (proto
[i
] == prop_atoms
.wm_delete_window
) {
622 /* this means we can request the window to close */
623 self
->delete_window
= TRUE
;
624 } else if (proto
[i
] == prop_atoms
.wm_take_focus
)
625 /* if this protocol is requested, then the window will be
626 notified whenever we want it to receive focus */
627 self
->focus_notify
= TRUE
;
633 static void client_get_gravity(Client
*self
)
635 XWindowAttributes wattrib
;
638 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
639 g_assert(ret
!= BadWindow
);
640 self
->gravity
= wattrib
.win_gravity
;
643 void client_update_normal_hints(Client
*self
)
647 int oldgravity
= self
->gravity
;
650 self
->min_ratio
= 0.0f
;
651 self
->max_ratio
= 0.0f
;
652 SIZE_SET(self
->size_inc
, 1, 1);
653 SIZE_SET(self
->base_size
, 0, 0);
654 SIZE_SET(self
->min_size
, 0, 0);
655 SIZE_SET(self
->max_size
, G_MAXINT
, G_MAXINT
);
657 /* get the hints from the window */
658 if (XGetWMNormalHints(ob_display
, self
->window
, &size
, &ret
)) {
659 self
->positioned
= (size
.flags
& (PPosition
|USPosition
));
661 if (size
.flags
& PWinGravity
) {
662 self
->gravity
= size
.win_gravity
;
664 /* if the client has a frame, i.e. has already been mapped and
665 is changing its gravity */
666 if (self
->frame
&& self
->gravity
!= oldgravity
) {
667 /* move our idea of the client's position based on its new
669 self
->area
.x
= self
->frame
->area
.x
;
670 self
->area
.y
= self
->frame
->area
.y
;
671 frame_frame_gravity(self
->frame
, &self
->area
.x
, &self
->area
.y
);
675 if (size
.flags
& PAspect
) {
676 if (size
.min_aspect
.y
)
677 self
->min_ratio
= (float)size
.min_aspect
.x
/ size
.min_aspect
.y
;
678 if (size
.max_aspect
.y
)
679 self
->max_ratio
= (float)size
.max_aspect
.x
/ size
.max_aspect
.y
;
682 if (size
.flags
& PMinSize
)
683 SIZE_SET(self
->min_size
, size
.min_width
, size
.min_height
);
685 if (size
.flags
& PMaxSize
)
686 SIZE_SET(self
->max_size
, size
.max_width
, size
.max_height
);
688 if (size
.flags
& PBaseSize
)
689 SIZE_SET(self
->base_size
, size
.base_width
, size
.base_height
);
691 if (size
.flags
& PResizeInc
)
692 SIZE_SET(self
->size_inc
, size
.width_inc
, size
.height_inc
);
696 void client_setup_decor_and_functions(Client
*self
)
698 /* start with everything (cept fullscreen) */
699 self
->decorations
= Decor_Titlebar
| Decor_Handle
| Decor_Border
|
700 Decor_Icon
| Decor_AllDesktops
| Decor_Iconify
| Decor_Maximize
;
701 self
->functions
= Func_Resize
| Func_Move
| Func_Iconify
| Func_Maximize
|
703 if (self
->delete_window
) {
704 self
->decorations
|= Decor_Close
;
705 self
->functions
|= Func_Close
;
708 if (!(self
->min_size
.width
< self
->max_size
.width
||
709 self
->min_size
.height
< self
->max_size
.height
)) {
710 self
->decorations
&= ~(Decor_Maximize
| Decor_Handle
);
711 self
->functions
&= ~(Func_Resize
| Func_Maximize
);
714 switch (self
->type
) {
716 /* normal windows retain all of the possible decorations and
717 functionality, and are the only windows that you can fullscreen */
718 self
->functions
|= Func_Fullscreen
;
722 /* dialogs cannot be maximized */
723 self
->decorations
&= ~Decor_Maximize
;
724 self
->functions
&= ~Func_Maximize
;
730 /* these windows get less functionality */
731 self
->decorations
&= ~(Decor_Iconify
| Decor_Handle
);
732 self
->functions
&= ~(Func_Iconify
| Func_Resize
);
738 /* none of these windows are manipulated by the window manager */
739 self
->decorations
= 0;
744 /* Mwm Hints are applied subtractively to what has already been chosen for
745 decor and functionality */
746 if (self
->mwmhints
.flags
& MwmFlag_Decorations
) {
747 if (! (self
->mwmhints
.decorations
& MwmDecor_All
)) {
748 if (! (self
->mwmhints
.decorations
& MwmDecor_Border
))
749 self
->decorations
&= ~Decor_Border
;
750 if (! (self
->mwmhints
.decorations
& MwmDecor_Handle
))
751 self
->decorations
&= ~Decor_Handle
;
752 if (! (self
->mwmhints
.decorations
& MwmDecor_Title
))
753 self
->decorations
&= ~Decor_Titlebar
;
754 if (! (self
->mwmhints
.decorations
& MwmDecor_Iconify
))
755 self
->decorations
&= ~Decor_Iconify
;
756 if (! (self
->mwmhints
.decorations
& MwmDecor_Maximize
))
757 self
->decorations
&= ~Decor_Maximize
;
761 if (self
->mwmhints
.flags
& MwmFlag_Functions
) {
762 if (! (self
->mwmhints
.functions
& MwmFunc_All
)) {
763 if (! (self
->mwmhints
.functions
& MwmFunc_Resize
))
764 self
->functions
&= ~Func_Resize
;
765 if (! (self
->mwmhints
.functions
& MwmFunc_Move
))
766 self
->functions
&= ~Func_Move
;
767 if (! (self
->mwmhints
.functions
& MwmFunc_Iconify
))
768 self
->functions
&= ~Func_Iconify
;
769 if (! (self
->mwmhints
.functions
& MwmFunc_Maximize
))
770 self
->functions
&= ~Func_Maximize
;
771 /* dont let mwm hints kill the close button
772 if (! (self->mwmhints.functions & MwmFunc_Close))
773 self->functions &= ~Func_Close; */
777 /* can't maximize without moving/resizing */
778 if (!((self
->functions
& Func_Move
) && (self
->functions
& Func_Resize
)))
779 self
->functions
&= ~Func_Maximize
;
781 /* finally, user specified disabled decorations are applied to subtract
783 if (self
->disabled_decorations
& Decor_Titlebar
)
784 self
->decorations
&= ~Decor_Titlebar
;
785 if (self
->disabled_decorations
& Decor_Handle
)
786 self
->decorations
&= ~Decor_Handle
;
787 if (self
->disabled_decorations
& Decor_Border
)
788 self
->decorations
&= ~Decor_Border
;
789 if (self
->disabled_decorations
& Decor_Iconify
)
790 self
->decorations
&= ~Decor_Iconify
;
791 if (self
->disabled_decorations
& Decor_Maximize
)
792 self
->decorations
&= ~Decor_Maximize
;
793 if (self
->disabled_decorations
& Decor_AllDesktops
)
794 self
->decorations
&= ~Decor_AllDesktops
;
795 if (self
->disabled_decorations
& Decor_Close
)
796 self
->decorations
&= ~Decor_Close
;
798 /* if we don't have a titlebar, then we cannot shade! */
799 if (!(self
->decorations
& Decor_Titlebar
))
800 self
->functions
&= ~Func_Shade
;
802 client_change_allowed_actions(self
);
805 /* change the decors on the frame */
806 engine_frame_adjust_size(self
->frame
);
807 /* with more/less decorations, we may need to be repositioned */
808 engine_frame_adjust_position(self
->frame
);
809 /* with new decor, the window's maximized size may change */
810 client_remaximize(self
);
814 static void client_change_allowed_actions(Client
*self
)
819 actions
[num
++] = prop_atoms
.net_wm_action_change_desktop
;
821 if (self
->functions
& Func_Shade
)
822 actions
[num
++] = prop_atoms
.net_wm_action_shade
;
823 if (self
->functions
& Func_Close
)
824 actions
[num
++] = prop_atoms
.net_wm_action_close
;
825 if (self
->functions
& Func_Move
)
826 actions
[num
++] = prop_atoms
.net_wm_action_move
;
827 if (self
->functions
& Func_Iconify
)
828 actions
[num
++] = prop_atoms
.net_wm_action_minimize
;
829 if (self
->functions
& Func_Resize
)
830 actions
[num
++] = prop_atoms
.net_wm_action_resize
;
831 if (self
->functions
& Func_Fullscreen
)
832 actions
[num
++] = prop_atoms
.net_wm_action_fullscreen
;
833 if (self
->functions
& Func_Maximize
) {
834 actions
[num
++] = prop_atoms
.net_wm_action_maximize_horz
;
835 actions
[num
++] = prop_atoms
.net_wm_action_maximize_vert
;
838 PROP_SET32A(self
->window
, net_wm_allowed_actions
, atom
, actions
, num
);
840 /* make sure the window isn't breaking any rules now */
842 if (!(self
->functions
& Func_Shade
) && self
->shaded
) {
843 if (self
->frame
) client_shade(self
, FALSE
);
844 else self
->shaded
= FALSE
;
846 if (!(self
->functions
& Func_Iconify
) && self
->iconic
) {
847 if (self
->frame
) client_iconify(self
, FALSE
, TRUE
);
848 else self
->iconic
= FALSE
;
850 if (!(self
->functions
& Func_Fullscreen
) && self
->fullscreen
) {
851 if (self
->frame
) client_fullscreen(self
, FALSE
, TRUE
);
852 else self
->fullscreen
= FALSE
;
854 if (!(self
->functions
& Func_Maximize
) && (self
->max_horz
||
856 if (self
->frame
) client_maximize(self
, FALSE
, 0, TRUE
);
857 else self
->max_vert
= self
->max_horz
= FALSE
;
861 void client_remaximize(Client
*self
)
864 if (self
->max_horz
&& self
->max_vert
)
866 else if (self
->max_horz
)
868 else if (self
->max_vert
)
871 return; /* not maximized */
872 self
->max_horz
= self
->max_vert
= FALSE
;
873 client_maximize(self
, TRUE
, dir
, FALSE
);
876 void client_update_wmhints(Client
*self
)
881 /* assume a window takes input if it doesnt specify */
882 self
->can_focus
= TRUE
;
884 if ((hints
= XGetWMHints(ob_display
, self
->window
)) != NULL
) {
885 if (hints
->flags
& InputHint
)
886 self
->can_focus
= hints
->input
;
888 /* only do this when starting! */
889 if (ob_state
== State_Starting
&& (hints
->flags
& StateHint
))
890 self
->iconic
= hints
->initial_state
== IconicState
;
892 if (hints
->flags
& XUrgencyHint
)
895 if (hints
->flags
& WindowGroupHint
) {
896 if (hints
->window_group
!= self
->group
) {
897 /* XXX: remove from the old group if there was one */
898 self
->group
= hints
->window_group
;
899 /* XXX: do stuff with the group */
901 } else /* no group! */
904 if (hints
->flags
& IconPixmapHint
) {
905 client_update_kwm_icon(self
);
906 /* try get the kwm icon first, this is a fallback only */
907 if (self
->pixmap_icon
== None
) {
908 self
->pixmap_icon
= hints
->icon_pixmap
;
909 if (hints
->flags
& IconMaskHint
)
910 self
->pixmap_icon_mask
= hints
->icon_mask
;
912 self
->pixmap_icon_mask
= None
;
915 engine_frame_adjust_icon(self
->frame
);
922 if (ur
!= self
->urgent
) {
924 g_message("Urgent Hint for 0x%lx: %s\n", self
->window
,
926 /* fire the urgent callback if we're mapped, otherwise, wait until
927 after we're mapped */
929 dispatch_client(Event_Client_Urgent
, self
, self
->urgent
, 0);
933 void client_update_title(Client
*self
)
937 if (self
->title
!= NULL
)
941 if (!PROP_GETS(self
->window
, net_wm_name
, utf8
, data
)) {
942 /* try old x stuff */
943 if (PROP_GETS(self
->window
, wm_name
, string
, data
)) {
944 /* convert it to UTF-8 */
948 u
= g_locale_to_utf8(data
, -1, &r
, &w
, NULL
);
950 g_warning("Unable to convert string to UTF-8");
957 data
= g_strdup("Unnamed Window");
959 PROP_SETS(self
->window
, net_wm_visible_name
, utf8
, data
);
965 engine_frame_adjust_title(self
->frame
);
968 void client_update_icon_title(Client
*self
)
972 if (self
->icon_title
!= NULL
)
973 g_free(self
->icon_title
);
976 if (!PROP_GETS(self
->window
, net_wm_icon_name
, utf8
, data
)) {
977 /* try old x stuff */
978 if (PROP_GETS(self
->window
, wm_icon_name
, string
, data
)) {
979 /* convert it to UTF-8 */
983 u
= g_locale_to_utf8(data
, -1, &r
, &w
, NULL
);
985 g_warning("Unable to convert string to UTF-8");
992 data
= g_strdup("Unnamed Window");
994 PROP_SETS(self
->window
, net_wm_visible_icon_name
, utf8
, data
);
997 self
->icon_title
= data
;
1000 void client_update_class(Client
*self
)
1006 if (self
->res_name
) g_free(self
->res_name
);
1007 if (self
->res_class
) g_free(self
->res_class
);
1008 if (self
->role
) g_free(self
->role
);
1010 self
->res_name
= self
->res_class
= self
->role
= NULL
;
1012 data
= g_ptr_array_new();
1014 if (PROP_GETSA(self
->window
, wm_class
, string
, data
)) {
1016 self
->res_name
= g_strdup(g_ptr_array_index(data
, 0));
1018 self
->res_class
= g_strdup(g_ptr_array_index(data
, 1));
1021 for (i
= 0; i
< data
->len
; ++i
)
1022 g_free(g_ptr_array_index(data
, i
));
1023 g_ptr_array_free(data
, TRUE
);
1025 if (PROP_GETS(self
->window
, wm_window_role
, string
, s
))
1026 self
->role
= g_strdup(s
);
1028 if (self
->res_name
== NULL
) self
->res_name
= g_strdup("");
1029 if (self
->res_class
== NULL
) self
->res_class
= g_strdup("");
1030 if (self
->role
== NULL
) self
->role
= g_strdup("");
1033 void client_update_strut(Client
*self
)
1037 if (PROP_GET32A(self
->window
, net_wm_strut
, cardinal
, data
, 4)) {
1038 STRUT_SET(self
->strut
, data
[0], data
[1], data
[2], data
[3]);
1041 STRUT_SET(self
->strut
, 0, 0, 0, 0);
1043 /* updating here is pointless while we're being mapped cuz we're not in
1044 the client list yet */
1046 screen_update_struts();
1049 void client_update_icons(Client
*self
)
1052 unsigned long *data
;
1053 unsigned long w
, h
, i
;
1056 for (j
= 0; j
< self
->nicons
; ++j
)
1057 g_free(self
->icons
[j
].data
);
1058 if (self
->nicons
> 0)
1059 g_free(self
->icons
);
1062 if (PROP_GET32U(self
->window
, net_wm_icon
, cardinal
, data
, num
)) {
1063 /* figure out how many valid icons are in here */
1065 while (num
- i
> 2) {
1073 self
->icons
= g_new(Icon
, self
->nicons
);
1075 /* store the icons */
1077 for (j
= 0; j
< self
->nicons
; ++j
) {
1078 w
= self
->icons
[j
].w
= data
[i
++];
1079 h
= self
->icons
[j
].h
= data
[i
++];
1080 self
->icons
[j
].data
=
1081 g_memdup(&data
[i
], w
* h
* sizeof(gulong
));
1089 if (self
->nicons
<= 0) {
1091 self
->icons
= g_new0(Icon
, 1);
1095 engine_frame_adjust_icon(self
->frame
);
1098 void client_update_kwm_icon(Client
*self
)
1102 if (PROP_GET32A(self
->window
, kwm_win_icon
, kwm_win_icon
, data
, 2)) {
1103 self
->pixmap_icon
= data
[0];
1104 self
->pixmap_icon_mask
= data
[1];
1107 self
->pixmap_icon
= self
->pixmap_icon_mask
= None
;
1110 engine_frame_adjust_icon(self
->frame
);
1113 static void client_change_state(Client
*self
)
1115 unsigned long state
[2];
1119 state
[0] = self
->wmstate
;
1121 PROP_SET32A(self
->window
, wm_state
, wm_state
, state
, 2);
1125 netstate
[num
++] = prop_atoms
.net_wm_state_modal
;
1127 netstate
[num
++] = prop_atoms
.net_wm_state_shaded
;
1129 netstate
[num
++] = prop_atoms
.net_wm_state_hidden
;
1130 if (self
->skip_taskbar
)
1131 netstate
[num
++] = prop_atoms
.net_wm_state_skip_taskbar
;
1132 if (self
->skip_pager
)
1133 netstate
[num
++] = prop_atoms
.net_wm_state_skip_pager
;
1134 if (self
->fullscreen
)
1135 netstate
[num
++] = prop_atoms
.net_wm_state_fullscreen
;
1137 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_vert
;
1139 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_horz
;
1141 netstate
[num
++] = prop_atoms
.net_wm_state_above
;
1143 netstate
[num
++] = prop_atoms
.net_wm_state_below
;
1144 PROP_SET32A(self
->window
, net_wm_state
, atom
, netstate
, num
);
1146 client_calc_layer(self
);
1149 engine_frame_adjust_state(self
->frame
);
1152 static Client
*search_focus_tree(Client
*node
, Client
*skip
)
1157 for (it
= node
->transients
; it
!= NULL
; it
= g_slist_next(it
)) {
1158 Client
*c
= it
->data
;
1159 if (c
== skip
) continue; /* circular? */
1160 if ((ret
= search_focus_tree(c
, skip
))) return ret
;
1161 if (c
->focused
) return c
;
1166 void client_calc_layer(Client
*self
)
1172 /* are we fullscreen, or do we have a fullscreen transient parent? */
1176 if (c
->fullscreen
) {
1180 c
= c
->transient_for
;
1182 if (!fs
&& self
->fullscreen
) {
1183 /* is one of our transients focused? */
1184 c
= search_focus_tree(self
, self
);
1185 if (c
!= NULL
) fs
= TRUE
;
1188 if (self
->iconic
) l
= Layer_Icon
;
1189 else if (fs
) l
= Layer_Fullscreen
;
1190 else if (self
->type
== Type_Desktop
) l
= Layer_Desktop
;
1191 else if (self
->type
== Type_Dock
) {
1192 if (!self
->below
) l
= Layer_Top
;
1193 else l
= Layer_Normal
;
1195 else if (self
->above
) l
= Layer_Above
;
1196 else if (self
->below
) l
= Layer_Below
;
1197 else l
= Layer_Normal
;
1199 if (l
!= self
->layer
) {
1202 stacking_raise(self
);
1206 gboolean
client_should_show(Client
*self
)
1208 if (self
->iconic
) return FALSE
;
1209 else if (!(self
->desktop
== screen_desktop
||
1210 self
->desktop
== DESKTOP_ALL
)) return FALSE
;
1211 else if (client_normal(self
) && screen_showing_desktop
) return FALSE
;
1216 static void client_showhide(Client
*self
)
1219 if (client_should_show(self
))
1220 engine_frame_show(self
->frame
);
1222 engine_frame_hide(self
->frame
);
1225 gboolean
client_normal(Client
*self
) {
1226 return ! (self
->type
== Type_Desktop
|| self
->type
== Type_Dock
||
1227 self
->type
== Type_Splash
);
1230 static void client_apply_startup_state(Client
*self
)
1232 /* these are in a carefully crafted order.. */
1235 self
->iconic
= FALSE
;
1236 client_iconify(self
, TRUE
, FALSE
);
1238 if (self
->fullscreen
) {
1239 self
->fullscreen
= FALSE
;
1240 client_fullscreen(self
, TRUE
, FALSE
);
1243 self
->shaded
= FALSE
;
1244 client_shade(self
, TRUE
);
1247 dispatch_client(Event_Client_Urgent
, self
, self
->urgent
, 0);
1249 if (self
->max_vert
&& self
->max_horz
) {
1250 self
->max_vert
= self
->max_horz
= FALSE
;
1251 client_maximize(self
, TRUE
, 0, FALSE
);
1252 } else if (self
->max_vert
) {
1253 self
->max_vert
= FALSE
;
1254 client_maximize(self
, TRUE
, 2, FALSE
);
1255 } else if (self
->max_horz
) {
1256 self
->max_horz
= FALSE
;
1257 client_maximize(self
, TRUE
, 1, FALSE
);
1260 /* nothing to do for the other states:
1269 void client_configure(Client
*self
, Corner anchor
, int x
, int y
, int w
, int h
,
1270 gboolean user
, gboolean final
)
1272 gboolean moved
= FALSE
, resized
= FALSE
;
1274 w
-= self
->base_size
.width
;
1275 h
-= self
->base_size
.height
;
1278 /* for interactive resizing. have to move half an increment in each
1281 /* how far we are towards the next size inc */
1282 int mw
= w
% self
->size_inc
.width
;
1283 int mh
= h
% self
->size_inc
.height
;
1285 int aw
= self
->size_inc
.width
/ 2;
1286 int ah
= self
->size_inc
.height
/ 2;
1287 /* don't let us move into a new size increment */
1288 if (mw
+ aw
>= self
->size_inc
.width
)
1289 aw
= self
->size_inc
.width
- mw
- 1;
1290 if (mh
+ ah
>= self
->size_inc
.height
)
1291 ah
= self
->size_inc
.height
- mh
- 1;
1295 /* if this is a user-requested resize, then check against min/max
1296 sizes and aspect ratios */
1298 /* smaller than min size or bigger than max size? */
1299 if (w
> self
->max_size
.width
) w
= self
->max_size
.width
;
1300 if (w
< self
->min_size
.width
) w
= self
->min_size
.width
;
1301 if (h
> self
->max_size
.height
) h
= self
->max_size
.height
;
1302 if (h
< self
->min_size
.height
) h
= self
->min_size
.height
;
1304 /* adjust the height ot match the width for the aspect ratios */
1305 if (self
->min_ratio
)
1306 if (h
* self
->min_ratio
> w
) h
= (int)(w
/ self
->min_ratio
);
1307 if (self
->max_ratio
)
1308 if (h
* self
->max_ratio
< w
) h
= (int)(w
/ self
->max_ratio
);
1311 /* keep to the increments */
1312 w
/= self
->size_inc
.width
;
1313 h
/= self
->size_inc
.height
;
1315 /* you cannot resize to nothing */
1319 /* store the logical size */
1320 SIZE_SET(self
->logical_size
, w
, h
);
1322 w
*= self
->size_inc
.width
;
1323 h
*= self
->size_inc
.height
;
1325 w
+= self
->base_size
.width
;
1326 h
+= self
->base_size
.height
;
1329 case Corner_TopLeft
:
1331 case Corner_TopRight
:
1332 x
-= w
- self
->area
.width
;
1334 case Corner_BottomLeft
:
1335 y
-= h
- self
->area
.height
;
1337 case Corner_BottomRight
:
1338 x
-= w
- self
->area
.width
;
1339 y
-= h
- self
->area
.height
;
1343 moved
= x
!= self
->area
.x
|| y
!= self
->area
.y
;
1344 resized
= w
!= self
->area
.width
|| h
!= self
->area
.height
;
1346 RECT_SET(self
->area
, x
, y
, w
, h
);
1349 XResizeWindow(ob_display
, self
->window
, w
, h
);
1351 /* move/resize the frame to match the request */
1353 /* Adjust the size and then the position, as required by the EWMH */
1355 engine_frame_adjust_size(self
->frame
);
1357 engine_frame_adjust_position(self
->frame
);
1359 if (!user
|| final
) {
1361 event
.type
= ConfigureNotify
;
1362 event
.xconfigure
.display
= ob_display
;
1363 event
.xconfigure
.event
= self
->window
;
1364 event
.xconfigure
.window
= self
->window
;
1366 /* root window coords with border in mind */
1367 event
.xconfigure
.x
= x
- self
->border_width
+
1368 self
->frame
->size
.left
;
1369 event
.xconfigure
.y
= y
- self
->border_width
+
1370 self
->frame
->size
.top
;
1372 event
.xconfigure
.width
= self
->area
.width
;
1373 event
.xconfigure
.height
= self
->area
.height
;
1374 event
.xconfigure
.border_width
= self
->border_width
;
1375 event
.xconfigure
.above
= self
->frame
->plate
;
1376 event
.xconfigure
.override_redirect
= FALSE
;
1377 XSendEvent(event
.xconfigure
.display
, event
.xconfigure
.window
,
1378 FALSE
, StructureNotifyMask
, &event
);
1384 void client_fullscreen(Client
*self
, gboolean fs
, gboolean savearea
)
1386 static int saved_func
, saved_decor
;
1389 if (!(self
->functions
& Func_Fullscreen
) || /* can't */
1390 self
->fullscreen
== fs
) return; /* already done */
1392 self
->fullscreen
= fs
;
1393 client_change_state(self
); /* change the state hints on the client */
1396 /* save the functions and remove them */
1397 saved_func
= self
->functions
;
1398 self
->functions
&= (Func_Close
| Func_Fullscreen
|
1400 /* save the decorations and remove them */
1401 saved_decor
= self
->decorations
;
1402 self
->decorations
= 0;
1405 dimensions
[0] = self
->area
.x
;
1406 dimensions
[1] = self
->area
.y
;
1407 dimensions
[2] = self
->area
.width
;
1408 dimensions
[3] = self
->area
.height
;
1410 PROP_SET32A(self
->window
, openbox_premax
, cardinal
,
1415 w
= screen_physical_size
.width
;
1416 h
= screen_physical_size
.height
;
1420 self
->functions
= saved_func
;
1421 self
->decorations
= saved_decor
;
1423 if (PROP_GET32A(self
->window
, openbox_premax
, cardinal
,
1431 /* pick some fallbacks... */
1432 x
= screen_area(self
->desktop
)->x
+
1433 screen_area(self
->desktop
)->width
/ 4;
1434 y
= screen_area(self
->desktop
)->y
+
1435 screen_area(self
->desktop
)->height
/ 4;
1436 w
= screen_area(self
->desktop
)->width
/ 2;
1437 h
= screen_area(self
->desktop
)->height
/ 2;
1441 client_change_allowed_actions(self
); /* based on the new _functions */
1443 /* when fullscreening, don't obey things like increments, fill the
1445 client_configure(self
, Corner_TopLeft
, x
, y
, w
, h
, !fs
, TRUE
);
1447 /* raise (back) into our stacking layer */
1448 stacking_raise(self
);
1450 /* try focus us when we go into fullscreen mode */
1454 void client_iconify(Client
*self
, gboolean iconic
, gboolean curdesk
)
1456 if (self
->iconic
== iconic
) return; /* nothing to do */
1458 g_message("%sconifying window: 0x%lx\n", (iconic
? "I" : "Uni"),
1461 self
->iconic
= iconic
;
1464 self
->wmstate
= IconicState
;
1465 self
->ignore_unmaps
++;
1466 /* we unmap the client itself so that we can get MapRequest events,
1467 and because the ICCCM tells us to! */
1468 XUnmapWindow(ob_display
, self
->window
);
1471 client_set_desktop(self
, screen_desktop
);
1472 self
->wmstate
= self
->shaded
? IconicState
: NormalState
;
1473 XMapWindow(ob_display
, self
->window
);
1475 client_change_state(self
);
1476 client_showhide(self
);
1477 screen_update_struts();
1480 void client_maximize(Client
*self
, gboolean max
, int dir
, gboolean savearea
)
1484 g_assert(dir
== 0 || dir
== 1 || dir
== 2);
1485 if (!(self
->functions
& Func_Maximize
)) return; /* can't */
1487 /* check if already done */
1489 if (dir
== 0 && self
->max_horz
&& self
->max_vert
) return;
1490 if (dir
== 1 && self
->max_horz
) return;
1491 if (dir
== 2 && self
->max_vert
) return;
1493 if (dir
== 0 && !self
->max_horz
&& !self
->max_vert
) return;
1494 if (dir
== 1 && !self
->max_horz
) return;
1495 if (dir
== 2 && !self
->max_vert
) return;
1498 /* work with the frame's coords */
1499 x
= self
->frame
->area
.x
;
1500 y
= self
->frame
->area
.y
;
1501 w
= self
->area
.width
;
1502 h
= self
->area
.height
;
1514 /* get the property off the window and use it for the dimensions
1515 we are already maxed on */
1516 if (PROP_GET32A(self
->window
, openbox_premax
, cardinal
,
1518 if (self
->max_horz
) {
1519 dimensions
[0] = readdim
[0];
1520 dimensions
[2] = readdim
[2];
1522 if (self
->max_vert
) {
1523 dimensions
[1] = readdim
[1];
1524 dimensions
[3] = readdim
[3];
1529 PROP_SET32A(self
->window
, openbox_premax
, cardinal
,
1532 if (dir
== 0 || dir
== 1) { /* horz */
1533 x
= screen_area(self
->desktop
)->x
- self
->frame
->size
.left
;
1534 w
= screen_area(self
->desktop
)->x
+
1535 screen_area(self
->desktop
)->width
;
1537 if (dir
== 0 || dir
== 2) { /* vert */
1538 y
= screen_area(self
->desktop
)->y
;
1539 h
= screen_area(self
->desktop
)->y
+
1540 screen_area(self
->desktop
)->height
-
1541 self
->frame
->size
.top
- self
->frame
->size
.bottom
;
1546 if (PROP_GET32A(self
->window
, openbox_premax
, cardinal
,
1548 if (dir
== 0 || dir
== 1) { /* horz */
1552 if (dir
== 0 || dir
== 2) { /* vert */
1558 /* pick some fallbacks... */
1559 if (dir
== 0 || dir
== 1) { /* horz */
1560 x
= screen_area(self
->desktop
)->x
+
1561 screen_area(self
->desktop
)->width
/ 4;
1562 w
= screen_area(self
->desktop
)->width
/ 2;
1564 if (dir
== 0 || dir
== 2) { /* vert */
1565 y
= screen_area(self
->desktop
)->y
+
1566 screen_area(self
->desktop
)->height
/ 4;
1567 h
= screen_area(self
->desktop
)->height
/ 2;
1572 if (dir
== 0 || dir
== 1) /* horz */
1573 self
->max_horz
= max
;
1574 if (dir
== 0 || dir
== 2) /* vert */
1575 self
->max_vert
= max
;
1577 if (!self
->max_horz
&& !self
->max_vert
)
1578 PROP_ERASE(self
->window
, openbox_premax
);
1580 client_change_state(self
); /* change the state hints on the client */
1582 /* figure out where the client should be going */
1583 frame_frame_gravity(self
->frame
, &x
, &y
);
1584 client_configure(self
, Corner_TopLeft
, x
, y
, w
, h
, TRUE
, TRUE
);
1587 void client_shade(Client
*self
, gboolean shade
)
1589 if (!(self
->functions
& Func_Shade
) || /* can't */
1590 self
->shaded
== shade
) return; /* already done */
1592 /* when we're iconic, don't change the wmstate */
1594 self
->wmstate
= shade
? IconicState
: NormalState
;
1595 self
->shaded
= shade
;
1596 client_change_state(self
);
1597 engine_frame_adjust_size(self
->frame
);
1600 void client_close(Client
*self
)
1604 if (!(self
->functions
& Func_Close
)) return;
1607 XXX: itd be cool to do timeouts and shit here for killing the client's
1609 like... if the window is around after 5 seconds, then the close button
1610 turns a nice red, and if this function is called again, the client is
1614 ce
.xclient
.type
= ClientMessage
;
1615 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
1616 ce
.xclient
.display
= ob_display
;
1617 ce
.xclient
.window
= self
->window
;
1618 ce
.xclient
.format
= 32;
1619 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_delete_window
;
1620 ce
.xclient
.data
.l
[1] = CurrentTime
;
1621 ce
.xclient
.data
.l
[2] = 0l;
1622 ce
.xclient
.data
.l
[3] = 0l;
1623 ce
.xclient
.data
.l
[4] = 0l;
1624 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
1627 void client_set_desktop(Client
*self
, guint target
)
1631 if (target
== self
->desktop
) return;
1633 g_message("Setting desktop %u\n", target
);
1635 if (!(target
< screen_num_desktops
||
1636 target
== DESKTOP_ALL
))
1639 old
= self
->desktop
;
1640 self
->desktop
= target
;
1641 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, target
);
1642 /* the frame can display the current desktop state */
1643 engine_frame_adjust_state(self
->frame
);
1644 /* 'move' the window to the new desktop */
1645 client_showhide(self
);
1646 screen_update_struts();
1648 dispatch_client(Event_Client_Desktop
, self
, target
, old
);
1651 static Client
*search_modal_tree(Client
*node
, Client
*skip
)
1656 for (it
= node
->transients
; it
!= NULL
; it
= it
->next
) {
1657 Client
*c
= it
->data
;
1658 if (c
== skip
) continue; /* circular? */
1659 if ((ret
= search_modal_tree(c
, skip
))) return ret
;
1660 if (c
->modal
) return c
;
1665 Client
*client_find_modal_child(Client
*self
)
1667 return search_modal_tree(self
, self
);
1670 gboolean
client_validate(Client
*self
)
1674 XSync(ob_display
, FALSE
); /* get all events on the server */
1676 if (XCheckTypedWindowEvent(ob_display
, self
->window
, DestroyNotify
, &e
) ||
1677 XCheckTypedWindowEvent(ob_display
, self
->window
, UnmapNotify
, &e
)) {
1678 XPutBackEvent(ob_display
, &e
);
1685 void client_set_wm_state(Client
*self
, long state
)
1687 if (state
== self
->wmstate
) return; /* no change */
1691 client_iconify(self
, TRUE
, TRUE
);
1694 client_iconify(self
, FALSE
, TRUE
);
1699 void client_set_state(Client
*self
, Atom action
, long data1
, long data2
)
1701 gboolean shaded
= self
->shaded
;
1702 gboolean fullscreen
= self
->fullscreen
;
1703 gboolean max_horz
= self
->max_horz
;
1704 gboolean max_vert
= self
->max_vert
;
1707 if (!(action
== prop_atoms
.net_wm_state_add
||
1708 action
== prop_atoms
.net_wm_state_remove
||
1709 action
== prop_atoms
.net_wm_state_toggle
))
1710 /* an invalid action was passed to the client message, ignore it */
1713 for (i
= 0; i
< 2; ++i
) {
1714 Atom state
= i
== 0 ? data1
: data2
;
1716 if (!state
) continue;
1718 /* if toggling, then pick whether we're adding or removing */
1719 if (action
== prop_atoms
.net_wm_state_toggle
) {
1720 if (state
== prop_atoms
.net_wm_state_modal
)
1721 action
= self
->modal
? prop_atoms
.net_wm_state_remove
:
1722 prop_atoms
.net_wm_state_add
;
1723 else if (state
== prop_atoms
.net_wm_state_maximized_vert
)
1724 action
= self
->max_vert
? prop_atoms
.net_wm_state_remove
:
1725 prop_atoms
.net_wm_state_add
;
1726 else if (state
== prop_atoms
.net_wm_state_maximized_horz
)
1727 action
= self
->max_horz
? prop_atoms
.net_wm_state_remove
:
1728 prop_atoms
.net_wm_state_add
;
1729 else if (state
== prop_atoms
.net_wm_state_shaded
)
1730 action
= self
->shaded
? prop_atoms
.net_wm_state_remove
:
1731 prop_atoms
.net_wm_state_add
;
1732 else if (state
== prop_atoms
.net_wm_state_skip_taskbar
)
1733 action
= self
->skip_taskbar
?
1734 prop_atoms
.net_wm_state_remove
:
1735 prop_atoms
.net_wm_state_add
;
1736 else if (state
== prop_atoms
.net_wm_state_skip_pager
)
1737 action
= self
->skip_pager
?
1738 prop_atoms
.net_wm_state_remove
:
1739 prop_atoms
.net_wm_state_add
;
1740 else if (state
== prop_atoms
.net_wm_state_fullscreen
)
1741 action
= self
->fullscreen
?
1742 prop_atoms
.net_wm_state_remove
:
1743 prop_atoms
.net_wm_state_add
;
1744 else if (state
== prop_atoms
.net_wm_state_above
)
1745 action
= self
->above
? prop_atoms
.net_wm_state_remove
:
1746 prop_atoms
.net_wm_state_add
;
1747 else if (state
== prop_atoms
.net_wm_state_below
)
1748 action
= self
->below
? prop_atoms
.net_wm_state_remove
:
1749 prop_atoms
.net_wm_state_add
;
1752 if (action
== prop_atoms
.net_wm_state_add
) {
1753 if (state
== prop_atoms
.net_wm_state_modal
) {
1754 /* XXX raise here or something? */
1756 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
1758 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
1760 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
1762 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
1763 self
->skip_taskbar
= TRUE
;
1764 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
1765 self
->skip_pager
= TRUE
;
1766 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
1768 } else if (state
== prop_atoms
.net_wm_state_above
) {
1770 } else if (state
== prop_atoms
.net_wm_state_below
) {
1774 } else { /* action == prop_atoms.net_wm_state_remove */
1775 if (state
== prop_atoms
.net_wm_state_modal
) {
1776 self
->modal
= FALSE
;
1777 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
1779 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
1781 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
1783 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
1784 self
->skip_taskbar
= FALSE
;
1785 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
1786 self
->skip_pager
= FALSE
;
1787 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
1789 } else if (state
== prop_atoms
.net_wm_state_above
) {
1790 self
->above
= FALSE
;
1791 } else if (state
== prop_atoms
.net_wm_state_below
) {
1792 self
->below
= FALSE
;
1796 if (max_horz
!= self
->max_horz
|| max_vert
!= self
->max_vert
) {
1797 if (max_horz
!= self
->max_horz
&& max_vert
!= self
->max_vert
) {
1799 if (max_horz
== max_vert
) { /* both going the same way */
1800 client_maximize(self
, max_horz
, 0, TRUE
);
1802 client_maximize(self
, max_horz
, 1, TRUE
);
1803 client_maximize(self
, max_vert
, 2, TRUE
);
1807 if (max_horz
!= self
->max_horz
)
1808 client_maximize(self
, max_horz
, 1, TRUE
);
1810 client_maximize(self
, max_vert
, 2, TRUE
);
1813 /* change fullscreen state before shading, as it will affect if the window
1815 if (fullscreen
!= self
->fullscreen
)
1816 client_fullscreen(self
, fullscreen
, TRUE
);
1817 if (shaded
!= self
->shaded
)
1818 client_shade(self
, shaded
);
1819 client_calc_layer(self
);
1820 client_change_state(self
); /* change the hint to relect these changes */
1823 gboolean
client_focus(Client
*self
)
1828 /* if we have a modal child, then focus it, not us */
1829 child
= client_find_modal_child(self
);
1831 return client_focus(child
);
1833 /* won't try focus if the client doesn't want it, or if the window isn't
1834 visible on the screen */
1835 if (!(self
->frame
->visible
&&
1836 (self
->can_focus
|| self
->focus_notify
)))
1839 /* do a check to see if the window has already been unmapped or destroyed
1840 do this intelligently while watching out for unmaps we've generated
1841 (ignore_unmaps > 0) */
1842 if (XCheckTypedWindowEvent(ob_display
, self
->window
,
1843 DestroyNotify
, &ev
)) {
1844 XPutBackEvent(ob_display
, &ev
);
1847 while (XCheckTypedWindowEvent(ob_display
, self
->window
,
1848 UnmapNotify
, &ev
)) {
1849 if (self
->ignore_unmaps
) {
1850 self
->ignore_unmaps
--;
1852 XPutBackEvent(ob_display
, &ev
);
1857 if (self
->can_focus
)
1858 XSetInputFocus(ob_display
, self
->window
, RevertToNone
, CurrentTime
);
1860 if (self
->focus_notify
) {
1862 ce
.xclient
.type
= ClientMessage
;
1863 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
1864 ce
.xclient
.display
= ob_display
;
1865 ce
.xclient
.window
= self
->window
;
1866 ce
.xclient
.format
= 32;
1867 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_take_focus
;
1868 ce
.xclient
.data
.l
[1] = event_lasttime
;
1869 ce
.xclient
.data
.l
[2] = 0l;
1870 ce
.xclient
.data
.l
[3] = 0l;
1871 ce
.xclient
.data
.l
[4] = 0l;
1872 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
1875 /*XSync(ob_display, FALSE); XXX Why sync? */
1879 void client_unfocus(Client
*self
)
1881 g_assert(focus_client
== self
);
1882 focus_set_client(NULL
);