fix volume and backlight OSD(new dependency) fix icon_handler causing crash if client had no .class or .name prop

This commit is contained in:
Rene Kievits
2022-04-20 10:29:05 +02:00
parent fbd7d5e920
commit b11fa86729
7 changed files with 120 additions and 86 deletions

View File

@@ -207,11 +207,12 @@ return gears.table.join(
{},
"XF86AudioLowerVolume",
function(c)
awful.spawn.easy_async("pactl set-sink-volume @DEFAULT_SINK@ -2%")
awesome.emit_signal("widget::volume")
awesome.emit_signal("module::volume_osd:show", true)
awesome.emit_signal("module::slider:update")
awesome.emit_signal("widget::volume_osd:rerun")
awful.spawn.easy_async_with_shell("pactl set-sink-volume @DEFAULT_SINK@ -2%", function()
awesome.emit_signal("widget::volume")
awesome.emit_signal("module::volume_osd:show", true)
awesome.emit_signal("module::slider:update")
awesome.emit_signal("widget::volume_osd:rerun")
end)
end,
{ description = "Lower volume", group = "System" }
),
@@ -219,11 +220,12 @@ return gears.table.join(
{},
"XF86AudioRaiseVolume",
function(c)
awful.spawn.easy_async("pactl set-sink-volume @DEFAULT_SINK@ +2%")
awesome.emit_signal("widget::volume")
awesome.emit_signal("module::volume_osd:show", true)
awesome.emit_signal("module::slider:update")
awesome.emit_signal("widget::volume_osd:rerun")
awful.spawn.easy_async_with_shell("pactl set-sink-volume @DEFAULT_SINK@ +2%", function()
awesome.emit_signal("widget::volume")
awesome.emit_signal("module::volume_osd:show", true)
awesome.emit_signal("module::slider:update")
awesome.emit_signal("widget::volume_osd:rerun")
end)
end,
{ description = "Increase volume", group = "System" }
),
@@ -243,10 +245,18 @@ return gears.table.join(
{},
"XF86MonBrightnessUp",
function(c)
awful.spawn("xbacklight -time 100 -inc 10%+")
awesome.emit_signal("module::brightness_osd:show", true)
awesome.emit_signal("module::brightness_slider:update")
awesome.emit_signal("widget::brightness_osd:rerun")
--awful.spawn("xbacklight -time 100 -inc 10%+")
awful.spawn.easy_async_with_shell(
"pkexec xfpm-power-backlight-helper --get-brightness",
function(stdout)
awful.spawn.easy_async_with_shell("pkexec xfpm-power-backlight-helper --set-brightness " .. tostring(tonumber(stdout) + BACKLIGHT_SEPS), function(stdou2)
end)
awesome.emit_signal("module::brightness_osd:show", true)
awesome.emit_signal("module::brightness_slider:update")
awesome.emit_signal("widget::brightness_osd:rerun")
end
)
end,
{ description = "Raise backlight brightness", group = "System" }
),
@@ -254,10 +264,17 @@ return gears.table.join(
{},
"XF86MonBrightnessDown",
function(c)
awful.spawn("xbacklight -time 100 -dec 10%-")
awesome.emit_signal("widget::brightness_osd:rerun")
awesome.emit_signal("module::brightness_osd:show", true)
awesome.emit_signal("module::brightness_slider:update")
awful.spawn.easy_async_with_shell(
"pkexec xfpm-power-backlight-helper --get-brightness",
function(stdout)
awful.spawn.easy_async_with_shell("pkexec xfpm-power-backlight-helper --set-brightness " .. tostring(tonumber(stdout) - BACKLIGHT_SEPS), function(stdout2)
end)
awesome.emit_signal("module::brightness_osd:show", true)
awesome.emit_signal("module::brightness_slider:update")
awesome.emit_signal("widget::brightness_osd:rerun")
end
)
end,
{ description = "Lower backlight brightness", group = "System" }
),

View File

@@ -15,4 +15,4 @@ require("src.core.signals")
require("mappings.global_buttons")
require("mappings.bind_to_tags")
require("crylia_bar.init")
require("src.tools.auto_starter")(user_vars.autostart)
--require("src.tools.auto_starter")(user_vars.autostart)

Binary file not shown.

Before

Width:  |  Height:  |  Size: 292 KiB

After

Width:  |  Height:  |  Size: 245 KiB

View File

@@ -12,7 +12,17 @@ local wibox = require("wibox")
-- Icon directory path
local icondir = awful.util.getdir("config") .. "src/assets/icons/brightness/"
-- TODO: fix backlight keys and osd not working correctly
BACKLIGHT_MAX_BRIGHTNESS = 0
BACKLIGHT_SEPS = 0
awful.spawn.easy_async_with_shell(
"pkexec xfpm-power-backlight-helper --get-max-brightness",
function(stdout)
BACKLIGHT_MAX_BRIGHTNESS = tonumber(stdout)
BACKLIGHT_SEPS = BACKLIGHT_MAX_BRIGHTNESS / 100
BACKLIGHT_SEPS = math.floor(BACKLIGHT_SEPS)
end
)
return function(s)
local brightness_osd_widget = wibox.widget {
@@ -102,41 +112,46 @@ return function(s)
brightness_osd_widget.container.osd_layout.icon_slider_layout.slider_layout.brightness_slider:connect_signal(
"property::value",
function()
local brightness_value = brightness_osd_widget.container.osd_layout.icon_slider_layout.slider_layout.brightness_slider:get_value()
-- Performance is horrible, or it overrides and executes at the same time as the keymappings
--awful.spawn("xbacklight -set " .. brightness_value, false)
brightness_osd_widget.container.osd_layout.icon_slider_layout.label_value_layout.value:set_text(brightness_value .. "%")
awful.spawn.easy_async_with_shell(
"pkexec xfpm-power-backlight-helper --get-brightness",
function(stdout)
local brightness_value = math.floor((tonumber(stdout) - 1) / (BACKLIGHT_MAX_BRIGHTNESS - 1) * 100)
-- Performance is horrible, or it overrides and executes at the same time as the keymappings
--awful.spawn("xbacklight -set " .. brightness_value, false)
brightness_osd_widget.container.osd_layout.icon_slider_layout.label_value_layout.value:set_text(tostring(brightness_value) .. "%")
awesome.emit_signal(
"widget::brightness:update",
brightness_value
awesome.emit_signal(
"widget::brightness:update",
brightness_value
)
if awful.screen.focused().show_brightness_osd then
awesome.emit_signal(
"module::brightness_osd:show",
true
)
end
local icon = icondir .. "brightness"
if brightness_value >= 0 and brightness_value < 34 then
icon = icon .. "-low"
elseif brightness_value >= 34 and brightness_value < 67 then
icon = icon .. "-medium"
elseif brightness_value >= 67 then
icon = icon .. "-high"
end
brightness_osd_widget.container.osd_layout.icon_slider_layout.icon_margin1.icon_margin2.icon:set_image(icon .. ".svg")
end
)
if awful.screen.focused().show_brightness_osd then
awesome.emit_signal(
"module::brightness_osd:show",
true
)
end
local icon = icondir .. "brightness"
if brightness_value >= 0 and brightness_value < 34 then
icon = icon .. "-low"
elseif brightness_value >= 34 and brightness_value < 67 then
icon = icon .. "-medium"
elseif brightness_value >= 67 then
icon = icon .. "-high"
end
brightness_osd_widget.container.osd_layout.icon_slider_layout.icon_margin1.icon_margin2.icon:set_image(icon .. ".svg")
end
)
local update_slider = function()
awful.spawn.easy_async_with_shell(
[[ sleep 0.1 && xbacklight -get ]],
[[ pkexec xfpm-power-backlight-helper --get-brightness ]],
function(stdout)
stdout = stdout:sub(1, -9)
brightness_osd_widget.container.osd_layout.icon_slider_layout.slider_layout.brightness_slider:set_value(tonumber(stdout))
stdout = math.floor((tonumber(stdout) - 1) / (BACKLIGHT_MAX_BRIGHTNESS - 1) * 100)
brightness_osd_widget.container.osd_layout.icon_slider_layout.slider_layout.brightness_slider:set_value(stdout)
end
)
end

View File

@@ -100,33 +100,38 @@ return function(s)
}
local function update_osd()
local volume_level = volume_osd_widget.container.osd_layout.icon_slider_layout.slider_layout.volume_slider:get_value()
awesome.emit_signal("widget::volume")
volume_osd_widget.container.osd_layout.icon_slider_layout.label_value_layout.value:set_text(volume_level .. "%")
awful.spawn.easy_async_with_shell(
"pacmd list-sinks|grep -A 15 '* index'| awk '/volume: front/{ print $5 }' | sed 's/[%|,]//g'",
function(stdout)
local volume_level = stdout:gsub("\n", "")
awesome.emit_signal("widget::volume")
volume_osd_widget.container.osd_layout.icon_slider_layout.label_value_layout.value:set_text(volume_level .. "%")
awesome.emit_signal(
"widget::volume:update",
volume_level
awesome.emit_signal(
"widget::volume:update",
volume_level
)
if awful.screen.focused().show_volume_osd then
awesome.emit_signal(
"module::volume_osd:show",
true
)
end
volume_level = tonumber(volume_level)
local icon = icondir .. "volume"
if volume_level < 1 then
icon = icon .. "-mute"
elseif volume_level >= 1 and volume_level < 34 then
icon = icon .. "-low"
elseif volume_level >= 34 and volume_level < 67 then
icon = icon .. "-medium"
elseif volume_level >= 67 then
icon = icon .. "-high"
end
volume_osd_widget.container.osd_layout.icon_slider_layout.icon_margin1.icon_margin2.icon:set_image(icon .. ".svg")
end
)
if awful.screen.focused().show_volume_osd then
awesome.emit_signal(
"module::volume_osd:show",
true
)
end
local icon = icondir .. "volume"
if volume_level < 1 then
icon = icon .. "-mute"
elseif volume_level >= 1 and volume_level < 34 then
icon = icon .. "-low"
elseif volume_level >= 34 and volume_level < 67 then
icon = icon .. "-medium"
elseif volume_level >= 67 then
icon = icon .. "-high"
end
volume_osd_widget.container.osd_layout.icon_slider_layout.icon_margin1.icon_margin2.icon:set_image(icon .. ".svg")
end
volume_osd_widget.container.osd_layout.icon_slider_layout.slider_layout.volume_slider:connect_signal(
@@ -146,12 +151,10 @@ return function(s)
else
awful.spawn.easy_async_with_shell(
[[
SINK="$(pacmd stat | awk -F": " '/^Default sink name: /{print $2}')"
echo $(pacmd list-sinks | awk '/^\s+name: /{indefault = $2 == "<'$SINK'>"} /^\s+volume: / && indefault {print $5; exit}')
pacmd list-sinks|grep -A 15 '* index'| awk '/volume: front/{ print $5 }' | sed 's/[%|,]//g'
]],
function(stdout2)
stdout2 = stdout2:sub(1, -3)
stdout2 = stdout2:gsub("\n", "")
volume_osd_widget.container.osd_layout.icon_slider_layout.slider_layout.volume_slider:set_value(tonumber(stdout2))
update_osd()
end

View File

@@ -19,16 +19,14 @@ function Get_icon(theme, client, program_string, class_string, is_steam)
clientName = "steam_icon_" .. tostring(client) .. ".svg"
elseif client then
if client.class then
clientName = string.lower(client.class) .. ".svg"
clientName = string.lower(client.class:gsub(" ", "")) .. ".svg"
elseif client.name then
clientName = string.lower(client.name) .. ".svg"
elseif type(client) == "string" then
clientName = client .. ".svg"
clientName = string.lower(client.name:gsub(" ", "")) .. ".svg"
else
if client.icon == nil then
return "/usr/share/icons/Papirus-Dark/128x128/apps/application-default-icon.svg"
else
if client.icon then
return client.icon
else
return "/usr/share/icons/Papirus-Dark/128x128/apps/application-default-icon.svg"
end
end
else
@@ -59,6 +57,8 @@ function Get_icon(theme, client, program_string, class_string, is_steam)
if ioStream ~= nil then
icon_cache[#icon_cache + 1] = iconDir .. clientName
return iconDir .. clientName
elseif not class_string then
return "/usr/share/icons/Papirus-Dark/128x128/apps/application-default-icon.svg"
else
clientName = class_string .. ".svg"
iconDir = "/usr/share/icons/" .. theme .. "/" .. res .. "/apps/"
@@ -73,7 +73,7 @@ function Get_icon(theme, client, program_string, class_string, is_steam)
end
end
if client then
return client:Get_icon(1)
return "/usr/share/icons/Papirus-Dark/128x128/apps/application-default-icon.svg"
end
end
end

View File

@@ -59,8 +59,7 @@ return function()
local get_volume = function()
awful.spawn.easy_async_with_shell(
[[
SINK="$(pacmd stat | awk -F": " '/^Default sink name: /{print $2}')"
echo $(pacmd list-sinks | awk '/^\s+name: /{indefault = $2 == "<'$SINK'>"} /^\s+volume: / && indefault {print $5; exit}')
pacmd list-sinks|grep -A 15 '* index'| awk '/volume: front/{ print $5 }' | sed 's/[%|,]//g'
]],
function(stdout)
local icon = icondir .. "volume"