Add an Emoji Picker as a launcher mode with a searchable grid
The launcher gains an emoji mode like Clipboard History: >emoji switches in place without closing or animating, and glassmxrph emoji toggles it. Emoji show as a grid instead of named rows; the selected or hovered emoji's name is the section label. Search requires every term and ranks name matches before keyword matches; Enter copies with wl-copy. assets/emoji.tsv comes from Unicode 17 emoji-test.txt without skin-tone variants, with keywords from the rofi emopicker list (scripts/emoji-data). The test driver caps snapshot results, since IPC replies have a size limit. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
29dd64572a
commit
b3076a4cde
13 files changed
+2220
-29
No files matched your search
@@ -14,6 +14,8 @@ import "../core"
|
||||
// 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.
|
||||
// Emoji mode (>emoji, `glassmxrph emoji`) shows a searchable emoji grid the
|
||||
// same way; the selected emoji's name is the section label.
|
||||
// Runtime selects the concrete Wayland layer implementation.
|
||||
// qmllint disable uncreatable-type
|
||||
PanelWindow {
|
||||
@@ -39,10 +41,13 @@ PanelWindow {
|
||||
})
|
||||
readonly property string query: search.text.trim()
|
||||
readonly property bool clipboardMode: ShellState.launcherMode === "clipboard"
|
||||
readonly property bool commandMode: !clipboardMode && query.startsWith(">")
|
||||
readonly property bool emojiMode: ShellState.launcherMode === "emoji"
|
||||
readonly property bool commandMode: !clipboardMode && !emojiMode && query.startsWith(">")
|
||||
property bool browsing: false
|
||||
readonly property bool showList: clipboardMode || query !== ""
|
||||
readonly property bool showGrid: !showList && browsing
|
||||
readonly property bool showList: clipboardMode || !emojiMode && query !== ""
|
||||
readonly property bool showGrid: !showList && !emojiMode && browsing
|
||||
// Arrow keys move through whichever grid is showing.
|
||||
readonly property int columns: emojiMode ? emojiColumns : showGrid ? gridColumns : 1
|
||||
readonly property var allApps: ApplicationsService.launchable.map(entry => ({
|
||||
id: entry.id,
|
||||
title: entry.name,
|
||||
@@ -55,7 +60,13 @@ PanelWindow {
|
||||
description: "",
|
||||
clip: e
|
||||
})) : []
|
||||
readonly property var results: clipboardMode ? clipboardResults : showList ? (commandMode ? commands.results : apps.results) : showGrid ? allApps : []
|
||||
readonly property var emojiResults: emojiMode && ShellState.launcherOpen ? EmojiService.filter(query).map(e => ({
|
||||
id: e.emoji,
|
||||
title: e.name,
|
||||
description: "",
|
||||
glyph: e
|
||||
})) : []
|
||||
readonly property var results: clipboardMode ? clipboardResults : emojiMode ? emojiResults : 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)
|
||||
@@ -63,7 +74,11 @@ PanelWindow {
|
||||
readonly property real maxBodyHeight: Math.min(460, root.height * 0.78 - barHeight - (root.height * 0.22))
|
||||
// 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
|
||||
// Emoji mode shows six rows of the grid; the rest scroll.
|
||||
readonly property int emojiCell: 52
|
||||
readonly property int emojiColumns: Math.max(1, Math.floor((targetWidth - 24) / emojiCell))
|
||||
readonly property real emojiRows: 6 * emojiCell
|
||||
readonly property real bodyHeight: emojiMode ? Math.min(maxBodyHeight, Math.max(84, Math.min(emojiGrid.contentHeight, emojiRows) + 42)) : 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 {
|
||||
@@ -76,12 +91,16 @@ PanelWindow {
|
||||
selectedIndex = 0;
|
||||
list.contentY = 0;
|
||||
grid.contentY = 0;
|
||||
emojiGrid.contentY = 0;
|
||||
emojiGrid.hovered = "";
|
||||
}
|
||||
function select(offset) {
|
||||
if (!results.length)
|
||||
return;
|
||||
selectedIndex = Math.max(0, Math.min(results.length - 1, selectedIndex + offset));
|
||||
if (showGrid)
|
||||
if (emojiMode)
|
||||
emojiGrid.positionViewAtIndex(selectedIndex, GridView.Contain);
|
||||
else if (showGrid)
|
||||
grid.positionViewAtIndex(selectedIndex, GridView.Contain);
|
||||
else
|
||||
list.positionViewAtIndex(selectedIndex, ListView.Contain);
|
||||
@@ -93,6 +112,9 @@ PanelWindow {
|
||||
if (result.clip) {
|
||||
ClipboardService.copy(result.clip);
|
||||
ShellState.launcherOpen = false;
|
||||
} else if (result.glyph) {
|
||||
EmojiService.copy(result.glyph);
|
||||
ShellState.launcherOpen = false;
|
||||
} else if (result.command) {
|
||||
const command = CommandRegistry.commands.find(c => c.id === result.id);
|
||||
if (!command || !command.stay)
|
||||
@@ -104,7 +126,7 @@ PanelWindow {
|
||||
launchError = ApplicationsService.error;
|
||||
}
|
||||
function toggleBrowse() {
|
||||
if (clipboardMode) {
|
||||
if (clipboardMode || emojiMode) {
|
||||
ShellState.launcherMode = "apps";
|
||||
return;
|
||||
}
|
||||
@@ -125,10 +147,14 @@ PanelWindow {
|
||||
root.launchError = "";
|
||||
root.selectedIndex = 0;
|
||||
ClipboardService.refresh();
|
||||
if (root.emojiMode)
|
||||
EmojiService.load();
|
||||
Qt.callLater(() => search.forceActiveFocus());
|
||||
}
|
||||
}
|
||||
function onLauncherModeChanged() {
|
||||
if (root.emojiMode)
|
||||
EmojiService.load();
|
||||
if (!ShellState.launcherOpen)
|
||||
return;
|
||||
root.snapping = true;
|
||||
@@ -212,7 +238,7 @@ PanelWindow {
|
||||
radius: 12
|
||||
color: root.browsing ? Theme.accent : browseArea.containsMouse ? Theme.hover : Theme.transparent
|
||||
Accessible.role: Accessible.Button
|
||||
Accessible.name: root.clipboardMode ? "Back to search" : root.browsing ? "Hide applications" : "Show all applications"
|
||||
Accessible.name: root.clipboardMode || root.emojiMode ? "Back to search" : root.browsing ? "Hide applications" : "Show all applications"
|
||||
Behavior on color {
|
||||
ColorAnimation {
|
||||
duration: Theme.duration / 2
|
||||
@@ -220,7 +246,7 @@ PanelWindow {
|
||||
}
|
||||
Text {
|
||||
anchors.centerIn: parent
|
||||
text: root.commandMode ? ">" : !Icons.available ? (root.clipboardMode ? "⎘" : "⌕") : root.clipboardMode ? "" : ""
|
||||
text: root.commandMode ? ">" : !Icons.available ? (root.clipboardMode ? "⎘" : root.emojiMode ? "☺" : "⌕") : root.clipboardMode ? "" : root.emojiMode ? "" : ""
|
||||
font.family: Icons.available && !root.commandMode ? Icons.family : ""
|
||||
color: root.browsing ? Theme.accentText : Theme.textSecondary
|
||||
font.pixelSize: 20
|
||||
@@ -234,14 +260,14 @@ PanelWindow {
|
||||
}
|
||||
ToolTip.visible: browseArea.containsMouse
|
||||
ToolTip.delay: 600
|
||||
ToolTip.text: root.clipboardMode ? "Back to search" : root.browsing ? "Hide applications" : "All applications"
|
||||
ToolTip.text: root.clipboardMode || root.emojiMode ? "Back to search" : root.browsing ? "Hide applications" : "All applications"
|
||||
}
|
||||
TextField {
|
||||
id: search
|
||||
objectName: "launcherSearch"
|
||||
Layout.fillWidth: true
|
||||
Layout.preferredHeight: 40
|
||||
placeholderText: root.clipboardMode ? "Clipboard History" : root.browsing ? "Search applications" : "Search :3"
|
||||
placeholderText: root.clipboardMode ? "Clipboard History" : root.emojiMode ? "Search emoji" : root.browsing ? "Search applications" : "Search :3"
|
||||
color: Theme.text
|
||||
placeholderTextColor: Theme.textSecondary
|
||||
selectByMouse: true
|
||||
@@ -260,20 +286,20 @@ PanelWindow {
|
||||
ShellState.launcherOpen = false;
|
||||
}
|
||||
Keys.onDownPressed: {
|
||||
if (!root.showList && !root.browsing)
|
||||
if (!root.showList && !root.browsing && !root.emojiMode)
|
||||
root.browsing = true;
|
||||
else
|
||||
root.select(root.showGrid ? root.gridColumns : 1);
|
||||
root.select(root.columns);
|
||||
}
|
||||
Keys.onUpPressed: root.select(root.showGrid ? -root.gridColumns : -1)
|
||||
Keys.onUpPressed: root.select(-root.columns)
|
||||
Keys.onRightPressed: event => {
|
||||
if (root.showGrid || event.modifiers & Qt.ControlModifier)
|
||||
if (root.columns > 1 || event.modifiers & Qt.ControlModifier)
|
||||
root.select(1);
|
||||
else
|
||||
event.accepted = false;
|
||||
}
|
||||
Keys.onLeftPressed: event => {
|
||||
if (root.showGrid || event.modifiers & Qt.ControlModifier)
|
||||
if (root.columns > 1 || event.modifiers & Qt.ControlModifier)
|
||||
root.select(-1);
|
||||
else
|
||||
event.accepted = false;
|
||||
@@ -312,7 +338,7 @@ PanelWindow {
|
||||
id: section
|
||||
x: 22
|
||||
y: 12
|
||||
text: root.clipboardMode ? (!root.results.length ? "" : root.query ? "Matches" : "Recent") : root.showGrid ? "Applications" : root.commandMode ? "Settings" : root.results.length ? "Top hits" : ""
|
||||
text: root.emojiMode ? (emojiGrid.hovered || (root.results[root.selectedIndex] || {}).title || "") : 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
|
||||
@@ -479,11 +505,66 @@ PanelWindow {
|
||||
Accessible.onPressAction: root.activate(index)
|
||||
}
|
||||
}
|
||||
GridView {
|
||||
id: emojiGrid
|
||||
objectName: "launcherEmoji"
|
||||
// Name of the emoji under the pointer, shown instead of the selection's.
|
||||
property string hovered: ""
|
||||
visible: root.emojiMode
|
||||
anchors.fill: parent
|
||||
anchors.topMargin: 32
|
||||
anchors.leftMargin: 12
|
||||
anchors.rightMargin: 12
|
||||
anchors.bottomMargin: 10
|
||||
clip: true
|
||||
model: root.emojiMode ? root.results : []
|
||||
cellWidth: Math.floor(width / root.emojiColumns)
|
||||
cellHeight: root.emojiCell
|
||||
boundsBehavior: Flickable.StopAtBounds
|
||||
ScrollBar.vertical: ScrollBar {}
|
||||
delegate: Item {
|
||||
id: glyph
|
||||
required property var modelData
|
||||
required property int index
|
||||
readonly property bool selected: root.selectedIndex === index
|
||||
width: emojiGrid.cellWidth
|
||||
height: emojiGrid.cellHeight
|
||||
Rectangle {
|
||||
anchors.fill: parent
|
||||
anchors.margins: 3
|
||||
radius: 12
|
||||
color: glyph.selected ? Qt.alpha(Theme.accent, 0.35) : glyphArea.containsMouse ? Theme.hover : Theme.transparent
|
||||
border.width: glyph.selected ? 1 : 0
|
||||
border.color: Theme.accentVivid
|
||||
}
|
||||
Text {
|
||||
anchors.centerIn: parent
|
||||
text: glyph.modelData.id
|
||||
textFormat: Text.PlainText
|
||||
font.pixelSize: 28
|
||||
}
|
||||
MouseArea {
|
||||
id: glyphArea
|
||||
anchors.fill: parent
|
||||
hoverEnabled: true
|
||||
onContainsMouseChanged: {
|
||||
if (containsMouse)
|
||||
emojiGrid.hovered = glyph.modelData.title;
|
||||
else if (emojiGrid.hovered === glyph.modelData.title)
|
||||
emojiGrid.hovered = "";
|
||||
}
|
||||
onClicked: root.activate(glyph.index)
|
||||
}
|
||||
Accessible.role: Accessible.Button
|
||||
Accessible.name: modelData.title
|
||||
Accessible.onPressAction: root.activate(index)
|
||||
}
|
||||
}
|
||||
Text {
|
||||
anchors.centerIn: parent
|
||||
anchors.verticalCenterOffset: 12
|
||||
visible: root.showList && root.results.length === 0
|
||||
text: root.clipboardMode ? (ClipboardService.error || (root.query ? "No matches" : ClipboardService.loaded ? "Clipboard history is empty" : "Loading…")) : root.commandMode ? "No matching settings" : "No results"
|
||||
visible: (root.showList || root.emojiMode) && root.results.length === 0
|
||||
text: root.emojiMode ? (EmojiService.loaded ? "No matching emoji" : "Loading…") : 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
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user