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", "XF86AudioLowerVolume",
function(c) function(c)
awful.spawn.easy_async("pactl set-sink-volume @DEFAULT_SINK@ -2%") awful.spawn.easy_async_with_shell("pactl set-sink-volume @DEFAULT_SINK@ -2%", function()
awesome.emit_signal("widget::volume") awesome.emit_signal("widget::volume")
awesome.emit_signal("module::volume_osd:show", true) awesome.emit_signal("module::volume_osd:show", true)
awesome.emit_signal("module::slider:update") awesome.emit_signal("module::slider:update")
awesome.emit_signal("widget::volume_osd:rerun") awesome.emit_signal("widget::volume_osd:rerun")
end)
end, end,
{ description = "Lower volume", group = "System" } { description = "Lower volume", group = "System" }
), ),
@@ -219,11 +220,12 @@ return gears.table.join(
{}, {},
"XF86AudioRaiseVolume", "XF86AudioRaiseVolume",
function(c) function(c)
awful.spawn.easy_async("pactl set-sink-volume @DEFAULT_SINK@ +2%") awful.spawn.easy_async_with_shell("pactl set-sink-volume @DEFAULT_SINK@ +2%", function()
awesome.emit_signal("widget::volume") awesome.emit_signal("widget::volume")
awesome.emit_signal("module::volume_osd:show", true) awesome.emit_signal("module::volume_osd:show", true)
awesome.emit_signal("module::slider:update") awesome.emit_signal("module::slider:update")
awesome.emit_signal("widget::volume_osd:rerun") awesome.emit_signal("widget::volume_osd:rerun")
end)
end, end,
{ description = "Increase volume", group = "System" } { description = "Increase volume", group = "System" }
), ),
@@ -243,10 +245,18 @@ return gears.table.join(
{}, {},
"XF86MonBrightnessUp", "XF86MonBrightnessUp",
function(c) function(c)
awful.spawn("xbacklight -time 100 -inc 10%+") --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_osd:show", true)
awesome.emit_signal("module::brightness_slider:update") awesome.emit_signal("module::brightness_slider:update")
awesome.emit_signal("widget::brightness_osd:rerun") awesome.emit_signal("widget::brightness_osd:rerun")
end
)
end, end,
{ description = "Raise backlight brightness", group = "System" } { description = "Raise backlight brightness", group = "System" }
), ),
@@ -254,10 +264,17 @@ return gears.table.join(
{}, {},
"XF86MonBrightnessDown", "XF86MonBrightnessDown",
function(c) function(c)
awful.spawn("xbacklight -time 100 -dec 10%-") awful.spawn.easy_async_with_shell(
awesome.emit_signal("widget::brightness_osd:rerun") "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_osd:show", true)
awesome.emit_signal("module::brightness_slider:update") awesome.emit_signal("module::brightness_slider:update")
awesome.emit_signal("widget::brightness_osd:rerun")
end
)
end, end,
{ description = "Lower backlight brightness", group = "System" } { description = "Lower backlight brightness", group = "System" }
), ),

View File

@@ -15,4 +15,4 @@ require("src.core.signals")
require("mappings.global_buttons") require("mappings.global_buttons")
require("mappings.bind_to_tags") require("mappings.bind_to_tags")
require("crylia_bar.init") 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 -- Icon directory path
local icondir = awful.util.getdir("config") .. "src/assets/icons/brightness/" 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) return function(s)
local brightness_osd_widget = wibox.widget { local brightness_osd_widget = wibox.widget {
@@ -102,10 +112,13 @@ return function(s)
brightness_osd_widget.container.osd_layout.icon_slider_layout.slider_layout.brightness_slider:connect_signal( brightness_osd_widget.container.osd_layout.icon_slider_layout.slider_layout.brightness_slider:connect_signal(
"property::value", "property::value",
function() function()
local brightness_value = brightness_osd_widget.container.osd_layout.icon_slider_layout.slider_layout.brightness_slider:get_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 -- Performance is horrible, or it overrides and executes at the same time as the keymappings
--awful.spawn("xbacklight -set " .. brightness_value, false) --awful.spawn("xbacklight -set " .. brightness_value, false)
brightness_osd_widget.container.osd_layout.icon_slider_layout.label_value_layout.value:set_text(brightness_value .. "%") brightness_osd_widget.container.osd_layout.icon_slider_layout.label_value_layout.value:set_text(tostring(brightness_value) .. "%")
awesome.emit_signal( awesome.emit_signal(
"widget::brightness:update", "widget::brightness:update",
@@ -130,13 +143,15 @@ return function(s)
brightness_osd_widget.container.osd_layout.icon_slider_layout.icon_margin1.icon_margin2.icon:set_image(icon .. ".svg") brightness_osd_widget.container.osd_layout.icon_slider_layout.icon_margin1.icon_margin2.icon:set_image(icon .. ".svg")
end end
) )
end
)
local update_slider = function() local update_slider = function()
awful.spawn.easy_async_with_shell( awful.spawn.easy_async_with_shell(
[[ sleep 0.1 && xbacklight -get ]], [[ pkexec xfpm-power-backlight-helper --get-brightness ]],
function(stdout) function(stdout)
stdout = stdout:sub(1, -9) 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(tonumber(stdout)) brightness_osd_widget.container.osd_layout.icon_slider_layout.slider_layout.brightness_slider:set_value(stdout)
end end
) )
end end

View File

@@ -100,7 +100,10 @@ return function(s)
} }
local function update_osd() local function update_osd()
local volume_level = volume_osd_widget.container.osd_layout.icon_slider_layout.slider_layout.volume_slider:get_value() 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") awesome.emit_signal("widget::volume")
volume_osd_widget.container.osd_layout.icon_slider_layout.label_value_layout.value:set_text(volume_level .. "%") volume_osd_widget.container.osd_layout.icon_slider_layout.label_value_layout.value:set_text(volume_level .. "%")
@@ -115,7 +118,7 @@ return function(s)
true true
) )
end end
volume_level = tonumber(volume_level)
local icon = icondir .. "volume" local icon = icondir .. "volume"
if volume_level < 1 then if volume_level < 1 then
icon = icon .. "-mute" icon = icon .. "-mute"
@@ -128,6 +131,8 @@ return function(s)
end end
volume_osd_widget.container.osd_layout.icon_slider_layout.icon_margin1.icon_margin2.icon:set_image(icon .. ".svg") volume_osd_widget.container.osd_layout.icon_slider_layout.icon_margin1.icon_margin2.icon:set_image(icon .. ".svg")
end end
)
end
volume_osd_widget.container.osd_layout.icon_slider_layout.slider_layout.volume_slider:connect_signal( volume_osd_widget.container.osd_layout.icon_slider_layout.slider_layout.volume_slider:connect_signal(
"property::value", "property::value",
@@ -146,12 +151,10 @@ return function(s)
else else
awful.spawn.easy_async_with_shell( awful.spawn.easy_async_with_shell(
[[ [[
SINK="$(pacmd stat | awk -F": " '/^Default sink name: /{print $2}')" pacmd list-sinks|grep -A 15 '* index'| awk '/volume: front/{ print $5 }' | sed 's/[%|,]//g'
echo $(pacmd list-sinks | awk '/^\s+name: /{indefault = $2 == "<'$SINK'>"} /^\s+volume: / && indefault {print $5; exit}')
]], ]],
function(stdout2) 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)) volume_osd_widget.container.osd_layout.icon_slider_layout.slider_layout.volume_slider:set_value(tonumber(stdout2))
update_osd() update_osd()
end end

View File

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

View File

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