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
;
22 static void parse_assign(char *name
, ParseToken
*value
)
24 if (!g_ascii_strcasecmp(name
, "focusnew")) {
25 if (value
->type
!= TOKEN_BOOL
)
26 yyerror("invalid value");
28 focus_new
= value
->data
.bool;
30 } else if (!g_ascii_strcasecmp(name
, "followmouse")) {
31 if (value
->type
!= TOKEN_BOOL
)
32 yyerror("invalid value");
34 focus_follow
= value
->data
.bool;
37 yyerror("invalid option");
38 parse_free_token(value
);
43 /* create the window which gets focus when no clients get it. Have to
44 make it override-redirect so we don't try manage it, since it is
46 XSetWindowAttributes attrib
;
52 attrib
.override_redirect
= TRUE
;
53 focus_backup
= XCreateWindow(ob_display
, ob_root
,
55 CopyFromParent
, InputOutput
, CopyFromParent
,
56 CWOverrideRedirect
, &attrib
);
57 XMapRaised(ob_display
, focus_backup
);
59 /* start with nothing focused */
60 focus_set_client(NULL
);
62 parse_reg_section("focus", NULL
, parse_assign
);
69 for (i
= 0; i
< screen_num_desktops
; ++i
)
70 g_list_free(focus_order
[i
]);
74 XDestroyWindow(ob_display
, focus_backup
);
76 /* reset focus to root */
77 XSetInputFocus(ob_display
, PointerRoot
, RevertToPointerRoot
,
81 void focus_set_client(Client
*client
)
87 /* uninstall the old colormap, and install the new one */
88 screen_install_colormap(focus_client
, FALSE
);
89 screen_install_colormap(client
, TRUE
);
92 /* when nothing will be focused, send focus to the backup target */
93 XSetInputFocus(ob_display
, focus_backup
, RevertToPointerRoot
,
95 XSync(ob_display
, FALSE
);
99 focus_client
= client
;
101 /* move to the top of the list */
102 if (client
!= NULL
) {
103 desktop
= client
->desktop
;
104 if (desktop
== DESKTOP_ALL
) desktop
= screen_desktop
;
105 focus_order
[desktop
] = g_list_remove(focus_order
[desktop
], client
);
106 focus_order
[desktop
] = g_list_prepend(focus_order
[desktop
], client
);
109 /* set the NET_ACTIVE_WINDOW hint */
110 active
= client
? client
->window
: None
;
111 PROP_SET32(ob_root
, net_active_window
, window
, active
);
113 if (focus_client
!= NULL
)
114 dispatch_client(Event_Client_Focus
, focus_client
, 0, 0);
116 dispatch_client(Event_Client_Unfocus
, old
, 0, 0);
119 static gboolean
focus_under_pointer()
126 if (XQueryPointer(ob_display
, ob_root
, &w
, &w
, &x
, &y
, &i
, &i
, &u
)) {
127 for (it
= stacking_list
; it
!= NULL
; it
= it
->next
) {
128 Client
*c
= it
->data
;
129 if (c
->desktop
== screen_desktop
&&
130 RECT_CONTAINS(c
->frame
->area
, x
, y
))
134 return client_normal(it
->data
) && client_focus(it
->data
);
139 void focus_fallback(gboolean switching_desks
)
142 gboolean under
= FALSE
;
147 /* unfocus any focused clients.. they can be focused by Pointer events
148 and such, and then when I try focus them, I won't get a FocusIn event
151 focus_set_client(NULL
);
153 if (switching_desks
) {
154 /* don't skip any windows when switching desktops */
158 under
= focus_under_pointer();
162 for (it
= focus_order
[screen_desktop
]; it
!= NULL
; it
= it
->next
)
163 if (it
->data
!= old
&& client_normal(it
->data
))
164 if (client_focus(it
->data
))
166 if (it
== NULL
) /* nothing to focus */
167 focus_set_client(NULL
);