diff --git a/batteryarc-widget/batteryarc.lua b/batteryarc-widget/batteryarc.lua index e1ab203f..cadd91d3 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,45 @@ 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 + 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 - text.text = charge + + if charge == 100 then + --text.text = string.format("%03d", charge) + text.text = "OK" + text.font = "Play 10" + else + text.text = charge + text.font = "Play 12" + end end, batteryarc) @@ -110,4 +124,4 @@ function show_battery_warning() } end -return batteryarc_widget \ No newline at end of file +return batteryarc_widget diff --git a/mpdarc-widget/mpdarc.lua b/mpdarc-widget/mpdarc.lua new file mode 100644 index 00000000..ce0f8d1d --- /dev/null +++ b/mpdarc-widget/mpdarc.lua @@ -0,0 +1,111 @@ +------------------------------------------------- +-- 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 +------------------------------------------------- + +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 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/" + +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", + 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 mpdstatus = string.match(stdout, "%[(%a+)%]") + local mpdpercent = string.match(stdout, "(%d?%d)%%") + 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((100-mpdpercent)/100) + else + icon.image = STOP_ICON_NAME + widget.value = 1 + --widget.colors = { beautiful.widget_red } + end +end + +mpdarc:connect_signal("button::press", function(_, _, _, button) + 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) + 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 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 diff --git a/volumearc-widget/volumearc.lua b/volumearc-widget/volumearc.lua index c2c0af96..f215b69c 100644 --- a/volumearc-widget/volumearc.lua +++ b/volumearc-widget/volumearc.lua @@ -15,27 +15,51 @@ 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 bash -c "alsamixer -c0"' + +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, + thickness = 2, + forced_height = 32, + forced_width = 32, + rounded_edge = true, bg = "#ffffff11", - paddings = 2, + paddings = 4, 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, _, _, _) 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 +67,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 +89,4 @@ end) watch(GET_VOLUME_CMD, 1, update_graphic, volumearc) -return volumearc_widget \ No newline at end of file +return volumearc_widget