From 5449374e3daba28377fcb6a347f3493c602b245a Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Thu, 21 Aug 2008 15:36:54 +0200 Subject: [PATCH] client: check for visibility before arranging Signed-off-by: Julien Danjou --- client.c | 29 +++++++++++++++-------------- client.h | 7 +++++++ event.c | 22 ++++++++++++---------- ewmh.c | 7 ++++++- screen.c | 6 ++++-- tag.c | 6 +++--- titlebar.c | 12 +++++------- 7 files changed, 52 insertions(+), 37 deletions(-) diff --git a/client.c b/client.c index 81a77da5..b104d624 100644 --- a/client.c +++ b/client.c @@ -255,7 +255,7 @@ client_focus(client_t *c) /* Some layouts use focused client differently, so call them back. * And anyway, we have maybe unhidden */ - globalconf.screens[c->screen].need_arrange = true; + client_need_arrange(c); /* execute hook */ luaA_client_userdata_new(globalconf.L, globalconf.screen_focus->client_focus); @@ -623,8 +623,7 @@ client_setfloating(client_t *c, bool floating) } else client_setlayer(c, c->oldlayer); - if(client_isvisible(c, c->screen)) - globalconf.screens[c->screen].need_arrange = true; + client_need_arrange(c); widget_invalidate_cache(c->screen, WIDGET_CACHE_CLIENTS); client_saveprops(c); } @@ -928,10 +927,13 @@ client_setborder(client_t *c, int width) xcb_configure_window(globalconf.connection, c->win, XCB_CONFIG_WINDOW_BORDER_WIDTH, &w); - if(c->isfloating || layout_get_current(c->screen) == layout_floating) - titlebar_update_geometry_floating(c); - else - globalconf.screens[c->screen].need_arrange = true; + if(client_isvisible(c, c->screen)) + { + if(c->isfloating || layout_get_current(c->screen) == layout_floating) + titlebar_update_geometry_floating(c); + else + globalconf.screens[c->screen].need_arrange = true; + } } /** Kill a client. @@ -960,8 +962,8 @@ luaA_client_swap(lua_State *L) client_t **c = luaA_checkudata(L, 1, "client"); client_t **swap = luaA_checkudata(L, 2, "client"); client_list_swap(&globalconf.clients, *swap, *c); - globalconf.screens[(*c)->screen].need_arrange = true; - globalconf.screens[(*swap)->screen].need_arrange = true; + client_need_arrange(*c); + client_need_arrange(*swap); widget_invalidate_cache((*c)->screen, WIDGET_CACHE_CLIENTS); widget_invalidate_cache((*swap)->screen, WIDGET_CACHE_CLIENTS); return 0; @@ -1155,9 +1157,9 @@ luaA_client_newindex(lua_State *L) b = luaA_checkboolean(L, 3); if(b != (*c)->ishidden) { + client_need_arrange(*c); (*c)->ishidden = b; - if(client_maybevisible(*c, (*c)->screen)) - globalconf.screens[(*c)->screen].need_arrange = true; + client_need_arrange(*c); } break; case A_TK_ICON_PATH: @@ -1181,8 +1183,7 @@ luaA_client_newindex(lua_State *L) break; case A_TK_HONORSIZEHINTS: (*c)->honorsizehints = luaA_checkboolean(L, 3); - if(client_isvisible(*c, (*c)->screen)) - globalconf.screens[(*c)->screen].need_arrange = true; + client_need_arrange(*c); break; case A_TK_BORDER_WIDTH: client_setborder(*c, luaL_checknumber(L, 3)); @@ -1211,7 +1212,7 @@ luaA_client_newindex(lua_State *L) simplewindow_delete(&(*c)->titlebar->sw); titlebar_unref(&(*c)->titlebar); (*c)->titlebar = NULL; - globalconf.screens[(*c)->screen].need_arrange = true; + client_need_arrange(*c); } if(t) diff --git a/client.h b/client.h index ba8aba9c..14a33463 100644 --- a/client.h +++ b/client.h @@ -26,6 +26,13 @@ #include "structs.h" +#define client_need_arrange(c) \ + do { \ + if(!globalconf.screens[(c)->screen].need_arrange \ + && client_isvisible(c, (c)->screen)) \ + globalconf.screens[(c)->screen].need_arrange = true; \ + } while(0) + bool client_maybevisible(client_t *, int); bool client_isvisible(client_t *, int); client_t * client_getbywin(xcb_window_t); diff --git a/event.c b/event.c index 7bbeda99..a5cccfd3 100644 --- a/event.c +++ b/event.c @@ -221,7 +221,7 @@ event_handle_configurerequest(void *data __attribute__ ((unused)), } else { - globalconf.screens[c->screen].need_arrange = true; + client_need_arrange(c); /* If we do not resize the client, at least tell it that it * has its new configuration. That fixes at least * gnome-terminal */ @@ -531,7 +531,6 @@ event_handle_propertynotify(void *data __attribute__ ((unused)), xcb_connection_t *connection, xcb_property_notify_event_t *ev) { client_t *c; - xcb_window_t trans; xembed_window_t *emwin; xcb_size_hints_t size_hints; @@ -543,13 +542,16 @@ event_handle_propertynotify(void *data __attribute__ ((unused)), { if(ev->atom == WM_TRANSIENT_FOR) { - xcb_get_wm_transient_for_reply(connection, - xcb_get_wm_transient_for_unchecked(connection, - c->win), - &trans, NULL); - if(!c->isfloating - && (c->isfloating = (client_getbywin(trans) != NULL))) - globalconf.screens[c->screen].need_arrange = true; + if(!c->isfloating) + { + xcb_window_t trans; + xcb_get_wm_transient_for_reply(connection, + xcb_get_wm_transient_for_unchecked(connection, + c->win), + &trans, NULL); + if(client_getbywin(trans)) + client_setfloating(c, true); + } } else if (ev->atom == WM_NORMAL_HINTS) client_updatesizehints(c, &size_hints); @@ -652,8 +654,8 @@ event_handle_clientmessage(void *data __attribute__ ((unused)), && ev->format == 32 && ev->data.data32[0] == XCB_WM_STATE_ICONIC) { + client_need_arrange(c); c->ishidden = true; - globalconf.screens[c->screen].need_arrange = true; } } else if(ev->type == _XEMBED) diff --git a/ewmh.c b/ewmh.c index b508f838..a15f8940 100644 --- a/ewmh.c +++ b/ewmh.c @@ -343,10 +343,15 @@ ewmh_process_state_atom(client_t *c, xcb_atom_t state, int set) else if(state == _NET_WM_STATE_HIDDEN) { if(set == _NET_WM_STATE_REMOVE) + { + client_need_arrange(c); c->ishidden = false; + } else if(set == _NET_WM_STATE_ADD) + { + client_need_arrange(c); c->ishidden = true; - globalconf.screens[c->screen].need_arrange = true; + } } else if(state == _NET_WM_STATE_DEMANDS_ATTENTION) { diff --git a/screen.c b/screen.c index eef42e66..ce6daa68 100644 --- a/screen.c +++ b/screen.c @@ -132,6 +132,7 @@ screen_client_moveto(client_t *c, int new_screen, bool doresize) tag_array_t *old_tags = &globalconf.screens[old_screen].tags, *new_tags = &globalconf.screens[new_screen].tags; area_t from, to; + bool wasvisible = client_isvisible(c, c->screen); c->screen = new_screen; @@ -210,8 +211,9 @@ screen_client_moveto(client_t *c, int new_screen, bool doresize) else { c->f_geometry = new_f_geometry; - globalconf.screens[old_screen].need_arrange = true; - globalconf.screens[c->screen].need_arrange = true; + if(wasvisible) + globalconf.screens[old_screen].need_arrange = true; + client_need_arrange(c); } } } diff --git a/tag.c b/tag.c index cbe25d0e..e5c4ed57 100644 --- a/tag.c +++ b/tag.c @@ -135,7 +135,7 @@ tag_client(client_t *c, tag_t *t) client_array_append(&t->clients, c); client_saveprops(c); widget_invalidate_cache(c->screen, WIDGET_CACHE_CLIENTS); - globalconf.screens[c->screen].need_arrange = true; + client_need_arrange(c); } /** Untag a client with specified tag. @@ -148,11 +148,11 @@ untag_client(client_t *c, tag_t *t) for(int i = 0; i < t->clients.len; i++) if(t->clients.tab[i] == c) { + client_need_arrange(c); client_array_take(&t->clients, i); tag_unref(&t); client_saveprops(c); widget_invalidate_cache(c->screen, WIDGET_CACHE_CLIENTS); - globalconf.screens[c->screen].need_arrange = true; return; } } @@ -471,7 +471,7 @@ luaA_tag_newindex(lua_State *L) return 0; } - if((*tag)->screen != SCREEN_UNDEF) + if((*tag)->screen != SCREEN_UNDEF && (*tag)->selected) globalconf.screens[(*tag)->screen].need_arrange = true; return 0; diff --git a/titlebar.c b/titlebar.c index f8866051..e6ba40cb 100644 --- a/titlebar.c +++ b/titlebar.c @@ -290,8 +290,7 @@ titlebar_init(client_t *c) xcb_change_window_attributes(globalconf.connection, c->titlebar->sw->window, XCB_CW_BORDER_PIXEL, &c->titlebar->border.color.pixel); - if(client_isvisible(c, c->screen)) - globalconf.screens[c->screen].need_arrange = true; + client_need_arrange(c); c->titlebar->need_update = true; } @@ -388,7 +387,7 @@ luaA_titlebar_newindex(lua_State *L) simplewindow_delete(&(*newc)->titlebar->sw); titlebar_unref(&(*newc)->titlebar); (*newc)->titlebar = NULL; - globalconf.screens[(*newc)->screen].need_arrange = true; + client_need_arrange(*newc); } /* Attach titlebar to client */ (*newc)->titlebar = *titlebar; @@ -404,7 +403,7 @@ luaA_titlebar_newindex(lua_State *L) /* unref and NULL the ref */ titlebar_unref(&c->titlebar); c->titlebar = NULL; - globalconf.screens[c->screen].need_arrange = true; + client_need_arrange(c); } } break; @@ -463,9 +462,8 @@ luaA_titlebar_newindex(lua_State *L) return 0; } - if((c || (c = client_getbytitlebar(*titlebar))) - && client_isvisible(c, c->screen)) - globalconf.screens[c->screen].need_arrange = true; + if((c || (c = client_getbytitlebar(*titlebar)))) + client_need_arrange(c); return 0; }