repositories / dotfiles
dotfiles
bugabingas dorkfiles
owned by bugabinga
hypr/modules/hypr_osd.lua
RawFile outline
local nugu = require("generated.nugu")
local t = nugu.current()
local M = {}
local function squote(value)
return "'" .. tostring(value):gsub("'", "'\"'\"'") .. "'"
end
local function dquote(value)
return '"' .. tostring(value):gsub('\\', '\\\\'):gsub('"', '\\"') .. '"'
end
local function notify(icon, ms, color, message)
return table.concat({
"hyprctl notify",
tostring(icon),
tostring(ms),
squote(nugu.rgb(color)),
squote(message),
}, " ")
end
local function notify_live(icon, ms, color, message)
return table.concat({
"hyprctl notify",
tostring(icon),
tostring(ms),
squote(nugu.rgb(color)),
dquote(message),
}, " ")
end
local function sh(command)
return "bash -lc " .. squote(command)
end
local function after(command, notice)
return sh(command .. " && " .. notice)
end
local function around(command, notice)
return sh(command .. "; " .. notice)
end
local ok = 5
local info = 1
local hint = 2
M.session = {
reload = after("hyprctl reload", notify(ok, 1200, t.ui.accent, "Hyprland reloaded")),
lock = around(notify(info, 900, t.ui.focus, "Locking"), "hyprlock"),
suspend = around(notify(info, 900, t.ui.focus, "Suspending"), "loginctl lock-session && systemctl suspend"),
}
M.notifications = {
clear_all = sh("makoctl dismiss --all; hyprctl dismissnotify"),
}
M.capture = {
region = function(command)
return after(command, notify(ok, 1400, t.ui.accent, "Region captured"))
end,
window = function(command)
return after(command, notify(ok, 1400, t.ui.accent, "Window captured"))
end,
output = function(command)
return after(command, notify(ok, 1400, t.ui.accent, "Output captured"))
end,
annotate = function(command)
return after(command, notify(ok, 1400, t.ui.accent, "Screenshot annotated"))
end,
color = function(command)
return after(command, notify(ok, 1200, t.ui.accent, "Color copied"))
end,
}
M.controls = {
volume_up = around(
"wpctl set-volume -l 1 @DEFAULT_AUDIO_SINK@ 2%+; "
.. "level=$(wpctl get-volume @DEFAULT_AUDIO_SINK@ | sed 's/^Volume: //')",
notify_live(info, 700, t.ui.focus, "Volume $level")
),
volume_down = around(
"wpctl set-volume @DEFAULT_AUDIO_SINK@ 2%-; "
.. "level=$(wpctl get-volume @DEFAULT_AUDIO_SINK@ | sed 's/^Volume: //')",
notify_live(info, 700, t.ui.focus, "Volume $level")
),
mute = around(
"wpctl set-mute @DEFAULT_AUDIO_SINK@ toggle; "
.. "state=$(wpctl get-volume @DEFAULT_AUDIO_SINK@ | "
.. "grep -q '\\[MUTED\\]' && echo muted || echo live)",
notify_live(info, 900, t.ui.focus, "Audio $state")
),
mic_mute = around(
"wpctl set-mute @DEFAULT_AUDIO_SOURCE@ toggle; "
.. "state=$(wpctl get-volume @DEFAULT_AUDIO_SOURCE@ | "
.. "grep -q '\\[MUTED\\]' && echo muted || echo live)",
notify_live(info, 900, t.ui.focus, "Mic $state")
),
brightness_up = around(
"brightnessctl -e4 -n2 set 5%+; level=$(brightnessctl -m | awk -F, '{print $4}')",
notify_live(hint, 700, t.warning, "Brightness $level")
),
brightness_down = around(
"brightnessctl -e4 -n2 set 5%-; level=$(brightnessctl -m | awk -F, '{print $4}')",
notify_live(hint, 700, t.warning, "Brightness $level")
),
media_next = after("playerctl next", notify(info, 900, t.info, "Next track")),
media_toggle = after("playerctl play-pause", notify(info, 900, t.info, "Play/pause")),
media_prev = after("playerctl previous", notify(info, 900, t.info, "Previous track")),
}
return M