hyprwm / Hyprland

Hyprland is an independent, highly customizable, dynamic tiling Wayland compositor that doesn't sacrifice on its looks.
https://hyprland.org
BSD 3-Clause "New" or "Revised" License
19.76k stars 840 forks source link

Export `XDG_ACTIVATION_TOKEN` for apps launched by Hyprland #1350

Open q234rty opened 1 year ago

q234rty commented 1 year ago

Currently firefox supports using this variable to activate itself. Without this, one has to manually switch to the workspace firefox is in when opening an url. While in theory this should be exported by the app launching firefox, currently there are many apps that don't do this. If the compositor supports this, one can easily workaround that by editing desktop files to use hyprctl dispatch exec.

This is implemented by sway in https://github.com/swaywm/sway/pull/6639, though I personally don't care much about workspace matching.

vaxerski commented 1 year ago

doesnt it already work with misc:focus_on_activate?

q234rty commented 1 year ago

doesnt it already work with misc:focus_on_activate?

This only works if the app tries to activate itself, i.e. only works when XDG_ACTIVATION_TOKEN is set. If you launch firefox using foot's url-mode it will work, but it won't work when you just do firefox "https://google.com" in a terminal.

q234rty commented 1 year ago

Of course, with misc:focus_on_activate = false none of the above will work, but that's not the case I'm talking about here.

vaxerski commented 1 year ago

the reason I keep it off and generally not work on it is that it was causing me more issues than switching workspaces to firefox. Maybe it's my shady impl, maybe not, but some apps would repeatedly spam activation a kjhillion times a second (e.g. obs)

q234rty commented 1 year ago

but some apps would repeatedly spam activation a kjhillion times a second (e.g. obs)

How do I reproduce that?

vaxerski commented 1 year ago

open obs and start recording iirc

q234rty commented 1 year ago

Yeah that's probably a qtbug or something, but it doesn't seem to cause any actual issue even with misc:focus_on_activate = true, and imo should not block implementing this.

vaxerski commented 1 year ago

it doesnt block it, but the 129 other issues don't make this a priority either. You're free and welcome to try making a patch yourself and making a MR.

q234rty commented 1 year ago

but some apps would repeatedly spam activation a kjhillion times a second (e.g. obs)

I believe this no longer happens with qt 6.5.

romanstingler commented 1 year ago

doesnt it already work with misc:focus_on_activate?

This only works if the app tries to activate itself, i.e. only works when XDG_ACTIVATION_TOKEN is set. If you launch firefox using foot's url-mode it will work, but it won't work when you just do firefox "https://google.com" in a terminal.

with misc:focus_on_activate = true on firefox-nightly it jumps to the workspace where firefox is located if I call firefox-nightly "https://google.com" in a terminal

fufexan commented 1 year ago

Still, telegram-desktop will get focused when a notification is received. Not great to be interrupted like that.

ZerdoX-x commented 11 months ago

@fufexan @vaxerski Ilya Fedin, developer of telegram-desktop was surprised when I told him that Hyprland switches workspaces and focusing telegram-desktop every time notification arrives. They use QWindow::alert, here is a quote from https://github.com/telegramdesktop/tdesktop/issues/26343 not really related to this issue thread:

Apparently that's how your compositor reacts to QWindow::alert? It blinks in taskbar/dock on KDE (both X11/Wayland), Windows and macOS.


@q234rty

I believe this no longer happens with qt 6.5.

Today I migrated my system from qt5 to qt6 and stumbled upon this issue, when telegram grabs focus and switches workspaces every. damn. message. It was all good in qt5 since afaik it did not support focus request in wayland.

Now I have dev-qt/qtbase and dev-qt/qtwayland v6.6.0 both.


Maybe we can reopen https://github.com/hyprwm/Hyprland/issues/2732 and migrate discussion related to telegram-desktop and obs there? They both qt and I don't think they do something wrong about this, maybe we treat their signals wrong? Just disabling misc:focus_on_activate is not a solution to the OP issue in my opinion. I still want to use this feature flawlessly in my daily work, for example, when I open links from terminal or my code editor, as #1350 OP

q234rty commented 11 months ago

I believe this no longer happens with qt 6.5.

Today I migrated my system from qt5 to qt6 and stumbled upon this issue, when telegram grabs focus and switches workspaces every. damn. message. It was all good in qt5 since afaik it did not support focus request in wayland.

I was talking about the obs issue where activation requests were literally spammed, which was AFAIK fixed in https://invent.kde.org/qt/qt/qtwayland/-/commit/2fa2a5184dcdf54a7868d73418ed141713587969

Now, for telegram-desktop the easy workaround would be to disable "Draw attention to the window" in its notifications settings. Though if there would be activation spams from other apps, making focus_on_activate into a window rule could be a consideration.

The original issue about firefox mentioned here was "fixed" by gtk, which had a wrong implementation of xdg-activation causing wlroots-based compositors to reject it's request. See e.g. https://github.com/swaywm/sway/issues/4155 and https://gitlab.gnome.org/GNOME/gtk/-/merge_requests/5293. Exporting XDG_ACTIVATION_TOKEN would still be useful for workspace matching if the application supports this environment variable.

ZerdoX-x commented 11 months ago

Now, for telegram-desktop the easy workaround would be to disable "Draw attention to the window" in its notifications settings.

Oh, that's nice. I have enabled focus_on_activate back and disabled this feature in telegram, thank you :)