aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/lib.rs27
-rw-r--r--src/win32/init.rs37
-rw-r--r--src/win32/mod.rs14
-rw-r--r--src/x11/window/mod.rs10
4 files changed, 54 insertions, 34 deletions
diff --git a/src/lib.rs b/src/lib.rs
index adc6e07..49c7474 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -217,6 +217,33 @@ impl BuilderAttribs<'static> {
}
}
+impl<'a> BuilderAttribs<'a> {
+ fn extract_non_static(mut self) -> (BuilderAttribs<'static>, Option<&'a winimpl::Window>) {
+ let sharing = self.sharing.take();
+
+ let new_attribs = BuilderAttribs {
+ headless: self.headless,
+ strict: self.strict,
+ sharing: None,
+ dimensions: self.dimensions,
+ title: self.title,
+ monitor: self.monitor,
+ gl_version: self.gl_version,
+ gl_debug: self.gl_debug,
+ vsync: self.vsync,
+ visible: self.visible,
+ multisampling: self.multisampling,
+ depth_bits: self.depth_bits,
+ stencil_bits: self.stencil_bits,
+ color_bits: self.color_bits,
+ alpha_bits: self.alpha_bits,
+ stereoscopy: self.stereoscopy,
+ };
+
+ (new_attribs, sharing)
+ }
+}
+
#[cfg(feature = "window")]
impl<'a> WindowBuilder<'a> {
/// Initializes a new `WindowBuilder` with default values.
diff --git a/src/win32/init.rs b/src/win32/init.rs
index 754d251..9e0e3a7 100644
--- a/src/win32/init.rs
+++ b/src/win32/init.rs
@@ -2,6 +2,7 @@ use std::sync::atomic::AtomicBool;
use std::ptr;
use super::event;
use super::Window;
+use BuilderAttribs;
use {CreationError, Event};
use CreationError::OsError;
@@ -27,18 +28,14 @@ thread_local!(static WINDOW: Rc<RefCell<Option<(winapi::HWND, Sender<Event>)>>>
pub struct ContextHack(pub winapi::HGLRC);
unsafe impl Send for ContextHack {}
-pub fn new_window(builder_dimensions: Option<(u32, u32)>, builder_title: String,
- builder_monitor: Option<super::MonitorID>,
- builder_gl_version: Option<(u32, u32)>, builder_debug: bool,
- builder_vsync: bool, builder_hidden: bool,
- builder_sharelists: Option<ContextHack>, builder_multisampling: Option<u16>)
+pub fn new_window(builder: BuilderAttribs<'static>, builder_sharelists: Option<ContextHack>)
-> Result<Window, CreationError>
{
use std::mem;
use std::os;
// initializing variables to be sent to the task
- let title = builder_title.as_slice().utf16_units()
+ let title = builder.title.as_slice().utf16_units()
.chain(Some(0).into_iter()).collect::<Vec<u16>>(); // title to utf16
//let hints = hints.clone();
let (tx, rx) = channel();
@@ -80,15 +77,15 @@ pub fn new_window(builder_dimensions: Option<(u32, u32)>, builder_title: String,
// building a RECT object with coordinates
let mut rect = winapi::RECT {
- left: 0, right: builder_dimensions.unwrap_or((1024, 768)).0 as winapi::LONG,
- top: 0, bottom: builder_dimensions.unwrap_or((1024, 768)).1 as winapi::LONG,
+ left: 0, right: builder.dimensions.unwrap_or((1024, 768)).0 as winapi::LONG,
+ top: 0, bottom: builder.dimensions.unwrap_or((1024, 768)).1 as winapi::LONG,
};
// switching to fullscreen if necessary
// this means adjusting the window's position so that it overlaps the right monitor,
// and change the monitor's resolution if necessary
- if builder_monitor.is_some() {
- let monitor = builder_monitor.as_ref().unwrap();
+ if builder.monitor.is_some() {
+ let monitor = builder.monitor.as_ref().unwrap();
// adjusting the rect
{
@@ -117,7 +114,7 @@ pub fn new_window(builder_dimensions: Option<(u32, u32)>, builder_title: String,
}
// computing the style and extended style of the window
- let (ex_style, style) = if builder_monitor.is_some() {
+ let (ex_style, style) = if builder.monitor.is_some() {
(winapi::WS_EX_APPWINDOW, winapi::WS_POPUP | winapi::WS_CLIPSIBLINGS | winapi::WS_CLIPCHILDREN)
} else {
(winapi::WS_EX_APPWINDOW | winapi::WS_EX_WINDOWEDGE,
@@ -250,13 +247,13 @@ pub fn new_window(builder_dimensions: Option<(u32, u32)>, builder_title: String,
// creating the real window this time
let real_window = unsafe {
- let (width, height) = if builder_monitor.is_some() || builder_dimensions.is_some() {
+ let (width, height) = if builder.monitor.is_some() || builder.dimensions.is_some() {
(Some(rect.right - rect.left), Some(rect.bottom - rect.top))
} else {
(None, None)
};
- let style = if builder_hidden {
+ let style = if !builder.visible || builder.headless {
style
} else {
style | winapi::WS_VISIBLE
@@ -265,8 +262,8 @@ pub fn new_window(builder_dimensions: Option<(u32, u32)>, builder_title: String,
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 },
+ 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(), kernel32::GetModuleHandleW(ptr::null()),
ptr::null_mut());
@@ -309,15 +306,15 @@ pub fn new_window(builder_dimensions: Option<(u32, u32)>, builder_title: String,
let mut attributes = Vec::new();
- if builder_gl_version.is_some() {
- let version = builder_gl_version.as_ref().unwrap();
+ if builder.gl_version.is_some() {
+ let version = builder.gl_version.as_ref().unwrap();
attributes.push(gl::wgl_extra::CONTEXT_MAJOR_VERSION_ARB as libc::c_int);
attributes.push(version.0 as libc::c_int);
attributes.push(gl::wgl_extra::CONTEXT_MINOR_VERSION_ARB as libc::c_int);
attributes.push(version.1 as libc::c_int);
}
- if builder_debug {
+ if builder.gl_debug {
attributes.push(gl::wgl_extra::CONTEXT_FLAGS_ARB as libc::c_int);
attributes.push(gl::wgl_extra::CONTEXT_DEBUG_BIT_ARB as libc::c_int);
}
@@ -351,7 +348,7 @@ pub fn new_window(builder_dimensions: Option<(u32, u32)>, builder_title: String,
};
// calling SetForegroundWindow if fullscreen
- if builder_monitor.is_some() {
+ if builder.monitor.is_some() {
unsafe { user32::SetForegroundWindow(real_window) };
}
@@ -381,7 +378,7 @@ pub fn new_window(builder_dimensions: Option<(u32, u32)>, builder_title: String,
};
// handling vsync
- if builder_vsync {
+ if builder.vsync {
if extra_functions.SwapIntervalEXT.is_loaded() {
unsafe { gl::wgl::MakeCurrent(hdc as *const libc::c_void, context) };
if unsafe { extra_functions.SwapIntervalEXT(1) } == 0 {
diff --git a/src/win32/mod.rs b/src/win32/mod.rs
index ea7e0ff..c502e3d 100644
--- a/src/win32/mod.rs
+++ b/src/win32/mod.rs
@@ -26,10 +26,8 @@ pub struct HeadlessContext(Window);
impl HeadlessContext {
/// See the docs in the crate root file.
pub fn new(builder: BuilderAttribs) -> Result<HeadlessContext, CreationError> {
- let BuilderAttribs { dimensions, gl_version, gl_debug, .. } = builder;
- init::new_window(dimensions, "".to_string(), None, gl_version, gl_debug, false, true,
- None, None)
- .map(|w| HeadlessContext(w))
+ let (builder, _) = builder.extract_non_static();
+ init::new_window(builder, None).map(|w| HeadlessContext(w))
}
/// See the docs in the crate root file.
@@ -86,11 +84,9 @@ unsafe impl Sync for Window {}
impl Window {
/// See the docs in the crate root file.
pub fn new(builder: BuilderAttribs) -> Result<Window, CreationError> {
- let BuilderAttribs { dimensions, title, monitor, gl_version,
- gl_debug, vsync, visible, sharing, multisampling, .. } = builder;
- init::new_window(dimensions, title, monitor, gl_version, gl_debug, vsync,
- !visible, sharing.map(|w| init::ContextHack(w.context)),
- multisampling)
+ let (builder, sharing) = builder.extract_non_static();
+ let sharing = sharing.map(|w| init::ContextHack(w.context));
+ init::new_window(builder, sharing)
}
}
diff --git a/src/x11/window/mod.rs b/src/x11/window/mod.rs
index 9ab10e6..b1cd6d4 100644
--- a/src/x11/window/mod.rs
+++ b/src/x11/window/mod.rs
@@ -620,7 +620,7 @@ impl Window {
}
}
- fn get_geometry(&self) -> Option<(i32, i32, u32, u32)> {
+ fn get_geometry(&self) -> Option<(i32, i32, u32, u32, u32)> {
unsafe {
use std::mem;
@@ -639,12 +639,12 @@ impl Window {
return None;
}
- Some((x as i32, y as i32, width as u32, height as u32))
+ Some((x as i32, y as i32, width as u32, height as u32, border as u32))
}
}
pub fn get_position(&self) -> Option<(i32, i32)> {
- self.get_geometry().map(|(x, y, _, _)| (x, y))
+ self.get_geometry().map(|(x, y, _, _, _)| (x, y))
}
pub fn set_position(&self, x: i32, y: i32) {
@@ -652,11 +652,11 @@ impl Window {
}
pub fn get_inner_size(&self) -> Option<(u32, u32)> {
- self.get_geometry().map(|(_, _, w, h)| (w, h))
+ self.get_geometry().map(|(_, _, w, h, _)| (w, h))
}
pub fn get_outer_size(&self) -> Option<(u32, u32)> {
- unimplemented!()
+ self.get_geometry().map(|(_, _, w, h, b)| (w + b, h + b)) // TODO: is this really outside?
}
pub fn set_inner_size(&self, _x: u32, _y: u32) {