mirror of
https://github.com/rust-windowing/winit.git
synced 2026-06-26 22:53:15 -04:00
Creating window when event loop is not running generally doesn't work, since a bunch of events and sync OS requests can't be processed. This is also an issue on e.g. Android, since window can't be created outside event loop easily. Thus deprecate the window creation when event loop is not running, as well as other resource creation to running event loop. Given that all the examples use the bad pattern of creating the window when event loop is not running and also most example existence is questionable, since they show single thing and the majority of their code is window/event loop initialization, they wore merged into a single example 'window.rs' example that showcases very simple application using winit. Fixes #3399.
88 lines
2.8 KiB
Rust
88 lines
2.8 KiB
Rust
use crate::{
|
|
event_loop::{ActiveEventLoop, EventLoopBuilder},
|
|
monitor::MonitorHandle,
|
|
window::{Window, WindowAttributes},
|
|
};
|
|
|
|
pub use crate::window::Theme;
|
|
|
|
/// Additional methods on [`ActiveEventLoop`] that are specific to Wayland.
|
|
pub trait ActiveEventLoopExtWayland {
|
|
/// True if the [`ActiveEventLoop`] uses Wayland.
|
|
fn is_wayland(&self) -> bool;
|
|
}
|
|
|
|
impl ActiveEventLoopExtWayland for ActiveEventLoop {
|
|
#[inline]
|
|
fn is_wayland(&self) -> bool {
|
|
self.p.is_wayland()
|
|
}
|
|
}
|
|
|
|
/// Additional methods on [`EventLoopBuilder`] that are specific to Wayland.
|
|
pub trait EventLoopBuilderExtWayland {
|
|
/// Force using Wayland.
|
|
fn with_wayland(&mut self) -> &mut Self;
|
|
|
|
/// Whether to allow the event loop to be created off of the main thread.
|
|
///
|
|
/// By default, the window is only allowed to be created on the main
|
|
/// thread, to make platform compatibility easier.
|
|
fn with_any_thread(&mut self, any_thread: bool) -> &mut Self;
|
|
}
|
|
|
|
impl<T> EventLoopBuilderExtWayland for EventLoopBuilder<T> {
|
|
#[inline]
|
|
fn with_wayland(&mut self) -> &mut Self {
|
|
self.platform_specific.forced_backend = Some(crate::platform_impl::Backend::Wayland);
|
|
self
|
|
}
|
|
|
|
#[inline]
|
|
fn with_any_thread(&mut self, any_thread: bool) -> &mut Self {
|
|
self.platform_specific.any_thread = any_thread;
|
|
self
|
|
}
|
|
}
|
|
|
|
/// Additional methods on [`Window`] that are specific to Wayland.
|
|
pub trait WindowExtWayland {}
|
|
|
|
impl WindowExtWayland for Window {}
|
|
|
|
/// Additional methods on [`WindowAttributes`] that are specific to Wayland.
|
|
pub trait WindowAttributesExtWayland {
|
|
/// Build window with the given name.
|
|
///
|
|
/// The `general` name sets an application ID, which should match the `.desktop`
|
|
/// file distributed with your program. The `instance` is a `no-op`.
|
|
///
|
|
/// For details about application ID conventions, see the
|
|
/// [Desktop Entry Spec](https://specifications.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html#desktop-file-id)
|
|
fn with_name(self, general: impl Into<String>, instance: impl Into<String>) -> Self;
|
|
}
|
|
|
|
impl WindowAttributesExtWayland for WindowAttributes {
|
|
#[inline]
|
|
fn with_name(mut self, general: impl Into<String>, instance: impl Into<String>) -> Self {
|
|
self.platform_specific.name = Some(crate::platform_impl::ApplicationName::new(
|
|
general.into(),
|
|
instance.into(),
|
|
));
|
|
self
|
|
}
|
|
}
|
|
|
|
/// Additional methods on `MonitorHandle` that are specific to Wayland.
|
|
pub trait MonitorHandleExtWayland {
|
|
/// Returns the inner identifier of the monitor.
|
|
fn native_id(&self) -> u32;
|
|
}
|
|
|
|
impl MonitorHandleExtWayland for MonitorHandle {
|
|
#[inline]
|
|
fn native_id(&self) -> u32 {
|
|
self.inner.native_identifier()
|
|
}
|
|
}
|