Skip to content

Type clipboard history as keystrokes with Ctrl+Enter - #11701

Open
fabieng83 wants to merge 1 commit into
omacom:quattrofrom
fabieng83:clipboard-type-on-ctrl-enter
Open

fabieng83 wants to merge 1 commit into
omacom:quattrofrom
fabieng83:clipboard-type-on-ctrl-enter

Conversation

@fabieng83

Copy link
Copy Markdown

Summary

Enter in the clipboard manager still pastes. Ctrl+Enter types the selected text as keystrokes at ~20 characters/sec instead of pasting.

This is for fields that block paste (some password inputs, remote desktops, kiosk apps) while still accepting real keystrokes.

Typing is text-only; images keep the existing paste path.

Shortcuts (clipboard overlay)

Key Action
Enter Paste (unchanged)
Ctrl+Enter Type as keystrokes
Shift+Enter Copy only (unchanged)
Alt+Enter Open (unchanged)

How

  • omarchy-clipboard-paste-text --type copies the history entry, waits for the overlay to close, then runs wtype -d 50 - so the text is typed from stdin (newlines/quotes never hit argv).
  • The overlay also handles Ctrl+Enter in QML (Shortcut / ShortcutOverride / Control held).
  • Layer-shell surfaces often receive Ctrl+Enter as plain Enter (IME/compositor swallow Control). While the overlay is open, a compositor bind CTRL + RETURN calls omarchy.clipboard typeCurrent; it is unbound on close so Ctrl+Enter stays free in other apps.

Related open PRs (not the same feature)

Checked open PRs/issues before opening this:

None of those type the clip as keystrokes.

Testing

  • bash test/shell.d/clipboard-test.sh passes, including new --type helper assertions and QML wiring checks.
  • ./test/all: clipboard tests pass. Unrelated failures on this machine: config-test.sh, launch-about-test.sh, locate-test.sh, runtime-smoke-test.sh, snapper-test.sh, unowned-system-paths-test.sh (missing omarchy-pkgs / compositor IPC counts).
  • Lived on Hyprland: Super+Ctrl+V, Ctrl+Enter types into the previously focused window after a short delay.

Docs

manual/08-unified-clipboard-history.md lists the overlay keys.

Enter still pastes. Ctrl+Enter types the selected text through wtype
at ~20 characters/sec, which is useful when paste is blocked.

Layer-shell overlays often see Ctrl+Enter as plain Enter, so the
picker also installs a compositor bind while it is open.
@llstrk

llstrk commented Oct 1, 2026

Copy link
Copy Markdown

Automated AI review

Community review: Independent automated community review, unaffiliated with the Omarchy team, intended to help prepare PRs for their review.

Outcome: The helper now strips trailing newlines from every history paste and copy, not only typing.

Return and Shift+Return lose trailing newlines

text=$(jq -j ...) drops trailing newlines and NUL bytes before wl-copy on every --history-index path. Impact: echo hi\n is now pasted or copied as echo hi.

Suggested change: keep the direct jq -j ... | wl-copy pipe and read text only for --type.

Reproducer (fails at 4e18ce8)

Reviewed head: 4e18ce8. Base for comparison: 692c02c (merge base).

Cause: copy_history_entry now reads the entry with text=$(jq -j ...) and copies printf '%s' "$text" | wl-copy. Command substitution strips every trailing newline and bash drops NUL bytes, so the bytes put on the clipboard by the existing paste (--shift-insert --history-index) and copy (--copy-only --history-index) paths change. The base piped jq -j ... | wl-copy directly.

Test (append to test/shell.d/clipboard-test.sh, after the existing helper tests)

It uses the file's own wl-copy/wtype stubs and $TMPDIR layout.

# Return and Shift+Return put the history entry on the clipboard byte for
# byte, including its trailing newline.
jq -n '[{type:"text", text:"echo hi\n"}]' >"$TMPDIR/home/.local/state/omarchy/clipboard-history.json"
for flag in --shift-insert --copy-only; do
  rm -f "$TMPDIR/copied"
  WL_COPY_OUT="$TMPDIR/copied" WTYPE_OUT="$TMPDIR/wtype" HOME="$TMPDIR/home" PATH="$TMPDIR/bin:$PATH" \
    "$ROOT/bin/omarchy-clipboard-paste-text" "$flag" --history-index 0
  cmp -s "$TMPDIR/copied" <(printf 'echo hi\n') ||
    fail "clipboard paste helper $flag keeps the entry's trailing newline" "copied bytes: $(od -An -c "$TMPDIR/copied")"
  pass "clipboard paste helper $flag keeps the entry's trailing newline"
done

Run: bash test/shell.d/clipboard-test.sh

Actual output

At the PR head (last lines; exit 1):

ok - clipboard open helper opens image entries in Tensaku
copied bytes:    e   c   h   o       h   i
not ok - clipboard paste helper --shift-insert keeps the entry's trailing newline

At the merge base (exit 0):

ok - clipboard paste helper --shift-insert keeps the entry's trailing newline
ok - clipboard paste helper --copy-only keeps the entry's trailing newline

The PR head merged into current quattro fails the same way. With the head helper changed to keep the direct pipe for the copy and read the text separately only for --type (below), the whole file passes, including the PR's new --type assertions:

-  text=$(jq -j --argjson index "$history_index" '.[$index].text' "$history_path")
-  printf '%s' "$text" | wl-copy
+  jq -j --argjson index "$history_index" '.[$index].text' "$history_path" | wl-copy
+  if [[ $type_keys == "true" ]]; then
+    text=$(jq -j --argjson index "$history_index" '.[$index].text' "$history_path")
+  fi

Byte-level comparison (helper run with recording stubs, same history entry)

Entry text (JSON) Mode Base wl-copy bytes Head wl-copy bytes
"echo hi\n" --shift-insert --history-index 0 65 63 68 6f 20 68 69 0a 65 63 68 6f 20 68 69
"echo hi\n" --copy-only --history-index 0 65 63 68 6f 20 68 69 0a 65 63 68 6f 20 68 69
"a\n\n\n" --copy-only --history-index 0 61 0a 0a 0a 61
"foo<NUL>bar" --copy-only --history-index 0 66 6f 6f 00 62 61 72 66 6f 6f 62 61 72 (stderr: warning: command substitution: ignored null byte in input)
"line one\r\nline two\r\n" --copy-only --history-index 0 ... 74 77 6f 0d 0a ... 74 77 6f 0d

(<NUL> stands for the JSON escape for U+0000.) The existing assertions cannot see this: the fixture entry is built with "$(printf '...\n')" (already stripped) and compared with $(<file) (strips again).

Closing the overlay removes user Ctrl+Return binds

hl.unbind("CTRL + RETURN") removes every bind spelled CTRL + RETURN in Hyprland 0.56.2 and main (from source, not run). Impact: a user's own such bind is lost on the first close until a config reload; after a shell crash while open, Ctrl+Return stays captured until the next open and close.

Suggested change: create one disabled bind in Lua config and toggle it with set_enabled (see Details).

More findings: overlay state after Ctrl+Return, rebase onto current quattro

Ctrl+Return leaves overlay state set for the next open

Ctrl+Return hides the overlay with opened = false, bypassing close(), so ctrlHeld and clearConfirmOpen survive, and typeCurrent() ignores the delete confirmation. Impact: a later Return or Shift+Return can type instead of paste or copy, and Ctrl+Return during "Delete entire clipboard history?" types the entry and leaves that dialog armed.

Suggested change: reset both flags when opened becomes false and return early from typeCurrent() while clearConfirmOpen is set.

The bare IpcHandler fails shell-ipc-socket-test.sh after a merge with quattro

quattro now requires first-party IPC handlers to use ShellIpc (#13435). Merged into the current tip, the PR's IpcHandler makes test/shell.d/shell-ipc-socket-test.sh fail; it still works at runtime through the slower qs ipc fallback. Impact: an existing test fails after the merge, which is otherwise conflict-free.

Suggested change: declare the handler as ShellIpc { target: "omarchy.clipboard"; ... } when rebasing; the PR's own assertion still matches.

Reproducer: Control state (fails at 4e18ce8, headless QML harness)

Reviewed head: 4e18ce8.

Cause: Keys.onPressed sets ctrlHeld = true on the Control press and only Keys.onReleased (or close()) clears it. Ctrl+Return hides the overlay through typeSelected(), which sets root.opened = false directly and does not go through close(). If Control is still held when the overlay hides (the usual case), the release goes to the window that regains focus. open() does not reset the flag. On the next open, wantsType() returns true for any Return, and the Return branch checks wantsType before Shift, so Return and Shift+Return both call --type.

When it shows: the next open gets no Control release, for example via omarchy menu clipboard, a user binding without Ctrl, or a quick Super+Ctrl+V tap that is released before the overlay has focus. Escape, a click outside the card, or Super+Ctrl+V to close go through close() and clear it.

Harness

Headless Qt Quick Test (qmltestrunner, QT_QPA_PLATFORM=offscreen, Qt 6.11.2) loading the PR's Clipboard.qml and ClipboardHistory.js unchanged except for removing the four PanelWindow lines that only exist under Quickshell (anchors { top: true; ... } and three WlrLayershell.* attached properties). Quickshell, Quickshell.Io, qs.Commons and qs.Ui are test doubles: Quickshell.execDetached records argv instead of running anything, PanelWindow is a plain Item, ConfirmDialog.handleKey is copied verbatim. Key events are sent with QtTest's keyPress/keyClick.

The test models the PR's main path: the overlay receives the Control press, Return is consumed by the compositor CTRL + RETURN bind, which calls typeCurrent() over IPC.

function test_08_return_after_compositor_ctrl_return_pastes() {
  openWithHistory()                       // two text entries, c.open("{}")
  keyPress(Qt.Key_Control)                // Control reaches the overlay
  compare(c.typeCurrent(), "ok")          // Return taken by the compositor bind
  compare(helperLog()[0], "--type --history-index 0")

  Quickshell.reset()
  c.open("{}"); wait(50)                  // reopened without a Control key event
  keyClick(Qt.Key_Return, Qt.ShiftModifier)
  compare(helperLog()[0], "--copy-only --history-index 0", "Shift+Return copies on the next open")
}

(helperLog() lists the arguments of every recorded omarchy-clipboard-* helper call.)

Actual output at the PR head

QDEBUG : qmltestrunner::ClipboardTypeKeys::test_08_return_after_compositor_ctrl_return_pastes() qml: OBSERVED Shift+Return on next open: ["--type --history-index 0"]
FAIL!  : qmltestrunner::ClipboardTypeKeys::test_08_return_after_compositor_ctrl_return_pastes() Shift+Return copies on the next open
   Actual   (): --type --history-index 0
   Expected (): --copy-only --history-index 0

The same test with a plain keyClick(Qt.Key_Return) on the next open (expecting the paste call):

QDEBUG : qmltestrunner::ClipboardTypeKeys::test_08b_plain_return_after_compositor_ctrl_return_pastes() qml: OBSERVED plain Return on next open (compositor path): ["--type --history-index 0"]
FAIL!  : qmltestrunner::ClipboardTypeKeys::test_08b_plain_return_after_compositor_ctrl_return_pastes() plain Return pastes on the next open
   Actual   (): --type --history-index 0
   Expected (): --shift-insert --history-index 0

Same results with the PR merged into current quattro (where the overlay is an OverlayWindow).

With ctrlHeld (and clearConfirmOpen) reset when opened becomes false, both pass:

QDEBUG : qmltestrunner::ClipboardTypeKeys::test_08_return_after_compositor_ctrl_return_pastes() qml: OBSERVED Shift+Return on next open: ["--copy-only --history-index 0"]
PASS   : qmltestrunner::ClipboardTypeKeys::test_08_return_after_compositor_ctrl_return_pastes()
QDEBUG : qmltestrunner::ClipboardTypeKeys::test_08b_plain_return_after_compositor_ctrl_return_pastes() qml: OBSERVED plain Return on next open (compositor path): ["--shift-insert --history-index 0"]
PASS   : qmltestrunner::ClipboardTypeKeys::test_08b_plain_return_after_compositor_ctrl_return_pastes()

Candidate change used for that run:

-  onOpenedChanged: root.setTypeBind(root.opened)
+  onOpenedChanged: {
+    if (!root.opened) {
+      root.ctrlHeld = false
+      root.clearConfirmOpen = false
+    }
+    root.setTypeBind(root.opened)
+  }

Limit: the harness cannot model the compositor moving keyboard focus away (in the harness, a hidden item still receives key events), so the "Control release is not delivered" step is represented by not sending it. The test does not run Hyprland or Quickshell.

Reproducer: delete confirmation (fails at 4e18ce8, headless QML harness)

Reviewed head: 4e18ce8.

Cause: while the overlay is open the compositor CTRL + RETURN bind is active, so Ctrl+Return never reaches QML; it calls typeCurrent() over IPC. typeCurrent() checks opened and the row count but not clearConfirmOpen (the PR's Shortcut is disabled while the confirmation is open, the IPC path is not). typeSelected() hides the overlay with root.opened = false, which skips close() and therefore cancelClearHistory(). open() does not reset clearConfirmOpen, so the next open shows the confirmation again with Delete preselected (requestClearHistory() sets selectedIndex = 1).

Harness

Same headless Qt Quick Test harness as the Control-state reproducer: the PR's Clipboard.qml with Quickshell-only PanelWindow lines removed, test doubles for Quickshell, Quickshell.Io, qs.Commons, qs.Ui (ConfirmDialog.handleKey copied verbatim), Quickshell.execDetached recording argv only.

function test_09_ctrl_return_in_clear_confirm() {
  openWithHistory()                             // two text entries, c.open("{}")
  keyClick(Qt.Key_Delete, Qt.ShiftModifier)     // "Delete entire clipboard history?"
  compare(c.clearConfirmOpen, true)
  var result = c.typeCurrent()                  // Ctrl+Return, taken by the compositor bind
  var typedDuringConfirm = helperLog().length
  if (!c.opened) {
    c.open("{}"); wait(50)                      // next normal open
    keyClick(Qt.Key_Return)
  }
  compare(typedDuringConfirm, 0, "Ctrl+Return does not type while the delete confirmation is open")
  compare(c.history.length, 2, "history survives")
}

Actual output at the PR head

QDEBUG : qmltestrunner::ClipboardTypeKeys::test_09_ctrl_return_in_clear_confirm() qml: OBSERVED typeCurrent during confirm: ok ["--type --history-index 0"] opened=false clearConfirmOpen=true
QDEBUG : qmltestrunner::ClipboardTypeKeys::test_09_ctrl_return_in_clear_confirm() qml: OBSERVED next open: clearConfirmOpen=true
QDEBUG : qmltestrunner::ClipboardTypeKeys::test_09_ctrl_return_in_clear_confirm() qml: OBSERVED after Return on next open: history length=0 ["--type --history-index 0"]
FAIL!  : qmltestrunner::ClipboardTypeKeys::test_09_ctrl_return_in_clear_confirm() Ctrl+Return does not type while the delete confirmation is open
   Actual   (): 1
   Expected (): 0

So the entry is typed into the previously focused window while the modal confirmation is showing, the confirmation is still open on the next launch, and a plain Return there clears the whole history. Same result with the PR merged into current quattro.

With if (root.clearConfirmOpen) return "confirming" in typeCurrent() (plus resetting clearConfirmOpen when opened becomes false), the test passes:

QDEBUG : qmltestrunner::ClipboardTypeKeys::test_09_ctrl_return_in_clear_confirm() qml: OBSERVED typeCurrent during confirm: confirming [] opened=true clearConfirmOpen=true
PASS   : qmltestrunner::ClipboardTypeKeys::test_09_ctrl_return_in_clear_confirm()

Limit: the compositor bind is represented by calling typeCurrent() directly; Hyprland and Quickshell IPC are not run. That Hyprland consumes a matching bind's key press (so QML does not also see it) is from Hyprland source (CKeybindManager::handleKeybinds: a non-non_consuming bind sets found = true, so the event is not passed to the client).

Reproducer: rebase onto quattro (fails on the merge)

Reviewed head: 4e18ce8. quattro tip: 8b4eae6.

quattro gained shell/Commons/ShellIpc.qml (an IpcHandler that also registers with IpcRegistry, so omarchy-shell can answer over the shell's own socket, #13435) and a test that every first-party handler uses it. The PR adds a bare IpcHandler { target: "omarchy.clipboard" ... } to shell/plugins/clipboard/Clipboard.qml. The merge is textually clean.

Steps

(Not run as written: the review built the equivalent clean merge in its own clone and ran the test there.)

git fetch origin quattro pull/11701/head:pr-11701
git checkout --detach origin/quattro
git merge --no-edit pr-11701          # merges without conflicts
bash test/shell.d/shell-ipc-socket-test.sh

Actual output (last lines; exit 1)

ok - a stale socket with nothing listening falls back to qs ipc
ok - without the socket calls go through qs ipc
ok - a call for another display does not reach this shell's socket
expected: ["shell/Commons/IpcRegistry.qml","shell/Commons/ShellIpc.qml"]
actual:   ["shell/Commons/IpcRegistry.qml","shell/Commons/ShellIpc.qml","shell/plugins/clipboard/Clipboard.qml"]
not ok - first-party IPC handlers register through ShellIpc

The same test passes on quattro alone. test/shell.d/clipboard-test.sh (including the PR's six new assertions) passes on the merge.

Fix on rebase: declare the handler as ShellIpc { target: "omarchy.clipboard"; function typeCurrent(): string { ... } }. The PR's own assertion (target: "omarchy.clipboard"[\s\S]*function typeCurrent\(\): string) still matches.

Details

Ctrl+Return bind mechanism. In Hyprland 0.56.2 hlUnbind calls CKeybindManager::removeKeybind(displayKeys), which erases every bind whose normalized display key matches, across submaps; Hyprland main does the same through removeByDisplayKey. While the overlay is open, a user's own Ctrl+Return bind also fires (0.56.2). default/hypr/bindings/utilities.lua (lines 48-49) already warns about unbinding by key. On 0.56.2 even a kept handle's remove() erases by modifier and key, so a disabled bind toggled with set_enabled is safer. Sketch (source-checked against 0.56.2 and main, not run):

omarchy_clipboard_type_bind = hl.bind("CTRL + RETURN", hl.dsp.exec_cmd("omarchy-shell -q omarchy.clipboard typeCurrent"), { description = "Type clipboard entry" })
omarchy_clipboard_type_bind:set_enabled(false)

QML then runs hyprctl eval 'omarchy_clipboard_type_bind:set_enabled(true)' on open and (false) on close. Disabled binds are skipped without consuming the key, and a config reload recreates the bind disabled.

Verified

  • wtype -d 50 - types from stdin with a 50 ms delay (about 18 characters per second); leading-dash and non-ASCII text stays off argv.
  • Invalid indexes (abc, -1, 99) exit without copying; empty text types nothing; --copy-only takes precedence over --type.
  • In the headless QML harness, Return pastes, Shift+Return copies, Ctrl+Return types once, typeCurrent follows the highlighted row, and bind and unbind pair up on Escape, paste, type and shell reload.
  • The PR's clipboard tests pass at the head and merged into current quattro.

Optional test improvements

  • The "Ctrl+Enter types the selected entry" assertion still passes when the Return branch calls activateIndex, because [\s\S]* reaches the Shortcut's typeIndex; anchor it to the Keys branch.
  • The wtype stub records only argv, so the new test still passes when the helper sends empty stdin; record stdin and compare the typed bytes.

Untested: whether Control still held after the 0.3 s delay alters the first typed characters needs a real compositor run.

Related open PRs: #8350, #12801, #12991, #13103 and #11920 conflict in bin/omarchy-clipboard-paste-text; #7452, #10919, #13103 and #11920 conflict in Clipboard.qml. #12991 and #13103 refocus the origin window before pasting, which typing would also need.


Review information

Test scope: Source, sandboxed shell tests and a headless QML harness at 4e18ce8; Hyprland and Quickshell not run.

AI process: Opus 5.5 Medium coordination and synthesis, Opus 5.5 Xhigh technical review and final fact check, GPT 6 Sol Xhigh search for related issues, Opus 5.5 Medium editorial check.

Opt out: To stop receiving these reviews, reply to this comment saying so.

@jandrusk

Copy link
Copy Markdown

Two things on the current head (4e18ce8, unchanged since the review above):

  1. Still strips trailing newlines from every history paste/copy. text=$(jq -j …) runs on every --history-index path, not just --type, so echo hi⏎ now pastes as echo hi. Keep the original pipe for the copy, and read the text (with a sentinel) only when typing:
jq -j --argjson index "$history_index" '.[$index].text' "$history_path" | wl-copy
if [[ $type_keys == "true" ]]; then
  text=$(jq -j --argjson index "$history_index" '.[$index].text' "$history_path"; printf x)
  text=${text%x}
fi
  1. Typed newlines press Enter. With wtype -, any newline in the entry becomes a Return keystroke, so typing a multi-line history item into a terminal runs each line as a command. That's different from paste, where most shells use bracketed paste. Consider refusing --type for multi-line entries, or stopping at the first newline with a notification.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants