Merge pull request #345 from shubham-cpp/update-brightnessctl

Simplified get_brightness_cmd and using gears.filesystem
This commit is contained in:
streetturtle 2022-07-16 20:40:04 -04:00 committed by GitHub
commit 0e96494f47
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 17 additions and 14 deletions

View File

@ -12,10 +12,11 @@ local awful = require("awful")
local wibox = require("wibox") local wibox = require("wibox")
local watch = require("awful.widget.watch") local watch = require("awful.widget.watch")
local spawn = require("awful.spawn") local spawn = require("awful.spawn")
local gfs = require("gears.filesystem")
local naughty = require("naughty") local naughty = require("naughty")
local beautiful = require("beautiful") local beautiful = require("beautiful")
local ICON_DIR = os.getenv("HOME") .. '/.config/awesome/awesome-wm-widgets/brightness-widget/' local ICON_DIR = gfs.get_configuration_dir() .. "awesome-wm-widgets/brightness-widget/"
local get_brightness_cmd local get_brightness_cmd
local set_brightness_cmd local set_brightness_cmd
local inc_brightness_cmd local inc_brightness_cmd
@ -24,14 +25,14 @@ local dec_brightness_cmd
local brightness_widget = {} local brightness_widget = {}
local function show_warning(message) local function show_warning(message)
naughty.notify{ naughty.notify({
preset = naughty.config.presets.critical, preset = naughty.config.presets.critical,
title = 'Brightness Widget', title = "Brightness Widget",
text = message} text = message,
})
end end
local function worker(user_args) local function worker(user_args)
local args = user_args or {} local args = user_args or {}
local type = args.type or 'arc' -- arc or icon_and_text local type = args.type or 'arc' -- arc or icon_and_text
@ -56,10 +57,10 @@ local function worker(user_args)
inc_brightness_cmd = 'xbacklight -inc ' .. step inc_brightness_cmd = 'xbacklight -inc ' .. step
dec_brightness_cmd = 'xbacklight -dec ' .. step dec_brightness_cmd = 'xbacklight -dec ' .. step
elseif program == 'brightnessctl' then elseif program == 'brightnessctl' then
get_brightness_cmd = 'bash -c "brightnessctl -m | cut -d, -f4 | tr -d %"' get_brightness_cmd = "brightnessctl get"
set_brightness_cmd = 'brightnessctl set %d%%' -- <level> set_brightness_cmd = "brightnessctl set %d%%" -- <level>
inc_brightness_cmd = 'brightnessctl set +' .. step .. '%' inc_brightness_cmd = "brightnessctl set +" .. step .. "%"
dec_brightness_cmd = 'brightnessctl set ' .. step .. '-%' dec_brightness_cmd = "brightnessctl set " .. step .. "-%"
else else
show_warning(program .. " command is not supported by the widget") show_warning(program .. " command is not supported by the widget")
return return
@ -187,6 +188,8 @@ local function worker(user_args)
return brightness_widget.widget return brightness_widget.widget
end end
return setmetatable(brightness_widget, { __call = function(_, ...) return setmetatable(brightness_widget, {
__call = function(_, ...)
return worker(...) return worker(...)
end }) end,
})