Skip to main content

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//! The tray icon ([`tray`]) is a StatusNotifierItem over GIO's D-Bus,
28//! which both toolkits' loops run.
29
30#[cfg(target_os = "linux")]
31pub mod tray;
32#[cfg(target_os = "linux")]
33pub mod wayland;
34#[cfg(target_os = "linux")]
35pub mod x11;
36
37use mitsuami_core::raw_window_handle::{HandleError, RawDisplayHandle, RawWindowHandle};
38use mitsuami_core::{NativeSurface, SurfaceHandle, SurfaceInput};
39
40/// A surface on a display that has none to give (GTK's Broadway, Qt's
41/// offscreen platform, which tests run on): the app is told of it and its
42/// size, as headless tells it, but it has no handles to present to.
43pub struct NoSurface;
44
45impl NoSurface {
46    pub fn handle() -> SurfaceHandle {
47        SurfaceHandle::new(NoSurface)
48    }
49}
50
51// SAFETY: it returns no handles.
52unsafe impl NativeSurface for NoSurface {
53    fn window_handle(&self) -> Result<RawWindowHandle, HandleError> {
54        Err(HandleError::NotSupported)
55    }
56
57    fn display_handle(&self) -> Result<RawDisplayHandle, HandleError> {
58        Err(HandleError::NotSupported)
59    }
60}
61
62/// What a pointer lock or a shortcuts inhibitor reports, from a thread of
63/// its own.
64#[derive(Clone, Debug, PartialEq)]
65pub enum LockEvent {
66    /// Input for the surface: the pointer's moves while locked (and on
67    /// X11, whose grab takes them from the toolkit, its buttons and
68    /// wheel).
69    Input(SurfaceInput),
70    /// The compositor or X server ended it, or it couldn't be made.
71    Ended,
72}
73
74/// Where a lock reports, on its own thread.
75pub type LockSink = Box<dyn Fn(LockEvent) + Send + Sync>;