Merge branch '74-externalize-config'
Note: breaking change, now widgets should be created with parentheses, i.e. battery(), instead of battery. Read more in README of the widget.
|
@ -109,7 +109,7 @@ watch("acpi -i", 10,
|
||||||
batteryType = "battery-empty%s-symbolic"
|
batteryType = "battery-empty%s-symbolic"
|
||||||
if status ~= 'Charging' and os.difftime(os.time(), last_battery_check) > 300 then
|
if status ~= 'Charging' and os.difftime(os.time(), last_battery_check) > 300 then
|
||||||
-- if 5 minutes have elapsed since the last warning
|
-- if 5 minutes have elapsed since the last warning
|
||||||
last_battery_check = time()
|
last_battery_check = os.time()
|
||||||
|
|
||||||
show_battery_warning()
|
show_battery_warning()
|
||||||
end
|
end
|
||||||
|
|
|
@ -11,18 +11,27 @@ Depending of the battery status it could look following ways:
|
||||||
- ![80_d](./80_d.png) - more than 40 percent
|
- ![80_d](./80_d.png) - more than 40 percent
|
||||||
- ![80_c](./80_c.png) - more than 40 percent, charging
|
- ![80_c](./80_c.png) - more than 40 percent, charging
|
||||||
|
|
||||||
Widget uses following beautiful variables with values:
|
If a battery level is low then warning popup will show up:
|
||||||
|
|
||||||
```lua
|
![warning](./warning.png)
|
||||||
theme.widget_main_color = "#74aeab"
|
|
||||||
theme.widget_red = "#e53935"
|
|
||||||
theme.widget_yellow = "#c0ca33"
|
|
||||||
theme.widget_green = "#43a047"
|
|
||||||
theme.widget_black = "#000000"
|
|
||||||
theme.widget_transparent = "#00000000"
|
|
||||||
```
|
|
||||||
|
|
||||||
which means that you need to copy the code above and paste it in your **theme.lua**. Otherwise you can change colors directly in the widget.
|
## Customization
|
||||||
|
|
||||||
|
It is possible to customize widget by providing a table with all or some of the following config parameters:
|
||||||
|
|
||||||
|
| Name | Default | Description |
|
||||||
|
|---|---|---|
|
||||||
|
| `font` | Font | Play 6 |
|
||||||
|
| `arc_thickness` | 2 | Thickness of the arc |
|
||||||
|
| `show_current_level`| false | Show current charge level |
|
||||||
|
| `main_color` | `beautiful.fg_color` | Color of the text with the current charge level and the arc |
|
||||||
|
| `low_level_color` | #e53935 | Arc color when battery charge is less that 15% |
|
||||||
|
| `medium_level_color` | #c0ca33 | Arc color when battery charge is between 15% and 40% |
|
||||||
|
| `charging` | `beautiful.fg_color` | Color of the circle inside the arc when charging |
|
||||||
|
| `warning_msg_title` | _Huston, we have a problem_ | Title of the warning popup |
|
||||||
|
| `warning_msg_text` | _Battery is dying_ | Text of the warning popup |
|
||||||
|
| `warning_msg_position` | `bottom_right` | Position of the warning popup |
|
||||||
|
| `warning_msg_icon` | ~/.config/awesome/awesome-wm-widgets/batteryarc-widget/spaceman.jpg | Icon of the warning popup |
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
|
@ -35,11 +44,17 @@ s.mytasklist, -- Middle widget
|
||||||
{ -- Right widgets
|
{ -- Right widgets
|
||||||
layout = wibox.layout.fixed.horizontal,
|
layout = wibox.layout.fixed.horizontal,
|
||||||
...
|
...
|
||||||
batteryarc_widget,
|
--[[default]]
|
||||||
|
batteryarc_widget(),
|
||||||
|
--[[or customized]]
|
||||||
|
batteryarc_widget({
|
||||||
|
show_current_level = true,
|
||||||
|
thickness = '1',
|
||||||
|
}),
|
||||||
|
}
|
||||||
...
|
...
|
||||||
```
|
```
|
||||||
You can get the icon for warning popup [here](https://vk.com/images/stickers/1933/512.png)
|
|
||||||
|
|
||||||
## Troubleshooting
|
## Troubleshooting
|
||||||
|
|
||||||
In case of any doubts or questions don't hesitate to raise an [issue](https://github.com/streetturtle/awesome-wm-widgets/issues/new).
|
In case of any doubts or questions please raise an [issue](https://github.com/streetturtle/awesome-wm-widgets/issues/new).
|
||||||
|
|
|
@ -16,9 +16,29 @@ local watch = require("awful.widget.watch")
|
||||||
|
|
||||||
local HOME = os.getenv("HOME")
|
local HOME = os.getenv("HOME")
|
||||||
|
|
||||||
|
local widget = {}
|
||||||
|
|
||||||
|
local function worker(args)
|
||||||
|
|
||||||
|
local args = args or {}
|
||||||
|
|
||||||
|
local font = args.font or 'Play 6'
|
||||||
|
local arc_thickness = args.thickness or 2
|
||||||
|
local show_current_level = args.show_current_level or false
|
||||||
|
|
||||||
|
local main_color = args.main_color or beautiful.fg_color
|
||||||
|
local low_level_color = args.low_level_color or '#e53935'
|
||||||
|
local medium_level_color = args.medium_level_color or '#c0ca33'
|
||||||
|
local charging_color = args.charging_color or '#43a047'
|
||||||
|
|
||||||
|
local warning_msg_title = args.warning_msg_title or 'Huston, we have a problem'
|
||||||
|
local warning_msg_text = args.warning_msg_text or 'Battery is dying'
|
||||||
|
local warning_msg_position = args.warning_msg_position or 'bottom_right'
|
||||||
|
local warning_msg_icon = args.warning_msg_icon or HOME .. '/.config/awesome/awesome-wm-widgets/batteryarc-widget/spaceman.jpg'
|
||||||
|
|
||||||
local text = wibox.widget {
|
local text = wibox.widget {
|
||||||
id = "txt",
|
id = "txt",
|
||||||
font = "Play 6",
|
font = font,
|
||||||
align = 'center', -- align the text
|
align = 'center', -- align the text
|
||||||
valign = 'center',
|
valign = 'center',
|
||||||
widget = wibox.widget.textbox
|
widget = wibox.widget.textbox
|
||||||
|
@ -26,11 +46,11 @@ local text = wibox.widget {
|
||||||
|
|
||||||
local text_with_background = wibox.container.background(text)
|
local text_with_background = wibox.container.background(text)
|
||||||
|
|
||||||
local batteryarc = wibox.widget {
|
widget = wibox.widget {
|
||||||
text_with_background,
|
text_with_background,
|
||||||
max_value = 1,
|
max_value = 1,
|
||||||
rounded_edge = true,
|
rounded_edge = true,
|
||||||
thickness = 2,
|
thickness = arc_thickness,
|
||||||
start_angle = 4.71238898, -- 2pi*3/4
|
start_angle = 4.71238898, -- 2pi*3/4
|
||||||
forced_height = 18,
|
forced_height = 18,
|
||||||
forced_width = 18,
|
forced_width = 18,
|
||||||
|
@ -90,20 +110,24 @@ watch("acpi -i", 10,
|
||||||
widget.value = charge / 100
|
widget.value = charge / 100
|
||||||
|
|
||||||
if status == 'Charging' then
|
if status == 'Charging' then
|
||||||
text_with_background.bg = beautiful.widget_green
|
text_with_background.bg = charging_color
|
||||||
text_with_background.fg = beautiful.widget_black
|
text_with_background.fg = '#000000'
|
||||||
else
|
else
|
||||||
text_with_background.bg = beautiful.widget_transparent
|
text_with_background.bg = '#00000000'
|
||||||
text_with_background.fg = beautiful.widget_main_color
|
text_with_background.fg = main_color
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if show_current_level == true then
|
||||||
--- if battery is fully charged (100) there is not enough place for three digits, so we don't show any text
|
--- if battery is fully charged (100) there is not enough place for three digits, so we don't show any text
|
||||||
text.text = charge == 100
|
text.text = charge == 100
|
||||||
and ''
|
and ''
|
||||||
or string.format('%d', charge)
|
or string.format('%d', charge)
|
||||||
|
else
|
||||||
|
text.text = ''
|
||||||
|
end
|
||||||
|
|
||||||
if charge < 15 then
|
if charge < 15 then
|
||||||
batteryarc.colors = { beautiful.widget_red }
|
widget.colors = { low_level_color }
|
||||||
if status ~= 'Charging' and os.difftime(os.time(), last_battery_check) > 300 then
|
if status ~= 'Charging' and os.difftime(os.time(), last_battery_check) > 300 then
|
||||||
-- if 5 minutes have elapsed since the last warning
|
-- if 5 minutes have elapsed since the last warning
|
||||||
last_battery_check = os.time()
|
last_battery_check = os.time()
|
||||||
|
@ -111,12 +135,12 @@ watch("acpi -i", 10,
|
||||||
show_battery_warning()
|
show_battery_warning()
|
||||||
end
|
end
|
||||||
elseif charge > 15 and charge < 40 then
|
elseif charge > 15 and charge < 40 then
|
||||||
batteryarc.colors = { beautiful.widget_yellow }
|
widget.colors = { medium_level_color }
|
||||||
else
|
else
|
||||||
batteryarc.colors = { beautiful.widget_main_color }
|
widget.colors = { main_color }
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
batteryarc)
|
widget)
|
||||||
|
|
||||||
-- Popup with battery info
|
-- Popup with battery info
|
||||||
-- One way of creating a pop-up notification - naughty.notify
|
-- One way of creating a pop-up notification - naughty.notify
|
||||||
|
@ -135,8 +159,12 @@ function show_battery_status()
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
batteryarc:connect_signal("mouse::enter", function() show_battery_status() end)
|
widget:connect_signal("mouse::enter", function()
|
||||||
batteryarc:connect_signal("mouse::leave", function() naughty.destroy(notification) end)
|
show_battery_status()
|
||||||
|
end)
|
||||||
|
widget:connect_signal("mouse::leave", function()
|
||||||
|
naughty.destroy(notification)
|
||||||
|
end)
|
||||||
|
|
||||||
-- Alternative to naughty.notify - tooltip. You can compare both and choose the preferred one
|
-- Alternative to naughty.notify - tooltip. You can compare both and choose the preferred one
|
||||||
|
|
||||||
|
@ -150,17 +178,23 @@ batteryarc:connect_signal("mouse::leave", function() naughty.destroy(notificatio
|
||||||
--[[ Show warning notification ]]
|
--[[ Show warning notification ]]
|
||||||
function show_battery_warning()
|
function show_battery_warning()
|
||||||
naughty.notify {
|
naughty.notify {
|
||||||
icon = HOME .. "/.config/awesome/awesome-wm-widgets/batteryarc-widget/spaceman.jpg",
|
icon = warning_msg_icon,
|
||||||
icon_size = 100,
|
icon_size = 100,
|
||||||
text = "Battery is dying", -- switch text and title
|
text = warning_msg_text,
|
||||||
title = "Huston, we have a problem",
|
title = warning_msg_title,
|
||||||
timeout = 25, -- show the warning for a longer time
|
timeout = 25, -- show the warning for a longer time
|
||||||
hover_timeout = 0.5,
|
hover_timeout = 0.5,
|
||||||
position = "bottom_right",
|
position = warning_msg_position,
|
||||||
bg = "#F06060",
|
bg = "#F06060",
|
||||||
fg = "#EEE9EF",
|
fg = "#EEE9EF",
|
||||||
width = 300,
|
width = 300,
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
return batteryarc
|
return widget
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
return setmetatable(widget, { __call = function(_, ...)
|
||||||
|
return worker(...)
|
||||||
|
end })
|
||||||
|
|
After Width: | Height: | Size: 13 KiB |
|
@ -2,6 +2,29 @@
|
||||||
|
|
||||||
This widget represents current brightness level: ![Brightness widget](./br-wid-1.png)
|
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 |
|
||||||
|
| `path_to_icon` | `/usr/share/icons/Arc/status/symbolic/display-brightness-symbolic.svg` | Path to the icon |
|
||||||
|
| `font` | `Play 9` | Font |
|
||||||
|
|
||||||
|
### Example:
|
||||||
|
|
||||||
|
```lua
|
||||||
|
brightness_widget({
|
||||||
|
get_brightness_cmd = 'xbacklight -get',
|
||||||
|
inc_brightness_cmd = 'xbacklight -inc 5',
|
||||||
|
dec_brightness_cmd = 'xbacklight -dec 5'
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
First you need to get the current brightness level. There are two options:
|
First you need to get the current brightness level. There are two options:
|
||||||
|
@ -29,8 +52,6 @@ First you need to get the current brightness level. There are two options:
|
||||||
49.18
|
49.18
|
||||||
```
|
```
|
||||||
|
|
||||||
Depending on the chosen option change `GET_BRIGHTNESS_CMD` variable in **brightness.lua**.
|
|
||||||
|
|
||||||
Then clone this repo under **~/.config/awesome/**:
|
Then clone this repo under **~/.config/awesome/**:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
|
@ -50,7 +71,15 @@ s.mytasklist, -- Middle widget
|
||||||
{ -- Right widgets
|
{ -- Right widgets
|
||||||
layout = wibox.layout.fixed.horizontal,
|
layout = wibox.layout.fixed.horizontal,
|
||||||
...
|
...
|
||||||
brightness_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'
|
||||||
|
})
|
||||||
|
}
|
||||||
...
|
...
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
-- https://github.com/streetturtle/awesome-wm-widgets/tree/master/brightness-widget
|
-- https://github.com/streetturtle/awesome-wm-widgets/tree/master/brightness-widget
|
||||||
|
|
||||||
-- @author Pavel Makhov
|
-- @author Pavel Makhov
|
||||||
-- @copyright 2017 Pavel Makhov
|
-- @copyright 2017-2019 Pavel Makhov
|
||||||
-------------------------------------------------
|
-------------------------------------------------
|
||||||
|
|
||||||
local wibox = require("wibox")
|
local wibox = require("wibox")
|
||||||
|
@ -17,12 +17,24 @@ local GET_BRIGHTNESS_CMD = "light -G" -- "xbacklight -get"
|
||||||
local INC_BRIGHTNESS_CMD = "light -A 5" -- "xbacklight -inc 5"
|
local INC_BRIGHTNESS_CMD = "light -A 5" -- "xbacklight -inc 5"
|
||||||
local DEC_BRIGHTNESS_CMD = "light -U 5" -- "xbacklight -dec 5"
|
local DEC_BRIGHTNESS_CMD = "light -U 5" -- "xbacklight -dec 5"
|
||||||
|
|
||||||
|
local widget = {}
|
||||||
|
|
||||||
|
local function worker(args)
|
||||||
|
|
||||||
|
local args = 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 font = args.font or 'Play 9'
|
||||||
|
|
||||||
local brightness_text = wibox.widget.textbox()
|
local brightness_text = wibox.widget.textbox()
|
||||||
brightness_text:set_font('Play 9')
|
brightness_text:set_font(font)
|
||||||
|
|
||||||
local brightness_icon = wibox.widget {
|
local brightness_icon = wibox.widget {
|
||||||
{
|
{
|
||||||
image = PATH_TO_ICON,
|
image = path_to_icon,
|
||||||
resize = false,
|
resize = false,
|
||||||
widget = wibox.widget.imagebox,
|
widget = wibox.widget.imagebox,
|
||||||
},
|
},
|
||||||
|
@ -30,23 +42,30 @@ local brightness_icon = wibox.widget {
|
||||||
widget = wibox.container.margin
|
widget = wibox.container.margin
|
||||||
}
|
}
|
||||||
|
|
||||||
local brightness_widget = wibox.widget {
|
widget = wibox.widget {
|
||||||
brightness_icon,
|
brightness_icon,
|
||||||
brightness_text,
|
brightness_text,
|
||||||
layout = wibox.layout.fixed.horizontal,
|
layout = wibox.layout.fixed.horizontal,
|
||||||
}
|
}
|
||||||
|
|
||||||
local update_widget = function(widget, stdout, stderr, exitreason, exitcode)
|
local update_widget = function(widget, stdout, _, _, _)
|
||||||
local brightness_level = tonumber(string.format("%.0f", stdout))
|
local brightness_level = tonumber(string.format("%.0f", stdout))
|
||||||
widget:set_text(" " .. brightness_level .. "%")
|
widget:set_text(" " .. brightness_level .. "%")
|
||||||
end,
|
end,
|
||||||
|
|
||||||
brightness_widget:connect_signal("button::press", function(_,_,_,button)
|
widget:connect_signal("button::press", function(_, _, _, button)
|
||||||
if (button == 4) then spawn(INC_BRIGHTNESS_CMD, false)
|
if (button == 4) then
|
||||||
elseif (button == 5) then spawn(DEC_BRIGHTNESS_CMD, false)
|
spawn(inc_brightness_cmd, false)
|
||||||
|
elseif (button == 5) then
|
||||||
|
spawn(dec_brightness_cmd, false)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
watch(GET_BRIGHTNESS_CMD, 1, update_widget, brightness_text)
|
watch(get_brightness_cmd, 1, update_widget, brightness_text)
|
||||||
|
|
||||||
return brightness_widget
|
return widget
|
||||||
|
end
|
||||||
|
|
||||||
|
return setmetatable(widget, { __call = function(_, ...)
|
||||||
|
return worker(...)
|
||||||
|
end })
|
||||||
|
|
|
@ -1,12 +1,34 @@
|
||||||
# Brightness widget
|
# Brightness widget
|
||||||
|
|
||||||
![Brightness widget](./br-wid-1.png)
|
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 |
|
||||||
|
| `path_to_icon` | `/usr/share/icons/Arc/status/symbolic/display-brightness-symbolic.svg` | Path to the icon |
|
||||||
|
|
||||||
|
### 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'
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
This widget represents current brightness level.
|
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
Firstly you need to get the current brightness level. There are two options:
|
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)
|
- using `xbacklight` command (depending on your video card (I guess) it may or may not work)
|
||||||
|
|
||||||
|
@ -30,19 +52,36 @@ Firstly you need to get the current brightness level. There are two options:
|
||||||
light -G
|
light -G
|
||||||
49.18
|
49.18
|
||||||
```
|
```
|
||||||
Depending on the chosen option change `GET_BRIGHTNESS_CMD` variable in **brightness.lua**.
|
|
||||||
|
|
||||||
Then in **rc.lua** add the import on top of the file and then add widget to the wibox:
|
Then clone this repo under **~/.config/awesome/**:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
git clone https://github.com/streetturtle/awesome-wm-widgets.git ~/.config/awesome/
|
||||||
|
```
|
||||||
|
|
||||||
|
Require widget at the beginning of **rc.lua**:
|
||||||
|
|
||||||
```lua
|
```lua
|
||||||
require("awesome-wm-widgets.brightness-widget.brightness")
|
local brightnessarc_widget = require("awesome-wm-widgets.brightnessarc-widget.brightnessarc")
|
||||||
...
|
```
|
||||||
-- Add widgets to the wibox
|
|
||||||
s.mywibox:setup {
|
Add widget to the tasklist:
|
||||||
...
|
|
||||||
|
```lua
|
||||||
|
s.mytasklist, -- Middle widget
|
||||||
{ -- Right widgets
|
{ -- 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'
|
||||||
|
})
|
||||||
|
}
|
||||||
...
|
...
|
||||||
brightness_widget
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## Controls
|
## Controls
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
-- Brightness Widget for Awesome Window Manager
|
-- Brightness Widget for Awesome Window Manager
|
||||||
-- Shows the brightness level of the laptop display
|
-- Shows the brightness level of the laptop display
|
||||||
-- More details could be found here:
|
-- More details could be found here:
|
||||||
-- https://github.com/streetturtle/awesome-wm-widgets/tree/master/brightnessarc-widget
|
-- https://github.com/streetturtle/awesome-wm-widgets/tree/master/widget-widget
|
||||||
|
|
||||||
-- @author Pavel Makhov
|
-- @author Pavel Makhov
|
||||||
-- @copyright 2019 Pavel Makhov
|
-- @copyright 2019 Pavel Makhov
|
||||||
|
@ -11,20 +11,33 @@
|
||||||
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 beautiful = require("beautiful")
|
||||||
|
|
||||||
local PATH_TO_ICON = "/usr/share/icons/Arc/status/symbolic/display-brightness-symbolic.svg"
|
local PATH_TO_ICON = "/usr/share/icons/Arc/status/symbolic/display-brightness-symbolic.svg"
|
||||||
local GET_BRIGHTNESS_CMD = "light -G" -- "xbacklight -get"
|
local GET_BRIGHTNESS_CMD = "light -G" -- "xbacklight -get"
|
||||||
local INC_BRIGHTNESS_CMD = "light -A 5" -- "xbacklight -inc 5"
|
local INC_BRIGHTNESS_CMD = "light -A 5" -- "xbacklight -inc 5"
|
||||||
local DEC_BRIGHTNESS_CMD = "light -U 5" -- "xbacklight -dec 5"
|
local DEC_BRIGHTNESS_CMD = "light -U 5" -- "xbacklight -dec 5"
|
||||||
|
|
||||||
|
local widget = {}
|
||||||
|
|
||||||
|
local function worker(args)
|
||||||
|
|
||||||
|
local args = 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 path_to_icon = args.path_to_icon or PATH_TO_ICON
|
||||||
|
|
||||||
local icon = {
|
local icon = {
|
||||||
id = "icon",
|
id = "icon",
|
||||||
image = PATH_TO_ICON,
|
image = path_to_icon,
|
||||||
resize = true,
|
resize = true,
|
||||||
widget = wibox.widget.imagebox,
|
widget = wibox.widget.imagebox,
|
||||||
}
|
}
|
||||||
|
|
||||||
local brightnessarc = wibox.widget {
|
widget = wibox.widget {
|
||||||
icon,
|
icon,
|
||||||
max_value = 1,
|
max_value = 1,
|
||||||
thickness = 2,
|
thickness = 2,
|
||||||
|
@ -33,6 +46,7 @@ local brightnessarc = wibox.widget {
|
||||||
forced_width = 18,
|
forced_width = 18,
|
||||||
bg = "#ffffff11",
|
bg = "#ffffff11",
|
||||||
paddings = 2,
|
paddings = 2,
|
||||||
|
colors = {color},
|
||||||
widget = wibox.container.arcchart
|
widget = wibox.container.arcchart
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,12 +57,19 @@ local update_widget = function(widget, stdout)
|
||||||
widget.value = brightness_level / 100;
|
widget.value = brightness_level / 100;
|
||||||
end,
|
end,
|
||||||
|
|
||||||
brightnessarc:connect_signal("button::press", function(_, _, _, button)
|
widget:connect_signal("button::press", function(_, _, _, button)
|
||||||
if (button == 4) then spawn(INC_BRIGHTNESS_CMD, false)
|
if (button == 4) then
|
||||||
elseif (button == 5) then spawn(DEC_BRIGHTNESS_CMD, false)
|
spawn(inc_brightness_cmd, false)
|
||||||
|
elseif (button == 5) then
|
||||||
|
spawn(dec_brightness_cmd, false)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
watch(GET_BRIGHTNESS_CMD, 1, update_widget, brightnessarc)
|
watch(get_brightness_cmd, 1, update_widget, widget)
|
||||||
|
|
||||||
return brightnessarc
|
return widget
|
||||||
|
end
|
||||||
|
|
||||||
|
return setmetatable(widget, { __call = function(_, ...)
|
||||||
|
return worker(...)
|
||||||
|
end })
|
||||||
|
|
|
@ -2,9 +2,7 @@
|
||||||
|
|
||||||
This widget shows the average CPU load among all cores of the machine:
|
This widget shows the average CPU load among all cores of the machine:
|
||||||
|
|
||||||
![screenshot](out.gif)
|
![screenshot](cpu.gif)
|
||||||
|
|
||||||
When the load is more than 80% the graph becomes red. You can easily customize the widget by changing colors, step width, step spacing, width and interval.
|
|
||||||
|
|
||||||
## How it works
|
## How it works
|
||||||
|
|
||||||
|
@ -18,6 +16,32 @@ cpu 197294 718 50102 2002182 3844 0 2724 0 0 0
|
||||||
|
|
||||||
and calculates the percentage.
|
and calculates the percentage.
|
||||||
|
|
||||||
|
## Customization
|
||||||
|
|
||||||
|
It is possible to customize widget by providing a table with all or some of the following config parameters:
|
||||||
|
|
||||||
|
| Name | Default | Description |
|
||||||
|
|---|---|---|
|
||||||
|
| `width` | 50 | Width of the widget |
|
||||||
|
| `step_width` | 2 | Width of the step |
|
||||||
|
| `step_spacing` | 1 | Space size between steps |
|
||||||
|
| `color` | `beautiful.fg_normal` | Color of the graph |
|
||||||
|
|
||||||
|
### Example
|
||||||
|
|
||||||
|
```lua
|
||||||
|
cpu_widget({
|
||||||
|
width = 70,
|
||||||
|
step_width = 2,
|
||||||
|
step_spacing = 0,
|
||||||
|
color = '#434c5e'
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
|
The config above results in the following widget:
|
||||||
|
|
||||||
|
![custom](./custom.png)
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
Clone/download repo and use widget in **rc.lua**:
|
Clone/download repo and use widget in **rc.lua**:
|
||||||
|
@ -29,6 +53,14 @@ s.mytasklist, -- Middle widget
|
||||||
{ -- Right widgets
|
{ -- Right widgets
|
||||||
layout = wibox.layout.fixed.horizontal,
|
layout = wibox.layout.fixed.horizontal,
|
||||||
...
|
...
|
||||||
cpu_widget,
|
-- default
|
||||||
|
cpu_widget(),
|
||||||
|
-- or custom
|
||||||
|
cpu_widget({
|
||||||
|
width = 70,
|
||||||
|
step_width = 2,
|
||||||
|
step_spacing = 0,
|
||||||
|
color = '#434c5e'
|
||||||
|
})
|
||||||
...
|
...
|
||||||
```
|
```
|
||||||
|
|
|
@ -10,15 +10,27 @@
|
||||||
|
|
||||||
local watch = require("awful.widget.watch")
|
local watch = require("awful.widget.watch")
|
||||||
local wibox = require("wibox")
|
local wibox = require("wibox")
|
||||||
|
local beautiful = require("beautiful")
|
||||||
|
|
||||||
|
local widget = {}
|
||||||
|
|
||||||
|
local function worker(args)
|
||||||
|
|
||||||
|
local args = args or {}
|
||||||
|
|
||||||
|
local width = args.width or 50
|
||||||
|
local step_width = args.step_width or 2
|
||||||
|
local step_spacing = args.step_spacing or 1
|
||||||
|
local color= args.color or beautiful.fg_normal
|
||||||
|
|
||||||
local cpugraph_widget = wibox.widget {
|
local cpugraph_widget = wibox.widget {
|
||||||
max_value = 100,
|
max_value = 100,
|
||||||
background_color = "#00000000",
|
background_color = "#00000000",
|
||||||
forced_width = 50,
|
forced_width = width,
|
||||||
step_width = 2,
|
step_width = step_width,
|
||||||
step_spacing = 1,
|
step_spacing = step_spacing,
|
||||||
widget = wibox.widget.graph,
|
widget = wibox.widget.graph,
|
||||||
color = "linear:0,0:0,22:0,#FF0000:0.3,#FFFF00:0.5,#74aeab"
|
color = "linear:0,0:0,20:0,#FF0000:0.3,#FFFF00:0.6," .. color
|
||||||
}
|
}
|
||||||
|
|
||||||
--- By default graph widget goes from left to right, so we mirror it and push up a bit
|
--- By default graph widget goes from left to right, so we mirror it and push up a bit
|
||||||
|
@ -47,3 +59,9 @@ watch([[bash -c "cat /proc/stat | grep '^cpu '"]], 1,
|
||||||
)
|
)
|
||||||
|
|
||||||
return cpu_widget
|
return cpu_widget
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
return setmetatable(widget, { __call = function(_, ...)
|
||||||
|
return worker(...)
|
||||||
|
end })
|
||||||
|
|
After Width: | Height: | Size: 4.8 KiB |
After Width: | Height: | Size: 1.9 KiB |
|
@ -2,8 +2,14 @@ local awful = require("awful")
|
||||||
local watch = require("awful.widget.watch")
|
local watch = require("awful.widget.watch")
|
||||||
local wibox = require("wibox")
|
local wibox = require("wibox")
|
||||||
|
|
||||||
|
local ramgraph_widget = {}
|
||||||
|
|
||||||
|
local function worker(args)
|
||||||
|
|
||||||
|
local args = args or {}
|
||||||
|
|
||||||
--- Main ram widget shown on wibar
|
--- Main ram widget shown on wibar
|
||||||
local ramgraph_widget = wibox.widget {
|
ramgraph_widget = wibox.widget {
|
||||||
border_width = 0,
|
border_width = 0,
|
||||||
colors = {
|
colors = {
|
||||||
'#74aeab', '#26403f'
|
'#74aeab', '#26403f'
|
||||||
|
@ -42,7 +48,7 @@ local function getPercentage(value)
|
||||||
return math.floor(value / (total+total_swap) * 100 + 0.5) .. '%'
|
return math.floor(value / (total+total_swap) * 100 + 0.5) .. '%'
|
||||||
end
|
end
|
||||||
|
|
||||||
watch('bash -c "free | grep -z Mem.*Swap.*"', 1,
|
watch('bash -c "LANGUAGE=en_US.UTF-8 free | grep -z Mem.*Swap.*"', 1,
|
||||||
function(widget, stdout, stderr, exitreason, exitcode)
|
function(widget, stdout, stderr, exitreason, exitcode)
|
||||||
total, used, free, shared, buff_cache, available, total_swap, used_swap, free_swap =
|
total, used, free, shared, buff_cache, available, total_swap, used_swap, free_swap =
|
||||||
stdout:match('(%d+)%s*(%d+)%s*(%d+)%s*(%d+)%s*(%d+)%s*(%d+)%s*Swap:%s*(%d+)%s*(%d+)%s*(%d+)')
|
stdout:match('(%d+)%s*(%d+)%s*(%d+)%s*(%d+)%s*(%d+)%s*(%d+)%s*Swap:%s*(%d+)%s*(%d+)%s*(%d+)')
|
||||||
|
@ -75,4 +81,10 @@ ramgraph_widget:buttons(
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
return ramgraph_widget
|
return ramgraph_widget
|
||||||
|
end
|
||||||
|
|
||||||
|
return setmetatable(ramgraph_widget, { __call = function(_, ...)
|
||||||
|
return worker(...)
|
||||||
|
end })
|
||||||
|
|
18
secrets.lua
|
@ -1,18 +0,0 @@
|
||||||
-------------------------------------------------
|
|
||||||
-- Allows to store client specific settings in one place
|
|
||||||
--
|
|
||||||
-- @author Pavel Makhov
|
|
||||||
-- @copyright 2019 Pavel Makhov
|
|
||||||
--------------------------------------------
|
|
||||||
|
|
||||||
local secrets = {
|
|
||||||
-- Yandex.Translate API key - https://tech.yandex.com/translate/
|
|
||||||
translate_widget_api_key = os.getenv('AWW_TRANSLATE_API_KEY') or 'API_KEY',
|
|
||||||
|
|
||||||
-- OpenWeatherMap API key - https://openweathermap.org/appid
|
|
||||||
weather_widget_api_key = os.getenv('AWW_WEATHER_API_KEY') or 'API_KEY',
|
|
||||||
weather_widget_city = os.getenv('AWW_WEATHER_CITY') or 'Montreal,ca',
|
|
||||||
weather_widget_units = os.getenv('AWW_WEATHER_UNITS') or 'metric' -- for celsius, or 'imperial' for fahrenheit
|
|
||||||
}
|
|
||||||
|
|
||||||
return secrets
|
|
|
@ -1,9 +1,9 @@
|
||||||
# Spotify widget
|
# Spotify widget
|
||||||
|
|
||||||
This widget displays currently playing song on [Spotify for Linux](https://www.spotify.com/download/linux/) client: ![screenshot](./spo-wid-1.png) and consists of two parts:
|
This widget displays currently playing song on [Spotify for Linux](https://www.spotify.com/download/linux/) client: ![screenshot](./spo-wid-default.png) and consists of two parts:
|
||||||
|
|
||||||
- status icon which shows if music is currently playing
|
- status icon which shows if music is currently playing
|
||||||
- artist and name of the current song playing
|
- artist and name of the current song
|
||||||
|
|
||||||
## Controls
|
## Controls
|
||||||
|
|
||||||
|
@ -15,11 +15,42 @@ This widget displays currently playing song on [Spotify for Linux](https://www.s
|
||||||
|
|
||||||
Note that widget uses the Arc icon theme, so it should be [installed](https://github.com/horst3180/arc-icon-theme#installation) first under **/usr/share/icons/Arc/** folder.
|
Note that widget uses the Arc icon theme, so it should be [installed](https://github.com/horst3180/arc-icon-theme#installation) first under **/usr/share/icons/Arc/** folder.
|
||||||
|
|
||||||
|
## Customization
|
||||||
|
|
||||||
|
It is possible to customize widget by providing a table with all or some of the following config parameters:
|
||||||
|
|
||||||
|
| Name | Default | Description |
|
||||||
|
|---|---|---|
|
||||||
|
| `play_icon` | `/usr/share/icons/Arc/actions/24/player_play.png` | Play icon |
|
||||||
|
| `pause_icon` | `/usr/share/icons/Arc/actions/24/player_pause.png` | Pause icon |
|
||||||
|
| `font` | `Play 9`| Font |
|
||||||
|
|
||||||
|
### Example:
|
||||||
|
|
||||||
|
```lua
|
||||||
|
spotify_widget({
|
||||||
|
font = 'Ubuntu Mono 9',
|
||||||
|
play_icon = '/usr/share/icons/Papirus-Light/24x24/categories/spotify.svg',
|
||||||
|
pause_icon = '/usr/share/icons/Papirus-Dark/24x24/panel/spotify-indicator.svg'
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
|
Gives following widget:
|
||||||
|
|
||||||
|
![screenshot](./spo-wid-custom.png)
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
First you need to have spotify CLI installed. Here is how you can do it (except widget part): [pavelmakhov.com/2016/02/awesome-wm-spotify](http://pavelmakhov.com/2016/02/awesome-wm-spotify)
|
First you need to have spotify CLI installed, it uses dbus to communicate with spotify-client:
|
||||||
|
|
||||||
To use this widget clone repo under **~/.config/awesome/** and then add it in **rc.lua**:
|
```bash
|
||||||
|
git clone https://gist.github.com/fa6258f3ff7b17747ee3.git
|
||||||
|
cd ./fa6258f3ff7b17747ee3
|
||||||
|
chmod +x sp
|
||||||
|
sudo cp ./sp /usr/local/bin/
|
||||||
|
```
|
||||||
|
|
||||||
|
Then clone repo under **~/.config/awesome/** and add widget in **rc.lua**:
|
||||||
|
|
||||||
```lua
|
```lua
|
||||||
local spotify_widget = require("awesome-wm-widgets.spotify-widget.spotify")
|
local spotify_widget = require("awesome-wm-widgets.spotify-widget.spotify")
|
||||||
|
@ -28,6 +59,13 @@ s.mytasklist, -- Middle widget
|
||||||
{ -- Right widgets
|
{ -- Right widgets
|
||||||
layout = wibox.layout.fixed.horizontal,
|
layout = wibox.layout.fixed.horizontal,
|
||||||
...
|
...
|
||||||
spotify_widget,
|
-- default
|
||||||
|
spotify_widget(),
|
||||||
|
-- customized
|
||||||
|
spotify_widget({
|
||||||
|
font = 'Ubuntu Mono 9',
|
||||||
|
play_icon = '/usr/share/icons/Papirus-Light/24x24/categories/spotify.svg',
|
||||||
|
pause_icon = '/usr/share/icons/Papirus-Dark/24x24/panel/spotify-indicator.svg'
|
||||||
|
}),
|
||||||
...
|
...
|
||||||
```
|
```
|
||||||
|
|
After Width: | Height: | Size: 4.5 KiB |
After Width: | Height: | Size: 3.7 KiB |
|
@ -14,9 +14,18 @@ local watch = require("awful.widget.watch")
|
||||||
|
|
||||||
local GET_SPOTIFY_STATUS_CMD = 'sp status'
|
local GET_SPOTIFY_STATUS_CMD = 'sp status'
|
||||||
local GET_CURRENT_SONG_CMD = 'sp current-oneline'
|
local GET_CURRENT_SONG_CMD = 'sp current-oneline'
|
||||||
local PATH_TO_ICONS = "/usr/share/icons/Arc"
|
|
||||||
|
|
||||||
local spotify_widget = wibox.widget {
|
local spotify_widget = {}
|
||||||
|
|
||||||
|
local function worker(args)
|
||||||
|
|
||||||
|
local args = args or {}
|
||||||
|
|
||||||
|
local play_icon = args.play_icon or '/usr/share/icons/Arc/actions/24/player_play.png'
|
||||||
|
local pause_icon = args.pause_icon or '/usr/share/icons/Arc/actions/24/player_pause.png'
|
||||||
|
local font = args.font or 'Play 9'
|
||||||
|
|
||||||
|
spotify_widget = wibox.widget {
|
||||||
{
|
{
|
||||||
id = "icon",
|
id = "icon",
|
||||||
widget = wibox.widget.imagebox,
|
widget = wibox.widget.imagebox,
|
||||||
|
@ -24,13 +33,11 @@ local spotify_widget = wibox.widget {
|
||||||
{
|
{
|
||||||
id = 'current_song',
|
id = 'current_song',
|
||||||
widget = wibox.widget.textbox,
|
widget = wibox.widget.textbox,
|
||||||
font = 'Play 9'
|
font = font
|
||||||
},
|
},
|
||||||
layout = wibox.layout.align.horizontal,
|
layout = wibox.layout.align.horizontal,
|
||||||
set_status = function(self, is_playing)
|
set_status = function(self, is_playing)
|
||||||
self.icon.image = PATH_TO_ICONS ..
|
self.icon.image = (is_playing and play_icon or pause_icon)
|
||||||
(is_playing and "/actions/24/player_play.png"
|
|
||||||
or "/actions/24/player_pause.png")
|
|
||||||
end,
|
end,
|
||||||
set_text = function(self, path)
|
set_text = function(self, path)
|
||||||
self.current_song.markup = path
|
self.current_song.markup = path
|
||||||
|
@ -60,9 +67,12 @@ watch(GET_CURRENT_SONG_CMD, 1, update_widget_text, spotify_widget)
|
||||||
-- - scroll up - play next song
|
-- - scroll up - play next song
|
||||||
-- - scroll down - play previous song
|
-- - scroll down - play previous song
|
||||||
spotify_widget:connect_signal("button::press", function(_, _, _, button)
|
spotify_widget:connect_signal("button::press", function(_, _, _, button)
|
||||||
if (button == 1) then awful.spawn("sp play", false) -- left click
|
if (button == 1) then
|
||||||
elseif (button == 4) then awful.spawn("sp next", false) -- scroll up
|
awful.spawn("sp play", false) -- left click
|
||||||
elseif (button == 5) then awful.spawn("sp prev", false) -- scroll down
|
elseif (button == 4) then
|
||||||
|
awful.spawn("sp next", false) -- scroll up
|
||||||
|
elseif (button == 5) then
|
||||||
|
awful.spawn("sp prev", false) -- scroll down
|
||||||
end
|
end
|
||||||
awful.spawn.easy_async(GET_SPOTIFY_STATUS_CMD, function(stdout, stderr, exitreason, exitcode)
|
awful.spawn.easy_async(GET_SPOTIFY_STATUS_CMD, function(stdout, stderr, exitreason, exitcode)
|
||||||
update_widget_icon(spotify_widget, stdout, stderr, exitreason, exitcode)
|
update_widget_icon(spotify_widget, stdout, stderr, exitreason, exitcode)
|
||||||
|
@ -70,3 +80,9 @@ spotify_widget:connect_signal("button::press", function(_, _, _, button)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
return spotify_widget
|
return spotify_widget
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
return setmetatable(spotify_widget, { __call = function(_, ...)
|
||||||
|
return worker(...)
|
||||||
|
end })
|
|
@ -1,10 +1,18 @@
|
||||||
# Volume widget
|
# Volume widget
|
||||||
|
|
||||||
Simple and easy-to-install widget for Awesome Window Manager which represents the sound level: ![Volume Widget](
|
Simple and easy-to-install widget for Awesome Window Manager which shows the sound level: ![Volume Widget](
|
||||||
./vol-widget-1.png)
|
./vol-widget-1.png)
|
||||||
|
|
||||||
Note that widget uses the Arc icon theme, so it should be [installed](https://github.com/horst3180/arc-icon-theme#installation) first under **/usr/share/icons/Arc/** folder.
|
Note that widget uses the Arc icon theme, so it should be [installed](https://github.com/horst3180/arc-icon-theme#installation) first under **/usr/share/icons/Arc/** folder.
|
||||||
|
|
||||||
|
## Customization
|
||||||
|
|
||||||
|
It is possible to customize widget by providing a table with all or some of the following config parameters:
|
||||||
|
|
||||||
|
| Name | Default | Description |
|
||||||
|
|---|---|---|
|
||||||
|
| `volume_audio_controller` | `pulse` | audio device |
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
- clone/copy **volume.lua** file;
|
- clone/copy **volume.lua** file;
|
||||||
|
@ -18,7 +26,7 @@ s.mytasklist, -- Middle widget
|
||||||
{ -- Right widgets
|
{ -- Right widgets
|
||||||
layout = wibox.layout.fixed.horizontal,
|
layout = wibox.layout.fixed.horizontal,
|
||||||
...
|
...
|
||||||
volume_widget,
|
volume_widget(),
|
||||||
...
|
...
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -31,6 +39,43 @@ s.mytasklist, -- Middle widget
|
||||||
sudo sed -i 's/bebebe/ed4737/g' ./audio-volume-muted-symbolic_red.svg
|
sudo sed -i 's/bebebe/ed4737/g' ./audio-volume-muted-symbolic_red.svg
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Pulse or ALSA only
|
||||||
|
|
||||||
|
Try running this command:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
amixer -D pulse sget Master
|
||||||
|
```
|
||||||
|
|
||||||
|
If that prints something like this, then the default setting of 'pulse' is probably fine:
|
||||||
|
|
||||||
|
```
|
||||||
|
Simple mixer control 'Master',0
|
||||||
|
Capabilities: pvolume pvolume-joined pswitch pswitch-joined
|
||||||
|
Playback channels: Mono
|
||||||
|
Limits: Playback 0 - 64
|
||||||
|
Mono: Playback 64 [100%] [0.00dB] [on]
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
If it prints something like this:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ amixer -D pulse sget Master
|
||||||
|
ALSA lib pulse.c:243:(pulse_connect) PulseAudio: Unable to connect: Connection refused
|
||||||
|
|
||||||
|
amixer: Mixer attach pulse error: Connection refused
|
||||||
|
```
|
||||||
|
then set `volume_audio_controller` to `alsa_only` in widget constructor:
|
||||||
|
|
||||||
|
```lua
|
||||||
|
volume_widget({
|
||||||
|
volume_audio_controller = 'alsa_only'
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
|
.
|
||||||
|
|
||||||
## Control volume
|
## Control volume
|
||||||
|
|
||||||
To mute/unmute click on the widget. To increase/decrease volume scroll up or down when mouse cursor is over the widget.
|
To mute/unmute click on the widget. To increase/decrease volume scroll up or down when mouse cursor is over the widget.
|
||||||
|
|
|
@ -15,12 +15,26 @@ local spawn = require("awful.spawn")
|
||||||
|
|
||||||
local path_to_icons = "/usr/share/icons/Arc/status/symbolic/"
|
local path_to_icons = "/usr/share/icons/Arc/status/symbolic/"
|
||||||
|
|
||||||
local GET_VOLUME_CMD = 'amixer -D pulse sget Master'
|
local volume_widget = {}
|
||||||
local INC_VOLUME_CMD = 'amixer -D pulse sset Master 5%+'
|
|
||||||
local DEC_VOLUME_CMD = 'amixer -D pulse sset Master 5%-'
|
|
||||||
local TOG_VOLUME_CMD = 'amixer -D pulse sset Master toggle'
|
|
||||||
|
|
||||||
local volume_widget = wibox.widget {
|
local function worker(args)
|
||||||
|
|
||||||
|
local args = args or {}
|
||||||
|
|
||||||
|
local volume_audio_controller = args.volume_audio_controller or 'pulse'
|
||||||
|
|
||||||
|
local device_arg = ''
|
||||||
|
if volume_audio_controller == 'pulse' then
|
||||||
|
device_arg = '-D pulse'
|
||||||
|
end
|
||||||
|
|
||||||
|
local GET_VOLUME_CMD = 'amixer ' .. device_arg .. ' sget Master'
|
||||||
|
local INC_VOLUME_CMD = 'amixer ' .. device_arg .. ' sset Master 5%+'
|
||||||
|
local DEC_VOLUME_CMD = 'amixer ' .. device_arg .. ' sset Master 5%-'
|
||||||
|
local TOG_VOLUME_CMD = 'amixer ' .. device_arg .. ' sset Master toggle'
|
||||||
|
|
||||||
|
|
||||||
|
volume_widget = wibox.widget {
|
||||||
{
|
{
|
||||||
id = "icon",
|
id = "icon",
|
||||||
image = path_to_icons .. "audio-volume-muted-symbolic.svg",
|
image = path_to_icons .. "audio-volume-muted-symbolic.svg",
|
||||||
|
@ -65,3 +79,6 @@ end)
|
||||||
watch(GET_VOLUME_CMD, 1, update_graphic, volume_widget)
|
watch(GET_VOLUME_CMD, 1, update_graphic, volume_widget)
|
||||||
|
|
||||||
return volume_widget
|
return volume_widget
|
||||||
|
end
|
||||||
|
|
||||||
|
return setmetatable(volume_widget, { __call = function(_, ...) return worker(...) end })
|
||||||
|
|
|
@ -1,17 +1,54 @@
|
||||||
# Volumearc widget
|
# Volumearc widget
|
||||||
|
|
||||||
Almost the same as [volumebar widget](https://github.com/streetturtle/awesome-wm-widgets/tree/master/volumebar-widget), but using arcchart:
|
Almost the same as [volumebar widget](https://github.com/streetturtle/awesome-wm-widgets/tree/master/volumebar-widget), but using [arcchart](https://awesomewm.org/doc/api/classes/wibox.container.arcchart.html):
|
||||||
|
|
||||||
![screenshot](out.gif)
|
![screenshot](out.gif)
|
||||||
|
|
||||||
Supports:
|
Supports
|
||||||
- scroll up - increase volume,
|
- scroll up - increase volume,
|
||||||
- scroll down - decrease volume,
|
- scroll down - decrease volume,
|
||||||
- left click - mute/unmute.
|
- left click - mute/unmute.
|
||||||
|
|
||||||
|
## Customization
|
||||||
|
|
||||||
|
It is possible to customize widget by providing a table with all or some of the following config parameters:
|
||||||
|
|
||||||
|
| Name | Default | Description |
|
||||||
|
|---|---|---|
|
||||||
|
| `main_color` | `beautiful.fg_normal` | Color of the arc |
|
||||||
|
| `mute_color` | `beautiful.fg_urgent` | Color of the arc when mute |
|
||||||
|
| `path_to_icon` | /usr/share/icons/Arc/status/symbolic/audio-volume-muted-symbolic.svg | Path to the icon |
|
||||||
|
| `thickness` | 2 | The arc thickness |
|
||||||
|
| `height` | `beautiful.fg_normal` | Widget height |
|
||||||
|
| `get_volume_cmd` | `amixer -D pulse sget Master` | Get current volume level |
|
||||||
|
| `inc_volume_cmd` | `amixer -D pulse sset Master 5%+` | Increase volume level |
|
||||||
|
| `dec_volume_cmd` | `amixer -D pulse sset Master 5%-` | Descrease volume level |
|
||||||
|
| `tog_volume_cmd` | `amixer -D pulse sset Master toggle` | Mute / unmute |
|
||||||
|
|
||||||
|
### Example:
|
||||||
|
|
||||||
|
```lua
|
||||||
|
volumearc_widget({
|
||||||
|
main_color = '#af13f7',
|
||||||
|
mute_color = '#ff0000',
|
||||||
|
thickness = 5,
|
||||||
|
height = 25
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
|
The config above results in the following widget:
|
||||||
|
|
||||||
|
![custom](./custom.png)
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
Clone repo, include widget and use it in **rc.lua**:
|
1. Clone this repo under **~/.config/awesome/**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
git clone https://github.com/streetturtle/awesome-wm-widgets.git ~/.config/awesome/
|
||||||
|
```
|
||||||
|
|
||||||
|
1. Require volumearc widget at the beginning of **rc.lua**:
|
||||||
|
|
||||||
```lua
|
```lua
|
||||||
require("volumearc")
|
require("volumearc")
|
||||||
|
|
After Width: | Height: | Size: 9.2 KiB |
|
@ -21,9 +21,26 @@ local TOG_VOLUME_CMD = 'amixer -D pulse sset Master toggle'
|
||||||
|
|
||||||
local PATH_TO_ICON = "/usr/share/icons/Arc/status/symbolic/audio-volume-muted-symbolic.svg"
|
local PATH_TO_ICON = "/usr/share/icons/Arc/status/symbolic/audio-volume-muted-symbolic.svg"
|
||||||
|
|
||||||
|
local widget = {}
|
||||||
|
|
||||||
|
local function worker(args)
|
||||||
|
|
||||||
|
local args = args or {}
|
||||||
|
|
||||||
|
local main_color = args.main_color or beautiful.fg_color
|
||||||
|
local mute_color = args.mute_color or beautiful.fg_urgent
|
||||||
|
local path_to_icon = args.path_to_icon or PATH_TO_ICON
|
||||||
|
local thickness = args.thickness or 2
|
||||||
|
local height = args.height or 18
|
||||||
|
|
||||||
|
local get_volume_cmd = args.get_volume_cmd or GET_VOLUME_CMD
|
||||||
|
local inc_volume_cmd = args.inc_volume_cmd or INC_VOLUME_CMD
|
||||||
|
local dec_volume_cmd = args.dec_volume_cmd or DEC_VOLUME_CMD
|
||||||
|
local tog_volume_cmd = args.tog_volume_cmd or TOG_VOLUME_CMD
|
||||||
|
|
||||||
local icon = {
|
local icon = {
|
||||||
id = "icon",
|
id = "icon",
|
||||||
image = PATH_TO_ICON,
|
image = path_to_icon,
|
||||||
resize = true,
|
resize = true,
|
||||||
widget = wibox.widget.imagebox,
|
widget = wibox.widget.imagebox,
|
||||||
}
|
}
|
||||||
|
@ -31,37 +48,40 @@ local icon = {
|
||||||
local volumearc = wibox.widget {
|
local volumearc = wibox.widget {
|
||||||
icon,
|
icon,
|
||||||
max_value = 1,
|
max_value = 1,
|
||||||
thickness = 2,
|
thickness = thickness,
|
||||||
start_angle = 4.71238898, -- 2pi*3/4
|
start_angle = 4.71238898, -- 2pi*3/4
|
||||||
forced_height = 18,
|
forced_height = height,
|
||||||
forced_width = 18,
|
forced_width = height,
|
||||||
bg = "#ffffff11",
|
bg = "#ffffff11",
|
||||||
paddings = 2,
|
paddings = 2,
|
||||||
widget = wibox.container.arcchart
|
widget = wibox.container.arcchart
|
||||||
}
|
}
|
||||||
|
|
||||||
local update_graphic = function(widget, stdout, _, _, _)
|
local update_graphic = function(widget, stdout, _, _, _)
|
||||||
local mute = string.match(stdout, "%[(o%D%D?)%]")
|
local mute = string.match(stdout, "%[(o%D%D?)%]") -- \[(o\D\D?)\] - [on] or [off]
|
||||||
local volume = string.match(stdout, "(%d?%d?%d)%%")
|
local volume = string.match(stdout, "(%d?%d?%d)%%") -- (\d?\d?\d)\%)
|
||||||
volume = tonumber(string.format("% 3d", volume))
|
volume = tonumber(string.format("% 3d", volume))
|
||||||
|
|
||||||
widget.value = volume / 100;
|
widget.value = volume / 100;
|
||||||
widget.colors = mute == 'off' and { beautiful.widget_red }
|
widget.colors = mute == 'off'
|
||||||
or { beautiful.widget_main_color }
|
and { mute_color }
|
||||||
|
or { main_color }
|
||||||
end
|
end
|
||||||
|
|
||||||
volumearc:connect_signal("button::press", function(_, _, _, button)
|
volumearc:connect_signal("button::press", function(_, _, _, button)
|
||||||
if (button == 4) then awful.spawn(INC_VOLUME_CMD, false)
|
if (button == 4) then awful.spawn(inc_volume_cmd, false)
|
||||||
elseif (button == 5) then awful.spawn(DEC_VOLUME_CMD, false)
|
elseif (button == 5) then awful.spawn(dec_volume_cmd, false)
|
||||||
elseif (button == 1) then awful.spawn(TOG_VOLUME_CMD, false)
|
elseif (button == 1) then awful.spawn(tog_volume_cmd, false)
|
||||||
end
|
end
|
||||||
|
|
||||||
spawn.easy_async(GET_VOLUME_CMD, function(stdout, stderr, exitreason, exitcode)
|
spawn.easy_async(get_volume_cmd, function(stdout, stderr, exitreason, exitcode)
|
||||||
update_graphic(volumearc, stdout, stderr, exitreason, exitcode)
|
update_graphic(volumearc, stdout, stderr, exitreason, exitcode)
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
watch(GET_VOLUME_CMD, 1, update_graphic, volumearc)
|
watch(get_volume_cmd, 1, update_graphic, volumearc)
|
||||||
|
|
||||||
return volumearc
|
return volumearc
|
||||||
|
end
|
||||||
|
|
||||||
|
return setmetatable(widget, { __call = function(_, ...) return worker(...) end })
|
||||||
|
|
|
@ -9,18 +9,72 @@ Supports
|
||||||
- scroll down - decrease volume,
|
- scroll down - decrease volume,
|
||||||
- left click - mute/unmute.
|
- left click - mute/unmute.
|
||||||
|
|
||||||
|
## Customization
|
||||||
|
|
||||||
|
It is possible to customize widget by providing a table with all or some of the following config parameters:
|
||||||
|
|
||||||
|
| Name | Default | Description |
|
||||||
|
|---|---|---|
|
||||||
|
| `main_color` | `beautiful.fg_normal` | Color of the bar |
|
||||||
|
| `mute_color` | `beautiful.fg_urgent` | Color of the bar when mute |
|
||||||
|
| `width` | 50 | The bar width |
|
||||||
|
| `shape` | `bar` | [gears.shape](https://awesomewm.org/doc/api/libraries/gears.shape.html), could be `octogon`, `hexagon`, `powerline`, etc |
|
||||||
|
| `margin` | `10` | Top and bottom margin (if your wibar is 22 px high, bar will be 2 px (22 - 2*10)) |
|
||||||
|
| `get_volume_cmd` | `amixer -D pulse sget Master` | Get current volume level |
|
||||||
|
| `inc_volume_cmd` | `amixer -D pulse sset Master 5%+` | Increase volume level |
|
||||||
|
| `dec_volume_cmd` | `amixer -D pulse sset Master 5%-` | Descrease volume level |
|
||||||
|
| `tog_volume_cmd` | `amixer -D pulse sset Master toggle` | Mute / unmute |
|
||||||
|
|
||||||
|
### Example:
|
||||||
|
|
||||||
|
```lua
|
||||||
|
volumebar_widget({
|
||||||
|
main_color = '#af13f7',
|
||||||
|
mute_color = '#ff0000',
|
||||||
|
width = 80,
|
||||||
|
shape = 'rounded_bar',
|
||||||
|
margins = 8
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
|
Above config results in following widget:
|
||||||
|
|
||||||
|
![custom](./custom.png)
|
||||||
|
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
Clone repo, include widget and use it in **rc.lua**:
|
1. Clone this repo under **~/.config/awesome/**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
git clone https://github.com/streetturtle/awesome-wm-widgets.git ~/.config/awesome/
|
||||||
|
```
|
||||||
|
|
||||||
|
1. Require volumebar widget at the beginning of **rc.lua**:
|
||||||
|
|
||||||
```lua
|
```lua
|
||||||
local volumebar_widget = require("awesome-wm-widgets.volumebar-widget.volumebar")
|
local volumebar_widget = require("awesome-wm-widgets.volumebar-widget.volumebar")
|
||||||
...
|
```
|
||||||
|
|
||||||
|
1. Add widget to the tasklist:
|
||||||
|
|
||||||
|
```lua
|
||||||
s.mytasklist, -- Middle widget
|
s.mytasklist, -- Middle widget
|
||||||
{ -- Right widgets
|
{ -- Right widgets
|
||||||
layout = wibox.layout.fixed.horizontal,
|
layout = wibox.layout.fixed.horizontal,
|
||||||
...
|
...
|
||||||
volumebar_widget,
|
--[[default]]
|
||||||
|
volumebar_widget(),
|
||||||
|
--[[or customized]]
|
||||||
|
volumebar_widget({
|
||||||
|
main_color = '#af13f7',
|
||||||
|
mute_color = '#ff0000',
|
||||||
|
width = 80,
|
||||||
|
shape = 'rounded_bar', -- octogon, hexagon, powerline, etc
|
||||||
|
-- bar's height = wibar's height minus 2x margins
|
||||||
|
margins = 8
|
||||||
|
}),
|
||||||
|
|
||||||
...
|
...
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
After Width: | Height: | Size: 8.9 KiB |
|
@ -9,6 +9,7 @@
|
||||||
-------------------------------------------------
|
-------------------------------------------------
|
||||||
|
|
||||||
local awful = require("awful")
|
local awful = require("awful")
|
||||||
|
local beautiful = require("beautiful")
|
||||||
local gears = require("gears")
|
local gears = require("gears")
|
||||||
local spawn = require("awful.spawn")
|
local spawn = require("awful.spawn")
|
||||||
local watch = require("awful.widget.watch")
|
local watch = require("awful.widget.watch")
|
||||||
|
@ -19,48 +20,66 @@ local INC_VOLUME_CMD = 'amixer -D pulse sset Master 5%+'
|
||||||
local DEC_VOLUME_CMD = 'amixer -D pulse sset Master 5%-'
|
local DEC_VOLUME_CMD = 'amixer -D pulse sset Master 5%-'
|
||||||
local TOG_VOLUME_CMD = 'amixer -D pulse sset Master toggle'
|
local TOG_VOLUME_CMD = 'amixer -D pulse sset Master toggle'
|
||||||
|
|
||||||
local bar_color = "#74aeab"
|
local widget = {}
|
||||||
local mute_color = "#ff0000"
|
|
||||||
local background_color = "#3a3a3a"
|
local function worker(args)
|
||||||
|
|
||||||
|
local args = args or {}
|
||||||
|
|
||||||
|
local main_color = args.main_color or beautiful.fg_normal
|
||||||
|
local mute_color = args.mute_color or beautiful.fg_urgent
|
||||||
|
local width = args.width or 50
|
||||||
|
local shape = args.shape or 'bar'
|
||||||
|
local margins = args.margins or 10
|
||||||
|
|
||||||
|
local get_volume_cmd = args.get_volume_cmd or GET_VOLUME_CMD
|
||||||
|
local inc_volume_cmd = args.inc_volume_cmd or INC_VOLUME_CMD
|
||||||
|
local dec_volume_cmd = args.dec_volume_cmd or DEC_VOLUME_CMD
|
||||||
|
local tog_volume_cmd = args.tog_volume_cmd or TOG_VOLUME_CMD
|
||||||
|
|
||||||
local volumebar_widget = wibox.widget {
|
local volumebar_widget = wibox.widget {
|
||||||
max_value = 1,
|
max_value = 1,
|
||||||
forced_width = 50,
|
forced_width = width,
|
||||||
paddings = 0,
|
color = main_color,
|
||||||
border_width = 0.5,
|
background_color = '#ffffff11',
|
||||||
color = bar_color,
|
shape = gears.shape[shape],
|
||||||
background_color = background_color,
|
|
||||||
shape = gears.shape.bar,
|
|
||||||
clip = true,
|
|
||||||
margins = {
|
margins = {
|
||||||
top = 10,
|
top = margins,
|
||||||
bottom = 10,
|
bottom = margins,
|
||||||
},
|
},
|
||||||
widget = wibox.widget.progressbar
|
widget = wibox.widget.progressbar
|
||||||
}
|
}
|
||||||
|
|
||||||
local update_graphic = function(widget, stdout, _, _, _)
|
local update_graphic = function(widget, stdout, _, _, _)
|
||||||
local mute = string.match(stdout, "%[(o%D%D?)%]")
|
local mute = string.match(stdout, "%[(o%D%D?)%]") -- \[(o\D\D?)\] - [on] or [off]
|
||||||
local volume = string.match(stdout, "(%d?%d?%d)%%")
|
local volume = string.match(stdout, "(%d?%d?%d)%%") -- (\d?\d?\d)\%)
|
||||||
volume = tonumber(string.format("% 3d", volume))
|
volume = tonumber(string.format("% 3d", volume))
|
||||||
|
|
||||||
widget.value = volume / 100;
|
widget.value = volume / 100;
|
||||||
widget.color = mute == "off" and mute_color
|
widget.color = mute == "off"
|
||||||
or bar_color
|
and mute_color
|
||||||
|
or main_color
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
volumebar_widget:connect_signal("button::press", function(_, _, _, button)
|
volumebar_widget:connect_signal("button::press", function(_, _, _, button)
|
||||||
if (button == 4) then awful.spawn(INC_VOLUME_CMD)
|
if (button == 4) then
|
||||||
elseif (button == 5) then awful.spawn(DEC_VOLUME_CMD)
|
awful.spawn(inc_volume_cmd)
|
||||||
elseif (button == 1) then awful.spawn(TOG_VOLUME_CMD)
|
elseif (button == 5) then
|
||||||
|
awful.spawn(dec_volume_cmd)
|
||||||
|
elseif (button == 1) then
|
||||||
|
awful.spawn(tog_volume_cmd)
|
||||||
end
|
end
|
||||||
|
|
||||||
spawn.easy_async(GET_VOLUME_CMD, function(stdout, stderr, exitreason, exitcode)
|
spawn.easy_async(get_volume_cmd, function(stdout, stderr, exitreason, exitcode)
|
||||||
update_graphic(volumebar_widget, stdout, stderr, exitreason, exitcode)
|
update_graphic(volumebar_widget, stdout, stderr, exitreason, exitcode)
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
watch(GET_VOLUME_CMD, 1, update_graphic, volumebar_widget)
|
watch(get_volume_cmd, 1, update_graphic, volumebar_widget)
|
||||||
|
|
||||||
return volumebar_widget
|
return volumebar_widget
|
||||||
|
end
|
||||||
|
|
||||||
|
return setmetatable(widget, { __call = function(_, ...) return worker(...) end })
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,30 @@
|
||||||
|
|
||||||
Note that widget uses the Arc icon theme, so it should be [installed](https://github.com/horst3180/arc-icon-theme#installation) first under **/usr/share/icons/Arc/** folder.
|
Note that widget uses the Arc icon theme, so it should be [installed](https://github.com/horst3180/arc-icon-theme#installation) first under **/usr/share/icons/Arc/** folder.
|
||||||
|
|
||||||
|
## Customization
|
||||||
|
|
||||||
|
It is possible to customize widget by providing a table with all or some of the following config parameters:
|
||||||
|
|
||||||
|
| Name | Default | Description |
|
||||||
|
|---|---|---|
|
||||||
|
| `font` | `Play 9` | Font |
|
||||||
|
| `city` | `Montreal,ca` | City name and country code, [more info](https://openweathermap.org/current) |
|
||||||
|
| `api_key` | none| API key, required |
|
||||||
|
| `units` | `metric` | `metric` for celsius, `imperial` for fahrenheit |
|
||||||
|
| `both_units_widget` | `false` | show temperature in both units (15°C (59°F)) or in one (15°C) |
|
||||||
|
| `both_units_popup` | `false` | same as above but for popup |
|
||||||
|
|
||||||
|
### Example:
|
||||||
|
|
||||||
|
```lua
|
||||||
|
weather_widget({
|
||||||
|
api_key = 'your-api-key',
|
||||||
|
units = 'imperial',
|
||||||
|
font = 'Ubuntu Mono 9'
|
||||||
|
}),
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
1. Install lua socket - to make HTTP calls to get the weather information.
|
1. Install lua socket - to make HTTP calls to get the weather information.
|
||||||
|
@ -24,7 +48,7 @@ Note that widget uses the Arc icon theme, so it should be [installed](https://gi
|
||||||
git clone https://github.com/streetturtle/awesome-wm-widgets.git ~/.config/awesome/
|
git clone https://github.com/streetturtle/awesome-wm-widgets.git ~/.config/awesome/
|
||||||
```
|
```
|
||||||
|
|
||||||
1. Get Open Weather Map app id here: [openweathermap.org/appid](https://openweathermap.org/appid) and place it in **~/.config/awesome/awesome-wm-widgets/secrets.lua**, or directly in the widget. Don't forget to set also your city and units - C/F.
|
1. Get Open Weather Map app id here: [openweathermap.org/appid](https://openweathermap.org/appid).
|
||||||
|
|
||||||
1. Require weather widget at the beginning of **rc.lua**:
|
1. Require weather widget at the beginning of **rc.lua**:
|
||||||
|
|
||||||
|
@ -39,7 +63,14 @@ Note that widget uses the Arc icon theme, so it should be [installed](https://gi
|
||||||
{ -- Right widgets
|
{ -- Right widgets
|
||||||
layout = wibox.layout.fixed.horizontal,
|
layout = wibox.layout.fixed.horizontal,
|
||||||
...
|
...
|
||||||
weather_widget,
|
--default
|
||||||
|
weather_widget({api_key = 'your-api-key'}),
|
||||||
|
--customized
|
||||||
|
weather_widget({
|
||||||
|
api_key = 'your-api-key',
|
||||||
|
units = 'imperial',
|
||||||
|
font = 'Ubuntu Mono 9'
|
||||||
|
})
|
||||||
...
|
...
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
@ -14,17 +14,28 @@ local naughty = require("naughty")
|
||||||
local wibox = require("wibox")
|
local wibox = require("wibox")
|
||||||
local gears = require("gears")
|
local gears = require("gears")
|
||||||
|
|
||||||
local secrets = require("awesome-wm-widgets.secrets")
|
local path_to_icons = "/usr/share/icons/Arc/status/symbolic/"
|
||||||
|
|
||||||
|
local weather_widget = {}
|
||||||
|
|
||||||
|
local function worker(args)
|
||||||
|
|
||||||
|
local args = args or {}
|
||||||
|
|
||||||
|
local font = args.font or 'Play 9'
|
||||||
|
local city = args.city or 'Montreal,ca'
|
||||||
|
local api_key = args.api_key or naughty.notify{preset = naughty.config.presets.critical, text = 'OpenweatherMap API key is not set'}
|
||||||
|
local units = args.units or 'metric'
|
||||||
|
local both_units_widget = args.both_units_widget or false
|
||||||
|
local both_units_popup = args.both_units_popup or false
|
||||||
|
|
||||||
local weather_api_url = (
|
local weather_api_url = (
|
||||||
'https://api.openweathermap.org/data/2.5/weather'
|
'https://api.openweathermap.org/data/2.5/weather'
|
||||||
.. '?q=' .. secrets.weather_widget_city
|
.. '?q=' .. city
|
||||||
.. '&appid=' .. secrets.weather_widget_api_key
|
.. '&appid=' .. api_key
|
||||||
.. '&units=' .. secrets.weather_widget_units
|
.. '&units=' .. units
|
||||||
)
|
)
|
||||||
|
|
||||||
local path_to_icons = "/usr/share/icons/Arc/status/symbolic/"
|
|
||||||
|
|
||||||
local icon_widget = wibox.widget {
|
local icon_widget = wibox.widget {
|
||||||
{
|
{
|
||||||
id = "icon",
|
id = "icon",
|
||||||
|
@ -38,11 +49,11 @@ local icon_widget = wibox.widget {
|
||||||
}
|
}
|
||||||
|
|
||||||
local temp_widget = wibox.widget {
|
local temp_widget = wibox.widget {
|
||||||
font = "Play 9",
|
font = font,
|
||||||
widget = wibox.widget.textbox,
|
widget = wibox.widget.textbox,
|
||||||
}
|
}
|
||||||
|
|
||||||
local weather_widget = wibox.widget {
|
weather_widget = wibox.widget {
|
||||||
icon_widget,
|
icon_widget,
|
||||||
temp_widget,
|
temp_widget,
|
||||||
layout = wibox.layout.fixed.horizontal,
|
layout = wibox.layout.fixed.horizontal,
|
||||||
|
@ -98,9 +109,39 @@ local function to_direction(degrees)
|
||||||
return directions[math.floor((degrees % 360) / 22.5) + 1]
|
return directions[math.floor((degrees % 360) / 22.5) + 1]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Convert degrees Celsius to Fahrenheit
|
||||||
|
local function celsius_to_fahrenheit(c)
|
||||||
|
return c*9/5+32
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Convert degrees Fahrenheit to Celsius
|
||||||
|
local function fahrenheit_to_celsius(f)
|
||||||
|
return (f-32)*5/9
|
||||||
|
end
|
||||||
|
|
||||||
local weather_timer = gears.timer({ timeout = 60 })
|
local weather_timer = gears.timer({ timeout = 60 })
|
||||||
local resp
|
local resp
|
||||||
|
|
||||||
|
local function gen_temperature_str(temp, fmt_str, show_other_units)
|
||||||
|
local temp_str = string.format(fmt_str, temp)
|
||||||
|
local s = temp_str .. '°' .. (units == 'metric' and 'C' or 'F')
|
||||||
|
|
||||||
|
if (show_other_units) then
|
||||||
|
local temp_conv, units_conv
|
||||||
|
if (units == 'metric') then
|
||||||
|
temp_conv = celsius_to_fahrenheit(temp)
|
||||||
|
units_conv = 'F'
|
||||||
|
else
|
||||||
|
temp_conv = fahrenheit_to_celsius(temp)
|
||||||
|
units_conv = 'C'
|
||||||
|
end
|
||||||
|
|
||||||
|
local temp_conv_str = string.format(fmt_str, temp_conv)
|
||||||
|
s = s .. ' ' .. '('.. temp_conv_str .. '°' .. units_conv .. ')'
|
||||||
|
end
|
||||||
|
return s
|
||||||
|
end
|
||||||
|
|
||||||
weather_timer:connect_signal("timeout", function ()
|
weather_timer:connect_signal("timeout", function ()
|
||||||
local resp_json = {}
|
local resp_json = {}
|
||||||
local res, status = http.request{
|
local res, status = http.request{
|
||||||
|
@ -132,9 +173,7 @@ weather_timer:connect_signal("timeout", function ()
|
||||||
elseif (resp_json ~= nil and resp_json ~= '') then
|
elseif (resp_json ~= nil and resp_json ~= '') then
|
||||||
resp = json.decode(resp_json)
|
resp = json.decode(resp_json)
|
||||||
icon_widget.image = path_to_icons .. icon_map[resp.weather[1].icon]
|
icon_widget.image = path_to_icons .. icon_map[resp.weather[1].icon]
|
||||||
temp_widget:set_text(string.gsub(resp.main.temp, "%.%d+", "")
|
temp_widget:set_text(gen_temperature_str(resp.main.temp, '%.0f', both_units_widget))
|
||||||
.. '°'
|
|
||||||
.. (secrets.weather_widget_units == 'metric' and 'C' or 'F'))
|
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
weather_timer:start()
|
weather_timer:start()
|
||||||
|
@ -149,13 +188,13 @@ weather_widget:connect_signal("mouse::enter", function()
|
||||||
text =
|
text =
|
||||||
'<big>' .. resp.weather[1].main .. ' (' .. resp.weather[1].description .. ')</big><br>' ..
|
'<big>' .. resp.weather[1].main .. ' (' .. resp.weather[1].description .. ')</big><br>' ..
|
||||||
'<b>Humidity:</b> ' .. resp.main.humidity .. '%<br>' ..
|
'<b>Humidity:</b> ' .. resp.main.humidity .. '%<br>' ..
|
||||||
'<b>Temperature:</b> ' .. resp.main.temp .. '°'
|
'<b>Temperature:</b> ' .. gen_temperature_str(resp.main.temp, '%.1f',
|
||||||
.. (secrets.weather_widget_units == 'metric' and 'C' or 'F') .. '<br>' ..
|
both_units_popup) .. '<br>' ..
|
||||||
'<b>Pressure:</b> ' .. resp.main.pressure .. 'hPa<br>' ..
|
'<b>Pressure:</b> ' .. resp.main.pressure .. 'hPa<br>' ..
|
||||||
'<b>Clouds:</b> ' .. resp.clouds.all .. '%<br>' ..
|
'<b>Clouds:</b> ' .. resp.clouds.all .. '%<br>' ..
|
||||||
'<b>Wind:</b> ' .. resp.wind.speed .. 'm/s (' .. to_direction(resp.wind.deg) .. ')',
|
'<b>Wind:</b> ' .. resp.wind.speed .. 'm/s (' .. to_direction(resp.wind.deg) .. ')',
|
||||||
timeout = 5, hover_timeout = 10,
|
timeout = 5, hover_timeout = 10,
|
||||||
width = 200
|
width = (both_units_popup == true and 210 or 200)
|
||||||
}
|
}
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
@ -164,3 +203,8 @@ weather_widget:connect_signal("mouse::leave", function()
|
||||||
end)
|
end)
|
||||||
|
|
||||||
return weather_widget
|
return weather_widget
|
||||||
|
end
|
||||||
|
|
||||||
|
return setmetatable(weather_widget, { __call = function(_, ...)
|
||||||
|
return worker(...)
|
||||||
|
end })
|
||||||
|
|