Set shm pool size based on layer surface width and height

This commit is contained in:
2025-04-25 14:38:22 -07:00
parent adacd7a2ab
commit 0cf379c6f7
4 changed files with 9 additions and 9 deletions

View File

@@ -3,6 +3,8 @@ use crate::{surface::UnsetErr, vec_utils::WlMessage, WlClient};
const NAMESPACE: &str = "chlorostart"; const NAMESPACE: &str = "chlorostart";
const OVERLAY: u32 = 3; const OVERLAY: u32 = 3;
const STRIDE: usize = 4;
const EXCLUSIVE: u32 = 1; // exclusize keyboard focus
impl WlClient { impl WlClient {
pub fn layer_shell_get_layer_surface(&mut self) -> Result<(), Box<dyn Error>> { pub fn layer_shell_get_layer_surface(&mut self) -> Result<(), Box<dyn Error>> {
@@ -85,7 +87,6 @@ impl WlClient {
let object: u32 = self.layer_surface_id.unwrap(); let object: u32 = self.layer_surface_id.unwrap();
const OPCODE: u16 = 4; const OPCODE: u16 = 4;
const MSG_SIZE: u16 = 12; const MSG_SIZE: u16 = 12;
const EXCLUSIVE: u32 = 1; // exclusize keyboard focus
let mut request = vec![0u8; MSG_SIZE as usize]; let mut request = vec![0u8; MSG_SIZE as usize];
let mut offset: usize = 0; let mut offset: usize = 0;

View File

@@ -89,4 +89,3 @@ impl WlClient {
Ok(()) Ok(())
} }
} }

View File

@@ -19,14 +19,12 @@ impl WlClient {
self.wl_compositor_create_surface()?; self.wl_compositor_create_surface()?;
self.layer_shell_get_layer_surface()?; self.layer_shell_get_layer_surface()?;
self.layer_surface_set_size(200, 200)?; self.layer_surface_set_size(800, 800)?;
self.layer_surface_set_keyboard_interactivity()?; self.layer_surface_set_keyboard_interactivity()?;
self.wl_surface_commit()?; self.wl_surface_commit()?;
self.wl_shm_create_pool()?; self.wl_shm_create_pool(800, 800)?;
self.wl_shm_pool_create_buffer(0, 200, 200)?; self.wl_shm_pool_create_buffer(0, 800, 800)?;
// self.wl_surface_attach()?;
// self.wl_surface_commit()?;
Ok(()) Ok(())
} }

View File

@@ -1,15 +1,17 @@
use std::{io::Write, error::Error, os::unix::net::SocketAncillary}; use std::{io::Write, error::Error, os::unix::net::SocketAncillary};
use crate::{WlClient, vec_utils::WlMessage, shm}; use crate::{WlClient, vec_utils::WlMessage, shm};
const STRIDE: usize = 4;
impl WlClient { impl WlClient {
pub fn wl_shm_format(event: &Vec<u8>) { pub fn wl_shm_format(event: &Vec<u8>) {
let mut offset = 0; let mut offset = 0;
println!("Received pixel format: {:x}", event.read_u32(&mut offset)); println!("Received pixel format: {:x}", event.read_u32(&mut offset));
} }
pub fn wl_shm_create_pool(&mut self) -> Result<(), String> { pub fn wl_shm_create_pool(&mut self, width: usize, height: usize) -> Result<(), String> {
self.current_id += 1; self.current_id += 1;
self.shm_pool = Some(match shm::ShmPool::new(4096, self.current_id) { self.shm_pool = Some(match shm::ShmPool::new(width * height * STRIDE, self.current_id) {
Ok(val) => val, Ok(val) => val,
Err(err) => { Err(err) => {
return Err(err.to_string()); return Err(err.to_string());