Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mpdarc-widget #44

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
36 changes: 25 additions & 11 deletions batteryarc-widget/batteryarc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

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

Expand Down Expand Up @@ -110,4 +124,4 @@ function show_battery_warning()
}
end

return batteryarc_widget
return batteryarc_widget
111 changes: 111 additions & 0 deletions mpdarc-widget/mpdarc.lua
Original file line number Diff line number Diff line change
@@ -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
134 changes: 134 additions & 0 deletions pomodoroarc-widget/pomodoroarc.lua
Original file line number Diff line number Diff line change
@@ -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
Loading