Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slightly reduce number of cfgs #3071

Merged
merged 5 commits into from
Sep 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,7 @@ pub struct KeyEvent {
// Allowing `broken_intra_doc_links` for `logical_key`, because
// `key_without_modifiers` is not available on all platforms
#[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)
)]
/// This value is affected by all modifiers except <kbd>Ctrl</kbd>.
Expand Down
5 changes: 2 additions & 3 deletions src/event_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,9 +374,8 @@ impl<T> EventLoopWindowTarget<T> {
/// - **Wayland / macOS / iOS / Android / Orbital:** Unsupported.
///
/// [`DeviceEvent`]: crate::event::DeviceEvent
pub fn listen_device_events(&self, _allowed: DeviceEvents) {
#[cfg(any(x11_platform, wasm_platform, wayland_platform, windows))]
self.p.listen_device_events(_allowed);
pub fn listen_device_events(&self, allowed: DeviceEvents) {
self.p.listen_device_events(allowed);
}
}

Expand Down
7 changes: 6 additions & 1 deletion src/platform_impl/android/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use crate::{
dpi::{PhysicalPosition, PhysicalSize, Position, Size},
error,
event::{self, InnerSizeWriter, StartCause},
event_loop::{self, ControlFlow, EventLoopWindowTarget as RootELW},
event_loop::{self, ControlFlow, DeviceEvents, EventLoopWindowTarget as RootELW},
platform::pump_events::PumpStatus,
window::{
self, CursorGrabMode, ImePurpose, ResizeDirection, Theme, WindowButtons, WindowLevel,
Expand Down Expand Up @@ -743,6 +743,9 @@ impl<T: 'static> EventLoopWindowTarget<T> {
v
}

#[inline]
pub fn listen_device_events(&self, _allowed: DeviceEvents) {}

pub fn raw_display_handle(&self) -> RawDisplayHandle {
RawDisplayHandle::Android(AndroidDisplayHandle::empty())
}
Expand Down Expand Up @@ -995,6 +998,8 @@ impl Window {
None
}

pub fn set_content_protected(&self, _protected: bool) {}

pub fn has_focus(&self) -> bool {
*HAS_FOCUS.read().unwrap()
}
Expand Down
6 changes: 5 additions & 1 deletion src/platform_impl/ios/event_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ use crate::{
error::EventLoopError,
event::Event,
event_loop::{
ControlFlow, EventLoopClosed, EventLoopWindowTarget as RootEventLoopWindowTarget,
ControlFlow, DeviceEvents, EventLoopClosed,
EventLoopWindowTarget as RootEventLoopWindowTarget,
},
platform::ios::Idiom,
};
Expand All @@ -45,6 +46,9 @@ impl<T: 'static> EventLoopWindowTarget<T> {
Some(MonitorHandle::new(UIScreen::main(self.mtm)))
}

#[inline]
pub fn listen_device_events(&self, _allowed: DeviceEvents) {}

pub fn raw_display_handle(&self) -> RawDisplayHandle {
RawDisplayHandle::UiKit(UiKitDisplayHandle::empty())
}
Expand Down
2 changes: 2 additions & 0 deletions src/platform_impl/ios/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,8 @@ impl Inner {
None
}

pub fn set_content_protected(&self, _protected: bool) {}

pub fn has_focus(&self) -> bool {
self.window.isKeyWindow()
}
Expand Down
93 changes: 21 additions & 72 deletions src/platform_impl/linux/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ impl VideoMode {

#[inline]
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)
}
}

Expand Down Expand Up @@ -316,12 +316,7 @@ impl Window {

#[inline]
pub fn id(&self) -> WindowId {
match self {
#[cfg(wayland_platform)]
Self::Wayland(window) => window.id(),
#[cfg(x11_platform)]
Self::X(window) => window.id(),
}
x11_or_wayland!(match self; Window(w) => w.id())
}

#[inline]
Expand Down Expand Up @@ -500,23 +495,13 @@ impl Window {
}

#[inline]
pub fn set_window_level(&self, _level: WindowLevel) {
match self {
#[cfg(x11_platform)]
Window::X(ref w) => w.set_window_level(_level),
#[cfg(wayland_platform)]
Window::Wayland(_) => (),
}
pub fn set_window_level(&self, level: WindowLevel) {
x11_or_wayland!(match self; Window(w) => w.set_window_level(level))
}

#[inline]
pub fn set_window_icon(&self, _window_icon: Option<Icon>) {
match self {
#[cfg(x11_platform)]
Window::X(ref w) => w.set_window_icon(_window_icon),
#[cfg(wayland_platform)]
Window::Wayland(_) => (),
}
pub fn set_window_icon(&self, window_icon: Option<Icon>) {
x11_or_wayland!(match self; Window(w) => w.set_window_icon(window_icon.map(|icon| icon.inner)))
}

#[inline]
Expand All @@ -541,12 +526,7 @@ impl Window {

#[inline]
pub fn focus_window(&self) {
match self {
#[cfg(x11_platform)]
Window::X(ref w) => w.focus_window(),
#[cfg(wayland_platform)]
Window::Wayland(_) => (),
}
x11_or_wayland!(match self; Window(w) => w.focus_window())
}
pub fn request_user_attention(&self, request_type: Option<UserAttentionType>) {
x11_or_wayland!(match self; Window(w) => w.request_user_attention(request_type))
Expand All @@ -564,18 +544,7 @@ impl Window {

#[inline]
pub fn current_monitor(&self) -> Option<MonitorHandle> {
match self {
#[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)
}
}
Some(x11_or_wayland!(match self; Window(w) => w.current_monitor()?; as MonitorHandle))
}

#[inline]
Expand All @@ -598,15 +567,7 @@ impl Window {

#[inline]
pub fn primary_monitor(&self) -> Option<MonitorHandle> {
match self {
#[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(),
}
Some(x11_or_wayland!(match self; Window(w) => w.primary_monitor()?; as MonitorHandle))
}

#[inline]
Expand All @@ -629,6 +590,10 @@ impl Window {
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]
pub fn has_focus(&self) -> bool {
x11_or_wayland!(match self; Window(window) => window.has_focus())
Expand Down Expand Up @@ -843,41 +808,25 @@ impl<T> EventLoopWindowTarget<T> {
#[cfg(wayland_platform)]
EventLoopWindowTarget::Wayland(ref evlp) => evlp
.available_monitors()
.into_iter()
.map(MonitorHandle::Wayland)
.collect(),
#[cfg(x11_platform)]
EventLoopWindowTarget::X(ref evlp) => evlp
.x_connection()
.available_monitors()
.into_iter()
.flatten()
.map(MonitorHandle::X)
.collect(),
EventLoopWindowTarget::X(ref evlp) => {
evlp.available_monitors().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) => {
let primary_monitor = MonitorHandle::X(evlp.x_connection().primary_monitor().ok()?);
Some(primary_monitor)
}
}
Some(
x11_or_wayland!(match self; EventLoopWindowTarget(evlp) => evlp.primary_monitor()?; as MonitorHandle),
)
}

#[inline]
pub fn listen_device_events(&self, _allowed: DeviceEvents) {
match *self {
#[cfg(wayland_platform)]
EventLoopWindowTarget::Wayland(_) => (),
#[cfg(x11_platform)]
EventLoopWindowTarget::X(ref evlp) => evlp.set_listen_device_events(_allowed),
}
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 {
Expand Down
7 changes: 6 additions & 1 deletion src/platform_impl/linux/wayland/event_loop/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ use sctk::reexports::client::{Connection, Proxy, QueueHandle, WaylandSource};
use crate::dpi::{LogicalSize, PhysicalSize};
use crate::error::{EventLoopError, OsError as RootOsError};
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_impl::platform::min_timeout;
use crate::platform_impl::platform::sticky_exit_callback;
Expand Down Expand Up @@ -681,6 +683,9 @@ pub struct EventLoopWindowTarget<T> {
}

impl<T> EventLoopWindowTarget<T> {
#[inline]
pub fn listen_device_events(&self, _allowed: DeviceEvents) {}

pub fn raw_display_handle(&self) -> RawDisplayHandle {
let mut display_handle = WaylandDisplayHandle::empty();
display_handle.display = self.connection.display().id().as_ptr() as *mut _;
Expand Down
13 changes: 5 additions & 8 deletions src/platform_impl/linux/wayland/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,22 @@ use sctk::reexports::client::Proxy;
use sctk::output::OutputData;

use crate::dpi::{PhysicalPosition, PhysicalSize};
use crate::platform_impl::platform::{
MonitorHandle as PlatformMonitorHandle, VideoMode as PlatformVideoMode,
};
use crate::platform_impl::platform::VideoMode as PlatformVideoMode;

use super::event_loop::EventLoopWindowTarget;

impl<T> EventLoopWindowTarget<T> {
#[inline]
pub fn available_monitors(&self) -> Vec<MonitorHandle> {
pub fn available_monitors(&self) -> impl Iterator<Item = MonitorHandle> {
self.state
.borrow()
.output_state
.outputs()
.map(MonitorHandle::new)
.collect()
}

#[inline]
pub fn primary_monitor(&self) -> Option<PlatformMonitorHandle> {
pub fn primary_monitor(&self) -> Option<MonitorHandle> {
// There's no primary monitor on Wayland.
None
}
Expand Down Expand Up @@ -157,7 +154,7 @@ impl VideoMode {
self.refresh_rate_millihertz
}

pub fn monitor(&self) -> PlatformMonitorHandle {
PlatformMonitorHandle::Wayland(self.monitor.clone())
pub fn monitor(&self) -> MonitorHandle {
self.monitor.clone()
}
}
17 changes: 14 additions & 3 deletions src/platform_impl/linux/wayland/window/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ use crate::error::{ExternalError, NotSupportedError, OsError as RootOsError};
use crate::event::{Ime, WindowEvent};
use crate::event_loop::AsyncRequestSerial;
use crate::platform_impl::{
Fullscreen, MonitorHandle as PlatformMonitorHandle, OsError,
Fullscreen, MonitorHandle as PlatformMonitorHandle, OsError, PlatformIcon,
PlatformSpecificWindowBuilderAttributes as PlatformAttributes,
};
use crate::window::{
CursorGrabMode, CursorIcon, ImePurpose, ResizeDirection, Theme, UserAttentionType,
WindowAttributes, WindowButtons,
WindowAttributes, WindowButtons, WindowLevel,
};

use super::event_loop::sink::EventSink;
Expand Down Expand Up @@ -419,6 +419,12 @@ impl Window {
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]
pub fn set_minimized(&self, minimized: bool) {
// You can't unminimize the window on Wayland.
Expand Down Expand Up @@ -612,6 +618,9 @@ impl Window {
self.window_state.lock().unwrap().set_ime_purpose(purpose);
}

#[inline]
pub fn focus_window(&self) {}

#[inline]
pub fn surface(&self) -> &WlSurface {
self.window.wl_surface()
Expand All @@ -629,7 +638,7 @@ impl Window {
}

#[inline]
pub fn primary_monitor(&self) -> Option<PlatformMonitorHandle> {
pub fn primary_monitor(&self) -> Option<MonitorHandle> {
// XXX there's no such concept on Wayland.
None
}
Expand Down Expand Up @@ -658,6 +667,8 @@ impl Window {
self.window_state.lock().unwrap().theme()
}

pub fn set_content_protected(&self, _protected: bool) {}

#[inline]
pub fn title(&self) -> String {
self.window_state.lock().unwrap().title().to_owned()
Expand Down
3 changes: 2 additions & 1 deletion src/platform_impl/linux/x11/event_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1317,7 +1317,8 @@ impl<T: 'static> EventProcessor<T> {
for (window_id, window) in wt.windows.borrow().iter() {
if let Some(window) = window.upgrade() {
// 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 {
let (width, height) = window.inner_size_physical();
let (new_width, new_height) = window.adjust_for_dpi(
Expand Down
10 changes: 9 additions & 1 deletion src/platform_impl/linux/x11/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,15 @@ impl<T> EventLoopWindowTarget<T> {
&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);
}

Expand Down
Loading
Loading