Merge branch '74-externalize-config' of github.com:streetturtle/awesome-wm-widgets into 74-externalize-config

This commit is contained in:
Pavel Makhov 2019-07-03 09:41:09 -04:00
commit 3d84ce64bd
16 changed files with 560 additions and 358 deletions

View File

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

View File

@ -16,21 +16,41 @@ local watch = require("awful.widget.watch")
local HOME = os.getenv("HOME") local HOME = os.getenv("HOME")
local text = wibox.widget { 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 {
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
} }
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,
@ -40,11 +60,11 @@ local batteryarc = wibox.widget {
set_value = function(self, value) set_value = function(self, value)
self.value = value self.value = value
end, end,
} }
local last_battery_check = os.time() local last_battery_check = os.time()
watch("acpi -i", 10, watch("acpi -i", 10,
function(widget, stdout) function(widget, stdout)
local batteryType local batteryType
@ -55,7 +75,7 @@ watch("acpi -i", 10,
if string.match(s, 'rate information') then if string.match(s, 'rate information') then
-- ignore such line -- ignore such line
elseif status ~= nil then elseif status ~= nil then
table.insert(battery_info, {status = status, charge = tonumber(charge_str)}) table.insert(battery_info, { status = status, charge = tonumber(charge_str) })
else else
local cap_str = string.match(s, '.+:.+last full capacity (%d+)') local cap_str = string.match(s, '.+:.+last full capacity (%d+)')
table.insert(capacities, tonumber(cap_str)) table.insert(capacities, tonumber(cap_str))
@ -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,17 +135,17 @@ 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
local notification local notification
function show_battery_status() function show_battery_status()
awful.spawn.easy_async([[bash -c 'acpi']], awful.spawn.easy_async([[bash -c 'acpi']],
function(stdout, _, _, _) function(stdout, _, _, _)
naughty.destroy(notification) naughty.destroy(notification)
@ -133,34 +157,44 @@ function show_battery_status()
width = 200, width = 200,
} }
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
--battery_popup = awful.tooltip({objects = {battery_widget}}) --battery_popup = awful.tooltip({objects = {battery_widget}})
-- To use colors from beautiful theme put -- To use colors from beautiful theme put
-- following lines in rc.lua before require("battery"): -- following lines in rc.lua before require("battery"):
-- beautiful.tooltip_fg = beautiful.fg_normal -- beautiful.tooltip_fg = beautiful.fg_normal
-- beautiful.tooltip_bg = beautiful.bg_normal -- beautiful.tooltip_bg = beautiful.bg_normal
--[[ 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
return widget
end end
return batteryarc return setmetatable(widget, { __call = function(_, ...)
return worker(...)
end })

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

View File

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

View File

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

View File

@ -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'
})
... ...
``` ```

View File

@ -10,24 +10,36 @@
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 = {}
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 {
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
local cpu_widget = wibox.container.margin(wibox.container.mirror(cpugraph_widget, { horizontal = true }), 0, 0, 0, 2) local cpu_widget = wibox.container.margin(wibox.container.mirror(cpugraph_widget, { horizontal = true }), 0, 0, 0, 2)
local total_prev = 0 local total_prev = 0
local idle_prev = 0 local idle_prev = 0
watch([[bash -c "cat /proc/stat | grep '^cpu '"]], 1, watch([[bash -c "cat /proc/stat | grep '^cpu '"]], 1,
function(widget, stdout) function(widget, stdout)
local user, nice, system, idle, iowait, irq, softirq, steal, guest, guest_nice = local user, nice, system, idle, iowait, irq, softirq, steal, guest, guest_nice =
stdout:match('(%d+)%s(%d+)%s(%d+)%s(%d+)%s(%d+)%s(%d+)%s(%d+)%s(%d+)%s(%d+)%s(%d+)%s') stdout:match('(%d+)%s(%d+)%s(%d+)%s(%d+)%s(%d+)%s(%d+)%s(%d+)%s(%d+)%s(%d+)%s(%d+)%s')
@ -44,6 +56,12 @@ watch([[bash -c "cat /proc/stat | grep '^cpu '"]], 1,
idle_prev = idle idle_prev = idle
end, end,
cpugraph_widget cpugraph_widget
) )
return cpu_widget return cpu_widget
end
return setmetatable(widget, { __call = function(_, ...)
return worker(...)
end })

BIN
cpu-widget/cpu.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 KiB

BIN
cpu-widget/custom.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

View File

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

View File

@ -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,25 +33,23 @@ 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
end, end,
} }
local update_widget_icon = function(widget, stdout, _, _, _) local update_widget_icon = function(widget, stdout, _, _, _)
stdout = string.gsub(stdout, "\n", "") stdout = string.gsub(stdout, "\n", "")
widget:set_status(stdout == 'Playing' and true or false) widget:set_status(stdout == 'Playing' and true or false)
end end
local update_widget_text = function(widget, stdout, _, _, _) local update_widget_text = function(widget, stdout, _, _, _)
if string.find(stdout, 'Error: Spotify is not running.') ~= nil then if string.find(stdout, 'Error: Spotify is not running.') ~= nil then
widget:set_text('') widget:set_text('')
widget:set_visible(false) widget:set_visible(false)
@ -50,23 +57,32 @@ local update_widget_text = function(widget, stdout, _, _, _)
widget:set_text(stdout) widget:set_text(stdout)
widget:set_visible(true) widget:set_visible(true)
end end
end end
watch(GET_SPOTIFY_STATUS_CMD, 1, update_widget_icon, spotify_widget) watch(GET_SPOTIFY_STATUS_CMD, 1, update_widget_icon, spotify_widget)
watch(GET_CURRENT_SONG_CMD, 1, update_widget_text, spotify_widget) watch(GET_CURRENT_SONG_CMD, 1, update_widget_text, spotify_widget)
--- Adds mouse controls to the widget: --- Adds mouse controls to the widget:
-- - left click - play/pause -- - left click - play/pause
-- - 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)
end) end)
end) end)
return spotify_widget return spotify_widget
end
return setmetatable(spotify_widget, { __call = function(_, ...)
return worker(...)
end })

View File

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

View File

@ -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'
})
... ...
``` ```

View File

@ -16,31 +16,42 @@ 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 = {}
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 icon_widget = wibox.widget {
{ {
id = "icon", id = "icon",
resize = false, resize = false,
widget = wibox.widget.imagebox, widget = wibox.widget.imagebox,
}, },
layout = wibox.container.margin(_ , 0, 0, 3), layout = wibox.container.margin(_, 0, 0, 3),
set_image = function(self, path) set_image = function(self, path)
self.icon.image = path self.icon.image = path
end, end,
} }
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,
} }
--- Maps openWeatherMap icons to Arc icons --- Maps openWeatherMap icons to Arc icons
local icon_map = { local icon_map = {
["01d"] = "weather-clear-symbolic.svg", ["01d"] = "weather-clear-symbolic.svg",
["02d"] = "weather-few-clouds-symbolic.svg", ["02d"] = "weather-few-clouds-symbolic.svg",
["03d"] = "weather-clouds-symbolic.svg", ["03d"] = "weather-clouds-symbolic.svg",
@ -59,10 +70,10 @@ local icon_map = {
["11n"] = "weather-storm-symbolic.svg", ["11n"] = "weather-storm-symbolic.svg",
["13n"] = "weather-snow-symbolic.svg", ["13n"] = "weather-snow-symbolic.svg",
["50n"] = "weather-fog-symbolic.svg" ["50n"] = "weather-fog-symbolic.svg"
} }
--- Return wind direction as a string. --- Return wind direction as a string.
local function to_direction(degrees) local function to_direction(degrees)
-- Ref: https://www.campbellsci.eu/blog/convert-wind-directions -- Ref: https://www.campbellsci.eu/blog/convert-wind-directions
if degrees == nil then if degrees == nil then
return "Unknown dir" return "Unknown dir"
@ -87,19 +98,19 @@ local function to_direction(degrees)
"N", "N",
} }
return directions[math.floor((degrees % 360) / 22.5) + 1] return directions[math.floor((degrees % 360) / 22.5) + 1]
end end
local weather_timer = gears.timer({ timeout = 60 }) local weather_timer = gears.timer({ timeout = 60 })
local resp local resp
weather_timer:connect_signal("timeout", function () weather_timer:connect_signal("timeout", function()
local resp_json, status = http.request('https://api.openweathermap.org/data/2.5/weather?q=' local resp_json, status = http.request('https://api.openweathermap.org/data/2.5/weather?q='
.. secrets.weather_widget_city .. city
.. '&appid=' .. secrets.weather_widget_api_key .. '&appid=' .. api_key
.. '&units=' .. secrets.weather_widget_units) .. '&units=' .. units)
if (status ~= 200 and resp_json ~= nil) then if (status ~= 200 and resp_json ~= nil) then
local err_resp = json.decode(resp_json) local err_resp = json.decode(resp_json)
naughty.notify{ naughty.notify {
title = 'Weather Widget Error', title = 'Weather Widget Error',
text = err_resp.message, text = err_resp.message,
preset = naughty.config.presets.critical, preset = naughty.config.presets.critical,
@ -109,20 +120,19 @@ weather_timer:connect_signal("timeout", function ()
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(string.gsub(resp.main.temp, "%.%d+", "")
.. '°' .. '°'
.. (secrets.weather_widget_units == 'metric' and 'C' or 'F')) .. (units == 'metric' and 'C' or 'F'))
end end
end) end)
weather_timer:start() weather_timer:start()
weather_timer:emit_signal("timeout") weather_timer:emit_signal("timeout")
--- Notification with weather information. Popups when mouse hovers over the icon --- Notification with weather information. Popups when mouse hovers over the icon
local notification local notification
weather_widget:connect_signal("mouse::enter", function() weather_widget:connect_signal("mouse::enter", function()
notification = naughty.notify{ notification = naughty.notify {
icon = path_to_icons .. icon_map[resp.weather[1].icon], icon = path_to_icons .. icon_map[resp.weather[1].icon],
icon_size=20, icon_size = 20,
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> ' .. resp.main.temp .. '°'
.. (secrets.weather_widget_units == 'metric' and 'C' or 'F') .. '<br>' .. .. (secrets.weather_widget_units == 'metric' and 'C' or 'F') .. '<br>' ..
@ -132,10 +142,15 @@ weather_widget:connect_signal("mouse::enter", function()
timeout = 5, hover_timeout = 10, timeout = 5, hover_timeout = 10,
width = 200 width = 200
} }
end) end)
weather_widget:connect_signal("mouse::leave", function() weather_widget:connect_signal("mouse::leave", function()
naughty.destroy(notification) naughty.destroy(notification)
end) end)
return weather_widget return weather_widget
end
return setmetatable(weather_widget, { __call = function(_, ...)
return worker(...)
end })