Skip to content

Commit

Permalink
hyprland: update monocle/smartgaps
Browse files Browse the repository at this point in the history
no_gaps_when_only has been removed removed
  • Loading branch information
fufexan committed Nov 4, 2024
1 parent 055a3b3 commit dea1d6b
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 6 deletions.
7 changes: 1 addition & 6 deletions home/programs/wayland/hyprland/binds.nix
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ in {
];

# binds
bind = let
monocle = "dwindle:no_gaps_when_only";
in
bind =
[
# compositor commands
"$mod SHIFT, E, exec, pkill Hyprland"
Expand All @@ -45,9 +43,6 @@ in {
"$mod, P, pseudo,"
"$mod ALT, ,resizeactive,"

# toggle "monocle" (no_gaps_when_only)
"$mod, M, exec, hyprctl keyword ${monocle} $(($(hyprctl getoption ${monocle} -j | jaq -r '.int') ^ 1))"

# utility
# terminal
"$mod, Return, exec, run-as-service foot"
Expand Down
1 change: 1 addition & 0 deletions home/programs/wayland/hyprland/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ in {
./binds.nix
./rules.nix
./settings.nix
./smartgaps.nix
];

home.packages = [
Expand Down
55 changes: 55 additions & 0 deletions home/programs/wayland/hyprland/smartgaps.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{
config,
pkgs,
lib,
...
}: let
inherit (config.wayland.windowManager.hyprland.settings.general) gaps_in gaps_out border_size;
inherit (config.wayland.windowManager.hyprland.settings.decoration) rounding;
inherit (builtins) concatStringsSep;

toggleSmartGaps = let
workspaceSelectors = ["w[t1]" "w[tg1]" "f[1]"];
forEach = f: concatStringsSep "\n" (map f workspaceSelectors);
in
pkgs.writeShellScript "toggleSmartGaps" ''
hyprctl -j workspacerules | ${lib.getExe pkgs.jaq} -e 'any(.[]; select(.workspaceString == "w[t1]" or .workspaceString == "w[tg1]" or .workspaceString == "w[f1]") | (.gapsIn | all(. == 0)) and (.gapsOut | all(. == 0)))' > /dev/null
if [ $? -eq 0 ]; then
${forEach (selector: ''
hyprctl keyword workspace "${selector}, gapsout:${toString gaps_out}, gapsin:${toString gaps_in}"
hyprctl keyword windowrulev2 "bordersize ${toString border_size}, floating:0, onworkspace:${selector}"
hyprctl keyword windowrulev2 "rounding ${toString rounding}, floating:0, onworkspace:${selector}"
'')}
else
${forEach (selector: ''
hyprctl keyword workspace "${selector}, gapsout:0, gapsin:0"
hyprctl keyword windowrulev2 "bordersize 0, floating:0, onworkspace:${selector}"
hyprctl keyword windowrulev2 "rounding 0, floating:0, onworkspace:${selector}"
'')}
fi
'';
in {
# Ref https://wiki.hyprland.org/Configuring/Workspace-Rules/
# "Smart gaps" / "No gaps when only"
wayland.windowManager.hyprland.settings = {
workspace = [
"w[t1], gapsout:0, gapsin:0"
"w[tg1], gapsout:0, gapsin:0"
"f[1], gapsout:0, gapsin:0"
];

windowrulev2 = [
"bordersize 0, floating:0, onworkspace:w[t1]"
"rounding 0, floating:0, onworkspace:w[t1]"
"bordersize 0, floating:0, onworkspace:w[tg1]"
"rounding 0, floating:0, onworkspace:w[tg1]"
"bordersize 0, floating:0, onworkspace:f[1]"
"rounding 0, floating:0, onworkspace:f[1]"
];

bind = [
"$mod, M, exec, ${toggleSmartGaps}"
];
};
}

0 comments on commit dea1d6b

Please sign in to comment.