tauri-apps / tauri

Build smaller, faster, and more secure desktop applications with a web frontend.
https://tauri.app
Apache License 2.0
81.76k stars 2.45k forks source link

[bug] `window.cursorPosition` errors in v2 #10340

Open bicarlsen opened 1 month ago

bicarlsen commented 1 month ago

Describe the bug

In v2 when calling __TAURI__.window.cursorPosition() I receive the error GDK may only be used from the main thread on the backend.

Reproduction

From a Tauri v2 app, in the console run __TAURI__.window.cursorPosition().

Expected behavior

Cursor position should be returned.

Full tauri info output

[✔] Environment
    - OS: Pop!_OS 22.4.0 X64
    ✔ webkit2gtk-4.1: 2.44.2
    ✔ rsvg2: 2.52.5
    ✔ rustc: 1.81.0-nightly (e9e6e2e44 2024-06-28)
    ✔ cargo: 1.81.0-nightly (4ed7bee47 2024-06-25)
    ✔ rustup: 1.27.1 (54dd3d00f 2024-04-24)
    ✔ Rust toolchain: nightly-x86_64-unknown-linux-gnu (environment override by RUSTUP_TOOLCHAIN)
    - node: 19.9.0
    - npm: 9.6.3

[-] Packages
    - tauri [RUST]: 2.0.0-beta.22
    - tauri-build [RUST]: 2.0.0-beta.17
    - wry [RUST]: 0.41.0
    - tao [RUST]: 0.28.1
    - tauri-cli [RUST]: 2.0.0-beta.18
    - @tauri-apps/api : not installed!
    - @tauri-apps/cli [NPM]: 2.0.0-beta.18

[-] App
    - build-type: bundle
    - CSP: unset
    - frontendDist: ../dist
    - devUrl: http://localhost:1420/

Stack trace

thread 'tokio-runtime-worker' panicked at /home/xxx/.cargo/registry/src/index.crates.io-6f17d22bba15001f/gdk-0.18.0/src/auto/display.rs:301:9:
GDK may only be used from the main thread.

Additional context

No response

bicarlsen commented 1 month ago

@FabianLars I also tested on Windows and got the same error, so my guess is it's a platform independent bug.

FabianLars commented 1 month ago

Do you still have the full error from the Windows test? I doubt it's exactly the same since we don't use GDK on Windows so it'd be interesting to see where it panics.

bicarlsen commented 1 month ago

Oops, it appears it is working on Windows now. I must have messed something up when testing the first time. Sorry about that.