2022-06-11 18:57:19 +02:00
|
|
|
//! The [`Window`] struct and associated types.
|
2023-12-23 16:12:29 +01:00
|
|
|
use std::fmt;
|
2019-02-05 10:30:33 -05:00
|
|
|
|
2023-05-09 20:19:35 +03:00
|
|
|
#[doc(inline)]
|
|
|
|
|
pub use cursor_icon::{CursorIcon, ParseError as CursorIconParseError};
|
2023-12-25 09:25:09 +01:00
|
|
|
#[cfg(feature = "serde")]
|
|
|
|
|
use serde::{Deserialize, Serialize};
|
2023-05-09 20:19:35 +03:00
|
|
|
|
2024-02-03 07:27:17 +04:00
|
|
|
pub use crate::cursor::{BadImage, Cursor, CustomCursor, CustomCursorSource, MAX_CURSOR_SIZE};
|
2019-06-19 16:49:43 -04:00
|
|
|
use crate::dpi::{PhysicalPosition, PhysicalSize, Position, Size};
|
2024-01-31 17:29:59 +04:00
|
|
|
use crate::error::{ExternalError, NotSupportedError};
|
2020-03-07 19:42:21 +00:00
|
|
|
pub use crate::icon::{BadIcon, Icon};
|
2023-12-26 22:12:33 +01:00
|
|
|
use crate::monitor::{MonitorHandle, VideoModeHandle};
|
2024-01-31 17:29:59 +04:00
|
|
|
use crate::platform_impl::{self, PlatformSpecificWindowAttributes};
|
2024-08-23 23:40:27 +03:00
|
|
|
use crate::utils::AsAny;
|
2024-08-08 00:46:28 +02:00
|
|
|
|
2019-02-05 10:30:33 -05:00
|
|
|
/// Identifier of a window. Unique for each window.
|
|
|
|
|
///
|
2024-03-16 10:22:29 +01:00
|
|
|
/// Can be obtained with [`window.id()`][`Window::id`].
|
2019-02-05 10:30:33 -05:00
|
|
|
///
|
|
|
|
|
/// Whenever you receive an event specific to a window, this event contains a `WindowId` which you
|
|
|
|
|
/// can then compare to the ids of your windows.
|
2024-04-15 00:06:18 +07:00
|
|
|
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
2019-02-05 10:30:33 -05:00
|
|
|
pub struct WindowId(pub(crate) platform_impl::WindowId);
|
|
|
|
|
|
|
|
|
|
impl WindowId {
|
2022-06-11 18:57:19 +02:00
|
|
|
/// Returns a dummy id, useful for unit testing.
|
2021-08-30 19:40:02 +02:00
|
|
|
///
|
2024-07-14 13:14:32 +02:00
|
|
|
/// # Notes
|
2021-08-30 19:40:02 +02:00
|
|
|
///
|
|
|
|
|
/// The only guarantee made about the return value of this function is that
|
|
|
|
|
/// it will always be equal to itself and to future values returned by this function.
|
2022-06-11 18:57:19 +02:00
|
|
|
/// No other guarantees are made. This may be equal to a real [`WindowId`].
|
2024-07-14 13:14:32 +02:00
|
|
|
pub const fn dummy() -> Self {
|
|
|
|
|
WindowId(platform_impl::WindowId::dummy())
|
2019-02-05 10:30:33 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-15 00:06:18 +07:00
|
|
|
impl fmt::Debug for WindowId {
|
|
|
|
|
fn fmt(&self, fmtr: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
|
|
|
self.0.fmt(fmtr)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-02 14:27:19 +03:00
|
|
|
impl From<WindowId> for u64 {
|
|
|
|
|
fn from(window_id: WindowId) -> Self {
|
2022-07-06 02:09:40 +09:00
|
|
|
window_id.0.into()
|
2022-07-02 14:27:19 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl From<u64> for WindowId {
|
|
|
|
|
fn from(raw_id: u64) -> Self {
|
2022-07-06 02:09:40 +09:00
|
|
|
Self(raw_id.into())
|
2022-07-02 14:27:19 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-30 11:17:36 +02:00
|
|
|
/// Attributes used when creating a window.
|
2024-08-08 00:46:28 +02:00
|
|
|
#[derive(Debug, Clone, PartialEq)]
|
2023-01-27 07:38:56 +02:00
|
|
|
pub struct WindowAttributes {
|
2024-09-04 15:04:48 +02:00
|
|
|
pub surface_size: Option<Size>,
|
|
|
|
|
pub min_surface_size: Option<Size>,
|
|
|
|
|
pub max_surface_size: Option<Size>,
|
|
|
|
|
pub surface_resize_increments: Option<Size>,
|
2021-03-25 21:18:51 +03:00
|
|
|
pub position: Option<Position>,
|
2019-02-05 10:30:33 -05:00
|
|
|
pub resizable: bool,
|
2022-11-29 12:03:51 +02:00
|
|
|
pub enabled_buttons: WindowButtons,
|
2019-02-05 10:30:33 -05:00
|
|
|
pub title: String,
|
|
|
|
|
pub maximized: bool,
|
|
|
|
|
pub visible: bool,
|
|
|
|
|
pub transparent: bool,
|
2023-10-08 22:53:15 +03:00
|
|
|
pub blur: bool,
|
2019-02-05 10:30:33 -05:00
|
|
|
pub decorations: bool,
|
|
|
|
|
pub window_icon: Option<Icon>,
|
2022-10-19 03:34:36 +09:00
|
|
|
pub preferred_theme: Option<Theme>,
|
2022-11-23 15:51:34 +02:00
|
|
|
pub content_protected: bool,
|
2022-11-26 03:50:58 +02:00
|
|
|
pub window_level: WindowLevel,
|
2023-01-27 07:08:29 +02:00
|
|
|
pub active: bool,
|
2023-12-26 19:50:58 +01:00
|
|
|
pub cursor: Cursor,
|
2023-10-17 04:54:12 +04:00
|
|
|
#[cfg(feature = "rwh_06")]
|
2023-12-26 20:13:02 +01:00
|
|
|
pub(crate) parent_window: Option<SendSyncRawWindowHandle>,
|
|
|
|
|
pub fullscreen: Option<Fullscreen>,
|
2024-01-17 23:37:28 +01:00
|
|
|
// Platform-specific configuration.
|
|
|
|
|
#[allow(dead_code)]
|
2024-01-31 17:29:59 +04:00
|
|
|
pub(crate) platform_specific: PlatformSpecificWindowAttributes,
|
2019-02-05 10:30:33 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Default for WindowAttributes {
|
|
|
|
|
#[inline]
|
|
|
|
|
fn default() -> WindowAttributes {
|
|
|
|
|
WindowAttributes {
|
2024-09-04 15:04:48 +02:00
|
|
|
surface_size: None,
|
|
|
|
|
min_surface_size: None,
|
|
|
|
|
max_surface_size: None,
|
|
|
|
|
surface_resize_increments: None,
|
2021-03-25 21:18:51 +03:00
|
|
|
position: None,
|
2019-02-05 10:30:33 -05:00
|
|
|
resizable: true,
|
2022-11-29 12:03:51 +02:00
|
|
|
enabled_buttons: WindowButtons::all(),
|
2019-02-05 10:30:33 -05:00
|
|
|
title: "winit window".to_owned(),
|
|
|
|
|
maximized: false,
|
2023-12-26 20:13:02 +01:00
|
|
|
fullscreen: None,
|
2019-02-05 10:30:33 -05:00
|
|
|
visible: true,
|
|
|
|
|
transparent: false,
|
2023-10-08 22:53:15 +03:00
|
|
|
blur: false,
|
2019-02-05 10:30:33 -05:00
|
|
|
decorations: true,
|
2022-11-26 03:50:58 +02:00
|
|
|
window_level: Default::default(),
|
2019-02-05 10:30:33 -05:00
|
|
|
window_icon: None,
|
2022-10-19 03:34:36 +09:00
|
|
|
preferred_theme: None,
|
2022-11-23 15:51:34 +02:00
|
|
|
content_protected: false,
|
2023-12-26 19:50:58 +01:00
|
|
|
cursor: Cursor::default(),
|
2023-10-14 19:07:39 -07:00
|
|
|
#[cfg(feature = "rwh_06")]
|
2023-12-26 20:13:02 +01:00
|
|
|
parent_window: None,
|
2023-01-27 07:08:29 +02:00
|
|
|
active: true,
|
2024-01-17 23:37:28 +01:00
|
|
|
platform_specific: Default::default(),
|
2019-02-05 10:30:33 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-09-24 00:10:33 +10:00
|
|
|
|
2023-12-26 20:13:02 +01:00
|
|
|
/// Wrapper for [`rwh_06::RawWindowHandle`] for [`WindowAttributes::parent_window`].
|
|
|
|
|
///
|
|
|
|
|
/// # Safety
|
|
|
|
|
///
|
2024-01-31 17:29:59 +04:00
|
|
|
/// The user has to account for that when using [`WindowAttributes::with_parent_window()`],
|
2023-12-26 20:13:02 +01:00
|
|
|
/// which is `unsafe`.
|
2024-08-08 00:46:28 +02:00
|
|
|
#[derive(Debug, Clone, PartialEq)]
|
2023-12-26 20:13:02 +01:00
|
|
|
#[cfg(feature = "rwh_06")]
|
|
|
|
|
pub(crate) struct SendSyncRawWindowHandle(pub(crate) rwh_06::RawWindowHandle);
|
|
|
|
|
|
|
|
|
|
#[cfg(feature = "rwh_06")]
|
|
|
|
|
unsafe impl Send for SendSyncRawWindowHandle {}
|
|
|
|
|
#[cfg(feature = "rwh_06")]
|
|
|
|
|
unsafe impl Sync for SendSyncRawWindowHandle {}
|
|
|
|
|
|
2024-01-31 17:29:59 +04:00
|
|
|
impl WindowAttributes {
|
|
|
|
|
/// Get the parent window stored on the attributes.
|
|
|
|
|
#[cfg(feature = "rwh_06")]
|
|
|
|
|
pub fn parent_window(&self) -> Option<&rwh_06::RawWindowHandle> {
|
|
|
|
|
self.parent_window.as_ref().map(|handle| &handle.0)
|
2023-01-27 07:38:56 +02:00
|
|
|
}
|
|
|
|
|
|
2024-09-04 15:04:48 +02:00
|
|
|
/// Requests the surface to be of specific dimensions.
|
2019-10-16 12:18:02 -04:00
|
|
|
///
|
2022-06-10 19:05:28 +02:00
|
|
|
/// If this is not set, some platform-specific dimensions will be used.
|
|
|
|
|
///
|
2024-09-04 15:04:48 +02:00
|
|
|
/// See [`Window::request_surface_size`] for details.
|
2015-09-21 14:42:05 +02:00
|
|
|
#[inline]
|
2024-09-04 15:04:48 +02:00
|
|
|
pub fn with_surface_size<S: Into<Size>>(mut self, size: S) -> Self {
|
|
|
|
|
self.surface_size = Some(size.into());
|
2015-02-16 09:29:37 +01:00
|
|
|
self
|
|
|
|
|
}
|
2017-06-21 20:10:23 +01:00
|
|
|
|
2024-09-04 15:04:48 +02:00
|
|
|
/// Sets the minimum dimensions the surface can have.
|
2022-06-10 19:05:28 +02:00
|
|
|
///
|
2024-09-04 15:04:48 +02:00
|
|
|
/// If this is not set, the surface will have no minimum dimensions (aside from reserved).
|
2019-10-16 12:18:02 -04:00
|
|
|
///
|
2024-09-04 15:04:48 +02:00
|
|
|
/// See [`Window::set_min_surface_size`] for details.
|
2015-11-09 01:42:54 -08:00
|
|
|
#[inline]
|
2024-09-04 15:04:48 +02:00
|
|
|
pub fn with_min_surface_size<S: Into<Size>>(mut self, min_size: S) -> Self {
|
|
|
|
|
self.min_surface_size = Some(min_size.into());
|
2015-11-09 01:42:54 -08:00
|
|
|
self
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-04 15:04:48 +02:00
|
|
|
/// Sets the maximum dimensions the surface can have.
|
2022-06-10 19:05:28 +02:00
|
|
|
///
|
2024-09-04 15:04:48 +02:00
|
|
|
/// If this is not set, the surface will have no maximum, or the maximum will be restricted to
|
2022-06-10 19:05:28 +02:00
|
|
|
/// the primary monitor's dimensions by the platform.
|
2019-10-16 12:18:02 -04:00
|
|
|
///
|
2024-09-04 15:04:48 +02:00
|
|
|
/// See [`Window::set_max_surface_size`] for details.
|
2015-11-09 01:42:54 -08:00
|
|
|
#[inline]
|
2024-09-04 15:04:48 +02:00
|
|
|
pub fn with_max_surface_size<S: Into<Size>>(mut self, max_size: S) -> Self {
|
|
|
|
|
self.max_surface_size = Some(max_size.into());
|
|
|
|
|
self
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Build window with resize increments hint.
|
|
|
|
|
///
|
|
|
|
|
/// The default is `None`.
|
|
|
|
|
///
|
|
|
|
|
/// See [`Window::set_surface_resize_increments`] for details.
|
|
|
|
|
#[inline]
|
|
|
|
|
pub fn with_surface_resize_increments<S: Into<Size>>(
|
|
|
|
|
mut self,
|
|
|
|
|
surface_resize_increments: S,
|
|
|
|
|
) -> Self {
|
|
|
|
|
self.surface_resize_increments = Some(surface_resize_increments.into());
|
2015-11-09 01:42:54 -08:00
|
|
|
self
|
|
|
|
|
}
|
2015-02-16 09:29:37 +01:00
|
|
|
|
2021-03-25 21:18:51 +03:00
|
|
|
/// Sets a desired initial position for the window.
|
|
|
|
|
///
|
2022-06-10 19:05:28 +02:00
|
|
|
/// If this is not set, some platform-specific position will be chosen.
|
2021-03-25 21:18:51 +03:00
|
|
|
///
|
2022-06-10 19:05:28 +02:00
|
|
|
/// See [`Window::set_outer_position`] for details.
|
|
|
|
|
///
|
|
|
|
|
/// ## Platform-specific
|
|
|
|
|
///
|
2022-07-20 13:45:12 +02:00
|
|
|
/// - **macOS:** The top left corner position of the window content, the window's "inner"
|
2022-06-10 19:05:28 +02:00
|
|
|
/// position. The window title bar will be placed above it. The window will be positioned such
|
2024-09-04 15:04:48 +02:00
|
|
|
/// that it fits on screen, maintaining set `surface_size` if any. If you need to precisely
|
2022-06-10 19:05:28 +02:00
|
|
|
/// position the top left corner of the whole window you have to use
|
|
|
|
|
/// [`Window::set_outer_position`] after creating the window.
|
2022-07-20 13:45:12 +02:00
|
|
|
/// - **Windows:** The top left corner position of the window title bar, the window's "outer"
|
2022-06-10 19:05:28 +02:00
|
|
|
/// position. There may be a small gap between this position and the window due to the
|
|
|
|
|
/// specifics of the Window Manager.
|
2022-07-20 13:45:12 +02:00
|
|
|
/// - **X11:** The top left corner of the window, the window's "outer" position.
|
|
|
|
|
/// - **Others:** Ignored.
|
2021-03-25 21:18:51 +03:00
|
|
|
#[inline]
|
|
|
|
|
pub fn with_position<P: Into<Position>>(mut self, position: P) -> Self {
|
2024-01-31 17:29:59 +04:00
|
|
|
self.position = Some(position.into());
|
2021-03-25 21:18:51 +03:00
|
|
|
self
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-16 12:18:02 -04:00
|
|
|
/// Sets whether the window is resizable or not.
|
2018-06-02 08:51:24 -06:00
|
|
|
///
|
2022-06-10 19:05:28 +02:00
|
|
|
/// The default is `true`.
|
|
|
|
|
///
|
2019-10-16 12:18:02 -04:00
|
|
|
/// See [`Window::set_resizable`] for details.
|
2018-06-02 08:51:24 -06:00
|
|
|
#[inline]
|
2019-09-24 00:10:33 +10:00
|
|
|
pub fn with_resizable(mut self, resizable: bool) -> Self {
|
2024-01-31 17:29:59 +04:00
|
|
|
self.resizable = resizable;
|
2018-06-02 08:51:24 -06:00
|
|
|
self
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-29 12:03:51 +02:00
|
|
|
/// Sets the enabled window buttons.
|
|
|
|
|
///
|
|
|
|
|
/// The default is [`WindowButtons::all`]
|
|
|
|
|
///
|
|
|
|
|
/// See [`Window::set_enabled_buttons`] for details.
|
|
|
|
|
#[inline]
|
|
|
|
|
pub fn with_enabled_buttons(mut self, buttons: WindowButtons) -> Self {
|
2024-01-31 17:29:59 +04:00
|
|
|
self.enabled_buttons = buttons;
|
2022-11-29 12:03:51 +02:00
|
|
|
self
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-10 19:05:28 +02:00
|
|
|
/// Sets the initial title of the window in the title bar.
|
|
|
|
|
///
|
|
|
|
|
/// The default is `"winit window"`.
|
2019-10-16 12:18:02 -04:00
|
|
|
///
|
|
|
|
|
/// See [`Window::set_title`] for details.
|
2015-09-21 14:42:05 +02:00
|
|
|
#[inline]
|
2019-09-24 00:10:33 +10:00
|
|
|
pub fn with_title<T: Into<String>>(mut self, title: T) -> Self {
|
2024-01-31 17:29:59 +04:00
|
|
|
self.title = title.into();
|
2015-02-16 09:29:37 +01:00
|
|
|
self
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-10 19:05:28 +02:00
|
|
|
/// Sets whether the window should be put into fullscreen upon creation.
|
|
|
|
|
///
|
|
|
|
|
/// The default is `None`.
|
2019-07-29 11:18:23 +02:00
|
|
|
///
|
2019-10-16 12:18:02 -04:00
|
|
|
/// See [`Window::set_fullscreen`] for details.
|
2015-09-21 14:42:05 +02:00
|
|
|
#[inline]
|
2020-08-01 23:10:33 +00:00
|
|
|
pub fn with_fullscreen(mut self, fullscreen: Option<Fullscreen>) -> Self {
|
2024-01-31 17:29:59 +04:00
|
|
|
self.fullscreen = fullscreen;
|
2015-02-16 09:29:37 +01:00
|
|
|
self
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-10 19:05:28 +02:00
|
|
|
/// Request that the window is maximized upon creation.
|
|
|
|
|
///
|
|
|
|
|
/// The default is `false`.
|
2019-10-16 12:18:02 -04:00
|
|
|
///
|
|
|
|
|
/// See [`Window::set_maximized`] for details.
|
2017-08-28 00:19:26 +01:00
|
|
|
#[inline]
|
2019-09-24 00:10:33 +10:00
|
|
|
pub fn with_maximized(mut self, maximized: bool) -> Self {
|
2024-01-31 17:29:59 +04:00
|
|
|
self.maximized = maximized;
|
2017-08-28 00:19:26 +01:00
|
|
|
self
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-10 19:05:28 +02:00
|
|
|
/// Sets whether the window will be initially visible or hidden.
|
|
|
|
|
///
|
|
|
|
|
/// The default is to show the window.
|
2019-10-16 12:18:02 -04:00
|
|
|
///
|
|
|
|
|
/// See [`Window::set_visible`] for details.
|
2015-09-21 14:42:05 +02:00
|
|
|
#[inline]
|
2019-09-24 00:10:33 +10:00
|
|
|
pub fn with_visible(mut self, visible: bool) -> Self {
|
2024-01-31 17:29:59 +04:00
|
|
|
self.visible = visible;
|
2015-02-16 09:29:37 +01:00
|
|
|
self
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-15 15:19:33 +02:00
|
|
|
/// Sets whether the background of the window should be transparent.
|
2022-06-10 19:05:28 +02:00
|
|
|
///
|
|
|
|
|
/// If this is `true`, writing colors with alpha values different than
|
2023-01-15 23:39:36 +03:00
|
|
|
/// `1.0` will produce a transparent window. On some platforms this
|
|
|
|
|
/// is more of a hint for the system and you'd still have the alpha
|
|
|
|
|
/// buffer. To control it see [`Window::set_transparent`].
|
2022-06-10 19:05:28 +02:00
|
|
|
///
|
|
|
|
|
/// The default is `false`.
|
2015-09-21 14:42:05 +02:00
|
|
|
#[inline]
|
2019-09-24 00:10:33 +10:00
|
|
|
pub fn with_transparent(mut self, transparent: bool) -> Self {
|
2024-01-31 17:29:59 +04:00
|
|
|
self.transparent = transparent;
|
2015-05-15 15:19:33 +02:00
|
|
|
self
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-08 22:53:15 +03:00
|
|
|
/// Sets whether the background of the window should be blurred by the system.
|
|
|
|
|
///
|
|
|
|
|
/// The default is `false`.
|
|
|
|
|
///
|
|
|
|
|
/// See [`Window::set_blur`] for details.
|
|
|
|
|
#[inline]
|
|
|
|
|
pub fn with_blur(mut self, blur: bool) -> Self {
|
2024-01-31 17:29:59 +04:00
|
|
|
self.blur = blur;
|
2023-10-08 22:53:15 +03:00
|
|
|
self
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-12 09:53:28 +03:00
|
|
|
/// Get whether the window will support transparency.
|
|
|
|
|
#[inline]
|
|
|
|
|
pub fn transparent(&self) -> bool {
|
2024-01-31 17:29:59 +04:00
|
|
|
self.transparent
|
2022-06-12 09:53:28 +03:00
|
|
|
}
|
|
|
|
|
|
2015-05-15 15:19:33 +02:00
|
|
|
/// Sets whether the window should have a border, a title bar, etc.
|
2019-10-16 12:18:02 -04:00
|
|
|
///
|
2022-06-10 19:05:28 +02:00
|
|
|
/// The default is `true`.
|
|
|
|
|
///
|
2019-10-16 12:18:02 -04:00
|
|
|
/// See [`Window::set_decorations`] for details.
|
2015-09-21 14:42:05 +02:00
|
|
|
#[inline]
|
2019-09-24 00:10:33 +10:00
|
|
|
pub fn with_decorations(mut self, decorations: bool) -> Self {
|
2024-01-31 17:29:59 +04:00
|
|
|
self.decorations = decorations;
|
2015-05-15 15:19:33 +02:00
|
|
|
self
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-26 03:50:58 +02:00
|
|
|
/// Sets the window level.
|
2019-10-16 12:18:02 -04:00
|
|
|
///
|
2022-11-26 03:50:58 +02:00
|
|
|
/// This is just a hint to the OS, and the system could ignore it.
|
|
|
|
|
///
|
|
|
|
|
/// The default is [`WindowLevel::Normal`].
|
2022-06-10 19:05:28 +02:00
|
|
|
///
|
2022-11-26 03:50:58 +02:00
|
|
|
/// See [`WindowLevel`] for details.
|
2018-05-20 10:24:05 -04:00
|
|
|
#[inline]
|
2022-11-26 03:50:58 +02:00
|
|
|
pub fn with_window_level(mut self, level: WindowLevel) -> Self {
|
2024-01-31 17:29:59 +04:00
|
|
|
self.window_level = level;
|
2018-05-20 10:24:05 -04:00
|
|
|
self
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-16 12:18:02 -04:00
|
|
|
/// Sets the window icon.
|
2018-05-07 17:36:21 -04:00
|
|
|
///
|
2022-06-10 19:05:28 +02:00
|
|
|
/// The default is `None`.
|
|
|
|
|
///
|
2019-10-16 12:18:02 -04:00
|
|
|
/// See [`Window::set_window_icon`] for details.
|
2018-05-07 17:36:21 -04:00
|
|
|
#[inline]
|
2019-09-24 00:10:33 +10:00
|
|
|
pub fn with_window_icon(mut self, window_icon: Option<Icon>) -> Self {
|
2024-01-31 17:29:59 +04:00
|
|
|
self.window_icon = window_icon;
|
2018-05-07 17:36:21 -04:00
|
|
|
self
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-19 03:34:36 +09:00
|
|
|
/// Sets a specific theme for the window.
|
|
|
|
|
///
|
|
|
|
|
/// If `None` is provided, the window will use the system theme.
|
|
|
|
|
///
|
|
|
|
|
/// The default is `None`.
|
|
|
|
|
///
|
|
|
|
|
/// ## Platform-specific
|
|
|
|
|
///
|
2023-10-10 09:23:37 +04:00
|
|
|
/// - **Wayland:** This controls only CSD. When using `None` it'll try to use dbus to get the
|
|
|
|
|
/// system preference. When explicit theme is used, this will avoid dbus all together.
|
2022-11-29 11:05:51 +02:00
|
|
|
/// - **x11:** Build window with `_GTK_THEME_VARIANT` hint set to `dark` or `light`.
|
2023-01-05 06:58:08 -07:00
|
|
|
/// - **iOS / Android / Web / x11 / Orbital:** Ignored.
|
2022-10-19 03:34:36 +09:00
|
|
|
#[inline]
|
|
|
|
|
pub fn with_theme(mut self, theme: Option<Theme>) -> Self {
|
2024-01-31 17:29:59 +04:00
|
|
|
self.preferred_theme = theme;
|
2022-10-19 03:34:36 +09:00
|
|
|
self
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-23 15:51:34 +02:00
|
|
|
/// Prevents the window contents from being captured by other apps.
|
|
|
|
|
///
|
|
|
|
|
/// The default is `false`.
|
|
|
|
|
///
|
|
|
|
|
/// ## Platform-specific
|
|
|
|
|
///
|
2024-07-25 15:15:21 +02:00
|
|
|
/// - **macOS**: if `false`, [`NSWindowSharingNone`] is used but doesn't completely prevent all
|
|
|
|
|
/// apps from reading the window content, for instance, QuickTime.
|
2023-01-05 06:58:08 -07:00
|
|
|
/// - **iOS / Android / Web / x11 / Orbital:** Ignored.
|
2022-11-23 15:51:34 +02:00
|
|
|
///
|
|
|
|
|
/// [`NSWindowSharingNone`]: https://developer.apple.com/documentation/appkit/nswindowsharingtype/nswindowsharingnone
|
|
|
|
|
#[inline]
|
|
|
|
|
pub fn with_content_protected(mut self, protected: bool) -> Self {
|
2024-01-31 17:29:59 +04:00
|
|
|
self.content_protected = protected;
|
2022-11-23 15:51:34 +02:00
|
|
|
self
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-27 07:08:29 +02:00
|
|
|
/// Whether the window will be initially focused or not.
|
|
|
|
|
///
|
|
|
|
|
/// The window should be assumed as not focused by default
|
|
|
|
|
/// following by the [`WindowEvent::Focused`].
|
|
|
|
|
///
|
|
|
|
|
/// ## Platform-specific:
|
|
|
|
|
///
|
|
|
|
|
/// **Android / iOS / X11 / Wayland / Orbital:** Unsupported.
|
|
|
|
|
///
|
|
|
|
|
/// [`WindowEvent::Focused`]: crate::event::WindowEvent::Focused.
|
|
|
|
|
#[inline]
|
2023-10-14 19:07:39 -07:00
|
|
|
pub fn with_active(mut self, active: bool) -> Self {
|
2024-01-31 17:29:59 +04:00
|
|
|
self.active = active;
|
2023-01-27 07:08:29 +02:00
|
|
|
self
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-26 19:50:58 +01:00
|
|
|
/// Modifies the cursor icon of the window.
|
|
|
|
|
///
|
|
|
|
|
/// The default is [`CursorIcon::Default`].
|
|
|
|
|
///
|
|
|
|
|
/// See [`Window::set_cursor()`] for more details.
|
|
|
|
|
#[inline]
|
|
|
|
|
pub fn with_cursor(mut self, cursor: impl Into<Cursor>) -> Self {
|
2024-01-31 17:29:59 +04:00
|
|
|
self.cursor = cursor.into();
|
2023-12-26 19:50:58 +01:00
|
|
|
self
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-22 08:07:13 +08:00
|
|
|
/// Build window with parent window.
|
|
|
|
|
///
|
|
|
|
|
/// The default is `None`.
|
|
|
|
|
///
|
|
|
|
|
/// ## Safety
|
|
|
|
|
///
|
|
|
|
|
/// `parent_window` must be a valid window handle.
|
|
|
|
|
///
|
|
|
|
|
/// ## Platform-specific
|
|
|
|
|
///
|
|
|
|
|
/// - **Windows** : A child window has the WS_CHILD style and is confined
|
2024-07-25 15:15:21 +02:00
|
|
|
/// to the client area of its parent window. For more information, see
|
|
|
|
|
/// <https://docs.microsoft.com/en-us/windows/win32/winmsg/window-features#child-windows>
|
2022-12-22 08:07:13 +08:00
|
|
|
/// - **X11**: A child window is confined to the client area of its parent window.
|
2023-07-11 18:26:00 +02:00
|
|
|
/// - **Android / iOS / Wayland / Web:** Unsupported.
|
2023-10-14 19:07:39 -07:00
|
|
|
#[cfg(feature = "rwh_06")]
|
2022-12-22 08:07:13 +08:00
|
|
|
#[inline]
|
2023-10-14 19:07:39 -07:00
|
|
|
pub unsafe fn with_parent_window(
|
|
|
|
|
mut self,
|
|
|
|
|
parent_window: Option<rwh_06::RawWindowHandle>,
|
|
|
|
|
) -> Self {
|
2024-01-31 17:29:59 +04:00
|
|
|
self.parent_window = parent_window.map(SendSyncRawWindowHandle);
|
2022-12-22 08:07:13 +08:00
|
|
|
self
|
|
|
|
|
}
|
2015-02-16 09:29:37 +01:00
|
|
|
}
|
|
|
|
|
|
2024-08-23 23:40:27 +03:00
|
|
|
/// Represents a window.
|
|
|
|
|
///
|
|
|
|
|
/// The window is closed when dropped.
|
|
|
|
|
///
|
|
|
|
|
/// ## Threading
|
|
|
|
|
///
|
|
|
|
|
/// This is `Send + Sync`, meaning that it can be freely used from other
|
|
|
|
|
/// threads.
|
|
|
|
|
///
|
|
|
|
|
/// However, some platforms (macOS, Web and iOS) only allow user interface
|
|
|
|
|
/// interactions on the main thread, so on those platforms, if you use the
|
|
|
|
|
/// window from a thread other than the main, the code is scheduled to run on
|
|
|
|
|
/// the main thread, and your thread may be blocked until that completes.
|
|
|
|
|
///
|
|
|
|
|
/// ## Platform-specific
|
|
|
|
|
///
|
|
|
|
|
/// **Web:** The [`Window`], which is represented by a `HTMLElementCanvas`, can
|
|
|
|
|
/// not be closed by dropping the [`Window`].
|
|
|
|
|
pub trait Window: AsAny + Send + Sync {
|
2019-05-29 21:29:54 -04:00
|
|
|
/// Returns an identifier unique to the window.
|
2024-08-23 23:40:27 +03:00
|
|
|
fn id(&self) -> WindowId;
|
2015-02-16 09:29:37 +01:00
|
|
|
|
2023-10-28 14:23:20 +04:00
|
|
|
/// Returns the scale factor that can be used to map logical pixels to physical pixels, and
|
|
|
|
|
/// vice versa.
|
2015-02-16 09:29:37 +01:00
|
|
|
///
|
2019-05-29 21:29:54 -04:00
|
|
|
/// Note that this value can change depending on user action (for example if the window is
|
2022-06-11 18:57:19 +02:00
|
|
|
/// moved to another screen); as such, tracking [`WindowEvent::ScaleFactorChanged`] events is
|
2019-05-29 21:29:54 -04:00
|
|
|
/// the most robust way to track the DPI you need to use to draw.
|
2015-02-16 09:29:37 +01:00
|
|
|
///
|
2023-10-28 14:23:20 +04:00
|
|
|
/// This value may differ from [`MonitorHandle::scale_factor`].
|
|
|
|
|
///
|
2024-02-26 14:52:00 +01:00
|
|
|
/// See the [`dpi`] crate for more information.
|
2023-10-28 14:23:20 +04:00
|
|
|
///
|
2015-02-16 09:29:37 +01:00
|
|
|
/// ## Platform-specific
|
|
|
|
|
///
|
2024-02-26 14:52:00 +01:00
|
|
|
/// The scale factor is calculated differently on different platforms:
|
|
|
|
|
///
|
|
|
|
|
/// - **Windows:** On Windows 8 and 10, per-monitor scaling is readily configured by users from
|
|
|
|
|
/// the display settings. While users are free to select any option they want, they're only
|
|
|
|
|
/// given a selection of "nice" scale factors, i.e. 1.0, 1.25, 1.5... on Windows 7. The scale
|
|
|
|
|
/// factor is global and changing it requires logging out. See [this article][windows_1] for
|
|
|
|
|
/// technical details.
|
|
|
|
|
/// - **macOS:** Recent macOS versions allow the user to change the scaling factor for specific
|
|
|
|
|
/// displays. When available, the user may pick a per-monitor scaling factor from a set of
|
|
|
|
|
/// pre-defined settings. All "retina displays" have a scaling factor above 1.0 by default,
|
|
|
|
|
/// but the specific value varies across devices.
|
|
|
|
|
/// - **X11:** Many man-hours have been spent trying to figure out how to handle DPI in X11.
|
|
|
|
|
/// Winit currently uses a three-pronged approach:
|
|
|
|
|
/// + Use the value in the `WINIT_X11_SCALE_FACTOR` environment variable if present.
|
|
|
|
|
/// + If not present, use the value set in `Xft.dpi` in Xresources.
|
|
|
|
|
/// + Otherwise, calculate the scale factor based on the millimeter monitor dimensions
|
|
|
|
|
/// provided by XRandR.
|
|
|
|
|
///
|
|
|
|
|
/// If `WINIT_X11_SCALE_FACTOR` is set to `randr`, it'll ignore the `Xft.dpi` field and use
|
2024-07-25 15:15:21 +02:00
|
|
|
/// the XRandR scaling method. Generally speaking, you should try to configure the
|
|
|
|
|
/// standard system variables to do what you want before resorting to
|
|
|
|
|
/// `WINIT_X11_SCALE_FACTOR`.
|
2024-02-26 14:52:00 +01:00
|
|
|
/// - **Wayland:** The scale factor is suggested by the compositor for each window individually
|
|
|
|
|
/// by using the wp-fractional-scale protocol if available. Falls back to integer-scale
|
|
|
|
|
/// factors otherwise.
|
|
|
|
|
///
|
|
|
|
|
/// The monitor scale factor may differ from the window scale factor.
|
|
|
|
|
/// - **iOS:** Scale factors are set by Apple to the value that best suits the device, and range
|
|
|
|
|
/// from `1.0` to `3.0`. See [this article][apple_1] and [this article][apple_2] for more
|
|
|
|
|
/// information.
|
|
|
|
|
///
|
|
|
|
|
/// This uses the underlying `UIView`'s [`contentScaleFactor`].
|
|
|
|
|
/// - **Android:** Scale factors are set by the manufacturer to the value that best suits the
|
|
|
|
|
/// device, and range from `1.0` to `4.0`. See [this article][android_1] for more information.
|
|
|
|
|
///
|
|
|
|
|
/// This is currently unimplemented, and this function always returns 1.0.
|
|
|
|
|
/// - **Web:** The scale factor is the ratio between CSS pixels and the physical device pixels.
|
|
|
|
|
/// In other words, it is the value of [`window.devicePixelRatio`][web_1]. It is affected by
|
|
|
|
|
/// both the screen scaling and the browser zoom level and can go below `1.0`.
|
|
|
|
|
/// - **Orbital:** This is currently unimplemented, and this function always returns 1.0.
|
2019-05-29 21:29:54 -04:00
|
|
|
///
|
2022-06-11 18:57:19 +02:00
|
|
|
/// [`WindowEvent::ScaleFactorChanged`]: crate::event::WindowEvent::ScaleFactorChanged
|
2024-02-26 14:52:00 +01:00
|
|
|
/// [windows_1]: https://docs.microsoft.com/en-us/windows/win32/hidpi/high-dpi-desktop-application-development-on-windows
|
|
|
|
|
/// [apple_1]: https://developer.apple.com/library/archive/documentation/DeviceInformation/Reference/iOSDeviceCompatibility/Displays/Displays.html
|
|
|
|
|
/// [apple_2]: https://developer.apple.com/design/human-interface-guidelines/macos/icons-and-images/image-size-and-resolution/
|
|
|
|
|
/// [android_1]: https://developer.android.com/training/multiscreen/screendensities
|
|
|
|
|
/// [web_1]: https://developer.mozilla.org/en-US/docs/Web/API/Window/devicePixelRatio
|
2019-05-29 21:29:54 -04:00
|
|
|
/// [`contentScaleFactor`]: https://developer.apple.com/documentation/uikit/uiview/1622657-contentscalefactor?language=objc
|
2024-08-23 23:40:27 +03:00
|
|
|
fn scale_factor(&self) -> f64;
|
2015-02-16 09:29:37 +01:00
|
|
|
|
2023-08-27 16:15:09 +02:00
|
|
|
/// Queues a [`WindowEvent::RedrawRequested`] event to be emitted that aligns with the windowing
|
2023-06-22 09:12:47 +04:00
|
|
|
/// system drawing loop.
|
2019-02-05 10:30:33 -05:00
|
|
|
///
|
2019-06-18 00:22:01 +02:00
|
|
|
/// This is the **strongly encouraged** method of redrawing windows, as it can integrate with
|
2023-06-22 09:12:47 +04:00
|
|
|
/// OS-requested redraws (e.g. when a window gets resized). To improve the event delivery
|
|
|
|
|
/// consider using [`Window::pre_present_notify`] as described in docs.
|
2019-02-05 10:30:33 -05:00
|
|
|
///
|
2023-06-18 11:42:57 +01:00
|
|
|
/// Applications should always aim to redraw whenever they receive a `RedrawRequested` event.
|
|
|
|
|
///
|
|
|
|
|
/// There are no strong guarantees about when exactly a `RedrawRequest` event will be emitted
|
|
|
|
|
/// with respect to other events, since the requirements can vary significantly between
|
|
|
|
|
/// windowing systems.
|
2019-05-25 18:10:41 -07:00
|
|
|
///
|
2023-06-22 09:12:47 +04:00
|
|
|
/// However as the event aligns with the windowing system drawing loop, it may not arrive in
|
|
|
|
|
/// same or even next event loop iteration.
|
|
|
|
|
///
|
2019-05-25 18:10:41 -07:00
|
|
|
/// ## Platform-specific
|
|
|
|
|
///
|
2023-06-18 11:42:57 +01:00
|
|
|
/// - **Windows** This API uses `RedrawWindow` to request a `WM_PAINT` message and
|
2023-10-20 14:52:01 +04:00
|
|
|
/// `RedrawRequested` is emitted in sync with any `WM_PAINT` messages.
|
2023-06-22 09:12:47 +04:00
|
|
|
/// - **Wayland:** The events are aligned with the frame callbacks when
|
|
|
|
|
/// [`Window::pre_present_notify`] is used.
|
2023-08-27 16:15:09 +02:00
|
|
|
/// - **Web:** [`WindowEvent::RedrawRequested`] will be aligned with the
|
|
|
|
|
/// `requestAnimationFrame`.
|
2022-06-11 18:57:19 +02:00
|
|
|
///
|
2023-08-27 16:15:09 +02:00
|
|
|
/// [`WindowEvent::RedrawRequested`]: crate::event::WindowEvent::RedrawRequested
|
2024-08-23 23:40:27 +03:00
|
|
|
fn request_redraw(&self);
|
2023-05-28 20:02:59 +02:00
|
|
|
|
2023-11-01 15:07:35 -06:00
|
|
|
/// Notify the windowing system before presenting to the window.
|
2023-06-22 08:08:53 +04:00
|
|
|
///
|
2023-11-01 15:07:35 -06:00
|
|
|
/// You should call this event after your drawing operations, but before you submit
|
2023-06-22 08:08:53 +04:00
|
|
|
/// the buffer to the display or commit your drawings. Doing so will help winit to properly
|
2023-11-01 15:07:35 -06:00
|
|
|
/// schedule and make assumptions about its internal state. For example, it could properly
|
2023-08-27 16:15:09 +02:00
|
|
|
/// throttle [`WindowEvent::RedrawRequested`].
|
2023-06-22 08:08:53 +04:00
|
|
|
///
|
|
|
|
|
/// ## Example
|
|
|
|
|
///
|
|
|
|
|
/// This example illustrates how it looks with OpenGL, but it applies to other graphics
|
|
|
|
|
/// APIs and software rendering.
|
|
|
|
|
///
|
|
|
|
|
/// ```no_run
|
|
|
|
|
/// # use winit::window::Window;
|
|
|
|
|
/// # fn swap_buffers() {}
|
2024-08-23 23:40:27 +03:00
|
|
|
/// # fn scope(window: &dyn Window) {
|
2023-06-22 08:08:53 +04:00
|
|
|
/// // Do the actual drawing with OpenGL.
|
|
|
|
|
///
|
|
|
|
|
/// // Notify winit that we're about to submit buffer to the windowing system.
|
|
|
|
|
/// window.pre_present_notify();
|
|
|
|
|
///
|
2024-02-19 11:58:44 +07:00
|
|
|
/// // Submit buffer to the windowing system.
|
2023-06-22 08:08:53 +04:00
|
|
|
/// swap_buffers();
|
2024-01-31 17:29:59 +04:00
|
|
|
/// # }
|
2023-06-22 08:08:53 +04:00
|
|
|
/// ```
|
|
|
|
|
///
|
|
|
|
|
/// ## Platform-specific
|
|
|
|
|
///
|
2024-06-06 11:11:06 +02:00
|
|
|
/// - **Android / iOS / X11 / Web / Windows / macOS / Orbital:** Unsupported.
|
|
|
|
|
/// - **Wayland:** Schedules a frame callback to throttle [`WindowEvent::RedrawRequested`].
|
2023-06-22 08:08:53 +04:00
|
|
|
///
|
2023-08-27 16:15:09 +02:00
|
|
|
/// [`WindowEvent::RedrawRequested`]: crate::event::WindowEvent::RedrawRequested
|
2024-08-23 23:40:27 +03:00
|
|
|
fn pre_present_notify(&self);
|
2023-06-22 08:08:53 +04:00
|
|
|
|
2023-05-28 20:02:59 +02:00
|
|
|
/// Reset the dead key state of the keyboard.
|
|
|
|
|
///
|
|
|
|
|
/// This is useful when a dead key is bound to trigger an action. Then
|
|
|
|
|
/// this function can be called to reset the dead key state so that
|
|
|
|
|
/// follow-up text input won't be affected by the dead key.
|
|
|
|
|
///
|
|
|
|
|
/// ## Platform-specific
|
|
|
|
|
/// - **Web, macOS:** Does nothing
|
|
|
|
|
// ---------------------------
|
|
|
|
|
// Developers' Note: If this cannot be implemented on every desktop platform
|
|
|
|
|
// at least, then this function should be provided through a platform specific
|
|
|
|
|
// extension trait
|
2024-08-23 23:40:27 +03:00
|
|
|
fn reset_dead_keys(&self);
|
2024-02-25 19:20:39 -08:00
|
|
|
|
2019-05-29 21:29:54 -04:00
|
|
|
/// Returns the position of the top-left hand corner of the window's client area relative to the
|
|
|
|
|
/// top-left hand corner of the desktop.
|
|
|
|
|
///
|
2022-06-11 18:57:19 +02:00
|
|
|
/// The same conditions that apply to [`Window::outer_position`] apply to this method.
|
2019-05-29 21:29:54 -04:00
|
|
|
///
|
|
|
|
|
/// ## Platform-specific
|
|
|
|
|
///
|
2024-08-19 12:41:29 +02:00
|
|
|
/// - **iOS:** Returns the top left coordinates of the window's [safe area] in the screen space
|
|
|
|
|
/// coordinate system.
|
2019-12-31 14:39:33 -08:00
|
|
|
/// - **Web:** Returns the top-left coordinates relative to the viewport. _Note: this returns
|
2022-06-11 18:57:19 +02:00
|
|
|
/// the same value as [`Window::outer_position`]._
|
2020-07-26 21:13:17 +00:00
|
|
|
/// - **Android / Wayland:** Always returns [`NotSupportedError`].
|
2019-05-29 21:29:54 -04:00
|
|
|
///
|
|
|
|
|
/// [safe area]: https://developer.apple.com/documentation/uikit/uiview/2891103-safeareainsets?language=objc
|
2024-08-23 23:40:27 +03:00
|
|
|
fn inner_position(&self) -> Result<PhysicalPosition<i32>, NotSupportedError>;
|
2019-02-05 10:30:33 -05:00
|
|
|
|
2015-02-16 09:29:37 +01:00
|
|
|
/// Returns the position of the top-left hand corner of the window relative to the
|
2022-06-11 18:57:19 +02:00
|
|
|
/// top-left hand corner of the desktop.
|
2015-02-16 09:29:37 +01:00
|
|
|
///
|
2015-03-25 23:44:21 -04:00
|
|
|
/// Note that the top-left hand corner of the desktop is not necessarily the same as
|
2022-06-11 18:57:19 +02:00
|
|
|
/// the screen. If the user uses a desktop with multiple monitors, the top-left hand corner
|
|
|
|
|
/// of the desktop is the top-left hand corner of the monitor at the top-left of the desktop.
|
2015-02-16 09:29:37 +01:00
|
|
|
///
|
|
|
|
|
/// The coordinates can be negative if the top-left hand corner of the window is outside
|
2022-06-11 18:57:19 +02:00
|
|
|
/// of the visible screen region.
|
2015-02-16 09:29:37 +01:00
|
|
|
///
|
2019-05-25 18:10:41 -07:00
|
|
|
/// ## Platform-specific
|
|
|
|
|
///
|
2024-08-19 12:41:29 +02:00
|
|
|
/// - **iOS:** Returns the top left coordinates of the window in the screen space coordinate
|
|
|
|
|
/// system.
|
2019-12-31 14:39:33 -08:00
|
|
|
/// - **Web:** Returns the top-left coordinates relative to the viewport.
|
2020-07-26 21:13:17 +00:00
|
|
|
/// - **Android / Wayland:** Always returns [`NotSupportedError`].
|
2024-08-23 23:40:27 +03:00
|
|
|
fn outer_position(&self) -> Result<PhysicalPosition<i32>, NotSupportedError>;
|
2018-04-16 21:40:30 -04:00
|
|
|
|
2015-02-16 09:29:37 +01:00
|
|
|
/// Modifies the position of the window.
|
|
|
|
|
///
|
2022-06-11 18:57:19 +02:00
|
|
|
/// See [`Window::outer_position`] for more information about the coordinates.
|
|
|
|
|
/// This automatically un-maximizes the window if it's maximized.
|
2015-02-16 09:29:37 +01:00
|
|
|
///
|
2022-01-02 14:56:13 +11:00
|
|
|
/// ```no_run
|
|
|
|
|
/// # use winit::dpi::{LogicalPosition, PhysicalPosition};
|
|
|
|
|
/// # use winit::window::Window;
|
2024-08-23 23:40:27 +03:00
|
|
|
/// # fn scope(window: &dyn Window) {
|
2022-01-02 14:56:13 +11:00
|
|
|
/// // Specify the position in logical dimensions like this:
|
2024-08-23 23:40:27 +03:00
|
|
|
/// window.set_outer_position(LogicalPosition::new(400.0, 200.0).into());
|
2022-01-02 14:56:13 +11:00
|
|
|
///
|
|
|
|
|
/// // Or specify the position in physical dimensions like this:
|
2024-08-23 23:40:27 +03:00
|
|
|
/// window.set_outer_position(PhysicalPosition::new(400, 200).into());
|
2024-01-31 17:29:59 +04:00
|
|
|
/// # }
|
2022-01-02 14:56:13 +11:00
|
|
|
/// ```
|
|
|
|
|
///
|
2019-05-25 18:10:41 -07:00
|
|
|
/// ## Platform-specific
|
|
|
|
|
///
|
2024-08-19 12:41:29 +02:00
|
|
|
/// - **iOS:** Sets the top left coordinates of the window in the screen space coordinate
|
|
|
|
|
/// system.
|
2023-07-10 23:55:43 +02:00
|
|
|
/// - **Web:** Sets the top-left coordinates relative to the viewport. Doesn't account for CSS
|
|
|
|
|
/// [`transform`].
|
2020-07-26 21:13:17 +00:00
|
|
|
/// - **Android / Wayland:** Unsupported.
|
2023-07-10 23:55:43 +02:00
|
|
|
///
|
|
|
|
|
/// [`transform`]: https://developer.mozilla.org/en-US/docs/Web/CSS/transform
|
2024-08-23 23:40:27 +03:00
|
|
|
fn set_outer_position(&self, position: Position);
|
2015-02-16 09:29:37 +01:00
|
|
|
|
2024-09-04 15:04:48 +02:00
|
|
|
/// Returns the size of the window's render-able surface.
|
2015-07-25 13:57:52 +02:00
|
|
|
///
|
2024-09-04 15:04:48 +02:00
|
|
|
/// This is the dimensions you should pass to things like Wgpu or Glutin when configuring.
|
2015-02-16 09:29:37 +01:00
|
|
|
///
|
2019-05-25 18:10:41 -07:00
|
|
|
/// ## Platform-specific
|
|
|
|
|
///
|
2024-08-19 12:41:29 +02:00
|
|
|
/// - **iOS:** Returns the `PhysicalSize` of the window's [safe area] in screen space
|
|
|
|
|
/// coordinates.
|
2023-07-10 12:50:28 +02:00
|
|
|
/// - **Web:** Returns the size of the canvas element. Doesn't account for CSS [`transform`].
|
2019-05-25 18:10:41 -07:00
|
|
|
///
|
2019-05-29 21:29:54 -04:00
|
|
|
/// [safe area]: https://developer.apple.com/documentation/uikit/uiview/2891103-safeareainsets?language=objc
|
2023-07-10 12:50:28 +02:00
|
|
|
/// [`transform`]: https://developer.mozilla.org/en-US/docs/Web/CSS/transform
|
2024-09-04 15:04:48 +02:00
|
|
|
fn surface_size(&self) -> PhysicalSize<u32>;
|
2015-02-16 09:29:37 +01:00
|
|
|
|
2024-09-04 15:04:48 +02:00
|
|
|
/// Request the new size for the surface.
|
2023-07-10 04:02:26 +00:00
|
|
|
///
|
|
|
|
|
/// On platforms where the size is entirely controlled by the user the
|
|
|
|
|
/// applied size will be returned immediately, resize event in such case
|
|
|
|
|
/// may not be generated.
|
|
|
|
|
///
|
2024-09-04 15:04:48 +02:00
|
|
|
/// On platforms where resizing is disallowed by the windowing system, the current surface size
|
|
|
|
|
/// is returned immediately, and the user one is ignored.
|
2023-07-10 04:02:26 +00:00
|
|
|
///
|
|
|
|
|
/// When `None` is returned, it means that the request went to the display system,
|
2024-09-04 15:04:48 +02:00
|
|
|
/// and the actual size will be delivered later with the [`WindowEvent::SurfaceResized`].
|
2015-02-16 09:29:37 +01:00
|
|
|
///
|
2024-09-04 15:04:48 +02:00
|
|
|
/// See [`Window::surface_size`] for more information about the values.
|
2023-07-10 04:02:26 +00:00
|
|
|
///
|
|
|
|
|
/// The request could automatically un-maximize the window if it's maximized.
|
2019-05-25 18:10:41 -07:00
|
|
|
///
|
2022-01-02 14:56:13 +11:00
|
|
|
/// ```no_run
|
|
|
|
|
/// # use winit::dpi::{LogicalSize, PhysicalSize};
|
|
|
|
|
/// # use winit::window::Window;
|
2024-08-23 23:40:27 +03:00
|
|
|
/// # fn scope(window: &dyn Window) {
|
2022-01-02 14:56:13 +11:00
|
|
|
/// // Specify the size in logical dimensions like this:
|
2024-09-04 15:04:48 +02:00
|
|
|
/// let _ = window.request_surface_size(LogicalSize::new(400.0, 200.0).into());
|
2022-01-02 14:56:13 +11:00
|
|
|
///
|
|
|
|
|
/// // Or specify the size in physical dimensions like this:
|
2024-09-04 15:04:48 +02:00
|
|
|
/// let _ = window.request_surface_size(PhysicalSize::new(400, 200).into());
|
2024-01-31 17:29:59 +04:00
|
|
|
/// # }
|
2022-01-02 14:56:13 +11:00
|
|
|
/// ```
|
|
|
|
|
///
|
2019-05-25 18:10:41 -07:00
|
|
|
/// ## Platform-specific
|
|
|
|
|
///
|
2023-07-10 12:50:28 +02:00
|
|
|
/// - **Web:** Sets the size of the canvas element. Doesn't account for CSS [`transform`].
|
2023-07-10 04:02:26 +00:00
|
|
|
///
|
2024-09-04 15:04:48 +02:00
|
|
|
/// [`WindowEvent::SurfaceResized`]: crate::event::WindowEvent::SurfaceResized
|
2023-07-10 12:50:28 +02:00
|
|
|
/// [`transform`]: https://developer.mozilla.org/en-US/docs/Web/CSS/transform
|
2023-07-10 04:02:26 +00:00
|
|
|
#[must_use]
|
2024-09-04 15:04:48 +02:00
|
|
|
fn request_surface_size(&self, size: Size) -> Option<PhysicalSize<u32>>;
|
2015-02-16 09:29:37 +01:00
|
|
|
|
2024-09-04 15:04:48 +02:00
|
|
|
/// Returns the size of the entire window.
|
2019-05-29 21:29:54 -04:00
|
|
|
///
|
2024-09-04 15:04:48 +02:00
|
|
|
/// These dimensions include window decorations like the title bar and borders. If you don't
|
|
|
|
|
/// want that (and you usually don't), use [`Window::surface_size`] instead.
|
2019-05-25 18:10:41 -07:00
|
|
|
///
|
|
|
|
|
/// ## Platform-specific
|
|
|
|
|
///
|
2024-08-19 12:41:29 +02:00
|
|
|
/// - **iOS:** Returns the [`PhysicalSize`] of the window in screen space coordinates.
|
2019-12-31 14:39:33 -08:00
|
|
|
/// - **Web:** Returns the size of the canvas element. _Note: this returns the same value as
|
2024-09-04 15:04:48 +02:00
|
|
|
/// [`Window::surface_size`]._
|
2024-08-23 23:40:27 +03:00
|
|
|
fn outer_size(&self) -> PhysicalSize<u32>;
|
2018-03-23 05:35:35 -04:00
|
|
|
|
2024-09-04 15:04:48 +02:00
|
|
|
/// Sets a minimum dimensions of the window's surface.
|
2019-05-25 18:10:41 -07:00
|
|
|
///
|
2022-01-02 14:56:13 +11:00
|
|
|
/// ```no_run
|
|
|
|
|
/// # use winit::dpi::{LogicalSize, PhysicalSize};
|
|
|
|
|
/// # use winit::window::Window;
|
2024-08-23 23:40:27 +03:00
|
|
|
/// # fn scope(window: &dyn Window) {
|
2022-01-02 14:56:13 +11:00
|
|
|
/// // Specify the size in logical dimensions like this:
|
2024-09-04 15:04:48 +02:00
|
|
|
/// window.set_min_surface_size(Some(LogicalSize::new(400.0, 200.0).into()));
|
2022-01-02 14:56:13 +11:00
|
|
|
///
|
|
|
|
|
/// // Or specify the size in physical dimensions like this:
|
2024-09-04 15:04:48 +02:00
|
|
|
/// window.set_min_surface_size(Some(PhysicalSize::new(400, 200).into()));
|
2024-01-31 17:29:59 +04:00
|
|
|
/// # }
|
2022-01-02 14:56:13 +11:00
|
|
|
/// ```
|
|
|
|
|
///
|
2019-05-25 18:10:41 -07:00
|
|
|
/// ## Platform-specific
|
|
|
|
|
///
|
2023-07-11 13:14:40 +02:00
|
|
|
/// - **iOS / Android / Orbital:** Unsupported.
|
2024-09-04 15:04:48 +02:00
|
|
|
fn set_min_surface_size(&self, min_size: Option<Size>);
|
2018-03-23 05:35:35 -04:00
|
|
|
|
2024-09-04 15:04:48 +02:00
|
|
|
/// Sets a maximum dimensions of the window's surface.
|
2019-05-25 18:10:41 -07:00
|
|
|
///
|
2022-01-02 14:56:13 +11:00
|
|
|
/// ```no_run
|
|
|
|
|
/// # use winit::dpi::{LogicalSize, PhysicalSize};
|
|
|
|
|
/// # use winit::window::Window;
|
2024-08-23 23:40:27 +03:00
|
|
|
/// # fn scope(window: &dyn Window) {
|
2022-01-02 14:56:13 +11:00
|
|
|
/// // Specify the size in logical dimensions like this:
|
2024-09-04 15:04:48 +02:00
|
|
|
/// window.set_max_surface_size(Some(LogicalSize::new(400.0, 200.0).into()));
|
2022-01-02 14:56:13 +11:00
|
|
|
///
|
|
|
|
|
/// // Or specify the size in physical dimensions like this:
|
2024-09-04 15:04:48 +02:00
|
|
|
/// window.set_max_surface_size(Some(PhysicalSize::new(400, 200).into()));
|
2024-01-31 17:29:59 +04:00
|
|
|
/// # }
|
2022-01-02 14:56:13 +11:00
|
|
|
/// ```
|
|
|
|
|
///
|
2019-05-25 18:10:41 -07:00
|
|
|
/// ## Platform-specific
|
|
|
|
|
///
|
2023-07-11 13:14:40 +02:00
|
|
|
/// - **iOS / Android / Orbital:** Unsupported.
|
2024-09-04 15:04:48 +02:00
|
|
|
fn set_max_surface_size(&self, max_size: Option<Size>);
|
2022-09-03 21:50:22 +03:00
|
|
|
|
2024-09-04 15:04:48 +02:00
|
|
|
/// Returns surface resize increments if any were set.
|
2022-09-03 21:50:22 +03:00
|
|
|
///
|
|
|
|
|
/// ## Platform-specific
|
|
|
|
|
///
|
2024-04-21 13:05:41 +00:00
|
|
|
/// - **iOS / Android / Web / Wayland / Orbital:** Always returns [`None`].
|
2024-09-04 15:04:48 +02:00
|
|
|
fn surface_resize_increments(&self) -> Option<PhysicalSize<u32>>;
|
2022-09-03 21:50:22 +03:00
|
|
|
|
2024-09-04 15:04:48 +02:00
|
|
|
/// Sets resize increments of the surface.
|
2022-09-03 21:50:22 +03:00
|
|
|
///
|
2024-09-04 15:04:48 +02:00
|
|
|
/// This is a niche constraint hint usually employed by terminal emulators and other such apps
|
|
|
|
|
/// that need "blocky" resizes.
|
2022-09-03 21:50:22 +03:00
|
|
|
///
|
|
|
|
|
/// ## Platform-specific
|
|
|
|
|
///
|
|
|
|
|
/// - **macOS:** Increments are converted to logical size and then macOS rounds them to whole
|
|
|
|
|
/// numbers.
|
2024-04-21 13:05:41 +00:00
|
|
|
/// - **Wayland:** Not implemented.
|
2023-01-05 06:58:08 -07:00
|
|
|
/// - **iOS / Android / Web / Orbital:** Unsupported.
|
2024-09-04 15:04:48 +02:00
|
|
|
fn set_surface_resize_increments(&self, increments: Option<Size>);
|
2018-06-11 16:47:50 -06:00
|
|
|
|
2019-05-29 21:29:54 -04:00
|
|
|
/// Modifies the title of the window.
|
2018-07-16 16:44:29 +02:00
|
|
|
///
|
2018-06-14 19:42:18 -04:00
|
|
|
/// ## Platform-specific
|
|
|
|
|
///
|
2020-07-26 21:13:17 +00:00
|
|
|
/// - **iOS / Android:** Unsupported.
|
2024-08-23 23:40:27 +03:00
|
|
|
fn set_title(&self, title: &str);
|
2015-02-20 12:32:40 -08:00
|
|
|
|
2023-01-15 23:39:36 +03:00
|
|
|
/// Change the window transparency state.
|
|
|
|
|
///
|
|
|
|
|
/// This is just a hint that may not change anything about
|
2024-02-19 11:58:44 +07:00
|
|
|
/// the window transparency, however doing a mismatch between
|
2023-01-15 23:39:36 +03:00
|
|
|
/// the content of your window and this hint may result in
|
|
|
|
|
/// visual artifacts.
|
|
|
|
|
///
|
2024-01-31 17:29:59 +04:00
|
|
|
/// The default value follows the [`WindowAttributes::with_transparent`].
|
2023-01-15 23:39:36 +03:00
|
|
|
///
|
|
|
|
|
/// ## Platform-specific
|
|
|
|
|
///
|
2024-06-15 15:41:34 +03:00
|
|
|
/// - **macOS:** This will reset the window's background color.
|
2024-02-10 17:40:06 -07:00
|
|
|
/// - **Web / iOS / Android:** Unsupported.
|
2024-01-31 17:29:59 +04:00
|
|
|
/// - **X11:** Can only be set while building the window, with
|
|
|
|
|
/// [`WindowAttributes::with_transparent`].
|
2024-08-23 23:40:27 +03:00
|
|
|
fn set_transparent(&self, transparent: bool);
|
2023-01-15 23:39:36 +03:00
|
|
|
|
2023-10-08 22:53:15 +03:00
|
|
|
/// Change the window blur state.
|
|
|
|
|
///
|
|
|
|
|
/// If `true`, this will make the transparent window background blurry.
|
|
|
|
|
///
|
|
|
|
|
/// ## Platform-specific
|
|
|
|
|
///
|
2023-10-28 14:22:10 +04:00
|
|
|
/// - **Android / iOS / X11 / Web / Windows:** Unsupported.
|
2023-10-08 22:53:15 +03:00
|
|
|
/// - **Wayland:** Only works with org_kde_kwin_blur_manager protocol.
|
2024-08-23 23:40:27 +03:00
|
|
|
fn set_blur(&self, blur: bool);
|
2023-10-08 22:53:15 +03:00
|
|
|
|
2019-05-29 21:29:54 -04:00
|
|
|
/// Modifies the window's visibility.
|
2019-05-25 18:10:41 -07:00
|
|
|
///
|
2019-05-29 21:29:54 -04:00
|
|
|
/// If `false`, this will hide the window. If `true`, this will show the window.
|
2022-06-11 18:57:19 +02:00
|
|
|
///
|
2019-05-25 18:10:41 -07:00
|
|
|
/// ## Platform-specific
|
|
|
|
|
///
|
2020-07-26 21:13:17 +00:00
|
|
|
/// - **Android / Wayland / Web:** Unsupported.
|
2024-08-23 23:40:27 +03:00
|
|
|
fn set_visible(&self, visible: bool);
|
2015-02-16 09:29:37 +01:00
|
|
|
|
2022-07-15 14:02:12 -02:30
|
|
|
/// Gets the window's current visibility state.
|
2022-02-17 20:44:14 +02:00
|
|
|
///
|
2022-06-11 18:57:19 +02:00
|
|
|
/// `None` means it couldn't be determined, so it is not recommended to use this to drive your
|
|
|
|
|
/// rendering backend.
|
2022-02-17 20:44:14 +02:00
|
|
|
///
|
|
|
|
|
/// ## Platform-specific
|
|
|
|
|
///
|
|
|
|
|
/// - **X11:** Not implemented.
|
|
|
|
|
/// - **Wayland / iOS / Android / Web:** Unsupported.
|
2024-08-23 23:40:27 +03:00
|
|
|
fn is_visible(&self) -> Option<bool>;
|
2022-02-17 20:44:14 +02:00
|
|
|
|
2019-05-29 21:29:54 -04:00
|
|
|
/// Sets whether the window is resizable or not.
|
2019-05-25 18:10:41 -07:00
|
|
|
///
|
2022-06-11 18:57:19 +02:00
|
|
|
/// Note that making the window unresizable doesn't exempt you from handling
|
2024-09-04 15:04:48 +02:00
|
|
|
/// [`WindowEvent::SurfaceResized`], as that event can still be triggered by DPI scaling,
|
|
|
|
|
/// entering fullscreen mode, etc. Also, the window could still be resized by calling
|
|
|
|
|
/// [`Window::request_surface_size`].
|
2015-03-26 17:04:01 +01:00
|
|
|
///
|
2018-06-18 12:32:18 -04:00
|
|
|
/// ## Platform-specific
|
|
|
|
|
///
|
2019-05-29 21:29:54 -04:00
|
|
|
/// This only has an effect on desktop platforms.
|
|
|
|
|
///
|
2022-07-20 13:45:12 +02:00
|
|
|
/// - **X11:** Due to a bug in XFCE, this has no effect on Xfwm.
|
2020-07-26 21:13:17 +00:00
|
|
|
/// - **iOS / Android / Web:** Unsupported.
|
2022-06-11 18:57:19 +02:00
|
|
|
///
|
2024-09-04 15:04:48 +02:00
|
|
|
/// [`WindowEvent::SurfaceResized`]: crate::event::WindowEvent::SurfaceResized
|
2024-08-23 23:40:27 +03:00
|
|
|
fn set_resizable(&self, resizable: bool);
|
2017-01-28 15:05:36 +01:00
|
|
|
|
2022-02-17 17:03:17 +02:00
|
|
|
/// Gets the window's current resizable state.
|
|
|
|
|
///
|
|
|
|
|
/// ## Platform-specific
|
|
|
|
|
///
|
2022-04-07 03:05:11 +03:00
|
|
|
/// - **X11:** Not implemented.
|
2022-02-17 17:03:17 +02:00
|
|
|
/// - **iOS / Android / Web:** Unsupported.
|
2024-08-23 23:40:27 +03:00
|
|
|
fn is_resizable(&self) -> bool;
|
2022-02-17 17:03:17 +02:00
|
|
|
|
2022-11-29 12:03:51 +02:00
|
|
|
/// Sets the enabled window buttons.
|
|
|
|
|
///
|
|
|
|
|
/// ## Platform-specific
|
|
|
|
|
///
|
2023-01-05 06:58:08 -07:00
|
|
|
/// - **Wayland / X11 / Orbital:** Not implemented.
|
2022-11-29 12:03:51 +02:00
|
|
|
/// - **Web / iOS / Android:** Unsupported.
|
2024-08-23 23:40:27 +03:00
|
|
|
fn set_enabled_buttons(&self, buttons: WindowButtons);
|
2022-11-29 12:03:51 +02:00
|
|
|
|
|
|
|
|
/// Gets the enabled window buttons.
|
|
|
|
|
///
|
|
|
|
|
/// ## Platform-specific
|
|
|
|
|
///
|
2023-01-05 06:58:08 -07:00
|
|
|
/// - **Wayland / X11 / Orbital:** Not implemented. Always returns [`WindowButtons::all`].
|
2022-11-29 12:03:51 +02:00
|
|
|
/// - **Web / iOS / Android:** Unsupported. Always returns [`WindowButtons::all`].
|
2024-08-23 23:40:27 +03:00
|
|
|
fn enabled_buttons(&self) -> WindowButtons;
|
2022-11-29 12:03:51 +02:00
|
|
|
|
2019-12-22 01:04:11 -05:00
|
|
|
/// Sets the window to minimized or back
|
|
|
|
|
///
|
|
|
|
|
/// ## Platform-specific
|
|
|
|
|
///
|
2023-01-05 06:58:08 -07:00
|
|
|
/// - **iOS / Android / Web / Orbital:** Unsupported.
|
2020-07-26 21:13:17 +00:00
|
|
|
/// - **Wayland:** Un-minimize is unsupported.
|
2024-08-23 23:40:27 +03:00
|
|
|
fn set_minimized(&self, minimized: bool);
|
2019-12-22 01:04:11 -05:00
|
|
|
|
2023-01-19 23:39:04 +02:00
|
|
|
/// Gets the window's current minimized state.
|
|
|
|
|
///
|
|
|
|
|
/// `None` will be returned, if the minimized state couldn't be determined.
|
|
|
|
|
///
|
|
|
|
|
/// ## Note
|
|
|
|
|
///
|
|
|
|
|
/// - You shouldn't stop rendering for minimized windows, however you could lower the fps.
|
|
|
|
|
///
|
|
|
|
|
/// ## Platform-specific
|
|
|
|
|
///
|
|
|
|
|
/// - **Wayland**: always `None`.
|
|
|
|
|
/// - **iOS / Android / Web / Orbital:** Unsupported.
|
2024-08-23 23:40:27 +03:00
|
|
|
fn is_minimized(&self) -> Option<bool>;
|
2023-01-19 23:39:04 +02:00
|
|
|
|
2019-05-25 18:10:41 -07:00
|
|
|
/// Sets the window to maximized or back.
|
|
|
|
|
///
|
|
|
|
|
/// ## Platform-specific
|
2019-05-29 21:29:54 -04:00
|
|
|
///
|
2024-02-10 17:40:06 -07:00
|
|
|
/// - **iOS / Android / Web:** Unsupported.
|
2024-08-23 23:40:27 +03:00
|
|
|
fn set_maximized(&self, maximized: bool);
|
2017-08-28 00:19:26 +01:00
|
|
|
|
2021-01-27 20:01:17 +02:00
|
|
|
/// Gets the window's current maximized state.
|
|
|
|
|
///
|
|
|
|
|
/// ## Platform-specific
|
|
|
|
|
///
|
2024-02-10 17:40:06 -07:00
|
|
|
/// - **iOS / Android / Web:** Unsupported.
|
2024-08-23 23:40:27 +03:00
|
|
|
fn is_maximized(&self) -> bool;
|
2021-01-27 20:01:17 +02:00
|
|
|
|
2019-05-25 18:10:41 -07:00
|
|
|
/// Sets the window to fullscreen or back.
|
|
|
|
|
///
|
|
|
|
|
/// ## Platform-specific
|
2019-05-29 21:29:54 -04:00
|
|
|
///
|
2022-06-11 18:57:19 +02:00
|
|
|
/// - **macOS:** [`Fullscreen::Exclusive`] provides true exclusive mode with a video mode
|
2019-07-29 21:16:14 +03:00
|
|
|
/// change. *Caveat!* macOS doesn't provide task switching (or spaces!) while in exclusive
|
|
|
|
|
/// fullscreen mode. This mode should be used when a video mode change is desired, but for a
|
|
|
|
|
/// better user experience, borderless fullscreen might be preferred.
|
|
|
|
|
///
|
2022-06-11 18:57:19 +02:00
|
|
|
/// [`Fullscreen::Borderless`] provides a borderless fullscreen window on a
|
2019-07-29 21:16:14 +03:00
|
|
|
/// separate space. This is the idiomatic way for fullscreen games to work
|
2019-11-11 18:05:59 -05:00
|
|
|
/// on macOS. See `WindowExtMacOs::set_simple_fullscreen` if
|
2019-07-29 21:16:14 +03:00
|
|
|
/// separate spaces are not preferred.
|
|
|
|
|
///
|
2022-06-11 18:57:19 +02:00
|
|
|
/// The dock and the menu bar are disabled in exclusive fullscreen mode.
|
Update SCTK to 0.11.0
* Update SCTK to 0.11.0
Updates smithay-client-toolkit to 0.11.0. The major highlight
of that updated, is update of wayland-rs to 0.27.0. Switching
to wayland-cursor, instead of using libwayland-cursor. It
also fixes the following bugs:
- Disabled repeat rate not being handled.
- Decoration buttons not working after tty switch.
- Scaling not being applied on output reenable.
- Crash when `XCURSOR_SIZE` is `0`.
- Pointer getting created in some cases without pointer capability.
- On kwin, fix space between window and decorations on startup.
- Incorrect size event when entering fullscreen when using
client side decorations.
- Client side decorations not being hided properly in fullscreen.
- Size tracking between fullscreen/tiled state changes.
- Repeat rate triggering multiple times from slow callback handler.
- Resizable attribute not being applied properly on startup.
- Not working IME
Besides those fixes it also adds a bunch of missing virtual key codes,
implements proper cursor grabbing, adds right click on decorations
to open application menu, disabled maximize button for non-resizeable
window, and fall back for cursor icon to similar ones, if the requested
is missing.
It also adds new methods to a `Theme` trait, such as:
- `title_font(&self) -> Option<(String, f32)>` - The font for a title.
- `title_color(&self, window_active: bool) -> [u8; 4]` - The color of
the text in the title.
Fixes #1680.
Fixes #1678.
Fixes #1676.
Fixes #1646.
Fixes #1614.
Fixes #1601.
Fixes #1533.
Fixes #1509.
Fixes #952.
Fixes #947.
2020-09-29 00:11:43 +03:00
|
|
|
/// - **Wayland:** Does not support exclusive fullscreen mode and will no-op a request.
|
2019-07-29 11:18:23 +02:00
|
|
|
/// - **Windows:** Screen saver is disabled in fullscreen mode.
|
2023-01-05 06:58:08 -07:00
|
|
|
/// - **Android / Orbital:** Unsupported.
|
2024-07-23 20:33:10 +02:00
|
|
|
/// - **Web:** Passing a [`MonitorHandle`] or [`VideoModeHandle`] that was not created with
|
|
|
|
|
#[cfg_attr(
|
|
|
|
|
any(web_platform, docsrs),
|
|
|
|
|
doc = " [detailed monitor permissions][crate::platform::web::ActiveEventLoopExtWeb::request_detailed_monitor_permission]"
|
|
|
|
|
)]
|
|
|
|
|
#[cfg_attr(not(any(web_platform, docsrs)), doc = " detailed monitor permissions")]
|
|
|
|
|
/// or calling without a [transient activation] does nothing.
|
2023-03-26 17:19:26 +02:00
|
|
|
///
|
|
|
|
|
/// [transient activation]: https://developer.mozilla.org/en-US/docs/Glossary/Transient_activation
|
2024-08-23 23:40:27 +03:00
|
|
|
fn set_fullscreen(&self, fullscreen: Option<Fullscreen>);
|
2017-09-07 09:33:46 +01:00
|
|
|
|
2019-04-26 03:09:32 +10:00
|
|
|
/// Gets the window's current fullscreen state.
|
2019-05-25 18:10:41 -07:00
|
|
|
///
|
|
|
|
|
/// ## Platform-specific
|
2019-05-29 21:29:54 -04:00
|
|
|
///
|
2023-01-05 06:58:08 -07:00
|
|
|
/// - **Android / Orbital:** Will always return `None`.
|
2020-09-22 04:54:47 +03:00
|
|
|
/// - **Wayland:** Can return `Borderless(None)` when there are no monitors.
|
2024-08-23 23:40:27 +03:00
|
|
|
/// - **Web:** Can only return `None` or `Borderless(None)`.
|
|
|
|
|
fn fullscreen(&self) -> Option<Fullscreen>;
|
2019-04-26 03:09:32 +10:00
|
|
|
|
2017-12-22 07:50:46 -05:00
|
|
|
/// Turn window decorations on or off.
|
2019-05-25 18:10:41 -07:00
|
|
|
///
|
2023-01-28 07:50:34 +00:00
|
|
|
/// Enable/disable window decorations provided by the server or Winit.
|
|
|
|
|
/// By default this is enabled. Note that fullscreen windows and windows on
|
2024-07-10 16:17:39 +02:00
|
|
|
/// mobile and Web platforms naturally do not have decorations.
|
2023-01-28 07:50:34 +00:00
|
|
|
///
|
2019-05-25 18:10:41 -07:00
|
|
|
/// ## Platform-specific
|
2020-07-26 21:13:17 +00:00
|
|
|
///
|
2023-01-28 07:50:34 +00:00
|
|
|
/// - **iOS / Android / Web:** No effect.
|
2024-08-23 23:40:27 +03:00
|
|
|
fn set_decorations(&self, decorations: bool);
|
2017-12-22 07:50:46 -05:00
|
|
|
|
2022-02-17 15:31:13 +02:00
|
|
|
/// Gets the window's current decorations state.
|
|
|
|
|
///
|
2023-01-28 07:50:34 +00:00
|
|
|
/// Returns `true` when windows are decorated (server-side or by Winit).
|
2024-07-10 16:17:39 +02:00
|
|
|
/// Also returns `true` when no decorations are required (mobile, Web).
|
2023-01-28 07:50:34 +00:00
|
|
|
///
|
2022-02-17 15:31:13 +02:00
|
|
|
/// ## Platform-specific
|
|
|
|
|
///
|
2023-01-28 07:50:34 +00:00
|
|
|
/// - **iOS / Android / Web:** Always returns `true`.
|
2024-08-23 23:40:27 +03:00
|
|
|
fn is_decorated(&self) -> bool;
|
2022-02-17 15:31:13 +02:00
|
|
|
|
2022-11-26 03:50:58 +02:00
|
|
|
/// Change the window level.
|
2019-05-25 18:10:41 -07:00
|
|
|
///
|
2022-11-26 03:50:58 +02:00
|
|
|
/// This is just a hint to the OS, and the system could ignore it.
|
2019-05-29 21:29:54 -04:00
|
|
|
///
|
2022-11-26 03:50:58 +02:00
|
|
|
/// See [`WindowLevel`] for details.
|
2024-08-23 23:40:27 +03:00
|
|
|
fn set_window_level(&self, level: WindowLevel);
|
2018-05-20 10:24:05 -04:00
|
|
|
|
2022-06-11 18:57:19 +02:00
|
|
|
/// Sets the window icon.
|
|
|
|
|
///
|
|
|
|
|
/// On Windows and X11, this is typically the small icon in the top-left
|
2018-05-07 17:36:21 -04:00
|
|
|
/// corner of the titlebar.
|
|
|
|
|
///
|
|
|
|
|
/// ## Platform-specific
|
|
|
|
|
///
|
2023-01-05 06:58:08 -07:00
|
|
|
/// - **iOS / Android / Web / Wayland / macOS / Orbital:** Unsupported.
|
2019-10-16 12:18:02 -04:00
|
|
|
///
|
2022-06-11 18:57:19 +02:00
|
|
|
/// - **Windows:** Sets `ICON_SMALL`. The base size for a window icon is 16x16, but it's
|
|
|
|
|
/// recommended to account for screen scaling and pick a multiple of that, i.e. 32x32.
|
2019-10-16 12:18:02 -04:00
|
|
|
///
|
2022-06-11 18:57:19 +02:00
|
|
|
/// - **X11:** Has no universal guidelines for icon sizes, so you're at the whims of the WM.
|
|
|
|
|
/// That said, it's usually in the same ballpark as on Windows.
|
2024-08-23 23:40:27 +03:00
|
|
|
fn set_window_icon(&self, window_icon: Option<Icon>);
|
2018-05-07 17:36:21 -04:00
|
|
|
|
2023-06-22 19:12:14 +00:00
|
|
|
/// Set the IME cursor editing area, where the `position` is the top left corner of that area
|
|
|
|
|
/// and `size` is the size of this area starting from the position. An example of such area
|
|
|
|
|
/// could be a input field in the UI or line in the editor.
|
2019-05-25 18:10:41 -07:00
|
|
|
///
|
2023-06-22 19:12:14 +00:00
|
|
|
/// The windowing system could place a candidate box close to that area, but try to not obscure
|
|
|
|
|
/// the specified area, so the user input to it stays visible.
|
|
|
|
|
///
|
|
|
|
|
/// The candidate box is the window / popup / overlay that allows you to select the desired
|
|
|
|
|
/// characters. The look of this box may differ between input devices, even on the same
|
|
|
|
|
/// platform.
|
2022-05-07 05:29:25 +03:00
|
|
|
///
|
|
|
|
|
/// (Apple's official term is "candidate window", see their [chinese] and [japanese] guides).
|
|
|
|
|
///
|
|
|
|
|
/// ## Example
|
|
|
|
|
///
|
2022-01-02 14:56:13 +11:00
|
|
|
/// ```no_run
|
2023-06-22 19:12:14 +00:00
|
|
|
/// # use winit::dpi::{LogicalPosition, PhysicalPosition, LogicalSize, PhysicalSize};
|
2022-01-02 14:56:13 +11:00
|
|
|
/// # use winit::window::Window;
|
2024-08-23 23:40:27 +03:00
|
|
|
/// # fn scope(window: &dyn Window) {
|
2022-01-02 14:56:13 +11:00
|
|
|
/// // Specify the position in logical dimensions like this:
|
2024-08-23 23:40:27 +03:00
|
|
|
/// window.set_ime_cursor_area(
|
|
|
|
|
/// LogicalPosition::new(400.0, 200.0).into(),
|
|
|
|
|
/// LogicalSize::new(100, 100).into(),
|
|
|
|
|
/// );
|
2022-01-02 14:56:13 +11:00
|
|
|
///
|
|
|
|
|
/// // Or specify the position in physical dimensions like this:
|
2024-08-23 23:40:27 +03:00
|
|
|
/// window.set_ime_cursor_area(
|
|
|
|
|
/// PhysicalPosition::new(400, 200).into(),
|
|
|
|
|
/// PhysicalSize::new(100, 100).into(),
|
|
|
|
|
/// );
|
2024-01-31 17:29:59 +04:00
|
|
|
/// # }
|
2022-01-02 14:56:13 +11:00
|
|
|
/// ```
|
|
|
|
|
///
|
2019-05-25 18:10:41 -07:00
|
|
|
/// ## Platform-specific
|
|
|
|
|
///
|
2023-06-22 19:12:14 +00:00
|
|
|
/// - **X11:** - area is not supported, only position.
|
2023-01-05 06:58:08 -07:00
|
|
|
/// - **iOS / Android / Web / Orbital:** Unsupported.
|
2022-05-07 05:29:25 +03:00
|
|
|
///
|
|
|
|
|
/// [chinese]: https://support.apple.com/guide/chinese-input-method/use-the-candidate-window-cim12992/104/mac/12.0
|
|
|
|
|
/// [japanese]: https://support.apple.com/guide/japanese-input-method/use-the-candidate-window-jpim10262/6.3/mac/12.0
|
2024-08-23 23:40:27 +03:00
|
|
|
fn set_ime_cursor_area(&self, position: Position, size: Size);
|
2020-11-27 03:03:08 +01:00
|
|
|
|
2022-05-07 05:29:25 +03:00
|
|
|
/// Sets whether the window should get IME events
|
|
|
|
|
///
|
|
|
|
|
/// When IME is allowed, the window will receive [`Ime`] events, and during the
|
2023-05-28 20:02:59 +02:00
|
|
|
/// preedit phase the window will NOT get [`KeyboardInput`] events. The window
|
|
|
|
|
/// should allow IME while it is expecting text input.
|
2022-05-07 05:29:25 +03:00
|
|
|
///
|
|
|
|
|
/// When IME is not allowed, the window won't receive [`Ime`] events, and will
|
2023-05-28 20:02:59 +02:00
|
|
|
/// receive [`KeyboardInput`] events for every keypress instead. Not allowing
|
|
|
|
|
/// IME is useful for games for example.
|
2022-05-07 05:29:25 +03:00
|
|
|
///
|
|
|
|
|
/// IME is **not** allowed by default.
|
|
|
|
|
///
|
|
|
|
|
/// ## Platform-specific
|
|
|
|
|
///
|
|
|
|
|
/// - **macOS:** IME must be enabled to receive text-input where dead-key sequences are
|
|
|
|
|
/// combined.
|
2024-08-19 22:04:29 +02:00
|
|
|
/// - **iOS:** This will show / hide the soft keyboard.
|
|
|
|
|
/// - **Android / Web / Orbital:** Unsupported.
|
2023-06-30 19:59:24 +04:00
|
|
|
/// - **X11**: Enabling IME will disable dead keys reporting during compose.
|
2022-05-07 05:29:25 +03:00
|
|
|
///
|
|
|
|
|
/// [`Ime`]: crate::event::WindowEvent::Ime
|
|
|
|
|
/// [`KeyboardInput`]: crate::event::WindowEvent::KeyboardInput
|
2024-08-23 23:40:27 +03:00
|
|
|
fn set_ime_allowed(&self, allowed: bool);
|
2022-05-07 05:29:25 +03:00
|
|
|
|
2023-01-29 16:46:46 +01:00
|
|
|
/// Sets the IME purpose for the window using [`ImePurpose`].
|
|
|
|
|
///
|
|
|
|
|
/// ## Platform-specific
|
|
|
|
|
///
|
|
|
|
|
/// - **iOS / Android / Web / Windows / X11 / macOS / Orbital:** Unsupported.
|
2024-08-23 23:40:27 +03:00
|
|
|
fn set_ime_purpose(&self, purpose: ImePurpose);
|
2023-01-29 16:46:46 +01:00
|
|
|
|
2021-05-19 18:39:53 +02:00
|
|
|
/// Brings the window to the front and sets input focus. Has no effect if the window is
|
|
|
|
|
/// already in focus, minimized, or not visible.
|
|
|
|
|
///
|
|
|
|
|
/// This method steals input focus from other applications. Do not use this method unless
|
|
|
|
|
/// you are certain that's what the user wants. Focus stealing can cause an extremely disruptive
|
|
|
|
|
/// user experience.
|
|
|
|
|
///
|
|
|
|
|
/// ## Platform-specific
|
|
|
|
|
///
|
2023-07-11 13:14:40 +02:00
|
|
|
/// - **iOS / Android / Wayland / Orbital:** Unsupported.
|
2024-08-23 23:40:27 +03:00
|
|
|
fn focus_window(&self);
|
2021-05-19 18:39:53 +02:00
|
|
|
|
2023-01-17 03:30:14 +02:00
|
|
|
/// Gets whether the window has keyboard focus.
|
|
|
|
|
///
|
|
|
|
|
/// This queries the same state information as [`WindowEvent::Focused`].
|
|
|
|
|
///
|
|
|
|
|
/// [`WindowEvent::Focused`]: crate::event::WindowEvent::Focused
|
2024-08-23 23:40:27 +03:00
|
|
|
fn has_focus(&self) -> bool;
|
2023-01-17 03:30:14 +02:00
|
|
|
|
2020-11-27 03:03:08 +01:00
|
|
|
/// Requests user attention to the window, this has no effect if the application
|
|
|
|
|
/// is already focused. How requesting for user attention manifests is platform dependent,
|
2022-06-11 18:57:19 +02:00
|
|
|
/// see [`UserAttentionType`] for details.
|
2020-11-27 03:03:08 +01:00
|
|
|
///
|
|
|
|
|
/// Providing `None` will unset the request for user attention. Unsetting the request for
|
|
|
|
|
/// user attention might not be done automatically by the WM when the window receives input.
|
|
|
|
|
///
|
|
|
|
|
/// ## Platform-specific
|
|
|
|
|
///
|
2023-01-05 06:58:08 -07:00
|
|
|
/// - **iOS / Android / Web / Orbital:** Unsupported.
|
2020-11-27 03:03:08 +01:00
|
|
|
/// - **macOS:** `None` has no effect.
|
|
|
|
|
/// - **X11:** Requests for user attention must be manually cleared.
|
2021-08-17 07:59:57 +03:00
|
|
|
/// - **Wayland:** Requires `xdg_activation_v1` protocol, `None` has no effect.
|
2024-08-23 23:40:27 +03:00
|
|
|
fn request_user_attention(&self, request_type: Option<UserAttentionType>);
|
2022-10-19 03:34:36 +09:00
|
|
|
|
2024-06-20 16:05:34 +02:00
|
|
|
/// Set or override the window theme.
|
|
|
|
|
///
|
|
|
|
|
/// Specify `None` to reset the theme to the system default.
|
2022-10-19 03:34:36 +09:00
|
|
|
///
|
|
|
|
|
/// ## Platform-specific
|
|
|
|
|
///
|
2023-10-10 09:23:37 +04:00
|
|
|
/// - **Wayland:** Sets the theme for the client side decorations. Using `None` will use dbus to
|
|
|
|
|
/// get the system preference.
|
2023-05-30 11:22:19 +02:00
|
|
|
/// - **X11:** Sets `_GTK_THEME_VARIANT` hint to `dark` or `light` and if `None` is used, it
|
|
|
|
|
/// will default to [`Theme::Dark`].
|
|
|
|
|
/// - **iOS / Android / Web / Orbital:** Unsupported.
|
2024-08-23 23:40:27 +03:00
|
|
|
fn set_theme(&self, theme: Option<Theme>);
|
2022-11-29 11:05:51 +02:00
|
|
|
|
2024-08-05 20:51:38 +02:00
|
|
|
/// Returns the current window theme.
|
2024-06-20 16:05:34 +02:00
|
|
|
///
|
2024-08-05 20:51:38 +02:00
|
|
|
/// Returns `None` if it cannot be determined on the current platform.
|
2022-11-29 11:05:51 +02:00
|
|
|
///
|
|
|
|
|
/// ## Platform-specific
|
|
|
|
|
///
|
2024-08-05 20:51:38 +02:00
|
|
|
/// - **iOS / Android / x11 / Orbital:** Unsupported.
|
|
|
|
|
/// - **Wayland:** Only returns theme overrides.
|
2024-08-23 23:40:27 +03:00
|
|
|
fn theme(&self) -> Option<Theme>;
|
2022-11-03 10:11:37 -07:00
|
|
|
|
2022-11-23 15:51:34 +02:00
|
|
|
/// Prevents the window contents from being captured by other apps.
|
|
|
|
|
///
|
|
|
|
|
/// ## Platform-specific
|
|
|
|
|
///
|
2024-07-25 15:15:21 +02:00
|
|
|
/// - **macOS**: if `false`, [`NSWindowSharingNone`] is used but doesn't completely prevent all
|
|
|
|
|
/// apps from reading the window content, for instance, QuickTime.
|
2023-01-05 06:58:08 -07:00
|
|
|
/// - **iOS / Android / x11 / Wayland / Web / Orbital:** Unsupported.
|
2022-11-23 15:51:34 +02:00
|
|
|
///
|
|
|
|
|
/// [`NSWindowSharingNone`]: https://developer.apple.com/documentation/appkit/nswindowsharingtype/nswindowsharingnone
|
2024-08-23 23:40:27 +03:00
|
|
|
fn set_content_protected(&self, protected: bool);
|
2022-11-23 15:51:34 +02:00
|
|
|
|
2022-11-03 10:11:37 -07:00
|
|
|
/// Gets the current title of the window.
|
|
|
|
|
///
|
|
|
|
|
/// ## Platform-specific
|
|
|
|
|
///
|
|
|
|
|
/// - **iOS / Android / x11 / Wayland / Web:** Unsupported. Always returns an empty string.
|
2024-08-23 23:40:27 +03:00
|
|
|
fn title(&self) -> String;
|
2018-05-17 21:28:30 -04:00
|
|
|
|
2019-05-29 21:29:54 -04:00
|
|
|
/// Modifies the cursor icon of the window.
|
2019-05-25 18:10:41 -07:00
|
|
|
///
|
|
|
|
|
/// ## Platform-specific
|
|
|
|
|
///
|
2023-01-05 06:58:08 -07:00
|
|
|
/// - **iOS / Android / Orbital:** Unsupported.
|
2023-12-25 07:20:52 +01:00
|
|
|
/// - **Web:** Custom cursors have to be loaded and decoded first, until then the previous
|
|
|
|
|
/// cursor is shown.
|
2024-08-23 23:40:27 +03:00
|
|
|
fn set_cursor(&self, cursor: Cursor);
|
2023-12-16 22:02:17 +02:00
|
|
|
|
2019-05-29 21:29:54 -04:00
|
|
|
/// Changes the position of the cursor in window coordinates.
|
2019-05-25 18:10:41 -07:00
|
|
|
///
|
2022-01-02 14:56:13 +11:00
|
|
|
/// ```no_run
|
|
|
|
|
/// # use winit::dpi::{LogicalPosition, PhysicalPosition};
|
|
|
|
|
/// # use winit::window::Window;
|
2024-08-23 23:40:27 +03:00
|
|
|
/// # fn scope(window: &dyn Window) {
|
2022-01-02 14:56:13 +11:00
|
|
|
/// // Specify the position in logical dimensions like this:
|
2024-08-23 23:40:27 +03:00
|
|
|
/// window.set_cursor_position(LogicalPosition::new(400.0, 200.0).into());
|
2022-01-02 14:56:13 +11:00
|
|
|
///
|
|
|
|
|
/// // Or specify the position in physical dimensions like this:
|
2024-08-23 23:40:27 +03:00
|
|
|
/// window.set_cursor_position(PhysicalPosition::new(400, 200).into());
|
2024-01-31 17:29:59 +04:00
|
|
|
/// # }
|
2022-01-02 14:56:13 +11:00
|
|
|
/// ```
|
|
|
|
|
///
|
2019-05-25 18:10:41 -07:00
|
|
|
/// ## Platform-specific
|
|
|
|
|
///
|
2024-02-24 23:15:38 +01:00
|
|
|
/// - **Wayland**: Cursor must be in [`CursorGrabMode::Locked`].
|
|
|
|
|
/// - **iOS / Android / Web / Orbital:** Always returns an [`ExternalError::NotSupported`].
|
2024-08-23 23:40:27 +03:00
|
|
|
fn set_cursor_position(&self, position: Position) -> Result<(), ExternalError>;
|
2018-06-16 10:14:12 -04:00
|
|
|
|
2024-03-16 10:22:29 +01:00
|
|
|
/// Set grabbing [mode][CursorGrabMode] on the cursor preventing it from leaving the window.
|
2019-05-25 18:10:41 -07:00
|
|
|
///
|
2022-06-13 09:43:14 +03:00
|
|
|
/// # Example
|
Update SCTK to 0.11.0
* Update SCTK to 0.11.0
Updates smithay-client-toolkit to 0.11.0. The major highlight
of that updated, is update of wayland-rs to 0.27.0. Switching
to wayland-cursor, instead of using libwayland-cursor. It
also fixes the following bugs:
- Disabled repeat rate not being handled.
- Decoration buttons not working after tty switch.
- Scaling not being applied on output reenable.
- Crash when `XCURSOR_SIZE` is `0`.
- Pointer getting created in some cases without pointer capability.
- On kwin, fix space between window and decorations on startup.
- Incorrect size event when entering fullscreen when using
client side decorations.
- Client side decorations not being hided properly in fullscreen.
- Size tracking between fullscreen/tiled state changes.
- Repeat rate triggering multiple times from slow callback handler.
- Resizable attribute not being applied properly on startup.
- Not working IME
Besides those fixes it also adds a bunch of missing virtual key codes,
implements proper cursor grabbing, adds right click on decorations
to open application menu, disabled maximize button for non-resizeable
window, and fall back for cursor icon to similar ones, if the requested
is missing.
It also adds new methods to a `Theme` trait, such as:
- `title_font(&self) -> Option<(String, f32)>` - The font for a title.
- `title_color(&self, window_active: bool) -> [u8; 4]` - The color of
the text in the title.
Fixes #1680.
Fixes #1678.
Fixes #1676.
Fixes #1646.
Fixes #1614.
Fixes #1601.
Fixes #1533.
Fixes #1509.
Fixes #952.
Fixes #947.
2020-09-29 00:11:43 +03:00
|
|
|
///
|
2022-06-13 09:43:14 +03:00
|
|
|
/// First try confining the cursor, and if that fails, try locking it instead.
|
2019-05-25 18:10:41 -07:00
|
|
|
///
|
2022-06-17 14:19:09 +02:00
|
|
|
/// ```no_run
|
2022-06-13 09:43:14 +03:00
|
|
|
/// # use winit::window::{CursorGrabMode, Window};
|
2024-08-23 23:40:27 +03:00
|
|
|
/// # fn scope(window: &dyn Window) {
|
2022-06-13 09:43:14 +03:00
|
|
|
/// window
|
|
|
|
|
/// .set_cursor_grab(CursorGrabMode::Confined)
|
|
|
|
|
/// .or_else(|_e| window.set_cursor_grab(CursorGrabMode::Locked))
|
|
|
|
|
/// .unwrap();
|
2024-01-31 17:29:59 +04:00
|
|
|
/// # }
|
2022-06-13 09:43:14 +03:00
|
|
|
/// ```
|
2024-08-23 23:40:27 +03:00
|
|
|
fn set_cursor_grab(&self, mode: CursorGrabMode) -> Result<(), ExternalError>;
|
2018-06-16 10:14:12 -04:00
|
|
|
|
2019-06-02 00:06:41 +00:00
|
|
|
/// Modifies the cursor's visibility.
|
|
|
|
|
///
|
|
|
|
|
/// If `false`, this will hide the cursor. If `true`, this will show the cursor.
|
2019-05-29 21:29:54 -04:00
|
|
|
///
|
|
|
|
|
/// ## Platform-specific
|
|
|
|
|
///
|
|
|
|
|
/// - **Windows:** The cursor is only hidden within the confines of the window.
|
|
|
|
|
/// - **X11:** The cursor is only hidden within the confines of the window.
|
2019-10-02 03:25:59 +02:00
|
|
|
/// - **Wayland:** The cursor is only hidden within the confines of the window.
|
2019-05-29 21:29:54 -04:00
|
|
|
/// - **macOS:** The cursor is hidden as long as the window has input focus, even if the cursor
|
|
|
|
|
/// is outside of the window.
|
2024-02-10 17:40:06 -07:00
|
|
|
/// - **iOS / Android:** Unsupported.
|
2024-08-23 23:40:27 +03:00
|
|
|
fn set_cursor_visible(&self, visible: bool);
|
2021-03-07 10:43:23 +01:00
|
|
|
|
|
|
|
|
/// Moves the window with the left mouse button until the button is released.
|
|
|
|
|
///
|
|
|
|
|
/// There's no guarantee that this will work unless the left mouse button was pressed
|
|
|
|
|
/// immediately before this function is called.
|
|
|
|
|
///
|
|
|
|
|
/// ## Platform-specific
|
|
|
|
|
///
|
|
|
|
|
/// - **X11:** Un-grabs the cursor.
|
|
|
|
|
/// - **Wayland:** Requires the cursor to be inside the window to be dragged.
|
|
|
|
|
/// - **macOS:** May prevent the button release event to be triggered.
|
2024-02-10 17:40:06 -07:00
|
|
|
/// - **iOS / Android / Web:** Always returns an [`ExternalError::NotSupported`].
|
2024-08-23 23:40:27 +03:00
|
|
|
fn drag_window(&self) -> Result<(), ExternalError>;
|
2022-04-12 19:10:46 +02:00
|
|
|
|
2023-01-11 18:07:09 +01:00
|
|
|
/// Resizes the window with the left mouse button until the button is released.
|
|
|
|
|
///
|
|
|
|
|
/// There's no guarantee that this will work unless the left mouse button was pressed
|
|
|
|
|
/// immediately before this function is called.
|
|
|
|
|
///
|
|
|
|
|
/// ## Platform-specific
|
|
|
|
|
///
|
2023-07-21 20:01:56 +02:00
|
|
|
/// - **macOS:** Always returns an [`ExternalError::NotSupported`]
|
2024-02-10 17:40:06 -07:00
|
|
|
/// - **iOS / Android / Web:** Always returns an [`ExternalError::NotSupported`].
|
2024-08-23 23:40:27 +03:00
|
|
|
fn drag_resize_window(&self, direction: ResizeDirection) -> Result<(), ExternalError>;
|
2023-01-11 18:07:09 +01:00
|
|
|
|
2023-10-11 01:16:16 +03:30
|
|
|
/// Show [window menu] at a specified position .
|
|
|
|
|
///
|
|
|
|
|
/// This is the context menu that is normally shown when interacting with
|
|
|
|
|
/// the title bar. This is useful when implementing custom decorations.
|
|
|
|
|
///
|
|
|
|
|
/// ## Platform-specific
|
|
|
|
|
/// **Android / iOS / macOS / Orbital / Wayland / Web / X11:** Unsupported.
|
|
|
|
|
///
|
|
|
|
|
/// [window menu]: https://en.wikipedia.org/wiki/Common_menus_in_Microsoft_Windows#System_menu
|
2024-08-23 23:40:27 +03:00
|
|
|
fn show_window_menu(&self, position: Position);
|
2023-10-11 01:16:16 +03:30
|
|
|
|
2022-04-12 19:10:46 +02:00
|
|
|
/// Modifies whether the window catches cursor events.
|
|
|
|
|
///
|
|
|
|
|
/// If `true`, the window will catch the cursor events. If `false`, events are passed through
|
|
|
|
|
/// the window such that any other window behind it receives them. By default hittest is
|
|
|
|
|
/// enabled.
|
|
|
|
|
///
|
|
|
|
|
/// ## Platform-specific
|
|
|
|
|
///
|
2023-10-13 20:42:07 -07:00
|
|
|
/// - **iOS / Android / Web / Orbital:** Always returns an [`ExternalError::NotSupported`].
|
2024-08-23 23:40:27 +03:00
|
|
|
fn set_cursor_hittest(&self, hittest: bool) -> Result<(), ExternalError>;
|
2015-02-16 09:29:37 +01:00
|
|
|
|
2020-09-07 20:09:24 +03:00
|
|
|
/// Returns the monitor on which the window currently resides.
|
|
|
|
|
///
|
|
|
|
|
/// Returns `None` if current monitor can't be detected.
|
2024-08-23 23:40:27 +03:00
|
|
|
fn current_monitor(&self) -> Option<MonitorHandle>;
|
2015-02-16 09:29:37 +01:00
|
|
|
|
2019-05-29 21:29:54 -04:00
|
|
|
/// Returns the list of all the monitors available on the system.
|
|
|
|
|
///
|
2024-01-31 17:29:59 +04:00
|
|
|
/// This is the same as [`ActiveEventLoop::available_monitors`], and is provided for
|
|
|
|
|
/// convenience.
|
2019-05-29 21:29:54 -04:00
|
|
|
///
|
2024-07-23 20:33:10 +02:00
|
|
|
///
|
|
|
|
|
/// ## Platform-specific
|
|
|
|
|
///
|
|
|
|
|
/// **Web:** Only returns the current monitor without
|
|
|
|
|
#[cfg_attr(
|
|
|
|
|
any(web_platform, docsrs),
|
|
|
|
|
doc = "[detailed monitor permissions][crate::platform::web::ActiveEventLoopExtWeb::request_detailed_monitor_permission]."
|
|
|
|
|
)]
|
|
|
|
|
#[cfg_attr(not(any(web_platform, docsrs)), doc = "detailed monitor permissions.")]
|
|
|
|
|
///
|
|
|
|
|
#[rustfmt::skip]
|
2024-01-31 17:29:59 +04:00
|
|
|
/// [`ActiveEventLoop::available_monitors`]: crate::event_loop::ActiveEventLoop::available_monitors
|
2024-08-23 23:40:27 +03:00
|
|
|
fn available_monitors(&self) -> Box<dyn Iterator<Item = MonitorHandle>>;
|
2015-03-16 13:52:58 -07:00
|
|
|
|
2019-05-29 21:29:54 -04:00
|
|
|
/// Returns the primary monitor of the system.
|
|
|
|
|
///
|
2020-09-07 20:20:47 +03:00
|
|
|
/// Returns `None` if it can't identify any monitor as a primary one.
|
|
|
|
|
///
|
2024-01-31 17:29:59 +04:00
|
|
|
/// This is the same as [`ActiveEventLoop::primary_monitor`], and is provided for convenience.
|
2019-05-29 21:29:54 -04:00
|
|
|
///
|
|
|
|
|
/// ## Platform-specific
|
|
|
|
|
///
|
2024-07-23 20:33:10 +02:00
|
|
|
/// - **Wayland:** Always returns `None`.
|
|
|
|
|
/// - **Web:** Always returns `None` without
|
|
|
|
|
#[cfg_attr(
|
|
|
|
|
any(web_platform, docsrs),
|
|
|
|
|
doc = " [detailed monitor permissions][crate::platform::web::ActiveEventLoopExtWeb::request_detailed_monitor_permission]."
|
|
|
|
|
)]
|
|
|
|
|
#[cfg_attr(not(any(web_platform, docsrs)), doc = " detailed monitor permissions.")]
|
2022-06-11 18:57:19 +02:00
|
|
|
///
|
2024-07-23 20:33:10 +02:00
|
|
|
#[rustfmt::skip]
|
2024-01-31 17:29:59 +04:00
|
|
|
/// [`ActiveEventLoop::primary_monitor`]: crate::event_loop::ActiveEventLoop::primary_monitor
|
2024-08-23 23:40:27 +03:00
|
|
|
fn primary_monitor(&self) -> Option<MonitorHandle>;
|
|
|
|
|
|
|
|
|
|
/// Get the raw-window-handle v0.6 display handle.
|
|
|
|
|
#[cfg(feature = "rwh_06")]
|
|
|
|
|
fn rwh_06_display_handle(&self) -> &dyn rwh_06::HasDisplayHandle;
|
|
|
|
|
|
|
|
|
|
/// Get the raw-window-handle v0.6 window handle.
|
|
|
|
|
#[cfg(feature = "rwh_06")]
|
|
|
|
|
fn rwh_06_window_handle(&self) -> &dyn rwh_06::HasWindowHandle;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl dyn Window {
|
|
|
|
|
/// Create a new [`WindowAttributes`] which allows modifying the window's attributes before
|
|
|
|
|
/// creation.
|
|
|
|
|
pub fn default_attributes() -> WindowAttributes {
|
|
|
|
|
WindowAttributes::default()
|
2015-02-16 09:29:37 +01:00
|
|
|
}
|
2019-02-05 10:30:33 -05:00
|
|
|
}
|
2023-08-14 21:19:57 +02:00
|
|
|
|
2024-08-23 23:40:27 +03:00
|
|
|
impl PartialEq for dyn Window + '_ {
|
|
|
|
|
fn eq(&self, other: &dyn Window) -> bool {
|
|
|
|
|
self.id().eq(&other.id())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Eq for dyn Window + '_ {}
|
2023-10-14 19:07:39 -07:00
|
|
|
|
2024-08-23 23:40:27 +03:00
|
|
|
impl std::hash::Hash for dyn Window + '_ {
|
|
|
|
|
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
|
|
|
|
|
self.id().hash(state);
|
2023-10-14 19:07:39 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[cfg(feature = "rwh_06")]
|
2024-08-23 23:40:27 +03:00
|
|
|
impl rwh_06::HasDisplayHandle for dyn Window + '_ {
|
2023-10-14 19:07:39 -07:00
|
|
|
fn display_handle(&self) -> Result<rwh_06::DisplayHandle<'_>, rwh_06::HandleError> {
|
2024-08-23 23:40:27 +03:00
|
|
|
self.rwh_06_display_handle().display_handle()
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-10-14 19:07:39 -07:00
|
|
|
|
2024-08-23 23:40:27 +03:00
|
|
|
#[cfg(feature = "rwh_06")]
|
|
|
|
|
impl rwh_06::HasWindowHandle for dyn Window + '_ {
|
|
|
|
|
fn window_handle(&self) -> Result<rwh_06::WindowHandle<'_>, rwh_06::HandleError> {
|
|
|
|
|
self.rwh_06_window_handle().window_handle()
|
2023-10-14 19:07:39 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-13 09:43:14 +03:00
|
|
|
/// The behavior of cursor grabbing.
|
|
|
|
|
///
|
|
|
|
|
/// Use this enum with [`Window::set_cursor_grab`] to grab the cursor.
|
|
|
|
|
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
|
|
|
|
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
|
|
|
|
pub enum CursorGrabMode {
|
|
|
|
|
/// No grabbing of the cursor is performed.
|
|
|
|
|
None,
|
|
|
|
|
|
|
|
|
|
/// The cursor is confined to the window area.
|
|
|
|
|
///
|
|
|
|
|
/// There's no guarantee that the cursor will be hidden. You should hide it by yourself if you
|
|
|
|
|
/// want to do so.
|
|
|
|
|
///
|
|
|
|
|
/// ## Platform-specific
|
|
|
|
|
///
|
|
|
|
|
/// - **macOS:** Not implemented. Always returns [`ExternalError::NotSupported`] for now.
|
2024-02-10 17:40:06 -07:00
|
|
|
/// - **iOS / Android / Web:** Always returns an [`ExternalError::NotSupported`].
|
2022-06-13 09:43:14 +03:00
|
|
|
Confined,
|
|
|
|
|
|
|
|
|
|
/// The cursor is locked inside the window area to the certain position.
|
|
|
|
|
///
|
|
|
|
|
/// There's no guarantee that the cursor will be hidden. You should hide it by yourself if you
|
|
|
|
|
/// want to do so.
|
|
|
|
|
///
|
|
|
|
|
/// ## Platform-specific
|
|
|
|
|
///
|
|
|
|
|
/// - **X11 / Windows:** Not implemented. Always returns [`ExternalError::NotSupported`] for
|
|
|
|
|
/// now.
|
2024-02-10 17:40:06 -07:00
|
|
|
/// - **iOS / Android:** Always returns an [`ExternalError::NotSupported`].
|
2022-06-13 09:43:14 +03:00
|
|
|
Locked,
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-11 18:07:09 +01:00
|
|
|
/// Defines the orientation that a window resize will be performed.
|
|
|
|
|
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
|
2024-08-08 00:46:28 +02:00
|
|
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
2023-01-11 18:07:09 +01:00
|
|
|
pub enum ResizeDirection {
|
|
|
|
|
East,
|
|
|
|
|
North,
|
|
|
|
|
NorthEast,
|
|
|
|
|
NorthWest,
|
|
|
|
|
South,
|
|
|
|
|
SouthEast,
|
|
|
|
|
SouthWest,
|
|
|
|
|
West,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl From<ResizeDirection> for CursorIcon {
|
|
|
|
|
fn from(direction: ResizeDirection) -> Self {
|
|
|
|
|
use ResizeDirection::*;
|
|
|
|
|
match direction {
|
|
|
|
|
East => CursorIcon::EResize,
|
|
|
|
|
North => CursorIcon::NResize,
|
|
|
|
|
NorthEast => CursorIcon::NeResize,
|
|
|
|
|
NorthWest => CursorIcon::NwResize,
|
|
|
|
|
South => CursorIcon::SResize,
|
|
|
|
|
SouthEast => CursorIcon::SeResize,
|
|
|
|
|
SouthWest => CursorIcon::SwResize,
|
|
|
|
|
West => CursorIcon::WResize,
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-02-16 09:29:37 +01:00
|
|
|
}
|
2019-07-29 21:16:14 +03:00
|
|
|
|
2020-09-22 04:54:47 +03:00
|
|
|
/// Fullscreen modes.
|
2024-08-08 00:46:28 +02:00
|
|
|
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
|
2019-07-29 21:16:14 +03:00
|
|
|
pub enum Fullscreen {
|
2023-12-26 22:12:33 +01:00
|
|
|
Exclusive(VideoModeHandle),
|
2020-09-22 04:54:47 +03:00
|
|
|
|
|
|
|
|
/// Providing `None` to `Borderless` will fullscreen on the current monitor.
|
|
|
|
|
Borderless(Option<MonitorHandle>),
|
2019-07-29 21:16:14 +03:00
|
|
|
}
|
2019-12-22 19:04:09 +00:00
|
|
|
|
2023-01-31 12:14:15 +03:00
|
|
|
/// The theme variant to use.
|
2024-08-08 00:46:28 +02:00
|
|
|
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
2023-01-31 12:14:15 +03:00
|
|
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
2019-12-22 19:04:09 +00:00
|
|
|
pub enum Theme {
|
2023-01-31 12:14:15 +03:00
|
|
|
/// Use the light variant.
|
2019-12-22 19:04:09 +00:00
|
|
|
Light,
|
2023-01-31 12:14:15 +03:00
|
|
|
|
|
|
|
|
/// Use the dark variant.
|
2019-12-22 19:04:09 +00:00
|
|
|
Dark,
|
|
|
|
|
}
|
2020-11-27 03:03:08 +01:00
|
|
|
|
|
|
|
|
/// ## Platform-specific
|
|
|
|
|
///
|
2022-06-11 18:57:19 +02:00
|
|
|
/// - **X11:** Sets the WM's `XUrgencyHint`. No distinction between [`Critical`] and
|
|
|
|
|
/// [`Informational`].
|
|
|
|
|
///
|
|
|
|
|
/// [`Critical`]: Self::Critical
|
|
|
|
|
/// [`Informational`]: Self::Informational
|
2024-08-08 00:46:28 +02:00
|
|
|
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash)]
|
|
|
|
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
2020-11-27 03:03:08 +01:00
|
|
|
pub enum UserAttentionType {
|
|
|
|
|
/// ## Platform-specific
|
2022-07-20 13:45:12 +02:00
|
|
|
///
|
2020-11-27 03:03:08 +01:00
|
|
|
/// - **macOS:** Bounces the dock icon until the application is in focus.
|
|
|
|
|
/// - **Windows:** Flashes both the window and the taskbar button until the application is in
|
|
|
|
|
/// focus.
|
|
|
|
|
Critical,
|
2023-03-12 18:02:49 +01:00
|
|
|
|
2020-11-27 03:03:08 +01:00
|
|
|
/// ## Platform-specific
|
2022-07-20 13:45:12 +02:00
|
|
|
///
|
2020-11-27 03:03:08 +01:00
|
|
|
/// - **macOS:** Bounces the dock icon once.
|
|
|
|
|
/// - **Windows:** Flashes the taskbar button until the application is in focus.
|
2023-03-12 18:02:49 +01:00
|
|
|
#[default]
|
2020-11-27 03:03:08 +01:00
|
|
|
Informational,
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-25 09:25:09 +01:00
|
|
|
bitflags::bitflags! {
|
2023-06-02 15:44:36 +01:00
|
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
2022-11-29 12:03:51 +02:00
|
|
|
pub struct WindowButtons: u32 {
|
|
|
|
|
const CLOSE = 1 << 0;
|
|
|
|
|
const MINIMIZE = 1 << 1;
|
|
|
|
|
const MAXIMIZE = 1 << 2;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-26 03:50:58 +02:00
|
|
|
/// A window level groups windows with respect to their z-position.
|
|
|
|
|
///
|
|
|
|
|
/// The relative ordering between windows in different window levels is fixed.
|
|
|
|
|
/// The z-order of a window within the same window level may change dynamically on user interaction.
|
|
|
|
|
///
|
|
|
|
|
/// ## Platform-specific
|
|
|
|
|
///
|
|
|
|
|
/// - **iOS / Android / Web / Wayland:** Unsupported.
|
2024-08-08 00:46:28 +02:00
|
|
|
#[derive(Debug, Default, PartialEq, Eq, Clone, Copy, Hash)]
|
|
|
|
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
2022-11-26 03:50:58 +02:00
|
|
|
pub enum WindowLevel {
|
|
|
|
|
/// The window will always be below normal windows.
|
|
|
|
|
///
|
|
|
|
|
/// This is useful for a widget-based app.
|
|
|
|
|
AlwaysOnBottom,
|
2023-03-12 18:02:49 +01:00
|
|
|
|
2022-11-26 03:50:58 +02:00
|
|
|
/// The default.
|
2023-03-12 18:02:49 +01:00
|
|
|
#[default]
|
2022-11-26 03:50:58 +02:00
|
|
|
Normal,
|
2023-03-12 18:02:49 +01:00
|
|
|
|
2022-11-26 03:50:58 +02:00
|
|
|
/// The window will always be on top of normal windows.
|
|
|
|
|
AlwaysOnTop,
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-29 16:46:46 +01:00
|
|
|
/// Generic IME purposes for use in [`Window::set_ime_purpose`].
|
|
|
|
|
///
|
|
|
|
|
/// The purpose may improve UX by optimizing the IME for the specific use case,
|
|
|
|
|
/// if winit can express the purpose to the platform and the platform reacts accordingly.
|
|
|
|
|
///
|
|
|
|
|
/// ## Platform-specific
|
|
|
|
|
///
|
|
|
|
|
/// - **iOS / Android / Web / Windows / X11 / macOS / Orbital:** Unsupported.
|
|
|
|
|
#[non_exhaustive]
|
2024-08-08 00:46:28 +02:00
|
|
|
#[derive(Debug, PartialEq, Eq, Clone, Copy, Hash)]
|
|
|
|
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
2023-01-29 16:46:46 +01:00
|
|
|
pub enum ImePurpose {
|
|
|
|
|
/// No special hints for the IME (default).
|
|
|
|
|
Normal,
|
|
|
|
|
/// The IME is used for password input.
|
|
|
|
|
Password,
|
|
|
|
|
/// The IME is used to input into a terminal.
|
|
|
|
|
///
|
|
|
|
|
/// For example, that could alter OSK on Wayland to show extra buttons.
|
|
|
|
|
Terminal,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Default for ImePurpose {
|
|
|
|
|
fn default() -> Self {
|
|
|
|
|
Self::Normal
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-07-20 13:16:51 +00:00
|
|
|
|
|
|
|
|
/// An opaque token used to activate the [`Window`].
|
|
|
|
|
///
|
|
|
|
|
/// [`Window`]: crate::window::Window
|
2024-08-08 00:46:28 +02:00
|
|
|
#[derive(Debug, PartialEq, Eq, Clone, Hash)]
|
2023-07-20 13:16:51 +00:00
|
|
|
pub struct ActivationToken {
|
|
|
|
|
pub(crate) _token: String,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl ActivationToken {
|
|
|
|
|
pub(crate) fn _new(_token: String) -> Self {
|
|
|
|
|
Self { _token }
|
|
|
|
|
}
|
|
|
|
|
}
|