From f8fdfa4ec9ccadb261ace4d6689a15fd79bdffad Mon Sep 17 00:00:00 2001 From: Erik Kinnunen Date: Mon, 7 Oct 2024 15:23:46 +0300 Subject: [PATCH] Return `Window` even when pixel measurements not reported in ioctl (#115) Co-authored-by: Dhruv Bhanushali --- src/main.rs | 7 ++++--- src/models/window.rs | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index 8a0f6e6..e43f7ce 100644 --- a/src/main.rs +++ b/src/main.rs @@ -18,9 +18,10 @@ use log::debug; use std::sync::LazyLock; static PLS: LazyLock = LazyLock::new(|| { - let (supports_gfx, window) = match (is_supported(), Window::try_new()) { - (true, Some(window)) => (true, Some(window)), - _ => (false, None), + let window = Window::try_new(); + let supports_gfx = match &window { + Some(win) if win.ws_xpixel > 0 && win.ws_ypixel > 0 => is_supported(), + _ => false, }; Pls { diff --git a/src/models/window.rs b/src/models/window.rs index 6df64f7..ea14a72 100644 --- a/src/models/window.rs +++ b/src/models/window.rs @@ -19,7 +19,7 @@ impl Window { let mut win = Self::default(); #[allow(clippy::useless_conversion)] let r = unsafe { ioctl(STDOUT_FILENO, TIOCGWINSZ.into(), &mut win) }; - if r == 0 && win.ws_xpixel > win.ws_col && win.ws_ypixel > win.ws_row { + if r == 0 && win.ws_row > 0 && win.ws_col > 0 { return Some(win); } warn!("Could not determine cell dimensions.");