Skip to content

Commit

Permalink
feat: impl a ton more stuffs
Browse files Browse the repository at this point in the history
  • Loading branch information
technobaboo committed Jan 31, 2025
1 parent 64f6154 commit 9b5eb9d
Show file tree
Hide file tree
Showing 16 changed files with 797 additions and 246 deletions.
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

86 changes: 80 additions & 6 deletions src/wayland/core/buffer.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,89 @@
use super::shm_pool::ShmPool;
use mint::Vector2;
use nanoid::nanoid;
use parking_lot::Mutex;
use std::sync::Arc;
use stereokit_rust::{
tex::{Tex, TexFormat, TexType},
util::Color32,
};
pub use waynest::server::protocol::core::wayland::wl_buffer::*;
use waynest::server::{
protocol::core::wayland::wl_shm::Format, Client, Dispatcher, Object, Result,
use waynest::{
server::{protocol::core::wayland::wl_shm::Format, Client, Dispatcher, Object, Result},
wire::ObjectId,
};

#[derive(Debug, Clone)]
pub enum BufferBacking {
Shm(Arc<ShmPool>),
Dmabuf(()),
}
#[derive(Debug, Dispatcher)]
pub struct Buffer {
pub offset: usize,
pub stride: usize,
pub size: Vector2<u32>,
pub format: Format,
pub id: ObjectId,
offset: usize,
stride: usize,
pub size: Vector2<usize>,
format: Format,
backing: BufferBacking,
tex: Mutex<Tex>,
}
impl Buffer {
pub fn new(
id: ObjectId,
offset: usize,
stride: usize,
size: Vector2<usize>,
format: Format,
backing: BufferBacking,
) -> Self {
let tex = Tex::new(
TexType::ImageNomips | TexType::Dynamic,
TexFormat::RGBA32,
nanoid!(),
);

Self {
id,
offset,
stride,
size,
format,
backing,
tex: Mutex::new(tex),
}
}
pub fn update_tex(&self) {
match &self.backing {
BufferBacking::Shm(shm_pool) => {
let pixel_count = self.size.x * self.size.y;
let mut data = Vec::with_capacity(pixel_count);
let map_lock = shm_pool.data_lock();
let mut cursor = self.offset;
for _ in 0..self.size.x {
for _ in 0..self.size.x {
data.push(Color32 {
a: match self.format {
Format::Argb8888 => map_lock[cursor],
Format::Xrgb8888 => 255,
_ => panic!("what the hell bruh"),
},
r: map_lock[cursor + 1],
g: map_lock[cursor + 2],
b: map_lock[cursor + 3],
});

cursor += 4;
}
cursor += self.stride;
}
self.tex
.lock()
.set_colors32(self.size.x, self.size.y, data.as_slice());
}
BufferBacking::Dmabuf(_) => {}
}
}
}
impl WlBuffer for Buffer {
async fn destroy(&self, _object: &Object, _client: &mut Client) -> Result<()> {
Expand Down
50 changes: 44 additions & 6 deletions src/wayland/core/compositor.rs
Original file line number Diff line number Diff line change
@@ -1,31 +1,69 @@
use crate::wayland::core::surface::{Surface, WlSurface};
use super::surface::WL_SURFACE_REGISTRY;
use crate::wayland::core::surface::Surface;
pub use waynest::server::protocol::core::wayland::wl_compositor::*;
use waynest::{
server::{Client, Dispatcher, Object, Result},
server::{
protocol::core::wayland::{wl_region::WlRegion, wl_surface::WlSurface},
Client, Dispatcher, Object, Result,
},
wire::ObjectId,
};

#[derive(Debug, Dispatcher, Default)]
pub struct Compositor;

impl WlCompositor for Compositor {
async fn create_surface(
&self,
_object: &Object,
client: &mut Client,
id: ObjectId,
) -> Result<()> {
client.insert(Surface::default().into_object(id));
let surface = Surface::new(client).into_object(id);
WL_SURFACE_REGISTRY.add_raw(&surface.as_dispatcher()?);
client.insert(surface);

Ok(())
}

async fn create_region(
&self,
_object: &Object,
client: &mut Client,
id: ObjectId,
) -> Result<()> {
client.insert(Region::default().into_object(id));
Ok(())
}
}

#[derive(Debug, Dispatcher, Default)]
pub struct Region {}
impl WlRegion for Region {
async fn add(
&self,
_object: &Object,
_client: &mut Client,
_id: ObjectId,
_x: i32,
_y: i32,
_width: i32,
_height: i32,
) -> Result<()> {
todo!()
Ok(())
}

async fn subtract(
&self,
_object: &Object,
_client: &mut Client,
_x: i32,
_y: i32,
_width: i32,
_height: i32,
) -> Result<()> {
Ok(())
}

async fn destroy(&self, _object: &Object, _client: &mut Client) -> Result<()> {
Ok(())
}
}
25 changes: 17 additions & 8 deletions src/wayland/core/display.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
use crate::wayland::core::{
callback::{Callback, WlCallback},
registry::{Registry, WlRegistry},
use crate::wayland::{
core::{
callback::{Callback, WlCallback},
registry::{Registry, WlRegistry},
},
MessageSink,
};
pub use waynest::server::protocol::core::wayland::wl_display::*;
use waynest::{
server::{Client, Dispatcher, Object, Result},
wire::ObjectId,
};

#[derive(Debug, Dispatcher, Default)]
pub struct Display;

#[derive(Debug, Dispatcher)]
pub struct Display {
pub message_sink: MessageSink,
pub pid: Option<i32>,
}
impl WlDisplay for Display {
async fn sync(
&self,
Expand All @@ -24,10 +29,14 @@ impl WlDisplay for Display {

callback
.as_dispatcher::<Callback>()?
.done(&callback, client, serial)
.done(&callback, serial)
.send(client)
.await?;

self.delete_id(object, client, callback_id.as_raw()).await
self.delete_id(object, callback_id.as_raw())
.send(client)
.await?;
Ok(())
}

async fn get_registry(
Expand Down
15 changes: 9 additions & 6 deletions src/wayland/core/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,47 +30,47 @@ impl Registry {
pub async fn advertise_globals(&self, object: &Object, client: &mut Client) -> Result<()> {
self.global(
object,
client,
RegistryGlobals::COMPOSITOR,
Compositor::INTERFACE.to_string(),
Compositor::VERSION,
)
.send(client)
.await?;

self.global(
object,
client,
RegistryGlobals::SHM,
Shm::INTERFACE.to_string(),
Shm::VERSION,
)
.send(client)
.await?;

self.global(
object,
client,
RegistryGlobals::WM_BASE,
WmBase::INTERFACE.to_string(),
WmBase::VERSION,
)
.send(client)
.await?;

self.global(
object,
client,
RegistryGlobals::SEAT,
Seat::INTERFACE.to_string(),
Seat::VERSION,
)
.send(client)
.await?;

self.global(
object,
client,
RegistryGlobals::OUTPUT,
Output::INTERFACE.to_string(),
Output::VERSION,
)
.send(client)
.await?;

Ok(())
Expand Down Expand Up @@ -105,7 +105,10 @@ impl WlRegistry for Registry {
RegistryGlobals::OUTPUT => {
client.insert(Output::default().into_object(new_id.object_id))
}
_ => return Err(Error::Internal),
id => {
tracing::error!(id, "Wayland: failed to bind to registry global");
return Err(Error::Internal);
}
}

Ok(())
Expand Down
6 changes: 2 additions & 4 deletions src/wayland/core/shm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,14 @@ use waynest::{

#[derive(Debug, Dispatcher, Default)]
pub struct Shm;

impl Shm {
pub async fn advertise_formats(&self, object: &Object, client: &mut Client) -> Result<()> {
self.format(object, client, Format::Argb8888).await?;
self.format(object, client, Format::Xrgb8888).await?;
self.format(object, Format::Argb8888).send(client).await?;
self.format(object, Format::Xrgb8888).send(client).await?;

Ok(())
}
}

impl WlShm for Shm {
async fn create_pool(
&self,
Expand Down
Loading

0 comments on commit 9b5eb9d

Please sign in to comment.