From f627664b335e43e32f3c71aed690f192401b4aab Mon Sep 17 00:00:00 2001 From: Osspial Date: Thu, 16 May 2019 01:13:31 -0400 Subject: [PATCH 01/22] First name consistency pass. More to come! --- examples/cursor_grab.rs | 4 +- examples/min_max_size.rs | 4 +- examples/multithreaded.rs | 18 ++-- examples/resizable.rs | 2 +- src/monitor.rs | 4 +- src/platform_impl/android/mod.rs | 14 +-- src/platform_impl/emscripten/mod.rs | 36 +++---- src/platform_impl/ios/mod.rs | 16 +-- src/platform_impl/linux/mod.rs | 44 ++++----- src/platform_impl/linux/wayland/event_loop.rs | 4 +- src/platform_impl/linux/wayland/window.rs | 18 ++-- src/platform_impl/linux/x11/monitor.rs | 4 +- src/platform_impl/linux/x11/util/randr.rs | 2 +- src/platform_impl/linux/x11/window.rs | 98 +++++++++---------- src/platform_impl/macos/monitor.rs | 4 +- src/platform_impl/macos/window.rs | 40 ++++---- src/platform_impl/windows/monitor.rs | 2 +- src/platform_impl/windows/window.rs | 46 ++++----- src/platform_impl/windows/window_state.rs | 4 +- src/window.rs | 77 ++++++--------- 20 files changed, 211 insertions(+), 230 deletions(-) diff --git a/examples/cursor_grab.rs b/examples/cursor_grab.rs index 741d0d74aa..8e7b1f7e3b 100644 --- a/examples/cursor_grab.rs +++ b/examples/cursor_grab.rs @@ -29,8 +29,8 @@ fn main() { use winit::event::VirtualKeyCode::*; match key { Escape => *control_flow = ControlFlow::Exit, - G => window.grab_cursor(!modifiers.shift).unwrap(), - H => window.hide_cursor(!modifiers.shift), + G => window.set_cursor_grab(!modifiers.shift).unwrap(), + H => window.set_cursor_visible(modifiers.shift), _ => (), } } diff --git a/examples/min_max_size.rs b/examples/min_max_size.rs index dea437635c..37c0fe7f94 100644 --- a/examples/min_max_size.rs +++ b/examples/min_max_size.rs @@ -12,8 +12,8 @@ fn main() { .build(&event_loop) .unwrap(); - window.set_min_dimensions(Some(LogicalSize::new(400.0, 200.0))); - window.set_max_dimensions(Some(LogicalSize::new(800.0, 400.0))); + window.set_min_inner_size(Some(LogicalSize::new(400.0, 200.0))); + window.set_max_inner_size(Some(LogicalSize::new(800.0, 400.0))); event_loop.run(move |event, _, control_flow| { println!("{:?}", event); diff --git a/examples/multithreaded.rs b/examples/multithreaded.rs index f5907ca3ef..776ab42a4d 100644 --- a/examples/multithreaded.rs +++ b/examples/multithreaded.rs @@ -17,7 +17,7 @@ fn main() { let mut window_senders = HashMap::with_capacity(WINDOW_COUNT); for _ in 0..WINDOW_COUNT { let window = WindowBuilder::new() - .with_dimensions(WINDOW_SIZE.into()) + .with_inner_size(WINDOW_SIZE.into()) .build(&event_loop) .unwrap(); let (tx, rx) = mpsc::channel(); @@ -45,22 +45,22 @@ fn main() { true => Some(window.get_current_monitor()), false => None, }), - G => window.grab_cursor(state).unwrap(), - H => window.hide_cursor(state), + G => window.set_cursor_grab(state).unwrap(), + H => window.set_cursor_visible(!state), I => { println!("Info:"); - println!("-> position : {:?}", window.get_position()); + println!("-> outer_position : {:?}", window.get_outer_position()); println!("-> inner_position : {:?}", window.get_inner_position()); println!("-> outer_size : {:?}", window.get_outer_size()); println!("-> inner_size : {:?}", window.get_inner_size()); }, - L => window.set_min_dimensions(match state { + L => window.set_min_inner_size(match state { true => Some(WINDOW_SIZE.into()), false => None, }), M => window.set_maximized(state), - P => window.set_position({ - let mut position = window.get_position().unwrap(); + P => window.set_outer_position({ + let mut position = window.get_outer_position().unwrap(); let sign = if state { 1.0 } else { -1.0 }; position.x += 10.0 * sign; position.y += 10.0 * sign; @@ -77,9 +77,9 @@ fn main() { WINDOW_SIZE.1 as i32 / 2, ).into()).unwrap(), Z => { - window.hide(); + window.set_visible(false); thread::sleep(Duration::from_secs(1)); - window.show(); + window.set_visible(true); }, _ => (), } diff --git a/examples/resizable.rs b/examples/resizable.rs index f5690b86b7..969ce04b3a 100644 --- a/examples/resizable.rs +++ b/examples/resizable.rs @@ -10,7 +10,7 @@ fn main() { let window = WindowBuilder::new() .with_title("Hit space to toggle resizability.") - .with_dimensions((400, 200).into()) + .with_inner_size((400, 200).into()) .with_resizable(resizable) .build(&event_loop) .unwrap(); diff --git a/src/monitor.rs b/src/monitor.rs index 7533cb78dd..6a6eb00005 100644 --- a/src/monitor.rs +++ b/src/monitor.rs @@ -72,8 +72,8 @@ impl MonitorHandle { /// Returns the top-left corner position of the monitor relative to the larger full /// screen area. #[inline] - pub fn get_position(&self) -> PhysicalPosition { - self.inner.get_position() + pub fn get_outer_position(&self) -> PhysicalPosition { + self.inner.get_outer_position() } /// Returns the DPI factor that can be used to map logical pixels to physical pixels, and vice versa. diff --git a/src/platform_impl/android/mod.rs b/src/platform_impl/android/mod.rs index 8cad342610..0985664298 100644 --- a/src/platform_impl/android/mod.rs +++ b/src/platform_impl/android/mod.rs @@ -205,7 +205,7 @@ impl fmt::Debug for MonitorHandle { let monitor_id_proxy = MonitorHandle { name: self.get_name(), dimensions: self.get_dimensions(), - position: self.get_position(), + position: self.get_outer_position(), hidpi_factor: self.get_hidpi_factor(), }; @@ -231,7 +231,7 @@ impl MonitorHandle { } #[inline] - pub fn get_position(&self) -> PhysicalPosition { + pub fn get_outer_position(&self) -> PhysicalPosition { // Android assumes single screen (0, 0).into() } @@ -285,7 +285,7 @@ impl Window { } #[inline] - pub fn get_position(&self) -> Option { + pub fn get_outer_position(&self) -> Option { // N/A None } @@ -297,17 +297,17 @@ impl Window { } #[inline] - pub fn set_position(&self, _position: LogicalPosition) { + pub fn set_outer_position(&self, _position: LogicalPosition) { // N/A } #[inline] - pub fn set_min_dimensions(&self, _dimensions: Option) { + pub fn set_min_inner_size(&self, _dimensions: Option) { // N/A } #[inline] - pub fn set_max_dimensions(&self, _dimensions: Option) { + pub fn set_max_inner_size(&self, _dimensions: Option) { // N/A } @@ -348,7 +348,7 @@ impl Window { } #[inline] - pub fn grab_cursor(&self, _grab: bool) -> Result<(), String> { + pub fn set_cursor_grab(&self, _grab: bool) -> Result<(), String> { Err("Cursor grabbing is not possible on Android.".to_owned()) } diff --git a/src/platform_impl/emscripten/mod.rs b/src/platform_impl/emscripten/mod.rs index 95baa7f8e4..47f479dad0 100644 --- a/src/platform_impl/emscripten/mod.rs +++ b/src/platform_impl/emscripten/mod.rs @@ -46,7 +46,7 @@ impl MonitorHandle { } #[inline] - pub fn get_position(&self) -> PhysicalPosition { + pub fn get_outer_position(&self) -> PhysicalPosition { unimplemented!() } @@ -163,7 +163,7 @@ impl WindowId { pub struct Window2 { cursor_grabbed: Mutex, - cursor_hidden: Mutex, + cursor_visible: Mutex, is_fullscreen: bool, events: Box>>, } @@ -387,8 +387,8 @@ impl Window { } let w = Window2 { - cursor_grabbed: Default::default(), - cursor_hidden: Default::default(), + cursor_grabbed: Mutex::new(false), + cursor_visible: Mutex::new(true), events: Default::default(), is_fullscreen: attribs.fullscreen.is_some(), }; @@ -427,7 +427,7 @@ impl Window { em_try(ffi::emscripten_set_fullscreenchange_callback(ptr::null(), 0 as *mut c_void, ffi::EM_FALSE, Some(fullscreen_callback))) .map_err(|e| ::CreationError::OsError(e))?; } - } else if let Some(size) = attribs.dimensions { + } else if let Some(size) = attribs.inner_size { window.set_inner_size(size); } @@ -445,7 +445,7 @@ impl Window { } #[inline] - pub fn get_position(&self) -> Option { + pub fn get_outer_position(&self) -> Option { Some((0, 0).into()) } @@ -455,7 +455,7 @@ impl Window { } #[inline] - pub fn set_position(&self, _: LogicalPosition) { + pub fn set_outer_position(&self, _: LogicalPosition) { } #[inline] @@ -497,12 +497,12 @@ impl Window { } #[inline] - pub fn set_min_dimensions(&self, _dimensions: Option) { + pub fn set_min_inner_size(&self, _dimensions: Option) { // N/A } #[inline] - pub fn set_max_dimensions(&self, _dimensions: Option) { + pub fn set_max_inner_size(&self, _dimensions: Option) { // N/A } @@ -527,7 +527,7 @@ impl Window { } #[inline] - pub fn grab_cursor(&self, grab: bool) -> Result<(), String> { + pub fn set_cursor_grab(&self, grab: bool) -> Result<(), String> { let mut grabbed_lock = self.window.cursor_grabbed.lock().unwrap(); if grab == *grabbed_lock { return Ok(()); } unsafe { @@ -554,15 +554,15 @@ impl Window { } #[inline] - pub fn hide_cursor(&self, hide: bool) { - let mut hidden_lock = self.window.cursor_hidden.lock().unwrap(); - if hide == *hidden_lock { return; } - if hide { - unsafe { ffi::emscripten_hide_mouse() }; - } else { + pub fn set_cursor_visible(&self, visible: bool) { + let mut visible_lock = self.window.cursor_visible.lock().unwrap(); + if visible == *visible_lock { return; } + if visible { show_mouse(); + } else { + unsafe { ffi::emscripten_hide_mouse() }; } - *hidden_lock = hide; + *visible_lock = visible; } #[inline] @@ -639,7 +639,7 @@ impl Drop for Window { unsafe { // Return back to normal cursor state self.hide_cursor(false); - self.grab_cursor(false); + self.set_cursor_grab(false); // Exit fullscreen if on if self.window.is_fullscreen { diff --git a/src/platform_impl/ios/mod.rs b/src/platform_impl/ios/mod.rs index ed8d74ba84..5d468371ca 100644 --- a/src/platform_impl/ios/mod.rs +++ b/src/platform_impl/ios/mod.rs @@ -160,7 +160,7 @@ impl fmt::Debug for MonitorHandle { let monitor_id_proxy = MonitorHandle { name: self.get_name(), dimensions: self.get_dimensions(), - position: self.get_position(), + position: self.get_outer_position(), hidpi_factor: self.get_hidpi_factor(), }; @@ -187,7 +187,7 @@ impl MonitorHandle { } #[inline] - pub fn get_position(&self) -> PhysicalPosition { + pub fn get_outer_position(&self) -> PhysicalPosition { // iOS assumes single screen (0, 0).into() } @@ -396,7 +396,7 @@ impl Window { } #[inline] - pub fn get_position(&self) -> Option { + pub fn get_outer_position(&self) -> Option { // N/A None } @@ -408,7 +408,7 @@ impl Window { } #[inline] - pub fn set_position(&self, _position: LogicalPosition) { + pub fn set_outer_position(&self, _position: LogicalPosition) { // N/A } @@ -428,12 +428,12 @@ impl Window { } #[inline] - pub fn set_min_dimensions(&self, _dimensions: Option) { + pub fn set_min_inner_size(&self, _dimensions: Option) { // N/A } #[inline] - pub fn set_max_dimensions(&self, _dimensions: Option) { + pub fn set_max_inner_size(&self, _dimensions: Option) { // N/A } @@ -448,12 +448,12 @@ impl Window { } #[inline] - pub fn grab_cursor(&self, _grab: bool) -> Result<(), String> { + pub fn set_cursor_grab(&self, _grab: bool) -> Result<(), String> { Err("Cursor grabbing is not possible on iOS.".to_owned()) } #[inline] - pub fn hide_cursor(&self, _hide: bool) { + pub fn set_cursor_visible(&self, _visible: bool) { // N/A } diff --git a/src/platform_impl/linux/mod.rs b/src/platform_impl/linux/mod.rs index b609a4bc2b..eef90e0f65 100644 --- a/src/platform_impl/linux/mod.rs +++ b/src/platform_impl/linux/mod.rs @@ -112,10 +112,10 @@ impl MonitorHandle { } #[inline] - pub fn get_position(&self) -> PhysicalPosition { + pub fn get_outer_position(&self) -> PhysicalPosition { match self { - &MonitorHandle::X(ref m) => m.get_position(), - &MonitorHandle::Wayland(ref m) => m.get_position(), + &MonitorHandle::X(ref m) => m.get_outer_position(), + &MonitorHandle::Wayland(ref m) => m.get_outer_position(), } } @@ -178,10 +178,10 @@ impl Window { } #[inline] - pub fn get_position(&self) -> Option { + pub fn get_outer_position(&self) -> Option { match self { - &Window::X(ref w) => w.get_position(), - &Window::Wayland(ref w) => w.get_position(), + &Window::X(ref w) => w.get_outer_position(), + &Window::Wayland(ref w) => w.get_outer_position(), } } @@ -194,10 +194,10 @@ impl Window { } #[inline] - pub fn set_position(&self, position: LogicalPosition) { + pub fn set_outer_position(&self, position: LogicalPosition) { match self { - &Window::X(ref w) => w.set_position(position), - &Window::Wayland(ref w) => w.set_position(position), + &Window::X(ref w) => w.set_outer_position(position), + &Window::Wayland(ref w) => w.set_outer_position(position), } } @@ -226,18 +226,18 @@ impl Window { } #[inline] - pub fn set_min_dimensions(&self, dimensions: Option) { + pub fn set_min_inner_size(&self, dimensions: Option) { match self { - &Window::X(ref w) => w.set_min_dimensions(dimensions), - &Window::Wayland(ref w) => w.set_min_dimensions(dimensions), + &Window::X(ref w) => w.set_min_inner_size(dimensions), + &Window::Wayland(ref w) => w.set_min_inner_size(dimensions), } } #[inline] - pub fn set_max_dimensions(&self, dimensions: Option) { + pub fn set_max_inner_size(&self, dimensions: Option) { match self { - &Window::X(ref w) => w.set_max_dimensions(dimensions), - &Window::Wayland(ref w) => w.set_max_dimensions(dimensions), + &Window::X(ref w) => w.set_max_inner_size(dimensions), + &Window::Wayland(ref w) => w.set_max_inner_size(dimensions), } } @@ -258,18 +258,18 @@ impl Window { } #[inline] - pub fn grab_cursor(&self, grab: bool) -> Result<(), String> { + pub fn set_cursor_grab(&self, grab: bool) -> Result<(), String> { match self { - &Window::X(ref window) => window.grab_cursor(grab), - &Window::Wayland(ref window) => window.grab_cursor(grab), + &Window::X(ref window) => window.set_cursor_grab(grab), + &Window::Wayland(ref window) => window.set_cursor_grab(grab), } } #[inline] - pub fn hide_cursor(&self, hide: bool) { + pub fn set_cursor_visible(&self, visible: bool) { match self { - &Window::X(ref window) => window.hide_cursor(hide), - &Window::Wayland(ref window) => window.hide_cursor(hide), + &Window::X(ref window) => window.set_cursor_visible(visible), + &Window::Wayland(ref window) => window.set_cursor_visible(visible), } } @@ -574,4 +574,4 @@ fn sticky_exit_callback( }; // user callback callback(evt, target, cf) -} \ No newline at end of file +} diff --git a/src/platform_impl/linux/wayland/event_loop.rs b/src/platform_impl/linux/wayland/event_loop.rs index dbd23ba30c..231e51a591 100644 --- a/src/platform_impl/linux/wayland/event_loop.rs +++ b/src/platform_impl/linux/wayland/event_loop.rs @@ -535,7 +535,7 @@ impl fmt::Debug for MonitorHandle { name: self.get_name(), native_identifier: self.get_native_identifier(), dimensions: self.get_dimensions(), - position: self.get_position(), + position: self.get_outer_position(), hidpi_factor: self.get_hidpi_factor(), }; @@ -567,7 +567,7 @@ impl MonitorHandle { }.into() } - pub fn get_position(&self) -> PhysicalPosition { + pub fn get_outer_position(&self) -> PhysicalPosition { self.mgr .with_info(&self.proxy, |_, info| info.location) .unwrap_or((0, 0)) diff --git a/src/platform_impl/linux/wayland/window.rs b/src/platform_impl/linux/wayland/window.rs index 15f0341c8f..962607c66a 100644 --- a/src/platform_impl/linux/wayland/window.rs +++ b/src/platform_impl/linux/wayland/window.rs @@ -29,7 +29,7 @@ pub struct Window { impl Window { pub fn new(evlp: &EventLoopWindowTarget, attributes: WindowAttributes, pl_attribs: PlAttributes) -> Result { - let (width, height) = attributes.dimensions.map(Into::into).unwrap_or((800, 600)); + let (width, height) = attributes.inner_size.map(Into::into).unwrap_or((800, 600)); // Create the window let size = Arc::new(Mutex::new((width, height))); let fullscreen = Arc::new(Mutex::new(false)); @@ -109,8 +109,8 @@ impl Window { frame.set_title(attributes.title); // min-max dimensions - frame.set_min_size(attributes.min_dimensions.map(Into::into)); - frame.set_max_size(attributes.max_dimensions.map(Into::into)); + frame.set_min_size(attributes.min_inner_size.map(Into::into)); + frame.set_max_size(attributes.max_inner_size.map(Into::into)); let kill_switch = Arc::new(Mutex::new(false)); let need_frame_refresh = Arc::new(Mutex::new(true)); @@ -165,7 +165,7 @@ impl Window { } #[inline] - pub fn get_position(&self) -> Option { + pub fn get_outer_position(&self) -> Option { // Not possible with wayland None } @@ -177,7 +177,7 @@ impl Window { } #[inline] - pub fn set_position(&self, _pos: LogicalPosition) { + pub fn set_outer_position(&self, _pos: LogicalPosition) { // Not possible with wayland } @@ -205,12 +205,12 @@ impl Window { } #[inline] - pub fn set_min_dimensions(&self, dimensions: Option) { + pub fn set_min_inner_size(&self, dimensions: Option) { self.frame.lock().unwrap().set_min_size(dimensions.map(Into::into)); } #[inline] - pub fn set_max_dimensions(&self, dimensions: Option) { + pub fn set_max_inner_size(&self, dimensions: Option) { self.frame.lock().unwrap().set_max_size(dimensions.map(Into::into)); } @@ -270,12 +270,12 @@ impl Window { } #[inline] - pub fn hide_cursor(&self, _hide: bool) { + pub fn set_cursor_visible(&self, _visible: bool) { // TODO: This isn't possible on Wayland yet } #[inline] - pub fn grab_cursor(&self, _grab: bool) -> Result<(), String> { + pub fn set_cursor_grab(&self, _grab: bool) -> Result<(), String> { Err("Cursor grabbing is not yet possible on Wayland.".to_owned()) } diff --git a/src/platform_impl/linux/x11/monitor.rs b/src/platform_impl/linux/x11/monitor.rs index 9f0d92b703..159358c10c 100644 --- a/src/platform_impl/linux/x11/monitor.rs +++ b/src/platform_impl/linux/x11/monitor.rs @@ -67,7 +67,7 @@ impl MonitorHandle { primary: bool, ) -> Option { let (name, hidpi_factor) = unsafe { xconn.get_output_info(resources, &repr)? }; - let (dimensions, position) = unsafe { (repr.get_dimensions(), repr.get_position()) }; + let (dimensions, position) = unsafe { (repr.get_dimensions(), repr.get_outer_position()) }; let rect = util::AaRect::new(position, dimensions); Some(MonitorHandle { id, @@ -93,7 +93,7 @@ impl MonitorHandle { self.dimensions.into() } - pub fn get_position(&self) -> PhysicalPosition { + pub fn get_outer_position(&self) -> PhysicalPosition { self.position.into() } diff --git a/src/platform_impl/linux/x11/util/randr.rs b/src/platform_impl/linux/x11/util/randr.rs index a07c8257a7..acf2ac8b87 100644 --- a/src/platform_impl/linux/x11/util/randr.rs +++ b/src/platform_impl/linux/x11/util/randr.rs @@ -58,7 +58,7 @@ impl MonitorRepr { } } - pub unsafe fn get_position(&self) -> (i32, i32) { + pub unsafe fn get_outer_position(&self) -> (i32, i32) { match *self { MonitorRepr::Monitor(monitor) => ((*monitor).x as i32, (*monitor).y as i32), MonitorRepr::Crtc(crtc) => ((*crtc).x as i32, (*crtc).y as i32), diff --git a/src/platform_impl/linux/x11/window.rs b/src/platform_impl/linux/x11/window.rs index 21f6cf0d8a..f7b96dfeb9 100644 --- a/src/platform_impl/linux/x11/window.rs +++ b/src/platform_impl/linux/x11/window.rs @@ -42,8 +42,8 @@ pub struct SharedState { // Used to restore position after exiting fullscreen. pub restore_position: Option<(i32, i32)>, pub frame_extents: Option, - pub min_dimensions: Option, - pub max_dimensions: Option, + pub min_inner_size: Option, + pub max_inner_size: Option, } impl SharedState { @@ -64,7 +64,7 @@ pub struct UnownedWindow { screen_id: i32, // never changes cursor: Mutex, cursor_grabbed: Mutex, - cursor_hidden: Mutex, + cursor_visible: Mutex, ime_sender: Mutex, pub multitouch: bool, // never changes pub shared_state: Mutex, @@ -110,26 +110,26 @@ impl UnownedWindow { info!("Guessed window DPI factor: {}", dpi_factor); - let max_dimensions: Option<(u32, u32)> = window_attrs.max_dimensions.map(|size| { + let max_inner_size: Option<(u32, u32)> = window_attrs.max_inner_size.map(|size| { size.to_physical(dpi_factor).into() }); - let min_dimensions: Option<(u32, u32)> = window_attrs.min_dimensions.map(|size| { + let min_inner_size: Option<(u32, u32)> = window_attrs.min_inner_size.map(|size| { size.to_physical(dpi_factor).into() }); let dimensions = { // x11 only applies constraints when the window is actively resized // by the user, so we have to manually apply the initial constraints - let mut dimensions: (u32, u32) = window_attrs.dimensions + let mut dimensions: (u32, u32) = window_attrs.inner_size .or_else(|| Some((800, 600).into())) .map(|size| size.to_physical(dpi_factor)) .map(Into::into) .unwrap(); - if let Some(max) = max_dimensions { + if let Some(max) = max_inner_size { dimensions.0 = cmp::min(dimensions.0, max.0); dimensions.1 = cmp::min(dimensions.1, max.1); } - if let Some(min) = min_dimensions { + if let Some(min) = min_inner_size { dimensions.0 = cmp::max(dimensions.0, min.0); dimensions.1 = cmp::max(dimensions.1, min.1); } @@ -209,8 +209,8 @@ impl UnownedWindow { root, screen_id, cursor: Default::default(), - cursor_grabbed: Default::default(), - cursor_hidden: Default::default(), + cursor_grabbed: Mutex::new(false), + cursor_visible: Mutex::new(true), ime_sender: Mutex::new(event_loop.ime_sender.clone()), multitouch: window_attrs.multitouch, shared_state: SharedState::new(dpi_factor), @@ -290,27 +290,27 @@ impl UnownedWindow { // set size hints { - let mut min_dimensions = window_attrs.min_dimensions + let mut min_inner_size = window_attrs.min_inner_size .map(|size| size.to_physical(dpi_factor)); - let mut max_dimensions = window_attrs.max_dimensions + let mut max_inner_size = window_attrs.max_inner_size .map(|size| size.to_physical(dpi_factor)); if !window_attrs.resizable { if util::wm_name_is_one_of(&["Xfwm4"]) { warn!("To avoid a WM bug, disabling resizing has no effect on Xfwm4"); } else { - max_dimensions = Some(dimensions.into()); - min_dimensions = Some(dimensions.into()); + max_inner_size = Some(dimensions.into()); + min_inner_size = Some(dimensions.into()); let mut shared_state_lock = window.shared_state.lock(); - shared_state_lock.min_dimensions = window_attrs.min_dimensions; - shared_state_lock.max_dimensions = window_attrs.max_dimensions; + shared_state_lock.min_inner_size = window_attrs.min_inner_size; + shared_state_lock.max_inner_size = window_attrs.max_inner_size; } } let mut normal_hints = util::NormalHints::new(xconn); normal_hints.set_size(Some(dimensions)); - normal_hints.set_min_size(min_dimensions.map(Into::into)); - normal_hints.set_max_size(max_dimensions.map(Into::into)); + normal_hints.set_min_size(min_inner_size.map(Into::into)); + normal_hints.set_max_size(max_inner_size.map(Into::into)); normal_hints.set_resize_increments(pl_attribs.resize_increments); normal_hints.set_base_size(pl_attribs.base_size); xconn.set_normal_hints(window.xwindow, normal_hints).queue(); @@ -535,9 +535,9 @@ impl UnownedWindow { flusher }, Some(RootMonitorHandle { inner: PlatformMonitorHandle::X(monitor) }) => { - let window_position = self.get_position_physical(); + let window_position = self.get_outer_position_physical(); self.shared_state.lock().restore_position = window_position; - let monitor_origin: (i32, i32) = monitor.get_position().into(); + let monitor_origin: (i32, i32) = monitor.get_outer_position().into(); self.set_position_inner(monitor_origin.0, monitor_origin.1).queue(); self.set_fullscreen_hint(true) } @@ -561,7 +561,7 @@ impl UnownedWindow { fn get_rect(&self) -> Option { // TODO: This might round-trip more times than needed. - if let (Some(position), Some(size)) = (self.get_position_physical(), self.get_outer_size_physical()) { + if let (Some(position), Some(size)) = (self.get_outer_position_physical(), self.get_outer_size_physical()) { Some(util::AaRect::new(position, size)) } else { None @@ -728,26 +728,26 @@ impl UnownedWindow { (*self.shared_state.lock()).frame_extents.take(); } - pub(crate) fn get_position_physical(&self) -> Option<(i32, i32)> { + pub(crate) fn get_outer_position_physical(&self) -> Option<(i32, i32)> { let extents = (*self.shared_state.lock()).frame_extents.clone(); if let Some(extents) = extents { self.get_inner_position_physical() .map(|(x, y)| extents.inner_pos_to_outer(x, y)) } else { self.update_cached_frame_extents(); - self.get_position_physical() + self.get_outer_position_physical() } } #[inline] - pub fn get_position(&self) -> Option { + pub fn get_outer_position(&self) -> Option { let extents = (*self.shared_state.lock()).frame_extents.clone(); if let Some(extents) = extents { self.get_inner_position() .map(|logical| extents.inner_pos_to_outer_logical(logical, self.get_hidpi_factor())) } else { self.update_cached_frame_extents(); - self.get_position() + self.get_outer_position() } } @@ -794,7 +794,7 @@ impl UnownedWindow { } #[inline] - pub fn set_position(&self, logical_position: LogicalPosition) { + pub fn set_outer_position(&self, logical_position: LogicalPosition) { let (x, y) = logical_position.to_physical(self.get_hidpi_factor()).into(); self.set_position_physical(x, y); } @@ -861,32 +861,32 @@ impl UnownedWindow { self.xconn.set_normal_hints(self.xwindow, normal_hints).flush() } - pub(crate) fn set_min_dimensions_physical(&self, dimensions: Option<(u32, u32)>) { + pub(crate) fn set_min_inner_size_physical(&self, dimensions: Option<(u32, u32)>) { self.update_normal_hints(|normal_hints| normal_hints.set_min_size(dimensions)) .expect("Failed to call `XSetWMNormalHints`"); } #[inline] - pub fn set_min_dimensions(&self, logical_dimensions: Option) { - self.shared_state.lock().min_dimensions = logical_dimensions; + pub fn set_min_inner_size(&self, logical_dimensions: Option) { + self.shared_state.lock().min_inner_size = logical_dimensions; let physical_dimensions = logical_dimensions.map(|logical_dimensions| { logical_dimensions.to_physical(self.get_hidpi_factor()).into() }); - self.set_min_dimensions_physical(physical_dimensions); + self.set_min_inner_size_physical(physical_dimensions); } - pub(crate) fn set_max_dimensions_physical(&self, dimensions: Option<(u32, u32)>) { + pub(crate) fn set_max_inner_size_physical(&self, dimensions: Option<(u32, u32)>) { self.update_normal_hints(|normal_hints| normal_hints.set_max_size(dimensions)) .expect("Failed to call `XSetWMNormalHints`"); } #[inline] - pub fn set_max_dimensions(&self, logical_dimensions: Option) { - self.shared_state.lock().max_dimensions = logical_dimensions; + pub fn set_max_inner_size(&self, logical_dimensions: Option) { + self.shared_state.lock().max_inner_size = logical_dimensions; let physical_dimensions = logical_dimensions.map(|logical_dimensions| { logical_dimensions.to_physical(self.get_hidpi_factor()).into() }); - self.set_max_dimensions_physical(physical_dimensions); + self.set_max_inner_size_physical(physical_dimensions); } pub(crate) fn adjust_for_dpi( @@ -936,22 +936,22 @@ impl UnownedWindow { let (logical_min, logical_max) = if resizable { let shared_state_lock = self.shared_state.lock(); - (shared_state_lock.min_dimensions, shared_state_lock.max_dimensions) + (shared_state_lock.min_inner_size, shared_state_lock.max_inner_size) } else { let window_size = self.get_inner_size(); (window_size.clone(), window_size) }; let dpi_factor = self.get_hidpi_factor(); - let min_dimensions = logical_min + let min_inner_size = logical_min .map(|logical_size| logical_size.to_physical(dpi_factor)) .map(Into::into); - let max_dimensions = logical_max + let max_inner_size = logical_max .map(|logical_size| logical_size.to_physical(dpi_factor)) .map(Into::into); self.update_normal_hints(|normal_hints| { - normal_hints.set_min_size(min_dimensions); - normal_hints.set_max_size(max_dimensions); + normal_hints.set_min_size(min_inner_size); + normal_hints.set_max_size(max_inner_size); }).expect("Failed to call `XSetWMNormalHints`"); } @@ -1073,7 +1073,7 @@ impl UnownedWindow { #[inline] pub fn set_cursor(&self, cursor: MouseCursor) { *self.cursor.lock() = cursor; - if !*self.cursor_hidden.lock() { + if *self.cursor_visible.lock() { self.update_cursor(self.get_cursor(cursor)); } } @@ -1117,7 +1117,7 @@ impl UnownedWindow { } #[inline] - pub fn grab_cursor(&self, grab: bool) -> Result<(), String> { + pub fn set_cursor_grab(&self, grab: bool) -> Result<(), String> { let mut grabbed_lock = self.cursor_grabbed.lock(); if grab == *grabbed_lock { return Ok(()); } unsafe { @@ -1173,16 +1173,16 @@ impl UnownedWindow { } #[inline] - pub fn hide_cursor(&self, hide: bool) { - let mut hidden_lock = self.cursor_hidden.lock(); - if hide == *hidden_lock {return; } - let cursor = if hide { - self.create_empty_cursor().expect("Failed to create empty cursor") - } else { + pub fn set_cursor_visible(&self, visible: bool) { + let mut visible_lock = self.cursor_visible.lock(); + if visible == *visible_lock {return; } + let cursor = if visible { self.get_cursor(*self.cursor.lock()) + } else { + self.create_empty_cursor().expect("Failed to create empty cursor") }; - *hidden_lock = hide; - drop(hidden_lock); + *visible_lock = visible; + drop(visible_lock); self.update_cursor(cursor); } diff --git a/src/platform_impl/macos/monitor.rs b/src/platform_impl/macos/monitor.rs index c3c6ce2dfd..7415e3c893 100644 --- a/src/platform_impl/macos/monitor.rs +++ b/src/platform_impl/macos/monitor.rs @@ -41,7 +41,7 @@ impl fmt::Debug for MonitorHandle { name: self.get_name(), native_identifier: self.get_native_identifier(), dimensions: self.get_dimensions(), - position: self.get_position(), + position: self.get_outer_position(), hidpi_factor: self.get_hidpi_factor(), }; @@ -77,7 +77,7 @@ impl MonitorHandle { } #[inline] - pub fn get_position(&self) -> PhysicalPosition { + pub fn get_outer_position(&self) -> PhysicalPosition { let bounds = unsafe { CGDisplayBounds(self.get_native_identifier()) }; PhysicalPosition::from_logical( (bounds.origin.x as f64, bounds.origin.y as f64), diff --git a/src/platform_impl/macos/window.rs b/src/platform_impl/macos/window.rs index 8c98b9bca2..cd11c1d7d4 100644 --- a/src/platform_impl/macos/window.rs +++ b/src/platform_impl/macos/window.rs @@ -110,7 +110,7 @@ fn create_window( let frame = match screen { Some(screen) => appkit::NSScreen::frame(screen), None => { - let (width, height) = attrs.dimensions + let (width, height) = attrs.inner_size .map(|logical| (logical.width, logical.height)) .unwrap_or_else(|| (800.0, 600.0)); NSRect::new(NSPoint::new(0.0, 0.0), NSSize::new(width, height)) @@ -245,7 +245,7 @@ pub struct UnownedWindow { pub shared_state: Arc>, decorations: AtomicBool, cursor: Weak>, - cursor_hidden: AtomicBool, + cursor_visible: AtomicBool, } unsafe impl Send for UnownedWindow {} @@ -289,8 +289,8 @@ impl UnownedWindow { nsapp.activateIgnoringOtherApps_(YES); - win_attribs.min_dimensions.map(|dim| set_min_dimensions(*nswindow, dim)); - win_attribs.max_dimensions.map(|dim| set_max_dimensions(*nswindow, dim)); + win_attribs.min_inner_size.map(|dim| set_min_inner_size(*nswindow, dim)); + win_attribs.max_inner_size.map(|dim| set_max_inner_size(*nswindow, dim)); use cocoa::foundation::NSArray; // register for drag and drop operations. @@ -317,7 +317,7 @@ impl UnownedWindow { shared_state: Arc::new(Mutex::new(win_attribs.into())), decorations: AtomicBool::new(decorations), cursor, - cursor_hidden: Default::default(), + cursor_visible: AtomicBool::new(true), }); let delegate = new_delegate(&window, fullscreen.is_some()); @@ -395,7 +395,7 @@ impl UnownedWindow { AppState::queue_redraw(RootWindowId(self.id())); } - pub fn get_position(&self) -> Option { + pub fn get_outer_position(&self) -> Option { let frame_rect = unsafe { NSWindow::frame(*self.nswindow) }; Some(( frame_rect.origin.x as f64, @@ -416,7 +416,7 @@ impl UnownedWindow { ).into()) } - pub fn set_position(&self, position: LogicalPosition) { + pub fn set_outer_position(&self, position: LogicalPosition) { let dummy = NSRect::new( NSPoint::new( position.x, @@ -450,17 +450,17 @@ impl UnownedWindow { } } - pub fn set_min_dimensions(&self, dimensions: Option) { + pub fn set_min_inner_size(&self, dimensions: Option) { unsafe { let dimensions = dimensions.unwrap_or_else(|| (0, 0).into()); - set_min_dimensions(*self.nswindow, dimensions); + set_min_inner_size(*self.nswindow, dimensions); } } - pub fn set_max_dimensions(&self, dimensions: Option) { + pub fn set_max_inner_size(&self, dimensions: Option) { unsafe { let dimensions = dimensions.unwrap_or_else(|| (!0, !0).into()); - set_max_dimensions(*self.nswindow, dimensions); + set_max_inner_size(*self.nswindow, dimensions); } } @@ -497,24 +497,24 @@ impl UnownedWindow { } #[inline] - pub fn grab_cursor(&self, grab: bool) -> Result<(), String> { + pub fn set_cursor_grab(&self, grab: bool) -> Result<(), String> { // TODO: Do this for real https://stackoverflow.com/a/40922095/5435443 CGDisplay::associate_mouse_and_mouse_cursor_position(!grab) .map_err(|status| format!("Failed to grab cursor: `CGError` {:?}", status)) } #[inline] - pub fn hide_cursor(&self, hide: bool) { + pub fn set_cursor_visible(&self, visible: bool) { let cursor_class = class!(NSCursor); // macOS uses a "hide counter" like Windows does, so we avoid incrementing it more than once. // (otherwise, `hide_cursor(false)` would need to be called n times!) - if hide != self.cursor_hidden.load(Ordering::Acquire) { - if hide { - let _: () = unsafe { msg_send![cursor_class, hide] }; - } else { + if visible != self.cursor_visible.load(Ordering::Acquire) { + if visible { let _: () = unsafe { msg_send![cursor_class, unhide] }; + } else { + let _: () = unsafe { msg_send![cursor_class, hide] }; } - self.cursor_hidden.store(hide, Ordering::Release); + self.cursor_visible.store(visible, Ordering::Release); } } @@ -869,7 +869,7 @@ impl Drop for UnownedWindow { } } -unsafe fn set_min_dimensions(window: V, mut min_size: LogicalSize) { +unsafe fn set_min_inner_size(window: V, mut min_size: LogicalSize) { let mut current_rect = NSWindow::frame(window); let content_rect = NSWindow::contentRectForFrameRect_(window, NSWindow::frame(window)); // Convert from client area size to window size @@ -893,7 +893,7 @@ unsafe fn set_min_dimensions(window: V, mut min_size: Logica } } -unsafe fn set_max_dimensions(window: V, mut max_size: LogicalSize) { +unsafe fn set_max_inner_size(window: V, mut max_size: LogicalSize) { let mut current_rect = NSWindow::frame(window); let content_rect = NSWindow::contentRectForFrameRect_(window, NSWindow::frame(window)); // Convert from client area size to window size diff --git a/src/platform_impl/windows/monitor.rs b/src/platform_impl/windows/monitor.rs index 585a2e0d37..f46efac8a3 100644 --- a/src/platform_impl/windows/monitor.rs +++ b/src/platform_impl/windows/monitor.rs @@ -162,7 +162,7 @@ impl MonitorHandle { } #[inline] - pub fn get_position(&self) -> PhysicalPosition { + pub fn get_outer_position(&self) -> PhysicalPosition { self.position.into() } diff --git a/src/platform_impl/windows/window.rs b/src/platform_impl/windows/window.rs index dceb957934..6e2c634b27 100644 --- a/src/platform_impl/windows/window.rs +++ b/src/platform_impl/windows/window.rs @@ -103,16 +103,10 @@ impl Window { } #[inline] - pub fn show(&self) { - unsafe { - winuser::ShowWindow(self.window.0, winuser::SW_SHOW); - } - } - - #[inline] - pub fn hide(&self) { - unsafe { - winuser::ShowWindow(self.window.0, winuser::SW_HIDE); + pub fn set_visible(&self, visible: bool) { + match visible { + true => unsafe { winuser::ShowWindow(self.window.0, winuser::SW_SHOW); }, + false => unsafe { winuser::ShowWindow(self.window.0, winuser::SW_HIDE); }, } } @@ -132,14 +126,14 @@ impl Window { } } - pub(crate) fn get_position_physical(&self) -> Option<(i32, i32)> { + pub(crate) fn get_outer_position_physical(&self) -> Option<(i32, i32)> { util::get_window_rect(self.window.0) .map(|rect| (rect.left as i32, rect.top as i32)) } #[inline] - pub fn get_position(&self) -> Option { - self.get_position_physical() + pub fn get_outer_position(&self) -> Option { + self.get_outer_position_physical() .map(|physical_position| { let dpi_factor = self.get_hidpi_factor(); LogicalPosition::from_physical(physical_position, dpi_factor) @@ -179,7 +173,7 @@ impl Window { } #[inline] - pub fn set_position(&self, logical_position: LogicalPosition) { + pub fn set_outer_position(&self, logical_position: LogicalPosition) { let dpi_factor = self.get_hidpi_factor(); let (x, y) = logical_position.to_physical(dpi_factor).into(); self.set_position_physical(x, y); @@ -259,7 +253,7 @@ impl Window { self.set_inner_size_physical(width, height); } - pub(crate) fn set_min_dimensions_physical(&self, dimensions: Option<(u32, u32)>) { + pub(crate) fn set_min_inner_size_physical(&self, dimensions: Option<(u32, u32)>) { self.window_state.lock().min_size = dimensions.map(Into::into); // Make windows re-check the window size bounds. self.get_inner_size_physical() @@ -267,15 +261,15 @@ impl Window { } #[inline] - pub fn set_min_dimensions(&self, logical_size: Option) { + pub fn set_min_inner_size(&self, logical_size: Option) { let physical_size = logical_size.map(|logical_size| { let dpi_factor = self.get_hidpi_factor(); logical_size.to_physical(dpi_factor).into() }); - self.set_min_dimensions_physical(physical_size); + self.set_min_inner_size_physical(physical_size); } - pub fn set_max_dimensions_physical(&self, dimensions: Option<(u32, u32)>) { + pub fn set_max_inner_size_physical(&self, dimensions: Option<(u32, u32)>) { self.window_state.lock().max_size = dimensions.map(Into::into); // Make windows re-check the window size bounds. self.get_inner_size_physical() @@ -283,12 +277,12 @@ impl Window { } #[inline] - pub fn set_max_dimensions(&self, logical_size: Option) { + pub fn set_max_inner_size(&self, logical_size: Option) { let physical_size = logical_size.map(|logical_size| { let dpi_factor = self.get_hidpi_factor(); logical_size.to_physical(dpi_factor).into() }); - self.set_max_dimensions_physical(physical_size); + self.set_max_inner_size_physical(physical_size); } #[inline] @@ -325,7 +319,7 @@ impl Window { } #[inline] - pub fn grab_cursor(&self, grab: bool) -> Result<(), String> { + pub fn set_cursor_grab(&self, grab: bool) -> Result<(), String> { let window = self.window.clone(); let window_state = Arc::clone(&self.window_state); let (tx, rx) = channel(); @@ -340,14 +334,14 @@ impl Window { } #[inline] - pub fn hide_cursor(&self, hide: bool) { + pub fn set_cursor_visible(&self, visible: bool) { let window = self.window.clone(); let window_state = Arc::clone(&self.window_state); let (tx, rx) = channel(); self.thread_executor.execute_in_thread(move || { let result = window_state.lock().mouse - .set_cursor_flags(window.0, |f| f.set(CursorFlags::HIDDEN, hide)) + .set_cursor_flags(window.0, |f| f.set(CursorFlags::HIDDEN, !visible)) .map_err(|e| e.to_string()); let _ = tx.send(result); }); @@ -413,7 +407,7 @@ impl Window { match &monitor { &Some(RootMonitorHandle { ref inner }) => { - let (x, y): (i32, i32) = inner.get_position().into(); + let (x, y): (i32, i32) = inner.get_outer_position().into(); let (width, height): (u32, u32) = inner.get_dimensions().into(); let mut monitor = monitor.clone(); @@ -641,7 +635,7 @@ unsafe fn init( }; info!("Guessed window DPI factor: {}", guessed_dpi_factor); - let dimensions = attributes.dimensions.unwrap_or_else(|| (1024, 768).into()); + let dimensions = attributes.inner_size.unwrap_or_else(|| (1024, 768).into()); let mut window_flags = WindowFlags::empty(); window_flags.set(WindowFlags::DECORATIONS, attributes.decorations); @@ -763,7 +757,7 @@ unsafe fn init( force_window_active(win.window.0); } - if let Some(dimensions) = attributes.dimensions { + if let Some(dimensions) = attributes.inner_size { win.set_inner_size(dimensions); } diff --git a/src/platform_impl/windows/window_state.rs b/src/platform_impl/windows/window_state.rs index 844707d6f8..ceb5910bd0 100644 --- a/src/platform_impl/windows/window_state.rs +++ b/src/platform_impl/windows/window_state.rs @@ -95,8 +95,8 @@ impl WindowState { cursor_flags: CursorFlags::empty(), }, - min_size: attributes.min_dimensions, - max_size: attributes.max_dimensions, + min_size: attributes.min_inner_size, + max_size: attributes.max_inner_size, window_icon, taskbar_icon, diff --git a/src/window.rs b/src/window.rs index 0bc9c08b3b..53b2217928 100644 --- a/src/window.rs +++ b/src/window.rs @@ -84,17 +84,17 @@ pub struct WindowAttributes { /// used. /// /// The default is `None`. - pub dimensions: Option, + pub inner_size: Option, /// The minimum dimensions a window can be, If this is `None`, the window will have no minimum dimensions (aside from reserved). /// /// The default is `None`. - pub min_dimensions: Option, + pub min_inner_size: Option, /// The maximum dimensions a window can be, If this is `None`, the maximum will have no maximum or will be set to the primary monitor's dimensions by the platform. /// /// The default is `None`. - pub max_dimensions: Option, + pub max_inner_size: Option, /// Whether the window is resizable or not. /// @@ -151,9 +151,9 @@ impl Default for WindowAttributes { #[inline] fn default() -> WindowAttributes { WindowAttributes { - dimensions: None, - min_dimensions: None, - max_dimensions: None, + inner_size: None, + min_inner_size: None, + max_inner_size: None, resizable: true, title: "winit window".to_owned(), maximized: false, @@ -179,22 +179,22 @@ impl WindowBuilder { /// Requests the window to be of specific dimensions. #[inline] - pub fn with_dimensions(mut self, size: LogicalSize) -> WindowBuilder { - self.window.dimensions = Some(size); + pub fn with_inner_size(mut self, size: LogicalSize) -> WindowBuilder { + self.window.inner_size = Some(size); self } /// Sets a minimum dimension size for the window #[inline] - pub fn with_min_dimensions(mut self, min_size: LogicalSize) -> WindowBuilder { - self.window.min_dimensions = Some(min_size); + pub fn with_min_inner_size(mut self, min_size: LogicalSize) -> WindowBuilder { + self.window.min_inner_size = Some(min_size); self } /// Sets a maximum dimension size for the window #[inline] - pub fn with_max_dimensions(mut self, max_size: LogicalSize) -> WindowBuilder { - self.window.max_dimensions = Some(max_size); + pub fn with_max_inner_size(mut self, max_size: LogicalSize) -> WindowBuilder { + self.window.max_inner_size = Some(max_size); self } @@ -295,7 +295,7 @@ impl WindowBuilder { /// out of memory, etc. #[inline] pub fn build(mut self, window_target: &EventLoopWindowTarget) -> Result { - self.window.dimensions = Some(self.window.dimensions.unwrap_or_else(|| { + self.window.inner_size = Some(self.window.inner_size.unwrap_or_else(|| { if let Some(ref monitor) = self.window.fullscreen { // resizing the window to the dimensions of the monitor when fullscreen LogicalSize::from_physical(monitor.get_dimensions(), 1.0) @@ -335,26 +335,12 @@ impl Window { self.window.set_title(title) } - /// Shows the window if it was hidden. - /// - /// ## Platform-specific - /// - /// - Has no effect on Android + /// Modifies the window's visibility. /// + /// If `false`, this will hide the window. If `true`, this will show the window. #[inline] - pub fn show(&self) { - self.window.show() - } - - /// Hides the window if it was visible. - /// - /// ## Platform-specific - /// - /// - Has no effect on Android - /// - #[inline] - pub fn hide(&self) { - self.window.hide() + pub fn set_visible(&self, visible: bool) { + self.window.set_visible(visible) } /// Emits a `WindowEvent::RedrawRequested` event in the associated event loop after all OS @@ -368,6 +354,7 @@ impl Window { /// * While processing `EventsCleared`. /// * While processing a `RedrawRequested` event that was sent during `EventsCleared` or any /// directly subsequent `RedrawRequested` event. + #[inline] pub fn request_redraw(&self) { self.window.request_redraw() } @@ -384,14 +371,14 @@ impl Window { /// /// Returns `None` if the window no longer exists. #[inline] - pub fn get_position(&self) -> Option { - self.window.get_position() + pub fn get_outer_position(&self) -> Option { + self.window.get_outer_position() } /// Returns the position of the top-left hand corner of the window's client area relative to the /// top-left hand corner of the desktop. /// - /// The same conditions that apply to `get_position` apply to this method. + /// The same conditions that apply to `get_outer_position` apply to this method. #[inline] pub fn get_inner_position(&self) -> Option { self.window.get_inner_position() @@ -399,12 +386,12 @@ impl Window { /// Modifies the position of the window. /// - /// See `get_position` for more information about the coordinates. + /// See `get_outer_position` for more information about the coordinates. /// /// This is a no-op if the window has already been closed. #[inline] - pub fn set_position(&self, position: LogicalPosition) { - self.window.set_position(position) + pub fn set_outer_position(&self, position: LogicalPosition) { + self.window.set_outer_position(position) } /// Returns the logical size of the window's client area. @@ -442,14 +429,14 @@ impl Window { /// Sets a minimum dimension size for the window. #[inline] - pub fn set_min_dimensions(&self, dimensions: Option) { - self.window.set_min_dimensions(dimensions) + pub fn set_min_inner_size(&self, dimensions: Option) { + self.window.set_min_inner_size(dimensions) } /// Sets a maximum dimension size for the window. #[inline] - pub fn set_max_dimensions(&self, dimensions: Option) { - self.window.set_max_dimensions(dimensions) + pub fn set_max_inner_size(&self, dimensions: Option) { + self.window.set_max_inner_size(dimensions) } /// Sets whether the window is resizable or not. @@ -505,8 +492,8 @@ impl Window { /// /// This has no effect on Android or iOS. #[inline] - pub fn grab_cursor(&self, grab: bool) -> Result<(), String> { - self.window.grab_cursor(grab) + pub fn set_cursor_grab(&self, grab: bool) -> Result<(), String> { + self.window.set_cursor_grab(grab) } /// Hides the cursor, making it invisible but still usable. @@ -520,8 +507,8 @@ impl Window { /// /// This has no effect on Android or iOS. #[inline] - pub fn hide_cursor(&self, hide: bool) { - self.window.hide_cursor(hide) + pub fn set_cursor_visible(&self, visible: bool) { + self.window.set_cursor_visible(visible) } /// Sets the window to maximized or back From e823983b2f66e2d352af25c08d609d9fcd3be5d4 Mon Sep 17 00:00:00 2001 From: Osspial Date: Sat, 18 May 2019 01:01:11 -0400 Subject: [PATCH 02/22] Remove multitouch variable (hopefully this compiles!) --- src/platform_impl/android/mod.rs | 2 +- src/platform_impl/linux/x11/event_processor.rs | 7 ++----- src/platform_impl/linux/x11/window.rs | 12 ++++-------- src/window.rs | 12 ------------ 4 files changed, 7 insertions(+), 26 deletions(-) diff --git a/src/platform_impl/android/mod.rs b/src/platform_impl/android/mod.rs index 0985664298..c1df7782dd 100644 --- a/src/platform_impl/android/mod.rs +++ b/src/platform_impl/android/mod.rs @@ -257,7 +257,7 @@ impl Window { return Err(OsError(format!("Android's native window is null"))); } - android_glue::set_multitouch(win_attribs.multitouch); + android_glue::set_multitouch(true); Ok(Window { native_window: native_window as *const _, diff --git a/src/platform_impl/linux/x11/event_processor.rs b/src/platform_impl/linux/x11/event_processor.rs index 9b27fff0aa..1dbd5327c1 100644 --- a/src/platform_impl/linux/x11/event_processor.rs +++ b/src/platform_impl/linux/x11/event_processor.rs @@ -534,10 +534,7 @@ impl EventProcessor { let device_id = mkdid(xev.deviceid); if (xev.flags & ffi::XIPointerEmulated) != 0 { // Deliver multi-touch events instead of emulated mouse events. - let return_now = self - .with_window(xev.event, |window| window.multitouch) - .unwrap_or(true); - if return_now { return; } + return; } let modifiers = ModifiersState::from(xev.mods); @@ -1007,4 +1004,4 @@ impl EventProcessor { Err(_) => (), } } -} \ No newline at end of file +} diff --git a/src/platform_impl/linux/x11/window.rs b/src/platform_impl/linux/x11/window.rs index f7b96dfeb9..5e1af7d81a 100644 --- a/src/platform_impl/linux/x11/window.rs +++ b/src/platform_impl/linux/x11/window.rs @@ -66,7 +66,6 @@ pub struct UnownedWindow { cursor_grabbed: Mutex, cursor_visible: Mutex, ime_sender: Mutex, - pub multitouch: bool, // never changes pub shared_state: Mutex, pending_redraws: Arc<::std::sync::Mutex>>, } @@ -212,7 +211,6 @@ impl UnownedWindow { cursor_grabbed: Mutex::new(false), cursor_visible: Mutex::new(true), ime_sender: Mutex::new(event_loop.ime_sender.clone()), - multitouch: window_attrs.multitouch, shared_state: SharedState::new(dpi_factor), pending_redraws: event_loop.pending_redraws.clone(), }; @@ -361,12 +359,10 @@ impl UnownedWindow { | ffi::XI_EnterMask | ffi::XI_LeaveMask | ffi::XI_FocusInMask - | ffi::XI_FocusOutMask; - if window_attrs.multitouch { - mask |= ffi::XI_TouchBeginMask - | ffi::XI_TouchUpdateMask - | ffi::XI_TouchEndMask; - } + | ffi::XI_FocusOutMask + | ffi::XI_TouchBeginMask + | ffi::XI_TouchUpdateMask + | ffi::XI_TouchEndMask; mask }; xconn.select_xinput_events(window.xwindow, ffi::XIAllMasterDevices, mask).queue(); diff --git a/src/window.rs b/src/window.rs index 53b2217928..7f82c2686d 100644 --- a/src/window.rs +++ b/src/window.rs @@ -141,10 +141,6 @@ pub struct WindowAttributes { /// /// The default is `None`. pub window_icon: Option, - - /// [iOS only] Enable multitouch, - /// see [multipleTouchEnabled](https://developer.apple.com/documentation/uikit/uiview/1622519-multipletouchenabled) - pub multitouch: bool, } impl Default for WindowAttributes { @@ -163,7 +159,6 @@ impl Default for WindowAttributes { decorations: true, always_on_top: false, window_icon: None, - multitouch: false, } } } @@ -282,13 +277,6 @@ impl WindowBuilder { self } - /// Enables multitouch. - #[inline] - pub fn with_multitouch(mut self) -> WindowBuilder { - self.window.multitouch = true; - self - } - /// Builds the window. /// /// Error should be very rare and only occur in case of permission denied, incompatible system, From 6ef9fe4c6bf1f8f4f553da2c5c3fd730a6c2ae67 Mon Sep 17 00:00:00 2001 From: Osspial Date: Mon, 20 May 2019 20:40:47 -0400 Subject: [PATCH 03/22] Remove CreationError::NotSupported --- src/window.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/window.rs b/src/window.rs index 7f82c2686d..c407ae4222 100644 --- a/src/window.rs +++ b/src/window.rs @@ -582,15 +582,12 @@ impl Window { #[derive(Debug, Clone)] pub enum CreationError { OsError(String), - /// TODO: remove this error - NotSupported, } impl CreationError { fn to_string(&self) -> &str { match *self { CreationError::OsError(ref text) => &text, - CreationError::NotSupported => "Some of the requested attributes are not supported", } } } From 00d1d6bc1ee28baa849d0265c433d760cf51a897 Mon Sep 17 00:00:00 2001 From: Osspial Date: Wed, 22 May 2019 16:42:45 -0400 Subject: [PATCH 04/22] Add new error handling types --- src/error.rs | 41 ++++++++++++++++++ src/lib.rs | 2 + src/platform_impl/android/mod.rs | 11 +++-- src/platform_impl/emscripten/mod.rs | 7 ++- src/platform_impl/ios/mod.rs | 19 ++++---- src/platform_impl/linux/mod.rs | 24 +++++----- src/platform_impl/linux/wayland/window.rs | 17 +++----- src/platform_impl/linux/x11/window.rs | 53 +++++++++++------------ src/platform_impl/macos/mod.rs | 4 ++ src/platform_impl/macos/window.rs | 28 ++++++------ src/platform_impl/windows/mod.rs | 2 + src/platform_impl/windows/window.rs | 13 +++--- src/window.rs | 5 ++- 13 files changed, 135 insertions(+), 91 deletions(-) create mode 100644 src/error.rs diff --git a/src/error.rs b/src/error.rs new file mode 100644 index 0000000000..eb848b2435 --- /dev/null +++ b/src/error.rs @@ -0,0 +1,41 @@ +use platform_impl; + +pub enum ExternalError { + NotSupported(NotSupportedError), + Os(OsError), +} + +pub struct NotSupportedError { + _marker: (), +} + +pub struct OsError { + line: u32, + file: &'static str, + error: platform_impl::OsError, +} + +impl NotSupportedError { + #[inline] + pub(crate) fn new() -> NotSupportedError { + NotSupportedError { + _marker: () + } + } +} + +impl OsError { + pub(crate) fn new(line: u32, file: &'static str, error: platform_impl::OsError) -> OsError { + OsError { + line, + file, + error, + } + } +} + +macro_rules! os_error { + ($error:expr) => {{ + crate::error::OsError::new(line!(), file!(), $error) + }} +} diff --git a/src/lib.rs b/src/lib.rs index 4936241ee5..af3dfbfb4f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -115,6 +115,8 @@ extern crate smithay_client_toolkit as sctk; extern crate calloop; pub mod dpi; +#[macro_use] +pub mod error; pub mod event; pub mod event_loop; mod icon; diff --git a/src/platform_impl/android/mod.rs b/src/platform_impl/android/mod.rs index c1df7782dd..f94fe1a760 100644 --- a/src/platform_impl/android/mod.rs +++ b/src/platform_impl/android/mod.rs @@ -23,9 +23,12 @@ use { WindowId as RootWindowId, }; use CreationError::OsError; +use error::{ExternalError, NotSupportedError}; use events::{Touch, TouchPhase}; use window::MonitorHandle as RootMonitorHandle; +pub type OsError = std::io::Error; + pub struct EventLoop { event_rx: Receiver, suspend_callback: RefCell ()>>>, @@ -348,8 +351,8 @@ impl Window { } #[inline] - pub fn set_cursor_grab(&self, _grab: bool) -> Result<(), String> { - Err("Cursor grabbing is not possible on Android.".to_owned()) + pub fn set_cursor_grab(&self, _grab: bool) -> Result<(), ExternalError> { + Err(ExternalError::NotSupported(NotSupportedError::new())) } #[inline] @@ -358,8 +361,8 @@ impl Window { } #[inline] - pub fn set_cursor_position(&self, _position: LogicalPosition) -> Result<(), String> { - Err("Setting cursor position is not possible on Android.".to_owned()) + pub fn set_cursor_position(&self, _position: LogicalPosition) -> Result<(), ExternalError> { + Err(ExternalError::NotSupported(NotSupportedError::new())) } #[inline] diff --git a/src/platform_impl/emscripten/mod.rs b/src/platform_impl/emscripten/mod.rs index 47f479dad0..0a7a57a101 100644 --- a/src/platform_impl/emscripten/mod.rs +++ b/src/platform_impl/emscripten/mod.rs @@ -10,6 +10,7 @@ use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::{Mutex, Arc}; use dpi::{LogicalPosition, LogicalSize, PhysicalPosition, PhysicalSize}; +use error::{ExternalError, NotSupportedError}; use window::MonitorHandle as RootMonitorHandle; const DOCUMENT_NAME: &'static str = "#document\0"; @@ -24,6 +25,8 @@ pub struct PlatformSpecificWindowBuilderAttributes; unsafe impl Send for PlatformSpecificWindowBuilderAttributes {} unsafe impl Sync for PlatformSpecificWindowBuilderAttributes {} +pub type OsError = std::io::Error; + #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct DeviceId; @@ -527,7 +530,7 @@ impl Window { } #[inline] - pub fn set_cursor_grab(&self, grab: bool) -> Result<(), String> { + pub fn set_cursor_grab(&self, grab: bool) -> Result<(), ExternalError> { let mut grabbed_lock = self.window.cursor_grabbed.lock().unwrap(); if grab == *grabbed_lock { return Ok(()); } unsafe { @@ -571,7 +574,7 @@ impl Window { } #[inline] - pub fn set_cursor_position(&self, _position: LogicalPosition) -> Result<(), String> { + pub fn set_cursor_position(&self, _position: LogicalPosition) -> Result<(), ExternalError> { Err("Setting cursor position is not possible on Emscripten.".to_owned()) } diff --git a/src/platform_impl/ios/mod.rs b/src/platform_impl/ios/mod.rs index 5d468371ca..6b58408690 100644 --- a/src/platform_impl/ios/mod.rs +++ b/src/platform_impl/ios/mod.rs @@ -81,6 +81,7 @@ use { WindowEvent, WindowId as RootEventId, }; +use error::{ExternalError, NotSupportedError}; use events::{Touch, TouchPhase}; use window::MonitorHandle as RootMonitorHandle; @@ -105,6 +106,8 @@ use self::ffi::{ static mut JMPBUF: Option> = None; +pub type OsError = std::io::Error; + pub struct Window { _events_queue: Arc>>, delegate_state: Box, @@ -385,13 +388,7 @@ impl Window { // N/A } - #[inline] - pub fn show(&self) { - // N/A - } - - #[inline] - pub fn hide(&self) { + pub fn set_visible(&self, _visible: bool) { // N/A } @@ -448,8 +445,8 @@ impl Window { } #[inline] - pub fn set_cursor_grab(&self, _grab: bool) -> Result<(), String> { - Err("Cursor grabbing is not possible on iOS.".to_owned()) + pub fn set_cursor_grab(&self, _grab: bool) -> Result<(), ExternalError> { + Err(NotSupportedError::new()) } #[inline] @@ -463,8 +460,8 @@ impl Window { } #[inline] - pub fn set_cursor_position(&self, _position: LogicalPosition) -> Result<(), String> { - Err("Setting cursor position is not possible on iOS.".to_owned()) + pub fn set_cursor_position(&self, _position: LogicalPosition) -> Result<(), ExternalError> { + Err(NotSupportedError::new()) } #[inline] diff --git a/src/platform_impl/linux/mod.rs b/src/platform_impl/linux/mod.rs index eef90e0f65..32a36ddadd 100644 --- a/src/platform_impl/linux/mod.rs +++ b/src/platform_impl/linux/mod.rs @@ -11,6 +11,7 @@ use sctk::reexports::client::ConnectError; use dpi::{LogicalPosition, LogicalSize, PhysicalPosition, PhysicalSize}; use icon::Icon; +use error::ExternalError; use event::Event; use event_loop::{EventLoopClosed, ControlFlow, EventLoopWindowTarget as RootELW}; use monitor::MonitorHandle as RootMonitorHandle; @@ -51,6 +52,11 @@ lazy_static!( }; ); +pub enum OsError { + XError(XError), + XMisc(&'static str), +} + pub enum Window { X(x11::Window), Wayland(wayland::Window), @@ -162,18 +168,10 @@ impl Window { } #[inline] - pub fn show(&self) { - match self { - &Window::X(ref w) => w.show(), - &Window::Wayland(ref w) => w.show(), - } - } - - #[inline] - pub fn hide(&self) { + pub fn set_visible(&self, visible: bool) { match self { - &Window::X(ref w) => w.hide(), - &Window::Wayland(ref w) => w.hide(), + &Window::X(ref w) => w.set_visible(visible), + &Window::Wayland(ref w) => w.set_visible(visible), } } @@ -258,7 +256,7 @@ impl Window { } #[inline] - pub fn set_cursor_grab(&self, grab: bool) -> Result<(), String> { + pub fn set_cursor_grab(&self, grab: bool) -> Result<(), ExternalError> { match self { &Window::X(ref window) => window.set_cursor_grab(grab), &Window::Wayland(ref window) => window.set_cursor_grab(grab), @@ -282,7 +280,7 @@ impl Window { } #[inline] - pub fn set_cursor_position(&self, position: LogicalPosition) -> Result<(), String> { + pub fn set_cursor_position(&self, position: LogicalPosition) -> Result<(), ExternalError> { match self { &Window::X(ref w) => w.set_cursor_position(position), &Window::Wayland(ref w) => w.set_cursor_position(position), diff --git a/src/platform_impl/linux/wayland/window.rs b/src/platform_impl/linux/wayland/window.rs index 962607c66a..8a56dc2a3f 100644 --- a/src/platform_impl/linux/wayland/window.rs +++ b/src/platform_impl/linux/wayland/window.rs @@ -2,6 +2,7 @@ use std::collections::VecDeque; use std::sync::{Arc, Mutex, Weak}; use dpi::{LogicalPosition, LogicalSize}; +use error::{ExternalError, NotSupportedError}; use platform_impl::{MonitorHandle as PlatformMonitorHandle, PlatformSpecificWindowBuilderAttributes as PlAttributes}; use monitor::MonitorHandle as RootMonitorHandle; use window::{CreationError, WindowAttributes, MouseCursor}; @@ -154,13 +155,7 @@ impl Window { self.frame.lock().unwrap().set_title(title.into()); } - #[inline] - pub fn show(&self) { - // TODO - } - - #[inline] - pub fn hide(&self) { + pub fn set_visible(&self, _visible: bool) { // TODO } @@ -275,13 +270,13 @@ impl Window { } #[inline] - pub fn set_cursor_grab(&self, _grab: bool) -> Result<(), String> { - Err("Cursor grabbing is not yet possible on Wayland.".to_owned()) + pub fn set_cursor_grab(&self, _grab: bool) -> Result<(), ExternalError> { + Err(ExternalError::NotSupported(NotSupportedError::new())) } #[inline] - pub fn set_cursor_position(&self, _pos: LogicalPosition) -> Result<(), String> { - Err("Setting the cursor position is not yet possible on Wayland.".to_owned()) + pub fn set_cursor_position(&self, _pos: LogicalPosition) -> Result<(), ExternalError> { + Err(ExternalError::NotSupported(NotSupportedError::new())) } pub fn get_display(&self) -> &Display { diff --git a/src/platform_impl/linux/x11/window.rs b/src/platform_impl/linux/x11/window.rs index 5e1af7d81a..0441b3757f 100644 --- a/src/platform_impl/linux/x11/window.rs +++ b/src/platform_impl/linux/x11/window.rs @@ -8,11 +8,12 @@ use std::sync::Arc; use libc; use parking_lot::Mutex; +use error::ExternalError; use window::{Icon, MouseCursor, WindowAttributes}; -use window::CreationError::{self, OsError}; +use window::CreationError; use dpi::{LogicalPosition, LogicalSize}; use platform_impl::MonitorHandle as PlatformMonitorHandle; -use platform_impl::PlatformSpecificWindowBuilderAttributes; +use platform_impl::{OsError, PlatformSpecificWindowBuilderAttributes}; use platform_impl::x11::MonitorHandle as X11MonitorHandle; use monitor::MonitorHandle as RootMonitorHandle; @@ -104,7 +105,7 @@ impl UnownedWindow { .unwrap_or(1.0) }) } else { - return Err(OsError(format!("No monitors were detected."))); + return Err(CreationError::OsError(format!("No monitors were detected."))); }; info!("Guessed window DPI factor: {}", dpi_factor); @@ -345,13 +346,13 @@ impl UnownedWindow { &mut supported_ptr, ); if supported_ptr == ffi::False { - return Err(OsError(format!("`XkbSetDetectableAutoRepeat` failed"))); + return Err(CreationError::OsError(format!("`XkbSetDetectableAutoRepeat` failed"))); } } // Select XInput2 events let mask = { - let mut mask = ffi::XI_MotionMask + let mask = ffi::XI_MotionMask | ffi::XI_ButtonPressMask | ffi::XI_ButtonReleaseMask //| ffi::XI_KeyPressMask @@ -372,7 +373,7 @@ impl UnownedWindow { .borrow_mut() .create_context(window.xwindow); if let Err(err) = result { - return Err(OsError(format!("Failed to create input context: {:?}", err))); + return Err(CreationError::OsError(format!("Failed to create input context: {:?}", err))); } } @@ -411,7 +412,7 @@ impl UnownedWindow { // We never want to give the user a broken window, since by then, it's too late to handle. xconn.sync_with_server() .map(|_| window) - .map_err(|x_err| OsError( + .map_err(|x_err| CreationError::OsError( format!("X server returned error while building window: {:?}", x_err) )) } @@ -698,20 +699,18 @@ impl UnownedWindow { } #[inline] - pub fn show(&self) { - unsafe { - (self.xconn.xlib.XMapRaised)(self.xconn.display, self.xwindow); - self.xconn.flush_requests() - .expect("Failed to call XMapRaised"); - } - } - - #[inline] - pub fn hide(&self) { - unsafe { - (self.xconn.xlib.XUnmapWindow)(self.xconn.display, self.xwindow); - self.xconn.flush_requests() - .expect("Failed to call XUnmapWindow"); + pub fn set_visible(&self, visible: bool) { + match visible { + true => unsafe { + (self.xconn.xlib.XMapRaised)(self.xconn.display, self.xwindow); + self.xconn.flush_requests() + .expect("Failed to call XMapRaised"); + }, + false => unsafe { + (self.xconn.xlib.XUnmapWindow)(self.xconn.display, self.xwindow); + self.xconn.flush_requests() + .expect("Failed to call XUnmapWindow"); + } } } @@ -1113,7 +1112,7 @@ impl UnownedWindow { } #[inline] - pub fn set_cursor_grab(&self, grab: bool) -> Result<(), String> { + pub fn set_cursor_grab(&self, grab: bool) -> Result<(), ExternalError> { let mut grabbed_lock = self.cursor_grabbed.lock(); if grab == *grabbed_lock { return Ok(()); } unsafe { @@ -1157,10 +1156,10 @@ impl UnownedWindow { ffi::GrabNotViewable => Err("Cursor could not be grabbed: grab location not viewable"), ffi::GrabFrozen => Err("Cursor could not be grabbed: frozen by another client"), _ => unreachable!(), - }.map_err(|err| err.to_owned()) + }.map_err(|err| ExternalError::Os(os_error!(OsError::XMisc(err)))) } else { self.xconn.flush_requests() - .map_err(|err| format!("Failed to call `XUngrabPointer`: {:?}", err)) + .map_err(|err| ExternalError::Os(os_error!(OsError::XError(err)))) }; if result.is_ok() { *grabbed_lock = grab; @@ -1187,7 +1186,7 @@ impl UnownedWindow { self.get_current_monitor().hidpi_factor } - pub fn set_cursor_position_physical(&self, x: i32, y: i32) -> Result<(), String> { + pub fn set_cursor_position_physical(&self, x: i32, y: i32) -> Result<(), ExternalError> { unsafe { (self.xconn.xlib.XWarpPointer)( self.xconn.display, @@ -1200,12 +1199,12 @@ impl UnownedWindow { x, y, ); - self.xconn.flush_requests().map_err(|e| format!("`XWarpPointer` failed: {:?}", e)) + self.xconn.flush_requests().map_err(|e| ExternalError::Os(os_error!(OsError::XError(e)))) } } #[inline] - pub fn set_cursor_position(&self, logical_position: LogicalPosition) -> Result<(), String> { + pub fn set_cursor_position(&self, logical_position: LogicalPosition) -> Result<(), ExternalError> { let (x, y) = logical_position.to_physical(self.get_hidpi_factor()).into(); self.set_cursor_position_physical(x, y) } diff --git a/src/platform_impl/macos/mod.rs b/src/platform_impl/macos/mod.rs index 0e04d369aa..2765d8e44d 100644 --- a/src/platform_impl/macos/mod.rs +++ b/src/platform_impl/macos/mod.rs @@ -44,6 +44,10 @@ pub struct Window { _delegate: util::IdRef, } +pub enum OsError { + CGError(core_graphics::base::CGError), +} + unsafe impl Send for Window {} unsafe impl Sync for Window {} diff --git a/src/platform_impl/macos/window.rs b/src/platform_impl/macos/window.rs index cd11c1d7d4..58a059ef78 100644 --- a/src/platform_impl/macos/window.rs +++ b/src/platform_impl/macos/window.rs @@ -17,6 +17,7 @@ use objc::{runtime::{Class, Object, Sel, BOOL, YES, NO}, declare::ClassDecl}; use { dpi::{LogicalPosition, LogicalSize}, icon::Icon, + error::ExternalError, monitor::MonitorHandle as RootMonitorHandle, window::{ CreationError, MouseCursor, WindowAttributes, WindowId as RootWindowId, @@ -24,6 +25,7 @@ use { }; use platform::macos::{ActivationPolicy, WindowExtMacOS}; use platform_impl::platform::{ + OsError, app_state::AppState, ffi, monitor::{self, MonitorHandle}, util::{self, IdRef}, view::{self, new_view}, window_delegate::new_delegate, @@ -381,14 +383,11 @@ impl UnownedWindow { } } - #[inline] - pub fn show(&self) { - unsafe { util::make_key_and_order_front_async(*self.nswindow) }; - } - - #[inline] - pub fn hide(&self) { - unsafe { util::order_out_async(*self.nswindow) }; + pub fn set_visible(&self, visible: bool) { + match visible { + true => unsafe { util::make_key_and_order_front_async(*self.nswindow) }, + false => unsafe { util::order_out_async(*self.nswindow) }, + } } pub fn request_redraw(&self) { @@ -497,10 +496,10 @@ impl UnownedWindow { } #[inline] - pub fn set_cursor_grab(&self, grab: bool) -> Result<(), String> { + pub fn set_cursor_grab(&self, grab: bool) -> Result<(), ExternalError> { // TODO: Do this for real https://stackoverflow.com/a/40922095/5435443 CGDisplay::associate_mouse_and_mouse_cursor_position(!grab) - .map_err(|status| format!("Failed to grab cursor: `CGError` {:?}", status)) + .map_err(|status| ExternalError::Os(os_error!(OsError::CGError(status)))) } #[inline] @@ -524,17 +523,16 @@ impl UnownedWindow { } #[inline] - pub fn set_cursor_position(&self, cursor_position: LogicalPosition) -> Result<(), String> { - let window_position = self.get_inner_position() - .ok_or("`get_inner_position` failed".to_owned())?; + pub fn set_cursor_position(&self, cursor_position: LogicalPosition) -> Result<(), ExternalError> { + let window_position = self.get_inner_position().unwrap(); let point = appkit::CGPoint { x: (cursor_position.x + window_position.x) as CGFloat, y: (cursor_position.y + window_position.y) as CGFloat, }; CGDisplay::warp_mouse_cursor_position(point) - .map_err(|e| format!("`CGWarpMouseCursorPosition` failed: {:?}", e))?; + .map_err(|e| ExternalError::Os(os_error!(OsError::CGError(e))))?; CGDisplay::associate_mouse_and_mouse_cursor_position(true) - .map_err(|e| format!("`CGAssociateMouseAndMouseCursorPosition` failed: {:?}", e))?; + .map_err(|e| ExternalError::Os(os_error!(OsError::CGError(e))))?; Ok(()) } diff --git a/src/platform_impl/windows/mod.rs b/src/platform_impl/windows/mod.rs index 855dd6675b..14e9b8e530 100644 --- a/src/platform_impl/windows/mod.rs +++ b/src/platform_impl/windows/mod.rs @@ -52,6 +52,8 @@ fn wrap_device_id(id: u32) -> RootDeviceId { RootDeviceId(DeviceId(id)) } +pub type OsError = std::io::Error; + #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct WindowId(HWND); unsafe impl Send for WindowId {} diff --git a/src/platform_impl/windows/window.rs b/src/platform_impl/windows/window.rs index 6e2c634b27..1fd2b2c233 100644 --- a/src/platform_impl/windows/window.rs +++ b/src/platform_impl/windows/window.rs @@ -19,6 +19,7 @@ use winapi::um::oleidl::LPDROPTARGET; use winapi::um::winnt::{LONG, LPCWSTR}; use window::{CreationError, Icon, MouseCursor, WindowAttributes}; +use error::ExternalError; use dpi::{LogicalPosition, LogicalSize, PhysicalSize}; use monitor::MonitorHandle as RootMonitorHandle; use platform_impl::platform::{ @@ -319,7 +320,7 @@ impl Window { } #[inline] - pub fn set_cursor_grab(&self, grab: bool) -> Result<(), String> { + pub fn set_cursor_grab(&self, grab: bool) -> Result<(), ExternalError> { let window = self.window.clone(); let window_state = Arc::clone(&self.window_state); let (tx, rx) = channel(); @@ -327,7 +328,7 @@ impl Window { self.thread_executor.execute_in_thread(move || { let result = window_state.lock().mouse .set_cursor_flags(window.0, |f| f.set(CursorFlags::GRABBED, grab)) - .map_err(|e| e.to_string()); + .map_err(|e| ExternalError::Os(os_error!(e))); let _ = tx.send(result); }); rx.recv().unwrap() @@ -353,21 +354,21 @@ impl Window { self.window_state.lock().dpi_factor } - fn set_cursor_position_physical(&self, x: i32, y: i32) -> Result<(), String> { + fn set_cursor_position_physical(&self, x: i32, y: i32) -> Result<(), ExternalError> { let mut point = POINT { x, y }; unsafe { if winuser::ClientToScreen(self.window.0, &mut point) == 0 { - return Err("`ClientToScreen` failed".to_owned()); + return Err(ExternalError::Os(os_error!(io::Error::last_os_error()))); } if winuser::SetCursorPos(point.x, point.y) == 0 { - return Err("`SetCursorPos` failed".to_owned()); + return Err(ExternalError::Os(os_error!(io::Error::last_os_error()))); } } Ok(()) } #[inline] - pub fn set_cursor_position(&self, logical_position: LogicalPosition) -> Result<(), String> { + pub fn set_cursor_position(&self, logical_position: LogicalPosition) -> Result<(), ExternalError> { let dpi_factor = self.get_hidpi_factor(); let (x, y) = logical_position.to_physical(dpi_factor).into(); self.set_cursor_position_physical(x, y) diff --git a/src/window.rs b/src/window.rs index c407ae4222..0f86c5691f 100644 --- a/src/window.rs +++ b/src/window.rs @@ -2,6 +2,7 @@ use std::{fmt, error}; use platform_impl; +use error::ExternalError; use event_loop::EventLoopWindowTarget; use monitor::{AvailableMonitorsIter, MonitorHandle}; use dpi::{LogicalPosition, LogicalSize}; @@ -468,7 +469,7 @@ impl Window { /// Changes the position of the cursor in window coordinates. #[inline] - pub fn set_cursor_position(&self, position: LogicalPosition) -> Result<(), String> { + pub fn set_cursor_position(&self, position: LogicalPosition) -> Result<(), ExternalError> { self.window.set_cursor_position(position) } @@ -480,7 +481,7 @@ impl Window { /// /// This has no effect on Android or iOS. #[inline] - pub fn set_cursor_grab(&self, grab: bool) -> Result<(), String> { + pub fn set_cursor_grab(&self, grab: bool) -> Result<(), ExternalError> { self.window.set_cursor_grab(grab) } From 3e7d6222674e733da48ee5ecb856971c0f1215c8 Mon Sep 17 00:00:00 2001 From: Osspial Date: Wed, 22 May 2019 17:16:38 -0400 Subject: [PATCH 05/22] Remove `get_` prefix from getters. This is as per the Rust naming conventions recommended in https://rust-lang-nursery.github.io/api-guidelines/naming.html#getter-names-follow-rust-convention-c-getter --- examples/fullscreen.rs | 14 +-- examples/monitor_list.rs | 2 +- examples/multithreaded.rs | 12 +-- src/dpi.rs | 6 +- src/event_loop.rs | 8 +- src/monitor.rs | 32 +++--- src/platform/android.rs | 6 +- src/platform/ios.rs | 18 ++-- src/platform/macos.rs | 26 ++--- src/platform/unix.rs | 54 +++++----- src/platform/windows.rs | 14 +-- src/platform_impl/android/mod.rs | 60 +++++------ src/platform_impl/emscripten/mod.rs | 46 ++++---- src/platform_impl/ios/mod.rs | 52 ++++----- src/platform_impl/linux/mod.rs | 94 ++++++++-------- src/platform_impl/linux/wayland/event_loop.rs | 34 +++--- src/platform_impl/linux/wayland/window.rs | 28 ++--- .../linux/x11/event_processor.rs | 16 +-- src/platform_impl/linux/x11/monitor.rs | 20 ++-- src/platform_impl/linux/x11/util/geometry.rs | 4 +- src/platform_impl/linux/x11/util/randr.rs | 6 +- src/platform_impl/linux/x11/window.rs | 100 +++++++++--------- src/platform_impl/macos/event_loop.rs | 8 +- src/platform_impl/macos/monitor.rs | 36 +++---- src/platform_impl/macos/window.rs | 34 +++--- src/platform_impl/macos/window_delegate.rs | 4 +- src/platform_impl/windows/dpi.rs | 6 +- src/platform_impl/windows/event_loop.rs | 10 +- src/platform_impl/windows/mod.rs | 2 +- src/platform_impl/windows/monitor.rs | 34 +++--- src/platform_impl/windows/window.rs | 70 ++++++------ src/window.rs | 50 ++++----- 32 files changed, 453 insertions(+), 453 deletions(-) diff --git a/examples/fullscreen.rs b/examples/fullscreen.rs index e178ed1ec0..8827751f19 100644 --- a/examples/fullscreen.rs +++ b/examples/fullscreen.rs @@ -82,16 +82,16 @@ fn main() { if !is_fullscreen { window.set_fullscreen(None); } else { - window.set_fullscreen(Some(window.get_current_monitor())); + window.set_fullscreen(Some(window.current_monitor())); } } (VirtualKeyCode::S, ElementState::Pressed) => { - println!("window.get_fullscreen {:?}", window.get_fullscreen()); + println!("window.fullscreen {:?}", window.fullscreen()); #[cfg(target_os = "macos")] { use winit::platform::macos::WindowExtMacOS; - println!("window.get_simple_fullscreen {:?}", WindowExtMacOS::get_simple_fullscreen(&window)); + println!("window.simple_fullscreen {:?}", WindowExtMacOS::simple_fullscreen(&window)); } } (VirtualKeyCode::M, ElementState::Pressed) => { @@ -113,8 +113,8 @@ fn main() { // Enumerate monitors and prompt user to choose one fn prompt_for_monitor(event_loop: &EventLoop<()>) -> MonitorHandle { - for (num, monitor) in event_loop.get_available_monitors().enumerate() { - println!("Monitor #{}: {:?}", num, monitor.get_name()); + for (num, monitor) in event_loop.available_monitors().enumerate() { + println!("Monitor #{}: {:?}", num, monitor.name()); } print!("Please write the number of the monitor to use: "); @@ -123,9 +123,9 @@ fn prompt_for_monitor(event_loop: &EventLoop<()>) -> MonitorHandle { let mut num = String::new(); io::stdin().read_line(&mut num).unwrap(); let num = num.trim().parse().ok().expect("Please enter a number"); - let monitor = event_loop.get_available_monitors().nth(num).expect("Please enter a valid ID"); + let monitor = event_loop.available_monitors().nth(num).expect("Please enter a valid ID"); - println!("Using {:?}", monitor.get_name()); + println!("Using {:?}", monitor.name()); monitor } diff --git a/examples/monitor_list.rs b/examples/monitor_list.rs index 335aa02281..42e683bf23 100644 --- a/examples/monitor_list.rs +++ b/examples/monitor_list.rs @@ -5,5 +5,5 @@ use winit::window::WindowBuilder; fn main() { let event_loop = EventLoop::new(); let window = WindowBuilder::new().build(&event_loop).unwrap(); - println!("{:#?}\nPrimary: {:#?}", window.get_available_monitors(), window.get_primary_monitor()); + println!("{:#?}\nPrimary: {:#?}", window.available_monitors(), window.primary_monitor()); } diff --git a/examples/multithreaded.rs b/examples/multithreaded.rs index 776ab42a4d..5bfba334cc 100644 --- a/examples/multithreaded.rs +++ b/examples/multithreaded.rs @@ -42,17 +42,17 @@ fn main() { }), D => window.set_decorations(!state), F => window.set_fullscreen(match state { - true => Some(window.get_current_monitor()), + true => Some(window.current_monitor()), false => None, }), G => window.set_cursor_grab(state).unwrap(), H => window.set_cursor_visible(!state), I => { println!("Info:"); - println!("-> outer_position : {:?}", window.get_outer_position()); - println!("-> inner_position : {:?}", window.get_inner_position()); - println!("-> outer_size : {:?}", window.get_outer_size()); - println!("-> inner_size : {:?}", window.get_inner_size()); + println!("-> outer_position : {:?}", window.outer_position()); + println!("-> inner_position : {:?}", window.inner_position()); + println!("-> outer_size : {:?}", window.outer_size()); + println!("-> inner_size : {:?}", window.inner_size()); }, L => window.set_min_inner_size(match state { true => Some(WINDOW_SIZE.into()), @@ -60,7 +60,7 @@ fn main() { }), M => window.set_maximized(state), P => window.set_outer_position({ - let mut position = window.get_outer_position().unwrap(); + let mut position = window.outer_position().unwrap(); let sign = if state { 1.0 } else { -1.0 }; position.x += 10.0 * sign; position.y += 10.0 * sign; diff --git a/src/dpi.rs b/src/dpi.rs index cae9b4012c..afd1cbfd0b 100644 --- a/src/dpi.rs +++ b/src/dpi.rs @@ -33,10 +33,10 @@ //! windows. This event is sent any time the DPI factor changes, either because the window moved to another monitor, //! or because the user changed the configuration of their screen. //! - You can also retrieve the DPI factor of a monitor by calling -//! [`MonitorHandle::get_hidpi_factor`](../monitor/struct.MonitorHandle.html#method.get_hidpi_factor), or the +//! [`MonitorHandle::hidpi_factor`](../monitor/struct.MonitorHandle.html#method.hidpi_factor), or the //! current DPI factor applied to a window by calling -//! [`Window::get_hidpi_factor`](../window/struct.Window.html#method.get_hidpi_factor), which is roughly equivalent -//! to `window.get_current_monitor().get_hidpi_factor()`. +//! [`Window::hidpi_factor`](../window/struct.Window.html#method.hidpi_factor), which is roughly equivalent +//! to `window.current_monitor().hidpi_factor()`. //! //! Depending on the platform, the window's actual DPI factor may only be known after //! the event loop has started and your window has been drawn once. To properly handle these cases, diff --git a/src/event_loop.rs b/src/event_loop.rs index ab6839cdc6..4314a0258d 100644 --- a/src/event_loop.rs +++ b/src/event_loop.rs @@ -117,15 +117,15 @@ impl EventLoop { /// // Note: should be replaced with `-> impl Iterator` once stable. #[inline] - pub fn get_available_monitors(&self) -> AvailableMonitorsIter { - let data = self.event_loop.get_available_monitors(); + pub fn available_monitors(&self) -> AvailableMonitorsIter { + let data = self.event_loop.available_monitors(); AvailableMonitorsIter{ data: data.into_iter() } } /// Returns the primary monitor of the system. #[inline] - pub fn get_primary_monitor(&self) -> MonitorHandle { - MonitorHandle { inner: self.event_loop.get_primary_monitor() } + pub fn primary_monitor(&self) -> MonitorHandle { + MonitorHandle { inner: self.event_loop.primary_monitor() } } /// Hijacks the calling thread and initializes the `winit` event loop with the provided diff --git a/src/monitor.rs b/src/monitor.rs index 6a6eb00005..a74d29c192 100644 --- a/src/monitor.rs +++ b/src/monitor.rs @@ -3,13 +3,13 @@ //! If you want to get basic information about a monitor, you can use the [`MonitorHandle`][monitor_id] //! type. This is retreived from an [`AvailableMonitorsIter`][monitor_iter], which can be acquired //! with: -//! - [`EventLoop::get_available_monitors`][loop_get] -//! - [`Window::get_available_monitors`][window_get]. +//! - [`EventLoop::available_monitors`][loop_get] +//! - [`Window::available_monitors`][window_get]. //! //! [monitor_id]: ./struct.MonitorHandle.html //! [monitor_iter]: ./struct.AvailableMonitorsIter.html -//! [loop_get]: ../event_loop/struct.EventLoop.html#method.get_available_monitors -//! [window_get]: ../window/struct.Window.html#method.get_available_monitors +//! [loop_get]: ../event_loop/struct.EventLoop.html#method.available_monitors +//! [window_get]: ../window/struct.Window.html#method.available_monitors use std::collections::vec_deque::IntoIter as VecDequeIter; use platform_impl; @@ -18,11 +18,11 @@ use dpi::{PhysicalPosition, PhysicalSize}; /// An iterator over all available monitors. /// /// Can be acquired with: -/// - [`EventLoop::get_available_monitors`][loop_get] -/// - [`Window::get_available_monitors`][window_get]. +/// - [`EventLoop::available_monitors`][loop_get] +/// - [`Window::available_monitors`][window_get]. /// -/// [loop_get]: ../event_loop/struct.EventLoop.html#method.get_available_monitors -/// [window_get]: ../window/struct.Window.html#method.get_available_monitors +/// [loop_get]: ../event_loop/struct.EventLoop.html#method.available_monitors +/// [window_get]: ../window/struct.Window.html#method.available_monitors // Implementation note: we retrieve the list once, then serve each element by one by one. // This may change in the future. #[derive(Debug)] @@ -59,21 +59,21 @@ impl MonitorHandle { /// /// Returns `None` if the monitor doesn't exist anymore. #[inline] - pub fn get_name(&self) -> Option { - self.inner.get_name() + pub fn name(&self) -> Option { + self.inner.name() } /// Returns the monitor's resolution. #[inline] - pub fn get_dimensions(&self) -> PhysicalSize { - self.inner.get_dimensions() + pub fn dimensions(&self) -> PhysicalSize { + self.inner.dimensions() } /// Returns the top-left corner position of the monitor relative to the larger full /// screen area. #[inline] - pub fn get_outer_position(&self) -> PhysicalPosition { - self.inner.get_outer_position() + pub fn outer_position(&self) -> PhysicalPosition { + self.inner.outer_position() } /// Returns the DPI factor that can be used to map logical pixels to physical pixels, and vice versa. @@ -85,7 +85,7 @@ impl MonitorHandle { /// - **X11:** Can be overridden using the `WINIT_HIDPI_FACTOR` environment variable. /// - **Android:** Always returns 1.0. #[inline] - pub fn get_hidpi_factor(&self) -> f64 { - self.inner.get_hidpi_factor() + pub fn hidpi_factor(&self) -> f64 { + self.inner.hidpi_factor() } } diff --git a/src/platform/android.rs b/src/platform/android.rs index 37ee0e1d4b..82a7345361 100644 --- a/src/platform/android.rs +++ b/src/platform/android.rs @@ -19,13 +19,13 @@ impl EventLoopExtAndroid for EventLoop { /// Additional methods on `Window` that are specific to Android. pub trait WindowExtAndroid { - fn get_native_window(&self) -> *const c_void; + fn native_window(&self) -> *const c_void; } impl WindowExtAndroid for Window { #[inline] - fn get_native_window(&self) -> *const c_void { - self.window.get_native_window() + fn native_window(&self) -> *const c_void { + self.window.native_window() } } diff --git a/src/platform/ios.rs b/src/platform/ios.rs index 7a2345b044..c66ba327bd 100644 --- a/src/platform/ios.rs +++ b/src/platform/ios.rs @@ -9,23 +9,23 @@ pub trait WindowExtIOS { /// Returns a pointer to the `UIWindow` that is used by this window. /// /// The pointer will become invalid when the `Window` is destroyed. - fn get_uiwindow(&self) -> *mut c_void; + fn uiwindow(&self) -> *mut c_void; /// Returns a pointer to the `UIView` that is used by this window. /// /// The pointer will become invalid when the `Window` is destroyed. - fn get_uiview(&self) -> *mut c_void; + fn uiview(&self) -> *mut c_void; } impl WindowExtIOS for Window { #[inline] - fn get_uiwindow(&self) -> *mut c_void { - self.window.get_uiwindow() as _ + fn uiwindow(&self) -> *mut c_void { + self.window.uiwindow() as _ } #[inline] - fn get_uiview(&self) -> *mut c_void { - self.window.get_uiview() as _ + fn uiview(&self) -> *mut c_void { + self.window.uiview() as _ } } @@ -48,12 +48,12 @@ impl WindowBuilderExtIOS for WindowBuilder { /// Additional methods on `MonitorHandle` that are specific to iOS. pub trait MonitorHandleExtIOS { /// Returns a pointer to the `UIScreen` that is used by this monitor. - fn get_uiscreen(&self) -> *mut c_void; + fn uiscreen(&self) -> *mut c_void; } impl MonitorHandleExtIOS for MonitorHandle { #[inline] - fn get_uiscreen(&self) -> *mut c_void { - self.inner.get_uiscreen() as _ + fn uiscreen(&self) -> *mut c_void { + self.inner.uiscreen() as _ } } diff --git a/src/platform/macos.rs b/src/platform/macos.rs index ff09afa42c..3162b6efc2 100644 --- a/src/platform/macos.rs +++ b/src/platform/macos.rs @@ -11,12 +11,12 @@ pub trait WindowExtMacOS { /// Returns a pointer to the cocoa `NSWindow` that is used by this window. /// /// The pointer will become invalid when the `Window` is destroyed. - fn get_nswindow(&self) -> *mut c_void; + fn nswindow(&self) -> *mut c_void; /// Returns a pointer to the cocoa `NSView` that is used by this window. /// /// The pointer will become invalid when the `Window` is destroyed. - fn get_nsview(&self) -> *mut c_void; + fn nsview(&self) -> *mut c_void; /// Request user attention, causing the application's dock icon to bounce. /// Note that this has no effect if the application is already focused. @@ -27,7 +27,7 @@ pub trait WindowExtMacOS { fn request_user_attention(&self, is_critical: bool); /// Returns whether or not the window is in simple fullscreen mode. - fn get_simple_fullscreen(&self) -> bool; + fn simple_fullscreen(&self) -> bool; /// Toggles a fullscreen mode that doesn't require a new macOS space. /// Returns a boolean indicating whether the transition was successful (this @@ -41,13 +41,13 @@ pub trait WindowExtMacOS { impl WindowExtMacOS for Window { #[inline] - fn get_nswindow(&self) -> *mut c_void { - self.window.get_nswindow() + fn nswindow(&self) -> *mut c_void { + self.window.nswindow() } #[inline] - fn get_nsview(&self) -> *mut c_void { - self.window.get_nsview() + fn nsview(&self) -> *mut c_void { + self.window.nsview() } #[inline] @@ -56,8 +56,8 @@ impl WindowExtMacOS for Window { } #[inline] - fn get_simple_fullscreen(&self) -> bool { - self.window.get_simple_fullscreen() + fn simple_fullscreen(&self) -> bool { + self.window.simple_fullscreen() } #[inline] @@ -167,16 +167,16 @@ pub trait MonitorHandleExtMacOS { /// Returns the identifier of the monitor for Cocoa. fn native_id(&self) -> u32; /// Returns a pointer to the NSScreen representing this monitor. - fn get_nsscreen(&self) -> Option<*mut c_void>; + fn nsscreen(&self) -> Option<*mut c_void>; } impl MonitorHandleExtMacOS for MonitorHandle { #[inline] fn native_id(&self) -> u32 { - self.inner.get_native_identifier() + self.inner.native_identifier() } - fn get_nsscreen(&self) -> Option<*mut c_void> { - self.inner.get_nsscreen().map(|s| s as *mut c_void) + fn nsscreen(&self) -> Option<*mut c_void> { + self.inner.nsscreen().map(|s| s as *mut c_void) } } diff --git a/src/platform/unix.rs b/src/platform/unix.rs index df7d0100e1..5f212fdf48 100644 --- a/src/platform/unix.rs +++ b/src/platform/unix.rs @@ -110,14 +110,14 @@ pub trait EventLoopExtUnix { fn is_x11(&self) -> bool; #[doc(hidden)] - fn get_xlib_xconnection(&self) -> Option>; + fn xlib_xconnection(&self) -> Option>; /// Returns a pointer to the `wl_display` object of wayland that is used by this `EventLoop`. /// /// Returns `None` if the `EventLoop` doesn't use wayland (if it uses xlib for example). /// /// The pointer will become invalid when the glutin `EventLoop` is destroyed. - fn get_wayland_display(&self) -> Option<*mut raw::c_void>; + fn wayland_display(&self) -> Option<*mut raw::c_void>; } impl EventLoopExtUnix for EventLoop { @@ -154,7 +154,7 @@ impl EventLoopExtUnix for EventLoop { #[inline] #[doc(hidden)] - fn get_xlib_xconnection(&self) -> Option> { + fn xlib_xconnection(&self) -> Option> { match self.event_loop { LinuxEventLoop::X(ref e) => Some(e.x_connection().clone()), _ => None @@ -162,9 +162,9 @@ impl EventLoopExtUnix for EventLoop { } #[inline] - fn get_wayland_display(&self) -> Option<*mut raw::c_void> { + fn wayland_display(&self) -> Option<*mut raw::c_void> { match self.event_loop { - LinuxEventLoop::Wayland(ref e) => Some(e.get_display().get_display_ptr() as *mut _), + LinuxEventLoop::Wayland(ref e) => Some(e.display().get_display_ptr() as *mut _), _ => None } } @@ -175,19 +175,19 @@ pub trait WindowExtUnix { /// Returns the ID of the `Window` xlib object that is used by this window. /// /// Returns `None` if the window doesn't use xlib (if it uses wayland for example). - fn get_xlib_window(&self) -> Option; + fn xlib_window(&self) -> Option; /// 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 raw::c_void>; + fn xlib_display(&self) -> Option<*mut raw::c_void>; - fn get_xlib_screen_id(&self) -> Option; + fn xlib_screen_id(&self) -> Option; #[doc(hidden)] - fn get_xlib_xconnection(&self) -> Option>; + fn xlib_xconnection(&self) -> Option>; /// Set window urgency hint (`XUrgencyHint`). Only relevant on X. fn set_urgent(&self, is_urgent: bool); @@ -197,21 +197,21 @@ pub trait WindowExtUnix { /// 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_xcb_connection(&self) -> Option<*mut raw::c_void>; + fn xcb_connection(&self) -> Option<*mut raw::c_void>; /// Returns a pointer to the `wl_surface` object of wayland that is used by this window. /// /// Returns `None` if the window doesn't use wayland (if it uses xlib for example). /// /// The pointer will become invalid when the glutin `Window` is destroyed. - fn get_wayland_surface(&self) -> Option<*mut raw::c_void>; + fn wayland_surface(&self) -> Option<*mut raw::c_void>; /// Returns a pointer to the `wl_display` object of wayland that is used by this window. /// /// Returns `None` if the window doesn't use wayland (if it uses xlib for example). /// /// The pointer will become invalid when the glutin `Window` is destroyed. - fn get_wayland_display(&self) -> Option<*mut raw::c_void>; + fn wayland_display(&self) -> Option<*mut raw::c_void>; /// Sets the color theme of the client side window decorations on wayland fn set_wayland_theme(&self, theme: WaylandTheme); @@ -228,42 +228,42 @@ pub trait WindowExtUnix { impl WindowExtUnix for Window { #[inline] - fn get_xlib_window(&self) -> Option { + fn xlib_window(&self) -> Option { match self.window { - LinuxWindow::X(ref w) => Some(w.get_xlib_window()), + LinuxWindow::X(ref w) => Some(w.xlib_window()), _ => None } } #[inline] - fn get_xlib_display(&self) -> Option<*mut raw::c_void> { + fn xlib_display(&self) -> Option<*mut raw::c_void> { match self.window { - LinuxWindow::X(ref w) => Some(w.get_xlib_display()), + LinuxWindow::X(ref w) => Some(w.xlib_display()), _ => None } } #[inline] - fn get_xlib_screen_id(&self) -> Option { + fn xlib_screen_id(&self) -> Option { match self.window { - LinuxWindow::X(ref w) => Some(w.get_xlib_screen_id()), + LinuxWindow::X(ref w) => Some(w.xlib_screen_id()), _ => None } } #[inline] #[doc(hidden)] - fn get_xlib_xconnection(&self) -> Option> { + fn xlib_xconnection(&self) -> Option> { match self.window { - LinuxWindow::X(ref w) => Some(w.get_xlib_xconnection()), + LinuxWindow::X(ref w) => Some(w.xlib_xconnection()), _ => None } } #[inline] - fn get_xcb_connection(&self) -> Option<*mut raw::c_void> { + fn xcb_connection(&self) -> Option<*mut raw::c_void> { match self.window { - LinuxWindow::X(ref w) => Some(w.get_xcb_connection()), + LinuxWindow::X(ref w) => Some(w.xcb_connection()), _ => None } } @@ -276,17 +276,17 @@ impl WindowExtUnix for Window { } #[inline] - fn get_wayland_surface(&self) -> Option<*mut raw::c_void> { + fn wayland_surface(&self) -> Option<*mut raw::c_void> { match self.window { - LinuxWindow::Wayland(ref w) => Some(w.get_surface().as_ref().c_ptr() as *mut _), + LinuxWindow::Wayland(ref w) => Some(w.surface().as_ref().c_ptr() as *mut _), _ => None } } #[inline] - fn get_wayland_display(&self) -> Option<*mut raw::c_void> { + fn wayland_display(&self) -> Option<*mut raw::c_void> { match self.window { - LinuxWindow::Wayland(ref w) => Some(w.get_display().as_ref().c_ptr() as *mut _), + LinuxWindow::Wayland(ref w) => Some(w.display().as_ref().c_ptr() as *mut _), _ => None } } @@ -398,6 +398,6 @@ pub trait MonitorHandleExtUnix { impl MonitorHandleExtUnix for MonitorHandle { #[inline] fn native_id(&self) -> u32 { - self.inner.get_native_identifier() + self.inner.native_identifier() } } diff --git a/src/platform/windows.rs b/src/platform/windows.rs index 7a9de6880a..9f47365c84 100644 --- a/src/platform/windows.rs +++ b/src/platform/windows.rs @@ -33,7 +33,7 @@ pub trait WindowExtWindows { /// Returns the native handle that is used by this window. /// /// The pointer will become invalid when the native window was destroyed. - fn get_hwnd(&self) -> *mut libc::c_void; + fn hwnd(&self) -> *mut libc::c_void; /// This sets `ICON_BIG`. A good ceiling here is 256x256. fn set_taskbar_icon(&self, taskbar_icon: Option); @@ -41,7 +41,7 @@ pub trait WindowExtWindows { impl WindowExtWindows for Window { #[inline] - fn get_hwnd(&self) -> *mut libc::c_void { + fn hwnd(&self) -> *mut libc::c_void { self.window.hwnd() as *mut _ } @@ -95,12 +95,12 @@ pub trait MonitorHandleExtWindows { impl MonitorHandleExtWindows for MonitorHandle { #[inline] fn native_id(&self) -> String { - self.inner.get_native_identifier() + self.inner.native_identifier() } #[inline] fn hmonitor(&self) -> *mut c_void { - self.inner.get_hmonitor() as *mut _ + self.inner.hmonitor() as *mut _ } } @@ -109,12 +109,12 @@ pub trait DeviceIdExtWindows { /// Returns an identifier that persistently refers to this specific device. /// /// Will return `None` if the device is no longer available. - fn get_persistent_identifier(&self) -> Option; + fn persistent_identifier(&self) -> Option; } impl DeviceIdExtWindows for DeviceId { #[inline] - fn get_persistent_identifier(&self) -> Option { - self.0.get_persistent_identifier() + fn persistent_identifier(&self) -> Option { + self.0.persistent_identifier() } } diff --git a/src/platform_impl/android/mod.rs b/src/platform_impl/android/mod.rs index f94fe1a760..7040f848d5 100644 --- a/src/platform_impl/android/mod.rs +++ b/src/platform_impl/android/mod.rs @@ -48,14 +48,14 @@ impl EventLoop { } #[inline] - pub fn get_available_monitors(&self) -> VecDeque { + pub fn available_monitors(&self) -> VecDeque { let mut rb = VecDeque::with_capacity(1); rb.push_back(MonitorHandle); rb } #[inline] - pub fn get_primary_monitor(&self) -> MonitorHandle { + pub fn primary_monitor(&self) -> MonitorHandle { MonitorHandle } @@ -65,7 +65,7 @@ impl EventLoop { while let Ok(event) = self.event_rx.try_recv() { let e = match event{ android_glue::Event::EventMotion(motion) => { - let dpi_factor = MonitorHandle.get_hidpi_factor(); + let dpi_factor = MonitorHandle.hidpi_factor(); let location = LogicalPosition::from_physical( (motion.x as f64, motion.y as f64), dpi_factor, @@ -102,12 +102,12 @@ impl EventLoop { android_glue::Event::WindowResized | android_glue::Event::ConfigChanged => { // Activity Orientation changed or resized. - let native_window = unsafe { android_glue::get_native_window() }; + let native_window = unsafe { android_glue::native_window() }; if native_window.is_null() { None } else { - let dpi_factor = MonitorHandle.get_hidpi_factor(); - let physical_size = MonitorHandle.get_dimensions(); + let dpi_factor = MonitorHandle.hidpi_factor(); + let physical_size = MonitorHandle.dimensions(); let size = LogicalSize::from_physical(physical_size, dpi_factor); Some(Event::WindowEvent { window_id: RootWindowId(WindowId), @@ -206,10 +206,10 @@ impl fmt::Debug for MonitorHandle { } let monitor_id_proxy = MonitorHandle { - name: self.get_name(), - dimensions: self.get_dimensions(), - position: self.get_outer_position(), - hidpi_factor: self.get_hidpi_factor(), + name: self.name(), + dimensions: self.dimensions(), + position: self.outer_position(), + hidpi_factor: self.hidpi_factor(), }; monitor_id_proxy.fmt(f) @@ -218,14 +218,14 @@ impl fmt::Debug for MonitorHandle { impl MonitorHandle { #[inline] - pub fn get_name(&self) -> Option { + pub fn name(&self) -> Option { Some("Primary".to_string()) } #[inline] - pub fn get_dimensions(&self) -> PhysicalSize { + pub fn dimensions(&self) -> PhysicalSize { unsafe { - let window = android_glue::get_native_window(); + let window = android_glue::native_window(); ( ffi::ANativeWindow_getWidth(window) as f64, ffi::ANativeWindow_getHeight(window) as f64, @@ -234,13 +234,13 @@ impl MonitorHandle { } #[inline] - pub fn get_outer_position(&self) -> PhysicalPosition { + pub fn outer_position(&self) -> PhysicalPosition { // Android assumes single screen (0, 0).into() } #[inline] - pub fn get_hidpi_factor(&self) -> f64 { + pub fn hidpi_factor(&self) -> f64 { 1.0 } } @@ -255,7 +255,7 @@ impl Window { _: PlatformSpecificWindowBuilderAttributes) -> Result { - let native_window = unsafe { android_glue::get_native_window() }; + let native_window = unsafe { android_glue::native_window() }; if native_window.is_null() { return Err(OsError(format!("Android's native window is null"))); } @@ -268,7 +268,7 @@ impl Window { } #[inline] - pub fn get_native_window(&self) -> *const c_void { + pub fn native_window(&self) -> *const c_void { self.native_window } @@ -288,13 +288,13 @@ impl Window { } #[inline] - pub fn get_outer_position(&self) -> Option { + pub fn outer_position(&self) -> Option { // N/A None } #[inline] - pub fn get_inner_position(&self) -> Option { + pub fn inner_position(&self) -> Option { // N/A None } @@ -320,19 +320,19 @@ impl Window { } #[inline] - pub fn get_inner_size(&self) -> Option { + pub fn inner_size(&self) -> Option { if self.native_window.is_null() { None } else { - let dpi_factor = self.get_hidpi_factor(); - let physical_size = self.get_current_monitor().get_dimensions(); + let dpi_factor = self.hidpi_factor(); + let physical_size = self.current_monitor().dimensions(); Some(LogicalSize::from_physical(physical_size, dpi_factor)) } } #[inline] - pub fn get_outer_size(&self) -> Option { - self.get_inner_size() + pub fn outer_size(&self) -> Option { + self.inner_size() } #[inline] @@ -341,8 +341,8 @@ impl Window { } #[inline] - pub fn get_hidpi_factor(&self) -> f64 { - self.get_current_monitor().get_hidpi_factor() + pub fn hidpi_factor(&self) -> f64 { + self.current_monitor().hidpi_factor() } #[inline] @@ -372,7 +372,7 @@ impl Window { } #[inline] - pub fn get_fullscreen(&self) -> Option { + pub fn fullscreen(&self) -> Option { // N/A // Android has single screen maximized apps so nothing to do None @@ -405,19 +405,19 @@ impl Window { } #[inline] - pub fn get_current_monitor(&self) -> RootMonitorHandle { + pub fn current_monitor(&self) -> RootMonitorHandle { RootMonitorHandle { inner: MonitorHandle } } #[inline] - pub fn get_available_monitors(&self) -> VecDeque { + pub fn available_monitors(&self) -> VecDeque { let mut rb = VecDeque::with_capacity(1); rb.push_back(MonitorHandle); rb } #[inline] - pub fn get_primary_monitor(&self) -> MonitorHandle { + pub fn primary_monitor(&self) -> MonitorHandle { MonitorHandle } diff --git a/src/platform_impl/emscripten/mod.rs b/src/platform_impl/emscripten/mod.rs index 0a7a57a101..9badc84f30 100644 --- a/src/platform_impl/emscripten/mod.rs +++ b/src/platform_impl/emscripten/mod.rs @@ -15,7 +15,7 @@ use window::MonitorHandle as RootMonitorHandle; const DOCUMENT_NAME: &'static str = "#document\0"; -fn get_hidpi_factor() -> f64 { +fn hidpi_factor() -> f64 { unsafe { ffi::emscripten_get_device_pixel_ratio() as f64 } } @@ -44,23 +44,23 @@ pub struct MonitorHandle; impl MonitorHandle { #[inline] - pub fn get_name(&self) -> Option { + pub fn name(&self) -> Option { Some("Canvas".to_owned()) } #[inline] - pub fn get_outer_position(&self) -> PhysicalPosition { + pub fn outer_position(&self) -> PhysicalPosition { unimplemented!() } #[inline] - pub fn get_dimensions(&self) -> PhysicalSize { + pub fn dimensions(&self) -> PhysicalSize { (0, 0).into() } #[inline] - pub fn get_hidpi_factor(&self) -> f64 { - get_hidpi_factor() + pub fn hidpi_factor(&self) -> f64 { + hidpi_factor() } } @@ -116,14 +116,14 @@ impl EventLoop { } #[inline] - pub fn get_available_monitors(&self) -> VecDeque { + pub fn available_monitors(&self) -> VecDeque { let mut list = VecDeque::with_capacity(1); list.push_back(MonitorHandle); list } #[inline] - pub fn get_primary_monitor(&self) -> MonitorHandle { + pub fn primary_monitor(&self) -> MonitorHandle { MonitorHandle } @@ -211,7 +211,7 @@ extern "C" fn mouse_callback( match event_type { ffi::EMSCRIPTEN_EVENT_MOUSEMOVE => { - let dpi_factor = get_hidpi_factor(); + let dpi_factor = hidpi_factor(); let position = LogicalPosition::from_physical( ((*event).canvasX as f64, (*event).canvasY as f64), dpi_factor, @@ -331,7 +331,7 @@ extern fn touch_callback( for touch in 0..(*event).numTouches as usize { let touch = (*event).touches[touch]; if touch.isChanged == ffi::EM_TRUE { - let dpi_factor = get_hidpi_factor(); + let dpi_factor = hidpi_factor(); let location = LogicalPosition::from_physical( (touch.canvasX as f64, touch.canvasY as f64), dpi_factor, @@ -448,12 +448,12 @@ impl Window { } #[inline] - pub fn get_outer_position(&self) -> Option { + pub fn outer_position(&self) -> Option { Some((0, 0).into()) } #[inline] - pub fn get_inner_position(&self) -> Option { + pub fn inner_position(&self) -> Option { Some((0, 0).into()) } @@ -462,7 +462,7 @@ impl Window { } #[inline] - pub fn get_inner_size(&self) -> Option { + pub fn inner_size(&self) -> Option { unsafe { let mut width = 0; let mut height = 0; @@ -473,7 +473,7 @@ impl Window { { None } else { - let dpi_factor = self.get_hidpi_factor(); + let dpi_factor = self.hidpi_factor(); let logical = LogicalSize::from_physical((width as u32, height as u32), dpi_factor); Some(logical) } @@ -481,14 +481,14 @@ impl Window { } #[inline] - pub fn get_outer_size(&self) -> Option { - self.get_inner_size() + pub fn outer_size(&self) -> Option { + self.inner_size() } #[inline] pub fn set_inner_size(&self, size: LogicalSize) { unsafe { - let dpi_factor = self.get_hidpi_factor(); + let dpi_factor = self.hidpi_factor(); let physical = PhysicalSize::from_logical(size, dpi_factor); let (width, height): (u32, u32) = physical.into(); ffi::emscripten_set_element_css_size( @@ -569,8 +569,8 @@ impl Window { } #[inline] - pub fn get_hidpi_factor(&self) -> f64 { - get_hidpi_factor() + pub fn hidpi_factor(&self) -> f64 { + hidpi_factor() } #[inline] @@ -584,7 +584,7 @@ impl Window { } #[inline] - pub fn get_fullscreen(&self) -> Option<::MonitorHandle> { + pub fn fullscreen(&self) -> Option<::MonitorHandle> { None } @@ -614,19 +614,19 @@ impl Window { } #[inline] - pub fn get_current_monitor(&self) -> RootMonitorHandle { + pub fn current_monitor(&self) -> RootMonitorHandle { RootMonitorHandle { inner: MonitorHandle } } #[inline] - pub fn get_available_monitors(&self) -> VecDeque { + pub fn available_monitors(&self) -> VecDeque { let mut list = VecDeque::with_capacity(1); list.push_back(MonitorHandle); list } #[inline] - pub fn get_primary_monitor(&self) -> MonitorHandle { + pub fn primary_monitor(&self) -> MonitorHandle { MonitorHandle } } diff --git a/src/platform_impl/ios/mod.rs b/src/platform_impl/ios/mod.rs index 6b58408690..cb606e2aeb 100644 --- a/src/platform_impl/ios/mod.rs +++ b/src/platform_impl/ios/mod.rs @@ -161,10 +161,10 @@ impl fmt::Debug for MonitorHandle { } let monitor_id_proxy = MonitorHandle { - name: self.get_name(), - dimensions: self.get_dimensions(), - position: self.get_outer_position(), - hidpi_factor: self.get_hidpi_factor(), + name: self.name(), + dimensions: self.dimensions(), + position: self.outer_position(), + hidpi_factor: self.hidpi_factor(), }; monitor_id_proxy.fmt(f) @@ -173,31 +173,31 @@ impl fmt::Debug for MonitorHandle { impl MonitorHandle { #[inline] - pub fn get_uiscreen(&self) -> id { + pub fn uiscreen(&self) -> id { let class = class!(UIScreen); unsafe { msg_send![class, mainScreen] } } #[inline] - pub fn get_name(&self) -> Option { + pub fn name(&self) -> Option { Some("Primary".to_string()) } #[inline] - pub fn get_dimensions(&self) -> PhysicalSize { - let bounds: CGRect = unsafe { msg_send![self.get_uiscreen(), nativeBounds] }; + pub fn dimensions(&self) -> PhysicalSize { + let bounds: CGRect = unsafe { msg_send![self.uiscreen(), nativeBounds] }; (bounds.size.width as f64, bounds.size.height as f64).into() } #[inline] - pub fn get_outer_position(&self) -> PhysicalPosition { + pub fn outer_position(&self) -> PhysicalPosition { // iOS assumes single screen (0, 0).into() } #[inline] - pub fn get_hidpi_factor(&self) -> f64 { - let scale: CGFloat = unsafe { msg_send![self.get_uiscreen(), nativeScale] }; + pub fn hidpi_factor(&self) -> f64 { + let scale: CGFloat = unsafe { msg_send![self.uiscreen(), nativeScale] }; scale as f64 } } @@ -220,14 +220,14 @@ impl EventLoop { } #[inline] - pub fn get_available_monitors(&self) -> VecDeque { + pub fn available_monitors(&self) -> VecDeque { let mut rb = VecDeque::with_capacity(1); rb.push_back(MonitorHandle); rb } #[inline] - pub fn get_primary_monitor(&self) -> MonitorHandle { + pub fn primary_monitor(&self) -> MonitorHandle { MonitorHandle } @@ -345,7 +345,7 @@ impl Window { (&mut *delegate).set_ivar("eventsQueue", mem::transmute::<_, *mut c_void>(events_queue)); // easiest? way to get access to PlatformSpecificWindowBuilderAttributes to configure the view - let rect: CGRect = msg_send![MonitorHandle.get_uiscreen(), bounds]; + let rect: CGRect = msg_send![MonitorHandle.uiscreen(), bounds]; let uiview_class = class!(UIView); let root_view_class = pl_attributes.root_view_class; @@ -374,12 +374,12 @@ impl Window { } #[inline] - pub fn get_uiwindow(&self) -> id { + pub fn uiwindow(&self) -> id { self.delegate_state.window } #[inline] - pub fn get_uiview(&self) -> id { + pub fn uiview(&self) -> id { self.delegate_state.view } @@ -393,13 +393,13 @@ impl Window { } #[inline] - pub fn get_outer_position(&self) -> Option { + pub fn outer_position(&self) -> Option { // N/A None } #[inline] - pub fn get_inner_position(&self) -> Option { + pub fn inner_position(&self) -> Option { // N/A None } @@ -410,13 +410,13 @@ impl Window { } #[inline] - pub fn get_inner_size(&self) -> Option { + pub fn inner_size(&self) -> Option { Some(self.delegate_state.size) } #[inline] - pub fn get_outer_size(&self) -> Option { - self.get_inner_size() + pub fn outer_size(&self) -> Option { + self.inner_size() } #[inline] @@ -455,7 +455,7 @@ impl Window { } #[inline] - pub fn get_hidpi_factor(&self) -> f64 { + pub fn hidpi_factor(&self) -> f64 { self.delegate_state.scale } @@ -471,7 +471,7 @@ impl Window { } #[inline] - pub fn get_fullscreen(&self) -> Option { + pub fn fullscreen(&self) -> Option { // N/A // iOS has single screen maximized apps so nothing to do None @@ -504,19 +504,19 @@ impl Window { } #[inline] - pub fn get_current_monitor(&self) -> RootMonitorHandle { + pub fn current_monitor(&self) -> RootMonitorHandle { RootMonitorHandle { inner: MonitorHandle } } #[inline] - pub fn get_available_monitors(&self) -> VecDeque { + pub fn available_monitors(&self) -> VecDeque { let mut rb = VecDeque::with_capacity(1); rb.push_back(MonitorHandle); rb } #[inline] - pub fn get_primary_monitor(&self) -> MonitorHandle { + pub fn primary_monitor(&self) -> MonitorHandle { MonitorHandle } diff --git a/src/platform_impl/linux/mod.rs b/src/platform_impl/linux/mod.rs index 32a36ddadd..f62966e374 100644 --- a/src/platform_impl/linux/mod.rs +++ b/src/platform_impl/linux/mod.rs @@ -94,42 +94,42 @@ pub enum MonitorHandle { impl MonitorHandle { #[inline] - pub fn get_name(&self) -> Option { + pub fn name(&self) -> Option { match self { - &MonitorHandle::X(ref m) => m.get_name(), - &MonitorHandle::Wayland(ref m) => m.get_name(), + &MonitorHandle::X(ref m) => m.name(), + &MonitorHandle::Wayland(ref m) => m.name(), } } #[inline] - pub fn get_native_identifier(&self) -> u32 { + pub fn native_identifier(&self) -> u32 { match self { - &MonitorHandle::X(ref m) => m.get_native_identifier(), - &MonitorHandle::Wayland(ref m) => m.get_native_identifier(), + &MonitorHandle::X(ref m) => m.native_identifier(), + &MonitorHandle::Wayland(ref m) => m.native_identifier(), } } #[inline] - pub fn get_dimensions(&self) -> PhysicalSize { + pub fn dimensions(&self) -> PhysicalSize { match self { - &MonitorHandle::X(ref m) => m.get_dimensions(), - &MonitorHandle::Wayland(ref m) => m.get_dimensions(), + &MonitorHandle::X(ref m) => m.dimensions(), + &MonitorHandle::Wayland(ref m) => m.dimensions(), } } #[inline] - pub fn get_outer_position(&self) -> PhysicalPosition { + pub fn outer_position(&self) -> PhysicalPosition { match self { - &MonitorHandle::X(ref m) => m.get_outer_position(), - &MonitorHandle::Wayland(ref m) => m.get_outer_position(), + &MonitorHandle::X(ref m) => m.outer_position(), + &MonitorHandle::Wayland(ref m) => m.outer_position(), } } #[inline] - pub fn get_hidpi_factor(&self) -> f64 { + pub fn hidpi_factor(&self) -> f64 { match self { - &MonitorHandle::X(ref m) => m.get_hidpi_factor(), - &MonitorHandle::Wayland(ref m) => m.get_hidpi_factor() as f64, + &MonitorHandle::X(ref m) => m.hidpi_factor(), + &MonitorHandle::Wayland(ref m) => m.hidpi_factor() as f64, } } } @@ -176,18 +176,18 @@ impl Window { } #[inline] - pub fn get_outer_position(&self) -> Option { + pub fn outer_position(&self) -> Option { match self { - &Window::X(ref w) => w.get_outer_position(), - &Window::Wayland(ref w) => w.get_outer_position(), + &Window::X(ref w) => w.outer_position(), + &Window::Wayland(ref w) => w.outer_position(), } } #[inline] - pub fn get_inner_position(&self) -> Option { + pub fn inner_position(&self) -> Option { match self { - &Window::X(ref m) => m.get_inner_position(), - &Window::Wayland(ref m) => m.get_inner_position(), + &Window::X(ref m) => m.inner_position(), + &Window::Wayland(ref m) => m.inner_position(), } } @@ -200,18 +200,18 @@ impl Window { } #[inline] - pub fn get_inner_size(&self) -> Option { + pub fn inner_size(&self) -> Option { match self { - &Window::X(ref w) => w.get_inner_size(), - &Window::Wayland(ref w) => w.get_inner_size(), + &Window::X(ref w) => w.inner_size(), + &Window::Wayland(ref w) => w.inner_size(), } } #[inline] - pub fn get_outer_size(&self) -> Option { + pub fn outer_size(&self) -> Option { match self { - &Window::X(ref w) => w.get_outer_size(), - &Window::Wayland(ref w) => w.get_outer_size(), + &Window::X(ref w) => w.outer_size(), + &Window::Wayland(ref w) => w.outer_size(), } } @@ -272,9 +272,9 @@ impl Window { } #[inline] - pub fn get_hidpi_factor(&self) -> f64 { + pub fn hidpi_factor(&self) -> f64 { match self { - &Window::X(ref w) => w.get_hidpi_factor(), + &Window::X(ref w) => w.hidpi_factor(), &Window::Wayland(ref w) => w.hidpi_factor() as f64, } } @@ -296,10 +296,10 @@ impl Window { } #[inline] - pub fn get_fullscreen(&self) -> Option { + pub fn fullscreen(&self) -> Option { match self { - &Window::X(ref w) => w.get_fullscreen(), - &Window::Wayland(ref w) => w.get_fullscreen() + &Window::X(ref w) => w.fullscreen(), + &Window::Wayland(ref w) => w.fullscreen() .map(|monitor_id| RootMonitorHandle { inner: MonitorHandle::Wayland(monitor_id) }) } } @@ -353,21 +353,21 @@ impl Window { } #[inline] - pub fn get_current_monitor(&self) -> RootMonitorHandle { + pub fn current_monitor(&self) -> RootMonitorHandle { match self { - &Window::X(ref window) => RootMonitorHandle { inner: MonitorHandle::X(window.get_current_monitor()) }, - &Window::Wayland(ref window) => RootMonitorHandle { inner: MonitorHandle::Wayland(window.get_current_monitor()) }, + &Window::X(ref window) => RootMonitorHandle { inner: MonitorHandle::X(window.current_monitor()) }, + &Window::Wayland(ref window) => RootMonitorHandle { inner: MonitorHandle::Wayland(window.current_monitor()) }, } } #[inline] - pub fn get_available_monitors(&self) -> VecDeque { + pub fn available_monitors(&self) -> VecDeque { match self { - &Window::X(ref window) => window.get_available_monitors() + &Window::X(ref window) => window.available_monitors() .into_iter() .map(MonitorHandle::X) .collect(), - &Window::Wayland(ref window) => window.get_available_monitors() + &Window::Wayland(ref window) => window.available_monitors() .into_iter() .map(MonitorHandle::Wayland) .collect(), @@ -375,10 +375,10 @@ impl Window { } #[inline] - pub fn get_primary_monitor(&self) -> MonitorHandle { + pub fn primary_monitor(&self) -> MonitorHandle { match self { - &Window::X(ref window) => MonitorHandle::X(window.get_primary_monitor()), - &Window::Wayland(ref window) => MonitorHandle::Wayland(window.get_primary_monitor()), + &Window::X(ref window) => MonitorHandle::X(window.primary_monitor()), + &Window::Wayland(ref window) => MonitorHandle::Wayland(window.primary_monitor()), } } } @@ -479,16 +479,16 @@ impl EventLoop { } #[inline] - pub fn get_available_monitors(&self) -> VecDeque { + pub fn available_monitors(&self) -> VecDeque { match *self { EventLoop::Wayland(ref evlp) => evlp - .get_available_monitors() + .available_monitors() .into_iter() .map(MonitorHandle::Wayland) .collect(), EventLoop::X(ref evlp) => evlp .x_connection() - .get_available_monitors() + .available_monitors() .into_iter() .map(MonitorHandle::X) .collect(), @@ -496,10 +496,10 @@ impl EventLoop { } #[inline] - pub fn get_primary_monitor(&self) -> MonitorHandle { + pub fn primary_monitor(&self) -> MonitorHandle { match *self { - EventLoop::Wayland(ref evlp) => MonitorHandle::Wayland(evlp.get_primary_monitor()), - EventLoop::X(ref evlp) => MonitorHandle::X(evlp.x_connection().get_primary_monitor()), + EventLoop::Wayland(ref evlp) => MonitorHandle::Wayland(evlp.primary_monitor()), + EventLoop::X(ref evlp) => MonitorHandle::X(evlp.x_connection().primary_monitor()), } } diff --git a/src/platform_impl/linux/wayland/event_loop.rs b/src/platform_impl/linux/wayland/event_loop.rs index 231e51a591..55f192f60b 100644 --- a/src/platform_impl/linux/wayland/event_loop.rs +++ b/src/platform_impl/linux/wayland/event_loop.rs @@ -296,15 +296,15 @@ impl EventLoop { callback(::event::Event::LoopDestroyed, &self.window_target, &mut control_flow); } - pub fn get_primary_monitor(&self) -> MonitorHandle { - get_primary_monitor(&self.outputs) + pub fn primary_monitor(&self) -> MonitorHandle { + primary_monitor(&self.outputs) } - pub fn get_available_monitors(&self) -> VecDeque { - get_available_monitors(&self.outputs) + pub fn available_monitors(&self) -> VecDeque { + available_monitors(&self.outputs) } - pub fn get_display(&self) -> &Display { + pub fn display(&self) -> &Display { &*self.display } @@ -532,11 +532,11 @@ impl fmt::Debug for MonitorHandle { } let monitor_id_proxy = MonitorHandle { - name: self.get_name(), - native_identifier: self.get_native_identifier(), - dimensions: self.get_dimensions(), - position: self.get_outer_position(), - hidpi_factor: self.get_hidpi_factor(), + name: self.name(), + native_identifier: self.native_identifier(), + dimensions: self.dimensions(), + position: self.outer_position(), + hidpi_factor: self.hidpi_factor(), }; monitor_id_proxy.fmt(f) @@ -544,18 +544,18 @@ impl fmt::Debug for MonitorHandle { } impl MonitorHandle { - pub fn get_name(&self) -> Option { + pub fn name(&self) -> Option { self.mgr.with_info(&self.proxy, |_, info| { format!("{} ({})", info.model, info.make) }) } #[inline] - pub fn get_native_identifier(&self) -> u32 { + pub fn native_identifier(&self) -> u32 { self.mgr.with_info(&self.proxy, |id, _| id).unwrap_or(0) } - pub fn get_dimensions(&self) -> PhysicalSize { + pub fn dimensions(&self) -> PhysicalSize { match self.mgr.with_info(&self.proxy, |_, info| { info.modes .iter() @@ -567,7 +567,7 @@ impl MonitorHandle { }.into() } - pub fn get_outer_position(&self) -> PhysicalPosition { + pub fn outer_position(&self) -> PhysicalPosition { self.mgr .with_info(&self.proxy, |_, info| info.location) .unwrap_or((0, 0)) @@ -575,14 +575,14 @@ impl MonitorHandle { } #[inline] - pub fn get_hidpi_factor(&self) -> i32 { + pub fn hidpi_factor(&self) -> i32 { self.mgr .with_info(&self.proxy, |_, info| info.scale_factor) .unwrap_or(1) } } -pub fn get_primary_monitor(outputs: &OutputMgr) -> MonitorHandle { +pub fn primary_monitor(outputs: &OutputMgr) -> MonitorHandle { outputs.with_all(|list| { if let Some(&(_, ref proxy, _)) = list.first() { MonitorHandle { @@ -595,7 +595,7 @@ pub fn get_primary_monitor(outputs: &OutputMgr) -> MonitorHandle { }) } -pub fn get_available_monitors(outputs: &OutputMgr) -> VecDeque { +pub fn available_monitors(outputs: &OutputMgr) -> VecDeque { outputs.with_all(|list| { list.iter() .map(|&(_, ref proxy, _)| MonitorHandle { diff --git a/src/platform_impl/linux/wayland/window.rs b/src/platform_impl/linux/wayland/window.rs index 8a56dc2a3f..7554d6c77d 100644 --- a/src/platform_impl/linux/wayland/window.rs +++ b/src/platform_impl/linux/wayland/window.rs @@ -14,7 +14,7 @@ use sctk::reexports::client::protocol::{wl_seat, wl_surface}; use sctk::output::OutputMgr; use super::{make_wid, EventLoopWindowTarget, MonitorHandle, WindowId}; -use platform_impl::platform::wayland::event_loop::{get_available_monitors, get_primary_monitor}; +use platform_impl::platform::wayland::event_loop::{available_monitors, primary_monitor}; pub struct Window { surface: wl_surface::WlSurface, @@ -160,13 +160,13 @@ impl Window { } #[inline] - pub fn get_outer_position(&self) -> Option { + pub fn outer_position(&self) -> Option { // Not possible with wayland None } #[inline] - pub fn get_inner_position(&self) -> Option { + pub fn inner_position(&self) -> Option { // Not possible with wayland None } @@ -176,7 +176,7 @@ impl Window { // Not possible with wayland } - pub fn get_inner_size(&self) -> Option { + pub fn inner_size(&self) -> Option { Some(self.size.lock().unwrap().clone().into()) } @@ -185,7 +185,7 @@ impl Window { } #[inline] - pub fn get_outer_size(&self) -> Option { + pub fn outer_size(&self) -> Option { let (w, h) = self.size.lock().unwrap().clone(); // let (w, h) = super::wayland_window::add_borders(w as i32, h as i32); Some((w, h).into()) @@ -232,9 +232,9 @@ impl Window { } } - pub fn get_fullscreen(&self) -> Option { + pub fn fullscreen(&self) -> Option { if *(self.fullscreen.lock().unwrap()) { - Some(self.get_current_monitor()) + Some(self.current_monitor()) } else { None } @@ -279,15 +279,15 @@ impl Window { Err(ExternalError::NotSupported(NotSupportedError::new())) } - pub fn get_display(&self) -> &Display { + pub fn display(&self) -> &Display { &*self.display } - pub fn get_surface(&self) -> &wl_surface::WlSurface { + pub fn surface(&self) -> &wl_surface::WlSurface { &self.surface } - pub fn get_current_monitor(&self) -> MonitorHandle { + pub fn current_monitor(&self) -> MonitorHandle { let output = get_outputs(&self.surface).last().unwrap().clone(); MonitorHandle { proxy: output, @@ -295,12 +295,12 @@ impl Window { } } - pub fn get_available_monitors(&self) -> VecDeque { - get_available_monitors(&self.outputs) + pub fn available_monitors(&self) -> VecDeque { + available_monitors(&self.outputs) } - pub fn get_primary_monitor(&self) -> MonitorHandle { - get_primary_monitor(&self.outputs) + pub fn primary_monitor(&self) -> MonitorHandle { + primary_monitor(&self.outputs) } } diff --git a/src/platform_impl/linux/x11/event_processor.rs b/src/platform_impl/linux/x11/event_processor.rs index 1dbd5327c1..dcd4e9f184 100644 --- a/src/platform_impl/linux/x11/event_processor.rs +++ b/src/platform_impl/linux/x11/event_processor.rs @@ -270,7 +270,7 @@ impl EventProcessor { let new_inner_size = (xev.width as u32, xev.height as u32); let new_inner_position = (xev.x as i32, xev.y as i32); - let mut monitor = window.get_current_monitor(); // This must be done *before* locking! + let mut monitor = window.current_monitor(); // This must be done *before* locking! let mut shared_state_lock = window.shared_state.lock(); let (mut resized, moved) = { @@ -619,7 +619,7 @@ impl EventProcessor { }); if cursor_moved == Some(true) { let dpi_factor = self.with_window(xev.event, |window| { - window.get_hidpi_factor() + window.hidpi_factor() }); if let Some(dpi_factor) = dpi_factor { let position = LogicalPosition::from_physical( @@ -718,7 +718,7 @@ impl EventProcessor { }); if let Some(dpi_factor) = self.with_window(xev.event, |window| { - window.get_hidpi_factor() + window.hidpi_factor() }) { let position = LogicalPosition::from_physical( (xev.event_x as f64, xev.event_y as f64), @@ -764,7 +764,7 @@ impl EventProcessor { let xev: &ffi::XIFocusInEvent = unsafe { &*(xev.data as *const _) }; let dpi_factor = match self.with_window(xev.event, |window| { - window.get_hidpi_factor() + window.hidpi_factor() }) { Some(dpi_factor) => dpi_factor, None => return, @@ -822,7 +822,7 @@ impl EventProcessor { _ => unreachable!() }; let dpi_factor = self.with_window(xev.event, |window| { - window.get_hidpi_factor() + window.hidpi_factor() }); if let Some(dpi_factor) = dpi_factor { let location = LogicalPosition::from_physical( @@ -957,7 +957,7 @@ impl EventProcessor { // In the future, it would be quite easy to emit monitor hotplug events. let prev_list = monitor::invalidate_cached_monitor_list(); if let Some(prev_list) = prev_list { - let new_list = wt.xconn.get_available_monitors(); + let new_list = wt.xconn.available_monitors(); for new_monitor in new_list { prev_list .iter() @@ -967,7 +967,7 @@ impl EventProcessor { for (window_id, window) in wt.windows.borrow().iter() { if let Some(window) = window.upgrade() { // Check if the window is on this monitor - let monitor = window.get_current_monitor(); + let monitor = window.current_monitor(); if monitor.name == new_monitor.name { callback(Event::WindowEvent { window_id: mkwid(window_id.0), @@ -975,7 +975,7 @@ impl EventProcessor { new_monitor.hidpi_factor ), }); - let (width, height) = match window.get_inner_size_physical() { + let (width, height) = match window.inner_size_physical() { Some(result) => result, None => continue, }; diff --git a/src/platform_impl/linux/x11/monitor.rs b/src/platform_impl/linux/x11/monitor.rs index 159358c10c..12511674f2 100644 --- a/src/platform_impl/linux/x11/monitor.rs +++ b/src/platform_impl/linux/x11/monitor.rs @@ -67,7 +67,7 @@ impl MonitorHandle { primary: bool, ) -> Option { let (name, hidpi_factor) = unsafe { xconn.get_output_info(resources, &repr)? }; - let (dimensions, position) = unsafe { (repr.get_dimensions(), repr.get_outer_position()) }; + let (dimensions, position) = unsafe { (repr.dimensions(), repr.outer_position()) }; let rect = util::AaRect::new(position, dimensions); Some(MonitorHandle { id, @@ -80,32 +80,32 @@ impl MonitorHandle { }) } - pub fn get_name(&self) -> Option { + pub fn name(&self) -> Option { Some(self.name.clone()) } #[inline] - pub fn get_native_identifier(&self) -> u32 { + pub fn native_identifier(&self) -> u32 { self.id as u32 } - pub fn get_dimensions(&self) -> PhysicalSize { + pub fn dimensions(&self) -> PhysicalSize { self.dimensions.into() } - pub fn get_outer_position(&self) -> PhysicalPosition { + pub fn outer_position(&self) -> PhysicalPosition { self.position.into() } #[inline] - pub fn get_hidpi_factor(&self) -> f64 { + pub fn hidpi_factor(&self) -> f64 { self.hidpi_factor } } impl XConnection { pub fn get_monitor_for_window(&self, window_rect: Option) -> MonitorHandle { - let monitors = self.get_available_monitors(); + let monitors = self.available_monitors(); let default = monitors .get(0) .expect("[winit] Failed to find any monitors using XRandR."); @@ -206,7 +206,7 @@ impl XConnection { } } - pub fn get_available_monitors(&self) -> Vec { + pub fn available_monitors(&self) -> Vec { let mut monitors_lock = MONITORS.lock(); (*monitors_lock) .as_ref() @@ -222,8 +222,8 @@ impl XConnection { } #[inline] - pub fn get_primary_monitor(&self) -> MonitorHandle { - self.get_available_monitors() + pub fn primary_monitor(&self) -> MonitorHandle { + self.available_monitors() .into_iter() .find(|monitor| monitor.primary) .expect("[winit] Failed to find any monitors using XRandR.") diff --git a/src/platform_impl/linux/x11/util/geometry.rs b/src/platform_impl/linux/x11/util/geometry.rs index 635552c7b6..f3bd12819b 100644 --- a/src/platform_impl/linux/x11/util/geometry.rs +++ b/src/platform_impl/linux/x11/util/geometry.rs @@ -152,7 +152,7 @@ impl FrameExtentsHeuristic { } impl XConnection { - // This is adequate for get_inner_position + // This is adequate for inner_position pub fn translate_coords(&self, window: ffi::Window, root: ffi::Window) -> Result { let mut translated_coords: TranslatedCoords = unsafe { mem::uninitialized() }; unsafe { @@ -171,7 +171,7 @@ impl XConnection { self.check_errors().map(|_| translated_coords) } - // This is adequate for get_inner_size + // This is adequate for inner_size pub fn get_geometry(&self, window: ffi::Window) -> Result { let mut geometry: Geometry = unsafe { mem::uninitialized() }; let _status = unsafe { diff --git a/src/platform_impl/linux/x11/util/randr.rs b/src/platform_impl/linux/x11/util/randr.rs index acf2ac8b87..f7c98d8296 100644 --- a/src/platform_impl/linux/x11/util/randr.rs +++ b/src/platform_impl/linux/x11/util/randr.rs @@ -51,14 +51,14 @@ impl MonitorRepr { } } - pub unsafe fn get_dimensions(&self) -> (u32, u32) { + pub unsafe fn dimensions(&self) -> (u32, u32) { match *self { MonitorRepr::Monitor(monitor) => ((*monitor).width as u32, (*monitor).height as u32), MonitorRepr::Crtc(crtc) => ((*crtc).width as u32, (*crtc).height as u32), } } - pub unsafe fn get_outer_position(&self) -> (i32, i32) { + pub unsafe fn outer_position(&self) -> (i32, i32) { match *self { MonitorRepr::Monitor(monitor) => ((*monitor).x as i32, (*monitor).y as i32), MonitorRepr::Crtc(crtc) => ((*crtc).x as i32, (*crtc).y as i32), @@ -123,7 +123,7 @@ impl XConnection { dpi / 96. } else { calc_dpi_factor( - repr.get_dimensions(), + repr.dimensions(), ((*output_info).mm_width as u64, (*output_info).mm_height as u64), ) }; diff --git a/src/platform_impl/linux/x11/window.rs b/src/platform_impl/linux/x11/window.rs index 0441b3757f..b303bf8391 100644 --- a/src/platform_impl/linux/x11/window.rs +++ b/src/platform_impl/linux/x11/window.rs @@ -80,11 +80,11 @@ impl UnownedWindow { let xconn = &event_loop.xconn; let root = event_loop.root; - let monitors = xconn.get_available_monitors(); + let monitors = xconn.available_monitors(); let dpi_factor = if !monitors.is_empty() { - let mut dpi_factor = Some(monitors[0].get_hidpi_factor()); + let mut dpi_factor = Some(monitors[0].hidpi_factor()); for monitor in &monitors { - if Some(monitor.get_hidpi_factor()) != dpi_factor { + if Some(monitor.hidpi_factor()) != dpi_factor { dpi_factor = None; } } @@ -96,7 +96,7 @@ impl UnownedWindow { let mut dpi_factor = None; for monitor in &monitors { if monitor.rect.contains_point(x, y) { - dpi_factor = Some(monitor.get_hidpi_factor()); + dpi_factor = Some(monitor.hidpi_factor()); break; } } @@ -418,12 +418,12 @@ impl UnownedWindow { } fn logicalize_coords(&self, (x, y): (i32, i32)) -> LogicalPosition { - let dpi = self.get_hidpi_factor(); + let dpi = self.hidpi_factor(); LogicalPosition::from_physical((x, y), dpi) } fn logicalize_size(&self, (width, height): (u32, u32)) -> LogicalSize { - let dpi = self.get_hidpi_factor(); + let dpi = self.hidpi_factor(); LogicalSize::from_physical((width, height), dpi) } @@ -532,9 +532,9 @@ impl UnownedWindow { flusher }, Some(RootMonitorHandle { inner: PlatformMonitorHandle::X(monitor) }) => { - let window_position = self.get_outer_position_physical(); + let window_position = self.outer_position_physical(); self.shared_state.lock().restore_position = window_position; - let monitor_origin: (i32, i32) = monitor.get_outer_position().into(); + let monitor_origin: (i32, i32) = monitor.outer_position().into(); self.set_position_inner(monitor_origin.0, monitor_origin.1).queue(); self.set_fullscreen_hint(true) } @@ -543,7 +543,7 @@ impl UnownedWindow { } #[inline] - pub fn get_fullscreen(&self) -> Option { + pub fn fullscreen(&self) -> Option { self.shared_state.lock().fullscreen.clone() } @@ -558,7 +558,7 @@ impl UnownedWindow { fn get_rect(&self) -> Option { // TODO: This might round-trip more times than needed. - if let (Some(position), Some(size)) = (self.get_outer_position_physical(), self.get_outer_size_physical()) { + if let (Some(position), Some(size)) = (self.outer_position_physical(), self.outer_size_physical()) { Some(util::AaRect::new(position, size)) } else { None @@ -566,7 +566,7 @@ impl UnownedWindow { } #[inline] - pub fn get_current_monitor(&self) -> X11MonitorHandle { + pub fn current_monitor(&self) -> X11MonitorHandle { let monitor = self.shared_state .lock() .last_monitor @@ -580,12 +580,12 @@ impl UnownedWindow { }) } - pub fn get_available_monitors(&self) -> Vec { - self.xconn.get_available_monitors() + pub fn available_monitors(&self) -> Vec { + self.xconn.available_monitors() } - pub fn get_primary_monitor(&self) -> X11MonitorHandle { - self.xconn.get_primary_monitor() + pub fn primary_monitor(&self) -> X11MonitorHandle { + self.xconn.primary_monitor() } fn set_maximized_inner(&self, maximized: bool) -> util::Flusher { @@ -723,38 +723,38 @@ impl UnownedWindow { (*self.shared_state.lock()).frame_extents.take(); } - pub(crate) fn get_outer_position_physical(&self) -> Option<(i32, i32)> { + pub(crate) fn outer_position_physical(&self) -> Option<(i32, i32)> { let extents = (*self.shared_state.lock()).frame_extents.clone(); if let Some(extents) = extents { - self.get_inner_position_physical() + self.inner_position_physical() .map(|(x, y)| extents.inner_pos_to_outer(x, y)) } else { self.update_cached_frame_extents(); - self.get_outer_position_physical() + self.outer_position_physical() } } #[inline] - pub fn get_outer_position(&self) -> Option { + pub fn outer_position(&self) -> Option { let extents = (*self.shared_state.lock()).frame_extents.clone(); if let Some(extents) = extents { - self.get_inner_position() - .map(|logical| extents.inner_pos_to_outer_logical(logical, self.get_hidpi_factor())) + self.inner_position() + .map(|logical| extents.inner_pos_to_outer_logical(logical, self.hidpi_factor())) } else { self.update_cached_frame_extents(); - self.get_outer_position() + self.outer_position() } } - pub(crate) fn get_inner_position_physical(&self) -> Option<(i32, i32)> { + pub(crate) fn inner_position_physical(&self) -> Option<(i32, i32)> { self.xconn.translate_coords(self.xwindow, self.root) .ok() .map(|coords| (coords.x_rel_root, coords.y_rel_root)) } #[inline] - pub fn get_inner_position(&self) -> Option { - self.get_inner_position_physical() + pub fn inner_position(&self) -> Option { + self.inner_position_physical() .map(|coords| self.logicalize_coords(coords)) } @@ -790,42 +790,42 @@ impl UnownedWindow { #[inline] pub fn set_outer_position(&self, logical_position: LogicalPosition) { - let (x, y) = logical_position.to_physical(self.get_hidpi_factor()).into(); + let (x, y) = logical_position.to_physical(self.hidpi_factor()).into(); self.set_position_physical(x, y); } - pub(crate) fn get_inner_size_physical(&self) -> Option<(u32, u32)> { + pub(crate) fn inner_size_physical(&self) -> Option<(u32, u32)> { self.xconn.get_geometry(self.xwindow) .ok() .map(|geo| (geo.width, geo.height)) } #[inline] - pub fn get_inner_size(&self) -> Option { - self.get_inner_size_physical() + pub fn inner_size(&self) -> Option { + self.inner_size_physical() .map(|size| self.logicalize_size(size)) } - pub(crate) fn get_outer_size_physical(&self) -> Option<(u32, u32)> { + pub(crate) fn outer_size_physical(&self) -> Option<(u32, u32)> { let extents = self.shared_state.lock().frame_extents.clone(); if let Some(extents) = extents { - self.get_inner_size_physical() + self.inner_size_physical() .map(|(w, h)| extents.inner_size_to_outer(w, h)) } else { self.update_cached_frame_extents(); - self.get_outer_size_physical() + self.outer_size_physical() } } #[inline] - pub fn get_outer_size(&self) -> Option { + pub fn outer_size(&self) -> Option { let extents = self.shared_state.lock().frame_extents.clone(); if let Some(extents) = extents { - self.get_inner_size() - .map(|logical| extents.inner_size_to_outer_logical(logical, self.get_hidpi_factor())) + self.inner_size() + .map(|logical| extents.inner_size_to_outer_logical(logical, self.hidpi_factor())) } else { self.update_cached_frame_extents(); - self.get_outer_size() + self.outer_size() } } @@ -843,7 +843,7 @@ impl UnownedWindow { #[inline] pub fn set_inner_size(&self, logical_size: LogicalSize) { - let dpi_factor = self.get_hidpi_factor(); + let dpi_factor = self.hidpi_factor(); let (width, height) = logical_size.to_physical(dpi_factor).into(); self.set_inner_size_physical(width, height); } @@ -865,7 +865,7 @@ impl UnownedWindow { pub fn set_min_inner_size(&self, logical_dimensions: Option) { self.shared_state.lock().min_inner_size = logical_dimensions; let physical_dimensions = logical_dimensions.map(|logical_dimensions| { - logical_dimensions.to_physical(self.get_hidpi_factor()).into() + logical_dimensions.to_physical(self.hidpi_factor()).into() }); self.set_min_inner_size_physical(physical_dimensions); } @@ -879,7 +879,7 @@ impl UnownedWindow { pub fn set_max_inner_size(&self, logical_dimensions: Option) { self.shared_state.lock().max_inner_size = logical_dimensions; let physical_dimensions = logical_dimensions.map(|logical_dimensions| { - logical_dimensions.to_physical(self.get_hidpi_factor()).into() + logical_dimensions.to_physical(self.hidpi_factor()).into() }); self.set_max_inner_size_physical(physical_dimensions); } @@ -933,11 +933,11 @@ impl UnownedWindow { let shared_state_lock = self.shared_state.lock(); (shared_state_lock.min_inner_size, shared_state_lock.max_inner_size) } else { - let window_size = self.get_inner_size(); + let window_size = self.inner_size(); (window_size.clone(), window_size) }; - let dpi_factor = self.get_hidpi_factor(); + let dpi_factor = self.hidpi_factor(); let min_inner_size = logical_min .map(|logical_size| logical_size.to_physical(dpi_factor)) .map(Into::into); @@ -951,27 +951,27 @@ impl UnownedWindow { } #[inline] - pub fn get_xlib_display(&self) -> *mut c_void { + pub fn xlib_display(&self) -> *mut c_void { self.xconn.display as _ } #[inline] - pub fn get_xlib_screen_id(&self) -> c_int { + pub fn xlib_screen_id(&self) -> c_int { self.screen_id } #[inline] - pub fn get_xlib_xconnection(&self) -> Arc { + pub fn xlib_xconnection(&self) -> Arc { Arc::clone(&self.xconn) } #[inline] - pub fn get_xlib_window(&self) -> c_ulong { + pub fn xlib_window(&self) -> c_ulong { self.xwindow } #[inline] - pub fn get_xcb_connection(&self) -> *mut c_void { + pub fn xcb_connection(&self) -> *mut c_void { unsafe { (self.xconn.xlib_xcb.XGetXCBConnection)(self.xconn.display) as *mut _ } @@ -1182,8 +1182,8 @@ impl UnownedWindow { } #[inline] - pub fn get_hidpi_factor(&self) -> f64 { - self.get_current_monitor().hidpi_factor + pub fn hidpi_factor(&self) -> f64 { + self.current_monitor().hidpi_factor } pub fn set_cursor_position_physical(&self, x: i32, y: i32) -> Result<(), ExternalError> { @@ -1205,7 +1205,7 @@ impl UnownedWindow { #[inline] pub fn set_cursor_position(&self, logical_position: LogicalPosition) -> Result<(), ExternalError> { - let (x, y) = logical_position.to_physical(self.get_hidpi_factor()).into(); + let (x, y) = logical_position.to_physical(self.hidpi_factor()).into(); self.set_cursor_position_physical(x, y) } @@ -1217,7 +1217,7 @@ impl UnownedWindow { #[inline] pub fn set_ime_spot(&self, logical_spot: LogicalPosition) { - let (x, y) = logical_spot.to_physical(self.get_hidpi_factor()).into(); + let (x, y) = logical_spot.to_physical(self.hidpi_factor()).into(); self.set_ime_spot_physical(x, y); } diff --git a/src/platform_impl/macos/event_loop.rs b/src/platform_impl/macos/event_loop.rs index 23c2102ae2..510dd84bf1 100644 --- a/src/platform_impl/macos/event_loop.rs +++ b/src/platform_impl/macos/event_loop.rs @@ -61,13 +61,13 @@ impl EventLoop { } #[inline] - pub fn get_available_monitors(&self) -> VecDeque { - monitor::get_available_monitors() + pub fn available_monitors(&self) -> VecDeque { + monitor::available_monitors() } #[inline] - pub fn get_primary_monitor(&self) -> MonitorHandle { - monitor::get_primary_monitor() + pub fn primary_monitor(&self) -> MonitorHandle { + monitor::primary_monitor() } pub fn window_target(&self) -> &RootWindowTarget { diff --git a/src/platform_impl/macos/monitor.rs b/src/platform_impl/macos/monitor.rs index 7415e3c893..bbc644afcc 100644 --- a/src/platform_impl/macos/monitor.rs +++ b/src/platform_impl/macos/monitor.rs @@ -9,7 +9,7 @@ use platform_impl::platform::util::IdRef; #[derive(Clone, PartialEq)] pub struct MonitorHandle(CGDirectDisplayID); -pub fn get_available_monitors() -> VecDeque { +pub fn available_monitors() -> VecDeque { if let Ok(displays) = CGDisplay::active_displays() { let mut monitors = VecDeque::with_capacity(displays.len()); for display in displays { @@ -21,7 +21,7 @@ pub fn get_available_monitors() -> VecDeque { } } -pub fn get_primary_monitor() -> MonitorHandle { +pub fn primary_monitor() -> MonitorHandle { MonitorHandle(CGDisplay::main().id) } @@ -38,11 +38,11 @@ impl fmt::Debug for MonitorHandle { } let monitor_id_proxy = MonitorHandle { - name: self.get_name(), - native_identifier: self.get_native_identifier(), - dimensions: self.get_dimensions(), - position: self.get_outer_position(), - hidpi_factor: self.get_hidpi_factor(), + name: self.name(), + native_identifier: self.native_identifier(), + dimensions: self.dimensions(), + position: self.outer_position(), + hidpi_factor: self.hidpi_factor(), }; monitor_id_proxy.fmt(f) @@ -54,48 +54,48 @@ impl MonitorHandle { MonitorHandle(id) } - pub fn get_name(&self) -> Option { + pub fn name(&self) -> Option { let MonitorHandle(display_id) = *self; let screen_num = CGDisplay::new(display_id).model_number(); Some(format!("Monitor #{}", screen_num)) } #[inline] - pub fn get_native_identifier(&self) -> u32 { + pub fn native_identifier(&self) -> u32 { self.0 } - pub fn get_dimensions(&self) -> PhysicalSize { + pub fn dimensions(&self) -> PhysicalSize { let MonitorHandle(display_id) = *self; let display = CGDisplay::new(display_id); let height = display.pixels_high(); let width = display.pixels_wide(); PhysicalSize::from_logical( (width as f64, height as f64), - self.get_hidpi_factor(), + self.hidpi_factor(), ) } #[inline] - pub fn get_outer_position(&self) -> PhysicalPosition { - let bounds = unsafe { CGDisplayBounds(self.get_native_identifier()) }; + pub fn outer_position(&self) -> PhysicalPosition { + let bounds = unsafe { CGDisplayBounds(self.native_identifier()) }; PhysicalPosition::from_logical( (bounds.origin.x as f64, bounds.origin.y as f64), - self.get_hidpi_factor(), + self.hidpi_factor(), ) } - pub fn get_hidpi_factor(&self) -> f64 { - let screen = match self.get_nsscreen() { + pub fn hidpi_factor(&self) -> f64 { + let screen = match self.nsscreen() { Some(screen) => screen, None => return 1.0, // default to 1.0 when we can't find the screen }; unsafe { NSScreen::backingScaleFactor(screen) as f64 } } - pub(crate) fn get_nsscreen(&self) -> Option { + pub(crate) fn nsscreen(&self) -> Option { unsafe { - let native_id = self.get_native_identifier(); + let native_id = self.native_identifier(); let screens = NSScreen::screens(nil); let count: NSUInteger = msg_send![screens, count]; let key = IdRef::new(NSString::alloc(nil).init_str("NSScreenNumber")); diff --git a/src/platform_impl/macos/window.rs b/src/platform_impl/macos/window.rs index 58a059ef78..23f7d4ef8e 100644 --- a/src/platform_impl/macos/window.rs +++ b/src/platform_impl/macos/window.rs @@ -104,7 +104,7 @@ fn create_window( let pool = NSAutoreleasePool::new(nil); let screen = match attrs.fullscreen { Some(ref monitor_id) => { - let monitor_screen = monitor_id.inner.get_nsscreen(); + let monitor_screen = monitor_id.inner.nsscreen(); Some(monitor_screen.unwrap_or(appkit::NSScreen::mainScreen(nil))) }, _ => None, @@ -326,7 +326,7 @@ impl UnownedWindow { // Set fullscreen mode after we setup everything if let Some(monitor) = fullscreen { - if monitor.inner != window.get_current_monitor().inner { + if monitor.inner != window.current_monitor().inner { // To do this with native fullscreen, we probably need to // warp the window... while we could use // `enterFullScreenMode`, they're idiomatically different @@ -394,7 +394,7 @@ impl UnownedWindow { AppState::queue_redraw(RootWindowId(self.id())); } - pub fn get_outer_position(&self) -> Option { + pub fn outer_position(&self) -> Option { let frame_rect = unsafe { NSWindow::frame(*self.nswindow) }; Some(( frame_rect.origin.x as f64, @@ -402,7 +402,7 @@ impl UnownedWindow { ).into()) } - pub fn get_inner_position(&self) -> Option { + pub fn inner_position(&self) -> Option { let content_rect = unsafe { NSWindow::contentRectForFrameRect_( *self.nswindow, @@ -431,13 +431,13 @@ impl UnownedWindow { } #[inline] - pub fn get_inner_size(&self) -> Option { + pub fn inner_size(&self) -> Option { let view_frame = unsafe { NSView::frame(*self.nsview) }; Some((view_frame.size.width as f64, view_frame.size.height as f64).into()) } #[inline] - pub fn get_outer_size(&self) -> Option { + pub fn outer_size(&self) -> Option { let view_frame = unsafe { NSWindow::frame(*self.nswindow) }; Some((view_frame.size.width as f64, view_frame.size.height as f64).into()) } @@ -518,13 +518,13 @@ impl UnownedWindow { } #[inline] - pub fn get_hidpi_factor(&self) -> f64 { + pub fn hidpi_factor(&self) -> f64 { unsafe { NSWindow::backingScaleFactor(*self.nswindow) as _ } } #[inline] pub fn set_cursor_position(&self, cursor_position: LogicalPosition) -> Result<(), ExternalError> { - let window_position = self.get_inner_position().unwrap(); + let window_position = self.inner_position().unwrap(); let point = appkit::CGPoint { x: (cursor_position.x + window_position.x) as CGFloat, y: (cursor_position.y + window_position.y) as CGFloat, @@ -635,7 +635,7 @@ impl UnownedWindow { } #[inline] - pub fn get_fullscreen(&self) -> Option { + pub fn fullscreen(&self) -> Option { let shared_state_lock = self.shared_state.lock().unwrap(); shared_state_lock.fullscreen.clone() } @@ -746,7 +746,7 @@ impl UnownedWindow { } #[inline] - pub fn get_current_monitor(&self) -> RootMonitorHandle { + pub fn current_monitor(&self) -> RootMonitorHandle { unsafe { let screen: id = msg_send![*self.nswindow, screen]; let desc = NSScreen::deviceDescription(screen); @@ -758,24 +758,24 @@ impl UnownedWindow { } #[inline] - pub fn get_available_monitors(&self) -> VecDeque { - monitor::get_available_monitors() + pub fn available_monitors(&self) -> VecDeque { + monitor::available_monitors() } #[inline] - pub fn get_primary_monitor(&self) -> MonitorHandle { - monitor::get_primary_monitor() + pub fn primary_monitor(&self) -> MonitorHandle { + monitor::primary_monitor() } } impl WindowExtMacOS for UnownedWindow { #[inline] - fn get_nswindow(&self) -> *mut c_void { + fn nswindow(&self) -> *mut c_void { *self.nswindow as *mut _ } #[inline] - fn get_nsview(&self) -> *mut c_void { + fn nsview(&self) -> *mut c_void { *self.nsview as *mut _ } @@ -790,7 +790,7 @@ impl WindowExtMacOS for UnownedWindow { } #[inline] - fn get_simple_fullscreen(&self) -> bool { + fn simple_fullscreen(&self) -> bool { let shared_state_lock = self.shared_state.lock().unwrap(); shared_state_lock.is_simple_fullscreen } diff --git a/src/platform_impl/macos/window_delegate.rs b/src/platform_impl/macos/window_delegate.rs index 83defb3f2b..46460c341d 100644 --- a/src/platform_impl/macos/window_delegate.rs +++ b/src/platform_impl/macos/window_delegate.rs @@ -37,7 +37,7 @@ impl WindowDelegateState { window: &Arc, initial_fullscreen: bool, ) -> Self { - let dpi_factor = window.get_hidpi_factor(); + let dpi_factor = window.hidpi_factor(); let mut delegate_state = WindowDelegateState { nswindow: window.nswindow.clone(), @@ -408,7 +408,7 @@ extern fn window_did_enter_fullscreen(this: &Object, _: Sel, _: id) { trace!("Triggered `windowDidEnterFullscreen:`"); with_state(this, |state| { state.with_window(|window| { - let monitor = window.get_current_monitor(); + let monitor = window.current_monitor(); trace!("Locked shared state in `window_did_enter_fullscreen`"); window.shared_state.lock().unwrap().fullscreen = Some(monitor); trace!("Unlocked shared state in `window_will_enter_fullscreen`"); diff --git a/src/platform_impl/windows/dpi.rs b/src/platform_impl/windows/dpi.rs index ea4bc655f7..4bf31f3922 100644 --- a/src/platform_impl/windows/dpi.rs +++ b/src/platform_impl/windows/dpi.rs @@ -144,7 +144,7 @@ pub fn dpi_to_scale_factor(dpi: u32) -> f64 { dpi as f64 / BASE_DPI as f64 } -pub unsafe fn get_hwnd_dpi(hwnd: HWND) -> u32 { +pub unsafe fn hwnd_dpi(hwnd: HWND) -> u32 { let hdc = winuser::GetDC(hwnd); if hdc.is_null() { panic!("[winit] `GetDC` returned null!"); @@ -184,6 +184,6 @@ pub unsafe fn get_hwnd_dpi(hwnd: HWND) -> u32 { } } -pub fn get_hwnd_scale_factor(hwnd: HWND) -> f64 { - dpi_to_scale_factor(unsafe { get_hwnd_dpi(hwnd) }) +pub fn hwnd_scale_factor(hwnd: HWND) -> f64 { + dpi_to_scale_factor(unsafe { hwnd_dpi(hwnd) }) } diff --git a/src/platform_impl/windows/event_loop.rs b/src/platform_impl/windows/event_loop.rs index fc8f7edb58..585c33b222 100644 --- a/src/platform_impl/windows/event_loop.rs +++ b/src/platform_impl/windows/event_loop.rs @@ -52,7 +52,7 @@ use platform_impl::platform::dpi::{ become_dpi_aware, dpi_to_scale_factor, enable_non_client_dpi_scaling, - get_hwnd_scale_factor, + hwnd_scale_factor, }; use platform_impl::platform::drop_handler::FileDropHandler; use platform_impl::platform::event::{handle_extended_keys, process_key_params, vkey_to_winit_vkey}; @@ -869,7 +869,7 @@ unsafe extern "system" fn public_window_callback( let windowpos = lparam as *const winuser::WINDOWPOS; if (*windowpos).flags & winuser::SWP_NOMOVE != winuser::SWP_NOMOVE { - let dpi_factor = get_hwnd_scale_factor(window); + let dpi_factor = hwnd_scale_factor(window); let logical_position = LogicalPosition::from_physical( ((*windowpos).x, (*windowpos).y), dpi_factor, @@ -889,7 +889,7 @@ unsafe extern "system" fn public_window_callback( let w = LOWORD(lparam as DWORD) as u32; let h = HIWORD(lparam as DWORD) as u32; - let dpi_factor = get_hwnd_scale_factor(window); + let dpi_factor = hwnd_scale_factor(window); let logical_size = LogicalSize::from_physical((w, h), dpi_factor); let event = Event::WindowEvent { window_id: RootWindowId(WindowId(window)), @@ -954,7 +954,7 @@ unsafe extern "system" fn public_window_callback( let x = windowsx::GET_X_LPARAM(lparam) as f64; let y = windowsx::GET_Y_LPARAM(lparam) as f64; - let dpi_factor = get_hwnd_scale_factor(window); + let dpi_factor = hwnd_scale_factor(window); let position = LogicalPosition::from_physical((x, y), dpi_factor); subclass_input.send_event(Event::WindowEvent { @@ -1305,7 +1305,7 @@ unsafe extern "system" fn public_window_callback( inputs.as_mut_ptr(), mem::size_of::() as INT, ) > 0 { - let dpi_factor = get_hwnd_scale_factor(window); + let dpi_factor = hwnd_scale_factor(window); for input in &inputs { let x = (input.x as f64) / 100f64; let y = (input.y as f64) / 100f64; diff --git a/src/platform_impl/windows/mod.rs b/src/platform_impl/windows/mod.rs index 14e9b8e530..307423c389 100644 --- a/src/platform_impl/windows/mod.rs +++ b/src/platform_impl/windows/mod.rs @@ -36,7 +36,7 @@ impl DeviceId { } impl DeviceId { - pub fn get_persistent_identifier(&self) -> Option { + pub fn persistent_identifier(&self) -> Option { if self.0 != 0 { raw_input::get_raw_input_device_name(self.0 as _) } else { diff --git a/src/platform_impl/windows/monitor.rs b/src/platform_impl/windows/monitor.rs index f46efac8a3..d4ef520a23 100644 --- a/src/platform_impl/windows/monitor.rs +++ b/src/platform_impl/windows/monitor.rs @@ -50,7 +50,7 @@ unsafe extern "system" fn monitor_enum_proc( TRUE // continue enumeration } -pub fn get_available_monitors() -> VecDeque { +pub fn available_monitors() -> VecDeque { let mut monitors: VecDeque = VecDeque::new(); unsafe { winuser::EnumDisplayMonitors( @@ -63,7 +63,7 @@ pub fn get_available_monitors() -> VecDeque { monitors } -pub fn get_primary_monitor() -> MonitorHandle { +pub fn primary_monitor() -> MonitorHandle { const ORIGIN: POINT = POINT { x: 0, y: 0 }; let hmonitor = unsafe { winuser::MonitorFromPoint(ORIGIN, winuser::MONITOR_DEFAULTTOPRIMARY) @@ -71,7 +71,7 @@ pub fn get_primary_monitor() -> MonitorHandle { MonitorHandle::from_hmonitor(hmonitor) } -pub fn get_current_monitor(hwnd: HWND) -> MonitorHandle { +pub fn current_monitor(hwnd: HWND) -> MonitorHandle { let hmonitor = unsafe { winuser::MonitorFromWindow(hwnd, winuser::MONITOR_DEFAULTTONEAREST) }; @@ -80,22 +80,22 @@ pub fn get_current_monitor(hwnd: HWND) -> MonitorHandle { impl EventLoop { // TODO: Investigate opportunities for caching - pub fn get_available_monitors(&self) -> VecDeque { - get_available_monitors() + pub fn available_monitors(&self) -> VecDeque { + available_monitors() } - pub fn get_primary_monitor(&self) -> MonitorHandle { - get_primary_monitor() + pub fn primary_monitor(&self) -> MonitorHandle { + primary_monitor() } } impl Window { - pub fn get_available_monitors(&self) -> VecDeque { - get_available_monitors() + pub fn available_monitors(&self) -> VecDeque { + available_monitors() } - pub fn get_primary_monitor(&self) -> MonitorHandle { - get_primary_monitor() + pub fn primary_monitor(&self) -> MonitorHandle { + primary_monitor() } } @@ -142,32 +142,32 @@ impl MonitorHandle { } #[inline] - pub fn get_name(&self) -> Option { + pub fn name(&self) -> Option { Some(self.monitor_name.clone()) } #[inline] - pub fn get_native_identifier(&self) -> String { + pub fn native_identifier(&self) -> String { self.monitor_name.clone() } #[inline] - pub fn get_hmonitor(&self) -> HMONITOR { + pub fn hmonitor(&self) -> HMONITOR { self.hmonitor.0 } #[inline] - pub fn get_dimensions(&self) -> PhysicalSize { + pub fn dimensions(&self) -> PhysicalSize { self.dimensions.into() } #[inline] - pub fn get_outer_position(&self) -> PhysicalPosition { + pub fn outer_position(&self) -> PhysicalPosition { self.position.into() } #[inline] - pub fn get_hidpi_factor(&self) -> f64 { + pub fn hidpi_factor(&self) -> f64 { self.hidpi_factor } } diff --git a/src/platform_impl/windows/window.rs b/src/platform_impl/windows/window.rs index 1fd2b2c233..f6624e1f7a 100644 --- a/src/platform_impl/windows/window.rs +++ b/src/platform_impl/windows/window.rs @@ -24,7 +24,7 @@ use dpi::{LogicalPosition, LogicalSize, PhysicalSize}; use monitor::MonitorHandle as RootMonitorHandle; use platform_impl::platform::{ {PlatformSpecificWindowBuilderAttributes, WindowId}, - dpi::{dpi_to_scale_factor, get_hwnd_dpi}, + dpi::{dpi_to_scale_factor, hwnd_dpi}, drop_handler::FileDropHandler, event_loop::{self, EventLoopWindowTarget, DESTROY_MSG_ID, INITIAL_DPI_MSG_ID, REQUEST_REDRAW_NO_NEWEVENTS_MSG_ID}, icon::{self, IconType, WinIcon}, @@ -127,21 +127,21 @@ impl Window { } } - pub(crate) fn get_outer_position_physical(&self) -> Option<(i32, i32)> { + pub(crate) fn outer_position_physical(&self) -> Option<(i32, i32)> { util::get_window_rect(self.window.0) .map(|rect| (rect.left as i32, rect.top as i32)) } #[inline] - pub fn get_outer_position(&self) -> Option { - self.get_outer_position_physical() + pub fn outer_position(&self) -> Option { + self.outer_position_physical() .map(|physical_position| { - let dpi_factor = self.get_hidpi_factor(); + let dpi_factor = self.hidpi_factor(); LogicalPosition::from_physical(physical_position, dpi_factor) }) } - pub(crate) fn get_inner_position_physical(&self) -> Option<(i32, i32)> { + pub(crate) fn inner_position_physical(&self) -> Option<(i32, i32)> { let mut position: POINT = unsafe { mem::zeroed() }; if unsafe { winuser::ClientToScreen(self.window.0, &mut position) } == 0 { return None; @@ -150,10 +150,10 @@ impl Window { } #[inline] - pub fn get_inner_position(&self) -> Option { - self.get_inner_position_physical() + pub fn inner_position(&self) -> Option { + self.inner_position_physical() .map(|physical_position| { - let dpi_factor = self.get_hidpi_factor(); + let dpi_factor = self.hidpi_factor(); LogicalPosition::from_physical(physical_position, dpi_factor) }) } @@ -175,12 +175,12 @@ impl Window { #[inline] pub fn set_outer_position(&self, logical_position: LogicalPosition) { - let dpi_factor = self.get_hidpi_factor(); + let dpi_factor = self.hidpi_factor(); let (x, y) = logical_position.to_physical(dpi_factor).into(); self.set_position_physical(x, y); } - pub(crate) fn get_inner_size_physical(&self) -> Option<(u32, u32)> { + pub(crate) fn inner_size_physical(&self) -> Option<(u32, u32)> { let mut rect: RECT = unsafe { mem::uninitialized() }; if unsafe { winuser::GetClientRect(self.window.0, &mut rect) } == 0 { return None; @@ -192,15 +192,15 @@ impl Window { } #[inline] - pub fn get_inner_size(&self) -> Option { - self.get_inner_size_physical() + pub fn inner_size(&self) -> Option { + self.inner_size_physical() .map(|physical_size| { - let dpi_factor = self.get_hidpi_factor(); + let dpi_factor = self.hidpi_factor(); LogicalSize::from_physical(physical_size, dpi_factor) }) } - pub(crate) fn get_outer_size_physical(&self) -> Option<(u32, u32)> { + pub(crate) fn outer_size_physical(&self) -> Option<(u32, u32)> { util::get_window_rect(self.window.0) .map(|rect| ( (rect.right - rect.left) as u32, @@ -209,10 +209,10 @@ impl Window { } #[inline] - pub fn get_outer_size(&self) -> Option { - self.get_outer_size_physical() + pub fn outer_size(&self) -> Option { + self.outer_size_physical() .map(|physical_size| { - let dpi_factor = self.get_hidpi_factor(); + let dpi_factor = self.hidpi_factor(); LogicalSize::from_physical(physical_size, dpi_factor) }) } @@ -249,7 +249,7 @@ impl Window { #[inline] pub fn set_inner_size(&self, logical_size: LogicalSize) { - let dpi_factor = self.get_hidpi_factor(); + let dpi_factor = self.hidpi_factor(); let (width, height) = logical_size.to_physical(dpi_factor).into(); self.set_inner_size_physical(width, height); } @@ -257,14 +257,14 @@ impl Window { pub(crate) fn set_min_inner_size_physical(&self, dimensions: Option<(u32, u32)>) { self.window_state.lock().min_size = dimensions.map(Into::into); // Make windows re-check the window size bounds. - self.get_inner_size_physical() + self.inner_size_physical() .map(|(width, height)| self.set_inner_size_physical(width, height)); } #[inline] pub fn set_min_inner_size(&self, logical_size: Option) { let physical_size = logical_size.map(|logical_size| { - let dpi_factor = self.get_hidpi_factor(); + let dpi_factor = self.hidpi_factor(); logical_size.to_physical(dpi_factor).into() }); self.set_min_inner_size_physical(physical_size); @@ -273,14 +273,14 @@ impl Window { pub fn set_max_inner_size_physical(&self, dimensions: Option<(u32, u32)>) { self.window_state.lock().max_size = dimensions.map(Into::into); // Make windows re-check the window size bounds. - self.get_inner_size_physical() + self.inner_size_physical() .map(|(width, height)| self.set_inner_size_physical(width, height)); } #[inline] pub fn set_max_inner_size(&self, logical_size: Option) { let physical_size = logical_size.map(|logical_size| { - let dpi_factor = self.get_hidpi_factor(); + let dpi_factor = self.hidpi_factor(); logical_size.to_physical(dpi_factor).into() }); self.set_max_inner_size_physical(physical_size); @@ -350,7 +350,7 @@ impl Window { } #[inline] - pub fn get_hidpi_factor(&self) -> f64 { + pub fn hidpi_factor(&self) -> f64 { self.window_state.lock().dpi_factor } @@ -369,7 +369,7 @@ impl Window { #[inline] pub fn set_cursor_position(&self, logical_position: LogicalPosition) -> Result<(), ExternalError> { - let dpi_factor = self.get_hidpi_factor(); + let dpi_factor = self.hidpi_factor(); let (x, y) = logical_position.to_physical(dpi_factor).into(); self.set_cursor_position_physical(x, y) } @@ -395,7 +395,7 @@ impl Window { } #[inline] - pub fn get_fullscreen(&self) -> Option { + pub fn fullscreen(&self) -> Option { let window_state = self.window_state.lock(); window_state.fullscreen.clone() } @@ -408,8 +408,8 @@ impl Window { match &monitor { &Some(RootMonitorHandle { ref inner }) => { - let (x, y): (i32, i32) = inner.get_outer_position().into(); - let (width, height): (u32, u32) = inner.get_dimensions().into(); + let (x, y): (i32, i32) = inner.outer_position().into(); + let (width, height): (u32, u32) = inner.dimensions().into(); let mut monitor = monitor.clone(); self.thread_executor.execute_in_thread(move || { @@ -491,9 +491,9 @@ impl Window { } #[inline] - pub fn get_current_monitor(&self) -> RootMonitorHandle { + pub fn current_monitor(&self) -> RootMonitorHandle { RootMonitorHandle { - inner: monitor::get_current_monitor(self.window.0), + inner: monitor::current_monitor(self.window.0), } } @@ -607,11 +607,11 @@ unsafe fn init( let class_name = register_window_class(&window_icon, &taskbar_icon); let guessed_dpi_factor = { - let monitors = monitor::get_available_monitors(); + let monitors = monitor::available_monitors(); let dpi_factor = if !monitors.is_empty() { - let mut dpi_factor = Some(monitors[0].get_hidpi_factor()); + let mut dpi_factor = Some(monitors[0].hidpi_factor()); for monitor in &monitors { - if Some(monitor.get_hidpi_factor()) != dpi_factor { + if Some(monitor.hidpi_factor()) != dpi_factor { dpi_factor = None; } } @@ -625,7 +625,7 @@ unsafe fn init( let mut dpi_factor = None; for monitor in &monitors { if monitor.contains_point(&cursor_pos) { - dpi_factor = Some(monitor.get_hidpi_factor()); + dpi_factor = Some(monitor.hidpi_factor()); break; } } @@ -683,7 +683,7 @@ unsafe fn init( } } - let dpi = get_hwnd_dpi(real_window.0); + let dpi = hwnd_dpi(real_window.0); let dpi_factor = dpi_to_scale_factor(dpi); if dpi_factor != guessed_dpi_factor { let (width, height): (u32, u32) = dimensions.into(); diff --git a/src/window.rs b/src/window.rs index 0f86c5691f..27fedbb022 100644 --- a/src/window.rs +++ b/src/window.rs @@ -287,7 +287,7 @@ impl WindowBuilder { self.window.inner_size = Some(self.window.inner_size.unwrap_or_else(|| { if let Some(ref monitor) = self.window.fullscreen { // resizing the window to the dimensions of the monitor when fullscreen - LogicalSize::from_physical(monitor.get_dimensions(), 1.0) + LogicalSize::from_physical(monitor.dimensions(), 1.0) } else { // default dimensions (1024, 768).into() @@ -360,22 +360,22 @@ impl Window { /// /// Returns `None` if the window no longer exists. #[inline] - pub fn get_outer_position(&self) -> Option { - self.window.get_outer_position() + pub fn outer_position(&self) -> Option { + self.window.outer_position() } /// Returns the position of the top-left hand corner of the window's client area relative to the /// top-left hand corner of the desktop. /// - /// The same conditions that apply to `get_outer_position` apply to this method. + /// The same conditions that apply to `outer_position` apply to this method. #[inline] - pub fn get_inner_position(&self) -> Option { - self.window.get_inner_position() + pub fn inner_position(&self) -> Option { + self.window.inner_position() } /// Modifies the position of the window. /// - /// See `get_outer_position` for more information about the coordinates. + /// See `outer_position` for more information about the coordinates. /// /// This is a no-op if the window has already been closed. #[inline] @@ -391,24 +391,24 @@ impl Window { /// /// Returns `None` if the window no longer exists. #[inline] - pub fn get_inner_size(&self) -> Option { - self.window.get_inner_size() + pub fn inner_size(&self) -> Option { + self.window.inner_size() } /// Returns the logical size of the entire window. /// /// These dimensions include the title bar and borders. If you don't want that (and you usually don't), - /// use `get_inner_size` instead. + /// use `inner_size` instead. /// /// Returns `None` if the window no longer exists. #[inline] - pub fn get_outer_size(&self) -> Option { - self.window.get_outer_size() + pub fn outer_size(&self) -> Option { + self.window.outer_size() } /// Modifies the inner size of the window. /// - /// See `get_inner_size` for more information about the values. + /// See `inner_size` for more information about the values. /// /// This is a no-op if the window has already been closed. #[inline] @@ -456,8 +456,8 @@ impl Window { /// - **X11:** This respects Xft.dpi, and can be overridden using the `WINIT_HIDPI_FACTOR` environment variable. /// - **Android:** Always returns 1.0. #[inline] - pub fn get_hidpi_factor(&self) -> f64 { - self.window.get_hidpi_factor() + pub fn hidpi_factor(&self) -> f64 { + self.window.hidpi_factor() } /// Modifies the mouse cursor of the window. @@ -514,8 +514,8 @@ impl Window { /// Gets the window's current fullscreen state. #[inline] - pub fn get_fullscreen(&self) -> Option { - self.window.get_fullscreen() + pub fn fullscreen(&self) -> Option { + self.window.fullscreen() } /// Turn window decorations on or off. @@ -551,25 +551,25 @@ impl Window { /// Returns the monitor on which the window currently resides #[inline] - pub fn get_current_monitor(&self) -> MonitorHandle { - self.window.get_current_monitor() + pub fn current_monitor(&self) -> MonitorHandle { + self.window.current_monitor() } /// Returns the list of all the monitors available on the system. /// - /// This is the same as `EventLoop::get_available_monitors`, and is provided for convenience. + /// This is the same as `EventLoop::available_monitors`, and is provided for convenience. #[inline] - pub fn get_available_monitors(&self) -> AvailableMonitorsIter { - let data = self.window.get_available_monitors(); + pub fn available_monitors(&self) -> AvailableMonitorsIter { + let data = self.window.available_monitors(); AvailableMonitorsIter { data: data.into_iter() } } /// Returns the primary monitor of the system. /// - /// This is the same as `EventLoop::get_primary_monitor`, and is provided for convenience. + /// This is the same as `EventLoop::primary_monitor`, and is provided for convenience. #[inline] - pub fn get_primary_monitor(&self) -> MonitorHandle { - MonitorHandle { inner: self.window.get_primary_monitor() } + pub fn primary_monitor(&self) -> MonitorHandle { + MonitorHandle { inner: self.window.primary_monitor() } } /// Returns an identifier unique to the window. From 45b941bf471e4fbb89f48c7c23e1b3f676deb091 Mon Sep 17 00:00:00 2001 From: Osspial Date: Wed, 22 May 2019 18:07:01 -0400 Subject: [PATCH 06/22] Make changes to Window position and size function signatures --- src/error.rs | 2 + src/platform_impl/ios/mod.rs | 16 ++--- src/platform_impl/linux/mod.rs | 10 +-- src/platform_impl/linux/wayland/window.rs | 18 +++-- .../linux/x11/event_processor.rs | 5 +- src/platform_impl/linux/x11/window.rs | 64 ++++++++--------- src/platform_impl/macos/window.rs | 18 ++--- src/platform_impl/windows/window.rs | 70 +++++++++---------- src/window.rs | 22 ++---- 9 files changed, 101 insertions(+), 124 deletions(-) diff --git a/src/error.rs b/src/error.rs index eb848b2435..49aca4b81c 100644 --- a/src/error.rs +++ b/src/error.rs @@ -5,6 +5,8 @@ pub enum ExternalError { Os(OsError), } +/// TODO: MANUALLY IMPLEMENT TRAITS +#[derive(Debug)] pub struct NotSupportedError { _marker: (), } diff --git a/src/platform_impl/ios/mod.rs b/src/platform_impl/ios/mod.rs index cb606e2aeb..017c0e1bd9 100644 --- a/src/platform_impl/ios/mod.rs +++ b/src/platform_impl/ios/mod.rs @@ -393,15 +393,13 @@ impl Window { } #[inline] - pub fn outer_position(&self) -> Option { - // N/A - None + pub fn outer_position(&self) -> Result { + Err(NotSupportedError::new()) } #[inline] - pub fn inner_position(&self) -> Option { - // N/A - None + pub fn inner_position(&self) -> Result { + Err(NotSupportedError::new()) } #[inline] @@ -410,12 +408,12 @@ impl Window { } #[inline] - pub fn inner_size(&self) -> Option { - Some(self.delegate_state.size) + pub fn inner_size(&self) -> LogicalSize { + self.delegate_state.size } #[inline] - pub fn outer_size(&self) -> Option { + pub fn outer_size(&self) -> LogicalSize { self.inner_size() } diff --git a/src/platform_impl/linux/mod.rs b/src/platform_impl/linux/mod.rs index f62966e374..c142052580 100644 --- a/src/platform_impl/linux/mod.rs +++ b/src/platform_impl/linux/mod.rs @@ -11,7 +11,7 @@ use sctk::reexports::client::ConnectError; use dpi::{LogicalPosition, LogicalSize, PhysicalPosition, PhysicalSize}; use icon::Icon; -use error::ExternalError; +use error::{ExternalError, NotSupportedError}; use event::Event; use event_loop::{EventLoopClosed, ControlFlow, EventLoopWindowTarget as RootELW}; use monitor::MonitorHandle as RootMonitorHandle; @@ -176,7 +176,7 @@ impl Window { } #[inline] - pub fn outer_position(&self) -> Option { + pub fn outer_position(&self) -> Result { match self { &Window::X(ref w) => w.outer_position(), &Window::Wayland(ref w) => w.outer_position(), @@ -184,7 +184,7 @@ impl Window { } #[inline] - pub fn inner_position(&self) -> Option { + pub fn inner_position(&self) -> Result { match self { &Window::X(ref m) => m.inner_position(), &Window::Wayland(ref m) => m.inner_position(), @@ -200,7 +200,7 @@ impl Window { } #[inline] - pub fn inner_size(&self) -> Option { + pub fn inner_size(&self) -> LogicalSize { match self { &Window::X(ref w) => w.inner_size(), &Window::Wayland(ref w) => w.inner_size(), @@ -208,7 +208,7 @@ impl Window { } #[inline] - pub fn outer_size(&self) -> Option { + pub fn outer_size(&self) -> LogicalSize { match self { &Window::X(ref w) => w.outer_size(), &Window::Wayland(ref w) => w.outer_size(), diff --git a/src/platform_impl/linux/wayland/window.rs b/src/platform_impl/linux/wayland/window.rs index 7554d6c77d..ebcb652e9c 100644 --- a/src/platform_impl/linux/wayland/window.rs +++ b/src/platform_impl/linux/wayland/window.rs @@ -160,15 +160,13 @@ impl Window { } #[inline] - pub fn outer_position(&self) -> Option { - // Not possible with wayland - None + pub fn outer_position(&self) -> Result { + Err(NotSupportedError::new()) } #[inline] - pub fn inner_position(&self) -> Option { - // Not possible with wayland - None + pub fn inner_position(&self) -> Result { + Err(NotSupportedError::new()) } #[inline] @@ -176,8 +174,8 @@ impl Window { // Not possible with wayland } - pub fn inner_size(&self) -> Option { - Some(self.size.lock().unwrap().clone().into()) + pub fn inner_size(&self) -> LogicalSize { + self.size.lock().unwrap().clone().into() } pub fn request_redraw(&self) { @@ -185,10 +183,10 @@ impl Window { } #[inline] - pub fn outer_size(&self) -> Option { + pub fn outer_size(&self) -> LogicalSize { let (w, h) = self.size.lock().unwrap().clone(); // let (w, h) = super::wayland_window::add_borders(w as i32, h as i32); - Some((w, h).into()) + (w, h).into() } #[inline] diff --git a/src/platform_impl/linux/x11/event_processor.rs b/src/platform_impl/linux/x11/event_processor.rs index dcd4e9f184..19332dc957 100644 --- a/src/platform_impl/linux/x11/event_processor.rs +++ b/src/platform_impl/linux/x11/event_processor.rs @@ -975,10 +975,7 @@ impl EventProcessor { new_monitor.hidpi_factor ), }); - let (width, height) = match window.inner_size_physical() { - Some(result) => result, - None => continue, - }; + let (width, height) = window.inner_size_physical(); let (_, _, flusher) = window.adjust_for_dpi( prev_monitor.hidpi_factor, new_monitor.hidpi_factor, diff --git a/src/platform_impl/linux/x11/window.rs b/src/platform_impl/linux/x11/window.rs index b303bf8391..6ce2c8f35c 100644 --- a/src/platform_impl/linux/x11/window.rs +++ b/src/platform_impl/linux/x11/window.rs @@ -8,7 +8,7 @@ use std::sync::Arc; use libc; use parking_lot::Mutex; -use error::ExternalError; +use error::{ExternalError, NotSupportedError}; use window::{Icon, MouseCursor, WindowAttributes}; use window::CreationError; use dpi::{LogicalPosition, LogicalSize}; @@ -533,7 +533,7 @@ impl UnownedWindow { }, Some(RootMonitorHandle { inner: PlatformMonitorHandle::X(monitor) }) => { let window_position = self.outer_position_physical(); - self.shared_state.lock().restore_position = window_position; + self.shared_state.lock().restore_position = Some(window_position); let monitor_origin: (i32, i32) = monitor.outer_position().into(); self.set_position_inner(monitor_origin.0, monitor_origin.1).queue(); self.set_fullscreen_hint(true) @@ -556,13 +556,11 @@ impl UnownedWindow { self.invalidate_cached_frame_extents(); } - fn get_rect(&self) -> Option { + fn get_rect(&self) -> util::AaRect { // TODO: This might round-trip more times than needed. - if let (Some(position), Some(size)) = (self.outer_position_physical(), self.outer_size_physical()) { - Some(util::AaRect::new(position, size)) - } else { - None - } + let position = self.outer_position_physical(); + let size = self.outer_size_physical(); + util::AaRect::new(position, size) } #[inline] @@ -574,7 +572,7 @@ impl UnownedWindow { .cloned(); monitor .unwrap_or_else(|| { - let monitor = self.xconn.get_monitor_for_window(self.get_rect()).to_owned(); + let monitor = self.xconn.get_monitor_for_window(Some(self.get_rect())).to_owned(); self.shared_state.lock().last_monitor = Some(monitor.clone()); monitor }) @@ -723,11 +721,11 @@ impl UnownedWindow { (*self.shared_state.lock()).frame_extents.take(); } - pub(crate) fn outer_position_physical(&self) -> Option<(i32, i32)> { + pub(crate) fn outer_position_physical(&self) -> (i32, i32) { let extents = (*self.shared_state.lock()).frame_extents.clone(); if let Some(extents) = extents { - self.inner_position_physical() - .map(|(x, y)| extents.inner_pos_to_outer(x, y)) + let (x, y) = self.inner_position_physical(); + extents.inner_pos_to_outer(x, y) } else { self.update_cached_frame_extents(); self.outer_position_physical() @@ -735,27 +733,28 @@ impl UnownedWindow { } #[inline] - pub fn outer_position(&self) -> Option { + pub fn outer_position(&self) -> Result { let extents = (*self.shared_state.lock()).frame_extents.clone(); if let Some(extents) = extents { - self.inner_position() - .map(|logical| extents.inner_pos_to_outer_logical(logical, self.hidpi_factor())) + let logical = self.inner_position().unwrap(); + Ok(extents.inner_pos_to_outer_logical(logical, self.hidpi_factor())) } else { self.update_cached_frame_extents(); self.outer_position() } } - pub(crate) fn inner_position_physical(&self) -> Option<(i32, i32)> { + pub(crate) fn inner_position_physical(&self) -> (i32, i32) { + // This should be okay to unwrap since the only error XTranslateCoordinates can return + // is BadWindow, and if the window handle is bad we have bigger problems. self.xconn.translate_coords(self.xwindow, self.root) - .ok() .map(|coords| (coords.x_rel_root, coords.y_rel_root)) + .unwrap() } #[inline] - pub fn inner_position(&self) -> Option { - self.inner_position_physical() - .map(|coords| self.logicalize_coords(coords)) + pub fn inner_position(&self) -> Result { + Ok(self.logicalize_coords(self.inner_position_physical())) } pub(crate) fn set_position_inner(&self, mut x: i32, mut y: i32) -> util::Flusher { @@ -794,23 +793,24 @@ impl UnownedWindow { self.set_position_physical(x, y); } - pub(crate) fn inner_size_physical(&self) -> Option<(u32, u32)> { + pub(crate) fn inner_size_physical(&self) -> (u32, u32) { + // This should be okay to unwrap since the only error XGetGeometry can return + // is BadWindow, and if the window handle is bad we have bigger problems. self.xconn.get_geometry(self.xwindow) - .ok() .map(|geo| (geo.width, geo.height)) + .unwrap() } #[inline] - pub fn inner_size(&self) -> Option { - self.inner_size_physical() - .map(|size| self.logicalize_size(size)) + pub fn inner_size(&self) -> LogicalSize { + self.logicalize_size(self.inner_size_physical()) } - pub(crate) fn outer_size_physical(&self) -> Option<(u32, u32)> { + pub(crate) fn outer_size_physical(&self) -> (u32, u32) { let extents = self.shared_state.lock().frame_extents.clone(); if let Some(extents) = extents { - self.inner_size_physical() - .map(|(w, h)| extents.inner_size_to_outer(w, h)) + let (w, h) = self.inner_size_physical(); + extents.inner_size_to_outer(w, h) } else { self.update_cached_frame_extents(); self.outer_size_physical() @@ -818,11 +818,11 @@ impl UnownedWindow { } #[inline] - pub fn outer_size(&self) -> Option { + pub fn outer_size(&self) -> LogicalSize { let extents = self.shared_state.lock().frame_extents.clone(); if let Some(extents) = extents { - self.inner_size() - .map(|logical| extents.inner_size_to_outer_logical(logical, self.hidpi_factor())) + let logical = self.inner_size(); + extents.inner_size_to_outer_logical(logical, self.hidpi_factor()) } else { self.update_cached_frame_extents(); self.outer_size() @@ -933,7 +933,7 @@ impl UnownedWindow { let shared_state_lock = self.shared_state.lock(); (shared_state_lock.min_inner_size, shared_state_lock.max_inner_size) } else { - let window_size = self.inner_size(); + let window_size = Some(self.inner_size()); (window_size.clone(), window_size) }; diff --git a/src/platform_impl/macos/window.rs b/src/platform_impl/macos/window.rs index 23f7d4ef8e..f4707bf981 100644 --- a/src/platform_impl/macos/window.rs +++ b/src/platform_impl/macos/window.rs @@ -17,7 +17,7 @@ use objc::{runtime::{Class, Object, Sel, BOOL, YES, NO}, declare::ClassDecl}; use { dpi::{LogicalPosition, LogicalSize}, icon::Icon, - error::ExternalError, + error::{ExternalError, NotSupportedError}, monitor::MonitorHandle as RootMonitorHandle, window::{ CreationError, MouseCursor, WindowAttributes, WindowId as RootWindowId, @@ -394,22 +394,22 @@ impl UnownedWindow { AppState::queue_redraw(RootWindowId(self.id())); } - pub fn outer_position(&self) -> Option { + pub fn outer_position(&self) -> Result { let frame_rect = unsafe { NSWindow::frame(*self.nswindow) }; - Some(( + Ok(( frame_rect.origin.x as f64, util::bottom_left_to_top_left(frame_rect), ).into()) } - pub fn inner_position(&self) -> Option { + pub fn inner_position(&self) -> Result { let content_rect = unsafe { NSWindow::contentRectForFrameRect_( *self.nswindow, NSWindow::frame(*self.nswindow), ) }; - Some(( + Ok(( content_rect.origin.x as f64, util::bottom_left_to_top_left(content_rect), ).into()) @@ -431,15 +431,15 @@ impl UnownedWindow { } #[inline] - pub fn inner_size(&self) -> Option { + pub fn inner_size(&self) -> LogicalSize { let view_frame = unsafe { NSView::frame(*self.nsview) }; - Some((view_frame.size.width as f64, view_frame.size.height as f64).into()) + (view_frame.size.width as f64, view_frame.size.height as f64).into() } #[inline] - pub fn outer_size(&self) -> Option { + pub fn outer_size(&self) -> LogicalSize { let view_frame = unsafe { NSWindow::frame(*self.nswindow) }; - Some((view_frame.size.width as f64, view_frame.size.height as f64).into()) + (view_frame.size.width as f64, view_frame.size.height as f64).into() } #[inline] diff --git a/src/platform_impl/windows/window.rs b/src/platform_impl/windows/window.rs index f6624e1f7a..36e6a83046 100644 --- a/src/platform_impl/windows/window.rs +++ b/src/platform_impl/windows/window.rs @@ -19,7 +19,7 @@ use winapi::um::oleidl::LPDROPTARGET; use winapi::um::winnt::{LONG, LPCWSTR}; use window::{CreationError, Icon, MouseCursor, WindowAttributes}; -use error::ExternalError; +use error::{ExternalError, NotSupportedError}; use dpi::{LogicalPosition, LogicalSize, PhysicalSize}; use monitor::MonitorHandle as RootMonitorHandle; use platform_impl::platform::{ @@ -127,35 +127,32 @@ impl Window { } } - pub(crate) fn outer_position_physical(&self) -> Option<(i32, i32)> { + pub(crate) fn outer_position_physical(&self) -> (i32, i32) { util::get_window_rect(self.window.0) .map(|rect| (rect.left as i32, rect.top as i32)) + .unwrap() } #[inline] - pub fn outer_position(&self) -> Option { - self.outer_position_physical() - .map(|physical_position| { - let dpi_factor = self.hidpi_factor(); - LogicalPosition::from_physical(physical_position, dpi_factor) - }) + pub fn outer_position(&self) -> Result { + let physical_position = self.outer_position_physical(); + let dpi_factor = self.hidpi_factor(); + Ok(LogicalPosition::from_physical(physical_position, dpi_factor)) } - pub(crate) fn inner_position_physical(&self) -> Option<(i32, i32)> { + pub(crate) fn inner_position_physical(&self) -> (i32, i32) { let mut position: POINT = unsafe { mem::zeroed() }; if unsafe { winuser::ClientToScreen(self.window.0, &mut position) } == 0 { - return None; + panic!("Unexpected ClientToScreen failure: please report this error to https://github.com/rust-windowing/winit") } - Some((position.x, position.y)) + (position.x, position.y) } #[inline] - pub fn inner_position(&self) -> Option { - self.inner_position_physical() - .map(|physical_position| { - let dpi_factor = self.hidpi_factor(); - LogicalPosition::from_physical(physical_position, dpi_factor) - }) + pub fn inner_position(&self) -> Result { + let physical_position = self.inner_position_physical(); + let dpi_factor = self.hidpi_factor(); + Ok(LogicalPosition::from_physical(physical_position, dpi_factor)) } pub(crate) fn set_position_physical(&self, x: i32, y: i32) { @@ -180,41 +177,38 @@ impl Window { self.set_position_physical(x, y); } - pub(crate) fn inner_size_physical(&self) -> Option<(u32, u32)> { + pub(crate) fn inner_size_physical(&self) -> (u32, u32) { let mut rect: RECT = unsafe { mem::uninitialized() }; if unsafe { winuser::GetClientRect(self.window.0, &mut rect) } == 0 { - return None; + panic!("Unexpected GetClientRect failure: please report this error to https://github.com/rust-windowing/winit") } - Some(( + ( (rect.right - rect.left) as u32, (rect.bottom - rect.top) as u32, - )) + ) } #[inline] - pub fn inner_size(&self) -> Option { - self.inner_size_physical() - .map(|physical_size| { - let dpi_factor = self.hidpi_factor(); - LogicalSize::from_physical(physical_size, dpi_factor) - }) + pub fn inner_size(&self) -> LogicalSize { + let physical_size = self.inner_size_physical(); + let dpi_factor = self.hidpi_factor(); + LogicalSize::from_physical(physical_size, dpi_factor) } - pub(crate) fn outer_size_physical(&self) -> Option<(u32, u32)> { + pub(crate) fn outer_size_physical(&self) -> (u32, u32) { util::get_window_rect(self.window.0) .map(|rect| ( (rect.right - rect.left) as u32, (rect.bottom - rect.top) as u32, )) + .unwrap() } #[inline] - pub fn outer_size(&self) -> Option { - self.outer_size_physical() - .map(|physical_size| { - let dpi_factor = self.hidpi_factor(); - LogicalSize::from_physical(physical_size, dpi_factor) - }) + pub fn outer_size(&self) -> LogicalSize { + let physical_size = self.outer_size_physical(); + let dpi_factor = self.hidpi_factor(); + LogicalSize::from_physical(physical_size, dpi_factor) } pub(crate) fn set_inner_size_physical(&self, x: u32, y: u32) { @@ -257,8 +251,8 @@ impl Window { pub(crate) fn set_min_inner_size_physical(&self, dimensions: Option<(u32, u32)>) { self.window_state.lock().min_size = dimensions.map(Into::into); // Make windows re-check the window size bounds. - self.inner_size_physical() - .map(|(width, height)| self.set_inner_size_physical(width, height)); + let (width, height) = self.inner_size_physical(); + self.set_inner_size_physical(width, height); } #[inline] @@ -273,8 +267,8 @@ impl Window { pub fn set_max_inner_size_physical(&self, dimensions: Option<(u32, u32)>) { self.window_state.lock().max_size = dimensions.map(Into::into); // Make windows re-check the window size bounds. - self.inner_size_physical() - .map(|(width, height)| self.set_inner_size_physical(width, height)); + let (width, height) = self.inner_size_physical(); + self.set_inner_size_physical(width, height); } #[inline] diff --git a/src/window.rs b/src/window.rs index 27fedbb022..535206f558 100644 --- a/src/window.rs +++ b/src/window.rs @@ -2,7 +2,7 @@ use std::{fmt, error}; use platform_impl; -use error::ExternalError; +use error::{ExternalError, NotSupportedError}; use event_loop::EventLoopWindowTarget; use monitor::{AvailableMonitorsIter, MonitorHandle}; use dpi::{LogicalPosition, LogicalSize}; @@ -317,8 +317,6 @@ impl Window { } /// Modifies the title of the window. - /// - /// This is a no-op if the window has already been closed. #[inline] pub fn set_title(&self, title: &str) { self.window.set_title(title) @@ -357,10 +355,8 @@ impl Window { /// /// The coordinates can be negative if the top-left hand corner of the window is outside /// of the visible screen region. - /// - /// Returns `None` if the window no longer exists. #[inline] - pub fn outer_position(&self) -> Option { + pub fn outer_position(&self) -> Result { self.window.outer_position() } @@ -369,15 +365,13 @@ impl Window { /// /// The same conditions that apply to `outer_position` apply to this method. #[inline] - pub fn inner_position(&self) -> Option { + pub fn inner_position(&self) -> Result { self.window.inner_position() } /// Modifies the position of the window. /// /// See `outer_position` for more information about the coordinates. - /// - /// This is a no-op if the window has already been closed. #[inline] pub fn set_outer_position(&self, position: LogicalPosition) { self.window.set_outer_position(position) @@ -388,10 +382,8 @@ impl Window { /// The client area is the content of the window, excluding the title bar and borders. /// /// Converting the returned `LogicalSize` to `PhysicalSize` produces the size your framebuffer should be. - /// - /// Returns `None` if the window no longer exists. #[inline] - pub fn inner_size(&self) -> Option { + pub fn inner_size(&self) -> LogicalSize { self.window.inner_size() } @@ -399,18 +391,14 @@ impl Window { /// /// These dimensions include the title bar and borders. If you don't want that (and you usually don't), /// use `inner_size` instead. - /// - /// Returns `None` if the window no longer exists. #[inline] - pub fn outer_size(&self) -> Option { + pub fn outer_size(&self) -> LogicalSize { self.window.outer_size() } /// Modifies the inner size of the window. /// /// See `inner_size` for more information about the values. - /// - /// This is a no-op if the window has already been closed. #[inline] pub fn set_inner_size(&self, size: LogicalSize) { self.window.set_inner_size(size) From 61e2812fd122a7319f890533a2c9418ec1a3fac2 Mon Sep 17 00:00:00 2001 From: Osspial Date: Wed, 22 May 2019 19:57:09 -0400 Subject: [PATCH 07/22] Remove CreationError in favor of OsError --- src/platform_impl/linux/mod.rs | 6 +-- src/platform_impl/linux/wayland/window.rs | 6 +-- src/platform_impl/linux/x11/ime/mod.rs | 3 +- src/platform_impl/linux/x11/mod.rs | 5 +- src/platform_impl/linux/x11/window.rs | 20 ++++---- src/platform_impl/macos/mod.rs | 6 ++- src/platform_impl/macos/window.rs | 12 ++--- src/platform_impl/windows/icon.rs | 13 +++--- src/platform_impl/windows/monitor.rs | 6 +-- src/platform_impl/windows/util.rs | 57 +---------------------- src/platform_impl/windows/window.rs | 29 +++++------- src/window.rs | 34 ++------------ 12 files changed, 59 insertions(+), 138 deletions(-) diff --git a/src/platform_impl/linux/mod.rs b/src/platform_impl/linux/mod.rs index c142052580..7fff1988e3 100644 --- a/src/platform_impl/linux/mod.rs +++ b/src/platform_impl/linux/mod.rs @@ -11,11 +11,11 @@ use sctk::reexports::client::ConnectError; use dpi::{LogicalPosition, LogicalSize, PhysicalPosition, PhysicalSize}; use icon::Icon; -use error::{ExternalError, NotSupportedError}; +use error::{ExternalError, NotSupportedError, OsError as RootOsError}; use event::Event; use event_loop::{EventLoopClosed, ControlFlow, EventLoopWindowTarget as RootELW}; use monitor::MonitorHandle as RootMonitorHandle; -use window::{WindowAttributes, CreationError, MouseCursor}; +use window::{WindowAttributes, MouseCursor}; use self::x11::{XConnection, XError}; use self::x11::ffi::XVisualInfo; pub use self::x11::XNotSupported; @@ -140,7 +140,7 @@ impl Window { window_target: &EventLoopWindowTarget, attribs: WindowAttributes, pl_attribs: PlatformSpecificWindowBuilderAttributes, - ) -> Result { + ) -> Result { match *window_target { EventLoopWindowTarget::Wayland(ref window_target) => { wayland::Window::new(window_target, attribs, pl_attribs).map(Window::Wayland) diff --git a/src/platform_impl/linux/wayland/window.rs b/src/platform_impl/linux/wayland/window.rs index ebcb652e9c..509a31224b 100644 --- a/src/platform_impl/linux/wayland/window.rs +++ b/src/platform_impl/linux/wayland/window.rs @@ -2,10 +2,10 @@ use std::collections::VecDeque; use std::sync::{Arc, Mutex, Weak}; use dpi::{LogicalPosition, LogicalSize}; -use error::{ExternalError, NotSupportedError}; +use error::{ExternalError, NotSupportedError, OsError as RootOsError}; use platform_impl::{MonitorHandle as PlatformMonitorHandle, PlatformSpecificWindowBuilderAttributes as PlAttributes}; use monitor::MonitorHandle as RootMonitorHandle; -use window::{CreationError, WindowAttributes, MouseCursor}; +use window::{WindowAttributes, MouseCursor}; use sctk::surface::{get_dpi_factor, get_outputs}; use sctk::window::{ConceptFrame, Event as WEvent, State as WState, Window as SWindow, Theme}; @@ -29,7 +29,7 @@ pub struct Window { } impl Window { - pub fn new(evlp: &EventLoopWindowTarget, attributes: WindowAttributes, pl_attribs: PlAttributes) -> Result { + pub fn new(evlp: &EventLoopWindowTarget, attributes: WindowAttributes, pl_attribs: PlAttributes) -> Result { let (width, height) = attributes.inner_size.map(Into::into).unwrap_or((800, 600)); // Create the window let size = Arc::new(Mutex::new((width, height))); diff --git a/src/platform_impl/linux/x11/ime/mod.rs b/src/platform_impl/linux/x11/ime/mod.rs index 2298050cd0..73aad7c978 100644 --- a/src/platform_impl/linux/x11/ime/mod.rs +++ b/src/platform_impl/linux/x11/ime/mod.rs @@ -12,8 +12,9 @@ use super::{ffi, util, XConnection, XError}; use self::inner::{close_im, ImeInner}; use self::input_method::PotentialInputMethods; -use self::context::{ImeContextCreationError, ImeContext}; +use self::context::ImeContext; use self::callbacks::*; +pub use self::context::ImeContextCreationError; pub type ImeReceiver = Receiver<(ffi::Window, i16, i16)>; pub type ImeSender = Sender<(ffi::Window, i16, i16)>; diff --git a/src/platform_impl/linux/x11/mod.rs b/src/platform_impl/linux/x11/mod.rs index f6e42f5126..bd2103abc7 100644 --- a/src/platform_impl/linux/x11/mod.rs +++ b/src/platform_impl/linux/x11/mod.rs @@ -25,11 +25,12 @@ use std::sync::{Arc, mpsc, Weak, Mutex}; use libc::{self, setlocale, LC_CTYPE}; +use error::OsError as RootOsError; use event_loop::{ControlFlow, EventLoopClosed, EventLoopWindowTarget as RootELW}; use event::{WindowEvent, Event}; use platform_impl::PlatformSpecificWindowBuilderAttributes; use platform_impl::platform::sticky_exit_callback; -use window::{CreationError, WindowAttributes}; +use window::{WindowAttributes}; use self::dnd::{Dnd, DndState}; use self::ime::{ImeReceiver, ImeSender, ImeCreationError, Ime}; use self::event_processor::EventProcessor; @@ -427,7 +428,7 @@ impl Window { event_loop: &EventLoopWindowTarget, attribs: WindowAttributes, pl_attribs: PlatformSpecificWindowBuilderAttributes - ) -> Result { + ) -> Result { let window = Arc::new(UnownedWindow::new(&event_loop, attribs, pl_attribs)?); event_loop.windows .borrow_mut() diff --git a/src/platform_impl/linux/x11/window.rs b/src/platform_impl/linux/x11/window.rs index 6ce2c8f35c..238d4fac5b 100644 --- a/src/platform_impl/linux/x11/window.rs +++ b/src/platform_impl/linux/x11/window.rs @@ -8,12 +8,12 @@ use std::sync::Arc; use libc; use parking_lot::Mutex; -use error::{ExternalError, NotSupportedError}; +use error::{ExternalError, NotSupportedError, OsError as RootOsError}; use window::{Icon, MouseCursor, WindowAttributes}; -use window::CreationError; use dpi::{LogicalPosition, LogicalSize}; use platform_impl::MonitorHandle as PlatformMonitorHandle; use platform_impl::{OsError, PlatformSpecificWindowBuilderAttributes}; +use platform_impl::x11::ime::ImeContextCreationError; use platform_impl::x11::MonitorHandle as X11MonitorHandle; use monitor::MonitorHandle as RootMonitorHandle; @@ -76,7 +76,7 @@ impl UnownedWindow { event_loop: &EventLoopWindowTarget, window_attrs: WindowAttributes, pl_attribs: PlatformSpecificWindowBuilderAttributes, - ) -> Result { + ) -> Result { let xconn = &event_loop.xconn; let root = event_loop.root; @@ -105,7 +105,7 @@ impl UnownedWindow { .unwrap_or(1.0) }) } else { - return Err(CreationError::OsError(format!("No monitors were detected."))); + return Err(os_error!(OsError::XMisc("No monitors were detected."))); }; info!("Guessed window DPI factor: {}", dpi_factor); @@ -346,7 +346,7 @@ impl UnownedWindow { &mut supported_ptr, ); if supported_ptr == ffi::False { - return Err(CreationError::OsError(format!("`XkbSetDetectableAutoRepeat` failed"))); + return Err(os_error!(OsError::XMisc("`XkbSetDetectableAutoRepeat` failed"))); } } @@ -373,7 +373,11 @@ impl UnownedWindow { .borrow_mut() .create_context(window.xwindow); if let Err(err) = result { - return Err(CreationError::OsError(format!("Failed to create input context: {:?}", err))); + let e = match err { + ImeContextCreationError::XError(err) => OsError::XError(err), + ImeContextCreationError::Null => OsError::XMisc("IME Context creation failed"), + }; + return Err(os_error!(e)); } } @@ -412,9 +416,7 @@ impl UnownedWindow { // We never want to give the user a broken window, since by then, it's too late to handle. xconn.sync_with_server() .map(|_| window) - .map_err(|x_err| CreationError::OsError( - format!("X server returned error while building window: {:?}", x_err) - )) + .map_err(|x_err| os_error!(OsError::XError(x_err))) } fn logicalize_coords(&self, (x, y): (i32, i32)) -> LogicalPosition { diff --git a/src/platform_impl/macos/mod.rs b/src/platform_impl/macos/mod.rs index 2765d8e44d..e4558f612c 100644 --- a/src/platform_impl/macos/mod.rs +++ b/src/platform_impl/macos/mod.rs @@ -16,7 +16,8 @@ mod window_delegate; use std::{ops::Deref, sync::Arc}; use { - event::DeviceId as RootDeviceId, window::{CreationError, WindowAttributes}, + event::DeviceId as RootDeviceId, window::WindowAttributes, + error::OsError as RootOsError, }; pub use self::{ event_loop::{EventLoop, EventLoopWindowTarget, Proxy as EventLoopProxy}, @@ -46,6 +47,7 @@ pub struct Window { pub enum OsError { CGError(core_graphics::base::CGError), + CreationError(&'static str) } unsafe impl Send for Window {} @@ -64,7 +66,7 @@ impl Window { _window_target: &EventLoopWindowTarget, attributes: WindowAttributes, pl_attribs: PlatformSpecificWindowBuilderAttributes, - ) -> Result { + ) -> Result { let (window, _delegate) = UnownedWindow::new(attributes, pl_attribs)?; Ok(Window { window, _delegate }) } diff --git a/src/platform_impl/macos/window.rs b/src/platform_impl/macos/window.rs index f4707bf981..744f5003a8 100644 --- a/src/platform_impl/macos/window.rs +++ b/src/platform_impl/macos/window.rs @@ -17,10 +17,10 @@ use objc::{runtime::{Class, Object, Sel, BOOL, YES, NO}, declare::ClassDecl}; use { dpi::{LogicalPosition, LogicalSize}, icon::Icon, - error::{ExternalError, NotSupportedError}, + error::{ExternalError, NotSupportedError, OsError as RootOsError}, monitor::MonitorHandle as RootMonitorHandle, window::{ - CreationError, MouseCursor, WindowAttributes, WindowId as RootWindowId, + MouseCursor, WindowAttributes, WindowId as RootWindowId, }, }; use platform::macos::{ActivationPolicy, WindowExtMacOS}; @@ -257,7 +257,7 @@ impl UnownedWindow { pub fn new( mut win_attribs: WindowAttributes, pl_attribs: PlatformSpecificWindowBuilderAttributes, - ) -> Result<(Arc, IdRef), CreationError> { + ) -> Result<(Arc, IdRef), RootOsError> { unsafe { if !msg_send![class!(NSThread), isMainThread] { panic!("Windows can only be created on the main thread on macOS"); @@ -268,17 +268,17 @@ impl UnownedWindow { let nsapp = create_app(pl_attribs.activation_policy).ok_or_else(|| { unsafe { pool.drain() }; - CreationError::OsError(format!("Couldn't create `NSApplication`")) + os_error!(OsError::CreationError("Couldn't create `NSApplication`")) })?; let nswindow = create_window(&win_attribs, &pl_attribs).ok_or_else(|| { unsafe { pool.drain() }; - CreationError::OsError(format!("Couldn't create `NSWindow`")) + os_error!(OsError::CreationError("Couldn't create `NSWindow`")) })?; let (nsview, cursor) = unsafe { create_view(*nswindow) }.ok_or_else(|| { unsafe { pool.drain() }; - CreationError::OsError(format!("Couldn't create `NSView`")) + os_error!(OsError::CreationError("Couldn't create `NSView`")) })?; let input_context = unsafe { util::create_input_context(*nsview) }; diff --git a/src/platform_impl/windows/icon.rs b/src/platform_impl/windows/icon.rs index c45bdf6fde..3a617ceb04 100644 --- a/src/platform_impl/windows/icon.rs +++ b/src/platform_impl/windows/icon.rs @@ -1,4 +1,4 @@ -use std::{self, mem, ptr}; +use std::{mem, ptr, io}; use std::os::windows::ffi::OsStrExt; use std::path::Path; @@ -8,7 +8,6 @@ use winapi::shared::windef::{HICON, HWND}; use winapi::um::winuser; use icon::{Pixel, PIXEL_SIZE, Icon}; -use platform_impl::platform::util; impl Pixel { fn to_bgra(&mut self) { @@ -31,7 +30,7 @@ unsafe impl Send for WinIcon {} impl WinIcon { #[allow(dead_code)] - pub fn from_path>(path: P) -> Result { + pub fn from_path>(path: P) -> Result { let wide_path: Vec = path.as_ref().as_os_str().encode_wide().collect(); let handle = unsafe { winuser::LoadImageW( @@ -46,15 +45,15 @@ impl WinIcon { if !handle.is_null() { Ok(WinIcon { handle }) } else { - Err(util::WinError::from_last_error()) + Err(io::Error::last_os_error()) } } - pub fn from_icon(icon: Icon) -> Result { + pub fn from_icon(icon: Icon) -> Result { Self::from_rgba(icon.rgba, icon.width, icon.height) } - pub fn from_rgba(mut rgba: Vec, width: u32, height: u32) -> Result { + pub fn from_rgba(mut rgba: Vec, width: u32, height: u32) -> Result { assert_eq!(rgba.len() % PIXEL_SIZE, 0); let pixel_count = rgba.len() / PIXEL_SIZE; assert_eq!(pixel_count, (width * height) as usize); @@ -80,7 +79,7 @@ impl WinIcon { if !handle.is_null() { Ok(WinIcon { handle }) } else { - Err(util::WinError::from_last_error()) + Err(io::Error::last_os_error()) } } diff --git a/src/platform_impl/windows/monitor.rs b/src/platform_impl/windows/monitor.rs index d4ef520a23..83c2d412f8 100644 --- a/src/platform_impl/windows/monitor.rs +++ b/src/platform_impl/windows/monitor.rs @@ -3,7 +3,7 @@ use winapi::shared::windef::{HDC, HMONITOR, HWND, LPRECT, POINT}; use winapi::um::winnt::LONG; use winapi::um::winuser; -use std::{mem, ptr}; +use std::{mem, ptr, io}; use std::collections::VecDeque; use super::{EventLoop, util}; @@ -99,7 +99,7 @@ impl Window { } } -pub(crate) fn get_monitor_info(hmonitor: HMONITOR) -> Result { +pub(crate) fn get_monitor_info(hmonitor: HMONITOR) -> Result { let mut monitor_info: winuser::MONITORINFOEXW = unsafe { mem::uninitialized() }; monitor_info.cbSize = mem::size_of::() as DWORD; let status = unsafe { @@ -109,7 +109,7 @@ pub(crate) fn get_monitor_info(hmonitor: HMONITOR) -> Result(bitset: T, flag: T) -> bool @@ -117,45 +103,6 @@ pub fn is_focused(window: HWND) -> bool { window == unsafe{ winuser::GetActiveWindow() } } -#[derive(Debug, Default, Clone, PartialEq, Eq)] -pub struct WinError(Option); - -impl WinError { - pub fn from_last_error() -> Self { - WinError(unsafe { get_last_error() }) - } -} - -pub unsafe fn get_last_error() -> Option { - let err = GetLastError(); - if err != 0 { - let buf_addr: LPCWSTR = { - let mut buf_addr: LPCWSTR = mem::uninitialized(); - FormatMessageW( - FORMAT_MESSAGE_ALLOCATE_BUFFER - | FORMAT_MESSAGE_FROM_SYSTEM - | FORMAT_MESSAGE_IGNORE_INSERTS, - ptr::null(), - err, - MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT) as DWORD, - // This is a pointer to a pointer - &mut buf_addr as *mut LPCWSTR as *mut _, - 0, - ptr::null_mut(), - ); - buf_addr - }; - if !buf_addr.is_null() { - let buf_len = lstrlenW(buf_addr) as usize; - let buf_slice = std::slice::from_raw_parts(buf_addr, buf_len); - let string = wchar_to_string(buf_slice); - LocalFree(buf_addr as *mut _); - return Some(string); - } - } - None -} - impl MouseCursor { pub(crate) fn to_windows_cursor(self) -> *const wchar_t { match self { diff --git a/src/platform_impl/windows/window.rs b/src/platform_impl/windows/window.rs index 36e6a83046..5d6b8a0558 100644 --- a/src/platform_impl/windows/window.rs +++ b/src/platform_impl/windows/window.rs @@ -18,8 +18,8 @@ use winapi::um::wingdi::{CreateRectRgn, DeleteObject}; use winapi::um::oleidl::LPDROPTARGET; use winapi::um::winnt::{LONG, LPCWSTR}; -use window::{CreationError, Icon, MouseCursor, WindowAttributes}; -use error::{ExternalError, NotSupportedError}; +use window::{Icon, MouseCursor, WindowAttributes}; +use error::{ExternalError, NotSupportedError, OsError as RootOsError}; use dpi::{LogicalPosition, LogicalSize, PhysicalSize}; use monitor::MonitorHandle as RootMonitorHandle; use platform_impl::platform::{ @@ -51,7 +51,7 @@ impl Window { event_loop: &EventLoopWindowTarget, w_attr: WindowAttributes, pl_attr: PlatformSpecificWindowBuilderAttributes, - ) -> Result { + ) -> Result { // We dispatch an `init` function because of code style. // First person to remove the need for cloning here gets a cookie! // @@ -564,9 +564,9 @@ pub unsafe fn adjust_size( unsafe fn init( mut attributes: WindowAttributes, - mut pl_attribs: PlatformSpecificWindowBuilderAttributes, + pl_attribs: PlatformSpecificWindowBuilderAttributes, event_loop: &EventLoopWindowTarget, -) -> Result { +) -> Result { let title = OsStr::new(&attributes.title) .encode_wide() .chain(Some(0).into_iter()) @@ -576,22 +576,18 @@ unsafe fn init( let icon = attributes.window_icon .take() .map(WinIcon::from_icon); - if icon.is_some() { - Some(icon.unwrap().map_err(|err| { - CreationError::OsError(format!("Failed to create `ICON_SMALL`: {:?}", err)) - })?) + if let Some(icon) = icon { + Some(icon.map_err(|e| os_error!(e))?) } else { None } }; let taskbar_icon = { - let icon = pl_attribs.taskbar_icon + let icon = attributes.window_icon .take() .map(WinIcon::from_icon); - if icon.is_some() { - Some(icon.unwrap().map_err(|err| { - CreationError::OsError(format!("Failed to create `ICON_BIG`: {:?}", err)) - })?) + if let Some(icon) = icon { + Some(icon.map_err(|e| os_error!(e))?) } else { None } @@ -611,7 +607,7 @@ unsafe fn init( } dpi_factor } else { - return Err(CreationError::OsError(format!("No monitors were detected."))); + return Err(os_error!(io::Error::new(io::ErrorKind::NotFound, "No monitors were detected."))); }; dpi_factor.unwrap_or_else(|| { util::get_cursor_pos() @@ -659,8 +655,7 @@ unsafe fn init( ); if handle.is_null() { - return Err(CreationError::OsError(format!("CreateWindowEx function failed: {}", - format!("{}", io::Error::last_os_error())))); + return Err(os_error!(io::Error::last_os_error())); } WindowWrapper(handle) diff --git a/src/window.rs b/src/window.rs index 535206f558..19f0539830 100644 --- a/src/window.rs +++ b/src/window.rs @@ -1,8 +1,8 @@ //! The `Window` struct and associated types. -use std::{fmt, error}; +use std::fmt; use platform_impl; -use error::{ExternalError, NotSupportedError}; +use error::{ExternalError, NotSupportedError, OsError}; use event_loop::EventLoopWindowTarget; use monitor::{AvailableMonitorsIter, MonitorHandle}; use dpi::{LogicalPosition, LogicalSize}; @@ -283,7 +283,7 @@ impl WindowBuilder { /// Error should be very rare and only occur in case of permission denied, incompatible system, /// out of memory, etc. #[inline] - pub fn build(mut self, window_target: &EventLoopWindowTarget) -> Result { + pub fn build(mut self, window_target: &EventLoopWindowTarget) -> Result { self.window.inner_size = Some(self.window.inner_size.unwrap_or_else(|| { if let Some(ref monitor) = self.window.fullscreen { // resizing the window to the dimensions of the monitor when fullscreen @@ -311,7 +311,7 @@ impl Window { /// Error should be very rare and only occur in case of permission denied, incompatible system, /// out of memory, etc. #[inline] - pub fn new(event_loop: &EventLoopWindowTarget) -> Result { + pub fn new(event_loop: &EventLoopWindowTarget) -> Result { let builder = WindowBuilder::new(); builder.build(event_loop) } @@ -567,32 +567,6 @@ impl Window { } } -/// Error that can happen while creating a window or a headless renderer. -#[derive(Debug, Clone)] -pub enum CreationError { - OsError(String), -} - -impl CreationError { - fn to_string(&self) -> &str { - match *self { - CreationError::OsError(ref text) => &text, - } - } -} - -impl fmt::Display for CreationError { - fn fmt(&self, formatter: &mut fmt::Formatter) -> Result<(), fmt::Error> { - formatter.write_str(self.to_string()) - } -} - -impl error::Error for CreationError { - fn description(&self) -> &str { - self.to_string() - } -} - /// Describes the appearance of the mouse cursor. #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] From 39ce52482e73856c8e5193e7398b6c50f9c2bdcd Mon Sep 17 00:00:00 2001 From: Osspial Date: Sat, 25 May 2019 22:07:46 -0400 Subject: [PATCH 08/22] Begin updating iOS backend --- src/platform/ios.rs | 32 ++++++++++++++--------------- src/platform_impl/ios/event_loop.rs | 8 ++++---- src/platform_impl/ios/mod.rs | 4 ++-- src/platform_impl/ios/view.rs | 4 ++-- src/platform_impl/ios/window.rs | 23 ++++++++++----------- src/window.rs | 18 ++++++++-------- 6 files changed, 44 insertions(+), 45 deletions(-) diff --git a/src/platform/ios.rs b/src/platform/ios.rs index 39f2e55061..1713fa327f 100644 --- a/src/platform/ios.rs +++ b/src/platform/ios.rs @@ -9,12 +9,12 @@ use window::{Window, WindowBuilder}; /// Additional methods on `EventLoop` that are specific to iOS. pub trait EventLoopExtIOS { /// Returns the idiom (phone/tablet/tv/etc) for the current device. - fn get_idiom(&self) -> Idiom; + fn idiom(&self) -> Idiom; } impl EventLoopExtIOS for EventLoop { - fn get_idiom(&self) -> Idiom { - self.event_loop.get_idiom() + fn idiom(&self) -> Idiom { + self.event_loop.idiom() } } @@ -23,28 +23,28 @@ pub trait WindowExtIOS { /// Returns a pointer to the `UIWindow` that is used by this window. /// /// The pointer will become invalid when the `Window` is destroyed. - fn uiwindow(&self) -> *mut c_void; + fn ui_window(&self) -> *mut c_void; /// Returns a pointer to the `UIViewController` that is used by this window. /// /// The pointer will become invalid when the `Window` is destroyed. - fn get_uiviewcontroller(&self) -> *mut c_void; + fn ui_view_controller(&self) -> *mut c_void; /// Returns a pointer to the `UIView` that is used by this window. /// /// The pointer will become invalid when the `Window` is destroyed. - fn uiview(&self) -> *mut c_void; + fn ui_view(&self) -> *mut c_void; } impl WindowExtIOS for Window { #[inline] - fn uiwindow(&self) -> *mut c_void { - self.window.uiwindow() as _ + fn ui_window(&self) -> *mut c_void { + self.window.ui_window() as _ } #[inline] - fn uiview(&self) -> *mut c_void { - self.window.uiview() as _ + fn ui_view(&self) -> *mut c_void { + self.window.ui_view() as _ } #[inline] @@ -64,13 +64,13 @@ pub trait WindowBuilderExtIOS { /// /// The class will be initialized by calling `[root_view initWithFrame:CGRect]` fn with_root_view_class(self, root_view_class: *const c_void) -> WindowBuilder; - + /// Sets the `contentScaleFactor` of the underlying `UIWindow` to `hidpi_factor`. - /// + /// /// The default value is device dependent, and it's recommended GLES or Metal applications set - /// this to `MonitorHandle::get_hidpi_factor()`. + /// this to `MonitorHandle::hidpi_factor()`. fn with_hidpi_factor(self, hidpi_factor: f64) -> WindowBuilder; - + /// Sets the valid orientations for the `Window`. fn with_valid_orientations(self, valid_orientations: ValidOrientations) -> WindowBuilder; } @@ -115,7 +115,7 @@ pub enum ValidOrientations { LandscapeAndPortrait, Landscape, - + /// Excludes `PortraitUpsideDown` on iphone Portrait, } @@ -128,7 +128,7 @@ impl Default for ValidOrientations { } /// The device [idiom]. -/// +/// /// [idiom]: https://developer.apple.com/documentation/uikit/uidevice/1620037-userinterfaceidiom?language=objc #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub enum Idiom { diff --git a/src/platform_impl/ios/event_loop.rs b/src/platform_impl/ios/event_loop.rs index 76929980eb..563fd63d6d 100644 --- a/src/platform_impl/ios/event_loop.rs +++ b/src/platform_impl/ios/event_loop.rs @@ -140,10 +140,10 @@ impl EventLoop { // EventLoopExtIOS impl EventLoop { - pub fn get_idiom(&self) -> Idiom { + pub fn idiom(&self) -> Idiom { // guaranteed to be on main thread unsafe { - self::get_idiom() + self::idiom() } } } @@ -313,7 +313,7 @@ where } // must be called on main thread -pub unsafe fn get_idiom() -> Idiom { +pub unsafe fn idiom() -> Idiom { let device: id = msg_send![class!(UIDevice), currentDevice]; let raw_idiom: UIUserInterfaceIdiom = msg_send![device, userInterfaceIdiom]; raw_idiom.into() @@ -331,4 +331,4 @@ impl From for Capabilities { Capabilities { supports_safe_area } } -} \ No newline at end of file +} diff --git a/src/platform_impl/ios/mod.rs b/src/platform_impl/ios/mod.rs index 22fe5161f9..fb5cbd04f0 100644 --- a/src/platform_impl/ios/mod.rs +++ b/src/platform_impl/ios/mod.rs @@ -342,12 +342,12 @@ impl Window { } #[inline] - pub fn uiwindow(&self) -> id { + pub fn ui_window(&self) -> id { self.delegate_state.window } #[inline] - pub fn uiview(&self) -> id { + pub fn ui_view(&self) -> id { self.delegate_state.view } diff --git a/src/platform_impl/ios/view.rs b/src/platform_impl/ios/view.rs index 72918f0ce6..4c7746cff3 100644 --- a/src/platform_impl/ios/view.rs +++ b/src/platform_impl/ios/view.rs @@ -31,7 +31,7 @@ use platform_impl::platform::window::{PlatformSpecificWindowBuilderAttributes}; unsafe fn get_view_class(root_view_class: &'static Class) -> &'static Class { static mut CLASSES: Option> = None; static mut ID: usize = 0; - + if CLASSES.is_none() { CLASSES = Some(HashMap::default()); } @@ -289,7 +289,7 @@ pub unsafe fn create_view_controller( } else { YES }; - let idiom = event_loop::get_idiom(); + let idiom = event_loop::idiom(); let supported_orientations = UIInterfaceOrientationMask::from_valid_orientations_idiom( platform_attributes.valid_orientations, idiom, diff --git a/src/platform_impl/ios/window.rs b/src/platform_impl/ios/window.rs index 0d44c64f22..c75f6cfd91 100644 --- a/src/platform_impl/ios/window.rs +++ b/src/platform_impl/ios/window.rs @@ -56,15 +56,14 @@ impl Inner { debug!("`Window::set_title` is ignored on iOS") } - pub fn show(&self) { - unsafe { - let () = msg_send![self.window, setHidden:NO]; - } - } - - pub fn hide(&self) { - unsafe { - let () = msg_send![self.window, setHidden:YES]; + pub fn set_visible(&self, visible: bool) { + match visible { + true => unsafe { + let () = msg_send![self.window, setHidden:NO]; + }, + false => unsafe { + let () = msg_send![self.window, setHidden:YES]; + }, } } @@ -73,7 +72,7 @@ impl Inner { let () = msg_send![self.view, setNeedsDisplay]; } } - + pub fn get_inner_position(&self) -> Option { unsafe { let safe_area = self.safe_area_screen_space(); @@ -344,7 +343,7 @@ impl Window { // WindowExtIOS impl Inner { pub fn get_uiwindow(&self) -> id { self.window } - pub fn get_uiviewcontroller(&self) -> id { self.view_controller } + pub fn ui_view_controller(&self) -> id { self.view_controller } pub fn get_uiview(&self) -> id { self.view } pub fn set_hidpi_factor(&self, hidpi_factor: f64) { @@ -357,7 +356,7 @@ impl Inner { pub fn set_valid_orientations(&self, valid_orientations: ValidOrientations) { unsafe { - let idiom = event_loop::get_idiom(); + let idiom = event_loop::idiom(); let supported_orientations = UIInterfaceOrientationMask::from_valid_orientations_idiom(valid_orientations, idiom); msg_send![self.view_controller, setSupportedInterfaceOrientations:supported_orientations]; } diff --git a/src/window.rs b/src/window.rs index 7a7ce5c559..d40e76ecfd 100644 --- a/src/window.rs +++ b/src/window.rs @@ -386,7 +386,7 @@ impl Window { /// /// - **iOS:** Can only be called on the main thread. Returns the top left coordinates of the /// window's [safe area] in the screen space coordinate system. - /// + /// /// [safe area]: https://developer.apple.com/documentation/uikit/uiview/2891103-safeareainsets?language=objc #[inline] pub fn inner_position(&self) -> Result { @@ -418,7 +418,7 @@ impl Window { /// /// - **iOS:** Can only be called on the main thread. Returns the `LogicalSize` of the window's /// [safe area] in screen space coordinates. - /// + /// /// [safe area]: https://developer.apple.com/documentation/uikit/uiview/2891103-safeareainsets?language=objc #[inline] pub fn inner_size(&self) -> LogicalSize { @@ -505,7 +505,7 @@ impl Window { /// - **Android:** Always returns 1.0. /// - **iOS:** Can only be called on the main thread. Returns the underlying `UIView`'s /// [`contentScaleFactor`]. - /// + /// /// [`contentScaleFactor`]: https://developer.apple.com/documentation/uikit/uiview/1622657-contentscalefactor?language=objc #[inline] pub fn hidpi_factor(&self) -> f64 { @@ -564,7 +564,7 @@ impl Window { /// Sets the window to maximized or back. /// /// ## Platform-specific - /// + /// /// - **iOS:** Has no effect. #[inline] pub fn set_maximized(&self, maximized: bool) { @@ -574,7 +574,7 @@ impl Window { /// Sets the window to fullscreen or back. /// /// ## Platform-specific - /// + /// /// - **iOS:** Can only be called on the main thread. #[inline] pub fn set_fullscreen(&self, monitor: Option) { @@ -584,7 +584,7 @@ impl Window { /// Gets the window's current fullscreen state. /// /// ## Platform-specific - /// + /// /// - **iOS:** Can only be called on the main thread. #[inline] pub fn fullscreen(&self) -> Option { @@ -594,10 +594,10 @@ impl Window { /// Turn window decorations on or off. /// /// ## Platform-specific - /// + /// /// - **iOS:** Can only be called on the main thread. Controls whether the status bar is hidden /// via [`setPrefersStatusBarHidden`]. - /// + /// /// [`setPrefersStatusBarHidden`]: https://developer.apple.com/documentation/uikit/uiviewcontroller/1621440-prefersstatusbarhidden?language=objc #[inline] pub fn set_decorations(&self, decorations: bool) { @@ -607,7 +607,7 @@ impl Window { /// Change whether or not the window will always be on top of other windows. /// /// ## Platform-specific - /// + /// /// - **iOS:** Has no effect. #[inline] pub fn set_always_on_top(&self, always_on_top: bool) { From c0fa9389d806b077fe0b51ff4bf9a49e617ebad2 Mon Sep 17 00:00:00 2001 From: Osspial Date: Sat, 25 May 2019 22:14:46 -0400 Subject: [PATCH 09/22] Change MonitorHandle::outer_position to just position --- src/monitor.rs | 4 ++-- src/platform_impl/ios/monitor.rs | 22 +++++++++---------- src/platform_impl/linux/mod.rs | 6 ++--- src/platform_impl/linux/wayland/event_loop.rs | 4 ++-- src/platform_impl/linux/x11/monitor.rs | 4 ++-- src/platform_impl/linux/x11/util/randr.rs | 2 +- src/platform_impl/macos/monitor.rs | 4 ++-- src/platform_impl/windows/monitor.rs | 2 +- 8 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/monitor.rs b/src/monitor.rs index a74d29c192..8fab7ca44c 100644 --- a/src/monitor.rs +++ b/src/monitor.rs @@ -72,8 +72,8 @@ impl MonitorHandle { /// Returns the top-left corner position of the monitor relative to the larger full /// screen area. #[inline] - pub fn outer_position(&self) -> PhysicalPosition { - self.inner.outer_position() + pub fn position(&self) -> PhysicalPosition { + self.inner.position() } /// Returns the DPI factor that can be used to map logical pixels to physical pixels, and vice versa. diff --git a/src/platform_impl/ios/monitor.rs b/src/platform_impl/ios/monitor.rs index 8d01909397..de559642ea 100644 --- a/src/platform_impl/ios/monitor.rs +++ b/src/platform_impl/ios/monitor.rs @@ -78,10 +78,10 @@ impl fmt::Debug for MonitorHandle { } let monitor_id_proxy = MonitorHandle { - name: self.get_name(), - dimensions: self.get_dimensions(), - position: self.get_position(), - hidpi_factor: self.get_hidpi_factor(), + name: self.name(), + dimensions: self.dimensions(), + position: self.position(), + hidpi_factor: self.hidpi_factor(), }; monitor_id_proxy.fmt(f) @@ -99,7 +99,7 @@ impl MonitorHandle { } impl Inner { - pub fn get_name(&self) -> Option { + pub fn name(&self) -> Option { unsafe { if self.uiscreen == main_uiscreen().uiscreen { Some("Primary".to_string()) @@ -113,22 +113,22 @@ impl Inner { } } } - - pub fn get_dimensions(&self) -> PhysicalSize { + + pub fn dimensions(&self) -> PhysicalSize { unsafe { let bounds: CGRect = msg_send![self.get_uiscreen(), nativeBounds]; (bounds.size.width as f64, bounds.size.height as f64).into() } } - - pub fn get_position(&self) -> PhysicalPosition { + + pub fn position(&self) -> PhysicalPosition { unsafe { let bounds: CGRect = msg_send![self.get_uiscreen(), nativeBounds]; (bounds.origin.x as f64, bounds.origin.y as f64).into() } } - - pub fn get_hidpi_factor(&self) -> f64 { + + pub fn hidpi_factor(&self) -> f64 { unsafe { let scale: CGFloat = msg_send![self.get_uiscreen(), nativeScale]; scale as f64 diff --git a/src/platform_impl/linux/mod.rs b/src/platform_impl/linux/mod.rs index 7fff1988e3..dbabdb3b49 100644 --- a/src/platform_impl/linux/mod.rs +++ b/src/platform_impl/linux/mod.rs @@ -118,10 +118,10 @@ impl MonitorHandle { } #[inline] - pub fn outer_position(&self) -> PhysicalPosition { + pub fn position(&self) -> PhysicalPosition { match self { - &MonitorHandle::X(ref m) => m.outer_position(), - &MonitorHandle::Wayland(ref m) => m.outer_position(), + &MonitorHandle::X(ref m) => m.position(), + &MonitorHandle::Wayland(ref m) => m.position(), } } diff --git a/src/platform_impl/linux/wayland/event_loop.rs b/src/platform_impl/linux/wayland/event_loop.rs index 55f192f60b..a327606487 100644 --- a/src/platform_impl/linux/wayland/event_loop.rs +++ b/src/platform_impl/linux/wayland/event_loop.rs @@ -535,7 +535,7 @@ impl fmt::Debug for MonitorHandle { name: self.name(), native_identifier: self.native_identifier(), dimensions: self.dimensions(), - position: self.outer_position(), + position: self.position(), hidpi_factor: self.hidpi_factor(), }; @@ -567,7 +567,7 @@ impl MonitorHandle { }.into() } - pub fn outer_position(&self) -> PhysicalPosition { + pub fn position(&self) -> PhysicalPosition { self.mgr .with_info(&self.proxy, |_, info| info.location) .unwrap_or((0, 0)) diff --git a/src/platform_impl/linux/x11/monitor.rs b/src/platform_impl/linux/x11/monitor.rs index 12511674f2..638ebce18d 100644 --- a/src/platform_impl/linux/x11/monitor.rs +++ b/src/platform_impl/linux/x11/monitor.rs @@ -67,7 +67,7 @@ impl MonitorHandle { primary: bool, ) -> Option { let (name, hidpi_factor) = unsafe { xconn.get_output_info(resources, &repr)? }; - let (dimensions, position) = unsafe { (repr.dimensions(), repr.outer_position()) }; + let (dimensions, position) = unsafe { (repr.dimensions(), repr.position()) }; let rect = util::AaRect::new(position, dimensions); Some(MonitorHandle { id, @@ -93,7 +93,7 @@ impl MonitorHandle { self.dimensions.into() } - pub fn outer_position(&self) -> PhysicalPosition { + pub fn position(&self) -> PhysicalPosition { self.position.into() } diff --git a/src/platform_impl/linux/x11/util/randr.rs b/src/platform_impl/linux/x11/util/randr.rs index f7c98d8296..3abbf849c7 100644 --- a/src/platform_impl/linux/x11/util/randr.rs +++ b/src/platform_impl/linux/x11/util/randr.rs @@ -58,7 +58,7 @@ impl MonitorRepr { } } - pub unsafe fn outer_position(&self) -> (i32, i32) { + pub unsafe fn position(&self) -> (i32, i32) { match *self { MonitorRepr::Monitor(monitor) => ((*monitor).x as i32, (*monitor).y as i32), MonitorRepr::Crtc(crtc) => ((*crtc).x as i32, (*crtc).y as i32), diff --git a/src/platform_impl/macos/monitor.rs b/src/platform_impl/macos/monitor.rs index bbc644afcc..78e4e3eca9 100644 --- a/src/platform_impl/macos/monitor.rs +++ b/src/platform_impl/macos/monitor.rs @@ -41,7 +41,7 @@ impl fmt::Debug for MonitorHandle { name: self.name(), native_identifier: self.native_identifier(), dimensions: self.dimensions(), - position: self.outer_position(), + position: self.position(), hidpi_factor: self.hidpi_factor(), }; @@ -77,7 +77,7 @@ impl MonitorHandle { } #[inline] - pub fn outer_position(&self) -> PhysicalPosition { + pub fn position(&self) -> PhysicalPosition { let bounds = unsafe { CGDisplayBounds(self.native_identifier()) }; PhysicalPosition::from_logical( (bounds.origin.x as f64, bounds.origin.y as f64), diff --git a/src/platform_impl/windows/monitor.rs b/src/platform_impl/windows/monitor.rs index 83c2d412f8..ccbe581b83 100644 --- a/src/platform_impl/windows/monitor.rs +++ b/src/platform_impl/windows/monitor.rs @@ -162,7 +162,7 @@ impl MonitorHandle { } #[inline] - pub fn outer_position(&self) -> PhysicalPosition { + pub fn position(&self) -> PhysicalPosition { self.position.into() } From 192a28efb4d517ec7f313631822b60eb4243b60a Mon Sep 17 00:00:00 2001 From: Osspial Date: Sat, 25 May 2019 22:28:50 -0400 Subject: [PATCH 10/22] Fix build on Windows and Linux --- src/platform_impl/linux/x11/window.rs | 2 +- src/platform_impl/windows/window.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/platform_impl/linux/x11/window.rs b/src/platform_impl/linux/x11/window.rs index 238d4fac5b..300d438d28 100644 --- a/src/platform_impl/linux/x11/window.rs +++ b/src/platform_impl/linux/x11/window.rs @@ -536,7 +536,7 @@ impl UnownedWindow { Some(RootMonitorHandle { inner: PlatformMonitorHandle::X(monitor) }) => { let window_position = self.outer_position_physical(); self.shared_state.lock().restore_position = Some(window_position); - let monitor_origin: (i32, i32) = monitor.outer_position().into(); + let monitor_origin: (i32, i32) = monitor.position().into(); self.set_position_inner(monitor_origin.0, monitor_origin.1).queue(); self.set_fullscreen_hint(true) } diff --git a/src/platform_impl/windows/window.rs b/src/platform_impl/windows/window.rs index 5d6b8a0558..f0692c9172 100644 --- a/src/platform_impl/windows/window.rs +++ b/src/platform_impl/windows/window.rs @@ -402,7 +402,7 @@ impl Window { match &monitor { &Some(RootMonitorHandle { ref inner }) => { - let (x, y): (i32, i32) = inner.outer_position().into(); + let (x, y): (i32, i32) = inner.position().into(); let (width, height): (u32, u32) = inner.dimensions().into(); let mut monitor = monitor.clone(); From ac4d5bf05c87e35a9ce0f4714f01aa4811cfaef7 Mon Sep 17 00:00:00 2001 From: Osspial Date: Mon, 27 May 2019 22:57:10 -0400 Subject: [PATCH 11/22] Add Display and Error implementations to Error types --- src/error.rs | 39 ++++++++++++++++++++++++++++++++-- src/platform_impl/linux/mod.rs | 12 ++++++++++- src/platform_impl/macos/mod.rs | 12 ++++++++++- src/util.rs | 0 4 files changed, 59 insertions(+), 4 deletions(-) delete mode 100644 src/util.rs diff --git a/src/error.rs b/src/error.rs index 49aca4b81c..ff569f1abf 100644 --- a/src/error.rs +++ b/src/error.rs @@ -1,16 +1,20 @@ +use std::fmt; +use std::error; + use platform_impl; +#[derive(Debug)] pub enum ExternalError { NotSupported(NotSupportedError), Os(OsError), } -/// TODO: MANUALLY IMPLEMENT TRAITS -#[derive(Debug)] +#[derive(Clone)] pub struct NotSupportedError { _marker: (), } +#[derive(Debug)] pub struct OsError { line: u32, file: &'static str, @@ -41,3 +45,34 @@ macro_rules! os_error { crate::error::OsError::new(line!(), file!(), $error) }} } + +impl fmt::Display for OsError { + fn fmt(&self, formatter: &mut fmt::Formatter) -> Result<(), fmt::Error> { + formatter.pad(&format!("os error at {}:{}: {}", self.file, self.line, self.error)) + } +} + +impl fmt::Display for ExternalError { + fn fmt(&self, formatter: &mut fmt::Formatter) -> Result<(), fmt::Error> { + match self { + ExternalError::NotSupported(e) => e.fmt(formatter), + ExternalError::Os(e) => e.fmt(formatter), + } + } +} + +impl fmt::Debug for NotSupportedError { + fn fmt(&self, formatter: &mut fmt::Formatter) -> Result<(), fmt::Error> { + formatter.debug_struct("NotSupportedError").finish() + } +} + +impl fmt::Display for NotSupportedError { + fn fmt(&self, formatter: &mut fmt::Formatter) -> Result<(), fmt::Error> { + formatter.pad("the requested operation is not supported by Winit") + } +} + +impl error::Error for OsError {} +impl error::Error for ExternalError {} +impl error::Error for NotSupportedError {} diff --git a/src/platform_impl/linux/mod.rs b/src/platform_impl/linux/mod.rs index dbabdb3b49..88c5114bd2 100644 --- a/src/platform_impl/linux/mod.rs +++ b/src/platform_impl/linux/mod.rs @@ -1,7 +1,7 @@ #![cfg(any(target_os = "linux", target_os = "dragonfly", target_os = "freebsd", target_os = "netbsd", target_os = "openbsd"))] use std::collections::VecDeque; -use std::{env, mem}; +use std::{env, mem, fmt}; use std::ffi::CStr; use std::os::raw::*; use std::sync::Arc; @@ -52,11 +52,21 @@ lazy_static!( }; ); +#[derive(Debug, Clone)] pub enum OsError { XError(XError), XMisc(&'static str), } +impl fmt::Display for OsError { + fn fmt(&self, formatter: &mut fmt::Formatter) -> Result<(), fmt::Error> { + match self { + OsError::XError(e) => formatter.pad(&e.description), + OsError::XMisc(e) => formatter.pad(e), + } + } +} + pub enum Window { X(x11::Window), Wayland(wayland::Window), diff --git a/src/platform_impl/macos/mod.rs b/src/platform_impl/macos/mod.rs index e4558f612c..2b5d9f5dec 100644 --- a/src/platform_impl/macos/mod.rs +++ b/src/platform_impl/macos/mod.rs @@ -13,7 +13,7 @@ mod view; mod window; mod window_delegate; -use std::{ops::Deref, sync::Arc}; +use std::{fmt, ops::Deref, sync::Arc}; use { event::DeviceId as RootDeviceId, window::WindowAttributes, @@ -45,6 +45,7 @@ pub struct Window { _delegate: util::IdRef, } +#[derive(Debug)] pub enum OsError { CGError(core_graphics::base::CGError), CreationError(&'static str) @@ -71,3 +72,12 @@ impl Window { Ok(Window { window, _delegate }) } } + +impl fmt::Display for OsError { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + match self { + OsError::CGError(e) => f.pad(&format!("CGError {}", e)), + OsError::CreationError(e) => f.pad(e), + } + } +} diff --git a/src/util.rs b/src/util.rs deleted file mode 100644 index e69de29bb2..0000000000 From ecce663e0aad47f06c23c4ad5e5af139fcf188bd Mon Sep 17 00:00:00 2001 From: Osspial Date: Mon, 27 May 2019 23:08:20 -0400 Subject: [PATCH 12/22] Attempt to fix iOS build. I can't actually check that this works since I can't cross-compile to iOS on a Windows machine (thanks apple :/) but this should be one of several commits to get it working. --- src/platform_impl/ios/event_loop.rs | 8 +- src/platform_impl/ios/mod.rs | 537 +--------------------------- src/platform_impl/ios/monitor.rs | 8 +- src/platform_impl/ios/view.rs | 4 +- src/platform_impl/ios/window.rs | 57 +-- 5 files changed, 48 insertions(+), 566 deletions(-) diff --git a/src/platform_impl/ios/event_loop.rs b/src/platform_impl/ios/event_loop.rs index 563fd63d6d..76929980eb 100644 --- a/src/platform_impl/ios/event_loop.rs +++ b/src/platform_impl/ios/event_loop.rs @@ -140,10 +140,10 @@ impl EventLoop { // EventLoopExtIOS impl EventLoop { - pub fn idiom(&self) -> Idiom { + pub fn get_idiom(&self) -> Idiom { // guaranteed to be on main thread unsafe { - self::idiom() + self::get_idiom() } } } @@ -313,7 +313,7 @@ where } // must be called on main thread -pub unsafe fn idiom() -> Idiom { +pub unsafe fn get_idiom() -> Idiom { let device: id = msg_send![class!(UIDevice), currentDevice]; let raw_idiom: UIUserInterfaceIdiom = msg_send![device, userInterfaceIdiom]; raw_idiom.into() @@ -331,4 +331,4 @@ impl From for Capabilities { Capabilities { supports_safe_area } } -} +} \ No newline at end of file diff --git a/src/platform_impl/ios/mod.rs b/src/platform_impl/ios/mod.rs index fb5cbd04f0..c73b224f6a 100644 --- a/src/platform_impl/ios/mod.rs +++ b/src/platform_impl/ios/mod.rs @@ -58,194 +58,13 @@ #![cfg(target_os = "ios")] -use std::{fmt, mem, ptr}; -use std::cell::RefCell; -use std::collections::VecDeque; -use std::os::raw::*; -use std::sync::Arc; - -use objc::declare::ClassDecl; -use objc::runtime::{BOOL, Class, Object, Sel, YES}; - -use { - CreationError, - Event, - LogicalPosition, - LogicalSize, - MouseCursor, - PhysicalPosition, - PhysicalSize, - WindowAttributes, - WindowEvent, - WindowId as RootEventId, -}; -use error::{ExternalError, NotSupportedError}; -use events::{Touch, TouchPhase}; -use window::MonitorHandle as RootMonitorHandle; - -mod ffi; -use self::ffi::{ - CFTimeInterval, - CFRunLoopRunInMode, - CGFloat, - CGPoint, - CGRect, - id, - JBLEN, - JmpBuf, - kCFRunLoopDefaultMode, - kCFRunLoopRunHandledSource, - longjmp, - nil, - NSString, - setjmp, - UIApplicationMain, - }; - -static mut JMPBUF: Option> = None; - -pub type OsError = std::io::Error; - -pub struct Window { - _events_queue: Arc>>, - delegate_state: Box, -} - -unsafe impl Send for Window {} -unsafe impl Sync for Window {} - -#[derive(Debug)] -struct DelegateState { - window: id, - controller: id, - view: id, - size: LogicalSize, - scale: f64, -} - -impl DelegateState { - fn new(window: id, controller: id, view: id, size: LogicalSize, scale: f64) -> DelegateState { - DelegateState { - window, - controller, - view, - size, - scale, - } - } -} - -impl Drop for DelegateState { - fn drop(&mut self) { - unsafe { - let _: () = msg_send![self.window, release]; - let _: () = msg_send![self.controller, release]; - let _: () = msg_send![self.view, release]; - } - } -} - -#[derive(Clone)] -pub struct MonitorHandle; - -impl fmt::Debug for MonitorHandle { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - #[derive(Debug)] - struct MonitorHandle { - name: Option, - dimensions: PhysicalSize, - position: PhysicalPosition, - hidpi_factor: f64, - } - - let monitor_id_proxy = MonitorHandle { - name: self.name(), - dimensions: self.dimensions(), - position: self.outer_position(), - hidpi_factor: self.hidpi_factor(), - }; - - monitor_id_proxy.fmt(f) - } -} - -impl MonitorHandle { - #[inline] - pub fn uiscreen(&self) -> id { - let class = class!(UIScreen); - unsafe { msg_send![class, mainScreen] } - } - - #[inline] - pub fn name(&self) -> Option { - Some("Primary".to_string()) - } - - #[inline] - pub fn dimensions(&self) -> PhysicalSize { - let bounds: CGRect = unsafe { msg_send![self.uiscreen(), nativeBounds] }; - (bounds.size.width as f64, bounds.size.height as f64).into() - } - - #[inline] - pub fn outer_position(&self) -> PhysicalPosition { - // iOS assumes single screen - (0, 0).into() - } - - #[inline] - pub fn hidpi_factor(&self) -> f64 { - let scale: CGFloat = unsafe { msg_send![self.uiscreen(), nativeScale] }; - scale as f64 - } -} - -pub struct EventLoop { - events_queue: Arc>>, -} - -#[derive(Clone)] -pub struct EventLoopProxy; - -impl EventLoop { - pub fn new() -> EventLoop { - unsafe { - if !msg_send![class!(NSThread), isMainThread] { - panic!("`EventLoop` can only be created on the main thread on iOS"); - } - } - EventLoop { events_queue: Default::default() } - } - - #[inline] - pub fn available_monitors(&self) -> VecDeque { - let mut rb = VecDeque::with_capacity(1); - rb.push_back(MonitorHandle); - rb - } - - #[inline] - pub fn primary_monitor(&self) -> MonitorHandle { - MonitorHandle - } - - pub fn poll_events(&mut self, mut callback: F) - where F: FnMut(::Event) - { - if let Some(event) = self.events_queue.borrow_mut().pop_front() { - callback(event); - return; - } - - unsafe { - // jump hack, so we won't quit on willTerminate event before processing it - assert!(JMPBUF.is_some(), "`EventLoop::poll_events` must be called after window creation on iOS"); - if setjmp(mem::transmute_copy(&mut JMPBUF)) != 0 { - if let Some(event) = self.events_queue.borrow_mut().pop_front() { - callback(event); - return; - } - } +// TODO: (mtak-) UIKit requires main thread for virtually all function/method calls. This could be +// worked around in the future by using GCD (grand central dispatch) and/or caching of values like +// window size/position. +macro_rules! assert_main_thread { + ($($t:tt)*) => { + if !msg_send![class!(NSThread), isMainThread] { + panic!($($t)*); } }; } @@ -272,346 +91,8 @@ pub struct DeviceId { impl DeviceId { pub unsafe fn dummy() -> Self { - DeviceId - } -} - -#[derive(Clone)] -pub struct PlatformSpecificWindowBuilderAttributes { - pub root_view_class: &'static Class, -} - -impl Default for PlatformSpecificWindowBuilderAttributes { - fn default() -> Self { - PlatformSpecificWindowBuilderAttributes { - root_view_class: class!(UIView), - } - } -} - -// TODO: AFAIK transparency is enabled by default on iOS, -// so to be consistent with other platforms we have to change that. -impl Window { - pub fn new( - ev: &EventLoop, - _attributes: WindowAttributes, - pl_attributes: PlatformSpecificWindowBuilderAttributes, - ) -> Result { - unsafe { - debug_assert!(mem::size_of_val(&JMPBUF) == mem::size_of::>()); - assert!(mem::replace(&mut JMPBUF, Some(Box::new([0; JBLEN]))).is_none(), "Only one `Window` is supported on iOS"); - } - - unsafe { - if setjmp(mem::transmute_copy(&mut JMPBUF)) != 0 { - let app_class = class!(UIApplication); - let app: id = msg_send![app_class, sharedApplication]; - let delegate: id = msg_send![app, delegate]; - let state: *mut c_void = *(&*delegate).get_ivar("winitState"); - let mut delegate_state = Box::from_raw(state as *mut DelegateState); - let events_queue = &*ev.events_queue; - (&mut *delegate).set_ivar("eventsQueue", mem::transmute::<_, *mut c_void>(events_queue)); - - // easiest? way to get access to PlatformSpecificWindowBuilderAttributes to configure the view - let rect: CGRect = msg_send![MonitorHandle.uiscreen(), bounds]; - - let uiview_class = class!(UIView); - let root_view_class = pl_attributes.root_view_class; - let is_uiview: BOOL = msg_send![root_view_class, isSubclassOfClass:uiview_class]; - assert!(is_uiview == YES, "`root_view_class` must inherit from `UIView`"); - - delegate_state.view = msg_send![root_view_class, alloc]; - assert!(!delegate_state.view.is_null(), "Failed to create `UIView` instance"); - delegate_state.view = msg_send![delegate_state.view, initWithFrame:rect]; - assert!(!delegate_state.view.is_null(), "Failed to initialize `UIView` instance"); - - let _: () = msg_send![delegate_state.controller, setView:delegate_state.view]; - let _: () = msg_send![delegate_state.window, makeKeyAndVisible]; - - return Ok(Window { - _events_queue: ev.events_queue.clone(), - delegate_state, - }); - } - } - - create_delegate_class(); - start_app(); - - panic!("Couldn't create `UIApplication`!") - } - - #[inline] - pub fn ui_window(&self) -> id { - self.delegate_state.window - } - - #[inline] - pub fn ui_view(&self) -> id { - self.delegate_state.view - } - - #[inline] - pub fn set_title(&self, _title: &str) { - // N/A - } - - pub fn set_visible(&self, _visible: bool) { - // N/A - } - - #[inline] - pub fn outer_position(&self) -> Result { - Err(NotSupportedError::new()) - } - - #[inline] - pub fn inner_position(&self) -> Result { - Err(NotSupportedError::new()) - } - - #[inline] - pub fn set_outer_position(&self, _position: LogicalPosition) { - // N/A - } - - #[inline] - pub fn inner_size(&self) -> LogicalSize { - self.delegate_state.size - } - - #[inline] - pub fn outer_size(&self) -> LogicalSize { - self.inner_size() - } - - #[inline] - pub fn set_inner_size(&self, _size: LogicalSize) { - // N/A - } - - #[inline] - pub fn set_min_inner_size(&self, _dimensions: Option) { - // N/A - } - - #[inline] - pub fn set_max_inner_size(&self, _dimensions: Option) { - // N/A - } - - #[inline] - pub fn set_resizable(&self, _resizable: bool) { - // N/A - } - - #[inline] - pub fn set_cursor(&self, _cursor: MouseCursor) { - // N/A - } - - #[inline] - pub fn set_cursor_grab(&self, _grab: bool) -> Result<(), ExternalError> { - Err(NotSupportedError::new()) - } - - #[inline] - pub fn set_cursor_visible(&self, _visible: bool) { - // N/A - } - - #[inline] - pub fn hidpi_factor(&self) -> f64 { - self.delegate_state.scale - } - - #[inline] - pub fn set_cursor_position(&self, _position: LogicalPosition) -> Result<(), ExternalError> { - Err(NotSupportedError::new()) - } - - #[inline] - pub fn set_maximized(&self, _maximized: bool) { - // N/A - // iOS has single screen maximized apps so nothing to do - } - - #[inline] - pub fn fullscreen(&self) -> Option { - // N/A - // iOS has single screen maximized apps so nothing to do - None - } - - #[inline] - pub fn set_fullscreen(&self, _monitor: Option) { - // N/A - // iOS has single screen maximized apps so nothing to do - } - - #[inline] - pub fn set_decorations(&self, _decorations: bool) { - // N/A - } - - #[inline] - pub fn set_always_on_top(&self, _always_on_top: bool) { - // N/A - } - - #[inline] - pub fn set_window_icon(&self, _icon: Option<::Icon>) { - // N/A - } - - #[inline] - pub fn set_ime_spot(&self, _logical_spot: LogicalPosition) { - // N/A - } - - #[inline] - pub fn current_monitor(&self) -> RootMonitorHandle { - RootMonitorHandle { inner: MonitorHandle } - } - - #[inline] - pub fn available_monitors(&self) -> VecDeque { - let mut rb = VecDeque::with_capacity(1); - rb.push_back(MonitorHandle); - rb - } - - #[inline] - pub fn primary_monitor(&self) -> MonitorHandle { - MonitorHandle - } - - #[inline] - pub fn id(&self) -> WindowId { - WindowId - } -} - -fn create_delegate_class() { - extern fn did_finish_launching(this: &mut Object, _: Sel, _: id, _: id) -> BOOL { - let screen_class = class!(UIScreen); - let window_class = class!(UIWindow); - let controller_class = class!(UIViewController); - unsafe { - let main_screen: id = msg_send![screen_class, mainScreen]; - let bounds: CGRect = msg_send![main_screen, bounds]; - let scale: CGFloat = msg_send![main_screen, nativeScale]; - - let window: id = msg_send![window_class, alloc]; - let window: id = msg_send![window, initWithFrame:bounds.clone()]; - - let size = (bounds.size.width as f64, bounds.size.height as f64).into(); - - let view_controller: id = msg_send![controller_class, alloc]; - let view_controller: id = msg_send![view_controller, init]; - - let _: () = msg_send![window, setRootViewController:view_controller]; - - let state = Box::new(DelegateState::new(window, view_controller, ptr::null_mut(), size, scale as f64)); - let state_ptr: *mut DelegateState = mem::transmute(state); - this.set_ivar("winitState", state_ptr as *mut c_void); - - // The `UIView` is setup in `Window::new` which gets `longjmp`'ed to here. - // This makes it easier to configure the specific `UIView` type. - let _: () = msg_send![this, performSelector:sel!(postLaunch:) withObject:nil afterDelay:0.0]; - } - YES - } - - extern fn post_launch(_: &Object, _: Sel, _: id) { - unsafe { longjmp(mem::transmute_copy(&mut JMPBUF), 1); } - } - - extern fn did_become_active(this: &Object, _: Sel, _: id) { - unsafe { - let events_queue: *mut c_void = *this.get_ivar("eventsQueue"); - let events_queue = &*(events_queue as *const RefCell>); - events_queue.borrow_mut().push_back(Event::WindowEvent { - window_id: RootEventId(WindowId), - event: WindowEvent::Focused(true), - }); - } - } - - extern fn will_resign_active(this: &Object, _: Sel, _: id) { - unsafe { - let events_queue: *mut c_void = *this.get_ivar("eventsQueue"); - let events_queue = &*(events_queue as *const RefCell>); - events_queue.borrow_mut().push_back(Event::WindowEvent { - window_id: RootEventId(WindowId), - event: WindowEvent::Focused(false), - }); - } - } - - extern fn will_enter_foreground(this: &Object, _: Sel, _: id) { - unsafe { - let events_queue: *mut c_void = *this.get_ivar("eventsQueue"); - let events_queue = &*(events_queue as *const RefCell>); - events_queue.borrow_mut().push_back(Event::Suspended(false)); - } - } - - extern fn did_enter_background(this: &Object, _: Sel, _: id) { - unsafe { - let events_queue: *mut c_void = *this.get_ivar("eventsQueue"); - let events_queue = &*(events_queue as *const RefCell>); - events_queue.borrow_mut().push_back(Event::Suspended(true)); - } - } - - extern fn will_terminate(this: &Object, _: Sel, _: id) { - unsafe { - let events_queue: *mut c_void = *this.get_ivar("eventsQueue"); - let events_queue = &*(events_queue as *const RefCell>); - // push event to the front to garantee that we'll process it - // immidiatly after jump - events_queue.borrow_mut().push_front(Event::WindowEvent { - window_id: RootEventId(WindowId), - event: WindowEvent::Destroyed, - }); - longjmp(mem::transmute_copy(&mut JMPBUF), 1); - } - } - - extern fn handle_touches(this: &Object, _: Sel, touches: id, _:id) { - unsafe { - let events_queue: *mut c_void = *this.get_ivar("eventsQueue"); - let events_queue = &*(events_queue as *const RefCell>); - - let touches_enum: id = msg_send![touches, objectEnumerator]; - - loop { - let touch: id = msg_send![touches_enum, nextObject]; - if touch == nil { - break - } - let location: CGPoint = msg_send![touch, locationInView:nil]; - let touch_id = touch as u64; - let phase: i32 = msg_send![touch, phase]; - - events_queue.borrow_mut().push_back(Event::WindowEvent { - window_id: RootEventId(WindowId), - event: WindowEvent::Touch(Touch { - device_id: DEVICE_ID, - id: touch_id, - location: (location.x as f64, location.y as f64).into(), - phase: match phase { - 0 => TouchPhase::Started, - 1 => TouchPhase::Moved, - // 2 is UITouchPhaseStationary and is not expected here - 3 => TouchPhase::Ended, - 4 => TouchPhase::Cancelled, - _ => panic!("unexpected touch phase: {:?}", phase) - } - }), - }); - } + DeviceId { + uiscreen: std::ptr::null_mut(), } } } diff --git a/src/platform_impl/ios/monitor.rs b/src/platform_impl/ios/monitor.rs index de559642ea..73b35351d1 100644 --- a/src/platform_impl/ios/monitor.rs +++ b/src/platform_impl/ios/monitor.rs @@ -78,10 +78,10 @@ impl fmt::Debug for MonitorHandle { } let monitor_id_proxy = MonitorHandle { - name: self.name(), - dimensions: self.dimensions(), - position: self.position(), - hidpi_factor: self.hidpi_factor(), + name: self.get_name(), + dimensions: self.get_dimensions(), + position: self.get_position(), + hidpi_factor: self.get_hidpi_factor(), }; monitor_id_proxy.fmt(f) diff --git a/src/platform_impl/ios/view.rs b/src/platform_impl/ios/view.rs index 4c7746cff3..72918f0ce6 100644 --- a/src/platform_impl/ios/view.rs +++ b/src/platform_impl/ios/view.rs @@ -31,7 +31,7 @@ use platform_impl::platform::window::{PlatformSpecificWindowBuilderAttributes}; unsafe fn get_view_class(root_view_class: &'static Class) -> &'static Class { static mut CLASSES: Option> = None; static mut ID: usize = 0; - + if CLASSES.is_none() { CLASSES = Some(HashMap::default()); } @@ -289,7 +289,7 @@ pub unsafe fn create_view_controller( } else { YES }; - let idiom = event_loop::idiom(); + let idiom = event_loop::get_idiom(); let supported_orientations = UIInterfaceOrientationMask::from_valid_orientations_idiom( platform_attributes.valid_orientations, idiom, diff --git a/src/platform_impl/ios/window.rs b/src/platform_impl/ios/window.rs index c75f6cfd91..47eadb975d 100644 --- a/src/platform_impl/ios/window.rs +++ b/src/platform_impl/ios/window.rs @@ -6,6 +6,7 @@ use std::{ use objc::runtime::{Class, NO, Object, YES}; use dpi::{self, LogicalPosition, LogicalSize}; +use error::{ExternalError, NotSupportedError, OsError as RootOsError}; use icon::Icon; use monitor::MonitorHandle as RootMonitorHandle; use platform::ios::{MonitorHandleExtIOS, ValidOrientations}; @@ -73,27 +74,27 @@ impl Inner { } } - pub fn get_inner_position(&self) -> Option { + pub fn inner_position(&self) -> Result { unsafe { let safe_area = self.safe_area_screen_space(); - Some(LogicalPosition { + Ok(LogicalPosition { x: safe_area.origin.x, y: safe_area.origin.y, }) } } - pub fn get_position(&self) -> Option { + pub fn outer_position(&self) -> Result { unsafe { let screen_frame = self.screen_frame(); - Some(LogicalPosition { + Ok(LogicalPosition { x: screen_frame.origin.x, y: screen_frame.origin.y, }) } } - pub fn set_position(&self, position: LogicalPosition) { + pub fn set_outer_position(&self, position: LogicalPosition) { unsafe { let screen_frame = self.screen_frame(); let new_screen_frame = CGRect { @@ -108,23 +109,23 @@ impl Inner { } } - pub fn get_inner_size(&self) -> Option { + pub fn inner_size(&self) -> LogicalSize { unsafe { let safe_area = self.safe_area_screen_space(); - Some(LogicalSize { + LogicalSize { width: safe_area.size.width, height: safe_area.size.height, - }) + } } } - pub fn get_outer_size(&self) -> Option { + pub fn outer_size(&self) -> LogicalSize { unsafe { let screen_frame = self.screen_frame(); - Some(LogicalSize { + LogicalSize { width: screen_frame.size.width, height: screen_frame.size.height, - }) + } } } @@ -132,19 +133,19 @@ impl Inner { unimplemented!("not clear what `Window::set_inner_size` means on iOS"); } - pub fn set_min_dimensions(&self, _dimensions: Option) { - warn!("`Window::set_min_dimensions` is ignored on iOS") + pub fn set_min_inner_size(&self, _dimensions: Option) { + warn!("`Window::set_min_inner_size` is ignored on iOS") } - pub fn set_max_dimensions(&self, _dimensions: Option) { - warn!("`Window::set_max_dimensions` is ignored on iOS") + pub fn set_max_inner_size(&self, _dimensions: Option) { + warn!("`Window::set_max_inner_size` is ignored on iOS") } pub fn set_resizable(&self, _resizable: bool) { warn!("`Window::set_resizable` is ignored on iOS") } - pub fn get_hidpi_factor(&self) -> f64 { + pub fn hidpi_factor(&self) -> f64 { unsafe { let hidpi: CGFloat = msg_send![self.view, contentScaleFactor]; hidpi as _ @@ -155,16 +156,16 @@ impl Inner { debug!("`Window::set_cursor` ignored on iOS") } - pub fn set_cursor_position(&self, _position: LogicalPosition) -> Result<(), String> { - Err("Setting cursor position is not possible on iOS.".to_owned()) + pub fn set_cursor_position(&self, _position: LogicalPosition) -> Result<(), ExternalError> { + Err(ExternalError::NotSupported(NotSupportedError::new())) } - pub fn grab_cursor(&self, _grab: bool) -> Result<(), String> { - Err("Cursor grabbing is not possible on iOS.".to_owned()) + pub fn grab_cursor(&self, _grab: bool) -> Result<(), ExternalError> { + Err(ExternalError::NotSupported(NotSupportedError::new())) } - pub fn hide_cursor(&self, _hide: bool) { - debug!("`Window::hide_cursor` is ignored on iOS") + pub fn set_cursor_visible(&self, visible: bool) { + debug!("`Window::set_cursor_visible` is ignored on iOS") } pub fn set_maximized(&self, _maximized: bool) { @@ -190,7 +191,7 @@ impl Inner { } } - pub fn get_fullscreen(&self) -> Option { + pub fn fullscreen(&self) -> Option { unsafe { let monitor = self.get_current_monitor(); let uiscreen = monitor.inner.get_uiscreen(); @@ -229,20 +230,20 @@ impl Inner { warn!("`Window::set_ime_spot` is ignored on iOS") } - pub fn get_current_monitor(&self) -> RootMonitorHandle { + pub fn current_monitor(&self) -> RootMonitorHandle { unsafe { let uiscreen: id = msg_send![self.window, screen]; RootMonitorHandle { inner: MonitorHandle::retained_new(uiscreen) } } } - pub fn get_available_monitors(&self) -> VecDeque { + pub fn available_monitors(&self) -> VecDeque { unsafe { monitor::uiscreens() } } - pub fn get_primary_monitor(&self) -> MonitorHandle { + pub fn primary_monitor(&self) -> MonitorHandle { unsafe { monitor::main_uiscreen() } @@ -343,7 +344,7 @@ impl Window { // WindowExtIOS impl Inner { pub fn get_uiwindow(&self) -> id { self.window } - pub fn ui_view_controller(&self) -> id { self.view_controller } + pub fn get_uiviewcontroller(&self) -> id { self.view_controller } pub fn get_uiview(&self) -> id { self.view } pub fn set_hidpi_factor(&self, hidpi_factor: f64) { @@ -356,7 +357,7 @@ impl Inner { pub fn set_valid_orientations(&self, valid_orientations: ValidOrientations) { unsafe { - let idiom = event_loop::idiom(); + let idiom = event_loop::get_idiom(); let supported_orientations = UIInterfaceOrientationMask::from_valid_orientations_idiom(valid_orientations, idiom); msg_send![self.view_controller, setSupportedInterfaceOrientations:supported_orientations]; } From 21077bd2ce9d31341f421e73071fa86fb980cb89 Mon Sep 17 00:00:00 2001 From: Osspial Date: Tue, 28 May 2019 01:11:45 -0400 Subject: [PATCH 13/22] Attempt to fix iOS errors, and muck up Travis to make debugging easier --- .travis.yml | 64 ++++++++++++++--------------- src/error.rs | 5 +++ src/platform/ios.rs | 15 +++++++ src/platform_impl/ios/event_loop.rs | 8 ++-- src/platform_impl/ios/monitor.rs | 16 ++++---- src/platform_impl/ios/view.rs | 8 ++-- src/platform_impl/ios/window.rs | 31 +++++++------- 7 files changed, 82 insertions(+), 65 deletions(-) diff --git a/.travis.yml b/.travis.yml index e8b7e47c5a..8d487a4818 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,38 +4,6 @@ cache: cargo matrix: include: - # Linux 32bit - - env: TARGET=i686-unknown-linux-gnu - os: linux - rust: nightly - addons: - apt: - # Cross compiler and cross compiled C libraries - packages: &i686_packages - - gcc-multilib - - env: TARGET=i686-unknown-linux-gnu - os: linux - rust: stable - addons: - apt: - packages: *i686_packages - - # Linux 64bit - - env: TARGET=x86_64-unknown-linux-gnu - os: linux - rust: nightly - - env: TARGET=x86_64-unknown-linux-gnu - os: linux - rust: stable - - # macOS - - env: TARGET=x86_64-apple-darwin - os: osx - rust: nightly - - env: TARGET=x86_64-apple-darwin - os: osx - rust: stable - # iOS - env: TARGET=x86_64-apple-ios os: osx @@ -44,6 +12,38 @@ matrix: os: osx rust: stable + # # Linux 32bit + # - env: TARGET=i686-unknown-linux-gnu + # os: linux + # rust: nightly + # addons: + # apt: + # # Cross compiler and cross compiled C libraries + # packages: &i686_packages + # - gcc-multilib + # - env: TARGET=i686-unknown-linux-gnu + # os: linux + # rust: stable + # addons: + # apt: + # packages: *i686_packages + + # # Linux 64bit + # - env: TARGET=x86_64-unknown-linux-gnu + # os: linux + # rust: nightly + # - env: TARGET=x86_64-unknown-linux-gnu + # os: linux + # rust: stable + + # # macOS + # - env: TARGET=x86_64-apple-darwin + # os: osx + # rust: nightly + # - env: TARGET=x86_64-apple-darwin + # os: osx + # rust: stable + install: - rustup self update - rustup target add $TARGET; true diff --git a/src/error.rs b/src/error.rs index ff569f1abf..a06a96849b 100644 --- a/src/error.rs +++ b/src/error.rs @@ -3,17 +3,22 @@ use std::error; use platform_impl; +/// An error whose cause it outside Winit's control. #[derive(Debug)] pub enum ExternalError { + /// The operation is not supported by the backend. NotSupported(NotSupportedError), + /// The OS cannot perform the operation. Os(OsError), } +/// The error type for when the requested operation is not supported by the backend. #[derive(Clone)] pub struct NotSupportedError { _marker: (), } +/// The error type for when the OS cannot perform the requested operation. #[derive(Debug)] pub struct OsError { line: u32, diff --git a/src/platform/ios.rs b/src/platform/ios.rs index 1713fa327f..6cd980c5cd 100644 --- a/src/platform/ios.rs +++ b/src/platform/ios.rs @@ -34,6 +34,16 @@ pub trait WindowExtIOS { /// /// The pointer will become invalid when the `Window` is destroyed. fn ui_view(&self) -> *mut c_void; + + /// Sets the HiDpi factor used by this window. + /// + /// This translates to `-[UIWindow setContentScaleFactor:hidpi_factor]`. + fn set_hidpi_factor(&self, hidpi_factor: f64); + + /// Sets the valid orientations for screens showing this `Window`. + /// + /// On iPhones and iPods upside down portrait is never enabled. + fn set_valid_orientations(&self, valid_orientations: ValidOrientations); } impl WindowExtIOS for Window { @@ -42,6 +52,11 @@ impl WindowExtIOS for Window { self.window.ui_window() as _ } + #[inline] + fn ui_view_controller(&self) -> *mut c_void { + self.window.ui_view_controller() as _ + } + #[inline] fn ui_view(&self) -> *mut c_void { self.window.ui_view() as _ diff --git a/src/platform_impl/ios/event_loop.rs b/src/platform_impl/ios/event_loop.rs index 76929980eb..589348c73c 100644 --- a/src/platform_impl/ios/event_loop.rs +++ b/src/platform_impl/ios/event_loop.rs @@ -119,14 +119,14 @@ impl EventLoop { EventLoopProxy::new(self.window_target.p.sender_to_clone.clone()) } - pub fn get_available_monitors(&self) -> VecDeque { + pub fn available_monitors(&self) -> VecDeque { // guaranteed to be on main thread unsafe { monitor::uiscreens() } } - pub fn get_primary_monitor(&self) -> MonitorHandle { + pub fn primary_monitor(&self) -> MonitorHandle { // guaranteed to be on main thread unsafe { monitor::main_uiscreen() @@ -140,7 +140,7 @@ impl EventLoop { // EventLoopExtIOS impl EventLoop { - pub fn get_idiom(&self) -> Idiom { + pub fn idiom(&self) -> Idiom { // guaranteed to be on main thread unsafe { self::get_idiom() @@ -331,4 +331,4 @@ impl From for Capabilities { Capabilities { supports_safe_area } } -} \ No newline at end of file +} diff --git a/src/platform_impl/ios/monitor.rs b/src/platform_impl/ios/monitor.rs index 73b35351d1..14e7d3790c 100644 --- a/src/platform_impl/ios/monitor.rs +++ b/src/platform_impl/ios/monitor.rs @@ -78,10 +78,10 @@ impl fmt::Debug for MonitorHandle { } let monitor_id_proxy = MonitorHandle { - name: self.get_name(), - dimensions: self.get_dimensions(), - position: self.get_position(), - hidpi_factor: self.get_hidpi_factor(), + name: self.name(), + dimensions: self.dimensions(), + position: self.position(), + hidpi_factor: self.hidpi_factor(), }; monitor_id_proxy.fmt(f) @@ -116,21 +116,21 @@ impl Inner { pub fn dimensions(&self) -> PhysicalSize { unsafe { - let bounds: CGRect = msg_send![self.get_uiscreen(), nativeBounds]; + let bounds: CGRect = msg_send![self.ui_screen(), nativeBounds]; (bounds.size.width as f64, bounds.size.height as f64).into() } } pub fn position(&self) -> PhysicalPosition { unsafe { - let bounds: CGRect = msg_send![self.get_uiscreen(), nativeBounds]; + let bounds: CGRect = msg_send![self.ui_screen(), nativeBounds]; (bounds.origin.x as f64, bounds.origin.y as f64).into() } } pub fn hidpi_factor(&self) -> f64 { unsafe { - let scale: CGFloat = msg_send![self.get_uiscreen(), nativeScale]; + let scale: CGFloat = msg_send![self.ui_screen(), nativeScale]; scale as f64 } } @@ -138,7 +138,7 @@ impl Inner { // MonitorHandleExtIOS impl Inner { - pub fn get_uiscreen(&self) -> id { + pub fn ui_screen(&self) -> id { self.uiscreen } } diff --git a/src/platform_impl/ios/view.rs b/src/platform_impl/ios/view.rs index 72918f0ce6..68134c4f42 100644 --- a/src/platform_impl/ios/view.rs +++ b/src/platform_impl/ios/view.rs @@ -31,7 +31,7 @@ use platform_impl::platform::window::{PlatformSpecificWindowBuilderAttributes}; unsafe fn get_view_class(root_view_class: &'static Class) -> &'static Class { static mut CLASSES: Option> = None; static mut ID: usize = 0; - + if CLASSES.is_none() { CLASSES = Some(HashMap::default()); } @@ -265,9 +265,7 @@ pub unsafe fn create_view( assert!(!view.is_null(), "Failed to create `UIView` instance"); let view: id = msg_send![view, initWithFrame:frame]; assert!(!view.is_null(), "Failed to initialize `UIView` instance"); - if window_attributes.multitouch { - let () = msg_send![view, setMultipleTouchEnabled:YES]; - } + let () = msg_send![view, setMultipleTouchEnabled:YES]; view } @@ -318,7 +316,7 @@ pub unsafe fn create_window( let () = msg_send![window, setContentScaleFactor:hidpi_factor as CGFloat]; } if let &Some(ref monitor) = &window_attributes.fullscreen { - let () = msg_send![window, setScreen:monitor.get_uiscreen()]; + let () = msg_send![window, setScreen:monitor.ui_screen()]; } window diff --git a/src/platform_impl/ios/window.rs b/src/platform_impl/ios/window.rs index 47eadb975d..18a26cab3c 100644 --- a/src/platform_impl/ios/window.rs +++ b/src/platform_impl/ios/window.rs @@ -11,7 +11,6 @@ use icon::Icon; use monitor::MonitorHandle as RootMonitorHandle; use platform::ios::{MonitorHandleExtIOS, ValidOrientations}; use window::{ - CreationError, MouseCursor, WindowAttributes, }; @@ -160,7 +159,7 @@ impl Inner { Err(ExternalError::NotSupported(NotSupportedError::new())) } - pub fn grab_cursor(&self, _grab: bool) -> Result<(), ExternalError> { + pub fn set_cursor_grab(&self, _grab: bool) -> Result<(), ExternalError> { Err(ExternalError::NotSupported(NotSupportedError::new())) } @@ -176,7 +175,7 @@ impl Inner { unsafe { match monitor { Some(monitor) => { - let uiscreen = monitor.get_uiscreen() as id; + let uiscreen = monitor.ui_screen() as id; let current: id = msg_send![self.window, screen]; let bounds: CGRect = msg_send![uiscreen, bounds]; @@ -193,8 +192,8 @@ impl Inner { pub fn fullscreen(&self) -> Option { unsafe { - let monitor = self.get_current_monitor(); - let uiscreen = monitor.inner.get_uiscreen(); + let monitor = self.current_monitor(); + let uiscreen = monitor.inner.ui_screen(); let screen_space_bounds = self.screen_frame(); let screen_bounds: CGRect = msg_send![uiscreen, bounds]; @@ -294,12 +293,12 @@ impl Window { event_loop: &EventLoopWindowTarget, window_attributes: WindowAttributes, platform_attributes: PlatformSpecificWindowBuilderAttributes, - ) -> Result { - if let Some(_) = window_attributes.min_dimensions { - warn!("`WindowAttributes::min_dimensions` is ignored on iOS"); + ) -> Result { + if let Some(_) = window_attributes.min_inner_size { + warn!("`WindowAttributes::min_inner_size` is ignored on iOS"); } - if let Some(_) = window_attributes.max_dimensions { - warn!("`WindowAttributes::max_dimensions` is ignored on iOS"); + if let Some(_) = window_attributes.max_inner_size { + warn!("`WindowAttributes::max_inner_size` is ignored on iOS"); } if window_attributes.always_on_top { warn!("`WindowAttributes::always_on_top` is unsupported on iOS"); @@ -309,11 +308,11 @@ impl Window { unsafe { let screen = window_attributes.fullscreen .as_ref() - .map(|screen| screen.get_uiscreen() as _) - .unwrap_or_else(|| monitor::main_uiscreen().get_uiscreen()); + .map(|screen| screen.ui_screen() as _) + .unwrap_or_else(|| monitor::main_uiscreen().ui_screen()); let screen_bounds: CGRect = msg_send![screen, bounds]; - let frame = match window_attributes.dimensions { + let frame = match window_attributes.inner_size { Some(dim) => CGRect { origin: screen_bounds.origin, size: CGSize { width: dim.width, height: dim.height }, @@ -343,9 +342,9 @@ impl Window { // WindowExtIOS impl Inner { - pub fn get_uiwindow(&self) -> id { self.window } - pub fn get_uiviewcontroller(&self) -> id { self.view_controller } - pub fn get_uiview(&self) -> id { self.view } + pub fn ui_window(&self) -> id { self.window } + pub fn ui_view_controller(&self) -> id { self.view_controller } + pub fn ui_view(&self) -> id { self.view } pub fn set_hidpi_factor(&self, hidpi_factor: f64) { unsafe { From c4cb1e6a07dc6d88c375f71ef3c2ac318d493719 Mon Sep 17 00:00:00 2001 From: Osspial Date: Tue, 28 May 2019 01:23:20 -0400 Subject: [PATCH 14/22] More iOS fixins --- src/error.rs | 1 + src/platform/ios.rs | 6 +++--- src/platform_impl/ios/mod.rs | 2 ++ src/platform_impl/ios/window.rs | 2 +- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/error.rs b/src/error.rs index a06a96849b..85046ae5ef 100644 --- a/src/error.rs +++ b/src/error.rs @@ -45,6 +45,7 @@ impl OsError { } } +#[allow(unused_macros)] macro_rules! os_error { ($error:expr) => {{ crate::error::OsError::new(line!(), file!(), $error) diff --git a/src/platform/ios.rs b/src/platform/ios.rs index 6cd980c5cd..85fcdff622 100644 --- a/src/platform/ios.rs +++ b/src/platform/ios.rs @@ -113,13 +113,13 @@ impl WindowBuilderExtIOS for WindowBuilder { /// Additional methods on `MonitorHandle` that are specific to iOS. pub trait MonitorHandleExtIOS { /// Returns a pointer to the `UIScreen` that is used by this monitor. - fn uiscreen(&self) -> *mut c_void; + fn ui_screen(&self) -> *mut c_void; } impl MonitorHandleExtIOS for MonitorHandle { #[inline] - fn uiscreen(&self) -> *mut c_void { - self.inner.uiscreen() as _ + fn ui_screen(&self) -> *mut c_void { + self.inner.ui_screen() as _ } } diff --git a/src/platform_impl/ios/mod.rs b/src/platform_impl/ios/mod.rs index c73b224f6a..5c5dc1dae8 100644 --- a/src/platform_impl/ios/mod.rs +++ b/src/platform_impl/ios/mod.rs @@ -99,3 +99,5 @@ impl DeviceId { unsafe impl Send for DeviceId {} unsafe impl Sync for DeviceId {} + +pub enum OsError {} diff --git a/src/platform_impl/ios/window.rs b/src/platform_impl/ios/window.rs index 18a26cab3c..358082b9e9 100644 --- a/src/platform_impl/ios/window.rs +++ b/src/platform_impl/ios/window.rs @@ -293,7 +293,7 @@ impl Window { event_loop: &EventLoopWindowTarget, window_attributes: WindowAttributes, platform_attributes: PlatformSpecificWindowBuilderAttributes, - ) -> Result { + ) -> Result { if let Some(_) = window_attributes.min_inner_size { warn!("`WindowAttributes::min_inner_size` is ignored on iOS"); } From 288c8a294b909f3def8d81984543a407290f1198 Mon Sep 17 00:00:00 2001 From: Osspial Date: Tue, 28 May 2019 01:28:23 -0400 Subject: [PATCH 15/22] Add Debug and Display impls to OsError --- src/platform_impl/ios/mod.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/platform_impl/ios/mod.rs b/src/platform_impl/ios/mod.rs index 5c5dc1dae8..4250b074af 100644 --- a/src/platform_impl/ios/mod.rs +++ b/src/platform_impl/ios/mod.rs @@ -76,6 +76,8 @@ mod monitor; mod view; mod window; +use std::fmt; + pub use self::event_loop::{EventLoop, EventLoopProxy, EventLoopWindowTarget}; pub use self::monitor::MonitorHandle; pub use self::window::{ @@ -100,4 +102,11 @@ impl DeviceId { unsafe impl Send for DeviceId {} unsafe impl Sync for DeviceId {} +#[derive(Debug)] pub enum OsError {} + +impl fmt::Display for OsError { + fn fmt(&self, _: &mut fmt::Formatter) -> fmt::Result { + match self {} + } +} From 5b477a739ce5a4028e64ecccb84749929b2c00f8 Mon Sep 17 00:00:00 2001 From: Osspial Date: Tue, 28 May 2019 01:32:47 -0400 Subject: [PATCH 16/22] Fix Display impl --- src/platform_impl/ios/mod.rs | 4 +++- src/platform_impl/ios/view.rs | 2 +- src/platform_impl/ios/window.rs | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/platform_impl/ios/mod.rs b/src/platform_impl/ios/mod.rs index 4250b074af..73dd2b2e66 100644 --- a/src/platform_impl/ios/mod.rs +++ b/src/platform_impl/ios/mod.rs @@ -107,6 +107,8 @@ pub enum OsError {} impl fmt::Display for OsError { fn fmt(&self, _: &mut fmt::Formatter) -> fmt::Result { - match self {} + match self { + _ => unreachable!() + } } } diff --git a/src/platform_impl/ios/view.rs b/src/platform_impl/ios/view.rs index 68134c4f42..9205df43b3 100644 --- a/src/platform_impl/ios/view.rs +++ b/src/platform_impl/ios/view.rs @@ -255,7 +255,7 @@ unsafe fn get_window_class() -> &'static Class { // requires main thread pub unsafe fn create_view( - window_attributes: &WindowAttributes, + _window_attributes: &WindowAttributes, platform_attributes: &PlatformSpecificWindowBuilderAttributes, frame: CGRect, ) -> id { diff --git a/src/platform_impl/ios/window.rs b/src/platform_impl/ios/window.rs index 358082b9e9..99c934de40 100644 --- a/src/platform_impl/ios/window.rs +++ b/src/platform_impl/ios/window.rs @@ -163,7 +163,7 @@ impl Inner { Err(ExternalError::NotSupported(NotSupportedError::new())) } - pub fn set_cursor_visible(&self, visible: bool) { + pub fn set_cursor_visible(&self, _visible: bool) { debug!("`Window::set_cursor_visible` is ignored on iOS") } From deb56cf8abb3c040c35a621b0cc29c341f709e9d Mon Sep 17 00:00:00 2001 From: Osspial Date: Tue, 28 May 2019 01:37:33 -0400 Subject: [PATCH 17/22] Fix unused code warnings and travis --- .travis.yml | 64 ++++++++++++++++++++++++++-------------------------- src/error.rs | 2 ++ 2 files changed, 34 insertions(+), 32 deletions(-) diff --git a/.travis.yml b/.travis.yml index 8d487a4818..e8b7e47c5a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,6 +4,38 @@ cache: cargo matrix: include: + # Linux 32bit + - env: TARGET=i686-unknown-linux-gnu + os: linux + rust: nightly + addons: + apt: + # Cross compiler and cross compiled C libraries + packages: &i686_packages + - gcc-multilib + - env: TARGET=i686-unknown-linux-gnu + os: linux + rust: stable + addons: + apt: + packages: *i686_packages + + # Linux 64bit + - env: TARGET=x86_64-unknown-linux-gnu + os: linux + rust: nightly + - env: TARGET=x86_64-unknown-linux-gnu + os: linux + rust: stable + + # macOS + - env: TARGET=x86_64-apple-darwin + os: osx + rust: nightly + - env: TARGET=x86_64-apple-darwin + os: osx + rust: stable + # iOS - env: TARGET=x86_64-apple-ios os: osx @@ -12,38 +44,6 @@ matrix: os: osx rust: stable - # # Linux 32bit - # - env: TARGET=i686-unknown-linux-gnu - # os: linux - # rust: nightly - # addons: - # apt: - # # Cross compiler and cross compiled C libraries - # packages: &i686_packages - # - gcc-multilib - # - env: TARGET=i686-unknown-linux-gnu - # os: linux - # rust: stable - # addons: - # apt: - # packages: *i686_packages - - # # Linux 64bit - # - env: TARGET=x86_64-unknown-linux-gnu - # os: linux - # rust: nightly - # - env: TARGET=x86_64-unknown-linux-gnu - # os: linux - # rust: stable - - # # macOS - # - env: TARGET=x86_64-apple-darwin - # os: osx - # rust: nightly - # - env: TARGET=x86_64-apple-darwin - # os: osx - # rust: stable - install: - rustup self update - rustup target add $TARGET; true diff --git a/src/error.rs b/src/error.rs index 85046ae5ef..83c37210ae 100644 --- a/src/error.rs +++ b/src/error.rs @@ -28,6 +28,7 @@ pub struct OsError { impl NotSupportedError { #[inline] + #[allow(dead_code)] pub(crate) fn new() -> NotSupportedError { NotSupportedError { _marker: () @@ -36,6 +37,7 @@ impl NotSupportedError { } impl OsError { + #[allow(dead_code)] pub(crate) fn new(line: u32, file: &'static str, error: platform_impl::OsError) -> OsError { OsError { line, From 7b41baea155af4e83b7e644494307da765632053 Mon Sep 17 00:00:00 2001 From: Osspial Date: Wed, 29 May 2019 02:37:15 -0400 Subject: [PATCH 18/22] Rename set_ime_spot to set_ime_position --- src/platform_impl/android/mod.rs | 2 +- src/platform_impl/emscripten/mod.rs | 2 +- src/platform_impl/ios/window.rs | 4 ++-- src/platform_impl/linux/mod.rs | 4 ++-- src/platform_impl/linux/x11/window.rs | 6 +++--- src/platform_impl/macos/view.rs | 2 +- src/platform_impl/macos/window.rs | 4 ++-- src/platform_impl/windows/window.rs | 2 +- src/window.rs | 4 ++-- 9 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/platform_impl/android/mod.rs b/src/platform_impl/android/mod.rs index 7040f848d5..3857e3db3d 100644 --- a/src/platform_impl/android/mod.rs +++ b/src/platform_impl/android/mod.rs @@ -400,7 +400,7 @@ impl Window { } #[inline] - pub fn set_ime_spot(&self, _spot: LogicalPosition) { + pub fn set_ime_position(&self, _spot: LogicalPosition) { // N/A } diff --git a/src/platform_impl/emscripten/mod.rs b/src/platform_impl/emscripten/mod.rs index 9badc84f30..b64ffc2db5 100644 --- a/src/platform_impl/emscripten/mod.rs +++ b/src/platform_impl/emscripten/mod.rs @@ -609,7 +609,7 @@ impl Window { } #[inline] - pub fn set_ime_spot(&self, _logical_spot: LogicalPosition) { + pub fn set_ime_position(&self, _logical_spot: LogicalPosition) { // N/A } diff --git a/src/platform_impl/ios/window.rs b/src/platform_impl/ios/window.rs index 99c934de40..88a399d088 100644 --- a/src/platform_impl/ios/window.rs +++ b/src/platform_impl/ios/window.rs @@ -225,8 +225,8 @@ impl Inner { warn!("`Window::set_window_icon` is ignored on iOS") } - pub fn set_ime_spot(&self, _position: LogicalPosition) { - warn!("`Window::set_ime_spot` is ignored on iOS") + pub fn set_ime_position(&self, _position: LogicalPosition) { + warn!("`Window::set_ime_position` is ignored on iOS") } pub fn current_monitor(&self) -> RootMonitorHandle { diff --git a/src/platform_impl/linux/mod.rs b/src/platform_impl/linux/mod.rs index 88c5114bd2..96a2b30dc1 100644 --- a/src/platform_impl/linux/mod.rs +++ b/src/platform_impl/linux/mod.rs @@ -347,9 +347,9 @@ impl Window { } #[inline] - pub fn set_ime_spot(&self, position: LogicalPosition) { + pub fn set_ime_position(&self, position: LogicalPosition) { match self { - &Window::X(ref w) => w.set_ime_spot(position), + &Window::X(ref w) => w.set_ime_position(position), &Window::Wayland(_) => (), } } diff --git a/src/platform_impl/linux/x11/window.rs b/src/platform_impl/linux/x11/window.rs index 300d438d28..cb532b6ffa 100644 --- a/src/platform_impl/linux/x11/window.rs +++ b/src/platform_impl/linux/x11/window.rs @@ -1211,16 +1211,16 @@ impl UnownedWindow { self.set_cursor_position_physical(x, y) } - pub(crate) fn set_ime_spot_physical(&self, x: i32, y: i32) { + pub(crate) fn set_ime_position_physical(&self, x: i32, y: i32) { let _ = self.ime_sender .lock() .send((self.xwindow, x as i16, y as i16)); } #[inline] - pub fn set_ime_spot(&self, logical_spot: LogicalPosition) { + pub fn set_ime_position(&self, logical_spot: LogicalPosition) { let (x, y) = logical_spot.to_physical(self.hidpi_factor()).into(); - self.set_ime_spot_physical(x, y); + self.set_ime_position_physical(x, y); } #[inline] diff --git a/src/platform_impl/macos/view.rs b/src/platform_impl/macos/view.rs index 914962c6c6..481087ff43 100644 --- a/src/platform_impl/macos/view.rs +++ b/src/platform_impl/macos/view.rs @@ -58,7 +58,7 @@ pub fn new_view(nswindow: id) -> (IdRef, Weak>) { } } -pub unsafe fn set_ime_spot(nsview: id, input_context: id, x: f64, y: f64) { +pub unsafe fn set_ime_position(nsview: id, input_context: id, x: f64, y: f64) { let state_ptr: *mut c_void = *(*nsview).get_mut_ivar("winitState"); let state = &mut *(state_ptr as *mut ViewState); let content_rect = NSWindow::contentRectForFrameRect_( diff --git a/src/platform_impl/macos/window.rs b/src/platform_impl/macos/window.rs index 744f5003a8..9277b4aa39 100644 --- a/src/platform_impl/macos/window.rs +++ b/src/platform_impl/macos/window.rs @@ -734,9 +734,9 @@ impl UnownedWindow { } #[inline] - pub fn set_ime_spot(&self, logical_spot: LogicalPosition) { + pub fn set_ime_position(&self, logical_spot: LogicalPosition) { unsafe { - view::set_ime_spot( + view::set_ime_position( *self.nsview, *self.input_context, logical_spot.x, diff --git a/src/platform_impl/windows/window.rs b/src/platform_impl/windows/window.rs index f0692c9172..f918fa2b84 100644 --- a/src/platform_impl/windows/window.rs +++ b/src/platform_impl/windows/window.rs @@ -518,7 +518,7 @@ impl Window { } #[inline] - pub fn set_ime_spot(&self, _logical_spot: LogicalPosition) { + pub fn set_ime_position(&self, _logical_spot: LogicalPosition) { unimplemented!(); } } diff --git a/src/window.rs b/src/window.rs index d40e76ecfd..8cc07ced75 100644 --- a/src/window.rs +++ b/src/window.rs @@ -633,8 +633,8 @@ impl Window { /// /// **iOS:** Has no effect. #[inline] - pub fn set_ime_spot(&self, position: LogicalPosition) { - self.window.set_ime_spot(position) + pub fn set_ime_position(&self, position: LogicalPosition) { + self.window.set_ime_position(position) } /// Returns the monitor on which the window currently resides From ecc77f78a3edbad056903b1b74818866772698f2 Mon Sep 17 00:00:00 2001 From: Osspial Date: Wed, 29 May 2019 12:30:32 -0400 Subject: [PATCH 19/22] Add CHANGELOG entry --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index bf53744b65..6d48e850c8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -37,6 +37,8 @@ - `LoopDestroyed` is emitted when the `run` or `run_return` method is about to exit. - Rename `MonitorId` to `MonitorHandle`. - Removed `serde` implementations from `ControlFlow`. +- Rename several functions to improve both internal consistency and compliance with Rust API guidelines. +- Remove `WindowBuilder::multitouch` field, since it was only implemented on a few platforms. Multitouch is always enabled now. # Version 0.19.1 (2019-04-08) From 7803a4f2bb91a2c197d769f8fb98b4c7db6413dc Mon Sep 17 00:00:00 2001 From: Osspial Date: Wed, 29 May 2019 12:32:51 -0400 Subject: [PATCH 20/22] Rename set_cursor to set_cursor_icon and MouseCursor to CursorIcon --- examples/cursor.rs | 30 ++++---- examples/multithreaded.rs | 8 +-- src/platform_impl/android/mod.rs | 4 +- src/platform_impl/emscripten/mod.rs | 2 +- src/platform_impl/ios/window.rs | 6 +- src/platform_impl/linux/mod.rs | 8 +-- src/platform_impl/linux/wayland/window.rs | 4 +- src/platform_impl/linux/x11/window.rs | 86 +++++++++++------------ src/platform_impl/macos/util/cursor.rs | 66 ++++++++--------- src/platform_impl/macos/window.rs | 4 +- src/platform_impl/windows/util.rs | 40 +++++------ src/platform_impl/windows/window.rs | 4 +- src/platform_impl/windows/window_state.rs | 6 +- src/window.rs | 12 ++-- tests/serde_objects.rs | 4 +- 15 files changed, 142 insertions(+), 142 deletions(-) diff --git a/examples/cursor.rs b/examples/cursor.rs index 27c003ac2d..59441c2233 100644 --- a/examples/cursor.rs +++ b/examples/cursor.rs @@ -1,6 +1,6 @@ extern crate winit; -use winit::window::{WindowBuilder, MouseCursor}; +use winit::window::{WindowBuilder, CursorIcon}; use winit::event::{Event, WindowEvent, ElementState, KeyboardInput}; use winit::event_loop::{EventLoop, ControlFlow}; @@ -16,7 +16,7 @@ fn main() { match event { Event::WindowEvent { event: WindowEvent::KeyboardInput { input: KeyboardInput { state: ElementState::Pressed, .. }, .. }, .. } => { println!("Setting cursor to \"{:?}\"", CURSORS[cursor_idx]); - window.set_cursor(CURSORS[cursor_idx]); + window.set_cursor_icon(CURSORS[cursor_idx]); if cursor_idx < CURSORS.len() - 1 { cursor_idx += 1; } else { @@ -32,17 +32,17 @@ fn main() { }); } -const CURSORS: &[MouseCursor] = &[ - MouseCursor::Default, MouseCursor::Crosshair, MouseCursor::Hand, - MouseCursor::Arrow, MouseCursor::Move, MouseCursor::Text, - MouseCursor::Wait, MouseCursor::Help, MouseCursor::Progress, - MouseCursor::NotAllowed, MouseCursor::ContextMenu, MouseCursor::Cell, - MouseCursor::VerticalText, MouseCursor::Alias, MouseCursor::Copy, - MouseCursor::NoDrop, MouseCursor::Grab, MouseCursor::Grabbing, - MouseCursor::AllScroll, MouseCursor::ZoomIn, MouseCursor::ZoomOut, - MouseCursor::EResize, MouseCursor::NResize, MouseCursor::NeResize, - MouseCursor::NwResize, MouseCursor::SResize, MouseCursor::SeResize, - MouseCursor::SwResize, MouseCursor::WResize, MouseCursor::EwResize, - MouseCursor::NsResize, MouseCursor::NeswResize, MouseCursor::NwseResize, - MouseCursor::ColResize, MouseCursor::RowResize +const CURSORS: &[CursorIcon] = &[ + CursorIcon::Default, CursorIcon::Crosshair, CursorIcon::Hand, + CursorIcon::Arrow, CursorIcon::Move, CursorIcon::Text, + CursorIcon::Wait, CursorIcon::Help, CursorIcon::Progress, + CursorIcon::NotAllowed, CursorIcon::ContextMenu, CursorIcon::Cell, + CursorIcon::VerticalText, CursorIcon::Alias, CursorIcon::Copy, + CursorIcon::NoDrop, CursorIcon::Grab, CursorIcon::Grabbing, + CursorIcon::AllScroll, CursorIcon::ZoomIn, CursorIcon::ZoomOut, + CursorIcon::EResize, CursorIcon::NResize, CursorIcon::NeResize, + CursorIcon::NwResize, CursorIcon::SResize, CursorIcon::SeResize, + CursorIcon::SwResize, CursorIcon::WResize, CursorIcon::EwResize, + CursorIcon::NsResize, CursorIcon::NeswResize, CursorIcon::NwseResize, + CursorIcon::ColResize, CursorIcon::RowResize ]; diff --git a/examples/multithreaded.rs b/examples/multithreaded.rs index 5bfba334cc..054087994e 100644 --- a/examples/multithreaded.rs +++ b/examples/multithreaded.rs @@ -5,7 +5,7 @@ use std::{collections::HashMap, sync::mpsc, thread, time::Duration}; use winit::{ event::{ElementState, Event, KeyboardInput, VirtualKeyCode, WindowEvent}, - event_loop::{ControlFlow, EventLoop}, window::{MouseCursor, WindowBuilder}, + event_loop::{ControlFlow, EventLoop}, window::{CursorIcon, WindowBuilder}, }; const WINDOW_COUNT: usize = 3; @@ -36,9 +36,9 @@ fn main() { use self::VirtualKeyCode::*; match key { A => window.set_always_on_top(state), - C => window.set_cursor(match state { - true => MouseCursor::Progress, - false => MouseCursor::Default, + C => window.set_cursor_icon(match state { + true => CursorIcon::Progress, + false => CursorIcon::Default, }), D => window.set_decorations(!state), F => window.set_fullscreen(match state { diff --git a/src/platform_impl/android/mod.rs b/src/platform_impl/android/mod.rs index 3857e3db3d..ce58c0e758 100644 --- a/src/platform_impl/android/mod.rs +++ b/src/platform_impl/android/mod.rs @@ -15,7 +15,7 @@ use { Event, LogicalPosition, LogicalSize, - MouseCursor, + CursorIcon, PhysicalPosition, PhysicalSize, WindowAttributes, @@ -346,7 +346,7 @@ impl Window { } #[inline] - pub fn set_cursor(&self, _: MouseCursor) { + pub fn set_cursor_icon(&self, _: CursorIcon) { // N/A } diff --git a/src/platform_impl/emscripten/mod.rs b/src/platform_impl/emscripten/mod.rs index b64ffc2db5..140ba53d97 100644 --- a/src/platform_impl/emscripten/mod.rs +++ b/src/platform_impl/emscripten/mod.rs @@ -525,7 +525,7 @@ impl Window { } #[inline] - pub fn set_cursor(&self, _cursor: ::MouseCursor) { + pub fn set_cursor_icon(&self, _cursor: ::CursorIcon) { // N/A } diff --git a/src/platform_impl/ios/window.rs b/src/platform_impl/ios/window.rs index 88a399d088..2ebbb469fa 100644 --- a/src/platform_impl/ios/window.rs +++ b/src/platform_impl/ios/window.rs @@ -11,7 +11,7 @@ use icon::Icon; use monitor::MonitorHandle as RootMonitorHandle; use platform::ios::{MonitorHandleExtIOS, ValidOrientations}; use window::{ - MouseCursor, + CursorIcon, WindowAttributes, }; use platform_impl::{ @@ -151,8 +151,8 @@ impl Inner { } } - pub fn set_cursor(&self, _cursor: MouseCursor) { - debug!("`Window::set_cursor` ignored on iOS") + pub fn set_cursor_icon(&self, _cursor: CursorIcon) { + debug!("`Window::set_cursor_icon` ignored on iOS") } pub fn set_cursor_position(&self, _position: LogicalPosition) -> Result<(), ExternalError> { diff --git a/src/platform_impl/linux/mod.rs b/src/platform_impl/linux/mod.rs index 96a2b30dc1..3b316a25d8 100644 --- a/src/platform_impl/linux/mod.rs +++ b/src/platform_impl/linux/mod.rs @@ -15,7 +15,7 @@ use error::{ExternalError, NotSupportedError, OsError as RootOsError}; use event::Event; use event_loop::{EventLoopClosed, ControlFlow, EventLoopWindowTarget as RootELW}; use monitor::MonitorHandle as RootMonitorHandle; -use window::{WindowAttributes, MouseCursor}; +use window::{WindowAttributes, CursorIcon}; use self::x11::{XConnection, XError}; use self::x11::ffi::XVisualInfo; pub use self::x11::XNotSupported; @@ -258,10 +258,10 @@ impl Window { } #[inline] - pub fn set_cursor(&self, cursor: MouseCursor) { + pub fn set_cursor_icon(&self, cursor: CursorIcon) { match self { - &Window::X(ref w) => w.set_cursor(cursor), - &Window::Wayland(ref w) => w.set_cursor(cursor) + &Window::X(ref w) => w.set_cursor_icon(cursor), + &Window::Wayland(ref w) => w.set_cursor_icon(cursor) } } diff --git a/src/platform_impl/linux/wayland/window.rs b/src/platform_impl/linux/wayland/window.rs index 509a31224b..976caf7593 100644 --- a/src/platform_impl/linux/wayland/window.rs +++ b/src/platform_impl/linux/wayland/window.rs @@ -5,7 +5,7 @@ use dpi::{LogicalPosition, LogicalSize}; use error::{ExternalError, NotSupportedError, OsError as RootOsError}; use platform_impl::{MonitorHandle as PlatformMonitorHandle, PlatformSpecificWindowBuilderAttributes as PlAttributes}; use monitor::MonitorHandle as RootMonitorHandle; -use window::{WindowAttributes, MouseCursor}; +use window::{WindowAttributes, CursorIcon}; use sctk::surface::{get_dpi_factor, get_outputs}; use sctk::window::{ConceptFrame, Event as WEvent, State as WState, Window as SWindow, Theme}; @@ -258,7 +258,7 @@ impl Window { } #[inline] - pub fn set_cursor(&self, _cursor: MouseCursor) { + pub fn set_cursor_icon(&self, _cursor: CursorIcon) { // TODO } diff --git a/src/platform_impl/linux/x11/window.rs b/src/platform_impl/linux/x11/window.rs index cb532b6ffa..1e5330c7d5 100644 --- a/src/platform_impl/linux/x11/window.rs +++ b/src/platform_impl/linux/x11/window.rs @@ -9,7 +9,7 @@ use libc; use parking_lot::Mutex; use error::{ExternalError, NotSupportedError, OsError as RootOsError}; -use window::{Icon, MouseCursor, WindowAttributes}; +use window::{Icon, CursorIcon, WindowAttributes}; use dpi::{LogicalPosition, LogicalSize}; use platform_impl::MonitorHandle as PlatformMonitorHandle; use platform_impl::{OsError, PlatformSpecificWindowBuilderAttributes}; @@ -63,7 +63,7 @@ pub struct UnownedWindow { xwindow: ffi::Window, // never changes root: ffi::Window, // never changes screen_id: i32, // never changes - cursor: Mutex, + cursor: Mutex, cursor_grabbed: Mutex, cursor_visible: Mutex, ime_sender: Mutex, @@ -998,7 +998,7 @@ impl UnownedWindow { 0 } - fn get_cursor(&self, cursor: MouseCursor) -> ffi::Cursor { + fn get_cursor(&self, cursor: CursorIcon) -> ffi::Cursor { let load = |name: &[u8]| { self.load_cursor(name) }; @@ -1012,48 +1012,48 @@ impl UnownedWindow { // // Try the better looking (or more suiting) names first. match cursor { - MouseCursor::Alias => load(b"link\0"), - MouseCursor::Arrow => load(b"arrow\0"), - MouseCursor::Cell => load(b"plus\0"), - MouseCursor::Copy => load(b"copy\0"), - MouseCursor::Crosshair => load(b"crosshair\0"), - MouseCursor::Default => load(b"left_ptr\0"), - MouseCursor::Hand => loadn(&[b"hand2\0", b"hand1\0"]), - MouseCursor::Help => load(b"question_arrow\0"), - MouseCursor::Move => load(b"move\0"), - MouseCursor::Grab => loadn(&[b"openhand\0", b"grab\0"]), - MouseCursor::Grabbing => loadn(&[b"closedhand\0", b"grabbing\0"]), - MouseCursor::Progress => load(b"left_ptr_watch\0"), - MouseCursor::AllScroll => load(b"all-scroll\0"), - MouseCursor::ContextMenu => load(b"context-menu\0"), - - MouseCursor::NoDrop => loadn(&[b"no-drop\0", b"circle\0"]), - MouseCursor::NotAllowed => load(b"crossed_circle\0"), + CursorIcon::Alias => load(b"link\0"), + CursorIcon::Arrow => load(b"arrow\0"), + CursorIcon::Cell => load(b"plus\0"), + CursorIcon::Copy => load(b"copy\0"), + CursorIcon::Crosshair => load(b"crosshair\0"), + CursorIcon::Default => load(b"left_ptr\0"), + CursorIcon::Hand => loadn(&[b"hand2\0", b"hand1\0"]), + CursorIcon::Help => load(b"question_arrow\0"), + CursorIcon::Move => load(b"move\0"), + CursorIcon::Grab => loadn(&[b"openhand\0", b"grab\0"]), + CursorIcon::Grabbing => loadn(&[b"closedhand\0", b"grabbing\0"]), + CursorIcon::Progress => load(b"left_ptr_watch\0"), + CursorIcon::AllScroll => load(b"all-scroll\0"), + CursorIcon::ContextMenu => load(b"context-menu\0"), + + CursorIcon::NoDrop => loadn(&[b"no-drop\0", b"circle\0"]), + CursorIcon::NotAllowed => load(b"crossed_circle\0"), // Resize cursors - MouseCursor::EResize => load(b"right_side\0"), - MouseCursor::NResize => load(b"top_side\0"), - MouseCursor::NeResize => load(b"top_right_corner\0"), - MouseCursor::NwResize => load(b"top_left_corner\0"), - MouseCursor::SResize => load(b"bottom_side\0"), - MouseCursor::SeResize => load(b"bottom_right_corner\0"), - MouseCursor::SwResize => load(b"bottom_left_corner\0"), - MouseCursor::WResize => load(b"left_side\0"), - MouseCursor::EwResize => load(b"h_double_arrow\0"), - MouseCursor::NsResize => load(b"v_double_arrow\0"), - MouseCursor::NwseResize => loadn(&[b"bd_double_arrow\0", b"size_bdiag\0"]), - MouseCursor::NeswResize => loadn(&[b"fd_double_arrow\0", b"size_fdiag\0"]), - MouseCursor::ColResize => loadn(&[b"split_h\0", b"h_double_arrow\0"]), - MouseCursor::RowResize => loadn(&[b"split_v\0", b"v_double_arrow\0"]), - - MouseCursor::Text => loadn(&[b"text\0", b"xterm\0"]), - MouseCursor::VerticalText => load(b"vertical-text\0"), - - MouseCursor::Wait => load(b"watch\0"), - - MouseCursor::ZoomIn => load(b"zoom-in\0"), - MouseCursor::ZoomOut => load(b"zoom-out\0"), + CursorIcon::EResize => load(b"right_side\0"), + CursorIcon::NResize => load(b"top_side\0"), + CursorIcon::NeResize => load(b"top_right_corner\0"), + CursorIcon::NwResize => load(b"top_left_corner\0"), + CursorIcon::SResize => load(b"bottom_side\0"), + CursorIcon::SeResize => load(b"bottom_right_corner\0"), + CursorIcon::SwResize => load(b"bottom_left_corner\0"), + CursorIcon::WResize => load(b"left_side\0"), + CursorIcon::EwResize => load(b"h_double_arrow\0"), + CursorIcon::NsResize => load(b"v_double_arrow\0"), + CursorIcon::NwseResize => loadn(&[b"bd_double_arrow\0", b"size_bdiag\0"]), + CursorIcon::NeswResize => loadn(&[b"fd_double_arrow\0", b"size_fdiag\0"]), + CursorIcon::ColResize => loadn(&[b"split_h\0", b"h_double_arrow\0"]), + CursorIcon::RowResize => loadn(&[b"split_v\0", b"v_double_arrow\0"]), + + CursorIcon::Text => loadn(&[b"text\0", b"xterm\0"]), + CursorIcon::VerticalText => load(b"vertical-text\0"), + + CursorIcon::Wait => load(b"watch\0"), + + CursorIcon::ZoomIn => load(b"zoom-in\0"), + CursorIcon::ZoomOut => load(b"zoom-out\0"), } } @@ -1068,7 +1068,7 @@ impl UnownedWindow { } #[inline] - pub fn set_cursor(&self, cursor: MouseCursor) { + pub fn set_cursor_icon(&self, cursor: CursorIcon) { *self.cursor.lock() = cursor; if *self.cursor_visible.lock() { self.update_cursor(self.get_cursor(cursor)); diff --git a/src/platform_impl/macos/util/cursor.rs b/src/platform_impl/macos/util/cursor.rs index dd017555a3..9d93762d86 100644 --- a/src/platform_impl/macos/util/cursor.rs +++ b/src/platform_impl/macos/util/cursor.rs @@ -4,7 +4,7 @@ use cocoa::{ }; use objc::runtime::Sel; -use window::MouseCursor; +use window::CursorIcon; pub enum Cursor { Native(&'static str), @@ -12,54 +12,54 @@ pub enum Cursor { WebKit(&'static str), } -impl From for Cursor { - fn from(cursor: MouseCursor) -> Self { +impl From for Cursor { + fn from(cursor: CursorIcon) -> Self { match cursor { - MouseCursor::Arrow | MouseCursor::Default => Cursor::Native("arrowCursor"), - MouseCursor::Hand => Cursor::Native("pointingHandCursor"), - MouseCursor::Grabbing | MouseCursor::Grab => Cursor::Native("closedHandCursor"), - MouseCursor::Text => Cursor::Native("IBeamCursor"), - MouseCursor::VerticalText => Cursor::Native("IBeamCursorForVerticalLayout"), - MouseCursor::Copy => Cursor::Native("dragCopyCursor"), - MouseCursor::Alias => Cursor::Native("dragLinkCursor"), - MouseCursor::NotAllowed | MouseCursor::NoDrop => Cursor::Native("operationNotAllowedCursor"), - MouseCursor::ContextMenu => Cursor::Native("contextualMenuCursor"), - MouseCursor::Crosshair => Cursor::Native("crosshairCursor"), - MouseCursor::EResize => Cursor::Native("resizeRightCursor"), - MouseCursor::NResize => Cursor::Native("resizeUpCursor"), - MouseCursor::WResize => Cursor::Native("resizeLeftCursor"), - MouseCursor::SResize => Cursor::Native("resizeDownCursor"), - MouseCursor::EwResize | MouseCursor::ColResize => Cursor::Native("resizeLeftRightCursor"), - MouseCursor::NsResize | MouseCursor::RowResize => Cursor::Native("resizeUpDownCursor"), + CursorIcon::Arrow | CursorIcon::Default => Cursor::Native("arrowCursor"), + CursorIcon::Hand => Cursor::Native("pointingHandCursor"), + CursorIcon::Grabbing | CursorIcon::Grab => Cursor::Native("closedHandCursor"), + CursorIcon::Text => Cursor::Native("IBeamCursor"), + CursorIcon::VerticalText => Cursor::Native("IBeamCursorForVerticalLayout"), + CursorIcon::Copy => Cursor::Native("dragCopyCursor"), + CursorIcon::Alias => Cursor::Native("dragLinkCursor"), + CursorIcon::NotAllowed | CursorIcon::NoDrop => Cursor::Native("operationNotAllowedCursor"), + CursorIcon::ContextMenu => Cursor::Native("contextualMenuCursor"), + CursorIcon::Crosshair => Cursor::Native("crosshairCursor"), + CursorIcon::EResize => Cursor::Native("resizeRightCursor"), + CursorIcon::NResize => Cursor::Native("resizeUpCursor"), + CursorIcon::WResize => Cursor::Native("resizeLeftCursor"), + CursorIcon::SResize => Cursor::Native("resizeDownCursor"), + CursorIcon::EwResize | CursorIcon::ColResize => Cursor::Native("resizeLeftRightCursor"), + CursorIcon::NsResize | CursorIcon::RowResize => Cursor::Native("resizeUpDownCursor"), // Undocumented cursors: https://stackoverflow.com/a/46635398/5435443 - MouseCursor::Help => Cursor::Undocumented("_helpCursor"), - MouseCursor::ZoomIn => Cursor::Undocumented("_zoomInCursor"), - MouseCursor::ZoomOut => Cursor::Undocumented("_zoomOutCursor"), - MouseCursor::NeResize => Cursor::Undocumented("_windowResizeNorthEastCursor"), - MouseCursor::NwResize => Cursor::Undocumented("_windowResizeNorthWestCursor"), - MouseCursor::SeResize => Cursor::Undocumented("_windowResizeSouthEastCursor"), - MouseCursor::SwResize => Cursor::Undocumented("_windowResizeSouthWestCursor"), - MouseCursor::NeswResize => Cursor::Undocumented("_windowResizeNorthEastSouthWestCursor"), - MouseCursor::NwseResize => Cursor::Undocumented("_windowResizeNorthWestSouthEastCursor"), + CursorIcon::Help => Cursor::Undocumented("_helpCursor"), + CursorIcon::ZoomIn => Cursor::Undocumented("_zoomInCursor"), + CursorIcon::ZoomOut => Cursor::Undocumented("_zoomOutCursor"), + CursorIcon::NeResize => Cursor::Undocumented("_windowResizeNorthEastCursor"), + CursorIcon::NwResize => Cursor::Undocumented("_windowResizeNorthWestCursor"), + CursorIcon::SeResize => Cursor::Undocumented("_windowResizeSouthEastCursor"), + CursorIcon::SwResize => Cursor::Undocumented("_windowResizeSouthWestCursor"), + CursorIcon::NeswResize => Cursor::Undocumented("_windowResizeNorthEastSouthWestCursor"), + CursorIcon::NwseResize => Cursor::Undocumented("_windowResizeNorthWestSouthEastCursor"), // While these are available, the former just loads a white arrow, // and the latter loads an ugly deflated beachball! - // MouseCursor::Move => Cursor::Undocumented("_moveCursor"), - // MouseCursor::Wait => Cursor::Undocumented("_waitCursor"), + // CursorIcon::Move => Cursor::Undocumented("_moveCursor"), + // CursorIcon::Wait => Cursor::Undocumented("_waitCursor"), // An even more undocumented cursor... // https://bugs.eclipse.org/bugs/show_bug.cgi?id=522349 // This is the wrong semantics for `Wait`, but it's the same as // what's used in Safari and Chrome. - MouseCursor::Wait | MouseCursor::Progress => Cursor::Undocumented("busyButClickableCursor"), + CursorIcon::Wait | CursorIcon::Progress => Cursor::Undocumented("busyButClickableCursor"), // For the rest, we can just snatch the cursors from WebKit... // They fit the style of the native cursors, and will seem // completely standard to macOS users. // https://stackoverflow.com/a/21786835/5435443 - MouseCursor::Move | MouseCursor::AllScroll => Cursor::WebKit("move"), - MouseCursor::Cell => Cursor::WebKit("cell"), + CursorIcon::Move | CursorIcon::AllScroll => Cursor::WebKit("move"), + CursorIcon::Cell => Cursor::WebKit("cell"), } } } diff --git a/src/platform_impl/macos/window.rs b/src/platform_impl/macos/window.rs index 9277b4aa39..143d77e2fb 100644 --- a/src/platform_impl/macos/window.rs +++ b/src/platform_impl/macos/window.rs @@ -20,7 +20,7 @@ use { error::{ExternalError, NotSupportedError, OsError as RootOsError}, monitor::MonitorHandle as RootMonitorHandle, window::{ - MouseCursor, WindowAttributes, WindowId as RootWindowId, + CursorIcon, WindowAttributes, WindowId as RootWindowId, }, }; use platform::macos::{ActivationPolicy, WindowExtMacOS}; @@ -483,7 +483,7 @@ impl UnownedWindow { } // Otherwise, we don't change the mask until we exit fullscreen. } - pub fn set_cursor(&self, cursor: MouseCursor) { + pub fn set_cursor_icon(&self, cursor: CursorIcon) { let cursor = util::Cursor::from(cursor); if let Some(cursor_access) = self.cursor.upgrade() { *cursor_access.lock().unwrap() = cursor; diff --git a/src/platform_impl/windows/util.rs b/src/platform_impl/windows/util.rs index 6a540a4904..a46c44bd0b 100644 --- a/src/platform_impl/windows/util.rs +++ b/src/platform_impl/windows/util.rs @@ -2,7 +2,7 @@ use std::{mem, ptr, slice, io}; use std::ops::BitAnd; use std::sync::atomic::{AtomicBool, Ordering}; -use window::MouseCursor; +use window::CursorIcon; use winapi::ctypes::wchar_t; use winapi::shared::minwindef::{BOOL, DWORD}; use winapi::shared::windef::{HWND, POINT, RECT}; @@ -103,27 +103,27 @@ pub fn is_focused(window: HWND) -> bool { window == unsafe{ winuser::GetActiveWindow() } } -impl MouseCursor { +impl CursorIcon { pub(crate) fn to_windows_cursor(self) -> *const wchar_t { match self { - MouseCursor::Arrow | MouseCursor::Default => winuser::IDC_ARROW, - MouseCursor::Hand => winuser::IDC_HAND, - MouseCursor::Crosshair => winuser::IDC_CROSS, - MouseCursor::Text | MouseCursor::VerticalText => winuser::IDC_IBEAM, - MouseCursor::NotAllowed | MouseCursor::NoDrop => winuser::IDC_NO, - MouseCursor::Grab | MouseCursor::Grabbing | - MouseCursor::Move | MouseCursor::AllScroll => winuser::IDC_SIZEALL, - MouseCursor::EResize | MouseCursor::WResize | - MouseCursor::EwResize | MouseCursor::ColResize => winuser::IDC_SIZEWE, - MouseCursor::NResize | MouseCursor::SResize | - MouseCursor::NsResize | MouseCursor::RowResize => winuser::IDC_SIZENS, - MouseCursor::NeResize | MouseCursor::SwResize | - MouseCursor::NeswResize => winuser::IDC_SIZENESW, - MouseCursor::NwResize | MouseCursor::SeResize | - MouseCursor::NwseResize => winuser::IDC_SIZENWSE, - MouseCursor::Wait => winuser::IDC_WAIT, - MouseCursor::Progress => winuser::IDC_APPSTARTING, - MouseCursor::Help => winuser::IDC_HELP, + CursorIcon::Arrow | CursorIcon::Default => winuser::IDC_ARROW, + CursorIcon::Hand => winuser::IDC_HAND, + CursorIcon::Crosshair => winuser::IDC_CROSS, + CursorIcon::Text | CursorIcon::VerticalText => winuser::IDC_IBEAM, + CursorIcon::NotAllowed | CursorIcon::NoDrop => winuser::IDC_NO, + CursorIcon::Grab | CursorIcon::Grabbing | + CursorIcon::Move | CursorIcon::AllScroll => winuser::IDC_SIZEALL, + CursorIcon::EResize | CursorIcon::WResize | + CursorIcon::EwResize | CursorIcon::ColResize => winuser::IDC_SIZEWE, + CursorIcon::NResize | CursorIcon::SResize | + CursorIcon::NsResize | CursorIcon::RowResize => winuser::IDC_SIZENS, + CursorIcon::NeResize | CursorIcon::SwResize | + CursorIcon::NeswResize => winuser::IDC_SIZENESW, + CursorIcon::NwResize | CursorIcon::SeResize | + CursorIcon::NwseResize => winuser::IDC_SIZENWSE, + CursorIcon::Wait => winuser::IDC_WAIT, + CursorIcon::Progress => winuser::IDC_APPSTARTING, + CursorIcon::Help => winuser::IDC_HELP, _ => winuser::IDC_ARROW, // use arrow for the missing cases. } } diff --git a/src/platform_impl/windows/window.rs b/src/platform_impl/windows/window.rs index f918fa2b84..351ffc1c8c 100644 --- a/src/platform_impl/windows/window.rs +++ b/src/platform_impl/windows/window.rs @@ -18,7 +18,7 @@ use winapi::um::wingdi::{CreateRectRgn, DeleteObject}; use winapi::um::oleidl::LPDROPTARGET; use winapi::um::winnt::{LONG, LPCWSTR}; -use window::{Icon, MouseCursor, WindowAttributes}; +use window::{Icon, CursorIcon, WindowAttributes}; use error::{ExternalError, NotSupportedError, OsError as RootOsError}; use dpi::{LogicalPosition, LogicalSize, PhysicalSize}; use monitor::MonitorHandle as RootMonitorHandle; @@ -302,7 +302,7 @@ impl Window { } #[inline] - pub fn set_cursor(&self, cursor: MouseCursor) { + pub fn set_cursor_icon(&self, cursor: CursorIcon) { self.window_state.lock().mouse.cursor = cursor; self.thread_executor.execute_in_thread(move || unsafe { let cursor = winuser::LoadCursorW( diff --git a/src/platform_impl/windows/window_state.rs b/src/platform_impl/windows/window_state.rs index ceb5910bd0..41dcb228f5 100644 --- a/src/platform_impl/windows/window_state.rs +++ b/src/platform_impl/windows/window_state.rs @@ -1,5 +1,5 @@ use monitor::MonitorHandle; -use window::{MouseCursor, WindowAttributes}; +use window::{CursorIcon, WindowAttributes}; use std::{io, ptr}; use parking_lot::MutexGuard; use dpi::LogicalSize; @@ -36,7 +36,7 @@ pub struct SavedWindow { #[derive(Clone)] pub struct MouseProperties { - pub cursor: MouseCursor, + pub cursor: CursorIcon, pub buttons_down: u32, cursor_flags: CursorFlags, } @@ -90,7 +90,7 @@ impl WindowState { ) -> WindowState { WindowState { mouse: MouseProperties { - cursor: MouseCursor::default(), + cursor: CursorIcon::default(), buttons_down: 0, cursor_flags: CursorFlags::empty(), }, diff --git a/src/window.rs b/src/window.rs index 8cc07ced75..6d02423de8 100644 --- a/src/window.rs +++ b/src/window.rs @@ -512,15 +512,15 @@ impl Window { self.window.hidpi_factor() } - /// Modifies the mouse cursor of the window. + /// Modifies the cursor icon of the window. /// /// ## Platform-specific /// /// - **iOS:** Has no effect. /// - **Android:** Has no effect. #[inline] - pub fn set_cursor(&self, cursor: MouseCursor) { - self.window.set_cursor(cursor); + pub fn set_cursor_icon(&self, cursor: CursorIcon) { + self.window.set_cursor_icon(cursor); } /// Changes the position of the cursor in window coordinates. @@ -682,7 +682,7 @@ impl Window { /// Describes the appearance of the mouse cursor. #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] -pub enum MouseCursor { +pub enum CursorIcon { /// The platform-dependent default cursor. Default, /// A simple crosshair. @@ -736,8 +736,8 @@ pub enum MouseCursor { RowResize, } -impl Default for MouseCursor { +impl Default for CursorIcon { fn default() -> Self { - MouseCursor::Default + CursorIcon::Default } } diff --git a/tests/serde_objects.rs b/tests/serde_objects.rs index 5effbbda09..00f30b8fef 100644 --- a/tests/serde_objects.rs +++ b/tests/serde_objects.rs @@ -3,7 +3,7 @@ extern crate serde; extern crate winit; -use winit::window::{MouseCursor}; +use winit::window::{CursorIcon}; use winit::event::{ KeyboardInput, TouchPhase, ElementState, MouseButton, MouseScrollDelta, VirtualKeyCode, ModifiersState @@ -15,7 +15,7 @@ fn needs_serde>() {} #[test] fn window_serde() { - needs_serde::(); + needs_serde::(); } #[test] From c3fa2cd7dffcc7961067339704fd899b8157e715 Mon Sep 17 00:00:00 2001 From: Osspial Date: Wed, 29 May 2019 12:49:34 -0400 Subject: [PATCH 21/22] Organize Window functions into multiple, categorized impls --- src/window.rs | 239 ++++++++++++++++++++++++++------------------------ 1 file changed, 126 insertions(+), 113 deletions(-) diff --git a/src/window.rs b/src/window.rs index 6d02423de8..2567d94d70 100644 --- a/src/window.rs +++ b/src/window.rs @@ -303,6 +303,7 @@ impl WindowBuilder { } } +/// Base Window functions. impl Window { /// Creates a new Window for platforms where this is appropriate. /// @@ -316,26 +317,31 @@ impl Window { builder.build(event_loop) } - /// Modifies the title of the window. - /// - /// ## Platform-specific - /// - /// - Has no effect on iOS. + /// Returns an identifier unique to the window. #[inline] - pub fn set_title(&self, title: &str) { - self.window.set_title(title) + pub fn id(&self) -> WindowId { + WindowId(self.window.id()) } - /// Modifies the window's visibility. + /// Returns the DPI factor that can be used to map logical pixels to physical pixels, and vice versa. + /// + /// See the [`dpi`](dpi/index.html) module for more information. + /// + /// Note that this value can change depending on user action (for example if the window is + /// moved to another screen); as such, tracking `WindowEvent::HiDpiFactorChanged` events is + /// the most robust way to track the DPI you need to use to draw. /// - /// If `false`, this will hide the window. If `true`, this will show the window. /// ## Platform-specific /// - /// - **Android:** Has no effect. - /// - **iOS:** Can only be called on the main thread. + /// - **X11:** This respects Xft.dpi, and can be overridden using the `WINIT_HIDPI_FACTOR` environment variable. + /// - **Android:** Always returns 1.0. + /// - **iOS:** Can only be called on the main thread. Returns the underlying `UIView`'s + /// [`contentScaleFactor`]. + /// + /// [`contentScaleFactor`]: https://developer.apple.com/documentation/uikit/uiview/1622657-contentscalefactor?language=objc #[inline] - pub fn set_visible(&self, visible: bool) { - self.window.set_visible(visible) + pub fn hidpi_factor(&self) -> f64 { + self.window.hidpi_factor() } /// Emits a `WindowEvent::RedrawRequested` event in the associated event loop after all OS @@ -357,6 +363,25 @@ impl Window { pub fn request_redraw(&self) { self.window.request_redraw() } +} + +/// Position and size functions. +impl Window { + /// Returns the position of the top-left hand corner of the window's client area relative to the + /// top-left hand corner of the desktop. + /// + /// The same conditions that apply to `outer_position` apply to this method. + /// + /// ## Platform-specific + /// + /// - **iOS:** Can only be called on the main thread. Returns the top left coordinates of the + /// window's [safe area] in the screen space coordinate system. + /// + /// [safe area]: https://developer.apple.com/documentation/uikit/uiview/2891103-safeareainsets?language=objc + #[inline] + pub fn inner_position(&self) -> Result { + self.window.inner_position() + } /// Returns the position of the top-left hand corner of the window relative to the /// top-left hand corner of the desktop. @@ -377,22 +402,6 @@ impl Window { self.window.outer_position() } - /// Returns the position of the top-left hand corner of the window's client area relative to the - /// top-left hand corner of the desktop. - /// - /// The same conditions that apply to `outer_position` apply to this method. - /// - /// ## Platform-specific - /// - /// - **iOS:** Can only be called on the main thread. Returns the top left coordinates of the - /// window's [safe area] in the screen space coordinate system. - /// - /// [safe area]: https://developer.apple.com/documentation/uikit/uiview/2891103-safeareainsets?language=objc - #[inline] - pub fn inner_position(&self) -> Result { - self.window.inner_position() - } - /// Modifies the position of the window. /// /// See `outer_position` for more information about the coordinates. @@ -425,31 +434,31 @@ impl Window { self.window.inner_size() } - /// Returns the logical size of the entire window. + /// Modifies the inner size of the window. /// - /// These dimensions include the title bar and borders. If you don't want that (and you usually don't), - /// use `inner_size` instead. + /// See `inner_size` for more information about the values. /// /// ## Platform-specific /// - /// - **iOS:** Can only be called on the main thread. Returns the `LogicalSize` of the window in - /// screen space coordinates. + /// - **iOS:** Unimplemented. Currently this panics, as it's not clear what `set_inner_size` + /// would mean for iOS. #[inline] - pub fn outer_size(&self) -> LogicalSize { - self.window.outer_size() + pub fn set_inner_size(&self, size: LogicalSize) { + self.window.set_inner_size(size) } - /// Modifies the inner size of the window. + /// Returns the logical size of the entire window. /// - /// See `inner_size` for more information about the values. + /// These dimensions include the title bar and borders. If you don't want that (and you usually don't), + /// use `inner_size` instead. /// /// ## Platform-specific /// - /// - **iOS:** Unimplemented. Currently this panics, as it's not clear what `set_inner_size` - /// would mean for iOS. + /// - **iOS:** Can only be called on the main thread. Returns the `LogicalSize` of the window in + /// screen space coordinates. #[inline] - pub fn set_inner_size(&self, size: LogicalSize) { - self.window.set_inner_size(size) + pub fn outer_size(&self) -> LogicalSize { + self.window.outer_size() } /// Sets a minimum dimension size for the window. @@ -471,94 +480,49 @@ impl Window { pub fn set_max_inner_size(&self, dimensions: Option) { self.window.set_max_inner_size(dimensions) } +} - /// Sets whether the window is resizable or not. - /// - /// Note that making the window unresizable doesn't exempt you from handling `Resized`, as that event can still be - /// triggered by DPI scaling, entering fullscreen mode, etc. - /// - /// ## Platform-specific - /// - /// This only has an effect on desktop platforms. - /// - /// Due to a bug in XFCE, this has no effect on Xfwm. - /// - /// ## Platform-specific - /// - /// - **iOS:** Has no effect. - #[inline] - pub fn set_resizable(&self, resizable: bool) { - self.window.set_resizable(resizable) - } - - /// Returns the DPI factor that can be used to map logical pixels to physical pixels, and vice versa. - /// - /// See the [`dpi`](dpi/index.html) module for more information. - /// - /// Note that this value can change depending on user action (for example if the window is - /// moved to another screen); as such, tracking `WindowEvent::HiDpiFactorChanged` events is - /// the most robust way to track the DPI you need to use to draw. +/// Misc. attribute functions. +impl Window { + /// Modifies the title of the window. /// /// ## Platform-specific /// - /// - **X11:** This respects Xft.dpi, and can be overridden using the `WINIT_HIDPI_FACTOR` environment variable. - /// - **Android:** Always returns 1.0. - /// - **iOS:** Can only be called on the main thread. Returns the underlying `UIView`'s - /// [`contentScaleFactor`]. - /// - /// [`contentScaleFactor`]: https://developer.apple.com/documentation/uikit/uiview/1622657-contentscalefactor?language=objc + /// - Has no effect on iOS. #[inline] - pub fn hidpi_factor(&self) -> f64 { - self.window.hidpi_factor() + pub fn set_title(&self, title: &str) { + self.window.set_title(title) } - /// Modifies the cursor icon of the window. + /// Modifies the window's visibility. /// + /// If `false`, this will hide the window. If `true`, this will show the window. /// ## Platform-specific /// - /// - **iOS:** Has no effect. /// - **Android:** Has no effect. + /// - **iOS:** Can only be called on the main thread. #[inline] - pub fn set_cursor_icon(&self, cursor: CursorIcon) { - self.window.set_cursor_icon(cursor); + pub fn set_visible(&self, visible: bool) { + self.window.set_visible(visible) } - /// Changes the position of the cursor in window coordinates. - /// - /// ## Platform-specific + /// Sets whether the window is resizable or not. /// - /// - **iOS:** Always returns an `Err`. - #[inline] - pub fn set_cursor_position(&self, position: LogicalPosition) -> Result<(), ExternalError> { - self.window.set_cursor_position(position) - } - - /// Grabs the cursor, preventing it from leaving the window. + /// Note that making the window unresizable doesn't exempt you from handling `Resized`, as that event can still be + /// triggered by DPI scaling, entering fullscreen mode, etc. /// /// ## Platform-specific /// - /// - **macOS:** This presently merely locks the cursor in a fixed location, which looks visually - /// awkward. - /// - **Android:** Has no effect. - /// - **iOS:** Always returns an Err. - #[inline] - pub fn set_cursor_grab(&self, grab: bool) -> Result<(), ExternalError> { - self.window.set_cursor_grab(grab) - } - - /// Hides the cursor, making it invisible but still usable. + /// This only has an effect on desktop platforms. + /// + /// Due to a bug in XFCE, this has no effect on Xfwm. /// /// ## Platform-specific /// - /// - **Windows:** The cursor is only hidden within the confines of the window. - /// - **X11:** The cursor is only hidden within the confines of the window. - /// - **macOS:** The cursor is hidden as long as the window has input focus, even if the cursor is - /// outside of the window. /// - **iOS:** Has no effect. - /// - **Android:** Has no effect. #[inline] - pub fn set_cursor_visible(&self, visible: bool) { - self.window.set_cursor_visible(visible) + pub fn set_resizable(&self, resizable: bool) { + self.window.set_resizable(resizable) } /// Sets the window to maximized or back. @@ -636,7 +600,62 @@ impl Window { pub fn set_ime_position(&self, position: LogicalPosition) { self.window.set_ime_position(position) } +} +/// Cursor functions. +impl Window { + /// Modifies the cursor icon of the window. + /// + /// ## Platform-specific + /// + /// - **iOS:** Has no effect. + /// - **Android:** Has no effect. + #[inline] + pub fn set_cursor_icon(&self, cursor: CursorIcon) { + self.window.set_cursor_icon(cursor); + } + + /// Changes the position of the cursor in window coordinates. + /// + /// ## Platform-specific + /// + /// - **iOS:** Always returns an `Err`. + #[inline] + pub fn set_cursor_position(&self, position: LogicalPosition) -> Result<(), ExternalError> { + self.window.set_cursor_position(position) + } + + /// Grabs the cursor, preventing it from leaving the window. + /// + /// ## Platform-specific + /// + /// - **macOS:** This presently merely locks the cursor in a fixed location, which looks visually + /// awkward. + /// - **Android:** Has no effect. + /// - **iOS:** Always returns an Err. + #[inline] + pub fn set_cursor_grab(&self, grab: bool) -> Result<(), ExternalError> { + self.window.set_cursor_grab(grab) + } + + /// Hides the cursor, making it invisible but still usable. + /// + /// ## Platform-specific + /// + /// - **Windows:** The cursor is only hidden within the confines of the window. + /// - **X11:** The cursor is only hidden within the confines of the window. + /// - **macOS:** The cursor is hidden as long as the window has input focus, even if the cursor is + /// outside of the window. + /// - **iOS:** Has no effect. + /// - **Android:** Has no effect. + #[inline] + pub fn set_cursor_visible(&self, visible: bool) { + self.window.set_cursor_visible(visible) + } +} + +/// Monitor info functions. +impl Window { /// Returns the monitor on which the window currently resides /// /// ## Platform-specific @@ -671,12 +690,6 @@ impl Window { pub fn primary_monitor(&self) -> MonitorHandle { MonitorHandle { inner: self.window.primary_monitor() } } - - /// Returns an identifier unique to the window. - #[inline] - pub fn id(&self) -> WindowId { - WindowId(self.window.id()) - } } /// Describes the appearance of the mouse cursor. From 7126ad6f98b80bba5de4e79270610255ef8d2087 Mon Sep 17 00:00:00 2001 From: Osspial Date: Wed, 29 May 2019 18:47:33 -0400 Subject: [PATCH 22/22] Improve clarity of function ordering and docs in EventLoop --- src/event_loop.rs | 41 ++++++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/src/event_loop.rs b/src/event_loop.rs index 68e70afff6..476e7ed5e1 100644 --- a/src/event_loop.rs +++ b/src/event_loop.rs @@ -94,9 +94,9 @@ impl Default for ControlFlow { impl EventLoop<()> { /// Builds a new event loop with a `()` as the user event type. - /// + /// /// ## Platform-specific - /// + /// /// - **iOS:** Can only be called on the main thread. pub fn new() -> EventLoop<()> { EventLoop::<()>::new_user_event() @@ -110,9 +110,9 @@ impl EventLoop { /// using an environment variable `WINIT_UNIX_BACKEND`. Legal values are `x11` and `wayland`. /// If it is not set, winit will try to connect to a wayland connection, and if it fails will /// fallback on x11. If this variable is set with any other value, winit will panic. - /// + /// /// ## Platform-specific - /// + /// /// - **iOS:** Can only be called on the main thread. pub fn new_user_event() -> EventLoop { EventLoop { @@ -121,21 +121,6 @@ impl EventLoop { } } - /// Returns the list of all the monitors available on the system. - /// - // Note: should be replaced with `-> impl Iterator` once stable. - #[inline] - pub fn available_monitors(&self) -> AvailableMonitorsIter { - let data = self.event_loop.available_monitors(); - AvailableMonitorsIter{ data: data.into_iter() } - } - - /// Returns the primary monitor of the system. - #[inline] - pub fn primary_monitor(&self) -> MonitorHandle { - MonitorHandle { inner: self.event_loop.primary_monitor() } - } - /// Hijacks the calling thread and initializes the `winit` event loop with the provided /// closure. Since the closure is `'static`, it must be a `move` closure if it needs to /// access any data from the calling context. @@ -153,13 +138,27 @@ impl EventLoop { self.event_loop.run(event_handler) } - /// Creates an `EventLoopProxy` that can be used to wake up the `EventLoop` from another - /// thread. + /// Creates an `EventLoopProxy` that can be used to dispatch user events to the main event loop. pub fn create_proxy(&self) -> EventLoopProxy { EventLoopProxy { event_loop_proxy: self.event_loop.create_proxy(), } } + + /// Returns the list of all the monitors available on the system. + /// + // Note: should be replaced with `-> impl Iterator` once stable. + #[inline] + pub fn available_monitors(&self) -> AvailableMonitorsIter { + let data = self.event_loop.available_monitors(); + AvailableMonitorsIter{ data: data.into_iter() } + } + + /// Returns the primary monitor of the system. + #[inline] + pub fn primary_monitor(&self) -> MonitorHandle { + MonitorHandle { inner: self.event_loop.primary_monitor() } + } } impl Deref for EventLoop {