Merge pull request #1901 from actionless/xresources-titlebar-hover-press

feat(beatiful: theme_assets; themes: xresources): recolor titlebar icons for `hover` and `press` states
This commit is contained in:
Emmanuel Lepage Vallée 2017-07-10 10:11:50 -04:00 committed by GitHub
commit bb26c32726
4 changed files with 83 additions and 39 deletions

View File

@ -12,7 +12,7 @@ env:
matrix: matrix:
- LUA=5.2 LUANAME=lua5.2 DO_COVERAGE=coveralls - 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 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. # 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 - 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. # Note: luarocks does not work with Lua 5.0.
@ -148,6 +148,10 @@ install:
} }
script: script:
- export CMAKE_ARGS="-DLUA_LIBRARY=${LUALIBRARY} -DLUA_INCLUDE_DIR=${LUAINCLUDE} -D OVERRIDE_VERSION=$AWESOME_VERSION -DSTRICT_TESTS=true" - 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 if [ "$DO_COVERAGE" = "codecov" ]; then
export CXXFLAGS="-fprofile-arcs -ftest-coverage" export CXXFLAGS="-fprofile-arcs -ftest-coverage"

View File

@ -7,6 +7,7 @@
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
local cairo = require("lgi").cairo local cairo = require("lgi").cairo
local surface = require("gears.surface")
local gears_color = require("gears.color") local gears_color = require("gears.color")
local recolor_image = gears_color.recolor_image local recolor_image = gears_color.recolor_image
local screen = screen local screen = screen
@ -207,48 +208,57 @@ function theme_assets.wallpaper(bg, fg, alt_fg, s)
return img return img
end end
--- Recolor unfocused titlebar icons. --- Recolor titlebar icons.
-- @tparam table theme Beautiful theme table -- @tparam table theme Beautiful theme table.
-- @tparam color color Icons' color. -- @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. -- @treturn table Beautiful theme table with the images recolored.
function theme_assets.recolor_titlebar_normal(theme, color) function theme_assets.recolor_titlebar(theme, color, state, postfix)
for _, titlebar_icon in ipairs({ if postfix then postfix='_'..postfix end
'titlebar_close_button_normal', for _, titlebar_icon_name in ipairs({
'titlebar_minimize_button_normal', 'titlebar_close_button_'..state..'',
'titlebar_ontop_button_normal_inactive', 'titlebar_minimize_button_'..state..'',
'titlebar_ontop_button_normal_active', 'titlebar_ontop_button_'..state..'_inactive',
'titlebar_sticky_button_normal_inactive', 'titlebar_ontop_button_'..state..'_active',
'titlebar_sticky_button_normal_active', 'titlebar_sticky_button_'..state..'_inactive',
'titlebar_floating_button_normal_inactive', 'titlebar_sticky_button_'..state..'_active',
'titlebar_floating_button_normal_active', 'titlebar_floating_button_'..state..'_inactive',
'titlebar_maximized_button_normal_inactive', 'titlebar_floating_button_'..state..'_active',
'titlebar_maximized_button_normal_active', 'titlebar_maximized_button_'..state..'_inactive',
'titlebar_maximized_button_'..state..'_active',
}) do }) 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 end
return theme return theme
end 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 table theme Beautiful theme table
-- @tparam color color Icons' color. -- @tparam color color Icons' color.
-- @treturn table Beautiful theme table with the images recolored. -- @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) function theme_assets.recolor_titlebar_focus(theme, color)
for _, titlebar_icon in ipairs({ return theme_assets.recolor_titlebar(theme, color, "focus")
'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
end end
--- Recolor layout icons. --- Recolor layout icons.

View File

@ -47,10 +47,11 @@ local steps = {
-- Everything should be done by now -- Everything should be done by now
local geom = test_client2:geometry() local geom = test_client2:geometry()
local bw = test_client2.border_width local bw = test_client2.border_width
assert(geom.x == 100, geom.x) local ug = test_client2:tags()[1].gap
assert(geom.y == 110, geom.y) assert(geom.x - 2*ug == 100, geom.x - 2*ug)
assert(geom.width + 2*bw == 600, geom.width + 2*bw) assert(geom.y - 2*ug == 110, geom.y - 2*ug)
assert(geom.height + 2*bw == 610, geom.height + 2*bw) 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 local wb = fake_screen.mywibox
assert(wb.screen == fake_screen, tostring(wb.screen) .. " ~= " .. tostring(fake_screen)) assert(wb.screen == fake_screen, tostring(wb.screen) .. " ~= " .. tostring(fake_screen))

View File

@ -59,11 +59,40 @@ theme.menu_width = dpi(100)
-- beautiful.variable in your rc.lua -- beautiful.variable in your rc.lua
--theme.bg_widget = "#cc0000" --theme.bg_widget = "#cc0000"
-- Recolor titlebar icons: -- Recolor Layout icons:
theme = theme_assets.recolor_titlebar_normal(theme, theme.fg_normal)
theme = theme_assets.recolor_titlebar_focus(theme, theme.fg_focus)
theme = theme_assets.recolor_layout(theme, theme.fg_normal) 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 -- 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. -- from /usr/share/icons and /usr/share/icons/hicolor will be used.
theme.icon_theme = nil theme.icon_theme = nil