From 8d1f20c5adf221decde0c680ceec40f9f2c455ef Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Mon, 11 Aug 2008 11:57:57 +0200 Subject: [PATCH] client: implement maybevisible(), and use it for maprequest Signed-off-by: Julien Danjou --- client.c | 30 +++++++++++++++--------------- client.h | 1 + event.c | 3 ++- 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/client.c b/client.c index a2e5190a2..acf386646 100644 --- a/client.c +++ b/client.c @@ -123,9 +123,9 @@ window_isprotodel(xcb_window_t win) * \return true if the client is visible, false otherwise. */ 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; for(int i = 0; i < tags->len; i++) @@ -135,6 +135,18 @@ client_isvisible(client_t *c, int screen) 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. * \param w The client window to find. * \return A client pointer if found, NULL otherwise. @@ -217,19 +229,7 @@ client_ban(client_t *c) static void client_focus(client_t *c) { - bool istagged = false; - 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) + if(!client_maybevisible(c, c->screen)) return; /* unfocus current selected client */ diff --git a/client.h b/client.h index 393484f4d..5dddf9056 100644 --- a/client.h +++ b/client.h @@ -26,6 +26,7 @@ #include "structs.h" +bool client_maybevisible(client_t *, int); bool client_isvisible(client_t *, int); client_t * client_getbywin(xcb_window_t); void client_setlayer(client_t *, layer_t); diff --git a/event.c b/event.c index 95da39dce..7a726607f 100644 --- a/event.c +++ b/event.c @@ -458,8 +458,9 @@ event_handle_maprequest(void *data __attribute__ ((unused)), } 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); /* it will be raised, so just update ourself */ client_raise(c);