Auth dialog: OSK auto-open, hex keysyms, and remote text input
CI / test (push) Failing after 52s

- Show the on-screen keyboard when the password dialog opens or reopens, and hide it on submit. Tapping the password field reopens it after a manual Hide.
- Route Chandra Remote text commits (including Enter, Tab, and Backspace) into the password dialog while it is up.
- Keymap: read hex keysyms (`0x31`, `0x20ac`, `0xffb7`) from libxkbcommon text-v1 keymaps, and accept `0x01000000`-range Unicode keysyms.
- Keymap: keypad keys produce digits when NumLock (Mod2) is active.
- Tests cover hex keysym parsing, NumLock keypad mapping, and the OSK/remote-text flow.
This commit is contained in:
nandi committed 2026-11-28 18:51:15 -08:00
1 parent 40c5d6722c
commit 851c39d827
5 files changed
+218 -12

No files matched your search

+9 -1
View File
@@ -313,6 +313,7 @@ fn ChandraCompositor::open_auth(self : ChandraCompositor, l : AuthLink, v : @pol
// Nothing else gets the keyboard or the pointer while it is up. // Nothing else gets the keyboard or the pointer while it is up.
self.set_kbd_focus(None) self.set_kbd_focus(None)
self.leave_pointer() self.leave_pointer()
self.osk_sync()
self.damage.mark_full() self.damage.mark_full()
} }
@@ -330,6 +331,7 @@ fn ChandraCompositor::close_auth(self : ChandraCompositor, dismiss : Bool) -> Un
Some(w) => if self.windows.contains(w) { self.set_kbd_focus(Some(w)) } Some(w) => if self.windows.contains(w) { self.set_kbd_focus(Some(w)) }
None => () None => ()
} }
self.osk_sync()
self.damage.mark_full() self.damage.mark_full()
} }
None => () None => ()
@@ -448,7 +450,13 @@ fn ChandraCompositor::auth_input(self : ChandraCompositor, ui : AuthUi, ev : @ne
PointerButton(button, pressed) => PointerButton(button, pressed) =>
if pressed && button == 272U { if pressed && button == 272U {
match self.auth_hit(ui) { match self.auth_hit(ui) {
Some(f) => self.auth_act(ui, ui.view.activate(f)) Some(f) => {
if f == Field && self.osk_enabled {
self.osk_manual_hide = false
self.osk_sync()
}
self.auth_act(ui, ui.view.activate(f))
}
None => () None => ()
} }
} }
+65
View File
@@ -920,3 +920,68 @@ test "Face unlock window: snaps, Apply, then the password dialog gets the keyboa
@sys.unlink(hpath) @sys.unlink(hpath)
comp.close() comp.close()
} }
///|
test "hex-keysym keymap, OSK auto-open/reopen, touch OSK tap, and remote_commit_text type into the password dialog" {
let hex_keymap : String =
#|xkb_keymap {
#|xkb_keycodes "evdev_aliases(qwerty)" {
#| minimum = 8;
#| maximum = 255;
#| <ESC> = 9;
#| <BKSP> = 22;
#| <AD03> = 26;
#| <AD04> = 27;
#| <AD09> = 32;
#| <RTRN> = 36;
#| <AC03> = 40;
#| <AB07> = 58;
#| <SPCE> = 65;
#|};
#|xkb_symbols "pc_us_inet(evdev)" {
#| key <ESC> { [ 0xff1b ] };
#| key <BKSP> { [ 0xff08, 0xff08 ] };
#| key <AD03> { [ 0x65, 0x45 ] };
#| key <AD04> { [ 0x72, 0x52 ] };
#| key <AD09> { [ 0x6f, 0x4f ] };
#| key <RTRN> { [ 0xff0d ] };
#| key <AC03> { [ 0x64, 0x44 ] };
#| key <AB07> { [ 0x6d, 0x4d ] };
#| key <SPCE> { [ 0x20 ] };
#|};
#|};
let r = rig("hex-osk-remote", None, "")
let comp = r.comp
comp.server.set_keymap(@utf8.encode(hex_keymap))
comp.set_osk_enabled(true)
assert_false(comp.osk_is_visible())
let (_, ok) = comp.control_command("auth-demo")
assert_true(ok)
assert_true(r.settle(fn() { comp.auth_view().map(v => v.phase == Asking).unwrap_or(false) }))
assert_true(comp.osk_is_visible())
let d = r.view()
// Physical/hardware keyboard typing through hex-keysym keymap.
auth_type(comp, "de")
assert_eq(d.typed(), 2)
// Touch OSK tap reaches the password field.
let (mx, my) = comp.osk_key_center("m").unwrap()
click_at(comp, mx, my, 20U)
assert_eq(d.typed(), 3)
// Chandra Remote text commit routes to the password dialog.
assert_true(comp.remote_commit_text("o"))
assert_eq(d.typed(), 4)
auth_alt(comp, 19U)
assert_true(d.reveal)
assert_eq(d.field_text(), "demo")
// Manual OSK Hide dismisses it; tapping the password field brings it back.
let (hx, hy) = comp.osk_key_center("Hide").unwrap()
click_at(comp, hx, hy, 25U)
assert_false(comp.osk_is_visible())
auth_click(comp, Field)
assert_true(comp.osk_is_visible())
// Submitting authorizes and hides the OSK automatically.
auth_press(comp, 28U)
assert_true(r.settle(fn() { comp.auth_view() is None && comp.auth_demos.length() == 0 }))
assert_false(comp.osk_is_visible())
comp.close()
}
+21
View File
@@ -2129,6 +2129,27 @@ pub fn ChandraCompositor::remote_commit_text(
text : String, text : String,
) -> Bool { ) -> Bool {
self.note_activity(@sys.monotonic_ms()) self.note_activity(@sys.monotonic_ms())
if self.auth is Some(_) {
for ch in text {
match self.auth {
Some(cur) =>
match ch {
'\n' | '\r' =>
self.auth_act(cur, cur.view.key(@polkit.key_enter, 0U, None))
'\t' => self.auth_act(cur, cur.view.key(@polkit.key_tab, 0U, None))
'\u{08}' | '\u{7f}' =>
self.auth_act(cur, cur.view.key(@polkit.key_backspace, 0U, None))
_ if ch.to_int() >= 0x20 =>
self.auth_act(cur, cur.view.key(0U, 0U, Some(ch)))
_ => ()
}
None => break
}
}
self.damage.mark_full()
self.frame_changed = true
return true
}
if self.shell.popup_open() { if self.shell.popup_open() {
for ch in text { for ch in text {
let name = match ch { let name = match ch {
+47 -11
View File
@@ -3,9 +3,10 @@
/// The compositor sees keys as evdev codes; the characters they type depend on the keyboard /// The compositor sees keys as evdev codes; the characters they type depend on the keyboard
/// layout, and a password typed on the wrong layout is the wrong password. So the auth dialog reads /// layout, and a password typed on the wrong layout is the wrong password. So the auth dialog reads
/// the xkb keymap (text format v1, what the host hands `WaylandServer::set_keymap`): the keycode /// the xkb keymap (text format v1, what the host hands `WaylandServer::set_keymap`): the keycode
/// names (`<AE01> = 10;`) and each key's symbols per group and level (`key <AE01> { [ 1, exclam ] };`), /// names (`<AE01> = 10;`) and each key's symbols per group and level (`key <AE01> { [ 1, exclam ] };`
/// and maps keysym names to characters (ASCII and Latin-1 names, `Uxxxx`, `0x100xxxxx`). Without a /// or hex keysyms like `[ 0x31, 0x21 ]`), and maps keysym names and hex keysyms (`0x20..0x7e`,
/// keymap (nested windows, tests) a built-in US layout is used. /// `0xa0..0xff`, `0x20ac`, keypad `0xff80..0xffb9`, `Uxxxx`, `0x01000000..0x0110ffff`) to
/// characters. Without a keymap (nested windows, tests) a built-in US layout is used.
///| One key's keysym names: groups, then levels. ///| One key's keysym names: groups, then levels.
struct KeySyms { struct KeySyms {
@@ -375,8 +376,8 @@ fn names() -> Map[String, Int] {
} }
///| ///|
fn hex_value(s : String) -> Int? { fn hex_u32(s : String) -> UInt? {
let mut v = 0 let mut v = 0U
if s.length() == 0 || s.length() > 8 { if s.length() == 0 || s.length() > 8 {
return None return None
} }
@@ -390,7 +391,7 @@ fn hex_value(s : String) -> Int? {
} else { } else {
return None return None
} }
v = v * 16 + d v = v * 16U + d.reinterpret_as_uint()
} }
Some(v) Some(v)
} }
@@ -401,10 +402,36 @@ pub fn keysym_char(name : String) -> Char? {
Some(cp) => return Some(Int::unsafe_to_char(cp)) Some(cp) => return Some(Int::unsafe_to_char(cp))
None => () None => ()
} }
let cp = if name.length() >= 5 && name.has_prefix("U") { let cp : Int? = if name.length() >= 5 && name.has_prefix("U") {
hex_value(name[1:].to_string()) match hex_u32(name[1:].to_string()) {
} else if (name.length() == 9 || name.length() == 10) && name.has_prefix("0x100") { Some(v) if v < 0x110000U => Some(v.reinterpret_as_int())
hex_value(name[5:].to_string()) _ => None
}
} else if name.length() >= 3 && (name.has_prefix("0x") || name.has_prefix("0X")) {
match hex_u32(name[2:].to_string()) {
Some(ks) =>
if (ks >= 0x20U && ks <= 0x7eU) || (ks >= 0xa0U && ks <= 0xffU) {
Some(ks.reinterpret_as_int())
} else if ks >= 0x01000000U && ks <= 0x0110ffffU {
Some((ks - 0x01000000U).reinterpret_as_int())
} else if ks == 0x20acU {
Some(0x20ac)
} else if ks >= 0xffb0U && ks <= 0xffb9U {
Some(0x30 + (ks - 0xffb0U).reinterpret_as_int())
} else {
match ks {
0xffaeU => Some(0x2e)
0xffabU => Some(0x2b)
0xffadU => Some(0x2d)
0xffaaU => Some(0x2a)
0xffafU => Some(0x2f)
0xff80U => Some(0x20)
0xffacU => Some(0x2c)
_ => None
}
}
None => None
}
} else { } else {
None None
} }
@@ -415,7 +442,7 @@ pub fn keysym_char(name : String) -> Char? {
} }
} }
///| Modifier bits of an xkb state (wl_keyboard.modifiers): Shift, Lock (Caps), Mod5 (AltGr). ///| Modifier bits of an xkb state (wl_keyboard.modifiers): Shift, Lock (Caps), Ctrl, Alt, NumLock (Mod2), Mod5 (AltGr).
pub let mask_shift : UInt = 1 pub let mask_shift : UInt = 1
///| ///|
@@ -427,6 +454,9 @@ pub let mask_ctrl : UInt = 4
///| ///|
pub let mask_alt : UInt = 8 pub let mask_alt : UInt = 8
///|
pub let mask_numlock : UInt = 0x10
///| ///|
pub let mask_altgr : UInt = 0x80 pub let mask_altgr : UInt = 0x80
@@ -473,6 +503,12 @@ pub fn Keymap::char_for(self : Keymap, code : UInt, mods : UInt, group : UInt) -
_ => () _ => ()
} }
} }
// Keypad keys (evdev KP7..KPDL) flip between navigation and digits when NumLock is active.
if code >= 71U && code <= 83U && (mods & mask_numlock) != 0U {
if at(base) is None && at(base + 1) is Some(_) {
level = base + (if shift { 0 } else { 1 })
}
}
at(level) at(level)
} }
+76
View File
@@ -77,7 +77,83 @@ test "keysym names" {
assert_eq(@polkit.keysym_char("EuroSign"), Some('€')) assert_eq(@polkit.keysym_char("EuroSign"), Some('€'))
assert_eq(@polkit.keysym_char("U0431"), Some('б')) assert_eq(@polkit.keysym_char("U0431"), Some('б'))
assert_eq(@polkit.keysym_char("0x10020ac"), Some('€')) assert_eq(@polkit.keysym_char("0x10020ac"), Some('€'))
assert_eq(@polkit.keysym_char("0x010020ac"), Some('€'))
assert_eq(@polkit.keysym_char("0x1000431"), Some('б'))
assert_eq(@polkit.keysym_char("Shift_L"), None) assert_eq(@polkit.keysym_char("Shift_L"), None)
// Numeric hex keysyms emitted by libxkbcommon's text v1 serialization.
assert_eq(@polkit.keysym_char("0x64"), Some('d'))
assert_eq(@polkit.keysym_char("0x44"), Some('D'))
assert_eq(@polkit.keysym_char("0x31"), Some('1'))
assert_eq(@polkit.keysym_char("0x21"), Some('!'))
assert_eq(@polkit.keysym_char("0x20"), Some(' '))
assert_eq(@polkit.keysym_char("0X7e"), Some('~'))
assert_eq(@polkit.keysym_char("0xe4"), Some('ä'))
assert_eq(@polkit.keysym_char("0xc4"), Some('Ä'))
assert_eq(@polkit.keysym_char("0x20ac"), Some('€'))
assert_eq(@polkit.keysym_char("0xffb7"), Some('7'))
assert_eq(@polkit.keysym_char("0xffae"), Some('.'))
assert_eq(@polkit.keysym_char("0xffab"), Some('+'))
// Non-printable X11 keysyms (editing, modifiers, dead keys, XF86 media keys, controls).
assert_eq(@polkit.keysym_char("0xff08"), None)
assert_eq(@polkit.keysym_char("0xff0d"), None)
assert_eq(@polkit.keysym_char("0xff1b"), None)
assert_eq(@polkit.keysym_char("0xffe1"), None)
assert_eq(@polkit.keysym_char("0xfe52"), None)
assert_eq(@polkit.keysym_char("0x1008ff11"), None)
assert_eq(@polkit.keysym_char("0x1005ff70"), None)
assert_eq(@polkit.keysym_char("0x000a"), None)
assert_eq(@polkit.keysym_char("0x007f"), None)
}
///| Hex keysyms as emitted by libxkbcommon 1.13's xkb_keymap_get_as_string(XKB_KEYMAP_FORMAT_TEXT_V1).
let xkb_hex_text : String =
#|xkb_keymap {
#|xkb_keycodes "evdev_aliases(qwerty)" {
#| minimum = 8;
#| maximum = 255;
#| <AE01> = 10;
#| <BKSP> = 22;
#| <AD03> = 26;
#| <RTRN> = 36;
#| <AC03> = 40;
#| <AC11> = 48;
#| <SPCE> = 65;
#| <KP7> = 79;
#|};
#|xkb_symbols "pc_us_inet(evdev)" {
#| key <AE01> { [ 0x31, 0x21 ] };
#| key <BKSP> { [ 0xff08, 0xff08 ] };
#| key <AD03> { [ 0x65, 0x45, 0x20ac, 0x20ac ] };
#| key <RTRN> { [ 0xff0d ] };
#| key <AC03> { [ 0x64, 0x44 ] };
#| key <AC11> { [ 0xe4, 0xc4 ] };
#| key <SPCE> { [ 0x20 ] };
#| key <KP7> { [ 0xff95, 0xffb7 ] };
#|};
#|};
///|
test "libxkbcommon hex keysym keymap: ASCII, Shift, Caps Lock, AltGr, NumLock and non-printable keys" {
let km = @polkit.Keymap::from_text(xkb_hex_text)
assert_eq(km.char_for(32U, 0U, 0U), Some('d'))
assert_eq(km.char_for(32U, @polkit.mask_shift, 0U), Some('D'))
assert_eq(km.char_for(32U, @polkit.mask_lock, 0U), Some('D'))
assert_eq(km.char_for(32U, @polkit.mask_shift | @polkit.mask_lock, 0U), Some('d'))
assert_eq(km.char_for(2U, 0U, 0U), Some('1'))
assert_eq(km.char_for(2U, @polkit.mask_shift, 0U), Some('!'))
assert_eq(km.char_for(2U, @polkit.mask_lock, 0U), Some('1'))
assert_eq(km.char_for(18U, 0U, 0U), Some('e'))
assert_eq(km.char_for(18U, @polkit.mask_altgr, 0U), Some('€'))
assert_eq(km.char_for(40U, 0U, 0U), Some('ä'))
assert_eq(km.char_for(40U, @polkit.mask_lock, 0U), Some('Ä'))
assert_eq(km.char_for(57U, 0U, 0U), Some(' '))
// Keypad 7: Home without NumLock, '7' with NumLock, back to Home with NumLock+Shift.
assert_eq(km.char_for(71U, 0U, 0U), None)
assert_eq(km.char_for(71U, @polkit.mask_numlock, 0U), Some('7'))
assert_eq(km.char_for(71U, @polkit.mask_numlock | @polkit.mask_shift, 0U), None)
// Non-printable editing keys stay None.
assert_eq(km.char_for(14U, 0U, 0U), None)
assert_eq(km.char_for(28U, 0U, 0U), None)
} }
///| ///|