1
0
Fork 0
mirror of https://github.com/Zedfrigg/ironbar.git synced 2025-07-01 02:31:04 +02:00

refactor: macros to reduce repeated code

This commit is contained in:
Jake Stanger 2022-12-11 22:45:52 +00:00
parent 9d5049dde0
commit 5e21cbcca6
No known key found for this signature in database
GPG key ID: C51FC8F9CB0BEA61
18 changed files with 225 additions and 248 deletions

View file

@ -4,7 +4,7 @@ use crate::dynamic_string::DynamicString;
use crate::modules::{Module, ModuleInfo, ModuleLocation, ModuleUpdateEvent, WidgetContext};
use crate::popup::Popup;
use crate::script::{OutputStream, Script};
use crate::{await_sync, error as err, Config};
use crate::{await_sync, read_lock, send, write_lock, Config};
use color_eyre::Result;
use gtk::gdk::Monitor;
use gtk::prelude::*;
@ -251,10 +251,7 @@ where
/// Registers the popup content with the popup.
fn register_popup_content(popup: &Arc<RwLock<Popup>>, id: usize, popup_content: gtk::Box) {
popup
.write()
.expect(err::ERR_WRITE_LOCK)
.register_content(id, popup_content);
write_lock!(popup).register_content(id, popup_content);
}
/// Sets up the bridge channel receiver
@ -277,14 +274,14 @@ fn setup_receiver<TSend>(
match ev {
ModuleUpdateEvent::Update(update) => {
if has_popup {
p_tx.send(update.clone()).expect(err::ERR_CHANNEL_SEND);
send!(p_tx, update.clone());
}
w_tx.send(update).expect(err::ERR_CHANNEL_SEND);
send!(w_tx, update);
}
ModuleUpdateEvent::TogglePopup(geometry) => {
debug!("Toggling popup for {} [#{}]", name, id);
let popup = popup.read().expect(err::ERR_READ_LOCK);
let popup = read_lock!(popup);
if popup.is_visible() {
popup.hide();
} else {
@ -295,7 +292,7 @@ fn setup_receiver<TSend>(
ModuleUpdateEvent::OpenPopup(geometry) => {
debug!("Opening popup for {} [#{}]", name, id);
let popup = popup.read().expect(err::ERR_READ_LOCK);
let popup = read_lock!(popup);
popup.hide();
popup.show_content(id);
popup.show(geometry);
@ -303,7 +300,7 @@ fn setup_receiver<TSend>(
ModuleUpdateEvent::ClosePopup => {
debug!("Closing popup for {} [#{}]", name, id);
let popup = popup.read().expect(err::ERR_READ_LOCK);
let popup = read_lock!(popup);
popup.hide();
}
}
@ -333,7 +330,7 @@ fn setup_module_common_options(container: EventBox, common: CommonConfig) {
spawn(async move {
script
.run(|(_, success)| {
tx.send(success).expect(err::ERR_CHANNEL_SEND);
send!(tx, success);
})
.await;
});