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
File diff suppressed because it is too large.
Load diff
@@ -54,7 +54,8 @@ Singleton {
|
||||
}
|
||||
property bool launcherOpen: false
|
||||
property var launcherScreen: null
|
||||
// "apps" searches applications and commands; "clipboard" is Clipboard History.
|
||||
// "apps" searches applications and commands; "clipboard" is Clipboard History;
|
||||
// "emoji" is the Emoji Picker.
|
||||
// Changing it on an open launcher switches in place.
|
||||
property string launcherMode: "apps"
|
||||
function activeScreen() {
|
||||
@@ -63,7 +64,7 @@ Singleton {
|
||||
function openLauncher(mode) {
|
||||
wallpaperPickerOpen=false;
|
||||
dashboardOpen = false;
|
||||
launcherMode = mode === "clipboard" ? "clipboard" : "apps";
|
||||
launcherMode = mode === "clipboard" || mode === "emoji" ? mode : "apps";
|
||||
if (launcherOpen)
|
||||
return;
|
||||
controlCenterOpen = false;
|
||||
@@ -77,11 +78,14 @@ Singleton {
|
||||
else
|
||||
openLauncher();
|
||||
}
|
||||
function toggleClipboard() {
|
||||
if (launcherOpen && launcherMode === "clipboard")
|
||||
function toggleLauncherMode(mode) {
|
||||
if (launcherOpen && launcherMode === mode)
|
||||
launcherOpen = false;
|
||||
else
|
||||
openLauncher("clipboard");
|
||||
openLauncher(mode);
|
||||
}
|
||||
function toggleClipboard() {
|
||||
toggleLauncherMode("clipboard");
|
||||
}
|
||||
property var settingsWindow: null
|
||||
property bool settingsOpen: false
|
||||
|
||||
@@ -23,6 +23,14 @@ Singleton {
|
||||
kind: "Command",
|
||||
stay: true,
|
||||
run: () => ShellState.openLauncher("clipboard")
|
||||
},
|
||||
{
|
||||
id: "emoji",
|
||||
title: "Emoji Picker",
|
||||
description: "Search and copy an emoji",
|
||||
kind: "Command",
|
||||
stay: true,
|
||||
run: () => ShellState.openLauncher("emoji")
|
||||
}
|
||||
]
|
||||
// Extensions are registered by trusted QML code, never interpreted from search text.
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -22,6 +22,10 @@ Singleton {
|
||||
function clipboard(): void {
|
||||
ShellState.toggleClipboard();
|
||||
}
|
||||
// Opens the Emoji Picker, or closes it when it is showing.
|
||||
function emoji(): void {
|
||||
ShellState.toggleLauncherMode("emoji");
|
||||
}
|
||||
function status(): string {
|
||||
return JSON.stringify({
|
||||
opened: ShellState.launcherOpen,
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
pragma Singleton
|
||||
import QtQuick
|
||||
import Quickshell
|
||||
import Quickshell.Io
|
||||
|
||||
// Emoji for the launcher's emoji mode, from assets/emoji.tsv (scripts/emoji-data).
|
||||
// The list is read the first time emoji mode opens and kept for the session.
|
||||
Singleton {
|
||||
id: root
|
||||
// Unicode order: {emoji, name, keywords} with lower-case search text.
|
||||
property var entries: []
|
||||
property bool loaded: false
|
||||
|
||||
function load() {
|
||||
if (!file.path)
|
||||
file.path = Qt.resolvedUrl("../assets/emoji.tsv").toString().replace("file://", "");
|
||||
}
|
||||
// Space-separated terms, all required. Name matches come before keyword
|
||||
// matches; Unicode order is kept within each.
|
||||
function filter(query) {
|
||||
const terms = query.toLowerCase().split(/\s+/).filter(t => t);
|
||||
if (!terms.length)
|
||||
return entries;
|
||||
const named = [], tagged = [];
|
||||
for (const e of entries) {
|
||||
if (!terms.every(t => e.search.includes(t)))
|
||||
continue;
|
||||
(terms.every(t => e.lowerName.includes(t)) ? named : tagged).push(e);
|
||||
}
|
||||
return named.concat(tagged);
|
||||
}
|
||||
function copy(entry) {
|
||||
if (!entry)
|
||||
return false;
|
||||
Quickshell.execDetached(["wl-copy", "--", entry.emoji]);
|
||||
return true;
|
||||
}
|
||||
|
||||
FileView {
|
||||
id: file
|
||||
onLoaded: {
|
||||
root.entries = text().split("\n").filter(line => line).map(line => {
|
||||
const [emoji, name, keywords] = line.split("\t");
|
||||
const lowerName = name.toLowerCase();
|
||||
return {
|
||||
emoji: emoji,
|
||||
name: name,
|
||||
lowerName: lowerName,
|
||||
search: lowerName + " " + (keywords || "")
|
||||
};
|
||||
});
|
||||
root.loaded = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,3 +18,4 @@ singleton EasyEffectsService 1.0 EasyEffectsService.qml
|
||||
singleton PluginService 1.0 PluginService.qml
|
||||
singleton NotificationService 1.0 NotificationService.qml
|
||||
singleton ClipboardService 1.0 ClipboardService.qml
|
||||
singleton EmojiService 1.0 EmojiService.qml
|
||||
@@ -56,7 +56,9 @@ Item {
|
||||
query: root.search().text,
|
||||
focused: root.search().activeFocus,
|
||||
selected: w.selectedIndex,
|
||||
results: w.results.map(r => ({
|
||||
// IPC replies have a size limit; the emoji grid holds ~1900 results.
|
||||
resultCount: w.results.length,
|
||||
results: w.results.slice(0, 200).map(r => ({
|
||||
id: r.id,
|
||||
title: r.title,
|
||||
command: !!r.command,
|
||||
|
||||
Reference in new issue
Block a user