Merge branch '74-externalize-config' of github.com:streetturtle/awesome-wm-widgets into 74-externalize-config
This commit is contained in:
commit
3d84ce64bd
|
@ -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,151 +16,185 @@ local watch = require("awful.widget.watch")
|
||||||
|
|
||||||
local HOME = os.getenv("HOME")
|
local HOME = os.getenv("HOME")
|
||||||
|
|
||||||
local text = wibox.widget {
|
local widget = {}
|
||||||
id = "txt",
|
|
||||||
font = "Play 6",
|
|
||||||
align = 'center', -- align the text
|
|
||||||
valign = 'center',
|
|
||||||
widget = wibox.widget.textbox
|
|
||||||
}
|
|
||||||
|
|
||||||
local text_with_background = wibox.container.background(text)
|
local function worker(args)
|
||||||
|
|
||||||
local batteryarc = wibox.widget {
|
local args = args or {}
|
||||||
text_with_background,
|
|
||||||
max_value = 1,
|
|
||||||
rounded_edge = true,
|
|
||||||
thickness = 2,
|
|
||||||
start_angle = 4.71238898, -- 2pi*3/4
|
|
||||||
forced_height = 18,
|
|
||||||
forced_width = 18,
|
|
||||||
bg = "#ffffff11",
|
|
||||||
paddings = 2,
|
|
||||||
widget = wibox.container.arcchart,
|
|
||||||
set_value = function(self, value)
|
|
||||||
self.value = value
|
|
||||||
end,
|
|
||||||
}
|
|
||||||
|
|
||||||
local last_battery_check = os.time()
|
local font = args.font or 'Play 6'
|
||||||
|
local arc_thickness = args.thickness or 2
|
||||||
|
local show_current_level = args.show_current_level or false
|
||||||
|
|
||||||
watch("acpi -i", 10,
|
local main_color = args.main_color or beautiful.fg_color
|
||||||
function(widget, stdout)
|
local low_level_color = args.low_level_color or '#e53935'
|
||||||
local batteryType
|
local medium_level_color = args.medium_level_color or '#c0ca33'
|
||||||
|
local charging_color = args.charging_color or '#43a047'
|
||||||
|
|
||||||
local battery_info = {}
|
local warning_msg_title = args.warning_msg_title or 'Huston, we have a problem'
|
||||||
local capacities = {}
|
local warning_msg_text = args.warning_msg_text or 'Battery is dying'
|
||||||
for s in stdout:gmatch("[^\r\n]+") do
|
local warning_msg_position = args.warning_msg_position or 'bottom_right'
|
||||||
local status, charge_str, time = string.match(s, '.+: (%a+), (%d?%d?%d)%%,?.*')
|
local warning_msg_icon = args.warning_msg_icon or HOME .. '/.config/awesome/awesome-wm-widgets/batteryarc-widget/spaceman.jpg'
|
||||||
if string.match(s, 'rate information') then
|
|
||||||
-- ignore such line
|
|
||||||
elseif status ~= nil then
|
|
||||||
table.insert(battery_info, {status = status, charge = tonumber(charge_str)})
|
|
||||||
else
|
|
||||||
local cap_str = string.match(s, '.+:.+last full capacity (%d+)')
|
|
||||||
table.insert(capacities, tonumber(cap_str))
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
local capacity = 0
|
local text = wibox.widget {
|
||||||
for i, cap in ipairs(capacities) do
|
id = "txt",
|
||||||
capacity = capacity + cap
|
font = font,
|
||||||
end
|
align = 'center', -- align the text
|
||||||
|
valign = 'center',
|
||||||
local charge = 0
|
widget = wibox.widget.textbox
|
||||||
local status
|
|
||||||
for i, batt in ipairs(battery_info) do
|
|
||||||
if batt.charge >= charge then
|
|
||||||
-- use most charged battery status. This is arbitrary, and maybe another metric should be used
|
|
||||||
status = batt.status
|
|
||||||
end
|
|
||||||
|
|
||||||
charge = charge + batt.charge * capacities[i]
|
|
||||||
end
|
|
||||||
|
|
||||||
local charge_percentage
|
|
||||||
if capacity > 5 then
|
|
||||||
charge = charge / capacity
|
|
||||||
charge_percentage = charge / 100
|
|
||||||
else
|
|
||||||
-- when widget.value is < 0.04, the widget shows a full circle (as widget.value=1)
|
|
||||||
charge_percentage = 0.05
|
|
||||||
end
|
|
||||||
|
|
||||||
widget.value = charge / 100
|
|
||||||
|
|
||||||
if status == 'Charging' then
|
|
||||||
text_with_background.bg = beautiful.widget_green
|
|
||||||
text_with_background.fg = beautiful.widget_black
|
|
||||||
else
|
|
||||||
text_with_background.bg = beautiful.widget_transparent
|
|
||||||
text_with_background.fg = beautiful.widget_main_color
|
|
||||||
end
|
|
||||||
|
|
||||||
--- 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
|
|
||||||
and ''
|
|
||||||
or string.format('%d', charge)
|
|
||||||
|
|
||||||
if charge < 15 then
|
|
||||||
batteryarc.colors = { beautiful.widget_red }
|
|
||||||
if status ~= 'Charging' and os.difftime(os.time(), last_battery_check) > 300 then
|
|
||||||
-- if 5 minutes have elapsed since the last warning
|
|
||||||
last_battery_check = os.time()
|
|
||||||
|
|
||||||
show_battery_warning()
|
|
||||||
end
|
|
||||||
elseif charge > 15 and charge < 40 then
|
|
||||||
batteryarc.colors = { beautiful.widget_yellow }
|
|
||||||
else
|
|
||||||
batteryarc.colors = { beautiful.widget_main_color }
|
|
||||||
end
|
|
||||||
end,
|
|
||||||
batteryarc)
|
|
||||||
|
|
||||||
-- Popup with battery info
|
|
||||||
-- One way of creating a pop-up notification - naughty.notify
|
|
||||||
local notification
|
|
||||||
function show_battery_status()
|
|
||||||
awful.spawn.easy_async([[bash -c 'acpi']],
|
|
||||||
function(stdout, _, _, _)
|
|
||||||
naughty.destroy(notification)
|
|
||||||
notification = naughty.notify {
|
|
||||||
text = stdout,
|
|
||||||
title = "Battery status",
|
|
||||||
timeout = 5,
|
|
||||||
hover_timeout = 0.5,
|
|
||||||
width = 200,
|
|
||||||
}
|
|
||||||
end)
|
|
||||||
end
|
|
||||||
|
|
||||||
batteryarc:connect_signal("mouse::enter", function() show_battery_status() end)
|
|
||||||
batteryarc:connect_signal("mouse::leave", function() naughty.destroy(notification) end)
|
|
||||||
|
|
||||||
-- Alternative to naughty.notify - tooltip. You can compare both and choose the preferred one
|
|
||||||
|
|
||||||
--battery_popup = awful.tooltip({objects = {battery_widget}})
|
|
||||||
|
|
||||||
-- To use colors from beautiful theme put
|
|
||||||
-- following lines in rc.lua before require("battery"):
|
|
||||||
-- beautiful.tooltip_fg = beautiful.fg_normal
|
|
||||||
-- beautiful.tooltip_bg = beautiful.bg_normal
|
|
||||||
|
|
||||||
--[[ Show warning notification ]]
|
|
||||||
function show_battery_warning()
|
|
||||||
naughty.notify {
|
|
||||||
icon = HOME .. "/.config/awesome/awesome-wm-widgets/batteryarc-widget/spaceman.jpg",
|
|
||||||
icon_size = 100,
|
|
||||||
text = "Battery is dying", -- switch text and title
|
|
||||||
title = "Huston, we have a problem",
|
|
||||||
timeout = 25, -- show the warning for a longer time
|
|
||||||
hover_timeout = 0.5,
|
|
||||||
position = "bottom_right",
|
|
||||||
bg = "#F06060",
|
|
||||||
fg = "#EEE9EF",
|
|
||||||
width = 300,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
local text_with_background = wibox.container.background(text)
|
||||||
|
|
||||||
|
widget = wibox.widget {
|
||||||
|
text_with_background,
|
||||||
|
max_value = 1,
|
||||||
|
rounded_edge = true,
|
||||||
|
thickness = arc_thickness,
|
||||||
|
start_angle = 4.71238898, -- 2pi*3/4
|
||||||
|
forced_height = 18,
|
||||||
|
forced_width = 18,
|
||||||
|
bg = "#ffffff11",
|
||||||
|
paddings = 2,
|
||||||
|
widget = wibox.container.arcchart,
|
||||||
|
set_value = function(self, value)
|
||||||
|
self.value = value
|
||||||
|
end,
|
||||||
|
}
|
||||||
|
|
||||||
|
local last_battery_check = os.time()
|
||||||
|
|
||||||
|
watch("acpi -i", 10,
|
||||||
|
function(widget, stdout)
|
||||||
|
local batteryType
|
||||||
|
|
||||||
|
local battery_info = {}
|
||||||
|
local capacities = {}
|
||||||
|
for s in stdout:gmatch("[^\r\n]+") do
|
||||||
|
local status, charge_str, time = string.match(s, '.+: (%a+), (%d?%d?%d)%%,?.*')
|
||||||
|
if string.match(s, 'rate information') then
|
||||||
|
-- ignore such line
|
||||||
|
elseif status ~= nil then
|
||||||
|
table.insert(battery_info, { status = status, charge = tonumber(charge_str) })
|
||||||
|
else
|
||||||
|
local cap_str = string.match(s, '.+:.+last full capacity (%d+)')
|
||||||
|
table.insert(capacities, tonumber(cap_str))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local capacity = 0
|
||||||
|
for i, cap in ipairs(capacities) do
|
||||||
|
capacity = capacity + cap
|
||||||
|
end
|
||||||
|
|
||||||
|
local charge = 0
|
||||||
|
local status
|
||||||
|
for i, batt in ipairs(battery_info) do
|
||||||
|
if batt.charge >= charge then
|
||||||
|
-- use most charged battery status. This is arbitrary, and maybe another metric should be used
|
||||||
|
status = batt.status
|
||||||
|
end
|
||||||
|
|
||||||
|
charge = charge + batt.charge * capacities[i]
|
||||||
|
end
|
||||||
|
|
||||||
|
local charge_percentage
|
||||||
|
if capacity > 5 then
|
||||||
|
charge = charge / capacity
|
||||||
|
charge_percentage = charge / 100
|
||||||
|
else
|
||||||
|
-- when widget.value is < 0.04, the widget shows a full circle (as widget.value=1)
|
||||||
|
charge_percentage = 0.05
|
||||||
|
end
|
||||||
|
|
||||||
|
widget.value = charge / 100
|
||||||
|
|
||||||
|
if status == 'Charging' then
|
||||||
|
text_with_background.bg = charging_color
|
||||||
|
text_with_background.fg = '#000000'
|
||||||
|
else
|
||||||
|
text_with_background.bg = '#00000000'
|
||||||
|
text_with_background.fg = main_color
|
||||||
|
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
|
||||||
|
text.text = charge == 100
|
||||||
|
and ''
|
||||||
|
or string.format('%d', charge)
|
||||||
|
else
|
||||||
|
text.text = ''
|
||||||
|
end
|
||||||
|
|
||||||
|
if charge < 15 then
|
||||||
|
widget.colors = { low_level_color }
|
||||||
|
if status ~= 'Charging' and os.difftime(os.time(), last_battery_check) > 300 then
|
||||||
|
-- if 5 minutes have elapsed since the last warning
|
||||||
|
last_battery_check = os.time()
|
||||||
|
|
||||||
|
show_battery_warning()
|
||||||
|
end
|
||||||
|
elseif charge > 15 and charge < 40 then
|
||||||
|
widget.colors = { medium_level_color }
|
||||||
|
else
|
||||||
|
widget.colors = { main_color }
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
widget)
|
||||||
|
|
||||||
|
-- Popup with battery info
|
||||||
|
-- One way of creating a pop-up notification - naughty.notify
|
||||||
|
local notification
|
||||||
|
function show_battery_status()
|
||||||
|
awful.spawn.easy_async([[bash -c 'acpi']],
|
||||||
|
function(stdout, _, _, _)
|
||||||
|
naughty.destroy(notification)
|
||||||
|
notification = naughty.notify {
|
||||||
|
text = stdout,
|
||||||
|
title = "Battery status",
|
||||||
|
timeout = 5,
|
||||||
|
hover_timeout = 0.5,
|
||||||
|
width = 200,
|
||||||
|
}
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
|
widget:connect_signal("mouse::enter", function()
|
||||||
|
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
|
||||||
|
|
||||||
|
--battery_popup = awful.tooltip({objects = {battery_widget}})
|
||||||
|
|
||||||
|
-- To use colors from beautiful theme put
|
||||||
|
-- following lines in rc.lua before require("battery"):
|
||||||
|
-- beautiful.tooltip_fg = beautiful.fg_normal
|
||||||
|
-- beautiful.tooltip_bg = beautiful.bg_normal
|
||||||
|
|
||||||
|
--[[ Show warning notification ]]
|
||||||
|
function show_battery_warning()
|
||||||
|
naughty.notify {
|
||||||
|
icon = warning_msg_icon,
|
||||||
|
icon_size = 100,
|
||||||
|
text = warning_msg_text,
|
||||||
|
title = warning_msg_title,
|
||||||
|
timeout = 25, -- show the warning for a longer time
|
||||||
|
hover_timeout = 0.5,
|
||||||
|
position = warning_msg_position,
|
||||||
|
bg = "#F06060",
|
||||||
|
fg = "#EEE9EF",
|
||||||
|
width = 300,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
return widget
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return batteryarc
|
return setmetatable(widget, { __call = function(_, ...)
|
||||||
|
return worker(...)
|
||||||
|
end })
|
||||||
|
|
Binary file not shown.
After Width: | Height: | Size: 13 KiB |
|
@ -11,6 +11,7 @@ It is possible to customize widget by providing a table with all or some of the
|
||||||
| `get_brightness_cmd` | `light -G` | Get current screen brightness |
|
| `get_brightness_cmd` | `light -G` | Get current screen brightness |
|
||||||
| `inc_brightness_cmd` | `light -A 5` | Increase brightness |
|
| `inc_brightness_cmd` | `light -A 5` | Increase brightness |
|
||||||
| `dec_brightness_cmd` | `light -U 5`| Decrease 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 |
|
| `path_to_icon` | `/usr/share/icons/Arc/status/symbolic/display-brightness-symbolic.svg` | Path to the icon |
|
||||||
|
|
||||||
### Example:
|
### Example:
|
||||||
|
@ -20,6 +21,7 @@ brightnessarc_widget({
|
||||||
get_brightness_cmd = 'xbacklight -get',
|
get_brightness_cmd = 'xbacklight -get',
|
||||||
inc_brightness_cmd = 'xbacklight -inc 5',
|
inc_brightness_cmd = 'xbacklight -inc 5',
|
||||||
dec_brightness_cmd = 'xbacklight -dec 5'
|
dec_brightness_cmd = 'xbacklight -dec 5'
|
||||||
|
color = '/usr/share/icons/Arc/status/symbolic/brightness-display-symbolic.svg'
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -60,7 +62,7 @@ git clone https://github.com/streetturtle/awesome-wm-widgets.git ~/.config/aweso
|
||||||
Require widget at the beginning of **rc.lua**:
|
Require widget at the beginning of **rc.lua**:
|
||||||
|
|
||||||
```lua
|
```lua
|
||||||
local brightness_widget = require("awesome-wm-widgets.brightness-widget.brightness")
|
local brightnessarc_widget = require("awesome-wm-widgets.brightnessarc-widget.brightnessarc")
|
||||||
```
|
```
|
||||||
|
|
||||||
Add widget to the tasklist:
|
Add widget to the tasklist:
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
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"
|
||||||
|
@ -26,6 +27,7 @@ local function worker(args)
|
||||||
local get_brightness_cmd = args.get_brightness_cmd or GET_BRIGHTNESS_CMD
|
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 inc_brightness_cmd = args.inc_brightness_cmd or INC_BRIGHTNESS_CMD
|
||||||
local dec_brightness_cmd = args.dec_brightness_cmd or DEC_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 path_to_icon = args.path_to_icon or PATH_TO_ICON
|
||||||
|
|
||||||
local icon = {
|
local icon = {
|
||||||
|
@ -44,6 +46,7 @@ local function worker(args)
|
||||||
forced_width = 18,
|
forced_width = 18,
|
||||||
bg = "#ffffff11",
|
bg = "#ffffff11",
|
||||||
paddings = 2,
|
paddings = 2,
|
||||||
|
colors = {color},
|
||||||
widget = wibox.container.arcchart
|
widget = wibox.container.arcchart
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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,40 +10,58 @@
|
||||||
|
|
||||||
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 cpugraph_widget = wibox.widget {
|
local widget = {}
|
||||||
max_value = 100,
|
|
||||||
background_color = "#00000000",
|
|
||||||
forced_width = 50,
|
|
||||||
step_width = 2,
|
|
||||||
step_spacing = 1,
|
|
||||||
widget = wibox.widget.graph,
|
|
||||||
color = "linear:0,0:0,22:0,#FF0000:0.3,#FFFF00:0.5,#74aeab"
|
|
||||||
}
|
|
||||||
|
|
||||||
--- By default graph widget goes from left to right, so we mirror it and push up a bit
|
local function worker(args)
|
||||||
local cpu_widget = wibox.container.margin(wibox.container.mirror(cpugraph_widget, { horizontal = true }), 0, 0, 0, 2)
|
|
||||||
|
|
||||||
local total_prev = 0
|
local args = args or {}
|
||||||
local idle_prev = 0
|
|
||||||
|
|
||||||
watch([[bash -c "cat /proc/stat | grep '^cpu '"]], 1,
|
local width = args.width or 50
|
||||||
function(widget, stdout)
|
local step_width = args.step_width or 2
|
||||||
local user, nice, system, idle, iowait, irq, softirq, steal, guest, guest_nice =
|
local step_spacing = args.step_spacing or 1
|
||||||
stdout:match('(%d+)%s(%d+)%s(%d+)%s(%d+)%s(%d+)%s(%d+)%s(%d+)%s(%d+)%s(%d+)%s(%d+)%s')
|
local color= args.color or beautiful.fg_normal
|
||||||
|
|
||||||
local total = user + nice + system + idle + iowait + irq + softirq + steal
|
local cpugraph_widget = wibox.widget {
|
||||||
|
max_value = 100,
|
||||||
|
background_color = "#00000000",
|
||||||
|
forced_width = width,
|
||||||
|
step_width = step_width,
|
||||||
|
step_spacing = step_spacing,
|
||||||
|
widget = wibox.widget.graph,
|
||||||
|
color = "linear:0,0:0,20:0,#FF0000:0.3,#FFFF00:0.6," .. color
|
||||||
|
}
|
||||||
|
|
||||||
local diff_idle = idle - idle_prev
|
--- By default graph widget goes from left to right, so we mirror it and push up a bit
|
||||||
local diff_total = total - total_prev
|
local cpu_widget = wibox.container.margin(wibox.container.mirror(cpugraph_widget, { horizontal = true }), 0, 0, 0, 2)
|
||||||
local diff_usage = (1000 * (diff_total - diff_idle) / diff_total + 5) / 10
|
|
||||||
|
|
||||||
widget:add_value(diff_usage)
|
local total_prev = 0
|
||||||
|
local idle_prev = 0
|
||||||
|
|
||||||
total_prev = total
|
watch([[bash -c "cat /proc/stat | grep '^cpu '"]], 1,
|
||||||
idle_prev = idle
|
function(widget, stdout)
|
||||||
end,
|
local user, nice, system, idle, iowait, irq, softirq, steal, guest, guest_nice =
|
||||||
cpugraph_widget
|
stdout:match('(%d+)%s(%d+)%s(%d+)%s(%d+)%s(%d+)%s(%d+)%s(%d+)%s(%d+)%s(%d+)%s(%d+)%s')
|
||||||
)
|
|
||||||
|
|
||||||
return cpu_widget
|
local total = user + nice + system + idle + iowait + irq + softirq + steal
|
||||||
|
|
||||||
|
local diff_idle = idle - idle_prev
|
||||||
|
local diff_total = total - total_prev
|
||||||
|
local diff_usage = (1000 * (diff_total - diff_idle) / diff_total + 5) / 10
|
||||||
|
|
||||||
|
widget:add_value(diff_usage)
|
||||||
|
|
||||||
|
total_prev = total
|
||||||
|
idle_prev = idle
|
||||||
|
end,
|
||||||
|
cpugraph_widget
|
||||||
|
)
|
||||||
|
|
||||||
|
return cpu_widget
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
return setmetatable(widget, { __call = function(_, ...)
|
||||||
|
return worker(...)
|
||||||
|
end })
|
||||||
|
|
Binary file not shown.
After Width: | Height: | Size: 4.8 KiB |
Binary file not shown.
After Width: | Height: | Size: 1.9 KiB |
|
@ -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'
|
||||||
|
}),
|
||||||
...
|
...
|
||||||
```
|
```
|
||||||
|
|
Binary file not shown.
After Width: | Height: | Size: 4.5 KiB |
Binary file not shown.
After Width: | Height: | Size: 3.7 KiB |
|
@ -14,59 +14,75 @@ 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 = {}
|
||||||
{
|
|
||||||
id = "icon",
|
|
||||||
widget = wibox.widget.imagebox,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id = 'current_song',
|
|
||||||
widget = wibox.widget.textbox,
|
|
||||||
font = 'Play 9'
|
|
||||||
},
|
|
||||||
layout = wibox.layout.align.horizontal,
|
|
||||||
set_status = function(self, is_playing)
|
|
||||||
self.icon.image = PATH_TO_ICONS ..
|
|
||||||
(is_playing and "/actions/24/player_play.png"
|
|
||||||
or "/actions/24/player_pause.png")
|
|
||||||
end,
|
|
||||||
set_text = function(self, path)
|
|
||||||
self.current_song.markup = path
|
|
||||||
end,
|
|
||||||
}
|
|
||||||
|
|
||||||
local update_widget_icon = function(widget, stdout, _, _, _)
|
local function worker(args)
|
||||||
stdout = string.gsub(stdout, "\n", "")
|
|
||||||
widget:set_status(stdout == 'Playing' and true or false)
|
|
||||||
end
|
|
||||||
|
|
||||||
local update_widget_text = function(widget, stdout, _, _, _)
|
local args = args or {}
|
||||||
if string.find(stdout, 'Error: Spotify is not running.') ~= nil then
|
|
||||||
widget:set_text('')
|
local play_icon = args.play_icon or '/usr/share/icons/Arc/actions/24/player_play.png'
|
||||||
widget:set_visible(false)
|
local pause_icon = args.pause_icon or '/usr/share/icons/Arc/actions/24/player_pause.png'
|
||||||
else
|
local font = args.font or 'Play 9'
|
||||||
widget:set_text(stdout)
|
|
||||||
widget:set_visible(true)
|
spotify_widget = wibox.widget {
|
||||||
|
{
|
||||||
|
id = "icon",
|
||||||
|
widget = wibox.widget.imagebox,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id = 'current_song',
|
||||||
|
widget = wibox.widget.textbox,
|
||||||
|
font = font
|
||||||
|
},
|
||||||
|
layout = wibox.layout.align.horizontal,
|
||||||
|
set_status = function(self, is_playing)
|
||||||
|
self.icon.image = (is_playing and play_icon or pause_icon)
|
||||||
|
end,
|
||||||
|
set_text = function(self, path)
|
||||||
|
self.current_song.markup = path
|
||||||
|
end,
|
||||||
|
}
|
||||||
|
|
||||||
|
local update_widget_icon = function(widget, stdout, _, _, _)
|
||||||
|
stdout = string.gsub(stdout, "\n", "")
|
||||||
|
widget:set_status(stdout == 'Playing' and true or false)
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
watch(GET_SPOTIFY_STATUS_CMD, 1, update_widget_icon, spotify_widget)
|
local update_widget_text = function(widget, stdout, _, _, _)
|
||||||
watch(GET_CURRENT_SONG_CMD, 1, update_widget_text, spotify_widget)
|
if string.find(stdout, 'Error: Spotify is not running.') ~= nil then
|
||||||
|
widget:set_text('')
|
||||||
--- Adds mouse controls to the widget:
|
widget:set_visible(false)
|
||||||
-- - left click - play/pause
|
else
|
||||||
-- - scroll up - play next song
|
widget:set_text(stdout)
|
||||||
-- - scroll down - play previous song
|
widget:set_visible(true)
|
||||||
spotify_widget:connect_signal("button::press", function(_, _, _, button)
|
end
|
||||||
if (button == 1) then awful.spawn("sp play", false) -- left click
|
|
||||||
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)
|
|
||||||
update_widget_icon(spotify_widget, stdout, stderr, exitreason, exitcode)
|
watch(GET_SPOTIFY_STATUS_CMD, 1, update_widget_icon, spotify_widget)
|
||||||
|
watch(GET_CURRENT_SONG_CMD, 1, update_widget_text, spotify_widget)
|
||||||
|
|
||||||
|
--- Adds mouse controls to the widget:
|
||||||
|
-- - left click - play/pause
|
||||||
|
-- - scroll up - play next song
|
||||||
|
-- - scroll down - play previous song
|
||||||
|
spotify_widget:connect_signal("button::press", function(_, _, _, button)
|
||||||
|
if (button == 1) then
|
||||||
|
awful.spawn("sp play", false) -- left click
|
||||||
|
elseif (button == 4) then
|
||||||
|
awful.spawn("sp next", false) -- scroll up
|
||||||
|
elseif (button == 5) then
|
||||||
|
awful.spawn("sp prev", false) -- scroll down
|
||||||
|
end
|
||||||
|
awful.spawn.easy_async(GET_SPOTIFY_STATUS_CMD, function(stdout, stderr, exitreason, exitcode)
|
||||||
|
update_widget_icon(spotify_widget, stdout, stderr, exitreason, exitcode)
|
||||||
|
end)
|
||||||
end)
|
end)
|
||||||
end)
|
|
||||||
|
|
||||||
return spotify_widget
|
return spotify_widget
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
return setmetatable(spotify_widget, { __call = function(_, ...)
|
||||||
|
return worker(...)
|
||||||
|
end })
|
|
@ -36,7 +36,7 @@ volumearc_widget({
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
Above config results in following widget:
|
The config above results in the following widget:
|
||||||
|
|
||||||
![custom](./custom.png)
|
![custom](./custom.png)
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,28 @@
|
||||||
|
|
||||||
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 |
|
||||||
|
|
||||||
|
### 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 +46,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 +61,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'
|
||||||
|
})
|
||||||
...
|
...
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
@ -16,126 +16,141 @@ local secrets = require("awesome-wm-widgets.secrets")
|
||||||
|
|
||||||
local path_to_icons = "/usr/share/icons/Arc/status/symbolic/"
|
local path_to_icons = "/usr/share/icons/Arc/status/symbolic/"
|
||||||
|
|
||||||
local icon_widget = wibox.widget {
|
local weather_widget = {}
|
||||||
{
|
|
||||||
id = "icon",
|
|
||||||
resize = false,
|
|
||||||
widget = wibox.widget.imagebox,
|
|
||||||
},
|
|
||||||
layout = wibox.container.margin(_ , 0, 0, 3),
|
|
||||||
set_image = function(self, path)
|
|
||||||
self.icon.image = path
|
|
||||||
end,
|
|
||||||
}
|
|
||||||
|
|
||||||
local temp_widget = wibox.widget{
|
local function worker(args)
|
||||||
font = "Play 9",
|
|
||||||
widget = wibox.widget.textbox,
|
|
||||||
}
|
|
||||||
|
|
||||||
local weather_widget = wibox.widget {
|
local args = args or {}
|
||||||
icon_widget,
|
|
||||||
temp_widget,
|
|
||||||
layout = wibox.layout.fixed.horizontal,
|
|
||||||
}
|
|
||||||
|
|
||||||
--- Maps openWeatherMap icons to Arc icons
|
local font = args.font or 'Play 9'
|
||||||
local icon_map = {
|
local city = args.city or 'Montreal,ca'
|
||||||
["01d"] = "weather-clear-symbolic.svg",
|
local api_key = args.api_key or naughty.notify{preset = naughty.config.presets.critical, text = 'OpenweatherMap API key is not set'}
|
||||||
["02d"] = "weather-few-clouds-symbolic.svg",
|
local units = args.units or 'metric'
|
||||||
["03d"] = "weather-clouds-symbolic.svg",
|
|
||||||
["04d"] = "weather-overcast-symbolic.svg",
|
|
||||||
["09d"] = "weather-showers-scattered-symbolic.svg",
|
|
||||||
["10d"] = "weather-showers-symbolic.svg",
|
|
||||||
["11d"] = "weather-storm-symbolic.svg",
|
|
||||||
["13d"] = "weather-snow-symbolic.svg",
|
|
||||||
["50d"] = "weather-fog-symbolic.svg",
|
|
||||||
["01n"] = "weather-clear-night-symbolic.svg",
|
|
||||||
["02n"] = "weather-few-clouds-night-symbolic.svg",
|
|
||||||
["03n"] = "weather-clouds-night-symbolic.svg",
|
|
||||||
["04n"] = "weather-overcast-symbolic.svg",
|
|
||||||
["09n"] = "weather-showers-scattered-symbolic.svg",
|
|
||||||
["10n"] = "weather-showers-symbolic.svg",
|
|
||||||
["11n"] = "weather-storm-symbolic.svg",
|
|
||||||
["13n"] = "weather-snow-symbolic.svg",
|
|
||||||
["50n"] = "weather-fog-symbolic.svg"
|
|
||||||
}
|
|
||||||
|
|
||||||
--- Return wind direction as a string.
|
local icon_widget = wibox.widget {
|
||||||
local function to_direction(degrees)
|
{
|
||||||
-- Ref: https://www.campbellsci.eu/blog/convert-wind-directions
|
id = "icon",
|
||||||
if degrees == nil then
|
resize = false,
|
||||||
return "Unknown dir"
|
widget = wibox.widget.imagebox,
|
||||||
end
|
},
|
||||||
local directions = {
|
layout = wibox.container.margin(_, 0, 0, 3),
|
||||||
"N",
|
set_image = function(self, path)
|
||||||
"NNE",
|
self.icon.image = path
|
||||||
"NE",
|
end,
|
||||||
"ENE",
|
|
||||||
"E",
|
|
||||||
"ESE",
|
|
||||||
"SE",
|
|
||||||
"SSE",
|
|
||||||
"S",
|
|
||||||
"SSW",
|
|
||||||
"SW",
|
|
||||||
"WSW",
|
|
||||||
"W",
|
|
||||||
"WNW",
|
|
||||||
"NW",
|
|
||||||
"NNW",
|
|
||||||
"N",
|
|
||||||
}
|
}
|
||||||
return directions[math.floor((degrees % 360) / 22.5) + 1]
|
|
||||||
|
local temp_widget = wibox.widget {
|
||||||
|
font = font,
|
||||||
|
widget = wibox.widget.textbox,
|
||||||
|
}
|
||||||
|
|
||||||
|
weather_widget = wibox.widget {
|
||||||
|
icon_widget,
|
||||||
|
temp_widget,
|
||||||
|
layout = wibox.layout.fixed.horizontal,
|
||||||
|
}
|
||||||
|
|
||||||
|
--- Maps openWeatherMap icons to Arc icons
|
||||||
|
local icon_map = {
|
||||||
|
["01d"] = "weather-clear-symbolic.svg",
|
||||||
|
["02d"] = "weather-few-clouds-symbolic.svg",
|
||||||
|
["03d"] = "weather-clouds-symbolic.svg",
|
||||||
|
["04d"] = "weather-overcast-symbolic.svg",
|
||||||
|
["09d"] = "weather-showers-scattered-symbolic.svg",
|
||||||
|
["10d"] = "weather-showers-symbolic.svg",
|
||||||
|
["11d"] = "weather-storm-symbolic.svg",
|
||||||
|
["13d"] = "weather-snow-symbolic.svg",
|
||||||
|
["50d"] = "weather-fog-symbolic.svg",
|
||||||
|
["01n"] = "weather-clear-night-symbolic.svg",
|
||||||
|
["02n"] = "weather-few-clouds-night-symbolic.svg",
|
||||||
|
["03n"] = "weather-clouds-night-symbolic.svg",
|
||||||
|
["04n"] = "weather-overcast-symbolic.svg",
|
||||||
|
["09n"] = "weather-showers-scattered-symbolic.svg",
|
||||||
|
["10n"] = "weather-showers-symbolic.svg",
|
||||||
|
["11n"] = "weather-storm-symbolic.svg",
|
||||||
|
["13n"] = "weather-snow-symbolic.svg",
|
||||||
|
["50n"] = "weather-fog-symbolic.svg"
|
||||||
|
}
|
||||||
|
|
||||||
|
--- Return wind direction as a string.
|
||||||
|
local function to_direction(degrees)
|
||||||
|
-- Ref: https://www.campbellsci.eu/blog/convert-wind-directions
|
||||||
|
if degrees == nil then
|
||||||
|
return "Unknown dir"
|
||||||
|
end
|
||||||
|
local directions = {
|
||||||
|
"N",
|
||||||
|
"NNE",
|
||||||
|
"NE",
|
||||||
|
"ENE",
|
||||||
|
"E",
|
||||||
|
"ESE",
|
||||||
|
"SE",
|
||||||
|
"SSE",
|
||||||
|
"S",
|
||||||
|
"SSW",
|
||||||
|
"SW",
|
||||||
|
"WSW",
|
||||||
|
"W",
|
||||||
|
"WNW",
|
||||||
|
"NW",
|
||||||
|
"NNW",
|
||||||
|
"N",
|
||||||
|
}
|
||||||
|
return directions[math.floor((degrees % 360) / 22.5) + 1]
|
||||||
|
end
|
||||||
|
|
||||||
|
local weather_timer = gears.timer({ timeout = 60 })
|
||||||
|
local resp
|
||||||
|
|
||||||
|
weather_timer:connect_signal("timeout", function()
|
||||||
|
local resp_json, status = http.request('https://api.openweathermap.org/data/2.5/weather?q='
|
||||||
|
.. city
|
||||||
|
.. '&appid=' .. api_key
|
||||||
|
.. '&units=' .. units)
|
||||||
|
if (status ~= 200 and resp_json ~= nil) then
|
||||||
|
local err_resp = json.decode(resp_json)
|
||||||
|
naughty.notify {
|
||||||
|
title = 'Weather Widget Error',
|
||||||
|
text = err_resp.message,
|
||||||
|
preset = naughty.config.presets.critical,
|
||||||
|
}
|
||||||
|
elseif (resp_json ~= nil) then
|
||||||
|
resp = json.decode(resp_json)
|
||||||
|
icon_widget.image = path_to_icons .. icon_map[resp.weather[1].icon]
|
||||||
|
temp_widget:set_text(string.gsub(resp.main.temp, "%.%d+", "")
|
||||||
|
.. '°'
|
||||||
|
.. (units == 'metric' and 'C' or 'F'))
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
weather_timer:start()
|
||||||
|
weather_timer:emit_signal("timeout")
|
||||||
|
|
||||||
|
--- Notification with weather information. Popups when mouse hovers over the icon
|
||||||
|
local notification
|
||||||
|
weather_widget:connect_signal("mouse::enter", function()
|
||||||
|
notification = naughty.notify {
|
||||||
|
icon = path_to_icons .. icon_map[resp.weather[1].icon],
|
||||||
|
icon_size = 20,
|
||||||
|
text = '<big>' .. resp.weather[1].main .. ' (' .. resp.weather[1].description .. ')</big><br>' ..
|
||||||
|
'<b>Humidity:</b> ' .. resp.main.humidity .. '%<br>' ..
|
||||||
|
'<b>Temperature:</b> ' .. resp.main.temp .. '°'
|
||||||
|
.. (secrets.weather_widget_units == 'metric' and 'C' or 'F') .. '<br>' ..
|
||||||
|
'<b>Pressure:</b> ' .. resp.main.pressure .. 'hPa<br>' ..
|
||||||
|
'<b>Clouds:</b> ' .. resp.clouds.all .. '%<br>' ..
|
||||||
|
'<b>Wind:</b> ' .. resp.wind.speed .. 'm/s (' .. to_direction(resp.wind.deg) .. ')',
|
||||||
|
timeout = 5, hover_timeout = 10,
|
||||||
|
width = 200
|
||||||
|
}
|
||||||
|
end)
|
||||||
|
|
||||||
|
weather_widget:connect_signal("mouse::leave", function()
|
||||||
|
naughty.destroy(notification)
|
||||||
|
end)
|
||||||
|
|
||||||
|
return weather_widget
|
||||||
end
|
end
|
||||||
|
|
||||||
local weather_timer = gears.timer({ timeout = 60 })
|
return setmetatable(weather_widget, { __call = function(_, ...)
|
||||||
local resp
|
return worker(...)
|
||||||
|
end })
|
||||||
weather_timer:connect_signal("timeout", function ()
|
|
||||||
local resp_json, status = http.request('https://api.openweathermap.org/data/2.5/weather?q='
|
|
||||||
.. secrets.weather_widget_city
|
|
||||||
.. '&appid=' .. secrets.weather_widget_api_key
|
|
||||||
.. '&units=' .. secrets.weather_widget_units)
|
|
||||||
if (status ~= 200 and resp_json ~= nil) then
|
|
||||||
local err_resp = json.decode(resp_json)
|
|
||||||
naughty.notify{
|
|
||||||
title = 'Weather Widget Error',
|
|
||||||
text = err_resp.message,
|
|
||||||
preset = naughty.config.presets.critical,
|
|
||||||
}
|
|
||||||
elseif (resp_json ~= nil) then
|
|
||||||
resp = json.decode(resp_json)
|
|
||||||
icon_widget.image = path_to_icons .. icon_map[resp.weather[1].icon]
|
|
||||||
temp_widget:set_text(string.gsub(resp.main.temp, "%.%d+", "")
|
|
||||||
.. '°'
|
|
||||||
.. (secrets.weather_widget_units == 'metric' and 'C' or 'F'))
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
weather_timer:start()
|
|
||||||
weather_timer:emit_signal("timeout")
|
|
||||||
|
|
||||||
--- Notification with weather information. Popups when mouse hovers over the icon
|
|
||||||
local notification
|
|
||||||
weather_widget:connect_signal("mouse::enter", function()
|
|
||||||
notification = naughty.notify{
|
|
||||||
icon = path_to_icons .. icon_map[resp.weather[1].icon],
|
|
||||||
icon_size=20,
|
|
||||||
text =
|
|
||||||
'<big>' .. resp.weather[1].main .. ' (' .. resp.weather[1].description .. ')</big><br>' ..
|
|
||||||
'<b>Humidity:</b> ' .. resp.main.humidity .. '%<br>' ..
|
|
||||||
'<b>Temperature:</b> ' .. resp.main.temp .. '°'
|
|
||||||
.. (secrets.weather_widget_units == 'metric' and 'C' or 'F') .. '<br>' ..
|
|
||||||
'<b>Pressure:</b> ' .. resp.main.pressure .. 'hPa<br>' ..
|
|
||||||
'<b>Clouds:</b> ' .. resp.clouds.all .. '%<br>' ..
|
|
||||||
'<b>Wind:</b> ' .. resp.wind.speed .. 'm/s (' .. to_direction(resp.wind.deg) .. ')',
|
|
||||||
timeout = 5, hover_timeout = 10,
|
|
||||||
width = 200
|
|
||||||
}
|
|
||||||
end)
|
|
||||||
|
|
||||||
weather_widget:connect_signal("mouse::leave", function()
|
|
||||||
naughty.destroy(notification)
|
|
||||||
end)
|
|
||||||
|
|
||||||
return weather_widget
|
|
||||||
|
|
Loading…
Reference in New Issue