Add global hotkeys for toggling MiddleDrag and menu bar visibility#121
Add global hotkeys for toggling MiddleDrag and menu bar visibility#121NullPointerDepressiveDisorder merged 8 commits intomainfrom
Conversation
- Implemented global hotkey ⌘⇧E to toggle MiddleDrag functionality. - Implemented global hotkey ⌘⇧M to toggle the visibility of the menu bar icon. - Updated MenuBarController to handle menu bar icon visibility and added corresponding menu item. This enhances user accessibility and control over the application features.
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
Pull request overview
Adds global keyboard shortcuts to control MiddleDrag and the app’s menu bar presence, improving accessibility for power users.
Changes:
- Introduces a Carbon-based
GlobalHotKeyManagerfor system-wide hotkey registration. - Registers ⌘⇧E (toggle MiddleDrag) and ⌘⇧M (toggle menu bar icon visibility) during app initialization.
- Extends
MenuBarControllerwith menu bar icon visibility controls and adds a corresponding menu item.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| MiddleDrag/Utilities/GlobalHotKeyManager.swift | New shared manager that registers/unregisters system-wide hotkeys and dispatches handlers to the main thread. |
| MiddleDrag/UI/MenuBarController.swift | Adds menu item + logic to hide/show the status item and a public API to toggle visibility (for the global hotkey). |
| MiddleDrag/AppDelegate.swift | Registers the new global hotkeys and connects them to MenuBarController actions. |
| MiddleDrag.xcodeproj/project.pbxproj | Adds the new utility file to the project and updates folder-sync exception lists. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Hey, thanks for working on this feature! My menu bar is very full so I'd also like to be able to hide MiddleClick.
However, I use Cmd+Shift+E and Cmd+Shift+M all the time in my IDE, so I wouldn't want to have MiddleDrag override them.
I get wanting a hotkey to toggle MiddleDrag, but do we really need a hotkey to toggle the visibility?
I think the easiest way would be to:
- to hide it, click the menu item
- to show it again, open MiddleClick from spotlight
For context, this is how Rectangle does it:

It would be ideal if the shortcut was configurable, but I'm well aware that requires more time and effort.
@filippo-orru Love the active feedback, thanks a bunch! I will make spotlight work as well as allow for hotkey rebinding. |
- Added a new HotKeyRecorderView for capturing user-defined hotkey combinations. - Updated UserPreferences to include customizable hotkey bindings for toggling MiddleDrag and menu bar visibility. - Enhanced MenuBarController to allow users to change hotkeys via the menu. - Refactored hotkey registration logic in AppDelegate to support dynamic updates based on user preferences. This improves user experience by providing flexibility in hotkey configuration.
- Implemented applicationShouldHandleReopen in AppDelegate to toggle menu bar visibility when the application is reopened. - Updated the menu item text in MenuBarController to clarify the method for restoring the menu bar icon. These changes enhance user interaction with the application and improve clarity in the menu options.
- Added a deinitializer in HotKeyRecorderView to ensure the local keyboard monitor is removed when the instance is deallocated. - Introduced a cancelRecording method to stop any ongoing recording and clean up the keyboard monitor. - Updated MenuBarController to call cancelRecording when an alert is dismissed, ensuring no leaked monitors occur. These changes enhance memory safety and improve the user experience by preventing potential issues with lingering keyboard monitors.
…ionality - Updated MultitouchManager and related tests to ensure safe memory handling with the introduction of 'unsafe' keyword in critical areas. - Enhanced AlertHelperTests and SystemGestureHelperTests to utilize 'unsafe' settings provider for better test isolation. - Added new tests for GlobalHotKeyManager and HotKeyRecorderView to validate hotkey registration and recording functionality. - Improved MenuBarController tests to ensure menu bar visibility toggling works as expected. These changes enhance the robustness of multitouch and hotkey functionalities while ensuring better test coverage.
- Updated AppDelegate to call showMenuBarIcon instead of toggleMenuBarVisibility for improved clarity. - Added new tests for MenuBarController to verify the behavior of showMenuBarIcon under various conditions. - Enhanced GlobalHotKeyManagerTests and HotKeyRecorderViewTests with additional test cases for better coverage and validation of hotkey functionality. These changes improve the robustness of menu bar interactions and ensure comprehensive testing of hotkey features.
- Added a check to prevent the button click action in MenuBarController when running tests, avoiding modal menu loops that can stall CI processes. This change improves test reliability and ensures smoother continuous integration workflows.
- Updated hotkey binding closures in MenuBarController to use guard statements for safer self-referencing. - This change enhances memory safety by preventing potential retain cycles and ensures smoother execution of hotkey updates. These improvements contribute to the overall robustness of the menu bar functionality.

This enhances user accessibility and control over the application features.
Type of Change
Related Issues
Testing Performed
Checklist
Code Coverage
Screenshots / Recordings
Additional Notes