diff options
Diffstat (limited to 'accounts/gkleen@sif/shell/quickshell/ActiveWindowDisplay.qml')
-rw-r--r-- | accounts/gkleen@sif/shell/quickshell/ActiveWindowDisplay.qml | 188 |
1 files changed, 133 insertions, 55 deletions
diff --git a/accounts/gkleen@sif/shell/quickshell/ActiveWindowDisplay.qml b/accounts/gkleen@sif/shell/quickshell/ActiveWindowDisplay.qml index 57ade488..dcc23279 100644 --- a/accounts/gkleen@sif/shell/quickshell/ActiveWindowDisplay.qml +++ b/accounts/gkleen@sif/shell/quickshell/ActiveWindowDisplay.qml | |||
@@ -22,72 +22,150 @@ Item { | |||
22 | width: activeWindowDisplayContent.width | 22 | width: activeWindowDisplayContent.width |
23 | height: parent.height | 23 | height: parent.height |
24 | 24 | ||
25 | Row { | 25 | WrapperMouseArea { |
26 | id: activeWindowDisplayContent | 26 | id: widgetMouseArea |
27 | 27 | ||
28 | width: childrenRect.width | 28 | anchors.fill: parent |
29 | height: parent.height | ||
30 | anchors.verticalCenter: parent.verticalCenter | ||
31 | spacing: 8 | ||
32 | 29 | ||
33 | IconImage { | 30 | hoverEnabled: true |
34 | id: activeWindowIcon | ||
35 | 31 | ||
36 | height: 14 | 32 | Item { |
37 | width: 14 | 33 | anchors.fill: parent |
38 | 34 | ||
39 | anchors.verticalCenter: parent.verticalCenter | 35 | Row { |
36 | id: activeWindowDisplayContent | ||
40 | 37 | ||
41 | source: { | 38 | width: childrenRect.width |
42 | let icon = activeWindowDisplay.windowEntry?.icon | 39 | height: parent.height |
43 | if (typeof icon === 'string' || icon instanceof String) { | 40 | anchors.verticalCenter: parent.verticalCenter |
44 | if (icon.includes("?path=")) { | 41 | spacing: 8 |
45 | const split = icon.split("?path=") | 42 | |
46 | if (split.length !== 2) | 43 | IconImage { |
44 | id: activeWindowIcon | ||
45 | |||
46 | implicitSize: 14 | ||
47 | |||
48 | anchors.verticalCenter: parent.verticalCenter | ||
49 | |||
50 | source: { | ||
51 | let icon = activeWindowDisplay.windowEntry?.icon | ||
52 | if (typeof icon === 'string' || icon instanceof String) { | ||
53 | if (icon.includes("?path=")) { | ||
54 | const split = icon.split("?path=") | ||
55 | if (split.length !== 2) | ||
56 | return icon | ||
57 | const name = split[0] | ||
58 | const path = split[1] | ||
59 | const fileName = name.substring( | ||
60 | name.lastIndexOf("/") + 1) | ||
61 | return `file://${path}/${fileName}` | ||
62 | } else | ||
63 | icon = Quickshell.iconPath(icon); | ||
47 | return icon | 64 | return icon |
48 | const name = split[0] | 65 | } |
49 | const path = split[1] | 66 | return "" |
50 | const fileName = name.substring( | 67 | } |
51 | name.lastIndexOf("/") + 1) | 68 | asynchronous: true |
52 | return `file://${path}/${fileName}` | 69 | smooth: true |
53 | } else | 70 | mipmap: true |
54 | icon = Quickshell.iconPath(icon); | ||
55 | return icon | ||
56 | } | 71 | } |
57 | return "" | 72 | |
73 | Text { | ||
74 | id: windowTitle | ||
75 | |||
76 | width: Math.min(implicitWidth, activeWindowDisplay.maxWidth - activeWindowIcon.width - activeWindowDisplayContent.spacing) | ||
77 | |||
78 | property var appAliases: { "Firefox": "Mozilla Firefox", "mpv Media Player": "mpv", "Thunderbird": "Mozilla Thunderbird", "Thunderbird (LMU)": "Mozilla Thunderbird" } | ||
79 | |||
80 | elide: Text.ElideRight | ||
81 | maximumLineCount: 1 | ||
82 | color: "white" | ||
83 | anchors.verticalCenter: parent.verticalCenter | ||
84 | text: { | ||
85 | if (!activeWindowDisplay.activeWindow) | ||
86 | return ""; | ||
87 | |||
88 | var title = activeWindowDisplay.activeWindow.title; | ||
89 | var appName = activeWindowDisplay.windowEntry?.name; | ||
90 | if (appAliases[appName]) | ||
91 | appName = appAliases[appName]; | ||
92 | if (appName && title.endsWith(appName)) { | ||
93 | const oldTitle = title; | ||
94 | title = title.substring(0, title.length - appName.length); | ||
95 | title = title.replace(/\s*(—|-)\s*$/, ""); | ||
96 | if (!title) | ||
97 | title = oldTitle; | ||
98 | } | ||
99 | return title; | ||
100 | } | ||
101 | } | ||
102 | } | ||
103 | } | ||
104 | } | ||
105 | |||
106 | Loader { | ||
107 | id: tooltipLoader | ||
108 | |||
109 | active: false | ||
110 | |||
111 | Connections { | ||
112 | target: widgetMouseArea | ||
113 | function onContainsMouseChanged() { | ||
114 | if (widgetMouseArea.containsMouse) | ||
115 | tooltipLoader.active = true; | ||
58 | } | 116 | } |
59 | asynchronous: true | ||
60 | smooth: true | ||
61 | mipmap: true | ||
62 | } | 117 | } |
63 | 118 | ||
64 | Text { | 119 | PopupWindow { |
65 | id: windowTitle | 120 | id: tooltip |
66 | 121 | ||
67 | width: Math.min(implicitWidth, activeWindowDisplay.maxWidth - activeWindowIcon.width - activeWindowDisplayContent.spacing) | 122 | property bool nextVisible: widgetMouseArea.containsMouse || tooltipMouseArea.containsMouse |
68 | 123 | ||
69 | property var appAliases: { "Firefox": "Mozilla Firefox", "mpv Media Player": "mpv", "Thunderbird": "Mozilla Thunderbird", "Thunderbird (LMU)": "Mozilla Thunderbird" } | 124 | anchor { |
70 | 125 | item: widgetMouseArea | |
71 | elide: Text.ElideRight | 126 | edges: Edges.Bottom | Edges.Left |
72 | maximumLineCount: 1 | 127 | } |
73 | color: "white" | 128 | visible: false |
74 | anchors.verticalCenter: parent.verticalCenter | 129 | |
75 | text: { | 130 | onNextVisibleChanged: hangTimer.restart() |
76 | if (!activeWindowDisplay.activeWindow) | 131 | |
77 | return ""; | 132 | Timer { |
78 | 133 | id: hangTimer | |
79 | var title = activeWindowDisplay.activeWindow.title; | 134 | interval: tooltip.visible ? 100 : 500 |
80 | var appName = activeWindowDisplay.windowEntry?.name; | 135 | onTriggered: { |
81 | if (appAliases[appName]) | 136 | tooltip.visible = tooltip.nextVisible; |
82 | appName = appAliases[appName]; | 137 | if (!tooltip.visible) |
83 | if (appName && title.endsWith(appName)) { | 138 | tooltipLoader.active = false; |
84 | const oldTitle = title; | 139 | } |
85 | title = title.substring(0, title.length - appName.length); | 140 | } |
86 | title = title.replace(/\s*(—|-)\s*$/, ""); | 141 | |
87 | if (!title) | 142 | implicitWidth: widgetTooltipText.contentWidth + 16 |
88 | title = oldTitle; | 143 | implicitHeight: widgetTooltipText.contentHeight + 16 |
144 | color: "black" | ||
145 | |||
146 | WrapperMouseArea { | ||
147 | id: tooltipMouseArea | ||
148 | |||
149 | hoverEnabled: true | ||
150 | enabled: true | ||
151 | |||
152 | anchors.fill: parent | ||
153 | |||
154 | Item { | ||
155 | anchors.fill: parent | ||
156 | |||
157 | Text { | ||
158 | id: widgetTooltipText | ||
159 | |||
160 | anchors.centerIn: parent | ||
161 | |||
162 | font.pointSize: 10 | ||
163 | font.family: "Fira Mono" | ||
164 | color: "white" | ||
165 | |||
166 | text: JSON.stringify(Object.assign({}, activeWindowDisplay.activeWindow), null, 2) | ||
167 | } | ||
89 | } | 168 | } |
90 | return title; | ||
91 | } | 169 | } |
92 | } | 170 | } |
93 | } | 171 | } |