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"
25 #include "moveresize.h"
37 #include "menuframe.h"
40 #include "render/render.h"
42 #include "obt/display.h"
50 # include <signal.h> /* for kill() */
54 #include <X11/Xutil.h>
56 /*! The event mask to grab on client windows */
57 #define CLIENT_EVENTMASK (PropertyChangeMask | StructureNotifyMask | \
60 #define CLIENT_NOPROPAGATEMASK (ButtonPressMask | ButtonReleaseMask | \
65 ObClientCallback func
;
69 GList
*client_list
= NULL
;
71 static GSList
*client_destroy_notifies
= NULL
;
73 static void client_get_all(ObClient
*self
, gboolean real
);
74 static void client_get_startup_id(ObClient
*self
);
75 static void client_get_session_ids(ObClient
*self
);
76 static void client_get_area(ObClient
*self
);
77 static void client_get_desktop(ObClient
*self
);
78 static void client_get_state(ObClient
*self
);
79 static void client_get_shaped(ObClient
*self
);
80 static void client_get_mwm_hints(ObClient
*self
);
81 static void client_get_colormap(ObClient
*self
);
82 static void client_set_desktop_recursive(ObClient
*self
,
86 static void client_change_allowed_actions(ObClient
*self
);
87 static void client_change_state(ObClient
*self
);
88 static void client_change_wm_state(ObClient
*self
);
89 static void client_apply_startup_state(ObClient
*self
,
90 gint x
, gint y
, gint w
, gint h
);
91 static void client_restore_session_state(ObClient
*self
);
92 static gboolean
client_restore_session_stacking(ObClient
*self
);
93 static ObAppSettings
*client_get_settings_state(ObClient
*self
);
94 static void client_update_transient_tree(ObClient
*self
,
95 ObGroup
*oldgroup
, ObGroup
*newgroup
,
96 gboolean oldgtran
, gboolean newgtran
,
99 static void client_present(ObClient
*self
, gboolean here
, gboolean raise
,
101 static GSList
*client_search_all_top_parents_internal(ObClient
*self
,
103 ObStackingLayer layer
);
104 static void client_call_notifies(ObClient
*self
, GSList
*list
);
105 static void client_ping_event(ObClient
*self
, gboolean dead
);
108 void client_startup(gboolean reconfig
)
110 if (reconfig
) return;
115 void client_shutdown(gboolean reconfig
)
117 if (reconfig
) return;
120 static void client_call_notifies(ObClient
*self
, GSList
*list
)
124 for (it
= list
; it
; it
= g_slist_next(it
)) {
125 ClientCallback
*d
= it
->data
;
126 d
->func(self
, d
->data
);
130 void client_add_destroy_notify(ObClientCallback func
, gpointer data
)
132 ClientCallback
*d
= g_new(ClientCallback
, 1);
135 client_destroy_notifies
= g_slist_prepend(client_destroy_notifies
, d
);
138 void client_remove_destroy_notify(ObClientCallback func
)
142 for (it
= client_destroy_notifies
; it
; it
= g_slist_next(it
)) {
143 ClientCallback
*d
= it
->data
;
144 if (d
->func
== func
) {
146 client_destroy_notifies
=
147 g_slist_delete_link(client_destroy_notifies
, it
);
153 void client_set_list(void)
155 Window
*windows
, *win_it
;
157 guint size
= g_list_length(client_list
);
159 /* create an array of the window ids */
161 windows
= g_new(Window
, size
);
163 for (it
= client_list
; it
; it
= g_list_next(it
), ++win_it
)
164 *win_it
= ((ObClient
*)it
->data
)->window
;
168 OBT_PROP_SETA32(obt_root(ob_screen
), NET_CLIENT_LIST
, WINDOW
,
169 (gulong
*)windows
, size
);
177 void client_manage(Window window
)
180 XSetWindowAttributes attrib_set
;
181 gboolean activate
= FALSE
;
182 ObAppSettings
*settings
;
183 gboolean transient
= FALSE
;
184 Rect place
, *monitor
;
185 Time launch_time
, map_time
;
187 ob_debug("Managing window: 0x%lx", window
);
189 map_time
= event_get_server_time();
191 /* choose the events we want to receive on the CLIENT window */
192 attrib_set
.event_mask
= CLIENT_EVENTMASK
;
193 attrib_set
.do_not_propagate_mask
= CLIENT_NOPROPAGATEMASK
;
194 XChangeWindowAttributes(obt_display
, window
,
195 CWEventMask
|CWDontPropagate
, &attrib_set
);
197 /* create the ObClient struct, and populate it from the hints on the
199 self
= g_new0(ObClient
, 1);
200 self
->obwin
.type
= OB_WINDOW_CLASS_CLIENT
;
201 self
->window
= window
;
203 /* non-zero defaults */
204 self
->wmstate
= WithdrawnState
; /* make sure it gets updated first time */
205 self
->gravity
= NorthWestGravity
;
206 self
->desktop
= screen_num_desktops
; /* always an invalid value */
208 /* get all the stuff off the window */
209 client_get_all(self
, TRUE
);
211 ob_debug("Window type: %d", self
->type
);
212 ob_debug("Window group: 0x%x", self
->group
?self
->group
->leader
:0);
214 /* now we have all of the window's information so we can set this up.
215 do this before creating the frame, so it can tell that we are still
216 mapping and doesn't go applying things right away */
217 client_setup_decor_and_functions(self
, FALSE
);
219 /* specify that if we exit, the window should not be destroyed and
220 should be reparented back to root automatically */
221 XChangeSaveSet(obt_display
, window
, SetModeInsert
);
223 /* create the decoration frame for the client window */
224 self
->frame
= frame_new(self
);
226 frame_grab_client(self
->frame
);
228 /* we've grabbed everything and set everything that we need to at mapping
232 /* per-app settings override stuff from client_get_all, and return the
233 settings for other uses too. the returned settings is a shallow copy,
234 that needs to be freed with g_free(). */
235 settings
= client_get_settings_state(self
);
236 /* the session should get the last say though */
237 client_restore_session_state(self
);
239 /* tell startup notification that this app started */
240 launch_time
= sn_app_started(self
->startup_id
, self
->class, self
->name
);
242 /* do this after we have a frame.. it uses the frame to help determine the
243 WM_STATE to apply. */
244 client_change_state(self
);
246 /* add ourselves to the focus order */
247 focus_order_add_new(self
);
249 /* do this to add ourselves to the stacking list in a non-intrusive way */
250 client_calc_layer(self
);
252 /* focus the new window? */
253 if (ob_state() != OB_STATE_STARTING
&&
254 (!self
->session
|| self
->session
->focused
) &&
255 /* this means focus=true for window is same as config_focus_new=true */
256 ((config_focus_new
|| (settings
&& settings
->focus
== 1)) ||
257 client_search_focus_tree_full(self
)) &&
258 /* this checks for focus=false for the window */
259 (!settings
|| settings
->focus
!= 0) &&
260 focus_valid_target(self
, FALSE
, FALSE
, TRUE
, FALSE
, FALSE
))
265 /* remove the client's border */
266 XSetWindowBorderWidth(obt_display
, self
->window
, 0);
268 /* adjust the frame to the client's size before showing or placing
270 frame_adjust_area(self
->frame
, FALSE
, TRUE
, FALSE
);
271 frame_adjust_client_area(self
->frame
);
273 /* where the frame was placed is where the window was originally */
275 monitor
= screen_physical_area_monitor(screen_find_monitor(&place
));
277 /* figure out placement for the window if the window is new */
278 if (ob_state() == OB_STATE_RUNNING
) {
279 ob_debug("Positioned: %s @ %d %d",
280 (!self
->positioned
? "no" :
281 (self
->positioned
== PPosition
? "program specified" :
282 (self
->positioned
== USPosition
? "user specified" :
283 (self
->positioned
== (PPosition
| USPosition
) ?
284 "program + user specified" :
285 "BADNESS !?")))), place
.x
, place
.y
);
287 ob_debug("Sized: %s @ %d %d",
288 (!self
->sized
? "no" :
289 (self
->sized
== PSize
? "program specified" :
290 (self
->sized
== USSize
? "user specified" :
291 (self
->sized
== (PSize
| USSize
) ?
292 "program + user specified" :
293 "BADNESS !?")))), place
.width
, place
.height
);
295 /* splash screens are also returned as TRUE for transient,
296 and so will be forced on screen below */
297 transient
= place_client(self
, &place
.x
, &place
.y
, settings
);
299 /* make sure the window is visible. */
300 client_find_onscreen(self
, &place
.x
, &place
.y
,
301 place
.width
, place
.height
,
302 /* non-normal clients has less rules, and
303 windows that are being restored from a
304 session do also. we can assume you want
305 it back where you saved it. Clients saying
306 they placed themselves are subjected to
307 harder rules, ones that are placed by
308 place.c or by the user are allowed partially
309 off-screen and on xinerama divides (ie,
310 it is up to the placement routines to avoid
311 the xinerama divides)
313 splash screens get "transient" set to TRUE by
314 the place_client call
316 ob_state() == OB_STATE_RUNNING
&&
318 (!((self
->positioned
& USPosition
) ||
319 (settings
&& settings
->pos_given
)) &&
320 client_normal(self
) &&
322 /* don't move oldschool fullscreen windows to
323 fit inside the struts (fixes Acroread, which
324 makes its fullscreen window fit the screen
325 but it is not USSize'd or USPosition'd) */
326 !(self
->decorations
== 0 &&
327 RECT_EQUAL(place
, *monitor
)))));
330 /* if the window isn't user-sized, then make it fit inside
331 the visible screen area on its monitor. Use basically the same rules
332 for forcing the window on screen in the client_find_onscreen call.
334 do this after place_client, it chooses the monitor!
336 splash screens get "transient" set to TRUE by
337 the place_client call
339 if (ob_state() == OB_STATE_RUNNING
&&
341 (!(self
->sized
& USSize
|| self
->positioned
& USPosition
) &&
342 client_normal(self
) &&
344 /* don't shrink oldschool fullscreen windows to fit inside the
345 struts (fixes Acroread, which makes its fullscreen window
346 fit the screen but it is not USSize'd or USPosition'd) */
347 !(self
->decorations
== 0 && RECT_EQUAL(place
, *monitor
)))))
349 Rect
*a
= screen_area(self
->desktop
, SCREEN_AREA_ONE_MONITOR
, &place
);
351 /* get the size of the frame */
352 place
.width
+= self
->frame
->size
.left
+ self
->frame
->size
.right
;
353 place
.height
+= self
->frame
->size
.top
+ self
->frame
->size
.bottom
;
355 /* fit the window inside the area */
356 place
.width
= MIN(place
.width
, a
->width
);
357 place
.height
= MIN(place
.height
, a
->height
);
359 ob_debug("setting window size to %dx%d", place
.width
, place
.height
);
361 /* get the size of the client back */
362 place
.width
-= self
->frame
->size
.left
+ self
->frame
->size
.right
;
363 place
.height
-= self
->frame
->size
.top
+ self
->frame
->size
.bottom
;
368 ob_debug("placing window 0x%x at %d, %d with size %d x %d. "
369 "some restrictions may apply",
370 self
->window
, place
.x
, place
.y
, place
.width
, place
.height
);
372 ob_debug(" but session requested %d, %d %d x %d instead, "
374 self
->session
->x
, self
->session
->y
,
375 self
->session
->w
, self
->session
->h
);
377 /* do this after the window is placed, so the premax/prefullscreen numbers
380 this also places the window
382 client_apply_startup_state(self
, place
.x
, place
.y
,
383 place
.width
, place
.height
);
388 ob_debug_type(OB_DEBUG_FOCUS
, "Going to try activate new window? %s",
389 activate
? "yes" : "no");
391 gboolean raise
= FALSE
;
393 /* This is focus stealing prevention */
394 ob_debug_type(OB_DEBUG_FOCUS
,
395 "Want to focus new window 0x%x at time %u "
396 "launched at %u (last user interaction time %u)",
397 self
->window
, map_time
, launch_time
,
398 event_last_user_time
);
400 if (menu_frame_visible
|| moveresize_in_progress
) {
403 ob_debug_type(OB_DEBUG_FOCUS
,
404 "Not focusing the window because the user is inside "
405 "an Openbox menu or is move/resizing a window and "
406 "we don't want to interrupt them");
409 /* if it's on another desktop */
410 else if (!(self
->desktop
== screen_desktop
||
411 self
->desktop
== DESKTOP_ALL
) &&
412 /* the timestamp is from before you changed desktops */
413 launch_time
&& screen_desktop_user_time
&&
414 !event_time_after(launch_time
, screen_desktop_user_time
))
418 ob_debug_type(OB_DEBUG_FOCUS
,
419 "Not focusing the window because its on another "
422 /* If something is focused, and it's not our relative... */
423 else if (focus_client
&& client_search_focus_tree_full(self
) == NULL
&&
424 client_search_focus_group_full(self
) == NULL
)
426 /* If the user is working in another window right now, then don't
428 if (event_last_user_time
&& launch_time
&&
429 event_time_after(event_last_user_time
, launch_time
) &&
430 event_last_user_time
!= launch_time
&&
431 event_time_after(event_last_user_time
,
432 map_time
- OB_EVENT_USER_TIME_DELAY
))
435 ob_debug_type(OB_DEBUG_FOCUS
,
436 "Not focusing the window because the user is "
437 "working in another window");
439 /* If its a transient (and its parents aren't focused) */
440 else if (client_has_parent(self
)) {
442 ob_debug_type(OB_DEBUG_FOCUS
,
443 "Not focusing the window because it is a "
444 "transient, and its relatives aren't focused");
446 /* Don't steal focus from globally active clients.
447 I stole this idea from KWin. It seems nice.
449 else if (!(focus_client
->can_focus
||
450 focus_client
->focus_notify
))
453 ob_debug_type(OB_DEBUG_FOCUS
,
454 "Not focusing the window because a globally "
455 "active client has focus");
457 /* Don't move focus if it's not going to go to this window
459 else if (client_focus_target(self
) != self
) {
462 ob_debug_type(OB_DEBUG_FOCUS
,
463 "Not focusing the window because another window "
464 "would get the focus anyway");
466 else if (!(self
->desktop
== screen_desktop
||
467 self
->desktop
== DESKTOP_ALL
))
471 ob_debug_type(OB_DEBUG_FOCUS
,
472 "Not focusing the window because it is on "
473 "another desktop and no relatives are focused ");
478 ob_debug_type(OB_DEBUG_FOCUS
,
479 "Focus stealing prevention activated for %s at "
480 "time %u (last user interactioon time %u)",
481 self
->title
, map_time
, event_last_user_time
);
482 /* if the client isn't focused, then hilite it so the user
484 client_hilite(self
, TRUE
);
485 /* we may want to raise it even tho we're not activating it */
486 if (raise
&& !client_restore_session_stacking(self
))
487 stacking_raise(CLIENT_AS_WINDOW(self
));
491 /* This may look rather odd. Well it's because new windows are added
492 to the stacking order non-intrusively. If we're not going to focus
493 the new window or hilite it, then we raise it to the top. This will
494 take affect for things that don't get focused like splash screens.
495 Also if you don't have focus_new enabled, then it's going to get
496 raised to the top. Legacy begets legacy I guess?
498 if (!client_restore_session_stacking(self
))
499 stacking_raise(CLIENT_AS_WINDOW(self
));
502 mouse_grab_for_client(self
, TRUE
);
504 /* this has to happen before we try focus the window, but we want it to
505 happen after the client's stacking has been determined or it looks bad
509 if (!config_focus_under_mouse
)
510 ignore_start
= event_start_ignore_all_enters();
514 if (!config_focus_under_mouse
)
515 event_end_ignore_all_enters(ignore_start
);
519 gboolean stacked
= client_restore_session_stacking(self
);
520 client_present(self
, FALSE
, !stacked
, TRUE
);
523 /* add to client list/map */
524 client_list
= g_list_append(client_list
, self
);
525 window_add(&self
->window
, CLIENT_AS_WINDOW(self
));
527 /* this has to happen after we're in the client_list */
528 if (STRUT_EXISTS(self
->strut
))
529 screen_update_areas();
531 /* update the list hints */
534 /* watch for when the application stops responding. only do this for
535 normal windows, i.e. windows which have titlebars and close buttons
536 and things like that.
537 we don't need to stop pinging on unmanage, because it will be handled
538 automatically by the destroy callback!
540 if (self
->ping
&& client_normal(self
))
541 ping_start(self
, client_ping_event
);
543 /* free the ObAppSettings shallow copy */
546 ob_debug("Managed window 0x%lx plate 0x%x (%s)",
547 window
, self
->frame
->window
, self
->class);
551 ObClient
*client_fake_manage(Window window
)
554 ObAppSettings
*settings
;
556 ob_debug("Pretend-managing window: %lx", window
);
558 /* do this minimal stuff to figure out the client's decorations */
560 self
= g_new0(ObClient
, 1);
561 self
->window
= window
;
563 client_get_all(self
, FALSE
);
564 /* per-app settings override stuff, and return the settings for other
565 uses too. this returns a shallow copy that needs to be freed */
566 settings
= client_get_settings_state(self
);
568 client_setup_decor_and_functions(self
, FALSE
);
570 /* create the decoration frame for the client window and adjust its size */
571 self
->frame
= frame_new(self
);
572 frame_adjust_area(self
->frame
, FALSE
, TRUE
, TRUE
);
574 ob_debug("gave extents left %d right %d top %d bottom %d",
575 self
->frame
->size
.left
, self
->frame
->size
.right
,
576 self
->frame
->size
.top
, self
->frame
->size
.bottom
);
578 /* free the ObAppSettings shallow copy */
584 void client_unmanage_all(void)
586 while (client_list
!= NULL
)
587 client_unmanage(client_list
->data
);
590 void client_unmanage(ObClient
*self
)
596 ob_debug("Unmanaging window: 0x%x plate 0x%x (%s) (%s)",
597 self
->window
, self
->frame
->window
,
598 self
->class, self
->title
? self
->title
: "");
600 g_assert(self
!= NULL
);
602 /* we dont want events no more. do this before hiding the frame so we
603 don't generate more events */
604 XSelectInput(obt_display
, self
->window
, NoEventMask
);
606 /* ignore enter events from the unmap so it doesnt mess with the focus */
607 if (!config_focus_under_mouse
)
608 ignore_start
= event_start_ignore_all_enters();
610 frame_hide(self
->frame
);
611 /* flush to send the hide to the server quickly */
614 if (!config_focus_under_mouse
)
615 event_end_ignore_all_enters(ignore_start
);
617 mouse_grab_for_client(self
, FALSE
);
619 /* remove the window from our save set */
620 XChangeSaveSet(obt_display
, self
->window
, SetModeDelete
);
622 /* update the focus lists */
623 focus_order_remove(self
);
624 if (client_focused(self
)) {
625 /* don't leave an invalid focus_client */
629 client_list
= g_list_remove(client_list
, self
);
630 stacking_remove(self
);
631 window_remove(self
->window
);
633 /* once the client is out of the list, update the struts to remove its
635 if (STRUT_EXISTS(self
->strut
))
636 screen_update_areas();
638 client_call_notifies(self
, client_destroy_notifies
);
640 /* tell our parent(s) that we're gone */
641 for (it
= self
->parents
; it
; it
= g_slist_next(it
))
642 ((ObClient
*)it
->data
)->transients
=
643 g_slist_remove(((ObClient
*)it
->data
)->transients
,self
);
645 /* tell our transients that we're gone */
646 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
647 ((ObClient
*)it
->data
)->parents
=
648 g_slist_remove(((ObClient
*)it
->data
)->parents
, self
);
649 /* we could be keeping our children in a higher layer */
650 client_calc_layer(it
->data
);
653 /* remove from its group */
655 group_remove(self
->group
, self
);
659 /* restore the window's original geometry so it is not lost */
665 if (self
->fullscreen
)
666 a
= self
->pre_fullscreen_area
;
667 else if (self
->max_horz
|| self
->max_vert
) {
668 if (self
->max_horz
) {
669 a
.x
= self
->pre_max_area
.x
;
670 a
.width
= self
->pre_max_area
.width
;
672 if (self
->max_vert
) {
673 a
.y
= self
->pre_max_area
.y
;
674 a
.height
= self
->pre_max_area
.height
;
678 self
->fullscreen
= self
->max_horz
= self
->max_vert
= FALSE
;
679 /* let it be moved and resized no matter what */
680 self
->functions
= OB_CLIENT_FUNC_MOVE
| OB_CLIENT_FUNC_RESIZE
;
681 self
->decorations
= 0; /* unmanaged windows have no decor */
683 /* give the client its border back */
684 XSetWindowBorderWidth(obt_display
, self
->window
, self
->border_width
);
686 client_move_resize(self
, a
.x
, a
.y
, a
.width
, a
.height
);
689 /* reparent the window out of the frame, and free the frame */
690 frame_release_client(self
->frame
);
691 frame_free(self
->frame
);
694 if (ob_state() != OB_STATE_EXITING
) {
695 /* these values should not be persisted across a window
697 OBT_PROP_ERASE(self
->window
, NET_WM_DESKTOP
);
698 OBT_PROP_ERASE(self
->window
, NET_WM_STATE
);
699 OBT_PROP_ERASE(self
->window
, WM_STATE
);
701 /* if we're left in an unmapped state, the client wont be mapped.
702 this is bad, since we will no longer be managing the window on
704 XMapWindow(obt_display
, self
->window
);
707 /* these should not be left on the window ever. other window managers
708 don't necessarily use them and it will mess them up (like compiz) */
709 OBT_PROP_ERASE(self
->window
, NET_WM_VISIBLE_NAME
);
710 OBT_PROP_ERASE(self
->window
, NET_WM_VISIBLE_ICON_NAME
);
712 /* update the list hints */
715 ob_debug("Unmanaged window 0x%lx", self
->window
);
717 /* free all data allocated in the client struct */
718 g_slist_free(self
->transients
);
719 for (j
= 0; j
< self
->nicons
; ++j
)
720 g_free(self
->icons
[j
].data
);
721 if (self
->nicons
> 0)
723 g_free(self
->startup_id
);
724 g_free(self
->wm_command
);
726 g_free(self
->icon_title
);
730 g_free(self
->client_machine
);
731 g_free(self
->sm_client_id
);
735 void client_fake_unmanage(ObClient
*self
)
737 /* this is all that got allocated to get the decorations */
739 frame_free(self
->frame
);
743 /*! Returns a new structure containing the per-app settings for this client.
744 The returned structure needs to be freed with g_free. */
745 static ObAppSettings
*client_get_settings_state(ObClient
*self
)
747 ObAppSettings
*settings
;
750 settings
= config_create_app_settings();
752 for (it
= config_per_app_settings
; it
; it
= g_slist_next(it
)) {
753 ObAppSettings
*app
= it
->data
;
754 gboolean match
= TRUE
;
756 g_assert(app
->name
!= NULL
|| app
->class != NULL
);
758 /* we know that either name or class is not NULL so it will have to
759 match to use the rule */
761 !g_pattern_match(app
->name
, strlen(self
->name
), self
->name
, NULL
))
763 else if (app
->class &&
764 !g_pattern_match(app
->class,
765 strlen(self
->class), self
->class, NULL
))
767 else if (app
->role
&&
768 !g_pattern_match(app
->role
,
769 strlen(self
->role
), self
->role
, NULL
))
773 ob_debug("Window matching: %s", app
->name
);
775 /* copy the settings to our struct, overriding the existing
776 settings if they are not defaults */
777 config_app_settings_copy_non_defaults(app
, settings
);
781 if (settings
->shade
!= -1)
782 self
->shaded
= !!settings
->shade
;
783 if (settings
->decor
!= -1)
784 self
->undecorated
= !settings
->decor
;
785 if (settings
->iconic
!= -1)
786 self
->iconic
= !!settings
->iconic
;
787 if (settings
->skip_pager
!= -1)
788 self
->skip_pager
= !!settings
->skip_pager
;
789 if (settings
->skip_taskbar
!= -1)
790 self
->skip_taskbar
= !!settings
->skip_taskbar
;
792 if (settings
->max_vert
!= -1)
793 self
->max_vert
= !!settings
->max_vert
;
794 if (settings
->max_horz
!= -1)
795 self
->max_horz
= !!settings
->max_horz
;
797 if (settings
->fullscreen
!= -1)
798 self
->fullscreen
= !!settings
->fullscreen
;
800 if (settings
->desktop
) {
801 if (settings
->desktop
== DESKTOP_ALL
)
802 self
->desktop
= settings
->desktop
;
803 else if (settings
->desktop
> 0 &&
804 settings
->desktop
<= screen_num_desktops
)
805 self
->desktop
= settings
->desktop
- 1;
808 if (settings
->layer
== -1) {
812 else if (settings
->layer
== 0) {
816 else if (settings
->layer
== 1) {
823 static void client_restore_session_state(ObClient
*self
)
827 ob_debug_type(OB_DEBUG_SM
,
828 "Restore session for client %s", self
->title
);
830 if (!(it
= session_state_find(self
))) {
831 ob_debug_type(OB_DEBUG_SM
,
832 "Session data not found for client %s", self
->title
);
836 self
->session
= it
->data
;
838 ob_debug_type(OB_DEBUG_SM
, "Session data loaded for client %s",
841 RECT_SET_POINT(self
->area
, self
->session
->x
, self
->session
->y
);
842 self
->positioned
= USPosition
;
843 self
->sized
= USSize
;
844 if (self
->session
->w
> 0)
845 self
->area
.width
= self
->session
->w
;
846 if (self
->session
->h
> 0)
847 self
->area
.height
= self
->session
->h
;
848 XResizeWindow(obt_display
, self
->window
,
849 self
->area
.width
, self
->area
.height
);
851 self
->desktop
= (self
->session
->desktop
== DESKTOP_ALL
?
852 self
->session
->desktop
:
853 MIN(screen_num_desktops
- 1, self
->session
->desktop
));
854 OBT_PROP_SET32(self
->window
, NET_WM_DESKTOP
, CARDINAL
, self
->desktop
);
856 self
->shaded
= self
->session
->shaded
;
857 self
->iconic
= self
->session
->iconic
;
858 self
->skip_pager
= self
->session
->skip_pager
;
859 self
->skip_taskbar
= self
->session
->skip_taskbar
;
860 self
->fullscreen
= self
->session
->fullscreen
;
861 self
->above
= self
->session
->above
;
862 self
->below
= self
->session
->below
;
863 self
->max_horz
= self
->session
->max_horz
;
864 self
->max_vert
= self
->session
->max_vert
;
865 self
->undecorated
= self
->session
->undecorated
;
868 static gboolean
client_restore_session_stacking(ObClient
*self
)
872 if (!self
->session
) return FALSE
;
874 mypos
= g_list_find(session_saved_state
, self
->session
);
875 if (!mypos
) return FALSE
;
877 /* start above me and look for the first client */
878 for (it
= g_list_previous(mypos
); it
; it
= g_list_previous(it
)) {
881 for (cit
= client_list
; cit
; cit
= g_list_next(cit
)) {
882 ObClient
*c
= cit
->data
;
883 /* found a client that was in the session, so go below it */
884 if (c
->session
== it
->data
) {
885 stacking_below(CLIENT_AS_WINDOW(self
),
886 CLIENT_AS_WINDOW(cit
->data
));
894 void client_move_onscreen(ObClient
*self
, gboolean rude
)
896 gint x
= self
->area
.x
;
897 gint y
= self
->area
.y
;
898 if (client_find_onscreen(self
, &x
, &y
,
900 self
->area
.height
, rude
)) {
901 client_move(self
, x
, y
);
905 gboolean
client_find_onscreen(ObClient
*self
, gint
*x
, gint
*y
, gint w
, gint h
,
908 gint ox
= *x
, oy
= *y
;
909 gboolean rudel
= rude
, ruder
= rude
, rudet
= rude
, rudeb
= rude
;
915 RECT_SET(desired
, *x
, *y
, w
, h
);
916 frame_rect_to_frame(self
->frame
, &desired
);
918 /* get where the frame would be */
919 frame_client_gravity(self
->frame
, x
, y
);
921 /* get the requested size of the window with decorations */
922 fw
= self
->frame
->size
.left
+ w
+ self
->frame
->size
.right
;
923 fh
= self
->frame
->size
.top
+ h
+ self
->frame
->size
.bottom
;
925 /* If rudeness wasn't requested, then still be rude in a given direction
926 if the client is not moving, only resizing in that direction */
928 Point oldtl
, oldtr
, oldbl
, oldbr
;
929 Point newtl
, newtr
, newbl
, newbr
;
930 gboolean stationary_l
, stationary_r
, stationary_t
, stationary_b
;
932 POINT_SET(oldtl
, self
->frame
->area
.x
, self
->frame
->area
.y
);
933 POINT_SET(oldbr
, self
->frame
->area
.x
+ self
->frame
->area
.width
- 1,
934 self
->frame
->area
.y
+ self
->frame
->area
.height
- 1);
935 POINT_SET(oldtr
, oldbr
.x
, oldtl
.y
);
936 POINT_SET(oldbl
, oldtl
.x
, oldbr
.y
);
938 POINT_SET(newtl
, *x
, *y
);
939 POINT_SET(newbr
, *x
+ fw
- 1, *y
+ fh
- 1);
940 POINT_SET(newtr
, newbr
.x
, newtl
.y
);
941 POINT_SET(newbl
, newtl
.x
, newbr
.y
);
943 /* is it moving or just resizing from some corner? */
944 stationary_l
= oldtl
.x
== newtl
.x
;
945 stationary_r
= oldtr
.x
== newtr
.x
;
946 stationary_t
= oldtl
.y
== newtl
.y
;
947 stationary_b
= oldbl
.y
== newbl
.y
;
949 /* if left edge is growing and didnt move right edge */
950 if (stationary_r
&& newtl
.x
< oldtl
.x
)
952 /* if right edge is growing and didnt move left edge */
953 if (stationary_l
&& newtr
.x
> oldtr
.x
)
955 /* if top edge is growing and didnt move bottom edge */
956 if (stationary_b
&& newtl
.y
< oldtl
.y
)
958 /* if bottom edge is growing and didnt move top edge */
959 if (stationary_t
&& newbl
.y
> oldbl
.y
)
963 /* we iterate through every monitor that the window is at least partially
964 on, to make sure it is obeying the rules on them all
966 if the window does not appear on any monitors, then use the first one
969 for (i
= 0; i
< screen_num_monitors
; ++i
) {
972 if (!screen_physical_area_monitor_contains(i
, &desired
)) {
973 if (i
< screen_num_monitors
- 1 || found_mon
)
976 /* the window is not inside any monitor! so just use the first
978 a
= screen_area(self
->desktop
, 0, NULL
);
981 a
= screen_area(self
->desktop
, SCREEN_AREA_ONE_MONITOR
, &desired
);
984 /* This makes sure windows aren't entirely outside of the screen so you
985 can't see them at all.
986 It makes sure 10% of the window is on the screen at least. At don't
987 let it move itself off the top of the screen, which would hide the
988 titlebar on you. (The user can still do this if they want too, it's
989 only limiting the application.
991 if (client_normal(self
)) {
992 if (!self
->strut
.right
&& *x
+ fw
/10 >= a
->x
+ a
->width
- 1)
993 *x
= a
->x
+ a
->width
- fw
/10;
994 if (!self
->strut
.bottom
&& *y
+ fh
/10 >= a
->y
+ a
->height
- 1)
995 *y
= a
->y
+ a
->height
- fh
/10;
996 if (!self
->strut
.left
&& *x
+ fw
*9/10 - 1 < a
->x
)
998 if (!self
->strut
.top
&& *y
+ fh
*9/10 - 1 < a
->y
)
1002 /* This here doesn't let windows even a pixel outside the
1003 struts/screen. When called from client_manage, programs placing
1004 themselves are forced completely onscreen, while things like
1005 xterm -geometry resolution-width/2 will work fine. Trying to
1006 place it completely offscreen will be handled in the above code.
1007 Sorry for this confused comment, i am tired. */
1008 if (rudel
&& !self
->strut
.left
&& *x
< a
->x
) *x
= a
->x
;
1009 if (ruder
&& !self
->strut
.right
&& *x
+ fw
> a
->x
+ a
->width
)
1010 *x
= a
->x
+ MAX(0, a
->width
- fw
);
1012 if (rudet
&& !self
->strut
.top
&& *y
< a
->y
) *y
= a
->y
;
1013 if (rudeb
&& !self
->strut
.bottom
&& *y
+ fh
> a
->y
+ a
->height
)
1014 *y
= a
->y
+ MAX(0, a
->height
- fh
);
1019 /* get where the client should be */
1020 frame_frame_gravity(self
->frame
, x
, y
);
1022 return ox
!= *x
|| oy
!= *y
;
1025 static void client_get_all(ObClient
*self
, gboolean real
)
1027 /* this is needed for the frame to set itself up */
1028 client_get_area(self
);
1030 /* these things can change the decor and functions of the window */
1032 client_get_mwm_hints(self
);
1033 /* this can change the mwmhints for special cases */
1034 client_get_type_and_transientness(self
);
1035 client_get_state(self
);
1036 client_update_normal_hints(self
);
1038 /* get the session related properties, these can change decorations
1039 from per-app settings */
1040 client_get_session_ids(self
);
1042 /* now we got everything that can affect the decorations */
1046 /* get this early so we have it for debugging */
1047 client_update_title(self
);
1049 client_update_protocols(self
);
1051 client_update_wmhints(self
);
1052 /* this may have already been called from client_update_wmhints */
1053 if (!self
->parents
&& !self
->transient_for_group
)
1054 client_update_transient_for(self
);
1056 client_get_startup_id(self
);
1057 client_get_desktop(self
);/* uses transient data/group/startup id if a
1058 desktop is not specified */
1059 client_get_shaped(self
);
1062 /* a couple type-based defaults for new windows */
1064 /* this makes sure that these windows appear on all desktops */
1065 if (self
->type
== OB_CLIENT_TYPE_DESKTOP
)
1066 self
->desktop
= DESKTOP_ALL
;
1070 client_update_sync_request_counter(self
);
1073 client_get_colormap(self
);
1074 client_update_strut(self
);
1075 client_update_icons(self
);
1076 client_update_icon_geometry(self
);
1079 static void client_get_startup_id(ObClient
*self
)
1081 if (!(OBT_PROP_GETS(self
->window
, NET_STARTUP_ID
, utf8
,
1082 &self
->startup_id
)))
1084 OBT_PROP_GETS(self
->group
->leader
,
1085 NET_STARTUP_ID
, utf8
, &self
->startup_id
);
1088 static void client_get_area(ObClient
*self
)
1090 XWindowAttributes wattrib
;
1093 ret
= XGetWindowAttributes(obt_display
, self
->window
, &wattrib
);
1094 g_assert(ret
!= BadWindow
);
1096 RECT_SET(self
->area
, wattrib
.x
, wattrib
.y
, wattrib
.width
, wattrib
.height
);
1097 POINT_SET(self
->root_pos
, wattrib
.x
, wattrib
.y
);
1098 self
->border_width
= wattrib
.border_width
;
1100 ob_debug("client area: %d %d %d %d bw %d", wattrib
.x
, wattrib
.y
,
1101 wattrib
.width
, wattrib
.height
, wattrib
.border_width
);
1104 static void client_get_desktop(ObClient
*self
)
1106 guint32 d
= screen_num_desktops
; /* an always-invalid value */
1108 if (OBT_PROP_GET32(self
->window
, NET_WM_DESKTOP
, CARDINAL
, &d
)) {
1109 if (d
>= screen_num_desktops
&& d
!= DESKTOP_ALL
)
1110 self
->desktop
= screen_num_desktops
- 1;
1113 ob_debug("client requested desktop 0x%x", self
->desktop
);
1116 gboolean first
= TRUE
;
1117 guint all
= screen_num_desktops
; /* not a valid value */
1119 /* if they are all on one desktop, then open it on the
1121 for (it
= self
->parents
; it
; it
= g_slist_next(it
)) {
1122 ObClient
*c
= it
->data
;
1124 if (c
->desktop
== DESKTOP_ALL
) continue;
1130 else if (all
!= c
->desktop
)
1131 all
= screen_num_desktops
; /* make it invalid */
1133 if (all
!= screen_num_desktops
) {
1134 self
->desktop
= all
;
1136 ob_debug("client desktop set from parents: 0x%x",
1139 /* try get from the startup-notification protocol */
1140 else if (sn_get_desktop(self
->startup_id
, &self
->desktop
)) {
1141 if (self
->desktop
>= screen_num_desktops
&&
1142 self
->desktop
!= DESKTOP_ALL
)
1143 self
->desktop
= screen_num_desktops
- 1;
1144 ob_debug("client desktop set from startup-notification: 0x%x",
1147 /* defaults to the current desktop */
1149 self
->desktop
= screen_desktop
;
1150 ob_debug("client desktop set to the current desktop: %d",
1156 static void client_get_state(ObClient
*self
)
1161 if (OBT_PROP_GETA32(self
->window
, NET_WM_STATE
, ATOM
, &state
, &num
)) {
1163 for (i
= 0; i
< num
; ++i
) {
1164 if (state
[i
] == OBT_PROP_ATOM(NET_WM_STATE_MODAL
))
1166 else if (state
[i
] == OBT_PROP_ATOM(NET_WM_STATE_SHADED
))
1167 self
->shaded
= TRUE
;
1168 else if (state
[i
] == OBT_PROP_ATOM(NET_WM_STATE_HIDDEN
))
1169 self
->iconic
= TRUE
;
1170 else if (state
[i
] == OBT_PROP_ATOM(NET_WM_STATE_SKIP_TASKBAR
))
1171 self
->skip_taskbar
= TRUE
;
1172 else if (state
[i
] == OBT_PROP_ATOM(NET_WM_STATE_SKIP_PAGER
))
1173 self
->skip_pager
= TRUE
;
1174 else if (state
[i
] == OBT_PROP_ATOM(NET_WM_STATE_FULLSCREEN
))
1175 self
->fullscreen
= TRUE
;
1176 else if (state
[i
] == OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_VERT
))
1177 self
->max_vert
= TRUE
;
1178 else if (state
[i
] == OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_HORZ
))
1179 self
->max_horz
= TRUE
;
1180 else if (state
[i
] == OBT_PROP_ATOM(NET_WM_STATE_ABOVE
))
1182 else if (state
[i
] == OBT_PROP_ATOM(NET_WM_STATE_BELOW
))
1184 else if (state
[i
] == OBT_PROP_ATOM(NET_WM_STATE_DEMANDS_ATTENTION
))
1185 self
->demands_attention
= TRUE
;
1186 else if (state
[i
] == OBT_PROP_ATOM(OB_WM_STATE_UNDECORATED
))
1187 self
->undecorated
= TRUE
;
1194 static void client_get_shaped(ObClient
*self
)
1196 self
->shaped
= FALSE
;
1198 if (obt_display_extension_shape
) {
1203 XShapeSelectInput(obt_display
, self
->window
, ShapeNotifyMask
);
1205 XShapeQueryExtents(obt_display
, self
->window
, &s
, &foo
,
1206 &foo
, &ufoo
, &ufoo
, &foo
, &foo
, &foo
, &ufoo
,
1208 self
->shaped
= (s
!= 0);
1213 void client_update_transient_for(ObClient
*self
)
1216 ObClient
*target
= NULL
;
1217 gboolean trangroup
= FALSE
;
1219 if (XGetTransientForHint(obt_display
, self
->window
, &t
)) {
1220 if (t
!= self
->window
) { /* cant be transient to itself! */
1221 ObWindow
*tw
= window_find(t
);
1222 /* if this happens then we need to check for it*/
1223 g_assert(tw
!= CLIENT_AS_WINDOW(self
));
1224 if (tw
&& WINDOW_IS_CLIENT(tw
)) {
1225 /* watch out for windows with a parent that is something
1226 different, like a dockapp for example */
1227 target
= WINDOW_AS_CLIENT(tw
);
1231 /* Setting the transient_for to Root is actually illegal, however
1232 applications from time have done this to specify transient for
1234 if (!target
&& self
->group
&& t
== obt_root(ob_screen
))
1236 } else if (self
->group
&& self
->transient
)
1239 client_update_transient_tree(self
, self
->group
, self
->group
,
1240 self
->transient_for_group
, trangroup
,
1241 client_direct_parent(self
), target
);
1242 self
->transient_for_group
= trangroup
;
1246 static void client_update_transient_tree(ObClient
*self
,
1247 ObGroup
*oldgroup
, ObGroup
*newgroup
,
1248 gboolean oldgtran
, gboolean newgtran
,
1249 ObClient
* oldparent
,
1250 ObClient
*newparent
)
1255 g_assert(!oldgtran
|| oldgroup
);
1256 g_assert(!newgtran
|| newgroup
);
1257 g_assert((!oldgtran
&& !oldparent
) ||
1258 (oldgtran
&& !oldparent
) ||
1259 (!oldgtran
&& oldparent
));
1260 g_assert((!newgtran
&& !newparent
) ||
1261 (newgtran
&& !newparent
) ||
1262 (!newgtran
&& newparent
));
1265 Group transient windows are not allowed to have other group
1266 transient windows as their children.
1270 /* No change has occured */
1271 if (oldgroup
== newgroup
&&
1272 oldgtran
== newgtran
&&
1273 oldparent
== newparent
) return;
1275 /** Remove the client from the transient tree **/
1277 for (it
= self
->transients
; it
; it
= next
) {
1278 next
= g_slist_next(it
);
1280 self
->transients
= g_slist_delete_link(self
->transients
, it
);
1281 c
->parents
= g_slist_remove(c
->parents
, self
);
1283 for (it
= self
->parents
; it
; it
= next
) {
1284 next
= g_slist_next(it
);
1286 self
->parents
= g_slist_delete_link(self
->parents
, it
);
1287 c
->transients
= g_slist_remove(c
->transients
, self
);
1290 /** Re-add the client to the transient tree **/
1292 /* If we're transient for a group then we need to add ourselves to all our
1295 for (it
= newgroup
->members
; it
; it
= g_slist_next(it
)) {
1298 !client_search_top_direct_parent(c
)->transient_for_group
&&
1301 c
->transients
= g_slist_prepend(c
->transients
, self
);
1302 self
->parents
= g_slist_prepend(self
->parents
, c
);
1307 /* If we are now transient for a single window we need to add ourselves to
1310 WARNING: Cyclical transient ness is possible if two windows are
1311 transient for eachother.
1313 else if (newparent
&&
1314 /* don't make ourself its child if it is already our child */
1315 !client_is_direct_child(self
, newparent
) &&
1316 client_normal(newparent
))
1318 newparent
->transients
= g_slist_prepend(newparent
->transients
, self
);
1319 self
->parents
= g_slist_prepend(self
->parents
, newparent
);
1322 /* Add any group transient windows to our children. But if we're transient
1323 for the group, then other group transients are not our children.
1325 WARNING: Cyclical transient-ness is possible. For e.g. if:
1326 A is transient for the group
1327 B is transient for A
1328 C is transient for B
1329 A can't be transient for C or we have a cycle
1331 if (!newgtran
&& newgroup
&&
1333 !client_search_top_direct_parent(newparent
)->transient_for_group
) &&
1334 client_normal(self
))
1336 for (it
= newgroup
->members
; it
; it
= g_slist_next(it
)) {
1338 if (c
!= self
&& c
->transient_for_group
&&
1339 /* Don't make it our child if it is already our parent */
1340 !client_is_direct_child(c
, self
))
1342 self
->transients
= g_slist_prepend(self
->transients
, c
);
1343 c
->parents
= g_slist_prepend(c
->parents
, self
);
1348 /** If we change our group transient-ness, our children change their
1349 effect group transient-ness, which affects how they relate to other
1352 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
1354 if (!c
->transient_for_group
)
1355 client_update_transient_tree(c
, c
->group
, c
->group
,
1356 c
->transient_for_group
,
1357 c
->transient_for_group
,
1358 client_direct_parent(c
),
1359 client_direct_parent(c
));
1363 static void client_get_mwm_hints(ObClient
*self
)
1368 self
->mwmhints
.flags
= 0; /* default to none */
1370 if (OBT_PROP_GETA32(self
->window
, MOTIF_WM_HINTS
, MOTIF_WM_HINTS
,
1372 if (num
>= OB_MWM_ELEMENTS
) {
1373 self
->mwmhints
.flags
= hints
[0];
1374 self
->mwmhints
.functions
= hints
[1];
1375 self
->mwmhints
.decorations
= hints
[2];
1381 void client_get_type_and_transientness(ObClient
*self
)
1388 self
->transient
= FALSE
;
1390 if (OBT_PROP_GETA32(self
->window
, NET_WM_WINDOW_TYPE
, ATOM
, &val
, &num
)) {
1391 /* use the first value that we know about in the array */
1392 for (i
= 0; i
< num
; ++i
) {
1393 if (val
[i
] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_DESKTOP
))
1394 self
->type
= OB_CLIENT_TYPE_DESKTOP
;
1395 else if (val
[i
] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_DOCK
))
1396 self
->type
= OB_CLIENT_TYPE_DOCK
;
1397 else if (val
[i
] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_TOOLBAR
))
1398 self
->type
= OB_CLIENT_TYPE_TOOLBAR
;
1399 else if (val
[i
] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_MENU
))
1400 self
->type
= OB_CLIENT_TYPE_MENU
;
1401 else if (val
[i
] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_UTILITY
))
1402 self
->type
= OB_CLIENT_TYPE_UTILITY
;
1403 else if (val
[i
] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_SPLASH
))
1404 self
->type
= OB_CLIENT_TYPE_SPLASH
;
1405 else if (val
[i
] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_DIALOG
))
1406 self
->type
= OB_CLIENT_TYPE_DIALOG
;
1407 else if (val
[i
] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_NORMAL
))
1408 self
->type
= OB_CLIENT_TYPE_NORMAL
;
1409 else if (val
[i
] == OBT_PROP_ATOM(KDE_NET_WM_WINDOW_TYPE_OVERRIDE
))
1411 /* prevent this window from getting any decor or
1413 self
->mwmhints
.flags
&= (OB_MWM_FLAG_FUNCTIONS
|
1414 OB_MWM_FLAG_DECORATIONS
);
1415 self
->mwmhints
.decorations
= 0;
1416 self
->mwmhints
.functions
= 0;
1418 if (self
->type
!= (ObClientType
) -1)
1419 break; /* grab the first legit type */
1424 if (XGetTransientForHint(obt_display
, self
->window
, &t
))
1425 self
->transient
= TRUE
;
1427 if (self
->type
== (ObClientType
) -1) {
1428 /*the window type hint was not set, which means we either classify
1429 ourself as a normal window or a dialog, depending on if we are a
1431 if (self
->transient
)
1432 self
->type
= OB_CLIENT_TYPE_DIALOG
;
1434 self
->type
= OB_CLIENT_TYPE_NORMAL
;
1437 /* then, based on our type, we can update our transientness.. */
1438 if (self
->type
== OB_CLIENT_TYPE_DIALOG
||
1439 self
->type
== OB_CLIENT_TYPE_TOOLBAR
||
1440 self
->type
== OB_CLIENT_TYPE_MENU
||
1441 self
->type
== OB_CLIENT_TYPE_UTILITY
)
1443 self
->transient
= TRUE
;
1447 void client_update_protocols(ObClient
*self
)
1452 self
->focus_notify
= FALSE
;
1453 self
->delete_window
= FALSE
;
1455 if (OBT_PROP_GETA32(self
->window
, WM_PROTOCOLS
, ATOM
, &proto
, &num_ret
)) {
1456 for (i
= 0; i
< num_ret
; ++i
) {
1457 if (proto
[i
] == OBT_PROP_ATOM(WM_DELETE_WINDOW
))
1458 /* this means we can request the window to close */
1459 self
->delete_window
= TRUE
;
1460 else if (proto
[i
] == OBT_PROP_ATOM(WM_TAKE_FOCUS
))
1461 /* if this protocol is requested, then the window will be
1462 notified whenever we want it to receive focus */
1463 self
->focus_notify
= TRUE
;
1464 else if (proto
[i
] == OBT_PROP_ATOM(NET_WM_PING
))
1465 /* if this protocol is requested, then the window will allow
1466 pings to determine if it is still alive */
1469 else if (proto
[i
] == OBT_PROP_ATOM(NET_WM_SYNC_REQUEST
))
1470 /* if this protocol is requested, then resizing the
1471 window will be synchronized between the frame and the
1473 self
->sync_request
= TRUE
;
1481 void client_update_sync_request_counter(ObClient
*self
)
1485 if (OBT_PROP_GET32(self
->window
, NET_WM_SYNC_REQUEST_COUNTER
, CARDINAL
,&i
))
1487 self
->sync_counter
= i
;
1489 self
->sync_counter
= None
;
1493 static void client_get_colormap(ObClient
*self
)
1495 XWindowAttributes wa
;
1497 if (XGetWindowAttributes(obt_display
, self
->window
, &wa
))
1498 client_update_colormap(self
, wa
.colormap
);
1501 void client_update_colormap(ObClient
*self
, Colormap colormap
)
1503 if (colormap
== self
->colormap
) return;
1505 ob_debug("Setting client %s colormap: 0x%x", self
->title
, colormap
);
1507 if (client_focused(self
)) {
1508 screen_install_colormap(self
, FALSE
); /* uninstall old one */
1509 self
->colormap
= colormap
;
1510 screen_install_colormap(self
, FALSE
); /* install new one */
1512 self
->colormap
= colormap
;
1515 void client_update_normal_hints(ObClient
*self
)
1521 self
->min_ratio
= 0.0f
;
1522 self
->max_ratio
= 0.0f
;
1523 SIZE_SET(self
->size_inc
, 1, 1);
1524 SIZE_SET(self
->base_size
, 0, 0);
1525 SIZE_SET(self
->min_size
, 0, 0);
1526 SIZE_SET(self
->max_size
, G_MAXINT
, G_MAXINT
);
1528 /* get the hints from the window */
1529 if (XGetWMNormalHints(obt_display
, self
->window
, &size
, &ret
)) {
1530 /* normal windows can't request placement! har har
1531 if (!client_normal(self))
1533 self
->positioned
= (size
.flags
& (PPosition
|USPosition
));
1534 self
->sized
= (size
.flags
& (PSize
|USSize
));
1536 if (size
.flags
& PWinGravity
)
1537 self
->gravity
= size
.win_gravity
;
1539 if (size
.flags
& PAspect
) {
1540 if (size
.min_aspect
.y
)
1542 (gfloat
) size
.min_aspect
.x
/ size
.min_aspect
.y
;
1543 if (size
.max_aspect
.y
)
1545 (gfloat
) size
.max_aspect
.x
/ size
.max_aspect
.y
;
1548 if (size
.flags
& PMinSize
)
1549 SIZE_SET(self
->min_size
, size
.min_width
, size
.min_height
);
1551 if (size
.flags
& PMaxSize
)
1552 SIZE_SET(self
->max_size
, size
.max_width
, size
.max_height
);
1554 if (size
.flags
& PBaseSize
)
1555 SIZE_SET(self
->base_size
, size
.base_width
, size
.base_height
);
1557 if (size
.flags
& PResizeInc
&& size
.width_inc
&& size
.height_inc
)
1558 SIZE_SET(self
->size_inc
, size
.width_inc
, size
.height_inc
);
1560 ob_debug("Normal hints: min size (%d %d) max size (%d %d)",
1561 self
->min_size
.width
, self
->min_size
.height
,
1562 self
->max_size
.width
, self
->max_size
.height
);
1563 ob_debug("size inc (%d %d) base size (%d %d)",
1564 self
->size_inc
.width
, self
->size_inc
.height
,
1565 self
->base_size
.width
, self
->base_size
.height
);
1568 ob_debug("Normal hints: not set");
1571 void client_setup_decor_and_functions(ObClient
*self
, gboolean reconfig
)
1573 /* start with everything (cept fullscreen) */
1575 (OB_FRAME_DECOR_TITLEBAR
|
1576 OB_FRAME_DECOR_HANDLE
|
1577 OB_FRAME_DECOR_GRIPS
|
1578 OB_FRAME_DECOR_BORDER
|
1579 OB_FRAME_DECOR_ICON
|
1580 OB_FRAME_DECOR_ALLDESKTOPS
|
1581 OB_FRAME_DECOR_ICONIFY
|
1582 OB_FRAME_DECOR_MAXIMIZE
|
1583 OB_FRAME_DECOR_SHADE
|
1584 OB_FRAME_DECOR_CLOSE
);
1586 (OB_CLIENT_FUNC_RESIZE
|
1587 OB_CLIENT_FUNC_MOVE
|
1588 OB_CLIENT_FUNC_ICONIFY
|
1589 OB_CLIENT_FUNC_MAXIMIZE
|
1590 OB_CLIENT_FUNC_SHADE
|
1591 OB_CLIENT_FUNC_CLOSE
|
1592 OB_CLIENT_FUNC_BELOW
|
1593 OB_CLIENT_FUNC_ABOVE
|
1594 OB_CLIENT_FUNC_UNDECORATE
);
1596 if (!(self
->min_size
.width
< self
->max_size
.width
||
1597 self
->min_size
.height
< self
->max_size
.height
))
1598 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
1600 switch (self
->type
) {
1601 case OB_CLIENT_TYPE_NORMAL
:
1602 /* normal windows retain all of the possible decorations and
1603 functionality, and can be fullscreen */
1604 self
->functions
|= OB_CLIENT_FUNC_FULLSCREEN
;
1607 case OB_CLIENT_TYPE_DIALOG
:
1608 /* sometimes apps make dialog windows fullscreen for some reason (for
1609 e.g. kpdf does this..) */
1610 self
->functions
|= OB_CLIENT_FUNC_FULLSCREEN
;
1613 case OB_CLIENT_TYPE_UTILITY
:
1614 /* these windows don't have anything added or removed by default */
1617 case OB_CLIENT_TYPE_MENU
:
1618 case OB_CLIENT_TYPE_TOOLBAR
:
1619 /* these windows can't iconify or maximize */
1620 self
->decorations
&= ~(OB_FRAME_DECOR_ICONIFY
|
1621 OB_FRAME_DECOR_MAXIMIZE
);
1622 self
->functions
&= ~(OB_CLIENT_FUNC_ICONIFY
|
1623 OB_CLIENT_FUNC_MAXIMIZE
);
1626 case OB_CLIENT_TYPE_SPLASH
:
1627 /* these don't get get any decorations, and the only thing you can
1628 do with them is move them */
1629 self
->decorations
= 0;
1630 self
->functions
= OB_CLIENT_FUNC_MOVE
;
1633 case OB_CLIENT_TYPE_DESKTOP
:
1634 /* these windows are not manipulated by the window manager */
1635 self
->decorations
= 0;
1636 self
->functions
= 0;
1639 case OB_CLIENT_TYPE_DOCK
:
1640 /* these windows are not manipulated by the window manager, but they
1641 can set below layer which has a special meaning */
1642 self
->decorations
= 0;
1643 self
->functions
= OB_CLIENT_FUNC_BELOW
;
1647 /* Mwm Hints are applied subtractively to what has already been chosen for
1648 decor and functionality */
1649 if (self
->mwmhints
.flags
& OB_MWM_FLAG_DECORATIONS
) {
1650 if (! (self
->mwmhints
.decorations
& OB_MWM_DECOR_ALL
)) {
1651 if (! ((self
->mwmhints
.decorations
& OB_MWM_DECOR_HANDLE
) ||
1652 (self
->mwmhints
.decorations
& OB_MWM_DECOR_TITLE
)))
1654 /* if the mwm hints request no handle or title, then all
1655 decorations are disabled, but keep the border if that's
1657 if (self
->mwmhints
.decorations
& OB_MWM_DECOR_BORDER
)
1658 self
->decorations
= OB_FRAME_DECOR_BORDER
;
1660 self
->decorations
= 0;
1665 if (self
->mwmhints
.flags
& OB_MWM_FLAG_FUNCTIONS
) {
1666 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_ALL
)) {
1667 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_RESIZE
))
1668 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
1669 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_MOVE
))
1670 self
->functions
&= ~OB_CLIENT_FUNC_MOVE
;
1671 /* dont let mwm hints kill any buttons
1672 if (! (self->mwmhints.functions & OB_MWM_FUNC_ICONIFY))
1673 self->functions &= ~OB_CLIENT_FUNC_ICONIFY;
1674 if (! (self->mwmhints.functions & OB_MWM_FUNC_MAXIMIZE))
1675 self->functions &= ~OB_CLIENT_FUNC_MAXIMIZE;
1677 /* dont let mwm hints kill the close button
1678 if (! (self->mwmhints.functions & MwmFunc_Close))
1679 self->functions &= ~OB_CLIENT_FUNC_CLOSE; */
1683 if (!(self
->functions
& OB_CLIENT_FUNC_SHADE
))
1684 self
->decorations
&= ~OB_FRAME_DECOR_SHADE
;
1685 if (!(self
->functions
& OB_CLIENT_FUNC_ICONIFY
))
1686 self
->decorations
&= ~OB_FRAME_DECOR_ICONIFY
;
1687 if (!(self
->functions
& OB_CLIENT_FUNC_RESIZE
))
1688 self
->decorations
&= ~(OB_FRAME_DECOR_GRIPS
| OB_FRAME_DECOR_HANDLE
);
1690 /* can't maximize without moving/resizing */
1691 if (!((self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) &&
1692 (self
->functions
& OB_CLIENT_FUNC_MOVE
) &&
1693 (self
->functions
& OB_CLIENT_FUNC_RESIZE
))) {
1694 self
->functions
&= ~OB_CLIENT_FUNC_MAXIMIZE
;
1695 self
->decorations
&= ~OB_FRAME_DECOR_MAXIMIZE
;
1698 if (self
->max_horz
&& self
->max_vert
) {
1699 /* you can't resize fully maximized windows */
1700 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
1701 /* kill the handle on fully maxed windows */
1702 self
->decorations
&= ~(OB_FRAME_DECOR_HANDLE
| OB_FRAME_DECOR_GRIPS
);
1705 /* If there are no decorations to remove, don't allow the user to try
1707 if (self
->decorations
== 0)
1708 self
->functions
&= ~OB_CLIENT_FUNC_UNDECORATE
;
1710 /* finally, the user can have requested no decorations, which overrides
1711 everything (but doesnt give it a border if it doesnt have one) */
1712 if (self
->undecorated
)
1713 self
->decorations
= 0;
1715 /* if we don't have a titlebar, then we cannot shade! */
1716 if (!(self
->decorations
& OB_FRAME_DECOR_TITLEBAR
))
1717 self
->functions
&= ~OB_CLIENT_FUNC_SHADE
;
1719 /* now we need to check against rules for the client's current state */
1720 if (self
->fullscreen
) {
1721 self
->functions
&= (OB_CLIENT_FUNC_CLOSE
|
1722 OB_CLIENT_FUNC_FULLSCREEN
|
1723 OB_CLIENT_FUNC_ICONIFY
);
1724 self
->decorations
= 0;
1727 client_change_allowed_actions(self
);
1730 /* force reconfigure to make sure decorations are updated */
1731 client_reconfigure(self
, TRUE
);
1734 static void client_change_allowed_actions(ObClient
*self
)
1739 /* desktop windows are kept on all desktops */
1740 if (self
->type
!= OB_CLIENT_TYPE_DESKTOP
)
1741 actions
[num
++] = OBT_PROP_ATOM(NET_WM_ACTION_CHANGE_DESKTOP
);
1743 if (self
->functions
& OB_CLIENT_FUNC_SHADE
)
1744 actions
[num
++] = OBT_PROP_ATOM(NET_WM_ACTION_SHADE
);
1745 if (self
->functions
& OB_CLIENT_FUNC_CLOSE
)
1746 actions
[num
++] = OBT_PROP_ATOM(NET_WM_ACTION_CLOSE
);
1747 if (self
->functions
& OB_CLIENT_FUNC_MOVE
)
1748 actions
[num
++] = OBT_PROP_ATOM(NET_WM_ACTION_MOVE
);
1749 if (self
->functions
& OB_CLIENT_FUNC_ICONIFY
)
1750 actions
[num
++] = OBT_PROP_ATOM(NET_WM_ACTION_MINIMIZE
);
1751 if (self
->functions
& OB_CLIENT_FUNC_RESIZE
)
1752 actions
[num
++] = OBT_PROP_ATOM(NET_WM_ACTION_RESIZE
);
1753 if (self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
)
1754 actions
[num
++] = OBT_PROP_ATOM(NET_WM_ACTION_FULLSCREEN
);
1755 if (self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) {
1756 actions
[num
++] = OBT_PROP_ATOM(NET_WM_ACTION_MAXIMIZE_HORZ
);
1757 actions
[num
++] = OBT_PROP_ATOM(NET_WM_ACTION_MAXIMIZE_VERT
);
1759 if (self
->functions
& OB_CLIENT_FUNC_ABOVE
)
1760 actions
[num
++] = OBT_PROP_ATOM(NET_WM_ACTION_ABOVE
);
1761 if (self
->functions
& OB_CLIENT_FUNC_BELOW
)
1762 actions
[num
++] = OBT_PROP_ATOM(NET_WM_ACTION_BELOW
);
1763 if (self
->functions
& OB_CLIENT_FUNC_UNDECORATE
)
1764 actions
[num
++] = OBT_PROP_ATOM(OB_WM_ACTION_UNDECORATE
);
1766 OBT_PROP_SETA32(self
->window
, NET_WM_ALLOWED_ACTIONS
, ATOM
, actions
, num
);
1768 /* make sure the window isn't breaking any rules now
1770 don't check ICONIFY here. just cuz a window can't iconify doesnt mean
1771 it can't be iconified with its parent
1774 if (!(self
->functions
& OB_CLIENT_FUNC_SHADE
) && self
->shaded
) {
1775 if (self
->frame
) client_shade(self
, FALSE
);
1776 else self
->shaded
= FALSE
;
1778 if (!(self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
) && self
->fullscreen
) {
1779 if (self
->frame
) client_fullscreen(self
, FALSE
);
1780 else self
->fullscreen
= FALSE
;
1782 if (!(self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) && (self
->max_horz
||
1784 if (self
->frame
) client_maximize(self
, FALSE
, 0);
1785 else self
->max_vert
= self
->max_horz
= FALSE
;
1789 void client_update_wmhints(ObClient
*self
)
1793 /* assume a window takes input if it doesnt specify */
1794 self
->can_focus
= TRUE
;
1796 if ((hints
= XGetWMHints(obt_display
, self
->window
)) != NULL
) {
1799 if (hints
->flags
& InputHint
)
1800 self
->can_focus
= hints
->input
;
1802 /* only do this when first managing the window *AND* when we aren't
1804 if (ob_state() != OB_STATE_STARTING
&& self
->frame
== NULL
)
1805 if (hints
->flags
& StateHint
)
1806 self
->iconic
= hints
->initial_state
== IconicState
;
1809 self
->urgent
= (hints
->flags
& XUrgencyHint
);
1810 if (self
->urgent
&& !ur
)
1811 client_hilite(self
, TRUE
);
1812 else if (!self
->urgent
&& ur
&& self
->demands_attention
)
1813 client_hilite(self
, FALSE
);
1815 if (!(hints
->flags
& WindowGroupHint
))
1816 hints
->window_group
= None
;
1818 /* did the group state change? */
1819 if (hints
->window_group
!=
1820 (self
->group
? self
->group
->leader
: None
))
1822 ObGroup
*oldgroup
= self
->group
;
1824 /* remove from the old group if there was one */
1825 if (self
->group
!= NULL
) {
1826 group_remove(self
->group
, self
);
1830 /* add ourself to the group if we have one */
1831 if (hints
->window_group
!= None
) {
1832 self
->group
= group_add(hints
->window_group
, self
);
1835 /* Put ourselves into the new group's transient tree, and remove
1836 ourselves from the old group's */
1837 client_update_transient_tree(self
, oldgroup
, self
->group
,
1838 self
->transient_for_group
,
1839 self
->transient_for_group
,
1840 client_direct_parent(self
),
1841 client_direct_parent(self
));
1843 /* Lastly, being in a group, or not, can change if the window is
1844 transient for anything.
1846 The logic for this is:
1847 self->transient = TRUE always if the window wants to be
1848 transient for something, even if transient_for was NULL because
1849 it wasn't in a group before.
1851 If parents was NULL and oldgroup was NULL we can assume
1852 that when we add the new group, it will become transient for
1855 If transient_for_group is TRUE, then it must have already
1856 had a group. If it is getting a new group, the above call to
1857 client_update_transient_tree has already taken care of
1858 everything ! If it is losing all group status then it will
1859 no longer be transient for anything and that needs to be
1862 if (self
->transient
&&
1863 ((self
->parents
== NULL
&& oldgroup
== NULL
) ||
1864 (self
->transient_for_group
&& !self
->group
)))
1865 client_update_transient_for(self
);
1868 /* the WM_HINTS can contain an icon */
1869 if (hints
->flags
& IconPixmapHint
)
1870 client_update_icons(self
);
1876 void client_update_title(ObClient
*self
)
1879 gchar
*visible
= NULL
;
1881 g_free(self
->title
);
1884 if (!OBT_PROP_GETS(self
->window
, NET_WM_NAME
, utf8
, &data
)) {
1885 /* try old x stuff */
1886 if (!(OBT_PROP_GETS(self
->window
, WM_NAME
, locale
, &data
)
1887 || OBT_PROP_GETS(self
->window
, WM_NAME
, utf8
, &data
))) {
1888 if (self
->transient
) {
1890 GNOME alert windows are not given titles:
1891 http://developer.gnome.org/projects/gup/hig/draft_hig_new/windows-alert.html
1893 data
= g_strdup("");
1895 data
= g_strdup("Unnamed Window");
1899 if (self
->client_machine
) {
1900 visible
= g_strdup_printf("%s (%s)", data
, self
->client_machine
);
1905 if (self
->not_responding
) {
1907 if (self
->close_tried_term
)
1908 visible
= g_strdup_printf("%s - [%s]", data
, _("Killing..."));
1910 visible
= g_strdup_printf("%s - [%s]", data
, _("Not Responding"));
1914 OBT_PROP_SETS(self
->window
, NET_WM_VISIBLE_NAME
, utf8
, visible
);
1915 self
->title
= visible
;
1918 frame_adjust_title(self
->frame
);
1920 /* update the icon title */
1922 g_free(self
->icon_title
);
1925 if (!OBT_PROP_GETS(self
->window
, NET_WM_ICON_NAME
, utf8
, &data
))
1926 /* try old x stuff */
1927 if (!(OBT_PROP_GETS(self
->window
, WM_ICON_NAME
, locale
, &data
) ||
1928 OBT_PROP_GETS(self
->window
, WM_ICON_NAME
, utf8
, &data
)))
1929 data
= g_strdup(self
->title
);
1931 if (self
->client_machine
) {
1932 visible
= g_strdup_printf("%s (%s)", data
, self
->client_machine
);
1937 if (self
->not_responding
) {
1939 if (self
->close_tried_term
)
1940 visible
= g_strdup_printf("%s - [%s]", data
, _("Killing..."));
1942 visible
= g_strdup_printf("%s - [%s]", data
, _("Not Responding"));
1946 OBT_PROP_SETS(self
->window
, NET_WM_VISIBLE_ICON_NAME
, utf8
, visible
);
1947 self
->icon_title
= visible
;
1950 void client_update_strut(ObClient
*self
)
1954 gboolean got
= FALSE
;
1957 if (OBT_PROP_GETA32(self
->window
, NET_WM_STRUT_PARTIAL
, CARDINAL
,
1962 STRUT_PARTIAL_SET(strut
,
1963 data
[0], data
[2], data
[1], data
[3],
1964 data
[4], data
[5], data
[8], data
[9],
1965 data
[6], data
[7], data
[10], data
[11]);
1971 OBT_PROP_GETA32(self
->window
, NET_WM_STRUT
, CARDINAL
, &data
, &num
)) {
1977 /* use the screen's width/height */
1978 a
= screen_physical_area_all_monitors();
1980 STRUT_PARTIAL_SET(strut
,
1981 data
[0], data
[2], data
[1], data
[3],
1982 a
->y
, a
->y
+ a
->height
- 1,
1983 a
->x
, a
->x
+ a
->width
- 1,
1984 a
->y
, a
->y
+ a
->height
- 1,
1985 a
->x
, a
->x
+ a
->width
- 1);
1992 STRUT_PARTIAL_SET(strut
, 0, 0, 0, 0,
1993 0, 0, 0, 0, 0, 0, 0, 0);
1995 if (!STRUT_EQUAL(strut
, self
->strut
)) {
1996 self
->strut
= strut
;
1998 /* updating here is pointless while we're being mapped cuz we're not in
1999 the client list yet */
2001 screen_update_areas();
2005 /* Avoid storing icons above this size if possible */
2006 #define AVOID_ABOVE 64
2008 void client_update_icons(ObClient
*self
)
2013 guint num_seen
; /* number of icons present */
2014 guint num_small_seen
; /* number of icons small enough present */
2015 guint smallest
, smallest_area
;
2017 for (i
= 0; i
< self
->nicons
; ++i
)
2018 g_free(self
->icons
[i
].data
);
2019 if (self
->nicons
> 0)
2020 g_free(self
->icons
);
2023 if (OBT_PROP_GETA32(self
->window
, NET_WM_ICON
, CARDINAL
, &data
, &num
)) {
2024 /* figure out how many valid icons are in here */
2026 num_seen
= num_small_seen
= 0;
2027 smallest
= smallest_area
= 0;
2033 /* watch for it being too small for the specified size, or for
2034 zero sized icons. */
2035 if (i
> num
|| w
== 0 || h
== 0) break;
2037 if (!smallest_area
|| w
*h
< smallest_area
) {
2038 smallest
= num_seen
;
2039 smallest_area
= w
*h
;
2042 if (w
<= AVOID_ABOVE
&& h
<= AVOID_ABOVE
)
2045 if (num_small_seen
> 0)
2046 self
->nicons
= num_small_seen
;
2050 self
->icons
= g_new(ObClientIcon
, self
->nicons
);
2052 /* store the icons */
2054 for (j
= 0; j
< self
->nicons
;) {
2057 w
= self
->icons
[j
].width
= data
[i
++];
2058 h
= self
->icons
[j
].height
= data
[i
++];
2060 /* if there are some icons smaller than the threshold, we're
2061 skipping all the ones above */
2062 if (num_small_seen
> 0) {
2063 if (w
> AVOID_ABOVE
|| h
> AVOID_ABOVE
) {
2068 /* if there were no icons smaller than the threshold, then we are
2069 only taking the smallest available one we saw */
2070 else if (j
!= smallest
) {
2075 self
->icons
[j
].data
= g_new(RrPixel32
, w
* h
);
2076 for (x
= 0, y
= 0, t
= 0; t
< w
* h
; ++t
, ++x
, ++i
) {
2081 self
->icons
[j
].data
[t
] =
2082 (((data
[i
] >> 24) & 0xff) << RrDefaultAlphaOffset
) +
2083 (((data
[i
] >> 16) & 0xff) << RrDefaultRedOffset
) +
2084 (((data
[i
] >> 8) & 0xff) << RrDefaultGreenOffset
) +
2085 (((data
[i
] >> 0) & 0xff) << RrDefaultBlueOffset
);
2096 if ((hints
= XGetWMHints(obt_display
, self
->window
))) {
2097 if (hints
->flags
& IconPixmapHint
) {
2099 self
->icons
= g_new(ObClientIcon
, self
->nicons
);
2100 obt_display_ignore_errors(TRUE
);
2101 if (!RrPixmapToRGBA(ob_rr_inst
,
2103 (hints
->flags
& IconMaskHint
?
2104 hints
->icon_mask
: None
),
2105 &self
->icons
[0].width
,
2106 &self
->icons
[0].height
,
2107 &self
->icons
[0].data
))
2109 g_free(self
->icons
);
2112 obt_display_ignore_errors(FALSE
);
2118 /* set the default icon onto the window
2119 in theory, this could be a race, but if a window doesn't set an icon
2120 or removes it entirely, it's not very likely it is going to set one
2121 right away afterwards
2123 if it has parents, then one of them will have an icon already
2125 if (self
->nicons
== 0 && !self
->parents
) {
2126 RrPixel32
*icon
= ob_rr_theme
->def_win_icon
;
2129 data
= g_new(gulong
, 48*48+2);
2130 data
[0] = data
[1] = 48;
2131 for (i
= 0; i
< 48*48; ++i
)
2132 data
[i
+2] = (((icon
[i
] >> RrDefaultAlphaOffset
) & 0xff) << 24) +
2133 (((icon
[i
] >> RrDefaultRedOffset
) & 0xff) << 16) +
2134 (((icon
[i
] >> RrDefaultGreenOffset
) & 0xff) << 8) +
2135 (((icon
[i
] >> RrDefaultBlueOffset
) & 0xff) << 0);
2136 OBT_PROP_SETA32(self
->window
, NET_WM_ICON
, CARDINAL
, data
, 48*48+2);
2138 } else if (self
->frame
)
2139 /* don't draw the icon empty if we're just setting one now anyways,
2140 we'll get the property change any second */
2141 frame_adjust_icon(self
->frame
);
2144 void client_update_icon_geometry(ObClient
*self
)
2149 RECT_SET(self
->icon_geometry
, 0, 0, 0, 0);
2151 if (OBT_PROP_GETA32(self
->window
, NET_WM_ICON_GEOMETRY
, CARDINAL
,
2155 /* don't let them set it with an area < 0 */
2156 RECT_SET(self
->icon_geometry
, data
[0], data
[1],
2157 MAX(data
[2],0), MAX(data
[3],0));
2162 static void client_get_session_ids(ObClient
*self
)
2169 if (!OBT_PROP_GET32(self
->window
, WM_CLIENT_LEADER
, WINDOW
, &leader
))
2172 /* get the SM_CLIENT_ID */
2175 got
= OBT_PROP_GETS(leader
, SM_CLIENT_ID
, locale
, &self
->sm_client_id
);
2177 OBT_PROP_GETS(self
->window
, SM_CLIENT_ID
, locale
, &self
->sm_client_id
);
2179 /* get the WM_CLASS (name and class). make them "" if they are not
2183 got
= OBT_PROP_GETSS(leader
, WM_CLASS
, locale
, &ss
);
2185 got
= OBT_PROP_GETSS(self
->window
, WM_CLASS
, locale
, &ss
);
2189 self
->name
= g_strdup(ss
[0]);
2191 self
->class = g_strdup(ss
[1]);
2196 if (self
->name
== NULL
) self
->name
= g_strdup("");
2197 if (self
->class == NULL
) self
->class = g_strdup("");
2199 /* get the WM_WINDOW_ROLE. make it "" if it is not provided */
2202 got
= OBT_PROP_GETS(leader
, WM_WINDOW_ROLE
, locale
, &s
);
2204 got
= OBT_PROP_GETS(self
->window
, WM_WINDOW_ROLE
, locale
, &s
);
2209 self
->role
= g_strdup("");
2211 /* get the WM_COMMAND */
2215 got
= OBT_PROP_GETSS(leader
, WM_COMMAND
, locale
, &ss
);
2217 got
= OBT_PROP_GETSS(self
->window
, WM_COMMAND
, locale
, &ss
);
2220 /* merge/mash them all together */
2221 gchar
*merge
= NULL
;
2224 for (i
= 0; ss
[i
]; ++i
) {
2227 merge
= g_strconcat(merge
, ss
[i
], NULL
);
2229 merge
= g_strconcat(ss
[i
], NULL
);
2234 self
->wm_command
= merge
;
2237 /* get the WM_CLIENT_MACHINE */
2240 got
= OBT_PROP_GETS(leader
, WM_CLIENT_MACHINE
, locale
, &s
);
2242 got
= OBT_PROP_GETS(self
->window
, WM_CLIENT_MACHINE
, locale
, &s
);
2245 gchar localhost
[128];
2248 gethostname(localhost
, 127);
2249 localhost
[127] = '\0';
2250 if (strcmp(localhost
, s
) != 0)
2251 self
->client_machine
= s
;
2255 /* see if it has the PID set too (the PID requires that the
2256 WM_CLIENT_MACHINE be set) */
2257 if (OBT_PROP_GET32(self
->window
, NET_WM_PID
, CARDINAL
, &pid
))
2262 static void client_change_wm_state(ObClient
*self
)
2267 old
= self
->wmstate
;
2269 if (self
->shaded
|| self
->iconic
||
2270 (self
->desktop
!= DESKTOP_ALL
&& self
->desktop
!= screen_desktop
))
2272 self
->wmstate
= IconicState
;
2274 self
->wmstate
= NormalState
;
2276 if (old
!= self
->wmstate
) {
2277 OBT_PROP_MSG(ob_screen
, self
->window
, KDE_WM_CHANGE_STATE
,
2278 self
->wmstate
, 1, 0, 0, 0);
2280 state
[0] = self
->wmstate
;
2282 OBT_PROP_SETA32(self
->window
, WM_STATE
, WM_STATE
, state
, 2);
2286 static void client_change_state(ObClient
*self
)
2288 gulong netstate
[12];
2293 netstate
[num
++] = OBT_PROP_ATOM(NET_WM_STATE_MODAL
);
2295 netstate
[num
++] = OBT_PROP_ATOM(NET_WM_STATE_SHADED
);
2297 netstate
[num
++] = OBT_PROP_ATOM(NET_WM_STATE_HIDDEN
);
2298 if (self
->skip_taskbar
)
2299 netstate
[num
++] = OBT_PROP_ATOM(NET_WM_STATE_SKIP_TASKBAR
);
2300 if (self
->skip_pager
)
2301 netstate
[num
++] = OBT_PROP_ATOM(NET_WM_STATE_SKIP_PAGER
);
2302 if (self
->fullscreen
)
2303 netstate
[num
++] = OBT_PROP_ATOM(NET_WM_STATE_FULLSCREEN
);
2305 netstate
[num
++] = OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_VERT
);
2307 netstate
[num
++] = OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_HORZ
);
2309 netstate
[num
++] = OBT_PROP_ATOM(NET_WM_STATE_ABOVE
);
2311 netstate
[num
++] = OBT_PROP_ATOM(NET_WM_STATE_BELOW
);
2312 if (self
->demands_attention
)
2313 netstate
[num
++] = OBT_PROP_ATOM(NET_WM_STATE_DEMANDS_ATTENTION
);
2314 if (self
->undecorated
)
2315 netstate
[num
++] = OBT_PROP_ATOM(OB_WM_STATE_UNDECORATED
);
2316 OBT_PROP_SETA32(self
->window
, NET_WM_STATE
, ATOM
, netstate
, num
);
2319 frame_adjust_state(self
->frame
);
2322 ObClient
*client_search_focus_tree(ObClient
*self
)
2327 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
2328 if (client_focused(it
->data
)) return it
->data
;
2329 if ((ret
= client_search_focus_tree(it
->data
))) return ret
;
2334 ObClient
*client_search_focus_tree_full(ObClient
*self
)
2336 if (self
->parents
) {
2339 for (it
= self
->parents
; it
; it
= g_slist_next(it
)) {
2340 ObClient
*c
= it
->data
;
2341 if ((c
= client_search_focus_tree_full(it
->data
))) return c
;
2347 /* this function checks the whole tree, the client_search_focus_tree
2348 does not, so we need to check this window */
2349 if (client_focused(self
))
2351 return client_search_focus_tree(self
);
2355 ObClient
*client_search_focus_group_full(ObClient
*self
)
2360 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
2361 ObClient
*c
= it
->data
;
2363 if (client_focused(c
)) return c
;
2364 if ((c
= client_search_focus_tree(it
->data
))) return c
;
2367 if (client_focused(self
)) return self
;
2371 gboolean
client_has_parent(ObClient
*self
)
2373 return self
->parents
!= NULL
;
2376 static ObStackingLayer
calc_layer(ObClient
*self
)
2381 monitor
= screen_physical_area_monitor(client_monitor(self
));
2383 if (self
->type
== OB_CLIENT_TYPE_DESKTOP
)
2384 l
= OB_STACKING_LAYER_DESKTOP
;
2385 else if (self
->type
== OB_CLIENT_TYPE_DOCK
) {
2386 if (self
->below
) l
= OB_STACKING_LAYER_NORMAL
;
2387 else l
= OB_STACKING_LAYER_ABOVE
;
2389 else if ((self
->fullscreen
||
2390 /* No decorations and fills the monitor = oldskool fullscreen.
2391 But not for maximized windows.
2393 (self
->decorations
== 0 &&
2394 !(self
->max_horz
&& self
->max_vert
) &&
2395 RECT_EQUAL(self
->area
, *monitor
))) &&
2396 (client_focused(self
) || client_search_focus_tree(self
)))
2397 l
= OB_STACKING_LAYER_FULLSCREEN
;
2398 else if (self
->above
) l
= OB_STACKING_LAYER_ABOVE
;
2399 else if (self
->below
) l
= OB_STACKING_LAYER_BELOW
;
2400 else l
= OB_STACKING_LAYER_NORMAL
;
2407 static void client_calc_layer_recursive(ObClient
*self
, ObClient
*orig
,
2408 ObStackingLayer min
)
2410 ObStackingLayer old
, own
;
2414 own
= calc_layer(self
);
2415 self
->layer
= MAX(own
, min
);
2417 if (self
->layer
!= old
) {
2418 stacking_remove(CLIENT_AS_WINDOW(self
));
2419 stacking_add_nonintrusive(CLIENT_AS_WINDOW(self
));
2422 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
2423 client_calc_layer_recursive(it
->data
, orig
,
2427 void client_calc_layer(ObClient
*self
)
2434 /* transients take on the layer of their parents */
2435 it
= client_search_all_top_parents(self
);
2437 for (; it
; it
= g_slist_next(it
))
2438 client_calc_layer_recursive(it
->data
, orig
, 0);
2441 gboolean
client_should_show(ObClient
*self
)
2445 if (client_normal(self
) && screen_showing_desktop
)
2447 if (self
->desktop
== screen_desktop
|| self
->desktop
== DESKTOP_ALL
)
2453 gboolean
client_show(ObClient
*self
)
2455 gboolean show
= FALSE
;
2457 if (client_should_show(self
)) {
2458 frame_show(self
->frame
);
2461 /* According to the ICCCM (sec 4.1.3.1) when a window is not visible,
2462 it needs to be in IconicState. This includes when it is on another
2465 client_change_wm_state(self
);
2470 gboolean
client_hide(ObClient
*self
)
2472 gboolean hide
= FALSE
;
2474 if (!client_should_show(self
)) {
2475 if (self
== focus_client
) {
2476 /* if there is a grab going on, then we need to cancel it. if we
2477 move focus during the grab, applications will get
2478 NotifyWhileGrabbed events and ignore them !
2480 actions should not rely on being able to move focus during an
2483 event_cancel_all_key_grabs();
2486 /* We don't need to ignore enter events here.
2487 The window can hide/iconify in 3 different ways:
2488 1 - through an x message. in this case we ignore all enter events
2489 caused by responding to the x message (unless underMouse)
2490 2 - by a keyboard action. in this case we ignore all enter events
2491 caused by the action
2492 3 - by a mouse action. in this case they are doing stuff with the
2493 mouse and focus _should_ move.
2495 Also in action_end, we simulate an enter event that can't be ignored
2496 so trying to ignore them is futile in case 3 anyways
2499 frame_hide(self
->frame
);
2502 /* According to the ICCCM (sec 4.1.3.1) when a window is not visible,
2503 it needs to be in IconicState. This includes when it is on another
2506 client_change_wm_state(self
);
2511 void client_showhide(ObClient
*self
)
2513 if (!client_show(self
))
2517 gboolean
client_normal(ObClient
*self
) {
2518 return ! (self
->type
== OB_CLIENT_TYPE_DESKTOP
||
2519 self
->type
== OB_CLIENT_TYPE_DOCK
||
2520 self
->type
== OB_CLIENT_TYPE_SPLASH
);
2523 gboolean
client_helper(ObClient
*self
)
2525 return (self
->type
== OB_CLIENT_TYPE_UTILITY
||
2526 self
->type
== OB_CLIENT_TYPE_MENU
||
2527 self
->type
== OB_CLIENT_TYPE_TOOLBAR
);
2530 gboolean
client_mouse_focusable(ObClient
*self
)
2532 return !(self
->type
== OB_CLIENT_TYPE_MENU
||
2533 self
->type
== OB_CLIENT_TYPE_TOOLBAR
||
2534 self
->type
== OB_CLIENT_TYPE_SPLASH
||
2535 self
->type
== OB_CLIENT_TYPE_DOCK
);
2538 gboolean
client_enter_focusable(ObClient
*self
)
2540 /* you can focus desktops but it shouldn't on enter */
2541 return (client_mouse_focusable(self
) &&
2542 self
->type
!= OB_CLIENT_TYPE_DESKTOP
);
2546 static void client_apply_startup_state(ObClient
*self
,
2547 gint x
, gint y
, gint w
, gint h
)
2549 /* save the states that we are going to apply */
2550 gboolean iconic
= self
->iconic
;
2551 gboolean fullscreen
= self
->fullscreen
;
2552 gboolean undecorated
= self
->undecorated
;
2553 gboolean shaded
= self
->shaded
;
2554 gboolean demands_attention
= self
->demands_attention
;
2555 gboolean max_horz
= self
->max_horz
;
2556 gboolean max_vert
= self
->max_vert
;
2560 /* turn them all off in the client, so they won't affect the window
2562 self
->iconic
= self
->fullscreen
= self
->undecorated
= self
->shaded
=
2563 self
->demands_attention
= self
->max_horz
= self
->max_vert
= FALSE
;
2565 /* move the client to its placed position, or it it's already there,
2566 generate a ConfigureNotify telling the client where it is.
2568 do this after adjusting the frame. otherwise it gets all weird and
2569 clients don't work right
2571 do this before applying the states so they have the correct
2572 pre-max/pre-fullscreen values
2574 client_try_configure(self
, &x
, &y
, &w
, &h
, &l
, &l
, FALSE
);
2575 ob_debug("placed window 0x%x at %d, %d with size %d x %d",
2576 self
->window
, x
, y
, w
, h
);
2577 /* save the area, and make it where it should be for the premax stuff */
2578 oldarea
= self
->area
;
2579 RECT_SET(self
->area
, x
, y
, w
, h
);
2581 /* apply the states. these are in a carefully crafted order.. */
2584 client_iconify(self
, TRUE
, FALSE
, TRUE
);
2586 client_fullscreen(self
, TRUE
);
2588 client_set_undecorated(self
, TRUE
);
2590 client_shade(self
, TRUE
);
2591 if (demands_attention
)
2592 client_hilite(self
, TRUE
);
2594 if (max_vert
&& max_horz
)
2595 client_maximize(self
, TRUE
, 0);
2597 client_maximize(self
, TRUE
, 2);
2599 client_maximize(self
, TRUE
, 1);
2601 /* if the window hasn't been configured yet, then do so now, in fact the
2602 x,y,w,h may _not_ be the same as the area rect, which can end up
2603 meaning that the client isn't properly moved/resized by the fullscreen
2605 pho can cause this because it maps at size of the screen but not 0,0
2606 so openbox moves it on screen to 0,0 (thus x,y=0,0 and area.x,y don't).
2607 then fullscreen'ing makes it go to 0,0 which it thinks it already is at
2608 cuz thats where the pre-fullscreen will be. however the actual area is
2609 not, so this needs to be called even if we have fullscreened/maxed
2611 self
->area
= oldarea
;
2612 client_configure(self
, x
, y
, w
, h
, FALSE
, TRUE
, FALSE
);
2614 /* set the desktop hint, to make sure that it always exists */
2615 OBT_PROP_SET32(self
->window
, NET_WM_DESKTOP
, CARDINAL
, self
->desktop
);
2617 /* nothing to do for the other states:
2626 void client_gravity_resize_w(ObClient
*self
, gint
*x
, gint oldw
, gint neww
)
2628 /* these should be the current values. this is for when you're not moving,
2630 g_assert(*x
== self
->area
.x
);
2631 g_assert(oldw
== self
->area
.width
);
2634 switch (self
->gravity
) {
2636 case NorthWestGravity
:
2638 case SouthWestGravity
:
2645 *x
-= (neww
- oldw
) / 2;
2647 case NorthEastGravity
:
2649 case SouthEastGravity
:
2655 void client_gravity_resize_h(ObClient
*self
, gint
*y
, gint oldh
, gint newh
)
2657 /* these should be the current values. this is for when you're not moving,
2659 g_assert(*y
== self
->area
.y
);
2660 g_assert(oldh
== self
->area
.height
);
2663 switch (self
->gravity
) {
2665 case NorthWestGravity
:
2667 case NorthEastGravity
:
2674 *y
-= (newh
- oldh
) / 2;
2676 case SouthWestGravity
:
2678 case SouthEastGravity
:
2684 void client_try_configure(ObClient
*self
, gint
*x
, gint
*y
, gint
*w
, gint
*h
,
2685 gint
*logicalw
, gint
*logicalh
,
2688 Rect desired
= {*x
, *y
, *w
, *h
};
2689 frame_rect_to_frame(self
->frame
, &desired
);
2691 /* make the frame recalculate its dimentions n shit without changing
2692 anything visible for real, this way the constraints below can work with
2693 the updated frame dimensions. */
2694 frame_adjust_area(self
->frame
, FALSE
, TRUE
, TRUE
);
2696 /* gets the frame's position */
2697 frame_client_gravity(self
->frame
, x
, y
);
2699 /* these positions are frame positions, not client positions */
2701 /* set the size and position if fullscreen */
2702 if (self
->fullscreen
) {
2706 i
= screen_find_monitor(&desired
);
2707 a
= screen_physical_area_monitor(i
);
2714 user
= FALSE
; /* ignore if the client can't be moved/resized when it
2718 } else if (self
->max_horz
|| self
->max_vert
) {
2722 /* use all possible struts when maximizing to the full screen */
2723 i
= screen_find_monitor(&desired
);
2724 a
= screen_area(self
->desktop
, i
,
2725 (self
->max_horz
&& self
->max_vert
? NULL
: &desired
));
2727 /* set the size and position if maximized */
2728 if (self
->max_horz
) {
2730 *w
= a
->width
- self
->frame
->size
.left
- self
->frame
->size
.right
;
2732 if (self
->max_vert
) {
2734 *h
= a
->height
- self
->frame
->size
.top
- self
->frame
->size
.bottom
;
2737 user
= FALSE
; /* ignore if the client can't be moved/resized when it
2743 /* gets the client's position */
2744 frame_frame_gravity(self
->frame
, x
, y
);
2746 /* work within the prefered sizes given by the window */
2747 if (!(*w
== self
->area
.width
&& *h
== self
->area
.height
)) {
2748 gint basew
, baseh
, minw
, minh
;
2750 gfloat minratio
, maxratio
;
2752 incw
= self
->fullscreen
|| self
->max_horz
? 1 : self
->size_inc
.width
;
2753 inch
= self
->fullscreen
|| self
->max_vert
? 1 : self
->size_inc
.height
;
2754 minratio
= self
->fullscreen
|| (self
->max_horz
&& self
->max_vert
) ?
2755 0 : self
->min_ratio
;
2756 maxratio
= self
->fullscreen
|| (self
->max_horz
&& self
->max_vert
) ?
2757 0 : self
->max_ratio
;
2759 /* base size is substituted with min size if not specified */
2760 if (self
->base_size
.width
|| self
->base_size
.height
) {
2761 basew
= self
->base_size
.width
;
2762 baseh
= self
->base_size
.height
;
2764 basew
= self
->min_size
.width
;
2765 baseh
= self
->min_size
.height
;
2767 /* min size is substituted with base size if not specified */
2768 if (self
->min_size
.width
|| self
->min_size
.height
) {
2769 minw
= self
->min_size
.width
;
2770 minh
= self
->min_size
.height
;
2772 minw
= self
->base_size
.width
;
2773 minh
= self
->base_size
.height
;
2776 /* if this is a user-requested resize, then check against min/max
2779 /* smaller than min size or bigger than max size? */
2780 if (*w
> self
->max_size
.width
) *w
= self
->max_size
.width
;
2781 if (*w
< minw
) *w
= minw
;
2782 if (*h
> self
->max_size
.height
) *h
= self
->max_size
.height
;
2783 if (*h
< minh
) *h
= minh
;
2788 /* keep to the increments */
2792 /* you cannot resize to nothing */
2793 if (basew
+ *w
< 1) *w
= 1 - basew
;
2794 if (baseh
+ *h
< 1) *h
= 1 - baseh
;
2796 /* save the logical size */
2797 *logicalw
= incw
> 1 ? *w
: *w
+ basew
;
2798 *logicalh
= inch
> 1 ? *h
: *h
+ baseh
;
2806 /* adjust the height to match the width for the aspect ratios.
2807 for this, min size is not substituted for base size ever. */
2808 *w
-= self
->base_size
.width
;
2809 *h
-= self
->base_size
.height
;
2812 if (*h
* minratio
> *w
) {
2813 *h
= (gint
)(*w
/ minratio
);
2815 /* you cannot resize to nothing */
2818 *w
= (gint
)(*h
* minratio
);
2822 if (*h
* maxratio
< *w
) {
2823 *h
= (gint
)(*w
/ maxratio
);
2825 /* you cannot resize to nothing */
2828 *w
= (gint
)(*h
* minratio
);
2832 *w
+= self
->base_size
.width
;
2833 *h
+= self
->base_size
.height
;
2836 /* these override the above states! if you cant move you can't move! */
2838 if (!(self
->functions
& OB_CLIENT_FUNC_MOVE
)) {
2842 if (!(self
->functions
& OB_CLIENT_FUNC_RESIZE
)) {
2843 *w
= self
->area
.width
;
2844 *h
= self
->area
.height
;
2853 void client_configure(ObClient
*self
, gint x
, gint y
, gint w
, gint h
,
2854 gboolean user
, gboolean final
, gboolean force_reply
)
2857 gboolean send_resize_client
;
2858 gboolean moved
= FALSE
, resized
= FALSE
, rootmoved
= FALSE
;
2859 gboolean fmoved
, fresized
;
2860 guint fdecor
= self
->frame
->decorations
;
2861 gboolean fhorz
= self
->frame
->max_horz
;
2862 gboolean fvert
= self
->frame
->max_vert
;
2863 gint logicalw
, logicalh
;
2865 /* find the new x, y, width, and height (and logical size) */
2866 client_try_configure(self
, &x
, &y
, &w
, &h
, &logicalw
, &logicalh
, user
);
2868 /* set the logical size if things changed */
2869 if (!(w
== self
->area
.width
&& h
== self
->area
.height
))
2870 SIZE_SET(self
->logical_size
, logicalw
, logicalh
);
2872 /* figure out if we moved or resized or what */
2873 moved
= (x
!= self
->area
.x
|| y
!= self
->area
.y
);
2874 resized
= (w
!= self
->area
.width
|| h
!= self
->area
.height
);
2876 oldw
= self
->area
.width
;
2877 oldh
= self
->area
.height
;
2878 RECT_SET(self
->area
, x
, y
, w
, h
);
2880 /* for app-requested resizes, always resize if 'resized' is true.
2881 for user-requested ones, only resize if final is true, or when
2882 resizing in redraw mode */
2883 send_resize_client
= ((!user
&& resized
) ||
2885 (resized
&& config_resize_redraw
))));
2887 /* if the client is enlarging, then resize the client before the frame */
2888 if (send_resize_client
&& (w
> oldw
|| h
> oldh
)) {
2889 XMoveResizeWindow(obt_display
, self
->window
,
2890 self
->frame
->size
.left
, self
->frame
->size
.top
,
2891 MAX(w
, oldw
), MAX(h
, oldh
));
2892 frame_adjust_client_area(self
->frame
);
2895 /* find the frame's dimensions and move/resize it */
2899 /* if decorations changed, then readjust everything for the frame */
2900 if (self
->decorations
!= fdecor
||
2901 self
->max_horz
!= fhorz
|| self
->max_vert
!= fvert
)
2903 fmoved
= fresized
= TRUE
;
2906 /* adjust the frame */
2907 if (fmoved
|| fresized
) {
2908 gulong ignore_start
;
2910 ignore_start
= event_start_ignore_all_enters();
2912 frame_adjust_area(self
->frame
, fmoved
, fresized
, FALSE
);
2915 event_end_ignore_all_enters(ignore_start
);
2918 if (!user
|| final
) {
2919 gint oldrx
= self
->root_pos
.x
;
2920 gint oldry
= self
->root_pos
.y
;
2921 /* we have reset the client to 0 border width, so don't include
2922 it in these coords */
2923 POINT_SET(self
->root_pos
,
2924 self
->frame
->area
.x
+ self
->frame
->size
.left
-
2926 self
->frame
->area
.y
+ self
->frame
->size
.top
-
2927 self
->border_width
);
2928 if (self
->root_pos
.x
!= oldrx
|| self
->root_pos
.y
!= oldry
)
2932 /* This is kinda tricky and should not be changed.. let me explain!
2934 When user = FALSE, then the request is coming from the application
2935 itself, and we are more strict about when to send a synthetic
2936 ConfigureNotify. We strictly follow the rules of the ICCCM sec 4.1.5
2937 in this case (if force_reply is true)
2939 When user = TRUE, then the request is coming from "us", like when we
2940 maximize a window or something. In this case we are more lenient. We
2941 used to follow the same rules as above, but _Java_ Swing can't handle
2942 this. So just to appease Swing, when user = TRUE, we always send
2943 a synthetic ConfigureNotify to give the window its root coordinates.
2945 if ((!user
&& !resized
&& (rootmoved
|| force_reply
)) ||
2946 (user
&& final
&& rootmoved
))
2950 event
.type
= ConfigureNotify
;
2951 event
.xconfigure
.display
= obt_display
;
2952 event
.xconfigure
.event
= self
->window
;
2953 event
.xconfigure
.window
= self
->window
;
2955 ob_debug("Sending ConfigureNotify to %s for %d,%d %dx%d",
2956 self
->title
, self
->root_pos
.x
, self
->root_pos
.y
, w
, h
);
2958 /* root window real coords */
2959 event
.xconfigure
.x
= self
->root_pos
.x
;
2960 event
.xconfigure
.y
= self
->root_pos
.y
;
2961 event
.xconfigure
.width
= w
;
2962 event
.xconfigure
.height
= h
;
2963 event
.xconfigure
.border_width
= self
->border_width
;
2964 event
.xconfigure
.above
= None
;
2965 event
.xconfigure
.override_redirect
= FALSE
;
2966 XSendEvent(event
.xconfigure
.display
, event
.xconfigure
.window
,
2967 FALSE
, StructureNotifyMask
, &event
);
2970 /* if the client is shrinking, then resize the frame before the client.
2972 both of these resize sections may run, because the top one only resizes
2973 in the direction that is growing
2975 if (send_resize_client
&& (w
<= oldw
|| h
<= oldh
)) {
2976 frame_adjust_client_area(self
->frame
);
2977 XMoveResizeWindow(obt_display
, self
->window
,
2978 self
->frame
->size
.left
, self
->frame
->size
.top
, w
, h
);
2981 XFlush(obt_display
);
2984 void client_fullscreen(ObClient
*self
, gboolean fs
)
2988 if (!(self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
) || /* can't */
2989 self
->fullscreen
== fs
) return; /* already done */
2991 self
->fullscreen
= fs
;
2992 client_change_state(self
); /* change the state hints on the client */
2995 self
->pre_fullscreen_area
= self
->area
;
2996 /* if the window is maximized, its area isn't all that meaningful.
2997 save it's premax area instead. */
2998 if (self
->max_horz
) {
2999 self
->pre_fullscreen_area
.x
= self
->pre_max_area
.x
;
3000 self
->pre_fullscreen_area
.width
= self
->pre_max_area
.width
;
3002 if (self
->max_vert
) {
3003 self
->pre_fullscreen_area
.y
= self
->pre_max_area
.y
;
3004 self
->pre_fullscreen_area
.height
= self
->pre_max_area
.height
;
3007 /* these will help configure_full figure out where to fullscreen
3011 w
= self
->area
.width
;
3012 h
= self
->area
.height
;
3014 g_assert(self
->pre_fullscreen_area
.width
> 0 &&
3015 self
->pre_fullscreen_area
.height
> 0);
3017 x
= self
->pre_fullscreen_area
.x
;
3018 y
= self
->pre_fullscreen_area
.y
;
3019 w
= self
->pre_fullscreen_area
.width
;
3020 h
= self
->pre_fullscreen_area
.height
;
3021 RECT_SET(self
->pre_fullscreen_area
, 0, 0, 0, 0);
3024 ob_debug("Window %s going fullscreen (%d)",
3025 self
->title
, self
->fullscreen
);
3027 client_setup_decor_and_functions(self
, FALSE
);
3028 client_move_resize(self
, x
, y
, w
, h
);
3030 /* and adjust our layer/stacking. do this after resizing the window,
3031 and applying decorations, because windows which fill the screen are
3032 considered "fullscreen" and it affects their layer */
3033 client_calc_layer(self
);
3036 /* try focus us when we go into fullscreen mode */
3041 static void client_iconify_recursive(ObClient
*self
,
3042 gboolean iconic
, gboolean curdesk
,
3043 gboolean hide_animation
)
3046 gboolean changed
= FALSE
;
3049 if (self
->iconic
!= iconic
) {
3050 ob_debug("%sconifying window: 0x%lx", (iconic
? "I" : "Uni"),
3054 /* don't let non-normal windows iconify along with their parents
3056 if (client_normal(self
)) {
3057 self
->iconic
= iconic
;
3059 /* update the focus lists.. iconic windows go to the bottom of
3061 focus_order_to_bottom(self
);
3066 self
->iconic
= iconic
;
3068 if (curdesk
&& self
->desktop
!= screen_desktop
&&
3069 self
->desktop
!= DESKTOP_ALL
)
3070 client_set_desktop(self
, screen_desktop
, FALSE
, FALSE
);
3072 /* this puts it after the current focused window */
3073 focus_order_remove(self
);
3074 focus_order_add_new(self
);
3081 client_change_state(self
);
3082 if (config_animate_iconify
&& !hide_animation
)
3083 frame_begin_iconify_animation(self
->frame
, iconic
);
3084 /* do this after starting the animation so it doesn't flash */
3085 client_showhide(self
);
3088 /* iconify all direct transients, and deiconify all transients
3090 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
3091 if (it
->data
!= self
)
3092 if (client_is_direct_child(self
, it
->data
) || !iconic
)
3093 client_iconify_recursive(it
->data
, iconic
, curdesk
,
3097 void client_iconify(ObClient
*self
, gboolean iconic
, gboolean curdesk
,
3098 gboolean hide_animation
)
3100 if (self
->functions
& OB_CLIENT_FUNC_ICONIFY
|| !iconic
) {
3101 /* move up the transient chain as far as possible first */
3102 self
= client_search_top_direct_parent(self
);
3103 client_iconify_recursive(self
, iconic
, curdesk
, hide_animation
);
3107 void client_maximize(ObClient
*self
, gboolean max
, gint dir
)
3111 g_assert(dir
== 0 || dir
== 1 || dir
== 2);
3112 if (!(self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
)) return; /* can't */
3114 /* check if already done */
3116 if (dir
== 0 && self
->max_horz
&& self
->max_vert
) return;
3117 if (dir
== 1 && self
->max_horz
) return;
3118 if (dir
== 2 && self
->max_vert
) return;
3120 if (dir
== 0 && !self
->max_horz
&& !self
->max_vert
) return;
3121 if (dir
== 1 && !self
->max_horz
) return;
3122 if (dir
== 2 && !self
->max_vert
) return;
3125 /* these will help configure_full figure out which screen to fill with
3129 w
= self
->area
.width
;
3130 h
= self
->area
.height
;
3133 if ((dir
== 0 || dir
== 1) && !self
->max_horz
) { /* horz */
3134 RECT_SET(self
->pre_max_area
,
3135 self
->area
.x
, self
->pre_max_area
.y
,
3136 self
->area
.width
, self
->pre_max_area
.height
);
3138 if ((dir
== 0 || dir
== 2) && !self
->max_vert
) { /* vert */
3139 RECT_SET(self
->pre_max_area
,
3140 self
->pre_max_area
.x
, self
->area
.y
,
3141 self
->pre_max_area
.width
, self
->area
.height
);
3144 if ((dir
== 0 || dir
== 1) && self
->max_horz
) { /* horz */
3145 g_assert(self
->pre_max_area
.width
> 0);
3147 x
= self
->pre_max_area
.x
;
3148 w
= self
->pre_max_area
.width
;
3150 RECT_SET(self
->pre_max_area
, 0, self
->pre_max_area
.y
,
3151 0, self
->pre_max_area
.height
);
3153 if ((dir
== 0 || dir
== 2) && self
->max_vert
) { /* vert */
3154 g_assert(self
->pre_max_area
.height
> 0);
3156 y
= self
->pre_max_area
.y
;
3157 h
= self
->pre_max_area
.height
;
3159 RECT_SET(self
->pre_max_area
, self
->pre_max_area
.x
, 0,
3160 self
->pre_max_area
.width
, 0);
3164 if (dir
== 0 || dir
== 1) /* horz */
3165 self
->max_horz
= max
;
3166 if (dir
== 0 || dir
== 2) /* vert */
3167 self
->max_vert
= max
;
3169 client_change_state(self
); /* change the state hints on the client */
3171 client_setup_decor_and_functions(self
, FALSE
);
3172 client_move_resize(self
, x
, y
, w
, h
);
3175 void client_shade(ObClient
*self
, gboolean shade
)
3177 if ((!(self
->functions
& OB_CLIENT_FUNC_SHADE
) &&
3178 shade
) || /* can't shade */
3179 self
->shaded
== shade
) return; /* already done */
3181 self
->shaded
= shade
;
3182 client_change_state(self
);
3183 client_change_wm_state(self
); /* the window is being hidden/shown */
3184 /* resize the frame to just the titlebar */
3185 frame_adjust_area(self
->frame
, FALSE
, TRUE
, FALSE
);
3188 static void client_ping_event(ObClient
*self
, gboolean dead
)
3190 self
->not_responding
= dead
;
3191 client_update_title(self
);
3194 /* try kill it nicely the first time again, if it started responding
3196 self
->close_tried_term
= FALSE
;
3200 void client_close(ObClient
*self
)
3202 if (!(self
->functions
& OB_CLIENT_FUNC_CLOSE
)) return;
3204 /* in the case that the client provides no means to requesting that it
3205 close, we just kill it */
3206 if (!self
->delete_window
)
3207 /* don't use client_kill(), we should only kill based on PID in
3208 response to a lack of PING replies */
3209 XKillClient(obt_display
, self
->window
);
3210 else if (self
->not_responding
)
3213 /* request the client to close with WM_DELETE_WINDOW */
3214 OBT_PROP_MSG_TO(self
->window
, self
->window
, WM_PROTOCOLS
,
3215 OBT_PROP_ATOM(WM_DELETE_WINDOW
), event_curtime
,
3216 0, 0, 0, NoEventMask
);
3219 void client_kill(ObClient
*self
)
3221 if (!self
->client_machine
&& self
->pid
) {
3222 /* running on the local host */
3223 if (!self
->close_tried_term
) {
3224 ob_debug("killing window 0x%x with pid %lu, with SIGTERM",
3225 self
->window
, self
->pid
);
3226 kill(self
->pid
, SIGTERM
);
3227 self
->close_tried_term
= TRUE
;
3229 /* show that we're trying to kill it */
3230 client_update_title(self
);
3233 ob_debug("killing window 0x%x with pid %lu, with SIGKILL",
3234 self
->window
, self
->pid
);
3235 kill(self
->pid
, SIGKILL
); /* kill -9 */
3239 XKillClient(obt_display
, self
->window
);
3242 void client_hilite(ObClient
*self
, gboolean hilite
)
3244 if (self
->demands_attention
== hilite
)
3245 return; /* no change */
3247 /* don't allow focused windows to hilite */
3248 self
->demands_attention
= hilite
&& !client_focused(self
);
3249 if (self
->frame
!= NULL
) { /* if we're mapping, just set the state */
3250 if (self
->demands_attention
)
3251 frame_flash_start(self
->frame
);
3253 frame_flash_stop(self
->frame
);
3254 client_change_state(self
);
3258 static void client_set_desktop_recursive(ObClient
*self
,
3266 if (target
!= self
->desktop
&& self
->type
!= OB_CLIENT_TYPE_DESKTOP
) {
3268 ob_debug("Setting desktop %u", target
+1);
3270 g_assert(target
< screen_num_desktops
|| target
== DESKTOP_ALL
);
3272 old
= self
->desktop
;
3273 self
->desktop
= target
;
3274 OBT_PROP_SET32(self
->window
, NET_WM_DESKTOP
, CARDINAL
, target
);
3275 /* the frame can display the current desktop state */
3276 frame_adjust_state(self
->frame
);
3277 /* 'move' the window to the new desktop */
3281 /* raise if it was not already on the desktop */
3282 if (old
!= DESKTOP_ALL
&& !dontraise
)
3283 stacking_raise(CLIENT_AS_WINDOW(self
));
3284 if (STRUT_EXISTS(self
->strut
))
3285 screen_update_areas();
3287 /* the new desktop's geometry may be different, so we may need to
3288 resize, for example if we are maximized */
3289 client_reconfigure(self
, FALSE
);
3292 /* move all transients */
3293 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
3294 if (it
->data
!= self
)
3295 if (client_is_direct_child(self
, it
->data
))
3296 client_set_desktop_recursive(it
->data
, target
,
3297 donthide
, dontraise
);
3300 void client_set_desktop(ObClient
*self
, guint target
,
3301 gboolean donthide
, gboolean dontraise
)
3303 self
= client_search_top_direct_parent(self
);
3304 client_set_desktop_recursive(self
, target
, donthide
, dontraise
);
3307 gboolean
client_is_direct_child(ObClient
*parent
, ObClient
*child
)
3309 while (child
!= parent
&& (child
= client_direct_parent(child
)));
3310 return child
== parent
;
3313 ObClient
*client_search_modal_child(ObClient
*self
)
3318 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
3319 ObClient
*c
= it
->data
;
3320 if ((ret
= client_search_modal_child(c
))) return ret
;
3321 if (c
->modal
) return c
;
3326 gboolean
client_validate(ObClient
*self
)
3330 XSync(obt_display
, FALSE
); /* get all events on the server */
3332 if (XCheckTypedWindowEvent(obt_display
, self
->window
, DestroyNotify
, &e
) ||
3333 XCheckTypedWindowEvent(obt_display
, self
->window
, UnmapNotify
, &e
))
3335 XPutBackEvent(obt_display
, &e
);
3342 void client_set_wm_state(ObClient
*self
, glong state
)
3344 if (state
== self
->wmstate
) return; /* no change */
3348 client_iconify(self
, TRUE
, TRUE
, FALSE
);
3351 client_iconify(self
, FALSE
, TRUE
, FALSE
);
3356 void client_set_state(ObClient
*self
, Atom action
, glong data1
, glong data2
)
3358 gboolean shaded
= self
->shaded
;
3359 gboolean fullscreen
= self
->fullscreen
;
3360 gboolean undecorated
= self
->undecorated
;
3361 gboolean max_horz
= self
->max_horz
;
3362 gboolean max_vert
= self
->max_vert
;
3363 gboolean modal
= self
->modal
;
3364 gboolean iconic
= self
->iconic
;
3365 gboolean demands_attention
= self
->demands_attention
;
3366 gboolean above
= self
->above
;
3367 gboolean below
= self
->below
;
3370 if (!(action
== OBT_PROP_ATOM(NET_WM_STATE_ADD
) ||
3371 action
== OBT_PROP_ATOM(NET_WM_STATE_REMOVE
) ||
3372 action
== OBT_PROP_ATOM(NET_WM_STATE_TOGGLE
)))
3373 /* an invalid action was passed to the client message, ignore it */
3376 for (i
= 0; i
< 2; ++i
) {
3377 Atom state
= i
== 0 ? data1
: data2
;
3379 if (!state
) continue;
3381 /* if toggling, then pick whether we're adding or removing */
3382 if (action
== OBT_PROP_ATOM(NET_WM_STATE_TOGGLE
)) {
3383 if (state
== OBT_PROP_ATOM(NET_WM_STATE_MODAL
))
3384 action
= modal
? OBT_PROP_ATOM(NET_WM_STATE_REMOVE
) :
3385 OBT_PROP_ATOM(NET_WM_STATE_ADD
);
3386 else if (state
== OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_VERT
))
3387 action
= self
->max_vert
? OBT_PROP_ATOM(NET_WM_STATE_REMOVE
) :
3388 OBT_PROP_ATOM(NET_WM_STATE_ADD
);
3389 else if (state
== OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_HORZ
))
3390 action
= self
->max_horz
? OBT_PROP_ATOM(NET_WM_STATE_REMOVE
) :
3391 OBT_PROP_ATOM(NET_WM_STATE_ADD
);
3392 else if (state
== OBT_PROP_ATOM(NET_WM_STATE_SHADED
))
3393 action
= shaded
? OBT_PROP_ATOM(NET_WM_STATE_REMOVE
) :
3394 OBT_PROP_ATOM(NET_WM_STATE_ADD
);
3395 else if (state
== OBT_PROP_ATOM(NET_WM_STATE_SKIP_TASKBAR
))
3396 action
= self
->skip_taskbar
?
3397 OBT_PROP_ATOM(NET_WM_STATE_REMOVE
) :
3398 OBT_PROP_ATOM(NET_WM_STATE_ADD
);
3399 else if (state
== OBT_PROP_ATOM(NET_WM_STATE_SKIP_PAGER
))
3400 action
= self
->skip_pager
?
3401 OBT_PROP_ATOM(NET_WM_STATE_REMOVE
) :
3402 OBT_PROP_ATOM(NET_WM_STATE_ADD
);
3403 else if (state
== OBT_PROP_ATOM(NET_WM_STATE_HIDDEN
))
3404 action
= self
->iconic
?
3405 OBT_PROP_ATOM(NET_WM_STATE_REMOVE
) :
3406 OBT_PROP_ATOM(NET_WM_STATE_ADD
);
3407 else if (state
== OBT_PROP_ATOM(NET_WM_STATE_FULLSCREEN
))
3408 action
= fullscreen
?
3409 OBT_PROP_ATOM(NET_WM_STATE_REMOVE
) :
3410 OBT_PROP_ATOM(NET_WM_STATE_ADD
);
3411 else if (state
== OBT_PROP_ATOM(NET_WM_STATE_ABOVE
))
3412 action
= self
->above
? OBT_PROP_ATOM(NET_WM_STATE_REMOVE
) :
3413 OBT_PROP_ATOM(NET_WM_STATE_ADD
);
3414 else if (state
== OBT_PROP_ATOM(NET_WM_STATE_BELOW
))
3415 action
= self
->below
? OBT_PROP_ATOM(NET_WM_STATE_REMOVE
) :
3416 OBT_PROP_ATOM(NET_WM_STATE_ADD
);
3417 else if (state
== OBT_PROP_ATOM(NET_WM_STATE_DEMANDS_ATTENTION
))
3418 action
= self
->demands_attention
?
3419 OBT_PROP_ATOM(NET_WM_STATE_REMOVE
) :
3420 OBT_PROP_ATOM(NET_WM_STATE_ADD
);
3421 else if (state
== OBT_PROP_ATOM(OB_WM_STATE_UNDECORATED
))
3422 action
= undecorated
? OBT_PROP_ATOM(NET_WM_STATE_REMOVE
) :
3423 OBT_PROP_ATOM(NET_WM_STATE_ADD
);
3426 if (action
== OBT_PROP_ATOM(NET_WM_STATE_ADD
)) {
3427 if (state
== OBT_PROP_ATOM(NET_WM_STATE_MODAL
)) {
3429 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_VERT
)) {
3431 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_HORZ
)) {
3433 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_SHADED
)) {
3435 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_SKIP_TASKBAR
)) {
3436 self
->skip_taskbar
= TRUE
;
3437 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_SKIP_PAGER
)) {
3438 self
->skip_pager
= TRUE
;
3439 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_HIDDEN
)) {
3441 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_FULLSCREEN
)) {
3443 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_ABOVE
)) {
3446 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_BELOW
)) {
3449 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_DEMANDS_ATTENTION
)){
3450 demands_attention
= TRUE
;
3451 } else if (state
== OBT_PROP_ATOM(OB_WM_STATE_UNDECORATED
)) {
3455 } else { /* action == OBT_PROP_ATOM(NET_WM_STATE_REMOVE) */
3456 if (state
== OBT_PROP_ATOM(NET_WM_STATE_MODAL
)) {
3458 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_VERT
)) {
3460 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_HORZ
)) {
3462 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_SHADED
)) {
3464 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_SKIP_TASKBAR
)) {
3465 self
->skip_taskbar
= FALSE
;
3466 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_SKIP_PAGER
)) {
3467 self
->skip_pager
= FALSE
;
3468 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_HIDDEN
)) {
3470 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_FULLSCREEN
)) {
3472 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_ABOVE
)) {
3474 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_BELOW
)) {
3476 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_DEMANDS_ATTENTION
)){
3477 demands_attention
= FALSE
;
3478 } else if (state
== OBT_PROP_ATOM(OB_WM_STATE_UNDECORATED
)) {
3479 undecorated
= FALSE
;
3484 if (max_horz
!= self
->max_horz
|| max_vert
!= self
->max_vert
) {
3485 if (max_horz
!= self
->max_horz
&& max_vert
!= self
->max_vert
) {
3487 if (max_horz
== max_vert
) { /* both going the same way */
3488 client_maximize(self
, max_horz
, 0);
3490 client_maximize(self
, max_horz
, 1);
3491 client_maximize(self
, max_vert
, 2);
3495 if (max_horz
!= self
->max_horz
)
3496 client_maximize(self
, max_horz
, 1);
3498 client_maximize(self
, max_vert
, 2);
3501 /* change fullscreen state before shading, as it will affect if the window
3503 if (fullscreen
!= self
->fullscreen
)
3504 client_fullscreen(self
, fullscreen
);
3505 if (shaded
!= self
->shaded
)
3506 client_shade(self
, shaded
);
3507 if (undecorated
!= self
->undecorated
)
3508 client_set_undecorated(self
, undecorated
);
3509 if (above
!= self
->above
|| below
!= self
->below
) {
3510 self
->above
= above
;
3511 self
->below
= below
;
3512 client_calc_layer(self
);
3515 if (modal
!= self
->modal
) {
3516 self
->modal
= modal
;
3517 /* when a window changes modality, then its stacking order with its
3518 transients needs to change */
3519 stacking_raise(CLIENT_AS_WINDOW(self
));
3521 /* it also may get focused. if something is focused that shouldn't
3522 be focused anymore, then move the focus */
3523 if (focus_client
&& client_focus_target(focus_client
) != focus_client
)
3524 client_focus(focus_client
);
3527 if (iconic
!= self
->iconic
)
3528 client_iconify(self
, iconic
, FALSE
, FALSE
);
3530 if (demands_attention
!= self
->demands_attention
)
3531 client_hilite(self
, demands_attention
);
3533 client_change_state(self
); /* change the hint to reflect these changes */
3536 ObClient
*client_focus_target(ObClient
*self
)
3538 ObClient
*child
= NULL
;
3540 child
= client_search_modal_child(self
);
3541 if (child
) return child
;
3545 gboolean
client_can_focus(ObClient
*self
)
3547 /* choose the correct target */
3548 self
= client_focus_target(self
);
3550 if (!self
->frame
->visible
)
3553 if (!(self
->can_focus
|| self
->focus_notify
))
3559 gboolean
client_focus(ObClient
*self
)
3561 /* we might not focus this window, so if we have modal children which would
3562 be focused instead, bring them to this desktop */
3563 client_bring_modal_windows(self
);
3565 /* choose the correct target */
3566 self
= client_focus_target(self
);
3568 if (!client_can_focus(self
)) {
3569 ob_debug_type(OB_DEBUG_FOCUS
,
3570 "Client %s can't be focused", self
->title
);
3574 ob_debug_type(OB_DEBUG_FOCUS
,
3575 "Focusing client \"%s\" (0x%x) at time %u",
3576 self
->title
, self
->window
, event_curtime
);
3578 /* if using focus_delay, stop the timer now so that focus doesn't
3580 event_halt_focus_delay();
3582 /* if there is a grab going on, then we need to cancel it. if we move
3583 focus during the grab, applications will get NotifyWhileGrabbed events
3586 actions should not rely on being able to move focus during an
3589 event_cancel_all_key_grabs();
3591 obt_display_ignore_errors(TRUE
);
3593 if (self
->can_focus
) {
3594 /* This can cause a BadMatch error with CurrentTime, or if an app
3595 passed in a bad time for _NET_WM_ACTIVE_WINDOW. */
3596 XSetInputFocus(obt_display
, self
->window
, RevertToPointerRoot
,
3600 if (self
->focus_notify
) {
3602 ce
.xclient
.type
= ClientMessage
;
3603 ce
.xclient
.message_type
= OBT_PROP_ATOM(WM_PROTOCOLS
);
3604 ce
.xclient
.display
= obt_display
;
3605 ce
.xclient
.window
= self
->window
;
3606 ce
.xclient
.format
= 32;
3607 ce
.xclient
.data
.l
[0] = OBT_PROP_ATOM(WM_TAKE_FOCUS
);
3608 ce
.xclient
.data
.l
[1] = event_curtime
;
3609 ce
.xclient
.data
.l
[2] = 0l;
3610 ce
.xclient
.data
.l
[3] = 0l;
3611 ce
.xclient
.data
.l
[4] = 0l;
3612 XSendEvent(obt_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
3615 obt_display_ignore_errors(FALSE
);
3617 ob_debug_type(OB_DEBUG_FOCUS
, "Error focusing? %d",
3618 obt_display_error_occured
);
3619 return !obt_display_error_occured
;
3622 static void client_present(ObClient
*self
, gboolean here
, gboolean raise
,
3625 if (client_normal(self
) && screen_showing_desktop
)
3626 screen_show_desktop(FALSE
, self
);
3628 client_iconify(self
, FALSE
, here
, FALSE
);
3629 if (self
->desktop
!= DESKTOP_ALL
&&
3630 self
->desktop
!= screen_desktop
)
3633 client_set_desktop(self
, screen_desktop
, FALSE
, TRUE
);
3635 screen_set_desktop(self
->desktop
, FALSE
);
3636 } else if (!self
->frame
->visible
)
3637 /* if its not visible for other reasons, then don't mess
3640 if (self
->shaded
&& unshade
)
3641 client_shade(self
, FALSE
);
3643 stacking_raise(CLIENT_AS_WINDOW(self
));
3648 void client_activate(ObClient
*self
, gboolean here
, gboolean raise
,
3649 gboolean unshade
, gboolean user
)
3651 client_present(self
, here
, raise
, unshade
);
3654 static void client_bring_windows_recursive(ObClient
*self
,
3662 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
3663 client_bring_windows_recursive(it
->data
, desktop
,
3664 helpers
, modals
, iconic
);
3666 if (((helpers
&& client_helper(self
)) ||
3667 (modals
&& self
->modal
)) &&
3668 ((self
->desktop
!= desktop
&& self
->desktop
!= DESKTOP_ALL
) ||
3669 (iconic
&& self
->iconic
)))
3671 if (iconic
&& self
->iconic
)
3672 client_iconify(self
, FALSE
, TRUE
, FALSE
);
3674 client_set_desktop(self
, desktop
, FALSE
, FALSE
);
3678 void client_bring_helper_windows(ObClient
*self
)
3680 client_bring_windows_recursive(self
, self
->desktop
, TRUE
, FALSE
, FALSE
);
3683 void client_bring_modal_windows(ObClient
*self
)
3685 client_bring_windows_recursive(self
, self
->desktop
, FALSE
, TRUE
, TRUE
);
3688 gboolean
client_focused(ObClient
*self
)
3690 return self
== focus_client
;
3693 static ObClientIcon
* client_icon_recursive(ObClient
*self
, gint w
, gint h
)
3696 gulong min_diff
, min_i
;
3698 if (!self
->nicons
) {
3699 ObClientIcon
*parent
= NULL
;
3702 for (it
= self
->parents
; it
; it
= g_slist_next(it
)) {
3703 ObClient
*c
= it
->data
;
3704 if ((parent
= client_icon_recursive(c
, w
, h
)))
3711 /* some kind of crappy approximation to find the icon closest in size to
3712 what we requested, but icons are generally all the same ratio as
3713 eachother so it's good enough. */
3715 min_diff
= ABS(self
->icons
[0].width
- w
) + ABS(self
->icons
[0].height
- h
);
3718 for (i
= 1; i
< self
->nicons
; ++i
) {
3721 diff
= ABS(self
->icons
[i
].width
- w
) + ABS(self
->icons
[i
].height
- h
);
3722 if (diff
< min_diff
) {
3727 return &self
->icons
[min_i
];
3730 const ObClientIcon
* client_icon(ObClient
*self
, gint w
, gint h
)
3733 static ObClientIcon deficon
;
3735 if (!(ret
= client_icon_recursive(self
, w
, h
))) {
3736 deficon
.width
= deficon
.height
= 48;
3737 deficon
.data
= ob_rr_theme
->def_win_icon
;
3743 void client_set_layer(ObClient
*self
, gint layer
)
3747 self
->above
= FALSE
;
3748 } else if (layer
== 0) {
3749 self
->below
= self
->above
= FALSE
;
3751 self
->below
= FALSE
;
3754 client_calc_layer(self
);
3755 client_change_state(self
); /* reflect this in the state hints */
3758 void client_set_undecorated(ObClient
*self
, gboolean undecorated
)
3760 if (self
->undecorated
!= undecorated
&&
3761 /* don't let it undecorate if the function is missing, but let
3763 (self
->functions
& OB_CLIENT_FUNC_UNDECORATE
|| !undecorated
))
3765 self
->undecorated
= undecorated
;
3766 client_setup_decor_and_functions(self
, TRUE
);
3767 client_change_state(self
); /* reflect this in the state hints */
3771 guint
client_monitor(ObClient
*self
)
3773 return screen_find_monitor(&self
->frame
->area
);
3776 ObClient
*client_direct_parent(ObClient
*self
)
3778 if (!self
->parents
) return NULL
;
3779 if (self
->transient_for_group
) return NULL
;
3780 return self
->parents
->data
;
3783 ObClient
*client_search_top_direct_parent(ObClient
*self
)
3786 while ((p
= client_direct_parent(self
))) self
= p
;
3790 static GSList
*client_search_all_top_parents_internal(ObClient
*self
,
3792 ObStackingLayer layer
)
3797 /* move up the direct transient chain as far as possible */
3798 while ((p
= client_direct_parent(self
)) &&
3799 (!bylayer
|| p
->layer
== layer
))
3803 ret
= g_slist_prepend(NULL
, self
);
3805 ret
= g_slist_copy(self
->parents
);
3810 GSList
*client_search_all_top_parents(ObClient
*self
)
3812 return client_search_all_top_parents_internal(self
, FALSE
, 0);
3815 GSList
*client_search_all_top_parents_layer(ObClient
*self
)
3817 return client_search_all_top_parents_internal(self
, TRUE
, self
->layer
);
3820 ObClient
*client_search_focus_parent(ObClient
*self
)
3824 for (it
= self
->parents
; it
; it
= g_slist_next(it
))
3825 if (client_focused(it
->data
)) return it
->data
;
3830 ObClient
*client_search_parent(ObClient
*self
, ObClient
*search
)
3834 for (it
= self
->parents
; it
; it
= g_slist_next(it
))
3835 if (it
->data
== search
) return search
;
3840 ObClient
*client_search_transient(ObClient
*self
, ObClient
*search
)
3844 for (sit
= self
->transients
; sit
; sit
= g_slist_next(sit
)) {
3845 if (sit
->data
== search
)
3847 if (client_search_transient(sit
->data
, search
))
3853 static void detect_edge(Rect area
, ObDirection dir
,
3854 gint my_head
, gint my_size
,
3855 gint my_edge_start
, gint my_edge_size
,
3856 gint
*dest
, gboolean
*near_edge
)
3858 gint edge_start
, edge_size
, head
, tail
;
3859 gboolean skip_head
= FALSE
, skip_tail
= FALSE
;
3862 case OB_DIRECTION_NORTH
:
3863 case OB_DIRECTION_SOUTH
:
3864 edge_start
= area
.x
;
3865 edge_size
= area
.width
;
3867 case OB_DIRECTION_EAST
:
3868 case OB_DIRECTION_WEST
:
3869 edge_start
= area
.y
;
3870 edge_size
= area
.height
;
3873 g_assert_not_reached();
3876 /* do we collide with this window? */
3877 if (!RANGES_INTERSECT(my_edge_start
, my_edge_size
,
3878 edge_start
, edge_size
))
3882 case OB_DIRECTION_NORTH
:
3883 head
= RECT_BOTTOM(area
);
3884 tail
= RECT_TOP(area
);
3886 case OB_DIRECTION_SOUTH
:
3887 head
= RECT_TOP(area
);
3888 tail
= RECT_BOTTOM(area
);
3890 case OB_DIRECTION_WEST
:
3891 head
= RECT_RIGHT(area
);
3892 tail
= RECT_LEFT(area
);
3894 case OB_DIRECTION_EAST
:
3895 head
= RECT_LEFT(area
);
3896 tail
= RECT_RIGHT(area
);
3899 g_assert_not_reached();
3902 case OB_DIRECTION_NORTH
:
3903 case OB_DIRECTION_WEST
:
3904 /* check if our window is past the head of this window */
3905 if (my_head
<= head
+ 1)
3907 /* check if our window's tail is past the tail of this window */
3908 if (my_head
+ my_size
- 1 <= tail
)
3910 /* check if the head of this window is closer than the previously
3911 chosen edge (take into account that the previously chosen
3912 edge might have been a tail, not a head) */
3913 if (head
+ (*near_edge
? 0 : my_size
) < *dest
)
3915 /* check if the tail of this window is closer than the previously
3916 chosen edge (take into account that the previously chosen
3917 edge might have been a head, not a tail) */
3918 if (tail
- (!*near_edge
? 0 : my_size
) < *dest
)
3921 case OB_DIRECTION_SOUTH
:
3922 case OB_DIRECTION_EAST
:
3923 /* check if our window is past the head of this window */
3924 if (my_head
>= head
- 1)
3926 /* check if our window's tail is past the tail of this window */
3927 if (my_head
- my_size
+ 1 >= tail
)
3929 /* check if the head of this window is closer than the previously
3930 chosen edge (take into account that the previously chosen
3931 edge might have been a tail, not a head) */
3932 if (head
- (*near_edge
? 0 : my_size
) > *dest
)
3934 /* check if the tail of this window is closer than the previously
3935 chosen edge (take into account that the previously chosen
3936 edge might have been a head, not a tail) */
3937 if (tail
+ (!*near_edge
? 0 : my_size
) > *dest
)
3941 g_assert_not_reached();
3944 ob_debug("my head %d size %d", my_head
, my_size
);
3945 ob_debug("head %d tail %d deest %d", head
, tail
, *dest
);
3947 ob_debug("using near edge %d", head
);
3951 else if (!skip_tail
) {
3952 ob_debug("using far edge %d", tail
);
3958 void client_find_edge_directional(ObClient
*self
, ObDirection dir
,
3959 gint my_head
, gint my_size
,
3960 gint my_edge_start
, gint my_edge_size
,
3961 gint
*dest
, gboolean
*near_edge
)
3968 a
= screen_area(self
->desktop
, SCREEN_AREA_ALL_MONITORS
,
3969 &self
->frame
->area
);
3970 mon
= screen_area(self
->desktop
, SCREEN_AREA_ONE_MONITOR
,
3971 &self
->frame
->area
);
3974 case OB_DIRECTION_NORTH
:
3975 if (my_head
>= RECT_TOP(*mon
) + 1)
3976 edge
= RECT_TOP(*mon
) - 1;
3978 edge
= RECT_TOP(*a
) - 1;
3980 case OB_DIRECTION_SOUTH
:
3981 if (my_head
<= RECT_BOTTOM(*mon
) - 1)
3982 edge
= RECT_BOTTOM(*mon
) + 1;
3984 edge
= RECT_BOTTOM(*a
) + 1;
3986 case OB_DIRECTION_EAST
:
3987 if (my_head
<= RECT_RIGHT(*mon
) - 1)
3988 edge
= RECT_RIGHT(*mon
) + 1;
3990 edge
= RECT_RIGHT(*a
) + 1;
3992 case OB_DIRECTION_WEST
:
3993 if (my_head
>= RECT_LEFT(*mon
) + 1)
3994 edge
= RECT_LEFT(*mon
) - 1;
3996 edge
= RECT_LEFT(*a
) - 1;
3999 g_assert_not_reached();
4001 /* default to the far edge, then narrow it down */
4005 for (it
= client_list
; it
; it
= g_list_next(it
)) {
4006 ObClient
*cur
= it
->data
;
4008 /* skip windows to not bump into */
4013 if (self
->desktop
!= cur
->desktop
&& cur
->desktop
!= DESKTOP_ALL
&&
4014 cur
->desktop
!= screen_desktop
)
4017 ob_debug("trying window %s", cur
->title
);
4019 detect_edge(cur
->frame
->area
, dir
, my_head
, my_size
, my_edge_start
,
4020 my_edge_size
, dest
, near_edge
);
4022 dock_get_area(&dock_area
);
4023 detect_edge(dock_area
, dir
, my_head
, my_size
, my_edge_start
,
4024 my_edge_size
, dest
, near_edge
);
4029 void client_find_move_directional(ObClient
*self
, ObDirection dir
,
4033 gint e
, e_start
, e_size
;
4037 case OB_DIRECTION_EAST
:
4038 head
= RECT_RIGHT(self
->frame
->area
);
4039 size
= self
->frame
->area
.width
;
4040 e_start
= RECT_TOP(self
->frame
->area
);
4041 e_size
= self
->frame
->area
.height
;
4043 case OB_DIRECTION_WEST
:
4044 head
= RECT_LEFT(self
->frame
->area
);
4045 size
= self
->frame
->area
.width
;
4046 e_start
= RECT_TOP(self
->frame
->area
);
4047 e_size
= self
->frame
->area
.height
;
4049 case OB_DIRECTION_NORTH
:
4050 head
= RECT_TOP(self
->frame
->area
);
4051 size
= self
->frame
->area
.height
;
4052 e_start
= RECT_LEFT(self
->frame
->area
);
4053 e_size
= self
->frame
->area
.width
;
4055 case OB_DIRECTION_SOUTH
:
4056 head
= RECT_BOTTOM(self
->frame
->area
);
4057 size
= self
->frame
->area
.height
;
4058 e_start
= RECT_LEFT(self
->frame
->area
);
4059 e_size
= self
->frame
->area
.width
;
4062 g_assert_not_reached();
4065 client_find_edge_directional(self
, dir
, head
, size
,
4066 e_start
, e_size
, &e
, &near
);
4067 *x
= self
->frame
->area
.x
;
4068 *y
= self
->frame
->area
.y
;
4070 case OB_DIRECTION_EAST
:
4071 if (near
) e
-= self
->frame
->area
.width
;
4075 case OB_DIRECTION_WEST
:
4077 else e
-= self
->frame
->area
.width
;
4080 case OB_DIRECTION_NORTH
:
4082 else e
-= self
->frame
->area
.height
;
4085 case OB_DIRECTION_SOUTH
:
4086 if (near
) e
-= self
->frame
->area
.height
;
4091 g_assert_not_reached();
4093 frame_frame_gravity(self
->frame
, x
, y
);
4096 void client_find_resize_directional(ObClient
*self
, ObDirection side
,
4098 gint
*x
, gint
*y
, gint
*w
, gint
*h
)
4101 gint e
, e_start
, e_size
, delta
;
4106 case OB_DIRECTION_EAST
:
4107 head
= RECT_RIGHT(self
->frame
->area
) +
4108 (self
->size_inc
.width
- 1) * (grow
? 1 : -1);
4109 e_start
= RECT_TOP(self
->frame
->area
);
4110 e_size
= self
->frame
->area
.height
;
4111 dir
= grow
? OB_DIRECTION_EAST
: OB_DIRECTION_WEST
;
4113 case OB_DIRECTION_WEST
:
4114 head
= RECT_LEFT(self
->frame
->area
) -
4115 (self
->size_inc
.width
- 1) * (grow
? 1 : -1);
4116 e_start
= RECT_TOP(self
->frame
->area
);
4117 e_size
= self
->frame
->area
.height
;
4118 dir
= grow
? OB_DIRECTION_WEST
: OB_DIRECTION_EAST
;
4120 case OB_DIRECTION_NORTH
:
4121 head
= RECT_TOP(self
->frame
->area
) -
4122 (self
->size_inc
.height
- 1) * (grow
? 1 : -1);
4123 e_start
= RECT_LEFT(self
->frame
->area
);
4124 e_size
= self
->frame
->area
.width
;
4125 dir
= grow
? OB_DIRECTION_NORTH
: OB_DIRECTION_SOUTH
;
4127 case OB_DIRECTION_SOUTH
:
4128 head
= RECT_BOTTOM(self
->frame
->area
) +
4129 (self
->size_inc
.height
- 1) * (grow
? 1 : -1);
4130 e_start
= RECT_LEFT(self
->frame
->area
);
4131 e_size
= self
->frame
->area
.width
;
4132 dir
= grow
? OB_DIRECTION_SOUTH
: OB_DIRECTION_NORTH
;
4135 g_assert_not_reached();
4138 ob_debug("head %d dir %d", head
, dir
);
4139 client_find_edge_directional(self
, dir
, head
, 1,
4140 e_start
, e_size
, &e
, &near
);
4141 ob_debug("edge %d", e
);
4142 *x
= self
->frame
->area
.x
;
4143 *y
= self
->frame
->area
.y
;
4144 *w
= self
->frame
->area
.width
;
4145 *h
= self
->frame
->area
.height
;
4147 case OB_DIRECTION_EAST
:
4148 if (grow
== near
) --e
;
4149 delta
= e
- RECT_RIGHT(self
->frame
->area
);
4152 case OB_DIRECTION_WEST
:
4153 if (grow
== near
) ++e
;
4154 delta
= RECT_LEFT(self
->frame
->area
) - e
;
4158 case OB_DIRECTION_NORTH
:
4159 if (grow
== near
) ++e
;
4160 delta
= RECT_TOP(self
->frame
->area
) - e
;
4164 case OB_DIRECTION_SOUTH
:
4165 if (grow
== near
) --e
;
4166 delta
= e
- RECT_BOTTOM(self
->frame
->area
);
4170 g_assert_not_reached();
4172 frame_frame_gravity(self
->frame
, x
, y
);
4173 *w
-= self
->frame
->size
.left
+ self
->frame
->size
.right
;
4174 *h
-= self
->frame
->size
.top
+ self
->frame
->size
.bottom
;
4177 ObClient
* client_under_pointer(void)
4181 ObClient
*ret
= NULL
;
4183 if (screen_pointer_pos(&x
, &y
)) {
4184 for (it
= stacking_list
; it
; it
= g_list_next(it
)) {
4185 if (WINDOW_IS_CLIENT(it
->data
)) {
4186 ObClient
*c
= WINDOW_AS_CLIENT(it
->data
);
4187 if (c
->frame
->visible
&&
4188 /* check the desktop, this is done during desktop
4189 switching and windows are shown/hidden status is not
4191 (c
->desktop
== screen_desktop
||
4192 c
->desktop
== DESKTOP_ALL
) &&
4193 /* ignore all animating windows */
4194 !frame_iconify_animating(c
->frame
) &&
4195 RECT_CONTAINS(c
->frame
->area
, x
, y
))
4206 gboolean
client_has_group_siblings(ObClient
*self
)
4208 return self
->group
&& self
->group
->members
->next
;