7 #include "moveresize.h"
9 #include "extensions.h"
23 #include "render/render.h"
26 #include <X11/Xutil.h>
28 /*! The event mask to grab on client windows */
29 #define CLIENT_EVENTMASK (PropertyChangeMask | FocusChangeMask | \
32 #define CLIENT_NOPROPAGATEMASK (ButtonPressMask | ButtonReleaseMask | \
35 GList
*client_list
= NULL
;
37 static void client_get_all(ObClient
*self
);
38 static void client_toggle_border(ObClient
*self
, gboolean show
);
39 static void client_get_area(ObClient
*self
);
40 static void client_get_desktop(ObClient
*self
);
41 static void client_get_state(ObClient
*self
);
42 static void client_get_shaped(ObClient
*self
);
43 static void client_get_mwm_hints(ObClient
*self
);
44 static void client_get_gravity(ObClient
*self
);
45 static void client_showhide(ObClient
*self
);
46 static void client_change_allowed_actions(ObClient
*self
);
47 static void client_change_state(ObClient
*self
);
48 static void client_apply_startup_state(ObClient
*self
);
49 static void client_restore_session_state(ObClient
*self
);
56 void client_shutdown()
60 void client_set_list()
62 Window
*windows
, *win_it
;
64 guint size
= g_list_length(client_list
);
66 /* create an array of the window ids */
68 windows
= g_new(Window
, size
);
70 for (it
= client_list
; it
!= NULL
; it
= it
->next
, ++win_it
)
71 *win_it
= ((ObClient
*)it
->data
)->window
;
75 PROP_SETA32(RootWindow(ob_display
, ob_screen
),
76 net_client_list
, window
, (guint32
*)windows
, size
);
85 void client_foreach_transient(ObClient *self, ObClientForeachFunc func, void *data)
89 for (it = self->transients; it; it = it->next) {
90 if (!func(it->data, data)) return;
91 client_foreach_transient(it->data, func, data);
95 void client_foreach_ancestor(ObClient *self, ObClientForeachFunc func, void *data)
97 if (self->transient_for) {
98 if (self->transient_for != OB_TRAN_GROUP) {
99 if (!func(self->transient_for, data)) return;
100 client_foreach_ancestor(self->transient_for, func, data);
104 for (it = self->group->members; it; it = it->next)
105 if (it->data != self &&
106 !((ObClient*)it->data)->transient_for) {
107 if (!func(it->data, data)) return;
108 client_foreach_ancestor(it->data, func, data);
115 void client_manage_all()
117 unsigned int i
, j
, nchild
;
120 XWindowAttributes attrib
;
122 XQueryTree(ob_display
, RootWindow(ob_display
, ob_screen
),
123 &w
, &w
, &children
, &nchild
);
125 /* remove all icon windows from the list */
126 for (i
= 0; i
< nchild
; i
++) {
127 if (children
[i
] == None
) continue;
128 wmhints
= XGetWMHints(ob_display
, children
[i
]);
130 if ((wmhints
->flags
& IconWindowHint
) &&
131 (wmhints
->icon_window
!= children
[i
]))
132 for (j
= 0; j
< nchild
; j
++)
133 if (children
[j
] == wmhints
->icon_window
) {
141 for (i
= 0; i
< nchild
; ++i
) {
142 if (children
[i
] == None
)
144 if (XGetWindowAttributes(ob_display
, children
[i
], &attrib
)) {
145 if (attrib
.override_redirect
) continue;
147 if (attrib
.map_state
!= IsUnmapped
)
148 client_manage(children
[i
]);
153 /* stack them as they were on startup!
154 why with stacking_lower? Why, because then windows who aren't in the
155 stacking list are on the top where you can see them instead of buried
157 for (i
= startup_stack_size
; i
> 0; --i
) {
160 w
= startup_stack_order
[i
-1];
161 obw
= g_hash_table_lookup(window_map
, &w
);
163 g_assert(WINDOW_IS_CLIENT(obw
));
164 stacking_lower(CLIENT_AS_WINDOW(obw
));
167 g_free(startup_stack_order
);
168 startup_stack_order
= NULL
;
169 startup_stack_size
= 0;
171 if (config_focus_new
) {
174 active
= g_hash_table_lookup(window_map
, &startup_active
);
176 g_assert(WINDOW_IS_CLIENT(active
));
177 if (!client_focus(WINDOW_AS_CLIENT(active
)))
178 focus_fallback(OB_FOCUS_FALLBACK_NOFOCUS
);
180 focus_fallback(OB_FOCUS_FALLBACK_NOFOCUS
);
184 void client_manage(Window window
)
188 XWindowAttributes attrib
;
189 XSetWindowAttributes attrib_set
;
191 gboolean activate
= FALSE
;
195 /* check if it has already been unmapped by the time we started mapping
196 the grab does a sync so we don't have to here */
197 if (XCheckTypedWindowEvent(ob_display
, window
, DestroyNotify
, &e
) ||
198 XCheckTypedWindowEvent(ob_display
, window
, UnmapNotify
, &e
)) {
199 XPutBackEvent(ob_display
, &e
);
202 return; /* don't manage it */
205 /* make sure it isn't an override-redirect window */
206 if (!XGetWindowAttributes(ob_display
, window
, &attrib
) ||
207 attrib
.override_redirect
) {
209 return; /* don't manage it */
212 /* is the window a docking app */
213 if ((wmhint
= XGetWMHints(ob_display
, window
))) {
214 if ((wmhint
->flags
& StateHint
) &&
215 wmhint
->initial_state
== WithdrawnState
) {
216 dock_add(window
, wmhint
);
224 ob_debug("Managing window: %lx\n", window
);
226 /* choose the events we want to receive on the CLIENT window */
227 attrib_set
.event_mask
= CLIENT_EVENTMASK
;
228 attrib_set
.do_not_propagate_mask
= CLIENT_NOPROPAGATEMASK
;
229 XChangeWindowAttributes(ob_display
, window
,
230 CWEventMask
|CWDontPropagate
, &attrib_set
);
233 /* create the ObClient struct, and populate it from the hints on the
235 self
= g_new(ObClient
, 1);
236 self
->obwin
.type
= Window_Client
;
237 self
->window
= window
;
239 client_get_all(self
);
240 client_restore_session_state(self
);
242 client_change_state(self
);
244 /* remove the client's border (and adjust re gravity) */
245 client_toggle_border(self
, FALSE
);
247 /* specify that if we exit, the window should not be destroyed and should
248 be reparented back to root automatically */
249 XChangeSaveSet(ob_display
, window
, SetModeInsert
);
251 /* create the decoration frame for the client window */
252 self
->frame
= frame_new();
254 frame_grab_client(self
->frame
, self
);
256 client_apply_startup_state(self
);
260 /* update the focus lists */
261 focus_order_add_new(self
);
263 stacking_add(CLIENT_AS_WINDOW(self
));
265 /* focus the new window? */
266 if (ob_state() != OB_STATE_STARTING
&& config_focus_new
&&
267 /* note the check against Type_Normal/Dialog, not client_normal(self),
268 which would also include other types. in this case we want more
269 strict rules for focus */
270 (self
->type
== OB_CLIENT_TYPE_NORMAL
||
271 self
->type
== OB_CLIENT_TYPE_DIALOG
))
273 if (self
->desktop
!= screen_desktop
) {
274 /* activate the window */
277 gboolean group_foc
= FALSE
;
282 for (it
= self
->group
->members
; it
; it
= it
->next
)
284 if (client_focused(it
->data
))
292 (!self
->transient_for
&& (!self
->group
||
293 !self
->group
->members
->next
))) ||
294 client_search_focus_tree_full(self
) ||
296 !client_normal(focus_client
))
298 /* activate the window */
304 dispatch_client(Event_Client_New
, self
, 0, 0);
306 /* make sure the window is visible */
307 if (ob_state() == OB_STATE_RUNNING
)
308 client_move_onscreen(self
, TRUE
);
310 screen_update_areas();
312 client_showhide(self
);
314 /* use client_focus instead of client_activate cuz client_activate does
315 stuff like switch desktops etc and I'm not interested in all that when
316 a window maps since its not based on an action from the user like
317 clicking a window to activate is. so keep the new window out of the way
319 if (activate
) client_focus(self
);
321 /* client_activate does this but we aret using it so we have to do it
323 if (screen_showing_desktop
)
324 screen_show_desktop(FALSE
);
326 /* add to client list/map */
327 client_list
= g_list_append(client_list
, self
);
328 g_hash_table_insert(window_map
, &self
->window
, self
);
330 /* update the list hints */
333 keyboard_grab_for_client(self
, TRUE
);
334 mouse_grab_for_client(self
, TRUE
);
336 dispatch_client(Event_Client_Mapped
, self
, 0, 0);
338 ob_debug("Managed window 0x%lx (%s)\n", window
, self
->class);
341 void client_unmanage_all()
343 while (client_list
!= NULL
)
344 client_unmanage(client_list
->data
);
347 /* called by client_unmanage() to close any menus referencing this client */
348 void client_close_menus(gpointer key
, gpointer value
, gpointer self
)
350 if (((ObMenu
*)value
)->client
== (ObClient
*)self
)
351 menu_hide((ObMenu
*)value
);
354 void client_unmanage(ObClient
*self
)
359 ob_debug("Unmanaging window: %lx (%s)\n", self
->window
, self
->class);
361 dispatch_client(Event_Client_Destroy
, self
, 0, 0);
362 g_assert(self
!= NULL
);
364 keyboard_grab_for_client(self
, FALSE
);
365 mouse_grab_for_client(self
, FALSE
);
367 /* remove the window from our save set */
368 XChangeSaveSet(ob_display
, self
->window
, SetModeDelete
);
370 /* we dont want events no more */
371 XSelectInput(ob_display
, self
->window
, NoEventMask
);
373 frame_hide(self
->frame
);
375 client_list
= g_list_remove(client_list
, self
);
376 stacking_remove(self
);
377 g_hash_table_remove(window_map
, &self
->window
);
379 /* update the focus lists */
380 focus_order_remove(self
);
382 /* once the client is out of the list, update the struts to remove it's
384 screen_update_areas();
386 /* tell our parent(s) that we're gone */
387 if (self
->transient_for
== OB_TRAN_GROUP
) { /* transient of group */
390 for (it
= self
->group
->members
; it
; it
= it
->next
)
391 if (it
->data
!= self
)
392 ((ObClient
*)it
->data
)->transients
=
393 g_slist_remove(((ObClient
*)it
->data
)->transients
, self
);
394 } else if (self
->transient_for
) { /* transient of window */
395 self
->transient_for
->transients
=
396 g_slist_remove(self
->transient_for
->transients
, self
);
399 /* tell our transients that we're gone */
400 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
) {
401 if (((ObClient
*)it
->data
)->transient_for
!= OB_TRAN_GROUP
) {
402 ((ObClient
*)it
->data
)->transient_for
= NULL
;
403 client_calc_layer(it
->data
);
407 if (moveresize_client
== self
)
408 moveresize_end(TRUE
);
410 /* close any windows that are attached to this window */
411 g_hash_table_foreach(menu_hash
, client_close_menus
, self
);
414 if (focus_client
== self
) {
417 /* focus the last focused window on the desktop, and ignore enter
418 events from the unmap so it doesnt mess with the focus */
419 while (XCheckTypedEvent(ob_display
, EnterNotify
, &e
));
420 client_unfocus(self
);
423 /* remove from its group */
425 group_remove(self
->group
, self
);
429 /* dispatch the unmapped event */
430 dispatch_client(Event_Client_Unmapped
, self
, 0, 0);
431 g_assert(self
!= NULL
);
433 /* give the client its border back */
434 client_toggle_border(self
, TRUE
);
436 /* reparent the window out of the frame, and free the frame */
437 frame_release_client(self
->frame
, self
);
440 if (ob_state() != OB_STATE_EXITING
) {
441 /* these values should not be persisted across a window
443 PROP_ERASE(self
->window
, net_wm_desktop
);
444 PROP_ERASE(self
->window
, net_wm_state
);
445 PROP_ERASE(self
->window
, wm_state
);
447 /* if we're left in an iconic state, the client wont be mapped. this is
448 bad, since we will no longer be managing the window on restart */
450 XMapWindow(ob_display
, self
->window
);
454 ob_debug("Unmanaged window 0x%lx\n", self
->window
);
456 /* free all data allocated in the client struct */
457 g_slist_free(self
->transients
);
458 for (j
= 0; j
< self
->nicons
; ++j
)
459 g_free(self
->icons
[j
].data
);
460 if (self
->nicons
> 0)
463 g_free(self
->icon_title
);
469 /* update the list hints */
473 static void client_restore_session_state(ObClient
*self
)
477 s
= session_state_find(self
);
480 RECT_SET(self
->area
, s
->x
, s
->y
, s
->w
, s
->h
);
481 self
->positioned
= TRUE
;
482 XResizeWindow(ob_display
, self
->window
, s
->w
, s
->h
);
484 self
->desktop
= s
->desktop
== DESKTOP_ALL
? s
->desktop
:
485 MIN(screen_num_desktops
- 1, s
->desktop
);
486 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, self
->desktop
);
488 self
->shaded
= s
->shaded
;
489 self
->iconic
= s
->iconic
;
490 self
->skip_pager
= s
->skip_pager
;
491 self
->skip_taskbar
= s
->skip_taskbar
;
492 self
->fullscreen
= s
->fullscreen
;
493 self
->above
= s
->above
;
494 self
->below
= s
->below
;
495 self
->max_horz
= s
->max_horz
;
496 self
->max_vert
= s
->max_vert
;
498 session_state_free(s
);
501 void client_move_onscreen(ObClient
*self
, gboolean rude
)
503 int x
= self
->area
.x
;
504 int y
= self
->area
.y
;
505 if (client_find_onscreen(self
, &x
, &y
,
506 self
->frame
->area
.width
,
507 self
->frame
->area
.height
, rude
)) {
508 client_configure(self
, OB_CORNER_TOPLEFT
, x
, y
,
509 self
->area
.width
, self
->area
.height
,
514 gboolean
client_find_onscreen(ObClient
*self
, int *x
, int *y
, int w
, int h
,
518 int ox
= *x
, oy
= *y
;
520 frame_client_gravity(self
->frame
, x
, y
); /* get where the frame
523 /* XXX watch for xinerama dead areas */
525 a
= screen_area(self
->desktop
);
526 if (!self
->strut
.right
&& *x
>= a
->x
+ a
->width
- 1)
527 *x
= a
->x
+ a
->width
- self
->frame
->area
.width
;
528 if (!self
->strut
.bottom
&& *y
>= a
->y
+ a
->height
- 1)
529 *y
= a
->y
+ a
->height
- self
->frame
->area
.height
;
530 if (!self
->strut
.left
&& *x
+ self
->frame
->area
.width
- 1 < a
->x
)
532 if (!self
->strut
.top
&& *y
+ self
->frame
->area
.height
- 1 < a
->y
)
536 /* this is my MOZILLA BITCHSLAP. oh ya it fucking feels good.
537 Java can suck it too. */
539 /* dont let windows map/move into the strut unless they
540 are bigger than the available area */
542 if (!self
->strut
.left
&& *x
< a
->x
) *x
= a
->x
;
543 if (!self
->strut
.right
&& *x
+ w
> a
->x
+ a
->width
)
544 *x
= a
->x
+ a
->width
- w
;
546 if (h
<= a
->height
) {
547 if (!self
->strut
.top
&& *y
< a
->y
) *y
= a
->y
;
548 if (!self
->strut
.bottom
&& *y
+ h
> a
->y
+ a
->height
)
549 *y
= a
->y
+ a
->height
- h
;
553 frame_frame_gravity(self
->frame
, x
, y
); /* get where the client
556 return ox
!= *x
|| oy
!= *y
;
559 static void client_toggle_border(ObClient
*self
, gboolean show
)
561 /* adjust our idea of where the client is, based on its border. When the
562 border is removed, the client should now be considered to be in a
564 when re-adding the border to the client, the same operation needs to be
566 int oldx
= self
->area
.x
, oldy
= self
->area
.y
;
567 int x
= oldx
, y
= oldy
;
568 switch(self
->gravity
) {
570 case NorthWestGravity
:
572 case SouthWestGravity
:
574 case NorthEastGravity
:
576 case SouthEastGravity
:
577 if (show
) x
-= self
->border_width
* 2;
578 else x
+= self
->border_width
* 2;
585 if (show
) x
-= self
->border_width
;
586 else x
+= self
->border_width
;
589 switch(self
->gravity
) {
591 case NorthWestGravity
:
593 case NorthEastGravity
:
595 case SouthWestGravity
:
597 case SouthEastGravity
:
598 if (show
) y
-= self
->border_width
* 2;
599 else y
+= self
->border_width
* 2;
606 if (show
) y
-= self
->border_width
;
607 else y
+= self
->border_width
;
614 XSetWindowBorderWidth(ob_display
, self
->window
, self
->border_width
);
616 /* move the client so it is back it the right spot _with_ its
618 if (x
!= oldx
|| y
!= oldy
)
619 XMoveWindow(ob_display
, self
->window
, x
, y
);
621 XSetWindowBorderWidth(ob_display
, self
->window
, 0);
625 static void client_get_all(ObClient
*self
)
627 /* update EVERYTHING!! */
629 self
->ignore_unmaps
= 0;
633 self
->title
= self
->icon_title
= NULL
;
634 self
->title_count
= 1;
635 self
->name
= self
->class = self
->role
= NULL
;
636 self
->wmstate
= NormalState
;
637 self
->transient
= FALSE
;
638 self
->transients
= NULL
;
639 self
->transient_for
= NULL
;
641 self
->urgent
= FALSE
;
642 self
->positioned
= FALSE
;
643 self
->decorate
= TRUE
;
647 client_get_area(self
);
648 client_update_transient_for(self
);
649 client_update_wmhints(self
);
650 client_get_desktop(self
);
651 client_get_state(self
);
652 client_get_shaped(self
);
654 client_get_mwm_hints(self
);
655 client_get_type(self
);/* this can change the mwmhints for special cases */
657 client_update_protocols(self
);
659 client_get_gravity(self
); /* get the attribute gravity */
660 client_update_normal_hints(self
); /* this may override the attribute
663 /* got the type, the mwmhints, the protocols, and the normal hints
664 (min/max sizes), so we're ready to set up the decorations/functions */
665 client_setup_decor_and_functions(self
);
667 client_update_title(self
);
668 client_update_class(self
);
669 client_update_strut(self
);
670 client_update_icons(self
);
673 static void client_get_area(ObClient
*self
)
675 XWindowAttributes wattrib
;
678 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
679 g_assert(ret
!= BadWindow
);
681 RECT_SET(self
->area
, wattrib
.x
, wattrib
.y
, wattrib
.width
, wattrib
.height
);
682 self
->border_width
= wattrib
.border_width
;
685 static void client_get_desktop(ObClient
*self
)
687 guint32 d
= screen_num_desktops
; /* an always-invalid value */
689 if (PROP_GET32(self
->window
, net_wm_desktop
, cardinal
, &d
)) {
690 if (d
>= screen_num_desktops
&& d
!= DESKTOP_ALL
)
691 self
->desktop
= screen_num_desktops
- 1;
695 gboolean trdesk
= FALSE
;
697 if (self
->transient_for
) {
698 if (self
->transient_for
!= OB_TRAN_GROUP
) {
699 self
->desktop
= self
->transient_for
->desktop
;
704 for (it
= self
->group
->members
; it
; it
= it
->next
)
705 if (it
->data
!= self
&&
706 !((ObClient
*)it
->data
)->transient_for
) {
707 self
->desktop
= ((ObClient
*)it
->data
)->desktop
;
714 /* defaults to the current desktop */
715 self
->desktop
= screen_desktop
;
717 if (self
->desktop
!= d
) {
718 /* set the desktop hint, to make sure that it always exists */
719 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, self
->desktop
);
723 static void client_get_state(ObClient
*self
)
728 self
->modal
= self
->shaded
= self
->max_horz
= self
->max_vert
=
729 self
->fullscreen
= self
->above
= self
->below
= self
->iconic
=
730 self
->skip_taskbar
= self
->skip_pager
= FALSE
;
732 if (PROP_GETA32(self
->window
, net_wm_state
, atom
, &state
, &num
)) {
734 for (i
= 0; i
< num
; ++i
) {
735 if (state
[i
] == prop_atoms
.net_wm_state_modal
)
737 else if (state
[i
] == prop_atoms
.net_wm_state_shaded
)
739 else if (state
[i
] == prop_atoms
.net_wm_state_hidden
)
741 else if (state
[i
] == prop_atoms
.net_wm_state_skip_taskbar
)
742 self
->skip_taskbar
= TRUE
;
743 else if (state
[i
] == prop_atoms
.net_wm_state_skip_pager
)
744 self
->skip_pager
= TRUE
;
745 else if (state
[i
] == prop_atoms
.net_wm_state_fullscreen
)
746 self
->fullscreen
= TRUE
;
747 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_vert
)
748 self
->max_vert
= TRUE
;
749 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_horz
)
750 self
->max_horz
= TRUE
;
751 else if (state
[i
] == prop_atoms
.net_wm_state_above
)
753 else if (state
[i
] == prop_atoms
.net_wm_state_below
)
761 static void client_get_shaped(ObClient
*self
)
763 self
->shaped
= FALSE
;
765 if (extensions_shape
) {
770 XShapeSelectInput(ob_display
, self
->window
, ShapeNotifyMask
);
772 XShapeQueryExtents(ob_display
, self
->window
, &s
, &foo
,
773 &foo
, &ufoo
, &ufoo
, &foo
, &foo
, &foo
, &ufoo
,
775 self
->shaped
= (s
!= 0);
780 void client_update_transient_for(ObClient
*self
)
783 ObClient
*target
= NULL
;
785 if (XGetTransientForHint(ob_display
, self
->window
, &t
)) {
786 self
->transient
= TRUE
;
787 if (t
!= self
->window
) { /* cant be transient to itself! */
788 target
= g_hash_table_lookup(window_map
, &t
);
789 /* if this happens then we need to check for it*/
790 g_assert(target
!= self
);
791 g_assert(!target
|| WINDOW_IS_CLIENT(target
));
793 if (!target
&& self
->group
) {
794 /* not transient to a client, see if it is transient for a
796 if (t
== self
->group
->leader
||
798 t
== RootWindow(ob_display
, ob_screen
)) {
799 /* window is a transient for its group! */
800 target
= OB_TRAN_GROUP
;
805 self
->transient
= FALSE
;
807 /* if anything has changed... */
808 if (target
!= self
->transient_for
) {
809 if (self
->transient_for
== OB_TRAN_GROUP
) { /* transient of group */
812 /* remove from old parents */
813 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
814 ObClient
*c
= it
->data
;
815 if (c
!= self
&& !c
->transient_for
)
816 c
->transients
= g_slist_remove(c
->transients
, self
);
818 } else if (self
->transient_for
!= NULL
) { /* transient of window */
819 /* remove from old parent */
820 self
->transient_for
->transients
=
821 g_slist_remove(self
->transient_for
->transients
, self
);
823 self
->transient_for
= target
;
824 if (self
->transient_for
== OB_TRAN_GROUP
) { /* transient of group */
827 /* add to new parents */
828 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
829 ObClient
*c
= it
->data
;
830 if (c
!= self
&& !c
->transient_for
)
831 c
->transients
= g_slist_append(c
->transients
, self
);
834 /* remove all transients which are in the group, that causes
835 circlular pointer hell of doom */
836 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
838 for (sit
= self
->transients
; sit
; sit
= next
) {
839 next
= g_slist_next(sit
);
840 if (sit
->data
== it
->data
)
842 g_slist_delete_link(self
->transients
, sit
);
845 } else if (self
->transient_for
!= NULL
) { /* transient of window */
846 /* add to new parent */
847 self
->transient_for
->transients
=
848 g_slist_append(self
->transient_for
->transients
, self
);
853 static void client_get_mwm_hints(ObClient
*self
)
858 self
->mwmhints
.flags
= 0; /* default to none */
860 if (PROP_GETA32(self
->window
, motif_wm_hints
, motif_wm_hints
,
862 if (num
>= OB_MWM_ELEMENTS
) {
863 self
->mwmhints
.flags
= hints
[0];
864 self
->mwmhints
.functions
= hints
[1];
865 self
->mwmhints
.decorations
= hints
[2];
871 void client_get_type(ObClient
*self
)
878 if (PROP_GETA32(self
->window
, net_wm_window_type
, atom
, &val
, &num
)) {
879 /* use the first value that we know about in the array */
880 for (i
= 0; i
< num
; ++i
) {
881 if (val
[i
] == prop_atoms
.net_wm_window_type_desktop
)
882 self
->type
= OB_CLIENT_TYPE_DESKTOP
;
883 else if (val
[i
] == prop_atoms
.net_wm_window_type_dock
)
884 self
->type
= OB_CLIENT_TYPE_DOCK
;
885 else if (val
[i
] == prop_atoms
.net_wm_window_type_toolbar
)
886 self
->type
= OB_CLIENT_TYPE_TOOLBAR
;
887 else if (val
[i
] == prop_atoms
.net_wm_window_type_menu
)
888 self
->type
= OB_CLIENT_TYPE_MENU
;
889 else if (val
[i
] == prop_atoms
.net_wm_window_type_utility
)
890 self
->type
= OB_CLIENT_TYPE_UTILITY
;
891 else if (val
[i
] == prop_atoms
.net_wm_window_type_splash
)
892 self
->type
= OB_CLIENT_TYPE_SPLASH
;
893 else if (val
[i
] == prop_atoms
.net_wm_window_type_dialog
)
894 self
->type
= OB_CLIENT_TYPE_DIALOG
;
895 else if (val
[i
] == prop_atoms
.net_wm_window_type_normal
)
896 self
->type
= OB_CLIENT_TYPE_NORMAL
;
897 else if (val
[i
] == prop_atoms
.kde_net_wm_window_type_override
) {
898 /* prevent this window from getting any decor or
900 self
->mwmhints
.flags
&= (OB_MWM_FLAG_FUNCTIONS
|
901 OB_MWM_FLAG_DECORATIONS
);
902 self
->mwmhints
.decorations
= 0;
903 self
->mwmhints
.functions
= 0;
905 if (self
->type
!= (ObClientType
) -1)
906 break; /* grab the first legit type */
911 if (self
->type
== (ObClientType
) -1) {
912 /*the window type hint was not set, which means we either classify
913 ourself as a normal window or a dialog, depending on if we are a
916 self
->type
= OB_CLIENT_TYPE_DIALOG
;
918 self
->type
= OB_CLIENT_TYPE_NORMAL
;
922 void client_update_protocols(ObClient
*self
)
927 self
->focus_notify
= FALSE
;
928 self
->delete_window
= FALSE
;
930 if (PROP_GETA32(self
->window
, wm_protocols
, atom
, &proto
, &num_return
)) {
931 for (i
= 0; i
< num_return
; ++i
) {
932 if (proto
[i
] == prop_atoms
.wm_delete_window
) {
933 /* this means we can request the window to close */
934 self
->delete_window
= TRUE
;
935 } else if (proto
[i
] == prop_atoms
.wm_take_focus
)
936 /* if this protocol is requested, then the window will be
937 notified whenever we want it to receive focus */
938 self
->focus_notify
= TRUE
;
944 static void client_get_gravity(ObClient
*self
)
946 XWindowAttributes wattrib
;
949 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
950 g_assert(ret
!= BadWindow
);
951 self
->gravity
= wattrib
.win_gravity
;
954 void client_update_normal_hints(ObClient
*self
)
958 int oldgravity
= self
->gravity
;
961 self
->min_ratio
= 0.0f
;
962 self
->max_ratio
= 0.0f
;
963 SIZE_SET(self
->size_inc
, 1, 1);
964 SIZE_SET(self
->base_size
, 0, 0);
965 SIZE_SET(self
->min_size
, 0, 0);
966 SIZE_SET(self
->max_size
, G_MAXINT
, G_MAXINT
);
968 /* get the hints from the window */
969 if (XGetWMNormalHints(ob_display
, self
->window
, &size
, &ret
)) {
970 self
->positioned
= !!(size
.flags
& (PPosition
|USPosition
));
972 if (size
.flags
& PWinGravity
) {
973 self
->gravity
= size
.win_gravity
;
975 /* if the client has a frame, i.e. has already been mapped and
976 is changing its gravity */
977 if (self
->frame
&& self
->gravity
!= oldgravity
) {
978 /* move our idea of the client's position based on its new
980 self
->area
.x
= self
->frame
->area
.x
;
981 self
->area
.y
= self
->frame
->area
.y
;
982 frame_frame_gravity(self
->frame
, &self
->area
.x
, &self
->area
.y
);
986 if (size
.flags
& PAspect
) {
987 if (size
.min_aspect
.y
)
988 self
->min_ratio
= (float)size
.min_aspect
.x
/ size
.min_aspect
.y
;
989 if (size
.max_aspect
.y
)
990 self
->max_ratio
= (float)size
.max_aspect
.x
/ size
.max_aspect
.y
;
993 if (size
.flags
& PMinSize
)
994 SIZE_SET(self
->min_size
, size
.min_width
, size
.min_height
);
996 if (size
.flags
& PMaxSize
)
997 SIZE_SET(self
->max_size
, size
.max_width
, size
.max_height
);
999 if (size
.flags
& PBaseSize
)
1000 SIZE_SET(self
->base_size
, size
.base_width
, size
.base_height
);
1002 if (size
.flags
& PResizeInc
)
1003 SIZE_SET(self
->size_inc
, size
.width_inc
, size
.height_inc
);
1007 void client_setup_decor_and_functions(ObClient
*self
)
1009 /* start with everything (cept fullscreen) */
1010 self
->decorations
= (OB_FRAME_DECOR_TITLEBAR
|
1011 OB_FRAME_DECOR_HANDLE
|
1012 OB_FRAME_DECOR_GRIPS
|
1013 OB_FRAME_DECOR_BORDER
|
1014 OB_FRAME_DECOR_ICON
|
1015 OB_FRAME_DECOR_ALLDESKTOPS
|
1016 OB_FRAME_DECOR_ICONIFY
|
1017 OB_FRAME_DECOR_MAXIMIZE
|
1018 OB_FRAME_DECOR_SHADE
);
1019 self
->functions
= (OB_CLIENT_FUNC_RESIZE
|
1020 OB_CLIENT_FUNC_MOVE
|
1021 OB_CLIENT_FUNC_ICONIFY
|
1022 OB_CLIENT_FUNC_MAXIMIZE
|
1023 OB_CLIENT_FUNC_SHADE
);
1024 if (self
->delete_window
) {
1025 self
->functions
|= OB_CLIENT_FUNC_CLOSE
;
1026 self
->decorations
|= OB_FRAME_DECOR_CLOSE
;
1029 if (!(self
->min_size
.width
< self
->max_size
.width
||
1030 self
->min_size
.height
< self
->max_size
.height
))
1031 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
1033 switch (self
->type
) {
1034 case OB_CLIENT_TYPE_NORMAL
:
1035 /* normal windows retain all of the possible decorations and
1036 functionality, and are the only windows that you can fullscreen */
1037 self
->functions
|= OB_CLIENT_FUNC_FULLSCREEN
;
1040 case OB_CLIENT_TYPE_DIALOG
:
1041 case OB_CLIENT_TYPE_UTILITY
:
1042 /* these windows cannot be maximized */
1043 self
->functions
&= ~OB_CLIENT_FUNC_MAXIMIZE
;
1046 case OB_CLIENT_TYPE_MENU
:
1047 case OB_CLIENT_TYPE_TOOLBAR
:
1048 /* these windows get less functionality */
1049 self
->functions
&= ~(OB_CLIENT_FUNC_ICONIFY
| OB_CLIENT_FUNC_RESIZE
);
1052 case OB_CLIENT_TYPE_DESKTOP
:
1053 case OB_CLIENT_TYPE_DOCK
:
1054 case OB_CLIENT_TYPE_SPLASH
:
1055 /* none of these windows are manipulated by the window manager */
1056 self
->decorations
= 0;
1057 self
->functions
= 0;
1061 /* Mwm Hints are applied subtractively to what has already been chosen for
1062 decor and functionality */
1063 if (self
->mwmhints
.flags
& OB_MWM_FLAG_DECORATIONS
) {
1064 if (! (self
->mwmhints
.decorations
& OB_MWM_DECOR_ALL
)) {
1065 if (! ((self
->mwmhints
.decorations
& OB_MWM_DECOR_HANDLE
) ||
1066 (self
->mwmhints
.decorations
& OB_MWM_DECOR_TITLE
)))
1067 /* if the mwm hints request no handle or title, then all
1068 decorations are disabled */
1069 self
->decorations
= 0;
1073 if (self
->mwmhints
.flags
& OB_MWM_FLAG_FUNCTIONS
) {
1074 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_ALL
)) {
1075 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_RESIZE
))
1076 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
1077 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_MOVE
))
1078 self
->functions
&= ~OB_CLIENT_FUNC_MOVE
;
1079 /* dont let mwm hints kill any buttons
1080 if (! (self->mwmhints.functions & OB_MWM_FUNC_ICONIFY))
1081 self->functions &= ~OB_CLIENT_FUNC_ICONIFY;
1082 if (! (self->mwmhints.functions & OB_MWM_FUNC_MAXIMIZE))
1083 self->functions &= ~OB_CLIENT_FUNC_MAXIMIZE;
1085 /* dont let mwm hints kill the close button
1086 if (! (self->mwmhints.functions & MwmFunc_Close))
1087 self->functions &= ~OB_CLIENT_FUNC_CLOSE; */
1091 if (!(self
->functions
& OB_CLIENT_FUNC_SHADE
))
1092 self
->decorations
&= ~OB_FRAME_DECOR_SHADE
;
1093 if (!(self
->functions
& OB_CLIENT_FUNC_ICONIFY
))
1094 self
->decorations
&= ~OB_FRAME_DECOR_ICONIFY
;
1095 if (!(self
->functions
& OB_CLIENT_FUNC_RESIZE
))
1096 self
->decorations
&= ~OB_FRAME_DECOR_GRIPS
;
1098 /* can't maximize without moving/resizing */
1099 if (!((self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) &&
1100 (self
->functions
& OB_CLIENT_FUNC_MOVE
) &&
1101 (self
->functions
& OB_CLIENT_FUNC_RESIZE
))) {
1102 self
->functions
&= ~OB_CLIENT_FUNC_MAXIMIZE
;
1103 self
->decorations
&= ~OB_FRAME_DECOR_MAXIMIZE
;
1106 /* finally, the user can have requested no decorations, which overrides
1108 if (!self
->decorate
)
1109 self
->decorations
= OB_FRAME_DECOR_BORDER
;
1111 /* if we don't have a titlebar, then we cannot shade! */
1112 if (!(self
->decorations
& OB_FRAME_DECOR_TITLEBAR
))
1113 self
->functions
&= ~OB_CLIENT_FUNC_SHADE
;
1115 /* now we need to check against rules for the client's current state */
1116 if (self
->fullscreen
) {
1117 self
->functions
&= (OB_CLIENT_FUNC_CLOSE
|
1118 OB_CLIENT_FUNC_FULLSCREEN
|
1119 OB_CLIENT_FUNC_ICONIFY
);
1120 self
->decorations
= 0;
1123 client_change_allowed_actions(self
);
1126 /* adjust the client's decorations, etc. */
1127 client_reconfigure(self
);
1129 /* this makes sure that these windows appear on all desktops */
1130 if (self
->type
== OB_CLIENT_TYPE_DESKTOP
&&
1131 self
->desktop
!= DESKTOP_ALL
)
1133 self
->desktop
= DESKTOP_ALL
;
1138 static void client_change_allowed_actions(ObClient
*self
)
1143 /* desktop windows are kept on all desktops */
1144 if (self
->type
!= OB_CLIENT_TYPE_DESKTOP
)
1145 actions
[num
++] = prop_atoms
.net_wm_action_change_desktop
;
1147 if (self
->functions
& OB_CLIENT_FUNC_SHADE
)
1148 actions
[num
++] = prop_atoms
.net_wm_action_shade
;
1149 if (self
->functions
& OB_CLIENT_FUNC_CLOSE
)
1150 actions
[num
++] = prop_atoms
.net_wm_action_close
;
1151 if (self
->functions
& OB_CLIENT_FUNC_MOVE
)
1152 actions
[num
++] = prop_atoms
.net_wm_action_move
;
1153 if (self
->functions
& OB_CLIENT_FUNC_ICONIFY
)
1154 actions
[num
++] = prop_atoms
.net_wm_action_minimize
;
1155 if (self
->functions
& OB_CLIENT_FUNC_RESIZE
)
1156 actions
[num
++] = prop_atoms
.net_wm_action_resize
;
1157 if (self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
)
1158 actions
[num
++] = prop_atoms
.net_wm_action_fullscreen
;
1159 if (self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) {
1160 actions
[num
++] = prop_atoms
.net_wm_action_maximize_horz
;
1161 actions
[num
++] = prop_atoms
.net_wm_action_maximize_vert
;
1164 PROP_SETA32(self
->window
, net_wm_allowed_actions
, atom
, actions
, num
);
1166 /* make sure the window isn't breaking any rules now */
1168 if (!(self
->functions
& OB_CLIENT_FUNC_SHADE
) && self
->shaded
) {
1169 if (self
->frame
) client_shade(self
, FALSE
);
1170 else self
->shaded
= FALSE
;
1172 if (!(self
->functions
& OB_CLIENT_FUNC_ICONIFY
) && self
->iconic
) {
1173 if (self
->frame
) client_iconify(self
, FALSE
, TRUE
);
1174 else self
->iconic
= FALSE
;
1176 if (!(self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
) && self
->fullscreen
) {
1177 if (self
->frame
) client_fullscreen(self
, FALSE
, TRUE
);
1178 else self
->fullscreen
= FALSE
;
1180 if (!(self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) && (self
->max_horz
||
1182 if (self
->frame
) client_maximize(self
, FALSE
, 0, TRUE
);
1183 else self
->max_vert
= self
->max_horz
= FALSE
;
1187 void client_reconfigure(ObClient
*self
)
1189 /* by making this pass FALSE for user, we avoid the emacs event storm where
1190 every configurenotify causes an update in its normal hints, i think this
1191 is generally what we want anyways... */
1192 client_configure(self
, OB_CORNER_TOPLEFT
, self
->area
.x
, self
->area
.y
,
1193 self
->area
.width
, self
->area
.height
, FALSE
, TRUE
);
1196 void client_update_wmhints(ObClient
*self
)
1199 gboolean ur
= FALSE
;
1202 /* assume a window takes input if it doesnt specify */
1203 self
->can_focus
= TRUE
;
1205 if ((hints
= XGetWMHints(ob_display
, self
->window
)) != NULL
) {
1206 if (hints
->flags
& InputHint
)
1207 self
->can_focus
= hints
->input
;
1209 /* only do this when first managing the window *AND* when we aren't
1211 if (ob_state() != OB_STATE_STARTING
&& self
->frame
== NULL
)
1212 if (hints
->flags
& StateHint
)
1213 self
->iconic
= hints
->initial_state
== IconicState
;
1215 if (hints
->flags
& XUrgencyHint
)
1218 if (!(hints
->flags
& WindowGroupHint
))
1219 hints
->window_group
= None
;
1221 /* did the group state change? */
1222 if (hints
->window_group
!=
1223 (self
->group
? self
->group
->leader
: None
)) {
1224 /* remove from the old group if there was one */
1225 if (self
->group
!= NULL
) {
1226 /* remove transients of the group */
1227 for (it
= self
->group
->members
; it
; it
= it
->next
)
1228 self
->transients
= g_slist_remove(self
->transients
,
1230 group_remove(self
->group
, self
);
1233 if (hints
->window_group
!= None
) {
1234 self
->group
= group_add(hints
->window_group
, self
);
1236 /* i can only have transients from the group if i am not
1238 if (!self
->transient_for
) {
1239 /* add other transients of the group that are already
1241 for (it
= self
->group
->members
; it
; it
= it
->next
) {
1242 ObClient
*c
= it
->data
;
1243 if (c
!= self
&& c
->transient_for
== OB_TRAN_GROUP
)
1245 g_slist_append(self
->transients
, c
);
1250 /* because the self->transient flag wont change from this call,
1251 we don't need to update the window's type and such, only its
1252 transient_for, and the transients lists of other windows in
1253 the group may be affected */
1254 client_update_transient_for(self
);
1257 /* the WM_HINTS can contain an icon */
1258 client_update_icons(self
);
1263 if (ur
!= self
->urgent
) {
1265 ob_debug("Urgent Hint for 0x%lx: %s\n", self
->window
,
1267 /* fire the urgent callback if we're mapped, otherwise, wait until
1268 after we're mapped */
1270 dispatch_client(Event_Client_Urgent
, self
, self
->urgent
, 0);
1274 void client_update_title(ObClient
*self
)
1280 gboolean read_title
;
1282 g_free(self
->title
);
1285 if (!PROP_GETS(self
->window
, net_wm_name
, utf8
, &data
))
1286 /* try old x stuff */
1287 if (!PROP_GETS(self
->window
, wm_name
, locale
, &data
))
1288 data
= g_strdup("Unnamed Window");
1290 /* look for duplicates and append a number */
1292 for (it
= client_list
; it
; it
= it
->next
)
1293 if (it
->data
!= self
) {
1294 ObClient
*c
= it
->data
;
1295 if (0 == strncmp(c
->title
, data
, strlen(data
)))
1296 nums
|= 1 << c
->title_count
;
1298 /* find first free number */
1299 for (i
= 1; i
<= 32; ++i
)
1300 if (!(nums
& (1 << i
))) {
1301 if (self
->title_count
== 1 || i
== 1)
1302 self
->title_count
= i
;
1305 /* dont display the number for the first window */
1306 if (self
->title_count
> 1) {
1307 char *vdata
, *ndata
;
1308 ndata
= g_strdup_printf(" - [%u]", self
->title_count
);
1309 vdata
= g_strconcat(data
, ndata
, NULL
);
1315 PROP_SETS(self
->window
, net_wm_visible_name
, data
);
1320 frame_adjust_title(self
->frame
);
1322 /* update the icon title */
1324 g_free(self
->icon_title
);
1328 if (!PROP_GETS(self
->window
, net_wm_icon_name
, utf8
, &data
))
1329 /* try old x stuff */
1330 if (!PROP_GETS(self
->window
, wm_icon_name
, locale
, &data
)) {
1331 data
= g_strdup(self
->title
);
1335 /* append the title count, dont display the number for the first window */
1336 if (read_title
&& self
->title_count
> 1) {
1337 char *vdata
, *ndata
;
1338 ndata
= g_strdup_printf(" - [%u]", self
->title_count
);
1339 vdata
= g_strconcat(data
, ndata
, NULL
);
1345 PROP_SETS(self
->window
, net_wm_visible_icon_name
, data
);
1347 self
->icon_title
= data
;
1350 void client_update_class(ObClient
*self
)
1355 if (self
->name
) g_free(self
->name
);
1356 if (self
->class) g_free(self
->class);
1357 if (self
->role
) g_free(self
->role
);
1359 self
->name
= self
->class = self
->role
= NULL
;
1361 if (PROP_GETSS(self
->window
, wm_class
, locale
, &data
)) {
1363 self
->name
= g_strdup(data
[0]);
1365 self
->class = g_strdup(data
[1]);
1370 if (PROP_GETS(self
->window
, wm_window_role
, locale
, &s
))
1371 self
->role
= g_strdup(s
);
1373 if (self
->name
== NULL
) self
->name
= g_strdup("");
1374 if (self
->class == NULL
) self
->class = g_strdup("");
1375 if (self
->role
== NULL
) self
->role
= g_strdup("");
1378 void client_update_strut(ObClient
*self
)
1382 gboolean got
= FALSE
;
1384 if (PROP_GETA32(self
->window
, net_wm_strut_partial
, cardinal
,
1388 STRUT_PARTIAL_SET(self
->strut
,
1389 data
[0], data
[2], data
[1], data
[3],
1390 data
[4], data
[5], data
[8], data
[9],
1391 data
[6], data
[7], data
[10], data
[11]);
1397 PROP_GETA32(self
->window
, net_wm_strut
, cardinal
, &data
, &num
)) {
1400 STRUT_PARTIAL_SET(self
->strut
,
1401 data
[0], data
[2], data
[1], data
[3],
1402 0, 0, 0, 0, 0, 0, 0, 0);
1408 STRUT_PARTIAL_SET(self
->strut
, 0, 0, 0, 0,
1409 0, 0, 0, 0, 0, 0, 0, 0);
1411 /* updating here is pointless while we're being mapped cuz we're not in
1412 the client list yet */
1414 screen_update_areas();
1417 void client_update_icons(ObClient
*self
)
1423 for (i
= 0; i
< self
->nicons
; ++i
)
1424 g_free(self
->icons
[i
].data
);
1425 if (self
->nicons
> 0)
1426 g_free(self
->icons
);
1429 if (PROP_GETA32(self
->window
, net_wm_icon
, cardinal
, &data
, &num
)) {
1430 /* figure out how many valid icons are in here */
1432 while (num
- i
> 2) {
1436 if (i
> num
|| w
*h
== 0) break;
1440 self
->icons
= g_new(ObClientIcon
, self
->nicons
);
1442 /* store the icons */
1444 for (j
= 0; j
< self
->nicons
; ++j
) {
1447 w
= self
->icons
[j
].width
= data
[i
++];
1448 h
= self
->icons
[j
].height
= data
[i
++];
1450 if (w
*h
== 0) continue;
1452 self
->icons
[j
].data
= g_new(RrPixel32
, w
* h
);
1453 for (x
= 0, y
= 0, t
= 0; t
< w
* h
; ++t
, ++x
, ++i
) {
1458 self
->icons
[j
].data
[t
] =
1459 (((data
[i
] >> 24) & 0xff) << RrDefaultAlphaOffset
) +
1460 (((data
[i
] >> 16) & 0xff) << RrDefaultRedOffset
) +
1461 (((data
[i
] >> 8) & 0xff) << RrDefaultGreenOffset
) +
1462 (((data
[i
] >> 0) & 0xff) << RrDefaultBlueOffset
);
1468 } else if (PROP_GETA32(self
->window
, kwm_win_icon
,
1469 kwm_win_icon
, &data
, &num
)) {
1472 self
->icons
= g_new(ObClientIcon
, self
->nicons
);
1473 xerror_set_ignore(TRUE
);
1474 if (!RrPixmapToRGBA(ob_rr_inst
,
1476 &self
->icons
[self
->nicons
-1].width
,
1477 &self
->icons
[self
->nicons
-1].height
,
1478 &self
->icons
[self
->nicons
-1].data
)) {
1479 g_free(&self
->icons
[self
->nicons
-1]);
1482 xerror_set_ignore(FALSE
);
1488 if ((hints
= XGetWMHints(ob_display
, self
->window
))) {
1489 if (hints
->flags
& IconPixmapHint
) {
1491 self
->icons
= g_new(ObClientIcon
, self
->nicons
);
1492 xerror_set_ignore(TRUE
);
1493 if (!RrPixmapToRGBA(ob_rr_inst
,
1495 (hints
->flags
& IconMaskHint
?
1496 hints
->icon_mask
: None
),
1497 &self
->icons
[self
->nicons
-1].width
,
1498 &self
->icons
[self
->nicons
-1].height
,
1499 &self
->icons
[self
->nicons
-1].data
)){
1500 g_free(&self
->icons
[self
->nicons
-1]);
1503 xerror_set_ignore(FALSE
);
1510 frame_adjust_icon(self
->frame
);
1513 static void client_change_state(ObClient
*self
)
1516 guint32 netstate
[10];
1519 state
[0] = self
->wmstate
;
1521 PROP_SETA32(self
->window
, wm_state
, wm_state
, state
, 2);
1525 netstate
[num
++] = prop_atoms
.net_wm_state_modal
;
1527 netstate
[num
++] = prop_atoms
.net_wm_state_shaded
;
1529 netstate
[num
++] = prop_atoms
.net_wm_state_hidden
;
1530 if (self
->skip_taskbar
)
1531 netstate
[num
++] = prop_atoms
.net_wm_state_skip_taskbar
;
1532 if (self
->skip_pager
)
1533 netstate
[num
++] = prop_atoms
.net_wm_state_skip_pager
;
1534 if (self
->fullscreen
)
1535 netstate
[num
++] = prop_atoms
.net_wm_state_fullscreen
;
1537 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_vert
;
1539 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_horz
;
1541 netstate
[num
++] = prop_atoms
.net_wm_state_above
;
1543 netstate
[num
++] = prop_atoms
.net_wm_state_below
;
1544 PROP_SETA32(self
->window
, net_wm_state
, atom
, netstate
, num
);
1546 client_calc_layer(self
);
1549 frame_adjust_state(self
->frame
);
1552 ObClient
*client_search_focus_tree(ObClient
*self
)
1557 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
) {
1558 if (client_focused(it
->data
)) return it
->data
;
1559 if ((ret
= client_search_focus_tree(it
->data
))) return ret
;
1564 ObClient
*client_search_focus_tree_full(ObClient
*self
)
1566 if (self
->transient_for
) {
1567 if (self
->transient_for
!= OB_TRAN_GROUP
) {
1568 return client_search_focus_tree_full(self
->transient_for
);
1571 gboolean recursed
= FALSE
;
1573 for (it
= self
->group
->members
; it
; it
= it
->next
)
1574 if (!((ObClient
*)it
->data
)->transient_for
) {
1576 if ((c
= client_search_focus_tree_full(it
->data
)))
1585 /* this function checks the whole tree, the client_search_focus_tree~
1586 does not, so we need to check this window */
1587 if (client_focused(self
))
1589 return client_search_focus_tree(self
);
1592 static ObStackingLayer
calc_layer(ObClient
*self
)
1596 if (self
->fullscreen
) l
= OB_STACKING_LAYER_FULLSCREEN
;
1597 else if (self
->type
== OB_CLIENT_TYPE_DESKTOP
)
1598 l
= OB_STACKING_LAYER_DESKTOP
;
1599 else if (self
->type
== OB_CLIENT_TYPE_DOCK
) {
1600 if (!self
->below
) l
= OB_STACKING_LAYER_TOP
;
1601 else l
= OB_STACKING_LAYER_NORMAL
;
1603 else if (self
->above
) l
= OB_STACKING_LAYER_ABOVE
;
1604 else if (self
->below
) l
= OB_STACKING_LAYER_BELOW
;
1605 else l
= OB_STACKING_LAYER_NORMAL
;
1610 static void client_calc_layer_recursive(ObClient
*self
, ObClient
*orig
,
1611 ObStackingLayer l
, gboolean raised
)
1613 ObStackingLayer old
, own
;
1617 own
= calc_layer(self
);
1618 self
->layer
= l
> own
? l
: own
;
1620 for (it
= self
->transients
; it
; it
= it
->next
)
1621 client_calc_layer_recursive(it
->data
, orig
,
1622 l
, raised
? raised
: l
!= old
);
1624 if (!raised
&& l
!= old
)
1625 if (orig
->frame
) { /* only restack if the original window is managed */
1626 /* XXX add_non_intrusive ever? */
1627 stacking_remove(CLIENT_AS_WINDOW(self
));
1628 stacking_add(CLIENT_AS_WINDOW(self
));
1632 void client_calc_layer(ObClient
*self
)
1639 /* transients take on the layer of their parents */
1640 self
= client_search_top_transient(self
);
1642 l
= calc_layer(self
);
1644 client_calc_layer_recursive(self
, orig
, l
, FALSE
);
1647 gboolean
client_should_show(ObClient
*self
)
1649 if (self
->iconic
) return FALSE
;
1650 else if (!(self
->desktop
== screen_desktop
||
1651 self
->desktop
== DESKTOP_ALL
)) return FALSE
;
1652 else if (client_normal(self
) && screen_showing_desktop
) return FALSE
;
1657 static void client_showhide(ObClient
*self
)
1660 if (client_should_show(self
))
1661 frame_show(self
->frame
);
1663 frame_hide(self
->frame
);
1666 gboolean
client_normal(ObClient
*self
) {
1667 return ! (self
->type
== OB_CLIENT_TYPE_DESKTOP
||
1668 self
->type
== OB_CLIENT_TYPE_DOCK
||
1669 self
->type
== OB_CLIENT_TYPE_SPLASH
);
1672 static void client_apply_startup_state(ObClient
*self
)
1674 /* these are in a carefully crafted order.. */
1677 self
->iconic
= FALSE
;
1678 client_iconify(self
, TRUE
, FALSE
);
1680 if (self
->fullscreen
) {
1681 self
->fullscreen
= FALSE
;
1682 client_fullscreen(self
, TRUE
, FALSE
);
1685 self
->shaded
= FALSE
;
1686 client_shade(self
, TRUE
);
1689 dispatch_client(Event_Client_Urgent
, self
, self
->urgent
, 0);
1691 if (self
->max_vert
&& self
->max_horz
) {
1692 self
->max_vert
= self
->max_horz
= FALSE
;
1693 client_maximize(self
, TRUE
, 0, FALSE
);
1694 } else if (self
->max_vert
) {
1695 self
->max_vert
= FALSE
;
1696 client_maximize(self
, TRUE
, 2, FALSE
);
1697 } else if (self
->max_horz
) {
1698 self
->max_horz
= FALSE
;
1699 client_maximize(self
, TRUE
, 1, FALSE
);
1702 /* nothing to do for the other states:
1711 void client_configure_full(ObClient
*self
, ObCorner anchor
,
1712 int x
, int y
, int w
, int h
,
1713 gboolean user
, gboolean final
,
1714 gboolean force_reply
)
1716 gboolean moved
= FALSE
, resized
= FALSE
;
1717 guint fdecor
= self
->frame
->decorations
;
1719 /* make the frame recalculate its dimentions n shit without changing
1720 anything visible for real, this way the constraints below can work with
1721 the updated frame dimensions. */
1722 frame_adjust_area(self
->frame
, TRUE
, TRUE
, TRUE
);
1724 /* gets the frame's position */
1725 frame_client_gravity(self
->frame
, &x
, &y
);
1727 /* these positions are frame positions, not client positions */
1729 /* set the size and position if fullscreen */
1730 if (self
->fullscreen
) {
1733 XF86VidModeModeLine mode
;
1738 i
= client_monitor(self
);
1739 a
= screen_physical_area_monitor(i
);
1742 if (i
== 0 && /* primary head */
1743 extensions_vidmode
&&
1744 XF86VidModeGetViewPort(ob_display
, ob_screen
, &x
, &y
) &&
1745 /* get the mode last so the mode.privsize isnt freed incorrectly */
1746 XF86VidModeGetModeLine(ob_display
, ob_screen
, &dot
, &mode
)) {
1751 if (mode
.privsize
) XFree(mode
.private);
1761 user
= FALSE
; /* ignore that increment etc shit when in fullscreen */
1765 a
= screen_area_monitor(self
->desktop
, client_monitor(self
));
1767 /* set the size and position if maximized */
1768 if (self
->max_horz
) {
1770 w
= a
->width
- self
->frame
->size
.left
- self
->frame
->size
.right
;
1772 if (self
->max_vert
) {
1774 h
= a
->height
- self
->frame
->size
.top
- self
->frame
->size
.bottom
;
1778 /* gets the client's position */
1779 frame_frame_gravity(self
->frame
, &x
, &y
);
1781 /* these override the above states! if you cant move you can't move! */
1783 if (!(self
->functions
& OB_CLIENT_FUNC_MOVE
)) {
1787 if (!(self
->functions
& OB_CLIENT_FUNC_RESIZE
)) {
1788 w
= self
->area
.width
;
1789 h
= self
->area
.height
;
1793 if (!(w
== self
->area
.width
&& h
== self
->area
.height
)) {
1794 int basew
, baseh
, minw
, minh
;
1796 /* base size is substituted with min size if not specified */
1797 if (self
->base_size
.width
|| self
->base_size
.height
) {
1798 basew
= self
->base_size
.width
;
1799 baseh
= self
->base_size
.height
;
1801 basew
= self
->min_size
.width
;
1802 baseh
= self
->min_size
.height
;
1804 /* min size is substituted with base size if not specified */
1805 if (self
->min_size
.width
|| self
->min_size
.height
) {
1806 minw
= self
->min_size
.width
;
1807 minh
= self
->min_size
.height
;
1809 minw
= self
->base_size
.width
;
1810 minh
= self
->base_size
.height
;
1814 /* for interactive resizing. have to move half an increment in each
1817 /* how far we are towards the next size inc */
1818 int mw
= (w
- basew
) % self
->size_inc
.width
;
1819 int mh
= (h
- baseh
) % self
->size_inc
.height
;
1821 int aw
= self
->size_inc
.width
/ 2;
1822 int ah
= self
->size_inc
.height
/ 2;
1823 /* don't let us move into a new size increment */
1824 if (mw
+ aw
>= self
->size_inc
.width
)
1825 aw
= self
->size_inc
.width
- mw
- 1;
1826 if (mh
+ ah
>= self
->size_inc
.height
)
1827 ah
= self
->size_inc
.height
- mh
- 1;
1831 /* if this is a user-requested resize, then check against min/max
1834 /* smaller than min size or bigger than max size? */
1835 if (w
> self
->max_size
.width
) w
= self
->max_size
.width
;
1836 if (w
< minw
) w
= minw
;
1837 if (h
> self
->max_size
.height
) h
= self
->max_size
.height
;
1838 if (h
< minh
) h
= minh
;
1844 /* keep to the increments */
1845 w
/= self
->size_inc
.width
;
1846 h
/= self
->size_inc
.height
;
1848 /* you cannot resize to nothing */
1849 if (basew
+ w
< 1) w
= 1 - basew
;
1850 if (baseh
+ h
< 1) h
= 1 - baseh
;
1852 /* store the logical size */
1853 SIZE_SET(self
->logical_size
,
1854 self
->size_inc
.width
> 1 ? w
: w
+ basew
,
1855 self
->size_inc
.height
> 1 ? h
: h
+ baseh
);
1857 w
*= self
->size_inc
.width
;
1858 h
*= self
->size_inc
.height
;
1864 /* adjust the height to match the width for the aspect ratios.
1865 for this, min size is not substituted for base size ever. */
1866 w
-= self
->base_size
.width
;
1867 h
-= self
->base_size
.height
;
1869 if (self
->min_ratio
)
1870 if (h
* self
->min_ratio
> w
) h
= (int)(w
/ self
->min_ratio
);
1871 if (self
->max_ratio
)
1872 if (h
* self
->max_ratio
< w
) h
= (int)(w
/ self
->max_ratio
);
1874 w
+= self
->base_size
.width
;
1875 h
+= self
->base_size
.height
;
1880 case OB_CORNER_TOPLEFT
:
1882 case OB_CORNER_TOPRIGHT
:
1883 x
-= w
- self
->area
.width
;
1885 case OB_CORNER_BOTTOMLEFT
:
1886 y
-= h
- self
->area
.height
;
1888 case OB_CORNER_BOTTOMRIGHT
:
1889 x
-= w
- self
->area
.width
;
1890 y
-= h
- self
->area
.height
;
1894 moved
= x
!= self
->area
.x
|| y
!= self
->area
.y
;
1895 resized
= w
!= self
->area
.width
|| h
!= self
->area
.height
;
1897 RECT_SET(self
->area
, x
, y
, w
, h
);
1899 /* for app-requested resizes, always resize if 'resized' is true.
1900 for user-requested ones, only resize if final is true, or when
1901 resizing in redraw mode */
1902 if ((!user
&& resized
) ||
1903 (user
&& (final
|| (resized
&& config_redraw_resize
))))
1904 XResizeWindow(ob_display
, self
->window
, w
, h
);
1906 /* move/resize the frame to match the request */
1908 if (self
->decorations
!= fdecor
)
1909 moved
= resized
= TRUE
;
1911 if (moved
|| resized
)
1912 frame_adjust_area(self
->frame
, moved
, resized
, FALSE
);
1914 if (!resized
&& (force_reply
|| ((!user
&& moved
) || (user
&& final
))))
1917 event
.type
= ConfigureNotify
;
1918 event
.xconfigure
.display
= ob_display
;
1919 event
.xconfigure
.event
= self
->window
;
1920 event
.xconfigure
.window
= self
->window
;
1922 /* root window real coords */
1923 event
.xconfigure
.x
= self
->frame
->area
.x
+ self
->frame
->size
.left
-
1925 event
.xconfigure
.y
= self
->frame
->area
.y
+ self
->frame
->size
.top
-
1927 event
.xconfigure
.width
= w
;
1928 event
.xconfigure
.height
= h
;
1929 event
.xconfigure
.border_width
= 0;
1930 event
.xconfigure
.above
= self
->frame
->plate
;
1931 event
.xconfigure
.override_redirect
= FALSE
;
1932 XSendEvent(event
.xconfigure
.display
, event
.xconfigure
.window
,
1933 FALSE
, StructureNotifyMask
, &event
);
1938 void client_fullscreen(ObClient
*self
, gboolean fs
, gboolean savearea
)
1942 if (!(self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
) || /* can't */
1943 self
->fullscreen
== fs
) return; /* already done */
1945 self
->fullscreen
= fs
;
1946 client_change_state(self
); /* change the state hints on the client,
1947 and adjust out layer/stacking */
1951 guint32 dimensions
[4];
1952 dimensions
[0] = self
->area
.x
;
1953 dimensions
[1] = self
->area
.y
;
1954 dimensions
[2] = self
->area
.width
;
1955 dimensions
[3] = self
->area
.height
;
1957 PROP_SETA32(self
->window
, openbox_premax
, cardinal
,
1961 /* these are not actually used cuz client_configure will set them
1962 as appropriate when the window is fullscreened */
1969 /* pick some fallbacks... */
1970 a
= screen_area_monitor(self
->desktop
, 0);
1971 x
= a
->x
+ a
->width
/ 4;
1972 y
= a
->y
+ a
->height
/ 4;
1976 if (PROP_GETA32(self
->window
, openbox_premax
, cardinal
,
1977 (guint32
**)&dimensions
, &num
)) {
1988 client_setup_decor_and_functions(self
);
1990 client_configure(self
, OB_CORNER_TOPLEFT
, x
, y
, w
, h
, TRUE
, TRUE
);
1992 /* try focus us when we go into fullscreen mode */
1996 static void client_iconify_recursive(ObClient
*self
,
1997 gboolean iconic
, gboolean curdesk
)
2000 gboolean changed
= FALSE
;
2003 if (self
->iconic
!= iconic
) {
2004 ob_debug("%sconifying window: 0x%lx\n", (iconic
? "I" : "Uni"),
2007 self
->iconic
= iconic
;
2010 if (self
->functions
& OB_CLIENT_FUNC_ICONIFY
) {
2011 self
->wmstate
= IconicState
;
2012 self
->ignore_unmaps
++;
2013 /* we unmap the client itself so that we can get MapRequest
2014 events, and because the ICCCM tells us to! */
2015 XUnmapWindow(ob_display
, self
->window
);
2017 /* update the focus lists.. iconic windows go to the bottom of
2018 the list, put the new iconic window at the 'top of the
2020 focus_order_to_top(self
);
2026 client_set_desktop(self
, screen_desktop
, FALSE
);
2027 self
->wmstate
= self
->shaded
? IconicState
: NormalState
;
2028 XMapWindow(ob_display
, self
->window
);
2030 /* this puts it after the current focused window */
2031 focus_order_remove(self
);
2032 focus_order_add_new(self
);
2034 /* this is here cuz with the VIDMODE extension, the viewport can
2035 change while a fullscreen window is iconic, and when it
2036 uniconifies, it would be nice if it did so to the new position
2038 client_reconfigure(self
);
2045 client_change_state(self
);
2046 client_showhide(self
);
2047 screen_update_areas();
2049 dispatch_client(iconic
? Event_Client_Unmapped
: Event_Client_Mapped
,
2053 /* iconify all transients */
2054 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
)
2055 if (it
->data
!= self
) client_iconify_recursive(it
->data
,
2059 void client_iconify(ObClient
*self
, gboolean iconic
, gboolean curdesk
)
2061 /* move up the transient chain as far as possible first */
2062 self
= client_search_top_transient(self
);
2064 client_iconify_recursive(client_search_top_transient(self
),
2068 void client_maximize(ObClient
*self
, gboolean max
, int dir
, gboolean savearea
)
2072 g_assert(dir
== 0 || dir
== 1 || dir
== 2);
2073 if (!(self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
)) return; /* can't */
2075 /* check if already done */
2077 if (dir
== 0 && self
->max_horz
&& self
->max_vert
) return;
2078 if (dir
== 1 && self
->max_horz
) return;
2079 if (dir
== 2 && self
->max_vert
) return;
2081 if (dir
== 0 && !self
->max_horz
&& !self
->max_vert
) return;
2082 if (dir
== 1 && !self
->max_horz
) return;
2083 if (dir
== 2 && !self
->max_vert
) return;
2086 /* work with the frame's coords */
2087 x
= self
->frame
->area
.x
;
2088 y
= self
->frame
->area
.y
;
2089 w
= self
->area
.width
;
2090 h
= self
->area
.height
;
2094 gint32 dimensions
[4];
2103 /* get the property off the window and use it for the dimensions
2104 we are already maxed on */
2105 if (PROP_GETA32(self
->window
, openbox_premax
, cardinal
,
2106 (guint32
**)&readdim
, &num
)) {
2108 if (self
->max_horz
) {
2109 dimensions
[0] = readdim
[0];
2110 dimensions
[2] = readdim
[2];
2112 if (self
->max_vert
) {
2113 dimensions
[1] = readdim
[1];
2114 dimensions
[3] = readdim
[3];
2120 PROP_SETA32(self
->window
, openbox_premax
, cardinal
,
2121 (guint32
*)dimensions
, 4);
2128 /* pick some fallbacks... */
2129 a
= screen_area_monitor(self
->desktop
, 0);
2130 if (dir
== 0 || dir
== 1) { /* horz */
2131 x
= a
->x
+ a
->width
/ 4;
2134 if (dir
== 0 || dir
== 2) { /* vert */
2135 y
= a
->y
+ a
->height
/ 4;
2139 if (PROP_GETA32(self
->window
, openbox_premax
, cardinal
,
2140 (guint32
**)&dimensions
, &num
)) {
2142 if (dir
== 0 || dir
== 1) { /* horz */
2146 if (dir
== 0 || dir
== 2) { /* vert */
2155 if (dir
== 0 || dir
== 1) /* horz */
2156 self
->max_horz
= max
;
2157 if (dir
== 0 || dir
== 2) /* vert */
2158 self
->max_vert
= max
;
2160 if (!self
->max_horz
&& !self
->max_vert
)
2161 PROP_ERASE(self
->window
, openbox_premax
);
2163 client_change_state(self
); /* change the state hints on the client */
2165 /* figure out where the client should be going */
2166 frame_frame_gravity(self
->frame
, &x
, &y
);
2167 client_configure(self
, OB_CORNER_TOPLEFT
, x
, y
, w
, h
, TRUE
, TRUE
);
2170 void client_shade(ObClient
*self
, gboolean shade
)
2172 if ((!(self
->functions
& OB_CLIENT_FUNC_SHADE
) &&
2173 shade
) || /* can't shade */
2174 self
->shaded
== shade
) return; /* already done */
2176 /* when we're iconic, don't change the wmstate */
2178 self
->wmstate
= shade
? IconicState
: NormalState
;
2179 self
->shaded
= shade
;
2180 client_change_state(self
);
2181 /* resize the frame to just the titlebar */
2182 frame_adjust_area(self
->frame
, FALSE
, FALSE
, FALSE
);
2185 void client_close(ObClient
*self
)
2189 if (!(self
->functions
& OB_CLIENT_FUNC_CLOSE
)) return;
2192 XXX: itd be cool to do timeouts and shit here for killing the client's
2194 like... if the window is around after 5 seconds, then the close button
2195 turns a nice red, and if this function is called again, the client is
2199 ce
.xclient
.type
= ClientMessage
;
2200 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
2201 ce
.xclient
.display
= ob_display
;
2202 ce
.xclient
.window
= self
->window
;
2203 ce
.xclient
.format
= 32;
2204 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_delete_window
;
2205 ce
.xclient
.data
.l
[1] = event_lasttime
;
2206 ce
.xclient
.data
.l
[2] = 0l;
2207 ce
.xclient
.data
.l
[3] = 0l;
2208 ce
.xclient
.data
.l
[4] = 0l;
2209 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
2212 void client_kill(ObClient
*self
)
2214 XKillClient(ob_display
, self
->window
);
2217 void client_set_desktop_recursive(ObClient
*self
,
2218 guint target
, gboolean donthide
)
2223 if (target
!= self
->desktop
) {
2225 ob_debug("Setting desktop %u\n", target
+1);
2227 g_assert(target
< screen_num_desktops
|| target
== DESKTOP_ALL
);
2229 /* remove from the old desktop(s) */
2230 focus_order_remove(self
);
2232 old
= self
->desktop
;
2233 self
->desktop
= target
;
2234 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, target
);
2235 /* the frame can display the current desktop state */
2236 frame_adjust_state(self
->frame
);
2237 /* 'move' the window to the new desktop */
2239 client_showhide(self
);
2240 /* raise if it was not already on the desktop */
2241 if (old
!= DESKTOP_ALL
)
2242 stacking_raise(CLIENT_AS_WINDOW(self
));
2243 screen_update_areas();
2245 /* add to the new desktop(s) */
2246 if (config_focus_new
)
2247 focus_order_to_top(self
);
2249 focus_order_to_bottom(self
);
2251 dispatch_client(Event_Client_Desktop
, self
, target
, old
);
2254 /* move all transients */
2255 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
)
2256 if (it
->data
!= self
) client_set_desktop_recursive(it
->data
,
2260 void client_set_desktop(ObClient
*self
, guint target
, gboolean donthide
)
2262 client_set_desktop_recursive(client_search_top_transient(self
),
2266 ObClient
*client_search_modal_child(ObClient
*self
)
2271 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
) {
2272 ObClient
*c
= it
->data
;
2273 if ((ret
= client_search_modal_child(c
))) return ret
;
2274 if (c
->modal
) return c
;
2279 gboolean
client_validate(ObClient
*self
)
2283 XSync(ob_display
, FALSE
); /* get all events on the server */
2285 if (XCheckTypedWindowEvent(ob_display
, self
->window
, DestroyNotify
, &e
) ||
2286 XCheckTypedWindowEvent(ob_display
, self
->window
, UnmapNotify
, &e
)) {
2287 XPutBackEvent(ob_display
, &e
);
2294 void client_set_wm_state(ObClient
*self
, long state
)
2296 if (state
== self
->wmstate
) return; /* no change */
2300 client_iconify(self
, TRUE
, TRUE
);
2303 client_iconify(self
, FALSE
, TRUE
);
2308 void client_set_state(ObClient
*self
, Atom action
, long data1
, long data2
)
2310 gboolean shaded
= self
->shaded
;
2311 gboolean fullscreen
= self
->fullscreen
;
2312 gboolean max_horz
= self
->max_horz
;
2313 gboolean max_vert
= self
->max_vert
;
2316 if (!(action
== prop_atoms
.net_wm_state_add
||
2317 action
== prop_atoms
.net_wm_state_remove
||
2318 action
== prop_atoms
.net_wm_state_toggle
))
2319 /* an invalid action was passed to the client message, ignore it */
2322 for (i
= 0; i
< 2; ++i
) {
2323 Atom state
= i
== 0 ? data1
: data2
;
2325 if (!state
) continue;
2327 /* if toggling, then pick whether we're adding or removing */
2328 if (action
== prop_atoms
.net_wm_state_toggle
) {
2329 if (state
== prop_atoms
.net_wm_state_modal
)
2330 action
= self
->modal
? prop_atoms
.net_wm_state_remove
:
2331 prop_atoms
.net_wm_state_add
;
2332 else if (state
== prop_atoms
.net_wm_state_maximized_vert
)
2333 action
= self
->max_vert
? prop_atoms
.net_wm_state_remove
:
2334 prop_atoms
.net_wm_state_add
;
2335 else if (state
== prop_atoms
.net_wm_state_maximized_horz
)
2336 action
= self
->max_horz
? prop_atoms
.net_wm_state_remove
:
2337 prop_atoms
.net_wm_state_add
;
2338 else if (state
== prop_atoms
.net_wm_state_shaded
)
2339 action
= self
->shaded
? prop_atoms
.net_wm_state_remove
:
2340 prop_atoms
.net_wm_state_add
;
2341 else if (state
== prop_atoms
.net_wm_state_skip_taskbar
)
2342 action
= self
->skip_taskbar
?
2343 prop_atoms
.net_wm_state_remove
:
2344 prop_atoms
.net_wm_state_add
;
2345 else if (state
== prop_atoms
.net_wm_state_skip_pager
)
2346 action
= self
->skip_pager
?
2347 prop_atoms
.net_wm_state_remove
:
2348 prop_atoms
.net_wm_state_add
;
2349 else if (state
== prop_atoms
.net_wm_state_fullscreen
)
2350 action
= self
->fullscreen
?
2351 prop_atoms
.net_wm_state_remove
:
2352 prop_atoms
.net_wm_state_add
;
2353 else if (state
== prop_atoms
.net_wm_state_above
)
2354 action
= self
->above
? prop_atoms
.net_wm_state_remove
:
2355 prop_atoms
.net_wm_state_add
;
2356 else if (state
== prop_atoms
.net_wm_state_below
)
2357 action
= self
->below
? prop_atoms
.net_wm_state_remove
:
2358 prop_atoms
.net_wm_state_add
;
2361 if (action
== prop_atoms
.net_wm_state_add
) {
2362 if (state
== prop_atoms
.net_wm_state_modal
) {
2363 /* XXX raise here or something? */
2365 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
2367 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
2369 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
2371 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
2372 self
->skip_taskbar
= TRUE
;
2373 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
2374 self
->skip_pager
= TRUE
;
2375 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
2377 } else if (state
== prop_atoms
.net_wm_state_above
) {
2379 } else if (state
== prop_atoms
.net_wm_state_below
) {
2383 } else { /* action == prop_atoms.net_wm_state_remove */
2384 if (state
== prop_atoms
.net_wm_state_modal
) {
2385 self
->modal
= FALSE
;
2386 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
2388 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
2390 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
2392 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
2393 self
->skip_taskbar
= FALSE
;
2394 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
2395 self
->skip_pager
= FALSE
;
2396 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
2398 } else if (state
== prop_atoms
.net_wm_state_above
) {
2399 self
->above
= FALSE
;
2400 } else if (state
== prop_atoms
.net_wm_state_below
) {
2401 self
->below
= FALSE
;
2405 if (max_horz
!= self
->max_horz
|| max_vert
!= self
->max_vert
) {
2406 if (max_horz
!= self
->max_horz
&& max_vert
!= self
->max_vert
) {
2408 if (max_horz
== max_vert
) { /* both going the same way */
2409 client_maximize(self
, max_horz
, 0, TRUE
);
2411 client_maximize(self
, max_horz
, 1, TRUE
);
2412 client_maximize(self
, max_vert
, 2, TRUE
);
2416 if (max_horz
!= self
->max_horz
)
2417 client_maximize(self
, max_horz
, 1, TRUE
);
2419 client_maximize(self
, max_vert
, 2, TRUE
);
2422 /* change fullscreen state before shading, as it will affect if the window
2424 if (fullscreen
!= self
->fullscreen
)
2425 client_fullscreen(self
, fullscreen
, TRUE
);
2426 if (shaded
!= self
->shaded
)
2427 client_shade(self
, shaded
);
2428 client_calc_layer(self
);
2429 client_change_state(self
); /* change the hint to reflect these changes */
2432 ObClient
*client_focus_target(ObClient
*self
)
2436 /* if we have a modal child, then focus it, not us */
2437 child
= client_search_modal_child(self
);
2438 if (child
) return child
;
2442 gboolean
client_can_focus(ObClient
*self
)
2446 /* choose the correct target */
2447 self
= client_focus_target(self
);
2449 if (!self
->frame
->visible
)
2452 if (!((self
->can_focus
|| self
->focus_notify
) &&
2453 (self
->desktop
== screen_desktop
||
2454 self
->desktop
== DESKTOP_ALL
) &&
2458 /* do a check to see if the window has already been unmapped or destroyed
2459 do this intelligently while watching out for unmaps we've generated
2460 (ignore_unmaps > 0) */
2461 if (XCheckTypedWindowEvent(ob_display
, self
->window
,
2462 DestroyNotify
, &ev
)) {
2463 XPutBackEvent(ob_display
, &ev
);
2466 while (XCheckTypedWindowEvent(ob_display
, self
->window
,
2467 UnmapNotify
, &ev
)) {
2468 if (self
->ignore_unmaps
) {
2469 self
->ignore_unmaps
--;
2471 XPutBackEvent(ob_display
, &ev
);
2479 gboolean
client_focus(ObClient
*self
)
2481 /* choose the correct target */
2482 self
= client_focus_target(self
);
2484 if (!client_can_focus(self
)) {
2485 if (!self
->frame
->visible
) {
2486 /* update the focus lists */
2487 focus_order_to_top(self
);
2492 if (self
->can_focus
)
2493 /* RevertToPointerRoot causes much more headache than RevertToNone, so
2494 I choose to use it always, hopefully to find errors quicker, if any
2495 are left. (I hate X. I hate focus events.) */
2496 XSetInputFocus(ob_display
, self
->window
, RevertToPointerRoot
,
2499 if (self
->focus_notify
) {
2501 ce
.xclient
.type
= ClientMessage
;
2502 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
2503 ce
.xclient
.display
= ob_display
;
2504 ce
.xclient
.window
= self
->window
;
2505 ce
.xclient
.format
= 32;
2506 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_take_focus
;
2507 ce
.xclient
.data
.l
[1] = event_lasttime
;
2508 ce
.xclient
.data
.l
[2] = 0l;
2509 ce
.xclient
.data
.l
[3] = 0l;
2510 ce
.xclient
.data
.l
[4] = 0l;
2511 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
2515 ob_debug("%sively focusing %lx at %d\n",
2516 (self
->can_focus
? "act" : "pass"),
2517 self
->window
, (int) event_lasttime
);
2520 /* Cause the FocusIn to come back to us. Important for desktop switches,
2521 since otherwise we'll have no FocusIn on the queue and send it off to
2522 the focus_backup. */
2523 XSync(ob_display
, FALSE
);
2527 void client_unfocus(ObClient
*self
)
2529 g_assert(focus_client
== self
);
2531 ob_debug("client_unfocus for %lx\n", self
->window
);
2533 focus_fallback(OB_FOCUS_FALLBACK_UNFOCUSING
);
2536 void client_activate(ObClient
*self
)
2538 if (client_normal(self
) && screen_showing_desktop
)
2539 screen_show_desktop(FALSE
);
2541 client_iconify(self
, FALSE
, FALSE
);
2542 if (self
->desktop
!= DESKTOP_ALL
&&
2543 self
->desktop
!= screen_desktop
)
2544 screen_set_desktop(self
->desktop
);
2545 else if (!self
->frame
->visible
)
2546 /* if its not visible for other reasons, then don't mess
2550 client_shade(self
, FALSE
);
2552 stacking_raise(CLIENT_AS_WINDOW(self
));
2555 gboolean
client_focused(ObClient
*self
)
2557 return self
== focus_client
;
2560 ObClientIcon
*client_icon(ObClient
*self
, int w
, int h
)
2563 /* si is the smallest image >= req */
2564 /* li is the largest image < req */
2565 unsigned long size
, smallest
= 0xffffffff, largest
= 0, si
= 0, li
= 0;
2567 if (!self
->nicons
) return NULL
;
2569 for (i
= 0; i
< self
->nicons
; ++i
) {
2570 size
= self
->icons
[i
].width
* self
->icons
[i
].height
;
2571 if (size
< smallest
&& size
>= (unsigned)(w
* h
)) {
2575 if (size
> largest
&& size
<= (unsigned)(w
* h
)) {
2580 if (largest
== 0) /* didnt find one smaller than the requested size */
2581 return &self
->icons
[si
];
2582 return &self
->icons
[li
];
2585 /* this be mostly ripped from fvwm */
2586 ObClient
*client_find_directional(ObClient
*c
, ObDirection dir
)
2588 int my_cx
, my_cy
, his_cx
, his_cy
;
2591 int score
, best_score
;
2592 ObClient
*best_client
, *cur
;
2598 /* first, find the centre coords of the currently focused window */
2599 my_cx
= c
->frame
->area
.x
+ c
->frame
->area
.width
/ 2;
2600 my_cy
= c
->frame
->area
.y
+ c
->frame
->area
.height
/ 2;
2605 for(it
= g_list_first(client_list
); it
; it
= it
->next
) {
2608 /* the currently selected window isn't interesting */
2611 if (!client_normal(cur
))
2613 if(c
->desktop
!= cur
->desktop
&& cur
->desktop
!= DESKTOP_ALL
)
2617 if(client_focus_target(cur
) == cur
&&
2618 !(cur
->can_focus
|| cur
->focus_notify
))
2621 /* find the centre coords of this window, from the
2622 * currently focused window's point of view */
2623 his_cx
= (cur
->frame
->area
.x
- my_cx
)
2624 + cur
->frame
->area
.width
/ 2;
2625 his_cy
= (cur
->frame
->area
.y
- my_cy
)
2626 + cur
->frame
->area
.height
/ 2;
2628 if(dir
== OB_DIRECTION_NORTHEAST
|| dir
== OB_DIRECTION_SOUTHEAST
||
2629 dir
== OB_DIRECTION_SOUTHWEST
|| dir
== OB_DIRECTION_NORTHWEST
) {
2631 /* Rotate the diagonals 45 degrees counterclockwise.
2632 * To do this, multiply the matrix /+h +h\ with the
2633 * vector (x y). \-h +h/
2634 * h = sqrt(0.5). We can set h := 1 since absolute
2635 * distance doesn't matter here. */
2636 tx
= his_cx
+ his_cy
;
2637 his_cy
= -his_cx
+ his_cy
;
2642 case OB_DIRECTION_NORTH
:
2643 case OB_DIRECTION_SOUTH
:
2644 case OB_DIRECTION_NORTHEAST
:
2645 case OB_DIRECTION_SOUTHWEST
:
2646 offset
= (his_cx
< 0) ? -his_cx
: his_cx
;
2647 distance
= ((dir
== OB_DIRECTION_NORTH
||
2648 dir
== OB_DIRECTION_NORTHEAST
) ?
2651 case OB_DIRECTION_EAST
:
2652 case OB_DIRECTION_WEST
:
2653 case OB_DIRECTION_SOUTHEAST
:
2654 case OB_DIRECTION_NORTHWEST
:
2655 offset
= (his_cy
< 0) ? -his_cy
: his_cy
;
2656 distance
= ((dir
== OB_DIRECTION_WEST
||
2657 dir
== OB_DIRECTION_NORTHWEST
) ?
2662 /* the target must be in the requested direction */
2666 /* Calculate score for this window. The smaller the better. */
2667 score
= distance
+ offset
;
2669 /* windows more than 45 degrees off the direction are
2670 * heavily penalized and will only be chosen if nothing
2671 * else within a million pixels */
2672 if(offset
> distance
)
2675 if(best_score
== -1 || score
< best_score
)
2683 void client_set_layer(ObClient
*self
, int layer
)
2687 self
->above
= FALSE
;
2688 } else if (layer
== 0) {
2689 self
->below
= self
->above
= FALSE
;
2691 self
->below
= FALSE
;
2694 client_calc_layer(self
);
2695 client_change_state(self
); /* reflect this in the state hints */
2698 guint
client_monitor(ObClient
*self
)
2702 for (i
= 0; i
< screen_num_monitors
; ++i
) {
2703 Rect
*area
= screen_physical_area_monitor(i
);
2704 if (RECT_INTERSECTS_RECT(*area
, self
->frame
->area
))
2707 if (i
== screen_num_monitors
) i
= 0;
2708 g_assert(i
< screen_num_monitors
);
2712 ObClient
*client_search_top_transient(ObClient
*self
)
2714 /* move up the transient chain as far as possible */
2715 if (self
->transient_for
) {
2716 if (self
->transient_for
!= OB_TRAN_GROUP
) {
2717 return client_search_top_transient(self
->transient_for
);
2721 for (it
= self
->group
->members
; it
; it
= it
->next
) {
2722 ObClient
*c
= it
->data
;
2724 /* checking transient_for prevents infinate loops! */
2725 if (c
!= self
&& !c
->transient_for
)
2736 ObClient
*client_search_transient(ObClient
*self
, ObClient
*search
)
2740 for (sit
= self
->transients
; sit
; sit
= g_slist_next(sit
)) {
2741 if (sit
->data
== search
)
2743 if (client_search_transient(sit
->data
, search
))
2749 gchar
* client_get_sm_client_id(ObClient
*self
)
2753 if (!PROP_GETS(self
->window
, sm_client_id
, locale
, &id
) && self
->group
)
2754 PROP_GETS(self
->group
->leader
, sm_client_id
, locale
, &id
);
2758 /* finds the nearest edge in the given direction from the current client
2759 * note to self: the edge is the -frame- edge (the actual one), not the
2762 int client_directional_edge_search(ObClient
*c
, ObDirection dir
)
2765 int my_edge_start
, my_edge_end
, my_offset
;
2772 a
= screen_area(c
->desktop
);
2775 case OB_DIRECTION_NORTH
:
2776 my_edge_start
= c
->frame
->area
.x
;
2777 my_edge_end
= c
->frame
->area
.x
+ c
->frame
->area
.width
;
2778 my_offset
= c
->frame
->area
.y
;
2780 dest
= a
->y
; /* default: top of screen */
2782 for(it
= g_list_first(client_list
); it
; it
= it
->next
) {
2783 int his_edge_start
, his_edge_end
, his_offset
;
2784 ObClient
*cur
= it
->data
;
2788 if(!client_normal(cur
))
2790 if(c
->desktop
!= cur
->desktop
&& cur
->desktop
!= DESKTOP_ALL
)
2795 his_edge_start
= cur
->frame
->area
.x
;
2796 his_edge_end
= cur
->frame
->area
.x
+ cur
->frame
->area
.width
;
2797 his_offset
= cur
->frame
->area
.y
+ cur
->frame
->area
.height
;
2799 if(his_offset
+ c
->size_inc
.height
> my_offset
)
2802 if(his_offset
< dest
)
2805 if(his_edge_start
>= my_edge_start
&&
2806 his_edge_start
<= my_edge_end
)
2809 if(my_edge_start
>= his_edge_start
&&
2810 my_edge_start
<= his_edge_end
)
2815 case OB_DIRECTION_SOUTH
:
2816 my_edge_start
= c
->frame
->area
.x
;
2817 my_edge_end
= c
->frame
->area
.x
+ c
->frame
->area
.width
;
2818 my_offset
= c
->frame
->area
.y
+ c
->frame
->area
.height
;
2820 dest
= a
->y
+ a
->height
; /* default: bottom of screen */
2822 for(it
= g_list_first(client_list
); it
; it
= it
->next
) {
2823 int his_edge_start
, his_edge_end
, his_offset
;
2824 ObClient
*cur
= it
->data
;
2828 if(!client_normal(cur
))
2830 if(c
->desktop
!= cur
->desktop
&& cur
->desktop
!= DESKTOP_ALL
)
2835 his_edge_start
= cur
->frame
->area
.x
;
2836 his_edge_end
= cur
->frame
->area
.x
+ cur
->frame
->area
.width
;
2837 his_offset
= cur
->frame
->area
.y
;
2840 if(his_offset
- c
->size_inc
.height
< my_offset
)
2843 if(his_offset
> dest
)
2846 if(his_edge_start
>= my_edge_start
&&
2847 his_edge_start
<= my_edge_end
)
2850 if(my_edge_start
>= his_edge_start
&&
2851 my_edge_start
<= his_edge_end
)
2856 case OB_DIRECTION_WEST
:
2857 my_edge_start
= c
->frame
->area
.y
;
2858 my_edge_end
= c
->frame
->area
.y
+ c
->frame
->area
.height
;
2859 my_offset
= c
->frame
->area
.x
;
2861 dest
= a
->x
; /* default: leftmost egde of screen */
2863 for(it
= g_list_first(client_list
); it
; it
= it
->next
) {
2864 int his_edge_start
, his_edge_end
, his_offset
;
2865 ObClient
*cur
= it
->data
;
2869 if(!client_normal(cur
))
2871 if(c
->desktop
!= cur
->desktop
&& cur
->desktop
!= DESKTOP_ALL
)
2876 his_edge_start
= cur
->frame
->area
.y
;
2877 his_edge_end
= cur
->frame
->area
.y
+ cur
->frame
->area
.height
;
2878 his_offset
= cur
->frame
->area
.x
+ cur
->frame
->area
.width
;
2880 if(his_offset
+ c
->size_inc
.width
> my_offset
)
2883 if(his_offset
< dest
)
2886 if(his_edge_start
>= my_edge_start
&&
2887 his_edge_start
<= my_edge_end
)
2890 if(my_edge_start
>= his_edge_start
&&
2891 my_edge_start
<= his_edge_end
)
2897 case OB_DIRECTION_EAST
:
2898 my_edge_start
= c
->frame
->area
.y
;
2899 my_edge_end
= c
->frame
->area
.y
+ c
->frame
->area
.height
;
2900 my_offset
= c
->frame
->area
.x
+ c
->frame
->area
.width
;
2902 dest
= a
->x
+ a
->width
; /* default: rightmost edge of screen */
2904 for(it
= g_list_first(client_list
); it
; it
= it
->next
) {
2905 int his_edge_start
, his_edge_end
, his_offset
;
2906 ObClient
*cur
= it
->data
;
2910 if(!client_normal(cur
))
2912 if(c
->desktop
!= cur
->desktop
&& cur
->desktop
!= DESKTOP_ALL
)
2917 his_edge_start
= cur
->frame
->area
.y
;
2918 his_edge_end
= cur
->frame
->area
.y
+ cur
->frame
->area
.height
;
2919 his_offset
= cur
->frame
->area
.x
;
2921 if(his_offset
- c
->size_inc
.width
< my_offset
)
2924 if(his_offset
> dest
)
2927 if(his_edge_start
>= my_edge_start
&&
2928 his_edge_start
<= my_edge_end
)
2931 if(my_edge_start
>= his_edge_start
&&
2932 my_edge_start
<= his_edge_end
)
2937 case OB_DIRECTION_NORTHEAST
:
2938 case OB_DIRECTION_SOUTHEAST
:
2939 case OB_DIRECTION_NORTHWEST
:
2940 case OB_DIRECTION_SOUTHWEST
:
2941 /* not implemented */
2944 g_assert_not_reached();