diff --git a/CHANGELOG.md b/CHANGELOG.md index fd8a6066..734814eb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # Unreleased +- Implement `Window::set_fullscreen`, `Window::set_maximized` and `Window::set_decorations` for Wayland. + # Version 0.10.0 (2017-12-27) - Add support for `Touch` for emscripten backend. diff --git a/src/platform/linux/mod.rs b/src/platform/linux/mod.rs index d8e466a6..a84f1364 100644 --- a/src/platform/linux/mod.rs +++ b/src/platform/linux/mod.rs @@ -248,9 +248,7 @@ impl Window { pub fn set_maximized(&self, maximized: bool) { match self { &Window::X(ref w) => w.set_maximized(maximized), - &Window::Wayland(ref _w) => { - unimplemented!(); - } + &Window::Wayland(ref w) => w.set_maximized(maximized), } } @@ -258,9 +256,7 @@ impl Window { pub fn set_fullscreen(&self, monitor: Option) { match self { &Window::X(ref w) => w.set_fullscreen(monitor), - &Window::Wayland(ref _w) => { - unimplemented!(); - } + &Window::Wayland(ref w) => w.set_fullscreen(monitor) } } @@ -268,9 +264,7 @@ impl Window { pub fn set_decorations(&self, decorations: bool) { match self { &Window::X(ref w) => w.set_decorations(decorations), - &Window::Wayland(ref _w) => { - unimplemented!(); - } + &Window::Wayland(ref w) => w.set_decorations(decorations) } } diff --git a/src/platform/linux/wayland/window.rs b/src/platform/linux/wayland/window.rs index a5c2057a..fce940e0 100644 --- a/src/platform/linux/wayland/window.rs +++ b/src/platform/linux/wayland/window.rs @@ -18,6 +18,7 @@ pub struct Window { size: Arc>, kill_switch: (Arc>, Arc>), display: Arc, + need_frame_refresh: Arc> } impl Window { @@ -59,6 +60,7 @@ impl Window { } let kill_switch = Arc::new(Mutex::new(false)); + let need_frame_refresh = Arc::new(Mutex::new(true)); let frame = Arc::new(Mutex::new(frame)); { @@ -67,7 +69,7 @@ impl Window { closed: false, newsize: None, need_refresh: false, - need_frame_refresh: true, + need_frame_refresh: need_frame_refresh.clone(), surface: surface.clone().unwrap(), kill_switch: kill_switch.clone(), frame: Arc::downgrade(&frame) @@ -81,7 +83,8 @@ impl Window { frame: frame, monitors: monitor_list, size: size, - kill_switch: (kill_switch, evlp.cleanup_needed.clone()) + kill_switch: (kill_switch, evlp.cleanup_needed.clone()), + need_frame_refresh: need_frame_refresh }) } @@ -160,6 +163,28 @@ impl Window { factor } + pub fn set_decorations(&self, decorate: bool) { + self.frame.lock().unwrap().set_decorate(decorate); + *(self.need_frame_refresh.lock().unwrap()) = true; + } + + pub fn set_maximized(&self, maximized: bool) { + if maximized { + self.frame.lock().unwrap().set_state(FrameState::Maximized); + } else { + self.frame.lock().unwrap().set_state(FrameState::Regular); + } + } + + pub fn set_fullscreen(&self, monitor: Option) { + if let Some(RootMonitorId { inner: PlatformMonitorId::Wayland(ref monitor_id) }) = monitor { + let info = monitor_id.info.lock().unwrap(); + self.frame.lock().unwrap().set_state(FrameState::Fullscreen(Some(&info.output))); + } else { + self.frame.lock().unwrap().set_state(FrameState::Regular); + } + } + #[inline] pub fn set_cursor_position(&self, _x: i32, _y: i32) -> Result<(), ()> { // TODO: not yet possible on wayland @@ -197,7 +222,7 @@ struct InternalWindow { surface: wl_surface::WlSurface, newsize: Option<(i32, i32)>, need_refresh: bool, - need_frame_refresh: bool, + need_frame_refresh: Arc>, closed: bool, kill_switch: Arc>, frame: Weak> @@ -242,7 +267,7 @@ impl WindowStore { f( window.newsize.take(), window.need_refresh, - window.need_frame_refresh, + ::std::mem::replace(&mut *window.need_frame_refresh.lock().unwrap(), false), window.closed, make_wid(&window.surface), opt_mutex_lock.as_mut().map(|m| &mut **m) @@ -271,7 +296,7 @@ fn decorated_impl() -> FrameImplementation { if window.surface.equals(&idata.surface) { window.newsize = newsize; window.need_refresh = true; - window.need_frame_refresh = true; + *(window.need_frame_refresh.lock().unwrap()) = true; return; } } @@ -289,7 +314,7 @@ fn decorated_impl() -> FrameImplementation { let store = evqh.state().get_mut(&idata.store_token); for window in &mut store.windows { if window.surface.equals(&idata.surface) { - window.need_frame_refresh = true; + *(window.need_frame_refresh.lock().unwrap()) = true; return; } }