diff options
| author | Xavier Lhinares <60365026+XLhinares@users.noreply.github.com> | 2026-03-15 16:17:49 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-03-15 19:17:49 +1100 |
| commit | 63c86e950b59ba1b29df367065ee2623b0335906 (patch) | |
| tree | e18790ab4dd006e8b3f872f218afdddfdbb7247b /utils/Icons.qml | |
| parent | nix: remove outdated app2unit version pin (#1266) (diff) | |
| download | caelestia-shell-63c86e950b59ba1b29df367065ee2623b0335906.tar.gz caelestia-shell-63c86e950b59ba1b29df367065ee2623b0335906.tar.bz2 caelestia-shell-63c86e950b59ba1b29df367065ee2623b0335906.zip | |
bar: allow setting custom workspace app icons in shell.json (#1214)
* bar: allow setting custom workspace app icons in shell.json
* rename to windowIcons and use regex field for regex
Also allow specifying regex flags and exact name
* add default config (fix steam icons)
---------
Co-authored-by: 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com>
Diffstat (limited to 'utils/Icons.qml')
| -rw-r--r-- | utils/Icons.qml | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/utils/Icons.qml b/utils/Icons.qml index c06cbf8..34f8049 100644 --- a/utils/Icons.qml +++ b/utils/Icons.qml @@ -79,6 +79,26 @@ Singleton { Office: "content_paste" }) + // Checks if a name matches an icon config. Icon configs can have the following keys: + // - name: The exact name of the icon + // - regex: A regex to match against the name (takes priority over name) + // - flags: The regex flags (only used if regex is set) + // - icon: The icon to use + function matchIconConfig(name: string, iconConfig: var): bool { + if (!iconConfig.icon) + return false; + + if (iconConfig.regex) { + const re = new RegExp(iconConfig.regex, iconConfig.flags ?? ""); + if (re.test(name)) + return true; + } else if (iconConfig.name === name) { + return true; + } + + return false; + } + function getAppIcon(name: string, fallback: string): string { const icon = DesktopEntries.heuristicLookup(name)?.icon; if (fallback !== "undefined") @@ -87,6 +107,10 @@ Singleton { } function getAppCategoryIcon(name: string, fallback: string): string { + for (const iconConfig of Config.bar.workspaces.windowIcons) + if (matchIconConfig(name, iconConfig)) + return iconConfig.icon; + const categories = DesktopEntries.heuristicLookup(name)?.categories; if (categories) @@ -188,11 +212,9 @@ Singleton { function getSpecialWsIcon(name: string): string { name = name.toLowerCase().slice("special:".length); - for (const iconConfig of Config.bar.workspaces.specialWorkspaceIcons) { - if (iconConfig.name === name) { + for (const iconConfig of Config.bar.workspaces.specialWorkspaceIcons) + if (matchIconConfig(name, iconConfig)) return iconConfig.icon; - } - } if (name === "special") return "star"; |