mitsuami_linux/lib.rs
1//! `GpuSurface` on Linux, for the GTK and Kirigami backends: a surface of
2//! our own over the widget that keeps its space, which the app presents to
3//! directly, and the pointer lock the toolkits don't offer.
4//!
5//! - Wayland ([`wayland`]): a `wl_surface`, a desync subsurface of the
6//! window's surface, on the toolkit's connection. The toolkits' own
7//! routes wait for their frame clocks: GTK's `GtkGraphicsOffload` showed
8//! a frame more latency than a window of the app's own (2ksbox measured
9//! it); a desync subsurface doesn't wait for the window's commits. The
10//! pointer lock is `zwp_locked_pointer_v1` with relative motion, and Qt,
11//! which has no API for it, inhibits the compositor's shortcuts with
12//! `zwp_keyboard_shortcuts_inhibitor_v1`.
13//! - X11 ([`x11`]): a child window of the window's, on an xcb connection of
14//! our own, which the app may use from any thread. The pointer lock is a
15//! pointer grab on it, the cursor warped back to its middle after each
16//! move.
17//!
18//! Both take no input (an empty input region, an empty input shape), so
19//! the toolkit keeps the pointer, and the backend places them over their
20//! widget after each of the window's frames. Each lives as long as the
21//! app's handle, so a GPU surface made on it never outlives it. Other
22//! displays (GTK's Broadway, Qt's offscreen platform) get a [`NoSurface`].
23//!
24//! Pointer locks report on a thread of their own ([`LockEvent`]); the
25//! backend sends what they report to its UI thread.
26
27#[cfg(target_os = "linux")]
28pub mod wayland;
29#[cfg(target_os = "linux")]
30pub mod x11;
31
32use mitsuami_core::raw_window_handle::{HandleError, RawDisplayHandle, RawWindowHandle};
33use mitsuami_core::{NativeSurface, SurfaceHandle, SurfaceInput};
34
35/// A surface on a display that has none to give (GTK's Broadway, Qt's
36/// offscreen platform, which tests run on): the app is told of it and its
37/// size, as headless tells it, but it has no handles to present to.
38pub struct NoSurface;
39
40impl NoSurface {
41 pub fn handle() -> SurfaceHandle {
42 SurfaceHandle::new(NoSurface)
43 }
44}
45
46// SAFETY: it returns no handles.
47unsafe impl NativeSurface for NoSurface {
48 fn window_handle(&self) -> Result<RawWindowHandle, HandleError> {
49 Err(HandleError::NotSupported)
50 }
51
52 fn display_handle(&self) -> Result<RawDisplayHandle, HandleError> {
53 Err(HandleError::NotSupported)
54 }
55}
56
57/// What a pointer lock or a shortcuts inhibitor reports, from a thread of
58/// its own.
59#[derive(Clone, Debug, PartialEq)]
60pub enum LockEvent {
61 /// Input for the surface: the pointer's moves while locked (and on
62 /// X11, whose grab takes them from the toolkit, its buttons and
63 /// wheel).
64 Input(SurfaceInput),
65 /// The compositor or X server ended it, or it couldn't be made.
66 Ended,
67}
68
69/// Where a lock reports, on its own thread.
70pub type LockSink = Box<dyn Fn(LockEvent) + Send + Sync>;