cirruslabs / tart

macOS and Linux VMs on Apple Silicon to use in CI and other automations
https://tart.run
Other
3.67k stars 103 forks source link

The flag --capture-system-keys doesn't seem to work. #703

Closed alopecoid closed 6 months ago

alopecoid commented 6 months ago

Hi,

The flag --capture-system-keys doesn't seem to work; the macOS guest doesn't seem to capture the keys adequately from the macOS host. For example, CMD+Tab (to bring up the App Switcher) and CMD+Space (to bring up Spotlight) both execute on the host versus the guest. I am running the same version of macOS on both host and guest (see below).

I have also noticed this behavior when testing UTM and VirtualBuddy, so I assume that this is an issue inherent within Apple's underlying virtualization framework. However, I also assume that --capture-system-keys was meant to somehow work around the issue, otherwise could its purpose be clarified? (This issue within UTM is actually what led me to try tart, in the hopes that tart figured out some clever way around it).

Using --vnc-experimental instead does indeed seem to work around this issue, however UI latency is noticeably slower in this mode, so I would prefer to avoid it.

Thank you!

MacBook Pro Apple M3 Max
macOS 14.2.1 (23C71)
tart 2.4.4
edigaryev commented 6 months ago

macOS 14.2.1 (23C71)

Is that a version of a host OS? If so, what is the version of the macOS running in guest?

The reason I'm asking because --capture-system-keys works just fine for me, both for Command + Space bar and Command + Tab.

I'm running macOS 14.0 (Sonoma) guest on a macOS 14.2.1 (Sonoma) host.

alopecoid commented 6 months ago

Hi,

Easy to miss, but I mention this in the original post:

I am running the same version of macOS on both host and guest [...]

...so both host and guest are running macOS 14.2.1 (23C71).

Thank you!

edigaryev commented 6 months ago

Thanks for the clarification.

...so both host and guest are running macOS 14.2.1 (23C71).

I've just installed macOS 14.2.1 using tart create --from-ipsw=latest <VM>, started it with tart run --capture-system-keys <VM> command-line argument, and everything works just fine.

Honestly, I have no idea what could be different with your setup.

fkorotkov commented 6 months ago

I've also tried to reproduce with no luck. I wonder if you have changed any preferences in the Keyboard section? Also are you using an external keyboard?

alopecoid commented 6 months ago

I think you are correct; this seems to have something to do with keyboard configuration. As mentioned in my original post, I am experiencing similar problems in both UTM and VirtualBuddy. So I went back to my UTM configuration and in the Virtualization section swapped the Keyboard from Generic USB to Mac Keyboard (macOS 14+). After some rudimentary testing, everything seems to work correctly. This is unintuitive (to me), as the keyboard I'm using is indeed a "generic USB keyboard" and not a Mac keyboard. My guess is that if the generic keyboard is configured correctly on the host, it will "look like" a Mac keyboard on the guest, which seems to be the case because when set to Mac Keyboard (macOS 14+), both the built-in MacBook keyboard and the external generic keyboard work as intended on the guest.

Peripheral thought: This makes me wonder if certain other input settings are always "relative" across the guest and host systems; for example, scroll/tracking speed settings, etc. And if so, are these "additive" or "multiplicative" if adjusted to non-default values on the guest?

Anyway, all that said, I'm not exactly sure how to apply this newfound knowledge to Tart. In other words, while in UTM I explicitly (and apparently incorrectly) set my keyboard configuration to Generic USB, I did not explicitly set any keyboard configuration for Tart. So the problem seems inverted; by default UTM seems to configure the external keyboard correctly, while Tart does not. Forgive me if I'm missing something obvious, but where does one configure the keyboard in Tart? I couldn't find any mention of it in tart help, in the online docs, or from a search through the GitHub repo.

Thank you!

fkorotkov commented 6 months ago

Interesting findings! Thanks for sharing!

Tart uses the Mac keyboard by default on Sonoma hosts like yours:

https://github.com/cirruslabs/tart/blob/090a8232fc0bb604fc86a60dbcef5952ada010b2/Sources/tart/Platform/Darwin.swift#L102-L105

We kept the Generic one for compatibility with macOS Monterey.

On that note, could you please try to run a suspendable VM via tart run --capture-system-keys --suspendable? This way you Sonoma VM will get only one keyboard:

https://github.com/cirruslabs/tart/blob/090a8232fc0bb604fc86a60dbcef5952ada010b2/Sources/tart/Platform/Darwin.swift#L111-L113

fkorotkov commented 6 months ago

Closing since can't reproduce. :-(