tauri icon indicating copy to clipboard operation
tauri copied to clipboard

[bug] In linux `appWindow.isFocused` is always `false`.

Open ayangweb opened this issue 1 year ago β€’ 2 comments

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

ayangweb avatar Oct 12 '24 05:10 ayangweb

Hey guys🀣, the task on Linux is arduous, the revolution has not yet succeeded, comrades still need to work hardπŸ€¦β€β™‚οΈ!

witt-bit avatar Oct 12 '24 07:10 witt-bit

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.

jerrybaxia avatar Nov 27 '24 15:11 jerrybaxia

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()))

VassilisM avatar Jan 09 '25 07:01 VassilisM

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?

BlazeStorm001 avatar Mar 18 '25 11:03 BlazeStorm001