From f5daac771e818dd49571efdcf1b75df4e6f0df7a Mon Sep 17 00:00:00 2001 From: Andrey Lesnikov Date: Wed, 19 Oct 2016 19:11:02 +0300 Subject: [PATCH] Prepared winit for glutin porting --- src/api/cocoa/mod.rs | 9 +-------- src/api/x11/window.rs | 10 ++++++++++ src/os/macos.rs | 0 src/os/unix.rs | 23 ++++++++++++++++++++++- 4 files changed, 33 insertions(+), 9 deletions(-) mode change 100644 => 100755 src/api/cocoa/mod.rs mode change 100644 => 100755 src/os/macos.rs diff --git a/src/api/cocoa/mod.rs b/src/api/cocoa/mod.rs old mode 100644 new mode 100755 index f75adb2d..0a8a0e42 --- a/src/api/cocoa/mod.rs +++ b/src/api/cocoa/mod.rs @@ -11,22 +11,15 @@ use os::macos::ActivationPolicy; use objc::runtime::{Class, Object, Sel, BOOL, YES, NO}; use objc::declare::ClassDecl; -use cgl::{CGLEnable, kCGLCECrashOnRemovedFunctions, CGLSetParameter, kCGLCPSurfaceOpacity}; - use cocoa::base::{id, nil}; use cocoa::foundation::{NSAutoreleasePool, NSDate, NSDefaultRunLoopMode, NSPoint, NSRect, NSSize, NSString, NSUInteger}; -use cocoa::appkit::{self, NSApplication, NSEvent, NSOpenGLContext, NSOpenGLPixelFormat, NSView, NSWindow}; - -use core_foundation::base::TCFType; -use core_foundation::string::CFString; -use core_foundation::bundle::{CFBundleGetBundleWithIdentifier, CFBundleGetFunctionPointerForName}; +use cocoa::appkit::{self, NSApplication, NSEvent, NSView, NSWindow}; use core_graphics::display::{CGAssociateMouseAndMouseCursorPosition, CGMainDisplayID, CGDisplayPixelsHigh, CGWarpMouseCursorPosition}; use std::ffi::CStr; use std::collections::VecDeque; -use std::str::FromStr; use std::str::from_utf8; use std::sync::Mutex; use std::ops::Deref; diff --git a/src/api/x11/window.rs b/src/api/x11/window.rs index b2013d23..cdc2d62b 100644 --- a/src/api/x11/window.rs +++ b/src/api/x11/window.rs @@ -717,6 +717,16 @@ impl Window { self.x.display.display as *mut libc::c_void } + #[inline] + pub fn get_xlib_screen_id(&self) -> *mut libc::c_void { + self.x.screen_id as *mut libc::c_void + } + + #[inline] + pub fn get_xlib_xconnection(&self) -> Arc { + self.x.display.clone() + } + #[inline] pub fn platform_display(&self) -> *mut libc::c_void { self.x.display.display as *mut libc::c_void diff --git a/src/os/macos.rs b/src/os/macos.rs old mode 100644 new mode 100755 diff --git a/src/os/unix.rs b/src/os/unix.rs index e6229714..d325f135 100644 --- a/src/os/unix.rs +++ b/src/os/unix.rs @@ -1,13 +1,17 @@ #![cfg(any(target_os = "linux", target_os = "dragonfly", target_os = "freebsd", target_os = "openbsd"))] +use std::sync::Arc; use libc; use Window; use platform::Window as LinuxWindow; use WindowBuilder; +use api::x11::XConnection; use wayland_client::protocol::wl_display::WlDisplay; use wayland_client::protocol::wl_surface::WlSurface; +pub use api::x11; + /// 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. @@ -23,8 +27,11 @@ pub trait WindowExt { /// /// The pointer will become invalid when the glutin `Window` is destroyed. fn get_xlib_display(&self) -> Option<*mut libc::c_void>; + + fn get_xlib_screen_id(&self) -> Option<*mut libc::c_void>; + + fn get_xlib_xconnection(&self) -> Option>; - /// /// This function returns the underlying `xcb_connection_t` of an xlib `Display`. /// /// Returns `None` if the window doesn't use xlib (if it uses wayland for example). @@ -82,6 +89,20 @@ impl WindowExt for Window { } } + fn get_xlib_screen_id(&self) -> Option<*mut libc::c_void> { + match self.window { + LinuxWindow::X(ref w) => Some(w.get_xlib_screen_id()), + _ => None + } + } + + fn get_xlib_xconnection(&self) -> Option> { + match self.window { + LinuxWindow::X(ref w) => Some(w.get_xlib_xconnection()), + _ => None + } + } + fn get_xcb_connection(&self) -> Option<*mut libc::c_void> { match self.window { LinuxWindow::X(ref w) => Some(w.get_xcb_connection()),