1 /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
3 client.c for the Openbox window manager
4 Copyright (c) 2006 Mikael Magnusson
5 Copyright (c) 2003-2007 Dana Jansens
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 See the COPYING file for a copy of the GNU General Public License.
22 #include "startupnotify.h"
26 #include "moveresize.h"
30 #include "extensions.h"
40 #include "menuframe.h"
43 #include "render/render.h"
51 # include <signal.h> /* for kill() */
55 #include <X11/Xutil.h>
57 /*! The event mask to grab on client windows */
58 #define CLIENT_EVENTMASK (PropertyChangeMask | StructureNotifyMask | \
61 #define CLIENT_NOPROPAGATEMASK (ButtonPressMask | ButtonReleaseMask | \
66 ObClientCallback func
;
70 GList
*client_list
= NULL
;
72 static GSList
*client_destroy_notifies
= NULL
;
74 static void client_get_all(ObClient
*self
, gboolean real
);
75 static void client_get_startup_id(ObClient
*self
);
76 static void client_get_session_ids(ObClient
*self
);
77 static void client_get_area(ObClient
*self
);
78 static void client_get_desktop(ObClient
*self
);
79 static void client_get_state(ObClient
*self
);
80 static void client_get_shaped(ObClient
*self
);
81 static void client_get_mwm_hints(ObClient
*self
);
82 static void client_get_colormap(ObClient
*self
);
83 static void client_set_desktop_recursive(ObClient
*self
,
87 static void client_change_allowed_actions(ObClient
*self
);
88 static void client_change_state(ObClient
*self
);
89 static void client_change_wm_state(ObClient
*self
);
90 static void client_apply_startup_state(ObClient
*self
,
91 gint x
, gint y
, gint w
, gint h
);
92 static void client_restore_session_state(ObClient
*self
);
93 static gboolean
client_restore_session_stacking(ObClient
*self
);
94 static ObAppSettings
*client_get_settings_state(ObClient
*self
);
95 static void client_update_transient_tree(ObClient
*self
,
96 ObGroup
*oldgroup
, ObGroup
*newgroup
,
97 gboolean oldgtran
, gboolean newgtran
,
100 static void client_present(ObClient
*self
, gboolean here
, gboolean raise
,
102 static GSList
*client_search_all_top_parents_internal(ObClient
*self
,
104 ObStackingLayer layer
);
105 static void client_call_notifies(ObClient
*self
, GSList
*list
);
106 static void client_ping_event(ObClient
*self
, gboolean dead
);
109 void client_startup(gboolean reconfig
)
111 if (reconfig
) return;
116 void client_shutdown(gboolean reconfig
)
118 if (reconfig
) return;
121 static void client_call_notifies(ObClient
*self
, GSList
*list
)
125 for (it
= list
; it
; it
= g_slist_next(it
)) {
126 ClientCallback
*d
= it
->data
;
127 d
->func(self
, d
->data
);
131 void client_add_destroy_notify(ObClientCallback func
, gpointer data
)
133 ClientCallback
*d
= g_new(ClientCallback
, 1);
136 client_destroy_notifies
= g_slist_prepend(client_destroy_notifies
, d
);
139 void client_remove_destroy_notify(ObClientCallback func
)
143 for (it
= client_destroy_notifies
; it
; it
= g_slist_next(it
)) {
144 ClientCallback
*d
= it
->data
;
145 if (d
->func
== func
) {
147 client_destroy_notifies
=
148 g_slist_delete_link(client_destroy_notifies
, it
);
154 void client_set_list(void)
156 Window
*windows
, *win_it
;
158 guint size
= g_list_length(client_list
);
160 /* create an array of the window ids */
162 windows
= g_new(Window
, size
);
164 for (it
= client_list
; it
; it
= g_list_next(it
), ++win_it
)
165 *win_it
= ((ObClient
*)it
->data
)->window
;
169 PROP_SETA32(RootWindow(ob_display
, ob_screen
),
170 net_client_list
, window
, (gulong
*)windows
, size
);
178 void client_manage_all(void)
183 XWindowAttributes attrib
;
185 XQueryTree(ob_display
, RootWindow(ob_display
, ob_screen
),
186 &w
, &w
, &children
, &nchild
);
188 /* remove all icon windows from the list */
189 for (i
= 0; i
< nchild
; i
++) {
190 if (children
[i
] == None
) continue;
191 wmhints
= XGetWMHints(ob_display
, children
[i
]);
193 if ((wmhints
->flags
& IconWindowHint
) &&
194 (wmhints
->icon_window
!= children
[i
]))
195 for (j
= 0; j
< nchild
; j
++)
196 if (children
[j
] == wmhints
->icon_window
) {
204 for (i
= 0; i
< nchild
; ++i
) {
205 if (children
[i
] == None
)
207 if (XGetWindowAttributes(ob_display
, children
[i
], &attrib
)) {
208 if (attrib
.override_redirect
) continue;
210 if (attrib
.map_state
!= IsUnmapped
)
211 client_manage(children
[i
]);
217 void client_manage(Window window
)
221 XWindowAttributes attrib
;
222 XSetWindowAttributes attrib_set
;
224 gboolean activate
= FALSE
;
225 ObAppSettings
*settings
;
226 gboolean transient
= FALSE
;
227 Rect place
, *monitor
;
228 Time launch_time
, map_time
;
232 /* check if it has already been unmapped by the time we started
233 mapping. the grab does a sync so we don't have to here */
234 if (XCheckTypedWindowEvent(ob_display
, window
, DestroyNotify
, &e
) ||
235 XCheckTypedWindowEvent(ob_display
, window
, UnmapNotify
, &e
))
237 XPutBackEvent(ob_display
, &e
);
239 ob_debug("Trying to manage unmapped window. Aborting that.\n");
241 return; /* don't manage it */
244 /* make sure it isn't an override-redirect window */
245 if (!XGetWindowAttributes(ob_display
, window
, &attrib
) ||
246 attrib
.override_redirect
)
249 return; /* don't manage it */
252 /* is the window a docking app */
253 if ((wmhint
= XGetWMHints(ob_display
, window
))) {
254 if ((wmhint
->flags
& StateHint
) &&
255 wmhint
->initial_state
== WithdrawnState
)
257 dock_add(window
, wmhint
);
265 ob_debug("Managing window: 0x%lx\n", window
);
267 map_time
= event_get_server_time();
269 /* choose the events we want to receive on the CLIENT window */
270 attrib_set
.event_mask
= CLIENT_EVENTMASK
;
271 attrib_set
.do_not_propagate_mask
= CLIENT_NOPROPAGATEMASK
;
272 XChangeWindowAttributes(ob_display
, window
,
273 CWEventMask
|CWDontPropagate
, &attrib_set
);
275 /* create the ObClient struct, and populate it from the hints on the
277 self
= g_new0(ObClient
, 1);
278 self
->obwin
.type
= Window_Client
;
279 self
->window
= window
;
281 /* non-zero defaults */
282 self
->wmstate
= WithdrawnState
; /* make sure it gets updated first time */
283 self
->gravity
= NorthWestGravity
;
284 self
->desktop
= screen_num_desktops
; /* always an invalid value */
286 /* get all the stuff off the window */
287 client_get_all(self
, TRUE
);
289 ob_debug("Window type: %d\n", self
->type
);
290 ob_debug("Window group: 0x%x\n", self
->group
?self
->group
->leader
:0);
292 /* specify that if we exit, the window should not be destroyed and
293 should be reparented back to root automatically */
294 XChangeSaveSet(ob_display
, window
, SetModeInsert
);
296 /* create the decoration frame for the client window */
297 self
->frame
= frame_new(self
);
299 frame_grab_client(self
->frame
);
301 /* we've grabbed everything and set everything that we need to at mapping
305 /* per-app settings override stuff from client_get_all, and return the
306 settings for other uses too. the returned settings is a shallow copy,
307 that needs to be freed with g_free(). */
308 settings
= client_get_settings_state(self
);
309 /* the session should get the last say though */
310 client_restore_session_state(self
);
312 /* now we have all of the window's information so we can set this up */
313 client_setup_decor_and_functions(self
, FALSE
);
315 /* tell startup notification that this app started */
316 launch_time
= sn_app_started(self
->startup_id
, self
->class, self
->name
);
318 /* do this after we have a frame.. it uses the frame to help determine the
319 WM_STATE to apply. */
320 client_change_state(self
);
322 /* add ourselves to the focus order */
323 focus_order_add_new(self
);
325 /* do this to add ourselves to the stacking list in a non-intrusive way */
326 client_calc_layer(self
);
328 /* focus the new window? */
329 if (ob_state() != OB_STATE_STARTING
&&
330 (!self
->session
|| self
->session
->focused
) &&
331 /* this means focus=true for window is same as config_focus_new=true */
332 ((config_focus_new
|| (settings
&& settings
->focus
== 1)) ||
333 client_search_focus_tree_full(self
)) &&
334 /* this checks for focus=false for the window */
335 (!settings
|| settings
->focus
!= 0) &&
336 focus_valid_target(self
, FALSE
, FALSE
, TRUE
, FALSE
, FALSE
))
341 /* remove the client's border */
342 XSetWindowBorderWidth(ob_display
, self
->window
, 0);
344 /* adjust the frame to the client's size before showing or placing
346 frame_adjust_area(self
->frame
, FALSE
, TRUE
, FALSE
);
347 frame_adjust_client_area(self
->frame
);
349 /* where the frame was placed is where the window was originally */
351 monitor
= screen_physical_area_monitor(screen_find_monitor(&place
));
353 /* figure out placement for the window if the window is new */
354 if (ob_state() == OB_STATE_RUNNING
) {
355 ob_debug("Positioned: %s @ %d %d\n",
356 (!self
->positioned
? "no" :
357 (self
->positioned
== PPosition
? "program specified" :
358 (self
->positioned
== USPosition
? "user specified" :
359 (self
->positioned
== (PPosition
| USPosition
) ?
360 "program + user specified" :
361 "BADNESS !?")))), place
.x
, place
.y
);
363 ob_debug("Sized: %s @ %d %d\n",
364 (!self
->sized
? "no" :
365 (self
->sized
== PSize
? "program specified" :
366 (self
->sized
== USSize
? "user specified" :
367 (self
->sized
== (PSize
| USSize
) ?
368 "program + user specified" :
369 "BADNESS !?")))), place
.width
, place
.height
);
371 /* splash screens are also returned as TRUE for transient,
372 and so will be forced on screen below */
373 transient
= place_client(self
, &place
.x
, &place
.y
, settings
);
375 /* make sure the window is visible. */
376 client_find_onscreen(self
, &place
.x
, &place
.y
,
377 place
.width
, place
.height
,
378 /* non-normal clients has less rules, and
379 windows that are being restored from a
380 session do also. we can assume you want
381 it back where you saved it. Clients saying
382 they placed themselves are subjected to
383 harder rules, ones that are placed by
384 place.c or by the user are allowed partially
385 off-screen and on xinerama divides (ie,
386 it is up to the placement routines to avoid
387 the xinerama divides)
389 splash screens get "transient" set to TRUE by
390 the place_client call
392 ob_state() == OB_STATE_RUNNING
&&
394 (!((self
->positioned
& USPosition
) ||
395 (settings
&& settings
->pos_given
)) &&
396 client_normal(self
) &&
398 /* don't move oldschool fullscreen windows to
399 fit inside the struts (fixes Acroread, which
400 makes its fullscreen window fit the screen
401 but it is not USSize'd or USPosition'd) */
402 !(self
->decorations
== 0 &&
403 RECT_EQUAL(place
, *monitor
)))));
406 /* if the window isn't user-sized, then make it fit inside
407 the visible screen area on its monitor. Use basically the same rules
408 for forcing the window on screen in the client_find_onscreen call.
410 do this after place_client, it chooses the monitor!
412 splash screens get "transient" set to TRUE by
413 the place_client call
415 if (ob_state() == OB_STATE_RUNNING
&&
417 (!(self
->sized
& USSize
|| self
->positioned
& USPosition
) &&
418 client_normal(self
) &&
420 /* don't shrink oldschool fullscreen windows to fit inside the
421 struts (fixes Acroread, which makes its fullscreen window
422 fit the screen but it is not USSize'd or USPosition'd) */
423 !(self
->decorations
== 0 && RECT_EQUAL(place
, *monitor
)))))
425 Rect
*a
= screen_area(self
->desktop
, SCREEN_AREA_ONE_MONITOR
, &place
);
427 /* get the size of the frame */
428 place
.width
+= self
->frame
->size
.left
+ self
->frame
->size
.right
;
429 place
.height
+= self
->frame
->size
.top
+ self
->frame
->size
.bottom
;
431 /* fit the window inside the area */
432 place
.width
= MIN(place
.width
, a
->width
);
433 place
.height
= MIN(place
.height
, a
->height
);
435 ob_debug("setting window size to %dx%d\n", place
.width
, place
.height
);
437 /* get the size of the client back */
438 place
.width
-= self
->frame
->size
.left
+ self
->frame
->size
.right
;
439 place
.height
-= self
->frame
->size
.top
+ self
->frame
->size
.bottom
;
444 ob_debug("placing window 0x%x at %d, %d with size %d x %d. "
445 "some restrictions may apply\n",
446 self
->window
, place
.x
, place
.y
, place
.width
, place
.height
);
448 ob_debug(" but session requested %d, %d %d x %d instead, "
450 self
->session
->x
, self
->session
->y
,
451 self
->session
->w
, self
->session
->h
);
453 /* do this after the window is placed, so the premax/prefullscreen numbers
456 this also places the window
458 client_apply_startup_state(self
, place
.x
, place
.y
,
459 place
.width
, place
.height
);
464 ob_debug_type(OB_DEBUG_FOCUS
, "Going to try activate new window? %s\n",
465 activate
? "yes" : "no");
467 gboolean raise
= FALSE
;
469 /* This is focus stealing prevention */
470 ob_debug_type(OB_DEBUG_FOCUS
,
471 "Want to focus new window 0x%x at time %u "
472 "launched at %u (last user interaction time %u)\n",
473 self
->window
, map_time
, launch_time
,
474 event_last_user_time
);
476 if (menu_frame_visible
|| moveresize_in_progress
) {
479 ob_debug_type(OB_DEBUG_FOCUS
,
480 "Not focusing the window because the user is inside "
481 "an Openbox menu or is move/resizing a window and "
482 "we don't want to interrupt them\n");
485 /* if it's on another desktop */
486 else if (!(self
->desktop
== screen_desktop
||
487 self
->desktop
== DESKTOP_ALL
) &&
488 /* the timestamp is from before you changed desktops */
489 launch_time
&& screen_desktop_user_time
&&
490 !event_time_after(launch_time
, screen_desktop_user_time
))
494 ob_debug_type(OB_DEBUG_FOCUS
,
495 "Not focusing the window because its on another "
498 /* If something is focused, and it's not our relative... */
499 else if (focus_client
&& client_search_focus_tree_full(self
) == NULL
&&
500 client_search_focus_group_full(self
) == NULL
)
502 /* If the user is working in another window right now, then don't
504 if (event_last_user_time
&& launch_time
&&
505 event_time_after(event_last_user_time
, launch_time
) &&
506 event_last_user_time
!= launch_time
&&
507 event_time_after(event_last_user_time
,
508 map_time
- OB_EVENT_USER_TIME_DELAY
))
511 ob_debug_type(OB_DEBUG_FOCUS
,
512 "Not focusing the window because the user is "
513 "working in another window\n");
515 /* If its a transient (and its parents aren't focused) */
516 else if (client_has_parent(self
)) {
518 ob_debug_type(OB_DEBUG_FOCUS
,
519 "Not focusing the window because it is a "
520 "transient, and its relatives aren't focused\n");
522 /* Don't steal focus from globally active clients.
523 I stole this idea from KWin. It seems nice.
525 else if (!(focus_client
->can_focus
||
526 focus_client
->focus_notify
))
529 ob_debug_type(OB_DEBUG_FOCUS
,
530 "Not focusing the window because a globally "
531 "active client has focus\n");
533 /* Don't move focus if it's not going to go to this window
535 else if (client_focus_target(self
) != self
) {
538 ob_debug_type(OB_DEBUG_FOCUS
,
539 "Not focusing the window because another window "
540 "would get the focus anyway\n");
542 else if (!(self
->desktop
== screen_desktop
||
543 self
->desktop
== DESKTOP_ALL
))
547 ob_debug_type(OB_DEBUG_FOCUS
,
548 "Not focusing the window because it is on "
549 "another desktop and no relatives are focused ");
554 ob_debug_type(OB_DEBUG_FOCUS
,
555 "Focus stealing prevention activated for %s at "
556 "time %u (last user interactioon time %u)\n",
557 self
->title
, map_time
, event_last_user_time
);
558 /* if the client isn't focused, then hilite it so the user
560 client_hilite(self
, TRUE
);
561 /* we may want to raise it even tho we're not activating it */
562 if (raise
&& !client_restore_session_stacking(self
))
563 stacking_raise(CLIENT_AS_WINDOW(self
));
567 /* This may look rather odd. Well it's because new windows are added
568 to the stacking order non-intrusively. If we're not going to focus
569 the new window or hilite it, then we raise it to the top. This will
570 take affect for things that don't get focused like splash screens.
571 Also if you don't have focus_new enabled, then it's going to get
572 raised to the top. Legacy begets legacy I guess?
574 if (!client_restore_session_stacking(self
))
575 stacking_raise(CLIENT_AS_WINDOW(self
));
578 mouse_grab_for_client(self
, TRUE
);
580 /* this has to happen before we try focus the window, but we want it to
581 happen after the client's stacking has been determined or it looks bad
585 if (!config_focus_under_mouse
)
586 ignore_start
= event_start_ignore_all_enters();
590 if (!config_focus_under_mouse
)
591 event_end_ignore_all_enters(ignore_start
);
595 gboolean stacked
= client_restore_session_stacking(self
);
596 client_present(self
, FALSE
, !stacked
, TRUE
);
599 /* add to client list/map */
600 client_list
= g_list_append(client_list
, self
);
601 g_hash_table_insert(window_map
, &self
->window
, self
);
603 /* this has to happen after we're in the client_list */
604 if (STRUT_EXISTS(self
->strut
))
605 screen_update_areas();
607 /* update the list hints */
610 /* watch for when the application stops responding. only do this for
611 normal windows, i.e. windows which have titlebars and close buttons
612 and things like that.
613 we don't need to stop pinging on unmanage, because it will be handled
614 automatically by the destroy callback!
616 if (self
->ping
&& client_normal(self
))
617 ping_start(self
, client_ping_event
);
619 /* free the ObAppSettings shallow copy */
622 ob_debug("Managed window 0x%lx plate 0x%x (%s)\n",
623 window
, self
->frame
->window
, self
->class);
629 ObClient
*client_fake_manage(Window window
)
632 ObAppSettings
*settings
;
634 ob_debug("Pretend-managing window: %lx\n", window
);
636 /* do this minimal stuff to figure out the client's decorations */
638 self
= g_new0(ObClient
, 1);
639 self
->window
= window
;
641 client_get_all(self
, FALSE
);
642 /* per-app settings override stuff, and return the settings for other
643 uses too. this returns a shallow copy that needs to be freed */
644 settings
= client_get_settings_state(self
);
646 client_setup_decor_and_functions(self
, FALSE
);
648 /* create the decoration frame for the client window and adjust its size */
649 self
->frame
= frame_new(self
);
650 frame_adjust_area(self
->frame
, FALSE
, TRUE
, TRUE
);
652 ob_debug("gave extents left %d right %d top %d bottom %d\n",
653 self
->frame
->size
.left
, self
->frame
->size
.right
,
654 self
->frame
->size
.top
, self
->frame
->size
.bottom
);
656 /* free the ObAppSettings shallow copy */
662 void client_unmanage_all(void)
664 while (client_list
!= NULL
)
665 client_unmanage(client_list
->data
);
668 void client_unmanage(ObClient
*self
)
674 ob_debug("Unmanaging window: 0x%x plate 0x%x (%s) (%s)\n",
675 self
->window
, self
->frame
->window
,
676 self
->class, self
->title
? self
->title
: "");
678 g_assert(self
!= NULL
);
680 /* we dont want events no more. do this before hiding the frame so we
681 don't generate more events */
682 XSelectInput(ob_display
, self
->window
, NoEventMask
);
684 /* ignore enter events from the unmap so it doesnt mess with the focus */
685 if (!config_focus_under_mouse
)
686 ignore_start
= event_start_ignore_all_enters();
688 frame_hide(self
->frame
);
689 /* flush to send the hide to the server quickly */
692 if (!config_focus_under_mouse
)
693 event_end_ignore_all_enters(ignore_start
);
695 mouse_grab_for_client(self
, FALSE
);
697 /* remove the window from our save set */
698 XChangeSaveSet(ob_display
, self
->window
, SetModeDelete
);
700 /* update the focus lists */
701 focus_order_remove(self
);
702 if (client_focused(self
)) {
703 /* don't leave an invalid focus_client */
707 client_list
= g_list_remove(client_list
, self
);
708 stacking_remove(self
);
709 g_hash_table_remove(window_map
, &self
->window
);
711 /* once the client is out of the list, update the struts to remove its
713 if (STRUT_EXISTS(self
->strut
))
714 screen_update_areas();
716 client_call_notifies(self
, client_destroy_notifies
);
718 /* tell our parent(s) that we're gone */
719 for (it
= self
->parents
; it
; it
= g_slist_next(it
))
720 ((ObClient
*)it
->data
)->transients
=
721 g_slist_remove(((ObClient
*)it
->data
)->transients
,self
);
723 /* tell our transients that we're gone */
724 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
725 ((ObClient
*)it
->data
)->parents
=
726 g_slist_remove(((ObClient
*)it
->data
)->parents
, self
);
727 /* we could be keeping our children in a higher layer */
728 client_calc_layer(it
->data
);
731 /* remove from its group */
733 group_remove(self
->group
, self
);
737 /* restore the window's original geometry so it is not lost */
743 if (self
->fullscreen
)
744 a
= self
->pre_fullscreen_area
;
745 else if (self
->max_horz
|| self
->max_vert
) {
746 if (self
->max_horz
) {
747 a
.x
= self
->pre_max_area
.x
;
748 a
.width
= self
->pre_max_area
.width
;
750 if (self
->max_vert
) {
751 a
.y
= self
->pre_max_area
.y
;
752 a
.height
= self
->pre_max_area
.height
;
756 self
->fullscreen
= self
->max_horz
= self
->max_vert
= FALSE
;
757 /* let it be moved and resized no matter what */
758 self
->functions
= OB_CLIENT_FUNC_MOVE
| OB_CLIENT_FUNC_RESIZE
;
759 self
->decorations
= 0; /* unmanaged windows have no decor */
761 /* give the client its border back */
762 XSetWindowBorderWidth(ob_display
, self
->window
, self
->border_width
);
764 client_move_resize(self
, a
.x
, a
.y
, a
.width
, a
.height
);
767 /* reparent the window out of the frame, and free the frame */
768 frame_release_client(self
->frame
);
769 frame_free(self
->frame
);
772 if (ob_state() != OB_STATE_EXITING
) {
773 /* these values should not be persisted across a window
775 PROP_ERASE(self
->window
, net_wm_desktop
);
776 PROP_ERASE(self
->window
, net_wm_state
);
777 PROP_ERASE(self
->window
, wm_state
);
779 /* if we're left in an unmapped state, the client wont be mapped.
780 this is bad, since we will no longer be managing the window on
782 XMapWindow(ob_display
, self
->window
);
785 /* these should not be left on the window ever. other window managers
786 don't necessarily use them and it will mess them up (like compiz) */
787 PROP_ERASE(self
->window
, net_wm_visible_name
);
788 PROP_ERASE(self
->window
, net_wm_visible_icon_name
);
790 /* update the list hints */
793 ob_debug("Unmanaged window 0x%lx\n", self
->window
);
795 /* free all data allocated in the client struct */
796 g_slist_free(self
->transients
);
797 for (j
= 0; j
< self
->nicons
; ++j
)
798 g_free(self
->icons
[j
].data
);
799 if (self
->nicons
> 0)
801 g_free(self
->wm_command
);
803 g_free(self
->icon_title
);
807 g_free(self
->client_machine
);
808 g_free(self
->sm_client_id
);
812 void client_fake_unmanage(ObClient
*self
)
814 /* this is all that got allocated to get the decorations */
816 frame_free(self
->frame
);
820 /*! Returns a new structure containing the per-app settings for this client.
821 The returned structure needs to be freed with g_free. */
822 static ObAppSettings
*client_get_settings_state(ObClient
*self
)
824 ObAppSettings
*settings
;
827 settings
= config_create_app_settings();
829 for (it
= config_per_app_settings
; it
; it
= g_slist_next(it
)) {
830 ObAppSettings
*app
= it
->data
;
831 gboolean match
= TRUE
;
833 g_assert(app
->name
!= NULL
|| app
->class != NULL
);
835 /* we know that either name or class is not NULL so it will have to
836 match to use the rule */
838 !g_pattern_match(app
->name
, strlen(self
->name
), self
->name
, NULL
))
840 else if (app
->class &&
841 !g_pattern_match(app
->class,
842 strlen(self
->class), self
->class, NULL
))
844 else if (app
->role
&&
845 !g_pattern_match(app
->role
,
846 strlen(self
->role
), self
->role
, NULL
))
850 ob_debug("Window matching: %s\n", app
->name
);
852 /* copy the settings to our struct, overriding the existing
853 settings if they are not defaults */
854 config_app_settings_copy_non_defaults(app
, settings
);
858 if (settings
->shade
!= -1)
859 self
->shaded
= !!settings
->shade
;
860 if (settings
->decor
!= -1)
861 self
->undecorated
= !settings
->decor
;
862 if (settings
->iconic
!= -1)
863 self
->iconic
= !!settings
->iconic
;
864 if (settings
->skip_pager
!= -1)
865 self
->skip_pager
= !!settings
->skip_pager
;
866 if (settings
->skip_taskbar
!= -1)
867 self
->skip_taskbar
= !!settings
->skip_taskbar
;
869 if (settings
->max_vert
!= -1)
870 self
->max_vert
= !!settings
->max_vert
;
871 if (settings
->max_horz
!= -1)
872 self
->max_horz
= !!settings
->max_horz
;
874 if (settings
->fullscreen
!= -1)
875 self
->fullscreen
= !!settings
->fullscreen
;
877 if (settings
->desktop
) {
878 if (settings
->desktop
== DESKTOP_ALL
)
879 self
->desktop
= settings
->desktop
;
880 else if (settings
->desktop
> 0 &&
881 settings
->desktop
<= screen_num_desktops
)
882 self
->desktop
= settings
->desktop
- 1;
885 if (settings
->layer
== -1) {
889 else if (settings
->layer
== 0) {
893 else if (settings
->layer
== 1) {
900 static void client_restore_session_state(ObClient
*self
)
904 ob_debug_type(OB_DEBUG_SM
,
905 "Restore session for client %s\n", self
->title
);
907 if (!(it
= session_state_find(self
))) {
908 ob_debug_type(OB_DEBUG_SM
,
909 "Session data not found for client %s\n", self
->title
);
913 self
->session
= it
->data
;
915 ob_debug_type(OB_DEBUG_SM
, "Session data loaded for client %s\n",
918 RECT_SET_POINT(self
->area
, self
->session
->x
, self
->session
->y
);
919 self
->positioned
= USPosition
;
920 self
->sized
= USSize
;
921 if (self
->session
->w
> 0)
922 self
->area
.width
= self
->session
->w
;
923 if (self
->session
->h
> 0)
924 self
->area
.height
= self
->session
->h
;
925 XResizeWindow(ob_display
, self
->window
,
926 self
->area
.width
, self
->area
.height
);
928 self
->desktop
= (self
->session
->desktop
== DESKTOP_ALL
?
929 self
->session
->desktop
:
930 MIN(screen_num_desktops
- 1, self
->session
->desktop
));
931 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, self
->desktop
);
933 self
->shaded
= self
->session
->shaded
;
934 self
->iconic
= self
->session
->iconic
;
935 self
->skip_pager
= self
->session
->skip_pager
;
936 self
->skip_taskbar
= self
->session
->skip_taskbar
;
937 self
->fullscreen
= self
->session
->fullscreen
;
938 self
->above
= self
->session
->above
;
939 self
->below
= self
->session
->below
;
940 self
->max_horz
= self
->session
->max_horz
;
941 self
->max_vert
= self
->session
->max_vert
;
942 self
->undecorated
= self
->session
->undecorated
;
945 static gboolean
client_restore_session_stacking(ObClient
*self
)
949 if (!self
->session
) return FALSE
;
951 mypos
= g_list_find(session_saved_state
, self
->session
);
952 if (!mypos
) return FALSE
;
954 /* start above me and look for the first client */
955 for (it
= g_list_previous(mypos
); it
; it
= g_list_previous(it
)) {
958 for (cit
= client_list
; cit
; cit
= g_list_next(cit
)) {
959 ObClient
*c
= cit
->data
;
960 /* found a client that was in the session, so go below it */
961 if (c
->session
== it
->data
) {
962 stacking_below(CLIENT_AS_WINDOW(self
),
963 CLIENT_AS_WINDOW(cit
->data
));
971 void client_move_onscreen(ObClient
*self
, gboolean rude
)
973 gint x
= self
->area
.x
;
974 gint y
= self
->area
.y
;
975 if (client_find_onscreen(self
, &x
, &y
,
977 self
->area
.height
, rude
)) {
978 client_move(self
, x
, y
);
982 gboolean
client_find_onscreen(ObClient
*self
, gint
*x
, gint
*y
, gint w
, gint h
,
985 gint ox
= *x
, oy
= *y
;
986 gboolean rudel
= rude
, ruder
= rude
, rudet
= rude
, rudeb
= rude
;
991 RECT_SET(desired
, *x
, *y
, w
, h
);
992 frame_rect_to_frame(self
->frame
, &desired
);
994 /* get where the frame would be */
995 frame_client_gravity(self
->frame
, x
, y
);
997 /* get the requested size of the window with decorations */
998 fw
= self
->frame
->size
.left
+ w
+ self
->frame
->size
.right
;
999 fh
= self
->frame
->size
.top
+ h
+ self
->frame
->size
.bottom
;
1001 /* If rudeness wasn't requested, then still be rude in a given direction
1002 if the client is not moving, only resizing in that direction */
1004 Point oldtl
, oldtr
, oldbl
, oldbr
;
1005 Point newtl
, newtr
, newbl
, newbr
;
1006 gboolean stationary_l
, stationary_r
, stationary_t
, stationary_b
;
1008 POINT_SET(oldtl
, self
->frame
->area
.x
, self
->frame
->area
.y
);
1009 POINT_SET(oldbr
, self
->frame
->area
.x
+ self
->frame
->area
.width
- 1,
1010 self
->frame
->area
.y
+ self
->frame
->area
.height
- 1);
1011 POINT_SET(oldtr
, oldbr
.x
, oldtl
.y
);
1012 POINT_SET(oldbl
, oldtl
.x
, oldbr
.y
);
1014 POINT_SET(newtl
, *x
, *y
);
1015 POINT_SET(newbr
, *x
+ fw
- 1, *y
+ fh
- 1);
1016 POINT_SET(newtr
, newbr
.x
, newtl
.y
);
1017 POINT_SET(newbl
, newtl
.x
, newbr
.y
);
1019 /* is it moving or just resizing from some corner? */
1020 stationary_l
= oldtl
.x
== newtl
.x
;
1021 stationary_r
= oldtr
.x
== newtr
.x
;
1022 stationary_t
= oldtl
.y
== newtl
.y
;
1023 stationary_b
= oldbl
.y
== newbl
.y
;
1025 /* if left edge is growing and didnt move right edge */
1026 if (stationary_r
&& newtl
.x
< oldtl
.x
)
1028 /* if right edge is growing and didnt move left edge */
1029 if (stationary_l
&& newtr
.x
> oldtr
.x
)
1031 /* if top edge is growing and didnt move bottom edge */
1032 if (stationary_b
&& newtl
.y
< oldtl
.y
)
1034 /* if bottom edge is growing and didnt move top edge */
1035 if (stationary_t
&& newbl
.y
> oldbl
.y
)
1039 for (i
= 0; i
< screen_num_monitors
; ++i
) {
1042 if (!screen_physical_area_monitor_contains(i
, &desired
)) {
1043 if (i
< screen_num_monitors
- 1)
1046 /* the window is not inside any monitor! so just use the first
1048 a
= screen_area(self
->desktop
, 0, NULL
);
1050 a
= screen_area(self
->desktop
, SCREEN_AREA_ONE_MONITOR
, &desired
);
1052 /* This makes sure windows aren't entirely outside of the screen so you
1053 can't see them at all.
1054 It makes sure 10% of the window is on the screen at least. At don't
1055 let it move itself off the top of the screen, which would hide the
1056 titlebar on you. (The user can still do this if they want too, it's
1057 only limiting the application.
1059 if (client_normal(self
)) {
1060 if (!self
->strut
.right
&& *x
+ fw
/10 >= a
->x
+ a
->width
- 1)
1061 *x
= a
->x
+ a
->width
- fw
/10;
1062 if (!self
->strut
.bottom
&& *y
+ fh
/10 >= a
->y
+ a
->height
- 1)
1063 *y
= a
->y
+ a
->height
- fh
/10;
1064 if (!self
->strut
.left
&& *x
+ fw
*9/10 - 1 < a
->x
)
1065 *x
= a
->x
- fw
*9/10;
1066 if (!self
->strut
.top
&& *y
+ fh
*9/10 - 1 < a
->y
)
1067 *y
= a
->y
- fh
*9/10;
1070 /* This here doesn't let windows even a pixel outside the
1071 struts/screen. When called from client_manage, programs placing
1072 themselves are forced completely onscreen, while things like
1073 xterm -geometry resolution-width/2 will work fine. Trying to
1074 place it completely offscreen will be handled in the above code.
1075 Sorry for this confused comment, i am tired. */
1076 if (rudel
&& !self
->strut
.left
&& *x
< a
->x
) *x
= a
->x
;
1077 if (ruder
&& !self
->strut
.right
&& *x
+ fw
> a
->x
+ a
->width
)
1078 *x
= a
->x
+ MAX(0, a
->width
- fw
);
1080 if (rudet
&& !self
->strut
.top
&& *y
< a
->y
) *y
= a
->y
;
1081 if (rudeb
&& !self
->strut
.bottom
&& *y
+ fh
> a
->y
+ a
->height
)
1082 *y
= a
->y
+ MAX(0, a
->height
- fh
);
1087 /* get where the client should be */
1088 frame_frame_gravity(self
->frame
, x
, y
);
1090 return ox
!= *x
|| oy
!= *y
;
1093 static void client_get_all(ObClient
*self
, gboolean real
)
1095 /* this is needed for the frame to set itself up */
1096 client_get_area(self
);
1098 /* these things can change the decor and functions of the window */
1100 client_get_mwm_hints(self
);
1101 /* this can change the mwmhints for special cases */
1102 client_get_type_and_transientness(self
);
1103 client_get_state(self
);
1104 client_update_normal_hints(self
);
1106 /* get the session related properties, these can change decorations
1107 from per-app settings */
1108 client_get_session_ids(self
);
1110 /* now we got everything that can affect the decorations */
1114 /* get this early so we have it for debugging */
1115 client_update_title(self
);
1117 client_update_protocols(self
);
1119 client_update_wmhints(self
);
1120 /* this may have already been called from client_update_wmhints */
1121 if (!self
->parents
&& !self
->transient_for_group
)
1122 client_update_transient_for(self
);
1124 client_get_startup_id(self
);
1125 client_get_desktop(self
);/* uses transient data/group/startup id if a
1126 desktop is not specified */
1127 client_get_shaped(self
);
1130 /* a couple type-based defaults for new windows */
1132 /* this makes sure that these windows appear on all desktops */
1133 if (self
->type
== OB_CLIENT_TYPE_DESKTOP
)
1134 self
->desktop
= DESKTOP_ALL
;
1138 client_update_sync_request_counter(self
);
1141 client_get_colormap(self
);
1142 client_update_strut(self
);
1143 client_update_icons(self
);
1144 client_update_icon_geometry(self
);
1147 static void client_get_startup_id(ObClient
*self
)
1149 if (!(PROP_GETS(self
->window
, net_startup_id
, utf8
, &self
->startup_id
)))
1151 PROP_GETS(self
->group
->leader
,
1152 net_startup_id
, utf8
, &self
->startup_id
);
1155 static void client_get_area(ObClient
*self
)
1157 XWindowAttributes wattrib
;
1160 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
1161 g_assert(ret
!= BadWindow
);
1163 RECT_SET(self
->area
, wattrib
.x
, wattrib
.y
, wattrib
.width
, wattrib
.height
);
1164 POINT_SET(self
->root_pos
, wattrib
.x
, wattrib
.y
);
1165 self
->border_width
= wattrib
.border_width
;
1167 ob_debug("client area: %d %d %d %d bw %d\n", wattrib
.x
, wattrib
.y
,
1168 wattrib
.width
, wattrib
.height
, wattrib
.border_width
);
1171 static void client_get_desktop(ObClient
*self
)
1173 guint32 d
= screen_num_desktops
; /* an always-invalid value */
1175 if (PROP_GET32(self
->window
, net_wm_desktop
, cardinal
, &d
)) {
1176 if (d
>= screen_num_desktops
&& d
!= DESKTOP_ALL
)
1177 self
->desktop
= screen_num_desktops
- 1;
1180 ob_debug("client requested desktop 0x%x\n", self
->desktop
);
1183 gboolean first
= TRUE
;
1184 guint all
= screen_num_desktops
; /* not a valid value */
1186 /* if they are all on one desktop, then open it on the
1188 for (it
= self
->parents
; it
; it
= g_slist_next(it
)) {
1189 ObClient
*c
= it
->data
;
1191 if (c
->desktop
== DESKTOP_ALL
) continue;
1197 else if (all
!= c
->desktop
)
1198 all
= screen_num_desktops
; /* make it invalid */
1200 if (all
!= screen_num_desktops
) {
1201 self
->desktop
= all
;
1203 ob_debug("client desktop set from parents: 0x%x\n",
1206 /* try get from the startup-notification protocol */
1207 else if (sn_get_desktop(self
->startup_id
, &self
->desktop
)) {
1208 if (self
->desktop
>= screen_num_desktops
&&
1209 self
->desktop
!= DESKTOP_ALL
)
1210 self
->desktop
= screen_num_desktops
- 1;
1211 ob_debug("client desktop set from startup-notification: 0x%x\n",
1214 /* defaults to the current desktop */
1216 self
->desktop
= screen_desktop
;
1217 ob_debug("client desktop set to the current desktop: %d\n",
1223 static void client_get_state(ObClient
*self
)
1228 if (PROP_GETA32(self
->window
, net_wm_state
, atom
, &state
, &num
)) {
1230 for (i
= 0; i
< num
; ++i
) {
1231 if (state
[i
] == prop_atoms
.net_wm_state_modal
)
1233 else if (state
[i
] == prop_atoms
.net_wm_state_shaded
)
1234 self
->shaded
= TRUE
;
1235 else if (state
[i
] == prop_atoms
.net_wm_state_hidden
)
1236 self
->iconic
= TRUE
;
1237 else if (state
[i
] == prop_atoms
.net_wm_state_skip_taskbar
)
1238 self
->skip_taskbar
= TRUE
;
1239 else if (state
[i
] == prop_atoms
.net_wm_state_skip_pager
)
1240 self
->skip_pager
= TRUE
;
1241 else if (state
[i
] == prop_atoms
.net_wm_state_fullscreen
)
1242 self
->fullscreen
= TRUE
;
1243 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_vert
)
1244 self
->max_vert
= TRUE
;
1245 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_horz
)
1246 self
->max_horz
= TRUE
;
1247 else if (state
[i
] == prop_atoms
.net_wm_state_above
)
1249 else if (state
[i
] == prop_atoms
.net_wm_state_below
)
1251 else if (state
[i
] == prop_atoms
.net_wm_state_demands_attention
)
1252 self
->demands_attention
= TRUE
;
1253 else if (state
[i
] == prop_atoms
.ob_wm_state_undecorated
)
1254 self
->undecorated
= TRUE
;
1261 static void client_get_shaped(ObClient
*self
)
1263 self
->shaped
= FALSE
;
1265 if (extensions_shape
) {
1270 XShapeSelectInput(ob_display
, self
->window
, ShapeNotifyMask
);
1272 XShapeQueryExtents(ob_display
, self
->window
, &s
, &foo
,
1273 &foo
, &ufoo
, &ufoo
, &foo
, &foo
, &foo
, &ufoo
,
1275 self
->shaped
= (s
!= 0);
1280 void client_update_transient_for(ObClient
*self
)
1283 ObClient
*target
= NULL
;
1284 gboolean trangroup
= FALSE
;
1286 if (XGetTransientForHint(ob_display
, self
->window
, &t
)) {
1287 if (t
!= self
->window
) { /* cant be transient to itself! */
1288 target
= g_hash_table_lookup(window_map
, &t
);
1289 /* if this happens then we need to check for it*/
1290 g_assert(target
!= self
);
1291 if (target
&& !WINDOW_IS_CLIENT(target
)) {
1292 /* this can happen when a dialog is a child of
1293 a dockapp, for example */
1298 /* Setting the transient_for to Root is actually illegal, however
1299 applications from time have done this to specify transient for
1301 if (!target
&& self
->group
&& t
== RootWindow(ob_display
, ob_screen
))
1303 } else if (self
->group
&& self
->transient
)
1306 client_update_transient_tree(self
, self
->group
, self
->group
,
1307 self
->transient_for_group
, trangroup
,
1308 client_direct_parent(self
), target
);
1309 self
->transient_for_group
= trangroup
;
1313 static void client_update_transient_tree(ObClient
*self
,
1314 ObGroup
*oldgroup
, ObGroup
*newgroup
,
1315 gboolean oldgtran
, gboolean newgtran
,
1316 ObClient
* oldparent
,
1317 ObClient
*newparent
)
1322 g_assert(!oldgtran
|| oldgroup
);
1323 g_assert(!newgtran
|| newgroup
);
1324 g_assert((!oldgtran
&& !oldparent
) ||
1325 (oldgtran
&& !oldparent
) ||
1326 (!oldgtran
&& oldparent
));
1327 g_assert((!newgtran
&& !newparent
) ||
1328 (newgtran
&& !newparent
) ||
1329 (!newgtran
&& newparent
));
1332 Group transient windows are not allowed to have other group
1333 transient windows as their children.
1337 /* No change has occured */
1338 if (oldgroup
== newgroup
&&
1339 oldgtran
== newgtran
&&
1340 oldparent
== newparent
) return;
1342 /** Remove the client from the transient tree **/
1344 for (it
= self
->transients
; it
; it
= next
) {
1345 next
= g_slist_next(it
);
1347 self
->transients
= g_slist_delete_link(self
->transients
, it
);
1348 c
->parents
= g_slist_remove(c
->parents
, self
);
1350 for (it
= self
->parents
; it
; it
= next
) {
1351 next
= g_slist_next(it
);
1353 self
->parents
= g_slist_delete_link(self
->parents
, it
);
1354 c
->transients
= g_slist_remove(c
->transients
, self
);
1357 /** Re-add the client to the transient tree **/
1359 /* If we're transient for a group then we need to add ourselves to all our
1362 for (it
= newgroup
->members
; it
; it
= g_slist_next(it
)) {
1365 !client_search_top_direct_parent(c
)->transient_for_group
&&
1368 c
->transients
= g_slist_prepend(c
->transients
, self
);
1369 self
->parents
= g_slist_prepend(self
->parents
, c
);
1374 /* If we are now transient for a single window we need to add ourselves to
1377 WARNING: Cyclical transient ness is possible if two windows are
1378 transient for eachother.
1380 else if (newparent
&&
1381 /* don't make ourself its child if it is already our child */
1382 !client_is_direct_child(self
, newparent
) &&
1383 client_normal(newparent
))
1385 newparent
->transients
= g_slist_prepend(newparent
->transients
, self
);
1386 self
->parents
= g_slist_prepend(self
->parents
, newparent
);
1389 /* Add any group transient windows to our children. But if we're transient
1390 for the group, then other group transients are not our children.
1392 WARNING: Cyclical transient-ness is possible. For e.g. if:
1393 A is transient for the group
1394 B is transient for A
1395 C is transient for B
1396 A can't be transient for C or we have a cycle
1398 if (!newgtran
&& newgroup
&&
1400 !client_search_top_direct_parent(newparent
)->transient_for_group
) &&
1401 client_normal(self
))
1403 for (it
= newgroup
->members
; it
; it
= g_slist_next(it
)) {
1405 if (c
!= self
&& c
->transient_for_group
&&
1406 /* Don't make it our child if it is already our parent */
1407 !client_is_direct_child(c
, self
))
1409 self
->transients
= g_slist_prepend(self
->transients
, c
);
1410 c
->parents
= g_slist_prepend(c
->parents
, self
);
1415 /** If we change our group transient-ness, our children change their
1416 effect group transient-ness, which affects how they relate to other
1419 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
1421 if (!c
->transient_for_group
)
1422 client_update_transient_tree(c
, c
->group
, c
->group
,
1423 c
->transient_for_group
,
1424 c
->transient_for_group
,
1425 client_direct_parent(c
),
1426 client_direct_parent(c
));
1430 static void client_get_mwm_hints(ObClient
*self
)
1435 self
->mwmhints
.flags
= 0; /* default to none */
1437 if (PROP_GETA32(self
->window
, motif_wm_hints
, motif_wm_hints
,
1439 if (num
>= OB_MWM_ELEMENTS
) {
1440 self
->mwmhints
.flags
= hints
[0];
1441 self
->mwmhints
.functions
= hints
[1];
1442 self
->mwmhints
.decorations
= hints
[2];
1448 void client_get_type_and_transientness(ObClient
*self
)
1455 self
->transient
= FALSE
;
1457 if (PROP_GETA32(self
->window
, net_wm_window_type
, atom
, &val
, &num
)) {
1458 /* use the first value that we know about in the array */
1459 for (i
= 0; i
< num
; ++i
) {
1460 if (val
[i
] == prop_atoms
.net_wm_window_type_desktop
)
1461 self
->type
= OB_CLIENT_TYPE_DESKTOP
;
1462 else if (val
[i
] == prop_atoms
.net_wm_window_type_dock
)
1463 self
->type
= OB_CLIENT_TYPE_DOCK
;
1464 else if (val
[i
] == prop_atoms
.net_wm_window_type_toolbar
)
1465 self
->type
= OB_CLIENT_TYPE_TOOLBAR
;
1466 else if (val
[i
] == prop_atoms
.net_wm_window_type_menu
)
1467 self
->type
= OB_CLIENT_TYPE_MENU
;
1468 else if (val
[i
] == prop_atoms
.net_wm_window_type_utility
)
1469 self
->type
= OB_CLIENT_TYPE_UTILITY
;
1470 else if (val
[i
] == prop_atoms
.net_wm_window_type_splash
)
1471 self
->type
= OB_CLIENT_TYPE_SPLASH
;
1472 else if (val
[i
] == prop_atoms
.net_wm_window_type_dialog
)
1473 self
->type
= OB_CLIENT_TYPE_DIALOG
;
1474 else if (val
[i
] == prop_atoms
.net_wm_window_type_normal
)
1475 self
->type
= OB_CLIENT_TYPE_NORMAL
;
1476 else if (val
[i
] == prop_atoms
.kde_net_wm_window_type_override
) {
1477 /* prevent this window from getting any decor or
1479 self
->mwmhints
.flags
&= (OB_MWM_FLAG_FUNCTIONS
|
1480 OB_MWM_FLAG_DECORATIONS
);
1481 self
->mwmhints
.decorations
= 0;
1482 self
->mwmhints
.functions
= 0;
1484 if (self
->type
!= (ObClientType
) -1)
1485 break; /* grab the first legit type */
1490 if (XGetTransientForHint(ob_display
, self
->window
, &t
))
1491 self
->transient
= TRUE
;
1493 if (self
->type
== (ObClientType
) -1) {
1494 /*the window type hint was not set, which means we either classify
1495 ourself as a normal window or a dialog, depending on if we are a
1497 if (self
->transient
)
1498 self
->type
= OB_CLIENT_TYPE_DIALOG
;
1500 self
->type
= OB_CLIENT_TYPE_NORMAL
;
1503 /* then, based on our type, we can update our transientness.. */
1504 if (self
->type
== OB_CLIENT_TYPE_DIALOG
||
1505 self
->type
== OB_CLIENT_TYPE_TOOLBAR
||
1506 self
->type
== OB_CLIENT_TYPE_MENU
||
1507 self
->type
== OB_CLIENT_TYPE_UTILITY
)
1509 self
->transient
= TRUE
;
1513 void client_update_protocols(ObClient
*self
)
1516 guint num_return
, i
;
1518 self
->focus_notify
= FALSE
;
1519 self
->delete_window
= FALSE
;
1521 if (PROP_GETA32(self
->window
, wm_protocols
, atom
, &proto
, &num_return
)) {
1522 for (i
= 0; i
< num_return
; ++i
) {
1523 if (proto
[i
] == prop_atoms
.wm_delete_window
)
1524 /* this means we can request the window to close */
1525 self
->delete_window
= TRUE
;
1526 else if (proto
[i
] == prop_atoms
.wm_take_focus
)
1527 /* if this protocol is requested, then the window will be
1528 notified whenever we want it to receive focus */
1529 self
->focus_notify
= TRUE
;
1530 else if (proto
[i
] == prop_atoms
.net_wm_ping
)
1531 /* if this protocol is requested, then the window will allow
1532 pings to determine if it is still alive */
1535 else if (proto
[i
] == prop_atoms
.net_wm_sync_request
)
1536 /* if this protocol is requested, then resizing the
1537 window will be synchronized between the frame and the
1539 self
->sync_request
= TRUE
;
1547 void client_update_sync_request_counter(ObClient
*self
)
1551 if (PROP_GET32(self
->window
, net_wm_sync_request_counter
, cardinal
, &i
)) {
1552 self
->sync_counter
= i
;
1554 self
->sync_counter
= None
;
1558 static void client_get_colormap(ObClient
*self
)
1560 XWindowAttributes wa
;
1562 if (XGetWindowAttributes(ob_display
, self
->window
, &wa
))
1563 client_update_colormap(self
, wa
.colormap
);
1566 void client_update_colormap(ObClient
*self
, Colormap colormap
)
1568 if (colormap
== self
->colormap
) return;
1570 ob_debug("Setting client %s colormap: 0x%x\n", self
->title
, colormap
);
1572 if (client_focused(self
)) {
1573 screen_install_colormap(self
, FALSE
); /* uninstall old one */
1574 self
->colormap
= colormap
;
1575 screen_install_colormap(self
, FALSE
); /* install new one */
1577 self
->colormap
= colormap
;
1580 void client_update_normal_hints(ObClient
*self
)
1586 self
->min_ratio
= 0.0f
;
1587 self
->max_ratio
= 0.0f
;
1588 SIZE_SET(self
->size_inc
, 1, 1);
1589 SIZE_SET(self
->base_size
, 0, 0);
1590 SIZE_SET(self
->min_size
, 0, 0);
1591 SIZE_SET(self
->max_size
, G_MAXINT
, G_MAXINT
);
1593 /* get the hints from the window */
1594 if (XGetWMNormalHints(ob_display
, self
->window
, &size
, &ret
)) {
1595 /* normal windows can't request placement! har har
1596 if (!client_normal(self))
1598 self
->positioned
= (size
.flags
& (PPosition
|USPosition
));
1599 self
->sized
= (size
.flags
& (PSize
|USSize
));
1601 if (size
.flags
& PWinGravity
)
1602 self
->gravity
= size
.win_gravity
;
1604 if (size
.flags
& PAspect
) {
1605 if (size
.min_aspect
.y
)
1607 (gfloat
) size
.min_aspect
.x
/ size
.min_aspect
.y
;
1608 if (size
.max_aspect
.y
)
1610 (gfloat
) size
.max_aspect
.x
/ size
.max_aspect
.y
;
1613 if (size
.flags
& PMinSize
)
1614 SIZE_SET(self
->min_size
, size
.min_width
, size
.min_height
);
1616 if (size
.flags
& PMaxSize
)
1617 SIZE_SET(self
->max_size
, size
.max_width
, size
.max_height
);
1619 if (size
.flags
& PBaseSize
)
1620 SIZE_SET(self
->base_size
, size
.base_width
, size
.base_height
);
1622 if (size
.flags
& PResizeInc
&& size
.width_inc
&& size
.height_inc
)
1623 SIZE_SET(self
->size_inc
, size
.width_inc
, size
.height_inc
);
1625 ob_debug("Normal hints: min size (%d %d) max size (%d %d)\n "
1626 "size inc (%d %d) base size (%d %d)\n",
1627 self
->min_size
.width
, self
->min_size
.height
,
1628 self
->max_size
.width
, self
->max_size
.height
,
1629 self
->size_inc
.width
, self
->size_inc
.height
,
1630 self
->base_size
.width
, self
->base_size
.height
);
1633 ob_debug("Normal hints: not set\n");
1636 void client_setup_decor_and_functions(ObClient
*self
, gboolean reconfig
)
1638 /* start with everything (cept fullscreen) */
1640 (OB_FRAME_DECOR_TITLEBAR
|
1641 OB_FRAME_DECOR_HANDLE
|
1642 OB_FRAME_DECOR_GRIPS
|
1643 OB_FRAME_DECOR_BORDER
|
1644 OB_FRAME_DECOR_ICON
|
1645 OB_FRAME_DECOR_ALLDESKTOPS
|
1646 OB_FRAME_DECOR_ICONIFY
|
1647 OB_FRAME_DECOR_MAXIMIZE
|
1648 OB_FRAME_DECOR_SHADE
|
1649 OB_FRAME_DECOR_CLOSE
);
1651 (OB_CLIENT_FUNC_RESIZE
|
1652 OB_CLIENT_FUNC_MOVE
|
1653 OB_CLIENT_FUNC_ICONIFY
|
1654 OB_CLIENT_FUNC_MAXIMIZE
|
1655 OB_CLIENT_FUNC_SHADE
|
1656 OB_CLIENT_FUNC_CLOSE
|
1657 OB_CLIENT_FUNC_BELOW
|
1658 OB_CLIENT_FUNC_ABOVE
|
1659 OB_CLIENT_FUNC_UNDECORATE
);
1661 if (!(self
->min_size
.width
< self
->max_size
.width
||
1662 self
->min_size
.height
< self
->max_size
.height
))
1663 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
1665 switch (self
->type
) {
1666 case OB_CLIENT_TYPE_NORMAL
:
1667 /* normal windows retain all of the possible decorations and
1668 functionality, and can be fullscreen */
1669 self
->functions
|= OB_CLIENT_FUNC_FULLSCREEN
;
1672 case OB_CLIENT_TYPE_DIALOG
:
1673 /* sometimes apps make dialog windows fullscreen for some reason (for
1674 e.g. kpdf does this..) */
1675 self
->functions
|= OB_CLIENT_FUNC_FULLSCREEN
;
1678 case OB_CLIENT_TYPE_UTILITY
:
1679 /* these windows don't have anything added or removed by default */
1682 case OB_CLIENT_TYPE_MENU
:
1683 case OB_CLIENT_TYPE_TOOLBAR
:
1684 /* these windows can't iconify or maximize */
1685 self
->decorations
&= ~(OB_FRAME_DECOR_ICONIFY
|
1686 OB_FRAME_DECOR_MAXIMIZE
);
1687 self
->functions
&= ~(OB_CLIENT_FUNC_ICONIFY
|
1688 OB_CLIENT_FUNC_MAXIMIZE
);
1691 case OB_CLIENT_TYPE_SPLASH
:
1692 /* these don't get get any decorations, and the only thing you can
1693 do with them is move them */
1694 self
->decorations
= 0;
1695 self
->functions
= OB_CLIENT_FUNC_MOVE
;
1698 case OB_CLIENT_TYPE_DESKTOP
:
1699 /* these windows are not manipulated by the window manager */
1700 self
->decorations
= 0;
1701 self
->functions
= 0;
1704 case OB_CLIENT_TYPE_DOCK
:
1705 /* these windows are not manipulated by the window manager, but they
1706 can set below layer which has a special meaning */
1707 self
->decorations
= 0;
1708 self
->functions
= OB_CLIENT_FUNC_BELOW
;
1712 /* Mwm Hints are applied subtractively to what has already been chosen for
1713 decor and functionality */
1714 if (self
->mwmhints
.flags
& OB_MWM_FLAG_DECORATIONS
) {
1715 if (! (self
->mwmhints
.decorations
& OB_MWM_DECOR_ALL
)) {
1716 if (! ((self
->mwmhints
.decorations
& OB_MWM_DECOR_HANDLE
) ||
1717 (self
->mwmhints
.decorations
& OB_MWM_DECOR_TITLE
)))
1719 /* if the mwm hints request no handle or title, then all
1720 decorations are disabled, but keep the border if that's
1722 if (self
->mwmhints
.decorations
& OB_MWM_DECOR_BORDER
)
1723 self
->decorations
= OB_FRAME_DECOR_BORDER
;
1725 self
->decorations
= 0;
1730 if (self
->mwmhints
.flags
& OB_MWM_FLAG_FUNCTIONS
) {
1731 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_ALL
)) {
1732 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_RESIZE
))
1733 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
1734 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_MOVE
))
1735 self
->functions
&= ~OB_CLIENT_FUNC_MOVE
;
1736 /* dont let mwm hints kill any buttons
1737 if (! (self->mwmhints.functions & OB_MWM_FUNC_ICONIFY))
1738 self->functions &= ~OB_CLIENT_FUNC_ICONIFY;
1739 if (! (self->mwmhints.functions & OB_MWM_FUNC_MAXIMIZE))
1740 self->functions &= ~OB_CLIENT_FUNC_MAXIMIZE;
1742 /* dont let mwm hints kill the close button
1743 if (! (self->mwmhints.functions & MwmFunc_Close))
1744 self->functions &= ~OB_CLIENT_FUNC_CLOSE; */
1748 if (!(self
->functions
& OB_CLIENT_FUNC_SHADE
))
1749 self
->decorations
&= ~OB_FRAME_DECOR_SHADE
;
1750 if (!(self
->functions
& OB_CLIENT_FUNC_ICONIFY
))
1751 self
->decorations
&= ~OB_FRAME_DECOR_ICONIFY
;
1752 if (!(self
->functions
& OB_CLIENT_FUNC_RESIZE
))
1753 self
->decorations
&= ~(OB_FRAME_DECOR_GRIPS
| OB_FRAME_DECOR_HANDLE
);
1755 /* can't maximize without moving/resizing */
1756 if (!((self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) &&
1757 (self
->functions
& OB_CLIENT_FUNC_MOVE
) &&
1758 (self
->functions
& OB_CLIENT_FUNC_RESIZE
))) {
1759 self
->functions
&= ~OB_CLIENT_FUNC_MAXIMIZE
;
1760 self
->decorations
&= ~OB_FRAME_DECOR_MAXIMIZE
;
1763 if (self
->max_horz
&& self
->max_vert
) {
1764 /* you can't resize fully maximized windows */
1765 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
1766 /* kill the handle on fully maxed windows */
1767 self
->decorations
&= ~(OB_FRAME_DECOR_HANDLE
| OB_FRAME_DECOR_GRIPS
);
1770 /* If there are no decorations to remove, don't allow the user to try
1772 if (self
->decorations
== 0)
1773 self
->functions
&= ~OB_CLIENT_FUNC_UNDECORATE
;
1775 /* finally, the user can have requested no decorations, which overrides
1776 everything (but doesnt give it a border if it doesnt have one) */
1777 if (self
->undecorated
)
1778 self
->decorations
= 0;
1780 /* if we don't have a titlebar, then we cannot shade! */
1781 if (!(self
->decorations
& OB_FRAME_DECOR_TITLEBAR
))
1782 self
->functions
&= ~OB_CLIENT_FUNC_SHADE
;
1784 /* now we need to check against rules for the client's current state */
1785 if (self
->fullscreen
) {
1786 self
->functions
&= (OB_CLIENT_FUNC_CLOSE
|
1787 OB_CLIENT_FUNC_FULLSCREEN
|
1788 OB_CLIENT_FUNC_ICONIFY
);
1789 self
->decorations
= 0;
1792 client_change_allowed_actions(self
);
1795 /* force reconfigure to make sure decorations are updated */
1796 client_reconfigure(self
, TRUE
);
1799 static void client_change_allowed_actions(ObClient
*self
)
1804 /* desktop windows are kept on all desktops */
1805 if (self
->type
!= OB_CLIENT_TYPE_DESKTOP
)
1806 actions
[num
++] = prop_atoms
.net_wm_action_change_desktop
;
1808 if (self
->functions
& OB_CLIENT_FUNC_SHADE
)
1809 actions
[num
++] = prop_atoms
.net_wm_action_shade
;
1810 if (self
->functions
& OB_CLIENT_FUNC_CLOSE
)
1811 actions
[num
++] = prop_atoms
.net_wm_action_close
;
1812 if (self
->functions
& OB_CLIENT_FUNC_MOVE
)
1813 actions
[num
++] = prop_atoms
.net_wm_action_move
;
1814 if (self
->functions
& OB_CLIENT_FUNC_ICONIFY
)
1815 actions
[num
++] = prop_atoms
.net_wm_action_minimize
;
1816 if (self
->functions
& OB_CLIENT_FUNC_RESIZE
)
1817 actions
[num
++] = prop_atoms
.net_wm_action_resize
;
1818 if (self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
)
1819 actions
[num
++] = prop_atoms
.net_wm_action_fullscreen
;
1820 if (self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) {
1821 actions
[num
++] = prop_atoms
.net_wm_action_maximize_horz
;
1822 actions
[num
++] = prop_atoms
.net_wm_action_maximize_vert
;
1824 if (self
->functions
& OB_CLIENT_FUNC_ABOVE
)
1825 actions
[num
++] = prop_atoms
.net_wm_action_above
;
1826 if (self
->functions
& OB_CLIENT_FUNC_BELOW
)
1827 actions
[num
++] = prop_atoms
.net_wm_action_below
;
1828 if (self
->functions
& OB_CLIENT_FUNC_UNDECORATE
)
1829 actions
[num
++] = prop_atoms
.ob_wm_action_undecorate
;
1831 PROP_SETA32(self
->window
, net_wm_allowed_actions
, atom
, actions
, num
);
1833 /* make sure the window isn't breaking any rules now */
1835 if (!(self
->functions
& OB_CLIENT_FUNC_SHADE
) && self
->shaded
) {
1836 if (self
->frame
) client_shade(self
, FALSE
);
1837 else self
->shaded
= FALSE
;
1839 if (!(self
->functions
& OB_CLIENT_FUNC_ICONIFY
) && self
->iconic
) {
1840 if (self
->frame
) client_iconify(self
, FALSE
, TRUE
, FALSE
);
1841 else self
->iconic
= FALSE
;
1843 if (!(self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
) && self
->fullscreen
) {
1844 if (self
->frame
) client_fullscreen(self
, FALSE
);
1845 else self
->fullscreen
= FALSE
;
1847 if (!(self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) && (self
->max_horz
||
1849 if (self
->frame
) client_maximize(self
, FALSE
, 0);
1850 else self
->max_vert
= self
->max_horz
= FALSE
;
1854 void client_update_wmhints(ObClient
*self
)
1858 /* assume a window takes input if it doesnt specify */
1859 self
->can_focus
= TRUE
;
1861 if ((hints
= XGetWMHints(ob_display
, self
->window
)) != NULL
) {
1864 if (hints
->flags
& InputHint
)
1865 self
->can_focus
= hints
->input
;
1867 /* only do this when first managing the window *AND* when we aren't
1869 if (ob_state() != OB_STATE_STARTING
&& self
->frame
== NULL
)
1870 if (hints
->flags
& StateHint
)
1871 self
->iconic
= hints
->initial_state
== IconicState
;
1874 self
->urgent
= (hints
->flags
& XUrgencyHint
);
1875 if (self
->urgent
&& !ur
)
1876 client_hilite(self
, TRUE
);
1877 else if (!self
->urgent
&& ur
&& self
->demands_attention
)
1878 client_hilite(self
, FALSE
);
1880 if (!(hints
->flags
& WindowGroupHint
))
1881 hints
->window_group
= None
;
1883 /* did the group state change? */
1884 if (hints
->window_group
!=
1885 (self
->group
? self
->group
->leader
: None
))
1887 ObGroup
*oldgroup
= self
->group
;
1889 /* remove from the old group if there was one */
1890 if (self
->group
!= NULL
) {
1891 group_remove(self
->group
, self
);
1895 /* add ourself to the group if we have one */
1896 if (hints
->window_group
!= None
) {
1897 self
->group
= group_add(hints
->window_group
, self
);
1900 /* Put ourselves into the new group's transient tree, and remove
1901 ourselves from the old group's */
1902 client_update_transient_tree(self
, oldgroup
, self
->group
,
1903 self
->transient_for_group
,
1904 self
->transient_for_group
,
1905 client_direct_parent(self
),
1906 client_direct_parent(self
));
1908 /* Lastly, being in a group, or not, can change if the window is
1909 transient for anything.
1911 The logic for this is:
1912 self->transient = TRUE always if the window wants to be
1913 transient for something, even if transient_for was NULL because
1914 it wasn't in a group before.
1916 If parents was NULL and oldgroup was NULL we can assume
1917 that when we add the new group, it will become transient for
1920 If transient_for_group is TRUE, then it must have already
1921 had a group. If it is getting a new group, the above call to
1922 client_update_transient_tree has already taken care of
1923 everything ! If it is losing all group status then it will
1924 no longer be transient for anything and that needs to be
1927 if (self
->transient
&&
1928 ((self
->parents
== NULL
&& oldgroup
== NULL
) ||
1929 (self
->transient_for_group
&& !self
->group
)))
1930 client_update_transient_for(self
);
1933 /* the WM_HINTS can contain an icon */
1934 if (hints
->flags
& IconPixmapHint
)
1935 client_update_icons(self
);
1941 void client_update_title(ObClient
*self
)
1944 gchar
*visible
= NULL
;
1946 g_free(self
->title
);
1949 if (!PROP_GETS(self
->window
, net_wm_name
, utf8
, &data
)) {
1950 /* try old x stuff */
1951 if (!(PROP_GETS(self
->window
, wm_name
, locale
, &data
)
1952 || PROP_GETS(self
->window
, wm_name
, utf8
, &data
))) {
1953 if (self
->transient
) {
1955 GNOME alert windows are not given titles:
1956 http://developer.gnome.org/projects/gup/hig/draft_hig_new/windows-alert.html
1958 data
= g_strdup("");
1960 data
= g_strdup("Unnamed Window");
1964 if (self
->client_machine
) {
1965 visible
= g_strdup_printf("%s (%s)", data
, self
->client_machine
);
1970 if (self
->not_responding
) {
1972 if (self
->close_tried_term
)
1973 visible
= g_strdup_printf("%s - [%s]", data
, _("Killing..."));
1975 visible
= g_strdup_printf("%s - [%s]", data
, _("Not Responding"));
1979 PROP_SETS(self
->window
, net_wm_visible_name
, visible
);
1980 self
->title
= visible
;
1983 frame_adjust_title(self
->frame
);
1985 /* update the icon title */
1987 g_free(self
->icon_title
);
1990 if (!PROP_GETS(self
->window
, net_wm_icon_name
, utf8
, &data
))
1991 /* try old x stuff */
1992 if (!(PROP_GETS(self
->window
, wm_icon_name
, locale
, &data
) ||
1993 PROP_GETS(self
->window
, wm_icon_name
, utf8
, &data
)))
1994 data
= g_strdup(self
->title
);
1996 if (self
->client_machine
) {
1997 visible
= g_strdup_printf("%s (%s)", data
, self
->client_machine
);
2002 if (self
->not_responding
) {
2004 if (self
->close_tried_term
)
2005 visible
= g_strdup_printf("%s - [%s]", data
, _("Killing..."));
2007 visible
= g_strdup_printf("%s - [%s]", data
, _("Not Responding"));
2011 PROP_SETS(self
->window
, net_wm_visible_icon_name
, visible
);
2012 self
->icon_title
= visible
;
2015 void client_update_strut(ObClient
*self
)
2019 gboolean got
= FALSE
;
2022 if (PROP_GETA32(self
->window
, net_wm_strut_partial
, cardinal
,
2026 STRUT_PARTIAL_SET(strut
,
2027 data
[0], data
[2], data
[1], data
[3],
2028 data
[4], data
[5], data
[8], data
[9],
2029 data
[6], data
[7], data
[10], data
[11]);
2035 PROP_GETA32(self
->window
, net_wm_strut
, cardinal
, &data
, &num
)) {
2041 /* use the screen's width/height */
2042 a
= screen_physical_area_all_monitors();
2044 STRUT_PARTIAL_SET(strut
,
2045 data
[0], data
[2], data
[1], data
[3],
2046 a
->y
, a
->y
+ a
->height
- 1,
2047 a
->x
, a
->x
+ a
->width
- 1,
2048 a
->y
, a
->y
+ a
->height
- 1,
2049 a
->x
, a
->x
+ a
->width
- 1);
2056 STRUT_PARTIAL_SET(strut
, 0, 0, 0, 0,
2057 0, 0, 0, 0, 0, 0, 0, 0);
2059 if (!STRUT_EQUAL(strut
, self
->strut
)) {
2060 self
->strut
= strut
;
2062 /* updating here is pointless while we're being mapped cuz we're not in
2063 the client list yet */
2065 screen_update_areas();
2069 void client_update_icons(ObClient
*self
)
2075 for (i
= 0; i
< self
->nicons
; ++i
)
2076 g_free(self
->icons
[i
].data
);
2077 if (self
->nicons
> 0)
2078 g_free(self
->icons
);
2081 if (PROP_GETA32(self
->window
, net_wm_icon
, cardinal
, &data
, &num
)) {
2082 /* figure out how many valid icons are in here */
2084 while (num
- i
> 2) {
2088 if (i
> num
|| w
*h
== 0) break;
2092 self
->icons
= g_new(ObClientIcon
, self
->nicons
);
2094 /* store the icons */
2096 for (j
= 0; j
< self
->nicons
; ++j
) {
2099 w
= self
->icons
[j
].width
= data
[i
++];
2100 h
= self
->icons
[j
].height
= data
[i
++];
2102 if (w
*h
== 0) continue;
2104 self
->icons
[j
].data
= g_new(RrPixel32
, w
* h
);
2105 for (x
= 0, y
= 0, t
= 0; t
< w
* h
; ++t
, ++x
, ++i
) {
2110 self
->icons
[j
].data
[t
] =
2111 (((data
[i
] >> 24) & 0xff) << RrDefaultAlphaOffset
) +
2112 (((data
[i
] >> 16) & 0xff) << RrDefaultRedOffset
) +
2113 (((data
[i
] >> 8) & 0xff) << RrDefaultGreenOffset
) +
2114 (((data
[i
] >> 0) & 0xff) << RrDefaultBlueOffset
);
2123 if ((hints
= XGetWMHints(ob_display
, self
->window
))) {
2124 if (hints
->flags
& IconPixmapHint
) {
2126 self
->icons
= g_new(ObClientIcon
, self
->nicons
);
2127 xerror_set_ignore(TRUE
);
2128 if (!RrPixmapToRGBA(ob_rr_inst
,
2130 (hints
->flags
& IconMaskHint
?
2131 hints
->icon_mask
: None
),
2132 &self
->icons
[0].width
,
2133 &self
->icons
[0].height
,
2134 &self
->icons
[0].data
))
2136 g_free(self
->icons
);
2139 xerror_set_ignore(FALSE
);
2145 /* set the default icon onto the window
2146 in theory, this could be a race, but if a window doesn't set an icon
2147 or removes it entirely, it's not very likely it is going to set one
2148 right away afterwards
2150 if it has parents, then one of them will have an icon already
2152 if (self
->nicons
== 0 && !self
->parents
) {
2153 RrPixel32
*icon
= ob_rr_theme
->def_win_icon
;
2156 data
= g_new(gulong
, 48*48+2);
2157 data
[0] = data
[1] = 48;
2158 for (i
= 0; i
< 48*48; ++i
)
2159 data
[i
+2] = (((icon
[i
] >> RrDefaultAlphaOffset
) & 0xff) << 24) +
2160 (((icon
[i
] >> RrDefaultRedOffset
) & 0xff) << 16) +
2161 (((icon
[i
] >> RrDefaultGreenOffset
) & 0xff) << 8) +
2162 (((icon
[i
] >> RrDefaultBlueOffset
) & 0xff) << 0);
2163 PROP_SETA32(self
->window
, net_wm_icon
, cardinal
, data
, 48*48+2);
2165 } else if (self
->frame
)
2166 /* don't draw the icon empty if we're just setting one now anyways,
2167 we'll get the property change any second */
2168 frame_adjust_icon(self
->frame
);
2171 void client_update_icon_geometry(ObClient
*self
)
2176 RECT_SET(self
->icon_geometry
, 0, 0, 0, 0);
2178 if (PROP_GETA32(self
->window
, net_wm_icon_geometry
, cardinal
, &data
, &num
)
2181 /* don't let them set it with an area < 0 */
2182 RECT_SET(self
->icon_geometry
, data
[0], data
[1],
2183 MAX(data
[2],0), MAX(data
[3],0));
2187 static void client_get_session_ids(ObClient
*self
)
2194 if (!PROP_GET32(self
->window
, wm_client_leader
, window
, &leader
))
2197 /* get the SM_CLIENT_ID */
2200 got
= PROP_GETS(leader
, sm_client_id
, locale
, &self
->sm_client_id
);
2202 PROP_GETS(self
->window
, sm_client_id
, locale
, &self
->sm_client_id
);
2204 /* get the WM_CLASS (name and class). make them "" if they are not
2208 got
= PROP_GETSS(leader
, wm_class
, locale
, &ss
);
2210 got
= PROP_GETSS(self
->window
, wm_class
, locale
, &ss
);
2214 self
->name
= g_strdup(ss
[0]);
2216 self
->class = g_strdup(ss
[1]);
2221 if (self
->name
== NULL
) self
->name
= g_strdup("");
2222 if (self
->class == NULL
) self
->class = g_strdup("");
2224 /* get the WM_WINDOW_ROLE. make it "" if it is not provided */
2227 got
= PROP_GETS(leader
, wm_window_role
, locale
, &s
);
2229 got
= PROP_GETS(self
->window
, wm_window_role
, locale
, &s
);
2234 self
->role
= g_strdup("");
2236 /* get the WM_COMMAND */
2240 got
= PROP_GETSS(leader
, wm_command
, locale
, &ss
);
2242 got
= PROP_GETSS(self
->window
, wm_command
, locale
, &ss
);
2245 /* merge/mash them all together */
2246 gchar
*merge
= NULL
;
2249 for (i
= 0; ss
[i
]; ++i
) {
2252 merge
= g_strconcat(merge
, ss
[i
], NULL
);
2254 merge
= g_strconcat(ss
[i
], NULL
);
2259 self
->wm_command
= merge
;
2262 /* get the WM_CLIENT_MACHINE */
2265 got
= PROP_GETS(leader
, wm_client_machine
, locale
, &s
);
2267 got
= PROP_GETS(self
->window
, wm_client_machine
, locale
, &s
);
2270 gchar localhost
[128];
2273 gethostname(localhost
, 127);
2274 localhost
[127] = '\0';
2275 if (strcmp(localhost
, s
) != 0)
2276 self
->client_machine
= s
;
2280 /* see if it has the PID set too (the PID requires that the
2281 WM_CLIENT_MACHINE be set) */
2282 if (PROP_GET32(self
->window
, net_wm_pid
, cardinal
, &pid
))
2287 static void client_change_wm_state(ObClient
*self
)
2292 old
= self
->wmstate
;
2294 if (self
->shaded
|| self
->iconic
||
2295 (self
->desktop
!= DESKTOP_ALL
&& self
->desktop
!= screen_desktop
))
2297 self
->wmstate
= IconicState
;
2299 self
->wmstate
= NormalState
;
2301 if (old
!= self
->wmstate
) {
2302 PROP_MSG(self
->window
, kde_wm_change_state
,
2303 self
->wmstate
, 1, 0, 0);
2305 state
[0] = self
->wmstate
;
2307 PROP_SETA32(self
->window
, wm_state
, wm_state
, state
, 2);
2311 static void client_change_state(ObClient
*self
)
2313 gulong netstate
[12];
2318 netstate
[num
++] = prop_atoms
.net_wm_state_modal
;
2320 netstate
[num
++] = prop_atoms
.net_wm_state_shaded
;
2322 netstate
[num
++] = prop_atoms
.net_wm_state_hidden
;
2323 if (self
->skip_taskbar
)
2324 netstate
[num
++] = prop_atoms
.net_wm_state_skip_taskbar
;
2325 if (self
->skip_pager
)
2326 netstate
[num
++] = prop_atoms
.net_wm_state_skip_pager
;
2327 if (self
->fullscreen
)
2328 netstate
[num
++] = prop_atoms
.net_wm_state_fullscreen
;
2330 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_vert
;
2332 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_horz
;
2334 netstate
[num
++] = prop_atoms
.net_wm_state_above
;
2336 netstate
[num
++] = prop_atoms
.net_wm_state_below
;
2337 if (self
->demands_attention
)
2338 netstate
[num
++] = prop_atoms
.net_wm_state_demands_attention
;
2339 if (self
->undecorated
)
2340 netstate
[num
++] = prop_atoms
.ob_wm_state_undecorated
;
2341 PROP_SETA32(self
->window
, net_wm_state
, atom
, netstate
, num
);
2344 frame_adjust_state(self
->frame
);
2347 ObClient
*client_search_focus_tree(ObClient
*self
)
2352 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
2353 if (client_focused(it
->data
)) return it
->data
;
2354 if ((ret
= client_search_focus_tree(it
->data
))) return ret
;
2359 ObClient
*client_search_focus_tree_full(ObClient
*self
)
2361 if (self
->parents
) {
2364 for (it
= self
->parents
; it
; it
= g_slist_next(it
)) {
2365 ObClient
*c
= it
->data
;
2366 if ((c
= client_search_focus_tree_full(it
->data
))) return c
;
2372 /* this function checks the whole tree, the client_search_focus_tree
2373 does not, so we need to check this window */
2374 if (client_focused(self
))
2376 return client_search_focus_tree(self
);
2380 ObClient
*client_search_focus_group_full(ObClient
*self
)
2385 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
2386 ObClient
*c
= it
->data
;
2388 if (client_focused(c
)) return c
;
2389 if ((c
= client_search_focus_tree(it
->data
))) return c
;
2392 if (client_focused(self
)) return self
;
2396 gboolean
client_has_parent(ObClient
*self
)
2398 return self
->parents
!= NULL
;
2401 static ObStackingLayer
calc_layer(ObClient
*self
)
2406 monitor
= screen_physical_area_monitor(client_monitor(self
));
2408 if (self
->type
== OB_CLIENT_TYPE_DESKTOP
)
2409 l
= OB_STACKING_LAYER_DESKTOP
;
2410 else if (self
->type
== OB_CLIENT_TYPE_DOCK
) {
2411 if (self
->below
) l
= OB_STACKING_LAYER_NORMAL
;
2412 else l
= OB_STACKING_LAYER_ABOVE
;
2414 else if ((self
->fullscreen
||
2415 /* No decorations and fills the monitor = oldskool fullscreen.
2416 But not for maximized windows.
2418 (self
->decorations
== 0 &&
2419 !(self
->max_horz
&& self
->max_vert
) &&
2420 RECT_EQUAL(self
->area
, *monitor
))) &&
2421 (client_focused(self
) || client_search_focus_tree(self
)))
2422 l
= OB_STACKING_LAYER_FULLSCREEN
;
2423 else if (self
->above
) l
= OB_STACKING_LAYER_ABOVE
;
2424 else if (self
->below
) l
= OB_STACKING_LAYER_BELOW
;
2425 else l
= OB_STACKING_LAYER_NORMAL
;
2432 static void client_calc_layer_recursive(ObClient
*self
, ObClient
*orig
,
2433 ObStackingLayer min
)
2435 ObStackingLayer old
, own
;
2439 own
= calc_layer(self
);
2440 self
->layer
= MAX(own
, min
);
2442 if (self
->layer
!= old
) {
2443 stacking_remove(CLIENT_AS_WINDOW(self
));
2444 stacking_add_nonintrusive(CLIENT_AS_WINDOW(self
));
2447 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
2448 client_calc_layer_recursive(it
->data
, orig
,
2452 void client_calc_layer(ObClient
*self
)
2459 /* transients take on the layer of their parents */
2460 it
= client_search_all_top_parents(self
);
2462 for (; it
; it
= g_slist_next(it
))
2463 client_calc_layer_recursive(it
->data
, orig
, 0);
2466 gboolean
client_should_show(ObClient
*self
)
2470 if (client_normal(self
) && screen_showing_desktop
)
2472 if (self
->desktop
== screen_desktop
|| self
->desktop
== DESKTOP_ALL
)
2478 gboolean
client_show(ObClient
*self
)
2480 gboolean show
= FALSE
;
2482 if (client_should_show(self
)) {
2483 frame_show(self
->frame
);
2486 /* According to the ICCCM (sec 4.1.3.1) when a window is not visible,
2487 it needs to be in IconicState. This includes when it is on another
2490 client_change_wm_state(self
);
2495 gboolean
client_hide(ObClient
*self
)
2497 gboolean hide
= FALSE
;
2499 if (!client_should_show(self
)) {
2500 if (self
== focus_client
) {
2501 /* if there is a grab going on, then we need to cancel it. if we
2502 move focus during the grab, applications will get
2503 NotifyWhileGrabbed events and ignore them !
2505 actions should not rely on being able to move focus during an
2508 event_cancel_all_key_grabs();
2511 /* We don't need to ignore enter events here.
2512 The window can hide/iconify in 3 different ways:
2513 1 - through an x message. in this case we ignore all enter events
2514 caused by responding to the x message (unless underMouse)
2515 2 - by a keyboard action. in this case we ignore all enter events
2516 caused by the action
2517 3 - by a mouse action. in this case they are doing stuff with the
2518 mouse and focus _should_ move.
2520 Also in action_end, we simulate an enter event that can't be ignored
2521 so trying to ignore them is futile in case 3 anyways
2524 frame_hide(self
->frame
);
2527 /* According to the ICCCM (sec 4.1.3.1) when a window is not visible,
2528 it needs to be in IconicState. This includes when it is on another
2531 client_change_wm_state(self
);
2536 void client_showhide(ObClient
*self
)
2538 if (!client_show(self
))
2542 gboolean
client_normal(ObClient
*self
) {
2543 return ! (self
->type
== OB_CLIENT_TYPE_DESKTOP
||
2544 self
->type
== OB_CLIENT_TYPE_DOCK
||
2545 self
->type
== OB_CLIENT_TYPE_SPLASH
);
2548 gboolean
client_helper(ObClient
*self
)
2550 return (self
->type
== OB_CLIENT_TYPE_UTILITY
||
2551 self
->type
== OB_CLIENT_TYPE_MENU
||
2552 self
->type
== OB_CLIENT_TYPE_TOOLBAR
);
2555 gboolean
client_mouse_focusable(ObClient
*self
)
2557 return !(self
->type
== OB_CLIENT_TYPE_MENU
||
2558 self
->type
== OB_CLIENT_TYPE_TOOLBAR
||
2559 self
->type
== OB_CLIENT_TYPE_SPLASH
||
2560 self
->type
== OB_CLIENT_TYPE_DOCK
);
2563 gboolean
client_enter_focusable(ObClient
*self
)
2565 /* you can focus desktops but it shouldn't on enter */
2566 return (client_mouse_focusable(self
) &&
2567 self
->type
!= OB_CLIENT_TYPE_DESKTOP
);
2571 static void client_apply_startup_state(ObClient
*self
,
2572 gint x
, gint y
, gint w
, gint h
)
2574 /* save the states that we are going to apply */
2575 gboolean iconic
= self
->iconic
;
2576 gboolean fullscreen
= self
->fullscreen
;
2577 gboolean undecorated
= self
->undecorated
;
2578 gboolean shaded
= self
->shaded
;
2579 gboolean demands_attention
= self
->demands_attention
;
2580 gboolean max_horz
= self
->max_horz
;
2581 gboolean max_vert
= self
->max_vert
;
2585 /* turn them all off in the client, so they won't affect the window
2587 self
->iconic
= self
->fullscreen
= self
->undecorated
= self
->shaded
=
2588 self
->demands_attention
= self
->max_horz
= self
->max_vert
= FALSE
;
2590 /* move the client to its placed position, or it it's already there,
2591 generate a ConfigureNotify telling the client where it is.
2593 do this after adjusting the frame. otherwise it gets all weird and
2594 clients don't work right
2596 do this before applying the states so they have the correct
2597 pre-max/pre-fullscreen values
2599 client_try_configure(self
, &x
, &y
, &w
, &h
, &l
, &l
, FALSE
);
2600 ob_debug("placed window 0x%x at %d, %d with size %d x %d\n",
2601 self
->window
, x
, y
, w
, h
);
2602 /* save the area, and make it where it should be for the premax stuff */
2603 oldarea
= self
->area
;
2604 RECT_SET(self
->area
, x
, y
, w
, h
);
2606 /* apply the states. these are in a carefully crafted order.. */
2609 client_iconify(self
, TRUE
, FALSE
, TRUE
);
2611 client_fullscreen(self
, TRUE
);
2613 client_set_undecorated(self
, TRUE
);
2615 client_shade(self
, TRUE
);
2616 if (demands_attention
)
2617 client_hilite(self
, TRUE
);
2619 if (max_vert
&& max_horz
)
2620 client_maximize(self
, TRUE
, 0);
2622 client_maximize(self
, TRUE
, 2);
2624 client_maximize(self
, TRUE
, 1);
2626 /* if the window hasn't been configured yet, then do so now, in fact the
2627 x,y,w,h may _not_ be the same as the area rect, which can end up
2628 meaning that the client isn't properly moved/resized by the fullscreen
2630 pho can cause this because it maps at size of the screen but not 0,0
2631 so openbox moves it on screen to 0,0 (thus x,y=0,0 and area.x,y don't).
2632 then fullscreen'ing makes it go to 0,0 which it thinks it already is at
2633 cuz thats where the pre-fullscreen will be. however the actual area is
2634 not, so this needs to be called even if we have fullscreened/maxed
2636 self
->area
= oldarea
;
2637 client_configure(self
, x
, y
, w
, h
, FALSE
, TRUE
, FALSE
);
2639 /* set the desktop hint, to make sure that it always exists */
2640 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, self
->desktop
);
2642 /* nothing to do for the other states:
2651 void client_gravity_resize_w(ObClient
*self
, gint
*x
, gint oldw
, gint neww
)
2653 /* these should be the current values. this is for when you're not moving,
2655 g_assert(*x
== self
->area
.x
);
2656 g_assert(oldw
== self
->area
.width
);
2659 switch (self
->gravity
) {
2661 case NorthWestGravity
:
2663 case SouthWestGravity
:
2670 *x
-= (neww
- oldw
) / 2;
2672 case NorthEastGravity
:
2674 case SouthEastGravity
:
2680 void client_gravity_resize_h(ObClient
*self
, gint
*y
, gint oldh
, gint newh
)
2682 /* these should be the current values. this is for when you're not moving,
2684 g_assert(*y
== self
->area
.y
);
2685 g_assert(oldh
== self
->area
.height
);
2688 switch (self
->gravity
) {
2690 case NorthWestGravity
:
2692 case NorthEastGravity
:
2699 *y
-= (newh
- oldh
) / 2;
2701 case SouthWestGravity
:
2703 case SouthEastGravity
:
2709 void client_try_configure(ObClient
*self
, gint
*x
, gint
*y
, gint
*w
, gint
*h
,
2710 gint
*logicalw
, gint
*logicalh
,
2713 Rect desired
= {*x
, *y
, *w
, *h
};
2714 frame_rect_to_frame(self
->frame
, &desired
);
2716 /* make the frame recalculate its dimentions n shit without changing
2717 anything visible for real, this way the constraints below can work with
2718 the updated frame dimensions. */
2719 frame_adjust_area(self
->frame
, FALSE
, TRUE
, TRUE
);
2721 /* gets the frame's position */
2722 frame_client_gravity(self
->frame
, x
, y
);
2724 /* these positions are frame positions, not client positions */
2726 /* set the size and position if fullscreen */
2727 if (self
->fullscreen
) {
2731 i
= screen_find_monitor(&desired
);
2732 a
= screen_physical_area_monitor(i
);
2739 user
= FALSE
; /* ignore if the client can't be moved/resized when it
2743 } else if (self
->max_horz
|| self
->max_vert
) {
2747 /* use all possible struts when maximizing to the full screen */
2748 i
= screen_find_monitor(&desired
);
2749 a
= screen_area(self
->desktop
, i
,
2750 (self
->max_horz
&& self
->max_vert
? NULL
: &desired
));
2752 /* set the size and position if maximized */
2753 if (self
->max_horz
) {
2755 *w
= a
->width
- self
->frame
->size
.left
- self
->frame
->size
.right
;
2757 if (self
->max_vert
) {
2759 *h
= a
->height
- self
->frame
->size
.top
- self
->frame
->size
.bottom
;
2762 user
= FALSE
; /* ignore if the client can't be moved/resized when it
2768 /* gets the client's position */
2769 frame_frame_gravity(self
->frame
, x
, y
);
2771 /* work within the prefered sizes given by the window */
2772 if (!(*w
== self
->area
.width
&& *h
== self
->area
.height
)) {
2773 gint basew
, baseh
, minw
, minh
;
2775 gfloat minratio
, maxratio
;
2777 incw
= self
->fullscreen
|| self
->max_horz
? 1 : self
->size_inc
.width
;
2778 inch
= self
->fullscreen
|| self
->max_vert
? 1 : self
->size_inc
.height
;
2779 minratio
= self
->fullscreen
|| (self
->max_horz
&& self
->max_vert
) ?
2780 0 : self
->min_ratio
;
2781 maxratio
= self
->fullscreen
|| (self
->max_horz
&& self
->max_vert
) ?
2782 0 : self
->max_ratio
;
2784 /* base size is substituted with min size if not specified */
2785 if (self
->base_size
.width
|| self
->base_size
.height
) {
2786 basew
= self
->base_size
.width
;
2787 baseh
= self
->base_size
.height
;
2789 basew
= self
->min_size
.width
;
2790 baseh
= self
->min_size
.height
;
2792 /* min size is substituted with base size if not specified */
2793 if (self
->min_size
.width
|| self
->min_size
.height
) {
2794 minw
= self
->min_size
.width
;
2795 minh
= self
->min_size
.height
;
2797 minw
= self
->base_size
.width
;
2798 minh
= self
->base_size
.height
;
2801 /* if this is a user-requested resize, then check against min/max
2804 /* smaller than min size or bigger than max size? */
2805 if (*w
> self
->max_size
.width
) *w
= self
->max_size
.width
;
2806 if (*w
< minw
) *w
= minw
;
2807 if (*h
> self
->max_size
.height
) *h
= self
->max_size
.height
;
2808 if (*h
< minh
) *h
= minh
;
2813 /* keep to the increments */
2817 /* you cannot resize to nothing */
2818 if (basew
+ *w
< 1) *w
= 1 - basew
;
2819 if (baseh
+ *h
< 1) *h
= 1 - baseh
;
2821 /* save the logical size */
2822 *logicalw
= incw
> 1 ? *w
: *w
+ basew
;
2823 *logicalh
= inch
> 1 ? *h
: *h
+ baseh
;
2831 /* adjust the height to match the width for the aspect ratios.
2832 for this, min size is not substituted for base size ever. */
2833 *w
-= self
->base_size
.width
;
2834 *h
-= self
->base_size
.height
;
2837 if (*h
* minratio
> *w
) {
2838 *h
= (gint
)(*w
/ minratio
);
2840 /* you cannot resize to nothing */
2843 *w
= (gint
)(*h
* minratio
);
2847 if (*h
* maxratio
< *w
) {
2848 *h
= (gint
)(*w
/ maxratio
);
2850 /* you cannot resize to nothing */
2853 *w
= (gint
)(*h
* minratio
);
2857 *w
+= self
->base_size
.width
;
2858 *h
+= self
->base_size
.height
;
2861 /* these override the above states! if you cant move you can't move! */
2863 if (!(self
->functions
& OB_CLIENT_FUNC_MOVE
)) {
2867 if (!(self
->functions
& OB_CLIENT_FUNC_RESIZE
)) {
2868 *w
= self
->area
.width
;
2869 *h
= self
->area
.height
;
2878 void client_configure(ObClient
*self
, gint x
, gint y
, gint w
, gint h
,
2879 gboolean user
, gboolean final
, gboolean force_reply
)
2882 gboolean send_resize_client
;
2883 gboolean moved
= FALSE
, resized
= FALSE
, rootmoved
= FALSE
;
2884 gboolean fmoved
, fresized
;
2885 guint fdecor
= self
->frame
->decorations
;
2886 gboolean fhorz
= self
->frame
->max_horz
;
2887 gboolean fvert
= self
->frame
->max_vert
;
2888 gint logicalw
, logicalh
;
2890 /* find the new x, y, width, and height (and logical size) */
2891 client_try_configure(self
, &x
, &y
, &w
, &h
, &logicalw
, &logicalh
, user
);
2893 /* set the logical size if things changed */
2894 if (!(w
== self
->area
.width
&& h
== self
->area
.height
))
2895 SIZE_SET(self
->logical_size
, logicalw
, logicalh
);
2897 /* figure out if we moved or resized or what */
2898 moved
= (x
!= self
->area
.x
|| y
!= self
->area
.y
);
2899 resized
= (w
!= self
->area
.width
|| h
!= self
->area
.height
);
2901 oldw
= self
->area
.width
;
2902 oldh
= self
->area
.height
;
2903 RECT_SET(self
->area
, x
, y
, w
, h
);
2905 /* for app-requested resizes, always resize if 'resized' is true.
2906 for user-requested ones, only resize if final is true, or when
2907 resizing in redraw mode */
2908 send_resize_client
= ((!user
&& resized
) ||
2910 (resized
&& config_resize_redraw
))));
2912 /* if the client is enlarging, then resize the client before the frame */
2913 if (send_resize_client
&& (w
> oldw
|| h
> oldh
)) {
2914 XMoveResizeWindow(ob_display
, self
->window
,
2915 self
->frame
->size
.left
, self
->frame
->size
.top
,
2916 MAX(w
, oldw
), MAX(h
, oldh
));
2917 frame_adjust_client_area(self
->frame
);
2920 /* find the frame's dimensions and move/resize it */
2924 /* if decorations changed, then readjust everything for the frame */
2925 if (self
->decorations
!= fdecor
||
2926 self
->max_horz
!= fhorz
|| self
->max_vert
!= fvert
)
2928 fmoved
= fresized
= TRUE
;
2931 /* adjust the frame */
2932 if (fmoved
|| fresized
) {
2933 gulong ignore_start
;
2935 ignore_start
= event_start_ignore_all_enters();
2937 frame_adjust_area(self
->frame
, fmoved
, fresized
, FALSE
);
2940 event_end_ignore_all_enters(ignore_start
);
2943 if (!user
|| final
) {
2944 gint oldrx
= self
->root_pos
.x
;
2945 gint oldry
= self
->root_pos
.y
;
2946 /* we have reset the client to 0 border width, so don't include
2947 it in these coords */
2948 POINT_SET(self
->root_pos
,
2949 self
->frame
->area
.x
+ self
->frame
->size
.left
-
2951 self
->frame
->area
.y
+ self
->frame
->size
.top
-
2952 self
->border_width
);
2953 if (self
->root_pos
.x
!= oldrx
|| self
->root_pos
.y
!= oldry
)
2957 /* This is kinda tricky and should not be changed.. let me explain!
2959 When user = FALSE, then the request is coming from the application
2960 itself, and we are more strict about when to send a synthetic
2961 ConfigureNotify. We strictly follow the rules of the ICCCM sec 4.1.5
2962 in this case (if force_reply is true)
2964 When user = TRUE, then the request is coming from "us", like when we
2965 maximize a window or something. In this case we are more lenient. We
2966 used to follow the same rules as above, but _Java_ Swing can't handle
2967 this. So just to appease Swing, when user = TRUE, we always send
2968 a synthetic ConfigureNotify to give the window its root coordinates.
2970 if ((!user
&& !resized
&& (rootmoved
|| force_reply
)) ||
2971 (user
&& final
&& rootmoved
))
2975 event
.type
= ConfigureNotify
;
2976 event
.xconfigure
.display
= ob_display
;
2977 event
.xconfigure
.event
= self
->window
;
2978 event
.xconfigure
.window
= self
->window
;
2980 ob_debug("Sending ConfigureNotify to %s for %d,%d %dx%d\n",
2981 self
->title
, self
->root_pos
.x
, self
->root_pos
.y
, w
, h
);
2983 /* root window real coords */
2984 event
.xconfigure
.x
= self
->root_pos
.x
;
2985 event
.xconfigure
.y
= self
->root_pos
.y
;
2986 event
.xconfigure
.width
= w
;
2987 event
.xconfigure
.height
= h
;
2988 event
.xconfigure
.border_width
= self
->border_width
;
2989 event
.xconfigure
.above
= None
;
2990 event
.xconfigure
.override_redirect
= FALSE
;
2991 XSendEvent(event
.xconfigure
.display
, event
.xconfigure
.window
,
2992 FALSE
, StructureNotifyMask
, &event
);
2995 /* if the client is shrinking, then resize the frame before the client.
2997 both of these resize sections may run, because the top one only resizes
2998 in the direction that is growing
3000 if (send_resize_client
&& (w
<= oldw
|| h
<= oldh
)) {
3001 frame_adjust_client_area(self
->frame
);
3002 XMoveResizeWindow(ob_display
, self
->window
,
3003 self
->frame
->size
.left
, self
->frame
->size
.top
, w
, h
);
3009 void client_fullscreen(ObClient
*self
, gboolean fs
)
3013 if (!(self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
) || /* can't */
3014 self
->fullscreen
== fs
) return; /* already done */
3016 self
->fullscreen
= fs
;
3017 client_change_state(self
); /* change the state hints on the client */
3020 self
->pre_fullscreen_area
= self
->area
;
3021 /* if the window is maximized, its area isn't all that meaningful.
3022 save it's premax area instead. */
3023 if (self
->max_horz
) {
3024 self
->pre_fullscreen_area
.x
= self
->pre_max_area
.x
;
3025 self
->pre_fullscreen_area
.width
= self
->pre_max_area
.width
;
3027 if (self
->max_vert
) {
3028 self
->pre_fullscreen_area
.y
= self
->pre_max_area
.y
;
3029 self
->pre_fullscreen_area
.height
= self
->pre_max_area
.height
;
3032 /* these will help configure_full figure out where to fullscreen
3036 w
= self
->area
.width
;
3037 h
= self
->area
.height
;
3039 g_assert(self
->pre_fullscreen_area
.width
> 0 &&
3040 self
->pre_fullscreen_area
.height
> 0);
3042 x
= self
->pre_fullscreen_area
.x
;
3043 y
= self
->pre_fullscreen_area
.y
;
3044 w
= self
->pre_fullscreen_area
.width
;
3045 h
= self
->pre_fullscreen_area
.height
;
3046 RECT_SET(self
->pre_fullscreen_area
, 0, 0, 0, 0);
3049 ob_debug("Window %s going fullscreen (%d)\n",
3050 self
->title
, self
->fullscreen
);
3052 client_setup_decor_and_functions(self
, FALSE
);
3053 client_move_resize(self
, x
, y
, w
, h
);
3055 /* and adjust our layer/stacking. do this after resizing the window,
3056 and applying decorations, because windows which fill the screen are
3057 considered "fullscreen" and it affects their layer */
3058 client_calc_layer(self
);
3061 /* try focus us when we go into fullscreen mode */
3066 static void client_iconify_recursive(ObClient
*self
,
3067 gboolean iconic
, gboolean curdesk
,
3068 gboolean hide_animation
)
3071 gboolean changed
= FALSE
;
3074 if (self
->iconic
!= iconic
) {
3075 ob_debug("%sconifying window: 0x%lx\n", (iconic
? "I" : "Uni"),
3079 /* don't let non-normal windows iconify along with their parents
3081 if (client_normal(self
)) {
3082 self
->iconic
= iconic
;
3084 /* update the focus lists.. iconic windows go to the bottom of
3086 focus_order_to_bottom(self
);
3091 self
->iconic
= iconic
;
3093 if (curdesk
&& self
->desktop
!= screen_desktop
&&
3094 self
->desktop
!= DESKTOP_ALL
)
3095 client_set_desktop(self
, screen_desktop
, FALSE
, FALSE
);
3097 /* this puts it after the current focused window */
3098 focus_order_remove(self
);
3099 focus_order_add_new(self
);
3106 client_change_state(self
);
3107 if (config_animate_iconify
&& !hide_animation
)
3108 frame_begin_iconify_animation(self
->frame
, iconic
);
3109 /* do this after starting the animation so it doesn't flash */
3110 client_showhide(self
);
3113 /* iconify all direct transients, and deiconify all transients
3115 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
3116 if (it
->data
!= self
)
3117 if (client_is_direct_child(self
, it
->data
) || !iconic
)
3118 client_iconify_recursive(it
->data
, iconic
, curdesk
,
3122 void client_iconify(ObClient
*self
, gboolean iconic
, gboolean curdesk
,
3123 gboolean hide_animation
)
3125 if (self
->functions
& OB_CLIENT_FUNC_ICONIFY
|| !iconic
) {
3126 /* move up the transient chain as far as possible first */
3127 self
= client_search_top_direct_parent(self
);
3128 client_iconify_recursive(self
, iconic
, curdesk
, hide_animation
);
3132 void client_maximize(ObClient
*self
, gboolean max
, gint dir
)
3136 g_assert(dir
== 0 || dir
== 1 || dir
== 2);
3137 if (!(self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
)) return; /* can't */
3139 /* check if already done */
3141 if (dir
== 0 && self
->max_horz
&& self
->max_vert
) return;
3142 if (dir
== 1 && self
->max_horz
) return;
3143 if (dir
== 2 && self
->max_vert
) return;
3145 if (dir
== 0 && !self
->max_horz
&& !self
->max_vert
) return;
3146 if (dir
== 1 && !self
->max_horz
) return;
3147 if (dir
== 2 && !self
->max_vert
) return;
3150 /* these will help configure_full figure out which screen to fill with
3154 w
= self
->area
.width
;
3155 h
= self
->area
.height
;
3158 if ((dir
== 0 || dir
== 1) && !self
->max_horz
) { /* horz */
3159 RECT_SET(self
->pre_max_area
,
3160 self
->area
.x
, self
->pre_max_area
.y
,
3161 self
->area
.width
, self
->pre_max_area
.height
);
3163 if ((dir
== 0 || dir
== 2) && !self
->max_vert
) { /* vert */
3164 RECT_SET(self
->pre_max_area
,
3165 self
->pre_max_area
.x
, self
->area
.y
,
3166 self
->pre_max_area
.width
, self
->area
.height
);
3169 if ((dir
== 0 || dir
== 1) && self
->max_horz
) { /* horz */
3170 g_assert(self
->pre_max_area
.width
> 0);
3172 x
= self
->pre_max_area
.x
;
3173 w
= self
->pre_max_area
.width
;
3175 RECT_SET(self
->pre_max_area
, 0, self
->pre_max_area
.y
,
3176 0, self
->pre_max_area
.height
);
3178 if ((dir
== 0 || dir
== 2) && self
->max_vert
) { /* vert */
3179 g_assert(self
->pre_max_area
.height
> 0);
3181 y
= self
->pre_max_area
.y
;
3182 h
= self
->pre_max_area
.height
;
3184 RECT_SET(self
->pre_max_area
, self
->pre_max_area
.x
, 0,
3185 self
->pre_max_area
.width
, 0);
3189 if (dir
== 0 || dir
== 1) /* horz */
3190 self
->max_horz
= max
;
3191 if (dir
== 0 || dir
== 2) /* vert */
3192 self
->max_vert
= max
;
3194 client_change_state(self
); /* change the state hints on the client */
3196 client_setup_decor_and_functions(self
, FALSE
);
3197 client_move_resize(self
, x
, y
, w
, h
);
3200 void client_shade(ObClient
*self
, gboolean shade
)
3202 if ((!(self
->functions
& OB_CLIENT_FUNC_SHADE
) &&
3203 shade
) || /* can't shade */
3204 self
->shaded
== shade
) return; /* already done */
3206 self
->shaded
= shade
;
3207 client_change_state(self
);
3208 client_change_wm_state(self
); /* the window is being hidden/shown */
3209 /* resize the frame to just the titlebar */
3210 frame_adjust_area(self
->frame
, FALSE
, TRUE
, FALSE
);
3213 static void client_ping_event(ObClient
*self
, gboolean dead
)
3215 self
->not_responding
= dead
;
3216 client_update_title(self
);
3219 /* try kill it nicely the first time again, if it started responding
3221 self
->close_tried_term
= FALSE
;
3225 void client_close(ObClient
*self
)
3227 if (!(self
->functions
& OB_CLIENT_FUNC_CLOSE
)) return;
3229 /* in the case that the client provides no means to requesting that it
3230 close, we just kill it */
3231 if (!self
->delete_window
)
3232 /* don't use client_kill(), we should only kill based on PID in
3233 response to a lack of PING replies */
3234 XKillClient(ob_display
, self
->window
);
3235 else if (self
->not_responding
)
3238 /* request the client to close with WM_DELETE_WINDOW */
3239 PROP_MSG_TO(self
->window
, self
->window
, wm_protocols
,
3240 prop_atoms
.wm_delete_window
, event_curtime
, 0, 0, 0,
3244 void client_kill(ObClient
*self
)
3246 if (!self
->client_machine
&& self
->pid
) {
3247 /* running on the local host */
3248 if (!self
->close_tried_term
) {
3249 ob_debug("killing window 0x%x with pid %lu, with SIGTERM\n",
3250 self
->window
, self
->pid
);
3251 kill(self
->pid
, SIGTERM
);
3252 self
->close_tried_term
= TRUE
;
3254 /* show that we're trying to kill it */
3255 client_update_title(self
);
3258 ob_debug("killing window 0x%x with pid %lu, with SIGKILL\n",
3259 self
->window
, self
->pid
);
3260 kill(self
->pid
, SIGKILL
); /* kill -9 */
3264 XKillClient(ob_display
, self
->window
);
3267 void client_hilite(ObClient
*self
, gboolean hilite
)
3269 if (self
->demands_attention
== hilite
)
3270 return; /* no change */
3272 /* don't allow focused windows to hilite */
3273 self
->demands_attention
= hilite
&& !client_focused(self
);
3274 if (self
->frame
!= NULL
) { /* if we're mapping, just set the state */
3275 if (self
->demands_attention
)
3276 frame_flash_start(self
->frame
);
3278 frame_flash_stop(self
->frame
);
3279 client_change_state(self
);
3283 static void client_set_desktop_recursive(ObClient
*self
,
3291 if (target
!= self
->desktop
&& self
->type
!= OB_CLIENT_TYPE_DESKTOP
) {
3293 ob_debug("Setting desktop %u\n", target
+1);
3295 g_assert(target
< screen_num_desktops
|| target
== DESKTOP_ALL
);
3297 old
= self
->desktop
;
3298 self
->desktop
= target
;
3299 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, target
);
3300 /* the frame can display the current desktop state */
3301 frame_adjust_state(self
->frame
);
3302 /* 'move' the window to the new desktop */
3306 /* raise if it was not already on the desktop */
3307 if (old
!= DESKTOP_ALL
&& !dontraise
)
3308 stacking_raise(CLIENT_AS_WINDOW(self
));
3309 if (STRUT_EXISTS(self
->strut
))
3310 screen_update_areas();
3312 /* the new desktop's geometry may be different, so we may need to
3313 resize, for example if we are maximized */
3314 client_reconfigure(self
, FALSE
);
3317 /* move all transients */
3318 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
3319 if (it
->data
!= self
)
3320 if (client_is_direct_child(self
, it
->data
))
3321 client_set_desktop_recursive(it
->data
, target
,
3322 donthide
, dontraise
);
3325 void client_set_desktop(ObClient
*self
, guint target
,
3326 gboolean donthide
, gboolean dontraise
)
3328 self
= client_search_top_direct_parent(self
);
3329 client_set_desktop_recursive(self
, target
, donthide
, dontraise
);
3332 gboolean
client_is_direct_child(ObClient
*parent
, ObClient
*child
)
3334 while (child
!= parent
&& (child
= client_direct_parent(child
)));
3335 return child
== parent
;
3338 ObClient
*client_search_modal_child(ObClient
*self
)
3343 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
3344 ObClient
*c
= it
->data
;
3345 if ((ret
= client_search_modal_child(c
))) return ret
;
3346 if (c
->modal
) return c
;
3351 gboolean
client_validate(ObClient
*self
)
3355 XSync(ob_display
, FALSE
); /* get all events on the server */
3357 if (XCheckTypedWindowEvent(ob_display
, self
->window
, DestroyNotify
, &e
) ||
3358 XCheckTypedWindowEvent(ob_display
, self
->window
, UnmapNotify
, &e
)) {
3359 XPutBackEvent(ob_display
, &e
);
3366 void client_set_wm_state(ObClient
*self
, glong state
)
3368 if (state
== self
->wmstate
) return; /* no change */
3372 client_iconify(self
, TRUE
, TRUE
, FALSE
);
3375 client_iconify(self
, FALSE
, TRUE
, FALSE
);
3380 void client_set_state(ObClient
*self
, Atom action
, glong data1
, glong data2
)
3382 gboolean shaded
= self
->shaded
;
3383 gboolean fullscreen
= self
->fullscreen
;
3384 gboolean undecorated
= self
->undecorated
;
3385 gboolean max_horz
= self
->max_horz
;
3386 gboolean max_vert
= self
->max_vert
;
3387 gboolean modal
= self
->modal
;
3388 gboolean iconic
= self
->iconic
;
3389 gboolean demands_attention
= self
->demands_attention
;
3390 gboolean above
= self
->above
;
3391 gboolean below
= self
->below
;
3394 if (!(action
== prop_atoms
.net_wm_state_add
||
3395 action
== prop_atoms
.net_wm_state_remove
||
3396 action
== prop_atoms
.net_wm_state_toggle
))
3397 /* an invalid action was passed to the client message, ignore it */
3400 for (i
= 0; i
< 2; ++i
) {
3401 Atom state
= i
== 0 ? data1
: data2
;
3403 if (!state
) continue;
3405 /* if toggling, then pick whether we're adding or removing */
3406 if (action
== prop_atoms
.net_wm_state_toggle
) {
3407 if (state
== prop_atoms
.net_wm_state_modal
)
3408 action
= modal
? prop_atoms
.net_wm_state_remove
:
3409 prop_atoms
.net_wm_state_add
;
3410 else if (state
== prop_atoms
.net_wm_state_maximized_vert
)
3411 action
= self
->max_vert
? prop_atoms
.net_wm_state_remove
:
3412 prop_atoms
.net_wm_state_add
;
3413 else if (state
== prop_atoms
.net_wm_state_maximized_horz
)
3414 action
= self
->max_horz
? prop_atoms
.net_wm_state_remove
:
3415 prop_atoms
.net_wm_state_add
;
3416 else if (state
== prop_atoms
.net_wm_state_shaded
)
3417 action
= shaded
? prop_atoms
.net_wm_state_remove
:
3418 prop_atoms
.net_wm_state_add
;
3419 else if (state
== prop_atoms
.net_wm_state_skip_taskbar
)
3420 action
= self
->skip_taskbar
?
3421 prop_atoms
.net_wm_state_remove
:
3422 prop_atoms
.net_wm_state_add
;
3423 else if (state
== prop_atoms
.net_wm_state_skip_pager
)
3424 action
= self
->skip_pager
?
3425 prop_atoms
.net_wm_state_remove
:
3426 prop_atoms
.net_wm_state_add
;
3427 else if (state
== prop_atoms
.net_wm_state_hidden
)
3428 action
= self
->iconic
?
3429 prop_atoms
.net_wm_state_remove
:
3430 prop_atoms
.net_wm_state_add
;
3431 else if (state
== prop_atoms
.net_wm_state_fullscreen
)
3432 action
= fullscreen
?
3433 prop_atoms
.net_wm_state_remove
:
3434 prop_atoms
.net_wm_state_add
;
3435 else if (state
== prop_atoms
.net_wm_state_above
)
3436 action
= self
->above
? prop_atoms
.net_wm_state_remove
:
3437 prop_atoms
.net_wm_state_add
;
3438 else if (state
== prop_atoms
.net_wm_state_below
)
3439 action
= self
->below
? prop_atoms
.net_wm_state_remove
:
3440 prop_atoms
.net_wm_state_add
;
3441 else if (state
== prop_atoms
.net_wm_state_demands_attention
)
3442 action
= self
->demands_attention
?
3443 prop_atoms
.net_wm_state_remove
:
3444 prop_atoms
.net_wm_state_add
;
3445 else if (state
== prop_atoms
.ob_wm_state_undecorated
)
3446 action
= undecorated
? prop_atoms
.net_wm_state_remove
:
3447 prop_atoms
.net_wm_state_add
;
3450 if (action
== prop_atoms
.net_wm_state_add
) {
3451 if (state
== prop_atoms
.net_wm_state_modal
) {
3453 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
3455 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
3457 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
3459 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
3460 self
->skip_taskbar
= TRUE
;
3461 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
3462 self
->skip_pager
= TRUE
;
3463 } else if (state
== prop_atoms
.net_wm_state_hidden
) {
3465 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
3467 } else if (state
== prop_atoms
.net_wm_state_above
) {
3470 } else if (state
== prop_atoms
.net_wm_state_below
) {
3473 } else if (state
== prop_atoms
.net_wm_state_demands_attention
) {
3474 demands_attention
= TRUE
;
3475 } else if (state
== prop_atoms
.ob_wm_state_undecorated
) {
3479 } else { /* action == prop_atoms.net_wm_state_remove */
3480 if (state
== prop_atoms
.net_wm_state_modal
) {
3482 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
3484 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
3486 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
3488 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
3489 self
->skip_taskbar
= FALSE
;
3490 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
3491 self
->skip_pager
= FALSE
;
3492 } else if (state
== prop_atoms
.net_wm_state_hidden
) {
3494 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
3496 } else if (state
== prop_atoms
.net_wm_state_above
) {
3498 } else if (state
== prop_atoms
.net_wm_state_below
) {
3500 } else if (state
== prop_atoms
.net_wm_state_demands_attention
) {
3501 demands_attention
= FALSE
;
3502 } else if (state
== prop_atoms
.ob_wm_state_undecorated
) {
3503 undecorated
= FALSE
;
3508 if (max_horz
!= self
->max_horz
|| max_vert
!= self
->max_vert
) {
3509 if (max_horz
!= self
->max_horz
&& max_vert
!= self
->max_vert
) {
3511 if (max_horz
== max_vert
) { /* both going the same way */
3512 client_maximize(self
, max_horz
, 0);
3514 client_maximize(self
, max_horz
, 1);
3515 client_maximize(self
, max_vert
, 2);
3519 if (max_horz
!= self
->max_horz
)
3520 client_maximize(self
, max_horz
, 1);
3522 client_maximize(self
, max_vert
, 2);
3525 /* change fullscreen state before shading, as it will affect if the window
3527 if (fullscreen
!= self
->fullscreen
)
3528 client_fullscreen(self
, fullscreen
);
3529 if (shaded
!= self
->shaded
)
3530 client_shade(self
, shaded
);
3531 if (undecorated
!= self
->undecorated
)
3532 client_set_undecorated(self
, undecorated
);
3533 if (above
!= self
->above
|| below
!= self
->below
) {
3534 self
->above
= above
;
3535 self
->below
= below
;
3536 client_calc_layer(self
);
3539 if (modal
!= self
->modal
) {
3540 self
->modal
= modal
;
3541 /* when a window changes modality, then its stacking order with its
3542 transients needs to change */
3543 stacking_raise(CLIENT_AS_WINDOW(self
));
3545 /* it also may get focused. if something is focused that shouldn't
3546 be focused anymore, then move the focus */
3547 if (focus_client
&& client_focus_target(focus_client
) != focus_client
)
3548 client_focus(focus_client
);
3551 if (iconic
!= self
->iconic
)
3552 client_iconify(self
, iconic
, FALSE
, FALSE
);
3554 if (demands_attention
!= self
->demands_attention
)
3555 client_hilite(self
, demands_attention
);
3557 client_change_state(self
); /* change the hint to reflect these changes */
3560 ObClient
*client_focus_target(ObClient
*self
)
3562 ObClient
*child
= NULL
;
3564 child
= client_search_modal_child(self
);
3565 if (child
) return child
;
3569 gboolean
client_can_focus(ObClient
*self
)
3571 /* choose the correct target */
3572 self
= client_focus_target(self
);
3574 if (!self
->frame
->visible
)
3577 if (!(self
->can_focus
|| self
->focus_notify
))
3583 gboolean
client_focus(ObClient
*self
)
3585 /* we might not focus this window, so if we have modal children which would
3586 be focused instead, bring them to this desktop */
3587 client_bring_modal_windows(self
);
3589 /* choose the correct target */
3590 self
= client_focus_target(self
);
3592 if (!client_can_focus(self
)) {
3593 ob_debug_type(OB_DEBUG_FOCUS
,
3594 "Client %s can't be focused\n", self
->title
);
3598 ob_debug_type(OB_DEBUG_FOCUS
,
3599 "Focusing client \"%s\" (0x%x) at time %u\n",
3600 self
->title
, self
->window
, event_curtime
);
3602 /* if using focus_delay, stop the timer now so that focus doesn't
3604 event_halt_focus_delay();
3606 /* if there is a grab going on, then we need to cancel it. if we move
3607 focus during the grab, applications will get NotifyWhileGrabbed events
3610 actions should not rely on being able to move focus during an
3613 event_cancel_all_key_grabs();
3615 xerror_set_ignore(TRUE
);
3616 xerror_occured
= FALSE
;
3618 if (self
->can_focus
) {
3619 /* This can cause a BadMatch error with CurrentTime, or if an app
3620 passed in a bad time for _NET_WM_ACTIVE_WINDOW. */
3621 XSetInputFocus(ob_display
, self
->window
, RevertToPointerRoot
,
3625 if (self
->focus_notify
) {
3627 ce
.xclient
.type
= ClientMessage
;
3628 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
3629 ce
.xclient
.display
= ob_display
;
3630 ce
.xclient
.window
= self
->window
;
3631 ce
.xclient
.format
= 32;
3632 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_take_focus
;
3633 ce
.xclient
.data
.l
[1] = event_curtime
;
3634 ce
.xclient
.data
.l
[2] = 0l;
3635 ce
.xclient
.data
.l
[3] = 0l;
3636 ce
.xclient
.data
.l
[4] = 0l;
3637 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
3640 xerror_set_ignore(FALSE
);
3642 ob_debug_type(OB_DEBUG_FOCUS
, "Error focusing? %d\n", xerror_occured
);
3643 return !xerror_occured
;
3646 static void client_present(ObClient
*self
, gboolean here
, gboolean raise
,
3649 if (client_normal(self
) && screen_showing_desktop
)
3650 screen_show_desktop(FALSE
, self
);
3652 client_iconify(self
, FALSE
, here
, FALSE
);
3653 if (self
->desktop
!= DESKTOP_ALL
&&
3654 self
->desktop
!= screen_desktop
)
3657 client_set_desktop(self
, screen_desktop
, FALSE
, TRUE
);
3659 screen_set_desktop(self
->desktop
, FALSE
);
3660 } else if (!self
->frame
->visible
)
3661 /* if its not visible for other reasons, then don't mess
3664 if (self
->shaded
&& unshade
)
3665 client_shade(self
, FALSE
);
3667 stacking_raise(CLIENT_AS_WINDOW(self
));
3672 void client_activate(ObClient
*self
, gboolean here
, gboolean raise
,
3673 gboolean unshade
, gboolean user
)
3675 client_present(self
, here
, raise
, unshade
);
3678 static void client_bring_windows_recursive(ObClient
*self
,
3686 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
3687 client_bring_windows_recursive(it
->data
, desktop
,
3688 helpers
, modals
, iconic
);
3690 if (((helpers
&& client_helper(self
)) ||
3691 (modals
&& self
->modal
)) &&
3692 ((self
->desktop
!= desktop
&& self
->desktop
!= DESKTOP_ALL
) ||
3693 (iconic
&& self
->iconic
)))
3695 if (iconic
&& self
->iconic
)
3696 client_iconify(self
, FALSE
, TRUE
, FALSE
);
3698 client_set_desktop(self
, desktop
, FALSE
, FALSE
);
3702 void client_bring_helper_windows(ObClient
*self
)
3704 client_bring_windows_recursive(self
, self
->desktop
, TRUE
, FALSE
, FALSE
);
3707 void client_bring_modal_windows(ObClient
*self
)
3709 client_bring_windows_recursive(self
, self
->desktop
, FALSE
, TRUE
, TRUE
);
3712 gboolean
client_focused(ObClient
*self
)
3714 return self
== focus_client
;
3717 static ObClientIcon
* client_icon_recursive(ObClient
*self
, gint w
, gint h
)
3720 gulong min_diff
, min_i
;
3722 if (!self
->nicons
) {
3723 ObClientIcon
*parent
= NULL
;
3726 for (it
= self
->parents
; it
; it
= g_slist_next(it
)) {
3727 ObClient
*c
= it
->data
;
3728 if ((parent
= client_icon_recursive(c
, w
, h
)))
3735 /* some kind of crappy approximation to find the icon closest in size to
3736 what we requested, but icons are generally all the same ratio as
3737 eachother so it's good enough. */
3739 min_diff
= ABS(self
->icons
[0].width
- w
) + ABS(self
->icons
[0].height
- h
);
3742 for (i
= 1; i
< self
->nicons
; ++i
) {
3745 diff
= ABS(self
->icons
[i
].width
- w
) + ABS(self
->icons
[i
].height
- h
);
3746 if (diff
< min_diff
) {
3751 return &self
->icons
[min_i
];
3754 const ObClientIcon
* client_icon(ObClient
*self
, gint w
, gint h
)
3757 static ObClientIcon deficon
;
3759 if (!(ret
= client_icon_recursive(self
, w
, h
))) {
3760 deficon
.width
= deficon
.height
= 48;
3761 deficon
.data
= ob_rr_theme
->def_win_icon
;
3767 void client_set_layer(ObClient
*self
, gint layer
)
3771 self
->above
= FALSE
;
3772 } else if (layer
== 0) {
3773 self
->below
= self
->above
= FALSE
;
3775 self
->below
= FALSE
;
3778 client_calc_layer(self
);
3779 client_change_state(self
); /* reflect this in the state hints */
3782 void client_set_undecorated(ObClient
*self
, gboolean undecorated
)
3784 if (self
->undecorated
!= undecorated
&&
3785 /* don't let it undecorate if the function is missing, but let
3787 (self
->functions
& OB_CLIENT_FUNC_UNDECORATE
|| !undecorated
))
3789 self
->undecorated
= undecorated
;
3790 client_setup_decor_and_functions(self
, TRUE
);
3791 client_change_state(self
); /* reflect this in the state hints */
3795 guint
client_monitor(ObClient
*self
)
3797 return screen_find_monitor(&self
->frame
->area
);
3800 ObClient
*client_direct_parent(ObClient
*self
)
3802 if (!self
->parents
) return NULL
;
3803 if (self
->transient_for_group
) return NULL
;
3804 return self
->parents
->data
;
3807 ObClient
*client_search_top_direct_parent(ObClient
*self
)
3810 while ((p
= client_direct_parent(self
))) self
= p
;
3814 static GSList
*client_search_all_top_parents_internal(ObClient
*self
,
3816 ObStackingLayer layer
)
3821 /* move up the direct transient chain as far as possible */
3822 while ((p
= client_direct_parent(self
)) &&
3823 (!bylayer
|| p
->layer
== layer
))
3827 ret
= g_slist_prepend(NULL
, self
);
3829 ret
= g_slist_copy(self
->parents
);
3834 GSList
*client_search_all_top_parents(ObClient
*self
)
3836 return client_search_all_top_parents_internal(self
, FALSE
, 0);
3839 GSList
*client_search_all_top_parents_layer(ObClient
*self
)
3841 return client_search_all_top_parents_internal(self
, TRUE
, self
->layer
);
3844 ObClient
*client_search_focus_parent(ObClient
*self
)
3848 for (it
= self
->parents
; it
; it
= g_slist_next(it
))
3849 if (client_focused(it
->data
)) return it
->data
;
3854 ObClient
*client_search_parent(ObClient
*self
, ObClient
*search
)
3858 for (it
= self
->parents
; it
; it
= g_slist_next(it
))
3859 if (it
->data
== search
) return search
;
3864 ObClient
*client_search_transient(ObClient
*self
, ObClient
*search
)
3868 for (sit
= self
->transients
; sit
; sit
= g_slist_next(sit
)) {
3869 if (sit
->data
== search
)
3871 if (client_search_transient(sit
->data
, search
))
3877 static void detect_edge(Rect area
, ObDirection dir
,
3878 gint my_head
, gint my_size
,
3879 gint my_edge_start
, gint my_edge_size
,
3880 gint
*dest
, gboolean
*near_edge
)
3882 gint edge_start
, edge_size
, head
, tail
;
3883 gboolean skip_head
= FALSE
, skip_tail
= FALSE
;
3886 case OB_DIRECTION_NORTH
:
3887 case OB_DIRECTION_SOUTH
:
3888 edge_start
= area
.x
;
3889 edge_size
= area
.width
;
3891 case OB_DIRECTION_EAST
:
3892 case OB_DIRECTION_WEST
:
3893 edge_start
= area
.y
;
3894 edge_size
= area
.height
;
3897 g_assert_not_reached();
3900 /* do we collide with this window? */
3901 if (!RANGES_INTERSECT(my_edge_start
, my_edge_size
,
3902 edge_start
, edge_size
))
3906 case OB_DIRECTION_NORTH
:
3907 head
= RECT_BOTTOM(area
);
3908 tail
= RECT_TOP(area
);
3910 case OB_DIRECTION_SOUTH
:
3911 head
= RECT_TOP(area
);
3912 tail
= RECT_BOTTOM(area
);
3914 case OB_DIRECTION_WEST
:
3915 head
= RECT_RIGHT(area
);
3916 tail
= RECT_LEFT(area
);
3918 case OB_DIRECTION_EAST
:
3919 head
= RECT_LEFT(area
);
3920 tail
= RECT_RIGHT(area
);
3923 g_assert_not_reached();
3926 case OB_DIRECTION_NORTH
:
3927 case OB_DIRECTION_WEST
:
3928 /* check if our window is past the head of this window */
3929 if (my_head
<= head
+ 1)
3931 /* check if our window's tail is past the tail of this window */
3932 if (my_head
+ my_size
- 1 <= tail
)
3934 /* check if the head of this window is closer than the previously
3935 chosen edge (take into account that the previously chosen
3936 edge might have been a tail, not a head) */
3937 if (head
+ (*near_edge
? 0 : my_size
) < *dest
)
3939 /* check if the tail of this window is closer than the previously
3940 chosen edge (take into account that the previously chosen
3941 edge might have been a head, not a tail) */
3942 if (tail
- (!*near_edge
? 0 : my_size
) < *dest
)
3945 case OB_DIRECTION_SOUTH
:
3946 case OB_DIRECTION_EAST
:
3947 /* check if our window is past the head of this window */
3948 if (my_head
>= head
- 1)
3950 /* check if our window's tail is past the tail of this window */
3951 if (my_head
- my_size
+ 1 >= tail
)
3953 /* check if the head of this window is closer than the previously
3954 chosen edge (take into account that the previously chosen
3955 edge might have been a tail, not a head) */
3956 if (head
- (*near_edge
? 0 : my_size
) > *dest
)
3958 /* check if the tail of this window is closer than the previously
3959 chosen edge (take into account that the previously chosen
3960 edge might have been a head, not a tail) */
3961 if (tail
+ (!*near_edge
? 0 : my_size
) > *dest
)
3965 g_assert_not_reached();
3968 ob_debug("my head %d size %d\n", my_head
, my_size
);
3969 ob_debug("head %d tail %d deest %d\n", head
, tail
, *dest
);
3971 ob_debug("using near edge %d\n", head
);
3975 else if (!skip_tail
) {
3976 ob_debug("using far edge %d\n", tail
);
3982 void client_find_edge_directional(ObClient
*self
, ObDirection dir
,
3983 gint my_head
, gint my_size
,
3984 gint my_edge_start
, gint my_edge_size
,
3985 gint
*dest
, gboolean
*near_edge
)
3992 a
= screen_area(self
->desktop
, SCREEN_AREA_ALL_MONITORS
,
3993 &self
->frame
->area
);
3994 mon
= screen_area(self
->desktop
, SCREEN_AREA_ONE_MONITOR
,
3995 &self
->frame
->area
);
3998 case OB_DIRECTION_NORTH
:
3999 if (my_head
>= RECT_TOP(*mon
) + 1)
4000 edge
= RECT_TOP(*mon
) - 1;
4002 edge
= RECT_TOP(*a
) - 1;
4004 case OB_DIRECTION_SOUTH
:
4005 if (my_head
<= RECT_BOTTOM(*mon
) - 1)
4006 edge
= RECT_BOTTOM(*mon
) + 1;
4008 edge
= RECT_BOTTOM(*a
) + 1;
4010 case OB_DIRECTION_EAST
:
4011 if (my_head
<= RECT_RIGHT(*mon
) - 1)
4012 edge
= RECT_RIGHT(*mon
) + 1;
4014 edge
= RECT_RIGHT(*a
) + 1;
4016 case OB_DIRECTION_WEST
:
4017 if (my_head
>= RECT_LEFT(*mon
) + 1)
4018 edge
= RECT_LEFT(*mon
) - 1;
4020 edge
= RECT_LEFT(*a
) - 1;
4023 g_assert_not_reached();
4025 /* default to the far edge, then narrow it down */
4029 for (it
= client_list
; it
; it
= g_list_next(it
)) {
4030 ObClient
*cur
= it
->data
;
4032 /* skip windows to not bump into */
4037 if (self
->desktop
!= cur
->desktop
&& cur
->desktop
!= DESKTOP_ALL
&&
4038 cur
->desktop
!= screen_desktop
)
4041 ob_debug("trying window %s\n", cur
->title
);
4043 detect_edge(cur
->frame
->area
, dir
, my_head
, my_size
, my_edge_start
,
4044 my_edge_size
, dest
, near_edge
);
4046 dock_get_area(&dock_area
);
4047 detect_edge(dock_area
, dir
, my_head
, my_size
, my_edge_start
,
4048 my_edge_size
, dest
, near_edge
);
4053 void client_find_move_directional(ObClient
*self
, ObDirection dir
,
4057 gint e
, e_start
, e_size
;
4061 case OB_DIRECTION_EAST
:
4062 head
= RECT_RIGHT(self
->frame
->area
);
4063 size
= self
->frame
->area
.width
;
4064 e_start
= RECT_TOP(self
->frame
->area
);
4065 e_size
= self
->frame
->area
.height
;
4067 case OB_DIRECTION_WEST
:
4068 head
= RECT_LEFT(self
->frame
->area
);
4069 size
= self
->frame
->area
.width
;
4070 e_start
= RECT_TOP(self
->frame
->area
);
4071 e_size
= self
->frame
->area
.height
;
4073 case OB_DIRECTION_NORTH
:
4074 head
= RECT_TOP(self
->frame
->area
);
4075 size
= self
->frame
->area
.height
;
4076 e_start
= RECT_LEFT(self
->frame
->area
);
4077 e_size
= self
->frame
->area
.width
;
4079 case OB_DIRECTION_SOUTH
:
4080 head
= RECT_BOTTOM(self
->frame
->area
);
4081 size
= self
->frame
->area
.height
;
4082 e_start
= RECT_LEFT(self
->frame
->area
);
4083 e_size
= self
->frame
->area
.width
;
4086 g_assert_not_reached();
4089 client_find_edge_directional(self
, dir
, head
, size
,
4090 e_start
, e_size
, &e
, &near
);
4091 *x
= self
->frame
->area
.x
;
4092 *y
= self
->frame
->area
.y
;
4094 case OB_DIRECTION_EAST
:
4095 if (near
) e
-= self
->frame
->area
.width
;
4099 case OB_DIRECTION_WEST
:
4101 else e
-= self
->frame
->area
.width
;
4104 case OB_DIRECTION_NORTH
:
4106 else e
-= self
->frame
->area
.height
;
4109 case OB_DIRECTION_SOUTH
:
4110 if (near
) e
-= self
->frame
->area
.height
;
4115 g_assert_not_reached();
4117 frame_frame_gravity(self
->frame
, x
, y
);
4120 void client_find_resize_directional(ObClient
*self
, ObDirection side
,
4122 gint
*x
, gint
*y
, gint
*w
, gint
*h
)
4125 gint e
, e_start
, e_size
, delta
;
4130 case OB_DIRECTION_EAST
:
4131 head
= RECT_RIGHT(self
->frame
->area
) +
4132 (self
->size_inc
.width
- 1) * (grow
? 1 : -1);
4133 e_start
= RECT_TOP(self
->frame
->area
);
4134 e_size
= self
->frame
->area
.height
;
4135 dir
= grow
? OB_DIRECTION_EAST
: OB_DIRECTION_WEST
;
4137 case OB_DIRECTION_WEST
:
4138 head
= RECT_LEFT(self
->frame
->area
) -
4139 (self
->size_inc
.width
- 1) * (grow
? 1 : -1);
4140 e_start
= RECT_TOP(self
->frame
->area
);
4141 e_size
= self
->frame
->area
.height
;
4142 dir
= grow
? OB_DIRECTION_WEST
: OB_DIRECTION_EAST
;
4144 case OB_DIRECTION_NORTH
:
4145 head
= RECT_TOP(self
->frame
->area
) -
4146 (self
->size_inc
.height
- 1) * (grow
? 1 : -1);
4147 e_start
= RECT_LEFT(self
->frame
->area
);
4148 e_size
= self
->frame
->area
.width
;
4149 dir
= grow
? OB_DIRECTION_NORTH
: OB_DIRECTION_SOUTH
;
4151 case OB_DIRECTION_SOUTH
:
4152 head
= RECT_BOTTOM(self
->frame
->area
) +
4153 (self
->size_inc
.height
- 1) * (grow
? 1 : -1);
4154 e_start
= RECT_LEFT(self
->frame
->area
);
4155 e_size
= self
->frame
->area
.width
;
4156 dir
= grow
? OB_DIRECTION_SOUTH
: OB_DIRECTION_NORTH
;
4159 g_assert_not_reached();
4162 ob_debug("head %d dir %d\n", head
, dir
);
4163 client_find_edge_directional(self
, dir
, head
, 1,
4164 e_start
, e_size
, &e
, &near
);
4165 ob_debug("edge %d\n", e
);
4166 *x
= self
->frame
->area
.x
;
4167 *y
= self
->frame
->area
.y
;
4168 *w
= self
->frame
->area
.width
;
4169 *h
= self
->frame
->area
.height
;
4171 case OB_DIRECTION_EAST
:
4172 if (grow
== near
) --e
;
4173 delta
= e
- RECT_RIGHT(self
->frame
->area
);
4176 case OB_DIRECTION_WEST
:
4177 if (grow
== near
) ++e
;
4178 delta
= RECT_LEFT(self
->frame
->area
) - e
;
4182 case OB_DIRECTION_NORTH
:
4183 if (grow
== near
) ++e
;
4184 delta
= RECT_TOP(self
->frame
->area
) - e
;
4188 case OB_DIRECTION_SOUTH
:
4189 if (grow
== near
) --e
;
4190 delta
= e
- RECT_BOTTOM(self
->frame
->area
);
4194 g_assert_not_reached();
4196 frame_frame_gravity(self
->frame
, x
, y
);
4197 *w
-= self
->frame
->size
.left
+ self
->frame
->size
.right
;
4198 *h
-= self
->frame
->size
.top
+ self
->frame
->size
.bottom
;
4201 ObClient
* client_under_pointer(void)
4205 ObClient
*ret
= NULL
;
4207 if (screen_pointer_pos(&x
, &y
)) {
4208 for (it
= stacking_list
; it
; it
= g_list_next(it
)) {
4209 if (WINDOW_IS_CLIENT(it
->data
)) {
4210 ObClient
*c
= WINDOW_AS_CLIENT(it
->data
);
4211 if (c
->frame
->visible
&&
4212 /* check the desktop, this is done during desktop
4213 switching and windows are shown/hidden status is not
4215 (c
->desktop
== screen_desktop
||
4216 c
->desktop
== DESKTOP_ALL
) &&
4217 /* ignore all animating windows */
4218 !frame_iconify_animating(c
->frame
) &&
4219 RECT_CONTAINS(c
->frame
->area
, x
, y
))
4230 gboolean
client_has_group_siblings(ObClient
*self
)
4232 return self
->group
&& self
->group
->members
->next
;