From 3014105bbf383040316cf927928a5e058d01b511 Mon Sep 17 00:00:00 2001 From: Mark Date: Sat, 16 Jul 2022 16:06:02 -0700 Subject: [PATCH] Added backlight module --- bin/init.lua | 30 ------ binds/init.lua | 1 - desktop/init.lua | 3 +- desktop/widgets/backlight.lua | 101 ------------------ .../backlight/backlight.fish | 0 modules/backlight/init.lua | 6 ++ .../backlight/keybinds.lua | 14 +-- modules/backlight/util.lua | 62 +++++++++++ modules/backlight/widget.lua | 101 ++++++++++++++++++ rc.lua | 1 - wrapper/backlight.lua | 36 ------- wrapper/init.lua | 3 - 12 files changed, 178 insertions(+), 180 deletions(-) delete mode 100755 desktop/widgets/backlight.lua rename bin/scripts/backlight => modules/backlight/backlight.fish (100%) create mode 100644 modules/backlight/init.lua rename binds/system/backlight.lua => modules/backlight/keybinds.lua (78%) create mode 100755 modules/backlight/util.lua create mode 100755 modules/backlight/widget.lua delete mode 100755 wrapper/backlight.lua delete mode 100755 wrapper/init.lua diff --git a/bin/init.lua b/bin/init.lua index fb2c7dc..e63249b 100755 --- a/bin/init.lua +++ b/bin/init.lua @@ -17,36 +17,6 @@ return { end }, - backlight = { - watch = function(timeout, callback, widget) - awful.widget.watch(script_dir .. "backlight get", timeout, callback, widget) - end, - - get = function(callback) - awful.spawn.easy_async(script_dir .. "backlight get", callback) - end, - - set = function(value) - awful.spawn(script_dir .. "backlight set " .. value, false) - end, - - up = function() - awful.spawn(script_dir .. "backlight up", false) - end, - - down = function() - awful.spawn(script_dir .. "backlight down", false) - end, - - redshift = function(temp) - awful.spawn("redshift -O " .. tostring(temp), false) - end, - - redshift_reset = function() - awful.spawn("redshift -x", false) - end, - }, - battery = { watch = function(timeout, callback, widget) awful.widget.watch(script_dir .. "battery", timeout, callback, widget) diff --git a/binds/init.lua b/binds/init.lua index 6bc3cf3..ac201a0 100755 --- a/binds/init.lua +++ b/binds/init.lua @@ -1,6 +1,5 @@ return { keys = gears.table.join( - require("binds.system.backlight"), require("binds.system.system"), require("binds.window.client"), diff --git a/desktop/init.lua b/desktop/init.lua index 0a36eb8..0f93c70 100755 --- a/desktop/init.lua +++ b/desktop/init.lua @@ -10,7 +10,6 @@ local desktop = { tagindicator = require("desktop.widgets.tagindicator"), launcher = require("desktop.widgets.launcher"), shortcut = require("desktop.widgets.shortcut"), - --winstat = require("desktop.widgets.window_status"), space = function(size) return wibox.widget { @@ -45,7 +44,7 @@ local desktop = { -- Load conditional modules if conf.backlight_enabled then - desktop.widgets.backlight = require("desktop.widgets.backlight") + desktop.widgets.backlight = modules.backlight.widgets.backlight end if conf.battery_enabled then desktop.widgets.battery = require("desktop.widgets.battery") diff --git a/desktop/widgets/backlight.lua b/desktop/widgets/backlight.lua deleted file mode 100755 index d474ba1..0000000 --- a/desktop/widgets/backlight.lua +++ /dev/null @@ -1,101 +0,0 @@ -local backlight = {} - - -backlight.icon = wibox.widget { - id = "icon", - image = beautiful.icons.brightness.i, - resize = true, - widget = wibox.widget.imagebox, -} - -backlight.arc = wibox.widget { - { - backlight.icon, - top = beautiful.dpi(1), - bottom = beautiful.dpi(1), - layout = wibox.container.margin, - }, - max_value = 100, - thickness = beautiful.dpi(4), - start_angle = 4.71238898, -- 2pi*3/4 - --forced_height = beautiful.dpi(16), - --forced_width = beautiful.dpi(16), - colors = {"#27D4CC", "#00446B"}, - bg = "#FFFFFF30", - paddings = beautiful.dpi(2), - widget = wibox.container.arcchart -} - - -backlight.widget = wibox.widget { - { - { -- Right space - widget = wibox.widget.separator, - color = beautiful.color.transparent, - forced_width = beautiful.dpi(3) - }, - { -- Main indicator. Can be replaced with backlight.arc - backlight.arc, - top = beautiful.dpi(2), - bottom = beautiful.dpi(2), - layout = wibox.container.margin, - }, - { -- Left space - widget = wibox.widget.separator, - color = beautiful.color.transparent, - forced_width = beautiful.dpi(3) - }, - layout = wibox.layout.align.horizontal, - }, - layout = wibox.container.background, -} - -backlight.widget:connect_signal("mouse::enter", function(result) - backlight.widget.bg = beautiful.color.bar.hover_bg - -end) - -backlight.widget:connect_signal("mouse::leave", function(result) - backlight.widget.bg = beautiful.color.transparent -end) - -backlight.widget:connect_signal("button::press", - function(_, _, _, button, mods) - -- Scroll up - if (button == 4) then - wrapper.backlight.up() - -- Scroll down - elseif (button == 5) then - wrapper.backlight.down() - end - end -) - -backlight.update = function(value) - backlight.arc.value = value - - --[[if value > 90 then backlight.icon.image = beautiful.icons.brightness.i - elseif value > 80 then backlight.icon.image = beautiful.icons.brightness.h - elseif value > 70 then backlight.icon.image = beautiful.icons.brightness.g - elseif value > 60 then backlight.icon.image = beautiful.icons.brightness.f - elseif value > 50 then backlight.icon.image = beautiful.icons.brightness.e - elseif value > 40 then backlight.icon.image = beautiful.icons.brightness.d - elseif value > 30 then backlight.icon.image = beautiful.icons.brightness.c - elseif value > 20 then backlight.icon.image = beautiful.icons.brightness.b - elseif value <= 10 then backlight.icon.image = beautiful.icons.brightness.a end - --]] - -end - - --- Add various hooks -wrapper.backlight.add_hook(backlight.update) -bin.backlight.watch( - 5, - function() - wrapper.backlight.read(backlight.update) - end, - backlight.widget -) - -return backlight.widget diff --git a/bin/scripts/backlight b/modules/backlight/backlight.fish similarity index 100% rename from bin/scripts/backlight rename to modules/backlight/backlight.fish diff --git a/modules/backlight/init.lua b/modules/backlight/init.lua new file mode 100644 index 0000000..d4d127f --- /dev/null +++ b/modules/backlight/init.lua @@ -0,0 +1,6 @@ +return { + widgets = { + backlight = require("modules.backlight.widget").widget + }, + keybinds = require("modules.backlight.keybinds"), +} diff --git a/binds/system/backlight.lua b/modules/backlight/keybinds.lua similarity index 78% rename from binds/system/backlight.lua rename to modules/backlight/keybinds.lua index e5f8685..372e47f 100755 --- a/binds/system/backlight.lua +++ b/modules/backlight/keybinds.lua @@ -1,7 +1,9 @@ +local backlight = req_rel(..., "util") + return gears.table.join( awful.key( {}, "XF86MonBrightnessUp", function () - wrapper.backlight.up() + backlight.backlight_up() end, { description = "Raise brightness", @@ -11,7 +13,7 @@ return gears.table.join( awful.key( {}, "XF86MonBrightnessDown", function () - wrapper.backlight.down() + backlight.backlight_down() end, { description = "Lower brightness", @@ -21,7 +23,7 @@ return gears.table.join( awful.key( { "Mod4" }, "o", function () - bin.backlight.redshift(5600) + backlight.redshift(5600) end, { description = "Default redshift", @@ -31,7 +33,7 @@ return gears.table.join( awful.key( { "Mod4", "Shift" }, "o", function () - bin.backlight.redshift_reset() + backlight.reset_redshift() end, { description = "Reset redshift", @@ -41,11 +43,11 @@ return gears.table.join( awful.key( { "Mod4", "Shift", "Control" }, "o", function () - bin.backlight.redshift_reset() + backlight.reset_redshift() awful.prompt.run { prompt = "Color temperature: ", textbox = awful.screen.focused().mypromptbox.widget, - exe_callback = bin.backlight.redshift + exe_callback = backlight.redshift } end, { diff --git a/modules/backlight/util.lua b/modules/backlight/util.lua new file mode 100755 index 0000000..8faccb6 --- /dev/null +++ b/modules/backlight/util.lua @@ -0,0 +1,62 @@ +local backlight = {} + +-- The space at the end is important! +local script = configuration_dir .. "modules/backlight/backlight.fish" +script = script .. " " + +backlight.hooks = {} +backlight.add_hook = function(callback) + backlight.hooks[#backlight.hooks + 1] = callback +end + +backlight.exec_hooks = function() + backlight.read(function(status) + for i=1, #backlight.hooks do + backlight.hooks[i](status) + end + end) +end + +backlight.read = function(callback) + awful.spawn.easy_async( + script .. "get", + function(stdout, stderr, exitreason, exitcode) + callback(tonumber(stdout)) + end + ) +end + +backlight.set = function(value) +awful.spawn(script .. "set " .. value, false) +end + +backlight.watch = function(timeout, callback, widget) + awful.widget.watch( + script .. "get", + timeout, + callback, + widget + ) +end + + +backlight.backlight_up = function() + awful.spawn(script .. "up", false) + backlight.exec_hooks() +end + +backlight.backlight_down = function() + awful.spawn(script .. "down", false) + backlight.exec_hooks() +end + +backlight.redshift = function(temp) + awful.spawn("redshift -O " .. tostring(temp), false) +end + +backlight.reset_redshift = function() + awful.spawn("redshift -x", false) +end + + +return backlight diff --git a/modules/backlight/widget.lua b/modules/backlight/widget.lua new file mode 100755 index 0000000..a7cf3e9 --- /dev/null +++ b/modules/backlight/widget.lua @@ -0,0 +1,101 @@ +local backlight = req_rel(..., "util") +local widget = {} + + +widget.icon = wibox.widget { + id = "icon", + image = beautiful.icons.brightness.i, + resize = true, + widget = wibox.widget.imagebox, +} + +widget.arc = wibox.widget { + { + widget.icon, + top = beautiful.dpi(1), + bottom = beautiful.dpi(1), + layout = wibox.container.margin, + }, + max_value = 100, + thickness = beautiful.dpi(4), + start_angle = 4.71238898, -- 2pi*3/4 + --forced_height = beautiful.dpi(16), + --forced_width = beautiful.dpi(16), + colors = {"#27D4CC", "#00446B"}, + bg = "#FFFFFF30", + paddings = beautiful.dpi(2), + widget = wibox.container.arcchart +} + + +widget.widget = wibox.widget { + { + { -- Right space + widget = wibox.widget.separator, + color = beautiful.color.transparent, + forced_width = beautiful.dpi(3) + }, + { -- Main indicator. Can be replaced with widget.arc + widget.arc, + top = beautiful.dpi(2), + bottom = beautiful.dpi(2), + layout = wibox.container.margin, + }, + { -- Left space + widget = wibox.widget.separator, + color = beautiful.color.transparent, + forced_width = beautiful.dpi(3) + }, + layout = wibox.layout.align.horizontal, + }, + layout = wibox.container.background, +} + +widget.widget:connect_signal("mouse::enter", function(result) + widget.widget.bg = beautiful.color.bar.hover_bg + +end) + +widget.widget:connect_signal("mouse::leave", function(result) + widget.widget.bg = beautiful.color.transparent +end) + +widget.widget:connect_signal("button::press", + function(_, _, _, button, mods) + -- Scroll up + if (button == 4) then + backlight.backlight_up() + -- Scroll down + elseif (button == 5) then + backlight.backlight_down() + end + end +) + +widget.update = function(value) + widget.arc.value = value + + --[[if value > 90 then widget.icon.image = beautiful.icons.brightness.i + elseif value > 80 then widget.icon.image = beautiful.icons.brightness.h + elseif value > 70 then widget.icon.image = beautiful.icons.brightness.g + elseif value > 60 then widget.icon.image = beautiful.icons.brightness.f + elseif value > 50 then widget.icon.image = beautiful.icons.brightness.e + elseif value > 40 then widget.icon.image = beautiful.icons.brightness.d + elseif value > 30 then widget.icon.image = beautiful.icons.brightness.c + elseif value > 20 then widget.icon.image = beautiful.icons.brightness.b + elseif value <= 10 then widget.icon.image = beautiful.icons.brightness.a end + --]] + +end + + +backlight.add_hook(widget.update) +backlight.watch( + 5, + function() + backlight.read(widget.update) + end, + widget.widget +) + +return widget diff --git a/rc.lua b/rc.lua index 12368bc..a2de4bc 100755 --- a/rc.lua +++ b/rc.lua @@ -31,7 +31,6 @@ layoutmanager = require("desktop.layoutmanager") layoutmanager.layouts = conf.layouts bin = require("bin") -wrapper = require("wrapper") beautiful.init(require("theme")) diff --git a/wrapper/backlight.lua b/wrapper/backlight.lua deleted file mode 100755 index 0b9c85f..0000000 --- a/wrapper/backlight.lua +++ /dev/null @@ -1,36 +0,0 @@ -local backlight = {} - - -backlight.hooks = {} -backlight.add_hook = function(callback) - backlight.hooks[#backlight.hooks + 1] = callback -end - -backlight.exec_hooks = function() - backlight.read(function(status) - for i=1, #backlight.hooks do - backlight.hooks[i](status) - end - end) -end - -backlight.read = function(callback) - bin.backlight.get( - function(stdout, stderr, exitreason, exitcode) - callback(tonumber(stdout)) - end - ) -end - - -backlight.up = function() - bin.backlight.up() - backlight.exec_hooks() -end - -backlight.down = function() - bin.backlight.down() - backlight.exec_hooks() -end - -return backlight diff --git a/wrapper/init.lua b/wrapper/init.lua deleted file mode 100755 index 1a2d722..0000000 --- a/wrapper/init.lua +++ /dev/null @@ -1,3 +0,0 @@ -return { - backlight = require("wrapper.backlight") -}