blob: 1fa27a71c381bc2050fe7ddba2c3c53ebf551c18 (
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
|
import Quickshell
import Quickshell.Widgets
import QtQuick
import QtQuick.Layouts
import qs.components
import qs.services
import qs.config
IComponent {
id: root
property list<DesktopEntry> entries: AppSearch.query(inputCleaned)
property int selectedIndex: -1
name: "Applications"
implicitHeight: valid ? layout.height : 0
preview: Component {
IconImage {
source: Quickshell.iconPath(answer, "image-missing")
implicitWidth: General.appIconSize
implicitHeight: General.appIconSize
}
}
property string predictiveCompletion: entries[selectedIndex]?.name.slice(input.length) || ""
process: function () {
const valid = entries.length > 0;
// TODO: consider removing the valid check
const selected = valid ? entries[selectedIndex] : "";
return {
valid,
priority: valid,
answer: selected?.icon || ""
};
}
exec: function () {
SelectionState.selected?.modelData?.execute();
}
up: function () {
if (selectedIndex <= 0)
return true;
selectedIndex--;
}
down: function () {
if (selectedIndex + 1 > listView.count - 1)
return true;
selectedIndex++;
}
home: function () {
if (selectedIndex <= 0)
return true;
selectedIndex = 0;
}
end: function () {
if (selectedIndex + 1 > listView.count - 1)
return true;
selectedIndex = listView.count - 1;
}
pgup: function () {
if (selectedIndex <= 0)
return true;
const pageSize = Math.floor(listView.height / (General.appIconSize + Launcher.innerMargin * 2));
if (selectedIndex - pageSize < 0)
selectedIndex = 0;
else
selectedIndex -= pageSize;
}
pgdn: function () {
if (selectedIndex === entries.length - 1)
return true;
const pageSize = Math.floor(listView.height / (General.appIconSize + Launcher.innerMargin * 2));
if (selectedIndex + pageSize >= listView.count) {
selectedIndex = listView.count - 1;
} else {
selectedIndex += pageSize;
}
}
onEntriesChanged: {
if (selectedIndex !== -1) {
if (selectedIndex > entries.length - 1)
selectedIndex = entries.length - 1;
syncSelectionState();
return;
}
selectedIndex = 0;
syncSelectionState();
}
onSelectedIndexChanged: {
Qt.callLater(() => {
// so at least it exist
listView.scrollToIndex(selectedIndex, ListView.Visible);
syncSelectionState();
listView.scrollToIndex(selectedIndex, ListView.Contain);
});
}
syncSelectionState: function () {
Qt.callLater(() => {
if (selectedIndex < 0 || selectedIndex >= listView.count || !root.visible)
return;
state.selected = listView.itemAtIndex(selectedIndex);
});
}
IInnerComponent {
id: layout
fromParent: false
width: parent.width
height: Math.min(listView.contentHeight + titleBar.height, Launcher.widgetHeight * 1.5)
IListView {
id: listView
Layout.fillWidth: true
Layout.fillHeight: true
clip: true
model: entries
spacing: 0
highlightMoveDuration: 500
delegate: Item {
required property DesktopEntry modelData
required property int index
visible: modelData !== null
width: item.implicitWidth + Launcher.innerMargin * 4
height: item.height + Launcher.innerMargin * 4
RowLayout {
id: item
scale: root.isSelectedPriority() && index === selectedIndex ? 1.01 : 0.99
anchors.left: parent.left
anchors.top: parent.top
anchors.margins: Launcher.innerMargin * 2
spacing: Launcher.innerMargin * 2
IconImage {
source: modelData ? Quickshell.iconPath(modelData.icon, "image-missing") : ""
implicitWidth: General.appIconSize
implicitHeight: General.appIconSize
}
IText {
text: modelData ? modelData.name : ""
renderType: Text.QtRendering
font.bold: root.isSelectedPriority() && index === selectedIndex
color: root.isSelectedPriority() && index === selectedIndex ? Colors.foreground1 : Colors.foreground2
Behavior on color {
ColorAnimation {
duration: General.animationDuration
easing.type: Easing.InOutQuad
}
}
}
Behavior on scale {
ISpringAnimation {}
}
}
IMouseArea {
anchors.fill: parent
hoverEnabled: true
onEntered_: {
root.selectedIndex = index;
}
onPressed: {
root._exec();
}
}
}
onContentYChanged: {
SelectionState.syncSelectionState();
}
}
}
}
|