Skip to content

Commit

Permalink
Implement set_maximized, set_fullscreen and set_decorations for wayla…
Browse files Browse the repository at this point in the history
…nd (#383)

* wayland: implement Window::set_decorations()

* wayland: implement Window::set_maximized()

* wayland: implement Window::set_fullscreen()

* Update changelog.
  • Loading branch information
vberger authored and tomaka committed Jan 13, 2018
1 parent dddd9de commit 0ea4f93
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 15 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
12 changes: 3 additions & 9 deletions src/platform/linux/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,29 +248,23 @@ 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),
}
}

#[inline]
pub fn set_fullscreen(&self, monitor: Option<RootMonitorId>) {
match self {
&Window::X(ref w) => w.set_fullscreen(monitor),
&Window::Wayland(ref _w) => {
unimplemented!();
}
&Window::Wayland(ref w) => w.set_fullscreen(monitor)
}
}

#[inline]
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)
}
}

Expand Down
37 changes: 31 additions & 6 deletions src/platform/linux/wayland/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ pub struct Window {
size: Arc<Mutex<(u32, u32)>>,
kill_switch: (Arc<Mutex<bool>>, Arc<Mutex<bool>>),
display: Arc<wl_display::WlDisplay>,
need_frame_refresh: Arc<Mutex<bool>>
}

impl Window {
Expand Down Expand Up @@ -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));

{
Expand All @@ -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)
Expand All @@ -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
})
}

Expand Down Expand Up @@ -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<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]
pub fn set_cursor_position(&self, _x: i32, _y: i32) -> Result<(), ()> {
// TODO: not yet possible on wayland
Expand Down Expand Up @@ -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<Mutex<bool>>,
closed: bool,
kill_switch: Arc<Mutex<bool>>,
frame: Weak<Mutex<Frame>>
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -271,7 +296,7 @@ fn decorated_impl() -> FrameImplementation<FrameIData> {
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;
}
}
Expand All @@ -289,7 +314,7 @@ fn decorated_impl() -> FrameImplementation<FrameIData> {
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;
}
}
Expand Down

0 comments on commit 0ea4f93

Please sign in to comment.