Clean up a few things
This commit is contained in:
@@ -10,26 +10,27 @@ struct WlHeader {
|
|||||||
|
|
||||||
pub struct WlClient {
|
pub struct WlClient {
|
||||||
pub socket: Mutex<UnixStream>,
|
pub socket: Mutex<UnixStream>,
|
||||||
pub running: AtomicBool,
|
|
||||||
pub current_id: AtomicU32,
|
pub current_id: AtomicU32,
|
||||||
pub registry_id: AtomicU32,
|
pub running: AtomicBool,
|
||||||
pub shm_id: AtomicU32,
|
|
||||||
pub shmpool_id: AtomicU32,
|
|
||||||
pub shm_pool: Mutex<shm::ShmPool>,
|
pub shm_pool: Mutex<shm::ShmPool>,
|
||||||
pub compositor_id: AtomicU32,
|
|
||||||
pub surface_id: AtomicU32,
|
|
||||||
pub active_buffer: AtomicBool,
|
pub active_buffer: AtomicBool,
|
||||||
pub buffer1: Mutex<Option<wl_buffer>>,
|
pub buffer1: Mutex<Option<wl_buffer>>,
|
||||||
pub buffer2: Mutex<Option<wl_buffer>>,
|
pub buffer2: Mutex<Option<wl_buffer>>,
|
||||||
pub frame_hint_id: AtomicU32,
|
|
||||||
pub xdg_wm_base_id: AtomicU32,
|
|
||||||
pub layer_shell_id: AtomicU32,
|
|
||||||
pub layer_surface_id: AtomicU32,
|
|
||||||
pub seat_id: AtomicU32,
|
|
||||||
pub keyboard_id: AtomicU32,
|
|
||||||
pub keymap_fd: Mutex<Option<shm::ShmPool>>,
|
pub keymap_fd: Mutex<Option<shm::ShmPool>>,
|
||||||
pub keymap: RwLock<Option<HashMap<u32, Vec<String>>>>,
|
pub keymap: RwLock<Option<HashMap<u32, Vec<String>>>>,
|
||||||
pub drawables: Mutex<Vec<Box<dyn Drawable>>>,
|
pub drawables: Mutex<Vec<Box<dyn Drawable>>>,
|
||||||
|
|
||||||
|
pub registry_id: AtomicU32,
|
||||||
|
pub shm_id: AtomicU32,
|
||||||
|
pub shmpool_id: AtomicU32,
|
||||||
|
pub seat_id: AtomicU32,
|
||||||
|
pub keyboard_id: AtomicU32,
|
||||||
|
pub compositor_id: AtomicU32,
|
||||||
|
pub surface_id: AtomicU32,
|
||||||
|
pub xdg_wm_base_id: AtomicU32,
|
||||||
|
pub layer_shell_id: AtomicU32,
|
||||||
|
pub layer_surface_id: AtomicU32,
|
||||||
|
pub frame_hint_id: AtomicU32,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl WlClient {
|
impl WlClient {
|
||||||
@@ -131,6 +132,12 @@ impl WlClient {
|
|||||||
|
|
||||||
drop(socket);
|
drop(socket);
|
||||||
|
|
||||||
|
if let Some(buffer) = self.buffer1.lock()?.as_mut() {
|
||||||
|
if header.object == buffer.id && header.opcode == 0 { // wl_buffer::release
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if header.object == self.registry_id.load(Ordering::Relaxed) && header.opcode == 0 { // wl_registry::global
|
if header.object == self.registry_id.load(Ordering::Relaxed) && header.opcode == 0 { // wl_registry::global
|
||||||
self.wl_registry_global(&event)?;
|
self.wl_registry_global(&event)?;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,13 +35,15 @@ impl WlClient {
|
|||||||
id: current_id + 1,
|
id: current_id + 1,
|
||||||
offset: 0,
|
offset: 0,
|
||||||
width: 800,
|
width: 800,
|
||||||
height: 800
|
height: 800,
|
||||||
|
ready: true,
|
||||||
});
|
});
|
||||||
*buffer2 = Some(wl_buffer {
|
*buffer2 = Some(wl_buffer {
|
||||||
id: current_id + 2,
|
id: current_id + 2,
|
||||||
offset: 800 * 800, // pixel offset
|
offset: 800 * 800, // pixel offset in pool
|
||||||
width: 800,
|
width: 800,
|
||||||
height: 800
|
height: 800,
|
||||||
|
ready: true,
|
||||||
});
|
});
|
||||||
self.wl_shm_pool_create_buffer(buffer1.as_ref().unwrap())?;
|
self.wl_shm_pool_create_buffer(buffer1.as_ref().unwrap())?;
|
||||||
self.wl_shm_pool_create_buffer(buffer2.as_ref().unwrap())?;
|
self.wl_shm_pool_create_buffer(buffer2.as_ref().unwrap())?;
|
||||||
@@ -84,37 +86,29 @@ impl WlClient {
|
|||||||
// version,
|
// version,
|
||||||
// );
|
// );
|
||||||
|
|
||||||
// TODO: Collapse these into one line (probably using a macro)
|
macro_rules! bind_global {
|
||||||
|
($global:tt) => {
|
||||||
|
let current_id = self.current_id.fetch_add(1, Ordering::Relaxed) + 1;
|
||||||
|
self.wl_registry_bind(&name, &interface, &version, ¤t_id)?;
|
||||||
|
self.$global.store(current_id, Ordering::Relaxed);
|
||||||
|
self.init_toplevel().unwrap_or_else(|err| {eprintln!("{}", err)});
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
if interface == "wl_shm" {
|
if interface == "wl_shm" {
|
||||||
let current_id = self.current_id.fetch_add(1, Ordering::Relaxed) + 1;
|
bind_global!(shm_id);
|
||||||
self.wl_registry_bind(&name, &interface, &version, ¤t_id)?;
|
|
||||||
self.shm_id.store(current_id, Ordering::Relaxed);
|
|
||||||
self.init_toplevel().unwrap_or_else(|err| {eprintln!("{}", err)});
|
|
||||||
}
|
}
|
||||||
else if interface == "wl_compositor" {
|
else if interface == "wl_compositor" {
|
||||||
let current_id = self.current_id.fetch_add(1, Ordering::Relaxed) + 1;
|
bind_global!(compositor_id);
|
||||||
self.wl_registry_bind(&name, &interface, &version, ¤t_id)?;
|
|
||||||
self.compositor_id.store(current_id, Ordering::Relaxed);
|
|
||||||
self.init_toplevel().unwrap_or_else(|err| {eprintln!("{}", err)});
|
|
||||||
}
|
}
|
||||||
else if interface == "xdg_wm_base" {
|
else if interface == "xdg_wm_base" {
|
||||||
let current_id = self.current_id.fetch_add(1, Ordering::Relaxed) + 1;
|
bind_global!(xdg_wm_base_id);
|
||||||
self.wl_registry_bind(&name, &interface, &version, ¤t_id)?;
|
|
||||||
self.xdg_wm_base_id.store(current_id, Ordering::Relaxed);
|
|
||||||
self.init_toplevel().unwrap_or_else(|err| {eprintln!("{}", err)});
|
|
||||||
}
|
}
|
||||||
else if interface == "zwlr_layer_shell_v1" {
|
else if interface == "zwlr_layer_shell_v1" {
|
||||||
let current_id = self.current_id.fetch_add(1, Ordering::Relaxed) + 1;
|
bind_global!(layer_shell_id);
|
||||||
self.wl_registry_bind(&name, &interface, &version, ¤t_id)?;
|
|
||||||
self.layer_shell_id.store(current_id, Ordering::Relaxed);
|
|
||||||
self.init_toplevel().unwrap_or_else(|err| {eprintln!("{}", err)});
|
|
||||||
}
|
}
|
||||||
else if interface == "wl_seat" {
|
else if interface == "wl_seat" {
|
||||||
let current_id = self.current_id.fetch_add(1, Ordering::Relaxed) + 1;
|
bind_global!(seat_id);
|
||||||
self.wl_registry_bind(&name, &interface, &version, ¤t_id)?;
|
|
||||||
self.seat_id.store(current_id, Ordering::Relaxed);
|
|
||||||
self.init_toplevel().unwrap_or_else(|err| {eprintln!("{}", err)});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ pub struct wl_buffer {
|
|||||||
pub offset: usize,
|
pub offset: usize,
|
||||||
pub width: usize,
|
pub width: usize,
|
||||||
pub height: usize,
|
pub height: usize,
|
||||||
|
pub ready: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl WlClient {
|
impl WlClient {
|
||||||
|
|||||||
Reference in New Issue
Block a user