add niri-auto-centre script

This commit is contained in:
William 2026-02-16 11:59:32 -03:00
parent bea4771272
commit 19ecca4ea8
3 changed files with 33 additions and 2 deletions

View file

@ -123,6 +123,7 @@
}
spawn-at-startup "noctalia-shell" "-d"
spawn-at-startup "${lib.getExe pkgs.niri-auto-centre}"
layer-rule {
match namespace="^noctalia-overview*"
place-within-backdrop true

View file

@ -5,8 +5,6 @@
{ pkgs, ... }:
{
packages.hm-cli = pkgs.writeShellScriptBin "hm" ''
set -e
HM="${pkgs.lib.getExe pkgs.home-manager}"
FLAKE_PATH="''${HM_PATH:-$HOME/.config/home-manager}"
FLAKE_OUTPUT="''${HM_USER:-$(whoami)@$(hostname)}"

View file

@ -0,0 +1,32 @@
{ ... }:
{
perSystem =
{ pkgs, ... }:
{
packages.niri-auto-centre = pkgs.writeShellApplication {
name = "niri-auto-centre";
runtimeInputs = [ pkgs.jq ];
text = ''
while true; do
ACTIVE_WORKSPACE=$(niri msg --json workspaces | jq -r '.[] | select(.is_active == true)')
WORKSPACE_ID=$(echo "$ACTIVE_WORKSPACE" | jq -r '.id')
OUTPUT_NAME=$(echo "$ACTIVE_WORKSPACE" | jq -r '.output')
MONITOR_WIDTH=$(niri msg --json outputs | jq -r ".\"$OUTPUT_NAME\".logical.width")
SUMMED_TILE_WIDTH=$(niri msg --json windows | jq --argjson wid "$WORKSPACE_ID" -r '
[.[] | select(.workspace_id == $wid) | {col: .layout.pos_in_scrolling_layout[0], width: .layout.tile_size[0]}]
| group_by(.col) | map(first.width) | add
')
if awk "BEGIN {exit !($SUMMED_TILE_WIDTH < $MONITOR_WIDTH)}"; then
niri msg action center-visible-columns
fi
sleep 0.1
done
'';
};
};
}