From c94f7b67679e733b8721c3dcf9d3a7e2b21ad07e Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Tue, 6 Oct 2009 19:04:36 +0200 Subject: [PATCH] window: import border_width property Signed-off-by: Julien Danjou --- event.c | 2 +- objects/client.c | 58 ++++-------------------------------------------- objects/client.h | 5 ++--- objects/wibox.c | 38 +++++++++---------------------- objects/wibox.h | 2 -- objects/window.c | 35 +++++++++++++++++++++++++++++ objects/window.h | 5 ++++- 7 files changed, 56 insertions(+), 89 deletions(-) diff --git a/event.c b/event.c index f3d04917..bcaea27e 100644 --- a/event.c +++ b/event.c @@ -276,7 +276,7 @@ event_handle_configurerequest(void *data __attribute__ ((unused)), if(ev->value_mask & XCB_CONFIG_WINDOW_BORDER_WIDTH) { luaA_object_push(globalconf.L, c); - client_set_border_width(globalconf.L, -1, ev->border_width); + window_set_border_width(globalconf.L, -1, ev->border_width); lua_pop(globalconf.L, 1); } diff --git a/objects/client.c b/objects/client.c index c2adbb8a..a70a0f1f 100644 --- a/objects/client.c +++ b/objects/client.c @@ -462,8 +462,8 @@ HANDLE_GEOM(height) luaA_object_emit_signal(globalconf.L, -1, "property::geometry", 0); - /* Push client */ - client_set_border_width(globalconf.L, -1, wgeom->border_width); + /* Set border width */ + window_set_border_width(globalconf.L, -1, wgeom->border_width); /* we honor size hints by default */ c->size_hints_honor = true; @@ -792,14 +792,14 @@ client_set_fullscreen(lua_State *L, int cidx, bool s) geometry = screen_area_get(c->screen, false); c->geometries.fullscreen = c->geometry; c->border_width_fs = c->border_width; - client_set_border_width(L, cidx, 0); + window_set_border_width(L, cidx, 0); c->fullscreen = true; } else { geometry = c->geometries.fullscreen; c->fullscreen = false; - client_set_border_width(L, cidx, c->border_width_fs); + window_set_border_width(L, cidx, c->border_width_fs); } client_resize(c, geometry, false); stack_windows(); @@ -1144,44 +1144,6 @@ luaA_client_isvisible(lua_State *L) return 1; } -/** Set client border width. - * \param L The Lua VM state. - * \param cidx The client index. - * \param width The border width. - */ -void -client_set_border_width(lua_State *L, int cidx, int width) -{ - client_t *c = luaA_checkudata(L, cidx, &client_class); - uint32_t w = width; - - if(width > 0 && (c->type == WINDOW_TYPE_DOCK - || c->type == WINDOW_TYPE_SPLASH - || c->type == WINDOW_TYPE_DESKTOP - || c->fullscreen)) - return; - - if(width == c->border_width || width < 0) - return; - - /* disallow change of border width if the client is fullscreen */ - if(c->fullscreen) - return; - - /* Update geometry with the new border. */ - c->geometry.width -= 2 * c->border_width; - c->geometry.height -= 2 * c->border_width; - - c->border_width = width; - xcb_configure_window(globalconf.connection, c->window, - XCB_CONFIG_WINDOW_BORDER_WIDTH, &w); - - c->geometry.width += 2 * c->border_width; - c->geometry.height += 2 * c->border_width; - - luaA_object_emit_signal(L, cidx, "property::border_width", 0); -} - /** Set a client icon. * \param L The Lua VM state. * \param cidx The client index on the stack. @@ -1451,13 +1413,6 @@ luaA_client_set_size_hints_honor(lua_State *L, client_t *c) return 0; } -static int -luaA_client_set_border_width(lua_State *L, client_t *c) -{ - client_set_border_width(L, -3, luaL_checknumber(L, -1)); - return 0; -} - static int luaA_client_set_ontop(lua_State *L, client_t *c) { @@ -1528,7 +1483,6 @@ LUA_OBJECT_EXPORT_PROPERTY(client, client_t, sticky, lua_pushboolean) LUA_OBJECT_EXPORT_PROPERTY(client, client_t, size_hints_honor, lua_pushboolean) LUA_OBJECT_EXPORT_PROPERTY(client, client_t, maximized_horizontal, lua_pushboolean) LUA_OBJECT_EXPORT_PROPERTY(client, client_t, maximized_vertical, lua_pushboolean) -LUA_OBJECT_EXPORT_PROPERTY(client, client_t, border_width, lua_pushnumber) static int luaA_client_get_content(lua_State *L, client_t *c) @@ -1964,10 +1918,6 @@ client_class_setup(lua_State *L) (lua_class_propfunc_t) luaA_client_set_size_hints_honor, (lua_class_propfunc_t) luaA_client_get_size_hints_honor, (lua_class_propfunc_t) luaA_client_set_size_hints_honor); - luaA_class_add_property(&client_class, A_TK_BORDER_WIDTH, - (lua_class_propfunc_t) luaA_client_set_border_width, - (lua_class_propfunc_t) luaA_client_get_border_width, - (lua_class_propfunc_t) luaA_client_set_border_width); luaA_class_add_property(&client_class, A_TK_URGENT, (lua_class_propfunc_t) luaA_client_set_urgent, (lua_class_propfunc_t) luaA_client_get_urgent, diff --git a/objects/client.h b/objects/client.h index 6ac75703..6761fade 100644 --- a/objects/client.h +++ b/objects/client.h @@ -79,8 +79,8 @@ struct client_t /** Internal geometry (matching X11 protocol) */ area_t internal; } geometries; - /** Border width and pre-fullscreen border width */ - int border_width, border_width_fs; + /** Pre-fullscreen border width */ + int border_width_fs; /** True if the client is sticky */ bool sticky; /** Has urgency hint */ @@ -164,7 +164,6 @@ void client_set_fullscreen(lua_State *, int, bool); void client_set_maximized_horizontal(lua_State *, int, bool); void client_set_maximized_vertical(lua_State *, int, bool); void client_set_minimized(lua_State *, int, bool); -void client_set_border_width(lua_State *, int, int); void client_set_urgent(lua_State *, int, bool); void client_set_pid(lua_State *, int, uint32_t); void client_set_role(lua_State *, int, char *); diff --git a/objects/wibox.c b/objects/wibox.c index abece00d..c0242831 100644 --- a/objects/wibox.c +++ b/objects/wibox.c @@ -751,6 +751,13 @@ wibox_attach(lua_State *L, int udx, screen_t *s) screen_emit_signal(L, wibox->screen, "property::workarea", 0); } +static int +luaA_wibox_need_update(lua_State *L) +{ + wibox_need_update(luaA_checkudata(L, 1, &wibox_class)); + return 0; +} + /** Create a new wibox. * \param L The Lua VM state. * \return The number of elements pushed on stack. @@ -782,6 +789,9 @@ luaA_wibox_new(lua_State *L) if(!w->geometry.height) w->geometry.height = 1; + lua_pushcfunction(L, luaA_wibox_need_update); + luaA_object_add_signal(L, -2, "property::border_width", -1); + return 1; } @@ -856,7 +866,6 @@ luaA_wibox_geometry(lua_State *L) LUA_OBJECT_EXPORT_PROPERTY(wibox, wibox_t, ontop, lua_pushboolean) LUA_OBJECT_EXPORT_PROPERTY(wibox, wibox_t, cursor, lua_pushstring) LUA_OBJECT_EXPORT_PROPERTY(wibox, wibox_t, visible, lua_pushboolean) -LUA_OBJECT_EXPORT_PROPERTY(wibox, wibox_t, border_width, lua_pushnumber) static int luaA_wibox_set_x(lua_State *L, wibox_t *wibox) @@ -1175,29 +1184,6 @@ luaA_wibox_get_widgets(lua_State *L, wibox_t *wibox) return luaA_object_push_item(L, 1, wibox->widgets_table); } -/** Set the wibox border width. - * \param L The Lua VM state. - * \param wibox The wibox object. - * \return The number of elements pushed on stack. - */ -static int -luaA_wibox_set_border_width(lua_State *L, wibox_t *wibox) -{ - wibox_t *w = luaA_checkudata(L, -3, &wibox_class); - int32_t border_width = luaL_checknumber(L, -1); - if(border_width != w->border_width && border_width >= 0) - { - if (w->window != XCB_NONE) - xcb_configure_window(globalconf.connection, w->window, XCB_CONFIG_WINDOW_BORDER_WIDTH, - (uint32_t[]) { border_width }); - w->border_width = border_width; - /* Need update if transparent background */ - wibox_need_update(w); - luaA_object_emit_signal(L, -3, "property::border_width", 0); - } - return 0; -} - static int luaA_wibox_set_shape_bounding(lua_State *L, wibox_t *wibox) { @@ -1264,10 +1250,6 @@ wibox_class_setup(lua_State *L) (lua_class_propfunc_t) luaA_wibox_set_visible, (lua_class_propfunc_t) luaA_wibox_get_visible, (lua_class_propfunc_t) luaA_wibox_set_visible); - luaA_class_add_property(&wibox_class, A_TK_BORDER_WIDTH, - (lua_class_propfunc_t) luaA_wibox_set_border_width, - (lua_class_propfunc_t) luaA_wibox_get_border_width, - (lua_class_propfunc_t) luaA_wibox_set_border_width); luaA_class_add_property(&wibox_class, A_TK_ORIENTATION, (lua_class_propfunc_t) luaA_wibox_set_orientation, (lua_class_propfunc_t) luaA_wibox_get_orientation, diff --git a/objects/wibox.h b/objects/wibox.h index 12e24ae6..d18b1a11 100644 --- a/objects/wibox.h +++ b/objects/wibox.h @@ -53,8 +53,6 @@ struct wibox_t xcb_gcontext_t gc; /** The window geometry. */ area_t geometry; - /** The window border width */ - uint16_t border_width; /** Draw context */ draw_context_t ctx; /** Orientation */ diff --git a/objects/window.c b/objects/window.c index d4c699f3..78256165 100644 --- a/objects/window.c +++ b/objects/window.c @@ -148,8 +148,39 @@ luaA_window_set_border_color(lua_State *L, window_t *window) return 0; } +/** Set a window border width. + * \param L The Lua VM state. + * \param idx The window index. + * \param width The border width. + */ +void +window_set_border_width(lua_State *L, int idx, int width) +{ + window_t *window = luaA_checkudata(L, idx, &window_class); + + if(width == window->border_width || width < 0) + return; + + if(window->window) + xcb_configure_window(globalconf.connection, window->window, + XCB_CONFIG_WINDOW_BORDER_WIDTH, + (uint32_t[]) { width }); + + window->border_width = width; + + luaA_object_emit_signal(L, idx, "property::border_width", 0); +} + +static int +luaA_window_set_border_width(lua_State *L, window_t *c) +{ + window_set_border_width(L, -3, luaL_checknumber(L, -1)); + return 0; +} + LUA_OBJECT_EXPORT_PROPERTY(window, window_t, window, lua_pushnumber) LUA_OBJECT_EXPORT_PROPERTY(window, window_t, border_color, luaA_pushxcolor) +LUA_OBJECT_EXPORT_PROPERTY(window, window_t, border_width, lua_pushnumber) void window_class_setup(lua_State *L) @@ -183,6 +214,10 @@ window_class_setup(lua_State *L) (lua_class_propfunc_t) luaA_window_set_border_color, (lua_class_propfunc_t) luaA_window_get_border_color, (lua_class_propfunc_t) luaA_window_set_border_color); + luaA_class_add_property(&window_class, A_TK_BORDER_WIDTH, + (lua_class_propfunc_t) luaA_window_set_border_width, + (lua_class_propfunc_t) luaA_window_get_border_width, + (lua_class_propfunc_t) luaA_window_set_border_width); } // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80 diff --git a/objects/window.h b/objects/window.h index 3a93ae5f..12a36d2e 100644 --- a/objects/window.h +++ b/objects/window.h @@ -39,7 +39,9 @@ /** Button bindings */ \ button_array_t buttons; \ /** Border color */ \ - xcolor_t border_color; + xcolor_t border_color; \ + /** Border width */ \ + uint16_t border_width; /** Window structure */ typedef struct @@ -52,6 +54,7 @@ lua_class_t window_class; void window_class_setup(lua_State *); void window_set_opacity(lua_State *, int, double); +void window_set_border_width(lua_State *, int, int); #endif // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80