2026-08-29 17:40:48 -04:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
2026-09-21 16:34:23 -04:00
|
|
|
# omarchy:summary=Toggle a scratch workspace (scratchpad, fastmail, beeper), starting its resident apps when any is missing.
|
2026-08-29 17:40:48 -04:00
|
|
|
|
|
|
|
|
set -uo pipefail
|
|
|
|
|
|
2026-09-22 10:42:16 -04:00
|
|
|
# Usage: omarchy-toggle-scratch [scratchpad|fastmail|beeper]
|
2026-09-21 16:34:23 -04:00
|
|
|
#
|
|
|
|
|
# Each profile is a special workspace, the monitor it opens on, and its
|
|
|
|
|
# resident apps (class pattern -> launch command; the pattern is an anchored
|
|
|
|
|
# ERE, so a plain class name matches itself). hypr/hyprland.lua pins every
|
|
|
|
|
# class to its workspace, so only the launch and the reveal are left here. A
|
|
|
|
|
# resident is launched only when no window on the workspace matches it, which
|
|
|
|
|
# is what keeps a launcher that always opens a fresh window (the Chromium
|
|
|
|
|
# web apps) from piling up duplicates. On first start the master layout gives
|
|
|
|
|
# the master slot to whichever window appears first (a terminal beats an
|
|
|
|
|
# Electron app); swap them afterwards if the arrangement matters.
|
|
|
|
|
#
|
|
|
|
|
# HOME_MONITOR is a connector name or an EDID description (the latter, as in
|
|
|
|
|
# the workspace rules, survives a different DP connector after re-docking).
|
|
|
|
|
# When it is empty or that monitor is absent, the workspace opens on the
|
|
|
|
|
# focused one.
|
|
|
|
|
HOME_MONITOR=""
|
|
|
|
|
case ${1:-scratchpad} in
|
|
|
|
|
scratchpad)
|
|
|
|
|
NAME="scratchpad"
|
|
|
|
|
HOME_MONITOR="Apple Computer Inc StudioDisplay 0x984262A7"
|
|
|
|
|
MEMBERS=(
|
|
|
|
|
"com.anthropic.Claude|claude-desktop"
|
|
|
|
|
"kitty-herdr|kitty --class=kitty-herdr --config $HOME/.config/kitty/herdr.conf"
|
|
|
|
|
)
|
|
|
|
|
;;
|
|
|
|
|
fastmail)
|
|
|
|
|
NAME="fastmail"
|
|
|
|
|
MEMBERS=("com.fastmail.Fastmail|gtk-launch fastmail")
|
|
|
|
|
;;
|
|
|
|
|
beeper)
|
|
|
|
|
NAME="beeper"
|
|
|
|
|
MEMBERS=("Beeper|gtk-launch beeper")
|
|
|
|
|
;;
|
|
|
|
|
*)
|
2026-09-22 10:42:16 -04:00
|
|
|
echo "usage: ${0##*/} [scratchpad|fastmail|beeper]" >&2
|
2026-09-21 16:34:23 -04:00
|
|
|
exit 2
|
|
|
|
|
;;
|
|
|
|
|
esac
|
2026-08-29 17:40:48 -04:00
|
|
|
WORKSPACE="special:$NAME"
|
|
|
|
|
|
2026-09-21 16:34:23 -04:00
|
|
|
# Classes of the windows living on the scratchpad, shown or hidden.
|
|
|
|
|
scratch_classes() {
|
|
|
|
|
hyprctl clients -j | jq -r --arg ws "$WORKSPACE" '.[] | select(.workspace.name == $ws) | .class'
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
scratch_windows() {
|
|
|
|
|
scratch_classes | wc -l
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Name of the monitor currently displaying the scratchpad, if any.
|
|
|
|
|
scratch_monitor() {
|
|
|
|
|
hyprctl monitors -j | jq -r --arg ws "$WORKSPACE" '.[] | select(.specialWorkspace.name == $ws) | .name'
|
2026-08-29 17:40:48 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
scratch_visible() {
|
2026-09-21 16:34:23 -04:00
|
|
|
[[ -n $(scratch_monitor) ]]
|
2026-08-29 17:40:48 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Hyprland's lua config takes lua expressions on `hyprctl dispatch`; the
|
|
|
|
|
# classic dispatcher is the pre-lua fallback (same shape as omarchy-cycle).
|
2026-09-21 16:34:23 -04:00
|
|
|
focus_monitor() {
|
|
|
|
|
hyprctl dispatch "hl.dsp.focus({ monitor = \"$1\" })" >/dev/null 2>&1 ||
|
|
|
|
|
hyprctl dispatch focusmonitor "$1" >/dev/null
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# togglespecialworkspace acts on the focused monitor, so focus decides where
|
|
|
|
|
# the scratchpad appears (or which copy hides).
|
|
|
|
|
toggle_on() {
|
|
|
|
|
focus_monitor "$1"
|
2026-08-29 17:40:48 -04:00
|
|
|
hyprctl dispatch "hl.dsp.workspace.toggle_special(\"$NAME\")" >/dev/null 2>&1 ||
|
|
|
|
|
hyprctl dispatch togglespecialworkspace "$NAME" >/dev/null
|
|
|
|
|
}
|
|
|
|
|
|
2026-09-21 16:34:23 -04:00
|
|
|
# The profile's home monitor when connected, else whatever is focused.
|
|
|
|
|
target_monitor() {
|
|
|
|
|
hyprctl monitors -j | jq -r --arg m "$HOME_MONITOR" \
|
|
|
|
|
'first(.[] | select(.name == $m or .description == $m)) // first(.[] | select(.focused)) | .name'
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Showing: just hide, even if a member is gone. Missing members come back on
|
|
|
|
|
# the next reveal.
|
|
|
|
|
shown=$(scratch_monitor)
|
|
|
|
|
if [[ -n $shown ]]; then
|
|
|
|
|
toggle_on "$shown"
|
2026-08-29 17:40:48 -04:00
|
|
|
exit 0
|
|
|
|
|
fi
|
|
|
|
|
|
2026-09-21 16:34:23 -04:00
|
|
|
present=$(scratch_classes)
|
|
|
|
|
before=$(grep -c . <<<"$present")
|
|
|
|
|
launched=0
|
|
|
|
|
for member in "${MEMBERS[@]}"; do
|
|
|
|
|
pattern=${member%%|*}
|
|
|
|
|
grep -qE "^(${pattern})$" <<<"$present" && continue
|
|
|
|
|
setsid uwsm-app -- ${member#*|} >/dev/null 2>&1 &
|
|
|
|
|
launched=1
|
2026-08-29 17:40:48 -04:00
|
|
|
done
|
|
|
|
|
|
2026-09-21 16:34:23 -04:00
|
|
|
if ((launched)); then
|
|
|
|
|
# Reveal once the first newcomer lands; later ones (Claude takes a few
|
|
|
|
|
# seconds) drop straight onto the now-visible scratchpad. Deciding the
|
|
|
|
|
# reveal after the window lands keeps this correct whether or not the rule
|
|
|
|
|
# already showed the workspace.
|
|
|
|
|
for _ in {1..80}; do
|
|
|
|
|
sleep 0.1
|
|
|
|
|
(($(scratch_windows) > before)) && break
|
|
|
|
|
done
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
scratch_visible || toggle_on "$(target_monitor)"
|