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 Window
*client_startup_stack_order
= NULL
;
27 static gulong client_startup_stack_size
= 0;
29 static void client_get_all(Client
*self
);
30 static void client_toggle_border(Client
*self
, gboolean show
);
31 static void client_get_area(Client
*self
);
32 static void client_get_desktop(Client
*self
);
33 static void client_get_state(Client
*self
);
34 static void client_get_shaped(Client
*self
);
35 static void client_get_mwm_hints(Client
*self
);
36 static void client_get_gravity(Client
*self
);
37 static void client_showhide(Client
*self
);
38 static void client_change_allowed_actions(Client
*self
);
39 static void client_change_state(Client
*self
);
40 static Client
*search_focus_tree(Client
*node
, Client
*skip
);
41 static void client_apply_startup_state(Client
*self
);
42 static Client
*search_modal_tree(Client
*node
, Client
*skip
);
44 static guint
map_hash(Window
*w
) { return *w
; }
45 static gboolean
map_key_comp(Window
*w1
, Window
*w2
) { return *w1
== *w2
; }
49 client_map
= g_hash_table_new((GHashFunc
)map_hash
,
50 (GEqualFunc
)map_key_comp
);
52 /* save the stacking order on startup! */
53 if (!PROP_GET32U(ob_root
, net_client_list_stacking
, window
,
54 client_startup_stack_order
, client_startup_stack_size
))
56 g_message("%ld", client_startup_stack_size
);
61 void client_shutdown()
63 g_hash_table_destroy(client_map
);
66 void client_set_list()
68 Window
*windows
, *win_it
;
70 guint size
= g_slist_length(client_list
);
72 /* create an array of the window ids */
74 windows
= g_new(Window
, size
);
76 for (it
= client_list
; it
!= NULL
; it
= it
->next
, ++win_it
)
77 *win_it
= ((Client
*)it
->data
)->window
;
81 PROP_SET32A(ob_root
, net_client_list
, window
, windows
, size
);
89 void client_manage_all()
91 unsigned int i
, j
, nchild
;
94 XWindowAttributes attrib
;
96 XQueryTree(ob_display
, ob_root
, &w
, &w
, &children
, &nchild
);
98 /* remove all icon windows from the list */
99 for (i
= 0; i
< nchild
; i
++) {
100 if (children
[i
] == None
) continue;
101 wmhints
= XGetWMHints(ob_display
, children
[i
]);
103 if ((wmhints
->flags
& IconWindowHint
) &&
104 (wmhints
->icon_window
!= children
[i
]))
105 for (j
= 0; j
< nchild
; j
++)
106 if (children
[j
] == wmhints
->icon_window
) {
114 for (i
= 0; i
< nchild
; ++i
) {
115 if (children
[i
] == None
)
117 if (XGetWindowAttributes(ob_display
, children
[i
], &attrib
)) {
118 if (attrib
.override_redirect
) continue;
120 if (attrib
.map_state
!= IsUnmapped
)
121 client_manage(children
[i
]);
126 /* stack them as they were on startup!
127 why with stacking_lower? Why, because then windows who aren't in the
128 stacking list are on the top where you can see them instead of buried
130 for (i
= client_startup_stack_size
; i
> 0; --i
) {
133 w
= client_startup_stack_order
[i
-1];
134 c
= g_hash_table_lookup(client_map
, &w
);
135 if (c
) stacking_lower(c
);
137 g_free(client_startup_stack_order
);
138 client_startup_stack_order
= NULL
;
139 client_startup_stack_size
= 0;
142 void client_manage(Window window
)
146 XWindowAttributes attrib
;
147 XSetWindowAttributes attrib_set
;
148 /* XWMHints *wmhint; */
153 /* check if it has already been unmapped by the time we started mapping
154 the grab does a sync so we don't have to here */
155 if (XCheckTypedWindowEvent(ob_display
, window
, DestroyNotify
, &e
) ||
156 XCheckTypedWindowEvent(ob_display
, window
, UnmapNotify
, &e
)) {
157 XPutBackEvent(ob_display
, &e
);
160 return; /* don't manage it */
163 /* make sure it isn't an override-redirect window */
164 if (!XGetWindowAttributes(ob_display
, window
, &attrib
) ||
165 attrib
.override_redirect
) {
167 return; /* don't manage it */
170 /* /\* is the window a docking app *\/
171 if ((wmhint = XGetWMHints(ob_display, window))) {
172 if ((wmhint->flags & StateHint) &&
173 wmhint->initial_state == WithdrawnState) {
174 /\* XXX: make dock apps work! *\/
183 /* choose the events we want to receive on the CLIENT window */
184 attrib_set
.event_mask
= CLIENT_EVENTMASK
;
185 attrib_set
.do_not_propagate_mask
= CLIENT_NOPROPAGATEMASK
;
186 XChangeWindowAttributes(ob_display
, window
,
187 CWEventMask
|CWDontPropagate
, &attrib_set
);
190 /* create the Client struct, and populate it from the hints on the
192 client
= g_new(Client
, 1);
193 client
->window
= window
;
194 client_get_all(client
);
196 /* remove the client's border (and adjust re gravity) */
197 client_toggle_border(client
, FALSE
);
199 /* specify that if we exit, the window should not be destroyed and should
200 be reparented back to root automatically */
201 XChangeSaveSet(ob_display
, window
, SetModeInsert
);
203 /* create the decoration frame for the client window */
204 client
->frame
= engine_frame_new();
206 engine_frame_grab_client(client
->frame
, client
);
208 client_apply_startup_state(client
);
212 client_list
= g_slist_append(client_list
, client
);
213 stacking_list
= g_list_append(stacking_list
, client
);
214 g_assert(!g_hash_table_lookup(client_map
, &client
->window
));
215 g_hash_table_insert(client_map
, &client
->window
, client
);
217 /* update the focus lists */
218 if (client
->desktop
== DESKTOP_ALL
) {
219 for (i
= 0; i
< screen_num_desktops
; ++i
)
220 focus_order
[i
] = g_list_append(focus_order
[i
], client
);
223 focus_order
[i
] = g_list_append(focus_order
[i
], client
);
226 stacking_raise(client
);
228 screen_update_struts();
230 dispatch_client(Event_Client_New
, client
, 0, 0);
232 client_showhide(client
);
234 dispatch_client(Event_Client_Mapped
, client
, 0, 0);
236 /* update the list hints */
239 g_message("Managed window 0x%lx", window
);
242 void client_unmanage_all()
244 while (client_list
!= NULL
)
245 client_unmanage(client_list
->data
);
248 void client_unmanage(Client
*client
)
254 g_message("Unmanaging window: %lx", client
->window
);
256 dispatch_client(Event_Client_Destroy
, client
, 0, 0);
257 g_assert(client
!= NULL
);
259 /* remove the window from our save set */
260 XChangeSaveSet(ob_display
, client
->window
, SetModeDelete
);
262 /* we dont want events no more */
263 XSelectInput(ob_display
, client
->window
, NoEventMask
);
265 engine_frame_hide(client
->frame
);
267 client_list
= g_slist_remove(client_list
, client
);
268 stacking_list
= g_list_remove(stacking_list
, client
);
269 g_hash_table_remove(client_map
, &client
->window
);
271 /* update the focus lists */
272 if (client
->desktop
== DESKTOP_ALL
) {
273 for (i
= 0; i
< screen_num_desktops
; ++i
)
274 focus_order
[i
] = g_list_remove(focus_order
[i
], client
);
277 focus_order
[i
] = g_list_remove(focus_order
[i
], client
);
280 /* once the client is out of the list, update the struts to remove it's
282 screen_update_struts();
284 /* tell our parent that we're gone */
285 if (client
->transient_for
!= NULL
)
286 client
->transient_for
->transients
=
287 g_slist_remove(client
->transient_for
->transients
, client
);
289 /* tell our transients that we're gone */
290 for (it
= client
->transients
; it
!= NULL
; it
= it
->next
) {
291 ((Client
*)it
->data
)->transient_for
= NULL
;
292 client_calc_layer(it
->data
);
295 /* dispatch the unmapped event */
296 dispatch_client(Event_Client_Unmapped
, client
, 0, 0);
297 g_assert(client
!= NULL
);
299 /* unfocus the client (dispatchs the focus event) (we're out of the
300 transient lists already, so being modal doesn't matter) */
301 if (client_focused(client
))
302 client_unfocus(client
);
304 /* give the client its border back */
305 client_toggle_border(client
, TRUE
);
307 /* reparent the window out of the frame, and free the frame */
308 engine_frame_release_client(client
->frame
, client
);
309 client
->frame
= NULL
;
311 if (ob_state
!= State_Exiting
) {
312 /* these values should not be persisted across a window
314 prop_erase(client
->window
, prop_atoms
.net_wm_desktop
);
315 prop_erase(client
->window
, prop_atoms
.net_wm_state
);
317 /* if we're left in an iconic state, the client wont be mapped. this is
318 bad, since we will no longer be managing the window on restart */
320 XMapWindow(ob_display
, client
->window
);
323 /* free all data allocated in the client struct */
324 g_slist_free(client
->transients
);
325 for (j
= 0; j
< client
->nicons
; ++j
)
326 g_free(client
->icons
[j
].data
);
327 if (client
->nicons
> 0)
328 g_free(client
->icons
);
329 g_free(client
->title
);
330 g_free(client
->icon_title
);
331 g_free(client
->name
);
332 g_free(client
->class);
333 g_free(client
->role
);
336 /* update the list hints */
340 static void client_toggle_border(Client
*self
, gboolean show
)
342 /* adjust our idea of where the client is, based on its border. When the
343 border is removed, the client should now be considered to be in a
345 when re-adding the border to the client, the same operation needs to be
347 int oldx
= self
->area
.x
, oldy
= self
->area
.y
;
348 int x
= oldx
, y
= oldy
;
349 switch(self
->gravity
) {
351 case NorthWestGravity
:
353 case SouthWestGravity
:
355 case NorthEastGravity
:
357 case SouthEastGravity
:
358 if (show
) x
-= self
->border_width
* 2;
359 else x
+= self
->border_width
* 2;
366 if (show
) x
-= self
->border_width
;
367 else x
+= self
->border_width
;
370 switch(self
->gravity
) {
372 case NorthWestGravity
:
374 case NorthEastGravity
:
376 case SouthWestGravity
:
378 case SouthEastGravity
:
379 if (show
) y
-= self
->border_width
* 2;
380 else y
+= self
->border_width
* 2;
387 if (show
) y
-= self
->border_width
;
388 else y
+= self
->border_width
;
395 XSetWindowBorderWidth(ob_display
, self
->window
, self
->border_width
);
397 /* move the client so it is back it the right spot _with_ its
399 if (x
!= oldx
|| y
!= oldy
)
400 XMoveWindow(ob_display
, self
->window
, x
, y
);
402 XSetWindowBorderWidth(ob_display
, self
->window
, 0);
406 static void client_get_all(Client
*self
)
408 /* update EVERYTHING!! */
410 self
->ignore_unmaps
= 0;
414 self
->title
= self
->icon_title
= NULL
;
415 self
->name
= self
->class = self
->role
= NULL
;
416 self
->wmstate
= NormalState
;
417 self
->transient
= FALSE
;
418 self
->transients
= NULL
;
419 self
->transient_for
= NULL
;
421 self
->urgent
= FALSE
;
422 self
->positioned
= FALSE
;
423 self
->disabled_decorations
= 0;
427 client_get_area(self
);
428 client_get_desktop(self
);
429 client_get_state(self
);
430 client_get_shaped(self
);
432 client_update_transient_for(self
);
433 client_get_mwm_hints(self
);
434 client_get_type(self
);/* this can change the mwmhints for special cases */
436 client_update_protocols(self
);
438 client_get_gravity(self
); /* get the attribute gravity */
439 client_update_normal_hints(self
); /* this may override the attribute
442 /* got the type, the mwmhints, the protocols, and the normal hints
443 (min/max sizes), so we're ready to set up the decorations/functions */
444 client_setup_decor_and_functions(self
);
446 client_update_wmhints(self
);
447 client_update_title(self
);
448 client_update_icon_title(self
);
449 client_update_class(self
);
450 client_update_strut(self
);
451 client_update_icons(self
);
452 client_update_kwm_icon(self
);
454 /* this makes sure that these windows appear on all desktops */
455 if (self
->type
== Type_Desktop
)
456 self
->desktop
= DESKTOP_ALL
;
458 /* set the desktop hint, to make sure that it always exists, and to
459 reflect any changes we've made here */
460 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, self
->desktop
);
462 client_change_state(self
);
465 static void client_get_area(Client
*self
)
467 XWindowAttributes wattrib
;
470 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
471 g_assert(ret
!= BadWindow
);
473 RECT_SET(self
->area
, wattrib
.x
, wattrib
.y
, wattrib
.width
, wattrib
.height
);
474 self
->border_width
= wattrib
.border_width
;
477 static void client_get_desktop(Client
*self
)
481 if (PROP_GET32(self
->window
, net_wm_desktop
, cardinal
, d
)) {
482 if (d
>= screen_num_desktops
&& d
!= DESKTOP_ALL
)
483 d
= screen_num_desktops
- 1;
486 /* defaults to the current desktop */
487 self
->desktop
= screen_desktop
;
491 static void client_get_state(Client
*self
)
496 self
->modal
= self
->shaded
= self
->max_horz
= self
->max_vert
=
497 self
->fullscreen
= self
->above
= self
->below
= self
->iconic
=
498 self
->skip_taskbar
= self
->skip_pager
= FALSE
;
500 if (PROP_GET32U(self
->window
, net_wm_state
, atom
, state
, num
)) {
502 for (i
= 0; i
< num
; ++i
) {
503 if (state
[i
] == prop_atoms
.net_wm_state_modal
)
505 else if (state
[i
] == prop_atoms
.net_wm_state_shaded
)
507 else if (state
[i
] == prop_atoms
.net_wm_state_hidden
)
509 else if (state
[i
] == prop_atoms
.net_wm_state_skip_taskbar
)
510 self
->skip_taskbar
= TRUE
;
511 else if (state
[i
] == prop_atoms
.net_wm_state_skip_pager
)
512 self
->skip_pager
= TRUE
;
513 else if (state
[i
] == prop_atoms
.net_wm_state_fullscreen
)
514 self
->fullscreen
= TRUE
;
515 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_vert
)
516 self
->max_vert
= TRUE
;
517 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_horz
)
518 self
->max_horz
= TRUE
;
519 else if (state
[i
] == prop_atoms
.net_wm_state_above
)
521 else if (state
[i
] == prop_atoms
.net_wm_state_below
)
529 static void client_get_shaped(Client
*self
)
531 self
->shaped
= FALSE
;
533 if (extensions_shape
) {
538 XShapeSelectInput(ob_display
, self
->window
, ShapeNotifyMask
);
540 XShapeQueryExtents(ob_display
, self
->window
, &s
, &foo
,
541 &foo
, &ufoo
, &ufoo
, &foo
, &foo
, &foo
, &ufoo
,
543 self
->shaped
= (s
!= 0);
548 void client_update_transient_for(Client
*self
)
553 if (XGetTransientForHint(ob_display
, self
->window
, &t
) &&
554 t
!= self
->window
) { /* cant be transient to itself! */
555 self
->transient
= TRUE
;
556 c
= g_hash_table_lookup(client_map
, &t
);
557 g_assert(c
!= self
);/* if this happens then we need to check for it*/
559 if (!c
/*XXX: && _group*/) {
560 /* not transient to a client, see if it is transient for a
562 if (/*t == _group->leader() || */
565 /* window is a transient for its group! */
566 /* XXX: for now this is treated as non-transient.
567 this needs to be fixed! */
571 self
->transient
= FALSE
;
573 /* if anything has changed... */
574 if (c
!= self
->transient_for
) {
575 if (self
->transient_for
)
576 /* remove from old parent */
577 self
->transient_for
->transients
=
578 g_slist_remove(self
->transient_for
->transients
, self
);
579 self
->transient_for
= c
;
580 if (self
->transient_for
)
581 /* add to new parent */
582 self
->transient_for
->transients
=
583 g_slist_append(self
->transient_for
->transients
, self
);
587 static void client_get_mwm_hints(Client
*self
)
590 unsigned long *hints
;
592 self
->mwmhints
.flags
= 0; /* default to none */
594 if (PROP_GET32U(self
->window
, motif_wm_hints
, motif_wm_hints
, hints
, num
)) {
595 if (num
>= MWM_ELEMENTS
) {
596 self
->mwmhints
.flags
= hints
[0];
597 self
->mwmhints
.functions
= hints
[1];
598 self
->mwmhints
.decorations
= hints
[2];
604 void client_get_type(Client
*self
)
610 if (PROP_GET32U(self
->window
, net_wm_window_type
, atom
, val
, num
)) {
611 /* use the first value that we know about in the array */
612 for (i
= 0; i
< num
; ++i
) {
613 if (val
[i
] == prop_atoms
.net_wm_window_type_desktop
)
614 self
->type
= Type_Desktop
;
615 else if (val
[i
] == prop_atoms
.net_wm_window_type_dock
)
616 self
->type
= Type_Dock
;
617 else if (val
[i
] == prop_atoms
.net_wm_window_type_toolbar
)
618 self
->type
= Type_Toolbar
;
619 else if (val
[i
] == prop_atoms
.net_wm_window_type_menu
)
620 self
->type
= Type_Menu
;
621 else if (val
[i
] == prop_atoms
.net_wm_window_type_utility
)
622 self
->type
= Type_Utility
;
623 else if (val
[i
] == prop_atoms
.net_wm_window_type_splash
)
624 self
->type
= Type_Splash
;
625 else if (val
[i
] == prop_atoms
.net_wm_window_type_dialog
)
626 self
->type
= Type_Dialog
;
627 else if (val
[i
] == prop_atoms
.net_wm_window_type_normal
)
628 self
->type
= Type_Normal
;
629 else if (val
[i
] == prop_atoms
.kde_net_wm_window_type_override
) {
630 /* prevent this window from getting any decor or
632 self
->mwmhints
.flags
&= (MwmFlag_Functions
|
633 MwmFlag_Decorations
);
634 self
->mwmhints
.decorations
= 0;
635 self
->mwmhints
.functions
= 0;
637 if (self
->type
!= (WindowType
) -1)
638 break; /* grab the first legit type */
643 if (self
->type
== (WindowType
) -1) {
644 /*the window type hint was not set, which means we either classify
645 ourself as a normal window or a dialog, depending on if we are a
648 self
->type
= Type_Dialog
;
650 self
->type
= Type_Normal
;
654 void client_update_protocols(Client
*self
)
657 gulong num_return
, i
;
659 self
->focus_notify
= FALSE
;
660 self
->delete_window
= FALSE
;
662 if (PROP_GET32U(self
->window
, wm_protocols
, atom
, proto
, num_return
)) {
663 for (i
= 0; i
< num_return
; ++i
) {
664 if (proto
[i
] == prop_atoms
.wm_delete_window
) {
665 /* this means we can request the window to close */
666 self
->delete_window
= TRUE
;
667 } else if (proto
[i
] == prop_atoms
.wm_take_focus
)
668 /* if this protocol is requested, then the window will be
669 notified whenever we want it to receive focus */
670 self
->focus_notify
= TRUE
;
676 static void client_get_gravity(Client
*self
)
678 XWindowAttributes wattrib
;
681 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
682 g_assert(ret
!= BadWindow
);
683 self
->gravity
= wattrib
.win_gravity
;
686 void client_update_normal_hints(Client
*self
)
690 int oldgravity
= self
->gravity
;
693 self
->min_ratio
= 0.0f
;
694 self
->max_ratio
= 0.0f
;
695 SIZE_SET(self
->size_inc
, 1, 1);
696 SIZE_SET(self
->base_size
, 0, 0);
697 SIZE_SET(self
->min_size
, 0, 0);
698 SIZE_SET(self
->max_size
, G_MAXINT
, G_MAXINT
);
700 /* get the hints from the window */
701 if (XGetWMNormalHints(ob_display
, self
->window
, &size
, &ret
)) {
702 self
->positioned
= (size
.flags
& (PPosition
|USPosition
));
704 if (size
.flags
& PWinGravity
) {
705 self
->gravity
= size
.win_gravity
;
707 /* if the client has a frame, i.e. has already been mapped and
708 is changing its gravity */
709 if (self
->frame
&& self
->gravity
!= oldgravity
) {
710 /* move our idea of the client's position based on its new
712 self
->area
.x
= self
->frame
->area
.x
;
713 self
->area
.y
= self
->frame
->area
.y
;
714 frame_frame_gravity(self
->frame
, &self
->area
.x
, &self
->area
.y
);
718 if (size
.flags
& PAspect
) {
719 if (size
.min_aspect
.y
)
720 self
->min_ratio
= (float)size
.min_aspect
.x
/ size
.min_aspect
.y
;
721 if (size
.max_aspect
.y
)
722 self
->max_ratio
= (float)size
.max_aspect
.x
/ size
.max_aspect
.y
;
725 if (size
.flags
& PMinSize
)
726 SIZE_SET(self
->min_size
, size
.min_width
, size
.min_height
);
728 if (size
.flags
& PMaxSize
)
729 SIZE_SET(self
->max_size
, size
.max_width
, size
.max_height
);
731 if (size
.flags
& PBaseSize
)
732 SIZE_SET(self
->base_size
, size
.base_width
, size
.base_height
);
734 if (size
.flags
& PResizeInc
)
735 SIZE_SET(self
->size_inc
, size
.width_inc
, size
.height_inc
);
739 void client_setup_decor_and_functions(Client
*self
)
741 /* start with everything (cept fullscreen) */
742 self
->decorations
= Decor_Titlebar
| Decor_Handle
| Decor_Border
|
743 Decor_Icon
| Decor_AllDesktops
| Decor_Iconify
| Decor_Maximize
;
744 self
->functions
= Func_Resize
| Func_Move
| Func_Iconify
| Func_Maximize
|
746 if (self
->delete_window
) {
747 self
->decorations
|= Decor_Close
;
748 self
->functions
|= Func_Close
;
751 if (!(self
->min_size
.width
< self
->max_size
.width
||
752 self
->min_size
.height
< self
->max_size
.height
)) {
753 self
->decorations
&= ~(Decor_Maximize
| Decor_Handle
);
754 self
->functions
&= ~(Func_Resize
| Func_Maximize
);
757 switch (self
->type
) {
759 /* normal windows retain all of the possible decorations and
760 functionality, and are the only windows that you can fullscreen */
761 self
->functions
|= Func_Fullscreen
;
765 /* dialogs cannot be maximized */
766 self
->decorations
&= ~Decor_Maximize
;
767 self
->functions
&= ~Func_Maximize
;
773 /* these windows get less functionality */
774 self
->decorations
&= ~(Decor_Iconify
| Decor_Handle
);
775 self
->functions
&= ~(Func_Iconify
| Func_Resize
);
781 /* none of these windows are manipulated by the window manager */
782 self
->decorations
= 0;
787 /* Mwm Hints are applied subtractively to what has already been chosen for
788 decor and functionality */
789 if (self
->mwmhints
.flags
& MwmFlag_Decorations
) {
790 if (! (self
->mwmhints
.decorations
& MwmDecor_All
)) {
791 if (! (self
->mwmhints
.decorations
& MwmDecor_Border
))
792 self
->decorations
&= ~Decor_Border
;
793 if (! (self
->mwmhints
.decorations
& MwmDecor_Handle
))
794 self
->decorations
&= ~Decor_Handle
;
795 if (! (self
->mwmhints
.decorations
& MwmDecor_Title
))
796 self
->decorations
&= ~Decor_Titlebar
;
797 if (! (self
->mwmhints
.decorations
& MwmDecor_Iconify
))
798 self
->decorations
&= ~Decor_Iconify
;
799 if (! (self
->mwmhints
.decorations
& MwmDecor_Maximize
))
800 self
->decorations
&= ~Decor_Maximize
;
804 if (self
->mwmhints
.flags
& MwmFlag_Functions
) {
805 if (! (self
->mwmhints
.functions
& MwmFunc_All
)) {
806 if (! (self
->mwmhints
.functions
& MwmFunc_Resize
))
807 self
->functions
&= ~Func_Resize
;
808 if (! (self
->mwmhints
.functions
& MwmFunc_Move
))
809 self
->functions
&= ~Func_Move
;
810 if (! (self
->mwmhints
.functions
& MwmFunc_Iconify
))
811 self
->functions
&= ~Func_Iconify
;
812 if (! (self
->mwmhints
.functions
& MwmFunc_Maximize
))
813 self
->functions
&= ~Func_Maximize
;
814 /* dont let mwm hints kill the close button
815 if (! (self->mwmhints.functions & MwmFunc_Close))
816 self->functions &= ~Func_Close; */
820 /* can't maximize without moving/resizing */
821 if (!((self
->functions
& Func_Move
) && (self
->functions
& Func_Resize
)))
822 self
->functions
&= ~(Func_Maximize
| Func_Fullscreen
);
824 /* finally, user specified disabled decorations are applied to subtract
826 if (self
->disabled_decorations
& Decor_Titlebar
)
827 self
->decorations
&= ~Decor_Titlebar
;
828 if (self
->disabled_decorations
& Decor_Handle
)
829 self
->decorations
&= ~Decor_Handle
;
830 if (self
->disabled_decorations
& Decor_Border
)
831 self
->decorations
&= ~Decor_Border
;
832 if (self
->disabled_decorations
& Decor_Iconify
)
833 self
->decorations
&= ~Decor_Iconify
;
834 if (self
->disabled_decorations
& Decor_Maximize
)
835 self
->decorations
&= ~Decor_Maximize
;
836 if (self
->disabled_decorations
& Decor_AllDesktops
)
837 self
->decorations
&= ~Decor_AllDesktops
;
838 if (self
->disabled_decorations
& Decor_Close
)
839 self
->decorations
&= ~Decor_Close
;
841 /* if we don't have a titlebar, then we cannot shade! */
842 if (!(self
->decorations
& Decor_Titlebar
))
843 self
->functions
&= ~Func_Shade
;
845 client_change_allowed_actions(self
);
848 /* change the decors on the frame, and with more/less decorations,
849 we may also need to be repositioned */
850 engine_frame_adjust_area(self
->frame
, TRUE
, TRUE
);
851 /* with new decor, the window's maximized size may change */
852 client_remaximize(self
);
856 static void client_change_allowed_actions(Client
*self
)
861 actions
[num
++] = prop_atoms
.net_wm_action_change_desktop
;
863 if (self
->functions
& Func_Shade
)
864 actions
[num
++] = prop_atoms
.net_wm_action_shade
;
865 if (self
->functions
& Func_Close
)
866 actions
[num
++] = prop_atoms
.net_wm_action_close
;
867 if (self
->functions
& Func_Move
)
868 actions
[num
++] = prop_atoms
.net_wm_action_move
;
869 if (self
->functions
& Func_Iconify
)
870 actions
[num
++] = prop_atoms
.net_wm_action_minimize
;
871 if (self
->functions
& Func_Resize
)
872 actions
[num
++] = prop_atoms
.net_wm_action_resize
;
873 if (self
->functions
& Func_Fullscreen
)
874 actions
[num
++] = prop_atoms
.net_wm_action_fullscreen
;
875 if (self
->functions
& Func_Maximize
) {
876 actions
[num
++] = prop_atoms
.net_wm_action_maximize_horz
;
877 actions
[num
++] = prop_atoms
.net_wm_action_maximize_vert
;
880 PROP_SET32A(self
->window
, net_wm_allowed_actions
, atom
, actions
, num
);
882 /* make sure the window isn't breaking any rules now */
884 if (!(self
->functions
& Func_Shade
) && self
->shaded
) {
885 if (self
->frame
) client_shade(self
, FALSE
);
886 else self
->shaded
= FALSE
;
888 if (!(self
->functions
& Func_Iconify
) && self
->iconic
) {
889 if (self
->frame
) client_iconify(self
, FALSE
, TRUE
);
890 else self
->iconic
= FALSE
;
892 if (!(self
->functions
& Func_Fullscreen
) && self
->fullscreen
) {
893 if (self
->frame
) client_fullscreen(self
, FALSE
, TRUE
);
894 else self
->fullscreen
= FALSE
;
896 if (!(self
->functions
& Func_Maximize
) && (self
->max_horz
||
898 if (self
->frame
) client_maximize(self
, FALSE
, 0, TRUE
);
899 else self
->max_vert
= self
->max_horz
= FALSE
;
903 void client_remaximize(Client
*self
)
906 if (self
->max_horz
&& self
->max_vert
)
908 else if (self
->max_horz
)
910 else if (self
->max_vert
)
913 return; /* not maximized */
914 self
->max_horz
= self
->max_vert
= FALSE
;
915 client_maximize(self
, TRUE
, dir
, FALSE
);
918 void client_update_wmhints(Client
*self
)
923 /* assume a window takes input if it doesnt specify */
924 self
->can_focus
= TRUE
;
926 if ((hints
= XGetWMHints(ob_display
, self
->window
)) != NULL
) {
927 if (hints
->flags
& InputHint
)
928 self
->can_focus
= hints
->input
;
930 /* only do this when starting! */
931 if (ob_state
== State_Starting
&& (hints
->flags
& StateHint
))
932 self
->iconic
= hints
->initial_state
== IconicState
;
934 if (hints
->flags
& XUrgencyHint
)
937 if (hints
->flags
& WindowGroupHint
) {
938 if (hints
->window_group
!= self
->group
) {
939 /* XXX: remove from the old group if there was one */
940 self
->group
= hints
->window_group
;
941 /* XXX: do stuff with the group */
943 } else /* no group! */
946 if (hints
->flags
& IconPixmapHint
) {
947 client_update_kwm_icon(self
);
948 /* try get the kwm icon first, this is a fallback only */
949 if (self
->pixmap_icon
== None
) {
950 self
->pixmap_icon
= hints
->icon_pixmap
;
951 if (hints
->flags
& IconMaskHint
)
952 self
->pixmap_icon_mask
= hints
->icon_mask
;
954 self
->pixmap_icon_mask
= None
;
957 engine_frame_adjust_icon(self
->frame
);
964 if (ur
!= self
->urgent
) {
966 g_message("Urgent Hint for 0x%lx: %s", self
->window
,
968 /* fire the urgent callback if we're mapped, otherwise, wait until
969 after we're mapped */
971 dispatch_client(Event_Client_Urgent
, self
, self
->urgent
, 0);
975 void client_update_title(Client
*self
)
982 if (!PROP_GETS(self
->window
, net_wm_name
, utf8
, data
)) {
983 /* try old x stuff */
984 if (PROP_GETS(self
->window
, wm_name
, string
, data
)) {
985 /* convert it to UTF-8 */
989 u
= g_locale_to_utf8(data
, -1, &r
, &w
, NULL
);
991 g_warning("Unable to convert string to UTF-8");
998 data
= g_strdup("Unnamed Window");
1000 PROP_SETS(self
->window
, net_wm_visible_name
, utf8
, data
);
1006 engine_frame_adjust_title(self
->frame
);
1009 void client_update_icon_title(Client
*self
)
1013 g_free(self
->icon_title
);
1016 if (!PROP_GETS(self
->window
, net_wm_icon_name
, utf8
, data
)) {
1017 /* try old x stuff */
1018 if (PROP_GETS(self
->window
, wm_icon_name
, string
, data
)) {
1019 /* convert it to UTF-8 */
1023 u
= g_locale_to_utf8(data
, -1, &r
, &w
, NULL
);
1025 g_warning("Unable to convert string to UTF-8");
1032 data
= g_strdup("Unnamed Window");
1034 PROP_SETS(self
->window
, net_wm_visible_icon_name
, utf8
, data
);
1037 self
->icon_title
= data
;
1040 void client_update_class(Client
*self
)
1046 if (self
->name
) g_free(self
->name
);
1047 if (self
->class) g_free(self
->class);
1048 if (self
->role
) g_free(self
->role
);
1050 self
->name
= self
->class = self
->role
= NULL
;
1052 data
= g_ptr_array_new();
1054 if (PROP_GETSA(self
->window
, wm_class
, string
, data
)) {
1056 self
->name
= g_strdup(g_ptr_array_index(data
, 0));
1058 self
->class = g_strdup(g_ptr_array_index(data
, 1));
1061 for (i
= 0; i
< data
->len
; ++i
)
1062 g_free(g_ptr_array_index(data
, i
));
1063 g_ptr_array_free(data
, TRUE
);
1065 if (PROP_GETS(self
->window
, wm_window_role
, string
, s
))
1066 self
->role
= g_strdup(s
);
1068 if (self
->name
== NULL
) self
->name
= g_strdup("");
1069 if (self
->class == NULL
) self
->class = g_strdup("");
1070 if (self
->role
== NULL
) self
->role
= g_strdup("");
1073 void client_update_strut(Client
*self
)
1077 if (PROP_GET32A(self
->window
, net_wm_strut
, cardinal
, data
, 4)) {
1078 STRUT_SET(self
->strut
, data
[0], data
[1], data
[2], data
[3]);
1081 STRUT_SET(self
->strut
, 0, 0, 0, 0);
1083 /* updating here is pointless while we're being mapped cuz we're not in
1084 the client list yet */
1086 screen_update_struts();
1089 void client_update_icons(Client
*self
)
1092 unsigned long *data
;
1093 unsigned long w
, h
, i
;
1096 for (j
= 0; j
< self
->nicons
; ++j
)
1097 g_free(self
->icons
[j
].data
);
1098 if (self
->nicons
> 0)
1099 g_free(self
->icons
);
1102 if (PROP_GET32U(self
->window
, net_wm_icon
, cardinal
, data
, num
)) {
1103 /* figure out how many valid icons are in here */
1105 while (num
- i
> 2) {
1113 self
->icons
= g_new(Icon
, self
->nicons
);
1115 /* store the icons */
1117 for (j
= 0; j
< self
->nicons
; ++j
) {
1118 w
= self
->icons
[j
].w
= data
[i
++];
1119 h
= self
->icons
[j
].h
= data
[i
++];
1120 self
->icons
[j
].data
=
1121 g_memdup(&data
[i
], w
* h
* sizeof(gulong
));
1129 if (self
->nicons
<= 0) {
1131 self
->icons
= g_new0(Icon
, 1);
1135 engine_frame_adjust_icon(self
->frame
);
1138 void client_update_kwm_icon(Client
*self
)
1142 if (PROP_GET32A(self
->window
, kwm_win_icon
, kwm_win_icon
, data
, 2)) {
1143 self
->pixmap_icon
= data
[0];
1144 self
->pixmap_icon_mask
= data
[1];
1147 self
->pixmap_icon
= self
->pixmap_icon_mask
= None
;
1150 engine_frame_adjust_icon(self
->frame
);
1153 static void client_change_state(Client
*self
)
1155 unsigned long state
[2];
1159 state
[0] = self
->wmstate
;
1161 PROP_SET32A(self
->window
, wm_state
, wm_state
, state
, 2);
1165 netstate
[num
++] = prop_atoms
.net_wm_state_modal
;
1167 netstate
[num
++] = prop_atoms
.net_wm_state_shaded
;
1169 netstate
[num
++] = prop_atoms
.net_wm_state_hidden
;
1170 if (self
->skip_taskbar
)
1171 netstate
[num
++] = prop_atoms
.net_wm_state_skip_taskbar
;
1172 if (self
->skip_pager
)
1173 netstate
[num
++] = prop_atoms
.net_wm_state_skip_pager
;
1174 if (self
->fullscreen
)
1175 netstate
[num
++] = prop_atoms
.net_wm_state_fullscreen
;
1177 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_vert
;
1179 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_horz
;
1181 netstate
[num
++] = prop_atoms
.net_wm_state_above
;
1183 netstate
[num
++] = prop_atoms
.net_wm_state_below
;
1184 PROP_SET32A(self
->window
, net_wm_state
, atom
, netstate
, num
);
1186 client_calc_layer(self
);
1189 engine_frame_adjust_state(self
->frame
);
1192 static Client
*search_focus_tree(Client
*node
, Client
*skip
)
1197 for (it
= node
->transients
; it
!= NULL
; it
= it
->next
) {
1198 Client
*c
= it
->data
;
1199 if (c
== skip
) continue; /* circular? */
1200 if ((ret
= search_focus_tree(c
, skip
))) return ret
;
1201 if (client_focused(c
)) return c
;
1206 void client_calc_layer(Client
*self
)
1212 /* are we fullscreen, or do we have a fullscreen transient parent? */
1216 if (c
->fullscreen
) {
1220 c
= c
->transient_for
;
1222 if (!fs
&& self
->fullscreen
) {
1223 /* is one of our transients focused? */
1224 c
= search_focus_tree(self
, self
);
1225 if (c
!= NULL
) fs
= TRUE
;
1228 if (self
->iconic
) l
= Layer_Icon
;
1229 else if (fs
) l
= Layer_Fullscreen
;
1230 else if (self
->type
== Type_Desktop
) l
= Layer_Desktop
;
1231 else if (self
->type
== Type_Dock
) {
1232 if (!self
->below
) l
= Layer_Top
;
1233 else l
= Layer_Normal
;
1235 else if (self
->above
) l
= Layer_Above
;
1236 else if (self
->below
) l
= Layer_Below
;
1237 else l
= Layer_Normal
;
1239 if (l
!= self
->layer
) {
1242 stacking_raise(self
);
1246 gboolean
client_should_show(Client
*self
)
1248 if (self
->iconic
) return FALSE
;
1249 else if (!(self
->desktop
== screen_desktop
||
1250 self
->desktop
== DESKTOP_ALL
)) return FALSE
;
1251 else if (client_normal(self
) && screen_showing_desktop
) return FALSE
;
1256 static void client_showhide(Client
*self
)
1259 if (client_should_show(self
))
1260 engine_frame_show(self
->frame
);
1262 engine_frame_hide(self
->frame
);
1265 gboolean
client_normal(Client
*self
) {
1266 return ! (self
->type
== Type_Desktop
|| self
->type
== Type_Dock
||
1267 self
->type
== Type_Splash
);
1270 static void client_apply_startup_state(Client
*self
)
1272 /* these are in a carefully crafted order.. */
1275 self
->iconic
= FALSE
;
1276 client_iconify(self
, TRUE
, FALSE
);
1278 if (self
->fullscreen
) {
1279 self
->fullscreen
= FALSE
;
1280 client_fullscreen(self
, TRUE
, FALSE
);
1283 self
->shaded
= FALSE
;
1284 client_shade(self
, TRUE
);
1287 dispatch_client(Event_Client_Urgent
, self
, self
->urgent
, 0);
1289 if (self
->max_vert
&& self
->max_horz
) {
1290 self
->max_vert
= self
->max_horz
= FALSE
;
1291 client_maximize(self
, TRUE
, 0, FALSE
);
1292 } else if (self
->max_vert
) {
1293 self
->max_vert
= FALSE
;
1294 client_maximize(self
, TRUE
, 2, FALSE
);
1295 } else if (self
->max_horz
) {
1296 self
->max_horz
= FALSE
;
1297 client_maximize(self
, TRUE
, 1, FALSE
);
1300 /* nothing to do for the other states:
1309 void client_configure(Client
*self
, Corner anchor
, int x
, int y
, int w
, int h
,
1310 gboolean user
, gboolean final
)
1312 gboolean moved
= FALSE
, resized
= FALSE
;
1314 /* set the size and position if fullscreen */
1315 if (self
->fullscreen
) {
1318 w
= screen_physical_size
.width
;
1319 h
= screen_physical_size
.height
;
1321 /* set the size and position if maximized */
1322 if (self
->max_horz
) {
1323 x
= screen_area(self
->desktop
)->x
- self
->frame
->size
.left
;
1324 w
= screen_area(self
->desktop
)->x
+
1325 screen_area(self
->desktop
)->width
;
1327 if (self
->max_vert
) {
1328 y
= screen_area(self
->desktop
)->y
;
1329 h
= screen_area(self
->desktop
)->y
+
1330 screen_area(self
->desktop
)->height
-
1331 self
->frame
->size
.top
- self
->frame
->size
.bottom
;
1335 /* these override the above states! if you cant move you can't move! */
1337 if (!(self
->functions
& Func_Move
)) {
1341 if (!(self
->functions
& Func_Resize
)) {
1342 w
= self
->area
.width
;
1343 h
= self
->area
.height
;
1347 if (!(w
== self
->area
.width
&& h
== self
->area
.height
)) {
1348 w
-= self
->base_size
.width
;
1349 h
-= self
->base_size
.height
;
1352 /* for interactive resizing. have to move half an increment in each
1355 /* how far we are towards the next size inc */
1356 int mw
= w
% self
->size_inc
.width
;
1357 int mh
= h
% self
->size_inc
.height
;
1359 int aw
= self
->size_inc
.width
/ 2;
1360 int ah
= self
->size_inc
.height
/ 2;
1361 /* don't let us move into a new size increment */
1362 if (mw
+ aw
>= self
->size_inc
.width
)
1363 aw
= self
->size_inc
.width
- mw
- 1;
1364 if (mh
+ ah
>= self
->size_inc
.height
)
1365 ah
= self
->size_inc
.height
- mh
- 1;
1369 /* if this is a user-requested resize, then check against min/max
1370 sizes and aspect ratios */
1372 /* smaller than min size or bigger than max size? */
1373 if (w
> self
->max_size
.width
) w
= self
->max_size
.width
;
1374 if (w
< self
->min_size
.width
) w
= self
->min_size
.width
;
1375 if (h
> self
->max_size
.height
) h
= self
->max_size
.height
;
1376 if (h
< self
->min_size
.height
) h
= self
->min_size
.height
;
1378 /* adjust the height ot match the width for the aspect ratios */
1379 if (self
->min_ratio
)
1380 if (h
* self
->min_ratio
> w
) h
= (int)(w
/ self
->min_ratio
);
1381 if (self
->max_ratio
)
1382 if (h
* self
->max_ratio
< w
) h
= (int)(w
/ self
->max_ratio
);
1385 /* keep to the increments */
1386 w
/= self
->size_inc
.width
;
1387 h
/= self
->size_inc
.height
;
1389 /* you cannot resize to nothing */
1393 /* store the logical size */
1394 SIZE_SET(self
->logical_size
, w
, h
);
1396 w
*= self
->size_inc
.width
;
1397 h
*= self
->size_inc
.height
;
1399 w
+= self
->base_size
.width
;
1400 h
+= self
->base_size
.height
;
1404 case Corner_TopLeft
:
1406 case Corner_TopRight
:
1407 x
-= w
- self
->area
.width
;
1409 case Corner_BottomLeft
:
1410 y
-= h
- self
->area
.height
;
1412 case Corner_BottomRight
:
1413 x
-= w
- self
->area
.width
;
1414 y
-= h
- self
->area
.height
;
1418 moved
= x
!= self
->area
.x
|| y
!= self
->area
.y
;
1419 resized
= w
!= self
->area
.width
|| h
!= self
->area
.height
;
1421 RECT_SET(self
->area
, x
, y
, w
, h
);
1424 XResizeWindow(ob_display
, self
->window
, w
, h
);
1426 /* move/resize the frame to match the request */
1428 if (moved
|| resized
)
1429 engine_frame_adjust_area(self
->frame
, moved
, resized
);
1431 if (!user
|| final
) {
1433 event
.type
= ConfigureNotify
;
1434 event
.xconfigure
.display
= ob_display
;
1435 event
.xconfigure
.event
= self
->window
;
1436 event
.xconfigure
.window
= self
->window
;
1438 /* root window coords with border in mind */
1439 event
.xconfigure
.x
= x
- self
->border_width
+
1440 self
->frame
->size
.left
;
1441 event
.xconfigure
.y
= y
- self
->border_width
+
1442 self
->frame
->size
.top
;
1444 event
.xconfigure
.width
= self
->area
.width
;
1445 event
.xconfigure
.height
= self
->area
.height
;
1446 event
.xconfigure
.border_width
= self
->border_width
;
1447 event
.xconfigure
.above
= self
->frame
->plate
;
1448 event
.xconfigure
.override_redirect
= FALSE
;
1449 XSendEvent(event
.xconfigure
.display
, event
.xconfigure
.window
,
1450 FALSE
, StructureNotifyMask
, &event
);
1455 void client_fullscreen(Client
*self
, gboolean fs
, gboolean savearea
)
1459 if (!(self
->functions
& Func_Fullscreen
) || /* can't */
1460 self
->fullscreen
== fs
) return; /* already done */
1462 self
->fullscreen
= fs
;
1463 client_change_state(self
); /* change the state hints on the client */
1466 /* save the functions and remove them */
1467 self
->pre_fs_func
= self
->functions
;
1468 self
->functions
&= (Func_Close
| Func_Fullscreen
|
1470 /* save the decorations and remove them */
1471 self
->pre_fs_decor
= self
->decorations
;
1472 self
->decorations
= 0;
1475 dimensions
[0] = self
->area
.x
;
1476 dimensions
[1] = self
->area
.y
;
1477 dimensions
[2] = self
->area
.width
;
1478 dimensions
[3] = self
->area
.height
;
1480 PROP_SET32A(self
->window
, openbox_premax
, cardinal
,
1484 /* these are not actually used cuz client_configure will set them
1485 as appropriate when the window is fullscreened */
1490 self
->functions
= self
->pre_fs_func
;
1491 self
->decorations
= self
->pre_fs_decor
;
1493 if (PROP_GET32A(self
->window
, openbox_premax
, cardinal
,
1501 /* pick some fallbacks... */
1502 x
= screen_area(self
->desktop
)->x
+
1503 screen_area(self
->desktop
)->width
/ 4;
1504 y
= screen_area(self
->desktop
)->y
+
1505 screen_area(self
->desktop
)->height
/ 4;
1506 w
= screen_area(self
->desktop
)->width
/ 2;
1507 h
= screen_area(self
->desktop
)->height
/ 2;
1511 client_change_allowed_actions(self
); /* based on the new _functions */
1513 /* when fullscreening, don't obey things like increments, fill the
1515 client_configure(self
, Corner_TopLeft
, x
, y
, w
, h
, !fs
, TRUE
);
1517 /* raise (back) into our stacking layer */
1518 stacking_raise(self
);
1520 /* try focus us when we go into fullscreen mode */
1524 void client_iconify(Client
*self
, gboolean iconic
, gboolean curdesk
)
1526 if (self
->iconic
== iconic
) return; /* nothing to do */
1528 g_message("%sconifying window: 0x%lx", (iconic
? "I" : "Uni"),
1531 self
->iconic
= iconic
;
1534 self
->wmstate
= IconicState
;
1535 self
->ignore_unmaps
++;
1536 /* we unmap the client itself so that we can get MapRequest events,
1537 and because the ICCCM tells us to! */
1538 XUnmapWindow(ob_display
, self
->window
);
1541 client_set_desktop(self
, screen_desktop
);
1542 self
->wmstate
= self
->shaded
? IconicState
: NormalState
;
1543 XMapWindow(ob_display
, self
->window
);
1545 client_change_state(self
);
1546 client_showhide(self
);
1547 screen_update_struts();
1549 dispatch_client(iconic
? Event_Client_Unmapped
: Event_Client_Mapped
,
1553 void client_maximize(Client
*self
, gboolean max
, int dir
, gboolean savearea
)
1557 g_assert(dir
== 0 || dir
== 1 || dir
== 2);
1558 if (!(self
->functions
& Func_Maximize
)) return; /* can't */
1560 /* check if already done */
1562 if (dir
== 0 && self
->max_horz
&& self
->max_vert
) return;
1563 if (dir
== 1 && self
->max_horz
) return;
1564 if (dir
== 2 && self
->max_vert
) return;
1566 if (dir
== 0 && !self
->max_horz
&& !self
->max_vert
) return;
1567 if (dir
== 1 && !self
->max_horz
) return;
1568 if (dir
== 2 && !self
->max_vert
) return;
1571 /* work with the frame's coords */
1572 x
= self
->frame
->area
.x
;
1573 y
= self
->frame
->area
.y
;
1574 w
= self
->area
.width
;
1575 h
= self
->area
.height
;
1587 /* get the property off the window and use it for the dimensions
1588 we are already maxed on */
1589 if (PROP_GET32A(self
->window
, openbox_premax
, cardinal
,
1591 if (self
->max_horz
) {
1592 dimensions
[0] = readdim
[0];
1593 dimensions
[2] = readdim
[2];
1595 if (self
->max_vert
) {
1596 dimensions
[1] = readdim
[1];
1597 dimensions
[3] = readdim
[3];
1602 PROP_SET32A(self
->window
, openbox_premax
, cardinal
,
1606 /* pass the client's current position info. the client_configure
1607 will move/size stuff as appropriate for a maximized window */
1610 w
= self
->area
.width
;
1611 h
= self
->area
.height
;
1615 if (PROP_GET32A(self
->window
, openbox_premax
, cardinal
,
1617 if (dir
== 0 || dir
== 1) { /* horz */
1621 if (dir
== 0 || dir
== 2) { /* vert */
1627 /* pick some fallbacks... */
1628 if (dir
== 0 || dir
== 1) { /* horz */
1629 x
= screen_area(self
->desktop
)->x
+
1630 screen_area(self
->desktop
)->width
/ 4;
1631 w
= screen_area(self
->desktop
)->width
/ 2;
1633 if (dir
== 0 || dir
== 2) { /* vert */
1634 y
= screen_area(self
->desktop
)->y
+
1635 screen_area(self
->desktop
)->height
/ 4;
1636 h
= screen_area(self
->desktop
)->height
/ 2;
1641 if (dir
== 0 || dir
== 1) /* horz */
1642 self
->max_horz
= max
;
1643 if (dir
== 0 || dir
== 2) /* vert */
1644 self
->max_vert
= max
;
1646 if (!self
->max_horz
&& !self
->max_vert
)
1647 PROP_ERASE(self
->window
, openbox_premax
);
1649 client_change_state(self
); /* change the state hints on the client */
1651 /* figure out where the client should be going */
1652 frame_frame_gravity(self
->frame
, &x
, &y
);
1653 client_configure(self
, Corner_TopLeft
, x
, y
, w
, h
, TRUE
, TRUE
);
1656 void client_shade(Client
*self
, gboolean shade
)
1658 if (!(self
->functions
& Func_Shade
) || /* can't */
1659 self
->shaded
== shade
) return; /* already done */
1661 /* when we're iconic, don't change the wmstate */
1663 self
->wmstate
= shade
? IconicState
: NormalState
;
1664 self
->shaded
= shade
;
1665 client_change_state(self
);
1666 /* resize the frame to just the titlebar */
1667 engine_frame_adjust_area(self
->frame
, FALSE
, FALSE
);
1670 void client_close(Client
*self
)
1674 if (!(self
->functions
& Func_Close
)) return;
1677 XXX: itd be cool to do timeouts and shit here for killing the client's
1679 like... if the window is around after 5 seconds, then the close button
1680 turns a nice red, and if this function is called again, the client is
1684 ce
.xclient
.type
= ClientMessage
;
1685 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
1686 ce
.xclient
.display
= ob_display
;
1687 ce
.xclient
.window
= self
->window
;
1688 ce
.xclient
.format
= 32;
1689 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_delete_window
;
1690 ce
.xclient
.data
.l
[1] = event_lasttime
;
1691 ce
.xclient
.data
.l
[2] = 0l;
1692 ce
.xclient
.data
.l
[3] = 0l;
1693 ce
.xclient
.data
.l
[4] = 0l;
1694 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
1697 void client_kill(Client
*self
)
1699 XKillClient(ob_display
, self
->window
);
1702 void client_set_desktop(Client
*self
, guint target
)
1706 if (target
== self
->desktop
) return;
1708 g_message("Setting desktop %u\n", target
);
1710 g_assert(target
< screen_num_desktops
|| target
== DESKTOP_ALL
);
1712 old
= self
->desktop
;
1713 self
->desktop
= target
;
1714 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, target
);
1715 /* the frame can display the current desktop state */
1716 engine_frame_adjust_state(self
->frame
);
1717 /* 'move' the window to the new desktop */
1718 client_showhide(self
);
1719 screen_update_struts();
1721 /* update the focus lists */
1722 if (old
== DESKTOP_ALL
) {
1723 for (i
= 0; i
< screen_num_desktops
; ++i
)
1724 focus_order
[i
] = g_list_remove(focus_order
[i
], self
);
1725 focus_order
[target
] = g_list_prepend(focus_order
[target
], self
);
1727 focus_order
[old
] = g_list_remove(focus_order
[old
], self
);
1728 if (target
== DESKTOP_ALL
)
1729 for (i
= 0; i
< screen_num_desktops
; ++i
)
1730 focus_order
[i
] = g_list_prepend(focus_order
[i
], self
);
1733 dispatch_client(Event_Client_Desktop
, self
, target
, old
);
1736 static Client
*search_modal_tree(Client
*node
, Client
*skip
)
1741 for (it
= node
->transients
; it
!= NULL
; it
= it
->next
) {
1742 Client
*c
= it
->data
;
1743 if (c
== skip
) continue; /* circular? */
1744 if ((ret
= search_modal_tree(c
, skip
))) return ret
;
1745 if (c
->modal
) return c
;
1750 Client
*client_find_modal_child(Client
*self
)
1752 return search_modal_tree(self
, self
);
1755 gboolean
client_validate(Client
*self
)
1759 XSync(ob_display
, FALSE
); /* get all events on the server */
1761 if (XCheckTypedWindowEvent(ob_display
, self
->window
, DestroyNotify
, &e
) ||
1762 XCheckTypedWindowEvent(ob_display
, self
->window
, UnmapNotify
, &e
)) {
1763 XPutBackEvent(ob_display
, &e
);
1770 void client_set_wm_state(Client
*self
, long state
)
1772 if (state
== self
->wmstate
) return; /* no change */
1776 client_iconify(self
, TRUE
, TRUE
);
1779 client_iconify(self
, FALSE
, TRUE
);
1784 void client_set_state(Client
*self
, Atom action
, long data1
, long data2
)
1786 gboolean shaded
= self
->shaded
;
1787 gboolean fullscreen
= self
->fullscreen
;
1788 gboolean max_horz
= self
->max_horz
;
1789 gboolean max_vert
= self
->max_vert
;
1792 if (!(action
== prop_atoms
.net_wm_state_add
||
1793 action
== prop_atoms
.net_wm_state_remove
||
1794 action
== prop_atoms
.net_wm_state_toggle
))
1795 /* an invalid action was passed to the client message, ignore it */
1798 for (i
= 0; i
< 2; ++i
) {
1799 Atom state
= i
== 0 ? data1
: data2
;
1801 if (!state
) continue;
1803 /* if toggling, then pick whether we're adding or removing */
1804 if (action
== prop_atoms
.net_wm_state_toggle
) {
1805 if (state
== prop_atoms
.net_wm_state_modal
)
1806 action
= self
->modal
? prop_atoms
.net_wm_state_remove
:
1807 prop_atoms
.net_wm_state_add
;
1808 else if (state
== prop_atoms
.net_wm_state_maximized_vert
)
1809 action
= self
->max_vert
? prop_atoms
.net_wm_state_remove
:
1810 prop_atoms
.net_wm_state_add
;
1811 else if (state
== prop_atoms
.net_wm_state_maximized_horz
)
1812 action
= self
->max_horz
? prop_atoms
.net_wm_state_remove
:
1813 prop_atoms
.net_wm_state_add
;
1814 else if (state
== prop_atoms
.net_wm_state_shaded
)
1815 action
= self
->shaded
? prop_atoms
.net_wm_state_remove
:
1816 prop_atoms
.net_wm_state_add
;
1817 else if (state
== prop_atoms
.net_wm_state_skip_taskbar
)
1818 action
= self
->skip_taskbar
?
1819 prop_atoms
.net_wm_state_remove
:
1820 prop_atoms
.net_wm_state_add
;
1821 else if (state
== prop_atoms
.net_wm_state_skip_pager
)
1822 action
= self
->skip_pager
?
1823 prop_atoms
.net_wm_state_remove
:
1824 prop_atoms
.net_wm_state_add
;
1825 else if (state
== prop_atoms
.net_wm_state_fullscreen
)
1826 action
= self
->fullscreen
?
1827 prop_atoms
.net_wm_state_remove
:
1828 prop_atoms
.net_wm_state_add
;
1829 else if (state
== prop_atoms
.net_wm_state_above
)
1830 action
= self
->above
? prop_atoms
.net_wm_state_remove
:
1831 prop_atoms
.net_wm_state_add
;
1832 else if (state
== prop_atoms
.net_wm_state_below
)
1833 action
= self
->below
? prop_atoms
.net_wm_state_remove
:
1834 prop_atoms
.net_wm_state_add
;
1837 if (action
== prop_atoms
.net_wm_state_add
) {
1838 if (state
== prop_atoms
.net_wm_state_modal
) {
1839 /* XXX raise here or something? */
1841 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
1843 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
1845 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
1847 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
1848 self
->skip_taskbar
= TRUE
;
1849 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
1850 self
->skip_pager
= TRUE
;
1851 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
1853 } else if (state
== prop_atoms
.net_wm_state_above
) {
1855 } else if (state
== prop_atoms
.net_wm_state_below
) {
1859 } else { /* action == prop_atoms.net_wm_state_remove */
1860 if (state
== prop_atoms
.net_wm_state_modal
) {
1861 self
->modal
= FALSE
;
1862 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
1864 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
1866 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
1868 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
1869 self
->skip_taskbar
= FALSE
;
1870 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
1871 self
->skip_pager
= FALSE
;
1872 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
1874 } else if (state
== prop_atoms
.net_wm_state_above
) {
1875 self
->above
= FALSE
;
1876 } else if (state
== prop_atoms
.net_wm_state_below
) {
1877 self
->below
= FALSE
;
1881 if (max_horz
!= self
->max_horz
|| max_vert
!= self
->max_vert
) {
1882 if (max_horz
!= self
->max_horz
&& max_vert
!= self
->max_vert
) {
1884 if (max_horz
== max_vert
) { /* both going the same way */
1885 client_maximize(self
, max_horz
, 0, TRUE
);
1887 client_maximize(self
, max_horz
, 1, TRUE
);
1888 client_maximize(self
, max_vert
, 2, TRUE
);
1892 if (max_horz
!= self
->max_horz
)
1893 client_maximize(self
, max_horz
, 1, TRUE
);
1895 client_maximize(self
, max_vert
, 2, TRUE
);
1898 /* change fullscreen state before shading, as it will affect if the window
1900 if (fullscreen
!= self
->fullscreen
)
1901 client_fullscreen(self
, fullscreen
, TRUE
);
1902 if (shaded
!= self
->shaded
)
1903 client_shade(self
, shaded
);
1904 client_calc_layer(self
);
1905 client_change_state(self
); /* change the hint to relect these changes */
1908 gboolean
client_focus(Client
*self
)
1913 /* if we have a modal child, then focus it, not us */
1914 child
= client_find_modal_child(self
);
1916 return client_focus(child
);
1918 /* won't try focus if the client doesn't want it, or if the window isn't
1919 visible on the screen */
1920 if (!(self
->frame
->visible
&&
1921 (self
->can_focus
|| self
->focus_notify
)))
1924 /* do a check to see if the window has already been unmapped or destroyed
1925 do this intelligently while watching out for unmaps we've generated
1926 (ignore_unmaps > 0) */
1927 if (XCheckTypedWindowEvent(ob_display
, self
->window
,
1928 DestroyNotify
, &ev
)) {
1929 XPutBackEvent(ob_display
, &ev
);
1932 while (XCheckTypedWindowEvent(ob_display
, self
->window
,
1933 UnmapNotify
, &ev
)) {
1934 if (self
->ignore_unmaps
) {
1935 self
->ignore_unmaps
--;
1937 XPutBackEvent(ob_display
, &ev
);
1942 if (self
->can_focus
)
1943 XSetInputFocus(ob_display
, self
->window
, RevertToNone
,
1946 if (self
->focus_notify
) {
1948 ce
.xclient
.type
= ClientMessage
;
1949 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
1950 ce
.xclient
.display
= ob_display
;
1951 ce
.xclient
.window
= self
->window
;
1952 ce
.xclient
.format
= 32;
1953 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_take_focus
;
1954 ce
.xclient
.data
.l
[1] = CurrentTime
;
1955 ce
.xclient
.data
.l
[2] = 0l;
1956 ce
.xclient
.data
.l
[3] = 0l;
1957 ce
.xclient
.data
.l
[4] = 0l;
1958 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
1961 /* XSync(ob_display, FALSE); XXX Why sync? */
1965 void client_unfocus(Client
*self
)
1967 g_assert(focus_client
== self
);
1968 client_set_focused(self
, FALSE
);
1971 gboolean
client_focused(Client
*self
)
1973 return self
== focus_client
;
1976 void client_set_focused(Client
*self
, gboolean focused
)
1979 if (focus_client
!= self
)
1980 focus_set_client(self
);
1982 if (focus_client
== self
)
1983 focus_set_client(NULL
);
1986 /* focus state can affect the stacking layer */
1987 client_calc_layer(self
);
1989 engine_frame_adjust_focus(self
->frame
);