Remove api_transition macro (#279)

* Remove api_transition macro

* Rename Window2 to Window

* Try fix X11 code
This commit is contained in:
tomaka 2017-09-06 17:32:24 +02:00 committed by GitHub
parent 0ada6c15ea
commit 342d5d8587
13 changed files with 97 additions and 247 deletions

View file

@ -38,8 +38,8 @@ lazy_static!(
};
);
pub enum Window2 {
X(x11::Window2),
pub enum Window {
X(x11::Window),
Wayland(wayland::Window)
}
@ -87,7 +87,7 @@ impl MonitorId {
}
}
impl Window2 {
impl Window {
#[inline]
pub fn new(events_loop: &EventsLoop,
window: &::WindowAttributes,
@ -96,11 +96,11 @@ impl Window2 {
{
match *events_loop {
EventsLoop::Wayland(ref evlp) => {
wayland::Window::new(evlp, window).map(Window2::Wayland)
wayland::Window::new(evlp, window).map(Window::Wayland)
},
EventsLoop::X(ref el) => {
x11::Window2::new(el, window, pl_attribs).map(Window2::X)
x11::Window::new(el, window, pl_attribs).map(Window::X)
},
}
}
@ -108,104 +108,104 @@ impl Window2 {
#[inline]
pub fn id(&self) -> WindowId {
match self {
&Window2::X(ref w) => WindowId::X(w.id()),
&Window2::Wayland(ref w) => WindowId::Wayland(w.id())
&Window::X(ref w) => WindowId::X(w.id()),
&Window::Wayland(ref w) => WindowId::Wayland(w.id())
}
}
#[inline]
pub fn set_title(&self, title: &str) {
match self {
&Window2::X(ref w) => w.set_title(title),
&Window2::Wayland(ref w) => w.set_title(title)
&Window::X(ref w) => w.set_title(title),
&Window::Wayland(ref w) => w.set_title(title)
}
}
#[inline]
pub fn show(&self) {
match self {
&Window2::X(ref w) => w.show(),
&Window2::Wayland(ref w) => w.show()
&Window::X(ref w) => w.show(),
&Window::Wayland(ref w) => w.show()
}
}
#[inline]
pub fn hide(&self) {
match self {
&Window2::X(ref w) => w.hide(),
&Window2::Wayland(ref w) => w.hide()
&Window::X(ref w) => w.hide(),
&Window::Wayland(ref w) => w.hide()
}
}
#[inline]
pub fn get_position(&self) -> Option<(i32, i32)> {
match self {
&Window2::X(ref w) => w.get_position(),
&Window2::Wayland(ref w) => w.get_position()
&Window::X(ref w) => w.get_position(),
&Window::Wayland(ref w) => w.get_position()
}
}
#[inline]
pub fn set_position(&self, x: i32, y: i32) {
match self {
&Window2::X(ref w) => w.set_position(x, y),
&Window2::Wayland(ref w) => w.set_position(x, y)
&Window::X(ref w) => w.set_position(x, y),
&Window::Wayland(ref w) => w.set_position(x, y)
}
}
#[inline]
pub fn get_inner_size(&self) -> Option<(u32, u32)> {
match self {
&Window2::X(ref w) => w.get_inner_size(),
&Window2::Wayland(ref w) => w.get_inner_size()
&Window::X(ref w) => w.get_inner_size(),
&Window::Wayland(ref w) => w.get_inner_size()
}
}
#[inline]
pub fn get_outer_size(&self) -> Option<(u32, u32)> {
match self {
&Window2::X(ref w) => w.get_outer_size(),
&Window2::Wayland(ref w) => w.get_outer_size()
&Window::X(ref w) => w.get_outer_size(),
&Window::Wayland(ref w) => w.get_outer_size()
}
}
#[inline]
pub fn set_inner_size(&self, x: u32, y: u32) {
match self {
&Window2::X(ref w) => w.set_inner_size(x, y),
&Window2::Wayland(ref w) => w.set_inner_size(x, y)
&Window::X(ref w) => w.set_inner_size(x, y),
&Window::Wayland(ref w) => w.set_inner_size(x, y)
}
}
#[inline]
pub fn set_cursor(&self, cursor: MouseCursor) {
match self {
&Window2::X(ref w) => w.set_cursor(cursor),
&Window2::Wayland(ref w) => w.set_cursor(cursor)
&Window::X(ref w) => w.set_cursor(cursor),
&Window::Wayland(ref w) => w.set_cursor(cursor)
}
}
#[inline]
pub fn set_cursor_state(&self, state: CursorState) -> Result<(), String> {
match self {
&Window2::X(ref w) => w.set_cursor_state(state),
&Window2::Wayland(ref w) => w.set_cursor_state(state)
&Window::X(ref w) => w.set_cursor_state(state),
&Window::Wayland(ref w) => w.set_cursor_state(state)
}
}
#[inline]
pub fn hidpi_factor(&self) -> f32 {
match self {
&Window2::X(ref w) => w.hidpi_factor(),
&Window2::Wayland(ref w) => w.hidpi_factor()
&Window::X(ref w) => w.hidpi_factor(),
&Window::Wayland(ref w) => w.hidpi_factor()
}
}
#[inline]
pub fn set_cursor_position(&self, x: i32, y: i32) -> Result<(), ()> {
match self {
&Window2::X(ref w) => w.set_cursor_position(x, y),
&Window2::Wayland(ref w) => w.set_cursor_position(x, y)
&Window::X(ref w) => w.set_cursor_position(x, y),
&Window::Wayland(ref w) => w.set_cursor_position(x, y)
}
}
@ -213,8 +213,8 @@ impl Window2 {
pub fn platform_display(&self) -> *mut libc::c_void {
use wayland_client::Proxy;
match self {
&Window2::X(ref w) => w.platform_display(),
&Window2::Wayland(ref w) => w.get_display().ptr() as *mut _
&Window::X(ref w) => w.platform_display(),
&Window::Wayland(ref w) => w.get_display().ptr() as *mut _
}
}
@ -222,24 +222,24 @@ impl Window2 {
pub fn platform_window(&self) -> *mut libc::c_void {
use wayland_client::Proxy;
match self {
&Window2::X(ref w) => w.platform_window(),
&Window2::Wayland(ref w) => w.get_surface().ptr() as *mut _
&Window::X(ref w) => w.platform_window(),
&Window::Wayland(ref w) => w.get_surface().ptr() as *mut _
}
}
#[inline]
pub fn set_maximized(&self, maximized: bool) {
match self {
&Window2::X(ref w) => w.set_maximized(maximized),
&Window2::Wayland(ref _w) => {},
&Window::X(ref w) => w.set_maximized(maximized),
&Window::Wayland(ref _w) => {},
}
}
#[inline]
pub fn set_fullscreen(&self, state: FullScreenState) {
match self {
&Window2::X(ref w) => w.set_fullscreen(state),
&Window2::Wayland(ref _w) => {},
&Window::X(ref w) => w.set_fullscreen(state),
&Window::Wayland(ref _w) => {},
}
}
}

View file

@ -1,7 +1,7 @@
#![cfg(any(target_os = "linux", target_os = "dragonfly", target_os = "freebsd", target_os = "openbsd"))]
pub use self::monitor::{MonitorId, get_available_monitors, get_primary_monitor};
pub use self::window::{Window, XWindow};
pub use self::window::{Window2, XWindow};
pub use self::xdisplay::{XConnection, XNotSupported, XError};
pub mod ffi;
@ -655,16 +655,16 @@ pub struct WindowId(ffi::Window);
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct DeviceId(c_int);
pub struct Window2 {
pub window: Arc<Window>,
pub struct Window {
pub window: Arc<Window2>,
display: Weak<XConnection>,
windows: Weak<Mutex<HashMap<WindowId, WindowData>>>,
}
impl ::std::ops::Deref for Window2 {
type Target = Window;
impl ::std::ops::Deref for Window {
type Target = Window2;
#[inline]
fn deref(&self) -> &Window {
fn deref(&self) -> &Window2 {
&*self.window
}
}
@ -674,13 +674,13 @@ lazy_static! { // TODO: use a static mutex when that's possible, and put me
static ref GLOBAL_XOPENIM_LOCK: Mutex<()> = Mutex::new(());
}
impl Window2 {
impl Window {
pub fn new(x_events_loop: &EventsLoop,
window: &::WindowAttributes,
pl_attribs: &PlatformSpecificWindowBuilderAttributes)
-> Result<Self, CreationError>
{
let win = ::std::sync::Arc::new(try!(Window::new(&x_events_loop, window, pl_attribs)));
let win = ::std::sync::Arc::new(try!(Window2::new(&x_events_loop, window, pl_attribs)));
// creating IM
let im = unsafe {
@ -716,7 +716,7 @@ impl Window2 {
cursor_pos: None,
});
Ok(Window2 {
Ok(Window {
window: win,
windows: Arc::downgrade(&x_events_loop.windows),
display: Arc::downgrade(&x_events_loop.display),
@ -749,7 +749,7 @@ impl Window2 {
}
}
impl Drop for Window2 {
impl Drop for Window {
fn drop(&mut self) {
if let (Some(windows), Some(display)) = (self.windows.upgrade(), self.display.upgrade()) {
let mut windows = windows.lock().unwrap();

View file

@ -40,8 +40,8 @@ pub struct XWindow {
unsafe impl Send for XWindow {}
unsafe impl Sync for XWindow {}
unsafe impl Send for Window {}
unsafe impl Sync for Window {}
unsafe impl Send for Window2 {}
unsafe impl Sync for Window2 {}
impl XWindow {
fn switch_to_fullscreen_mode(&self, monitor: i32, width: u16, height: u16) {
@ -141,15 +141,15 @@ impl Drop for XWindow {
}
}
pub struct Window {
pub struct Window2 {
pub x: Arc<XWindow>,
cursor_state: Mutex<CursorState>,
}
impl Window {
impl Window2 {
pub fn new(ctx: &EventsLoop, window_attrs: &WindowAttributes,
pl_attribs: &PlatformSpecificWindowBuilderAttributes)
-> Result<Window, CreationError>
-> Result<Window2, CreationError>
{
let display = &ctx.display;
let dimensions = {
@ -306,7 +306,7 @@ impl Window {
};
}
let window = Window {
let window = Window2 {
x: Arc::new(XWindow {
display: display.clone(),
window: window,
@ -402,16 +402,16 @@ impl Window {
match state {
FullScreenState::None => {
self.x.switch_from_fullscreen_mode();
Window::set_netwm(&self.x.display, self.x.window, self.x.root, "_NET_WM_STATE_FULLSCREEN", false);
Window2::set_netwm(&self.x.display, self.x.window, self.x.root, "_NET_WM_STATE_FULLSCREEN", false);
},
FullScreenState::Windowed => {
self.x.switch_from_fullscreen_mode();
Window::set_netwm(&self.x.display, self.x.window, self.x.root, "_NET_WM_STATE_FULLSCREEN", true);
Window2::set_netwm(&self.x.display, self.x.window, self.x.root, "_NET_WM_STATE_FULLSCREEN", true);
},
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);
Window2::set_netwm(&self.x.display, self.x.window, self.x.root, "_NET_WM_STATE_FULLSCREEN", true);
} else {
eprintln!("[winit] Couldn't get window dimensions to go fullscreen");
}
@ -421,8 +421,8 @@ impl Window {
}
pub fn set_maximized(&self, maximized: bool) {
Window::set_netwm(&self.x.display, self.x.window, self.x.root, "_NET_WM_STATE_MAXIMIZED_HORZ", maximized);
Window::set_netwm(&self.x.display, self.x.window, self.x.root, "_NET_WM_STATE_MAXIMIZED_VERT", maximized);
Window2::set_netwm(&self.x.display, self.x.window, self.x.root, "_NET_WM_STATE_MAXIMIZED_HORZ", maximized);
Window2::set_netwm(&self.x.display, self.x.window, self.x.root, "_NET_WM_STATE_MAXIMIZED_VERT", maximized);
}
pub fn set_title(&self, title: &str) {