46 lines
1.3 KiB
Lua
46 lines
1.3 KiB
Lua
-- This source code form is subject to the terms of the MPL-v2 https://mozilla.org/MPL/2.0/ --
|
|
-- (re)loads the config file and stores settings
|
|
local X = require("x")
|
|
local Conf = {}
|
|
|
|
function Conf.onKeyPress(key, mod, cb)
|
|
if type(key) ~= "string" or type(mod) ~= "number" or type(cb) ~= "function" then
|
|
error("Parameters are wrong")
|
|
end
|
|
local n, err = X.grabKey(key, mod)
|
|
assert(not err, err)
|
|
local id = key..mod
|
|
if Conf.keyPressHandlers[id] then
|
|
error(string.format("Key %s with mod %i already bound", key, mod))
|
|
end
|
|
Conf.keyPressHandlers[id] = cb
|
|
end
|
|
|
|
function Conf.on(t, cb)
|
|
Conf.eventHandlers[t] = cb
|
|
end
|
|
|
|
function Conf.init(path)
|
|
Conf.keyPressHandlers = {}
|
|
Conf.keyReleaseHandlers = {}
|
|
Conf.eventHandlers = {}
|
|
path = path or Conf.cmdArgs.config or (os.getenv("XDG_CONFIG_HOME") or (os.getenv("HOME").."/.config")).."/thornWM/config.lua"
|
|
local func = loadfile(path)
|
|
if func then
|
|
local s, err = pcall(func)
|
|
if s then
|
|
return
|
|
end
|
|
print(string.format("Config %s failed:%s", path, err))
|
|
os.exit(1)
|
|
else
|
|
print(string.format("Config %s not found", path))
|
|
end
|
|
local s, err = pcall((os.getenv("XDG_CONFIG_DIRS") or "/etc/xdg") .. "thornWM/config.lua")
|
|
if not s then
|
|
print(string.format("Config %s failed:%s", path, err))
|
|
os.exit(1)
|
|
end
|
|
end
|
|
|
|
return Conf
|