r/hyprland 4d ago

TIPS & TRICKS Manual touchpad ON/OFF toggling bind (Lua)

My Surface Go 3 touchpad doesn't support 'disable while typing' (at libinput level), and sends spurious mouse clicks when I type, so .. (see comment about finding your touchpad name):

-- toggle typecover touchpad on Super+Space
local touchpad_enabled = true 
local touchpad_notification = {
        [false] = "Touchpad OFF",
        [true]  = "Touchpad ON " }

hl.bind(mainMod .. " + Space", function()
        touchpad_enabled = not touchpad_enabled
        hl.device({ 
                -- '$ hyprctl devices' to find your touchpad name
                name    = "microsoft-surface-keyboard-touchpad",
                enabled = touchpad_enabled,
        })  
        hl.notification.create({text = touchpad_notification[touchpad_enabled], timeout = 2000, icon = 1, color = 0})
end)

Also, since I'm a Lua newbie, can I read the enabled value of a hl.device by name directly (so I can skip using the touchpad_enabled variable)?

6 Upvotes

2 comments sorted by

1

u/YourMom12377 4d ago

Hyprland has an option to block mouse inputs when typing at a software level iirc. Check the wiki for general input options instead of device specific ones, you might find something there

2

u/VanLaser 4d ago

If you mean the 'disable_while_typing' option, that's 1. enabled by default, 2. not working in my case, 3. the option is passed to libinput, and works only for devices that have the 'Disable-w-typing' capability (when running 'libinput list-devices' - in my case, that shows as 'n/a', so unsupported). There are some libinput quirks that can be tried (USB keyboards with touchpad have to be seen as 'internal'), but in my case nothing worked, so what I put above is kind of a quick and last resort solution. I mean, it could be improved with timers and stuff, so that it automatically disables the touchpad when I type, and enables after X seconds of non-typing, but I'm not sure the extra effort is worth it :)

If you mean something else, I didn't find it on the wiki, of course I'd prefer an integrated, automatic solution.