systray: added definable icon spacing

Default is 0. Customized by adding theme.systray_icon_spacing
directive in theme.
This commit is contained in:
Dario Russo 2014-05-10 00:08:42 -04:00 committed by Dario Russo
parent 9fce440078
commit 07595ca617
2 changed files with 14 additions and 9 deletions

View File

@ -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 x, y, _, _ = lbase.rect_to_device_geometry(cr, 0, 0, width, height)
local num_entries = capi.awesome.systray() local num_entries = capi.awesome.systray()
local bg = beautiful.bg_systray or beautiful.bg_normal or "#000000" 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 -- Figure out if the cairo context is rotated
local dir_x, dir_y = cr:user_to_device_distance(1, 0) local dir_x, dir_y = cr:user_to_device_distance(1, 0)
@ -40,12 +41,13 @@ function systray:draw(wibox, cr, width, height)
else else
base = in_dir / num_entries base = in_dir / num_entries
end 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 end
function systray:fit(width, height) function systray:fit(width, height)
local num_entries = capi.awesome.systray() local num_entries = capi.awesome.systray()
local base = base_size local base = base_size
local spacing = beautiful.systray_icon_spacing or 0
if base == nil then if base == nil then
if width < height then if width < height then
base = width base = width
@ -53,10 +55,11 @@ function systray:fit(width, height)
base = height base = height
end end
end end
base = base + spacing
if horizontal then if horizontal then
return base * num_entries, base return base * num_entries - spacing, base
end end
return base, base * num_entries return base, base * num_entries - spacing
end end
local function new(revers) local function new(revers)

View File

@ -268,7 +268,7 @@ luaA_systray_invalidate(void)
} }
static 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) if(base_size <= 0)
return; return;
@ -276,9 +276,9 @@ systray_update(int base_size, bool horizontal, bool reverse)
/* Give the systray window the correct size */ /* Give the systray window the correct size */
uint32_t config_vals[4] = { base_size, base_size, 0, 0 }; uint32_t config_vals[4] = { base_size, base_size, 0, 0 };
if(horizontal) if(horizontal)
config_vals[0] = base_size * globalconf.embedded.len; config_vals[0] = base_size * globalconf.embedded.len + spacing * (globalconf.embedded.len - 1);
else 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, xcb_configure_window(globalconf.connection,
globalconf.systray.window, globalconf.systray.window,
XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT, XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT,
@ -301,9 +301,9 @@ systray_update(int base_size, bool horizontal, bool reverse)
config_vals); config_vals);
xcb_map_window(globalconf.connection, em->win); xcb_map_window(globalconf.connection, em->win);
if(horizontal) if(horizontal)
config_vals[0] += base_size; config_vals[0] += base_size + spacing;
else 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 horiz If true, the systray is horizontal, else vertical
* \lparam bg Color of the systray background * \lparam bg Color of the systray background
* \lparam revers If true, the systray icon order will be reversed, else default * \lparam revers If true, the systray icon order will be reversed, else default
* \lparam spacing The size of the spacing between icons
*/ */
int int
luaA_systray(lua_State *L) luaA_systray(lua_State *L)
@ -332,6 +333,7 @@ luaA_systray(lua_State *L)
bool horiz = lua_toboolean(L, 5); bool horiz = lua_toboolean(L, 5);
const char *bg = luaL_checklstring(L, 6, &bg_len); const char *bg = luaL_checklstring(L, 6, &bg_len);
bool revers = lua_toboolean(L, 7); bool revers = lua_toboolean(L, 7);
int spacing = luaL_checknumber(L, 8);
color_t bg_color; color_t bg_color;
if(color_init_reply(color_init_unchecked(&bg_color, bg, bg_len))) 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) if(globalconf.embedded.len != 0)
{ {
systray_update(base_size, horiz, revers); systray_update(base_size, horiz, revers, spacing);
xcb_map_window(globalconf.connection, xcb_map_window(globalconf.connection,
globalconf.systray.window); globalconf.systray.window);
} }