This commit is contained in:
kiri committed 2026-09-22 21:44:35 +02:00
1 parent f164d8b76e
commit 5748b3409b
60 files changed
+1346 -590

No files matched your search

@@ -0,0 +1,168 @@
{
browser,
handy,
launcher,
swapMonitorWorkspaces,
terminal,
}:
let
spawnLocked = command: {
spawn-sh = command;
_props.allow-when-locked = true;
};
withCooldown = action: {
${action} = { };
_props.cooldown-ms = 150;
};
in
{
# Application and utility launchers
"Mod+Return" = {
spawn = terminal;
_props.hotkey-overlay-title = "Terminal";
};
"Mod+B" = {
spawn = browser;
_props.hotkey-overlay-title = "Browser";
};
"Mod+Shift+N" = {
spawn-sh = "rename-workspace";
_props.hotkey-overlay-title = "Name workspace (empty clears)";
};
"Mod+N" = {
spawn-sh = "open-notes";
_props.hotkey-overlay-title = "Find or create notes";
};
"Mod+Space" = {
_props.repeat = false;
spawn = launcher;
_props.hotkey-overlay-title = "App Launcher";
};
# Dictation
"Mod+D" = {
spawn = [
"systemctl"
"--user"
"start"
"handy-ptt.service"
];
_props.repeat = false;
_props.hotkey-overlay-title = "Hold to Dictate";
};
"Mod+Shift+D" = {
spawn-sh = "systemctl --user stop handy-ptt.service && ${handy} --toggle-transcription";
_props.repeat = false;
_props.hotkey-overlay-title = "Toggle Dictation";
};
"Mod+Ctrl+D" = {
spawn-sh = "systemctl --user stop handy-ptt.service && ${handy} --cancel";
_props.repeat = false;
_props.hotkey-overlay-title = "Cancel Dictation";
};
# Hardware media, volume, and brightness keys
"XF86AudioPlay" = spawnLocked "playerctl play-pause";
"XF86AudioStop" = spawnLocked "playerctl stop";
"XF86AudioPrev" = spawnLocked "playerctl previous";
"XF86AudioNext" = spawnLocked "playerctl next";
"XF86AudioRaiseVolume" = spawnLocked "wpctl set-volume @DEFAULT_AUDIO_SINK@ 5%+";
"XF86AudioLowerVolume" = spawnLocked "wpctl set-volume @DEFAULT_AUDIO_SINK@ 5%-";
"XF86AudioMute" = spawnLocked "wpctl set-mute @DEFAULT_AUDIO_SINK@ toggle";
"XF86AudioMicMute" = spawnLocked "wpctl set-mute @DEFAULT_AUDIO_SOURCE@ toggle";
"XF86MonBrightnessUp" = spawnLocked "brightnessctl s 5%+";
"XF86MonBrightnessDown" = spawnLocked "brightnessctl s 5%-";
# Screenshots
"Mod+S".screenshot = { };
# Session and compositor controls
"Mod+Escape" = {
toggle-keyboard-shortcuts-inhibit = { };
_props.allow-inhibiting = false;
};
"Mod+Ctrl+L" = {
spawn-sh = "loginctl lock-session";
_props.hotkey-overlay-title = "Lock Screen";
};
# Overview and window close
"Mod+O" = {
toggle-overview = { };
_props.repeat = false;
};
"Mod+Q" = {
close-window = { };
_props.repeat = false;
};
# Keyboard focus movement
"Mod+H".focus-column-or-monitor-left = { };
"Mod+J".focus-window-down = { };
"Mod+K".focus-window-up = { };
"Mod+L".focus-column-or-monitor-right = { };
# Keyboard window and column movement
"Mod+Alt+H".move-column-left-or-to-monitor-left = { };
"Mod+Alt+J".move-window-down-or-to-workspace-down = { };
"Mod+Alt+K".move-window-up-or-to-workspace-up = { };
"Mod+Alt+L".move-column-right-or-to-monitor-right = { };
# Move focus, columns, and workspaces across monitors
"Mod+Tab".focus-monitor-next = { };
"Mod+A" = {
_props.repeat = false;
spawn = swapMonitorWorkspaces;
_props.hotkey-overlay-title = "Swap Monitor Workspaces";
};
"Mod+Alt+Tab".move-column-to-monitor-next = { };
"Mod+Shift+Tab".move-workspace-to-monitor-next = { };
# Linear workspace navigation
"Mod+U".focus-workspace-down = { };
"Mod+I".focus-workspace-up = { };
# Move columns between adjacent workspaces
"Mod+Alt+U".move-column-to-workspace-down = { };
"Mod+Alt+I".move-column-to-workspace-up = { };
# Reorder workspaces
"Mod+Shift+U".move-workspace-down = { };
"Mod+Shift+I".move-workspace-up = { };
# Mouse workspace navigation
"Mod+WheelScrollDown" = withCooldown "focus-workspace-down";
"Mod+WheelScrollUp" = withCooldown "focus-workspace-up";
"Mod+Alt+WheelScrollDown" = withCooldown "move-column-to-workspace-down";
"Mod+Alt+WheelScrollUp" = withCooldown "move-column-to-workspace-up";
# Mouse column navigation and movement
"Mod+WheelScrollRight".focus-column-or-monitor-right = { };
"Mod+WheelScrollLeft".focus-column-or-monitor-left = { };
"Mod+Alt+WheelScrollRight".move-column-right-or-to-monitor-right = { };
"Mod+Alt+WheelScrollLeft".move-column-left-or-to-monitor-left = { };
"Mod+Shift+WheelScrollDown".focus-column-or-monitor-right = { };
"Mod+Shift+WheelScrollUp".focus-column-or-monitor-left = { };
# Add and remove windows from columns
"Mod+BracketLeft".consume-or-expel-window-left = { };
"Mod+BracketRight".consume-or-expel-window-right = { };
"Mod+Comma".consume-window-into-column = { };
"Mod+Period".expel-window-from-column = { };
# Column and window presentation modes
"Mod+R".switch-preset-column-width = { };
"Mod+F".maximize-column = { };
"Mod+Shift+F".fullscreen-window = { };
# Manual column width and window height adjustments
"Mod+Shift+H".set-column-width = "-10%";
"Mod+Shift+L".set-column-width = "+10%";
"Mod+Shift+J".set-window-height = "+10%";
"Mod+Shift+K".set-window-height = "-10%";
# Floating and tabbed layout toggles
"Mod+Alt+V".toggle-window-floating = { };
"Mod+Shift+V".switch-focus-between-floating-and-tiling = { };
"Mod+W".toggle-column-tabbed-display = { };
}
@@ -0,0 +1,88 @@
{ pkgs }:
pkgs.writeScriptBin "niri-shortcut-swap-monitor-workspaces" ''
#!${pkgs.python3}/bin/python3
import fcntl
import json
import os
import socket
import sys
def disposable(workspace):
return workspace["active_window_id"] is None and workspace["name"] is None
def swap(connection):
with connection.makefile("rw", encoding="utf-8") as stream:
def request(message):
stream.write(json.dumps(message) + "\n")
stream.flush()
reply = json.loads(stream.readline())
if "Err" in reply:
raise RuntimeError(reply["Err"])
return reply["Ok"]
def action(name, **arguments):
request({"Action": {name: arguments}})
workspaces = request("Workspaces")["Workspaces"]
source = next((ws for ws in workspaces if ws["is_focused"]), None)
active = {
ws["output"]: ws for ws in workspaces
if ws["output"] is not None and ws["is_active"]
}
if source is None or source["output"] not in active or len(active) < 2:
return
outputs = sorted(active)
target = active[outputs[(outputs.index(source["output"]) + 1) % len(outputs)]]
if source["active_window_id"] is None and target["active_window_id"] is None:
return
# IDs survive moves; numeric workspace positions do not.
moves = ((source, target), (target, source))
for workspace, destination in moves:
action(
"MoveWorkspaceToMonitor",
reference={"Id": workspace["id"]},
output=destination["output"],
)
# Activate the original monitor last to keep keyboard focus there.
for workspace, destination in moves:
current = request("Workspaces")["Workspaces"]
arriving = next((
ws for ws in current
if ws["id"] == workspace["id"] and ws["output"] == destination["output"]
), None)
if arriving is None and disposable(workspace):
# Niri may discard an unnamed empty workspace during the swap.
arriving = max((
ws for ws in current
if ws["output"] == destination["output"] and disposable(ws)
), key=lambda ws: ws["idx"], default=None)
if arriving is None:
raise RuntimeError("workspace or monitor disappeared during swap")
reference = {"Id": arriving["id"]}
# Focus empty workspaces before reordering so Niri retains them.
action("FocusWorkspace", reference=reference)
action("MoveWorkspaceToIndex", reference=reference, index=destination["idx"])
def main():
lock_path = os.path.join(os.environ["XDG_RUNTIME_DIR"], "niri-swap-workspaces.lock")
with open(lock_path, "a") as lock:
try:
fcntl.flock(lock, fcntl.LOCK_EX | fcntl.LOCK_NB)
except BlockingIOError:
return
with socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) as connection:
connection.settimeout(5)
connection.connect(os.environ["NIRI_SOCKET"])
swap(connection)
try:
main()
except (OSError, ValueError, KeyError, RuntimeError) as error:
sys.exit(f"niri workspace swap: {error}")
''