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"
38 #include "menuframe.h"
41 #include "render/render.h"
43 #include "obt/display.h"
51 # include <signal.h> /* for kill() */
55 #include <X11/Xutil.h>
57 /*! The event mask to grab on client windows */
58 #define CLIENT_EVENTMASK (PropertyChangeMask | StructureNotifyMask | \
61 #define CLIENT_NOPROPAGATEMASK (ButtonPressMask | ButtonReleaseMask | \
66 ObClientCallback func
;
70 GList
*client_list
= NULL
;
72 static GSList
*client_destroy_notifies
= NULL
;
74 static void client_get_all(ObClient
*self
, gboolean real
);
75 static void client_get_startup_id(ObClient
*self
);
76 static void client_get_session_ids(ObClient
*self
);
77 static void client_get_area(ObClient
*self
);
78 static void client_get_desktop(ObClient
*self
);
79 static void client_get_state(ObClient
*self
);
80 static void client_get_shaped(ObClient
*self
);
81 static void client_get_mwm_hints(ObClient
*self
);
82 static void client_get_colormap(ObClient
*self
);
83 static void client_set_desktop_recursive(ObClient
*self
,
87 static void client_change_allowed_actions(ObClient
*self
);
88 static void client_change_state(ObClient
*self
);
89 static void client_change_wm_state(ObClient
*self
);
90 static void client_apply_startup_state(ObClient
*self
,
91 gint x
, gint y
, gint w
, gint h
);
92 static void client_restore_session_state(ObClient
*self
);
93 static gboolean
client_restore_session_stacking(ObClient
*self
);
94 static ObAppSettings
*client_get_settings_state(ObClient
*self
);
95 static void client_update_transient_tree(ObClient
*self
,
96 ObGroup
*oldgroup
, ObGroup
*newgroup
,
97 gboolean oldgtran
, gboolean newgtran
,
100 static void client_present(ObClient
*self
, gboolean here
, gboolean raise
,
102 static GSList
*client_search_all_top_parents_internal(ObClient
*self
,
104 ObStackingLayer layer
);
105 static void client_call_notifies(ObClient
*self
, GSList
*list
);
106 static void client_ping_event(ObClient
*self
, gboolean dead
);
109 void client_startup(gboolean reconfig
)
111 if (reconfig
) return;
116 void client_shutdown(gboolean reconfig
)
118 if (reconfig
) return;
121 static void client_call_notifies(ObClient
*self
, GSList
*list
)
125 for (it
= list
; it
; it
= g_slist_next(it
)) {
126 ClientCallback
*d
= it
->data
;
127 d
->func(self
, d
->data
);
131 void client_add_destroy_notify(ObClientCallback func
, gpointer data
)
133 ClientCallback
*d
= g_new(ClientCallback
, 1);
136 client_destroy_notifies
= g_slist_prepend(client_destroy_notifies
, d
);
139 void client_remove_destroy_notify(ObClientCallback func
)
143 for (it
= client_destroy_notifies
; it
; it
= g_slist_next(it
)) {
144 ClientCallback
*d
= it
->data
;
145 if (d
->func
== func
) {
147 client_destroy_notifies
=
148 g_slist_delete_link(client_destroy_notifies
, it
);
154 void client_set_list(void)
156 Window
*windows
, *win_it
;
158 guint size
= g_list_length(client_list
);
160 /* create an array of the window ids */
162 windows
= g_new(Window
, size
);
164 for (it
= client_list
; it
; it
= g_list_next(it
), ++win_it
)
165 *win_it
= ((ObClient
*)it
->data
)->window
;
169 OBT_PROP_SETA32(obt_root(ob_screen
), NET_CLIENT_LIST
, WINDOW
,
170 (gulong
*)windows
, size
);
178 void client_manage(Window window
, ObPrompt
*prompt
)
181 XSetWindowAttributes attrib_set
;
182 gboolean activate
= FALSE
;
183 ObAppSettings
*settings
;
184 gboolean transient
= FALSE
;
185 Rect place
, *monitor
;
186 Time launch_time
, map_time
;
188 ob_debug("Managing window: 0x%lx", window
);
190 map_time
= event_get_server_time();
192 /* choose the events we want to receive on the CLIENT window */
193 attrib_set
.event_mask
= CLIENT_EVENTMASK
;
195 attrib_set
.event_mask
|= KeyPressMask
;
196 attrib_set
.do_not_propagate_mask
= CLIENT_NOPROPAGATEMASK
;
197 XChangeWindowAttributes(obt_display
, window
,
198 CWEventMask
|CWDontPropagate
, &attrib_set
);
200 /* create the ObClient struct, and populate it from the hints on the
202 self
= g_new0(ObClient
, 1);
203 self
->obwin
.type
= OB_WINDOW_CLASS_CLIENT
;
204 self
->window
= window
;
205 self
->prompt
= prompt
;
207 /* non-zero defaults */
208 self
->wmstate
= WithdrawnState
; /* make sure it gets updated first time */
209 self
->gravity
= NorthWestGravity
;
210 self
->desktop
= screen_num_desktops
; /* always an invalid value */
212 /* get all the stuff off the window */
213 client_get_all(self
, TRUE
);
215 ob_debug("Window type: %d", self
->type
);
216 ob_debug("Window group: 0x%x", self
->group
?self
->group
->leader
:0);
218 /* now we have all of the window's information so we can set this up.
219 do this before creating the frame, so it can tell that we are still
220 mapping and doesn't go applying things right away */
221 client_setup_decor_and_functions(self
, FALSE
);
223 /* specify that if we exit, the window should not be destroyed and
224 should be reparented back to root automatically */
226 XChangeSaveSet(obt_display
, window
, SetModeInsert
);
228 /* create the decoration frame for the client window */
229 self
->frame
= frame_new(self
);
231 frame_grab_client(self
->frame
);
233 /* we've grabbed everything and set everything that we need to at mapping
237 /* per-app settings override stuff from client_get_all, and return the
238 settings for other uses too. the returned settings is a shallow copy,
239 that needs to be freed with g_free(). */
240 settings
= client_get_settings_state(self
);
241 /* the session should get the last say though */
242 client_restore_session_state(self
);
244 /* tell startup notification that this app started */
245 launch_time
= sn_app_started(self
->startup_id
, self
->class, self
->name
);
247 /* do this after we have a frame.. it uses the frame to help determine the
248 WM_STATE to apply. */
249 client_change_state(self
);
251 /* add ourselves to the focus order */
252 focus_order_add_new(self
);
254 /* do this to add ourselves to the stacking list in a non-intrusive way */
255 client_calc_layer(self
);
257 /* focus the new window? */
258 if (ob_state() != OB_STATE_STARTING
&&
259 (!self
->session
|| self
->session
->focused
) &&
260 /* this means focus=true for window is same as config_focus_new=true */
261 ((config_focus_new
|| (settings
&& settings
->focus
== 1)) ||
262 client_search_focus_tree_full(self
)) &&
263 /* this checks for focus=false for the window */
264 (!settings
|| settings
->focus
!= 0) &&
265 focus_valid_target(self
, FALSE
, FALSE
, TRUE
, FALSE
, FALSE
))
270 /* remove the client's border */
271 XSetWindowBorderWidth(obt_display
, self
->window
, 0);
273 /* adjust the frame to the client's size before showing or placing
275 frame_adjust_area(self
->frame
, FALSE
, TRUE
, FALSE
);
276 frame_adjust_client_area(self
->frame
);
278 /* where the frame was placed is where the window was originally */
280 monitor
= screen_physical_area_monitor(screen_find_monitor(&place
));
282 /* figure out placement for the window if the window is new */
283 if (ob_state() == OB_STATE_RUNNING
) {
284 ob_debug("Positioned: %s @ %d %d",
285 (!self
->positioned
? "no" :
286 (self
->positioned
== PPosition
? "program specified" :
287 (self
->positioned
== USPosition
? "user specified" :
288 (self
->positioned
== (PPosition
| USPosition
) ?
289 "program + user specified" :
290 "BADNESS !?")))), place
.x
, place
.y
);
292 ob_debug("Sized: %s @ %d %d",
293 (!self
->sized
? "no" :
294 (self
->sized
== PSize
? "program specified" :
295 (self
->sized
== USSize
? "user specified" :
296 (self
->sized
== (PSize
| USSize
) ?
297 "program + user specified" :
298 "BADNESS !?")))), place
.width
, place
.height
);
300 /* splash screens are also returned as TRUE for transient,
301 and so will be forced on screen below */
302 transient
= place_client(self
, &place
.x
, &place
.y
, settings
);
304 /* make sure the window is visible. */
305 client_find_onscreen(self
, &place
.x
, &place
.y
,
306 place
.width
, place
.height
,
307 /* non-normal clients has less rules, and
308 windows that are being restored from a
309 session do also. we can assume you want
310 it back where you saved it. Clients saying
311 they placed themselves are subjected to
312 harder rules, ones that are placed by
313 place.c or by the user are allowed partially
314 off-screen and on xinerama divides (ie,
315 it is up to the placement routines to avoid
316 the xinerama divides)
318 splash screens get "transient" set to TRUE by
319 the place_client call
321 ob_state() == OB_STATE_RUNNING
&&
323 (!((self
->positioned
& USPosition
) ||
324 (settings
&& settings
->pos_given
)) &&
325 client_normal(self
) &&
327 /* don't move oldschool fullscreen windows to
328 fit inside the struts (fixes Acroread, which
329 makes its fullscreen window fit the screen
330 but it is not USSize'd or USPosition'd) */
331 !(self
->decorations
== 0 &&
332 RECT_EQUAL(place
, *monitor
)))));
335 /* if the window isn't user-sized, then make it fit inside
336 the visible screen area on its monitor. Use basically the same rules
337 for forcing the window on screen in the client_find_onscreen call.
339 do this after place_client, it chooses the monitor!
341 splash screens get "transient" set to TRUE by
342 the place_client call
344 if (ob_state() == OB_STATE_RUNNING
&&
346 (!(self
->sized
& USSize
|| self
->positioned
& USPosition
) &&
347 client_normal(self
) &&
349 /* don't shrink oldschool fullscreen windows to fit inside the
350 struts (fixes Acroread, which makes its fullscreen window
351 fit the screen but it is not USSize'd or USPosition'd) */
352 !(self
->decorations
== 0 && RECT_EQUAL(place
, *monitor
)))))
354 Rect
*a
= screen_area(self
->desktop
, SCREEN_AREA_ONE_MONITOR
, &place
);
356 /* get the size of the frame */
357 place
.width
+= self
->frame
->size
.left
+ self
->frame
->size
.right
;
358 place
.height
+= self
->frame
->size
.top
+ self
->frame
->size
.bottom
;
360 /* fit the window inside the area */
361 place
.width
= MIN(place
.width
, a
->width
);
362 place
.height
= MIN(place
.height
, a
->height
);
364 ob_debug("setting window size to %dx%d", place
.width
, place
.height
);
366 /* get the size of the client back */
367 place
.width
-= self
->frame
->size
.left
+ self
->frame
->size
.right
;
368 place
.height
-= self
->frame
->size
.top
+ self
->frame
->size
.bottom
;
373 ob_debug("placing window 0x%x at %d, %d with size %d x %d. "
374 "some restrictions may apply",
375 self
->window
, place
.x
, place
.y
, place
.width
, place
.height
);
377 ob_debug(" but session requested %d, %d %d x %d instead, "
379 self
->session
->x
, self
->session
->y
,
380 self
->session
->w
, self
->session
->h
);
382 /* do this after the window is placed, so the premax/prefullscreen numbers
385 this also places the window
387 client_apply_startup_state(self
, place
.x
, place
.y
,
388 place
.width
, place
.height
);
393 ob_debug_type(OB_DEBUG_FOCUS
, "Going to try activate new window? %s",
394 activate
? "yes" : "no");
396 gboolean raise
= FALSE
;
398 /* This is focus stealing prevention */
399 ob_debug_type(OB_DEBUG_FOCUS
,
400 "Want to focus new window 0x%x at time %u "
401 "launched at %u (last user interaction time %u)",
402 self
->window
, map_time
, launch_time
,
403 event_last_user_time
);
405 if (menu_frame_visible
|| moveresize_in_progress
) {
408 ob_debug_type(OB_DEBUG_FOCUS
,
409 "Not focusing the window because the user is inside "
410 "an Openbox menu or is move/resizing a window and "
411 "we don't want to interrupt them");
414 /* if it's on another desktop */
415 else if (!(self
->desktop
== screen_desktop
||
416 self
->desktop
== DESKTOP_ALL
) &&
417 /* the timestamp is from before you changed desktops */
418 launch_time
&& screen_desktop_user_time
&&
419 !event_time_after(launch_time
, screen_desktop_user_time
))
423 ob_debug_type(OB_DEBUG_FOCUS
,
424 "Not focusing the window because its on another "
427 /* If something is focused, and it's not our relative... */
428 else if (focus_client
&& client_search_focus_tree_full(self
) == NULL
&&
429 client_search_focus_group_full(self
) == NULL
)
431 /* If the user is working in another window right now, then don't
433 if (event_last_user_time
&& launch_time
&&
434 event_time_after(event_last_user_time
, launch_time
) &&
435 event_last_user_time
!= launch_time
&&
436 event_time_after(event_last_user_time
,
437 map_time
- OB_EVENT_USER_TIME_DELAY
))
440 ob_debug_type(OB_DEBUG_FOCUS
,
441 "Not focusing the window because the user is "
442 "working in another window");
444 /* If its a transient (and its parents aren't focused) */
445 else if (client_has_parent(self
)) {
447 ob_debug_type(OB_DEBUG_FOCUS
,
448 "Not focusing the window because it is a "
449 "transient, and its relatives aren't focused");
451 /* Don't steal focus from globally active clients.
452 I stole this idea from KWin. It seems nice.
454 else if (!(focus_client
->can_focus
||
455 focus_client
->focus_notify
))
458 ob_debug_type(OB_DEBUG_FOCUS
,
459 "Not focusing the window because a globally "
460 "active client has focus");
462 /* Don't move focus if it's not going to go to this window
464 else if (client_focus_target(self
) != self
) {
467 ob_debug_type(OB_DEBUG_FOCUS
,
468 "Not focusing the window because another window "
469 "would get the focus anyway");
471 else if (!(self
->desktop
== screen_desktop
||
472 self
->desktop
== DESKTOP_ALL
))
476 ob_debug_type(OB_DEBUG_FOCUS
,
477 "Not focusing the window because it is on "
478 "another desktop and no relatives are focused ");
483 ob_debug_type(OB_DEBUG_FOCUS
,
484 "Focus stealing prevention activated for %s at "
485 "time %u (last user interactioon time %u)",
486 self
->title
, map_time
, event_last_user_time
);
487 /* if the client isn't focused, then hilite it so the user
489 client_hilite(self
, TRUE
);
490 /* we may want to raise it even tho we're not activating it */
491 if (raise
&& !client_restore_session_stacking(self
))
492 stacking_raise(CLIENT_AS_WINDOW(self
));
496 /* This may look rather odd. Well it's because new windows are added
497 to the stacking order non-intrusively. If we're not going to focus
498 the new window or hilite it, then we raise it to the top. This will
499 take affect for things that don't get focused like splash screens.
500 Also if you don't have focus_new enabled, then it's going to get
501 raised to the top. Legacy begets legacy I guess?
503 if (!client_restore_session_stacking(self
))
504 stacking_raise(CLIENT_AS_WINDOW(self
));
507 mouse_grab_for_client(self
, TRUE
);
509 /* this has to happen before we try focus the window, but we want it to
510 happen after the client's stacking has been determined or it looks bad
514 if (!config_focus_under_mouse
)
515 ignore_start
= event_start_ignore_all_enters();
519 if (!config_focus_under_mouse
)
520 event_end_ignore_all_enters(ignore_start
);
524 gboolean stacked
= client_restore_session_stacking(self
);
525 client_present(self
, FALSE
, !stacked
, TRUE
);
528 /* add to client list/map */
529 client_list
= g_list_append(client_list
, self
);
530 window_add(&self
->window
, CLIENT_AS_WINDOW(self
));
532 /* this has to happen after we're in the client_list */
533 if (STRUT_EXISTS(self
->strut
))
534 screen_update_areas();
536 /* update the list hints */
539 /* watch for when the application stops responding. only do this for
540 normal windows, i.e. windows which have titlebars and close buttons
541 and things like that.
542 we don't need to stop pinging on unmanage, because it will be handled
543 automatically by the destroy callback!
545 if (self
->ping
&& client_normal(self
))
546 ping_start(self
, client_ping_event
);
548 /* free the ObAppSettings shallow copy */
551 ob_debug("Managed window 0x%lx plate 0x%x (%s)",
552 window
, self
->frame
->window
, self
->class);
556 ObClient
*client_fake_manage(Window window
)
559 ObAppSettings
*settings
;
561 ob_debug("Pretend-managing window: %lx", window
);
563 /* do this minimal stuff to figure out the client's decorations */
565 self
= g_new0(ObClient
, 1);
566 self
->window
= window
;
568 client_get_all(self
, FALSE
);
569 /* per-app settings override stuff, and return the settings for other
570 uses too. this returns a shallow copy that needs to be freed */
571 settings
= client_get_settings_state(self
);
573 client_setup_decor_and_functions(self
, FALSE
);
575 /* create the decoration frame for the client window and adjust its size */
576 self
->frame
= frame_new(self
);
577 frame_adjust_area(self
->frame
, FALSE
, TRUE
, TRUE
);
579 ob_debug("gave extents left %d right %d top %d bottom %d",
580 self
->frame
->size
.left
, self
->frame
->size
.right
,
581 self
->frame
->size
.top
, self
->frame
->size
.bottom
);
583 /* free the ObAppSettings shallow copy */
589 void client_unmanage_all(void)
591 while (client_list
!= NULL
)
592 client_unmanage(client_list
->data
);
595 void client_unmanage(ObClient
*self
)
601 ob_debug("Unmanaging window: 0x%x plate 0x%x (%s) (%s)",
602 self
->window
, self
->frame
->window
,
603 self
->class, self
->title
? self
->title
: "");
605 g_assert(self
!= NULL
);
607 /* we dont want events no more. do this before hiding the frame so we
608 don't generate more events */
609 XSelectInput(obt_display
, self
->window
, NoEventMask
);
611 /* ignore enter events from the unmap so it doesnt mess with the focus */
612 if (!config_focus_under_mouse
)
613 ignore_start
= event_start_ignore_all_enters();
615 frame_hide(self
->frame
);
616 /* flush to send the hide to the server quickly */
619 if (!config_focus_under_mouse
)
620 event_end_ignore_all_enters(ignore_start
);
622 mouse_grab_for_client(self
, FALSE
);
624 /* remove the window from our save set */
626 XChangeSaveSet(obt_display
, self
->window
, SetModeDelete
);
628 /* update the focus lists */
629 focus_order_remove(self
);
630 if (client_focused(self
)) {
631 /* don't leave an invalid focus_client */
635 client_list
= g_list_remove(client_list
, self
);
636 stacking_remove(self
);
637 window_remove(self
->window
);
639 /* once the client is out of the list, update the struts to remove its
641 if (STRUT_EXISTS(self
->strut
))
642 screen_update_areas();
644 client_call_notifies(self
, client_destroy_notifies
);
646 /* tell our parent(s) that we're gone */
647 for (it
= self
->parents
; it
; it
= g_slist_next(it
))
648 ((ObClient
*)it
->data
)->transients
=
649 g_slist_remove(((ObClient
*)it
->data
)->transients
,self
);
651 /* tell our transients that we're gone */
652 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
653 ((ObClient
*)it
->data
)->parents
=
654 g_slist_remove(((ObClient
*)it
->data
)->parents
, self
);
655 /* we could be keeping our children in a higher layer */
656 client_calc_layer(it
->data
);
659 /* remove from its group */
661 group_remove(self
->group
, self
);
665 /* restore the window's original geometry so it is not lost */
671 if (self
->fullscreen
)
672 a
= self
->pre_fullscreen_area
;
673 else if (self
->max_horz
|| self
->max_vert
) {
674 if (self
->max_horz
) {
675 a
.x
= self
->pre_max_area
.x
;
676 a
.width
= self
->pre_max_area
.width
;
678 if (self
->max_vert
) {
679 a
.y
= self
->pre_max_area
.y
;
680 a
.height
= self
->pre_max_area
.height
;
684 self
->fullscreen
= self
->max_horz
= self
->max_vert
= FALSE
;
685 /* let it be moved and resized no matter what */
686 self
->functions
= OB_CLIENT_FUNC_MOVE
| OB_CLIENT_FUNC_RESIZE
;
687 self
->decorations
= 0; /* unmanaged windows have no decor */
689 /* give the client its border back */
690 XSetWindowBorderWidth(obt_display
, self
->window
, self
->border_width
);
692 client_move_resize(self
, a
.x
, a
.y
, a
.width
, a
.height
);
695 /* reparent the window out of the frame, and free the frame */
696 frame_release_client(self
->frame
);
697 frame_free(self
->frame
);
700 if (ob_state() != OB_STATE_EXITING
) {
701 /* these values should not be persisted across a window
703 OBT_PROP_ERASE(self
->window
, NET_WM_DESKTOP
);
704 OBT_PROP_ERASE(self
->window
, NET_WM_STATE
);
705 OBT_PROP_ERASE(self
->window
, WM_STATE
);
707 /* if we're left in an unmapped state, the client wont be mapped.
708 this is bad, since we will no longer be managing the window on
710 XMapWindow(obt_display
, self
->window
);
713 /* these should not be left on the window ever. other window managers
714 don't necessarily use them and it will mess them up (like compiz) */
715 OBT_PROP_ERASE(self
->window
, NET_WM_VISIBLE_NAME
);
716 OBT_PROP_ERASE(self
->window
, NET_WM_VISIBLE_ICON_NAME
);
718 /* update the list hints */
721 ob_debug("Unmanaged window 0x%lx", self
->window
);
723 /* free all data allocated in the client struct */
724 g_slist_free(self
->transients
);
725 for (j
= 0; j
< self
->nicons
; ++j
)
726 g_free(self
->icons
[j
].data
);
727 if (self
->nicons
> 0)
729 g_free(self
->startup_id
);
730 g_free(self
->wm_command
);
732 g_free(self
->icon_title
);
736 g_free(self
->client_machine
);
737 g_free(self
->sm_client_id
);
741 void client_fake_unmanage(ObClient
*self
)
743 /* this is all that got allocated to get the decorations */
745 frame_free(self
->frame
);
749 /*! Returns a new structure containing the per-app settings for this client.
750 The returned structure needs to be freed with g_free. */
751 static ObAppSettings
*client_get_settings_state(ObClient
*self
)
753 ObAppSettings
*settings
;
756 settings
= config_create_app_settings();
758 for (it
= config_per_app_settings
; it
; it
= g_slist_next(it
)) {
759 ObAppSettings
*app
= it
->data
;
760 gboolean match
= TRUE
;
762 g_assert(app
->name
!= NULL
|| app
->class != NULL
);
764 /* we know that either name or class is not NULL so it will have to
765 match to use the rule */
767 !g_pattern_match(app
->name
, strlen(self
->name
), self
->name
, NULL
))
769 else if (app
->class &&
770 !g_pattern_match(app
->class,
771 strlen(self
->class), self
->class, NULL
))
773 else if (app
->role
&&
774 !g_pattern_match(app
->role
,
775 strlen(self
->role
), self
->role
, NULL
))
779 ob_debug("Window matching: %s", app
->name
);
781 /* copy the settings to our struct, overriding the existing
782 settings if they are not defaults */
783 config_app_settings_copy_non_defaults(app
, settings
);
787 if (settings
->shade
!= -1)
788 self
->shaded
= !!settings
->shade
;
789 if (settings
->decor
!= -1)
790 self
->undecorated
= !settings
->decor
;
791 if (settings
->iconic
!= -1)
792 self
->iconic
= !!settings
->iconic
;
793 if (settings
->skip_pager
!= -1)
794 self
->skip_pager
= !!settings
->skip_pager
;
795 if (settings
->skip_taskbar
!= -1)
796 self
->skip_taskbar
= !!settings
->skip_taskbar
;
798 if (settings
->max_vert
!= -1)
799 self
->max_vert
= !!settings
->max_vert
;
800 if (settings
->max_horz
!= -1)
801 self
->max_horz
= !!settings
->max_horz
;
803 if (settings
->fullscreen
!= -1)
804 self
->fullscreen
= !!settings
->fullscreen
;
806 if (settings
->desktop
) {
807 if (settings
->desktop
== DESKTOP_ALL
)
808 self
->desktop
= settings
->desktop
;
809 else if (settings
->desktop
> 0 &&
810 settings
->desktop
<= screen_num_desktops
)
811 self
->desktop
= settings
->desktop
- 1;
814 if (settings
->layer
== -1) {
818 else if (settings
->layer
== 0) {
822 else if (settings
->layer
== 1) {
829 static void client_restore_session_state(ObClient
*self
)
833 ob_debug_type(OB_DEBUG_SM
,
834 "Restore session for client %s", self
->title
);
836 if (!(it
= session_state_find(self
))) {
837 ob_debug_type(OB_DEBUG_SM
,
838 "Session data not found for client %s", self
->title
);
842 self
->session
= it
->data
;
844 ob_debug_type(OB_DEBUG_SM
, "Session data loaded for client %s",
847 RECT_SET_POINT(self
->area
, self
->session
->x
, self
->session
->y
);
848 self
->positioned
= USPosition
;
849 self
->sized
= USSize
;
850 if (self
->session
->w
> 0)
851 self
->area
.width
= self
->session
->w
;
852 if (self
->session
->h
> 0)
853 self
->area
.height
= self
->session
->h
;
854 XResizeWindow(obt_display
, self
->window
,
855 self
->area
.width
, self
->area
.height
);
857 self
->desktop
= (self
->session
->desktop
== DESKTOP_ALL
?
858 self
->session
->desktop
:
859 MIN(screen_num_desktops
- 1, self
->session
->desktop
));
860 OBT_PROP_SET32(self
->window
, NET_WM_DESKTOP
, CARDINAL
, self
->desktop
);
862 self
->shaded
= self
->session
->shaded
;
863 self
->iconic
= self
->session
->iconic
;
864 self
->skip_pager
= self
->session
->skip_pager
;
865 self
->skip_taskbar
= self
->session
->skip_taskbar
;
866 self
->fullscreen
= self
->session
->fullscreen
;
867 self
->above
= self
->session
->above
;
868 self
->below
= self
->session
->below
;
869 self
->max_horz
= self
->session
->max_horz
;
870 self
->max_vert
= self
->session
->max_vert
;
871 self
->undecorated
= self
->session
->undecorated
;
874 static gboolean
client_restore_session_stacking(ObClient
*self
)
878 if (!self
->session
) return FALSE
;
880 mypos
= g_list_find(session_saved_state
, self
->session
);
881 if (!mypos
) return FALSE
;
883 /* start above me and look for the first client */
884 for (it
= g_list_previous(mypos
); it
; it
= g_list_previous(it
)) {
887 for (cit
= client_list
; cit
; cit
= g_list_next(cit
)) {
888 ObClient
*c
= cit
->data
;
889 /* found a client that was in the session, so go below it */
890 if (c
->session
== it
->data
) {
891 stacking_below(CLIENT_AS_WINDOW(self
),
892 CLIENT_AS_WINDOW(cit
->data
));
900 void client_move_onscreen(ObClient
*self
, gboolean rude
)
902 gint x
= self
->area
.x
;
903 gint y
= self
->area
.y
;
904 if (client_find_onscreen(self
, &x
, &y
,
906 self
->area
.height
, rude
)) {
907 client_move(self
, x
, y
);
911 gboolean
client_find_onscreen(ObClient
*self
, gint
*x
, gint
*y
, gint w
, gint h
,
914 gint ox
= *x
, oy
= *y
;
915 gboolean rudel
= rude
, ruder
= rude
, rudet
= rude
, rudeb
= rude
;
921 RECT_SET(desired
, *x
, *y
, w
, h
);
922 frame_rect_to_frame(self
->frame
, &desired
);
924 /* get where the frame would be */
925 frame_client_gravity(self
->frame
, x
, y
);
927 /* get the requested size of the window with decorations */
928 fw
= self
->frame
->size
.left
+ w
+ self
->frame
->size
.right
;
929 fh
= self
->frame
->size
.top
+ h
+ self
->frame
->size
.bottom
;
931 /* If rudeness wasn't requested, then still be rude in a given direction
932 if the client is not moving, only resizing in that direction */
934 Point oldtl
, oldtr
, oldbl
, oldbr
;
935 Point newtl
, newtr
, newbl
, newbr
;
936 gboolean stationary_l
, stationary_r
, stationary_t
, stationary_b
;
938 POINT_SET(oldtl
, self
->frame
->area
.x
, self
->frame
->area
.y
);
939 POINT_SET(oldbr
, self
->frame
->area
.x
+ self
->frame
->area
.width
- 1,
940 self
->frame
->area
.y
+ self
->frame
->area
.height
- 1);
941 POINT_SET(oldtr
, oldbr
.x
, oldtl
.y
);
942 POINT_SET(oldbl
, oldtl
.x
, oldbr
.y
);
944 POINT_SET(newtl
, *x
, *y
);
945 POINT_SET(newbr
, *x
+ fw
- 1, *y
+ fh
- 1);
946 POINT_SET(newtr
, newbr
.x
, newtl
.y
);
947 POINT_SET(newbl
, newtl
.x
, newbr
.y
);
949 /* is it moving or just resizing from some corner? */
950 stationary_l
= oldtl
.x
== newtl
.x
;
951 stationary_r
= oldtr
.x
== newtr
.x
;
952 stationary_t
= oldtl
.y
== newtl
.y
;
953 stationary_b
= oldbl
.y
== newbl
.y
;
955 /* if left edge is growing and didnt move right edge */
956 if (stationary_r
&& newtl
.x
< oldtl
.x
)
958 /* if right edge is growing and didnt move left edge */
959 if (stationary_l
&& newtr
.x
> oldtr
.x
)
961 /* if top edge is growing and didnt move bottom edge */
962 if (stationary_b
&& newtl
.y
< oldtl
.y
)
964 /* if bottom edge is growing and didnt move top edge */
965 if (stationary_t
&& newbl
.y
> oldbl
.y
)
969 /* we iterate through every monitor that the window is at least partially
970 on, to make sure it is obeying the rules on them all
972 if the window does not appear on any monitors, then use the first one
975 for (i
= 0; i
< screen_num_monitors
; ++i
) {
978 if (!screen_physical_area_monitor_contains(i
, &desired
)) {
979 if (i
< screen_num_monitors
- 1 || found_mon
)
982 /* the window is not inside any monitor! so just use the first
984 a
= screen_area(self
->desktop
, 0, NULL
);
987 a
= screen_area(self
->desktop
, SCREEN_AREA_ONE_MONITOR
, &desired
);
990 /* This makes sure windows aren't entirely outside of the screen so you
991 can't see them at all.
992 It makes sure 10% of the window is on the screen at least. At don't
993 let it move itself off the top of the screen, which would hide the
994 titlebar on you. (The user can still do this if they want too, it's
995 only limiting the application.
997 if (client_normal(self
)) {
998 if (!self
->strut
.right
&& *x
+ fw
/10 >= a
->x
+ a
->width
- 1)
999 *x
= a
->x
+ a
->width
- fw
/10;
1000 if (!self
->strut
.bottom
&& *y
+ fh
/10 >= a
->y
+ a
->height
- 1)
1001 *y
= a
->y
+ a
->height
- fh
/10;
1002 if (!self
->strut
.left
&& *x
+ fw
*9/10 - 1 < a
->x
)
1003 *x
= a
->x
- fw
*9/10;
1004 if (!self
->strut
.top
&& *y
+ fh
*9/10 - 1 < a
->y
)
1005 *y
= a
->y
- fh
*9/10;
1008 /* This here doesn't let windows even a pixel outside the
1009 struts/screen. When called from client_manage, programs placing
1010 themselves are forced completely onscreen, while things like
1011 xterm -geometry resolution-width/2 will work fine. Trying to
1012 place it completely offscreen will be handled in the above code.
1013 Sorry for this confused comment, i am tired. */
1014 if (rudel
&& !self
->strut
.left
&& *x
< a
->x
) *x
= a
->x
;
1015 if (ruder
&& !self
->strut
.right
&& *x
+ fw
> a
->x
+ a
->width
)
1016 *x
= a
->x
+ MAX(0, a
->width
- fw
);
1018 if (rudet
&& !self
->strut
.top
&& *y
< a
->y
) *y
= a
->y
;
1019 if (rudeb
&& !self
->strut
.bottom
&& *y
+ fh
> a
->y
+ a
->height
)
1020 *y
= a
->y
+ MAX(0, a
->height
- fh
);
1025 /* get where the client should be */
1026 frame_frame_gravity(self
->frame
, x
, y
);
1028 return ox
!= *x
|| oy
!= *y
;
1031 static void client_get_all(ObClient
*self
, gboolean real
)
1033 /* this is needed for the frame to set itself up */
1034 client_get_area(self
);
1036 /* these things can change the decor and functions of the window */
1038 client_get_mwm_hints(self
);
1039 /* this can change the mwmhints for special cases */
1040 client_get_type_and_transientness(self
);
1041 client_get_state(self
);
1042 client_update_normal_hints(self
);
1044 /* get the session related properties, these can change decorations
1045 from per-app settings */
1046 client_get_session_ids(self
);
1048 /* now we got everything that can affect the decorations */
1052 /* get this early so we have it for debugging */
1053 client_update_title(self
);
1055 client_update_protocols(self
);
1057 client_update_wmhints(self
);
1058 /* this may have already been called from client_update_wmhints */
1059 if (!self
->parents
&& !self
->transient_for_group
)
1060 client_update_transient_for(self
);
1062 client_get_startup_id(self
);
1063 client_get_desktop(self
);/* uses transient data/group/startup id if a
1064 desktop is not specified */
1065 client_get_shaped(self
);
1068 /* a couple type-based defaults for new windows */
1070 /* this makes sure that these windows appear on all desktops */
1071 if (self
->type
== OB_CLIENT_TYPE_DESKTOP
)
1072 self
->desktop
= DESKTOP_ALL
;
1076 client_update_sync_request_counter(self
);
1079 client_get_colormap(self
);
1080 client_update_strut(self
);
1081 client_update_icons(self
);
1082 client_update_icon_geometry(self
);
1085 static void client_get_startup_id(ObClient
*self
)
1087 if (!(OBT_PROP_GETS(self
->window
, NET_STARTUP_ID
, utf8
,
1088 &self
->startup_id
)))
1090 OBT_PROP_GETS(self
->group
->leader
,
1091 NET_STARTUP_ID
, utf8
, &self
->startup_id
);
1094 static void client_get_area(ObClient
*self
)
1096 XWindowAttributes wattrib
;
1099 ret
= XGetWindowAttributes(obt_display
, self
->window
, &wattrib
);
1100 g_assert(ret
!= BadWindow
);
1102 RECT_SET(self
->area
, wattrib
.x
, wattrib
.y
, wattrib
.width
, wattrib
.height
);
1103 POINT_SET(self
->root_pos
, wattrib
.x
, wattrib
.y
);
1104 self
->border_width
= wattrib
.border_width
;
1106 ob_debug("client area: %d %d %d %d bw %d", wattrib
.x
, wattrib
.y
,
1107 wattrib
.width
, wattrib
.height
, wattrib
.border_width
);
1110 static void client_get_desktop(ObClient
*self
)
1112 guint32 d
= screen_num_desktops
; /* an always-invalid value */
1114 if (OBT_PROP_GET32(self
->window
, NET_WM_DESKTOP
, CARDINAL
, &d
)) {
1115 if (d
>= screen_num_desktops
&& d
!= DESKTOP_ALL
)
1116 self
->desktop
= screen_num_desktops
- 1;
1119 ob_debug("client requested desktop 0x%x", self
->desktop
);
1122 gboolean first
= TRUE
;
1123 guint all
= screen_num_desktops
; /* not a valid value */
1125 /* if they are all on one desktop, then open it on the
1127 for (it
= self
->parents
; it
; it
= g_slist_next(it
)) {
1128 ObClient
*c
= it
->data
;
1130 if (c
->desktop
== DESKTOP_ALL
) continue;
1136 else if (all
!= c
->desktop
)
1137 all
= screen_num_desktops
; /* make it invalid */
1139 if (all
!= screen_num_desktops
) {
1140 self
->desktop
= all
;
1142 ob_debug("client desktop set from parents: 0x%x",
1145 /* try get from the startup-notification protocol */
1146 else if (sn_get_desktop(self
->startup_id
, &self
->desktop
)) {
1147 if (self
->desktop
>= screen_num_desktops
&&
1148 self
->desktop
!= DESKTOP_ALL
)
1149 self
->desktop
= screen_num_desktops
- 1;
1150 ob_debug("client desktop set from startup-notification: 0x%x",
1153 /* defaults to the current desktop */
1155 self
->desktop
= screen_desktop
;
1156 ob_debug("client desktop set to the current desktop: %d",
1162 static void client_get_state(ObClient
*self
)
1167 if (OBT_PROP_GETA32(self
->window
, NET_WM_STATE
, ATOM
, &state
, &num
)) {
1169 for (i
= 0; i
< num
; ++i
) {
1170 if (state
[i
] == OBT_PROP_ATOM(NET_WM_STATE_MODAL
))
1172 else if (state
[i
] == OBT_PROP_ATOM(NET_WM_STATE_SHADED
))
1173 self
->shaded
= TRUE
;
1174 else if (state
[i
] == OBT_PROP_ATOM(NET_WM_STATE_HIDDEN
))
1175 self
->iconic
= TRUE
;
1176 else if (state
[i
] == OBT_PROP_ATOM(NET_WM_STATE_SKIP_TASKBAR
))
1177 self
->skip_taskbar
= TRUE
;
1178 else if (state
[i
] == OBT_PROP_ATOM(NET_WM_STATE_SKIP_PAGER
))
1179 self
->skip_pager
= TRUE
;
1180 else if (state
[i
] == OBT_PROP_ATOM(NET_WM_STATE_FULLSCREEN
))
1181 self
->fullscreen
= TRUE
;
1182 else if (state
[i
] == OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_VERT
))
1183 self
->max_vert
= TRUE
;
1184 else if (state
[i
] == OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_HORZ
))
1185 self
->max_horz
= TRUE
;
1186 else if (state
[i
] == OBT_PROP_ATOM(NET_WM_STATE_ABOVE
))
1188 else if (state
[i
] == OBT_PROP_ATOM(NET_WM_STATE_BELOW
))
1190 else if (state
[i
] == OBT_PROP_ATOM(NET_WM_STATE_DEMANDS_ATTENTION
))
1191 self
->demands_attention
= TRUE
;
1192 else if (state
[i
] == OBT_PROP_ATOM(OB_WM_STATE_UNDECORATED
))
1193 self
->undecorated
= TRUE
;
1200 static void client_get_shaped(ObClient
*self
)
1202 self
->shaped
= FALSE
;
1204 if (obt_display_extension_shape
) {
1209 XShapeSelectInput(obt_display
, self
->window
, ShapeNotifyMask
);
1211 XShapeQueryExtents(obt_display
, self
->window
, &s
, &foo
,
1212 &foo
, &ufoo
, &ufoo
, &foo
, &foo
, &foo
, &ufoo
,
1214 self
->shaped
= (s
!= 0);
1219 void client_update_transient_for(ObClient
*self
)
1222 ObClient
*target
= NULL
;
1223 gboolean trangroup
= FALSE
;
1225 if (XGetTransientForHint(obt_display
, self
->window
, &t
)) {
1226 if (t
!= self
->window
) { /* cant be transient to itself! */
1227 ObWindow
*tw
= window_find(t
);
1228 /* if this happens then we need to check for it*/
1229 g_assert(tw
!= CLIENT_AS_WINDOW(self
));
1230 if (tw
&& WINDOW_IS_CLIENT(tw
)) {
1231 /* watch out for windows with a parent that is something
1232 different, like a dockapp for example */
1233 target
= WINDOW_AS_CLIENT(tw
);
1237 /* Setting the transient_for to Root is actually illegal, however
1238 applications from time have done this to specify transient for
1240 if (!target
&& self
->group
&& t
== obt_root(ob_screen
))
1242 } else if (self
->group
&& self
->transient
)
1245 client_update_transient_tree(self
, self
->group
, self
->group
,
1246 self
->transient_for_group
, trangroup
,
1247 client_direct_parent(self
), target
);
1248 self
->transient_for_group
= trangroup
;
1252 static void client_update_transient_tree(ObClient
*self
,
1253 ObGroup
*oldgroup
, ObGroup
*newgroup
,
1254 gboolean oldgtran
, gboolean newgtran
,
1255 ObClient
* oldparent
,
1256 ObClient
*newparent
)
1261 g_assert(!oldgtran
|| oldgroup
);
1262 g_assert(!newgtran
|| newgroup
);
1263 g_assert((!oldgtran
&& !oldparent
) ||
1264 (oldgtran
&& !oldparent
) ||
1265 (!oldgtran
&& oldparent
));
1266 g_assert((!newgtran
&& !newparent
) ||
1267 (newgtran
&& !newparent
) ||
1268 (!newgtran
&& newparent
));
1271 Group transient windows are not allowed to have other group
1272 transient windows as their children.
1276 /* No change has occured */
1277 if (oldgroup
== newgroup
&&
1278 oldgtran
== newgtran
&&
1279 oldparent
== newparent
) return;
1281 /** Remove the client from the transient tree **/
1283 for (it
= self
->transients
; it
; it
= next
) {
1284 next
= g_slist_next(it
);
1286 self
->transients
= g_slist_delete_link(self
->transients
, it
);
1287 c
->parents
= g_slist_remove(c
->parents
, self
);
1289 for (it
= self
->parents
; it
; it
= next
) {
1290 next
= g_slist_next(it
);
1292 self
->parents
= g_slist_delete_link(self
->parents
, it
);
1293 c
->transients
= g_slist_remove(c
->transients
, self
);
1296 /** Re-add the client to the transient tree **/
1298 /* If we're transient for a group then we need to add ourselves to all our
1301 for (it
= newgroup
->members
; it
; it
= g_slist_next(it
)) {
1304 !client_search_top_direct_parent(c
)->transient_for_group
&&
1307 c
->transients
= g_slist_prepend(c
->transients
, self
);
1308 self
->parents
= g_slist_prepend(self
->parents
, c
);
1313 /* If we are now transient for a single window we need to add ourselves to
1316 WARNING: Cyclical transient ness is possible if two windows are
1317 transient for eachother.
1319 else if (newparent
&&
1320 /* don't make ourself its child if it is already our child */
1321 !client_is_direct_child(self
, newparent
) &&
1322 client_normal(newparent
))
1324 newparent
->transients
= g_slist_prepend(newparent
->transients
, self
);
1325 self
->parents
= g_slist_prepend(self
->parents
, newparent
);
1328 /* Add any group transient windows to our children. But if we're transient
1329 for the group, then other group transients are not our children.
1331 WARNING: Cyclical transient-ness is possible. For e.g. if:
1332 A is transient for the group
1333 B is transient for A
1334 C is transient for B
1335 A can't be transient for C or we have a cycle
1337 if (!newgtran
&& newgroup
&&
1339 !client_search_top_direct_parent(newparent
)->transient_for_group
) &&
1340 client_normal(self
))
1342 for (it
= newgroup
->members
; it
; it
= g_slist_next(it
)) {
1344 if (c
!= self
&& c
->transient_for_group
&&
1345 /* Don't make it our child if it is already our parent */
1346 !client_is_direct_child(c
, self
))
1348 self
->transients
= g_slist_prepend(self
->transients
, c
);
1349 c
->parents
= g_slist_prepend(c
->parents
, self
);
1354 /** If we change our group transient-ness, our children change their
1355 effect group transient-ness, which affects how they relate to other
1358 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
1360 if (!c
->transient_for_group
)
1361 client_update_transient_tree(c
, c
->group
, c
->group
,
1362 c
->transient_for_group
,
1363 c
->transient_for_group
,
1364 client_direct_parent(c
),
1365 client_direct_parent(c
));
1369 static void client_get_mwm_hints(ObClient
*self
)
1374 self
->mwmhints
.flags
= 0; /* default to none */
1376 if (OBT_PROP_GETA32(self
->window
, MOTIF_WM_HINTS
, MOTIF_WM_HINTS
,
1378 if (num
>= OB_MWM_ELEMENTS
) {
1379 self
->mwmhints
.flags
= hints
[0];
1380 self
->mwmhints
.functions
= hints
[1];
1381 self
->mwmhints
.decorations
= hints
[2];
1387 void client_get_type_and_transientness(ObClient
*self
)
1394 self
->transient
= FALSE
;
1396 if (OBT_PROP_GETA32(self
->window
, NET_WM_WINDOW_TYPE
, ATOM
, &val
, &num
)) {
1397 /* use the first value that we know about in the array */
1398 for (i
= 0; i
< num
; ++i
) {
1399 if (val
[i
] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_DESKTOP
))
1400 self
->type
= OB_CLIENT_TYPE_DESKTOP
;
1401 else if (val
[i
] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_DOCK
))
1402 self
->type
= OB_CLIENT_TYPE_DOCK
;
1403 else if (val
[i
] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_TOOLBAR
))
1404 self
->type
= OB_CLIENT_TYPE_TOOLBAR
;
1405 else if (val
[i
] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_MENU
))
1406 self
->type
= OB_CLIENT_TYPE_MENU
;
1407 else if (val
[i
] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_UTILITY
))
1408 self
->type
= OB_CLIENT_TYPE_UTILITY
;
1409 else if (val
[i
] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_SPLASH
))
1410 self
->type
= OB_CLIENT_TYPE_SPLASH
;
1411 else if (val
[i
] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_DIALOG
))
1412 self
->type
= OB_CLIENT_TYPE_DIALOG
;
1413 else if (val
[i
] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_NORMAL
))
1414 self
->type
= OB_CLIENT_TYPE_NORMAL
;
1415 else if (val
[i
] == OBT_PROP_ATOM(KDE_NET_WM_WINDOW_TYPE_OVERRIDE
))
1417 /* prevent this window from getting any decor or
1419 self
->mwmhints
.flags
&= (OB_MWM_FLAG_FUNCTIONS
|
1420 OB_MWM_FLAG_DECORATIONS
);
1421 self
->mwmhints
.decorations
= 0;
1422 self
->mwmhints
.functions
= 0;
1424 if (self
->type
!= (ObClientType
) -1)
1425 break; /* grab the first legit type */
1430 if (XGetTransientForHint(obt_display
, self
->window
, &t
))
1431 self
->transient
= TRUE
;
1433 if (self
->type
== (ObClientType
) -1) {
1434 /*the window type hint was not set, which means we either classify
1435 ourself as a normal window or a dialog, depending on if we are a
1437 if (self
->transient
)
1438 self
->type
= OB_CLIENT_TYPE_DIALOG
;
1440 self
->type
= OB_CLIENT_TYPE_NORMAL
;
1443 /* then, based on our type, we can update our transientness.. */
1444 if (self
->type
== OB_CLIENT_TYPE_DIALOG
||
1445 self
->type
== OB_CLIENT_TYPE_TOOLBAR
||
1446 self
->type
== OB_CLIENT_TYPE_MENU
||
1447 self
->type
== OB_CLIENT_TYPE_UTILITY
)
1449 self
->transient
= TRUE
;
1453 void client_update_protocols(ObClient
*self
)
1458 self
->focus_notify
= FALSE
;
1459 self
->delete_window
= FALSE
;
1461 if (OBT_PROP_GETA32(self
->window
, WM_PROTOCOLS
, ATOM
, &proto
, &num_ret
)) {
1462 for (i
= 0; i
< num_ret
; ++i
) {
1463 if (proto
[i
] == OBT_PROP_ATOM(WM_DELETE_WINDOW
))
1464 /* this means we can request the window to close */
1465 self
->delete_window
= TRUE
;
1466 else if (proto
[i
] == OBT_PROP_ATOM(WM_TAKE_FOCUS
))
1467 /* if this protocol is requested, then the window will be
1468 notified whenever we want it to receive focus */
1469 self
->focus_notify
= TRUE
;
1470 else if (proto
[i
] == OBT_PROP_ATOM(NET_WM_PING
))
1471 /* if this protocol is requested, then the window will allow
1472 pings to determine if it is still alive */
1475 else if (proto
[i
] == OBT_PROP_ATOM(NET_WM_SYNC_REQUEST
))
1476 /* if this protocol is requested, then resizing the
1477 window will be synchronized between the frame and the
1479 self
->sync_request
= TRUE
;
1487 void client_update_sync_request_counter(ObClient
*self
)
1491 if (OBT_PROP_GET32(self
->window
, NET_WM_SYNC_REQUEST_COUNTER
, CARDINAL
,&i
))
1493 self
->sync_counter
= i
;
1495 self
->sync_counter
= None
;
1499 static void client_get_colormap(ObClient
*self
)
1501 XWindowAttributes wa
;
1503 if (XGetWindowAttributes(obt_display
, self
->window
, &wa
))
1504 client_update_colormap(self
, wa
.colormap
);
1507 void client_update_colormap(ObClient
*self
, Colormap colormap
)
1509 if (colormap
== self
->colormap
) return;
1511 ob_debug("Setting client %s colormap: 0x%x", self
->title
, colormap
);
1513 if (client_focused(self
)) {
1514 screen_install_colormap(self
, FALSE
); /* uninstall old one */
1515 self
->colormap
= colormap
;
1516 screen_install_colormap(self
, FALSE
); /* install new one */
1518 self
->colormap
= colormap
;
1521 void client_update_normal_hints(ObClient
*self
)
1527 self
->min_ratio
= 0.0f
;
1528 self
->max_ratio
= 0.0f
;
1529 SIZE_SET(self
->size_inc
, 1, 1);
1530 SIZE_SET(self
->base_size
, 0, 0);
1531 SIZE_SET(self
->min_size
, 0, 0);
1532 SIZE_SET(self
->max_size
, G_MAXINT
, G_MAXINT
);
1534 /* get the hints from the window */
1535 if (XGetWMNormalHints(obt_display
, self
->window
, &size
, &ret
)) {
1536 /* normal windows can't request placement! har har
1537 if (!client_normal(self))
1539 self
->positioned
= (size
.flags
& (PPosition
|USPosition
));
1540 self
->sized
= (size
.flags
& (PSize
|USSize
));
1542 if (size
.flags
& PWinGravity
)
1543 self
->gravity
= size
.win_gravity
;
1545 if (size
.flags
& PAspect
) {
1546 if (size
.min_aspect
.y
)
1548 (gfloat
) size
.min_aspect
.x
/ size
.min_aspect
.y
;
1549 if (size
.max_aspect
.y
)
1551 (gfloat
) size
.max_aspect
.x
/ size
.max_aspect
.y
;
1554 if (size
.flags
& PMinSize
)
1555 SIZE_SET(self
->min_size
, size
.min_width
, size
.min_height
);
1557 if (size
.flags
& PMaxSize
)
1558 SIZE_SET(self
->max_size
, size
.max_width
, size
.max_height
);
1560 if (size
.flags
& PBaseSize
)
1561 SIZE_SET(self
->base_size
, size
.base_width
, size
.base_height
);
1563 if (size
.flags
& PResizeInc
&& size
.width_inc
&& size
.height_inc
)
1564 SIZE_SET(self
->size_inc
, size
.width_inc
, size
.height_inc
);
1566 ob_debug("Normal hints: min size (%d %d) max size (%d %d)",
1567 self
->min_size
.width
, self
->min_size
.height
,
1568 self
->max_size
.width
, self
->max_size
.height
);
1569 ob_debug("size inc (%d %d) base size (%d %d)",
1570 self
->size_inc
.width
, self
->size_inc
.height
,
1571 self
->base_size
.width
, self
->base_size
.height
);
1574 ob_debug("Normal hints: not set");
1577 void client_setup_decor_and_functions(ObClient
*self
, gboolean reconfig
)
1579 /* start with everything (cept fullscreen) */
1581 (OB_FRAME_DECOR_TITLEBAR
|
1582 OB_FRAME_DECOR_HANDLE
|
1583 OB_FRAME_DECOR_GRIPS
|
1584 OB_FRAME_DECOR_BORDER
|
1585 OB_FRAME_DECOR_ICON
|
1586 OB_FRAME_DECOR_ALLDESKTOPS
|
1587 OB_FRAME_DECOR_ICONIFY
|
1588 OB_FRAME_DECOR_MAXIMIZE
|
1589 OB_FRAME_DECOR_SHADE
|
1590 OB_FRAME_DECOR_CLOSE
);
1592 (OB_CLIENT_FUNC_RESIZE
|
1593 OB_CLIENT_FUNC_MOVE
|
1594 OB_CLIENT_FUNC_ICONIFY
|
1595 OB_CLIENT_FUNC_MAXIMIZE
|
1596 OB_CLIENT_FUNC_SHADE
|
1597 OB_CLIENT_FUNC_CLOSE
|
1598 OB_CLIENT_FUNC_BELOW
|
1599 OB_CLIENT_FUNC_ABOVE
|
1600 OB_CLIENT_FUNC_UNDECORATE
);
1602 if (!(self
->min_size
.width
< self
->max_size
.width
||
1603 self
->min_size
.height
< self
->max_size
.height
))
1604 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
1606 switch (self
->type
) {
1607 case OB_CLIENT_TYPE_NORMAL
:
1608 /* normal windows retain all of the possible decorations and
1609 functionality, and can be fullscreen */
1610 self
->functions
|= OB_CLIENT_FUNC_FULLSCREEN
;
1613 case OB_CLIENT_TYPE_DIALOG
:
1614 /* sometimes apps make dialog windows fullscreen for some reason (for
1615 e.g. kpdf does this..) */
1616 self
->functions
|= OB_CLIENT_FUNC_FULLSCREEN
;
1619 case OB_CLIENT_TYPE_UTILITY
:
1620 /* these windows don't have anything added or removed by default */
1623 case OB_CLIENT_TYPE_MENU
:
1624 case OB_CLIENT_TYPE_TOOLBAR
:
1625 /* these windows can't iconify or maximize */
1626 self
->decorations
&= ~(OB_FRAME_DECOR_ICONIFY
|
1627 OB_FRAME_DECOR_MAXIMIZE
);
1628 self
->functions
&= ~(OB_CLIENT_FUNC_ICONIFY
|
1629 OB_CLIENT_FUNC_MAXIMIZE
);
1632 case OB_CLIENT_TYPE_SPLASH
:
1633 /* these don't get get any decorations, and the only thing you can
1634 do with them is move them */
1635 self
->decorations
= 0;
1636 self
->functions
= OB_CLIENT_FUNC_MOVE
;
1639 case OB_CLIENT_TYPE_DESKTOP
:
1640 /* these windows are not manipulated by the window manager */
1641 self
->decorations
= 0;
1642 self
->functions
= 0;
1645 case OB_CLIENT_TYPE_DOCK
:
1646 /* these windows are not manipulated by the window manager, but they
1647 can set below layer which has a special meaning */
1648 self
->decorations
= 0;
1649 self
->functions
= OB_CLIENT_FUNC_BELOW
;
1653 /* Mwm Hints are applied subtractively to what has already been chosen for
1654 decor and functionality */
1655 if (self
->mwmhints
.flags
& OB_MWM_FLAG_DECORATIONS
) {
1656 if (! (self
->mwmhints
.decorations
& OB_MWM_DECOR_ALL
)) {
1657 if (! ((self
->mwmhints
.decorations
& OB_MWM_DECOR_HANDLE
) ||
1658 (self
->mwmhints
.decorations
& OB_MWM_DECOR_TITLE
)))
1660 /* if the mwm hints request no handle or title, then all
1661 decorations are disabled, but keep the border if that's
1663 if (self
->mwmhints
.decorations
& OB_MWM_DECOR_BORDER
)
1664 self
->decorations
= OB_FRAME_DECOR_BORDER
;
1666 self
->decorations
= 0;
1671 if (self
->mwmhints
.flags
& OB_MWM_FLAG_FUNCTIONS
) {
1672 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_ALL
)) {
1673 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_RESIZE
))
1674 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
1675 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_MOVE
))
1676 self
->functions
&= ~OB_CLIENT_FUNC_MOVE
;
1677 /* dont let mwm hints kill any buttons
1678 if (! (self->mwmhints.functions & OB_MWM_FUNC_ICONIFY))
1679 self->functions &= ~OB_CLIENT_FUNC_ICONIFY;
1680 if (! (self->mwmhints.functions & OB_MWM_FUNC_MAXIMIZE))
1681 self->functions &= ~OB_CLIENT_FUNC_MAXIMIZE;
1683 /* dont let mwm hints kill the close button
1684 if (! (self->mwmhints.functions & MwmFunc_Close))
1685 self->functions &= ~OB_CLIENT_FUNC_CLOSE; */
1689 if (!(self
->functions
& OB_CLIENT_FUNC_SHADE
))
1690 self
->decorations
&= ~OB_FRAME_DECOR_SHADE
;
1691 if (!(self
->functions
& OB_CLIENT_FUNC_ICONIFY
))
1692 self
->decorations
&= ~OB_FRAME_DECOR_ICONIFY
;
1693 if (!(self
->functions
& OB_CLIENT_FUNC_RESIZE
))
1694 self
->decorations
&= ~(OB_FRAME_DECOR_GRIPS
| OB_FRAME_DECOR_HANDLE
);
1696 /* can't maximize without moving/resizing */
1697 if (!((self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) &&
1698 (self
->functions
& OB_CLIENT_FUNC_MOVE
) &&
1699 (self
->functions
& OB_CLIENT_FUNC_RESIZE
))) {
1700 self
->functions
&= ~OB_CLIENT_FUNC_MAXIMIZE
;
1701 self
->decorations
&= ~OB_FRAME_DECOR_MAXIMIZE
;
1704 if (self
->max_horz
&& self
->max_vert
) {
1705 /* you can't resize fully maximized windows */
1706 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
1707 /* kill the handle on fully maxed windows */
1708 self
->decorations
&= ~(OB_FRAME_DECOR_HANDLE
| OB_FRAME_DECOR_GRIPS
);
1711 /* If there are no decorations to remove, don't allow the user to try
1713 if (self
->decorations
== 0)
1714 self
->functions
&= ~OB_CLIENT_FUNC_UNDECORATE
;
1716 /* finally, the user can have requested no decorations, which overrides
1717 everything (but doesnt give it a border if it doesnt have one) */
1718 if (self
->undecorated
)
1719 self
->decorations
= 0;
1721 /* if we don't have a titlebar, then we cannot shade! */
1722 if (!(self
->decorations
& OB_FRAME_DECOR_TITLEBAR
))
1723 self
->functions
&= ~OB_CLIENT_FUNC_SHADE
;
1725 /* now we need to check against rules for the client's current state */
1726 if (self
->fullscreen
) {
1727 self
->functions
&= (OB_CLIENT_FUNC_CLOSE
|
1728 OB_CLIENT_FUNC_FULLSCREEN
|
1729 OB_CLIENT_FUNC_ICONIFY
);
1730 self
->decorations
= 0;
1733 client_change_allowed_actions(self
);
1736 /* force reconfigure to make sure decorations are updated */
1737 client_reconfigure(self
, TRUE
);
1740 static void client_change_allowed_actions(ObClient
*self
)
1745 /* desktop windows are kept on all desktops */
1746 if (self
->type
!= OB_CLIENT_TYPE_DESKTOP
)
1747 actions
[num
++] = OBT_PROP_ATOM(NET_WM_ACTION_CHANGE_DESKTOP
);
1749 if (self
->functions
& OB_CLIENT_FUNC_SHADE
)
1750 actions
[num
++] = OBT_PROP_ATOM(NET_WM_ACTION_SHADE
);
1751 if (self
->functions
& OB_CLIENT_FUNC_CLOSE
)
1752 actions
[num
++] = OBT_PROP_ATOM(NET_WM_ACTION_CLOSE
);
1753 if (self
->functions
& OB_CLIENT_FUNC_MOVE
)
1754 actions
[num
++] = OBT_PROP_ATOM(NET_WM_ACTION_MOVE
);
1755 if (self
->functions
& OB_CLIENT_FUNC_ICONIFY
)
1756 actions
[num
++] = OBT_PROP_ATOM(NET_WM_ACTION_MINIMIZE
);
1757 if (self
->functions
& OB_CLIENT_FUNC_RESIZE
)
1758 actions
[num
++] = OBT_PROP_ATOM(NET_WM_ACTION_RESIZE
);
1759 if (self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
)
1760 actions
[num
++] = OBT_PROP_ATOM(NET_WM_ACTION_FULLSCREEN
);
1761 if (self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) {
1762 actions
[num
++] = OBT_PROP_ATOM(NET_WM_ACTION_MAXIMIZE_HORZ
);
1763 actions
[num
++] = OBT_PROP_ATOM(NET_WM_ACTION_MAXIMIZE_VERT
);
1765 if (self
->functions
& OB_CLIENT_FUNC_ABOVE
)
1766 actions
[num
++] = OBT_PROP_ATOM(NET_WM_ACTION_ABOVE
);
1767 if (self
->functions
& OB_CLIENT_FUNC_BELOW
)
1768 actions
[num
++] = OBT_PROP_ATOM(NET_WM_ACTION_BELOW
);
1769 if (self
->functions
& OB_CLIENT_FUNC_UNDECORATE
)
1770 actions
[num
++] = OBT_PROP_ATOM(OB_WM_ACTION_UNDECORATE
);
1772 OBT_PROP_SETA32(self
->window
, NET_WM_ALLOWED_ACTIONS
, ATOM
, actions
, num
);
1774 /* make sure the window isn't breaking any rules now
1776 don't check ICONIFY here. just cuz a window can't iconify doesnt mean
1777 it can't be iconified with its parent
1780 if (!(self
->functions
& OB_CLIENT_FUNC_SHADE
) && self
->shaded
) {
1781 if (self
->frame
) client_shade(self
, FALSE
);
1782 else self
->shaded
= FALSE
;
1784 if (!(self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
) && self
->fullscreen
) {
1785 if (self
->frame
) client_fullscreen(self
, FALSE
);
1786 else self
->fullscreen
= FALSE
;
1788 if (!(self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) && (self
->max_horz
||
1790 if (self
->frame
) client_maximize(self
, FALSE
, 0);
1791 else self
->max_vert
= self
->max_horz
= FALSE
;
1795 void client_update_wmhints(ObClient
*self
)
1799 /* assume a window takes input if it doesnt specify */
1800 self
->can_focus
= TRUE
;
1802 if ((hints
= XGetWMHints(obt_display
, self
->window
)) != NULL
) {
1805 if (hints
->flags
& InputHint
)
1806 self
->can_focus
= hints
->input
;
1808 /* only do this when first managing the window *AND* when we aren't
1810 if (ob_state() != OB_STATE_STARTING
&& self
->frame
== NULL
)
1811 if (hints
->flags
& StateHint
)
1812 self
->iconic
= hints
->initial_state
== IconicState
;
1815 self
->urgent
= (hints
->flags
& XUrgencyHint
);
1816 if (self
->urgent
&& !ur
)
1817 client_hilite(self
, TRUE
);
1818 else if (!self
->urgent
&& ur
&& self
->demands_attention
)
1819 client_hilite(self
, FALSE
);
1821 if (!(hints
->flags
& WindowGroupHint
))
1822 hints
->window_group
= None
;
1824 /* did the group state change? */
1825 if (hints
->window_group
!=
1826 (self
->group
? self
->group
->leader
: None
))
1828 ObGroup
*oldgroup
= self
->group
;
1830 /* remove from the old group if there was one */
1831 if (self
->group
!= NULL
) {
1832 group_remove(self
->group
, self
);
1836 /* add ourself to the group if we have one */
1837 if (hints
->window_group
!= None
) {
1838 self
->group
= group_add(hints
->window_group
, self
);
1841 /* Put ourselves into the new group's transient tree, and remove
1842 ourselves from the old group's */
1843 client_update_transient_tree(self
, oldgroup
, self
->group
,
1844 self
->transient_for_group
,
1845 self
->transient_for_group
,
1846 client_direct_parent(self
),
1847 client_direct_parent(self
));
1849 /* Lastly, being in a group, or not, can change if the window is
1850 transient for anything.
1852 The logic for this is:
1853 self->transient = TRUE always if the window wants to be
1854 transient for something, even if transient_for was NULL because
1855 it wasn't in a group before.
1857 If parents was NULL and oldgroup was NULL we can assume
1858 that when we add the new group, it will become transient for
1861 If transient_for_group is TRUE, then it must have already
1862 had a group. If it is getting a new group, the above call to
1863 client_update_transient_tree has already taken care of
1864 everything ! If it is losing all group status then it will
1865 no longer be transient for anything and that needs to be
1868 if (self
->transient
&&
1869 ((self
->parents
== NULL
&& oldgroup
== NULL
) ||
1870 (self
->transient_for_group
&& !self
->group
)))
1871 client_update_transient_for(self
);
1874 /* the WM_HINTS can contain an icon */
1875 if (hints
->flags
& IconPixmapHint
)
1876 client_update_icons(self
);
1882 void client_update_title(ObClient
*self
)
1885 gchar
*visible
= NULL
;
1887 g_free(self
->title
);
1890 if (!OBT_PROP_GETS(self
->window
, NET_WM_NAME
, utf8
, &data
)) {
1891 /* try old x stuff */
1892 if (!(OBT_PROP_GETS(self
->window
, WM_NAME
, locale
, &data
)
1893 || OBT_PROP_GETS(self
->window
, WM_NAME
, utf8
, &data
))) {
1894 if (self
->transient
) {
1896 GNOME alert windows are not given titles:
1897 http://developer.gnome.org/projects/gup/hig/draft_hig_new/windows-alert.html
1899 data
= g_strdup("");
1901 data
= g_strdup("Unnamed Window");
1905 if (self
->client_machine
) {
1906 visible
= g_strdup_printf("%s (%s)", data
, self
->client_machine
);
1911 if (self
->not_responding
) {
1913 if (self
->close_tried_term
)
1914 visible
= g_strdup_printf("%s - [%s]", data
, _("Killing..."));
1916 visible
= g_strdup_printf("%s - [%s]", data
, _("Not Responding"));
1920 OBT_PROP_SETS(self
->window
, NET_WM_VISIBLE_NAME
, utf8
, visible
);
1921 self
->title
= visible
;
1924 frame_adjust_title(self
->frame
);
1926 /* update the icon title */
1928 g_free(self
->icon_title
);
1931 if (!OBT_PROP_GETS(self
->window
, NET_WM_ICON_NAME
, utf8
, &data
))
1932 /* try old x stuff */
1933 if (!(OBT_PROP_GETS(self
->window
, WM_ICON_NAME
, locale
, &data
) ||
1934 OBT_PROP_GETS(self
->window
, WM_ICON_NAME
, utf8
, &data
)))
1935 data
= g_strdup(self
->title
);
1937 if (self
->client_machine
) {
1938 visible
= g_strdup_printf("%s (%s)", data
, self
->client_machine
);
1943 if (self
->not_responding
) {
1945 if (self
->close_tried_term
)
1946 visible
= g_strdup_printf("%s - [%s]", data
, _("Killing..."));
1948 visible
= g_strdup_printf("%s - [%s]", data
, _("Not Responding"));
1952 OBT_PROP_SETS(self
->window
, NET_WM_VISIBLE_ICON_NAME
, utf8
, visible
);
1953 self
->icon_title
= visible
;
1956 void client_update_strut(ObClient
*self
)
1960 gboolean got
= FALSE
;
1963 if (OBT_PROP_GETA32(self
->window
, NET_WM_STRUT_PARTIAL
, CARDINAL
,
1968 STRUT_PARTIAL_SET(strut
,
1969 data
[0], data
[2], data
[1], data
[3],
1970 data
[4], data
[5], data
[8], data
[9],
1971 data
[6], data
[7], data
[10], data
[11]);
1977 OBT_PROP_GETA32(self
->window
, NET_WM_STRUT
, CARDINAL
, &data
, &num
)) {
1983 /* use the screen's width/height */
1984 a
= screen_physical_area_all_monitors();
1986 STRUT_PARTIAL_SET(strut
,
1987 data
[0], data
[2], data
[1], data
[3],
1988 a
->y
, a
->y
+ a
->height
- 1,
1989 a
->x
, a
->x
+ a
->width
- 1,
1990 a
->y
, a
->y
+ a
->height
- 1,
1991 a
->x
, a
->x
+ a
->width
- 1);
1998 STRUT_PARTIAL_SET(strut
, 0, 0, 0, 0,
1999 0, 0, 0, 0, 0, 0, 0, 0);
2001 if (!STRUT_EQUAL(strut
, self
->strut
)) {
2002 self
->strut
= strut
;
2004 /* updating here is pointless while we're being mapped cuz we're not in
2005 the client list yet */
2007 screen_update_areas();
2011 /* Avoid storing icons above this size if possible */
2012 #define AVOID_ABOVE 64
2014 void client_update_icons(ObClient
*self
)
2019 guint num_seen
; /* number of icons present */
2020 guint num_small_seen
; /* number of icons small enough present */
2021 guint smallest
, smallest_area
;
2023 for (i
= 0; i
< self
->nicons
; ++i
)
2024 g_free(self
->icons
[i
].data
);
2025 if (self
->nicons
> 0)
2026 g_free(self
->icons
);
2029 if (OBT_PROP_GETA32(self
->window
, NET_WM_ICON
, CARDINAL
, &data
, &num
)) {
2030 /* figure out how many valid icons are in here */
2032 num_seen
= num_small_seen
= 0;
2033 smallest
= smallest_area
= 0;
2039 /* watch for it being too small for the specified size, or for
2040 zero sized icons. */
2041 if (i
> num
|| w
== 0 || h
== 0) break;
2043 if (!smallest_area
|| w
*h
< smallest_area
) {
2044 smallest
= num_seen
;
2045 smallest_area
= w
*h
;
2048 if (w
<= AVOID_ABOVE
&& h
<= AVOID_ABOVE
)
2051 if (num_small_seen
> 0)
2052 self
->nicons
= num_small_seen
;
2056 self
->icons
= g_new(ObClientIcon
, self
->nicons
);
2058 /* store the icons */
2060 for (j
= 0; j
< self
->nicons
;) {
2063 w
= self
->icons
[j
].width
= data
[i
++];
2064 h
= self
->icons
[j
].height
= data
[i
++];
2066 /* if there are some icons smaller than the threshold, we're
2067 skipping all the ones above */
2068 if (num_small_seen
> 0) {
2069 if (w
> AVOID_ABOVE
|| h
> AVOID_ABOVE
) {
2074 /* if there were no icons smaller than the threshold, then we are
2075 only taking the smallest available one we saw */
2076 else if (j
!= smallest
) {
2081 self
->icons
[j
].data
= g_new(RrPixel32
, w
* h
);
2082 for (x
= 0, y
= 0, t
= 0; t
< w
* h
; ++t
, ++x
, ++i
) {
2087 self
->icons
[j
].data
[t
] =
2088 (((data
[i
] >> 24) & 0xff) << RrDefaultAlphaOffset
) +
2089 (((data
[i
] >> 16) & 0xff) << RrDefaultRedOffset
) +
2090 (((data
[i
] >> 8) & 0xff) << RrDefaultGreenOffset
) +
2091 (((data
[i
] >> 0) & 0xff) << RrDefaultBlueOffset
);
2102 if ((hints
= XGetWMHints(obt_display
, self
->window
))) {
2103 if (hints
->flags
& IconPixmapHint
) {
2105 self
->icons
= g_new(ObClientIcon
, self
->nicons
);
2106 obt_display_ignore_errors(TRUE
);
2107 if (!RrPixmapToRGBA(ob_rr_inst
,
2109 (hints
->flags
& IconMaskHint
?
2110 hints
->icon_mask
: None
),
2111 &self
->icons
[0].width
,
2112 &self
->icons
[0].height
,
2113 &self
->icons
[0].data
))
2115 g_free(self
->icons
);
2118 obt_display_ignore_errors(FALSE
);
2124 /* set the default icon onto the window
2125 in theory, this could be a race, but if a window doesn't set an icon
2126 or removes it entirely, it's not very likely it is going to set one
2127 right away afterwards
2129 if it has parents, then one of them will have an icon already
2131 if (self
->nicons
== 0 && !self
->parents
) {
2132 RrPixel32
*icon
= ob_rr_theme
->def_win_icon
;
2135 data
= g_new(gulong
, 48*48+2);
2136 data
[0] = data
[1] = 48;
2137 for (i
= 0; i
< 48*48; ++i
)
2138 data
[i
+2] = (((icon
[i
] >> RrDefaultAlphaOffset
) & 0xff) << 24) +
2139 (((icon
[i
] >> RrDefaultRedOffset
) & 0xff) << 16) +
2140 (((icon
[i
] >> RrDefaultGreenOffset
) & 0xff) << 8) +
2141 (((icon
[i
] >> RrDefaultBlueOffset
) & 0xff) << 0);
2142 OBT_PROP_SETA32(self
->window
, NET_WM_ICON
, CARDINAL
, data
, 48*48+2);
2144 } else if (self
->frame
)
2145 /* don't draw the icon empty if we're just setting one now anyways,
2146 we'll get the property change any second */
2147 frame_adjust_icon(self
->frame
);
2150 void client_update_icon_geometry(ObClient
*self
)
2155 RECT_SET(self
->icon_geometry
, 0, 0, 0, 0);
2157 if (OBT_PROP_GETA32(self
->window
, NET_WM_ICON_GEOMETRY
, CARDINAL
,
2161 /* don't let them set it with an area < 0 */
2162 RECT_SET(self
->icon_geometry
, data
[0], data
[1],
2163 MAX(data
[2],0), MAX(data
[3],0));
2168 static void client_get_session_ids(ObClient
*self
)
2175 if (!OBT_PROP_GET32(self
->window
, WM_CLIENT_LEADER
, WINDOW
, &leader
))
2178 /* get the SM_CLIENT_ID */
2181 got
= OBT_PROP_GETS(leader
, SM_CLIENT_ID
, locale
, &self
->sm_client_id
);
2183 OBT_PROP_GETS(self
->window
, SM_CLIENT_ID
, locale
, &self
->sm_client_id
);
2185 /* get the WM_CLASS (name and class). make them "" if they are not
2189 got
= OBT_PROP_GETSS(leader
, WM_CLASS
, locale
, &ss
);
2191 got
= OBT_PROP_GETSS(self
->window
, WM_CLASS
, locale
, &ss
);
2195 self
->name
= g_strdup(ss
[0]);
2197 self
->class = g_strdup(ss
[1]);
2202 if (self
->name
== NULL
) self
->name
= g_strdup("");
2203 if (self
->class == NULL
) self
->class = g_strdup("");
2205 /* get the WM_WINDOW_ROLE. make it "" if it is not provided */
2208 got
= OBT_PROP_GETS(leader
, WM_WINDOW_ROLE
, locale
, &s
);
2210 got
= OBT_PROP_GETS(self
->window
, WM_WINDOW_ROLE
, locale
, &s
);
2215 self
->role
= g_strdup("");
2217 /* get the WM_COMMAND */
2221 got
= OBT_PROP_GETSS(leader
, WM_COMMAND
, locale
, &ss
);
2223 got
= OBT_PROP_GETSS(self
->window
, WM_COMMAND
, locale
, &ss
);
2226 /* merge/mash them all together */
2227 gchar
*merge
= NULL
;
2230 for (i
= 0; ss
[i
]; ++i
) {
2233 merge
= g_strconcat(merge
, ss
[i
], NULL
);
2235 merge
= g_strconcat(ss
[i
], NULL
);
2240 self
->wm_command
= merge
;
2243 /* get the WM_CLIENT_MACHINE */
2246 got
= OBT_PROP_GETS(leader
, WM_CLIENT_MACHINE
, locale
, &s
);
2248 got
= OBT_PROP_GETS(self
->window
, WM_CLIENT_MACHINE
, locale
, &s
);
2251 gchar localhost
[128];
2254 gethostname(localhost
, 127);
2255 localhost
[127] = '\0';
2256 if (strcmp(localhost
, s
) != 0)
2257 self
->client_machine
= s
;
2261 /* see if it has the PID set too (the PID requires that the
2262 WM_CLIENT_MACHINE be set) */
2263 if (OBT_PROP_GET32(self
->window
, NET_WM_PID
, CARDINAL
, &pid
))
2268 static void client_change_wm_state(ObClient
*self
)
2273 old
= self
->wmstate
;
2275 if (self
->shaded
|| self
->iconic
||
2276 (self
->desktop
!= DESKTOP_ALL
&& self
->desktop
!= screen_desktop
))
2278 self
->wmstate
= IconicState
;
2280 self
->wmstate
= NormalState
;
2282 if (old
!= self
->wmstate
) {
2283 OBT_PROP_MSG(ob_screen
, self
->window
, KDE_WM_CHANGE_STATE
,
2284 self
->wmstate
, 1, 0, 0, 0);
2286 state
[0] = self
->wmstate
;
2288 OBT_PROP_SETA32(self
->window
, WM_STATE
, WM_STATE
, state
, 2);
2292 static void client_change_state(ObClient
*self
)
2294 gulong netstate
[12];
2299 netstate
[num
++] = OBT_PROP_ATOM(NET_WM_STATE_MODAL
);
2301 netstate
[num
++] = OBT_PROP_ATOM(NET_WM_STATE_SHADED
);
2303 netstate
[num
++] = OBT_PROP_ATOM(NET_WM_STATE_HIDDEN
);
2304 if (self
->skip_taskbar
)
2305 netstate
[num
++] = OBT_PROP_ATOM(NET_WM_STATE_SKIP_TASKBAR
);
2306 if (self
->skip_pager
)
2307 netstate
[num
++] = OBT_PROP_ATOM(NET_WM_STATE_SKIP_PAGER
);
2308 if (self
->fullscreen
)
2309 netstate
[num
++] = OBT_PROP_ATOM(NET_WM_STATE_FULLSCREEN
);
2311 netstate
[num
++] = OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_VERT
);
2313 netstate
[num
++] = OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_HORZ
);
2315 netstate
[num
++] = OBT_PROP_ATOM(NET_WM_STATE_ABOVE
);
2317 netstate
[num
++] = OBT_PROP_ATOM(NET_WM_STATE_BELOW
);
2318 if (self
->demands_attention
)
2319 netstate
[num
++] = OBT_PROP_ATOM(NET_WM_STATE_DEMANDS_ATTENTION
);
2320 if (self
->undecorated
)
2321 netstate
[num
++] = OBT_PROP_ATOM(OB_WM_STATE_UNDECORATED
);
2322 OBT_PROP_SETA32(self
->window
, NET_WM_STATE
, ATOM
, netstate
, num
);
2325 frame_adjust_state(self
->frame
);
2328 ObClient
*client_search_focus_tree(ObClient
*self
)
2333 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
2334 if (client_focused(it
->data
)) return it
->data
;
2335 if ((ret
= client_search_focus_tree(it
->data
))) return ret
;
2340 ObClient
*client_search_focus_tree_full(ObClient
*self
)
2342 if (self
->parents
) {
2345 for (it
= self
->parents
; it
; it
= g_slist_next(it
)) {
2346 ObClient
*c
= it
->data
;
2347 if ((c
= client_search_focus_tree_full(it
->data
))) return c
;
2353 /* this function checks the whole tree, the client_search_focus_tree
2354 does not, so we need to check this window */
2355 if (client_focused(self
))
2357 return client_search_focus_tree(self
);
2361 ObClient
*client_search_focus_group_full(ObClient
*self
)
2366 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
2367 ObClient
*c
= it
->data
;
2369 if (client_focused(c
)) return c
;
2370 if ((c
= client_search_focus_tree(it
->data
))) return c
;
2373 if (client_focused(self
)) return self
;
2377 gboolean
client_has_parent(ObClient
*self
)
2379 return self
->parents
!= NULL
;
2382 static ObStackingLayer
calc_layer(ObClient
*self
)
2387 monitor
= screen_physical_area_monitor(client_monitor(self
));
2389 if (self
->type
== OB_CLIENT_TYPE_DESKTOP
)
2390 l
= OB_STACKING_LAYER_DESKTOP
;
2391 else if (self
->type
== OB_CLIENT_TYPE_DOCK
) {
2392 if (self
->below
) l
= OB_STACKING_LAYER_NORMAL
;
2393 else l
= OB_STACKING_LAYER_ABOVE
;
2395 else if ((self
->fullscreen
||
2396 /* No decorations and fills the monitor = oldskool fullscreen.
2397 But not for maximized windows.
2399 (self
->decorations
== 0 &&
2400 !(self
->max_horz
&& self
->max_vert
) &&
2401 RECT_EQUAL(self
->area
, *monitor
))) &&
2402 /* you are fullscreen while you or your children are focused.. */
2403 (client_focused(self
) || client_search_focus_tree(self
) ||
2404 /* you can be fullscreen if you're on another desktop */
2405 (self
->desktop
!= screen_desktop
&&
2406 self
->desktop
!= DESKTOP_ALL
) ||
2407 /* and you can also be fullscreen if the focused client is on
2408 another monitor, or nothing else is focused */
2410 client_monitor(focus_client
) != client_monitor(self
))))
2411 l
= OB_STACKING_LAYER_FULLSCREEN
;
2412 else if (self
->above
) l
= OB_STACKING_LAYER_ABOVE
;
2413 else if (self
->below
) l
= OB_STACKING_LAYER_BELOW
;
2414 else l
= OB_STACKING_LAYER_NORMAL
;
2421 static void client_calc_layer_recursive(ObClient
*self
, ObClient
*orig
,
2422 ObStackingLayer min
)
2424 ObStackingLayer old
, own
;
2428 own
= calc_layer(self
);
2429 self
->layer
= MAX(own
, min
);
2431 if (self
->layer
!= old
) {
2432 stacking_remove(CLIENT_AS_WINDOW(self
));
2433 stacking_add_nonintrusive(CLIENT_AS_WINDOW(self
));
2436 /* we've been restacked */
2437 self
->visited
= TRUE
;
2439 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
2440 client_calc_layer_recursive(it
->data
, orig
,
2444 static void client_calc_layer_internal(ObClient
*self
)
2448 /* transients take on the layer of their parents */
2449 sit
= client_search_all_top_parents(self
);
2451 for (; sit
; sit
= g_slist_next(sit
))
2452 client_calc_layer_recursive(sit
->data
, self
, 0);
2455 void client_calc_layer(ObClient
*self
)
2459 /* skip over stuff above fullscreen layer */
2460 for (it
= stacking_list
; it
; it
= g_list_next(it
))
2461 if (window_layer(it
->data
) <= OB_STACKING_LAYER_FULLSCREEN
) break;
2463 /* find the windows in the fullscreen layer, and mark them not-visited */
2464 for (; it
; it
= g_list_next(it
)) {
2465 if (window_layer(it
->data
) < OB_STACKING_LAYER_FULLSCREEN
) break;
2466 else if (WINDOW_IS_CLIENT(it
->data
))
2467 WINDOW_AS_CLIENT(it
->data
)->visited
= FALSE
;
2470 client_calc_layer_internal(self
);
2472 /* skip over stuff above fullscreen layer */
2473 for (it
= stacking_list
; it
; it
= g_list_next(it
))
2474 if (window_layer(it
->data
) <= OB_STACKING_LAYER_FULLSCREEN
) break;
2476 /* now recalc any windows in the fullscreen layer which have not
2477 had their layer recalced already */
2478 for (; it
; it
= g_list_next(it
)) {
2479 if (window_layer(it
->data
) < OB_STACKING_LAYER_FULLSCREEN
) break;
2480 else if (WINDOW_IS_CLIENT(it
->data
) &&
2481 !WINDOW_AS_CLIENT(it
->data
)->visited
)
2482 client_calc_layer_internal(it
->data
);
2486 gboolean
client_should_show(ObClient
*self
)
2490 if (client_normal(self
) && screen_showing_desktop
)
2492 if (self
->desktop
== screen_desktop
|| self
->desktop
== DESKTOP_ALL
)
2498 gboolean
client_show(ObClient
*self
)
2500 gboolean show
= FALSE
;
2502 if (client_should_show(self
)) {
2503 frame_show(self
->frame
);
2506 /* According to the ICCCM (sec 4.1.3.1) when a window is not visible,
2507 it needs to be in IconicState. This includes when it is on another
2510 client_change_wm_state(self
);
2515 gboolean
client_hide(ObClient
*self
)
2517 gboolean hide
= FALSE
;
2519 if (!client_should_show(self
)) {
2520 if (self
== focus_client
) {
2521 /* if there is a grab going on, then we need to cancel it. if we
2522 move focus during the grab, applications will get
2523 NotifyWhileGrabbed events and ignore them !
2525 actions should not rely on being able to move focus during an
2528 event_cancel_all_key_grabs();
2531 /* We don't need to ignore enter events here.
2532 The window can hide/iconify in 3 different ways:
2533 1 - through an x message. in this case we ignore all enter events
2534 caused by responding to the x message (unless underMouse)
2535 2 - by a keyboard action. in this case we ignore all enter events
2536 caused by the action
2537 3 - by a mouse action. in this case they are doing stuff with the
2538 mouse and focus _should_ move.
2540 Also in action_end, we simulate an enter event that can't be ignored
2541 so trying to ignore them is futile in case 3 anyways
2544 frame_hide(self
->frame
);
2547 /* According to the ICCCM (sec 4.1.3.1) when a window is not visible,
2548 it needs to be in IconicState. This includes when it is on another
2551 client_change_wm_state(self
);
2556 void client_showhide(ObClient
*self
)
2558 if (!client_show(self
))
2562 gboolean
client_normal(ObClient
*self
) {
2563 return ! (self
->type
== OB_CLIENT_TYPE_DESKTOP
||
2564 self
->type
== OB_CLIENT_TYPE_DOCK
||
2565 self
->type
== OB_CLIENT_TYPE_SPLASH
);
2568 gboolean
client_helper(ObClient
*self
)
2570 return (self
->type
== OB_CLIENT_TYPE_UTILITY
||
2571 self
->type
== OB_CLIENT_TYPE_MENU
||
2572 self
->type
== OB_CLIENT_TYPE_TOOLBAR
);
2575 gboolean
client_mouse_focusable(ObClient
*self
)
2577 return !(self
->type
== OB_CLIENT_TYPE_MENU
||
2578 self
->type
== OB_CLIENT_TYPE_TOOLBAR
||
2579 self
->type
== OB_CLIENT_TYPE_SPLASH
||
2580 self
->type
== OB_CLIENT_TYPE_DOCK
);
2583 gboolean
client_enter_focusable(ObClient
*self
)
2585 /* you can focus desktops but it shouldn't on enter */
2586 return (client_mouse_focusable(self
) &&
2587 self
->type
!= OB_CLIENT_TYPE_DESKTOP
);
2591 static void client_apply_startup_state(ObClient
*self
,
2592 gint x
, gint y
, gint w
, gint h
)
2594 /* save the states that we are going to apply */
2595 gboolean iconic
= self
->iconic
;
2596 gboolean fullscreen
= self
->fullscreen
;
2597 gboolean undecorated
= self
->undecorated
;
2598 gboolean shaded
= self
->shaded
;
2599 gboolean demands_attention
= self
->demands_attention
;
2600 gboolean max_horz
= self
->max_horz
;
2601 gboolean max_vert
= self
->max_vert
;
2605 /* turn them all off in the client, so they won't affect the window
2607 self
->iconic
= self
->fullscreen
= self
->undecorated
= self
->shaded
=
2608 self
->demands_attention
= self
->max_horz
= self
->max_vert
= FALSE
;
2610 /* move the client to its placed position, or it it's already there,
2611 generate a ConfigureNotify telling the client where it is.
2613 do this after adjusting the frame. otherwise it gets all weird and
2614 clients don't work right
2616 do this before applying the states so they have the correct
2617 pre-max/pre-fullscreen values
2619 client_try_configure(self
, &x
, &y
, &w
, &h
, &l
, &l
, FALSE
);
2620 ob_debug("placed window 0x%x at %d, %d with size %d x %d",
2621 self
->window
, x
, y
, w
, h
);
2622 /* save the area, and make it where it should be for the premax stuff */
2623 oldarea
= self
->area
;
2624 RECT_SET(self
->area
, x
, y
, w
, h
);
2626 /* apply the states. these are in a carefully crafted order.. */
2629 client_iconify(self
, TRUE
, FALSE
, TRUE
);
2631 client_fullscreen(self
, TRUE
);
2633 client_set_undecorated(self
, TRUE
);
2635 client_shade(self
, TRUE
);
2636 if (demands_attention
)
2637 client_hilite(self
, TRUE
);
2639 if (max_vert
&& max_horz
)
2640 client_maximize(self
, TRUE
, 0);
2642 client_maximize(self
, TRUE
, 2);
2644 client_maximize(self
, TRUE
, 1);
2646 /* if the window hasn't been configured yet, then do so now, in fact the
2647 x,y,w,h may _not_ be the same as the area rect, which can end up
2648 meaning that the client isn't properly moved/resized by the fullscreen
2650 pho can cause this because it maps at size of the screen but not 0,0
2651 so openbox moves it on screen to 0,0 (thus x,y=0,0 and area.x,y don't).
2652 then fullscreen'ing makes it go to 0,0 which it thinks it already is at
2653 cuz thats where the pre-fullscreen will be. however the actual area is
2654 not, so this needs to be called even if we have fullscreened/maxed
2656 self
->area
= oldarea
;
2657 client_configure(self
, x
, y
, w
, h
, FALSE
, TRUE
, FALSE
);
2659 /* set the desktop hint, to make sure that it always exists */
2660 OBT_PROP_SET32(self
->window
, NET_WM_DESKTOP
, CARDINAL
, self
->desktop
);
2662 /* nothing to do for the other states:
2671 void client_gravity_resize_w(ObClient
*self
, gint
*x
, gint oldw
, gint neww
)
2673 /* these should be the current values. this is for when you're not moving,
2675 g_assert(*x
== self
->area
.x
);
2676 g_assert(oldw
== self
->area
.width
);
2679 switch (self
->gravity
) {
2681 case NorthWestGravity
:
2683 case SouthWestGravity
:
2690 *x
-= (neww
- oldw
) / 2;
2692 case NorthEastGravity
:
2694 case SouthEastGravity
:
2700 void client_gravity_resize_h(ObClient
*self
, gint
*y
, gint oldh
, gint newh
)
2702 /* these should be the current values. this is for when you're not moving,
2704 g_assert(*y
== self
->area
.y
);
2705 g_assert(oldh
== self
->area
.height
);
2708 switch (self
->gravity
) {
2710 case NorthWestGravity
:
2712 case NorthEastGravity
:
2719 *y
-= (newh
- oldh
) / 2;
2721 case SouthWestGravity
:
2723 case SouthEastGravity
:
2729 void client_try_configure(ObClient
*self
, gint
*x
, gint
*y
, gint
*w
, gint
*h
,
2730 gint
*logicalw
, gint
*logicalh
,
2733 Rect desired
= {*x
, *y
, *w
, *h
};
2734 frame_rect_to_frame(self
->frame
, &desired
);
2736 /* make the frame recalculate its dimentions n shit without changing
2737 anything visible for real, this way the constraints below can work with
2738 the updated frame dimensions. */
2739 frame_adjust_area(self
->frame
, FALSE
, TRUE
, TRUE
);
2741 /* gets the frame's position */
2742 frame_client_gravity(self
->frame
, x
, y
);
2744 /* these positions are frame positions, not client positions */
2746 /* set the size and position if fullscreen */
2747 if (self
->fullscreen
) {
2751 i
= screen_find_monitor(&desired
);
2752 a
= screen_physical_area_monitor(i
);
2759 user
= FALSE
; /* ignore if the client can't be moved/resized when it
2763 } else if (self
->max_horz
|| self
->max_vert
) {
2767 /* use all possible struts when maximizing to the full screen */
2768 i
= screen_find_monitor(&desired
);
2769 a
= screen_area(self
->desktop
, i
,
2770 (self
->max_horz
&& self
->max_vert
? NULL
: &desired
));
2772 /* set the size and position if maximized */
2773 if (self
->max_horz
) {
2775 *w
= a
->width
- self
->frame
->size
.left
- self
->frame
->size
.right
;
2777 if (self
->max_vert
) {
2779 *h
= a
->height
- self
->frame
->size
.top
- self
->frame
->size
.bottom
;
2782 user
= FALSE
; /* ignore if the client can't be moved/resized when it
2788 /* gets the client's position */
2789 frame_frame_gravity(self
->frame
, x
, y
);
2791 /* work within the prefered sizes given by the window */
2792 if (!(*w
== self
->area
.width
&& *h
== self
->area
.height
)) {
2793 gint basew
, baseh
, minw
, minh
;
2795 gfloat minratio
, maxratio
;
2797 incw
= self
->fullscreen
|| self
->max_horz
? 1 : self
->size_inc
.width
;
2798 inch
= self
->fullscreen
|| self
->max_vert
? 1 : self
->size_inc
.height
;
2799 minratio
= self
->fullscreen
|| (self
->max_horz
&& self
->max_vert
) ?
2800 0 : self
->min_ratio
;
2801 maxratio
= self
->fullscreen
|| (self
->max_horz
&& self
->max_vert
) ?
2802 0 : self
->max_ratio
;
2804 /* base size is substituted with min size if not specified */
2805 if (self
->base_size
.width
|| self
->base_size
.height
) {
2806 basew
= self
->base_size
.width
;
2807 baseh
= self
->base_size
.height
;
2809 basew
= self
->min_size
.width
;
2810 baseh
= self
->min_size
.height
;
2812 /* min size is substituted with base size if not specified */
2813 if (self
->min_size
.width
|| self
->min_size
.height
) {
2814 minw
= self
->min_size
.width
;
2815 minh
= self
->min_size
.height
;
2817 minw
= self
->base_size
.width
;
2818 minh
= self
->base_size
.height
;
2821 /* if this is a user-requested resize, then check against min/max
2824 /* smaller than min size or bigger than max size? */
2825 if (*w
> self
->max_size
.width
) *w
= self
->max_size
.width
;
2826 if (*w
< minw
) *w
= minw
;
2827 if (*h
> self
->max_size
.height
) *h
= self
->max_size
.height
;
2828 if (*h
< minh
) *h
= minh
;
2833 /* keep to the increments */
2837 /* you cannot resize to nothing */
2838 if (basew
+ *w
< 1) *w
= 1 - basew
;
2839 if (baseh
+ *h
< 1) *h
= 1 - baseh
;
2841 /* save the logical size */
2842 *logicalw
= incw
> 1 ? *w
: *w
+ basew
;
2843 *logicalh
= inch
> 1 ? *h
: *h
+ baseh
;
2851 /* adjust the height to match the width for the aspect ratios.
2852 for this, min size is not substituted for base size ever. */
2853 *w
-= self
->base_size
.width
;
2854 *h
-= self
->base_size
.height
;
2857 if (*h
* minratio
> *w
) {
2858 *h
= (gint
)(*w
/ minratio
);
2860 /* you cannot resize to nothing */
2863 *w
= (gint
)(*h
* minratio
);
2867 if (*h
* maxratio
< *w
) {
2868 *h
= (gint
)(*w
/ maxratio
);
2870 /* you cannot resize to nothing */
2873 *w
= (gint
)(*h
* minratio
);
2877 *w
+= self
->base_size
.width
;
2878 *h
+= self
->base_size
.height
;
2881 /* these override the above states! if you cant move you can't move! */
2883 if (!(self
->functions
& OB_CLIENT_FUNC_MOVE
)) {
2887 if (!(self
->functions
& OB_CLIENT_FUNC_RESIZE
)) {
2888 *w
= self
->area
.width
;
2889 *h
= self
->area
.height
;
2898 void client_configure(ObClient
*self
, gint x
, gint y
, gint w
, gint h
,
2899 gboolean user
, gboolean final
, gboolean force_reply
)
2903 gboolean send_resize_client
;
2904 gboolean moved
= FALSE
, resized
= FALSE
, rootmoved
= FALSE
;
2905 gboolean fmoved
, fresized
;
2906 guint fdecor
= self
->frame
->decorations
;
2907 gboolean fhorz
= self
->frame
->max_horz
;
2908 gboolean fvert
= self
->frame
->max_vert
;
2909 gint logicalw
, logicalh
;
2911 /* find the new x, y, width, and height (and logical size) */
2912 client_try_configure(self
, &x
, &y
, &w
, &h
, &logicalw
, &logicalh
, user
);
2914 /* set the logical size if things changed */
2915 if (!(w
== self
->area
.width
&& h
== self
->area
.height
))
2916 SIZE_SET(self
->logical_size
, logicalw
, logicalh
);
2918 /* figure out if we moved or resized or what */
2919 moved
= (x
!= self
->area
.x
|| y
!= self
->area
.y
);
2920 resized
= (w
!= self
->area
.width
|| h
!= self
->area
.height
);
2922 oldw
= self
->area
.width
;
2923 oldh
= self
->area
.height
;
2924 oldframe
= self
->frame
->area
;
2925 RECT_SET(self
->area
, x
, y
, w
, h
);
2927 /* for app-requested resizes, always resize if 'resized' is true.
2928 for user-requested ones, only resize if final is true, or when
2929 resizing in redraw mode */
2930 send_resize_client
= ((!user
&& resized
) ||
2932 (resized
&& config_resize_redraw
))));
2934 /* if the client is enlarging, then resize the client before the frame */
2935 if (send_resize_client
&& (w
> oldw
|| h
> oldh
)) {
2936 XMoveResizeWindow(obt_display
, self
->window
,
2937 self
->frame
->size
.left
, self
->frame
->size
.top
,
2938 MAX(w
, oldw
), MAX(h
, oldh
));
2939 frame_adjust_client_area(self
->frame
);
2942 /* find the frame's dimensions and move/resize it */
2946 /* if decorations changed, then readjust everything for the frame */
2947 if (self
->decorations
!= fdecor
||
2948 self
->max_horz
!= fhorz
|| self
->max_vert
!= fvert
)
2950 fmoved
= fresized
= TRUE
;
2953 /* adjust the frame */
2954 if (fmoved
|| fresized
) {
2955 gulong ignore_start
;
2957 ignore_start
= event_start_ignore_all_enters();
2959 frame_adjust_area(self
->frame
, fmoved
, fresized
, FALSE
);
2962 event_end_ignore_all_enters(ignore_start
);
2965 if (!user
|| final
) {
2966 gint oldrx
= self
->root_pos
.x
;
2967 gint oldry
= self
->root_pos
.y
;
2968 /* we have reset the client to 0 border width, so don't include
2969 it in these coords */
2970 POINT_SET(self
->root_pos
,
2971 self
->frame
->area
.x
+ self
->frame
->size
.left
-
2973 self
->frame
->area
.y
+ self
->frame
->size
.top
-
2974 self
->border_width
);
2975 if (self
->root_pos
.x
!= oldrx
|| self
->root_pos
.y
!= oldry
)
2979 /* This is kinda tricky and should not be changed.. let me explain!
2981 When user = FALSE, then the request is coming from the application
2982 itself, and we are more strict about when to send a synthetic
2983 ConfigureNotify. We strictly follow the rules of the ICCCM sec 4.1.5
2984 in this case (if force_reply is true)
2986 When user = TRUE, then the request is coming from "us", like when we
2987 maximize a window or something. In this case we are more lenient. We
2988 used to follow the same rules as above, but _Java_ Swing can't handle
2989 this. So just to appease Swing, when user = TRUE, we always send
2990 a synthetic ConfigureNotify to give the window its root coordinates.
2992 if ((!user
&& !resized
&& (rootmoved
|| force_reply
)) ||
2993 (user
&& final
&& rootmoved
))
2997 event
.type
= ConfigureNotify
;
2998 event
.xconfigure
.display
= obt_display
;
2999 event
.xconfigure
.event
= self
->window
;
3000 event
.xconfigure
.window
= self
->window
;
3002 ob_debug("Sending ConfigureNotify to %s for %d,%d %dx%d",
3003 self
->title
, self
->root_pos
.x
, self
->root_pos
.y
, w
, h
);
3005 /* root window real coords */
3006 event
.xconfigure
.x
= self
->root_pos
.x
;
3007 event
.xconfigure
.y
= self
->root_pos
.y
;
3008 event
.xconfigure
.width
= w
;
3009 event
.xconfigure
.height
= h
;
3010 event
.xconfigure
.border_width
= self
->border_width
;
3011 event
.xconfigure
.above
= None
;
3012 event
.xconfigure
.override_redirect
= FALSE
;
3013 XSendEvent(event
.xconfigure
.display
, event
.xconfigure
.window
,
3014 FALSE
, StructureNotifyMask
, &event
);
3017 /* if the client is shrinking, then resize the frame before the client.
3019 both of these resize sections may run, because the top one only resizes
3020 in the direction that is growing
3022 if (send_resize_client
&& (w
<= oldw
|| h
<= oldh
)) {
3023 frame_adjust_client_area(self
->frame
);
3024 XMoveResizeWindow(obt_display
, self
->window
,
3025 self
->frame
->size
.left
, self
->frame
->size
.top
, w
, h
);
3028 XFlush(obt_display
);
3030 /* if it moved between monitors, then this can affect the stacking
3031 layer of this window or others - for fullscreen windows */
3032 if (screen_find_monitor(&self
->frame
->area
) !=
3033 screen_find_monitor(&oldframe
))
3035 client_calc_layer(self
);
3039 void client_fullscreen(ObClient
*self
, gboolean fs
)
3043 if (!(self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
) || /* can't */
3044 self
->fullscreen
== fs
) return; /* already done */
3046 self
->fullscreen
= fs
;
3047 client_change_state(self
); /* change the state hints on the client */
3050 self
->pre_fullscreen_area
= self
->area
;
3051 /* if the window is maximized, its area isn't all that meaningful.
3052 save it's premax area instead. */
3053 if (self
->max_horz
) {
3054 self
->pre_fullscreen_area
.x
= self
->pre_max_area
.x
;
3055 self
->pre_fullscreen_area
.width
= self
->pre_max_area
.width
;
3057 if (self
->max_vert
) {
3058 self
->pre_fullscreen_area
.y
= self
->pre_max_area
.y
;
3059 self
->pre_fullscreen_area
.height
= self
->pre_max_area
.height
;
3062 /* these will help configure_full figure out where to fullscreen
3066 w
= self
->area
.width
;
3067 h
= self
->area
.height
;
3069 g_assert(self
->pre_fullscreen_area
.width
> 0 &&
3070 self
->pre_fullscreen_area
.height
> 0);
3072 x
= self
->pre_fullscreen_area
.x
;
3073 y
= self
->pre_fullscreen_area
.y
;
3074 w
= self
->pre_fullscreen_area
.width
;
3075 h
= self
->pre_fullscreen_area
.height
;
3076 RECT_SET(self
->pre_fullscreen_area
, 0, 0, 0, 0);
3079 ob_debug("Window %s going fullscreen (%d)",
3080 self
->title
, self
->fullscreen
);
3082 client_setup_decor_and_functions(self
, FALSE
);
3083 client_move_resize(self
, x
, y
, w
, h
);
3085 /* and adjust our layer/stacking. do this after resizing the window,
3086 and applying decorations, because windows which fill the screen are
3087 considered "fullscreen" and it affects their layer */
3088 client_calc_layer(self
);
3091 /* try focus us when we go into fullscreen mode */
3096 static void client_iconify_recursive(ObClient
*self
,
3097 gboolean iconic
, gboolean curdesk
,
3098 gboolean hide_animation
)
3101 gboolean changed
= FALSE
;
3104 if (self
->iconic
!= iconic
) {
3105 ob_debug("%sconifying window: 0x%lx", (iconic
? "I" : "Uni"),
3109 /* don't let non-normal windows iconify along with their parents
3111 if (client_normal(self
)) {
3112 self
->iconic
= iconic
;
3114 /* update the focus lists.. iconic windows go to the bottom of
3116 focus_order_to_bottom(self
);
3121 self
->iconic
= iconic
;
3123 if (curdesk
&& self
->desktop
!= screen_desktop
&&
3124 self
->desktop
!= DESKTOP_ALL
)
3125 client_set_desktop(self
, screen_desktop
, FALSE
, FALSE
);
3127 /* this puts it after the current focused window */
3128 focus_order_remove(self
);
3129 focus_order_add_new(self
);
3136 client_change_state(self
);
3137 if (config_animate_iconify
&& !hide_animation
)
3138 frame_begin_iconify_animation(self
->frame
, iconic
);
3139 /* do this after starting the animation so it doesn't flash */
3140 client_showhide(self
);
3143 /* iconify all direct transients, and deiconify all transients
3145 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
3146 if (it
->data
!= self
)
3147 if (client_is_direct_child(self
, it
->data
) || !iconic
)
3148 client_iconify_recursive(it
->data
, iconic
, curdesk
,
3152 void client_iconify(ObClient
*self
, gboolean iconic
, gboolean curdesk
,
3153 gboolean hide_animation
)
3155 if (self
->functions
& OB_CLIENT_FUNC_ICONIFY
|| !iconic
) {
3156 /* move up the transient chain as far as possible first */
3157 self
= client_search_top_direct_parent(self
);
3158 client_iconify_recursive(self
, iconic
, curdesk
, hide_animation
);
3162 void client_maximize(ObClient
*self
, gboolean max
, gint dir
)
3166 g_assert(dir
== 0 || dir
== 1 || dir
== 2);
3167 if (!(self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
)) return; /* can't */
3169 /* check if already done */
3171 if (dir
== 0 && self
->max_horz
&& self
->max_vert
) return;
3172 if (dir
== 1 && self
->max_horz
) return;
3173 if (dir
== 2 && self
->max_vert
) return;
3175 if (dir
== 0 && !self
->max_horz
&& !self
->max_vert
) return;
3176 if (dir
== 1 && !self
->max_horz
) return;
3177 if (dir
== 2 && !self
->max_vert
) return;
3180 /* these will help configure_full figure out which screen to fill with
3184 w
= self
->area
.width
;
3185 h
= self
->area
.height
;
3188 if ((dir
== 0 || dir
== 1) && !self
->max_horz
) { /* horz */
3189 RECT_SET(self
->pre_max_area
,
3190 self
->area
.x
, self
->pre_max_area
.y
,
3191 self
->area
.width
, self
->pre_max_area
.height
);
3193 if ((dir
== 0 || dir
== 2) && !self
->max_vert
) { /* vert */
3194 RECT_SET(self
->pre_max_area
,
3195 self
->pre_max_area
.x
, self
->area
.y
,
3196 self
->pre_max_area
.width
, self
->area
.height
);
3199 if ((dir
== 0 || dir
== 1) && self
->max_horz
) { /* horz */
3200 g_assert(self
->pre_max_area
.width
> 0);
3202 x
= self
->pre_max_area
.x
;
3203 w
= self
->pre_max_area
.width
;
3205 RECT_SET(self
->pre_max_area
, 0, self
->pre_max_area
.y
,
3206 0, self
->pre_max_area
.height
);
3208 if ((dir
== 0 || dir
== 2) && self
->max_vert
) { /* vert */
3209 g_assert(self
->pre_max_area
.height
> 0);
3211 y
= self
->pre_max_area
.y
;
3212 h
= self
->pre_max_area
.height
;
3214 RECT_SET(self
->pre_max_area
, self
->pre_max_area
.x
, 0,
3215 self
->pre_max_area
.width
, 0);
3219 if (dir
== 0 || dir
== 1) /* horz */
3220 self
->max_horz
= max
;
3221 if (dir
== 0 || dir
== 2) /* vert */
3222 self
->max_vert
= max
;
3224 client_change_state(self
); /* change the state hints on the client */
3226 client_setup_decor_and_functions(self
, FALSE
);
3227 client_move_resize(self
, x
, y
, w
, h
);
3230 void client_shade(ObClient
*self
, gboolean shade
)
3232 if ((!(self
->functions
& OB_CLIENT_FUNC_SHADE
) &&
3233 shade
) || /* can't shade */
3234 self
->shaded
== shade
) return; /* already done */
3236 self
->shaded
= shade
;
3237 client_change_state(self
);
3238 client_change_wm_state(self
); /* the window is being hidden/shown */
3239 /* resize the frame to just the titlebar */
3240 frame_adjust_area(self
->frame
, FALSE
, TRUE
, FALSE
);
3243 static void client_ping_event(ObClient
*self
, gboolean dead
)
3245 self
->not_responding
= dead
;
3246 client_update_title(self
);
3249 /* try kill it nicely the first time again, if it started responding
3251 self
->close_tried_term
= FALSE
;
3255 void client_close(ObClient
*self
)
3257 if (!(self
->functions
& OB_CLIENT_FUNC_CLOSE
)) return;
3260 prompt_hide(self
->prompt
);
3264 /* in the case that the client provides no means to requesting that it
3265 close, we just kill it */
3266 if (!self
->delete_window
)
3267 /* don't use client_kill(), we should only kill based on PID in
3268 response to a lack of PING replies */
3269 XKillClient(obt_display
, self
->window
);
3270 else if (self
->not_responding
)
3273 /* request the client to close with WM_DELETE_WINDOW */
3274 OBT_PROP_MSG_TO(self
->window
, self
->window
, WM_PROTOCOLS
,
3275 OBT_PROP_ATOM(WM_DELETE_WINDOW
), event_curtime
,
3276 0, 0, 0, NoEventMask
);
3279 void client_kill(ObClient
*self
)
3281 if (!self
->client_machine
&& self
->pid
) {
3282 /* running on the local host */
3283 if (!self
->close_tried_term
) {
3284 ob_debug("killing window 0x%x with pid %lu, with SIGTERM",
3285 self
->window
, self
->pid
);
3286 kill(self
->pid
, SIGTERM
);
3287 self
->close_tried_term
= TRUE
;
3289 /* show that we're trying to kill it */
3290 client_update_title(self
);
3293 ob_debug("killing window 0x%x with pid %lu, with SIGKILL",
3294 self
->window
, self
->pid
);
3295 kill(self
->pid
, SIGKILL
); /* kill -9 */
3299 XKillClient(obt_display
, self
->window
);
3302 void client_hilite(ObClient
*self
, gboolean hilite
)
3304 if (self
->demands_attention
== hilite
)
3305 return; /* no change */
3307 /* don't allow focused windows to hilite */
3308 self
->demands_attention
= hilite
&& !client_focused(self
);
3309 if (self
->frame
!= NULL
) { /* if we're mapping, just set the state */
3310 if (self
->demands_attention
)
3311 frame_flash_start(self
->frame
);
3313 frame_flash_stop(self
->frame
);
3314 client_change_state(self
);
3318 static void client_set_desktop_recursive(ObClient
*self
,
3326 if (target
!= self
->desktop
&& self
->type
!= OB_CLIENT_TYPE_DESKTOP
) {
3328 ob_debug("Setting desktop %u", target
+1);
3330 g_assert(target
< screen_num_desktops
|| target
== DESKTOP_ALL
);
3332 old
= self
->desktop
;
3333 self
->desktop
= target
;
3334 OBT_PROP_SET32(self
->window
, NET_WM_DESKTOP
, CARDINAL
, target
);
3335 /* the frame can display the current desktop state */
3336 frame_adjust_state(self
->frame
);
3337 /* 'move' the window to the new desktop */
3341 /* raise if it was not already on the desktop */
3342 if (old
!= DESKTOP_ALL
&& !dontraise
)
3343 stacking_raise(CLIENT_AS_WINDOW(self
));
3344 if (STRUT_EXISTS(self
->strut
))
3345 screen_update_areas();
3347 /* the new desktop's geometry may be different, so we may need to
3348 resize, for example if we are maximized */
3349 client_reconfigure(self
, FALSE
);
3352 /* move all transients */
3353 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
3354 if (it
->data
!= self
)
3355 if (client_is_direct_child(self
, it
->data
))
3356 client_set_desktop_recursive(it
->data
, target
,
3357 donthide
, dontraise
);
3360 void client_set_desktop(ObClient
*self
, guint target
,
3361 gboolean donthide
, gboolean dontraise
)
3363 self
= client_search_top_direct_parent(self
);
3364 client_set_desktop_recursive(self
, target
, donthide
, dontraise
);
3367 gboolean
client_is_direct_child(ObClient
*parent
, ObClient
*child
)
3369 while (child
!= parent
&& (child
= client_direct_parent(child
)));
3370 return child
== parent
;
3373 ObClient
*client_search_modal_child(ObClient
*self
)
3378 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
3379 ObClient
*c
= it
->data
;
3380 if ((ret
= client_search_modal_child(c
))) return ret
;
3381 if (c
->modal
) return c
;
3386 gboolean
client_validate(ObClient
*self
)
3390 XSync(obt_display
, FALSE
); /* get all events on the server */
3392 if (XCheckTypedWindowEvent(obt_display
, self
->window
, DestroyNotify
, &e
) ||
3393 XCheckTypedWindowEvent(obt_display
, self
->window
, UnmapNotify
, &e
))
3395 XPutBackEvent(obt_display
, &e
);
3402 void client_set_wm_state(ObClient
*self
, glong state
)
3404 if (state
== self
->wmstate
) return; /* no change */
3408 client_iconify(self
, TRUE
, TRUE
, FALSE
);
3411 client_iconify(self
, FALSE
, TRUE
, FALSE
);
3416 void client_set_state(ObClient
*self
, Atom action
, glong data1
, glong data2
)
3418 gboolean shaded
= self
->shaded
;
3419 gboolean fullscreen
= self
->fullscreen
;
3420 gboolean undecorated
= self
->undecorated
;
3421 gboolean max_horz
= self
->max_horz
;
3422 gboolean max_vert
= self
->max_vert
;
3423 gboolean modal
= self
->modal
;
3424 gboolean iconic
= self
->iconic
;
3425 gboolean demands_attention
= self
->demands_attention
;
3426 gboolean above
= self
->above
;
3427 gboolean below
= self
->below
;
3430 if (!(action
== OBT_PROP_ATOM(NET_WM_STATE_ADD
) ||
3431 action
== OBT_PROP_ATOM(NET_WM_STATE_REMOVE
) ||
3432 action
== OBT_PROP_ATOM(NET_WM_STATE_TOGGLE
)))
3433 /* an invalid action was passed to the client message, ignore it */
3436 for (i
= 0; i
< 2; ++i
) {
3437 Atom state
= i
== 0 ? data1
: data2
;
3439 if (!state
) continue;
3441 /* if toggling, then pick whether we're adding or removing */
3442 if (action
== OBT_PROP_ATOM(NET_WM_STATE_TOGGLE
)) {
3443 if (state
== OBT_PROP_ATOM(NET_WM_STATE_MODAL
))
3444 action
= modal
? OBT_PROP_ATOM(NET_WM_STATE_REMOVE
) :
3445 OBT_PROP_ATOM(NET_WM_STATE_ADD
);
3446 else if (state
== OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_VERT
))
3447 action
= self
->max_vert
? OBT_PROP_ATOM(NET_WM_STATE_REMOVE
) :
3448 OBT_PROP_ATOM(NET_WM_STATE_ADD
);
3449 else if (state
== OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_HORZ
))
3450 action
= self
->max_horz
? OBT_PROP_ATOM(NET_WM_STATE_REMOVE
) :
3451 OBT_PROP_ATOM(NET_WM_STATE_ADD
);
3452 else if (state
== OBT_PROP_ATOM(NET_WM_STATE_SHADED
))
3453 action
= shaded
? OBT_PROP_ATOM(NET_WM_STATE_REMOVE
) :
3454 OBT_PROP_ATOM(NET_WM_STATE_ADD
);
3455 else if (state
== OBT_PROP_ATOM(NET_WM_STATE_SKIP_TASKBAR
))
3456 action
= self
->skip_taskbar
?
3457 OBT_PROP_ATOM(NET_WM_STATE_REMOVE
) :
3458 OBT_PROP_ATOM(NET_WM_STATE_ADD
);
3459 else if (state
== OBT_PROP_ATOM(NET_WM_STATE_SKIP_PAGER
))
3460 action
= self
->skip_pager
?
3461 OBT_PROP_ATOM(NET_WM_STATE_REMOVE
) :
3462 OBT_PROP_ATOM(NET_WM_STATE_ADD
);
3463 else if (state
== OBT_PROP_ATOM(NET_WM_STATE_HIDDEN
))
3464 action
= self
->iconic
?
3465 OBT_PROP_ATOM(NET_WM_STATE_REMOVE
) :
3466 OBT_PROP_ATOM(NET_WM_STATE_ADD
);
3467 else if (state
== OBT_PROP_ATOM(NET_WM_STATE_FULLSCREEN
))
3468 action
= fullscreen
?
3469 OBT_PROP_ATOM(NET_WM_STATE_REMOVE
) :
3470 OBT_PROP_ATOM(NET_WM_STATE_ADD
);
3471 else if (state
== OBT_PROP_ATOM(NET_WM_STATE_ABOVE
))
3472 action
= self
->above
? OBT_PROP_ATOM(NET_WM_STATE_REMOVE
) :
3473 OBT_PROP_ATOM(NET_WM_STATE_ADD
);
3474 else if (state
== OBT_PROP_ATOM(NET_WM_STATE_BELOW
))
3475 action
= self
->below
? OBT_PROP_ATOM(NET_WM_STATE_REMOVE
) :
3476 OBT_PROP_ATOM(NET_WM_STATE_ADD
);
3477 else if (state
== OBT_PROP_ATOM(NET_WM_STATE_DEMANDS_ATTENTION
))
3478 action
= self
->demands_attention
?
3479 OBT_PROP_ATOM(NET_WM_STATE_REMOVE
) :
3480 OBT_PROP_ATOM(NET_WM_STATE_ADD
);
3481 else if (state
== OBT_PROP_ATOM(OB_WM_STATE_UNDECORATED
))
3482 action
= undecorated
? OBT_PROP_ATOM(NET_WM_STATE_REMOVE
) :
3483 OBT_PROP_ATOM(NET_WM_STATE_ADD
);
3486 if (action
== OBT_PROP_ATOM(NET_WM_STATE_ADD
)) {
3487 if (state
== OBT_PROP_ATOM(NET_WM_STATE_MODAL
)) {
3489 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_VERT
)) {
3491 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_HORZ
)) {
3493 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_SHADED
)) {
3495 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_SKIP_TASKBAR
)) {
3496 self
->skip_taskbar
= TRUE
;
3497 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_SKIP_PAGER
)) {
3498 self
->skip_pager
= TRUE
;
3499 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_HIDDEN
)) {
3501 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_FULLSCREEN
)) {
3503 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_ABOVE
)) {
3506 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_BELOW
)) {
3509 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_DEMANDS_ATTENTION
)){
3510 demands_attention
= TRUE
;
3511 } else if (state
== OBT_PROP_ATOM(OB_WM_STATE_UNDECORATED
)) {
3515 } else { /* action == OBT_PROP_ATOM(NET_WM_STATE_REMOVE) */
3516 if (state
== OBT_PROP_ATOM(NET_WM_STATE_MODAL
)) {
3518 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_VERT
)) {
3520 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_HORZ
)) {
3522 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_SHADED
)) {
3524 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_SKIP_TASKBAR
)) {
3525 self
->skip_taskbar
= FALSE
;
3526 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_SKIP_PAGER
)) {
3527 self
->skip_pager
= FALSE
;
3528 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_HIDDEN
)) {
3530 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_FULLSCREEN
)) {
3532 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_ABOVE
)) {
3534 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_BELOW
)) {
3536 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_DEMANDS_ATTENTION
)){
3537 demands_attention
= FALSE
;
3538 } else if (state
== OBT_PROP_ATOM(OB_WM_STATE_UNDECORATED
)) {
3539 undecorated
= FALSE
;
3544 if (max_horz
!= self
->max_horz
|| max_vert
!= self
->max_vert
) {
3545 if (max_horz
!= self
->max_horz
&& max_vert
!= self
->max_vert
) {
3547 if (max_horz
== max_vert
) { /* both going the same way */
3548 client_maximize(self
, max_horz
, 0);
3550 client_maximize(self
, max_horz
, 1);
3551 client_maximize(self
, max_vert
, 2);
3555 if (max_horz
!= self
->max_horz
)
3556 client_maximize(self
, max_horz
, 1);
3558 client_maximize(self
, max_vert
, 2);
3561 /* change fullscreen state before shading, as it will affect if the window
3563 if (fullscreen
!= self
->fullscreen
)
3564 client_fullscreen(self
, fullscreen
);
3565 if (shaded
!= self
->shaded
)
3566 client_shade(self
, shaded
);
3567 if (undecorated
!= self
->undecorated
)
3568 client_set_undecorated(self
, undecorated
);
3569 if (above
!= self
->above
|| below
!= self
->below
) {
3570 self
->above
= above
;
3571 self
->below
= below
;
3572 client_calc_layer(self
);
3575 if (modal
!= self
->modal
) {
3576 self
->modal
= modal
;
3577 /* when a window changes modality, then its stacking order with its
3578 transients needs to change */
3579 stacking_raise(CLIENT_AS_WINDOW(self
));
3581 /* it also may get focused. if something is focused that shouldn't
3582 be focused anymore, then move the focus */
3583 if (focus_client
&& client_focus_target(focus_client
) != focus_client
)
3584 client_focus(focus_client
);
3587 if (iconic
!= self
->iconic
)
3588 client_iconify(self
, iconic
, FALSE
, FALSE
);
3590 if (demands_attention
!= self
->demands_attention
)
3591 client_hilite(self
, demands_attention
);
3593 client_change_state(self
); /* change the hint to reflect these changes */
3596 ObClient
*client_focus_target(ObClient
*self
)
3598 ObClient
*child
= NULL
;
3600 child
= client_search_modal_child(self
);
3601 if (child
) return child
;
3605 gboolean
client_can_focus(ObClient
*self
)
3607 /* choose the correct target */
3608 self
= client_focus_target(self
);
3610 if (!self
->frame
->visible
)
3613 if (!(self
->can_focus
|| self
->focus_notify
))
3619 gboolean
client_focus(ObClient
*self
)
3621 /* we might not focus this window, so if we have modal children which would
3622 be focused instead, bring them to this desktop */
3623 client_bring_modal_windows(self
);
3625 /* choose the correct target */
3626 self
= client_focus_target(self
);
3628 if (!client_can_focus(self
)) {
3629 ob_debug_type(OB_DEBUG_FOCUS
,
3630 "Client %s can't be focused", self
->title
);
3634 ob_debug_type(OB_DEBUG_FOCUS
,
3635 "Focusing client \"%s\" (0x%x) at time %u",
3636 self
->title
, self
->window
, event_curtime
);
3638 /* if using focus_delay, stop the timer now so that focus doesn't
3640 event_halt_focus_delay();
3642 /* if there is a grab going on, then we need to cancel it. if we move
3643 focus during the grab, applications will get NotifyWhileGrabbed events
3646 actions should not rely on being able to move focus during an
3649 event_cancel_all_key_grabs();
3651 obt_display_ignore_errors(TRUE
);
3653 if (self
->can_focus
) {
3654 /* This can cause a BadMatch error with CurrentTime, or if an app
3655 passed in a bad time for _NET_WM_ACTIVE_WINDOW. */
3656 XSetInputFocus(obt_display
, self
->window
, RevertToPointerRoot
,
3660 if (self
->focus_notify
) {
3662 ce
.xclient
.type
= ClientMessage
;
3663 ce
.xclient
.message_type
= OBT_PROP_ATOM(WM_PROTOCOLS
);
3664 ce
.xclient
.display
= obt_display
;
3665 ce
.xclient
.window
= self
->window
;
3666 ce
.xclient
.format
= 32;
3667 ce
.xclient
.data
.l
[0] = OBT_PROP_ATOM(WM_TAKE_FOCUS
);
3668 ce
.xclient
.data
.l
[1] = event_curtime
;
3669 ce
.xclient
.data
.l
[2] = 0l;
3670 ce
.xclient
.data
.l
[3] = 0l;
3671 ce
.xclient
.data
.l
[4] = 0l;
3672 XSendEvent(obt_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
3675 obt_display_ignore_errors(FALSE
);
3677 ob_debug_type(OB_DEBUG_FOCUS
, "Error focusing? %d",
3678 obt_display_error_occured
);
3679 return !obt_display_error_occured
;
3682 static void client_present(ObClient
*self
, gboolean here
, gboolean raise
,
3685 if (client_normal(self
) && screen_showing_desktop
)
3686 screen_show_desktop(FALSE
, self
);
3688 client_iconify(self
, FALSE
, here
, FALSE
);
3689 if (self
->desktop
!= DESKTOP_ALL
&&
3690 self
->desktop
!= screen_desktop
)
3693 client_set_desktop(self
, screen_desktop
, FALSE
, TRUE
);
3695 screen_set_desktop(self
->desktop
, FALSE
);
3696 } else if (!self
->frame
->visible
)
3697 /* if its not visible for other reasons, then don't mess
3700 if (self
->shaded
&& unshade
)
3701 client_shade(self
, FALSE
);
3703 stacking_raise(CLIENT_AS_WINDOW(self
));
3708 void client_activate(ObClient
*self
, gboolean here
, gboolean raise
,
3709 gboolean unshade
, gboolean user
)
3711 client_present(self
, here
, raise
, unshade
);
3714 static void client_bring_windows_recursive(ObClient
*self
,
3722 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
3723 client_bring_windows_recursive(it
->data
, desktop
,
3724 helpers
, modals
, iconic
);
3726 if (((helpers
&& client_helper(self
)) ||
3727 (modals
&& self
->modal
)) &&
3728 ((self
->desktop
!= desktop
&& self
->desktop
!= DESKTOP_ALL
) ||
3729 (iconic
&& self
->iconic
)))
3731 if (iconic
&& self
->iconic
)
3732 client_iconify(self
, FALSE
, TRUE
, FALSE
);
3734 client_set_desktop(self
, desktop
, FALSE
, FALSE
);
3738 void client_bring_helper_windows(ObClient
*self
)
3740 client_bring_windows_recursive(self
, self
->desktop
, TRUE
, FALSE
, FALSE
);
3743 void client_bring_modal_windows(ObClient
*self
)
3745 client_bring_windows_recursive(self
, self
->desktop
, FALSE
, TRUE
, TRUE
);
3748 gboolean
client_focused(ObClient
*self
)
3750 return self
== focus_client
;
3753 static ObClientIcon
* client_icon_recursive(ObClient
*self
, gint w
, gint h
)
3756 gulong min_diff
, min_i
;
3758 if (!self
->nicons
) {
3759 ObClientIcon
*parent
= NULL
;
3762 for (it
= self
->parents
; it
; it
= g_slist_next(it
)) {
3763 ObClient
*c
= it
->data
;
3764 if ((parent
= client_icon_recursive(c
, w
, h
)))
3771 /* some kind of crappy approximation to find the icon closest in size to
3772 what we requested, but icons are generally all the same ratio as
3773 eachother so it's good enough. */
3775 min_diff
= ABS(self
->icons
[0].width
- w
) + ABS(self
->icons
[0].height
- h
);
3778 for (i
= 1; i
< self
->nicons
; ++i
) {
3781 diff
= ABS(self
->icons
[i
].width
- w
) + ABS(self
->icons
[i
].height
- h
);
3782 if (diff
< min_diff
) {
3787 return &self
->icons
[min_i
];
3790 const ObClientIcon
* client_icon(ObClient
*self
, gint w
, gint h
)
3793 static ObClientIcon deficon
;
3795 if (!(ret
= client_icon_recursive(self
, w
, h
))) {
3796 deficon
.width
= deficon
.height
= 48;
3797 deficon
.data
= ob_rr_theme
->def_win_icon
;
3803 void client_set_layer(ObClient
*self
, gint layer
)
3807 self
->above
= FALSE
;
3808 } else if (layer
== 0) {
3809 self
->below
= self
->above
= FALSE
;
3811 self
->below
= FALSE
;
3814 client_calc_layer(self
);
3815 client_change_state(self
); /* reflect this in the state hints */
3818 void client_set_undecorated(ObClient
*self
, gboolean undecorated
)
3820 if (self
->undecorated
!= undecorated
&&
3821 /* don't let it undecorate if the function is missing, but let
3823 (self
->functions
& OB_CLIENT_FUNC_UNDECORATE
|| !undecorated
))
3825 self
->undecorated
= undecorated
;
3826 client_setup_decor_and_functions(self
, TRUE
);
3827 client_change_state(self
); /* reflect this in the state hints */
3831 guint
client_monitor(ObClient
*self
)
3833 return screen_find_monitor(&self
->frame
->area
);
3836 ObClient
*client_direct_parent(ObClient
*self
)
3838 if (!self
->parents
) return NULL
;
3839 if (self
->transient_for_group
) return NULL
;
3840 return self
->parents
->data
;
3843 ObClient
*client_search_top_direct_parent(ObClient
*self
)
3846 while ((p
= client_direct_parent(self
))) self
= p
;
3850 static GSList
*client_search_all_top_parents_internal(ObClient
*self
,
3852 ObStackingLayer layer
)
3857 /* move up the direct transient chain as far as possible */
3858 while ((p
= client_direct_parent(self
)) &&
3859 (!bylayer
|| p
->layer
== layer
))
3863 ret
= g_slist_prepend(NULL
, self
);
3865 ret
= g_slist_copy(self
->parents
);
3870 GSList
*client_search_all_top_parents(ObClient
*self
)
3872 return client_search_all_top_parents_internal(self
, FALSE
, 0);
3875 GSList
*client_search_all_top_parents_layer(ObClient
*self
)
3877 return client_search_all_top_parents_internal(self
, TRUE
, self
->layer
);
3880 ObClient
*client_search_focus_parent(ObClient
*self
)
3884 for (it
= self
->parents
; it
; it
= g_slist_next(it
))
3885 if (client_focused(it
->data
)) return it
->data
;
3890 ObClient
*client_search_parent(ObClient
*self
, ObClient
*search
)
3894 for (it
= self
->parents
; it
; it
= g_slist_next(it
))
3895 if (it
->data
== search
) return search
;
3900 ObClient
*client_search_transient(ObClient
*self
, ObClient
*search
)
3904 for (sit
= self
->transients
; sit
; sit
= g_slist_next(sit
)) {
3905 if (sit
->data
== search
)
3907 if (client_search_transient(sit
->data
, search
))
3913 static void detect_edge(Rect area
, ObDirection dir
,
3914 gint my_head
, gint my_size
,
3915 gint my_edge_start
, gint my_edge_size
,
3916 gint
*dest
, gboolean
*near_edge
)
3918 gint edge_start
, edge_size
, head
, tail
;
3919 gboolean skip_head
= FALSE
, skip_tail
= FALSE
;
3922 case OB_DIRECTION_NORTH
:
3923 case OB_DIRECTION_SOUTH
:
3924 edge_start
= area
.x
;
3925 edge_size
= area
.width
;
3927 case OB_DIRECTION_EAST
:
3928 case OB_DIRECTION_WEST
:
3929 edge_start
= area
.y
;
3930 edge_size
= area
.height
;
3933 g_assert_not_reached();
3936 /* do we collide with this window? */
3937 if (!RANGES_INTERSECT(my_edge_start
, my_edge_size
,
3938 edge_start
, edge_size
))
3942 case OB_DIRECTION_NORTH
:
3943 head
= RECT_BOTTOM(area
);
3944 tail
= RECT_TOP(area
);
3946 case OB_DIRECTION_SOUTH
:
3947 head
= RECT_TOP(area
);
3948 tail
= RECT_BOTTOM(area
);
3950 case OB_DIRECTION_WEST
:
3951 head
= RECT_RIGHT(area
);
3952 tail
= RECT_LEFT(area
);
3954 case OB_DIRECTION_EAST
:
3955 head
= RECT_LEFT(area
);
3956 tail
= RECT_RIGHT(area
);
3959 g_assert_not_reached();
3962 case OB_DIRECTION_NORTH
:
3963 case OB_DIRECTION_WEST
:
3964 /* check if our window is past the head of this window */
3965 if (my_head
<= head
+ 1)
3967 /* check if our window's tail is past the tail of this window */
3968 if (my_head
+ my_size
- 1 <= tail
)
3970 /* check if the head of this window is closer than the previously
3971 chosen edge (take into account that the previously chosen
3972 edge might have been a tail, not a head) */
3973 if (head
+ (*near_edge
? 0 : my_size
) < *dest
)
3975 /* check if the tail of this window is closer than the previously
3976 chosen edge (take into account that the previously chosen
3977 edge might have been a head, not a tail) */
3978 if (tail
- (!*near_edge
? 0 : my_size
) < *dest
)
3981 case OB_DIRECTION_SOUTH
:
3982 case OB_DIRECTION_EAST
:
3983 /* check if our window is past the head of this window */
3984 if (my_head
>= head
- 1)
3986 /* check if our window's tail is past the tail of this window */
3987 if (my_head
- my_size
+ 1 >= tail
)
3989 /* check if the head of this window is closer than the previously
3990 chosen edge (take into account that the previously chosen
3991 edge might have been a tail, not a head) */
3992 if (head
- (*near_edge
? 0 : my_size
) > *dest
)
3994 /* check if the tail of this window is closer than the previously
3995 chosen edge (take into account that the previously chosen
3996 edge might have been a head, not a tail) */
3997 if (tail
+ (!*near_edge
? 0 : my_size
) > *dest
)
4001 g_assert_not_reached();
4004 ob_debug("my head %d size %d", my_head
, my_size
);
4005 ob_debug("head %d tail %d deest %d", head
, tail
, *dest
);
4007 ob_debug("using near edge %d", head
);
4011 else if (!skip_tail
) {
4012 ob_debug("using far edge %d", tail
);
4018 void client_find_edge_directional(ObClient
*self
, ObDirection dir
,
4019 gint my_head
, gint my_size
,
4020 gint my_edge_start
, gint my_edge_size
,
4021 gint
*dest
, gboolean
*near_edge
)
4028 a
= screen_area(self
->desktop
, SCREEN_AREA_ALL_MONITORS
,
4029 &self
->frame
->area
);
4030 mon
= screen_area(self
->desktop
, SCREEN_AREA_ONE_MONITOR
,
4031 &self
->frame
->area
);
4034 case OB_DIRECTION_NORTH
:
4035 if (my_head
>= RECT_TOP(*mon
) + 1)
4036 edge
= RECT_TOP(*mon
) - 1;
4038 edge
= RECT_TOP(*a
) - 1;
4040 case OB_DIRECTION_SOUTH
:
4041 if (my_head
<= RECT_BOTTOM(*mon
) - 1)
4042 edge
= RECT_BOTTOM(*mon
) + 1;
4044 edge
= RECT_BOTTOM(*a
) + 1;
4046 case OB_DIRECTION_EAST
:
4047 if (my_head
<= RECT_RIGHT(*mon
) - 1)
4048 edge
= RECT_RIGHT(*mon
) + 1;
4050 edge
= RECT_RIGHT(*a
) + 1;
4052 case OB_DIRECTION_WEST
:
4053 if (my_head
>= RECT_LEFT(*mon
) + 1)
4054 edge
= RECT_LEFT(*mon
) - 1;
4056 edge
= RECT_LEFT(*a
) - 1;
4059 g_assert_not_reached();
4061 /* default to the far edge, then narrow it down */
4065 for (it
= client_list
; it
; it
= g_list_next(it
)) {
4066 ObClient
*cur
= it
->data
;
4068 /* skip windows to not bump into */
4073 if (self
->desktop
!= cur
->desktop
&& cur
->desktop
!= DESKTOP_ALL
&&
4074 cur
->desktop
!= screen_desktop
)
4077 ob_debug("trying window %s", cur
->title
);
4079 detect_edge(cur
->frame
->area
, dir
, my_head
, my_size
, my_edge_start
,
4080 my_edge_size
, dest
, near_edge
);
4082 dock_get_area(&dock_area
);
4083 detect_edge(dock_area
, dir
, my_head
, my_size
, my_edge_start
,
4084 my_edge_size
, dest
, near_edge
);
4089 void client_find_move_directional(ObClient
*self
, ObDirection dir
,
4093 gint e
, e_start
, e_size
;
4097 case OB_DIRECTION_EAST
:
4098 head
= RECT_RIGHT(self
->frame
->area
);
4099 size
= self
->frame
->area
.width
;
4100 e_start
= RECT_TOP(self
->frame
->area
);
4101 e_size
= self
->frame
->area
.height
;
4103 case OB_DIRECTION_WEST
:
4104 head
= RECT_LEFT(self
->frame
->area
);
4105 size
= self
->frame
->area
.width
;
4106 e_start
= RECT_TOP(self
->frame
->area
);
4107 e_size
= self
->frame
->area
.height
;
4109 case OB_DIRECTION_NORTH
:
4110 head
= RECT_TOP(self
->frame
->area
);
4111 size
= self
->frame
->area
.height
;
4112 e_start
= RECT_LEFT(self
->frame
->area
);
4113 e_size
= self
->frame
->area
.width
;
4115 case OB_DIRECTION_SOUTH
:
4116 head
= RECT_BOTTOM(self
->frame
->area
);
4117 size
= self
->frame
->area
.height
;
4118 e_start
= RECT_LEFT(self
->frame
->area
);
4119 e_size
= self
->frame
->area
.width
;
4122 g_assert_not_reached();
4125 client_find_edge_directional(self
, dir
, head
, size
,
4126 e_start
, e_size
, &e
, &near
);
4127 *x
= self
->frame
->area
.x
;
4128 *y
= self
->frame
->area
.y
;
4130 case OB_DIRECTION_EAST
:
4131 if (near
) e
-= self
->frame
->area
.width
;
4135 case OB_DIRECTION_WEST
:
4137 else e
-= self
->frame
->area
.width
;
4140 case OB_DIRECTION_NORTH
:
4142 else e
-= self
->frame
->area
.height
;
4145 case OB_DIRECTION_SOUTH
:
4146 if (near
) e
-= self
->frame
->area
.height
;
4151 g_assert_not_reached();
4153 frame_frame_gravity(self
->frame
, x
, y
);
4156 void client_find_resize_directional(ObClient
*self
, ObDirection side
,
4158 gint
*x
, gint
*y
, gint
*w
, gint
*h
)
4161 gint e
, e_start
, e_size
, delta
;
4166 case OB_DIRECTION_EAST
:
4167 head
= RECT_RIGHT(self
->frame
->area
) +
4168 (self
->size_inc
.width
- 1) * (grow
? 1 : -1);
4169 e_start
= RECT_TOP(self
->frame
->area
);
4170 e_size
= self
->frame
->area
.height
;
4171 dir
= grow
? OB_DIRECTION_EAST
: OB_DIRECTION_WEST
;
4173 case OB_DIRECTION_WEST
:
4174 head
= RECT_LEFT(self
->frame
->area
) -
4175 (self
->size_inc
.width
- 1) * (grow
? 1 : -1);
4176 e_start
= RECT_TOP(self
->frame
->area
);
4177 e_size
= self
->frame
->area
.height
;
4178 dir
= grow
? OB_DIRECTION_WEST
: OB_DIRECTION_EAST
;
4180 case OB_DIRECTION_NORTH
:
4181 head
= RECT_TOP(self
->frame
->area
) -
4182 (self
->size_inc
.height
- 1) * (grow
? 1 : -1);
4183 e_start
= RECT_LEFT(self
->frame
->area
);
4184 e_size
= self
->frame
->area
.width
;
4185 dir
= grow
? OB_DIRECTION_NORTH
: OB_DIRECTION_SOUTH
;
4187 case OB_DIRECTION_SOUTH
:
4188 head
= RECT_BOTTOM(self
->frame
->area
) +
4189 (self
->size_inc
.height
- 1) * (grow
? 1 : -1);
4190 e_start
= RECT_LEFT(self
->frame
->area
);
4191 e_size
= self
->frame
->area
.width
;
4192 dir
= grow
? OB_DIRECTION_SOUTH
: OB_DIRECTION_NORTH
;
4195 g_assert_not_reached();
4198 ob_debug("head %d dir %d", head
, dir
);
4199 client_find_edge_directional(self
, dir
, head
, 1,
4200 e_start
, e_size
, &e
, &near
);
4201 ob_debug("edge %d", e
);
4202 *x
= self
->frame
->area
.x
;
4203 *y
= self
->frame
->area
.y
;
4204 *w
= self
->frame
->area
.width
;
4205 *h
= self
->frame
->area
.height
;
4207 case OB_DIRECTION_EAST
:
4208 if (grow
== near
) --e
;
4209 delta
= e
- RECT_RIGHT(self
->frame
->area
);
4212 case OB_DIRECTION_WEST
:
4213 if (grow
== near
) ++e
;
4214 delta
= RECT_LEFT(self
->frame
->area
) - e
;
4218 case OB_DIRECTION_NORTH
:
4219 if (grow
== near
) ++e
;
4220 delta
= RECT_TOP(self
->frame
->area
) - e
;
4224 case OB_DIRECTION_SOUTH
:
4225 if (grow
== near
) --e
;
4226 delta
= e
- RECT_BOTTOM(self
->frame
->area
);
4230 g_assert_not_reached();
4232 frame_frame_gravity(self
->frame
, x
, y
);
4233 *w
-= self
->frame
->size
.left
+ self
->frame
->size
.right
;
4234 *h
-= self
->frame
->size
.top
+ self
->frame
->size
.bottom
;
4237 ObClient
* client_under_pointer(void)
4241 ObClient
*ret
= NULL
;
4243 if (screen_pointer_pos(&x
, &y
)) {
4244 for (it
= stacking_list
; it
; it
= g_list_next(it
)) {
4245 if (WINDOW_IS_CLIENT(it
->data
)) {
4246 ObClient
*c
= WINDOW_AS_CLIENT(it
->data
);
4247 if (c
->frame
->visible
&&
4248 /* check the desktop, this is done during desktop
4249 switching and windows are shown/hidden status is not
4251 (c
->desktop
== screen_desktop
||
4252 c
->desktop
== DESKTOP_ALL
) &&
4253 /* ignore all animating windows */
4254 !frame_iconify_animating(c
->frame
) &&
4255 RECT_CONTAINS(c
->frame
->area
, x
, y
))
4266 gboolean
client_has_group_siblings(ObClient
*self
)
4268 return self
->group
&& self
->group
->members
->next
;