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