Compare commits
No commits in common. "b970e02f369860645616cdf49fe04e04aa46b3d1" and "30662edfe8bac80b356324e642a188f505429d80" have entirely different histories.
b970e02f36
...
30662edfe8
4 changed files with 48 additions and 136 deletions
|
|
@ -11,17 +11,11 @@ use niri_tag::Config;
|
|||
fn main() -> Result<()> {
|
||||
// try to read a config
|
||||
let xdg = Xdg::new()?;
|
||||
let mut config_file = xdg.config()?;
|
||||
config_file.push("niri-tag");
|
||||
config_file.push("config.toml");
|
||||
if !config_file.try_exists().is_ok_and(|i| i) {
|
||||
config_file.clear();
|
||||
config_file.push("etc");
|
||||
config_file.push("niri-tag");
|
||||
config_file.push("config.toml");
|
||||
}
|
||||
let mut config_dir = xdg.config()?;
|
||||
config_dir.push("niri-tag");
|
||||
config_dir.push("config.toml");
|
||||
|
||||
let config = std::fs::File::open(config_file)
|
||||
let config = std::fs::File::open(config_dir)
|
||||
.map_err(|e| anyhow!(e))
|
||||
.and_then(|mut f| {
|
||||
let mut buf = String::new();
|
||||
|
|
|
|||
|
|
@ -47,11 +47,10 @@ impl NiriTag {
|
|||
ts.occupied = false;
|
||||
}
|
||||
});
|
||||
if let Some(old) = self.tags.get(&old_tag)
|
||||
&& old_tag != 0
|
||||
&& !old.occupied
|
||||
{
|
||||
self.fire_event(TagEvent::TagEmpty(old_tag)).await;
|
||||
if let Some(old) = self.tags.get(&old_tag) {
|
||||
if old_tag != 0 && !old.occupied {
|
||||
self.fire_event(TagEvent::TagEmpty(old_tag)).await;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -209,14 +208,14 @@ impl NiriTag {
|
|||
affected_windows,
|
||||
)
|
||||
.await;
|
||||
if let Some(focus) = focus
|
||||
&& tag_visible
|
||||
{
|
||||
tell(
|
||||
&mut self.socket,
|
||||
Request::Action(Action::FocusWindow { id: focus }),
|
||||
)
|
||||
.await?;
|
||||
if let Some(focus) = focus {
|
||||
if tag_visible {
|
||||
tell(
|
||||
&mut self.socket,
|
||||
Request::Action(Action::FocusWindow { id: focus }),
|
||||
)
|
||||
.await?;
|
||||
}
|
||||
}
|
||||
}
|
||||
TagExclusive(t) => {
|
||||
|
|
@ -294,68 +293,38 @@ impl NiriTag {
|
|||
}
|
||||
Receivable::TagCmd(cmd) => match cmd {
|
||||
TagCmd::AddTagToWin(t) => {
|
||||
let win = self.get_focused_window().await?;
|
||||
if win
|
||||
.app_id
|
||||
.as_ref()
|
||||
.is_some_and(|name| self.config.scratchpads.contains_key(name))
|
||||
{
|
||||
&[]
|
||||
let wid = self.get_focused_window().await?.id;
|
||||
self.change_window_tag(wid, Some(t)).await?;
|
||||
let entry = self.tags.entry(t).or_default();
|
||||
if entry.windows.len() == 1 && self.config.activation_on_fill {
|
||||
entry.enabled = true;
|
||||
self.fire_event(TagEvent::TagEnabled(t)).await;
|
||||
&[Tag(t), Window(wid)]
|
||||
} else {
|
||||
let wid = win.id;
|
||||
self.change_window_tag(wid, Some(t)).await?;
|
||||
let entry = self.tags.entry(t).or_default();
|
||||
if entry.windows.len() == 1 && self.config.activation_on_fill {
|
||||
entry.enabled = true;
|
||||
self.fire_event(TagEvent::TagEnabled(t)).await;
|
||||
&[Tag(t), Window(wid)]
|
||||
} else {
|
||||
&[Window(wid)]
|
||||
}
|
||||
}
|
||||
}
|
||||
TagCmd::RemoveTagFromWin(_) => {
|
||||
let win = self.get_focused_window().await?;
|
||||
if win
|
||||
.app_id
|
||||
.as_ref()
|
||||
.is_some_and(|name| self.config.scratchpads.contains_key(name))
|
||||
{
|
||||
&[]
|
||||
} else {
|
||||
let wid = win.id;
|
||||
self.change_window_tag(wid, None).await?;
|
||||
&[Window(wid)]
|
||||
}
|
||||
}
|
||||
TagCmd::RemoveTagFromWin(_) => {
|
||||
let wid = self.get_focused_window().await?.id;
|
||||
self.change_window_tag(wid, None).await?;
|
||||
&[Window(wid)]
|
||||
}
|
||||
TagCmd::ToggleTagOnWin(t) => {
|
||||
let win = self.get_focused_window().await?;
|
||||
if win
|
||||
.app_id
|
||||
.as_ref()
|
||||
.is_some_and(|name| self.config.scratchpads.contains_key(name))
|
||||
{
|
||||
&[]
|
||||
let wid = self.get_focused_window().await?.id;
|
||||
let new_tag = if *self.windows.entry(wid).or_insert(0) == t {
|
||||
0
|
||||
} else {
|
||||
let wid = win.id;
|
||||
let new_tag = if *self.windows.entry(wid).or_insert(0) == t {
|
||||
0
|
||||
} else {
|
||||
t
|
||||
};
|
||||
self.change_window_tag(wid, Some(new_tag)).await?;
|
||||
tracing::debug!("toggling {} to tag {}", wid, new_tag);
|
||||
let entry = self.tags.entry(new_tag).or_default();
|
||||
if new_tag != 0
|
||||
&& entry.windows.len() == 1
|
||||
&& self.config.activation_on_fill
|
||||
{
|
||||
entry.enabled = true;
|
||||
self.fire_event(TagEvent::TagEnabled(t)).await;
|
||||
&[Tag(t), Window(wid)]
|
||||
} else {
|
||||
&[Window(wid)]
|
||||
}
|
||||
t
|
||||
};
|
||||
self.change_window_tag(wid, Some(new_tag)).await?;
|
||||
tracing::debug!("toggling {} to tag {}", wid, new_tag);
|
||||
let entry = self.tags.entry(new_tag).or_default();
|
||||
if new_tag != 0 && entry.windows.len() == 1 && self.config.activation_on_fill {
|
||||
entry.enabled = true;
|
||||
self.fire_event(TagEvent::TagEnabled(t)).await;
|
||||
&[Tag(t), Window(wid)]
|
||||
} else {
|
||||
&[Window(wid)]
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -417,26 +386,7 @@ impl NiriTag {
|
|||
use Event::*;
|
||||
match ev {
|
||||
WindowOpenedOrChanged { window } => {
|
||||
let wid = window.id;
|
||||
let current_tag = self.windows.get(&wid).copied();
|
||||
// only reassign if window is new or still untagged
|
||||
// this handles the common case where app_id: None arrives first
|
||||
if current_tag.is_none() || current_tag == Some(0) {
|
||||
if let Some(ref app_id) = window.app_id
|
||||
&& let Some(&tag) = self.config.scratchpads.get(app_id)
|
||||
{
|
||||
tracing::debug!(
|
||||
"scratchpad: auto-assigning wid={} app_id={} to tag {}",
|
||||
wid,
|
||||
app_id,
|
||||
tag
|
||||
);
|
||||
self.change_window_tag(wid, Some(tag)).await?;
|
||||
self.do_actions(&[TagAction::Window(wid)]).await?;
|
||||
} else if current_tag.is_none() {
|
||||
self.windows.insert(wid, 0);
|
||||
}
|
||||
}
|
||||
self.windows.entry(window.id).or_insert(0);
|
||||
Ok(())
|
||||
}
|
||||
WindowClosed { id } => {
|
||||
|
|
@ -445,10 +395,10 @@ impl NiriTag {
|
|||
ts.windows.remove(&id);
|
||||
ts.occupied = !ts.windows.is_empty();
|
||||
});
|
||||
if let Some(tag) = self.tags.get(&t)
|
||||
&& !tag.occupied
|
||||
{
|
||||
self.fire_event(TagEvent::TagEmpty(t)).await;
|
||||
if let Some(tag) = self.tags.get(&t) {
|
||||
if !tag.occupied {
|
||||
self.fire_event(TagEvent::TagEmpty(t)).await;
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
|
|
@ -527,6 +477,7 @@ impl NiriTag {
|
|||
(0..=self.config.prepopulate).for_each(|i| {
|
||||
self.tags.entry(i).or_default();
|
||||
});
|
||||
|
||||
loop {
|
||||
let recvd: Receivable = future::or(
|
||||
async { ev_rx.recv().await.map(Receivable::Event) },
|
||||
|
|
|
|||
|
|
@ -60,7 +60,6 @@ pub struct Config {
|
|||
pub strict: bool,
|
||||
#[serde(default = "default_true")]
|
||||
pub activation_on_fill: bool,
|
||||
pub scratchpads: HashMap<String, u8>,
|
||||
}
|
||||
|
||||
impl Default for Config {
|
||||
|
|
@ -69,7 +68,6 @@ impl Default for Config {
|
|||
prepopulate: 3,
|
||||
strict: true,
|
||||
activation_on_fill: true,
|
||||
scratchpads: HashMap::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
31
module.nix
31
module.nix
|
|
@ -8,12 +8,9 @@ let
|
|||
inherit (lib)
|
||||
mkEnableOption
|
||||
mkPackageOption
|
||||
mkOption
|
||||
mkIf
|
||||
getExe
|
||||
types
|
||||
;
|
||||
inherit (types) attrsOf bool;
|
||||
name = "Niri Tag Manager";
|
||||
in
|
||||
{
|
||||
|
|
@ -23,18 +20,6 @@ in
|
|||
nullable = true;
|
||||
default = "niri-tag";
|
||||
};
|
||||
prepopulate = mkOption {
|
||||
type = types.numbers.between 0 255;
|
||||
default = 3;
|
||||
};
|
||||
scratchpads = mkOption {
|
||||
type = attrsOf (types.numbers.between 1 255);
|
||||
default = { };
|
||||
};
|
||||
strict = mkOption {
|
||||
type = bool;
|
||||
default = true;
|
||||
};
|
||||
};
|
||||
config =
|
||||
let
|
||||
|
|
@ -55,22 +40,6 @@ in
|
|||
PrivateTmp = true;
|
||||
};
|
||||
};
|
||||
etc.environment."/etc/niri-tag/config.toml" =
|
||||
let
|
||||
scratchpads =
|
||||
let
|
||||
contents = lib.mapAttrsToList (app: number: "${app} = ${toString number}\n") cfg.scratchpads;
|
||||
in
|
||||
lib.optionalString (lib.count <| lib.attrsToList cfg.scratchpads) ''
|
||||
[scratchpads]
|
||||
${contents}
|
||||
'';
|
||||
in
|
||||
pkgs.writeTextFile "config.toml" ''
|
||||
prepopulate = ${toString cfg.prepopulate}
|
||||
strict = ${lib.boolToString cfg.strict}
|
||||
${scratchpads}
|
||||
'';
|
||||
environment.systemPackages = [ cfg.package ];
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue