Compare commits

...

2 Commits

Author SHA1 Message Date
1ec5921248 chore: add debug flag + housekeeping 2025-06-23 12:49:34 +10:00
18d349c11f fix: ensure TagEmpty event fires 2025-06-23 12:41:01 +10:00
2 changed files with 17 additions and 16 deletions

View File

@ -2,7 +2,7 @@ mod ipc;
mod manager;
mod socket;
use std::io::Read;
use std::{env, io::Read};
use anyhow::{Context, Result, anyhow};
use microxdg::Xdg;
@ -31,7 +31,11 @@ fn main() -> Result<()> {
tracing_subscriber::fmt()
.with_max_level(tracing::Level::DEBUG)
.init();
let span = tracing::span!(tracing::Level::DEBUG, "main");
let span = if env::var("NIRI_TAG_DEBUG").is_ok() {
tracing::span!(tracing::Level::DEBUG, "main")
} else {
tracing::span!(tracing::Level::INFO, "main")
};
let _ = span.enter();
// spawn socket consumer for niri event stream
let (niri_tx, niri_rx) = smol::channel::unbounded();

View File

@ -158,7 +158,6 @@ impl NiriTag {
Tag(tag) => {
tracing::debug!("Changing tag {}", tag);
let tag_visible = *self.tags.entry(tag).or_insert(true);
tracing::debug!("Windows: {:?}", self.windows);
let affected_windows: Vec<u64> = self
.windows
.iter()
@ -239,7 +238,7 @@ impl NiriTag {
})
.detach();
};
let add_tag = async |tx: Sender<TagEvent>, windows: &HashMap<u64, u8>, t| {
let add_tag_fire = async |tx: Sender<TagEvent>, windows: &HashMap<u64, u8>, t| {
if windows
.iter()
.filter(|(_, tag)| **tag == t)
@ -249,14 +248,12 @@ impl NiriTag {
send_event(tx, TagEvent::TagOccupied(t)).await;
}
};
let rm_tag = async |tx: Sender<TagEvent>, windows: &HashMap<u64, u8>, wid, old_tag| {
if old_tag != 0
&& windows
.iter()
.filter(|(w, tag)| **tag == old_tag && **w != wid)
.collect::<Vec<(_, _)>>()
.is_empty()
{
let rm_tag_fire = async |tx: Sender<TagEvent>, windows: &HashMap<u64, u8>, wid, old_tag| {
let same_tagged = windows
.iter()
.filter(|(w, tag)| **tag == old_tag && **w != wid)
.count();
if same_tagged == 0 && old_tag != 0 {
send_event(tx, TagEvent::TagEmpty(old_tag)).await;
}
};
@ -294,7 +291,7 @@ impl NiriTag {
self.windows.insert(wid, t);
tracing::debug!("adding tag {} to {}", t, wid);
let tx = self.ev_tx.clone();
add_tag(tx, &self.windows, t).await;
add_tag_fire(tx, &self.windows, t).await;
Window(wid)
}
TagCmd::RemoveTagFromWin(_) => {
@ -303,7 +300,7 @@ impl NiriTag {
let old_tag = self.windows.insert(wid, 0).unwrap_or(0);
tracing::debug!("resetting tag on {}", wid);
let tx = self.ev_tx.clone();
rm_tag(tx, &self.windows, wid, old_tag).await;
rm_tag_fire(tx, &self.windows, wid, old_tag).await;
Window(wid)
}
TagCmd::ToggleTagOnWin(t) => {
@ -314,9 +311,9 @@ impl NiriTag {
let toggle = if this_tag == t { 0 } else { t };
let tx = self.ev_tx.clone();
if toggle == 0 {
rm_tag(tx, &self.windows, wid, this_tag).await;
rm_tag_fire(tx, &self.windows, wid, this_tag).await;
} else {
add_tag(tx, &self.windows, t).await;
add_tag_fire(tx, &self.windows, t).await;
}
tracing::debug!("toggling {} to tag {}", wid, toggle);
self.windows.insert(wid, toggle);