tauri icon indicating copy to clipboard operation
tauri copied to clipboard

Cannot have focus on Ubuntu GNOME

Open bachrc opened this issue 2 years ago • 11 comments

Describe the bug

I am on Ubuntu 22.04, with GNOME on Xorg (because Tauri doesn’t support global shortcuts on wayland)

My app launches as a tray app.

I registered a global shortcut to show my window, and it works well. Though : the window does not have any focus. When the shortcut is triggered, i get my window, i make it .show(), and I make it .set_focus()… but it won’t. I must click on it to get my focus. Same with a tray item as a trigger.

Reproduction

  1. Crrate a Tauri app
  2. Main window is hidden by default
  3. App is a tray app
  4. Register a global shortcut : when triggered, get the main window and make it visible. No focus
  5. You can make a set_focus too : no focus on the app

Expected behavior

With a show(), the window is supposed to get the focus.

Platform and versions

Environment
  › OS: Ubuntu 22.04 X64
  › Node.js: 18.13.0
  › npm: 8.19.3
  › pnpm: 7.25.1
  › yarn: Not installed!
  › rustup: 1.25.2
  › rustc: 1.67.0
  › cargo: 1.67.0
  › Rust toolchain: stable-x86_64-unknown-linux-gnu 

Packages
  › @tauri-apps/cli [NPM]: 1.2.3
  › @tauri-apps/api [NPM]: 1.2.0
  › tauri [RUST]: 1.2.4,
  › tauri-build [RUST]: 1.2.1,
  › tao [RUST]: 0.15.8,
  › wry [RUST]: 0.23.4,

App
  › build-type: bundle
  › CSP: unset
  › distDir: ../build
  › devPath: http://localhost:5173/
  › framework: Svelte
  › bundler: Vite

App directory structure
  ├─ src
  ├─ .idea
  ├─ build
  ├─ .svelte-kit
  ├─ static
  ├─ .git
  ├─ node_modules
  └─ src-tauri

Stack trace

No errors

Additional context

No response

bachrc avatar Feb 18 '23 17:02 bachrc

Same happens with me.

ParthJadhav avatar Feb 18 '23 17:02 ParthJadhav

Could you guys test with another desktop environment or another window manager? I am pretty sure that's just another Gnome bug (or a restriction).

amrbashir avatar Feb 28 '23 14:02 amrbashir

I had the same problem with archlinux Gnome 43.3, I tested it in a virtual machine with the Deepin desktop environment and found no such problem, I guess maybe it's a Gnome bug?

Additional, when I tested on Gnome, I found that if I don't do anything to the window, I have no problem getting focus at all, but if I open the window with a shortcut once, my mouse has any action in the window (click, scroll wheel), After I close the window, and the next time I open the window with a shortcut, getting focus fails.

Pylogmon avatar Mar 01 '23 05:03 Pylogmon

I don't have any other DE, I cannot test on another one.

What could the Gnome bug be? I searched through the Gnome issue tracker, and I couldn't find something like this.

bachrc avatar Mar 01 '23 19:03 bachrc

I am not sure if it is a bug or not but recently, I have seen more often than before that a lot of APIs stopped working on Gnome, for example, set_focus and unminimize and I am not sure if it is just a restriction imposed by the Window Manager in Gnome or straight up a bug but we are calling the right GTK methods so if they ever fix it, the fix will land in tauri automatically.

amrbashir avatar Mar 01 '23 20:03 amrbashir

+1

klauss194 avatar Mar 04 '23 22:03 klauss194

I just found the same issue on KDE Plasma. Unlike Gnome, when I create a window using a shortcut key on the desktop in KDE, it can capture focus well. However, if the focus is on another window and I create a window using a shortcut key, this new window will not be able to capture focus. Hope this information helps.

Pylogmon avatar Apr 22 '23 15:04 Pylogmon

I found that there is such an option in the KDE settings, the default is low, if it is set to none, it can solve this problem, I don't know if there is a similar setting under Gnome. image

Pylogmon avatar Apr 22 '23 16:04 Pylogmon

I found that there is such an option in the KDE settings, the default is low, if it is set to none, it can solve this problem, I don't know if there is a similar setting under Gnome. image

this should be added to the docs somewhere I was looking for it for too long

0-don avatar Dec 16 '23 16:12 0-don

Has anyone found a solution for Gnome?

ayangweb avatar Oct 17 '24 12:10 ayangweb

Faced same issue and it drives me crazy, because I cannot force/ask users of the app to change KDE settings because my app needs it. I have experimented and investigated little bit. Manage to reproduce this bug on bare minimum. Here you can find sample of minimal code https://github.com/ansirotenko/ccv/tree/experiments. All plugins are excluded (even global shortcut). Basically my sample have 2 threads. First reports window.is_focused, second tires to show and focus window in the loop. The problem is that window never focused if you press any button in focused window and then click outside.

I've been a good boy all year. Hope Santa will bring me a good gift this year ;)

ansirotenko avatar Dec 02 '24 00:12 ansirotenko

Yeah, expecting users to change settings isn't going to work. I have this issue on KDE Plasma, and it seems like something Tauri should handle, because using tauri-plugin-opener to reveal a file does open and focus the file browser.

mikew avatar Jul 07 '25 15:07 mikew