diff options
| author | srdusr <[email protected]> | 2024-07-31 16:22:00 +0200 |
|---|---|---|
| committer | srdusr <[email protected]> | 2024-07-31 16:22:00 +0200 |
| commit | c180bfc34e4c74ba7cac9e0220e9c172c239fe71 (patch) | |
| tree | 45550c7eb7ae819a9c3a415acb9cfa5be1cfd03b /crates/x11/src/platform/tests.rs | |
| parent | 38683f069a039f9da6d7ddc64167850560fd07ed (diff) | |
| download | srdwm-c180bfc34e4c74ba7cac9e0220e9c172c239fe71.tar.gz srdwm-c180bfc34e4c74ba7cac9e0220e9c172c239fe71.zip | |
Split crates/x11/src/lib.rs (925 lines) into platform/
Pure reorganization, no behavior change - verified by diffing the
function-name and struct/trait-name sets before/after (both identical)
plus a full cargo test pass. lib.rs is now a thin shim (mod
declaration + pub use), same pattern crates/config used, since a crate
root can't itself become a directory. platform/mod.rs keeps the atom
table, Frame/X11Platform's struct definitions, the small free-function
helpers (err, modmask_for_keycode_in_mod_slots, rgb_to_pixel), and the
ClonedForRender trait+impl. The rest splits by concern:
- connect.rs: connect, keymap/modifier helpers, grab_keybindings.
- window.rs: manage_new_window and the other per-client lifecycle
methods (window_title/class, supports_wm_delete, unmanage,
frame_for).
- events.rs: handle_event, the X11 event-dispatch loop.
- actions.rs: raise_and_focus/request_close/sync_geometry/
redraw_all_decorations.
- trait_impl.rs: `impl Platform for X11Platform` - named to avoid
clippy's module_inception lint, since the containing directory is
already named `platform`.
- tests.rs: unsplit, same reasoning as every other split this pass.
A handful of X11Platform methods (frame_for, manage_new_window,
unmanage, raise_and_focus, request_close, sync_geometry,
keycode_to_keysym, modifiers_from_state, handle_event) went from
private to pub(super): called across what are now sibling submodules,
which Rust's privacy model doesn't let see each other's private items.
Diffstat (limited to 'crates/x11/src/platform/tests.rs')
| -rw-r--r-- | crates/x11/src/platform/tests.rs | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/crates/x11/src/platform/tests.rs b/crates/x11/src/platform/tests.rs new file mode 100644 index 0000000..61d8124 --- /dev/null +++ b/crates/x11/src/platform/tests.rs @@ -0,0 +1,48 @@ + use super::*; + + /// Builds a flattened `GetModifierMappingReply.keycodes`-shaped slice: + /// 8 slots (Shift, Lock, Control, Mod1..Mod5) of `per` keycodes each, + /// zero-padded, with `assignments` placing one real keycode into + /// specific slots. + fn modmap(per: usize, assignments: &[(usize, u8)]) -> Vec<u8> { + let mut v = vec![0u8; per * 8]; + for &(slot, kc) in assignments { + v[slot * per] = kc; + } + v + } + + #[test] + fn finds_numlock_on_mod2_the_common_case() { + let keycodes = modmap(2, &[(4, 77)]); // slot 4 == Mod2 + assert_eq!(modmask_for_keycode_in_mod_slots(77, 2, &keycodes), ModMask::M2); + } + + #[test] + fn finds_numlock_on_mod5_an_uncommon_but_real_layout() { + let keycodes = modmap(2, &[(7, 90)]); // slot 7 == Mod5 + assert_eq!(modmask_for_keycode_in_mod_slots(90, 2, &keycodes), ModMask::M5); + } + + #[test] + fn ignores_the_keycode_if_it_only_appears_in_shift_lock_or_control() { + // A keycode bound to Lock (e.g. Caps Lock's own keycode) must never + // be mistaken for Num Lock - only slots 3..8 (Mod1..Mod5) count. + let keycodes = modmap(2, &[(1, 66)]); // slot 1 == Lock + assert_eq!(modmask_for_keycode_in_mod_slots(66, 2, &keycodes), ModMask::from(0u16)); + } + + #[test] + fn keycode_zero_never_matches_even_if_a_slot_is_unpadded_zero() { + // Unused modifier slots are zero-padded, so keycode 0 must never + // resolve to a mask - otherwise a keyboard with no Num Lock key at + // all would spuriously "find" it in the first empty slot. + let keycodes = modmap(2, &[]); + assert_eq!(modmask_for_keycode_in_mod_slots(0, 2, &keycodes), ModMask::from(0u16)); + } + + #[test] + fn no_match_anywhere_returns_empty_mask() { + let keycodes = modmap(2, &[(3, 50)]); + assert_eq!(modmask_for_keycode_in_mod_slots(99, 2, &keycodes), ModMask::from(0u16)); + } |