From 8cdb2d572038cda19ab2c53b61abbfb9150fe6f5 Mon Sep 17 00:00:00 2001 From: Naglis Jonaitis Date: Tue, 9 Apr 2024 19:20:09 +0300 Subject: [PATCH] Set the desktop filename and app name of the Qt application Currently, the app ID of the Dangerzone GUI application when running under Wayland is `python3`, which is not very useful if one wants to automate some action related to the Dangerzone application window (e.g. to always start Dangerzone window in floating mode under Sway WM). Setting the desktop filename property also sets the app ID of the application under Wayland. According to Qt documentation[1], the property value should be the name of the application's .desktop file but without the extension. Qt documentation also states: > This property gives a precise indication of what desktop entry > represents the application and it is needed by the windowing system to > retrieve such information without resorting to imprecise heuristics. Therefore I also think that setting this property is needed to display the correct application name and icon (taken from the .desktop entry) when running under certain windowing systems (like Wayland) (see also #402). Note that this property is not enough, as we've encountered systems where setting just the desktop file name does not alter the detected application name by the window manager. For this reason, we also use set the application name [2] to `dangerzone`, to remove any ambiguity. [1]: https://doc.qt.io/qt-6/qguiapplication.html#desktopFileName-prop [2]: https://doc.qt.io/qt-6/qcoreapplication.html#applicationName-prop Fixes #402 --- dangerzone/gui/__init__.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/dangerzone/gui/__init__.py b/dangerzone/gui/__init__.py index a6ed69b29..d7595edcc 100644 --- a/dangerzone/gui/__init__.py +++ b/dangerzone/gui/__init__.py @@ -56,6 +56,21 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: with open(get_resource_path("dangerzone.css"), "r") as f: style = f.read() self.setStyleSheet(style) + + # Needed under certain windowing systems to match the application to the + # desktop entry in order to display the correct application name and icon + # and to allow identifying windows that belong to the application (e.g. + # under Wayland it sets the correct app ID). The value is the name of the + # Dangerzone .desktop file. + self.setDesktopFileName("press.freedom.dangerzone") + + # In some combinations of window managers and OSes, if we don't set an + # application name, then the window manager may report it as `python3` or + # `__init__.py`. Always set this to `dangerzone`, which corresponds to the + # executable name as well. + # See: https://github.com/freedomofpress/dangerzone/issues/402 + self.setApplicationName("dangerzone") + self.original_event = self.event def monkeypatch_event(arg__1: QtCore.QEvent) -> bool: