wvr_server: output enter & leave for xdg-toplevel

This commit is contained in:
galister 2026-07-04 05:45:27 +09:00
parent 0cea27c066
commit c98791aeb7
2 changed files with 27 additions and 1 deletions

View File

@ -3,6 +3,7 @@ use smithay::backend::allocator::dmabuf::Dmabuf;
use smithay::backend::renderer::{BufferType, buffer_type};
use smithay::desktop::{PopupKind, PopupManager};
use smithay::input::{Seat, SeatHandler, SeatState};
use smithay::output::Output;
use smithay::reexports::rustix::fs::{OFlags, fcntl_setfl};
use smithay::reexports::wayland_protocols::xdg::decoration::zv1::server::zxdg_toplevel_decoration_v1;
use smithay::reexports::wayland_protocols::xdg::shell::server::xdg_toplevel;
@ -59,6 +60,7 @@ use crate::ipc::event_queue::SyncEventQueue;
use super::WayVRTask;
pub struct Application {
pub output: Output,
pub image_importer: ImageImporter,
pub dmabuf_state: (DmabufState, DmabufGlobal, Option<DmabufFeedback>),
pub compositor: compositor::CompositorState,
@ -80,6 +82,7 @@ pub struct Application {
impl Application {
pub fn cleanup(&mut self) {
self.image_importer.cleanup();
self.output.cleanup();
}
pub fn set_clipboard_text(&mut self, content: &str) {
@ -118,6 +121,18 @@ impl Application {
}
}
}
fn send_initial_surface_state(&self, surface: &WlSurface) {
self.output.enter(surface);
smithay::wayland::compositor::with_states(surface, |states| {
send_surface_state(surface, states, 1, smithay::utils::Transform::Normal);
with_fractional_scale(states, |fractional| {
fractional.set_preferred_scale(1.0);
});
});
}
}
impl compositor::CompositorHandler for Application {
@ -328,7 +343,9 @@ impl XdgShellHandler for Application {
}
fn new_toplevel(&mut self, surface: ToplevelSurface) {
if let Some(client) = surface.wl_surface().client() {
let wl_surface = surface.wl_surface();
self.send_initial_surface_state(wl_surface);
if let Some(client) = wl_surface.client() {
self.wayvr_tasks
.send(WayVRTask::NewToplevel(client.id(), surface.clone()));
}
@ -339,6 +356,8 @@ impl XdgShellHandler for Application {
}
fn toplevel_destroyed(&mut self, surface: ToplevelSurface) {
self.output.leave(surface.wl_surface());
if let Some(client) = surface.wl_surface().client() {
self.wayvr_tasks
.send(WayVRTask::DropToplevel(client.id(), surface.clone()));

View File

@ -41,6 +41,7 @@ use std::{
time::{Duration, Instant},
};
use vulkano::image::view::ImageView;
use wayland_protocols::xdg::shell::server::xdg_toplevel;
use wayvr_ipc::{packet_client::PositionMode, packet_server};
use wgui::gfx::WGfx;
use wlx_capture::frame::Transform;
@ -223,6 +224,7 @@ impl WvrServerState {
let dma_importer = ImageImporter::new(gfx);
let state = Application {
output,
image_importer: dma_importer,
display_handle: dh,
compositor,
@ -363,6 +365,11 @@ impl WvrServerState {
size.w as _,
size.h as _,
);
toplevel.with_pending_state(|state| {
state.size = Some(size);
state.states.set(xdg_toplevel::State::Activated);
});
toplevel.send_configure();
let mut icon = icon;