sourcegit icon indicating copy to clipboard operation
sourcegit copied to clipboard

Swallows shotcut keys on MacOSX.

Open wl2776 opened this issue 1 year ago • 4 comments

On MacOSX I have configured a hotkey Ctrl-<backtick> (the key above Control on the embedded keyboard or the key below Esc on Windows kbd) to run an AppleScript in the Automator application. That script launches the Terminal application or brings it to front if it is already running.

The issue: when SourceGit's window has focus, this shortcut does not work, Terminal window doesn't appear. Also, I don't see a rotating gear icon in the menu bar indicating that the Automator is performing its action.

When another application has focus (Visual Studio Code, or Safari or Calendar, ...), the rotating gear shows, then the terminal window shows up, when I press Ctrl+backtick.

Probably, the issue is that on first usage of the shortcut, these applications request permissions to access other applications' data. SourceGit doesn't ask for these permissions.

Details: HW: Macbook Pro M1, Apple silicon (ARM chip). OS: MacOSX Sonoma 14.7.1 Sourcegit is installed from released package, downloaded from Github

Unfortunately, I have limited capabilities to track down this issue on Macbook, because I cannot build it from sources.

wl2776 avatar Dec 23 '24 09:12 wl2776

SourceGit does not use this hotkey. And I can use Ctrl+<backtick> to trigger PixPin (a screenshot app, it use Ctrl+<backtick> to switch captured screenshots) while focusing on SourceGit

love-linger avatar Dec 23 '24 09:12 love-linger

I believe, the issue is somewhere in the Launcher.OnKeyDown method.

Could you check it?

To reproduce

  1. Open Automator or Shortcuts
  2. Create new action opening Terminal application (stock Terminal.app, not iTerm2 or any other terminals)
  3. Bind that action to some hotkey.

wl2776 avatar Jan 05 '25 16:01 wl2776

I believe, the issue is somewhere in the Launcher.OnKeyDown method.

image

  • At line 113, SourceGit just cleans the _unhandledModifiers
  • From line 116 to 120, the code is only works on Windows and Linux platforms.
  • From line 123 to 215, the code requires key on macOS, not Ctrl
  • From line 216 to 230, SourceGit will not handle the key <backtick>
  • At line 232, we just fallback to the Window.OnKeyDown
  • After the line 235, if this key down event has not been handled, SourceGit just records the key modifiers, and leave this event unhandled.

BTW. as I said above, on my MacBook Pro (M3 Max), I can confirm the Ctrl+<backtick> works (will trigger another app) no matter which control was focused in SourceGit

love-linger avatar Jan 06 '25 01:01 love-linger

Thank you for this detailed analysis.

on my MacBook Pro (M3 Max), I can confirm the Ctrl+<backtick> works (will trigger another app)

Do you mean that you have tried Automator.app or Shortcuts.app? I thought there could be several methods to install global shortcut handler in MacOS. Unfortunately, I have zero experience in programming for MacOS and cannot be sure.

On my macbook (M1 Pro, macos Sonoma 14.7.2) I have two more programs, that handle Ctrl-backtick shortcut: Far2l and Visual Studio Code. When Far2l has focus, it handles Ctrl-backtick and prevents the Automator from opening Terminal. When VSCode has focus, it doesn't do anything, and Terminal opens.

I thought you could run SourceGit under debugger and see how it works on MacOS

Unfortunately, I have very limited capabilities to debug the code. My macbook is a corporate PC, controlled by the cybersecurity department and I am not allowed to install arbitrary software on it.

wl2776 avatar Jan 06 '25 14:01 wl2776