client: rewrite focus()
Hidden client are not more hiddent if focus requested (FS#245) Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
parent
fb093696bb
commit
4b2293d43d
51
client.c
51
client.c
|
@ -212,26 +212,34 @@ client_ban(client_t *c)
|
||||||
|
|
||||||
/** Give focus to client, or to first client if client is NULL.
|
/** Give focus to client, or to first client if client is NULL.
|
||||||
* \param c The client or NULL.
|
* \param c The client or NULL.
|
||||||
* \param screen Virtual screen number.
|
|
||||||
* \return True if a window (even root) has received focus, false otherwise.
|
* \return True if a window (even root) has received focus, false otherwise.
|
||||||
*/
|
*/
|
||||||
void
|
static void
|
||||||
client_focus(client_t *c, int screen)
|
client_focus(client_t *c)
|
||||||
{
|
{
|
||||||
int phys_screen;
|
bool istagged = false;
|
||||||
|
tag_array_t *tags = &globalconf.screens[c->screen].tags;
|
||||||
|
|
||||||
/* if c is NULL or invisible, take next client in the focus history */
|
/* Just check if the client is tagged with at least one visible tag.
|
||||||
if((!c || (c && (!client_isvisible(c, screen))))
|
* If so, we can give it the focus. */
|
||||||
&& !(c = globalconf.screens[screen].client_focus))
|
for(int i = 0; i < tags->len; i++)
|
||||||
/* if c is still NULL take next client in the stack */
|
if(tags->tab[i]->selected && is_client_tagged(c, tags->tab[i]))
|
||||||
for(c = globalconf.clients; c && (c->skip || !client_isvisible(c, screen)); c = c->next);
|
{
|
||||||
|
istagged = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!istagged)
|
||||||
|
return;
|
||||||
|
|
||||||
/* unfocus current selected client */
|
/* unfocus current selected client */
|
||||||
if(globalconf.screen_focus->client_focus && c != globalconf.screen_focus->client_focus)
|
if(globalconf.screen_focus->client_focus
|
||||||
|
&& c != globalconf.screen_focus->client_focus)
|
||||||
client_unfocus(globalconf.screen_focus->client_focus);
|
client_unfocus(globalconf.screen_focus->client_focus);
|
||||||
|
|
||||||
if(c)
|
/* stop hiding c */
|
||||||
{
|
c->ishidden = false;
|
||||||
|
|
||||||
/* unban the client before focusing or it will fail */
|
/* unban the client before focusing or it will fail */
|
||||||
client_unban(c);
|
client_unban(c);
|
||||||
|
|
||||||
|
@ -240,26 +248,17 @@ client_focus(client_t *c, int screen)
|
||||||
|
|
||||||
xcb_set_input_focus(globalconf.connection, XCB_INPUT_FOCUS_POINTER_ROOT,
|
xcb_set_input_focus(globalconf.connection, XCB_INPUT_FOCUS_POINTER_ROOT,
|
||||||
c->win, XCB_CURRENT_TIME);
|
c->win, XCB_CURRENT_TIME);
|
||||||
phys_screen = c->phys_screen;
|
|
||||||
|
|
||||||
/* Some layouts use focused client differently, so call them back. */
|
/* Some layouts use focused client differently, so call them back.
|
||||||
|
* And anyway, we have maybe unhidden */
|
||||||
globalconf.screens[c->screen].need_arrange = true;
|
globalconf.screens[c->screen].need_arrange = true;
|
||||||
|
|
||||||
/* execute hook */
|
/* execute hook */
|
||||||
luaA_client_userdata_new(globalconf.L, globalconf.screen_focus->client_focus);
|
luaA_client_userdata_new(globalconf.L, globalconf.screen_focus->client_focus);
|
||||||
luaA_dofunction(globalconf.L, globalconf.hooks.focus, 1, 0);
|
luaA_dofunction(globalconf.L, globalconf.hooks.focus, 1, 0);
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
phys_screen = screen_virttophys(screen);
|
|
||||||
xcb_set_input_focus(globalconf.connection,
|
|
||||||
XCB_INPUT_FOCUS_POINTER_ROOT,
|
|
||||||
xutil_screen_get(globalconf.connection, phys_screen)->root,
|
|
||||||
XCB_CURRENT_TIME);
|
|
||||||
}
|
|
||||||
|
|
||||||
ewmh_update_net_active_window(phys_screen);
|
ewmh_update_net_active_window(c->phys_screen);
|
||||||
widget_invalidate_cache(screen, WIDGET_CACHE_CLIENTS);
|
widget_invalidate_cache(c->screen, WIDGET_CACHE_CLIENTS);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Restack clients.
|
/** Restack clients.
|
||||||
|
@ -990,7 +989,7 @@ static int
|
||||||
luaA_client_focus_set(lua_State *L)
|
luaA_client_focus_set(lua_State *L)
|
||||||
{
|
{
|
||||||
client_t **c = luaA_checkudata(L, 1, "client");
|
client_t **c = luaA_checkudata(L, 1, "client");
|
||||||
client_focus(*c, (*c)->screen);
|
client_focus(*c);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
1
client.h
1
client.h
|
@ -28,7 +28,6 @@
|
||||||
|
|
||||||
bool client_isvisible(client_t *, int);
|
bool client_isvisible(client_t *, int);
|
||||||
client_t * client_getbywin(xcb_window_t);
|
client_t * client_getbywin(xcb_window_t);
|
||||||
void client_focus(client_t *, int);
|
|
||||||
void client_setlayer(client_t *, layer_t);
|
void client_setlayer(client_t *, layer_t);
|
||||||
void client_stack(void);
|
void client_stack(void);
|
||||||
void client_raise(client_t *);
|
void client_raise(client_t *);
|
||||||
|
|
Loading…
Reference in New Issue