repositories / dotfiles
dotfiles
bugabingas dorkfiles
owned by bugabinga
quickshell/nuguland/LauncherPanel.qml
Rawpragma ComponentBehavior: Bound
import QtQuick
import Quickshell
import Quickshell.Widgets
import "Util.js" as Util
FocusScope {
id: root
required property Theme theme
required property Launcher launcherService
required property SurfaceManager surfaces
property string query: ""
property var panelState: launcherService ? Util.parseJson(launcherService.search(query), {
"results": [],
"selectedIndex": -1,
"providerIntent": "app",
"query": ""
}) : ({
"results": [],
"selectedIndex": -1,
"providerIntent": "app",
"query": ""
})
readonly property var results: panelState.results || []
readonly property int selectedIndex: Math.max(0, Math.min(results.length - 1, Number(panelState.selectedIndex || 0)))
readonly property var selectedRow: results.length > 0 ? results[selectedIndex] : ({})
readonly property var selectedActions: selectedRow.actions || []
readonly property var selectedDetails: selectedRow.details || []
readonly property int rowHeight: 52
readonly property int rowSpacing: 4
readonly property int rowStride: rowHeight + rowSpacing
readonly property int rightWidth: Math.min(300, Math.max(260, Math.round(width * 0.36)))
function refresh() {
if (launcherService)
panelState = Util.parseJson(launcherService.search(query), panelState);
}
function setQuery(text) {
query = String(text || "");
refresh();
}
function close() {
if (surfaces)
surfaces.closePopout("launcher-activated");
}
function activateSelected() {
if (!launcherService || results.length === 0)
return;
launcherService.activate(JSON.stringify(selectedRow));
close();
}
function activateAction(index) {
if (!launcherService || results.length === 0 || index < 0 || index >= selectedActions.length)
return;
launcherService.activateAction(JSON.stringify(selectedRow), index);
close();
}
function select(index) {
if (results.length === 0)
return;
const i = Math.max(0, Math.min(results.length - 1, Number(index)));
const next = Object.assign({}, panelState);
next.selectedIndex = i;
panelState = next;
const top = i * rowStride;
const bottom = top + rowHeight;
if (top < resultsFlick.contentY)
resultsFlick.contentY = top;
else if (bottom > resultsFlick.contentY + resultsFlick.height)
resultsFlick.contentY = bottom - resultsFlick.height;
}
function wheelSelect(deltaY) {
if (results.length <= 1)
return;
const direction = Number(deltaY) >= 0 ? -1 : 1;
select(selectedIndex + direction);
}
function keyAction(event) {
if (event.modifiers & Qt.ControlModifier) {
const n = Number(event.text);
if (n >= 1 && n <= selectedActions.length) {
event.accepted = true;
activateAction(n - 1);
}
}
}
width: parent ? parent.width : 0
height: parent ? parent.height : 0
focus: true
Component.onCompleted: Qt.callLater(searchInput.forceActiveFocus)
onVisibleChanged: if (visible)
Qt.callLater(searchInput.forceActiveFocus)
Keys.onUpPressed: event => {
event.accepted = true;
select(selectedIndex - 1);
}
Keys.onDownPressed: event => {
event.accepted = true;
select(selectedIndex + 1);
}
Keys.onReturnPressed: event => {
event.accepted = true;
activateSelected();
}
Keys.onEnterPressed: event => {
event.accepted = true;
activateSelected();
}
Keys.onPressed: event => keyAction(event)
WheelHandler {
target: root
onWheel: event => {
event.accepted = true;
root.wheelSelect(event.angleDelta.y);
}
}
Rectangle {
anchors.fill: parent
radius: 14
color: root.theme ? root.theme.ui.backdrop : "#242424"
border.width: 1
border.color: root.theme ? root.theme.withAlpha(root.theme.ui.normal, 0.34) : "#666666"
}
Rectangle {
anchors.left: parent.left
anchors.right: parent.right
anchors.bottom: parent.bottom
height: 3
color: root.theme ? root.theme.ui.accent : "#d86dd8"
}
Row {
anchors.fill: parent
anchors.margins: 1
Item {
width: Math.max(1, parent.width - root.rightWidth)
height: parent.height
Rectangle {
id: searchBox
anchors.left: parent.left
anchors.right: parent.right
anchors.top: parent.top
height: 66
color: "transparent"
Text {
anchors.left: parent.left
anchors.leftMargin: 20
anchors.verticalCenter: parent.verticalCenter
text: "⌕"
color: root.theme ? root.theme.ui.accent : "#d86dd8"
font.pixelSize: 21
}
TextInput {
id: searchInput
anchors.left: parent.left
anchors.leftMargin: 60
anchors.right: parent.right
anchors.rightMargin: 18
anchors.verticalCenter: parent.verticalCenter
color: root.theme ? root.theme.content.normal : "white"
selectionColor: root.theme ? root.theme.ui.focus : "#ffffff"
selectedTextColor: root.theme ? root.theme.content.backdrop : "black"
font.family: "IBM Plex Mono"
font.pixelSize: 25
text: root.query
focus: true
clip: true
onTextChanged: {
if (text !== root.query)
root.setQuery(text);
}
onAccepted: root.activateSelected()
Keys.onUpPressed: event => {
event.accepted = true;
root.select(root.selectedIndex - 1);
}
Keys.onDownPressed: event => {
event.accepted = true;
root.select(root.selectedIndex + 1);
}
Keys.onReturnPressed: event => {
event.accepted = true;
root.activateSelected();
}
Keys.onEnterPressed: event => {
event.accepted = true;
root.activateSelected();
}
Keys.onPressed: event => root.keyAction(event)
}
Rectangle {
anchors.left: parent.left
anchors.right: parent.right
anchors.bottom: parent.bottom
height: 1
color: root.theme ? root.theme.withAlpha(root.theme.ui.normal, 0.22) : "#444444"
}
}
Flickable {
id: resultsFlick
objectName: "launcherResultList"
anchors.left: parent.left
anchors.right: parent.right
anchors.top: searchBox.bottom
anchors.bottom: parent.bottom
anchors.margins: 8
contentHeight: resultColumn.implicitHeight
interactive: false
clip: true
boundsBehavior: Flickable.StopAtBounds
Behavior on contentY {
NumberAnimation {
duration: root.theme && root.theme.lowPowerMode ? 0 : 120
easing.type: Easing.OutCubic
}
}
Column {
id: resultColumn
width: resultsFlick.width
spacing: root.rowSpacing
Repeater {
model: root.results.slice(0, 60)
delegate: Rectangle {
id: rrow
required property int index
required property var modelData
readonly property bool isSelected: index === root.selectedIndex
width: parent.width
height: root.rowHeight
radius: 11
color: root.theme ? (isSelected ? root.theme.ui.focus : "transparent") : (isSelected ? "#9aabae" : "transparent")
Item {
id: iconSlot
anchors.left: parent.left
anchors.leftMargin: 11
anchors.verticalCenter: parent.verticalCenter
width: 30
height: 30
Rectangle {
anchors.fill: parent
radius: 8
color: root.theme ? root.theme.content.backdrop : "#121212"
}
IconImage {
id: appIcon
anchors.fill: parent
anchors.margins: 4
visible: appIcon.status === Image.Ready
source: String(rrow.modelData.icon || "").length > 0 ? Quickshell.iconPath(String(rrow.modelData.icon), true) : ""
}
Text {
anchors.centerIn: parent
visible: !appIcon.visible
text: String(rrow.modelData.glyph || "")
font.family: "Symbols Nerd Font Mono"
font.pixelSize: 17
color: root.theme ? root.theme.ui.accent : "#d86dd8"
}
}
Column {
anchors.left: iconSlot.right
anchors.leftMargin: 12
anchors.right: ordinal.left
anchors.rightMargin: 10
anchors.verticalCenter: parent.verticalCenter
spacing: 2
NuguText {
theme: root.theme
selected: rrow.isSelected
text: rrow.modelData.title || rrow.modelData.id || "app"
width: parent.width
}
NuguText {
theme: root.theme
variant: "meta"
selected: rrow.isSelected
text: rrow.modelData.subtitle || rrow.modelData.comment || rrow.modelData.desktopId || "app"
width: parent.width
opacity: rrow.isSelected ? 0.82 : 0.72
}
}
NuguText {
id: ordinal
anchors.right: parent.right
anchors.rightMargin: 12
anchors.verticalCenter: parent.verticalCenter
theme: root.theme
variant: "mono"
selected: rrow.isSelected
text: rrow.index === 0 ? "enter" : String(rrow.index + 1)
width: 42
horizontalAlignment: Text.AlignRight
opacity: rrow.isSelected ? 0.8 : 0.52
}
MouseArea {
anchors.fill: parent
onClicked: root.select(rrow.index)
onDoubleClicked: root.activateSelected()
onWheel: wheel => {
wheel.accepted = true;
root.wheelSelect(wheel.angleDelta.y);
}
}
}
}
}
}
}
Rectangle {
width: root.rightWidth
height: parent.height
color: "transparent"
border.width: 0
Rectangle {
anchors.left: parent.left
anchors.top: parent.top
anchors.bottom: parent.bottom
width: 1
color: root.theme ? root.theme.withAlpha(root.theme.ui.normal, 0.22) : "#444444"
}
Column {
anchors.fill: parent
anchors.margins: 22
spacing: 6
Row {
width: parent.width
height: 58
spacing: 14
Item {
width: 56
height: 56
Rectangle {
anchors.fill: parent
radius: 15
color: root.theme ? root.theme.content.backdrop : "#121212"
}
IconImage {
id: detailIcon
anchors.fill: parent
anchors.margins: 8
visible: detailIcon.status === Image.Ready
source: String(root.selectedRow.icon || "").length > 0 ? Quickshell.iconPath(String(root.selectedRow.icon), true) : ""
}
Text {
anchors.centerIn: parent
visible: !detailIcon.visible
text: String(root.selectedRow.glyph || "")
font.family: "Symbols Nerd Font Mono"
font.pixelSize: 27
color: root.theme ? root.theme.ui.accent : "#d86dd8"
}
}
Column {
width: Math.max(1, parent.width - 70)
anchors.verticalCenter: parent.verticalCenter
spacing: 3
NuguText {
theme: root.theme
variant: "title"
text: root.selectedRow.title || "No apps"
width: parent.width
font.pixelSize: 22
}
NuguText {
theme: root.theme
variant: "mono"
text: root.selectedRow.genericName || root.selectedRow.desktopId || "app"
width: parent.width
opacity: 0.62
}
}
}
NuguText {
theme: root.theme
variant: "mono"
text: "actions"
width: parent.width
topPadding: 24
bottomPadding: 8
opacity: 0.68
}
Rectangle {
width: parent.width
height: 42
radius: 11
color: root.theme ? root.theme.content.backdrop : "#121212"
NuguText {
anchors.left: parent.left
anchors.leftMargin: 12
anchors.verticalCenter: parent.verticalCenter
theme: root.theme
text: "open"
width: parent.width - 78
}
NuguText {
anchors.right: parent.right
anchors.rightMargin: 12
anchors.verticalCenter: parent.verticalCenter
theme: root.theme
variant: "mono"
text: "enter"
width: 52
horizontalAlignment: Text.AlignRight
opacity: 0.7
}
MouseArea {
anchors.fill: parent
onClicked: root.activateSelected()
}
}
Repeater {
model: root.selectedActions.slice(0, 4)
delegate: Rectangle {
id: actionRow
required property int index
required property var modelData
width: parent.width
height: 42
radius: 11
color: root.theme ? root.theme.content.backdrop : "#121212"
NuguText {
anchors.left: parent.left
anchors.leftMargin: 12
anchors.verticalCenter: parent.verticalCenter
theme: root.theme
text: actionRow.modelData.title || actionRow.modelData.id || "action"
width: parent.width - 78
}
NuguText {
anchors.right: parent.right
anchors.rightMargin: 12
anchors.verticalCenter: parent.verticalCenter
theme: root.theme
variant: "mono"
text: "ctrl " + (actionRow.index + 1)
width: 52
horizontalAlignment: Text.AlignRight
opacity: 0.7
}
MouseArea {
anchors.fill: parent
onClicked: root.activateAction(actionRow.index)
}
}
}
NuguText {
theme: root.theme
variant: "mono"
text: "desktop entry"
width: parent.width
topPadding: 24
bottomPadding: 8
opacity: 0.68
}
Rectangle {
width: parent.width
height: detailColumn.implicitHeight + 20
radius: 11
color: root.theme ? root.theme.content.backdrop : "#121212"
Column {
id: detailColumn
anchors.left: parent.left
anchors.right: parent.right
anchors.top: parent.top
anchors.margins: 10
spacing: 6
Repeater {
model: root.selectedDetails
delegate: Row {
id: detailRow
required property var modelData
width: parent.width
spacing: 10
NuguText {
theme: root.theme
variant: "meta"
text: detailRow.modelData.label || ""
width: 70
opacity: 0.62
}
NuguText {
theme: root.theme
variant: "meta"
text: detailRow.modelData.value || "—"
width: Math.max(1, parent.width - 80)
horizontalAlignment: Text.AlignRight
}
}
}
}
}
}
}
}
}