init
This commit is contained in:
commit
d2743fe41d
22 changed files with 2290 additions and 0 deletions
46
lib/conf.lua
Normal file
46
lib/conf.lua
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
-- 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
|
||||
Loading…
Add table
Add a link
Reference in a new issue