Genymobile / scrcpy

Display and control your Android device
Apache License 2.0
113.19k stars 10.8k forks source link

Command-key is not released after shifting keyboard layout on Mac #4251

Open metayan opened 1 year ago

metayan commented 1 year ago

Environment

Describe the bug

  1. scrcpy is in focus on Mac
  2. text input field is in focus in scrcpy
  3. switch input language on Mac with command-space, allowing the keyboard layout list to be shown
  4. release the command key to select a keyboard layout

From the point of view of scrcpy, the command key does not get "released", and any keypress after that on the Mac is as if the command key was still held.

For example, if m is pressed when scrcpy is in this state, the menu is shown on the phone, if right arrow is pressed, the screen is rotated, and so on.

This state is kept until one of the command keys is pressed and released by itself.

Notes command key = In Preferences -> Keyboard -> Shortcuts -> Input Sources, "Select the previous input source" is set to "⌘Space" and marked as active.

Observation Every time this command-key lock happens, 32 bytes are leaked:

leaks scrcpy
Process:         scrcpy [33958]
Path:            /Users/Shared/*/scrcpy
Load Address:    0x106b6a000
Identifier:      scrcpy
Version:         ???
Code Type:       X86-64
Parent Process:  bash [33955]

Date/Time:       2023-08-23 19:33:03.383 +0200
Launch Time:     2023-08-23 18:57:03.243 +0200
OS Version:      Mac OS X 10.15.7 (19H2026)
Report Version:  7
Analysis Tool:   /usr/bin/leaks

Physical footprint:         103.4M
Physical footprint (peak):  106.4M
----

leaks Report Version: 4.0
Process 33958: 34330 nodes malloced for 25462 KB
Process 33958: 4 leaks for 128 total leaked bytes.

    4 (128 bytes) << TOTAL >>
      1 (32 bytes) ROOT LEAK: <TSMInputSource 0x7fbb734f77b0> [32]
      1 (32 bytes) ROOT LEAK: <TSMInputSource 0x7fbb734f82e0> [32]
      1 (32 bytes) ROOT LEAK: <TSMInputSource 0x7fbb73594770> [32]
      1 (32 bytes) ROOT LEAK: <TSMInputSource 0x7fbb737adf40> [32]
rom1v commented 1 year ago

Probably a bug in SDL, since scrcpy just reads the button state from the SDL event:

https://github.com/Genymobile/scrcpy/blob/1ee46970e373ea3c34c3d9b632fef34982d7a52b/app/src/input_manager.c#L366-L373