From 0c8c81ea97aabcb388021cdc1707ef4e4fa377bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Fri, 31 Jul 2026 01:09:31 +0300 Subject: [PATCH] feat(niri): log in on a plain workspace, not "code" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The eight declared `workspace "name"` nodes are all created on the first output niri connects (HDMI-A-1, 14ms before DP-1), and niri makes the first declared one active there — so the second monitor logged in showing "code". workspace_startup.sh focuses the first plain workspace on every output, then hands focus back to the focus-at-startup output. `empty-workspace-above-first` puts that plain workspace at index 1 so it sits above the named block and waybar labels it 1 rather than 9. Both are needed. The option alone was tested by relogin and still comes up on "code" — it creates the workspace but never focuses it. It also shifts every Mod+ by one, which is accepted. --- .config/niri/config.kdl | 18 ++++++++++++++ .config/scripts/niri/workspace_startup.sh | 29 +++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100755 .config/scripts/niri/workspace_startup.sh diff --git a/.config/niri/config.kdl b/.config/niri/config.kdl index da3073e..8b080da 100644 --- a/.config/niri/config.kdl +++ b/.config/niri/config.kdl @@ -80,6 +80,18 @@ layout { center-focused-column "never" + // Puts a plain workspace at index 1 on every output, above the declared + // named block — so the workspace waybar labels on HDMI-A-1 is 1, not 9. + // + // This is NOT a replacement for workspace_startup.sh, which was tested: + // alone it still logs in with the first NAMED workspace active, because it + // only creates the workspace, it never focuses it. The two go together — + // this one supplies index 1, the script focuses it. + // + // Cost, accepted knowingly: every Mod+ shifts by one, since + // workspace_nav.sh indexes plain workspaces and this adds one at the top. + empty-workspace-above-first + // New windows take the whole working area — the closest thing to dwindle // handing a new window all the free space. 1.0 is in the preset cycle too, // otherwise one Mod+R drops a window to 1/3 with no way back to full. @@ -138,6 +150,12 @@ spawn-at-startup "sh" "-c" "sleep 3 && wl-paste --type text --watch cliphist sto spawn-at-startup "sh" "-c" "sleep 3 && wl-paste --type image --watch cliphist store" spawn-at-startup "sh" "-c" "sleep 4 && rfkill unblock bluetooth && bluetoothctl power on" +// The declared app workspaces below all get created on the first output niri +// connects (HDMI-A-1), so that monitor logs in showing "code". This puts every +// output back on a plain workspace. Early on purpose: it must finish before the +// sleep-3/sleep-4 apps map their windows, or one lands on the wrong monitor. +spawn-at-startup "sh" "-c" "sleep 1 && bash ~/.config/scripts/niri/workspace_startup.sh" + screenshot-path "~/Pictures/Screenshots/Screenshot from %Y-%m-%d %H-%M-%S.png" // Animations stay at niri's defaults (on), unlike Hyprland where they were off. diff --git a/.config/scripts/niri/workspace_startup.sh b/.config/scripts/niri/workspace_startup.sh new file mode 100755 index 0000000..d707b88 --- /dev/null +++ b/.config/scripts/niri/workspace_startup.sh @@ -0,0 +1,29 @@ +#!/usr/bin/env bash +# Put every output on a plain (unnamed) workspace at login. +# +# The app workspaces are declared in config.kdl, so niri creates them all on one +# output at startup and that output comes up showing "code" — the first declared +# one — instead of an empty workspace. Nothing else moves them until their +# Alt+ bind runs, so the fix is a one-shot nudge: focus the first plain +# workspace on each output, then hand focus back to the output that had it +# (the one with `focus-at-startup`). +# +# focus-workspace takes an index into the FOCUSED output's list, hence the +# focus-monitor before each one — same reason workspace_nav.sh scopes by output. +set -euo pipefail + +ws=$(niri msg -j workspaces) +home=$(jq -r '.[] | select(.is_focused == true) | .output' <<<"$ws") + +while read -r out; do + idx=$(jq -r --arg o "$out" ' + [ .[] | select(.output == $o and .name == null) ] | sort_by(.idx) | .[0].idx // empty + ' <<<"$ws") + [ -n "$idx" ] || continue + niri msg action focus-monitor "$out" >/dev/null + niri msg action focus-workspace "$idx" >/dev/null +done < <(jq -r '[ .[].output ] | unique | .[]' <<<"$ws") + +if [ -n "$home" ]; then + niri msg action focus-monitor "$home" >/dev/null +fi