Remove dead code and fix all clippy/fmt warnings

- Remove CapturedFrame struct and last_capture field (no consumer yet)
- Remove display_handle field (re-obtainable when needed)
- Prefix output_manager_state and xdg_decoration_state with _ (kept
  alive for Wayland globals but not directly read)
- Keep framebuffer capture logging to verify ExportMem path works
This commit is contained in:
Till Wegmueller 2026-04-04 19:07:46 +02:00
parent 5fee1a9b40
commit 9ab3e6d782
2 changed files with 25 additions and 67 deletions

View file

@ -14,7 +14,7 @@ use smithay::{
};
use tracing::warn;
use crate::state::{CapturedFrame, WayRay};
use crate::state::WayRay;
/// Dark grey clear color for the compositor background.
const CLEAR_COLOR: [f32; 4] = [0.1, 0.1, 0.1, 1.0];
@ -36,7 +36,6 @@ pub fn render_output_frame(
let age = backend.buffer_age().unwrap_or(0);
// Render within a block so framebuffer is dropped before submit.
// Returns (damage, optional captured frame) on success.
let render_result = {
let (renderer, mut framebuffer) = match backend.bind() {
Ok(pair) => pair,
@ -63,26 +62,18 @@ pub fn render_output_frame(
match render_result {
Ok(result) => {
// Clone damage before we consume the framebuffer for capture.
let damage = result.damage.cloned();
// Capture the framebuffer while it is still bound.
// Verify framebuffer capture path works (will be consumed
// by network transport in Phase 1).
let output_size = state.output.current_mode().unwrap().size;
let region: Rectangle<i32, BufferCoord> = Rectangle::from_size(
Size::from((output_size.w, output_size.h)),
);
let region: Rectangle<i32, BufferCoord> =
Rectangle::from_size(Size::from((output_size.w, output_size.h)));
let capture = match renderer.copy_framebuffer(
&framebuffer,
region,
Fourcc::Argb8888,
) {
match renderer.copy_framebuffer(&framebuffer, region, Fourcc::Argb8888) {
Ok(mapping) => match renderer.map_texture(&mapping) {
Ok(pixels) => {
let damage_rects = damage
.as_ref()
.map(|d| d.len())
.unwrap_or(0);
let damage_rects = damage.as_ref().map(|d| d.len()).unwrap_or(0);
tracing::debug!(
width = output_size.w,
height = output_size.h,
@ -90,28 +81,17 @@ pub fn render_output_frame(
damage_rects,
"framebuffer captured"
);
Some(CapturedFrame {
data: pixels.to_vec(),
width: output_size.w,
height: output_size.h,
damage: damage
.as_ref()
.cloned()
.unwrap_or_default(),
})
}
Err(err) => {
tracing::warn!(?err, "failed to map framebuffer");
None
}
},
Err(err) => {
tracing::warn!(?err, "failed to copy framebuffer");
None
}
};
}
Ok((damage, capture))
Ok(damage)
}
Err(err) => {
warn!(?err, "damage tracker render failed");
@ -122,11 +102,7 @@ pub fn render_output_frame(
// framebuffer is now dropped, backend is no longer borrowed.
match render_result {
Ok((damage, capture)) => {
// Store the captured frame for later consumption by the
// network transport layer.
state.last_capture = capture;
Ok(damage) => {
let has_damage = damage.is_some();
let submit_result = if let Some(ref rects) = damage {

View file

@ -1,8 +1,7 @@
use smithay::{
backend::input::{
AbsolutePositionEvent, Axis, AxisSource, ButtonState, Event as InputEventTrait,
InputBackend, InputEvent, KeyboardKeyEvent,
PointerAxisEvent as PointerAxisEventTrait,
InputBackend, InputEvent, KeyboardKeyEvent, PointerAxisEvent as PointerAxisEventTrait,
PointerButtonEvent as PointerButtonEventTrait,
},
desktop::{Space, WindowSurfaceType},
@ -12,48 +11,36 @@ use smithay::{
pointer::{AxisFrame, ButtonEvent, MotionEvent},
},
output::Output,
reexports::wayland_server::{Display, DisplayHandle},
utils::{Clock, Monotonic, Physical, Rectangle, SERIAL_COUNTER},
reexports::wayland_server::Display,
utils::{Clock, Monotonic, SERIAL_COUNTER},
wayland::{
compositor::CompositorState,
output::OutputManagerState,
selection::{
data_device::DataDeviceState,
primary_selection::PrimarySelectionState,
},
selection::{data_device::DataDeviceState, primary_selection::PrimarySelectionState},
shell::xdg::{XdgShellState, decoration::XdgDecorationState},
shm::ShmState,
},
};
use tracing::info;
/// Captured framebuffer data from the last render pass.
pub struct CapturedFrame {
pub data: Vec<u8>,
pub width: i32,
pub height: i32,
pub damage: Vec<Rectangle<i32, Physical>>,
}
/// Central compositor state holding all Smithay subsystem states.
///
/// This is the "god struct" pattern required by Smithay — a single type that
/// implements all handler traits and holds all protocol global state.
pub struct WayRay {
pub display_handle: DisplayHandle,
pub compositor_state: CompositorState,
pub xdg_shell_state: XdgShellState,
pub shm_state: ShmState,
pub seat_state: SeatState<Self>,
pub output_manager_state: OutputManagerState,
pub data_device_state: DataDeviceState,
pub primary_selection_state: PrimarySelectionState,
pub xdg_decoration_state: XdgDecorationState,
pub space: Space<smithay::desktop::Window>,
pub seat: Seat<Self>,
pub clock: Clock<Monotonic>,
pub output: Output,
pub last_capture: Option<CapturedFrame>,
// Kept alive to maintain their Wayland globals — not accessed directly.
_output_manager_state: OutputManagerState,
_xdg_decoration_state: XdgDecorationState,
}
impl WayRay {
@ -66,7 +53,6 @@ impl WayRay {
let shm_state = ShmState::new::<Self>(&dh, vec![]);
let data_device_state = DataDeviceState::new::<Self>(&dh);
let primary_selection_state = PrimarySelectionState::new::<Self>(&dh);
let xdg_decoration_state = XdgDecorationState::new::<Self>(&dh);
let mut seat_state = SeatState::new();
let mut seat = seat_state.new_wl_seat(&dh, "wayray");
@ -75,25 +61,21 @@ impl WayRay {
.expect("failed to add keyboard to seat");
seat.add_pointer();
let output_manager_state = OutputManagerState::new_with_xdg_output::<Self>(&dh);
info!("all Smithay subsystem states initialized");
Self {
display_handle: dh,
compositor_state,
xdg_shell_state,
shm_state,
seat_state,
output_manager_state,
data_device_state,
primary_selection_state,
xdg_decoration_state,
space: Space::default(),
seat,
clock: Clock::new(),
output,
last_capture: None,
_output_manager_state: OutputManagerState::new_with_xdg_output::<Self>(&dh),
_xdg_decoration_state: XdgDecorationState::new::<Self>(&dh),
}
}
@ -171,12 +153,12 @@ impl WayRay {
let source = event.source();
let horizontal_amount = event
.amount(Axis::Horizontal)
.unwrap_or_else(|| event.amount_v120(Axis::Horizontal).unwrap_or(0.0) * 3.0 / 120.0);
let vertical_amount = event
.amount(Axis::Vertical)
.unwrap_or_else(|| event.amount_v120(Axis::Vertical).unwrap_or(0.0) * 3.0 / 120.0);
let horizontal_amount = event.amount(Axis::Horizontal).unwrap_or_else(|| {
event.amount_v120(Axis::Horizontal).unwrap_or(0.0) * 3.0 / 120.0
});
let vertical_amount = event.amount(Axis::Vertical).unwrap_or_else(|| {
event.amount_v120(Axis::Vertical).unwrap_or(0.0) * 3.0 / 120.0
});
let mut frame = AxisFrame::new(event.time_msec()).source(source);