Fully disable trackpad while typing, re-enable if/when changing window focus #1273
Replies: 3 comments 1 reply
-
|
I have a PR that adds this in an even better way than this script. We'll see if DHH and crew want to include it in the base or not, but if not I'll be making it something folks can install. If the goal is to support m1/m2 macbooks out of the box though, I really do think they need this feature. In hyprland with the window focus following the mouse, you just end up typing all over the place constantly. Check out the PR here: #2268 |
Beta Was this translation helpful? Give feedback.
-
|
Fantastic! |
Beta Was this translation helpful? Give feedback.
-
|
I found a way to solve this by creating: Reboot after adding. You can specify Match rules more using manufacturer/device IDs and such, if you don't want every keyboard regarded as internal - for that use:
Sources: Hyprland discussion about a similar problem: |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
This is an aggressive solution, but on my M1 MacBook Pro with its large trackpad, typing was extremely difficult due to poor palm rejection. The cursor would constantly jump around and change window focus, making the internal keyboard nearly unusable.
The
~/.config/hypr/input.confsetting ofdisable_while_typing = truein thetouchpadblock didn't work for me. This might be because I havekeydinstalled, which creates a virtual keyboard that could be interfering with Hyprland's hardware keyboard detection.This workaround isn't ideal since you have to wait for the cursor to unlock in some situations, but it's much better than the alternative. Without it, the trackpad interference made typing on the internal keyboard practically impossible - my cursor would constantly jump to other windows and disrupt my workflow. There's probably a better solution out there since this feels like overkill, but for now it makes the machine actually usable for typing.
Here's how it works - by default when typing, the cursor will not be able to move until the timeout that you define in the script has passed. 1.5 seconds has been what I've been testing with, but I may see if 1 second or even 0.5 seconds will be enough.
On boot the script will dynamically read what you have bound for window movement and cache those values. Then when you move the window focus via the keyboard, it will unlock the cursor immediately (even though you just pressed some keys) so you don't have to wait for the timeout penalty in those moving window cases.
The last hurdle for me is if/when I want to move the mouse or scroll in the same window that I'm already typing in, then I do have to wait until the timeout finishes to do so. Or when super + tabbing to another workspace, or alt + tabbing to another window, or when pressing ctrl + r to refresh a browser. So what I did is also cancel the timeout if any modifier is pressed alone, any arrow is pressed, or any chord is pressed. So you can press esc (or any other single modifier or chord) to get immediate mouse movement back. But when you're typing normally the cursor is locked in place and it works really well.
Here's the script you can put somewhere. I chose
~/.config/hypr/disable-trackpad-while-typing.shand then reference in your~/.config/hypr/autostart.conffile (shown at the end of this script).Reference the script in your
~/.config/hypr/autostart.conffile like soCaveats
I have passwordless sudo setup so that after I'm logged in I can run sudo commands without being prompted. That allows this script to start with the permissions it needs to enable/disable the trackpad while also executing some queries to the underlying hyprland instance via the currently running user. If there is a better way to do this, I'd love feedback.
Note
This was made with claude code, though it was iterated on and tested for several hours by me, a human programmer, to make work as well as possible. But run this at your own risk, I could have missed something, or maybe there's a one-liner that actually makes all of this totally unnecessary. Gosh, I hope so! 😂
Prerequisites / Setup Instructions:
Install dependencies:
Verify trackpad detection:
Test the script:
Add to autostart (already done in your case):
Configure passwordless sudo (recommended):
The script is quite lightweight - it mainly uses standard Linux tools. The key dependency is
evtestfor monitoring keyboard events andsocatfor Hyprland integration. Both are small packages available in most Linux distributions.Beta Was this translation helpful? Give feedback.
All reactions