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:
Julien Danjou 2008-08-11 11:51:54 +02:00
parent fb093696bb
commit 4b2293d43d
2 changed files with 35 additions and 37 deletions

View File

@ -212,54 +212,53 @@ 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 */
client_unban(c);
globalconf.screen_focus = &globalconf.screens[c->screen]; /* unban the client before focusing or it will fail */
globalconf.screen_focus->client_focus = c; client_unban(c);
xcb_set_input_focus(globalconf.connection, XCB_INPUT_FOCUS_POINTER_ROOT, globalconf.screen_focus = &globalconf.screens[c->screen];
c->win, XCB_CURRENT_TIME); globalconf.screen_focus->client_focus = c;
phys_screen = c->phys_screen;
/* Some layouts use focused client differently, so call them back. */ xcb_set_input_focus(globalconf.connection, XCB_INPUT_FOCUS_POINTER_ROOT,
globalconf.screens[c->screen].need_arrange = true; c->win, XCB_CURRENT_TIME);
/* execute hook */ /* Some layouts use focused client differently, so call them back.
luaA_client_userdata_new(globalconf.L, globalconf.screen_focus->client_focus); * And anyway, we have maybe unhidden */
luaA_dofunction(globalconf.L, globalconf.hooks.focus, 1, 0); globalconf.screens[c->screen].need_arrange = true;
}
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); /* execute hook */
widget_invalidate_cache(screen, WIDGET_CACHE_CLIENTS); luaA_client_userdata_new(globalconf.L, globalconf.screen_focus->client_focus);
luaA_dofunction(globalconf.L, globalconf.hooks.focus, 1, 0);
ewmh_update_net_active_window(c->phys_screen);
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;
} }

View File

@ -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 *);