Skip to content

libinput: install lua plugin examples w/ vsconf - #62481

Merged
Duncaen merged 1 commit into
void-linux:masterfrom
dogknowsnx:libinput
Sep 12, 2026
Merged

libinput: install lua plugin examples w/ vsconf#62481
Duncaen merged 1 commit into
void-linux:masterfrom
dogknowsnx:libinput

Conversation

@dogknowsnx

@dogknowsnx dogknowsnx commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

Testing the changes

  • I tested the changes in this PR: YES

Local build testing

  • I built this PR locally for my native architecture, x86_64-glibc

Example plugin examples:

10-logitech-mx-master-horiz-scroll.lua
-- SPDX-License-Identifier: MIT
--
-- This plugin inverts the horizontal scroll direction of
-- the Logitech MX Master mouse. OOTB the mouse scrolls
-- in the opposite direction to all other mice out there.
--
-- This plugin is only needed when the mouse is connected
-- to the Logitech Bolt receiver - on that receiver we cannot
-- tell which device is connected.
--
-- For the Logitech Unifying receiver and Bluetooth please
-- add the ModelInvertHorizontalScrolling=1 quirk
-- in quirks/30-vendor-logitech.quirks.
--
--
-- Install this file in /etc/libinput/plugins and
--
-- UNCOMMENT THIS LINE TO ACTIVATE THE PLUGIN
-- libinput:register({1})
libinput:connect("new-evdev-device", function (device)
    local info = device:info()
    if info.vid == 0x046D and info.pid == 0xC548 then
        device:connect("evdev-frame", function (device, frame, timestamp)
            for _, event in ipairs(frame) do
                if event.usage == evdev.REL_HWHEEL or event.usage == evdev.REL_HWHEEL_HI_RES then
                    event.value = -event.value
                end
            end
            return frame
        end)
    end
end)
10-wheel-to-button.lua
-- 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)

Installing them directly into /etc/libinput/plugins instead, would produce the same error messages, obviously

Avoids (harmless) error messages from compositors which autoload plugins
@Duncaen
Duncaen merged commit 81ea48a into void-linux:master Sep 12, 2026
8 checks passed
@dogknowsnx
dogknowsnx deleted the libinput branch September 12, 2026 17:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants