diff --git a/examples/fullscreen.rs b/examples/fullscreen.rs index c29013c41..18ae80029 100644 --- a/examples/fullscreen.rs +++ b/examples/fullscreen.rs @@ -82,6 +82,15 @@ fn main() { window.set_fullscreen(Some(window.get_current_monitor())); } } + (winit::VirtualKeyCode::S, winit::ElementState::Pressed) => { + println!("window.get_fullscreen {:?}", window.get_fullscreen()); + + #[cfg(target_os = "macos")] + { + use winit::os::macos::WindowExt; + println!("window.get_simple_fullscreen {:?}", WindowExt::get_simple_fullscreen(&window)); + } + } (winit::VirtualKeyCode::M, winit::ElementState::Pressed) => { is_maximized = !is_maximized; window.set_maximized(is_maximized); diff --git a/src/os/macos.rs b/src/os/macos.rs index b9ea993b3..927b14358 100644 --- a/src/os/macos.rs +++ b/src/os/macos.rs @@ -23,6 +23,9 @@ pub trait WindowExt { /// - `true`: the dock icon will bounce until the application is focused. 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; + /// Toggles a fullscreen mode that doesn't require a new macOS space. /// Returns a boolean indicating whether the transition was successful (this /// won't work if the window was already in the native fullscreen). @@ -49,6 +52,11 @@ impl WindowExt for Window { self.window.request_user_attention(is_critical) } + #[inline] + fn get_simple_fullscreen(&self) -> bool { + self.window.get_simple_fullscreen() + } + #[inline] fn set_simple_fullscreen(&self, fullscreen: bool) -> bool { self.window.set_simple_fullscreen(fullscreen) diff --git a/src/platform/android/mod.rs b/src/platform/android/mod.rs index dad73801b..b69876d1e 100644 --- a/src/platform/android/mod.rs +++ b/src/platform/android/mod.rs @@ -368,6 +368,13 @@ impl Window { // Android has single screen maximized apps so nothing to do } + #[inline] + pub fn get_fullscreen(&self) -> Option { + // N/A + // Android has single screen maximized apps so nothing to do + None + } + #[inline] pub fn set_fullscreen(&self, _monitor: Option) { // N/A diff --git a/src/platform/emscripten/mod.rs b/src/platform/emscripten/mod.rs index 3a5feb61d..550c2b223 100644 --- a/src/platform/emscripten/mod.rs +++ b/src/platform/emscripten/mod.rs @@ -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 diff --git a/src/platform/ios/mod.rs b/src/platform/ios/mod.rs index 6830ace4a..8bc679152 100644 --- a/src/platform/ios/mod.rs +++ b/src/platform/ios/mod.rs @@ -473,6 +473,13 @@ impl Window { // iOS has single screen maximized apps so nothing to do } + #[inline] + pub fn get_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 diff --git a/src/platform/linux/mod.rs b/src/platform/linux/mod.rs index 1f88cdfed..d74188ad0 100644 --- a/src/platform/linux/mod.rs +++ b/src/platform/linux/mod.rs @@ -301,6 +301,15 @@ impl Window { } } + #[inline] + pub fn get_fullscreen(&self) -> Option { + 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) { match self { diff --git a/src/platform/linux/wayland/window.rs b/src/platform/linux/wayland/window.rs index 45ae3bd41..417572270 100644 --- a/src/platform/linux/wayland/window.rs +++ b/src/platform/linux/wayland/window.rs @@ -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>, Arc>), display: Arc, need_frame_refresh: Arc>, + fullscreen: Arc>, } 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 { + if *(self.fullscreen.lock().unwrap()) { + Some(self.get_current_monitor()) + } else { + None + } + } + pub fn set_fullscreen(&self, monitor: Option) { if let Some(RootMonitorId { inner: PlatformMonitorId::Wayland(ref monitor_id), @@ -302,6 +317,7 @@ struct InternalWindow { surface: Proxy, newsize: Option<(u32, u32)>, size: Arc>, + fullscreen: Arc>, need_refresh: bool, need_frame_refresh: Arc>, closed: bool, diff --git a/src/platform/linux/x11/window.rs b/src/platform/linux/x11/window.rs index 8a5f711ea..6d69b61cd 100644 --- a/src/platform/linux/x11/window.rs +++ b/src/platform/linux/x11/window.rs @@ -37,6 +37,7 @@ pub struct SharedState { pub guessed_dpi: Option, pub last_monitor: Option, pub dpi_adjusted: Option<(f64, f64)>, + pub fullscreen: Option, // Used to restore position after exiting fullscreen. pub restore_position: Option<(i32, i32)>, pub frame_extents: Option, @@ -533,8 +534,14 @@ impl UnownedWindow { } } + #[inline] + pub fn get_fullscreen(&self) -> Option { + self.shared_state.lock().fullscreen.clone() + } + #[inline] pub fn set_fullscreen(&self, monitor: Option) { + self.shared_state.lock().fullscreen = monitor.clone(); self.set_fullscreen_inner(monitor) .flush() .expect("Failed to change window fullscreen state"); diff --git a/src/platform/macos/window.rs b/src/platform/macos/window.rs index 4fc27328a..1f82a9360 100644 --- a/src/platform/macos/window.rs +++ b/src/platform/macos/window.rs @@ -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 { + 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 diff --git a/src/platform/windows/window.rs b/src/platform/windows/window.rs index 0d664d4d5..fc7256900 100644 --- a/src/platform/windows/window.rs +++ b/src/platform/windows/window.rs @@ -355,6 +355,12 @@ impl Window { }); } + #[inline] + pub fn get_fullscreen(&self) -> Option { + let window_state = self.window_state.lock().unwrap(); + window_state.fullscreen.clone() + } + #[inline] pub fn set_fullscreen(&self, monitor: Option) { unsafe { diff --git a/src/window.rs b/src/window.rs index 1bc0dbf61..50471ec2e 100644 --- a/src/window.rs +++ b/src/window.rs @@ -369,6 +369,12 @@ impl Window { self.window.set_fullscreen(monitor) } + /// Gets the window's current fullscreen state. + #[inline] + pub fn get_fullscreen(&self) -> Option { + self.window.get_fullscreen() + } + /// Turn window decorations on or off. #[inline] pub fn set_decorations(&self, decorations: bool) {