1
0
Fork 0
forked from wry/wry

all: add HashMapExt

This commit is contained in:
Julian Orth 2024-05-08 15:13:21 +02:00
parent 4c0e6d9b51
commit 0d7a07ec40
29 changed files with 99 additions and 69 deletions

View file

@ -33,7 +33,7 @@ use {
object::Version,
state::DeviceHandlerData,
tree::{Direction, Node, ToplevelNode},
utils::{bitflags::BitflagsExt, smallmap::SmallMap},
utils::{bitflags::BitflagsExt, hash_map_ext::HashMapExt, smallmap::SmallMap},
wire::WlDataOfferId,
xkbcommon::{KeyboardState, XkbState, XKB_KEY_DOWN, XKB_KEY_UP},
},
@ -237,7 +237,7 @@ impl WlSeatGlobal {
| InputEvent::TabletPadStrip { time_usec, .. } => {
self.last_input_usec.set(time_usec);
if self.idle_notifications.is_not_empty() {
for (_, notification) in self.idle_notifications.lock().drain() {
for notification in self.idle_notifications.lock().drain_values() {
notification.resume.trigger();
}
}

View file

@ -19,7 +19,10 @@ use {
object::Version,
time::now_usec,
tree::{FoundNode, Node},
utils::{bindings::PerClientBindings, clonecell::CloneCell, copyhashmap::CopyHashMap},
utils::{
bindings::PerClientBindings, clonecell::CloneCell, copyhashmap::CopyHashMap,
hash_map_ext::HashMapExt,
},
},
std::{
cell::{Cell, RefCell},
@ -293,18 +296,18 @@ impl WlSeatGlobal {
pub fn tablet_clear(&self) {
self.tablet.seats.clear();
for (_, tablet) in self.tablet.tablets.lock().drain() {
for tablet in self.tablet.tablets.lock().drain_values() {
tablet.pads.clear();
tablet.bindings.clear();
tablet.tools.clear();
}
for (_, tool) in self.tablet.tools.lock().drain() {
for tool in self.tablet.tools.lock().drain_values() {
tool.cursor.detach();
tool.opt.tool.take();
tool.tool_owner.destroy(&tool);
tool.bindings.clear();
}
for (_, pad) in self.tablet.pads.lock().drain() {
for pad in self.tablet.pads.lock().drain_values() {
pad.pad_owner.destroy(&pad);
pad.tablet.take();
pad.bindings.clear();
@ -324,14 +327,14 @@ impl WlSeatGlobal {
let Some(tablet) = self.tablet.tablets.remove(&id) else {
return;
};
for (_, tool) in tablet.tools.lock().drain() {
for tool in tablet.tools.lock().drain_values() {
self.tablet_handle_remove_tool(now_usec(), tool.id);
}
for (_, pad) in tablet.pads.lock().drain() {
for pad in tablet.pads.lock().drain_values() {
pad.pad_owner.destroy(&pad);
pad.tablet.take();
}
for (_, binding) in tablet.bindings.lock().drain() {
for binding in tablet.bindings.lock().drain_values() {
binding.send_removed();
}
}

View file

@ -14,7 +14,7 @@ use {
wl_surface::WlSurface,
},
time::{now_usec, usec_to_msec},
utils::clonecell::CloneCell,
utils::{clonecell::CloneCell, hash_map_ext::HashMapExt},
},
std::{cell::Cell, rc::Rc},
};
@ -76,7 +76,7 @@ impl WlSeatGlobal {
if let Some(tablet) = pad.tablet.take() {
tablet.pads.remove(&pad.id);
}
for (_, binding) in pad.bindings.lock().drain() {
for binding in pad.bindings.lock().drain_values() {
binding.send_removed();
}
}

View file

@ -15,7 +15,7 @@ use {
},
rect::Rect,
time::usec_to_msec,
utils::clonecell::CloneCell,
utils::{clonecell::CloneCell, hash_map_ext::HashMapExt},
},
std::{cell::Cell, rc::Rc},
};
@ -31,7 +31,7 @@ impl WlSeatGlobal {
tool.opt.tool.take();
tool.cursor.detach();
tool.tool_owner.destroy(&tool);
for (_, binding) in tool.bindings.lock().drain() {
for binding in tool.bindings.lock().drain_values() {
binding.send_removed();
}
tool.tablet.tools.remove(&id);

View file

@ -4,6 +4,7 @@ use {
utils::{
clonecell::CloneCell,
copyhashmap::CopyHashMap,
hash_map_ext::HashMapExt,
linkedlist::{LinkedList, LinkedNode, NodeRef},
numcell::NumCell,
},
@ -102,7 +103,7 @@ impl CommitTimelines {
}
pub fn clear(&self) {
for (_, list) in self.gc.lock().drain() {
for list in self.gc.lock().drain_values() {
break_loops(&list);
}
}

View file

@ -29,7 +29,7 @@ use {
OutputNode, ToplevelData, ToplevelNode, ToplevelNodeBase, ToplevelNodeId,
WorkspaceNode,
},
utils::clonecell::CloneCell,
utils::{clonecell::CloneCell, hash_map_ext::HashMapExt},
wire::{xdg_toplevel::*, XdgToplevelId},
},
ahash::{AHashMap, AHashSet},
@ -218,7 +218,7 @@ impl XdgToplevelRequestHandler for XdgToplevel {
Some(p) => Some(p.children.borrow_mut()),
_ => None,
};
for (_, child) in children.drain() {
for child in children.drain_values() {
child.parent.set(parent.clone());
if let Some(parent_children) = &mut parent_children {
parent_children.insert(child.id, child);
@ -418,7 +418,7 @@ impl XdgToplevel {
{
let new_parent = self.parent.get();
let mut children = self.children.borrow_mut();
for (_, child) in children.drain() {
for child in children.drain_values() {
child.parent.set(new_parent.clone());
}
}

View file

@ -5,7 +5,7 @@ use {
ifs::{wl_buffer::WlBuffer, zwp_linux_dmabuf_v1::ZwpLinuxDmabufV1},
leaks::Tracker,
object::Object,
utils::errorfmt::ErrorFmt,
utils::{errorfmt::ErrorFmt, hash_map_ext::HashMapExt},
video::dmabuf::{DmaBuf, DmaBufPlane, PlaneVec, MAX_PLANES},
wire::{zwp_linux_buffer_params_v1::*, WlBufferId, ZwpLinuxBufferParamsV1Id},
},
@ -90,7 +90,7 @@ impl ZwpLinuxBufferParamsV1 {
modifier,
planes: PlaneVec::new(),
};
let mut planes: Vec<_> = self.planes.borrow_mut().drain().map(|v| v.1).collect();
let mut planes: Vec<_> = self.planes.borrow_mut().drain_values().collect();
planes.sort_by_key(|a| a.plane_idx);
for (i, p) in planes.into_iter().enumerate() {
if p.plane_idx as usize != i {