76 lines
3.2 KiB
Go
76 lines
3.2 KiB
Go
// Copyright (c) 2026 Storm Dragon
|
|
// Authors: Storm Dragon, Angus Kola
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
package input
|
|
|
|
const (
|
|
OCRObject Command = "ocr-object"
|
|
OCRWindow Command = "ocr-window"
|
|
OCRDesktop Command = "ocr-desktop"
|
|
OCRClipboard Command = "ocr-clipboard"
|
|
OCRPreviousCharacter Command = "ocr-previous-character"
|
|
OCRNextCharacter Command = "ocr-next-character"
|
|
OCRPreviousWord Command = "ocr-previous-word"
|
|
OCRNextWord Command = "ocr-next-word"
|
|
OCRPreviousLine Command = "ocr-previous-line"
|
|
OCRNextLine Command = "ocr-next-line"
|
|
OCRLineStart Command = "ocr-line-start"
|
|
OCRLineEnd Command = "ocr-line-end"
|
|
OCRDocumentStart Command = "ocr-document-start"
|
|
OCRDocumentEnd Command = "ocr-document-end"
|
|
OCRPreviousPage Command = "ocr-previous-page"
|
|
OCRNextPage Command = "ocr-next-page"
|
|
OCRSelectAll Command = "ocr-select-all"
|
|
OCRCopySelection Command = "ocr-copy-selection"
|
|
OCRActivate Command = "ocr-activate"
|
|
OCRRefresh Command = "ocr-refresh"
|
|
OCRDismiss Command = "ocr-dismiss"
|
|
OCRDismissAndPass Command = "ocr-dismiss-and-pass"
|
|
)
|
|
|
|
// OCRPendingBindings claims cancellation only while capture/recognition runs.
|
|
func OCRPendingBindings(global CommandBindings) CommandBindings {
|
|
bindings := make(CommandBindings, len(global)+1)
|
|
for chord, command := range global {
|
|
bindings[chord] = command
|
|
}
|
|
bindings[CommandChord{Symbol: 0xff1b}] = OCRDismiss
|
|
return bindings
|
|
}
|
|
|
|
// OCRCommandBindings overlays the temporary document controls on configured
|
|
// global commands. It never imports browser structural bindings. Chord retains
|
|
// Shift for the future selection owner; no extra persisted binding scope exists.
|
|
func OCRCommandBindings(global CommandBindings) CommandBindings {
|
|
bindings := make(CommandBindings, len(global)+32)
|
|
for chord, command := range global {
|
|
bindings[chord] = command
|
|
}
|
|
for _, binding := range []struct {
|
|
symbol uint32
|
|
modifiers uint16
|
|
command Command
|
|
}{
|
|
{leftKeySymbol, 0, OCRPreviousCharacter}, {rightKeySymbol, 0, OCRNextCharacter},
|
|
{leftKeySymbol, controlModifier, OCRPreviousWord}, {rightKeySymbol, controlModifier, OCRNextWord},
|
|
{upKeySymbol, 0, OCRPreviousLine}, {downKeySymbol, 0, OCRNextLine},
|
|
{0xff50, 0, OCRLineStart}, {0xff57, 0, OCRLineEnd},
|
|
{0xff50, controlModifier, OCRDocumentStart}, {0xff57, controlModifier, OCRDocumentEnd},
|
|
{0xff55, 0, OCRPreviousPage}, {0xff56, 0, OCRNextPage},
|
|
} {
|
|
for _, shift := range []uint16{0, 1} {
|
|
bindings[CommandChord{Symbol: binding.symbol, Modifiers: binding.modifiers | shift}] = binding.command
|
|
}
|
|
}
|
|
bindings[CommandChord{Symbol: 'a', Modifiers: controlModifier}] = OCRSelectAll
|
|
bindings[CommandChord{Symbol: 'c', Modifiers: controlModifier}] = OCRCopySelection
|
|
bindings[CommandChord{Symbol: returnKeySymbol}] = OCRActivate
|
|
bindings[CommandChord{Symbol: ' '}] = OCRActivate
|
|
bindings[CommandChord{Symbol: 0xffc2, CthulhuModifier: true}] = OCRRefresh
|
|
bindings[CommandChord{Symbol: 0xff1b}] = OCRDismiss
|
|
bindings[CommandChord{Symbol: 0xff09}] = OCRDismissAndPass
|
|
bindings[CommandChord{Symbol: 0xff09, Modifiers: 1}] = OCRDismissAndPass
|
|
return bindings
|
|
}
|