From 13105c2bfdb1c5bb8e508d5e1df1fb86c041cfdf Mon Sep 17 00:00:00 2001 From: Donovan Glover Date: Sat, 12 Aug 2023 11:49:29 -0400 Subject: [PATCH 01/15] feat: Dim floating windows with the same class Note that checking for `not floating -> floating` results in inconsistent behavior when the floating state is toggled, so an all-or-nothing approach seems ideal here. The commented lines are me keeping track of the last_floating state so I can reference this commit later if I need to. --- src/lib.rs | 21 +++++++++++++++++++++ src/main.rs | 29 +++++++++++++++++++++++++++-- 2 files changed, 48 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 36749f4..34c2065 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -54,6 +54,18 @@ pub fn spawn_dim_thread( }); } +pub fn set_dim(strength: f64, persist: bool) -> hyprland::Result<()> { + if persist { + Keyword::set("decoration:dim_inactive", "yes")?; + }; + + Keyword::set("decoration:dim_strength", strength)?; + + log("info: Set a permanent dim (until next event) without spawning thread"); + + Ok(()) +} + /// Gets whether the current workspace is a special workspace or not. /// /// This function works by getting which workspace the active window is in. @@ -81,3 +93,12 @@ pub fn special_only_has_one_visible_window() -> bool { false } + +pub fn is_floating() -> bool { + if let Some(client) = Client::get_active().unwrap() { + let Client { floating, .. } = client; + return floating; + } + + false +} diff --git a/src/main.rs b/src/main.rs index 4496aa5..6112489 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,9 @@ use clap::Parser; use cli::Cli; +use hyprdim::is_floating; use hyprdim::is_special; use hyprdim::log; +use hyprdim::set_dim; use hyprdim::spawn_dim_thread; use hyprdim::special_only_has_one_visible_window; use hyprland::data::Workspace; @@ -58,6 +60,8 @@ fn main() -> hyprland::Result<()> { // Keep track of state let num_threads: Arc> = Arc::new(Mutex::new(0)); let last_address: Arc>> = Arc::new(Mutex::new(None)); + let last_class: Arc>> = Arc::new(Mutex::new(None)); + // let last_floating: Arc> = Arc::new(Mutex::new(false)); let in_special_workspace: Arc> = Arc::new(Mutex::new(is_special())); // Initialize with dim so the user sees something, but only if the user wants dim @@ -74,7 +78,7 @@ fn main() -> hyprland::Result<()> { // On active window changes event_listener.add_active_window_change_handler(move |data| { // Ignore the event if no window_address was given - let Some(WindowEventData { window_address, .. }) = data else { return }; + let Some(WindowEventData { window_address, window_class, .. }) = data else { return }; // Clone inside since u16 does not implement copy let num_threads = num_threads.clone(); @@ -86,7 +90,23 @@ fn main() -> hyprland::Result<()> { } } + let mut same_class = false; + + if let Some(ref old_class) = *last_class.lock().unwrap() { + if format!("{old_class}") == format!("{window_class}") { + same_class = true; + } + } + + // let mut both_floating = false; + // + // if *last_floating.lock().unwrap() == is_floating() { + // both_floating = true; + // } + *last_address.lock().unwrap() = Some(window_address.clone()); + *last_class.lock().unwrap() = Some(window_class.clone()); + // *last_floating.lock().unwrap() = is_floating(); // Get the state of the current parent workspace let parent_workspace = Workspace::get_active().unwrap(); @@ -133,7 +153,12 @@ fn main() -> hyprland::Result<()> { } } - spawn_dim_thread(num_threads, strength, persist, duration, false); + // if same_class && is_floating() && !both_floating { + if same_class && is_floating() { + set_dim(strength, persist).unwrap(); + } else { + spawn_dim_thread(num_threads, strength, persist, duration, false); + } }); thread::spawn(move || -> hyprland::Result<()> { From 0deecb18e432907da41e3bc1286a30717f8bb7c9 Mon Sep 17 00:00:00 2001 From: Donovan Glover Date: Sat, 12 Aug 2023 13:16:23 -0400 Subject: [PATCH 02/15] chore: Remove last_floating comments --- src/main.rs | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/main.rs b/src/main.rs index 6112489..fae1176 100644 --- a/src/main.rs +++ b/src/main.rs @@ -61,7 +61,6 @@ fn main() -> hyprland::Result<()> { let num_threads: Arc> = Arc::new(Mutex::new(0)); let last_address: Arc>> = Arc::new(Mutex::new(None)); let last_class: Arc>> = Arc::new(Mutex::new(None)); - // let last_floating: Arc> = Arc::new(Mutex::new(false)); let in_special_workspace: Arc> = Arc::new(Mutex::new(is_special())); // Initialize with dim so the user sees something, but only if the user wants dim @@ -98,15 +97,8 @@ fn main() -> hyprland::Result<()> { } } - // let mut both_floating = false; - // - // if *last_floating.lock().unwrap() == is_floating() { - // both_floating = true; - // } - *last_address.lock().unwrap() = Some(window_address.clone()); *last_class.lock().unwrap() = Some(window_class.clone()); - // *last_floating.lock().unwrap() = is_floating(); // Get the state of the current parent workspace let parent_workspace = Workspace::get_active().unwrap(); @@ -153,7 +145,6 @@ fn main() -> hyprland::Result<()> { } } - // if same_class && is_floating() && !both_floating { if same_class && is_floating() { set_dim(strength, persist).unwrap(); } else { From 26e07afee391bce8dcbe56c1f36340f2810a52ca Mon Sep 17 00:00:00 2001 From: Donovan Glover Date: Sat, 12 Aug 2023 18:24:20 -0400 Subject: [PATCH 03/15] feat: Prevent set_dim windows from being undimmed by threads --- src/lib.rs | 11 ++++++++--- src/main.rs | 6 ++++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 34c2065..3a1d97e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -23,6 +23,7 @@ pub fn log(text: &str) { /// enough, dimming is disabled. pub fn spawn_dim_thread( num_threads: Arc>, + is_set_dim: Arc>, strength: f64, persist: bool, duration: u64, @@ -43,11 +44,15 @@ pub fn spawn_dim_thread( thread::sleep(time::Duration::from_millis(duration)); *num_threads.lock().unwrap() -= 1; - // If this is the last thread, remove dim + // If this is the last thread and we're not setting dim, remove dim if *num_threads.lock().unwrap() == 0 { - Keyword::set("decoration:dim_strength", 0)?; + if *is_set_dim.lock().unwrap() { + log("info: Last thread, but not removing dim since permanent dim is active"); + } else { + Keyword::set("decoration:dim_strength", 0)?; - log("info: Removed dim (last thread)"); + log("info: Removed dim (last thread)"); + } } Ok(()) diff --git a/src/main.rs b/src/main.rs index fae1176..906c783 100644 --- a/src/main.rs +++ b/src/main.rs @@ -61,6 +61,7 @@ fn main() -> hyprland::Result<()> { let num_threads: Arc> = Arc::new(Mutex::new(0)); let last_address: Arc>> = Arc::new(Mutex::new(None)); let last_class: Arc>> = Arc::new(Mutex::new(None)); + let is_set_dim: Arc> = Arc::new(Mutex::new(false)); let in_special_workspace: Arc> = Arc::new(Mutex::new(is_special())); // Initialize with dim so the user sees something, but only if the user wants dim @@ -71,7 +72,7 @@ fn main() -> hyprland::Result<()> { Keyword::set("decoration:dim_strength", 0)?; Keyword::set("decoration:dim_inactive", "yes")?; } else { - spawn_dim_thread(num_threads.clone(), strength, persist, duration, true); + spawn_dim_thread(num_threads.clone(), is_set_dim.clone(), strength, persist, duration, true); } // On active window changes @@ -79,8 +80,9 @@ fn main() -> hyprland::Result<()> { // Ignore the event if no window_address was given let Some(WindowEventData { window_address, window_class, .. }) = data else { return }; - // Clone inside since u16 does not implement copy + // Clone inside since primitives don't implement copy let num_threads = num_threads.clone(); + let is_set_dim = is_set_dim.clone(); // If the last address is the same as the new window, don't dim if let Some(ref old_address) = *last_address.lock().unwrap() { From c25da60f118d20af4442cbb4c138652d5c24f9a8 Mon Sep 17 00:00:00 2001 From: Donovan Glover Date: Sat, 12 Aug 2023 18:30:06 -0400 Subject: [PATCH 04/15] feat: Dim dialogs before checking no_dim_when_only This fixes an issue where dialogs wouldn't be dimmed in workspaces that only have one window (or a fullscreen window). --- src/main.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/main.rs b/src/main.rs index 906c783..705bd07 100644 --- a/src/main.rs +++ b/src/main.rs @@ -132,6 +132,12 @@ fn main() -> hyprland::Result<()> { } } + if same_class && is_floating() { + *is_set_dim.lock().unwrap() = true; + set_dim(strength, persist).unwrap(); + return; + } + // Don't dim when switching to another workspace with only one window if no_dim_when_only { if (parent_workspace.windows == 1 || parent_workspace.fullscreen) @@ -147,11 +153,8 @@ fn main() -> hyprland::Result<()> { } } - if same_class && is_floating() { - set_dim(strength, persist).unwrap(); - } else { - spawn_dim_thread(num_threads, strength, persist, duration, false); - } + *is_set_dim.lock().unwrap() = false; + spawn_dim_thread(num_threads, is_set_dim, strength, persist, duration, false); }); thread::spawn(move || -> hyprland::Result<()> { From 75d661733c482648856b23de5c2158aafc8cfcae Mon Sep 17 00:00:00 2001 From: Donovan Glover Date: Sat, 12 Aug 2023 23:13:52 -0400 Subject: [PATCH 05/15] feat: Add --dim-floating-when-same-class --- src/cli.rs | 11 +++++++++++ src/main.rs | 11 +++++++---- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/cli.rs b/src/cli.rs index 804897b..5900b14 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -91,6 +91,17 @@ pub struct Cli { #[arg(short = 'I', long, default_value_t = false)] pub ignore_leaving_special: bool, + /// Dim windows if they're the same class and floating + /// + /// This option is particularly useful for dimming dialog boxes started by applications + /// since those tend to have the same class and be floating. + /// + /// The dim is a permanent dim while working in the floating window of the same class. + /// + /// Note that the dim is removed when switching workspaces or doing any other event. + #[arg(short = 'D', long, default_value_t = false)] + pub dim_floating_when_same_class: bool, + /// Show information about what hyprdim is doing #[arg(short, long, default_value_t = false)] pub verbose: bool, diff --git a/src/main.rs b/src/main.rs index 705bd07..139c0e5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -49,6 +49,7 @@ fn main() -> hyprland::Result<()> { no_dim_when_only, ignore_entering_special, ignore_leaving_special, + dim_floating_when_same_class, .. } = Cli::parse(); @@ -132,10 +133,12 @@ fn main() -> hyprland::Result<()> { } } - if same_class && is_floating() { - *is_set_dim.lock().unwrap() = true; - set_dim(strength, persist).unwrap(); - return; + if dim_floating_when_same_class { + if same_class && is_floating() { + *is_set_dim.lock().unwrap() = true; + set_dim(strength, persist).unwrap(); + return; + } } // Don't dim when switching to another workspace with only one window From 656875906d31919454e82964b0d07d5e2b130238 Mon Sep 17 00:00:00 2001 From: Donovan Glover Date: Sat, 12 Aug 2023 23:40:30 -0400 Subject: [PATCH 06/15] feat: Add --strength-floating-when-same-class This makes it possible to increase the dim for dialog boxes. --- src/cli.rs | 8 ++++++++ src/main.rs | 3 ++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/cli.rs b/src/cli.rs index 5900b14..0cdf8f8 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -102,6 +102,14 @@ pub struct Cli { #[arg(short = 'D', long, default_value_t = false)] pub dim_floating_when_same_class: bool, + /// How much to dim same-class floating windows + /// + /// A value from 0 (no dim) to 1 (maximum dim) + /// + /// Note that negative numbers such as -1 and -5 are also supported for "light dim". + #[arg(short = 'S', long, value_name = "STRENGTH", default_value_t = 0.7)] + pub strength_floating_when_same_class: f64, + /// Show information about what hyprdim is doing #[arg(short, long, default_value_t = false)] pub verbose: bool, diff --git a/src/main.rs b/src/main.rs index 139c0e5..3fb767f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -50,6 +50,7 @@ fn main() -> hyprland::Result<()> { ignore_entering_special, ignore_leaving_special, dim_floating_when_same_class, + strength_floating_when_same_class, .. } = Cli::parse(); @@ -136,7 +137,7 @@ fn main() -> hyprland::Result<()> { if dim_floating_when_same_class { if same_class && is_floating() { *is_set_dim.lock().unwrap() = true; - set_dim(strength, persist).unwrap(); + set_dim(strength_floating_when_same_class, persist).unwrap(); return; } } From 37f21d86a6350ce58f5e522a3289cee2ea7da6ff Mon Sep 17 00:00:00 2001 From: Donovan Glover Date: Sun, 13 Aug 2023 00:11:00 -0400 Subject: [PATCH 07/15] feat: Shorten arguments to --dialog-dim/strength This makes things easier to remember even though the code isn't exclusive to dialogs. --- src/cli.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cli.rs b/src/cli.rs index 0cdf8f8..25b65f7 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -99,7 +99,7 @@ pub struct Cli { /// The dim is a permanent dim while working in the floating window of the same class. /// /// Note that the dim is removed when switching workspaces or doing any other event. - #[arg(short = 'D', long, default_value_t = false)] + #[arg(short = 'D', long = "dialog-dim", default_value_t = false)] pub dim_floating_when_same_class: bool, /// How much to dim same-class floating windows @@ -107,7 +107,7 @@ pub struct Cli { /// A value from 0 (no dim) to 1 (maximum dim) /// /// Note that negative numbers such as -1 and -5 are also supported for "light dim". - #[arg(short = 'S', long, value_name = "STRENGTH", default_value_t = 0.7)] + #[arg(short = 'S', long = "dialog-strength", value_name = "STRENGTH", default_value_t = 0.7)] pub strength_floating_when_same_class: f64, /// Show information about what hyprdim is doing From 13264b781855224162dbb23dea7476eb2f9392bf Mon Sep 17 00:00:00 2001 From: Donovan Glover Date: Sun, 13 Aug 2023 00:30:04 -0400 Subject: [PATCH 08/15] chore: Update shell completions --- completions/_hyprdim | 4 ++++ completions/hyprdim.bash | 10 +++++++++- completions/hyprdim.fish | 2 ++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/completions/_hyprdim b/completions/_hyprdim index e3b0555..bf70f0a 100644 --- a/completions/_hyprdim +++ b/completions/_hyprdim @@ -23,6 +23,8 @@ _hyprdim() { '--fade=[Fade animation speed from 0 (instantaneous) to 255 (very slow)]:FADE: ' \ '-b+[Bezier curve used for the animation]:BEZIER: ' \ '--bezier=[Bezier curve used for the animation]:BEZIER: ' \ +'-S+[How much to dim same-class floating windows]:STRENGTH: ' \ +'--dialog-strength=[How much to dim same-class floating windows]:STRENGTH: ' \ '-p[Prevent dim_inactive from being disabled by \`hyprctl reload\` etc]' \ '--persist[Prevent dim_inactive from being disabled by \`hyprctl reload\` etc]' \ '-n[Don'\''t dim when switching to a workspace that only has one visible window]' \ @@ -31,6 +33,8 @@ _hyprdim() { '--ignore-entering-special[Don'\''t dim when opening a special workspace]' \ '-I[Don'\''t dim when closing a special workspace]' \ '--ignore-leaving-special[Don'\''t dim when closing a special workspace]' \ +'-D[Dim windows if they'\''re the same class and floating]' \ +'--dialog-dim[Dim windows if they'\''re the same class and floating]' \ '-v[Show information about what hyprdim is doing]' \ '--verbose[Show information about what hyprdim is doing]' \ '-h[Print help (see more with '\''--help'\'')]' \ diff --git a/completions/hyprdim.bash b/completions/hyprdim.bash index c6912b1..9614a94 100644 --- a/completions/hyprdim.bash +++ b/completions/hyprdim.bash @@ -19,7 +19,7 @@ _hyprdim() { case "${cmd}" in hyprdim) - opts="-s -d -f -b -p -n -i -I -v -h -V --strength --duration --fade --bezier --persist --no-dim-when-only --ignore-entering-special --ignore-leaving-special --verbose --help --version" + opts="-s -d -f -b -p -n -i -I -D -S -v -h -V --strength --duration --fade --bezier --persist --no-dim-when-only --ignore-entering-special --ignore-leaving-special --dialog-dim --dialog-strength --verbose --help --version" if [[ ${cur} == -* || ${COMP_CWORD} -eq 1 ]] ; then COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) return 0 @@ -57,6 +57,14 @@ _hyprdim() { COMPREPLY=($(compgen -f "${cur}")) return 0 ;; + --dialog-strength) + COMPREPLY=($(compgen -f "${cur}")) + return 0 + ;; + -S) + COMPREPLY=($(compgen -f "${cur}")) + return 0 + ;; *) COMPREPLY=() ;; diff --git a/completions/hyprdim.fish b/completions/hyprdim.fish index 2217ddb..0f20186 100644 --- a/completions/hyprdim.fish +++ b/completions/hyprdim.fish @@ -2,10 +2,12 @@ complete -c hyprdim -s s -l strength -d 'A value from 0 (no dim) to 1 (maximum d complete -c hyprdim -s d -l duration -d 'How many milliseconds to wait before removing dim' -r complete -c hyprdim -s f -l fade -d 'Fade animation speed from 0 (instantaneous) to 255 (very slow)' -r complete -c hyprdim -s b -l bezier -d 'Bezier curve used for the animation' -r +complete -c hyprdim -s S -l dialog-strength -d 'How much to dim same-class floating windows' -r complete -c hyprdim -s p -l persist -d 'Prevent dim_inactive from being disabled by `hyprctl reload` etc' complete -c hyprdim -s n -l no-dim-when-only -d 'Don\'t dim when switching to a workspace that only has one visible window' complete -c hyprdim -s i -l ignore-entering-special -d 'Don\'t dim when opening a special workspace' complete -c hyprdim -s I -l ignore-leaving-special -d 'Don\'t dim when closing a special workspace' +complete -c hyprdim -s D -l dialog-dim -d 'Dim windows if they\'re the same class and floating' complete -c hyprdim -s v -l verbose -d 'Show information about what hyprdim is doing' complete -c hyprdim -s h -l help -d 'Print help (see more with \'--help\')' complete -c hyprdim -s V -l version -d 'Print version' From 31e39e523916713e8a4e968b55be60be18da9050 Mon Sep 17 00:00:00 2001 From: Donovan Glover Date: Sun, 13 Aug 2023 00:30:11 -0400 Subject: [PATCH 09/15] chore: Update man pages --- man/hyprdim.1 | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/man/hyprdim.1 b/man/hyprdim.1 index 27a610f..3972421 100644 --- a/man/hyprdim.1 +++ b/man/hyprdim.1 @@ -4,7 +4,7 @@ .SH NAME hyprdim \- Automatically dim windows in Hyprland when switching between them. .SH SYNOPSIS -\fBhyprdim\fR [\fB\-s\fR|\fB\-\-strength\fR] [\fB\-d\fR|\fB\-\-duration\fR] [\fB\-f\fR|\fB\-\-fade\fR] [\fB\-b\fR|\fB\-\-bezier\fR] [\fB\-p\fR|\fB\-\-persist\fR] [\fB\-n\fR|\fB\-\-no\-dim\-when\-only\fR] [\fB\-i\fR|\fB\-\-ignore\-entering\-special\fR] [\fB\-I\fR|\fB\-\-ignore\-leaving\-special\fR] [\fB\-v\fR|\fB\-\-verbose\fR] [\fB\-h\fR|\fB\-\-help\fR] [\fB\-V\fR|\fB\-\-version\fR] +\fBhyprdim\fR [\fB\-s\fR|\fB\-\-strength\fR] [\fB\-d\fR|\fB\-\-duration\fR] [\fB\-f\fR|\fB\-\-fade\fR] [\fB\-b\fR|\fB\-\-bezier\fR] [\fB\-p\fR|\fB\-\-persist\fR] [\fB\-n\fR|\fB\-\-no\-dim\-when\-only\fR] [\fB\-i\fR|\fB\-\-ignore\-entering\-special\fR] [\fB\-I\fR|\fB\-\-ignore\-leaving\-special\fR] [\fB\-D\fR|\fB\-\-dialog\-dim\fR] [\fB\-S\fR|\fB\-\-dialog\-strength\fR] [\fB\-v\fR|\fB\-\-verbose\fR] [\fB\-h\fR|\fB\-\-help\fR] [\fB\-V\fR|\fB\-\-version\fR] .SH DESCRIPTION .PP hyprdim is a daemon that automatically dims windows in Hyprland[1] when @@ -74,6 +74,22 @@ Don\*(Aqt dim when closing a special workspace This is useful if you have multiple windows in your main workspace and usually don\*(Aqt switch between them. .TP +\fB\-D\fR, \fB\-\-dialog\-dim\fR +Dim windows if they\*(Aqre the same class and floating + +This option is particularly useful for dimming dialog boxes started by applications since those tend to have the same class and be floating. + +The dim is a permanent dim while working in the floating window of the same class. + +Note that the dim is removed when switching workspaces or doing any other event. +.TP +\fB\-S\fR, \fB\-\-dialog\-strength\fR=\fISTRENGTH\fR [default: 0.7] +How much to dim same\-class floating windows + +A value from 0 (no dim) to 1 (maximum dim) + +Note that negative numbers such as \-1 and \-5 are also supported for "light dim". +.TP \fB\-v\fR, \fB\-\-verbose\fR Show information about what hyprdim is doing .TP From 8342c2b71b4fb3b3ccc53b9fbfe3f4d3bc63075f Mon Sep 17 00:00:00 2001 From: Donovan Glover Date: Sun, 13 Aug 2023 00:35:52 -0400 Subject: [PATCH 10/15] chore: Update usage in README --- README.md | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 95e52c4..242117d 100644 --- a/README.md +++ b/README.md @@ -51,17 +51,19 @@ Make sure `$HOME/.cargo/bin` is in your `$PATH` if it isn't already. Usage: hyprdim [OPTIONS] Options: - -s, --strength A value from 0 (no dim) to 1 (maximum dim) [default: 0.4] - -d, --duration How many milliseconds to wait before removing dim [default: 800] - -f, --fade Fade animation speed from 0 (instantaneous) to 255 (very slow) [default: 7] - -b, --bezier Bezier curve used for the animation [default: default] - -p, --persist Prevent dim_inactive from being disabled by `hyprctl reload` etc - -n, --no-dim-when-only Don't dim when switching to a workspace that only has one visible window - -i, --ignore-entering-special Don't dim when opening a special workspace - -I, --ignore-leaving-special Don't dim when closing a special workspace - -v, --verbose Show information about what hyprdim is doing - -h, --help Print help (see more with '--help') - -V, --version Print version + -s, --strength A value from 0 (no dim) to 1 (maximum dim) [default: 0.4] + -d, --duration How many milliseconds to wait before removing dim [default: 800] + -f, --fade Fade animation speed from 0 (instantaneous) to 255 (very slow) [default: 7] + -b, --bezier Bezier curve used for the animation [default: default] + -p, --persist Prevent dim_inactive from being disabled by `hyprctl reload` etc + -n, --no-dim-when-only Don't dim when switching to a workspace that only has one visible window + -i, --ignore-entering-special Don't dim when opening a special workspace + -I, --ignore-leaving-special Don't dim when closing a special workspace + -D, --dialog-dim Dim windows if they're the same class and floating + -S, --dialog-strength How much to dim same-class floating windows [default: 0.7] + -v, --verbose Show information about what hyprdim is doing + -h, --help Print help (see more with '--help') + -V, --version Print version ``` ## Contributing From 2b0e501f499e6035bdb3ebbee1e1f9cd3bf135d9 Mon Sep 17 00:00:00 2001 From: Donovan Glover Date: Sun, 13 Aug 2023 01:59:52 -0400 Subject: [PATCH 11/15] feat: Merge --dialog-strength with --dialog-dim When setting dialog-dim, it is implied that the user may or may not want to set the dialog-strength as well. Furthermore, the usage of dim-strength by its own wasn't very useful. --- src/cli.rs | 12 +++--------- src/main.rs | 9 +++++---- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/src/cli.rs b/src/cli.rs index 25b65f7..17e32d2 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -99,16 +99,10 @@ pub struct Cli { /// The dim is a permanent dim while working in the floating window of the same class. /// /// Note that the dim is removed when switching workspaces or doing any other event. - #[arg(short = 'D', long = "dialog-dim", default_value_t = false)] - pub dim_floating_when_same_class: bool, - - /// How much to dim same-class floating windows - /// - /// A value from 0 (no dim) to 1 (maximum dim) /// - /// Note that negative numbers such as -1 and -5 are also supported for "light dim". - #[arg(short = 'S', long = "dialog-strength", value_name = "STRENGTH", default_value_t = 0.7)] - pub strength_floating_when_same_class: f64, + /// Optionally specify a strength value to change how much dim is applied to dialog windows. + #[arg(short = 'D', long, value_name = "STRENGTH", default_value = None, default_missing_value = "0.7", num_args = 0..=1)] + pub dialog_dim: Option, /// Show information about what hyprdim is doing #[arg(short, long, default_value_t = false)] diff --git a/src/main.rs b/src/main.rs index 3fb767f..bc7d679 100644 --- a/src/main.rs +++ b/src/main.rs @@ -49,8 +49,7 @@ fn main() -> hyprland::Result<()> { no_dim_when_only, ignore_entering_special, ignore_leaving_special, - dim_floating_when_same_class, - strength_floating_when_same_class, + dialog_dim, .. } = Cli::parse(); @@ -134,10 +133,12 @@ fn main() -> hyprland::Result<()> { } } - if dim_floating_when_same_class { + // Enable dim when using a floating windows with the same class as the last window, + // but only if the user specified the argument to do so. + if let Some(dialog_strength) = dialog_dim { if same_class && is_floating() { *is_set_dim.lock().unwrap() = true; - set_dim(strength_floating_when_same_class, persist).unwrap(); + set_dim(dialog_strength, persist).unwrap(); return; } } From 991c7307568541ef67a2af841109c754f153c5e0 Mon Sep 17 00:00:00 2001 From: Donovan Glover Date: Sun, 13 Aug 2023 13:08:13 -0400 Subject: [PATCH 12/15] feat: Show default dialog-dim strength in cli help --- src/cli.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/cli.rs b/src/cli.rs index 17e32d2..6cf4e86 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -91,7 +91,7 @@ pub struct Cli { #[arg(short = 'I', long, default_value_t = false)] pub ignore_leaving_special: bool, - /// Dim windows if they're the same class and floating + /// Dim windows if they're the same class and floating (strength_default: 0.7) /// /// This option is particularly useful for dimming dialog boxes started by applications /// since those tend to have the same class and be floating. @@ -101,6 +101,7 @@ pub struct Cli { /// Note that the dim is removed when switching workspaces or doing any other event. /// /// Optionally specify a strength value to change how much dim is applied to dialog windows. + /// The default strength value is 0.7. #[arg(short = 'D', long, value_name = "STRENGTH", default_value = None, default_missing_value = "0.7", num_args = 0..=1)] pub dialog_dim: Option, From 0b8cb93947e0ed59553aa525cc39b003a018ad90 Mon Sep 17 00:00:00 2001 From: Donovan Glover Date: Sun, 13 Aug 2023 13:10:28 -0400 Subject: [PATCH 13/15] chore: Update shell completions --- completions/_hyprdim | 6 ++---- completions/hyprdim.bash | 6 +++--- completions/hyprdim.fish | 3 +-- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/completions/_hyprdim b/completions/_hyprdim index bf70f0a..b2cbbe2 100644 --- a/completions/_hyprdim +++ b/completions/_hyprdim @@ -23,8 +23,8 @@ _hyprdim() { '--fade=[Fade animation speed from 0 (instantaneous) to 255 (very slow)]:FADE: ' \ '-b+[Bezier curve used for the animation]:BEZIER: ' \ '--bezier=[Bezier curve used for the animation]:BEZIER: ' \ -'-S+[How much to dim same-class floating windows]:STRENGTH: ' \ -'--dialog-strength=[How much to dim same-class floating windows]:STRENGTH: ' \ +'-D+[Dim windows if they'\''re the same class and floating (strength_default\: 0.7)]' \ +'--dialog-dim=[Dim windows if they'\''re the same class and floating (strength_default\: 0.7)]' \ '-p[Prevent dim_inactive from being disabled by \`hyprctl reload\` etc]' \ '--persist[Prevent dim_inactive from being disabled by \`hyprctl reload\` etc]' \ '-n[Don'\''t dim when switching to a workspace that only has one visible window]' \ @@ -33,8 +33,6 @@ _hyprdim() { '--ignore-entering-special[Don'\''t dim when opening a special workspace]' \ '-I[Don'\''t dim when closing a special workspace]' \ '--ignore-leaving-special[Don'\''t dim when closing a special workspace]' \ -'-D[Dim windows if they'\''re the same class and floating]' \ -'--dialog-dim[Dim windows if they'\''re the same class and floating]' \ '-v[Show information about what hyprdim is doing]' \ '--verbose[Show information about what hyprdim is doing]' \ '-h[Print help (see more with '\''--help'\'')]' \ diff --git a/completions/hyprdim.bash b/completions/hyprdim.bash index 9614a94..9b31880 100644 --- a/completions/hyprdim.bash +++ b/completions/hyprdim.bash @@ -19,7 +19,7 @@ _hyprdim() { case "${cmd}" in hyprdim) - opts="-s -d -f -b -p -n -i -I -D -S -v -h -V --strength --duration --fade --bezier --persist --no-dim-when-only --ignore-entering-special --ignore-leaving-special --dialog-dim --dialog-strength --verbose --help --version" + opts="-s -d -f -b -p -n -i -I -D -v -h -V --strength --duration --fade --bezier --persist --no-dim-when-only --ignore-entering-special --ignore-leaving-special --dialog-dim --verbose --help --version" if [[ ${cur} == -* || ${COMP_CWORD} -eq 1 ]] ; then COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) return 0 @@ -57,11 +57,11 @@ _hyprdim() { COMPREPLY=($(compgen -f "${cur}")) return 0 ;; - --dialog-strength) + --dialog-dim) COMPREPLY=($(compgen -f "${cur}")) return 0 ;; - -S) + -D) COMPREPLY=($(compgen -f "${cur}")) return 0 ;; diff --git a/completions/hyprdim.fish b/completions/hyprdim.fish index 0f20186..6d2406f 100644 --- a/completions/hyprdim.fish +++ b/completions/hyprdim.fish @@ -2,12 +2,11 @@ complete -c hyprdim -s s -l strength -d 'A value from 0 (no dim) to 1 (maximum d complete -c hyprdim -s d -l duration -d 'How many milliseconds to wait before removing dim' -r complete -c hyprdim -s f -l fade -d 'Fade animation speed from 0 (instantaneous) to 255 (very slow)' -r complete -c hyprdim -s b -l bezier -d 'Bezier curve used for the animation' -r -complete -c hyprdim -s S -l dialog-strength -d 'How much to dim same-class floating windows' -r +complete -c hyprdim -s D -l dialog-dim -d 'Dim windows if they\'re the same class and floating (strength_default: 0.7)' -r complete -c hyprdim -s p -l persist -d 'Prevent dim_inactive from being disabled by `hyprctl reload` etc' complete -c hyprdim -s n -l no-dim-when-only -d 'Don\'t dim when switching to a workspace that only has one visible window' complete -c hyprdim -s i -l ignore-entering-special -d 'Don\'t dim when opening a special workspace' complete -c hyprdim -s I -l ignore-leaving-special -d 'Don\'t dim when closing a special workspace' -complete -c hyprdim -s D -l dialog-dim -d 'Dim windows if they\'re the same class and floating' complete -c hyprdim -s v -l verbose -d 'Show information about what hyprdim is doing' complete -c hyprdim -s h -l help -d 'Print help (see more with \'--help\')' complete -c hyprdim -s V -l version -d 'Print version' From 18bfc5fdf34858bb5453d3c238bec8a2ea4b9c79 Mon Sep 17 00:00:00 2001 From: Donovan Glover Date: Sun, 13 Aug 2023 13:10:33 -0400 Subject: [PATCH 14/15] chore: Update man pages --- man/hyprdim.1 | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/man/hyprdim.1 b/man/hyprdim.1 index 3972421..fad998e 100644 --- a/man/hyprdim.1 +++ b/man/hyprdim.1 @@ -4,7 +4,7 @@ .SH NAME hyprdim \- Automatically dim windows in Hyprland when switching between them. .SH SYNOPSIS -\fBhyprdim\fR [\fB\-s\fR|\fB\-\-strength\fR] [\fB\-d\fR|\fB\-\-duration\fR] [\fB\-f\fR|\fB\-\-fade\fR] [\fB\-b\fR|\fB\-\-bezier\fR] [\fB\-p\fR|\fB\-\-persist\fR] [\fB\-n\fR|\fB\-\-no\-dim\-when\-only\fR] [\fB\-i\fR|\fB\-\-ignore\-entering\-special\fR] [\fB\-I\fR|\fB\-\-ignore\-leaving\-special\fR] [\fB\-D\fR|\fB\-\-dialog\-dim\fR] [\fB\-S\fR|\fB\-\-dialog\-strength\fR] [\fB\-v\fR|\fB\-\-verbose\fR] [\fB\-h\fR|\fB\-\-help\fR] [\fB\-V\fR|\fB\-\-version\fR] +\fBhyprdim\fR [\fB\-s\fR|\fB\-\-strength\fR] [\fB\-d\fR|\fB\-\-duration\fR] [\fB\-f\fR|\fB\-\-fade\fR] [\fB\-b\fR|\fB\-\-bezier\fR] [\fB\-p\fR|\fB\-\-persist\fR] [\fB\-n\fR|\fB\-\-no\-dim\-when\-only\fR] [\fB\-i\fR|\fB\-\-ignore\-entering\-special\fR] [\fB\-I\fR|\fB\-\-ignore\-leaving\-special\fR] [\fB\-D\fR|\fB\-\-dialog\-dim\fR] [\fB\-v\fR|\fB\-\-verbose\fR] [\fB\-h\fR|\fB\-\-help\fR] [\fB\-V\fR|\fB\-\-version\fR] .SH DESCRIPTION .PP hyprdim is a daemon that automatically dims windows in Hyprland[1] when @@ -74,21 +74,16 @@ Don\*(Aqt dim when closing a special workspace This is useful if you have multiple windows in your main workspace and usually don\*(Aqt switch between them. .TP -\fB\-D\fR, \fB\-\-dialog\-dim\fR -Dim windows if they\*(Aqre the same class and floating +\fB\-D\fR, \fB\-\-dialog\-dim\fR=\fISTRENGTH\fR +Dim windows if they\*(Aqre the same class and floating (strength_default: 0.7) This option is particularly useful for dimming dialog boxes started by applications since those tend to have the same class and be floating. The dim is a permanent dim while working in the floating window of the same class. Note that the dim is removed when switching workspaces or doing any other event. -.TP -\fB\-S\fR, \fB\-\-dialog\-strength\fR=\fISTRENGTH\fR [default: 0.7] -How much to dim same\-class floating windows - -A value from 0 (no dim) to 1 (maximum dim) -Note that negative numbers such as \-1 and \-5 are also supported for "light dim". +Optionally specify a strength value to change how much dim is applied to dialog windows. The default strength value is 0.7. .TP \fB\-v\fR, \fB\-\-verbose\fR Show information about what hyprdim is doing From 262fb9fec7563c1e8bd7dfbedf3d25e8b693724d Mon Sep 17 00:00:00 2001 From: Donovan Glover Date: Sun, 13 Aug 2023 13:11:46 -0400 Subject: [PATCH 15/15] chore: Update usage in README --- README.md | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 242117d..1e83675 100644 --- a/README.md +++ b/README.md @@ -51,19 +51,18 @@ Make sure `$HOME/.cargo/bin` is in your `$PATH` if it isn't already. Usage: hyprdim [OPTIONS] Options: - -s, --strength A value from 0 (no dim) to 1 (maximum dim) [default: 0.4] - -d, --duration How many milliseconds to wait before removing dim [default: 800] - -f, --fade Fade animation speed from 0 (instantaneous) to 255 (very slow) [default: 7] - -b, --bezier Bezier curve used for the animation [default: default] - -p, --persist Prevent dim_inactive from being disabled by `hyprctl reload` etc - -n, --no-dim-when-only Don't dim when switching to a workspace that only has one visible window - -i, --ignore-entering-special Don't dim when opening a special workspace - -I, --ignore-leaving-special Don't dim when closing a special workspace - -D, --dialog-dim Dim windows if they're the same class and floating - -S, --dialog-strength How much to dim same-class floating windows [default: 0.7] - -v, --verbose Show information about what hyprdim is doing - -h, --help Print help (see more with '--help') - -V, --version Print version + -s, --strength A value from 0 (no dim) to 1 (maximum dim) [default: 0.4] + -d, --duration How many milliseconds to wait before removing dim [default: 800] + -f, --fade Fade animation speed from 0 (instantaneous) to 255 (very slow) [default: 7] + -b, --bezier Bezier curve used for the animation [default: default] + -p, --persist Prevent dim_inactive from being disabled by `hyprctl reload` etc + -n, --no-dim-when-only Don't dim when switching to a workspace that only has one visible window + -i, --ignore-entering-special Don't dim when opening a special workspace + -I, --ignore-leaving-special Don't dim when closing a special workspace + -D, --dialog-dim [] Dim windows if they're the same class and floating (strength_default: 0.7) + -v, --verbose Show information about what hyprdim is doing + -h, --help Print help (see more with '--help') + -V, --version Print version ``` ## Contributing