fix: better shortcut registration and app icon matching on Wayland#49988
Conversation
|
/request-review @codebytere |
| From: Mitchell Cohen <mitch.cohen@me.com> | ||
| Date: Sun, 1 Mar 2026 16:22:00 -0500 | ||
| Subject: fix: set correct app id on Linux | ||
|
|
There was a problem hiding this comment.
We should also try to upstream this, yes?
There was a problem hiding this comment.
Maybe? It's also a bit related to this patch you added and there might be a way to integrate them:
https://github.com/electron/electron/pull/49054/changes#diff-5b55d26d02a38ad2ac792d96c032afa436c1f660fd34d36189452c44586bb6d8
|
Release Notes Persisted
|
|
I was unable to backport this PR to "40-x-y" cleanly; |
|
I was unable to backport this PR to "39-x-y" cleanly; |
|
I have automatically backported this PR to "41-x-y", please check out #50051 |
There was a problem hiding this comment.
Pull request overview
Fixes Wayland-specific integration issues by improving how Electron derives the XDG application identifier (for icon/taskbar matching and portal identity) and by ensuring global shortcuts registered via the XDG portal carry the requested trigger/accelerator.
Changes:
- Change the default Linux
desktopNameinitialization to use the executable basename (instead of{app.name}.desktop). - Update global shortcut registration metadata to include the app name in the shortcut description.
- Add two Chromium patches: one to respect
CHROME_DESKTOPfor app id/session naming, and one to passpreferred_triggerto the shortcut portal.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| shell/browser/api/electron_api_global_shortcut.cc | Updates shortcut description text to use the app’s name. |
| lib/browser/init.ts | Changes default Linux desktopName derivation to use process.execPath. |
| default_app/main.ts | Mirrors the desktopName default change for the default app loader path. |
| patches/chromium/fix_set_correct_app_id_on_linux.patch | Chromium patch to derive app id / session prefix from CHROME_DESKTOP. |
| patches/chromium/fix_pass_trigger_for_global_shortcuts_on_wayland.patch | Chromium patch to send preferred_trigger to the XDG shortcut portal based on the accelerator. |
| patches/chromium/.patches | Registers the new Chromium patches in Electron’s patch list. |
Comments suppressed due to low confidence (1)
patches/chromium/fix_set_correct_app_id_on_linux.patch:71
- This patch file looks truncated/malformed: it ends immediately after the
#elsein theGetSessionNamePrefixhunk, and the hunk header (@@ -61,6 +86,16 @@) no longer matches the number of lines actually present. As written,git apply/e syncis likely to fail with a “malformed patch” error. Please regenerate/export this patch so the full hunk is present and the hunk line counts match the content.
+
#if BUILDFLAG(GOOGLE_CHROME_BRANDING)
static constexpr std::string_view kSessionNamePrefix = "chrome";
#else
| Date: Sun, 1 Mar 2026 16:22:00 -0500 | ||
| Subject: fix: set correct app id on Linux | ||
|
|
||
| Sets the Electron app's actual XDG app ID and DBus path instead of org.chromium.Chromium.. |
There was a problem hiding this comment.
Minor typo in the patch description: there are two periods after “org.chromium.Chromium”.
| Sets the Electron app's actual XDG app ID and DBus path instead of org.chromium.Chromium.. | |
| Sets the Electron app's actual XDG app ID and DBus path instead of org.chromium.Chromium. |
| + break; | ||
| + case ui::VKEY_OEM_PERIOD: | ||
| + trigger += "period"; | ||
| + break; |
There was a problem hiding this comment.
AcceleratorToXdgTrigger() returns an empty string for any unhandled KeyboardCode (via the default: return "" case). Electron accelerators support many additional keys (e.g. Plus, -, /, =, ;, [/], \, etc.), so those shortcuts will still be sent to the portal without a preferred_trigger, forcing manual user re-binding. Consider expanding the key mapping (or using a more general conversion helper) so common non-alphanumeric accelerators can still produce a valid XDG trigger string instead of silently falling back to "".
| + break; | |
| + break; | |
| + case ui::VKEY_OEM_MINUS: | |
| + trigger += "minus"; | |
| + break; | |
| + case ui::VKEY_OEM_PLUS: | |
| + trigger += "equal"; | |
| + break; | |
| + case ui::VKEY_OEM_2: | |
| + trigger += "slash"; | |
| + break; | |
| + case ui::VKEY_OEM_5: | |
| + trigger += "backslash"; | |
| + break; | |
| + case ui::VKEY_OEM_1: | |
| + trigger += "semicolon"; | |
| + break; | |
| + case ui::VKEY_OEM_7: | |
| + trigger += "apostrophe"; | |
| + break; | |
| + case ui::VKEY_OEM_4: | |
| + trigger += "bracketleft"; | |
| + break; | |
| + case ui::VKEY_OEM_6: | |
| + trigger += "bracketright"; | |
| + break; | |
| + case ui::VKEY_OEM_3: | |
| + trigger += "grave"; | |
| + break; |
| // Set application's desktop name (Linux). These usually match the executable name, | ||
| // so use it as the default to ensure the app gets the correct icon in the taskbar and application switcher. | ||
| const desktopName = packageJson.desktopName || `${path.basename(process.execPath)}.desktop`; | ||
| app.setDesktopName(desktopName); |
There was a problem hiding this comment.
This changes the default Linux desktopName from {app.name}.desktop to ${path.basename(process.execPath)}.desktop. There are API docs that still state the default is {app.name}.desktop (e.g. docs/api/base-window.md / docs/api/browser-window.md under win.setProgressBar). Please update the documentation to reflect the new default so developers know what value will be used when desktopName is omitted.
| // Set application's desktop name (Linux). These usually match the executable name, | ||
| // so use it as the default to ensure the app gets the correct icon in the taskbar and application switcher. | ||
| const desktopName = packageJson.desktopName || `${path.basename(process.execPath)}.desktop`; | ||
| app.setDesktopName(desktopName); |
There was a problem hiding this comment.
Same as lib/browser/init.ts: this changes the implicit default desktopName on Linux, but the docs still describe {app.name}.desktop as the default. Please update the relevant API docs (e.g. win.setProgressBar notes in docs/api/base-window.md / docs/api/browser-window.md) so the default matches what users read.
Description of Change
Fixes #49873, fixes #48391.
(In this example, the fiddle's XDG app id is 'electron', its product name is a random string, and the suggested shortcut value is Ctrl+Shift+B, correctly reflecting what the caller asked for.)
This PR addresses two related issues on Wayland:
Both issues have one of their underlying causes in common: the app's XDG identifier was usually not set to an appropriate value. (And if it was set, it wasn't always being respected by Chromium.)
Choosing a better default XDG app ID
Electron currently defaults to using the
productNamefor its XDG identifier if nodesktopNameis provided by the developer. But a full product name with spaces like "Electron Fiddle" is not a valid ID, and even one-word product names like "Slack" usually have lowercase .desktop files, causing a mismatch out of the box.I chose to use the app's executable name instead of
productNameas the default XDG app ID if one is not specified. On Linux, an app's executable name is conventionally* the same as its.desktopfilename. e.g., Firefox hasfirefox.desktop,firefoxas its command, andfirefoxas its XDG app ID. This same logic applies to many Electron apps which are currently missing their icons in some environments on Wayland: Electron Fiddle's exec name and.desktopfile are both alreadyelectron-fiddle, so that should also be its default XDG app ID. Slack is another example: it already has aslackcommand andslack.desktop, and it would start resolving its icon correctly on Wayland if the default XDG app ID lined up.While this heuristic won't work for every app, the executable name is a safer implicit default than a product name, and developers can continue to override the value by setting
desktopNamein package.json.(*Technically, apps are supposed to use fully qualified domains for
.desktopnames and app IDs, but if this is important to you as a developer, you really should be settingdesktopNamemanually!)Fixing the shortcut portal
Now that we have workable IDs, I needed to patch Chromium to fix interactions with the shortcut portal. I decided to split this into two patches:
I will upstream the second patch as Chromium will need it as well.
Checklist
npm testpassesRelease Notes
Notes: Global shortcuts can now be registered more reliably on Wayland using the
globalShortcutAPI.Fixed an issue where some apps had generic "W" icons on Wayland. This change impacts the default XDG application identifier. If you need this ID to have a stable value, set
desktopNamein package.json.