mirror of
https://github.com/awesomeWM/awesome
synced 2024-11-17 07:47:41 +01:00
feat(beatiful: theme_assets; themes: xresources): recolor titlebar icons for hover
and press
states
This commit is contained in:
parent
9ace887caa
commit
5fdb2c6298
2 changed files with 73 additions and 34 deletions
|
@ -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.
|
||||||
function theme_assets.recolor_titlebar_focus(theme, color)
|
-- @deprecated recolor_titlebar_normal
|
||||||
for _, titlebar_icon in ipairs({
|
function theme_assets.recolor_titlebar_normal(theme, color)
|
||||||
'titlebar_close_button_focus',
|
return theme_assets.recolor_titlebar(theme, color, "normal")
|
||||||
'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
|
end
|
||||||
return theme
|
|
||||||
|
--- 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)
|
||||||
|
return theme_assets.recolor_titlebar(theme, color, "focus")
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Recolor layout icons.
|
--- Recolor layout icons.
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in a new issue