Feat/fullscreen getters (#838)

* feat: [macos] add get_fullscreen and get_simple_fullscreen

* feat: [windows] add get_fullscreen

* feat: [ios] add get_fullscreen

* feat: [android] add get_fullscreen

* feat: [emscripten] add get_fullscreen

* feat: [linux] add get_fullscreen

* feedback: `get_fullscreen() -> bool` -> `get_fullscreen() -> Option<Id>`
This commit is contained in:
acheronfail
2019-04-26 03:09:32 +10:00
committed by Osspial
parent 4e5321b0aa
commit 4469f29e70
11 changed files with 95 additions and 2 deletions

View File

@@ -368,6 +368,13 @@ impl Window {
// Android has single screen maximized apps so nothing to do
}
#[inline]
pub fn get_fullscreen(&self) -> Option<RootMonitorId> {
// N/A
// Android has single screen maximized apps so nothing to do
None
}
#[inline]
pub fn set_fullscreen(&self, _monitor: Option<RootMonitorId>) {
// N/A

View File

@@ -580,6 +580,11 @@ impl Window {
// iOS has single screen maximized apps so nothing to do
}
#[inline]
pub fn get_fullscreen(&self) -> Option<::MonitorId> {
None
}
#[inline]
pub fn set_fullscreen(&self, _monitor: Option<::MonitorId>) {
// iOS has single screen maximized apps so nothing to do

View File

@@ -473,6 +473,13 @@ impl Window {
// iOS has single screen maximized apps so nothing to do
}
#[inline]
pub fn get_fullscreen(&self) -> Option<RootMonitorId> {
// N/A
// iOS has single screen maximized apps so nothing to do
None
}
#[inline]
pub fn set_fullscreen(&self, _monitor: Option<RootMonitorId>) {
// N/A

View File

@@ -301,6 +301,15 @@ impl Window {
}
}
#[inline]
pub fn get_fullscreen(&self) -> Option<RootMonitorId> {
match self {
&Window::X(ref w) => w.get_fullscreen(),
&Window::Wayland(ref w) => w.get_fullscreen()
.map(|monitor_id| RootMonitorId { inner: MonitorId::Wayland(monitor_id) })
}
}
#[inline]
pub fn set_fullscreen(&self, monitor: Option<RootMonitorId>) {
match self {

View File

@@ -7,7 +7,7 @@ use platform::{MonitorId as PlatformMonitorId, PlatformSpecificWindowBuilderAttr
use window::MonitorId as RootMonitorId;
use sctk::surface::{get_dpi_factor, get_outputs};
use sctk::window::{ConceptFrame, Event as WEvent, Window as SWindow, Theme};
use sctk::window::{ConceptFrame, Event as WEvent, State as WState, Window as SWindow, Theme};
use sctk::reexports::client::{Display, Proxy};
use sctk::reexports::client::protocol::{wl_seat, wl_surface};
use sctk::reexports::client::protocol::wl_surface::RequestsTrait as SurfaceRequests;
@@ -24,6 +24,7 @@ pub struct Window {
kill_switch: (Arc<Mutex<bool>>, Arc<Mutex<bool>>),
display: Arc<Display>,
need_frame_refresh: Arc<Mutex<bool>>,
fullscreen: Arc<Mutex<bool>>,
}
impl Window {
@@ -31,6 +32,7 @@ impl Window {
let (width, height) = attributes.dimensions.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));
let window_store = evlp.store.clone();
let surface = evlp.env.create_surface(move |dpi, surface| {
@@ -45,12 +47,15 @@ impl Window {
surface.clone(),
(width, height),
move |event| match event {
WEvent::Configure { new_size, .. } => {
WEvent::Configure { new_size, states } => {
let mut store = window_store.lock().unwrap();
let is_fullscreen = states.contains(&WState::Fullscreen);
for window in &mut store.windows {
if window.surface.equals(&my_surface) {
window.newsize = new_size;
window.need_refresh = true;
*(window.fullscreen.lock().unwrap()) = is_fullscreen;
*(window.need_frame_refresh.lock().unwrap()) = true;
return;
}
@@ -114,6 +119,7 @@ impl Window {
closed: false,
newsize: None,
size: size.clone(),
fullscreen: fullscreen.clone(),
need_refresh: false,
need_frame_refresh: need_frame_refresh.clone(),
surface: surface.clone(),
@@ -132,6 +138,7 @@ impl Window {
size: size,
kill_switch: (kill_switch, evlp.cleanup_needed.clone()),
need_frame_refresh: need_frame_refresh,
fullscreen: fullscreen,
})
}
@@ -223,6 +230,14 @@ impl Window {
}
}
pub fn get_fullscreen(&self) -> Option<MonitorId> {
if *(self.fullscreen.lock().unwrap()) {
Some(self.get_current_monitor())
} else {
None
}
}
pub fn set_fullscreen(&self, monitor: Option<RootMonitorId>) {
if let Some(RootMonitorId {
inner: PlatformMonitorId::Wayland(ref monitor_id),
@@ -302,6 +317,7 @@ struct InternalWindow {
surface: Proxy<wl_surface::WlSurface>,
newsize: Option<(u32, u32)>,
size: Arc<Mutex<(u32, u32)>>,
fullscreen: Arc<Mutex<bool>>,
need_refresh: bool,
need_frame_refresh: Arc<Mutex<bool>>,
closed: bool,

View File

@@ -37,6 +37,7 @@ pub struct SharedState {
pub guessed_dpi: Option<f64>,
pub last_monitor: Option<X11MonitorId>,
pub dpi_adjusted: Option<(f64, f64)>,
pub fullscreen: Option<RootMonitorId>,
// Used to restore position after exiting fullscreen.
pub restore_position: Option<(i32, i32)>,
pub frame_extents: Option<util::FrameExtentsHeuristic>,
@@ -533,8 +534,14 @@ impl UnownedWindow {
}
}
#[inline]
pub fn get_fullscreen(&self) -> Option<RootMonitorId> {
self.shared_state.lock().fullscreen.clone()
}
#[inline]
pub fn set_fullscreen(&self, monitor: Option<RootMonitorId>) {
self.shared_state.lock().fullscreen = monitor.clone();
self.set_fullscreen_inner(monitor)
.flush()
.expect("Failed to change window fullscreen state");

View File

@@ -618,6 +618,11 @@ impl WindowExt for Window2 {
}
}
#[inline]
fn get_simple_fullscreen(&self) -> bool {
self.delegate.state.is_simple_fullscreen.get()
}
#[inline]
fn set_simple_fullscreen(&self, fullscreen: bool) -> bool {
let state = &self.delegate.state;
@@ -1137,6 +1142,14 @@ impl Window2 {
self.delegate.state.perform_maximized(maximized)
}
#[inline]
pub fn get_fullscreen(&self) -> Option<RootMonitorId> {
let state = &self.delegate.state;
let win_attribs = state.win_attribs.borrow();
win_attribs.fullscreen.clone()
}
#[inline]
/// TODO: Right now set_fullscreen do not work on switching monitors
/// in fullscreen mode

View File

@@ -355,6 +355,12 @@ impl Window {
});
}
#[inline]
pub fn get_fullscreen(&self) -> Option<RootMonitorId> {
let window_state = self.window_state.lock().unwrap();
window_state.fullscreen.clone()
}
#[inline]
pub fn set_fullscreen(&self, monitor: Option<RootMonitorId>) {
unsafe {