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
;
19 gboolean focus_new
= TRUE
;
20 gboolean focus_follow
= TRUE
;
21 int focus_ignore_in
= 0;
23 static void parse_assign(char *name
, ParseToken
*value
)
25 if (!g_ascii_strcasecmp(name
, "focusnew")) {
26 if (value
->type
!= TOKEN_BOOL
)
27 yyerror("invalid value");
29 focus_new
= value
->data
.bool;
31 } else if (!g_ascii_strcasecmp(name
, "followmouse")) {
32 if (value
->type
!= TOKEN_BOOL
)
33 yyerror("invalid value");
35 focus_follow
= value
->data
.bool;
38 yyerror("invalid option");
39 parse_free_token(value
);
44 /* create the window which gets focus when no clients get it. Have to
45 make it override-redirect so we don't try manage it, since it is
47 XSetWindowAttributes attrib
;
53 attrib
.override_redirect
= TRUE
;
54 focus_backup
= XCreateWindow(ob_display
, ob_root
,
56 CopyFromParent
, InputOutput
, CopyFromParent
,
57 CWOverrideRedirect
, &attrib
);
58 XMapRaised(ob_display
, focus_backup
);
60 /* start with nothing focused */
61 focus_set_client(NULL
);
63 parse_reg_section("focus", NULL
, parse_assign
);
70 for (i
= 0; i
< screen_num_desktops
; ++i
)
71 g_list_free(focus_order
[i
]);
75 XDestroyWindow(ob_display
, focus_backup
);
77 /* reset focus to root */
78 XSetInputFocus(ob_display
, PointerRoot
, RevertToPointerRoot
,
82 void focus_set_client(Client
*client
)
88 /* uninstall the old colormap, and install the new one */
89 screen_install_colormap(focus_client
, FALSE
);
90 screen_install_colormap(client
, TRUE
);
93 /* when nothing will be focused, send focus to the backup target */
94 XSetInputFocus(ob_display
, focus_backup
, RevertToPointerRoot
,
96 XSync(ob_display
, FALSE
);
100 focus_client
= client
;
102 /* move to the top of the list */
103 if (focus_ignore_in
) {
104 g_assert(focus_ignore_in
> 0);
106 } else if (client
!= NULL
) {
107 desktop
= client
->desktop
;
108 if (desktop
== DESKTOP_ALL
) desktop
= screen_desktop
;
109 focus_order
[desktop
] = g_list_remove(focus_order
[desktop
], client
);
110 focus_order
[desktop
] = g_list_prepend(focus_order
[desktop
], client
);
113 /* set the NET_ACTIVE_WINDOW hint */
114 active
= client
? client
->window
: None
;
115 PROP_SET32(ob_root
, net_active_window
, window
, active
);
117 if (focus_client
!= NULL
)
118 dispatch_client(Event_Client_Focus
, focus_client
, 0, 0);
120 dispatch_client(Event_Client_Unfocus
, old
, 0, 0);
123 static gboolean
focus_under_pointer()
130 if (XQueryPointer(ob_display
, ob_root
, &w
, &w
, &x
, &y
, &i
, &i
, &u
)) {
131 for (it
= stacking_list
; it
!= NULL
; it
= it
->next
) {
132 Client
*c
= it
->data
;
133 if (c
->desktop
== screen_desktop
&&
134 RECT_CONTAINS(c
->frame
->area
, x
, y
))
138 return client_normal(it
->data
) && client_focus(it
->data
);
143 void focus_fallback(gboolean switching_desks
)
146 gboolean under
= FALSE
;
151 /* unfocus any focused clients.. they can be focused by Pointer events
152 and such, and then when I try focus them, I won't get a FocusIn event
155 focus_set_client(NULL
);
157 if (switching_desks
) {
158 /* don't skip any windows when switching desktops */
162 under
= focus_under_pointer();
166 for (it
= focus_order
[screen_desktop
]; it
!= NULL
; it
= it
->next
)
167 if (it
->data
!= old
&& client_normal(it
->data
))
168 if (client_focus(it
->data
))
170 if (it
== NULL
) /* nothing to focus */
171 focus_set_client(NULL
);