Grow the notch launcher down once you search
The empty launcher stays in the widened notch, now laid out exactly like the launcher window's bar. Typing (or the magnifying glass / Down) hands over to the launcher window, which opens at the notch's size with the text already in it and only grows down with the results; clearing the search shrinks it back into the notch. The query and browse state are shared through ShellState, keys typed during the hand-over carry across, and the bar keeps its keyboard claim so focus returns on its own. The launcher window's open state is read from plain properties so it never maps for a frame on a stale value. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
1f029922ec
commit
415b1b3cd6
5 files changed
+151
-202
No files matched your search
@@ -1,61 +1,37 @@
|
||||
pragma ComponentBehavior: Bound
|
||||
import QtQuick
|
||||
import QtQuick.Controls
|
||||
import "../components"
|
||||
import "../core"
|
||||
import "../services"
|
||||
import "../theme"
|
||||
|
||||
// The launcher in notch mode: a search field and a row of top matches inside
|
||||
// the widened notch, the way a notification shows there. Enter launches the
|
||||
// highlighted match, Tab and the arrow keys move along the row, Escape clears
|
||||
// and then closes. Clipboard history and emoji open the launcher window.
|
||||
// The launcher's empty state in notch mode: its search bar inside the widened
|
||||
// notch, laid out exactly like the launcher window's bar. The first keystroke
|
||||
// (or the magnifying glass) hands over to the launcher window, which opens at
|
||||
// this size and grows down with the results; clearing the search hands back.
|
||||
Item {
|
||||
id: root
|
||||
property bool active: false
|
||||
readonly property string query: input.text.trim()
|
||||
readonly property bool commandMode: query.startsWith(">")
|
||||
readonly property int maxShown: 6
|
||||
readonly property var results: (commandMode ? commands.results : apps.results).slice(0, maxShown)
|
||||
property int selectedIndex: 0
|
||||
property string launchError: ""
|
||||
readonly property var selected: results[selectedIndex] || null
|
||||
onResultsChanged: selectedIndex = 0
|
||||
// The launcher window's bar is this tall; rows centre on it.
|
||||
readonly property int barHeight: 60
|
||||
readonly property int pillSize: 36
|
||||
property string pillHover: ""
|
||||
onActiveChanged: {
|
||||
input.text = "";
|
||||
launchError = "";
|
||||
selectedIndex = 0;
|
||||
if (active)
|
||||
Qt.callLater(() => input.forceActiveFocus());
|
||||
}
|
||||
|
||||
AppSearch {
|
||||
id: apps
|
||||
enabled: root.active && root.query !== "" && !root.commandMode
|
||||
query: root.query
|
||||
limit: root.maxShown
|
||||
}
|
||||
CommandSearch {
|
||||
id: commands
|
||||
enabled: root.active && root.commandMode
|
||||
query: root.query
|
||||
limit: root.maxShown
|
||||
}
|
||||
function select(offset) {
|
||||
if (results.length)
|
||||
selectedIndex = (selectedIndex + offset + results.length) % results.length;
|
||||
}
|
||||
function activate(index) {
|
||||
const result = results[index];
|
||||
if (!result)
|
||||
if (!active)
|
||||
return;
|
||||
if (result.command) {
|
||||
const command = CommandRegistry.commands.find(c => c.id === result.id);
|
||||
if (!command || !command.stay)
|
||||
ShellState.launcherOpen = false;
|
||||
CommandRegistry.execute(result.id);
|
||||
} else if (ApplicationsService.launch(result.entry, null))
|
||||
ShellState.launcherOpen = false;
|
||||
else
|
||||
launchError = ApplicationsService.error;
|
||||
if (input.text !== ShellState.launcherQuery)
|
||||
input.text = ShellState.launcherQuery;
|
||||
Qt.callLater(() => {
|
||||
input.forceActiveFocus();
|
||||
input.cursorPosition = input.text.length;
|
||||
});
|
||||
}
|
||||
Connections {
|
||||
target: ShellState
|
||||
function onLauncherQueryChanged() {
|
||||
if (input.text !== ShellState.launcherQuery)
|
||||
input.text = ShellState.launcherQuery;
|
||||
}
|
||||
}
|
||||
|
||||
// Swallows clicks so they reach the field, not the pill behind it.
|
||||
@@ -63,169 +39,103 @@ Item {
|
||||
anchors.fill: parent
|
||||
onClicked: input.forceActiveFocus()
|
||||
}
|
||||
Text {
|
||||
id: glass
|
||||
x: 14
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
text: Icons.available ? "" : "⌕"
|
||||
font.family: Icons.available ? Icons.family : ""
|
||||
font.pixelSize: 17
|
||||
color: Theme.textSecondary
|
||||
}
|
||||
// Typed text, then the highlighted match's name in grey after it.
|
||||
Item {
|
||||
id: field
|
||||
anchors.left: glass.right
|
||||
anchors.leftMargin: 10
|
||||
anchors.right: strip.left
|
||||
anchors.rightMargin: 12
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
height: 24
|
||||
clip: true
|
||||
TextInput {
|
||||
id: input
|
||||
objectName: "notchSearchInput"
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
width: Math.max(1, Math.min(contentWidth + 2, field.width))
|
||||
color: Theme.text
|
||||
selectionColor: Theme.accent
|
||||
selectedTextColor: Theme.text
|
||||
font.pixelSize: 15
|
||||
maximumLength: 256
|
||||
onTextEdited: root.launchError = ""
|
||||
Keys.onEscapePressed: {
|
||||
if (text !== "")
|
||||
clear();
|
||||
else
|
||||
ShellState.launcherOpen = false;
|
||||
}
|
||||
Keys.onTabPressed: root.select(1)
|
||||
Keys.onBacktabPressed: root.select(-1)
|
||||
Keys.onDownPressed: root.select(1)
|
||||
Keys.onUpPressed: root.select(-1)
|
||||
Keys.onRightPressed: event => {
|
||||
if (cursorPosition === text.length && root.results.length)
|
||||
root.select(1);
|
||||
else
|
||||
event.accepted = false;
|
||||
}
|
||||
Keys.onLeftPressed: event => {
|
||||
if (cursorPosition === text.length && root.selectedIndex > 0)
|
||||
root.select(-1);
|
||||
else
|
||||
event.accepted = false;
|
||||
}
|
||||
Keys.onReturnPressed: root.activate(root.selectedIndex)
|
||||
Keys.onEnterPressed: root.activate(root.selectedIndex)
|
||||
}
|
||||
Rectangle {
|
||||
x: 12
|
||||
y: (root.barHeight - height) / 2
|
||||
width: 38
|
||||
height: 38
|
||||
radius: 12
|
||||
color: browseArea.containsMouse ? Theme.hover : Theme.transparent
|
||||
Accessible.role: Accessible.Button
|
||||
Accessible.name: "Show all applications"
|
||||
Text {
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
x: input.text === "" ? 0 : input.width + 8
|
||||
width: Math.max(0, field.width - x)
|
||||
elide: Text.ElideRight
|
||||
font.pixelSize: 15
|
||||
color: root.launchError ? Theme.urgent : Theme.textSecondary
|
||||
text: root.launchError ? root.launchError : input.text === "" ? "Search apps" : root.selected ? "— " + root.selected.title : "No matches"
|
||||
anchors.centerIn: parent
|
||||
text: Icons.available ? "" : "⌕"
|
||||
font.family: Icons.available ? Icons.family : ""
|
||||
color: Theme.textSecondary
|
||||
font.pixelSize: 20
|
||||
}
|
||||
MouseArea {
|
||||
id: browseArea
|
||||
anchors.fill: parent
|
||||
hoverEnabled: true
|
||||
cursorShape: Qt.PointingHandCursor
|
||||
onClicked: ShellState.launcherBrowse = true
|
||||
}
|
||||
}
|
||||
// Top matches; the highlighted one launches on Enter.
|
||||
Row {
|
||||
id: strip
|
||||
anchors.right: modes.left
|
||||
anchors.rightMargin: 10
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
spacing: 4
|
||||
Repeater {
|
||||
model: root.results
|
||||
Rectangle {
|
||||
id: tile
|
||||
required property var modelData
|
||||
required property int index
|
||||
readonly property bool current: index === root.selectedIndex
|
||||
width: 34
|
||||
height: 34
|
||||
radius: 10
|
||||
color: current ? Qt.alpha(Theme.accent, 0.35) : tileArea.containsMouse ? Theme.hover : Theme.transparent
|
||||
border.width: current ? 1 : 0
|
||||
border.color: Qt.alpha(Theme.accent, 0.8)
|
||||
Accessible.role: Accessible.Button
|
||||
Accessible.name: modelData.title
|
||||
Image {
|
||||
id: tileIcon
|
||||
anchors.centerIn: parent
|
||||
width: 24
|
||||
height: 24
|
||||
source: tile.modelData.entry ? ApplicationsService.icon(tile.modelData.entry) : ""
|
||||
sourceSize: Qt.size(48, 48)
|
||||
asynchronous: true
|
||||
smooth: true
|
||||
mipmap: true
|
||||
}
|
||||
Text {
|
||||
anchors.centerIn: parent
|
||||
visible: tileIcon.status !== Image.Ready
|
||||
text: tile.modelData.command ? (Icons.available ? "" : ">") : tile.modelData.title.charAt(0).toUpperCase()
|
||||
font.family: Icons.available ? Icons.family : ""
|
||||
font.pixelSize: 15
|
||||
color: Theme.text
|
||||
}
|
||||
MouseArea {
|
||||
id: tileArea
|
||||
anchors.fill: parent
|
||||
hoverEnabled: true
|
||||
cursorShape: Qt.PointingHandCursor
|
||||
onEntered: root.selectedIndex = tile.index
|
||||
onClicked: root.activate(tile.index)
|
||||
}
|
||||
}
|
||||
}
|
||||
TextField {
|
||||
id: input
|
||||
objectName: "notchSearchInput"
|
||||
x: 60
|
||||
y: (root.barHeight - height) / 2
|
||||
width: pills.x - x - 18
|
||||
height: 40
|
||||
placeholderText: root.pillHover || "Search :3"
|
||||
color: Theme.text
|
||||
placeholderTextColor: Theme.textSecondary
|
||||
selectByMouse: true
|
||||
font.pixelSize: 22
|
||||
font.weight: Font.Light
|
||||
background: Item {}
|
||||
padding: 0
|
||||
maximumLength: 256
|
||||
// Any text opens the launcher window with it.
|
||||
onTextChanged: if (ShellState.notchLauncher && text !== ShellState.launcherQuery)
|
||||
ShellState.launcherQuery = text
|
||||
Keys.onEscapePressed: ShellState.launcherOpen = false
|
||||
Keys.onDownPressed: ShellState.launcherBrowse = true
|
||||
}
|
||||
// Clipboard history and emoji open the full launcher window.
|
||||
// Clipboard history and emoji, as in the launcher's bar.
|
||||
Row {
|
||||
id: modes
|
||||
anchors.right: parent.right
|
||||
anchors.rightMargin: 12
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
spacing: 4
|
||||
id: pills
|
||||
x: root.width - width - 14
|
||||
y: (root.barHeight - root.pillSize) / 2
|
||||
spacing: 6
|
||||
Repeater {
|
||||
model: [
|
||||
{
|
||||
mode: "clipboard",
|
||||
label: "Clipboard",
|
||||
glyph: "",
|
||||
fallback: "C",
|
||||
name: "Clipboard history"
|
||||
fallback: "⎘"
|
||||
},
|
||||
{
|
||||
mode: "emoji",
|
||||
label: "Emoji",
|
||||
glyph: "",
|
||||
fallback: ":)",
|
||||
name: "Emoji"
|
||||
fallback: "☺"
|
||||
}
|
||||
]
|
||||
Rectangle {
|
||||
id: mode
|
||||
GlassPanel {
|
||||
id: pill
|
||||
required property var modelData
|
||||
width: 28
|
||||
height: 28
|
||||
radius: 14
|
||||
color: modeArea.containsMouse ? Theme.hover : Theme.fill
|
||||
border.width: 1
|
||||
width: root.pillSize
|
||||
height: width
|
||||
radius: width / 2
|
||||
color: pillArea.containsMouse ? Theme.hover : Theme.fill
|
||||
border.color: Theme.hairline
|
||||
plain: true
|
||||
Accessible.role: Accessible.Button
|
||||
Accessible.name: modelData.name
|
||||
Accessible.name: modelData.label
|
||||
Text {
|
||||
anchors.centerIn: parent
|
||||
text: Icons.available ? mode.modelData.glyph : mode.modelData.fallback
|
||||
text: Icons.available ? pill.modelData.glyph : pill.modelData.fallback
|
||||
font.family: Icons.available ? Icons.family : ""
|
||||
font.pixelSize: 14
|
||||
font.pixelSize: 17
|
||||
color: Theme.text
|
||||
}
|
||||
MouseArea {
|
||||
id: modeArea
|
||||
id: pillArea
|
||||
anchors.fill: parent
|
||||
hoverEnabled: true
|
||||
cursorShape: Qt.PointingHandCursor
|
||||
onClicked: ShellState.openLauncher(mode.modelData.mode)
|
||||
onContainsMouseChanged: {
|
||||
if (containsMouse)
|
||||
root.pillHover = pill.modelData.label;
|
||||
else if (root.pillHover === pill.modelData.label)
|
||||
root.pillHover = "";
|
||||
}
|
||||
onClicked: ShellState.openLauncher(pill.modelData.mode)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user