io/input,io/key: [API] replace SoftKeyboardOp with a command

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2023-10-09 16:37:21 -05:00
parent be36fc88aa
commit 5dd41f74d3
6 changed files with 18 additions and 34 deletions
+7 -7
View File
@@ -37,7 +37,7 @@ func TestKeyMultiples(t *testing.T) {
ops := new(op.Ops)
r := new(Router)
key.SoftKeyboardOp{Show: true}.Add(ops)
r.Source().Queue(key.SoftKeyboardCmd{Show: true})
key.InputOp{Tag: &handlers[0]}.Add(ops)
r.Source().Queue(key.FocusCmd{Tag: &handlers[2]})
key.InputOp{Tag: &handlers[1]}.Add(ops)
@@ -61,11 +61,11 @@ func TestKeyStacked(t *testing.T) {
key.InputOp{Tag: &handlers[0]}.Add(ops)
r.Source().Queue(key.FocusCmd{})
key.SoftKeyboardOp{Show: false}.Add(ops)
r.Source().Queue(key.SoftKeyboardCmd{Show: false})
key.InputOp{Tag: &handlers[1]}.Add(ops)
r.Source().Queue(key.FocusCmd{Tag: &handlers[1]})
key.InputOp{Tag: &handlers[2]}.Add(ops)
key.SoftKeyboardOp{Show: true}.Add(ops)
r.Source().Queue(key.SoftKeyboardCmd{Show: true})
key.InputOp{Tag: &handlers[3]}.Add(ops)
r.Frame(ops)
@@ -84,7 +84,7 @@ func TestKeySoftKeyboardNoFocus(t *testing.T) {
// It's possible to open the keyboard
// without any active focus:
key.SoftKeyboardOp{Show: true}.Add(ops)
r.Source().Queue(key.SoftKeyboardCmd{Show: true})
r.Frame(ops)
@@ -100,7 +100,7 @@ func TestKeyRemoveFocus(t *testing.T) {
// New InputOp with Focus and Keyboard:
key.InputOp{Tag: &handlers[0], Keys: "Short-Tab"}.Add(ops)
r.Source().Queue(key.FocusCmd{Tag: &handlers[0]})
key.SoftKeyboardOp{Show: true}.Add(ops)
r.Source().Queue(key.SoftKeyboardCmd{Show: true})
// New InputOp without any focus:
key.InputOp{Tag: &handlers[1], Keys: "Short-Tab"}.Add(ops)
@@ -152,7 +152,7 @@ func TestKeyRemoveFocus(t *testing.T) {
// exists in the previous frame:
r.Source().Queue(key.FocusCmd{Tag: &handlers[0]})
key.InputOp{Tag: &handlers[0]}.Add(ops)
key.SoftKeyboardOp{Show: true}.Add(ops)
r.Source().Queue(key.SoftKeyboardCmd{Show: true})
// Remove focus.
key.InputOp{Tag: &handlers[1]}.Add(ops)
@@ -173,7 +173,7 @@ func TestKeyFocusedInvisible(t *testing.T) {
// Set new InputOp with focus:
r.Source().Queue(key.FocusCmd{Tag: &handlers[0]})
key.InputOp{Tag: &handlers[0]}.Add(ops)
key.SoftKeyboardOp{Show: true}.Add(ops)
r.Source().Queue(key.SoftKeyboardCmd{Show: true})
// Set new InputOp without focus:
key.InputOp{Tag: &handlers[1]}.Add(ops)
+2 -5
View File
@@ -216,6 +216,8 @@ func (q *Router) executeCommands() {
switch req := req.(type) {
case key.FocusCmd:
q.key.queue.Focus(req.Tag, &q.handlers)
case key.SoftKeyboardCmd:
q.key.queue.softKeyboard(req.Show)
}
}
q.commands = nil
@@ -504,11 +506,6 @@ func (q *Router) collect() {
act := system.Action(encOp.Data[1])
pc.actionInputOp(act)
case ops.TypeKeySoftKeyboard:
op := key.SoftKeyboardOp{
Show: encOp.Data[1] != 0,
}
kq.softKeyboard(op.Show)
case ops.TypeKeyInput:
filter := key.Set(*encOp.Refs[1].(*string))
op := key.InputOp{
+7 -15
View File
@@ -34,6 +34,11 @@ type InputOp struct {
Keys Set
}
// SoftKeyboardCmd shows or hides the on-screen keyboard, if available.
type SoftKeyboardCmd struct {
Show bool
}
// Set is an expression that describes a set of key combinations, in the form
// "<modifiers>-<keyset>|...". Modifiers are separated by dashes, optional
// modifiers are enclosed by parentheses. A key set is either a literal key
@@ -50,12 +55,6 @@ type InputOp struct {
// - Shift-(Ctrl)-A matches A if shift is pressed, and optionally ctrl.
type Set string
// SoftKeyboardOp shows or hide the on-screen keyboard, if available.
// It replaces any previous SoftKeyboardOp.
type SoftKeyboardOp struct {
Show bool
}
// SelectionOp updates the selection for an input handler.
type SelectionOp struct {
Tag event.Tag
@@ -337,14 +336,6 @@ func (h InputOp) Add(o *op.Ops) {
data[1] = byte(h.Hint)
}
func (h SoftKeyboardOp) Add(o *op.Ops) {
data := ops.Write(&o.Internal, ops.TypeKeySoftKeyboardLen)
data[0] = byte(ops.TypeKeySoftKeyboard)
if h.Show {
data[1] = 1
}
}
func (s SnippetOp) Add(o *op.Ops) {
data := ops.Write2String(&o.Internal, ops.TypeSnippetLen, s.Tag, s.Text)
data[0] = byte(ops.TypeSnippet)
@@ -371,7 +362,8 @@ func (FocusEvent) ImplementsEvent() {}
func (SnippetEvent) ImplementsEvent() {}
func (SelectionEvent) ImplementsEvent() {}
func (FocusCmd) ImplementsCommand() {}
func (FocusCmd) ImplementsCommand() {}
func (SoftKeyboardCmd) ImplementsCommand() {}
func (m Modifiers) String() string {
var strs []string