Emoji picker (Super+.): search, tabs, skin tones, recents, text-input-v3 insertion
CI / test (push) Canceled after 0s
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:
39 files changed
+4942
-41
No files matched your search
@@ -103,6 +103,9 @@ enum ObjKind {
|
||||
ObjPrimaryOffer(UInt, UInt)
|
||||
ObjCursorShapeMgr
|
||||
ObjCursorShapeDev
|
||||
/// zwp_text_input_manager_v3 and its zwp_text_input_v3 objects (text_input.mbt).
|
||||
ObjTextInputMgr
|
||||
ObjTextInput
|
||||
}
|
||||
|
||||
///|
|
||||
@@ -241,6 +244,8 @@ struct ClientConn {
|
||||
mut next_offer : UInt
|
||||
/// wp_cursor_shape_v1 shape the client last asked for (0 = never set).
|
||||
mut cursor_shape : UInt
|
||||
/// zwp_text_input_v3 objects, by id (text_input.mbt).
|
||||
text_inputs : Map[UInt, TextInputState]
|
||||
mut alive : Bool
|
||||
}
|
||||
|
||||
@@ -272,6 +277,7 @@ fn ClientConn::new(client_id : UInt, fd : Int) -> ClientConn {
|
||||
source_actions: {},
|
||||
next_offer: 0xff000000U,
|
||||
cursor_shape: 0U,
|
||||
text_inputs: {},
|
||||
alive: true,
|
||||
}
|
||||
}
|
||||
@@ -345,6 +351,9 @@ pub(all) struct WaylandServer {
|
||||
mut primary : (UInt, UInt)?
|
||||
/// Client that currently has keyboard focus (receives selection events).
|
||||
mut kbd_client : UInt?
|
||||
/// The surface with keyboard focus: (client id, wl_surface id). Text inputs created while it
|
||||
/// has focus are told so at once.
|
||||
mut kbd_surface : (UInt, UInt)?
|
||||
/// Area a popup must stay inside, as (x, y, w, h) relative to its parent's content origin
|
||||
/// (the parent window id is passed). The host sets this; the default never constrains.
|
||||
mut popup_bounds : (UInt64) -> (Int, Int, Int, Int)
|
||||
@@ -388,6 +397,7 @@ pub fn WaylandServer::listen(
|
||||
keymap: Bytes::from_array([]),
|
||||
selection: None,
|
||||
kbd_client: None,
|
||||
kbd_surface: None,
|
||||
primary: None,
|
||||
popup_bounds: fn(_) { (-1000000, -1000000, 2000000, 2000000) },
|
||||
own_mimes: [],
|
||||
@@ -460,6 +470,7 @@ fn emit_registry_globals(c : ClientConn, reg_id : UInt) -> Unit {
|
||||
(9U, "wp_cursor_shape_manager_v1", 1U),
|
||||
(10U, "org_kde_kwin_server_decoration_manager", 1U),
|
||||
(11U, "zwp_primary_selection_device_manager_v1", 1U),
|
||||
(12U, "zwp_text_input_manager_v3", 1U),
|
||||
]
|
||||
for g in globals {
|
||||
let w = WireWriter::new()
|
||||
@@ -680,6 +691,8 @@ fn WaylandServer::dispatch_msg(
|
||||
c.data_ver = ver
|
||||
} else if iface == "zwp_primary_selection_device_manager_v1" {
|
||||
c.objects.set(new_id, ObjPrimaryManager)
|
||||
} else if iface == "zwp_text_input_manager_v3" {
|
||||
c.objects.set(new_id, ObjTextInputMgr)
|
||||
} else if iface == "wl_subcompositor" {
|
||||
c.objects.set(new_id, ObjSubcompositor)
|
||||
} else if iface == "wl_output" {
|
||||
@@ -1072,6 +1085,7 @@ fn WaylandServer::dispatch_msg(
|
||||
let id = reader.u32()
|
||||
c.objects.set(id, ObjCursorShapeDev)
|
||||
}
|
||||
ObjTextInputMgr | ObjTextInput => self.text_input_request(c, kind, obj_id, opcode, reader)
|
||||
ObjCursorShapeDev =>
|
||||
if opcode == 1U {
|
||||
// set_shape(serial, shape)
|
||||
@@ -2058,6 +2072,7 @@ pub fn WaylandServer::keyboard_enter(self : WaylandServer, win_id : UInt64) -> U
|
||||
None => ()
|
||||
Some((c, tl)) => {
|
||||
self.kbd_client = Some(c.client_id)
|
||||
self.kbd_surface = Some((c.client_id, tl.wl_surface_id))
|
||||
self.send_selection(c)
|
||||
self.send_primary(c)
|
||||
for kid in c.keyboard_ids {
|
||||
@@ -2067,6 +2082,7 @@ pub fn WaylandServer::keyboard_enter(self : WaylandServer, win_id : UInt64) -> U
|
||||
w.array([])
|
||||
c.send_msg(w.finish_msg(kid, 1U))
|
||||
}
|
||||
text_inputs_enter(c, tl.wl_surface_id)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2075,13 +2091,18 @@ pub fn WaylandServer::keyboard_enter(self : WaylandServer, win_id : UInt64) -> U
|
||||
pub fn WaylandServer::keyboard_leave(self : WaylandServer, win_id : UInt64) -> Unit {
|
||||
match self.win_client(win_id) {
|
||||
None => ()
|
||||
Some((c, tl)) =>
|
||||
Some((c, tl)) => {
|
||||
for kid in c.keyboard_ids {
|
||||
let w = WireWriter::new()
|
||||
w.u32(self.next_serial())
|
||||
w.u32(tl.wl_surface_id)
|
||||
c.send_msg(w.finish_msg(kid, 2U))
|
||||
}
|
||||
text_inputs_leave(c, tl.wl_surface_id)
|
||||
if self.kbd_surface == Some((c.client_id, tl.wl_surface_id)) {
|
||||
self.kbd_surface = None
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,193 @@
|
||||
///| text-input-v3 (zwp_text_input_v3): how Chandra types into apps, the way an input method does.
|
||||
///
|
||||
/// An app with a text field focused enables its text input; the compositor can then send it text
|
||||
/// (commit_string) that the app inserts at its caret, whatever the keyboard layout. The emoji
|
||||
/// picker uses it (compositor/host/emoji_picker.mbt). GTK 3 and 4, Qt 6, Firefox, foot and
|
||||
/// Ghostty speak it; Chromium only with --enable-wayland-ime.
|
||||
///
|
||||
/// The protocol follows keyboard focus: a text input gets `enter` with the focused surface when
|
||||
/// its client has the keyboard (or at once when created while it does) and `leave` when it goes.
|
||||
/// enable / disable / set_cursor_rectangle are double-buffered and take effect on commit; `done`
|
||||
/// carries how many commits the client has made, as the protocol asks.
|
||||
|
||||
///| One zwp_text_input_v3.
|
||||
struct TextInputState {
|
||||
/// The surface it was sent `enter` for (0: none).
|
||||
mut surface : UInt
|
||||
mut enabled : Bool
|
||||
mut pend_enabled : Bool
|
||||
/// The caret, surface-local (x, y, w, h); None until the client says.
|
||||
mut cursor : (Int, Int, Int, Int)?
|
||||
mut pend_cursor : (Int, Int, Int, Int)?
|
||||
/// commit requests received (the serial `done` carries).
|
||||
mut commits : UInt
|
||||
}
|
||||
|
||||
///| Requests on the manager and on text inputs.
|
||||
fn WaylandServer::text_input_request(
|
||||
self : WaylandServer,
|
||||
c : ClientConn,
|
||||
kind : ObjKind,
|
||||
obj_id : UInt,
|
||||
opcode : UInt,
|
||||
reader : WireReader,
|
||||
) -> Unit {
|
||||
match kind {
|
||||
ObjTextInputMgr =>
|
||||
if opcode == 0U {
|
||||
// destroy
|
||||
c.objects.remove(obj_id)
|
||||
send_delete_id(c, obj_id)
|
||||
} else if opcode == 1U {
|
||||
// get_text_input(id: new_id, seat)
|
||||
let id = reader.u32()
|
||||
c.objects.set(id, ObjTextInput)
|
||||
let ti : TextInputState = {
|
||||
surface: 0U,
|
||||
enabled: false,
|
||||
pend_enabled: false,
|
||||
cursor: None,
|
||||
pend_cursor: None,
|
||||
commits: 0U,
|
||||
}
|
||||
c.text_inputs.set(id, ti)
|
||||
match self.kbd_surface {
|
||||
Some((cid, sid)) if cid == c.client_id && c.surfaces.contains(sid) => {
|
||||
ti.surface = sid
|
||||
send_text_input_surface(c, id, 0U, sid)
|
||||
}
|
||||
_ => ()
|
||||
}
|
||||
}
|
||||
ObjTextInput =>
|
||||
match c.text_inputs.get(obj_id) {
|
||||
None => ()
|
||||
Some(ti) =>
|
||||
match opcode {
|
||||
0U => {
|
||||
// destroy
|
||||
c.text_inputs.remove(obj_id)
|
||||
c.objects.remove(obj_id)
|
||||
send_delete_id(c, obj_id)
|
||||
}
|
||||
1U => {
|
||||
// enable: also resets the pending state
|
||||
ti.pend_enabled = true
|
||||
ti.pend_cursor = None
|
||||
}
|
||||
2U => ti.pend_enabled = false // disable
|
||||
6U => {
|
||||
// set_cursor_rectangle(x, y, width, height)
|
||||
let x = reader.i32()
|
||||
let y = reader.i32()
|
||||
let w = reader.i32()
|
||||
let h = reader.i32()
|
||||
ti.pend_cursor = Some((x, y, w, h))
|
||||
}
|
||||
7U => {
|
||||
// commit
|
||||
ti.commits = ti.commits + 1U
|
||||
ti.enabled = ti.pend_enabled
|
||||
match ti.pend_cursor {
|
||||
Some(r) => ti.cursor = Some(r)
|
||||
None => if !ti.enabled { ti.cursor = None }
|
||||
}
|
||||
}
|
||||
// set_surrounding_text, set_text_change_cause, set_content_type: not needed to
|
||||
// insert text.
|
||||
_ => ()
|
||||
}
|
||||
}
|
||||
_ => ()
|
||||
}
|
||||
}
|
||||
|
||||
///| enter (opcode 0) or leave (1) for `surface`.
|
||||
fn send_text_input_surface(c : ClientConn, id : UInt, opcode : UInt, surface : UInt) -> Unit {
|
||||
let w = WireWriter::new()
|
||||
w.u32(surface)
|
||||
c.send_msg(w.finish_msg(id, opcode))
|
||||
}
|
||||
|
||||
///| The client's keyboard focus moved to `surface`: tell its text inputs.
|
||||
fn text_inputs_enter(c : ClientConn, surface : UInt) -> Unit {
|
||||
for id, ti in c.text_inputs {
|
||||
if ti.surface != 0U && ti.surface != surface {
|
||||
send_text_input_surface(c, id, 1U, ti.surface)
|
||||
}
|
||||
if ti.surface != surface {
|
||||
ti.surface = surface
|
||||
send_text_input_surface(c, id, 0U, surface)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
///| The client lost keyboard focus on `surface`.
|
||||
fn text_inputs_leave(c : ClientConn, surface : UInt) -> Unit {
|
||||
for id, ti in c.text_inputs {
|
||||
if ti.surface == surface {
|
||||
ti.surface = 0U
|
||||
// The client disables it in answer; until it commits that, it can't take text anyway.
|
||||
ti.enabled = false
|
||||
send_text_input_surface(c, id, 1U, surface)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
///| The enabled text inputs on window `win_id`'s surface: (client, ids).
|
||||
fn WaylandServer::active_text_inputs(self : WaylandServer, win_id : UInt64) -> (ClientConn, Array[UInt])? {
|
||||
match self.win_client(win_id) {
|
||||
None => None
|
||||
Some((c, tl)) => {
|
||||
let ids : Array[UInt] = []
|
||||
for id, ti in c.text_inputs {
|
||||
if ti.enabled && ti.surface == tl.wl_surface_id {
|
||||
ids.push(id)
|
||||
}
|
||||
}
|
||||
if ids.length() == 0 {
|
||||
None
|
||||
} else {
|
||||
Some((c, ids))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
///| Whether window `win_id` has a text field taking text right now (an enabled text input on its
|
||||
/// focused surface).
|
||||
pub fn WaylandServer::text_input_active(self : WaylandServer, win_id : UInt64) -> Bool {
|
||||
self.active_text_inputs(win_id) is Some(_)
|
||||
}
|
||||
|
||||
///| The caret of window `win_id`'s active text input, relative to its surface: (x, y, w, h).
|
||||
pub fn WaylandServer::text_input_cursor(self : WaylandServer, win_id : UInt64) -> (Int, Int, Int, Int)? {
|
||||
match self.active_text_inputs(win_id) {
|
||||
Some((c, ids)) =>
|
||||
match c.text_inputs.get(ids[0]) {
|
||||
Some(ti) => ti.cursor
|
||||
None => None
|
||||
}
|
||||
None => None
|
||||
}
|
||||
}
|
||||
|
||||
///| Type `text` into window `win_id`'s focused text field (commit_string + done). False when it
|
||||
/// has no enabled text input: nothing was sent.
|
||||
pub fn WaylandServer::text_input_commit(self : WaylandServer, win_id : UInt64, text : String) -> Bool {
|
||||
match self.active_text_inputs(win_id) {
|
||||
None => false
|
||||
Some((c, ids)) => {
|
||||
for id in ids {
|
||||
let ti = c.text_inputs.get(id).unwrap()
|
||||
let w = WireWriter::new()
|
||||
w.str(text)
|
||||
c.send_msg(w.finish_msg(id, 3U)) // commit_string
|
||||
let d = WireWriter::new()
|
||||
d.u32(ti.commits)
|
||||
c.send_msg(d.finish_msg(id, 5U)) // done
|
||||
}
|
||||
true
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user