Slightly reduce number of cfgs (#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:
Mads Marquart 2023-09-01 23:14:16 +02:00 committed by GitHub
parent 67b041e231
commit a06ea45c0f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
19 changed files with 121 additions and 125 deletions

View file

@ -23,11 +23,11 @@ use crate::{
event_loop::AsyncRequestSerial,
platform_impl::{
x11::{atoms::*, MonitorHandle as X11MonitorHandle, WakeSender, X11Error},
Fullscreen, MonitorHandle as PlatformMonitorHandle, OsError,
Fullscreen, MonitorHandle as PlatformMonitorHandle, OsError, PlatformIcon,
PlatformSpecificWindowBuilderAttributes, VideoMode as PlatformVideoMode,
},
window::{
CursorGrabMode, CursorIcon, Icon, ImePurpose, ResizeDirection, Theme, UserAttentionType,
CursorGrabMode, CursorIcon, ImePurpose, ResizeDirection, Theme, UserAttentionType,
WindowAttributes, WindowButtons, WindowLevel,
},
};
@ -469,7 +469,7 @@ impl UnownedWindow {
// Set window icons
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
@ -778,7 +778,9 @@ impl UnownedWindow {
Fullscreen::Borderless(Some(PlatformMonitorHandle::X(monitor))) => {
(None, monitor)
}
Fullscreen::Borderless(None) => (None, self.current_monitor()),
Fullscreen::Borderless(None) => {
(None, self.shared_state_lock().last_monitor.clone())
}
#[cfg(wayland_platform)]
_ => unreachable!(),
};
@ -874,9 +876,8 @@ impl UnownedWindow {
}
}
#[inline]
pub fn current_monitor(&self) -> X11MonitorHandle {
self.shared_state_lock().last_monitor.clone()
pub fn current_monitor(&self) -> Option<X11MonitorHandle> {
Some(self.shared_state_lock().last_monitor.clone())
}
pub fn available_monitors(&self) -> Vec<X11MonitorHandle> {
@ -885,10 +886,12 @@ impl UnownedWindow {
.expect("Failed to get available monitors")
}
pub fn primary_monitor(&self) -> X11MonitorHandle {
self.xconn
.primary_monitor()
.expect("Failed to get primary monitor")
pub fn primary_monitor(&self) -> Option<X11MonitorHandle> {
Some(
self.xconn
.primary_monitor()
.expect("Failed to get primary monitor"),
)
}
#[inline]
@ -1077,7 +1080,7 @@ impl UnownedWindow {
.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 icon_atom = atoms[_NET_WM_ICON];
let data = icon.to_cardinals();
@ -1104,7 +1107,7 @@ impl UnownedWindow {
}
#[inline]
pub fn set_window_icon(&self, icon: Option<Icon>) {
pub(crate) fn set_window_icon(&self, icon: Option<PlatformIcon>) {
match icon {
Some(icon) => self.set_icon_inner(icon),
None => self.unset_icon_inner(),
@ -1565,7 +1568,7 @@ impl UnownedWindow {
#[inline]
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> {
@ -1806,6 +1809,8 @@ impl UnownedWindow {
None
}
pub fn set_content_protected(&self, _protected: bool) {}
#[inline]
pub fn has_focus(&self) -> bool {
self.shared_state_lock().has_focus