1
0
Fork 0

Adding upstream version 0.0~git20250520.a1d9079+dfsg.

Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
Daniel Baumann 2025-05-24 19:46:29 +02:00
parent 590ac7ff5f
commit 20149b7f3a
Signed by: daniel
GPG key ID: FBB4F0E80A80222F
456 changed files with 70406 additions and 0 deletions

60
event/key/code_string.go Normal file
View file

@ -0,0 +1,60 @@
// Code generated by "stringer -type=Code"; DO NOT EDIT
package key
import "fmt"
const (
_Code_name_0 = "CodeUnknown"
_Code_name_1 = "CodeACodeBCodeCCodeDCodeECodeFCodeGCodeHCodeICodeJCodeKCodeLCodeMCodeNCodeOCodePCodeQCodeRCodeSCodeTCodeUCodeVCodeWCodeXCodeYCodeZCode1Code2Code3Code4Code5Code6Code7Code8Code9Code0CodeReturnEnterCodeEscapeCodeDeleteBackspaceCodeTabCodeSpacebarCodeHyphenMinusCodeEqualSignCodeLeftSquareBracketCodeRightSquareBracketCodeBackslash"
_Code_name_2 = "CodeSemicolonCodeApostropheCodeGraveAccentCodeCommaCodeFullStopCodeSlashCodeCapsLockCodeF1CodeF2CodeF3CodeF4CodeF5CodeF6CodeF7CodeF8CodeF9CodeF10CodeF11CodeF12"
_Code_name_3 = "CodePauseCodeInsertCodeHomeCodePageUpCodeDeleteForwardCodeEndCodePageDownCodeRightArrowCodeLeftArrowCodeDownArrowCodeUpArrowCodeKeypadNumLockCodeKeypadSlashCodeKeypadAsteriskCodeKeypadHyphenMinusCodeKeypadPlusSignCodeKeypadEnterCodeKeypad1CodeKeypad2CodeKeypad3CodeKeypad4CodeKeypad5CodeKeypad6CodeKeypad7CodeKeypad8CodeKeypad9CodeKeypad0CodeKeypadFullStop"
_Code_name_4 = "CodeKeypadEqualSignCodeF13CodeF14CodeF15CodeF16CodeF17CodeF18CodeF19CodeF20CodeF21CodeF22CodeF23CodeF24"
_Code_name_5 = "CodeHelp"
_Code_name_6 = "CodeMuteCodeVolumeUpCodeVolumeDown"
_Code_name_7 = "CodeLeftControlCodeLeftShiftCodeLeftAltCodeLeftGUICodeRightControlCodeRightShiftCodeRightAltCodeRightGUI"
_Code_name_8 = "CodeCompose"
)
var (
_Code_index_0 = [...]uint8{0, 11}
_Code_index_1 = [...]uint16{0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100, 105, 110, 115, 120, 125, 130, 135, 140, 145, 150, 155, 160, 165, 170, 175, 180, 195, 205, 224, 231, 243, 258, 271, 292, 314, 327}
_Code_index_2 = [...]uint8{0, 13, 27, 42, 51, 63, 72, 84, 90, 96, 102, 108, 114, 120, 126, 132, 138, 145, 152, 159}
_Code_index_3 = [...]uint16{0, 9, 19, 27, 37, 54, 61, 73, 87, 100, 113, 124, 141, 156, 174, 195, 213, 228, 239, 250, 261, 272, 283, 294, 305, 316, 327, 338, 356}
_Code_index_4 = [...]uint8{0, 19, 26, 33, 40, 47, 54, 61, 68, 75, 82, 89, 96, 103}
_Code_index_5 = [...]uint8{0, 8}
_Code_index_6 = [...]uint8{0, 8, 20, 34}
_Code_index_7 = [...]uint8{0, 15, 28, 39, 50, 66, 80, 92, 104}
_Code_index_8 = [...]uint8{0, 11}
)
func (i Code) String() string {
switch {
case i == 0:
return _Code_name_0
case 4 <= i && i <= 49:
i -= 4
return _Code_name_1[_Code_index_1[i]:_Code_index_1[i+1]]
case 51 <= i && i <= 69:
i -= 51
return _Code_name_2[_Code_index_2[i]:_Code_index_2[i+1]]
case 72 <= i && i <= 99:
i -= 72
return _Code_name_3[_Code_index_3[i]:_Code_index_3[i+1]]
case 103 <= i && i <= 115:
i -= 103
return _Code_name_4[_Code_index_4[i]:_Code_index_4[i+1]]
case i == 117:
return _Code_name_5
case 127 <= i && i <= 129:
i -= 127
return _Code_name_6[_Code_index_6[i]:_Code_index_6[i+1]]
case 224 <= i && i <= 231:
i -= 224
return _Code_name_7[_Code_index_7[i]:_Code_index_7[i+1]]
case i == 65536:
return _Code_name_8
default:
return fmt.Sprintf("Code(%d)", i)
}
}

270
event/key/key.go Normal file
View file

@ -0,0 +1,270 @@
// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:generate stringer -type=Code
// Package key defines an event for physical keyboard keys.
//
// On-screen software keyboards do not send key events.
//
// See the golang.org/x/mobile/app package for details on the event model.
package key
import (
"fmt"
"strings"
)
// Event is a key event.
type Event struct {
// Rune is the meaning of the key event as determined by the
// operating system. The mapping is determined by system-dependent
// current layout, modifiers, lock-states, etc.
//
// If non-negative, it is a Unicode codepoint: pressing the 'a' key
// generates different Runes 'a' or 'A' (but the same Code) depending on
// the state of the shift key.
//
// If -1, the key does not generate a Unicode codepoint. To distinguish
// them, look at Code.
Rune rune
// Code is the identity of the physical key relative to a notional
// "standard" keyboard, independent of current layout, modifiers,
// lock-states, etc
//
// For standard key codes, its value matches USB HID key codes.
// Compare its value to uint32-typed constants in this package, such
// as CodeLeftShift and CodeEscape.
//
// Pressing the regular '2' key and number-pad '2' key (with Num-Lock)
// generate different Codes (but the same Rune).
Code Code
// Modifiers is a bitmask representing a set of modifier keys: ModShift,
// ModAlt, etc.
Modifiers Modifiers
// Direction is the direction of the key event: DirPress, DirRelease,
// or DirNone (for key repeats).
Direction Direction
// TODO: add a Device ID, for multiple input devices?
// TODO: add a time.Time?
}
func (e Event) String() string {
if e.Rune >= 0 {
return fmt.Sprintf("key.Event{%q (%v), %v, %v}", e.Rune, e.Code, e.Modifiers, e.Direction)
}
return fmt.Sprintf("key.Event{(%v), %v, %v}", e.Code, e.Modifiers, e.Direction)
}
// Direction is the direction of the key event.
type Direction uint8
const (
DirNone Direction = 0
DirPress Direction = 1
DirRelease Direction = 2
)
// Modifiers is a bitmask representing a set of modifier keys.
type Modifiers uint32
const (
ModShift Modifiers = 1 << 0
ModControl Modifiers = 1 << 1
ModAlt Modifiers = 1 << 2
ModMeta Modifiers = 1 << 3 // called "Command" on OS X
)
// Code is the identity of a key relative to a notional "standard" keyboard.
type Code uint32
// Physical key codes.
//
// For standard key codes, its value matches USB HID key codes.
// TODO: add missing codes.
const (
CodeUnknown Code = 0
CodeA Code = 4
CodeB Code = 5
CodeC Code = 6
CodeD Code = 7
CodeE Code = 8
CodeF Code = 9
CodeG Code = 10
CodeH Code = 11
CodeI Code = 12
CodeJ Code = 13
CodeK Code = 14
CodeL Code = 15
CodeM Code = 16
CodeN Code = 17
CodeO Code = 18
CodeP Code = 19
CodeQ Code = 20
CodeR Code = 21
CodeS Code = 22
CodeT Code = 23
CodeU Code = 24
CodeV Code = 25
CodeW Code = 26
CodeX Code = 27
CodeY Code = 28
CodeZ Code = 29
Code1 Code = 30
Code2 Code = 31
Code3 Code = 32
Code4 Code = 33
Code5 Code = 34
Code6 Code = 35
Code7 Code = 36
Code8 Code = 37
Code9 Code = 38
Code0 Code = 39
CodeReturnEnter Code = 40
CodeEscape Code = 41
CodeDeleteBackspace Code = 42
CodeTab Code = 43
CodeSpacebar Code = 44
CodeHyphenMinus Code = 45 // -
CodeEqualSign Code = 46 // =
CodeLeftSquareBracket Code = 47 // [
CodeRightSquareBracket Code = 48 // ]
CodeBackslash Code = 49 // \
CodeSemicolon Code = 51 // ;
CodeApostrophe Code = 52 // '
CodeGraveAccent Code = 53 // `
CodeComma Code = 54 // ,
CodeFullStop Code = 55 // .
CodeSlash Code = 56 // /
CodeCapsLock Code = 57
CodeF1 Code = 58
CodeF2 Code = 59
CodeF3 Code = 60
CodeF4 Code = 61
CodeF5 Code = 62
CodeF6 Code = 63
CodeF7 Code = 64
CodeF8 Code = 65
CodeF9 Code = 66
CodeF10 Code = 67
CodeF11 Code = 68
CodeF12 Code = 69
CodePause Code = 72
CodeInsert Code = 73
CodeHome Code = 74
CodePageUp Code = 75
CodeDeleteForward Code = 76
CodeEnd Code = 77
CodePageDown Code = 78
CodeRightArrow Code = 79
CodeLeftArrow Code = 80
CodeDownArrow Code = 81
CodeUpArrow Code = 82
CodeKeypadNumLock Code = 83
CodeKeypadSlash Code = 84 // /
CodeKeypadAsterisk Code = 85 // *
CodeKeypadHyphenMinus Code = 86 // -
CodeKeypadPlusSign Code = 87 // +
CodeKeypadEnter Code = 88
CodeKeypad1 Code = 89
CodeKeypad2 Code = 90
CodeKeypad3 Code = 91
CodeKeypad4 Code = 92
CodeKeypad5 Code = 93
CodeKeypad6 Code = 94
CodeKeypad7 Code = 95
CodeKeypad8 Code = 96
CodeKeypad9 Code = 97
CodeKeypad0 Code = 98
CodeKeypadFullStop Code = 99 // .
CodeKeypadEqualSign Code = 103 // =
CodeF13 Code = 104
CodeF14 Code = 105
CodeF15 Code = 106
CodeF16 Code = 107
CodeF17 Code = 108
CodeF18 Code = 109
CodeF19 Code = 110
CodeF20 Code = 111
CodeF21 Code = 112
CodeF22 Code = 113
CodeF23 Code = 114
CodeF24 Code = 115
CodeHelp Code = 117
CodeMute Code = 127
CodeVolumeUp Code = 128
CodeVolumeDown Code = 129
CodeLeftControl Code = 224
CodeLeftShift Code = 225
CodeLeftAlt Code = 226
CodeLeftGUI Code = 227
CodeRightControl Code = 228
CodeRightShift Code = 229
CodeRightAlt Code = 230
CodeRightGUI Code = 231
// The following codes are not part of the standard USB HID Usage IDs for
// keyboards. See http://www.usb.org/developers/hidpage/Hut1_12v2.pdf
//
// Usage IDs are uint16s, so these non-standard values start at 0x10000.
// CodeCompose is the Code for a compose key, sometimes called a multi key,
// used to input non-ASCII characters such as ñ being composed of n and ~.
//
// See https://en.wikipedia.org/wiki/Compose_key
CodeCompose Code = 0x10000
)
// TODO: Given we use runes outside the unicode space, should we provide a
// printing function? Related: it's a little unfortunate that printing a
// key.Event with %v gives not very readable output like:
// {100 7 key.Modifiers() Press}
var mods = [...]struct {
m Modifiers
s string
}{
{ModShift, "Shift"},
{ModControl, "Control"},
{ModAlt, "Alt"},
{ModMeta, "Meta"},
}
func (m Modifiers) String() string {
var match []string
for _, mod := range mods {
if mod.m&m != 0 {
match = append(match, mod.s)
}
}
return "key.Modifiers(" + strings.Join(match, "|") + ")"
}
func (d Direction) String() string {
switch d {
case DirNone:
return "None"
case DirPress:
return "Press"
case DirRelease:
return "Release"
default:
return fmt.Sprintf("key.Direction(%d)", d)
}
}

View file

@ -0,0 +1,136 @@
// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Package lifecycle defines an event for an app's lifecycle.
//
// The app lifecycle consists of moving back and forth between an ordered
// sequence of stages. For example, being at a stage greater than or equal to
// StageVisible means that the app is visible on the screen.
//
// A lifecycle event is a change from one stage to another, which crosses every
// intermediate stage. For example, changing from StageAlive to StageFocused
// implicitly crosses StageVisible.
//
// Crosses can be in a positive or negative direction. A positive crossing of
// StageFocused means that the app has gained the focus. A negative crossing
// means it has lost the focus.
//
// See the golang.org/x/mobile/app package for details on the event model.
package lifecycle
import (
"fmt"
)
// Cross is whether a lifecycle stage was crossed.
type Cross uint32
func (c Cross) String() string {
switch c {
case CrossOn:
return "on"
case CrossOff:
return "off"
}
return "none"
}
const (
CrossNone Cross = 0
CrossOn Cross = 1
CrossOff Cross = 2
)
// Event is a lifecycle change from an old stage to a new stage.
type Event struct {
From, To Stage
// DrawContext is the state used for painting, if any is valid.
//
// For OpenGL apps, a non-nil DrawContext is a gl.Context.
//
// TODO: make this an App method if we move away from an event channel?
DrawContext interface{}
}
func (e Event) String() string {
return fmt.Sprintf("lifecycle.Event{From:%v, To:%v, DrawContext:%v}", e.From, e.To, e.DrawContext)
}
// Crosses reports whether the transition from From to To crosses the stage s:
// - It returns CrossOn if it does, and the lifecycle change is positive.
// - It returns CrossOff if it does, and the lifecycle change is negative.
// - Otherwise, it returns CrossNone.
//
// See the documentation for Stage for more discussion of positive and negative
// crosses.
func (e Event) Crosses(s Stage) Cross {
switch {
case e.From < s && e.To >= s:
return CrossOn
case e.From >= s && e.To < s:
return CrossOff
}
return CrossNone
}
// Stage is a stage in the app's lifecycle. The values are ordered, so that a
// lifecycle change from stage From to stage To implicitly crosses every stage
// in the range (min, max], exclusive on the low end and inclusive on the high
// end, where min is the minimum of From and To, and max is the maximum.
//
// The documentation for individual stages talk about positive and negative
// crosses. A positive lifecycle change is one where its From stage is less
// than its To stage. Similarly, a negative lifecycle change is one where From
// is greater than To. Thus, a positive lifecycle change crosses every stage in
// the range (From, To] in increasing order, and a negative lifecycle change
// crosses every stage in the range (To, From] in decreasing order.
type Stage uint32
// TODO: how does iOS map to these stages? What do cross-platform mobile
// abstractions do?
const (
// StageDead is the zero stage. No lifecycle change crosses this stage,
// but:
// - A positive change from this stage is the very first lifecycle change.
// - A negative change to this stage is the very last lifecycle change.
StageDead Stage = iota
// StageAlive means that the app is alive.
// - A positive cross means that the app has been created.
// - A negative cross means that the app is being destroyed.
// Each cross, either from or to StageDead, will occur only once.
// On Android, these correspond to onCreate and onDestroy.
StageAlive
// StageVisible means that the app window is visible.
// - A positive cross means that the app window has become visible.
// - A negative cross means that the app window has become invisible.
// On Android, these correspond to onStart and onStop.
// On Desktop, an app window can become invisible if e.g. it is minimized,
// unmapped, or not on a visible workspace.
StageVisible
// StageFocused means that the app window has the focus.
// - A positive cross means that the app window has gained the focus.
// - A negative cross means that the app window has lost the focus.
// On Android, these correspond to onResume and onFreeze.
StageFocused
)
func (s Stage) String() string {
switch s {
case StageDead:
return "StageDead"
case StageAlive:
return "StageAlive"
case StageVisible:
return "StageVisible"
case StageFocused:
return "StageFocused"
default:
return fmt.Sprintf("lifecycle.Stage(%d)", s)
}
}

90
event/mouse/mouse.go Normal file
View file

@ -0,0 +1,90 @@
// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Package mouse defines an event for mouse input.
//
// See the golang.org/x/mobile/app package for details on the event model.
package mouse
import (
"fmt"
"golang.org/x/mobile/event/key"
)
// Event is a mouse event.
type Event struct {
// X and Y are the mouse location, in pixels.
X, Y float32
// Button is the mouse button being pressed or released. Its value may be
// zero, for a mouse move or drag without any button change.
Button Button
// TODO: have a field to hold what other buttons are down, for detecting
// drags or button-chords.
// Modifiers is a bitmask representing a set of modifier keys:
// key.ModShift, key.ModAlt, etc.
Modifiers key.Modifiers
// Direction is the direction of the mouse event: DirPress, DirRelease,
// or DirNone (for mouse moves or drags).
Direction Direction
// TODO: add a Device ID, for multiple input devices?
// TODO: add a time.Time?
}
// Button is a mouse button.
type Button int32
// IsWheel reports whether the button is for a scroll wheel.
func (b Button) IsWheel() bool {
return b < 0
}
// TODO: have a separate axis concept for wheel up/down? How does that relate
// to joystick events?
const (
ButtonNone Button = +0
ButtonLeft Button = +1
ButtonMiddle Button = +2
ButtonRight Button = +3
ButtonWheelUp Button = -1
ButtonWheelDown Button = -2
ButtonWheelLeft Button = -3
ButtonWheelRight Button = -4
)
// Direction is the direction of the mouse event.
type Direction uint8
const (
DirNone Direction = 0
DirPress Direction = 1
DirRelease Direction = 2
// DirStep is a simultaneous press and release, such as a single step of a
// mouse wheel.
//
// Its value equals DirPress | DirRelease.
DirStep Direction = 3
)
func (d Direction) String() string {
switch d {
case DirNone:
return "None"
case DirPress:
return "Press"
case DirRelease:
return "Release"
case DirStep:
return "Step"
default:
return fmt.Sprintf("mouse.Direction(%d)", d)
}
}

24
event/paint/paint.go Normal file
View file

@ -0,0 +1,24 @@
// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Package paint defines an event for the app being ready to paint.
//
// See the golang.org/x/mobile/app package for details on the event model.
package paint
// Event indicates that the app is ready to paint the next frame of the GUI.
//
// A frame is completed by calling the App's Publish method.
type Event struct {
// External is true for paint events sent by the screen driver.
//
// An external event may be sent at any time in response to an
// operating system event, for example the window opened, was
// resized, or the screen memory was lost.
//
// Programs actively drawing to the screen as fast as vsync allows
// should ignore external paint events to avoid a backlog of paint
// events building up.
External bool
}

92
event/size/size.go Normal file
View file

@ -0,0 +1,92 @@
// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Package size defines an event for the dimensions, physical resolution and
// orientation of the app's window.
//
// See the golang.org/x/mobile/app package for details on the event model.
package size
import (
"image"
"golang.org/x/mobile/geom"
)
// Event holds the dimensions, physical resolution and orientation of the app's
// window.
type Event struct {
// WidthPx and HeightPx are the window's dimensions in pixels.
WidthPx, HeightPx int
// WidthPt and HeightPt are the window's physical dimensions in points
// (1/72 of an inch).
//
// The values are based on PixelsPerPt and are therefore approximate, as
// per the comment on PixelsPerPt.
WidthPt, HeightPt geom.Pt
// PixelsPerPt is the window's physical resolution. It is the number of
// pixels in a single geom.Pt, from the golang.org/x/mobile/geom package.
//
// There are a wide variety of pixel densities in existing phones and
// tablets, so apps should be written to expect various non-integer
// PixelsPerPt values. In general, work in geom.Pt.
//
// The value is approximate, in that the OS, drivers or hardware may report
// approximate or quantized values. An N x N pixel square should be roughly
// 1 square inch for N = int(PixelsPerPt * 72), although different square
// lengths (in pixels) might be closer to 1 inch in practice. Nonetheless,
// this PixelsPerPt value should be consistent with e.g. the ratio of
// WidthPx to WidthPt.
PixelsPerPt float32
// Orientation is the orientation of the device screen.
Orientation Orientation
}
// Size returns the window's size in pixels, at the time this size event was
// sent.
func (e Event) Size() image.Point {
return image.Point{e.WidthPx, e.HeightPx}
}
// Bounds returns the window's bounds in pixels, at the time this size event
// was sent.
//
// The top-left pixel is always (0, 0). The bottom-right pixel is given by the
// width and height.
func (e Event) Bounds() image.Rectangle {
return image.Rectangle{Max: image.Point{e.WidthPx, e.HeightPx}}
}
// Orientation is the orientation of the device screen.
type Orientation int
const (
// OrientationUnknown means device orientation cannot be determined.
//
// Equivalent on Android to Configuration.ORIENTATION_UNKNOWN
// and on iOS to:
// UIDeviceOrientationUnknown
// UIDeviceOrientationFaceUp
// UIDeviceOrientationFaceDown
OrientationUnknown Orientation = iota
// OrientationPortrait is a device oriented so it is tall and thin.
//
// Equivalent on Android to Configuration.ORIENTATION_PORTRAIT
// and on iOS to:
// UIDeviceOrientationPortrait
// UIDeviceOrientationPortraitUpsideDown
OrientationPortrait
// OrientationLandscape is a device oriented so it is short and wide.
//
// Equivalent on Android to Configuration.ORIENTATION_LANDSCAPE
// and on iOS to:
// UIDeviceOrientationLandscapeLeft
// UIDeviceOrientationLandscapeRight
OrientationLandscape
)

72
event/touch/touch.go Normal file
View file

@ -0,0 +1,72 @@
// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Package touch defines an event for touch input.
//
// See the golang.org/x/mobile/app package for details on the event model.
package touch
// The best source on android input events is the NDK: include/android/input.h
//
// iOS event handling guide:
// https://developer.apple.com/library/ios/documentation/EventHandling/Conceptual/EventHandlingiPhoneOS
import (
"fmt"
)
// Event is a touch event.
type Event struct {
// X and Y are the touch location, in pixels.
X, Y float32
// Sequence is the sequence number. The same number is shared by all events
// in a sequence. A sequence begins with a single TypeBegin, is followed by
// zero or more TypeMoves, and ends with a single TypeEnd. A Sequence
// distinguishes concurrent sequences but its value is subsequently reused.
Sequence Sequence
// Type is the touch type.
Type Type
}
// Sequence identifies a sequence of touch events.
type Sequence int64
// Type describes the type of a touch event.
type Type byte
const (
// TypeBegin is a user first touching the device.
//
// On Android, this is a AMOTION_EVENT_ACTION_DOWN.
// On iOS, this is a call to touchesBegan.
TypeBegin Type = iota
// TypeMove is a user dragging across the device.
//
// A TypeMove is delivered between a TypeBegin and TypeEnd.
//
// On Android, this is a AMOTION_EVENT_ACTION_MOVE.
// On iOS, this is a call to touchesMoved.
TypeMove
// TypeEnd is a user no longer touching the device.
//
// On Android, this is a AMOTION_EVENT_ACTION_UP.
// On iOS, this is a call to touchesEnded.
TypeEnd
)
func (t Type) String() string {
switch t {
case TypeBegin:
return "begin"
case TypeMove:
return "move"
case TypeEnd:
return "end"
}
return fmt.Sprintf("touch.Type(%d)", t)
}