From 2c1bc7a18e5ea9fd324078d960b3f05db1cba753 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Fournier-S=27niehotta?= Date: Wed, 4 Apr 2018 11:38:49 +0200 Subject: [PATCH 1/8] first commit with my versions of volumearc and batteryarc --- batteryarc-widget/batteryarc.lua | 32 ++++++++++++++++-------- volumearc-widget/volumearc.lua | 43 ++++++++++++++++++++++++++------ 2 files changed, 56 insertions(+), 19 deletions(-) diff --git a/batteryarc-widget/batteryarc.lua b/batteryarc-widget/batteryarc.lua index e1ab203f..52206e3f 100644 --- a/batteryarc-widget/batteryarc.lua +++ b/batteryarc-widget/batteryarc.lua @@ -9,7 +9,7 @@ local HOME = os.getenv("HOME") -- only text local text = wibox.widget { id = "txt", - font = "Play 5", + font = "Play 8", widget = wibox.widget.textbox } @@ -25,10 +25,10 @@ local batteryarc = wibox.widget { rounded_edge = true, thickness = 2, start_angle = 4.71238898, -- 2pi*3/4 - forced_height = 17, - forced_width = 17, + forced_height = 32, + forced_width = 32, bg = "#ffffff11", - paddings = 2, + paddings = 4, widget = wibox.container.arcchart, set_value = function(self, value) self.value = value @@ -38,31 +38,41 @@ local batteryarc = wibox.widget { -- mirror the widget, so that chart value increases clockwise local batteryarc_widget = wibox.container.mirror(batteryarc, { horizontal = true }) -watch("acpi", 10, +watch("acpi", 30, function(widget, stdout, stderr, exitreason, exitcode) local batteryType local _, status, charge_str, time = string.match(stdout, '(.+): (%a+), (%d?%d%d)%%,? ?.*') local charge = tonumber(charge_str) widget.value = charge / 100 if status == 'Charging' then - mirrored_text_with_background.bg = beautiful.widget_green - mirrored_text_with_background.fg = beautiful.widget_black + mirrored_text_with_background.fg = beautiful.widget_green + --mirrored_text_with_background.fg = beautiful.widget_black else mirrored_text_with_background.bg = beautiful.widget_transparent mirrored_text_with_background.fg = beautiful.widget_main_color end - if charge < 15 then + if charge < 10 then batteryarc.colors = { beautiful.widget_red } if status ~= 'Charging' then show_battery_warning() end - elseif charge > 15 and charge < 40 then + elseif charge > 10 and charge < 25 then batteryarc.colors = { beautiful.widget_yellow } + elseif charge < 100 then + batteryarc.colors = { beautiful.widget_green } else batteryarc.colors = { beautiful.widget_main_color } end - text.text = charge + + if charge == 100 then + --text.text = string.format("%03d", charge) + text.text = charge + text.font = "Play 8" + else + text.text = charge + text.font = "Play 12" + end end, batteryarc) @@ -110,4 +120,4 @@ function show_battery_warning() } end -return batteryarc_widget \ No newline at end of file +return batteryarc_widget diff --git a/volumearc-widget/volumearc.lua b/volumearc-widget/volumearc.lua index c2c0af96..52847ef3 100644 --- a/volumearc-widget/volumearc.lua +++ b/volumearc-widget/volumearc.lua @@ -15,18 +15,37 @@ local watch = require("awful.widget.watch") local wibox = require("wibox") local GET_VOLUME_CMD = 'amixer -D pulse sget Master' -local INC_VOLUME_CMD = 'amixer -D pulse sset Master 5%+' -local DEC_VOLUME_CMD = 'amixer -D pulse sset Master 5%-' +--local INC_VOLUME_CMD = 'amixer -D pulse sset Master 5%+' +local INC_VOLUME_CMD = 'amixer -q -c 0 sset Master 2dB+' +--local DEC_VOLUME_CMD = 'amixer -D pulse sset Master 5%-' +local DEC_VOLUME_CMD = 'amixer -q -c 0 sset Master 2dB-' local TOG_VOLUME_CMD = 'amixer -D pulse sset Master toggle' +local MIXER_CMD = 'urxvtc -e alsamixer' + +local text = wibox.widget { + id = "txt", + font = "Play 12", + widget = wibox.widget.textbox +} +-- mirror the text, because the whole widget will be mirrored after +--local mirrored_text = wibox.container.margin(wibox.container.mirror(text, { horizontal = true })) +--mirrored_text.right = 2 -- pour centrer le texte dans le rond +-- +local mirrored_text = wibox.container.mirror(text, { horizontal = true }) + +-- mirrored text with background +local mirrored_text_with_background = wibox.container.background(mirrored_text) local volumearc = wibox.widget { + mirrored_text_with_background, max_value = 1, thickness = 2, start_angle = 4.71238898, -- 2pi*3/4 - forced_height = 17, - forced_width = 17, + forced_height = 32, + forced_width = 32, + rounded_edge = true, bg = "#ffffff11", - paddings = 2, + paddings = 4, widget = wibox.container.arcchart } @@ -34,8 +53,9 @@ local volumearc_widget = wibox.container.mirror(volumearc, { horizontal = true } 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)) + local volume1 = string.match(stdout, "(%d?%d?%d)%%") + volume = tonumber(string.format("% 3d", volume1)) + volumepad = tonumber(string.format("% 3d", volume1)) widget.value = volume / 100; if mute == "off" then @@ -43,12 +63,19 @@ local update_graphic = function(widget, stdout, _, _, _) else widget.colors = { beautiful.widget_main_color } end + if volume == 100 then + text.text = string.format("%03d", volumepad) + else + text.text = string.format("%02d", volumepad) + text.font = "Play 11" + end end volumearc:connect_signal("button::press", function(_, _, _, button) if (button == 4) then awful.spawn(INC_VOLUME_CMD, false) elseif (button == 5) then awful.spawn(DEC_VOLUME_CMD, false) elseif (button == 1) then awful.spawn(TOG_VOLUME_CMD, false) + elseif (button == 3) then awful.spawn(MIXER_CMD, false) end spawn.easy_async(GET_VOLUME_CMD, function(stdout, stderr, exitreason, exitcode) @@ -58,4 +85,4 @@ end) watch(GET_VOLUME_CMD, 1, update_graphic, volumearc) -return volumearc_widget \ No newline at end of file +return volumearc_widget From 57bddc1ee995a19475e4944337b095db62451217 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Fournier-S=27niehotta?= Date: Wed, 4 Apr 2018 16:11:14 +0200 Subject: [PATCH 2/8] change behavior of right click for volumearc, font config for batteryarc --- batteryarc-widget/batteryarc.lua | 4 ++-- volumearc-widget/volumearc.lua | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/batteryarc-widget/batteryarc.lua b/batteryarc-widget/batteryarc.lua index 52206e3f..b5f22e5d 100644 --- a/batteryarc-widget/batteryarc.lua +++ b/batteryarc-widget/batteryarc.lua @@ -67,8 +67,8 @@ watch("acpi", 30, if charge == 100 then --text.text = string.format("%03d", charge) - text.text = charge - text.font = "Play 8" + text.text = "OK" + text.font = "Play 10" else text.text = charge text.font = "Play 12" diff --git a/volumearc-widget/volumearc.lua b/volumearc-widget/volumearc.lua index 52847ef3..af2cf879 100644 --- a/volumearc-widget/volumearc.lua +++ b/volumearc-widget/volumearc.lua @@ -20,7 +20,7 @@ local INC_VOLUME_CMD = 'amixer -q -c 0 sset Master 2dB+' --local DEC_VOLUME_CMD = 'amixer -D pulse sset Master 5%-' local DEC_VOLUME_CMD = 'amixer -q -c 0 sset Master 2dB-' local TOG_VOLUME_CMD = 'amixer -D pulse sset Master toggle' -local MIXER_CMD = 'urxvtc -e alsamixer' +local MIXER_CMD = 'urxvtc -e bash -c "alsamixer -c0"' local text = wibox.widget { id = "txt", @@ -39,8 +39,8 @@ local mirrored_text_with_background = wibox.container.background(mirrored_text) local volumearc = wibox.widget { mirrored_text_with_background, max_value = 1, - thickness = 2, start_angle = 4.71238898, -- 2pi*3/4 + thickness = 2, forced_height = 32, forced_width = 32, rounded_edge = true, From ec3f459fd09b17665f7aab78b12cc2e932f851f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Fournier-S=27niehotta?= Date: Fri, 13 Apr 2018 13:37:46 +0200 Subject: [PATCH 3/8] batteryarc: color to distinguish between charging and de-charging behaviors --- batteryarc-widget/batteryarc.lua | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/batteryarc-widget/batteryarc.lua b/batteryarc-widget/batteryarc.lua index b5f22e5d..cadd91d3 100644 --- a/batteryarc-widget/batteryarc.lua +++ b/batteryarc-widget/batteryarc.lua @@ -60,7 +60,11 @@ watch("acpi", 30, elseif charge > 10 and charge < 25 then batteryarc.colors = { beautiful.widget_yellow } elseif charge < 100 then - batteryarc.colors = { beautiful.widget_green } + if status == 'Charging' then + batteryarc.colors = { beautiful.widget_green } + else + batteryarc.colors = { beautiful.widget_main_color } + end else batteryarc.colors = { beautiful.widget_main_color } end From bf6f9c0c582e02fbb542c42053a1ccd34300e068 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Fournier-S=27niehotta?= Date: Fri, 13 Apr 2018 13:39:03 +0200 Subject: [PATCH 4/8] volumearc: margin container to center text --- volumearc-widget/volumearc.lua | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/volumearc-widget/volumearc.lua b/volumearc-widget/volumearc.lua index af2cf879..f215b69c 100644 --- a/volumearc-widget/volumearc.lua +++ b/volumearc-widget/volumearc.lua @@ -49,6 +49,10 @@ local volumearc = wibox.widget { widget = wibox.container.arcchart } +--local volumearc_widget = wibox.container.margin(wibox.container.mirror(volumearc, { horizontal = true })) +--volumearc_widget.margins = 4 +--local mirrored_text = wibox.container.margin(wibox.container.mirror(text, { horizontal = true })) +--mirrored_text.right = 2 -- pour centrer le texte dans le rond local volumearc_widget = wibox.container.mirror(volumearc, { horizontal = true }) local update_graphic = function(widget, stdout, _, _, _) From 59db8a0b4b3f22e6b90b4ab7b1567f505f5478f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Fournier-S=27niehotta?= Date: Fri, 13 Apr 2018 13:39:23 +0200 Subject: [PATCH 5/8] first commit of the pomodoroarc widget --- pomodoroarc-widget/pomodoroarc.lua | 134 +++++++++++++++++++++++++++++ 1 file changed, 134 insertions(+) create mode 100644 pomodoroarc-widget/pomodoroarc.lua diff --git a/pomodoroarc-widget/pomodoroarc.lua b/pomodoroarc-widget/pomodoroarc.lua new file mode 100644 index 00000000..51585706 --- /dev/null +++ b/pomodoroarc-widget/pomodoroarc.lua @@ -0,0 +1,134 @@ +------------------------------------------------- +-- Pomodoro Arc Widget for Awesome Window Manager +-- Modelled after Pavel Makhov's work + +-- @author Raphaël Fournier-S'niehotta +-- @copyright 2018 Raphaël Fournier-S'niehotta +------------------------------------------------- + +local awful = require("awful") +local beautiful = require("beautiful") +local spawn = require("awful.spawn") +local watch = require("awful.widget.watch") +local wibox = require("wibox") +local naughty = require("naughty") + +local GET_pomodoro_CMD = "/home/raph/scripts/pomo/pomo.sh clock" +local PAUSE_pomodoro_CMD = "/home/raph/scripts/pomo/pomo.sh pause" +local START_pomodoro_CMD = "/home/raph/scripts/pomo/pomo.sh start" +local STOP_pomodoro_CMD = "/home/raph/scripts/pomo/pomo.sh stop" + +local text = wibox.widget { + id = "txt", + --font = "Play 12", +font = "Inconsolata Medium 13", + widget = wibox.widget.textbox +} +-- mirror the text, because the whole widget will be mirrored after +local mirrored_text = wibox.container.margin(wibox.container.mirror(text, { horizontal = true })) +mirrored_text.right = 5 -- pour centrer le texte dans le rond +-- +--local mirrored_text = wibox.container.mirror(text, { horizontal = true }) + +-- mirrored text with background +local mirrored_text_with_background = wibox.container.background(mirrored_text) + +local pomodoroarc = wibox.widget { + mirrored_text_with_background, + max_value = 1, + thickness = 2, + start_angle = 4.71238898, -- 2pi*3/4 + forced_height = 32, + forced_width = 32, + rounded_edge = true, + bg = "#ffffff11", + paddings = 0, + widget = wibox.container.arcchart +} + +local pomodoroarc_widget = wibox.container.mirror(pomodoroarc, { horizontal = true }) + +local update_graphic = function(widget, stdout, _, _, _) + local pomostatus = string.match(stdout, " (%D?%D?):%D?%D?") + if pomostatus == "--" then +text.font = "Inconsolata Medium 13" + widget.colors = { beautiful.widget_main_color } + text.text = "25" + widget.value = 1 + else +text.font = "Inconsolata Medium 13" + local pomomin = string.match(stdout, "[ P]?[BW](%d?%d?):%d?%d?") + local pomosec = string.match(stdout, "[ P]?[BW]%d?%d?:(%d?%d?)") + local pomodoro = pomomin * 60 + pomosec + + local status = string.match(stdout, "([ P]?)[BW]%d?%d?:%d?%d?") + local workbreak = string.match(stdout, "[ P]?([BW])%d?%d?:%d?%d?") + text.text = pomomin + + --naughty.notify { + --text = pomomin, + --title = "pomodoro debug", + --timeout = 5, + --hover_timeout = 0.5, + --width = 200, + --} + + if status == " " then -- clock ticking + if workbreak == "W" then + widget.value = tonumber(pomodoro/(25*60)) + if tonumber(pomomin) < 5 then -- last 5 min of pomo + widget.colors = { beautiful.widget_red } + else + widget.colors = { beautiful.widget_blue } + end + elseif workbreak == "B" then -- color during pause + widget.colors = { beautiful.widget_green } + widget.value = tonumber(pomodoro/(5*60)) + end + elseif status == "P" then -- paused + if workbreak == "W" then + widget.colors = { beautiful.widget_yellow } + widget.value = tonumber(pomodoro/(25*60)) +text.font = "Inconsolata Medium 13" + text.text = "PW" + elseif workbreak == "B" then + widget.colors = { beautiful.widget_yellow } + widget.value = tonumber(pomodoro/(5*60)) +text.font = "Inconsolata Medium 13" + text.text = "PB" + end + end + end +end + +pomodoroarc:connect_signal("button::press", function(_, _, _, button) + if (button == 2) then awful.spawn(PAUSE_pomodoro_CMD, false) + elseif (button == 1) then awful.spawn(START_pomodoro_CMD, false) + elseif (button == 3) then awful.spawn(STOP_pomodoro_CMD, false) + end + + spawn.easy_async(GET_pomodoro_CMD, function(stdout, stderr, exitreason, exitcode) + update_graphic(pomodoroarc, stdout, stderr, exitreason, exitcode) + end) +end) + +local notification +function show_pomodoro_status() + spawn.easy_async(GET_pomodoro_CMD, + function(stdout, _, _, _) + notification = naughty.notify { + text = stdout, + title = "pomodoro status", + timeout = 5, + hover_timeout = 0.5, + width = 200, + } + end) +end + +pomodoroarc:connect_signal("mouse::enter", function() show_pomodoro_status() end) +pomodoroarc:connect_signal("mouse::leave", function() naughty.destroy(notification) end) + +watch(GET_pomodoro_CMD, 1, update_graphic, pomodoroarc) + +return pomodoroarc_widget From be6987668839affcf2e36e241aed8c1fffb76074 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Fournier-S=27niehotta?= Date: Sat, 14 Apr 2018 22:05:55 +0200 Subject: [PATCH 6/8] first commit of mpdarc widget. Works --- mpdarc-widget/mpdarc.lua | 99 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 mpdarc-widget/mpdarc.lua diff --git a/mpdarc-widget/mpdarc.lua b/mpdarc-widget/mpdarc.lua new file mode 100644 index 00000000..317f0bd2 --- /dev/null +++ b/mpdarc-widget/mpdarc.lua @@ -0,0 +1,99 @@ +------------------------------------------------- +-- mpd Arc Widget for Awesome Window Manager +-- Modelled after Pavel Makhov's work + +-- @author Raphaël Fournier-S'niehotta +-- @copyright 2018 Raphaël Fournier-S'niehotta +------------------------------------------------- + +local awful = require("awful") +local beautiful = require("beautiful") +local spawn = require("awful.spawn") +local watch = require("awful.widget.watch") +local wibox = require("wibox") +local naughty = require("naughty") + +local GET_MPD_CMD = "mpc status" +local PAUSE_MPD_CMD = "mpc pause" +local START_MPD_CMD = "mpc play" +local STOP_MPD_CMD = "mpc stop" + +local PATH_TO_ICONS = "/usr/share/icons/Arc" +local PAUSE_ICON_NAME = PATH_TO_ICONS .. "/actions/24/player_pause.png" +local PLAY_ICON_NAME = PATH_TO_ICONS .. "/actions/24/player_play.png" +local STOP_ICON_NAME = PATH_TO_ICONS .. "/actions/24/player_stop.png" + +local icon = wibox.widget { + id = "icon", + widget = wibox.widget.imagebox, + image = PLAY_ICON_NAME + } +local mirrored_icon = wibox.container.mirror(icon, { horizontal = true }) + +local mpdarc = wibox.widget { + mirrored_icon, + max_value = 1, + value = 0.75, + thickness = 2, + start_angle = 4.71238898, -- 2pi*3/4 + forced_height = 32, + forced_width = 32, + rounded_edge = true, + bg = "#ffffff11", + paddings = 0, + widget = wibox.container.arcchart +} + +local mpdarc_widget = wibox.container.mirror(mpdarc, { horizontal = true }) + +local update_graphic = function(widget, stdout, _, _, _) + stdout = string.gsub(stdout, "\n", "") + local mpdpercent = string.match(stdout, "(%d%d)%%") + local mpdstatus = string.match(stdout, "%[(%a+)%]") + if mpdstatus == "playing" then + icon.image = PLAY_ICON_NAME + widget.colors = { beautiful.widget_main_color } + widget.value = tonumber((100-mpdpercent)/100) + elseif mpdstatus == "paused" then + icon.image = PAUSE_ICON_NAME + widget.colors = { beautiful.widget_main_color } + widget.value = tonumber(mpdpercent/100) + else + icon.image = STOP_ICON_NAME + widget.colors = { beautiful.widget_red } + end +end + +mpdarc:connect_signal("button::press", function(_, _, _, button) + if (button == 1) then awful.spawn("mpc toggle", false) -- left click + elseif (button == 2) then awful.spawn("mpc stop", false) + elseif (button == 3) then awful.spawn("mpc pause", false) + elseif (button == 4) then awful.spawn("mpc next", false) -- scroll up + elseif (button == 5) then awful.spawn("mpc prev", false) -- scroll down + end + + spawn.easy_async(GET_MPD_CMD, function(stdout, stderr, exitreason, exitcode) + update_graphic(mpdarc, stdout, stderr, exitreason, exitcode) + end) +end) + +local notification +function show_MPD_status() + spawn.easy_async(GET_MPD_CMD, + function(stdout, _, _, _) + notification = naughty.notify { + text = stdout, + title = "MPD", + timeout = 5, + hover_timeout = 0.5, + width = 600, + } + end) +end + +mpdarc:connect_signal("mouse::enter", function() show_MPD_status() end) +mpdarc:connect_signal("mouse::leave", function() naughty.destroy(notification) end) + +watch(GET_MPD_CMD, 1, update_graphic, mpdarc) + +return mpdarc_widget From f7c50252dbb7dfccda1b45c1720631d1d4a22b69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Fournier-S=27niehotta?= Date: Mon, 16 Apr 2018 12:21:49 +0200 Subject: [PATCH 7/8] stop state --- mpdarc-widget/mpdarc.lua | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/mpdarc-widget/mpdarc.lua b/mpdarc-widget/mpdarc.lua index 317f0bd2..8e1b729f 100644 --- a/mpdarc-widget/mpdarc.lua +++ b/mpdarc-widget/mpdarc.lua @@ -18,10 +18,15 @@ local PAUSE_MPD_CMD = "mpc pause" local START_MPD_CMD = "mpc play" local STOP_MPD_CMD = "mpc stop" -local PATH_TO_ICONS = "/usr/share/icons/Arc" -local PAUSE_ICON_NAME = PATH_TO_ICONS .. "/actions/24/player_pause.png" -local PLAY_ICON_NAME = PATH_TO_ICONS .. "/actions/24/player_play.png" -local STOP_ICON_NAME = PATH_TO_ICONS .. "/actions/24/player_stop.png" +--local PATH_TO_ICONS = "/usr/share/icons/Arc/actions/24/player_" +local PATH_TO_ICONS = "/home/raph/.config/awesome/themes/myzenburn/" + +local PAUSE_ICON_NAME = PATH_TO_ICONS .. "pause.png" +local PLAY_ICON_NAME = PATH_TO_ICONS .. "play.png" +local STOP_ICON_NAME = PATH_TO_ICONS .. "stop.png" +--local PAUSE_ICON_NAME = PATH_TO_ICONS .. "/actions/24/player_pause.png" +--local PLAY_ICON_NAME = PATH_TO_ICONS .. "/actions/24/player_play.png" +--local STOP_ICON_NAME = PATH_TO_ICONS .. "/actions/24/player_stop.png" local icon = wibox.widget { id = "icon", @@ -48,19 +53,21 @@ local mpdarc_widget = wibox.container.mirror(mpdarc, { horizontal = true }) local update_graphic = function(widget, stdout, _, _, _) stdout = string.gsub(stdout, "\n", "") - local mpdpercent = string.match(stdout, "(%d%d)%%") local mpdstatus = string.match(stdout, "%[(%a+)%]") if mpdstatus == "playing" then + local mpdpercent = string.match(stdout, "(%d%d)%%") icon.image = PLAY_ICON_NAME widget.colors = { beautiful.widget_main_color } widget.value = tonumber((100-mpdpercent)/100) elseif mpdstatus == "paused" then + local mpdpercent = string.match(stdout, "(%d%d)%%") icon.image = PAUSE_ICON_NAME widget.colors = { beautiful.widget_main_color } widget.value = tonumber(mpdpercent/100) else icon.image = STOP_ICON_NAME - widget.colors = { beautiful.widget_red } + widget.value = 1 + --widget.colors = { beautiful.widget_red } end end From ec894674e8899d26b6b7458c498400d93d06f8be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Fournier-S=27niehotta?= Date: Thu, 30 Aug 2018 13:38:31 +0200 Subject: [PATCH 8/8] changing mouse button actions --- mpdarc-widget/mpdarc.lua | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/mpdarc-widget/mpdarc.lua b/mpdarc-widget/mpdarc.lua index 8e1b729f..ce0f8d1d 100644 --- a/mpdarc-widget/mpdarc.lua +++ b/mpdarc-widget/mpdarc.lua @@ -1,6 +1,8 @@ ------------------------------------------------- -- mpd Arc Widget for Awesome Window Manager +-- -- Modelled after Pavel Makhov's work +-- See his github repo: https://github.com/streetturtle/awesome-wm-widgets/ -- @author Raphaël Fournier-S'niehotta -- @copyright 2018 Raphaël Fournier-S'niehotta @@ -14,9 +16,13 @@ local wibox = require("wibox") local naughty = require("naughty") local GET_MPD_CMD = "mpc status" -local PAUSE_MPD_CMD = "mpc pause" +local TOGGLE_MPD_CMD = "mpc toggle" local START_MPD_CMD = "mpc play" +local PAUSE_MPD_CMD = "mpc pause" local STOP_MPD_CMD = "mpc stop" +local PREV_MPD_CMD = "mpc prev" +local NEXT_MPD_CMD = "mpc next" +local MPDCLIENT_CMD = "sonata" --local PATH_TO_ICONS = "/usr/share/icons/Arc/actions/24/player_" local PATH_TO_ICONS = "/home/raph/.config/awesome/themes/myzenburn/" @@ -54,16 +60,15 @@ local mpdarc_widget = wibox.container.mirror(mpdarc, { horizontal = true }) local update_graphic = function(widget, stdout, _, _, _) stdout = string.gsub(stdout, "\n", "") local mpdstatus = string.match(stdout, "%[(%a+)%]") + local mpdpercent = string.match(stdout, "(%d?%d)%%") if mpdstatus == "playing" then - local mpdpercent = string.match(stdout, "(%d%d)%%") icon.image = PLAY_ICON_NAME widget.colors = { beautiful.widget_main_color } widget.value = tonumber((100-mpdpercent)/100) elseif mpdstatus == "paused" then - local mpdpercent = string.match(stdout, "(%d%d)%%") icon.image = PAUSE_ICON_NAME widget.colors = { beautiful.widget_main_color } - widget.value = tonumber(mpdpercent/100) + widget.value = tonumber((100-mpdpercent)/100) else icon.image = STOP_ICON_NAME widget.value = 1 @@ -72,11 +77,11 @@ local update_graphic = function(widget, stdout, _, _, _) end mpdarc:connect_signal("button::press", function(_, _, _, button) - if (button == 1) then awful.spawn("mpc toggle", false) -- left click - elseif (button == 2) then awful.spawn("mpc stop", false) - elseif (button == 3) then awful.spawn("mpc pause", false) - elseif (button == 4) then awful.spawn("mpc next", false) -- scroll up - elseif (button == 5) then awful.spawn("mpc prev", false) -- scroll down + if (button == 1) then awful.spawn(TOGGLE_MPD_CMD, false) -- left click + elseif (button == 2) then awful.spawn(MPDCLIENT_CMD, false) -- middle click + elseif (button == 3) then awful.spawn(STOP_MPD_CMD, false) + elseif (button == 4) then awful.spawn(NEXT_MPD_CMD, false) -- scroll up + elseif (button == 5) then awful.spawn(PREV_MPD_CMD, false) -- scroll down end spawn.easy_async(GET_MPD_CMD, function(stdout, stderr, exitreason, exitcode)