summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--battery-widget/README.md2
-rw-r--r--battery-widget/battery.lua13
-rw-r--r--batteryarc-widget/README.md2
-rw-r--r--batteryarc-widget/batteryarc.lua7
-rw-r--r--cpu-widget/cpu-widget.lua33
-rw-r--r--todo-widget/README.md23
-rw-r--r--todo-widget/todo.gifbin0 -> 203168 bytes
-rw-r--r--todo-widget/todo.lua272
-rw-r--r--volume-widget/README.md65
-rw-r--r--volume-widget/volume.lua178
10 files changed, 472 insertions, 123 deletions
diff --git a/battery-widget/README.md b/battery-widget/README.md
index 823a3f7..4ea14d8 100644
--- a/battery-widget/README.md
+++ b/battery-widget/README.md
@@ -32,7 +32,7 @@ It is possible to customize widget by providing a table with all or some of the
| `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/battery-widget/spaceman.jpg | Icon of the warning popup |
-| `disable_battery_warning` | `false` | Disable low battery warning |
+| `enable_battery_warning` | `true` | Display low battery warning |
*Note: the widget expects following icons be present in the folder:
diff --git a/battery-widget/battery.lua b/battery-widget/battery.lua
index 43cdaee..d84e591 100644
--- a/battery-widget/battery.lua
+++ b/battery-widget/battery.lua
@@ -38,7 +38,10 @@ local function worker(args)
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 disable_battery_warning = args.disable_battery_warning or false
+ local enable_battery_warning = args.enable_battery_warning
+ if enable_battery_warning == nil then
+ enable_battery_warning = true
+ end
if not gfs.dir_readable(path_to_icons) then
naughty.notify{
@@ -116,10 +119,8 @@ local function worker(args)
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
+ local status, charge_str, time = string.match(s, '.+: (%a+), (%d?%d?%d)%%,?(.*)')
+ if status ~= nil then
table.insert(battery_info, {status = status, charge = tonumber(charge_str)})
else
local cap_str = string.match(s, '.+:.+last full capacity (%d+)')
@@ -150,7 +151,7 @@ local function worker(args)
if (charge >= 0 and charge < 15) then
batteryType = "battery-empty%s-symbolic"
- if (not disable_battery_warning) and status ~= 'Charging' and os.difftime(os.time(), last_battery_check) > 300 then
+ if enable_battery_warning and 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()
diff --git a/batteryarc-widget/README.md b/batteryarc-widget/README.md
index f537534..96e1aeb 100644
--- a/batteryarc-widget/README.md
+++ b/batteryarc-widget/README.md
@@ -33,7 +33,7 @@ It is possible to customize widget by providing a table with all or some of the
| `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 |
-| `disable_battery_warning` | `false` | Disable low battery warning |
+| `enable_battery_warning` | `true` | Display low battery warning |
## Requirements
diff --git a/batteryarc-widget/batteryarc.lua b/batteryarc-widget/batteryarc.lua
index 1843cf1..0bf6bc0 100644
--- a/batteryarc-widget/batteryarc.lua
+++ b/batteryarc-widget/batteryarc.lua
@@ -36,7 +36,10 @@ local function worker(args)
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 disable_battery_warning = args.disable_battery_warning or false
+ local enable_battery_warning = args.enable_battery_warning
+ if enable_battery_warning == nil then
+ enable_battery_warning = true
+ end
local text = wibox.widget {
id = "txt",
@@ -125,7 +128,7 @@ local function worker(args)
if charge < 15 then
widget.colors = { low_level_color }
- if (not disable_battery_warning) and status ~= 'Charging' and os.difftime(os.time(), last_battery_check) > 300 then
+ if enable_battery_warning and 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()
diff --git a/cpu-widget/cpu-widget.lua b/cpu-widget/cpu-widget.lua
index 7dfc5a7..e0dea4d 100644
--- a/cpu-widget/cpu-widget.lua
+++ b/cpu-widget/cpu-widget.lua
@@ -57,7 +57,7 @@ local function worker(args)
local is_update = true
local process_rows = {
- spacing = 8,
+ -- spacing = 8,
layout = wibox.layout.fixed.vertical,
}
@@ -192,29 +192,34 @@ local function worker(args)
local row = wibox.widget {
{
{
- text = pid,
- forced_width = 40,
- widget = wibox.widget.textbox
- },
- {
- text = comm,
- forced_width = 40,
- widget = wibox.widget.textbox
- },
- {
{
- text = cpu,
+ text = pid,
forced_width = 40,
widget = wibox.widget.textbox
},
{
- text = mem,
+ text = comm,
forced_width = 40,
widget = wibox.widget.textbox
},
+ {
+ {
+ text = cpu,
+ forced_width = 40,
+ widget = wibox.widget.textbox
+ },
+ {
+ text = mem,
+ forced_width = 40,
+ widget = wibox.widget.textbox
+ },
+ layout = wibox.layout.align.horizontal
+ },
layout = wibox.layout.align.horizontal
},
- layout = wibox.layout.align.horizontal
+ top = 4,
+ bottom = 4,
+ widget = wibox.container.margin
},
widget = wibox.container.background
}
diff --git a/todo-widget/README.md b/todo-widget/README.md
new file mode 100644
index 0000000..979f4f2
--- /dev/null
+++ b/todo-widget/README.md
@@ -0,0 +1,23 @@
+# ToDo Widget (in progress)
+
+This widget displays a list of to do items and allows to mark item as done/undone, delete an item and create a new ones:
+
+![screenshot](./todo.gif)
+
+# Installation
+
+Put a **json.lua** from this repository: https://github.com/rxi/json.lua under ~/.config/awesone folder. And don't forget to start a repo :)
+
+Then clone this repo under **~/.config/awesome/** and add the widget in **rc.lua**:
+
+```lua
+local todo_widget = require("awesome-wm-widgets.todo-widget.todo")
+...
+s.mytasklist, -- Middle widget
+ { -- Right widgets
+ layout = wibox.layout.fixed.horizontal,
+ ...
+ -- default
+ todo_widget(),
+ ...
+```
diff --git a/todo-widget/todo.gif b/todo-widget/todo.gif
new file mode 100644
index 0000000..7160e21
--- /dev/null
+++ b/todo-widget/todo.gif
Binary files differ
diff --git a/todo-widget/todo.lua b/todo-widget/todo.lua
new file mode 100644
index 0000000..ee459cf
--- /dev/null
+++ b/todo-widget/todo.lua
@@ -0,0 +1,272 @@
+-------------------------------------------------
+-- ToDo Widget for Awesome Window Manager
+-- More details could be found here:
+-- https://github.com/streetturtle/awesome-wm-widgets/tree/master/todo-widget
+
+-- @author Pavel Makhov
+-- @copyright 2020 Pavel Makhov
+-------------------------------------------------
+
+local awful = require("awful")
+local wibox = require("wibox")
+local json = require("json")
+local spawn = require("awful.spawn")
+local naughty = require("naughty")
+local gears = require("gears")
+local beautiful = require("beautiful")
+local gfs = require("gears.filesystem")
+local gs = require("gears.string")
+
+local HOME_DIR = os.getenv("HOME")
+
+local STORAGE = HOME_DIR .. '/.cache/awmw/todo-widget/todos.json'
+local GET_TODO_ITEMS = 'bash -c "cat ' .. STORAGE .. '"'
+
+local rows = { layout = wibox.layout.fixed.vertical }
+
+local todo_widget = {}
+
+todo_widget.widget = wibox.widget {
+ {
+ {
+ id = "icon",
+ widget = wibox.widget.imagebox
+ },
+ id = "margin",
+ margins = 4,
+ layout = wibox.container.margin
+ },
+ {
+ id = "txt",
+ widget = wibox.widget.textbox
+ },
+ layout = wibox.layout.fixed.horizontal,
+ set_text = function(self, new_value)
+ self.txt.text = new_value
+ end,
+ set_icon = function(self, new_value)
+ self.margin.icon.image = new_value
+ end
+}
+
+function todo_widget:update_counter(todos)
+ local todo_count = 0
+ for _,p in ipairs(todos) do
+ if not p.status then
+ todo_count = todo_count + 1
+ end
+ end
+
+ todo_widget.widget:set_text(todo_count)
+end
+
+local popup = awful.popup{
+ bg = beautiful.bg_normal,
+ ontop = true,
+ visible = false,
+ shape = gears.shape.rounded_rect,
+ border_width = 1,
+ border_color = beautiful.bg_focus,
+ maximum_width = 400,
+ offset = { y = 5 },
+ widget = {}
+}
+
+local add_button = wibox.widget {
+ {
+ {
+ image = '/usr/share/icons/Arc/actions/symbolic/list-add-symbolic.svg',
+ resize = false,
+ widget = wibox.widget.imagebox
+ },
+ top = 11,
+ left = 8,
+ right = 8,
+ layout = wibox.container.margin
+ },
+ shape = function(cr, width, height)
+ gears.shape.circle(cr, width, height, 12)
+ end,
+ widget = wibox.container.background
+}
+
+add_button:connect_signal("button::press", function(c)
+ local pr = awful.widget.prompt()
+
+ table.insert(rows, wibox.widget {
+ {
+ {
+ pr.widget,
+ spacing = 8,
+ layout = wibox.layout.align.horizontal
+ },
+ margins = 8,
+ layout = wibox.container.margin
+ },
+ bg = beautiful.bg_normal,
+ widget = wibox.container.background
+ })
+ awful.prompt.run{
+ prompt = "<b>New item</b>: ",
+ bg = beautiful.bg_normal,
+ bg_cursor = beautiful.fg_urgent,
+ textbox = pr.widget,
+ exe_callback = function(input_text)
+ if not input_text or #input_text == 0 then return end
+ spawn.easy_async(GET_TODO_ITEMS, function(stdout)
+ local res = json.decode(stdout)
+ table.insert(res.todo_items, {todo_item = input_text, status = false})
+ spawn.easy_async_with_shell("echo '" .. json.encode(res) .. "' > " .. STORAGE, function()
+ spawn.easy_async(GET_TODO_ITEMS, function(stdout) update_widget(stdout) end)
+ end)
+ end)
+ end
+ }
+ popup:setup(rows)
+end)
+add_button:connect_signal("mouse::enter", function(c) c:set_bg(beautiful.bg_focus) end)
+add_button:connect_signal("mouse::leave", function(c) c:set_bg(beautiful.bg_normal) end)
+
+local function worker(args)
+
+ local args = args or {}
+
+ local icon = args.icon or '/usr/share/icons/Arc/status/symbolic/checkbox-checked-symbolic.svg'
+
+ todo_widget.widget:set_icon(icon)
+
+ function update_widget(stdout)
+ local result = json.decode(stdout)
+ if result == nil or result == '' then result = {} end
+ todo_widget:update_counter(result.todo_items)
+
+ for i = 0, #rows do rows[i]=nil end
+
+ local first_row = wibox.widget {
+ {
+ {widget = wibox.widget.textbox},
+ {
+ markup = '<span size="large" font_weight="bold" color="#ffffff">ToDo</span>',
+ align = 'center',
+ forced_width = 350, -- for horizontal alignment
+ forced_height = 40,
+ widget = wibox.widget.textbox
+ },
+ add_button,
+ spacing = 8,
+ layout = wibox.layout.fixed.horizontal
+ },
+ bg = beautiful.bg_normal,
+ widget = wibox.container.background
+ }
+
+ table.insert(rows, first_row)
+
+
+ for i, todo_item in ipairs(result.todo_items) do
+
+ local checkbox = wibox.widget {
+ checked = todo_item.status,
+ color = beautiful.bg_normal,
+ paddings = 2,
+ shape = gears.shape.circle,
+ forced_width = 20,
+ forced_height = 20,
+ check_color = beautiful.fg_urgent,
+ widget = wibox.widget.checkbox
+ }
+
+ checkbox:connect_signal("button::press", function(c)
+ c:set_checked(not c.checked)
+ todo_item.status = not todo_item.status
+ result.todo_items[i] = todo_item
+ spawn.easy_async_with_shell("echo '" .. json.encode(result) .. "' > " .. STORAGE)
+ todo_widget:update_counter(result.todo_items)
+ end)
+
+ local trash_button = wibox.widget {
+ {
+ { image = '/usr/share/icons/Arc/actions/symbolic/window-close-symbolic.svg',
+ resize = false,
+ widget = wibox.widget.imagebox
+ },
+ margins = 5,
+ layout = wibox.container.margin
+ },
+ border_width = 1,
+ shape = function(cr, width, height)
+ gears.shape.circle(cr, width, height, 10)
+ end,
+ widget = wibox.container.background
+ }
+
+ trash_button:connect_signal("button::press", function(c)
+ table.remove(result.todo_items, i)
+ spawn.easy_async_with_shell("printf '" .. json.encode(result) .. "' > /home/pmakhov/.cache/awmw/todo-widget/todos.json")
+ spawn.easy_async(GET_TODO_ITEMS, function(stdout) update_widget(stdout) end)
+ end)
+
+ local row = wibox.widget {
+ {
+ {
+ {
+
+ checkbox,
+ valign = 'center',
+ layout = wibox.container.place,
+ },
+ {
+ {
+ text = todo_item.todo_item,
+ align = 'left',
+ widget = wibox.widget.textbox
+ },
+ left = 10,
+ layout = wibox.container.margin
+ },
+ {
+ trash_button,
+ valign = 'center',
+ layout = wibox.container.place,
+ },
+ spacing = 8,
+ layout = wibox.layout.align.horizontal
+ },
+ margins = 8,
+ layout = wibox.container.margin
+ },
+ bg = beautiful.bg_normal,
+ widget = wibox.container.background
+ }
+
+ row:connect_signal("mouse::enter", function(c) c:set_bg(beautiful.bg_focus) end)
+ row:connect_signal("mouse::leave", function(c) c:set_bg(beautiful.bg_normal) end)
+
+ table.insert(rows, row)
+ end
+
+ popup:setup(rows)
+ end
+
+ todo_widget.widget:buttons(
+ awful.util.table.join(
+ awful.button({}, 1, function()
+ if popup.visible then
+ popup.visible = not popup.visible
+ else
+ popup:move_next_to(mouse.current_widget_geometry)
+ end
+ end)
+ )
+ )
+
+ spawn.easy_async(GET_TODO_ITEMS, function(stdout) update_widget(stdout) end)
+
+ return todo_widget.widget
+end
+
+if not gfs.file_readable(STORAGE) then
+ spawn.easy_async(string.format([[bash -c "dirname %s | xargs mkdir -p && echo '{\"todo_items\":{}}' > %s"]], STORAGE, STORAGE))
+end
+
+return setmetatable(todo_widget, { __call = function(_, ...) return worker(...) end })
diff --git a/volume-widget/README.md b/volume-widget/README.md
index e43177a..065a504 100644
--- a/volume-widget/README.md
+++ b/volume-widget/README.md
@@ -10,9 +10,9 @@ It is possible to customize widget by providing a table with all or some of the
| Name | Default | Description |
|---|---|---|
-| `volume_audio_controller` | `pulse` | audio device |
-| `display_notification` | `false` | Display a notification on mouseover |
-| `notification_position` | `top_right` | The notification position |
+| `volume_audio_controller`| `pulse` | audio device |
+| `display_notification` | `false` | Display a notification on mouseover and keypress |
+| `notification_position` | `top_right`| The notification position |
## Installation
@@ -21,16 +21,47 @@ It is possible to customize widget by providing a table with all or some of the
- include `volume.lua` and add volume widget to your wibox in rc.lua:
```lua
-require("volume")
+local volume_widget = require("awesome-wm-widgets.volume-widget.volume")
...
-s.mytasklist, -- Middle widget
- { -- Right widgets
- layout = wibox.layout.fixed.horizontal,
- ...
- volume_widget(),
- ...
+ s.mytasklist, -- Middle widget
+ { -- Right widgets
+ ...
+ volume_widget({display_notification = true}),
+ ...
+
+```
+### Control volume
+
+To mute/unmute click on the widget. To increase/decrease volume scroll up or down when mouse cursor is over the widget.
+
+If you want to control volume level by keyboard shortcuts add following lines in shortcut section of the **rc.lua**:
+IF you have notification activated, a notification will pop-up on key press
+
+```lua
+-- Key bindings
+globalkeys = gears.table.join(
+ awful.key(
+ {},
+ 'XF86AudioRaiseVolume',
+ volume_widget.raise,
+ {description = 'volume up', group = 'hotkeys'}
+ ),
+ awful.key(
+ {},
+ 'XF86AudioLowerVolume',
+ volume_widget.lower,
+ {description = 'volume down', group = 'hotkeys'}
+ ),
+ awful.key(
+ {},
+ 'XF86AudioMute',
+ volume_widget.toggle,
+ {description = 'toggle mute', group = 'hotkeys'}
+ ),
```
+### Icons
+
- _Optional step._ In Arc icon theme the muted audio level icon (![Volume-widget](./audio-volume-muted-symbolic.png)) looks like 0 level icon, which could be a bit misleading.
So I decided to use original muted icon for low audio level, and the same icon, but colored in red for muted audio level. Fortunately icons are in svg format, so you can easily recolor them with `sed`, so it would look like this (![Volume Widget](./audio-volume-muted-symbolic_red.png)):
@@ -74,17 +105,3 @@ volume_widget({
volume_audio_controller = 'alsa_only'
})
```
-
-.
-
-## Control volume
-
-To mute/unmute click on the widget. To increase/decrease volume scroll up or down when mouse cursor is over the widget.
-
-If you want to control volume level by keyboard shortcuts add following lines in shortcut section of the **rc.lua** (the commands could be slightly different depending on your PC configuration):
-
-```lua
-awful.key({ modkey}, "[", function () awful.spawn("amixer -D pulse sset Master 5%+") end, {description = "increase volume", group = "custom"}),
-awful.key({ modkey}, "]", function () awful.spawn("amixer -D pulse sset Master 5%-") end, {description = "decrease volume", group = "custom"}),
-awful.key({ modkey}, "\", function () awful.spawn("amixer -D pulse set Master +1 toggle") end, {description = "mute volume", group = "custom"}),
-```
diff --git a/volume-widget/volume.lua b/volume-widget/volume.lua
index ef95550..652c39b 100644
--- a/volume-widget/volume.lua
+++ b/volume-widget/volume.lua
@@ -4,7 +4,7 @@
-- More details could be found here:
-- https://github.com/streetturtle/awesome-wm-widgets/tree/master/volume-widget
--- @author Pavel Makhov
+-- @author Pavel Makhov, Aurélien Lajoie
-- @copyright 2018 Pavel Makhov
-------------------------------------------------
@@ -16,35 +16,101 @@ local gfs = require("gears.filesystem")
local dpi = require('beautiful').xresources.apply_dpi
local PATH_TO_ICONS = "/usr/share/icons/Arc/status/symbolic/"
+local volume_icon_name="audio-volume-high-symbolic"
+local GET_VOLUME_CMD = 'amixer sget Master'
-local volume_widget = {}
+local volume = {device = '', display_notification = false, notification = nil}
-local function worker(args)
+function volume:toggle()
+ volume:_cmd('amixer ' .. volume.device .. ' sset Master toggle')
+end
+
+function volume:raise()
+ volume:_cmd('amixer ' .. volume.device .. ' sset Master 5%+')
+end
+function volume:lower()
+ volume:_cmd('amixer ' .. volume.device .. ' sset Master 5%-')
+end
+
+--{{{ Icon and notification update
+
+--------------------------------------------------
+-- Set the icon and return the message to display
+-- base on sound level and mute
+--------------------------------------------------
+local function parse_output(stdout)
+ local level = string.match(stdout, "(%d?%d?%d)%%")
+ if stdout:find("%[off%]") then
+ volume_icon_name="audio-volume-muted-symbolic_red"
+ return level.."% <span color=\"red\"><b>Mute</b></span>"
+ end
+ level = tonumber(string.format("% 3d", level))
+
+ if (level >= 0 and level < 25) then
+ volume_icon_name="audio-volume-muted-symbolic"
+ elseif (level < 50) then
+ volume_icon_name="audio-volume-low-symbolic"
+ elseif (level < 75) then
+ volume_icon_name="audio-volume-medium-symbolic"
+ else
+ volume_icon_name="audio-volume-high-symbolic"
+ end
+ return level.."%"
+end
+--------------------------------------------------------
+--Update the icon and the notification if needed
+--------------------------------------------------------
+local function update_graphic(widget, stdout, _, _, _)
+ local txt = parse_output(stdout)
+ widget.image = PATH_TO_ICONS .. volume_icon_name .. ".svg"
+ if volume.display_notification then
+ volume.notification.iconbox.image = PATH_TO_ICONS .. volume_icon_name .. ".svg"
+ naughty.replace_text(volume.notification, "Volume", txt)
+ end
+end
+
+local function notif(msg, keep)
+ if volume.display_notification then
+ naughty.destroy(volume.notification)
+ volume.notification= naughty.notify{
+ text = msg,
+ icon=PATH_TO_ICONS .. volume_icon_name .. ".svg",
+ icon_size = dpi(16),
+ title = "Volume",
+ position = volume.position,
+ timeout = keep and 0 or 2, hover_timeout = 0.5,
+ width = 200,
+ }
+ end
+end
+
+--}}}
+
+local function worker(args)
+--{{{ Args
local args = args or {}
local volume_audio_controller = args.volume_audio_controller or 'pulse'
- local display_notification = args.display_notification or false
- local position = args.notification_position or "top_right"
- local device_arg = ''
+ volume.display_notification = args.display_notification or false
+ volume.position = args.notification_position or "top_right"
if volume_audio_controller == 'pulse' then
- device_arg = '-D pulse'
+ volume.device = '-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'
-
+ GET_VOLUME_CMD = 'amixer ' .. volume.device.. ' sget Master'
+--}}}
+--{{{ Check for icon path
if not gfs.dir_readable(PATH_TO_ICONS) then
naughty.notify{
title = "Volume Widget",
text = "Folder with icons doesn't exist: " .. PATH_TO_ICONS,
preset = naughty.config.presets.critical
}
+ return
end
-
- volume_widget = wibox.widget {
+--}}}
+--{{{ Widget creation
+ volume.widget = wibox.widget {
{
id = "icon",
image = PATH_TO_ICONS .. "audio-volume-muted-symbolic.svg",
@@ -56,79 +122,41 @@ local function worker(args)
self.icon.image = path
end
}
-
- local notification
- local volume_icon_name="audio-volume-high-symbolic"
-
- local function get_notification_text(txt)
- local mute = string.match(txt, "%[(o%a%a?)%]")
- local volume = string.match(txt, "(%d?%d?%d)%%")
- volume = tonumber(string.format("% 3d", volume))
- if mute == "off" then
- return volume.."% <span color=\"red\"><b>Mute</b></span>"
- else
- return volume .."%"
- end
+--}}}
+--{{{ Spawn functions
+ function volume:_cmd(cmd)
+ notif("")
+ spawn.easy_async(cmd, function(stdout, stderr, exitreason, exitcode)
+ update_graphic(volume.widget, stdout, stderr, exitreason, exitcode)
+ end)
end
- local function show_volume(val)
+ local function show()
spawn.easy_async(GET_VOLUME_CMD,
function(stdout, _, _, _)
- naughty.destroy(notification)
- notification = naughty.notify{
- text = get_notification_text(stdout),
- icon=PATH_TO_ICONS .. val .. ".svg",
- icon_size = dpi(16),
- title = "Volume",
- position = position,
- timeout = 0, hover_timeout = 0.5,
- width = 200,
- }
+ txt = parse_output(stdout)
+ notif(txt, true)
end
)
end
-
-
- local update_graphic = function(widget, stdout, _, _, _)
- local mute = string.match(stdout, "%[(o%D%D?)%]")
- local volume = string.match(stdout, "(%d?%d?%d)%%")
- volume = tonumber(string.format("% 3d", volume))
- if mute == "off" then volume_icon_name="audio-volume-muted-symbolic_red"
- elseif (volume >= 0 and volume < 25) then volume_icon_name="audio-volume-muted-symbolic"
- elseif (volume < 50) then volume_icon_name="audio-volume-low-symbolic"
- elseif (volume < 75) then volume_icon_name="audio-volume-medium-symbolic"
- elseif (volume <= 100) then volume_icon_name="audio-volume-high-symbolic"
- end
- widget.image = PATH_TO_ICONS .. volume_icon_name .. ".svg"
- if display_notification then
- notification.iconbox.image = PATH_TO_ICONS .. volume_icon_name .. ".svg"
- naughty.replace_text(notification, "Volume", get_notification_text(stdout))
- end
- end
-
+--}}}
+--{{{ Mouse event
--[[ allows control volume level by:
- clicking on the widget to mute/unmute
- scrolling when cursor is over the widget
]]
- volume_widget:connect_signal("button::press", function(_,_,_,button)
- if (button == 4) then spawn(INC_VOLUME_CMD, false)
- elseif (button == 5) then spawn(DEC_VOLUME_CMD, false)
- elseif (button == 1) then spawn(TOG_VOLUME_CMD, false)
+ volume.widget:connect_signal("button::press", function(_,_,_,button)
+ if (button == 4) then volume.raise()
+ elseif (button == 5) then volume.lower()
+ elseif (button == 1) then volume.toggle()
end
-
- spawn.easy_async(GET_VOLUME_CMD, function(stdout, stderr, exitreason, exitcode)
- update_graphic(volume_widget, stdout, stderr, exitreason, exitcode)
- end)
end)
-
- if display_notification then
- volume_widget:connect_signal("mouse::enter", function() show_volume(volume_icon_name) end)
- volume_widget:connect_signal("mouse::leave", function() naughty.destroy(notification) end)
+ if volume.display_notification then
+ volume.widget:connect_signal("mouse::enter", function() show() end)
+ volume.widget:connect_signal("mouse::leave", function() naughty.destroy(volume.notification) end)
end
-
- 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 })
+return setmetatable(volume, { __call = function(_, ...) return worker(...) end })