diff options
Diffstat (limited to 'accounts/gkleen@sif/shell/quickshell/ActiveWindowDisplay.qml')
-rw-r--r-- | accounts/gkleen@sif/shell/quickshell/ActiveWindowDisplay.qml | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/accounts/gkleen@sif/shell/quickshell/ActiveWindowDisplay.qml b/accounts/gkleen@sif/shell/quickshell/ActiveWindowDisplay.qml new file mode 100644 index 00000000..57ade488 --- /dev/null +++ b/accounts/gkleen@sif/shell/quickshell/ActiveWindowDisplay.qml | |||
@@ -0,0 +1,94 @@ | |||
1 | import QtQuick | ||
2 | import qs.Services | ||
3 | import Quickshell | ||
4 | import Quickshell.Widgets | ||
5 | |||
6 | Item { | ||
7 | id: activeWindowDisplay | ||
8 | |||
9 | required property int maxWidth | ||
10 | required property var screen | ||
11 | |||
12 | property var activeWindow: { | ||
13 | let currWindowId = Array.from(NiriService.workspaces).find(ws => { | ||
14 | return ws.output === screen.name && ws.is_active; | ||
15 | })?.active_window_id; | ||
16 | |||
17 | return currWindowId ? Array.from(NiriService.windows).find(win => win.id == currWindowId) : null; | ||
18 | } | ||
19 | property var windowEntry: activeWindow ? DesktopEntries.heuristicLookup(activeWindow.app_id) : null | ||
20 | |||
21 | anchors.verticalCenter: parent.verticalCenter | ||
22 | width: activeWindowDisplayContent.width | ||
23 | height: parent.height | ||
24 | |||
25 | Row { | ||
26 | id: activeWindowDisplayContent | ||
27 | |||
28 | width: childrenRect.width | ||
29 | height: parent.height | ||
30 | anchors.verticalCenter: parent.verticalCenter | ||
31 | spacing: 8 | ||
32 | |||
33 | IconImage { | ||
34 | id: activeWindowIcon | ||
35 | |||
36 | height: 14 | ||
37 | width: 14 | ||
38 | |||
39 | anchors.verticalCenter: parent.verticalCenter | ||
40 | |||
41 | source: { | ||
42 | let icon = activeWindowDisplay.windowEntry?.icon | ||
43 | if (typeof icon === 'string' || icon instanceof String) { | ||
44 | if (icon.includes("?path=")) { | ||
45 | const split = icon.split("?path=") | ||
46 | if (split.length !== 2) | ||
47 | return icon | ||
48 | const name = split[0] | ||
49 | const path = split[1] | ||
50 | const fileName = name.substring( | ||
51 | name.lastIndexOf("/") + 1) | ||
52 | return `file://${path}/${fileName}` | ||
53 | } else | ||
54 | icon = Quickshell.iconPath(icon); | ||
55 | return icon | ||
56 | } | ||
57 | return "" | ||
58 | } | ||
59 | asynchronous: true | ||
60 | smooth: true | ||
61 | mipmap: true | ||
62 | } | ||
63 | |||
64 | Text { | ||
65 | id: windowTitle | ||
66 | |||
67 | width: Math.min(implicitWidth, activeWindowDisplay.maxWidth - activeWindowIcon.width - activeWindowDisplayContent.spacing) | ||
68 | |||
69 | property var appAliases: { "Firefox": "Mozilla Firefox", "mpv Media Player": "mpv", "Thunderbird": "Mozilla Thunderbird", "Thunderbird (LMU)": "Mozilla Thunderbird" } | ||
70 | |||
71 | elide: Text.ElideRight | ||
72 | maximumLineCount: 1 | ||
73 | color: "white" | ||
74 | anchors.verticalCenter: parent.verticalCenter | ||
75 | text: { | ||
76 | if (!activeWindowDisplay.activeWindow) | ||
77 | return ""; | ||
78 | |||
79 | var title = activeWindowDisplay.activeWindow.title; | ||
80 | var appName = activeWindowDisplay.windowEntry?.name; | ||
81 | if (appAliases[appName]) | ||
82 | appName = appAliases[appName]; | ||
83 | if (appName && title.endsWith(appName)) { | ||
84 | const oldTitle = title; | ||
85 | title = title.substring(0, title.length - appName.length); | ||
86 | title = title.replace(/\s*(—|-)\s*$/, ""); | ||
87 | if (!title) | ||
88 | title = oldTitle; | ||
89 | } | ||
90 | return title; | ||
91 | } | ||
92 | } | ||
93 | } | ||
94 | } | ||