14 Client
*focus_client
= NULL
;
15 GList
**focus_order
= NULL
; /* these lists are created when screen_startup
16 sets the number of desktops */
18 Window focus_backup
= None
;
22 /* create the window which gets focus when no clients get it. Have to
23 make it override-redirect so we don't try manage it, since it is
25 XSetWindowAttributes attrib
;
29 attrib
.override_redirect
= TRUE
;
30 focus_backup
= XCreateWindow(ob_display
, ob_root
,
32 CopyFromParent
, InputOutput
, CopyFromParent
,
33 CWOverrideRedirect
, &attrib
);
34 XMapRaised(ob_display
, focus_backup
);
36 /* start with nothing focused */
37 focus_set_client(NULL
);
44 for (i
= 0; i
< screen_num_desktops
; ++i
)
45 g_list_free(focus_order
[i
]);
49 XDestroyWindow(ob_display
, focus_backup
);
51 /* reset focus to root */
52 XSetInputFocus(ob_display
, PointerRoot
, RevertToPointerRoot
,
56 void focus_set_client(Client
*client
)
62 /* uninstall the old colormap, and install the new one */
63 screen_install_colormap(focus_client
, FALSE
);
64 screen_install_colormap(client
, TRUE
);
67 /* when nothing will be focused, send focus to the backup target */
68 XSetInputFocus(ob_display
, focus_backup
, RevertToPointerRoot
,
70 XSync(ob_display
, FALSE
);
74 focus_client
= client
;
76 /* move to the top of the list */
78 desktop
= client
->desktop
;
79 if (desktop
== DESKTOP_ALL
) desktop
= screen_desktop
;
80 focus_order
[desktop
] = g_list_remove(focus_order
[desktop
], client
);
81 focus_order
[desktop
] = g_list_prepend(focus_order
[desktop
], client
);
84 /* set the NET_ACTIVE_WINDOW hint */
85 active
= client
? client
->window
: None
;
86 PROP_SET32(ob_root
, net_active_window
, window
, active
);
88 if (focus_client
!= NULL
)
89 dispatch_client(Event_Client_Focus
, focus_client
, 0, 0);
91 dispatch_client(Event_Client_Unfocus
, old
, 0, 0);
94 static gboolean
focus_under_pointer()
101 if (XQueryPointer(ob_display
, ob_root
, &w
, &w
, &x
, &y
, &i
, &i
, &u
)) {
102 for (it
= stacking_list
; it
!= NULL
; it
= it
->next
) {
103 Client
*c
= it
->data
;
104 if (c
->desktop
== screen_desktop
&&
105 RECT_CONTAINS(c
->frame
->area
, x
, y
))
109 return client_normal(it
->data
) && client_focus(it
->data
);
114 void focus_fallback(gboolean switching_desks
)
116 ConfigValue focus_follow
;
118 gboolean under
= FALSE
;
123 /* unfocus any focused clients.. they can be focused by Pointer events
124 and such, and then when I try focus them, I won't get a FocusIn event
127 focus_set_client(NULL
);
129 if (switching_desks
) {
130 /* don't skip any windows when switching desktops */
133 if (!config_get("focusFollowsMouse", Config_Bool
, &focus_follow
))
134 g_assert_not_reached();
135 if (focus_follow
.bool)
136 under
= focus_under_pointer();
140 for (it
= focus_order
[screen_desktop
]; it
!= NULL
; it
= it
->next
)
141 if (it
->data
!= old
&& client_normal(it
->data
))
142 if (client_focus(it
->data
))
144 if (it
== NULL
) /* nothing to focus */
145 focus_set_client(NULL
);