1 /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
3 client.c for the Openbox window manager
4 Copyright (c) 2006 Mikael Magnusson
5 Copyright (c) 2003-2007 Dana Jansens
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 See the COPYING file for a copy of the GNU General Public License.
22 #include "startupnotify.h"
26 #include "moveresize.h"
30 #include "extensions.h"
41 #include "menuframe.h"
44 #include "render/render.h"
52 # include <signal.h> /* for kill() */
56 #include <X11/Xutil.h>
58 /*! The event mask to grab on client windows */
59 #define CLIENT_EVENTMASK (PropertyChangeMask | StructureNotifyMask | \
62 #define CLIENT_NOPROPAGATEMASK (ButtonPressMask | ButtonReleaseMask | \
67 ObClientCallback func
;
71 GList
*client_list
= NULL
;
73 static GSList
*client_destroy_notifies
= NULL
;
74 static RrImage
*client_default_icon
= NULL
;
76 static void client_get_all(ObClient
*self
, gboolean real
);
77 static void client_get_startup_id(ObClient
*self
);
78 static void client_get_session_ids(ObClient
*self
);
79 static void client_get_area(ObClient
*self
);
80 static void client_get_desktop(ObClient
*self
);
81 static void client_get_state(ObClient
*self
);
82 static void client_get_shaped(ObClient
*self
);
83 static void client_get_mwm_hints(ObClient
*self
);
84 static void client_get_colormap(ObClient
*self
);
85 static void client_set_desktop_recursive(ObClient
*self
,
89 static void client_change_allowed_actions(ObClient
*self
);
90 static void client_change_state(ObClient
*self
);
91 static void client_change_wm_state(ObClient
*self
);
92 static void client_apply_startup_state(ObClient
*self
,
93 gint x
, gint y
, gint w
, gint h
);
94 static void client_restore_session_state(ObClient
*self
);
95 static gboolean
client_restore_session_stacking(ObClient
*self
);
96 static ObAppSettings
*client_get_settings_state(ObClient
*self
);
97 static void client_update_transient_tree(ObClient
*self
,
98 ObGroup
*oldgroup
, ObGroup
*newgroup
,
99 gboolean oldgtran
, gboolean newgtran
,
101 ObClient
*newparent
);
102 static void client_present(ObClient
*self
, gboolean here
, gboolean raise
,
104 static GSList
*client_search_all_top_parents_internal(ObClient
*self
,
106 ObStackingLayer layer
);
107 static void client_call_notifies(ObClient
*self
, GSList
*list
);
108 static void client_ping_event(ObClient
*self
, gboolean dead
);
109 static void client_prompt_kill(ObClient
*self
);
112 void client_startup(gboolean reconfig
)
114 if ((client_default_icon
= RrImageCacheFind(ob_rr_icons
,
115 ob_rr_theme
->def_win_icon
,
116 ob_rr_theme
->def_win_icon_w
,
117 ob_rr_theme
->def_win_icon_h
)))
118 RrImageRef(client_default_icon
);
120 client_default_icon
= RrImageNew(ob_rr_icons
);
121 RrImageAddPicture(client_default_icon
,
122 ob_rr_theme
->def_win_icon
,
123 ob_rr_theme
->def_win_icon_w
,
124 ob_rr_theme
->def_win_icon_h
);
127 if (reconfig
) return;
132 void client_shutdown(gboolean reconfig
)
134 RrImageUnref(client_default_icon
);
135 client_default_icon
= NULL
;
137 if (reconfig
) return;
140 static void client_call_notifies(ObClient
*self
, GSList
*list
)
144 for (it
= list
; it
; it
= g_slist_next(it
)) {
145 ClientCallback
*d
= it
->data
;
146 d
->func(self
, d
->data
);
150 void client_add_destroy_notify(ObClientCallback func
, gpointer data
)
152 ClientCallback
*d
= g_new(ClientCallback
, 1);
155 client_destroy_notifies
= g_slist_prepend(client_destroy_notifies
, d
);
158 void client_remove_destroy_notify(ObClientCallback func
)
162 for (it
= client_destroy_notifies
; it
; it
= g_slist_next(it
)) {
163 ClientCallback
*d
= it
->data
;
164 if (d
->func
== func
) {
166 client_destroy_notifies
=
167 g_slist_delete_link(client_destroy_notifies
, it
);
173 void client_set_list(void)
175 Window
*windows
, *win_it
;
177 guint size
= g_list_length(client_list
);
179 /* create an array of the window ids */
181 windows
= g_new(Window
, size
);
183 for (it
= client_list
; it
; it
= g_list_next(it
), ++win_it
)
184 *win_it
= ((ObClient
*)it
->data
)->window
;
188 PROP_SETA32(RootWindow(ob_display
, ob_screen
),
189 net_client_list
, window
, (gulong
*)windows
, size
);
197 void client_manage_all(void)
202 XWindowAttributes attrib
;
204 XQueryTree(ob_display
, RootWindow(ob_display
, ob_screen
),
205 &w
, &w
, &children
, &nchild
);
207 /* remove all icon windows from the list */
208 for (i
= 0; i
< nchild
; i
++) {
209 if (children
[i
] == None
) continue;
210 wmhints
= XGetWMHints(ob_display
, children
[i
]);
212 if ((wmhints
->flags
& IconWindowHint
) &&
213 (wmhints
->icon_window
!= children
[i
]))
214 for (j
= 0; j
< nchild
; j
++)
215 if (children
[j
] == wmhints
->icon_window
) {
223 /* manage windows in reverse order from how they were originally mapped.
224 this is an attempt to manage children windows before their parents, so
225 that when the parent is mapped, it can find the child */
226 for (i
= 0; i
< nchild
; ++i
) {
227 if (children
[i
] == None
)
229 if (XGetWindowAttributes(ob_display
, children
[i
], &attrib
)) {
230 if (attrib
.override_redirect
) continue;
232 if (attrib
.map_state
!= IsUnmapped
)
233 client_manage(children
[i
], NULL
);
239 void client_manage(Window window
, ObPrompt
*prompt
)
243 XWindowAttributes attrib
;
244 XSetWindowAttributes attrib_set
;
246 gboolean activate
= FALSE
;
247 ObAppSettings
*settings
;
248 gboolean transient
= FALSE
;
249 Rect place
, *monitor
;
250 Time launch_time
, map_time
;
254 /* check if it has already been unmapped by the time we started
255 mapping. the grab does a sync so we don't have to here */
256 if (XCheckTypedWindowEvent(ob_display
, window
, DestroyNotify
, &e
) ||
257 XCheckTypedWindowEvent(ob_display
, window
, UnmapNotify
, &e
))
259 XPutBackEvent(ob_display
, &e
);
261 ob_debug("Trying to manage unmapped window. Aborting that.\n");
263 return; /* don't manage it */
266 /* make sure it isn't an override-redirect window */
267 if (!XGetWindowAttributes(ob_display
, window
, &attrib
) ||
268 attrib
.override_redirect
)
271 return; /* don't manage it */
274 /* is the window a docking app */
275 if ((wmhint
= XGetWMHints(ob_display
, window
))) {
276 if ((wmhint
->flags
& StateHint
) &&
277 wmhint
->initial_state
== WithdrawnState
)
279 dock_add(window
, wmhint
);
287 ob_debug("Managing window: 0x%lx\n", window
);
289 map_time
= event_get_server_time();
291 /* choose the events we want to receive on the CLIENT window
292 (ObPrompt windows can request events too) */
293 attrib_set
.event_mask
= CLIENT_EVENTMASK
|
294 (prompt
? prompt
->event_mask
: 0);
295 attrib_set
.do_not_propagate_mask
= CLIENT_NOPROPAGATEMASK
;
296 XChangeWindowAttributes(ob_display
, window
,
297 CWEventMask
|CWDontPropagate
, &attrib_set
);
299 /* create the ObClient struct, and populate it from the hints on the
301 self
= g_new0(ObClient
, 1);
302 self
->obwin
.type
= Window_Client
;
303 self
->window
= window
;
304 self
->prompt
= prompt
;
306 /* non-zero defaults */
307 self
->wmstate
= WithdrawnState
; /* make sure it gets updated first time */
308 self
->gravity
= NorthWestGravity
;
309 self
->desktop
= screen_num_desktops
; /* always an invalid value */
311 /* get all the stuff off the window */
312 client_get_all(self
, TRUE
);
314 ob_debug("Window type: %d\n", self
->type
);
315 ob_debug("Window group: 0x%x\n", self
->group
?self
->group
->leader
:0);
317 /* now we have all of the window's information so we can set this up.
318 do this before creating the frame, so it can tell that we are still
319 mapping and doesn't go applying things right away */
320 client_setup_decor_and_functions(self
, FALSE
);
322 /* specify that if we exit, the window should not be destroyed and
323 should be reparented back to root automatically, unless we are managing
324 an internal ObPrompt window */
326 XChangeSaveSet(ob_display
, window
, SetModeInsert
);
328 /* create the decoration frame for the client window */
329 self
->frame
= frame_new(self
);
331 frame_grab_client(self
->frame
);
333 /* we've grabbed everything and set everything that we need to at mapping
337 /* per-app settings override stuff from client_get_all, and return the
338 settings for other uses too. the returned settings is a shallow copy,
339 that needs to be freed with g_free(). */
340 settings
= client_get_settings_state(self
);
341 /* the session should get the last say though */
342 client_restore_session_state(self
);
344 /* tell startup notification that this app started */
345 launch_time
= sn_app_started(self
->startup_id
, self
->class, self
->name
);
347 /* do this after we have a frame.. it uses the frame to help determine the
348 WM_STATE to apply. */
349 client_change_state(self
);
351 /* add ourselves to the focus order */
352 focus_order_add_new(self
);
354 /* do this to add ourselves to the stacking list in a non-intrusive way */
355 client_calc_layer(self
);
357 /* focus the new window? */
358 if (ob_state() != OB_STATE_STARTING
&&
359 (!self
->session
|| self
->session
->focused
) &&
360 /* this means focus=true for window is same as config_focus_new=true */
361 ((config_focus_new
|| (settings
&& settings
->focus
== 1)) ||
362 client_search_focus_tree_full(self
)) &&
363 /* this checks for focus=false for the window */
364 (!settings
|| settings
->focus
!= 0) &&
365 focus_valid_target(self
, FALSE
, FALSE
, TRUE
, FALSE
, FALSE
))
370 /* remove the client's border */
371 XSetWindowBorderWidth(ob_display
, self
->window
, 0);
373 /* adjust the frame to the client's size before showing or placing
375 frame_adjust_area(self
->frame
, FALSE
, TRUE
, FALSE
);
376 frame_adjust_client_area(self
->frame
);
378 /* where the frame was placed is where the window was originally */
380 monitor
= screen_physical_area_monitor(screen_find_monitor(&place
));
382 /* figure out placement for the window if the window is new */
383 if (ob_state() == OB_STATE_RUNNING
) {
384 ob_debug("Positioned: %s @ %d %d\n",
385 (!self
->positioned
? "no" :
386 (self
->positioned
== PPosition
? "program specified" :
387 (self
->positioned
== USPosition
? "user specified" :
388 (self
->positioned
== (PPosition
| USPosition
) ?
389 "program + user specified" :
390 "BADNESS !?")))), place
.x
, place
.y
);
392 ob_debug("Sized: %s @ %d %d\n",
393 (!self
->sized
? "no" :
394 (self
->sized
== PSize
? "program specified" :
395 (self
->sized
== USSize
? "user specified" :
396 (self
->sized
== (PSize
| USSize
) ?
397 "program + user specified" :
398 "BADNESS !?")))), place
.width
, place
.height
);
400 /* splash screens are also returned as TRUE for transient,
401 and so will be forced on screen below */
402 transient
= place_client(self
, &place
.x
, &place
.y
, settings
);
404 /* make sure the window is visible. */
405 client_find_onscreen(self
, &place
.x
, &place
.y
,
406 place
.width
, place
.height
,
407 /* non-normal clients has less rules, and
408 windows that are being restored from a
409 session do also. we can assume you want
410 it back where you saved it. Clients saying
411 they placed themselves are subjected to
412 harder rules, ones that are placed by
413 place.c or by the user are allowed partially
414 off-screen and on xinerama divides (ie,
415 it is up to the placement routines to avoid
416 the xinerama divides)
418 splash screens get "transient" set to TRUE by
419 the place_client call
421 ob_state() == OB_STATE_RUNNING
&&
423 (!((self
->positioned
& USPosition
) ||
424 (settings
&& settings
->pos_given
)) &&
425 client_normal(self
) &&
427 /* don't move oldschool fullscreen windows to
428 fit inside the struts (fixes Acroread, which
429 makes its fullscreen window fit the screen
430 but it is not USSize'd or USPosition'd) */
431 !(self
->decorations
== 0 &&
432 RECT_EQUAL(place
, *monitor
)))));
435 /* if the window isn't user-sized, then make it fit inside
436 the visible screen area on its monitor. Use basically the same rules
437 for forcing the window on screen in the client_find_onscreen call.
439 do this after place_client, it chooses the monitor!
441 splash screens get "transient" set to TRUE by
442 the place_client call
444 if (ob_state() == OB_STATE_RUNNING
&&
446 (!(self
->sized
& USSize
|| self
->positioned
& USPosition
) &&
447 client_normal(self
) &&
449 /* don't shrink oldschool fullscreen windows to fit inside the
450 struts (fixes Acroread, which makes its fullscreen window
451 fit the screen but it is not USSize'd or USPosition'd) */
452 !(self
->decorations
== 0 && RECT_EQUAL(place
, *monitor
)))))
454 Rect
*a
= screen_area(self
->desktop
, SCREEN_AREA_ONE_MONITOR
, &place
);
456 /* get the size of the frame */
457 place
.width
+= self
->frame
->size
.left
+ self
->frame
->size
.right
;
458 place
.height
+= self
->frame
->size
.top
+ self
->frame
->size
.bottom
;
460 /* fit the window inside the area */
461 place
.width
= MIN(place
.width
, a
->width
);
462 place
.height
= MIN(place
.height
, a
->height
);
464 ob_debug("setting window size to %dx%d\n", place
.width
, place
.height
);
466 /* get the size of the client back */
467 place
.width
-= self
->frame
->size
.left
+ self
->frame
->size
.right
;
468 place
.height
-= self
->frame
->size
.top
+ self
->frame
->size
.bottom
;
473 ob_debug("placing window 0x%x at %d, %d with size %d x %d. "
474 "some restrictions may apply\n",
475 self
->window
, place
.x
, place
.y
, place
.width
, place
.height
);
477 ob_debug(" but session requested %d, %d %d x %d instead, "
479 self
->session
->x
, self
->session
->y
,
480 self
->session
->w
, self
->session
->h
);
482 /* do this after the window is placed, so the premax/prefullscreen numbers
485 this also places the window
487 client_apply_startup_state(self
, place
.x
, place
.y
,
488 place
.width
, place
.height
);
493 ob_debug_type(OB_DEBUG_FOCUS
, "Going to try activate new window? %s\n",
494 activate
? "yes" : "no");
496 gboolean raise
= FALSE
;
498 /* This is focus stealing prevention */
499 ob_debug_type(OB_DEBUG_FOCUS
,
500 "Want to focus new window 0x%x at time %u "
501 "launched at %u (last user interaction time %u)\n",
502 self
->window
, map_time
, launch_time
,
503 event_last_user_time
);
505 if (menu_frame_visible
|| moveresize_in_progress
) {
508 ob_debug_type(OB_DEBUG_FOCUS
,
509 "Not focusing the window because the user is inside "
510 "an Openbox menu or is move/resizing a window and "
511 "we don't want to interrupt them\n");
514 /* if it's on another desktop */
515 else if (!(self
->desktop
== screen_desktop
||
516 self
->desktop
== DESKTOP_ALL
) &&
517 /* the timestamp is from before you changed desktops */
518 launch_time
&& screen_desktop_user_time
&&
519 !event_time_after(launch_time
, screen_desktop_user_time
))
523 ob_debug_type(OB_DEBUG_FOCUS
,
524 "Not focusing the window because its on another "
527 /* If something is focused, and it's not our relative... */
528 else if (focus_client
&& client_search_focus_tree_full(self
) == NULL
&&
529 client_search_focus_group_full(self
) == NULL
)
531 /* If the user is working in another window right now, then don't
533 if (event_last_user_time
&& launch_time
&&
534 event_time_after(event_last_user_time
, launch_time
) &&
535 event_last_user_time
!= launch_time
&&
536 event_time_after(event_last_user_time
,
537 map_time
- OB_EVENT_USER_TIME_DELAY
))
540 ob_debug_type(OB_DEBUG_FOCUS
,
541 "Not focusing the window because the user is "
542 "working in another window\n");
544 /* If it's a transient (and its parents aren't focused) */
545 else if (client_has_parent(self
)) {
547 ob_debug_type(OB_DEBUG_FOCUS
,
548 "Not focusing the window because it is a "
549 "transient, and its relatives aren't focused\n");
551 /* Don't steal focus from globally active clients.
552 I stole this idea from KWin. It seems nice.
554 else if (!(focus_client
->can_focus
||
555 focus_client
->focus_notify
))
558 ob_debug_type(OB_DEBUG_FOCUS
,
559 "Not focusing the window because a globally "
560 "active client has focus\n");
562 /* Don't move focus if it's not going to go to this window
564 else if (client_focus_target(self
) != self
) {
567 ob_debug_type(OB_DEBUG_FOCUS
,
568 "Not focusing the window because another window "
569 "would get the focus anyway\n");
571 else if (!(self
->desktop
== screen_desktop
||
572 self
->desktop
== DESKTOP_ALL
))
576 ob_debug_type(OB_DEBUG_FOCUS
,
577 "Not focusing the window because it is on "
578 "another desktop and no relatives are focused ");
583 ob_debug_type(OB_DEBUG_FOCUS
,
584 "Focus stealing prevention activated for %s at "
585 "time %u (last user interaction time %u)\n",
586 self
->title
, map_time
, event_last_user_time
);
587 /* if the client isn't focused, then hilite it so the user
589 client_hilite(self
, TRUE
);
590 /* we may want to raise it even tho we're not activating it */
591 if (raise
&& !client_restore_session_stacking(self
))
592 stacking_raise(CLIENT_AS_WINDOW(self
));
596 /* This may look rather odd. Well it's because new windows are added
597 to the stacking order non-intrusively. If we're not going to focus
598 the new window or hilite it, then we raise it to the top. This will
599 take affect for things that don't get focused like splash screens.
600 Also if you don't have focus_new enabled, then it's going to get
601 raised to the top. Legacy begets legacy I guess?
603 if (!client_restore_session_stacking(self
))
604 stacking_raise(CLIENT_AS_WINDOW(self
));
607 mouse_grab_for_client(self
, TRUE
);
609 /* this has to happen before we try focus the window, but we want it to
610 happen after the client's stacking has been determined or it looks bad
614 if (!config_focus_under_mouse
)
615 ignore_start
= event_start_ignore_all_enters();
619 if (!config_focus_under_mouse
)
620 event_end_ignore_all_enters(ignore_start
);
624 gboolean stacked
= client_restore_session_stacking(self
);
625 client_present(self
, FALSE
, !stacked
, TRUE
);
628 /* add to client list/map */
629 client_list
= g_list_append(client_list
, self
);
630 g_hash_table_insert(window_map
, &self
->window
, self
);
632 /* this has to happen after we're in the client_list */
633 if (STRUT_EXISTS(self
->strut
))
634 screen_update_areas();
636 /* update the list hints */
639 /* free the ObAppSettings shallow copy */
642 ob_debug("Managed window 0x%lx plate 0x%x (%s)\n",
643 window
, self
->frame
->window
, self
->class);
649 ObClient
*client_fake_manage(Window window
)
652 ObAppSettings
*settings
;
654 ob_debug("Pretend-managing window: %lx\n", window
);
656 /* do this minimal stuff to figure out the client's decorations */
658 self
= g_new0(ObClient
, 1);
659 self
->window
= window
;
661 client_get_all(self
, FALSE
);
662 /* per-app settings override stuff, and return the settings for other
663 uses too. this returns a shallow copy that needs to be freed */
664 settings
= client_get_settings_state(self
);
666 client_setup_decor_and_functions(self
, FALSE
);
668 /* create the decoration frame for the client window and adjust its size */
669 self
->frame
= frame_new(self
);
670 frame_adjust_area(self
->frame
, FALSE
, TRUE
, TRUE
);
672 ob_debug("gave extents left %d right %d top %d bottom %d\n",
673 self
->frame
->size
.left
, self
->frame
->size
.right
,
674 self
->frame
->size
.top
, self
->frame
->size
.bottom
);
676 /* free the ObAppSettings shallow copy */
682 void client_unmanage_all(void)
685 client_unmanage(client_list
->data
);
688 void client_unmanage(ObClient
*self
)
693 ob_debug("Unmanaging window: 0x%x plate 0x%x (%s) (%s)\n",
694 self
->window
, self
->frame
->window
,
695 self
->class, self
->title
? self
->title
: "");
697 g_assert(self
!= NULL
);
699 /* we dont want events no more. do this before hiding the frame so we
700 don't generate more events */
701 XSelectInput(ob_display
, self
->window
, NoEventMask
);
703 /* ignore enter events from the unmap so it doesnt mess with the focus */
704 if (!config_focus_under_mouse
)
705 ignore_start
= event_start_ignore_all_enters();
707 frame_hide(self
->frame
);
708 /* flush to send the hide to the server quickly */
711 if (!config_focus_under_mouse
)
712 event_end_ignore_all_enters(ignore_start
);
714 mouse_grab_for_client(self
, FALSE
);
716 /* remove the window from our save set, unless we are managing an internal
719 XChangeSaveSet(ob_display
, self
->window
, SetModeDelete
);
721 /* update the focus lists */
722 focus_order_remove(self
);
723 if (client_focused(self
)) {
724 /* don't leave an invalid focus_client */
728 /* if we're prompting to kill the client, close that */
729 prompt_unref(self
->kill_prompt
);
730 self
->kill_prompt
= NULL
;
732 client_list
= g_list_remove(client_list
, self
);
733 stacking_remove(self
);
734 g_hash_table_remove(window_map
, &self
->window
);
736 /* once the client is out of the list, update the struts to remove its
738 if (STRUT_EXISTS(self
->strut
))
739 screen_update_areas();
741 client_call_notifies(self
, client_destroy_notifies
);
743 /* tell our parent(s) that we're gone */
744 for (it
= self
->parents
; it
; it
= g_slist_next(it
))
745 ((ObClient
*)it
->data
)->transients
=
746 g_slist_remove(((ObClient
*)it
->data
)->transients
,self
);
748 /* tell our transients that we're gone */
749 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
750 ((ObClient
*)it
->data
)->parents
=
751 g_slist_remove(((ObClient
*)it
->data
)->parents
, self
);
752 /* we could be keeping our children in a higher layer */
753 client_calc_layer(it
->data
);
756 /* remove from its group */
758 group_remove(self
->group
, self
);
762 /* restore the window's original geometry so it is not lost */
768 if (self
->fullscreen
)
769 a
= self
->pre_fullscreen_area
;
770 else if (self
->max_horz
|| self
->max_vert
) {
771 if (self
->max_horz
) {
772 a
.x
= self
->pre_max_area
.x
;
773 a
.width
= self
->pre_max_area
.width
;
775 if (self
->max_vert
) {
776 a
.y
= self
->pre_max_area
.y
;
777 a
.height
= self
->pre_max_area
.height
;
781 self
->fullscreen
= self
->max_horz
= self
->max_vert
= FALSE
;
782 /* let it be moved and resized no matter what */
783 self
->functions
= OB_CLIENT_FUNC_MOVE
| OB_CLIENT_FUNC_RESIZE
;
784 self
->decorations
= 0; /* unmanaged windows have no decor */
786 /* give the client its border back */
787 XSetWindowBorderWidth(ob_display
, self
->window
, self
->border_width
);
789 client_move_resize(self
, a
.x
, a
.y
, a
.width
, a
.height
);
792 /* reparent the window out of the frame, and free the frame */
793 frame_release_client(self
->frame
);
794 frame_free(self
->frame
);
797 if (ob_state() != OB_STATE_EXITING
) {
798 /* these values should not be persisted across a window
800 PROP_ERASE(self
->window
, net_wm_desktop
);
801 PROP_ERASE(self
->window
, net_wm_state
);
802 PROP_ERASE(self
->window
, wm_state
);
804 /* if we're left in an unmapped state, the client wont be mapped.
805 this is bad, since we will no longer be managing the window on
807 XMapWindow(ob_display
, self
->window
);
810 /* these should not be left on the window ever. other window managers
811 don't necessarily use them and it will mess them up (like compiz) */
812 PROP_ERASE(self
->window
, net_wm_visible_name
);
813 PROP_ERASE(self
->window
, net_wm_visible_icon_name
);
815 /* update the list hints */
818 ob_debug("Unmanaged window 0x%lx\n", self
->window
);
820 /* free all data allocated in the client struct */
821 RrImageUnref(self
->icon_set
);
822 g_slist_free(self
->transients
);
823 g_free(self
->startup_id
);
824 g_free(self
->wm_command
);
826 g_free(self
->icon_title
);
827 g_free(self
->original_title
);
831 g_free(self
->client_machine
);
832 g_free(self
->sm_client_id
);
836 void client_fake_unmanage(ObClient
*self
)
838 /* this is all that got allocated to get the decorations */
840 frame_free(self
->frame
);
844 /*! Returns a new structure containing the per-app settings for this client.
845 The returned structure needs to be freed with g_free. */
846 static ObAppSettings
*client_get_settings_state(ObClient
*self
)
848 ObAppSettings
*settings
;
851 settings
= config_create_app_settings();
853 for (it
= config_per_app_settings
; it
; it
= g_slist_next(it
)) {
854 ObAppSettings
*app
= it
->data
;
855 gboolean match
= TRUE
;
857 g_assert(app
->name
!= NULL
|| app
->class != NULL
);
859 /* we know that either name or class is not NULL so it will have to
860 match to use the rule */
862 !g_pattern_match(app
->name
, strlen(self
->name
), self
->name
, NULL
))
864 else if (app
->class &&
865 !g_pattern_match(app
->class,
866 strlen(self
->class), self
->class, NULL
))
868 else if (app
->role
&&
869 !g_pattern_match(app
->role
,
870 strlen(self
->role
), self
->role
, NULL
))
872 else if ((signed)app
->type
>= 0 && app
->type
!= self
->type
)
876 ob_debug("Window matching: %s\n", app
->name
);
878 /* copy the settings to our struct, overriding the existing
879 settings if they are not defaults */
880 config_app_settings_copy_non_defaults(app
, settings
);
884 if (settings
->shade
!= -1)
885 self
->shaded
= !!settings
->shade
;
886 if (settings
->decor
!= -1)
887 self
->undecorated
= !settings
->decor
;
888 if (settings
->iconic
!= -1)
889 self
->iconic
= !!settings
->iconic
;
890 if (settings
->skip_pager
!= -1)
891 self
->skip_pager
= !!settings
->skip_pager
;
892 if (settings
->skip_taskbar
!= -1)
893 self
->skip_taskbar
= !!settings
->skip_taskbar
;
895 if (settings
->max_vert
!= -1)
896 self
->max_vert
= !!settings
->max_vert
;
897 if (settings
->max_horz
!= -1)
898 self
->max_horz
= !!settings
->max_horz
;
900 if (settings
->fullscreen
!= -1)
901 self
->fullscreen
= !!settings
->fullscreen
;
903 if (settings
->desktop
) {
904 if (settings
->desktop
== DESKTOP_ALL
)
905 self
->desktop
= settings
->desktop
;
906 else if (settings
->desktop
> 0 &&
907 settings
->desktop
<= screen_num_desktops
)
908 self
->desktop
= settings
->desktop
- 1;
911 if (settings
->layer
== -1) {
915 else if (settings
->layer
== 0) {
919 else if (settings
->layer
== 1) {
926 static void client_restore_session_state(ObClient
*self
)
930 ob_debug_type(OB_DEBUG_SM
,
931 "Restore session for client %s\n", self
->title
);
933 if (!(it
= session_state_find(self
))) {
934 ob_debug_type(OB_DEBUG_SM
,
935 "Session data not found for client %s\n", self
->title
);
939 self
->session
= it
->data
;
941 ob_debug_type(OB_DEBUG_SM
, "Session data loaded for client %s\n",
944 RECT_SET_POINT(self
->area
, self
->session
->x
, self
->session
->y
);
945 self
->positioned
= USPosition
;
946 self
->sized
= USSize
;
947 if (self
->session
->w
> 0)
948 self
->area
.width
= self
->session
->w
;
949 if (self
->session
->h
> 0)
950 self
->area
.height
= self
->session
->h
;
951 XResizeWindow(ob_display
, self
->window
,
952 self
->area
.width
, self
->area
.height
);
954 self
->desktop
= (self
->session
->desktop
== DESKTOP_ALL
?
955 self
->session
->desktop
:
956 MIN(screen_num_desktops
- 1, self
->session
->desktop
));
957 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, self
->desktop
);
959 self
->shaded
= self
->session
->shaded
;
960 self
->iconic
= self
->session
->iconic
;
961 self
->skip_pager
= self
->session
->skip_pager
;
962 self
->skip_taskbar
= self
->session
->skip_taskbar
;
963 self
->fullscreen
= self
->session
->fullscreen
;
964 self
->above
= self
->session
->above
;
965 self
->below
= self
->session
->below
;
966 self
->max_horz
= self
->session
->max_horz
;
967 self
->max_vert
= self
->session
->max_vert
;
968 self
->undecorated
= self
->session
->undecorated
;
971 static gboolean
client_restore_session_stacking(ObClient
*self
)
975 if (!self
->session
) return FALSE
;
977 mypos
= g_list_find(session_saved_state
, self
->session
);
978 if (!mypos
) return FALSE
;
980 /* start above me and look for the first client */
981 for (it
= g_list_previous(mypos
); it
; it
= g_list_previous(it
)) {
984 for (cit
= client_list
; cit
; cit
= g_list_next(cit
)) {
985 ObClient
*c
= cit
->data
;
986 /* found a client that was in the session, so go below it */
987 if (c
->session
== it
->data
) {
988 stacking_below(CLIENT_AS_WINDOW(self
),
989 CLIENT_AS_WINDOW(cit
->data
));
997 void client_move_onscreen(ObClient
*self
, gboolean rude
)
999 gint x
= self
->area
.x
;
1000 gint y
= self
->area
.y
;
1001 if (client_find_onscreen(self
, &x
, &y
,
1003 self
->area
.height
, rude
)) {
1004 client_move(self
, x
, y
);
1008 gboolean
client_find_onscreen(ObClient
*self
, gint
*x
, gint
*y
, gint w
, gint h
,
1011 gint ox
= *x
, oy
= *y
;
1012 gboolean rudel
= rude
, ruder
= rude
, rudet
= rude
, rudeb
= rude
;
1018 RECT_SET(desired
, *x
, *y
, w
, h
);
1019 frame_rect_to_frame(self
->frame
, &desired
);
1021 /* get where the frame would be */
1022 frame_client_gravity(self
->frame
, x
, y
);
1024 /* get the requested size of the window with decorations */
1025 fw
= self
->frame
->size
.left
+ w
+ self
->frame
->size
.right
;
1026 fh
= self
->frame
->size
.top
+ h
+ self
->frame
->size
.bottom
;
1028 /* If rudeness wasn't requested, then still be rude in a given direction
1029 if the client is not moving, only resizing in that direction */
1031 Point oldtl
, oldtr
, oldbl
, oldbr
;
1032 Point newtl
, newtr
, newbl
, newbr
;
1033 gboolean stationary_l
, stationary_r
, stationary_t
, stationary_b
;
1035 POINT_SET(oldtl
, self
->frame
->area
.x
, self
->frame
->area
.y
);
1036 POINT_SET(oldbr
, self
->frame
->area
.x
+ self
->frame
->area
.width
- 1,
1037 self
->frame
->area
.y
+ self
->frame
->area
.height
- 1);
1038 POINT_SET(oldtr
, oldbr
.x
, oldtl
.y
);
1039 POINT_SET(oldbl
, oldtl
.x
, oldbr
.y
);
1041 POINT_SET(newtl
, *x
, *y
);
1042 POINT_SET(newbr
, *x
+ fw
- 1, *y
+ fh
- 1);
1043 POINT_SET(newtr
, newbr
.x
, newtl
.y
);
1044 POINT_SET(newbl
, newtl
.x
, newbr
.y
);
1046 /* is it moving or just resizing from some corner? */
1047 stationary_l
= oldtl
.x
== newtl
.x
;
1048 stationary_r
= oldtr
.x
== newtr
.x
;
1049 stationary_t
= oldtl
.y
== newtl
.y
;
1050 stationary_b
= oldbl
.y
== newbl
.y
;
1052 /* if left edge is growing and didnt move right edge */
1053 if (stationary_r
&& newtl
.x
< oldtl
.x
)
1055 /* if right edge is growing and didnt move left edge */
1056 if (stationary_l
&& newtr
.x
> oldtr
.x
)
1058 /* if top edge is growing and didnt move bottom edge */
1059 if (stationary_b
&& newtl
.y
< oldtl
.y
)
1061 /* if bottom edge is growing and didnt move top edge */
1062 if (stationary_t
&& newbl
.y
> oldbl
.y
)
1066 /* we iterate through every monitor that the window is at least partially
1067 on, to make sure it is obeying the rules on them all
1069 if the window does not appear on any monitors, then use the first one
1072 for (i
= 0; i
< screen_num_monitors
; ++i
) {
1075 if (!screen_physical_area_monitor_contains(i
, &desired
)) {
1076 if (i
< screen_num_monitors
- 1 || found_mon
)
1079 /* the window is not inside any monitor! so just use the first
1081 a
= screen_area(self
->desktop
, 0, NULL
);
1084 a
= screen_area(self
->desktop
, SCREEN_AREA_ONE_MONITOR
, &desired
);
1087 /* This makes sure windows aren't entirely outside of the screen so you
1088 can't see them at all.
1089 It makes sure 10% of the window is on the screen at least. And don't
1090 let it move itself off the top of the screen, which would hide the
1091 titlebar on you. (The user can still do this if they want too, it's
1092 only limiting the application.
1094 if (client_normal(self
)) {
1095 if (!self
->strut
.right
&& *x
+ fw
/10 >= a
->x
+ a
->width
- 1)
1096 *x
= a
->x
+ a
->width
- fw
/10;
1097 if (!self
->strut
.bottom
&& *y
+ fh
/10 >= a
->y
+ a
->height
- 1)
1098 *y
= a
->y
+ a
->height
- fh
/10;
1099 if (!self
->strut
.left
&& *x
+ fw
*9/10 - 1 < a
->x
)
1100 *x
= a
->x
- fw
*9/10;
1101 if (!self
->strut
.top
&& *y
+ fh
*9/10 - 1 < a
->y
)
1102 *y
= a
->y
- fh
*9/10;
1105 /* This here doesn't let windows even a pixel outside the
1106 struts/screen. When called from client_manage, programs placing
1107 themselves are forced completely onscreen, while things like
1108 xterm -geometry resolution-width/2 will work fine. Trying to
1109 place it completely offscreen will be handled in the above code.
1110 Sorry for this confused comment, i am tired. */
1111 if (rudel
&& !self
->strut
.left
&& *x
< a
->x
) *x
= a
->x
;
1112 if (ruder
&& !self
->strut
.right
&& *x
+ fw
> a
->x
+ a
->width
)
1113 *x
= a
->x
+ MAX(0, a
->width
- fw
);
1115 if (rudet
&& !self
->strut
.top
&& *y
< a
->y
) *y
= a
->y
;
1116 if (rudeb
&& !self
->strut
.bottom
&& *y
+ fh
> a
->y
+ a
->height
)
1117 *y
= a
->y
+ MAX(0, a
->height
- fh
);
1122 /* get where the client should be */
1123 frame_frame_gravity(self
->frame
, x
, y
);
1125 return ox
!= *x
|| oy
!= *y
;
1128 static void client_get_all(ObClient
*self
, gboolean real
)
1130 /* this is needed for the frame to set itself up */
1131 client_get_area(self
);
1133 /* these things can change the decor and functions of the window */
1135 client_get_mwm_hints(self
);
1136 /* this can change the mwmhints for special cases */
1137 client_get_type_and_transientness(self
);
1138 client_get_state(self
);
1139 client_update_normal_hints(self
);
1141 /* get the session related properties, these can change decorations
1142 from per-app settings */
1143 client_get_session_ids(self
);
1145 /* now we got everything that can affect the decorations */
1149 /* get this early so we have it for debugging */
1150 client_update_title(self
);
1152 client_update_protocols(self
);
1154 client_update_wmhints(self
);
1155 /* this may have already been called from client_update_wmhints */
1156 if (!self
->parents
&& !self
->transient_for_group
)
1157 client_update_transient_for(self
);
1159 client_get_startup_id(self
);
1160 client_get_desktop(self
);/* uses transient data/group/startup id if a
1161 desktop is not specified */
1162 client_get_shaped(self
);
1165 /* a couple type-based defaults for new windows */
1167 /* this makes sure that these windows appear on all desktops */
1168 if (self
->type
== OB_CLIENT_TYPE_DESKTOP
)
1169 self
->desktop
= DESKTOP_ALL
;
1173 client_update_sync_request_counter(self
);
1176 client_get_colormap(self
);
1177 client_update_strut(self
);
1178 client_update_icons(self
);
1179 client_update_icon_geometry(self
);
1182 static void client_get_startup_id(ObClient
*self
)
1184 if (!(PROP_GETS(self
->window
, net_startup_id
, utf8
, &self
->startup_id
)))
1186 PROP_GETS(self
->group
->leader
,
1187 net_startup_id
, utf8
, &self
->startup_id
);
1190 static void client_get_area(ObClient
*self
)
1192 XWindowAttributes wattrib
;
1195 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
1196 g_assert(ret
!= BadWindow
);
1198 RECT_SET(self
->area
, wattrib
.x
, wattrib
.y
, wattrib
.width
, wattrib
.height
);
1199 POINT_SET(self
->root_pos
, wattrib
.x
, wattrib
.y
);
1200 self
->border_width
= wattrib
.border_width
;
1202 ob_debug("client area: %d %d %d %d bw %d\n", wattrib
.x
, wattrib
.y
,
1203 wattrib
.width
, wattrib
.height
, wattrib
.border_width
);
1206 static void client_get_desktop(ObClient
*self
)
1208 guint32 d
= screen_num_desktops
; /* an always-invalid value */
1210 if (PROP_GET32(self
->window
, net_wm_desktop
, cardinal
, &d
)) {
1211 if (d
>= screen_num_desktops
&& d
!= DESKTOP_ALL
)
1212 self
->desktop
= screen_num_desktops
- 1;
1215 ob_debug("client requested desktop 0x%x\n", self
->desktop
);
1218 gboolean first
= TRUE
;
1219 guint all
= screen_num_desktops
; /* not a valid value */
1221 /* if they are all on one desktop, then open it on the
1223 for (it
= self
->parents
; it
; it
= g_slist_next(it
)) {
1224 ObClient
*c
= it
->data
;
1226 if (c
->desktop
== DESKTOP_ALL
) continue;
1232 else if (all
!= c
->desktop
)
1233 all
= screen_num_desktops
; /* make it invalid */
1235 if (all
!= screen_num_desktops
) {
1236 self
->desktop
= all
;
1238 ob_debug("client desktop set from parents: 0x%x\n",
1241 /* try get from the startup-notification protocol */
1242 else if (sn_get_desktop(self
->startup_id
, &self
->desktop
)) {
1243 if (self
->desktop
>= screen_num_desktops
&&
1244 self
->desktop
!= DESKTOP_ALL
)
1245 self
->desktop
= screen_num_desktops
- 1;
1246 ob_debug("client desktop set from startup-notification: 0x%x\n",
1249 /* defaults to the current desktop */
1251 self
->desktop
= screen_desktop
;
1252 ob_debug("client desktop set to the current desktop: %d\n",
1258 static void client_get_state(ObClient
*self
)
1263 if (PROP_GETA32(self
->window
, net_wm_state
, atom
, &state
, &num
)) {
1265 for (i
= 0; i
< num
; ++i
) {
1266 if (state
[i
] == prop_atoms
.net_wm_state_modal
)
1268 else if (state
[i
] == prop_atoms
.net_wm_state_shaded
)
1269 self
->shaded
= TRUE
;
1270 else if (state
[i
] == prop_atoms
.net_wm_state_hidden
)
1271 self
->iconic
= TRUE
;
1272 else if (state
[i
] == prop_atoms
.net_wm_state_skip_taskbar
)
1273 self
->skip_taskbar
= TRUE
;
1274 else if (state
[i
] == prop_atoms
.net_wm_state_skip_pager
)
1275 self
->skip_pager
= TRUE
;
1276 else if (state
[i
] == prop_atoms
.net_wm_state_fullscreen
)
1277 self
->fullscreen
= TRUE
;
1278 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_vert
)
1279 self
->max_vert
= TRUE
;
1280 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_horz
)
1281 self
->max_horz
= TRUE
;
1282 else if (state
[i
] == prop_atoms
.net_wm_state_above
)
1284 else if (state
[i
] == prop_atoms
.net_wm_state_below
)
1286 else if (state
[i
] == prop_atoms
.net_wm_state_demands_attention
)
1287 self
->demands_attention
= TRUE
;
1288 else if (state
[i
] == prop_atoms
.ob_wm_state_undecorated
)
1289 self
->undecorated
= TRUE
;
1296 static void client_get_shaped(ObClient
*self
)
1298 self
->shaped
= FALSE
;
1300 if (extensions_shape
) {
1305 XShapeSelectInput(ob_display
, self
->window
, ShapeNotifyMask
);
1307 XShapeQueryExtents(ob_display
, self
->window
, &s
, &foo
,
1308 &foo
, &ufoo
, &ufoo
, &foo
, &foo
, &foo
, &ufoo
,
1315 void client_update_transient_for(ObClient
*self
)
1318 ObClient
*target
= NULL
;
1319 gboolean trangroup
= FALSE
;
1321 if (XGetTransientForHint(ob_display
, self
->window
, &t
)) {
1322 if (t
!= self
->window
) { /* can't be transient to itself! */
1323 target
= g_hash_table_lookup(window_map
, &t
);
1324 /* if this happens then we need to check for it */
1325 g_assert(target
!= self
);
1326 if (target
&& !WINDOW_IS_CLIENT(target
)) {
1327 /* watch out for windows with a parent that is something
1328 different, like a dockapp for example */
1333 /* Setting the transient_for to Root is actually illegal, however
1334 applications from time have done this to specify transient for
1336 if (!target
&& self
->group
&& t
== RootWindow(ob_display
, ob_screen
))
1338 } else if (self
->group
&& self
->transient
)
1341 client_update_transient_tree(self
, self
->group
, self
->group
,
1342 self
->transient_for_group
, trangroup
,
1343 client_direct_parent(self
), target
);
1344 self
->transient_for_group
= trangroup
;
1348 static void client_update_transient_tree(ObClient
*self
,
1349 ObGroup
*oldgroup
, ObGroup
*newgroup
,
1350 gboolean oldgtran
, gboolean newgtran
,
1351 ObClient
* oldparent
,
1352 ObClient
*newparent
)
1357 g_assert(!oldgtran
|| oldgroup
);
1358 g_assert(!newgtran
|| newgroup
);
1359 g_assert((!oldgtran
&& !oldparent
) ||
1360 (oldgtran
&& !oldparent
) ||
1361 (!oldgtran
&& oldparent
));
1362 g_assert((!newgtran
&& !newparent
) ||
1363 (newgtran
&& !newparent
) ||
1364 (!newgtran
&& newparent
));
1367 Group transient windows are not allowed to have other group
1368 transient windows as their children.
1372 /* No change has occured */
1373 if (oldgroup
== newgroup
&&
1374 oldgtran
== newgtran
&&
1375 oldparent
== newparent
) return;
1377 /** Remove the client from the transient tree **/
1379 for (it
= self
->transients
; it
; it
= next
) {
1380 next
= g_slist_next(it
);
1382 self
->transients
= g_slist_delete_link(self
->transients
, it
);
1383 c
->parents
= g_slist_remove(c
->parents
, self
);
1385 for (it
= self
->parents
; it
; it
= next
) {
1386 next
= g_slist_next(it
);
1388 self
->parents
= g_slist_delete_link(self
->parents
, it
);
1389 c
->transients
= g_slist_remove(c
->transients
, self
);
1392 /** Re-add the client to the transient tree **/
1394 /* If we're transient for a group then we need to add ourselves to all our
1397 for (it
= newgroup
->members
; it
; it
= g_slist_next(it
)) {
1400 !client_search_top_direct_parent(c
)->transient_for_group
&&
1403 c
->transients
= g_slist_prepend(c
->transients
, self
);
1404 self
->parents
= g_slist_prepend(self
->parents
, c
);
1409 /* If we are now transient for a single window we need to add ourselves to
1412 WARNING: Cyclical transient-ness is possible if two windows are
1413 transient for eachother.
1415 else if (newparent
&&
1416 /* don't make ourself its child if it is already our child */
1417 !client_is_direct_child(self
, newparent
) &&
1418 client_normal(newparent
))
1420 newparent
->transients
= g_slist_prepend(newparent
->transients
, self
);
1421 self
->parents
= g_slist_prepend(self
->parents
, newparent
);
1424 /* Add any group transient windows to our children. But if we're transient
1425 for the group, then other group transients are not our children.
1427 WARNING: Cyclical transient-ness is possible. For e.g. if:
1428 A is transient for the group
1429 B is transient for A
1430 C is transient for B
1431 A can't be transient for C or we have a cycle
1433 if (!newgtran
&& newgroup
&&
1435 !client_search_top_direct_parent(newparent
)->transient_for_group
) &&
1436 client_normal(self
))
1438 for (it
= newgroup
->members
; it
; it
= g_slist_next(it
)) {
1440 if (c
!= self
&& c
->transient_for_group
&&
1441 /* Don't make it our child if it is already our parent */
1442 !client_is_direct_child(c
, self
))
1444 self
->transients
= g_slist_prepend(self
->transients
, c
);
1445 c
->parents
= g_slist_prepend(c
->parents
, self
);
1450 /** If we change our group transient-ness, our children change their
1451 effective group transient-ness, which affects how they relate to other
1454 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
1456 if (!c
->transient_for_group
)
1457 client_update_transient_tree(c
, c
->group
, c
->group
,
1458 c
->transient_for_group
,
1459 c
->transient_for_group
,
1460 client_direct_parent(c
),
1461 client_direct_parent(c
));
1465 static void client_get_mwm_hints(ObClient
*self
)
1470 self
->mwmhints
.flags
= 0; /* default to none */
1472 if (PROP_GETA32(self
->window
, motif_wm_hints
, motif_wm_hints
,
1474 if (num
>= OB_MWM_ELEMENTS
) {
1475 self
->mwmhints
.flags
= hints
[0];
1476 self
->mwmhints
.functions
= hints
[1];
1477 self
->mwmhints
.decorations
= hints
[2];
1483 void client_get_type_and_transientness(ObClient
*self
)
1490 self
->transient
= FALSE
;
1492 if (PROP_GETA32(self
->window
, net_wm_window_type
, atom
, &val
, &num
)) {
1493 /* use the first value that we know about in the array */
1494 for (i
= 0; i
< num
; ++i
) {
1495 if (val
[i
] == prop_atoms
.net_wm_window_type_desktop
)
1496 self
->type
= OB_CLIENT_TYPE_DESKTOP
;
1497 else if (val
[i
] == prop_atoms
.net_wm_window_type_dock
)
1498 self
->type
= OB_CLIENT_TYPE_DOCK
;
1499 else if (val
[i
] == prop_atoms
.net_wm_window_type_toolbar
)
1500 self
->type
= OB_CLIENT_TYPE_TOOLBAR
;
1501 else if (val
[i
] == prop_atoms
.net_wm_window_type_menu
)
1502 self
->type
= OB_CLIENT_TYPE_MENU
;
1503 else if (val
[i
] == prop_atoms
.net_wm_window_type_utility
)
1504 self
->type
= OB_CLIENT_TYPE_UTILITY
;
1505 else if (val
[i
] == prop_atoms
.net_wm_window_type_splash
)
1506 self
->type
= OB_CLIENT_TYPE_SPLASH
;
1507 else if (val
[i
] == prop_atoms
.net_wm_window_type_dialog
)
1508 self
->type
= OB_CLIENT_TYPE_DIALOG
;
1509 else if (val
[i
] == prop_atoms
.net_wm_window_type_normal
)
1510 self
->type
= OB_CLIENT_TYPE_NORMAL
;
1511 else if (val
[i
] == prop_atoms
.kde_net_wm_window_type_override
) {
1512 /* prevent this window from getting any decor or
1514 self
->mwmhints
.flags
&= (OB_MWM_FLAG_FUNCTIONS
|
1515 OB_MWM_FLAG_DECORATIONS
);
1516 self
->mwmhints
.decorations
= 0;
1517 self
->mwmhints
.functions
= 0;
1519 if (self
->type
!= (ObClientType
) -1)
1520 break; /* grab the first legit type */
1525 if (XGetTransientForHint(ob_display
, self
->window
, &t
))
1526 self
->transient
= TRUE
;
1528 if (self
->type
== (ObClientType
) -1) {
1529 /*the window type hint was not set, which means we either classify
1530 ourself as a normal window or a dialog, depending on if we are a
1532 if (self
->transient
)
1533 self
->type
= OB_CLIENT_TYPE_DIALOG
;
1535 self
->type
= OB_CLIENT_TYPE_NORMAL
;
1538 /* then, based on our type, we can update our transientness.. */
1539 if (self
->type
== OB_CLIENT_TYPE_DIALOG
||
1540 self
->type
== OB_CLIENT_TYPE_TOOLBAR
||
1541 self
->type
== OB_CLIENT_TYPE_MENU
||
1542 self
->type
== OB_CLIENT_TYPE_UTILITY
)
1544 self
->transient
= TRUE
;
1548 void client_update_protocols(ObClient
*self
)
1551 guint num_return
, i
;
1553 self
->focus_notify
= FALSE
;
1554 self
->delete_window
= FALSE
;
1556 if (PROP_GETA32(self
->window
, wm_protocols
, atom
, &proto
, &num_return
)) {
1557 for (i
= 0; i
< num_return
; ++i
) {
1558 if (proto
[i
] == prop_atoms
.wm_delete_window
)
1559 /* this means we can request the window to close */
1560 self
->delete_window
= TRUE
;
1561 else if (proto
[i
] == prop_atoms
.wm_take_focus
)
1562 /* if this protocol is requested, then the window will be
1563 notified whenever we want it to receive focus */
1564 self
->focus_notify
= TRUE
;
1565 else if (proto
[i
] == prop_atoms
.net_wm_ping
)
1566 /* if this protocol is requested, then the window will allow
1567 pings to determine if it is still alive */
1570 else if (proto
[i
] == prop_atoms
.net_wm_sync_request
)
1571 /* if this protocol is requested, then resizing the
1572 window will be synchronized between the frame and the
1574 self
->sync_request
= TRUE
;
1582 void client_update_sync_request_counter(ObClient
*self
)
1586 if (PROP_GET32(self
->window
, net_wm_sync_request_counter
, cardinal
, &i
)) {
1587 self
->sync_counter
= i
;
1589 self
->sync_counter
= None
;
1593 static void client_get_colormap(ObClient
*self
)
1595 XWindowAttributes wa
;
1597 if (XGetWindowAttributes(ob_display
, self
->window
, &wa
))
1598 client_update_colormap(self
, wa
.colormap
);
1601 void client_update_colormap(ObClient
*self
, Colormap colormap
)
1603 if (colormap
== self
->colormap
) return;
1605 ob_debug("Setting client %s colormap: 0x%x\n", self
->title
, colormap
);
1607 if (client_focused(self
)) {
1608 screen_install_colormap(self
, FALSE
); /* uninstall old one */
1609 self
->colormap
= colormap
;
1610 screen_install_colormap(self
, TRUE
); /* install new one */
1612 self
->colormap
= colormap
;
1615 void client_update_normal_hints(ObClient
*self
)
1621 self
->min_ratio
= 0.0f
;
1622 self
->max_ratio
= 0.0f
;
1623 SIZE_SET(self
->size_inc
, 1, 1);
1624 SIZE_SET(self
->base_size
, -1, -1);
1625 SIZE_SET(self
->min_size
, 0, 0);
1626 SIZE_SET(self
->max_size
, G_MAXINT
, G_MAXINT
);
1628 /* get the hints from the window */
1629 if (XGetWMNormalHints(ob_display
, self
->window
, &size
, &ret
)) {
1630 /* normal windows can't request placement! har har
1631 if (!client_normal(self))
1633 self
->positioned
= (size
.flags
& (PPosition
|USPosition
));
1634 self
->sized
= (size
.flags
& (PSize
|USSize
));
1636 if (size
.flags
& PWinGravity
)
1637 self
->gravity
= size
.win_gravity
;
1639 if (size
.flags
& PAspect
) {
1640 if (size
.min_aspect
.y
)
1642 (gfloat
) size
.min_aspect
.x
/ size
.min_aspect
.y
;
1643 if (size
.max_aspect
.y
)
1645 (gfloat
) size
.max_aspect
.x
/ size
.max_aspect
.y
;
1648 if (size
.flags
& PMinSize
)
1649 SIZE_SET(self
->min_size
, size
.min_width
, size
.min_height
);
1651 if (size
.flags
& PMaxSize
)
1652 SIZE_SET(self
->max_size
, size
.max_width
, size
.max_height
);
1654 if (size
.flags
& PBaseSize
)
1655 SIZE_SET(self
->base_size
, size
.base_width
, size
.base_height
);
1657 if (size
.flags
& PResizeInc
&& size
.width_inc
&& size
.height_inc
)
1658 SIZE_SET(self
->size_inc
, size
.width_inc
, size
.height_inc
);
1660 ob_debug("Normal hints: min size (%d %d) max size (%d %d)\n "
1661 "size inc (%d %d) base size (%d %d)\n",
1662 self
->min_size
.width
, self
->min_size
.height
,
1663 self
->max_size
.width
, self
->max_size
.height
,
1664 self
->size_inc
.width
, self
->size_inc
.height
,
1665 self
->base_size
.width
, self
->base_size
.height
);
1668 ob_debug("Normal hints: not set\n");
1671 void client_setup_decor_and_functions(ObClient
*self
, gboolean reconfig
)
1673 /* start with everything (cept fullscreen) */
1675 (OB_FRAME_DECOR_TITLEBAR
|
1676 OB_FRAME_DECOR_HANDLE
|
1677 OB_FRAME_DECOR_GRIPS
|
1678 OB_FRAME_DECOR_BORDER
|
1679 OB_FRAME_DECOR_ICON
|
1680 OB_FRAME_DECOR_ALLDESKTOPS
|
1681 OB_FRAME_DECOR_ICONIFY
|
1682 OB_FRAME_DECOR_MAXIMIZE
|
1683 OB_FRAME_DECOR_SHADE
|
1684 OB_FRAME_DECOR_CLOSE
);
1686 (OB_CLIENT_FUNC_RESIZE
|
1687 OB_CLIENT_FUNC_MOVE
|
1688 OB_CLIENT_FUNC_ICONIFY
|
1689 OB_CLIENT_FUNC_MAXIMIZE
|
1690 OB_CLIENT_FUNC_SHADE
|
1691 OB_CLIENT_FUNC_CLOSE
|
1692 OB_CLIENT_FUNC_BELOW
|
1693 OB_CLIENT_FUNC_ABOVE
|
1694 OB_CLIENT_FUNC_UNDECORATE
);
1696 if (!(self
->min_size
.width
< self
->max_size
.width
||
1697 self
->min_size
.height
< self
->max_size
.height
))
1698 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
1700 switch (self
->type
) {
1701 case OB_CLIENT_TYPE_NORMAL
:
1702 /* normal windows retain all of the possible decorations and
1703 functionality, and can be fullscreen */
1704 self
->functions
|= OB_CLIENT_FUNC_FULLSCREEN
;
1707 case OB_CLIENT_TYPE_DIALOG
:
1708 /* sometimes apps make dialog windows fullscreen for some reason (for
1709 e.g. kpdf does this..) */
1710 self
->functions
|= OB_CLIENT_FUNC_FULLSCREEN
;
1713 case OB_CLIENT_TYPE_UTILITY
:
1714 /* these windows don't have anything added or removed by default */
1717 case OB_CLIENT_TYPE_MENU
:
1718 case OB_CLIENT_TYPE_TOOLBAR
:
1719 /* these windows can't iconify or maximize */
1720 self
->decorations
&= ~(OB_FRAME_DECOR_ICONIFY
|
1721 OB_FRAME_DECOR_MAXIMIZE
);
1722 self
->functions
&= ~(OB_CLIENT_FUNC_ICONIFY
|
1723 OB_CLIENT_FUNC_MAXIMIZE
);
1726 case OB_CLIENT_TYPE_SPLASH
:
1727 /* these don't get get any decorations, and the only thing you can
1728 do with them is move them */
1729 self
->decorations
= 0;
1730 self
->functions
= OB_CLIENT_FUNC_MOVE
;
1733 case OB_CLIENT_TYPE_DESKTOP
:
1734 /* these windows are not manipulated by the window manager */
1735 self
->decorations
= 0;
1736 self
->functions
= 0;
1739 case OB_CLIENT_TYPE_DOCK
:
1740 /* these windows are not manipulated by the window manager, but they
1741 can set below layer which has a special meaning */
1742 self
->decorations
= 0;
1743 self
->functions
= OB_CLIENT_FUNC_BELOW
;
1747 /* Mwm Hints are applied subtractively to what has already been chosen for
1748 decor and functionality */
1749 if (self
->mwmhints
.flags
& OB_MWM_FLAG_DECORATIONS
) {
1750 if (! (self
->mwmhints
.decorations
& OB_MWM_DECOR_ALL
)) {
1751 if (! ((self
->mwmhints
.decorations
& OB_MWM_DECOR_HANDLE
) ||
1752 (self
->mwmhints
.decorations
& OB_MWM_DECOR_TITLE
)))
1754 /* if the mwm hints request no handle or title, then all
1755 decorations are disabled, but keep the border if that's
1757 if (self
->mwmhints
.decorations
& OB_MWM_DECOR_BORDER
)
1758 self
->decorations
= OB_FRAME_DECOR_BORDER
;
1760 self
->decorations
= 0;
1765 if (self
->mwmhints
.flags
& OB_MWM_FLAG_FUNCTIONS
) {
1766 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_ALL
)) {
1767 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_RESIZE
))
1768 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
1769 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_MOVE
))
1770 self
->functions
&= ~OB_CLIENT_FUNC_MOVE
;
1771 /* dont let mwm hints kill any buttons
1772 if (! (self->mwmhints.functions & OB_MWM_FUNC_ICONIFY))
1773 self->functions &= ~OB_CLIENT_FUNC_ICONIFY;
1774 if (! (self->mwmhints.functions & OB_MWM_FUNC_MAXIMIZE))
1775 self->functions &= ~OB_CLIENT_FUNC_MAXIMIZE;
1777 /* dont let mwm hints kill the close button
1778 if (! (self->mwmhints.functions & MwmFunc_Close))
1779 self->functions &= ~OB_CLIENT_FUNC_CLOSE; */
1783 if (!(self
->functions
& OB_CLIENT_FUNC_SHADE
))
1784 self
->decorations
&= ~OB_FRAME_DECOR_SHADE
;
1785 if (!(self
->functions
& OB_CLIENT_FUNC_ICONIFY
))
1786 self
->decorations
&= ~OB_FRAME_DECOR_ICONIFY
;
1787 if (!(self
->functions
& OB_CLIENT_FUNC_RESIZE
))
1788 self
->decorations
&= ~(OB_FRAME_DECOR_GRIPS
| OB_FRAME_DECOR_HANDLE
);
1790 /* can't maximize without moving/resizing */
1791 if (!((self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) &&
1792 (self
->functions
& OB_CLIENT_FUNC_MOVE
) &&
1793 (self
->functions
& OB_CLIENT_FUNC_RESIZE
))) {
1794 self
->functions
&= ~OB_CLIENT_FUNC_MAXIMIZE
;
1795 self
->decorations
&= ~OB_FRAME_DECOR_MAXIMIZE
;
1798 if (self
->max_horz
&& self
->max_vert
) {
1799 /* you can't resize fully maximized windows */
1800 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
1801 /* kill the handle on fully maxed windows */
1802 self
->decorations
&= ~(OB_FRAME_DECOR_HANDLE
| OB_FRAME_DECOR_GRIPS
);
1805 /* If there are no decorations to remove, don't allow the user to try
1807 if (self
->decorations
== 0)
1808 self
->functions
&= ~OB_CLIENT_FUNC_UNDECORATE
;
1810 /* finally, the user can have requested no decorations, which overrides
1811 everything (but doesnt give it a border if it doesnt have one) */
1812 if (self
->undecorated
)
1813 self
->decorations
= 0;
1815 /* if we don't have a titlebar, then we cannot shade! */
1816 if (!(self
->decorations
& OB_FRAME_DECOR_TITLEBAR
))
1817 self
->functions
&= ~OB_CLIENT_FUNC_SHADE
;
1819 /* now we need to check against rules for the client's current state */
1820 if (self
->fullscreen
) {
1821 self
->functions
&= (OB_CLIENT_FUNC_CLOSE
|
1822 OB_CLIENT_FUNC_FULLSCREEN
|
1823 OB_CLIENT_FUNC_ICONIFY
);
1824 self
->decorations
= 0;
1827 client_change_allowed_actions(self
);
1830 /* force reconfigure to make sure decorations are updated */
1831 client_reconfigure(self
, TRUE
);
1834 static void client_change_allowed_actions(ObClient
*self
)
1839 /* desktop windows are kept on all desktops */
1840 if (self
->type
!= OB_CLIENT_TYPE_DESKTOP
)
1841 actions
[num
++] = prop_atoms
.net_wm_action_change_desktop
;
1843 if (self
->functions
& OB_CLIENT_FUNC_SHADE
)
1844 actions
[num
++] = prop_atoms
.net_wm_action_shade
;
1845 if (self
->functions
& OB_CLIENT_FUNC_CLOSE
)
1846 actions
[num
++] = prop_atoms
.net_wm_action_close
;
1847 if (self
->functions
& OB_CLIENT_FUNC_MOVE
)
1848 actions
[num
++] = prop_atoms
.net_wm_action_move
;
1849 if (self
->functions
& OB_CLIENT_FUNC_ICONIFY
)
1850 actions
[num
++] = prop_atoms
.net_wm_action_minimize
;
1851 if (self
->functions
& OB_CLIENT_FUNC_RESIZE
)
1852 actions
[num
++] = prop_atoms
.net_wm_action_resize
;
1853 if (self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
)
1854 actions
[num
++] = prop_atoms
.net_wm_action_fullscreen
;
1855 if (self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) {
1856 actions
[num
++] = prop_atoms
.net_wm_action_maximize_horz
;
1857 actions
[num
++] = prop_atoms
.net_wm_action_maximize_vert
;
1859 if (self
->functions
& OB_CLIENT_FUNC_ABOVE
)
1860 actions
[num
++] = prop_atoms
.net_wm_action_above
;
1861 if (self
->functions
& OB_CLIENT_FUNC_BELOW
)
1862 actions
[num
++] = prop_atoms
.net_wm_action_below
;
1863 if (self
->functions
& OB_CLIENT_FUNC_UNDECORATE
)
1864 actions
[num
++] = prop_atoms
.ob_wm_action_undecorate
;
1866 PROP_SETA32(self
->window
, net_wm_allowed_actions
, atom
, actions
, num
);
1868 /* make sure the window isn't breaking any rules now
1870 don't check ICONIFY here. just cuz a window can't iconify doesnt mean
1871 it can't be iconified with its parent
1874 if (!(self
->functions
& OB_CLIENT_FUNC_SHADE
) && self
->shaded
) {
1875 if (self
->frame
) client_shade(self
, FALSE
);
1876 else self
->shaded
= FALSE
;
1878 if (!(self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
) && self
->fullscreen
) {
1879 if (self
->frame
) client_fullscreen(self
, FALSE
);
1880 else self
->fullscreen
= FALSE
;
1882 if (!(self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) && (self
->max_horz
||
1884 if (self
->frame
) client_maximize(self
, FALSE
, 0);
1885 else self
->max_vert
= self
->max_horz
= FALSE
;
1889 void client_update_wmhints(ObClient
*self
)
1893 /* assume a window takes input if it doesn't specify */
1894 self
->can_focus
= TRUE
;
1896 if ((hints
= XGetWMHints(ob_display
, self
->window
)) != NULL
) {
1899 if (hints
->flags
& InputHint
)
1900 self
->can_focus
= hints
->input
;
1902 /* only do this when first managing the window *AND* when we aren't
1904 if (ob_state() != OB_STATE_STARTING
&& self
->frame
== NULL
)
1905 if (hints
->flags
& StateHint
)
1906 self
->iconic
= hints
->initial_state
== IconicState
;
1909 self
->urgent
= (hints
->flags
& XUrgencyHint
);
1910 if (self
->urgent
&& !ur
)
1911 client_hilite(self
, TRUE
);
1912 else if (!self
->urgent
&& ur
&& self
->demands_attention
)
1913 client_hilite(self
, FALSE
);
1915 if (!(hints
->flags
& WindowGroupHint
))
1916 hints
->window_group
= None
;
1918 /* did the group state change? */
1919 if (hints
->window_group
!=
1920 (self
->group
? self
->group
->leader
: None
))
1922 ObGroup
*oldgroup
= self
->group
;
1924 /* remove from the old group if there was one */
1926 group_remove(self
->group
, self
);
1930 /* add ourself to the group if we have one */
1931 if (hints
->window_group
!= None
) {
1932 self
->group
= group_add(hints
->window_group
, self
);
1935 /* Put ourselves into the new group's transient tree, and remove
1936 ourselves from the old group's */
1937 client_update_transient_tree(self
, oldgroup
, self
->group
,
1938 self
->transient_for_group
,
1939 self
->transient_for_group
,
1940 client_direct_parent(self
),
1941 client_direct_parent(self
));
1943 /* Lastly, being in a group, or not, can change if the window is
1944 transient for anything.
1946 The logic for this is:
1947 self->transient = TRUE always if the window wants to be
1948 transient for something, even if transient_for was NULL because
1949 it wasn't in a group before.
1951 If parents was NULL and oldgroup was NULL we can assume
1952 that when we add the new group, it will become transient for
1955 If transient_for_group is TRUE, then it must have already
1956 had a group. If it is getting a new group, the above call to
1957 client_update_transient_tree has already taken care of
1958 everything ! If it is losing all group status then it will
1959 no longer be transient for anything and that needs to be
1962 if (self
->transient
&&
1963 ((self
->parents
== NULL
&& oldgroup
== NULL
) ||
1964 (self
->transient_for_group
&& !self
->group
)))
1965 client_update_transient_for(self
);
1968 /* the WM_HINTS can contain an icon */
1969 if (hints
->flags
& IconPixmapHint
)
1970 client_update_icons(self
);
1976 void client_update_title(ObClient
*self
)
1979 gchar
*visible
= NULL
;
1981 g_free(self
->title
);
1982 g_free(self
->original_title
);
1985 if (!PROP_GETS(self
->window
, net_wm_name
, utf8
, &data
)) {
1986 /* try old x stuff */
1987 if (!(PROP_GETS(self
->window
, wm_name
, locale
, &data
)
1988 || PROP_GETS(self
->window
, wm_name
, utf8
, &data
))) {
1989 if (self
->transient
) {
1991 GNOME alert windows are not given titles:
1992 http://developer.gnome.org/projects/gup/hig/draft_hig_new/windows-alert.html
1994 data
= g_strdup("");
1996 data
= g_strdup(_("Unnamed Window"));
1999 self
->original_title
= g_strdup(data
);
2001 if (self
->client_machine
) {
2002 visible
= g_strdup_printf("%s (%s)", data
, self
->client_machine
);
2007 if (self
->not_responding
) {
2009 if (self
->kill_level
> 0)
2010 visible
= g_strdup_printf("%s - [%s]", data
, _("Killing..."));
2012 visible
= g_strdup_printf("%s - [%s]", data
, _("Not Responding"));
2016 PROP_SETS(self
->window
, net_wm_visible_name
, visible
);
2017 self
->title
= visible
;
2020 frame_adjust_title(self
->frame
);
2022 /* update the icon title */
2024 g_free(self
->icon_title
);
2027 if (!PROP_GETS(self
->window
, net_wm_icon_name
, utf8
, &data
))
2028 /* try old x stuff */
2029 if (!(PROP_GETS(self
->window
, wm_icon_name
, locale
, &data
) ||
2030 PROP_GETS(self
->window
, wm_icon_name
, utf8
, &data
)))
2031 data
= g_strdup(self
->title
);
2033 if (self
->client_machine
) {
2034 visible
= g_strdup_printf("%s (%s)", data
, self
->client_machine
);
2039 if (self
->not_responding
) {
2041 if (self
->kill_level
> 0)
2042 visible
= g_strdup_printf("%s - [%s]", data
, _("Killing..."));
2044 visible
= g_strdup_printf("%s - [%s]", data
, _("Not Responding"));
2048 PROP_SETS(self
->window
, net_wm_visible_icon_name
, visible
);
2049 self
->icon_title
= visible
;
2052 void client_update_strut(ObClient
*self
)
2056 gboolean got
= FALSE
;
2059 if (PROP_GETA32(self
->window
, net_wm_strut_partial
, cardinal
,
2063 STRUT_PARTIAL_SET(strut
,
2064 data
[0], data
[2], data
[1], data
[3],
2065 data
[4], data
[5], data
[8], data
[9],
2066 data
[6], data
[7], data
[10], data
[11]);
2072 PROP_GETA32(self
->window
, net_wm_strut
, cardinal
, &data
, &num
)) {
2078 /* use the screen's width/height */
2079 a
= screen_physical_area_all_monitors();
2081 STRUT_PARTIAL_SET(strut
,
2082 data
[0], data
[2], data
[1], data
[3],
2083 a
->y
, a
->y
+ a
->height
- 1,
2084 a
->x
, a
->x
+ a
->width
- 1,
2085 a
->y
, a
->y
+ a
->height
- 1,
2086 a
->x
, a
->x
+ a
->width
- 1);
2093 STRUT_PARTIAL_SET(strut
, 0, 0, 0, 0,
2094 0, 0, 0, 0, 0, 0, 0, 0);
2096 if (!STRUT_EQUAL(strut
, self
->strut
)) {
2097 self
->strut
= strut
;
2099 /* updating here is pointless while we're being mapped cuz we're not in
2100 the client list yet */
2102 screen_update_areas();
2106 void client_update_icons(ObClient
*self
)
2111 guint num_seen
; /* number of icons present */
2116 /* grab the server, because we might be setting the window's icon and
2117 we don't want them to set it in between and we overwrite their own
2121 if (PROP_GETA32(self
->window
, net_wm_icon
, cardinal
, &data
, &num
)) {
2122 /* figure out how many valid icons are in here */
2125 while (i
+ 2 < num
) { /* +2 is to make sure there is a w and h */
2128 /* watch for the data being too small for the specified size,
2129 or for zero sized icons. */
2130 if (i
+ w
*h
> num
|| w
== 0 || h
== 0) break;
2132 /* convert it to the right bit order for ObRender */
2133 for (j
= 0; j
< w
*h
; ++j
)
2135 (((data
[i
+j
] >> 24) & 0xff) << RrDefaultAlphaOffset
) +
2136 (((data
[i
+j
] >> 16) & 0xff) << RrDefaultRedOffset
) +
2137 (((data
[i
+j
] >> 8) & 0xff) << RrDefaultGreenOffset
) +
2138 (((data
[i
+j
] >> 0) & 0xff) << RrDefaultBlueOffset
);
2140 /* is it in the cache? */
2141 img
= RrImageCacheFind(ob_rr_icons
, &data
[i
], w
, h
);
2142 if (img
) RrImageRef(img
); /* own it */
2147 /* don't bother looping anymore if we already found it in the cache
2148 since we'll just use that! */
2152 /* if it's not in the cache yet, then add it to the cache now.
2153 we have already converted it to the correct bit order above */
2154 if (!img
&& num_seen
> 0) {
2155 img
= RrImageNew(ob_rr_icons
);
2157 for (j
= 0; j
< num_seen
; ++j
) {
2160 RrImageAddPicture(img
, &data
[i
], w
, h
);
2168 /* if we didn't find an image from the NET_WM_ICON stuff, then try the
2173 if ((hints
= XGetWMHints(ob_display
, self
->window
))) {
2174 if (hints
->flags
& IconPixmapHint
) {
2176 xerror_set_ignore(TRUE
);
2177 xicon
= RrPixmapToRGBA(ob_rr_inst
,
2179 (hints
->flags
& IconMaskHint
?
2180 hints
->icon_mask
: None
),
2181 (gint
*)&w
, (gint
*)&h
, &data
);
2182 xerror_set_ignore(FALSE
);
2186 if (w
> 0 && h
> 0) {
2187 /* is this icon in the cache yet? */
2188 img
= RrImageCacheFind(ob_rr_icons
, data
, w
, h
);
2189 if (img
) RrImageRef(img
); /* own it */
2191 /* if not, then add it */
2193 img
= RrImageNew(ob_rr_icons
);
2194 RrImageAddPicture(img
, data
, w
, h
);
2205 /* set the client's icons to be whatever we found */
2206 RrImageUnref(self
->icon_set
);
2207 self
->icon_set
= img
;
2209 /* if the client has no icon at all, then we set a default icon onto it.
2210 but, if it has parents, then one of them will have an icon already
2212 if (!self
->icon_set
&& !self
->parents
) {
2213 RrPixel32
*icon
= ob_rr_theme
->def_win_icon
;
2214 gulong
*ldata
; /* use a long here to satisfy OBT_PROP_SETA32 */
2216 w
= ob_rr_theme
->def_win_icon_w
;
2217 h
= ob_rr_theme
->def_win_icon_h
;
2218 ldata
= g_new(gulong
, w
*h
+2);
2221 for (i
= 0; i
< w
*h
; ++i
)
2222 ldata
[i
+2] = (((icon
[i
] >> RrDefaultAlphaOffset
) & 0xff) << 24) +
2223 (((icon
[i
] >> RrDefaultRedOffset
) & 0xff) << 16) +
2224 (((icon
[i
] >> RrDefaultGreenOffset
) & 0xff) << 8) +
2225 (((icon
[i
] >> RrDefaultBlueOffset
) & 0xff) << 0);
2226 PROP_SETA32(self
->window
, net_wm_icon
, cardinal
, ldata
, w
*h
+2);
2228 } else if (self
->frame
)
2229 /* don't draw the icon empty if we're just setting one now anyways,
2230 we'll get the property change any second */
2231 frame_adjust_icon(self
->frame
);
2236 void client_update_icon_geometry(ObClient
*self
)
2241 RECT_SET(self
->icon_geometry
, 0, 0, 0, 0);
2243 if (PROP_GETA32(self
->window
, net_wm_icon_geometry
, cardinal
, &data
, &num
))
2246 /* don't let them set it with an area < 0 */
2247 RECT_SET(self
->icon_geometry
, data
[0], data
[1],
2248 MAX(data
[2],0), MAX(data
[3],0));
2253 static void client_get_session_ids(ObClient
*self
)
2260 if (!PROP_GET32(self
->window
, wm_client_leader
, window
, &leader
))
2263 /* get the SM_CLIENT_ID */
2266 got
= PROP_GETS(leader
, sm_client_id
, locale
, &self
->sm_client_id
);
2268 PROP_GETS(self
->window
, sm_client_id
, locale
, &self
->sm_client_id
);
2270 /* get the WM_CLASS (name and class). make them "" if they are not
2274 got
= PROP_GETSS(leader
, wm_class
, locale
, &ss
);
2276 got
= PROP_GETSS(self
->window
, wm_class
, locale
, &ss
);
2280 self
->name
= g_strdup(ss
[0]);
2282 self
->class = g_strdup(ss
[1]);
2287 if (self
->name
== NULL
) self
->name
= g_strdup("");
2288 if (self
->class == NULL
) self
->class = g_strdup("");
2290 /* get the WM_WINDOW_ROLE. make it "" if it is not provided */
2293 got
= PROP_GETS(leader
, wm_window_role
, locale
, &s
);
2295 got
= PROP_GETS(self
->window
, wm_window_role
, locale
, &s
);
2300 self
->role
= g_strdup("");
2302 /* get the WM_COMMAND */
2306 got
= PROP_GETSS(leader
, wm_command
, locale
, &ss
);
2308 got
= PROP_GETSS(self
->window
, wm_command
, locale
, &ss
);
2311 /* merge/mash them all together */
2312 gchar
*merge
= NULL
;
2315 for (i
= 0; ss
[i
]; ++i
) {
2318 merge
= g_strconcat(merge
, ss
[i
], NULL
);
2320 merge
= g_strconcat(ss
[i
], NULL
);
2325 self
->wm_command
= merge
;
2328 /* get the WM_CLIENT_MACHINE */
2331 got
= PROP_GETS(leader
, wm_client_machine
, locale
, &s
);
2333 got
= PROP_GETS(self
->window
, wm_client_machine
, locale
, &s
);
2336 gchar localhost
[128];
2339 gethostname(localhost
, 127);
2340 localhost
[127] = '\0';
2341 if (strcmp(localhost
, s
) != 0)
2342 self
->client_machine
= s
;
2346 /* see if it has the PID set too (the PID requires that the
2347 WM_CLIENT_MACHINE be set) */
2348 if (PROP_GET32(self
->window
, net_wm_pid
, cardinal
, &pid
))
2353 static void client_change_wm_state(ObClient
*self
)
2358 old
= self
->wmstate
;
2360 if (self
->shaded
|| self
->iconic
||
2361 (self
->desktop
!= DESKTOP_ALL
&& self
->desktop
!= screen_desktop
))
2363 self
->wmstate
= IconicState
;
2365 self
->wmstate
= NormalState
;
2367 if (old
!= self
->wmstate
) {
2368 PROP_MSG(self
->window
, kde_wm_change_state
,
2369 self
->wmstate
, 1, 0, 0);
2371 state
[0] = self
->wmstate
;
2373 PROP_SETA32(self
->window
, wm_state
, wm_state
, state
, 2);
2377 static void client_change_state(ObClient
*self
)
2379 gulong netstate
[12];
2384 netstate
[num
++] = prop_atoms
.net_wm_state_modal
;
2386 netstate
[num
++] = prop_atoms
.net_wm_state_shaded
;
2388 netstate
[num
++] = prop_atoms
.net_wm_state_hidden
;
2389 if (self
->skip_taskbar
)
2390 netstate
[num
++] = prop_atoms
.net_wm_state_skip_taskbar
;
2391 if (self
->skip_pager
)
2392 netstate
[num
++] = prop_atoms
.net_wm_state_skip_pager
;
2393 if (self
->fullscreen
)
2394 netstate
[num
++] = prop_atoms
.net_wm_state_fullscreen
;
2396 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_vert
;
2398 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_horz
;
2400 netstate
[num
++] = prop_atoms
.net_wm_state_above
;
2402 netstate
[num
++] = prop_atoms
.net_wm_state_below
;
2403 if (self
->demands_attention
)
2404 netstate
[num
++] = prop_atoms
.net_wm_state_demands_attention
;
2405 if (self
->undecorated
)
2406 netstate
[num
++] = prop_atoms
.ob_wm_state_undecorated
;
2407 PROP_SETA32(self
->window
, net_wm_state
, atom
, netstate
, num
);
2410 frame_adjust_state(self
->frame
);
2413 ObClient
*client_search_focus_tree(ObClient
*self
)
2418 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
2419 if (client_focused(it
->data
)) return it
->data
;
2420 if ((ret
= client_search_focus_tree(it
->data
))) return ret
;
2425 ObClient
*client_search_focus_tree_full(ObClient
*self
)
2427 if (self
->parents
) {
2430 for (it
= self
->parents
; it
; it
= g_slist_next(it
)) {
2431 ObClient
*c
= it
->data
;
2432 if ((c
= client_search_focus_tree_full(it
->data
))) return c
;
2438 /* this function checks the whole tree, the client_search_focus_tree
2439 does not, so we need to check this window */
2440 if (client_focused(self
))
2442 return client_search_focus_tree(self
);
2446 ObClient
*client_search_focus_group_full(ObClient
*self
)
2451 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
2452 ObClient
*c
= it
->data
;
2454 if (client_focused(c
)) return c
;
2455 if ((c
= client_search_focus_tree(it
->data
))) return c
;
2458 if (client_focused(self
)) return self
;
2462 gboolean
client_has_parent(ObClient
*self
)
2464 return self
->parents
!= NULL
;
2467 static ObStackingLayer
calc_layer(ObClient
*self
)
2472 monitor
= screen_physical_area_monitor(client_monitor(self
));
2474 if (self
->type
== OB_CLIENT_TYPE_DESKTOP
)
2475 l
= OB_STACKING_LAYER_DESKTOP
;
2476 else if (self
->type
== OB_CLIENT_TYPE_DOCK
) {
2477 if (self
->below
) l
= OB_STACKING_LAYER_NORMAL
;
2478 else l
= OB_STACKING_LAYER_ABOVE
;
2480 else if ((self
->fullscreen
||
2481 /* No decorations and fills the monitor = oldskool fullscreen.
2482 But not for maximized windows.
2484 (self
->decorations
== 0 &&
2485 !(self
->max_horz
&& self
->max_vert
) &&
2486 RECT_EQUAL(self
->area
, *monitor
))) &&
2487 /* you are fullscreen while you or your children are focused.. */
2488 (client_focused(self
) || client_search_focus_tree(self
) ||
2489 /* you can be fullscreen if you're on another desktop */
2490 (self
->desktop
!= screen_desktop
&&
2491 self
->desktop
!= DESKTOP_ALL
) ||
2492 /* and you can also be fullscreen if the focused client is on
2493 another monitor, or nothing else is focused */
2495 client_monitor(focus_client
) != client_monitor(self
))))
2496 l
= OB_STACKING_LAYER_FULLSCREEN
;
2497 else if (self
->above
) l
= OB_STACKING_LAYER_ABOVE
;
2498 else if (self
->below
) l
= OB_STACKING_LAYER_BELOW
;
2499 else l
= OB_STACKING_LAYER_NORMAL
;
2506 static void client_calc_layer_recursive(ObClient
*self
, ObClient
*orig
,
2507 ObStackingLayer min
)
2509 ObStackingLayer old
, own
;
2513 own
= calc_layer(self
);
2514 self
->layer
= MAX(own
, min
);
2516 if (self
->layer
!= old
) {
2517 stacking_remove(CLIENT_AS_WINDOW(self
));
2518 stacking_add_nonintrusive(CLIENT_AS_WINDOW(self
));
2521 /* we've been restacked */
2522 self
->visited
= TRUE
;
2524 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
2525 client_calc_layer_recursive(it
->data
, orig
,
2529 static void client_calc_layer_internal(ObClient
*self
)
2533 /* transients take on the layer of their parents */
2534 sit
= client_search_all_top_parents(self
);
2536 for (; sit
; sit
= g_slist_next(sit
))
2537 client_calc_layer_recursive(sit
->data
, self
, 0);
2540 void client_calc_layer(ObClient
*self
)
2544 /* skip over stuff above fullscreen layer */
2545 for (it
= stacking_list
; it
; it
= g_list_next(it
))
2546 if (window_layer(it
->data
) <= OB_STACKING_LAYER_FULLSCREEN
) break;
2548 /* find the windows in the fullscreen layer, and mark them not-visited */
2549 for (; it
; it
= g_list_next(it
)) {
2550 if (window_layer(it
->data
) < OB_STACKING_LAYER_FULLSCREEN
) break;
2551 else if (WINDOW_IS_CLIENT(it
->data
))
2552 WINDOW_AS_CLIENT(it
->data
)->visited
= FALSE
;
2555 client_calc_layer_internal(self
);
2557 /* skip over stuff above fullscreen layer */
2558 for (it
= stacking_list
; it
; it
= g_list_next(it
))
2559 if (window_layer(it
->data
) <= OB_STACKING_LAYER_FULLSCREEN
) break;
2561 /* now recalc any windows in the fullscreen layer which have not
2562 had their layer recalced already */
2563 for (; it
; it
= g_list_next(it
)) {
2564 if (window_layer(it
->data
) < OB_STACKING_LAYER_FULLSCREEN
) break;
2565 else if (WINDOW_IS_CLIENT(it
->data
) &&
2566 !WINDOW_AS_CLIENT(it
->data
)->visited
)
2567 client_calc_layer_internal(it
->data
);
2571 gboolean
client_should_show(ObClient
*self
)
2575 if (client_normal(self
) && screen_showing_desktop
)
2577 if (self
->desktop
== screen_desktop
|| self
->desktop
== DESKTOP_ALL
)
2583 gboolean
client_show(ObClient
*self
)
2585 gboolean show
= FALSE
;
2587 if (client_should_show(self
)) {
2588 /* replay pending pointer event before showing the window, in case it
2589 should be going to something under the window */
2590 mouse_replay_pointer();
2592 frame_show(self
->frame
);
2595 /* According to the ICCCM (sec 4.1.3.1) when a window is not visible,
2596 it needs to be in IconicState. This includes when it is on another
2599 client_change_wm_state(self
);
2604 gboolean
client_hide(ObClient
*self
)
2606 gboolean hide
= FALSE
;
2608 if (!client_should_show(self
)) {
2609 if (self
== focus_client
) {
2610 event_cancel_all_key_grabs();
2613 /* We don't need to ignore enter events here.
2614 The window can hide/iconify in 3 different ways:
2615 1 - through an x message. in this case we ignore all enter events
2616 caused by responding to the x message (unless underMouse)
2617 2 - by a keyboard action. in this case we ignore all enter events
2618 caused by the action
2619 3 - by a mouse action. in this case they are doing stuff with the
2620 mouse and focus _should_ move.
2622 Also in action_end, we simulate an enter event that can't be ignored
2623 so trying to ignore them is futile in case 3 anyways
2626 /* replay pending pointer event before hiding the window, in case it
2627 should be going to the window */
2628 mouse_replay_pointer();
2630 frame_hide(self
->frame
);
2633 /* According to the ICCCM (sec 4.1.3.1) when a window is not visible,
2634 it needs to be in IconicState. This includes when it is on another
2637 client_change_wm_state(self
);
2642 void client_showhide(ObClient
*self
)
2644 if (!client_show(self
))
2648 gboolean
client_normal(ObClient
*self
) {
2649 return ! (self
->type
== OB_CLIENT_TYPE_DESKTOP
||
2650 self
->type
== OB_CLIENT_TYPE_DOCK
||
2651 self
->type
== OB_CLIENT_TYPE_SPLASH
);
2654 gboolean
client_helper(ObClient
*self
)
2656 return (self
->type
== OB_CLIENT_TYPE_UTILITY
||
2657 self
->type
== OB_CLIENT_TYPE_MENU
||
2658 self
->type
== OB_CLIENT_TYPE_TOOLBAR
);
2661 gboolean
client_mouse_focusable(ObClient
*self
)
2663 return !(self
->type
== OB_CLIENT_TYPE_MENU
||
2664 self
->type
== OB_CLIENT_TYPE_TOOLBAR
||
2665 self
->type
== OB_CLIENT_TYPE_SPLASH
||
2666 self
->type
== OB_CLIENT_TYPE_DOCK
);
2669 gboolean
client_enter_focusable(ObClient
*self
)
2671 /* you can focus desktops but it shouldn't on enter */
2672 return (client_mouse_focusable(self
) &&
2673 self
->type
!= OB_CLIENT_TYPE_DESKTOP
);
2677 static void client_apply_startup_state(ObClient
*self
,
2678 gint x
, gint y
, gint w
, gint h
)
2680 /* save the states that we are going to apply */
2681 gboolean iconic
= self
->iconic
;
2682 gboolean fullscreen
= self
->fullscreen
;
2683 gboolean undecorated
= self
->undecorated
;
2684 gboolean shaded
= self
->shaded
;
2685 gboolean demands_attention
= self
->demands_attention
;
2686 gboolean max_horz
= self
->max_horz
;
2687 gboolean max_vert
= self
->max_vert
;
2691 /* turn them all off in the client, so they won't affect the window
2693 self
->iconic
= self
->fullscreen
= self
->undecorated
= self
->shaded
=
2694 self
->demands_attention
= self
->max_horz
= self
->max_vert
= FALSE
;
2696 /* move the client to its placed position, or it it's already there,
2697 generate a ConfigureNotify telling the client where it is.
2699 do this after adjusting the frame. otherwise it gets all weird and
2700 clients don't work right
2702 do this before applying the states so they have the correct
2703 pre-max/pre-fullscreen values
2705 client_try_configure(self
, &x
, &y
, &w
, &h
, &l
, &l
, FALSE
);
2706 ob_debug("placed window 0x%x at %d, %d with size %d x %d\n",
2707 self
->window
, x
, y
, w
, h
);
2708 /* save the area, and make it where it should be for the premax stuff */
2709 oldarea
= self
->area
;
2710 RECT_SET(self
->area
, x
, y
, w
, h
);
2712 /* apply the states. these are in a carefully crafted order.. */
2715 client_iconify(self
, TRUE
, FALSE
, TRUE
);
2717 client_fullscreen(self
, TRUE
);
2719 client_set_undecorated(self
, TRUE
);
2721 client_shade(self
, TRUE
);
2722 if (demands_attention
)
2723 client_hilite(self
, TRUE
);
2725 if (max_vert
&& max_horz
)
2726 client_maximize(self
, TRUE
, 0);
2728 client_maximize(self
, TRUE
, 2);
2730 client_maximize(self
, TRUE
, 1);
2732 /* if the window hasn't been configured yet, then do so now, in fact the
2733 x,y,w,h may _not_ be the same as the area rect, which can end up
2734 meaning that the client isn't properly moved/resized by the fullscreen
2736 pho can cause this because it maps at size of the screen but not 0,0
2737 so openbox moves it on screen to 0,0 (thus x,y=0,0 and area.x,y don't).
2738 then fullscreen'ing makes it go to 0,0 which it thinks it already is at
2739 cuz thats where the pre-fullscreen will be. however the actual area is
2740 not, so this needs to be called even if we have fullscreened/maxed
2742 self
->area
= oldarea
;
2743 client_configure(self
, x
, y
, w
, h
, FALSE
, TRUE
, FALSE
);
2745 /* set the desktop hint, to make sure that it always exists */
2746 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, self
->desktop
);
2748 /* nothing to do for the other states:
2757 void client_gravity_resize_w(ObClient
*self
, gint
*x
, gint oldw
, gint neww
)
2759 /* these should be the current values. this is for when you're not moving,
2761 g_assert(*x
== self
->area
.x
);
2762 g_assert(oldw
== self
->area
.width
);
2765 switch (self
->gravity
) {
2767 case NorthWestGravity
:
2769 case SouthWestGravity
:
2776 *x
-= (neww
- oldw
) / 2;
2778 case NorthEastGravity
:
2780 case SouthEastGravity
:
2786 void client_gravity_resize_h(ObClient
*self
, gint
*y
, gint oldh
, gint newh
)
2788 /* these should be the current values. this is for when you're not moving,
2790 g_assert(*y
== self
->area
.y
);
2791 g_assert(oldh
== self
->area
.height
);
2794 switch (self
->gravity
) {
2796 case NorthWestGravity
:
2798 case NorthEastGravity
:
2805 *y
-= (newh
- oldh
) / 2;
2807 case SouthWestGravity
:
2809 case SouthEastGravity
:
2815 void client_try_configure(ObClient
*self
, gint
*x
, gint
*y
, gint
*w
, gint
*h
,
2816 gint
*logicalw
, gint
*logicalh
,
2819 Rect desired
= {*x
, *y
, *w
, *h
};
2820 frame_rect_to_frame(self
->frame
, &desired
);
2822 /* make the frame recalculate its dimensions n shit without changing
2823 anything visible for real, this way the constraints below can work with
2824 the updated frame dimensions. */
2825 frame_adjust_area(self
->frame
, FALSE
, TRUE
, TRUE
);
2827 /* gets the frame's position */
2828 frame_client_gravity(self
->frame
, x
, y
);
2830 /* these positions are frame positions, not client positions */
2832 /* set the size and position if fullscreen */
2833 if (self
->fullscreen
) {
2837 i
= screen_find_monitor(&desired
);
2838 a
= screen_physical_area_monitor(i
);
2845 user
= FALSE
; /* ignore if the client can't be moved/resized when it
2849 } else if (self
->max_horz
|| self
->max_vert
) {
2853 /* use all possible struts when maximizing to the full screen */
2854 i
= screen_find_monitor(&desired
);
2855 a
= screen_area(self
->desktop
, i
,
2856 (self
->max_horz
&& self
->max_vert
? NULL
: &desired
));
2858 /* set the size and position if maximized */
2859 if (self
->max_horz
) {
2861 *w
= a
->width
- self
->frame
->size
.left
- self
->frame
->size
.right
;
2863 if (self
->max_vert
) {
2865 *h
= a
->height
- self
->frame
->size
.top
- self
->frame
->size
.bottom
;
2868 user
= FALSE
; /* ignore if the client can't be moved/resized when it
2874 /* gets the client's position */
2875 frame_frame_gravity(self
->frame
, x
, y
);
2877 /* work within the preferred sizes given by the window, these may have
2878 changed rather than it's requested width and height, so always run
2879 through this code */
2881 gint basew
, baseh
, minw
, minh
;
2883 gfloat minratio
, maxratio
;
2885 incw
= self
->fullscreen
|| self
->max_horz
? 1 : self
->size_inc
.width
;
2886 inch
= self
->fullscreen
|| self
->max_vert
? 1 : self
->size_inc
.height
;
2887 minratio
= self
->fullscreen
|| (self
->max_horz
&& self
->max_vert
) ?
2888 0 : self
->min_ratio
;
2889 maxratio
= self
->fullscreen
|| (self
->max_horz
&& self
->max_vert
) ?
2890 0 : self
->max_ratio
;
2892 /* base size is substituted with min size if not specified */
2893 if (self
->base_size
.width
>= 0 || self
->base_size
.height
>= 0) {
2894 basew
= self
->base_size
.width
;
2895 baseh
= self
->base_size
.height
;
2897 basew
= self
->min_size
.width
;
2898 baseh
= self
->min_size
.height
;
2900 /* min size is substituted with base size if not specified */
2901 if (self
->min_size
.width
|| self
->min_size
.height
) {
2902 minw
= self
->min_size
.width
;
2903 minh
= self
->min_size
.height
;
2905 minw
= self
->base_size
.width
;
2906 minh
= self
->base_size
.height
;
2909 /* This comment is no longer true */
2910 /* if this is a user-requested resize, then check against min/max
2913 /* smaller than min size or bigger than max size? */
2914 if (*w
> self
->max_size
.width
) *w
= self
->max_size
.width
;
2915 if (*w
< minw
) *w
= minw
;
2916 if (*h
> self
->max_size
.height
) *h
= self
->max_size
.height
;
2917 if (*h
< minh
) *h
= minh
;
2922 /* keep to the increments */
2926 /* you cannot resize to nothing */
2927 if (basew
+ *w
< 1) *w
= 1 - basew
;
2928 if (baseh
+ *h
< 1) *h
= 1 - baseh
;
2930 /* save the logical size */
2931 *logicalw
= incw
> 1 ? *w
: *w
+ basew
;
2932 *logicalh
= inch
> 1 ? *h
: *h
+ baseh
;
2940 /* adjust the height to match the width for the aspect ratios.
2941 for this, min size is not substituted for base size ever. */
2942 *w
-= self
->base_size
.width
;
2943 *h
-= self
->base_size
.height
;
2946 if (*h
* minratio
> *w
) {
2947 *h
= (gint
)(*w
/ minratio
);
2949 /* you cannot resize to nothing */
2952 *w
= (gint
)(*h
* minratio
);
2956 if (*h
* maxratio
< *w
) {
2957 *h
= (gint
)(*w
/ maxratio
);
2959 /* you cannot resize to nothing */
2962 *w
= (gint
)(*h
* minratio
);
2966 *w
+= self
->base_size
.width
;
2967 *h
+= self
->base_size
.height
;
2970 /* these override the above states! if you cant move you can't move! */
2972 if (!(self
->functions
& OB_CLIENT_FUNC_MOVE
)) {
2976 if (!(self
->functions
& OB_CLIENT_FUNC_RESIZE
)) {
2977 *w
= self
->area
.width
;
2978 *h
= self
->area
.height
;
2987 void client_configure(ObClient
*self
, gint x
, gint y
, gint w
, gint h
,
2988 gboolean user
, gboolean final
, gboolean force_reply
)
2992 gboolean send_resize_client
;
2993 gboolean moved
= FALSE
, resized
= FALSE
, rootmoved
= FALSE
;
2994 gboolean fmoved
, fresized
;
2995 guint fdecor
= self
->frame
->decorations
;
2996 gboolean fhorz
= self
->frame
->max_horz
;
2997 gboolean fvert
= self
->frame
->max_vert
;
2998 gint logicalw
, logicalh
;
3000 /* find the new x, y, width, and height (and logical size) */
3001 client_try_configure(self
, &x
, &y
, &w
, &h
, &logicalw
, &logicalh
, user
);
3003 /* set the logical size if things changed */
3004 if (!(w
== self
->area
.width
&& h
== self
->area
.height
))
3005 SIZE_SET(self
->logical_size
, logicalw
, logicalh
);
3007 /* figure out if we moved or resized or what */
3008 moved
= (x
!= self
->area
.x
|| y
!= self
->area
.y
);
3009 resized
= (w
!= self
->area
.width
|| h
!= self
->area
.height
);
3011 oldw
= self
->area
.width
;
3012 oldh
= self
->area
.height
;
3013 oldframe
= self
->frame
->area
;
3014 RECT_SET(self
->area
, x
, y
, w
, h
);
3016 /* for app-requested resizes, always resize if 'resized' is true.
3017 for user-requested ones, only resize if final is true, or when
3018 resizing in redraw mode */
3019 send_resize_client
= ((!user
&& resized
) ||
3021 (resized
&& config_resize_redraw
))));
3023 /* if the client is enlarging, then resize the client before the frame */
3024 if (send_resize_client
&& (w
> oldw
|| h
> oldh
)) {
3025 XMoveResizeWindow(ob_display
, self
->window
,
3026 self
->frame
->size
.left
, self
->frame
->size
.top
,
3027 MAX(w
, oldw
), MAX(h
, oldh
));
3028 frame_adjust_client_area(self
->frame
);
3031 /* find the frame's dimensions and move/resize it */
3035 /* if decorations changed, then readjust everything for the frame */
3036 if (self
->decorations
!= fdecor
||
3037 self
->max_horz
!= fhorz
|| self
->max_vert
!= fvert
)
3039 fmoved
= fresized
= TRUE
;
3042 /* adjust the frame */
3043 if (fmoved
|| fresized
) {
3044 gulong ignore_start
;
3046 ignore_start
= event_start_ignore_all_enters();
3048 /* replay pending pointer event before move the window, in case it
3049 would change what window gets the event */
3050 mouse_replay_pointer();
3052 frame_adjust_area(self
->frame
, fmoved
, fresized
, FALSE
);
3055 event_end_ignore_all_enters(ignore_start
);
3058 if (!user
|| final
) {
3059 gint oldrx
= self
->root_pos
.x
;
3060 gint oldry
= self
->root_pos
.y
;
3061 /* we have reset the client to 0 border width, so don't include
3062 it in these coords */
3063 POINT_SET(self
->root_pos
,
3064 self
->frame
->area
.x
+ self
->frame
->size
.left
-
3066 self
->frame
->area
.y
+ self
->frame
->size
.top
-
3067 self
->border_width
);
3068 if (self
->root_pos
.x
!= oldrx
|| self
->root_pos
.y
!= oldry
)
3072 /* This is kinda tricky and should not be changed.. let me explain!
3074 When user = FALSE, then the request is coming from the application
3075 itself, and we are more strict about when to send a synthetic
3076 ConfigureNotify. We strictly follow the rules of the ICCCM sec 4.1.5
3077 in this case (if force_reply is true)
3079 When user = TRUE, then the request is coming from "us", like when we
3080 maximize a window or something. In this case we are more lenient. We
3081 used to follow the same rules as above, but _Java_ Swing can't handle
3082 this. So just to appease Swing, when user = TRUE, we always send
3083 a synthetic ConfigureNotify to give the window its root coordinates.
3085 if ((!user
&& !resized
&& (rootmoved
|| force_reply
)) ||
3086 (user
&& final
&& rootmoved
))
3090 event
.type
= ConfigureNotify
;
3091 event
.xconfigure
.display
= ob_display
;
3092 event
.xconfigure
.event
= self
->window
;
3093 event
.xconfigure
.window
= self
->window
;
3095 ob_debug("Sending ConfigureNotify to %s for %d,%d %dx%d\n",
3096 self
->title
, self
->root_pos
.x
, self
->root_pos
.y
, w
, h
);
3098 /* root window real coords */
3099 event
.xconfigure
.x
= self
->root_pos
.x
;
3100 event
.xconfigure
.y
= self
->root_pos
.y
;
3101 event
.xconfigure
.width
= w
;
3102 event
.xconfigure
.height
= h
;
3103 event
.xconfigure
.border_width
= self
->border_width
;
3104 event
.xconfigure
.above
= None
;
3105 event
.xconfigure
.override_redirect
= FALSE
;
3106 XSendEvent(event
.xconfigure
.display
, event
.xconfigure
.window
,
3107 FALSE
, StructureNotifyMask
, &event
);
3110 /* if the client is shrinking, then resize the frame before the client.
3112 both of these resize sections may run, because the top one only resizes
3113 in the direction that is growing
3115 if (send_resize_client
&& (w
<= oldw
|| h
<= oldh
)) {
3116 frame_adjust_client_area(self
->frame
);
3117 XMoveResizeWindow(ob_display
, self
->window
,
3118 self
->frame
->size
.left
, self
->frame
->size
.top
, w
, h
);
3123 /* if it moved between monitors, then this can affect the stacking
3124 layer of this window or others - for fullscreen windows */
3125 if (screen_find_monitor(&self
->frame
->area
) !=
3126 screen_find_monitor(&oldframe
))
3128 client_calc_layer(self
);
3132 void client_fullscreen(ObClient
*self
, gboolean fs
)
3136 if (!(self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
) || /* can't */
3137 self
->fullscreen
== fs
) return; /* already done */
3139 self
->fullscreen
= fs
;
3140 client_change_state(self
); /* change the state hints on the client */
3143 self
->pre_fullscreen_area
= self
->area
;
3144 /* if the window is maximized, its area isn't all that meaningful.
3145 save its premax area instead. */
3146 if (self
->max_horz
) {
3147 self
->pre_fullscreen_area
.x
= self
->pre_max_area
.x
;
3148 self
->pre_fullscreen_area
.width
= self
->pre_max_area
.width
;
3150 if (self
->max_vert
) {
3151 self
->pre_fullscreen_area
.y
= self
->pre_max_area
.y
;
3152 self
->pre_fullscreen_area
.height
= self
->pre_max_area
.height
;
3155 /* these will help configure_full figure out where to fullscreen
3159 w
= self
->area
.width
;
3160 h
= self
->area
.height
;
3162 g_assert(self
->pre_fullscreen_area
.width
> 0 &&
3163 self
->pre_fullscreen_area
.height
> 0);
3165 x
= self
->pre_fullscreen_area
.x
;
3166 y
= self
->pre_fullscreen_area
.y
;
3167 w
= self
->pre_fullscreen_area
.width
;
3168 h
= self
->pre_fullscreen_area
.height
;
3169 RECT_SET(self
->pre_fullscreen_area
, 0, 0, 0, 0);
3172 ob_debug("Window %s going fullscreen (%d)\n",
3173 self
->title
, self
->fullscreen
);
3175 client_setup_decor_and_functions(self
, FALSE
);
3176 client_move_resize(self
, x
, y
, w
, h
);
3178 /* and adjust our layer/stacking. do this after resizing the window,
3179 and applying decorations, because windows which fill the screen are
3180 considered "fullscreen" and it affects their layer */
3181 client_calc_layer(self
);
3184 /* try focus us when we go into fullscreen mode */
3189 static void client_iconify_recursive(ObClient
*self
,
3190 gboolean iconic
, gboolean curdesk
,
3191 gboolean hide_animation
)
3194 gboolean changed
= FALSE
;
3196 if (self
->iconic
!= iconic
) {
3197 ob_debug("%sconifying window: 0x%lx\n", (iconic
? "I" : "Uni"),
3201 /* don't let non-normal windows iconify along with their parents
3203 if (client_normal(self
)) {
3204 self
->iconic
= iconic
;
3206 /* update the focus lists.. iconic windows go to the bottom of
3208 focus_order_to_bottom(self
);
3213 self
->iconic
= iconic
;
3215 if (curdesk
&& self
->desktop
!= screen_desktop
&&
3216 self
->desktop
!= DESKTOP_ALL
)
3217 client_set_desktop(self
, screen_desktop
, FALSE
, FALSE
);
3219 /* this puts it after the current focused window */
3220 focus_order_remove(self
);
3221 focus_order_add_new(self
);
3228 client_change_state(self
);
3229 if (config_animate_iconify
&& !hide_animation
)
3230 frame_begin_iconify_animation(self
->frame
, iconic
);
3231 /* do this after starting the animation so it doesn't flash */
3232 client_showhide(self
);
3235 /* iconify all direct transients, and deiconify all transients
3237 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
3238 if (it
->data
!= self
)
3239 if (client_is_direct_child(self
, it
->data
) || !iconic
)
3240 client_iconify_recursive(it
->data
, iconic
, curdesk
,
3244 void client_iconify(ObClient
*self
, gboolean iconic
, gboolean curdesk
,
3245 gboolean hide_animation
)
3247 if (self
->functions
& OB_CLIENT_FUNC_ICONIFY
|| !iconic
) {
3248 /* move up the transient chain as far as possible first */
3249 self
= client_search_top_direct_parent(self
);
3250 client_iconify_recursive(self
, iconic
, curdesk
, hide_animation
);
3254 void client_maximize(ObClient
*self
, gboolean max
, gint dir
)
3258 g_assert(dir
== 0 || dir
== 1 || dir
== 2);
3259 if (!(self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) && max
) return;/* can't */
3261 /* check if already done */
3263 if (dir
== 0 && self
->max_horz
&& self
->max_vert
) return;
3264 if (dir
== 1 && self
->max_horz
) return;
3265 if (dir
== 2 && self
->max_vert
) return;
3267 if (dir
== 0 && !self
->max_horz
&& !self
->max_vert
) return;
3268 if (dir
== 1 && !self
->max_horz
) return;
3269 if (dir
== 2 && !self
->max_vert
) return;
3272 /* these will help configure_full figure out which screen to fill with
3276 w
= self
->area
.width
;
3277 h
= self
->area
.height
;
3280 if ((dir
== 0 || dir
== 1) && !self
->max_horz
) { /* horz */
3281 RECT_SET(self
->pre_max_area
,
3282 self
->area
.x
, self
->pre_max_area
.y
,
3283 self
->area
.width
, self
->pre_max_area
.height
);
3285 if ((dir
== 0 || dir
== 2) && !self
->max_vert
) { /* vert */
3286 RECT_SET(self
->pre_max_area
,
3287 self
->pre_max_area
.x
, self
->area
.y
,
3288 self
->pre_max_area
.width
, self
->area
.height
);
3291 if ((dir
== 0 || dir
== 1) && self
->max_horz
) { /* horz */
3292 g_assert(self
->pre_max_area
.width
> 0);
3294 x
= self
->pre_max_area
.x
;
3295 w
= self
->pre_max_area
.width
;
3297 RECT_SET(self
->pre_max_area
, 0, self
->pre_max_area
.y
,
3298 0, self
->pre_max_area
.height
);
3300 if ((dir
== 0 || dir
== 2) && self
->max_vert
) { /* vert */
3301 g_assert(self
->pre_max_area
.height
> 0);
3303 y
= self
->pre_max_area
.y
;
3304 h
= self
->pre_max_area
.height
;
3306 RECT_SET(self
->pre_max_area
, self
->pre_max_area
.x
, 0,
3307 self
->pre_max_area
.width
, 0);
3311 if (dir
== 0 || dir
== 1) /* horz */
3312 self
->max_horz
= max
;
3313 if (dir
== 0 || dir
== 2) /* vert */
3314 self
->max_vert
= max
;
3316 client_change_state(self
); /* change the state hints on the client */
3318 client_setup_decor_and_functions(self
, FALSE
);
3319 client_move_resize(self
, x
, y
, w
, h
);
3322 void client_shade(ObClient
*self
, gboolean shade
)
3324 if ((!(self
->functions
& OB_CLIENT_FUNC_SHADE
) &&
3325 shade
) || /* can't shade */
3326 self
->shaded
== shade
) return; /* already done */
3328 self
->shaded
= shade
;
3329 client_change_state(self
);
3330 client_change_wm_state(self
); /* the window is being hidden/shown */
3331 /* resize the frame to just the titlebar */
3332 frame_adjust_area(self
->frame
, FALSE
, TRUE
, FALSE
);
3335 static void client_ping_event(ObClient
*self
, gboolean dead
)
3337 if (self
->not_responding
!= dead
) {
3338 self
->not_responding
= dead
;
3339 client_update_title(self
);
3342 /* the client isn't responding, so ask to kill it */
3343 client_prompt_kill(self
);
3345 /* it came back to life ! */
3347 if (self
->kill_prompt
) {
3348 prompt_unref(self
->kill_prompt
);
3349 self
->kill_prompt
= NULL
;
3352 self
->kill_level
= 0;
3357 void client_close(ObClient
*self
)
3359 if (!(self
->functions
& OB_CLIENT_FUNC_CLOSE
)) return;
3361 /* if closing an internal obprompt, that is just cancelling it */
3363 prompt_cancel(self
->prompt
);
3367 /* in the case that the client provides no means to requesting that it
3368 close, we just kill it */
3369 if (!self
->delete_window
)
3370 /* don't use client_kill(), we should only kill based on PID in
3371 response to a lack of PING replies */
3372 XKillClient(ob_display
, self
->window
);
3374 /* request the client to close with WM_DELETE_WINDOW */
3375 PROP_MSG_TO(self
->window
, self
->window
, wm_protocols
,
3376 prop_atoms
.wm_delete_window
, event_curtime
, 0, 0, 0,
3379 /* we're trying to close the window, so see if it is responding. if it
3380 is not, then we will let them kill the window */
3382 ping_start(self
, client_ping_event
);
3384 /* if we already know the window isn't responding (maybe they clicked
3385 no in the kill dialog but it hasn't come back to life), then show
3387 if (self
->not_responding
)
3388 client_prompt_kill(self
);
3392 #define OB_KILL_RESULT_NO 0
3393 #define OB_KILL_RESULT_YES 1
3395 static void client_kill_requested(ObPrompt
*p
, gint result
, gpointer data
)
3397 ObClient
*self
= data
;
3399 if (result
== OB_KILL_RESULT_YES
)
3402 prompt_unref(self
->kill_prompt
);
3403 self
->kill_prompt
= NULL
;
3406 static void client_prompt_kill(ObClient
*self
)
3408 /* check if we're already prompting */
3409 if (!self
->kill_prompt
) {
3410 ObPromptAnswer answers
[] = {
3411 { 0, OB_KILL_RESULT_NO
},
3412 { 0, OB_KILL_RESULT_YES
}
3415 const gchar
*y
, *title
;
3417 title
= self
->original_title
;
3418 if (title
[0] == '\0') {
3419 /* empty string, so use its parent */
3420 ObClient
*p
= client_search_top_direct_parent(self
);
3421 if (p
) title
= p
->original_title
;
3424 if (client_on_localhost(self
)) {
3427 if (self
->kill_level
== 0)
3433 (_("The window \"%s\" does not seem to be responding. Do you want to force it to exit by sending the %s signal?"),
3435 y
= _("End Process");
3439 (_("The window \"%s\" does not seem to be responding. Do you want to disconnect it from the X server?"),
3441 y
= _("Disconnect");
3443 /* set the dialog buttons' text */
3444 answers
[0].text
= _("Cancel"); /* "no" */
3445 answers
[1].text
= y
; /* "yes" */
3447 self
->kill_prompt
= prompt_new(m
, answers
,
3448 sizeof(answers
)/sizeof(answers
[0]),
3449 OB_KILL_RESULT_NO
, /* default = no */
3450 OB_KILL_RESULT_NO
, /* cancel = no */
3451 client_kill_requested
, self
);
3455 prompt_show(self
->kill_prompt
, self
, TRUE
);
3458 void client_kill(ObClient
*self
)
3460 /* don't kill our own windows */
3461 if (self
->prompt
) return;
3463 if (client_on_localhost(self
) && self
->pid
) {
3464 /* running on the local host */
3465 if (self
->kill_level
== 0) {
3466 ob_debug("killing window 0x%x with pid %lu, with SIGTERM",
3467 self
->window
, self
->pid
);
3468 kill(self
->pid
, SIGTERM
);
3471 /* show that we're trying to kill it */
3472 client_update_title(self
);
3475 ob_debug("killing window 0x%x with pid %lu, with SIGKILL\n",
3476 self
->window
, self
->pid
);
3477 kill(self
->pid
, SIGKILL
); /* kill -9 */
3481 /* running on a remote host */
3482 XKillClient(ob_display
, self
->window
);
3486 void client_hilite(ObClient
*self
, gboolean hilite
)
3488 if (self
->demands_attention
== hilite
)
3489 return; /* no change */
3491 /* don't allow focused windows to hilite */
3492 self
->demands_attention
= hilite
&& !client_focused(self
);
3493 if (self
->frame
!= NULL
) { /* if we're mapping, just set the state */
3494 if (self
->demands_attention
)
3495 frame_flash_start(self
->frame
);
3497 frame_flash_stop(self
->frame
);
3498 client_change_state(self
);
3502 static void client_set_desktop_recursive(ObClient
*self
,
3510 if (target
!= self
->desktop
&& self
->type
!= OB_CLIENT_TYPE_DESKTOP
) {
3512 ob_debug("Setting desktop %u\n", target
+1);
3514 g_assert(target
< screen_num_desktops
|| target
== DESKTOP_ALL
);
3516 old
= self
->desktop
;
3517 self
->desktop
= target
;
3518 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, target
);
3519 /* the frame can display the current desktop state */
3520 frame_adjust_state(self
->frame
);
3521 /* 'move' the window to the new desktop */
3525 /* raise if it was not already on the desktop */
3526 if (old
!= DESKTOP_ALL
&& !dontraise
)
3527 stacking_raise(CLIENT_AS_WINDOW(self
));
3528 if (STRUT_EXISTS(self
->strut
))
3529 screen_update_areas();
3531 /* the new desktop's geometry may be different, so we may need to
3532 resize, for example if we are maximized */
3533 client_reconfigure(self
, FALSE
);
3536 /* move all transients */
3537 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
3538 if (it
->data
!= self
)
3539 if (client_is_direct_child(self
, it
->data
))
3540 client_set_desktop_recursive(it
->data
, target
,
3541 donthide
, dontraise
);
3544 void client_set_desktop(ObClient
*self
, guint target
,
3545 gboolean donthide
, gboolean dontraise
)
3547 self
= client_search_top_direct_parent(self
);
3548 client_set_desktop_recursive(self
, target
, donthide
, dontraise
);
3551 gboolean
client_is_direct_child(ObClient
*parent
, ObClient
*child
)
3553 while (child
!= parent
&& (child
= client_direct_parent(child
)));
3554 return child
== parent
;
3557 ObClient
*client_search_modal_child(ObClient
*self
)
3562 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
3563 ObClient
*c
= it
->data
;
3564 if ((ret
= client_search_modal_child(c
))) return ret
;
3565 if (c
->modal
) return c
;
3570 gboolean
client_validate(ObClient
*self
)
3574 XSync(ob_display
, FALSE
); /* get all events on the server */
3576 if (XCheckTypedWindowEvent(ob_display
, self
->window
, DestroyNotify
, &e
) ||
3577 XCheckTypedWindowEvent(ob_display
, self
->window
, UnmapNotify
, &e
)) {
3578 XPutBackEvent(ob_display
, &e
);
3585 void client_set_wm_state(ObClient
*self
, glong state
)
3587 if (state
== self
->wmstate
) return; /* no change */
3591 client_iconify(self
, TRUE
, TRUE
, FALSE
);
3594 client_iconify(self
, FALSE
, TRUE
, FALSE
);
3599 void client_set_state(ObClient
*self
, Atom action
, glong data1
, glong data2
)
3601 gboolean shaded
= self
->shaded
;
3602 gboolean fullscreen
= self
->fullscreen
;
3603 gboolean undecorated
= self
->undecorated
;
3604 gboolean max_horz
= self
->max_horz
;
3605 gboolean max_vert
= self
->max_vert
;
3606 gboolean modal
= self
->modal
;
3607 gboolean iconic
= self
->iconic
;
3608 gboolean demands_attention
= self
->demands_attention
;
3609 gboolean above
= self
->above
;
3610 gboolean below
= self
->below
;
3613 if (!(action
== prop_atoms
.net_wm_state_add
||
3614 action
== prop_atoms
.net_wm_state_remove
||
3615 action
== prop_atoms
.net_wm_state_toggle
))
3616 /* an invalid action was passed to the client message, ignore it */
3619 for (i
= 0; i
< 2; ++i
) {
3620 Atom state
= i
== 0 ? data1
: data2
;
3622 if (!state
) continue;
3624 /* if toggling, then pick whether we're adding or removing */
3625 if (action
== prop_atoms
.net_wm_state_toggle
) {
3626 if (state
== prop_atoms
.net_wm_state_modal
)
3627 action
= modal
? prop_atoms
.net_wm_state_remove
:
3628 prop_atoms
.net_wm_state_add
;
3629 else if (state
== prop_atoms
.net_wm_state_maximized_vert
)
3630 action
= self
->max_vert
? prop_atoms
.net_wm_state_remove
:
3631 prop_atoms
.net_wm_state_add
;
3632 else if (state
== prop_atoms
.net_wm_state_maximized_horz
)
3633 action
= self
->max_horz
? prop_atoms
.net_wm_state_remove
:
3634 prop_atoms
.net_wm_state_add
;
3635 else if (state
== prop_atoms
.net_wm_state_shaded
)
3636 action
= shaded
? prop_atoms
.net_wm_state_remove
:
3637 prop_atoms
.net_wm_state_add
;
3638 else if (state
== prop_atoms
.net_wm_state_skip_taskbar
)
3639 action
= self
->skip_taskbar
?
3640 prop_atoms
.net_wm_state_remove
:
3641 prop_atoms
.net_wm_state_add
;
3642 else if (state
== prop_atoms
.net_wm_state_skip_pager
)
3643 action
= self
->skip_pager
?
3644 prop_atoms
.net_wm_state_remove
:
3645 prop_atoms
.net_wm_state_add
;
3646 else if (state
== prop_atoms
.net_wm_state_hidden
)
3647 action
= self
->iconic
?
3648 prop_atoms
.net_wm_state_remove
:
3649 prop_atoms
.net_wm_state_add
;
3650 else if (state
== prop_atoms
.net_wm_state_fullscreen
)
3651 action
= fullscreen
?
3652 prop_atoms
.net_wm_state_remove
:
3653 prop_atoms
.net_wm_state_add
;
3654 else if (state
== prop_atoms
.net_wm_state_above
)
3655 action
= self
->above
? prop_atoms
.net_wm_state_remove
:
3656 prop_atoms
.net_wm_state_add
;
3657 else if (state
== prop_atoms
.net_wm_state_below
)
3658 action
= self
->below
? prop_atoms
.net_wm_state_remove
:
3659 prop_atoms
.net_wm_state_add
;
3660 else if (state
== prop_atoms
.net_wm_state_demands_attention
)
3661 action
= self
->demands_attention
?
3662 prop_atoms
.net_wm_state_remove
:
3663 prop_atoms
.net_wm_state_add
;
3664 else if (state
== prop_atoms
.ob_wm_state_undecorated
)
3665 action
= undecorated
? prop_atoms
.net_wm_state_remove
:
3666 prop_atoms
.net_wm_state_add
;
3669 if (action
== prop_atoms
.net_wm_state_add
) {
3670 if (state
== prop_atoms
.net_wm_state_modal
) {
3672 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
3674 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
3676 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
3678 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
3679 self
->skip_taskbar
= TRUE
;
3680 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
3681 self
->skip_pager
= TRUE
;
3682 } else if (state
== prop_atoms
.net_wm_state_hidden
) {
3684 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
3686 } else if (state
== prop_atoms
.net_wm_state_above
) {
3689 } else if (state
== prop_atoms
.net_wm_state_below
) {
3692 } else if (state
== prop_atoms
.net_wm_state_demands_attention
) {
3693 demands_attention
= TRUE
;
3694 } else if (state
== prop_atoms
.ob_wm_state_undecorated
) {
3698 } else { /* action == prop_atoms.net_wm_state_remove */
3699 if (state
== prop_atoms
.net_wm_state_modal
) {
3701 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
3703 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
3705 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
3707 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
3708 self
->skip_taskbar
= FALSE
;
3709 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
3710 self
->skip_pager
= FALSE
;
3711 } else if (state
== prop_atoms
.net_wm_state_hidden
) {
3713 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
3715 } else if (state
== prop_atoms
.net_wm_state_above
) {
3717 } else if (state
== prop_atoms
.net_wm_state_below
) {
3719 } else if (state
== prop_atoms
.net_wm_state_demands_attention
) {
3720 demands_attention
= FALSE
;
3721 } else if (state
== prop_atoms
.ob_wm_state_undecorated
) {
3722 undecorated
= FALSE
;
3727 if (max_horz
!= self
->max_horz
|| max_vert
!= self
->max_vert
) {
3728 if (max_horz
!= self
->max_horz
&& max_vert
!= self
->max_vert
) {
3730 if (max_horz
== max_vert
) { /* both going the same way */
3731 client_maximize(self
, max_horz
, 0);
3733 client_maximize(self
, max_horz
, 1);
3734 client_maximize(self
, max_vert
, 2);
3738 if (max_horz
!= self
->max_horz
)
3739 client_maximize(self
, max_horz
, 1);
3741 client_maximize(self
, max_vert
, 2);
3744 /* change fullscreen state before shading, as it will affect if the window
3746 if (fullscreen
!= self
->fullscreen
)
3747 client_fullscreen(self
, fullscreen
);
3748 if (shaded
!= self
->shaded
)
3749 client_shade(self
, shaded
);
3750 if (undecorated
!= self
->undecorated
)
3751 client_set_undecorated(self
, undecorated
);
3752 if (above
!= self
->above
|| below
!= self
->below
) {
3753 self
->above
= above
;
3754 self
->below
= below
;
3755 client_calc_layer(self
);
3758 if (modal
!= self
->modal
) {
3759 self
->modal
= modal
;
3760 /* when a window changes modality, then its stacking order with its
3761 transients needs to change */
3762 stacking_raise(CLIENT_AS_WINDOW(self
));
3764 /* it also may get focused. if something is focused that shouldn't
3765 be focused anymore, then move the focus */
3766 if (focus_client
&& client_focus_target(focus_client
) != focus_client
)
3767 client_focus(focus_client
);
3770 if (iconic
!= self
->iconic
)
3771 client_iconify(self
, iconic
, FALSE
, FALSE
);
3773 if (demands_attention
!= self
->demands_attention
)
3774 client_hilite(self
, demands_attention
);
3776 client_change_state(self
); /* change the hint to reflect these changes */
3779 ObClient
*client_focus_target(ObClient
*self
)
3781 ObClient
*child
= NULL
;
3783 child
= client_search_modal_child(self
);
3784 if (child
) return child
;
3788 gboolean
client_can_focus(ObClient
*self
)
3790 /* choose the correct target */
3791 self
= client_focus_target(self
);
3793 if (!self
->frame
->visible
)
3796 if (!(self
->can_focus
|| self
->focus_notify
))
3802 gboolean
client_focus(ObClient
*self
)
3804 /* we might not focus this window, so if we have modal children which would
3805 be focused instead, bring them to this desktop */
3806 client_bring_modal_windows(self
);
3808 /* choose the correct target */
3809 self
= client_focus_target(self
);
3811 if (!client_can_focus(self
)) {
3812 ob_debug_type(OB_DEBUG_FOCUS
,
3813 "Client %s can't be focused\n", self
->title
);
3817 ob_debug_type(OB_DEBUG_FOCUS
,
3818 "Focusing client \"%s\" (0x%x) at time %u\n",
3819 self
->title
, self
->window
, event_curtime
);
3821 /* if using focus_delay, stop the timer now so that focus doesn't
3823 event_halt_focus_delay();
3825 event_cancel_all_key_grabs();
3827 xerror_set_ignore(TRUE
);
3828 xerror_occured
= FALSE
;
3830 if (self
->can_focus
) {
3831 /* This can cause a BadMatch error with CurrentTime, or if an app
3832 passed in a bad time for _NET_WM_ACTIVE_WINDOW. */
3833 XSetInputFocus(ob_display
, self
->window
, RevertToPointerRoot
,
3837 if (self
->focus_notify
) {
3839 ce
.xclient
.type
= ClientMessage
;
3840 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
3841 ce
.xclient
.display
= ob_display
;
3842 ce
.xclient
.window
= self
->window
;
3843 ce
.xclient
.format
= 32;
3844 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_take_focus
;
3845 ce
.xclient
.data
.l
[1] = event_curtime
;
3846 ce
.xclient
.data
.l
[2] = 0l;
3847 ce
.xclient
.data
.l
[3] = 0l;
3848 ce
.xclient
.data
.l
[4] = 0l;
3849 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
3852 xerror_set_ignore(FALSE
);
3854 ob_debug_type(OB_DEBUG_FOCUS
, "Error focusing? %d\n", xerror_occured
);
3855 return !xerror_occured
;
3858 static void client_present(ObClient
*self
, gboolean here
, gboolean raise
,
3861 if (client_normal(self
) && screen_showing_desktop
)
3862 screen_show_desktop(FALSE
, self
);
3864 client_iconify(self
, FALSE
, here
, FALSE
);
3865 if (self
->desktop
!= DESKTOP_ALL
&&
3866 self
->desktop
!= screen_desktop
)
3869 client_set_desktop(self
, screen_desktop
, FALSE
, TRUE
);
3871 screen_set_desktop(self
->desktop
, FALSE
);
3872 } else if (!self
->frame
->visible
)
3873 /* if its not visible for other reasons, then don't mess
3876 if (self
->shaded
&& unshade
)
3877 client_shade(self
, FALSE
);
3879 stacking_raise(CLIENT_AS_WINDOW(self
));
3884 /* this function exists to map to the client_activate message in the ewmh,
3885 the user arg is unused because nobody uses it correctly anyway. */
3886 void client_activate(ObClient
*self
, gboolean here
, gboolean raise
,
3887 gboolean unshade
, gboolean user
)
3889 client_present(self
, here
, raise
, unshade
);
3892 static void client_bring_windows_recursive(ObClient
*self
,
3900 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
3901 client_bring_windows_recursive(it
->data
, desktop
,
3902 helpers
, modals
, iconic
);
3904 if (((helpers
&& client_helper(self
)) ||
3905 (modals
&& self
->modal
)) &&
3906 ((self
->desktop
!= desktop
&& self
->desktop
!= DESKTOP_ALL
) ||
3907 (iconic
&& self
->iconic
)))
3909 if (iconic
&& self
->iconic
)
3910 client_iconify(self
, FALSE
, TRUE
, FALSE
);
3912 client_set_desktop(self
, desktop
, FALSE
, FALSE
);
3916 void client_bring_helper_windows(ObClient
*self
)
3918 client_bring_windows_recursive(self
, self
->desktop
, TRUE
, FALSE
, FALSE
);
3921 void client_bring_modal_windows(ObClient
*self
)
3923 client_bring_windows_recursive(self
, self
->desktop
, FALSE
, TRUE
, TRUE
);
3926 gboolean
client_focused(ObClient
*self
)
3928 return self
== focus_client
;
3931 RrImage
* client_icon(ObClient
*self
)
3933 RrImage
*ret
= NULL
;
3936 ret
= self
->icon_set
;
3937 else if (self
->parents
) {
3939 for (it
= self
->parents
; it
&& !ret
; it
= g_slist_next(it
))
3940 ret
= client_icon(it
->data
);
3943 ret
= client_default_icon
;
3947 void client_set_layer(ObClient
*self
, gint layer
)
3951 self
->above
= FALSE
;
3952 } else if (layer
== 0) {
3953 self
->below
= self
->above
= FALSE
;
3955 self
->below
= FALSE
;
3958 client_calc_layer(self
);
3959 client_change_state(self
); /* reflect this in the state hints */
3962 void client_set_undecorated(ObClient
*self
, gboolean undecorated
)
3964 if (self
->undecorated
!= undecorated
&&
3965 /* don't let it undecorate if the function is missing, but let
3967 (self
->functions
& OB_CLIENT_FUNC_UNDECORATE
|| !undecorated
))
3969 self
->undecorated
= undecorated
;
3970 client_setup_decor_and_functions(self
, TRUE
);
3971 client_change_state(self
); /* reflect this in the state hints */
3975 guint
client_monitor(ObClient
*self
)
3977 return screen_find_monitor(&self
->frame
->area
);
3980 ObClient
*client_direct_parent(ObClient
*self
)
3982 if (!self
->parents
) return NULL
;
3983 if (self
->transient_for_group
) return NULL
;
3984 return self
->parents
->data
;
3987 ObClient
*client_search_top_direct_parent(ObClient
*self
)
3990 while ((p
= client_direct_parent(self
))) self
= p
;
3994 static GSList
*client_search_all_top_parents_internal(ObClient
*self
,
3996 ObStackingLayer layer
)
4001 /* move up the direct transient chain as far as possible */
4002 while ((p
= client_direct_parent(self
)) &&
4003 (!bylayer
|| p
->layer
== layer
))
4007 ret
= g_slist_prepend(NULL
, self
);
4009 ret
= g_slist_copy(self
->parents
);
4014 GSList
*client_search_all_top_parents(ObClient
*self
)
4016 return client_search_all_top_parents_internal(self
, FALSE
, 0);
4019 GSList
*client_search_all_top_parents_layer(ObClient
*self
)
4021 return client_search_all_top_parents_internal(self
, TRUE
, self
->layer
);
4024 ObClient
*client_search_focus_parent(ObClient
*self
)
4028 for (it
= self
->parents
; it
; it
= g_slist_next(it
))
4029 if (client_focused(it
->data
)) return it
->data
;
4034 ObClient
*client_search_parent(ObClient
*self
, ObClient
*search
)
4038 for (it
= self
->parents
; it
; it
= g_slist_next(it
))
4039 if (it
->data
== search
) return search
;
4044 ObClient
*client_search_transient(ObClient
*self
, ObClient
*search
)
4048 for (sit
= self
->transients
; sit
; sit
= g_slist_next(sit
)) {
4049 if (sit
->data
== search
)
4051 if (client_search_transient(sit
->data
, search
))
4057 static void detect_edge(Rect area
, ObDirection dir
,
4058 gint my_head
, gint my_size
,
4059 gint my_edge_start
, gint my_edge_size
,
4060 gint
*dest
, gboolean
*near_edge
)
4062 gint edge_start
, edge_size
, head
, tail
;
4063 gboolean skip_head
= FALSE
, skip_tail
= FALSE
;
4066 case OB_DIRECTION_NORTH
:
4067 case OB_DIRECTION_SOUTH
:
4068 edge_start
= area
.x
;
4069 edge_size
= area
.width
;
4071 case OB_DIRECTION_EAST
:
4072 case OB_DIRECTION_WEST
:
4073 edge_start
= area
.y
;
4074 edge_size
= area
.height
;
4077 g_assert_not_reached();
4080 /* do we collide with this window? */
4081 if (!RANGES_INTERSECT(my_edge_start
, my_edge_size
,
4082 edge_start
, edge_size
))
4086 case OB_DIRECTION_NORTH
:
4087 head
= RECT_BOTTOM(area
);
4088 tail
= RECT_TOP(area
);
4090 case OB_DIRECTION_SOUTH
:
4091 head
= RECT_TOP(area
);
4092 tail
= RECT_BOTTOM(area
);
4094 case OB_DIRECTION_WEST
:
4095 head
= RECT_RIGHT(area
);
4096 tail
= RECT_LEFT(area
);
4098 case OB_DIRECTION_EAST
:
4099 head
= RECT_LEFT(area
);
4100 tail
= RECT_RIGHT(area
);
4103 g_assert_not_reached();
4106 case OB_DIRECTION_NORTH
:
4107 case OB_DIRECTION_WEST
:
4108 /* check if our window is past the head of this window */
4109 if (my_head
<= head
+ 1)
4111 /* check if our window's tail is past the tail of this window */
4112 if (my_head
+ my_size
- 1 <= tail
)
4114 /* check if the head of this window is closer than the previously
4115 chosen edge (take into account that the previously chosen
4116 edge might have been a tail, not a head) */
4117 if (head
+ (*near_edge
? 0 : my_size
) <= *dest
)
4119 /* check if the tail of this window is closer than the previously
4120 chosen edge (take into account that the previously chosen
4121 edge might have been a head, not a tail) */
4122 if (tail
- (!*near_edge
? 0 : my_size
) <= *dest
)
4125 case OB_DIRECTION_SOUTH
:
4126 case OB_DIRECTION_EAST
:
4127 /* check if our window is past the head of this window */
4128 if (my_head
>= head
- 1)
4130 /* check if our window's tail is past the tail of this window */
4131 if (my_head
- my_size
+ 1 >= tail
)
4133 /* check if the head of this window is closer than the previously
4134 chosen edge (take into account that the previously chosen
4135 edge might have been a tail, not a head) */
4136 if (head
- (*near_edge
? 0 : my_size
) >= *dest
)
4138 /* check if the tail of this window is closer than the previously
4139 chosen edge (take into account that the previously chosen
4140 edge might have been a head, not a tail) */
4141 if (tail
+ (!*near_edge
? 0 : my_size
) >= *dest
)
4145 g_assert_not_reached();
4148 ob_debug("my head %d size %d\n", my_head
, my_size
);
4149 ob_debug("head %d tail %d dest %d\n", head
, tail
, *dest
);
4151 ob_debug("using near edge %d\n", head
);
4155 else if (!skip_tail
) {
4156 ob_debug("using far edge %d\n", tail
);
4162 void client_find_edge_directional(ObClient
*self
, ObDirection dir
,
4163 gint my_head
, gint my_size
,
4164 gint my_edge_start
, gint my_edge_size
,
4165 gint
*dest
, gboolean
*near_edge
)
4172 a
= screen_area(self
->desktop
, SCREEN_AREA_ALL_MONITORS
,
4173 &self
->frame
->area
);
4174 mon
= screen_area(self
->desktop
, SCREEN_AREA_ONE_MONITOR
,
4175 &self
->frame
->area
);
4178 case OB_DIRECTION_NORTH
:
4179 if (my_head
>= RECT_TOP(*mon
) + 1)
4180 edge
= RECT_TOP(*mon
) - 1;
4182 edge
= RECT_TOP(*a
) - 1;
4184 case OB_DIRECTION_SOUTH
:
4185 if (my_head
<= RECT_BOTTOM(*mon
) - 1)
4186 edge
= RECT_BOTTOM(*mon
) + 1;
4188 edge
= RECT_BOTTOM(*a
) + 1;
4190 case OB_DIRECTION_EAST
:
4191 if (my_head
<= RECT_RIGHT(*mon
) - 1)
4192 edge
= RECT_RIGHT(*mon
) + 1;
4194 edge
= RECT_RIGHT(*a
) + 1;
4196 case OB_DIRECTION_WEST
:
4197 if (my_head
>= RECT_LEFT(*mon
) + 1)
4198 edge
= RECT_LEFT(*mon
) - 1;
4200 edge
= RECT_LEFT(*a
) - 1;
4203 g_assert_not_reached();
4205 /* default to the far edge, then narrow it down */
4209 for (it
= client_list
; it
; it
= g_list_next(it
)) {
4210 ObClient
*cur
= it
->data
;
4212 /* skip windows to not bump into */
4217 if (self
->desktop
!= cur
->desktop
&& cur
->desktop
!= DESKTOP_ALL
&&
4218 cur
->desktop
!= screen_desktop
)
4221 ob_debug("trying window %s\n", cur
->title
);
4223 detect_edge(cur
->frame
->area
, dir
, my_head
, my_size
, my_edge_start
,
4224 my_edge_size
, dest
, near_edge
);
4226 dock_get_area(&dock_area
);
4227 detect_edge(dock_area
, dir
, my_head
, my_size
, my_edge_start
,
4228 my_edge_size
, dest
, near_edge
);
4233 void client_find_move_directional(ObClient
*self
, ObDirection dir
,
4237 gint e
, e_start
, e_size
;
4241 case OB_DIRECTION_EAST
:
4242 head
= RECT_RIGHT(self
->frame
->area
);
4243 size
= self
->frame
->area
.width
;
4244 e_start
= RECT_TOP(self
->frame
->area
);
4245 e_size
= self
->frame
->area
.height
;
4247 case OB_DIRECTION_WEST
:
4248 head
= RECT_LEFT(self
->frame
->area
);
4249 size
= self
->frame
->area
.width
;
4250 e_start
= RECT_TOP(self
->frame
->area
);
4251 e_size
= self
->frame
->area
.height
;
4253 case OB_DIRECTION_NORTH
:
4254 head
= RECT_TOP(self
->frame
->area
);
4255 size
= self
->frame
->area
.height
;
4256 e_start
= RECT_LEFT(self
->frame
->area
);
4257 e_size
= self
->frame
->area
.width
;
4259 case OB_DIRECTION_SOUTH
:
4260 head
= RECT_BOTTOM(self
->frame
->area
);
4261 size
= self
->frame
->area
.height
;
4262 e_start
= RECT_LEFT(self
->frame
->area
);
4263 e_size
= self
->frame
->area
.width
;
4266 g_assert_not_reached();
4269 client_find_edge_directional(self
, dir
, head
, size
,
4270 e_start
, e_size
, &e
, &near
);
4271 *x
= self
->frame
->area
.x
;
4272 *y
= self
->frame
->area
.y
;
4274 case OB_DIRECTION_EAST
:
4275 if (near
) e
-= self
->frame
->area
.width
;
4279 case OB_DIRECTION_WEST
:
4281 else e
-= self
->frame
->area
.width
;
4284 case OB_DIRECTION_NORTH
:
4286 else e
-= self
->frame
->area
.height
;
4289 case OB_DIRECTION_SOUTH
:
4290 if (near
) e
-= self
->frame
->area
.height
;
4295 g_assert_not_reached();
4297 frame_frame_gravity(self
->frame
, x
, y
);
4300 void client_find_resize_directional(ObClient
*self
, ObDirection side
,
4302 gint
*x
, gint
*y
, gint
*w
, gint
*h
)
4305 gint e
, e_start
, e_size
, delta
;
4310 case OB_DIRECTION_EAST
:
4311 head
= RECT_RIGHT(self
->frame
->area
) +
4312 (self
->size_inc
.width
- 1) * (grow
? 1 : 0);
4313 e_start
= RECT_TOP(self
->frame
->area
);
4314 e_size
= self
->frame
->area
.height
;
4315 dir
= grow
? OB_DIRECTION_EAST
: OB_DIRECTION_WEST
;
4317 case OB_DIRECTION_WEST
:
4318 head
= RECT_LEFT(self
->frame
->area
) -
4319 (self
->size_inc
.width
- 1) * (grow
? 1 : 0);
4320 e_start
= RECT_TOP(self
->frame
->area
);
4321 e_size
= self
->frame
->area
.height
;
4322 dir
= grow
? OB_DIRECTION_WEST
: OB_DIRECTION_EAST
;
4324 case OB_DIRECTION_NORTH
:
4325 head
= RECT_TOP(self
->frame
->area
) -
4326 (self
->size_inc
.height
- 1) * (grow
? 1 : 0);
4327 e_start
= RECT_LEFT(self
->frame
->area
);
4328 e_size
= self
->frame
->area
.width
;
4329 dir
= grow
? OB_DIRECTION_NORTH
: OB_DIRECTION_SOUTH
;
4331 case OB_DIRECTION_SOUTH
:
4332 head
= RECT_BOTTOM(self
->frame
->area
) +
4333 (self
->size_inc
.height
- 1) * (grow
? 1 : 0);
4334 e_start
= RECT_LEFT(self
->frame
->area
);
4335 e_size
= self
->frame
->area
.width
;
4336 dir
= grow
? OB_DIRECTION_SOUTH
: OB_DIRECTION_NORTH
;
4339 g_assert_not_reached();
4342 ob_debug("head %d dir %d\n", head
, dir
);
4343 client_find_edge_directional(self
, dir
, head
, 1,
4344 e_start
, e_size
, &e
, &near
);
4345 ob_debug("edge %d\n", e
);
4346 *x
= self
->frame
->area
.x
;
4347 *y
= self
->frame
->area
.y
;
4348 *w
= self
->frame
->area
.width
;
4349 *h
= self
->frame
->area
.height
;
4351 case OB_DIRECTION_EAST
:
4352 if (grow
== near
) --e
;
4353 delta
= e
- RECT_RIGHT(self
->frame
->area
);
4356 case OB_DIRECTION_WEST
:
4357 if (grow
== near
) ++e
;
4358 delta
= RECT_LEFT(self
->frame
->area
) - e
;
4362 case OB_DIRECTION_NORTH
:
4363 if (grow
== near
) ++e
;
4364 delta
= RECT_TOP(self
->frame
->area
) - e
;
4368 case OB_DIRECTION_SOUTH
:
4369 if (grow
== near
) --e
;
4370 delta
= e
- RECT_BOTTOM(self
->frame
->area
);
4374 g_assert_not_reached();
4376 frame_frame_gravity(self
->frame
, x
, y
);
4377 *w
-= self
->frame
->size
.left
+ self
->frame
->size
.right
;
4378 *h
-= self
->frame
->size
.top
+ self
->frame
->size
.bottom
;
4381 ObClient
* client_under_pointer(void)
4385 ObClient
*ret
= NULL
;
4387 if (screen_pointer_pos(&x
, &y
)) {
4388 for (it
= stacking_list
; it
; it
= g_list_next(it
)) {
4389 if (WINDOW_IS_CLIENT(it
->data
)) {
4390 ObClient
*c
= WINDOW_AS_CLIENT(it
->data
);
4391 if (c
->frame
->visible
&&
4392 /* check the desktop, this is done during desktop
4393 switching and windows are shown/hidden status is not
4395 (c
->desktop
== screen_desktop
||
4396 c
->desktop
== DESKTOP_ALL
) &&
4397 /* ignore all animating windows */
4398 !frame_iconify_animating(c
->frame
) &&
4399 RECT_CONTAINS(c
->frame
->area
, x
, y
))
4410 gboolean
client_has_group_siblings(ObClient
*self
)
4412 return self
->group
&& self
->group
->members
->next
;
4415 /*! Returns TRUE if the client is running on the same machine as Openbox */
4416 gboolean
client_on_localhost(ObClient
*self
)
4418 return self
->client_machine
== NULL
;