client: implement maybevisible(), and use it for maprequest

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2008-08-11 11:57:57 +02:00
parent 4b2293d43d
commit 8d1f20c5ad
3 changed files with 18 additions and 16 deletions

View File

@ -123,9 +123,9 @@ window_isprotodel(xcb_window_t win)
* \return true if the client is visible, false otherwise. * \return true if the client is visible, false otherwise.
*/ */
bool bool
client_isvisible(client_t *c, int screen) client_maybevisible(client_t *c, int screen)
{ {
if(c && !c->ishidden && c->screen == screen) if(c->screen == screen)
{ {
tag_array_t *tags = &globalconf.screens[screen].tags; tag_array_t *tags = &globalconf.screens[screen].tags;
for(int i = 0; i < tags->len; i++) for(int i = 0; i < tags->len; i++)
@ -135,6 +135,18 @@ client_isvisible(client_t *c, int screen)
return false; return false;
} }
/** Returns true if a client is tagged
* with one of the tags of the specified screen and is not hidden.
* \param c The client to check.
* \param screen Virtual screen number.
* \return true if the client is visible, false otherwise.
*/
bool
client_isvisible(client_t *c, int screen)
{
return (!c->ishidden && client_maybevisible(c, screen));
}
/** Get a client by its window. /** Get a client by its window.
* \param w The client window to find. * \param w The client window to find.
* \return A client pointer if found, NULL otherwise. * \return A client pointer if found, NULL otherwise.
@ -217,19 +229,7 @@ client_ban(client_t *c)
static void static void
client_focus(client_t *c) client_focus(client_t *c)
{ {
bool istagged = false; if(!client_maybevisible(c, c->screen))
tag_array_t *tags = &globalconf.screens[c->screen].tags;
/* 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; return;
/* unfocus current selected client */ /* unfocus current selected client */

View File

@ -26,6 +26,7 @@
#include "structs.h" #include "structs.h"
bool client_maybevisible(client_t *, int);
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_setlayer(client_t *, layer_t); void client_setlayer(client_t *, layer_t);

View File

@ -458,8 +458,9 @@ event_handle_maprequest(void *data __attribute__ ((unused)),
} }
else if((c = client_getbywin(ev->window))) else if((c = client_getbywin(ev->window)))
{ {
if(client_isvisible(c, c->screen)) if(client_maybevisible(c, c->screen))
{ {
c->ishidden = false;
xcb_map_window(globalconf.connection, ev->window); xcb_map_window(globalconf.connection, ev->window);
/* it will be raised, so just update ourself */ /* it will be raised, so just update ourself */
client_raise(c); client_raise(c);