Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bug] globalShortcut Ctrl+Space is invalid when NumLock is on #537

Closed
beyondlov1 opened this issue Aug 18, 2022 · 8 comments · Fixed by #532 · May be fixed by wravery/tao#1
Closed

[bug] globalShortcut Ctrl+Space is invalid when NumLock is on #537

beyondlov1 opened this issue Aug 18, 2022 · 8 comments · Fixed by #532 · May be fixed by wravery/tao#1

Comments

@beyondlov1
Copy link

Describe the bug

globalShortcut Ctrl+Space is invalid when NumLock is on, but it works well when NumLock is off.

Reproduction

js code:

import { register } from '@tauri-apps/api/globalShortcut';
register('Ctrl+Space', () => {
  // do something
});

Expected behavior

globalShortcut works when NumLock is on

Platform and versions

Environment
› OS: Ubuntu 20.04 X64
› Node.js: 16.16.0
› npm: 8.11.0
› pnpm: 6.11.0
› yarn: 1.22.15
› rustup: 1.25.1
› rustc: 1.62.1
› cargo: 1.62.1
› Rust toolchain: stable-x86_64-unknown-linux-gnu

Packages
› @tauri-apps/cli [NPM]: 1.0.5
› @tauri-apps/api [NPM]: 1.0.2
› tauri [RUST]: 1.0.5,
› tauri-build [RUST]: 1.0.4,
› tao [RUST]: 0.12.2,
› wry [RUST]: 0.19.0,

App
› build-type: bundle
› CSP: unset
› distDir: ../dist
› devPath: http://localhost:5173/
› framework: Vue.js

Stack trace

No response

Additional context

No response

@beyondlov1 beyondlov1 added status: needs triage This issue or pull request needs to be investigated type: bug labels Aug 18, 2022
@amrbashir
Copy link
Member

Please turn on NumLock, run xev in your terminal, then press Space and finally paste the output here

@beyondlov1
Copy link
Author

NumLock is on, Space:

KeyPress event, serial 32, synthetic NO, window 0x4400001,
    root 0x539, subw 0x0, time 65236105, (313,280), root:(751,349),
    state 0x10, keycode 65 (keysym 0x20, space), same_screen YES,
    XLookupString gives 1 bytes: (20) " "
    XmbLookupString gives 1 bytes: (20) " "
    XFilterEvent returns: False

KeyRelease event, serial 32, synthetic NO, window 0x4400001,
    root 0x539, subw 0x0, time 65236249, (313,280), root:(751,349),
    state 0x10, keycode 65 (keysym 0x20, space), same_screen YES,
    XLookupString gives 1 bytes: (20) " "
    XFilterEvent returns: False

NumLock is off Space:

KeyPress event, serial 32, synthetic NO, window 0x4400001,
    root 0x539, subw 0x0, time 65461115, (495,701), root:(512,718),
    state 0x0, keycode 65 (keysym 0x20, space), same_screen YES,
    XLookupString gives 1 bytes: (20) " "
    XmbLookupString gives 1 bytes: (20) " "
    XFilterEvent returns: False

KeyRelease event, serial 32, synthetic NO, window 0x4400001,
    root 0x539, subw 0x0, time 65461211, (495,701), root:(512,718),
    state 0x0, keycode 65 (keysym 0x20, space), same_screen YES,
    XLookupString gives 1 bytes: (20) " "
    XFilterEvent returns: False

NumLock is on, Ctrl:

KeyPress event, serial 32, synthetic NO, window 0x4400001,
    root 0x539, subw 0x0, time 66057985, (857,215), root:(874,232),
    state 0x10, keycode 37 (keysym 0xffe3, Control_L), same_screen YES,
    XLookupString gives 0 bytes: 
    XmbLookupString gives 0 bytes: 
    XFilterEvent returns: False

KeyRelease event, serial 32, synthetic NO, window 0x4400001,
    root 0x539, subw 0x0, time 66058113, (857,215), root:(874,232),
    state 0x14, keycode 37 (keysym 0xffe3, Control_L), same_screen YES,
    XLookupString gives 0 bytes: 
    XFilterEvent returns: False

NumLock is off, Ctrl:

KeyPress event, serial 32, synthetic NO, window 0x4400001,
    root 0x539, subw 0x0, time 66135170, (461,1161), root:(478,1178),
    state 0x0, keycode 37 (keysym 0xffe3, Control_L), same_screen YES,
    XLookupString gives 0 bytes: 
    XmbLookupString gives 0 bytes: 
    XFilterEvent returns: False

KeyRelease event, serial 32, synthetic NO, window 0x4400001,
    root 0x539, subw 0x0, time 66135282, (461,1161), root:(478,1178),
    state 0x4, keycode 37 (keysym 0xffe3, Control_L), same_screen YES,
    XLookupString gives 0 bytes: 
    XFilterEvent returns: False

The Ctrl's state is different.
By the way, CapsLock also has the same problem.

@amrbashir amrbashir transferred this issue from tauri-apps/tauri Aug 19, 2022
@amrbashir
Copy link
Member

amrbashir commented Aug 19, 2022

Thanks for filing an issue, it made me aware of this weird X11 behavior.

Apparently, in X11, NumLock is considered a mask (or as we consider it in our code, a modifier) so when it is ON, state will contains its mask (0x10) along with other modifiers, in this case Ctrl (0x04).

The bug is that we use the value of state as an id to see if it exists in our shortcut manager, and when NumLock is ON, it won't be able to find the shortcut in the manager because it contains another mask that we didn't account for. This also maybe the cause of #307.

@amrbashir
Copy link
Member

amrbashir commented Aug 19, 2022

#538 should fix this. If you want to test the fix, add this to your Cargo.toml and then run cargo update -p tao in src-tauri

Edit: the fix is now part of the dev branch

[patch.crates-io]
tao = { git = "https://github.com/tauri-apps/tao", branch = "dev" }

@beyondlov1
Copy link
Author

beyondlov1 commented Aug 20, 2022

It doesn't work. Is there some thing wrong with my config?

Cargo.toml:

[build-dependencies]
tauri-build = { version = "1.0.4", features = [] }

[dependencies]
serde_json = "1.0"
serde = { version = "1.0", features = ["derive"] }
tauri = { version = "1.0.5", features = ["api-all", "system-tray"] }
rusqlite = { version = "0.28.0", features = ["bundled"] }
lazy_static = "1.4.0"
dirs = "4.0.0"
tao = "0.13.3"

[features]
default = [ "custom-protocol" ]
custom-protocol = [ "tauri/custom-protocol" ]

[patch.crates-io]
tao = { git = "https://github.com/tauri-apps/tao", branch = "dev" }

[net]
git-fetch-with-cli = true

Cargo.lock:

...

[[package]]
name = "app"
version = "0.1.0"
dependencies = [
 "dirs",
 "lazy_static",
 "rusqlite",
 "serde",
 "serde_json",
 "tao 0.13.3",
 "tauri",
 "tauri-build",
]


[[package]]
name = "tao"
version = "0.13.3"
source = "git+https://github.com/tauri-apps/tao?branch=dev#f7953e770d1391e16178ba8f8bda0ef41676428f"
dependencies = [
 "bitflags",
 "cairo-rs",
 "cc",
 "cocoa",
 "core-foundation",
 "core-graphics",
 "crossbeam-channel",
 "dispatch",
 "gdk",
 "gdk-pixbuf",
 "gdk-sys",
 "gdkx11-sys",
 "gio",
 "glib",
 "glib-sys",
 "gtk",
 "image",
 "instant",
 "jni 0.19.0",
 "lazy_static",
 "libc",
 "log",
 "ndk",
 "ndk-context",
 "ndk-sys",
 "objc",
 "once_cell",
 "parking_lot",
 "paste",
 "png 0.17.5",
 "raw-window-handle 0.5.0",
 "scopeguard",
 "unicode-segmentation",
 "uuid 1.1.2",
 "windows 0.37.0",
 "windows-implement",
 "x11-dl",
]
...

tauri info:

Environment
  › OS: Ubuntu 20.04 X64
  › Node.js: 16.16.0
  › npm: 8.18.0
  › pnpm: Not installed!
  › yarn: Not installed!
  › rustup: 1.25.1
  › rustc: 1.62.1
  › cargo: 1.62.1
  › Rust toolchain: stable-x86_64-unknown-linux-gnu 

Packages
  › @tauri-apps/cli [NPM]: 1.0.5
  › @tauri-apps/api [NPM]: 1.0.2
  › tauri [RUST]: 1.0.5,
  › tauri-build [RUST]: 1.0.4,
  › tao [RUST]: 0.13.3 (0.12.2, 0.13.3),
  › wry [RUST]: 0.19.0,

App
  › build-type: bundle
  › CSP: unset
  › distDir: ../dist
  › devPath: http://localhost:5173/
  › framework: Vue.js

App directory structure
  ├─ .vscode
  ├─ dist
  ├─ public
  ├─ node_modules
  ├─ .git
  ├─ src-tauri
  └─ src

@amrbashir
Copy link
Member

can you try the global_shortcut from this repo instead?

git clone https://github.com/tauri-apps/tao
cd tao
cargo r --example global_shortcut

@beyondlov1
Copy link
Author

I run the example, and the problem is still there.
there is no output when NumLock is on.

@amrbashir
Copy link
Member

Thanks for testing, looks like the bug is not resolved just yet. I will repoen #307 to track this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants