blob: f903f1fb8c130238afa41531ac681692246c9149 (
plain)
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
|
import QtQuick
import QtQuick.Controls
import Quickshell
import Quickshell.Io
Rectangle {
id: appLauncher
width: 400
height: 600
color: shellRoot.black
antialiasing: true
property bool isVisible: false
property int hoverIndex: 0
property var apps: []
signal requestClose()
focus: true
Keys.onEscapePressed: requestClose()
Keys.onUpPressed: {
hoverIndex--;
if (hoverIndex < 0) hoverIndex += appListModel.count;
listView.positionViewAtIndex(hoverIndex, ListView.Contain);
}
Keys.onDownPressed: {
hoverIndex = (hoverIndex + 1) % appListModel.count;
listView.positionViewAtIndex(hoverIndex, ListView.Contain);
}
Keys.onReturnPressed: {
if (hoverIndex >= 0 && hoverIndex < appListModel.count) {
launchApp(appListModel.get(hoverIndex).appCommand)
console.log(appListModel.get(hoverIndex).appCommand)
}
}
Keys.onEnterPressed: {
if (hoverIndex >= 0 && hoverIndex < appListModel.count) {
launchApp(appListModel.get(hoverIndex).appCommand)
console.log(appListModel.get(hoverIndex).appCommand)
}
}
onIsVisibleChanged: {
if (!isVisible) return;
hoverIndex = 0;
appLauncher.forceActiveFocus();
searchInput.forceActiveFocus();
}
Process {
id: appLoader
running: false
command: ["sh", "-c", "~/.config/quickshell/scripts/list-apps.sh"]
stdout: SplitParser {
onRead: data => {
const lines = data.split('\n');
for (const line of lines) {
if (line.trim().length === 0) continue;
const parts = line.split('|');
if (parts.length < 4) continue;
apps.push({
appName: parts[0],
appDescription: parts[1],
appIcon: parts[2],
appCommand: parts[3]
});
}
applySearch("");
}
}
onRunningChanged: {
if (running) return;
appLoader.running = false;
}
}
function loadApps() {
appLoader.running = true;
}
function applySearch(searchString) {
appListModel.clear();
for (const app of apps) {
if (app.appName.toLowerCase().includes(searchString.toLowerCase())) {
appListModel.append(app);
}
}
}
Component.onCompleted: {
loadApps();
}
Column {
anchors.fill: parent
anchors.margins: 12
spacing: 8
Rectangle {
width: parent.width
height: 36
color: "transparent"
Text {
anchors.centerIn: parent
text: "Applications"
font.family: shellRoot.fontFamily
font.pixelSize: 20
font.weight: Font.Medium
color: shellRoot.white
}
Rectangle {
width: 28
height: 28
anchors.right: parent.right
anchors.verticalCenter: parent.verticalCenter
radius: 6
color: closeMouseArea.containsMouse ? shellRoot.red : "transparent"
Text {
anchors.centerIn: parent
text: "✕"
font.family: shellRoot.fontFamily
font.pixelSize: 16
font.weight: Font.Bold
color: closeMouseArea.containsMouse ? shellRoot.white : shellRoot.red
}
MouseArea {
id: closeMouseArea
anchors.fill: parent
hoverEnabled: true
cursorShape: Qt.PointingHandCursor
onClicked: appLauncher.requestClose()
}
}
}
Rectangle {
width: parent.width
height: 36
color: shellRoot.black
border.color: shellRoot.green
border.width: 1
TextInput {
id: searchInput
width: parent.width
anchors.left: parent.left
anchors.right: parent.right
anchors.leftMargin: 8
anchors.rightMargin: 8
anchors.verticalCenter: parent.verticalCenter
color: "white"
font.pixelSize: 14
onTextEdited: {
applySearch(searchInput.text);
hoverIndex = 0;
}
}
}
ListView {
id: listView
width: parent.width
height: parent.height - 88
spacing: 8
clip: true
model: ListModel {
id: appListModel
}
delegate: Rectangle {
width: listView.width
height: 30
color: {
if (appLauncher.hoverIndex === index) return shellRoot.lightgray;
return shellRoot.gray;
}
Row {
anchors.fill: parent
anchors.leftMargin: 12
anchors.rightMargin: 12
anchors.topMargin: 8
anchors.bottomMargin: 8
spacing: 12
Text {
width: parent.width - 62
anchors.centerIn: parent
text: model.appName
font.family: shellRoot.fontFamily
font.pixelSize: 14
font.weight: Font.Medium
color: {
return shellRoot.white;
}
elide: Text.ElideRight
}
}
MouseArea {
id: mouseArea
anchors.fill: parent
hoverEnabled: true
cursorShape: Qt.PointingHandCursor
onEntered: {
appLauncher.hoverIndex = index;
}
onClicked: {
launchApp(model.appCommand);
}
}
}
}
}
function launchApp(command) {
appLauncher.requestClose()
// Use a small delay before launching to ensure the window closes properly
Qt.callLater(() => {
Quickshell.execDetached(["sh", "-c", command + " &"])
})
}
}
|