fix: use app icon precedence for individual app categories

Not only is precedence used to choose which window is used to represent
the workspace, it is also now used to choose which category of each
window is used to represent the app itself.
This commit is contained in:
Kiana Sheibani 2026-02-08 07:07:23 -05:00
parent f611ec3c25
commit 31254372c8
Signed by: toki
GPG key ID: 6CB106C25E86A9F7

View file

@ -127,6 +127,31 @@ Singleton {
Office: "content_paste" Office: "content_paste"
}) })
// App icon precedence
// Used to preferentially pick app icon for display
readonly property var appIconPrec: ({
sports_esports: 10,
code: 9,
music_note: 9,
content_paste: 9,
graphic_eq: 8,
tv: 8,
edit_note: 6,
language: 5,
business_messages: 5,
files: 4,
mic: 4,
construction: 4,
terminal: 3,
monitor_heart: 3,
security: 3,
photo_library: 3,
archive: 2,
settings: 2,
build: 1,
host: 0
})
function getDesktopEntry(name: string): DesktopEntry { function getDesktopEntry(name: string): DesktopEntry {
name = name.toLowerCase().replace(/ /g, "-"); name = name.toLowerCase().replace(/ /g, "-");
@ -146,37 +171,18 @@ Singleton {
function getAppCategoryIcon(name: string, fallback: string): string { function getAppCategoryIcon(name: string, fallback: string): string {
const categories = getDesktopEntry(name)?.categories; const categories = getDesktopEntry(name)?.categories;
let values = [];
if (categories) if (categories)
for (const [key, value] of Object.entries(categoryIcons)) for (const [key, value] of Object.entries(categoryIcons))
if (categories.includes(key)) if (categories.includes(key) && value in appIconPrec)
return value; values.push(value);
if (values.length !== 0) {
return values.reduce((a, b) => appIconPrec[a] > appIconPrec[b] ? a : b);
} else {
return fallback; return fallback;
} }
}
// App icon precedence
// Used to preferentially display apps in a workspace
readonly property var appIconPrec: ({
sports_esports: 10,
code: 9,
music_note: 9,
content_paste: 9,
graphic_eq: 8,
tv: 8,
edit_note: 6,
language: 5,
business_messages: 5,
files: 4,
host: 4,
mic: 4,
construction: 4,
monitor_heart: 3,
security: 3,
archive: 3,
settings: 2,
build: 2,
photo_library: 1,
terminal: 1
})
function getWorkspaceIcon(workspace: HyprlandWorkspace): string { function getWorkspaceIcon(workspace: HyprlandWorkspace): string {
if (!workspace || workspace.toplevels.values.length === 0) return "add"; if (!workspace || workspace.toplevels.values.length === 0) return "add";