TurboVNC / turbovnc

Main TurboVNC repository
https://TurboVNC.org
GNU General Public License v2.0
773 stars 139 forks source link

Allow for updating Mac Keyboard bindings #345

Closed hillier1 closed 1 year ago

hillier1 commented 1 year ago

The default keyboard action on a Mac for paste is Command-V. In the latest 3.0 versions this puts the vnc client into Read Only Mode. Working on a mac, even with the vnc server running on a linux environment, its very common to accidentally hit Command-V instead of Control-V. There currently is no indication that the client has been set to Read Only.

If there was an option to remap the Command-V or change it to not be the default for Read Only that would be great.

dcommander commented 1 year ago

Yeah, I have experienced that issue myself. Note that, if the toolbar is enabled in non-fullscreen mode, the toolbar provides visual feedback as to whether view-only mode is active. If view-only mode is active, then the toolbar will be missing the four buttons that control sending keystrokes.

I think it would probably be best to just remove the Command-V hotkey, as toggling view-only mode can already be accomplished using Ctrl-Alt-Shift-V.

shg commented 1 year ago

I am testing TurboVNC viewer on macOS. It works great but I too am having trouble with keyboard shortcuts. The problem is that in addition to unintentionally pressing standard Mac keystrokes, I can't find a way to send the keys used in the Viewer shortcuts to the remote machine. For example, what would be the standard way of sending Cmd-X to the remote?

I have tried setting up a dummy shortcut for each menu item in the macOS System Preferences Keyboard to disable the TurboVNC Viewer shortcut by overriding it. However, this did not work. The original key combination is still taken by the Viewer application and not sent to the remote.

Is there any way to work around this? For me, I would be most happy to disable all shortcuts of the Viewer app, as I don't need to use shortcuts to control the Viewer at all when I am working on the remote machine.

dcommander commented 1 year ago

Providing a way to disable the TurboVNC Viewer shortcuts on macOS is easy. However, there will still be certain keystrokes that macOS hijacks, and there isn't any way to transmit those without implementing keyboard grabbing for macOS clients, which is hard. The TurboVNC Viewer is primarily designed around the needs of the TurboVNC Server, which only runs on Linux, so the focus of the keyboard grabbing feature is to allow keystrokes that might be used by a Linux remote desktop (such as Alt-Tab) to be transmitted. macOS doesn't generally hijack those keystrokes, so keyboard grabbing has never been a high priority for the Mac TurboVNC Viewer.

Just so we're clear, are you trying to use the TurboVNC Viewer with a Mac VNC server? Or is there a Linux application I'm not aware of that uses Cmd-X (which would surprise me, since PC keyboards have no Cmd key)?

shg commented 1 year ago

Thank you for your response.

I am connecting to a Linux server with the Mac viewer. The main reason why I'd like to send Cmd-* keys to the remote is Emacs. I use Emacs on both Linux and Mac. I use Cmd key as Meta key on the Mac and would like to control the remote Linux in the same way using the Mac keyboard.

shg commented 1 year ago

Was this closed because any ways for avoiding the issue of keys taken by the viewer app will not be (able to be) implemented?

dcommander commented 1 year ago

It was closed because the OP's issue specifically involved Cmd-V, and that was fixed. I can add a command-line parameter for disabling all macOS keyboard shortcuts, but again, it will only disable the ones that the TurboVNC Viewer creates. The operating system uses other shortcuts that we can't disable, so a complete solution would involve a keyboard grabbing feature for macOS. So what I need from you is confirmation that disabling just the shortcuts that the TurboVNC Viewer creates would be sufficient to solve your problem.

shg commented 1 year ago

Thank you. Yes, I understood that the original issue was already resolved and therefore closed.

For me, the most desirable Viewer behavior is to send all key combinations directly to the remote. I don't need to use keyboard shortcuts to control the Viewer at all, I want the remote machine to behave as if it were being controlled directly from its own terminal. As I wrote I needed to use Emacs on the remote and it uses many key combinations. For example I use Command+x for Meta-x on my local machines but I can't use it for a Linux remote because the viewer takes it and does not send it to the remote.

May I create a new issue specifically about the problem I am facing?

dcommander commented 1 year ago

Not necessary to file a new issue. Just indicate whether my proposal above (a command-line argument to disable the Cmd shortcuts) would solve the problem for you. If not, then the only other solution is keyboard grabbing on macOS, and there's already an open feature request for that.

shg commented 1 year ago

there will still be certain keystrokes that macOS hijacks

Do you know what are those certain keystrokes that would not be sent to the remote even after all viewer's shortcuts are disabled?

shg commented 1 year ago

@dcommander I tried to find the information by myself but haven't found it yet. Although I can't tell whether disabling the viewer's Cmd shortcuts is sufficient or not without knowing what other shortcuts will be still taken, I would be happy to test it if you have time to provide me with an experimental version with shortcuts turned off. Thank you for the support.

dcommander commented 1 year ago

Do you know what are those certain keystrokes that would not be sent to the remote even after all viewer's shortcuts are disabled?

As an experiment, I disabled the TurboVNC Viewer Mac menu accelerators, and on my Mac, the following Cmd keystrokes are still hijacked by macOS:

There may be other Cmd keystrokes that macOS hijacks depending on how it is configured.

If you don't need any of those specific keystrokes, then I don't mind adding a parameter to disable the Mac menu accelerators. Otherwise, the only solution will be to implement keyboard grabbing on macOS, which will pass through all keystrokes to the server. There is already an issue for that (#162), but it needs funding, because it is likely to involve JNI and Cocoa shenanigans.

shg commented 1 year ago

@dcommander Thank you very much for taking your time to test this!

Those key combinations are not used that often and I think I can work around it by assigning different keys when needed.

If the major key combinations, Cmd-F, Cmd-W, Cmd-X, etc. could be sent directly to the remote, it would greatly improve the usability of the application for me.

dcommander commented 1 year ago

I forgot to mention that Cmd-Q is also hijacked by macOS.

dcommander commented 1 year ago

You should now be able to disable the Mac hotkeys by passing -nomachotkeys to /opt/TurboVNC/bin/vncviewer. (In the evolving 3.1 version, you can set that parameter in ~/.vnc/default.turbovnc using the traditional <param>=<value> syntax, i.e. machotkeys=0.)

shg commented 1 year ago

I have confirmed that with the option the shortcut keys are removed from the menu and the key combinations that were previously taken by the application are now sent to the remote. This will greatly improve usability.

I will report back if there are any problems. Thanks a lot!

TobiaszCudnik commented 1 year ago

PSA: does NOT work in v3.0.3.

dcommander commented 1 year ago

PSA: does NOT work in v3.0.3.

Pro tip: You can look at the commit linked above and see which tags contain it. (The 3.0.3 tag does not contain it.) The commit is in both the 3.0.x and main (3.1.x) branches, so the 3.0.x pre-release build will have it, but it landed months after the 3.0.3 release.