layout: Round focus ring/border width to physical at the right place
Browse files at this commit0920ea9f9fdf0b744e79e8dea57d5945ba74f312Parent: 79e41d74 changed files +44 -18
- src/layout/mod.rs +1 -6
- src/layout/tests.rs +26 -6
- src/layout/tile.rs +16 -5
- src/window/mod.rs +1 -1
src/layout/mod.rsmodified+1 -6
| @@ -618,12 +618,7 @@ impl Options { | |||
| 618 | } | 618 | } |
| 619 | 619 | ||
| 620 | fn adjusted_for_scale(mut self, scale: f64) -> Self { | 620 | fn adjusted_for_scale(mut self, scale: f64) -> Self { |
| 621 | - let round = |logical: f64| round_logical_in_physical_max1(scale, logical); | 621 | + self.layout.gaps = round_logical_in_physical_max1(scale, self.layout.gaps); |
| 622 | - | ||
| 623 | - self.layout.gaps = round(self.layout.gaps); | ||
| 624 | - self.layout.focus_ring.width = round(self.layout.focus_ring.width); | ||
| 625 | - self.layout.border.width = round(self.layout.border.width); | ||
| 626 | - | ||
| 627 | self | 622 | self |
| 628 | } | 623 | } |
| 629 | } | 624 | } |
src/layout/tests.rsmodified+26 -6
| @@ -40,12 +40,13 @@ struct TestWindowInner { | |||
| 40 | is_pending_windowed_fullscreen: Cell<bool>, | 40 | is_pending_windowed_fullscreen: Cell<bool>, |
| 41 | animate_next_configure: Cell<bool>, | 41 | animate_next_configure: Cell<bool>, |
| 42 | animation_snapshot: RefCell<Option<LayoutElementRenderSnapshot>>, | 42 | animation_snapshot: RefCell<Option<LayoutElementRenderSnapshot>>, |
| 43 | + rules: ResolvedWindowRules, | ||
| 43 | } | 44 | } |
| 44 | 45 | ||
| 45 | #[derive(Debug, Clone)] | 46 | #[derive(Debug, Clone)] |
| 46 | struct TestWindow(Rc<TestWindowInner>); | 47 | struct TestWindow(Rc<TestWindowInner>); |
| 47 | 48 | ||
| 48 | -#[derive(Debug, Clone, Copy, Arbitrary)] | 49 | +#[derive(Debug, Clone, Arbitrary)] |
| 49 | struct TestWindowParams { | 50 | struct TestWindowParams { |
| 50 | #[proptest(strategy = "1..=5usize")] | 51 | #[proptest(strategy = "1..=5usize")] |
| 51 | id: usize, | 52 | id: usize, |
| @@ -56,6 +57,8 @@ struct TestWindowParams { | |||
| 56 | bbox: Rectangle<i32, Logical>, | 57 | bbox: Rectangle<i32, Logical>, |
| 57 | #[proptest(strategy = "arbitrary_min_max_size()")] | 58 | #[proptest(strategy = "arbitrary_min_max_size()")] |
| 58 | min_max_size: (Size<i32, Logical>, Size<i32, Logical>), | 59 | min_max_size: (Size<i32, Logical>, Size<i32, Logical>), |
| 60 | + #[proptest(strategy = "prop::option::of(arbitrary_rules())")] | ||
| 61 | + rules: Option<ResolvedWindowRules>, | ||
| 59 | } | 62 | } |
| 60 | 63 | ||
| 61 | impl TestWindowParams { | 64 | impl TestWindowParams { |
| @@ -66,6 +69,7 @@ impl TestWindowParams { | |||
| 66 | is_floating: false, | 69 | is_floating: false, |
| 67 | bbox: Rectangle::from_size(Size::from((100, 200))), | 70 | bbox: Rectangle::from_size(Size::from((100, 200))), |
| 68 | min_max_size: Default::default(), | 71 | min_max_size: Default::default(), |
| 72 | + rules: None, | ||
| 69 | } | 73 | } |
| 70 | } | 74 | } |
| 71 | } | 75 | } |
| @@ -88,6 +92,7 @@ impl TestWindow { | |||
| 88 | is_pending_windowed_fullscreen: Cell::new(false), | 92 | is_pending_windowed_fullscreen: Cell::new(false), |
| 89 | animate_next_configure: Cell::new(false), | 93 | animate_next_configure: Cell::new(false), |
| 90 | animation_snapshot: RefCell::new(None), | 94 | animation_snapshot: RefCell::new(None), |
| 95 | + rules: params.rules.unwrap_or(ResolvedWindowRules::empty()), | ||
| 91 | })) | 96 | })) |
| 92 | } | 97 | } |
| 93 | 98 | ||
| @@ -262,8 +267,7 @@ impl LayoutElement for TestWindow { | |||
| 262 | fn refresh(&self) {} | 267 | fn refresh(&self) {} |
| 263 | 268 | ||
| 264 | fn rules(&self) -> &ResolvedWindowRules { | 269 | fn rules(&self) -> &ResolvedWindowRules { |
| 265 | - static EMPTY: ResolvedWindowRules = ResolvedWindowRules::empty(); | 270 | + &self.0.rules |
| 266 | - &EMPTY | ||
| 267 | } | 271 | } |
| 268 | 272 | ||
| 269 | fn take_animation_snapshot(&mut self) -> Option<LayoutElementRenderSnapshot> { | 273 | fn take_animation_snapshot(&mut self) -> Option<LayoutElementRenderSnapshot> { |
| @@ -345,6 +349,19 @@ fn arbitrary_min_max_size() -> impl Strategy<Value = (Size<i32, Logical>, Size<i | |||
| 345 | ] | 349 | ] |
| 346 | } | 350 | } |
| 347 | 351 | ||
| 352 | +prop_compose! { | ||
| 353 | + fn arbitrary_rules()( | ||
| 354 | + focus_ring in arbitrary_focus_ring(), | ||
| 355 | + border in arbitrary_border(), | ||
| 356 | + ) -> ResolvedWindowRules { | ||
| 357 | + ResolvedWindowRules { | ||
| 358 | + focus_ring, | ||
| 359 | + border, | ||
| 360 | + ..ResolvedWindowRules::empty() | ||
| 361 | + } | ||
| 362 | + } | ||
| 363 | +} | ||
| 364 | + | ||
| 348 | fn arbitrary_view_offset_gesture_delta() -> impl Strategy<Value = f64> { | 365 | fn arbitrary_view_offset_gesture_delta() -> impl Strategy<Value = f64> { |
| 349 | prop_oneof![(-10f64..10f64), (-50000f64..50000f64),] | 366 | prop_oneof![(-10f64..10f64), (-50000f64..50000f64),] |
| 350 | } | 367 | } |
| @@ -891,6 +908,7 @@ impl Op { | |||
| 891 | } | 908 | } |
| 892 | } | 909 | } |
| 893 | 910 | ||
| 911 | + let is_floating = params.is_floating; | ||
| 894 | let win = TestWindow::new(params); | 912 | let win = TestWindow::new(params); |
| 895 | layout.add_window( | 913 | layout.add_window( |
| 896 | win, | 914 | win, |
| @@ -898,7 +916,7 @@ impl Op { | |||
| 898 | None, | 916 | None, |
| 899 | None, | 917 | None, |
| 900 | false, | 918 | false, |
| 901 | - params.is_floating, | 919 | + is_floating, |
| 902 | ActivateWindow::default(), | 920 | ActivateWindow::default(), |
| 903 | ); | 921 | ); |
| 904 | } | 922 | } |
| @@ -959,6 +977,7 @@ impl Op { | |||
| 959 | } | 977 | } |
| 960 | } | 978 | } |
| 961 | 979 | ||
| 980 | + let is_floating = params.is_floating; | ||
| 962 | let win = TestWindow::new(params); | 981 | let win = TestWindow::new(params); |
| 963 | layout.add_window( | 982 | layout.add_window( |
| 964 | win, | 983 | win, |
| @@ -966,7 +985,7 @@ impl Op { | |||
| 966 | None, | 985 | None, |
| 967 | None, | 986 | None, |
| 968 | false, | 987 | false, |
| 969 | - params.is_floating, | 988 | + is_floating, |
| 970 | ActivateWindow::default(), | 989 | ActivateWindow::default(), |
| 971 | ); | 990 | ); |
| 972 | } | 991 | } |
| @@ -1032,6 +1051,7 @@ impl Op { | |||
| 1032 | } | 1051 | } |
| 1033 | } | 1052 | } |
| 1034 | 1053 | ||
| 1054 | + let is_floating = params.is_floating; | ||
| 1035 | let win = TestWindow::new(params); | 1055 | let win = TestWindow::new(params); |
| 1036 | layout.add_window( | 1056 | layout.add_window( |
| 1037 | win, | 1057 | win, |
| @@ -1039,7 +1059,7 @@ impl Op { | |||
| 1039 | None, | 1059 | None, |
| 1040 | None, | 1060 | None, |
| 1041 | false, | 1061 | false, |
| 1042 | - params.is_floating, | 1062 | + is_floating, |
| 1043 | ActivateWindow::default(), | 1063 | ActivateWindow::default(), |
| 1044 | ); | 1064 | ); |
| 1045 | } | 1065 | } |
src/layout/tile.rsmodified+16 -5
| @@ -29,7 +29,9 @@ use crate::render_helpers::snapshot::RenderSnapshot; | |||
| 29 | use crate::render_helpers::solid_color::{SolidColorBuffer, SolidColorRenderElement}; | 29 | use crate::render_helpers::solid_color::{SolidColorBuffer, SolidColorRenderElement}; |
| 30 | use crate::render_helpers::RenderTarget; | 30 | use crate::render_helpers::RenderTarget; |
| 31 | use crate::utils::transaction::Transaction; | 31 | use crate::utils::transaction::Transaction; |
| 32 | -use crate::utils::{baba_is_float_offset, round_logical_in_physical}; | 32 | +use crate::utils::{ |
| 33 | + baba_is_float_offset, round_logical_in_physical, round_logical_in_physical_max1, | ||
| 34 | +}; | ||
| 33 | 35 | ||
| 34 | /// Toplevel window with decorations. | 36 | /// Toplevel window with decorations. |
| 35 | #[derive(Debug)] | 37 | #[derive(Debug)] |
| @@ -228,16 +230,20 @@ impl<W: LayoutElement> Tile<W> { | |||
| 228 | self.scale = scale; | 230 | self.scale = scale; |
| 229 | self.options = options; | 231 | self.options = options; |
| 230 | 232 | ||
| 233 | + let round_max1 = |logical| round_logical_in_physical_max1(self.scale, logical); | ||
| 234 | + | ||
| 231 | let rules = self.window.rules(); | 235 | let rules = self.window.rules(); |
| 232 | 236 | ||
| 233 | - let border_config = self.options.layout.border.merged_with(&rules.border); | 237 | + let mut border_config = self.options.layout.border.merged_with(&rules.border); |
| 238 | + border_config.width = round_max1(border_config.width); | ||
| 234 | self.border.update_config(border_config.into()); | 239 | self.border.update_config(border_config.into()); |
| 235 | 240 | ||
| 236 | - let focus_ring_config = self | 241 | + let mut focus_ring_config = self |
| 237 | .options | 242 | .options |
| 238 | .layout | 243 | .layout |
| 239 | .focus_ring | 244 | .focus_ring |
| 240 | .merged_with(&rules.focus_ring); | 245 | .merged_with(&rules.focus_ring); |
| 246 | + focus_ring_config.width = round_max1(focus_ring_config.width); | ||
| 241 | self.focus_ring.update_config(focus_ring_config); | 247 | self.focus_ring.update_config(focus_ring_config); |
| 242 | 248 | ||
| 243 | let shadow_config = self.options.layout.shadow.merged_with(&rules.shadow); | 249 | let shadow_config = self.options.layout.shadow.merged_with(&rules.shadow); |
| @@ -373,14 +379,19 @@ impl<W: LayoutElement> Tile<W> { | |||
| 373 | } | 379 | } |
| 374 | } | 380 | } |
| 375 | 381 | ||
| 382 | + let round_max1 = |logical| round_logical_in_physical_max1(self.scale, logical); | ||
| 383 | + | ||
| 376 | let rules = self.window.rules(); | 384 | let rules = self.window.rules(); |
| 377 | - let border_config = self.options.layout.border.merged_with(&rules.border); | 385 | + let mut border_config = self.options.layout.border.merged_with(&rules.border); |
| 386 | + border_config.width = round_max1(border_config.width); | ||
| 378 | self.border.update_config(border_config.into()); | 387 | self.border.update_config(border_config.into()); |
| 379 | - let focus_ring_config = self | 388 | + |
| 389 | + let mut focus_ring_config = self | ||
| 380 | .options | 390 | .options |
| 381 | .layout | 391 | .layout |
| 382 | .focus_ring | 392 | .focus_ring |
| 383 | .merged_with(&rules.focus_ring); | 393 | .merged_with(&rules.focus_ring); |
| 394 | + focus_ring_config.width = round_max1(focus_ring_config.width); | ||
| 384 | self.focus_ring.update_config(focus_ring_config); | 395 | self.focus_ring.update_config(focus_ring_config); |
| 385 | 396 | ||
| 386 | let shadow_config = self.options.layout.shadow.merged_with(&rules.shadow); | 397 | let shadow_config = self.options.layout.shadow.merged_with(&rules.shadow); |
src/window/mod.rsmodified+1 -1
| @@ -30,7 +30,7 @@ pub enum WindowRef<'a> { | |||
| 30 | } | 30 | } |
| 31 | 31 | ||
| 32 | /// Rules fully resolved for a window. | 32 | /// Rules fully resolved for a window. |
| 33 | -#[derive(Debug, PartialEq)] | 33 | +#[derive(Debug, PartialEq, Clone)] |
| 34 | pub struct ResolvedWindowRules { | 34 | pub struct ResolvedWindowRules { |
| 35 | /// Default width for this window. | 35 | /// Default width for this window. |
| 36 | /// | 36 | /// |