diff --git a/compositor/host/auth.mbt b/compositor/host/auth.mbt index b01f397..58b8103 100644 --- a/compositor/host/auth.mbt +++ b/compositor/host/auth.mbt @@ -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. self.set_kbd_focus(None) self.leave_pointer() + self.osk_sync() 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)) } None => () } + self.osk_sync() self.damage.mark_full() } None => () @@ -448,7 +450,13 @@ fn ChandraCompositor::auth_input(self : ChandraCompositor, ui : AuthUi, ev : @ne PointerButton(button, pressed) => if pressed && button == 272U { 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 => () } } diff --git a/compositor/host/auth_test.mbt b/compositor/host/auth_test.mbt index 334e23b..e9ee39d 100644 --- a/compositor/host/auth_test.mbt +++ b/compositor/host/auth_test.mbt @@ -920,3 +920,68 @@ test "Face unlock window: snaps, Apply, then the password dialog gets the keyboa @sys.unlink(hpath) 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; + #| = 9; + #| = 22; + #| = 26; + #| = 27; + #| = 32; + #| = 36; + #| = 40; + #| = 58; + #| = 65; + #|}; + #|xkb_symbols "pc_us_inet(evdev)" { + #| key { [ 0xff1b ] }; + #| key { [ 0xff08, 0xff08 ] }; + #| key { [ 0x65, 0x45 ] }; + #| key { [ 0x72, 0x52 ] }; + #| key { [ 0x6f, 0x4f ] }; + #| key { [ 0xff0d ] }; + #| key { [ 0x64, 0x44 ] }; + #| key { [ 0x6d, 0x4d ] }; + #| key { [ 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() +} diff --git a/compositor/host/compositor.mbt b/compositor/host/compositor.mbt index dbaa8ec..39ac913 100644 --- a/compositor/host/compositor.mbt +++ b/compositor/host/compositor.mbt @@ -2129,6 +2129,27 @@ pub fn ChandraCompositor::remote_commit_text( text : String, ) -> Bool { 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() { for ch in text { let name = match ch { diff --git a/compositor/polkit/keymap.mbt b/compositor/polkit/keymap.mbt index a360d4b..aef553b 100644 --- a/compositor/polkit/keymap.mbt +++ b/compositor/polkit/keymap.mbt @@ -3,9 +3,10 @@ /// 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 /// the xkb keymap (text format v1, what the host hands `WaylandServer::set_keymap`): the keycode -/// names (` = 10;`) and each key's symbols per group and level (`key { [ 1, exclam ] };`), -/// and maps keysym names to characters (ASCII and Latin-1 names, `Uxxxx`, `0x100xxxxx`). Without a -/// keymap (nested windows, tests) a built-in US layout is used. +/// names (` = 10;`) and each key's symbols per group and level (`key { [ 1, exclam ] };` +/// or hex keysyms like `[ 0x31, 0x21 ]`), and maps keysym names and hex keysyms (`0x20..0x7e`, +/// `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. struct KeySyms { @@ -375,8 +376,8 @@ fn names() -> Map[String, Int] { } ///| -fn hex_value(s : String) -> Int? { - let mut v = 0 +fn hex_u32(s : String) -> UInt? { + let mut v = 0U if s.length() == 0 || s.length() > 8 { return None } @@ -390,7 +391,7 @@ fn hex_value(s : String) -> Int? { } else { return None } - v = v * 16 + d + v = v * 16U + d.reinterpret_as_uint() } Some(v) } @@ -401,10 +402,36 @@ pub fn keysym_char(name : String) -> Char? { Some(cp) => return Some(Int::unsafe_to_char(cp)) None => () } - let cp = if name.length() >= 5 && name.has_prefix("U") { - hex_value(name[1:].to_string()) - } else if (name.length() == 9 || name.length() == 10) && name.has_prefix("0x100") { - hex_value(name[5:].to_string()) + let cp : Int? = if name.length() >= 5 && name.has_prefix("U") { + match hex_u32(name[1:].to_string()) { + Some(v) if v < 0x110000U => Some(v.reinterpret_as_int()) + _ => 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 { 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 ///| @@ -427,6 +454,9 @@ pub let mask_ctrl : UInt = 4 ///| pub let mask_alt : UInt = 8 +///| +pub let mask_numlock : UInt = 0x10 + ///| 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) } diff --git a/compositor/polkit/polkit_test.mbt b/compositor/polkit/polkit_test.mbt index 2feba2e..6ea0301 100644 --- a/compositor/polkit/polkit_test.mbt +++ b/compositor/polkit/polkit_test.mbt @@ -77,7 +77,83 @@ test "keysym names" { assert_eq(@polkit.keysym_char("EuroSign"), Some('€')) assert_eq(@polkit.keysym_char("U0431"), 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) + // 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; + #| = 10; + #| = 22; + #| = 26; + #| = 36; + #| = 40; + #| = 48; + #| = 65; + #| = 79; + #|}; + #|xkb_symbols "pc_us_inet(evdev)" { + #| key { [ 0x31, 0x21 ] }; + #| key { [ 0xff08, 0xff08 ] }; + #| key { [ 0x65, 0x45, 0x20ac, 0x20ac ] }; + #| key { [ 0xff0d ] }; + #| key { [ 0x64, 0x44 ] }; + #| key { [ 0xe4, 0xc4 ] }; + #| key { [ 0x20 ] }; + #| key { [ 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) } ///|