Initial commit

This commit is contained in:
Kristofers Solo
2022-04-27 11:41:37 +03:00
commit f1d310a07d
700 changed files with 101758 additions and 0 deletions

View File

@@ -0,0 +1,93 @@
# Brightness widget
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
It is possible to customize widget by providing a table with all or some of the following config parameters:
| Name | Default | Description |
|---|---|---|
| `type`| `arc` | The widget type. Could be `arc` or `icon_and_text` |
| `program` | `light` | The program used to control the brightness, either `light`, `xbacklight`, or `brightnessctl`. |
| `step` | 5 | Step |
| `base` | 20 | Base level to set brightness to on left click. |
| `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. Check the note below |
| `tooltip` | false | Display brightness level in a tooltip when the mouse cursor hovers the widget |
_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
To choose the right `program` argument, first you need to check which of them works better for you.
- using `xbacklight`:
Install (on Ubuntu it's available in the apt repository) it and check if it works by running:
```bash
xbacklight -get
```
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 (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
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.
- using `brightnessctl`:
On Ubuntu it is available in the apt repository. Install and check the ouptut of the following command.
```bash
brightnessctl --list
```
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 brightness_widget = require("awesome-wm-widgets.brightness-widget.brightness")
```
Add the widget to the tasklist:
```lua
s.mytasklist, -- Middle widget
{ -- Right widgets
layout = wibox.layout.fixed.horizontal,
...
-- default
brightness_widget(),
-- or customized
brightness_widget{
type = 'icon_and_text',
program = 'xbacklight',
step = 2,
}
}
...
```
## 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 () brightness_widget:inc() end, {description = "increase brightness", group = "custom"}),
awful.key({ modkey, "Shift"}, ";", function () brightness_widget:dec() end, {description = "decrease brightness", group = "custom"}),
```
On a laptop you can use `XF86MonBrightnessUp` and `XF86MonBrightnessDown` keys.

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 KiB

View File

@@ -0,0 +1,186 @@
-------------------------------------------------
-- 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/brightness-widget
-- @author 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 ICON_DIR = os.getenv("HOME") .. '/.config/awesome/awesome-wm-widgets/brightness-widget/'
local get_brightness_cmd
local set_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 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 100
local program = args.program or 'light'
local step = args.step or 5
local base = args.base or 20
local current_level = 0 -- current brightness value
local tooltip = args.tooltip or false
if program == 'light' then
get_brightness_cmd = 'light -G'
set_brightness_cmd = 'light -S %d' -- <level>
inc_brightness_cmd = 'light -A ' .. step
dec_brightness_cmd = 'light -U ' .. step
elseif program == 'xbacklight' then
get_brightness_cmd = 'xbacklight -get'
set_brightness_cmd = 'xbacklight -set %d' -- <level>
inc_brightness_cmd = 'xbacklight -inc ' .. step
dec_brightness_cmd = 'xbacklight -dec ' .. step
elseif program == 'brightnessctl' then
get_brightness_cmd = 'bash -c "brightnessctl -m | cut -d, -f4 | tr -d %"'
set_brightness_cmd = 'brightnessctl set %d%%' -- <level>
inc_brightness_cmd = 'brightnessctl set +' .. step .. '%'
dec_brightness_cmd = 'brightnessctl set ' .. 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,
},
valign = '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,
},
valign = 'center',
layout = wibox.container.place
},
max_value = 100,
thickness = 2,
start_angle = 4.71238898, -- 2pi*3/4
forced_height = 18,
forced_width = 18,
paddings = 2,
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))
current_level = brightness_level
widget:set_value(brightness_level)
end
function brightness_widget:set(value)
current_level = value
spawn.easy_async(string.format(set_brightness_cmd, value), function()
spawn.easy_async(get_brightness_cmd, function(out)
update_widget(brightness_widget.widget, out)
end)
end)
end
local old_level = 0
function brightness_widget:toggle()
if old_level < 0.1 then
-- avoid toggling between '0' and 'almost 0'
old_level = 1
end
if current_level < 0.1 then
-- restore previous level
current_level = old_level
else
-- save current brightness for later
old_level = current_level
current_level = 0
end
brightness_widget:set(current_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.widget:buttons(
awful.util.table.join(
awful.button({}, 1, function() brightness_widget:set(base) end),
awful.button({}, 3, function() brightness_widget:toggle() end),
awful.button({}, 4, function() brightness_widget:inc() end),
awful.button({}, 5, function() brightness_widget:dec() end)
)
)
watch(get_brightness_cmd, timeout, update_widget, brightness_widget.widget)
if tooltip then
awful.tooltip {
objects = { brightness_widget.widget },
timer_function = function()
return current_level .. " %"
end,
}
end
return brightness_widget.widget
end
return setmetatable(brightness_widget, { __call = function(_, ...)
return worker(...)
end })

View File

@@ -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>

After

Width:  |  Height:  |  Size: 6.3 KiB