diff options
| author | Craig Jennings <c@cjennings.net> | 2025-11-13 23:40:50 -0600 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2025-11-13 23:40:50 -0600 |
| commit | ce58581c4a8cc00054e063d4bbf4fbbaeb0a7b35 (patch) | |
| tree | 20d086d83fb24773c3eec65c5e9255d056ea91ef | |
| parent | bd0ea189aa0751a6c342c7a0b8a6f5265090388e (diff) | |
feat(mousetrap): Add configurable mouse wheel scrolling
Added `mouse-trap-enable-scrolling` variable to allow mouse wheel
scrolling while still blocking clicks and drags. Defaults to enabled
for better usability - users can still scroll with mouse/trackpad
but accidental clicks are prevented.
- Added defvar mouse-trap-enable-scrolling (default: t)
- Conditionally bind wheel events based on variable
- Updated docstrings to reflect new behavior
- Works for both mouse wheel and trackpad two-finger scrolling
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
| -rw-r--r-- | modules/mousetrap-mode.el | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/modules/mousetrap-mode.el b/modules/mousetrap-mode.el index 76c08c79..f31acbf8 100644 --- a/modules/mousetrap-mode.el +++ b/modules/mousetrap-mode.el @@ -16,6 +16,10 @@ ;; ------------------------------ Mouse Trap Mode ------------------------------ +(defvar mouse-trap-enable-scrolling t + "When non-nil, allow mouse wheel scrolling in `mouse-trap-mode'. +When nil, disable mouse wheel scrolling along with clicks and drags.") + (defvar mouse-trap-mode-map (let* ((prefixes '("" "C-" "M-" "S-" "C-M-" "C-S-" "M-S-" "C-M-S-")) ; modifiers (buttons (number-sequence 1 5)) ; mouse-1..5 @@ -28,21 +32,26 @@ (dolist (pref prefixes) (dolist (n buttons) (define-key map (kbd (format "<%s%s-%d>" pref type n)) #'ignore)))) - ;; wheel - (dolist (evt wheel) - (dolist (pref prefixes) - (define-key map (kbd (format "<%s%s>" pref evt)) #'ignore))) + ;; wheel (only disable if mouse-trap-enable-scrolling is nil) + (unless mouse-trap-enable-scrolling + (dolist (evt wheel) + (dolist (pref prefixes) + (define-key map (kbd (format "<%s%s>" pref evt)) #'ignore)))) map) - "Keymap for `mouse-trap-mode'. Unbinds almost every mouse event. + "Keymap for `mouse-trap-mode'. Unbinds almost every mouse event. -Disabling mouse prevents accidental mouse moves modifying text.") +Disabling mouse prevents accidental mouse moves modifying text. +Respects `mouse-trap-enable-scrolling' to optionally allow wheel scrolling.") (define-minor-mode mouse-trap-mode "Buffer-locally disable most mouse and trackpad events. When active, <mouse-*>, <down-mouse-*>, <drag-mouse-*>, -<double-mouse-*>, <triple-mouse-*>, and wheel events are bound to `ignore', -with or without C-, M-, S- modifiers." +<double-mouse-*>, and <triple-mouse-*> events are bound to `ignore', +with or without C-, M-, S- modifiers. + +Wheel scrolling is enabled by default, but can be disabled by +setting `mouse-trap-enable-scrolling' to nil before loading this file." :lighter " 🐭" :keymap mouse-trap-mode-map :group 'convenience) |
