| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
use std::{collections::VecDeque, ptr::NonNull}; |
| 13 |
|
| 14 |
pub use raw_window_handle::{RawDisplayHandle, RawWindowHandle}; |
| 15 |
use raw_window_handle::{WaylandDisplayHandle, WaylandWindowHandle}; |
| 16 |
pub use smithay_client_toolkit::{ |
| 17 |
compositor::Region, |
| 18 |
compositor::{CompositorHandler, CompositorState}, |
| 19 |
output::{OutputHandler, OutputState}, |
| 20 |
registry::{ProvidesRegistryState, RegistryState}, |
| 21 |
seat::{Capability, SeatHandler, SeatState}, |
| 22 |
shell::{ |
| 23 |
WaylandSurface, |
| 24 |
wlr_layer::{ |
| 25 |
Anchor, KeyboardInteractivity, Layer, LayerShell, LayerShellHandler, LayerSurface, |
| 26 |
LayerSurfaceConfigure, |
| 27 |
}, |
| 28 |
xdg::{ |
| 29 |
XdgShell, |
| 30 |
window::{Window as XdgWindow, WindowConfigure, WindowDecorations, WindowHandler}, |
| 31 |
}, |
| 32 |
}, |
| 33 |
}; |
| 34 |
pub use wayland_client::{ |
| 35 |
Connection, Dispatch, EventQueue, Proxy, QueueHandle, |
| 36 |
globals::{GlobalList, GlobalListContents, registry_queue_init}, |
| 37 |
protocol::wl_registry::WlRegistry, |
| 38 |
}; |
| 39 |
|
| 40 |
|
| 41 |
#[derive(Debug, Clone)] |
| 42 |
pub enum Pending { |
| 43 |
|
| 44 |
Resized { width: u32, height: u32 }, |
| 45 |
|
| 46 |
CloseRequested, |
| 47 |
} |
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
#[derive(Debug, Clone, Copy)] |
| 55 |
pub struct LayerConfig { |
| 56 |
pub layer: Layer, |
| 57 |
pub anchor: Anchor, |
| 58 |
pub exclusive_zone: i32, |
| 59 |
pub keyboard_interactivity: KeyboardInteractivity, |
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
pub no_input: bool, |
| 64 |
} |
| 65 |
|
| 66 |
impl LayerConfig { |
| 67 |
|
| 68 |
|
| 69 |
#[must_use] |
| 70 |
pub fn background(layer: Layer) -> Self { |
| 71 |
Self { |
| 72 |
layer, |
| 73 |
anchor: Anchor::TOP | Anchor::BOTTOM | Anchor::LEFT | Anchor::RIGHT, |
| 74 |
exclusive_zone: 0, |
| 75 |
keyboard_interactivity: KeyboardInteractivity::None, |
| 76 |
no_input: true, |
| 77 |
} |
| 78 |
} |
| 79 |
} |
| 80 |
|
| 81 |
|
| 82 |
pub struct WindowSpec<'a> { |
| 83 |
pub title: &'a str, |
| 84 |
pub app_id: &'a str, |
| 85 |
pub min_size: (u32, u32), |
| 86 |
pub initial_size: (u32, u32), |
| 87 |
|
| 88 |
|
| 89 |
pub layer: Option<LayerConfig>, |
| 90 |
} |
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
pub enum ShopSurface { |
| 99 |
Toplevel(XdgWindow), |
| 100 |
Layer(LayerSurface), |
| 101 |
} |
| 102 |
|
| 103 |
impl ShopSurface { |
| 104 |
#[must_use] |
| 105 |
pub fn wl_surface(&self) -> &wayland_client::protocol::wl_surface::WlSurface { |
| 106 |
match self { |
| 107 |
Self::Toplevel(window) => window.wl_surface(), |
| 108 |
Self::Layer(layer) => layer.wl_surface(), |
| 109 |
} |
| 110 |
} |
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
pub fn set_title(&self, title: impl Into<String>) { |
| 116 |
match self { |
| 117 |
Self::Toplevel(window) => window.set_title(title.into()), |
| 118 |
Self::Layer(_) => {} |
| 119 |
} |
| 120 |
} |
| 121 |
|
| 122 |
pub fn commit(&self) { |
| 123 |
match self { |
| 124 |
Self::Toplevel(window) => window.commit(), |
| 125 |
Self::Layer(layer) => layer.commit(), |
| 126 |
} |
| 127 |
} |
| 128 |
} |
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
pub struct WaylandChrome { |
| 134 |
pub registry: RegistryState, |
| 135 |
pub seat: SeatState, |
| 136 |
pub output: OutputState, |
| 137 |
pub compositor: CompositorState, |
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
pub xdg_shell: Option<XdgShell>, |
| 142 |
pub layer_shell: Option<LayerShell>, |
| 143 |
pub surface: ShopSurface, |
| 144 |
pub pending: VecDeque<Pending>, |
| 145 |
pub width: u32, |
| 146 |
pub height: u32, |
| 147 |
pub exit: bool, |
| 148 |
} |
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
pub fn raw_handles( |
| 158 |
conn: &Connection, |
| 159 |
chrome: &WaylandChrome, |
| 160 |
) -> (RawDisplayHandle, RawWindowHandle) { |
| 161 |
let display_ptr = |
| 162 |
NonNull::new(conn.backend().display_ptr().cast()).expect("wayland display ptr"); |
| 163 |
let surface_ptr = |
| 164 |
NonNull::new(chrome.surface.wl_surface().id().as_ptr().cast()).expect("wl_surface ptr"); |
| 165 |
let display = RawDisplayHandle::Wayland(WaylandDisplayHandle::new(display_ptr)); |
| 166 |
let window = RawWindowHandle::Wayland(WaylandWindowHandle::new(surface_ptr)); |
| 167 |
(display, window) |
| 168 |
} |
| 169 |
|