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
,
31 -100, -100, 1, 1, 0, 0, InputOnly
,
32 CopyFromParent
, CWOverrideRedirect
, &attrib
);
33 XMapRaised(ob_display
, focus_backup
);
35 /* start with nothing focused */
36 focus_set_client(NULL
);
43 for (i
= 0; i
< screen_num_desktops
; ++i
)
44 g_list_free(focus_order
[i
]);
48 XDestroyWindow(ob_display
, focus_backup
);
50 /* reset focus to root */
51 XSetInputFocus(ob_display
, PointerRoot
, RevertToPointerRoot
,
55 void focus_set_client(Client
*client
)
61 if (client
== focus_client
) return;
63 /* uninstall the old colormap, and install the new one */
64 screen_install_colormap(focus_client
, FALSE
);
65 screen_install_colormap(client
, TRUE
);
68 /* when nothing will be focused, send focus to the backup target */
69 XSetInputFocus(ob_display
, focus_backup
, RevertToPointerRoot
,
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
))
103 for (it
= stacking_list
; it
!= NULL
; it
= it
->next
) {
104 Client
*c
= it
->data
;
105 if (c
->desktop
== screen_desktop
&&
106 RECT_CONTAINS(c
->frame
->area
, x
, y
))
110 g_message("fallback (pointer) trying %lx", ((Client
*)it
->data
)->window
);
111 return client_normal(it
->data
) && client_focus(it
->data
);
117 void focus_fallback(gboolean switching_desks
)
119 ConfigValue focus_follow
;
121 gboolean fallback
= TRUE
;
123 if (!switching_desks
) {
124 if (!config_get("focusFollowsMouse", Config_Bool
, &focus_follow
))
125 g_assert_not_reached();
126 if (focus_follow
.bool)
127 fallback
= !focus_under_pointer();
131 for (it
= focus_order
[screen_desktop
]; it
!= NULL
; it
= it
->next
)
132 if (it
->data
!= focus_client
&& client_normal(it
->data
)) {
133 g_message("fallback trying %lx", ((Client
*)it
->data
)->window
);
134 if (client_focus(it
->data
))
139 if (it
== NULL
) /* nothing to focus */
140 focus_set_client(NULL
);