From 88c76cadf43b61f4f9416e47e9a0fc708923a362 Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Tue, 10 Jun 2008 19:35:38 +0200 Subject: [PATCH] [titlebar] Allow nil to be arg of titlebar_set() Signed-off-by: Julien Danjou --- client.c | 28 ++++++++++++++++++++-------- titlebar.c | 9 ++------- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/client.c b/client.c index 75995d62..27eebb73 100644 --- a/client.c +++ b/client.c @@ -1286,19 +1286,31 @@ static int luaA_client_titlebar_set(lua_State *L) { client_t **c = luaA_checkudata(L, 1, "client"); - titlebar_t **t = luaA_checkudata(L, 2, "titlebar"); - - if(client_getbytitlebar(*t)) - luaL_error(L, "titlebar is already used by another client"); + titlebar_t **t = NULL; + + if(lua_gettop(L) == 2) + { + t = luaA_checkudata(L, 2, "titlebar"); + if(client_getbytitlebar(*t)) + luaL_error(L, "titlebar is already used by another client"); + } /* If client had a titlebar, unref it */ if((*c)->titlebar) + { titlebar_unref(&(*c)->titlebar); + simplewindow_delete(&(*c)->titlebar->sw); + } - /* Attach titlebar to client */ - (*c)->titlebar = *t; - titlebar_ref(t); - titlebar_init(*c); + if(t) + { + /* Attach titlebar to client */ + (*c)->titlebar = *t; + titlebar_ref(t); + titlebar_init(*c); + } + else + (*c)->titlebar = NULL; if((*c)->isfloating || layout_get_current((*c)->screen) == layout_floating) titlebar_update_geometry_floating(*c); diff --git a/titlebar.c b/titlebar.c index 324e2db1..25e1d6d0 100644 --- a/titlebar.c +++ b/titlebar.c @@ -368,8 +368,6 @@ titlebar_init(client_t *c) { default: c->titlebar->position = Off; - if(c->titlebar->sw) - xcb_unmap_window(globalconf.connection, c->titlebar->sw->window); return; case Top: case Bottom: @@ -389,12 +387,9 @@ titlebar_init(client_t *c) break; } - /* Delete old statusbar */ - simplewindow_delete(&c->titlebar->sw); - c->titlebar->sw = simplewindow_new(globalconf.connection, - c->phys_screen, 0, 0, - width, height, 0); + c->phys_screen, 0, 0, + width, height, 0); titlebar_draw(c); xcb_map_window(globalconf.connection, c->titlebar->sw->window); }