From 07595ca6179083e302ae3596806261b8a71ab98b Mon Sep 17 00:00:00 2001 From: Dario Russo Date: Sat, 10 May 2014 00:08:42 -0400 Subject: [PATCH] systray: added definable icon spacing Default is 0. Customized by adding theme.systray_icon_spacing directive in theme. --- lib/wibox/widget/systray.lua.in | 9 ++++++--- systray.c | 14 ++++++++------ 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/lib/wibox/widget/systray.lua.in b/lib/wibox/widget/systray.lua.in index 9d340b19c..dc59590d3 100644 --- a/lib/wibox/widget/systray.lua.in +++ b/lib/wibox/widget/systray.lua.in @@ -23,6 +23,7 @@ function systray:draw(wibox, cr, width, height) local x, y, _, _ = lbase.rect_to_device_geometry(cr, 0, 0, width, height) local num_entries = capi.awesome.systray() local bg = beautiful.bg_systray or beautiful.bg_normal or "#000000" + local spacing = beautiful.systray_icon_spacing or 0 -- Figure out if the cairo context is rotated local dir_x, dir_y = cr:user_to_device_distance(1, 0) @@ -40,12 +41,13 @@ function systray:draw(wibox, cr, width, height) else base = in_dir / num_entries end - capi.awesome.systray(wibox.drawin, x, y, base, is_rotated, bg, reverse) + capi.awesome.systray(wibox.drawin, x, y, base, is_rotated, bg, reverse, spacing) end function systray:fit(width, height) local num_entries = capi.awesome.systray() local base = base_size + local spacing = beautiful.systray_icon_spacing or 0 if base == nil then if width < height then base = width @@ -53,10 +55,11 @@ function systray:fit(width, height) base = height end end + base = base + spacing if horizontal then - return base * num_entries, base + return base * num_entries - spacing, base end - return base, base * num_entries + return base, base * num_entries - spacing end local function new(revers) diff --git a/systray.c b/systray.c index 5f2bb413f..fa0b2d665 100644 --- a/systray.c +++ b/systray.c @@ -268,7 +268,7 @@ luaA_systray_invalidate(void) } static void -systray_update(int base_size, bool horizontal, bool reverse) +systray_update(int base_size, bool horizontal, bool reverse, int spacing) { if(base_size <= 0) return; @@ -276,9 +276,9 @@ systray_update(int base_size, bool horizontal, bool reverse) /* Give the systray window the correct size */ uint32_t config_vals[4] = { base_size, base_size, 0, 0 }; if(horizontal) - config_vals[0] = base_size * globalconf.embedded.len; + config_vals[0] = base_size * globalconf.embedded.len + spacing * (globalconf.embedded.len - 1); else - config_vals[1] = base_size * globalconf.embedded.len; + config_vals[1] = base_size * globalconf.embedded.len + spacing * (globalconf.embedded.len - 1); xcb_configure_window(globalconf.connection, globalconf.systray.window, XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT, @@ -301,9 +301,9 @@ systray_update(int base_size, bool horizontal, bool reverse) config_vals); xcb_map_window(globalconf.connection, em->win); if(horizontal) - config_vals[0] += base_size; + config_vals[0] += base_size + spacing; else - config_vals[1] += base_size; + config_vals[1] += base_size + spacing; } } @@ -318,6 +318,7 @@ systray_update(int base_size, bool horizontal, bool reverse) * \lparam horiz If true, the systray is horizontal, else vertical * \lparam bg Color of the systray background * \lparam revers If true, the systray icon order will be reversed, else default + * \lparam spacing The size of the spacing between icons */ int luaA_systray(lua_State *L) @@ -332,6 +333,7 @@ luaA_systray(lua_State *L) bool horiz = lua_toboolean(L, 5); const char *bg = luaL_checklstring(L, 6, &bg_len); bool revers = lua_toboolean(L, 7); + int spacing = luaL_checknumber(L, 8); color_t bg_color; if(color_init_reply(color_init_unchecked(&bg_color, bg, bg_len))) @@ -363,7 +365,7 @@ luaA_systray(lua_State *L) if(globalconf.embedded.len != 0) { - systray_update(base_size, horiz, revers); + systray_update(base_size, horiz, revers, spacing); xcb_map_window(globalconf.connection, globalconf.systray.window); }