Skip to content

Commit

Permalink
Fix the calculation of the window size (neovide#2908)
Browse files Browse the repository at this point in the history
  • Loading branch information
fredizzimo authored Dec 25, 2024
1 parent 8dcb30c commit d2552fb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ d3d_debug = [] # Enable the D3D debug layer

[dependencies]
anyhow = { version = "1.0.95", features = ["backtrace"] }
approx = "0.5.1"
async-trait = "0.1.83"
backtrace = "0.3.74"
clap = { version = "4.5.23", features = ["cargo", "derive", "env", "color"] }
Expand Down Expand Up @@ -79,7 +80,6 @@ notify-debouncer-full = "0.4.0"
regex = "1.11.1"

[dev-dependencies]
approx = "0.5.1"
scoped-env = "2.1.0"
serial_test = "3.2.0"

Expand Down
27 changes: 19 additions & 8 deletions src/window/window_wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ use {
#[cfg(target_os = "macos")]
use super::macos::MacosWindowFeature;

const GRID_TOLERANCE: f32 = 0e-6;

use approx::AbsDiffEq;
use log::trace;
use raw_window_handle::{HasWindowHandle, RawWindowHandle};
use winit::{
Expand Down Expand Up @@ -694,10 +697,14 @@ impl WinitWindowWrapper {
window_padding.top + window_padding.bottom,
);

let window_size = (*grid_size * self.renderer.grid_renderer.grid_scale)
.floor()
.try_cast()
.unwrap()
let window_size = *grid_size * self.renderer.grid_renderer.grid_scale;
let window_size = if window_size.abs_diff_eq(&window_size.round(), GRID_TOLERANCE) {
window_size.round()
} else {
window_size.floor()
}
.try_cast()
.unwrap()
+ window_padding_size;

log::info!(
Expand Down Expand Up @@ -742,10 +749,14 @@ impl WinitWindowWrapper {
PixelSize::new(self.saved_inner_size.width, self.saved_inner_size.height)
- window_padding_size;

let grid_size = (content_size / self.renderer.grid_renderer.grid_scale)
.floor()
.try_cast()
.unwrap();
let grid_size = content_size / self.renderer.grid_renderer.grid_scale;
let grid_size = if grid_size.abs_diff_eq(&grid_size.round(), GRID_TOLERANCE) {
grid_size.round()
} else {
grid_size.ceil()
}
.try_cast()
.unwrap();

grid_size.max(min)
}
Expand Down

0 comments on commit d2552fb

Please sign in to comment.