upgrade: waynest

This commit is contained in:
Nova
2025-09-26 16:32:46 -07:00
parent 96e910c450
commit 621a9c6d85
32 changed files with 774 additions and 637 deletions

View File

@@ -1,5 +1,5 @@
use crate::wayland::Message;
use crate::wayland::dmabuf::buffer_backing::DmabufBacking;
use crate::wayland::{Client, Message, WaylandResult};
use crate::wayland::{MessageSink, core::shm_buffer_backing::ShmBufferBacking, util::ClientExt};
use bevy::{
asset::{Assets, Handle},
@@ -8,11 +8,9 @@ use bevy::{
use bevy_dmabuf::import::ImportedDmatexs;
use mint::Vector2;
use std::sync::Arc;
pub use waynest::server::protocol::core::wayland::wl_buffer::*;
use waynest::{
server::{Client, Dispatcher, Result},
wire::ObjectId,
};
use waynest::ObjectId;
pub use waynest_protocols::server::core::wayland::wl_buffer::*;
use waynest_server::RequestDispatcher;
#[derive(Debug)]
pub struct BufferUsage {
@@ -41,7 +39,8 @@ pub enum BufferBacking {
Dmabuf(DmabufBacking),
}
#[derive(Debug, Dispatcher)]
#[derive(Debug, RequestDispatcher)]
#[waynest(error = crate::wayland::WaylandError)]
pub struct Buffer {
pub id: ObjectId,
backing: BufferBacking,
@@ -98,8 +97,10 @@ impl Buffer {
}
impl WlBuffer for Buffer {
type Connection = crate::wayland::Client;
/// https://wayland.app/protocols/wayland#wl_buffer:request:destroy
async fn destroy(&self, _client: &mut Client, _sender_id: ObjectId) -> Result<()> {
async fn destroy(&self, _client: &mut Client, _sender_id: ObjectId) -> WaylandResult<()> {
tracing::info!("Destroying buffer {:?}", self.id);
Ok(())
}

View File

@@ -1,10 +1,11 @@
pub use waynest::server::protocol::core::wayland::wl_callback::*;
use waynest::{
server::{Dispatcher, Result},
wire::ObjectId,
};
use waynest::ObjectId;
pub use waynest_protocols::server::core::wayland::wl_callback::*;
use waynest_server::RequestDispatcher;
#[derive(Debug, Dispatcher, Clone)]
#[derive(Debug, RequestDispatcher, Clone)]
#[waynest(error = crate::wayland::WaylandError)]
pub struct Callback(pub ObjectId);
/// https://wayland.app/protocols/wayland#wl_callback
impl WlCallback for Callback {}
impl WlCallback for Callback {
type Connection = crate::wayland::Client;
}

View File

@@ -1,24 +1,24 @@
use super::surface::WL_SURFACE_REGISTRY;
use crate::wayland::{WaylandResult, WaylandError};
use crate::wayland::{core::surface::Surface, util::ClientExt};
pub use waynest::server::protocol::core::wayland::wl_compositor::*;
use waynest::{
server::{
Client, Dispatcher, Result,
protocol::core::wayland::{wl_region::WlRegion, wl_surface::WlSurface},
},
wire::ObjectId,
};
use waynest::ObjectId;
use waynest_protocols::server::core::wayland::wl_surface::WlSurface;
pub use waynest_protocols::server::core::wayland::{wl_compositor::*, wl_region::*};
use waynest_server::RequestDispatcher;
#[derive(Debug, Dispatcher, Default)]
#[derive(Debug, waynest_server::RequestDispatcher, Default)]
#[waynest(error = WaylandError)]
pub struct Compositor;
impl WlCompositor for Compositor {
type Connection = crate::wayland::Client;
/// https://wayland.app/protocols/wayland#wl_compositor:request:create_surface
async fn create_surface(
&self,
client: &mut Client,
client: &mut Self::Connection,
_sender_id: ObjectId,
id: ObjectId,
) -> Result<()> {
) -> WaylandResult<()> {
let surface = client.insert(id, Surface::new(client, id));
if let Some(output) = client.display().output.get() {
surface.enter(client, id, output.id).await?;
@@ -31,46 +31,49 @@ impl WlCompositor for Compositor {
/// https://wayland.app/protocols/wayland#wl_compositor:request:create_region
async fn create_region(
&self,
client: &mut Client,
client: &mut Self::Connection,
_sender_id: ObjectId,
id: ObjectId,
) -> Result<()> {
) -> WaylandResult<()> {
client.insert(id, Region::default());
Ok(())
}
}
#[derive(Debug, Dispatcher, Default)]
#[derive(Debug, RequestDispatcher, Default)]
#[waynest(error = WaylandError)]
pub struct Region {}
impl WlRegion for Region {
type Connection = crate::wayland::Client;
/// https://wayland.app/protocols/wayland#wl_region:request:add
async fn add(
&self,
_client: &mut Client,
_client: &mut Self::Connection,
_sender_id: ObjectId,
_x: i32,
_y: i32,
_width: i32,
_height: i32,
) -> Result<()> {
) -> WaylandResult<()> {
Ok(())
}
/// https://wayland.app/protocols/wayland#wl_region:request:subtract
async fn subtract(
&self,
_client: &mut Client,
_client: &mut Self::Connection,
_sender_id: ObjectId,
_x: i32,
_y: i32,
_width: i32,
_height: i32,
) -> Result<()> {
) -> WaylandResult<()> {
Ok(())
}
/// https://wayland.app/protocols/wayland#wl_region:request:destroy
async fn destroy(&self, _client: &mut Client, _sender_id: ObjectId) -> Result<()> {
async fn destroy(&self, _client: &mut Self::Connection, _sender_id: ObjectId) -> WaylandResult<()> {
Ok(())
}
}

View File

@@ -1,26 +1,24 @@
use crate::wayland::{Client, WaylandResult};
use std::os::fd::OwnedFd;
use waynest::{
server::{
Client, Dispatcher, Result,
protocol::core::wayland::{
wl_data_device::*, wl_data_device_manager::*, wl_data_offer::WlDataOffer,
wl_data_source::*,
},
},
wire::ObjectId,
use waynest::ObjectId;
use waynest_protocols::server::core::wayland::{
wl_data_device::*, wl_data_device_manager::*, wl_data_offer::WlDataOffer, wl_data_source::*,
};
// TODO: actually implement this
#[derive(Debug, Dispatcher)]
#[derive(Debug, waynest_server::RequestDispatcher)]
#[waynest(error = crate::wayland::WaylandError)]
pub struct DataDeviceManager;
impl WlDataDeviceManager for DataDeviceManager {
type Connection = Client;
async fn create_data_source(
&self,
client: &mut Client,
client: &mut Self::Connection,
_sender_id: ObjectId,
id: ObjectId,
) -> Result<()> {
) -> WaylandResult<()> {
client.insert(id, DataSource);
Ok(())
}
@@ -31,116 +29,125 @@ impl WlDataDeviceManager for DataDeviceManager {
_sender_id: ObjectId,
id: ObjectId,
_seat: ObjectId,
) -> Result<()> {
) -> WaylandResult<()> {
client.insert(id, DataDevice);
Ok(())
}
}
#[derive(Debug, Dispatcher)]
#[derive(Debug, waynest_server::RequestDispatcher)]
#[waynest(error = crate::wayland::WaylandError)]
pub struct DataSource;
impl WlDataSource for DataSource {
type Connection = Client;
async fn send(
&self,
_client: &mut Client,
_client: &mut Self::Connection,
_sender_id: ObjectId,
_mime_type: String,
_fd: OwnedFd,
) -> Result<()> {
) -> WaylandResult<()> {
Ok(())
}
async fn offer(
&self,
_client: &mut Client,
_client: &mut Self::Connection,
_sender_id: ObjectId,
_mime_type: String,
) -> Result<()> {
) -> WaylandResult<()> {
Ok(())
}
async fn destroy(&self, _client: &mut Client, _sender_id: ObjectId) -> Result<()> {
async fn destroy(&self, _client: &mut Self::Connection, _sender_id: ObjectId) -> WaylandResult<()> {
Ok(())
}
async fn set_actions(
&self,
_client: &mut Client,
_client: &mut Self::Connection,
_sender_id: ObjectId,
_dnd_actions: DndAction,
) -> Result<()> {
) -> WaylandResult<()> {
Ok(())
}
}
#[derive(Debug, Dispatcher)]
#[derive(Debug, waynest_server::RequestDispatcher)]
#[waynest(error = crate::wayland::WaylandError)]
pub struct DataDevice;
impl WlDataDevice for DataDevice {
type Connection = Client;
async fn start_drag(
&self,
_client: &mut Client,
_client: &mut Self::Connection,
_sender_id: ObjectId,
_source: Option<ObjectId>,
_origin: ObjectId,
_icon: Option<ObjectId>,
_serial: u32,
) -> Result<()> {
) -> WaylandResult<()> {
Ok(())
}
async fn set_selection(
&self,
_client: &mut Client,
_client: &mut Self::Connection,
_sender_id: ObjectId,
_source: Option<ObjectId>,
_serial: u32,
) -> Result<()> {
) -> WaylandResult<()> {
Ok(())
}
async fn release(&self, _client: &mut Client, _sender_id: ObjectId) -> Result<()> {
async fn release(&self, _client: &mut Self::Connection, _sender_id: ObjectId) -> WaylandResult<()> {
Ok(())
}
}
#[derive(Debug, Dispatcher)]
#[derive(Debug, waynest_server::RequestDispatcher)]
#[waynest(error = crate::wayland::WaylandError)]
pub struct DataOffer;
impl WlDataOffer for DataOffer {
type Connection = Client;
async fn accept(
&self,
_client: &mut Client,
_client: &mut Self::Connection,
_sender_id: ObjectId,
_serial: u32,
_mime_type: Option<String>,
) -> Result<()> {
) -> WaylandResult<()> {
Ok(())
}
async fn receive(
&self,
_client: &mut Client,
_client: &mut Self::Connection,
_sender_id: ObjectId,
_mime_type: String,
_fd: OwnedFd,
) -> Result<()> {
) -> WaylandResult<()> {
Ok(())
}
async fn destroy(&self, _client: &mut Client, _sender_id: ObjectId) -> Result<()> {
async fn destroy(&self, _client: &mut Self::Connection, _sender_id: ObjectId) -> WaylandResult<()> {
Ok(())
}
async fn finish(&self, _client: &mut Client, _sender_id: ObjectId) -> Result<()> {
async fn finish(&self, _client: &mut Self::Connection, _sender_id: ObjectId) -> WaylandResult<()> {
Ok(())
}
async fn set_actions(
&self,
_client: &mut Client,
_client: &mut Self::Connection,
_sender_id: ObjectId,
_dnd_actions: DndAction,
_preferred_action: DndAction,
) -> Result<()> {
) -> WaylandResult<()> {
Ok(())
}
}

View File

@@ -1,6 +1,6 @@
use crate::{
nodes::items::panel::KEYMAPS,
wayland::{core::surface::Surface, util::ClientExt},
wayland::{Client, WaylandResult, core::surface::Surface, util::ClientExt},
};
use dashmap::{DashMap, DashSet};
use memfd::MemfdOptions;
@@ -15,11 +15,8 @@ use std::{
sync::{Arc, Weak},
};
use tokio::sync::Mutex;
pub use waynest::server::protocol::core::wayland::wl_keyboard::*;
use waynest::{
server::{Client, Dispatcher, Result},
wire::ObjectId,
};
use waynest::ObjectId;
pub use waynest_protocols::server::core::wayland::wl_keyboard::*;
#[derive(Default)]
struct ModifierState {
@@ -69,7 +66,8 @@ impl ModifierState {
}
}
#[derive(Dispatcher)]
#[derive(waynest_server::RequestDispatcher)]
#[waynest(error = crate::wayland::WaylandError)]
pub struct Keyboard {
pub id: ObjectId,
focused_surface: Mutex<Weak<Surface>>,
@@ -89,10 +87,9 @@ impl Keyboard {
}
}
async fn send_keymap(&self, client: &mut Client, keymap: &[u8]) -> Result<()> {
async fn send_keymap(&self, client: &mut Client, keymap: &[u8]) -> WaylandResult<()> {
let mut file = MemfdOptions::default()
.create("stardust-keymap")
.map_err(|e| waynest::server::Error::Custom(e.to_string()))?
.create("stardust-keymap")?
.into_file();
file.set_len(keymap.len() as u64)?;
file.write_all(keymap)?;
@@ -121,7 +118,7 @@ impl Keyboard {
keymap_id: u64,
key: u32,
pressed: bool,
) -> Result<()> {
) -> WaylandResult<()> {
// KEYMAP UPDATES
{
let mut old_keymap_id = self.current_keymap_id.lock().await;
@@ -224,7 +221,7 @@ impl Keyboard {
Ok(())
}
pub async fn reset(&self, client: &mut Client) -> Result<()> {
pub async fn reset(&self, client: &mut Client) -> WaylandResult<()> {
let mut modifier_state = self.modifier_state.lock().await;
modifier_state.pressed_keys.clear();
modifier_state.mods_depressed = 0;
@@ -247,8 +244,10 @@ impl Keyboard {
}
impl WlKeyboard for Keyboard {
type Connection = Client;
/// https://wayland.app/protocols/wayland#wl_keyboard:request:release
async fn release(&self, _client: &mut Client, _sender_id: ObjectId) -> Result<()> {
async fn release(&self, _client: &mut Self::Connection, _sender_id: ObjectId) -> WaylandResult<()> {
Ok(())
}
}

View File

@@ -1,17 +1,15 @@
use waynest::{
server::{Client, Dispatcher, Result},
wire::ObjectId,
};
use crate::wayland::{Client, WaylandResult};
use waynest::ObjectId;
pub use waynest_protocols::server::core::wayland::wl_output::*;
pub use waynest::server::protocol::core::wayland::wl_output::*;
#[derive(Debug, Dispatcher)]
#[derive(Debug, waynest_server::RequestDispatcher)]
#[waynest(error = crate::wayland::WaylandError)]
pub struct Output {
pub id: ObjectId,
pub version: u32,
}
impl Output {
pub async fn advertise_outputs(&self, client: &mut Client) -> Result<()> {
pub async fn advertise_outputs(&self, client: &mut Client) -> WaylandResult<()> {
self.geometry(
client,
self.id,
@@ -46,8 +44,10 @@ impl Output {
}
}
impl WlOutput for Output {
type Connection = Client;
/// https://wayland.app/protocols/wayland#wl_output:request:release
async fn release(&self, _client: &mut Client, _sender_id: ObjectId) -> Result<()> {
async fn release(&self, _client: &mut Self::Connection, _sender_id: ObjectId) -> WaylandResult<()> {
Ok(())
}
}

View File

@@ -1,19 +1,18 @@
use super::surface::SurfaceRole;
use crate::nodes::items::panel::Geometry;
use crate::wayland::core::{seat::fixed_from_f32, surface::Surface};
use crate::wayland::core::surface::Surface;
use crate::wayland::{Client, WaylandResult};
use mint::Vector2;
use std::sync::Arc;
use std::sync::Weak;
use tokio::sync::Mutex;
use tracing;
pub use waynest::server::protocol::core::wayland::wl_pointer::*;
use waynest::{
server::{Client, Dispatcher, Result},
wire::ObjectId,
};
use waynest::ObjectId;
use super::surface::SurfaceRole;
pub use waynest_protocols::server::core::wayland::wl_pointer::*;
#[derive(Dispatcher)]
#[derive(waynest_server::RequestDispatcher)]
#[waynest(error = crate::wayland::WaylandError)]
pub struct Pointer {
pub id: ObjectId,
version: u32,
@@ -35,7 +34,7 @@ impl Pointer {
client: &mut Client,
surface: Arc<Surface>,
position: Vector2<f32>,
) -> Result<()> {
) -> WaylandResult<()> {
tracing::debug!(
"Handling pointer motion at ({}, {})",
position.x,
@@ -65,8 +64,8 @@ impl Pointer {
self.id,
serial,
surface.id,
fixed_from_f32(position.x),
fixed_from_f32(position.y),
(position.x as f64).into(),
(position.y as f64).into(),
)
.await?;
@@ -80,8 +79,8 @@ impl Pointer {
client,
self.id,
0, // time
fixed_from_f32(position.x),
fixed_from_f32(position.y),
(position.x as f64).into(),
(position.y as f64).into(),
)
.await?;
if self.version >= 5 {
@@ -97,7 +96,7 @@ impl Pointer {
surface: Arc<Surface>,
button: u32,
pressed: bool,
) -> Result<()> {
) -> WaylandResult<()> {
tracing::debug!(
"Handling pointer button {} {} on surface {:?}",
button,
@@ -126,7 +125,7 @@ impl Pointer {
_surface: Arc<Surface>,
scroll_distance: Option<Vector2<f32>>,
scroll_steps: Option<Vector2<f32>>,
) -> Result<()> {
) -> WaylandResult<()> {
tracing::debug!(
"Handling pointer scroll: distance={:?}, steps={:?}",
scroll_distance,
@@ -138,7 +137,7 @@ impl Pointer {
self.id,
0, // time
Axis::HorizontalScroll,
fixed_from_f32(distance.x),
(distance.x as f64).into(),
)
.await?;
self.axis(
@@ -146,7 +145,7 @@ impl Pointer {
self.id,
0, // time
Axis::VerticalScroll,
fixed_from_f32(distance.y),
(distance.y as f64).into(),
)
.await?;
}
@@ -162,7 +161,7 @@ impl Pointer {
Ok(())
}
pub async fn reset(&self, client: &mut Client) -> Result<()> {
pub async fn reset(&self, client: &mut Client) -> WaylandResult<()> {
let mut focused = self.focused_surface.lock().await;
if let Some(old_surface) = focused.upgrade() {
let serial = client.next_event_serial();
@@ -179,16 +178,18 @@ impl Pointer {
}
impl WlPointer for Pointer {
type Connection = crate::wayland::Client;
/// https://wayland.app/protocols/wayland#wl_pointer:request:set_cursor
async fn set_cursor(
&self,
client: &mut Client,
client: &mut Self::Connection,
_sender_id: ObjectId,
_serial: u32,
surface: Option<ObjectId>,
hotspot_x: i32,
hotspot_y: i32,
) -> Result<()> {
) -> WaylandResult<()> {
if let Some(focused_surface) = self.focused_surface.lock().await.upgrade()
&& let Some(panel_item) = focused_surface.panel_item.lock().upgrade()
{
@@ -211,13 +212,19 @@ impl WlPointer for Pointer {
return Ok(());
};
surface.try_set_role(client, SurfaceRole::Cursor).await?;
surface
.try_set_role(SurfaceRole::Cursor, Error::Role)
.await?;
self.cursor_surface.lock().await.replace(surface);
Ok(())
}
/// https://wayland.app/protocols/wayland#wl_pointer:request:release
async fn release(&self, _client: &mut Client, _sender_id: ObjectId) -> Result<()> {
async fn release(
&self,
_client: &mut Self::Connection,
_sender_id: ObjectId,
) -> WaylandResult<()> {
Ok(())
}
}

View File

@@ -1,10 +1,11 @@
use crate::wayland::Client;
use crate::wayland::WaylandResult;
use crate::wayland::core::{keyboard::Keyboard, pointer::Pointer, surface::Surface, touch::Touch};
use mint::Vector2;
use std::sync::Arc;
use std::sync::OnceLock;
pub use waynest::server::protocol::core::wayland::wl_seat::*;
use waynest::server::{Client, Dispatcher, Result};
use waynest::wire::{Fixed, ObjectId};
use waynest::ObjectId;
pub use waynest_protocols::server::core::wayland::wl_seat::*;
#[derive(Debug)]
pub enum SeatMessage {
@@ -43,11 +44,8 @@ pub enum SeatMessage {
Reset,
}
pub fn fixed_from_f32(f: f32) -> Fixed {
unsafe { Fixed::from_raw((f * 256.0).round() as u32) }
}
#[derive(Default, Dispatcher)]
#[derive(Default, waynest_server::RequestDispatcher)]
#[waynest(error = crate::wayland::WaylandError)]
pub struct Seat {
version: u32,
pointer: OnceLock<Arc<Pointer>>,
@@ -56,7 +54,7 @@ pub struct Seat {
}
impl Seat {
pub async fn new(client: &mut Client, id: ObjectId, version: u32) -> Result<Self> {
pub async fn new(client: &mut Client, id: ObjectId, version: u32) -> WaylandResult<Self> {
let seat = Self {
version,
pointer: OnceLock::new(),
@@ -76,7 +74,11 @@ impl Seat {
Ok(seat)
}
pub async fn handle_message(&self, client: &mut Client, message: SeatMessage) -> Result<()> {
pub async fn handle_message(
&self,
client: &mut Client,
message: SeatMessage,
) -> WaylandResult<()> {
match message {
SeatMessage::PointerMotion { surface, position } => {
if let Some(pointer) = self.pointer.get() {
@@ -160,13 +162,15 @@ impl Seat {
}
}
impl WlSeat for Seat {
type Connection = crate::wayland::Client;
/// https://wayland.app/protocols/wayland#wl_seat:request:get_pointer
async fn get_pointer(
&self,
client: &mut Client,
client: &mut Self::Connection,
_sender_id: ObjectId,
id: ObjectId,
) -> Result<()> {
) -> WaylandResult<()> {
let pointer = client.insert(id, Pointer::new(id, self.version));
let _ = self.pointer.set(pointer);
Ok(())
@@ -175,10 +179,10 @@ impl WlSeat for Seat {
/// https://wayland.app/protocols/wayland#wl_seat:request:get_keyboard
async fn get_keyboard(
&self,
client: &mut Client,
client: &mut Self::Connection,
_sender_id: ObjectId,
id: ObjectId,
) -> Result<()> {
) -> WaylandResult<()> {
tracing::info!("Getting keyboard");
let keyboard = client.insert(id, Keyboard::new(id));
let _ = self.keyboard.set(keyboard);
@@ -188,17 +192,21 @@ impl WlSeat for Seat {
/// https://wayland.app/protocols/wayland#wl_seat:request:get_touch
async fn get_touch(
&self,
client: &mut Client,
client: &mut Self::Connection,
_sender_id: ObjectId,
id: ObjectId,
) -> Result<()> {
) -> WaylandResult<()> {
let touch = client.insert(id, Touch(id));
let _ = self.touch.set(touch);
Ok(())
}
/// https://wayland.app/protocols/wayland#wl_seat:request:release
async fn release(&self, _client: &mut Client, _sender_id: ObjectId) -> Result<()> {
async fn release(
&self,
_client: &mut Self::Connection,
_sender_id: ObjectId,
) -> WaylandResult<()> {
Ok(())
}
}

View File

@@ -1,16 +1,13 @@
use crate::wayland::{Client, WaylandResult, core::shm_pool::ShmPool};
use std::os::fd::OwnedFd;
use waynest::ObjectId;
pub use waynest_protocols::server::core::wayland::wl_shm::*;
use crate::wayland::core::shm_pool::ShmPool;
pub use waynest::server::protocol::core::wayland::wl_shm::*;
use waynest::{
server::{Client, Dispatcher, Result},
wire::ObjectId,
};
#[derive(Debug, Dispatcher, Default)]
#[derive(Debug, waynest_server::RequestDispatcher, Default)]
#[waynest(error = crate::wayland::WaylandError)]
pub struct Shm;
impl Shm {
pub async fn advertise_formats(&self, client: &mut Client, sender_id: ObjectId) -> Result<()> {
pub async fn advertise_formats(&self, client: &mut Client, sender_id: ObjectId) -> WaylandResult<()> {
self.format(client, sender_id, Format::Argb8888).await?;
self.format(client, sender_id, Format::Xrgb8888).await?;
@@ -18,22 +15,24 @@ impl Shm {
}
}
impl WlShm for Shm {
type Connection = crate::wayland::Client;
/// https://wayland.app/protocols/wayland#wl_shm:request:create_pool
async fn create_pool(
&self,
client: &mut Client,
client: &mut Self::Connection,
_sender_id: ObjectId,
pool_id: ObjectId,
fd: OwnedFd,
size: i32,
) -> Result<()> {
) -> WaylandResult<()> {
client.insert(pool_id, ShmPool::new(fd, size)?);
Ok(())
}
/// https://wayland.app/protocols/wayland#wl_shm:request:release
async fn release(&self, _client: &mut Client, _sender_id: ObjectId) -> Result<()> {
async fn release(&self, _client: &mut Self::Connection, _sender_id: ObjectId) -> WaylandResult<()> {
Ok(())
}
}

View File

@@ -33,7 +33,7 @@ use vulkano::{
},
sync::GpuFuture,
};
use waynest::server::protocol::core::wayland::wl_shm::Format;
use waynest_protocols::server::core::wayland::wl_shm::Format;
/// Parameters for a shared memory buffer
pub struct ShmBufferBacking {

View File

@@ -1,25 +1,24 @@
use super::shm_buffer_backing::ShmBufferBacking;
use crate::wayland::{
Client, WaylandResult,
core::buffer::{Buffer, BufferBacking},
};
use memmap2::{MmapOptions, RemapOptions};
use parking_lot::{Mutex, MutexGuard, RawMutex, lock_api::MappedMutexGuard};
use std::os::fd::{IntoRawFd, OwnedFd};
use waynest::{
server::{Client, Dispatcher, Result, protocol::core::wayland::wl_shm::Format},
wire::ObjectId,
};
use waynest::ObjectId;
use waynest_protocols::server::core::wayland::wl_shm::Format;
pub use waynest_protocols::server::core::wayland::wl_shm_pool::*;
use crate::wayland::core::buffer::{Buffer, BufferBacking};
pub use waynest::server::protocol::core::wayland::wl_shm_pool::*;
use super::shm_buffer_backing::ShmBufferBacking;
#[derive(Debug, Dispatcher)]
#[derive(Debug, waynest_server::RequestDispatcher)]
#[waynest(error = crate::wayland::WaylandError)]
pub struct ShmPool {
inner: Mutex<memmap2::MmapMut>,
}
impl ShmPool {
#[tracing::instrument(level = "debug", skip_all)]
pub fn new(fd: OwnedFd, size: i32) -> Result<Self> {
pub fn new(fd: OwnedFd, size: i32) -> WaylandResult<Self> {
let map = unsafe {
MmapOptions::new()
.len(size as usize)
@@ -38,11 +37,13 @@ impl ShmPool {
}
impl WlShmPool for ShmPool {
type Connection = Client;
/// https://wayland.app/protocols/wayland#wl_shm_pool:request:create_buffer
#[tracing::instrument(level = "debug", skip_all)]
async fn create_buffer(
&self,
client: &mut Client,
client: &mut Self::Connection,
sender_id: ObjectId,
id: ObjectId,
offset: i32,
@@ -50,7 +51,7 @@ impl WlShmPool for ShmPool {
height: i32,
stride: i32,
format: Format,
) -> Result<()> {
) -> WaylandResult<()> {
let params = ShmBufferBacking::new(
client.get::<ShmPool>(sender_id).unwrap(),
offset as usize,
@@ -65,7 +66,12 @@ impl WlShmPool for ShmPool {
/// https://wayland.app/protocols/wayland#wl_shm_pool:request:resize
#[tracing::instrument(level = "debug", skip_all)]
async fn resize(&self, _client: &mut Client, _sender_id: ObjectId, size: i32) -> Result<()> {
async fn resize(
&self,
_client: &mut Self::Connection,
_sender_id: ObjectId,
size: i32,
) -> WaylandResult<()> {
let mut inner = self.inner.lock();
unsafe { inner.remap(size as usize, RemapOptions::new().may_move(true))? };
Ok(())
@@ -73,7 +79,7 @@ impl WlShmPool for ShmPool {
/// https://wayland.app/protocols/wayland#wl_shm_pool:request:destroy
#[tracing::instrument(level = "debug", skip_all)]
async fn destroy(&self, _client: &mut Client, _sender_id: ObjectId) -> Result<()> {
async fn destroy(&self, _client: &mut Self::Connection, _sender_id: ObjectId) -> WaylandResult<()> {
Ok(())
}
}

View File

@@ -7,7 +7,7 @@ use crate::{
items::panel::{Geometry, PanelItem, SurfaceId},
},
wayland::{
Message, MessageSink,
Client, Message, MessageSink, WaylandError, WaylandResult,
core::buffer::BufferUsage,
presentation::{MonotonicTimestamp, PresentationFeedback},
util::{ClientExt, DoubleBuffer},
@@ -22,16 +22,14 @@ use bevy::{
use bevy_dmabuf::import::ImportedDmatexs;
use mint::Vector2;
use parking_lot::Mutex;
use std::sync::{Arc, OnceLock, Weak};
use waynest::{
server::{
self, Client, Dispatcher, Result,
protocol::{
core::wayland::{wl_output::Transform, wl_surface::*},
stable::presentation_time::wp_presentation_feedback::{Kind, WpPresentationFeedback},
},
},
wire::ObjectId,
use std::{
fmt::Display,
sync::{Arc, OnceLock, Weak},
};
use waynest::ObjectId;
use waynest_protocols::server::{
core::wayland::{wl_output::Transform, wl_surface::*},
stable::presentation_time::wp_presentation_feedback::{Kind, WpPresentationFeedback},
};
pub static WL_SURFACE_REGISTRY: Registry<Surface> = Registry::new();
@@ -43,6 +41,16 @@ pub enum SurfaceRole {
XdgToplevel,
XdgPopup,
}
impl Display for SurfaceRole {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
SurfaceRole::Cursor => f.write_str("SurfaceRole::Cursor"),
SurfaceRole::Subsurface => f.write_str("SurfaceRole::Subsurface"),
SurfaceRole::XdgToplevel => f.write_str("SurfaceRole::XdgToplevel"),
SurfaceRole::XdgPopup => f.write_str("SurfaceRole::XdgPopup"),
}
}
}
#[derive(Debug, Clone)]
pub struct BufferState {
@@ -81,7 +89,8 @@ impl SurfaceState {
// if returning false, don't run this callback again... just remove it
pub type OnCommitCallback = Box<dyn FnMut(&Surface, &SurfaceState) -> bool + Send + Sync>;
#[derive(Dispatcher)]
#[derive(waynest_server::RequestDispatcher)]
#[waynest(error = crate::wayland::WaylandError)]
pub struct Surface {
pub id: ObjectId,
pub surface_id: OnceLock<SurfaceId>,
@@ -130,24 +139,21 @@ impl Surface {
}
}
pub async fn try_set_role(&self, client: &mut Client, role: SurfaceRole) -> Result<()> {
pub async fn try_set_role(
&self,
role: SurfaceRole,
role_error: impl Into<u32>,
) -> WaylandResult<()> {
match self.role.get().cloned() {
Some(current_role) => {
if current_role == role {
Ok(())
} else {
client
.protocol_error(
self.id,
self.id,
1, // XDG_WM_BASE_ERROR_ROLE
"Surface has an incomparible role".to_string(),
)
.await?;
Err(server::Error::Custom(format!(
"Surface {} has role {current_role:?} but tried to set to {role:?}",
self.id
)))
Err(WaylandError::Fatal {
object_id: self.id,
code: role_error.into(),
message: "Surface has an incomparible role",
})
}
}
None => {
@@ -248,7 +254,7 @@ impl Surface {
// .map(|b| [b.size.x as u32, b.size.y as u32].into())
// }
// pub async fn release_old_buffer(&self, client: &mut Client) -> Result<()> {
// pub async fn release_old_buffer(&self, client: &mut Self::Connection) -> Result<()> {
// let (old_buffer, object) = {
// let lock = self.state.lock();
@@ -291,7 +297,7 @@ impl Surface {
client: &mut Client,
display_timestamp: MonotonicTimestamp,
refresh_cycle: u64,
) -> Result<()> {
) -> WaylandResult<()> {
let feedbacks = self
.presentation_feedback
.lock()
@@ -325,16 +331,18 @@ impl Surface {
}
}
impl WlSurface for Surface {
type Connection = crate::wayland::Client;
/// https://wayland.app/protocols/wayland#wl_surface:request:attach
#[tracing::instrument(level = "debug", skip_all)]
async fn attach(
&self,
client: &mut Client,
client: &mut Self::Connection,
_sender_id: ObjectId,
buffer: Option<ObjectId>,
_x: i32,
_y: i32,
) -> Result<()> {
) -> WaylandResult<()> {
self.state.lock().pending.buffer = buffer.and_then(|b| {
let buffer = client.get::<Buffer>(b)?;
let mut usage = Some(BufferUsage::new(client, &buffer));
@@ -350,13 +358,13 @@ impl WlSurface for Surface {
#[tracing::instrument(level = "debug", skip_all)]
async fn damage(
&self,
_client: &mut Client,
_client: &mut Self::Connection,
_sender_id: ObjectId,
_x: i32,
_y: i32,
_width: i32,
_height: i32,
) -> Result<()> {
) -> WaylandResult<()> {
Ok(())
}
@@ -364,10 +372,10 @@ impl WlSurface for Surface {
#[tracing::instrument(level = "debug", skip_all)]
async fn frame(
&self,
client: &mut Client,
client: &mut Self::Connection,
_sender_id: ObjectId,
callback_id: ObjectId,
) -> Result<()> {
) -> WaylandResult<()> {
let callback = client.insert(callback_id, Callback(callback_id));
self.state.lock().pending.frame_callbacks.push(callback);
Ok(())
@@ -377,10 +385,10 @@ impl WlSurface for Surface {
#[tracing::instrument(level = "debug", skip_all)]
async fn set_opaque_region(
&self,
_client: &mut Client,
_client: &mut Self::Connection,
_sender_id: ObjectId,
_region: Option<ObjectId>,
) -> Result<()> {
) -> WaylandResult<()> {
// nothing we can really do to repaint behind this so ignore it
Ok(())
}
@@ -389,17 +397,21 @@ impl WlSurface for Surface {
#[tracing::instrument(level = "debug", skip_all)]
async fn set_input_region(
&self,
_client: &mut Client,
_client: &mut Self::Connection,
_sender_id: ObjectId,
_region: Option<ObjectId>,
) -> Result<()> {
) -> WaylandResult<()> {
// too complicated to implement this for now so who the hell cares
Ok(())
}
/// https://wayland.app/protocols/wayland#wl_surface:request:commit
#[tracing::instrument(level = "debug", skip_all)]
async fn commit(&self, _client: &mut Client, _sender_id: ObjectId) -> Result<()> {
async fn commit(
&self,
_client: &mut Self::Connection,
_sender_id: ObjectId,
) -> WaylandResult<()> {
// we want the upload to complete before we give the image to bevy
let buffer_option = self
.state_lock()
@@ -428,10 +440,10 @@ impl WlSurface for Surface {
#[tracing::instrument(level = "debug", skip_all)]
async fn set_buffer_transform(
&self,
_client: &mut Client,
_client: &mut Self::Connection,
_sender_id: ObjectId,
_transform: Transform,
) -> Result<()> {
) -> WaylandResult<()> {
// we just don't have the output transform or fullscreen at all so this optimization is never needed
Ok(())
}
@@ -440,10 +452,10 @@ impl WlSurface for Surface {
#[tracing::instrument(level = "debug", skip_all)]
async fn set_buffer_scale(
&self,
_client: &mut Client,
_client: &mut Self::Connection,
_sender_id: ObjectId,
scale: i32,
) -> Result<()> {
) -> WaylandResult<()> {
self.state.lock().pending.density = scale as f32;
Ok(())
}
@@ -452,13 +464,13 @@ impl WlSurface for Surface {
#[tracing::instrument(level = "debug", skip_all)]
async fn damage_buffer(
&self,
_client: &mut Client,
_client: &mut Self::Connection,
_sender_id: ObjectId,
_x: i32,
_y: i32,
_width: i32,
_height: i32,
) -> Result<()> {
) -> WaylandResult<()> {
Ok(())
}
@@ -466,17 +478,21 @@ impl WlSurface for Surface {
#[tracing::instrument(level = "debug", skip_all)]
async fn offset(
&self,
_client: &mut Client,
_client: &mut Self::Connection,
_sender_id: ObjectId,
_x: i32,
_y: i32,
) -> Result<()> {
) -> WaylandResult<()> {
Ok(())
}
/// https://wayland.app/protocols/wayland#wl_surface:request:destroy
#[tracing::instrument(level = "debug", skip_all)]
async fn destroy(&self, _client: &mut Client, _sender_id: ObjectId) -> Result<()> {
async fn destroy(
&self,
_client: &mut Self::Connection,
_sender_id: ObjectId,
) -> WaylandResult<()> {
Ok(())
}
}

View File

@@ -1,15 +1,11 @@
use crate::wayland::core::surface::Surface;
use crate::wayland::{Client, WaylandResult, core::surface::Surface};
use mint::Vector2;
use std::sync::Arc;
pub use waynest::server::protocol::core::wayland::wl_touch::*;
use waynest::{
server::{Client, Dispatcher, Result},
wire::ObjectId,
};
use waynest::ObjectId;
pub use waynest_protocols::server::core::wayland::wl_touch::*;
use super::seat::fixed_from_f32;
#[derive(Debug, Dispatcher)]
#[derive(Debug, waynest_server::RequestDispatcher)]
#[waynest(error = crate::wayland::WaylandError)]
pub struct Touch(pub ObjectId);
impl Touch {
pub async fn handle_touch_down(
@@ -18,7 +14,7 @@ impl Touch {
surface: Arc<Surface>,
id: u32,
position: Vector2<f32>,
) -> Result<()> {
) -> WaylandResult<()> {
let serial = client.next_event_serial();
self.down(
client,
@@ -27,8 +23,8 @@ impl Touch {
0,
surface.id,
id as i32,
fixed_from_f32(position.x),
fixed_from_f32(position.y),
(position.x as f64).into(),
(position.y as f64).into(),
)
.await?;
self.frame(client, self.0).await
@@ -39,37 +35,39 @@ impl Touch {
client: &mut Client,
id: u32,
position: Vector2<f32>,
) -> Result<()> {
) -> WaylandResult<()> {
self.motion(
client,
self.0,
0,
id as i32,
fixed_from_f32(position.x),
fixed_from_f32(position.y),
(position.x as f64).into(),
(position.y as f64).into(),
)
.await?;
self.frame(client, self.0).await
}
pub async fn handle_touch_up(&self, client: &mut Client, id: u32) -> Result<()> {
pub async fn handle_touch_up(&self, client: &mut Client, id: u32) -> WaylandResult<()> {
let serial = client.next_event_serial();
self.up(client, self.0, serial, 0, id as i32).await?;
self.frame(client, self.0).await
}
pub async fn reset(&self, client: &mut Client) -> Result<()> {
pub async fn reset(&self, client: &mut Client) -> WaylandResult<()> {
self.frame(client, self.0).await
}
}
impl WlTouch for Touch {
type Connection = crate::wayland::Client;
/// https://wayland.app/protocols/wayland#wl_touch:request:release
async fn release(
&self,
_client: &mut waynest::server::Client,
_sender_id: waynest::wire::ObjectId,
) -> Result<()> {
_client: &mut Self::Connection,
_sender_id: ObjectId,
) -> WaylandResult<()> {
Ok(())
}
}