use super::__private as sealed;
use crate::event_loop::{EventLoopBuilder, EventLoopWindowTarget};
use crate::sync::ThreadSafety;
use crate::window::{Window, WindowBuilder};
use std::os::raw;
use winit::platform::wayland::{
EventLoopBuilderExtWayland as _, WindowBuilderExtWayland as _, WindowExtWayland as _,
};
#[doc(inline)]
pub use winit::platform::wayland::MonitorHandleExtWayland;
pub trait EventLoopWindowTargetExtWayland: sealed::EventLoopWindowTargetPrivate {
fn is_wayland(&self) -> bool;
fn wayland_display(&self) -> Option<*mut raw::c_void>;
}
impl<TS: ThreadSafety> EventLoopWindowTargetExtWayland for EventLoopWindowTarget<TS> {
#[inline]
fn is_wayland(&self) -> bool {
self.is_wayland
}
#[inline]
fn wayland_display(&self) -> Option<*mut raw::c_void> {
todo!()
}
}
pub trait EventLoopBuilderExtWayland: sealed::EventLoopBuilderPrivate {
fn with_wayland(&mut self) -> &mut Self;
fn with_any_thread(&mut self, any_thread: bool) -> &mut Self;
}
impl EventLoopBuilderExtWayland for EventLoopBuilder {
fn with_wayland(&mut self) -> &mut Self {
self.inner.with_wayland();
self
}
fn with_any_thread(&mut self, any_thread: bool) -> &mut Self {
self.inner.with_any_thread(any_thread);
self
}
}
pub trait WindowExtWayland: sealed::WindowPrivate {
fn wayland_surface(&self) -> Option<*mut raw::c_void>;
fn wayland_display(&self) -> Option<*mut raw::c_void>;
}
impl<TS: ThreadSafety> WindowExtWayland for Window<TS> {
#[inline]
fn wayland_surface(&self) -> Option<*mut raw::c_void> {
self.window().wayland_surface()
}
#[inline]
fn wayland_display(&self) -> Option<*mut raw::c_void> {
self.window().wayland_display()
}
}
pub trait WindowBuilderExtWayland: sealed::WindowBuilderPrivate {
fn with_name(self, general: impl Into<String>, instance: impl Into<String>) -> Self;
}
impl WindowBuilderExtWayland for WindowBuilder {
#[inline]
fn with_name(mut self, general: impl Into<String>, instance: impl Into<String>) -> Self {
self.platform
.set_x11_name((general.into(), instance.into()));
self
}
}
#[derive(Default)]
pub(crate) struct PlatformSpecific {
pub name: Option<(String, String)>,
}
impl PlatformSpecific {
pub fn set_x11_name(&mut self, x11_name: (String, String)) {
self.name = Some(x11_name);
}
pub fn apply_to(
self,
window_builder: winit::window::WindowBuilder,
) -> winit::window::WindowBuilder {
let mut window_builder = window_builder;
if let Some((general, instance)) = self.name {
window_builder = window_builder.with_name(general, instance);
}
window_builder
}
}