mirror of
https://github.com/rust-windowing/winit.git
synced 2026-08-31 05:40:04 -04: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:
@@ -82,6 +82,15 @@ fn main() {
|
|||||||
window.set_fullscreen(Some(window.get_current_monitor()));
|
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) => {
|
(winit::VirtualKeyCode::M, winit::ElementState::Pressed) => {
|
||||||
is_maximized = !is_maximized;
|
is_maximized = !is_maximized;
|
||||||
window.set_maximized(is_maximized);
|
window.set_maximized(is_maximized);
|
||||||
|
|||||||
@@ -23,6 +23,9 @@ pub trait WindowExt {
|
|||||||
/// - `true`: the dock icon will bounce until the application is focused.
|
/// - `true`: the dock icon will bounce until the application is focused.
|
||||||
fn request_user_attention(&self, is_critical: bool);
|
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.
|
/// Toggles a fullscreen mode that doesn't require a new macOS space.
|
||||||
/// Returns a boolean indicating whether the transition was successful (this
|
/// Returns a boolean indicating whether the transition was successful (this
|
||||||
/// won't work if the window was already in the native fullscreen).
|
/// 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)
|
self.window.request_user_attention(is_critical)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn get_simple_fullscreen(&self) -> bool {
|
||||||
|
self.window.get_simple_fullscreen()
|
||||||
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn set_simple_fullscreen(&self, fullscreen: bool) -> bool {
|
fn set_simple_fullscreen(&self, fullscreen: bool) -> bool {
|
||||||
self.window.set_simple_fullscreen(fullscreen)
|
self.window.set_simple_fullscreen(fullscreen)
|
||||||
|
|||||||
@@ -368,6 +368,13 @@ impl Window {
|
|||||||
// Android has single screen maximized apps so nothing to do
|
// 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]
|
#[inline]
|
||||||
pub fn set_fullscreen(&self, _monitor: Option<RootMonitorId>) {
|
pub fn set_fullscreen(&self, _monitor: Option<RootMonitorId>) {
|
||||||
// N/A
|
// N/A
|
||||||
|
|||||||
@@ -580,6 +580,11 @@ impl Window {
|
|||||||
// iOS has single screen maximized apps so nothing to do
|
// iOS has single screen maximized apps so nothing to do
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn get_fullscreen(&self) -> Option<::MonitorId> {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn set_fullscreen(&self, _monitor: Option<::MonitorId>) {
|
pub fn set_fullscreen(&self, _monitor: Option<::MonitorId>) {
|
||||||
// iOS has single screen maximized apps so nothing to do
|
// 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
|
// 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]
|
#[inline]
|
||||||
pub fn set_fullscreen(&self, _monitor: Option<RootMonitorId>) {
|
pub fn set_fullscreen(&self, _monitor: Option<RootMonitorId>) {
|
||||||
// N/A
|
// N/A
|
||||||
|
|||||||
@@ -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]
|
#[inline]
|
||||||
pub fn set_fullscreen(&self, monitor: Option<RootMonitorId>) {
|
pub fn set_fullscreen(&self, monitor: Option<RootMonitorId>) {
|
||||||
match self {
|
match self {
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ use platform::{MonitorId as PlatformMonitorId, PlatformSpecificWindowBuilderAttr
|
|||||||
use window::MonitorId as RootMonitorId;
|
use window::MonitorId as RootMonitorId;
|
||||||
|
|
||||||
use sctk::surface::{get_dpi_factor, get_outputs};
|
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::{Display, Proxy};
|
||||||
use sctk::reexports::client::protocol::{wl_seat, wl_surface};
|
use sctk::reexports::client::protocol::{wl_seat, wl_surface};
|
||||||
use sctk::reexports::client::protocol::wl_surface::RequestsTrait as SurfaceRequests;
|
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>>),
|
kill_switch: (Arc<Mutex<bool>>, Arc<Mutex<bool>>),
|
||||||
display: Arc<Display>,
|
display: Arc<Display>,
|
||||||
need_frame_refresh: Arc<Mutex<bool>>,
|
need_frame_refresh: Arc<Mutex<bool>>,
|
||||||
|
fullscreen: Arc<Mutex<bool>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Window {
|
impl Window {
|
||||||
@@ -31,6 +32,7 @@ impl Window {
|
|||||||
let (width, height) = attributes.dimensions.map(Into::into).unwrap_or((800, 600));
|
let (width, height) = attributes.dimensions.map(Into::into).unwrap_or((800, 600));
|
||||||
// Create the window
|
// Create the window
|
||||||
let size = Arc::new(Mutex::new((width, height)));
|
let size = Arc::new(Mutex::new((width, height)));
|
||||||
|
let fullscreen = Arc::new(Mutex::new(false));
|
||||||
|
|
||||||
let window_store = evlp.store.clone();
|
let window_store = evlp.store.clone();
|
||||||
let surface = evlp.env.create_surface(move |dpi, surface| {
|
let surface = evlp.env.create_surface(move |dpi, surface| {
|
||||||
@@ -45,12 +47,15 @@ impl Window {
|
|||||||
surface.clone(),
|
surface.clone(),
|
||||||
(width, height),
|
(width, height),
|
||||||
move |event| match event {
|
move |event| match event {
|
||||||
WEvent::Configure { new_size, .. } => {
|
WEvent::Configure { new_size, states } => {
|
||||||
let mut store = window_store.lock().unwrap();
|
let mut store = window_store.lock().unwrap();
|
||||||
|
let is_fullscreen = states.contains(&WState::Fullscreen);
|
||||||
|
|
||||||
for window in &mut store.windows {
|
for window in &mut store.windows {
|
||||||
if window.surface.equals(&my_surface) {
|
if window.surface.equals(&my_surface) {
|
||||||
window.newsize = new_size;
|
window.newsize = new_size;
|
||||||
window.need_refresh = true;
|
window.need_refresh = true;
|
||||||
|
*(window.fullscreen.lock().unwrap()) = is_fullscreen;
|
||||||
*(window.need_frame_refresh.lock().unwrap()) = true;
|
*(window.need_frame_refresh.lock().unwrap()) = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -114,6 +119,7 @@ impl Window {
|
|||||||
closed: false,
|
closed: false,
|
||||||
newsize: None,
|
newsize: None,
|
||||||
size: size.clone(),
|
size: size.clone(),
|
||||||
|
fullscreen: fullscreen.clone(),
|
||||||
need_refresh: false,
|
need_refresh: false,
|
||||||
need_frame_refresh: need_frame_refresh.clone(),
|
need_frame_refresh: need_frame_refresh.clone(),
|
||||||
surface: surface.clone(),
|
surface: surface.clone(),
|
||||||
@@ -132,6 +138,7 @@ impl Window {
|
|||||||
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,
|
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>) {
|
pub fn set_fullscreen(&self, monitor: Option<RootMonitorId>) {
|
||||||
if let Some(RootMonitorId {
|
if let Some(RootMonitorId {
|
||||||
inner: PlatformMonitorId::Wayland(ref monitor_id),
|
inner: PlatformMonitorId::Wayland(ref monitor_id),
|
||||||
@@ -302,6 +317,7 @@ struct InternalWindow {
|
|||||||
surface: Proxy<wl_surface::WlSurface>,
|
surface: Proxy<wl_surface::WlSurface>,
|
||||||
newsize: Option<(u32, u32)>,
|
newsize: Option<(u32, u32)>,
|
||||||
size: Arc<Mutex<(u32, u32)>>,
|
size: Arc<Mutex<(u32, u32)>>,
|
||||||
|
fullscreen: Arc<Mutex<bool>>,
|
||||||
need_refresh: bool,
|
need_refresh: bool,
|
||||||
need_frame_refresh: Arc<Mutex<bool>>,
|
need_frame_refresh: Arc<Mutex<bool>>,
|
||||||
closed: bool,
|
closed: bool,
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ pub struct SharedState {
|
|||||||
pub guessed_dpi: Option<f64>,
|
pub guessed_dpi: Option<f64>,
|
||||||
pub last_monitor: Option<X11MonitorId>,
|
pub last_monitor: Option<X11MonitorId>,
|
||||||
pub dpi_adjusted: Option<(f64, f64)>,
|
pub dpi_adjusted: Option<(f64, f64)>,
|
||||||
|
pub fullscreen: Option<RootMonitorId>,
|
||||||
// Used to restore position after exiting fullscreen.
|
// Used to restore position after exiting fullscreen.
|
||||||
pub restore_position: Option<(i32, i32)>,
|
pub restore_position: Option<(i32, i32)>,
|
||||||
pub frame_extents: Option<util::FrameExtentsHeuristic>,
|
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]
|
#[inline]
|
||||||
pub fn set_fullscreen(&self, monitor: Option<RootMonitorId>) {
|
pub fn set_fullscreen(&self, monitor: Option<RootMonitorId>) {
|
||||||
|
self.shared_state.lock().fullscreen = monitor.clone();
|
||||||
self.set_fullscreen_inner(monitor)
|
self.set_fullscreen_inner(monitor)
|
||||||
.flush()
|
.flush()
|
||||||
.expect("Failed to change window fullscreen state");
|
.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]
|
#[inline]
|
||||||
fn set_simple_fullscreen(&self, fullscreen: bool) -> bool {
|
fn set_simple_fullscreen(&self, fullscreen: bool) -> bool {
|
||||||
let state = &self.delegate.state;
|
let state = &self.delegate.state;
|
||||||
@@ -1137,6 +1142,14 @@ impl Window2 {
|
|||||||
self.delegate.state.perform_maximized(maximized)
|
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]
|
#[inline]
|
||||||
/// TODO: Right now set_fullscreen do not work on switching monitors
|
/// TODO: Right now set_fullscreen do not work on switching monitors
|
||||||
/// in fullscreen mode
|
/// in fullscreen mode
|
||||||
|
|||||||
@@ -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]
|
#[inline]
|
||||||
pub fn set_fullscreen(&self, monitor: Option<RootMonitorId>) {
|
pub fn set_fullscreen(&self, monitor: Option<RootMonitorId>) {
|
||||||
unsafe {
|
unsafe {
|
||||||
|
|||||||
@@ -369,6 +369,12 @@ impl Window {
|
|||||||
self.window.set_fullscreen(monitor)
|
self.window.set_fullscreen(monitor)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Gets the window's current fullscreen state.
|
||||||
|
#[inline]
|
||||||
|
pub fn get_fullscreen(&self) -> Option<MonitorId> {
|
||||||
|
self.window.get_fullscreen()
|
||||||
|
}
|
||||||
|
|
||||||
/// Turn window decorations on or off.
|
/// Turn window decorations on or off.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn set_decorations(&self, decorations: bool) {
|
pub fn set_decorations(&self, decorations: bool) {
|
||||||
|
|||||||
Reference in New Issue
Block a user