Add Clipboard History as a launcher mode backed by cliphist
The launcher gains a clipboard mode with the same bar, position and size: the latest five entries show at once and the rest scroll, search filters in recency order, Enter copies, Shift+Delete removes an entry. >clipboard switches in place without closing or animating; glassmxrph clipboard toggles it directly. History stays with the user's cliphist watcher. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
44a5aedbb2
commit
5a10469efe
15 files changed
+392
-24
No files matched your search
@@ -13,7 +13,18 @@ Singleton {
|
||||
page: page.id,
|
||||
available: page.available,
|
||||
run: page.launcherAction ? () => ShellState[page.launcherAction]() : undefined
|
||||
})).concat(extensions)
|
||||
})).concat(builtins, extensions)
|
||||
// `stay` commands keep the launcher open (they change its mode in place).
|
||||
readonly property var builtins: [
|
||||
{
|
||||
id: "clipboard",
|
||||
title: "Clipboard History",
|
||||
description: "Search and copy from cliphist",
|
||||
kind: "Command",
|
||||
stay: true,
|
||||
run: () => ShellState.openLauncher("clipboard")
|
||||
}
|
||||
]
|
||||
// Extensions are registered by trusted QML code, never interpreted from search text.
|
||||
function registerCommand(command) {
|
||||
if (!command || !/^[a-z][a-z0-9-]*$/.test(command.id) || !command.title || typeof command.run !== "function" || commands.some(c => c.id === command.id))
|
||||
|
||||
@@ -10,6 +10,7 @@ QtObject {
|
||||
title: command.title,
|
||||
description: command.description || "Shell command",
|
||||
command: true,
|
||||
kind: command.kind || "Settings",
|
||||
fields: [
|
||||
{
|
||||
text: command.id
|
||||
|
||||
@@ -12,6 +12,8 @@ import "../core"
|
||||
// Spotlight-style launcher: opens as a single search bar in the upper third.
|
||||
// Typing shows ranked results below it; the magnifying glass (or ↓ in an
|
||||
// empty bar) browses every application as an icon grid; > lists commands.
|
||||
// Clipboard mode (>clipboard, `glassmxrph clipboard`) lists cliphist history
|
||||
// in the same bar, newest first, without closing the window to switch.
|
||||
// Runtime selects the concrete Wayland layer implementation.
|
||||
// qmllint disable uncreatable-type
|
||||
PanelWindow {
|
||||
@@ -36,9 +38,10 @@ PanelWindow {
|
||||
showDescriptions: true
|
||||
})
|
||||
readonly property string query: search.text.trim()
|
||||
readonly property bool commandMode: query.startsWith(">")
|
||||
readonly property bool clipboardMode: ShellState.launcherMode === "clipboard"
|
||||
readonly property bool commandMode: !clipboardMode && query.startsWith(">")
|
||||
property bool browsing: false
|
||||
readonly property bool showList: query !== ""
|
||||
readonly property bool showList: clipboardMode || query !== ""
|
||||
readonly property bool showGrid: !showList && browsing
|
||||
readonly property var allApps: ApplicationsService.launchable.map(entry => ({
|
||||
id: entry.id,
|
||||
@@ -46,13 +49,28 @@ PanelWindow {
|
||||
description: entry.genericName || entry.comment || entry.id,
|
||||
entry: entry
|
||||
}))
|
||||
readonly property var results: showList ? (commandMode ? commands.results : apps.results) : showGrid ? allApps : []
|
||||
readonly property var clipboardResults: clipboardMode && ShellState.launcherOpen ? ClipboardService.filter(query).map(e => ({
|
||||
id: e.id,
|
||||
title: e.text.replace(/\s+/g, " ").trim(),
|
||||
description: "",
|
||||
clip: e
|
||||
})) : []
|
||||
readonly property var results: clipboardMode ? clipboardResults : showList ? (commandMode ? commands.results : apps.results) : showGrid ? allApps : []
|
||||
property int selectedIndex: 0
|
||||
property string launchError: ""
|
||||
readonly property real targetWidth: Math.min(options.width, root.width - 40)
|
||||
readonly property int barHeight: 60
|
||||
readonly property real maxBodyHeight: Math.min(460, root.height * 0.78 - barHeight - (root.height * 0.22))
|
||||
readonly property real bodyHeight: showList ? Math.min(maxBodyHeight, Math.max(84, list.contentHeight + 46 + (launchError ? 22 : 0))) : showGrid ? Math.min(maxBodyHeight, grid.contentHeight + 46) : 0
|
||||
// Clipboard mode shows the latest five rows; the rest scroll.
|
||||
readonly property real clipboardRows: 5 * 48 - 2
|
||||
readonly property real bodyHeight: showList ? Math.min(maxBodyHeight, Math.max(84, (clipboardMode ? Math.min(list.contentHeight, clipboardRows) : list.contentHeight) + 46 + (launchError ? 22 : 0))) : showGrid ? Math.min(maxBodyHeight, grid.contentHeight + 46) : 0
|
||||
// Mode switches resize without animating, so >clipboard lands in place.
|
||||
property bool snapping: false
|
||||
Timer {
|
||||
id: unsnap
|
||||
interval: 120
|
||||
onTriggered: root.snapping = false
|
||||
}
|
||||
readonly property int gridColumns: Math.max(1, Math.floor((targetWidth - 24) / 112))
|
||||
onResultsChanged: {
|
||||
selectedIndex = 0;
|
||||
@@ -72,8 +90,13 @@ PanelWindow {
|
||||
const result = results[index];
|
||||
if (!result)
|
||||
return;
|
||||
if (result.command) {
|
||||
if (result.clip) {
|
||||
ClipboardService.copy(result.clip);
|
||||
ShellState.launcherOpen = false;
|
||||
} else 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;
|
||||
@@ -81,6 +104,10 @@ PanelWindow {
|
||||
launchError = ApplicationsService.error;
|
||||
}
|
||||
function toggleBrowse() {
|
||||
if (clipboardMode) {
|
||||
ShellState.launcherMode = "apps";
|
||||
return;
|
||||
}
|
||||
browsing = !browsing;
|
||||
if (browsing)
|
||||
search.clear();
|
||||
@@ -97,9 +124,21 @@ PanelWindow {
|
||||
root.browsing = false;
|
||||
root.launchError = "";
|
||||
root.selectedIndex = 0;
|
||||
ClipboardService.refresh();
|
||||
Qt.callLater(() => search.forceActiveFocus());
|
||||
}
|
||||
}
|
||||
function onLauncherModeChanged() {
|
||||
if (!ShellState.launcherOpen)
|
||||
return;
|
||||
root.snapping = true;
|
||||
unsnap.restart();
|
||||
search.text = "";
|
||||
root.browsing = false;
|
||||
root.launchError = "";
|
||||
root.selectedIndex = 0;
|
||||
search.forceActiveFocus();
|
||||
}
|
||||
}
|
||||
AppSearch {
|
||||
id: apps
|
||||
@@ -135,6 +174,7 @@ PanelWindow {
|
||||
}
|
||||
}
|
||||
Behavior on height {
|
||||
enabled: !root.snapping
|
||||
NumberAnimation {
|
||||
duration: Theme.duration
|
||||
easing.type: Easing.OutCubic
|
||||
@@ -172,7 +212,7 @@ PanelWindow {
|
||||
radius: 12
|
||||
color: root.browsing ? Theme.accent : browseArea.containsMouse ? Theme.hover : Theme.transparent
|
||||
Accessible.role: Accessible.Button
|
||||
Accessible.name: root.browsing ? "Hide applications" : "Show all applications"
|
||||
Accessible.name: root.clipboardMode ? "Back to search" : root.browsing ? "Hide applications" : "Show all applications"
|
||||
Behavior on color {
|
||||
ColorAnimation {
|
||||
duration: Theme.duration / 2
|
||||
@@ -180,7 +220,7 @@ PanelWindow {
|
||||
}
|
||||
Text {
|
||||
anchors.centerIn: parent
|
||||
text: root.commandMode ? ">" : Icons.available ? "" : "⌕"
|
||||
text: root.commandMode ? ">" : !Icons.available ? (root.clipboardMode ? "⎘" : "⌕") : root.clipboardMode ? "" : ""
|
||||
font.family: Icons.available && !root.commandMode ? Icons.family : ""
|
||||
color: root.browsing ? Theme.accentText : Theme.textSecondary
|
||||
font.pixelSize: 20
|
||||
@@ -194,14 +234,14 @@ PanelWindow {
|
||||
}
|
||||
ToolTip.visible: browseArea.containsMouse
|
||||
ToolTip.delay: 600
|
||||
ToolTip.text: root.browsing ? "Hide applications" : "All applications"
|
||||
ToolTip.text: root.clipboardMode ? "Back to search" : root.browsing ? "Hide applications" : "All applications"
|
||||
}
|
||||
TextField {
|
||||
id: search
|
||||
objectName: "launcherSearch"
|
||||
Layout.fillWidth: true
|
||||
Layout.preferredHeight: 40
|
||||
placeholderText: root.browsing ? "Search applications" : "Search :3"
|
||||
placeholderText: root.clipboardMode ? "Clipboard History" : root.browsing ? "Search applications" : "Search :3"
|
||||
color: Theme.text
|
||||
placeholderTextColor: Theme.textSecondary
|
||||
selectByMouse: true
|
||||
@@ -238,6 +278,13 @@ PanelWindow {
|
||||
else
|
||||
event.accepted = false;
|
||||
}
|
||||
// Shift+Delete removes the selected clipboard entry from history.
|
||||
Keys.onDeletePressed: event => {
|
||||
if (root.clipboardMode && event.modifiers & Qt.ShiftModifier && root.results[root.selectedIndex])
|
||||
ClipboardService.remove(root.results[root.selectedIndex].clip);
|
||||
else
|
||||
event.accepted = false;
|
||||
}
|
||||
Keys.onTabPressed: root.select(1)
|
||||
Keys.onBacktabPressed: root.select(-1)
|
||||
Keys.onReturnPressed: root.activate(root.selectedIndex)
|
||||
@@ -265,7 +312,7 @@ PanelWindow {
|
||||
id: section
|
||||
x: 22
|
||||
y: 12
|
||||
text: root.showGrid ? "Applications" : root.commandMode ? "Settings" : root.results.length ? "Top hits" : ""
|
||||
text: root.clipboardMode ? (!root.results.length ? "" : root.query ? "Matches" : "Recent") : root.showGrid ? "Applications" : root.commandMode ? "Settings" : root.results.length ? "Top hits" : ""
|
||||
color: Theme.textSecondary
|
||||
font.pixelSize: 11
|
||||
font.weight: Font.DemiBold
|
||||
@@ -299,32 +346,39 @@ PanelWindow {
|
||||
anchors.rightMargin: 12
|
||||
spacing: 12
|
||||
Item {
|
||||
Layout.preferredWidth: 30
|
||||
readonly property var copied: resultRow.modelData.clip
|
||||
// Copied images get a wider thumbnail slot.
|
||||
Layout.preferredWidth: copied && copied.thumb ? 52 : 30
|
||||
Layout.preferredHeight: 30
|
||||
Image {
|
||||
id: icon
|
||||
anchors.fill: parent
|
||||
source: resultRow.modelData.entry ? ApplicationsService.icon(resultRow.modelData.entry) : ""
|
||||
sourceSize: Qt.size(60, 60)
|
||||
source: parent.copied ? (parent.copied.thumb ? "file://" + parent.copied.thumb : "") : resultRow.modelData.entry ? ApplicationsService.icon(resultRow.modelData.entry) : ""
|
||||
sourceSize: parent.copied ? Qt.size(104, 60) : Qt.size(60, 60)
|
||||
fillMode: Image.PreserveAspectFit
|
||||
asynchronous: !!parent.copied
|
||||
}
|
||||
Text {
|
||||
anchors.centerIn: parent
|
||||
visible: icon.source.toString() === "" || icon.status === Image.Error
|
||||
text: resultRow.modelData.command ? "⚙" : resultRow.modelData.title.slice(0, 2).toUpperCase()
|
||||
text: parent.copied ? (Icons.available ? (parent.copied.image ? "" : "") : "¶") : resultRow.modelData.command ? "⚙" : resultRow.modelData.title.slice(0, 2).toUpperCase()
|
||||
font.family: parent.copied && Icons.available ? Icons.family : ""
|
||||
color: resultRow.selected ? Theme.accentText : Theme.textSecondary
|
||||
font.pixelSize: 16
|
||||
font.pixelSize: parent.copied ? 18 : 16
|
||||
}
|
||||
}
|
||||
Text {
|
||||
text: resultRow.modelData.title
|
||||
// Clipboard text is shown as is, never as markup.
|
||||
textFormat: Text.PlainText
|
||||
Layout.fillWidth: !!resultRow.modelData.clip
|
||||
elide: Text.ElideRight
|
||||
color: resultRow.selected ? Theme.accentText : Theme.text
|
||||
font.pixelSize: 14
|
||||
font.weight: Font.Medium
|
||||
}
|
||||
Text {
|
||||
visible: root.options.showDescriptions
|
||||
visible: root.options.showDescriptions && !resultRow.modelData.clip
|
||||
text: "— " + resultRow.modelData.description
|
||||
Layout.fillWidth: true
|
||||
elide: Text.ElideRight
|
||||
@@ -332,11 +386,11 @@ PanelWindow {
|
||||
font.pixelSize: 12
|
||||
}
|
||||
Item {
|
||||
visible: !root.options.showDescriptions
|
||||
visible: !root.options.showDescriptions && !resultRow.modelData.clip
|
||||
Layout.fillWidth: true
|
||||
}
|
||||
Text {
|
||||
text: resultRow.modelData.command ? "Settings" : "Application"
|
||||
text: resultRow.modelData.clip ? (resultRow.modelData.clip.image ? "Image" : "Text") : resultRow.modelData.command ? resultRow.modelData.kind : "Application"
|
||||
color: resultRow.selected ? Qt.alpha(Theme.accentText, 0.75) : Theme.textSecondary
|
||||
font.pixelSize: 11
|
||||
}
|
||||
@@ -429,7 +483,7 @@ PanelWindow {
|
||||
anchors.centerIn: parent
|
||||
anchors.verticalCenterOffset: 12
|
||||
visible: root.showList && root.results.length === 0
|
||||
text: root.commandMode ? "No matching settings" : "No results"
|
||||
text: root.clipboardMode ? (ClipboardService.error || (root.query ? "No matches" : ClipboardService.loaded ? "Clipboard history is empty" : "Loading…")) : root.commandMode ? "No matching settings" : "No results"
|
||||
color: Theme.textSecondary
|
||||
font.pixelSize: 13
|
||||
}
|
||||
|
||||
@@ -18,9 +18,14 @@ Singleton {
|
||||
function close(): void {
|
||||
ShellState.launcherOpen = false;
|
||||
}
|
||||
// Opens Clipboard History, or closes it when it is showing.
|
||||
function clipboard(): void {
|
||||
ShellState.toggleClipboard();
|
||||
}
|
||||
function status(): string {
|
||||
return JSON.stringify({
|
||||
opened: ShellState.launcherOpen,
|
||||
mode: ShellState.launcherMode,
|
||||
screen: root.window && root.window.screen ? root.window.screen.name : "",
|
||||
ready: !!root.window
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user