Rework MonitorId::get_native_identifier (#267)

* Rework MonitorId::get_native_identifier

* Try fix compilation

* Returns the monitor ID on wayland as well

* Try fix compilation

* Fix iOS compilation
This commit is contained in:
tomaka 2017-08-30 08:49:18 +02:00 committed by GitHub
parent f7a8bcddb8
commit 7dc6fcdedc
16 changed files with 67 additions and 69 deletions

View file

@ -16,7 +16,6 @@ use std::collections::VecDeque;
use CursorState;
use WindowAttributes;
use FullScreenState;
use native_monitor::NativeMonitorId;
gen_api_transition!();
@ -48,11 +47,6 @@ impl MonitorId {
Some("Primary".to_string())
}
#[inline]
pub fn get_native_identifier(&self) -> NativeMonitorId {
NativeMonitorId::Unavailable
}
#[inline]
pub fn get_dimensions(&self) -> (u32, u32) {
unimplemented!()

View file

@ -70,7 +70,6 @@ use libc::c_int;
use objc::runtime::{Class, Object, Sel, BOOL, YES };
use objc::declare::{ ClassDecl };
use native_monitor::NativeMonitorId;
use { CreationError, CursorState, MouseCursor, WindowAttributes, FullScreenState };
use WindowEvent as Event;
use events::{ Touch, TouchPhase };
@ -153,11 +152,6 @@ impl MonitorId {
Some("Primary".to_string())
}
#[inline]
pub fn get_native_identifier(&self) -> NativeMonitorId {
NativeMonitorId::Unavailable
}
#[inline]
pub fn get_dimensions(&self) -> (u32, u32) {
unimplemented!()

View file

@ -142,7 +142,7 @@ impl MonitorId {
}
#[inline]
pub fn get_native_identifier(&self) -> ::native_monitor::NativeMonitorId {
pub fn get_native_identifier(&self) -> u32 {
match self {
&MonitorId::X(ref m) => m.get_native_identifier(),
&MonitorId::Wayland(ref m) => m.get_native_identifier(),

View file

@ -372,8 +372,8 @@ impl MonitorId {
}
#[inline]
pub fn get_native_identifier(&self) -> ::native_monitor::NativeMonitorId {
::native_monitor::NativeMonitorId::Unavailable
pub fn get_native_identifier(&self) -> u32 {
self.id
}
pub fn get_dimensions(&self) -> (u32, u32) {

View file

@ -56,7 +56,7 @@ impl Window {
*(decorated.handler()) = Some(DecoratedHandler::new());
// set fullscreen if necessary
if let FullScreenState::Exclusive(RootMonitorId(PlatformMonitorId::Wayland(ref monitor_id))) = attributes.fullscreen {
if let FullScreenState::Exclusive(RootMonitorId { inner: PlatformMonitorId::Wayland(ref monitor_id) }) = attributes.fullscreen {
ctxt.with_output(monitor_id.clone(), |output| {
decorated.set_fullscreen(Some(output))
});

View file

@ -2,7 +2,6 @@ use std::collections::VecDeque;
use std::sync::Arc;
use super::XConnection;
use native_monitor::NativeMonitorId;
#[derive(Clone)]
pub struct MonitorId(pub Arc<XConnection>, pub u32);
@ -30,8 +29,8 @@ impl MonitorId {
}
#[inline]
pub fn get_native_identifier(&self) -> NativeMonitorId {
NativeMonitorId::Numeric(self.1)
pub fn get_native_identifier(&self) -> u32 {
self.1
}
pub fn get_dimensions(&self) -> (u32, u32) {

View file

@ -215,7 +215,7 @@ impl Window {
let screen_id = match pl_attribs.screen_id {
Some(id) => id,
None => match window_attrs.fullscreen {
FullScreenState::Exclusive(RootMonitorId(PlatformMonitorId::X(X11MonitorId(_, monitor)))) => monitor as i32,
FullScreenState::Exclusive(RootMonitorId { inner: PlatformMonitorId::X(X11MonitorId(_, monitor)) }) => monitor as i32,
_ => unsafe { (display.xlib.XDefaultScreen)(display.display) },
}
};
@ -458,7 +458,7 @@ impl Window {
self.x.switch_from_fullscreen_mode();
Window::set_netwm(&self.x.display, self.x.window, self.x.root, "_NET_WM_STATE_FULLSCREEN", true);
},
FullScreenState::Exclusive(RootMonitorId(PlatformMonitorId::X(X11MonitorId(_, monitor)))) => {
FullScreenState::Exclusive(RootMonitorId { inner: PlatformMonitorId::X(X11MonitorId(_, monitor)) }) => {
if let Some(dimensions) = self.get_inner_size() {
self.x.switch_to_fullscreen_mode(monitor as i32, dimensions.0 as u16, dimensions.1 as u16);
Window::set_netwm(&self.x.display, self.x.window, self.x.root, "_NET_WM_STATE_FULLSCREEN", true);

View file

@ -1,6 +1,5 @@
use core_graphics::display;
use std::collections::VecDeque;
use native_monitor::NativeMonitorId;
#[derive(Clone)]
pub struct MonitorId(u32);
@ -33,9 +32,8 @@ impl MonitorId {
}
#[inline]
pub fn get_native_identifier(&self) -> NativeMonitorId {
let MonitorId(display_id) = *self;
NativeMonitorId::Numeric(display_id)
pub fn get_native_identifier(&self) -> u32 {
self.0
}
pub fn get_dimensions(&self) -> (u32, u32) {

View file

@ -4,7 +4,6 @@ use libc;
use WindowAttributes;
use FullScreenState;
use native_monitor::NativeMonitorId;
use os::macos::ActivationPolicy;
use os::macos::WindowExt;
@ -386,10 +385,7 @@ impl Window {
unsafe {
let screen = match attrs.fullscreen {
FullScreenState::Exclusive(ref monitor_id) => {
let native_id = match monitor_id.get_native_identifier() {
NativeMonitorId::Numeric(num) => num,
_ => panic!("OS X monitors should always have a numeric native ID")
};
let native_id = monitor_id.inner.get_native_identifier();
let matching_screen = {
let screens = appkit::NSScreen::screens(nil);
let count: NSUInteger = msg_send![screens, count];

View file

@ -4,8 +4,6 @@ use user32;
use std::collections::VecDeque;
use std::mem;
use native_monitor::NativeMonitorId;
/// Win32 implementation of the main `MonitorId` object.
#[derive(Clone)]
pub struct MonitorId {
@ -158,8 +156,8 @@ impl MonitorId {
/// See the docs of the crate root file.
#[inline]
pub fn get_native_identifier(&self) -> NativeMonitorId {
NativeMonitorId::Name(self.monitor_name.clone())
pub fn get_native_identifier(&self) -> String {
self.monitor_name.clone()
}
/// See the docs if the crate root file.

View file

@ -329,8 +329,8 @@ unsafe fn init(window: WindowAttributes, pl_attribs: PlatformSpecificWindowBuild
// 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
let fullscreen = if let FullScreenState::Exclusive(RootMonitorId(ref monitor)) = window.fullscreen {
try!(switch_to_fullscreen(&mut rect, monitor));
let fullscreen = if let FullScreenState::Exclusive(RootMonitorId { ref inner }) = window.fullscreen {
try!(switch_to_fullscreen(&mut rect, inner));
true
} else {
false