-
Notifications
You must be signed in to change notification settings - Fork 947
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split
platform::unix
into x11
and wayland
modules
- Loading branch information
Showing
5 changed files
with
228 additions
and
184 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,185 @@ | ||
use std::os::raw; | ||
|
||
use crate::{ | ||
event_loop::{EventLoopBuilder, EventLoopWindowTarget}, | ||
monitor::MonitorHandle, | ||
window::{Window, WindowBuilder}, | ||
}; | ||
|
||
use crate::platform_impl::{ | ||
ApplicationName, Backend, EventLoopWindowTarget as LinuxEventLoopWindowTarget, | ||
Window as LinuxWindow, | ||
}; | ||
|
||
pub use crate::window::Theme; | ||
|
||
/// Additional methods on [`EventLoopWindowTarget`] that are specific to Wayland. | ||
pub trait EventLoopWindowTargetExtWayland { | ||
/// True if the [`EventLoopWindowTarget`] uses Wayland. | ||
fn is_wayland(&self) -> bool; | ||
|
||
/// Returns a pointer to the `wl_display` object of wayland that is used by this | ||
/// [`EventLoopWindowTarget`]. | ||
/// | ||
/// Returns `None` if the [`EventLoop`] doesn't use wayland (if it uses xlib for example). | ||
/// | ||
/// The pointer will become invalid when the winit [`EventLoop`] is destroyed. | ||
/// | ||
/// [`EventLoop`]: crate::event_loop::EventLoop | ||
fn wayland_display(&self) -> Option<*mut raw::c_void>; | ||
} | ||
|
||
impl<T> EventLoopWindowTargetExtWayland for EventLoopWindowTarget<T> { | ||
#[inline] | ||
fn is_wayland(&self) -> bool { | ||
self.p.is_wayland() | ||
} | ||
|
||
#[inline] | ||
fn wayland_display(&self) -> Option<*mut raw::c_void> { | ||
match self.p { | ||
LinuxEventLoopWindowTarget::Wayland(ref p) => { | ||
Some(p.display().get_display_ptr() as *mut _) | ||
} | ||
#[cfg(feature = "x11")] | ||
_ => None, | ||
} | ||
} | ||
} | ||
|
||
/// 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(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 { | ||
/// Returns a pointer to the `wl_surface` object of wayland that is used by this window. | ||
/// | ||
/// Returns `None` if the window doesn't use wayland (if it uses xlib for example). | ||
/// | ||
/// The pointer will become invalid when the [`Window`] is destroyed. | ||
fn wayland_surface(&self) -> Option<*mut raw::c_void>; | ||
|
||
/// Returns a pointer to the `wl_display` object of wayland that is used by this window. | ||
/// | ||
/// Returns `None` if the window doesn't use wayland (if it uses xlib for example). | ||
/// | ||
/// The pointer will become invalid when the [`Window`] is destroyed. | ||
fn wayland_display(&self) -> Option<*mut raw::c_void>; | ||
|
||
/// Updates [`Theme`] of window decorations. | ||
/// | ||
/// You can also use `WINIT_WAYLAND_CSD_THEME` env variable to set the theme. | ||
/// Possible values for env variable are: "dark" and light" | ||
fn wayland_set_csd_theme(&self, config: Theme); | ||
|
||
/// Check if the window is ready for drawing | ||
/// | ||
/// It is a remnant of a previous implementation detail for the | ||
/// wayland backend, and is no longer relevant. | ||
/// | ||
/// Always return `true`. | ||
#[deprecated] | ||
fn is_ready(&self) -> bool; | ||
} | ||
|
||
impl WindowExtWayland for Window { | ||
#[inline] | ||
fn wayland_surface(&self) -> Option<*mut raw::c_void> { | ||
match self.window { | ||
LinuxWindow::Wayland(ref w) => Some(w.surface().as_ref().c_ptr() as *mut _), | ||
#[cfg(feature = "x11")] | ||
_ => None, | ||
} | ||
} | ||
|
||
#[inline] | ||
fn wayland_display(&self) -> Option<*mut raw::c_void> { | ||
match self.window { | ||
LinuxWindow::Wayland(ref w) => Some(w.display().get_display_ptr() as *mut _), | ||
#[cfg(feature = "x11")] | ||
_ => None, | ||
} | ||
} | ||
|
||
#[inline] | ||
fn wayland_set_csd_theme(&self, theme: Theme) { | ||
#[allow(clippy::single_match)] | ||
match self.window { | ||
LinuxWindow::Wayland(ref w) => w.set_csd_theme(theme), | ||
#[cfg(feature = "x11")] | ||
_ => (), | ||
} | ||
} | ||
|
||
#[inline] | ||
fn is_ready(&self) -> bool { | ||
true | ||
} | ||
} | ||
|
||
/// Additional methods on [`WindowBuilder`] that are specific to Wayland. | ||
pub trait WindowBuilderExtWayland { | ||
/// Build window with the given application ID. | ||
/// | ||
/// This should match the `.desktop` file destributed with your program. | ||
/// | ||
/// 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_application_id(self, application_id: impl Into<String>) -> Self; | ||
|
||
/// Build window with certain decoration [`Theme`] | ||
/// | ||
/// You can also use `WINIT_WAYLAND_CSD_THEME` env variable to set the theme. | ||
/// Possible values for env variable are: "dark" and light" | ||
fn with_wayland_csd_theme(self, theme: Theme) -> Self; | ||
} | ||
|
||
impl WindowBuilderExtWayland for WindowBuilder { | ||
#[inline] | ||
fn with_application_id(mut self, application_id: impl Into<String>) -> Self { | ||
self.platform_specific.name = Some(ApplicationName::new(application_id.into(), "")); | ||
self | ||
} | ||
|
||
#[inline] | ||
fn with_wayland_csd_theme(mut self, theme: Theme) -> Self { | ||
self.platform_specific.csd_theme = Some(theme); | ||
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() | ||
} | ||
} |
Oops, something went wrong.