mirror of
https://github.com/italicsjenga/winit-sonoma-fix.git
synced 2025-01-12 05:31:31 +11:00
Extract WindowAttributes from the BuilderAttribs
This commit is contained in:
parent
c244f8c033
commit
48fe9b2644
|
@ -28,7 +28,7 @@ pub struct HeadlessContext {
|
||||||
|
|
||||||
impl HeadlessContext {
|
impl HeadlessContext {
|
||||||
pub fn new(builder: BuilderAttribs) -> Result<HeadlessContext, CreationError> {
|
pub fn new(builder: BuilderAttribs) -> Result<HeadlessContext, CreationError> {
|
||||||
let (width, height) = builder.dimensions.unwrap_or((1024, 768));
|
let (width, height) = builder.window.dimensions.unwrap_or((1024, 768));
|
||||||
let context = unsafe {
|
let context = unsafe {
|
||||||
let attributes = [
|
let attributes = [
|
||||||
NSOpenGLPFAAccelerated as u32,
|
NSOpenGLPFAAccelerated as u32,
|
||||||
|
|
|
@ -301,7 +301,7 @@ impl Window {
|
||||||
};
|
};
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
if builder.transparent {
|
if builder.window.transparent {
|
||||||
let clear_col = {
|
let clear_col = {
|
||||||
let cls = Class::get("NSColor").unwrap();
|
let cls = Class::get("NSColor").unwrap();
|
||||||
|
|
||||||
|
@ -317,7 +317,7 @@ impl Window {
|
||||||
}
|
}
|
||||||
|
|
||||||
app.activateIgnoringOtherApps_(YES);
|
app.activateIgnoringOtherApps_(YES);
|
||||||
if builder.visible {
|
if builder.window.visible {
|
||||||
window.makeKeyAndOrderFront_(nil);
|
window.makeKeyAndOrderFront_(nil);
|
||||||
} else {
|
} else {
|
||||||
window.makeKeyWindow();
|
window.makeKeyWindow();
|
||||||
|
@ -358,7 +358,7 @@ impl Window {
|
||||||
|
|
||||||
fn create_window(builder: &BuilderAttribs) -> Option<IdRef> {
|
fn create_window(builder: &BuilderAttribs) -> Option<IdRef> {
|
||||||
unsafe {
|
unsafe {
|
||||||
let screen = match builder.monitor {
|
let screen = match builder.window.monitor {
|
||||||
Some(ref monitor_id) => {
|
Some(ref monitor_id) => {
|
||||||
let native_id = match monitor_id.get_native_identifier() {
|
let native_id = match monitor_id.get_native_identifier() {
|
||||||
NativeMonitorId::Numeric(num) => num,
|
NativeMonitorId::Numeric(num) => num,
|
||||||
|
@ -390,12 +390,12 @@ impl Window {
|
||||||
let frame = match screen {
|
let frame = match screen {
|
||||||
Some(screen) => NSScreen::frame(screen),
|
Some(screen) => NSScreen::frame(screen),
|
||||||
None => {
|
None => {
|
||||||
let (width, height) = builder.dimensions.unwrap_or((800, 600));
|
let (width, height) = builder.window.dimensions.unwrap_or((800, 600));
|
||||||
NSRect::new(NSPoint::new(0., 0.), NSSize::new(width as f64, height as f64))
|
NSRect::new(NSPoint::new(0., 0.), NSSize::new(width as f64, height as f64))
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let masks = if screen.is_some() || !builder.decorations {
|
let masks = if screen.is_some() || !builder.window.decorations {
|
||||||
NSBorderlessWindowMask as NSUInteger |
|
NSBorderlessWindowMask as NSUInteger |
|
||||||
NSResizableWindowMask as NSUInteger
|
NSResizableWindowMask as NSUInteger
|
||||||
} else {
|
} else {
|
||||||
|
@ -412,7 +412,7 @@ impl Window {
|
||||||
NO,
|
NO,
|
||||||
));
|
));
|
||||||
window.non_nil().map(|window| {
|
window.non_nil().map(|window| {
|
||||||
let title = IdRef::new(NSString::alloc(nil).init_str(&builder.title));
|
let title = IdRef::new(NSString::alloc(nil).init_str(&builder.window.title));
|
||||||
window.setTitle_(*title);
|
window.setTitle_(*title);
|
||||||
window.setAcceptsMouseMovedEvents_(YES);
|
window.setAcceptsMouseMovedEvents_(YES);
|
||||||
if screen.is_some() {
|
if screen.is_some() {
|
||||||
|
|
|
@ -367,7 +367,7 @@ impl<'a> ContextPrototype<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn finish_pbuffer(self) -> Result<Context, CreationError> {
|
pub fn finish_pbuffer(self) -> Result<Context, CreationError> {
|
||||||
let dimensions = self.builder.dimensions.unwrap_or((800, 600));
|
let dimensions = self.builder.window.dimensions.unwrap_or((800, 600));
|
||||||
|
|
||||||
let attrs = &[
|
let attrs = &[
|
||||||
ffi::egl::WIDTH as libc::c_int, dimensions.0 as libc::c_int,
|
ffi::egl::WIDTH as libc::c_int, dimensions.0 as libc::c_int,
|
||||||
|
|
|
@ -219,7 +219,7 @@ impl Window {
|
||||||
|
|
||||||
let state = &mut *self.delegate_state;
|
let state = &mut *self.delegate_state;
|
||||||
|
|
||||||
if builder.multitouch {
|
if builder.window.multitouch {
|
||||||
let _: () = msg_send![state.view, setMultipleTouchEnabled:YES];
|
let _: () = msg_send![state.view, setMultipleTouchEnabled:YES];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -37,7 +37,7 @@ impl OsMesaContext {
|
||||||
return Err(OsMesaCreationError::NotSupported);
|
return Err(OsMesaCreationError::NotSupported);
|
||||||
}
|
}
|
||||||
|
|
||||||
let dimensions = builder.dimensions.unwrap();
|
let dimensions = builder.window.dimensions.unwrap();
|
||||||
|
|
||||||
match builder.opengl.robustness {
|
match builder.opengl.robustness {
|
||||||
Robustness::RobustNoResetNotification | Robustness::RobustLoseContextOnReset => {
|
Robustness::RobustNoResetNotification | Robustness::RobustLoseContextOnReset => {
|
||||||
|
|
|
@ -251,7 +251,7 @@ impl Window {
|
||||||
|
|
||||||
if !is_egl_available() { return Err(CreationError::NotSupported) }
|
if !is_egl_available() { return Err(CreationError::NotSupported) }
|
||||||
|
|
||||||
let (w, h) = builder.dimensions.unwrap_or((800, 600));
|
let (w, h) = builder.window.dimensions.unwrap_or((800, 600));
|
||||||
|
|
||||||
let surface = EGLSurface::new(
|
let surface = EGLSurface::new(
|
||||||
wayland_context.compositor.create_surface(),
|
wayland_context.compositor.create_surface(),
|
||||||
|
@ -259,12 +259,12 @@ impl Window {
|
||||||
h as i32
|
h as i32
|
||||||
);
|
);
|
||||||
|
|
||||||
let mut shell_window = if let Some(PlatformMonitorID::Wayland(ref monitor)) = builder.monitor {
|
let mut shell_window = if let Some(PlatformMonitorID::Wayland(ref monitor)) = builder.window.monitor {
|
||||||
let shell_surface = wayland_context.shell.get_shell_surface(surface);
|
let shell_surface = wayland_context.shell.get_shell_surface(surface);
|
||||||
shell_surface.set_fullscreen(ShellFullscreenMethod::Default, Some(&monitor.output));
|
shell_surface.set_fullscreen(ShellFullscreenMethod::Default, Some(&monitor.output));
|
||||||
ShellWindow::Plain(shell_surface)
|
ShellWindow::Plain(shell_surface)
|
||||||
} else {
|
} else {
|
||||||
if builder.decorations {
|
if builder.window.decorations {
|
||||||
ShellWindow::Decorated(match DecoratedSurface::new(
|
ShellWindow::Decorated(match DecoratedSurface::new(
|
||||||
surface,
|
surface,
|
||||||
w as i32,
|
w as i32,
|
||||||
|
|
|
@ -47,7 +47,7 @@ pub fn new_window(builder: BuilderAttribs<'static>, builder_sharelists: Option<R
|
||||||
|
|
||||||
// initializing variables to be sent to the task
|
// initializing variables to be sent to the task
|
||||||
|
|
||||||
let title = OsStr::new(&builder.title).encode_wide().chain(Some(0).into_iter())
|
let title = OsStr::new(&builder.window.title).encode_wide().chain(Some(0).into_iter())
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
let (tx, rx) = channel();
|
let (tx, rx) = channel();
|
||||||
|
@ -92,20 +92,20 @@ unsafe fn init(title: Vec<u16>, builder: BuilderAttribs<'static>,
|
||||||
|
|
||||||
// building a RECT object with coordinates
|
// building a RECT object with coordinates
|
||||||
let mut rect = winapi::RECT {
|
let mut rect = winapi::RECT {
|
||||||
left: 0, right: builder.dimensions.unwrap_or((1024, 768)).0 as winapi::LONG,
|
left: 0, right: builder.window.dimensions.unwrap_or((1024, 768)).0 as winapi::LONG,
|
||||||
top: 0, bottom: builder.dimensions.unwrap_or((1024, 768)).1 as winapi::LONG,
|
top: 0, bottom: builder.window.dimensions.unwrap_or((1024, 768)).1 as winapi::LONG,
|
||||||
};
|
};
|
||||||
|
|
||||||
// switching to fullscreen if necessary
|
// switching to fullscreen if necessary
|
||||||
// this means adjusting the window's position so that it overlaps the right monitor,
|
// this means adjusting the window's position so that it overlaps the right monitor,
|
||||||
// and change the monitor's resolution if necessary
|
// and change the monitor's resolution if necessary
|
||||||
if builder.monitor.is_some() {
|
if builder.window.monitor.is_some() {
|
||||||
let monitor = builder.monitor.as_ref().unwrap();
|
let monitor = builder.window.monitor.as_ref().unwrap();
|
||||||
try!(switch_to_fullscreen(&mut rect, monitor));
|
try!(switch_to_fullscreen(&mut rect, monitor));
|
||||||
}
|
}
|
||||||
|
|
||||||
// computing the style and extended style of the window
|
// computing the style and extended style of the window
|
||||||
let (ex_style, style) = if builder.monitor.is_some() || builder.decorations == false {
|
let (ex_style, style) = if builder.window.monitor.is_some() || builder.window.decorations == false {
|
||||||
(winapi::WS_EX_APPWINDOW, winapi::WS_POPUP | winapi::WS_CLIPSIBLINGS | winapi::WS_CLIPCHILDREN)
|
(winapi::WS_EX_APPWINDOW, winapi::WS_POPUP | winapi::WS_CLIPSIBLINGS | winapi::WS_CLIPCHILDREN)
|
||||||
} else {
|
} else {
|
||||||
(winapi::WS_EX_APPWINDOW | winapi::WS_EX_WINDOWEDGE,
|
(winapi::WS_EX_APPWINDOW | winapi::WS_EX_WINDOWEDGE,
|
||||||
|
@ -117,19 +117,19 @@ unsafe fn init(title: Vec<u16>, builder: BuilderAttribs<'static>,
|
||||||
|
|
||||||
// creating the real window this time, by using the functions in `extra_functions`
|
// creating the real window this time, by using the functions in `extra_functions`
|
||||||
let real_window = {
|
let real_window = {
|
||||||
let (width, height) = if builder.monitor.is_some() || builder.dimensions.is_some() {
|
let (width, height) = if builder.window.monitor.is_some() || builder.window.dimensions.is_some() {
|
||||||
(Some(rect.right - rect.left), Some(rect.bottom - rect.top))
|
(Some(rect.right - rect.left), Some(rect.bottom - rect.top))
|
||||||
} else {
|
} else {
|
||||||
(None, None)
|
(None, None)
|
||||||
};
|
};
|
||||||
|
|
||||||
let (x, y) = if builder.monitor.is_some() {
|
let (x, y) = if builder.window.monitor.is_some() {
|
||||||
(Some(rect.left), Some(rect.top))
|
(Some(rect.left), Some(rect.top))
|
||||||
} else {
|
} else {
|
||||||
(None, None)
|
(None, None)
|
||||||
};
|
};
|
||||||
|
|
||||||
let style = if !builder.visible || builder.headless {
|
let style = if !builder.window.visible || builder.headless {
|
||||||
style
|
style
|
||||||
} else {
|
} else {
|
||||||
style | winapi::WS_VISIBLE
|
style | winapi::WS_VISIBLE
|
||||||
|
@ -203,7 +203,7 @@ unsafe fn init(title: Vec<u16>, builder: BuilderAttribs<'static>,
|
||||||
};
|
};
|
||||||
|
|
||||||
// making the window transparent
|
// making the window transparent
|
||||||
if builder.transparent {
|
if builder.window.transparent {
|
||||||
let bb = winapi::DWM_BLURBEHIND {
|
let bb = winapi::DWM_BLURBEHIND {
|
||||||
dwFlags: 0x1, // FIXME: DWM_BB_ENABLE;
|
dwFlags: 0x1, // FIXME: DWM_BB_ENABLE;
|
||||||
fEnable: 1,
|
fEnable: 1,
|
||||||
|
@ -215,7 +215,7 @@ unsafe fn init(title: Vec<u16>, builder: BuilderAttribs<'static>,
|
||||||
}
|
}
|
||||||
|
|
||||||
// calling SetForegroundWindow if fullscreen
|
// calling SetForegroundWindow if fullscreen
|
||||||
if builder.monitor.is_some() {
|
if builder.window.monitor.is_some() {
|
||||||
user32::SetForegroundWindow(real_window.0);
|
user32::SetForegroundWindow(real_window.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -296,9 +296,9 @@ pub struct Window {
|
||||||
|
|
||||||
impl Window {
|
impl Window {
|
||||||
pub fn new(display: &Arc<XConnection>, builder: BuilderAttribs) -> Result<Window, CreationError> {
|
pub fn new(display: &Arc<XConnection>, builder: BuilderAttribs) -> Result<Window, CreationError> {
|
||||||
let dimensions = builder.dimensions.unwrap_or((800, 600));
|
let dimensions = builder.window.dimensions.unwrap_or((800, 600));
|
||||||
|
|
||||||
let screen_id = match builder.monitor {
|
let screen_id = match builder.window.monitor {
|
||||||
Some(PlatformMonitorID::X(MonitorID(_, monitor))) => monitor as i32,
|
Some(PlatformMonitorID::X(MonitorID(_, monitor))) => monitor as i32,
|
||||||
_ => unsafe { (display.xlib.XDefaultScreen)(display.display) },
|
_ => unsafe { (display.xlib.XDefaultScreen)(display.display) },
|
||||||
};
|
};
|
||||||
|
@ -316,7 +316,7 @@ impl Window {
|
||||||
// FIXME: `XF86VidModeModeInfo` is missing its `hskew` field. Therefore we point to
|
// FIXME: `XF86VidModeModeInfo` is missing its `hskew` field. Therefore we point to
|
||||||
// `vsyncstart` instead of `vdisplay` as a temporary hack.
|
// `vsyncstart` instead of `vdisplay` as a temporary hack.
|
||||||
|
|
||||||
let mode_to_switch_to = if builder.monitor.is_some() {
|
let mode_to_switch_to = if builder.window.monitor.is_some() {
|
||||||
let matching_mode = (0 .. mode_num).map(|i| {
|
let matching_mode = (0 .. mode_num).map(|i| {
|
||||||
let m: ffi::XF86VidModeModeInfo = ptr::read(*modes.offset(i as isize) as *const _); m
|
let m: ffi::XF86VidModeModeInfo = ptr::read(*modes.offset(i as isize) as *const _); m
|
||||||
}).find(|m| m.hdisplay == dimensions.0 as u16 && m.vsyncstart == dimensions.1 as u16);
|
}).find(|m| m.hdisplay == dimensions.0 as u16 && m.vsyncstart == dimensions.1 as u16);
|
||||||
|
@ -415,7 +415,7 @@ impl Window {
|
||||||
ffi::KeyReleaseMask | ffi::ButtonPressMask |
|
ffi::KeyReleaseMask | ffi::ButtonPressMask |
|
||||||
ffi::ButtonReleaseMask | ffi::KeymapStateMask;
|
ffi::ButtonReleaseMask | ffi::KeymapStateMask;
|
||||||
swa.border_pixel = 0;
|
swa.border_pixel = 0;
|
||||||
if builder.transparent {
|
if builder.window.transparent {
|
||||||
swa.background_pixel = 0;
|
swa.background_pixel = 0;
|
||||||
}
|
}
|
||||||
swa.override_redirect = 0;
|
swa.override_redirect = 0;
|
||||||
|
@ -424,7 +424,7 @@ impl Window {
|
||||||
|
|
||||||
let mut window_attributes = ffi::CWBorderPixel | ffi::CWColormap | ffi::CWEventMask;
|
let mut window_attributes = ffi::CWBorderPixel | ffi::CWColormap | ffi::CWEventMask;
|
||||||
|
|
||||||
if builder.transparent {
|
if builder.window.transparent {
|
||||||
window_attributes |= ffi::CWBackPixel;
|
window_attributes |= ffi::CWBackPixel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -448,7 +448,7 @@ impl Window {
|
||||||
};
|
};
|
||||||
|
|
||||||
// set visibility
|
// set visibility
|
||||||
if builder.visible {
|
if builder.window.visible {
|
||||||
unsafe {
|
unsafe {
|
||||||
(display.xlib.XMapRaised)(display.display, window);
|
(display.xlib.XMapRaised)(display.display, window);
|
||||||
(display.xlib.XFlush)(display.display);
|
(display.xlib.XFlush)(display.display);
|
||||||
|
@ -461,7 +461,7 @@ impl Window {
|
||||||
(display.xlib.XInternAtom)(display.display, delete_window, 0)
|
(display.xlib.XInternAtom)(display.display, delete_window, 0)
|
||||||
);
|
);
|
||||||
(display.xlib.XSetWMProtocols)(display.display, window, &mut wm_delete_window, 1);
|
(display.xlib.XSetWMProtocols)(display.display, window, &mut wm_delete_window, 1);
|
||||||
with_c_str(&*builder.title, |title| {;
|
with_c_str(&*builder.window.title, |title| {;
|
||||||
(display.xlib.XStoreName)(display.display, window, title);
|
(display.xlib.XStoreName)(display.display, window, title);
|
||||||
});
|
});
|
||||||
(display.xlib.XFlush)(display.display);
|
(display.xlib.XFlush)(display.display);
|
||||||
|
@ -509,7 +509,7 @@ impl Window {
|
||||||
|
|
||||||
// Set ICCCM WM_CLASS property based on initial window title
|
// Set ICCCM WM_CLASS property based on initial window title
|
||||||
unsafe {
|
unsafe {
|
||||||
with_c_str(&*builder.title, |c_name| {
|
with_c_str(&*builder.window.title, |c_name| {
|
||||||
let hint = (display.xlib.XAllocClassHint)();
|
let hint = (display.xlib.XAllocClassHint)();
|
||||||
(*hint).res_name = c_name as *mut libc::c_char;
|
(*hint).res_name = c_name as *mut libc::c_char;
|
||||||
(*hint).res_class = c_name as *mut libc::c_char;
|
(*hint).res_class = c_name as *mut libc::c_char;
|
||||||
|
@ -518,7 +518,7 @@ impl Window {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
let is_fullscreen = builder.monitor.is_some();
|
let is_fullscreen = builder.window.monitor.is_some();
|
||||||
|
|
||||||
// finish creating the OpenGL context
|
// finish creating the OpenGL context
|
||||||
let context = match context {
|
let context = match context {
|
||||||
|
|
|
@ -6,6 +6,7 @@ use GlRequest;
|
||||||
use GlContext;
|
use GlContext;
|
||||||
use PixelFormat;
|
use PixelFormat;
|
||||||
use Robustness;
|
use Robustness;
|
||||||
|
use WindowAttributes;
|
||||||
|
|
||||||
use gl_common;
|
use gl_common;
|
||||||
use libc;
|
use libc;
|
||||||
|
@ -23,7 +24,10 @@ impl HeadlessRendererBuilder {
|
||||||
HeadlessRendererBuilder {
|
HeadlessRendererBuilder {
|
||||||
attribs: BuilderAttribs {
|
attribs: BuilderAttribs {
|
||||||
headless: true,
|
headless: true,
|
||||||
dimensions: Some((width, height)),
|
window: WindowAttributes {
|
||||||
|
dimensions: Some((width, height)),
|
||||||
|
.. Default::default()
|
||||||
|
},
|
||||||
.. BuilderAttribs::new()
|
.. BuilderAttribs::new()
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
77
src/lib.rs
77
src/lib.rs
|
@ -371,10 +371,6 @@ pub struct BuilderAttribs<'a> {
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
headless: bool,
|
headless: bool,
|
||||||
strict: bool,
|
strict: bool,
|
||||||
dimensions: Option<(u32, u32)>,
|
|
||||||
title: String,
|
|
||||||
monitor: Option<platform::MonitorID>,
|
|
||||||
visible: bool,
|
|
||||||
multisampling: Option<u16>,
|
multisampling: Option<u16>,
|
||||||
depth_bits: Option<u8>,
|
depth_bits: Option<u8>,
|
||||||
stencil_bits: Option<u8>,
|
stencil_bits: Option<u8>,
|
||||||
|
@ -382,9 +378,7 @@ pub struct BuilderAttribs<'a> {
|
||||||
alpha_bits: Option<u8>,
|
alpha_bits: Option<u8>,
|
||||||
stereoscopy: bool,
|
stereoscopy: bool,
|
||||||
srgb: Option<bool>,
|
srgb: Option<bool>,
|
||||||
transparent: bool,
|
window: WindowAttributes,
|
||||||
decorations: bool,
|
|
||||||
multitouch: bool,
|
|
||||||
opengl: GlAttributes<&'a platform::Window>,
|
opengl: GlAttributes<&'a platform::Window>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -393,10 +387,6 @@ impl BuilderAttribs<'static> {
|
||||||
BuilderAttribs {
|
BuilderAttribs {
|
||||||
headless: false,
|
headless: false,
|
||||||
strict: false,
|
strict: false,
|
||||||
dimensions: None,
|
|
||||||
title: "glutin window".to_string(),
|
|
||||||
monitor: None,
|
|
||||||
visible: true,
|
|
||||||
multisampling: None,
|
multisampling: None,
|
||||||
depth_bits: None,
|
depth_bits: None,
|
||||||
stencil_bits: None,
|
stencil_bits: None,
|
||||||
|
@ -404,9 +394,7 @@ impl BuilderAttribs<'static> {
|
||||||
alpha_bits: None,
|
alpha_bits: None,
|
||||||
stereoscopy: false,
|
stereoscopy: false,
|
||||||
srgb: None,
|
srgb: None,
|
||||||
transparent: false,
|
window: Default::default(),
|
||||||
decorations: true,
|
|
||||||
multitouch: false,
|
|
||||||
opengl: Default::default(),
|
opengl: Default::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -420,10 +408,6 @@ impl<'a> BuilderAttribs<'a> {
|
||||||
let new_attribs = BuilderAttribs {
|
let new_attribs = BuilderAttribs {
|
||||||
headless: self.headless,
|
headless: self.headless,
|
||||||
strict: self.strict,
|
strict: self.strict,
|
||||||
dimensions: self.dimensions,
|
|
||||||
title: self.title,
|
|
||||||
monitor: self.monitor,
|
|
||||||
visible: self.visible,
|
|
||||||
multisampling: self.multisampling,
|
multisampling: self.multisampling,
|
||||||
depth_bits: self.depth_bits,
|
depth_bits: self.depth_bits,
|
||||||
stencil_bits: self.stencil_bits,
|
stencil_bits: self.stencil_bits,
|
||||||
|
@ -431,9 +415,7 @@ impl<'a> BuilderAttribs<'a> {
|
||||||
alpha_bits: self.alpha_bits,
|
alpha_bits: self.alpha_bits,
|
||||||
stereoscopy: self.stereoscopy,
|
stereoscopy: self.stereoscopy,
|
||||||
srgb: self.srgb,
|
srgb: self.srgb,
|
||||||
transparent: self.transparent,
|
window: self.window,
|
||||||
decorations: self.decorations,
|
|
||||||
multitouch: self.multitouch,
|
|
||||||
opengl: GlAttributes {
|
opengl: GlAttributes {
|
||||||
sharing: None,
|
sharing: None,
|
||||||
version: self.opengl.version,
|
version: self.opengl.version,
|
||||||
|
@ -547,6 +529,59 @@ impl<'a> BuilderAttribs<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Attributes to use when creating a window.
|
||||||
|
#[derive(Clone)]
|
||||||
|
pub struct WindowAttributes {
|
||||||
|
/// The dimensions of the window. If this is `None`, some platform-specific dimensions will be
|
||||||
|
/// used.
|
||||||
|
///
|
||||||
|
/// The default is `None`.
|
||||||
|
pub dimensions: Option<(u32, u32)>,
|
||||||
|
|
||||||
|
/// If `Some`, the window will be in fullscreen mode with the given monitor.
|
||||||
|
///
|
||||||
|
/// The default is `None`.
|
||||||
|
pub monitor: Option<platform::MonitorID>,
|
||||||
|
|
||||||
|
/// The title of the window in the title bar.
|
||||||
|
///
|
||||||
|
/// The default is `"glutin window"`.
|
||||||
|
pub title: String,
|
||||||
|
|
||||||
|
/// Whether the window should be immediately visible upon creation.
|
||||||
|
///
|
||||||
|
/// The default is `true`.
|
||||||
|
pub visible: bool,
|
||||||
|
|
||||||
|
/// Whether the the window should be transparent. If this is true, writing colors
|
||||||
|
/// with alpha values different than `1.0` will produce a transparent window.
|
||||||
|
///
|
||||||
|
/// The default is `false`.
|
||||||
|
pub transparent: bool,
|
||||||
|
|
||||||
|
/// Whether the window should have borders and bars.
|
||||||
|
///
|
||||||
|
/// The default is `true`.
|
||||||
|
pub decorations: bool,
|
||||||
|
|
||||||
|
/// ??? TODO: document me
|
||||||
|
pub multitouch: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for WindowAttributes {
|
||||||
|
fn default() -> WindowAttributes {
|
||||||
|
WindowAttributes {
|
||||||
|
dimensions: None,
|
||||||
|
monitor: None,
|
||||||
|
title: "glutin window".to_owned(),
|
||||||
|
visible: true,
|
||||||
|
transparent: false,
|
||||||
|
decorations: true,
|
||||||
|
multitouch: false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Attributes to use when creating an OpenGL context.
|
/// Attributes to use when creating an OpenGL context.
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct GlAttributes<S> {
|
pub struct GlAttributes<S> {
|
||||||
|
|
|
@ -86,7 +86,7 @@ pub enum HeadlessContext {
|
||||||
|
|
||||||
impl HeadlessContext {
|
impl HeadlessContext {
|
||||||
pub fn new(mut builder: BuilderAttribs) -> Result<HeadlessContext, CreationError> {
|
pub fn new(mut builder: BuilderAttribs) -> Result<HeadlessContext, CreationError> {
|
||||||
builder.visible = false;
|
builder.window.visible = false;
|
||||||
|
|
||||||
// if EGL is available, we try using EGL first
|
// if EGL is available, we try using EGL first
|
||||||
// if EGL returns an error, we try the hidden window method
|
// if EGL returns an error, we try the hidden window method
|
||||||
|
|
|
@ -37,13 +37,13 @@ impl<'a> WindowBuilder<'a> {
|
||||||
///
|
///
|
||||||
/// Width and height are in pixels.
|
/// Width and height are in pixels.
|
||||||
pub fn with_dimensions(mut self, width: u32, height: u32) -> WindowBuilder<'a> {
|
pub fn with_dimensions(mut self, width: u32, height: u32) -> WindowBuilder<'a> {
|
||||||
self.attribs.dimensions = Some((width, height));
|
self.attribs.window.dimensions = Some((width, height));
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Requests a specific title for the window.
|
/// Requests a specific title for the window.
|
||||||
pub fn with_title(mut self, title: String) -> WindowBuilder<'a> {
|
pub fn with_title(mut self, title: String) -> WindowBuilder<'a> {
|
||||||
self.attribs.title = title;
|
self.attribs.window.title = title;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,7 +52,7 @@ impl<'a> WindowBuilder<'a> {
|
||||||
/// If you don't specify dimensions for the window, it will match the monitor's.
|
/// If you don't specify dimensions for the window, it will match the monitor's.
|
||||||
pub fn with_fullscreen(mut self, monitor: MonitorID) -> WindowBuilder<'a> {
|
pub fn with_fullscreen(mut self, monitor: MonitorID) -> WindowBuilder<'a> {
|
||||||
let MonitorID(monitor) = monitor;
|
let MonitorID(monitor) = monitor;
|
||||||
self.attribs.monitor = Some(monitor);
|
self.attribs.window.monitor = Some(monitor);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,7 +99,7 @@ impl<'a> WindowBuilder<'a> {
|
||||||
|
|
||||||
/// Sets whether the window will be initially hidden or visible.
|
/// Sets whether the window will be initially hidden or visible.
|
||||||
pub fn with_visibility(mut self, visible: bool) -> WindowBuilder<'a> {
|
pub fn with_visibility(mut self, visible: bool) -> WindowBuilder<'a> {
|
||||||
self.attribs.visible = visible;
|
self.attribs.window.visible = visible;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -147,19 +147,19 @@ impl<'a> WindowBuilder<'a> {
|
||||||
|
|
||||||
/// Sets whether the background of the window should be transparent.
|
/// Sets whether the background of the window should be transparent.
|
||||||
pub fn with_transparency(mut self, transparent: bool) -> WindowBuilder<'a> {
|
pub fn with_transparency(mut self, transparent: bool) -> WindowBuilder<'a> {
|
||||||
self.attribs.transparent = transparent;
|
self.attribs.window.transparent = transparent;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets whether the window should have a border, a title bar, etc.
|
/// Sets whether the window should have a border, a title bar, etc.
|
||||||
pub fn with_decorations(mut self, decorations: bool) -> WindowBuilder<'a> {
|
pub fn with_decorations(mut self, decorations: bool) -> WindowBuilder<'a> {
|
||||||
self.attribs.decorations = decorations;
|
self.attribs.window.decorations = decorations;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Enables multitouch
|
/// Enables multitouch
|
||||||
pub fn with_multitouch(mut self) -> WindowBuilder<'a> {
|
pub fn with_multitouch(mut self) -> WindowBuilder<'a> {
|
||||||
self.attribs.multitouch = true;
|
self.attribs.window.multitouch = true;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -169,13 +169,13 @@ impl<'a> WindowBuilder<'a> {
|
||||||
/// out of memory, etc.
|
/// out of memory, etc.
|
||||||
pub fn build(mut self) -> Result<Window, CreationError> {
|
pub fn build(mut self) -> Result<Window, CreationError> {
|
||||||
// resizing the window to the dimensions of the monitor when fullscreen
|
// resizing the window to the dimensions of the monitor when fullscreen
|
||||||
if self.attribs.dimensions.is_none() && self.attribs.monitor.is_some() {
|
if self.attribs.window.dimensions.is_none() && self.attribs.window.monitor.is_some() {
|
||||||
self.attribs.dimensions = Some(self.attribs.monitor.as_ref().unwrap().get_dimensions())
|
self.attribs.window.dimensions = Some(self.attribs.window.monitor.as_ref().unwrap().get_dimensions())
|
||||||
}
|
}
|
||||||
|
|
||||||
// default dimensions
|
// default dimensions
|
||||||
if self.attribs.dimensions.is_none() {
|
if self.attribs.window.dimensions.is_none() {
|
||||||
self.attribs.dimensions = Some((1024, 768));
|
self.attribs.window.dimensions = Some((1024, 768));
|
||||||
}
|
}
|
||||||
|
|
||||||
// building
|
// building
|
||||||
|
|
Loading…
Reference in a new issue