Files
omarchycn/default/hypr/bindings/clipboard.lua
T
David Heinemeier HanssonandClaude Fable 5 a0e6d65ba8 Keep universal clipboard shortcuts working in terminals
Sending the shortcut through wtype's virtual keyboard let the physically
held SUPER merge into the injected chord, so terminals saw
SUPER+CTRL+Insert instead of CTRL+Insert, and injected CTRL+V could even
trigger the SUPER+CTRL+V clipboard manager bind. Send via send_key_state
with no window target instead: explicit mods go straight to the focused
surface, layer-shell panels included.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XnMDbwJXQA3fvW8o8Pwr97
2026-07-23 18:08:31 -07:00

49 lines
1.8 KiB
Lua

-- Send with explicit mods to the focused surface by omitting the window target,
-- so universal clipboard shortcuts reach both normal windows and focused
-- layer-shell surfaces such as Omarchy panels. A virtual keyboard (wtype) won't
-- do: the physically held SUPER merges into the injected chord at the seat.
-- The down/up split works around Hyprland send_shortcut sometimes leaving
-- synthetic key state stuck/repeating.
-- https://github.com/hyprwm/Hyprland/discussions/14099
local function send_shortcut_once(mods, key)
return function()
hl.dispatch(hl.dsp.send_key_state({ mods = mods, key = key, state = "down" }))
hl.timer(function()
hl.dispatch(hl.dsp.send_key_state({ mods = mods, key = key, state = "up" }))
end, { timeout = 50, type = "oneshot" })
end
end
local terminal_classes = {
alacritty = true,
["com.mitchellh.ghostty"] = true,
foot = true,
kitty = true,
wezterm = true,
}
local function active_window_is_terminal()
local window = hl.get_active_window()
if not window or not window.class then
return false
end
return terminal_classes[window.class:lower()] == true
end
local function universal_clipboard_shortcut(default_mods, default_key, terminal_mods, terminal_key)
return function()
if active_window_is_terminal() then
send_shortcut_once(terminal_mods, terminal_key)()
else
send_shortcut_once(default_mods, default_key)()
end
end
end
o.bind("SUPER + C", "Universal copy", universal_clipboard_shortcut("CTRL", "C", "CTRL", "Insert"))
o.bind("SUPER + V", "Universal paste", universal_clipboard_shortcut("CTRL", "V", "SHIFT", "Insert"))
o.bind("SUPER + X", "Universal cut", send_shortcut_once("CTRL", "X"))
o.bind("SUPER + CTRL + V", "Clipboard manager", "omarchy-shell shell toggle omarchy.clipboard")