use slab instead of reinventing the wheel (#112)

This commit is contained in:
Ferdinand Schober
2024-04-26 00:10:04 +02:00
committed by GitHub
parent 279e582698
commit 3e96b42067
14 changed files with 83 additions and 115 deletions

View File

@@ -90,15 +90,13 @@ pub fn run() -> Result<()> {
log::info!("client {handle} deactivated");
}
}
FrontendEvent::Created(client) => {
let handle = client.handle;
FrontendEvent::Created(handle, client) => {
let port = client.port;
let pos = client.pos;
let hostname = client.hostname.as_deref().unwrap_or("");
log::info!("new client ({handle}): {hostname}:{port} - {pos}");
}
FrontendEvent::Updated(client) => {
let handle = client.handle;
FrontendEvent::Updated(handle, client) => {
let port = client.port;
let pos = client.pos;
let hostname = client.hostname.as_deref().unwrap_or("");
@@ -111,10 +109,10 @@ pub fn run() -> Result<()> {
log::warn!("{e}");
}
FrontendEvent::Enumerate(clients) => {
for (client, active) in clients.into_iter() {
for (handle, client, active) in clients.into_iter() {
log::info!(
"client ({}) [{}]: active: {}, associated addresses: [{}]",
client.handle,
handle,
client.hostname.as_deref().unwrap_or(""),
if active { "yes" } else { "no" },
client

View File

@@ -122,11 +122,11 @@ fn build_ui(app: &Application) {
FrontendEvent::Activated(handle, active) => {
window.activate_client(handle, active);
}
FrontendEvent::Created(client) => {
window.new_client(client, false);
FrontendEvent::Created(handle, client) => {
window.new_client(handle, client, false);
},
FrontendEvent::Updated(client) => {
window.update_client(client);
FrontendEvent::Updated(handle, client) => {
window.update_client(handle, client);
}
FrontendEvent::Error(e) => {
window.show_toast(e.as_str());
@@ -135,12 +135,12 @@ fn build_ui(app: &Application) {
window.delete_client(client);
}
FrontendEvent::Enumerate(clients) => {
for (client, active) in clients {
if window.client_idx(client.handle).is_some() {
window.activate_client(client.handle, active);
window.update_client(client);
for (handle, client, active) in clients {
if window.client_idx(handle).is_some() {
window.activate_client(handle, active);
window.update_client(handle, client);
} else {
window.new_client(client, active);
window.new_client(handle, client, active);
}
}
},

View File

@@ -10,9 +10,9 @@ glib::wrapper! {
}
impl ClientObject {
pub fn new(client: Client, active: bool) -> Self {
pub fn new(handle: ClientHandle, client: Client, active: bool) -> Self {
Object::builder()
.property("handle", client.handle)
.property("handle", handle)
.property("hostname", client.hostname)
.property("port", client.port as u32)
.property("position", client.pos.to_string())

View File

@@ -87,8 +87,8 @@ impl Window {
row
}
pub fn new_client(&self, client: Client, active: bool) {
let client = ClientObject::new(client, active);
pub fn new_client(&self, handle: ClientHandle, client: Client, active: bool) {
let client = ClientObject::new(handle, client, active);
self.clients().append(&client);
self.set_placeholder_visible(false);
}
@@ -115,9 +115,9 @@ impl Window {
}
}
pub fn update_client(&self, client: Client) {
let Some(idx) = self.client_idx(client.handle) else {
log::warn!("could not find client with handle {}", client.handle);
pub fn update_client(&self, handle: ClientHandle, client: Client) {
let Some(idx) = self.client_idx(handle) else {
log::warn!("could not find client with handle {}", handle);
return;
};
let client_object = self.clients().item(idx as u32).unwrap();