mirror of
https://github.com/italicsjenga/winit-sonoma-fix.git
synced 2025-01-11 05:21:31 +11:00
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:
parent
fa99b9ff5a
commit
062e0e52ee
|
@ -86,6 +86,15 @@ fn main() {
|
|||
window.set_fullscreen(Some(window.get_current_monitor()));
|
||||
}
|
||||
}
|
||||
(VirtualKeyCode::S, 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));
|
||||
}
|
||||
}
|
||||
(VirtualKeyCode::M, ElementState::Pressed) => {
|
||||
is_maximized = !is_maximized;
|
||||
window.set_maximized(is_maximized);
|
||||
|
|
|
@ -23,6 +23,9 @@ pub trait WindowExtMacOS {
|
|||
/// - `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 WindowExtMacOS 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)
|
||||
|
|
|
@ -368,6 +368,13 @@ impl Window {
|
|||
// Android has single screen maximized apps so nothing to do
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn get_fullscreen(&self) -> Option<RootMonitorHandle> {
|
||||
// N/A
|
||||
// Android has single screen maximized apps so nothing to do
|
||||
None
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn set_fullscreen(&self, _monitor: Option<RootMonitorHandle>) {
|
||||
// N/A
|
||||
|
|
|
@ -580,6 +580,11 @@ impl Window {
|
|||
// iOS has single screen maximized apps so nothing to do
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn get_fullscreen(&self) -> Option<::MonitorHandle> {
|
||||
None
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn set_fullscreen(&self, _monitor: Option<::MonitorHandle>) {
|
||||
// iOS has single screen maximized apps so nothing to do
|
||||
|
|
|
@ -473,6 +473,13 @@ impl Window {
|
|||
// iOS has single screen maximized apps so nothing to do
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn get_fullscreen(&self) -> Option<RootMonitorHandle> {
|
||||
// N/A
|
||||
// iOS has single screen maximized apps so nothing to do
|
||||
None
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn set_fullscreen(&self, _monitor: Option<RootMonitorHandle>) {
|
||||
// N/A
|
||||
|
|
|
@ -297,6 +297,15 @@ impl Window {
|
|||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn get_fullscreen(&self) -> Option<RootMonitorHandle> {
|
||||
match self {
|
||||
&Window::X(ref w) => w.get_fullscreen(),
|
||||
&Window::Wayland(ref w) => w.get_fullscreen()
|
||||
.map(|monitor_id| RootMonitorHandle { inner: MonitorHandle::Wayland(monitor_id) })
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn set_fullscreen(&self, monitor: Option<RootMonitorHandle>) {
|
||||
match self {
|
||||
|
|
|
@ -7,7 +7,7 @@ use monitor::MonitorHandle as RootMonitorHandle;
|
|||
use window::{CreationError, WindowAttributes, MouseCursor};
|
||||
|
||||
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;
|
||||
use sctk::reexports::client::protocol::{wl_seat, wl_surface};
|
||||
use sctk::output::OutputMgr;
|
||||
|
@ -23,7 +23,8 @@ pub struct Window {
|
|||
kill_switch: (Arc<Mutex<bool>>, Arc<Mutex<bool>>),
|
||||
display: Arc<Display>,
|
||||
need_frame_refresh: Arc<Mutex<bool>>,
|
||||
need_refresh: Arc<Mutex<bool>>
|
||||
need_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.as_ref().equals(&my_surface.as_ref()) {
|
||||
window.newsize = new_size;
|
||||
*(window.need_refresh.lock().unwrap()) = true;
|
||||
*(window.fullscreen.lock().unwrap()) = is_fullscreen;
|
||||
*(window.need_frame_refresh.lock().unwrap()) = true;
|
||||
return;
|
||||
}
|
||||
|
@ -117,6 +122,7 @@ impl Window {
|
|||
newsize: None,
|
||||
size: size.clone(),
|
||||
need_refresh: need_refresh.clone(),
|
||||
fullscreen: fullscreen.clone(),
|
||||
need_frame_refresh: need_frame_refresh.clone(),
|
||||
surface: surface.clone(),
|
||||
kill_switch: kill_switch.clone(),
|
||||
|
@ -135,6 +141,7 @@ impl Window {
|
|||
kill_switch: (kill_switch, evlp.cleanup_needed.clone()),
|
||||
need_frame_refresh,
|
||||
need_refresh,
|
||||
fullscreen,
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -230,6 +237,14 @@ impl Window {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn get_fullscreen(&self) -> Option<MonitorHandle> {
|
||||
if *(self.fullscreen.lock().unwrap()) {
|
||||
Some(self.get_current_monitor())
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_fullscreen(&self, monitor: Option<RootMonitorHandle>) {
|
||||
if let Some(RootMonitorHandle {
|
||||
inner: PlatformMonitorHandle::Wayland(ref monitor_id),
|
||||
|
@ -310,6 +325,7 @@ struct InternalWindow {
|
|||
newsize: Option<(u32, u32)>,
|
||||
size: Arc<Mutex<(u32, u32)>>,
|
||||
need_refresh: Arc<Mutex<bool>>,
|
||||
fullscreen: Arc<Mutex<bool>>,
|
||||
need_frame_refresh: Arc<Mutex<bool>>,
|
||||
closed: bool,
|
||||
kill_switch: Arc<Mutex<bool>>,
|
||||
|
|
|
@ -38,6 +38,7 @@ pub struct SharedState {
|
|||
pub guessed_dpi: Option<f64>,
|
||||
pub last_monitor: Option<X11MonitorHandle>,
|
||||
pub dpi_adjusted: Option<(f64, f64)>,
|
||||
pub fullscreen: Option<RootMonitorHandle>,
|
||||
// Used to restore position after exiting fullscreen.
|
||||
pub restore_position: Option<(i32, i32)>,
|
||||
pub frame_extents: Option<util::FrameExtentsHeuristic>,
|
||||
|
@ -536,8 +537,14 @@ impl UnownedWindow {
|
|||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn get_fullscreen(&self) -> Option<RootMonitorHandle> {
|
||||
self.shared_state.lock().fullscreen.clone()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn set_fullscreen(&self, monitor: Option<RootMonitorHandle>) {
|
||||
self.shared_state.lock().fullscreen = monitor.clone();
|
||||
self.set_fullscreen_inner(monitor)
|
||||
.flush()
|
||||
.expect("Failed to change window fullscreen state");
|
||||
|
|
|
@ -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<RootMonitorHandle> {
|
||||
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
|
||||
|
|
|
@ -399,6 +399,12 @@ impl Window {
|
|||
});
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn get_fullscreen(&self) -> Option<RootMonitorHandle> {
|
||||
let window_state = self.window_state.lock();
|
||||
window_state.fullscreen.clone()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn set_fullscreen(&self, monitor: Option<RootMonitorHandle>) {
|
||||
unsafe {
|
||||
|
|
|
@ -536,6 +536,12 @@ impl Window {
|
|||
self.window.set_fullscreen(monitor)
|
||||
}
|
||||
|
||||
/// Gets the window's current fullscreen state.
|
||||
#[inline]
|
||||
pub fn get_fullscreen(&self) -> Option<MonitorHandle> {
|
||||
self.window.get_fullscreen()
|
||||
}
|
||||
|
||||
/// Turn window decorations on or off.
|
||||
#[inline]
|
||||
pub fn set_decorations(&self, decorations: bool) {
|
||||
|
|
Loading…
Reference in a new issue