niri: app maps and edit-clipboard shortcuts

This commit is contained in:
js0ny 2025-11-25 17:35:23 +00:00
parent bd2a7fcc26
commit 40e3834b7f
5 changed files with 149 additions and 12 deletions

View file

@ -1,4 +1,9 @@
{config, ...}: let
{
config,
pkgs,
lib,
...
}: let
term = config.currentUser.defaultTerminal;
termRunner = config.currentUser.defaultTerminalRunner;
iconTheme = config.currentUser.iconTheme;
@ -7,8 +12,29 @@
launcher = "rofi";
kbdBacklightDev = config.currentHost.keyboardBacklightDevice;
kbdBacklightStep = config.currentHost.keyboardBacklightStep;
nirictl = import ./scripts.nix {inherit pkgs;};
in {
home.packages = [
nirictl.focusOrLaunch
];
programs.niri.settings.binds = with config.lib.niri.actions; {
# === Application Runner ===
"Mod+B".hotkey-overlay.title = "Focus or launch web browser";
"Mod+B".action = spawn "${lib.getExe nirictl.focusOrLaunch}" "firefox" "firefox";
"Mod+Shift+B".hotkey-overlay.title = "Launch web browser in private mode";
"Mod+Shift+B".action = spawn "firefox" "--private-window";
"Mod+Shift+A".hotkey-overlay.title = "Focus or launch CherryStudio (AI assistant)";
"Mod+Shift+A".action = spawn "${lib.getExe nirictl.focusOrLaunch}" "CherryStudio" "cherry-studio";
"Mod+O".hotkey-overlay.title = "Focus or launch Obsidian";
"Mod+O".action = spawn "${lib.getExe nirictl.focusOrLaunch}" "obsidian" "obsidian";
# TODO: Change "org.kde.dolphin" to a more generic explorer app id via config.currentUser
"Mod+E".hotkey-overlay.title = "Focus or launch file explorer";
"Mod+E".action = spawn "${lib.getExe nirictl.focusOrLaunch}" "org.kde.dolphin" "dolphin";
"Mod+Semicolon".action = spawn "neovide" "${config.home.homeDirectory}/Atelier";
"Mod+Apostrophe".action =
spawn-sh "EDITOR_MINIMAL=1 ${termRunner} -o close_on_child_death=yes --class=edit-clipboard-popup -e edit-clipboard --minimal";
"Mod+Shift+Slash".action = show-hotkey-overlay;
"Mod+Return".hotkey-overlay.title = "Open a Terminal: ${term}";
@ -22,17 +48,12 @@ in {
"Alt+Space".action =
spawn "${launcher}" "-show" "drun" "-icon-theme" "${iconTheme}" "-show-icons";
"Mod+Shift+W".hotkey-overlay.title = "Search open Window: rofi";
"Mod+Shift+W".action =
"Mod+W".hotkey-overlay.title = "Search open Window: rofi";
"Mod+W".action =
spawn "${launcher}" "-show" "window" "-icon-theme" "${iconTheme}" "-show-icons";
"Mod+V".action = spawn-sh "cliphist list | ${launcher} -dmenu | cliphist decode | wl-copy";
"Mod+E".hotkey-overlay.title = "Run file explorer";
"Mod+E".action = spawn "${explorer}";
"Mod+Shift+E".hotkey-overlay.title = "Run terminal explorer";
"Mod+Shift+E".action = spawn "${termRunner}" "-e" "${explorerTerm}";
"XF86AudioRaiseVolume".allow-when-locked = true;
"XF86AudioRaiseVolume".action =
spawn "wpctl" "set-volume" "@DEFAULT_AUDIO_SINK@" "0.1+";
@ -174,8 +195,6 @@ in {
"Mod+BracketLeft".action = consume-or-expel-window-left;
"Mod+BracketRight".action = consume-or-expel-window-right;
"Mod+Comma".action = consume-window-into-column;
"Mod+Period".action = expel-window-from-column;
"Mod+R".action = switch-preset-column-width;
"Mod+Shift+R".action = switch-preset-window-height;
@ -191,7 +210,8 @@ in {
"Mod+Shift+Equal".action = set-window-height "+10%";
"Mod+F".action = toggle-window-floating;
"Mod+Shift+F".action = switch-focus-between-floating-and-tiling;
"Mod+W".action = toggle-column-tabbed-display;
"Mod+G".hotkey-overlay.title = "Toggle Grouped Display";
"Mod+G".action = toggle-column-tabbed-display;
"Mod+Shift+S".action.screenshot = {show-pointer = true;};
"Print".action.screenshot = {show-pointer = true;};

View file

@ -0,0 +1,29 @@
# Stolen from basecamp/omarchy
{pkgs, ...}: {
focusOrLaunch = pkgs.writeShellApplication {
name = "nirictl-focus-or-launch";
runtimeInputs = [pkgs.jq pkgs.niri];
text = ''
if (($# == 0)); then
echo "Usage: $0 <app_id> <command-to-launch>" >&2
exit 1
fi
APP_ID="$1"
CMD="''${2:-$1}"
WINDOWS=$(niri msg --json windows)
TARGET_ID=$(echo "$WINDOWS" | jq -r ".[] | select(.app_id == \"$APP_ID\") | .id" | head -n 1)
if [ -n "$TARGET_ID" ]; then
niri msg action focus-window --id "$TARGET_ID"
else
eval "$CMD" &
fi
'';
};
}

View file

@ -2,6 +2,16 @@
{...}: {
programs.niri = {
settings.window-rules = [
{
matches = [
{
app-id = "^edit-clipboard-popup$";
}
];
open-floating = true;
opacity = 0.8;
}
# {{{ float, opacity 0.8, top right: Picture-in-Picture // waybar childs
{
matches = [

View file

@ -5,6 +5,31 @@
# Reads clipboard content, opens it in $EDITOR, and writes back to clipboard
edit-clipboard() {
# Parse command line arguments
while [ $# -gt 0 ]; do
case "$1" in
--minimal)
NVIM_MINIMAL=1
shift
;;
--editor)
if [ -n "$2" ] && [ "''${2#-}" = "$2" ]; then
EDITOR="$2"
shift 2
else
echo "Error: --editor requires an argument" >&2
return 1
fi
;;
*)
echo "Error: Unknown option: $1" >&2
echo "Usage: edit-clipboard [--popup] [--editor <editor>]" >&2
return 1
;;
esac
done
# Detect clipboard command based on platform
if command -v pbpaste >/dev/null 2>&1; then
# macOS
@ -57,6 +82,8 @@
# Cleanup
rm -f "$TMPFILE"
exit 0
}
if [ "''${0##*/}" = "edit-clipboard" ] || [ "''${0##*/}" = "edit-clipboard.sh" ]; then