Skip to content

Add global hotkeys for toggling MiddleDrag and menu bar visibility#121

Merged
NullPointerDepressiveDisorder merged 8 commits intomainfrom
feature/hide-icon
Mar 20, 2026
Merged

Add global hotkeys for toggling MiddleDrag and menu bar visibility#121
NullPointerDepressiveDisorder merged 8 commits intomainfrom
feature/hide-icon

Conversation

@NullPointerDepressiveDisorder
Copy link
Owner

@NullPointerDepressiveDisorder NullPointerDepressiveDisorder commented Mar 19, 2026

  • 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.

Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)
  • ✨ New feature (non-breaking change that adds functionality)
  • 💥 Breaking change (fix or feature that would cause existing functionality to change)
  • 📚 Documentation update
  • 🔧 Refactor (code change that neither fixes a bug nor adds a feature)
  • 🧪 Test improvement

Related Issues

Testing Performed

  • Tested with built-in trackpad
  • Tested with Magic Trackpad (if available)
  • Verified system gestures (Mission Control, etc.) still work
  • Tested in target apps (list any specific apps tested):

Checklist

  • My code follows the project's code style guidelines
  • I have tested my changes thoroughly
  • I have added comments for non-obvious logic
  • My changes don't break existing functionality
  • I have updated documentation if needed

Code Coverage

  • I have added tests for new functionality (where applicable)
  • My changes meet the 80% patch coverage requirement

Note: Codecov will automatically check patch coverage. PRs that don't meet the 80% threshold will fail the coverage check. Files in MiddleDragTests/, AppDelegate.swift, MiddleDragApp.swift, and UpdateManager.swift are excluded from coverage requirements.

Screenshots / Recordings

Additional Notes

- 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.
@NullPointerDepressiveDisorder NullPointerDepressiveDisorder linked an issue Mar 19, 2026 that may be closed by this pull request
Copilot AI review requested due to automatic review settings March 19, 2026 07:21
@sentry
Copy link
Contributor

sentry bot commented Mar 19, 2026

Codecov Report

❌ Patch coverage is 55.37634% with 166 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
MiddleDrag/Models/GestureModels.swift 28.08% 64 Missing ⚠️
MiddleDrag/UI/MenuBarController.swift 49.48% 49 Missing ⚠️
MiddleDrag/Utilities/GlobalHotKeyManager.swift 69.47% 29 Missing ⚠️
MiddleDrag/UI/HotKeyRecorderView.swift 65.71% 24 Missing ⚠️

📢 Thoughts on this report? Let us know!

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 GlobalHotKeyManager for system-wide hotkey registration.
  • Registers ⌘⇧E (toggle MiddleDrag) and ⌘⇧M (toggle menu bar icon visibility) during app initialization.
  • Extends MenuBarController with 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.

Copy link

@filippo-orru filippo-orru left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:
image

It would be ideal if the shortcut was configurable, but I'm well aware that requires more time and effort.

@NullPointerDepressiveDisorder
Copy link
Owner Author

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: image

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.
@NullPointerDepressiveDisorder NullPointerDepressiveDisorder merged commit c3bbf22 into main Mar 20, 2026
6 checks passed
@NullPointerDepressiveDisorder NullPointerDepressiveDisorder deleted the feature/hide-icon branch March 20, 2026 01:55
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.

Hide Menu Bar icon

3 participants