mirror of
https://github.com/italicsjenga/winit-sonoma-fix.git
synced 2024-12-25 14:51:30 +11:00
Add an os
module containing platform-specific traits
This commit is contained in:
parent
9fccb2e06e
commit
8c6a27d426
|
@ -658,11 +658,21 @@ impl Window {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn get_xlib_display(&self) -> *mut libc::c_void {
|
||||||
|
self.x.display.display as *mut libc::c_void
|
||||||
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn platform_display(&self) -> *mut libc::c_void {
|
pub fn platform_display(&self) -> *mut libc::c_void {
|
||||||
self.x.display.display as *mut libc::c_void
|
self.x.display.display as *mut libc::c_void
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn get_xlib_window(&self) -> *mut libc::c_void {
|
||||||
|
self.x.window as *mut libc::c_void
|
||||||
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn platform_window(&self) -> *mut libc::c_void {
|
pub fn platform_window(&self) -> *mut libc::c_void {
|
||||||
self.x.window as *mut libc::c_void
|
self.x.window as *mut libc::c_void
|
||||||
|
|
31
src/lib.rs
31
src/lib.rs
|
@ -61,7 +61,7 @@ extern crate x11_dl;
|
||||||
pub use events::*;
|
pub use events::*;
|
||||||
pub use headless::{HeadlessRendererBuilder, HeadlessContext};
|
pub use headless::{HeadlessRendererBuilder, HeadlessContext};
|
||||||
#[cfg(feature = "window")]
|
#[cfg(feature = "window")]
|
||||||
pub use window::{WindowBuilder, Window, WindowProxy, PollEventsIterator, WaitEventsIterator};
|
pub use window::{WindowBuilder, WindowProxy, PollEventsIterator, WaitEventsIterator};
|
||||||
#[cfg(feature = "window")]
|
#[cfg(feature = "window")]
|
||||||
pub use window::{AvailableMonitorsIter, MonitorId, get_available_monitors, get_primary_monitor};
|
pub use window::{AvailableMonitorsIter, MonitorId, get_available_monitors, get_primary_monitor};
|
||||||
#[cfg(feature = "window")]
|
#[cfg(feature = "window")]
|
||||||
|
@ -78,6 +78,35 @@ mod headless;
|
||||||
#[cfg(feature = "window")]
|
#[cfg(feature = "window")]
|
||||||
mod window;
|
mod window;
|
||||||
|
|
||||||
|
pub mod os;
|
||||||
|
|
||||||
|
/// Represents an OpenGL context and the Window or environment around it.
|
||||||
|
///
|
||||||
|
/// # Example
|
||||||
|
///
|
||||||
|
/// ```ignore
|
||||||
|
/// let window = Window::new().unwrap();
|
||||||
|
///
|
||||||
|
/// unsafe { window.make_current() };
|
||||||
|
///
|
||||||
|
/// loop {
|
||||||
|
/// for event in window.poll_events() {
|
||||||
|
/// match(event) {
|
||||||
|
/// // process events here
|
||||||
|
/// _ => ()
|
||||||
|
/// }
|
||||||
|
/// }
|
||||||
|
///
|
||||||
|
/// // draw everything here
|
||||||
|
///
|
||||||
|
/// window.swap_buffers();
|
||||||
|
/// std::old_io::timer::sleep(17);
|
||||||
|
/// }
|
||||||
|
/// ```
|
||||||
|
pub struct Window {
|
||||||
|
window: platform::Window,
|
||||||
|
}
|
||||||
|
|
||||||
/// Trait that describes objects that have access to an OpenGL context.
|
/// Trait that describes objects that have access to an OpenGL context.
|
||||||
pub trait GlContext {
|
pub trait GlContext {
|
||||||
/// Sets the context as the current context.
|
/// Sets the context as the current context.
|
||||||
|
|
9
src/os/mod.rs
Normal file
9
src/os/mod.rs
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
//! Contains traits with platform-specific methods in them.
|
||||||
|
//!
|
||||||
|
//! Contains the follow modules:
|
||||||
|
//!
|
||||||
|
//! - `unix`
|
||||||
|
//! - `windows`
|
||||||
|
//!
|
||||||
|
pub mod unix;
|
||||||
|
pub mod windows;
|
40
src/os/unix.rs
Normal file
40
src/os/unix.rs
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
#![cfg(any(target_os = "linux", target_os = "dragonfly", target_os = "freebsd"))]
|
||||||
|
|
||||||
|
use libc;
|
||||||
|
use Window;
|
||||||
|
use platform::Window as LinuxWindow;
|
||||||
|
|
||||||
|
/// Additional methods on `Window` that are specific to unix.
|
||||||
|
pub trait WindowExt {
|
||||||
|
/// Returns a pointer to the `Window` object of xlib that is used by this window.
|
||||||
|
///
|
||||||
|
/// Returns `None` if the window doesn't use xlib (if it uses wayland for example).
|
||||||
|
///
|
||||||
|
/// The pointer will become invalid when the glutin `Window` is destroyed.
|
||||||
|
fn get_xlib_window(&self) -> Option<*mut libc::c_void>;
|
||||||
|
|
||||||
|
/// Returns a pointer to the `Display` object of xlib that is used by this window.
|
||||||
|
///
|
||||||
|
/// Returns `None` if the window doesn't use xlib (if it uses wayland for example).
|
||||||
|
///
|
||||||
|
/// The pointer will become invalid when the glutin `Window` is destroyed.
|
||||||
|
fn get_xlib_display(&self) -> Option<*mut libc::c_void>;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl WindowExt for Window {
|
||||||
|
#[inline]
|
||||||
|
fn get_xlib_window(&self) -> Option<*mut libc::c_void> {
|
||||||
|
match self.window {
|
||||||
|
LinuxWindow::X(ref w) => Some(w.get_xlib_window()),
|
||||||
|
_ => None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn get_xlib_display(&self) -> Option<*mut libc::c_void> {
|
||||||
|
match self.window {
|
||||||
|
LinuxWindow::X(ref w) => Some(w.get_xlib_window()),
|
||||||
|
_ => None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
21
src/os/windows.rs
Normal file
21
src/os/windows.rs
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
#![cfg(target_os = "windows")]
|
||||||
|
|
||||||
|
use libc;
|
||||||
|
use Window;
|
||||||
|
|
||||||
|
/// Additional methods on `Window` that are specific to unix.
|
||||||
|
pub trait WindowExt {
|
||||||
|
/// Returns a pointer to the `Window` object of xlib that is used by this window.
|
||||||
|
///
|
||||||
|
/// Returns `None` if the window doesn't use xlib (if it uses wayland for example).
|
||||||
|
///
|
||||||
|
/// The pointer will become invalid when the glutin `Window` is destroyed.
|
||||||
|
fn get_hwnd(&self) -> *mut libc::c_void;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl WindowExt for Window {
|
||||||
|
#[inline]
|
||||||
|
fn get_hwnd(&self) -> *mut libc::c_void {
|
||||||
|
self.window.platform_window()
|
||||||
|
}
|
||||||
|
}
|
|
@ -14,6 +14,7 @@ use MouseCursor;
|
||||||
use PixelFormat;
|
use PixelFormat;
|
||||||
use PixelFormatRequirements;
|
use PixelFormatRequirements;
|
||||||
use Robustness;
|
use Robustness;
|
||||||
|
use Window;
|
||||||
use WindowAttributes;
|
use WindowAttributes;
|
||||||
use native_monitor::NativeMonitorId;
|
use native_monitor::NativeMonitorId;
|
||||||
|
|
||||||
|
@ -224,32 +225,6 @@ impl<'a> WindowBuilder<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Represents an OpenGL context and the Window or environment around it.
|
|
||||||
///
|
|
||||||
/// # Example
|
|
||||||
///
|
|
||||||
/// ```ignore
|
|
||||||
/// let window = Window::new().unwrap();
|
|
||||||
///
|
|
||||||
/// unsafe { window.make_current() };
|
|
||||||
///
|
|
||||||
/// loop {
|
|
||||||
/// for event in window.poll_events() {
|
|
||||||
/// match(event) {
|
|
||||||
/// // process events here
|
|
||||||
/// _ => ()
|
|
||||||
/// }
|
|
||||||
/// }
|
|
||||||
///
|
|
||||||
/// // draw everything here
|
|
||||||
///
|
|
||||||
/// window.swap_buffers();
|
|
||||||
/// std::old_io::timer::sleep(17);
|
|
||||||
/// }
|
|
||||||
/// ```
|
|
||||||
pub struct Window {
|
|
||||||
window: platform::Window,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Default for Window {
|
impl Default for Window {
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -439,7 +414,7 @@ impl Window {
|
||||||
self.window.swap_buffers()
|
self.window.swap_buffers()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Gets the native platform specific display for this window.
|
/// DEPRECATED. Gets the native platform specific display for this window.
|
||||||
/// This is typically only required when integrating with
|
/// This is typically only required when integrating with
|
||||||
/// other libraries that need this information.
|
/// other libraries that need this information.
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -447,7 +422,7 @@ impl Window {
|
||||||
self.window.platform_display()
|
self.window.platform_display()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Gets the native platform specific window handle. This is
|
/// DEPRECATED. Gets the native platform specific window handle. This is
|
||||||
/// typically only required when integrating with other libraries
|
/// typically only required when integrating with other libraries
|
||||||
/// that need this information.
|
/// that need this information.
|
||||||
#[inline]
|
#[inline]
|
||||||
|
|
Loading…
Reference in a new issue