208 lines
5.9 KiB
QML
208 lines
5.9 KiB
QML
import QtQuick
|
|
import Quickshell
|
|
import Quickshell.Wayland
|
|
import Quickshell.Hyprland
|
|
import Quickshell.Io
|
|
|
|
PanelWindow {
|
|
id: root
|
|
|
|
required property bool shellOpen
|
|
required property bool backgroundMode
|
|
required property list<var> apps
|
|
required property bool enableCacheFolder
|
|
|
|
signal requestClose
|
|
|
|
visible: root.backgroundMode || root.shellOpen
|
|
|
|
color: "transparent"
|
|
|
|
exclusionMode: ExclusionMode.Ignore
|
|
WlrLayershell.namespace: "quickshell:launcher"
|
|
WlrLayershell.layer: root.backgroundMode ? WlrLayer.Bottom : WlrLayer.Overlay
|
|
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) {
|
|
if (!root.backgroundMode)
|
|
root.requestClose();
|
|
return;
|
|
}
|
|
if (app.hyprlandDispatch) {
|
|
Hyprland.dispatch(app.hyprlandDispatch);
|
|
} else {
|
|
launcher.running = false;
|
|
launcher.command = app.exec;
|
|
launcher.running = true;
|
|
}
|
|
if (!root.backgroundMode)
|
|
root.requestClose();
|
|
}
|
|
|
|
Process {
|
|
id: launcher
|
|
running: false
|
|
stdout: SplitParser {
|
|
onRead: (line) => {
|
|
console.log(launcher.command)
|
|
console.log("Captured Output: " + line)
|
|
}
|
|
}
|
|
}
|
|
|
|
onVisibleChanged: {
|
|
if (root.visible) {
|
|
root.selectedIndex = 0;
|
|
Qt.callLater(() => focusScope.forceActiveFocus());
|
|
}
|
|
}
|
|
|
|
HyprlandFocusGrab {
|
|
windows: [root]
|
|
active: root.visible && !root.backgroundMode
|
|
onCleared: {
|
|
if (root.visible && !root.backgroundMode)
|
|
root.requestClose();
|
|
}
|
|
}
|
|
|
|
Rectangle {
|
|
anchors.fill: parent
|
|
color: "#cc0b0e14"
|
|
|
|
MouseArea {
|
|
anchors.fill: parent
|
|
onClicked: {
|
|
if (!root.backgroundMode)
|
|
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:
|
|
if (!root.backgroundMode)
|
|
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
|
|
enableCacheFolder: root.enableCacheFolder
|
|
|
|
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();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|