Skip to content

Commit

Permalink
Handle canceled singal
Browse files Browse the repository at this point in the history
  • Loading branch information
natural-harmonia-gropius committed Jun 7, 2024
1 parent ef1cda5 commit a8df734
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions inputevent.lua
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,6 @@ function table:filter(filter)
return nt
end

function table:remove(element)
return table.filter(self, function(i, v) return v ~= element end)
end

function table:join(separator)
local result = ""
for i, v in ipairs(self) do
Expand Down Expand Up @@ -280,6 +276,16 @@ function InputEvent:handler(event)
end
end

if event == "cancel" then
if #self.queue == 0 then
self:emit("release")
return
end

table.remove(self.queue)
return
end

self.queue = table.push(self.queue, event)
self.exec_debounced()
end
Expand Down Expand Up @@ -314,7 +320,10 @@ end

function InputEvent:bind()
self.exec_debounced = debounce(function() self:exec() end, self.duration)
mp.add_forced_key_binding(self.key, self.key, function(e) self:handler(e.event) end, { complex = true })
mp.add_forced_key_binding(self.key, self.key, function(e)
local event = e.canceled and "cancel" or e.event
self:handler(event)
end, { complex = true })
end

function InputEvent:unbind()
Expand Down

0 comments on commit a8df734

Please # to comment.