diff --git a/src/wayland/wl_client.rs b/src/wayland/wl_client.rs index 439ef90..509496d 100644 --- a/src/wayland/wl_client.rs +++ b/src/wayland/wl_client.rs @@ -10,26 +10,27 @@ struct WlHeader { pub struct WlClient { pub socket: Mutex, - pub running: AtomicBool, pub current_id: AtomicU32, - pub registry_id: AtomicU32, - pub shm_id: AtomicU32, - pub shmpool_id: AtomicU32, + pub running: AtomicBool, pub shm_pool: Mutex, - pub compositor_id: AtomicU32, - pub surface_id: AtomicU32, pub active_buffer: AtomicBool, pub buffer1: Mutex>, pub buffer2: Mutex>, - 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>, pub keymap: RwLock>>>, pub drawables: Mutex>>, + + 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 { @@ -131,6 +132,12 @@ impl WlClient { 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 self.wl_registry_global(&event)?; } diff --git a/src/wayland/wl_registry.rs b/src/wayland/wl_registry.rs index 7253cb3..82e4f47 100644 --- a/src/wayland/wl_registry.rs +++ b/src/wayland/wl_registry.rs @@ -35,13 +35,15 @@ impl WlClient { id: current_id + 1, offset: 0, width: 800, - height: 800 + height: 800, + ready: true, }); *buffer2 = Some(wl_buffer { id: current_id + 2, - offset: 800 * 800, // pixel offset + offset: 800 * 800, // pixel offset in pool width: 800, - height: 800 + height: 800, + ready: true, }); self.wl_shm_pool_create_buffer(buffer1.as_ref().unwrap())?; self.wl_shm_pool_create_buffer(buffer2.as_ref().unwrap())?; @@ -84,37 +86,29 @@ impl WlClient { // 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" { - let current_id = self.current_id.fetch_add(1, Ordering::Relaxed) + 1; - 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)}); + bind_global!(shm_id); } else if interface == "wl_compositor" { - let current_id = self.current_id.fetch_add(1, Ordering::Relaxed) + 1; - 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)}); + bind_global!(compositor_id); } else if interface == "xdg_wm_base" { - let current_id = self.current_id.fetch_add(1, Ordering::Relaxed) + 1; - 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)}); + bind_global!(xdg_wm_base_id); } else if interface == "zwlr_layer_shell_v1" { - let current_id = self.current_id.fetch_add(1, Ordering::Relaxed) + 1; - 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)}); + bind_global!(layer_shell_id); } else if interface == "wl_seat" { - let current_id = self.current_id.fetch_add(1, Ordering::Relaxed) + 1; - 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)}); + bind_global!(seat_id); } Ok(()) diff --git a/src/wayland/wl_shm.rs b/src/wayland/wl_shm.rs index 0c1d305..a115436 100644 --- a/src/wayland/wl_shm.rs +++ b/src/wayland/wl_shm.rs @@ -10,6 +10,7 @@ pub struct wl_buffer { pub offset: usize, pub width: usize, pub height: usize, + pub ready: bool, } impl WlClient {