Emoji picker (Super+.): search, tabs, skin tones, recents, text-input-v3 insertion
CI / test (push) Canceled after 0s

Compositor-drawn Win+. style picker. The focused app keeps keyboard focus so
its text-input-v3 field stays enabled; the emoji goes in with commit_string,
or onto the clipboard with a visible notice when the app has no text field.
Shortcut lives in the shortcut table (rebindable in Settings > Shortcuts).

- compositor/wayland/text_input.mbt: zwp_text_input_manager_v3 (global 12)
- compositor/emoji: Emoji 18.0 + CLDR 49 data (Unicode License), search,
  picker model, CBDT/CBLC + GSUB reader for Noto Color Emoji
- Chandra's own pinned bitmap Noto Color Emoji (scripts/fetch-emoji-font.sh,
  just emoji-font); Fedora's COLRv1 copy can't be drawn. Missing font shows
  an error panel.
- raster WIT: emoji-font, emoji-has, emoji-image; served by wasmhost
- state.edn :emoji {:recent [...] :skin-tone n}
- tests incl. a fake text-input client; docs/emoji-picker.md

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DPL5hkABDGJixotaqFv2X2
This commit is contained in:
Claude committed 2026-11-26 07:00:22 +00:00
1 parent 738928352e
commit 27252a97ab
39 files changed
+4942 -41

No files matched your search

+253
View File
@@ -0,0 +1,253 @@
///| The emoji picker (Super+.): opening, searching, keys, insertion through text-input-v3 into a
/// fake client, the clipboard when the app has no text field, and recents in state.edn.
///| evdev codes typed in these tests (US layout: tests have no keymap).
fn type_keys(comp : @host.ChandraCompositor, codes : Array[UInt], t : UInt) -> Unit {
for i, k in codes {
comp.handle_input(@nested.InputEvent::Key(k, true), t + i.reinterpret_as_uint() * 2U)
comp.handle_input(@nested.InputEvent::Key(k, false), t + i.reinterpret_as_uint() * 2U + 1U)
}
}
///| p i z z a
let pizza_keys : Array[UInt] = [25U, 23U, 44U, 44U, 30U]
///| Press Super+. the way a keyboard does it.
fn press_super_period(comp : @host.ChandraCompositor, t : UInt) -> Unit {
comp.handle_input(@nested.InputEvent::Key(125U, true), t)
comp.handle_input(@nested.InputEvent::Key(52U, true), t + 1U)
comp.handle_input(@nested.InputEvent::Key(52U, false), t + 2U)
comp.handle_input(@nested.InputEvent::Key(125U, false), t + 3U)
ignore(comp.compose_frame())
}
///| The string argument of a message's words (length word, then the bytes).
fn words_string(args : Array[UInt]) -> String {
let n = args[0].reinterpret_as_int() - 1
let b : Array[Byte] = []
for i = 0; i < n; i = i + 1 {
let w = args[1 + i / 4]
b.push(((w >> ((i % 4) * 8)) & 0xFFU).to_byte())
}
@utf8.decode_lossy(Bytes::from_array(b))
}
///| A client with a zwp_text_input_v3 on its seat: (text input id, keyboard id).
fn text_input_for(comp : @host.ChandraCompositor, c : TestWaylandClient) -> (UInt, UInt) {
let seat = bind_global(c, 2U, "wl_seat", 7U)
let kbd = c.alloc_id()
let wk = @wayland.WireWriter::new()
wk.u32(kbd)
c.send(wk.finish_msg(seat, 1U)) // get_keyboard
let mgr = bind_global(c, 2U, "zwp_text_input_manager_v3", 1U)
let ti = c.alloc_id()
let w = @wayland.WireWriter::new()
w.u32(ti)
w.u32(seat)
c.send(w.finish_msg(mgr, 1U))
for _i = 0; _i < 5; _i = _i + 1 {
comp.step()
@sys.sleep_ms(2)
}
(ti, kbd)
}
///| enable (or disable) the text input with the caret at (x, y, 2, h), then commit.
fn text_input_state(comp : @host.ChandraCompositor, c : TestWaylandClient, ti : UInt, on : Bool, x : Int, y : Int, h : Int) -> Unit {
c.send(@wayland.WireWriter::new().finish_msg(ti, if on { 1U } else { 2U }))
if on {
let r = @wayland.WireWriter::new()
r.i32(x)
r.i32(y)
r.i32(2)
r.i32(h)
c.send(r.finish_msg(ti, 6U))
}
c.send(@wayland.WireWriter::new().finish_msg(ti, 7U))
for _i = 0; _i < 5; _i = _i + 1 {
comp.step()
@sys.sleep_ms(2)
}
}
///|
test "Super+. opens the picker; typing searches, Enter types the emoji into the app's text field" {
let socket_path = "/tmp/wayland-moon-emoji-" + @sys.getpid().to_string() + ".sock"
let comp = @host.ChandraCompositor::new(socket_path, @scene.ThemeTokens::moon_night(), 1280, 720).unwrap()
let (a, shm_a, surf_a, xdg_a, _, _) = open_and_configure_client(comp, socket_path, "Editor", "editor")
commit_shm_frame(comp, a, shm_a, surf_a, xdg_a, 1UL)
assert_eq(comp.kbd_win, Some(1UL))
let (ti, kbd) = text_input_for(comp, a)
// Created while its window has the keyboard: told so at once (enter with the surface).
let first = drain_args(a)
let enter = first.iter().find_first(m => m.0 == ti && m.1 == 0U).unwrap()
assert_eq(enter.2[0], surf_a)
// The app enables it with the caret at (100, 50) in its surface.
text_input_state(comp, a, ti, true, 100, 50, 18)
assert_true(comp.server.text_input_active(1UL))
press_super_period(comp, 10U)
assert_true(comp.emoji_picker_open())
assert_eq(comp.emoji_picker_error(), "")
// The panel sits under the caret.
let (ox, oy) = comp.windows.get(1UL).unwrap().surface_origin()
let r = comp.emoji_ui.unwrap().rect
assert_eq((r.x, r.y), (ox + 100, oy + 50 + 18 + 6))
type_keys(comp, pizza_keys, 20U)
let p = comp.emoji_picker().unwrap()
assert_eq(p.query, "pizza")
assert_eq(p.selected().unwrap().text, "🍕")
ignore(drain_args(a))
type_keys(comp, [28U], 40U) // Enter
assert_false(comp.emoji_picker_open())
let msgs = drain_args(a)
// commit_string("🍕") then done(serial 1: one commit so far), and no key reached the app.
let commit = msgs.iter().find_first(m => m.0 == ti && m.1 == 3U).unwrap()
assert_eq(words_string(commit.2), "🍕")
let done = msgs.iter().find_first(m => m.0 == ti && m.1 == 5U).unwrap()
assert_eq(done.2[0], 1U)
assert_eq(count_msgs(msgs, kbd, 3U), 0) // wl_keyboard.key
assert_eq(count_msgs(msgs, kbd, 2U), 0) // the app never lost the keyboard
assert_false(comp.screenshot_toast_shown())
// Keys reach the app again.
type_keys(comp, [30U], 50U)
assert_eq(count_msgs(drain_args(a), kbd, 3U), 2)
comp.close()
}
///|
test "without an active text field the emoji goes to the clipboard, and a notice says so" {
let socket_path = "/tmp/wayland-moon-emoji2-" + @sys.getpid().to_string() + ".sock"
let comp = @host.ChandraCompositor::new(socket_path, @scene.ThemeTokens::moon_night(), 1280, 720).unwrap()
let (a, shm_a, surf_a, xdg_a, _, _) = open_and_configure_client(comp, socket_path, "Terminal", "term")
commit_shm_frame(comp, a, shm_a, surf_a, xdg_a, 1UL)
let (ti, _) = text_input_for(comp, a)
text_input_state(comp, a, ti, true, 10, 10, 16)
text_input_state(comp, a, ti, false, 0, 0, 0) // the app turned it off again
assert_false(comp.server.text_input_active(1UL))
press_super_period(comp, 10U)
ignore(drain_args(a))
match comp.emoji_picker().unwrap().selected() {
Some(it) => assert_eq(comp.emoji_insert(it.text, false), Copied("Terminal has no text field taking typed text (text-input-v3)"))
None => fail("nothing selected")
}
assert_false(comp.emoji_picker_open())
assert_true(comp.server.owns_selection())
assert_true(comp.screenshot_toast_shown())
// Nothing was typed into the app.
assert_eq(count_msgs(drain_args(a), ti, 3U), 0)
comp.close()
}
///|
test "picker keys: arrows, tabs, skin tone, Esc; clicks outside close it" {
let comp = new_comp("emoji-keys")
press_super_period(comp, 10U)
let p = comp.emoji_picker().unwrap()
assert_eq(p.tab, 1) // no recents yet: Smileys
type_keys(comp, [106U, 108U], 20U) // Right, Down
assert_eq(p.sel, 1 + 9)
type_keys(comp, [15U], 30U) // Tab: People
assert_eq((p.tab, p.sel), (2, 0))
// Ctrl+Right twice: medium-light skin tone, applied to the waving hand.
comp.handle_input(@nested.InputEvent::Modifiers(4U, 0U, 0U, 0U), 40U)
type_keys(comp, [106U, 106U], 41U)
comp.handle_input(@nested.InputEvent::Modifiers(0U, 0U, 0U, 0U), 45U)
assert_eq(p.tone, 2)
assert_eq(p.selected().unwrap().text, "👋🏼")
// Backspace with nothing typed does nothing; Esc closes.
type_keys(comp, [14U], 50U)
assert_true(comp.emoji_picker_open())
type_keys(comp, [1U], 60U)
assert_false(comp.emoji_picker_open())
// Super+. again opens it; a click outside closes it.
press_super_period(comp, 70U)
assert_true(comp.emoji_picker_open())
click_at(comp, 5, 300, 80U)
assert_false(comp.emoji_picker_open())
// Super+. twice: open, then closed.
press_super_period(comp, 90U)
press_super_period(comp, 100U)
assert_false(comp.emoji_picker_open())
}
///|
test "clicking an emoji in the grid picks it; Shift keeps the picker open" {
let comp = new_comp("emoji-click")
press_super_period(comp, 10U)
let r = comp.emoji_ui.unwrap().rect
// The grid starts under the search field and the tabs: its third cell.
let gx = r.x + 12 + 2 * 40 + 20
let gy = r.y + 12 + 34 * 2 + 16 + 20
comp.handle_input(@nested.InputEvent::Modifiers(1U, 0U, 0U, 0U), 20U)
click_at(comp, gx, gy, 21U)
comp.handle_input(@nested.InputEvent::Modifiers(0U, 0U, 0U, 0U), 25U)
// No window: copied, and the picker closes (there is nothing to keep typing into).
assert_false(comp.emoji_picker_open())
assert_true(comp.server.owns_selection())
press_super_period(comp, 30U)
let p = comp.emoji_picker().unwrap()
assert_eq(p.tab, 0) // the recent emoji
assert_eq(p.items().map(i => i.text), [@emoji.all()[2].text])
}
///|
test "recent emoji and the skin tone are kept in state.edn" {
if @sys.getenv("CHANDRA_TEST_CONFIG") == "1" {
write_state_edn("{:note \"keep\"}\n")
let a = new_comp("emoji-save-a")
a.shell.persist = true
press_super_period(a, 10U)
let p = a.emoji_picker().unwrap()
p.set_tone(3)
ignore(a.emoji_insert("👍🏽", false))
press_super_period(a, 20U)
ignore(a.emoji_insert("🍕", false))
// read_state_edn reads the file as ASCII; the emoji are UTF-8.
let dir = @sys.getenv("XDG_CONFIG_HOME")
let text = @utf8.decode_lossy(@sys.read_file_bytes(dir + "/chandra/state.edn"))
assert_true(text.contains(":emoji"))
assert_true(text.contains("\"🍕\" \"👍🏽\""))
assert_true(text.contains(":skin-tone 3"))
assert_true(text.contains(":note \"keep\""))
let b = new_comp("emoji-save-b")
b.shell.persist = true
press_super_period(b, 10U)
let q = b.emoji_picker().unwrap()
assert_eq(q.tab, 0)
assert_eq(q.tone, 3)
assert_eq(q.items().map(i => i.text), ["🍕", "👍🏽"])
}
}
///| CHANDRA_EMOJI_SHOTS=<dir>: pictures of the picker over a window (docs, the thread).
test "screenshots of the picker" {
let dir = @sys.getenv("CHANDRA_EMOJI_SHOTS")
if dir.length() > 0 {
ignore(@sys.mkdir_p(dir))
let socket_path = "/tmp/wayland-moon-emojishots-" + @sys.getpid().to_string() + ".sock"
let comp = @host.ChandraCompositor::new(socket_path, @scene.ThemeTokens::moon_night(), 1280, 720).unwrap()
let (a, shm_a, surf_a, xdg_a, _, _) = open_and_configure_client(comp, socket_path, "Notes", "notes")
commit_shm_frame(comp, a, shm_a, surf_a, xdg_a, 1UL)
let (ti, _) = text_input_for(comp, a)
text_input_state(comp, a, ti, true, 120, 90, 18)
let shot = fn(name : String) raise {
let frame = comp.compose_frame()
assert_eq(@sys.write_file_bytes(dir + "/" + name, @renderer.encode_png_compressed(frame)), 0)
}
press_super_period(comp, 10U)
shot("picker-smileys.png")
type_keys(comp, [35U, 18U, 30U, 19U, 20U], 20U) // h e a r t
shot("picker-search.png")
type_keys(comp, [14U, 14U, 14U, 14U, 14U, 15U], 40U) // clear, then Tab: People
comp.handle_input(@nested.InputEvent::Modifiers(4U, 0U, 0U, 0U), 60U)
type_keys(comp, [106U, 106U, 106U], 61U) // Ctrl+Right x3: medium skin tone
comp.handle_input(@nested.InputEvent::Modifiers(0U, 0U, 0U, 0U), 70U)
type_keys(comp, [106U, 108U], 71U)
shot("picker-people-tone.png")
// The clipboard notice: the app turns its text field off, then an emoji is chosen.
text_input_state(comp, a, ti, false, 0, 0, 0)
type_keys(comp, [28U], 80U)
shot("picker-copied-notice.png")
comp.close()
}
}