diff --git a/dpi/src/lib.rs b/dpi/src/lib.rs index 942d40a5cf..04b7df00bc 100644 --- a/dpi/src/lib.rs +++ b/dpi/src/lib.rs @@ -761,9 +761,10 @@ impl From> for Position { #[cfg(test)] mod tests { - use super::*; use std::collections::HashSet; + use super::*; + macro_rules! test_pixel_int_impl { ($($name:ident => $ty:ty),*) => {$( #[test] diff --git a/examples/control_flow.rs b/examples/control_flow.rs index a6076ed050..1dbbe06163 100644 --- a/examples/control_flow.rs +++ b/examples/control_flow.rs @@ -7,7 +7,6 @@ use std::time; use ::tracing::{info, warn}; #[cfg(web_platform)] use web_time as time; - use winit::application::ApplicationHandler; use winit::event::{ElementState, KeyEvent, StartCause, WindowEvent}; use winit::event_loop::{ActiveEventLoop, ControlFlow, EventLoop}; diff --git a/examples/window.rs b/examples/window.rs index c92f0ce96b..5ad1eed312 100644 --- a/examples/window.rs +++ b/examples/window.rs @@ -14,23 +14,21 @@ use cursor_icon::CursorIcon; use rwh_06::{DisplayHandle, HasDisplayHandle}; #[cfg(not(any(android_platform, ios_platform)))] use softbuffer::{Context, Surface}; - use winit::application::ApplicationHandler; use winit::dpi::{LogicalSize, PhysicalPosition, PhysicalSize}; use winit::event::{DeviceEvent, DeviceId, Ime, MouseButton, MouseScrollDelta, WindowEvent}; use winit::event_loop::{ActiveEventLoop, EventLoop}; use winit::keyboard::{Key, ModifiersState}; -use winit::window::{ - Cursor, CursorGrabMode, CustomCursor, CustomCursorSource, Fullscreen, Icon, ResizeDirection, - Theme, Window, WindowId, -}; - #[cfg(macos_platform)] use winit::platform::macos::{OptionAsAlt, WindowAttributesExtMacOS, WindowExtMacOS}; #[cfg(any(x11_platform, wayland_platform))] use winit::platform::startup_notify::{ self, EventLoopExtStartupNotify, WindowAttributesExtStartupNotify, WindowExtStartupNotify, }; +use winit::window::{ + Cursor, CursorGrabMode, CustomCursor, CustomCursorSource, Fullscreen, Icon, ResizeDirection, + Theme, Window, WindowId, +}; #[path = "util/tracing.rs"] mod tracing; @@ -705,6 +703,7 @@ impl WindowState { custom_cursors: &[CustomCursor], ) { use std::time::Duration; + use winit::platform::web::CustomCursorExtWebSys; let cursors = vec![ diff --git a/rustfmt.toml b/rustfmt.toml index e10d6b0027..722943bb56 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -11,6 +11,7 @@ error_on_unformatted = true format_macro_bodies = true hex_literal_case = "Lower" normalize_comments = true +group_imports = "StdExternalCrate" # Some macros break with this. reorder_impl_items = false newline_style = "Unix" diff --git a/src/event.rs b/src/event.rs index 86a992e2e2..25a1f51601 100644 --- a/src/event.rs +++ b/src/event.rs @@ -1004,9 +1004,10 @@ impl PartialEq for InnerSizeWriter { #[cfg(test)] mod tests { + use std::collections::{BTreeSet, HashSet}; + use crate::dpi::PhysicalPosition; use crate::event; - use std::collections::{BTreeSet, HashSet}; macro_rules! foreach_event { ($closure:expr) => {{ diff --git a/src/event_loop.rs b/src/event_loop.rs index abfdee2978..f83ef7828c 100644 --- a/src/event_loop.rs +++ b/src/event_loop.rs @@ -13,9 +13,9 @@ use std::marker::PhantomData; #[cfg(any(x11_platform, wayland_platform))] use std::os::unix::io::{AsFd, AsRawFd, BorrowedFd, RawFd}; use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering}; - #[cfg(not(web_platform))] use std::time::{Duration, Instant}; + #[cfg(web_platform)] use web_time::{Duration, Instant}; diff --git a/src/icon.rs b/src/icon.rs index b013d2f049..ba497cf8ea 100644 --- a/src/icon.rs +++ b/src/icon.rs @@ -1,7 +1,8 @@ -use crate::platform_impl::PlatformIcon; use std::error::Error; use std::{fmt, io, mem}; +use crate::platform_impl::PlatformIcon; + #[repr(C)] #[derive(Debug)] pub(crate) struct Pixel { diff --git a/src/keyboard.rs b/src/keyboard.rs index 49d55c1e1f..8c7005fe17 100644 --- a/src/keyboard.rs +++ b/src/keyboard.rs @@ -1758,9 +1758,10 @@ bitflags! { #[cfg(feature = "serde")] mod modifiers_serde { - use super::ModifiersState; use serde::{Deserialize, Deserializer, Serialize, Serializer}; + use super::ModifiersState; + #[derive(Default, Serialize, Deserialize)] #[serde(default)] #[serde(rename = "ModifiersState")] diff --git a/src/lib.rs b/src/lib.rs index 57a3bb62c2..8f850560a3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -177,6 +177,9 @@ #![cfg_attr(docsrs, feature(doc_auto_cfg, doc_cfg_hide), doc(cfg_hide(doc, docsrs)))] #![allow(clippy::missing_safety_doc)] +// Re-export DPI types so that users don't have to put it in Cargo.toml. +#[doc(inline)] +pub use dpi; #[cfg(feature = "rwh_04")] pub use rwh_04 as raw_window_handle_04; #[cfg(feature = "rwh_05")] @@ -184,10 +187,6 @@ pub use rwh_05 as raw_window_handle_05; #[cfg(feature = "rwh_06")] pub use rwh_06 as raw_window_handle; -// Re-export DPI types so that users don't have to put it in Cargo.toml. -#[doc(inline)] -pub use dpi; - pub mod application; #[cfg(any(doc, doctest, test))] pub mod changelog; diff --git a/src/platform/android.rs b/src/platform/android.rs index 46a46423fd..6c84214952 100644 --- a/src/platform/android.rs +++ b/src/platform/android.rs @@ -70,11 +70,10 @@ //! 4. Pass a clone of the `AndroidApp` that your application receives to Winit when building your //! event loop (as shown above). +use self::activity::{AndroidApp, ConfigurationRef, Rect}; use crate::event_loop::{ActiveEventLoop, EventLoop, EventLoopBuilder}; use crate::window::{Window, WindowAttributes}; -use self::activity::{AndroidApp, ConfigurationRef, Rect}; - /// Additional methods on [`EventLoop`] that are specific to Android. pub trait EventLoopExtAndroid {} diff --git a/src/platform/run_on_demand.rs b/src/platform/run_on_demand.rs index ac965ee139..3f8737de98 100644 --- a/src/platform/run_on_demand.rs +++ b/src/platform/run_on_demand.rs @@ -1,7 +1,6 @@ use crate::application::ApplicationHandler; use crate::error::EventLoopError; use crate::event_loop::{ActiveEventLoop, EventLoop}; - #[cfg(doc)] use crate::{platform::pump_events::EventLoopExtPumpEvents, window::Window}; diff --git a/src/platform/wayland.rs b/src/platform/wayland.rs index 28adf42ceb..f9b339f947 100644 --- a/src/platform/wayland.rs +++ b/src/platform/wayland.rs @@ -15,9 +15,8 @@ //! * `wayland-csd-adwaita-notitle`. use crate::event_loop::{ActiveEventLoop, EventLoop, EventLoopBuilder}; use crate::monitor::MonitorHandle; -use crate::window::{Window, WindowAttributes}; - pub use crate::window::Theme; +use crate::window::{Window, WindowAttributes}; /// Additional methods on [`ActiveEventLoop`] that are specific to Wayland. pub trait ActiveEventLoopExtWayland { diff --git a/src/platform/windows.rs b/src/platform/windows.rs index c1956bb7c9..664be87ed0 100644 --- a/src/platform/windows.rs +++ b/src/platform/windows.rs @@ -337,6 +337,7 @@ pub trait WindowExtWindows { /// # use winit::window::Window; /// # fn scope(window: Window) { /// use std::thread; + /// /// use winit::platform::windows::WindowExtWindows; /// use winit::raw_window_handle::HasWindowHandle; /// diff --git a/src/platform/x11.rs b/src/platform/x11.rs index 663dc704b6..7f1e245446 100644 --- a/src/platform/x11.rs +++ b/src/platform/x11.rs @@ -2,12 +2,11 @@ #[cfg(feature = "serde")] use serde::{Deserialize, Serialize}; +use crate::dpi::Size; use crate::event_loop::{ActiveEventLoop, EventLoop, EventLoopBuilder}; use crate::monitor::MonitorHandle; use crate::window::{Window, WindowAttributes}; -use crate::dpi::Size; - /// X window type. Maps directly to /// [`_NET_WM_WINDOW_TYPE`](https://specifications.freedesktop.org/wm-spec/wm-spec-1.5.html). #[derive(Debug, Default, Copy, Clone, PartialEq, Eq, Hash)] diff --git a/src/platform_impl/apple/appkit/app_state.rs b/src/platform_impl/apple/appkit/app_state.rs index e0ed74c5af..b90a85c7c5 100644 --- a/src/platform_impl/apple/appkit/app_state.rs +++ b/src/platform_impl/apple/appkit/app_state.rs @@ -10,15 +10,14 @@ use objc2::{declare_class, msg_send_id, mutability, ClassType, DeclaredClass}; use objc2_app_kit::{NSApplication, NSApplicationActivationPolicy, NSApplicationDelegate}; use objc2_foundation::{MainThreadMarker, NSNotification, NSObject, NSObjectProtocol}; -use crate::application::ApplicationHandler; -use crate::event::{StartCause, WindowEvent}; -use crate::event_loop::{ActiveEventLoop as RootActiveEventLoop, ControlFlow}; -use crate::window::WindowId as RootWindowId; - use super::event_handler::EventHandler; use super::event_loop::{stop_app_immediately, ActiveEventLoop, PanicInfo}; use super::observer::{EventLoopWaker, RunLoop}; use super::{menu, WindowId}; +use crate::application::ApplicationHandler; +use crate::event::{StartCause, WindowEvent}; +use crate::event_loop::{ActiveEventLoop as RootActiveEventLoop, ControlFlow}; +use crate::window::WindowId as RootWindowId; #[derive(Debug)] pub(super) struct AppState { diff --git a/src/platform_impl/apple/appkit/mod.rs b/src/platform_impl/apple/appkit/mod.rs index 2c3d3e3032..9ed0e05396 100644 --- a/src/platform_impl/apple/appkit/mod.rs +++ b/src/platform_impl/apple/appkit/mod.rs @@ -17,19 +17,17 @@ mod window_delegate; use std::fmt; +pub(crate) use self::cursor::CustomCursor as PlatformCustomCursor; pub(crate) use self::event::{physicalkey_to_scancode, scancode_to_physicalkey, KeyEventExtra}; pub(crate) use self::event_loop::{ ActiveEventLoop, EventLoop, EventLoopProxy, OwnedDisplayHandle, PlatformSpecificEventLoopAttributes, }; pub(crate) use self::monitor::{MonitorHandle, VideoModeHandle}; -pub(crate) use self::window::WindowId; +pub(crate) use self::window::{Window, WindowId}; pub(crate) use self::window_delegate::PlatformSpecificWindowAttributes; -use crate::event::DeviceId as RootDeviceId; - -pub(crate) use self::cursor::CustomCursor as PlatformCustomCursor; -pub(crate) use self::window::Window; pub(crate) use crate::cursor::OnlyCursorImageSource as PlatformCustomCursorSource; +use crate::event::DeviceId as RootDeviceId; pub(crate) use crate::icon::NoIcon as PlatformIcon; pub(crate) use crate::platform_impl::Fullscreen; diff --git a/src/platform_impl/apple/uikit/event_loop.rs b/src/platform_impl/apple/uikit/event_loop.rs index d628d25581..72e1b48548 100644 --- a/src/platform_impl/apple/uikit/event_loop.rs +++ b/src/platform_impl/apple/uikit/event_loop.rs @@ -17,17 +17,15 @@ use objc2::{msg_send_id, ClassType}; use objc2_foundation::{MainThreadMarker, NSString}; use objc2_ui_kit::{UIApplication, UIApplicationMain, UIScreen}; -use super::app_state::EventLoopHandler; +use super::app_delegate::AppDelegate; +use super::app_state::{AppState, EventLoopHandler}; +use super::{app_state, monitor, MonitorHandle}; use crate::application::ApplicationHandler; use crate::error::EventLoopError; use crate::event::Event; use crate::event_loop::{ActiveEventLoop as RootActiveEventLoop, ControlFlow, DeviceEvents}; use crate::window::{CustomCursor, CustomCursorSource}; -use super::app_delegate::AppDelegate; -use super::app_state::AppState; -use super::{app_state, monitor, MonitorHandle}; - #[derive(Debug)] pub struct ActiveEventLoop { pub(super) mtm: MainThreadMarker, diff --git a/src/platform_impl/apple/uikit/mod.rs b/src/platform_impl/apple/uikit/mod.rs index f69ac21b79..8eb839e787 100644 --- a/src/platform_impl/apple/uikit/mod.rs +++ b/src/platform_impl/apple/uikit/mod.rs @@ -10,8 +10,6 @@ mod window; use std::fmt; -use crate::event::DeviceId as RootDeviceId; - pub(crate) use self::event_loop::{ ActiveEventLoop, EventLoop, EventLoopProxy, OwnedDisplayHandle, PlatformSpecificEventLoopAttributes, @@ -21,6 +19,7 @@ pub(crate) use self::window::{PlatformSpecificWindowAttributes, Window, WindowId pub(crate) use crate::cursor::{ NoCustomCursor as PlatformCustomCursor, NoCustomCursor as PlatformCustomCursorSource, }; +use crate::event::DeviceId as RootDeviceId; pub(crate) use crate::icon::NoIcon as PlatformIcon; pub(crate) use crate::platform_impl::Fullscreen; diff --git a/src/platform_impl/linux/common/xkb/compose.rs b/src/platform_impl/linux/common/xkb/compose.rs index 9d4f590aec..3b5ddca134 100644 --- a/src/platform_impl/linux/common/xkb/compose.rs +++ b/src/platform_impl/linux/common/xkb/compose.rs @@ -6,13 +6,14 @@ use std::ops::Deref; use std::os::unix::ffi::OsStringExt; use std::ptr::NonNull; -use super::{XkbContext, XKBCH}; use smol_str::SmolStr; use xkbcommon_dl::{ xkb_compose_compile_flags, xkb_compose_feed_result, xkb_compose_state, xkb_compose_state_flags, xkb_compose_status, xkb_compose_table, xkb_keysym_t, }; +use super::{XkbContext, XKBCH}; + #[derive(Debug)] pub struct XkbComposeTable { table: NonNull, diff --git a/src/platform_impl/linux/common/xkb/keymap.rs b/src/platform_impl/linux/common/xkb/keymap.rs index 67aac5c19a..32a942820e 100644 --- a/src/platform_impl/linux/common/xkb/keymap.rs +++ b/src/platform_impl/linux/common/xkb/keymap.rs @@ -6,14 +6,13 @@ use std::ptr::{self, NonNull}; #[cfg(x11_platform)] use x11_dl::xlib_xcb::xcb_connection_t; -#[cfg(wayland_platform)] -use {memmap2::MmapOptions, std::os::unix::io::OwnedFd}; - use xkb::XKB_MOD_INVALID; use xkbcommon_dl::{ self as xkb, xkb_keycode_t, xkb_keymap, xkb_keymap_compile_flags, xkb_keysym_t, xkb_layout_index_t, xkb_mod_index_t, }; +#[cfg(wayland_platform)] +use {memmap2::MmapOptions, std::os::unix::io::OwnedFd}; use crate::keyboard::{Key, KeyCode, KeyLocation, NamedKey, NativeKey, NativeKeyCode, PhysicalKey}; #[cfg(x11_platform)] diff --git a/src/platform_impl/linux/common/xkb/mod.rs b/src/platform_impl/linux/common/xkb/mod.rs index 0b951b666c..d516883f5a 100644 --- a/src/platform_impl/linux/common/xkb/mod.rs +++ b/src/platform_impl/linux/common/xkb/mod.rs @@ -1,12 +1,11 @@ use std::ops::Deref; use std::os::raw::c_char; +#[cfg(wayland_platform)] +use std::os::unix::io::OwnedFd; use std::ptr::{self, NonNull}; use std::sync::atomic::{AtomicBool, Ordering}; -use crate::utils::Lazy; use smol_str::SmolStr; -#[cfg(wayland_platform)] -use std::os::unix::io::OwnedFd; use tracing::warn; use xkbcommon_dl::{ self as xkb, xkb_compose_status, xkb_context, xkb_context_flags, xkbcommon_compose_handle, @@ -18,16 +17,16 @@ use {x11_dl::xlib_xcb::xcb_connection_t, xkbcommon_dl::x11::xkbcommon_x11_handle use crate::event::{ElementState, KeyEvent}; use crate::keyboard::{Key, KeyLocation}; use crate::platform_impl::KeyEventExtra; +use crate::utils::Lazy; mod compose; mod keymap; mod state; use compose::{ComposeStatus, XkbComposeState, XkbComposeTable}; -use keymap::XkbKeymap; - #[cfg(x11_platform)] pub use keymap::raw_keycode_to_physicalkey; +use keymap::XkbKeymap; pub use keymap::{physicalkey_to_scancode, scancode_to_physicalkey}; pub use state::XkbState; diff --git a/src/platform_impl/linux/mod.rs b/src/platform_impl/linux/mod.rs index 3bd2d252bc..c75945211e 100644 --- a/src/platform_impl/linux/mod.rs +++ b/src/platform_impl/linux/mod.rs @@ -11,31 +11,30 @@ use std::{env, fmt}; #[cfg(x11_platform)] use std::{ffi::CStr, mem::MaybeUninit, os::raw::*, sync::Mutex}; -use crate::application::ApplicationHandler; -use crate::platform::pump_events::PumpStatus; -#[cfg(x11_platform)] -use crate::utils::Lazy; use smol_str::SmolStr; +pub(crate) use self::common::xkb::{physicalkey_to_scancode, scancode_to_physicalkey}; #[cfg(x11_platform)] use self::x11::{X11Error, XConnection, XError, XNotSupported}; +use crate::application::ApplicationHandler; +pub(crate) use crate::cursor::OnlyCursorImageSource as PlatformCustomCursorSource; use crate::dpi::{PhysicalPosition, PhysicalSize, Position, Size}; use crate::error::{EventLoopError, ExternalError, NotSupportedError, OsError as RootOsError}; use crate::event_loop::{AsyncRequestSerial, ControlFlow, DeviceEvents}; use crate::icon::Icon; +pub(crate) use crate::icon::RgbaIcon as PlatformIcon; use crate::keyboard::Key; +use crate::platform::pump_events::PumpStatus; #[cfg(x11_platform)] use crate::platform::x11::{WindowType as XWindowType, XlibErrorHook}; +pub(crate) use crate::platform_impl::Fullscreen; +#[cfg(x11_platform)] +use crate::utils::Lazy; use crate::window::{ ActivationToken, Cursor, CursorGrabMode, CustomCursor, CustomCursorSource, ImePurpose, ResizeDirection, Theme, UserAttentionType, WindowAttributes, WindowButtons, WindowLevel, }; -pub(crate) use self::common::xkb::{physicalkey_to_scancode, scancode_to_physicalkey}; -pub(crate) use crate::cursor::OnlyCursorImageSource as PlatformCustomCursorSource; -pub(crate) use crate::icon::RgbaIcon as PlatformIcon; -pub(crate) use crate::platform_impl::Fullscreen; - pub(crate) mod common; #[cfg(wayland_platform)] pub(crate) mod wayland; diff --git a/src/platform_impl/linux/wayland/event_loop/sink.rs b/src/platform_impl/linux/wayland/event_loop/sink.rs index ac3fb633c9..a313a621ce 100644 --- a/src/platform_impl/linux/wayland/event_loop/sink.rs +++ b/src/platform_impl/linux/wayland/event_loop/sink.rs @@ -2,12 +2,11 @@ use std::vec::Drain; +use super::{DeviceId, WindowId}; use crate::event::{DeviceEvent, DeviceId as RootDeviceId, Event, WindowEvent}; use crate::platform_impl::platform::DeviceId as PlatformDeviceId; use crate::window::WindowId as RootWindowId; -use super::{DeviceId, WindowId}; - /// An event loop's sink to deliver events from the Wayland event callbacks /// to the winit's user. #[derive(Default)] diff --git a/src/platform_impl/linux/wayland/mod.rs b/src/platform_impl/linux/wayland/mod.rs index 674671ff8c..07aad45db2 100644 --- a/src/platform_impl/linux/wayland/mod.rs +++ b/src/platform_impl/linux/wayland/mod.rs @@ -3,16 +3,16 @@ use std::fmt::Display; use std::sync::Arc; +pub use event_loop::{ActiveEventLoop, EventLoop, EventLoopProxy}; +pub use output::{MonitorHandle, VideoModeHandle}; use sctk::reexports::client::globals::{BindError, GlobalError}; use sctk::reexports::client::protocol::wl_surface::WlSurface; use sctk::reexports::client::{self, ConnectError, DispatchError, Proxy}; +pub use window::Window; pub(super) use crate::cursor::OnlyCursorImage as CustomCursor; use crate::dpi::{LogicalSize, PhysicalSize}; pub use crate::platform_impl::platform::{OsError, WindowId}; -pub use event_loop::{ActiveEventLoop, EventLoop, EventLoopProxy}; -pub use output::{MonitorHandle, VideoModeHandle}; -pub use window::Window; mod event_loop; mod output; diff --git a/src/platform_impl/linux/wayland/output.rs b/src/platform_impl/linux/wayland/output.rs index ae6c1b0695..2095afdcc1 100644 --- a/src/platform_impl/linux/wayland/output.rs +++ b/src/platform_impl/linux/wayland/output.rs @@ -1,13 +1,11 @@ +use sctk::output::OutputData; use sctk::reexports::client::protocol::wl_output::WlOutput; use sctk::reexports::client::Proxy; -use sctk::output::OutputData; - +use super::event_loop::ActiveEventLoop; use crate::dpi::{LogicalPosition, PhysicalPosition, PhysicalSize}; use crate::platform_impl::platform::VideoModeHandle as PlatformVideoModeHandle; -use super::event_loop::ActiveEventLoop; - impl ActiveEventLoop { #[inline] pub fn available_monitors(&self) -> impl Iterator { diff --git a/src/platform_impl/linux/wayland/seat/keyboard/mod.rs b/src/platform_impl/linux/wayland/seat/keyboard/mod.rs index ef4f99520b..2ce88cd76b 100644 --- a/src/platform_impl/linux/wayland/seat/keyboard/mod.rs +++ b/src/platform_impl/linux/wayland/seat/keyboard/mod.rs @@ -5,17 +5,15 @@ use std::time::Duration; use calloop::timer::{TimeoutAction, Timer}; use calloop::{LoopHandle, RegistrationToken}; -use tracing::warn; - use sctk::reexports::client::protocol::wl_keyboard::{ Event as WlKeyboardEvent, KeyState as WlKeyState, KeymapFormat as WlKeymapFormat, WlKeyboard, }; use sctk::reexports::client::protocol::wl_seat::WlSeat; use sctk::reexports::client::{Connection, Dispatch, Proxy, QueueHandle, WEnum}; +use tracing::warn; use crate::event::{ElementState, WindowEvent}; use crate::keyboard::ModifiersState; - use crate::platform_impl::common::xkb::Context; use crate::platform_impl::wayland::event_loop::sink::EventSink; use crate::platform_impl::wayland::state::WinitState; diff --git a/src/platform_impl/linux/wayland/seat/mod.rs b/src/platform_impl/linux/wayland/seat/mod.rs index 82e38e5414..36af28a535 100644 --- a/src/platform_impl/linux/wayland/seat/mod.rs +++ b/src/platform_impl/linux/wayland/seat/mod.rs @@ -3,17 +3,15 @@ use std::sync::Arc; use ahash::AHashMap; -use tracing::warn; - use sctk::reexports::client::backend::ObjectId; use sctk::reexports::client::protocol::wl_seat::WlSeat; use sctk::reexports::client::protocol::wl_touch::WlTouch; use sctk::reexports::client::{Connection, Proxy, QueueHandle}; use sctk::reexports::protocols::wp::relative_pointer::zv1::client::zwp_relative_pointer_v1::ZwpRelativePointerV1; use sctk::reexports::protocols::wp::text_input::zv3::client::zwp_text_input_v3::ZwpTextInputV3; - use sctk::seat::pointer::{ThemeSpec, ThemedPointer}; use sctk::seat::{Capability as SeatCapability, SeatHandler, SeatState}; +use tracing::warn; use crate::event::WindowEvent; use crate::keyboard::ModifiersState; @@ -24,12 +22,11 @@ mod pointer; mod text_input; mod touch; +use keyboard::{KeyboardData, KeyboardState}; pub use pointer::relative_pointer::RelativePointerState; pub use pointer::{PointerConstraintsState, WinitPointerData, WinitPointerDataExt}; -pub use text_input::{TextInputState, ZwpTextInputV3Ext}; - -use keyboard::{KeyboardData, KeyboardState}; use text_input::TextInputData; +pub use text_input::{TextInputState, ZwpTextInputV3Ext}; use touch::TouchPoint; #[derive(Debug, Default)] diff --git a/src/platform_impl/linux/wayland/seat/text_input/mod.rs b/src/platform_impl/linux/wayland/seat/text_input/mod.rs index 49d9363597..dff3723513 100644 --- a/src/platform_impl/linux/wayland/seat/text_input/mod.rs +++ b/src/platform_impl/linux/wayland/seat/text_input/mod.rs @@ -1,11 +1,9 @@ use std::ops::Deref; use sctk::globals::GlobalData; -use sctk::reexports::client::{Connection, Proxy, QueueHandle}; - use sctk::reexports::client::globals::{BindError, GlobalList}; use sctk::reexports::client::protocol::wl_surface::WlSurface; -use sctk::reexports::client::{delegate_dispatch, Dispatch}; +use sctk::reexports::client::{delegate_dispatch, Connection, Dispatch, Proxy, QueueHandle}; use sctk::reexports::protocols::wp::text_input::zv3::client::zwp_text_input_manager_v3::ZwpTextInputManagerV3; use sctk::reexports::protocols::wp::text_input::zv3::client::zwp_text_input_v3::{ ContentHint, ContentPurpose, Event as TextInputEvent, ZwpTextInputV3, diff --git a/src/platform_impl/linux/wayland/seat/touch/mod.rs b/src/platform_impl/linux/wayland/seat/touch/mod.rs index 124504feea..f4d2c14de5 100644 --- a/src/platform_impl/linux/wayland/seat/touch/mod.rs +++ b/src/platform_impl/linux/wayland/seat/touch/mod.rs @@ -1,17 +1,14 @@ //! Touch handling. -use tracing::warn; - use sctk::reexports::client::protocol::wl_seat::WlSeat; use sctk::reexports::client::protocol::wl_surface::WlSurface; use sctk::reexports::client::protocol::wl_touch::WlTouch; use sctk::reexports::client::{Connection, Proxy, QueueHandle}; - use sctk::seat::touch::{TouchData, TouchHandler}; +use tracing::warn; use crate::dpi::LogicalPosition; use crate::event::{Touch, TouchPhase, WindowEvent}; - use crate::platform_impl::wayland::state::WinitState; use crate::platform_impl::wayland::{self, DeviceId}; diff --git a/src/platform_impl/linux/wayland/state.rs b/src/platform_impl/linux/wayland/state.rs index b7b1e498be..b3379b364c 100644 --- a/src/platform_impl/linux/wayland/state.rs +++ b/src/platform_impl/linux/wayland/state.rs @@ -3,16 +3,14 @@ use std::sync::atomic::Ordering; use std::sync::{Arc, Mutex}; use ahash::AHashMap; - +use sctk::compositor::{CompositorHandler, CompositorState}; +use sctk::output::{OutputHandler, OutputState}; use sctk::reexports::calloop::LoopHandle; use sctk::reexports::client::backend::ObjectId; use sctk::reexports::client::globals::GlobalList; use sctk::reexports::client::protocol::wl_output::WlOutput; use sctk::reexports::client::protocol::wl_surface::WlSurface; use sctk::reexports::client::{Connection, Proxy, QueueHandle}; - -use sctk::compositor::{CompositorHandler, CompositorState}; -use sctk::output::{OutputHandler, OutputState}; use sctk::registry::{ProvidesRegistryState, RegistryState}; use sctk::seat::pointer::ThemedPointer; use sctk::seat::SeatState; diff --git a/src/platform_impl/linux/wayland/types/cursor.rs b/src/platform_impl/linux/wayland/types/cursor.rs index c1a0c2613a..83eeb47c1e 100644 --- a/src/platform_impl/linux/wayland/types/cursor.rs +++ b/src/platform_impl/linux/wayland/types/cursor.rs @@ -1,5 +1,4 @@ use cursor_icon::CursorIcon; - use sctk::reexports::client::protocol::wl_shm::Format; use sctk::shm::slot::{Buffer, SlotPool}; diff --git a/src/platform_impl/linux/wayland/types/kwin_blur.rs b/src/platform_impl/linux/wayland/types/kwin_blur.rs index 83e82ad78a..ed9bf18daa 100644 --- a/src/platform_impl/linux/wayland/types/kwin_blur.rs +++ b/src/platform_impl/linux/wayland/types/kwin_blur.rs @@ -1,13 +1,12 @@ //! Handling of KDE-compatible blur. +use sctk::globals::GlobalData; use sctk::reexports::client::globals::{BindError, GlobalList}; use sctk::reexports::client::protocol::wl_surface::WlSurface; use sctk::reexports::client::{delegate_dispatch, Connection, Dispatch, Proxy, QueueHandle}; use wayland_protocols_plasma::blur::client::org_kde_kwin_blur::OrgKdeKwinBlur; use wayland_protocols_plasma::blur::client::org_kde_kwin_blur_manager::OrgKdeKwinBlurManager; -use sctk::globals::GlobalData; - use crate::platform_impl::wayland::state::WinitState; /// KWin blur manager. diff --git a/src/platform_impl/linux/wayland/types/wp_fractional_scaling.rs b/src/platform_impl/linux/wayland/types/wp_fractional_scaling.rs index 2dfc9dbbe5..a1db8e54fa 100644 --- a/src/platform_impl/linux/wayland/types/wp_fractional_scaling.rs +++ b/src/platform_impl/linux/wayland/types/wp_fractional_scaling.rs @@ -1,5 +1,6 @@ //! Handling of the fractional scaling. +use sctk::globals::GlobalData; use sctk::reexports::client::globals::{BindError, GlobalList}; use sctk::reexports::client::protocol::wl_surface::WlSurface; use sctk::reexports::client::{delegate_dispatch, Connection, Dispatch, Proxy, QueueHandle}; @@ -8,8 +9,6 @@ use sctk::reexports::protocols::wp::fractional_scale::v1::client::wp_fractional_ Event as FractionalScalingEvent, WpFractionalScaleV1, }; -use sctk::globals::GlobalData; - use crate::platform_impl::wayland::state::WinitState; /// The scaling factor denominator. diff --git a/src/platform_impl/linux/wayland/types/wp_viewporter.rs b/src/platform_impl/linux/wayland/types/wp_viewporter.rs index 90764825d0..81b3ebd0c6 100644 --- a/src/platform_impl/linux/wayland/types/wp_viewporter.rs +++ b/src/platform_impl/linux/wayland/types/wp_viewporter.rs @@ -1,13 +1,12 @@ //! Handling of the wp-viewporter. +use sctk::globals::GlobalData; use sctk::reexports::client::globals::{BindError, GlobalList}; use sctk::reexports::client::protocol::wl_surface::WlSurface; use sctk::reexports::client::{delegate_dispatch, Connection, Dispatch, Proxy, QueueHandle}; use sctk::reexports::protocols::wp::viewporter::client::wp_viewport::WpViewport; use sctk::reexports::protocols::wp::viewporter::client::wp_viewporter::WpViewporter; -use sctk::globals::GlobalData; - use crate::platform_impl::wayland::state::WinitState; /// Viewporter. diff --git a/src/platform_impl/linux/wayland/types/xdg_activation.rs b/src/platform_impl/linux/wayland/types/xdg_activation.rs index 8bd21d0abb..2a638d3c97 100644 --- a/src/platform_impl/linux/wayland/types/xdg_activation.rs +++ b/src/platform_impl/linux/wayland/types/xdg_activation.rs @@ -3,6 +3,7 @@ use std::sync::atomic::AtomicBool; use std::sync::Weak; +use sctk::globals::GlobalData; use sctk::reexports::client::globals::{BindError, GlobalList}; use sctk::reexports::client::protocol::wl_surface::WlSurface; use sctk::reexports::client::{delegate_dispatch, Connection, Dispatch, Proxy, QueueHandle}; @@ -11,8 +12,6 @@ use sctk::reexports::protocols::xdg::activation::v1::client::xdg_activation_toke }; use sctk::reexports::protocols::xdg::activation::v1::client::xdg_activation_v1::XdgActivationV1; -use sctk::globals::GlobalData; - use crate::event_loop::AsyncRequestSerial; use crate::platform_impl::wayland::state::WinitState; use crate::platform_impl::WindowId; diff --git a/src/platform_impl/linux/wayland/window/mod.rs b/src/platform_impl/linux/wayland/window/mod.rs index 08e4504a83..8b5ea3a1f5 100644 --- a/src/platform_impl/linux/wayland/window/mod.rs +++ b/src/platform_impl/linux/wayland/window/mod.rs @@ -3,17 +3,20 @@ use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::{Arc, Mutex}; +use sctk::compositor::{CompositorState, Region, SurfaceData}; use sctk::reexports::client::protocol::wl_display::WlDisplay; use sctk::reexports::client::protocol::wl_surface::WlSurface; use sctk::reexports::client::{Proxy, QueueHandle}; - -use sctk::compositor::{CompositorState, Region, SurfaceData}; use sctk::reexports::protocols::xdg::activation::v1::client::xdg_activation_v1::XdgActivationV1; use sctk::shell::xdg::window::{Window as SctkWindow, WindowDecorations}; use sctk::shell::WaylandSurface; - use tracing::warn; +use super::event_loop::sink::EventSink; +use super::output::MonitorHandle; +use super::state::WinitState; +use super::types::xdg_activation::XdgActivationTokenData; +use super::{ActiveEventLoop, WaylandError, WindowId}; use crate::dpi::{LogicalSize, PhysicalPosition, PhysicalSize, Position, Size}; use crate::error::{ExternalError, NotSupportedError, OsError as RootOsError}; use crate::event::{Ime, WindowEvent}; @@ -26,12 +29,6 @@ use crate::window::{ WindowAttributes, WindowButtons, WindowLevel, }; -use super::event_loop::sink::EventSink; -use super::output::MonitorHandle; -use super::state::WinitState; -use super::types::xdg_activation::XdgActivationTokenData; -use super::{ActiveEventLoop, WaylandError, WindowId}; - pub(crate) mod state; pub use state::WindowState; diff --git a/src/platform_impl/linux/wayland/window/state.rs b/src/platform_impl/linux/wayland/window/state.rs index 7685b85952..9afff645a8 100644 --- a/src/platform_impl/linux/wayland/window/state.rs +++ b/src/platform_impl/linux/wayland/window/state.rs @@ -5,8 +5,7 @@ use std::sync::{Arc, Mutex, Weak}; use std::time::Duration; use ahash::HashSet; -use tracing::{info, warn}; - +use sctk::compositor::{CompositorState, Region, SurfaceData, SurfaceDataExt}; use sctk::reexports::client::backend::ObjectId; use sctk::reexports::client::protocol::wl_seat::WlSeat; use sctk::reexports::client::protocol::wl_shm::WlShm; @@ -19,8 +18,6 @@ use sctk::reexports::protocols::wp::fractional_scale::v1::client::wp_fractional_ use sctk::reexports::protocols::wp::text_input::zv3::client::zwp_text_input_v3::ZwpTextInputV3; use sctk::reexports::protocols::wp::viewporter::client::wp_viewport::WpViewport; use sctk::reexports::protocols::xdg::shell::client::xdg_toplevel::ResizeEdge as XdgResizeEdge; - -use sctk::compositor::{CompositorState, Region, SurfaceData, SurfaceDataExt}; use sctk::seat::pointer::{PointerDataExt, ThemedPointer}; use sctk::shell::xdg::window::{DecorationMode, Window, WindowConfigure}; use sctk::shell::xdg::XdgSurface; @@ -28,21 +25,21 @@ use sctk::shell::WaylandSurface; use sctk::shm::slot::SlotPool; use sctk::shm::Shm; use sctk::subcompositor::SubcompositorState; +use tracing::{info, warn}; use wayland_protocols_plasma::blur::client::org_kde_kwin_blur::OrgKdeKwinBlur; use crate::cursor::CustomCursor as RootCustomCursor; use crate::dpi::{LogicalPosition, LogicalSize, PhysicalSize, Size}; use crate::error::{ExternalError, NotSupportedError}; use crate::platform_impl::wayland::logical_to_physical_rounded; -use crate::platform_impl::wayland::types::cursor::{CustomCursor, SelectedCursor}; -use crate::platform_impl::wayland::types::kwin_blur::KWinBlurManager; -use crate::platform_impl::{PlatformCustomCursor, WindowId}; -use crate::window::{CursorGrabMode, CursorIcon, ImePurpose, ResizeDirection, Theme}; - use crate::platform_impl::wayland::seat::{ PointerConstraintsState, WinitPointerData, WinitPointerDataExt, ZwpTextInputV3Ext, }; use crate::platform_impl::wayland::state::{WindowCompositorUpdate, WinitState}; +use crate::platform_impl::wayland::types::cursor::{CustomCursor, SelectedCursor}; +use crate::platform_impl::wayland::types::kwin_blur::KWinBlurManager; +use crate::platform_impl::{PlatformCustomCursor, WindowId}; +use crate::window::{CursorGrabMode, CursorIcon, ImePurpose, ResizeDirection, Theme}; #[cfg(feature = "sctk-adwaita")] pub type WinitFrame = sctk_adwaita::AdwaitaFrame; diff --git a/src/platform_impl/linux/x11/activation.rs b/src/platform_impl/linux/x11/activation.rs index a5e961bb9d..3a3da9e90f 100644 --- a/src/platform_impl/linux/x11/activation.rs +++ b/src/platform_impl/linux/x11/activation.rs @@ -5,14 +5,14 @@ //! X11 has a "startup notification" specification similar to Wayland's, see this URL: //! -use super::atoms::*; -use super::{VoidCookie, X11Error, XConnection}; - use std::ffi::CString; use std::fmt::Write; use x11rb::protocol::xproto::{self, ConnectionExt as _}; +use super::atoms::*; +use super::{VoidCookie, X11Error, XConnection}; + impl XConnection { /// "Request" a new activation token from the server. pub(crate) fn request_activation_token(&self, window_title: &str) -> Result { diff --git a/src/platform_impl/linux/x11/atoms.rs b/src/platform_impl/linux/x11/atoms.rs index c6d96c8fe0..da98be098a 100644 --- a/src/platform_impl/linux/x11/atoms.rs +++ b/src/platform_impl/linux/x11/atoms.rs @@ -112,6 +112,7 @@ impl Index for Atoms { } } -pub(crate) use AtomName::*; // Make sure `None` is still defined. pub(crate) use core::option::Option::None; + +pub(crate) use AtomName::*; diff --git a/src/platform_impl/linux/x11/ime/callbacks.rs b/src/platform_impl/linux/x11/ime/callbacks.rs index c75724ec83..c4540b2d87 100644 --- a/src/platform_impl/linux/x11/ime/callbacks.rs +++ b/src/platform_impl/linux/x11/ime/callbacks.rs @@ -3,11 +3,10 @@ use std::os::raw::c_char; use std::ptr; use std::sync::Arc; -use super::{ffi, XConnection, XError}; - use super::context::{ImeContext, ImeContextCreationError}; use super::inner::{close_im, ImeInner}; use super::input_method::PotentialInputMethods; +use super::{ffi, XConnection, XError}; pub(crate) unsafe fn xim_set_callback( xconn: &Arc, diff --git a/src/platform_impl/linux/x11/ime/context.rs b/src/platform_impl/linux/x11/ime/context.rs index 89a241cce3..2ffaa9a32c 100644 --- a/src/platform_impl/linux/x11/ime/context.rs +++ b/src/platform_impl/linux/x11/ime/context.rs @@ -5,11 +5,10 @@ use std::{mem, ptr}; use x11_dl::xlib::{XIMCallback, XIMPreeditCaretCallbackStruct, XIMPreeditDrawCallbackStruct}; +use super::{ffi, util, XConnection, XError}; use crate::platform_impl::platform::x11::ime::input_method::{Style, XIMStyle}; use crate::platform_impl::platform::x11::ime::{ImeEvent, ImeEventSender}; -use super::{ffi, util, XConnection, XError}; - /// IME creation error. #[derive(Debug)] pub enum ImeContextCreationError { diff --git a/src/platform_impl/linux/x11/ime/inner.rs b/src/platform_impl/linux/x11/ime/inner.rs index 4d4f7cb473..0cb40b8a90 100644 --- a/src/platform_impl/linux/x11/ime/inner.rs +++ b/src/platform_impl/linux/x11/ime/inner.rs @@ -2,10 +2,9 @@ use std::collections::HashMap; use std::mem; use std::sync::Arc; -use super::{ffi, XConnection, XError}; - use super::context::ImeContext; use super::input_method::{InputMethod, PotentialInputMethods}; +use super::{ffi, XConnection, XError}; use crate::platform_impl::platform::x11::ime::ImeEventSender; pub(crate) unsafe fn close_im(xconn: &Arc, im: ffi::XIM) -> Result<(), XError> { diff --git a/src/platform_impl/linux/x11/ime/input_method.rs b/src/platform_impl/linux/x11/ime/input_method.rs index b9d3ca7101..3a068cc27c 100644 --- a/src/platform_impl/linux/x11/ime/input_method.rs +++ b/src/platform_impl/linux/x11/ime/input_method.rs @@ -3,9 +3,10 @@ use std::os::raw::{c_char, c_ulong, c_ushort}; use std::sync::{Arc, Mutex}; use std::{env, fmt, ptr}; +use x11rb::protocol::xproto; + use super::super::atoms::*; use super::{ffi, util, XConnection, XError}; -use x11rb::protocol::xproto; static GLOBAL_LOCK: Mutex<()> = Mutex::new(()); diff --git a/src/platform_impl/linux/x11/ime/mod.rs b/src/platform_impl/linux/x11/ime/mod.rs index 606e00d9f3..5af333d67e 100644 --- a/src/platform_impl/linux/x11/ime/mod.rs +++ b/src/platform_impl/linux/x11/ime/mod.rs @@ -12,13 +12,12 @@ use std::sync::Arc; use serde::{Deserialize, Serialize}; use tracing::debug; -use super::{ffi, util, XConnection, XError}; - use self::callbacks::*; use self::context::ImeContext; pub use self::context::ImeContextCreationError; use self::inner::{close_im, ImeInner}; use self::input_method::{PotentialInputMethods, Style}; +use super::{ffi, util, XConnection, XError}; #[derive(Debug, Clone, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] diff --git a/src/platform_impl/linux/x11/mod.rs b/src/platform_impl/linux/x11/mod.rs index a2a7382c88..389e1dac0a 100644 --- a/src/platform_impl/linux/x11/mod.rs +++ b/src/platform_impl/linux/x11/mod.rs @@ -16,7 +16,6 @@ use calloop::ping::Ping; use calloop::{EventLoop as Loop, Readiness}; use libc::{setlocale, LC_CTYPE}; use tracing::warn; - use x11rb::connection::RequestConnection; use x11rb::errors::{ConnectError, ConnectionError, IdsExhausted, ReplyError}; use x11rb::protocol::xinput::{self, ConnectionExt as _}; @@ -49,13 +48,12 @@ mod window; mod xdisplay; mod xsettings; -pub use util::CustomCursor; - use atoms::*; use dnd::{Dnd, DndState}; use event_processor::{EventProcessor, MAX_MOD_REPLAY_LEN}; use ime::{Ime, ImeCreationError, ImeReceiver, ImeRequest, ImeSender}; pub(crate) use monitor::{MonitorHandle, VideoModeHandle}; +pub use util::CustomCursor; use window::UnownedWindow; pub(crate) use xdisplay::{XConnection, XError, XNotSupported}; diff --git a/src/platform_impl/linux/x11/monitor.rs b/src/platform_impl/linux/x11/monitor.rs index 6580ac30de..2a26a26d90 100644 --- a/src/platform_impl/linux/x11/monitor.rs +++ b/src/platform_impl/linux/x11/monitor.rs @@ -1,10 +1,11 @@ -use super::{util, X11Error, XConnection}; -use crate::dpi::{PhysicalPosition, PhysicalSize}; -use crate::platform_impl::VideoModeHandle as PlatformVideoModeHandle; use x11rb::connection::RequestConnection; use x11rb::protocol::randr::{self, ConnectionExt as _}; use x11rb::protocol::xproto; +use super::{util, X11Error, XConnection}; +use crate::dpi::{PhysicalPosition, PhysicalSize}; +use crate::platform_impl::VideoModeHandle as PlatformVideoModeHandle; + // Used for testing. This should always be committed as false. const DISABLE_MONITOR_LIST_CACHING: bool = false; diff --git a/src/platform_impl/linux/x11/util/client_msg.rs b/src/platform_impl/linux/x11/util/client_msg.rs index cf5517764d..2a02eec1de 100644 --- a/src/platform_impl/linux/x11/util/client_msg.rs +++ b/src/platform_impl/linux/x11/util/client_msg.rs @@ -1,6 +1,7 @@ -use super::*; use x11rb::x11_utils::Serialize; +use super::*; + impl XConnection { pub fn send_client_msg( &self, diff --git a/src/platform_impl/linux/x11/util/cursor.rs b/src/platform_impl/linux/x11/util/cursor.rs index 169748d14d..c9522a5fb2 100644 --- a/src/platform_impl/linux/x11/util/cursor.rs +++ b/src/platform_impl/linux/x11/util/cursor.rs @@ -5,11 +5,10 @@ use std::{iter, slice}; use x11rb::connection::Connection; -use crate::platform_impl::PlatformCustomCursorSource; -use crate::window::CursorIcon; - use super::super::ActiveEventLoop; use super::*; +use crate::platform_impl::PlatformCustomCursorSource; +use crate::window::CursorIcon; impl XConnection { pub fn set_cursor_icon(&self, window: xproto::Window, cursor: Option) { diff --git a/src/platform_impl/linux/x11/util/hint.rs b/src/platform_impl/linux/x11/util/hint.rs index a31872d5b4..80de03c19f 100644 --- a/src/platform_impl/linux/x11/util/hint.rs +++ b/src/platform_impl/linux/x11/util/hint.rs @@ -1,7 +1,7 @@ -use crate::platform::x11::WindowType; use std::sync::Arc; use super::*; +use crate::platform::x11::WindowType; #[derive(Debug)] #[allow(dead_code)] diff --git a/src/platform_impl/linux/x11/util/input.rs b/src/platform_impl/linux/x11/util/input.rs index 37d21d1191..367e890154 100644 --- a/src/platform_impl/linux/x11/util/input.rs +++ b/src/platform_impl/linux/x11/util/input.rs @@ -1,4 +1,5 @@ use std::{slice, str}; + use x11rb::protocol::xinput::{self, ConnectionExt as _}; use x11rb::protocol::xkb; diff --git a/src/platform_impl/linux/x11/util/mod.rs b/src/platform_impl/linux/x11/util/mod.rs index 5c30293c31..47768b76c3 100644 --- a/src/platform_impl/linux/x11/util/mod.rs +++ b/src/platform_impl/linux/x11/util/mod.rs @@ -20,6 +20,8 @@ mod window_property; mod wm; mod xmodmap; +use x11rb::protocol::xproto::{self, ConnectionExt as _}; + pub use self::cursor::*; pub use self::geometry::*; pub use self::hint::*; @@ -28,10 +30,8 @@ pub use self::mouse::*; pub use self::window_property::*; pub use self::wm::*; pub use self::xmodmap::ModifierKeymap; - use super::atoms::*; use super::{ffi, VoidCookie, X11Error, XConnection, XError}; -use x11rb::protocol::xproto::{self, ConnectionExt as _}; pub fn maybe_change(field: &mut Option, value: T) -> bool { let wrapped = Some(value); diff --git a/src/platform_impl/linux/x11/util/randr.rs b/src/platform_impl/linux/x11/util/randr.rs index 6097bc517c..19df178a85 100644 --- a/src/platform_impl/linux/x11/util/randr.rs +++ b/src/platform_impl/linux/x11/util/randr.rs @@ -1,13 +1,13 @@ use std::str::FromStr; use std::{env, str}; +use tracing::warn; +use x11rb::protocol::randr::{self, ConnectionExt as _}; + use super::*; use crate::dpi::validate_scale_factor; use crate::platform_impl::platform::x11::{monitor, VideoModeHandle}; -use tracing::warn; -use x11rb::protocol::randr::{self, ConnectionExt as _}; - /// Represents values of `WINIT_HIDPI_FACTOR`. pub enum EnvVarDPI { Randr, diff --git a/src/platform_impl/linux/x11/util/window_property.rs b/src/platform_impl/linux/x11/util/window_property.rs index 0f4ca165d6..7329e7132f 100644 --- a/src/platform_impl/linux/x11/util/window_property.rs +++ b/src/platform_impl/linux/x11/util/window_property.rs @@ -3,7 +3,6 @@ use std::fmt; use std::sync::Arc; use bytemuck::{NoUninit, Pod}; - use x11rb::connection::Connection; use x11rb::errors::ReplyError; diff --git a/src/platform_impl/linux/x11/window.rs b/src/platform_impl/linux/x11/window.rs index b281b936f4..b5803afabd 100644 --- a/src/platform_impl/linux/x11/window.rs +++ b/src/platform_impl/linux/x11/window.rs @@ -13,6 +13,10 @@ use x11rb::protocol::xfixes::{ConnectionExt, RegionWrapper}; use x11rb::protocol::xproto::{self, ConnectionExt as _, Rectangle}; use x11rb::protocol::{randr, xinput}; +use super::util::{self, SelectedCursor}; +use super::{ + ffi, ActiveEventLoop, CookieResultExt, ImeRequest, ImeSender, VoidCookie, WindowId, XConnection, +}; use crate::cursor::{Cursor, CustomCursor as RootCustomCursor}; use crate::dpi::{PhysicalPosition, PhysicalSize, Position, Size}; use crate::error::{ExternalError, NotSupportedError, OsError as RootOsError}; @@ -32,11 +36,6 @@ use crate::window::{ WindowButtons, WindowLevel, }; -use super::util::{self, SelectedCursor}; -use super::{ - ffi, ActiveEventLoop, CookieResultExt, ImeRequest, ImeSender, VoidCookie, WindowId, XConnection, -}; - #[derive(Debug)] pub struct SharedState { pub cursor_pos: Option<(f64, f64)>, diff --git a/src/platform_impl/linux/x11/xdisplay.rs b/src/platform_impl/linux/x11/xdisplay.rs index 0a56f290a4..b1b870f313 100644 --- a/src/platform_impl/linux/x11/xdisplay.rs +++ b/src/platform_impl/linux/x11/xdisplay.rs @@ -4,17 +4,17 @@ use std::sync::atomic::{AtomicU32, Ordering}; use std::sync::{Arc, Mutex, RwLock, RwLockReadGuard}; use std::{fmt, ptr}; -use crate::window::CursorIcon; - -use super::atoms::Atoms; -use super::ffi; -use super::monitor::MonitorHandle; use x11rb::connection::Connection; use x11rb::protocol::randr::ConnectionExt as _; use x11rb::protocol::xproto::{self, ConnectionExt}; use x11rb::resource_manager; use x11rb::xcb_ffi::XCBConnection; +use super::atoms::Atoms; +use super::ffi; +use super::monitor::MonitorHandle; +use crate::window::CursorIcon; + /// A connection to an X server. pub struct XConnection { pub xlib: ffi::Xlib, diff --git a/src/platform_impl/mod.rs b/src/platform_impl/mod.rs index 446e4390f3..bd55440b89 100644 --- a/src/platform_impl/mod.rs +++ b/src/platform_impl/mod.rs @@ -22,13 +22,12 @@ use self::apple as platform; use self::linux as platform; #[cfg(orbital_platform)] use self::orbital as platform; +pub use self::platform::*; #[cfg(web_platform)] use self::web as platform; #[cfg(windows_platform)] use self::windows as platform; -pub use self::platform::*; - /// Helper for converting between platform-specific and generic /// [`VideoModeHandle`]/[`MonitorHandle`] #[derive(Clone, Debug, PartialEq, Eq)] diff --git a/src/platform_impl/orbital/event_loop.rs b/src/platform_impl/orbital/event_loop.rs index 06f85b3631..b709ce733f 100644 --- a/src/platform_impl/orbital/event_loop.rs +++ b/src/platform_impl/orbital/event_loop.rs @@ -12,6 +12,10 @@ use orbclient::{ }; use smol_str::SmolStr; +use super::{ + DeviceId, KeyEventExtra, MonitorHandle, OsError, PlatformSpecificEventLoopAttributes, + RedoxSocket, TimeSocket, WindowId, WindowProperties, +}; use crate::application::ApplicationHandler; use crate::error::EventLoopError; use crate::event::{self, Ime, Modifiers, StartCause}; @@ -24,11 +28,6 @@ use crate::window::{ CustomCursor as RootCustomCursor, CustomCursorSource, WindowId as RootWindowId, }; -use super::{ - DeviceId, KeyEventExtra, MonitorHandle, OsError, PlatformSpecificEventLoopAttributes, - RedoxSocket, TimeSocket, WindowId, WindowProperties, -}; - fn convert_scancode(scancode: u8) -> (PhysicalKey, Option) { // Key constants from https://docs.rs/orbclient/latest/orbclient/event/index.html let (key_code, named_key_opt) = match scancode { diff --git a/src/platform_impl/orbital/mod.rs b/src/platform_impl/orbital/mod.rs index f210a8ce04..2cfdd370de 100644 --- a/src/platform_impl/orbital/mod.rs +++ b/src/platform_impl/orbital/mod.rs @@ -6,10 +6,9 @@ use std::sync::Arc; use smol_str::SmolStr; +pub(crate) use self::event_loop::{ActiveEventLoop, EventLoop, EventLoopProxy, OwnedDisplayHandle}; use crate::dpi::{PhysicalPosition, PhysicalSize}; use crate::keyboard::Key; - -pub(crate) use self::event_loop::{ActiveEventLoop, EventLoop, EventLoopProxy, OwnedDisplayHandle}; mod event_loop; pub use self::window::Window; diff --git a/src/platform_impl/orbital/window.rs b/src/platform_impl/orbital/window.rs index d90d6a4584..e92740398a 100644 --- a/src/platform_impl/orbital/window.rs +++ b/src/platform_impl/orbital/window.rs @@ -1,16 +1,15 @@ use std::collections::VecDeque; use std::sync::{Arc, Mutex}; +use super::{ + ActiveEventLoop, MonitorHandle, OsError, RedoxSocket, TimeSocket, WindowId, WindowProperties, +}; use crate::cursor::Cursor; use crate::dpi::{PhysicalPosition, PhysicalSize, Position, Size}; use crate::platform_impl::Fullscreen; use crate::window::ImePurpose; use crate::{error, window}; -use super::{ - ActiveEventLoop, MonitorHandle, OsError, RedoxSocket, TimeSocket, WindowId, WindowProperties, -}; - // These values match the values uses in the `window_new` function in orbital: // https://gitlab.redox-os.org/redox-os/orbital/-/blob/master/src/scheme.rs const ORBITAL_FLAG_ASYNC: char = 'a'; diff --git a/src/platform_impl/web/async/dispatcher.rs b/src/platform_impl/web/async/dispatcher.rs index dffb04e92f..b024042223 100644 --- a/src/platform_impl/web/async/dispatcher.rs +++ b/src/platform_impl/web/async/dispatcher.rs @@ -1,9 +1,10 @@ -use super::super::main_thread::MainThreadMarker; -use super::{channel, Receiver, Sender, Wrapper}; use std::cell::Ref; use std::rc::Rc; use std::sync::{Arc, Condvar, Mutex}; +use super::super::main_thread::MainThreadMarker; +use super::{channel, Receiver, Sender, Wrapper}; + pub struct Dispatcher(Wrapper>>, Closure>); struct Closure(Box); diff --git a/src/platform_impl/web/async/mod.rs b/src/platform_impl/web/async/mod.rs index 4681cf9240..d372c7f69c 100644 --- a/src/platform_impl/web/async/mod.rs +++ b/src/platform_impl/web/async/mod.rs @@ -9,11 +9,12 @@ mod notifier; mod waker; mod wrapper; +use atomic_waker::AtomicWaker; +use concurrent_queue::{ConcurrentQueue, PushError}; + pub use self::abortable::{AbortHandle, Abortable, DropAbortHandle}; pub use self::channel::{channel, Receiver, Sender}; pub use self::dispatcher::{DispatchRunner, Dispatcher}; pub use self::notifier::{Notified, Notifier}; pub use self::waker::{Waker, WakerSpawner}; use self::wrapper::Wrapper; -use atomic_waker::AtomicWaker; -use concurrent_queue::{ConcurrentQueue, PushError}; diff --git a/src/platform_impl/web/async/wrapper.rs b/src/platform_impl/web/async/wrapper.rs index 2c7f6940d4..8d6de2f659 100644 --- a/src/platform_impl/web/async/wrapper.rs +++ b/src/platform_impl/web/async/wrapper.rs @@ -1,9 +1,10 @@ -use super::super::main_thread::MainThreadMarker; use std::cell::{Ref, RefCell}; use std::future::Future; use std::marker::PhantomData; use std::sync::Arc; +use super::super::main_thread::MainThreadMarker; + // Unsafe wrapper type that allows us to use `T` when it's not `Send` from other threads. // `value` **must** only be accessed on the main thread. pub struct Wrapper { diff --git a/src/platform_impl/web/event_loop/mod.rs b/src/platform_impl/web/event_loop/mod.rs index 874ab70be0..cc5ce82d93 100644 --- a/src/platform_impl/web/event_loop/mod.rs +++ b/src/platform_impl/web/event_loop/mod.rs @@ -1,13 +1,12 @@ use std::marker::PhantomData; +use super::{backend, device, window}; use crate::application::ApplicationHandler; use crate::error::EventLoopError; use crate::event::Event; use crate::event_loop::ActiveEventLoop as RootActiveEventLoop; use crate::platform::web::{ActiveEventLoopExtWebSys, PollStrategy, WaitUntilStrategy}; -use super::{backend, device, window}; - mod proxy; pub(crate) mod runner; mod state; diff --git a/src/platform_impl/web/event_loop/runner.rs b/src/platform_impl/web/event_loop/runner.rs index 5a7bbbb826..0663fcba96 100644 --- a/src/platform_impl/web/event_loop/runner.rs +++ b/src/platform_impl/web/event_loop/runner.rs @@ -1,3 +1,15 @@ +use std::cell::{Cell, RefCell}; +use std::collections::{HashSet, VecDeque}; +use std::iter; +use std::ops::Deref; +use std::rc::{Rc, Weak}; + +use js_sys::Function; +use wasm_bindgen::prelude::{wasm_bindgen, Closure}; +use wasm_bindgen::JsCast; +use web_sys::{Document, KeyboardEvent, PageTransitionEvent, PointerEvent, WheelEvent}; +use web_time::{Duration, Instant}; + use super::super::main_thread::MainThreadMarker; use super::super::DeviceId; use super::backend; @@ -14,17 +26,6 @@ use crate::platform_impl::platform::r#async::{DispatchRunner, Waker, WakerSpawne use crate::platform_impl::platform::window::Inner; use crate::window::WindowId; -use js_sys::Function; -use std::cell::{Cell, RefCell}; -use std::collections::{HashSet, VecDeque}; -use std::iter; -use std::ops::Deref; -use std::rc::{Rc, Weak}; -use wasm_bindgen::prelude::{wasm_bindgen, Closure}; -use wasm_bindgen::JsCast; -use web_sys::{Document, KeyboardEvent, PageTransitionEvent, PointerEvent, WheelEvent}; -use web_time::{Duration, Instant}; - pub struct Shared(Rc); pub(super) type EventHandler = dyn FnMut(Event); diff --git a/src/platform_impl/web/event_loop/state.rs b/src/platform_impl/web/event_loop/state.rs index d06e30edd6..f1ac134026 100644 --- a/src/platform_impl/web/event_loop/state.rs +++ b/src/platform_impl/web/event_loop/state.rs @@ -1,7 +1,7 @@ -use super::backend; - use web_time::Instant; +use super::backend; + #[derive(Debug)] pub enum State { Init, diff --git a/src/platform_impl/web/mod.rs b/src/platform_impl/web/mod.rs index 969d8bb188..9c2403425a 100644 --- a/src/platform_impl/web/mod.rs +++ b/src/platform_impl/web/mod.rs @@ -31,20 +31,20 @@ mod monitor; mod web_sys; mod window; +pub(crate) use cursor::{ + CustomCursor as PlatformCustomCursor, CustomCursorFuture, + CustomCursorSource as PlatformCustomCursorSource, +}; + pub use self::device::DeviceId; pub use self::error::OsError; pub(crate) use self::event_loop::{ ActiveEventLoop, EventLoop, EventLoopProxy, OwnedDisplayHandle, PlatformSpecificEventLoopAttributes, }; -pub use self::monitor::{MonitorHandle, VideoModeHandle}; -pub use self::window::{PlatformSpecificWindowAttributes, Window, WindowId}; - pub(crate) use self::keyboard::KeyEventExtra; +pub use self::monitor::{MonitorHandle, VideoModeHandle}; use self::web_sys as backend; +pub use self::window::{PlatformSpecificWindowAttributes, Window, WindowId}; pub(crate) use crate::icon::NoIcon as PlatformIcon; pub(crate) use crate::platform_impl::Fullscreen; -pub(crate) use cursor::{ - CustomCursor as PlatformCustomCursor, CustomCursorFuture, - CustomCursorSource as PlatformCustomCursorSource, -}; diff --git a/src/platform_impl/web/web_sys/animation_frame.rs b/src/platform_impl/web/web_sys/animation_frame.rs index 17aa8f6808..fde7ae28cd 100644 --- a/src/platform_impl/web/web_sys/animation_frame.rs +++ b/src/platform_impl/web/web_sys/animation_frame.rs @@ -1,5 +1,6 @@ use std::cell::Cell; use std::rc::Rc; + use wasm_bindgen::closure::Closure; use wasm_bindgen::JsCast; diff --git a/src/platform_impl/web/web_sys/canvas.rs b/src/platform_impl/web/web_sys/canvas.rs index 6f6524994d..f515bbf5ce 100644 --- a/src/platform_impl/web/web_sys/canvas.rs +++ b/src/platform_impl/web/web_sys/canvas.rs @@ -11,13 +11,6 @@ use web_sys::{ PointerEvent, WheelEvent, }; -use crate::dpi::{LogicalPosition, PhysicalPosition, PhysicalSize}; -use crate::error::OsError as RootOE; -use crate::event::{Force, InnerSizeWriter, MouseButton, MouseScrollDelta}; -use crate::keyboard::{Key, KeyLocation, ModifiersState, PhysicalKey}; -use crate::platform_impl::OsError; -use crate::window::{WindowAttributes, WindowId as RootWindowId}; - use super::super::cursor::CursorHandler; use super::super::main_thread::MainThreadMarker; use super::super::WindowId; @@ -27,6 +20,12 @@ use super::intersection_handle::IntersectionObserverHandle; use super::media_query_handle::MediaQueryListHandle; use super::pointer::PointerHandler; use super::{event, fullscreen, ButtonsState, ResizeScaleHandle}; +use crate::dpi::{LogicalPosition, PhysicalPosition, PhysicalSize}; +use crate::error::OsError as RootOE; +use crate::event::{Force, InnerSizeWriter, MouseButton, MouseScrollDelta}; +use crate::keyboard::{Key, KeyLocation, ModifiersState, PhysicalKey}; +use crate::platform_impl::OsError; +use crate::window::{WindowAttributes, WindowId as RootWindowId}; #[allow(dead_code)] pub struct Canvas { diff --git a/src/platform_impl/web/web_sys/event.rs b/src/platform_impl/web/web_sys/event.rs index ddd125765c..7d38fabdd1 100644 --- a/src/platform_impl/web/web_sys/event.rs +++ b/src/platform_impl/web/web_sys/event.rs @@ -1,14 +1,14 @@ -use crate::event::{MouseButton, MouseScrollDelta}; -use crate::keyboard::{Key, KeyLocation, ModifiersState, NamedKey, PhysicalKey}; +use std::cell::OnceCell; use dpi::{LogicalPosition, PhysicalPosition, Position}; use smol_str::SmolStr; -use std::cell::OnceCell; use wasm_bindgen::prelude::wasm_bindgen; use wasm_bindgen::{JsCast, JsValue}; use web_sys::{KeyboardEvent, MouseEvent, PointerEvent, WheelEvent}; use super::Engine; +use crate::event::{MouseButton, MouseScrollDelta}; +use crate::keyboard::{Key, KeyLocation, ModifiersState, NamedKey, PhysicalKey}; bitflags::bitflags! { // https://www.w3.org/TR/pointerevents3/#the-buttons-property diff --git a/src/platform_impl/web/web_sys/mod.rs b/src/platform_impl/web/web_sys/mod.rs index 08962b49bc..97019666b6 100644 --- a/src/platform_impl/web/web_sys/mod.rs +++ b/src/platform_impl/web/web_sys/mod.rs @@ -11,13 +11,6 @@ mod schedule; use std::sync::OnceLock; -pub use self::canvas::{Canvas, Style}; -pub use self::event::ButtonsState; -pub use self::event_handle::EventListenerHandle; -pub use self::resize_scaling::ResizeScaleHandle; -pub use self::schedule::Schedule; - -use crate::dpi::{LogicalPosition, LogicalSize}; use js_sys::Array; use wasm_bindgen::closure::Closure; use wasm_bindgen::prelude::wasm_bindgen; @@ -26,6 +19,13 @@ use web_sys::{ Document, HtmlCanvasElement, Navigator, PageTransitionEvent, VisibilityState, Window, }; +pub use self::canvas::{Canvas, Style}; +pub use self::event::ButtonsState; +pub use self::event_handle::EventListenerHandle; +pub use self::resize_scaling::ResizeScaleHandle; +pub use self::schedule::Schedule; +use crate::dpi::{LogicalPosition, LogicalSize}; + pub fn throw(msg: &str) { wasm_bindgen::throw_str(msg); } diff --git a/src/platform_impl/web/web_sys/pointer.rs b/src/platform_impl/web/web_sys/pointer.rs index 90e8b27b7f..f5e9365d5c 100644 --- a/src/platform_impl/web/web_sys/pointer.rs +++ b/src/platform_impl/web/web_sys/pointer.rs @@ -1,6 +1,9 @@ use std::cell::Cell; use std::rc::Rc; +use event::ButtonsState; +use web_sys::PointerEvent; + use super::canvas::Common; use super::event; use super::event_handle::EventListenerHandle; @@ -8,9 +11,6 @@ use crate::dpi::PhysicalPosition; use crate::event::{Force, MouseButton}; use crate::keyboard::ModifiersState; -use event::ButtonsState; -use web_sys::PointerEvent; - #[allow(dead_code)] pub(super) struct PointerHandler { on_cursor_leave: Option>, diff --git a/src/platform_impl/web/web_sys/resize_scaling.rs b/src/platform_impl/web/web_sys/resize_scaling.rs index fdfda75acd..3d19008bf1 100644 --- a/src/platform_impl/web/web_sys/resize_scaling.rs +++ b/src/platform_impl/web/web_sys/resize_scaling.rs @@ -1,3 +1,6 @@ +use std::cell::{Cell, RefCell}; +use std::rc::Rc; + use js_sys::{Array, Object}; use tracing::warn; use wasm_bindgen::prelude::{wasm_bindgen, Closure}; @@ -7,14 +10,10 @@ use web_sys::{ ResizeObserverEntry, ResizeObserverOptions, ResizeObserverSize, Window, }; -use crate::dpi::{LogicalSize, PhysicalSize}; - use super::super::backend; use super::canvas::Style; use super::media_query_handle::MediaQueryListHandle; - -use std::cell::{Cell, RefCell}; -use std::rc::Rc; +use crate::dpi::{LogicalSize, PhysicalSize}; pub struct ResizeScaleHandle(Rc); diff --git a/src/platform_impl/web/web_sys/schedule.rs b/src/platform_impl/web/web_sys/schedule.rs index 935e9b7978..48ba50e4cf 100644 --- a/src/platform_impl/web/web_sys/schedule.rs +++ b/src/platform_impl/web/web_sys/schedule.rs @@ -1,6 +1,7 @@ -use js_sys::{Array, Function, Object, Promise, Reflect}; use std::cell::OnceCell; use std::time::Duration; + +use js_sys::{Array, Function, Object, Promise, Reflect}; use wasm_bindgen::closure::Closure; use wasm_bindgen::prelude::wasm_bindgen; use wasm_bindgen::{JsCast, JsValue}; diff --git a/src/platform_impl/web/window.rs b/src/platform_impl/web/window.rs index acfefe3063..a18b9172ff 100644 --- a/src/platform_impl/web/window.rs +++ b/src/platform_impl/web/window.rs @@ -1,3 +1,14 @@ +use std::cell::RefCell; +use std::collections::VecDeque; +use std::rc::Rc; +use std::sync::Arc; + +use web_sys::HtmlCanvasElement; + +use super::main_thread::{MainThreadMarker, MainThreadSafe}; +use super::monitor::MonitorHandle; +use super::r#async::Dispatcher; +use super::{backend, ActiveEventLoop, Fullscreen}; use crate::dpi::{PhysicalPosition, PhysicalSize, Position, Size}; use crate::error::{ExternalError, NotSupportedError, OsError as RootOE}; use crate::icon::Icon; @@ -6,17 +17,6 @@ use crate::window::{ WindowAttributes, WindowButtons, WindowId as RootWI, WindowLevel, }; -use super::main_thread::{MainThreadMarker, MainThreadSafe}; -use super::monitor::MonitorHandle; -use super::r#async::Dispatcher; -use super::{backend, ActiveEventLoop, Fullscreen}; -use web_sys::HtmlCanvasElement; - -use std::cell::RefCell; -use std::collections::VecDeque; -use std::rc::Rc; -use std::sync::Arc; - pub struct Window { inner: Dispatcher, } diff --git a/src/platform_impl/windows/dark_mode.rs b/src/platform_impl/windows/dark_mode.rs index 4f910ad5c9..4e3a826296 100644 --- a/src/platform_impl/windows/dark_mode.rs +++ b/src/platform_impl/windows/dark_mode.rs @@ -2,7 +2,6 @@ /// which is inspired by the solution in https://github.com/ysc3839/win32-darkmode use std::{ffi::c_void, ptr}; -use crate::utils::Lazy; use windows_sys::core::PCSTR; use windows_sys::Win32::Foundation::{BOOL, HWND, NTSTATUS, S_OK}; use windows_sys::Win32::System::LibraryLoader::{GetProcAddress, LoadLibraryA}; @@ -11,9 +10,9 @@ use windows_sys::Win32::UI::Accessibility::{HCF_HIGHCONTRASTON, HIGHCONTRASTA}; use windows_sys::Win32::UI::Controls::SetWindowTheme; use windows_sys::Win32::UI::WindowsAndMessaging::{SystemParametersInfoA, SPI_GETHIGHCONTRAST}; -use crate::window::Theme; - use super::util; +use crate::utils::Lazy; +use crate::window::Theme; static WIN10_BUILD_VERSION: Lazy> = Lazy::new(|| { type RtlGetVersion = unsafe extern "system" fn(*mut OSVERSIONINFOW) -> NTSTATUS; diff --git a/src/platform_impl/windows/drop_handler.rs b/src/platform_impl/windows/drop_handler.rs index 2aab2cdff8..c30dd655e3 100644 --- a/src/platform_impl/windows/drop_handler.rs +++ b/src/platform_impl/windows/drop_handler.rs @@ -4,20 +4,18 @@ use std::path::PathBuf; use std::ptr; use std::sync::atomic::{AtomicUsize, Ordering}; +use tracing::debug; use windows_sys::core::{IUnknown, GUID, HRESULT}; use windows_sys::Win32::Foundation::{DV_E_FORMATETC, HWND, POINTL, S_OK}; use windows_sys::Win32::System::Com::{IDataObject, DVASPECT_CONTENT, FORMATETC, TYMED_HGLOBAL}; use windows_sys::Win32::System::Ole::{CF_HDROP, DROPEFFECT_COPY, DROPEFFECT_NONE}; use windows_sys::Win32::UI::Shell::{DragFinish, DragQueryFileW, HDROP}; -use tracing::debug; - +use crate::event::Event; use crate::platform_impl::platform::definitions::{ IDataObjectVtbl, IDropTarget, IDropTargetVtbl, IUnknownVtbl, }; use crate::platform_impl::platform::WindowId; - -use crate::event::Event; use crate::window::WindowId as RootWindowId; #[repr(C)] diff --git a/src/platform_impl/windows/event_loop.rs b/src/platform_impl/windows/event_loop.rs index e2d201ba37..007b06ccdf 100644 --- a/src/platform_impl/windows/event_loop.rs +++ b/src/platform_impl/windows/event_loop.rs @@ -12,8 +12,7 @@ use std::sync::{Arc, Mutex, MutexGuard}; use std::time::{Duration, Instant}; use std::{mem, panic, ptr}; -use crate::utils::Lazy; - +use runner::EventLoopRunner; use windows_sys::Win32::Devices::HumanInterfaceDevice::MOUSE_MOVE_RELATIVE; use windows_sys::Win32::Foundation::{HWND, LPARAM, LRESULT, POINT, RECT, WPARAM}; use windows_sys::Win32::Graphics::Gdi::{ @@ -56,6 +55,8 @@ use windows_sys::Win32::UI::WindowsAndMessaging::{ WS_EX_NOACTIVATE, WS_EX_TOOLWINDOW, WS_EX_TRANSPARENT, WS_OVERLAPPED, WS_POPUP, WS_VISIBLE, }; +use super::window::set_skip_taskbar; +use super::SelectedCursor; use crate::application::ApplicationHandler; use crate::dpi::{PhysicalPosition, PhysicalSize}; use crate::error::EventLoopError; @@ -80,13 +81,10 @@ use crate::platform_impl::platform::window_state::{ use crate::platform_impl::platform::{ raw_input, util, wrap_device_id, Fullscreen, WindowId, DEVICE_ID, }; +use crate::utils::Lazy; use crate::window::{ CustomCursor as RootCustomCursor, CustomCursorSource, WindowId as RootWindowId, }; -use runner::EventLoopRunner; - -use super::window::set_skip_taskbar; -use super::SelectedCursor; pub(crate) struct WindowData { pub window_state: Arc>, diff --git a/src/platform_impl/windows/event_loop/runner.rs b/src/platform_impl/windows/event_loop/runner.rs index f6ecabac2c..f84dde9b31 100644 --- a/src/platform_impl/windows/event_loop/runner.rs +++ b/src/platform_impl/windows/event_loop/runner.rs @@ -7,14 +7,13 @@ use std::{mem, panic}; use windows_sys::Win32::Foundation::HWND; +use super::ControlFlow; use crate::dpi::PhysicalSize; use crate::event::{Event, InnerSizeWriter, StartCause, WindowEvent}; use crate::platform_impl::platform::event_loop::{WindowData, GWL_USERDATA}; use crate::platform_impl::platform::get_window_long; use crate::window::WindowId; -use super::ControlFlow; - type EventHandler = Cell>>; pub(crate) struct EventLoopRunner { diff --git a/src/platform_impl/windows/icon.rs b/src/platform_impl/windows/icon.rs index 624c8c8279..19d7b69ca8 100644 --- a/src/platform_impl/windows/icon.rs +++ b/src/platform_impl/windows/icon.rs @@ -14,12 +14,11 @@ use windows_sys::Win32::UI::WindowsAndMessaging::{ HICON, ICONINFO, ICON_BIG, ICON_SMALL, IMAGE_ICON, LR_DEFAULTSIZE, LR_LOADFROMFILE, WM_SETICON, }; +use super::util; use crate::cursor::CursorImage; use crate::dpi::PhysicalSize; use crate::icon::*; -use super::util; - impl Pixel { fn convert_to_bgra(&mut self) { mem::swap(&mut self.r, &mut self.b); diff --git a/src/platform_impl/windows/keyboard.rs b/src/platform_impl/windows/keyboard.rs index 46716f4c67..02d1316e7c 100644 --- a/src/platform_impl/windows/keyboard.rs +++ b/src/platform_impl/windows/keyboard.rs @@ -6,6 +6,9 @@ use std::sync::atomic::AtomicU32; use std::sync::atomic::Ordering::Relaxed; use std::sync::{Mutex, MutexGuard}; +use smol_str::SmolStr; +use tracing::{trace, warn}; +use unicode_segmentation::UnicodeSegmentation; use windows_sys::Win32::Foundation::{HWND, LPARAM, WPARAM}; use windows_sys::Win32::System::SystemServices::LANG_KOREAN; use windows_sys::Win32::UI::Input::KeyboardAndMouse::{ @@ -23,10 +26,6 @@ use windows_sys::Win32::UI::WindowsAndMessaging::{ WM_KEYUP, WM_KILLFOCUS, WM_SETFOCUS, WM_SYSCHAR, WM_SYSDEADCHAR, WM_SYSKEYDOWN, WM_SYSKEYUP, }; -use smol_str::SmolStr; -use tracing::{trace, warn}; -use unicode_segmentation::UnicodeSegmentation; - use crate::event::{ElementState, KeyEvent}; use crate::keyboard::{Key, KeyCode, KeyLocation, NamedKey, NativeKey, NativeKeyCode, PhysicalKey}; use crate::platform_impl::platform::event_loop::ProcResult; diff --git a/src/platform_impl/windows/keyboard_layout.rs b/src/platform_impl/windows/keyboard_layout.rs index 5340e43d8b..a518886030 100644 --- a/src/platform_impl/windows/keyboard_layout.rs +++ b/src/platform_impl/windows/keyboard_layout.rs @@ -4,7 +4,6 @@ use std::ffi::OsString; use std::os::windows::ffi::OsStringExt; use std::sync::Mutex; -use crate::utils::Lazy; use smol_str::SmolStr; use windows_sys::Win32::System::SystemServices::{LANG_JAPANESE, LANG_KOREAN}; use windows_sys::Win32::UI::Input::KeyboardAndMouse::{ @@ -44,6 +43,7 @@ use windows_sys::Win32::UI::TextServices::HKL; use crate::keyboard::{Key, KeyCode, ModifiersState, NamedKey, NativeKey, PhysicalKey}; use crate::platform_impl::{loword, primarylangid, scancode_to_physicalkey}; +use crate::utils::Lazy; pub(crate) static LAYOUT_CACHE: Lazy> = Lazy::new(|| Mutex::new(LayoutCache::default())); diff --git a/src/platform_impl/windows/mod.rs b/src/platform_impl/windows/mod.rs index 15051f0ca3..a479ff268e 100644 --- a/src/platform_impl/windows/mod.rs +++ b/src/platform_impl/windows/mod.rs @@ -6,20 +6,17 @@ pub(crate) use self::event_loop::{ ActiveEventLoop, EventLoop, EventLoopProxy, OwnedDisplayHandle, PlatformSpecificEventLoopAttributes, }; -pub(crate) use self::icon::{SelectedCursor, WinIcon}; +pub use self::icon::WinIcon as PlatformIcon; +pub(crate) use self::icon::{SelectedCursor, WinCursor as PlatformCustomCursor, WinIcon}; pub(crate) use self::keyboard::{physicalkey_to_scancode, scancode_to_physicalkey}; pub(crate) use self::monitor::{MonitorHandle, VideoModeHandle}; pub(crate) use self::window::Window; - -pub(crate) use self::icon::WinCursor as PlatformCustomCursor; -pub use self::icon::WinIcon as PlatformIcon; pub(crate) use crate::cursor::OnlyCursorImageSource as PlatformCustomCursorSource; -use crate::platform_impl::Fullscreen; - use crate::event::DeviceId as RootDeviceId; use crate::icon::Icon; use crate::keyboard::Key; use crate::platform::windows::{BackdropType, Color, CornerPreference}; +use crate::platform_impl::Fullscreen; #[derive(Clone, Debug)] pub struct PlatformSpecificWindowAttributes { diff --git a/src/platform_impl/windows/util.rs b/src/platform_impl/windows/util.rs index 87bcbd4256..c7a337e791 100644 --- a/src/platform_impl/windows/util.rs +++ b/src/platform_impl/windows/util.rs @@ -5,7 +5,6 @@ use std::os::windows::prelude::{OsStrExt, OsStringExt}; use std::sync::atomic::{AtomicBool, Ordering}; use std::{io, mem, ptr}; -use crate::utils::Lazy; use windows_sys::core::{HRESULT, PCWSTR}; use windows_sys::Win32::Foundation::{BOOL, HANDLE, HMODULE, HWND, RECT}; use windows_sys::Win32::Graphics::Gdi::{ClientToScreen, HMONITOR}; @@ -24,6 +23,7 @@ use windows_sys::Win32::UI::WindowsAndMessaging::{ WINDOWPLACEMENT, }; +use crate::utils::Lazy; use crate::window::CursorIcon; pub fn encode_wide(string: impl AsRef) -> Vec { diff --git a/src/platform_impl/windows/window.rs b/src/platform_impl/windows/window.rs index 403d62df31..3bcafc3e5d 100644 --- a/src/platform_impl/windows/window.rs +++ b/src/platform_impl/windows/window.rs @@ -7,6 +7,7 @@ use std::sync::mpsc::channel; use std::sync::{Arc, Mutex, MutexGuard}; use std::{io, panic, ptr}; +use tracing::warn; use windows_sys::Win32::Foundation::{ HWND, LPARAM, OLE_E_WRONGCOMPOBJ, POINT, POINTS, RECT, RPC_E_CHANGED_MODE, S_OK, WPARAM, }; @@ -44,8 +45,6 @@ use windows_sys::Win32::UI::WindowsAndMessaging::{ WDA_EXCLUDEFROMCAPTURE, WDA_NONE, WM_NCLBUTTONDOWN, WM_SYSCOMMAND, WNDCLASSEXW, }; -use tracing::warn; - use crate::cursor::Cursor; use crate::dpi::{PhysicalPosition, PhysicalSize, Position, Size}; use crate::error::{ExternalError, NotSupportedError, OsError as RootOsError}; diff --git a/src/platform_impl/windows/window_state.rs b/src/platform_impl/windows/window_state.rs index 911467b4c7..d03ff40709 100644 --- a/src/platform_impl/windows/window_state.rs +++ b/src/platform_impl/windows/window_state.rs @@ -1,11 +1,7 @@ -use crate::dpi::{PhysicalPosition, PhysicalSize, Size}; -use crate::icon::Icon; -use crate::keyboard::ModifiersState; -use crate::platform_impl::platform::{event_loop, util, Fullscreen, SelectedCursor}; -use crate::window::{Theme, WindowAttributes}; -use bitflags::bitflags; use std::io; use std::sync::MutexGuard; + +use bitflags::bitflags; use windows_sys::Win32::Foundation::{HWND, RECT}; use windows_sys::Win32::Graphics::Gdi::InvalidateRgn; use windows_sys::Win32::UI::WindowsAndMessaging::{ @@ -20,6 +16,12 @@ use windows_sys::Win32::UI::WindowsAndMessaging::{ WS_MINIMIZEBOX, WS_OVERLAPPEDWINDOW, WS_POPUP, WS_SIZEBOX, WS_SYSMENU, WS_VISIBLE, }; +use crate::dpi::{PhysicalPosition, PhysicalSize, Size}; +use crate::icon::Icon; +use crate::keyboard::ModifiersState; +use crate::platform_impl::platform::{event_loop, util, Fullscreen, SelectedCursor}; +use crate::window::{Theme, WindowAttributes}; + /// Contains information about states and the window that the callback is going to use. pub(crate) struct WindowState { pub mouse: MouseProperties, diff --git a/src/window.rs b/src/window.rs index 775b3f5352..991ec4e157 100644 --- a/src/window.rs +++ b/src/window.rs @@ -1,19 +1,18 @@ //! The [`Window`] struct and associated types. use std::fmt; -use crate::dpi::{PhysicalPosition, PhysicalSize, Position, Size}; -use crate::error::{ExternalError, NotSupportedError}; -use crate::monitor::{MonitorHandle, VideoModeHandle}; -use crate::platform_impl::{self, PlatformSpecificWindowAttributes}; - -pub use crate::cursor::{BadImage, Cursor, CustomCursor, CustomCursorSource, MAX_CURSOR_SIZE}; -pub use crate::icon::{BadIcon, Icon}; - #[doc(inline)] pub use cursor_icon::{CursorIcon, ParseError as CursorIconParseError}; #[cfg(feature = "serde")] use serde::{Deserialize, Serialize}; +pub use crate::cursor::{BadImage, Cursor, CustomCursor, CustomCursorSource, MAX_CURSOR_SIZE}; +use crate::dpi::{PhysicalPosition, PhysicalSize, Position, Size}; +use crate::error::{ExternalError, NotSupportedError}; +pub use crate::icon::{BadIcon, Icon}; +use crate::monitor::{MonitorHandle, VideoModeHandle}; +use crate::platform_impl::{self, PlatformSpecificWindowAttributes}; + /// Represents a window. /// /// The window is closed when dropped.