164 lines
4.7 KiB
QML
164 lines
4.7 KiB
QML
import QtQuick
|
|
import Quickshell
|
|
import Quickshell.Wayland
|
|
import Quickshell.Hyprland
|
|
|
|
PanelWindow {
|
|
id: root
|
|
|
|
required property bool shellOpen
|
|
required property list<App> apps
|
|
|
|
signal requestClose()
|
|
|
|
visible: root.shellOpen
|
|
|
|
color: "transparent"
|
|
|
|
WlrLayershell.namespace: "quickshell:launcher"
|
|
WlrLayershell.layer: WlrLayer.Overlay
|
|
WlrLayershell.exclusiveZone: -1
|
|
WlrLayershell.keyboardFocus: root.visible ? WlrKeyboardFocus.OnDemand : WlrKeyboardFocus.None
|
|
|
|
anchors {
|
|
top: true
|
|
left: true
|
|
right: true
|
|
bottom: true
|
|
}
|
|
|
|
property Theme theme: Theme {}
|
|
|
|
property int selectedIndex: 0
|
|
|
|
readonly property int centerIndex: root.selectedIndex
|
|
|
|
function clampSelection() {
|
|
if (root.apps.length === 0) return;
|
|
if (root.selectedIndex >= root.apps.length) root.selectedIndex = root.apps.length - 1;
|
|
if (root.selectedIndex < 0) root.selectedIndex = 0;
|
|
}
|
|
|
|
function moveSelection(delta) {
|
|
if (root.apps.length === 0) return;
|
|
root.selectedIndex = (root.selectedIndex + delta + root.apps.length) % root.apps.length;
|
|
}
|
|
|
|
function activateSelection() {
|
|
const app = root.apps[root.selectedIndex];
|
|
if (!app) { root.requestClose(); return; }
|
|
Quickshell.execDetached(app.exec);
|
|
root.requestClose();
|
|
}
|
|
|
|
onVisibleChanged: {
|
|
if (root.visible) {
|
|
root.selectedIndex = 0;
|
|
Qt.callLater(() => focusScope.forceActiveFocus());
|
|
}
|
|
}
|
|
|
|
HyprlandFocusGrab {
|
|
windows: [root]
|
|
active: root.visible
|
|
onCleared: {
|
|
if (root.visible) root.requestClose();
|
|
}
|
|
}
|
|
|
|
Rectangle {
|
|
anchors.fill: parent
|
|
color: "#cc0b0e14"
|
|
|
|
MouseArea {
|
|
anchors.fill: parent
|
|
onClicked: root.requestClose()
|
|
}
|
|
}
|
|
|
|
FocusScope {
|
|
id: focusScope
|
|
anchors.fill: parent
|
|
focus: root.visible
|
|
|
|
Keys.onPressed: event => {
|
|
switch (event.key) {
|
|
case Qt.Key_Left:
|
|
root.moveSelection(-1);
|
|
break;
|
|
case Qt.Key_Right:
|
|
root.moveSelection(1);
|
|
break;
|
|
case Qt.Key_Return:
|
|
case Qt.Key_Enter:
|
|
root.activateSelection();
|
|
break;
|
|
case Qt.Key_Escape:
|
|
root.requestClose();
|
|
break;
|
|
default:
|
|
return;
|
|
}
|
|
event.accepted = true;
|
|
}
|
|
|
|
WheelHandler {
|
|
id: swipeHandler
|
|
target: focusScope
|
|
property real accX: 0
|
|
|
|
function step(delta) {
|
|
root.moveSelection(delta);
|
|
swipeHandler.accX = 0;
|
|
}
|
|
|
|
onWheel: event => {
|
|
const px = event.pixelDelta;
|
|
const ang = event.angleDelta;
|
|
const dx = px.x !== 0 ? px.x : ang.x;
|
|
swipeHandler.accX += dx;
|
|
if (swipeHandler.accX <= -root.theme.swipeThreshold) swipeHandler.step(1);
|
|
else if (swipeHandler.accX >= root.theme.swipeThreshold) swipeHandler.step(-1);
|
|
}
|
|
}
|
|
|
|
Item {
|
|
anchors.fill: parent
|
|
|
|
Repeater {
|
|
model: root.apps
|
|
|
|
AppButton {
|
|
required property var modelData
|
|
required property int index
|
|
|
|
theme: root.theme
|
|
app: modelData
|
|
selected: index === root.selectedIndex
|
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
anchors.horizontalCenterOffset: (index - root.centerIndex) * root.theme.carouselStepX
|
|
opacity: 1 - Math.min(Math.abs(index - root.centerIndex) * root.theme.carouselFadeStep, root.theme.carouselMaxFade)
|
|
scale: 1 - Math.min(Math.abs(index - root.centerIndex) * root.theme.carouselScaleStep, root.theme.carouselMaxScaleReduction)
|
|
|
|
Behavior on anchors.horizontalCenterOffset {
|
|
NumberAnimation { duration: root.theme.carouselDuration; easing.type: Easing.OutCubic }
|
|
}
|
|
Behavior on opacity {
|
|
NumberAnimation { duration: root.theme.carouselDuration }
|
|
}
|
|
Behavior on scale {
|
|
NumberAnimation { duration: root.theme.carouselDuration }
|
|
}
|
|
|
|
onActivated: {
|
|
root.selectedIndex = index;
|
|
root.activateSelection();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|