diff --git a/src/tag.rs b/src/tag.rs index f4b3490..f4cfda7 100644 --- a/src/tag.rs +++ b/src/tag.rs @@ -1,11 +1,10 @@ // SPDX-License-Identifier: GPL-3.0-or-later use std::{ + cell::RefCell, hash::Hash, - sync::{ - atomic::{AtomicU32, Ordering}, - Arc, Mutex, - }, + rc::Rc, + sync::atomic::{AtomicU32, Ordering}, }; use smithay::output::Output; @@ -64,31 +63,25 @@ impl Eq for TagInner {} /// /// A window may have 0 or more tags, and you can display 0 or more tags /// on each output at a time. -#[derive(Debug, Clone)] -pub struct Tag(Arc>); - -impl PartialEq for Tag { - fn eq(&self, other: &Self) -> bool { - Arc::ptr_eq(&self.0, &other.0) - } -} +#[derive(Debug, Clone, PartialEq)] +pub struct Tag(Rc>); // RefCell Safety: These methods should never panic because they are all self-contained or Copy. impl Tag { pub fn id(&self) -> TagId { - self.0.lock().expect("tag already locked").id + self.0.borrow().id } pub fn name(&self) -> String { - self.0.lock().expect("tag already locked").name.clone() + self.0.borrow().name.clone() } pub fn active(&self) -> bool { - self.0.lock().expect("tag already locked").active + self.0.borrow().active } pub fn set_active(&self, active: bool, state: &mut State) { - self.0.lock().expect("tag already locked").active = active; + self.0.borrow_mut().active = active; state.signal_state.tag_active.signal(|buf| { buf.push_back( @@ -103,7 +96,7 @@ impl Tag { impl Tag { pub fn new(name: String) -> Self { - Self(Arc::new(Mutex::new(TagInner { + Self(Rc::new(RefCell::new(TagInner { id: TagId::next(), name, active: false, diff --git a/tests/common/mod.rs b/tests/common/mod.rs index b9c8b93..45e6142 100644 --- a/tests/common/mod.rs +++ b/tests/common/mod.rs @@ -42,14 +42,9 @@ pub fn test_api( let loop_signal = event_loop.get_signal(); - let join_handle = std::thread::spawn(move || { - let res = std::panic::catch_unwind(|| { - test(sender); - }); + let join_handle = tokio::task::spawn_blocking(move || { + test(sender); loop_signal.stop(); - if let Err(err) = res { - std::panic::resume_unwind(err); - } }); event_loop.run(None, &mut state, |state| { @@ -71,7 +66,10 @@ pub fn test_api( ); })?; - if let Err(err) = join_handle.join() { + if let Err(err) = tokio::task::block_in_place(|| { + let handle = tokio::runtime::Handle::current(); + handle.block_on(join_handle) + }) { panic!("{err:?}"); }