chore: add debug flag + housekeeping
This commit is contained in:
parent
18d349c11f
commit
67e77c122f
@ -154,6 +154,7 @@ pub async fn event_provider(
|
||||
};
|
||||
if let Res::BadSockets(bad) = res {
|
||||
bad.into_iter().for_each(|b| {
|
||||
// TODO does Drop close this?
|
||||
sockets.remove(&b);
|
||||
});
|
||||
}
|
||||
|
@ -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;
|
||||
@ -28,10 +28,19 @@ fn main() -> Result<()> {
|
||||
// let systemd know we're ready
|
||||
let _ = libsystemd::daemon::notify(false, &[libsystemd::daemon::NotifyState::Ready])?;
|
||||
// debug stuff
|
||||
let debug = env::var("NIRI_TAG_DEBUG").is_ok();
|
||||
tracing_subscriber::fmt()
|
||||
.with_max_level(tracing::Level::DEBUG)
|
||||
.with_max_level(if debug {
|
||||
tracing::Level::DEBUG
|
||||
} else {
|
||||
tracing::Level::INFO
|
||||
})
|
||||
.init();
|
||||
let span = tracing::span!(tracing::Level::DEBUG, "main");
|
||||
let span = if debug {
|
||||
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();
|
||||
|
@ -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,8 +248,7 @@ impl NiriTag {
|
||||
send_event(tx, TagEvent::TagOccupied(t)).await;
|
||||
}
|
||||
};
|
||||
let rm_tag = async |tx: Sender<TagEvent>, windows: &HashMap<u64, u8>, wid, old_tag| {
|
||||
tracing::debug!("removing tag {}", wid);
|
||||
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)
|
||||
@ -293,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(_) => {
|
||||
@ -302,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) => {
|
||||
@ -313,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);
|
||||
|
11
lib/main.rs
11
lib/main.rs
@ -31,8 +31,17 @@ pub struct TagState {
|
||||
pub urgent: bool,
|
||||
}
|
||||
|
||||
#[derive(Default, Deserialize)]
|
||||
#[derive(Deserialize)]
|
||||
pub struct Config {
|
||||
pub prepopulate: u8,
|
||||
pub strict: bool,
|
||||
}
|
||||
|
||||
impl Default for Config {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
prepopulate: 3,
|
||||
strict: true,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user