aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPeter Atashian <retep998@gmail.com>2015-01-25 21:52:17 -0500
committerPeter Atashian <retep998@gmail.com>2015-01-25 21:52:17 -0500
commit33cd252f99c003570ac9c7b9e16267eafec8156e (patch)
treeca75ee7ee2296a47d6241c8f2ea9895423302518 /src
parentdf5fe355df5aa9ce9f233ad77593ed26e45cfd4c (diff)
downloadglutin-33cd252f99c003570ac9c7b9e16267eafec8156e.tar.gz
glutin-33cd252f99c003570ac9c7b9e16267eafec8156e.zip
Upgrade to latest winapi
Signed-off-by: Peter Atashian <retep998@gmail.com>
Diffstat (limited to 'src')
-rw-r--r--src/lib.rs6
-rw-r--r--src/win32/init.rs67
-rw-r--r--src/win32/mod.rs31
-rw-r--r--src/win32/monitor.rs5
4 files changed, 61 insertions, 48 deletions
diff --git a/src/lib.rs b/src/lib.rs
index f31edfe..ada4185 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -32,6 +32,12 @@ extern crate libc;
#[cfg(target_os = "windows")]
extern crate winapi;
+#[cfg(target_os = "windows")]
+extern crate "kernel32-sys" as kernel32;
+#[cfg(target_os = "windows")]
+extern crate "gdi32-sys" as gdi32;
+#[cfg(target_os = "windows")]
+extern crate "user32-sys" as user32;
#[cfg(target_os = "macos")]
extern crate cocoa;
#[cfg(target_os = "macos")]
diff --git a/src/win32/init.rs b/src/win32/init.rs
index 7317c42..a20361d 100644
--- a/src/win32/init.rs
+++ b/src/win32/init.rs
@@ -13,6 +13,9 @@ use std::sync::mpsc::{Sender, Receiver, channel};
use libc;
use super::gl;
use winapi;
+use kernel32;
+use user32;
+use gdi32;
/// Stores the current window and its events dispatcher.
///
@@ -57,7 +60,7 @@ pub fn new_window(builder_dimensions: Option<(u32, u32)>, builder_title: String,
lpfnWndProc: callback,
cbClsExtra: 0,
cbWndExtra: 0,
- hInstance: unsafe { winapi::GetModuleHandleW(ptr::null()) },
+ hInstance: unsafe { kernel32::GetModuleHandleW(ptr::null()) },
hIcon: ptr::null_mut(),
hCursor: ptr::null_mut(),
hbrBackground: ptr::null_mut(),
@@ -70,7 +73,7 @@ pub fn new_window(builder_dimensions: Option<(u32, u32)>, builder_title: String,
// an error, and because errors here are detected during CreateWindowEx anyway.
// Also since there is no weird element in the struct, there is no reason for this
// call to fail.
- unsafe { winapi::RegisterClassExW(&class) };
+ unsafe { user32::RegisterClassExW(&class) };
class_name
};
@@ -104,7 +107,7 @@ pub fn new_window(builder_dimensions: Option<(u32, u32)>, builder_title: String,
screen_settings.dmBitsPerPel = 32; // TODO: ?
screen_settings.dmFields = winapi::DM_BITSPERPEL | winapi::DM_PELSWIDTH | winapi::DM_PELSHEIGHT;
- let result = unsafe { winapi::ChangeDisplaySettingsExW(monitor.get_system_name().as_ptr(),
+ let result = unsafe { user32::ChangeDisplaySettingsExW(monitor.get_system_name().as_ptr(),
&mut screen_settings, ptr::null_mut(), winapi::CDS_FULLSCREEN, ptr::null_mut()) };
if result != winapi::DISP_CHANGE_SUCCESSFUL {
@@ -122,19 +125,19 @@ pub fn new_window(builder_dimensions: Option<(u32, u32)>, builder_title: String,
};
// adjusting the window coordinates using the style
- unsafe { winapi::AdjustWindowRectEx(&mut rect, style, 0, ex_style) };
+ unsafe { user32::AdjustWindowRectEx(&mut rect, style, 0, ex_style) };
// getting the address of wglCreateContextAttribsARB and the pixel format
// that we will use
let (extra_functions, pixel_format) = {
// creating a dummy invisible window for GL initialization
let dummy_window = unsafe {
- let handle = winapi::CreateWindowExW(ex_style, class_name.as_ptr(),
+ let handle = user32::CreateWindowExW(ex_style, class_name.as_ptr(),
title.as_ptr() as winapi::LPCWSTR,
style | winapi::WS_CLIPSIBLINGS | winapi::WS_CLIPCHILDREN,
winapi::CW_USEDEFAULT, winapi::CW_USEDEFAULT,
rect.right - rect.left, rect.bottom - rect.top,
- ptr::null_mut(), ptr::null_mut(), winapi::GetModuleHandleW(ptr::null()),
+ ptr::null_mut(), ptr::null_mut(), kernel32::GetModuleHandleW(ptr::null()),
ptr::null_mut());
if handle.is_null() {
@@ -149,11 +152,11 @@ pub fn new_window(builder_dimensions: Option<(u32, u32)>, builder_title: String,
// getting the HDC of the dummy window
let dummy_hdc = {
- let hdc = unsafe { winapi::GetDC(dummy_window) };
+ let hdc = unsafe { user32::GetDC(dummy_window) };
if hdc.is_null() {
tx.send(Err(OsError(format!("GetDC function failed: {}",
os::error_string(os::errno() as usize)))));
- unsafe { winapi::DestroyWindow(dummy_window); }
+ unsafe { user32::DestroyWindow(dummy_window); }
return;
}
hdc
@@ -176,21 +179,21 @@ pub fn new_window(builder_dimensions: Option<(u32, u32)>, builder_title: String,
output.cAuxBuffers = 0;
output.iLayerType = winapi::PFD_MAIN_PLANE;
- let pf_index = unsafe { winapi::ChoosePixelFormat(dummy_hdc, &output) };
+ let pf_index = unsafe { gdi32::ChoosePixelFormat(dummy_hdc, &output) };
if pf_index == 0 {
tx.send(Err(OsError(format!("ChoosePixelFormat function failed: {}",
os::error_string(os::errno() as usize)))));
- unsafe { winapi::DestroyWindow(dummy_window); }
+ unsafe { user32::DestroyWindow(dummy_window); }
return;
}
- if unsafe { winapi::DescribePixelFormat(dummy_hdc, pf_index,
+ if unsafe { gdi32::DescribePixelFormat(dummy_hdc, pf_index,
mem::size_of::<winapi::PIXELFORMATDESCRIPTOR>() as winapi::UINT, &mut output) } == 0
{
tx.send(Err(OsError(format!("DescribePixelFormat function failed: {}",
os::error_string(os::errno() as usize)))));
- unsafe { winapi::DestroyWindow(dummy_window); }
+ unsafe { user32::DestroyWindow(dummy_window); }
return;
}
@@ -199,10 +202,10 @@ pub fn new_window(builder_dimensions: Option<(u32, u32)>, builder_title: String,
// calling SetPixelFormat
unsafe {
- if winapi::SetPixelFormat(dummy_hdc, 1, &pixel_format) == 0 {
+ if gdi32::SetPixelFormat(dummy_hdc, 1, &pixel_format) == 0 {
tx.send(Err(OsError(format!("SetPixelFormat function failed: {}",
os::error_string(os::errno() as usize)))));
- winapi::DestroyWindow(dummy_window);
+ user32::DestroyWindow(dummy_window);
return;
}
}
@@ -213,7 +216,7 @@ pub fn new_window(builder_dimensions: Option<(u32, u32)>, builder_title: String,
if ctxt.is_null() {
tx.send(Err(OsError(format!("wglCreateContext function failed: {}",
os::error_string(os::errno() as usize)))));
- unsafe { winapi::DestroyWindow(dummy_window); }
+ unsafe { user32::DestroyWindow(dummy_window); }
return;
}
ctxt
@@ -239,7 +242,7 @@ pub fn new_window(builder_dimensions: Option<(u32, u32)>, builder_title: String,
// destroying the context and the window
unsafe { gl::wgl::DeleteContext(dummy_context); }
- unsafe { winapi::DestroyWindow(dummy_window); }
+ unsafe { user32::DestroyWindow(dummy_window); }
// returning the address
(extra_functions, pixel_format)
@@ -259,13 +262,13 @@ pub fn new_window(builder_dimensions: Option<(u32, u32)>, builder_title: String,
style | winapi::WS_VISIBLE
};
- let handle = winapi::CreateWindowExW(ex_style, class_name.as_ptr(),
+ let handle = user32::CreateWindowExW(ex_style, class_name.as_ptr(),
title.as_ptr() as winapi::LPCWSTR,
style | winapi::WS_CLIPSIBLINGS | winapi::WS_CLIPCHILDREN,
if builder_monitor.is_some() { 0 } else { winapi::CW_USEDEFAULT },
if builder_monitor.is_some() { 0 } else { winapi::CW_USEDEFAULT },
width.unwrap_or(winapi::CW_USEDEFAULT), height.unwrap_or(winapi::CW_USEDEFAULT),
- ptr::null_mut(), ptr::null_mut(), winapi::GetModuleHandleW(ptr::null()),
+ ptr::null_mut(), ptr::null_mut(), kernel32::GetModuleHandleW(ptr::null()),
ptr::null_mut());
if handle.is_null() {
@@ -280,11 +283,11 @@ pub fn new_window(builder_dimensions: Option<(u32, u32)>, builder_title: String,
// getting the HDC of the window
let hdc = {
- let hdc = unsafe { winapi::GetDC(real_window) };
+ let hdc = unsafe { user32::GetDC(real_window) };
if hdc.is_null() {
tx.send(Err(OsError(format!("GetDC function failed: {}",
os::error_string(os::errno() as usize)))));
- unsafe { winapi::DestroyWindow(real_window); }
+ unsafe { user32::DestroyWindow(real_window); }
return;
}
hdc
@@ -292,10 +295,10 @@ pub fn new_window(builder_dimensions: Option<(u32, u32)>, builder_title: String,
// calling SetPixelFormat
unsafe {
- if winapi::SetPixelFormat(hdc, 1, &pixel_format) == 0 {
+ if gdi32::SetPixelFormat(hdc, 1, &pixel_format) == 0 {
tx.send(Err(OsError(format!("SetPixelFormat function failed: {}",
os::error_string(os::errno() as usize)))));
- winapi::DestroyWindow(real_window);
+ user32::DestroyWindow(real_window);
return;
}
}
@@ -340,7 +343,7 @@ pub fn new_window(builder_dimensions: Option<(u32, u32)>, builder_title: String,
if ctxt.is_null() {
tx.send(Err(OsError(format!("OpenGL context creation failed: {}",
os::error_string(os::errno() as usize)))));
- unsafe { winapi::DestroyWindow(real_window); }
+ unsafe { user32::DestroyWindow(real_window); }
return;
}
@@ -349,7 +352,7 @@ pub fn new_window(builder_dimensions: Option<(u32, u32)>, builder_title: String,
// calling SetForegroundWindow if fullscreen
if builder_monitor.is_some() {
- unsafe { winapi::SetForegroundWindow(real_window) };
+ unsafe { user32::SetForegroundWindow(real_window) };
}
// filling the WINDOW task-local storage
@@ -366,12 +369,12 @@ pub fn new_window(builder_dimensions: Option<(u32, u32)>, builder_title: String,
let gl_library = {
let name = "opengl32.dll".utf16_units().chain(Some(0).into_iter())
.collect::<Vec<u16>>().as_ptr();
- let lib = unsafe { winapi::LoadLibraryW(name) };
+ let lib = unsafe { kernel32::LoadLibraryW(name) };
if lib.is_null() {
tx.send(Err(OsError(format!("LoadLibrary function failed: {}",
os::error_string(os::errno() as usize)))));
unsafe { gl::wgl::DeleteContext(context); }
- unsafe { winapi::DestroyWindow(real_window); }
+ unsafe { user32::DestroyWindow(real_window); }
return;
}
lib
@@ -384,7 +387,7 @@ pub fn new_window(builder_dimensions: Option<(u32, u32)>, builder_title: String,
if unsafe { extra_functions.SwapIntervalEXT(1) } == 0 {
tx.send(Err(OsError(format!("wglSwapIntervalEXT failed"))));
unsafe { gl::wgl::DeleteContext(context); }
- unsafe { winapi::DestroyWindow(real_window); }
+ unsafe { user32::DestroyWindow(real_window); }
return;
}
@@ -412,12 +415,12 @@ pub fn new_window(builder_dimensions: Option<(u32, u32)>, builder_title: String,
loop {
let mut msg = unsafe { mem::uninitialized() };
- if unsafe { winapi::GetMessageW(&mut msg, ptr::null_mut(), 0, 0) } == 0 {
+ if unsafe { user32::GetMessageW(&mut msg, ptr::null_mut(), 0, 0) } == 0 {
break;
}
- unsafe { winapi::TranslateMessage(&msg) };
- unsafe { winapi::DispatchMessageW(&msg) }; // calls `callback` (see below)
+ unsafe { user32::TranslateMessage(&msg) };
+ unsafe { user32::DispatchMessageW(&msg) }; // calls `callback` (see below)
}
});
@@ -461,7 +464,7 @@ extern "system" fn callback(window: winapi::HWND, msg: winapi::UINT,
};
if win == &window {
- unsafe { winapi::PostQuitMessage(0); }
+ unsafe { user32::PostQuitMessage(0); }
}
});
@@ -598,7 +601,7 @@ extern "system" fn callback(window: winapi::HWND, msg: winapi::UINT,
},
_ => unsafe {
- winapi::DefWindowProcW(window, msg, wparam, lparam)
+ user32::DefWindowProcW(window, msg, wparam, lparam)
}
}
}
diff --git a/src/win32/mod.rs b/src/win32/mod.rs
index 984278a..8104fc8 100644
--- a/src/win32/mod.rs
+++ b/src/win32/mod.rs
@@ -11,6 +11,9 @@ use BuilderAttribs;
pub use self::monitor::{MonitorID, get_available_monitors, get_primary_monitor};
use winapi;
+use user32;
+use kernel32;
+use gdi32;
mod event;
mod gl;
@@ -112,7 +115,7 @@ impl Window {
/// Calls SetWindowText on the HWND.
pub fn set_title(&self, text: &str) {
unsafe {
- winapi::SetWindowTextW(self.window,
+ user32::SetWindowTextW(self.window,
text.utf16_units().chain(Some(0).into_iter())
.collect::<Vec<u16>>().as_ptr() as winapi::LPCWSTR);
}
@@ -120,13 +123,13 @@ impl Window {
pub fn show(&self) {
unsafe {
- winapi::ShowWindow(self.window, winapi::SW_SHOW);
+ user32::ShowWindow(self.window, winapi::SW_SHOW);
}
}
pub fn hide(&self) {
unsafe {
- winapi::ShowWindow(self.window, winapi::SW_HIDE);
+ user32::ShowWindow(self.window, winapi::SW_HIDE);
}
}
@@ -137,7 +140,7 @@ impl Window {
let mut placement: winapi::WINDOWPLACEMENT = unsafe { mem::zeroed() };
placement.length = mem::size_of::<winapi::WINDOWPLACEMENT>() as winapi::UINT;
- if unsafe { winapi::GetWindowPlacement(self.window, &mut placement) } == 0 {
+ if unsafe { user32::GetWindowPlacement(self.window, &mut placement) } == 0 {
return None
}
@@ -150,9 +153,9 @@ impl Window {
use libc;
unsafe {
- winapi::SetWindowPos(self.window, ptr::null_mut(), x as libc::c_int, y as libc::c_int,
+ user32::SetWindowPos(self.window, ptr::null_mut(), x as libc::c_int, y as libc::c_int,
0, 0, winapi::SWP_NOZORDER | winapi::SWP_NOSIZE);
- winapi::UpdateWindow(self.window);
+ user32::UpdateWindow(self.window);
}
}
@@ -161,7 +164,7 @@ impl Window {
use std::mem;
let mut rect: winapi::RECT = unsafe { mem::uninitialized() };
- if unsafe { winapi::GetClientRect(self.window, &mut rect) } == 0 {
+ if unsafe { user32::GetClientRect(self.window, &mut rect) } == 0 {
return None
}
@@ -176,7 +179,7 @@ impl Window {
use std::mem;
let mut rect: winapi::RECT = unsafe { mem::uninitialized() };
- if unsafe { winapi::GetWindowRect(self.window, &mut rect) } == 0 {
+ if unsafe { user32::GetWindowRect(self.window, &mut rect) } == 0 {
return None
}
@@ -191,9 +194,9 @@ impl Window {
use libc;
unsafe {
- winapi::SetWindowPos(self.window, ptr::null_mut(), 0, 0, x as libc::c_int,
+ user32::SetWindowPos(self.window, ptr::null_mut(), 0, 0, x as libc::c_int,
y as libc::c_int, winapi::SWP_NOZORDER | winapi::SWP_NOREPOSITION);
- winapi::UpdateWindow(self.window);
+ user32::UpdateWindow(self.window);
}
}
@@ -263,14 +266,14 @@ impl Window {
unsafe {
let p = gl::wgl::GetProcAddress(addr) as *const ();
if !p.is_null() { return p; }
- winapi::GetProcAddress(self.gl_library, addr) as *const ()
+ kernel32::GetProcAddress(self.gl_library, addr) as *const ()
}
}
/// See the docs in the crate root file.
pub fn swap_buffers(&self) {
unsafe {
- winapi::SwapBuffers(self.hdc);
+ gdi32::SwapBuffers(self.hdc);
}
}
@@ -299,9 +302,9 @@ impl Window {
impl Drop for Window {
fn drop(&mut self) {
use std::ptr;
- unsafe { winapi::PostMessageW(self.window, winapi::WM_DESTROY, 0, 0); }
+ unsafe { user32::PostMessageW(self.window, winapi::WM_DESTROY, 0, 0); }
unsafe { gl::wgl::MakeCurrent(ptr::null(), ptr::null()); }
unsafe { gl::wgl::DeleteContext(self.context as *const libc::c_void); }
- unsafe { winapi::DestroyWindow(self.window); }
+ unsafe { user32::DestroyWindow(self.window); }
}
}
diff --git a/src/win32/monitor.rs b/src/win32/monitor.rs
index 2078a52..bcf27e2 100644
--- a/src/win32/monitor.rs
+++ b/src/win32/monitor.rs
@@ -1,4 +1,5 @@
use winapi;
+use user32;
use std::collections::RingBuf;
@@ -38,7 +39,7 @@ pub fn get_available_monitors() -> RingBuf<MonitorID> {
let mut output: winapi::DISPLAY_DEVICEW = unsafe { mem::zeroed() };
output.cb = mem::size_of::<winapi::DISPLAY_DEVICEW>() as winapi::DWORD;
- if unsafe { winapi::EnumDisplayDevicesW(ptr::null(),
+ if unsafe { user32::EnumDisplayDevicesW(ptr::null(),
id as winapi::DWORD, &mut output, 0) } == 0
{
// the device doesn't exist, which means we have finished enumerating
@@ -65,7 +66,7 @@ pub fn get_available_monitors() -> RingBuf<MonitorID> {
let mut dev: winapi::DEVMODEW = mem::zeroed();
dev.dmSize = mem::size_of::<winapi::DEVMODEW>() as winapi::WORD;
- if winapi::EnumDisplaySettingsExW(output.DeviceName.as_ptr(), winapi::ENUM_CURRENT_SETTINGS,
+ if user32::EnumDisplaySettingsExW(output.DeviceName.as_ptr(), winapi::ENUM_CURRENT_SETTINGS,
&mut dev, 0) == 0
{
continue;