40 lines
1.1 KiB
Lua
40 lines
1.1 KiB
Lua
-- This source code form is subject to the terms of the MPL-v2 https://mozilla.org/MPL/2.0/ --
|
|
-- Event handling
|
|
local X = require("x")
|
|
local Conf = require("conf")
|
|
local Tree = require("tree")
|
|
local Event = {}
|
|
|
|
local xEventHandlers = {}
|
|
xEventHandlers[X.MapRequest] = function(ev)
|
|
if Tree.windows[ev.id] then return print("got duplicate map request") end
|
|
local win = Tree.newWindow(ev)
|
|
local handler = Conf.eventHandlers.newWindow
|
|
if handler and win then handler(win) end
|
|
end
|
|
xEventHandlers[X.DestroyNotify] = function(ev)
|
|
local win = Tree.windows[ev.id]
|
|
local handler = Conf.eventHandlers.delWindow
|
|
if handler and win then handler(win) end
|
|
if win then
|
|
win:unmanage()
|
|
end
|
|
end
|
|
xEventHandlers[X.KeyPress] = function(ev)
|
|
local handler = Conf.keyPressHandlers[ev.key..ev.mask]
|
|
if handler then handler(ev) end
|
|
end
|
|
|
|
function Event.handleXEvents()
|
|
while X.pending() > 0 do
|
|
local ev = X.nextEvent()
|
|
if xEventHandlers[ev.type] then
|
|
xEventHandlers[ev.type](ev)
|
|
end
|
|
if Conf.eventHandlers[ev.type] then
|
|
pcall(Conf.eventHandlers[ev.type], ev)
|
|
end
|
|
end
|
|
end
|
|
|
|
return Event
|