From 5fdb2c629847a3c393fb211ce17d8b4eac02d35f Mon Sep 17 00:00:00 2001 From: actionless Date: Sun, 2 Jul 2017 19:36:26 +0200 Subject: [PATCH 1/3] feat(beatiful: theme_assets; themes: xresources): recolor titlebar icons for `hover` and `press` states --- lib/beautiful/theme_assets.lua | 72 +++++++++++++++++++--------------- themes/xresources/theme.lua | 35 +++++++++++++++-- 2 files changed, 73 insertions(+), 34 deletions(-) diff --git a/lib/beautiful/theme_assets.lua b/lib/beautiful/theme_assets.lua index 083412d83..109e908f5 100644 --- a/lib/beautiful/theme_assets.lua +++ b/lib/beautiful/theme_assets.lua @@ -7,6 +7,7 @@ ---------------------------------------------------------------------------- local cairo = require("lgi").cairo +local surface = require("gears.surface") local gears_color = require("gears.color") local recolor_image = gears_color.recolor_image local screen = screen @@ -207,48 +208,57 @@ function theme_assets.wallpaper(bg, fg, alt_fg, s) return img end ---- Recolor unfocused titlebar icons. --- @tparam table theme Beautiful theme table +--- Recolor titlebar icons. +-- @tparam table theme Beautiful theme table. -- @tparam color color Icons' color. +-- @tparam string state `"normal"` or `"focus"`. +-- @tparam string postfix `nil`, `"hover"` or `"press"`. -- @treturn table Beautiful theme table with the images recolored. -function theme_assets.recolor_titlebar_normal(theme, color) - for _, titlebar_icon in ipairs({ - 'titlebar_close_button_normal', - 'titlebar_minimize_button_normal', - 'titlebar_ontop_button_normal_inactive', - 'titlebar_ontop_button_normal_active', - 'titlebar_sticky_button_normal_inactive', - 'titlebar_sticky_button_normal_active', - 'titlebar_floating_button_normal_inactive', - 'titlebar_floating_button_normal_active', - 'titlebar_maximized_button_normal_inactive', - 'titlebar_maximized_button_normal_active', +function theme_assets.recolor_titlebar(theme, color, state, postfix) + if postfix then postfix='_'..postfix end + for _, titlebar_icon_name in ipairs({ + 'titlebar_close_button_'..state..'', + 'titlebar_minimize_button_'..state..'', + 'titlebar_ontop_button_'..state..'_inactive', + 'titlebar_ontop_button_'..state..'_active', + 'titlebar_sticky_button_'..state..'_inactive', + 'titlebar_sticky_button_'..state..'_active', + 'titlebar_floating_button_'..state..'_inactive', + 'titlebar_floating_button_'..state..'_active', + 'titlebar_maximized_button_'..state..'_inactive', + 'titlebar_maximized_button_'..state..'_active', }) do - theme[titlebar_icon] = recolor_image(theme[titlebar_icon], color) + local full_name = postfix and ( + titlebar_icon_name .. postfix + ) or titlebar_icon_name + local image = theme[full_name] or theme[titlebar_icon_name] + if image then + image = surface.duplicate_surface(image) + theme[full_name] = recolor_image(image, color) + end end return theme end ---- Recolor focused titlebar icons. + +--- Recolor unfocused titlebar icons. +-- This method is deprecated. Use a `beautiful.theme_assets.recolor_titlebar`. -- @tparam table theme Beautiful theme table -- @tparam color color Icons' color. -- @treturn table Beautiful theme table with the images recolored. +-- @deprecated recolor_titlebar_normal +function theme_assets.recolor_titlebar_normal(theme, color) + return theme_assets.recolor_titlebar(theme, color, "normal") +end + +--- Recolor focused titlebar icons. +-- This method is deprecated. Use a `beautiful.theme_assets.recolor_titlebar`. +-- @tparam table theme Beautiful theme table +-- @tparam color color Icons' color. +-- @treturn table Beautiful theme table with the images recolored. +-- @deprecated recolor_titlebar_focus function theme_assets.recolor_titlebar_focus(theme, color) - for _, titlebar_icon in ipairs({ - 'titlebar_close_button_focus', - 'titlebar_minimize_button_focus', - 'titlebar_ontop_button_focus_inactive', - 'titlebar_ontop_button_focus_active', - 'titlebar_sticky_button_focus_inactive', - 'titlebar_sticky_button_focus_active', - 'titlebar_floating_button_focus_inactive', - 'titlebar_floating_button_focus_active', - 'titlebar_maximized_button_focus_inactive', - 'titlebar_maximized_button_focus_active', - }) do - theme[titlebar_icon] = recolor_image(theme[titlebar_icon], color) - end - return theme + return theme_assets.recolor_titlebar(theme, color, "focus") end --- Recolor layout icons. diff --git a/themes/xresources/theme.lua b/themes/xresources/theme.lua index 9ede10a98..e11a83c9e 100644 --- a/themes/xresources/theme.lua +++ b/themes/xresources/theme.lua @@ -59,11 +59,40 @@ theme.menu_width = dpi(100) -- beautiful.variable in your rc.lua --theme.bg_widget = "#cc0000" --- Recolor titlebar icons: -theme = theme_assets.recolor_titlebar_normal(theme, theme.fg_normal) -theme = theme_assets.recolor_titlebar_focus(theme, theme.fg_focus) +-- Recolor Layout icons: theme = theme_assets.recolor_layout(theme, theme.fg_normal) +-- Recolor titlebar icons: +-- +local function darker(color_value, darker_n) + local result = "#" + for s in color_value:gmatch("[a-fA-F0-9][a-fA-F0-9]") do + local bg_numeric_value = tonumber("0x"..s) - darker_n + if bg_numeric_value < 0 then bg_numeric_value = 0 end + if bg_numeric_value > 255 then bg_numeric_value = 255 end + result = result .. string.format("%2.2x", bg_numeric_value) + end + return result +end +theme = theme_assets.recolor_titlebar( + theme, theme.fg_normal, "normal" +) +theme = theme_assets.recolor_titlebar( + theme, darker(theme.fg_normal, -60), "normal", "hover" +) +theme = theme_assets.recolor_titlebar( + theme, xrdb.color1, "normal", "press" +) +theme = theme_assets.recolor_titlebar( + theme, theme.fg_focus, "focus" +) +theme = theme_assets.recolor_titlebar( + theme, darker(theme.fg_focus, -60), "focus", "hover" +) +theme = theme_assets.recolor_titlebar( + theme, xrdb.color1, "focus", "press" +) + -- Define the icon theme for application icons. If not set then the icons -- from /usr/share/icons and /usr/share/icons/hicolor will be used. theme.icon_theme = nil From eb7c203f990f0b0f7c983bd552612baabfe1c237 Mon Sep 17 00:00:00 2001 From: actionless Date: Mon, 3 Jul 2017 00:23:57 +0200 Subject: [PATCH 2/3] chore(travis): use `xresources` theme on one of the test targets --- .travis.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 4078e8ee3..ad03d6f44 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,7 +12,7 @@ env: matrix: - LUA=5.2 LUANAME=lua5.2 DO_COVERAGE=coveralls # Lua 5.3 isn't available in Ubuntu Trusty, so some magic below installs it. - - LUA=5.3 LUANAME=lua5.3 LUALIBRARY=/usr/lib/liblua.so DO_COVERAGE=codecov + - LUA=5.3 LUANAME=lua5.3 LUALIBRARY=/usr/lib/liblua.so DO_COVERAGE=codecov AWESOME_THEME=xresources # luajit: installed from source. - LUA=5.1 LUANAME=luajit-2.0 LUALIBRARY=/usr/lib/libluajit-5.1.so LUAROCKS_ARGS=--lua-suffix=jit-2.0.5 TEST_PREV_COMMITS=1 # Note: luarocks does not work with Lua 5.0. @@ -148,6 +148,10 @@ install: } script: - export CMAKE_ARGS="-DLUA_LIBRARY=${LUALIBRARY} -DLUA_INCLUDE_DIR=${LUAINCLUDE} -D OVERRIDE_VERSION=$AWESOME_VERSION -DSTRICT_TESTS=true" + - | + if [ ! -z "$AWESOME_THEME" ]; then + sed awesomerc.lua -i -e "s/default\/theme/$AWESOME_THEME\/theme/g" + fi - | if [ "$DO_COVERAGE" = "codecov" ]; then export CXXFLAGS="-fprofile-arcs -ftest-coverage" From 0488905fccf3db45afbd63de74ec0a20316ed7b9 Mon Sep 17 00:00:00 2001 From: actionless Date: Mon, 3 Jul 2017 01:01:03 +0200 Subject: [PATCH 3/3] fix(tests: screen-changes): take in account useless_gap --- tests/test-screen-changes.lua | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tests/test-screen-changes.lua b/tests/test-screen-changes.lua index 68d624ad6..12146c44b 100644 --- a/tests/test-screen-changes.lua +++ b/tests/test-screen-changes.lua @@ -47,10 +47,11 @@ local steps = { -- Everything should be done by now local geom = test_client2:geometry() local bw = test_client2.border_width - assert(geom.x == 100, geom.x) - assert(geom.y == 110, geom.y) - assert(geom.width + 2*bw == 600, geom.width + 2*bw) - assert(geom.height + 2*bw == 610, geom.height + 2*bw) + local ug = test_client2:tags()[1].gap + assert(geom.x - 2*ug == 100, geom.x - 2*ug) + assert(geom.y - 2*ug == 110, geom.y - 2*ug) + assert(geom.width + 2*bw + 4*ug == 600, geom.width + 2*bw + 4*ug) + assert(geom.height + 2*bw + 4*ug == 610, geom.height + 2*bw + 4*ug) local wb = fake_screen.mywibox assert(wb.screen == fake_screen, tostring(wb.screen) .. " ~= " .. tostring(fake_screen))