1 /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
3 client.c for the Openbox window manager
4 Copyright (c) 2006 Mikael Magnusson
5 Copyright (c) 2003-2007 Dana Jansens
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 See the COPYING file for a copy of the GNU General Public License.
22 #include "startupnotify.h"
25 #include "moveresize.h"
39 #include "menuframe.h"
42 #include "render/render.h"
44 #include "obt/display.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 OBT_PROP_SETA32(obt_root(ob_screen
), NET_CLIENT_LIST
, WINDOW
,
189 (gulong
*)windows
, size
);
197 void client_manage(Window window
, ObPrompt
*prompt
)
200 XSetWindowAttributes attrib_set
;
201 gboolean activate
= FALSE
;
202 ObAppSettings
*settings
;
203 gboolean transient
= FALSE
;
204 Rect place
, *monitor
;
205 Time launch_time
, map_time
;
207 ob_debug("Managing window: 0x%lx", window
);
209 map_time
= event_get_server_time();
211 /* choose the events we want to receive on the CLIENT window
212 (ObPrompt windows can request events too) */
213 attrib_set
.event_mask
= CLIENT_EVENTMASK
|
214 (prompt
? prompt
->event_mask
: 0);
215 attrib_set
.do_not_propagate_mask
= CLIENT_NOPROPAGATEMASK
;
216 XChangeWindowAttributes(obt_display
, window
,
217 CWEventMask
|CWDontPropagate
, &attrib_set
);
219 /* create the ObClient struct, and populate it from the hints on the
221 self
= g_new0(ObClient
, 1);
222 self
->obwin
.type
= OB_WINDOW_CLASS_CLIENT
;
223 self
->window
= window
;
224 self
->prompt
= prompt
;
226 /* non-zero defaults */
227 self
->wmstate
= WithdrawnState
; /* make sure it gets updated first time */
228 self
->gravity
= NorthWestGravity
;
229 self
->desktop
= screen_num_desktops
; /* always an invalid value */
231 /* get all the stuff off the window */
232 client_get_all(self
, TRUE
);
234 ob_debug("Window type: %d", self
->type
);
235 ob_debug("Window group: 0x%x", self
->group
?self
->group
->leader
:0);
237 /* now we have all of the window's information so we can set this up.
238 do this before creating the frame, so it can tell that we are still
239 mapping and doesn't go applying things right away */
240 client_setup_decor_and_functions(self
, FALSE
);
242 /* specify that if we exit, the window should not be destroyed and
243 should be reparented back to root automatically, unless we are managing
244 an internal ObPrompt window */
246 XChangeSaveSet(obt_display
, window
, SetModeInsert
);
248 /* create the decoration frame for the client window */
249 self
->frame
= frame_new(self
);
251 frame_grab_client(self
->frame
);
253 /* we've grabbed everything and set everything that we need to at mapping
257 /* per-app settings override stuff from client_get_all, and return the
258 settings for other uses too. the returned settings is a shallow copy,
259 that needs to be freed with g_free(). */
260 settings
= client_get_settings_state(self
);
261 /* the session should get the last say though */
262 client_restore_session_state(self
);
264 /* tell startup notification that this app started */
265 launch_time
= sn_app_started(self
->startup_id
, self
->class, self
->name
);
267 /* do this after we have a frame.. it uses the frame to help determine the
268 WM_STATE to apply. */
269 client_change_state(self
);
271 /* add ourselves to the focus order */
272 focus_order_add_new(self
);
274 /* do this to add ourselves to the stacking list in a non-intrusive way */
275 client_calc_layer(self
);
277 /* focus the new window? */
278 if (ob_state() != OB_STATE_STARTING
&&
279 (!self
->session
|| self
->session
->focused
) &&
280 /* this means focus=true for window is same as config_focus_new=true */
281 ((config_focus_new
|| (settings
&& settings
->focus
== 1)) ||
282 client_search_focus_tree_full(self
)) &&
283 /* this checks for focus=false for the window */
284 (!settings
|| settings
->focus
!= 0) &&
285 focus_valid_target(self
, FALSE
, FALSE
, TRUE
, FALSE
, FALSE
))
290 /* remove the client's border */
291 XSetWindowBorderWidth(obt_display
, self
->window
, 0);
293 /* adjust the frame to the client's size before showing or placing
295 frame_adjust_area(self
->frame
, FALSE
, TRUE
, FALSE
);
296 frame_adjust_client_area(self
->frame
);
298 /* where the frame was placed is where the window was originally */
300 monitor
= screen_physical_area_monitor(screen_find_monitor(&place
));
302 /* figure out placement for the window if the window is new */
303 if (ob_state() == OB_STATE_RUNNING
) {
304 ob_debug("Positioned: %s @ %d %d",
305 (!self
->positioned
? "no" :
306 (self
->positioned
== PPosition
? "program specified" :
307 (self
->positioned
== USPosition
? "user specified" :
308 (self
->positioned
== (PPosition
| USPosition
) ?
309 "program + user specified" :
310 "BADNESS !?")))), place
.x
, place
.y
);
312 ob_debug("Sized: %s @ %d %d",
313 (!self
->sized
? "no" :
314 (self
->sized
== PSize
? "program specified" :
315 (self
->sized
== USSize
? "user specified" :
316 (self
->sized
== (PSize
| USSize
) ?
317 "program + user specified" :
318 "BADNESS !?")))), place
.width
, place
.height
);
320 /* splash screens are also returned as TRUE for transient,
321 and so will be forced on screen below */
322 transient
= place_client(self
, &place
.x
, &place
.y
, settings
);
324 /* make sure the window is visible. */
325 client_find_onscreen(self
, &place
.x
, &place
.y
,
326 place
.width
, place
.height
,
327 /* non-normal clients has less rules, and
328 windows that are being restored from a
329 session do also. we can assume you want
330 it back where you saved it. Clients saying
331 they placed themselves are subjected to
332 harder rules, ones that are placed by
333 place.c or by the user are allowed partially
334 off-screen and on xinerama divides (ie,
335 it is up to the placement routines to avoid
336 the xinerama divides)
338 splash screens get "transient" set to TRUE by
339 the place_client call
341 ob_state() == OB_STATE_RUNNING
&&
343 (!((self
->positioned
& USPosition
) ||
344 (settings
&& settings
->pos_given
)) &&
345 client_normal(self
) &&
347 /* don't move oldschool fullscreen windows to
348 fit inside the struts (fixes Acroread, which
349 makes its fullscreen window fit the screen
350 but it is not USSize'd or USPosition'd) */
351 !(self
->decorations
== 0 &&
352 RECT_EQUAL(place
, *monitor
)))));
355 /* if the window isn't user-sized, then make it fit inside
356 the visible screen area on its monitor. Use basically the same rules
357 for forcing the window on screen in the client_find_onscreen call.
359 do this after place_client, it chooses the monitor!
361 splash screens get "transient" set to TRUE by
362 the place_client call
364 if (ob_state() == OB_STATE_RUNNING
&&
366 (!(self
->sized
& USSize
|| self
->positioned
& USPosition
) &&
367 client_normal(self
) &&
369 /* don't shrink oldschool fullscreen windows to fit inside the
370 struts (fixes Acroread, which makes its fullscreen window
371 fit the screen but it is not USSize'd or USPosition'd) */
372 !(self
->decorations
== 0 && RECT_EQUAL(place
, *monitor
)))))
374 Rect
*a
= screen_area(self
->desktop
, SCREEN_AREA_ONE_MONITOR
, &place
);
376 /* get the size of the frame */
377 place
.width
+= self
->frame
->size
.left
+ self
->frame
->size
.right
;
378 place
.height
+= self
->frame
->size
.top
+ self
->frame
->size
.bottom
;
380 /* fit the window inside the area */
381 place
.width
= MIN(place
.width
, a
->width
);
382 place
.height
= MIN(place
.height
, a
->height
);
384 ob_debug("setting window size to %dx%d", place
.width
, place
.height
);
386 /* get the size of the client back */
387 place
.width
-= self
->frame
->size
.left
+ self
->frame
->size
.right
;
388 place
.height
-= self
->frame
->size
.top
+ self
->frame
->size
.bottom
;
393 ob_debug("placing window 0x%x at %d, %d with size %d x %d. "
394 "some restrictions may apply",
395 self
->window
, place
.x
, place
.y
, place
.width
, place
.height
);
397 ob_debug(" but session requested %d, %d %d x %d instead, "
399 self
->session
->x
, self
->session
->y
,
400 self
->session
->w
, self
->session
->h
);
402 /* do this after the window is placed, so the premax/prefullscreen numbers
405 this also places the window
407 client_apply_startup_state(self
, place
.x
, place
.y
,
408 place
.width
, place
.height
);
413 ob_debug_type(OB_DEBUG_FOCUS
, "Going to try activate new window? %s",
414 activate
? "yes" : "no");
416 gboolean raise
= FALSE
;
417 gboolean relative_focused
= FALSE
;
419 relative_focused
= (focus_client
!= NULL
&&
420 client_search_focus_tree_full(self
) != NULL
&&
421 client_search_focus_group_full(self
) != NULL
);
424 /* This is focus stealing prevention */
425 ob_debug_type(OB_DEBUG_FOCUS
,
426 "Want to focus new window 0x%x at time %u "
427 "launched at %u (last user interaction time %u)",
428 self
->window
, map_time
, launch_time
,
429 event_last_user_time
);
431 if (menu_frame_visible
|| moveresize_in_progress
) {
434 ob_debug_type(OB_DEBUG_FOCUS
,
435 "Not focusing the window because the user is inside "
436 "an Openbox menu or is move/resizing a window and "
437 "we don't want to interrupt them");
440 /* if it's on another desktop */
441 else if (!(self
->desktop
== screen_desktop
||
442 self
->desktop
== DESKTOP_ALL
) &&
443 /* the timestamp is from before you changed desktops */
444 launch_time
&& screen_desktop_user_time
&&
445 !event_time_after(launch_time
, screen_desktop_user_time
))
449 ob_debug_type(OB_DEBUG_FOCUS
,
450 "Not focusing the window because its on another "
453 /* If something is focused... */
454 else if (focus_client
) {
455 /* If the user is working in another window right now, then don't
457 if (event_last_user_time
&& launch_time
&&
458 event_time_after(event_last_user_time
, launch_time
) &&
459 event_last_user_time
!= launch_time
&&
460 event_time_after(event_last_user_time
,
461 map_time
- OB_EVENT_USER_TIME_DELAY
))
464 ob_debug_type(OB_DEBUG_FOCUS
,
465 "Not focusing the window because the user is "
466 "working in another window");
468 /* If the new window is a transient (and its relatives aren't
470 else if (client_has_parent(self
) && !relative_focused
) {
472 ob_debug_type(OB_DEBUG_FOCUS
,
473 "Not focusing the window because it is a "
474 "transient, and its relatives aren't focused");
476 /* Don't steal focus from globally active clients.
477 I stole this idea from KWin. It seems nice.
479 else if (!(focus_client
->can_focus
||
480 focus_client
->focus_notify
))
483 ob_debug_type(OB_DEBUG_FOCUS
,
484 "Not focusing the window because a globally "
485 "active client has focus");
487 /* Don't move focus if it's not going to go to this window
489 else if (client_focus_target(self
) != self
) {
492 ob_debug_type(OB_DEBUG_FOCUS
,
493 "Not focusing the window because another window "
494 "would get the focus anyway");
496 /* Don't move focus if the window is not visible on the current
497 desktop and none of its relatives are focused */
498 else if (!(self
->desktop
== screen_desktop
||
499 self
->desktop
== DESKTOP_ALL
) &&
504 ob_debug_type(OB_DEBUG_FOCUS
,
505 "Not focusing the window because it is on "
506 "another desktop and no relatives are focused ");
511 ob_debug_type(OB_DEBUG_FOCUS
,
512 "Focus stealing prevention activated for %s at "
513 "time %u (last user interaction time %u)",
514 self
->title
, map_time
, event_last_user_time
);
515 /* if the client isn't focused, then hilite it so the user
517 client_hilite(self
, TRUE
);
518 /* we may want to raise it even tho we're not activating it */
519 if (raise
&& !client_restore_session_stacking(self
))
520 stacking_raise(CLIENT_AS_WINDOW(self
));
524 /* This may look rather odd. Well it's because new windows are added
525 to the stacking order non-intrusively. If we're not going to focus
526 the new window or hilite it, then we raise it to the top. This will
527 take affect for things that don't get focused like splash screens.
528 Also if you don't have focus_new enabled, then it's going to get
529 raised to the top. Legacy begets legacy I guess?
531 if (!client_restore_session_stacking(self
))
532 stacking_raise(CLIENT_AS_WINDOW(self
));
535 mouse_grab_for_client(self
, TRUE
);
537 /* this has to happen before we try focus the window, but we want it to
538 happen after the client's stacking has been determined or it looks bad
542 if (!config_focus_under_mouse
)
543 ignore_start
= event_start_ignore_all_enters();
547 if (!config_focus_under_mouse
)
548 event_end_ignore_all_enters(ignore_start
);
552 gboolean stacked
= client_restore_session_stacking(self
);
553 client_present(self
, FALSE
, !stacked
, TRUE
);
556 /* add to client list/map */
557 client_list
= g_list_append(client_list
, self
);
558 window_add(&self
->window
, CLIENT_AS_WINDOW(self
));
560 /* this has to happen after we're in the client_list */
561 if (STRUT_EXISTS(self
->strut
))
562 screen_update_areas();
564 /* update the list hints */
567 /* free the ObAppSettings shallow copy */
570 ob_debug("Managed window 0x%lx plate 0x%x (%s)",
571 window
, self
->frame
->window
, self
->class);
573 hooks_queue(OB_HOOK_WIN_NEW
, self
);
577 ObClient
*client_fake_manage(Window window
)
580 ObAppSettings
*settings
;
582 ob_debug("Pretend-managing window: %lx", window
);
584 /* do this minimal stuff to figure out the client's decorations */
586 self
= g_new0(ObClient
, 1);
587 self
->window
= window
;
589 client_get_all(self
, FALSE
);
590 /* per-app settings override stuff, and return the settings for other
591 uses too. this returns a shallow copy that needs to be freed */
592 settings
= client_get_settings_state(self
);
594 client_setup_decor_and_functions(self
, FALSE
);
596 /* create the decoration frame for the client window and adjust its size */
597 self
->frame
= frame_new(self
);
598 frame_adjust_area(self
->frame
, FALSE
, TRUE
, TRUE
);
600 ob_debug("gave extents left %d right %d top %d bottom %d",
601 self
->frame
->size
.left
, self
->frame
->size
.right
,
602 self
->frame
->size
.top
, self
->frame
->size
.bottom
);
604 /* free the ObAppSettings shallow copy */
610 void client_unmanage_all(void)
613 client_unmanage(client_list
->data
);
616 void client_unmanage(ObClient
*self
)
621 ob_debug("Unmanaging window: 0x%x plate 0x%x (%s) (%s)",
622 self
->window
, self
->frame
->window
,
623 self
->class, self
->title
? self
->title
: "");
625 g_assert(self
!= NULL
);
627 /* we dont want events no more. do this before hiding the frame so we
628 don't generate more events */
629 XSelectInput(obt_display
, self
->window
, NoEventMask
);
631 /* ignore enter events from the unmap so it doesnt mess with the focus */
632 if (!config_focus_under_mouse
)
633 ignore_start
= event_start_ignore_all_enters();
635 frame_hide(self
->frame
);
636 /* flush to send the hide to the server quickly */
639 if (!config_focus_under_mouse
)
640 event_end_ignore_all_enters(ignore_start
);
642 mouse_grab_for_client(self
, FALSE
);
644 /* remove the window from our save set, unless we are managing an internal
647 XChangeSaveSet(obt_display
, self
->window
, SetModeDelete
);
649 /* this can't be queued to run later */
650 hooks_run(OB_HOOK_WIN_CLOSE
, self
);
652 /* update the focus lists */
653 focus_order_remove(self
);
654 if (client_focused(self
)) {
655 /* don't leave an invalid focus_client */
659 /* if we're prompting to kill the client, close that */
660 prompt_unref(self
->kill_prompt
);
661 self
->kill_prompt
= NULL
;
663 client_list
= g_list_remove(client_list
, self
);
664 stacking_remove(self
);
665 window_remove(self
->window
);
667 /* once the client is out of the list, update the struts to remove its
669 if (STRUT_EXISTS(self
->strut
))
670 screen_update_areas();
672 client_call_notifies(self
, client_destroy_notifies
);
674 /* tell our parent(s) that we're gone */
675 for (it
= self
->parents
; it
; it
= g_slist_next(it
))
676 ((ObClient
*)it
->data
)->transients
=
677 g_slist_remove(((ObClient
*)it
->data
)->transients
,self
);
679 /* tell our transients that we're gone */
680 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
681 ((ObClient
*)it
->data
)->parents
=
682 g_slist_remove(((ObClient
*)it
->data
)->parents
, self
);
683 /* we could be keeping our children in a higher layer */
684 client_calc_layer(it
->data
);
687 /* remove from its group */
689 group_remove(self
->group
, self
);
693 /* restore the window's original geometry so it is not lost */
699 if (self
->fullscreen
)
700 a
= self
->pre_fullscreen_area
;
701 else if (self
->max_horz
|| self
->max_vert
) {
702 if (self
->max_horz
) {
703 a
.x
= self
->pre_max_area
.x
;
704 a
.width
= self
->pre_max_area
.width
;
706 if (self
->max_vert
) {
707 a
.y
= self
->pre_max_area
.y
;
708 a
.height
= self
->pre_max_area
.height
;
712 self
->fullscreen
= self
->max_horz
= self
->max_vert
= FALSE
;
713 /* let it be moved and resized no matter what */
714 self
->functions
= OB_CLIENT_FUNC_MOVE
| OB_CLIENT_FUNC_RESIZE
;
715 self
->decorations
= 0; /* unmanaged windows have no decor */
717 /* give the client its border back */
718 XSetWindowBorderWidth(obt_display
, self
->window
, self
->border_width
);
720 client_move_resize(self
, a
.x
, a
.y
, a
.width
, a
.height
);
723 /* reparent the window out of the frame, and free the frame */
724 frame_release_client(self
->frame
);
725 frame_free(self
->frame
);
728 if (ob_state() != OB_STATE_EXITING
) {
729 /* these values should not be persisted across a window
731 OBT_PROP_ERASE(self
->window
, NET_WM_DESKTOP
);
732 OBT_PROP_ERASE(self
->window
, NET_WM_STATE
);
733 OBT_PROP_ERASE(self
->window
, WM_STATE
);
735 /* if we're left in an unmapped state, the client wont be mapped.
736 this is bad, since we will no longer be managing the window on
738 XMapWindow(obt_display
, self
->window
);
741 /* these should not be left on the window ever. other window managers
742 don't necessarily use them and it will mess them up (like compiz) */
743 OBT_PROP_ERASE(self
->window
, NET_WM_VISIBLE_NAME
);
744 OBT_PROP_ERASE(self
->window
, NET_WM_VISIBLE_ICON_NAME
);
746 /* update the list hints */
749 ob_debug("Unmanaged window 0x%lx", self
->window
);
751 /* free all data allocated in the client struct */
752 RrImageUnref(self
->icon_set
);
753 g_slist_free(self
->transients
);
754 g_free(self
->startup_id
);
755 g_free(self
->wm_command
);
757 g_free(self
->icon_title
);
758 g_free(self
->original_title
);
762 g_free(self
->client_machine
);
763 g_free(self
->sm_client_id
);
767 void client_fake_unmanage(ObClient
*self
)
769 /* this is all that got allocated to get the decorations */
771 frame_free(self
->frame
);
775 /*! Returns a new structure containing the per-app settings for this client.
776 The returned structure needs to be freed with g_free. */
777 static ObAppSettings
*client_get_settings_state(ObClient
*self
)
779 ObAppSettings
*settings
;
782 settings
= config_create_app_settings();
784 for (it
= config_per_app_settings
; it
; it
= g_slist_next(it
)) {
785 ObAppSettings
*app
= it
->data
;
786 gboolean match
= TRUE
;
788 g_assert(app
->name
!= NULL
|| app
->class != NULL
);
790 /* we know that either name or class is not NULL so it will have to
791 match to use the rule */
793 !g_pattern_match(app
->name
, strlen(self
->name
), self
->name
, NULL
))
795 else if (app
->class &&
796 !g_pattern_match(app
->class,
797 strlen(self
->class), self
->class, NULL
))
799 else if (app
->role
&&
800 !g_pattern_match(app
->role
,
801 strlen(self
->role
), self
->role
, NULL
))
803 else if ((signed)app
->type
>= 0 && app
->type
!= self
->type
)
807 ob_debug("Window matching: %s", app
->name
);
809 /* copy the settings to our struct, overriding the existing
810 settings if they are not defaults */
811 config_app_settings_copy_non_defaults(app
, settings
);
815 if (settings
->shade
!= -1)
816 self
->shaded
= !!settings
->shade
;
817 if (settings
->decor
!= -1)
818 self
->undecorated
= !settings
->decor
;
819 if (settings
->iconic
!= -1)
820 self
->iconic
= !!settings
->iconic
;
821 if (settings
->skip_pager
!= -1)
822 self
->skip_pager
= !!settings
->skip_pager
;
823 if (settings
->skip_taskbar
!= -1)
824 self
->skip_taskbar
= !!settings
->skip_taskbar
;
826 if (settings
->max_vert
!= -1)
827 self
->max_vert
= !!settings
->max_vert
;
828 if (settings
->max_horz
!= -1)
829 self
->max_horz
= !!settings
->max_horz
;
831 if (settings
->fullscreen
!= -1)
832 self
->fullscreen
= !!settings
->fullscreen
;
834 if (settings
->desktop
) {
835 if (settings
->desktop
== DESKTOP_ALL
)
836 self
->desktop
= settings
->desktop
;
837 else if (settings
->desktop
> 0 &&
838 settings
->desktop
<= screen_num_desktops
)
839 self
->desktop
= settings
->desktop
- 1;
842 if (settings
->layer
== -1) {
846 else if (settings
->layer
== 0) {
850 else if (settings
->layer
== 1) {
857 static void client_restore_session_state(ObClient
*self
)
861 ob_debug_type(OB_DEBUG_SM
,
862 "Restore session for client %s", self
->title
);
864 if (!(it
= session_state_find(self
))) {
865 ob_debug_type(OB_DEBUG_SM
,
866 "Session data not found for client %s", self
->title
);
870 self
->session
= it
->data
;
872 ob_debug_type(OB_DEBUG_SM
, "Session data loaded for client %s",
875 RECT_SET_POINT(self
->area
, self
->session
->x
, self
->session
->y
);
876 self
->positioned
= USPosition
;
877 self
->sized
= USSize
;
878 if (self
->session
->w
> 0)
879 self
->area
.width
= self
->session
->w
;
880 if (self
->session
->h
> 0)
881 self
->area
.height
= self
->session
->h
;
882 XResizeWindow(obt_display
, self
->window
,
883 self
->area
.width
, self
->area
.height
);
885 self
->desktop
= (self
->session
->desktop
== DESKTOP_ALL
?
886 self
->session
->desktop
:
887 MIN(screen_num_desktops
- 1, self
->session
->desktop
));
888 OBT_PROP_SET32(self
->window
, NET_WM_DESKTOP
, CARDINAL
, self
->desktop
);
890 self
->shaded
= self
->session
->shaded
;
891 self
->iconic
= self
->session
->iconic
;
892 self
->skip_pager
= self
->session
->skip_pager
;
893 self
->skip_taskbar
= self
->session
->skip_taskbar
;
894 self
->fullscreen
= self
->session
->fullscreen
;
895 self
->above
= self
->session
->above
;
896 self
->below
= self
->session
->below
;
897 self
->max_horz
= self
->session
->max_horz
;
898 self
->max_vert
= self
->session
->max_vert
;
899 self
->undecorated
= self
->session
->undecorated
;
902 static gboolean
client_restore_session_stacking(ObClient
*self
)
906 if (!self
->session
) return FALSE
;
908 mypos
= g_list_find(session_saved_state
, self
->session
);
909 if (!mypos
) return FALSE
;
911 /* start above me and look for the first client */
912 for (it
= g_list_previous(mypos
); it
; it
= g_list_previous(it
)) {
915 for (cit
= client_list
; cit
; cit
= g_list_next(cit
)) {
916 ObClient
*c
= cit
->data
;
917 /* found a client that was in the session, so go below it */
918 if (c
->session
== it
->data
) {
919 stacking_below(CLIENT_AS_WINDOW(self
),
920 CLIENT_AS_WINDOW(cit
->data
));
928 void client_move_onscreen(ObClient
*self
, gboolean rude
)
930 gint x
= self
->area
.x
;
931 gint y
= self
->area
.y
;
932 if (client_find_onscreen(self
, &x
, &y
,
934 self
->area
.height
, rude
)) {
935 client_move(self
, x
, y
);
939 gboolean
client_find_onscreen(ObClient
*self
, gint
*x
, gint
*y
, gint w
, gint h
,
942 gint ox
= *x
, oy
= *y
;
943 gboolean rudel
= rude
, ruder
= rude
, rudet
= rude
, rudeb
= rude
;
949 RECT_SET(desired
, *x
, *y
, w
, h
);
950 frame_rect_to_frame(self
->frame
, &desired
);
952 /* get where the frame would be */
953 frame_client_gravity(self
->frame
, x
, y
);
955 /* get the requested size of the window with decorations */
956 fw
= self
->frame
->size
.left
+ w
+ self
->frame
->size
.right
;
957 fh
= self
->frame
->size
.top
+ h
+ self
->frame
->size
.bottom
;
959 /* If rudeness wasn't requested, then still be rude in a given direction
960 if the client is not moving, only resizing in that direction */
962 Point oldtl
, oldtr
, oldbl
, oldbr
;
963 Point newtl
, newtr
, newbl
, newbr
;
964 gboolean stationary_l
, stationary_r
, stationary_t
, stationary_b
;
966 POINT_SET(oldtl
, self
->frame
->area
.x
, self
->frame
->area
.y
);
967 POINT_SET(oldbr
, self
->frame
->area
.x
+ self
->frame
->area
.width
- 1,
968 self
->frame
->area
.y
+ self
->frame
->area
.height
- 1);
969 POINT_SET(oldtr
, oldbr
.x
, oldtl
.y
);
970 POINT_SET(oldbl
, oldtl
.x
, oldbr
.y
);
972 POINT_SET(newtl
, *x
, *y
);
973 POINT_SET(newbr
, *x
+ fw
- 1, *y
+ fh
- 1);
974 POINT_SET(newtr
, newbr
.x
, newtl
.y
);
975 POINT_SET(newbl
, newtl
.x
, newbr
.y
);
977 /* is it moving or just resizing from some corner? */
978 stationary_l
= oldtl
.x
== newtl
.x
;
979 stationary_r
= oldtr
.x
== newtr
.x
;
980 stationary_t
= oldtl
.y
== newtl
.y
;
981 stationary_b
= oldbl
.y
== newbl
.y
;
983 /* if left edge is growing and didnt move right edge */
984 if (stationary_r
&& newtl
.x
< oldtl
.x
)
986 /* if right edge is growing and didnt move left edge */
987 if (stationary_l
&& newtr
.x
> oldtr
.x
)
989 /* if top edge is growing and didnt move bottom edge */
990 if (stationary_b
&& newtl
.y
< oldtl
.y
)
992 /* if bottom edge is growing and didnt move top edge */
993 if (stationary_t
&& newbl
.y
> oldbl
.y
)
997 /* we iterate through every monitor that the window is at least partially
998 on, to make sure it is obeying the rules on them all
1000 if the window does not appear on any monitors, then use the first one
1003 for (i
= 0; i
< screen_num_monitors
; ++i
) {
1006 if (!screen_physical_area_monitor_contains(i
, &desired
)) {
1007 if (i
< screen_num_monitors
- 1 || found_mon
)
1010 /* the window is not inside any monitor! so just use the first
1012 a
= screen_area(self
->desktop
, 0, NULL
);
1015 a
= screen_area(self
->desktop
, SCREEN_AREA_ONE_MONITOR
, &desired
);
1018 /* This makes sure windows aren't entirely outside of the screen so you
1019 can't see them at all.
1020 It makes sure 10% of the window is on the screen at least. And don't
1021 let it move itself off the top of the screen, which would hide the
1022 titlebar on you. (The user can still do this if they want too, it's
1023 only limiting the application.
1025 if (client_normal(self
)) {
1026 if (!self
->strut
.right
&& *x
+ fw
/10 >= a
->x
+ a
->width
- 1)
1027 *x
= a
->x
+ a
->width
- fw
/10;
1028 if (!self
->strut
.bottom
&& *y
+ fh
/10 >= a
->y
+ a
->height
- 1)
1029 *y
= a
->y
+ a
->height
- fh
/10;
1030 if (!self
->strut
.left
&& *x
+ fw
*9/10 - 1 < a
->x
)
1031 *x
= a
->x
- fw
*9/10;
1032 if (!self
->strut
.top
&& *y
+ fh
*9/10 - 1 < a
->y
)
1033 *y
= a
->y
- fh
*9/10;
1036 /* This here doesn't let windows even a pixel outside the
1037 struts/screen. When called from client_manage, programs placing
1038 themselves are forced completely onscreen, while things like
1039 xterm -geometry resolution-width/2 will work fine. Trying to
1040 place it completely offscreen will be handled in the above code.
1041 Sorry for this confused comment, i am tired. */
1042 if (rudel
&& !self
->strut
.left
&& *x
< a
->x
) *x
= a
->x
;
1043 if (ruder
&& !self
->strut
.right
&& *x
+ fw
> a
->x
+ a
->width
)
1044 *x
= a
->x
+ MAX(0, a
->width
- fw
);
1046 if (rudet
&& !self
->strut
.top
&& *y
< a
->y
) *y
= a
->y
;
1047 if (rudeb
&& !self
->strut
.bottom
&& *y
+ fh
> a
->y
+ a
->height
)
1048 *y
= a
->y
+ MAX(0, a
->height
- fh
);
1053 /* get where the client should be */
1054 frame_frame_gravity(self
->frame
, x
, y
);
1056 return ox
!= *x
|| oy
!= *y
;
1059 static void client_get_all(ObClient
*self
, gboolean real
)
1061 /* this is needed for the frame to set itself up */
1062 client_get_area(self
);
1064 /* these things can change the decor and functions of the window */
1066 client_get_mwm_hints(self
);
1067 /* this can change the mwmhints for special cases */
1068 client_get_type_and_transientness(self
);
1069 client_get_state(self
);
1070 client_update_normal_hints(self
);
1072 /* get the session related properties, these can change decorations
1073 from per-app settings */
1074 client_get_session_ids(self
);
1076 /* now we got everything that can affect the decorations */
1080 /* get this early so we have it for debugging */
1081 client_update_title(self
);
1083 client_update_protocols(self
);
1085 client_update_wmhints(self
);
1086 /* this may have already been called from client_update_wmhints */
1087 if (!self
->parents
&& !self
->transient_for_group
)
1088 client_update_transient_for(self
);
1090 client_get_startup_id(self
);
1091 client_get_desktop(self
);/* uses transient data/group/startup id if a
1092 desktop is not specified */
1093 client_get_shaped(self
);
1096 /* a couple type-based defaults for new windows */
1098 /* this makes sure that these windows appear on all desktops */
1099 if (self
->type
== OB_CLIENT_TYPE_DESKTOP
)
1100 self
->desktop
= DESKTOP_ALL
;
1104 client_update_sync_request_counter(self
);
1107 client_get_colormap(self
);
1108 client_update_strut(self
);
1109 client_update_icons(self
);
1110 client_update_icon_geometry(self
);
1113 static void client_get_startup_id(ObClient
*self
)
1115 if (!(OBT_PROP_GETS(self
->window
, NET_STARTUP_ID
, utf8
,
1116 &self
->startup_id
)))
1118 OBT_PROP_GETS(self
->group
->leader
,
1119 NET_STARTUP_ID
, utf8
, &self
->startup_id
);
1122 static void client_get_area(ObClient
*self
)
1124 XWindowAttributes wattrib
;
1127 ret
= XGetWindowAttributes(obt_display
, self
->window
, &wattrib
);
1128 g_assert(ret
!= BadWindow
);
1130 RECT_SET(self
->area
, wattrib
.x
, wattrib
.y
, wattrib
.width
, wattrib
.height
);
1131 POINT_SET(self
->root_pos
, wattrib
.x
, wattrib
.y
);
1132 self
->border_width
= wattrib
.border_width
;
1134 ob_debug("client area: %d %d %d %d bw %d", wattrib
.x
, wattrib
.y
,
1135 wattrib
.width
, wattrib
.height
, wattrib
.border_width
);
1138 static void client_get_desktop(ObClient
*self
)
1140 guint32 d
= screen_num_desktops
; /* an always-invalid value */
1142 if (OBT_PROP_GET32(self
->window
, NET_WM_DESKTOP
, CARDINAL
, &d
)) {
1143 if (d
>= screen_num_desktops
&& d
!= DESKTOP_ALL
)
1144 self
->desktop
= screen_num_desktops
- 1;
1147 ob_debug("client requested desktop 0x%x", self
->desktop
);
1150 gboolean first
= TRUE
;
1151 guint all
= screen_num_desktops
; /* not a valid value */
1153 /* if they are all on one desktop, then open it on the
1155 for (it
= self
->parents
; it
; it
= g_slist_next(it
)) {
1156 ObClient
*c
= it
->data
;
1158 if (c
->desktop
== DESKTOP_ALL
) continue;
1164 else if (all
!= c
->desktop
)
1165 all
= screen_num_desktops
; /* make it invalid */
1167 if (all
!= screen_num_desktops
) {
1168 self
->desktop
= all
;
1170 ob_debug("client desktop set from parents: 0x%x",
1173 /* try get from the startup-notification protocol */
1174 else if (sn_get_desktop(self
->startup_id
, &self
->desktop
)) {
1175 if (self
->desktop
>= screen_num_desktops
&&
1176 self
->desktop
!= DESKTOP_ALL
)
1177 self
->desktop
= screen_num_desktops
- 1;
1178 ob_debug("client desktop set from startup-notification: 0x%x",
1181 /* defaults to the current desktop */
1183 self
->desktop
= screen_desktop
;
1184 ob_debug("client desktop set to the current desktop: %d",
1190 static void client_get_state(ObClient
*self
)
1195 if (OBT_PROP_GETA32(self
->window
, NET_WM_STATE
, ATOM
, &state
, &num
)) {
1197 for (i
= 0; i
< num
; ++i
) {
1198 if (state
[i
] == OBT_PROP_ATOM(NET_WM_STATE_MODAL
))
1200 else if (state
[i
] == OBT_PROP_ATOM(NET_WM_STATE_SHADED
))
1201 self
->shaded
= TRUE
;
1202 else if (state
[i
] == OBT_PROP_ATOM(NET_WM_STATE_HIDDEN
))
1203 self
->iconic
= TRUE
;
1204 else if (state
[i
] == OBT_PROP_ATOM(NET_WM_STATE_SKIP_TASKBAR
))
1205 self
->skip_taskbar
= TRUE
;
1206 else if (state
[i
] == OBT_PROP_ATOM(NET_WM_STATE_SKIP_PAGER
))
1207 self
->skip_pager
= TRUE
;
1208 else if (state
[i
] == OBT_PROP_ATOM(NET_WM_STATE_FULLSCREEN
))
1209 self
->fullscreen
= TRUE
;
1210 else if (state
[i
] == OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_VERT
))
1211 self
->max_vert
= TRUE
;
1212 else if (state
[i
] == OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_HORZ
))
1213 self
->max_horz
= TRUE
;
1214 else if (state
[i
] == OBT_PROP_ATOM(NET_WM_STATE_ABOVE
))
1216 else if (state
[i
] == OBT_PROP_ATOM(NET_WM_STATE_BELOW
))
1218 else if (state
[i
] == OBT_PROP_ATOM(NET_WM_STATE_DEMANDS_ATTENTION
))
1219 self
->demands_attention
= TRUE
;
1220 else if (state
[i
] == OBT_PROP_ATOM(OB_WM_STATE_UNDECORATED
))
1221 self
->undecorated
= TRUE
;
1228 static void client_get_shaped(ObClient
*self
)
1230 self
->shaped
= FALSE
;
1232 if (obt_display_extension_shape
) {
1237 XShapeSelectInput(obt_display
, self
->window
, ShapeNotifyMask
);
1239 XShapeQueryExtents(obt_display
, self
->window
, &s
, &foo
,
1240 &foo
, &ufoo
, &ufoo
, &foo
, &foo
, &foo
, &ufoo
,
1247 void client_update_transient_for(ObClient
*self
)
1250 ObClient
*target
= NULL
;
1251 gboolean trangroup
= FALSE
;
1253 if (XGetTransientForHint(obt_display
, self
->window
, &t
)) {
1254 if (t
!= self
->window
) { /* can't be transient to itself! */
1255 ObWindow
*tw
= window_find(t
);
1256 /* if this happens then we need to check for it */
1257 g_assert(tw
!= CLIENT_AS_WINDOW(self
));
1258 if (tw
&& WINDOW_IS_CLIENT(tw
)) {
1259 /* watch out for windows with a parent that is something
1260 different, like a dockapp for example */
1261 target
= WINDOW_AS_CLIENT(tw
);
1265 /* Setting the transient_for to Root is actually illegal, however
1266 applications from time have done this to specify transient for
1268 if (!target
&& self
->group
&& t
== obt_root(ob_screen
))
1270 } else if (self
->group
&& self
->transient
)
1273 client_update_transient_tree(self
, self
->group
, self
->group
,
1274 self
->transient_for_group
, trangroup
,
1275 client_direct_parent(self
), target
);
1276 self
->transient_for_group
= trangroup
;
1280 static void client_update_transient_tree(ObClient
*self
,
1281 ObGroup
*oldgroup
, ObGroup
*newgroup
,
1282 gboolean oldgtran
, gboolean newgtran
,
1283 ObClient
* oldparent
,
1284 ObClient
*newparent
)
1289 g_assert(!oldgtran
|| oldgroup
);
1290 g_assert(!newgtran
|| newgroup
);
1291 g_assert((!oldgtran
&& !oldparent
) ||
1292 (oldgtran
&& !oldparent
) ||
1293 (!oldgtran
&& oldparent
));
1294 g_assert((!newgtran
&& !newparent
) ||
1295 (newgtran
&& !newparent
) ||
1296 (!newgtran
&& newparent
));
1299 Group transient windows are not allowed to have other group
1300 transient windows as their children.
1304 /* No change has occured */
1305 if (oldgroup
== newgroup
&&
1306 oldgtran
== newgtran
&&
1307 oldparent
== newparent
) return;
1309 /** Remove the client from the transient tree **/
1311 for (it
= self
->transients
; it
; it
= next
) {
1312 next
= g_slist_next(it
);
1314 self
->transients
= g_slist_delete_link(self
->transients
, it
);
1315 c
->parents
= g_slist_remove(c
->parents
, self
);
1317 for (it
= self
->parents
; it
; it
= next
) {
1318 next
= g_slist_next(it
);
1320 self
->parents
= g_slist_delete_link(self
->parents
, it
);
1321 c
->transients
= g_slist_remove(c
->transients
, self
);
1324 /** Re-add the client to the transient tree **/
1326 /* If we're transient for a group then we need to add ourselves to all our
1329 for (it
= newgroup
->members
; it
; it
= g_slist_next(it
)) {
1332 !client_search_top_direct_parent(c
)->transient_for_group
&&
1335 c
->transients
= g_slist_prepend(c
->transients
, self
);
1336 self
->parents
= g_slist_prepend(self
->parents
, c
);
1341 /* If we are now transient for a single window we need to add ourselves to
1344 WARNING: Cyclical transient-ness is possible if two windows are
1345 transient for eachother.
1347 else if (newparent
&&
1348 /* don't make ourself its child if it is already our child */
1349 !client_is_direct_child(self
, newparent
) &&
1350 client_normal(newparent
))
1352 newparent
->transients
= g_slist_prepend(newparent
->transients
, self
);
1353 self
->parents
= g_slist_prepend(self
->parents
, newparent
);
1356 /* Add any group transient windows to our children. But if we're transient
1357 for the group, then other group transients are not our children.
1359 WARNING: Cyclical transient-ness is possible. For e.g. if:
1360 A is transient for the group
1361 B is transient for A
1362 C is transient for B
1363 A can't be transient for C or we have a cycle
1365 if (!newgtran
&& newgroup
&&
1367 !client_search_top_direct_parent(newparent
)->transient_for_group
) &&
1368 client_normal(self
))
1370 for (it
= newgroup
->members
; it
; it
= g_slist_next(it
)) {
1372 if (c
!= self
&& c
->transient_for_group
&&
1373 /* Don't make it our child if it is already our parent */
1374 !client_is_direct_child(c
, self
))
1376 self
->transients
= g_slist_prepend(self
->transients
, c
);
1377 c
->parents
= g_slist_prepend(c
->parents
, self
);
1382 /** If we change our group transient-ness, our children change their
1383 effective group transient-ness, which affects how they relate to other
1386 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
1388 if (!c
->transient_for_group
)
1389 client_update_transient_tree(c
, c
->group
, c
->group
,
1390 c
->transient_for_group
,
1391 c
->transient_for_group
,
1392 client_direct_parent(c
),
1393 client_direct_parent(c
));
1397 static void client_get_mwm_hints(ObClient
*self
)
1402 self
->mwmhints
.flags
= 0; /* default to none */
1404 if (OBT_PROP_GETA32(self
->window
, MOTIF_WM_HINTS
, MOTIF_WM_HINTS
,
1406 if (num
>= OB_MWM_ELEMENTS
) {
1407 self
->mwmhints
.flags
= hints
[0];
1408 self
->mwmhints
.functions
= hints
[1];
1409 self
->mwmhints
.decorations
= hints
[2];
1415 void client_get_type_and_transientness(ObClient
*self
)
1422 self
->transient
= FALSE
;
1424 if (OBT_PROP_GETA32(self
->window
, NET_WM_WINDOW_TYPE
, ATOM
, &val
, &num
)) {
1425 /* use the first value that we know about in the array */
1426 for (i
= 0; i
< num
; ++i
) {
1427 if (val
[i
] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_DESKTOP
))
1428 self
->type
= OB_CLIENT_TYPE_DESKTOP
;
1429 else if (val
[i
] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_DOCK
))
1430 self
->type
= OB_CLIENT_TYPE_DOCK
;
1431 else if (val
[i
] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_TOOLBAR
))
1432 self
->type
= OB_CLIENT_TYPE_TOOLBAR
;
1433 else if (val
[i
] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_MENU
))
1434 self
->type
= OB_CLIENT_TYPE_MENU
;
1435 else if (val
[i
] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_UTILITY
))
1436 self
->type
= OB_CLIENT_TYPE_UTILITY
;
1437 else if (val
[i
] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_SPLASH
))
1438 self
->type
= OB_CLIENT_TYPE_SPLASH
;
1439 else if (val
[i
] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_DIALOG
))
1440 self
->type
= OB_CLIENT_TYPE_DIALOG
;
1441 else if (val
[i
] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_NORMAL
))
1442 self
->type
= OB_CLIENT_TYPE_NORMAL
;
1443 else if (val
[i
] == OBT_PROP_ATOM(KDE_NET_WM_WINDOW_TYPE_OVERRIDE
))
1445 /* prevent this window from getting any decor or
1447 self
->mwmhints
.flags
&= (OB_MWM_FLAG_FUNCTIONS
|
1448 OB_MWM_FLAG_DECORATIONS
);
1449 self
->mwmhints
.decorations
= 0;
1450 self
->mwmhints
.functions
= 0;
1452 if (self
->type
!= (ObClientType
) -1)
1453 break; /* grab the first legit type */
1458 if (XGetTransientForHint(obt_display
, self
->window
, &t
))
1459 self
->transient
= TRUE
;
1461 if (self
->type
== (ObClientType
) -1) {
1462 /*the window type hint was not set, which means we either classify
1463 ourself as a normal window or a dialog, depending on if we are a
1465 if (self
->transient
)
1466 self
->type
= OB_CLIENT_TYPE_DIALOG
;
1468 self
->type
= OB_CLIENT_TYPE_NORMAL
;
1471 /* then, based on our type, we can update our transientness.. */
1472 if (self
->type
== OB_CLIENT_TYPE_DIALOG
||
1473 self
->type
== OB_CLIENT_TYPE_TOOLBAR
||
1474 self
->type
== OB_CLIENT_TYPE_MENU
||
1475 self
->type
== OB_CLIENT_TYPE_UTILITY
)
1477 self
->transient
= TRUE
;
1481 void client_update_protocols(ObClient
*self
)
1486 self
->focus_notify
= FALSE
;
1487 self
->delete_window
= FALSE
;
1489 if (OBT_PROP_GETA32(self
->window
, WM_PROTOCOLS
, ATOM
, &proto
, &num_ret
)) {
1490 for (i
= 0; i
< num_ret
; ++i
) {
1491 if (proto
[i
] == OBT_PROP_ATOM(WM_DELETE_WINDOW
))
1492 /* this means we can request the window to close */
1493 self
->delete_window
= TRUE
;
1494 else if (proto
[i
] == OBT_PROP_ATOM(WM_TAKE_FOCUS
))
1495 /* if this protocol is requested, then the window will be
1496 notified whenever we want it to receive focus */
1497 self
->focus_notify
= TRUE
;
1498 else if (proto
[i
] == OBT_PROP_ATOM(NET_WM_PING
))
1499 /* if this protocol is requested, then the window will allow
1500 pings to determine if it is still alive */
1503 else if (proto
[i
] == OBT_PROP_ATOM(NET_WM_SYNC_REQUEST
))
1504 /* if this protocol is requested, then resizing the
1505 window will be synchronized between the frame and the
1507 self
->sync_request
= TRUE
;
1515 void client_update_sync_request_counter(ObClient
*self
)
1519 if (OBT_PROP_GET32(self
->window
, NET_WM_SYNC_REQUEST_COUNTER
, CARDINAL
,&i
))
1521 self
->sync_counter
= i
;
1523 self
->sync_counter
= None
;
1527 static void client_get_colormap(ObClient
*self
)
1529 XWindowAttributes wa
;
1531 if (XGetWindowAttributes(obt_display
, self
->window
, &wa
))
1532 client_update_colormap(self
, wa
.colormap
);
1535 void client_update_colormap(ObClient
*self
, Colormap colormap
)
1537 if (colormap
== self
->colormap
) return;
1539 ob_debug("Setting client %s colormap: 0x%x", self
->title
, colormap
);
1541 if (client_focused(self
)) {
1542 screen_install_colormap(self
, FALSE
); /* uninstall old one */
1543 self
->colormap
= colormap
;
1544 screen_install_colormap(self
, TRUE
); /* install new one */
1546 self
->colormap
= colormap
;
1549 void client_update_normal_hints(ObClient
*self
)
1555 self
->min_ratio
= 0.0f
;
1556 self
->max_ratio
= 0.0f
;
1557 SIZE_SET(self
->size_inc
, 1, 1);
1558 SIZE_SET(self
->base_size
, -1, -1);
1559 SIZE_SET(self
->min_size
, 0, 0);
1560 SIZE_SET(self
->max_size
, G_MAXINT
, G_MAXINT
);
1562 /* get the hints from the window */
1563 if (XGetWMNormalHints(obt_display
, self
->window
, &size
, &ret
)) {
1564 /* normal windows can't request placement! har har
1565 if (!client_normal(self))
1567 self
->positioned
= (size
.flags
& (PPosition
|USPosition
));
1568 self
->sized
= (size
.flags
& (PSize
|USSize
));
1570 if (size
.flags
& PWinGravity
)
1571 self
->gravity
= size
.win_gravity
;
1573 if (size
.flags
& PAspect
) {
1574 if (size
.min_aspect
.y
)
1576 (gfloat
) size
.min_aspect
.x
/ size
.min_aspect
.y
;
1577 if (size
.max_aspect
.y
)
1579 (gfloat
) size
.max_aspect
.x
/ size
.max_aspect
.y
;
1582 if (size
.flags
& PMinSize
)
1583 SIZE_SET(self
->min_size
, size
.min_width
, size
.min_height
);
1585 if (size
.flags
& PMaxSize
)
1586 SIZE_SET(self
->max_size
, size
.max_width
, size
.max_height
);
1588 if (size
.flags
& PBaseSize
)
1589 SIZE_SET(self
->base_size
, size
.base_width
, size
.base_height
);
1591 if (size
.flags
& PResizeInc
&& size
.width_inc
&& size
.height_inc
)
1592 SIZE_SET(self
->size_inc
, size
.width_inc
, size
.height_inc
);
1594 ob_debug("Normal hints: min size (%d %d) max size (%d %d)",
1595 self
->min_size
.width
, self
->min_size
.height
,
1596 self
->max_size
.width
, self
->max_size
.height
);
1597 ob_debug("size inc (%d %d) base size (%d %d)",
1598 self
->size_inc
.width
, self
->size_inc
.height
,
1599 self
->base_size
.width
, self
->base_size
.height
);
1602 ob_debug("Normal hints: not set");
1605 void client_setup_decor_and_functions(ObClient
*self
, gboolean reconfig
)
1607 /* start with everything (cept fullscreen) */
1609 (OB_FRAME_DECOR_TITLEBAR
|
1610 OB_FRAME_DECOR_HANDLE
|
1611 OB_FRAME_DECOR_GRIPS
|
1612 OB_FRAME_DECOR_BORDER
|
1613 OB_FRAME_DECOR_ICON
|
1614 OB_FRAME_DECOR_ALLDESKTOPS
|
1615 OB_FRAME_DECOR_ICONIFY
|
1616 OB_FRAME_DECOR_MAXIMIZE
|
1617 OB_FRAME_DECOR_SHADE
|
1618 OB_FRAME_DECOR_CLOSE
);
1620 (OB_CLIENT_FUNC_RESIZE
|
1621 OB_CLIENT_FUNC_MOVE
|
1622 OB_CLIENT_FUNC_ICONIFY
|
1623 OB_CLIENT_FUNC_MAXIMIZE
|
1624 OB_CLIENT_FUNC_SHADE
|
1625 OB_CLIENT_FUNC_CLOSE
|
1626 OB_CLIENT_FUNC_BELOW
|
1627 OB_CLIENT_FUNC_ABOVE
|
1628 OB_CLIENT_FUNC_UNDECORATE
);
1630 if (!(self
->min_size
.width
< self
->max_size
.width
||
1631 self
->min_size
.height
< self
->max_size
.height
))
1632 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
1634 switch (self
->type
) {
1635 case OB_CLIENT_TYPE_NORMAL
:
1636 /* normal windows retain all of the possible decorations and
1637 functionality, and can be fullscreen */
1638 self
->functions
|= OB_CLIENT_FUNC_FULLSCREEN
;
1641 case OB_CLIENT_TYPE_DIALOG
:
1642 /* sometimes apps make dialog windows fullscreen for some reason (for
1643 e.g. kpdf does this..) */
1644 self
->functions
|= OB_CLIENT_FUNC_FULLSCREEN
;
1647 case OB_CLIENT_TYPE_UTILITY
:
1648 /* these windows don't have anything added or removed by default */
1651 case OB_CLIENT_TYPE_MENU
:
1652 case OB_CLIENT_TYPE_TOOLBAR
:
1653 /* these windows can't iconify or maximize */
1654 self
->decorations
&= ~(OB_FRAME_DECOR_ICONIFY
|
1655 OB_FRAME_DECOR_MAXIMIZE
);
1656 self
->functions
&= ~(OB_CLIENT_FUNC_ICONIFY
|
1657 OB_CLIENT_FUNC_MAXIMIZE
);
1660 case OB_CLIENT_TYPE_SPLASH
:
1661 /* these don't get get any decorations, and the only thing you can
1662 do with them is move them */
1663 self
->decorations
= 0;
1664 self
->functions
= OB_CLIENT_FUNC_MOVE
;
1667 case OB_CLIENT_TYPE_DESKTOP
:
1668 /* these windows are not manipulated by the window manager */
1669 self
->decorations
= 0;
1670 self
->functions
= 0;
1673 case OB_CLIENT_TYPE_DOCK
:
1674 /* these windows are not manipulated by the window manager, but they
1675 can set below layer which has a special meaning */
1676 self
->decorations
= 0;
1677 self
->functions
= OB_CLIENT_FUNC_BELOW
;
1681 /* Mwm Hints are applied subtractively to what has already been chosen for
1682 decor and functionality */
1683 if (self
->mwmhints
.flags
& OB_MWM_FLAG_DECORATIONS
) {
1684 if (! (self
->mwmhints
.decorations
& OB_MWM_DECOR_ALL
)) {
1685 if (! ((self
->mwmhints
.decorations
& OB_MWM_DECOR_HANDLE
) ||
1686 (self
->mwmhints
.decorations
& OB_MWM_DECOR_TITLE
)))
1688 /* if the mwm hints request no handle or title, then all
1689 decorations are disabled, but keep the border if that's
1691 if (self
->mwmhints
.decorations
& OB_MWM_DECOR_BORDER
)
1692 self
->decorations
= OB_FRAME_DECOR_BORDER
;
1694 self
->decorations
= 0;
1699 if (self
->mwmhints
.flags
& OB_MWM_FLAG_FUNCTIONS
) {
1700 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_ALL
)) {
1701 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_RESIZE
))
1702 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
1703 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_MOVE
))
1704 self
->functions
&= ~OB_CLIENT_FUNC_MOVE
;
1705 /* dont let mwm hints kill any buttons
1706 if (! (self->mwmhints.functions & OB_MWM_FUNC_ICONIFY))
1707 self->functions &= ~OB_CLIENT_FUNC_ICONIFY;
1708 if (! (self->mwmhints.functions & OB_MWM_FUNC_MAXIMIZE))
1709 self->functions &= ~OB_CLIENT_FUNC_MAXIMIZE;
1711 /* dont let mwm hints kill the close button
1712 if (! (self->mwmhints.functions & MwmFunc_Close))
1713 self->functions &= ~OB_CLIENT_FUNC_CLOSE; */
1717 if (!(self
->functions
& OB_CLIENT_FUNC_SHADE
))
1718 self
->decorations
&= ~OB_FRAME_DECOR_SHADE
;
1719 if (!(self
->functions
& OB_CLIENT_FUNC_ICONIFY
))
1720 self
->decorations
&= ~OB_FRAME_DECOR_ICONIFY
;
1721 if (!(self
->functions
& OB_CLIENT_FUNC_RESIZE
))
1722 self
->decorations
&= ~(OB_FRAME_DECOR_GRIPS
| OB_FRAME_DECOR_HANDLE
);
1724 /* can't maximize without moving/resizing */
1725 if (!((self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) &&
1726 (self
->functions
& OB_CLIENT_FUNC_MOVE
) &&
1727 (self
->functions
& OB_CLIENT_FUNC_RESIZE
))) {
1728 self
->functions
&= ~OB_CLIENT_FUNC_MAXIMIZE
;
1729 self
->decorations
&= ~OB_FRAME_DECOR_MAXIMIZE
;
1732 if (self
->max_horz
&& self
->max_vert
) {
1733 /* you can't resize fully maximized windows */
1734 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
1735 /* kill the handle on fully maxed windows */
1736 self
->decorations
&= ~(OB_FRAME_DECOR_HANDLE
| OB_FRAME_DECOR_GRIPS
);
1739 /* If there are no decorations to remove, don't allow the user to try
1741 if (self
->decorations
== 0)
1742 self
->functions
&= ~OB_CLIENT_FUNC_UNDECORATE
;
1744 /* finally, the user can have requested no decorations, which overrides
1745 everything (but doesnt give it a border if it doesnt have one) */
1746 if (self
->undecorated
)
1747 self
->decorations
= 0;
1749 /* if we don't have a titlebar, then we cannot shade! */
1750 if (!(self
->decorations
& OB_FRAME_DECOR_TITLEBAR
))
1751 self
->functions
&= ~OB_CLIENT_FUNC_SHADE
;
1753 /* now we need to check against rules for the client's current state */
1754 if (self
->fullscreen
) {
1755 self
->functions
&= (OB_CLIENT_FUNC_CLOSE
|
1756 OB_CLIENT_FUNC_FULLSCREEN
|
1757 OB_CLIENT_FUNC_ICONIFY
);
1758 self
->decorations
= 0;
1761 client_change_allowed_actions(self
);
1764 /* force reconfigure to make sure decorations are updated */
1765 client_reconfigure(self
, TRUE
);
1768 static void client_change_allowed_actions(ObClient
*self
)
1773 /* desktop windows are kept on all desktops */
1774 if (self
->type
!= OB_CLIENT_TYPE_DESKTOP
)
1775 actions
[num
++] = OBT_PROP_ATOM(NET_WM_ACTION_CHANGE_DESKTOP
);
1777 if (self
->functions
& OB_CLIENT_FUNC_SHADE
)
1778 actions
[num
++] = OBT_PROP_ATOM(NET_WM_ACTION_SHADE
);
1779 if (self
->functions
& OB_CLIENT_FUNC_CLOSE
)
1780 actions
[num
++] = OBT_PROP_ATOM(NET_WM_ACTION_CLOSE
);
1781 if (self
->functions
& OB_CLIENT_FUNC_MOVE
)
1782 actions
[num
++] = OBT_PROP_ATOM(NET_WM_ACTION_MOVE
);
1783 if (self
->functions
& OB_CLIENT_FUNC_ICONIFY
)
1784 actions
[num
++] = OBT_PROP_ATOM(NET_WM_ACTION_MINIMIZE
);
1785 if (self
->functions
& OB_CLIENT_FUNC_RESIZE
)
1786 actions
[num
++] = OBT_PROP_ATOM(NET_WM_ACTION_RESIZE
);
1787 if (self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
)
1788 actions
[num
++] = OBT_PROP_ATOM(NET_WM_ACTION_FULLSCREEN
);
1789 if (self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) {
1790 actions
[num
++] = OBT_PROP_ATOM(NET_WM_ACTION_MAXIMIZE_HORZ
);
1791 actions
[num
++] = OBT_PROP_ATOM(NET_WM_ACTION_MAXIMIZE_VERT
);
1793 if (self
->functions
& OB_CLIENT_FUNC_ABOVE
)
1794 actions
[num
++] = OBT_PROP_ATOM(NET_WM_ACTION_ABOVE
);
1795 if (self
->functions
& OB_CLIENT_FUNC_BELOW
)
1796 actions
[num
++] = OBT_PROP_ATOM(NET_WM_ACTION_BELOW
);
1797 if (self
->functions
& OB_CLIENT_FUNC_UNDECORATE
)
1798 actions
[num
++] = OBT_PROP_ATOM(OB_WM_ACTION_UNDECORATE
);
1800 OBT_PROP_SETA32(self
->window
, NET_WM_ALLOWED_ACTIONS
, ATOM
, actions
, num
);
1802 /* make sure the window isn't breaking any rules now
1804 don't check ICONIFY here. just cuz a window can't iconify doesnt mean
1805 it can't be iconified with its parent
1808 if (!(self
->functions
& OB_CLIENT_FUNC_SHADE
) && self
->shaded
) {
1809 if (self
->frame
) client_shade(self
, FALSE
);
1810 else self
->shaded
= FALSE
;
1812 if (!(self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
) && self
->fullscreen
) {
1813 if (self
->frame
) client_fullscreen(self
, FALSE
);
1814 else self
->fullscreen
= FALSE
;
1816 if (!(self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) && (self
->max_horz
||
1818 if (self
->frame
) client_maximize(self
, FALSE
, 0);
1819 else self
->max_vert
= self
->max_horz
= FALSE
;
1823 void client_update_wmhints(ObClient
*self
)
1827 /* assume a window takes input if it doesn't specify */
1828 self
->can_focus
= TRUE
;
1830 if ((hints
= XGetWMHints(obt_display
, self
->window
)) != NULL
) {
1833 if (hints
->flags
& InputHint
)
1834 self
->can_focus
= hints
->input
;
1836 /* only do this when first managing the window *AND* when we aren't
1838 if (ob_state() != OB_STATE_STARTING
&& self
->frame
== NULL
)
1839 if (hints
->flags
& StateHint
)
1840 self
->iconic
= hints
->initial_state
== IconicState
;
1843 self
->urgent
= (hints
->flags
& XUrgencyHint
);
1844 if (self
->urgent
&& !ur
)
1845 client_hilite(self
, TRUE
);
1846 else if (!self
->urgent
&& ur
&& self
->demands_attention
)
1847 client_hilite(self
, FALSE
);
1849 if (!(hints
->flags
& WindowGroupHint
))
1850 hints
->window_group
= None
;
1852 /* did the group state change? */
1853 if (hints
->window_group
!=
1854 (self
->group
? self
->group
->leader
: None
))
1856 ObGroup
*oldgroup
= self
->group
;
1858 /* remove from the old group if there was one */
1860 group_remove(self
->group
, self
);
1864 /* add ourself to the group if we have one */
1865 if (hints
->window_group
!= None
) {
1866 self
->group
= group_add(hints
->window_group
, self
);
1869 /* Put ourselves into the new group's transient tree, and remove
1870 ourselves from the old group's */
1871 client_update_transient_tree(self
, oldgroup
, self
->group
,
1872 self
->transient_for_group
,
1873 self
->transient_for_group
,
1874 client_direct_parent(self
),
1875 client_direct_parent(self
));
1877 /* Lastly, being in a group, or not, can change if the window is
1878 transient for anything.
1880 The logic for this is:
1881 self->transient = TRUE always if the window wants to be
1882 transient for something, even if transient_for was NULL because
1883 it wasn't in a group before.
1885 If parents was NULL and oldgroup was NULL we can assume
1886 that when we add the new group, it will become transient for
1889 If transient_for_group is TRUE, then it must have already
1890 had a group. If it is getting a new group, the above call to
1891 client_update_transient_tree has already taken care of
1892 everything ! If it is losing all group status then it will
1893 no longer be transient for anything and that needs to be
1896 if (self
->transient
&&
1897 ((self
->parents
== NULL
&& oldgroup
== NULL
) ||
1898 (self
->transient_for_group
&& !self
->group
)))
1899 client_update_transient_for(self
);
1902 /* the WM_HINTS can contain an icon */
1903 if (hints
->flags
& IconPixmapHint
)
1904 client_update_icons(self
);
1910 void client_update_title(ObClient
*self
)
1913 gchar
*visible
= NULL
;
1915 g_free(self
->title
);
1916 g_free(self
->original_title
);
1919 if (!OBT_PROP_GETS(self
->window
, NET_WM_NAME
, utf8
, &data
)) {
1920 /* try old x stuff */
1921 if (!(OBT_PROP_GETS(self
->window
, WM_NAME
, locale
, &data
)
1922 || OBT_PROP_GETS(self
->window
, WM_NAME
, utf8
, &data
))) {
1923 if (self
->transient
) {
1925 GNOME alert windows are not given titles:
1926 http://developer.gnome.org/projects/gup/hig/draft_hig_new/windows-alert.html
1928 data
= g_strdup("");
1930 data
= g_strdup(_("Unnamed Window"));
1933 self
->original_title
= g_strdup(data
);
1935 if (self
->client_machine
) {
1936 visible
= g_strdup_printf("%s (%s)", data
, self
->client_machine
);
1941 if (self
->not_responding
) {
1943 if (self
->kill_level
> 0)
1944 visible
= g_strdup_printf("%s - [%s]", data
, _("Killing..."));
1946 visible
= g_strdup_printf("%s - [%s]", data
, _("Not Responding"));
1950 OBT_PROP_SETS(self
->window
, NET_WM_VISIBLE_NAME
, utf8
, visible
);
1951 self
->title
= visible
;
1954 frame_adjust_title(self
->frame
);
1956 /* update the icon title */
1958 g_free(self
->icon_title
);
1961 if (!OBT_PROP_GETS(self
->window
, NET_WM_ICON_NAME
, utf8
, &data
))
1962 /* try old x stuff */
1963 if (!(OBT_PROP_GETS(self
->window
, WM_ICON_NAME
, locale
, &data
) ||
1964 OBT_PROP_GETS(self
->window
, WM_ICON_NAME
, utf8
, &data
)))
1965 data
= g_strdup(self
->title
);
1967 if (self
->client_machine
) {
1968 visible
= g_strdup_printf("%s (%s)", data
, self
->client_machine
);
1973 if (self
->not_responding
) {
1975 if (self
->kill_level
> 0)
1976 visible
= g_strdup_printf("%s - [%s]", data
, _("Killing..."));
1978 visible
= g_strdup_printf("%s - [%s]", data
, _("Not Responding"));
1982 OBT_PROP_SETS(self
->window
, NET_WM_VISIBLE_ICON_NAME
, utf8
, visible
);
1983 self
->icon_title
= visible
;
1986 void client_update_strut(ObClient
*self
)
1990 gboolean got
= FALSE
;
1993 if (OBT_PROP_GETA32(self
->window
, NET_WM_STRUT_PARTIAL
, CARDINAL
,
1998 STRUT_PARTIAL_SET(strut
,
1999 data
[0], data
[2], data
[1], data
[3],
2000 data
[4], data
[5], data
[8], data
[9],
2001 data
[6], data
[7], data
[10], data
[11]);
2007 OBT_PROP_GETA32(self
->window
, NET_WM_STRUT
, CARDINAL
, &data
, &num
)) {
2013 /* use the screen's width/height */
2014 a
= screen_physical_area_all_monitors();
2016 STRUT_PARTIAL_SET(strut
,
2017 data
[0], data
[2], data
[1], data
[3],
2018 a
->y
, a
->y
+ a
->height
- 1,
2019 a
->x
, a
->x
+ a
->width
- 1,
2020 a
->y
, a
->y
+ a
->height
- 1,
2021 a
->x
, a
->x
+ a
->width
- 1);
2028 STRUT_PARTIAL_SET(strut
, 0, 0, 0, 0,
2029 0, 0, 0, 0, 0, 0, 0, 0);
2031 if (!STRUT_EQUAL(strut
, self
->strut
)) {
2032 self
->strut
= strut
;
2034 /* updating here is pointless while we're being mapped cuz we're not in
2035 the client list yet */
2037 screen_update_areas();
2041 void client_update_icons(ObClient
*self
)
2046 guint num_seen
; /* number of icons present */
2051 /* grab the server, because we might be setting the window's icon and
2052 we don't want them to set it in between and we overwrite their own
2056 if (OBT_PROP_GETA32(self
->window
, NET_WM_ICON
, CARDINAL
, &data
, &num
)) {
2057 /* figure out how many valid icons are in here */
2060 while (i
+ 2 < num
) { /* +2 is to make sure there is a w and h */
2063 /* watch for the data being too small for the specified size,
2064 or for zero sized icons. */
2065 if (i
+ w
*h
> num
|| w
== 0 || h
== 0) break;
2067 /* convert it to the right bit order for ObRender */
2068 for (j
= 0; j
< w
*h
; ++j
)
2070 (((data
[i
+j
] >> 24) & 0xff) << RrDefaultAlphaOffset
) +
2071 (((data
[i
+j
] >> 16) & 0xff) << RrDefaultRedOffset
) +
2072 (((data
[i
+j
] >> 8) & 0xff) << RrDefaultGreenOffset
) +
2073 (((data
[i
+j
] >> 0) & 0xff) << RrDefaultBlueOffset
);
2075 /* is it in the cache? */
2076 img
= RrImageCacheFind(ob_rr_icons
, &data
[i
], w
, h
);
2077 if (img
) RrImageRef(img
); /* own it */
2082 /* don't bother looping anymore if we already found it in the cache
2083 since we'll just use that! */
2087 /* if it's not in the cache yet, then add it to the cache now.
2088 we have already converted it to the correct bit order above */
2089 if (!img
&& num_seen
> 0) {
2090 img
= RrImageNew(ob_rr_icons
);
2092 for (j
= 0; j
< num_seen
; ++j
) {
2095 RrImageAddPicture(img
, &data
[i
], w
, h
);
2103 /* if we didn't find an image from the NET_WM_ICON stuff, then try the
2108 if ((hints
= XGetWMHints(obt_display
, self
->window
))) {
2109 if (hints
->flags
& IconPixmapHint
) {
2111 obt_display_ignore_errors(TRUE
);
2112 xicon
= RrPixmapToRGBA(ob_rr_inst
,
2114 (hints
->flags
& IconMaskHint
?
2115 hints
->icon_mask
: None
),
2116 (gint
*)&w
, (gint
*)&h
, &data
);
2117 obt_display_ignore_errors(FALSE
);
2121 if (w
> 0 && h
> 0) {
2122 /* is this icon in the cache yet? */
2123 img
= RrImageCacheFind(ob_rr_icons
, data
, w
, h
);
2124 if (img
) RrImageRef(img
); /* own it */
2126 /* if not, then add it */
2128 img
= RrImageNew(ob_rr_icons
);
2129 RrImageAddPicture(img
, data
, w
, h
);
2140 /* set the client's icons to be whatever we found */
2141 RrImageUnref(self
->icon_set
);
2142 self
->icon_set
= img
;
2144 /* if the client has no icon at all, then we set a default icon onto it.
2145 but, if it has parents, then one of them will have an icon already
2147 if (!self
->icon_set
&& !self
->parents
) {
2148 RrPixel32
*icon
= ob_rr_theme
->def_win_icon
;
2149 gulong
*ldata
; /* use a long here to satisfy OBT_PROP_SETA32 */
2151 w
= ob_rr_theme
->def_win_icon_w
;
2152 h
= ob_rr_theme
->def_win_icon_h
;
2153 ldata
= g_new(gulong
, w
*h
+2);
2156 for (i
= 0; i
< w
*h
; ++i
)
2157 ldata
[i
+2] = (((icon
[i
] >> RrDefaultAlphaOffset
) & 0xff) << 24) +
2158 (((icon
[i
] >> RrDefaultRedOffset
) & 0xff) << 16) +
2159 (((icon
[i
] >> RrDefaultGreenOffset
) & 0xff) << 8) +
2160 (((icon
[i
] >> RrDefaultBlueOffset
) & 0xff) << 0);
2161 OBT_PROP_SETA32(self
->window
, NET_WM_ICON
, CARDINAL
, ldata
, w
*h
+2);
2163 } else if (self
->frame
)
2164 /* don't draw the icon empty if we're just setting one now anyways,
2165 we'll get the property change any second */
2166 frame_adjust_icon(self
->frame
);
2171 void client_update_icon_geometry(ObClient
*self
)
2176 RECT_SET(self
->icon_geometry
, 0, 0, 0, 0);
2178 if (OBT_PROP_GETA32(self
->window
, NET_WM_ICON_GEOMETRY
, CARDINAL
,
2182 /* don't let them set it with an area < 0 */
2183 RECT_SET(self
->icon_geometry
, data
[0], data
[1],
2184 MAX(data
[2],0), MAX(data
[3],0));
2189 static void client_get_session_ids(ObClient
*self
)
2196 if (!OBT_PROP_GET32(self
->window
, WM_CLIENT_LEADER
, WINDOW
, &leader
))
2199 /* get the SM_CLIENT_ID */
2202 got
= OBT_PROP_GETS(leader
, SM_CLIENT_ID
, locale
, &self
->sm_client_id
);
2204 OBT_PROP_GETS(self
->window
, SM_CLIENT_ID
, locale
, &self
->sm_client_id
);
2206 /* get the WM_CLASS (name and class). make them "" if they are not
2210 got
= OBT_PROP_GETSS(leader
, WM_CLASS
, locale
, &ss
);
2212 got
= OBT_PROP_GETSS(self
->window
, WM_CLASS
, locale
, &ss
);
2216 self
->name
= g_strdup(ss
[0]);
2218 self
->class = g_strdup(ss
[1]);
2223 if (self
->name
== NULL
) self
->name
= g_strdup("");
2224 if (self
->class == NULL
) self
->class = g_strdup("");
2226 /* get the WM_WINDOW_ROLE. make it "" if it is not provided */
2229 got
= OBT_PROP_GETS(leader
, WM_WINDOW_ROLE
, locale
, &s
);
2231 got
= OBT_PROP_GETS(self
->window
, WM_WINDOW_ROLE
, locale
, &s
);
2236 self
->role
= g_strdup("");
2238 /* get the WM_COMMAND */
2242 got
= OBT_PROP_GETSS(leader
, WM_COMMAND
, locale
, &ss
);
2244 got
= OBT_PROP_GETSS(self
->window
, WM_COMMAND
, locale
, &ss
);
2247 /* merge/mash them all together */
2248 gchar
*merge
= NULL
;
2251 for (i
= 0; ss
[i
]; ++i
) {
2254 merge
= g_strconcat(merge
, ss
[i
], NULL
);
2256 merge
= g_strconcat(ss
[i
], NULL
);
2261 self
->wm_command
= merge
;
2264 /* get the WM_CLIENT_MACHINE */
2267 got
= OBT_PROP_GETS(leader
, WM_CLIENT_MACHINE
, locale
, &s
);
2269 got
= OBT_PROP_GETS(self
->window
, WM_CLIENT_MACHINE
, locale
, &s
);
2272 gchar localhost
[128];
2275 gethostname(localhost
, 127);
2276 localhost
[127] = '\0';
2277 if (strcmp(localhost
, s
) != 0)
2278 self
->client_machine
= s
;
2282 /* see if it has the PID set too (the PID requires that the
2283 WM_CLIENT_MACHINE be set) */
2284 if (OBT_PROP_GET32(self
->window
, NET_WM_PID
, CARDINAL
, &pid
))
2289 static void client_change_wm_state(ObClient
*self
)
2294 old
= self
->wmstate
;
2296 if (self
->shaded
|| self
->iconic
||
2297 (self
->desktop
!= DESKTOP_ALL
&& self
->desktop
!= screen_desktop
))
2299 self
->wmstate
= IconicState
;
2301 self
->wmstate
= NormalState
;
2303 if (old
!= self
->wmstate
) {
2304 OBT_PROP_MSG(ob_screen
, self
->window
, KDE_WM_CHANGE_STATE
,
2305 self
->wmstate
, 1, 0, 0, 0);
2307 state
[0] = self
->wmstate
;
2309 OBT_PROP_SETA32(self
->window
, WM_STATE
, WM_STATE
, state
, 2);
2313 static void client_change_state(ObClient
*self
)
2315 gulong netstate
[12];
2320 netstate
[num
++] = OBT_PROP_ATOM(NET_WM_STATE_MODAL
);
2322 netstate
[num
++] = OBT_PROP_ATOM(NET_WM_STATE_SHADED
);
2324 netstate
[num
++] = OBT_PROP_ATOM(NET_WM_STATE_HIDDEN
);
2325 if (self
->skip_taskbar
)
2326 netstate
[num
++] = OBT_PROP_ATOM(NET_WM_STATE_SKIP_TASKBAR
);
2327 if (self
->skip_pager
)
2328 netstate
[num
++] = OBT_PROP_ATOM(NET_WM_STATE_SKIP_PAGER
);
2329 if (self
->fullscreen
)
2330 netstate
[num
++] = OBT_PROP_ATOM(NET_WM_STATE_FULLSCREEN
);
2332 netstate
[num
++] = OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_VERT
);
2334 netstate
[num
++] = OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_HORZ
);
2336 netstate
[num
++] = OBT_PROP_ATOM(NET_WM_STATE_ABOVE
);
2338 netstate
[num
++] = OBT_PROP_ATOM(NET_WM_STATE_BELOW
);
2339 if (self
->demands_attention
)
2340 netstate
[num
++] = OBT_PROP_ATOM(NET_WM_STATE_DEMANDS_ATTENTION
);
2341 if (self
->undecorated
)
2342 netstate
[num
++] = OBT_PROP_ATOM(OB_WM_STATE_UNDECORATED
);
2343 OBT_PROP_SETA32(self
->window
, NET_WM_STATE
, ATOM
, netstate
, num
);
2346 frame_adjust_state(self
->frame
);
2349 ObClient
*client_search_focus_tree(ObClient
*self
)
2354 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
2355 if (client_focused(it
->data
)) return it
->data
;
2356 if ((ret
= client_search_focus_tree(it
->data
))) return ret
;
2361 ObClient
*client_search_focus_tree_full(ObClient
*self
)
2363 if (self
->parents
) {
2366 for (it
= self
->parents
; it
; it
= g_slist_next(it
)) {
2367 ObClient
*c
= it
->data
;
2368 if ((c
= client_search_focus_tree_full(it
->data
))) return c
;
2374 /* this function checks the whole tree, the client_search_focus_tree
2375 does not, so we need to check this window */
2376 if (client_focused(self
))
2378 return client_search_focus_tree(self
);
2382 ObClient
*client_search_focus_group_full(ObClient
*self
)
2387 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
2388 ObClient
*c
= it
->data
;
2390 if (client_focused(c
)) return c
;
2391 if ((c
= client_search_focus_tree(it
->data
))) return c
;
2394 if (client_focused(self
)) return self
;
2398 gboolean
client_has_parent(ObClient
*self
)
2400 return self
->parents
!= NULL
;
2403 static ObStackingLayer
calc_layer(ObClient
*self
)
2408 monitor
= screen_physical_area_monitor(client_monitor(self
));
2410 if (self
->type
== OB_CLIENT_TYPE_DESKTOP
)
2411 l
= OB_STACKING_LAYER_DESKTOP
;
2412 else if (self
->type
== OB_CLIENT_TYPE_DOCK
) {
2413 if (self
->below
) l
= OB_STACKING_LAYER_NORMAL
;
2414 else l
= OB_STACKING_LAYER_ABOVE
;
2416 else if ((self
->fullscreen
||
2417 /* No decorations and fills the monitor = oldskool fullscreen.
2418 But not for maximized windows.
2420 (self
->decorations
== 0 &&
2421 !(self
->max_horz
&& self
->max_vert
) &&
2422 RECT_EQUAL(self
->area
, *monitor
))) &&
2423 /* you are fullscreen while you or your children are focused.. */
2424 (client_focused(self
) || client_search_focus_tree(self
) ||
2425 /* you can be fullscreen if you're on another desktop */
2426 (self
->desktop
!= screen_desktop
&&
2427 self
->desktop
!= DESKTOP_ALL
) ||
2428 /* and you can also be fullscreen if the focused client is on
2429 another monitor, or nothing else is focused */
2431 client_monitor(focus_client
) != client_monitor(self
))))
2432 l
= OB_STACKING_LAYER_FULLSCREEN
;
2433 else if (self
->above
) l
= OB_STACKING_LAYER_ABOVE
;
2434 else if (self
->below
) l
= OB_STACKING_LAYER_BELOW
;
2435 else l
= OB_STACKING_LAYER_NORMAL
;
2442 static void client_calc_layer_recursive(ObClient
*self
, ObClient
*orig
,
2443 ObStackingLayer min
)
2445 ObStackingLayer old
, own
;
2449 own
= calc_layer(self
);
2450 self
->layer
= MAX(own
, min
);
2452 if (self
->layer
!= old
) {
2453 stacking_remove(CLIENT_AS_WINDOW(self
));
2454 stacking_add_nonintrusive(CLIENT_AS_WINDOW(self
));
2457 /* we've been restacked */
2458 self
->visited
= TRUE
;
2460 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
2461 client_calc_layer_recursive(it
->data
, orig
,
2465 static void client_calc_layer_internal(ObClient
*self
)
2469 /* transients take on the layer of their parents */
2470 sit
= client_search_all_top_parents(self
);
2472 for (; sit
; sit
= g_slist_next(sit
))
2473 client_calc_layer_recursive(sit
->data
, self
, 0);
2476 void client_calc_layer(ObClient
*self
)
2480 /* skip over stuff above fullscreen layer */
2481 for (it
= stacking_list
; it
; it
= g_list_next(it
))
2482 if (window_layer(it
->data
) <= OB_STACKING_LAYER_FULLSCREEN
) break;
2484 /* find the windows in the fullscreen layer, and mark them not-visited */
2485 for (; it
; it
= g_list_next(it
)) {
2486 if (window_layer(it
->data
) < OB_STACKING_LAYER_FULLSCREEN
) break;
2487 else if (WINDOW_IS_CLIENT(it
->data
))
2488 WINDOW_AS_CLIENT(it
->data
)->visited
= FALSE
;
2491 client_calc_layer_internal(self
);
2493 /* skip over stuff above fullscreen layer */
2494 for (it
= stacking_list
; it
; it
= g_list_next(it
))
2495 if (window_layer(it
->data
) <= OB_STACKING_LAYER_FULLSCREEN
) break;
2497 /* now recalc any windows in the fullscreen layer which have not
2498 had their layer recalced already */
2499 for (; it
; it
= g_list_next(it
)) {
2500 if (window_layer(it
->data
) < OB_STACKING_LAYER_FULLSCREEN
) break;
2501 else if (WINDOW_IS_CLIENT(it
->data
) &&
2502 !WINDOW_AS_CLIENT(it
->data
)->visited
)
2503 client_calc_layer_internal(it
->data
);
2507 gboolean
client_should_show(ObClient
*self
)
2511 if (client_normal(self
) && screen_showing_desktop
)
2513 if (self
->desktop
== screen_desktop
|| self
->desktop
== DESKTOP_ALL
)
2519 gboolean
client_show(ObClient
*self
)
2521 gboolean show
= FALSE
;
2523 if (client_should_show(self
)) {
2524 /* replay pending pointer event before showing the window, in case it
2525 should be going to something under the window */
2526 mouse_replay_pointer();
2528 frame_show(self
->frame
);
2531 /* According to the ICCCM (sec 4.1.3.1) when a window is not visible,
2532 it needs to be in IconicState. This includes when it is on another
2535 client_change_wm_state(self
);
2537 hooks_queue(OB_HOOK_WIN_VISIBLE
, self
);
2542 gboolean
client_hide(ObClient
*self
)
2544 gboolean hide
= FALSE
;
2546 if (!client_should_show(self
)) {
2547 if (self
== focus_client
) {
2548 event_cancel_all_key_grabs();
2551 /* We don't need to ignore enter events here.
2552 The window can hide/iconify in 3 different ways:
2553 1 - through an x message. in this case we ignore all enter events
2554 caused by responding to the x message (unless underMouse)
2555 2 - by a keyboard action. in this case we ignore all enter events
2556 caused by the action
2557 3 - by a mouse action. in this case they are doing stuff with the
2558 mouse and focus _should_ move.
2560 Also in action_end, we simulate an enter event that can't be ignored
2561 so trying to ignore them is futile in case 3 anyways
2564 /* replay pending pointer event before hiding the window, in case it
2565 should be going to the window */
2566 mouse_replay_pointer();
2568 frame_hide(self
->frame
);
2571 /* According to the ICCCM (sec 4.1.3.1) when a window is not visible,
2572 it needs to be in IconicState. This includes when it is on another
2575 client_change_wm_state(self
);
2577 hooks_queue(OB_HOOK_WIN_INVISIBLE
, self
);
2582 void client_showhide(ObClient
*self
)
2584 if (!client_show(self
))
2588 gboolean
client_normal(ObClient
*self
) {
2589 return ! (self
->type
== OB_CLIENT_TYPE_DESKTOP
||
2590 self
->type
== OB_CLIENT_TYPE_DOCK
||
2591 self
->type
== OB_CLIENT_TYPE_SPLASH
);
2594 gboolean
client_helper(ObClient
*self
)
2596 return (self
->type
== OB_CLIENT_TYPE_UTILITY
||
2597 self
->type
== OB_CLIENT_TYPE_MENU
||
2598 self
->type
== OB_CLIENT_TYPE_TOOLBAR
);
2601 gboolean
client_mouse_focusable(ObClient
*self
)
2603 return !(self
->type
== OB_CLIENT_TYPE_MENU
||
2604 self
->type
== OB_CLIENT_TYPE_TOOLBAR
||
2605 self
->type
== OB_CLIENT_TYPE_SPLASH
||
2606 self
->type
== OB_CLIENT_TYPE_DOCK
);
2609 gboolean
client_enter_focusable(ObClient
*self
)
2611 /* you can focus desktops but it shouldn't on enter */
2612 return (client_mouse_focusable(self
) &&
2613 self
->type
!= OB_CLIENT_TYPE_DESKTOP
);
2617 static void client_apply_startup_state(ObClient
*self
,
2618 gint x
, gint y
, gint w
, gint h
)
2620 /* save the states that we are going to apply */
2621 gboolean iconic
= self
->iconic
;
2622 gboolean fullscreen
= self
->fullscreen
;
2623 gboolean undecorated
= self
->undecorated
;
2624 gboolean shaded
= self
->shaded
;
2625 gboolean demands_attention
= self
->demands_attention
;
2626 gboolean max_horz
= self
->max_horz
;
2627 gboolean max_vert
= self
->max_vert
;
2631 /* turn them all off in the client, so they won't affect the window
2633 self
->iconic
= self
->fullscreen
= self
->undecorated
= self
->shaded
=
2634 self
->demands_attention
= self
->max_horz
= self
->max_vert
= FALSE
;
2636 /* move the client to its placed position, or it it's already there,
2637 generate a ConfigureNotify telling the client where it is.
2639 do this after adjusting the frame. otherwise it gets all weird and
2640 clients don't work right
2642 do this before applying the states so they have the correct
2643 pre-max/pre-fullscreen values
2645 client_try_configure(self
, &x
, &y
, &w
, &h
, &l
, &l
, FALSE
);
2646 ob_debug("placed window 0x%x at %d, %d with size %d x %d",
2647 self
->window
, x
, y
, w
, h
);
2648 /* save the area, and make it where it should be for the premax stuff */
2649 oldarea
= self
->area
;
2650 RECT_SET(self
->area
, x
, y
, w
, h
);
2652 /* apply the states. these are in a carefully crafted order.. */
2655 client_iconify(self
, TRUE
, FALSE
, TRUE
);
2657 client_fullscreen(self
, TRUE
);
2659 client_set_undecorated(self
, TRUE
);
2661 client_shade(self
, TRUE
);
2662 if (demands_attention
)
2663 client_hilite(self
, TRUE
);
2665 if (max_vert
&& max_horz
)
2666 client_maximize(self
, TRUE
, 0);
2668 client_maximize(self
, TRUE
, 2);
2670 client_maximize(self
, TRUE
, 1);
2672 /* if the window hasn't been configured yet, then do so now, in fact the
2673 x,y,w,h may _not_ be the same as the area rect, which can end up
2674 meaning that the client isn't properly moved/resized by the fullscreen
2676 pho can cause this because it maps at size of the screen but not 0,0
2677 so openbox moves it on screen to 0,0 (thus x,y=0,0 and area.x,y don't).
2678 then fullscreen'ing makes it go to 0,0 which it thinks it already is at
2679 cuz thats where the pre-fullscreen will be. however the actual area is
2680 not, so this needs to be called even if we have fullscreened/maxed
2682 self
->area
= oldarea
;
2683 client_configure(self
, x
, y
, w
, h
, FALSE
, TRUE
, FALSE
);
2685 /* set the desktop hint, to make sure that it always exists */
2686 OBT_PROP_SET32(self
->window
, NET_WM_DESKTOP
, CARDINAL
, self
->desktop
);
2688 /* nothing to do for the other states:
2697 void client_gravity_resize_w(ObClient
*self
, gint
*x
, gint oldw
, gint neww
)
2699 /* these should be the current values. this is for when you're not moving,
2701 g_assert(*x
== self
->area
.x
);
2702 g_assert(oldw
== self
->area
.width
);
2705 switch (self
->gravity
) {
2707 case NorthWestGravity
:
2709 case SouthWestGravity
:
2716 *x
-= (neww
- oldw
) / 2;
2718 case NorthEastGravity
:
2720 case SouthEastGravity
:
2726 void client_gravity_resize_h(ObClient
*self
, gint
*y
, gint oldh
, gint newh
)
2728 /* these should be the current values. this is for when you're not moving,
2730 g_assert(*y
== self
->area
.y
);
2731 g_assert(oldh
== self
->area
.height
);
2734 switch (self
->gravity
) {
2736 case NorthWestGravity
:
2738 case NorthEastGravity
:
2745 *y
-= (newh
- oldh
) / 2;
2747 case SouthWestGravity
:
2749 case SouthEastGravity
:
2755 void client_try_configure(ObClient
*self
, gint
*x
, gint
*y
, gint
*w
, gint
*h
,
2756 gint
*logicalw
, gint
*logicalh
,
2759 Rect desired
= {*x
, *y
, *w
, *h
};
2760 frame_rect_to_frame(self
->frame
, &desired
);
2762 /* make the frame recalculate its dimensions n shit without changing
2763 anything visible for real, this way the constraints below can work with
2764 the updated frame dimensions. */
2765 frame_adjust_area(self
->frame
, FALSE
, TRUE
, TRUE
);
2767 /* gets the frame's position */
2768 frame_client_gravity(self
->frame
, x
, y
);
2770 /* these positions are frame positions, not client positions */
2772 /* set the size and position if fullscreen */
2773 if (self
->fullscreen
) {
2777 i
= screen_find_monitor(&desired
);
2778 a
= screen_physical_area_monitor(i
);
2785 user
= FALSE
; /* ignore if the client can't be moved/resized when it
2789 } else if (self
->max_horz
|| self
->max_vert
) {
2793 /* use all possible struts when maximizing to the full screen */
2794 i
= screen_find_monitor(&desired
);
2795 a
= screen_area(self
->desktop
, i
,
2796 (self
->max_horz
&& self
->max_vert
? NULL
: &desired
));
2798 /* set the size and position if maximized */
2799 if (self
->max_horz
) {
2801 *w
= a
->width
- self
->frame
->size
.left
- self
->frame
->size
.right
;
2803 if (self
->max_vert
) {
2805 *h
= a
->height
- self
->frame
->size
.top
- self
->frame
->size
.bottom
;
2808 user
= FALSE
; /* ignore if the client can't be moved/resized when it
2814 /* gets the client's position */
2815 frame_frame_gravity(self
->frame
, x
, y
);
2817 /* work within the preferred sizes given by the window, these may have
2818 changed rather than it's requested width and height, so always run
2819 through this code */
2821 gint basew
, baseh
, minw
, minh
;
2823 gfloat minratio
, maxratio
;
2825 incw
= self
->fullscreen
|| self
->max_horz
? 1 : self
->size_inc
.width
;
2826 inch
= self
->fullscreen
|| self
->max_vert
? 1 : self
->size_inc
.height
;
2827 minratio
= self
->fullscreen
|| (self
->max_horz
&& self
->max_vert
) ?
2828 0 : self
->min_ratio
;
2829 maxratio
= self
->fullscreen
|| (self
->max_horz
&& self
->max_vert
) ?
2830 0 : self
->max_ratio
;
2832 /* base size is substituted with min size if not specified */
2833 if (self
->base_size
.width
>= 0 || self
->base_size
.height
>= 0) {
2834 basew
= self
->base_size
.width
;
2835 baseh
= self
->base_size
.height
;
2837 basew
= self
->min_size
.width
;
2838 baseh
= self
->min_size
.height
;
2840 /* min size is substituted with base size if not specified */
2841 if (self
->min_size
.width
|| self
->min_size
.height
) {
2842 minw
= self
->min_size
.width
;
2843 minh
= self
->min_size
.height
;
2845 minw
= self
->base_size
.width
;
2846 minh
= self
->base_size
.height
;
2849 /* This comment is no longer true */
2850 /* if this is a user-requested resize, then check against min/max
2853 /* smaller than min size or bigger than max size? */
2854 if (*w
> self
->max_size
.width
) *w
= self
->max_size
.width
;
2855 if (*w
< minw
) *w
= minw
;
2856 if (*h
> self
->max_size
.height
) *h
= self
->max_size
.height
;
2857 if (*h
< minh
) *h
= minh
;
2862 /* keep to the increments */
2866 /* you cannot resize to nothing */
2867 if (basew
+ *w
< 1) *w
= 1 - basew
;
2868 if (baseh
+ *h
< 1) *h
= 1 - baseh
;
2870 /* save the logical size */
2871 *logicalw
= incw
> 1 ? *w
: *w
+ basew
;
2872 *logicalh
= inch
> 1 ? *h
: *h
+ baseh
;
2880 /* adjust the height to match the width for the aspect ratios.
2881 for this, min size is not substituted for base size ever. */
2882 *w
-= self
->base_size
.width
;
2883 *h
-= self
->base_size
.height
;
2886 if (*h
* minratio
> *w
) {
2887 *h
= (gint
)(*w
/ minratio
);
2889 /* you cannot resize to nothing */
2892 *w
= (gint
)(*h
* minratio
);
2896 if (*h
* maxratio
< *w
) {
2897 *h
= (gint
)(*w
/ maxratio
);
2899 /* you cannot resize to nothing */
2902 *w
= (gint
)(*h
* minratio
);
2906 *w
+= self
->base_size
.width
;
2907 *h
+= self
->base_size
.height
;
2910 /* these override the above states! if you cant move you can't move! */
2912 if (!(self
->functions
& OB_CLIENT_FUNC_MOVE
)) {
2916 if (!(self
->functions
& OB_CLIENT_FUNC_RESIZE
)) {
2917 *w
= self
->area
.width
;
2918 *h
= self
->area
.height
;
2927 void client_configure(ObClient
*self
, gint x
, gint y
, gint w
, gint h
,
2928 gboolean user
, gboolean final
, gboolean force_reply
)
2932 gboolean send_resize_client
;
2933 gboolean moved
= FALSE
, resized
= FALSE
, rootmoved
= FALSE
;
2934 gboolean fmoved
, fresized
;
2935 guint fdecor
= self
->frame
->decorations
;
2936 gboolean fhorz
= self
->frame
->max_horz
;
2937 gboolean fvert
= self
->frame
->max_vert
;
2938 gint logicalw
, logicalh
;
2940 /* find the new x, y, width, and height (and logical size) */
2941 client_try_configure(self
, &x
, &y
, &w
, &h
, &logicalw
, &logicalh
, user
);
2943 /* set the logical size if things changed */
2944 if (!(w
== self
->area
.width
&& h
== self
->area
.height
))
2945 SIZE_SET(self
->logical_size
, logicalw
, logicalh
);
2947 /* figure out if we moved or resized or what */
2948 moved
= (x
!= self
->area
.x
|| y
!= self
->area
.y
);
2949 resized
= (w
!= self
->area
.width
|| h
!= self
->area
.height
);
2951 oldw
= self
->area
.width
;
2952 oldh
= self
->area
.height
;
2953 oldframe
= self
->frame
->area
;
2954 RECT_SET(self
->area
, x
, y
, w
, h
);
2956 /* for app-requested resizes, always resize if 'resized' is true.
2957 for user-requested ones, only resize if final is true, or when
2958 resizing in redraw mode */
2959 send_resize_client
= ((!user
&& resized
) ||
2961 (resized
&& config_resize_redraw
))));
2963 /* if the client is enlarging, then resize the client before the frame */
2964 if (send_resize_client
&& (w
> oldw
|| h
> oldh
)) {
2965 XMoveResizeWindow(obt_display
, self
->window
,
2966 self
->frame
->size
.left
, self
->frame
->size
.top
,
2967 MAX(w
, oldw
), MAX(h
, oldh
));
2968 frame_adjust_client_area(self
->frame
);
2971 /* find the frame's dimensions and move/resize it */
2975 /* if decorations changed, then readjust everything for the frame */
2976 if (self
->decorations
!= fdecor
||
2977 self
->max_horz
!= fhorz
|| self
->max_vert
!= fvert
)
2979 fmoved
= fresized
= TRUE
;
2982 /* adjust the frame */
2983 if (fmoved
|| fresized
) {
2984 gulong ignore_start
;
2986 ignore_start
= event_start_ignore_all_enters();
2988 /* replay pending pointer event before move the window, in case it
2989 would change what window gets the event */
2990 mouse_replay_pointer();
2992 frame_adjust_area(self
->frame
, fmoved
, fresized
, FALSE
);
2995 event_end_ignore_all_enters(ignore_start
);
2998 if (!user
|| final
) {
2999 gint oldrx
= self
->root_pos
.x
;
3000 gint oldry
= self
->root_pos
.y
;
3001 /* we have reset the client to 0 border width, so don't include
3002 it in these coords */
3003 POINT_SET(self
->root_pos
,
3004 self
->frame
->area
.x
+ self
->frame
->size
.left
-
3006 self
->frame
->area
.y
+ self
->frame
->size
.top
-
3007 self
->border_width
);
3008 if (self
->root_pos
.x
!= oldrx
|| self
->root_pos
.y
!= oldry
)
3012 /* This is kinda tricky and should not be changed.. let me explain!
3014 When user = FALSE, then the request is coming from the application
3015 itself, and we are more strict about when to send a synthetic
3016 ConfigureNotify. We strictly follow the rules of the ICCCM sec 4.1.5
3017 in this case (if force_reply is true)
3019 When user = TRUE, then the request is coming from "us", like when we
3020 maximize a window or something. In this case we are more lenient. We
3021 used to follow the same rules as above, but _Java_ Swing can't handle
3022 this. So just to appease Swing, when user = TRUE, we always send
3023 a synthetic ConfigureNotify to give the window its root coordinates.
3025 if ((!user
&& !resized
&& (rootmoved
|| force_reply
)) ||
3026 (user
&& final
&& rootmoved
))
3030 event
.type
= ConfigureNotify
;
3031 event
.xconfigure
.display
= obt_display
;
3032 event
.xconfigure
.event
= self
->window
;
3033 event
.xconfigure
.window
= self
->window
;
3035 ob_debug("Sending ConfigureNotify to %s for %d,%d %dx%d",
3036 self
->title
, self
->root_pos
.x
, self
->root_pos
.y
, w
, h
);
3038 /* root window real coords */
3039 event
.xconfigure
.x
= self
->root_pos
.x
;
3040 event
.xconfigure
.y
= self
->root_pos
.y
;
3041 event
.xconfigure
.width
= w
;
3042 event
.xconfigure
.height
= h
;
3043 event
.xconfigure
.border_width
= self
->border_width
;
3044 event
.xconfigure
.above
= None
;
3045 event
.xconfigure
.override_redirect
= FALSE
;
3046 XSendEvent(event
.xconfigure
.display
, event
.xconfigure
.window
,
3047 FALSE
, StructureNotifyMask
, &event
);
3050 /* if the client is shrinking, then resize the frame before the client.
3052 both of these resize sections may run, because the top one only resizes
3053 in the direction that is growing
3055 if (send_resize_client
&& (w
<= oldw
|| h
<= oldh
)) {
3056 frame_adjust_client_area(self
->frame
);
3057 XMoveResizeWindow(obt_display
, self
->window
,
3058 self
->frame
->size
.left
, self
->frame
->size
.top
, w
, h
);
3061 XFlush(obt_display
);
3063 /* if it moved between monitors, then this can affect the stacking
3064 layer of this window or others - for fullscreen windows */
3065 if (screen_find_monitor(&self
->frame
->area
) !=
3066 screen_find_monitor(&oldframe
))
3068 client_calc_layer(self
);
3072 void client_fullscreen(ObClient
*self
, gboolean fs
)
3076 if (!(self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
) || /* can't */
3077 self
->fullscreen
== fs
) return; /* already done */
3079 self
->fullscreen
= fs
;
3080 client_change_state(self
); /* change the state hints on the client */
3083 self
->pre_fullscreen_area
= self
->area
;
3084 /* if the window is maximized, its area isn't all that meaningful.
3085 save its premax area instead. */
3086 if (self
->max_horz
) {
3087 self
->pre_fullscreen_area
.x
= self
->pre_max_area
.x
;
3088 self
->pre_fullscreen_area
.width
= self
->pre_max_area
.width
;
3090 if (self
->max_vert
) {
3091 self
->pre_fullscreen_area
.y
= self
->pre_max_area
.y
;
3092 self
->pre_fullscreen_area
.height
= self
->pre_max_area
.height
;
3095 /* these will help configure_full figure out where to fullscreen
3099 w
= self
->area
.width
;
3100 h
= self
->area
.height
;
3102 g_assert(self
->pre_fullscreen_area
.width
> 0 &&
3103 self
->pre_fullscreen_area
.height
> 0);
3105 x
= self
->pre_fullscreen_area
.x
;
3106 y
= self
->pre_fullscreen_area
.y
;
3107 w
= self
->pre_fullscreen_area
.width
;
3108 h
= self
->pre_fullscreen_area
.height
;
3109 RECT_SET(self
->pre_fullscreen_area
, 0, 0, 0, 0);
3112 ob_debug("Window %s going fullscreen (%d)",
3113 self
->title
, self
->fullscreen
);
3115 client_setup_decor_and_functions(self
, FALSE
);
3116 client_move_resize(self
, x
, y
, w
, h
);
3118 /* and adjust our layer/stacking. do this after resizing the window,
3119 and applying decorations, because windows which fill the screen are
3120 considered "fullscreen" and it affects their layer */
3121 client_calc_layer(self
);
3124 /* try focus us when we go into fullscreen mode */
3129 static void client_iconify_recursive(ObClient
*self
,
3130 gboolean iconic
, gboolean curdesk
,
3131 gboolean hide_animation
)
3134 gboolean changed
= FALSE
;
3136 if (self
->iconic
!= iconic
) {
3137 ob_debug("%sconifying window: 0x%lx", (iconic
? "I" : "Uni"),
3141 /* don't let non-normal windows iconify along with their parents
3143 if (client_normal(self
)) {
3144 self
->iconic
= iconic
;
3146 /* update the focus lists.. iconic windows go to the bottom of
3148 focus_order_to_bottom(self
);
3153 self
->iconic
= iconic
;
3155 if (curdesk
&& self
->desktop
!= screen_desktop
&&
3156 self
->desktop
!= DESKTOP_ALL
)
3157 client_set_desktop(self
, screen_desktop
, FALSE
, FALSE
);
3159 /* this puts it after the current focused window */
3160 focus_order_remove(self
);
3161 focus_order_add_new(self
);
3168 client_change_state(self
);
3169 if (config_animate_iconify
&& !hide_animation
)
3170 frame_begin_iconify_animation(self
->frame
, iconic
);
3171 /* do this after starting the animation so it doesn't flash */
3172 client_showhide(self
);
3174 hooks_queue((iconic
? OB_HOOK_WIN_ICONIC
: OB_HOOK_WIN_UNICONIC
),
3178 /* iconify all direct transients, and deiconify all transients
3180 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
3181 if (it
->data
!= self
)
3182 if (client_is_direct_child(self
, it
->data
) || !iconic
)
3183 client_iconify_recursive(it
->data
, iconic
, curdesk
,
3187 void client_iconify(ObClient
*self
, gboolean iconic
, gboolean curdesk
,
3188 gboolean hide_animation
)
3190 if (self
->functions
& OB_CLIENT_FUNC_ICONIFY
|| !iconic
) {
3191 /* move up the transient chain as far as possible first */
3192 self
= client_search_top_direct_parent(self
);
3193 client_iconify_recursive(self
, iconic
, curdesk
, hide_animation
);
3197 void client_maximize(ObClient
*self
, gboolean max
, gint dir
)
3201 g_assert(dir
== 0 || dir
== 1 || dir
== 2);
3202 if (!(self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) && max
) return;/* can't */
3204 /* check if already done */
3206 if (dir
== 0 && self
->max_horz
&& self
->max_vert
) return;
3207 if (dir
== 1 && self
->max_horz
) return;
3208 if (dir
== 2 && self
->max_vert
) return;
3210 if (dir
== 0 && !self
->max_horz
&& !self
->max_vert
) return;
3211 if (dir
== 1 && !self
->max_horz
) return;
3212 if (dir
== 2 && !self
->max_vert
) return;
3215 /* these will help configure_full figure out which screen to fill with
3219 w
= self
->area
.width
;
3220 h
= self
->area
.height
;
3223 if ((dir
== 0 || dir
== 1) && !self
->max_horz
) { /* horz */
3224 RECT_SET(self
->pre_max_area
,
3225 self
->area
.x
, self
->pre_max_area
.y
,
3226 self
->area
.width
, self
->pre_max_area
.height
);
3228 if ((dir
== 0 || dir
== 2) && !self
->max_vert
) { /* vert */
3229 RECT_SET(self
->pre_max_area
,
3230 self
->pre_max_area
.x
, self
->area
.y
,
3231 self
->pre_max_area
.width
, self
->area
.height
);
3234 if ((dir
== 0 || dir
== 1) && self
->max_horz
) { /* horz */
3235 g_assert(self
->pre_max_area
.width
> 0);
3237 x
= self
->pre_max_area
.x
;
3238 w
= self
->pre_max_area
.width
;
3240 RECT_SET(self
->pre_max_area
, 0, self
->pre_max_area
.y
,
3241 0, self
->pre_max_area
.height
);
3243 if ((dir
== 0 || dir
== 2) && self
->max_vert
) { /* vert */
3244 g_assert(self
->pre_max_area
.height
> 0);
3246 y
= self
->pre_max_area
.y
;
3247 h
= self
->pre_max_area
.height
;
3249 RECT_SET(self
->pre_max_area
, self
->pre_max_area
.x
, 0,
3250 self
->pre_max_area
.width
, 0);
3254 if (dir
== 0 || dir
== 1) /* horz */
3255 self
->max_horz
= max
;
3256 if (dir
== 0 || dir
== 2) /* vert */
3257 self
->max_vert
= max
;
3259 client_change_state(self
); /* change the state hints on the client */
3261 client_setup_decor_and_functions(self
, FALSE
);
3262 client_move_resize(self
, x
, y
, w
, h
);
3264 hooks_queue((max
? OB_HOOK_WIN_MAX
: OB_HOOK_WIN_UNMAX
), self
);
3267 void client_shade(ObClient
*self
, gboolean shade
)
3269 if ((!(self
->functions
& OB_CLIENT_FUNC_SHADE
) &&
3270 shade
) || /* can't shade */
3271 self
->shaded
== shade
) return; /* already done */
3273 self
->shaded
= shade
;
3274 client_change_state(self
);
3275 client_change_wm_state(self
); /* the window is being hidden/shown */
3276 /* resize the frame to just the titlebar */
3277 frame_adjust_area(self
->frame
, FALSE
, TRUE
, FALSE
);
3279 hooks_queue((shade
? OB_HOOK_WIN_SHADE
: OB_HOOK_WIN_UNSHADE
), self
);
3282 static void client_ping_event(ObClient
*self
, gboolean dead
)
3284 if (self
->not_responding
!= dead
) {
3285 self
->not_responding
= dead
;
3286 client_update_title(self
);
3289 /* the client isn't responding, so ask to kill it */
3290 client_prompt_kill(self
);
3292 /* it came back to life ! */
3294 if (self
->kill_prompt
) {
3295 prompt_unref(self
->kill_prompt
);
3296 self
->kill_prompt
= NULL
;
3299 self
->kill_level
= 0;
3304 void client_close(ObClient
*self
)
3306 if (!(self
->functions
& OB_CLIENT_FUNC_CLOSE
)) return;
3308 /* if closing an internal obprompt, that is just cancelling it */
3310 prompt_cancel(self
->prompt
);
3314 /* in the case that the client provides no means to requesting that it
3315 close, we just kill it */
3316 if (!self
->delete_window
)
3317 /* don't use client_kill(), we should only kill based on PID in
3318 response to a lack of PING replies */
3319 XKillClient(obt_display
, self
->window
);
3321 /* request the client to close with WM_DELETE_WINDOW */
3322 OBT_PROP_MSG_TO(self
->window
, self
->window
, WM_PROTOCOLS
,
3323 OBT_PROP_ATOM(WM_DELETE_WINDOW
), event_curtime
,
3324 0, 0, 0, NoEventMask
);
3326 /* we're trying to close the window, so see if it is responding. if it
3327 is not, then we will let them kill the window */
3329 ping_start(self
, client_ping_event
);
3331 /* if we already know the window isn't responding (maybe they clicked
3332 no in the kill dialog but it hasn't come back to life), then show
3334 if (self
->not_responding
)
3335 client_prompt_kill(self
);
3339 #define OB_KILL_RESULT_NO 0
3340 #define OB_KILL_RESULT_YES 1
3342 static gboolean
client_kill_requested(ObPrompt
*p
, gint result
, gpointer data
)
3344 ObClient
*self
= data
;
3346 if (result
== OB_KILL_RESULT_YES
)
3348 return TRUE
; /* call the cleanup func */
3351 static void client_kill_cleanup(ObPrompt
*p
, gpointer data
)
3353 ObClient
*self
= data
;
3355 g_assert(p
== self
->kill_prompt
);
3357 prompt_unref(self
->kill_prompt
);
3358 self
->kill_prompt
= NULL
;
3361 static void client_prompt_kill(ObClient
*self
)
3363 /* check if we're already prompting */
3364 if (!self
->kill_prompt
) {
3365 ObPromptAnswer answers
[] = {
3366 { 0, OB_KILL_RESULT_NO
},
3367 { 0, OB_KILL_RESULT_YES
}
3370 const gchar
*y
, *title
;
3372 title
= self
->original_title
;
3373 if (title
[0] == '\0') {
3374 /* empty string, so use its parent */
3375 ObClient
*p
= client_search_top_direct_parent(self
);
3376 if (p
) title
= p
->original_title
;
3379 if (client_on_localhost(self
)) {
3382 if (self
->kill_level
== 0)
3388 (_("The window \"%s\" does not seem to be responding. Do you want to force it to exit by sending the %s signal?"),
3390 y
= _("End Process");
3394 (_("The window \"%s\" does not seem to be responding. Do you want to disconnect it from the X server?"),
3396 y
= _("Disconnect");
3398 /* set the dialog buttons' text */
3399 answers
[0].text
= _("Cancel"); /* "no" */
3400 answers
[1].text
= y
; /* "yes" */
3402 self
->kill_prompt
= prompt_new(m
, NULL
, answers
,
3403 sizeof(answers
)/sizeof(answers
[0]),
3404 OB_KILL_RESULT_NO
, /* default = no */
3405 OB_KILL_RESULT_NO
, /* cancel = no */
3406 client_kill_requested
,
3407 client_kill_cleanup
,
3412 prompt_show(self
->kill_prompt
, self
, TRUE
);
3415 void client_kill(ObClient
*self
)
3417 /* don't kill our own windows */
3418 if (self
->prompt
) return;
3420 if (client_on_localhost(self
) && self
->pid
) {
3421 /* running on the local host */
3422 if (self
->kill_level
== 0) {
3423 ob_debug("killing window 0x%x with pid %lu, with SIGTERM",
3424 self
->window
, self
->pid
);
3425 kill(self
->pid
, SIGTERM
);
3428 /* show that we're trying to kill it */
3429 client_update_title(self
);
3432 ob_debug("killing window 0x%x with pid %lu, with SIGKILL",
3433 self
->window
, self
->pid
);
3434 kill(self
->pid
, SIGKILL
); /* kill -9 */
3438 /* running on a remote host */
3439 XKillClient(obt_display
, self
->window
);
3443 void client_hilite(ObClient
*self
, gboolean hilite
)
3445 if (self
->demands_attention
== hilite
)
3446 return; /* no change */
3448 /* don't allow focused windows to hilite */
3449 self
->demands_attention
= hilite
&& !client_focused(self
);
3450 if (self
->frame
!= NULL
) { /* if we're mapping, just set the state */
3451 if (self
->demands_attention
)
3452 frame_flash_start(self
->frame
);
3454 frame_flash_stop(self
->frame
);
3455 client_change_state(self
);
3459 static void client_set_desktop_recursive(ObClient
*self
,
3467 if (target
!= self
->desktop
&& self
->type
!= OB_CLIENT_TYPE_DESKTOP
) {
3469 ob_debug("Setting desktop %u", target
+1);
3471 g_assert(target
< screen_num_desktops
|| target
== DESKTOP_ALL
);
3473 old
= self
->desktop
;
3474 self
->desktop
= target
;
3475 OBT_PROP_SET32(self
->window
, NET_WM_DESKTOP
, CARDINAL
, target
);
3476 /* the frame can display the current desktop state */
3477 frame_adjust_state(self
->frame
);
3478 /* 'move' the window to the new desktop */
3482 /* raise if it was not already on the desktop */
3483 if (old
!= DESKTOP_ALL
&& !dontraise
)
3484 stacking_raise(CLIENT_AS_WINDOW(self
));
3485 if (STRUT_EXISTS(self
->strut
))
3486 screen_update_areas();
3488 /* the new desktop's geometry may be different, so we may need to
3489 resize, for example if we are maximized */
3490 client_reconfigure(self
, FALSE
);
3492 if (old
!= self
->desktop
)
3493 hooks_queue(OB_HOOK_WIN_DESK_CHANGE
, self
);
3496 /* move all transients */
3497 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
3498 if (it
->data
!= self
)
3499 if (client_is_direct_child(self
, it
->data
))
3500 client_set_desktop_recursive(it
->data
, target
,
3501 donthide
, dontraise
);
3504 void client_set_desktop(ObClient
*self
, guint target
,
3505 gboolean donthide
, gboolean dontraise
)
3507 self
= client_search_top_direct_parent(self
);
3508 client_set_desktop_recursive(self
, target
, donthide
, dontraise
);
3511 gboolean
client_is_direct_child(ObClient
*parent
, ObClient
*child
)
3513 while (child
!= parent
&& (child
= client_direct_parent(child
)));
3514 return child
== parent
;
3517 ObClient
*client_search_modal_child(ObClient
*self
)
3522 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
3523 ObClient
*c
= it
->data
;
3524 if ((ret
= client_search_modal_child(c
))) return ret
;
3525 if (c
->modal
) return c
;
3530 gboolean
client_validate(ObClient
*self
)
3534 XSync(obt_display
, FALSE
); /* get all events on the server */
3536 if (XCheckTypedWindowEvent(obt_display
, self
->window
, DestroyNotify
, &e
) ||
3537 XCheckTypedWindowEvent(obt_display
, self
->window
, UnmapNotify
, &e
))
3539 XPutBackEvent(obt_display
, &e
);
3546 void client_set_wm_state(ObClient
*self
, glong state
)
3548 if (state
== self
->wmstate
) return; /* no change */
3552 client_iconify(self
, TRUE
, TRUE
, FALSE
);
3555 client_iconify(self
, FALSE
, TRUE
, FALSE
);
3560 void client_set_state(ObClient
*self
, Atom action
, glong data1
, glong data2
)
3562 gboolean shaded
= self
->shaded
;
3563 gboolean fullscreen
= self
->fullscreen
;
3564 gboolean undecorated
= self
->undecorated
;
3565 gboolean max_horz
= self
->max_horz
;
3566 gboolean max_vert
= self
->max_vert
;
3567 gboolean modal
= self
->modal
;
3568 gboolean iconic
= self
->iconic
;
3569 gboolean demands_attention
= self
->demands_attention
;
3570 gboolean above
= self
->above
;
3571 gboolean below
= self
->below
;
3575 if (!(action
== OBT_PROP_ATOM(NET_WM_STATE_ADD
) ||
3576 action
== OBT_PROP_ATOM(NET_WM_STATE_REMOVE
) ||
3577 action
== OBT_PROP_ATOM(NET_WM_STATE_TOGGLE
)))
3578 /* an invalid action was passed to the client message, ignore it */
3581 for (i
= 0; i
< 2; ++i
) {
3582 Atom state
= i
== 0 ? data1
: data2
;
3584 if (!state
) continue;
3586 /* if toggling, then pick whether we're adding or removing */
3587 if (action
== OBT_PROP_ATOM(NET_WM_STATE_TOGGLE
)) {
3588 if (state
== OBT_PROP_ATOM(NET_WM_STATE_MODAL
))
3590 else if (state
== OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_VERT
))
3591 value
= self
->max_vert
;
3592 else if (state
== OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_HORZ
))
3593 value
= self
->max_horz
;
3594 else if (state
== OBT_PROP_ATOM(NET_WM_STATE_SHADED
))
3596 else if (state
== OBT_PROP_ATOM(NET_WM_STATE_SKIP_TASKBAR
))
3597 value
= self
->skip_taskbar
;
3598 else if (state
== OBT_PROP_ATOM(NET_WM_STATE_SKIP_PAGER
))
3599 value
= self
->skip_pager
;
3600 else if (state
== OBT_PROP_ATOM(NET_WM_STATE_HIDDEN
))
3601 value
= self
->iconic
;
3602 else if (state
== OBT_PROP_ATOM(NET_WM_STATE_FULLSCREEN
))
3604 else if (state
== OBT_PROP_ATOM(NET_WM_STATE_ABOVE
))
3605 value
= self
->above
;
3606 else if (state
== OBT_PROP_ATOM(NET_WM_STATE_BELOW
))
3607 value
= self
->below
;
3608 else if (state
== OBT_PROP_ATOM(NET_WM_STATE_DEMANDS_ATTENTION
))
3609 value
= self
->demands_attention
;
3610 else if (state
== OBT_PROP_ATOM(OB_WM_STATE_UNDECORATED
))
3611 value
= undecorated
;
3612 action
= value
? OBT_PROP_ATOM(NET_WM_STATE_REMOVE
) :
3613 OBT_PROP_ATOM(NET_WM_STATE_ADD
);
3616 value
= action
== OBT_PROP_ATOM(NET_WM_STATE_ADD
);
3617 if (state
== OBT_PROP_ATOM(NET_WM_STATE_MODAL
)) {
3619 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_VERT
)) {
3621 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_HORZ
)) {
3623 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_SHADED
)) {
3625 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_SKIP_TASKBAR
)) {
3626 self
->skip_taskbar
= value
;
3627 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_SKIP_PAGER
)) {
3628 self
->skip_pager
= value
;
3629 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_HIDDEN
)) {
3631 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_FULLSCREEN
)) {
3633 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_ABOVE
)) {
3635 /* only unset below when setting above, otherwise you can't get to
3639 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_BELOW
)) {
3640 /* and vice versa */
3644 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_DEMANDS_ATTENTION
)){
3645 demands_attention
= value
;
3646 } else if (state
== OBT_PROP_ATOM(OB_WM_STATE_UNDECORATED
)) {
3647 undecorated
= value
;
3651 if (max_horz
!= self
->max_horz
|| max_vert
!= self
->max_vert
) {
3652 if (max_horz
!= self
->max_horz
&& max_vert
!= self
->max_vert
) {
3654 if (max_horz
== max_vert
) { /* both going the same way */
3655 client_maximize(self
, max_horz
, 0);
3657 client_maximize(self
, max_horz
, 1);
3658 client_maximize(self
, max_vert
, 2);
3662 if (max_horz
!= self
->max_horz
)
3663 client_maximize(self
, max_horz
, 1);
3665 client_maximize(self
, max_vert
, 2);
3668 /* change fullscreen state before shading, as it will affect if the window
3670 if (fullscreen
!= self
->fullscreen
)
3671 client_fullscreen(self
, fullscreen
);
3672 if (shaded
!= self
->shaded
)
3673 client_shade(self
, shaded
);
3674 if (undecorated
!= self
->undecorated
)
3675 client_set_undecorated(self
, undecorated
);
3676 if (above
!= self
->above
|| below
!= self
->below
) {
3677 self
->above
= above
;
3678 self
->below
= below
;
3679 client_calc_layer(self
);
3682 if (modal
!= self
->modal
) {
3683 self
->modal
= modal
;
3684 /* when a window changes modality, then its stacking order with its
3685 transients needs to change */
3686 stacking_raise(CLIENT_AS_WINDOW(self
));
3688 /* it also may get focused. if something is focused that shouldn't
3689 be focused anymore, then move the focus */
3690 if (focus_client
&& client_focus_target(focus_client
) != focus_client
)
3691 client_focus(focus_client
);
3694 if (iconic
!= self
->iconic
)
3695 client_iconify(self
, iconic
, FALSE
, FALSE
);
3697 if (demands_attention
!= self
->demands_attention
)
3698 client_hilite(self
, demands_attention
);
3700 client_change_state(self
); /* change the hint to reflect these changes */
3703 ObClient
*client_focus_target(ObClient
*self
)
3705 ObClient
*child
= NULL
;
3707 child
= client_search_modal_child(self
);
3708 if (child
) return child
;
3712 gboolean
client_can_focus(ObClient
*self
)
3714 /* choose the correct target */
3715 self
= client_focus_target(self
);
3717 if (!self
->frame
->visible
)
3720 if (!(self
->can_focus
|| self
->focus_notify
))
3726 gboolean
client_focus(ObClient
*self
)
3728 /* we might not focus this window, so if we have modal children which would
3729 be focused instead, bring them to this desktop */
3730 client_bring_modal_windows(self
);
3732 /* choose the correct target */
3733 self
= client_focus_target(self
);
3735 if (!client_can_focus(self
)) {
3736 ob_debug_type(OB_DEBUG_FOCUS
,
3737 "Client %s can't be focused", self
->title
);
3741 ob_debug_type(OB_DEBUG_FOCUS
,
3742 "Focusing client \"%s\" (0x%x) at time %u",
3743 self
->title
, self
->window
, event_curtime
);
3745 /* if using focus_delay, stop the timer now so that focus doesn't
3747 event_halt_focus_delay();
3749 event_cancel_all_key_grabs();
3751 obt_display_ignore_errors(TRUE
);
3753 if (self
->can_focus
) {
3754 /* This can cause a BadMatch error with CurrentTime, or if an app
3755 passed in a bad time for _NET_WM_ACTIVE_WINDOW. */
3756 XSetInputFocus(obt_display
, self
->window
, RevertToPointerRoot
,
3760 if (self
->focus_notify
) {
3762 ce
.xclient
.type
= ClientMessage
;
3763 ce
.xclient
.message_type
= OBT_PROP_ATOM(WM_PROTOCOLS
);
3764 ce
.xclient
.display
= obt_display
;
3765 ce
.xclient
.window
= self
->window
;
3766 ce
.xclient
.format
= 32;
3767 ce
.xclient
.data
.l
[0] = OBT_PROP_ATOM(WM_TAKE_FOCUS
);
3768 ce
.xclient
.data
.l
[1] = event_curtime
;
3769 ce
.xclient
.data
.l
[2] = 0l;
3770 ce
.xclient
.data
.l
[3] = 0l;
3771 ce
.xclient
.data
.l
[4] = 0l;
3772 XSendEvent(obt_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
3775 obt_display_ignore_errors(FALSE
);
3777 ob_debug_type(OB_DEBUG_FOCUS
, "Error focusing? %d",
3778 obt_display_error_occured
);
3779 return !obt_display_error_occured
;
3782 static void client_present(ObClient
*self
, gboolean here
, gboolean raise
,
3785 if (client_normal(self
) && screen_showing_desktop
)
3786 screen_show_desktop(FALSE
, self
);
3788 client_iconify(self
, FALSE
, here
, FALSE
);
3789 if (self
->desktop
!= DESKTOP_ALL
&&
3790 self
->desktop
!= screen_desktop
)
3793 client_set_desktop(self
, screen_desktop
, FALSE
, TRUE
);
3795 screen_set_desktop(self
->desktop
, FALSE
);
3796 } else if (!self
->frame
->visible
)
3797 /* if its not visible for other reasons, then don't mess
3800 if (self
->shaded
&& unshade
)
3801 client_shade(self
, FALSE
);
3803 stacking_raise(CLIENT_AS_WINDOW(self
));
3808 /* this function exists to map to the client_activate message in the ewmh,
3809 the user arg is unused because nobody uses it correctly anyway. */
3810 void client_activate(ObClient
*self
, gboolean here
, gboolean raise
,
3811 gboolean unshade
, gboolean user
)
3813 client_present(self
, here
, raise
, unshade
);
3816 static void client_bring_windows_recursive(ObClient
*self
,
3824 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
3825 client_bring_windows_recursive(it
->data
, desktop
,
3826 helpers
, modals
, iconic
);
3828 if (((helpers
&& client_helper(self
)) ||
3829 (modals
&& self
->modal
)) &&
3830 ((self
->desktop
!= desktop
&& self
->desktop
!= DESKTOP_ALL
) ||
3831 (iconic
&& self
->iconic
)))
3833 if (iconic
&& self
->iconic
)
3834 client_iconify(self
, FALSE
, TRUE
, FALSE
);
3836 client_set_desktop(self
, desktop
, FALSE
, FALSE
);
3840 void client_bring_helper_windows(ObClient
*self
)
3842 client_bring_windows_recursive(self
, self
->desktop
, TRUE
, FALSE
, FALSE
);
3845 void client_bring_modal_windows(ObClient
*self
)
3847 client_bring_windows_recursive(self
, self
->desktop
, FALSE
, TRUE
, TRUE
);
3850 gboolean
client_focused(ObClient
*self
)
3852 return self
== focus_client
;
3855 RrImage
* client_icon(ObClient
*self
)
3857 RrImage
*ret
= NULL
;
3860 ret
= self
->icon_set
;
3861 else if (self
->parents
) {
3863 for (it
= self
->parents
; it
&& !ret
; it
= g_slist_next(it
))
3864 ret
= client_icon(it
->data
);
3867 ret
= client_default_icon
;
3871 void client_set_layer(ObClient
*self
, gint layer
)
3875 self
->above
= FALSE
;
3876 } else if (layer
== 0) {
3877 self
->below
= self
->above
= FALSE
;
3879 self
->below
= FALSE
;
3882 client_calc_layer(self
);
3883 client_change_state(self
); /* reflect this in the state hints */
3886 void client_set_undecorated(ObClient
*self
, gboolean undecorated
)
3888 if (self
->undecorated
!= undecorated
&&
3889 /* don't let it undecorate if the function is missing, but let
3891 (self
->functions
& OB_CLIENT_FUNC_UNDECORATE
|| !undecorated
))
3893 self
->undecorated
= undecorated
;
3894 client_setup_decor_and_functions(self
, TRUE
);
3895 client_change_state(self
); /* reflect this in the state hints */
3897 hooks_queue((undecorated
?
3898 OB_HOOK_WIN_UNDECORATED
: OB_HOOK_WIN_DECORATED
), self
);
3902 guint
client_monitor(ObClient
*self
)
3904 return screen_find_monitor(&self
->frame
->area
);
3907 ObClient
*client_direct_parent(ObClient
*self
)
3909 if (!self
->parents
) return NULL
;
3910 if (self
->transient_for_group
) return NULL
;
3911 return self
->parents
->data
;
3914 ObClient
*client_search_top_direct_parent(ObClient
*self
)
3917 while ((p
= client_direct_parent(self
))) self
= p
;
3921 static GSList
*client_search_all_top_parents_internal(ObClient
*self
,
3923 ObStackingLayer layer
)
3928 /* move up the direct transient chain as far as possible */
3929 while ((p
= client_direct_parent(self
)) &&
3930 (!bylayer
|| p
->layer
== layer
))
3934 ret
= g_slist_prepend(NULL
, self
);
3936 ret
= g_slist_copy(self
->parents
);
3941 GSList
*client_search_all_top_parents(ObClient
*self
)
3943 return client_search_all_top_parents_internal(self
, FALSE
, 0);
3946 GSList
*client_search_all_top_parents_layer(ObClient
*self
)
3948 return client_search_all_top_parents_internal(self
, TRUE
, self
->layer
);
3951 ObClient
*client_search_focus_parent(ObClient
*self
)
3955 for (it
= self
->parents
; it
; it
= g_slist_next(it
))
3956 if (client_focused(it
->data
)) return it
->data
;
3961 ObClient
*client_search_parent(ObClient
*self
, ObClient
*search
)
3965 for (it
= self
->parents
; it
; it
= g_slist_next(it
))
3966 if (it
->data
== search
) return search
;
3971 ObClient
*client_search_transient(ObClient
*self
, ObClient
*search
)
3975 for (sit
= self
->transients
; sit
; sit
= g_slist_next(sit
)) {
3976 if (sit
->data
== search
)
3978 if (client_search_transient(sit
->data
, search
))
3984 static void detect_edge(Rect area
, ObDirection dir
,
3985 gint my_head
, gint my_size
,
3986 gint my_edge_start
, gint my_edge_size
,
3987 gint
*dest
, gboolean
*near_edge
)
3989 gint edge_start
, edge_size
, head
, tail
;
3990 gboolean skip_head
= FALSE
, skip_tail
= FALSE
;
3993 case OB_DIRECTION_NORTH
:
3994 case OB_DIRECTION_SOUTH
:
3995 edge_start
= area
.x
;
3996 edge_size
= area
.width
;
3998 case OB_DIRECTION_EAST
:
3999 case OB_DIRECTION_WEST
:
4000 edge_start
= area
.y
;
4001 edge_size
= area
.height
;
4004 g_assert_not_reached();
4007 /* do we collide with this window? */
4008 if (!RANGES_INTERSECT(my_edge_start
, my_edge_size
,
4009 edge_start
, edge_size
))
4013 case OB_DIRECTION_NORTH
:
4014 head
= RECT_BOTTOM(area
);
4015 tail
= RECT_TOP(area
);
4017 case OB_DIRECTION_SOUTH
:
4018 head
= RECT_TOP(area
);
4019 tail
= RECT_BOTTOM(area
);
4021 case OB_DIRECTION_WEST
:
4022 head
= RECT_RIGHT(area
);
4023 tail
= RECT_LEFT(area
);
4025 case OB_DIRECTION_EAST
:
4026 head
= RECT_LEFT(area
);
4027 tail
= RECT_RIGHT(area
);
4030 g_assert_not_reached();
4033 case OB_DIRECTION_NORTH
:
4034 case OB_DIRECTION_WEST
:
4035 /* check if our window is past the head of this window */
4036 if (my_head
<= head
+ 1)
4038 /* check if our window's tail is past the tail of this window */
4039 if (my_head
+ my_size
- 1 <= tail
)
4041 /* check if the head of this window is closer than the previously
4042 chosen edge (take into account that the previously chosen
4043 edge might have been a tail, not a head) */
4044 if (head
+ (*near_edge
? 0 : my_size
) <= *dest
)
4046 /* check if the tail of this window is closer than the previously
4047 chosen edge (take into account that the previously chosen
4048 edge might have been a head, not a tail) */
4049 if (tail
- (!*near_edge
? 0 : my_size
) <= *dest
)
4052 case OB_DIRECTION_SOUTH
:
4053 case OB_DIRECTION_EAST
:
4054 /* check if our window is past the head of this window */
4055 if (my_head
>= head
- 1)
4057 /* check if our window's tail is past the tail of this window */
4058 if (my_head
- my_size
+ 1 >= tail
)
4060 /* check if the head of this window is closer than the previously
4061 chosen edge (take into account that the previously chosen
4062 edge might have been a tail, not a head) */
4063 if (head
- (*near_edge
? 0 : my_size
) >= *dest
)
4065 /* check if the tail of this window is closer than the previously
4066 chosen edge (take into account that the previously chosen
4067 edge might have been a head, not a tail) */
4068 if (tail
+ (!*near_edge
? 0 : my_size
) >= *dest
)
4072 g_assert_not_reached();
4075 ob_debug("my head %d size %d", my_head
, my_size
);
4076 ob_debug("head %d tail %d dest %d", head
, tail
, *dest
);
4078 ob_debug("using near edge %d", head
);
4082 else if (!skip_tail
) {
4083 ob_debug("using far edge %d", tail
);
4089 void client_find_edge_directional(ObClient
*self
, ObDirection dir
,
4090 gint my_head
, gint my_size
,
4091 gint my_edge_start
, gint my_edge_size
,
4092 gint
*dest
, gboolean
*near_edge
)
4099 a
= screen_area(self
->desktop
, SCREEN_AREA_ALL_MONITORS
,
4100 &self
->frame
->area
);
4101 mon
= screen_area(self
->desktop
, SCREEN_AREA_ONE_MONITOR
,
4102 &self
->frame
->area
);
4105 case OB_DIRECTION_NORTH
:
4106 if (my_head
>= RECT_TOP(*mon
) + 1)
4107 edge
= RECT_TOP(*mon
) - 1;
4109 edge
= RECT_TOP(*a
) - 1;
4111 case OB_DIRECTION_SOUTH
:
4112 if (my_head
<= RECT_BOTTOM(*mon
) - 1)
4113 edge
= RECT_BOTTOM(*mon
) + 1;
4115 edge
= RECT_BOTTOM(*a
) + 1;
4117 case OB_DIRECTION_EAST
:
4118 if (my_head
<= RECT_RIGHT(*mon
) - 1)
4119 edge
= RECT_RIGHT(*mon
) + 1;
4121 edge
= RECT_RIGHT(*a
) + 1;
4123 case OB_DIRECTION_WEST
:
4124 if (my_head
>= RECT_LEFT(*mon
) + 1)
4125 edge
= RECT_LEFT(*mon
) - 1;
4127 edge
= RECT_LEFT(*a
) - 1;
4130 g_assert_not_reached();
4132 /* default to the far edge, then narrow it down */
4136 for (it
= client_list
; it
; it
= g_list_next(it
)) {
4137 ObClient
*cur
= it
->data
;
4139 /* skip windows to not bump into */
4144 if (self
->desktop
!= cur
->desktop
&& cur
->desktop
!= DESKTOP_ALL
&&
4145 cur
->desktop
!= screen_desktop
)
4148 ob_debug("trying window %s", cur
->title
);
4150 detect_edge(cur
->frame
->area
, dir
, my_head
, my_size
, my_edge_start
,
4151 my_edge_size
, dest
, near_edge
);
4153 dock_get_area(&dock_area
);
4154 detect_edge(dock_area
, dir
, my_head
, my_size
, my_edge_start
,
4155 my_edge_size
, dest
, near_edge
);
4160 void client_find_move_directional(ObClient
*self
, ObDirection dir
,
4164 gint e
, e_start
, e_size
;
4168 case OB_DIRECTION_EAST
:
4169 head
= RECT_RIGHT(self
->frame
->area
);
4170 size
= self
->frame
->area
.width
;
4171 e_start
= RECT_TOP(self
->frame
->area
);
4172 e_size
= self
->frame
->area
.height
;
4174 case OB_DIRECTION_WEST
:
4175 head
= RECT_LEFT(self
->frame
->area
);
4176 size
= self
->frame
->area
.width
;
4177 e_start
= RECT_TOP(self
->frame
->area
);
4178 e_size
= self
->frame
->area
.height
;
4180 case OB_DIRECTION_NORTH
:
4181 head
= RECT_TOP(self
->frame
->area
);
4182 size
= self
->frame
->area
.height
;
4183 e_start
= RECT_LEFT(self
->frame
->area
);
4184 e_size
= self
->frame
->area
.width
;
4186 case OB_DIRECTION_SOUTH
:
4187 head
= RECT_BOTTOM(self
->frame
->area
);
4188 size
= self
->frame
->area
.height
;
4189 e_start
= RECT_LEFT(self
->frame
->area
);
4190 e_size
= self
->frame
->area
.width
;
4193 g_assert_not_reached();
4196 client_find_edge_directional(self
, dir
, head
, size
,
4197 e_start
, e_size
, &e
, &near
);
4198 *x
= self
->frame
->area
.x
;
4199 *y
= self
->frame
->area
.y
;
4201 case OB_DIRECTION_EAST
:
4202 if (near
) e
-= self
->frame
->area
.width
;
4206 case OB_DIRECTION_WEST
:
4208 else e
-= self
->frame
->area
.width
;
4211 case OB_DIRECTION_NORTH
:
4213 else e
-= self
->frame
->area
.height
;
4216 case OB_DIRECTION_SOUTH
:
4217 if (near
) e
-= self
->frame
->area
.height
;
4222 g_assert_not_reached();
4224 frame_frame_gravity(self
->frame
, x
, y
);
4227 void client_find_resize_directional(ObClient
*self
, ObDirection side
,
4229 gint
*x
, gint
*y
, gint
*w
, gint
*h
)
4232 gint e
, e_start
, e_size
, delta
;
4237 case OB_DIRECTION_EAST
:
4238 head
= RECT_RIGHT(self
->frame
->area
) +
4239 (self
->size_inc
.width
- 1) * (grow
? 1 : 0);
4240 e_start
= RECT_TOP(self
->frame
->area
);
4241 e_size
= self
->frame
->area
.height
;
4242 dir
= grow
? OB_DIRECTION_EAST
: OB_DIRECTION_WEST
;
4244 case OB_DIRECTION_WEST
:
4245 head
= RECT_LEFT(self
->frame
->area
) -
4246 (self
->size_inc
.width
- 1) * (grow
? 1 : 0);
4247 e_start
= RECT_TOP(self
->frame
->area
);
4248 e_size
= self
->frame
->area
.height
;
4249 dir
= grow
? OB_DIRECTION_WEST
: OB_DIRECTION_EAST
;
4251 case OB_DIRECTION_NORTH
:
4252 head
= RECT_TOP(self
->frame
->area
) -
4253 (self
->size_inc
.height
- 1) * (grow
? 1 : 0);
4254 e_start
= RECT_LEFT(self
->frame
->area
);
4255 e_size
= self
->frame
->area
.width
;
4256 dir
= grow
? OB_DIRECTION_NORTH
: OB_DIRECTION_SOUTH
;
4258 case OB_DIRECTION_SOUTH
:
4259 head
= RECT_BOTTOM(self
->frame
->area
) +
4260 (self
->size_inc
.height
- 1) * (grow
? 1 : 0);
4261 e_start
= RECT_LEFT(self
->frame
->area
);
4262 e_size
= self
->frame
->area
.width
;
4263 dir
= grow
? OB_DIRECTION_SOUTH
: OB_DIRECTION_NORTH
;
4266 g_assert_not_reached();
4269 ob_debug("head %d dir %d", head
, dir
);
4270 client_find_edge_directional(self
, dir
, head
, 1,
4271 e_start
, e_size
, &e
, &near
);
4272 ob_debug("edge %d", e
);
4273 *x
= self
->frame
->area
.x
;
4274 *y
= self
->frame
->area
.y
;
4275 *w
= self
->frame
->area
.width
;
4276 *h
= self
->frame
->area
.height
;
4278 case OB_DIRECTION_EAST
:
4279 if (grow
== near
) --e
;
4280 delta
= e
- RECT_RIGHT(self
->frame
->area
);
4283 case OB_DIRECTION_WEST
:
4284 if (grow
== near
) ++e
;
4285 delta
= RECT_LEFT(self
->frame
->area
) - e
;
4289 case OB_DIRECTION_NORTH
:
4290 if (grow
== near
) ++e
;
4291 delta
= RECT_TOP(self
->frame
->area
) - e
;
4295 case OB_DIRECTION_SOUTH
:
4296 if (grow
== near
) --e
;
4297 delta
= e
- RECT_BOTTOM(self
->frame
->area
);
4301 g_assert_not_reached();
4303 frame_frame_gravity(self
->frame
, x
, y
);
4304 *w
-= self
->frame
->size
.left
+ self
->frame
->size
.right
;
4305 *h
-= self
->frame
->size
.top
+ self
->frame
->size
.bottom
;
4308 ObClient
* client_under_pointer(void)
4312 ObClient
*ret
= NULL
;
4314 if (screen_pointer_pos(&x
, &y
)) {
4315 for (it
= stacking_list
; it
; it
= g_list_next(it
)) {
4316 if (WINDOW_IS_CLIENT(it
->data
)) {
4317 ObClient
*c
= WINDOW_AS_CLIENT(it
->data
);
4318 if (c
->frame
->visible
&&
4319 /* check the desktop, this is done during desktop
4320 switching and windows are shown/hidden status is not
4322 (c
->desktop
== screen_desktop
||
4323 c
->desktop
== DESKTOP_ALL
) &&
4324 /* ignore all animating windows */
4325 !frame_iconify_animating(c
->frame
) &&
4326 RECT_CONTAINS(c
->frame
->area
, x
, y
))
4337 gboolean
client_has_group_siblings(ObClient
*self
)
4339 return self
->group
&& self
->group
->members
->next
;
4342 /*! Returns TRUE if the client is running on the same machine as Openbox */
4343 gboolean
client_on_localhost(ObClient
*self
)
4345 return self
->client_machine
== NULL
;