[niri|scripts] Revamp Discord scripts

- Make one generic script
- Edit niri keybinds
This commit is contained in:
aloslider committed 2026-08-11 19:01:55 +03:00
1 parent ea9594dc43
commit f1f983f4c0
4 files changed
+51 -44

No files matched your search

+2 -2
View File
@@ -100,8 +100,8 @@ binds {
Mod+O repeat=false { toggle-overview; } Mod+O repeat=false { toggle-overview; }
// --- Discord keybinds dirty trick --- // --- Discord keybinds dirty trick ---
CTRL+BracketLeft { spawn "~/.local/scripts/discord/focus-discord-toggle-mute.sh"; } CTRL+BracketLeft repeat=false { spawn "~/.local/scripts/discord/toggle-key.sh" "m"; }
CTRL+BracketRight { spawn "~/.local/scripts/discord/focus-discord-toggle-deafen.sh"; } CTRL+BracketRight repeat=false { spawn "~/.local/scripts/discord/toggle-key.sh" "d"; }
// --- Screnshot with grim+slurp+satty --- // --- Screnshot with grim+slurp+satty ---
Mod+S hotkey-overlay-title="Screenshot (region)" { spawn "~/.local/scripts/gss-screenshot.sh" "region"; } Mod+S hotkey-overlay-title="Screenshot (region)" { spawn "~/.local/scripts/gss-screenshot.sh" "region"; }
@@ -1,21 +0,0 @@
#!/bin/sh
APP_NAME="discord-canary"
PREV_ID=$(niri msg focused-window 2>/dev/null | awk '
/Window ID/ { gsub(":", "", $3); print $3; exit }
')
DISCORD_ID=$(niri msg windows 2>/dev/null | awk -v app="$APP_NAME" '
/^Window ID/ { id = $3; sub(":", "", id) }
$0 ~ "App ID: \"" app "\"" { print id; exit }
')
if [ -z "$DISCORD_ID" ]; then
notify-send "Discord not found" "Could not find $APP_NAME window"
exit 1
fi
niri msg action focus-window --id "$DISCORD_ID"
wtype -M ctrl -M shift -k d -m shift -m ctrl # default discord keybind
if [ -n "$PREV_ID" ]; then
niri msg action focus-window --id "$PREV_ID"
fi
@@ -1,21 +0,0 @@
#!/bin/sh
APP_NAME="discord-canary"
PREV_ID=$(niri msg focused-window 2>/dev/null | awk '
/Window ID/ { gsub(":", "", $3); print $3; exit }
')
DISCORD_ID=$(niri msg windows 2>/dev/null | awk -v app="$APP_NAME" '
/^Window ID/ { id = $3; sub(":", "", id) }
$0 ~ "App ID: \"" app "\"" { print id; exit }
')
if [ -z "$DISCORD_ID" ]; then
notify-send "Discord not found" "Could not find $APP_NAME window"
exit 1
fi
niri msg action focus-window --id "$DISCORD_ID"
wtype -M ctrl -M shift -k m -m shift -m ctrl # default discord keybind
if [ -n "$PREV_ID" ]; then
niri msg action focus-window --id "$PREV_ID"
fi
@@ -0,0 +1,49 @@
#!/bin/sh
set -eu
APP_NAME="discord-canary"
KEY="${1:-${KEY:-}}"
if [ -z "$KEY" ]; then
echo "usage: $0 <key> (e.g. m or d)" >&2
notify-send "Discord toggle" "Missing key (m/d)"
exit 1
fi
PREV_FOCUS=$(niri msg -j focused-window | jq -r '.id // empty')
WINS=$(niri msg -j windows)
WSS=$(niri msg -j workspaces)
DISCORD_ID=$(printf '%s' "$WINS" | jq -r --arg a "$APP_NAME" \
'.[] | select(.app_id == $a) | .id' | head -n1)
if [ -z "$DISCORD_ID" ]; then
notify-send "Discord not found" "Could not find $APP_NAME window"
exit 1
fi
# monitor-level shown window
SHOWN_WIN=$(printf '%s' "$WINS" | jq -r --argjson did "$DISCORD_ID" --argjson wss "$WSS" '
(.[] | select(.id == $did) | .workspace_id) as $wsid
| ($wss[] | select(.id == $wsid) | .output) as $out
| ($wss[] | select(.output == $out and .is_active) | .active_window_id // empty)
')
# focus Discord only if needed
if [ "$PREV_FOCUS" != "$DISCORD_ID" ]; then
niri msg action focus-window --id "$DISCORD_ID"
sleep 0.05
fi
wtype -M ctrl -M shift -k "$KEY" -m shift -m ctrl
sleep 0.05
# restore what that monitor was showing
if [ -n "${SHOWN_WIN:-}" ] && [ "$SHOWN_WIN" != "$DISCORD_ID" ]; then
niri msg action focus-window --id "$SHOWN_WIN"
sleep 0.05
fi
# # restore original global focus
if [ -n "$PREV_FOCUS" ] && [ "$PREV_FOCUS" != "$DISCORD_ID" ] && [ "$PREV_FOCUS" != "${SHOWN_WIN:-}" ]; then
niri msg action focus-window --id "$PREV_FOCUS"
fi