Split Orbital backend out into winit-orbital (#4243)

This commit is contained in:
Mads Marquart
2025-05-21 13:12:55 +02:00
committed by GitHub
parent e2b883d215
commit 47b938dbe7
11 changed files with 61 additions and 33 deletions

3
.github/CODEOWNERS vendored
View File

@@ -27,5 +27,4 @@
/src/platform_impl/windows @notgull /src/platform_impl/windows @notgull
# Orbital (Redox OS) # Orbital (Redox OS)
/src/platform/orbital.rs @jackpot51 /winit-orbital @jackpot51
/src/platform_impl/orbital @jackpot51

View File

@@ -182,6 +182,10 @@ jobs:
- name: Test winit core - name: Test winit core
run: cargo test -p winit-core run: cargo test -p winit-core
- name: Test winit Orbital
if: contains(matrix.platform.target, 'redox')
run: cargo test -p winit-orbital
# Test only on Linux x86_64, so we avoid spending unnecessary CI hours. # Test only on Linux x86_64, so we avoid spending unnecessary CI hours.
- name: Test dpi crate - name: Test dpi crate
if: > if: >

View File

@@ -1,5 +1,5 @@
[workspace] [workspace]
members = ["dpi", "winit-core"] members = ["dpi", "winit-core", "winit-orbital"]
resolver = "2" resolver = "2"
[workspace.package] [workspace.package]
@@ -13,6 +13,7 @@ rust-version = "1.80"
# `winit` has no version here to allow using it in dev deps for docs. # `winit` has no version here to allow using it in dev deps for docs.
winit = { path = "." } winit = { path = "." }
winit-core = { version = "0.0.0", path = "winit-core" } winit-core = { version = "0.0.0", path = "winit-core" }
winit-orbital = { version = "0.0.0", path = "winit-orbital" }
# Core dependencies. # Core dependencies.
bitflags = "2" bitflags = "2"
@@ -397,10 +398,8 @@ x11rb = { workspace = true, optional = true, features = [
] } ] }
xkbcommon-dl.workspace = true xkbcommon-dl.workspace = true
# Orbital
[target.'cfg(target_os = "redox")'.dependencies] [target.'cfg(target_os = "redox")'.dependencies]
orbclient.workspace = true winit-orbital.workspace = true
redox_syscall.workspace = true
# Web # Web
[target.'cfg(target_family = "wasm")'.dependencies] [target.'cfg(target_family = "wasm")'.dependencies]

View File

@@ -9,7 +9,7 @@ pub mod ios;
#[cfg(macos_platform)] #[cfg(macos_platform)]
pub mod macos; pub mod macos;
#[cfg(orbital_platform)] #[cfg(orbital_platform)]
pub mod orbital; pub use winit_orbital as orbital;
#[cfg(any(x11_platform, wayland_platform))] #[cfg(any(x11_platform, wayland_platform))]
pub mod startup_notify; pub mod startup_notify;
#[cfg(wayland_platform)] #[cfg(wayland_platform)]

View File

@@ -1,6 +0,0 @@
//! # Orbital / Redox OS
//!
//! Redox OS has some functionality not yet present that will be implemented
//! when its orbital display server provides it.
// There are no Orbital specific traits yet.

View File

@@ -5,7 +5,7 @@ mod apple;
#[cfg(any(x11_platform, wayland_platform))] #[cfg(any(x11_platform, wayland_platform))]
mod linux; mod linux;
#[cfg(orbital_platform)] #[cfg(orbital_platform)]
mod orbital; pub(crate) use winit_orbital as platform;
#[cfg(web_platform)] #[cfg(web_platform)]
mod web; mod web;
#[cfg(windows_platform)] #[cfg(windows_platform)]
@@ -17,8 +17,6 @@ use self::android as platform;
use self::apple as platform; use self::apple as platform;
#[cfg(any(x11_platform, wayland_platform))] #[cfg(any(x11_platform, wayland_platform))]
use self::linux as platform; use self::linux as platform;
#[cfg(orbital_platform)]
use self::orbital as platform;
#[allow(unused_imports)] #[allow(unused_imports)]
pub use self::platform::*; pub use self::platform::*;
#[cfg(web_platform)] #[cfg(web_platform)]

25
winit-orbital/Cargo.toml Normal file
View File

@@ -0,0 +1,25 @@
[package]
description = "Winit's Orbital/Redox backend"
documentation = "https://docs.rs/winit-orbital"
edition.workspace = true
license.workspace = true
name = "winit-orbital"
repository.workspace = true
rust-version.workspace = true
version = "0.0.0"
[features]
serde = ["dep:serde", "bitflags/serde", "smol_str/serde", "dpi/serde"]
[dependencies]
bitflags.workspace = true
dpi.workspace = true
rwh_06.workspace = true
serde = { workspace = true, optional = true }
smol_str.workspace = true
tracing.workspace = true
winit-core.workspace = true
# Platform-specific
orbclient.workspace = true
redox_syscall.workspace = true

1
winit-orbital/README.md Symbolic link
View File

@@ -0,0 +1 @@
../README.md

View File

@@ -25,8 +25,8 @@ use winit_core::keyboard::{
}; };
use winit_core::window::{Theme, Window as CoreWindow, WindowId}; use winit_core::window::{Theme, Window as CoreWindow, WindowId};
use super::{PlatformSpecificEventLoopAttributes, RedoxSocket, TimeSocket, WindowProperties}; use crate::window::Window;
use crate::platform_impl::Window; use crate::{RedoxSocket, TimeSocket, WindowProperties};
fn convert_scancode(scancode: u8) -> (PhysicalKey, Option<NamedKey>) { fn convert_scancode(scancode: u8) -> (PhysicalKey, Option<NamedKey>) {
// Key constants from https://docs.rs/orbclient/latest/orbclient/event/index.html // Key constants from https://docs.rs/orbclient/latest/orbclient/event/index.html
@@ -279,7 +279,7 @@ pub struct EventLoop {
} }
impl EventLoop { impl EventLoop {
pub(crate) fn new(_: &PlatformSpecificEventLoopAttributes) -> Result<Self, EventLoopError> { pub fn new(_: &PlatformSpecificEventLoopAttributes) -> Result<Self, EventLoopError> {
// NOTE: Create a channel which can hold only one event to automatically _squash_ user // NOTE: Create a channel which can hold only one event to automatically _squash_ user
// events. // events.
let (user_events_sender, user_events_receiver) = mpsc::sync_channel(1); let (user_events_sender, user_events_receiver) = mpsc::sync_channel(1);
@@ -757,3 +757,6 @@ impl rwh_06::HasDisplayHandle for OwnedDisplayHandle {
unsafe { Ok(rwh_06::DisplayHandle::borrow_raw(raw)) } unsafe { Ok(rwh_06::DisplayHandle::borrow_raw(raw)) }
} }
} }
#[derive(Default, Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub struct PlatformSpecificEventLoopAttributes {}

View File

@@ -1,12 +1,20 @@
#![cfg(target_os = "redox")] //! # Orbital / Redox OS
//!
//! Redox OS has some functionality not yet present that will be implemented
//! when its orbital display server provides it.
use std::{fmt, str}; use std::{fmt, str};
pub(crate) use self::event_loop::{ActiveEventLoop, EventLoop}; pub use self::event_loop::{EventLoop, PlatformSpecificEventLoopAttributes};
pub use self::window::Window;
mod event_loop; macro_rules! os_error {
mod window; ($error:expr) => {{
winit_core::error::OsError::new(line!(), file!(), $error)
}};
}
pub mod event_loop;
pub mod window;
#[derive(Debug)] #[derive(Debug)]
struct RedoxSocket { struct RedoxSocket {
@@ -62,7 +70,7 @@ impl Drop for RedoxSocket {
} }
#[derive(Debug)] #[derive(Debug)]
pub struct TimeSocket(RedoxSocket); struct TimeSocket(RedoxSocket);
impl TimeSocket { impl TimeSocket {
fn open() -> syscall::Result<Self> { fn open() -> syscall::Result<Self> {
@@ -88,12 +96,6 @@ impl TimeSocket {
} }
} }
#[derive(Default, Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub(crate) struct PlatformSpecificEventLoopAttributes {}
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
pub struct PlatformSpecificWindowAttributes;
struct WindowProperties<'a> { struct WindowProperties<'a> {
flags: &'a str, flags: &'a str,
x: i32, x: i32,

View File

@@ -8,8 +8,8 @@ use winit_core::error::{NotSupportedError, RequestError};
use winit_core::monitor::{Fullscreen, MonitorHandle as CoreMonitorHandle}; use winit_core::monitor::{Fullscreen, MonitorHandle as CoreMonitorHandle};
use winit_core::window::{self, ImePurpose, Window as CoreWindow, WindowId}; use winit_core::window::{self, ImePurpose, Window as CoreWindow, WindowId};
use super::event_loop::EventLoopProxy; use crate::event_loop::{ActiveEventLoop, EventLoopProxy};
use super::{ActiveEventLoop, RedoxSocket, WindowProperties}; use crate::{RedoxSocket, WindowProperties};
// These values match the values uses in the `window_new` function in orbital: // 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 // https://gitlab.redox-os.org/redox-os/orbital/-/blob/master/src/scheme.rs
@@ -486,3 +486,6 @@ impl Drop for Window {
self.event_loop_proxy.wake_socket.wake().unwrap(); self.event_loop_proxy.wake_socket.wake().unwrap();
} }
} }
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
pub struct PlatformSpecificWindowAttributes;