forge
Explore
Log in

Don't you dare go Hollow

Refactor layout to fractional-logical

Browse files at this commit

1dae45c58d7eabeda21ef490d712915890bf6cffIvan MolodetskikhParent: 997119c
Lets borders, gaps, and everything else stay pixel-perfect even with
fractional scale. Allows setting fractional border widths, gaps,
struts.

See the new wiki .md for more details.

35 changed files +1050 -652

Cargo.lockmodified+13 -3
@@ -143,6 +143,15 @@ dependencies = [
143 "num-traits",143 "num-traits",
144 ]144 ]
145 145
146+[[package]]
147+name = "approx"
148+version = "0.5.1"
149+source = "registry+https://github.com/rust-lang/crates.io-index"
150+checksum = "cab112f0a86d568ea0e627cc1d6be74a1e9cd55214684db5561995f6dad897c6"
151+dependencies = [
152+ "num-traits",
153+]
154+
146 [[package]]155 [[package]]
147 name = "arrayvec"156 name = "arrayvec"
148 version = "0.7.4"157 version = "0.7.4"
@@ -604,7 +613,7 @@ version = "0.18.0"
604 source = "registry+https://github.com/rust-lang/crates.io-index"613 source = "registry+https://github.com/rust-lang/crates.io-index"
605 checksum = "1a98d30140e3296250832bbaaff83b27dcd6fa3cc70fb6f1f3e5c9c0023b5317"614 checksum = "1a98d30140e3296250832bbaaff83b27dcd6fa3cc70fb6f1f3e5c9c0023b5317"
606 dependencies = [615 dependencies = [
607- "approx",616+ "approx 0.4.0",
608 "num-traits",617 "num-traits",
609 ]618 ]
610 619
@@ -2163,6 +2172,7 @@ name = "niri"
2163 version = "0.1.6"2172 version = "0.1.6"
2164 dependencies = [2173 dependencies = [
2165 "anyhow",2174 "anyhow",
2175+ "approx 0.5.1",
2166 "arrayvec",2176 "arrayvec",
2167 "async-channel",2177 "async-channel",
2168 "async-io 1.13.0",2178 "async-io 1.13.0",
@@ -3162,7 +3172,7 @@ checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67"
3162 [[package]]3172 [[package]]
3163 name = "smithay"3173 name = "smithay"
3164 version = "0.3.0"3174 version = "0.3.0"
3165-source = "git+https://github.com/Smithay/smithay.git#6169b213fb663d85d2e139d3bbe44dfae1ec9328"3175+source = "git+https://github.com/Smithay/smithay.git#b4f8120be0fb9b7f038d041efa7f6549e26cd2bc"
3166 dependencies = [3176 dependencies = [
3167 "appendlist",3177 "appendlist",
3168 "bitflags 2.5.0",3178 "bitflags 2.5.0",
@@ -3234,7 +3244,7 @@ dependencies = [
3234 [[package]]3244 [[package]]
3235 name = "smithay-drm-extras"3245 name = "smithay-drm-extras"
3236 version = "0.1.0"3246 version = "0.1.0"
3237-source = "git+https://github.com/Smithay/smithay.git#6169b213fb663d85d2e139d3bbe44dfae1ec9328"3247+source = "git+https://github.com/Smithay/smithay.git#b4f8120be0fb9b7f038d041efa7f6549e26cd2bc"
3238 dependencies = [3248 dependencies = [
3239 "drm",3249 "drm",
3240 "edid-rs",3250 "edid-rs",
Cargo.tomlmodified+1 -0
@@ -99,6 +99,7 @@ features = [
99 ]99 ]
100 100
101 [dev-dependencies]101 [dev-dependencies]
102+approx = "0.5.1"
102 k9 = "0.12.0"103 k9 = "0.12.0"
103 proptest = "1.4.0"104 proptest = "1.4.0"
104 proptest-derive = "0.4.0"105 proptest-derive = "0.4.0"
niri-config/src/lib.rsmodified+92 -22
@@ -331,6 +331,10 @@ pub struct Position {
331 pub y: i32,331 pub y: i32,
332 }332 }
333 333
334+// MIN and MAX generics are only used during parsing to check the value.
335+#[derive(Debug, Default, Clone, Copy, PartialEq)]
336+pub struct FloatOrInt<const MIN: i32, const MAX: i32>(pub f64);
337+
334 #[derive(knuffel::Decode, Debug, Clone, PartialEq)]338 #[derive(knuffel::Decode, Debug, Clone, PartialEq)]
335 pub struct Layout {339 pub struct Layout {
336 #[knuffel(child, default)]340 #[knuffel(child, default)]
@@ -344,7 +348,7 @@ pub struct Layout {
344 #[knuffel(child, unwrap(argument), default)]348 #[knuffel(child, unwrap(argument), default)]
345 pub center_focused_column: CenterFocusedColumn,349 pub center_focused_column: CenterFocusedColumn,
346 #[knuffel(child, unwrap(argument), default = Self::default().gaps)]350 #[knuffel(child, unwrap(argument), default = Self::default().gaps)]
347- pub gaps: u16,351+ pub gaps: FloatOrInt<0, 65535>,
348 #[knuffel(child, default)]352 #[knuffel(child, default)]
349 pub struts: Struts,353 pub struts: Struts,
350 }354 }
@@ -357,7 +361,7 @@ impl Default for Layout {
357 preset_column_widths: Default::default(),361 preset_column_widths: Default::default(),
358 default_column_width: Default::default(),362 default_column_width: Default::default(),
359 center_focused_column: Default::default(),363 center_focused_column: Default::default(),
360- gaps: 16,364+ gaps: FloatOrInt(16.),
361 struts: Default::default(),365 struts: Default::default(),
362 }366 }
363 }367 }
@@ -374,7 +378,7 @@ pub struct FocusRing {
374 #[knuffel(child)]378 #[knuffel(child)]
375 pub off: bool,379 pub off: bool,
376 #[knuffel(child, unwrap(argument), default = Self::default().width)]380 #[knuffel(child, unwrap(argument), default = Self::default().width)]
377- pub width: u16,381+ pub width: FloatOrInt<0, 65535>,
378 #[knuffel(child, default = Self::default().active_color)]382 #[knuffel(child, default = Self::default().active_color)]
379 pub active_color: Color,383 pub active_color: Color,
380 #[knuffel(child, default = Self::default().inactive_color)]384 #[knuffel(child, default = Self::default().inactive_color)]
@@ -389,7 +393,7 @@ impl Default for FocusRing {
389 fn default() -> Self {393 fn default() -> Self {
390 Self {394 Self {
391 off: false,395 off: false,
392- width: 4,396+ width: FloatOrInt(4.),
393 active_color: Color::new(127, 200, 255, 255),397 active_color: Color::new(127, 200, 255, 255),
394 inactive_color: Color::new(80, 80, 80, 255),398 inactive_color: Color::new(80, 80, 80, 255),
395 active_gradient: None,399 active_gradient: None,
@@ -422,7 +426,7 @@ pub struct Border {
422 #[knuffel(child)]426 #[knuffel(child)]
423 pub off: bool,427 pub off: bool,
424 #[knuffel(child, unwrap(argument), default = Self::default().width)]428 #[knuffel(child, unwrap(argument), default = Self::default().width)]
425- pub width: u16,429+ pub width: FloatOrInt<0, 65535>,
426 #[knuffel(child, default = Self::default().active_color)]430 #[knuffel(child, default = Self::default().active_color)]
427 pub active_color: Color,431 pub active_color: Color,
428 #[knuffel(child, default = Self::default().inactive_color)]432 #[knuffel(child, default = Self::default().inactive_color)]
@@ -437,7 +441,7 @@ impl Default for Border {
437 fn default() -> Self {441 fn default() -> Self {
438 Self {442 Self {
439 off: true,443 off: true,
440- width: 4,444+ width: FloatOrInt(4.),
441 active_color: Color::new(255, 200, 127, 255),445 active_color: Color::new(255, 200, 127, 255),
442 inactive_color: Color::new(80, 80, 80, 255),446 inactive_color: Color::new(80, 80, 80, 255),
443 active_gradient: None,447 active_gradient: None,
@@ -519,16 +523,16 @@ pub enum PresetWidth {
519 #[derive(Debug, Clone, PartialEq)]523 #[derive(Debug, Clone, PartialEq)]
520 pub struct DefaultColumnWidth(pub Option<PresetWidth>);524 pub struct DefaultColumnWidth(pub Option<PresetWidth>);
521 525
522-#[derive(knuffel::Decode, Debug, Default, Clone, Copy, PartialEq, Eq)]526+#[derive(knuffel::Decode, Debug, Default, Clone, Copy, PartialEq)]
523 pub struct Struts {527 pub struct Struts {
524 #[knuffel(child, unwrap(argument), default)]528 #[knuffel(child, unwrap(argument), default)]
525- pub left: u16,529+ pub left: FloatOrInt<0, 65535>,
526 #[knuffel(child, unwrap(argument), default)]530 #[knuffel(child, unwrap(argument), default)]
527- pub right: u16,531+ pub right: FloatOrInt<0, 65535>,
528 #[knuffel(child, unwrap(argument), default)]532 #[knuffel(child, unwrap(argument), default)]
529- pub top: u16,533+ pub top: FloatOrInt<0, 65535>,
530 #[knuffel(child, unwrap(argument), default)]534 #[knuffel(child, unwrap(argument), default)]
531- pub bottom: u16,535+ pub bottom: FloatOrInt<0, 65535>,
532 }536 }
533 537
534 #[derive(knuffel::Decode, Debug, Default, Clone, Copy, PartialEq, Eq)]538 #[derive(knuffel::Decode, Debug, Default, Clone, Copy, PartialEq, Eq)]
@@ -863,7 +867,7 @@ pub struct BorderRule {
863 #[knuffel(child)]867 #[knuffel(child)]
864 pub on: bool,868 pub on: bool,
865 #[knuffel(child, unwrap(argument))]869 #[knuffel(child, unwrap(argument))]
866- pub width: Option<u16>,870+ pub width: Option<FloatOrInt<0, 65535>>,
867 #[knuffel(child)]871 #[knuffel(child)]
868 pub active_color: Option<Color>,872 pub active_color: Option<Color>,
869 #[knuffel(child)]873 #[knuffel(child)]
@@ -1144,6 +1148,72 @@ impl<S: knuffel::traits::ErrorSpan> knuffel::DecodeScalar<S> for WorkspaceRefere
1144 }1148 }
1145 }1149 }
1146 1150
1151+impl<S: knuffel::traits::ErrorSpan, const MIN: i32, const MAX: i32> knuffel::DecodeScalar<S>
1152+ for FloatOrInt<MIN, MAX>
1153+{
1154+ fn type_check(
1155+ type_name: &Option<knuffel::span::Spanned<knuffel::ast::TypeName, S>>,
1156+ ctx: &mut knuffel::decode::Context<S>,
1157+ ) {
1158+ if let Some(type_name) = &type_name {
1159+ ctx.emit_error(DecodeError::unexpected(
1160+ type_name,
1161+ "type name",
1162+ "no type name expected for this node",
1163+ ));
1164+ }
1165+ }
1166+
1167+ fn raw_decode(
1168+ val: &knuffel::span::Spanned<knuffel::ast::Literal, S>,
1169+ ctx: &mut knuffel::decode::Context<S>,
1170+ ) -> Result<Self, DecodeError<S>> {
1171+ match &**val {
1172+ knuffel::ast::Literal::Int(ref value) => match value.try_into() {
1173+ Ok(v) => {
1174+ if (MIN..=MAX).contains(&v) {
1175+ Ok(FloatOrInt(f64::from(v)))
1176+ } else {
1177+ ctx.emit_error(DecodeError::conversion(
1178+ val,
1179+ format!("value must be between {MIN} and {MAX}"),
1180+ ));
1181+ Ok(FloatOrInt::default())
1182+ }
1183+ }
1184+ Err(e) => {
1185+ ctx.emit_error(DecodeError::conversion(val, e));
1186+ Ok(FloatOrInt::default())
1187+ }
1188+ },
1189+ knuffel::ast::Literal::Decimal(ref value) => match value.try_into() {
1190+ Ok(v) => {
1191+ if (f64::from(MIN)..=f64::from(MAX)).contains(&v) {
1192+ Ok(FloatOrInt(v))
1193+ } else {
1194+ ctx.emit_error(DecodeError::conversion(
1195+ val,
1196+ format!("value must be between {MIN} and {MAX}"),
1197+ ));
1198+ Ok(FloatOrInt::default())
1199+ }
1200+ }
1201+ Err(e) => {
1202+ ctx.emit_error(DecodeError::conversion(val, e));
1203+ Ok(FloatOrInt::default())
1204+ }
1205+ },
1206+ _ => {
1207+ ctx.emit_error(DecodeError::unsupported(
1208+ val,
1209+ "Unsupported value, only numbers are recognized",
1210+ ));
1211+ Ok(FloatOrInt::default())
1212+ }
1213+ }
1214+ }
1215+}
1216+
1147 #[derive(knuffel::Decode, Debug, Default, PartialEq)]1217 #[derive(knuffel::Decode, Debug, Default, PartialEq)]
1148 pub struct DebugConfig {1218 pub struct DebugConfig {
1149 #[knuffel(child, unwrap(argument))]1219 #[knuffel(child, unwrap(argument))]
@@ -2483,7 +2553,7 @@ mod tests {
2483 2553
2484 border {2554 border {
2485 on2555 on
2486- width 82556+ width 8.5
2487 }2557 }
2488 }2558 }
2489 2559
@@ -2579,7 +2649,7 @@ mod tests {
2579 layout: Layout {2649 layout: Layout {
2580 focus_ring: FocusRing {2650 focus_ring: FocusRing {
2581 off: false,2651 off: false,
2582- width: 5,2652+ width: FloatOrInt(5.),
2583 active_color: Color {2653 active_color: Color {
2584 r: 0,2654 r: 0,
2585 g: 100,2655 g: 100,
@@ -2602,7 +2672,7 @@ mod tests {
2602 },2672 },
2603 border: Border {2673 border: Border {
2604 off: false,2674 off: false,
2605- width: 3,2675+ width: FloatOrInt(3.),
2606 active_color: Color {2676 active_color: Color {
2607 r: 255,2677 r: 255,
2608 g: 200,2678 g: 200,
@@ -2627,12 +2697,12 @@ mod tests {
2627 default_column_width: Some(DefaultColumnWidth(Some(PresetWidth::Proportion(2697 default_column_width: Some(DefaultColumnWidth(Some(PresetWidth::Proportion(
2628 0.25,2698 0.25,
2629 )))),2699 )))),
2630- gaps: 8,2700+ gaps: FloatOrInt(8.),
2631 struts: Struts {2701 struts: Struts {
2632- left: 1,2702+ left: FloatOrInt(1.),
2633- right: 2,2703+ right: FloatOrInt(2.),
2634- top: 3,2704+ top: FloatOrInt(3.),
2635- bottom: 0,2705+ bottom: FloatOrInt(0.),
2636 },2706 },
2637 center_focused_column: CenterFocusedColumn::OnOverflow,2707 center_focused_column: CenterFocusedColumn::OnOverflow,
2638 },2708 },
@@ -2716,12 +2786,12 @@ mod tests {
2716 open_fullscreen: Some(false),2786 open_fullscreen: Some(false),
2717 focus_ring: BorderRule {2787 focus_ring: BorderRule {
2718 off: true,2788 off: true,
2719- width: Some(3),2789+ width: Some(FloatOrInt(3.)),
2720 ..Default::default()2790 ..Default::default()
2721 },2791 },
2722 border: BorderRule {2792 border: BorderRule {
2723 on: true,2793 on: true,
2724- width: Some(8),2794+ width: Some(FloatOrInt(8.5)),
2725 ..Default::default()2795 ..Default::default()
2726 },2796 },
2727 ..Default::default()2797 ..Default::default()
niri-visual-tests/src/cases/gradient_angle.rsmodified+3 -3
@@ -59,15 +59,15 @@ impl TestCase for GradientAngle {
59 ) -> Vec<Box<dyn RenderElement<GlesRenderer>>> {59 ) -> Vec<Box<dyn RenderElement<GlesRenderer>>> {
60 let (a, b) = (size.w / 4, size.h / 4);60 let (a, b) = (size.w / 4, size.h / 4);
61 let size = (size.w - a * 2, size.h - b * 2);61 let size = (size.w - a * 2, size.h - b * 2);
62- let area = Rectangle::from_loc_and_size((a, b), size);62+ let area = Rectangle::from_loc_and_size((a, b), size).to_f64();
63 63
64 [BorderRenderElement::new(64 [BorderRenderElement::new(
65 area.size,65 area.size,
66- Rectangle::from_loc_and_size((0, 0), area.size),66+ Rectangle::from_loc_and_size((0., 0.), area.size),
67 [1., 0., 0., 1.],67 [1., 0., 0., 1.],
68 [0., 1., 0., 1.],68 [0., 1., 0., 1.],
69 self.angle - FRAC_PI_2,69 self.angle - FRAC_PI_2,
70- Rectangle::from_loc_and_size((0, 0), area.size),70+ Rectangle::from_loc_and_size((0., 0.), area.size),
71 0.,71 0.,
72 CornerRadius::default(),72 CornerRadius::default(),
73 )73 )
niri-visual-tests/src/cases/gradient_area.rsmodified+9 -7
@@ -5,10 +5,10 @@ use std::time::Duration;
5 use niri::animation::ANIMATION_SLOWDOWN;5 use niri::animation::ANIMATION_SLOWDOWN;
6 use niri::layout::focus_ring::FocusRing;6 use niri::layout::focus_ring::FocusRing;
7 use niri::render_helpers::border::BorderRenderElement;7 use niri::render_helpers::border::BorderRenderElement;
8-use niri_config::{Color, CornerRadius};8+use niri_config::{Color, CornerRadius, FloatOrInt};
9 use smithay::backend::renderer::element::RenderElement;9 use smithay::backend::renderer::element::RenderElement;
10 use smithay::backend::renderer::gles::GlesRenderer;10 use smithay::backend::renderer::gles::GlesRenderer;
11-use smithay::utils::{Logical, Physical, Point, Rectangle, Scale, Size};11+use smithay::utils::{Logical, Physical, Point, Rectangle, Size};
12 12
13 use super::TestCase;13 use super::TestCase;
14 14
@@ -22,7 +22,7 @@ impl GradientArea {
22 pub fn new(_size: Size<i32, Logical>) -> Self {22 pub fn new(_size: Size<i32, Logical>) -> Self {
23 let border = FocusRing::new(niri_config::FocusRing {23 let border = FocusRing::new(niri_config::FocusRing {
24 off: false,24 off: false,
25- width: 1,25+ width: FloatOrInt(1.),
26 active_color: Color::new(255, 255, 255, 128),26 active_color: Color::new(255, 255, 255, 128),
27 inactive_color: Color::default(),27 inactive_color: Color::default(),
28 active_gradient: None,28 active_gradient: None,
@@ -75,13 +75,14 @@ impl TestCase for GradientArea {
75 75
76 let (a, b) = (size.w / 4, size.h / 4);76 let (a, b) = (size.w / 4, size.h / 4);
77 let rect_size = (size.w - a * 2, size.h - b * 2);77 let rect_size = (size.w - a * 2, size.h - b * 2);
78- let area = Rectangle::from_loc_and_size((a, b), rect_size);78+ let area = Rectangle::from_loc_and_size((a, b), rect_size).to_f64();
79 79
80 let g_size = Size::from((80 let g_size = Size::from((
81 (size.w as f32 / 8. + size.w as f32 / 8. * 7. * f).round() as i32,81 (size.w as f32 / 8. + size.w as f32 / 8. * 7. * f).round() as i32,
82 (size.h as f32 / 8. + size.h as f32 / 8. * 7. * f).round() as i32,82 (size.h as f32 / 8. + size.h as f32 / 8. * 7. * f).round() as i32,
83 ));83 ));
84- let g_loc = ((size.w - g_size.w) / 2, (size.h - g_size.h) / 2);84+ let g_loc = Point::from(((size.w - g_size.w) / 2, (size.h - g_size.h) / 2)).to_f64();
85+ let g_size = g_size.to_f64();
85 let mut g_area = Rectangle::from_loc_and_size(g_loc, g_size);86 let mut g_area = Rectangle::from_loc_and_size(g_loc, g_size);
86 g_area.loc -= area.loc;87 g_area.loc -= area.loc;
87 88
@@ -91,10 +92,11 @@ impl TestCase for GradientArea {
91 true,92 true,
92 Rectangle::default(),93 Rectangle::default(),
93 CornerRadius::default(),94 CornerRadius::default(),
95+ 1.,
94 );96 );
95 rv.extend(97 rv.extend(
96 self.border98 self.border
97- .render(renderer, Point::from(g_loc), Scale::from(1.))99+ .render(renderer, g_loc)
98 .map(|elem| Box::new(elem) as _),100 .map(|elem| Box::new(elem) as _),
99 );101 );
100 102
@@ -105,7 +107,7 @@ impl TestCase for GradientArea {
105 [1., 0., 0., 1.],107 [1., 0., 0., 1.],
106 [0., 1., 0., 1.],108 [0., 1., 0., 1.],
107 FRAC_PI_4,109 FRAC_PI_4,
108- Rectangle::from_loc_and_size((0, 0), rect_size),110+ Rectangle::from_loc_and_size((0, 0), rect_size).to_f64(),
109 0.,111 0.,
110 CornerRadius::default(),112 CornerRadius::default(),
111 )113 )
niri-visual-tests/src/cases/layout.rsmodified+2 -2
@@ -5,7 +5,7 @@ use niri::layout::workspace::ColumnWidth;
5 use niri::layout::{LayoutElement as _, Options};5 use niri::layout::{LayoutElement as _, Options};
6 use niri::render_helpers::RenderTarget;6 use niri::render_helpers::RenderTarget;
7 use niri::utils::get_monotonic_time;7 use niri::utils::get_monotonic_time;
8-use niri_config::Color;8+use niri_config::{Color, FloatOrInt};
9 use smithay::backend::renderer::element::RenderElement;9 use smithay::backend::renderer::element::RenderElement;
10 use smithay::backend::renderer::gles::GlesRenderer;10 use smithay::backend::renderer::gles::GlesRenderer;
11 use smithay::desktop::layer_map_for_output;11 use smithay::desktop::layer_map_for_output;
@@ -49,7 +49,7 @@ impl Layout {
49 },49 },
50 border: niri_config::Border {50 border: niri_config::Border {
51 off: false,51 off: false,
52- width: 4,52+ width: FloatOrInt(4.),
53 active_color: Color::new(255, 163, 72, 255),53 active_color: Color::new(255, 163, 72, 255),
54 inactive_color: Color::new(50, 50, 50, 255),54 inactive_color: Color::new(50, 50, 50, 255),
55 active_gradient: None,55 active_gradient: None,
niri-visual-tests/src/cases/tile.rsmodified+11 -10
@@ -3,7 +3,7 @@ use std::time::Duration;
3 3
4 use niri::layout::Options;4 use niri::layout::Options;
5 use niri::render_helpers::RenderTarget;5 use niri::render_helpers::RenderTarget;
6-use niri_config::Color;6+use niri_config::{Color, FloatOrInt};
7 use smithay::backend::renderer::element::RenderElement;7 use smithay::backend::renderer::element::RenderElement;
8 use smithay::backend::renderer::gles::GlesRenderer;8 use smithay::backend::renderer::gles::GlesRenderer;
9 use smithay::utils::{Logical, Physical, Point, Rectangle, Scale, Size};9 use smithay::utils::{Logical, Physical, Point, Rectangle, Scale, Size};
@@ -20,7 +20,7 @@ impl Tile {
20 pub fn freeform(size: Size<i32, Logical>) -> Self {20 pub fn freeform(size: Size<i32, Logical>) -> Self {
21 let window = TestWindow::freeform(0);21 let window = TestWindow::freeform(0);
22 let mut rv = Self::with_window(window);22 let mut rv = Self::with_window(window);
23- rv.tile.request_tile_size(size, false);23+ rv.tile.request_tile_size(size.to_f64(), false);
24 rv.window.communicate();24 rv.window.communicate();
25 rv25 rv
26 }26 }
@@ -28,7 +28,7 @@ impl Tile {
28 pub fn fixed_size(size: Size<i32, Logical>) -> Self {28 pub fn fixed_size(size: Size<i32, Logical>) -> Self {
29 let window = TestWindow::fixed_size(0);29 let window = TestWindow::fixed_size(0);
30 let mut rv = Self::with_window(window);30 let mut rv = Self::with_window(window);
31- rv.tile.request_tile_size(size, false);31+ rv.tile.request_tile_size(size.to_f64(), false);
32 rv.window.communicate();32 rv.window.communicate();
33 rv33 rv
34 }34 }
@@ -37,7 +37,7 @@ impl Tile {
37 let window = TestWindow::fixed_size(0);37 let window = TestWindow::fixed_size(0);
38 window.set_csd_shadow_width(64);38 window.set_csd_shadow_width(64);
39 let mut rv = Self::with_window(window);39 let mut rv = Self::with_window(window);
40- rv.tile.request_tile_size(size, false);40+ rv.tile.request_tile_size(size.to_f64(), false);
41 rv.window.communicate();41 rv.window.communicate();
42 rv42 rv
43 }43 }
@@ -71,13 +71,13 @@ impl Tile {
71 },71 },
72 border: niri_config::Border {72 border: niri_config::Border {
73 off: false,73 off: false,
74- width: 32,74+ width: FloatOrInt(32.),
75 active_color: Color::new(255, 163, 72, 255),75 active_color: Color::new(255, 163, 72, 255),
76 ..Default::default()76 ..Default::default()
77 },77 },
78 ..Default::default()78 ..Default::default()
79 };79 };
80- let tile = niri::layout::tile::Tile::new(window.clone(), Rc::new(options));80+ let tile = niri::layout::tile::Tile::new(window.clone(), 1., Rc::new(options));
81 Self { window, tile }81 Self { window, tile }
82 }82 }
83 }83 }
@@ -85,7 +85,7 @@ impl Tile {
85 impl TestCase for Tile {85 impl TestCase for Tile {
86 fn resize(&mut self, width: i32, height: i32) {86 fn resize(&mut self, width: i32, height: i32) {
87 self.tile87 self.tile
88- .request_tile_size(Size::from((width, height)), false);88+ .request_tile_size(Size::from((width, height)).to_f64(), false);
89 self.window.communicate();89 self.window.communicate();
90 }90 }
91 91
@@ -102,12 +102,13 @@ impl TestCase for Tile {
102 renderer: &mut GlesRenderer,102 renderer: &mut GlesRenderer,
103 size: Size<i32, Physical>,103 size: Size<i32, Physical>,
104 ) -> Vec<Box<dyn RenderElement<GlesRenderer>>> {104 ) -> Vec<Box<dyn RenderElement<GlesRenderer>>> {
105- let tile_size = self.tile.tile_size().to_physical(1);105+ let size = size.to_f64();
106- let location = Point::from(((size.w - tile_size.w) / 2, (size.h - tile_size.h) / 2));106+ let tile_size = self.tile.tile_size().to_physical(1.);
107+ let location = Point::from((size.w - tile_size.w, size.h - tile_size.h)).downscale(2.);
107 108
108 self.tile.update(109 self.tile.update(
109 true,110 true,
110- Rectangle::from_loc_and_size((-location.x, -location.y), size.to_logical(1)),111+ Rectangle::from_loc_and_size((-location.x, -location.y), size.to_logical(1.)),
111 );112 );
112 self.tile113 self.tile
113 .render(114 .render(
niri-visual-tests/src/cases/window.rsmodified+3 -1
@@ -47,7 +47,9 @@ impl TestCase for Window {
47 size: Size<i32, Physical>,47 size: Size<i32, Physical>,
48 ) -> Vec<Box<dyn RenderElement<GlesRenderer>>> {48 ) -> Vec<Box<dyn RenderElement<GlesRenderer>>> {
49 let win_size = self.window.size().to_physical(1);49 let win_size = self.window.size().to_physical(1);
50- let location = Point::from(((size.w - win_size.w) / 2, (size.h - win_size.h) / 2));50+ let location = Point::from((size.w - win_size.w, size.h - win_size.h))
51+ .to_f64()
52+ .downscale(2.);
51 53
52 self.window54 self.window
53 .render(55 .render(
niri-visual-tests/src/test_window.rsmodified+10 -12
@@ -6,9 +6,9 @@ use niri::layout::{
6 InteractiveResizeData, LayoutElement, LayoutElementRenderElement, LayoutElementRenderSnapshot,6 InteractiveResizeData, LayoutElement, LayoutElementRenderElement, LayoutElementRenderSnapshot,
7 };7 };
8 use niri::render_helpers::renderer::NiriRenderer;8 use niri::render_helpers::renderer::NiriRenderer;
9+use niri::render_helpers::solid_color::{SolidColorBuffer, SolidColorRenderElement};
9 use niri::render_helpers::{RenderTarget, SplitElements};10 use niri::render_helpers::{RenderTarget, SplitElements};
10 use niri::window::ResolvedWindowRules;11 use niri::window::ResolvedWindowRules;
11-use smithay::backend::renderer::element::solid::{SolidColorBuffer, SolidColorRenderElement};
12 use smithay::backend::renderer::element::{Id, Kind};12 use smithay::backend::renderer::element::{Id, Kind};
13 use smithay::output::{self, Output};13 use smithay::output::{self, Output};
14 use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface;14 use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface;
@@ -37,7 +37,7 @@ impl TestWindow {
37 let size = Size::from((100, 200));37 let size = Size::from((100, 200));
38 let min_size = Size::from((0, 0));38 let min_size = Size::from((0, 0));
39 let max_size = Size::from((0, 0));39 let max_size = Size::from((0, 0));
40- let buffer = SolidColorBuffer::new(size, [0.15, 0.64, 0.41, 1.]);40+ let buffer = SolidColorBuffer::new(size.to_f64(), [0.15, 0.64, 0.41, 1.]);
41 41
42 Self {42 Self {
43 id,43 id,
@@ -49,7 +49,7 @@ impl TestWindow {
49 buffer,49 buffer,
50 pending_fullscreen: false,50 pending_fullscreen: false,
51 csd_shadow_width: 0,51 csd_shadow_width: 0,
52- csd_shadow_buffer: SolidColorBuffer::new((0, 0), [0., 0., 0., 0.3]),52+ csd_shadow_buffer: SolidColorBuffer::new((0., 0.), [0., 0., 0., 0.3]),
53 })),53 })),
54 }54 }
55 }55 }
@@ -112,14 +112,14 @@ impl TestWindow {
112 112
113 if inner.size != new_size {113 if inner.size != new_size {
114 inner.size = new_size;114 inner.size = new_size;
115- inner.buffer.resize(new_size);115+ inner.buffer.resize(new_size.to_f64());
116 rv = true;116 rv = true;
117 }117 }
118 118
119 let mut csd_shadow_size = new_size;119 let mut csd_shadow_size = new_size;
120 csd_shadow_size.w += inner.csd_shadow_width * 2;120 csd_shadow_size.w += inner.csd_shadow_width * 2;
121 csd_shadow_size.h += inner.csd_shadow_width * 2;121 csd_shadow_size.h += inner.csd_shadow_width * 2;
122- inner.csd_shadow_buffer.resize(csd_shadow_size);122+ inner.csd_shadow_buffer.resize(csd_shadow_size.to_f64());
123 123
124 rv124 rv
125 }125 }
@@ -147,8 +147,8 @@ impl LayoutElement for TestWindow {
147 fn render<R: NiriRenderer>(147 fn render<R: NiriRenderer>(
148 &self,148 &self,
149 _renderer: &mut R,149 _renderer: &mut R,
150- location: Point<i32, Logical>,150+ location: Point<f64, Logical>,
151- scale: Scale<f64>,151+ _scale: Scale<f64>,
152 alpha: f32,152 alpha: f32,
153 _target: RenderTarget,153 _target: RenderTarget,
154 ) -> SplitElements<LayoutElementRenderElement<R>> {154 ) -> SplitElements<LayoutElementRenderElement<R>> {
@@ -158,17 +158,15 @@ impl LayoutElement for TestWindow {
158 normal: vec![158 normal: vec![
159 SolidColorRenderElement::from_buffer(159 SolidColorRenderElement::from_buffer(
160 &inner.buffer,160 &inner.buffer,
161- location.to_physical_precise_round(scale),161+ location,
162- scale,
163 alpha,162 alpha,
164 Kind::Unspecified,163 Kind::Unspecified,
165 )164 )
166 .into(),165 .into(),
167 SolidColorRenderElement::from_buffer(166 SolidColorRenderElement::from_buffer(
168 &inner.csd_shadow_buffer,167 &inner.csd_shadow_buffer,
169- (location - Point::from((inner.csd_shadow_width, inner.csd_shadow_width)))168+ location
170- .to_physical_precise_round(scale),169+ - Point::from((inner.csd_shadow_width, inner.csd_shadow_width)).to_f64(),
171- scale,
172 alpha,170 alpha,
173 Kind::Unspecified,171 Kind::Unspecified,
174 )172 )
src/handlers/xdg_shell.rsmodified+21 -20
@@ -788,9 +788,9 @@ impl State {
788 // window can be scrolled to both edges of the screen), but within the whole monitor's788 // window can be scrolled to both edges of the screen), but within the whole monitor's
789 // height.789 // height.
790 let mut target =790 let mut target =
791- Rectangle::from_loc_and_size((0, 0), (window_geo.size.w, output_geo.size.h));791+ Rectangle::from_loc_and_size((0, 0), (window_geo.size.w, output_geo.size.h)).to_f64();
792 target.loc -= self.niri.layout.window_loc(window).unwrap();792 target.loc -= self.niri.layout.window_loc(window).unwrap();
793- target.loc -= get_popup_toplevel_coords(popup);793+ target.loc -= get_popup_toplevel_coords(popup).to_f64();
794 794
795 self.position_popup_within_rect(popup, target);795 self.position_popup_within_rect(popup, target);
796 }796 }
@@ -813,10 +813,10 @@ impl State {
813 target.loc -= layer_geo.loc;813 target.loc -= layer_geo.loc;
814 target.loc -= get_popup_toplevel_coords(popup);814 target.loc -= get_popup_toplevel_coords(popup);
815 815
816- self.position_popup_within_rect(popup, target);816+ self.position_popup_within_rect(popup, target.to_f64());
817 }817 }
818 818
819- fn position_popup_within_rect(&self, popup: &PopupKind, target: Rectangle<i32, Logical>) {819+ fn position_popup_within_rect(&self, popup: &PopupKind, target: Rectangle<f64, Logical>) {
820 match popup {820 match popup {
821 PopupKind::Xdg(popup) => {821 PopupKind::Xdg(popup) => {
822 popup.with_pending_state(|state| {822 popup.with_pending_state(|state| {
@@ -826,28 +826,29 @@ impl State {
826 PopupKind::InputMethod(popup) => {826 PopupKind::InputMethod(popup) => {
827 let text_input_rectangle = popup.text_input_rectangle();827 let text_input_rectangle = popup.text_input_rectangle();
828 let mut bbox =828 let mut bbox =
829- utils::bbox_from_surface_tree(popup.wl_surface(), text_input_rectangle.loc);829+ utils::bbox_from_surface_tree(popup.wl_surface(), text_input_rectangle.loc)
830+ .to_f64();
830 831
831 // Position bbox horizontally first.832 // Position bbox horizontally first.
832 let overflow_x = (bbox.loc.x + bbox.size.w) - (target.loc.x + target.size.w);833 let overflow_x = (bbox.loc.x + bbox.size.w) - (target.loc.x + target.size.w);
833- if overflow_x > 0 {834+ if overflow_x > 0. {
834 bbox.loc.x -= overflow_x;835 bbox.loc.x -= overflow_x;
835 }836 }
836 837
837 // Ensure that the popup starts within the window.838 // Ensure that the popup starts within the window.
838- bbox.loc.x = bbox.loc.x.max(target.loc.x);839+ bbox.loc.x = f64::max(bbox.loc.x, target.loc.x);
839 840
840 // Try to position IME popup below the text input rectangle.841 // Try to position IME popup below the text input rectangle.
841 let mut below = bbox;842 let mut below = bbox;
842- below.loc.y += text_input_rectangle.size.h;843+ below.loc.y += f64::from(text_input_rectangle.size.h);
843 844
844 let mut above = bbox;845 let mut above = bbox;
845 above.loc.y -= bbox.size.h;846 above.loc.y -= bbox.size.h;
846 847
847 if target.loc.y + target.size.h >= below.loc.y + below.size.h {848 if target.loc.y + target.size.h >= below.loc.y + below.size.h {
848- popup.set_location(below.loc);849+ popup.set_location(below.loc.to_i32_round());
849 } else {850 } else {
850- popup.set_location(above.loc);851+ popup.set_location(above.loc.to_i32_round());
851 }852 }
852 }853 }
853 }854 }
@@ -907,25 +908,25 @@ impl State {
907 908
908 fn unconstrain_with_padding(909 fn unconstrain_with_padding(
909 positioner: PositionerState,910 positioner: PositionerState,
910- target: Rectangle<i32, Logical>,911+ target: Rectangle<f64, Logical>,
911 ) -> Rectangle<i32, Logical> {912 ) -> Rectangle<i32, Logical> {
912 // Try unconstraining with a small padding first which looks nicer, then if it doesn't fit try913 // Try unconstraining with a small padding first which looks nicer, then if it doesn't fit try
913 // unconstraining without padding.914 // unconstraining without padding.
914- const PADDING: i32 = 8;915+ const PADDING: f64 = 8.;
915 916
916 let mut padded = target;917 let mut padded = target;
917- if PADDING * 2 < padded.size.w {918+ if PADDING * 2. < padded.size.w {
918 padded.loc.x += PADDING;919 padded.loc.x += PADDING;
919- padded.size.w -= PADDING * 2;920+ padded.size.w -= PADDING * 2.;
920 }921 }
921- if PADDING * 2 < padded.size.h {922+ if PADDING * 2. < padded.size.h {
922 padded.loc.y += PADDING;923 padded.loc.y += PADDING;
923- padded.size.h -= PADDING * 2;924+ padded.size.h -= PADDING * 2.;
924 }925 }
925 926
926 // No padding, so just unconstrain with the original target.927 // No padding, so just unconstrain with the original target.
927 if padded == target {928 if padded == target {
928- return positioner.get_unconstrained_geometry(target);929+ return positioner.get_unconstrained_geometry(target.to_i32_round());
929 }930 }
930 931
931 // Do not try to resize to fit the padded target rectangle.932 // Do not try to resize to fit the padded target rectangle.
@@ -937,13 +938,13 @@ fn unconstrain_with_padding(
937 .constraint_adjustment938 .constraint_adjustment
938 .remove(ConstraintAdjustment::ResizeY);939 .remove(ConstraintAdjustment::ResizeY);
939 940
940- let geo = no_resize.get_unconstrained_geometry(padded);941+ let geo = no_resize.get_unconstrained_geometry(padded.to_i32_round());
941- if padded.contains_rect(geo) {942+ if padded.contains_rect(geo.to_f64()) {
942 return geo;943 return geo;
943 }944 }
944 945
945 // Could not unconstrain into the padded target, so resort to the regular one.946 // Could not unconstrain into the padded target, so resort to the regular one.
946- positioner.get_unconstrained_geometry(target)947+ positioner.get_unconstrained_geometry(target.to_i32_round())
947 }948 }
948 949
949 pub fn add_mapped_toplevel_pre_commit_hook(toplevel: &ToplevelSurface) -> HookId {950 pub fn add_mapped_toplevel_pre_commit_hook(toplevel: &ToplevelSurface) -> HookId {
src/input/mod.rsmodified+4 -4
@@ -935,7 +935,7 @@ impl State {
935 // Check if we have an active pointer constraint.935 // Check if we have an active pointer constraint.
936 let mut pointer_confined = None;936 let mut pointer_confined = None;
937 if let Some(focus) = &self.niri.pointer_focus.surface {937 if let Some(focus) = &self.niri.pointer_focus.surface {
938- let pos_within_surface = pos.to_i32_round() - focus.1;938+ let pos_within_surface = pos - focus.1;
939 939
940 let mut pointer_locked = false;940 let mut pointer_locked = false;
941 with_pointer_constraint(&focus.0, &pointer, |constraint| {941 with_pointer_constraint(&focus.0, &pointer, |constraint| {
@@ -946,7 +946,7 @@ impl State {
946 946
947 // Constraint does not apply if not within region.947 // Constraint does not apply if not within region.
948 if let Some(region) = constraint.region() {948 if let Some(region) = constraint.region() {
949- if !region.contains(pos_within_surface) {949+ if !region.contains(pos_within_surface.to_i32_round()) {
950 return;950 return;
951 }951 }
952 }952 }
@@ -1036,8 +1036,8 @@ impl State {
1036 1036
1037 // Prevent the pointer from leaving the confine region, if any.1037 // Prevent the pointer from leaving the confine region, if any.
1038 if let Some(region) = region {1038 if let Some(region) = region {
1039- let new_pos_within_surface = new_pos.to_i32_round() - focus_surface.1;1039+ let new_pos_within_surface = new_pos - focus_surface.1;
1040- if !region.contains(new_pos_within_surface) {1040+ if !region.contains(new_pos_within_surface.to_i32_round()) {
1041 prevent = true;1041 prevent = true;
1042 }1042 }
1043 }1043 }
src/input/resize_grab.rsmodified+2 -2
@@ -35,7 +35,7 @@ impl PointerGrab<State> for ResizeGrab {
35 &mut self,35 &mut self,
36 data: &mut State,36 data: &mut State,
37 handle: &mut PointerInnerHandle<'_, State>,37 handle: &mut PointerInnerHandle<'_, State>,
38- _focus: Option<(<State as SeatHandler>::PointerFocus, Point<i32, Logical>)>,38+ _focus: Option<(<State as SeatHandler>::PointerFocus, Point<f64, Logical>)>,
39 event: &MotionEvent,39 event: &MotionEvent,
40 ) {40 ) {
41 // While the grab is active, no client has pointer focus.41 // While the grab is active, no client has pointer focus.
@@ -60,7 +60,7 @@ impl PointerGrab<State> for ResizeGrab {
60 &mut self,60 &mut self,
61 data: &mut State,61 data: &mut State,
62 handle: &mut PointerInnerHandle<'_, State>,62 handle: &mut PointerInnerHandle<'_, State>,
63- _focus: Option<(<State as SeatHandler>::PointerFocus, Point<i32, Logical>)>,63+ _focus: Option<(<State as SeatHandler>::PointerFocus, Point<f64, Logical>)>,
64 event: &RelativeMotionEvent,64 event: &RelativeMotionEvent,
65 ) {65 ) {
66 // While the grab is active, no client has pointer focus.66 // While the grab is active, no client has pointer focus.
src/input/view_offset_grab.rsmodified+2 -2
@@ -46,7 +46,7 @@ impl PointerGrab<State> for ViewOffsetGrab {
46 &mut self,46 &mut self,
47 data: &mut State,47 data: &mut State,
48 handle: &mut PointerInnerHandle<'_, State>,48 handle: &mut PointerInnerHandle<'_, State>,
49- _focus: Option<(<State as SeatHandler>::PointerFocus, Point<i32, Logical>)>,49+ _focus: Option<(<State as SeatHandler>::PointerFocus, Point<f64, Logical>)>,
50 event: &MotionEvent,50 event: &MotionEvent,
51 ) {51 ) {
52 // While the grab is active, no client has pointer focus.52 // While the grab is active, no client has pointer focus.
@@ -74,7 +74,7 @@ impl PointerGrab<State> for ViewOffsetGrab {
74 &mut self,74 &mut self,
75 data: &mut State,75 data: &mut State,
76 handle: &mut PointerInnerHandle<'_, State>,76 handle: &mut PointerInnerHandle<'_, State>,
77- _focus: Option<(<State as SeatHandler>::PointerFocus, Point<i32, Logical>)>,77+ _focus: Option<(<State as SeatHandler>::PointerFocus, Point<f64, Logical>)>,
78 event: &RelativeMotionEvent,78 event: &RelativeMotionEvent,
79 ) {79 ) {
80 // While the grab is active, no client has pointer focus.80 // While the grab is active, no client has pointer focus.
src/layout/closing_window.rsmodified+15 -10
@@ -34,10 +34,10 @@ pub struct ClosingWindow {
34 block_out_from: Option<BlockOutFrom>,34 block_out_from: Option<BlockOutFrom>,
35 35
36 /// Size of the window geometry.36 /// Size of the window geometry.
37- geo_size: Size<i32, Logical>,37+ geo_size: Size<f64, Logical>,
38 38
39 /// Position in the workspace.39 /// Position in the workspace.
40- pos: Point<i32, Logical>,40+ pos: Point<f64, Logical>,
41 41
42 /// How much the texture should be offset.42 /// How much the texture should be offset.
43 buffer_offset: Point<f64, Logical>,43 buffer_offset: Point<f64, Logical>,
@@ -64,8 +64,8 @@ impl ClosingWindow {
64 renderer: &mut GlesRenderer,64 renderer: &mut GlesRenderer,
65 snapshot: RenderSnapshot<E, E>,65 snapshot: RenderSnapshot<E, E>,
66 scale: Scale<f64>,66 scale: Scale<f64>,
67- geo_size: Size<i32, Logical>,67+ geo_size: Size<f64, Logical>,
68- pos: Point<i32, Logical>,68+ pos: Point<f64, Logical>,
69 anim: Animation,69 anim: Animation,
70 ) -> anyhow::Result<Self> {70 ) -> anyhow::Result<Self> {
71 let _span = tracy_client::span!("ClosingWindow::new");71 let _span = tracy_client::span!("ClosingWindow::new");
@@ -123,7 +123,7 @@ impl ClosingWindow {
123 pub fn render(123 pub fn render(
124 &self,124 &self,
125 renderer: &mut GlesRenderer,125 renderer: &mut GlesRenderer,
126- view_rect: Rectangle<i32, Logical>,126+ view_rect: Rectangle<f64, Logical>,
127 scale: Scale<f64>,127 scale: Scale<f64>,
128 target: RenderTarget,128 target: RenderTarget,
129 ) -> ClosingWindowRenderElement {129 ) -> ClosingWindowRenderElement {
@@ -140,7 +140,12 @@ impl ClosingWindow {
140 let area_loc = Vec2::new(view_rect.loc.x as f32, view_rect.loc.y as f32);140 let area_loc = Vec2::new(view_rect.loc.x as f32, view_rect.loc.y as f32);
141 let area_size = Vec2::new(view_rect.size.w as f32, view_rect.size.h as f32);141 let area_size = Vec2::new(view_rect.size.w as f32, view_rect.size.h as f32);
142 142
143- let geo_loc = Vec2::new(self.pos.x as f32, self.pos.y as f32);143+ // Round to physical pixels relative to the view position. This is similar to what
144+ // happens when rendering normal windows.
145+ let relative = self.pos - view_rect.loc;
146+ let pos = view_rect.loc + relative.to_physical_precise_round(scale).to_logical(scale);
147+
148+ let geo_loc = Vec2::new(pos.x as f32, pos.y as f32);
144 let geo_size = Vec2::new(self.geo_size.w as f32, self.geo_size.h as f32);149 let geo_size = Vec2::new(self.geo_size.w as f32, self.geo_size.h as f32);
145 150
146 let input_to_geo = Mat3::from_scale(area_size / geo_size)151 let input_to_geo = Mat3::from_scale(area_size / geo_size)
@@ -171,7 +176,7 @@ impl ClosingWindow {
171 HashMap::from([(String::from("niri_tex"), buffer.texture().clone())]),176 HashMap::from([(String::from("niri_tex"), buffer.texture().clone())]),
172 Kind::Unspecified,177 Kind::Unspecified,
173 )178 )
174- .with_location(Point::from((0, 0)))179+ .with_location(Point::from((0., 0.)))
175 .into();180 .into();
176 }181 }
177 182
@@ -186,15 +191,15 @@ impl ClosingWindow {
186 191
187 let elem = PrimaryGpuTextureRenderElement(elem);192 let elem = PrimaryGpuTextureRenderElement(elem);
188 193
189- let center = self.geo_size.to_point().to_f64().downscale(2.);194+ let center = self.geo_size.to_point().downscale(2.);
190 let elem = RescaleRenderElement::from_element(195 let elem = RescaleRenderElement::from_element(
191 elem,196 elem,
192 (center - offset).to_physical_precise_round(scale),197 (center - offset).to_physical_precise_round(scale),
193 ((1. - clamped_progress) / 5. + 0.8).max(0.),198 ((1. - clamped_progress) / 5. + 0.8).max(0.),
194 );199 );
195 200
196- let mut location = self.pos.to_f64() + offset;201+ let mut location = self.pos + offset;
197- location.x -= view_rect.loc.x as f64;202+ location.x -= view_rect.loc.x;
198 let elem = RelocateRenderElement::from_element(203 let elem = RelocateRenderElement::from_element(
199 elem,204 elem,
200 location.to_physical_precise_round(scale),205 location.to_physical_precise_round(scale),
src/layout/focus_ring.rsmodified+37 -36
@@ -1,23 +1,22 @@
1-use std::cmp::{max, min};
2 use std::iter::zip;1 use std::iter::zip;
3 2
4 use arrayvec::ArrayVec;3 use arrayvec::ArrayVec;
5 use niri_config::{CornerRadius, Gradient, GradientRelativeTo};4 use niri_config::{CornerRadius, Gradient, GradientRelativeTo};
6-use smithay::backend::renderer::element::solid::{SolidColorBuffer, SolidColorRenderElement};
7 use smithay::backend::renderer::element::Kind;5 use smithay::backend::renderer::element::Kind;
8-use smithay::utils::{Logical, Point, Rectangle, Scale, Size};6+use smithay::utils::{Logical, Point, Rectangle, Size};
9 7
10 use crate::niri_render_elements;8 use crate::niri_render_elements;
11 use crate::render_helpers::border::BorderRenderElement;9 use crate::render_helpers::border::BorderRenderElement;
12 use crate::render_helpers::renderer::NiriRenderer;10 use crate::render_helpers::renderer::NiriRenderer;
11+use crate::render_helpers::solid_color::{SolidColorBuffer, SolidColorRenderElement};
13 12
14 #[derive(Debug)]13 #[derive(Debug)]
15 pub struct FocusRing {14 pub struct FocusRing {
16 buffers: [SolidColorBuffer; 8],15 buffers: [SolidColorBuffer; 8],
17- locations: [Point<i32, Logical>; 8],16+ locations: [Point<f64, Logical>; 8],
18- sizes: [Size<i32, Logical>; 8],17+ sizes: [Size<f64, Logical>; 8],
19 borders: [BorderRenderElement; 8],18 borders: [BorderRenderElement; 8],
20- full_size: Size<i32, Logical>,19+ full_size: Size<f64, Logical>,
21 is_border: bool,20 is_border: bool,
22 use_border_shader: bool,21 use_border_shader: bool,
23 config: niri_config::FocusRing,22 config: niri_config::FocusRing,
@@ -56,14 +55,15 @@ impl FocusRing {
56 55
57 pub fn update_render_elements(56 pub fn update_render_elements(
58 &mut self,57 &mut self,
59- win_size: Size<i32, Logical>,58+ win_size: Size<f64, Logical>,
60 is_active: bool,59 is_active: bool,
61 is_border: bool,60 is_border: bool,
62- view_rect: Rectangle<i32, Logical>,61+ view_rect: Rectangle<f64, Logical>,
63 radius: CornerRadius,62 radius: CornerRadius,
63+ scale: f64,
64 ) {64 ) {
65- let width = i32::from(self.config.width);65+ let width = self.config.width.0;
66- self.full_size = win_size + Size::from((width * 2, width * 2));66+ self.full_size = win_size + Size::from((width, width)).upscale(2.);
67 67
68 let color = if is_active {68 let color = if is_active {
69 self.config.active_color69 self.config.active_color
@@ -107,39 +107,48 @@ impl FocusRing {
107 0.107 0.
108 };108 };
109 109
110+ let ceil = |logical: f64| (logical * scale).ceil() / scale;
111+
112+ // All of this stuff should end up aligned to physical pixels because:
113+ // * Window size and border width are rounded to physical pixels before being passed to this
114+ // function.
115+ // * We will ceil the corner radii below.
116+ // * We do not divide anything, only add, subtract and multiply by integers.
117+ // * At rendering time, tile positions are rounded to physical pixels.
118+
110 if is_border {119 if is_border {
111- let top_left = max(width, radius.top_left.ceil() as i32);120+ let top_left = f64::max(width, ceil(f64::from(radius.top_left)));
112- let top_right = min(121+ let top_right = f64::min(
113 self.full_size.w - top_left,122 self.full_size.w - top_left,
114- max(width, radius.top_right.ceil() as i32),123+ f64::max(width, ceil(f64::from(radius.top_right))),
115 );124 );
116- let bottom_left = min(125+ let bottom_left = f64::min(
117 self.full_size.h - top_left,126 self.full_size.h - top_left,
118- max(width, radius.bottom_left.ceil() as i32),127+ f64::max(width, ceil(f64::from(radius.bottom_left))),
119 );128 );
120- let bottom_right = min(129+ let bottom_right = f64::min(
121 self.full_size.h - top_right,130 self.full_size.h - top_right,
122- min(131+ f64::min(
123 self.full_size.w - bottom_left,132 self.full_size.w - bottom_left,
124- max(width, radius.bottom_right.ceil() as i32),133+ f64::max(width, ceil(f64::from(radius.bottom_right))),
125 ),134 ),
126 );135 );
127 136
128 // Top edge.137 // Top edge.
129- self.sizes[0] = Size::from((win_size.w + width * 2 - top_left - top_right, width));138+ self.sizes[0] = Size::from((win_size.w + width * 2. - top_left - top_right, width));
130 self.locations[0] = Point::from((-width + top_left, -width));139 self.locations[0] = Point::from((-width + top_left, -width));
131 140
132 // Bottom edge.141 // Bottom edge.
133 self.sizes[1] =142 self.sizes[1] =
134- Size::from((win_size.w + width * 2 - bottom_left - bottom_right, width));143+ Size::from((win_size.w + width * 2. - bottom_left - bottom_right, width));
135 self.locations[1] = Point::from((-width + bottom_left, win_size.h));144 self.locations[1] = Point::from((-width + bottom_left, win_size.h));
136 145
137 // Left edge.146 // Left edge.
138- self.sizes[2] = Size::from((width, win_size.h + width * 2 - top_left - bottom_left));147+ self.sizes[2] = Size::from((width, win_size.h + width * 2. - top_left - bottom_left));
139 self.locations[2] = Point::from((-width, -width + top_left));148 self.locations[2] = Point::from((-width, -width + top_left));
140 149
141 // Right edge.150 // Right edge.
142- self.sizes[3] = Size::from((width, win_size.h + width * 2 - top_right - bottom_right));151+ self.sizes[3] = Size::from((width, win_size.h + width * 2. - top_right - bottom_right));
143 self.locations[3] = Point::from((win_size.w, -width + top_right));152 self.locations[3] = Point::from((win_size.w, -width + top_right));
144 153
145 // Top-left corner.154 // Top-left corner.
@@ -203,8 +212,7 @@ impl FocusRing {
203 pub fn render(212 pub fn render(
204 &self,213 &self,
205 renderer: &mut impl NiriRenderer,214 renderer: &mut impl NiriRenderer,
206- location: Point<i32, Logical>,215+ location: Point<f64, Logical>,
207- scale: Scale<f64>,
208 ) -> impl Iterator<Item = FocusRingRenderElement> {216 ) -> impl Iterator<Item = FocusRingRenderElement> {
209 let mut rv = ArrayVec::<_, 8>::new();217 let mut rv = ArrayVec::<_, 8>::new();
210 218
@@ -215,24 +223,17 @@ impl FocusRing {
215 let border_width = -self.locations[0].y;223 let border_width = -self.locations[0].y;
216 224
217 // If drawing as a border with width = 0, then there's nothing to draw.225 // If drawing as a border with width = 0, then there's nothing to draw.
218- if self.is_border && border_width == 0 {226+ if self.is_border && border_width == 0. {
219 return rv.into_iter();227 return rv.into_iter();
220 }228 }
221 229
222 let has_border_shader = BorderRenderElement::has_shader(renderer);230 let has_border_shader = BorderRenderElement::has_shader(renderer);
223 231
224- let mut push = |buffer, border: &BorderRenderElement, location: Point<i32, Logical>| {232+ let mut push = |buffer, border: &BorderRenderElement, location: Point<f64, Logical>| {
225 let elem = if self.use_border_shader && has_border_shader {233 let elem = if self.use_border_shader && has_border_shader {
226 border.clone().with_location(location).into()234 border.clone().with_location(location).into()
227 } else {235 } else {
228- SolidColorRenderElement::from_buffer(236+ SolidColorRenderElement::from_buffer(buffer, location, 1., Kind::Unspecified).into()
229- buffer,
230- location.to_physical_precise_round(scale),
231- scale,
232- 1.,
233- Kind::Unspecified,
234- )
235- .into()
236 };237 };
237 rv.push(elem);238 rv.push(elem);
238 };239 };
@@ -252,8 +253,8 @@ impl FocusRing {
252 rv.into_iter()253 rv.into_iter()
253 }254 }
254 255
255- pub fn width(&self) -> i32 {256+ pub fn width(&self) -> f64 {
256- self.config.width.into()257+ self.config.width.0
257 }258 }
258 259
259 pub fn is_off(&self) -> bool {260 pub fn is_off(&self) -> bool {
src/layout/mod.rsmodified+165 -39
@@ -34,9 +34,8 @@ use std::mem;
34 use std::rc::Rc;34 use std::rc::Rc;
35 use std::time::Duration;35 use std::time::Duration;
36 36
37-use niri_config::{CenterFocusedColumn, Config, Struts, Workspace as WorkspaceConfig};37+use niri_config::{CenterFocusedColumn, Config, FloatOrInt, Struts, Workspace as WorkspaceConfig};
38 use niri_ipc::SizeChange;38 use niri_ipc::SizeChange;
39-use smithay::backend::renderer::element::solid::{SolidColorBuffer, SolidColorRenderElement};
40 use smithay::backend::renderer::element::surface::WaylandSurfaceRenderElement;39 use smithay::backend::renderer::element::surface::WaylandSurfaceRenderElement;
41 use smithay::backend::renderer::element::Id;40 use smithay::backend::renderer::element::Id;
42 use smithay::backend::renderer::gles::{GlesRenderer, GlesTexture};41 use smithay::backend::renderer::gles::{GlesRenderer, GlesTexture};
@@ -50,9 +49,10 @@ use self::workspace::{compute_working_area, Column, ColumnWidth, OutputId, Works
50 use crate::niri_render_elements;49 use crate::niri_render_elements;
51 use crate::render_helpers::renderer::NiriRenderer;50 use crate::render_helpers::renderer::NiriRenderer;
52 use crate::render_helpers::snapshot::RenderSnapshot;51 use crate::render_helpers::snapshot::RenderSnapshot;
52+use crate::render_helpers::solid_color::{SolidColorBuffer, SolidColorRenderElement};
53 use crate::render_helpers::texture::TextureBuffer;53 use crate::render_helpers::texture::TextureBuffer;
54 use crate::render_helpers::{BakedBuffer, RenderTarget, SplitElements};54 use crate::render_helpers::{BakedBuffer, RenderTarget, SplitElements};
55-use crate::utils::{output_size, ResizeEdge};55+use crate::utils::{output_size, round_logical_in_physical_max1, ResizeEdge};
56 use crate::window::ResolvedWindowRules;56 use crate::window::ResolvedWindowRules;
57 57
58 pub mod closing_window;58 pub mod closing_window;
@@ -63,7 +63,7 @@ pub mod tile;
63 pub mod workspace;63 pub mod workspace;
64 64
65 /// Size changes up to this many pixels don't animate.65 /// Size changes up to this many pixels don't animate.
66-pub const RESIZE_ANIMATION_THRESHOLD: i32 = 10;66+pub const RESIZE_ANIMATION_THRESHOLD: f64 = 10.;
67 67
68 niri_render_elements! {68 niri_render_elements! {
69 LayoutElementRenderElement<R> => {69 LayoutElementRenderElement<R> => {
@@ -110,7 +110,7 @@ pub trait LayoutElement {
110 fn render<R: NiriRenderer>(110 fn render<R: NiriRenderer>(
111 &self,111 &self,
112 renderer: &mut R,112 renderer: &mut R,
113- location: Point<i32, Logical>,113+ location: Point<f64, Logical>,
114 scale: Scale<f64>,114 scale: Scale<f64>,
115 alpha: f32,115 alpha: f32,
116 target: RenderTarget,116 target: RenderTarget,
@@ -120,7 +120,7 @@ pub trait LayoutElement {
120 fn render_normal<R: NiriRenderer>(120 fn render_normal<R: NiriRenderer>(
121 &self,121 &self,
122 renderer: &mut R,122 renderer: &mut R,
123- location: Point<i32, Logical>,123+ location: Point<f64, Logical>,
124 scale: Scale<f64>,124 scale: Scale<f64>,
125 alpha: f32,125 alpha: f32,
126 target: RenderTarget,126 target: RenderTarget,
@@ -132,7 +132,7 @@ pub trait LayoutElement {
132 fn render_popups<R: NiriRenderer>(132 fn render_popups<R: NiriRenderer>(
133 &self,133 &self,
134 renderer: &mut R,134 renderer: &mut R,
135- location: Point<i32, Logical>,135+ location: Point<f64, Logical>,
136 scale: Scale<f64>,136 scale: Scale<f64>,
137 alpha: f32,137 alpha: f32,
138 target: RenderTarget,138 target: RenderTarget,
@@ -206,10 +206,10 @@ enum MonitorSet<W: LayoutElement> {
206 },206 },
207 }207 }
208 208
209-#[derive(Debug, PartialEq)]209+#[derive(Debug, Clone, PartialEq)]
210 pub struct Options {210 pub struct Options {
211 /// Padding around windows in logical pixels.211 /// Padding around windows in logical pixels.
212- pub gaps: i32,212+ pub gaps: f64,
213 /// Extra padding around the working area in logical pixels.213 /// Extra padding around the working area in logical pixels.
214 pub struts: Struts,214 pub struts: Struts,
215 pub focus_ring: niri_config::FocusRing,215 pub focus_ring: niri_config::FocusRing,
@@ -225,7 +225,7 @@ pub struct Options {
225 impl Default for Options {225 impl Default for Options {
226 fn default() -> Self {226 fn default() -> Self {
227 Self {227 Self {
228- gaps: 16,228+ gaps: 16.,
229 struts: Default::default(),229 struts: Default::default(),
230 focus_ring: Default::default(),230 focus_ring: Default::default(),
231 border: Default::default(),231 border: Default::default(),
@@ -265,7 +265,7 @@ impl Options {
265 .unwrap_or(Some(ColumnWidth::Proportion(0.5)));265 .unwrap_or(Some(ColumnWidth::Proportion(0.5)));
266 266
267 Self {267 Self {
268- gaps: layout.gaps.into(),268+ gaps: layout.gaps.0,
269 struts: layout.struts,269 struts: layout.struts,
270 focus_ring: layout.focus_ring,270 focus_ring: layout.focus_ring,
271 border: layout.border,271 border: layout.border,
@@ -275,6 +275,16 @@ impl Options {
275 animations: config.animations.clone(),275 animations: config.animations.clone(),
276 }276 }
277 }277 }
278+
279+ fn adjusted_for_scale(mut self, scale: f64) -> Self {
280+ let round = |logical: f64| round_logical_in_physical_max1(scale, logical);
281+
282+ self.gaps = round(self.gaps);
283+ self.focus_ring.width = FloatOrInt(round(self.focus_ring.width.0));
284+ self.border.width = FloatOrInt(round(self.border.width.0));
285+
286+ self
287+ }
278 }288 }
279 289
280 impl<W: LayoutElement> Layout<W> {290 impl<W: LayoutElement> Layout<W> {
@@ -486,12 +496,12 @@ impl<W: LayoutElement> Layout<W> {
486 width: Option<ColumnWidth>,496 width: Option<ColumnWidth>,
487 is_full_width: bool,497 is_full_width: bool,
488 ) -> Option<&Output> {498 ) -> Option<&Output> {
489- let mut width = width.unwrap_or_else(|| ColumnWidth::Fixed(window.size().w));499+ let mut width = width.unwrap_or_else(|| ColumnWidth::Fixed(f64::from(window.size().w)));
490 if let ColumnWidth::Fixed(w) = &mut width {500 if let ColumnWidth::Fixed(w) = &mut width {
491 let rules = window.rules();501 let rules = window.rules();
492 let border_config = rules.border.resolve_against(self.options.border);502 let border_config = rules.border.resolve_against(self.options.border);
493 if !border_config.off {503 if !border_config.off {
494- *w += border_config.width as i32 * 2;504+ *w += border_config.width.0 * 2.;
495 }505 }
496 }506 }
497 507
@@ -575,12 +585,12 @@ impl<W: LayoutElement> Layout<W> {
575 width: Option<ColumnWidth>,585 width: Option<ColumnWidth>,
576 is_full_width: bool,586 is_full_width: bool,
577 ) -> Option<&Output> {587 ) -> Option<&Output> {
578- let mut width = width.unwrap_or_else(|| ColumnWidth::Fixed(window.size().w));588+ let mut width = width.unwrap_or_else(|| ColumnWidth::Fixed(f64::from(window.size().w)));
579 if let ColumnWidth::Fixed(w) = &mut width {589 if let ColumnWidth::Fixed(w) = &mut width {
580 let rules = window.rules();590 let rules = window.rules();
581 let border_config = rules.border.resolve_against(self.options.border);591 let border_config = rules.border.resolve_against(self.options.border);
582 if !border_config.off {592 if !border_config.off {
583- *w += border_config.width as i32 * 2;593+ *w += border_config.width.0 * 2.;
584 }594 }
585 }595 }
586 596
@@ -633,12 +643,12 @@ impl<W: LayoutElement> Layout<W> {
633 width: Option<ColumnWidth>,643 width: Option<ColumnWidth>,
634 is_full_width: bool,644 is_full_width: bool,
635 ) -> Option<&Output> {645 ) -> Option<&Output> {
636- let mut width = width.unwrap_or_else(|| ColumnWidth::Fixed(window.size().w));646+ let mut width = width.unwrap_or_else(|| ColumnWidth::Fixed(f64::from(window.size().w)));
637 if let ColumnWidth::Fixed(w) = &mut width {647 if let ColumnWidth::Fixed(w) = &mut width {
638 let rules = window.rules();648 let rules = window.rules();
639 let border_config = rules.border.resolve_against(self.options.border);649 let border_config = rules.border.resolve_against(self.options.border);
640 if !border_config.off {650 if !border_config.off {
641- *w += border_config.width as i32 * 2;651+ *w += border_config.width.0 * 2.;
642 }652 }
643 }653 }
644 654
@@ -671,12 +681,12 @@ impl<W: LayoutElement> Layout<W> {
671 width: Option<ColumnWidth>,681 width: Option<ColumnWidth>,
672 is_full_width: bool,682 is_full_width: bool,
673 ) {683 ) {
674- let mut width = width.unwrap_or_else(|| ColumnWidth::Fixed(window.size().w));684+ let mut width = width.unwrap_or_else(|| ColumnWidth::Fixed(f64::from(window.size().w)));
675 if let ColumnWidth::Fixed(w) = &mut width {685 if let ColumnWidth::Fixed(w) = &mut width {
676 let rules = window.rules();686 let rules = window.rules();
677 let border_config = rules.border.resolve_against(self.options.border);687 let border_config = rules.border.resolve_against(self.options.border);
678 if !border_config.off {688 if !border_config.off {
679- *w += border_config.width as i32 * 2;689+ *w += border_config.width.0 * 2.;
680 }690 }
681 }691 }
682 692
@@ -887,7 +897,7 @@ impl<W: LayoutElement> Layout<W> {
887 None897 None
888 }898 }
889 899
890- pub fn window_loc(&self, window: &W::Id) -> Option<Point<i32, Logical>> {900+ pub fn window_loc(&self, window: &W::Id) -> Option<Point<f64, Logical>> {
891 match &self.monitor_set {901 match &self.monitor_set {
892 MonitorSet::Normal { monitors, .. } => {902 MonitorSet::Normal { monitors, .. } => {
893 for mon in monitors {903 for mon in monitors {
@@ -1440,7 +1450,7 @@ impl<W: LayoutElement> Layout<W> {
1440 &self,1450 &self,
1441 output: &Output,1451 output: &Output,
1442 pos_within_output: Point<f64, Logical>,1452 pos_within_output: Point<f64, Logical>,
1443- ) -> Option<(&W, Option<Point<i32, Logical>>)> {1453+ ) -> Option<(&W, Option<Point<f64, Logical>>)> {
1444 let MonitorSet::Normal { monitors, .. } = &self.monitor_set else {1454 let MonitorSet::Normal { monitors, .. } = &self.monitor_set else {
1445 return None;1455 return None;
1446 };1456 };
@@ -1485,8 +1495,15 @@ impl<W: LayoutElement> Layout<W> {
1485 );1495 );
1486 1496
1487 assert_eq!(1497 assert_eq!(
1488- workspace.options, self.options,1498+ workspace.base_options, self.options,
1489- "workspace options must be synchronized with layout"1499+ "workspace base options must be synchronized with layout"
1500+ );
1501+
1502+ let options = Options::clone(&workspace.base_options)
1503+ .adjusted_for_scale(workspace.scale().fractional_scale());
1504+ assert_eq!(
1505+ &*workspace.options, &options,
1506+ "workspace options must be base options adjusted for workspace scale"
1490 );1507 );
1491 1508
1492 assert!(1509 assert!(
@@ -1589,10 +1606,17 @@ impl<W: LayoutElement> Layout<W> {
1589 1606
1590 for workspace in &monitor.workspaces {1607 for workspace in &monitor.workspaces {
1591 assert_eq!(1608 assert_eq!(
1592- workspace.options, self.options,1609+ workspace.base_options, self.options,
1593 "workspace options must be synchronized with layout"1610 "workspace options must be synchronized with layout"
1594 );1611 );
1595 1612
1613+ let options = Options::clone(&workspace.base_options)
1614+ .adjusted_for_scale(workspace.scale().fractional_scale());
1615+ assert_eq!(
1616+ &*workspace.options, &options,
1617+ "workspace options must be base options adjusted for workspace scale"
1618+ );
1619+
1596 assert!(1620 assert!(
1597 seen_workspace_id.insert(workspace.id()),1621 seen_workspace_id.insert(workspace.id()),
1598 "workspace id must be unique"1622 "workspace id must be unique"
@@ -2368,13 +2392,14 @@ impl<W: LayoutElement> Default for MonitorSet<W> {
2368 mod tests {2392 mod tests {
2369 use std::cell::Cell;2393 use std::cell::Cell;
2370 2394
2371- use niri_config::WorkspaceName;2395+ use niri_config::{FloatOrInt, WorkspaceName};
2372 use proptest::prelude::*;2396 use proptest::prelude::*;
2373 use proptest_derive::Arbitrary;2397 use proptest_derive::Arbitrary;
2374 use smithay::output::{Mode, PhysicalProperties, Subpixel};2398 use smithay::output::{Mode, PhysicalProperties, Subpixel};
2375 use smithay::utils::Rectangle;2399 use smithay::utils::Rectangle;
2376 2400
2377 use super::*;2401 use super::*;
2402+ use crate::utils::round_logical_in_physical;
2378 2403
2379 impl<W: LayoutElement> Default for Layout<W> {2404 impl<W: LayoutElement> Default for Layout<W> {
2380 fn default() -> Self {2405 fn default() -> Self {
@@ -2459,7 +2484,7 @@ mod tests {
2459 fn render<R: NiriRenderer>(2484 fn render<R: NiriRenderer>(
2460 &self,2485 &self,
2461 _renderer: &mut R,2486 _renderer: &mut R,
2462- _location: Point<i32, Logical>,2487+ _location: Point<f64, Logical>,
2463 _scale: Scale<f64>,2488 _scale: Scale<f64>,
2464 _alpha: f32,2489 _alpha: f32,
2465 _target: RenderTarget,2490 _target: RenderTarget,
@@ -2595,9 +2620,19 @@ mod tests {
2595 ]2620 ]
2596 }2621 }
2597 2622
2623+ fn arbitrary_scale() -> impl Strategy<Value = f64> {
2624+ prop_oneof![Just(1.), Just(1.5), Just(2.),]
2625+ }
2626+
2598 #[derive(Debug, Clone, Copy, Arbitrary)]2627 #[derive(Debug, Clone, Copy, Arbitrary)]
2599 enum Op {2628 enum Op {
2600 AddOutput(#[proptest(strategy = "1..=5usize")] usize),2629 AddOutput(#[proptest(strategy = "1..=5usize")] usize),
2630+ AddScaledOutput {
2631+ #[proptest(strategy = "1..=5usize")]
2632+ id: usize,
2633+ #[proptest(strategy = "arbitrary_scale()")]
2634+ scale: f64,
2635+ },
2601 RemoveOutput(#[proptest(strategy = "1..=5usize")] usize),2636 RemoveOutput(#[proptest(strategy = "1..=5usize")] usize),
2602 FocusOutput(#[proptest(strategy = "1..=5usize")] usize),2637 FocusOutput(#[proptest(strategy = "1..=5usize")] usize),
2603 AddNamedWorkspace {2638 AddNamedWorkspace {
@@ -2769,6 +2804,32 @@ mod tests {
2769 );2804 );
2770 layout.add_output(output.clone());2805 layout.add_output(output.clone());
2771 }2806 }
2807+ Op::AddScaledOutput { id, scale } => {
2808+ let name = format!("output{id}");
2809+ if layout.outputs().any(|o| o.name() == name) {
2810+ return;
2811+ }
2812+
2813+ let output = Output::new(
2814+ name,
2815+ PhysicalProperties {
2816+ size: Size::from((1280, 720)),
2817+ subpixel: Subpixel::Unknown,
2818+ make: String::new(),
2819+ model: String::new(),
2820+ },
2821+ );
2822+ output.change_current_state(
2823+ Some(Mode {
2824+ size: Size::from((1280, 720)),
2825+ refresh: 60000,
2826+ }),
2827+ None,
2828+ Some(smithay::output::Scale::Fractional(scale)),
2829+ None,
2830+ );
2831+ layout.add_output(output.clone());
2832+ }
2772 Op::RemoveOutput(id) => {2833 Op::RemoveOutput(id) => {
2773 let name = format!("output{id}");2834 let name = format!("output{id}");
2774 let Some(output) = layout.outputs().find(|o| o.name() == name).cloned() else {2835 let Some(output) = layout.outputs().find(|o| o.name() == name).cloned() else {
@@ -3560,7 +3621,7 @@ mod tests {
3560 3621
3561 let mut options = Options::default();3622 let mut options = Options::default();
3562 options.border.off = false;3623 options.border.off = false;
3563- options.border.width = 1;3624+ options.border.width = FloatOrInt(1.);
3564 3625
3565 check_ops_with_options(options, &ops);3626 check_ops_with_options(options, &ops);
3566 }3627 }
@@ -3578,7 +3639,7 @@ mod tests {
3578 3639
3579 let mut options = Options::default();3640 let mut options = Options::default();
3580 options.border.off = false;3641 options.border.off = false;
3581- options.border.width = 1;3642+ options.border.width = FloatOrInt(1.);
3582 3643
3583 check_ops_with_options(options, &ops);3644 check_ops_with_options(options, &ops);
3584 }3645 }
@@ -3916,7 +3977,7 @@ mod tests {
3916 fn config_change_updates_cached_sizes() {3977 fn config_change_updates_cached_sizes() {
3917 let mut config = Config::default();3978 let mut config = Config::default();
3918 config.layout.border.off = false;3979 config.layout.border.off = false;
3919- config.layout.border.width = 2;3980+ config.layout.border.width = FloatOrInt(2.);
3920 3981
3921 let mut layout = Layout::new(&config);3982 let mut layout = Layout::new(&config);
3922 3983
@@ -3927,18 +3988,83 @@ mod tests {
3927 }3988 }
3928 .apply(&mut layout);3989 .apply(&mut layout);
3929 3990
3930- config.layout.border.width = 4;3991+ config.layout.border.width = FloatOrInt(4.);
3931 layout.update_config(&config);3992 layout.update_config(&config);
3932 3993
3933 layout.verify_invariants();3994 layout.verify_invariants();
3934 }3995 }
3935 3996
3936- fn arbitrary_spacing() -> impl Strategy<Value = u16> {3997+ #[test]
3998+ fn working_area_starts_at_physical_pixel() {
3999+ let struts = Struts {
4000+ left: FloatOrInt(0.5),
4001+ right: FloatOrInt(1.),
4002+ top: FloatOrInt(0.75),
4003+ bottom: FloatOrInt(1.),
4004+ };
4005+
4006+ let output = Output::new(
4007+ String::from("output"),
4008+ PhysicalProperties {
4009+ size: Size::from((1280, 720)),
4010+ subpixel: Subpixel::Unknown,
4011+ make: String::new(),
4012+ model: String::new(),
4013+ },
4014+ );
4015+ output.change_current_state(
4016+ Some(Mode {
4017+ size: Size::from((1280, 720)),
4018+ refresh: 60000,
4019+ }),
4020+ None,
4021+ None,
4022+ None,
4023+ );
4024+
4025+ let area = compute_working_area(&output, struts);
4026+
4027+ assert_eq!(round_logical_in_physical(1., area.loc.x), area.loc.x);
4028+ assert_eq!(round_logical_in_physical(1., area.loc.y), area.loc.y);
4029+ }
4030+
4031+ #[test]
4032+ fn large_fractional_strut() {
4033+ let struts = Struts {
4034+ left: FloatOrInt(0.),
4035+ right: FloatOrInt(0.),
4036+ top: FloatOrInt(50000.5),
4037+ bottom: FloatOrInt(0.),
4038+ };
4039+
4040+ let output = Output::new(
4041+ String::from("output"),
4042+ PhysicalProperties {
4043+ size: Size::from((1280, 720)),
4044+ subpixel: Subpixel::Unknown,
4045+ make: String::new(),
4046+ model: String::new(),
4047+ },
4048+ );
4049+ output.change_current_state(
4050+ Some(Mode {
4051+ size: Size::from((1280, 720)),
4052+ refresh: 60000,
4053+ }),
4054+ None,
4055+ None,
4056+ None,
4057+ );
4058+
4059+ compute_working_area(&output, struts);
4060+ }
4061+
4062+ fn arbitrary_spacing() -> impl Strategy<Value = f64> {
3937 // Give equal weight to:4063 // Give equal weight to:
3938 // - 0: the element is disabled4064 // - 0: the element is disabled
3939 // - 4: some reasonable value4065 // - 4: some reasonable value
3940 // - random value, likely unreasonably big4066 // - random value, likely unreasonably big
3941- prop_oneof![Just(0), Just(4), (1..=u16::MAX)]4067+ prop_oneof![Just(0.), Just(4.), ((1.)..=65535.)]
3942 }4068 }
3943 4069
3944 fn arbitrary_struts() -> impl Strategy<Value = Struts> {4070 fn arbitrary_struts() -> impl Strategy<Value = Struts> {
@@ -3949,10 +4075,10 @@ mod tests {
3949 arbitrary_spacing(),4075 arbitrary_spacing(),
3950 )4076 )
3951 .prop_map(|(left, right, top, bottom)| Struts {4077 .prop_map(|(left, right, top, bottom)| Struts {
3952- left,4078+ left: FloatOrInt(left),
3953- right,4079+ right: FloatOrInt(right),
3954- top,4080+ top: FloatOrInt(top),
3955- bottom,4081+ bottom: FloatOrInt(bottom),
3956 })4082 })
3957 }4083 }
3958 4084
@@ -3971,7 +4097,7 @@ mod tests {
3971 ) -> niri_config::FocusRing {4097 ) -> niri_config::FocusRing {
3972 niri_config::FocusRing {4098 niri_config::FocusRing {
3973 off,4099 off,
3974- width,4100+ width: FloatOrInt(width),
3975 ..Default::default()4101 ..Default::default()
3976 }4102 }
3977 }4103 }
@@ -3984,7 +4110,7 @@ mod tests {
3984 ) -> niri_config::Border {4110 ) -> niri_config::Border {
3985 niri_config::Border {4111 niri_config::Border {
3986 off,4112 off,
3987- width,4113+ width: FloatOrInt(width),
3988 ..Default::default()4114 ..Default::default()
3989 }4115 }
3990 }4116 }
@@ -3999,7 +4125,7 @@ mod tests {
3999 center_focused_column in arbitrary_center_focused_column(),4125 center_focused_column in arbitrary_center_focused_column(),
4000 ) -> Options {4126 ) -> Options {
4001 Options {4127 Options {
4002- gaps: gaps.into(),4128+ gaps,
4003 struts,4129 struts,
4004 center_focused_column,4130 center_focused_column,
4005 focus_ring,4131 focus_ring,
src/layout/monitor.rsmodified+27 -29
@@ -7,7 +7,7 @@ use smithay::backend::renderer::element::utils::{
7 CropRenderElement, Relocate, RelocateRenderElement,7 CropRenderElement, Relocate, RelocateRenderElement,
8 };8 };
9 use smithay::output::Output;9 use smithay::output::Output;
10-use smithay::utils::{Logical, Point, Rectangle, Scale};10+use smithay::utils::{Logical, Point, Rectangle};
11 11
12 use super::workspace::{12 use super::workspace::{
13 compute_working_area, Column, ColumnWidth, OutputId, Workspace, WorkspaceId,13 compute_working_area, Column, ColumnWidth, OutputId, Workspace, WorkspaceId,
@@ -19,7 +19,7 @@ use crate::input::swipe_tracker::SwipeTracker;
19 use crate::render_helpers::renderer::NiriRenderer;19 use crate::render_helpers::renderer::NiriRenderer;
20 use crate::render_helpers::RenderTarget;20 use crate::render_helpers::RenderTarget;
21 use crate::rubber_band::RubberBand;21 use crate::rubber_band::RubberBand;
22-use crate::utils::{output_size, ResizeEdge};22+use crate::utils::{output_size, to_physical_precise_round, ResizeEdge};
23 23
24 /// Amount of touchpad movement to scroll the height of one workspace.24 /// Amount of touchpad movement to scroll the height of one workspace.
25 const WORKSPACE_GESTURE_MOVEMENT: f64 = 300.;25 const WORKSPACE_GESTURE_MOVEMENT: f64 = 300.;
@@ -761,16 +761,16 @@ impl<W: LayoutElement> Monitor<W> {
761 /// Returns the geometry of the active tile relative to and clamped to the output.761 /// Returns the geometry of the active tile relative to and clamped to the output.
762 ///762 ///
763 /// During animations, assumes the final view position.763 /// During animations, assumes the final view position.
764- pub fn active_tile_visual_rectangle(&self) -> Option<Rectangle<i32, Logical>> {764+ pub fn active_tile_visual_rectangle(&self) -> Option<Rectangle<f64, Logical>> {
765 let mut rect = self.active_workspace_ref().active_tile_visual_rectangle()?;765 let mut rect = self.active_workspace_ref().active_tile_visual_rectangle()?;
766 766
767 if let Some(switch) = &self.workspace_switch {767 if let Some(switch) = &self.workspace_switch {
768- let size = output_size(&self.output);768+ let size = output_size(&self.output).to_f64();
769 769
770 let offset = switch.target_idx() - self.active_workspace_idx as f64;770 let offset = switch.target_idx() - self.active_workspace_idx as f64;
771- let offset = (offset * size.h as f64).round() as i32;771+ let offset = offset * size.h;
772 772
773- let clip_rect = Rectangle::from_loc_and_size((0, -offset), size);773+ let clip_rect = Rectangle::from_loc_and_size((0., -offset), size);
774 rect = rect.intersection(clip_rect)?;774 rect = rect.intersection(clip_rect)?;
775 }775 }
776 776
@@ -780,16 +780,16 @@ impl<W: LayoutElement> Monitor<W> {
780 pub fn window_under(780 pub fn window_under(
781 &self,781 &self,
782 pos_within_output: Point<f64, Logical>,782 pos_within_output: Point<f64, Logical>,
783- ) -> Option<(&W, Option<Point<i32, Logical>>)> {783+ ) -> Option<(&W, Option<Point<f64, Logical>>)> {
784 match &self.workspace_switch {784 match &self.workspace_switch {
785 Some(switch) => {785 Some(switch) => {
786- let size = output_size(&self.output);786+ let size = output_size(&self.output).to_f64();
787 787
788 let render_idx = switch.current_idx();788 let render_idx = switch.current_idx();
789 let before_idx = render_idx.floor();789 let before_idx = render_idx.floor();
790 let after_idx = render_idx.ceil();790 let after_idx = render_idx.ceil();
791 791
792- let offset = ((render_idx - before_idx) * size.h as f64).round() as i32;792+ let offset = (render_idx - before_idx) * size.h;
793 793
794 if after_idx < 0. || before_idx as usize >= self.workspaces.len() {794 if after_idx < 0. || before_idx as usize >= self.workspaces.len() {
795 return None;795 return None;
@@ -797,22 +797,22 @@ impl<W: LayoutElement> Monitor<W> {
797 797
798 let after_idx = after_idx as usize;798 let after_idx = after_idx as usize;
799 799
800- let (idx, ws_offset) = if pos_within_output.y < (size.h - offset) as f64 {800+ let (idx, ws_offset) = if pos_within_output.y < size.h - offset {
801 if before_idx < 0. {801 if before_idx < 0. {
802 return None;802 return None;
803 }803 }
804 804
805- (before_idx as usize, Point::from((0, offset)))805+ (before_idx as usize, Point::from((0., offset)))
806 } else {806 } else {
807 if after_idx >= self.workspaces.len() {807 if after_idx >= self.workspaces.len() {
808 return None;808 return None;
809 }809 }
810 810
811- (after_idx, Point::from((0, -size.h + offset)))811+ (after_idx, Point::from((0., -size.h + offset)))
812 };812 };
813 813
814 let ws = &self.workspaces[idx];814 let ws = &self.workspaces[idx];
815- let (win, win_pos) = ws.window_under(pos_within_output + ws_offset.to_f64())?;815+ let (win, win_pos) = ws.window_under(pos_within_output + ws_offset)?;
816 Some((win, win_pos.map(|p| p - ws_offset)))816 Some((win, win_pos.map(|p| p - ws_offset)))
817 }817 }
818 None => {818 None => {
@@ -831,7 +831,7 @@ impl<W: LayoutElement> Monitor<W> {
831 let before_idx = render_idx.floor();831 let before_idx = render_idx.floor();
832 let after_idx = render_idx.ceil();832 let after_idx = render_idx.ceil();
833 833
834- let offset = ((render_idx - before_idx) * size.h as f64).round() as i32;834+ let offset = (render_idx - before_idx) * size.h;
835 835
836 if after_idx < 0. || before_idx as usize >= self.workspaces.len() {836 if after_idx < 0. || before_idx as usize >= self.workspaces.len() {
837 return None;837 return None;
@@ -839,22 +839,22 @@ impl<W: LayoutElement> Monitor<W> {
839 839
840 let after_idx = after_idx as usize;840 let after_idx = after_idx as usize;
841 841
842- let (idx, ws_offset) = if pos_within_output.y < (size.h - offset) as f64 {842+ let (idx, ws_offset) = if pos_within_output.y < size.h - offset {
843 if before_idx < 0. {843 if before_idx < 0. {
844 return None;844 return None;
845 }845 }
846 846
847- (before_idx as usize, Point::from((0, offset)))847+ (before_idx as usize, Point::from((0., offset)))
848 } else {848 } else {
849 if after_idx >= self.workspaces.len() {849 if after_idx >= self.workspaces.len() {
850 return None;850 return None;
851 }851 }
852 852
853- (after_idx, Point::from((0, -size.h + offset)))853+ (after_idx, Point::from((0., -size.h + offset)))
854 };854 };
855 855
856 let ws = &self.workspaces[idx];856 let ws = &self.workspaces[idx];
857- ws.resize_edges_under(pos_within_output + ws_offset.to_f64())857+ ws.resize_edges_under(pos_within_output + ws_offset)
858 }858 }
859 None => {859 None => {
860 let ws = &self.workspaces[self.active_workspace_idx];860 let ws = &self.workspaces[self.active_workspace_idx];
@@ -880,10 +880,8 @@ impl<W: LayoutElement> Monitor<W> {
880 ) -> Vec<MonitorRenderElement<R>> {880 ) -> Vec<MonitorRenderElement<R>> {
881 let _span = tracy_client::span!("Monitor::render_elements");881 let _span = tracy_client::span!("Monitor::render_elements");
882 882
883- let output_scale = Scale::from(self.output.current_scale().fractional_scale());883+ let scale = self.output.current_scale().fractional_scale();
884- let output_transform = self.output.current_transform();884+ let size = output_size(&self.output);
885- let output_mode = self.output.current_mode().unwrap();
886- let size = output_transform.transform_size(output_mode.size);
887 885
888 match &self.workspace_switch {886 match &self.workspace_switch {
889 Some(switch) => {887 Some(switch) => {
@@ -891,7 +889,7 @@ impl<W: LayoutElement> Monitor<W> {
891 let before_idx = render_idx.floor();889 let before_idx = render_idx.floor();
892 let after_idx = render_idx.ceil();890 let after_idx = render_idx.ceil();
893 891
894- let offset = ((render_idx - before_idx) * size.h as f64).round() as i32;892+ let offset = (render_idx - before_idx) * size.h;
895 893
896 if after_idx < 0. || before_idx as usize >= self.workspaces.len() {894 if after_idx < 0. || before_idx as usize >= self.workspaces.len() {
897 return vec![];895 return vec![];
@@ -904,7 +902,7 @@ impl<W: LayoutElement> Monitor<W> {
904 Some(RelocateRenderElement::from_element(902 Some(RelocateRenderElement::from_element(
905 CropRenderElement::from_element(903 CropRenderElement::from_element(
906 elem,904 elem,
907- output_scale,905+ scale,
908 // HACK: crop to infinite bounds for all sides except the side906 // HACK: crop to infinite bounds for all sides except the side
909 // where the workspaces join,907 // where the workspaces join,
910 // otherwise it will cut pixel shaders and mess up908 // otherwise it will cut pixel shaders and mess up
@@ -914,7 +912,7 @@ impl<W: LayoutElement> Monitor<W> {
914 (i32::MAX / 2, i32::MAX / 2),912 (i32::MAX / 2, i32::MAX / 2),
915 ),913 ),
916 )?,914 )?,
917- (0, -offset + size.h),915+ Point::from((0., -offset + size.h)).to_physical_precise_round(scale),
918 Relocate::Relative,916 Relocate::Relative,
919 ))917 ))
920 });918 });
@@ -934,13 +932,13 @@ impl<W: LayoutElement> Monitor<W> {
934 Some(RelocateRenderElement::from_element(932 Some(RelocateRenderElement::from_element(
935 CropRenderElement::from_element(933 CropRenderElement::from_element(
936 elem,934 elem,
937- output_scale,935+ scale,
938 Rectangle::from_extemities(936 Rectangle::from_extemities(
939 (-i32::MAX / 2, -i32::MAX / 2),937 (-i32::MAX / 2, -i32::MAX / 2),
940- (i32::MAX / 2, size.h),938+ (i32::MAX / 2, to_physical_precise_round(scale, size.h)),
941 ),939 ),
942 )?,940 )?,
943- (0, -offset),941+ Point::from((0., -offset)).to_physical_precise_round(scale),
944 Relocate::Relative,942 Relocate::Relative,
945 ))943 ))
946 });944 });
@@ -955,7 +953,7 @@ impl<W: LayoutElement> Monitor<W> {
955 Some(RelocateRenderElement::from_element(953 Some(RelocateRenderElement::from_element(
956 CropRenderElement::from_element(954 CropRenderElement::from_element(
957 elem,955 elem,
958- output_scale,956+ scale,
959 // HACK: set infinite crop bounds due to a damage tracking bug957 // HACK: set infinite crop bounds due to a damage tracking bug
960 // which causes glitched rendering for maximized GTK windows.958 // which causes glitched rendering for maximized GTK windows.
961 // FIXME: use proper bounds after fixing the Crop element.959 // FIXME: use proper bounds after fixing the Crop element.
src/layout/opening_window.rsmodified+9 -9
@@ -55,8 +55,8 @@ impl OpenAnimation {
55 &self,55 &self,
56 renderer: &mut GlesRenderer,56 renderer: &mut GlesRenderer,
57 elements: &[impl RenderElement<GlesRenderer>],57 elements: &[impl RenderElement<GlesRenderer>],
58- geo_size: Size<i32, Logical>,58+ geo_size: Size<f64, Logical>,
59- location: Point<i32, Logical>,59+ location: Point<f64, Logical>,
60 scale: Scale<f64>,60 scale: Scale<f64>,
61 ) -> anyhow::Result<OpeningWindowRenderElement> {61 ) -> anyhow::Result<OpeningWindowRenderElement> {
62 let progress = self.anim.value();62 let progress = self.anim.value();
@@ -75,17 +75,17 @@ impl OpenAnimation {
75 let texture_size = geo.size.to_f64().to_logical(scale);75 let texture_size = geo.size.to_f64().to_logical(scale);
76 76
77 if Shaders::get(renderer).program(ProgramType::Open).is_some() {77 if Shaders::get(renderer).program(ProgramType::Open).is_some() {
78- let mut area = Rectangle::from_loc_and_size(location.to_f64() + offset, texture_size);78+ let mut area = Rectangle::from_loc_and_size(location + offset, texture_size);
79 79
80 // Expand the area a bit to allow for more varied effects.80 // Expand the area a bit to allow for more varied effects.
81 let mut target_size = area.size.upscale(1.5);81 let mut target_size = area.size.upscale(1.5);
82 target_size.w = f64::max(area.size.w + 1000., target_size.w);82 target_size.w = f64::max(area.size.w + 1000., target_size.w);
83 target_size.h = f64::max(area.size.h + 1000., target_size.h);83 target_size.h = f64::max(area.size.h + 1000., target_size.h);
84- let diff = target_size.to_point() - area.size.to_point();84+ let diff = (target_size.to_point() - area.size.to_point()).downscale(2.);
85- area.loc -= diff.downscale(2.);85+ let diff = diff.to_physical_precise_round(scale).to_logical(scale);
86- area.size += diff.to_size();86+ area.loc -= diff;
87+ area.size += diff.upscale(2.).to_size();
87 88
88- let area = area.to_i32_up();
89 let area_loc = Vec2::new(area.loc.x as f32, area.loc.y as f32);89 let area_loc = Vec2::new(area.loc.x as f32, area.loc.y as f32);
90 let area_size = Vec2::new(area.size.w as f32, area.size.h as f32);90 let area_size = Vec2::new(area.size.w as f32, area.size.h as f32);
91 91
@@ -135,7 +135,7 @@ impl OpenAnimation {
135 135
136 let elem = PrimaryGpuTextureRenderElement(elem);136 let elem = PrimaryGpuTextureRenderElement(elem);
137 137
138- let center = geo_size.to_point().to_f64().downscale(2.);138+ let center = geo_size.to_point().downscale(2.);
139 let elem = RescaleRenderElement::from_element(139 let elem = RescaleRenderElement::from_element(
140 elem,140 elem,
141 (center - offset).to_physical_precise_round(scale),141 (center - offset).to_physical_precise_round(scale),
@@ -144,7 +144,7 @@ impl OpenAnimation {
144 144
145 let elem = RelocateRenderElement::from_element(145 let elem = RelocateRenderElement::from_element(
146 elem,146 elem,
147- (location.to_f64() + offset).to_physical_precise_round(scale),147+ (location + offset).to_physical_precise_round(scale),
148 Relocate::Relative,148 Relocate::Relative,
149 );149 );
150 150
src/layout/tile.rsmodified+123 -98
@@ -1,10 +1,8 @@
1-use std::cmp::max;
2 use std::rc::Rc;1 use std::rc::Rc;
3 use std::time::Duration;2 use std::time::Duration;
4 3
5 use niri_config::CornerRadius;4 use niri_config::CornerRadius;
6 use smithay::backend::allocator::Fourcc;5 use smithay::backend::allocator::Fourcc;
7-use smithay::backend::renderer::element::solid::{SolidColorBuffer, SolidColorRenderElement};
8 use smithay::backend::renderer::element::{Element, Kind};6 use smithay::backend::renderer::element::{Element, Kind};
9 use smithay::backend::renderer::gles::GlesRenderer;7 use smithay::backend::renderer::gles::GlesRenderer;
10 use smithay::utils::{Logical, Point, Rectangle, Scale, Size, Transform};8 use smithay::utils::{Logical, Point, Rectangle, Scale, Size, Transform};
@@ -23,6 +21,7 @@ use crate::render_helpers::damage::ExtraDamage;
23 use crate::render_helpers::renderer::NiriRenderer;21 use crate::render_helpers::renderer::NiriRenderer;
24 use crate::render_helpers::resize::ResizeRenderElement;22 use crate::render_helpers::resize::ResizeRenderElement;
25 use crate::render_helpers::snapshot::RenderSnapshot;23 use crate::render_helpers::snapshot::RenderSnapshot;
24+use crate::render_helpers::solid_color::{SolidColorBuffer, SolidColorRenderElement};
26 use crate::render_helpers::{render_to_encompassing_texture, RenderTarget};25 use crate::render_helpers::{render_to_encompassing_texture, RenderTarget};
27 26
28 /// Toplevel window with decorations.27 /// Toplevel window with decorations.
@@ -50,7 +49,7 @@ pub struct Tile<W: LayoutElement> {
50 fullscreen_backdrop: SolidColorBuffer,49 fullscreen_backdrop: SolidColorBuffer,
51 50
52 /// The size we were requested to fullscreen into.51 /// The size we were requested to fullscreen into.
53- fullscreen_size: Size<i32, Logical>,52+ fullscreen_size: Size<f64, Logical>,
54 53
55 /// The animation upon opening a window.54 /// The animation upon opening a window.
56 open_animation: Option<OpenAnimation>,55 open_animation: Option<OpenAnimation>,
@@ -70,6 +69,9 @@ pub struct Tile<W: LayoutElement> {
70 /// Extra damage for clipped surface corner radius changes.69 /// Extra damage for clipped surface corner radius changes.
71 rounded_corner_damage: RoundedCornerDamage,70 rounded_corner_damage: RoundedCornerDamage,
72 71
72+ /// Scale of the output the tile is on (and rounds its sizes to).
73+ scale: f64,
74+
73 /// Configurable properties of the layout.75 /// Configurable properties of the layout.
74 pub options: Rc<Options>,76 pub options: Rc<Options>,
75 }77 }
@@ -93,18 +95,18 @@ type TileRenderSnapshot =
93 #[derive(Debug)]95 #[derive(Debug)]
94 struct ResizeAnimation {96 struct ResizeAnimation {
95 anim: Animation,97 anim: Animation,
96- size_from: Size<i32, Logical>,98+ size_from: Size<f64, Logical>,
97 snapshot: LayoutElementRenderSnapshot,99 snapshot: LayoutElementRenderSnapshot,
98 }100 }
99 101
100 #[derive(Debug)]102 #[derive(Debug)]
101 struct MoveAnimation {103 struct MoveAnimation {
102 anim: Animation,104 anim: Animation,
103- from: i32,105+ from: f64,
104 }106 }
105 107
106 impl<W: LayoutElement> Tile<W> {108 impl<W: LayoutElement> Tile<W> {
107- pub fn new(window: W, options: Rc<Options>) -> Self {109+ pub fn new(window: W, scale: f64, options: Rc<Options>) -> Self {
108 let rules = window.rules();110 let rules = window.rules();
109 let border_config = rules.border.resolve_against(options.border);111 let border_config = rules.border.resolve_against(options.border);
110 let focus_ring_config = rules.focus_ring.resolve_against(options.focus_ring.into());112 let focus_ring_config = rules.focus_ring.resolve_against(options.focus_ring.into());
@@ -114,7 +116,7 @@ impl<W: LayoutElement> Tile<W> {
114 border: FocusRing::new(border_config.into()),116 border: FocusRing::new(border_config.into()),
115 focus_ring: FocusRing::new(focus_ring_config.into()),117 focus_ring: FocusRing::new(focus_ring_config.into()),
116 is_fullscreen: false, // FIXME: up-to-date fullscreen right away, but we need size.118 is_fullscreen: false, // FIXME: up-to-date fullscreen right away, but we need size.
117- fullscreen_backdrop: SolidColorBuffer::new((0, 0), [0., 0., 0., 1.]),119+ fullscreen_backdrop: SolidColorBuffer::new((0., 0.), [0., 0., 0., 1.]),
118 fullscreen_size: Default::default(),120 fullscreen_size: Default::default(),
119 open_animation: None,121 open_animation: None,
120 resize_animation: None,122 resize_animation: None,
@@ -122,11 +124,13 @@ impl<W: LayoutElement> Tile<W> {
122 move_y_animation: None,124 move_y_animation: None,
123 unmap_snapshot: None,125 unmap_snapshot: None,
124 rounded_corner_damage: Default::default(),126 rounded_corner_damage: Default::default(),
127+ scale,
125 options,128 options,
126 }129 }
127 }130 }
128 131
129- pub fn update_config(&mut self, options: Rc<Options>) {132+ pub fn update_config(&mut self, scale: f64, options: Rc<Options>) {
133+ self.scale = scale;
130 self.options = options;134 self.options = options;
131 135
132 let rules = self.window.rules();136 let rules = self.window.rules();
@@ -147,7 +151,7 @@ impl<W: LayoutElement> Tile<W> {
147 151
148 pub fn update_window(&mut self) {152 pub fn update_window(&mut self) {
149 // FIXME: remove when we can get a fullscreen size right away.153 // FIXME: remove when we can get a fullscreen size right away.
150- if self.fullscreen_size != Size::from((0, 0)) {154+ if self.fullscreen_size != Size::from((0., 0.)) {
151 self.is_fullscreen = self.window.is_fullscreen();155 self.is_fullscreen = self.window.is_fullscreen();
152 }156 }
153 157
@@ -160,16 +164,16 @@ impl<W: LayoutElement> Tile<W> {
160 let val = resize.anim.value();164 let val = resize.anim.value();
161 let size_from = resize.size_from;165 let size_from = resize.size_from;
162 166
163- size.w = (size_from.w as f64 + (size.w - size_from.w) as f64 * val).round() as i32;167+ size.w = size_from.w + (size.w - size_from.w) * val;
164- size.h = (size_from.h as f64 + (size.h - size_from.h) as f64 * val).round() as i32;168+ size.h = size_from.h + (size.h - size_from.h) * val;
165 169
166 size170 size
167 } else {171 } else {
168 animate_from.size172 animate_from.size
169 };173 };
170 174
171- let change = self.window.size().to_point() - size_from.to_point();175+ let change = self.window.size().to_f64().to_point() - size_from.to_point();
172- let change = max(change.x.abs(), change.y.abs());176+ let change = f64::max(change.x.abs(), change.y.abs());
173 if change > RESIZE_ANIMATION_THRESHOLD {177 if change > RESIZE_ANIMATION_THRESHOLD {
174 let anim = Animation::new(0., 1., 0., self.options.animations.window_resize.anim);178 let anim = Animation::new(0., 1., 0., self.options.animations.window_resize.anim);
175 self.resize_animation = Some(ResizeAnimation {179 self.resize_animation = Some(ResizeAnimation {
@@ -235,13 +239,13 @@ impl<W: LayoutElement> Tile<W> {
235 || self.move_y_animation.is_some()239 || self.move_y_animation.is_some()
236 }240 }
237 241
238- pub fn update(&mut self, is_active: bool, view_rect: Rectangle<i32, Logical>) {242+ pub fn update(&mut self, is_active: bool, view_rect: Rectangle<f64, Logical>) {
239 let rules = self.window.rules();243 let rules = self.window.rules();
240 244
241 let draw_border_with_background = rules245 let draw_border_with_background = rules
242 .draw_border_with_background246 .draw_border_with_background
243 .unwrap_or_else(|| !self.window.has_ssd());247 .unwrap_or_else(|| !self.window.has_ssd());
244- let border_width = self.effective_border_width().unwrap_or(0);248+ let border_width = self.effective_border_width().unwrap_or(0.);
245 let radius = if self.is_fullscreen {249 let radius = if self.is_fullscreen {
246 CornerRadius::default()250 CornerRadius::default()
247 } else {251 } else {
@@ -260,6 +264,7 @@ impl<W: LayoutElement> Tile<W> {
260 view_rect.size,264 view_rect.size,
261 ),265 ),
262 radius,266 radius,
267+ self.scale,
263 );268 );
264 269
265 let draw_focus_ring_with_background = if self.effective_border_width().is_some() {270 let draw_focus_ring_with_background = if self.effective_border_width().is_some() {
@@ -281,20 +286,25 @@ impl<W: LayoutElement> Tile<W> {
281 !draw_focus_ring_with_background,286 !draw_focus_ring_with_background,
282 view_rect,287 view_rect,
283 radius,288 radius,
289+ self.scale,
284 );290 );
285 }291 }
286 292
287- pub fn render_offset(&self) -> Point<i32, Logical> {293+ pub fn scale(&self) -> f64 {
294+ self.scale
295+ }
296+
297+ pub fn render_offset(&self) -> Point<f64, Logical> {
288 let mut offset = Point::from((0., 0.));298 let mut offset = Point::from((0., 0.));
289 299
290 if let Some(move_) = &self.move_x_animation {300 if let Some(move_) = &self.move_x_animation {
291- offset.x += f64::from(move_.from) * move_.anim.value();301+ offset.x += move_.from * move_.anim.value();
292 }302 }
293 if let Some(move_) = &self.move_y_animation {303 if let Some(move_) = &self.move_y_animation {
294- offset.y += f64::from(move_.from) * move_.anim.value();304+ offset.y += move_.from * move_.anim.value();
295 }305 }
296 306
297- offset.to_i32_round()307+ offset
298 }308 }
299 309
300 pub fn start_open_animation(&mut self) {310 pub fn start_open_animation(&mut self) {
@@ -310,16 +320,16 @@ impl<W: LayoutElement> Tile<W> {
310 self.resize_animation.as_ref().map(|resize| &resize.anim)320 self.resize_animation.as_ref().map(|resize| &resize.anim)
311 }321 }
312 322
313- pub fn animate_move_from(&mut self, from: Point<i32, Logical>) {323+ pub fn animate_move_from(&mut self, from: Point<f64, Logical>) {
314 self.animate_move_x_from(from.x);324 self.animate_move_x_from(from.x);
315 self.animate_move_y_from(from.y);325 self.animate_move_y_from(from.y);
316 }326 }
317 327
318- pub fn animate_move_x_from(&mut self, from: i32) {328+ pub fn animate_move_x_from(&mut self, from: f64) {
319 self.animate_move_x_from_with_config(from, self.options.animations.window_movement.0);329 self.animate_move_x_from_with_config(from, self.options.animations.window_movement.0);
320 }330 }
321 331
322- pub fn animate_move_x_from_with_config(&mut self, from: i32, config: niri_config::Animation) {332+ pub fn animate_move_x_from_with_config(&mut self, from: f64, config: niri_config::Animation) {
323 let current_offset = self.render_offset().x;333 let current_offset = self.render_offset().x;
324 334
325 // Preserve the previous config if ongoing.335 // Preserve the previous config if ongoing.
@@ -334,11 +344,11 @@ impl<W: LayoutElement> Tile<W> {
334 });344 });
335 }345 }
336 346
337- pub fn animate_move_y_from(&mut self, from: i32) {347+ pub fn animate_move_y_from(&mut self, from: f64) {
338 self.animate_move_y_from_with_config(from, self.options.animations.window_movement.0);348 self.animate_move_y_from_with_config(from, self.options.animations.window_movement.0);
339 }349 }
340 350
341- pub fn animate_move_y_from_with_config(&mut self, from: i32, config: niri_config::Animation) {351+ pub fn animate_move_y_from_with_config(&mut self, from: f64, config: niri_config::Animation) {
342 let current_offset = self.render_offset().y;352 let current_offset = self.render_offset().y;
343 353
344 // Preserve the previous config if ongoing.354 // Preserve the previous config if ongoing.
@@ -370,7 +380,7 @@ impl<W: LayoutElement> Tile<W> {
370 }380 }
371 381
372 /// Returns `None` if the border is hidden and `Some(width)` if it should be shown.382 /// Returns `None` if the border is hidden and `Some(width)` if it should be shown.
373- fn effective_border_width(&self) -> Option<i32> {383+ fn effective_border_width(&self) -> Option<f64> {
374 if self.is_fullscreen {384 if self.is_fullscreen {
375 return None;385 return None;
376 }386 }
@@ -383,22 +393,27 @@ impl<W: LayoutElement> Tile<W> {
383 }393 }
384 394
385 /// Returns the location of the window's visual geometry within this Tile.395 /// Returns the location of the window's visual geometry within this Tile.
386- pub fn window_loc(&self) -> Point<i32, Logical> {396+ pub fn window_loc(&self) -> Point<f64, Logical> {
387- let mut loc = Point::from((0, 0));397+ let mut loc = Point::from((0., 0.));
388 398
389 // In fullscreen, center the window in the given size.399 // In fullscreen, center the window in the given size.
390 if self.is_fullscreen {400 if self.is_fullscreen {
391- let window_size = self.window.size();401+ let window_size = self.window_size();
392 let target_size = self.fullscreen_size;402 let target_size = self.fullscreen_size;
393 403
394 // Windows aren't supposed to be larger than the fullscreen size, but in case we get404 // Windows aren't supposed to be larger than the fullscreen size, but in case we get
395 // one, leave it at the top-left as usual.405 // one, leave it at the top-left as usual.
396 if window_size.w < target_size.w {406 if window_size.w < target_size.w {
397- loc.x += (target_size.w - window_size.w) / 2;407+ loc.x += (target_size.w - window_size.w) / 2.;
398 }408 }
399 if window_size.h < target_size.h {409 if window_size.h < target_size.h {
400- loc.y += (target_size.h - window_size.h) / 2;410+ loc.y += (target_size.h - window_size.h) / 2.;
401 }411 }
412+
413+ // Round to physical pixels.
414+ loc = loc
415+ .to_physical_precise_round(self.scale)
416+ .to_logical(self.scale);
402 }417 }
403 418
404 if let Some(width) = self.effective_border_width() {419 if let Some(width) = self.effective_border_width() {
@@ -408,68 +423,73 @@ impl<W: LayoutElement> Tile<W> {
408 loc423 loc
409 }424 }
410 425
411- pub fn tile_size(&self) -> Size<i32, Logical> {426+ pub fn tile_size(&self) -> Size<f64, Logical> {
412- let mut size = self.window.size();427+ let mut size = self.window_size();
413 428
414 if self.is_fullscreen {429 if self.is_fullscreen {
415 // Normally we'd just return the fullscreen size here, but this makes things a bit430 // Normally we'd just return the fullscreen size here, but this makes things a bit
416 // nicer if a fullscreen window is bigger than the fullscreen size for some reason.431 // nicer if a fullscreen window is bigger than the fullscreen size for some reason.
417- size.w = max(size.w, self.fullscreen_size.w);432+ size.w = f64::max(size.w, self.fullscreen_size.w);
418- size.h = max(size.h, self.fullscreen_size.h);433+ size.h = f64::max(size.h, self.fullscreen_size.h);
419 return size;434 return size;
420 }435 }
421 436
422 if let Some(width) = self.effective_border_width() {437 if let Some(width) = self.effective_border_width() {
423- size.w = size.w.saturating_add(width * 2);438+ size.w += width * 2.;
424- size.h = size.h.saturating_add(width * 2);439+ size.h += width * 2.;
425 }440 }
426 441
427 size442 size
428 }443 }
429 444
430- pub fn window_size(&self) -> Size<i32, Logical> {445+ pub fn window_size(&self) -> Size<f64, Logical> {
431- self.window.size()446+ let mut size = self.window.size().to_f64();
447+ size = size
448+ .to_physical_precise_round(self.scale)
449+ .to_logical(self.scale);
450+ size
432 }451 }
433 452
434- fn animated_window_size(&self) -> Size<i32, Logical> {453+ fn animated_window_size(&self) -> Size<f64, Logical> {
435- let mut size = self.window.size();454+ let mut size = self.window_size();
436 455
437 if let Some(resize) = &self.resize_animation {456 if let Some(resize) = &self.resize_animation {
438 let val = resize.anim.value();457 let val = resize.anim.value();
439- let size_from = resize.size_from;458+ let size_from = resize.size_from.to_f64();
440 459
441- size.w = (size_from.w as f64 + (size.w - size_from.w) as f64 * val).round() as i32;460+ size.w = f64::max(1., size_from.w + (size.w - size_from.w) * val);
442- size.w = max(1, size.w);461+ size.h = f64::max(1., size_from.h + (size.h - size_from.h) * val);
443- size.h = (size_from.h as f64 + (size.h - size_from.h) as f64 * val).round() as i32;462+ size = size
444- size.h = max(1, size.h);463+ .to_physical_precise_round(self.scale)
464+ .to_logical(self.scale);
445 }465 }
446 466
447 size467 size
448 }468 }
449 469
450- fn animated_tile_size(&self) -> Size<i32, Logical> {470+ fn animated_tile_size(&self) -> Size<f64, Logical> {
451 let mut size = self.animated_window_size();471 let mut size = self.animated_window_size();
452 472
453 if self.is_fullscreen {473 if self.is_fullscreen {
454 // Normally we'd just return the fullscreen size here, but this makes things a bit474 // Normally we'd just return the fullscreen size here, but this makes things a bit
455 // nicer if a fullscreen window is bigger than the fullscreen size for some reason.475 // nicer if a fullscreen window is bigger than the fullscreen size for some reason.
456- size.w = max(size.w, self.fullscreen_size.w);476+ size.w = f64::max(size.w, self.fullscreen_size.w);
457- size.h = max(size.h, self.fullscreen_size.h);477+ size.h = f64::max(size.h, self.fullscreen_size.h);
458 return size;478 return size;
459 }479 }
460 480
461 if let Some(width) = self.effective_border_width() {481 if let Some(width) = self.effective_border_width() {
462- size.w = size.w.saturating_add(width * 2);482+ size.w += width * 2.;
463- size.h = size.h.saturating_add(width * 2);483+ size.h += width * 2.;
464 }484 }
465 485
466 size486 size
467 }487 }
468 488
469- pub fn buf_loc(&self) -> Point<i32, Logical> {489+ pub fn buf_loc(&self) -> Point<f64, Logical> {
470- let mut loc = Point::from((0, 0));490+ let mut loc = Point::from((0., 0.));
471 loc += self.window_loc();491 loc += self.window_loc();
472- loc += self.window.buf_loc();492+ loc += self.window.buf_loc().to_f64();
473 loc493 loc
474 }494 }
475 495
@@ -479,74 +499,85 @@ impl<W: LayoutElement> Tile<W> {
479 }499 }
480 500
481 pub fn is_in_activation_region(&self, point: Point<f64, Logical>) -> bool {501 pub fn is_in_activation_region(&self, point: Point<f64, Logical>) -> bool {
482- let activation_region = Rectangle::from_loc_and_size((0, 0), self.tile_size());502+ let activation_region = Rectangle::from_loc_and_size((0., 0.), self.tile_size());
483- activation_region.to_f64().contains(point)503+ activation_region.contains(point)
484 }504 }
485 505
486- pub fn request_tile_size(&mut self, mut size: Size<i32, Logical>, animate: bool) {506+ pub fn request_tile_size(&mut self, mut size: Size<f64, Logical>, animate: bool) {
487 // Can't go through effective_border_width() because we might be fullscreen.507 // Can't go through effective_border_width() because we might be fullscreen.
488 if !self.border.is_off() {508 if !self.border.is_off() {
489 let width = self.border.width();509 let width = self.border.width();
490- size.w = max(1, size.w - width * 2);510+ size.w = f64::max(1., size.w - width * 2.);
491- size.h = max(1, size.h - width * 2);511+ size.h = f64::max(1., size.h - width * 2.);
492 }512 }
493 513
494- self.window.request_size(size, animate);514+ // The size request has to be i32 unfortunately, due to Wayland. We floor here instead of
515+ // round to avoid situations where proportionally-sized columns don't fit on the screen
516+ // exactly.
517+ self.window.request_size(size.to_i32_floor(), animate);
518+ }
519+
520+ pub fn tile_width_for_window_width(&self, size: f64) -> f64 {
521+ if self.border.is_off() {
522+ size
523+ } else {
524+ size + self.border.width() * 2.
525+ }
495 }526 }
496 527
497- pub fn tile_width_for_window_width(&self, size: i32) -> i32 {528+ pub fn tile_height_for_window_height(&self, size: f64) -> f64 {
498 if self.border.is_off() {529 if self.border.is_off() {
499 size530 size
500 } else {531 } else {
501- size.saturating_add(self.border.width() * 2)532+ size + self.border.width() * 2.
502 }533 }
503 }534 }
504 535
505- pub fn tile_height_for_window_height(&self, size: i32) -> i32 {536+ pub fn window_width_for_tile_width(&self, size: f64) -> f64 {
506 if self.border.is_off() {537 if self.border.is_off() {
507 size538 size
508 } else {539 } else {
509- size.saturating_add(self.border.width() * 2)540+ size - self.border.width() * 2.
510 }541 }
511 }542 }
512 543
513- pub fn window_height_for_tile_height(&self, size: i32) -> i32 {544+ pub fn window_height_for_tile_height(&self, size: f64) -> f64 {
514 if self.border.is_off() {545 if self.border.is_off() {
515 size546 size
516 } else {547 } else {
517- size.saturating_sub(self.border.width() * 2)548+ size - self.border.width() * 2.
518 }549 }
519 }550 }
520 551
521- pub fn request_fullscreen(&mut self, size: Size<i32, Logical>) {552+ pub fn request_fullscreen(&mut self, size: Size<f64, Logical>) {
522 self.fullscreen_backdrop.resize(size);553 self.fullscreen_backdrop.resize(size);
523 self.fullscreen_size = size;554 self.fullscreen_size = size;
524- self.window.request_fullscreen(size);555+ self.window.request_fullscreen(size.to_i32_round());
525 }556 }
526 557
527- pub fn min_size(&self) -> Size<i32, Logical> {558+ pub fn min_size(&self) -> Size<f64, Logical> {
528- let mut size = self.window.min_size();559+ let mut size = self.window.min_size().to_f64();
529 560
530 if let Some(width) = self.effective_border_width() {561 if let Some(width) = self.effective_border_width() {
531- size.w = max(1, size.w);562+ size.w = f64::max(1., size.w);
532- size.h = max(1, size.h);563+ size.h = f64::max(1., size.h);
533 564
534- size.w = size.w.saturating_add(width * 2);565+ size.w += width * 2.;
535- size.h = size.h.saturating_add(width * 2);566+ size.h += width * 2.;
536 }567 }
537 568
538 size569 size
539 }570 }
540 571
541- pub fn max_size(&self) -> Size<i32, Logical> {572+ pub fn max_size(&self) -> Size<f64, Logical> {
542- let mut size = self.window.max_size();573+ let mut size = self.window.max_size().to_f64();
543 574
544 if let Some(width) = self.effective_border_width() {575 if let Some(width) = self.effective_border_width() {
545- if size.w > 0 {576+ if size.w > 0. {
546- size.w = size.w.saturating_add(width * 2);577+ size.w += width * 2.;
547 }578 }
548- if size.h > 0 {579+ if size.h > 0. {
549- size.h = size.h.saturating_add(width * 2);580+ size.h += width * 2.;
550 }581 }
551 }582 }
552 583
@@ -567,7 +598,7 @@ impl<W: LayoutElement> Tile<W> {
567 fn render_inner<R: NiriRenderer>(598 fn render_inner<R: NiriRenderer>(
568 &self,599 &self,
569 renderer: &mut R,600 renderer: &mut R,
570- location: Point<i32, Logical>,601+ location: Point<f64, Logical>,
571 scale: Scale<f64>,602 scale: Scale<f64>,
572 focus_ring: bool,603 focus_ring: bool,
573 target: RenderTarget,604 target: RenderTarget,
@@ -581,7 +612,7 @@ impl<W: LayoutElement> Tile<W> {
581 };612 };
582 613
583 let window_loc = self.window_loc();614 let window_loc = self.window_loc();
584- let window_size = self.window_size();615+ let window_size = self.window_size().to_f64();
585 let animated_window_size = self.animated_window_size();616 let animated_window_size = self.animated_window_size();
586 let window_render_loc = location + window_loc;617 let window_render_loc = location + window_loc;
587 let area = Rectangle::from_loc_and_size(window_render_loc, animated_window_size);618 let area = Rectangle::from_loc_and_size(window_render_loc, animated_window_size);
@@ -609,7 +640,7 @@ impl<W: LayoutElement> Tile<W> {
609 if let Some(texture_from) = resize.snapshot.texture(gles_renderer, scale, target) {640 if let Some(texture_from) = resize.snapshot.texture(gles_renderer, scale, target) {
610 let window_elements = self.window.render_normal(641 let window_elements = self.window.render_normal(
611 gles_renderer,642 gles_renderer,
612- Point::from((0, 0)),643+ Point::from((0., 0.)),
613 scale,644 scale,
614 1.,645 1.,
615 target,646 target,
@@ -664,8 +695,7 @@ impl<W: LayoutElement> Tile<W> {
664 resize_fallback = Some(695 resize_fallback = Some(
665 SolidColorRenderElement::from_buffer(696 SolidColorRenderElement::from_buffer(
666 &fallback_buffer,697 &fallback_buffer,
667- area.loc.to_physical_precise_round(scale),698+ area.loc,
668- scale,
669 alpha,699 alpha,
670 Kind::Unspecified,700 Kind::Unspecified,
671 )701 )
@@ -726,11 +756,11 @@ impl<W: LayoutElement> Tile<W> {
726 if radius != CornerRadius::default() && has_border_shader {756 if radius != CornerRadius::default() && has_border_shader {
727 return BorderRenderElement::new(757 return BorderRenderElement::new(
728 geo.size,758 geo.size,
729- Rectangle::from_loc_and_size((0, 0), geo.size),759+ Rectangle::from_loc_and_size((0., 0.), geo.size),
730 elem.color(),760 elem.color(),
731 elem.color(),761 elem.color(),
732 0.,762 0.,
733- Rectangle::from_loc_and_size((0, 0), geo.size),763+ Rectangle::from_loc_and_size((0., 0.), geo.size),
734 0.,764 0.,
735 radius,765 radius,
736 )766 )
@@ -758,8 +788,7 @@ impl<W: LayoutElement> Tile<W> {
758 let elem = self.is_fullscreen.then(|| {788 let elem = self.is_fullscreen.then(|| {
759 SolidColorRenderElement::from_buffer(789 SolidColorRenderElement::from_buffer(
760 &self.fullscreen_backdrop,790 &self.fullscreen_backdrop,
761- location.to_physical_precise_round(scale),791+ location,
762- scale,
763 1.,792 1.,
764 Kind::Unspecified,793 Kind::Unspecified,
765 )794 )
@@ -769,23 +798,19 @@ impl<W: LayoutElement> Tile<W> {
769 798
770 let elem = self.effective_border_width().map(|width| {799 let elem = self.effective_border_width().map(|width| {
771 self.border800 self.border
772- .render(renderer, location + Point::from((width, width)), scale)801+ .render(renderer, location + Point::from((width, width)))
773 .map(Into::into)802 .map(Into::into)
774 });803 });
775 let rv = rv.chain(elem.into_iter().flatten());804 let rv = rv.chain(elem.into_iter().flatten());
776 805
777- let elem = focus_ring.then(|| {806+ let elem = focus_ring.then(|| self.focus_ring.render(renderer, location).map(Into::into));
778- self.focus_ring
779- .render(renderer, location, scale)
780- .map(Into::into)
781- });
782 rv.chain(elem.into_iter().flatten())807 rv.chain(elem.into_iter().flatten())
783 }808 }
784 809
785 pub fn render<R: NiriRenderer>(810 pub fn render<R: NiriRenderer>(
786 &self,811 &self,
787 renderer: &mut R,812 renderer: &mut R,
788- location: Point<i32, Logical>,813+ location: Point<f64, Logical>,
789 scale: Scale<f64>,814 scale: Scale<f64>,
790 focus_ring: bool,815 focus_ring: bool,
791 target: RenderTarget,816 target: RenderTarget,
@@ -798,7 +823,7 @@ impl<W: LayoutElement> Tile<W> {
798 if let Some(open) = &self.open_animation {823 if let Some(open) = &self.open_animation {
799 let renderer = renderer.as_gles_renderer();824 let renderer = renderer.as_gles_renderer();
800 let elements =825 let elements =
801- self.render_inner(renderer, Point::from((0, 0)), scale, focus_ring, target);826+ self.render_inner(renderer, Point::from((0., 0.)), scale, focus_ring, target);
802 let elements = elements.collect::<Vec<TileRenderElement<_>>>();827 let elements = elements.collect::<Vec<TileRenderElement<_>>>();
803 match open.render(renderer, &elements, self.tile_size(), location, scale) {828 match open.render(renderer, &elements, self.tile_size(), location, scale) {
804 Ok(elem) => {829 Ok(elem) => {
@@ -843,7 +868,7 @@ impl<W: LayoutElement> Tile<W> {
843 868
844 let contents = self.render(869 let contents = self.render(
845 renderer,870 renderer,
846- Point::from((0, 0)),871+ Point::from((0., 0.)),
847 scale,872 scale,
848 false,873 false,
849 RenderTarget::Output,874 RenderTarget::Output,
@@ -852,7 +877,7 @@ impl<W: LayoutElement> Tile<W> {
852 // A bit of a hack to render blocked out as for screencast, but I think it's fine here.877 // A bit of a hack to render blocked out as for screencast, but I think it's fine here.
853 let blocked_out_contents = self.render(878 let blocked_out_contents = self.render(
854 renderer,879 renderer,
855- Point::from((0, 0)),880+ Point::from((0., 0.)),
856 scale,881 scale,
857 false,882 false,
858 RenderTarget::Screencast,883 RenderTarget::Screencast,
src/layout/workspace.rsmodified+332 -228
@@ -5,6 +5,7 @@ use std::time::Duration;
5 5
6 use niri_config::{CenterFocusedColumn, PresetWidth, Struts, Workspace as WorkspaceConfig};6 use niri_config::{CenterFocusedColumn, PresetWidth, Struts, Workspace as WorkspaceConfig};
7 use niri_ipc::SizeChange;7 use niri_ipc::SizeChange;
8+use ordered_float::NotNan;
8 use smithay::backend::renderer::gles::GlesRenderer;9 use smithay::backend::renderer::gles::GlesRenderer;
9 use smithay::desktop::{layer_map_for_output, Window};10 use smithay::desktop::{layer_map_for_output, Window};
10 use smithay::output::Output;11 use smithay::output::Output;
@@ -54,13 +55,13 @@ pub struct Workspace<W: LayoutElement> {
54 ///55 ///
55 /// This should be computed from the current workspace output size, or, if all outputs have56 /// This should be computed from the current workspace output size, or, if all outputs have
56 /// been disconnected, preserved until a new output is connected.57 /// been disconnected, preserved until a new output is connected.
57- view_size: Size<i32, Logical>,58+ view_size: Size<f64, Logical>,
58 59
59 /// Latest known working area for this workspace.60 /// Latest known working area for this workspace.
60 ///61 ///
61 /// This is similar to view size, but takes into account things like layer shell exclusive62 /// This is similar to view size, but takes into account things like layer shell exclusive
62 /// zones.63 /// zones.
63- working_area: Rectangle<i32, Logical>,64+ working_area: Rectangle<f64, Logical>,
64 65
65 /// Columns of windows on this workspace.66 /// Columns of windows on this workspace.
66 pub columns: Vec<Column<W>>,67 pub columns: Vec<Column<W>>,
@@ -79,7 +80,7 @@ pub struct Workspace<W: LayoutElement> {
79 /// Any gaps, including left padding from work area left exclusive zone, is handled80 /// Any gaps, including left padding from work area left exclusive zone, is handled
80 /// with this view offset (rather than added as a constant elsewhere in the code). This allows81 /// with this view offset (rather than added as a constant elsewhere in the code). This allows
81 /// for natural handling of fullscreen windows, which must ignore work area padding.82 /// for natural handling of fullscreen windows, which must ignore work area padding.
82- view_offset: i32,83+ view_offset: f64,
83 84
84 /// Adjustment of the view offset, if one is currently ongoing.85 /// Adjustment of the view offset, if one is currently ongoing.
85 view_offset_adj: Option<ViewOffsetAdjustment>,86 view_offset_adj: Option<ViewOffsetAdjustment>,
@@ -94,15 +95,18 @@ pub struct Workspace<W: LayoutElement> {
94 /// index of the previous column to activate.95 /// index of the previous column to activate.
95 ///96 ///
96 /// The value is the view offset that the previous column had before, to restore it.97 /// The value is the view offset that the previous column had before, to restore it.
97- activate_prev_column_on_removal: Option<i32>,98+ activate_prev_column_on_removal: Option<f64>,
98 99
99 /// View offset to restore after unfullscreening.100 /// View offset to restore after unfullscreening.
100- view_offset_before_fullscreen: Option<i32>,101+ view_offset_before_fullscreen: Option<f64>,
101 102
102 /// Windows in the closing animation.103 /// Windows in the closing animation.
103 closing_windows: Vec<ClosingWindow>,104 closing_windows: Vec<ClosingWindow>,
104 105
105- /// Configurable properties of the layout.106+ /// Configurable properties of the layout as received from the parent monitor.
107+ pub base_options: Rc<Options>,
108+
109+ /// Configurable properties of the layout with logical sizes adjusted for the current `scale`.
106 pub options: Rc<Options>,110 pub options: Rc<Options>,
107 111
108 /// Optional name of this workspace.112 /// Optional name of this workspace.
@@ -137,7 +141,7 @@ niri_render_elements! {
137 #[derive(Debug, Clone, Copy, PartialEq)]141 #[derive(Debug, Clone, Copy, PartialEq)]
138 struct ColumnData {142 struct ColumnData {
139 /// Cached actual column width.143 /// Cached actual column width.
140- width: i32,144+ width: f64,
141 }145 }
142 146
143 #[derive(Debug)]147 #[derive(Debug)]
@@ -152,7 +156,7 @@ struct ViewGesture {
152 tracker: SwipeTracker,156 tracker: SwipeTracker,
153 delta_from_tracker: f64,157 delta_from_tracker: f64,
154 // The view offset we'll use if needed for activate_prev_column_on_removal.158 // The view offset we'll use if needed for activate_prev_column_on_removal.
155- static_view_offset: i32,159+ static_view_offset: f64,
156 /// Whether the gesture is controlled by the touchpad.160 /// Whether the gesture is controlled by the touchpad.
157 is_touchpad: bool,161 is_touchpad: bool,
158 }162 }
@@ -160,7 +164,7 @@ struct ViewGesture {
160 #[derive(Debug)]164 #[derive(Debug)]
161 struct InteractiveResize<W: LayoutElement> {165 struct InteractiveResize<W: LayoutElement> {
162 window: W::Id,166 window: W::Id,
163- original_window_size: Size<i32, Logical>,167+ original_window_size: Size<f64, Logical>,
164 data: InteractiveResizeData,168 data: InteractiveResizeData,
165 }169 }
166 170
@@ -175,7 +179,7 @@ pub enum ColumnWidth {
175 /// proportions.179 /// proportions.
176 Preset(usize),180 Preset(usize),
177 /// Fixed width in logical pixels.181 /// Fixed width in logical pixels.
178- Fixed(i32),182+ Fixed(f64),
179 }183 }
180 184
181 /// Height of a window in a column.185 /// Height of a window in a column.
@@ -190,12 +194,12 @@ pub enum ColumnWidth {
190 /// This does not preclude the usual set of binds to set or resize a window proportionally. Just,194 /// This does not preclude the usual set of binds to set or resize a window proportionally. Just,
191 /// they are converted to, and stored as fixed height right away, so that once you resize a window195 /// they are converted to, and stored as fixed height right away, so that once you resize a window
192 /// to fit the desired content, it can never become smaller than that when moving between monitors.196 /// to fit the desired content, it can never become smaller than that when moving between monitors.
193-#[derive(Debug, Clone, Copy, PartialEq, Eq)]197+#[derive(Debug, Clone, Copy, PartialEq)]
194 pub enum WindowHeight {198 pub enum WindowHeight {
195 /// Automatically computed height, evenly distributed across the column.199 /// Automatically computed height, evenly distributed across the column.
196 Auto,200 Auto,
197 /// Fixed height in logical pixels.201 /// Fixed height in logical pixels.
198- Fixed(i32),202+ Fixed(f64),
199 }203 }
200 204
201 #[derive(Debug)]205 #[derive(Debug)]
@@ -229,10 +233,13 @@ pub struct Column<W: LayoutElement> {
229 move_animation: Option<Animation>,233 move_animation: Option<Animation>,
230 234
231 /// Latest known view size for this column's workspace.235 /// Latest known view size for this column's workspace.
232- view_size: Size<i32, Logical>,236+ view_size: Size<f64, Logical>,
233 237
234 /// Latest known working area for this column's workspace.238 /// Latest known working area for this column's workspace.
235- working_area: Rectangle<i32, Logical>,239+ working_area: Rectangle<f64, Logical>,
240+
241+ /// Scale of the output the column is on (and rounds its sizes to).
242+ scale: f64,
236 243
237 /// Configurable properties of the layout.244 /// Configurable properties of the layout.
238 options: Rc<Options>,245 options: Rc<Options>,
@@ -247,7 +254,7 @@ struct TileData {
247 height: WindowHeight,254 height: WindowHeight,
248 255
249 /// Cached actual size of the tile.256 /// Cached actual size of the tile.
250- size: Size<i32, Logical>,257+ size: Size<f64, Logical>,
251 258
252 /// Cached whether the tile is being interactively resized by its left edge.259 /// Cached whether the tile is being interactively resized by its left edge.
253 interactively_resizing_by_left_edge: bool,260 interactively_resizing_by_left_edge: bool,
@@ -274,7 +281,7 @@ impl ViewOffsetAdjustment {
274 281
275 impl ColumnData {282 impl ColumnData {
276 pub fn new<W: LayoutElement>(column: &Column<W>) -> Self {283 pub fn new<W: LayoutElement>(column: &Column<W>) -> Self {
277- let mut rv = Self { width: 0 };284+ let mut rv = Self { width: 0. };
278 rv.update(column);285 rv.update(column);
279 rv286 rv
280 }287 }
@@ -285,10 +292,10 @@ impl ColumnData {
285 }292 }
286 293
287 impl ColumnWidth {294 impl ColumnWidth {
288- fn resolve(self, options: &Options, view_width: i32) -> i32 {295+ fn resolve(self, options: &Options, view_width: f64) -> f64 {
289 match self {296 match self {
290 ColumnWidth::Proportion(proportion) => {297 ColumnWidth::Proportion(proportion) => {
291- ((view_width - options.gaps) as f64 * proportion).floor() as i32 - options.gaps298+ (view_width - options.gaps) * proportion - options.gaps
292 }299 }
293 ColumnWidth::Preset(idx) => options.preset_widths[idx].resolve(options, view_width),300 ColumnWidth::Preset(idx) => options.preset_widths[idx].resolve(options, view_width),
294 ColumnWidth::Fixed(width) => width,301 ColumnWidth::Fixed(width) => width,
@@ -300,7 +307,7 @@ impl From<PresetWidth> for ColumnWidth {
300 fn from(value: PresetWidth) -> Self {307 fn from(value: PresetWidth) -> Self {
301 match value {308 match value {
302 PresetWidth::Proportion(p) => Self::Proportion(p.clamp(0., 10000.)),309 PresetWidth::Proportion(p) => Self::Proportion(p.clamp(0., 10000.)),
303- PresetWidth::Fixed(f) => Self::Fixed(f.clamp(1, 100000)),310+ PresetWidth::Fixed(f) => Self::Fixed(f64::from(f.clamp(1, 100000))),
304 }311 }
305 }312 }
306 }313 }
@@ -333,7 +340,7 @@ impl<W: LayoutElement> Workspace<W> {
333 pub fn new_with_config(340 pub fn new_with_config(
334 output: Output,341 output: Output,
335 config: Option<WorkspaceConfig>,342 config: Option<WorkspaceConfig>,
336- options: Rc<Options>,343+ base_options: Rc<Options>,
337 ) -> Self {344 ) -> Self {
338 let original_output = config345 let original_output = config
339 .as_ref()346 .as_ref()
@@ -341,10 +348,15 @@ impl<W: LayoutElement> Workspace<W> {
341 .map(OutputId)348 .map(OutputId)
342 .unwrap_or(OutputId::new(&output));349 .unwrap_or(OutputId::new(&output));
343 350
351+ let scale = output.current_scale();
352+ let options =
353+ Rc::new(Options::clone(&base_options).adjusted_for_scale(scale.fractional_scale()));
354+
344 let working_area = compute_working_area(&output, options.struts);355 let working_area = compute_working_area(&output, options.struts);
356+
345 Self {357 Self {
346 original_output,358 original_output,
347- scale: output.current_scale(),359+ scale,
348 transform: output.current_transform(),360 transform: output.current_transform(),
349 view_size: output_size(&output),361 view_size: output_size(&output),
350 working_area,362 working_area,
@@ -353,11 +365,12 @@ impl<W: LayoutElement> Workspace<W> {
353 data: vec![],365 data: vec![],
354 active_column_idx: 0,366 active_column_idx: 0,
355 interactive_resize: None,367 interactive_resize: None,
356- view_offset: 0,368+ view_offset: 0.,
357 view_offset_adj: None,369 view_offset_adj: None,
358 activate_prev_column_on_removal: None,370 activate_prev_column_on_removal: None,
359 view_offset_before_fullscreen: None,371 view_offset_before_fullscreen: None,
360 closing_windows: vec![],372 closing_windows: vec![],
373+ base_options,
361 options,374 options,
362 name: config.map(|c| c.name.0),375 name: config.map(|c| c.name.0),
363 id: WorkspaceId::next(),376 id: WorkspaceId::next(),
@@ -366,7 +379,7 @@ impl<W: LayoutElement> Workspace<W> {
366 379
367 pub fn new_with_config_no_outputs(380 pub fn new_with_config_no_outputs(
368 config: Option<WorkspaceConfig>,381 config: Option<WorkspaceConfig>,
369- options: Rc<Options>,382+ base_options: Rc<Options>,
370 ) -> Self {383 ) -> Self {
371 let original_output = OutputId(384 let original_output = OutputId(
372 config385 config
@@ -374,22 +387,28 @@ impl<W: LayoutElement> Workspace<W> {
374 .and_then(|c| c.open_on_output)387 .and_then(|c| c.open_on_output)
375 .unwrap_or_default(),388 .unwrap_or_default(),
376 );389 );
390+
391+ let scale = smithay::output::Scale::Integer(1);
392+ let options =
393+ Rc::new(Options::clone(&base_options).adjusted_for_scale(scale.fractional_scale()));
394+
377 Self {395 Self {
378 output: None,396 output: None,
379- scale: smithay::output::Scale::Integer(1),397+ scale,
380 transform: Transform::Normal,398 transform: Transform::Normal,
381 original_output,399 original_output,
382- view_size: Size::from((1280, 720)),400+ view_size: Size::from((1280., 720.)),
383- working_area: Rectangle::from_loc_and_size((0, 0), (1280, 720)),401+ working_area: Rectangle::from_loc_and_size((0., 0.), (1280., 720.)),
384 columns: vec![],402 columns: vec![],
385 data: vec![],403 data: vec![],
386 active_column_idx: 0,404 active_column_idx: 0,
387 interactive_resize: None,405 interactive_resize: None,
388- view_offset: 0,406+ view_offset: 0.,
389 view_offset_adj: None,407 view_offset_adj: None,
390 activate_prev_column_on_removal: None,408 activate_prev_column_on_removal: None,
391 view_offset_before_fullscreen: None,409 view_offset_before_fullscreen: None,
392 closing_windows: vec![],410 closing_windows: vec![],
411+ base_options,
393 options,412 options,
394 name: config.map(|c| c.name.0),413 name: config.map(|c| c.name.0),
395 id: WorkspaceId::next(),414 id: WorkspaceId::next(),
@@ -408,15 +427,19 @@ impl<W: LayoutElement> Workspace<W> {
408 self.name = None;427 self.name = None;
409 }428 }
410 429
430+ pub fn scale(&self) -> smithay::output::Scale {
431+ self.scale
432+ }
433+
411 pub fn advance_animations(&mut self, current_time: Duration) {434 pub fn advance_animations(&mut self, current_time: Duration) {
412 if let Some(ViewOffsetAdjustment::Animation(anim)) = &mut self.view_offset_adj {435 if let Some(ViewOffsetAdjustment::Animation(anim)) = &mut self.view_offset_adj {
413 anim.set_current_time(current_time);436 anim.set_current_time(current_time);
414- self.view_offset = anim.value().round() as i32;437+ self.view_offset = anim.value();
415 if anim.is_done() {438 if anim.is_done() {
416 self.view_offset_adj = None;439 self.view_offset_adj = None;
417 }440 }
418 } else if let Some(ViewOffsetAdjustment::Gesture(gesture)) = &self.view_offset_adj {441 } else if let Some(ViewOffsetAdjustment::Gesture(gesture)) = &self.view_offset_adj {
419- self.view_offset = gesture.current_view_offset.round() as i32;442+ self.view_offset = gesture.current_view_offset;
420 }443 }
421 444
422 for col in &mut self.columns {445 for col in &mut self.columns {
@@ -444,24 +467,28 @@ impl<W: LayoutElement> Workspace<W> {
444 }467 }
445 468
446 pub fn update_render_elements(&mut self, is_active: bool) {469 pub fn update_render_elements(&mut self, is_active: bool) {
447- let view_pos = Point::from((self.view_pos(), 0));470+ let view_pos = Point::from((self.view_pos(), 0.));
448 let view_size = self.view_size();471 let view_size = self.view_size();
449 let active_idx = self.active_column_idx;472 let active_idx = self.active_column_idx;
450 for (col_idx, (col, col_x)) in self.columns_mut().enumerate() {473 for (col_idx, (col, col_x)) in self.columns_mut().enumerate() {
451 let is_active = is_active && col_idx == active_idx;474 let is_active = is_active && col_idx == active_idx;
452- let col_off = Point::from((col_x, 0));475+ let col_off = Point::from((col_x, 0.));
453 let col_pos = view_pos - col_off - col.render_offset();476 let col_pos = view_pos - col_off - col.render_offset();
454 let view_rect = Rectangle::from_loc_and_size(col_pos, view_size);477 let view_rect = Rectangle::from_loc_and_size(col_pos, view_size);
455 col.update_render_elements(is_active, view_rect);478 col.update_render_elements(is_active, view_rect);
456 }479 }
457 }480 }
458 481
459- pub fn update_config(&mut self, options: Rc<Options>) {482+ pub fn update_config(&mut self, base_options: Rc<Options>) {
483+ let scale = self.scale.fractional_scale();
484+ let options = Rc::new(Options::clone(&base_options).adjusted_for_scale(scale));
485+
460 for (column, data) in zip(&mut self.columns, &mut self.data) {486 for (column, data) in zip(&mut self.columns, &mut self.data) {
461- column.update_config(options.clone());487+ column.update_config(scale, options.clone());
462 data.update(column);488 data.update(column);
463 }489 }
464 490
491+ self.base_options = base_options;
465 self.options = options;492 self.options = options;
466 }493 }
467 494
@@ -527,8 +554,8 @@ impl<W: LayoutElement> Workspace<W> {
527 &mut self,554 &mut self,
528 scale: smithay::output::Scale,555 scale: smithay::output::Scale,
529 transform: Transform,556 transform: Transform,
530- size: Size<i32, Logical>,557+ size: Size<f64, Logical>,
531- working_area: Rectangle<i32, Logical>,558+ working_area: Rectangle<f64, Logical>,
532 ) {559 ) {
533 let scale_transform_changed = self.transform != transform560 let scale_transform_changed = self.transform != transform
534 || self.scale.integer_scale() != scale.integer_scale()561 || self.scale.integer_scale() != scale.integer_scale()
@@ -537,11 +564,18 @@ impl<W: LayoutElement> Workspace<W> {
537 return;564 return;
538 }565 }
539 566
567+ let fractional_scale_changed = self.scale.fractional_scale() != scale.fractional_scale();
568+
540 self.scale = scale;569 self.scale = scale;
541 self.transform = transform;570 self.transform = transform;
542 self.view_size = size;571 self.view_size = size;
543 self.working_area = working_area;572 self.working_area = working_area;
544 573
574+ if fractional_scale_changed {
575+ // Options need to be recomputed for the new scale.
576+ self.update_config(self.base_options.clone());
577+ }
578+
545 for col in &mut self.columns {579 for col in &mut self.columns {
546 col.set_view_size(self.view_size, self.working_area);580 col.set_view_size(self.view_size, self.working_area);
547 }581 }
@@ -553,7 +587,7 @@ impl<W: LayoutElement> Workspace<W> {
553 }587 }
554 }588 }
555 589
556- pub fn view_size(&self) -> Size<i32, Logical> {590+ pub fn view_size(&self) -> Size<f64, Logical> {
557 self.view_size591 self.view_size
558 }592 }
559 593
@@ -586,20 +620,20 @@ impl<W: LayoutElement> Workspace<W> {
586 let mut width = width.resolve(&self.options, self.working_area.size.w);620 let mut width = width.resolve(&self.options, self.working_area.size.w);
587 621
588 if !is_fixed && !border.off {622 if !is_fixed && !border.off {
589- width -= border.width as i32 * 2;623+ width -= border.width.0 * 2.;
590 }624 }
591 625
592- max(1, width)626+ max(1, width.floor() as i32)
593 } else {627 } else {
594 0628 0
595 };629 };
596 630
597- let mut height = self.working_area.size.h - self.options.gaps * 2;631+ let mut height = self.working_area.size.h - self.options.gaps * 2.;
598 if !border.off {632 if !border.off {
599- height -= border.width as i32 * 2;633+ height -= border.width.0 * 2.;
600 }634 }
601 635
602- Size::from((width, max(height, 1)))636+ Size::from((width, max(height.floor() as i32, 1)))
603 }637 }
604 638
605 pub fn configure_new_window(639 pub fn configure_new_window(
@@ -617,7 +651,7 @@ impl<W: LayoutElement> Workspace<W> {
617 .expect("no x11 support")651 .expect("no x11 support")
618 .with_pending_state(|state| {652 .with_pending_state(|state| {
619 if state.states.contains(xdg_toplevel::State::Fullscreen) {653 if state.states.contains(xdg_toplevel::State::Fullscreen) {
620- state.size = Some(self.view_size);654+ state.size = Some(self.view_size.to_i32_round());
621 } else {655 } else {
622 state.size = Some(self.new_window_size(width, rules));656 state.size = Some(self.new_window_size(width, rules));
623 }657 }
@@ -626,15 +660,15 @@ impl<W: LayoutElement> Workspace<W> {
626 });660 });
627 }661 }
628 662
629- fn compute_new_view_offset_for_column(&self, current_x: i32, idx: usize) -> i32 {663+ fn compute_new_view_offset_for_column(&self, current_x: f64, idx: usize) -> f64 {
630 if self.columns[idx].is_fullscreen {664 if self.columns[idx].is_fullscreen {
631- return 0;665+ return 0.;
632 }666 }
633 667
634 let new_col_x = self.column_x(idx);668 let new_col_x = self.column_x(idx);
635 669
636 let final_x = if let Some(ViewOffsetAdjustment::Animation(anim)) = &self.view_offset_adj {670 let final_x = if let Some(ViewOffsetAdjustment::Animation(anim)) = &self.view_offset_adj {
637- current_x - self.view_offset + anim.to().round() as i32671+ current_x - self.view_offset + anim.to()
638 } else {672 } else {
639 current_x673 current_x
640 };674 };
@@ -651,7 +685,7 @@ impl<W: LayoutElement> Workspace<W> {
651 new_offset - self.working_area.loc.x685 new_offset - self.working_area.loc.x
652 }686 }
653 687
654- fn animate_view_offset(&mut self, current_x: i32, idx: usize, new_view_offset: i32) {688+ fn animate_view_offset(&mut self, current_x: f64, idx: usize, new_view_offset: f64) {
655 self.animate_view_offset_with_config(689 self.animate_view_offset_with_config(
656 current_x,690 current_x,
657 idx,691 idx,
@@ -662,9 +696,9 @@ impl<W: LayoutElement> Workspace<W> {
662 696
663 fn animate_view_offset_with_config(697 fn animate_view_offset_with_config(
664 &mut self,698 &mut self,
665- current_x: i32,699+ current_x: f64,
666 idx: usize,700 idx: usize,
667- new_view_offset: i32,701+ new_view_offset: f64,
668 config: niri_config::Animation,702 config: niri_config::Animation,
669 ) {703 ) {
670 let new_col_x = self.column_x(idx);704 let new_col_x = self.column_x(idx);
@@ -673,9 +707,8 @@ impl<W: LayoutElement> Workspace<W> {
673 707
674 // If we're already animating towards that, don't restart it.708 // If we're already animating towards that, don't restart it.
675 if let Some(ViewOffsetAdjustment::Animation(anim)) = &self.view_offset_adj {709 if let Some(ViewOffsetAdjustment::Animation(anim)) = &self.view_offset_adj {
676- if anim.value().round() as i32 == self.view_offset710+ let pixel = 1. / self.scale.fractional_scale();
677- && anim.to().round() as i32 == new_view_offset711+ if (anim.value() - self.view_offset).abs() < pixel && anim.to() == new_view_offset {
678- {
679 return;712 return;
680 }713 }
681 }714 }
@@ -688,8 +721,8 @@ impl<W: LayoutElement> Workspace<W> {
688 721
689 // FIXME: also compute and use current velocity.722 // FIXME: also compute and use current velocity.
690 self.view_offset_adj = Some(ViewOffsetAdjustment::Animation(Animation::new(723 self.view_offset_adj = Some(ViewOffsetAdjustment::Animation(Animation::new(
691- self.view_offset as f64,724+ self.view_offset,
692- new_view_offset as f64,725+ new_view_offset,
693 0.,726 0.,
694 config,727 config,
695 )));728 )));
@@ -697,7 +730,7 @@ impl<W: LayoutElement> Workspace<W> {
697 730
698 fn animate_view_offset_to_column_fit(731 fn animate_view_offset_to_column_fit(
699 &mut self,732 &mut self,
700- current_x: i32,733+ current_x: f64,
701 idx: usize,734 idx: usize,
702 config: niri_config::Animation,735 config: niri_config::Animation,
703 ) {736 ) {
@@ -707,7 +740,7 @@ impl<W: LayoutElement> Workspace<W> {
707 740
708 fn animate_view_offset_to_column_centered(741 fn animate_view_offset_to_column_centered(
709 &mut self,742 &mut self,
710- current_x: i32,743+ current_x: f64,
711 idx: usize,744 idx: usize,
712 config: niri_config::Animation,745 config: niri_config::Animation,
713 ) {746 ) {
@@ -731,14 +764,14 @@ impl<W: LayoutElement> Workspace<W> {
731 return;764 return;
732 }765 }
733 766
734- let new_view_offset = -(self.working_area.size.w - width) / 2 - self.working_area.loc.x;767+ let new_view_offset = -(self.working_area.size.w - width) / 2. - self.working_area.loc.x;
735 768
736 self.animate_view_offset_with_config(current_x, idx, new_view_offset, config);769 self.animate_view_offset_with_config(current_x, idx, new_view_offset, config);
737 }770 }
738 771
739 fn animate_view_offset_to_column(772 fn animate_view_offset_to_column(
740 &mut self,773 &mut self,
741- current_x: i32,774+ current_x: f64,
742 idx: usize,775 idx: usize,
743 prev_idx: Option<usize>,776 prev_idx: Option<usize>,
744 ) {777 ) {
@@ -752,7 +785,7 @@ impl<W: LayoutElement> Workspace<W> {
752 785
753 fn animate_view_offset_to_column_with_config(786 fn animate_view_offset_to_column_with_config(
754 &mut self,787 &mut self,
755- current_x: i32,788+ current_x: f64,
756 idx: usize,789 idx: usize,
757 prev_idx: Option<usize>,790 prev_idx: Option<usize>,
758 config: niri_config::Animation,791 config: niri_config::Animation,
@@ -786,7 +819,7 @@ impl<W: LayoutElement> Workspace<W> {
786 } else {819 } else {
787 // Source is right from target.820 // Source is right from target.
788 source_x - target_x + source_width821 source_x - target_x + source_width
789- } + self.options.gaps * 2;822+ } + self.options.gaps * 2.;
790 823
791 // If it fits together, do a normal animation, otherwise center the new column.824 // If it fits together, do a normal animation, otherwise center the new column.
792 if total_width <= self.working_area.size.w {825 if total_width <= self.working_area.size.w {
@@ -853,7 +886,7 @@ impl<W: LayoutElement> Workspace<W> {
853 width: ColumnWidth,886 width: ColumnWidth,
854 is_full_width: bool,887 is_full_width: bool,
855 ) {888 ) {
856- let tile = Tile::new(window, self.options.clone());889+ let tile = Tile::new(window, self.scale.fractional_scale(), self.options.clone());
857 self.add_tile_at(col_idx, tile, activate, width, is_full_width, None);890 self.add_tile_at(col_idx, tile, activate, width, is_full_width, None);
858 }891 }
859 892
@@ -874,6 +907,7 @@ impl<W: LayoutElement> Workspace<W> {
874 tile,907 tile,
875 self.view_size,908 self.view_size,
876 self.working_area,909 self.working_area,
910+ self.scale.fractional_scale(),
877 self.options.clone(),911 self.options.clone(),
878 width,912 width,
879 is_full_width,913 is_full_width,
@@ -889,7 +923,7 @@ impl<W: LayoutElement> Workspace<W> {
889 if was_empty {923 if was_empty {
890 if self.options.center_focused_column == CenterFocusedColumn::Always {924 if self.options.center_focused_column == CenterFocusedColumn::Always {
891 self.view_offset =925 self.view_offset =
892- -(self.working_area.size.w - width) / 2 - self.working_area.loc.x;926+ -(self.working_area.size.w - width) / 2. - self.working_area.loc.x;
893 } else {927 } else {
894 // Try to make the code produce a left-aligned offset, even in presence of left928 // Try to make the code produce a left-aligned offset, even in presence of left
895 // exclusive zones.929 // exclusive zones.
@@ -974,6 +1008,7 @@ impl<W: LayoutElement> Workspace<W> {
974 window,1008 window,
975 self.view_size,1009 self.view_size,
976 self.working_area,1010 self.working_area,
1011+ self.scale.fractional_scale(),
977 self.options.clone(),1012 self.options.clone(),
978 width,1013 width,
979 is_full_width,1014 is_full_width,
@@ -1017,6 +1052,7 @@ impl<W: LayoutElement> Workspace<W> {
1017 self.active_column_idx + 11052 self.active_column_idx + 1
1018 };1053 };
1019 1054
1055+ column.update_config(self.scale.fractional_scale(), self.options.clone());
1020 column.set_view_size(self.view_size, self.working_area);1056 column.set_view_size(self.view_size, self.working_area);
1021 let width = column.width();1057 let width = column.width();
1022 self.data.insert(idx, ColumnData::new(&column));1058 self.data.insert(idx, ColumnData::new(&column));
@@ -1028,7 +1064,7 @@ impl<W: LayoutElement> Workspace<W> {
1028 if was_empty {1064 if was_empty {
1029 if self.options.center_focused_column == CenterFocusedColumn::Always {1065 if self.options.center_focused_column == CenterFocusedColumn::Always {
1030 self.view_offset =1066 self.view_offset =
1031- -(self.working_area.size.w - width) / 2 - self.working_area.loc.x;1067+ -(self.working_area.size.w - width) / 2. - self.working_area.loc.x;
1032 } else {1068 } else {
1033 // Try to make the code produce a left-aligned offset, even in presence of left1069 // Try to make the code produce a left-aligned offset, even in presence of left
1034 // exclusive zones.1070 // exclusive zones.
@@ -1294,7 +1330,7 @@ impl<W: LayoutElement> Workspace<W> {
1294 1330
1295 // Move other columns in tandem with resizing.1331 // Move other columns in tandem with resizing.
1296 let started_resize_anim =1332 let started_resize_anim =
1297- column.tiles[tile_idx].resize_animation().is_some() && offset != 0;1333+ column.tiles[tile_idx].resize_animation().is_some() && offset != 0.;
1298 if started_resize_anim {1334 if started_resize_anim {
1299 if self.active_column_idx <= col_idx {1335 if self.active_column_idx <= col_idx {
1300 for col in &mut self.columns[col_idx + 1..] {1336 for col in &mut self.columns[col_idx + 1..] {
@@ -1317,7 +1353,7 @@ impl<W: LayoutElement> Workspace<W> {
1317 // If offset == 0, then don't mess with the view or the gesture. Some clients (Firefox,1353 // If offset == 0, then don't mess with the view or the gesture. Some clients (Firefox,
1318 // Chromium, Electron) currently don't commit after the ack of a configure that drops1354 // Chromium, Electron) currently don't commit after the ack of a configure that drops
1319 // the Resizing state, which can trigger this code path for a while.1355 // the Resizing state, which can trigger this code path for a while.
1320- let resize = if offset != 0 { resize } else { None };1356+ let resize = if offset != 0. { resize } else { None };
1321 if let Some(resize) = resize {1357 if let Some(resize) = resize {
1322 // If this is an interactive resize commit of an active window, then we need to1358 // If this is an interactive resize commit of an active window, then we need to
1323 // either preserve the view offset or adjust it accordingly.1359 // either preserve the view offset or adjust it accordingly.
@@ -1327,17 +1363,17 @@ impl<W: LayoutElement> Workspace<W> {
1327 let offset = if centered {1363 let offset = if centered {
1328 // FIXME: when view_offset becomes fractional, this can be made additive too.1364 // FIXME: when view_offset becomes fractional, this can be made additive too.
1329 let new_offset =1365 let new_offset =
1330- -(self.working_area.size.w - width) / 2 - self.working_area.loc.x;1366+ -(self.working_area.size.w - width) / 2. - self.working_area.loc.x;
1331 new_offset - self.view_offset1367 new_offset - self.view_offset
1332 } else if resize.edges.contains(ResizeEdge::LEFT) {1368 } else if resize.edges.contains(ResizeEdge::LEFT) {
1333 -offset1369 -offset
1334 } else {1370 } else {
1335- 01371+ 0.
1336 };1372 };
1337 1373
1338 self.view_offset += offset;1374 self.view_offset += offset;
1339 if let Some(ViewOffsetAdjustment::Animation(anim)) = &mut self.view_offset_adj {1375 if let Some(ViewOffsetAdjustment::Animation(anim)) = &mut self.view_offset_adj {
1340- anim.offset(offset as f64);1376+ anim.offset(offset);
1341 } else {1377 } else {
1342 // Don't bother with the gesture.1378 // Don't bother with the gesture.
1343 self.view_offset_adj = None;1379 self.view_offset_adj = None;
@@ -1388,7 +1424,7 @@ impl<W: LayoutElement> Workspace<W> {
1388 pub fn store_unmap_snapshot_if_empty(&mut self, renderer: &mut GlesRenderer, window: &W::Id) {1424 pub fn store_unmap_snapshot_if_empty(&mut self, renderer: &mut GlesRenderer, window: &W::Id) {
1389 let output_scale = Scale::from(self.scale.fractional_scale());1425 let output_scale = Scale::from(self.scale.fractional_scale());
1390 let view_size = self.view_size();1426 let view_size = self.view_size();
1391- for (tile, tile_pos) in self.tiles_with_render_positions_mut() {1427+ for (tile, tile_pos) in self.tiles_with_render_positions_mut(false) {
1392 if tile.window().id() == window {1428 if tile.window().id() == window {
1393 let view_pos = Point::from((-tile_pos.x, -tile_pos.y));1429 let view_pos = Point::from((-tile_pos.x, -tile_pos.y));
1394 let view_rect = Rectangle::from_loc_and_size(view_pos, view_size);1430 let view_rect = Rectangle::from_loc_and_size(view_pos, view_size);
@@ -1418,7 +1454,7 @@ impl<W: LayoutElement> Workspace<W> {
1418 let output_scale = Scale::from(self.scale.fractional_scale());1454 let output_scale = Scale::from(self.scale.fractional_scale());
1419 1455
1420 let (tile, mut tile_pos) = self1456 let (tile, mut tile_pos) = self
1421- .tiles_with_render_positions_mut()1457+ .tiles_with_render_positions_mut(false)
1422 .find(|(tile, _)| tile.window().id() == window)1458 .find(|(tile, _)| tile.window().id() == window)
1423 .unwrap();1459 .unwrap();
1424 1460
@@ -1454,8 +1490,11 @@ impl<W: LayoutElement> Workspace<W> {
1454 .data1490 .data
1455 .iter()1491 .iter()
1456 .enumerate()1492 .enumerate()
1457- .filter_map(|(idx, data)| (idx != tile_idx).then_some(data.size.w))1493+ .filter_map(|(idx, data)| {
1494+ (idx != tile_idx).then_some(NotNan::new(data.size.w).unwrap())
1495+ })
1458 .max()1496 .max()
1497+ .map(NotNan::into_inner)
1459 .unwrap()1498 .unwrap()
1460 };1499 };
1461 tile_pos.x -= offset;1500 tile_pos.x -= offset;
@@ -1476,10 +1515,13 @@ impl<W: LayoutElement> Workspace<W> {
1476 1515
1477 #[cfg(test)]1516 #[cfg(test)]
1478 pub fn verify_invariants(&self) {1517 pub fn verify_invariants(&self) {
1479- assert!(self.view_size.w > 0);1518+ use approx::assert_abs_diff_eq;
1480- assert!(self.view_size.h > 0);1519+
1481- assert!(self.scale.fractional_scale() > 0.);1520+ let scale = self.scale.fractional_scale();
1482- assert!(self.scale.fractional_scale().is_finite());1521+ assert!(self.view_size.w > 0.);
1522+ assert!(self.view_size.h > 0.);
1523+ assert!(scale > 0.);
1524+ assert!(scale.is_finite());
1483 assert_eq!(self.columns.len(), self.data.len());1525 assert_eq!(self.columns.len(), self.data.len());
1484 1526
1485 if !self.columns.is_empty() {1527 if !self.columns.is_empty() {
@@ -1487,6 +1529,7 @@ impl<W: LayoutElement> Workspace<W> {
1487 1529
1488 for (column, data) in zip(&self.columns, &self.data) {1530 for (column, data) in zip(&self.columns, &self.data) {
1489 assert!(Rc::ptr_eq(&self.options, &column.options));1531 assert!(Rc::ptr_eq(&self.options, &column.options));
1532+ assert_eq!(self.scale.fractional_scale(), column.scale);
1490 column.verify_invariants();1533 column.verify_invariants();
1491 1534
1492 let mut data2 = *data;1535 let mut data2 = *data;
@@ -1506,6 +1549,14 @@ impl<W: LayoutElement> Workspace<W> {
1506 })1549 })
1507 );1550 );
1508 }1551 }
1552+
1553+ for (_, tile_pos) in self.tiles_with_render_positions() {
1554+ let rounded_pos = tile_pos.to_physical_precise_round(scale).to_logical(scale);
1555+
1556+ // Tile positions must be rounded to physical pixels.
1557+ assert_abs_diff_eq!(tile_pos.x, rounded_pos.x, epsilon = 1e-5);
1558+ assert_abs_diff_eq!(tile_pos.y, rounded_pos.y, epsilon = 1e-5);
1559+ }
1509 }1560 }
1510 1561
1511 if let Some(resize) = &self.interactive_resize {1562 if let Some(resize) = &self.interactive_resize {
@@ -1599,7 +1650,7 @@ impl<W: LayoutElement> Workspace<W> {
1599 let view_offset_delta = -self.column_x(self.active_column_idx) + current_col_x;1650 let view_offset_delta = -self.column_x(self.active_column_idx) + current_col_x;
1600 self.view_offset += view_offset_delta;1651 self.view_offset += view_offset_delta;
1601 if let Some(ViewOffsetAdjustment::Animation(anim)) = &mut self.view_offset_adj {1652 if let Some(ViewOffsetAdjustment::Animation(anim)) = &mut self.view_offset_adj {
1602- anim.offset(view_offset_delta as f64);1653+ anim.offset(view_offset_delta);
1603 }1654 }
1604 1655
1605 // The column we just moved is offset by the difference between its new and old position.1656 // The column we just moved is offset by the difference between its new and old position.
@@ -1679,7 +1730,7 @@ impl<W: LayoutElement> Workspace<W> {
1679 }1730 }
1680 1731
1681 let offset = self.column_x(source_col_idx) - self.column_x(source_col_idx - 1);1732 let offset = self.column_x(source_col_idx) - self.column_x(source_col_idx - 1);
1682- let mut offset = Point::from((offset, 0));1733+ let mut offset = Point::from((offset, 0.));
1683 1734
1684 // Move into adjacent column.1735 // Move into adjacent column.
1685 let target_column_idx = source_col_idx - 1;1736 let target_column_idx = source_col_idx - 1;
@@ -1720,7 +1771,7 @@ impl<W: LayoutElement> Workspace<W> {
1720 let width = source_column.width;1771 let width = source_column.width;
1721 let is_full_width = source_column.is_full_width;1772 let is_full_width = source_column.is_full_width;
1722 1773
1723- let mut offset = Point::from((source_column.render_offset().x, 0));1774+ let mut offset = Point::from((source_column.render_offset().x, 0.));
1724 1775
1725 let tile = self.remove_tile_by_idx(source_col_idx, source_column.active_tile_idx, None);1776 let tile = self.remove_tile_by_idx(source_col_idx, source_column.active_tile_idx, None);
1726 1777
@@ -1749,7 +1800,7 @@ impl<W: LayoutElement> Workspace<W> {
1749 1800
1750 let source_col_idx = self.active_column_idx;1801 let source_col_idx = self.active_column_idx;
1751 let offset = self.column_x(source_col_idx) - self.column_x(source_col_idx + 1);1802 let offset = self.column_x(source_col_idx) - self.column_x(source_col_idx + 1);
1752- let mut offset = Point::from((offset, 0));1803+ let mut offset = Point::from((offset, 0.));
1753 1804
1754 let source_column = &self.columns[source_col_idx];1805 let source_column = &self.columns[source_col_idx];
1755 offset.x += source_column.render_offset().x;1806 offset.x += source_column.render_offset().x;
@@ -1827,7 +1878,7 @@ impl<W: LayoutElement> Workspace<W> {
1827 let offset = self.column_x(source_column_idx)1878 let offset = self.column_x(source_column_idx)
1828 + self.columns[source_column_idx].render_offset().x1879 + self.columns[source_column_idx].render_offset().x
1829 - self.column_x(self.active_column_idx);1880 - self.column_x(self.active_column_idx);
1830- let mut offset = Point::from((offset, 0));1881+ let mut offset = Point::from((offset, 0.));
1831 let prev_off = self.columns[source_column_idx].tile_offset(0);1882 let prev_off = self.columns[source_column_idx].tile_offset(0);
1832 1883
1833 let tile = self.remove_tile_by_idx(source_column_idx, 0, None);1884 let tile = self.remove_tile_by_idx(source_column_idx, 0, None);
@@ -1867,7 +1918,7 @@ impl<W: LayoutElement> Workspace<W> {
1867 1918
1868 let offset =1919 let offset =
1869 self.column_x(self.active_column_idx) - self.column_x(self.active_column_idx + 1);1920 self.column_x(self.active_column_idx) - self.column_x(self.active_column_idx + 1);
1870- let mut offset = Point::from((offset, 0));1921+ let mut offset = Point::from((offset, 0.));
1871 1922
1872 let source_column = &self.columns[self.active_column_idx];1923 let source_column = &self.columns[self.active_column_idx];
1873 if source_column.tiles.len() == 1 {1924 if source_column.tiles.len() == 1 {
@@ -1909,17 +1960,17 @@ impl<W: LayoutElement> Workspace<W> {
1909 }1960 }
1910 }1961 }
1911 1962
1912- fn view_pos(&self) -> i32 {1963+ fn view_pos(&self) -> f64 {
1913 self.column_x(self.active_column_idx) + self.view_offset1964 self.column_x(self.active_column_idx) + self.view_offset
1914 }1965 }
1915 1966
1916 /// Returns a view offset value suitable for saving and later restoration.1967 /// Returns a view offset value suitable for saving and later restoration.
1917 ///1968 ///
1918 /// This means that it shouldn't return an in-progress animation or gesture value.1969 /// This means that it shouldn't return an in-progress animation or gesture value.
1919- fn static_view_offset(&self) -> i32 {1970+ fn static_view_offset(&self) -> f64 {
1920 match &self.view_offset_adj {1971 match &self.view_offset_adj {
1921 // For animations we can return the final value.1972 // For animations we can return the final value.
1922- Some(ViewOffsetAdjustment::Animation(anim)) => anim.to().round() as i32,1973+ Some(ViewOffsetAdjustment::Animation(anim)) => anim.to(),
1923 Some(ViewOffsetAdjustment::Gesture(gesture)) => gesture.static_view_offset,1974 Some(ViewOffsetAdjustment::Gesture(gesture)) => gesture.static_view_offset,
1924 _ => self.view_offset,1975 _ => self.view_offset,
1925 }1976 }
@@ -1927,12 +1978,12 @@ impl<W: LayoutElement> Workspace<W> {
1927 1978
1928 // HACK: pass a self.data iterator in manually as a workaround for the lack of method partial1979 // HACK: pass a self.data iterator in manually as a workaround for the lack of method partial
1929 // borrowing. Note that this method's return value does not borrow the entire &Self!1980 // borrowing. Note that this method's return value does not borrow the entire &Self!
1930- fn column_xs(&self, data: impl Iterator<Item = ColumnData>) -> impl Iterator<Item = i32> {1981+ fn column_xs(&self, data: impl Iterator<Item = ColumnData>) -> impl Iterator<Item = f64> {
1931 let gaps = self.options.gaps;1982 let gaps = self.options.gaps;
1932- let mut x = 0;1983+ let mut x = 0.;
1933 1984
1934 // Chain with a dummy value to be able to get one past all columns' X.1985 // Chain with a dummy value to be able to get one past all columns' X.
1935- let dummy = ColumnData { width: 0 };1986+ let dummy = ColumnData { width: 0. };
1936 let data = data.chain(iter::once(dummy));1987 let data = data.chain(iter::once(dummy));
1937 1988
1938 data.map(move |data| {1989 data.map(move |data| {
@@ -1942,7 +1993,7 @@ impl<W: LayoutElement> Workspace<W> {
1942 })1993 })
1943 }1994 }
1944 1995
1945- fn column_x(&self, column_idx: usize) -> i32 {1996+ fn column_x(&self, column_idx: usize) -> f64 {
1946 self.column_xs(self.data.iter().copied())1997 self.column_xs(self.data.iter().copied())
1947 .nth(column_idx)1998 .nth(column_idx)
1948 .unwrap()1999 .unwrap()
@@ -1951,7 +2002,7 @@ impl<W: LayoutElement> Workspace<W> {
1951 fn column_xs_in_render_order(2002 fn column_xs_in_render_order(
1952 &self,2003 &self,
1953 data: impl Iterator<Item = ColumnData>,2004 data: impl Iterator<Item = ColumnData>,
1954- ) -> impl Iterator<Item = i32> {2005+ ) -> impl Iterator<Item = f64> {
1955 let active_idx = self.active_column_idx;2006 let active_idx = self.active_column_idx;
1956 let active_pos = self.column_x(active_idx);2007 let active_pos = self.column_x(active_idx);
1957 let offsets = self2008 let offsets = self
@@ -1961,12 +2012,12 @@ impl<W: LayoutElement> Workspace<W> {
1961 iter::once(active_pos).chain(offsets)2012 iter::once(active_pos).chain(offsets)
1962 }2013 }
1963 2014
1964- fn columns_mut(&mut self) -> impl Iterator<Item = (&mut Column<W>, i32)> + '_ {2015+ fn columns_mut(&mut self) -> impl Iterator<Item = (&mut Column<W>, f64)> + '_ {
1965 let offsets = self.column_xs(self.data.iter().copied());2016 let offsets = self.column_xs(self.data.iter().copied());
1966 zip(&mut self.columns, offsets)2017 zip(&mut self.columns, offsets)
1967 }2018 }
1968 2019
1969- fn columns_in_render_order(&self) -> impl Iterator<Item = (&Column<W>, i32)> + '_ {2020+ fn columns_in_render_order(&self) -> impl Iterator<Item = (&Column<W>, f64)> + '_ {
1970 let offsets = self.column_xs_in_render_order(self.data.iter().copied());2021 let offsets = self.column_xs_in_render_order(self.data.iter().copied());
1971 2022
1972 let (first, rest) = self.columns.split_at(self.active_column_idx);2023 let (first, rest) = self.columns.split_at(self.active_column_idx);
@@ -1976,7 +2027,7 @@ impl<W: LayoutElement> Workspace<W> {
1976 zip(tiles, offsets)2027 zip(tiles, offsets)
1977 }2028 }
1978 2029
1979- fn columns_in_render_order_mut(&mut self) -> impl Iterator<Item = (&mut Column<W>, i32)> + '_ {2030+ fn columns_in_render_order_mut(&mut self) -> impl Iterator<Item = (&mut Column<W>, f64)> + '_ {
1980 let offsets = self.column_xs_in_render_order(self.data.iter().copied());2031 let offsets = self.column_xs_in_render_order(self.data.iter().copied());
1981 2032
1982 let (first, rest) = self.columns.split_at_mut(self.active_column_idx);2033 let (first, rest) = self.columns.split_at_mut(self.active_column_idx);
@@ -1986,14 +2037,17 @@ impl<W: LayoutElement> Workspace<W> {
1986 zip(tiles, offsets)2037 zip(tiles, offsets)
1987 }2038 }
1988 2039
1989- fn tiles_with_render_positions(&self) -> impl Iterator<Item = (&Tile<W>, Point<i32, Logical>)> {2040+ fn tiles_with_render_positions(&self) -> impl Iterator<Item = (&Tile<W>, Point<f64, Logical>)> {
1990- let view_off = Point::from((-self.view_pos(), 0));2041+ let scale = self.scale.fractional_scale();
2042+ let view_off = Point::from((-self.view_pos(), 0.));
1991 self.columns_in_render_order()2043 self.columns_in_render_order()
1992 .flat_map(move |(col, col_x)| {2044 .flat_map(move |(col, col_x)| {
1993- let col_off = Point::from((col_x, 0));2045+ let col_off = Point::from((col_x, 0.));
1994 let col_render_off = col.render_offset();2046 let col_render_off = col.render_offset();
1995 col.tiles_in_render_order().map(move |(tile, tile_off)| {2047 col.tiles_in_render_order().map(move |(tile, tile_off)| {
1996 let pos = view_off + col_off + col_render_off + tile_off + tile.render_offset();2048 let pos = view_off + col_off + col_render_off + tile_off + tile.render_offset();
2049+ // Round to physical pixels.
2050+ let pos = pos.to_physical_precise_round(scale).to_logical(scale);
1997 (tile, pos)2051 (tile, pos)
1998 })2052 })
1999 })2053 })
@@ -2001,16 +2055,22 @@ impl<W: LayoutElement> Workspace<W> {
2001 2055
2002 fn tiles_with_render_positions_mut(2056 fn tiles_with_render_positions_mut(
2003 &mut self,2057 &mut self,
2004- ) -> impl Iterator<Item = (&mut Tile<W>, Point<i32, Logical>)> {2058+ round: bool,
2005- let view_off = Point::from((-self.view_pos(), 0));2059+ ) -> impl Iterator<Item = (&mut Tile<W>, Point<f64, Logical>)> {
2060+ let scale = self.scale.fractional_scale();
2061+ let view_off = Point::from((-self.view_pos(), 0.));
2006 self.columns_in_render_order_mut()2062 self.columns_in_render_order_mut()
2007 .flat_map(move |(col, col_x)| {2063 .flat_map(move |(col, col_x)| {
2008- let col_off = Point::from((col_x, 0));2064+ let col_off = Point::from((col_x, 0.));
2009 let col_render_off = col.render_offset();2065 let col_render_off = col.render_offset();
2010 col.tiles_in_render_order_mut()2066 col.tiles_in_render_order_mut()
2011 .map(move |(tile, tile_off)| {2067 .map(move |(tile, tile_off)| {
2012- let pos =2068+ let mut pos =
2013 view_off + col_off + col_render_off + tile_off + tile.render_offset();2069 view_off + col_off + col_render_off + tile_off + tile.render_offset();
2070+ // Round to physical pixels.
2071+ if round {
2072+ pos = pos.to_physical_precise_round(scale).to_logical(scale);
2073+ }
2014 (tile, pos)2074 (tile, pos)
2015 })2075 })
2016 })2076 })
@@ -2019,14 +2079,14 @@ impl<W: LayoutElement> Workspace<W> {
2019 /// Returns the geometry of the active tile relative to and clamped to the view.2079 /// Returns the geometry of the active tile relative to and clamped to the view.
2020 ///2080 ///
2021 /// During animations, assumes the final view position.2081 /// During animations, assumes the final view position.
2022- pub fn active_tile_visual_rectangle(&self) -> Option<Rectangle<i32, Logical>> {2082+ pub fn active_tile_visual_rectangle(&self) -> Option<Rectangle<f64, Logical>> {
2023 let col = self.columns.get(self.active_column_idx)?;2083 let col = self.columns.get(self.active_column_idx)?;
2024 2084
2025 let final_view_offset = self2085 let final_view_offset = self
2026 .view_offset_adj2086 .view_offset_adj
2027 .as_ref()2087 .as_ref()
2028- .map_or(self.view_offset, |adj| adj.target_view_offset() as i32);2088+ .map_or(self.view_offset, |adj| adj.target_view_offset());
2029- let view_off = Point::from((-final_view_offset, 0));2089+ let view_off = Point::from((-final_view_offset, 0.));
2030 2090
2031 let (tile, tile_off) = col.tiles().nth(col.active_tile_idx).unwrap();2091 let (tile, tile_off) = col.tiles().nth(col.active_tile_idx).unwrap();
2032 2092
@@ -2034,21 +2094,21 @@ impl<W: LayoutElement> Workspace<W> {
2034 let tile_size = tile.tile_size();2094 let tile_size = tile.tile_size();
2035 let tile_rect = Rectangle::from_loc_and_size(tile_pos, tile_size);2095 let tile_rect = Rectangle::from_loc_and_size(tile_pos, tile_size);
2036 2096
2037- let view = Rectangle::from_loc_and_size((0, 0), self.view_size);2097+ let view = Rectangle::from_loc_and_size((0., 0.), self.view_size);
2038 view.intersection(tile_rect)2098 view.intersection(tile_rect)
2039 }2099 }
2040 2100
2041 pub fn window_under(2101 pub fn window_under(
2042 &self,2102 &self,
2043 pos: Point<f64, Logical>,2103 pos: Point<f64, Logical>,
2044- ) -> Option<(&W, Option<Point<i32, Logical>>)> {2104+ ) -> Option<(&W, Option<Point<f64, Logical>>)> {
2045 if self.columns.is_empty() {2105 if self.columns.is_empty() {
2046 return None;2106 return None;
2047 }2107 }
2048 2108
2049 self.tiles_with_render_positions()2109 self.tiles_with_render_positions()
2050 .find_map(|(tile, tile_pos)| {2110 .find_map(|(tile, tile_pos)| {
2051- let pos_within_tile = pos - tile_pos.to_f64();2111+ let pos_within_tile = pos - tile_pos;
2052 2112
2053 if tile.is_in_input_region(pos_within_tile) {2113 if tile.is_in_input_region(pos_within_tile) {
2054 let pos_within_surface = tile_pos + tile.buf_loc();2114 let pos_within_surface = tile_pos + tile.buf_loc();
@@ -2068,7 +2128,7 @@ impl<W: LayoutElement> Workspace<W> {
2068 2128
2069 self.tiles_with_render_positions()2129 self.tiles_with_render_positions()
2070 .find_map(|(tile, tile_pos)| {2130 .find_map(|(tile, tile_pos)| {
2071- let pos_within_tile = pos - tile_pos.to_f64();2131+ let pos_within_tile = pos - tile_pos;
2072 2132
2073 // This logic should be consistent with window_under() in when it returns Some vs.2133 // This logic should be consistent with window_under() in when it returns Some vs.
2074 // None.2134 // None.
@@ -2190,6 +2250,7 @@ impl<W: LayoutElement> Workspace<W> {
2190 window,2250 window,
2191 self.view_size,2251 self.view_size,
2192 self.working_area,2252 self.working_area,
2253+ self.scale.fractional_scale(),
2193 self.options.clone(),2254 self.options.clone(),
2194 width,2255 width,
2195 is_full_width,2256 is_full_width,
@@ -2256,7 +2317,7 @@ impl<W: LayoutElement> Workspace<W> {
2256 let mut rv = vec![];2317 let mut rv = vec![];
2257 2318
2258 // Draw the closing windows on top.2319 // Draw the closing windows on top.
2259- let view_rect = Rectangle::from_loc_and_size((self.view_pos(), 0), self.view_size);2320+ let view_rect = Rectangle::from_loc_and_size((self.view_pos(), 0.), self.view_size);
2260 for closing in self.closing_windows.iter().rev() {2321 for closing in self.closing_windows.iter().rev() {
2261 let elem = closing.render(renderer.as_gles_renderer(), view_rect, output_scale, target);2322 let elem = closing.render(renderer.as_gles_renderer(), view_rect, output_scale, target);
2262 rv.push(elem.into());2323 rv.push(elem.into());
@@ -2291,9 +2352,9 @@ impl<W: LayoutElement> Workspace<W> {
2291 }2352 }
2292 2353
2293 let gesture = ViewGesture {2354 let gesture = ViewGesture {
2294- current_view_offset: self.view_offset as f64,2355+ current_view_offset: self.view_offset,
2295 tracker: SwipeTracker::new(),2356 tracker: SwipeTracker::new(),
2296- delta_from_tracker: self.view_offset as f64,2357+ delta_from_tracker: self.view_offset,
2297 static_view_offset: self.static_view_offset(),2358 static_view_offset: self.static_view_offset(),
2298 is_touchpad,2359 is_touchpad,
2299 };2360 };
@@ -2317,7 +2378,7 @@ impl<W: LayoutElement> Workspace<W> {
2317 gesture.tracker.push(delta_x, timestamp);2378 gesture.tracker.push(delta_x, timestamp);
2318 2379
2319 let norm_factor = if gesture.is_touchpad {2380 let norm_factor = if gesture.is_touchpad {
2320- self.working_area.size.w as f64 / VIEW_GESTURE_WORKING_AREA_MOVEMENT2381+ self.working_area.size.w / VIEW_GESTURE_WORKING_AREA_MOVEMENT
2321 } else {2382 } else {
2322 1.2383 1.
2323 };2384 };
@@ -2343,7 +2404,7 @@ impl<W: LayoutElement> Workspace<W> {
2343 // effort and bug potential.2404 // effort and bug potential.
2344 2405
2345 let norm_factor = if gesture.is_touchpad {2406 let norm_factor = if gesture.is_touchpad {
2346- self.working_area.size.w as f64 / VIEW_GESTURE_WORKING_AREA_MOVEMENT2407+ self.working_area.size.w / VIEW_GESTURE_WORKING_AREA_MOVEMENT
2347 } else {2408 } else {
2348 1.2409 1.
2349 };2410 };
@@ -2352,7 +2413,7 @@ impl<W: LayoutElement> Workspace<W> {
2352 let current_view_offset = pos + gesture.delta_from_tracker;2413 let current_view_offset = pos + gesture.delta_from_tracker;
2353 2414
2354 if self.columns.is_empty() {2415 if self.columns.is_empty() {
2355- self.view_offset = current_view_offset.round() as i32;2416+ self.view_offset = current_view_offset;
2356 self.view_offset_adj = None;2417 self.view_offset_adj = None;
2357 return true;2418 return true;
2358 }2419 }
@@ -2365,7 +2426,7 @@ impl<W: LayoutElement> Workspace<W> {
2365 // either side.2426 // either side.
2366 struct Snap {2427 struct Snap {
2367 // View position relative to x = 0 (the first column).2428 // View position relative to x = 0 (the first column).
2368- view_pos: i32,2429+ view_pos: f64,
2369 // Column to activate for this snapping point.2430 // Column to activate for this snapping point.
2370 col_idx: usize,2431 col_idx: usize,
2371 }2432 }
@@ -2376,7 +2437,7 @@ impl<W: LayoutElement> Workspace<W> {
2376 let right_strut = self.view_size.w - self.working_area.size.w - self.working_area.loc.x;2437 let right_strut = self.view_size.w - self.working_area.size.w - self.working_area.loc.x;
2377 2438
2378 if self.options.center_focused_column == CenterFocusedColumn::Always {2439 if self.options.center_focused_column == CenterFocusedColumn::Always {
2379- let mut col_x = 0;2440+ let mut col_x = 0.;
2380 for (col_idx, col) in self.columns.iter().enumerate() {2441 for (col_idx, col) in self.columns.iter().enumerate() {
2381 let col_w = col.width();2442 let col_w = col.width();
2382 2443
@@ -2385,7 +2446,7 @@ impl<W: LayoutElement> Workspace<W> {
2385 } else if self.working_area.size.w <= col_w {2446 } else if self.working_area.size.w <= col_w {
2386 col_x - left_strut2447 col_x - left_strut
2387 } else {2448 } else {
2388- col_x - (self.working_area.size.w - col_w) / 2 - left_strut2449+ col_x - (self.working_area.size.w - col_w) / 2. - left_strut
2389 };2450 };
2390 snapping_points.push(Snap { view_pos, col_idx });2451 snapping_points.push(Snap { view_pos, col_idx });
2391 2452
@@ -2404,7 +2465,7 @@ impl<W: LayoutElement> Workspace<W> {
2404 });2465 });
2405 };2466 };
2406 2467
2407- let mut col_x = 0;2468+ let mut col_x = 0.;
2408 for (col_idx, col) in self.columns.iter().enumerate() {2469 for (col_idx, col) in self.columns.iter().enumerate() {
2409 let col_w = col.width();2470 let col_w = col.width();
2410 2471
@@ -2417,7 +2478,7 @@ impl<W: LayoutElement> Workspace<W> {
2417 } else {2478 } else {
2418 // Logic from compute_new_view_offset.2479 // Logic from compute_new_view_offset.
2419 let padding =2480 let padding =
2420- ((self.working_area.size.w - col_w) / 2).clamp(0, self.options.gaps);2481+ ((self.working_area.size.w - col_w) / 2.).clamp(0., self.options.gaps);
2421 let left = col_x - padding - left_strut;2482 let left = col_x - padding - left_strut;
2422 let right = col_x + col_w + padding + right_strut;2483 let right = col_x + col_w + padding + right_strut;
2423 push(col_idx, left, right);2484 push(col_idx, left, right);
@@ -2428,13 +2489,13 @@ impl<W: LayoutElement> Workspace<W> {
2428 }2489 }
2429 2490
2430 // Find the closest snapping point.2491 // Find the closest snapping point.
2431- snapping_points.sort_by_key(|snap| snap.view_pos);2492+ snapping_points.sort_by_key(|snap| NotNan::new(snap.view_pos).unwrap());
2432 2493
2433 let active_col_x = self.column_x(self.active_column_idx);2494 let active_col_x = self.column_x(self.active_column_idx);
2434- let target_view_pos = (active_col_x as f64 + target_view_offset).round() as i32;2495+ let target_view_pos = active_col_x + target_view_offset;
2435 let target_snap = snapping_points2496 let target_snap = snapping_points
2436 .iter()2497 .iter()
2437- .min_by_key(|snap| snap.view_pos.abs_diff(target_view_pos))2498+ .min_by_key(|snap| NotNan::new((snap.view_pos - target_view_pos).abs()).unwrap())
2438 .unwrap();2499 .unwrap();
2439 2500
2440 let mut new_col_idx = target_snap.col_idx;2501 let mut new_col_idx = target_snap.col_idx;
@@ -2453,7 +2514,7 @@ impl<W: LayoutElement> Workspace<W> {
2453 }2514 }
2454 } else {2515 } else {
2455 let padding =2516 let padding =
2456- ((self.working_area.size.w - col_w) / 2).clamp(0, self.options.gaps);2517+ ((self.working_area.size.w - col_w) / 2.).clamp(0., self.options.gaps);
2457 if target_snap.view_pos + left_strut + self.working_area.size.w2518 if target_snap.view_pos + left_strut + self.working_area.size.w
2458 < col_x + col_w + padding2519 < col_x + col_w + padding
2459 {2520 {
@@ -2475,7 +2536,7 @@ impl<W: LayoutElement> Workspace<W> {
2475 }2536 }
2476 } else {2537 } else {
2477 let padding =2538 let padding =
2478- ((self.working_area.size.w - col_w) / 2).clamp(0, self.options.gaps);2539+ ((self.working_area.size.w - col_w) / 2.).clamp(0., self.options.gaps);
2479 if col_x - padding < target_snap.view_pos + left_strut {2540 if col_x - padding < target_snap.view_pos + left_strut {
2480 break;2541 break;
2481 }2542 }
@@ -2487,8 +2548,8 @@ impl<W: LayoutElement> Workspace<W> {
2487 }2548 }
2488 2549
2489 let new_col_x = self.column_x(new_col_idx);2550 let new_col_x = self.column_x(new_col_idx);
2490- let delta = (active_col_x - new_col_x) as f64;2551+ let delta = active_col_x - new_col_x;
2491- self.view_offset = (current_view_offset + delta).round() as i32;2552+ self.view_offset = current_view_offset + delta;
2492 2553
2493 if self.active_column_idx != new_col_idx {2554 if self.active_column_idx != new_col_idx {
2494 self.view_offset_before_fullscreen = None;2555 self.view_offset_before_fullscreen = None;
@@ -2500,7 +2561,7 @@ impl<W: LayoutElement> Workspace<W> {
2500 2561
2501 self.view_offset_adj = Some(ViewOffsetAdjustment::Animation(Animation::new(2562 self.view_offset_adj = Some(ViewOffsetAdjustment::Animation(Animation::new(
2502 current_view_offset + delta,2563 current_view_offset + delta,
2503- target_view_offset as f64,2564+ target_view_offset,
2504 velocity,2565 velocity,
2505 self.options.animations.horizontal_view_movement.0,2566 self.options.animations.horizontal_view_movement.0,
2506 )));2567 )));
@@ -2578,7 +2639,7 @@ impl<W: LayoutElement> Workspace<W> {
2578 dx *= 2.;2639 dx *= 2.;
2579 }2640 }
2580 2641
2581- let window_width = (f64::from(resize.original_window_size.w) + dx).round() as i32;2642+ let window_width = (resize.original_window_size.w + dx).round() as i32;
2582 col.set_column_width(SizeChange::SetFixed(window_width), Some(tile_idx), false);2643 col.set_column_width(SizeChange::SetFixed(window_width), Some(tile_idx), false);
2583 }2644 }
2584 2645
@@ -2594,7 +2655,7 @@ impl<W: LayoutElement> Workspace<W> {
2594 // FIXME: some smarter height distribution would be nice here so that vertical2655 // FIXME: some smarter height distribution would be nice here so that vertical
2595 // resizes work as expected in more cases.2656 // resizes work as expected in more cases.
2596 2657
2597- let window_height = (f64::from(resize.original_window_size.h) + dy).round() as i32;2658+ let window_height = (resize.original_window_size.h + dy).round() as i32;
2598 col.set_window_height(SizeChange::SetFixed(window_height), Some(tile_idx), false);2659 col.set_window_height(SizeChange::SetFixed(window_height), Some(tile_idx), false);
2599 }2660 }
2600 }2661 }
@@ -2657,20 +2718,23 @@ impl<W: LayoutElement> Workspace<W> {
2657 }2718 }
2658 2719
2659 impl<W: LayoutElement> Column<W> {2720 impl<W: LayoutElement> Column<W> {
2721+ #[allow(clippy::too_many_arguments)]
2660 fn new(2722 fn new(
2661 window: W,2723 window: W,
2662- view_size: Size<i32, Logical>,2724+ view_size: Size<f64, Logical>,
2663- working_area: Rectangle<i32, Logical>,2725+ working_area: Rectangle<f64, Logical>,
2726+ scale: f64,
2664 options: Rc<Options>,2727 options: Rc<Options>,
2665 width: ColumnWidth,2728 width: ColumnWidth,
2666 is_full_width: bool,2729 is_full_width: bool,
2667 animate_resize: bool,2730 animate_resize: bool,
2668 ) -> Self {2731 ) -> Self {
2669- let tile = Tile::new(window, options.clone());2732+ let tile = Tile::new(window, scale, options.clone());
2670 Self::new_with_tile(2733 Self::new_with_tile(
2671 tile,2734 tile,
2672 view_size,2735 view_size,
2673 working_area,2736 working_area,
2737+ scale,
2674 options,2738 options,
2675 width,2739 width,
2676 is_full_width,2740 is_full_width,
@@ -2678,10 +2742,12 @@ impl<W: LayoutElement> Column<W> {
2678 )2742 )
2679 }2743 }
2680 2744
2745+ #[allow(clippy::too_many_arguments)]
2681 fn new_with_tile(2746 fn new_with_tile(
2682 tile: Tile<W>,2747 tile: Tile<W>,
2683- view_size: Size<i32, Logical>,2748+ view_size: Size<f64, Logical>,
2684- working_area: Rectangle<i32, Logical>,2749+ working_area: Rectangle<f64, Logical>,
2750+ scale: f64,
2685 options: Rc<Options>,2751 options: Rc<Options>,
2686 width: ColumnWidth,2752 width: ColumnWidth,
2687 is_full_width: bool,2753 is_full_width: bool,
@@ -2697,6 +2763,7 @@ impl<W: LayoutElement> Column<W> {
2697 move_animation: None,2763 move_animation: None,
2698 view_size,2764 view_size,
2699 working_area,2765 working_area,
2766+ scale,
2700 options,2767 options,
2701 };2768 };
2702 2769
@@ -2711,7 +2778,7 @@ impl<W: LayoutElement> Column<W> {
2711 rv2778 rv
2712 }2779 }
2713 2780
2714- fn set_view_size(&mut self, size: Size<i32, Logical>, working_area: Rectangle<i32, Logical>) {2781+ fn set_view_size(&mut self, size: Size<f64, Logical>, working_area: Rectangle<f64, Logical>) {
2715 if self.view_size == size && self.working_area == working_area {2782 if self.view_size == size && self.working_area == working_area {
2716 return;2783 return;
2717 }2784 }
@@ -2722,7 +2789,7 @@ impl<W: LayoutElement> Column<W> {
2722 self.update_tile_sizes(false);2789 self.update_tile_sizes(false);
2723 }2790 }
2724 2791
2725- fn update_config(&mut self, options: Rc<Options>) {2792+ fn update_config(&mut self, scale: f64, options: Rc<Options>) {
2726 let mut update_sizes = false;2793 let mut update_sizes = false;
2727 2794
2728 // If preset widths changed, make our width non-preset.2795 // If preset widths changed, make our width non-preset.
@@ -2743,10 +2810,11 @@ impl<W: LayoutElement> Column<W> {
2743 }2810 }
2744 2811
2745 for (tile, data) in zip(&mut self.tiles, &mut self.data) {2812 for (tile, data) in zip(&mut self.tiles, &mut self.data) {
2746- tile.update_config(options.clone());2813+ tile.update_config(scale, options.clone());
2747 data.update(tile);2814 data.update(tile);
2748 }2815 }
2749 2816
2817+ self.scale = scale;
2750 self.options = options;2818 self.options = options;
2751 2819
2752 if update_sizes {2820 if update_sizes {
@@ -2780,7 +2848,7 @@ impl<W: LayoutElement> Column<W> {
2780 self.move_animation.is_some() || self.tiles.iter().any(Tile::are_animations_ongoing)2848 self.move_animation.is_some() || self.tiles.iter().any(Tile::are_animations_ongoing)
2781 }2849 }
2782 2850
2783- pub fn update_render_elements(&mut self, is_active: bool, view_rect: Rectangle<i32, Logical>) {2851+ pub fn update_render_elements(&mut self, is_active: bool, view_rect: Rectangle<f64, Logical>) {
2784 let active_idx = self.active_tile_idx;2852 let active_idx = self.active_tile_idx;
2785 for (tile_idx, (tile, tile_off)) in self.tiles_mut().enumerate() {2853 for (tile_idx, (tile, tile_off)) in self.tiles_mut().enumerate() {
2786 let is_active = is_active && tile_idx == active_idx;2854 let is_active = is_active && tile_idx == active_idx;
@@ -2791,17 +2859,17 @@ impl<W: LayoutElement> Column<W> {
2791 }2859 }
2792 }2860 }
2793 2861
2794- pub fn render_offset(&self) -> Point<i32, Logical> {2862+ pub fn render_offset(&self) -> Point<f64, Logical> {
2795 let mut offset = Point::from((0., 0.));2863 let mut offset = Point::from((0., 0.));
2796 2864
2797 if let Some(anim) = &self.move_animation {2865 if let Some(anim) = &self.move_animation {
2798 offset.x += anim.value();2866 offset.x += anim.value();
2799 }2867 }
2800 2868
2801- offset.to_i32_round()2869+ offset
2802 }2870 }
2803 2871
2804- pub fn animate_move_from(&mut self, from_x_offset: i32) {2872+ pub fn animate_move_from(&mut self, from_x_offset: f64) {
2805 self.animate_move_from_with_config(2873 self.animate_move_from_with_config(
2806 from_x_offset,2874 from_x_offset,
2807 self.options.animations.window_movement.0,2875 self.options.animations.window_movement.0,
@@ -2810,13 +2878,13 @@ impl<W: LayoutElement> Column<W> {
2810 2878
2811 pub fn animate_move_from_with_config(2879 pub fn animate_move_from_with_config(
2812 &mut self,2880 &mut self,
2813- from_x_offset: i32,2881+ from_x_offset: f64,
2814 config: niri_config::Animation,2882 config: niri_config::Animation,
2815 ) {2883 ) {
2816 let current_offset = self.move_animation.as_ref().map_or(0., Animation::value);2884 let current_offset = self.move_animation.as_ref().map_or(0., Animation::value);
2817 2885
2818 self.move_animation = Some(Animation::new(2886 self.move_animation = Some(Animation::new(
2819- f64::from(from_x_offset) + current_offset,2887+ from_x_offset + current_offset,
2820 0.,2888 0.,
2821 0.,2889 0.,
2822 config,2890 config,
@@ -2857,17 +2925,17 @@ impl<W: LayoutElement> Column<W> {
2857 .find(|(_, tile)| tile.window().id() == window)2925 .find(|(_, tile)| tile.window().id() == window)
2858 .unwrap();2926 .unwrap();
2859 2927
2860- let height = tile.window().size().h;2928+ let height = f64::from(tile.window().size().h);
2861 let offset = tile2929 let offset = tile
2862 .window()2930 .window()
2863 .animation_snapshot()2931 .animation_snapshot()
2864- .map_or(0, |from| from.size.h - height);2932+ .map_or(0., |from| from.size.h - height);
2865 2933
2866 tile.update_window();2934 tile.update_window();
2867 self.data[tile_idx].update(tile);2935 self.data[tile_idx].update(tile);
2868 2936
2869 // Move windows below in tandem with resizing.2937 // Move windows below in tandem with resizing.
2870- if tile.resize_animation().is_some() && offset != 0 {2938+ if tile.resize_animation().is_some() && offset != 0. {
2871 for tile in &mut self.tiles[tile_idx + 1..] {2939 for tile in &mut self.tiles[tile_idx + 1..] {
2872 tile.animate_move_y_from_with_config(2940 tile.animate_move_y_from_with_config(
2873 offset,2941 offset,
@@ -2891,27 +2959,29 @@ impl<W: LayoutElement> Column<W> {
2891 .iter()2959 .iter()
2892 .filter_map(|size| {2960 .filter_map(|size| {
2893 let w = size.w;2961 let w = size.w;
2894- if w == 0 {2962+ if w == 0. {
2895 None2963 None
2896 } else {2964 } else {
2897- Some(w)2965+ Some(NotNan::new(w).unwrap())
2898 }2966 }
2899 })2967 })
2900 .max()2968 .max()
2901- .unwrap_or(1);2969+ .map(NotNan::into_inner)
2970+ .unwrap_or(1.);
2902 let max_width = max_size2971 let max_width = max_size
2903 .iter()2972 .iter()
2904 .filter_map(|size| {2973 .filter_map(|size| {
2905 let w = size.w;2974 let w = size.w;
2906- if w == 0 {2975+ if w == 0. {
2907 None2976 None
2908 } else {2977 } else {
2909- Some(w)2978+ Some(NotNan::new(w).unwrap())
2910 }2979 }
2911 })2980 })
2912 .min()2981 .min()
2913- .unwrap_or(i32::MAX);2982+ .map(NotNan::into_inner)
2914- let max_width = max(max_width, min_width);2983+ .unwrap_or(f64::from(i32::MAX));
2984+ let max_width = f64::max(max_width, min_width);
2915 2985
2916 let width = if self.is_full_width {2986 let width = if self.is_full_width {
2917 ColumnWidth::Proportion(1.)2987 ColumnWidth::Proportion(1.)
@@ -2920,7 +2990,7 @@ impl<W: LayoutElement> Column<W> {
2920 };2990 };
2921 2991
2922 let width = width.resolve(&self.options, self.working_area.size.w);2992 let width = width.resolve(&self.options, self.working_area.size.w);
2923- let width = max(min(width, max_width), min_width);2993+ let width = f64::max(f64::min(width, max_width), min_width);
2924 2994
2925 // Compute the tile heights. Start by converting window heights to tile heights.2995 // Compute the tile heights. Start by converting window heights to tile heights.
2926 let mut heights = zip(&self.tiles, &self.data)2996 let mut heights = zip(&self.tiles, &self.data)
@@ -2937,18 +3007,18 @@ impl<W: LayoutElement> Column<W> {
2937 // Subtract all fixed-height tiles.3007 // Subtract all fixed-height tiles.
2938 for (h, (min_size, max_size)) in zip(&mut heights, zip(&min_size, &max_size)) {3008 for (h, (min_size, max_size)) in zip(&mut heights, zip(&min_size, &max_size)) {
2939 // Check if the tile has an exact height constraint.3009 // Check if the tile has an exact height constraint.
2940- if min_size.h > 0 && min_size.h == max_size.h {3010+ if min_size.h > 0. && min_size.h == max_size.h {
2941 *h = WindowHeight::Fixed(min_size.h);3011 *h = WindowHeight::Fixed(min_size.h);
2942 }3012 }
2943 3013
2944 if let WindowHeight::Fixed(h) = h {3014 if let WindowHeight::Fixed(h) = h {
2945- if max_size.h > 0 {3015+ if max_size.h > 0. {
2946- *h = min(*h, max_size.h);3016+ *h = f64::min(*h, max_size.h);
2947 }3017 }
2948- if min_size.h > 0 {3018+ if min_size.h > 0. {
2949- *h = max(*h, min_size.h);3019+ *h = f64::max(*h, min_size.h);
2950 }3020 }
2951- *h = max(*h, 1);3021+ *h = f64::max(*h, 1.);
2952 3022
2953 height_left -= *h + self.options.gaps;3023 height_left -= *h + self.options.gaps;
2954 auto_tiles_left -= 1;3024 auto_tiles_left -= 1;
@@ -2968,13 +3038,15 @@ impl<W: LayoutElement> Column<W> {
2968 // This case is separately handled above.3038 // This case is separately handled above.
2969 while auto_tiles_left > 0 {3039 while auto_tiles_left > 0 {
2970 // Compute the current auto height.3040 // Compute the current auto height.
2971- let auto_height = height_left / auto_tiles_left as i32 - self.options.gaps;3041+ let auto_height = height_left / auto_tiles_left as f64 - self.options.gaps;
2972- let auto_height = max(auto_height, 1);3042+ let auto_height = f64::max(auto_height, 1.);
2973 3043
2974 // Integer division above can result in imperfect height distribution. We will make some3044 // Integer division above can result in imperfect height distribution. We will make some
2975 // tiles 1 px taller to account for this.3045 // tiles 1 px taller to account for this.
2976- let mut ones_left = height_left3046+ let mut ones_left = f64::max(
2977- .saturating_sub((auto_height + self.options.gaps) * auto_tiles_left as i32);3047+ 0.,
3048+ height_left - (auto_height + self.options.gaps) * auto_tiles_left as f64,
3049+ ) as i32;
2978 3050
2979 let mut unsatisfied_min = false;3051 let mut unsatisfied_min = false;
2980 let mut ones_left_2 = ones_left;3052 let mut ones_left_2 = ones_left;
@@ -2985,12 +3057,12 @@ impl<W: LayoutElement> Column<W> {
2985 3057
2986 let mut auto = auto_height;3058 let mut auto = auto_height;
2987 if ones_left_2 > 0 {3059 if ones_left_2 > 0 {
2988- auto += 1;3060+ auto += 1.;
2989 ones_left_2 -= 1;3061 ones_left_2 -= 1;
2990 }3062 }
2991 3063
2992 // Check if the auto height satisfies the min height.3064 // Check if the auto height satisfies the min height.
2993- if min_size.h > 0 && min_size.h > auto {3065+ if min_size.h > 0. && min_size.h > auto {
2994 *h = WindowHeight::Fixed(min_size.h);3066 *h = WindowHeight::Fixed(min_size.h);
2995 height_left -= min_size.h + self.options.gaps;3067 height_left -= min_size.h + self.options.gaps;
2996 auto_tiles_left -= 1;3068 auto_tiles_left -= 1;
@@ -3013,7 +3085,7 @@ impl<W: LayoutElement> Column<W> {
3013 3085
3014 let mut auto = auto_height;3086 let mut auto = auto_height;
3015 if ones_left > 0 {3087 if ones_left > 0 {
3016- auto += 1;3088+ auto += 1.;
3017 ones_left -= 1;3089 ones_left -= 1;
3018 }3090 }
3019 3091
@@ -3034,8 +3106,13 @@ impl<W: LayoutElement> Column<W> {
3034 }3106 }
3035 }3107 }
3036 3108
3037- fn width(&self) -> i32 {3109+ fn width(&self) -> f64 {
3038- self.data.iter().map(|data| data.size.w).max().unwrap()3110+ self.data
3111+ .iter()
3112+ .map(|data| NotNan::new(data.size.w).unwrap())
3113+ .max()
3114+ .map(NotNan::into_inner)
3115+ .unwrap()
3039 }3116 }
3040 3117
3041 fn focus_up(&mut self) {3118 fn focus_up(&mut self) {
@@ -3094,6 +3171,8 @@ impl<W: LayoutElement> Column<W> {
3094 3171
3095 #[cfg(test)]3172 #[cfg(test)]
3096 fn verify_invariants(&self) {3173 fn verify_invariants(&self) {
3174+ use approx::assert_abs_diff_eq;
3175+
3097 assert!(!self.tiles.is_empty(), "columns can't be empty");3176 assert!(!self.tiles.is_empty(), "columns can't be empty");
3098 assert!(self.active_tile_idx < self.tiles.len());3177 assert!(self.active_tile_idx < self.tiles.len());
3099 assert_eq!(self.tiles.len(), self.data.len());3178 assert_eq!(self.tiles.len(), self.data.len());
@@ -3104,11 +3183,18 @@ impl<W: LayoutElement> Column<W> {
3104 3183
3105 for (tile, data) in zip(&self.tiles, &self.data) {3184 for (tile, data) in zip(&self.tiles, &self.data) {
3106 assert!(Rc::ptr_eq(&self.options, &tile.options));3185 assert!(Rc::ptr_eq(&self.options, &tile.options));
3186+ assert_eq!(self.scale, tile.scale());
3107 assert_eq!(self.is_fullscreen, tile.window().is_pending_fullscreen());3187 assert_eq!(self.is_fullscreen, tile.window().is_pending_fullscreen());
3108 3188
3109 let mut data2 = *data;3189 let mut data2 = *data;
3110 data2.update(tile);3190 data2.update(tile);
3111 assert_eq!(data, &data2, "tile data must be up to date");3191 assert_eq!(data, &data2, "tile data must be up to date");
3192+
3193+ let scale = tile.scale();
3194+ let size = tile.tile_size();
3195+ let rounded = size.to_physical_precise_round(scale).to_logical(scale);
3196+ assert_abs_diff_eq!(size.w, rounded.w, epsilon = 1e-5);
3197+ assert_abs_diff_eq!(size.h, rounded.h, epsilon = 1e-5);
3112 }3198 }
3113 }3199 }
3114 3200
@@ -3127,7 +3213,9 @@ impl<W: LayoutElement> Column<W> {
3127 .preset_widths3213 .preset_widths
3128 .iter()3214 .iter()
3129 .position(|prop| {3215 .position(|prop| {
3130- prop.resolve(&self.options, self.working_area.size.w) > current3216+ let resolved = prop.resolve(&self.options, self.working_area.size.w);
3217+ // Some allowance for fractional scaling purposes.
3218+ current + 1. < resolved
3131 })3219 })
3132 .unwrap_or(0)3220 .unwrap_or(0)
3133 }3221 }
@@ -3156,7 +3244,7 @@ impl<W: LayoutElement> Column<W> {
3156 };3244 };
3157 3245
3158 // FIXME: fix overflows then remove limits.3246 // FIXME: fix overflows then remove limits.
3159- const MAX_PX: i32 = 100000;3247+ const MAX_PX: f64 = 100000.;
3160 const MAX_F: f64 = 10000.;3248 const MAX_F: f64 = 10000.;
3161 3249
3162 let width = match (current, change) {3250 let width = match (current, change) {
@@ -3166,13 +3254,16 @@ impl<W: LayoutElement> Column<W> {
3166 // intention behind the ability to set a fixed size.3254 // intention behind the ability to set a fixed size.
3167 let tile_idx = tile_idx.unwrap_or(self.active_tile_idx);3255 let tile_idx = tile_idx.unwrap_or(self.active_tile_idx);
3168 let tile = &self.tiles[tile_idx];3256 let tile = &self.tiles[tile_idx];
3169- ColumnWidth::Fixed(tile.tile_width_for_window_width(fixed).clamp(1, MAX_PX))3257+ ColumnWidth::Fixed(
3258+ tile.tile_width_for_window_width(f64::from(fixed))
3259+ .clamp(1., MAX_PX),
3260+ )
3170 }3261 }
3171 (_, SizeChange::SetProportion(proportion)) => {3262 (_, SizeChange::SetProportion(proportion)) => {
3172 ColumnWidth::Proportion((proportion / 100.).clamp(0., MAX_F))3263 ColumnWidth::Proportion((proportion / 100.).clamp(0., MAX_F))
3173 }3264 }
3174 (_, SizeChange::AdjustFixed(delta)) => {3265 (_, SizeChange::AdjustFixed(delta)) => {
3175- let width = current_px.saturating_add(delta).clamp(1, MAX_PX);3266+ let width = (current_px + f64::from(delta)).clamp(1., MAX_PX);
3176 ColumnWidth::Fixed(width)3267 ColumnWidth::Fixed(width)
3177 }3268 }
3178 (ColumnWidth::Proportion(current), SizeChange::AdjustProportion(delta)) => {3269 (ColumnWidth::Proportion(current), SizeChange::AdjustProportion(delta)) => {
@@ -3180,8 +3271,12 @@ impl<W: LayoutElement> Column<W> {
3180 ColumnWidth::Proportion(proportion)3271 ColumnWidth::Proportion(proportion)
3181 }3272 }
3182 (ColumnWidth::Fixed(_), SizeChange::AdjustProportion(delta)) => {3273 (ColumnWidth::Fixed(_), SizeChange::AdjustProportion(delta)) => {
3183- let current = (current_px + self.options.gaps) as f643274+ let full = self.working_area.size.w - self.options.gaps;
3184- / (self.working_area.size.w - self.options.gaps) as f64;3275+ let current = if full == 0. {
3276+ 1.
3277+ } else {
3278+ (current_px + self.options.gaps) / full
3279+ };
3185 let proportion = (current + delta / 100.).clamp(0., MAX_F);3280 let proportion = (current + delta / 100.).clamp(0., MAX_F);
3186 ColumnWidth::Proportion(proportion)3281 ColumnWidth::Proportion(proportion)
3187 }3282 }
@@ -3200,28 +3295,29 @@ impl<W: LayoutElement> Column<W> {
3200 WindowHeight::Fixed(height) => height,3295 WindowHeight::Fixed(height) => height,
3201 };3296 };
3202 let current_tile_px = tile.tile_height_for_window_height(current_window_px);3297 let current_tile_px = tile.tile_height_for_window_height(current_window_px);
3203- let current_prop = (current_tile_px + self.options.gaps) as f643298+
3204- / (self.working_area.size.h - self.options.gaps) as f64;3299+ let full = self.working_area.size.h - self.options.gaps;
3300+ let current_prop = if full == 0. {
3301+ 1.
3302+ } else {
3303+ (current_tile_px + self.options.gaps) / (full)
3304+ };
3205 3305
3206 // FIXME: fix overflows then remove limits.3306 // FIXME: fix overflows then remove limits.
3207- const MAX_PX: i32 = 100000;3307+ const MAX_PX: f64 = 100000.;
3208 3308
3209 let mut window_height = match change {3309 let mut window_height = match change {
3210- SizeChange::SetFixed(fixed) => fixed,3310+ SizeChange::SetFixed(fixed) => f64::from(fixed),
3211 SizeChange::SetProportion(proportion) => {3311 SizeChange::SetProportion(proportion) => {
3212- let tile_height = ((self.working_area.size.h - self.options.gaps) as f643312+ let tile_height =
3213- * proportion3313+ (self.working_area.size.h - self.options.gaps) * proportion - self.options.gaps;
3214- - self.options.gaps as f64)
3215- .round() as i32;
3216 tile.window_height_for_tile_height(tile_height)3314 tile.window_height_for_tile_height(tile_height)
3217 }3315 }
3218- SizeChange::AdjustFixed(delta) => current_window_px.saturating_add(delta),3316+ SizeChange::AdjustFixed(delta) => current_window_px + f64::from(delta),
3219 SizeChange::AdjustProportion(delta) => {3317 SizeChange::AdjustProportion(delta) => {
3220 let proportion = current_prop + delta / 100.;3318 let proportion = current_prop + delta / 100.;
3221- let tile_height = ((self.working_area.size.h - self.options.gaps) as f643319+ let tile_height =
3222- * proportion3320+ (self.working_area.size.h - self.options.gaps) * proportion - self.options.gaps;
3223- - self.options.gaps as f64)
3224- .round() as i32;
3225 tile.window_height_for_tile_height(tile_height)3321 tile.window_height_for_tile_height(tile_height)
3226 }3322 }
3227 };3323 };
@@ -3232,13 +3328,13 @@ impl<W: LayoutElement> Column<W> {
3232 let max_h = win.max_size().h;3328 let max_h = win.max_size().h;
3233 3329
3234 if max_h > 0 {3330 if max_h > 0 {
3235- window_height = window_height.min(max_h);3331+ window_height = f64::min(window_height, f64::from(max_h));
3236 }3332 }
3237 if min_h > 0 {3333 if min_h > 0 {
3238- window_height = window_height.max(min_h);3334+ window_height = f64::max(window_height, f64::from(min_h));
3239 }3335 }
3240 3336
3241- self.data[tile_idx].height = WindowHeight::Fixed(window_height.clamp(1, MAX_PX));3337+ self.data[tile_idx].height = WindowHeight::Fixed(window_height.clamp(1., MAX_PX));
3242 self.update_tile_sizes(animate);3338 self.update_tile_sizes(animate);
3243 }3339 }
3244 3340
@@ -3259,7 +3355,7 @@ impl<W: LayoutElement> Column<W> {
3259 }3355 }
3260 3356
3261 /// Returns the static window location, not taking the render offset into account.3357 /// Returns the static window location, not taking the render offset into account.
3262- pub fn window_loc(&self, tile_idx: usize) -> Point<i32, Logical> {3358+ pub fn window_loc(&self, tile_idx: usize) -> Point<f64, Logical> {
3263 let (tile, pos) = self.tiles().nth(tile_idx).unwrap();3359 let (tile, pos) = self.tiles().nth(tile_idx).unwrap();
3264 pos + tile.window_loc()3360 pos + tile.window_loc()
3265 }3361 }
@@ -3269,11 +3365,11 @@ impl<W: LayoutElement> Column<W> {
3269 fn tile_offsets_iter(3365 fn tile_offsets_iter(
3270 &self,3366 &self,
3271 data: impl Iterator<Item = TileData>,3367 data: impl Iterator<Item = TileData>,
3272- ) -> impl Iterator<Item = Point<i32, Logical>> {3368+ ) -> impl Iterator<Item = Point<f64, Logical>> {
3273 let center = self.options.center_focused_column == CenterFocusedColumn::Always;3369 let center = self.options.center_focused_column == CenterFocusedColumn::Always;
3274 let gaps = self.options.gaps;3370 let gaps = self.options.gaps;
3275 let col_width = self.width();3371 let col_width = self.width();
3276- let mut y = 0;3372+ let mut y = 0.;
3277 3373
3278 if !self.is_fullscreen {3374 if !self.is_fullscreen {
3279 y = self.working_area.loc.y + self.options.gaps;3375 y = self.working_area.loc.y + self.options.gaps;
@@ -3288,10 +3384,10 @@ impl<W: LayoutElement> Column<W> {
3288 let data = data.chain(iter::once(dummy));3384 let data = data.chain(iter::once(dummy));
3289 3385
3290 data.map(move |data| {3386 data.map(move |data| {
3291- let mut pos = Point::from((0, y));3387+ let mut pos = Point::from((0., y));
3292 3388
3293 if center {3389 if center {
3294- pos.x = (col_width - data.size.w) / 2;3390+ pos.x = (col_width - data.size.w) / 2.;
3295 } else if data.interactively_resizing_by_left_edge {3391 } else if data.interactively_resizing_by_left_edge {
3296 pos.x = col_width - data.size.w;3392 pos.x = col_width - data.size.w;
3297 }3393 }
@@ -3301,18 +3397,18 @@ impl<W: LayoutElement> Column<W> {
3301 })3397 })
3302 }3398 }
3303 3399
3304- fn tile_offsets(&self) -> impl Iterator<Item = Point<i32, Logical>> + '_ {3400+ fn tile_offsets(&self) -> impl Iterator<Item = Point<f64, Logical>> + '_ {
3305 self.tile_offsets_iter(self.data.iter().copied())3401 self.tile_offsets_iter(self.data.iter().copied())
3306 }3402 }
3307 3403
3308- fn tile_offset(&self, tile_idx: usize) -> Point<i32, Logical> {3404+ fn tile_offset(&self, tile_idx: usize) -> Point<f64, Logical> {
3309 self.tile_offsets().nth(tile_idx).unwrap()3405 self.tile_offsets().nth(tile_idx).unwrap()
3310 }3406 }
3311 3407
3312 fn tile_offsets_in_render_order(3408 fn tile_offsets_in_render_order(
3313 &self,3409 &self,
3314 data: impl Iterator<Item = TileData>,3410 data: impl Iterator<Item = TileData>,
3315- ) -> impl Iterator<Item = Point<i32, Logical>> {3411+ ) -> impl Iterator<Item = Point<f64, Logical>> {
3316 let active_idx = self.active_tile_idx;3412 let active_idx = self.active_tile_idx;
3317 let active_pos = self.tile_offset(active_idx);3413 let active_pos = self.tile_offset(active_idx);
3318 let offsets = self3414 let offsets = self
@@ -3322,17 +3418,17 @@ impl<W: LayoutElement> Column<W> {
3322 iter::once(active_pos).chain(offsets)3418 iter::once(active_pos).chain(offsets)
3323 }3419 }
3324 3420
3325- fn tiles(&self) -> impl Iterator<Item = (&Tile<W>, Point<i32, Logical>)> + '_ {3421+ fn tiles(&self) -> impl Iterator<Item = (&Tile<W>, Point<f64, Logical>)> + '_ {
3326 let offsets = self.tile_offsets_iter(self.data.iter().copied());3422 let offsets = self.tile_offsets_iter(self.data.iter().copied());
3327 zip(&self.tiles, offsets)3423 zip(&self.tiles, offsets)
3328 }3424 }
3329 3425
3330- fn tiles_mut(&mut self) -> impl Iterator<Item = (&mut Tile<W>, Point<i32, Logical>)> + '_ {3426+ fn tiles_mut(&mut self) -> impl Iterator<Item = (&mut Tile<W>, Point<f64, Logical>)> + '_ {
3331 let offsets = self.tile_offsets_iter(self.data.iter().copied());3427 let offsets = self.tile_offsets_iter(self.data.iter().copied());
3332 zip(&mut self.tiles, offsets)3428 zip(&mut self.tiles, offsets)
3333 }3429 }
3334 3430
3335- fn tiles_in_render_order(&self) -> impl Iterator<Item = (&Tile<W>, Point<i32, Logical>)> + '_ {3431+ fn tiles_in_render_order(&self) -> impl Iterator<Item = (&Tile<W>, Point<f64, Logical>)> + '_ {
3336 let offsets = self.tile_offsets_in_render_order(self.data.iter().copied());3432 let offsets = self.tile_offsets_in_render_order(self.data.iter().copied());
3337 3433
3338 let (first, rest) = self.tiles.split_at(self.active_tile_idx);3434 let (first, rest) = self.tiles.split_at(self.active_tile_idx);
@@ -3344,7 +3440,7 @@ impl<W: LayoutElement> Column<W> {
3344 3440
3345 fn tiles_in_render_order_mut(3441 fn tiles_in_render_order_mut(
3346 &mut self,3442 &mut self,
3347- ) -> impl Iterator<Item = (&mut Tile<W>, Point<i32, Logical>)> + '_ {3443+ ) -> impl Iterator<Item = (&mut Tile<W>, Point<f64, Logical>)> + '_ {
3348 let offsets = self.tile_offsets_in_render_order(self.data.iter().copied());3444 let offsets = self.tile_offsets_in_render_order(self.data.iter().copied());
3349 3445
3350 let (first, rest) = self.tiles.split_at_mut(self.active_tile_idx);3446 let (first, rest) = self.tiles.split_at_mut(self.active_tile_idx);
@@ -3356,19 +3452,19 @@ impl<W: LayoutElement> Column<W> {
3356 }3452 }
3357 3453
3358 fn compute_new_view_offset(3454 fn compute_new_view_offset(
3359- cur_x: i32,3455+ cur_x: f64,
3360- view_width: i32,3456+ view_width: f64,
3361- new_col_x: i32,3457+ new_col_x: f64,
3362- new_col_width: i32,3458+ new_col_width: f64,
3363- gaps: i32,3459+ gaps: f64,
3364-) -> i32 {3460+) -> f64 {
3365 // If the column is wider than the view, always left-align it.3461 // If the column is wider than the view, always left-align it.
3366 if view_width <= new_col_width {3462 if view_width <= new_col_width {
3367- return 0;3463+ return 0.;
3368 }3464 }
3369 3465
3370 // Compute the padding in case it needs to be smaller due to large tile width.3466 // Compute the padding in case it needs to be smaller due to large tile width.
3371- let padding = ((view_width - new_col_width) / 2).clamp(0, gaps);3467+ let padding = ((view_width - new_col_width) / 2.).clamp(0., gaps);
3372 3468
3373 // Compute the desired new X with padding.3469 // Compute the desired new X with padding.
3374 let new_x = new_col_x - padding;3470 let new_x = new_col_x - padding;
@@ -3380,8 +3476,8 @@ fn compute_new_view_offset(
3380 }3476 }
3381 3477
3382 // Otherwise, prefer the alignment that results in less motion from the current position.3478 // Otherwise, prefer the alignment that results in less motion from the current position.
3383- let dist_to_left = cur_x.abs_diff(new_x);3479+ let dist_to_left = (cur_x - new_x).abs();
3384- let dist_to_right = (cur_x + view_width).abs_diff(new_right_x);3480+ let dist_to_right = ((cur_x + view_width) - new_right_x).abs();
3385 if dist_to_left <= dist_to_right {3481 if dist_to_left <= dist_to_right {
3386 -padding3482 -padding
3387 } else {3483 } else {
@@ -3389,41 +3485,49 @@ fn compute_new_view_offset(
3389 }3485 }
3390 }3486 }
3391 3487
3392-pub fn compute_working_area(output: &Output, struts: Struts) -> Rectangle<i32, Logical> {3488+pub fn compute_working_area(output: &Output, struts: Struts) -> Rectangle<f64, Logical> {
3393 // Start with the layer-shell non-exclusive zone.3489 // Start with the layer-shell non-exclusive zone.
3394- let mut working_area = layer_map_for_output(output).non_exclusive_zone();3490+ let mut working_area = layer_map_for_output(output).non_exclusive_zone().to_f64();
3395 3491
3396 // Add struts.3492 // Add struts.
3397- let w = working_area.size.w;3493+ working_area.size.w = f64::max(0., working_area.size.w - struts.left.0 - struts.right.0);
3398- let h = working_area.size.h;3494+ working_area.loc.x += struts.left.0;
3495+
3496+ working_area.size.h = f64::max(0., working_area.size.h - struts.top.0 - struts.bottom.0);
3497+ working_area.loc.y += struts.top.0;
3498+
3499+ // Round location to start at a physical pixel.
3500+ let scale = output.current_scale().fractional_scale();
3501+ let loc = working_area
3502+ .loc
3503+ .to_physical_precise_ceil(scale)
3504+ .to_logical(scale);
3399 3505
3400- working_area.size.w = w3506+ let mut size_diff = (loc - working_area.loc).to_size();
3401- .saturating_sub(struts.left.into())3507+ size_diff.w = f64::min(working_area.size.w, size_diff.w);
3402- .saturating_sub(struts.right.into());3508+ size_diff.h = f64::min(working_area.size.h, size_diff.h);
3403- working_area.loc.x += struts.left as i32;
3404 3509
3405- working_area.size.h = h3510+ working_area.size -= size_diff;
3406- .saturating_sub(struts.top.into())3511+ working_area.loc = loc;
3407- .saturating_sub(struts.bottom.into());
3408- working_area.loc.y += struts.top as i32;
3409 3512
3410 working_area3513 working_area
3411 }3514 }
3412 3515
3413 fn compute_toplevel_bounds(3516 fn compute_toplevel_bounds(
3414 border_config: niri_config::Border,3517 border_config: niri_config::Border,
3415- working_area_size: Size<i32, Logical>,3518+ working_area_size: Size<f64, Logical>,
3416- gaps: i32,3519+ gaps: f64,
3417 ) -> Size<i32, Logical> {3520 ) -> Size<i32, Logical> {
3418- let mut border = 0;3521+ let mut border = 0.;
3419 if !border_config.off {3522 if !border_config.off {
3420- border = border_config.width as i32 * 2;3523+ border = border_config.width.0 * 2.;
3421 }3524 }
3422 3525
3423 Size::from((3526 Size::from((
3424- max(working_area_size.w - gaps * 2 - border, 1),3527+ f64::max(working_area_size.w - gaps * 2. - border, 1.),
3425- max(working_area_size.h - gaps * 2 - border, 1),3528+ f64::max(working_area_size.h - gaps * 2. - border, 1.),
3426 ))3529 ))
3530+ .to_i32_floor()
3427 }3531 }
3428 3532
3429 fn cancel_resize_for_column<W: LayoutElement>(3533 fn cancel_resize_for_column<W: LayoutElement>(
src/niri.rsmodified+22 -17
@@ -346,12 +346,12 @@ pub enum KeyboardFocus {
346 ScreenshotUi,346 ScreenshotUi,
347 }347 }
348 348
349-#[derive(Default, Clone, PartialEq, Eq)]349+#[derive(Default, Clone, PartialEq)]
350 pub struct PointerFocus {350 pub struct PointerFocus {
351 // Output under pointer.351 // Output under pointer.
352 pub output: Option<Output>,352 pub output: Option<Output>,
353 // Surface under pointer and its location in global coordinate space.353 // Surface under pointer and its location in global coordinate space.
354- pub surface: Option<(WlSurface, Point<i32, Logical>)>,354+ pub surface: Option<(WlSurface, Point<f64, Logical>)>,
355 // If surface belongs to a window, this is that window.355 // If surface belongs to a window, this is that window.
356 pub window: Option<Window>,356 pub window: Option<Window>,
357 }357 }
@@ -588,8 +588,8 @@ impl State {
588 if let Some(rect) = rect {588 if let Some(rect) = rect {
589 let output_geo = self.niri.global_space.output_geometry(&output).unwrap();589 let output_geo = self.niri.global_space.output_geometry(&output).unwrap();
590 let mut rect = rect;590 let mut rect = rect;
591- rect.loc += output_geo.loc;591+ rect.loc += output_geo.loc.to_f64();
592- rv = self.move_cursor_to_rect(rect.to_f64(), mode);592+ rv = self.move_cursor_to_rect(rect, mode);
593 }593 }
594 594
595 rv595 rv
@@ -1659,7 +1659,7 @@ impl Niri {
1659 config,1659 config,
1660 } = data;1660 } = data;
1661 1661
1662- let size = output_size(&output);1662+ let size = output_size(&output).to_i32_round();
1663 1663
1664 let new_position = config1664 let new_position = config
1665 .map(|pos| Point::from((pos.x, pos.y)))1665 .map(|pos| Point::from((pos.x, pos.y)))
@@ -1763,7 +1763,7 @@ impl Niri {
1763 LockRenderState::Unlocked1763 LockRenderState::Unlocked
1764 };1764 };
1765 1765
1766- let size = output_size(&output);1766+ let size = output_size(&output).to_i32_round();
1767 let state = OutputState {1767 let state = OutputState {
1768 global,1768 global,
1769 redraw_state: RedrawState::Idle,1769 redraw_state: RedrawState::Idle,
@@ -1853,7 +1853,7 @@ impl Niri {
1853 }1853 }
1854 1854
1855 pub fn output_resized(&mut self, output: &Output) {1855 pub fn output_resized(&mut self, output: &Output) {
1856- let output_size = output_size(output);1856+ let output_size = output_size(output).to_i32_round();
1857 let is_locked = self.is_locked();1857 let is_locked = self.is_locked();
1858 1858
1859 layer_map_for_output(output).arrange();1859 layer_map_for_output(output).arrange();
@@ -1990,7 +1990,10 @@ impl Niri {
1990 WindowSurfaceType::ALL,1990 WindowSurfaceType::ALL,
1991 )1991 )
1992 .map(|(surface, pos_within_output)| {1992 .map(|(surface, pos_within_output)| {
1993- (surface, pos_within_output + output_pos_in_global_space)1993+ (
1994+ surface,
1995+ (pos_within_output + output_pos_in_global_space).to_f64(),
1996+ )
1994 });1997 });
1995 1998
1996 return rv;1999 return rv;
@@ -2005,14 +2008,15 @@ impl Niri {
2005 layers2008 layers
2006 .layer_under(layer, pos_within_output)2009 .layer_under(layer, pos_within_output)
2007 .and_then(|layer| {2010 .and_then(|layer| {
2008- let layer_pos_within_output = layers.layer_geometry(layer).unwrap().loc;2011+ let layer_pos_within_output =
2012+ layers.layer_geometry(layer).unwrap().loc.to_f64();
2009 layer2013 layer
2010 .surface_under(2014 .surface_under(
2011- pos_within_output - layer_pos_within_output.to_f64(),2015+ pos_within_output - layer_pos_within_output,
2012 WindowSurfaceType::ALL,2016 WindowSurfaceType::ALL,
2013 )2017 )
2014 .map(|(surface, pos_within_layer)| {2018 .map(|(surface, pos_within_layer)| {
2015- (surface, pos_within_layer + layer_pos_within_output)2019+ (surface, pos_within_layer.to_f64() + layer_pos_within_output)
2016 })2020 })
2017 })2021 })
2018 .map(|s| (s, None))2022 .map(|s| (s, None))
@@ -2026,11 +2030,11 @@ impl Niri {
2026 let window = &mapped.window;2030 let window = &mapped.window;
2027 window2031 window
2028 .surface_under(2032 .surface_under(
2029- pos_within_output - win_pos_within_output.to_f64(),2033+ pos_within_output - win_pos_within_output,
2030 WindowSurfaceType::ALL,2034 WindowSurfaceType::ALL,
2031 )2035 )
2032 .map(|(s, pos_within_window)| {2036 .map(|(s, pos_within_window)| {
2033- (s, pos_within_window + win_pos_within_output)2037+ (s, pos_within_window.to_f64() + win_pos_within_output)
2034 })2038 })
2035 .map(|s| (s, Some(window.clone())))2039 .map(|s| (s, Some(window.clone())))
2036 })2040 })
@@ -2057,7 +2061,8 @@ impl Niri {
2057 return rv;2061 return rv;
2058 };2062 };
2059 2063
2060- let surface_loc_in_global_space = surface_pos_within_output + output_pos_in_global_space;2064+ let surface_loc_in_global_space =
2065+ surface_pos_within_output + output_pos_in_global_space.to_f64();
2061 2066
2062 rv.surface = Some((surface, surface_loc_in_global_space));2067 rv.surface = Some((surface, surface_loc_in_global_space));
2063 rv.window = window;2068 rv.window = window;
@@ -3533,7 +3538,7 @@ impl Niri {
3533 // FIXME: pointer.3538 // FIXME: pointer.
3534 let elements = mapped.render(3539 let elements = mapped.render(
3535 renderer,3540 renderer,
3536- mapped.window.geometry().loc,3541+ mapped.window.geometry().loc.to_f64(),
3537 scale,3542 scale,
3538 alpha,3543 alpha,
3539 RenderTarget::ScreenCapture,3544 RenderTarget::ScreenCapture,
@@ -3784,8 +3789,8 @@ impl Niri {
3784 3789
3785 // Constraint does not apply if not within region.3790 // Constraint does not apply if not within region.
3786 if let Some(region) = constraint.region() {3791 if let Some(region) = constraint.region() {
3787- let new_pos_within_surface = new_pos.to_i32_round() - *surface_loc;3792+ let new_pos_within_surface = new_pos - *surface_loc;
3788- if !region.contains(new_pos_within_surface) {3793+ if !region.contains(new_pos_within_surface.to_i32_round()) {
3789 return;3794 return;
3790 }3795 }
3791 }3796 }
src/render_helpers/border.rsmodified+10 -10
@@ -26,12 +26,12 @@ pub struct BorderRenderElement {
26 26
27 #[derive(Debug, Clone, Copy, PartialEq)]27 #[derive(Debug, Clone, Copy, PartialEq)]
28 struct Parameters {28 struct Parameters {
29- size: Size<i32, Logical>,29+ size: Size<f64, Logical>,
30- gradient_area: Rectangle<i32, Logical>,30+ gradient_area: Rectangle<f64, Logical>,
31 color_from: [f32; 4],31 color_from: [f32; 4],
32 color_to: [f32; 4],32 color_to: [f32; 4],
33 angle: f32,33 angle: f32,
34- geometry: Rectangle<i32, Logical>,34+ geometry: Rectangle<f64, Logical>,
35 border_width: f32,35 border_width: f32,
36 corner_radius: CornerRadius,36 corner_radius: CornerRadius,
37 }37 }
@@ -39,12 +39,12 @@ struct Parameters {
39 impl BorderRenderElement {39 impl BorderRenderElement {
40 #[allow(clippy::too_many_arguments)]40 #[allow(clippy::too_many_arguments)]
41 pub fn new(41 pub fn new(
42- size: Size<i32, Logical>,42+ size: Size<f64, Logical>,
43- gradient_area: Rectangle<i32, Logical>,43+ gradient_area: Rectangle<f64, Logical>,
44 color_from: [f32; 4],44 color_from: [f32; 4],
45 color_to: [f32; 4],45 color_to: [f32; 4],
46 angle: f32,46 angle: f32,
47- geometry: Rectangle<i32, Logical>,47+ geometry: Rectangle<f64, Logical>,
48 border_width: f32,48 border_width: f32,
49 corner_radius: CornerRadius,49 corner_radius: CornerRadius,
50 ) -> Self {50 ) -> Self {
@@ -90,12 +90,12 @@ impl BorderRenderElement {
90 #[allow(clippy::too_many_arguments)]90 #[allow(clippy::too_many_arguments)]
91 pub fn update(91 pub fn update(
92 &mut self,92 &mut self,
93- size: Size<i32, Logical>,93+ size: Size<f64, Logical>,
94- gradient_area: Rectangle<i32, Logical>,94+ gradient_area: Rectangle<f64, Logical>,
95 color_from: [f32; 4],95 color_from: [f32; 4],
96 color_to: [f32; 4],96 color_to: [f32; 4],
97 angle: f32,97 angle: f32,
98- geometry: Rectangle<i32, Logical>,98+ geometry: Rectangle<f64, Logical>,
99 border_width: f32,99 border_width: f32,
100 corner_radius: CornerRadius,100 corner_radius: CornerRadius,
101 ) {101 ) {
@@ -172,7 +172,7 @@ impl BorderRenderElement {
172 );172 );
173 }173 }
174 174
175- pub fn with_location(mut self, location: Point<i32, Logical>) -> Self {175+ pub fn with_location(mut self, location: Point<f64, Logical>) -> Self {
176 self.inner = self.inner.with_location(location);176 self.inner = self.inner.with_location(location);
177 self177 self
178 }178 }
src/render_helpers/clipped_surface.rsmodified+8 -8
@@ -18,7 +18,7 @@ pub struct ClippedSurfaceRenderElement<R: NiriRenderer> {
18 inner: WaylandSurfaceRenderElement<R>,18 inner: WaylandSurfaceRenderElement<R>,
19 program: GlesTexProgram,19 program: GlesTexProgram,
20 corner_radius: CornerRadius,20 corner_radius: CornerRadius,
21- geometry: Rectangle<i32, Logical>,21+ geometry: Rectangle<f64, Logical>,
22 input_to_geo: Mat3,22 input_to_geo: Mat3,
23 }23 }
24 24
@@ -32,7 +32,7 @@ impl<R: NiriRenderer> ClippedSurfaceRenderElement<R> {
32 pub fn new(32 pub fn new(
33 elem: WaylandSurfaceRenderElement<R>,33 elem: WaylandSurfaceRenderElement<R>,
34 scale: Scale<f64>,34 scale: Scale<f64>,
35- geometry: Rectangle<i32, Logical>,35+ geometry: Rectangle<f64, Logical>,
36 program: GlesTexProgram,36 program: GlesTexProgram,
37 corner_radius: CornerRadius,37 corner_radius: CornerRadius,
38 ) -> Self {38 ) -> Self {
@@ -86,7 +86,7 @@ impl<R: NiriRenderer> ClippedSurfaceRenderElement<R> {
86 pub fn will_clip(86 pub fn will_clip(
87 elem: &WaylandSurfaceRenderElement<R>,87 elem: &WaylandSurfaceRenderElement<R>,
88 scale: Scale<f64>,88 scale: Scale<f64>,
89- geometry: Rectangle<i32, Logical>,89+ geometry: Rectangle<f64, Logical>,
90 corner_radius: CornerRadius,90 corner_radius: CornerRadius,
91 ) -> bool {91 ) -> bool {
92 let elem_geo = elem.geometry(scale);92 let elem_geo = elem.geometry(scale);
@@ -95,10 +95,10 @@ impl<R: NiriRenderer> ClippedSurfaceRenderElement<R> {
95 if corner_radius == CornerRadius::default() {95 if corner_radius == CornerRadius::default() {
96 !geo.contains_rect(elem_geo)96 !geo.contains_rect(elem_geo)
97 } else {97 } else {
98- let corners = Self::rounded_corners(geometry.to_f64(), corner_radius);98+ let corners = Self::rounded_corners(geometry, corner_radius);
99 let corners = corners99 let corners = corners
100 .into_iter()100 .into_iter()
101- .map(|rect| rect.to_physical_precise_round(scale));101+ .map(|rect| rect.to_physical_precise_up(scale));
102 let geo = Rectangle::subtract_rects_many([geo], corners);102 let geo = Rectangle::subtract_rects_many([geo], corners);
103 !Rectangle::subtract_rects_many([elem_geo], geo).is_empty()103 !Rectangle::subtract_rects_many([elem_geo], geo).is_empty()
104 }104 }
@@ -186,11 +186,11 @@ impl<R: NiriRenderer> Element for ClippedSurfaceRenderElement<R> {
186 if self.corner_radius == CornerRadius::default() {186 if self.corner_radius == CornerRadius::default() {
187 regions.collect()187 regions.collect()
188 } else {188 } else {
189- let corners = Self::rounded_corners(self.geometry.to_f64(), self.corner_radius);189+ let corners = Self::rounded_corners(self.geometry, self.corner_radius);
190 190
191 let elem_loc = self.geometry(scale).loc;191 let elem_loc = self.geometry(scale).loc;
192 let corners = corners.into_iter().map(|rect| {192 let corners = corners.into_iter().map(|rect| {
193- let mut rect = rect.to_physical_precise_round(scale);193+ let mut rect = rect.to_physical_precise_up(scale);
194 rect.loc -= elem_loc;194 rect.loc -= elem_loc;
195 rect195 rect
196 });196 });
@@ -278,7 +278,7 @@ impl<'render> RenderElement<TtyRenderer<'render>>
278 }278 }
279 279
280 impl RoundedCornerDamage {280 impl RoundedCornerDamage {
281- pub fn set_size(&mut self, size: Size<i32, Logical>) {281+ pub fn set_size(&mut self, size: Size<f64, Logical>) {
282 self.damage.set_size(size);282 self.damage.set_size(size);
283 }283 }
284 284
src/render_helpers/damage.rsmodified+4 -4
@@ -7,7 +7,7 @@ use smithay::utils::{Buffer, Logical, Physical, Point, Rectangle, Scale, Size};
7 pub struct ExtraDamage {7 pub struct ExtraDamage {
8 id: Id,8 id: Id,
9 commit: CommitCounter,9 commit: CommitCounter,
10- geometry: Rectangle<i32, Logical>,10+ geometry: Rectangle<f64, Logical>,
11 }11 }
12 12
13 impl ExtraDamage {13 impl ExtraDamage {
@@ -19,7 +19,7 @@ impl ExtraDamage {
19 }19 }
20 }20 }
21 21
22- pub fn set_size(&mut self, size: Size<i32, Logical>) {22+ pub fn set_size(&mut self, size: Size<f64, Logical>) {
23 if self.geometry.size == size {23 if self.geometry.size == size {
24 return;24 return;
25 }25 }
@@ -32,7 +32,7 @@ impl ExtraDamage {
32 self.commit.increment();32 self.commit.increment();
33 }33 }
34 34
35- pub fn with_location(mut self, location: Point<i32, Logical>) -> Self {35+ pub fn with_location(mut self, location: Point<f64, Logical>) -> Self {
36 self.geometry.loc = location;36 self.geometry.loc = location;
37 self37 self
38 }38 }
@@ -58,7 +58,7 @@ impl Element for ExtraDamage {
58 }58 }
59 59
60 fn geometry(&self, scale: Scale<f64>) -> Rectangle<i32, Physical> {60 fn geometry(&self, scale: Scale<f64>) -> Rectangle<i32, Physical> {
61- self.geometry.to_physical_precise_round(scale)61+ self.geometry.to_physical_precise_up(scale)
62 }62 }
63 }63 }
64 64
src/render_helpers/mod.rsmodified+8 -16
@@ -3,7 +3,6 @@ use std::ptr;
3 use anyhow::{ensure, Context};3 use anyhow::{ensure, Context};
4 use niri_config::BlockOutFrom;4 use niri_config::BlockOutFrom;
5 use smithay::backend::allocator::Fourcc;5 use smithay::backend::allocator::Fourcc;
6-use smithay::backend::renderer::element::solid::{SolidColorBuffer, SolidColorRenderElement};
7 use smithay::backend::renderer::element::utils::{Relocate, RelocateRenderElement};6 use smithay::backend::renderer::element::utils::{Relocate, RelocateRenderElement};
8 use smithay::backend::renderer::element::{Kind, RenderElement};7 use smithay::backend::renderer::element::{Kind, RenderElement};
9 use smithay::backend::renderer::gles::{GlesMapping, GlesRenderer, GlesTexture};8 use smithay::backend::renderer::gles::{GlesMapping, GlesRenderer, GlesTexture};
@@ -13,6 +12,7 @@ use smithay::reexports::wayland_server::protocol::wl_buffer::WlBuffer;
13 use smithay::reexports::wayland_server::protocol::wl_shm;12 use smithay::reexports::wayland_server::protocol::wl_shm;
14 use smithay::utils::{Logical, Physical, Point, Rectangle, Scale, Size, Transform};13 use smithay::utils::{Logical, Physical, Point, Rectangle, Scale, Size, Transform};
15 use smithay::wayland::shm;14 use smithay::wayland::shm;
15+use solid_color::{SolidColorBuffer, SolidColorRenderElement};
16 16
17 use self::primary_gpu_texture::PrimaryGpuTextureRenderElement;17 use self::primary_gpu_texture::PrimaryGpuTextureRenderElement;
18 use self::texture::{TextureBuffer, TextureRenderElement};18 use self::texture::{TextureBuffer, TextureRenderElement};
@@ -50,7 +50,7 @@ pub enum RenderTarget {
50 #[derive(Debug)]50 #[derive(Debug)]
51 pub struct BakedBuffer<B> {51 pub struct BakedBuffer<B> {
52 pub buffer: B,52 pub buffer: B,
53- pub location: Point<i32, Logical>,53+ pub location: Point<f64, Logical>,
54 pub src: Option<Rectangle<f64, Logical>>,54 pub src: Option<Rectangle<f64, Logical>>,
55 pub dst: Option<Size<i32, Logical>>,55 pub dst: Option<Size<i32, Logical>>,
56 }56 }
@@ -67,7 +67,7 @@ pub trait ToRenderElement {
67 67
68 fn to_render_element(68 fn to_render_element(
69 &self,69 &self,
70- location: Point<i32, Logical>,70+ location: Point<f64, Logical>,
71 scale: Scale<f64>,71 scale: Scale<f64>,
72 alpha: f32,72 alpha: f32,
73 kind: Kind,73 kind: Kind,
@@ -119,14 +119,14 @@ impl ToRenderElement for BakedBuffer<TextureBuffer<GlesTexture>> {
119 119
120 fn to_render_element(120 fn to_render_element(
121 &self,121 &self,
122- location: Point<i32, Logical>,122+ location: Point<f64, Logical>,
123 _scale: Scale<f64>,123 _scale: Scale<f64>,
124 alpha: f32,124 alpha: f32,
125 kind: Kind,125 kind: Kind,
126 ) -> Self::RenderElement {126 ) -> Self::RenderElement {
127 let elem = TextureRenderElement::from_texture_buffer(127 let elem = TextureRenderElement::from_texture_buffer(
128 self.buffer.clone(),128 self.buffer.clone(),
129- (location + self.location).to_f64(),129+ location + self.location,
130 alpha,130 alpha,
131 self.src,131 self.src,
132 self.dst.map(|dst| dst.to_f64()),132 self.dst.map(|dst| dst.to_f64()),
@@ -141,20 +141,12 @@ impl ToRenderElement for BakedBuffer<SolidColorBuffer> {
141 141
142 fn to_render_element(142 fn to_render_element(
143 &self,143 &self,
144- location: Point<i32, Logical>,144+ location: Point<f64, Logical>,
145- scale: Scale<f64>,145+ _scale: Scale<f64>,
146 alpha: f32,146 alpha: f32,
147 kind: Kind,147 kind: Kind,
148 ) -> Self::RenderElement {148 ) -> Self::RenderElement {
149- SolidColorRenderElement::from_buffer(149+ SolidColorRenderElement::from_buffer(&self.buffer, location + self.location, alpha, kind)
150- &self.buffer,
151- (location + self.location)
152- .to_physical_precise_round(scale)
153- .to_i32_round(),
154- scale,
155- alpha,
156- kind,
157- )
158 }150 }
159 }151 }
160 152
src/render_helpers/resize.rsmodified+8 -8
@@ -18,12 +18,12 @@ pub struct ResizeRenderElement(ShaderRenderElement);
18 impl ResizeRenderElement {18 impl ResizeRenderElement {
19 #[allow(clippy::too_many_arguments)]19 #[allow(clippy::too_many_arguments)]
20 pub fn new(20 pub fn new(
21- area: Rectangle<i32, Logical>,21+ area: Rectangle<f64, Logical>,
22 scale: Scale<f64>,22 scale: Scale<f64>,
23 texture_prev: (GlesTexture, Rectangle<i32, Physical>),23 texture_prev: (GlesTexture, Rectangle<i32, Physical>),
24- size_prev: Size<i32, Logical>,24+ size_prev: Size<f64, Logical>,
25 texture_next: (GlesTexture, Rectangle<i32, Physical>),25 texture_next: (GlesTexture, Rectangle<i32, Physical>),
26- size_next: Size<i32, Logical>,26+ size_next: Size<f64, Logical>,
27 progress: f32,27 progress: f32,
28 clamped_progress: f32,28 clamped_progress: f32,
29 corner_radius: CornerRadius,29 corner_radius: CornerRadius,
@@ -35,17 +35,17 @@ impl ResizeRenderElement {
35 let (texture_prev, tex_prev_geo) = texture_prev;35 let (texture_prev, tex_prev_geo) = texture_prev;
36 let (texture_next, tex_next_geo) = texture_next;36 let (texture_next, tex_next_geo) = texture_next;
37 37
38- let scale_prev = area.size.to_f64() / size_prev.to_f64();38+ let scale_prev = area.size / size_prev;
39- let scale_next = area.size.to_f64() / size_next.to_f64();39+ let scale_next = area.size / size_next;
40 40
41 // Compute the area necessary to fit a crossfade.41 // Compute the area necessary to fit a crossfade.
42 let tex_prev_geo_scaled = tex_prev_geo.to_f64().upscale(scale_prev);42 let tex_prev_geo_scaled = tex_prev_geo.to_f64().upscale(scale_prev);
43 let tex_next_geo_scaled = tex_next_geo.to_f64().upscale(scale_next);43 let tex_next_geo_scaled = tex_next_geo.to_f64().upscale(scale_next);
44- let combined_geo = tex_prev_geo_scaled.merge(tex_next_geo_scaled);44+ let combined_geo = tex_prev_geo_scaled.merge(tex_next_geo_scaled).to_i32_up();
45 45
46 let area = Rectangle::from_loc_and_size(46 let area = Rectangle::from_loc_and_size(
47- area.loc + combined_geo.loc.to_logical(scale).to_i32_round(),47+ area.loc + combined_geo.loc.to_logical(scale),
48- combined_geo.size.to_logical(scale).to_i32_round(),48+ combined_geo.size.to_logical(scale),
49 );49 );
50 50
51 // Convert Smithay types into glam types.51 // Convert Smithay types into glam types.
src/render_helpers/shader_element.rsmodified+9 -9
@@ -23,8 +23,8 @@ pub struct ShaderRenderElement {
23 program: ProgramType,23 program: ProgramType,
24 id: Id,24 id: Id,
25 commit_counter: CommitCounter,25 commit_counter: CommitCounter,
26- area: Rectangle<i32, Logical>,26+ area: Rectangle<f64, Logical>,
27- opaque_regions: Vec<Rectangle<i32, Logical>>,27+ opaque_regions: Vec<Rectangle<f64, Logical>>,
28 alpha: f32,28 alpha: f32,
29 additional_uniforms: Vec<Uniform<'static>>,29 additional_uniforms: Vec<Uniform<'static>>,
30 textures: HashMap<String, GlesTexture>,30 textures: HashMap<String, GlesTexture>,
@@ -198,8 +198,8 @@ impl ShaderRenderElement {
198 #[allow(clippy::too_many_arguments)]198 #[allow(clippy::too_many_arguments)]
199 pub fn new(199 pub fn new(
200 program: ProgramType,200 program: ProgramType,
201- size: Size<i32, Logical>,201+ size: Size<f64, Logical>,
202- opaque_regions: Option<Vec<Rectangle<i32, Logical>>>,202+ opaque_regions: Option<Vec<Rectangle<f64, Logical>>>,
203 alpha: f32,203 alpha: f32,
204 uniforms: Vec<Uniform<'_>>,204 uniforms: Vec<Uniform<'_>>,
205 textures: HashMap<String, GlesTexture>,205 textures: HashMap<String, GlesTexture>,
@@ -209,7 +209,7 @@ impl ShaderRenderElement {
209 program,209 program,
210 id: Id::new(),210 id: Id::new(),
211 commit_counter: CommitCounter::default(),211 commit_counter: CommitCounter::default(),
212- area: Rectangle::from_loc_and_size((0, 0), size),212+ area: Rectangle::from_loc_and_size((0., 0.), size),
213 opaque_regions: opaque_regions.unwrap_or_default(),213 opaque_regions: opaque_regions.unwrap_or_default(),
214 alpha,214 alpha,
215 additional_uniforms: uniforms.into_iter().map(|u| u.into_owned()).collect(),215 additional_uniforms: uniforms.into_iter().map(|u| u.into_owned()).collect(),
@@ -238,8 +238,8 @@ impl ShaderRenderElement {
238 238
239 pub fn update(239 pub fn update(
240 &mut self,240 &mut self,
241- size: Size<i32, Logical>,241+ size: Size<f64, Logical>,
242- opaque_regions: Option<Vec<Rectangle<i32, Logical>>>,242+ opaque_regions: Option<Vec<Rectangle<f64, Logical>>>,
243 uniforms: Vec<Uniform<'_>>,243 uniforms: Vec<Uniform<'_>>,
244 textures: HashMap<String, GlesTexture>,244 textures: HashMap<String, GlesTexture>,
245 ) {245 ) {
@@ -251,7 +251,7 @@ impl ShaderRenderElement {
251 self.commit_counter.increment();251 self.commit_counter.increment();
252 }252 }
253 253
254- pub fn with_location(mut self, location: Point<i32, Logical>) -> Self {254+ pub fn with_location(mut self, location: Point<f64, Logical>) -> Self {
255 self.area.loc = location;255 self.area.loc = location;
256 self256 self
257 }257 }
@@ -277,7 +277,7 @@ impl Element for ShaderRenderElement {
277 fn opaque_regions(&self, scale: Scale<f64>) -> OpaqueRegions<i32, Physical> {277 fn opaque_regions(&self, scale: Scale<f64>) -> OpaqueRegions<i32, Physical> {
278 self.opaque_regions278 self.opaque_regions
279 .iter()279 .iter()
280- .map(|region| region.to_physical_precise_round(scale))280+ .map(|region| region.to_physical_precise_down(scale))
281 .collect()281 .collect()
282 }282 }
283 283
src/render_helpers/snapshot.rsmodified+3 -3
@@ -25,7 +25,7 @@ pub struct RenderSnapshot<C, B> {
25 pub block_out_from: Option<BlockOutFrom>,25 pub block_out_from: Option<BlockOutFrom>,
26 26
27 /// Visual size of the element at the point of the snapshot.27 /// Visual size of the element at the point of the snapshot.
28- pub size: Size<i32, Logical>,28+ pub size: Size<f64, Logical>,
29 29
30 /// Contents rendered into a texture (lazily).30 /// Contents rendered into a texture (lazily).
31 pub texture: OnceCell<Option<(GlesTexture, Rectangle<i32, Physical>)>>,31 pub texture: OnceCell<Option<(GlesTexture, Rectangle<i32, Physical>)>>,
@@ -55,7 +55,7 @@ where
55 .blocked_out_contents55 .blocked_out_contents
56 .iter()56 .iter()
57 .map(|baked| {57 .map(|baked| {
58- baked.to_render_element(Point::from((0, 0)), scale, 1., Kind::Unspecified)58+ baked.to_render_element(Point::from((0., 0.)), scale, 1., Kind::Unspecified)
59 })59 })
60 .collect();60 .collect();
61 61
@@ -81,7 +81,7 @@ where
81 .contents81 .contents
82 .iter()82 .iter()
83 .map(|baked| {83 .map(|baked| {
84- baked.to_render_element(Point::from((0, 0)), scale, 1., Kind::Unspecified)84+ baked.to_render_element(Point::from((0., 0.)), scale, 1., Kind::Unspecified)
85 })85 })
86 .collect();86 .collect();
87 87
src/render_helpers/surface.rsmodified+3 -3
@@ -12,7 +12,7 @@ use super::BakedBuffer;
12 pub fn render_snapshot_from_surface_tree(12 pub fn render_snapshot_from_surface_tree(
13 renderer: &mut GlesRenderer,13 renderer: &mut GlesRenderer,
14 surface: &WlSurface,14 surface: &WlSurface,
15- location: Point<i32, Logical>,15+ location: Point<f64, Logical>,
16 storage: &mut Vec<BakedBuffer<TextureBuffer<GlesTexture>>>,16 storage: &mut Vec<BakedBuffer<TextureBuffer<GlesTexture>>>,
17 ) {17 ) {
18 let _span = tracy_client::span!("render_snapshot_from_surface_tree");18 let _span = tracy_client::span!("render_snapshot_from_surface_tree");
@@ -28,7 +28,7 @@ pub fn render_snapshot_from_surface_tree(
28 let data = &*data.borrow();28 let data = &*data.borrow();
29 29
30 if let Some(view) = data.view() {30 if let Some(view) = data.view() {
31- location += view.offset;31+ location += view.offset.to_f64();
32 TraversalAction::DoChildren(location)32 TraversalAction::DoChildren(location)
33 } else {33 } else {
34 TraversalAction::SkipChildren34 TraversalAction::SkipChildren
@@ -43,7 +43,7 @@ pub fn render_snapshot_from_surface_tree(
43 43
44 if let Some(data) = data {44 if let Some(data) = data {
45 if let Some(view) = data.borrow().view() {45 if let Some(view) = data.borrow().view() {
46- location += view.offset;46+ location += view.offset.to_f64();
47 } else {47 } else {
48 return;48 return;
49 }49 }
src/ui/config_error_notification.rsmodified+1 -1
@@ -144,7 +144,7 @@ impl ConfigErrorNotification {
144 let size = buffer.logical_size();144 let size = buffer.logical_size();
145 let y_range = size.h + f64::from(PADDING) * 2.;145 let y_range = size.h + f64::from(PADDING) * 2.;
146 146
147- let x = (f64::from(output_size.w) - size.w).max(0.) / 2.;147+ let x = (output_size.w - size.w).max(0.) / 2.;
148 let y = match &self.state {148 let y = match &self.state {
149 State::Hidden => unreachable!(),149 State::Hidden => unreachable!(),
150 State::Showing(anim) | State::Hiding(anim) => -size.h + anim.value() * y_range,150 State::Showing(anim) | State::Hiding(anim) => -size.h + anim.value() * y_range,
src/utils/mod.rsmodified+14 -6
@@ -95,16 +95,24 @@ pub fn to_physical_precise_round<N: Coordinate>(scale: f64, logical: impl Coordi
95 N::from_f64((logical.to_f64() * scale).round())95 N::from_f64((logical.to_f64() * scale).round())
96 }96 }
97 97
98-pub fn output_size(output: &Output) -> Size<i32, Logical> {98+pub fn round_logical_in_physical(scale: f64, logical: f64) -> f64 {
99+ (logical * scale).round() / scale
100+}
101+
102+pub fn round_logical_in_physical_max1(scale: f64, logical: f64) -> f64 {
103+ if logical == 0. {
104+ return 0.;
105+ }
106+
107+ (logical * scale).max(1.).round() / scale
108+}
109+
110+pub fn output_size(output: &Output) -> Size<f64, Logical> {
99 let output_scale = output.current_scale().fractional_scale();111 let output_scale = output.current_scale().fractional_scale();
100 let output_transform = output.current_transform();112 let output_transform = output.current_transform();
101 let output_mode = output.current_mode().unwrap();113 let output_mode = output.current_mode().unwrap();
102-
103- // Like in LayerMap::arrange().
104- //
105- // FIXME: return fractional logical size.
106 let logical_size = output_mode.size.to_f64().to_logical(output_scale);114 let logical_size = output_mode.size.to_f64().to_logical(output_scale);
107- output_transform.transform_size(logical_size.to_i32_round())115+ output_transform.transform_size(logical_size)
108 }116 }
109 117
110 pub fn logical_output(output: &Output) -> niri_ipc::LogicalOutput {118 pub fn logical_output(output: &Output) -> niri_ipc::LogicalOutput {
src/window/mapped.rsmodified+20 -30
@@ -3,7 +3,6 @@ use std::cmp::{max, min};
3 use std::time::Duration;3 use std::time::Duration;
4 4
5 use niri_config::WindowRule;5 use niri_config::WindowRule;
6-use smithay::backend::renderer::element::solid::{SolidColorBuffer, SolidColorRenderElement};
7 use smithay::backend::renderer::element::surface::render_elements_from_surface_tree;6 use smithay::backend::renderer::element::surface::render_elements_from_surface_tree;
8 use smithay::backend::renderer::element::{Id, Kind};7 use smithay::backend::renderer::element::{Id, Kind};
9 use smithay::backend::renderer::gles::GlesRenderer;8 use smithay::backend::renderer::gles::GlesRenderer;
@@ -24,6 +23,7 @@ use crate::layout::{
24 use crate::niri::WindowOffscreenId;23 use crate::niri::WindowOffscreenId;
25 use crate::render_helpers::renderer::NiriRenderer;24 use crate::render_helpers::renderer::NiriRenderer;
26 use crate::render_helpers::snapshot::RenderSnapshot;25 use crate::render_helpers::snapshot::RenderSnapshot;
26+use crate::render_helpers::solid_color::{SolidColorBuffer, SolidColorRenderElement};
27 use crate::render_helpers::surface::render_snapshot_from_surface_tree;27 use crate::render_helpers::surface::render_snapshot_from_surface_tree;
28 use crate::render_helpers::{BakedBuffer, RenderTarget, SplitElements};28 use crate::render_helpers::{BakedBuffer, RenderTarget, SplitElements};
29 use crate::utils::{send_scale_transform, ResizeEdge};29 use crate::utils::{send_scale_transform, ResizeEdge};
@@ -104,7 +104,7 @@ impl Mapped {
104 need_to_recompute_rules: false,104 need_to_recompute_rules: false,
105 is_focused: false,105 is_focused: false,
106 is_active_in_column: false,106 is_active_in_column: false,
107- block_out_buffer: RefCell::new(SolidColorBuffer::new((0, 0), [0., 0., 0., 1.])),107+ block_out_buffer: RefCell::new(SolidColorBuffer::new((0., 0.), [0., 0., 0., 1.])),
108 animate_next_configure: false,108 animate_next_configure: false,
109 animate_serials: Vec::new(),109 animate_serials: Vec::new(),
110 animation_snapshot: None,110 animation_snapshot: None,
@@ -158,18 +158,18 @@ impl Mapped {
158 fn render_snapshot(&self, renderer: &mut GlesRenderer) -> LayoutElementRenderSnapshot {158 fn render_snapshot(&self, renderer: &mut GlesRenderer) -> LayoutElementRenderSnapshot {
159 let _span = tracy_client::span!("Mapped::render_snapshot");159 let _span = tracy_client::span!("Mapped::render_snapshot");
160 160
161- let size = self.size();161+ let size = self.size().to_f64();
162 162
163 let mut buffer = self.block_out_buffer.borrow_mut();163 let mut buffer = self.block_out_buffer.borrow_mut();
164 buffer.resize(size);164 buffer.resize(size);
165 let blocked_out_contents = vec![BakedBuffer {165 let blocked_out_contents = vec![BakedBuffer {
166 buffer: buffer.clone(),166 buffer: buffer.clone(),
167- location: Point::from((0, 0)),167+ location: Point::from((0., 0.)),
168 src: None,168 src: None,
169 dst: None,169 dst: None,
170 }];170 }];
171 171
172- let buf_pos = self.window.geometry().loc.upscale(-1);172+ let buf_pos = self.window.geometry().loc.upscale(-1).to_f64();
173 173
174 let mut contents = vec![];174 let mut contents = vec![];
175 175
@@ -180,7 +180,7 @@ impl Mapped {
180 render_snapshot_from_surface_tree(180 render_snapshot_from_surface_tree(
181 renderer,181 renderer,
182 popup.wl_surface(),182 popup.wl_surface(),
183- buf_pos + offset,183+ buf_pos + offset.to_f64(),
184 &mut contents,184 &mut contents,
185 );185 );
186 }186 }
@@ -248,7 +248,7 @@ impl LayoutElement for Mapped {
248 fn render<R: NiriRenderer>(248 fn render<R: NiriRenderer>(
249 &self,249 &self,
250 renderer: &mut R,250 renderer: &mut R,
251- location: Point<i32, Logical>,251+ location: Point<f64, Logical>,
252 scale: Scale<f64>,252 scale: Scale<f64>,
253 alpha: f32,253 alpha: f32,
254 target: RenderTarget,254 target: RenderTarget,
@@ -257,17 +257,12 @@ impl LayoutElement for Mapped {
257 257
258 if target.should_block_out(self.rules.block_out_from) {258 if target.should_block_out(self.rules.block_out_from) {
259 let mut buffer = self.block_out_buffer.borrow_mut();259 let mut buffer = self.block_out_buffer.borrow_mut();
260- buffer.resize(self.window.geometry().size);260+ buffer.resize(self.window.geometry().size.to_f64());
261- let elem = SolidColorRenderElement::from_buffer(261+ let elem =
262- &buffer,262+ SolidColorRenderElement::from_buffer(&buffer, location, alpha, Kind::Unspecified);
263- location.to_physical_precise_round(scale),
264- scale,
265- alpha,
266- Kind::Unspecified,
267- );
268 rv.normal.push(elem.into());263 rv.normal.push(elem.into());
269 } else {264 } else {
270- let buf_pos = location - self.window.geometry().loc;265+ let buf_pos = location - self.window.geometry().loc.to_f64();
271 266
272 let surface = self.toplevel().wl_surface();267 let surface = self.toplevel().wl_surface();
273 for (popup, popup_offset) in PopupManager::popups_for_surface(surface) {268 for (popup, popup_offset) in PopupManager::popups_for_surface(surface) {
@@ -276,7 +271,7 @@ impl LayoutElement for Mapped {
276 rv.popups.extend(render_elements_from_surface_tree(271 rv.popups.extend(render_elements_from_surface_tree(
277 renderer,272 renderer,
278 popup.wl_surface(),273 popup.wl_surface(),
279- (buf_pos + offset).to_physical_precise_round(scale),274+ (buf_pos + offset.to_f64()).to_physical_precise_round(scale),
280 scale,275 scale,
281 alpha,276 alpha,
282 Kind::Unspecified,277 Kind::Unspecified,
@@ -299,24 +294,19 @@ impl LayoutElement for Mapped {
299 fn render_normal<R: NiriRenderer>(294 fn render_normal<R: NiriRenderer>(
300 &self,295 &self,
301 renderer: &mut R,296 renderer: &mut R,
302- location: Point<i32, Logical>,297+ location: Point<f64, Logical>,
303 scale: Scale<f64>,298 scale: Scale<f64>,
304 alpha: f32,299 alpha: f32,
305 target: RenderTarget,300 target: RenderTarget,
306 ) -> Vec<LayoutElementRenderElement<R>> {301 ) -> Vec<LayoutElementRenderElement<R>> {
307 if target.should_block_out(self.rules.block_out_from) {302 if target.should_block_out(self.rules.block_out_from) {
308 let mut buffer = self.block_out_buffer.borrow_mut();303 let mut buffer = self.block_out_buffer.borrow_mut();
309- buffer.resize(self.window.geometry().size);304+ buffer.resize(self.window.geometry().size.to_f64());
310- let elem = SolidColorRenderElement::from_buffer(305+ let elem =
311- &buffer,306+ SolidColorRenderElement::from_buffer(&buffer, location, alpha, Kind::Unspecified);
312- location.to_physical_precise_round(scale),
313- scale,
314- alpha,
315- Kind::Unspecified,
316- );
317 vec![elem.into()]307 vec![elem.into()]
318 } else {308 } else {
319- let buf_pos = location - self.window.geometry().loc;309+ let buf_pos = location - self.window.geometry().loc.to_f64();
320 let surface = self.toplevel().wl_surface();310 let surface = self.toplevel().wl_surface();
321 render_elements_from_surface_tree(311 render_elements_from_surface_tree(
322 renderer,312 renderer,
@@ -332,7 +322,7 @@ impl LayoutElement for Mapped {
332 fn render_popups<R: NiriRenderer>(322 fn render_popups<R: NiriRenderer>(
333 &self,323 &self,
334 renderer: &mut R,324 renderer: &mut R,
335- location: Point<i32, Logical>,325+ location: Point<f64, Logical>,
336 scale: Scale<f64>,326 scale: Scale<f64>,
337 alpha: f32,327 alpha: f32,
338 target: RenderTarget,328 target: RenderTarget,
@@ -342,7 +332,7 @@ impl LayoutElement for Mapped {
342 } else {332 } else {
343 let mut rv = vec![];333 let mut rv = vec![];
344 334
345- let buf_pos = location - self.window.geometry().loc;335+ let buf_pos = location - self.window.geometry().loc.to_f64();
346 let surface = self.toplevel().wl_surface();336 let surface = self.toplevel().wl_surface();
347 for (popup, popup_offset) in PopupManager::popups_for_surface(surface) {337 for (popup, popup_offset) in PopupManager::popups_for_surface(surface) {
348 let offset = self.window.geometry().loc + popup_offset - popup.geometry().loc;338 let offset = self.window.geometry().loc + popup_offset - popup.geometry().loc;
@@ -350,7 +340,7 @@ impl LayoutElement for Mapped {
350 rv.extend(render_elements_from_surface_tree(340 rv.extend(render_elements_from_surface_tree(
351 renderer,341 renderer,
352 popup.wl_surface(),342 popup.wl_surface(),
353- (buf_pos + offset).to_physical_precise_round(scale),343+ (buf_pos + offset.to_f64()).to_physical_precise_round(scale),
354 scale,344 scale,
355 alpha,345 alpha,
356 Kind::Unspecified,346 Kind::Unspecified,
wiki/Configuration:-Layout.mdmodified+24 -0
@@ -48,6 +48,10 @@ layout {
48 48
49 Set gaps around (inside and outside) windows in logical pixels.49 Set gaps around (inside and outside) windows in logical pixels.
50 50
51+<sup>Since: 0.1.7</sup> You can use fractional values.
52+The value will be rounded to physical pixels according to the scale factor of every output.
53+For example, `gaps 0.5` on an output with `scale 2` will result in one physical-pixel wide gaps.
54+
51 ```55 ```
52 layout {56 layout {
53 gaps 1657 gaps 16
@@ -170,6 +174,22 @@ layout {
170 }174 }
171 ```175 ```
172 176
177+#### Width
178+
179+Set the thickness of the border in logical pixels.
180+
181+<sup>Since: 0.1.7</sup> You can use fractional values.
182+The value will be rounded to physical pixels according to the scale factor of every output.
183+For example, `width 0.5` on an output with `scale 2` will result in one physical-pixel thick borders.
184+
185+```
186+layout {
187+ border {
188+ width 2
189+ }
190+}
191+```
192+
173 #### Colors193 #### Colors
174 194
175 Colors can be set in a variety of ways:195 Colors can be set in a variety of ways:
@@ -227,6 +247,10 @@ They are set in logical pixels.
227 Left and right struts will cause the next window to the side to always peek out slightly.247 Left and right struts will cause the next window to the side to always peek out slightly.
228 Top and bottom struts will simply add outer gaps in addition to the area occupied by layer-shell panels and regular gaps.248 Top and bottom struts will simply add outer gaps in addition to the area occupied by layer-shell panels and regular gaps.
229 249
250+<sup>Since: 0.1.7</sup> You can use fractional values.
251+The value will be rounded to physical pixels according to the scale factor of every output.
252+For example, `top 0.5` on an output with `scale 2` will result in one physical-pixel wide top strut.
253+
230 ```254 ```
231 layout {255 layout {
232 struts {256 struts {
wiki/Fractional-Layout.mdadded+34 -0
@@ -0,0 +1,34 @@
1+There are two main coordinate spaces in niri: physical (pixels of every individual output) and logical (shared among all outputs, takes into account the scale of every output).
2+Wayland clients mostly work in the logical space, and it's the most convenient space to do all the layout in, since it bakes in the output scaling factor.
3+
4+However, many things need to be sized or positioned at integer physical coordinates.
5+For example, Wayland toplevel buffers are assumed to be placed at an integer physical pixel on an output (and `WaylandSurfaceRenderElement` will do that for you).
6+Borders and focus rings should also have a width equal to an integer number of physical pixels to stay crisp (not to mention that `SolidColorRenderElement` does not anti-alias lines at fractional pixel positions).
7+
8+Integer physical coordinates do not necessarily correspond to integer logical coordinates though.
9+Even with an integer scale = 2, a physical pixel at (1, 1) will be at the logical position of (0.5, 0.5).
10+This problem becomes much worse with fractional scale factors where most integer logical coordinates will fall on fractional physical coordinates.
11+
12+Thus, niri uses fractional logical coordinates for most of its layout.
13+However, one needs to be very careful to keep things aligned to the physical grid to avoid artifacts like:
14+
15+* Border width alternating 1 px thicker/thinner
16+* Border showing 1 px off from the window at certain positions
17+* 1 px gaps around rounded corners
18+* Slightly blurry window contents during resizes
19+* And so on...
20+
21+The way it's handled in niri is:
22+
23+1. All relevant sizes on a workspace are rounded to an integer physical coordinate according to the current output scale. Things like struts, gaps, border widths, working area location.
24+
25+ It's important to understand that they remain fractional numbers in the logical space, but these numbers correspond to an integer number of pixels in the physical space.
26+ The rounding looks something like: `(logical_size * scale).round() / scale`.
27+ Whenever a workspace moves to an output with a different scale (or the output scale changes), all sizes are re-rounded from their original configured values to align with the new physical space.
28+2. The view offset and individual column/tile render offsets are *not* rounded to physical pixels, but:
29+3. `tiles_with_render_positions()` rounds tile positions to physical pixels as it returns them,
30+4. Custom shaders like opening, closing and resizing windows, are also careful to keep positions and sizes rounded to the physical pixels.
31+
32+The idea is that every tile can assume that it is rendered at an integer physical coordinate, therefore when shifting the position by, say, border width (also rounded to integer physical coordinates), the new position will stay rounded to integer physical coordinates.
33+The same logic works for the rest of the layout thanks to gaps, struts and working area being similarly rounded.
34+This way, the entire layout is always aligned, as long as it is positioned at an integer physical coordinate (which rounding the tile positions effectively achieves).
wiki/_Sidebar.mdmodified+1 -0
@@ -24,3 +24,4 @@
24 ## Development24 ## Development
25 * [Design Principles](./Design-Principles.md)25 * [Design Principles](./Design-Principles.md)
26 * [Developing niri](./Developing-niri.md)26 * [Developing niri](./Developing-niri.md)
27+* [Fractional Layout](./Fractional-Layout.md)