niri
Clone
https://git.tahinli.com/Tahinli/niri.git
0 watching·0 forks·Rust·GPL-3.0·12.1 MiB·53500dc·Tahinli·1 month ago·2998 commits
| 1 | use std::fmt::Write as _; |
| 2 | |
| 3 | use insta::assert_snapshot; |
| 4 | use niri_config::{Action, BoundAction, Config}; |
| 5 | use smithay::backend::input::{InputEvent, InputTime, KeyState, Keycode}; |
| 6 | use smithay::input::keyboard::xkb::Keymap; |
| 7 | use wayland_client::protocol::wl_pointer; |
| 8 | use wayland_client::protocol::wl_surface::WlSurface; |
| 9 | |
| 10 | use crate::tests::client::ClientId; |
| 11 | use crate::tests::fixture::Fixture; |
| 12 | use crate::tests::test_input_backend::{TestInputBackend, TestKeyboardKeyEvent}; |
| 13 | |
| 14 | #[derive(Clone, Copy)] |
| 15 | enum Op { |
| 16 | Press(Keycode), |
| 17 | Release(Keycode), |
| 18 | MouseButton { |
| 19 | name: &'static str, |
| 20 | code: u32, |
| 21 | state: wl_pointer::ButtonState, |
| 22 | }, |
| 23 | /// A scroll tick. Scrolls are momentary events, so they have no press or release. |
| 24 | Scroll { |
| 25 | name: &'static str, |
| 26 | source: wl_pointer::AxisSource, |
| 27 | /// Positive scrolls down. |
| 28 | amount: f64, |
| 29 | }, |
| 30 | } |
| 31 | |
| 32 | /// Mouse buttons that can be pressed and released, named after the binds that trigger them. |
| 33 | const MOUSE_BUTTONS: &[(&str, u32)] = &[ |
| 34 | ("MouseLeft", 0x110), |
| 35 | ("MouseRight", 0x111), |
| 36 | ("MouseMiddle", 0x112), |
| 37 | ("MouseBack", 0x113), |
| 38 | ("MouseForward", 0x114), |
| 39 | ]; |
| 40 | |
| 41 | /// Scrolls, named after the binds that trigger them. |
| 42 | const SCROLLS: &[(&str, wl_pointer::AxisSource, f64)] = &[ |
| 43 | ("WheelScrollDown", wl_pointer::AxisSource::Wheel, 10.), |
| 44 | ("WheelScrollUp", wl_pointer::AxisSource::Wheel, -10.), |
| 45 | ]; |
| 46 | |
| 47 | fn parse(keymap: &Keymap, input: &str) -> Vec<Op> { |
| 48 | let mut ops = Vec::new(); |
| 49 | for part in input.split_ascii_whitespace() { |
| 50 | // Scrolls are momentary, so they are written without a prefix. |
| 51 | let (pressed, name) = match part.as_bytes().first() { |
| 52 | Some(b'+') => (Some(true), &part[1..]), |
| 53 | Some(b'-') => (Some(false), &part[1..]), |
| 54 | _ => (None, part), |
| 55 | }; |
| 56 | |
| 57 | if let Some((name, source, amount)) = SCROLLS.iter().copied().find(|(n, _, _)| *n == name) { |
| 58 | assert!( |
| 59 | pressed.is_none(), |
| 60 | "scrolls have no press or release: {part}" |
| 61 | ); |
| 62 | ops.push(Op::Scroll { |
| 63 | name, |
| 64 | source, |
| 65 | amount, |
| 66 | }); |
| 67 | continue; |
| 68 | } |
| 69 | |
| 70 | if let Some((name, code)) = MOUSE_BUTTONS.iter().copied().find(|(n, _)| *n == name) { |
| 71 | let state = match pressed { |
| 72 | Some(true) => wl_pointer::ButtonState::Pressed, |
| 73 | Some(false) => wl_pointer::ButtonState::Released, |
| 74 | None => panic!("a mouse button needs a + or - prefix: {part}"), |
| 75 | }; |
| 76 | ops.push(Op::MouseButton { name, code, state }); |
| 77 | continue; |
| 78 | } |
| 79 | |
| 80 | let Some(key) = keymap.key_by_name(name) else { |
| 81 | panic!("unknown key {name}"); |
| 82 | }; |
| 83 | |
| 84 | let op = match pressed { |
| 85 | Some(true) => Op::Press(key), |
| 86 | Some(false) => Op::Release(key), |
| 87 | None => panic!("a key needs a + or - prefix: {part}"), |
| 88 | }; |
| 89 | |
| 90 | ops.push(op); |
| 91 | } |
| 92 | ops |
| 93 | } |
| 94 | |
| 95 | fn set_up(config: &str) -> (Fixture, ClientId, WlSurface) { |
| 96 | let mut config = Config::parse_mem(config).unwrap(); |
| 97 | |
| 98 | for bind in &mut config.binds.0 { |
| 99 | let actions = match &mut bind.action { |
| 100 | BoundAction::Press(press) => [Some(press), None], |
| 101 | BoundAction::Release(release) => [None, Some(release)], |
| 102 | BoundAction::Both { press, release } => [Some(press), Some(release)], |
| 103 | }; |
| 104 | for action in actions.into_iter().flatten() { |
| 105 | // knuffel doesn't understand #[cfg(test)]... |
| 106 | if !matches!(action, Action::Screenshot(_, _)) { |
| 107 | *action = Action::TestAction; |
| 108 | } |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | let mut f = Fixture::with_config(config); |
| 113 | f.add_output(1, (1920, 1080)); |
| 114 | |
| 115 | let id = f.add_client(); |
| 116 | let window = f.client(id).create_window(); |
| 117 | let surface = window.surface.clone(); |
| 118 | window.commit(); |
| 119 | f.roundtrip(id); |
| 120 | |
| 121 | let window = f.client(id).window(&surface); |
| 122 | window.attach_new_buffer(); |
| 123 | window.ack_last_and_commit(); |
| 124 | f.roundtrip(id); |
| 125 | |
| 126 | let _ = f.client(id).state.recent_keyboard_events(&surface); |
| 127 | |
| 128 | (f, id, surface) |
| 129 | } |
| 130 | |
| 131 | fn run_f(f: &mut Fixture, id: ClientId, surface: &WlSurface, input: &str) -> String { |
| 132 | let state = f.niri_state(); |
| 133 | let keyboard = state.niri.seat.get_keyboard().unwrap(); |
| 134 | let ops = keyboard.with_xkb_state(state, |xkb| { |
| 135 | let xkb = xkb.xkb().lock().unwrap(); |
| 136 | let keymap = unsafe { xkb.keymap() }; |
| 137 | parse(keymap, input) |
| 138 | }); |
| 139 | |
| 140 | let mut rv = String::new(); |
| 141 | for event in f.client(id).state.recent_keyboard_events(surface) { |
| 142 | let _ = writeln!(&mut rv, " surface {event}"); |
| 143 | } |
| 144 | |
| 145 | for op in ops { |
| 146 | let prev = f.niri().test_action_count; |
| 147 | |
| 148 | match op { |
| 149 | Op::Press(code) | Op::Release(code) => { |
| 150 | let key_state = match op { |
| 151 | Op::Press(_) => KeyState::Pressed, |
| 152 | Op::Release(_) => KeyState::Released, |
| 153 | _ => unreachable!(), |
| 154 | }; |
| 155 | |
| 156 | let state = f.niri_state(); |
| 157 | let keyboard = state.niri.seat.get_keyboard().unwrap(); |
| 158 | keyboard.with_xkb_state(state, |xkb| { |
| 159 | let xkb = xkb.xkb().lock().unwrap(); |
| 160 | let xkb_state = unsafe { xkb.state() }; |
| 161 | let keymap = xkb_state.get_keymap(); |
| 162 | |
| 163 | let c = match key_state { |
| 164 | KeyState::Pressed => "+", |
| 165 | KeyState::Released => "-", |
| 166 | }; |
| 167 | |
| 168 | let name = keymap.key_get_name(code).unwrap_or("None"); |
| 169 | let keysym = xkb_state.key_get_one_sym(code); |
| 170 | |
| 171 | let _ = writeln!(&mut rv, "{c}{name} {:>3} {keysym:?}", code.raw()); |
| 172 | }); |
| 173 | |
| 174 | let state = f.niri_state(); |
| 175 | state.process_input_event(InputEvent::<TestInputBackend>::Keyboard { |
| 176 | event: TestKeyboardKeyEvent { |
| 177 | time: InputTime::from_micros(0), |
| 178 | code, |
| 179 | state: key_state, |
| 180 | count: 1, // niri doesn't use this |
| 181 | }, |
| 182 | }); |
| 183 | } |
| 184 | Op::MouseButton { |
| 185 | name, |
| 186 | code, |
| 187 | state: button_state, |
| 188 | } => { |
| 189 | let c = match button_state { |
| 190 | wl_pointer::ButtonState::Pressed => "+", |
| 191 | wl_pointer::ButtonState::Released => "-", |
| 192 | _ => unreachable!(), |
| 193 | }; |
| 194 | let _ = writeln!(&mut rv, "{c}{name}"); |
| 195 | |
| 196 | let pointer = f.client(id).state.virtual_pointer(); |
| 197 | pointer.button(0, code, button_state); |
| 198 | pointer.frame(); |
| 199 | } |
| 200 | Op::Scroll { |
| 201 | name, |
| 202 | source, |
| 203 | amount, |
| 204 | } => { |
| 205 | let _ = writeln!(&mut rv, "{name}"); |
| 206 | |
| 207 | let pointer = f.client(id).state.virtual_pointer(); |
| 208 | pointer.axis_source(source); |
| 209 | pointer.axis(0, wl_pointer::Axis::VerticalScroll, amount); |
| 210 | pointer.frame(); |
| 211 | } |
| 212 | } |
| 213 | |
| 214 | f.roundtrip(id); |
| 215 | |
| 216 | let diff = f.niri().test_action_count - prev; |
| 217 | for _ in 0..diff { |
| 218 | let _ = writeln!(&mut rv, " niri test-action"); |
| 219 | } |
| 220 | |
| 221 | for event in f.client(id).state.recent_keyboard_events(surface) { |
| 222 | let _ = writeln!(&mut rv, " surface {event}"); |
| 223 | } |
| 224 | } |
| 225 | |
| 226 | rv |
| 227 | } |
| 228 | |
| 229 | fn run(config: &str, input: &str) -> String { |
| 230 | let (mut f, id, surface) = set_up(config); |
| 231 | run_f(&mut f, id, &surface, input) |
| 232 | } |
| 233 | |
| 234 | #[test] |
| 235 | fn combos() { |
| 236 | let c = " |
| 237 | binds { |
| 238 | Mod+Ctrl+Q { close-window; } |
| 239 | Mod+Ctrl+W { close-window; } |
| 240 | } |
| 241 | "; |
| 242 | |
| 243 | // Action press/release. |
| 244 | assert_snapshot!( |
| 245 | run(c, "+LWIN +LCTL +LatQ -LatQ -LCTL -LWIN"), |
| 246 | @" |
| 247 | +LWIN 133 XK_Super_L |
| 248 | surface key pressed: 125 |
| 249 | surface modifiers: depressed=64, latched=0, locked=0, group=0 |
| 250 | +LCTL 37 XK_Control_L |
| 251 | surface key pressed: 29 |
| 252 | surface modifiers: depressed=68, latched=0, locked=0, group=0 |
| 253 | +AD01 24 XK_q |
| 254 | niri test-action |
| 255 | -AD01 24 XK_q |
| 256 | -LCTL 37 XK_Control_L |
| 257 | surface key released: 29 |
| 258 | surface modifiers: depressed=64, latched=0, locked=0, group=0 |
| 259 | -LWIN 133 XK_Super_L |
| 260 | surface key released: 125 |
| 261 | surface modifiers: depressed=0, latched=0, locked=0, group=0 |
| 262 | " |
| 263 | ); |
| 264 | |
| 265 | // Two actions interleaved. |
| 266 | assert_snapshot!( |
| 267 | run(c, "+LWIN +LCTL +LatQ +LatW -LatQ -LatW -LCTL -LWIN"), |
| 268 | @" |
| 269 | +LWIN 133 XK_Super_L |
| 270 | surface key pressed: 125 |
| 271 | surface modifiers: depressed=64, latched=0, locked=0, group=0 |
| 272 | +LCTL 37 XK_Control_L |
| 273 | surface key pressed: 29 |
| 274 | surface modifiers: depressed=68, latched=0, locked=0, group=0 |
| 275 | +AD01 24 XK_q |
| 276 | niri test-action |
| 277 | +AD02 25 XK_w |
| 278 | niri test-action |
| 279 | -AD01 24 XK_q |
| 280 | -AD02 25 XK_w |
| 281 | -LCTL 37 XK_Control_L |
| 282 | surface key released: 29 |
| 283 | surface modifiers: depressed=64, latched=0, locked=0, group=0 |
| 284 | -LWIN 133 XK_Super_L |
| 285 | surface key released: 125 |
| 286 | surface modifiers: depressed=0, latched=0, locked=0, group=0 |
| 287 | " |
| 288 | ); |
| 289 | |
| 290 | // Extra Alt = no action. |
| 291 | assert_snapshot!( |
| 292 | run(c, "+LWIN +LCTL +LALT +LatQ -LALT -LatQ -LCTL -LWIN"), |
| 293 | @" |
| 294 | +LWIN 133 XK_Super_L |
| 295 | surface key pressed: 125 |
| 296 | surface modifiers: depressed=64, latched=0, locked=0, group=0 |
| 297 | +LCTL 37 XK_Control_L |
| 298 | surface key pressed: 29 |
| 299 | surface modifiers: depressed=68, latched=0, locked=0, group=0 |
| 300 | +LALT 64 XK_Alt_L |
| 301 | surface key pressed: 56 |
| 302 | surface modifiers: depressed=76, latched=0, locked=0, group=0 |
| 303 | +AD01 24 XK_q |
| 304 | surface key pressed: 16 |
| 305 | -LALT 64 XK_Alt_L |
| 306 | surface key released: 56 |
| 307 | surface modifiers: depressed=68, latched=0, locked=0, group=0 |
| 308 | -AD01 24 XK_q |
| 309 | surface key released: 16 |
| 310 | -LCTL 37 XK_Control_L |
| 311 | surface key released: 29 |
| 312 | surface modifiers: depressed=64, latched=0, locked=0, group=0 |
| 313 | -LWIN 133 XK_Super_L |
| 314 | surface key released: 125 |
| 315 | surface modifiers: depressed=0, latched=0, locked=0, group=0 |
| 316 | " |
| 317 | ); |
| 318 | |
| 319 | // Key that doesn't correspond to any bind. |
| 320 | assert_snapshot!( |
| 321 | run(c, "+LWIN +LCTL +LatA -LatA -LCTL -LWIN"), |
| 322 | @" |
| 323 | +LWIN 133 XK_Super_L |
| 324 | surface key pressed: 125 |
| 325 | surface modifiers: depressed=64, latched=0, locked=0, group=0 |
| 326 | +LCTL 37 XK_Control_L |
| 327 | surface key pressed: 29 |
| 328 | surface modifiers: depressed=68, latched=0, locked=0, group=0 |
| 329 | +AC01 38 XK_a |
| 330 | surface key pressed: 30 |
| 331 | -AC01 38 XK_a |
| 332 | surface key released: 30 |
| 333 | -LCTL 37 XK_Control_L |
| 334 | surface key released: 29 |
| 335 | surface modifiers: depressed=64, latched=0, locked=0, group=0 |
| 336 | -LWIN 133 XK_Super_L |
| 337 | surface key released: 125 |
| 338 | surface modifiers: depressed=0, latched=0, locked=0, group=0 |
| 339 | " |
| 340 | ); |
| 341 | |
| 342 | // Press action, press arbitrary, release action, release arbitrary. |
| 343 | assert_snapshot!( |
| 344 | run(c, "+LWIN +LCTL +LatQ +LatA -LatQ -LatA -LCTL -LWIN"), |
| 345 | @" |
| 346 | +LWIN 133 XK_Super_L |
| 347 | surface key pressed: 125 |
| 348 | surface modifiers: depressed=64, latched=0, locked=0, group=0 |
| 349 | +LCTL 37 XK_Control_L |
| 350 | surface key pressed: 29 |
| 351 | surface modifiers: depressed=68, latched=0, locked=0, group=0 |
| 352 | +AD01 24 XK_q |
| 353 | niri test-action |
| 354 | +AC01 38 XK_a |
| 355 | surface key pressed: 30 |
| 356 | -AD01 24 XK_q |
| 357 | -AC01 38 XK_a |
| 358 | surface key released: 30 |
| 359 | -LCTL 37 XK_Control_L |
| 360 | surface key released: 29 |
| 361 | surface modifiers: depressed=64, latched=0, locked=0, group=0 |
| 362 | -LWIN 133 XK_Super_L |
| 363 | surface key released: 125 |
| 364 | surface modifiers: depressed=0, latched=0, locked=0, group=0 |
| 365 | " |
| 366 | ); |
| 367 | |
| 368 | // Press arbitrary, press action, release arbitrary, release action. |
| 369 | assert_snapshot!( |
| 370 | run(c, "+LWIN +LCTL +LatA +LatQ -LatA -LatQ -LCTL -LWIN"), |
| 371 | @" |
| 372 | +LWIN 133 XK_Super_L |
| 373 | surface key pressed: 125 |
| 374 | surface modifiers: depressed=64, latched=0, locked=0, group=0 |
| 375 | +LCTL 37 XK_Control_L |
| 376 | surface key pressed: 29 |
| 377 | surface modifiers: depressed=68, latched=0, locked=0, group=0 |
| 378 | +AC01 38 XK_a |
| 379 | surface key pressed: 30 |
| 380 | +AD01 24 XK_q |
| 381 | niri test-action |
| 382 | -AC01 38 XK_a |
| 383 | surface key released: 30 |
| 384 | -AD01 24 XK_q |
| 385 | -LCTL 37 XK_Control_L |
| 386 | surface key released: 29 |
| 387 | surface modifiers: depressed=64, latched=0, locked=0, group=0 |
| 388 | -LWIN 133 XK_Super_L |
| 389 | surface key released: 125 |
| 390 | surface modifiers: depressed=0, latched=0, locked=0, group=0 |
| 391 | " |
| 392 | ); |
| 393 | |
| 394 | // Trigger action then release mods. |
| 395 | assert_snapshot!( |
| 396 | run(c, "+LWIN +LCTL +LatQ -LCTL -LWIN -LatQ"), |
| 397 | @" |
| 398 | +LWIN 133 XK_Super_L |
| 399 | surface key pressed: 125 |
| 400 | surface modifiers: depressed=64, latched=0, locked=0, group=0 |
| 401 | +LCTL 37 XK_Control_L |
| 402 | surface key pressed: 29 |
| 403 | surface modifiers: depressed=68, latched=0, locked=0, group=0 |
| 404 | +AD01 24 XK_q |
| 405 | niri test-action |
| 406 | -LCTL 37 XK_Control_L |
| 407 | surface key released: 29 |
| 408 | surface modifiers: depressed=64, latched=0, locked=0, group=0 |
| 409 | -LWIN 133 XK_Super_L |
| 410 | surface key released: 125 |
| 411 | surface modifiers: depressed=0, latched=0, locked=0, group=0 |
| 412 | -AD01 24 XK_q |
| 413 | " |
| 414 | ); |
| 415 | |
| 416 | // Modifiers after trigger key don't trigger the action. |
| 417 | assert_snapshot!( |
| 418 | run(c, "+LWIN +LatQ +LCTL -LCTL -LatQ -LWIN"), |
| 419 | @" |
| 420 | +LWIN 133 XK_Super_L |
| 421 | surface key pressed: 125 |
| 422 | surface modifiers: depressed=64, latched=0, locked=0, group=0 |
| 423 | +AD01 24 XK_q |
| 424 | surface key pressed: 16 |
| 425 | +LCTL 37 XK_Control_L |
| 426 | surface key pressed: 29 |
| 427 | surface modifiers: depressed=68, latched=0, locked=0, group=0 |
| 428 | -LCTL 37 XK_Control_L |
| 429 | surface key released: 29 |
| 430 | surface modifiers: depressed=64, latched=0, locked=0, group=0 |
| 431 | -AD01 24 XK_q |
| 432 | surface key released: 16 |
| 433 | -LWIN 133 XK_Super_L |
| 434 | surface key released: 125 |
| 435 | surface modifiers: depressed=0, latched=0, locked=0, group=0 |
| 436 | " |
| 437 | ); |
| 438 | } |
| 439 | |
| 440 | #[test] |
| 441 | fn inhibiting() { |
| 442 | let config = " |
| 443 | binds { |
| 444 | Q { close-window; } |
| 445 | U allow-inhibiting=false { close-window; } |
| 446 | } |
| 447 | "; |
| 448 | |
| 449 | let (mut f, id, surface) = set_up(config); |
| 450 | |
| 451 | let inhibitor = f.client(id).state.inhibit_shortcuts(&surface); |
| 452 | f.roundtrip(id); |
| 453 | |
| 454 | // While inhibiting, we don't intercept the shortcut. |
| 455 | assert_snapshot!( |
| 456 | run_f(&mut f, id, &surface, "+LatQ -LatQ"), |
| 457 | @" |
| 458 | +AD01 24 XK_q |
| 459 | surface key pressed: 16 |
| 460 | -AD01 24 XK_q |
| 461 | surface key released: 16 |
| 462 | " |
| 463 | ); |
| 464 | |
| 465 | // allow-inhibiting=false still triggers. |
| 466 | assert_snapshot!( |
| 467 | run_f(&mut f, id, &surface, "+LatU -LatU"), |
| 468 | @" |
| 469 | +AD07 30 XK_u |
| 470 | niri test-action |
| 471 | -AD07 30 XK_u |
| 472 | " |
| 473 | ); |
| 474 | |
| 475 | // Toggle it off after pressing the shortcut. |
| 476 | assert_snapshot!( |
| 477 | run_f(&mut f, id, &surface, "+LatQ"), |
| 478 | @" |
| 479 | +AD01 24 XK_q |
| 480 | surface key pressed: 16 |
| 481 | " |
| 482 | ); |
| 483 | |
| 484 | inhibitor.destroy(); |
| 485 | f.roundtrip(id); |
| 486 | |
| 487 | // The surface must get key release since it got the key press. |
| 488 | assert_snapshot!( |
| 489 | run_f(&mut f, id, &surface, "-LatQ"), |
| 490 | @" |
| 491 | -AD01 24 XK_q |
| 492 | surface key released: 16 |
| 493 | " |
| 494 | ); |
| 495 | |
| 496 | // Toggle it on after pressing the shortcut. |
| 497 | assert_snapshot!( |
| 498 | run_f(&mut f, id, &surface, "+LatQ"), |
| 499 | @" |
| 500 | +AD01 24 XK_q |
| 501 | niri test-action |
| 502 | " |
| 503 | ); |
| 504 | |
| 505 | let _inhibitor = f.client(id).state.inhibit_shortcuts(&surface); |
| 506 | f.roundtrip(id); |
| 507 | |
| 508 | // The surface must not get key release since there was no key press. |
| 509 | assert_snapshot!( |
| 510 | run_f(&mut f, id, &surface, "-LatQ"), |
| 511 | @"-AD01 24 XK_q" |
| 512 | ); |
| 513 | } |
| 514 | |
| 515 | #[test] |
| 516 | fn layouts() { |
| 517 | let c = r#" |
| 518 | input { |
| 519 | keyboard { |
| 520 | xkb { |
| 521 | layout "us,ru" |
| 522 | options "grp:lalt_toggle" |
| 523 | } |
| 524 | } |
| 525 | } |
| 526 | |
| 527 | binds { |
| 528 | Q { close-window; } |
| 529 | Shift+Slash { close-window; } |
| 530 | Cyrillic_ya { close-window; } |
| 531 | Shift+Cyrillic_che { close-window; } |
| 532 | Shift+Cyrillic_ES { close-window; } |
| 533 | } |
| 534 | "#; |
| 535 | |
| 536 | // On a cyrillic layout (ru), an ascii bind is searched in the ascii layout (us). |
| 537 | assert_snapshot!( |
| 538 | run(c, "+LALT -LALT +LatQ -LatQ"), |
| 539 | @" |
| 540 | +LALT 64 XK_ISO_Next_Group |
| 541 | surface key pressed: 56 |
| 542 | surface modifiers: depressed=0, latched=0, locked=0, group=1 |
| 543 | -LALT 64 XK_ISO_Next_Group |
| 544 | surface key released: 56 |
| 545 | +AD01 24 XK_Cyrillic_shorti |
| 546 | niri test-action |
| 547 | -AD01 24 XK_Cyrillic_shorti |
| 548 | " |
| 549 | ); |
| 550 | |
| 551 | // The slash key has . , in ru, and pressing those shouldn't search another layout. |
| 552 | assert_snapshot!( |
| 553 | run( |
| 554 | c, |
| 555 | " |
| 556 | +LFSH +AB10 -AB10 -LFSH \ |
| 557 | +LALT -LALT \ |
| 558 | +LFSH +AB10 -AB10 -LFSH |
| 559 | " |
| 560 | ), |
| 561 | @" |
| 562 | +LFSH 50 XK_Shift_L |
| 563 | surface key pressed: 42 |
| 564 | surface modifiers: depressed=1, latched=0, locked=0, group=0 |
| 565 | +AB10 61 XK_question |
| 566 | niri test-action |
| 567 | -AB10 61 XK_question |
| 568 | -LFSH 50 XK_Shift_L |
| 569 | surface key released: 42 |
| 570 | surface modifiers: depressed=0, latched=0, locked=0, group=0 |
| 571 | +LALT 64 XK_ISO_Next_Group |
| 572 | surface key pressed: 56 |
| 573 | surface modifiers: depressed=0, latched=0, locked=0, group=1 |
| 574 | -LALT 64 XK_ISO_Next_Group |
| 575 | surface key released: 56 |
| 576 | +LFSH 50 XK_Shift_L |
| 577 | surface key pressed: 42 |
| 578 | surface modifiers: depressed=1, latched=0, locked=0, group=1 |
| 579 | +AB10 61 XK_comma |
| 580 | surface key pressed: 53 |
| 581 | -AB10 61 XK_comma |
| 582 | surface key released: 53 |
| 583 | -LFSH 50 XK_Shift_L |
| 584 | surface key released: 42 |
| 585 | surface modifiers: depressed=0, latched=0, locked=0, group=1 |
| 586 | " |
| 587 | ); |
| 588 | |
| 589 | // In ru, / is on the \ / key (so, Shift + \). So, arguably, it would make sense for Shift + / |
| 590 | // to trigger it, but it currently doesn't (niri requires an unshifted trigger key, despite |
| 591 | // working fine with capital case alphabetic keys). |
| 592 | assert_snapshot!( |
| 593 | run(c, "+LALT -LALT +LFSH +BKSL -BKSL -LFSH"), |
| 594 | @" |
| 595 | +LALT 64 XK_ISO_Next_Group |
| 596 | surface key pressed: 56 |
| 597 | surface modifiers: depressed=0, latched=0, locked=0, group=1 |
| 598 | -LALT 64 XK_ISO_Next_Group |
| 599 | surface key released: 56 |
| 600 | +LFSH 50 XK_Shift_L |
| 601 | surface key pressed: 42 |
| 602 | surface modifiers: depressed=1, latched=0, locked=0, group=1 |
| 603 | +BKSL 51 XK_slash |
| 604 | surface key pressed: 43 |
| 605 | -BKSL 51 XK_slash |
| 606 | surface key released: 43 |
| 607 | -LFSH 50 XK_Shift_L |
| 608 | surface key released: 42 |
| 609 | surface modifiers: depressed=0, latched=0, locked=0, group=1 |
| 610 | " |
| 611 | ); |
| 612 | |
| 613 | // Я should trigger the Cyrillic_ya bind, but it currently doesn't. (Nobody binds keys like this |
| 614 | // in Russia, but people do in other countries with their non-ASCII characters.) |
| 615 | assert_snapshot!( |
| 616 | run(c, "+LALT -LALT +LatZ -LatZ"), |
| 617 | @" |
| 618 | +LALT 64 XK_ISO_Next_Group |
| 619 | surface key pressed: 56 |
| 620 | surface modifiers: depressed=0, latched=0, locked=0, group=1 |
| 621 | -LALT 64 XK_ISO_Next_Group |
| 622 | surface key released: 56 |
| 623 | +AB01 52 XK_Cyrillic_ya |
| 624 | surface key pressed: 44 |
| 625 | -AB01 52 XK_Cyrillic_ya |
| 626 | surface key released: 44 |
| 627 | " |
| 628 | ); |
| 629 | |
| 630 | // Non-ASCII binds should also be case-insensitive where reasonable, just like ASCII ones. Or, |
| 631 | // more accurately, the trigger key for a Modifier+key bind should be Modifier-insensitive. |
| 632 | assert_snapshot!( |
| 633 | run(c, "+LALT -LALT +LFSH +LatX -LatX -LFSH"), |
| 634 | @" |
| 635 | +LALT 64 XK_ISO_Next_Group |
| 636 | surface key pressed: 56 |
| 637 | surface modifiers: depressed=0, latched=0, locked=0, group=1 |
| 638 | -LALT 64 XK_ISO_Next_Group |
| 639 | surface key released: 56 |
| 640 | +LFSH 50 XK_Shift_L |
| 641 | surface key pressed: 42 |
| 642 | surface modifiers: depressed=1, latched=0, locked=0, group=1 |
| 643 | +AB02 53 XK_Cyrillic_CHE |
| 644 | surface key pressed: 45 |
| 645 | -AB02 53 XK_Cyrillic_CHE |
| 646 | surface key released: 45 |
| 647 | -LFSH 50 XK_Shift_L |
| 648 | surface key released: 42 |
| 649 | surface modifiers: depressed=0, latched=0, locked=0, group=1 |
| 650 | " |
| 651 | ); |
| 652 | assert_snapshot!( |
| 653 | run(c, "+LALT -LALT +LFSH +LatC -LatC -LFSH"), |
| 654 | @" |
| 655 | +LALT 64 XK_ISO_Next_Group |
| 656 | surface key pressed: 56 |
| 657 | surface modifiers: depressed=0, latched=0, locked=0, group=1 |
| 658 | -LALT 64 XK_ISO_Next_Group |
| 659 | surface key released: 56 |
| 660 | +LFSH 50 XK_Shift_L |
| 661 | surface key pressed: 42 |
| 662 | surface modifiers: depressed=1, latched=0, locked=0, group=1 |
| 663 | +AB03 54 XK_Cyrillic_ES |
| 664 | surface key pressed: 46 |
| 665 | -AB03 54 XK_Cyrillic_ES |
| 666 | surface key released: 46 |
| 667 | -LFSH 50 XK_Shift_L |
| 668 | surface key released: 42 |
| 669 | surface modifiers: depressed=0, latched=0, locked=0, group=1 |
| 670 | " |
| 671 | ); |
| 672 | |
| 673 | // ASCII binds on Russian should search the configured ASCII layout, not QWERTY. |
| 674 | // LatR corresponds to P on colemak_dh_ortho. |
| 675 | let c = r#" |
| 676 | input { |
| 677 | keyboard { |
| 678 | xkb { |
| 679 | layout "us,ru" |
| 680 | variant "colemak_dh_ortho," |
| 681 | options "grp:lalt_toggle" |
| 682 | } |
| 683 | } |
| 684 | } |
| 685 | |
| 686 | binds { |
| 687 | P { close-window; } |
| 688 | } |
| 689 | "#; |
| 690 | assert_snapshot!(run(c, "+LALT -LALT +LatR -LatR"), |
| 691 | @" |
| 692 | +LALT 64 XK_ISO_Next_Group |
| 693 | surface key pressed: 56 |
| 694 | surface modifiers: depressed=0, latched=0, locked=0, group=1 |
| 695 | -LALT 64 XK_ISO_Next_Group |
| 696 | surface key released: 56 |
| 697 | +AD04 27 XK_Cyrillic_ka |
| 698 | niri test-action |
| 699 | -AD04 27 XK_Cyrillic_ka |
| 700 | "); |
| 701 | |
| 702 | // ASCII fallback should find the first configured ASCII layout. |
| 703 | let c = r#" |
| 704 | input { |
| 705 | keyboard { |
| 706 | xkb { |
| 707 | layout "ru,us,us" |
| 708 | variant ",colemak_dh_ortho," |
| 709 | options "grp:lalt_toggle" |
| 710 | } |
| 711 | } |
| 712 | } |
| 713 | |
| 714 | binds { |
| 715 | P { close-window; } |
| 716 | } |
| 717 | "#; |
| 718 | // Input in ru (should fall back to us-colemak), |
| 719 | // then input in us-colemak (no fallback, works), |
| 720 | // then input in us-qwerty (no fallback, no bind). |
| 721 | assert_snapshot!(run(c, "+LatR -LatR +LALT -LALT +LatR -LatR +LALT -LALT +LatR -LatR"), |
| 722 | @" |
| 723 | +AD04 27 XK_Cyrillic_ka |
| 724 | niri test-action |
| 725 | -AD04 27 XK_Cyrillic_ka |
| 726 | +LALT 64 XK_ISO_Next_Group |
| 727 | surface key pressed: 56 |
| 728 | surface modifiers: depressed=0, latched=0, locked=0, group=1 |
| 729 | -LALT 64 XK_ISO_Next_Group |
| 730 | surface key released: 56 |
| 731 | +AD04 27 XK_p |
| 732 | niri test-action |
| 733 | -AD04 27 XK_p |
| 734 | +LALT 64 XK_ISO_Next_Group |
| 735 | surface key pressed: 56 |
| 736 | surface modifiers: depressed=0, latched=0, locked=0, group=2 |
| 737 | -LALT 64 XK_ISO_Next_Group |
| 738 | surface key released: 56 |
| 739 | +AD04 27 XK_r |
| 740 | surface key pressed: 19 |
| 741 | -AD04 27 XK_r |
| 742 | surface key released: 19 |
| 743 | "); |
| 744 | |
| 745 | // We require the modifiers to match the bind for it to trigger. |
| 746 | // So Ctrl-? cannot be triggered on us-qwerty since entering ? necessarily requires a Shift. |
| 747 | // If you spell out Shift like Super-Shift-?, it should be triggerable (but currently isn't). |
| 748 | let c = r#" |
| 749 | input { |
| 750 | keyboard { |
| 751 | xkb { |
| 752 | layout "us" |
| 753 | } |
| 754 | } |
| 755 | } |
| 756 | |
| 757 | binds { |
| 758 | Ctrl+question { close-window; } |
| 759 | Super+Shift+question { close-window; } |
| 760 | } |
| 761 | "#; |
| 762 | assert_snapshot!(run(c, "+LCTL +AB10 -AB10 +LFSH +AB10 -AB10"), |
| 763 | @" |
| 764 | +LCTL 37 XK_Control_L |
| 765 | surface key pressed: 29 |
| 766 | surface modifiers: depressed=4, latched=0, locked=0, group=0 |
| 767 | +AB10 61 XK_slash |
| 768 | surface key pressed: 53 |
| 769 | -AB10 61 XK_slash |
| 770 | surface key released: 53 |
| 771 | +LFSH 50 XK_Shift_L |
| 772 | surface key pressed: 42 |
| 773 | surface modifiers: depressed=5, latched=0, locked=0, group=0 |
| 774 | +AB10 61 XK_question |
| 775 | surface key pressed: 53 |
| 776 | -AB10 61 XK_question |
| 777 | surface key released: 53 |
| 778 | "); |
| 779 | assert_snapshot!(run(c, "+LWIN +LFSH +AB10 -AB10"), |
| 780 | @" |
| 781 | +LWIN 133 XK_Super_L |
| 782 | surface key pressed: 125 |
| 783 | surface modifiers: depressed=64, latched=0, locked=0, group=0 |
| 784 | +LFSH 50 XK_Shift_L |
| 785 | surface key pressed: 42 |
| 786 | surface modifiers: depressed=65, latched=0, locked=0, group=0 |
| 787 | +AB10 61 XK_question |
| 788 | surface key pressed: 53 |
| 789 | -AB10 61 XK_question |
| 790 | surface key released: 53 |
| 791 | "); |
| 792 | } |
| 793 | |
| 794 | #[test] |
| 795 | fn release_binds() { |
| 796 | let c = " |
| 797 | binds { |
| 798 | Mod { |
| 799 | release { toggle-overview; } |
| 800 | } |
| 801 | Mod+Q { |
| 802 | release { close-window; } |
| 803 | } |
| 804 | Mod+U { center-column; } |
| 805 | Ctrl+Alt_L { |
| 806 | release { switch-layout \"next\"; } |
| 807 | } |
| 808 | Ctrl+Alt+U { close-window; } |
| 809 | } |
| 810 | "; |
| 811 | |
| 812 | // Releasing Mod by itself runs its release action. |
| 813 | assert_snapshot!(run(c, "+LWIN -LWIN"), @" |
| 814 | +LWIN 133 XK_Super_L |
| 815 | surface key pressed: 125 |
| 816 | surface modifiers: depressed=64, latched=0, locked=0, group=0 |
| 817 | -LWIN 133 XK_Super_L |
| 818 | niri test-action |
| 819 | surface key released: 125 |
| 820 | surface modifiers: depressed=0, latched=0, locked=0, group=0 |
| 821 | "); |
| 822 | |
| 823 | // Pressing another key in between cancels a modifier-only release bind. |
| 824 | assert_snapshot!(run(c, "+LWIN +LatA -LatA -LWIN"), @" |
| 825 | +LWIN 133 XK_Super_L |
| 826 | surface key pressed: 125 |
| 827 | surface modifiers: depressed=64, latched=0, locked=0, group=0 |
| 828 | +AC01 38 XK_a |
| 829 | surface key pressed: 30 |
| 830 | -AC01 38 XK_a |
| 831 | surface key released: 30 |
| 832 | -LWIN 133 XK_Super_L |
| 833 | surface key released: 125 |
| 834 | surface modifiers: depressed=0, latched=0, locked=0, group=0 |
| 835 | "); |
| 836 | |
| 837 | // Pressing a key that triggers its own bind cancels the pending release bind. |
| 838 | assert_snapshot!(run(c, "+LWIN +LatU -LatU -LWIN"), @" |
| 839 | +LWIN 133 XK_Super_L |
| 840 | surface key pressed: 125 |
| 841 | surface modifiers: depressed=64, latched=0, locked=0, group=0 |
| 842 | +AD07 30 XK_u |
| 843 | niri test-action |
| 844 | -AD07 30 XK_u |
| 845 | -LWIN 133 XK_Super_L |
| 846 | surface key released: 125 |
| 847 | surface modifiers: depressed=0, latched=0, locked=0, group=0 |
| 848 | "); |
| 849 | |
| 850 | // A key that was already held when the bind was pressed doesn't cancel it: only input in |
| 851 | // between does. |
| 852 | assert_snapshot!(run(c, "+LatA +LWIN -LatA -LWIN"), @" |
| 853 | +AC01 38 XK_a |
| 854 | surface key pressed: 30 |
| 855 | +LWIN 133 XK_Super_L |
| 856 | surface key pressed: 125 |
| 857 | surface modifiers: depressed=64, latched=0, locked=0, group=0 |
| 858 | -AC01 38 XK_a |
| 859 | surface key released: 30 |
| 860 | -LWIN 133 XK_Super_L |
| 861 | niri test-action |
| 862 | surface key released: 125 |
| 863 | surface modifiers: depressed=0, latched=0, locked=0, group=0 |
| 864 | "); |
| 865 | |
| 866 | // A release-only bind on a regular key. |
| 867 | assert_snapshot!(run(c, "+LWIN +LatQ -LatQ -LWIN"), @" |
| 868 | +LWIN 133 XK_Super_L |
| 869 | surface key pressed: 125 |
| 870 | surface modifiers: depressed=64, latched=0, locked=0, group=0 |
| 871 | +AD01 24 XK_q |
| 872 | -AD01 24 XK_q |
| 873 | niri test-action |
| 874 | -LWIN 133 XK_Super_L |
| 875 | surface key released: 125 |
| 876 | surface modifiers: depressed=0, latched=0, locked=0, group=0 |
| 877 | "); |
| 878 | |
| 879 | // The release action runs even if the modifiers are released before the trigger key. |
| 880 | assert_snapshot!(run(c, "+LWIN +LatQ -LWIN -LatQ"), @" |
| 881 | +LWIN 133 XK_Super_L |
| 882 | surface key pressed: 125 |
| 883 | surface modifiers: depressed=64, latched=0, locked=0, group=0 |
| 884 | +AD01 24 XK_q |
| 885 | -LWIN 133 XK_Super_L |
| 886 | surface key released: 125 |
| 887 | surface modifiers: depressed=0, latched=0, locked=0, group=0 |
| 888 | -AD01 24 XK_q |
| 889 | niri test-action |
| 890 | "); |
| 891 | |
| 892 | // Another key in between cancels it, no matter the trigger. |
| 893 | assert_snapshot!(run(c, "+LWIN +LatQ +LatA -LatA -LWIN -LatQ"), @" |
| 894 | +LWIN 133 XK_Super_L |
| 895 | surface key pressed: 125 |
| 896 | surface modifiers: depressed=64, latched=0, locked=0, group=0 |
| 897 | +AD01 24 XK_q |
| 898 | +AC01 38 XK_a |
| 899 | surface key pressed: 30 |
| 900 | -AC01 38 XK_a |
| 901 | surface key released: 30 |
| 902 | -LWIN 133 XK_Super_L |
| 903 | surface key released: 125 |
| 904 | surface modifiers: depressed=0, latched=0, locked=0, group=0 |
| 905 | -AD01 24 XK_q |
| 906 | "); |
| 907 | |
| 908 | // Ctrl+Alt_L is a modifier-only bind: its whole key consists of modifiers, so releasing the |
| 909 | // combo on its own runs its release action. |
| 910 | assert_snapshot!(run(c, "+LCTL +LALT -LALT -LCTL"), @" |
| 911 | +LCTL 37 XK_Control_L |
| 912 | surface key pressed: 29 |
| 913 | surface modifiers: depressed=4, latched=0, locked=0, group=0 |
| 914 | +LALT 64 XK_Alt_L |
| 915 | surface key pressed: 56 |
| 916 | surface modifiers: depressed=12, latched=0, locked=0, group=0 |
| 917 | -LALT 64 XK_Alt_L |
| 918 | niri test-action |
| 919 | surface key released: 56 |
| 920 | surface modifiers: depressed=4, latched=0, locked=0, group=0 |
| 921 | -LCTL 37 XK_Control_L |
| 922 | surface key released: 29 |
| 923 | surface modifiers: depressed=0, latched=0, locked=0, group=0 |
| 924 | "); |
| 925 | |
| 926 | // Pressing another key in between cancels it, so using Ctrl+Alt+A as an app shortcut does not |
| 927 | // additionally switch the layout. |
| 928 | assert_snapshot!(run(c, "+LCTL +LALT +LatA -LatA -LALT -LCTL"), @" |
| 929 | +LCTL 37 XK_Control_L |
| 930 | surface key pressed: 29 |
| 931 | surface modifiers: depressed=4, latched=0, locked=0, group=0 |
| 932 | +LALT 64 XK_Alt_L |
| 933 | surface key pressed: 56 |
| 934 | surface modifiers: depressed=12, latched=0, locked=0, group=0 |
| 935 | +AC01 38 XK_a |
| 936 | surface key pressed: 30 |
| 937 | -AC01 38 XK_a |
| 938 | surface key released: 30 |
| 939 | -LALT 64 XK_Alt_L |
| 940 | surface key released: 56 |
| 941 | surface modifiers: depressed=4, latched=0, locked=0, group=0 |
| 942 | -LCTL 37 XK_Control_L |
| 943 | surface key released: 29 |
| 944 | surface modifiers: depressed=0, latched=0, locked=0, group=0 |
| 945 | "); |
| 946 | |
| 947 | // Pressing a key that triggers its own bind cancels the Ctrl+Alt_L release bind. |
| 948 | assert_snapshot!(run(c, "+LCTL +LALT +LatU -LatU -LALT -LCTL"), @" |
| 949 | +LCTL 37 XK_Control_L |
| 950 | surface key pressed: 29 |
| 951 | surface modifiers: depressed=4, latched=0, locked=0, group=0 |
| 952 | +LALT 64 XK_Alt_L |
| 953 | surface key pressed: 56 |
| 954 | surface modifiers: depressed=12, latched=0, locked=0, group=0 |
| 955 | +AD07 30 XK_u |
| 956 | niri test-action |
| 957 | -AD07 30 XK_u |
| 958 | -LALT 64 XK_Alt_L |
| 959 | surface key released: 56 |
| 960 | surface modifiers: depressed=4, latched=0, locked=0, group=0 |
| 961 | -LCTL 37 XK_Control_L |
| 962 | surface key released: 29 |
| 963 | surface modifiers: depressed=0, latched=0, locked=0, group=0 |
| 964 | "); |
| 965 | } |
| 966 | |
| 967 | #[test] |
| 968 | fn press_and_release_binds() { |
| 969 | let c = " |
| 970 | binds { |
| 971 | Mod+Q { |
| 972 | press { close-window; } |
| 973 | release { center-column; } |
| 974 | } |
| 975 | } |
| 976 | "; |
| 977 | |
| 978 | // Both actions run, and the key never reaches the surface. |
| 979 | assert_snapshot!(run(c, "+LWIN +LatQ -LatQ -LWIN"), @" |
| 980 | +LWIN 133 XK_Super_L |
| 981 | surface key pressed: 125 |
| 982 | surface modifiers: depressed=64, latched=0, locked=0, group=0 |
| 983 | +AD01 24 XK_q |
| 984 | niri test-action |
| 985 | -AD01 24 XK_q |
| 986 | niri test-action |
| 987 | -LWIN 133 XK_Super_L |
| 988 | surface key released: 125 |
| 989 | surface modifiers: depressed=0, latched=0, locked=0, group=0 |
| 990 | "); |
| 991 | |
| 992 | // The release action runs even if the modifiers are released first. |
| 993 | assert_snapshot!(run(c, "+LWIN +LatQ -LWIN -LatQ"), @" |
| 994 | +LWIN 133 XK_Super_L |
| 995 | surface key pressed: 125 |
| 996 | surface modifiers: depressed=64, latched=0, locked=0, group=0 |
| 997 | +AD01 24 XK_q |
| 998 | niri test-action |
| 999 | -LWIN 133 XK_Super_L |
| 1000 | surface key released: 125 |
| 1001 | surface modifiers: depressed=0, latched=0, locked=0, group=0 |
| 1002 | -AD01 24 XK_q |
| 1003 | niri test-action |
| 1004 | "); |
| 1005 | |
| 1006 | // Extra modifiers held at release don't stop the release action either. |
| 1007 | assert_snapshot!(run(c, "+LWIN +LatQ +LCTL +LFSH -LatQ -LFSH -LCTL -LWIN"), @" |
| 1008 | +LWIN 133 XK_Super_L |
| 1009 | surface key pressed: 125 |
| 1010 | surface modifiers: depressed=64, latched=0, locked=0, group=0 |
| 1011 | +AD01 24 XK_q |
| 1012 | niri test-action |
| 1013 | +LCTL 37 XK_Control_L |
| 1014 | surface key pressed: 29 |
| 1015 | surface modifiers: depressed=68, latched=0, locked=0, group=0 |
| 1016 | +LFSH 50 XK_Shift_L |
| 1017 | surface key pressed: 42 |
| 1018 | surface modifiers: depressed=69, latched=0, locked=0, group=0 |
| 1019 | -AD01 24 XK_Q |
| 1020 | niri test-action |
| 1021 | -LFSH 50 XK_Shift_L |
| 1022 | surface key released: 42 |
| 1023 | surface modifiers: depressed=68, latched=0, locked=0, group=0 |
| 1024 | -LCTL 37 XK_Control_L |
| 1025 | surface key released: 29 |
| 1026 | surface modifiers: depressed=64, latched=0, locked=0, group=0 |
| 1027 | -LWIN 133 XK_Super_L |
| 1028 | surface key released: 125 |
| 1029 | surface modifiers: depressed=0, latched=0, locked=0, group=0 |
| 1030 | "); |
| 1031 | |
| 1032 | // Push-to-talk: other input in between doesn't cancel the release action. |
| 1033 | assert_snapshot!(run(c, "+LWIN +LatQ +LatA -LatA -LatQ -LWIN"), @" |
| 1034 | +LWIN 133 XK_Super_L |
| 1035 | surface key pressed: 125 |
| 1036 | surface modifiers: depressed=64, latched=0, locked=0, group=0 |
| 1037 | +AD01 24 XK_q |
| 1038 | niri test-action |
| 1039 | +AC01 38 XK_a |
| 1040 | surface key pressed: 30 |
| 1041 | -AC01 38 XK_a |
| 1042 | surface key released: 30 |
| 1043 | -AD01 24 XK_q |
| 1044 | niri test-action |
| 1045 | -LWIN 133 XK_Super_L |
| 1046 | surface key released: 125 |
| 1047 | surface modifiers: depressed=0, latched=0, locked=0, group=0 |
| 1048 | "); |
| 1049 | |
| 1050 | // Pressing the key without the mod key held doesn't run either action. |
| 1051 | assert_snapshot!(run(c, "+LatQ +LWIN -LatQ -LWIN"), @" |
| 1052 | +AD01 24 XK_q |
| 1053 | surface key pressed: 16 |
| 1054 | +LWIN 133 XK_Super_L |
| 1055 | surface key pressed: 125 |
| 1056 | surface modifiers: depressed=64, latched=0, locked=0, group=0 |
| 1057 | -AD01 24 XK_q |
| 1058 | surface key released: 16 |
| 1059 | -LWIN 133 XK_Super_L |
| 1060 | surface key released: 125 |
| 1061 | surface modifiers: depressed=0, latched=0, locked=0, group=0 |
| 1062 | "); |
| 1063 | } |
| 1064 | |
| 1065 | #[test] |
| 1066 | fn generic_modifier_press_release() { |
| 1067 | let c = " |
| 1068 | binds { |
| 1069 | Super+Shift { |
| 1070 | press { close-window; } |
| 1071 | release { center-column; } |
| 1072 | } |
| 1073 | |
| 1074 | Ctrl+Shift { |
| 1075 | release { close-window; } |
| 1076 | } |
| 1077 | } |
| 1078 | "; |
| 1079 | |
| 1080 | // Press Super and then two Shifts. |
| 1081 | assert_snapshot!(run(c, "+LWIN +LFSH +RTSH -RTSH -LFSH -LWIN"), @" |
| 1082 | +LWIN 133 XK_Super_L |
| 1083 | surface key pressed: 125 |
| 1084 | surface modifiers: depressed=64, latched=0, locked=0, group=0 |
| 1085 | +LFSH 50 XK_Shift_L |
| 1086 | niri test-action |
| 1087 | surface modifiers: depressed=65, latched=0, locked=0, group=0 |
| 1088 | +RTSH 62 XK_Shift_R |
| 1089 | niri test-action |
| 1090 | -RTSH 62 XK_Shift_R |
| 1091 | niri test-action |
| 1092 | -LFSH 50 XK_Shift_L |
| 1093 | niri test-action |
| 1094 | surface modifiers: depressed=64, latched=0, locked=0, group=0 |
| 1095 | -LWIN 133 XK_Super_L |
| 1096 | surface key released: 125 |
| 1097 | surface modifiers: depressed=0, latched=0, locked=0, group=0 |
| 1098 | "); |
| 1099 | |
| 1100 | // Other release order. |
| 1101 | assert_snapshot!(run(c, "+LWIN +LFSH +RTSH -LFSH -RTSH -LWIN"), @" |
| 1102 | +LWIN 133 XK_Super_L |
| 1103 | surface key pressed: 125 |
| 1104 | surface modifiers: depressed=64, latched=0, locked=0, group=0 |
| 1105 | +LFSH 50 XK_Shift_L |
| 1106 | niri test-action |
| 1107 | surface modifiers: depressed=65, latched=0, locked=0, group=0 |
| 1108 | +RTSH 62 XK_Shift_R |
| 1109 | niri test-action |
| 1110 | -LFSH 50 XK_Shift_L |
| 1111 | niri test-action |
| 1112 | -RTSH 62 XK_Shift_R |
| 1113 | niri test-action |
| 1114 | surface modifiers: depressed=64, latched=0, locked=0, group=0 |
| 1115 | -LWIN 133 XK_Super_L |
| 1116 | surface key released: 125 |
| 1117 | surface modifiers: depressed=0, latched=0, locked=0, group=0 |
| 1118 | "); |
| 1119 | |
| 1120 | // Same but release-only. |
| 1121 | assert_snapshot!(run(c, "+LCTL +LFSH +RTSH -RTSH -LFSH -LCTL"), @" |
| 1122 | +LCTL 37 XK_Control_L |
| 1123 | surface key pressed: 29 |
| 1124 | surface modifiers: depressed=4, latched=0, locked=0, group=0 |
| 1125 | +LFSH 50 XK_Shift_L |
| 1126 | surface key pressed: 42 |
| 1127 | surface modifiers: depressed=5, latched=0, locked=0, group=0 |
| 1128 | +RTSH 62 XK_Shift_R |
| 1129 | surface key pressed: 54 |
| 1130 | -RTSH 62 XK_Shift_R |
| 1131 | niri test-action |
| 1132 | surface key released: 54 |
| 1133 | -LFSH 50 XK_Shift_L |
| 1134 | surface key released: 42 |
| 1135 | surface modifiers: depressed=4, latched=0, locked=0, group=0 |
| 1136 | -LCTL 37 XK_Control_L |
| 1137 | surface key released: 29 |
| 1138 | surface modifiers: depressed=0, latched=0, locked=0, group=0 |
| 1139 | "); |
| 1140 | |
| 1141 | // Other release order (release-only). |
| 1142 | assert_snapshot!(run(c, "+LCTL +LFSH +RTSH -LFSH -RTSH -LCTL"), @" |
| 1143 | +LCTL 37 XK_Control_L |
| 1144 | surface key pressed: 29 |
| 1145 | surface modifiers: depressed=4, latched=0, locked=0, group=0 |
| 1146 | +LFSH 50 XK_Shift_L |
| 1147 | surface key pressed: 42 |
| 1148 | surface modifiers: depressed=5, latched=0, locked=0, group=0 |
| 1149 | +RTSH 62 XK_Shift_R |
| 1150 | surface key pressed: 54 |
| 1151 | -LFSH 50 XK_Shift_L |
| 1152 | surface key released: 42 |
| 1153 | -RTSH 62 XK_Shift_R |
| 1154 | niri test-action |
| 1155 | surface key released: 54 |
| 1156 | surface modifiers: depressed=4, latched=0, locked=0, group=0 |
| 1157 | -LCTL 37 XK_Control_L |
| 1158 | surface key released: 29 |
| 1159 | surface modifiers: depressed=0, latched=0, locked=0, group=0 |
| 1160 | "); |
| 1161 | |
| 1162 | // Now, Shift first. |
| 1163 | assert_snapshot!(run(c, "+LFSH +LWIN -LWIN -LFSH"), @" |
| 1164 | +LFSH 50 XK_Shift_L |
| 1165 | surface key pressed: 42 |
| 1166 | surface modifiers: depressed=1, latched=0, locked=0, group=0 |
| 1167 | +LWIN 133 XK_Super_L |
| 1168 | niri test-action |
| 1169 | surface modifiers: depressed=65, latched=0, locked=0, group=0 |
| 1170 | -LWIN 133 XK_Super_L |
| 1171 | niri test-action |
| 1172 | surface modifiers: depressed=1, latched=0, locked=0, group=0 |
| 1173 | -LFSH 50 XK_Shift_L |
| 1174 | surface key released: 42 |
| 1175 | surface modifiers: depressed=0, latched=0, locked=0, group=0 |
| 1176 | "); |
| 1177 | |
| 1178 | // Two Supers. |
| 1179 | assert_snapshot!(run(c, "+LFSH +LWIN +RWIN -RWIN -LWIN -LFSH"), @" |
| 1180 | +LFSH 50 XK_Shift_L |
| 1181 | surface key pressed: 42 |
| 1182 | surface modifiers: depressed=1, latched=0, locked=0, group=0 |
| 1183 | +LWIN 133 XK_Super_L |
| 1184 | niri test-action |
| 1185 | surface modifiers: depressed=65, latched=0, locked=0, group=0 |
| 1186 | +RWIN 134 XK_Super_R |
| 1187 | niri test-action |
| 1188 | -RWIN 134 XK_Super_R |
| 1189 | niri test-action |
| 1190 | -LWIN 133 XK_Super_L |
| 1191 | niri test-action |
| 1192 | surface modifiers: depressed=1, latched=0, locked=0, group=0 |
| 1193 | -LFSH 50 XK_Shift_L |
| 1194 | surface key released: 42 |
| 1195 | surface modifiers: depressed=0, latched=0, locked=0, group=0 |
| 1196 | "); |
| 1197 | |
| 1198 | // Unrelated modifier in the middle. |
| 1199 | assert_snapshot!(run(c, "+LWIN +LCTL +LFSH -LCTL -LFSH -LWIN"), @" |
| 1200 | +LWIN 133 XK_Super_L |
| 1201 | surface key pressed: 125 |
| 1202 | surface modifiers: depressed=64, latched=0, locked=0, group=0 |
| 1203 | +LCTL 37 XK_Control_L |
| 1204 | surface key pressed: 29 |
| 1205 | surface modifiers: depressed=68, latched=0, locked=0, group=0 |
| 1206 | +LFSH 50 XK_Shift_L |
| 1207 | surface key pressed: 42 |
| 1208 | surface modifiers: depressed=69, latched=0, locked=0, group=0 |
| 1209 | -LCTL 37 XK_Control_L |
| 1210 | surface key released: 29 |
| 1211 | surface modifiers: depressed=65, latched=0, locked=0, group=0 |
| 1212 | -LFSH 50 XK_Shift_L |
| 1213 | surface key released: 42 |
| 1214 | surface modifiers: depressed=64, latched=0, locked=0, group=0 |
| 1215 | -LWIN 133 XK_Super_L |
| 1216 | surface key released: 125 |
| 1217 | surface modifiers: depressed=0, latched=0, locked=0, group=0 |
| 1218 | "); |
| 1219 | |
| 1220 | // Regressions. |
| 1221 | let c = " |
| 1222 | binds { |
| 1223 | Shift+Mod { close-window; } |
| 1224 | Ctrl+Super { close-window; } |
| 1225 | } |
| 1226 | "; |
| 1227 | |
| 1228 | assert_snapshot!(run(c, "+LFSH -LFSH"), @" |
| 1229 | +LFSH 50 XK_Shift_L |
| 1230 | surface key pressed: 42 |
| 1231 | surface modifiers: depressed=1, latched=0, locked=0, group=0 |
| 1232 | -LFSH 50 XK_Shift_L |
| 1233 | surface key released: 42 |
| 1234 | surface modifiers: depressed=0, latched=0, locked=0, group=0 |
| 1235 | "); |
| 1236 | |
| 1237 | assert_snapshot!(run(c, "+LFSH +LWIN -LWIN -LFSH"), @" |
| 1238 | +LFSH 50 XK_Shift_L |
| 1239 | surface key pressed: 42 |
| 1240 | surface modifiers: depressed=1, latched=0, locked=0, group=0 |
| 1241 | +LWIN 133 XK_Super_L |
| 1242 | niri test-action |
| 1243 | surface modifiers: depressed=65, latched=0, locked=0, group=0 |
| 1244 | -LWIN 133 XK_Super_L |
| 1245 | surface modifiers: depressed=1, latched=0, locked=0, group=0 |
| 1246 | -LFSH 50 XK_Shift_L |
| 1247 | surface key released: 42 |
| 1248 | surface modifiers: depressed=0, latched=0, locked=0, group=0 |
| 1249 | "); |
| 1250 | |
| 1251 | assert_snapshot!(run(c, "+LCTL -LCTL"), @" |
| 1252 | +LCTL 37 XK_Control_L |
| 1253 | surface key pressed: 29 |
| 1254 | surface modifiers: depressed=4, latched=0, locked=0, group=0 |
| 1255 | -LCTL 37 XK_Control_L |
| 1256 | surface key released: 29 |
| 1257 | surface modifiers: depressed=0, latched=0, locked=0, group=0 |
| 1258 | "); |
| 1259 | |
| 1260 | assert_snapshot!(run(c, "+LCTL +LWIN -LWIN -LCTL"), @" |
| 1261 | +LCTL 37 XK_Control_L |
| 1262 | surface key pressed: 29 |
| 1263 | surface modifiers: depressed=4, latched=0, locked=0, group=0 |
| 1264 | +LWIN 133 XK_Super_L |
| 1265 | niri test-action |
| 1266 | surface modifiers: depressed=68, latched=0, locked=0, group=0 |
| 1267 | -LWIN 133 XK_Super_L |
| 1268 | surface modifiers: depressed=4, latched=0, locked=0, group=0 |
| 1269 | -LCTL 37 XK_Control_L |
| 1270 | surface key released: 29 |
| 1271 | surface modifiers: depressed=0, latched=0, locked=0, group=0 |
| 1272 | "); |
| 1273 | } |
| 1274 | |
| 1275 | #[test] |
| 1276 | fn mod_key_press_and_release_bind() { |
| 1277 | let c = " |
| 1278 | binds { |
| 1279 | Mod { |
| 1280 | press { close-window; } |
| 1281 | release { center-column; } |
| 1282 | } |
| 1283 | } |
| 1284 | "; |
| 1285 | |
| 1286 | // Both actions run, and the window doesn't see the key press or release themselves, only the |
| 1287 | // modifier state. |
| 1288 | assert_snapshot!(run(c, "+LWIN -LWIN"), @" |
| 1289 | +LWIN 133 XK_Super_L |
| 1290 | niri test-action |
| 1291 | surface modifiers: depressed=64, latched=0, locked=0, group=0 |
| 1292 | -LWIN 133 XK_Super_L |
| 1293 | niri test-action |
| 1294 | surface modifiers: depressed=0, latched=0, locked=0, group=0 |
| 1295 | "); |
| 1296 | |
| 1297 | // Other input in between doesn't cancel the release action. |
| 1298 | assert_snapshot!(run(c, "+LWIN +LatA -LatA -LWIN"), @" |
| 1299 | +LWIN 133 XK_Super_L |
| 1300 | niri test-action |
| 1301 | surface modifiers: depressed=64, latched=0, locked=0, group=0 |
| 1302 | +AC01 38 XK_a |
| 1303 | surface key pressed: 30 |
| 1304 | -AC01 38 XK_a |
| 1305 | surface key released: 30 |
| 1306 | -LWIN 133 XK_Super_L |
| 1307 | niri test-action |
| 1308 | surface modifiers: depressed=0, latched=0, locked=0, group=0 |
| 1309 | "); |
| 1310 | } |
| 1311 | |
| 1312 | #[test] |
| 1313 | fn mod_key_press_and_release_bind_focus_change() { |
| 1314 | let c = " |
| 1315 | binds { |
| 1316 | Mod { |
| 1317 | press { close-window; } |
| 1318 | release { center-column; } |
| 1319 | } |
| 1320 | } |
| 1321 | "; |
| 1322 | |
| 1323 | let (mut f, id, surface) = set_up(c); |
| 1324 | |
| 1325 | // Hold mod: the press action runs, and the window sees the modifier state. |
| 1326 | run_f(&mut f, id, &surface, "+LWIN"); |
| 1327 | |
| 1328 | // A new window takes the keyboard focus while mod is held. |
| 1329 | let window = f.client(id).create_window(); |
| 1330 | let surface2 = window.surface.clone(); |
| 1331 | window.commit(); |
| 1332 | f.roundtrip(id); |
| 1333 | let window = f.client(id).window(&surface2); |
| 1334 | window.attach_new_buffer(); |
| 1335 | window.ack_last_and_commit(); |
| 1336 | f.roundtrip(id); |
| 1337 | |
| 1338 | // The new window doesn't see the key press or release, but the focus change and the |
| 1339 | // intercepted release still update its modifier state, so it doesn't get stuck with mod held. |
| 1340 | assert_snapshot!(run_f(&mut f, id, &surface2, "-LWIN +LatA -LatA"), @" |
| 1341 | surface enter: [] |
| 1342 | surface modifiers: depressed=64, latched=0, locked=0, group=0 |
| 1343 | -LWIN 133 XK_Super_L |
| 1344 | niri test-action |
| 1345 | surface modifiers: depressed=0, latched=0, locked=0, group=0 |
| 1346 | +AC01 38 XK_a |
| 1347 | surface key pressed: 30 |
| 1348 | -AC01 38 XK_a |
| 1349 | surface key released: 30 |
| 1350 | "); |
| 1351 | } |
| 1352 | |
| 1353 | #[test] |
| 1354 | fn modifier_key_trigger_binds() { |
| 1355 | let c = " |
| 1356 | binds { |
| 1357 | Mod+Control_L { |
| 1358 | press { close-window; } |
| 1359 | release { center-column; } |
| 1360 | } |
| 1361 | Alt+Control_L { close-window; } |
| 1362 | } |
| 1363 | "; |
| 1364 | |
| 1365 | // A modifier key used as the trigger is intercepted, so the window doesn't see the key press |
| 1366 | // and release, only the modifier state; both actions run. |
| 1367 | assert_snapshot!(run(c, "+LWIN +LCTL -LCTL -LWIN"), @" |
| 1368 | +LWIN 133 XK_Super_L |
| 1369 | surface key pressed: 125 |
| 1370 | surface modifiers: depressed=64, latched=0, locked=0, group=0 |
| 1371 | +LCTL 37 XK_Control_L |
| 1372 | niri test-action |
| 1373 | surface modifiers: depressed=68, latched=0, locked=0, group=0 |
| 1374 | -LCTL 37 XK_Control_L |
| 1375 | niri test-action |
| 1376 | surface modifiers: depressed=64, latched=0, locked=0, group=0 |
| 1377 | -LWIN 133 XK_Super_L |
| 1378 | surface key released: 125 |
| 1379 | surface modifiers: depressed=0, latched=0, locked=0, group=0 |
| 1380 | "); |
| 1381 | |
| 1382 | // Without the mod key held the bind doesn't match. |
| 1383 | assert_snapshot!(run(c, "+LCTL -LCTL"), @" |
| 1384 | +LCTL 37 XK_Control_L |
| 1385 | surface key pressed: 29 |
| 1386 | surface modifiers: depressed=4, latched=0, locked=0, group=0 |
| 1387 | -LCTL 37 XK_Control_L |
| 1388 | surface key released: 29 |
| 1389 | surface modifiers: depressed=0, latched=0, locked=0, group=0 |
| 1390 | "); |
| 1391 | |
| 1392 | // With Alt held instead, the Control_L press is intercepted, and only the press action runs. |
| 1393 | assert_snapshot!(run(c, "+LALT +LCTL -LCTL -LALT"), @" |
| 1394 | +LALT 64 XK_Alt_L |
| 1395 | surface key pressed: 56 |
| 1396 | surface modifiers: depressed=8, latched=0, locked=0, group=0 |
| 1397 | +LCTL 37 XK_Control_L |
| 1398 | niri test-action |
| 1399 | surface modifiers: depressed=12, latched=0, locked=0, group=0 |
| 1400 | -LCTL 37 XK_Control_L |
| 1401 | surface modifiers: depressed=8, latched=0, locked=0, group=0 |
| 1402 | -LALT 64 XK_Alt_L |
| 1403 | surface key released: 56 |
| 1404 | surface modifiers: depressed=0, latched=0, locked=0, group=0 |
| 1405 | "); |
| 1406 | } |
| 1407 | |
| 1408 | #[test] |
| 1409 | fn release_bind_on_modifier_key() { |
| 1410 | let c = " |
| 1411 | binds { |
| 1412 | Mod+Control_L { |
| 1413 | release { close-window; } |
| 1414 | } |
| 1415 | } |
| 1416 | "; |
| 1417 | |
| 1418 | // The press is forwarded so that apps see the modifier, and the release action runs when the |
| 1419 | // modifier is released on its own. |
| 1420 | assert_snapshot!(run(c, "+LWIN +LCTL -LCTL -LWIN"), @" |
| 1421 | +LWIN 133 XK_Super_L |
| 1422 | surface key pressed: 125 |
| 1423 | surface modifiers: depressed=64, latched=0, locked=0, group=0 |
| 1424 | +LCTL 37 XK_Control_L |
| 1425 | surface key pressed: 29 |
| 1426 | surface modifiers: depressed=68, latched=0, locked=0, group=0 |
| 1427 | -LCTL 37 XK_Control_L |
| 1428 | niri test-action |
| 1429 | surface key released: 29 |
| 1430 | surface modifiers: depressed=64, latched=0, locked=0, group=0 |
| 1431 | -LWIN 133 XK_Super_L |
| 1432 | surface key released: 125 |
| 1433 | surface modifiers: depressed=0, latched=0, locked=0, group=0 |
| 1434 | "); |
| 1435 | |
| 1436 | // Pressing another key in between cancels the release action. |
| 1437 | assert_snapshot!(run(c, "+LWIN +LCTL +LFSH -LCTL -LFSH -LWIN"), @" |
| 1438 | +LWIN 133 XK_Super_L |
| 1439 | surface key pressed: 125 |
| 1440 | surface modifiers: depressed=64, latched=0, locked=0, group=0 |
| 1441 | +LCTL 37 XK_Control_L |
| 1442 | surface key pressed: 29 |
| 1443 | surface modifiers: depressed=68, latched=0, locked=0, group=0 |
| 1444 | +LFSH 50 XK_Shift_L |
| 1445 | surface key pressed: 42 |
| 1446 | surface modifiers: depressed=69, latched=0, locked=0, group=0 |
| 1447 | -LCTL 37 XK_Control_L |
| 1448 | surface key released: 29 |
| 1449 | surface modifiers: depressed=65, latched=0, locked=0, group=0 |
| 1450 | -LFSH 50 XK_Shift_L |
| 1451 | surface key released: 42 |
| 1452 | surface modifiers: depressed=64, latched=0, locked=0, group=0 |
| 1453 | -LWIN 133 XK_Super_L |
| 1454 | surface key released: 125 |
| 1455 | surface modifiers: depressed=0, latched=0, locked=0, group=0 |
| 1456 | "); |
| 1457 | } |
| 1458 | |
| 1459 | #[test] |
| 1460 | fn modifier_key_and_keysym_triggers() { |
| 1461 | // `Ctrl` is not the mod key, so it is matched by keysym directly: both Control_L and |
| 1462 | // Control_R trigger it. |
| 1463 | let by_modifier = " |
| 1464 | binds { |
| 1465 | Ctrl { |
| 1466 | release { close-window; } |
| 1467 | } |
| 1468 | } |
| 1469 | "; |
| 1470 | |
| 1471 | assert_snapshot!(run(by_modifier, "+LCTL -LCTL"), @" |
| 1472 | +LCTL 37 XK_Control_L |
| 1473 | surface key pressed: 29 |
| 1474 | surface modifiers: depressed=4, latched=0, locked=0, group=0 |
| 1475 | -LCTL 37 XK_Control_L |
| 1476 | niri test-action |
| 1477 | surface key released: 29 |
| 1478 | surface modifiers: depressed=0, latched=0, locked=0, group=0 |
| 1479 | "); |
| 1480 | |
| 1481 | assert_snapshot!(run(by_modifier, "+RCTL -RCTL"), @" |
| 1482 | +RCTL 105 XK_Control_R |
| 1483 | surface key pressed: 97 |
| 1484 | surface modifiers: depressed=4, latched=0, locked=0, group=0 |
| 1485 | -RCTL 105 XK_Control_R |
| 1486 | niri test-action |
| 1487 | surface key released: 97 |
| 1488 | surface modifiers: depressed=0, latched=0, locked=0, group=0 |
| 1489 | "); |
| 1490 | |
| 1491 | // `Control_L` is a specific key instead, so it doesn't trigger on Control_R, which reaches |
| 1492 | // the window instead. |
| 1493 | let by_keysym = " |
| 1494 | binds { |
| 1495 | Control_L { |
| 1496 | release { close-window; } |
| 1497 | } |
| 1498 | } |
| 1499 | "; |
| 1500 | |
| 1501 | assert_snapshot!(run(by_keysym, "+LCTL -LCTL"), @" |
| 1502 | +LCTL 37 XK_Control_L |
| 1503 | surface key pressed: 29 |
| 1504 | surface modifiers: depressed=4, latched=0, locked=0, group=0 |
| 1505 | -LCTL 37 XK_Control_L |
| 1506 | niri test-action |
| 1507 | surface key released: 29 |
| 1508 | surface modifiers: depressed=0, latched=0, locked=0, group=0 |
| 1509 | "); |
| 1510 | |
| 1511 | assert_snapshot!(run(by_keysym, "+RCTL -RCTL"), @" |
| 1512 | +RCTL 105 XK_Control_R |
| 1513 | surface key pressed: 97 |
| 1514 | surface modifiers: depressed=4, latched=0, locked=0, group=0 |
| 1515 | -RCTL 105 XK_Control_R |
| 1516 | surface key released: 97 |
| 1517 | surface modifiers: depressed=0, latched=0, locked=0, group=0 |
| 1518 | "); |
| 1519 | } |
| 1520 | |
| 1521 | #[test] |
| 1522 | fn mod_key_trigger_with_own_modifier() { |
| 1523 | // The trigger is the configured mod key, and has Mod at a modifier. |
| 1524 | let bind_by_mod = " |
| 1525 | binds { |
| 1526 | Mod+Super_L { close-window; } |
| 1527 | } |
| 1528 | "; |
| 1529 | |
| 1530 | assert_snapshot!(run(bind_by_mod, "+LWIN -LWIN"), @" |
| 1531 | +LWIN 133 XK_Super_L |
| 1532 | niri test-action |
| 1533 | surface modifiers: depressed=64, latched=0, locked=0, group=0 |
| 1534 | -LWIN 133 XK_Super_L |
| 1535 | surface modifiers: depressed=0, latched=0, locked=0, group=0 |
| 1536 | "); |
| 1537 | |
| 1538 | let bind_by_keysym = " |
| 1539 | binds { |
| 1540 | Super_L { close-window; } |
| 1541 | } |
| 1542 | "; |
| 1543 | |
| 1544 | assert_snapshot!(run(bind_by_keysym, "+LWIN -LWIN"), @" |
| 1545 | +LWIN 133 XK_Super_L |
| 1546 | niri test-action |
| 1547 | surface modifiers: depressed=64, latched=0, locked=0, group=0 |
| 1548 | -LWIN 133 XK_Super_L |
| 1549 | surface modifiers: depressed=0, latched=0, locked=0, group=0 |
| 1550 | "); |
| 1551 | |
| 1552 | let bind_by_generic = " |
| 1553 | binds { |
| 1554 | Mod+Super { close-window; } |
| 1555 | } |
| 1556 | "; |
| 1557 | |
| 1558 | assert_snapshot!(run(bind_by_generic, "+LWIN -LWIN"), @" |
| 1559 | +LWIN 133 XK_Super_L |
| 1560 | niri test-action |
| 1561 | surface modifiers: depressed=64, latched=0, locked=0, group=0 |
| 1562 | -LWIN 133 XK_Super_L |
| 1563 | surface modifiers: depressed=0, latched=0, locked=0, group=0 |
| 1564 | "); |
| 1565 | } |
| 1566 | |
| 1567 | #[test] |
| 1568 | fn release_bind_requires_matching_modifiers_on_press() { |
| 1569 | let c = " |
| 1570 | binds { |
| 1571 | Mod+Ctrl+Q { |
| 1572 | release { close-window; } |
| 1573 | } |
| 1574 | } |
| 1575 | "; |
| 1576 | |
| 1577 | // Pressing Q without the mod key held forwards it and doesn't arm the release action, even if |
| 1578 | // the mod key is held by the time Q is released. |
| 1579 | assert_snapshot!(run(c, "+LCTL +LatQ +LWIN -LatQ -LWIN -LCTL"), @" |
| 1580 | +LCTL 37 XK_Control_L |
| 1581 | surface key pressed: 29 |
| 1582 | surface modifiers: depressed=4, latched=0, locked=0, group=0 |
| 1583 | +AD01 24 XK_q |
| 1584 | surface key pressed: 16 |
| 1585 | +LWIN 133 XK_Super_L |
| 1586 | surface key pressed: 125 |
| 1587 | surface modifiers: depressed=68, latched=0, locked=0, group=0 |
| 1588 | -AD01 24 XK_q |
| 1589 | surface key released: 16 |
| 1590 | -LWIN 133 XK_Super_L |
| 1591 | surface key released: 125 |
| 1592 | surface modifiers: depressed=4, latched=0, locked=0, group=0 |
| 1593 | -LCTL 37 XK_Control_L |
| 1594 | surface key released: 29 |
| 1595 | surface modifiers: depressed=0, latched=0, locked=0, group=0 |
| 1596 | "); |
| 1597 | } |
| 1598 | |
| 1599 | /// `Mod` and `Mod+Q` release-only binds, used by the inhibitor tests below. |
| 1600 | const INHIBITING_BINDS: &str = " |
| 1601 | binds { |
| 1602 | Mod { |
| 1603 | release { toggle-overview; } |
| 1604 | } |
| 1605 | Mod+Q { |
| 1606 | release { close-window; } |
| 1607 | } |
| 1608 | } |
| 1609 | "; |
| 1610 | |
| 1611 | #[test] |
| 1612 | fn inhibiting_release_binds() { |
| 1613 | let (mut f, id, surface) = set_up(INHIBITING_BINDS); |
| 1614 | let _inhibitor = f.client(id).state.inhibit_shortcuts(&surface); |
| 1615 | f.roundtrip(id); |
| 1616 | |
| 1617 | // While inhibiting, release binds don't run, and the whole key is forwarded to the window. |
| 1618 | assert_snapshot!(run_f(&mut f, id, &surface, "+LWIN +LatQ -LatQ -LWIN"), @" |
| 1619 | +LWIN 133 XK_Super_L |
| 1620 | surface key pressed: 125 |
| 1621 | surface modifiers: depressed=64, latched=0, locked=0, group=0 |
| 1622 | +AD01 24 XK_q |
| 1623 | surface key pressed: 16 |
| 1624 | -AD01 24 XK_q |
| 1625 | surface key released: 16 |
| 1626 | -LWIN 133 XK_Super_L |
| 1627 | surface key released: 125 |
| 1628 | surface modifiers: depressed=0, latched=0, locked=0, group=0 |
| 1629 | "); |
| 1630 | } |
| 1631 | |
| 1632 | #[test] |
| 1633 | fn release_binds_run_after_the_inhibitor_is_gone() { |
| 1634 | let (mut f, id, surface) = set_up(INHIBITING_BINDS); |
| 1635 | let inhibitor = f.client(id).state.inhibit_shortcuts(&surface); |
| 1636 | f.roundtrip(id); |
| 1637 | inhibitor.destroy(); |
| 1638 | f.roundtrip(id); |
| 1639 | |
| 1640 | assert_snapshot!(run_f(&mut f, id, &surface, "+LWIN +LatQ -LatQ -LWIN"), @" |
| 1641 | +LWIN 133 XK_Super_L |
| 1642 | surface key pressed: 125 |
| 1643 | surface modifiers: depressed=64, latched=0, locked=0, group=0 |
| 1644 | +AD01 24 XK_q |
| 1645 | -AD01 24 XK_q |
| 1646 | niri test-action |
| 1647 | -LWIN 133 XK_Super_L |
| 1648 | surface key released: 125 |
| 1649 | surface modifiers: depressed=0, latched=0, locked=0, group=0 |
| 1650 | "); |
| 1651 | } |
| 1652 | |
| 1653 | #[test] |
| 1654 | fn deactivating_the_inhibitor_does_not_arm_a_release_bind_retroactively() { |
| 1655 | let (mut f, id, surface) = set_up(INHIBITING_BINDS); |
| 1656 | let inhibitor = f.client(id).state.inhibit_shortcuts(&surface); |
| 1657 | f.roundtrip(id); |
| 1658 | |
| 1659 | // The press while inhibiting is forwarded and arms nothing. |
| 1660 | run_f(&mut f, id, &surface, "+LWIN +LatQ"); |
| 1661 | |
| 1662 | inhibitor.destroy(); |
| 1663 | f.roundtrip(id); |
| 1664 | |
| 1665 | // The release is still forwarded, and still runs no action. |
| 1666 | assert_snapshot!(run_f(&mut f, id, &surface, "-LatQ -LWIN"), @" |
| 1667 | -AD01 24 XK_q |
| 1668 | surface key released: 16 |
| 1669 | -LWIN 133 XK_Super_L |
| 1670 | surface key released: 125 |
| 1671 | surface modifiers: depressed=0, latched=0, locked=0, group=0 |
| 1672 | "); |
| 1673 | } |
| 1674 | |
| 1675 | #[test] |
| 1676 | fn activating_the_inhibitor_keeps_an_armed_release_bind() { |
| 1677 | let (mut f, id, surface) = set_up(INHIBITING_BINDS); |
| 1678 | |
| 1679 | // The press while not inhibiting is intercepted and arms the release action. |
| 1680 | run_f(&mut f, id, &surface, "+LWIN +LatQ"); |
| 1681 | |
| 1682 | let _inhibitor = f.client(id).state.inhibit_shortcuts(&surface); |
| 1683 | f.roundtrip(id); |
| 1684 | |
| 1685 | // The release stays intercepted, and still runs the armed release action. |
| 1686 | assert_snapshot!(run_f(&mut f, id, &surface, "-LatQ -LWIN"), @" |
| 1687 | -AD01 24 XK_q |
| 1688 | niri test-action |
| 1689 | -LWIN 133 XK_Super_L |
| 1690 | surface key released: 125 |
| 1691 | surface modifiers: depressed=0, latched=0, locked=0, group=0 |
| 1692 | "); |
| 1693 | } |
| 1694 | |
| 1695 | #[test] |
| 1696 | fn inhibiting_a_modifier_press_still_forwards_it() { |
| 1697 | let (mut f, id, surface) = set_up(INHIBITING_BINDS); |
| 1698 | let _inhibitor = f.client(id).state.inhibit_shortcuts(&surface); |
| 1699 | f.roundtrip(id); |
| 1700 | |
| 1701 | // A modifier press is forwarded either way; the inhibitor only decides whether it arms the |
| 1702 | // release action, and here it doesn't. |
| 1703 | assert_snapshot!(run_f(&mut f, id, &surface, "+LWIN"), @" |
| 1704 | +LWIN 133 XK_Super_L |
| 1705 | surface key pressed: 125 |
| 1706 | surface modifiers: depressed=64, latched=0, locked=0, group=0 |
| 1707 | "); |
| 1708 | } |
| 1709 | |
| 1710 | #[test] |
| 1711 | fn armed_modifier_release_runs_after_the_inhibitor_activates() { |
| 1712 | let (mut f, id, surface) = set_up(INHIBITING_BINDS); |
| 1713 | |
| 1714 | // The modifier press while not inhibiting arms its release action. |
| 1715 | run_f(&mut f, id, &surface, "+LWIN"); |
| 1716 | |
| 1717 | let _inhibitor = f.client(id).state.inhibit_shortcuts(&surface); |
| 1718 | f.roundtrip(id); |
| 1719 | |
| 1720 | assert_snapshot!(run_f(&mut f, id, &surface, "-LWIN"), @" |
| 1721 | -LWIN 133 XK_Super_L |
| 1722 | niri test-action |
| 1723 | surface key released: 125 |
| 1724 | surface modifiers: depressed=0, latched=0, locked=0, group=0 |
| 1725 | "); |
| 1726 | } |
| 1727 | |
| 1728 | #[test] |
| 1729 | fn egl_release_action_runs_when_press_opens_screenshot_ui() { |
| 1730 | // Release actions must always run if their press action ran, |
| 1731 | // including if the screenshot UI is opened before the key is released. |
| 1732 | let c = " |
| 1733 | binds { |
| 1734 | Mod+Q { |
| 1735 | press { screenshot; } |
| 1736 | release { close-window; } |
| 1737 | } |
| 1738 | } |
| 1739 | "; |
| 1740 | |
| 1741 | let (mut f, id, surface) = set_up(c); |
| 1742 | f.niri_state().backend.headless().add_renderer().unwrap(); |
| 1743 | |
| 1744 | assert_snapshot!(run_f(&mut f, id, &surface, "+LWIN +LatQ -LatQ -LWIN"), @" |
| 1745 | +LWIN 133 XK_Super_L |
| 1746 | surface key pressed: 125 |
| 1747 | surface modifiers: depressed=64, latched=0, locked=0, group=0 |
| 1748 | +AD01 24 XK_q |
| 1749 | surface leave |
| 1750 | -AD01 24 XK_q |
| 1751 | niri test-action |
| 1752 | -LWIN 133 XK_Super_L |
| 1753 | "); |
| 1754 | assert!(f.niri().screenshot_ui.is_open()); |
| 1755 | } |
| 1756 | |
| 1757 | #[test] |
| 1758 | fn cooldown_skips_whole_bind() { |
| 1759 | // A bind on cooldown is skipped entirely: its press runs no action, and no release action is |
| 1760 | // recorded, so its release runs no action either. |
| 1761 | let c = " |
| 1762 | binds { |
| 1763 | Mod+MouseLeft cooldown-ms=1000 { |
| 1764 | press { close-window; } |
| 1765 | release { center-column; } |
| 1766 | } |
| 1767 | } |
| 1768 | "; |
| 1769 | |
| 1770 | assert_snapshot!(run(c, "+LWIN +MouseLeft -MouseLeft +MouseLeft -MouseLeft -LWIN"), @" |
| 1771 | +LWIN 133 XK_Super_L |
| 1772 | surface key pressed: 125 |
| 1773 | surface modifiers: depressed=64, latched=0, locked=0, group=0 |
| 1774 | +MouseLeft |
| 1775 | niri test-action |
| 1776 | -MouseLeft |
| 1777 | niri test-action |
| 1778 | +MouseLeft |
| 1779 | -MouseLeft |
| 1780 | -LWIN 133 XK_Super_L |
| 1781 | surface key released: 125 |
| 1782 | surface modifiers: depressed=0, latched=0, locked=0, group=0 |
| 1783 | "); |
| 1784 | } |
| 1785 | |
| 1786 | #[test] |
| 1787 | fn cooldown_only_skips_the_action() { |
| 1788 | let c = " |
| 1789 | binds { |
| 1790 | Mod+Control_L cooldown-ms=1000 { close-window; } |
| 1791 | } |
| 1792 | "; |
| 1793 | |
| 1794 | // The cooldown only skips the action: the second press runs no action, but it is still |
| 1795 | // intercepted and hidden from the window, only advertising the modifier state. |
| 1796 | assert_snapshot!(run(c, "+LWIN +LCTL -LCTL +LCTL"), @" |
| 1797 | +LWIN 133 XK_Super_L |
| 1798 | surface key pressed: 125 |
| 1799 | surface modifiers: depressed=64, latched=0, locked=0, group=0 |
| 1800 | +LCTL 37 XK_Control_L |
| 1801 | niri test-action |
| 1802 | surface modifiers: depressed=68, latched=0, locked=0, group=0 |
| 1803 | -LCTL 37 XK_Control_L |
| 1804 | surface modifiers: depressed=64, latched=0, locked=0, group=0 |
| 1805 | +LCTL 37 XK_Control_L |
| 1806 | surface modifiers: depressed=68, latched=0, locked=0, group=0 |
| 1807 | "); |
| 1808 | } |
| 1809 | |
| 1810 | #[test] |
| 1811 | fn cooldown_applies_to_release_action_of_release_only_bind() { |
| 1812 | // The release action is what starts this bind, so the cooldown rate-limits it: it runs for the |
| 1813 | // first release, and not for the second while the bind is on cooldown. |
| 1814 | let c = " |
| 1815 | binds { |
| 1816 | Mod cooldown-ms=1000 { |
| 1817 | release { toggle-overview; } |
| 1818 | } |
| 1819 | } |
| 1820 | "; |
| 1821 | |
| 1822 | assert_snapshot!(run(c, "+LWIN -LWIN +LWIN -LWIN"), @" |
| 1823 | +LWIN 133 XK_Super_L |
| 1824 | surface key pressed: 125 |
| 1825 | surface modifiers: depressed=64, latched=0, locked=0, group=0 |
| 1826 | -LWIN 133 XK_Super_L |
| 1827 | niri test-action |
| 1828 | surface key released: 125 |
| 1829 | surface modifiers: depressed=0, latched=0, locked=0, group=0 |
| 1830 | +LWIN 133 XK_Super_L |
| 1831 | surface key pressed: 125 |
| 1832 | surface modifiers: depressed=64, latched=0, locked=0, group=0 |
| 1833 | -LWIN 133 XK_Super_L |
| 1834 | surface key released: 125 |
| 1835 | surface modifiers: depressed=0, latched=0, locked=0, group=0 |
| 1836 | "); |
| 1837 | } |
| 1838 | |
| 1839 | #[test] |
| 1840 | fn cooldown_applies_to_press_action_only() { |
| 1841 | // The cooldown applies to the press action only, and the release action runs only if its press |
| 1842 | // action ran, so the second press runs no action at all. |
| 1843 | let c = " |
| 1844 | binds { |
| 1845 | Mod+Q cooldown-ms=1000 { |
| 1846 | press { close-window; } |
| 1847 | release { center-column; } |
| 1848 | } |
| 1849 | } |
| 1850 | "; |
| 1851 | |
| 1852 | assert_snapshot!(run(c, "+LWIN +LatQ -LatQ +LatQ -LatQ -LWIN"), @" |
| 1853 | +LWIN 133 XK_Super_L |
| 1854 | surface key pressed: 125 |
| 1855 | surface modifiers: depressed=64, latched=0, locked=0, group=0 |
| 1856 | +AD01 24 XK_q |
| 1857 | niri test-action |
| 1858 | -AD01 24 XK_q |
| 1859 | niri test-action |
| 1860 | +AD01 24 XK_q |
| 1861 | -AD01 24 XK_q |
| 1862 | -LWIN 133 XK_Super_L |
| 1863 | surface key released: 125 |
| 1864 | surface modifiers: depressed=0, latched=0, locked=0, group=0 |
| 1865 | "); |
| 1866 | } |
| 1867 | |
| 1868 | #[test] |
| 1869 | fn release_bind_runs_when_mru_closes() { |
| 1870 | // `Alt` is a push-to-talk bind: the default Alt+Tab opens the MRU, and releasing Alt closes it |
| 1871 | // instead of going through the regular bind lookup, so its release action must still run. |
| 1872 | let c = " |
| 1873 | binds { |
| 1874 | Alt { |
| 1875 | press { spawn \"ptt-toggle\"; } |
| 1876 | release { spawn \"ptt-toggle\"; } |
| 1877 | } |
| 1878 | } |
| 1879 | "; |
| 1880 | |
| 1881 | assert_snapshot!(run(c, "+LALT +TAB -LALT"), @" |
| 1882 | +LALT 64 XK_Alt_L |
| 1883 | niri test-action |
| 1884 | surface modifiers: depressed=8, latched=0, locked=0, group=0 |
| 1885 | +TAB 23 XK_Tab |
| 1886 | surface leave |
| 1887 | -LALT 64 XK_Alt_L |
| 1888 | niri test-action |
| 1889 | surface enter: [] |
| 1890 | surface modifiers: depressed=0, latched=0, locked=0, group=0 |
| 1891 | surface modifiers: depressed=0, latched=0, locked=0, group=0 |
| 1892 | "); |
| 1893 | } |
| 1894 | |
| 1895 | #[test] |
| 1896 | fn mru_close_forwards_key_release_without_bind() { |
| 1897 | // No bind is recorded for Alt, so releasing it while the MRU is open closes the MRU and the |
| 1898 | // release is forwarded to the window like any other unsuppressed key. |
| 1899 | let c = " |
| 1900 | binds { |
| 1901 | Mod+Q { close-window; } |
| 1902 | } |
| 1903 | "; |
| 1904 | |
| 1905 | assert_snapshot!(run(c, "+LALT +TAB -LALT"), @" |
| 1906 | +LALT 64 XK_Alt_L |
| 1907 | surface key pressed: 56 |
| 1908 | surface modifiers: depressed=8, latched=0, locked=0, group=0 |
| 1909 | +TAB 23 XK_Tab |
| 1910 | surface leave |
| 1911 | -LALT 64 XK_Alt_L |
| 1912 | surface enter: [56] |
| 1913 | surface modifiers: depressed=0, latched=0, locked=0, group=0 |
| 1914 | surface key released: 56 |
| 1915 | surface modifiers: depressed=0, latched=0, locked=0, group=0 |
| 1916 | "); |
| 1917 | } |
| 1918 | |
| 1919 | #[test] |
| 1920 | fn mru_ignores_generic_modifier_binds() { |
| 1921 | let c = " |
| 1922 | binds { |
| 1923 | Alt+Ctrl { screenshot; } |
| 1924 | } |
| 1925 | "; |
| 1926 | |
| 1927 | // If a press runs the screenshot action, |
| 1928 | // we will get surface enter after it. |
| 1929 | assert_snapshot!(run(c, "+LALT +TAB -TAB +LFSH -LFSH -LALT"), @" |
| 1930 | +LALT 64 XK_Alt_L |
| 1931 | surface key pressed: 56 |
| 1932 | surface modifiers: depressed=8, latched=0, locked=0, group=0 |
| 1933 | +TAB 23 XK_Tab |
| 1934 | surface leave |
| 1935 | -TAB 23 XK_Tab |
| 1936 | +LFSH 50 XK_Shift_L |
| 1937 | -LFSH 50 XK_Shift_L |
| 1938 | -LALT 64 XK_Alt_L |
| 1939 | surface enter: [56] |
| 1940 | surface modifiers: depressed=0, latched=0, locked=0, group=0 |
| 1941 | surface key released: 56 |
| 1942 | surface modifiers: depressed=0, latched=0, locked=0, group=0 |
| 1943 | "); |
| 1944 | |
| 1945 | assert_snapshot!(run(c, "+LALT +TAB -TAB +LCTL -LCTL -LALT"), @" |
| 1946 | +LALT 64 XK_Alt_L |
| 1947 | surface key pressed: 56 |
| 1948 | surface modifiers: depressed=8, latched=0, locked=0, group=0 |
| 1949 | +TAB 23 XK_Tab |
| 1950 | surface leave |
| 1951 | -TAB 23 XK_Tab |
| 1952 | +LCTL 37 XK_Control_L |
| 1953 | -LCTL 37 XK_Control_L |
| 1954 | -LALT 64 XK_Alt_L |
| 1955 | surface enter: [56] |
| 1956 | surface modifiers: depressed=0, latched=0, locked=0, group=0 |
| 1957 | surface key released: 56 |
| 1958 | surface modifiers: depressed=0, latched=0, locked=0, group=0 |
| 1959 | "); |
| 1960 | |
| 1961 | let c = " |
| 1962 | binds { |
| 1963 | Ctrl+Shift { screenshot; } |
| 1964 | } |
| 1965 | "; |
| 1966 | |
| 1967 | assert_snapshot!(run(c, "+LALT +TAB -TAB +LFSH -LFSH -LALT"), @" |
| 1968 | +LALT 64 XK_Alt_L |
| 1969 | surface key pressed: 56 |
| 1970 | surface modifiers: depressed=8, latched=0, locked=0, group=0 |
| 1971 | +TAB 23 XK_Tab |
| 1972 | surface leave |
| 1973 | -TAB 23 XK_Tab |
| 1974 | +LFSH 50 XK_Shift_L |
| 1975 | -LFSH 50 XK_Shift_L |
| 1976 | -LALT 64 XK_Alt_L |
| 1977 | surface enter: [56] |
| 1978 | surface modifiers: depressed=0, latched=0, locked=0, group=0 |
| 1979 | surface key released: 56 |
| 1980 | surface modifiers: depressed=0, latched=0, locked=0, group=0 |
| 1981 | "); |
| 1982 | |
| 1983 | assert_snapshot!(run(c, "+LALT +TAB -TAB +LCTL +LFSH -LFSH -LCTL -LALT"), @" |
| 1984 | +LALT 64 XK_Alt_L |
| 1985 | surface key pressed: 56 |
| 1986 | surface modifiers: depressed=8, latched=0, locked=0, group=0 |
| 1987 | +TAB 23 XK_Tab |
| 1988 | surface leave |
| 1989 | -TAB 23 XK_Tab |
| 1990 | +LCTL 37 XK_Control_L |
| 1991 | +LFSH 50 XK_Shift_L |
| 1992 | -LFSH 50 XK_Shift_L |
| 1993 | -LCTL 37 XK_Control_L |
| 1994 | -LALT 64 XK_Alt_L |
| 1995 | surface enter: [56] |
| 1996 | surface modifiers: depressed=0, latched=0, locked=0, group=0 |
| 1997 | surface key released: 56 |
| 1998 | surface modifiers: depressed=0, latched=0, locked=0, group=0 |
| 1999 | "); |
| 2000 | |
| 2001 | // Now with a normal trigger. |
| 2002 | let c = " |
| 2003 | binds { |
| 2004 | Alt+Control_L { screenshot; } |
| 2005 | } |
| 2006 | "; |
| 2007 | |
| 2008 | assert_snapshot!(run(c, "+LALT +TAB -TAB +LFSH -LFSH -LALT"), @" |
| 2009 | +LALT 64 XK_Alt_L |
| 2010 | surface key pressed: 56 |
| 2011 | surface modifiers: depressed=8, latched=0, locked=0, group=0 |
| 2012 | +TAB 23 XK_Tab |
| 2013 | surface leave |
| 2014 | -TAB 23 XK_Tab |
| 2015 | +LFSH 50 XK_Shift_L |
| 2016 | -LFSH 50 XK_Shift_L |
| 2017 | -LALT 64 XK_Alt_L |
| 2018 | surface enter: [56] |
| 2019 | surface modifiers: depressed=0, latched=0, locked=0, group=0 |
| 2020 | surface key released: 56 |
| 2021 | surface modifiers: depressed=0, latched=0, locked=0, group=0 |
| 2022 | "); |
| 2023 | |
| 2024 | assert_snapshot!(run(c, "+LALT +TAB -TAB +LCTL -LCTL -LALT"), @" |
| 2025 | +LALT 64 XK_Alt_L |
| 2026 | surface key pressed: 56 |
| 2027 | surface modifiers: depressed=8, latched=0, locked=0, group=0 |
| 2028 | +TAB 23 XK_Tab |
| 2029 | surface leave |
| 2030 | -TAB 23 XK_Tab |
| 2031 | +LCTL 37 XK_Control_L |
| 2032 | surface enter: [56] |
| 2033 | surface modifiers: depressed=12, latched=0, locked=0, group=0 |
| 2034 | -LCTL 37 XK_Control_L |
| 2035 | surface modifiers: depressed=8, latched=0, locked=0, group=0 |
| 2036 | -LALT 64 XK_Alt_L |
| 2037 | surface key released: 56 |
| 2038 | surface modifiers: depressed=0, latched=0, locked=0, group=0 |
| 2039 | "); |
| 2040 | |
| 2041 | let c = " |
| 2042 | binds { |
| 2043 | Ctrl+Shift_L { screenshot; } |
| 2044 | } |
| 2045 | "; |
| 2046 | |
| 2047 | assert_snapshot!(run(c, "+LALT +TAB -TAB +LFSH -LFSH -LALT"), @" |
| 2048 | +LALT 64 XK_Alt_L |
| 2049 | surface key pressed: 56 |
| 2050 | surface modifiers: depressed=8, latched=0, locked=0, group=0 |
| 2051 | +TAB 23 XK_Tab |
| 2052 | surface leave |
| 2053 | -TAB 23 XK_Tab |
| 2054 | +LFSH 50 XK_Shift_L |
| 2055 | surface enter: [56] |
| 2056 | surface modifiers: depressed=9, latched=0, locked=0, group=0 |
| 2057 | -LFSH 50 XK_Shift_L |
| 2058 | surface modifiers: depressed=8, latched=0, locked=0, group=0 |
| 2059 | -LALT 64 XK_Alt_L |
| 2060 | surface key released: 56 |
| 2061 | surface modifiers: depressed=0, latched=0, locked=0, group=0 |
| 2062 | "); |
| 2063 | |
| 2064 | assert_snapshot!(run(c, "+LALT +TAB -TAB +LCTL +LFSH -LFSH -LCTL -LALT"), @" |
| 2065 | +LALT 64 XK_Alt_L |
| 2066 | surface key pressed: 56 |
| 2067 | surface modifiers: depressed=8, latched=0, locked=0, group=0 |
| 2068 | +TAB 23 XK_Tab |
| 2069 | surface leave |
| 2070 | -TAB 23 XK_Tab |
| 2071 | +LCTL 37 XK_Control_L |
| 2072 | +LFSH 50 XK_Shift_L |
| 2073 | surface enter: [29, 56] |
| 2074 | surface modifiers: depressed=13, latched=0, locked=0, group=0 |
| 2075 | -LFSH 50 XK_Shift_L |
| 2076 | surface modifiers: depressed=12, latched=0, locked=0, group=0 |
| 2077 | -LCTL 37 XK_Control_L |
| 2078 | surface key released: 29 |
| 2079 | surface modifiers: depressed=8, latched=0, locked=0, group=0 |
| 2080 | -LALT 64 XK_Alt_L |
| 2081 | surface key released: 56 |
| 2082 | surface modifiers: depressed=0, latched=0, locked=0, group=0 |
| 2083 | "); |
| 2084 | } |
| 2085 | |
| 2086 | #[test] |
| 2087 | fn vt_switch_runs_release_actions_of_held_binds() { |
| 2088 | // A VT switch can take the input away without ever delivering the releases of everything held |
| 2089 | // down, so the held binds are treated as released rather than forgotten. |
| 2090 | let c = " |
| 2091 | binds { |
| 2092 | Mod+Q { |
| 2093 | press { close-window; } |
| 2094 | release { center-column; } |
| 2095 | } |
| 2096 | Mod+MouseLeft { |
| 2097 | press { close-window; } |
| 2098 | release { center-column; } |
| 2099 | } |
| 2100 | } |
| 2101 | "; |
| 2102 | |
| 2103 | let (mut f, id, surface) = set_up(c); |
| 2104 | |
| 2105 | // Hold a key and a mouse button, both with press and release actions. |
| 2106 | run_f(&mut f, id, &surface, "+LWIN +LatQ +MouseLeft"); |
| 2107 | assert_eq!(f.niri().test_action_count, 2); |
| 2108 | |
| 2109 | // The VT switch runs both release actions. |
| 2110 | f.niri_state().do_action(Action::ChangeVt(1), false); |
| 2111 | assert_eq!(f.niri().test_action_count, 4); |
| 2112 | |
| 2113 | // If the releases arrive anyway, they run nothing. |
| 2114 | run_f(&mut f, id, &surface, "-LatQ -MouseLeft"); |
| 2115 | assert_eq!(f.niri().test_action_count, 4); |
| 2116 | } |
| 2117 | |
| 2118 | #[test] |
| 2119 | fn other_input_cancels_release_only_mouse_bind() { |
| 2120 | // A release-only mouse bind is cancelled by other input in between, just like a release-only |
| 2121 | // keyboard bind. |
| 2122 | let c = " |
| 2123 | binds { |
| 2124 | Mod+MouseLeft { |
| 2125 | release { close-window; } |
| 2126 | } |
| 2127 | } |
| 2128 | "; |
| 2129 | |
| 2130 | // Pressing a key in between cancels it. |
| 2131 | assert_snapshot!(run(c, "+LWIN +MouseLeft +LatA -LatA -MouseLeft -LWIN"), @" |
| 2132 | +LWIN 133 XK_Super_L |
| 2133 | surface key pressed: 125 |
| 2134 | surface modifiers: depressed=64, latched=0, locked=0, group=0 |
| 2135 | +MouseLeft |
| 2136 | +AC01 38 XK_a |
| 2137 | surface key pressed: 30 |
| 2138 | -AC01 38 XK_a |
| 2139 | surface key released: 30 |
| 2140 | -MouseLeft |
| 2141 | -LWIN 133 XK_Super_L |
| 2142 | surface key released: 125 |
| 2143 | surface modifiers: depressed=0, latched=0, locked=0, group=0 |
| 2144 | "); |
| 2145 | |
| 2146 | // Pressing another mouse button in between cancels it. |
| 2147 | assert_snapshot!(run(c, "+LWIN +MouseLeft +MouseRight -MouseRight -MouseLeft -LWIN"), @" |
| 2148 | +LWIN 133 XK_Super_L |
| 2149 | surface key pressed: 125 |
| 2150 | surface modifiers: depressed=64, latched=0, locked=0, group=0 |
| 2151 | +MouseLeft |
| 2152 | +MouseRight |
| 2153 | -MouseRight |
| 2154 | -MouseLeft |
| 2155 | -LWIN 133 XK_Super_L |
| 2156 | surface key released: 125 |
| 2157 | surface modifiers: depressed=0, latched=0, locked=0, group=0 |
| 2158 | "); |
| 2159 | |
| 2160 | // With nothing else in between, the release action runs. |
| 2161 | assert_snapshot!(run(c, "+LWIN +MouseLeft -MouseLeft -LWIN"), @" |
| 2162 | +LWIN 133 XK_Super_L |
| 2163 | surface key pressed: 125 |
| 2164 | surface modifiers: depressed=64, latched=0, locked=0, group=0 |
| 2165 | +MouseLeft |
| 2166 | -MouseLeft |
| 2167 | niri test-action |
| 2168 | -LWIN 133 XK_Super_L |
| 2169 | surface key released: 125 |
| 2170 | surface modifiers: depressed=0, latched=0, locked=0, group=0 |
| 2171 | "); |
| 2172 | } |
| 2173 | |
| 2174 | #[test] |
| 2175 | fn mouse_button_press_cancels_release_only_key_bind() { |
| 2176 | // A mouse button press is other input, so it interrupts a pending release-only keyboard bind, |
| 2177 | // including one on a bare modifier. Only the mouse bind's press action runs. |
| 2178 | let c = " |
| 2179 | binds { |
| 2180 | Mod { |
| 2181 | release { center-column; } |
| 2182 | } |
| 2183 | Mod+MouseLeft { close-window; } |
| 2184 | } |
| 2185 | "; |
| 2186 | |
| 2187 | assert_snapshot!(run(c, "+LWIN +MouseLeft -MouseLeft -LWIN"), @" |
| 2188 | +LWIN 133 XK_Super_L |
| 2189 | surface key pressed: 125 |
| 2190 | surface modifiers: depressed=64, latched=0, locked=0, group=0 |
| 2191 | +MouseLeft |
| 2192 | niri test-action |
| 2193 | -MouseLeft |
| 2194 | -LWIN 133 XK_Super_L |
| 2195 | surface key released: 125 |
| 2196 | surface modifiers: depressed=0, latched=0, locked=0, group=0 |
| 2197 | "); |
| 2198 | } |
| 2199 | |
| 2200 | #[test] |
| 2201 | fn scroll_cancels_release_only_key_bind() { |
| 2202 | // Scrolling is input, so it cancels a pending release-only bind. Here there is no scroll bind |
| 2203 | // for the held modifiers. |
| 2204 | let c = " |
| 2205 | binds { |
| 2206 | Mod { |
| 2207 | release { center-column; } |
| 2208 | } |
| 2209 | } |
| 2210 | "; |
| 2211 | |
| 2212 | // The scroll in between cancels the pending release bind, so the release runs no action. |
| 2213 | assert_snapshot!(run(c, "+LWIN WheelScrollDown -LWIN"), @" |
| 2214 | +LWIN 133 XK_Super_L |
| 2215 | surface key pressed: 125 |
| 2216 | surface modifiers: depressed=64, latched=0, locked=0, group=0 |
| 2217 | WheelScrollDown |
| 2218 | -LWIN 133 XK_Super_L |
| 2219 | surface key released: 125 |
| 2220 | surface modifiers: depressed=0, latched=0, locked=0, group=0 |
| 2221 | "); |
| 2222 | |
| 2223 | // Without a scroll in between, the release action runs. |
| 2224 | assert_snapshot!(run(c, "+LWIN -LWIN"), @" |
| 2225 | +LWIN 133 XK_Super_L |
| 2226 | surface key pressed: 125 |
| 2227 | surface modifiers: depressed=64, latched=0, locked=0, group=0 |
| 2228 | -LWIN 133 XK_Super_L |
| 2229 | niri test-action |
| 2230 | surface key released: 125 |
| 2231 | surface modifiers: depressed=0, latched=0, locked=0, group=0 |
| 2232 | "); |
| 2233 | } |
| 2234 | |
| 2235 | #[test] |
| 2236 | fn redundant_modifier_binds() { |
| 2237 | // Binds should behave identically with or without redundant modifiers. |
| 2238 | let input = "+LALT -LALT"; |
| 2239 | assert_eq!( |
| 2240 | run("binds { Alt_L { release { close-window; }; }; }", input), |
| 2241 | run("binds { Alt+Alt_L { release { close-window; }; }; }", input) |
| 2242 | ); |
| 2243 | |
| 2244 | let input = "+LALT +LatQ -LatQ -LALT"; |
| 2245 | assert_eq!( |
| 2246 | run("binds { Alt+Q { release { close-window; }; }; }", input), |
| 2247 | run("binds { Alt+Alt+Q { release { close-window; }; }; }", input) |
| 2248 | ); |
| 2249 | } |