Open Bug 1826330 Opened 2 years ago Updated 2 months ago

KDE Wayland: <appid>.desktop must match g_set_prgname(<appid>), otherwise windows have a wayland icon

Categories

(Core :: Widget: Gtk, defect, P3)

Desktop
Linux
defect

Tracking

()

People

(Reporter: jan, Unassigned)

References

(Blocks 3 open bugs)

Details

Attachments

(1 file)

Nightly, KDE Wayland, Debian Testing

if the desktop file is named: StartupWMClass nightly main window icon about/downloads/bookmark window icon
~/.local/share/applications/firefox.desktop WAYLAND WAYLAND
~/.local/share/applications/firefox-nightly.desktop nightly nightly
~/.local/share/applications/firefox.desktop firefox-nightly nightly WAYLAND (but nightly in taskbar)
~/.local/share/applications/firefox-nightly.desktop firefox-nightly nightly nightly
~/.local/share/applications/org.mozilla.firefox-nightly.desktop firefox-nightly nightly WAYLAND (but nightly in taskbar)
/var/lib/snapd/desktop/applications/firefox_firefox.desktop nightly WAYLAND (but nightly in taskbar)

Gnome Wayland doesn't have window icons, only taskbar icons.

Summary: KDE Wayland: .desktop file name must be exactly firefox-nightly, otherwise the about dialog has a wayland icon → KDE Wayland: .desktop file name must be exactly firefox-nightly, otherwise the about/downloads/bookmark windows have a wayland icon

MOZ_APP_REMOTINGNAME is either firefox, firefox-beta, firefox-dev, firefox-nightly, firefox-esr.

bug 1751153 - Correct Gnome+KDE taskbar icons:

  • Flatpak's desktop file has StartupWMClass=firefox, a correct KDE Wayland taskbar icon if started via terminal&via start menu.
  • Snap's desktop file doesn't have StartupWMClass=MOZ_APP_REMOTINGNAME, it has wrong KDE Wayland taskbar icons if started via terminal, but correct KDE Wayland taskbar icons if started via start menu. Start menu entries for Nightly are unexpectedly named "Firefox Web Browser".
  • bug 1831896 would extend the script from bug 1824327 to generate Fluent-localized .desktop files for Snap+Flatpak as well.

This bug - Correct KDE Wayland window icons if MOZ_ENABLE_WAYLAND=1:

  • Firefox uses tabs-in-titlebar by default on KDE (=no possibly wrong main window icon visible), about/downloads/bookmark window icons may be wrong.
  • Gnome doesn't have window icons.
  • <appid>.desktop must match g_set_prgname("<appid>") according to https://honk.sigxcpu.org/con/GTK__and_the_application_id.html

appid example:
desktop file is: /usr/share/applications/org.kde.discover.desktop
appid is: $ WAYLAND_DEBUG=1 plasma-discover |& grep 'xdg_toplevel@[0-9]\+\.set_app_id' [ 330637.227] -> xdg_toplevel@29.set_app_id("org.kde.discover")

Flatpak and Snap need special remotingnames:

  • Flatpak has wrong KDE Wayland window icons if started via terminal or via main menu.
    Flatpak has (requires) an org.mozilla.firefox.desktop file, IIUC it therefore needs to use org.mozilla.MOZ_APP_REMOTINGNAME instead of MOZ_APP_REMOTINGNAME as remotingname for g_set_prgname to have correct KDE Wayland window icons. StartupWMClass would then need to be changed as well or be removed.

    $ echo $XDG_DATA_DIRS
    /home/darkspirit/.local/share/flatpak/exports/share:/var/lib/flatpak/exports/share:/usr/local/share:/usr/share:/var/lib/snapd/desktop
    $ ls /var/lib/flatpak/exports/share/applications/*firefox*
    /var/lib/flatpak/exports/share/applications/org.mozilla.firefox.desktop
    $ MOZ_ENABLE_WAYLAND=1 WAYLAND_DEBUG=1 flatpak run org.mozilla.firefox |& grep 'xdg_toplevel@[0-9]\+\.set_app_id'
    [ 993077.554]  -> xdg_toplevel@43.set_app_id("firefox")
    [ 995694.442]  -> xdg_toplevel@75.set_app_id("firefox")
    [1022515.183]  -> xdg_toplevel@117.set_app_id("firefox")
    
  • Snap has wrong KDE Wayland window icons if started via terminal or via main menu.
    The real desktop file is (re)named firefox_firefox.desktop or firefox+userdefinedaliasname_firefox.desktop.
    It doesn't seem to matter how it's named inside the snap package.
    Format is packagename_appname.desktop or packagename+userdefinedaliasname_appname.desktop.
    Firefox therefore needs to use

    • <packagename>_<appname> (firefox_firefox)
    • or if SNAP_INSTANCE_KEY env var is not empty: <packagename>+<SNAP_INSTANCE_KEY>_<appname> (firefox+userdefinedaliasname_firefox)
      • Existing GetSnapInstanceName() is not useful because SNAP_INSTANCE_NAME contains _ (for snap run firefox_userdefinedaliasname) instead of + (for firefox+userdefinedaliasname_firefox.desktop).

    instead of MOZ_APP_REMOTINGNAME as remotingname for g_set_prgname to have correct KDE Wayland window icons. StartupWMClass would then need to be changed as well (which might not be possible) or be removed.

    If appname would become firefox-nightly, then Nightly could only be started with .firefox-nightly suffix:

    • snap run firefox.firefox-nightly starts firefox_firefox-nightly.desktop
    • snap run firefox_userdefinedaliasname.firefox-nightly starts firefox+userdefinedaliasname_firefox-nightly.desktop

    If appname would become nightly, then Nightly could only be started with .nightly suffix:

    • snap run firefox.nightly starts firefox_nightly.desktop
    • snap run firefox_userdefinedaliasname.nightly starts firefox+userdefinedaliasname_nightly.desktop

    If appname stays firefox for the firefox-nightly snap, the shorter command without .<appname> can be used:

    • relevant: snap run firefox starts firefox_firefox.desktop
    • irrelevant: snap run firefox.firefox
    • relevant: snap run firefox_userdefinedaliasname starts firefox+userdefinedaliasname_firefox.desktop
    • irrelevant: snap run firefox_userdefinedaliasname.firefox

    https://github.com/canonical/firefox-snap/blob/4eec4293c2a08cadd525fe19d82a7092cc265919/snapcraft.yaml#L27
    https://snapcraft.io/docs/snapcraft-yaml-reference
    https://snapcraft.io/docs/commands-and-aliases
    https://snapcraft.io/docs/environment-variables
    https://snapcraft.io/docs/parallel-installs

    $ echo $XDG_DATA_DIRS
    /home/darkspirit/.local/share/flatpak/exports/share:/var/lib/flatpak/exports/share:/usr/local/share:/usr/share:/var/lib/snapd/desktop
    $ ls /var/lib/snapd/desktop/applications/*firefox*
    /var/lib/snapd/desktop/applications/firefox_firefox.desktop
    $ MOZ_ENABLE_WAYLAND=1 WAYLAND_DEBUG=1 snap run firefox |& grep 'xdg_toplevel@[0-9]\+\.set_app_id'
    [2140293,649]  -> xdg_toplevel@43.set_app_id("firefox")
    $ sudo snap set system experimental.parallel-instances=true
    $ sudo snap install firefox_nightly --edge --unaliased
    $ ls /var/lib/snapd/desktop/applications/*firefox*
    /var/lib/snapd/desktop/applications/firefox_firefox.desktop  /var/lib/snapd/desktop/applications/firefox+nightly_firefox.desktop
    $ MOZ_ENABLE_WAYLAND=1 WAYLAND_DEBUG=1 snap run firefox_nightly |& grep 'xdg_toplevel@[0-9]\+\.set_app_id'
    [3310669,510]  -> xdg_toplevel@50.set_app_id("firefox-nightly")
    $ sudo snap install firefox_randomname --edge --unaliased
    $ sudo snap install firefox_second --unaliased
    $ sudo snap install firefox_beata --beta --unaliased
    $ ls /var/lib/snapd/desktop/applications/*firefox*
    /var/lib/snapd/desktop/applications/firefox+beata_firefox.desktop    /var/lib/snapd/desktop/applications/firefox+randomname_firefox.desktop
    /var/lib/snapd/desktop/applications/firefox_firefox.desktop          /var/lib/snapd/desktop/applications/firefox+second_firefox.desktop
    /var/lib/snapd/desktop/applications/firefox+nightly_firefox.desktop
    
  • unaffected: Mozilla's debian package (bug 1824327) has correct Gnome+KDE Wayland taskbar icons (StartupWMClass=MOZ_APP_REMOTINGNAME) and correct KDE Wayland window icons (MOZ_APP_REMOTINGNAME.desktop with g_set_prgname(MOZ_APP_REMOTINGNAME)).

See Also: → 1831896
Summary: KDE Wayland: .desktop file name must be exactly firefox-nightly, otherwise the about/downloads/bookmark windows have a wayland icon → KDE Wayland: <appid>.desktop must match g_set_prgname(<appid>), otherwise windows have a wayland icon
Priority: -- → P3

Here is some confidence:

Tested on KDE X11, KDE Xwayland and KDE Wayland:

  • Wayland: This bug is about setting a correct Wayland appid (g_set_prgname) inside Flatpak and Snap to match their desktop file names to have correct window icons (instead of a Wayland W icon) because Wayland apps can't set their icon themselves.

    X11: gdk_set_program_class(MOZ_APP_REMOTINGNAME) for X11 WMClass can be left untouched. It would not match org.mozilla.firefox.desktop or firefox_firefox.desktop, but StartupWMClass=MOZ_APP_REMOTINGNAME.
    If the logic required for Wayland would be applied here as well, StartupWMClass would need to be removed or become StartupWMClass=firefox+userdefinedaliasname_firefox in a second snap instance, but IIUC the desktop file can't be customized at snap install. Therefore the X11 logic should be left untouched.

  • What has been fixed in the past:

    • bug 1530052 set:
      g_set_prgname(MOZ_APP_REMOTINGNAME) for Wayland
      gdk_set_program_class(MOZ_APP_REMOTINGNAME) for X11
    • bug 1752418 introduced different MOZ_APP_REMOTINGNAMEs: firefox-nightly, firefox-beta, etc. Previously it had always been firefox.
  • How to check the Wayland appid or X11 class of an app:
    Wayland: $ WAYLAND_DEBUG=1 plasma-discover |& grep 'xdg_toplevel@[0-9]\+\.set_app_id'
    X11: $ xprop WM_CLASS + click on window

  • Overrides that shouldn't be neccessary:

    • Wayland: --name name-of-desktop-file-without-extension can override wrong g_set_prgname("doesnt-match-any-desktop-file-without-extension") on KDE Wayland to get correct window icons and window grouping.
    • X11:
      • --class matches-a-desktopfilename-or-startupwmclass can override wrong gdk_set_program_class("doesnt-match-any-desktop-filename-or-startupwmclass")
      • StartupWMClass=my-taskbaricon-and-windowgrouping-name can be used in a randomname.desktop file
        to match gdk_set_program_class("my-taskbaricon-and-windowgrouping-name" or --class=my-taskbaricon-and-windowgrouping-name
        if the desktop file is not named my-taskbaricon-and-windowgrouping-name.desktop.
  • Tested on Wayland:

    • $ MOZ_ENABLE_WAYLAND=1 flatpak run org.mozilla.firefox
      $ MOZ_ENABLE_WAYLAND=1 snap run firefox
      = Windows (about firefox/downloads/etc/main window with browser.tabs.inTitlebar=0) have Wayland's W icon. g_set_prgname("firefox") is wrong, there is no firefox.desktop with an icon.

    • $ MOZ_ENABLE_WAYLAND=1 flatpak run org.mozilla.firefox --name org.mozilla.firefox
      = correct icon as it matches org.mozilla.firefox.desktop. --name overrided wrong g_set_prgname

    • Nightly uses Wayland by default:
      $ snap run firefox_minefield
      = It has the icon of and is grouped with firefox-nightly.desktop from my firefox-nightly debian package. If I hadn't that installed, the icon would have been wrong.

    • $ snap run firefox_minefield --name firefox+minefield_firefox
      = It's correctly grouped with itself and it has the correct Icon as it matches its firefox+minefield_firefox.desktop file.

    • Xwayland has always correct window icons, but window grouping can be wrong:
      $ flatpak run org.mozilla.firefox + $ xprop WM_CLASS
      $ snap run firefox + $ xprop WM_CLASS

      WM_CLASS(STRING) = "Navigator", "firefox"

      = their windows aren't grouped by their .desktop file, but with windows of a completely different Firefox binary that also sets "firefox".

    • $ flatpak run org.mozilla.firefox --class org.mozilla.firefox + $ xprop WM_CLASS

      WM_CLASS(STRING) = "Navigator", "org.mozilla.firefox"

      = --class was able to override wrong g_set_prgname("firefox") to match org.mozilla.firefox.desktop to have correct window grouping.

    • $ flatpak run org.mozilla.firefox --name org.mozilla.firefox --class firefox-x11 + $ xprop WM_CLASS

      WM_CLASS(STRING) = "Navigator", "firefox-x11"

      = --name (Wayland app/desktop id) is irrelevant on Xwayland. Only WMClass is relevant.

    • $ WAYLAND_DEBUG=1 MOZ_ENABLE_WAYLAND=1 flatpak run org.mozilla.firefox --name org.mozilla.firefox --class firefox-x11 |& grep 'xdg_toplevel@[0-9]\+\.set_app_id'

      [1193475.868] -> xdg_toplevel@41.set_app_id("org.mozilla.firefox")

      = X11 WMClass is irrelevant on Wayland. Only --name (Wayland app/desktop id) is relevant.

  • Tested on X11:
    Window icon is set by the application. But Taskbar icon and window grouping can be configured via desktop file.

    • ~/.local/share/applications/secondprofile.desktop

      Icon=chromium
      Exec=firefox-nightly -P profilename %u

      = Secondprofile is shown with chromium icon in start menu.
      When starting Secondprofile, the chromium icon is shown for a short time and then replaced with the Nightly icon.

    • ~/.local/share/applications/secondprofile.desktop

      Icon=chromium
      Exec=firefox-nightly -P profilename %u --class secondprofile

      = overridden window class secondprofile matches secondprofile.desktop:
      The chromium icon is shown in taskbar for all secondprofile windows (but window icons are set by the binary and are still nightly).

    • ~/.local/share/applications/totallyrandomfilename.desktop

      Icon=chromium
      Exec=firefox-nightly -P profilename %u --class secondprofile

      = When starting Secondprofile, the chromium icon is shown for a short time and then replaced with the Nightly icon.

    • ~/.local/share/applications/totallyrandomfilename.desktop

      Icon=chromium
      Exec=firefox-nightly -P profilename %u --class secondprofile
      StartupWMClass=secondprofile

      = overridden WMClass matches StartupWMClass. The chromium icon is shown in taskbar for all secondprofile windows (but window icons are set by the binary and are still nightly).

    • $ flatpak run org.mozilla.firefox
      while having
      ~/.local/share/applications/firefox.desktop

      Icon=chromium

      = taskbar icon is chromium.

    • $ flatpak run org.mozilla.firefox
      while having
      ~/.local/share/applications/firefox.desktop

      Icon=chromium

      and a manually added StartupWMClass=firefox in /var/lib/flatpak/exports/share/applications/org.mozilla.firefox.desktop
      = taskbar icon is firefox

    • $ flatpak run org.mozilla.firefox --name org.mozilla.firefox + xprop WM_CLASS

      WM_CLASS(STRING) = "Navigator", "firefox"

      = overriding the Wayland app id does not override the X11 WMClass.


Cleanest fix: g_set_prgname() should contain the likeliest .desktop file name Firefox wants its icon from and be grouped with:

(Darkspirit from bug 1835135 comment 5)

  • bug 1826330:
    The terms DesktopId and Wayland app id refer to <DesktopId>.desktop.
    Call g_set_prgname() with desktopid that you get from a new method XREAppData::GetDesktopId which should return:

    • if IsRunningUnderFlatpak()
      org.mozilla.<MOZ_APP_REMOTINGNAME with "-" replaced with "_" > // to match org.mozilla.firefox.desktop, org.mozilla.thunderbird.desktop
      org.mozilla.<what GetDBusAppName returns>
    • else if SNAP_NAME env var is not empty:
      • If SNAP_INSTANCE_KEY env var is not empty:
        <SNAP_NAME>+<SNAP_INSTANCE_KEY>_<SNAP_NAME> // to match firefox+userdefinedaliasname_firefox.desktop, thunderbird+userdefinedaliasname_thunderbird.desktop
      • else
        <SNAP_NAME>_<SNAP_NAME> // to match firefox_firefox.desktop, thunderbird_thunderbird.desktop
    • else
      MOZ_APP_REMOTINGNAME // to match firefox-nightly.desktop, thunderbird.desktop

    Snap background:
    packagename can have multiple apps with desktop file. First app's name is usually the same as packagename.
    $ sudo snap install packagename
    $ sudo snap install packagename_userdefinedaliasname
    $ snap run packagename is possible if appname==packagename
    $ snap run packagename.appname (packagename_appname.desktop)
    $ snap run packagename_userdefinedaliasname is possible if appname==packagename
    $ snap run packagename_userdefinedaliasname.appname (packagename+userdefinedaliasname_appname.desktop)

    SNAP_NAME env var contains packagename.
    SNAP_INSTANCE_KEY env var contains userdefinedaliasname.
    SNAP_INSTANCE_NAME is packagename_userdefinedaliasname
    There is no env var for appname.

Blocks: 1836158
Blocks: 1836342

Wayland apps can't set their icon themselves, a .desktop file is required.
g_set_prgname(app_id) must match app_id.desktop which contains the icon.
Flatpak and Snap have special .desktop file name expectations:

Flatpak: org.vendorname.appname.desktop.
"-" is forbidden in Flatpak appnames, it must be replaced with "_".
Snap: snappackagename_snapappname.desktop
Snap parallel install: snappackagename+userdefinedaliasname_snapappname.desktop
Regular packages: MOZ_APP_REMOTINGNAME.desktop

Tested with:
$ sudo touch /.flatpak-info
$ WAYLAND_DEBUG=1 ./mach run |& grep 'xdg_toplevel@[0-9]+.set_app_id'
[1994505.534] -> xdg_toplevel@53.set_app_id("org.mozilla.firefox_default")
[2002340.447] -> xdg_toplevel@74.set_app_id("org.mozilla.firefox_default")
$ sudo rm /.flatpak-info
$ SNAP_NAME="firefox" WAYLAND_DEBUG=1 ./mach run |& grep 'xdg_toplevel@[0-9]+.set_app_id'
[2026616.395] -> xdg_toplevel@53.set_app_id("firefox_firefox")
$ SNAP_NAME="firefox" SNAP_INSTANCE_KEY="customalias" WAYLAND_DEBUG=1 ./mach run |& grep 'xdg_toplevel@[0-9]+.set_app_id'
[2052628.181] -> xdg_toplevel@53.set_app_id("firefox+customalias_firefox")
$ WAYLAND_DEBUG=1 ./mach run |& grep 'xdg_toplevel@[0-9]+.set_app_id'
[2063136.586] -> xdg_toplevel@53.set_app_id("firefox-default")
$ WAYLAND_DEBUG=1 ./mach run --name torbrowser |& grep 'xdg_toplevel@[0-9]+.set_app_id'
[3993637.547] -> xdg_toplevel@53.set_app_id("torbrowser")

Assignee: nobody → jan
Status: NEW → ASSIGNED
Blocks: 1868917
Duplicate of this bug: 1868917

What is missing to be able to land this ?

Flags: needinfo?(jan)

The bug assignee is inactive on Bugzilla, so the assignee is being reset.

Assignee: jan → nobody
Status: ASSIGNED → NEW

Redirect a needinfo that is pending on an inactive user to the triage owner.
:stransky, since the bug doesn't have a severity set, could you please set the severity or close the bug?

For more information, please visit BugBot documentation.

Flags: needinfo?(jan) → needinfo?(stransky)
Flags: needinfo?(stransky)
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: