Implement set_maximized, set_fullscreen and set_decorations for wayland (#383)

* wayland: implement Window::set_decorations()

* wayland: implement Window::set_maximized()

* wayland: implement Window::set_fullscreen()

* Update changelog.
This commit is contained in:
Victor Berger 2018-01-13 06:38:12 +01:00 committed by Pierre Krieger
parent dddd9de151
commit 0ea4f93f05
3 changed files with 36 additions and 15 deletions

View file

@ -1,5 +1,7 @@
# Unreleased # Unreleased
- Implement `Window::set_fullscreen`, `Window::set_maximized` and `Window::set_decorations` for Wayland.
# Version 0.10.0 (2017-12-27) # Version 0.10.0 (2017-12-27)
- Add support for `Touch` for emscripten backend. - Add support for `Touch` for emscripten backend.

View file

@ -248,9 +248,7 @@ impl Window {
pub fn set_maximized(&self, maximized: bool) { pub fn set_maximized(&self, maximized: bool) {
match self { match self {
&Window::X(ref w) => w.set_maximized(maximized), &Window::X(ref w) => w.set_maximized(maximized),
&Window::Wayland(ref _w) => { &Window::Wayland(ref w) => w.set_maximized(maximized),
unimplemented!();
}
} }
} }
@ -258,9 +256,7 @@ impl Window {
pub fn set_fullscreen(&self, monitor: Option<RootMonitorId>) { pub fn set_fullscreen(&self, monitor: Option<RootMonitorId>) {
match self { match self {
&Window::X(ref w) => w.set_fullscreen(monitor), &Window::X(ref w) => w.set_fullscreen(monitor),
&Window::Wayland(ref _w) => { &Window::Wayland(ref w) => w.set_fullscreen(monitor)
unimplemented!();
}
} }
} }
@ -268,9 +264,7 @@ impl Window {
pub fn set_decorations(&self, decorations: bool) { pub fn set_decorations(&self, decorations: bool) {
match self { match self {
&Window::X(ref w) => w.set_decorations(decorations), &Window::X(ref w) => w.set_decorations(decorations),
&Window::Wayland(ref _w) => { &Window::Wayland(ref w) => w.set_decorations(decorations)
unimplemented!();
}
} }
} }

View file

@ -18,6 +18,7 @@ pub struct Window {
size: Arc<Mutex<(u32, u32)>>, size: Arc<Mutex<(u32, u32)>>,
kill_switch: (Arc<Mutex<bool>>, Arc<Mutex<bool>>), kill_switch: (Arc<Mutex<bool>>, Arc<Mutex<bool>>),
display: Arc<wl_display::WlDisplay>, display: Arc<wl_display::WlDisplay>,
need_frame_refresh: Arc<Mutex<bool>>
} }
impl Window { impl Window {
@ -59,6 +60,7 @@ impl Window {
} }
let kill_switch = Arc::new(Mutex::new(false)); let kill_switch = Arc::new(Mutex::new(false));
let need_frame_refresh = Arc::new(Mutex::new(true));
let frame = Arc::new(Mutex::new(frame)); let frame = Arc::new(Mutex::new(frame));
{ {
@ -67,7 +69,7 @@ impl Window {
closed: false, closed: false,
newsize: None, newsize: None,
need_refresh: false, need_refresh: false,
need_frame_refresh: true, need_frame_refresh: need_frame_refresh.clone(),
surface: surface.clone().unwrap(), surface: surface.clone().unwrap(),
kill_switch: kill_switch.clone(), kill_switch: kill_switch.clone(),
frame: Arc::downgrade(&frame) frame: Arc::downgrade(&frame)
@ -81,7 +83,8 @@ impl Window {
frame: frame, frame: frame,
monitors: monitor_list, monitors: monitor_list,
size: size, 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 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<RootMonitorId>) {
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] #[inline]
pub fn set_cursor_position(&self, _x: i32, _y: i32) -> Result<(), ()> { pub fn set_cursor_position(&self, _x: i32, _y: i32) -> Result<(), ()> {
// TODO: not yet possible on wayland // TODO: not yet possible on wayland
@ -197,7 +222,7 @@ struct InternalWindow {
surface: wl_surface::WlSurface, surface: wl_surface::WlSurface,
newsize: Option<(i32, i32)>, newsize: Option<(i32, i32)>,
need_refresh: bool, need_refresh: bool,
need_frame_refresh: bool, need_frame_refresh: Arc<Mutex<bool>>,
closed: bool, closed: bool,
kill_switch: Arc<Mutex<bool>>, kill_switch: Arc<Mutex<bool>>,
frame: Weak<Mutex<Frame>> frame: Weak<Mutex<Frame>>
@ -242,7 +267,7 @@ impl WindowStore {
f( f(
window.newsize.take(), window.newsize.take(),
window.need_refresh, window.need_refresh,
window.need_frame_refresh, ::std::mem::replace(&mut *window.need_frame_refresh.lock().unwrap(), false),
window.closed, window.closed,
make_wid(&window.surface), make_wid(&window.surface),
opt_mutex_lock.as_mut().map(|m| &mut **m) opt_mutex_lock.as_mut().map(|m| &mut **m)
@ -271,7 +296,7 @@ fn decorated_impl() -> FrameImplementation<FrameIData> {
if window.surface.equals(&idata.surface) { if window.surface.equals(&idata.surface) {
window.newsize = newsize; window.newsize = newsize;
window.need_refresh = true; window.need_refresh = true;
window.need_frame_refresh = true; *(window.need_frame_refresh.lock().unwrap()) = true;
return; return;
} }
} }
@ -289,7 +314,7 @@ fn decorated_impl() -> FrameImplementation<FrameIData> {
let store = evqh.state().get_mut(&idata.store_token); let store = evqh.state().get_mut(&idata.store_token);
for window in &mut store.windows { for window in &mut store.windows {
if window.surface.equals(&idata.surface) { if window.surface.equals(&idata.surface) {
window.need_frame_refresh = true; *(window.need_frame_refresh.lock().unwrap()) = true;
return; return;
} }
} }