Clean up a few things
This commit is contained in:
@@ -10,26 +10,27 @@ struct WlHeader {
|
||||
|
||||
pub struct WlClient {
|
||||
pub socket: Mutex<UnixStream>,
|
||||
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<shm::ShmPool>,
|
||||
pub compositor_id: AtomicU32,
|
||||
pub surface_id: AtomicU32,
|
||||
pub active_buffer: AtomicBool,
|
||||
pub buffer1: 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: RwLock<Option<HashMap<u32, Vec<String>>>>,
|
||||
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 {
|
||||
@@ -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)?;
|
||||
}
|
||||
|
||||
@@ -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(())
|
||||
|
||||
@@ -10,6 +10,7 @@ pub struct wl_buffer {
|
||||
pub offset: usize,
|
||||
pub width: usize,
|
||||
pub height: usize,
|
||||
pub ready: bool,
|
||||
}
|
||||
|
||||
impl WlClient {
|
||||
|
||||
Reference in New Issue
Block a user