mirror of
https://github.com/italicsjenga/winit-sonoma-fix.git
synced 2024-12-23 13:51:30 +11:00
Slightly reduce number of cfg
s (#3071)
* Make Linux platforms less dependent on the root monitor handle * Add various functions to the Wayland platform to reduce cfgs * Don't use a cfg in listen_device_events * Don't use a cfg in set_content_protected * Fix instance of a target_os cfg
This commit is contained in:
parent
67b041e231
commit
a06ea45c0f
|
@ -672,7 +672,7 @@ pub struct KeyEvent {
|
||||||
// Allowing `broken_intra_doc_links` for `logical_key`, because
|
// Allowing `broken_intra_doc_links` for `logical_key`, because
|
||||||
// `key_without_modifiers` is not available on all platforms
|
// `key_without_modifiers` is not available on all platforms
|
||||||
#[cfg_attr(
|
#[cfg_attr(
|
||||||
not(any(target_os = "macos", target_os = "windows", target_os = "linux")),
|
not(any(windows_platform, macos_platform, x11_platform, wayland_platform)),
|
||||||
allow(rustdoc::broken_intra_doc_links)
|
allow(rustdoc::broken_intra_doc_links)
|
||||||
)]
|
)]
|
||||||
/// This value is affected by all modifiers except <kbd>Ctrl</kbd>.
|
/// This value is affected by all modifiers except <kbd>Ctrl</kbd>.
|
||||||
|
|
|
@ -374,9 +374,8 @@ impl<T> EventLoopWindowTarget<T> {
|
||||||
/// - **Wayland / macOS / iOS / Android / Orbital:** Unsupported.
|
/// - **Wayland / macOS / iOS / Android / Orbital:** Unsupported.
|
||||||
///
|
///
|
||||||
/// [`DeviceEvent`]: crate::event::DeviceEvent
|
/// [`DeviceEvent`]: crate::event::DeviceEvent
|
||||||
pub fn listen_device_events(&self, _allowed: DeviceEvents) {
|
pub fn listen_device_events(&self, allowed: DeviceEvents) {
|
||||||
#[cfg(any(x11_platform, wasm_platform, wayland_platform, windows))]
|
self.p.listen_device_events(allowed);
|
||||||
self.p.listen_device_events(_allowed);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,7 @@ use crate::{
|
||||||
dpi::{PhysicalPosition, PhysicalSize, Position, Size},
|
dpi::{PhysicalPosition, PhysicalSize, Position, Size},
|
||||||
error,
|
error,
|
||||||
event::{self, InnerSizeWriter, StartCause},
|
event::{self, InnerSizeWriter, StartCause},
|
||||||
event_loop::{self, ControlFlow, EventLoopWindowTarget as RootELW},
|
event_loop::{self, ControlFlow, DeviceEvents, EventLoopWindowTarget as RootELW},
|
||||||
platform::pump_events::PumpStatus,
|
platform::pump_events::PumpStatus,
|
||||||
window::{
|
window::{
|
||||||
self, CursorGrabMode, ImePurpose, ResizeDirection, Theme, WindowButtons, WindowLevel,
|
self, CursorGrabMode, ImePurpose, ResizeDirection, Theme, WindowButtons, WindowLevel,
|
||||||
|
@ -743,6 +743,9 @@ impl<T: 'static> EventLoopWindowTarget<T> {
|
||||||
v
|
v
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn listen_device_events(&self, _allowed: DeviceEvents) {}
|
||||||
|
|
||||||
pub fn raw_display_handle(&self) -> RawDisplayHandle {
|
pub fn raw_display_handle(&self) -> RawDisplayHandle {
|
||||||
RawDisplayHandle::Android(AndroidDisplayHandle::empty())
|
RawDisplayHandle::Android(AndroidDisplayHandle::empty())
|
||||||
}
|
}
|
||||||
|
@ -995,6 +998,8 @@ impl Window {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn set_content_protected(&self, _protected: bool) {}
|
||||||
|
|
||||||
pub fn has_focus(&self) -> bool {
|
pub fn has_focus(&self) -> bool {
|
||||||
*HAS_FOCUS.read().unwrap()
|
*HAS_FOCUS.read().unwrap()
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,8 @@ use crate::{
|
||||||
error::EventLoopError,
|
error::EventLoopError,
|
||||||
event::Event,
|
event::Event,
|
||||||
event_loop::{
|
event_loop::{
|
||||||
ControlFlow, EventLoopClosed, EventLoopWindowTarget as RootEventLoopWindowTarget,
|
ControlFlow, DeviceEvents, EventLoopClosed,
|
||||||
|
EventLoopWindowTarget as RootEventLoopWindowTarget,
|
||||||
},
|
},
|
||||||
platform::ios::Idiom,
|
platform::ios::Idiom,
|
||||||
};
|
};
|
||||||
|
@ -45,6 +46,9 @@ impl<T: 'static> EventLoopWindowTarget<T> {
|
||||||
Some(MonitorHandle::new(UIScreen::main(self.mtm)))
|
Some(MonitorHandle::new(UIScreen::main(self.mtm)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn listen_device_events(&self, _allowed: DeviceEvents) {}
|
||||||
|
|
||||||
pub fn raw_display_handle(&self) -> RawDisplayHandle {
|
pub fn raw_display_handle(&self) -> RawDisplayHandle {
|
||||||
RawDisplayHandle::UiKit(UiKitDisplayHandle::empty())
|
RawDisplayHandle::UiKit(UiKitDisplayHandle::empty())
|
||||||
}
|
}
|
||||||
|
|
|
@ -342,6 +342,8 @@ impl Inner {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn set_content_protected(&self, _protected: bool) {}
|
||||||
|
|
||||||
pub fn has_focus(&self) -> bool {
|
pub fn has_focus(&self) -> bool {
|
||||||
self.window.isKeyWindow()
|
self.window.isKeyWindow()
|
||||||
}
|
}
|
||||||
|
|
|
@ -283,7 +283,7 @@ impl VideoMode {
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn monitor(&self) -> MonitorHandle {
|
pub fn monitor(&self) -> MonitorHandle {
|
||||||
x11_or_wayland!(match self; VideoMode(m) => m.monitor())
|
x11_or_wayland!(match self; VideoMode(m) => m.monitor(); as MonitorHandle)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -316,12 +316,7 @@ impl Window {
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn id(&self) -> WindowId {
|
pub fn id(&self) -> WindowId {
|
||||||
match self {
|
x11_or_wayland!(match self; Window(w) => w.id())
|
||||||
#[cfg(wayland_platform)]
|
|
||||||
Self::Wayland(window) => window.id(),
|
|
||||||
#[cfg(x11_platform)]
|
|
||||||
Self::X(window) => window.id(),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -500,23 +495,13 @@ impl Window {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn set_window_level(&self, _level: WindowLevel) {
|
pub fn set_window_level(&self, level: WindowLevel) {
|
||||||
match self {
|
x11_or_wayland!(match self; Window(w) => w.set_window_level(level))
|
||||||
#[cfg(x11_platform)]
|
|
||||||
Window::X(ref w) => w.set_window_level(_level),
|
|
||||||
#[cfg(wayland_platform)]
|
|
||||||
Window::Wayland(_) => (),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn set_window_icon(&self, _window_icon: Option<Icon>) {
|
pub fn set_window_icon(&self, window_icon: Option<Icon>) {
|
||||||
match self {
|
x11_or_wayland!(match self; Window(w) => w.set_window_icon(window_icon.map(|icon| icon.inner)))
|
||||||
#[cfg(x11_platform)]
|
|
||||||
Window::X(ref w) => w.set_window_icon(_window_icon),
|
|
||||||
#[cfg(wayland_platform)]
|
|
||||||
Window::Wayland(_) => (),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -541,12 +526,7 @@ impl Window {
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn focus_window(&self) {
|
pub fn focus_window(&self) {
|
||||||
match self {
|
x11_or_wayland!(match self; Window(w) => w.focus_window())
|
||||||
#[cfg(x11_platform)]
|
|
||||||
Window::X(ref w) => w.focus_window(),
|
|
||||||
#[cfg(wayland_platform)]
|
|
||||||
Window::Wayland(_) => (),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
pub fn request_user_attention(&self, request_type: Option<UserAttentionType>) {
|
pub fn request_user_attention(&self, request_type: Option<UserAttentionType>) {
|
||||||
x11_or_wayland!(match self; Window(w) => w.request_user_attention(request_type))
|
x11_or_wayland!(match self; Window(w) => w.request_user_attention(request_type))
|
||||||
|
@ -564,18 +544,7 @@ impl Window {
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn current_monitor(&self) -> Option<MonitorHandle> {
|
pub fn current_monitor(&self) -> Option<MonitorHandle> {
|
||||||
match self {
|
Some(x11_or_wayland!(match self; Window(w) => w.current_monitor()?; as MonitorHandle))
|
||||||
#[cfg(x11_platform)]
|
|
||||||
Window::X(ref window) => {
|
|
||||||
let current_monitor = MonitorHandle::X(window.current_monitor());
|
|
||||||
Some(current_monitor)
|
|
||||||
}
|
|
||||||
#[cfg(wayland_platform)]
|
|
||||||
Window::Wayland(ref window) => {
|
|
||||||
let current_monitor = MonitorHandle::Wayland(window.current_monitor()?);
|
|
||||||
Some(current_monitor)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -598,15 +567,7 @@ impl Window {
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn primary_monitor(&self) -> Option<MonitorHandle> {
|
pub fn primary_monitor(&self) -> Option<MonitorHandle> {
|
||||||
match self {
|
Some(x11_or_wayland!(match self; Window(w) => w.primary_monitor()?; as MonitorHandle))
|
||||||
#[cfg(x11_platform)]
|
|
||||||
Window::X(ref window) => {
|
|
||||||
let primary_monitor = MonitorHandle::X(window.primary_monitor());
|
|
||||||
Some(primary_monitor)
|
|
||||||
}
|
|
||||||
#[cfg(wayland_platform)]
|
|
||||||
Window::Wayland(ref window) => window.primary_monitor(),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -629,6 +590,10 @@ impl Window {
|
||||||
x11_or_wayland!(match self; Window(window) => window.theme())
|
x11_or_wayland!(match self; Window(window) => window.theme())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn set_content_protected(&self, protected: bool) {
|
||||||
|
x11_or_wayland!(match self; Window(window) => window.set_content_protected(protected))
|
||||||
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn has_focus(&self) -> bool {
|
pub fn has_focus(&self) -> bool {
|
||||||
x11_or_wayland!(match self; Window(window) => window.has_focus())
|
x11_or_wayland!(match self; Window(window) => window.has_focus())
|
||||||
|
@ -843,41 +808,25 @@ impl<T> EventLoopWindowTarget<T> {
|
||||||
#[cfg(wayland_platform)]
|
#[cfg(wayland_platform)]
|
||||||
EventLoopWindowTarget::Wayland(ref evlp) => evlp
|
EventLoopWindowTarget::Wayland(ref evlp) => evlp
|
||||||
.available_monitors()
|
.available_monitors()
|
||||||
.into_iter()
|
|
||||||
.map(MonitorHandle::Wayland)
|
.map(MonitorHandle::Wayland)
|
||||||
.collect(),
|
.collect(),
|
||||||
#[cfg(x11_platform)]
|
#[cfg(x11_platform)]
|
||||||
EventLoopWindowTarget::X(ref evlp) => evlp
|
|
||||||
.x_connection()
|
|
||||||
.available_monitors()
|
|
||||||
.into_iter()
|
|
||||||
.flatten()
|
|
||||||
.map(MonitorHandle::X)
|
|
||||||
.collect(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn primary_monitor(&self) -> Option<MonitorHandle> {
|
|
||||||
match *self {
|
|
||||||
#[cfg(wayland_platform)]
|
|
||||||
EventLoopWindowTarget::Wayland(ref evlp) => evlp.primary_monitor(),
|
|
||||||
#[cfg(x11_platform)]
|
|
||||||
EventLoopWindowTarget::X(ref evlp) => {
|
EventLoopWindowTarget::X(ref evlp) => {
|
||||||
let primary_monitor = MonitorHandle::X(evlp.x_connection().primary_monitor().ok()?);
|
evlp.available_monitors().map(MonitorHandle::X).collect()
|
||||||
Some(primary_monitor)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn listen_device_events(&self, _allowed: DeviceEvents) {
|
pub fn primary_monitor(&self) -> Option<MonitorHandle> {
|
||||||
match *self {
|
Some(
|
||||||
#[cfg(wayland_platform)]
|
x11_or_wayland!(match self; EventLoopWindowTarget(evlp) => evlp.primary_monitor()?; as MonitorHandle),
|
||||||
EventLoopWindowTarget::Wayland(_) => (),
|
)
|
||||||
#[cfg(x11_platform)]
|
}
|
||||||
EventLoopWindowTarget::X(ref evlp) => evlp.set_listen_device_events(_allowed),
|
|
||||||
}
|
#[inline]
|
||||||
|
pub fn listen_device_events(&self, allowed: DeviceEvents) {
|
||||||
|
x11_or_wayland!(match self; Self(evlp) => evlp.listen_device_events(allowed))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn raw_display_handle(&self) -> raw_window_handle::RawDisplayHandle {
|
pub fn raw_display_handle(&self) -> raw_window_handle::RawDisplayHandle {
|
||||||
|
|
|
@ -19,7 +19,9 @@ use sctk::reexports::client::{Connection, Proxy, QueueHandle, WaylandSource};
|
||||||
use crate::dpi::{LogicalSize, PhysicalSize};
|
use crate::dpi::{LogicalSize, PhysicalSize};
|
||||||
use crate::error::{EventLoopError, OsError as RootOsError};
|
use crate::error::{EventLoopError, OsError as RootOsError};
|
||||||
use crate::event::{Event, InnerSizeWriter, StartCause, WindowEvent};
|
use crate::event::{Event, InnerSizeWriter, StartCause, WindowEvent};
|
||||||
use crate::event_loop::{ControlFlow, EventLoopWindowTarget as RootEventLoopWindowTarget};
|
use crate::event_loop::{
|
||||||
|
ControlFlow, DeviceEvents, EventLoopWindowTarget as RootEventLoopWindowTarget,
|
||||||
|
};
|
||||||
use crate::platform::pump_events::PumpStatus;
|
use crate::platform::pump_events::PumpStatus;
|
||||||
use crate::platform_impl::platform::min_timeout;
|
use crate::platform_impl::platform::min_timeout;
|
||||||
use crate::platform_impl::platform::sticky_exit_callback;
|
use crate::platform_impl::platform::sticky_exit_callback;
|
||||||
|
@ -681,6 +683,9 @@ pub struct EventLoopWindowTarget<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> EventLoopWindowTarget<T> {
|
impl<T> EventLoopWindowTarget<T> {
|
||||||
|
#[inline]
|
||||||
|
pub fn listen_device_events(&self, _allowed: DeviceEvents) {}
|
||||||
|
|
||||||
pub fn raw_display_handle(&self) -> RawDisplayHandle {
|
pub fn raw_display_handle(&self) -> RawDisplayHandle {
|
||||||
let mut display_handle = WaylandDisplayHandle::empty();
|
let mut display_handle = WaylandDisplayHandle::empty();
|
||||||
display_handle.display = self.connection.display().id().as_ptr() as *mut _;
|
display_handle.display = self.connection.display().id().as_ptr() as *mut _;
|
||||||
|
|
|
@ -4,25 +4,22 @@ use sctk::reexports::client::Proxy;
|
||||||
use sctk::output::OutputData;
|
use sctk::output::OutputData;
|
||||||
|
|
||||||
use crate::dpi::{PhysicalPosition, PhysicalSize};
|
use crate::dpi::{PhysicalPosition, PhysicalSize};
|
||||||
use crate::platform_impl::platform::{
|
use crate::platform_impl::platform::VideoMode as PlatformVideoMode;
|
||||||
MonitorHandle as PlatformMonitorHandle, VideoMode as PlatformVideoMode,
|
|
||||||
};
|
|
||||||
|
|
||||||
use super::event_loop::EventLoopWindowTarget;
|
use super::event_loop::EventLoopWindowTarget;
|
||||||
|
|
||||||
impl<T> EventLoopWindowTarget<T> {
|
impl<T> EventLoopWindowTarget<T> {
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn available_monitors(&self) -> Vec<MonitorHandle> {
|
pub fn available_monitors(&self) -> impl Iterator<Item = MonitorHandle> {
|
||||||
self.state
|
self.state
|
||||||
.borrow()
|
.borrow()
|
||||||
.output_state
|
.output_state
|
||||||
.outputs()
|
.outputs()
|
||||||
.map(MonitorHandle::new)
|
.map(MonitorHandle::new)
|
||||||
.collect()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn primary_monitor(&self) -> Option<PlatformMonitorHandle> {
|
pub fn primary_monitor(&self) -> Option<MonitorHandle> {
|
||||||
// There's no primary monitor on Wayland.
|
// There's no primary monitor on Wayland.
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
@ -157,7 +154,7 @@ impl VideoMode {
|
||||||
self.refresh_rate_millihertz
|
self.refresh_rate_millihertz
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn monitor(&self) -> PlatformMonitorHandle {
|
pub fn monitor(&self) -> MonitorHandle {
|
||||||
PlatformMonitorHandle::Wayland(self.monitor.clone())
|
self.monitor.clone()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,12 +24,12 @@ use crate::error::{ExternalError, NotSupportedError, OsError as RootOsError};
|
||||||
use crate::event::{Ime, WindowEvent};
|
use crate::event::{Ime, WindowEvent};
|
||||||
use crate::event_loop::AsyncRequestSerial;
|
use crate::event_loop::AsyncRequestSerial;
|
||||||
use crate::platform_impl::{
|
use crate::platform_impl::{
|
||||||
Fullscreen, MonitorHandle as PlatformMonitorHandle, OsError,
|
Fullscreen, MonitorHandle as PlatformMonitorHandle, OsError, PlatformIcon,
|
||||||
PlatformSpecificWindowBuilderAttributes as PlatformAttributes,
|
PlatformSpecificWindowBuilderAttributes as PlatformAttributes,
|
||||||
};
|
};
|
||||||
use crate::window::{
|
use crate::window::{
|
||||||
CursorGrabMode, CursorIcon, ImePurpose, ResizeDirection, Theme, UserAttentionType,
|
CursorGrabMode, CursorIcon, ImePurpose, ResizeDirection, Theme, UserAttentionType,
|
||||||
WindowAttributes, WindowButtons,
|
WindowAttributes, WindowButtons, WindowLevel,
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::event_loop::sink::EventSink;
|
use super::event_loop::sink::EventSink;
|
||||||
|
@ -419,6 +419,12 @@ impl Window {
|
||||||
self.window_state.lock().unwrap().is_decorated()
|
self.window_state.lock().unwrap().is_decorated()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn set_window_level(&self, _level: WindowLevel) {}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub(crate) fn set_window_icon(&self, _window_icon: Option<PlatformIcon>) {}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn set_minimized(&self, minimized: bool) {
|
pub fn set_minimized(&self, minimized: bool) {
|
||||||
// You can't unminimize the window on Wayland.
|
// You can't unminimize the window on Wayland.
|
||||||
|
@ -612,6 +618,9 @@ impl Window {
|
||||||
self.window_state.lock().unwrap().set_ime_purpose(purpose);
|
self.window_state.lock().unwrap().set_ime_purpose(purpose);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn focus_window(&self) {}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn surface(&self) -> &WlSurface {
|
pub fn surface(&self) -> &WlSurface {
|
||||||
self.window.wl_surface()
|
self.window.wl_surface()
|
||||||
|
@ -629,7 +638,7 @@ impl Window {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn primary_monitor(&self) -> Option<PlatformMonitorHandle> {
|
pub fn primary_monitor(&self) -> Option<MonitorHandle> {
|
||||||
// XXX there's no such concept on Wayland.
|
// XXX there's no such concept on Wayland.
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
@ -658,6 +667,8 @@ impl Window {
|
||||||
self.window_state.lock().unwrap().theme()
|
self.window_state.lock().unwrap().theme()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn set_content_protected(&self, _protected: bool) {}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn title(&self) -> String {
|
pub fn title(&self) -> String {
|
||||||
self.window_state.lock().unwrap().title().to_owned()
|
self.window_state.lock().unwrap().title().to_owned()
|
||||||
|
|
|
@ -1317,7 +1317,8 @@ impl<T: 'static> EventProcessor<T> {
|
||||||
for (window_id, window) in wt.windows.borrow().iter() {
|
for (window_id, window) in wt.windows.borrow().iter() {
|
||||||
if let Some(window) = window.upgrade() {
|
if let Some(window) = window.upgrade() {
|
||||||
// Check if the window is on this monitor
|
// Check if the window is on this monitor
|
||||||
let monitor = window.current_monitor();
|
let monitor =
|
||||||
|
window.shared_state_lock().last_monitor.clone();
|
||||||
if monitor.name == new_monitor.name {
|
if monitor.name == new_monitor.name {
|
||||||
let (width, height) = window.inner_size_physical();
|
let (width, height) = window.inner_size_physical();
|
||||||
let (new_width, new_height) = window.adjust_for_dpi(
|
let (new_width, new_height) = window.adjust_for_dpi(
|
||||||
|
|
|
@ -706,7 +706,15 @@ impl<T> EventLoopWindowTarget<T> {
|
||||||
&self.xconn
|
&self.xconn
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_listen_device_events(&self, allowed: DeviceEvents) {
|
pub fn available_monitors(&self) -> impl Iterator<Item = MonitorHandle> {
|
||||||
|
self.xconn.available_monitors().into_iter().flatten()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn primary_monitor(&self) -> Option<MonitorHandle> {
|
||||||
|
self.xconn.primary_monitor().ok()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn listen_device_events(&self, allowed: DeviceEvents) {
|
||||||
self.device_events.set(allowed);
|
self.device_events.set(allowed);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use super::{util, X11Error, XConnection};
|
use super::{util, X11Error, XConnection};
|
||||||
use crate::{
|
use crate::{
|
||||||
dpi::{PhysicalPosition, PhysicalSize},
|
dpi::{PhysicalPosition, PhysicalSize},
|
||||||
platform_impl::{MonitorHandle as PlatformMonitorHandle, VideoMode as PlatformVideoMode},
|
platform_impl::VideoMode as PlatformVideoMode,
|
||||||
};
|
};
|
||||||
use x11rb::{
|
use x11rb::{
|
||||||
connection::RequestConnection,
|
connection::RequestConnection,
|
||||||
|
@ -47,8 +47,8 @@ impl VideoMode {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn monitor(&self) -> PlatformMonitorHandle {
|
pub fn monitor(&self) -> MonitorHandle {
|
||||||
PlatformMonitorHandle::X(self.monitor.clone().unwrap())
|
self.monitor.clone().unwrap()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#![allow(clippy::assertions_on_constants)]
|
#![allow(clippy::assertions_on_constants)]
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::icon::{Icon, Pixel, PIXEL_SIZE};
|
use crate::icon::{Pixel, RgbaIcon, PIXEL_SIZE};
|
||||||
|
|
||||||
impl Pixel {
|
impl Pixel {
|
||||||
pub fn to_packed_argb(&self) -> Cardinal {
|
pub fn to_packed_argb(&self) -> Cardinal {
|
||||||
|
@ -18,16 +18,15 @@ impl Pixel {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Icon {
|
impl RgbaIcon {
|
||||||
pub(crate) fn to_cardinals(&self) -> Vec<Cardinal> {
|
pub(crate) fn to_cardinals(&self) -> Vec<Cardinal> {
|
||||||
let rgba_icon = &self.inner;
|
assert_eq!(self.rgba.len() % PIXEL_SIZE, 0);
|
||||||
assert_eq!(rgba_icon.rgba.len() % PIXEL_SIZE, 0);
|
let pixel_count = self.rgba.len() / PIXEL_SIZE;
|
||||||
let pixel_count = rgba_icon.rgba.len() / PIXEL_SIZE;
|
assert_eq!(pixel_count, (self.width * self.height) as usize);
|
||||||
assert_eq!(pixel_count, (rgba_icon.width * rgba_icon.height) as usize);
|
|
||||||
let mut data = Vec::with_capacity(pixel_count);
|
let mut data = Vec::with_capacity(pixel_count);
|
||||||
data.push(rgba_icon.width as Cardinal);
|
data.push(self.width as Cardinal);
|
||||||
data.push(rgba_icon.height as Cardinal);
|
data.push(self.height as Cardinal);
|
||||||
let pixels = rgba_icon.rgba.as_ptr() as *const Pixel;
|
let pixels = self.rgba.as_ptr() as *const Pixel;
|
||||||
for pixel_index in 0..pixel_count {
|
for pixel_index in 0..pixel_count {
|
||||||
let pixel = unsafe { &*pixels.add(pixel_index) };
|
let pixel = unsafe { &*pixels.add(pixel_index) };
|
||||||
data.push(pixel.to_packed_argb());
|
data.push(pixel.to_packed_argb());
|
||||||
|
|
|
@ -23,11 +23,11 @@ use crate::{
|
||||||
event_loop::AsyncRequestSerial,
|
event_loop::AsyncRequestSerial,
|
||||||
platform_impl::{
|
platform_impl::{
|
||||||
x11::{atoms::*, MonitorHandle as X11MonitorHandle, WakeSender, X11Error},
|
x11::{atoms::*, MonitorHandle as X11MonitorHandle, WakeSender, X11Error},
|
||||||
Fullscreen, MonitorHandle as PlatformMonitorHandle, OsError,
|
Fullscreen, MonitorHandle as PlatformMonitorHandle, OsError, PlatformIcon,
|
||||||
PlatformSpecificWindowBuilderAttributes, VideoMode as PlatformVideoMode,
|
PlatformSpecificWindowBuilderAttributes, VideoMode as PlatformVideoMode,
|
||||||
},
|
},
|
||||||
window::{
|
window::{
|
||||||
CursorGrabMode, CursorIcon, Icon, ImePurpose, ResizeDirection, Theme, UserAttentionType,
|
CursorGrabMode, CursorIcon, ImePurpose, ResizeDirection, Theme, UserAttentionType,
|
||||||
WindowAttributes, WindowButtons, WindowLevel,
|
WindowAttributes, WindowButtons, WindowLevel,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
@ -469,7 +469,7 @@ impl UnownedWindow {
|
||||||
|
|
||||||
// Set window icons
|
// Set window icons
|
||||||
if let Some(icon) = window_attrs.window_icon {
|
if let Some(icon) = window_attrs.window_icon {
|
||||||
leap!(window.set_icon_inner(icon)).ignore_error();
|
leap!(window.set_icon_inner(icon.inner)).ignore_error();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Opt into handling window close
|
// Opt into handling window close
|
||||||
|
@ -778,7 +778,9 @@ impl UnownedWindow {
|
||||||
Fullscreen::Borderless(Some(PlatformMonitorHandle::X(monitor))) => {
|
Fullscreen::Borderless(Some(PlatformMonitorHandle::X(monitor))) => {
|
||||||
(None, monitor)
|
(None, monitor)
|
||||||
}
|
}
|
||||||
Fullscreen::Borderless(None) => (None, self.current_monitor()),
|
Fullscreen::Borderless(None) => {
|
||||||
|
(None, self.shared_state_lock().last_monitor.clone())
|
||||||
|
}
|
||||||
#[cfg(wayland_platform)]
|
#[cfg(wayland_platform)]
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
};
|
};
|
||||||
|
@ -874,9 +876,8 @@ impl UnownedWindow {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
pub fn current_monitor(&self) -> Option<X11MonitorHandle> {
|
||||||
pub fn current_monitor(&self) -> X11MonitorHandle {
|
Some(self.shared_state_lock().last_monitor.clone())
|
||||||
self.shared_state_lock().last_monitor.clone()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn available_monitors(&self) -> Vec<X11MonitorHandle> {
|
pub fn available_monitors(&self) -> Vec<X11MonitorHandle> {
|
||||||
|
@ -885,10 +886,12 @@ impl UnownedWindow {
|
||||||
.expect("Failed to get available monitors")
|
.expect("Failed to get available monitors")
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn primary_monitor(&self) -> X11MonitorHandle {
|
pub fn primary_monitor(&self) -> Option<X11MonitorHandle> {
|
||||||
self.xconn
|
Some(
|
||||||
.primary_monitor()
|
self.xconn
|
||||||
.expect("Failed to get primary monitor")
|
.primary_monitor()
|
||||||
|
.expect("Failed to get primary monitor"),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -1077,7 +1080,7 @@ impl UnownedWindow {
|
||||||
.expect("Failed to set window-level state");
|
.expect("Failed to set window-level state");
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_icon_inner(&self, icon: Icon) -> Result<VoidCookie<'_>, X11Error> {
|
fn set_icon_inner(&self, icon: PlatformIcon) -> Result<VoidCookie<'_>, X11Error> {
|
||||||
let atoms = self.xconn.atoms();
|
let atoms = self.xconn.atoms();
|
||||||
let icon_atom = atoms[_NET_WM_ICON];
|
let icon_atom = atoms[_NET_WM_ICON];
|
||||||
let data = icon.to_cardinals();
|
let data = icon.to_cardinals();
|
||||||
|
@ -1104,7 +1107,7 @@ impl UnownedWindow {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn set_window_icon(&self, icon: Option<Icon>) {
|
pub(crate) fn set_window_icon(&self, icon: Option<PlatformIcon>) {
|
||||||
match icon {
|
match icon {
|
||||||
Some(icon) => self.set_icon_inner(icon),
|
Some(icon) => self.set_icon_inner(icon),
|
||||||
None => self.unset_icon_inner(),
|
None => self.unset_icon_inner(),
|
||||||
|
@ -1565,7 +1568,7 @@ impl UnownedWindow {
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn scale_factor(&self) -> f64 {
|
pub fn scale_factor(&self) -> f64 {
|
||||||
self.current_monitor().scale_factor
|
self.shared_state_lock().last_monitor.scale_factor
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_cursor_position_physical(&self, x: i32, y: i32) -> Result<(), ExternalError> {
|
pub fn set_cursor_position_physical(&self, x: i32, y: i32) -> Result<(), ExternalError> {
|
||||||
|
@ -1806,6 +1809,8 @@ impl UnownedWindow {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn set_content_protected(&self, _protected: bool) {}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn has_focus(&self) -> bool {
|
pub fn has_focus(&self) -> bool {
|
||||||
self.shared_state_lock().has_focus
|
self.shared_state_lock().has_focus
|
||||||
|
|
|
@ -27,7 +27,9 @@ use super::appkit::{NSApp, NSApplication, NSApplicationActivationPolicy, NSEvent
|
||||||
use crate::{
|
use crate::{
|
||||||
error::EventLoopError,
|
error::EventLoopError,
|
||||||
event::Event,
|
event::Event,
|
||||||
event_loop::{ControlFlow, EventLoopClosed, EventLoopWindowTarget as RootWindowTarget},
|
event_loop::{
|
||||||
|
ControlFlow, DeviceEvents, EventLoopClosed, EventLoopWindowTarget as RootWindowTarget,
|
||||||
|
},
|
||||||
platform::{macos::ActivationPolicy, pump_events::PumpStatus},
|
platform::{macos::ActivationPolicy, pump_events::PumpStatus},
|
||||||
platform_impl::platform::{
|
platform_impl::platform::{
|
||||||
app::WinitApplication,
|
app::WinitApplication,
|
||||||
|
@ -84,6 +86,9 @@ impl<T: 'static> EventLoopWindowTarget<T> {
|
||||||
Some(monitor)
|
Some(monitor)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn listen_device_events(&self, _allowed: DeviceEvents) {}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn raw_display_handle(&self) -> RawDisplayHandle {
|
pub fn raw_display_handle(&self) -> RawDisplayHandle {
|
||||||
RawDisplayHandle::AppKit(AppKitDisplayHandle::empty())
|
RawDisplayHandle::AppKit(AppKitDisplayHandle::empty())
|
||||||
|
|
|
@ -15,7 +15,7 @@ use raw_window_handle::{OrbitalDisplayHandle, RawDisplayHandle};
|
||||||
use crate::{
|
use crate::{
|
||||||
error::EventLoopError,
|
error::EventLoopError,
|
||||||
event::{self, Ime, Modifiers, StartCause},
|
event::{self, Ime, Modifiers, StartCause},
|
||||||
event_loop::{self, ControlFlow},
|
event_loop::{self, ControlFlow, DeviceEvents},
|
||||||
keyboard::{
|
keyboard::{
|
||||||
Key, KeyCode, KeyLocation, ModifiersKeys, ModifiersState, NativeKey, NativeKeyCode,
|
Key, KeyCode, KeyLocation, ModifiersKeys, ModifiersState, NativeKey, NativeKeyCode,
|
||||||
},
|
},
|
||||||
|
@ -765,6 +765,9 @@ impl<T: 'static> EventLoopWindowTarget<T> {
|
||||||
v
|
v
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn listen_device_events(&self, _allowed: DeviceEvents) {}
|
||||||
|
|
||||||
pub fn raw_display_handle(&self) -> RawDisplayHandle {
|
pub fn raw_display_handle(&self) -> RawDisplayHandle {
|
||||||
RawDisplayHandle::Orbital(OrbitalDisplayHandle::empty())
|
RawDisplayHandle::Orbital(OrbitalDisplayHandle::empty())
|
||||||
}
|
}
|
||||||
|
|
|
@ -426,6 +426,8 @@ impl Window {
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn set_theme(&self, _theme: Option<window::Theme>) {}
|
pub fn set_theme(&self, _theme: Option<window::Theme>) {}
|
||||||
|
|
||||||
|
pub fn set_content_protected(&self, _protected: bool) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Drop for Window {
|
impl Drop for Window {
|
||||||
|
|
|
@ -379,6 +379,8 @@ impl Inner {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn set_content_protected(&self, _protected: bool) {}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn has_focus(&self) -> bool {
|
pub fn has_focus(&self) -> bool {
|
||||||
self.has_focus.load(Ordering::Relaxed)
|
self.has_focus.load(Ordering::Relaxed)
|
||||||
|
|
|
@ -1273,10 +1273,9 @@ impl Window {
|
||||||
/// - **iOS / Android / x11 / Wayland / Web / Orbital:** Unsupported.
|
/// - **iOS / Android / x11 / Wayland / Web / Orbital:** Unsupported.
|
||||||
///
|
///
|
||||||
/// [`NSWindowSharingNone`]: https://developer.apple.com/documentation/appkit/nswindowsharingtype/nswindowsharingnone
|
/// [`NSWindowSharingNone`]: https://developer.apple.com/documentation/appkit/nswindowsharingtype/nswindowsharingnone
|
||||||
pub fn set_content_protected(&self, _protected: bool) {
|
pub fn set_content_protected(&self, protected: bool) {
|
||||||
#[cfg(any(macos_platform, windows_platform))]
|
|
||||||
self.window
|
self.window
|
||||||
.maybe_queue_on_main(move |w| w.set_content_protected(_protected))
|
.maybe_queue_on_main(move |w| w.set_content_protected(protected))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Gets the current title of the window.
|
/// Gets the current title of the window.
|
||||||
|
|
Loading…
Reference in a new issue