mirror of
https://gitlab.freedesktop.org/libinput/libinput.git
synced 2025-12-20 02:10:07 +01:00
plugins: add an example for using a wheel to trigger button scrolling
See https://gitlab.freedesktop.org/libinput/libinput/-/issues/1206 Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1356>
This commit is contained in:
parent
b870abd2f3
commit
941aa9f997
2 changed files with 65 additions and 0 deletions
64
plugins/10-wheel-to-button.lua
Normal file
64
plugins/10-wheel-to-button.lua
Normal file
|
|
@ -0,0 +1,64 @@
|
||||||
|
-- SPDX-License-Identifier: MIT
|
||||||
|
--
|
||||||
|
-- This is an example libinput plugin
|
||||||
|
--
|
||||||
|
-- This plugin maps a downwards mouse wheel to a button down event and
|
||||||
|
-- an upwards wheel movement to a button up event.
|
||||||
|
|
||||||
|
-- UNCOMMENT THIS LINE TO ACTIVATE THE PLUGIN
|
||||||
|
-- libinput:register({1})
|
||||||
|
|
||||||
|
-- The button we want to press on wheel events
|
||||||
|
local wheel_button = evdev.BTN_EXTRA
|
||||||
|
local button_states = {}
|
||||||
|
|
||||||
|
local function evdev_frame(device, frame, timestamp)
|
||||||
|
local events = {}
|
||||||
|
local modified = false
|
||||||
|
|
||||||
|
for _, v in ipairs(frame) do
|
||||||
|
if v.usage == evdev.REL_WHEEL then
|
||||||
|
-- REL_WHEEL is inverted, neg value -> down, pos value -> up
|
||||||
|
if v.value < 0 then
|
||||||
|
if not button_states[device] then
|
||||||
|
table.insert(events, { usage = wheel_button, value = 1 })
|
||||||
|
button_states[device] = true
|
||||||
|
end
|
||||||
|
else
|
||||||
|
if button_states[device] then
|
||||||
|
table.insert(events, { usage = wheel_button, value = 0 })
|
||||||
|
button_states[device] = false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
modified = true
|
||||||
|
-- Because REL_WHEEL is no longer a wheel, the high-res
|
||||||
|
-- events are dropped
|
||||||
|
elseif v.usage == evdev.REL_WHEEL_HI_RES then
|
||||||
|
modified = true
|
||||||
|
else
|
||||||
|
table.insert(events, v)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if modified then
|
||||||
|
return events
|
||||||
|
else
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function device_new(device)
|
||||||
|
local usages = device:usages()
|
||||||
|
if usages[evdev.REL_WHEEL] then
|
||||||
|
button_states[device] = false
|
||||||
|
if not usages[wheel_button] then
|
||||||
|
device:enable_evdev_usage(wheel_button)
|
||||||
|
end
|
||||||
|
device:connect("evdev-frame", evdev_frame)
|
||||||
|
device:connect("device-removed", function(dev)
|
||||||
|
button_states[dev] = nil
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
libinput:connect("new-evdev-device", device_new)
|
||||||
|
|
@ -7,6 +7,7 @@ plugins = [
|
||||||
'10-delay-motion.lua',
|
'10-delay-motion.lua',
|
||||||
'10-disable-feature.lua',
|
'10-disable-feature.lua',
|
||||||
'10-copilot-key-override.lua',
|
'10-copilot-key-override.lua',
|
||||||
|
'10-wheel-to-button.lua',
|
||||||
]
|
]
|
||||||
|
|
||||||
fs = import('fs')
|
fs = import('fs')
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue