Repository: qutebrowser/qutebrowser

Issue:
Allow to set DesktopFileName via cli flag
Allow to set DesktopFileName through cli flag. To make it easier to match specific qutebrowser instances to i3wm/swaywm workspaces.

https://github.com/qutebrowser/qutebrowser/blob/master/qutebrowser/app.py#L95


Discussion:
Setting `DesktopFileName` from the outside makes little sense - that's the name of the underlying `.desktop` file, so passing another value there wouldn't result in anything useful. I don't see a way to filter by that in i3wm either, FWIW.

Instead, you can filter by `instance` (`WM_NAME`), and use `--qt-arg name ...` to set it.
I see, it was the only value I found which correspondes to the app_id in sway/wayland. Setting `instance` doesn't work on Wayland. Is there a way to set the app_id?
I stand corrected - after talking to Drew Devault in IRC, it looks like `app_id` is only tangientally related to the desktop filename, and the Qt thing is a bit of a misnomer. I'll need to check if there are any other places where that information is used, though.

Qt doesn't seem to expose a built-in way to set it from outside, though.
I tested changing the DesktopFileName and re-launching `qutebrowser` with a temp basedir:

https://github.com/qutebrowser/qutebrowser/blob/d397725ebfbf375c17c1ddd20896e84454bb1a0b/qutebrowser/app.py#L97

It worked-- The resulting "app_id" was changed under Wayland.

I also wouldn't see it as a deal breaker if DesktopFileName _does_ need to point a .desktop file. That's exactly how Chromium implements SSBs / Single Site Browsers / PWAs-- a new ".desktop" file is created in `~/.local/share/applications` that launches Chromium with a different profile and icon.

If `qutebrowser` can handle the other parts, I'm happy to write my own `.desktop` files for alternate instances. Creating those could also be a feature added to a companion project like `qutebrowser-profile`. https://github.com/jtyers/qutebrowser-profile
The docs for the feature could simply say that the new value should correspond to such file located in `~/.local/share/applications/` and provide an example of creating one. But in my own test, it wasn't actually required.

Resolving patch:
diff --git a/qutebrowser/app.py b/qutebrowser/app.py
--- a/qutebrowser/app.py
+++ b/qutebrowser/app.py
@@ -94,7 +94,8 @@ def run(args):
     q_app = Application(args)
     q_app.setOrganizationName("qutebrowser")
     q_app.setApplicationName("qutebrowser")
-    q_app.setDesktopFileName("org.qutebrowser.qutebrowser")
+    # Default DesktopFileName is org.qutebrowser.qutebrowser, set in `get_argparser()`
+    q_app.setDesktopFileName(args.desktop_file_name)
     q_app.setApplicationVersion(qutebrowser.__version__)
 
     if args.version:
diff --git a/qutebrowser/qutebrowser.py b/qutebrowser/qutebrowser.py
--- a/qutebrowser/qutebrowser.py
+++ b/qutebrowser/qutebrowser.py
@@ -93,6 +93,11 @@ def get_argparser():
 
     parser.add_argument('--json-args', help=argparse.SUPPRESS)
     parser.add_argument('--temp-basedir-restarted', help=argparse.SUPPRESS)
+    parser.add_argument('--desktop-file-name',
+                        default="org.qutebrowser.qutebrowser",
+                        help="Set the base name of the desktop entry for this "
+                        "application. Used to set the app_id under Wayland. See "
+                        "https://doc.qt.io/qt-5/qguiapplication.html#desktopFileName-prop")
 
     debug = parser.add_argument_group('debug arguments')
     debug.add_argument('-l', '--loglevel', dest='loglevel',


Test patch: