Files
feresaria/vendor/smithay/examples/compositor.rs
T
aria 993bc0f88f Integrate native Rime and stabilize input, output, and rendering
- Add optional modifier-only Super binding whose tap is cancelled by
  other input, focus changes, grabs, locks, and session teardown.
- Ship the native ferese-rime user service, Rime defaults, installer
  inventory, package dependencies, session environment, and docs.
- Vendor Smithay 8a27023 with the SHM texture-cache format fix and add
  GPU regressions for format changes and resize snapshots.
- Release reused CRTC owners before staging output modes, then restore
  changed outputs before former owners when a transaction fails.
- Wait for resize-capture GPU completion, expand filtered surface
  damage, and preserve IME popup origin under fractional scaling.
- Mark weekends like holidays in both calendar layouts.
2026-10-30 03:13:43 +09:00

79 lines
2.0 KiB
Rust

use std::sync::Arc;
use smithay::delegate_dispatch2;
use smithay::reexports::wayland_server::Display;
use smithay::wayland::compositor::{CompositorClientState, CompositorHandler, CompositorState};
use wayland_server::backend::{ClientData, ClientId, DisconnectReason};
use wayland_server::protocol::wl_surface::WlSurface;
use wayland_server::{Client, ListeningSocket};
struct App {
compositor_state: CompositorState,
}
impl CompositorHandler for App {
fn compositor_state(&mut self) -> &mut CompositorState {
&mut self.compositor_state
}
fn client_compositor_state<'a>(&self, client: &'a Client) -> &'a CompositorClientState {
&client.get_data::<ClientState>().unwrap().compositor_state
}
fn commit(&mut self, surface: &WlSurface) {
dbg!("Commit", surface);
}
}
fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut display: Display<App> = Display::new()?;
let dh = display.handle();
let compositor_state = CompositorState::new::<App>(&dh);
let mut state = App { compositor_state };
let listener = ListeningSocket::bind("wayland-5").unwrap();
let mut clients = Vec::new();
loop {
if let Some(stream) = listener.accept().unwrap() {
println!("Got a client: {:?}", stream);
let client = display
.handle()
.insert_client(stream, Arc::new(ClientState::default()))
.unwrap();
clients.push(client);
}
display.dispatch_clients(&mut state)?;
display.flush_clients()?;
}
}
#[derive(Default)]
struct ClientState {
compositor_state: CompositorClientState,
}
impl ClientData for ClientState {
fn initialized(&self, _client_id: ClientId) {
println!("initialized");
}
fn disconnected(&self, _client_id: ClientId, _reason: DisconnectReason) {
println!("disconnected");
}
}
impl AsMut<CompositorState> for App {
fn as_mut(&mut self) -> &mut CompositorState {
&mut self.compositor_state
}
}
delegate_dispatch2!(App);