13 Client
*focus_client
= NULL
;
14 GList
**focus_order
= NULL
; /* these lists are created when screen_startup
15 sets the number of desktops */
17 Window focus_backup
= None
;
18 gboolean focus_new
= TRUE
;
19 gboolean focus_follow
= TRUE
;
23 /* create the window which gets focus when no clients get it. Have to
24 make it override-redirect so we don't try manage it, since it is
26 XSetWindowAttributes attrib
;
32 attrib
.override_redirect
= TRUE
;
33 focus_backup
= XCreateWindow(ob_display
, ob_root
,
35 CopyFromParent
, InputOutput
, CopyFromParent
,
36 CWOverrideRedirect
, &attrib
);
37 XMapRaised(ob_display
, focus_backup
);
39 /* start with nothing focused */
40 focus_set_client(NULL
);
47 for (i
= 0; i
< screen_num_desktops
; ++i
)
48 g_list_free(focus_order
[i
]);
52 XDestroyWindow(ob_display
, focus_backup
);
54 /* reset focus to root */
55 XSetInputFocus(ob_display
, PointerRoot
, RevertToPointerRoot
,
59 void focus_set_client(Client
*client
)
65 /* uninstall the old colormap, and install the new one */
66 screen_install_colormap(focus_client
, FALSE
);
67 screen_install_colormap(client
, TRUE
);
70 /* when nothing will be focused, send focus to the backup target */
71 XSetInputFocus(ob_display
, focus_backup
, RevertToPointerRoot
,
73 XSync(ob_display
, FALSE
);
77 focus_client
= client
;
79 /* move to the top of the list */
81 desktop
= client
->desktop
;
82 if (desktop
== DESKTOP_ALL
) desktop
= screen_desktop
;
83 focus_order
[desktop
] = g_list_remove(focus_order
[desktop
], client
);
84 focus_order
[desktop
] = g_list_prepend(focus_order
[desktop
], client
);
87 /* set the NET_ACTIVE_WINDOW hint */
88 active
= client
? client
->window
: None
;
89 PROP_SET32(ob_root
, net_active_window
, window
, active
);
91 if (focus_client
!= NULL
)
92 dispatch_client(Event_Client_Focus
, focus_client
, 0, 0);
94 dispatch_client(Event_Client_Unfocus
, old
, 0, 0);
97 static gboolean
focus_under_pointer()
104 if (XQueryPointer(ob_display
, ob_root
, &w
, &w
, &x
, &y
, &i
, &i
, &u
)) {
105 for (it
= stacking_list
; it
!= NULL
; it
= it
->next
) {
106 Client
*c
= it
->data
;
107 if (c
->desktop
== screen_desktop
&&
108 RECT_CONTAINS(c
->frame
->area
, x
, y
))
112 return client_normal(it
->data
) && client_focus(it
->data
);
117 void focus_fallback(gboolean switching_desks
)
120 gboolean under
= FALSE
;
125 /* unfocus any focused clients.. they can be focused by Pointer events
126 and such, and then when I try focus them, I won't get a FocusIn event
129 focus_set_client(NULL
);
131 if (switching_desks
) {
132 /* don't skip any windows when switching desktops */
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
);