Skip to content

Conversation

friday
Copy link
Member

@friday friday commented Feb 18, 2022

This fixes #162 for "pure" X11 (not Wayland or XWayland).

It's added as a non-default setting (because we can't support it in all environments).

It uses the command name or the "WM Class" in the .desktop entry (most apps don't specify the wm class) as the way to identify apps, and it only works on 100% matches (case-insensitive though). I think it's very important to avoid false positives, and better to start this way and deal with any false negatives we discover later (one seemingly safe way could be to strip non-alphanumerics before the comparison).

It's working well in my tests, and since swapping to using Wnck for this we can also add exceptions (like for Thunar that has two different apps identifying the same way and breaks in jumpapp and raise-or-run and even the default Gnome app launcher (but not in this PR).

Checklist

  • Verify that the test command ./ul test is passing (the CI server will check this if you don't)
  • Update the documentation according to your changes (when applicable)
  • Write unit tests for your changes (when applicable)

@friday friday force-pushed the feat/162/raise-if-started branch from 02fa9b0 to 1e99d80 Compare February 24, 2022 04:53
@friday friday marked this pull request as ready for review February 24, 2022 04:55
@friday friday force-pushed the feat/162/raise-if-started branch from 1e99d80 to 4a861b3 Compare February 24, 2022 05:07
@friday friday requested a review from troycurtisjr February 24, 2022 05:10
@friday friday added this to the 6.0.0 milestone Feb 24, 2022
@troycurtisjr
Copy link
Member

Code is looking good and I'll test it tonight on my system. I'm really glad you already added it as an option, otherwise that would have been my next PR 😁. Even though I don't personally want this setting enabled, I think making it the default makes total sense. It does seem to be the dominant mode among other launchers and as a new seeing those that would want it, might not realize it was available if it defaulted to off. For those of us that don't want it, when the behavior changes, that will prompt digging into the settings to see what changed and disabling it.

@friday
Copy link
Member Author

friday commented Feb 25, 2022

Code is looking good and I'll test it tonight on my system. I'm really glad you already added it as an option, otherwise that would have been my next PR grin. Even though I don't personally want this setting enabled, I think making it the default makes total sense. It does seem to be the dominant mode among other launchers and as a new seeing those that would want it, might not realize it was available if it defaulted to off. For those of us that don't want it, when the behavior changes, that will prompt digging into the settings to see what changed and disabling it.

I always intended to support the behavior to launch a new window via #476 and maybe adding a manual entry when there's no "new-window" action. And maybe adding a new hotkey (like shift+enter). I think this is a lot better than a setting for it, but we would have to implement #476 first for that, and that's harder. And seeing as there's no reliable way to solve this issue currently, then I prefer a setting so people can opt out if it causes issues for them (as with the Thunar example).

@troycurtisjr
Copy link
Member

Unfortunately it seems that wmctrl just doesn't work at all with Wayland and Wayland based apps. It will "see" apps that use XWayland, but none of the apps using native Wayland. In my current session I have Firefox, Zeal, Wavebox, several emacs windows, and Alacritty running. This is the output of wmctrl:

❯ wmctrl -l
0x00800142  0 arafel emacs@arafel
0x01e00003  1 arafel Fedora Chat | Fedora Design 🎨 - Wavebox
0x03000142  1 arafel emacs@arafel

On the upside it kinda works on my emacs session. Except that it picks a random window (presumably the first in the list) to raise, which means it takes me over to another desktop instead of raising the window on the current desktop. But then again maybe this kind of raising setting is just incompatible with a multi-window workflow.
Also it tries to use wavebox-launcher for wavebox, so that doesn't raise correctly either.

@friday
Copy link
Member Author

friday commented Feb 28, 2022

Oh, that sucks. I did test it in X11 mostly, but also Wayland (actually still using Wayland now because of it) and it worked for the apps I tested. Maybe because I have Gnome set up to remember my session 🤦, and it started the apps with xwayland because I was using X in the previous session.

It should "degrade gracefully" when it doesn't work, but making it default when it's not working with pure Wayland feels ugly.

Also, this means that ulauncher-toggle will only work if ulauncher is launcher with X11 or XWayland, although it's not the only thing that depends on this (same for centering and moving the window with the cursor).

I did find this, regarding your previous suggestion to use the Gnome APIs. It seems they removed that option unless you use a shell extension: https://www.reddit.com/r/gnome/comments/pneza1/gdbus_call_for_moving_windows_not_working_in/

Alternative I think this is what wmctrl would need for this to work in Wayland, and it doesn't look like this will be supported any time soon.

@friday
Copy link
Member Author

friday commented Mar 14, 2022

  • Rebased with v6
  • Made it non-default
  • Added a warning in the Preferences if using Wayland (like the hotkey warning). I think it's better to move both settings to a "X11" section instead though.
  • Added checks if using Wayland and if wmctrl is missing (since it's not a dependency now since e5df3b6 (we can revert add it back of course, but I think we shouldn't do that for just this feature)

I don't know if we should merge this, but it's the best I could do with this PR for now. I would like to find a better way, but I think there aren't any :(

@friday friday force-pushed the feat/162/raise-if-started branch 3 times, most recently from be7e681 to f30cd5c Compare March 25, 2022 14:38
@friday friday changed the title Use wmctrl to try to activate app before launching Try to activate app before launching Mar 25, 2022
@friday friday force-pushed the feat/162/raise-if-started branch from f30cd5c to fa9241f Compare March 25, 2022 15:12
@friday
Copy link
Member Author

friday commented Mar 25, 2022

Found a GTK API to use instead of wmctrl, so we don't need to introduce that dependency again, and we can control the implementation more to add exceptions etc.

Haven't tested in Wayland yet, but I know it won't work since it's x11 only.

@friday friday force-pushed the feat/162/raise-if-started branch 3 times, most recently from 482e49b to 8a042d2 Compare March 25, 2022 18:16
@friday friday force-pushed the feat/162/raise-if-started branch from 8a042d2 to 74baef3 Compare March 25, 2022 18:30
@friday friday merged commit 65654f1 into v6 Mar 28, 2022
@friday friday deleted the feat/162/raise-if-started branch March 28, 2022 15:31
@friday friday mentioned this pull request Mar 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Switch to application if it's already running
2 participants