summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorstreetturtle <streetturtle@gmail.com>2021-01-16 14:50:54 -0500
committerstreetturtle <streetturtle@gmail.com>2021-01-16 14:50:54 -0500
commit9b66b2ee444124df22543ccc38cd7b3b6302f994 (patch)
treeaae9f7dd8d458572d0dc9831449630875eec0cc5
parentb28f55e538e6e19aeb74c3f22342b0602dd7fbee (diff)
[brightness] rework brightness widget
also remove brightnessarc widget, as now it's possible to create arcchart widget in brightness widget
-rw-r--r--brightness-widget/README.md57
-rw-r--r--brightness-widget/br-wid-1.pngbin1355 -> 4912 bytes
-rw-r--r--brightness-widget/brightness.lua147
-rw-r--r--brightness-widget/brightness.svg153
-rw-r--r--brightnessarc-widget/README.md97
-rw-r--r--brightnessarc-widget/br-wid-1.pngbin1355 -> 0 bytes
-rw-r--r--brightnessarc-widget/brightnessarc.lua77
7 files changed, 284 insertions, 247 deletions
diff --git a/brightness-widget/README.md b/brightness-widget/README.md
index 02aa2d3..5428029 100644
--- a/brightness-widget/README.md
+++ b/brightness-widget/README.md
@@ -1,6 +1,6 @@
# Brightness widget
-This widget represents current brightness level: ![Brightness widget](./br-wid-1.png)
+This widget represents current brightness level, depending on config parameters could be an arcchart or icon with text: ![Brightness widget](./br-wid-1.png)
## Customization
@@ -8,50 +8,39 @@ It is possible to customize widget by providing a table with all or some of the
| Name | Default | Description |
|---|---|---|
-| `get_brightness_cmd` | `light -G` | Get current screen brightness |
-| `inc_brightness_cmd` | `light -A 5` | Increase brightness |
-| `dec_brightness_cmd` | `light -U 5`| Decrease brightness |
+| `type`| `arc` | The widget type. Could be `arc` or `icon_and_text` |
+| `program` | `light` | The program used to control the brightness, either 'light' or 'xbacklight'. |
+| `step` | 5 | Step |
| `path_to_icon` | `/usr/share/icons/Arc/status/symbolic/display-brightness-symbolic.svg` | Path to the icon |
| `font` | `Play 9` | Font |
-| `timeout` | 1 | How often in seconds the widget refreshes |
-
-### Example:
-
-```lua
-brightness_widget({
- get_brightness_cmd = 'xbacklight -get',
- inc_brightness_cmd = 'xbacklight -inc 5',
- dec_brightness_cmd = 'xbacklight -dec 5'
-})
-```
+| `timeout` | 1 | How often in seconds the widget refreshes. Check the note below |
+_Note:_ If brightness is controlled only by the widget (either by a mouse, or by a shortcut, then the `timeout` could be quite big, as there is no reason to synchronize the brightness level).
## Installation
-First you need to get the current brightness level. There are two options:
+To choose the right `program` argument, first you need to check which of them works better for you.
- - using `xbacklight` command (depending on your video card (I guess) it may or may not work)
+ - using `xbacklight`:
- To check if it works install xbackligth and check if it works:
+ Install (on Ubuntu it's available in the apt repository) it and check if it works by running:
```bash
- sudo apt-get install xbacklight
xbacklight -get
```
- If there is no output it means that it doesn't work, but there is a second option:
+ If there is no output it means that it doesn't work, you can either try to fix it, or try to use `light`.
- using `light` command
- Install it from this git repo: [github.com/haikarainen/light](https://github.com/haikarainen/light) and check if it works but running
+ Install (on Ubuntu it's available in the apt repository) from the repo: [github.com/haikarainen/light](https://github.com/haikarainen/light) and check if it works by running
```bash
- git clone https://github.com/haikarainen/light.git && \
- cd ./light && \
- sudo make && sudo make install \
light -G
49.18
+ light -A 5
```
+ If you're on Ubuntu/debian and if the brightness level doesn't change, try to do this: https://github.com/haikarainen/light/issues/113#issuecomment-632638436.
Then clone this repo under **~/.config/awesome/**:
@@ -65,7 +54,7 @@ Require widget at the beginning of **rc.lua**:
local brightness_widget = require("awesome-wm-widgets.brightness-widget.brightness")
```
-Add widget to the tasklist:
+Add the widget to the tasklist:
```lua
s.mytasklist, -- Middle widget
@@ -75,13 +64,13 @@ s.mytasklist, -- Middle widget
-- default
brightness_widget(),
-- or customized
- brightness_widget({
- get_brightness_cmd = 'xbacklight -get',
- inc_brightness_cmd = 'xbacklight -inc 5',
- dec_brightness_cmd = 'xbacklight -dec 5'
- })
+ brightness_widget{
+ type = 'icon_and_text',
+ program = 'xbacklight',
+ step = 2,
+ }
}
- ...
+ ...
```
## Controls
@@ -89,7 +78,7 @@ s.mytasklist, -- Middle widget
In order to change brightness by shortcuts you can add them to the `globalkeys` table in the **rc.lua**:
```lua
-awful.key({ modkey }, ";", function () awful.spawn("light -A 5") end, {description = "increase brightness", group = "custom"}),
-awful.key({ modkey, "Shift"}, ";", function () awful.spawn("light -U 5") end, {description = "decrease brightness", group = "custom"}),
+awful.key({ modkey }, ";", function () brightness_widget:inc() end, {description = "increase brightness", group = "custom"}),
+awful.key({ modkey, "Shift"}, ";", function () brightness_widget:dec() end, {description = "decrease brightness", group = "custom"}),
```
-On laptop you can use `XF86MonBrightnessUp` and `XF86MonBrightnessDown` keys.
+On a laptop you can use `XF86MonBrightnessUp` and `XF86MonBrightnessDown` keys.
diff --git a/brightness-widget/br-wid-1.png b/brightness-widget/br-wid-1.png
index f9200eb..b00b0e6 100644
--- a/brightness-widget/br-wid-1.png
+++ b/brightness-widget/br-wid-1.png
Binary files differ
diff --git a/brightness-widget/brightness.lua b/brightness-widget/brightness.lua
index 4686041..d5a79a9 100644
--- a/brightness-widget/brightness.lua
+++ b/brightness-widget/brightness.lua
@@ -5,66 +5,135 @@
-- https://github.com/streetturtle/awesome-wm-widgets/tree/master/brightness-widget
-- @author Pavel Makhov
--- @copyright 2017-2019 Pavel Makhov
+-- @copyright 2021 Pavel Makhov
-------------------------------------------------
+local awful = require("awful")
local wibox = require("wibox")
local watch = require("awful.widget.watch")
local spawn = require("awful.spawn")
+local naughty = require("naughty")
-local PATH_TO_ICON = "/usr/share/icons/Arc/status/symbolic/display-brightness-symbolic.svg"
-local GET_BRIGHTNESS_CMD = "light -G" -- "xbacklight -get"
-local INC_BRIGHTNESS_CMD = "light -A 5" -- "xbacklight -inc 5"
-local DEC_BRIGHTNESS_CMD = "light -U 5" -- "xbacklight -dec 5"
+local ICON_DIR = os.getenv("HOME") .. '/.config/awesome/awesome-wm-widgets/brightness-widget/'
+local get_brightness_cmd
+local inc_brightness_cmd
+local dec_brightness_cmd
local brightness_widget = {}
+local function show_warning(message)
+ naughty.notify{
+ preset = naughty.config.presets.critical,
+ title = 'Brightness Widget',
+ text = message}
+end
+
local function worker(user_args)
local args = user_args or {}
- local get_brightness_cmd = args.get_brightness_cmd or GET_BRIGHTNESS_CMD
- local inc_brightness_cmd = args.inc_brightness_cmd or INC_BRIGHTNESS_CMD
- local dec_brightness_cmd = args.dec_brightness_cmd or DEC_BRIGHTNESS_CMD
- local path_to_icon = args.path_to_icon or PATH_TO_ICON
+ local type = args.type or 'arc' -- arc or icon_and_text
+ local path_to_icon = args.path_to_icon or ICON_DIR .. 'brightness.svg'
local font = args.font or 'Play 9'
- local timeout = args.timeout or 1
-
- local brightness_text = wibox.widget.textbox()
- brightness_text:set_font(font)
-
- local brightness_icon = wibox.widget {
- {
- image = path_to_icon,
- resize = false,
- widget = wibox.widget.imagebox,
- },
- top = 3,
- widget = wibox.container.margin
- }
-
- brightness_widget = wibox.widget {
- brightness_icon,
- brightness_text,
- layout = wibox.layout.fixed.horizontal,
- }
+ local timeout = args.timeout or 100
+
+ local program = args.program or 'light'
+ local step = args.step or 5
+ if program == 'light' then
+ get_brightness_cmd = 'sh -c "light -G"'
+ inc_brightness_cmd = 'sh -c "light -A ' .. step .. '"'
+ dec_brightness_cmd = 'sh -c "light -U ' .. step .. '"'
+ elseif program == 'xbacklight' then
+ get_brightness_cmd = 'xbacklight -get'
+ inc_brightness_cmd = 'xbacklight -inc ' .. step
+ dec_brightness_cmd = 'xbacklight -dec ' .. step
+ else
+ show_warning(program .. " command is not supported by the widget")
+ return
+ end
+
+ if type == 'icon_and_text' then
+ brightness_widget.widget = wibox.widget {
+ {
+ {
+ image = path_to_icon,
+ resize = false,
+ widget = wibox.widget.imagebox,
+ },
+ valigh = 'center',
+ layout = wibox.container.place
+ },
+ {
+ id = 'txt',
+ font = font,
+ widget = wibox.widget.textbox
+ },
+ spacing = 4,
+ layout = wibox.layout.fixed.horizontal,
+ set_value = function(self, level)
+ self:get_children_by_id('txt')[1]:set_text(level .. '%')
+ end
+ }
+ elseif type == 'arc' then
+ brightness_widget.widget = wibox.widget {
+ {
+ {
+ image = path_to_icon,
+ resize = true,
+ widget = wibox.widget.imagebox,
+ },
+ valigh = 'center',
+ layout = wibox.container.place
+ },
+ max_value = 100,
+ thickness = 2,
+ start_angle = 4.71238898, -- 2pi*3/4
+ forced_height = 18,
+ forced_width = 18,
+ bg = bg_color,
+ paddings = 2,
+ colors = {color},
+ widget = wibox.container.arcchart,
+ set_value = function(self, level)
+ self:set_value(level)
+ end
+ }
+ else
+ show_warning(type .. " type is not supported by the widget")
+ return
+
+ end
local update_widget = function(widget, stdout, _, _, _)
local brightness_level = tonumber(string.format("%.0f", stdout))
- widget:set_text(" " .. brightness_level .. "%")
+ widget:set_value(brightness_level)
+ end
+
+ function brightness_widget:inc()
+ spawn.easy_async(inc_brightness_cmd, function()
+ spawn.easy_async(get_brightness_cmd, function(out)
+ update_widget(brightness_widget.widget, out)
+ end)
+ end)
+ end
+ function brightness_widget:dec()
+ spawn.easy_async(dec_brightness_cmd, function()
+ spawn.easy_async(get_brightness_cmd, function(out)
+ update_widget(brightness_widget.widget, out)
+ end)
+ end)
end
- brightness_widget:connect_signal("button::press", function(_, _, _, button)
- if (button == 4) then
- spawn(inc_brightness_cmd, false)
- elseif (button == 5) then
- spawn(dec_brightness_cmd, false)
- end
- end)
+ brightness_widget.widget:buttons(
+ awful.util.table.join(
+ awful.button({}, 4, function() brightness_widget:inc() end),
+ awful.button({}, 5, function() brightness_widget:dec() end)
+ )
+ )
- watch(get_brightness_cmd, timeout, update_widget, brightness_text)
+ watch(get_brightness_cmd, timeout, update_widget, brightness_widget.widget)
- return brightness_widget
+ return brightness_widget.widget
end
return setmetatable(brightness_widget, { __call = function(_, ...)
diff --git a/brightness-widget/brightness.svg b/brightness-widget/brightness.svg
new file mode 100644
index 0000000..d334372
--- /dev/null
+++ b/brightness-widget/brightness.svg
@@ -0,0 +1,153 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!-- Created with Inkscape (http://www.inkscape.org/) -->
+
+<svg
+ xmlns:dc="http://purl.org/dc/elements/1.1/"
+ xmlns:cc="http://creativecommons.org/ns#"
+ xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+ xmlns:svg="http://www.w3.org/2000/svg"
+ xmlns="http://www.w3.org/2000/svg"
+ xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
+ xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
+ width="16"
+ height="16"
+ id="svg2"
+ sodipodi:version="0.32"
+ inkscape:version="0.91 r13725"
+ version="1.0"
+ sodipodi:docname="display-brightness-symbolic.svg"
+ inkscape:output_extension="org.inkscape.output.svg.inkscape"
+ style="display:inline">
+ <defs
+ id="defs4" />
+ <sodipodi:namedview
+ id="base"
+ pagecolor="#ffffff"
+ bordercolor="#e7e7e7"
+ borderopacity="1"
+ inkscape:pageopacity="0.0"
+ inkscape:pageshadow="2"
+ inkscape:zoom="44.218752"
+ inkscape:cx="12.155025"
+ inkscape:cy="7.6228779"
+ inkscape:document-units="px"
+ inkscape:current-layer="layer1"
+ showgrid="true"
+ inkscape:showpageshadow="false"
+ showguides="false"
+ inkscape:guide-bbox="true"
+ inkscape:window-width="1920"
+ inkscape:window-height="1029"
+ inkscape:window-x="0"
+ inkscape:window-y="24"
+ inkscape:window-maximized="1"
+ inkscape:snap-global="true">
+ <sodipodi:guide
+ orientation="1,0"
+ position="0,112"
+ id="guide2383" />
+ <sodipodi:guide
+ orientation="0,1"
+ position="26.278146,128"
+ id="guide2385" />
+ <sodipodi:guide
+ orientation="1,0"
+ position="128,54.082119"
+ id="guide2387" />
+ <sodipodi:guide
+ orientation="0,1"
+ position="78.156291,0"
+ id="guide2389" />
+ <sodipodi:guide
+ orientation="0,1"
+ position="60.863576,64.084768"
+ id="guide2391" />
+ <inkscape:grid
+ type="xygrid"
+ id="grid3672"
+ visible="true"
+ enabled="true"
+ empspacing="8"
+ snapvisiblegridlinesonly="true" />
+ </sodipodi:namedview>
+ <metadata
+ id="metadata7">
+ <rdf:RDF>
+ <cc:Work
+ rdf:about="">
+ <dc:format>image/svg+xml</dc:format>
+ <dc:type
+ rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
+ <dc:title />
+ </cc:Work>
+ </rdf:RDF>
+ </metadata>
+ <g
+ inkscape:label="Icon"
+ inkscape:groupmode="layer"
+ id="layer1"
+ style="display:inline"
+ transform="translate(0,-6)">
+ <path
+ style="color:#000000;fill:#bebebe;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:1.5;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:accumulate"
+ d="m -12,6 -1,3 2,0 -1,-3 z m -5.65625,2.34375 1.40625,2.8125 1.40625,-1.40625 -2.8125,-1.40625 z m 11.3125,0 L -9.15625,9.75 -7.75,11.15625 -6.34375,8.34375 z M -12,10 c -2.209139,0 -4,1.790861 -4,4 0,2.209139 1.790861,4 4,4 2.209139,0 4,-1.790861 4,-4 0,-2.209139 -1.790861,-4 -4,-4 z m 0,1.5 c 1.380712,0 2.5,1.119288 2.5,2.5 0,1.380712 -1.119288,2.5 -2.5,2.5 -1.380712,0 -2.5,-1.119288 -2.5,-2.5 0,-1.380712 1.119288,-2.5 2.5,-2.5 z m -5,1.5 -3,1 3,1 0,-2 z m 10,0 0,2 3,-1 -3,-1 z m -9.25,3.84375 -1.40625,2.8125 2.8125,-1.40625 -1.40625,-1.40625 z m 8.5,0 -1.40625,1.40625 2.8125,1.40625 L -7.75,16.84375 z M -13,19 l 1,3 1,-3 -2,0 z"
+ id="path3085"
+ inkscape:connector-curvature="0" />
+ <path
+ id="path3102"
+ d="m 8,30 c -2.209139,0 -4,1.790861 -4,4 0,2.209139 1.790861,4 4,4 2.209139,0 4,-1.790861 4,-4 0,-2.209139 -1.790861,-4 -4,-4 z m 0,2 c 1.1045695,0 2,0.89543 2,2 0,1.104569 -0.8954305,2 -2,2 -1.1045695,0 -2,-0.895431 -2,-2 0,-1.10457 0.8954305,-2 2,-2 z"
+ style="opacity:0.35;color:#000000;fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:1.5;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:accumulate"
+ inkscape:connector-curvature="0" />
+ <path
+ inkscape:transform-center-y="-6.5"
+ sodipodi:nodetypes="cccc"
+ inkscape:connector-curvature="0"
+ id="path3104"
+ d="m 6,29 4,0 -2,-3 z"
+ style="fill:#808080;stroke:none" />
+ <path
+ inkscape:transform-center-y="-2.4999999"
+ inkscape:transform-center-x="-5.1291655"
+ style="fill:#808080;stroke:none"
+ d="m 11.330127,29.767949 2,3.464102 L 14.928204,30 z"
+ id="path3106"
+ inkscape:connector-curvature="0"
+ sodipodi:nodetypes="cccc" />
+ <path
+ sodipodi:nodetypes="cccc"
+ inkscape:connector-curvature="0"
+ id="path3108"
+ d="m 13.330127,34.767949 -2,3.464102 L 14.928203,38 z"
+ style="fill:#808080;stroke:none"
+ inkscape:transform-center-x="-5.129165"
+ inkscape:transform-center-y="2.5" />
+ <path
+ inkscape:transform-center-y="6.5"
+ style="fill:#808080;stroke:none"
+ d="m 10,39 -4.0000002,0 2.0000001,3 z"
+ id="path3110"
+ inkscape:connector-curvature="0"
+ sodipodi:nodetypes="cccc" />
+ <path
+ inkscape:transform-center-x="5.1291651"
+ sodipodi:nodetypes="cccc"
+ inkscape:connector-curvature="0"
+ id="path3112"
+ d="M 4.6698729,38.232051 2.6698728,34.767949 1.0717967,38 z"
+ style="fill:#808080;stroke:none"
+ inkscape:transform-center-y="2.5" />
+ <path
+ inkscape:transform-center-y="-2.5"
+ style="fill:#808080;stroke:none"
+ d="M 2.6698727,33.232051 4.669873,29.767949 1.0717967,30 z"
+ id="path3114"
+ inkscape:connector-curvature="0"
+ sodipodi:nodetypes="cccc"
+ inkscape:transform-center-x="5.129165" />
+ <path
+ style="color:#000000;fill:#bebebe;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:1.5;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:accumulate"
+ d="M 5.84375 0 L 5.09375 2.96875 L 2.15625 2.15625 L 2.96875 5.09375 L 0 5.84375 L 2.1875 8 L 0 10.15625 L 2.96875 10.90625 L 2.15625 13.84375 L 5.09375 13.03125 L 5.84375 16 L 8 13.8125 L 10.15625 16 L 10.90625 13.03125 L 13.84375 13.84375 L 13.03125 10.90625 L 16 10.15625 L 13.8125 8 L 16 5.84375 L 13.03125 5.09375 L 13.84375 2.15625 L 10.90625 2.96875 L 10.15625 0 L 8 2.1875 L 5.84375 0 z M 8 3 C 10.761424 3 13 5.2385763 13 8 C 13 10.761424 10.761424 13 8 13 L 8 3 z "
+ transform="translate(0,6)"
+ id="path3075" />
+ </g>
+</svg>
diff --git a/brightnessarc-widget/README.md b/brightnessarc-widget/README.md
deleted file mode 100644
index c27f366..0000000
--- a/brightnessarc-widget/README.md
+++ /dev/null
@@ -1,97 +0,0 @@
-# Brightness widget
-
-This widget represents current brightness level: ![Brightness widget](./br-wid-1.png)
-
-## Customization
-
-It is possible to customize widget by providing a table with all or some of the following config parameters:
-
-| Name | Default | Description |
-|---|---|---|
-| `get_brightness_cmd` | `light -G` | Get current screen brightness |
-| `inc_brightness_cmd` | `light -A 5` | Increase brightness |
-| `dec_brightness_cmd` | `light -U 5`| Decrease brightness |
-| `color` | `beautiful.fg_color` | Color of the arc |
-| `bg_color` | `#ffffff11` | Color of the arc's background |
-| `path_to_icon` | `/usr/share/icons/Arc/status/symbolic/display-brightness-symbolic.svg` | Path to the icon |
-| `timeout` | 1 | How often in seconds the widget refreshes |
-
-### Example:
-
-```lua
-brightnessarc_widget({
- get_brightness_cmd = 'xbacklight -get',
- inc_brightness_cmd = 'xbacklight -inc 5',
- dec_brightness_cmd = 'xbacklight -dec 5'
- color = '/usr/share/icons/Arc/status/symbolic/brightness-display-symbolic.svg'
-})
-```
-
-
-## Installation
-
-First you need to get the current brightness level. There are two options:
-
- - using `xbacklight` command (depending on your video card (I guess) it may or may not work)
-
- To check if it works install xbackligth and check if it works:
-
- ```bash
- sudo apt-get install xbacklight
- xbacklight -get
- ```
-
- If there is no output it means that it doesn't work, but there is a second option:
-
- - using `light` command
-
- Install it from this git repo: [github.com/haikarainen/light](https://github.com/haikarainen/light) and check if it works but running
-
- ```bash
- git clone https://github.com/haikarainen/light.git && \
- cd ./light && \
- sudo make && sudo make install \
- light -G
- 49.18
- ```
-
-Then clone this repo under **~/.config/awesome/**:
-
-```bash
-git clone https://github.com/streetturtle/awesome-wm-widgets.git ~/.config/awesome/awesome-wm-widgets
-```
-
-Require widget at the beginning of **rc.lua**:
-
-```lua
-local brightnessarc_widget = require("awesome-wm-widgets.brightnessarc-widget.brightnessarc")
-```
-
-Add widget to the tasklist:
-
-```lua
-s.mytasklist, -- Middle widget
- { -- Right widgets
- layout = wibox.layout.fixed.horizontal,
- ...
- -- default
- brightnessarc_widget(),
- -- or customized
- brightnessarc_widget({
- get_brightness_cmd = 'xbacklight -get',
- inc_brightness_cmd = 'xbacklight -inc 5',
- dec_brightness_cmd = 'xbacklight -dec 5'
- })
- }
- ...
-```
-
-## Controls
-
-In order to change brightness by shortcuts you can add them to the `globalkeys` table in the **rc.lua**:
-
-```lua
-awful.key({ modkey }, ";", function () awful.spawn("light -A 5") end, {description = "increase brightness", group = "custom"}),
-awful.key({ modkey, "Shift"}, ";", function () awful.spawn("light -U 5") end, {description = "decrease brightness", group = "custom"}),
-```
-On laptop you can use `XF86MonBrightnessUp` and `XF86MonBrightnessDown` keys.
diff --git a/brightnessarc-widget/br-wid-1.png b/brightnessarc-widget/br-wid-1.png
deleted file mode 100644
index f9200eb..0000000
--- a/brightnessarc-widget/br-wid-1.png
+++ /dev/null
Binary files differ
diff --git a/brightnessarc-widget/brightnessarc.lua b/brightnessarc-widget/brightnessarc.lua
deleted file mode 100644
index fd37894..0000000
--- a/brightnessarc-widget/brightnessarc.lua
+++ /dev/null
@@ -1,77 +0,0 @@
--------------------------------------------------
--- Brightness Widget for Awesome Window Manager
--- Shows the brightness level of the laptop display
--- More details could be found here:
--- https://github.com/streetturtle/awesome-wm-widgets/tree/master/widget-widget
-
--- @author Pavel Makhov
--- @copyright 2019 Pavel Makhov
--------------------------------------------------
-
-local wibox = require("wibox")
-local watch = require("awful.widget.watch")
-local spawn = require("awful.spawn")
-local beautiful = require("beautiful")
-
-local PATH_TO_ICON = "/usr/share/icons/Arc/status/symbolic/display-brightness-symbolic.svg"
-local GET_BRIGHTNESS_CMD = "light -G" -- "xbacklight -get"
-local INC_BRIGHTNESS_CMD = "light -A 5" -- "xbacklight -inc 5"
-local DEC_BRIGHTNESS_CMD = "light -U 5" -- "xbacklight -dec 5"
-
-local brightness_widget = {}
-
-local function worker(user_args)
-
- local args = user_args or {}
-
- local get_brightness_cmd = args.get_brightness_cmd or GET_BRIGHTNESS_CMD
- local inc_brightness_cmd = args.inc_brightness_cmd or INC_BRIGHTNESS_CMD
- local dec_brightness_cmd = args.dec_brightness_cmd or DEC_BRIGHTNESS_CMD
- local color = args.color or beautiful.fg_color
- local bg_color = args.bg_color or '#ffffff11'
- local path_to_icon = args.path_to_icon or PATH_TO_ICON
- local timeout = args.timeout or 1
-
- local icon = {
- id = "icon",
- image = path_to_icon,
- resize = true,
- widget = wibox.widget.imagebox,
- }
-
- brightness_widget = wibox.widget {
- icon,
- max_value = 1,
- thickness = 2,
- start_angle = 4.71238898, -- 2pi*3/4
- forced_height = 18,
- forced_width = 18,
- bg = bg_color,
- paddings = 2,
- colors = {color},
- widget = wibox.container.arcchart
- }
-
- local update_widget = function(widget, stdout)
- local brightness_level = string.match(stdout, "(%d?%d?%d?)")
- brightness_level = tonumber(string.format("% 3d", brightness_level))
-
- widget.value = brightness_level / 100;
- end
-
- brightness_widget:connect_signal("button::press", function(_, _, _, button)
- if (button == 4) then
- spawn(inc_brightness_cmd, false)
- elseif (button == 5) then
- spawn(dec_brightness_cmd, false)
- end
- end)
-
- watch(get_brightness_cmd, timeout, update_widget, brightness_widget)
-
- return brightness_widget
-end
-
-return setmetatable(brightness_widget, { __call = function(_, ...)
- return worker(...)
-end })