From 38683f069a039f9da6d7ddc64167850560fd07ed Mon Sep 17 00:00:00 2001 From: srdusr <99972264+srdusr@users.noreply.github.com> Date: Tue, 30 Jul 2024 22:10:00 +0200 Subject: Split crates/wayland/src/state.rs (1276 lines) into state/ Pure reorganization, no behavior change - verified by diffing the function-name and struct-name sets before/after (both identical) plus a full cargo test pass. mod.rs keeps ClientState/OutputEntry/CompState/ WindowAnim/RepeatState's definitions, the key-repeat impl, and the output-lookup impl (all small and tightly coupled to the type definitions), plus mod declarations. The one large impl CompState block (previously ~600 lines) splits by concern: - lifecycle.rs: new_managed_window, set_decorated_from_mode, redraw_decoration_buffer, remove_window. - layers.rs: ensure_layer_initial_configure. - focus.rs: set_keyboard_focus, set_window_activated. - menu.rs: open/close/run_context_menu_action, is_double_click. - geometry.rs: raise_pinned, sync_geometry. - tick.rs: tick_dirty_broadcasts, tick_animations, resync_stacking_order. - toplevel.rs: the with_toplevel_title/app_id/sync_toplevel_metadata free functions. - tests.rs: unsplit, same reasoning as every other split this pass. CompState's fields were already pub(crate) (this crate's existing convention, unlike core's/config's plain-private), so no field- visibility changes were needed - only resync_stacking_order (called from geometry.rs, defined in tick.rs) needed bumping from private to pub(crate), matching that same convention. --- crates/wayland/src/state/tests.rs | 58 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 crates/wayland/src/state/tests.rs (limited to 'crates/wayland/src/state/tests.rs') diff --git a/crates/wayland/src/state/tests.rs b/crates/wayland/src/state/tests.rs new file mode 100644 index 0000000..bccbae2 --- /dev/null +++ b/crates/wayland/src/state/tests.rs @@ -0,0 +1,58 @@ + use super::*; + + #[test] + fn focused_window_keeps_its_configured_colour() { + assert_eq!(effective_border_color((136, 192, 208), true), (136, 192, 208)); + } + + #[test] + fn unfocused_window_is_dimmed_but_still_recognisably_that_colour() { + let dimmed = effective_border_color((136, 192, 208), false); + // Dimmer in every channel... + assert!(dimmed.0 < 136 && dimmed.1 < 192 && dimmed.2 < 208); + // ...but not black, and the channels' relative order is preserved + // (still "bluish", not just "gray") so a per-window colour set via + // a rule stays distinguishable from another window's even while + // unfocused. + assert!(dimmed.0 > 0 || dimmed.1 > 0 || dimmed.2 > 0); + assert!(dimmed.2 >= dimmed.1 && dimmed.1 >= dimmed.0); + } + + #[test] + fn window_anim_starts_at_from_and_ends_at_to() { + let anim = WindowAnim { + from: srdwm_core::Rect::new(0, 100, 300, 200), + to: srdwm_core::Rect::new(0, 0, 300, 200), + start: Instant::now(), + duration: Duration::from_millis(200), + }; + assert_eq!(anim.current_rect(), anim.from); + assert!(!anim.is_done()); + } + + #[test] + fn window_anim_is_done_and_settles_exactly_on_to_once_duration_elapses() { + let anim = WindowAnim { + from: srdwm_core::Rect::new(0, 100, 300, 200), + to: srdwm_core::Rect::new(50, 0, 600, 400), + start: Instant::now() - Duration::from_millis(500), + duration: Duration::from_millis(200), + }; + assert!(anim.is_done()); + assert_eq!(anim.current_rect(), anim.to); + } + + #[test] + fn window_anim_midway_is_strictly_between_from_and_to_on_every_axis() { + let anim = WindowAnim { + from: srdwm_core::Rect::new(0, 200, 200, 100), + to: srdwm_core::Rect::new(100, 0, 800, 600), + start: Instant::now() - Duration::from_millis(100), + duration: Duration::from_millis(200), + }; + let r = anim.current_rect(); + assert!(r.x > 0 && r.x < 100); + assert!(r.y > 0 && r.y < 200); + assert!(r.width > 200 && r.width < 800); + assert!(r.height > 100 && r.height < 600); + } -- cgit v1.2.3