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,26 +212,34 @@ client_ban(client_t *c)
/** Give focus to client, or to first client if client is NULL.
* \param c The client or NULL.
* \param screen Virtual screen number.
* \return True if a window (even root) has received focus, false otherwise.
*/
void
client_focus(client_t *c, int screen)
static void
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 */
if((!c || (c && (!client_isvisible(c, screen))))
&& !(c = globalconf.screens[screen].client_focus))
/* if c is still NULL take next client in the stack */
for(c = globalconf.clients; c && (c->skip || !client_isvisible(c, screen)); c = c->next);
/* Just check if the client is tagged with at least one visible tag.
* If so, we can give it the focus. */
for(int i = 0; i < tags->len; i++)
if(tags->tab[i]->selected && is_client_tagged(c, tags->tab[i]))
{
istagged = true;
break;
}
if(!istagged)
return;
/* 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);
if(c)
{
/* stop hiding c */
c->ishidden = false;
/* unban the client before focusing or it will fail */
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,
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;
/* execute hook */
luaA_client_userdata_new(globalconf.L, globalconf.screen_focus->client_focus);
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);
widget_invalidate_cache(screen, WIDGET_CACHE_CLIENTS);
ewmh_update_net_active_window(c->phys_screen);
widget_invalidate_cache(c->screen, WIDGET_CACHE_CLIENTS);
}
/** Restack clients.
@ -990,7 +989,7 @@ static int
luaA_client_focus_set(lua_State *L)
{
client_t **c = luaA_checkudata(L, 1, "client");
client_focus(*c, (*c)->screen);
client_focus(*c);
return 0;
}

View File

@ -28,7 +28,6 @@
bool client_isvisible(client_t *, int);
client_t * client_getbywin(xcb_window_t);
void client_focus(client_t *, int);
void client_setlayer(client_t *, layer_t);
void client_stack(void);
void client_raise(client_t *);