[bug] In linux `appWindow.isFocused` is always `false`.
Describe the bug
Heyπ, appWindow.isFocused is always false in linux, but it's fine in macOS and Windows! How can this problem be solved?
const appWindow = getCurrentWebviewWindow();
const focused = await appWindow.isFocused();
Reproduction
No response
Expected behavior
No response
Full tauri info output
[β] Environment
- OS: Ubuntu 22.4.0 aarch64 (X64)
β webkit2gtk-4.1: 2.44.3
β rsvg2: 2.52.5
β rustc: 1.81.0 (eeb90cda1 2024-09-04)
β cargo: 1.81.0 (2dbb1af80 2024-08-20)
β rustup: 1.27.1 (54dd3d00f 2024-04-24)
β Rust toolchain: stable-aarch64-unknown-linux-gnu (default)
- node: 20.18.0
- pnpm: 9.12.1
- npm: 10.8.2
[-] Packages
- tauri π¦: 2.0.2
- tauri-build π¦: 2.0.1
- wry π¦: 0.44.1
- tao π¦: 0.30.3
- @tauri-apps/api ξ: 2.0.2
- @tauri-apps/cli ξ: 2.0.2
[-] Plugins
- tauri-plugin-single-instance π¦: 2.0.1
- @tauri-apps/plugin-single-instance ξ: not installed!
- tauri-plugin-os π¦: 2.0.1
- @tauri-apps/plugin-os ξ: 2.0.0
- tauri-plugin-global-shortcut π¦: 2.0.1
- @tauri-apps/plugin-global-shortcut ξ: 2.0.0
- tauri-plugin-log π¦: 2.0.1
- @tauri-apps/plugin-log ξ: 2.0.0
- tauri-plugin-process π¦: 2.0.1
- @tauri-apps/plugin-process ξ: 2.0.0
- tauri-plugin-fs π¦: 2.0.1
- @tauri-apps/plugin-fs ξ: 2.0.0
- tauri-plugin-autostart π¦: 2.0.1
- @tauri-apps/plugin-autostart ξ: 2.0.0
- tauri-plugin-window-state π¦: 2.0.1
- @tauri-apps/plugin-window-state ξ: not installed!
- tauri-plugin-dialog π¦: 2.0.1
- @tauri-apps/plugin-dialog ξ: 2.0.0
- tauri-plugin-updater π¦: 2.0.2
- @tauri-apps/plugin-updater ξ: 2.0.0
- tauri-plugin-shell π¦: 2.0.1
- @tauri-apps/plugin-shell ξ: 2.0.0
- tauri-plugin-sql π¦: 2.0.1
- @tauri-apps/plugin-sql ξ: 2.0.0
[-] App
- build-type: bundle
- CSP: unset
- frontendDist: ../dist
- devUrl: http://localhost:1420/
- framework: React
- bundler: Vite
Stack trace
No response
Additional context
No response
Hey guysπ€£, the task on Linux is arduous, the revolution has not yet succeeded, comrades still need to work hardπ€¦ββοΈ!
In my Window 10 app Window.isFocused is always false;
Cargo.toml
[build-dependencies]
tauri-build = {version = "2.0.3", features = []}
[dependencies]
serde = {version = "1", features = ["derive"]}
serde_json = "1"
tauri = {version = "2.1.1", features = ["unstable", "devtools"]}
tauri-plugin-shell = "2"
listen('tauri://focus', (event) => {
// never work
console.log('focus event');
});
const sendEmitClick = async () => {
// aways false
console.log('focusοΌ', await getCurrentWindow().isFocused());
};
Thank you.
In windows (10) it has a strange problem. The focus will be false in the beginning and will stay that way unless the window actually loses focus and gets it back:
This seems to have no effect in the beginning.
console.log(await appWindow.isFocused())
await appWindow.setFocus()
console.log(await appWindow.isFocused())
This will show false each time the titlebar is clicked (when using windows decorations) or when the area marked with data-tauri-drag-region is clicked (when using custom decorations).
It will only show true if another window gets clicked and then the tauri window.
await appWindow.onFocusChanged(async () => console.log(await appWindow.isFocused()))
Its the same with the Rust API as well, is_focused() returns false everytime it is called on linux. Anyone figured out a solution to this?