4 #include "extensions.h"
15 #include <X11/Xutil.h>
17 /*! The event mask to grab on client windows */
18 #define CLIENT_EVENTMASK (PropertyChangeMask | FocusChangeMask | \
21 #define CLIENT_NOPROPAGATEMASK (ButtonPressMask | ButtonReleaseMask | \
24 GSList
*client_list
= NULL
;
25 GHashTable
*client_map
= NULL
;
27 static Window
*client_startup_stack_order
= NULL
;
28 static gulong client_startup_stack_size
= 0;
30 static void client_get_all(Client
*self
);
31 static void client_toggle_border(Client
*self
, gboolean show
);
32 static void client_get_area(Client
*self
);
33 static void client_get_desktop(Client
*self
);
34 static void client_get_state(Client
*self
);
35 static void client_get_shaped(Client
*self
);
36 static void client_get_mwm_hints(Client
*self
);
37 static void client_get_gravity(Client
*self
);
38 static void client_showhide(Client
*self
);
39 static void client_change_allowed_actions(Client
*self
);
40 static void client_change_state(Client
*self
);
41 static Client
*search_focus_tree(Client
*node
, Client
*skip
);
42 static void client_apply_startup_state(Client
*self
);
43 static Client
*search_modal_tree(Client
*node
, Client
*skip
);
45 static guint
map_hash(Window
*w
) { return *w
; }
46 static gboolean
map_key_comp(Window
*w1
, Window
*w2
) { return *w1
== *w2
; }
50 client_map
= g_hash_table_new((GHashFunc
)map_hash
,
51 (GEqualFunc
)map_key_comp
);
53 /* save the stacking order on startup! */
54 PROP_GET32U(ob_root
, net_client_list_stacking
, window
,
55 client_startup_stack_order
, client_startup_stack_size
);
60 void client_shutdown()
62 g_hash_table_destroy(client_map
);
65 void client_set_list()
67 Window
*windows
, *win_it
;
69 guint size
= g_slist_length(client_list
);
71 /* create an array of the window ids */
73 windows
= g_new(Window
, size
);
75 for (it
= client_list
; it
!= NULL
; it
= it
->next
, ++win_it
)
76 *win_it
= ((Client
*)it
->data
)->window
;
80 PROP_SET32A(ob_root
, net_client_list
, window
, windows
, size
);
88 void client_manage_all()
90 ConfigValue focus_new
;
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 g_message("0x%lx %d %d", c
->window
, c
->iconic
, c
->shaded
);
136 if (c
) stacking_lower(c
);
138 g_free(client_startup_stack_order
);
139 client_startup_stack_order
= NULL
;
140 client_startup_stack_size
= 0;
142 if (!config_get("focusNew", Config_Bool
, &focus_new
))
143 g_assert_not_reached();
145 focus_fallback(FALSE
);
148 void client_manage(Window window
)
152 XWindowAttributes attrib
;
153 XSetWindowAttributes attrib_set
;
154 /* XWMHints *wmhint; */
156 ConfigValue focus_new
;
160 /* check if it has already been unmapped by the time we started mapping
161 the grab does a sync so we don't have to here */
162 if (XCheckTypedWindowEvent(ob_display
, window
, DestroyNotify
, &e
) ||
163 XCheckTypedWindowEvent(ob_display
, window
, UnmapNotify
, &e
)) {
164 XPutBackEvent(ob_display
, &e
);
167 return; /* don't manage it */
170 /* make sure it isn't an override-redirect window */
171 if (!XGetWindowAttributes(ob_display
, window
, &attrib
) ||
172 attrib
.override_redirect
) {
174 return; /* don't manage it */
177 /* /\* is the window a docking app *\/
178 if ((wmhint = XGetWMHints(ob_display, window))) {
179 if ((wmhint->flags & StateHint) &&
180 wmhint->initial_state == WithdrawnState) {
181 /\* XXX: make dock apps work! *\/
190 /* choose the events we want to receive on the CLIENT window */
191 attrib_set
.event_mask
= CLIENT_EVENTMASK
;
192 attrib_set
.do_not_propagate_mask
= CLIENT_NOPROPAGATEMASK
;
193 XChangeWindowAttributes(ob_display
, window
,
194 CWEventMask
|CWDontPropagate
, &attrib_set
);
197 /* create the Client struct, and populate it from the hints on the
199 client
= g_new(Client
, 1);
200 client
->window
= window
;
201 client_get_all(client
);
203 /* remove the client's border (and adjust re gravity) */
204 client_toggle_border(client
, FALSE
);
206 /* specify that if we exit, the window should not be destroyed and should
207 be reparented back to root automatically */
208 XChangeSaveSet(ob_display
, window
, SetModeInsert
);
210 /* create the decoration frame for the client window */
211 client
->frame
= engine_frame_new();
213 engine_frame_grab_client(client
->frame
, client
);
215 client_apply_startup_state(client
);
219 client_list
= g_slist_append(client_list
, client
);
220 stacking_list
= g_list_append(stacking_list
, client
);
221 g_assert(!g_hash_table_lookup(client_map
, &client
->window
));
222 g_hash_table_insert(client_map
, &client
->window
, client
);
224 /* update the focus lists */
225 if (client
->desktop
== DESKTOP_ALL
) {
226 for (i
= 0; i
< screen_num_desktops
; ++i
)
227 focus_order
[i
] = g_list_append(focus_order
[i
], client
);
230 focus_order
[i
] = g_list_append(focus_order
[i
], client
);
233 stacking_raise(client
);
235 screen_update_struts();
237 dispatch_client(Event_Client_New
, client
, 0, 0);
239 client_showhide(client
);
241 dispatch_client(Event_Client_Mapped
, client
, 0, 0);
243 if (!config_get("focusNew", Config_Bool
, &focus_new
))
244 g_assert_not_reached();
245 if (ob_state
!= State_Starting
&& focus_new
.bool)
246 client_focus(client
);
248 /* update the list hints */
251 /* g_message("Managed window 0x%lx", window);*/
254 void client_unmanage_all()
256 while (client_list
!= NULL
)
257 client_unmanage(client_list
->data
);
260 void client_unmanage(Client
*client
)
266 /* g_message("Unmanaging window: %lx", client->window);*/
268 dispatch_client(Event_Client_Destroy
, client
, 0, 0);
269 g_assert(client
!= NULL
);
271 /* remove the window from our save set */
272 XChangeSaveSet(ob_display
, client
->window
, SetModeDelete
);
274 /* we dont want events no more */
275 XSelectInput(ob_display
, client
->window
, NoEventMask
);
277 engine_frame_hide(client
->frame
);
279 client_list
= g_slist_remove(client_list
, client
);
280 stacking_list
= g_list_remove(stacking_list
, client
);
281 g_hash_table_remove(client_map
, &client
->window
);
283 /* update the focus lists */
284 if (client
->desktop
== DESKTOP_ALL
) {
285 for (i
= 0; i
< screen_num_desktops
; ++i
)
286 focus_order
[i
] = g_list_remove(focus_order
[i
], client
);
289 focus_order
[i
] = g_list_remove(focus_order
[i
], client
);
292 /* once the client is out of the list, update the struts to remove it's
294 screen_update_struts();
296 /* tell our parent that we're gone */
297 if (client
->transient_for
!= NULL
)
298 client
->transient_for
->transients
=
299 g_slist_remove(client
->transient_for
->transients
, client
);
301 /* tell our transients that we're gone */
302 for (it
= client
->transients
; it
!= NULL
; it
= it
->next
) {
303 ((Client
*)it
->data
)->transient_for
= NULL
;
304 client_calc_layer(it
->data
);
307 /* dispatch the unmapped event */
308 dispatch_client(Event_Client_Unmapped
, client
, 0, 0);
309 g_assert(client
!= NULL
);
311 /* give the client its border back */
312 client_toggle_border(client
, TRUE
);
314 /* reparent the window out of the frame, and free the frame */
315 engine_frame_release_client(client
->frame
, client
);
316 client
->frame
= NULL
;
318 if (ob_state
!= State_Exiting
) {
319 /* these values should not be persisted across a window
321 prop_erase(client
->window
, prop_atoms
.net_wm_desktop
);
322 prop_erase(client
->window
, prop_atoms
.net_wm_state
);
324 /* if we're left in an iconic state, the client wont be mapped. this is
325 bad, since we will no longer be managing the window on restart */
327 XMapWindow(ob_display
, client
->window
);
330 /* free all data allocated in the client struct */
331 g_slist_free(client
->transients
);
332 for (j
= 0; j
< client
->nicons
; ++j
)
333 g_free(client
->icons
[j
].data
);
334 if (client
->nicons
> 0)
335 g_free(client
->icons
);
336 g_free(client
->title
);
337 g_free(client
->icon_title
);
338 g_free(client
->name
);
339 g_free(client
->class);
340 g_free(client
->role
);
343 /* update the list hints */
347 static void client_toggle_border(Client
*self
, gboolean show
)
349 /* adjust our idea of where the client is, based on its border. When the
350 border is removed, the client should now be considered to be in a
352 when re-adding the border to the client, the same operation needs to be
354 int oldx
= self
->area
.x
, oldy
= self
->area
.y
;
355 int x
= oldx
, y
= oldy
;
356 switch(self
->gravity
) {
358 case NorthWestGravity
:
360 case SouthWestGravity
:
362 case NorthEastGravity
:
364 case SouthEastGravity
:
365 if (show
) x
-= self
->border_width
* 2;
366 else x
+= self
->border_width
* 2;
373 if (show
) x
-= self
->border_width
;
374 else x
+= self
->border_width
;
377 switch(self
->gravity
) {
379 case NorthWestGravity
:
381 case NorthEastGravity
:
383 case SouthWestGravity
:
385 case SouthEastGravity
:
386 if (show
) y
-= self
->border_width
* 2;
387 else y
+= self
->border_width
* 2;
394 if (show
) y
-= self
->border_width
;
395 else y
+= self
->border_width
;
402 XSetWindowBorderWidth(ob_display
, self
->window
, self
->border_width
);
404 /* move the client so it is back it the right spot _with_ its
406 if (x
!= oldx
|| y
!= oldy
)
407 XMoveWindow(ob_display
, self
->window
, x
, y
);
409 XSetWindowBorderWidth(ob_display
, self
->window
, 0);
413 static void client_get_all(Client
*self
)
415 /* update EVERYTHING!! */
417 self
->ignore_unmaps
= 0;
421 self
->title
= self
->icon_title
= NULL
;
422 self
->name
= self
->class = self
->role
= NULL
;
423 self
->wmstate
= NormalState
;
424 self
->transient
= FALSE
;
425 self
->transients
= NULL
;
426 self
->transient_for
= NULL
;
428 self
->urgent
= FALSE
;
429 self
->positioned
= FALSE
;
430 self
->disabled_decorations
= 0;
434 client_get_area(self
);
435 client_get_desktop(self
);
436 client_get_state(self
);
437 client_get_shaped(self
);
439 client_update_transient_for(self
);
440 client_get_mwm_hints(self
);
441 client_get_type(self
);/* this can change the mwmhints for special cases */
443 client_update_protocols(self
);
445 client_get_gravity(self
); /* get the attribute gravity */
446 client_update_normal_hints(self
); /* this may override the attribute
449 /* got the type, the mwmhints, the protocols, and the normal hints
450 (min/max sizes), so we're ready to set up the decorations/functions */
451 client_setup_decor_and_functions(self
);
453 client_update_wmhints(self
);
454 client_update_title(self
);
455 client_update_icon_title(self
);
456 client_update_class(self
);
457 client_update_strut(self
);
458 client_update_icons(self
);
459 client_update_kwm_icon(self
);
461 /* this makes sure that these windows appear on all desktops */
462 if (self
->type
== Type_Desktop
)
463 self
->desktop
= DESKTOP_ALL
;
465 /* set the desktop hint, to make sure that it always exists, and to
466 reflect any changes we've made here */
467 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, self
->desktop
);
469 client_change_state(self
);
472 static void client_get_area(Client
*self
)
474 XWindowAttributes wattrib
;
477 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
478 g_assert(ret
!= BadWindow
);
480 RECT_SET(self
->area
, wattrib
.x
, wattrib
.y
, wattrib
.width
, wattrib
.height
);
481 self
->border_width
= wattrib
.border_width
;
484 static void client_get_desktop(Client
*self
)
488 if (PROP_GET32(self
->window
, net_wm_desktop
, cardinal
, d
)) {
489 if (d
>= screen_num_desktops
&& d
!= DESKTOP_ALL
)
490 d
= screen_num_desktops
- 1;
493 /* defaults to the current desktop */
494 self
->desktop
= screen_desktop
;
498 static void client_get_state(Client
*self
)
503 self
->modal
= self
->shaded
= self
->max_horz
= self
->max_vert
=
504 self
->fullscreen
= self
->above
= self
->below
= self
->iconic
=
505 self
->skip_taskbar
= self
->skip_pager
= FALSE
;
507 if (PROP_GET32U(self
->window
, net_wm_state
, atom
, state
, num
)) {
509 for (i
= 0; i
< num
; ++i
) {
510 if (state
[i
] == prop_atoms
.net_wm_state_modal
)
512 else if (state
[i
] == prop_atoms
.net_wm_state_shaded
)
514 else if (state
[i
] == prop_atoms
.net_wm_state_hidden
)
516 else if (state
[i
] == prop_atoms
.net_wm_state_skip_taskbar
)
517 self
->skip_taskbar
= TRUE
;
518 else if (state
[i
] == prop_atoms
.net_wm_state_skip_pager
)
519 self
->skip_pager
= TRUE
;
520 else if (state
[i
] == prop_atoms
.net_wm_state_fullscreen
)
521 self
->fullscreen
= TRUE
;
522 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_vert
)
523 self
->max_vert
= TRUE
;
524 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_horz
)
525 self
->max_horz
= TRUE
;
526 else if (state
[i
] == prop_atoms
.net_wm_state_above
)
528 else if (state
[i
] == prop_atoms
.net_wm_state_below
)
536 static void client_get_shaped(Client
*self
)
538 self
->shaped
= FALSE
;
540 if (extensions_shape
) {
545 XShapeSelectInput(ob_display
, self
->window
, ShapeNotifyMask
);
547 XShapeQueryExtents(ob_display
, self
->window
, &s
, &foo
,
548 &foo
, &ufoo
, &ufoo
, &foo
, &foo
, &foo
, &ufoo
,
550 self
->shaped
= (s
!= 0);
555 void client_update_transient_for(Client
*self
)
560 if (XGetTransientForHint(ob_display
, self
->window
, &t
) &&
561 t
!= self
->window
) { /* cant be transient to itself! */
562 self
->transient
= TRUE
;
563 c
= g_hash_table_lookup(client_map
, &t
);
564 g_assert(c
!= self
);/* if this happens then we need to check for it*/
566 if (!c
/*XXX: && _group*/) {
567 /* not transient to a client, see if it is transient for a
569 if (/*t == _group->leader() || */
572 /* window is a transient for its group! */
573 /* XXX: for now this is treated as non-transient.
574 this needs to be fixed! */
578 self
->transient
= FALSE
;
580 /* if anything has changed... */
581 if (c
!= self
->transient_for
) {
582 if (self
->transient_for
)
583 /* remove from old parent */
584 self
->transient_for
->transients
=
585 g_slist_remove(self
->transient_for
->transients
, self
);
586 self
->transient_for
= c
;
587 if (self
->transient_for
)
588 /* add to new parent */
589 self
->transient_for
->transients
=
590 g_slist_append(self
->transient_for
->transients
, self
);
594 static void client_get_mwm_hints(Client
*self
)
597 unsigned long *hints
;
599 self
->mwmhints
.flags
= 0; /* default to none */
601 if (PROP_GET32U(self
->window
, motif_wm_hints
, motif_wm_hints
, hints
, num
)) {
602 if (num
>= MWM_ELEMENTS
) {
603 self
->mwmhints
.flags
= hints
[0];
604 self
->mwmhints
.functions
= hints
[1];
605 self
->mwmhints
.decorations
= hints
[2];
611 void client_get_type(Client
*self
)
617 if (PROP_GET32U(self
->window
, net_wm_window_type
, atom
, val
, num
)) {
618 /* use the first value that we know about in the array */
619 for (i
= 0; i
< num
; ++i
) {
620 if (val
[i
] == prop_atoms
.net_wm_window_type_desktop
)
621 self
->type
= Type_Desktop
;
622 else if (val
[i
] == prop_atoms
.net_wm_window_type_dock
)
623 self
->type
= Type_Dock
;
624 else if (val
[i
] == prop_atoms
.net_wm_window_type_toolbar
)
625 self
->type
= Type_Toolbar
;
626 else if (val
[i
] == prop_atoms
.net_wm_window_type_menu
)
627 self
->type
= Type_Menu
;
628 else if (val
[i
] == prop_atoms
.net_wm_window_type_utility
)
629 self
->type
= Type_Utility
;
630 else if (val
[i
] == prop_atoms
.net_wm_window_type_splash
)
631 self
->type
= Type_Splash
;
632 else if (val
[i
] == prop_atoms
.net_wm_window_type_dialog
)
633 self
->type
= Type_Dialog
;
634 else if (val
[i
] == prop_atoms
.net_wm_window_type_normal
)
635 self
->type
= Type_Normal
;
636 else if (val
[i
] == prop_atoms
.kde_net_wm_window_type_override
) {
637 /* prevent this window from getting any decor or
639 self
->mwmhints
.flags
&= (MwmFlag_Functions
|
640 MwmFlag_Decorations
);
641 self
->mwmhints
.decorations
= 0;
642 self
->mwmhints
.functions
= 0;
644 if (self
->type
!= (WindowType
) -1)
645 break; /* grab the first legit type */
650 if (self
->type
== (WindowType
) -1) {
651 /*the window type hint was not set, which means we either classify
652 ourself as a normal window or a dialog, depending on if we are a
655 self
->type
= Type_Dialog
;
657 self
->type
= Type_Normal
;
661 void client_update_protocols(Client
*self
)
664 gulong num_return
, i
;
666 self
->focus_notify
= FALSE
;
667 self
->delete_window
= FALSE
;
669 if (PROP_GET32U(self
->window
, wm_protocols
, atom
, proto
, num_return
)) {
670 for (i
= 0; i
< num_return
; ++i
) {
671 if (proto
[i
] == prop_atoms
.wm_delete_window
) {
672 /* this means we can request the window to close */
673 self
->delete_window
= TRUE
;
674 } else if (proto
[i
] == prop_atoms
.wm_take_focus
)
675 /* if this protocol is requested, then the window will be
676 notified whenever we want it to receive focus */
677 self
->focus_notify
= TRUE
;
683 static void client_get_gravity(Client
*self
)
685 XWindowAttributes wattrib
;
688 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
689 g_assert(ret
!= BadWindow
);
690 self
->gravity
= wattrib
.win_gravity
;
693 void client_update_normal_hints(Client
*self
)
697 int oldgravity
= self
->gravity
;
700 self
->min_ratio
= 0.0f
;
701 self
->max_ratio
= 0.0f
;
702 SIZE_SET(self
->size_inc
, 1, 1);
703 SIZE_SET(self
->base_size
, 0, 0);
704 SIZE_SET(self
->min_size
, 0, 0);
705 SIZE_SET(self
->max_size
, G_MAXINT
, G_MAXINT
);
707 /* get the hints from the window */
708 if (XGetWMNormalHints(ob_display
, self
->window
, &size
, &ret
)) {
709 self
->positioned
= (size
.flags
& (PPosition
|USPosition
));
711 if (size
.flags
& PWinGravity
) {
712 self
->gravity
= size
.win_gravity
;
714 /* if the client has a frame, i.e. has already been mapped and
715 is changing its gravity */
716 if (self
->frame
&& self
->gravity
!= oldgravity
) {
717 /* move our idea of the client's position based on its new
719 self
->area
.x
= self
->frame
->area
.x
;
720 self
->area
.y
= self
->frame
->area
.y
;
721 frame_frame_gravity(self
->frame
, &self
->area
.x
, &self
->area
.y
);
725 if (size
.flags
& PAspect
) {
726 if (size
.min_aspect
.y
)
727 self
->min_ratio
= (float)size
.min_aspect
.x
/ size
.min_aspect
.y
;
728 if (size
.max_aspect
.y
)
729 self
->max_ratio
= (float)size
.max_aspect
.x
/ size
.max_aspect
.y
;
732 if (size
.flags
& PMinSize
)
733 SIZE_SET(self
->min_size
, size
.min_width
, size
.min_height
);
735 if (size
.flags
& PMaxSize
)
736 SIZE_SET(self
->max_size
, size
.max_width
, size
.max_height
);
738 if (size
.flags
& PBaseSize
)
739 SIZE_SET(self
->base_size
, size
.base_width
, size
.base_height
);
741 if (size
.flags
& PResizeInc
)
742 SIZE_SET(self
->size_inc
, size
.width_inc
, size
.height_inc
);
746 void client_setup_decor_and_functions(Client
*self
)
748 /* start with everything (cept fullscreen) */
749 self
->decorations
= Decor_Titlebar
| Decor_Handle
| Decor_Border
|
750 Decor_Icon
| Decor_AllDesktops
| Decor_Iconify
| Decor_Maximize
;
751 self
->functions
= Func_Resize
| Func_Move
| Func_Iconify
| Func_Maximize
|
753 if (self
->delete_window
) {
754 self
->decorations
|= Decor_Close
;
755 self
->functions
|= Func_Close
;
758 if (!(self
->min_size
.width
< self
->max_size
.width
||
759 self
->min_size
.height
< self
->max_size
.height
)) {
760 self
->decorations
&= ~(Decor_Maximize
| Decor_Handle
);
761 self
->functions
&= ~(Func_Resize
| Func_Maximize
);
764 switch (self
->type
) {
766 /* normal windows retain all of the possible decorations and
767 functionality, and are the only windows that you can fullscreen */
768 self
->functions
|= Func_Fullscreen
;
772 /* dialogs cannot be maximized */
773 self
->decorations
&= ~Decor_Maximize
;
774 self
->functions
&= ~Func_Maximize
;
780 /* these windows get less functionality */
781 self
->decorations
&= ~(Decor_Iconify
| Decor_Handle
);
782 self
->functions
&= ~(Func_Iconify
| Func_Resize
);
788 /* none of these windows are manipulated by the window manager */
789 self
->decorations
= 0;
794 /* Mwm Hints are applied subtractively to what has already been chosen for
795 decor and functionality */
796 if (self
->mwmhints
.flags
& MwmFlag_Decorations
) {
797 if (! (self
->mwmhints
.decorations
& MwmDecor_All
)) {
798 if (! (self
->mwmhints
.decorations
& MwmDecor_Border
))
799 self
->decorations
&= ~Decor_Border
;
800 if (! (self
->mwmhints
.decorations
& MwmDecor_Handle
))
801 self
->decorations
&= ~Decor_Handle
;
802 if (! (self
->mwmhints
.decorations
& MwmDecor_Title
))
803 self
->decorations
&= ~Decor_Titlebar
;
804 if (! (self
->mwmhints
.decorations
& MwmDecor_Iconify
))
805 self
->decorations
&= ~Decor_Iconify
;
806 if (! (self
->mwmhints
.decorations
& MwmDecor_Maximize
))
807 self
->decorations
&= ~Decor_Maximize
;
811 if (self
->mwmhints
.flags
& MwmFlag_Functions
) {
812 if (! (self
->mwmhints
.functions
& MwmFunc_All
)) {
813 if (! (self
->mwmhints
.functions
& MwmFunc_Resize
))
814 self
->functions
&= ~Func_Resize
;
815 if (! (self
->mwmhints
.functions
& MwmFunc_Move
))
816 self
->functions
&= ~Func_Move
;
817 if (! (self
->mwmhints
.functions
& MwmFunc_Iconify
))
818 self
->functions
&= ~Func_Iconify
;
819 if (! (self
->mwmhints
.functions
& MwmFunc_Maximize
))
820 self
->functions
&= ~Func_Maximize
;
821 /* dont let mwm hints kill the close button
822 if (! (self->mwmhints.functions & MwmFunc_Close))
823 self->functions &= ~Func_Close; */
827 /* can't maximize without moving/resizing */
828 if (!((self
->functions
& Func_Move
) && (self
->functions
& Func_Resize
)))
829 self
->functions
&= ~(Func_Maximize
| Func_Fullscreen
);
831 /* finally, user specified disabled decorations are applied to subtract
833 if (self
->disabled_decorations
& Decor_Titlebar
)
834 self
->decorations
&= ~Decor_Titlebar
;
835 if (self
->disabled_decorations
& Decor_Handle
)
836 self
->decorations
&= ~Decor_Handle
;
837 if (self
->disabled_decorations
& Decor_Border
)
838 self
->decorations
&= ~Decor_Border
;
839 if (self
->disabled_decorations
& Decor_Iconify
)
840 self
->decorations
&= ~Decor_Iconify
;
841 if (self
->disabled_decorations
& Decor_Maximize
)
842 self
->decorations
&= ~Decor_Maximize
;
843 if (self
->disabled_decorations
& Decor_AllDesktops
)
844 self
->decorations
&= ~Decor_AllDesktops
;
845 if (self
->disabled_decorations
& Decor_Close
)
846 self
->decorations
&= ~Decor_Close
;
848 /* if we don't have a titlebar, then we cannot shade! */
849 if (!(self
->decorations
& Decor_Titlebar
))
850 self
->functions
&= ~Func_Shade
;
852 client_change_allowed_actions(self
);
855 /* change the decors on the frame, and with more/less decorations,
856 we may also need to be repositioned */
857 engine_frame_adjust_area(self
->frame
, TRUE
, TRUE
);
858 /* with new decor, the window's maximized size may change */
859 client_remaximize(self
);
863 static void client_change_allowed_actions(Client
*self
)
868 actions
[num
++] = prop_atoms
.net_wm_action_change_desktop
;
870 if (self
->functions
& Func_Shade
)
871 actions
[num
++] = prop_atoms
.net_wm_action_shade
;
872 if (self
->functions
& Func_Close
)
873 actions
[num
++] = prop_atoms
.net_wm_action_close
;
874 if (self
->functions
& Func_Move
)
875 actions
[num
++] = prop_atoms
.net_wm_action_move
;
876 if (self
->functions
& Func_Iconify
)
877 actions
[num
++] = prop_atoms
.net_wm_action_minimize
;
878 if (self
->functions
& Func_Resize
)
879 actions
[num
++] = prop_atoms
.net_wm_action_resize
;
880 if (self
->functions
& Func_Fullscreen
)
881 actions
[num
++] = prop_atoms
.net_wm_action_fullscreen
;
882 if (self
->functions
& Func_Maximize
) {
883 actions
[num
++] = prop_atoms
.net_wm_action_maximize_horz
;
884 actions
[num
++] = prop_atoms
.net_wm_action_maximize_vert
;
887 PROP_SET32A(self
->window
, net_wm_allowed_actions
, atom
, actions
, num
);
889 /* make sure the window isn't breaking any rules now */
891 if (!(self
->functions
& Func_Shade
) && self
->shaded
) {
892 if (self
->frame
) client_shade(self
, FALSE
);
893 else self
->shaded
= FALSE
;
895 if (!(self
->functions
& Func_Iconify
) && self
->iconic
) {
896 if (self
->frame
) client_iconify(self
, FALSE
, TRUE
);
897 else self
->iconic
= FALSE
;
899 if (!(self
->functions
& Func_Fullscreen
) && self
->fullscreen
) {
900 if (self
->frame
) client_fullscreen(self
, FALSE
, TRUE
);
901 else self
->fullscreen
= FALSE
;
903 if (!(self
->functions
& Func_Maximize
) && (self
->max_horz
||
905 if (self
->frame
) client_maximize(self
, FALSE
, 0, TRUE
);
906 else self
->max_vert
= self
->max_horz
= FALSE
;
910 void client_remaximize(Client
*self
)
913 if (self
->max_horz
&& self
->max_vert
)
915 else if (self
->max_horz
)
917 else if (self
->max_vert
)
920 return; /* not maximized */
921 self
->max_horz
= self
->max_vert
= FALSE
;
922 client_maximize(self
, TRUE
, dir
, FALSE
);
925 void client_update_wmhints(Client
*self
)
930 /* assume a window takes input if it doesnt specify */
931 self
->can_focus
= TRUE
;
933 if ((hints
= XGetWMHints(ob_display
, self
->window
)) != NULL
) {
934 if (hints
->flags
& InputHint
)
935 self
->can_focus
= hints
->input
;
937 /* only do this when starting! */
938 if (ob_state
== State_Starting
&& (hints
->flags
& StateHint
))
939 self
->iconic
= hints
->initial_state
== IconicState
;
941 if (hints
->flags
& XUrgencyHint
)
944 if (hints
->flags
& WindowGroupHint
) {
945 if (hints
->window_group
!= self
->group
) {
946 /* XXX: remove from the old group if there was one */
947 self
->group
= hints
->window_group
;
948 /* XXX: do stuff with the group */
950 } else /* no group! */
953 if (hints
->flags
& IconPixmapHint
) {
954 client_update_kwm_icon(self
);
955 /* try get the kwm icon first, this is a fallback only */
956 if (self
->pixmap_icon
== None
) {
957 self
->pixmap_icon
= hints
->icon_pixmap
;
958 if (hints
->flags
& IconMaskHint
)
959 self
->pixmap_icon_mask
= hints
->icon_mask
;
961 self
->pixmap_icon_mask
= None
;
964 engine_frame_adjust_icon(self
->frame
);
971 if (ur
!= self
->urgent
) {
973 g_message("Urgent Hint for 0x%lx: %s", self
->window
,
975 /* fire the urgent callback if we're mapped, otherwise, wait until
976 after we're mapped */
978 dispatch_client(Event_Client_Urgent
, self
, self
->urgent
, 0);
982 void client_update_title(Client
*self
)
989 if (!PROP_GETS(self
->window
, net_wm_name
, utf8
, data
)) {
990 /* try old x stuff */
991 if (PROP_GETS(self
->window
, wm_name
, string
, data
)) {
992 /* convert it to UTF-8 */
996 u
= g_locale_to_utf8(data
, -1, &r
, &w
, NULL
);
998 g_warning("Unable to convert string to UTF-8");
1005 data
= g_strdup("Unnamed Window");
1007 PROP_SETS(self
->window
, net_wm_visible_name
, utf8
, data
);
1013 engine_frame_adjust_title(self
->frame
);
1016 void client_update_icon_title(Client
*self
)
1020 g_free(self
->icon_title
);
1023 if (!PROP_GETS(self
->window
, net_wm_icon_name
, utf8
, data
)) {
1024 /* try old x stuff */
1025 if (PROP_GETS(self
->window
, wm_icon_name
, string
, data
)) {
1026 /* convert it to UTF-8 */
1030 u
= g_locale_to_utf8(data
, -1, &r
, &w
, NULL
);
1032 g_warning("Unable to convert string to UTF-8");
1039 data
= g_strdup("Unnamed Window");
1041 PROP_SETS(self
->window
, net_wm_visible_icon_name
, utf8
, data
);
1044 self
->icon_title
= data
;
1047 void client_update_class(Client
*self
)
1053 if (self
->name
) g_free(self
->name
);
1054 if (self
->class) g_free(self
->class);
1055 if (self
->role
) g_free(self
->role
);
1057 self
->name
= self
->class = self
->role
= NULL
;
1059 data
= g_ptr_array_new();
1061 if (PROP_GETSA(self
->window
, wm_class
, string
, data
)) {
1063 self
->name
= g_strdup(g_ptr_array_index(data
, 0));
1065 self
->class = g_strdup(g_ptr_array_index(data
, 1));
1068 for (i
= 0; i
< data
->len
; ++i
)
1069 g_free(g_ptr_array_index(data
, i
));
1070 g_ptr_array_free(data
, TRUE
);
1072 if (PROP_GETS(self
->window
, wm_window_role
, string
, s
))
1073 self
->role
= g_strdup(s
);
1075 if (self
->name
== NULL
) self
->name
= g_strdup("");
1076 if (self
->class == NULL
) self
->class = g_strdup("");
1077 if (self
->role
== NULL
) self
->role
= g_strdup("");
1080 void client_update_strut(Client
*self
)
1084 if (PROP_GET32A(self
->window
, net_wm_strut
, cardinal
, data
, 4)) {
1085 STRUT_SET(self
->strut
, data
[0], data
[1], data
[2], data
[3]);
1088 STRUT_SET(self
->strut
, 0, 0, 0, 0);
1090 /* updating here is pointless while we're being mapped cuz we're not in
1091 the client list yet */
1093 screen_update_struts();
1096 void client_update_icons(Client
*self
)
1099 unsigned long *data
;
1100 unsigned long w
, h
, i
;
1103 for (j
= 0; j
< self
->nicons
; ++j
)
1104 g_free(self
->icons
[j
].data
);
1105 if (self
->nicons
> 0)
1106 g_free(self
->icons
);
1109 if (PROP_GET32U(self
->window
, net_wm_icon
, cardinal
, data
, num
)) {
1110 /* figure out how many valid icons are in here */
1112 while (num
- i
> 2) {
1120 self
->icons
= g_new(Icon
, self
->nicons
);
1122 /* store the icons */
1124 for (j
= 0; j
< self
->nicons
; ++j
) {
1125 w
= self
->icons
[j
].width
= data
[i
++];
1126 h
= self
->icons
[j
].height
= data
[i
++];
1127 self
->icons
[j
].data
=
1128 g_memdup(&data
[i
], w
* h
* sizeof(gulong
));
1137 engine_frame_adjust_icon(self
->frame
);
1140 void client_update_kwm_icon(Client
*self
)
1144 if (PROP_GET32A(self
->window
, kwm_win_icon
, kwm_win_icon
, data
, 2)) {
1145 self
->pixmap_icon
= data
[0];
1146 self
->pixmap_icon_mask
= data
[1];
1149 self
->pixmap_icon
= self
->pixmap_icon_mask
= None
;
1152 engine_frame_adjust_icon(self
->frame
);
1155 static void client_change_state(Client
*self
)
1157 unsigned long state
[2];
1161 state
[0] = self
->wmstate
;
1163 PROP_SET32A(self
->window
, wm_state
, wm_state
, state
, 2);
1167 netstate
[num
++] = prop_atoms
.net_wm_state_modal
;
1169 netstate
[num
++] = prop_atoms
.net_wm_state_shaded
;
1171 netstate
[num
++] = prop_atoms
.net_wm_state_hidden
;
1172 if (self
->skip_taskbar
)
1173 netstate
[num
++] = prop_atoms
.net_wm_state_skip_taskbar
;
1174 if (self
->skip_pager
)
1175 netstate
[num
++] = prop_atoms
.net_wm_state_skip_pager
;
1176 if (self
->fullscreen
)
1177 netstate
[num
++] = prop_atoms
.net_wm_state_fullscreen
;
1179 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_vert
;
1181 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_horz
;
1183 netstate
[num
++] = prop_atoms
.net_wm_state_above
;
1185 netstate
[num
++] = prop_atoms
.net_wm_state_below
;
1186 PROP_SET32A(self
->window
, net_wm_state
, atom
, netstate
, num
);
1188 client_calc_layer(self
);
1191 engine_frame_adjust_state(self
->frame
);
1194 static Client
*search_focus_tree(Client
*node
, Client
*skip
)
1199 for (it
= node
->transients
; it
!= NULL
; it
= it
->next
) {
1200 Client
*c
= it
->data
;
1201 if (c
== skip
) continue; /* circular? */
1202 if ((ret
= search_focus_tree(c
, skip
))) return ret
;
1203 if (client_focused(c
)) return c
;
1208 void client_calc_layer(Client
*self
)
1214 /* are we fullscreen, or do we have a fullscreen transient parent? */
1218 if (c
->fullscreen
) {
1222 c
= c
->transient_for
;
1224 if (!fs
&& self
->fullscreen
) {
1225 /* is one of our transients focused? */
1226 c
= search_focus_tree(self
, self
);
1227 if (c
!= NULL
) fs
= TRUE
;
1230 if (self
->iconic
) l
= Layer_Icon
;
1231 else if (fs
) l
= Layer_Fullscreen
;
1232 else if (self
->type
== Type_Desktop
) l
= Layer_Desktop
;
1233 else if (self
->type
== Type_Dock
) {
1234 if (!self
->below
) l
= Layer_Top
;
1235 else l
= Layer_Normal
;
1237 else if (self
->above
) l
= Layer_Above
;
1238 else if (self
->below
) l
= Layer_Below
;
1239 else l
= Layer_Normal
;
1241 if (l
!= self
->layer
) {
1244 stacking_raise(self
);
1248 gboolean
client_should_show(Client
*self
)
1250 if (self
->iconic
) return FALSE
;
1251 else if (!(self
->desktop
== screen_desktop
||
1252 self
->desktop
== DESKTOP_ALL
)) return FALSE
;
1253 else if (client_normal(self
) && screen_showing_desktop
) return FALSE
;
1258 static void client_showhide(Client
*self
)
1261 if (client_should_show(self
))
1262 engine_frame_show(self
->frame
);
1264 engine_frame_hide(self
->frame
);
1267 gboolean
client_normal(Client
*self
) {
1268 return ! (self
->type
== Type_Desktop
|| self
->type
== Type_Dock
||
1269 self
->type
== Type_Splash
);
1272 static void client_apply_startup_state(Client
*self
)
1274 /* these are in a carefully crafted order.. */
1277 self
->iconic
= FALSE
;
1278 client_iconify(self
, TRUE
, FALSE
);
1280 if (self
->fullscreen
) {
1281 self
->fullscreen
= FALSE
;
1282 client_fullscreen(self
, TRUE
, FALSE
);
1285 self
->shaded
= FALSE
;
1286 client_shade(self
, TRUE
);
1289 dispatch_client(Event_Client_Urgent
, self
, self
->urgent
, 0);
1291 if (self
->max_vert
&& self
->max_horz
) {
1292 self
->max_vert
= self
->max_horz
= FALSE
;
1293 client_maximize(self
, TRUE
, 0, FALSE
);
1294 } else if (self
->max_vert
) {
1295 self
->max_vert
= FALSE
;
1296 client_maximize(self
, TRUE
, 2, FALSE
);
1297 } else if (self
->max_horz
) {
1298 self
->max_horz
= FALSE
;
1299 client_maximize(self
, TRUE
, 1, FALSE
);
1302 /* nothing to do for the other states:
1311 void client_configure(Client
*self
, Corner anchor
, int x
, int y
, int w
, int h
,
1312 gboolean user
, gboolean final
)
1314 gboolean moved
= FALSE
, resized
= FALSE
;
1316 /* set the size and position if fullscreen */
1317 if (self
->fullscreen
) {
1320 w
= screen_physical_size
.width
;
1321 h
= screen_physical_size
.height
;
1323 /* set the size and position if maximized */
1324 if (self
->max_horz
) {
1325 x
= screen_area(self
->desktop
)->x
- self
->frame
->size
.left
;
1326 w
= screen_area(self
->desktop
)->x
+
1327 screen_area(self
->desktop
)->width
;
1329 if (self
->max_vert
) {
1330 y
= screen_area(self
->desktop
)->y
;
1331 h
= screen_area(self
->desktop
)->y
+
1332 screen_area(self
->desktop
)->height
-
1333 self
->frame
->size
.top
- self
->frame
->size
.bottom
;
1337 /* these override the above states! if you cant move you can't move! */
1339 if (!(self
->functions
& Func_Move
)) {
1343 if (!(self
->functions
& Func_Resize
)) {
1344 w
= self
->area
.width
;
1345 h
= self
->area
.height
;
1349 if (!(w
== self
->area
.width
&& h
== self
->area
.height
)) {
1350 w
-= self
->base_size
.width
;
1351 h
-= self
->base_size
.height
;
1354 /* for interactive resizing. have to move half an increment in each
1357 /* how far we are towards the next size inc */
1358 int mw
= w
% self
->size_inc
.width
;
1359 int mh
= h
% self
->size_inc
.height
;
1361 int aw
= self
->size_inc
.width
/ 2;
1362 int ah
= self
->size_inc
.height
/ 2;
1363 /* don't let us move into a new size increment */
1364 if (mw
+ aw
>= self
->size_inc
.width
)
1365 aw
= self
->size_inc
.width
- mw
- 1;
1366 if (mh
+ ah
>= self
->size_inc
.height
)
1367 ah
= self
->size_inc
.height
- mh
- 1;
1371 /* if this is a user-requested resize, then check against min/max
1372 sizes and aspect ratios */
1374 /* smaller than min size or bigger than max size? */
1375 if (w
> self
->max_size
.width
) w
= self
->max_size
.width
;
1376 if (w
< self
->min_size
.width
) w
= self
->min_size
.width
;
1377 if (h
> self
->max_size
.height
) h
= self
->max_size
.height
;
1378 if (h
< self
->min_size
.height
) h
= self
->min_size
.height
;
1380 /* adjust the height ot match the width for the aspect ratios */
1381 if (self
->min_ratio
)
1382 if (h
* self
->min_ratio
> w
) h
= (int)(w
/ self
->min_ratio
);
1383 if (self
->max_ratio
)
1384 if (h
* self
->max_ratio
< w
) h
= (int)(w
/ self
->max_ratio
);
1387 /* keep to the increments */
1388 w
/= self
->size_inc
.width
;
1389 h
/= self
->size_inc
.height
;
1391 /* you cannot resize to nothing */
1395 /* store the logical size */
1396 SIZE_SET(self
->logical_size
, w
, h
);
1398 w
*= self
->size_inc
.width
;
1399 h
*= self
->size_inc
.height
;
1401 w
+= self
->base_size
.width
;
1402 h
+= self
->base_size
.height
;
1406 case Corner_TopLeft
:
1408 case Corner_TopRight
:
1409 x
-= w
- self
->area
.width
;
1411 case Corner_BottomLeft
:
1412 y
-= h
- self
->area
.height
;
1414 case Corner_BottomRight
:
1415 x
-= w
- self
->area
.width
;
1416 y
-= h
- self
->area
.height
;
1420 moved
= x
!= self
->area
.x
|| y
!= self
->area
.y
;
1421 resized
= w
!= self
->area
.width
|| h
!= self
->area
.height
;
1423 RECT_SET(self
->area
, x
, y
, w
, h
);
1426 XResizeWindow(ob_display
, self
->window
, w
, h
);
1428 /* move/resize the frame to match the request */
1430 if (moved
|| resized
)
1431 engine_frame_adjust_area(self
->frame
, moved
, resized
);
1433 if (!user
|| final
) {
1435 event
.type
= ConfigureNotify
;
1436 event
.xconfigure
.display
= ob_display
;
1437 event
.xconfigure
.event
= self
->window
;
1438 event
.xconfigure
.window
= self
->window
;
1440 /* root window coords with border in mind */
1441 event
.xconfigure
.x
= x
- self
->border_width
+
1442 self
->frame
->size
.left
;
1443 event
.xconfigure
.y
= y
- self
->border_width
+
1444 self
->frame
->size
.top
;
1446 event
.xconfigure
.width
= self
->area
.width
;
1447 event
.xconfigure
.height
= self
->area
.height
;
1448 event
.xconfigure
.border_width
= self
->border_width
;
1449 event
.xconfigure
.above
= self
->frame
->plate
;
1450 event
.xconfigure
.override_redirect
= FALSE
;
1451 XSendEvent(event
.xconfigure
.display
, event
.xconfigure
.window
,
1452 FALSE
, StructureNotifyMask
, &event
);
1457 void client_fullscreen(Client
*self
, gboolean fs
, gboolean savearea
)
1461 if (!(self
->functions
& Func_Fullscreen
) || /* can't */
1462 self
->fullscreen
== fs
) return; /* already done */
1464 self
->fullscreen
= fs
;
1465 client_change_state(self
); /* change the state hints on the client */
1468 /* save the functions and remove them */
1469 self
->pre_fs_func
= self
->functions
;
1470 self
->functions
&= (Func_Close
| Func_Fullscreen
|
1472 /* save the decorations and remove them */
1473 self
->pre_fs_decor
= self
->decorations
;
1474 self
->decorations
= 0;
1477 dimensions
[0] = self
->area
.x
;
1478 dimensions
[1] = self
->area
.y
;
1479 dimensions
[2] = self
->area
.width
;
1480 dimensions
[3] = self
->area
.height
;
1482 PROP_SET32A(self
->window
, openbox_premax
, cardinal
,
1486 /* these are not actually used cuz client_configure will set them
1487 as appropriate when the window is fullscreened */
1492 self
->functions
= self
->pre_fs_func
;
1493 self
->decorations
= self
->pre_fs_decor
;
1495 if (PROP_GET32A(self
->window
, openbox_premax
, cardinal
,
1503 /* pick some fallbacks... */
1504 x
= screen_area(self
->desktop
)->x
+
1505 screen_area(self
->desktop
)->width
/ 4;
1506 y
= screen_area(self
->desktop
)->y
+
1507 screen_area(self
->desktop
)->height
/ 4;
1508 w
= screen_area(self
->desktop
)->width
/ 2;
1509 h
= screen_area(self
->desktop
)->height
/ 2;
1513 client_change_allowed_actions(self
); /* based on the new _functions */
1515 /* when fullscreening, don't obey things like increments, fill the
1517 client_configure(self
, Corner_TopLeft
, x
, y
, w
, h
, !fs
, TRUE
);
1519 /* raise (back) into our stacking layer */
1520 stacking_raise(self
);
1522 /* try focus us when we go into fullscreen mode */
1526 void client_iconify(Client
*self
, gboolean iconic
, gboolean curdesk
)
1528 if (self
->iconic
== iconic
) return; /* nothing to do */
1530 g_message("%sconifying window: 0x%lx", (iconic
? "I" : "Uni"),
1533 self
->iconic
= iconic
;
1536 self
->wmstate
= IconicState
;
1537 self
->ignore_unmaps
++;
1538 /* we unmap the client itself so that we can get MapRequest events,
1539 and because the ICCCM tells us to! */
1540 XUnmapWindow(ob_display
, self
->window
);
1543 client_set_desktop(self
, screen_desktop
);
1544 self
->wmstate
= self
->shaded
? IconicState
: NormalState
;
1545 XMapWindow(ob_display
, self
->window
);
1547 client_change_state(self
);
1548 client_showhide(self
);
1549 screen_update_struts();
1551 dispatch_client(iconic
? Event_Client_Unmapped
: Event_Client_Mapped
,
1555 void client_maximize(Client
*self
, gboolean max
, int dir
, gboolean savearea
)
1559 g_assert(dir
== 0 || dir
== 1 || dir
== 2);
1560 if (!(self
->functions
& Func_Maximize
)) return; /* can't */
1562 /* check if already done */
1564 if (dir
== 0 && self
->max_horz
&& self
->max_vert
) return;
1565 if (dir
== 1 && self
->max_horz
) return;
1566 if (dir
== 2 && self
->max_vert
) return;
1568 if (dir
== 0 && !self
->max_horz
&& !self
->max_vert
) return;
1569 if (dir
== 1 && !self
->max_horz
) return;
1570 if (dir
== 2 && !self
->max_vert
) return;
1573 /* work with the frame's coords */
1574 x
= self
->frame
->area
.x
;
1575 y
= self
->frame
->area
.y
;
1576 w
= self
->area
.width
;
1577 h
= self
->area
.height
;
1589 /* get the property off the window and use it for the dimensions
1590 we are already maxed on */
1591 if (PROP_GET32A(self
->window
, openbox_premax
, cardinal
,
1593 if (self
->max_horz
) {
1594 dimensions
[0] = readdim
[0];
1595 dimensions
[2] = readdim
[2];
1597 if (self
->max_vert
) {
1598 dimensions
[1] = readdim
[1];
1599 dimensions
[3] = readdim
[3];
1604 PROP_SET32A(self
->window
, openbox_premax
, cardinal
,
1608 /* pass the client's current position info. the client_configure
1609 will move/size stuff as appropriate for a maximized window */
1612 w
= self
->area
.width
;
1613 h
= self
->area
.height
;
1617 if (PROP_GET32A(self
->window
, openbox_premax
, cardinal
,
1619 if (dir
== 0 || dir
== 1) { /* horz */
1623 if (dir
== 0 || dir
== 2) { /* vert */
1629 /* pick some fallbacks... */
1630 if (dir
== 0 || dir
== 1) { /* horz */
1631 x
= screen_area(self
->desktop
)->x
+
1632 screen_area(self
->desktop
)->width
/ 4;
1633 w
= screen_area(self
->desktop
)->width
/ 2;
1635 if (dir
== 0 || dir
== 2) { /* vert */
1636 y
= screen_area(self
->desktop
)->y
+
1637 screen_area(self
->desktop
)->height
/ 4;
1638 h
= screen_area(self
->desktop
)->height
/ 2;
1643 if (dir
== 0 || dir
== 1) /* horz */
1644 self
->max_horz
= max
;
1645 if (dir
== 0 || dir
== 2) /* vert */
1646 self
->max_vert
= max
;
1648 if (!self
->max_horz
&& !self
->max_vert
)
1649 PROP_ERASE(self
->window
, openbox_premax
);
1651 client_change_state(self
); /* change the state hints on the client */
1653 /* figure out where the client should be going */
1654 frame_frame_gravity(self
->frame
, &x
, &y
);
1655 client_configure(self
, Corner_TopLeft
, x
, y
, w
, h
, TRUE
, TRUE
);
1658 void client_shade(Client
*self
, gboolean shade
)
1660 if (!(self
->functions
& Func_Shade
) || /* can't */
1661 self
->shaded
== shade
) return; /* already done */
1663 /* when we're iconic, don't change the wmstate */
1665 self
->wmstate
= shade
? IconicState
: NormalState
;
1666 self
->shaded
= shade
;
1667 client_change_state(self
);
1668 /* resize the frame to just the titlebar */
1669 engine_frame_adjust_area(self
->frame
, FALSE
, FALSE
);
1672 void client_close(Client
*self
)
1676 if (!(self
->functions
& Func_Close
)) return;
1679 XXX: itd be cool to do timeouts and shit here for killing the client's
1681 like... if the window is around after 5 seconds, then the close button
1682 turns a nice red, and if this function is called again, the client is
1686 ce
.xclient
.type
= ClientMessage
;
1687 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
1688 ce
.xclient
.display
= ob_display
;
1689 ce
.xclient
.window
= self
->window
;
1690 ce
.xclient
.format
= 32;
1691 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_delete_window
;
1692 ce
.xclient
.data
.l
[1] = event_lasttime
;
1693 ce
.xclient
.data
.l
[2] = 0l;
1694 ce
.xclient
.data
.l
[3] = 0l;
1695 ce
.xclient
.data
.l
[4] = 0l;
1696 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
1699 void client_kill(Client
*self
)
1701 XKillClient(ob_display
, self
->window
);
1704 void client_set_desktop(Client
*self
, guint target
)
1708 if (target
== self
->desktop
) return;
1710 g_message("Setting desktop %u\n", target
);
1712 g_assert(target
< screen_num_desktops
|| target
== DESKTOP_ALL
);
1714 old
= self
->desktop
;
1715 self
->desktop
= target
;
1716 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, target
);
1717 /* the frame can display the current desktop state */
1718 engine_frame_adjust_state(self
->frame
);
1719 /* 'move' the window to the new desktop */
1720 client_showhide(self
);
1721 screen_update_struts();
1723 /* update the focus lists */
1724 if (old
== DESKTOP_ALL
) {
1725 for (i
= 0; i
< screen_num_desktops
; ++i
)
1726 focus_order
[i
] = g_list_remove(focus_order
[i
], self
);
1727 focus_order
[target
] = g_list_prepend(focus_order
[target
], self
);
1729 focus_order
[old
] = g_list_remove(focus_order
[old
], self
);
1730 if (target
== DESKTOP_ALL
)
1731 for (i
= 0; i
< screen_num_desktops
; ++i
)
1732 focus_order
[i
] = g_list_prepend(focus_order
[i
], self
);
1735 dispatch_client(Event_Client_Desktop
, self
, target
, old
);
1738 static Client
*search_modal_tree(Client
*node
, Client
*skip
)
1743 for (it
= node
->transients
; it
!= NULL
; it
= it
->next
) {
1744 Client
*c
= it
->data
;
1745 if (c
== skip
) continue; /* circular? */
1746 if ((ret
= search_modal_tree(c
, skip
))) return ret
;
1747 if (c
->modal
) return c
;
1752 Client
*client_find_modal_child(Client
*self
)
1754 return search_modal_tree(self
, self
);
1757 gboolean
client_validate(Client
*self
)
1761 XSync(ob_display
, FALSE
); /* get all events on the server */
1763 if (XCheckTypedWindowEvent(ob_display
, self
->window
, DestroyNotify
, &e
) ||
1764 XCheckTypedWindowEvent(ob_display
, self
->window
, UnmapNotify
, &e
)) {
1765 XPutBackEvent(ob_display
, &e
);
1772 void client_set_wm_state(Client
*self
, long state
)
1774 if (state
== self
->wmstate
) return; /* no change */
1778 client_iconify(self
, TRUE
, TRUE
);
1781 client_iconify(self
, FALSE
, TRUE
);
1786 void client_set_state(Client
*self
, Atom action
, long data1
, long data2
)
1788 gboolean shaded
= self
->shaded
;
1789 gboolean fullscreen
= self
->fullscreen
;
1790 gboolean max_horz
= self
->max_horz
;
1791 gboolean max_vert
= self
->max_vert
;
1794 if (!(action
== prop_atoms
.net_wm_state_add
||
1795 action
== prop_atoms
.net_wm_state_remove
||
1796 action
== prop_atoms
.net_wm_state_toggle
))
1797 /* an invalid action was passed to the client message, ignore it */
1800 for (i
= 0; i
< 2; ++i
) {
1801 Atom state
= i
== 0 ? data1
: data2
;
1803 if (!state
) continue;
1805 /* if toggling, then pick whether we're adding or removing */
1806 if (action
== prop_atoms
.net_wm_state_toggle
) {
1807 if (state
== prop_atoms
.net_wm_state_modal
)
1808 action
= self
->modal
? prop_atoms
.net_wm_state_remove
:
1809 prop_atoms
.net_wm_state_add
;
1810 else if (state
== prop_atoms
.net_wm_state_maximized_vert
)
1811 action
= self
->max_vert
? prop_atoms
.net_wm_state_remove
:
1812 prop_atoms
.net_wm_state_add
;
1813 else if (state
== prop_atoms
.net_wm_state_maximized_horz
)
1814 action
= self
->max_horz
? prop_atoms
.net_wm_state_remove
:
1815 prop_atoms
.net_wm_state_add
;
1816 else if (state
== prop_atoms
.net_wm_state_shaded
)
1817 action
= self
->shaded
? prop_atoms
.net_wm_state_remove
:
1818 prop_atoms
.net_wm_state_add
;
1819 else if (state
== prop_atoms
.net_wm_state_skip_taskbar
)
1820 action
= self
->skip_taskbar
?
1821 prop_atoms
.net_wm_state_remove
:
1822 prop_atoms
.net_wm_state_add
;
1823 else if (state
== prop_atoms
.net_wm_state_skip_pager
)
1824 action
= self
->skip_pager
?
1825 prop_atoms
.net_wm_state_remove
:
1826 prop_atoms
.net_wm_state_add
;
1827 else if (state
== prop_atoms
.net_wm_state_fullscreen
)
1828 action
= self
->fullscreen
?
1829 prop_atoms
.net_wm_state_remove
:
1830 prop_atoms
.net_wm_state_add
;
1831 else if (state
== prop_atoms
.net_wm_state_above
)
1832 action
= self
->above
? prop_atoms
.net_wm_state_remove
:
1833 prop_atoms
.net_wm_state_add
;
1834 else if (state
== prop_atoms
.net_wm_state_below
)
1835 action
= self
->below
? prop_atoms
.net_wm_state_remove
:
1836 prop_atoms
.net_wm_state_add
;
1839 if (action
== prop_atoms
.net_wm_state_add
) {
1840 if (state
== prop_atoms
.net_wm_state_modal
) {
1841 /* XXX raise here or something? */
1843 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
1845 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
1847 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
1849 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
1850 self
->skip_taskbar
= TRUE
;
1851 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
1852 self
->skip_pager
= TRUE
;
1853 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
1855 } else if (state
== prop_atoms
.net_wm_state_above
) {
1857 } else if (state
== prop_atoms
.net_wm_state_below
) {
1861 } else { /* action == prop_atoms.net_wm_state_remove */
1862 if (state
== prop_atoms
.net_wm_state_modal
) {
1863 self
->modal
= FALSE
;
1864 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
1866 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
1868 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
1870 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
1871 self
->skip_taskbar
= FALSE
;
1872 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
1873 self
->skip_pager
= FALSE
;
1874 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
1876 } else if (state
== prop_atoms
.net_wm_state_above
) {
1877 self
->above
= FALSE
;
1878 } else if (state
== prop_atoms
.net_wm_state_below
) {
1879 self
->below
= FALSE
;
1883 if (max_horz
!= self
->max_horz
|| max_vert
!= self
->max_vert
) {
1884 if (max_horz
!= self
->max_horz
&& max_vert
!= self
->max_vert
) {
1886 if (max_horz
== max_vert
) { /* both going the same way */
1887 client_maximize(self
, max_horz
, 0, TRUE
);
1889 client_maximize(self
, max_horz
, 1, TRUE
);
1890 client_maximize(self
, max_vert
, 2, TRUE
);
1894 if (max_horz
!= self
->max_horz
)
1895 client_maximize(self
, max_horz
, 1, TRUE
);
1897 client_maximize(self
, max_vert
, 2, TRUE
);
1900 /* change fullscreen state before shading, as it will affect if the window
1902 if (fullscreen
!= self
->fullscreen
)
1903 client_fullscreen(self
, fullscreen
, TRUE
);
1904 if (shaded
!= self
->shaded
)
1905 client_shade(self
, shaded
);
1906 client_calc_layer(self
);
1907 client_change_state(self
); /* change the hint to relect these changes */
1910 gboolean
client_focus(Client
*self
)
1915 /* if we have a modal child, then focus it, not us */
1916 child
= client_find_modal_child(self
);
1918 return client_focus(child
);
1920 /* won't try focus if the client doesn't want it, or if the window isn't
1921 visible on the screen */
1922 if (!(self
->frame
->visible
&&
1923 (self
->can_focus
|| self
->focus_notify
)))
1926 /* do a check to see if the window has already been unmapped or destroyed
1927 do this intelligently while watching out for unmaps we've generated
1928 (ignore_unmaps > 0) */
1929 if (XCheckTypedWindowEvent(ob_display
, self
->window
,
1930 DestroyNotify
, &ev
)) {
1931 XPutBackEvent(ob_display
, &ev
);
1934 while (XCheckTypedWindowEvent(ob_display
, self
->window
,
1935 UnmapNotify
, &ev
)) {
1936 if (self
->ignore_unmaps
) {
1937 self
->ignore_unmaps
--;
1939 XPutBackEvent(ob_display
, &ev
);
1944 if (self
->can_focus
)
1945 /* RevertToNone is used so that windows dont get focused inadvertantly
1946 by having the pointer in them, and then FocusIn events go missing */
1947 XSetInputFocus(ob_display
, self
->window
, RevertToNone
,
1950 if (self
->focus_notify
) {
1952 ce
.xclient
.type
= ClientMessage
;
1953 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
1954 ce
.xclient
.display
= ob_display
;
1955 ce
.xclient
.window
= self
->window
;
1956 ce
.xclient
.format
= 32;
1957 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_take_focus
;
1958 ce
.xclient
.data
.l
[1] = event_lasttime
;
1959 ce
.xclient
.data
.l
[2] = 0l;
1960 ce
.xclient
.data
.l
[3] = 0l;
1961 ce
.xclient
.data
.l
[4] = 0l;
1962 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
1965 g_message("focusing %lx", self
->window
);
1967 /* Cause the FocusIn to come back to us. Important for desktop switches,
1968 since otherwise we'll have no FocusIn on the queue and send it off to
1969 the focus_backup. */
1970 XSync(ob_display
, FALSE
);
1974 void client_unfocus(Client
*self
)
1976 g_assert(focus_client
== self
);
1977 focus_fallback(FALSE
);
1980 gboolean
client_focused(Client
*self
)
1982 return self
== focus_client
;
1985 Icon
*client_icon(Client
*self
, int w
, int h
)
1988 /* si is the smallest image >= req */
1989 /* li is the largest image < req */
1990 unsigned long size
, smallest
= 0xffffffff, largest
= 0, si
= 0, li
= 0;
1992 if (!self
->nicons
) return NULL
;
1994 for (i
= 0; i
< self
->nicons
; ++i
) {
1995 size
= self
->icons
[i
].width
* self
->icons
[i
].height
;
1996 if (size
< smallest
&& size
>= (unsigned)(w
* h
)) {
2000 if (size
> largest
&& size
<= (unsigned)(w
* h
)) {
2005 if (largest
== 0) /* didnt find one smaller than the requested size */
2006 return &self
->icons
[si
];
2007 return &self
->icons
[li
];