Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Switch out winapi to windows-rs #298

Draft
wants to merge 23 commits into
base: main
Choose a base branch
from
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Cleanup unused references
dklassic committed Jul 11, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 37e446ddfe7462da0a13bdeb78be048257d77b42
1 change: 0 additions & 1 deletion src/platform/windows/wgl/connection.rs
Original file line number Diff line number Diff line change
@@ -13,7 +13,6 @@ use euclid::default::Size2D;

use std::os::raw::c_void;

// use winapi::shared::windef::HWND;
use windows::Win32::Foundation::HWND;

/// Represents a connection to the display server.
2 changes: 1 addition & 1 deletion src/platform/windows/wgl/context.rs
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@ use std::mem;
use std::os::raw::{c_char, c_int, c_void};
use std::ptr;
use std::thread;
use windows::core::{s, w, PCSTR, PSTR};
use windows::core::PCSTR;
use windows::Win32::Foundation::HANDLE;
use windows::Win32::Foundation::HINSTANCE;
use windows::Win32::Foundation::HWND;
37 changes: 12 additions & 25 deletions src/platform/windows/wgl/device.rs
Original file line number Diff line number Diff line change
@@ -13,37 +13,24 @@ use std::ptr;
use std::sync::mpsc::{self, Sender};
use std::thread::{self, JoinHandle};
use windows::core::{Interface, PCSTR};
// use winapi::shared::dxgi::{IDXGIAdapter, IDXGIDevice};
// use winapi::shared::minwindef::{self, FALSE, UINT};
// use winapi::shared::ntdef::{HANDLE, LPCSTR};
use windows::Win32::Foundation::{HANDLE, HINSTANCE, HMODULE, LPARAM, LRESULT, WPARAM};
// use winapi::shared::windef::{HBRUSH, HDC, HWND};
use windows::Win32::Foundation::HWND;
use windows::Win32::Graphics::Gdi::{GetDC, HBRUSH, HDC};
// use winapi::shared::winerror::{self, S_OK};
use windows::Win32::Graphics::Dxgi::{IDXGIAdapter, IDXGIDevice};
// use winapi::um::d3d11::{D3D11CreateDevice, ID3D11Device, ID3D11DeviceContext, D3D11_SDK_VERSION};
use windows::Win32::Foundation::{HANDLE, HINSTANCE, HMODULE, LPARAM, LRESULT, WPARAM};
use windows::Win32::Graphics::Direct3D::D3D_DRIVER_TYPE_HARDWARE;
use windows::Win32::Graphics::Direct3D11::{
D3D11CreateDevice, ID3D11Device, ID3D11DeviceContext, D3D11_CREATE_DEVICE_FLAG,
D3D11_SDK_VERSION,
};
// use winapi::um::d3dcommon::D3D_DRIVER_TYPE_HARDWARE;
use windows::Win32::Graphics::Direct3D::D3D_DRIVER_TYPE_HARDWARE;
// use winapi::um::libloaderapi;
use windows::Win32::System::LibraryLoader::{GetModuleHandleA, GetProcAddress};
// use windows::Win32::System::LibraryLoader::GetProcAddress;
// use winapi::um::winuser::{self, COLOR_BACKGROUND, CS_OWNDC, MSG, WM_CLOSE};
use windows::Win32::Graphics::Dxgi::{IDXGIAdapter, IDXGIDevice};
use windows::Win32::Graphics::Gdi::ReleaseDC;
use windows::Win32::Graphics::Gdi::COLOR_BACKGROUND;
use windows::Win32::Graphics::Gdi::{GetDC, HBRUSH, HDC};
use windows::Win32::System::LibraryLoader::{GetModuleHandleA, GetProcAddress};
use windows::Win32::UI::WindowsAndMessaging::{
self as winuser, CreateWindowExA, DefWindowProcA, GetClassInfoA, GetWindowLongPtrA,
SetWindowLongPtrA, CREATESTRUCTA, GWLP_USERDATA, HCURSOR, HICON, HMENU, WINDOW_EX_STYLE,
WM_NCCREATE,
CreateWindowExA, DefWindowProcA, DispatchMessageA, GetClassInfoA, GetMessageA, PostMessageA,
RegisterClassA, TranslateMessage, HCURSOR, HICON, HMENU, WINDOW_EX_STYLE,
};
use windows::Win32::UI::WindowsAndMessaging::{CS_OWNDC, MSG, WM_CLOSE};
// use winapi::um::winuser::{WNDCLASSA, WS_OVERLAPPEDWINDOW};
use windows::Win32::UI::WindowsAndMessaging::{WNDCLASSA, WS_OVERLAPPEDWINDOW};
// use wio::com::ComPtr;

pub(crate) const HIDDEN_WINDOW_SIZE: c_int = 16;

@@ -289,7 +276,7 @@ pub(crate) struct DCGuard<'a> {
impl Drop for HiddenWindow {
fn drop(&mut self) {
unsafe {
winuser::PostMessageA(self.window, WM_CLOSE, WPARAM(0), LPARAM(0));
PostMessageA(self.window, WM_CLOSE, WPARAM(0), LPARAM(0));
if let Some(join_handle) = self.join_handle.take() {
drop(join_handle.join());
}
@@ -351,7 +338,7 @@ impl HiddenWindow {
lpszMenuName: PCSTR::null(),
lpszClassName: window_class_name,
};
let window_class_atom = winuser::RegisterClassA(&window_class);
let window_class_atom = RegisterClassA(&window_class);
assert_ne!(window_class_atom, 0);
}

@@ -373,9 +360,9 @@ impl HiddenWindow {
sender.send(SendableHWND(window)).unwrap();

let mut msg: MSG = mem::zeroed();
while winuser::GetMessageA(&mut msg, window, 0, 0) != false {
winuser::TranslateMessage(&msg);
winuser::DispatchMessageA(&msg);
while GetMessageA(&mut msg, window, 0, 0) != false {
TranslateMessage(&msg);
DispatchMessageA(&msg);
if msg.message == WM_CLOSE {
break;
}
1 change: 0 additions & 1 deletion src/platform/windows/wgl/surface.rs
Original file line number Diff line number Diff line change
@@ -16,7 +16,6 @@ use std::fmt::{self, Debug, Formatter};
use std::marker::PhantomData;
use std::mem;
use std::os::raw::c_void;
use std::ptr;
use std::thread;
use windows::core::Interface;
use windows::Win32::Foundation::HANDLE;