Add Kando pie menu of cursor-following popups and aichat quick role
Replace cursor_ask.sh with popup.sh launching popups from a Kando "popups" menu; cursor_follow.lua gains a popups table (sizes, follow until Enter, stay_focused) and pauses following while Kando is open. Add aichat config/role for the quick Claude popup and Kando menu/theme configs, with gen-colors syncing the Kando theme palette. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
# aichat config for the SUPER+A AI popups (popup.sh points AICHAT_CONFIG_FILE and AICHAT_ROLES_DIR here)
|
||||
# The API key stays out of the repo, in ~/.config/aichat/.env as CLAUDE_API_KEY=...
|
||||
model: claude:claude-haiku-5-5
|
||||
stream: true
|
||||
save: false
|
||||
wrap: auto
|
||||
wrap_code: false
|
||||
function_calling: false
|
||||
save_session: false
|
||||
# every REPL starts with a throwaway session (so follow-ups keep context) and the quick role
|
||||
repl_prelude: temp:quick
|
||||
left_prompt: '{color.cyan}> {color.reset}'
|
||||
right_prompt: ''
|
||||
|
||||
clients:
|
||||
- type: claude
|
||||
models:
|
||||
- name: claude-haiku-5-5
|
||||
max_input_tokens: 200000
|
||||
max_output_tokens: 4096
|
||||
require_max_tokens: true
|
||||
supports_vision: true
|
||||
# Haiku otherwise streams an empty thinking block, which aichat prints as <think></think>
|
||||
patch:
|
||||
chat_completions:
|
||||
'.*':
|
||||
body:
|
||||
thinking:
|
||||
type: disabled
|
||||
@@ -0,0 +1,8 @@
|
||||
You are a terse reference assistant in a small terminal popup, about 70 columns by 20 lines.
|
||||
Reply with only the answer, starting with its first word, in 1-3 short sentences.
|
||||
No preamble, alternatives, caveats or summaries. No headings, tables or bold.
|
||||
When first asked to write or make code, do not write it: reply with the library to use, then the
|
||||
key functions or methods in the order they would be called, one per line as `name()` and a few
|
||||
words on what it does. When the user then asks to see the code, write it in one short code block.
|
||||
If the question could mean two things, answer the likelier one and name the other in a few words.
|
||||
The user will ask a follow-up if they want more.
|
||||
+12
-4
@@ -6,7 +6,7 @@
|
||||
---- MONITORS ----
|
||||
------------------
|
||||
|
||||
hl.monitor({ output = "", mode = "preferred", position = "auto", scale = 1 })
|
||||
hl.monitor({ output = "", mode = "preferred", position = "auto", scale = 1.5 })
|
||||
-- Per-machine layout generated by nwg-displays
|
||||
pcall(require, "monitors")
|
||||
|
||||
@@ -249,8 +249,16 @@ hl.bind(mod .. " + B", hl.dsp.focus({ workspace = "previous" })) -- back_and_for
|
||||
for i = 1, 8 do
|
||||
-- Switch to workspace
|
||||
hl.bind(mod .. " + " .. i, hl.dsp.focus({ workspace = i }))
|
||||
-- Move container to workspace (silent = don't follow)
|
||||
hl.bind(mod .. " + CTRL + " .. i, hl.dsp.window.move({ workspace = i, follow = false }))
|
||||
-- Move container to workspace (silent = don't follow). A pinned window is unpinned first: Hyprland 0.56
|
||||
-- leaves a pinned window's layout on the hidden workspace once it's focused here, and floating or tiling
|
||||
-- it after that workspace is gone crashes Hyprland
|
||||
hl.bind(mod .. " + CTRL + " .. i, function()
|
||||
local w = hl.get_active_window()
|
||||
if w and w.pinned then
|
||||
hl.dispatch(hl.dsp.window.pin({ action = "disable" }))
|
||||
end
|
||||
hl.dispatch(hl.dsp.window.move({ workspace = i, follow = false }))
|
||||
end)
|
||||
-- Move to workspace AND follow (replaces $mod+Shift+N in i3)
|
||||
hl.bind(mod .. " + SHIFT + " .. i, hl.dsp.window.move({ workspace = i, follow = true }))
|
||||
end
|
||||
@@ -316,7 +324,7 @@ hl.window_rule({
|
||||
float = true,
|
||||
})
|
||||
|
||||
-- Picture-in-Picture windows float and follow the cursor (SUPER+P / SUPER+SHIFT+P), see cursor_follow.lua
|
||||
-- Picture-in-Picture windows float and follow the cursor (SUPER+Z / SUPER+SHIFT+Z), see cursor_follow.lua
|
||||
require("cursor_follow")
|
||||
|
||||
-------------------------------
|
||||
|
||||
@@ -1,153 +0,0 @@
|
||||
#!/bin/bash
|
||||
# cursor_ask: ask Claude a quick question in a popup that follows the mouse cursor
|
||||
# Opened by SUPER+A (see cursor_follow.lua), which freezes the window once the title
|
||||
# changes to "cursor-ask: <question>". Highlighted text is sent along with the first question.
|
||||
# Ctrl+C stops an answer, Ctrl+D or Esc closes the window.
|
||||
|
||||
model=${CURSOR_ASK_MODEL:-haiku}
|
||||
system="You are a terse reference assistant in a small terminal popup, about 70 columns by 20 lines. \
|
||||
Reply with only the answer, starting with its first word, in 1-3 short sentences. \
|
||||
No preamble, alternatives, caveats or summaries. No headings, tables or bold. \
|
||||
For requests to write or make code you are a guide, not a code writer: reply with the library to use, \
|
||||
then the key functions or methods in the order they would be called, one per line as \`name()\` \
|
||||
and a few words on what it does. Write actual code only if the user explicitly asks to see it. \
|
||||
If the question could mean two things, answer the likelier one and name the other in a few words. \
|
||||
The user will ask a follow-up if they want more."
|
||||
# highlighted text sent last time, so a stale selection is not sent again
|
||||
seen="${XDG_RUNTIME_DIR:-/tmp}/cursor-ask-selection"
|
||||
dir="${XDG_CACHE_HOME:-$HOME/.cache}/cursor-ask"
|
||||
|
||||
err=$(mktemp)
|
||||
trap 'rm -f "$err"' EXIT
|
||||
# Ctrl+C only interrupts the running answer or the prompt
|
||||
trap 'printf "\n"' INT
|
||||
|
||||
# keep these throwaway sessions out of real projects
|
||||
mkdir -p "$dir" && cd "$dir" || exit 1
|
||||
|
||||
title() {
|
||||
printf '\e]2;%s\a' "$1"
|
||||
}
|
||||
|
||||
# style markdown with terminal escapes and wrap it at word boundaries, a line at a time
|
||||
# so the answer still streams in
|
||||
md() {
|
||||
awk -v width="$(tput cols)" '
|
||||
function inline(s) {
|
||||
s = gensub(/\*\*([^*]+)\*\*/, "\033[1m\\1\033[22m", "g", s)
|
||||
s = gensub(/(^|[^*])\*([^* ][^*]*)\*/, "\\1\033[3m\\2\033[23m", "g", s)
|
||||
return gensub(/\[([^]]+)\]\(([^)]+)\)/, "\033[4m\\1\033[24m (\\2)", "g", s)
|
||||
}
|
||||
# length on screen, without the escape sequences
|
||||
function len(s) {
|
||||
gsub(/\033\[[0-9;]*m/, "", s)
|
||||
return length(s)
|
||||
}
|
||||
# print s word-wrapped, starting with first and indenting the following lines with rest
|
||||
function wrap(s, first, rest, w, n, i, line, used, fresh) {
|
||||
n = split(s, w, " ")
|
||||
line = first; used = len(first); fresh = 1
|
||||
for (i = 1; i <= n; i++) {
|
||||
if (!fresh && used + 1 + len(w[i]) > width) {
|
||||
print line
|
||||
line = rest; used = len(rest); fresh = 1
|
||||
}
|
||||
line = line (fresh ? "" : " ") w[i]
|
||||
used += (fresh ? 0 : 1) + len(w[i])
|
||||
fresh = 0
|
||||
}
|
||||
print line
|
||||
}
|
||||
/^[[:space:]]*```/ { code = !code; next }
|
||||
code { printf " \033[33m%s\033[39m\n", $0; fflush(); next }
|
||||
{
|
||||
pre = post = rest = ""
|
||||
if (match($0, /^#+[[:space:]]+/)) {
|
||||
pre = "\033[1;36m"; post = "\033[0m"
|
||||
} else if (match($0, /^([[:space:]]*)[-*+][[:space:]]+/, m)) {
|
||||
pre = m[1] "• "; rest = sprintf("%*s", len(pre), "")
|
||||
} else if (match($0, /^>[[:space:]]?/)) {
|
||||
pre = rest = "\033[2m│\033[22m "
|
||||
}
|
||||
line = substr($0, RLENGTH > 0 ? RLENGTH + 1 : 1)
|
||||
# balanced backticks split the line into text and inline code, alternately
|
||||
n = split(line, p, "`")
|
||||
if (n % 2) {
|
||||
line = ""
|
||||
for (i = 1; i <= n; i++) line = line (i % 2 ? inline(p[i]) : "\033[33m" p[i] "\033[39m")
|
||||
} else {
|
||||
line = inline(line)
|
||||
}
|
||||
wrap(line post, pre, rest)
|
||||
fflush()
|
||||
}'
|
||||
}
|
||||
|
||||
# the first character replaces the "thinking…" line; fails when nothing came back
|
||||
render() {
|
||||
local c
|
||||
if IFS= read -r -n1 -d '' c; then
|
||||
printf '\r\e[K%s' "$c"
|
||||
cat
|
||||
else
|
||||
printf '\r\e[K'
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
title cursor-ask
|
||||
|
||||
selection=$(wl-paste --primary --no-newline 2>/dev/null | head -c 20000)
|
||||
if [[ -n $selection && $selection != "$(cat "$seen" 2>/dev/null)" ]]; then
|
||||
printf '%s' "$selection" >"$seen"
|
||||
width=$(($(tput cols) - 2))
|
||||
printf '\e[2mwith highlighted text (Enter on an empty line drops it):\n'
|
||||
while IFS= read -r line; do
|
||||
printf '│ %s\n' "${line:0:width}"
|
||||
done < <(head -n 3 <<<"$selection")
|
||||
lines=$(wc -l <<<"$selection")
|
||||
((lines > 3)) && printf '│ … %d lines\n' "$lines"
|
||||
printf '\e[0m\n'
|
||||
else
|
||||
selection=
|
||||
fi
|
||||
|
||||
session=$(cat /proc/sys/kernel/random/uuid)
|
||||
while true; do
|
||||
IFS= read -e -r -p $'\001\e[1;36m\002> \001\e[0m\002' q
|
||||
status=$?
|
||||
((status == 1)) && exit # Ctrl+D
|
||||
((status > 128)) && continue # Ctrl+C
|
||||
if [[ -z ${q//[[:space:]]/} ]]; then
|
||||
if [[ -n $selection ]]; then
|
||||
selection=
|
||||
printf '\e[2m(dropped the highlighted text)\e[0m\n'
|
||||
fi
|
||||
continue
|
||||
fi
|
||||
history -s "$q"
|
||||
title "cursor-ask: ${q:0:60}"
|
||||
|
||||
prompt=$q
|
||||
if [[ -n $selection ]]; then
|
||||
prompt=$(printf '<selection>\n%s\n</selection>\n\n%s' "$selection" "$q")
|
||||
selection=
|
||||
fi
|
||||
# follow-ups continue the conversation once the first call has saved it
|
||||
if compgen -G "$HOME/.claude/projects/*/$session.jsonl" >/dev/null; then
|
||||
resume=(--resume "$session")
|
||||
else
|
||||
resume=(--session-id "$session")
|
||||
fi
|
||||
|
||||
printf '\e[2mthinking…\e[0m'
|
||||
claude -p "$prompt" --model "$model" --system-prompt "$system" "${resume[@]}" \
|
||||
--tools "" --strict-mcp-config \
|
||||
--output-format stream-json --verbose --include-partial-messages 2>"$err" |
|
||||
jq --unbuffered -j '
|
||||
if .type == "stream_event" and .event.delta.type? == "text_delta" then .event.delta.text
|
||||
elif .type == "result" and .is_error then "\u001b[31m\(.result)\u001b[0m"
|
||||
else empty end' |
|
||||
md | render || printf '\e[31m%s\e[0m' "$(tail -n 3 "$err")"
|
||||
printf '\n'
|
||||
done
|
||||
+205
-88
@@ -1,10 +1,12 @@
|
||||
-- cursor_follow: keep a floating window glued next to the mouse cursor (Hyprland Lua config)
|
||||
-- Picture-in-Picture windows follow automatically; SUPER+P makes the focused window follow,
|
||||
-- or pauses/resumes following; SUPER+SHIFT+P stops; SUPER+CTRL+P toggles a bigger window centered
|
||||
-- above the cursor; SUPER+ALT+Space/Left/Right play/pause and seek the video (via playerctl);
|
||||
-- SUPER+ALT+Up/Down widen/narrow the gap to the cursor; SUPER+ALT+P lists these keybindings.
|
||||
-- SUPER+A opens a terminal beside the cursor to ask Claude a quick question (cursor_ask.sh); it holds
|
||||
-- keyboard focus while following and stops following once the question is sent, so it can be scrolled.
|
||||
-- Picture-in-Picture windows follow automatically; SUPER+Z pauses following, and pressed again over
|
||||
-- another window makes that one follow instead (or over the paused one, resumes it);
|
||||
-- SUPER+SHIFT+Z stops; SUPER+CTRL+Z toggles a bigger window centered
|
||||
-- above the cursor; SUPER+ALT+S/A/D play/pause and seek the video (via playerctl);
|
||||
-- SUPER+ALT+Up/Down widen/narrow the gap to the cursor; SUPER+ALT+Right/Left grow/shrink the window;
|
||||
-- SUPER+ALT+Z lists these keybindings.
|
||||
-- SUPER+A opens a Kando pie menu of popups (popup.sh) that open beside the cursor; the keyboard ones
|
||||
-- hold focus while they follow it and stop following once Enter is pressed in them, so they can be scrolled.
|
||||
-- Load from hyprland.lua with: require("cursor_follow")
|
||||
|
||||
local M = {
|
||||
@@ -16,11 +18,21 @@ local M = {
|
||||
margin = 8, -- keep this far from monitor edges
|
||||
dir = { x = 1, y = -1 }, -- starting side of the cursor (right, above); flips at screen edges
|
||||
centered_scale = 1.25, -- window size multiplier while centered above the cursor
|
||||
size_step = 1.1, -- window size multiplier per grow key press (shrink divides by it)
|
||||
min_width = 160, -- smallest width the shrink key goes down to
|
||||
interval = 8, -- ms between cursor polls
|
||||
player = "firefox", -- MPRIS player for the video keys (Waterfox shows up as firefox)
|
||||
seek = 10, -- seconds skipped by the seek keys
|
||||
ask_width = 640, -- size of the SUPER+A question window
|
||||
ask_height = 420,
|
||||
-- SUPER+A menu popups by window class: size, and whether it follows the cursor until Enter is
|
||||
-- pressed in it (keyboard popups) or is only placed beside the cursor (ones used with the mouse)
|
||||
popups = {
|
||||
["popup-ai"] = { 640, 420, follow = true },
|
||||
["popup-term"] = { 640, 360, follow = true },
|
||||
-- the receipt printer page as a Chromium app, served locally or by the website
|
||||
["chrome-127.0.0.1__-Default"] = { 480, 720 },
|
||||
["chrome-www.adam-french.co.uk__receipt_-Default"] = { 480, 720 },
|
||||
["org.pulseaudio.pavucontrol"] = { 640, 480 },
|
||||
},
|
||||
},
|
||||
target = nil, -- address of the followed window
|
||||
paused = false,
|
||||
@@ -36,29 +48,27 @@ local timer
|
||||
local tag = "cursor-follow"
|
||||
-- marks it as centered too, so the mode survives a reload
|
||||
local centered_tag = "cursor-follow-centered"
|
||||
-- class of the SUPER+A question window; cursor_ask.sh retitles it to "cursor-ask: <question>"
|
||||
local ask_class = "cursor-ask"
|
||||
-- window that was following before the question window took over, picked back up when it closes
|
||||
local resume_after_ask
|
||||
-- window that was following before a popup took over, picked back up when the popup closes
|
||||
local resume_after_popup
|
||||
-- sticky notes, kept in the scratchpad
|
||||
local sticky_class = "xpad"
|
||||
-- the SUPER+A pie menu's full-screen window (Kando's settings window has the same class)
|
||||
local menu_class, menu_title = "menu.kando.Kando", "Kando Menu"
|
||||
|
||||
local function selector()
|
||||
return "address:" .. M.target
|
||||
end
|
||||
|
||||
local function is_ask(w)
|
||||
return w ~= nil and w.class == ask_class
|
||||
-- the popup spec of a following SUPER+A popup
|
||||
local function follow_popup(w)
|
||||
local p = w and cfg.popups[w.class]
|
||||
return p and p.follow and p
|
||||
end
|
||||
|
||||
-- a question has been sent from this window
|
||||
local function asked(w)
|
||||
return w.title:sub(1, #ask_class + 2) == ask_class .. ": "
|
||||
end
|
||||
|
||||
-- focus follows the mouse and the followed window is never under the cursor, so the question
|
||||
-- window holds keyboard focus while it follows
|
||||
-- focus follows the mouse and the followed window is never under the cursor, so a keyboard
|
||||
-- popup holds keyboard focus while it follows
|
||||
local function lock_focus(on)
|
||||
local w = M.target and hl.get_window(selector())
|
||||
if is_ask(w) then
|
||||
if follow_popup(M.target and hl.get_window(selector())) then
|
||||
hl.dispatch(hl.dsp.window.set_prop({ window = selector(), prop = "stay_focused", value = on and "1" or "0" }))
|
||||
end
|
||||
end
|
||||
@@ -106,6 +116,24 @@ function M.detach()
|
||||
last_x, last_y = nil, nil
|
||||
end
|
||||
|
||||
-- Position for a window of `size` beside the cursor, on the sides in `s` (flipped in place at
|
||||
-- the monitor edges), or centered above it
|
||||
local function beside_cursor(size, s, centered)
|
||||
local c, m = hl.get_cursor_pos(), hl.get_monitor_at_cursor()
|
||||
if not c or not m then
|
||||
return
|
||||
end
|
||||
local mw, mh = m.width / m.scale, m.height / m.scale
|
||||
local x, y
|
||||
if centered then
|
||||
x = clamp(c.x - size.x / 2, size.x, m.x, m.x + mw)
|
||||
else
|
||||
x, s.x = axis(c.x, size.x, m.x, m.x + mw, s.x)
|
||||
end
|
||||
y, s.y = axis(c.y, size.y, m.y, m.y + mh, s.y)
|
||||
return x, y
|
||||
end
|
||||
|
||||
local function place()
|
||||
local w = M.target and hl.get_window(selector())
|
||||
-- stop once the window is closed or tiled again
|
||||
@@ -113,20 +141,8 @@ local function place()
|
||||
M.detach()
|
||||
return
|
||||
end
|
||||
local c, m = hl.get_cursor_pos(), hl.get_monitor_at_cursor()
|
||||
if not c or not m then
|
||||
return
|
||||
end
|
||||
|
||||
local mw, mh = m.width / m.scale, m.height / m.scale
|
||||
local x, y
|
||||
if M.centered then
|
||||
x = clamp(c.x - w.size.x / 2, w.size.x, m.x, m.x + mw)
|
||||
else
|
||||
x, side.x = axis(c.x, w.size.x, m.x, m.x + mw, side.x)
|
||||
end
|
||||
y, side.y = axis(c.y, w.size.y, m.y, m.y + mh, side.y)
|
||||
if x == last_x and y == last_y then
|
||||
local x, y = beside_cursor(w.size, side, M.centered)
|
||||
if not x or (x == last_x and y == last_y) then
|
||||
return
|
||||
end
|
||||
last_x, last_y = x, y
|
||||
@@ -180,6 +196,20 @@ function M.toggle_centered()
|
||||
end
|
||||
end
|
||||
|
||||
-- Grow (f > 1) or shrink the followed window, keeping its aspect ratio and keeping it between
|
||||
-- min_width and the monitor width. Later windows start at the new size too.
|
||||
function M.scale(f)
|
||||
local w = M.target and hl.get_window(selector())
|
||||
if not w then
|
||||
return
|
||||
end
|
||||
local m = hl.get_monitor_at_cursor()
|
||||
local max = m and m.width / m.scale - 2 * cfg.margin or math.huge
|
||||
f = math.max(cfg.min_width / w.size.x, math.min(f, max / w.size.x))
|
||||
cfg.width, cfg.height = cfg.width * f, cfg.height * f
|
||||
resize(w.size.x * f, w.size.y * f)
|
||||
end
|
||||
|
||||
---------------
|
||||
---- RULES ----
|
||||
---------------
|
||||
@@ -197,13 +227,37 @@ hl.window_rule({
|
||||
keep_aspect_ratio = true,
|
||||
})
|
||||
|
||||
for class, p in pairs(cfg.popups) do
|
||||
hl.window_rule({
|
||||
name = "cursor-follow-" .. class,
|
||||
match = { class = "^(" .. class .. ")$" },
|
||||
float = true,
|
||||
pin = p.follow,
|
||||
size = p[1] .. " " .. p[2],
|
||||
no_anim = true,
|
||||
})
|
||||
end
|
||||
|
||||
hl.window_rule({
|
||||
name = "cursor-follow-ask",
|
||||
match = { class = "^(" .. ask_class .. ")$" },
|
||||
name = "cursor-follow-sticky",
|
||||
match = { class = "^(" .. sticky_class .. ")$" },
|
||||
workspace = "special:scratchpad silent",
|
||||
float = true,
|
||||
})
|
||||
|
||||
-- Kando draws the pie menu in a transparent window covering the screen
|
||||
hl.window_rule({
|
||||
name = "kando",
|
||||
match = { class = menu_class, title = menu_title },
|
||||
no_blur = true,
|
||||
opaque = true,
|
||||
move = { 0, 0 },
|
||||
rounding = 0,
|
||||
size = { "100%", "100%" },
|
||||
border_size = 0,
|
||||
no_anim = true,
|
||||
float = true,
|
||||
pin = true,
|
||||
size = cfg.ask_width .. " " .. cfg.ask_height,
|
||||
no_anim = true,
|
||||
})
|
||||
|
||||
----------------
|
||||
@@ -216,36 +270,71 @@ local function maybe_attach_pip(w)
|
||||
end
|
||||
end
|
||||
|
||||
local function maybe_attach_ask(w)
|
||||
if is_ask(w) and w.address ~= M.target then
|
||||
resume_after_ask = M.target
|
||||
M.attach(w, true)
|
||||
-- keyboard popups follow the cursor; the others are only placed beside it
|
||||
local function open_popup(w)
|
||||
local p = cfg.popups[w.class]
|
||||
if not p then
|
||||
return
|
||||
end
|
||||
if p.follow then
|
||||
if w.address ~= M.target then
|
||||
resume_after_popup = M.target
|
||||
M.attach(w, true)
|
||||
end
|
||||
return
|
||||
end
|
||||
local x, y = beside_cursor({ x = p[1], y = p[2] }, { x = cfg.dir.x, y = cfg.dir.y }, false)
|
||||
if x then
|
||||
hl.dispatch(hl.dsp.window.move({ window = "address:" .. w.address, x = x, y = y }))
|
||||
end
|
||||
end
|
||||
|
||||
-- The pie menu needs the keyboard (it selects when SUPER is released) and would otherwise have
|
||||
-- a following popup chase the cursor across it, so a following popup stays where it is from here on
|
||||
local function open_menu(w)
|
||||
if w.class ~= menu_class or w.title ~= menu_title then
|
||||
return
|
||||
end
|
||||
if M.target and not M.paused and follow_popup(hl.get_window(selector())) then
|
||||
M.toggle_pause()
|
||||
-- stay_focused may already have kept focus from the menu as it mapped
|
||||
hl.dispatch(hl.dsp.focus({ window = "address:" .. w.address }))
|
||||
end
|
||||
end
|
||||
|
||||
hl.on("window.open", maybe_attach_pip)
|
||||
hl.on("window.open", maybe_attach_ask)
|
||||
hl.on("window.open", open_popup)
|
||||
hl.on("window.open", open_menu)
|
||||
-- browsers can set the PiP title after the window maps
|
||||
hl.on("window.title", maybe_attach_pip)
|
||||
|
||||
-- stop following once a question is sent, so the answer can be scrolled with the mouse
|
||||
hl.on("window.title", function(w)
|
||||
if w.address == M.target and is_ask(w) and asked(w) and not M.paused then
|
||||
M.toggle_pause()
|
||||
end
|
||||
end)
|
||||
|
||||
hl.on("window.close", function(w)
|
||||
if w.address == M.target then
|
||||
M.detach()
|
||||
-- hand following back to the window the question window took over from
|
||||
local prev = is_ask(w) and resume_after_ask and hl.get_window("address:" .. resume_after_ask)
|
||||
-- hand following back to the window the popup took over from
|
||||
local prev = follow_popup(w) and resume_after_popup and hl.get_window("address:" .. resume_after_popup)
|
||||
if prev and prev.floating then
|
||||
M.attach(prev, true)
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
-- an unpinned window stays on one workspace (SUPER+CTRL+N unpins it to send it away), so stop following it
|
||||
hl.on("window.pin", function(w)
|
||||
if w.address == M.target and not w.pinned then
|
||||
M.detach()
|
||||
end
|
||||
end)
|
||||
|
||||
-- Enter in a following popup sends what was typed, so stop following and let the answer be
|
||||
-- scrolled with the mouse; non_consuming still passes the key on to the popup
|
||||
hl.bind("Return", function()
|
||||
local w = M.target and not M.paused and hl.get_active_window()
|
||||
if w and w.address == M.target and follow_popup(w) then
|
||||
M.toggle_pause()
|
||||
end
|
||||
end, { non_consuming = true })
|
||||
|
||||
------------------
|
||||
---- KEYBINDS ----
|
||||
------------------
|
||||
@@ -264,42 +353,48 @@ function M.help()
|
||||
hl.exec_cmd("notify-send -t 10000 'cursor follow' '" .. table.concat(lines, "\n") .. "'")
|
||||
end
|
||||
|
||||
function M.toggle_ask()
|
||||
-- show or hide the sticky notes in the scratchpad, moving any pads that are elsewhere into it
|
||||
function M.toggle_sticky()
|
||||
local pads = false
|
||||
for _, w in ipairs(hl.get_windows()) do
|
||||
if is_ask(w) then
|
||||
hl.dispatch(hl.dsp.window.close({ window = "address:" .. w.address }))
|
||||
return
|
||||
if w.class == sticky_class then
|
||||
pads = true
|
||||
if not w.workspace or w.workspace.name ~= "special:scratchpad" then
|
||||
hl.dispatch(
|
||||
hl.dsp.window.move({
|
||||
window = "address:" .. w.address,
|
||||
workspace = "special:scratchpad",
|
||||
follow = false,
|
||||
})
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
hl.exec_cmd(
|
||||
"kitty --class "
|
||||
.. ask_class
|
||||
.. " -o confirm_os_window_close=0 -o window_padding_width=10 -o 'map escape close_window' -e "
|
||||
.. os.getenv("HOME")
|
||||
.. "/.config/hypr/cursor_ask.sh"
|
||||
)
|
||||
if not pads then
|
||||
hl.exec_cmd("xpad --show")
|
||||
end
|
||||
hl.dispatch(hl.dsp.workspace.toggle_special("scratchpad"))
|
||||
end
|
||||
|
||||
-- Pause the following window. Once paused, the window under the cursor (focus follows the mouse)
|
||||
-- follows instead, leaving the paused one where it is, or the paused one resumes if it's under the cursor.
|
||||
function M.follow_or_pause()
|
||||
local w = hl.get_active_window()
|
||||
if M.target and (not M.paused or not w or w.address == M.target) then
|
||||
M.toggle_pause()
|
||||
elseif w then
|
||||
-- popups keep their own size
|
||||
M.attach(w, cfg.popups[w.class] ~= nil)
|
||||
end
|
||||
end
|
||||
|
||||
keys = {
|
||||
{
|
||||
"SUPER + P",
|
||||
"follow the focused window, or pause/resume",
|
||||
function()
|
||||
if M.target then
|
||||
M.toggle_pause()
|
||||
else
|
||||
local w = hl.get_active_window()
|
||||
if w then
|
||||
M.attach(w)
|
||||
end
|
||||
end
|
||||
end,
|
||||
},
|
||||
{ "SUPER + SHIFT + P", "stop following", M.detach },
|
||||
{ "SUPER + CTRL + P", "toggle a bigger window centered above the cursor", M.toggle_centered },
|
||||
{ "SUPER + ALT + space", "play/pause the video", player("play-pause") },
|
||||
{ "SUPER + ALT + left", "skip back " .. cfg.seek .. "s", player("position " .. cfg.seek .. "-"), { repeating = true } },
|
||||
{ "SUPER + ALT + right", "skip forward " .. cfg.seek .. "s", player("position " .. cfg.seek .. "+"), { repeating = true } },
|
||||
{ "SUPER + Z", "pause following; when paused, the window under the cursor follows instead", M.follow_or_pause },
|
||||
{ "SUPER + SHIFT + Z", "stop following", M.detach },
|
||||
{ "SUPER + CTRL + Z", "toggle a bigger window centered above the cursor", M.toggle_centered },
|
||||
{ "SUPER + ALT + S", "play/pause the video", player("play-pause") },
|
||||
{ "SUPER + ALT + A", "skip back " .. cfg.seek .. "s", player("position " .. cfg.seek .. "-"), { repeating = true } },
|
||||
{ "SUPER + ALT + D", "skip forward " .. cfg.seek .. "s", player("position " .. cfg.seek .. "+"), { repeating = true } },
|
||||
{
|
||||
"SUPER + ALT + up",
|
||||
"widen the gap to the cursor",
|
||||
@@ -316,8 +411,24 @@ keys = {
|
||||
end,
|
||||
{ repeating = true },
|
||||
},
|
||||
{ "SUPER + ALT + P", "show these keybindings", M.help },
|
||||
{ "SUPER + A", "ask Claude a quick question, or close the question window", M.toggle_ask },
|
||||
{
|
||||
"SUPER + ALT + right",
|
||||
"make the window bigger",
|
||||
function()
|
||||
M.scale(cfg.size_step)
|
||||
end,
|
||||
{ repeating = true },
|
||||
},
|
||||
{
|
||||
"SUPER + ALT + left",
|
||||
"make the window smaller",
|
||||
function()
|
||||
M.scale(1 / cfg.size_step)
|
||||
end,
|
||||
{ repeating = true },
|
||||
},
|
||||
{ "SUPER + ALT + Z", "show these keybindings", M.help },
|
||||
{ "SUPER + A", "pie menu of popups: hold SUPER, flick toward one, release", hl.dsp.global("kando:popups") },
|
||||
}
|
||||
|
||||
for _, k in ipairs(keys) do
|
||||
@@ -338,9 +449,15 @@ end
|
||||
if resumed then
|
||||
M.centered = hl.get_windows({ tag = centered_tag })[1] ~= nil
|
||||
M.attach(resumed, true)
|
||||
if is_ask(resumed) and asked(resumed) then
|
||||
-- popups spend most of their life with Enter already pressed
|
||||
if follow_popup(resumed) then
|
||||
M.toggle_pause()
|
||||
end
|
||||
end
|
||||
|
||||
-- the pie menu runs in the background so it opens instantly; its launcher defaults to XWayland
|
||||
hl.on("hyprland.start", function()
|
||||
hl.exec_cmd("env KANDO_OZONE_PLATFORM=wayland kando")
|
||||
end)
|
||||
|
||||
return M
|
||||
|
||||
Executable
+46
@@ -0,0 +1,46 @@
|
||||
#!/bin/bash
|
||||
# popup: open one of the popups in the SUPER+A pie menu (Kando runs `popup.sh <name>`)
|
||||
# cursor_follow.lua places each popup window beside the cursor by its class, and the keyboard
|
||||
# ones (ai, term) follow it until Enter is pressed in them.
|
||||
|
||||
kitty=(kitty -o confirm_os_window_close=0 -o window_padding_width=10)
|
||||
# aichat's config and quick role live next to this script; the API key is in ~/.config/aichat/.env
|
||||
export AICHAT_CONFIG_FILE="$HOME/.config/hypr/aichat/config.yaml"
|
||||
export AICHAT_ROLES_DIR="$HOME/.config/hypr/aichat/roles"
|
||||
|
||||
case $1 in
|
||||
ai)
|
||||
exec "${kitty[@]}" --class popup-ai -o 'map escape close_window' -e aichat
|
||||
;;
|
||||
region) # ask the AI about a dragged-out screen region
|
||||
geometry=$(slurp) || exit
|
||||
img=$(mktemp --suffix=.png)
|
||||
grim -g "$geometry" "$img" || exit
|
||||
exec "${kitty[@]}" --class popup-ai -o 'map escape close_window' -e "$0" region-chat "$img"
|
||||
;;
|
||||
region-chat) # runs inside the region popup: ask about the screenshot, then keep chatting about it
|
||||
read -e -r -p $'\001\e[36m\002about this region> \001\e[0m\002' q
|
||||
aichat --empty-session --save-session -s region -r quick -f "$2" "${q:-What is this?}"
|
||||
rm -f "$2"
|
||||
exec aichat -s region
|
||||
;;
|
||||
receipt) # the receipt printer page, served here while the Pi is down, otherwise by the website
|
||||
url=https://www.adam-french.co.uk/receipt/
|
||||
curl -sf -m 1 http://127.0.0.1:8765/healthz >/dev/null && url=http://127.0.0.1:8765/
|
||||
# Chromium names an app window's class after its URL, so cursor_follow.lua knows both of these
|
||||
exec chromium --no-first-run --no-default-browser-check --app="$url"
|
||||
;;
|
||||
sticky)
|
||||
exec hyprctl dispatch 'require("cursor_follow").toggle_sticky'
|
||||
;;
|
||||
term)
|
||||
exec "${kitty[@]}" --class popup-term
|
||||
;;
|
||||
audio)
|
||||
exec pavucontrol
|
||||
;;
|
||||
*)
|
||||
echo "usage: popup.sh ai|region|receipt|sticky|term|audio" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
Reference in New Issue
Block a user