80 lines
1.6 KiB
Lua
80 lines
1.6 KiB
Lua
---@enum Modifiers
|
|
local modifiers = {
|
|
super = "Super ",
|
|
ctrl = "Control ",
|
|
shift = "Shift ",
|
|
alt = "Alt ",
|
|
|
|
super_shift = "Super+Shift ",
|
|
super_ctrl = "Super+Control ",
|
|
super_ctrl_shift = "Super+Control+Shift ",
|
|
|
|
ctrl_shift = "Control+Shift ",
|
|
|
|
none = "None ",
|
|
}
|
|
|
|
|
|
--- Wrapper around the riverctl cmd
|
|
---@class River
|
|
local River = {
|
|
cmds = {
|
|
background = "swaybg -i %s"
|
|
},
|
|
keys = {
|
|
modifiers = modifiers
|
|
}
|
|
}
|
|
|
|
River.__index = River
|
|
|
|
--- River class constructor
|
|
---@param new? River to override properties
|
|
---@return River
|
|
function River:new(new)
|
|
local obj = new or {}
|
|
|
|
setmetatable(obj, self)
|
|
self.__index = self
|
|
|
|
return obj
|
|
end
|
|
|
|
--- Exec an arbitrary system command
|
|
---@param cmd string the command to execute
|
|
---@private
|
|
---@return string?
|
|
function River:exec(cmd)
|
|
os.execute(cmd)
|
|
end
|
|
|
|
--- Execute the given command with riverctl spawn
|
|
---@param cmd string the command to execute
|
|
function River:spawn(cmd)
|
|
self:exec(string.format([[riverctl spawn "%s"]], cmd))
|
|
end
|
|
|
|
--- Set a new wallpaper with the default cmds.background
|
|
---@param path string The path to the image
|
|
function River:set_bg(path)
|
|
self:spawn(string.format(self.cmds.background, path))
|
|
end
|
|
|
|
---@class MapArgs
|
|
---@field [1] Modifiers The modifier to use
|
|
---@field [2] string
|
|
---@field [3] string
|
|
---@field mode? ("normal"|"locked")[], }
|
|
|
|
--- Create a new mapping
|
|
--- @param args MapArgs
|
|
function River:map(args)
|
|
local modes = args.mode or { "normal" }
|
|
|
|
for _, mode in ipairs(modes) do
|
|
local map = string.format([[riverctl map %s %s %s %s]], mode, args[1], args[2], args[3])
|
|
self:exec(map)
|
|
end
|
|
end
|
|
|
|
return River
|