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
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 61 additions and 33 deletions

3
.github/CODEOWNERS vendored
View file

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

View file

@ -182,6 +182,10 @@ jobs:
- name: Test 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.
- name: Test dpi crate
if: >

View file

@ -1,5 +1,5 @@
[workspace]
members = ["dpi", "winit-core"]
members = ["dpi", "winit-core", "winit-orbital"]
resolver = "2"
[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 = { path = "." }
winit-core = { version = "0.0.0", path = "winit-core" }
winit-orbital = { version = "0.0.0", path = "winit-orbital" }
# Core dependencies.
bitflags = "2"
@ -397,10 +398,8 @@ x11rb = { workspace = true, optional = true, features = [
] }
xkbcommon-dl.workspace = true
# Orbital
[target.'cfg(target_os = "redox")'.dependencies]
orbclient.workspace = true
redox_syscall.workspace = true
winit-orbital.workspace = true
# Web
[target.'cfg(target_family = "wasm")'.dependencies]

View file

@ -9,7 +9,7 @@ pub mod ios;
#[cfg(macos_platform)]
pub mod macos;
#[cfg(orbital_platform)]
pub mod orbital;
pub use winit_orbital as orbital;
#[cfg(any(x11_platform, wayland_platform))]
pub mod startup_notify;
#[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))]
mod linux;
#[cfg(orbital_platform)]
mod orbital;
pub(crate) use winit_orbital as platform;
#[cfg(web_platform)]
mod web;
#[cfg(windows_platform)]
@ -17,8 +17,6 @@ use self::android as platform;
use self::apple as platform;
#[cfg(any(x11_platform, wayland_platform))]
use self::linux as platform;
#[cfg(orbital_platform)]
use self::orbital as platform;
#[allow(unused_imports)]
pub use self::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 super::{PlatformSpecificEventLoopAttributes, RedoxSocket, TimeSocket, WindowProperties};
use crate::platform_impl::Window;
use crate::window::Window;
use crate::{RedoxSocket, TimeSocket, WindowProperties};
fn convert_scancode(scancode: u8) -> (PhysicalKey, Option<NamedKey>) {
// Key constants from https://docs.rs/orbclient/latest/orbclient/event/index.html
@ -279,7 +279,7 @@ pub struct 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
// events.
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)) }
}
}
#[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};
pub(crate) use self::event_loop::{ActiveEventLoop, EventLoop};
pub use self::window::Window;
pub use self::event_loop::{EventLoop, PlatformSpecificEventLoopAttributes};
mod event_loop;
mod window;
macro_rules! os_error {
($error:expr) => {{
winit_core::error::OsError::new(line!(), file!(), $error)
}};
}
pub mod event_loop;
pub mod window;
#[derive(Debug)]
struct RedoxSocket {
@ -62,7 +70,7 @@ impl Drop for RedoxSocket {
}
#[derive(Debug)]
pub struct TimeSocket(RedoxSocket);
struct TimeSocket(RedoxSocket);
impl TimeSocket {
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> {
flags: &'a str,
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::window::{self, ImePurpose, Window as CoreWindow, WindowId};
use super::event_loop::EventLoopProxy;
use super::{ActiveEventLoop, RedoxSocket, WindowProperties};
use crate::event_loop::{ActiveEventLoop, EventLoopProxy};
use crate::{RedoxSocket, 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
@ -486,3 +486,6 @@ impl Drop for Window {
self.event_loop_proxy.wake_socket.wake().unwrap();
}
}
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
pub struct PlatformSpecificWindowAttributes;