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"
34 #include "focus_cycle.h"
39 #include "menuframe.h"
42 #include "obrender/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_save_app_rule_values(ObClient
*self
);
80 static void client_get_area(ObClient
*self
);
81 static void client_get_desktop(ObClient
*self
);
82 static void client_get_state(ObClient
*self
);
83 static void client_get_shaped(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
);
110 static gboolean
client_can_steal_focus(ObClient
*self
, Time steal_time
,
113 void client_startup(gboolean reconfig
)
115 if ((client_default_icon
= RrImageCacheFind(ob_rr_icons
,
116 ob_rr_theme
->def_win_icon
,
117 ob_rr_theme
->def_win_icon_w
,
118 ob_rr_theme
->def_win_icon_h
)))
119 RrImageRef(client_default_icon
);
121 client_default_icon
= RrImageNew(ob_rr_icons
);
122 RrImageAddPicture(client_default_icon
,
123 ob_rr_theme
->def_win_icon
,
124 ob_rr_theme
->def_win_icon_w
,
125 ob_rr_theme
->def_win_icon_h
);
128 if (reconfig
) return;
133 void client_shutdown(gboolean reconfig
)
135 RrImageUnref(client_default_icon
);
136 client_default_icon
= NULL
;
138 if (reconfig
) return;
141 static void client_call_notifies(ObClient
*self
, GSList
*list
)
145 for (it
= list
; it
; it
= g_slist_next(it
)) {
146 ClientCallback
*d
= it
->data
;
147 d
->func(self
, d
->data
);
151 void client_add_destroy_notify(ObClientCallback func
, gpointer data
)
153 ClientCallback
*d
= g_new(ClientCallback
, 1);
156 client_destroy_notifies
= g_slist_prepend(client_destroy_notifies
, d
);
159 void client_remove_destroy_notify(ObClientCallback func
)
163 for (it
= client_destroy_notifies
; it
; it
= g_slist_next(it
)) {
164 ClientCallback
*d
= it
->data
;
165 if (d
->func
== func
) {
167 client_destroy_notifies
=
168 g_slist_delete_link(client_destroy_notifies
, it
);
174 void client_set_list(void)
176 Window
*windows
, *win_it
;
178 guint size
= g_list_length(client_list
);
180 /* create an array of the window ids */
182 windows
= g_new(Window
, size
);
184 for (it
= client_list
; it
; it
= g_list_next(it
), ++win_it
)
185 *win_it
= ((ObClient
*)it
->data
)->window
;
189 OBT_PROP_SETA32(obt_root(ob_screen
), NET_CLIENT_LIST
, WINDOW
,
190 (gulong
*)windows
, size
);
198 void client_manage(Window window
, ObPrompt
*prompt
)
201 XSetWindowAttributes attrib_set
;
202 gboolean activate
= FALSE
;
203 ObAppSettings
*settings
;
204 gboolean transient
= FALSE
;
205 Rect place
, *monitor
;
206 Time launch_time
, map_time
;
209 ob_debug("Managing window: 0x%lx", window
);
211 map_time
= event_get_server_time();
213 /* choose the events we want to receive on the CLIENT window
214 (ObPrompt windows can request events too) */
215 attrib_set
.event_mask
= CLIENT_EVENTMASK
|
216 (prompt
? prompt
->event_mask
: 0);
217 attrib_set
.do_not_propagate_mask
= CLIENT_NOPROPAGATEMASK
;
218 XChangeWindowAttributes(obt_display
, window
,
219 CWEventMask
|CWDontPropagate
, &attrib_set
);
221 /* create the ObClient struct, and populate it from the hints on the
223 self
= g_new0(ObClient
, 1);
224 self
->obwin
.type
= OB_WINDOW_CLASS_CLIENT
;
225 self
->window
= window
;
226 self
->prompt
= prompt
;
227 self
->managed
= TRUE
;
229 /* non-zero defaults */
230 self
->wmstate
= WithdrawnState
; /* make sure it gets updated first time */
231 self
->gravity
= NorthWestGravity
;
232 self
->desktop
= screen_num_desktops
; /* always an invalid value */
234 /* get all the stuff off the window */
235 client_get_all(self
, TRUE
);
237 ob_debug("Window type: %d", self
->type
);
238 ob_debug("Window group: 0x%x", self
->group
?self
->group
->leader
:0);
239 ob_debug("Window name: %s class: %s role: %s title: %s",
240 self
->name
, self
->class, self
->role
, self
->title
);
242 /* per-app settings override stuff from client_get_all, and return the
243 settings for other uses too. the returned settings is a shallow copy,
244 that needs to be freed with g_free(). */
245 settings
= client_get_settings_state(self
);
247 /* now we have all of the window's information so we can set this up.
248 do this before creating the frame, so it can tell that we are still
249 mapping and doesn't go applying things right away */
250 client_setup_decor_and_functions(self
, FALSE
);
252 /* specify that if we exit, the window should not be destroyed and
253 should be reparented back to root automatically, unless we are managing
254 an internal ObPrompt window */
256 XChangeSaveSet(obt_display
, window
, SetModeInsert
);
258 /* create the decoration frame for the client window */
259 self
->frame
= frame_new(self
);
261 frame_grab_client(self
->frame
);
263 /* we've grabbed everything and set everything that we need to at mapping
267 /* the session should get the last say though */
268 client_restore_session_state(self
);
270 /* tell startup notification that this app started */
271 launch_time
= sn_app_started(self
->startup_id
, self
->class, self
->name
);
273 if (!OBT_PROP_GET32(self
->window
, NET_WM_USER_TIME
, CARDINAL
, &user_time
))
274 user_time
= map_time
;
276 /* do this after we have a frame.. it uses the frame to help determine the
277 WM_STATE to apply. */
278 client_change_state(self
);
280 /* add ourselves to the focus order */
281 focus_order_add_new(self
);
283 /* do this to add ourselves to the stacking list in a non-intrusive way */
284 client_calc_layer(self
);
286 /* focus the new window? */
287 if (ob_state() != OB_STATE_STARTING
&&
288 (!self
->session
|| self
->session
->focused
) &&
289 /* this means focus=true for window is same as config_focus_new=true */
290 ((config_focus_new
|| (settings
&& settings
->focus
== 1)) ||
291 client_search_focus_tree_full(self
)) &&
292 /* NET_WM_USER_TIME 0 when mapping means don't focus */
294 /* this checks for focus=false for the window */
295 (!settings
|| settings
->focus
!= 0) &&
296 focus_valid_target(self
, self
->desktop
,
297 FALSE
, FALSE
, TRUE
, FALSE
, FALSE
,
298 settings
->focus
== 1))
303 /* remove the client's border */
304 XSetWindowBorderWidth(obt_display
, self
->window
, 0);
306 /* adjust the frame to the client's size before showing or placing
308 frame_adjust_area(self
->frame
, FALSE
, TRUE
, FALSE
);
309 frame_adjust_client_area(self
->frame
);
311 /* where the frame was placed is where the window was originally */
313 monitor
= screen_physical_area_monitor(screen_find_monitor(&place
));
315 /* figure out placement for the window if the window is new */
316 if (ob_state() == OB_STATE_RUNNING
) {
317 ob_debug("Positioned: %s @ %d %d",
318 (!self
->positioned
? "no" :
319 (self
->positioned
== PPosition
? "program specified" :
320 (self
->positioned
== USPosition
? "user specified" :
321 (self
->positioned
== (PPosition
| USPosition
) ?
322 "program + user specified" :
323 "BADNESS !?")))), place
.x
, place
.y
);
325 ob_debug("Sized: %s @ %d %d",
326 (!self
->sized
? "no" :
327 (self
->sized
== PSize
? "program specified" :
328 (self
->sized
== USSize
? "user specified" :
329 (self
->sized
== (PSize
| USSize
) ?
330 "program + user specified" :
331 "BADNESS !?")))), place
.width
, place
.height
);
333 place_client(self
, &place
.x
, &place
.y
, settings
);
335 /* make sure the window is visible. */
336 client_find_onscreen(self
, &place
.x
, &place
.y
,
337 place
.width
, place
.height
,
338 /* non-normal clients has less rules, and
339 windows that are being restored from a
340 session do also. we can assume you want
341 it back where you saved it. Clients saying
342 they placed themselves are subjected to
343 harder rules, ones that are placed by
344 place.c or by the user are allowed partially
345 off-screen and on xinerama divides (ie,
346 it is up to the placement routines to avoid
347 the xinerama divides)
349 children and splash screens are forced on
350 screen, but i don't remember why i decided to
353 ob_state() == OB_STATE_RUNNING
&&
354 (self
->type
== OB_CLIENT_TYPE_DIALOG
||
355 self
->type
== OB_CLIENT_TYPE_SPLASH
||
356 (!((self
->positioned
& USPosition
) ||
357 (settings
&& settings
->pos_given
)) &&
358 client_normal(self
) &&
360 /* don't move oldschool fullscreen windows to
361 fit inside the struts (fixes Acroread, which
362 makes its fullscreen window fit the screen
363 but it is not USSize'd or USPosition'd) */
364 !(self
->decorations
== 0 &&
365 RECT_EQUAL(place
, *monitor
)))));
368 /* if the window isn't user-sized, then make it fit inside
369 the visible screen area on its monitor. Use basically the same rules
370 for forcing the window on screen in the client_find_onscreen call.
372 do this after place_client, it chooses the monitor!
374 splash screens get "transient" set to TRUE by
375 the place_client call
377 if (ob_state() == OB_STATE_RUNNING
&&
379 (!(self
->sized
& USSize
|| self
->positioned
& USPosition
) &&
380 client_normal(self
) &&
382 /* don't shrink oldschool fullscreen windows to fit inside the
383 struts (fixes Acroread, which makes its fullscreen window
384 fit the screen but it is not USSize'd or USPosition'd) */
385 !(self
->decorations
== 0 && RECT_EQUAL(place
, *monitor
)))))
387 Rect
*a
= screen_area(self
->desktop
, SCREEN_AREA_ONE_MONITOR
, &place
);
389 /* get the size of the frame */
390 place
.width
+= self
->frame
->size
.left
+ self
->frame
->size
.right
;
391 place
.height
+= self
->frame
->size
.top
+ self
->frame
->size
.bottom
;
393 /* fit the window inside the area */
394 place
.width
= MIN(place
.width
, a
->width
);
395 place
.height
= MIN(place
.height
, a
->height
);
397 ob_debug("setting window size to %dx%d", place
.width
, place
.height
);
399 /* get the size of the client back */
400 place
.width
-= self
->frame
->size
.left
+ self
->frame
->size
.right
;
401 place
.height
-= self
->frame
->size
.top
+ self
->frame
->size
.bottom
;
406 ob_debug("placing window 0x%x at %d, %d with size %d x %d. "
407 "some restrictions may apply",
408 self
->window
, place
.x
, place
.y
, place
.width
, place
.height
);
410 ob_debug(" but session requested %d, %d %d x %d instead, "
412 self
->session
->x
, self
->session
->y
,
413 self
->session
->w
, self
->session
->h
);
415 /* do this after the window is placed, so the premax/prefullscreen numbers
418 this also places the window
420 client_apply_startup_state(self
, place
.x
, place
.y
,
421 place
.width
, place
.height
);
426 ob_debug_type(OB_DEBUG_FOCUS
, "Going to try activate new window? %s",
427 activate
? "yes" : "no");
429 activate
= client_can_steal_focus(self
, map_time
, launch_time
);
432 /* if the client isn't stealing focus, then hilite it so the user
433 knows it is there, but don't do this if we're restoring from a
435 if (!client_restore_session_stacking(self
))
436 client_hilite(self
, TRUE
);
440 /* This may look rather odd. Well it's because new windows are added
441 to the stacking order non-intrusively. If we're not going to focus
442 the new window or hilite it, then we raise it to the top. This will
443 take affect for things that don't get focused like splash screens.
444 Also if you don't have focus_new enabled, then it's going to get
445 raised to the top. Legacy begets legacy I guess?
447 if (!client_restore_session_stacking(self
))
448 stacking_raise(CLIENT_AS_WINDOW(self
));
451 mouse_grab_for_client(self
, TRUE
);
453 /* this has to happen before we try focus the window, but we want it to
454 happen after the client's stacking has been determined or it looks bad
458 if (!config_focus_under_mouse
)
459 ignore_start
= event_start_ignore_all_enters();
463 if (!config_focus_under_mouse
)
464 event_end_ignore_all_enters(ignore_start
);
468 gboolean stacked
= client_restore_session_stacking(self
);
469 client_present(self
, FALSE
, !stacked
, TRUE
);
472 /* add to client list/map */
473 client_list
= g_list_append(client_list
, self
);
474 window_add(&self
->window
, CLIENT_AS_WINDOW(self
));
476 /* this has to happen after we're in the client_list */
477 if (STRUT_EXISTS(self
->strut
))
478 screen_update_areas();
480 /* update the list hints */
483 /* free the ObAppSettings shallow copy */
486 ob_debug("Managed window 0x%lx plate 0x%x (%s)",
487 window
, self
->frame
->window
, self
->class);
490 ObClient
*client_fake_manage(Window window
)
493 ObAppSettings
*settings
;
495 ob_debug("Pretend-managing window: %lx", window
);
497 /* do this minimal stuff to figure out the client's decorations */
499 self
= g_new0(ObClient
, 1);
500 self
->window
= window
;
502 client_get_all(self
, FALSE
);
503 /* per-app settings override stuff, and return the settings for other
504 uses too. this returns a shallow copy that needs to be freed */
505 settings
= client_get_settings_state(self
);
507 client_setup_decor_and_functions(self
, FALSE
);
509 /* create the decoration frame for the client window and adjust its size */
510 self
->frame
= frame_new(self
);
511 frame_adjust_area(self
->frame
, FALSE
, TRUE
, TRUE
);
513 ob_debug("gave extents left %d right %d top %d bottom %d",
514 self
->frame
->size
.left
, self
->frame
->size
.right
,
515 self
->frame
->size
.top
, self
->frame
->size
.bottom
);
517 /* free the ObAppSettings shallow copy */
523 void client_unmanage_all(void)
526 client_unmanage(client_list
->data
);
529 void client_unmanage(ObClient
*self
)
534 ob_debug("Unmanaging window: 0x%x plate 0x%x (%s) (%s)",
535 self
->window
, self
->frame
->window
,
536 self
->class, self
->title
? self
->title
: "");
538 g_assert(self
!= NULL
);
540 /* we dont want events no more. do this before hiding the frame so we
541 don't generate more events */
542 XSelectInput(obt_display
, self
->window
, NoEventMask
);
544 /* ignore enter events from the unmap so it doesnt mess with the focus */
545 if (!config_focus_under_mouse
)
546 ignore_start
= event_start_ignore_all_enters();
548 frame_hide(self
->frame
);
549 /* flush to send the hide to the server quickly */
552 if (!config_focus_under_mouse
)
553 event_end_ignore_all_enters(ignore_start
);
555 mouse_grab_for_client(self
, FALSE
);
557 self
->managed
= FALSE
;
559 /* remove the window from our save set, unless we are managing an internal
562 XChangeSaveSet(obt_display
, self
->window
, SetModeDelete
);
564 /* update the focus lists */
565 focus_order_remove(self
);
566 if (client_focused(self
)) {
567 /* don't leave an invalid focus_client */
571 /* if we're prompting to kill the client, close that */
572 prompt_unref(self
->kill_prompt
);
573 self
->kill_prompt
= NULL
;
575 client_list
= g_list_remove(client_list
, self
);
576 stacking_remove(self
);
577 window_remove(self
->window
);
579 /* once the client is out of the list, update the struts to remove its
581 if (STRUT_EXISTS(self
->strut
))
582 screen_update_areas();
584 client_call_notifies(self
, client_destroy_notifies
);
586 /* tell our parent(s) that we're gone */
587 for (it
= self
->parents
; it
; it
= g_slist_next(it
))
588 ((ObClient
*)it
->data
)->transients
=
589 g_slist_remove(((ObClient
*)it
->data
)->transients
,self
);
591 /* tell our transients that we're gone */
592 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
593 ((ObClient
*)it
->data
)->parents
=
594 g_slist_remove(((ObClient
*)it
->data
)->parents
, self
);
595 /* we could be keeping our children in a higher layer */
596 client_calc_layer(it
->data
);
599 /* remove from its group */
601 group_remove(self
->group
, self
);
605 /* restore the window's original geometry so it is not lost */
611 if (self
->fullscreen
)
612 a
= self
->pre_fullscreen_area
;
613 else if (self
->max_horz
|| self
->max_vert
) {
614 if (self
->max_horz
) {
615 a
.x
= self
->pre_max_area
.x
;
616 a
.width
= self
->pre_max_area
.width
;
618 if (self
->max_vert
) {
619 a
.y
= self
->pre_max_area
.y
;
620 a
.height
= self
->pre_max_area
.height
;
624 self
->fullscreen
= self
->max_horz
= self
->max_vert
= FALSE
;
625 /* let it be moved and resized no matter what */
626 self
->functions
= OB_CLIENT_FUNC_MOVE
| OB_CLIENT_FUNC_RESIZE
;
627 self
->decorations
= 0; /* unmanaged windows have no decor */
629 /* give the client its border back */
630 XSetWindowBorderWidth(obt_display
, self
->window
, self
->border_width
);
632 client_move_resize(self
, a
.x
, a
.y
, a
.width
, a
.height
);
635 /* reparent the window out of the frame, and free the frame */
636 frame_release_client(self
->frame
);
637 frame_free(self
->frame
);
640 if (ob_state() != OB_STATE_EXITING
) {
641 /* these values should not be persisted across a window
643 OBT_PROP_ERASE(self
->window
, NET_WM_DESKTOP
);
644 OBT_PROP_ERASE(self
->window
, NET_WM_STATE
);
645 OBT_PROP_ERASE(self
->window
, WM_STATE
);
647 /* if we're left in an unmapped state, the client wont be mapped.
648 this is bad, since we will no longer be managing the window on
650 XMapWindow(obt_display
, self
->window
);
653 /* these should not be left on the window ever. other window managers
654 don't necessarily use them and it will mess them up (like compiz) */
655 OBT_PROP_ERASE(self
->window
, NET_WM_VISIBLE_NAME
);
656 OBT_PROP_ERASE(self
->window
, NET_WM_VISIBLE_ICON_NAME
);
658 /* update the list hints */
661 ob_debug("Unmanaged window 0x%lx", self
->window
);
663 /* free all data allocated in the client struct */
664 RrImageUnref(self
->icon_set
);
665 g_slist_free(self
->transients
);
666 g_free(self
->startup_id
);
667 g_free(self
->wm_command
);
669 g_free(self
->icon_title
);
670 g_free(self
->original_title
);
674 g_free(self
->client_machine
);
675 g_free(self
->sm_client_id
);
679 void client_fake_unmanage(ObClient
*self
)
681 /* this is all that got allocated to get the decorations */
683 frame_free(self
->frame
);
687 static gboolean
client_can_steal_focus(ObClient
*self
, Time steal_time
,
691 gboolean relative_focused
;
692 gboolean parent_focused
;
696 parent_focused
= (focus_client
!= NULL
&&
697 client_search_focus_parent(self
));
698 relative_focused
= (focus_client
!= NULL
&&
699 (client_search_focus_tree_full(self
) != NULL
||
700 client_search_focus_group_full(self
) != NULL
));
702 /* This is focus stealing prevention */
703 ob_debug_type(OB_DEBUG_FOCUS
,
704 "Want to focus new window 0x%x at time %u "
705 "launched at %u (last user interaction time %u)",
706 self
->window
, steal_time
, launch_time
,
707 event_last_user_time
);
709 /* if it's on another desktop */
710 if (!(self
->desktop
== screen_desktop
||
711 self
->desktop
== DESKTOP_ALL
) &&
712 /* the timestamp is from before you changed desktops */
713 launch_time
&& screen_desktop_user_time
&&
714 !event_time_after(launch_time
, screen_desktop_user_time
))
717 ob_debug_type(OB_DEBUG_FOCUS
,
718 "Not focusing the window because its on another "
721 /* If something is focused... */
722 else if (focus_client
) {
723 /* If the user is working in another window right now, then don't
725 if (!parent_focused
&&
726 event_last_user_time
&& launch_time
&&
727 event_time_after(event_last_user_time
, launch_time
) &&
728 event_last_user_time
!= launch_time
&&
729 event_time_after(event_last_user_time
,
730 steal_time
- OB_EVENT_USER_TIME_DELAY
))
733 ob_debug_type(OB_DEBUG_FOCUS
,
734 "Not focusing the window because the user is "
735 "working in another window that is not "
738 /* If the new window is a transient (and its relatives aren't
740 else if (client_has_parent(self
) && !relative_focused
) {
742 ob_debug_type(OB_DEBUG_FOCUS
,
743 "Not focusing the window because it is a "
744 "transient, and its relatives aren't focused");
746 /* Don't steal focus from globally active clients.
747 I stole this idea from KWin. It seems nice.
749 else if (!(focus_client
->can_focus
||
750 focus_client
->focus_notify
))
753 ob_debug_type(OB_DEBUG_FOCUS
,
754 "Not focusing the window because a globally "
755 "active client has focus");
757 /* Don't move focus if it's not going to go to this window
759 else if (client_focus_target(self
) != self
) {
761 ob_debug_type(OB_DEBUG_FOCUS
,
762 "Not focusing the window because another window "
763 "would get the focus anyway");
765 /* Don't move focus if the window is not visible on the current
766 desktop and none of its relatives are focused */
767 else if (!(self
->desktop
== screen_desktop
||
768 self
->desktop
== DESKTOP_ALL
) &&
772 ob_debug_type(OB_DEBUG_FOCUS
,
773 "Not focusing the window because it is on "
774 "another desktop and no relatives are focused ");
779 ob_debug_type(OB_DEBUG_FOCUS
,
780 "Focus stealing prevention activated for %s at "
781 "time %u (last user interaction time %u)",
782 self
->title
, steal_time
, event_last_user_time
);
786 /*! Returns a new structure containing the per-app settings for this client.
787 The returned structure needs to be freed with g_free. */
788 static ObAppSettings
*client_get_settings_state(ObClient
*self
)
790 ObAppSettings
*settings
;
793 settings
= config_create_app_settings();
795 for (it
= config_per_app_settings
; it
; it
= g_slist_next(it
)) {
796 ObAppSettings
*app
= it
->data
;
797 gboolean match
= TRUE
;
799 g_assert(app
->name
!= NULL
|| app
->class != NULL
||
800 app
->role
!= NULL
|| app
->title
!= NULL
||
801 (signed)app
->type
>= 0);
804 !g_pattern_match(app
->name
, strlen(self
->name
), self
->name
, NULL
))
806 else if (app
->class &&
807 !g_pattern_match(app
->class,
808 strlen(self
->class), self
->class, NULL
))
810 else if (app
->role
&&
811 !g_pattern_match(app
->role
,
812 strlen(self
->role
), self
->role
, NULL
))
814 else if (app
->title
&&
815 !g_pattern_match(app
->title
,
816 strlen(self
->title
), self
->title
, NULL
))
818 else if ((signed)app
->type
>= 0 && app
->type
!= self
->type
) {
823 ob_debug("Window matching: %s", app
->name
);
825 /* copy the settings to our struct, overriding the existing
826 settings if they are not defaults */
827 config_app_settings_copy_non_defaults(app
, settings
);
831 if (settings
->shade
!= -1)
832 self
->shaded
= !!settings
->shade
;
833 if (settings
->decor
!= -1)
834 self
->undecorated
= !settings
->decor
;
835 if (settings
->iconic
!= -1)
836 self
->iconic
= !!settings
->iconic
;
837 if (settings
->skip_pager
!= -1)
838 self
->skip_pager
= !!settings
->skip_pager
;
839 if (settings
->skip_taskbar
!= -1)
840 self
->skip_taskbar
= !!settings
->skip_taskbar
;
842 if (settings
->max_vert
!= -1)
843 self
->max_vert
= !!settings
->max_vert
;
844 if (settings
->max_horz
!= -1)
845 self
->max_horz
= !!settings
->max_horz
;
847 if (settings
->fullscreen
!= -1)
848 self
->fullscreen
= !!settings
->fullscreen
;
850 if (settings
->desktop
) {
851 if (settings
->desktop
== DESKTOP_ALL
)
852 self
->desktop
= settings
->desktop
;
853 else if (settings
->desktop
> 0 &&
854 settings
->desktop
<= screen_num_desktops
)
855 self
->desktop
= settings
->desktop
- 1;
858 if (settings
->layer
== -1) {
862 else if (settings
->layer
== 0) {
866 else if (settings
->layer
== 1) {
873 static void client_restore_session_state(ObClient
*self
)
877 ob_debug_type(OB_DEBUG_SM
,
878 "Restore session for client %s", self
->title
);
880 if (!(it
= session_state_find(self
))) {
881 ob_debug_type(OB_DEBUG_SM
,
882 "Session data not found for client %s", self
->title
);
886 self
->session
= it
->data
;
888 ob_debug_type(OB_DEBUG_SM
, "Session data loaded for client %s",
891 RECT_SET_POINT(self
->area
, self
->session
->x
, self
->session
->y
);
892 self
->positioned
= USPosition
;
893 self
->sized
= USSize
;
894 if (self
->session
->w
> 0)
895 self
->area
.width
= self
->session
->w
;
896 if (self
->session
->h
> 0)
897 self
->area
.height
= self
->session
->h
;
898 XResizeWindow(obt_display
, self
->window
,
899 self
->area
.width
, self
->area
.height
);
901 self
->desktop
= (self
->session
->desktop
== DESKTOP_ALL
?
902 self
->session
->desktop
:
903 MIN(screen_num_desktops
- 1, self
->session
->desktop
));
904 OBT_PROP_SET32(self
->window
, NET_WM_DESKTOP
, CARDINAL
, self
->desktop
);
906 self
->shaded
= self
->session
->shaded
;
907 self
->iconic
= self
->session
->iconic
;
908 self
->skip_pager
= self
->session
->skip_pager
;
909 self
->skip_taskbar
= self
->session
->skip_taskbar
;
910 self
->fullscreen
= self
->session
->fullscreen
;
911 self
->above
= self
->session
->above
;
912 self
->below
= self
->session
->below
;
913 self
->max_horz
= self
->session
->max_horz
;
914 self
->max_vert
= self
->session
->max_vert
;
915 self
->undecorated
= self
->session
->undecorated
;
918 static gboolean
client_restore_session_stacking(ObClient
*self
)
922 if (!self
->session
) return FALSE
;
924 mypos
= g_list_find(session_saved_state
, self
->session
);
925 if (!mypos
) return FALSE
;
927 /* start above me and look for the first client */
928 for (it
= g_list_previous(mypos
); it
; it
= g_list_previous(it
)) {
931 for (cit
= client_list
; cit
; cit
= g_list_next(cit
)) {
932 ObClient
*c
= cit
->data
;
933 /* found a client that was in the session, so go below it */
934 if (c
->session
== it
->data
) {
935 stacking_below(CLIENT_AS_WINDOW(self
),
936 CLIENT_AS_WINDOW(cit
->data
));
944 void client_move_onscreen(ObClient
*self
, gboolean rude
)
946 gint x
= self
->area
.x
;
947 gint y
= self
->area
.y
;
948 if (client_find_onscreen(self
, &x
, &y
,
950 self
->area
.height
, rude
)) {
951 client_move(self
, x
, y
);
955 gboolean
client_find_onscreen(ObClient
*self
, gint
*x
, gint
*y
, gint w
, gint h
,
958 gint ox
= *x
, oy
= *y
;
959 gboolean rudel
= rude
, ruder
= rude
, rudet
= rude
, rudeb
= rude
;
965 RECT_SET(desired
, *x
, *y
, w
, h
);
966 frame_rect_to_frame(self
->frame
, &desired
);
968 /* get where the frame would be */
969 frame_client_gravity(self
->frame
, x
, y
);
971 /* get the requested size of the window with decorations */
972 fw
= self
->frame
->size
.left
+ w
+ self
->frame
->size
.right
;
973 fh
= self
->frame
->size
.top
+ h
+ self
->frame
->size
.bottom
;
975 /* If rudeness wasn't requested, then still be rude in a given direction
976 if the client is not moving, only resizing in that direction */
978 Point oldtl
, oldtr
, oldbl
, oldbr
;
979 Point newtl
, newtr
, newbl
, newbr
;
980 gboolean stationary_l
, stationary_r
, stationary_t
, stationary_b
;
982 POINT_SET(oldtl
, self
->frame
->area
.x
, self
->frame
->area
.y
);
983 POINT_SET(oldbr
, self
->frame
->area
.x
+ self
->frame
->area
.width
- 1,
984 self
->frame
->area
.y
+ self
->frame
->area
.height
- 1);
985 POINT_SET(oldtr
, oldbr
.x
, oldtl
.y
);
986 POINT_SET(oldbl
, oldtl
.x
, oldbr
.y
);
988 POINT_SET(newtl
, *x
, *y
);
989 POINT_SET(newbr
, *x
+ fw
- 1, *y
+ fh
- 1);
990 POINT_SET(newtr
, newbr
.x
, newtl
.y
);
991 POINT_SET(newbl
, newtl
.x
, newbr
.y
);
993 /* is it moving or just resizing from some corner? */
994 stationary_l
= oldtl
.x
== newtl
.x
;
995 stationary_r
= oldtr
.x
== newtr
.x
;
996 stationary_t
= oldtl
.y
== newtl
.y
;
997 stationary_b
= oldbl
.y
== newbl
.y
;
999 /* if left edge is growing and didnt move right edge */
1000 if (stationary_r
&& newtl
.x
< oldtl
.x
)
1002 /* if right edge is growing and didnt move left edge */
1003 if (stationary_l
&& newtr
.x
> oldtr
.x
)
1005 /* if top edge is growing and didnt move bottom edge */
1006 if (stationary_b
&& newtl
.y
< oldtl
.y
)
1008 /* if bottom edge is growing and didnt move top edge */
1009 if (stationary_t
&& newbl
.y
> oldbl
.y
)
1013 /* we iterate through every monitor that the window is at least partially
1014 on, to make sure it is obeying the rules on them all
1016 if the window does not appear on any monitors, then use the first one
1019 for (i
= 0; i
< screen_num_monitors
; ++i
) {
1022 if (!screen_physical_area_monitor_contains(i
, &desired
)) {
1023 if (i
< screen_num_monitors
- 1 || found_mon
)
1026 /* the window is not inside any monitor! so just use the first
1028 a
= screen_area(self
->desktop
, 0, NULL
);
1031 a
= screen_area(self
->desktop
, SCREEN_AREA_ONE_MONITOR
, &desired
);
1034 /* This makes sure windows aren't entirely outside of the screen so you
1035 can't see them at all.
1036 It makes sure 10% of the window is on the screen at least. And don't
1037 let it move itself off the top of the screen, which would hide the
1038 titlebar on you. (The user can still do this if they want too, it's
1039 only limiting the application.
1041 if (client_normal(self
)) {
1042 if (!self
->strut
.right
&& *x
+ fw
/10 >= a
->x
+ a
->width
- 1)
1043 *x
= a
->x
+ a
->width
- fw
/10;
1044 if (!self
->strut
.bottom
&& *y
+ fh
/10 >= a
->y
+ a
->height
- 1)
1045 *y
= a
->y
+ a
->height
- fh
/10;
1046 if (!self
->strut
.left
&& *x
+ fw
*9/10 - 1 < a
->x
)
1047 *x
= a
->x
- fw
*9/10;
1048 if (!self
->strut
.top
&& *y
+ fh
*9/10 - 1 < a
->y
)
1049 *y
= a
->y
- fh
*9/10;
1052 /* This here doesn't let windows even a pixel outside the
1053 struts/screen. When called from client_manage, programs placing
1054 themselves are forced completely onscreen, while things like
1055 xterm -geometry resolution-width/2 will work fine. Trying to
1056 place it completely offscreen will be handled in the above code.
1057 Sorry for this confused comment, i am tired. */
1058 if (rudel
&& !self
->strut
.left
&& *x
< a
->x
) *x
= a
->x
;
1059 if (ruder
&& !self
->strut
.right
&& *x
+ fw
> a
->x
+ a
->width
)
1060 *x
= a
->x
+ MAX(0, a
->width
- fw
);
1062 if (rudet
&& !self
->strut
.top
&& *y
< a
->y
) *y
= a
->y
;
1063 if (rudeb
&& !self
->strut
.bottom
&& *y
+ fh
> a
->y
+ a
->height
)
1064 *y
= a
->y
+ MAX(0, a
->height
- fh
);
1069 /* get where the client should be */
1070 frame_frame_gravity(self
->frame
, x
, y
);
1072 return ox
!= *x
|| oy
!= *y
;
1075 static void client_get_all(ObClient
*self
, gboolean real
)
1077 /* this is needed for the frame to set itself up */
1078 client_get_area(self
);
1080 /* these things can change the decor and functions of the window */
1082 client_get_mwm_hints(self
);
1083 /* this can change the mwmhints for special cases */
1084 client_get_type_and_transientness(self
);
1085 client_get_state(self
);
1086 client_update_normal_hints(self
);
1088 /* get the session related properties, these can change decorations
1089 from per-app settings */
1090 client_get_session_ids(self
);
1092 /* now we got everything that can affect the decorations */
1096 /* get this early so we have it for debugging */
1097 client_update_title(self
);
1099 /* save the values of the variables used for app rule matching */
1100 client_save_app_rule_values(self
);
1102 client_update_protocols(self
);
1104 client_update_wmhints(self
);
1105 /* this may have already been called from client_update_wmhints */
1106 if (!self
->parents
&& !self
->transient_for_group
)
1107 client_update_transient_for(self
);
1109 client_get_startup_id(self
);
1110 client_get_desktop(self
);/* uses transient data/group/startup id if a
1111 desktop is not specified */
1112 client_get_shaped(self
);
1115 /* a couple type-based defaults for new windows */
1117 /* this makes sure that these windows appear on all desktops */
1118 if (self
->type
== OB_CLIENT_TYPE_DESKTOP
)
1119 self
->desktop
= DESKTOP_ALL
;
1123 client_update_sync_request_counter(self
);
1126 client_get_colormap(self
);
1127 client_update_strut(self
);
1128 client_update_icons(self
);
1129 client_update_icon_geometry(self
);
1132 static void client_get_startup_id(ObClient
*self
)
1134 if (!(OBT_PROP_GETS(self
->window
, NET_STARTUP_ID
, utf8
,
1135 &self
->startup_id
)))
1137 OBT_PROP_GETS(self
->group
->leader
,
1138 NET_STARTUP_ID
, utf8
, &self
->startup_id
);
1141 static void client_get_area(ObClient
*self
)
1143 XWindowAttributes wattrib
;
1146 ret
= XGetWindowAttributes(obt_display
, self
->window
, &wattrib
);
1147 g_assert(ret
!= BadWindow
);
1149 RECT_SET(self
->area
, wattrib
.x
, wattrib
.y
, wattrib
.width
, wattrib
.height
);
1150 POINT_SET(self
->root_pos
, wattrib
.x
, wattrib
.y
);
1151 self
->border_width
= wattrib
.border_width
;
1153 ob_debug("client area: %d %d %d %d bw %d", wattrib
.x
, wattrib
.y
,
1154 wattrib
.width
, wattrib
.height
, wattrib
.border_width
);
1157 static void client_get_desktop(ObClient
*self
)
1159 guint32 d
= screen_num_desktops
; /* an always-invalid value */
1161 if (OBT_PROP_GET32(self
->window
, NET_WM_DESKTOP
, CARDINAL
, &d
)) {
1162 if (d
>= screen_num_desktops
&& d
!= DESKTOP_ALL
)
1163 self
->desktop
= screen_num_desktops
- 1;
1166 ob_debug("client requested desktop 0x%x", self
->desktop
);
1169 gboolean first
= TRUE
;
1170 guint all
= screen_num_desktops
; /* not a valid value */
1172 /* if they are all on one desktop, then open it on the
1174 for (it
= self
->parents
; it
; it
= g_slist_next(it
)) {
1175 ObClient
*c
= it
->data
;
1177 if (c
->desktop
== DESKTOP_ALL
) continue;
1183 else if (all
!= c
->desktop
)
1184 all
= screen_num_desktops
; /* make it invalid */
1186 if (all
!= screen_num_desktops
) {
1187 self
->desktop
= all
;
1189 ob_debug("client desktop set from parents: 0x%x",
1192 /* try get from the startup-notification protocol */
1193 else if (sn_get_desktop(self
->startup_id
, &self
->desktop
)) {
1194 if (self
->desktop
>= screen_num_desktops
&&
1195 self
->desktop
!= DESKTOP_ALL
)
1196 self
->desktop
= screen_num_desktops
- 1;
1197 ob_debug("client desktop set from startup-notification: 0x%x",
1200 /* defaults to the current desktop */
1202 self
->desktop
= screen_desktop
;
1203 ob_debug("client desktop set to the current desktop: %d",
1209 static void client_get_state(ObClient
*self
)
1214 if (OBT_PROP_GETA32(self
->window
, NET_WM_STATE
, ATOM
, &state
, &num
)) {
1216 for (i
= 0; i
< num
; ++i
) {
1217 if (state
[i
] == OBT_PROP_ATOM(NET_WM_STATE_MODAL
))
1219 else if (state
[i
] == OBT_PROP_ATOM(NET_WM_STATE_SHADED
))
1220 self
->shaded
= TRUE
;
1221 else if (state
[i
] == OBT_PROP_ATOM(NET_WM_STATE_HIDDEN
))
1222 self
->iconic
= TRUE
;
1223 else if (state
[i
] == OBT_PROP_ATOM(NET_WM_STATE_SKIP_TASKBAR
))
1224 self
->skip_taskbar
= TRUE
;
1225 else if (state
[i
] == OBT_PROP_ATOM(NET_WM_STATE_SKIP_PAGER
))
1226 self
->skip_pager
= TRUE
;
1227 else if (state
[i
] == OBT_PROP_ATOM(NET_WM_STATE_FULLSCREEN
))
1228 self
->fullscreen
= TRUE
;
1229 else if (state
[i
] == OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_VERT
))
1230 self
->max_vert
= TRUE
;
1231 else if (state
[i
] == OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_HORZ
))
1232 self
->max_horz
= TRUE
;
1233 else if (state
[i
] == OBT_PROP_ATOM(NET_WM_STATE_ABOVE
))
1235 else if (state
[i
] == OBT_PROP_ATOM(NET_WM_STATE_BELOW
))
1237 else if (state
[i
] == OBT_PROP_ATOM(NET_WM_STATE_DEMANDS_ATTENTION
))
1238 self
->demands_attention
= TRUE
;
1239 else if (state
[i
] == OBT_PROP_ATOM(OB_WM_STATE_UNDECORATED
))
1240 self
->undecorated
= TRUE
;
1247 static void client_get_shaped(ObClient
*self
)
1249 self
->shaped
= FALSE
;
1251 if (obt_display_extension_shape
) {
1256 XShapeSelectInput(obt_display
, self
->window
, ShapeNotifyMask
);
1258 XShapeQueryExtents(obt_display
, self
->window
, &s
, &foo
,
1259 &foo
, &ufoo
, &ufoo
, &foo
, &foo
, &foo
, &ufoo
,
1266 void client_update_transient_for(ObClient
*self
)
1269 ObClient
*target
= NULL
;
1270 gboolean trangroup
= FALSE
;
1272 if (XGetTransientForHint(obt_display
, self
->window
, &t
)) {
1273 if (t
!= self
->window
) { /* can't be transient to itself! */
1274 ObWindow
*tw
= window_find(t
);
1275 /* if this happens then we need to check for it */
1276 g_assert(tw
!= CLIENT_AS_WINDOW(self
));
1277 if (tw
&& WINDOW_IS_CLIENT(tw
)) {
1278 /* watch out for windows with a parent that is something
1279 different, like a dockapp for example */
1280 target
= WINDOW_AS_CLIENT(tw
);
1284 /* Setting the transient_for to Root is actually illegal, however
1285 applications from time have done this to specify transient for
1287 if (!target
&& self
->group
&& t
== obt_root(ob_screen
))
1289 } else if (self
->group
&& self
->transient
)
1292 client_update_transient_tree(self
, self
->group
, self
->group
,
1293 self
->transient_for_group
, trangroup
,
1294 client_direct_parent(self
), target
);
1295 self
->transient_for_group
= trangroup
;
1299 static void client_update_transient_tree(ObClient
*self
,
1300 ObGroup
*oldgroup
, ObGroup
*newgroup
,
1301 gboolean oldgtran
, gboolean newgtran
,
1302 ObClient
* oldparent
,
1303 ObClient
*newparent
)
1308 g_assert(!oldgtran
|| oldgroup
);
1309 g_assert(!newgtran
|| newgroup
);
1310 g_assert((!oldgtran
&& !oldparent
) ||
1311 (oldgtran
&& !oldparent
) ||
1312 (!oldgtran
&& oldparent
));
1313 g_assert((!newgtran
&& !newparent
) ||
1314 (newgtran
&& !newparent
) ||
1315 (!newgtran
&& newparent
));
1318 Group transient windows are not allowed to have other group
1319 transient windows as their children.
1322 /* No change has occured */
1323 if (oldgroup
== newgroup
&&
1324 oldgtran
== newgtran
&&
1325 oldparent
== newparent
) return;
1327 /** Remove the client from the transient tree **/
1329 for (it
= self
->transients
; it
; it
= next
) {
1330 next
= g_slist_next(it
);
1332 self
->transients
= g_slist_delete_link(self
->transients
, it
);
1333 c
->parents
= g_slist_remove(c
->parents
, self
);
1335 for (it
= self
->parents
; it
; it
= next
) {
1336 next
= g_slist_next(it
);
1338 self
->parents
= g_slist_delete_link(self
->parents
, it
);
1339 c
->transients
= g_slist_remove(c
->transients
, self
);
1342 /** Re-add the client to the transient tree **/
1344 /* If we're transient for a group then we need to add ourselves to all our
1347 for (it
= newgroup
->members
; it
; it
= g_slist_next(it
)) {
1350 !client_search_top_direct_parent(c
)->transient_for_group
&&
1353 c
->transients
= g_slist_prepend(c
->transients
, self
);
1354 self
->parents
= g_slist_prepend(self
->parents
, c
);
1359 /* If we are now transient for a single window we need to add ourselves to
1362 WARNING: Cyclical transient-ness is possible if two windows are
1363 transient for eachother.
1365 else if (newparent
&&
1366 /* don't make ourself its child if it is already our child */
1367 !client_is_direct_child(self
, newparent
) &&
1368 client_normal(newparent
))
1370 newparent
->transients
= g_slist_prepend(newparent
->transients
, self
);
1371 self
->parents
= g_slist_prepend(self
->parents
, newparent
);
1374 /* Add any group transient windows to our children. But if we're transient
1375 for the group, then other group transients are not our children.
1377 WARNING: Cyclical transient-ness is possible. For e.g. if:
1378 A is transient for the group
1379 B is transient for A
1380 C is transient for B
1381 A can't be transient for C or we have a cycle
1383 if (!newgtran
&& newgroup
&&
1385 !client_search_top_direct_parent(newparent
)->transient_for_group
) &&
1386 client_normal(self
))
1388 for (it
= newgroup
->members
; it
; it
= g_slist_next(it
)) {
1390 if (c
!= self
&& c
->transient_for_group
&&
1391 /* Don't make it our child if it is already our parent */
1392 !client_is_direct_child(c
, self
))
1394 self
->transients
= g_slist_prepend(self
->transients
, c
);
1395 c
->parents
= g_slist_prepend(c
->parents
, self
);
1400 /** If we change our group transient-ness, our children change their
1401 effective group transient-ness, which affects how they relate to other
1404 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
1406 if (!c
->transient_for_group
)
1407 client_update_transient_tree(c
, c
->group
, c
->group
,
1408 c
->transient_for_group
,
1409 c
->transient_for_group
,
1410 client_direct_parent(c
),
1411 client_direct_parent(c
));
1415 void client_get_mwm_hints(ObClient
*self
)
1420 self
->mwmhints
.flags
= 0; /* default to none */
1422 if (OBT_PROP_GETA32(self
->window
, MOTIF_WM_HINTS
, MOTIF_WM_HINTS
,
1424 if (num
>= OB_MWM_ELEMENTS
) {
1425 self
->mwmhints
.flags
= hints
[0];
1426 self
->mwmhints
.functions
= hints
[1];
1427 self
->mwmhints
.decorations
= hints
[2];
1433 void client_get_type_and_transientness(ObClient
*self
)
1440 self
->transient
= FALSE
;
1442 if (OBT_PROP_GETA32(self
->window
, NET_WM_WINDOW_TYPE
, ATOM
, &val
, &num
)) {
1443 /* use the first value that we know about in the array */
1444 for (i
= 0; i
< num
; ++i
) {
1445 if (val
[i
] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_DESKTOP
))
1446 self
->type
= OB_CLIENT_TYPE_DESKTOP
;
1447 else if (val
[i
] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_DOCK
))
1448 self
->type
= OB_CLIENT_TYPE_DOCK
;
1449 else if (val
[i
] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_TOOLBAR
))
1450 self
->type
= OB_CLIENT_TYPE_TOOLBAR
;
1451 else if (val
[i
] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_MENU
))
1452 self
->type
= OB_CLIENT_TYPE_MENU
;
1453 else if (val
[i
] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_UTILITY
))
1454 self
->type
= OB_CLIENT_TYPE_UTILITY
;
1455 else if (val
[i
] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_SPLASH
))
1456 self
->type
= OB_CLIENT_TYPE_SPLASH
;
1457 else if (val
[i
] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_DIALOG
))
1458 self
->type
= OB_CLIENT_TYPE_DIALOG
;
1459 else if (val
[i
] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_NORMAL
))
1460 self
->type
= OB_CLIENT_TYPE_NORMAL
;
1461 else if (val
[i
] == OBT_PROP_ATOM(KDE_NET_WM_WINDOW_TYPE_OVERRIDE
))
1463 /* prevent this window from getting any decor or
1465 self
->mwmhints
.flags
&= (OB_MWM_FLAG_FUNCTIONS
|
1466 OB_MWM_FLAG_DECORATIONS
);
1467 self
->mwmhints
.decorations
= 0;
1468 self
->mwmhints
.functions
= 0;
1470 if (self
->type
!= (ObClientType
) -1)
1471 break; /* grab the first legit type */
1476 if (XGetTransientForHint(obt_display
, self
->window
, &t
))
1477 self
->transient
= TRUE
;
1479 if (self
->type
== (ObClientType
) -1) {
1480 /*the window type hint was not set, which means we either classify
1481 ourself as a normal window or a dialog, depending on if we are a
1483 if (self
->transient
)
1484 self
->type
= OB_CLIENT_TYPE_DIALOG
;
1486 self
->type
= OB_CLIENT_TYPE_NORMAL
;
1489 /* then, based on our type, we can update our transientness.. */
1490 if (self
->type
== OB_CLIENT_TYPE_DIALOG
||
1491 self
->type
== OB_CLIENT_TYPE_TOOLBAR
||
1492 self
->type
== OB_CLIENT_TYPE_MENU
||
1493 self
->type
== OB_CLIENT_TYPE_UTILITY
)
1495 self
->transient
= TRUE
;
1499 void client_update_protocols(ObClient
*self
)
1504 self
->focus_notify
= FALSE
;
1505 self
->delete_window
= FALSE
;
1507 if (OBT_PROP_GETA32(self
->window
, WM_PROTOCOLS
, ATOM
, &proto
, &num_ret
)) {
1508 for (i
= 0; i
< num_ret
; ++i
) {
1509 if (proto
[i
] == OBT_PROP_ATOM(WM_DELETE_WINDOW
))
1510 /* this means we can request the window to close */
1511 self
->delete_window
= TRUE
;
1512 else if (proto
[i
] == OBT_PROP_ATOM(WM_TAKE_FOCUS
))
1513 /* if this protocol is requested, then the window will be
1514 notified whenever we want it to receive focus */
1515 self
->focus_notify
= TRUE
;
1516 else if (proto
[i
] == OBT_PROP_ATOM(NET_WM_PING
))
1517 /* if this protocol is requested, then the window will allow
1518 pings to determine if it is still alive */
1521 else if (proto
[i
] == OBT_PROP_ATOM(NET_WM_SYNC_REQUEST
))
1522 /* if this protocol is requested, then resizing the
1523 window will be synchronized between the frame and the
1525 self
->sync_request
= TRUE
;
1533 void client_update_sync_request_counter(ObClient
*self
)
1537 if (OBT_PROP_GET32(self
->window
, NET_WM_SYNC_REQUEST_COUNTER
, CARDINAL
,&i
))
1539 self
->sync_counter
= i
;
1541 self
->sync_counter
= None
;
1545 static void client_get_colormap(ObClient
*self
)
1547 XWindowAttributes wa
;
1549 if (XGetWindowAttributes(obt_display
, self
->window
, &wa
))
1550 client_update_colormap(self
, wa
.colormap
);
1553 void client_update_colormap(ObClient
*self
, Colormap colormap
)
1555 if (colormap
== self
->colormap
) return;
1557 ob_debug("Setting client %s colormap: 0x%x", self
->title
, colormap
);
1559 if (client_focused(self
)) {
1560 screen_install_colormap(self
, FALSE
); /* uninstall old one */
1561 self
->colormap
= colormap
;
1562 screen_install_colormap(self
, TRUE
); /* install new one */
1564 self
->colormap
= colormap
;
1567 void client_update_normal_hints(ObClient
*self
)
1573 self
->min_ratio
= 0.0f
;
1574 self
->max_ratio
= 0.0f
;
1575 SIZE_SET(self
->size_inc
, 1, 1);
1576 SIZE_SET(self
->base_size
, -1, -1);
1577 SIZE_SET(self
->min_size
, 0, 0);
1578 SIZE_SET(self
->max_size
, G_MAXINT
, G_MAXINT
);
1580 /* get the hints from the window */
1581 if (XGetWMNormalHints(obt_display
, self
->window
, &size
, &ret
)) {
1582 /* normal windows can't request placement! har har
1583 if (!client_normal(self))
1585 self
->positioned
= (size
.flags
& (PPosition
|USPosition
));
1586 self
->sized
= (size
.flags
& (PSize
|USSize
));
1588 if (size
.flags
& PWinGravity
)
1589 self
->gravity
= size
.win_gravity
;
1591 if (size
.flags
& PAspect
) {
1592 if (size
.min_aspect
.y
)
1594 (gfloat
) size
.min_aspect
.x
/ size
.min_aspect
.y
;
1595 if (size
.max_aspect
.y
)
1597 (gfloat
) size
.max_aspect
.x
/ size
.max_aspect
.y
;
1600 if (size
.flags
& PMinSize
)
1601 SIZE_SET(self
->min_size
, size
.min_width
, size
.min_height
);
1603 if (size
.flags
& PMaxSize
)
1604 SIZE_SET(self
->max_size
, size
.max_width
, size
.max_height
);
1606 if (size
.flags
& PBaseSize
)
1607 SIZE_SET(self
->base_size
, size
.base_width
, size
.base_height
);
1609 if (size
.flags
& PResizeInc
&& size
.width_inc
&& size
.height_inc
)
1610 SIZE_SET(self
->size_inc
, size
.width_inc
, size
.height_inc
);
1612 ob_debug("Normal hints: min size (%d %d) max size (%d %d)",
1613 self
->min_size
.width
, self
->min_size
.height
,
1614 self
->max_size
.width
, self
->max_size
.height
);
1615 ob_debug("size inc (%d %d) base size (%d %d)",
1616 self
->size_inc
.width
, self
->size_inc
.height
,
1617 self
->base_size
.width
, self
->base_size
.height
);
1620 ob_debug("Normal hints: not set");
1623 void client_setup_decor_and_functions(ObClient
*self
, gboolean reconfig
)
1625 /* start with everything (cept fullscreen) */
1627 (OB_FRAME_DECOR_TITLEBAR
|
1628 OB_FRAME_DECOR_HANDLE
|
1629 OB_FRAME_DECOR_GRIPS
|
1630 OB_FRAME_DECOR_BORDER
|
1631 OB_FRAME_DECOR_ICON
|
1632 OB_FRAME_DECOR_ALLDESKTOPS
|
1633 OB_FRAME_DECOR_ICONIFY
|
1634 OB_FRAME_DECOR_MAXIMIZE
|
1635 OB_FRAME_DECOR_SHADE
|
1636 OB_FRAME_DECOR_CLOSE
);
1638 (OB_CLIENT_FUNC_RESIZE
|
1639 OB_CLIENT_FUNC_MOVE
|
1640 OB_CLIENT_FUNC_ICONIFY
|
1641 OB_CLIENT_FUNC_MAXIMIZE
|
1642 OB_CLIENT_FUNC_SHADE
|
1643 OB_CLIENT_FUNC_CLOSE
|
1644 OB_CLIENT_FUNC_BELOW
|
1645 OB_CLIENT_FUNC_ABOVE
|
1646 OB_CLIENT_FUNC_UNDECORATE
);
1648 if (!(self
->min_size
.width
< self
->max_size
.width
||
1649 self
->min_size
.height
< self
->max_size
.height
))
1650 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
1652 switch (self
->type
) {
1653 case OB_CLIENT_TYPE_NORMAL
:
1654 /* normal windows retain all of the possible decorations and
1655 functionality, and can be fullscreen */
1656 self
->functions
|= OB_CLIENT_FUNC_FULLSCREEN
;
1659 case OB_CLIENT_TYPE_DIALOG
:
1660 /* sometimes apps make dialog windows fullscreen for some reason (for
1661 e.g. kpdf does this..) */
1662 self
->functions
|= OB_CLIENT_FUNC_FULLSCREEN
;
1665 case OB_CLIENT_TYPE_UTILITY
:
1666 /* these windows don't have anything added or removed by default */
1669 case OB_CLIENT_TYPE_MENU
:
1670 case OB_CLIENT_TYPE_TOOLBAR
:
1671 /* these windows can't iconify or maximize */
1672 self
->decorations
&= ~(OB_FRAME_DECOR_ICONIFY
|
1673 OB_FRAME_DECOR_MAXIMIZE
);
1674 self
->functions
&= ~(OB_CLIENT_FUNC_ICONIFY
|
1675 OB_CLIENT_FUNC_MAXIMIZE
);
1678 case OB_CLIENT_TYPE_SPLASH
:
1679 /* these don't get get any decorations, and the only thing you can
1680 do with them is move them */
1681 self
->decorations
= 0;
1682 self
->functions
= OB_CLIENT_FUNC_MOVE
;
1685 case OB_CLIENT_TYPE_DESKTOP
:
1686 /* these windows are not manipulated by the window manager */
1687 self
->decorations
= 0;
1688 self
->functions
= 0;
1691 case OB_CLIENT_TYPE_DOCK
:
1692 /* these windows are not manipulated by the window manager, but they
1693 can set below layer which has a special meaning */
1694 self
->decorations
= 0;
1695 self
->functions
= OB_CLIENT_FUNC_BELOW
;
1699 /* Mwm Hints are applied subtractively to what has already been chosen for
1700 decor and functionality */
1701 if (self
->mwmhints
.flags
& OB_MWM_FLAG_DECORATIONS
) {
1702 if (! (self
->mwmhints
.decorations
& OB_MWM_DECOR_ALL
)) {
1703 if (! ((self
->mwmhints
.decorations
& OB_MWM_DECOR_HANDLE
) ||
1704 (self
->mwmhints
.decorations
& OB_MWM_DECOR_TITLE
)))
1706 /* if the mwm hints request no handle or title, then all
1707 decorations are disabled, but keep the border if that's
1709 if (self
->mwmhints
.decorations
& OB_MWM_DECOR_BORDER
)
1710 self
->decorations
= OB_FRAME_DECOR_BORDER
;
1712 self
->decorations
= 0;
1717 if (self
->mwmhints
.flags
& OB_MWM_FLAG_FUNCTIONS
) {
1718 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_ALL
)) {
1719 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_RESIZE
))
1720 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
1721 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_MOVE
))
1722 self
->functions
&= ~OB_CLIENT_FUNC_MOVE
;
1723 /* dont let mwm hints kill any buttons
1724 if (! (self->mwmhints.functions & OB_MWM_FUNC_ICONIFY))
1725 self->functions &= ~OB_CLIENT_FUNC_ICONIFY;
1726 if (! (self->mwmhints.functions & OB_MWM_FUNC_MAXIMIZE))
1727 self->functions &= ~OB_CLIENT_FUNC_MAXIMIZE;
1729 /* dont let mwm hints kill the close button
1730 if (! (self->mwmhints.functions & MwmFunc_Close))
1731 self->functions &= ~OB_CLIENT_FUNC_CLOSE; */
1735 if (!(self
->functions
& OB_CLIENT_FUNC_SHADE
))
1736 self
->decorations
&= ~OB_FRAME_DECOR_SHADE
;
1737 if (!(self
->functions
& OB_CLIENT_FUNC_ICONIFY
))
1738 self
->decorations
&= ~OB_FRAME_DECOR_ICONIFY
;
1739 if (!(self
->functions
& OB_CLIENT_FUNC_RESIZE
))
1740 self
->decorations
&= ~(OB_FRAME_DECOR_GRIPS
| OB_FRAME_DECOR_HANDLE
);
1742 /* can't maximize without moving/resizing */
1743 if (!((self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) &&
1744 (self
->functions
& OB_CLIENT_FUNC_MOVE
) &&
1745 (self
->functions
& OB_CLIENT_FUNC_RESIZE
))) {
1746 self
->functions
&= ~OB_CLIENT_FUNC_MAXIMIZE
;
1747 self
->decorations
&= ~OB_FRAME_DECOR_MAXIMIZE
;
1750 if (self
->max_horz
&& self
->max_vert
) {
1751 /* you can't resize fully maximized windows */
1752 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
1753 /* kill the handle on fully maxed windows */
1754 self
->decorations
&= ~(OB_FRAME_DECOR_HANDLE
| OB_FRAME_DECOR_GRIPS
);
1757 /* If there are no decorations to remove, don't allow the user to try
1759 if (self
->decorations
== 0)
1760 self
->functions
&= ~OB_CLIENT_FUNC_UNDECORATE
;
1762 /* finally, the user can have requested no decorations, which overrides
1763 everything (but doesnt give it a border if it doesnt have one) */
1764 if (self
->undecorated
)
1765 self
->decorations
&= (config_theme_keepborder
?
1766 OB_FRAME_DECOR_BORDER
: 0);
1768 /* if we don't have a titlebar, then we cannot shade! */
1769 if (!(self
->decorations
& OB_FRAME_DECOR_TITLEBAR
))
1770 self
->functions
&= ~OB_CLIENT_FUNC_SHADE
;
1772 /* now we need to check against rules for the client's current state */
1773 if (self
->fullscreen
) {
1774 self
->functions
&= (OB_CLIENT_FUNC_CLOSE
|
1775 OB_CLIENT_FUNC_FULLSCREEN
|
1776 OB_CLIENT_FUNC_ICONIFY
);
1777 self
->decorations
= 0;
1780 client_change_allowed_actions(self
);
1783 /* force reconfigure to make sure decorations are updated */
1784 client_reconfigure(self
, TRUE
);
1787 static void client_change_allowed_actions(ObClient
*self
)
1792 /* desktop windows are kept on all desktops */
1793 if (self
->type
!= OB_CLIENT_TYPE_DESKTOP
)
1794 actions
[num
++] = OBT_PROP_ATOM(NET_WM_ACTION_CHANGE_DESKTOP
);
1796 if (self
->functions
& OB_CLIENT_FUNC_SHADE
)
1797 actions
[num
++] = OBT_PROP_ATOM(NET_WM_ACTION_SHADE
);
1798 if (self
->functions
& OB_CLIENT_FUNC_CLOSE
)
1799 actions
[num
++] = OBT_PROP_ATOM(NET_WM_ACTION_CLOSE
);
1800 if (self
->functions
& OB_CLIENT_FUNC_MOVE
)
1801 actions
[num
++] = OBT_PROP_ATOM(NET_WM_ACTION_MOVE
);
1802 if (self
->functions
& OB_CLIENT_FUNC_ICONIFY
)
1803 actions
[num
++] = OBT_PROP_ATOM(NET_WM_ACTION_MINIMIZE
);
1804 if (self
->functions
& OB_CLIENT_FUNC_RESIZE
)
1805 actions
[num
++] = OBT_PROP_ATOM(NET_WM_ACTION_RESIZE
);
1806 if (self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
)
1807 actions
[num
++] = OBT_PROP_ATOM(NET_WM_ACTION_FULLSCREEN
);
1808 if (self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) {
1809 actions
[num
++] = OBT_PROP_ATOM(NET_WM_ACTION_MAXIMIZE_HORZ
);
1810 actions
[num
++] = OBT_PROP_ATOM(NET_WM_ACTION_MAXIMIZE_VERT
);
1812 if (self
->functions
& OB_CLIENT_FUNC_ABOVE
)
1813 actions
[num
++] = OBT_PROP_ATOM(NET_WM_ACTION_ABOVE
);
1814 if (self
->functions
& OB_CLIENT_FUNC_BELOW
)
1815 actions
[num
++] = OBT_PROP_ATOM(NET_WM_ACTION_BELOW
);
1816 if (self
->functions
& OB_CLIENT_FUNC_UNDECORATE
)
1817 actions
[num
++] = OBT_PROP_ATOM(OB_WM_ACTION_UNDECORATE
);
1819 OBT_PROP_SETA32(self
->window
, NET_WM_ALLOWED_ACTIONS
, ATOM
, actions
, num
);
1821 /* make sure the window isn't breaking any rules now
1823 don't check ICONIFY here. just cuz a window can't iconify doesnt mean
1824 it can't be iconified with its parent
1827 if (!(self
->functions
& OB_CLIENT_FUNC_SHADE
) && self
->shaded
) {
1828 if (self
->frame
) client_shade(self
, FALSE
);
1829 else self
->shaded
= FALSE
;
1831 if (!(self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
) && self
->fullscreen
) {
1832 if (self
->frame
) client_fullscreen(self
, FALSE
);
1833 else self
->fullscreen
= FALSE
;
1835 if (!(self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) && (self
->max_horz
||
1837 if (self
->frame
) client_maximize(self
, FALSE
, 0);
1838 else self
->max_vert
= self
->max_horz
= FALSE
;
1842 void client_update_wmhints(ObClient
*self
)
1846 /* assume a window takes input if it doesn't specify */
1847 self
->can_focus
= TRUE
;
1849 if ((hints
= XGetWMHints(obt_display
, self
->window
)) != NULL
) {
1852 if (hints
->flags
& InputHint
)
1853 self
->can_focus
= hints
->input
;
1855 /* only do this when first managing the window *AND* when we aren't
1857 if (ob_state() != OB_STATE_STARTING
&& self
->frame
== NULL
)
1858 if (hints
->flags
& StateHint
)
1859 self
->iconic
= hints
->initial_state
== IconicState
;
1862 self
->urgent
= (hints
->flags
& XUrgencyHint
);
1863 if (self
->urgent
&& !ur
)
1864 client_hilite(self
, TRUE
);
1865 else if (!self
->urgent
&& ur
&& self
->demands_attention
)
1866 client_hilite(self
, FALSE
);
1868 if (!(hints
->flags
& WindowGroupHint
))
1869 hints
->window_group
= None
;
1871 /* did the group state change? */
1872 if (hints
->window_group
!=
1873 (self
->group
? self
->group
->leader
: None
))
1875 ObGroup
*oldgroup
= self
->group
;
1877 /* remove from the old group if there was one */
1879 group_remove(self
->group
, self
);
1883 /* add ourself to the group if we have one */
1884 if (hints
->window_group
!= None
) {
1885 self
->group
= group_add(hints
->window_group
, self
);
1888 /* Put ourselves into the new group's transient tree, and remove
1889 ourselves from the old group's */
1890 client_update_transient_tree(self
, oldgroup
, self
->group
,
1891 self
->transient_for_group
,
1892 self
->transient_for_group
,
1893 client_direct_parent(self
),
1894 client_direct_parent(self
));
1896 /* Lastly, being in a group, or not, can change if the window is
1897 transient for anything.
1899 The logic for this is:
1900 self->transient = TRUE always if the window wants to be
1901 transient for something, even if transient_for was NULL because
1902 it wasn't in a group before.
1904 If parents was NULL and oldgroup was NULL we can assume
1905 that when we add the new group, it will become transient for
1908 If transient_for_group is TRUE, then it must have already
1909 had a group. If it is getting a new group, the above call to
1910 client_update_transient_tree has already taken care of
1911 everything ! If it is losing all group status then it will
1912 no longer be transient for anything and that needs to be
1915 if (self
->transient
&&
1916 ((self
->parents
== NULL
&& oldgroup
== NULL
) ||
1917 (self
->transient_for_group
&& !self
->group
)))
1918 client_update_transient_for(self
);
1921 /* the WM_HINTS can contain an icon */
1922 if (hints
->flags
& IconPixmapHint
)
1923 client_update_icons(self
);
1928 focus_cycle_addremove(self
, TRUE
);
1931 void client_update_title(ObClient
*self
)
1934 gchar
*visible
= NULL
;
1936 g_free(self
->title
);
1937 g_free(self
->original_title
);
1940 if (!OBT_PROP_GETS(self
->window
, NET_WM_NAME
, utf8
, &data
)) {
1941 /* try old x stuff */
1942 if (!(OBT_PROP_GETS(self
->window
, WM_NAME
, locale
, &data
)
1943 || OBT_PROP_GETS(self
->window
, WM_NAME
, utf8
, &data
))) {
1944 if (self
->transient
) {
1946 GNOME alert windows are not given titles:
1947 http://developer.gnome.org/projects/gup/hig/draft_hig_new/windows-alert.html
1949 data
= g_strdup("");
1951 data
= g_strdup(_("Unnamed Window"));
1954 self
->original_title
= g_strdup(data
);
1956 if (self
->client_machine
) {
1957 visible
= g_strdup_printf("%s (%s)", data
, self
->client_machine
);
1962 if (self
->not_responding
) {
1964 if (self
->kill_level
> 0)
1965 visible
= g_strdup_printf("%s - [%s]", data
, _("Killing..."));
1967 visible
= g_strdup_printf("%s - [%s]", data
, _("Not Responding"));
1971 OBT_PROP_SETS(self
->window
, NET_WM_VISIBLE_NAME
, utf8
, visible
);
1972 self
->title
= visible
;
1975 frame_adjust_title(self
->frame
);
1977 /* update the icon title */
1979 g_free(self
->icon_title
);
1982 if (!OBT_PROP_GETS(self
->window
, NET_WM_ICON_NAME
, utf8
, &data
))
1983 /* try old x stuff */
1984 if (!(OBT_PROP_GETS(self
->window
, WM_ICON_NAME
, locale
, &data
) ||
1985 OBT_PROP_GETS(self
->window
, WM_ICON_NAME
, utf8
, &data
)))
1986 data
= g_strdup(self
->title
);
1988 if (self
->client_machine
) {
1989 visible
= g_strdup_printf("%s (%s)", data
, self
->client_machine
);
1994 if (self
->not_responding
) {
1996 if (self
->kill_level
> 0)
1997 visible
= g_strdup_printf("%s - [%s]", data
, _("Killing..."));
1999 visible
= g_strdup_printf("%s - [%s]", data
, _("Not Responding"));
2003 OBT_PROP_SETS(self
->window
, NET_WM_VISIBLE_ICON_NAME
, utf8
, visible
);
2004 self
->icon_title
= visible
;
2007 void client_update_strut(ObClient
*self
)
2011 gboolean got
= FALSE
;
2014 if (OBT_PROP_GETA32(self
->window
, NET_WM_STRUT_PARTIAL
, CARDINAL
,
2019 STRUT_PARTIAL_SET(strut
,
2020 data
[0], data
[2], data
[1], data
[3],
2021 data
[4], data
[5], data
[8], data
[9],
2022 data
[6], data
[7], data
[10], data
[11]);
2028 OBT_PROP_GETA32(self
->window
, NET_WM_STRUT
, CARDINAL
, &data
, &num
)) {
2034 /* use the screen's width/height */
2035 a
= screen_physical_area_all_monitors();
2037 STRUT_PARTIAL_SET(strut
,
2038 data
[0], data
[2], data
[1], data
[3],
2039 a
->y
, a
->y
+ a
->height
- 1,
2040 a
->x
, a
->x
+ a
->width
- 1,
2041 a
->y
, a
->y
+ a
->height
- 1,
2042 a
->x
, a
->x
+ a
->width
- 1);
2049 STRUT_PARTIAL_SET(strut
, 0, 0, 0, 0,
2050 0, 0, 0, 0, 0, 0, 0, 0);
2052 if (!PARTIAL_STRUT_EQUAL(strut
, self
->strut
)) {
2053 self
->strut
= strut
;
2055 /* updating here is pointless while we're being mapped cuz we're not in
2056 the client list yet */
2058 screen_update_areas();
2062 void client_update_icons(ObClient
*self
)
2067 guint num_seen
; /* number of icons present */
2072 /* grab the server, because we might be setting the window's icon and
2073 we don't want them to set it in between and we overwrite their own
2077 if (OBT_PROP_GETA32(self
->window
, NET_WM_ICON
, CARDINAL
, &data
, &num
)) {
2078 /* figure out how many valid icons are in here */
2081 while (i
+ 2 < num
) { /* +2 is to make sure there is a w and h */
2084 /* watch for the data being too small for the specified size,
2085 or for zero sized icons. */
2086 if (i
+ w
*h
> num
|| w
== 0 || h
== 0) break;
2088 /* convert it to the right bit order for ObRender */
2089 for (j
= 0; j
< w
*h
; ++j
)
2091 (((data
[i
+j
] >> 24) & 0xff) << RrDefaultAlphaOffset
) +
2092 (((data
[i
+j
] >> 16) & 0xff) << RrDefaultRedOffset
) +
2093 (((data
[i
+j
] >> 8) & 0xff) << RrDefaultGreenOffset
) +
2094 (((data
[i
+j
] >> 0) & 0xff) << RrDefaultBlueOffset
);
2096 /* is it in the cache? */
2097 img
= RrImageCacheFind(ob_rr_icons
, &data
[i
], w
, h
);
2098 if (img
) RrImageRef(img
); /* own it */
2103 /* don't bother looping anymore if we already found it in the cache
2104 since we'll just use that! */
2108 /* if it's not in the cache yet, then add it to the cache now.
2109 we have already converted it to the correct bit order above */
2110 if (!img
&& num_seen
> 0) {
2111 img
= RrImageNew(ob_rr_icons
);
2113 for (j
= 0; j
< num_seen
; ++j
) {
2116 RrImageAddPicture(img
, &data
[i
], w
, h
);
2124 /* if we didn't find an image from the NET_WM_ICON stuff, then try the
2129 if ((hints
= XGetWMHints(obt_display
, self
->window
))) {
2130 if (hints
->flags
& IconPixmapHint
) {
2132 obt_display_ignore_errors(TRUE
);
2133 xicon
= RrPixmapToRGBA(ob_rr_inst
,
2135 (hints
->flags
& IconMaskHint
?
2136 hints
->icon_mask
: None
),
2137 (gint
*)&w
, (gint
*)&h
, &data
);
2138 obt_display_ignore_errors(FALSE
);
2141 if (w
> 0 && h
> 0) {
2142 /* is this icon in the cache yet? */
2143 img
= RrImageCacheFind(ob_rr_icons
, data
, w
, h
);
2144 if (img
) RrImageRef(img
); /* own it */
2146 /* if not, then add it */
2148 img
= RrImageNew(ob_rr_icons
);
2149 RrImageAddPicture(img
, data
, w
, h
);
2160 /* set the client's icons to be whatever we found */
2161 RrImageUnref(self
->icon_set
);
2162 self
->icon_set
= img
;
2164 /* if the client has no icon at all, then we set a default icon onto it.
2165 but, if it has parents, then one of them will have an icon already
2167 if (!self
->icon_set
&& !self
->parents
) {
2168 RrPixel32
*icon
= ob_rr_theme
->def_win_icon
;
2169 gulong
*ldata
; /* use a long here to satisfy OBT_PROP_SETA32 */
2171 w
= ob_rr_theme
->def_win_icon_w
;
2172 h
= ob_rr_theme
->def_win_icon_h
;
2173 ldata
= g_new(gulong
, w
*h
+2);
2176 for (i
= 0; i
< w
*h
; ++i
)
2177 ldata
[i
+2] = (((icon
[i
] >> RrDefaultAlphaOffset
) & 0xff) << 24) +
2178 (((icon
[i
] >> RrDefaultRedOffset
) & 0xff) << 16) +
2179 (((icon
[i
] >> RrDefaultGreenOffset
) & 0xff) << 8) +
2180 (((icon
[i
] >> RrDefaultBlueOffset
) & 0xff) << 0);
2181 OBT_PROP_SETA32(self
->window
, NET_WM_ICON
, CARDINAL
, ldata
, w
*h
+2);
2183 } else if (self
->frame
)
2184 /* don't draw the icon empty if we're just setting one now anyways,
2185 we'll get the property change any second */
2186 frame_adjust_icon(self
->frame
);
2191 void client_update_icon_geometry(ObClient
*self
)
2196 RECT_SET(self
->icon_geometry
, 0, 0, 0, 0);
2198 if (OBT_PROP_GETA32(self
->window
, NET_WM_ICON_GEOMETRY
, CARDINAL
,
2202 /* don't let them set it with an area < 0 */
2203 RECT_SET(self
->icon_geometry
, data
[0], data
[1],
2204 MAX(data
[2],0), MAX(data
[3],0));
2209 static void client_get_session_ids(ObClient
*self
)
2216 if (!OBT_PROP_GET32(self
->window
, WM_CLIENT_LEADER
, WINDOW
, &leader
))
2219 /* get the SM_CLIENT_ID */
2222 got
= OBT_PROP_GETS(leader
, SM_CLIENT_ID
, locale
, &self
->sm_client_id
);
2224 OBT_PROP_GETS(self
->window
, SM_CLIENT_ID
, locale
, &self
->sm_client_id
);
2226 /* get the WM_CLASS (name and class). make them "" if they are not
2230 got
= OBT_PROP_GETSS(leader
, WM_CLASS
, locale
, &ss
);
2232 got
= OBT_PROP_GETSS(self
->window
, WM_CLASS
, locale
, &ss
);
2236 self
->name
= g_strdup(ss
[0]);
2238 self
->class = g_strdup(ss
[1]);
2243 if (self
->name
== NULL
) self
->name
= g_strdup("");
2244 if (self
->class == NULL
) self
->class = g_strdup("");
2246 /* get the WM_WINDOW_ROLE. make it "" if it is not provided */
2249 got
= OBT_PROP_GETS(leader
, WM_WINDOW_ROLE
, locale
, &s
);
2251 got
= OBT_PROP_GETS(self
->window
, WM_WINDOW_ROLE
, locale
, &s
);
2256 self
->role
= g_strdup("");
2258 /* get the WM_COMMAND */
2262 got
= OBT_PROP_GETSS(leader
, WM_COMMAND
, locale
, &ss
);
2264 got
= OBT_PROP_GETSS(self
->window
, WM_COMMAND
, locale
, &ss
);
2267 /* merge/mash them all together */
2268 gchar
*merge
= NULL
;
2271 for (i
= 0; ss
[i
]; ++i
) {
2274 merge
= g_strconcat(merge
, ss
[i
], NULL
);
2276 merge
= g_strconcat(ss
[i
], NULL
);
2281 self
->wm_command
= merge
;
2284 /* get the WM_CLIENT_MACHINE */
2287 got
= OBT_PROP_GETS(leader
, WM_CLIENT_MACHINE
, locale
, &s
);
2289 got
= OBT_PROP_GETS(self
->window
, WM_CLIENT_MACHINE
, locale
, &s
);
2292 gchar localhost
[128];
2295 gethostname(localhost
, 127);
2296 localhost
[127] = '\0';
2297 if (strcmp(localhost
, s
) != 0)
2298 self
->client_machine
= s
;
2302 /* see if it has the PID set too (the PID requires that the
2303 WM_CLIENT_MACHINE be set) */
2304 if (OBT_PROP_GET32(self
->window
, NET_WM_PID
, CARDINAL
, &pid
))
2309 /*! Save the properties used for app matching rules, as seen by Openbox when
2310 the window mapped, so that users can still access them later if the app
2312 static void client_save_app_rule_values(ObClient
*self
)
2316 OBT_PROP_SETS(self
->window
, OB_APP_ROLE
, utf8
, self
->role
);
2317 OBT_PROP_SETS(self
->window
, OB_APP_NAME
, utf8
, self
->name
);
2318 OBT_PROP_SETS(self
->window
, OB_APP_CLASS
, utf8
, self
->class);
2319 OBT_PROP_SETS(self
->window
, OB_APP_TITLE
, utf8
, self
->original_title
);
2321 switch (self
->type
) {
2322 case OB_CLIENT_TYPE_NORMAL
:
2323 type
= "normal"; break;
2324 case OB_CLIENT_TYPE_DIALOG
:
2325 type
= "dialog"; break;
2326 case OB_CLIENT_TYPE_UTILITY
:
2327 type
= "utility"; break;
2328 case OB_CLIENT_TYPE_MENU
:
2329 type
= "menu"; break;
2330 case OB_CLIENT_TYPE_TOOLBAR
:
2331 type
= "toolbar"; break;
2332 case OB_CLIENT_TYPE_SPLASH
:
2333 type
= "splash"; break;
2334 case OB_CLIENT_TYPE_DESKTOP
:
2335 type
= "desktop"; break;
2336 case OB_CLIENT_TYPE_DOCK
:
2337 type
= "dock"; break;
2339 OBT_PROP_SETS(self
->window
, OB_APP_TYPE
, utf8
, type
);
2342 static void client_change_wm_state(ObClient
*self
)
2347 old
= self
->wmstate
;
2349 if (self
->shaded
|| self
->iconic
||
2350 (self
->desktop
!= DESKTOP_ALL
&& self
->desktop
!= screen_desktop
))
2352 self
->wmstate
= IconicState
;
2354 self
->wmstate
= NormalState
;
2356 if (old
!= self
->wmstate
) {
2357 OBT_PROP_MSG(ob_screen
, self
->window
, KDE_WM_CHANGE_STATE
,
2358 self
->wmstate
, 1, 0, 0, 0);
2360 state
[0] = self
->wmstate
;
2362 OBT_PROP_SETA32(self
->window
, WM_STATE
, WM_STATE
, state
, 2);
2366 static void client_change_state(ObClient
*self
)
2368 gulong netstate
[12];
2373 netstate
[num
++] = OBT_PROP_ATOM(NET_WM_STATE_MODAL
);
2375 netstate
[num
++] = OBT_PROP_ATOM(NET_WM_STATE_SHADED
);
2377 netstate
[num
++] = OBT_PROP_ATOM(NET_WM_STATE_HIDDEN
);
2378 if (self
->skip_taskbar
)
2379 netstate
[num
++] = OBT_PROP_ATOM(NET_WM_STATE_SKIP_TASKBAR
);
2380 if (self
->skip_pager
)
2381 netstate
[num
++] = OBT_PROP_ATOM(NET_WM_STATE_SKIP_PAGER
);
2382 if (self
->fullscreen
)
2383 netstate
[num
++] = OBT_PROP_ATOM(NET_WM_STATE_FULLSCREEN
);
2385 netstate
[num
++] = OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_VERT
);
2387 netstate
[num
++] = OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_HORZ
);
2389 netstate
[num
++] = OBT_PROP_ATOM(NET_WM_STATE_ABOVE
);
2391 netstate
[num
++] = OBT_PROP_ATOM(NET_WM_STATE_BELOW
);
2392 if (self
->demands_attention
)
2393 netstate
[num
++] = OBT_PROP_ATOM(NET_WM_STATE_DEMANDS_ATTENTION
);
2394 if (self
->undecorated
)
2395 netstate
[num
++] = OBT_PROP_ATOM(OB_WM_STATE_UNDECORATED
);
2396 OBT_PROP_SETA32(self
->window
, NET_WM_STATE
, ATOM
, netstate
, num
);
2399 frame_adjust_state(self
->frame
);
2402 ObClient
*client_search_focus_tree(ObClient
*self
)
2407 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
2408 if (client_focused(it
->data
)) return it
->data
;
2409 if ((ret
= client_search_focus_tree(it
->data
))) return ret
;
2414 ObClient
*client_search_focus_tree_full(ObClient
*self
)
2416 if (self
->parents
) {
2419 for (it
= self
->parents
; it
; it
= g_slist_next(it
)) {
2420 ObClient
*c
= it
->data
;
2421 if ((c
= client_search_focus_tree_full(c
))) return c
;
2427 /* this function checks the whole tree, the client_search_focus_tree
2428 does not, so we need to check this window */
2429 if (client_focused(self
))
2431 return client_search_focus_tree(self
);
2435 ObClient
*client_search_focus_group_full(ObClient
*self
)
2440 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
2441 ObClient
*c
= it
->data
;
2443 if (client_focused(c
)) return c
;
2444 if ((c
= client_search_focus_tree(it
->data
))) return c
;
2447 if (client_focused(self
)) return self
;
2451 gboolean
client_has_parent(ObClient
*self
)
2453 return self
->parents
!= NULL
;
2456 static ObStackingLayer
calc_layer(ObClient
*self
)
2461 monitor
= screen_physical_area_monitor(client_monitor(self
));
2463 if (self
->type
== OB_CLIENT_TYPE_DESKTOP
)
2464 l
= OB_STACKING_LAYER_DESKTOP
;
2465 else if (self
->type
== OB_CLIENT_TYPE_DOCK
) {
2466 if (self
->below
) l
= OB_STACKING_LAYER_NORMAL
;
2467 else l
= OB_STACKING_LAYER_ABOVE
;
2469 else if ((self
->fullscreen
||
2470 /* No decorations and fills the monitor = oldskool fullscreen.
2471 But not for maximized windows.
2473 (self
->decorations
== 0 &&
2474 !(self
->max_horz
&& self
->max_vert
) &&
2475 RECT_EQUAL(self
->area
, *monitor
))) &&
2476 /* you are fullscreen while you or your children are focused.. */
2477 (client_focused(self
) || client_search_focus_tree(self
) ||
2478 /* you can be fullscreen if you're on another desktop */
2479 (self
->desktop
!= screen_desktop
&&
2480 self
->desktop
!= DESKTOP_ALL
) ||
2481 /* and you can also be fullscreen if the focused client is on
2482 another monitor, or nothing else is focused */
2484 client_monitor(focus_client
) != client_monitor(self
))))
2485 l
= OB_STACKING_LAYER_FULLSCREEN
;
2486 else if (self
->above
) l
= OB_STACKING_LAYER_ABOVE
;
2487 else if (self
->below
) l
= OB_STACKING_LAYER_BELOW
;
2488 else l
= OB_STACKING_LAYER_NORMAL
;
2495 static void client_calc_layer_recursive(ObClient
*self
, ObClient
*orig
,
2496 ObStackingLayer min
)
2498 ObStackingLayer old
, own
;
2502 own
= calc_layer(self
);
2503 self
->layer
= MAX(own
, min
);
2505 if (self
->layer
!= old
) {
2506 stacking_remove(CLIENT_AS_WINDOW(self
));
2507 stacking_add_nonintrusive(CLIENT_AS_WINDOW(self
));
2510 /* we've been restacked */
2511 self
->visited
= TRUE
;
2513 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
2514 client_calc_layer_recursive(it
->data
, orig
,
2518 static void client_calc_layer_internal(ObClient
*self
)
2522 /* transients take on the layer of their parents */
2523 sit
= client_search_all_top_parents(self
);
2525 for (; sit
; sit
= g_slist_next(sit
))
2526 client_calc_layer_recursive(sit
->data
, self
, 0);
2529 void client_calc_layer(ObClient
*self
)
2533 /* skip over stuff above fullscreen layer */
2534 for (it
= stacking_list
; it
; it
= g_list_next(it
))
2535 if (window_layer(it
->data
) <= OB_STACKING_LAYER_FULLSCREEN
) break;
2537 /* find the windows in the fullscreen layer, and mark them not-visited */
2538 for (; it
; it
= g_list_next(it
)) {
2539 if (window_layer(it
->data
) < OB_STACKING_LAYER_FULLSCREEN
) break;
2540 else if (WINDOW_IS_CLIENT(it
->data
))
2541 WINDOW_AS_CLIENT(it
->data
)->visited
= FALSE
;
2544 client_calc_layer_internal(self
);
2546 /* skip over stuff above fullscreen layer */
2547 for (it
= stacking_list
; it
; it
= g_list_next(it
))
2548 if (window_layer(it
->data
) <= OB_STACKING_LAYER_FULLSCREEN
) break;
2550 /* now recalc any windows in the fullscreen layer which have not
2551 had their layer recalced already */
2552 for (; it
; it
= g_list_next(it
)) {
2553 if (window_layer(it
->data
) < OB_STACKING_LAYER_FULLSCREEN
) break;
2554 else if (WINDOW_IS_CLIENT(it
->data
) &&
2555 !WINDOW_AS_CLIENT(it
->data
)->visited
)
2556 client_calc_layer_internal(it
->data
);
2560 gboolean
client_should_show(ObClient
*self
)
2564 if (client_normal(self
) && screen_showing_desktop
)
2566 if (self
->desktop
== screen_desktop
|| self
->desktop
== DESKTOP_ALL
)
2572 gboolean
client_show(ObClient
*self
)
2574 gboolean show
= FALSE
;
2576 if (client_should_show(self
)) {
2577 /* replay pending pointer event before showing the window, in case it
2578 should be going to something under the window */
2579 mouse_replay_pointer();
2581 frame_show(self
->frame
);
2584 /* According to the ICCCM (sec 4.1.3.1) when a window is not visible,
2585 it needs to be in IconicState. This includes when it is on another
2588 client_change_wm_state(self
);
2593 gboolean
client_hide(ObClient
*self
)
2595 gboolean hide
= FALSE
;
2597 if (!client_should_show(self
)) {
2598 /* We don't need to ignore enter events here.
2599 The window can hide/iconify in 3 different ways:
2600 1 - through an x message. in this case we ignore all enter events
2601 caused by responding to the x message (unless underMouse)
2602 2 - by a keyboard action. in this case we ignore all enter events
2603 caused by the action
2604 3 - by a mouse action. in this case they are doing stuff with the
2605 mouse and focus _should_ move.
2607 Also in action_end, we simulate an enter event that can't be ignored
2608 so trying to ignore them is futile in case 3 anyways
2611 /* replay pending pointer event before hiding the window, in case it
2612 should be going to the window */
2613 mouse_replay_pointer();
2615 frame_hide(self
->frame
);
2618 /* According to the ICCCM (sec 4.1.3.1) when a window is not visible,
2619 it needs to be in IconicState. This includes when it is on another
2622 client_change_wm_state(self
);
2627 void client_showhide(ObClient
*self
)
2629 if (!client_show(self
))
2633 gboolean
client_normal(ObClient
*self
) {
2634 return ! (self
->type
== OB_CLIENT_TYPE_DESKTOP
||
2635 self
->type
== OB_CLIENT_TYPE_DOCK
||
2636 self
->type
== OB_CLIENT_TYPE_SPLASH
);
2639 gboolean
client_helper(ObClient
*self
)
2641 return (self
->type
== OB_CLIENT_TYPE_UTILITY
||
2642 self
->type
== OB_CLIENT_TYPE_MENU
||
2643 self
->type
== OB_CLIENT_TYPE_TOOLBAR
);
2646 gboolean
client_mouse_focusable(ObClient
*self
)
2648 return !(self
->type
== OB_CLIENT_TYPE_MENU
||
2649 self
->type
== OB_CLIENT_TYPE_TOOLBAR
||
2650 self
->type
== OB_CLIENT_TYPE_SPLASH
||
2651 self
->type
== OB_CLIENT_TYPE_DOCK
);
2654 gboolean
client_enter_focusable(ObClient
*self
)
2656 /* you can focus desktops but it shouldn't on enter */
2657 return (client_mouse_focusable(self
) &&
2658 self
->type
!= OB_CLIENT_TYPE_DESKTOP
);
2661 static void client_apply_startup_state(ObClient
*self
,
2662 gint x
, gint y
, gint w
, gint h
)
2664 /* save the states that we are going to apply */
2665 gboolean iconic
= self
->iconic
;
2666 gboolean fullscreen
= self
->fullscreen
;
2667 gboolean undecorated
= self
->undecorated
;
2668 gboolean shaded
= self
->shaded
;
2669 gboolean demands_attention
= self
->demands_attention
;
2670 gboolean max_horz
= self
->max_horz
;
2671 gboolean max_vert
= self
->max_vert
;
2675 /* turn them all off in the client, so they won't affect the window
2677 self
->iconic
= self
->fullscreen
= self
->undecorated
= self
->shaded
=
2678 self
->demands_attention
= self
->max_horz
= self
->max_vert
= FALSE
;
2680 /* move the client to its placed position, or it it's already there,
2681 generate a ConfigureNotify telling the client where it is.
2683 do this after adjusting the frame. otherwise it gets all weird and
2684 clients don't work right
2686 do this before applying the states so they have the correct
2687 pre-max/pre-fullscreen values
2689 client_try_configure(self
, &x
, &y
, &w
, &h
, &l
, &l
, FALSE
);
2690 ob_debug("placed window 0x%x at %d, %d with size %d x %d",
2691 self
->window
, x
, y
, w
, h
);
2692 /* save the area, and make it where it should be for the premax stuff */
2693 oldarea
= self
->area
;
2694 RECT_SET(self
->area
, x
, y
, w
, h
);
2696 /* apply the states. these are in a carefully crafted order.. */
2699 client_iconify(self
, TRUE
, FALSE
, TRUE
);
2701 client_fullscreen(self
, TRUE
);
2703 client_set_undecorated(self
, TRUE
);
2705 client_shade(self
, TRUE
);
2706 if (demands_attention
)
2707 client_hilite(self
, TRUE
);
2709 if (max_vert
&& max_horz
)
2710 client_maximize(self
, TRUE
, 0);
2712 client_maximize(self
, TRUE
, 2);
2714 client_maximize(self
, TRUE
, 1);
2716 /* if the window hasn't been configured yet, then do so now, in fact the
2717 x,y,w,h may _not_ be the same as the area rect, which can end up
2718 meaning that the client isn't properly moved/resized by the fullscreen
2720 pho can cause this because it maps at size of the screen but not 0,0
2721 so openbox moves it on screen to 0,0 (thus x,y=0,0 and area.x,y don't).
2722 then fullscreen'ing makes it go to 0,0 which it thinks it already is at
2723 cuz thats where the pre-fullscreen will be. however the actual area is
2724 not, so this needs to be called even if we have fullscreened/maxed
2726 self
->area
= oldarea
;
2727 client_configure(self
, x
, y
, w
, h
, FALSE
, TRUE
, FALSE
);
2729 /* set the desktop hint, to make sure that it always exists */
2730 OBT_PROP_SET32(self
->window
, NET_WM_DESKTOP
, CARDINAL
, self
->desktop
);
2732 /* nothing to do for the other states:
2741 void client_gravity_resize_w(ObClient
*self
, gint
*x
, gint oldw
, gint neww
)
2743 /* these should be the current values. this is for when you're not moving,
2745 g_assert(*x
== self
->area
.x
);
2746 g_assert(oldw
== self
->area
.width
);
2749 switch (self
->gravity
) {
2751 case NorthWestGravity
:
2753 case SouthWestGravity
:
2760 *x
-= (neww
- oldw
) / 2;
2762 case NorthEastGravity
:
2764 case SouthEastGravity
:
2770 void client_gravity_resize_h(ObClient
*self
, gint
*y
, gint oldh
, gint newh
)
2772 /* these should be the current values. this is for when you're not moving,
2774 g_assert(*y
== self
->area
.y
);
2775 g_assert(oldh
== self
->area
.height
);
2778 switch (self
->gravity
) {
2780 case NorthWestGravity
:
2782 case NorthEastGravity
:
2789 *y
-= (newh
- oldh
) / 2;
2791 case SouthWestGravity
:
2793 case SouthEastGravity
:
2799 void client_try_configure(ObClient
*self
, gint
*x
, gint
*y
, gint
*w
, gint
*h
,
2800 gint
*logicalw
, gint
*logicalh
,
2803 Rect desired
= {*x
, *y
, *w
, *h
};
2804 frame_rect_to_frame(self
->frame
, &desired
);
2806 /* make the frame recalculate its dimensions n shit without changing
2807 anything visible for real, this way the constraints below can work with
2808 the updated frame dimensions. */
2809 frame_adjust_area(self
->frame
, FALSE
, TRUE
, TRUE
);
2811 /* gets the frame's position */
2812 frame_client_gravity(self
->frame
, x
, y
);
2814 /* these positions are frame positions, not client positions */
2816 /* set the size and position if fullscreen */
2817 if (self
->fullscreen
) {
2821 i
= screen_find_monitor(&desired
);
2822 a
= screen_physical_area_monitor(i
);
2829 user
= FALSE
; /* ignore if the client can't be moved/resized when it
2833 } else if (self
->max_horz
|| self
->max_vert
) {
2837 /* use all possible struts when maximizing to the full screen */
2838 i
= screen_find_monitor(&desired
);
2839 a
= screen_area(self
->desktop
, i
,
2840 (self
->max_horz
&& self
->max_vert
? NULL
: &desired
));
2842 /* set the size and position if maximized */
2843 if (self
->max_horz
) {
2845 *w
= a
->width
- self
->frame
->size
.left
- self
->frame
->size
.right
;
2847 if (self
->max_vert
) {
2849 *h
= a
->height
- self
->frame
->size
.top
- self
->frame
->size
.bottom
;
2852 user
= FALSE
; /* ignore if the client can't be moved/resized when it
2858 /* gets the client's position */
2859 frame_frame_gravity(self
->frame
, x
, y
);
2861 /* work within the preferred sizes given by the window, these may have
2862 changed rather than it's requested width and height, so always run
2863 through this code */
2865 gint basew
, baseh
, minw
, minh
;
2867 gfloat minratio
, maxratio
;
2869 incw
= self
->fullscreen
|| self
->max_horz
? 1 : self
->size_inc
.width
;
2870 inch
= self
->fullscreen
|| self
->max_vert
? 1 : self
->size_inc
.height
;
2871 minratio
= self
->fullscreen
|| (self
->max_horz
&& self
->max_vert
) ?
2872 0 : self
->min_ratio
;
2873 maxratio
= self
->fullscreen
|| (self
->max_horz
&& self
->max_vert
) ?
2874 0 : self
->max_ratio
;
2876 /* base size is substituted with min size if not specified */
2877 if (self
->base_size
.width
>= 0 || self
->base_size
.height
>= 0) {
2878 basew
= self
->base_size
.width
;
2879 baseh
= self
->base_size
.height
;
2881 basew
= self
->min_size
.width
;
2882 baseh
= self
->min_size
.height
;
2884 /* min size is substituted with base size if not specified */
2885 if (self
->min_size
.width
|| self
->min_size
.height
) {
2886 minw
= self
->min_size
.width
;
2887 minh
= self
->min_size
.height
;
2889 minw
= self
->base_size
.width
;
2890 minh
= self
->base_size
.height
;
2893 /* This comment is no longer true */
2894 /* if this is a user-requested resize, then check against min/max
2897 /* smaller than min size or bigger than max size? */
2898 if (*w
> self
->max_size
.width
) *w
= self
->max_size
.width
;
2899 if (*w
< minw
) *w
= minw
;
2900 if (*h
> self
->max_size
.height
) *h
= self
->max_size
.height
;
2901 if (*h
< minh
) *h
= minh
;
2906 /* keep to the increments */
2910 /* you cannot resize to nothing */
2911 if (basew
+ *w
< 1) *w
= 1 - basew
;
2912 if (baseh
+ *h
< 1) *h
= 1 - baseh
;
2914 /* save the logical size */
2915 *logicalw
= incw
> 1 ? *w
: *w
+ basew
;
2916 *logicalh
= inch
> 1 ? *h
: *h
+ baseh
;
2924 /* adjust the height to match the width for the aspect ratios.
2925 for this, min size is not substituted for base size ever. */
2926 *w
-= self
->base_size
.width
;
2927 *h
-= self
->base_size
.height
;
2930 if (*h
* minratio
> *w
) {
2931 *h
= (gint
)(*w
/ minratio
);
2933 /* you cannot resize to nothing */
2936 *w
= (gint
)(*h
* minratio
);
2940 if (*h
* maxratio
< *w
) {
2941 *h
= (gint
)(*w
/ maxratio
);
2943 /* you cannot resize to nothing */
2946 *w
= (gint
)(*h
* minratio
);
2950 *w
+= self
->base_size
.width
;
2951 *h
+= self
->base_size
.height
;
2954 /* these override the above states! if you cant move you can't move! */
2956 if (!(self
->functions
& OB_CLIENT_FUNC_MOVE
)) {
2960 if (!(self
->functions
& OB_CLIENT_FUNC_RESIZE
)) {
2961 *w
= self
->area
.width
;
2962 *h
= self
->area
.height
;
2970 void client_configure(ObClient
*self
, gint x
, gint y
, gint w
, gint h
,
2971 gboolean user
, gboolean final
, gboolean force_reply
)
2975 gboolean send_resize_client
;
2976 gboolean moved
= FALSE
, resized
= FALSE
, rootmoved
= FALSE
;
2977 gboolean fmoved
, fresized
;
2978 guint fdecor
= self
->frame
->decorations
;
2979 gboolean fhorz
= self
->frame
->max_horz
;
2980 gboolean fvert
= self
->frame
->max_vert
;
2981 gint logicalw
, logicalh
;
2983 /* find the new x, y, width, and height (and logical size) */
2984 client_try_configure(self
, &x
, &y
, &w
, &h
, &logicalw
, &logicalh
, user
);
2986 /* set the logical size if things changed */
2987 if (!(w
== self
->area
.width
&& h
== self
->area
.height
))
2988 SIZE_SET(self
->logical_size
, logicalw
, logicalh
);
2990 /* figure out if we moved or resized or what */
2991 moved
= (x
!= self
->area
.x
|| y
!= self
->area
.y
);
2992 resized
= (w
!= self
->area
.width
|| h
!= self
->area
.height
);
2994 oldw
= self
->area
.width
;
2995 oldh
= self
->area
.height
;
2996 oldframe
= self
->frame
->area
;
2997 RECT_SET(self
->area
, x
, y
, w
, h
);
2999 /* for app-requested resizes, always resize if 'resized' is true.
3000 for user-requested ones, only resize if final is true, or when
3001 resizing in redraw mode */
3002 send_resize_client
= ((!user
&& resized
) ||
3004 (resized
&& config_resize_redraw
))));
3006 /* if the client is enlarging, then resize the client before the frame */
3007 if (send_resize_client
&& (w
> oldw
|| h
> oldh
)) {
3008 XMoveResizeWindow(obt_display
, self
->window
,
3009 self
->frame
->size
.left
, self
->frame
->size
.top
,
3010 MAX(w
, oldw
), MAX(h
, oldh
));
3011 frame_adjust_client_area(self
->frame
);
3014 /* find the frame's dimensions and move/resize it */
3018 /* if decorations changed, then readjust everything for the frame */
3019 if (self
->decorations
!= fdecor
||
3020 self
->max_horz
!= fhorz
|| self
->max_vert
!= fvert
)
3022 fmoved
= fresized
= TRUE
;
3025 /* adjust the frame */
3026 if (fmoved
|| fresized
) {
3027 gulong ignore_start
;
3029 ignore_start
= event_start_ignore_all_enters();
3031 /* replay pending pointer event before move the window, in case it
3032 would change what window gets the event */
3033 mouse_replay_pointer();
3035 frame_adjust_area(self
->frame
, fmoved
, fresized
, FALSE
);
3038 event_end_ignore_all_enters(ignore_start
);
3041 if (!user
|| final
) {
3042 gint oldrx
= self
->root_pos
.x
;
3043 gint oldry
= self
->root_pos
.y
;
3044 /* we have reset the client to 0 border width, so don't include
3045 it in these coords */
3046 POINT_SET(self
->root_pos
,
3047 self
->frame
->area
.x
+ self
->frame
->size
.left
-
3049 self
->frame
->area
.y
+ self
->frame
->size
.top
-
3050 self
->border_width
);
3051 if (self
->root_pos
.x
!= oldrx
|| self
->root_pos
.y
!= oldry
)
3055 /* This is kinda tricky and should not be changed.. let me explain!
3057 When user = FALSE, then the request is coming from the application
3058 itself, and we are more strict about when to send a synthetic
3059 ConfigureNotify. We strictly follow the rules of the ICCCM sec 4.1.5
3060 in this case (if force_reply is true)
3062 When user = TRUE, then the request is coming from "us", like when we
3063 maximize a window or something. In this case we are more lenient. We
3064 used to follow the same rules as above, but _Java_ Swing can't handle
3065 this. So just to appease Swing, when user = TRUE, we always send
3066 a synthetic ConfigureNotify to give the window its root coordinates.
3068 if ((!user
&& !resized
&& (rootmoved
|| force_reply
)) ||
3069 (user
&& final
&& rootmoved
))
3073 event
.type
= ConfigureNotify
;
3074 event
.xconfigure
.display
= obt_display
;
3075 event
.xconfigure
.event
= self
->window
;
3076 event
.xconfigure
.window
= self
->window
;
3078 ob_debug("Sending ConfigureNotify to %s for %d,%d %dx%d",
3079 self
->title
, self
->root_pos
.x
, self
->root_pos
.y
, w
, h
);
3081 /* root window real coords */
3082 event
.xconfigure
.x
= self
->root_pos
.x
;
3083 event
.xconfigure
.y
= self
->root_pos
.y
;
3084 event
.xconfigure
.width
= w
;
3085 event
.xconfigure
.height
= h
;
3086 event
.xconfigure
.border_width
= self
->border_width
;
3087 event
.xconfigure
.above
= None
;
3088 event
.xconfigure
.override_redirect
= FALSE
;
3089 XSendEvent(event
.xconfigure
.display
, event
.xconfigure
.window
,
3090 FALSE
, StructureNotifyMask
, &event
);
3093 /* if the client is shrinking, then resize the frame before the client.
3095 both of these resize sections may run, because the top one only resizes
3096 in the direction that is growing
3098 if (send_resize_client
&& (w
<= oldw
|| h
<= oldh
)) {
3099 frame_adjust_client_area(self
->frame
);
3100 XMoveResizeWindow(obt_display
, self
->window
,
3101 self
->frame
->size
.left
, self
->frame
->size
.top
, w
, h
);
3104 XFlush(obt_display
);
3106 /* if it moved between monitors, then this can affect the stacking
3107 layer of this window or others - for fullscreen windows */
3108 if (screen_find_monitor(&self
->frame
->area
) !=
3109 screen_find_monitor(&oldframe
))
3111 client_calc_layer(self
);
3115 void client_fullscreen(ObClient
*self
, gboolean fs
)
3119 if (!(self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
) || /* can't */
3120 self
->fullscreen
== fs
) return; /* already done */
3122 self
->fullscreen
= fs
;
3123 client_change_state(self
); /* change the state hints on the client */
3126 self
->pre_fullscreen_area
= self
->area
;
3127 /* if the window is maximized, its area isn't all that meaningful.
3128 save its premax area instead. */
3129 if (self
->max_horz
) {
3130 self
->pre_fullscreen_area
.x
= self
->pre_max_area
.x
;
3131 self
->pre_fullscreen_area
.width
= self
->pre_max_area
.width
;
3133 if (self
->max_vert
) {
3134 self
->pre_fullscreen_area
.y
= self
->pre_max_area
.y
;
3135 self
->pre_fullscreen_area
.height
= self
->pre_max_area
.height
;
3138 /* these will help configure_full figure out where to fullscreen
3142 w
= self
->area
.width
;
3143 h
= self
->area
.height
;
3145 g_assert(self
->pre_fullscreen_area
.width
> 0 &&
3146 self
->pre_fullscreen_area
.height
> 0);
3148 x
= self
->pre_fullscreen_area
.x
;
3149 y
= self
->pre_fullscreen_area
.y
;
3150 w
= self
->pre_fullscreen_area
.width
;
3151 h
= self
->pre_fullscreen_area
.height
;
3152 RECT_SET(self
->pre_fullscreen_area
, 0, 0, 0, 0);
3155 ob_debug("Window %s going fullscreen (%d)",
3156 self
->title
, self
->fullscreen
);
3158 client_setup_decor_and_functions(self
, FALSE
);
3159 client_move_resize(self
, x
, y
, w
, h
);
3161 /* and adjust our layer/stacking. do this after resizing the window,
3162 and applying decorations, because windows which fill the screen are
3163 considered "fullscreen" and it affects their layer */
3164 client_calc_layer(self
);
3167 /* try focus us when we go into fullscreen mode */
3172 static void client_iconify_recursive(ObClient
*self
,
3173 gboolean iconic
, gboolean curdesk
,
3174 gboolean hide_animation
)
3177 gboolean changed
= FALSE
;
3179 if (self
->iconic
!= iconic
) {
3180 ob_debug("%sconifying window: 0x%lx", (iconic
? "I" : "Uni"),
3184 /* don't let non-normal windows iconify along with their parents
3186 if (client_normal(self
)) {
3187 self
->iconic
= iconic
;
3189 /* update the focus lists.. iconic windows go to the bottom of
3190 the list. this will also call focus_cycle_addremove(). */
3191 focus_order_to_bottom(self
);
3196 self
->iconic
= iconic
;
3198 if (curdesk
&& self
->desktop
!= screen_desktop
&&
3199 self
->desktop
!= DESKTOP_ALL
)
3200 client_set_desktop(self
, screen_desktop
, FALSE
, FALSE
);
3202 /* this puts it after the current focused window, this will
3203 also cause focus_cycle_addremove() to be called for the
3205 focus_order_like_new(self
);
3212 client_change_state(self
);
3213 if (config_animate_iconify
&& !hide_animation
)
3214 frame_begin_iconify_animation(self
->frame
, iconic
);
3215 /* do this after starting the animation so it doesn't flash */
3216 client_showhide(self
);
3219 /* iconify all direct transients, and deiconify all transients
3221 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
3222 if (it
->data
!= self
)
3223 if (client_is_direct_child(self
, it
->data
) || !iconic
)
3224 client_iconify_recursive(it
->data
, iconic
, curdesk
,
3228 void client_iconify(ObClient
*self
, gboolean iconic
, gboolean curdesk
,
3229 gboolean hide_animation
)
3231 if (self
->functions
& OB_CLIENT_FUNC_ICONIFY
|| !iconic
) {
3232 /* move up the transient chain as far as possible first */
3233 self
= client_search_top_direct_parent(self
);
3234 client_iconify_recursive(self
, iconic
, curdesk
, hide_animation
);
3238 void client_maximize(ObClient
*self
, gboolean max
, gint dir
)
3242 g_assert(dir
== 0 || dir
== 1 || dir
== 2);
3243 if (!(self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) && max
) return;/* can't */
3245 /* check if already done */
3247 if (dir
== 0 && self
->max_horz
&& self
->max_vert
) return;
3248 if (dir
== 1 && self
->max_horz
) return;
3249 if (dir
== 2 && self
->max_vert
) return;
3251 if (dir
== 0 && !self
->max_horz
&& !self
->max_vert
) return;
3252 if (dir
== 1 && !self
->max_horz
) return;
3253 if (dir
== 2 && !self
->max_vert
) return;
3256 /* these will help configure_full figure out which screen to fill with
3260 w
= self
->area
.width
;
3261 h
= self
->area
.height
;
3264 if ((dir
== 0 || dir
== 1) && !self
->max_horz
) { /* horz */
3265 RECT_SET(self
->pre_max_area
,
3266 self
->area
.x
, self
->pre_max_area
.y
,
3267 self
->area
.width
, self
->pre_max_area
.height
);
3269 if ((dir
== 0 || dir
== 2) && !self
->max_vert
) { /* vert */
3270 RECT_SET(self
->pre_max_area
,
3271 self
->pre_max_area
.x
, self
->area
.y
,
3272 self
->pre_max_area
.width
, self
->area
.height
);
3275 if ((dir
== 0 || dir
== 1) && self
->max_horz
) { /* horz */
3276 g_assert(self
->pre_max_area
.width
> 0);
3278 x
= self
->pre_max_area
.x
;
3279 w
= self
->pre_max_area
.width
;
3281 RECT_SET(self
->pre_max_area
, 0, self
->pre_max_area
.y
,
3282 0, self
->pre_max_area
.height
);
3284 if ((dir
== 0 || dir
== 2) && self
->max_vert
) { /* vert */
3285 g_assert(self
->pre_max_area
.height
> 0);
3287 y
= self
->pre_max_area
.y
;
3288 h
= self
->pre_max_area
.height
;
3290 RECT_SET(self
->pre_max_area
, self
->pre_max_area
.x
, 0,
3291 self
->pre_max_area
.width
, 0);
3295 if (dir
== 0 || dir
== 1) /* horz */
3296 self
->max_horz
= max
;
3297 if (dir
== 0 || dir
== 2) /* vert */
3298 self
->max_vert
= max
;
3300 client_change_state(self
); /* change the state hints on the client */
3302 client_setup_decor_and_functions(self
, FALSE
);
3303 client_move_resize(self
, x
, y
, w
, h
);
3306 void client_shade(ObClient
*self
, gboolean shade
)
3308 if ((!(self
->functions
& OB_CLIENT_FUNC_SHADE
) &&
3309 shade
) || /* can't shade */
3310 self
->shaded
== shade
) return; /* already done */
3312 self
->shaded
= shade
;
3313 client_change_state(self
);
3314 client_change_wm_state(self
); /* the window is being hidden/shown */
3315 /* resize the frame to just the titlebar */
3316 frame_adjust_area(self
->frame
, FALSE
, TRUE
, FALSE
);
3319 static void client_ping_event(ObClient
*self
, gboolean dead
)
3321 if (self
->not_responding
!= dead
) {
3322 self
->not_responding
= dead
;
3323 client_update_title(self
);
3326 /* the client isn't responding, so ask to kill it */
3327 client_prompt_kill(self
);
3329 /* it came back to life ! */
3331 if (self
->kill_prompt
) {
3332 prompt_unref(self
->kill_prompt
);
3333 self
->kill_prompt
= NULL
;
3336 self
->kill_level
= 0;
3341 void client_close(ObClient
*self
)
3343 if (!(self
->functions
& OB_CLIENT_FUNC_CLOSE
)) return;
3345 /* if closing an internal obprompt, that is just cancelling it */
3347 prompt_cancel(self
->prompt
);
3351 /* in the case that the client provides no means to requesting that it
3352 close, we just kill it */
3353 if (!self
->delete_window
)
3354 /* don't use client_kill(), we should only kill based on PID in
3355 response to a lack of PING replies */
3356 XKillClient(obt_display
, self
->window
);
3358 /* request the client to close with WM_DELETE_WINDOW */
3359 OBT_PROP_MSG_TO(self
->window
, self
->window
, WM_PROTOCOLS
,
3360 OBT_PROP_ATOM(WM_DELETE_WINDOW
), event_curtime
,
3361 0, 0, 0, NoEventMask
);
3363 /* we're trying to close the window, so see if it is responding. if it
3364 is not, then we will let them kill the window */
3366 ping_start(self
, client_ping_event
);
3368 /* if we already know the window isn't responding (maybe they clicked
3369 no in the kill dialog but it hasn't come back to life), then show
3371 if (self
->not_responding
)
3372 client_prompt_kill(self
);
3376 #define OB_KILL_RESULT_NO 0
3377 #define OB_KILL_RESULT_YES 1
3379 static gboolean
client_kill_requested(ObPrompt
*p
, gint result
, gpointer data
)
3381 ObClient
*self
= data
;
3383 if (result
== OB_KILL_RESULT_YES
)
3385 return TRUE
; /* call the cleanup func */
3388 static void client_kill_cleanup(ObPrompt
*p
, gpointer data
)
3390 ObClient
*self
= data
;
3392 g_assert(p
== self
->kill_prompt
);
3394 prompt_unref(self
->kill_prompt
);
3395 self
->kill_prompt
= NULL
;
3398 static void client_prompt_kill(ObClient
*self
)
3400 /* check if we're already prompting */
3401 if (!self
->kill_prompt
) {
3402 ObPromptAnswer answers
[] = {
3403 { 0, OB_KILL_RESULT_NO
},
3404 { 0, OB_KILL_RESULT_YES
}
3407 const gchar
*y
, *title
;
3409 title
= self
->original_title
;
3410 if (title
[0] == '\0') {
3411 /* empty string, so use its parent */
3412 ObClient
*p
= client_search_top_direct_parent(self
);
3413 if (p
) title
= p
->original_title
;
3416 if (client_on_localhost(self
)) {
3419 if (self
->kill_level
== 0)
3425 (_("The window \"%s\" does not seem to be responding. Do you want to force it to exit by sending the %s signal?"),
3427 y
= _("End Process");
3431 (_("The window \"%s\" does not seem to be responding. Do you want to disconnect it from the X server?"),
3433 y
= _("Disconnect");
3435 /* set the dialog buttons' text */
3436 answers
[0].text
= _("Cancel"); /* "no" */
3437 answers
[1].text
= y
; /* "yes" */
3439 self
->kill_prompt
= prompt_new(m
, NULL
, answers
,
3440 sizeof(answers
)/sizeof(answers
[0]),
3441 OB_KILL_RESULT_NO
, /* default = no */
3442 OB_KILL_RESULT_NO
, /* cancel = no */
3443 client_kill_requested
,
3444 client_kill_cleanup
,
3449 prompt_show(self
->kill_prompt
, self
, TRUE
);
3452 void client_kill(ObClient
*self
)
3454 /* don't kill our own windows */
3455 if (self
->prompt
) return;
3457 if (client_on_localhost(self
) && self
->pid
) {
3458 /* running on the local host */
3459 if (self
->kill_level
== 0) {
3460 ob_debug("killing window 0x%x with pid %lu, with SIGTERM",
3461 self
->window
, self
->pid
);
3462 kill(self
->pid
, SIGTERM
);
3465 /* show that we're trying to kill it */
3466 client_update_title(self
);
3469 ob_debug("killing window 0x%x with pid %lu, with SIGKILL",
3470 self
->window
, self
->pid
);
3471 kill(self
->pid
, SIGKILL
); /* kill -9 */
3475 /* running on a remote host */
3476 XKillClient(obt_display
, self
->window
);
3480 void client_hilite(ObClient
*self
, gboolean hilite
)
3482 if (self
->demands_attention
== hilite
)
3483 return; /* no change */
3485 /* don't allow focused windows to hilite */
3486 self
->demands_attention
= hilite
&& !client_focused(self
);
3487 if (self
->frame
!= NULL
) { /* if we're mapping, just set the state */
3488 if (self
->demands_attention
) {
3489 frame_flash_start(self
->frame
);
3491 /* if the window is on another desktop then raise it and make it
3492 the most recently used window */
3493 if (self
->desktop
!= screen_desktop
&&
3494 self
->desktop
!= DESKTOP_ALL
)
3496 stacking_raise(CLIENT_AS_WINDOW(self
));
3497 focus_order_to_top(self
);
3501 frame_flash_stop(self
->frame
);
3502 client_change_state(self
);
3506 static void client_set_desktop_recursive(ObClient
*self
,
3514 if (target
!= self
->desktop
&& self
->type
!= OB_CLIENT_TYPE_DESKTOP
) {
3516 ob_debug("Setting desktop %u", target
+1);
3518 g_assert(target
< screen_num_desktops
|| target
== DESKTOP_ALL
);
3520 old
= self
->desktop
;
3521 self
->desktop
= target
;
3522 OBT_PROP_SET32(self
->window
, NET_WM_DESKTOP
, CARDINAL
, target
);
3523 /* the frame can display the current desktop state */
3524 frame_adjust_state(self
->frame
);
3525 /* 'move' the window to the new desktop */
3529 /* raise if it was not already on the desktop */
3530 if (old
!= DESKTOP_ALL
&& !dontraise
)
3531 stacking_raise(CLIENT_AS_WINDOW(self
));
3532 if (STRUT_EXISTS(self
->strut
))
3533 screen_update_areas();
3535 /* the new desktop's geometry may be different, so we may need to
3536 resize, for example if we are maximized */
3537 client_reconfigure(self
, FALSE
);
3539 focus_cycle_addremove(self
, FALSE
);
3542 /* move all transients */
3543 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
3544 if (it
->data
!= self
)
3545 if (client_is_direct_child(self
, it
->data
))
3546 client_set_desktop_recursive(it
->data
, target
,
3547 donthide
, dontraise
);
3550 void client_set_desktop(ObClient
*self
, guint target
,
3551 gboolean donthide
, gboolean dontraise
)
3553 self
= client_search_top_direct_parent(self
);
3554 client_set_desktop_recursive(self
, target
, donthide
, dontraise
);
3556 focus_cycle_addremove(NULL
, TRUE
);
3559 gboolean
client_is_direct_child(ObClient
*parent
, ObClient
*child
)
3561 while (child
!= parent
&& (child
= client_direct_parent(child
)));
3562 return child
== parent
;
3565 ObClient
*client_search_modal_child(ObClient
*self
)
3570 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
3571 ObClient
*c
= it
->data
;
3572 if ((ret
= client_search_modal_child(c
))) return ret
;
3573 if (c
->modal
) return c
;
3578 static gboolean
client_validate_unmap(ObClient
*self
, int n
)
3581 gboolean ret
= TRUE
;
3583 if (XCheckTypedWindowEvent(obt_display
, self
->window
, UnmapNotify
, &e
)) {
3584 if (n
< self
->ignore_unmaps
) // ignore this one, but look for more
3585 ret
= client_validate_unmap(self
, n
+1);
3587 ret
= FALSE
; // the window is going to become unmanaged
3589 /* put them back on the event stack so they end up in the same order */
3590 XPutBackEvent(obt_display
, &e
);
3596 gboolean
client_validate(ObClient
*self
)
3600 XSync(obt_display
, FALSE
); /* get all events on the server */
3602 if (XCheckTypedWindowEvent(obt_display
, self
->window
, DestroyNotify
, &e
)) {
3603 XPutBackEvent(obt_display
, &e
);
3607 if (!client_validate_unmap(self
, 0))
3613 void client_set_wm_state(ObClient
*self
, glong state
)
3615 if (state
== self
->wmstate
) return; /* no change */
3619 client_iconify(self
, TRUE
, TRUE
, FALSE
);
3622 client_iconify(self
, FALSE
, TRUE
, FALSE
);
3627 void client_set_state(ObClient
*self
, Atom action
, glong data1
, glong data2
)
3629 gboolean shaded
= self
->shaded
;
3630 gboolean fullscreen
= self
->fullscreen
;
3631 gboolean undecorated
= self
->undecorated
;
3632 gboolean max_horz
= self
->max_horz
;
3633 gboolean max_vert
= self
->max_vert
;
3634 gboolean modal
= self
->modal
;
3635 gboolean iconic
= self
->iconic
;
3636 gboolean demands_attention
= self
->demands_attention
;
3637 gboolean above
= self
->above
;
3638 gboolean below
= self
->below
;
3642 if (!(action
== OBT_PROP_ATOM(NET_WM_STATE_ADD
) ||
3643 action
== OBT_PROP_ATOM(NET_WM_STATE_REMOVE
) ||
3644 action
== OBT_PROP_ATOM(NET_WM_STATE_TOGGLE
)))
3645 /* an invalid action was passed to the client message, ignore it */
3648 for (i
= 0; i
< 2; ++i
) {
3649 Atom state
= i
== 0 ? data1
: data2
;
3651 if (!state
) continue;
3653 /* if toggling, then pick whether we're adding or removing */
3654 if (action
== OBT_PROP_ATOM(NET_WM_STATE_TOGGLE
)) {
3655 if (state
== OBT_PROP_ATOM(NET_WM_STATE_MODAL
))
3657 else if (state
== OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_VERT
))
3658 value
= self
->max_vert
;
3659 else if (state
== OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_HORZ
))
3660 value
= self
->max_horz
;
3661 else if (state
== OBT_PROP_ATOM(NET_WM_STATE_SHADED
))
3663 else if (state
== OBT_PROP_ATOM(NET_WM_STATE_SKIP_TASKBAR
))
3664 value
= self
->skip_taskbar
;
3665 else if (state
== OBT_PROP_ATOM(NET_WM_STATE_SKIP_PAGER
))
3666 value
= self
->skip_pager
;
3667 else if (state
== OBT_PROP_ATOM(NET_WM_STATE_HIDDEN
))
3668 value
= self
->iconic
;
3669 else if (state
== OBT_PROP_ATOM(NET_WM_STATE_FULLSCREEN
))
3671 else if (state
== OBT_PROP_ATOM(NET_WM_STATE_ABOVE
))
3672 value
= self
->above
;
3673 else if (state
== OBT_PROP_ATOM(NET_WM_STATE_BELOW
))
3674 value
= self
->below
;
3675 else if (state
== OBT_PROP_ATOM(NET_WM_STATE_DEMANDS_ATTENTION
))
3676 value
= self
->demands_attention
;
3677 else if (state
== OBT_PROP_ATOM(OB_WM_STATE_UNDECORATED
))
3678 value
= undecorated
;
3680 g_assert_not_reached();
3681 action
= value
? OBT_PROP_ATOM(NET_WM_STATE_REMOVE
) :
3682 OBT_PROP_ATOM(NET_WM_STATE_ADD
);
3685 value
= action
== OBT_PROP_ATOM(NET_WM_STATE_ADD
);
3686 if (state
== OBT_PROP_ATOM(NET_WM_STATE_MODAL
)) {
3688 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_VERT
)) {
3690 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_HORZ
)) {
3692 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_SHADED
)) {
3694 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_SKIP_TASKBAR
)) {
3695 self
->skip_taskbar
= value
;
3696 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_SKIP_PAGER
)) {
3697 self
->skip_pager
= value
;
3698 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_HIDDEN
)) {
3700 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_FULLSCREEN
)) {
3702 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_ABOVE
)) {
3704 /* only unset below when setting above, otherwise you can't get to
3708 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_BELOW
)) {
3709 /* and vice versa */
3713 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_DEMANDS_ATTENTION
)){
3714 demands_attention
= value
;
3715 } else if (state
== OBT_PROP_ATOM(OB_WM_STATE_UNDECORATED
)) {
3716 undecorated
= value
;
3720 if (max_horz
!= self
->max_horz
|| max_vert
!= self
->max_vert
) {
3721 if (max_horz
!= self
->max_horz
&& max_vert
!= self
->max_vert
) {
3723 if (max_horz
== max_vert
) { /* both going the same way */
3724 client_maximize(self
, max_horz
, 0);
3726 client_maximize(self
, max_horz
, 1);
3727 client_maximize(self
, max_vert
, 2);
3731 if (max_horz
!= self
->max_horz
)
3732 client_maximize(self
, max_horz
, 1);
3734 client_maximize(self
, max_vert
, 2);
3737 /* change fullscreen state before shading, as it will affect if the window
3739 if (fullscreen
!= self
->fullscreen
)
3740 client_fullscreen(self
, fullscreen
);
3741 if (shaded
!= self
->shaded
)
3742 client_shade(self
, shaded
);
3743 if (undecorated
!= self
->undecorated
)
3744 client_set_undecorated(self
, undecorated
);
3745 if (above
!= self
->above
|| below
!= self
->below
) {
3746 self
->above
= above
;
3747 self
->below
= below
;
3748 client_calc_layer(self
);
3751 if (modal
!= self
->modal
) {
3752 self
->modal
= modal
;
3753 /* when a window changes modality, then its stacking order with its
3754 transients needs to change */
3755 stacking_raise(CLIENT_AS_WINDOW(self
));
3757 /* it also may get focused. if something is focused that shouldn't
3758 be focused anymore, then move the focus */
3759 if (focus_client
&& client_focus_target(focus_client
) != focus_client
)
3760 client_focus(focus_client
);
3763 if (iconic
!= self
->iconic
)
3764 client_iconify(self
, iconic
, FALSE
, FALSE
);
3766 if (demands_attention
!= self
->demands_attention
)
3767 client_hilite(self
, demands_attention
);
3769 client_change_state(self
); /* change the hint to reflect these changes */
3771 focus_cycle_addremove(self
, TRUE
);
3774 ObClient
*client_focus_target(ObClient
*self
)
3776 ObClient
*child
= NULL
;
3778 child
= client_search_modal_child(self
);
3779 if (child
) return child
;
3783 gboolean
client_can_focus(ObClient
*self
)
3785 /* choose the correct target */
3786 self
= client_focus_target(self
);
3788 if (!self
->frame
->visible
)
3791 if (!(self
->can_focus
|| self
->focus_notify
))
3797 gboolean
client_focus(ObClient
*self
)
3799 /* we might not focus this window, so if we have modal children which would
3800 be focused instead, bring them to this desktop */
3801 client_bring_modal_windows(self
);
3803 /* choose the correct target */
3804 self
= client_focus_target(self
);
3806 if (!client_can_focus(self
)) {
3807 ob_debug_type(OB_DEBUG_FOCUS
,
3808 "Client %s can't be focused", self
->title
);
3812 ob_debug_type(OB_DEBUG_FOCUS
,
3813 "Focusing client \"%s\" (0x%x) at time %u",
3814 self
->title
, self
->window
, event_curtime
);
3816 /* if using focus_delay, stop the timer now so that focus doesn't
3818 event_halt_focus_delay();
3820 obt_display_ignore_errors(TRUE
);
3822 if (self
->can_focus
) {
3823 /* This can cause a BadMatch error with CurrentTime, or if an app
3824 passed in a bad time for _NET_WM_ACTIVE_WINDOW. */
3825 XSetInputFocus(obt_display
, self
->window
, RevertToPointerRoot
,
3829 if (self
->focus_notify
) {
3831 ce
.xclient
.type
= ClientMessage
;
3832 ce
.xclient
.message_type
= OBT_PROP_ATOM(WM_PROTOCOLS
);
3833 ce
.xclient
.display
= obt_display
;
3834 ce
.xclient
.window
= self
->window
;
3835 ce
.xclient
.format
= 32;
3836 ce
.xclient
.data
.l
[0] = OBT_PROP_ATOM(WM_TAKE_FOCUS
);
3837 ce
.xclient
.data
.l
[1] = event_curtime
;
3838 ce
.xclient
.data
.l
[2] = 0l;
3839 ce
.xclient
.data
.l
[3] = 0l;
3840 ce
.xclient
.data
.l
[4] = 0l;
3841 XSendEvent(obt_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
3844 obt_display_ignore_errors(FALSE
);
3846 ob_debug_type(OB_DEBUG_FOCUS
, "Error focusing? %d",
3847 obt_display_error_occured
);
3848 return !obt_display_error_occured
;
3851 static void client_present(ObClient
*self
, gboolean here
, gboolean raise
,
3854 if (client_normal(self
) && screen_showing_desktop
)
3855 screen_show_desktop(FALSE
, self
);
3857 client_iconify(self
, FALSE
, here
, FALSE
);
3858 if (self
->desktop
!= DESKTOP_ALL
&&
3859 self
->desktop
!= screen_desktop
)
3862 client_set_desktop(self
, screen_desktop
, FALSE
, TRUE
);
3864 screen_set_desktop(self
->desktop
, FALSE
);
3865 } else if (!self
->frame
->visible
)
3866 /* if its not visible for other reasons, then don't mess
3869 if (self
->shaded
&& unshade
)
3870 client_shade(self
, FALSE
);
3872 stacking_raise(CLIENT_AS_WINDOW(self
));
3877 /* this function exists to map to the net_active_window message in the ewmh */
3878 void client_activate(ObClient
*self
, gboolean desktop
,
3879 gboolean here
, gboolean raise
,
3880 gboolean unshade
, gboolean user
)
3882 if ((user
&& (desktop
||
3883 self
->desktop
== DESKTOP_ALL
||
3884 self
->desktop
== screen_desktop
)) ||
3885 client_can_steal_focus(self
, event_curtime
, CurrentTime
))
3887 client_present(self
, here
, raise
, unshade
);
3890 client_hilite(self
, TRUE
);
3893 static void client_bring_windows_recursive(ObClient
*self
,
3901 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
3902 client_bring_windows_recursive(it
->data
, desktop
,
3903 helpers
, modals
, iconic
);
3905 if (((helpers
&& client_helper(self
)) ||
3906 (modals
&& self
->modal
)) &&
3907 ((self
->desktop
!= desktop
&& self
->desktop
!= DESKTOP_ALL
) ||
3908 (iconic
&& self
->iconic
)))
3910 if (iconic
&& self
->iconic
)
3911 client_iconify(self
, FALSE
, TRUE
, FALSE
);
3913 client_set_desktop(self
, desktop
, FALSE
, FALSE
);
3917 void client_bring_helper_windows(ObClient
*self
)
3919 client_bring_windows_recursive(self
, self
->desktop
, TRUE
, FALSE
, FALSE
);
3922 void client_bring_modal_windows(ObClient
*self
)
3924 client_bring_windows_recursive(self
, self
->desktop
, FALSE
, TRUE
, TRUE
);
3927 gboolean
client_focused(ObClient
*self
)
3929 return self
== focus_client
;
3932 RrImage
* client_icon(ObClient
*self
)
3934 RrImage
*ret
= NULL
;
3937 ret
= self
->icon_set
;
3938 else if (self
->parents
) {
3940 for (it
= self
->parents
; it
&& !ret
; it
= g_slist_next(it
))
3941 ret
= client_icon(it
->data
);
3944 ret
= client_default_icon
;
3948 void client_set_layer(ObClient
*self
, gint layer
)
3952 self
->above
= FALSE
;
3953 } else if (layer
== 0) {
3954 self
->below
= self
->above
= FALSE
;
3956 self
->below
= FALSE
;
3959 client_calc_layer(self
);
3960 client_change_state(self
); /* reflect this in the state hints */
3963 void client_set_undecorated(ObClient
*self
, gboolean undecorated
)
3965 if (self
->undecorated
!= undecorated
&&
3966 /* don't let it undecorate if the function is missing, but let
3968 (self
->functions
& OB_CLIENT_FUNC_UNDECORATE
|| !undecorated
))
3970 self
->undecorated
= undecorated
;
3971 client_setup_decor_and_functions(self
, TRUE
);
3972 client_change_state(self
); /* reflect this in the state hints */
3976 guint
client_monitor(ObClient
*self
)
3978 return screen_find_monitor(&self
->frame
->area
);
3981 ObClient
*client_direct_parent(ObClient
*self
)
3983 if (!self
->parents
) return NULL
;
3984 if (self
->transient_for_group
) return NULL
;
3985 return self
->parents
->data
;
3988 ObClient
*client_search_top_direct_parent(ObClient
*self
)
3991 while ((p
= client_direct_parent(self
))) self
= p
;
3995 static GSList
*client_search_all_top_parents_internal(ObClient
*self
,
3997 ObStackingLayer layer
)
4002 /* move up the direct transient chain as far as possible */
4003 while ((p
= client_direct_parent(self
)) &&
4004 (!bylayer
|| p
->layer
== layer
))
4008 ret
= g_slist_prepend(NULL
, self
);
4010 ret
= g_slist_copy(self
->parents
);
4015 GSList
*client_search_all_top_parents(ObClient
*self
)
4017 return client_search_all_top_parents_internal(self
, FALSE
, 0);
4020 GSList
*client_search_all_top_parents_layer(ObClient
*self
)
4022 return client_search_all_top_parents_internal(self
, TRUE
, self
->layer
);
4025 ObClient
*client_search_focus_parent(ObClient
*self
)
4029 for (it
= self
->parents
; it
; it
= g_slist_next(it
))
4030 if (client_focused(it
->data
)) return it
->data
;
4035 ObClient
*client_search_focus_parent_full(ObClient
*self
)
4038 ObClient
*ret
= NULL
;
4040 for (it
= self
->parents
; it
; it
= g_slist_next(it
)) {
4041 if (client_focused(it
->data
))
4044 ret
= client_search_focus_parent_full(it
->data
);
4050 ObClient
*client_search_parent(ObClient
*self
, ObClient
*search
)
4054 for (it
= self
->parents
; it
; it
= g_slist_next(it
))
4055 if (it
->data
== search
) return search
;
4060 ObClient
*client_search_transient(ObClient
*self
, ObClient
*search
)
4064 for (sit
= self
->transients
; sit
; sit
= g_slist_next(sit
)) {
4065 if (sit
->data
== search
)
4067 if (client_search_transient(sit
->data
, search
))
4073 static void detect_edge(Rect area
, ObDirection dir
,
4074 gint my_head
, gint my_size
,
4075 gint my_edge_start
, gint my_edge_size
,
4076 gint
*dest
, gboolean
*near_edge
)
4078 gint edge_start
, edge_size
, head
, tail
;
4079 gboolean skip_head
= FALSE
, skip_tail
= FALSE
;
4082 case OB_DIRECTION_NORTH
:
4083 case OB_DIRECTION_SOUTH
:
4084 edge_start
= area
.x
;
4085 edge_size
= area
.width
;
4087 case OB_DIRECTION_EAST
:
4088 case OB_DIRECTION_WEST
:
4089 edge_start
= area
.y
;
4090 edge_size
= area
.height
;
4093 g_assert_not_reached();
4096 /* do we collide with this window? */
4097 if (!RANGES_INTERSECT(my_edge_start
, my_edge_size
,
4098 edge_start
, edge_size
))
4102 case OB_DIRECTION_NORTH
:
4103 head
= RECT_BOTTOM(area
);
4104 tail
= RECT_TOP(area
);
4106 case OB_DIRECTION_SOUTH
:
4107 head
= RECT_TOP(area
);
4108 tail
= RECT_BOTTOM(area
);
4110 case OB_DIRECTION_WEST
:
4111 head
= RECT_RIGHT(area
);
4112 tail
= RECT_LEFT(area
);
4114 case OB_DIRECTION_EAST
:
4115 head
= RECT_LEFT(area
);
4116 tail
= RECT_RIGHT(area
);
4119 g_assert_not_reached();
4122 case OB_DIRECTION_NORTH
:
4123 case OB_DIRECTION_WEST
:
4124 /* check if our window is past the head of this window */
4125 if (my_head
<= head
+ 1)
4127 /* check if our window's tail is past the tail of this window */
4128 if (my_head
+ my_size
- 1 <= tail
)
4130 /* check if the head of this window is closer than the previously
4131 chosen edge (take into account that the previously chosen
4132 edge might have been a tail, not a head) */
4133 if (head
+ (*near_edge
? 0 : my_size
) <= *dest
)
4135 /* check if the tail of this window is closer than the previously
4136 chosen edge (take into account that the previously chosen
4137 edge might have been a head, not a tail) */
4138 if (tail
- (!*near_edge
? 0 : my_size
) <= *dest
)
4141 case OB_DIRECTION_SOUTH
:
4142 case OB_DIRECTION_EAST
:
4143 /* check if our window is past the head of this window */
4144 if (my_head
>= head
- 1)
4146 /* check if our window's tail is past the tail of this window */
4147 if (my_head
- my_size
+ 1 >= tail
)
4149 /* check if the head of this window is closer than the previously
4150 chosen edge (take into account that the previously chosen
4151 edge might have been a tail, not a head) */
4152 if (head
- (*near_edge
? 0 : my_size
) >= *dest
)
4154 /* check if the tail of this window is closer than the previously
4155 chosen edge (take into account that the previously chosen
4156 edge might have been a head, not a tail) */
4157 if (tail
+ (!*near_edge
? 0 : my_size
) >= *dest
)
4161 g_assert_not_reached();
4164 ob_debug("my head %d size %d", my_head
, my_size
);
4165 ob_debug("head %d tail %d dest %d", head
, tail
, *dest
);
4167 ob_debug("using near edge %d", head
);
4171 else if (!skip_tail
) {
4172 ob_debug("using far edge %d", tail
);
4178 void client_find_edge_directional(ObClient
*self
, ObDirection dir
,
4179 gint my_head
, gint my_size
,
4180 gint my_edge_start
, gint my_edge_size
,
4181 gint
*dest
, gboolean
*near_edge
)
4189 a
= screen_area(self
->desktop
, SCREEN_AREA_ALL_MONITORS
,
4190 &self
->frame
->area
);
4193 case OB_DIRECTION_NORTH
:
4194 edge
= RECT_TOP(*a
) - 1;
4196 case OB_DIRECTION_SOUTH
:
4197 edge
= RECT_BOTTOM(*a
) + 1;
4199 case OB_DIRECTION_EAST
:
4200 edge
= RECT_RIGHT(*a
) + 1;
4202 case OB_DIRECTION_WEST
:
4203 edge
= RECT_LEFT(*a
) - 1;
4206 g_assert_not_reached();
4208 /* default to the far edge, then narrow it down */
4212 /* search for edges of monitors */
4213 for (i
= 0; i
< screen_num_monitors
; ++i
) {
4214 Rect
*area
= screen_area(self
->desktop
, i
, NULL
);
4215 detect_edge(*area
, dir
, my_head
, my_size
, my_edge_start
,
4216 my_edge_size
, dest
, near_edge
);
4220 /* search for edges of clients */
4221 for (it
= client_list
; it
; it
= g_list_next(it
)) {
4222 ObClient
*cur
= it
->data
;
4224 /* skip windows to not bump into */
4229 if (self
->desktop
!= cur
->desktop
&& cur
->desktop
!= DESKTOP_ALL
&&
4230 cur
->desktop
!= screen_desktop
)
4233 ob_debug("trying window %s", cur
->title
);
4235 detect_edge(cur
->frame
->area
, dir
, my_head
, my_size
, my_edge_start
,
4236 my_edge_size
, dest
, near_edge
);
4238 dock_get_area(&dock_area
);
4239 detect_edge(dock_area
, dir
, my_head
, my_size
, my_edge_start
,
4240 my_edge_size
, dest
, near_edge
);
4244 void client_find_move_directional(ObClient
*self
, ObDirection dir
,
4248 gint e
, e_start
, e_size
;
4252 case OB_DIRECTION_EAST
:
4253 head
= RECT_RIGHT(self
->frame
->area
);
4254 size
= self
->frame
->area
.width
;
4255 e_start
= RECT_TOP(self
->frame
->area
);
4256 e_size
= self
->frame
->area
.height
;
4258 case OB_DIRECTION_WEST
:
4259 head
= RECT_LEFT(self
->frame
->area
);
4260 size
= self
->frame
->area
.width
;
4261 e_start
= RECT_TOP(self
->frame
->area
);
4262 e_size
= self
->frame
->area
.height
;
4264 case OB_DIRECTION_NORTH
:
4265 head
= RECT_TOP(self
->frame
->area
);
4266 size
= self
->frame
->area
.height
;
4267 e_start
= RECT_LEFT(self
->frame
->area
);
4268 e_size
= self
->frame
->area
.width
;
4270 case OB_DIRECTION_SOUTH
:
4271 head
= RECT_BOTTOM(self
->frame
->area
);
4272 size
= self
->frame
->area
.height
;
4273 e_start
= RECT_LEFT(self
->frame
->area
);
4274 e_size
= self
->frame
->area
.width
;
4277 g_assert_not_reached();
4280 client_find_edge_directional(self
, dir
, head
, size
,
4281 e_start
, e_size
, &e
, &near
);
4282 *x
= self
->frame
->area
.x
;
4283 *y
= self
->frame
->area
.y
;
4285 case OB_DIRECTION_EAST
:
4286 if (near
) e
-= self
->frame
->area
.width
;
4290 case OB_DIRECTION_WEST
:
4292 else e
-= self
->frame
->area
.width
;
4295 case OB_DIRECTION_NORTH
:
4297 else e
-= self
->frame
->area
.height
;
4300 case OB_DIRECTION_SOUTH
:
4301 if (near
) e
-= self
->frame
->area
.height
;
4306 g_assert_not_reached();
4308 frame_frame_gravity(self
->frame
, x
, y
);
4311 void client_find_resize_directional(ObClient
*self
, ObDirection side
,
4313 gint
*x
, gint
*y
, gint
*w
, gint
*h
)
4316 gint e
, e_start
, e_size
, delta
;
4321 case OB_DIRECTION_EAST
:
4322 head
= RECT_RIGHT(self
->frame
->area
) +
4323 (self
->size_inc
.width
- 1) * (grow
? 1 : 0);
4324 e_start
= RECT_TOP(self
->frame
->area
);
4325 e_size
= self
->frame
->area
.height
;
4326 dir
= grow
? OB_DIRECTION_EAST
: OB_DIRECTION_WEST
;
4328 case OB_DIRECTION_WEST
:
4329 head
= RECT_LEFT(self
->frame
->area
) -
4330 (self
->size_inc
.width
- 1) * (grow
? 1 : 0);
4331 e_start
= RECT_TOP(self
->frame
->area
);
4332 e_size
= self
->frame
->area
.height
;
4333 dir
= grow
? OB_DIRECTION_WEST
: OB_DIRECTION_EAST
;
4335 case OB_DIRECTION_NORTH
:
4336 head
= RECT_TOP(self
->frame
->area
) -
4337 (self
->size_inc
.height
- 1) * (grow
? 1 : 0);
4338 e_start
= RECT_LEFT(self
->frame
->area
);
4339 e_size
= self
->frame
->area
.width
;
4340 dir
= grow
? OB_DIRECTION_NORTH
: OB_DIRECTION_SOUTH
;
4342 case OB_DIRECTION_SOUTH
:
4343 head
= RECT_BOTTOM(self
->frame
->area
) +
4344 (self
->size_inc
.height
- 1) * (grow
? 1 : 0);
4345 e_start
= RECT_LEFT(self
->frame
->area
);
4346 e_size
= self
->frame
->area
.width
;
4347 dir
= grow
? OB_DIRECTION_SOUTH
: OB_DIRECTION_NORTH
;
4350 g_assert_not_reached();
4353 ob_debug("head %d dir %d", head
, dir
);
4354 client_find_edge_directional(self
, dir
, head
, 1,
4355 e_start
, e_size
, &e
, &near
);
4356 ob_debug("edge %d", e
);
4357 *x
= self
->frame
->area
.x
;
4358 *y
= self
->frame
->area
.y
;
4359 *w
= self
->frame
->area
.width
;
4360 *h
= self
->frame
->area
.height
;
4362 case OB_DIRECTION_EAST
:
4363 if (grow
== near
) --e
;
4364 delta
= e
- RECT_RIGHT(self
->frame
->area
);
4367 case OB_DIRECTION_WEST
:
4368 if (grow
== near
) ++e
;
4369 delta
= RECT_LEFT(self
->frame
->area
) - e
;
4373 case OB_DIRECTION_NORTH
:
4374 if (grow
== near
) ++e
;
4375 delta
= RECT_TOP(self
->frame
->area
) - e
;
4379 case OB_DIRECTION_SOUTH
:
4380 if (grow
== near
) --e
;
4381 delta
= e
- RECT_BOTTOM(self
->frame
->area
);
4385 g_assert_not_reached();
4387 frame_frame_gravity(self
->frame
, x
, y
);
4388 *w
-= self
->frame
->size
.left
+ self
->frame
->size
.right
;
4389 *h
-= self
->frame
->size
.top
+ self
->frame
->size
.bottom
;
4392 ObClient
* client_under_pointer(void)
4396 ObClient
*ret
= NULL
;
4398 if (screen_pointer_pos(&x
, &y
)) {
4399 for (it
= stacking_list
; it
; it
= g_list_next(it
)) {
4400 if (WINDOW_IS_CLIENT(it
->data
)) {
4401 ObClient
*c
= WINDOW_AS_CLIENT(it
->data
);
4402 if (c
->frame
->visible
&&
4403 /* check the desktop, this is done during desktop
4404 switching and windows are shown/hidden status is not
4406 (c
->desktop
== screen_desktop
||
4407 c
->desktop
== DESKTOP_ALL
) &&
4408 /* ignore all animating windows */
4409 !frame_iconify_animating(c
->frame
) &&
4410 RECT_CONTAINS(c
->frame
->area
, x
, y
))
4421 gboolean
client_has_group_siblings(ObClient
*self
)
4423 return self
->group
&& self
->group
->members
->next
;
4426 /*! Returns TRUE if the client is running on the same machine as Openbox */
4427 gboolean
client_on_localhost(ObClient
*self
)
4429 return self
->client_machine
== NULL
;