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