Skip to content

Commit 0adc089

Browse files
authored
Move shared code to a new crate winit-common
1 parent 3b986f5 commit 0adc089

File tree

29 files changed

+131
-68
lines changed

29 files changed

+131
-68
lines changed

.github/CODEOWNERS

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55
/src/platform/ios.rs @madsmtm
66
/src/platform/macos.rs @madsmtm
77
/src/platform_impl/apple @madsmtm
8+
/winit-common/src/core_foundation @madsmtm
9+
/winit-common/src/event_handler.rs @madsmtm
810

9-
# Unix
10-
/src/platform_impl/linux/mod.rs @kchibisov
11+
# XKB
12+
/winit-common/src/xkb @kchibisov
1113

1214
# Wayland
1315
/src/platform/wayland.rs @kchibisov

.github/workflows/ci.yml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,18 @@ jobs:
184184

185185
- name: Test winit Android
186186
if: contains(matrix.platform.target, 'android')
187-
run: cargo $CMD test -p winit-android --target=${{ matrix.platform.target }} --features native-activity --no-run
187+
run: cargo $CMD test -p winit-android --features native-activity --no-run
188+
189+
- name: Test winit Common (EventHandler)
190+
run: cargo $CMD test -p winit-common --features event-handler --no-run
191+
192+
- name: Test winit Common (CF)
193+
if: contains(matrix.platform.target, 'apple')
194+
run: cargo $CMD test -p winit-common --features core-foundation --no-run
195+
196+
- name: Test winit Common (XKB)
197+
if: contains(matrix.platform.target, 'linux')
198+
run: cargo $CMD test -p winit-common --features xkb,x11,wayland --no-run
188199

189200
- name: Test winit Orbital
190201
if: contains(matrix.platform.target, 'redox')

Cargo.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ rust-version = "1.80"
1313
# `winit` has no version here to allow using it in dev deps for docs.
1414
winit = { path = "." }
1515
winit-android = { version = "0.0.0", path = "winit-android" }
16+
winit-common = { version = "0.0.0", path = "winit-common" }
1617
winit-core = { version = "0.0.0", path = "winit-core" }
1718
winit-orbital = { version = "0.0.0", path = "winit-orbital" }
1819
winit-win32 = { version = "0.0.0", path = "winit-win32" }
@@ -172,12 +173,13 @@ wayland = [
172173
"sctk",
173174
"ahash",
174175
"memmap2",
176+
"winit-common/wayland",
175177
]
176178
wayland-csd-adwaita = ["sctk-adwaita", "sctk-adwaita/ab_glyph"]
177179
wayland-csd-adwaita-crossfont = ["sctk-adwaita", "sctk-adwaita/crossfont"]
178180
wayland-csd-adwaita-notitle = ["sctk-adwaita"]
179181
wayland-dlopen = ["wayland-backend/dlopen"]
180-
x11 = ["x11-dl", "bytemuck", "percent-encoding", "xkbcommon-dl/x11", "x11rb"]
182+
x11 = ["x11-dl", "bytemuck", "percent-encoding", "xkbcommon-dl/x11", "x11rb", "winit-common/x11"]
181183

182184
[build-dependencies]
183185
cfg_aliases.workspace = true
@@ -208,6 +210,7 @@ winit-android.workspace = true
208210
block2.workspace = true
209211
dispatch2.workspace = true
210212
objc2.workspace = true
213+
winit-common = { workspace = true, features = ["core-foundation", "event-handler"] }
211214

212215
# AppKit
213216
[target.'cfg(target_os = "macos")'.dependencies]
@@ -358,6 +361,7 @@ wayland-backend = { workspace = true, optional = true }
358361
wayland-client = { workspace = true, optional = true }
359362
wayland-protocols = { workspace = true, optional = true }
360363
wayland-protocols-plasma = { workspace = true, optional = true }
364+
winit-common = { workspace = true, features = ["xkb"] }
361365
x11-dl = { workspace = true, optional = true }
362366
x11rb = { workspace = true, optional = true, features = [
363367
"allow-unsafe-code",

src/platform_impl/apple/appkit/app_state.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ use dispatch2::MainThreadBound;
88
use objc2::MainThreadMarker;
99
use objc2_app_kit::{NSApplication, NSApplicationActivationPolicy, NSRunningApplication};
1010
use objc2_foundation::NSNotification;
11+
use winit_common::core_foundation::EventLoopProxy;
12+
use winit_common::event_handler::EventHandler;
1113
use winit_core::application::ApplicationHandler;
1214
use winit_core::event::{StartCause, WindowEvent};
1315
use winit_core::event_loop::ControlFlow;
1416
use winit_core::window::WindowId;
1517

16-
use super::super::event_handler::EventHandler;
17-
use super::super::event_loop_proxy::EventLoopProxy;
1818
use super::event_loop::{notify_windows_of_exit, stop_app_immediately, ActiveEventLoop};
1919
use super::menu;
2020
use super::observer::{EventLoopWaker, RunLoop};

src/platform_impl/apple/appkit/event_loop.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ use winit_core::event_loop::{
2222
use winit_core::monitor::MonitorHandle as CoreMonitorHandle;
2323
use winit_core::window::Theme;
2424

25-
use super::super::notification_center::create_observer;
2625
use super::app::override_send_event;
2726
use super::app_state::AppState;
2827
use super::cursor::CustomCursor;
2928
use super::event::dummy_event;
3029
use super::monitor;
30+
use super::notification_center::create_observer;
3131
use super::observer::setup_control_flow_observers;
3232
use crate::platform::macos::ActivationPolicy;
3333
use crate::platform_impl::Window;

src/platform_impl/apple/appkit/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ mod event_loop;
99
mod ffi;
1010
mod menu;
1111
mod monitor;
12+
mod notification_center;
1213
mod observer;
1314
mod view;
1415
mod window;

src/platform_impl/apple/notification_center.rs renamed to src/platform_impl/apple/appkit/notification_center.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// NOTE: This is symlinked to be contained in both the AppKit and UIKit implementations.
12
use std::ptr::NonNull;
23

34
use block2::RcBlock;
@@ -11,7 +12,7 @@ use objc2_foundation::{
1112
///
1213
/// This is used in Winit as an alternative to declaring an application delegate, as we want to
1314
/// give the user full control over those.
14-
pub fn create_observer(
15+
pub(crate) fn create_observer(
1516
center: &NSNotificationCenter,
1617
name: &NSNotificationName,
1718
handler: impl Fn(&NSNotification) + 'static,

src/platform_impl/apple/mod.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
1-
//! Apple/Darwin-specific implementations
2-
31
#[cfg(target_os = "macos")]
42
mod appkit;
5-
mod event_handler;
6-
mod event_loop_proxy;
7-
mod notification_center;
83
#[cfg(not(target_os = "macos"))]
94
mod uikit;
105

src/platform_impl/apple/uikit/app_state.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ use objc2_core_foundation::{
1616
CGSize,
1717
};
1818
use objc2_ui_kit::{UIApplication, UICoordinateSpace, UIView};
19+
use winit_common::core_foundation::EventLoopProxy;
20+
use winit_common::event_handler::EventHandler;
1921
use winit_core::application::ApplicationHandler;
2022
use winit_core::event::{StartCause, SurfaceSizeWriter, WindowEvent};
2123
use winit_core::event_loop::ControlFlow;
2224
use winit_core::window::WindowId;
2325

24-
use super::super::event_handler::EventHandler;
25-
use super::super::event_loop_proxy::EventLoopProxy;
2626
use super::window::WinitUIWindow;
2727
use super::ActiveEventLoop;
2828

src/platform_impl/apple/uikit/event_loop.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ use winit_core::event_loop::{
2626
use winit_core::monitor::MonitorHandle as CoreMonitorHandle;
2727
use winit_core::window::{Theme, Window as CoreWindow};
2828

29-
use super::super::notification_center::create_observer;
3029
use super::app_state::{send_occluded_event_for_all_windows, AppState};
30+
use super::notification_center::create_observer;
3131
use super::{app_state, monitor, MonitorHandle};
3232
use crate::platform_impl::Window;
3333

0 commit comments

Comments
 (0)