From e40bfedd30da6b858e8b93d60fb77b539d5134ed Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Mon, 12 Sep 2011 19:38:20 +0200 Subject: [PATCH] drawin: Don't cause X11 errors during allocation We were only creating an X11 window for a new drawin after we handled all the options that were passed in. However, this means that drawin({ height = 4 }) would try to resize the window before we created a window, which caused an X11 error. Fix this by moving our initialization before of the handling of construction arguments. Signed-off-by: Uli Schlachter --- objects/drawin.c | 41 +++++++++++++++++++---------------------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/objects/drawin.c b/objects/drawin.c index 0cfaa065a..e5a03cdf4 100644 --- a/objects/drawin.c +++ b/objects/drawin.c @@ -333,6 +333,24 @@ drawin_set_visible(lua_State *L, int udx, bool v) } } +static drawin_t * +drawin_allocator(lua_State *L) +{ + drawin_t *w = drawin_new(L); + + w->visible = false; + + w->opacity = -1; + w->cursor = a_strdup("left_ptr"); + w->geometry.width = 1; + w->geometry.height = 1; + w->type = _NET_WM_WINDOW_TYPE_NORMAL; + + drawin_init(w); + + return w; +} + /** Create a new drawin. * \param L The Lua VM state. * \return The number of elements pushed on stack. @@ -342,27 +360,6 @@ luaA_drawin_new(lua_State *L) { luaA_class_new(L, &drawin_class); - drawin_t *w = luaA_checkudata(L, -1, &drawin_class); - - w->visible = false; - - if(!w->opacity) - w->opacity = -1; - - if(!w->cursor) - w->cursor = a_strdup("left_ptr"); - - if(!w->geometry.width) - w->geometry.width = 1; - - if(!w->geometry.height) - w->geometry.height = 1; - - if(w->type == 0) - w->type = _NET_WM_WINDOW_TYPE_NORMAL; - - drawin_init(w); - return 1; } @@ -596,7 +593,7 @@ drawin_class_setup(lua_State *L) }; luaA_class_setup(L, &drawin_class, "drawin", &window_class, - (lua_class_allocator_t) drawin_new, + (lua_class_allocator_t) drawin_allocator, (lua_class_collector_t) drawin_wipe, NULL, luaA_class_index_miss_property, luaA_class_newindex_miss_property,