Skip to content

Commit 85b4f18

Browse files
notgulljackpot51
authored andcommitted
Port to win32
1 parent 95e8d05 commit 85b4f18

File tree

3 files changed

+14
-10
lines changed

3 files changed

+14
-10
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
/target
22
Cargo.lock
3-
/.idea
3+
/.idea
4+
/.vscode

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ wayland-backend = {version = "0.1.0-beta.14", features = ["client_system"]}
2121
wayland-client = {version = "0.30.0-beta.14"}
2222
x11-dl = "2.19.1"
2323

24-
[target.'cfg(target_os = "windows")'.dependencies.winapi]
25-
version = "0.3.9"
26-
features = ["windef", "wingdi", "winuser"]
24+
[target.'cfg(target_os = "windows")'.dependencies.windows-sys]
25+
version = "0.42.0"
26+
features = ["Win32_Graphics_Gdi", "Win32_UI_WindowsAndMessaging", "Win32_Foundation"]
2727

2828
[target.'cfg(target_os = "macos")'.dependencies]
2929
cocoa = "0.24.0"

src/win32.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
use crate::{GraphicsContextImpl, SwBufError};
22
use raw_window_handle::{HasRawWindowHandle, Win32WindowHandle};
33
use std::os::raw::c_int;
4-
use winapi::shared::windef::{HDC, HWND};
5-
use winapi::um::wingdi::{StretchDIBits, BITMAPINFOHEADER, BI_BITFIELDS, RGBQUAD};
6-
use winapi::um::winuser::{GetDC, ValidateRect};
4+
5+
use windows_sys::Win32::Foundation::HWND;
6+
use windows_sys::Win32::Graphics::Gdi::{
7+
StretchDIBits, BITMAPINFOHEADER, BI_BITFIELDS, RGBQUAD, HDC,
8+
ValidateRect, GetDC, SRCCOPY, DIB_RGB_COLORS,
9+
};
710

811
pub struct Win32Impl {
912
window: HWND,
@@ -22,7 +25,7 @@ impl Win32Impl {
2225
pub unsafe fn new<W: HasRawWindowHandle>(handle: &Win32WindowHandle) -> Result<Self, crate::SwBufError<W>> {
2326
let dc = GetDC(handle.hwnd as HWND);
2427

25-
if dc.is_null(){
28+
if dc == 0 {
2629
return Err(SwBufError::PlatformError(Some("Device Context is null".into()), None));
2730
}
2831

@@ -61,8 +64,8 @@ impl GraphicsContextImpl for Win32Impl {
6164
height as c_int,
6265
std::mem::transmute(buffer.as_ptr()),
6366
std::mem::transmute(&bitmap_info),
64-
winapi::um::wingdi::DIB_RGB_COLORS,
65-
winapi::um::wingdi::SRCCOPY,
67+
DIB_RGB_COLORS,
68+
SRCCOPY,
6669
);
6770

6871
ValidateRect(self.window, std::ptr::null_mut());

0 commit comments

Comments
 (0)