Repository navigation
Expand file tree
/
Copy pathshell.qml
More file actions
296 lines (266 loc) · 11.1 KB
/
Copy pathshell.qml
File metadata and controls
296 lines (266 loc) · 11.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
import Quickshell
import QtQuick
import Quickshell.Io
import "./config.js" as Config
import "./fonts/MusicTitleFont.js" as MusicTitleFont
import "./fonts/ShinonomeGothic.js" as ShinonomeGothic
import "./fonts/Ramche.js" as Ramche
PanelWindow {
id: deltatune
visible: false
mask: Region {}
anchors {
top: Config.c.anchors.top ?? true
right: Config.c.anchors.right ?? true
bottom: Config.c.anchors.bottom ?? false
left: Config.c.anchors.left ?? false
}
margins {
top: Config.c.margins.top ?? 25
right: Config.c.margins.right ?? 25
bottom: Config.c.margins.bottom ?? 0
left: Config.c.margins.left ?? 0
}
color: Config.c.backgroundColor ?? "transparent"
property real configScale: Config.c.scale ?? 2
implicitWidth: bitmapTitle.width * configScale
implicitHeight: bitmapTitle.height * configScale
property string musicTitleFontImage: "./fonts/MusicTitleFont.png"
property string shinonomeGothicImage: "./fonts/ShinonomeGothic.png"
property string ramcheImage: "./fonts/Ramche.png"
Item {
id: child
width: deltatune.implicitWidth
height: deltatune.implicitHeight
Item {
id: bitmapTitle
property string text: ""
property real characterSpacing: Config.c.characterSpacing ?? 1.2
property string fontImage: "./fonts/MusicTitleFont.png"
property string currentTitle: ""
property string currentStatus: ""
property bool isAnimating: false
property real baseX: deltatune.implicitWidth - width
property real slideOffset: Config.c.slideOffset ?? 30
property real animationDuration: Config.c.animationDuration ?? 600
property real titleDuration: Config.c.titleDuration ?? 7000
width: textRow.width
height: MusicTitleFont.fontInfo.lineHeight
opacity: 0.0
x: baseX + slideOffset
Behavior on opacity {
enabled: !bitmapTitle.isAnimating
NumberAnimation {
duration: bitmapTitle.animationDuration
easing.type: Easing.InOutQuad
onRunningChanged: {
if (!running && bitmapTitle.opacity === 0.0) {
bitmapTitle.x = bitmapTitle.baseX - bitmapTitle.slideOffset;
}
}
}
}
Behavior on x {
enabled: !bitmapTitle.isAnimating
NumberAnimation {
duration: bitmapTitle.animationDuration
easing.type: Easing.InOutQuad
}
}
function getFontForChar(charCode) {
if (charCode === 32) {
return {
charMap: {},
getCharData: function (code) {
return {
x: 0,
y: 0,
width: 3.5,
height: 19,
xoffset: 0,
yoffset: 0,
xadvance: 10
};
},
fontImage: "" // no image for space
};
} else
// Musical note and basic ASCII (English) - use MusicTitleFont
if (charCode === 9834 || (charCode >= 33 && charCode <= 126)) {
return {
charMap: MusicTitleFont.charMap,
getCharData: MusicTitleFont.getCharData,
fontImage: musicTitleFontImage
};
} else
// Hiragana, Katakana, Kanji ranges (Japanese) - use ShinonomeGothic
if ((charCode >= 0x3040 && charCode <= 0x309F) || // Hiragana
(charCode >= 0x30A0 && charCode <= 0x30FF) || // Katakana
(charCode >= 0x4E00 && charCode <= 0x9FAF)) {
// CJK Unified Ideographs
return {
charMap: ShinonomeGothic.charMap,
getCharData: function (code) {
var data = ShinonomeGothic.getCharData(code);
// Push Japanese characters down by 5 pixels (will be scaled 2x to 10px)
return {
x: data.x,
y: data.y,
width: data.width,
height: data.height,
xoffset: data.xoffset,
yoffset: data.yoffset + 5,
xadvance: data.xadvance
};
},
fontImage: shinonomeGothicImage
};
} else
// Hangul ranges (Korean) - use Ramche
if ((charCode >= 0xAC00 && charCode <= 0xD7AF) || // Hangul Syllables
(charCode >= 0x1100 && charCode <= 0x11FF) || // Hangul Jamo
(charCode >= 0x3130 && charCode <= 0x318F)) {
// Hangul Compatibility Jamo
return {
charMap: Ramche.charMap,
getCharData: function (code) {
var data = Ramche.getCharData(code);
// Push Korean characters down by 5 pixels (will be scaled 2x to 10px)
return {
x: data.x,
y: data.y,
width: data.width,
height: data.height,
xoffset: data.xoffset,
yoffset: data.yoffset + 5,
xadvance: data.xadvance
};
},
fontImage: ramcheImage
};
} else
// Default fallback to MusicTitleFont
{
return {
charMap: MusicTitleFont.charMap,
getCharData: MusicTitleFont.getCharData,
fontImage: musicTitleFontImage
};
}
}
Row {
id: textRow
spacing: bitmapTitle.characterSpacing
Repeater {
model: bitmapTitle.text.length
Image {
property int charCode: bitmapTitle.text.charCodeAt(index)
property var fontData: bitmapTitle.getFontForChar(charCode)
property var charData: fontData.getCharData(charCode)
property real configScale: Config.c.scale ?? 2
source: fontData.fontImage
sourceClipRect: Qt.rect(charData.x, charData.y, charData.width, charData.height)
width: charData.width * configScale
height: charData.height * configScale
x: charData.xoffset * configScale
y: charData.yoffset // * configScale
smooth: false
}
}
}
function updateMusicInfo() {
var statusProc = Qt.createQmlObject(`
import Quickshell.Io
Process {
id: proc
command: ["playerctl", "status"]
running: true
stdout: StdioCollector {
onStreamFinished: {
bitmapTitle.currentStatus = this.text.trim();
bitmapTitle.checkTitleUpdate();
proc.destroy();
}
}
}
`, bitmapTitle);
}
function checkTitleUpdate() {
if (currentStatus === "Playing") {
var titleProc = Qt.createQmlObject(`
import Quickshell.Io
Process {
id: proc
command: ["playerctl", "metadata", "xesam:title"]
running: true
stdout: StdioCollector {
onStreamFinished: {
var newTitle = this.text.trim();
if (newTitle.length > 0 && newTitle !== bitmapTitle.currentTitle) {
bitmapTitle.currentTitle = newTitle;
bitmapTitle.text = "♪ ~ " + newTitle;
bitmapTitle.showTitle();
} else if (newTitle.length === 0) {
bitmapTitle.hideTitle();
}
proc.destroy();
}
}
}
`, bitmapTitle);
} else {
hideTitle();
}
}
function showTitle() {
hideTimer.stop();
hideWindowTimer.stop();
isAnimating = true;
deltatune.visible = true;
opacity = 0.0;
x = baseX - slideOffset;
showAnimationTimer.start();
}
Timer {
id: showAnimationTimer
interval: 10
repeat: false
onTriggered: {
bitmapTitle.isAnimating = false;
bitmapTitle.opacity = 1.0;
bitmapTitle.x = bitmapTitle.baseX;
hideTimer.restart();
}
}
function hideTitle() {
hideTimer.stop();
showAnimationTimer.stop();
isAnimating = false;
opacity = 0.0;
x = baseX - slideOffset;
hideWindowTimer.restart();
}
Timer {
id: hideTimer
interval: bitmapTitle.titleDuration
running: false
repeat: false
onTriggered: bitmapTitle.hideTitle()
}
Timer {
interval: 1000
running: true
repeat: true
onTriggered: bitmapTitle.updateMusicInfo()
}
Timer {
id: hideWindowTimer
interval: Math.max(50, bitmapTitle.animationDuration + 20)
running: false
repeat: false
onTriggered: deltatune.visible = false
}
Component.onCompleted: updateMusicInfo()
}
}
}