From 85b4f189bd152b580f52bf138a31db65bfff5a5a Mon Sep 17 00:00:00 2001 From: jtnunley Date: Tue, 20 Dec 2022 08:08:46 -0800 Subject: [PATCH] Port to win32 --- .gitignore | 3 ++- Cargo.toml | 6 +++--- src/win32.rs | 15 +++++++++------ 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/.gitignore b/.gitignore index 6a59f55..2f45575 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /target Cargo.lock -/.idea \ No newline at end of file +/.idea +/.vscode diff --git a/Cargo.toml b/Cargo.toml index dfcba9b..d990769 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,9 +21,9 @@ wayland-backend = {version = "0.1.0-beta.14", features = ["client_system"]} wayland-client = {version = "0.30.0-beta.14"} x11-dl = "2.19.1" -[target.'cfg(target_os = "windows")'.dependencies.winapi] -version = "0.3.9" -features = ["windef", "wingdi", "winuser"] +[target.'cfg(target_os = "windows")'.dependencies.windows-sys] +version = "0.42.0" +features = ["Win32_Graphics_Gdi", "Win32_UI_WindowsAndMessaging", "Win32_Foundation"] [target.'cfg(target_os = "macos")'.dependencies] cocoa = "0.24.0" diff --git a/src/win32.rs b/src/win32.rs index 0517844..f4f1c5c 100644 --- a/src/win32.rs +++ b/src/win32.rs @@ -1,9 +1,12 @@ use crate::{GraphicsContextImpl, SwBufError}; use raw_window_handle::{HasRawWindowHandle, Win32WindowHandle}; use std::os::raw::c_int; -use winapi::shared::windef::{HDC, HWND}; -use winapi::um::wingdi::{StretchDIBits, BITMAPINFOHEADER, BI_BITFIELDS, RGBQUAD}; -use winapi::um::winuser::{GetDC, ValidateRect}; + +use windows_sys::Win32::Foundation::HWND; +use windows_sys::Win32::Graphics::Gdi::{ + StretchDIBits, BITMAPINFOHEADER, BI_BITFIELDS, RGBQUAD, HDC, + ValidateRect, GetDC, SRCCOPY, DIB_RGB_COLORS, +}; pub struct Win32Impl { window: HWND, @@ -22,7 +25,7 @@ impl Win32Impl { pub unsafe fn new(handle: &Win32WindowHandle) -> Result> { let dc = GetDC(handle.hwnd as HWND); - if dc.is_null(){ + if dc == 0 { return Err(SwBufError::PlatformError(Some("Device Context is null".into()), None)); } @@ -61,8 +64,8 @@ impl GraphicsContextImpl for Win32Impl { height as c_int, std::mem::transmute(buffer.as_ptr()), std::mem::transmute(&bitmap_info), - winapi::um::wingdi::DIB_RGB_COLORS, - winapi::um::wingdi::SRCCOPY, + DIB_RGB_COLORS, + SRCCOPY, ); ValidateRect(self.window, std::ptr::null_mut());