From 74e7611ceb64b13ce65a1f63306b41dcfec2881e Mon Sep 17 00:00:00 2001 From: intigonzalez Date: Thu, 7 Mar 2024 03:12:44 +0100 Subject: [PATCH] windows: get current display size (#8916) For the moment the windows port has a single display with hard-coded values. This first PR is just to at least fetch the **actual size of the current display**. The idea is using this code as a first template to start getting familar with the code base and prepare the work for enumerating all displays. --- crates/gpui/src/platform/windows/display.rs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/crates/gpui/src/platform/windows/display.rs b/crates/gpui/src/platform/windows/display.rs index 448433b6fb10ba1847f4e33bbbe35f710d9651ed..a865246f82976688ea7286644ed7d2a5df96e089 100644 --- a/crates/gpui/src/platform/windows/display.rs +++ b/crates/gpui/src/platform/windows/display.rs @@ -1,5 +1,9 @@ use anyhow::{anyhow, Result}; use uuid::Uuid; +use windows::{ + core::PCSTR, + Win32::Graphics::Gdi::{EnumDisplaySettingsA, DEVMODEA, ENUM_CURRENT_SETTINGS}, +}; use crate::{Bounds, DisplayId, GlobalPixels, PlatformDisplay, Point, Size}; @@ -23,13 +27,21 @@ impl PlatformDisplay for WindowsDisplay { Err(anyhow!("not implemented yet.")) } - // todo!("windows") fn bounds(&self) -> Bounds { + let mut dev = DEVMODEA { + dmSize: std::mem::size_of::() as _, + ..unsafe { std::mem::zeroed() } + }; + unsafe { EnumDisplaySettingsA(PCSTR::null(), ENUM_CURRENT_SETTINGS, &mut dev) }; + let w = dev.dmPelsWidth; + let h = dev.dmPelsHeight; + + log::debug!("Screen size: {w} {h}"); Bounds::new( Point::new(0.0.into(), 0.0.into()), Size { - width: 1920.0.into(), - height: 1280.0.into(), + width: GlobalPixels(w as f32), + height: GlobalPixels(h as f32), }, ) }