rename plugin to backend
This commit is contained in:
parent
7edb092f93
commit
8e7c945f0f
8 changed files with 68 additions and 68 deletions
|
|
@ -39,15 +39,15 @@ const (
|
||||||
KeyLimit
|
KeyLimit
|
||||||
)
|
)
|
||||||
|
|
||||||
type PluginInfo struct {
|
type BackendInfo struct {
|
||||||
Name string
|
Name string
|
||||||
Init func() (Plugin, error)
|
Init func() (Backend, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
var Plugins []PluginInfo = []PluginInfo{
|
var Backends []BackendInfo = []BackendInfo{
|
||||||
{"X11", InitX11Plugin},
|
{"X11", InitX11Backend},
|
||||||
{"RemoteDesktop portal", InitPortalPlugin},
|
{"RemoteDesktop portal", InitPortalBackend},
|
||||||
{"Windows", InitWindowsPlugin},
|
{"Windows", InitWindowsBackend},
|
||||||
}
|
}
|
||||||
|
|
||||||
type UnsupportedPlatformError struct {
|
type UnsupportedPlatformError struct {
|
||||||
|
|
@ -58,7 +58,7 @@ func (e UnsupportedPlatformError) Error() string {
|
||||||
return e.err.Error()
|
return e.err.Error()
|
||||||
}
|
}
|
||||||
|
|
||||||
type Plugin interface {
|
type Backend interface {
|
||||||
Close() error
|
Close() error
|
||||||
KeyboardText(text string) error
|
KeyboardText(text string) error
|
||||||
KeyboardKey(key Key) error
|
KeyboardKey(key Key) error
|
||||||
|
|
@ -40,14 +40,14 @@ const (
|
||||||
btnMiddle int32 = 0x112
|
btnMiddle int32 = 0x112
|
||||||
)
|
)
|
||||||
|
|
||||||
type portalPlugin struct {
|
type portalBackend struct {
|
||||||
bus *dbus.Conn
|
bus *dbus.Conn
|
||||||
remoteDesktop dbus.BusObject
|
remoteDesktop dbus.BusObject
|
||||||
sessionHandle dbus.ObjectPath
|
sessionHandle dbus.ObjectPath
|
||||||
lock sync.RWMutex
|
lock sync.RWMutex
|
||||||
}
|
}
|
||||||
|
|
||||||
func InitPortalPlugin() (Plugin, error) {
|
func InitPortalBackend() (Backend, error) {
|
||||||
bus, err := dbus.SessionBusPrivate()
|
bus, err := dbus.SessionBusPrivate()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, UnsupportedPlatformError{err}
|
return nil, UnsupportedPlatformError{err}
|
||||||
|
|
@ -139,7 +139,7 @@ func InitPortalPlugin() (Plugin, error) {
|
||||||
return nil, errors.New("keyboard or pointer access denied")
|
return nil, errors.New("keyboard or pointer access denied")
|
||||||
}
|
}
|
||||||
cleanupBus = false
|
cleanupBus = false
|
||||||
return &portalPlugin{bus: bus, remoteDesktop: remoteDesktop,
|
return &portalBackend{bus: bus, remoteDesktop: remoteDesktop,
|
||||||
sessionHandle: sessionHandle}, nil
|
sessionHandle: sessionHandle}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -171,7 +171,7 @@ func getResponse(bus *dbus.Conn, object dbus.BusObject, method string,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *portalPlugin) Close() error {
|
func (p *portalBackend) Close() error {
|
||||||
p.lock.Lock()
|
p.lock.Lock()
|
||||||
defer p.lock.Unlock()
|
defer p.lock.Unlock()
|
||||||
if p.bus == nil {
|
if p.bus == nil {
|
||||||
|
|
@ -185,7 +185,7 @@ func (p *portalPlugin) Close() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *portalPlugin) keyboardKeys(keys []Keysym) error {
|
func (p *portalBackend) keyboardKeys(keys []Keysym) error {
|
||||||
p.lock.RLock()
|
p.lock.RLock()
|
||||||
defer p.lock.RUnlock()
|
defer p.lock.RUnlock()
|
||||||
if p.bus == nil {
|
if p.bus == nil {
|
||||||
|
|
@ -204,7 +204,7 @@ func (p *portalPlugin) keyboardKeys(keys []Keysym) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *portalPlugin) KeyboardText(text string) error {
|
func (p *portalBackend) KeyboardText(text string) error {
|
||||||
keys := make([]Keysym, 0, len(text))
|
keys := make([]Keysym, 0, len(text))
|
||||||
for _, runeValue := range text {
|
for _, runeValue := range text {
|
||||||
keysym, err := RuneToKeysym(runeValue)
|
keysym, err := RuneToKeysym(runeValue)
|
||||||
|
|
@ -216,7 +216,7 @@ func (p *portalPlugin) KeyboardText(text string) error {
|
||||||
return p.keyboardKeys(keys)
|
return p.keyboardKeys(keys)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *portalPlugin) KeyboardKey(key Key) error {
|
func (p *portalBackend) KeyboardKey(key Key) error {
|
||||||
keysym, err := KeyToKeysym(key)
|
keysym, err := KeyToKeysym(key)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
@ -225,7 +225,7 @@ func (p *portalPlugin) KeyboardKey(key Key) error {
|
||||||
return p.keyboardKeys(keys[:])
|
return p.keyboardKeys(keys[:])
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *portalPlugin) PointerButton(button PointerButton, press bool) error {
|
func (p *portalBackend) PointerButton(button PointerButton, press bool) error {
|
||||||
p.lock.RLock()
|
p.lock.RLock()
|
||||||
defer p.lock.RUnlock()
|
defer p.lock.RUnlock()
|
||||||
if p.bus == nil {
|
if p.bus == nil {
|
||||||
|
|
@ -253,7 +253,7 @@ func (p *portalPlugin) PointerButton(button PointerButton, press bool) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *portalPlugin) PointerMove(deltaX, deltaY int) error {
|
func (p *portalBackend) PointerMove(deltaX, deltaY int) error {
|
||||||
p.lock.RLock()
|
p.lock.RLock()
|
||||||
defer p.lock.RUnlock()
|
defer p.lock.RUnlock()
|
||||||
if p.bus == nil {
|
if p.bus == nil {
|
||||||
|
|
@ -267,7 +267,7 @@ func (p *portalPlugin) PointerMove(deltaX, deltaY int) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *portalPlugin) pointerScrollFull(deltaHorizontal, deltaVertical int, finish bool) error {
|
func (p *portalBackend) pointerScrollFull(deltaHorizontal, deltaVertical int, finish bool) error {
|
||||||
p.lock.RLock()
|
p.lock.RLock()
|
||||||
defer p.lock.RUnlock()
|
defer p.lock.RUnlock()
|
||||||
if p.bus == nil {
|
if p.bus == nil {
|
||||||
|
|
@ -282,10 +282,10 @@ func (p *portalPlugin) pointerScrollFull(deltaHorizontal, deltaVertical int, fin
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *portalPlugin) PointerScroll(deltaHorizontal, deltaVertical int) error {
|
func (p *portalBackend) PointerScroll(deltaHorizontal, deltaVertical int) error {
|
||||||
return p.pointerScrollFull(deltaHorizontal, deltaVertical, false)
|
return p.pointerScrollFull(deltaHorizontal, deltaVertical, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *portalPlugin) PointerScrollFinish() error {
|
func (p *portalBackend) PointerScrollFinish() error {
|
||||||
return p.pointerScrollFull(0, 0, true)
|
return p.pointerScrollFull(0, 0, true)
|
||||||
}
|
}
|
||||||
|
|
@ -23,6 +23,6 @@ package main
|
||||||
|
|
||||||
import "errors"
|
import "errors"
|
||||||
|
|
||||||
func InitPortalPlugin() (Plugin, error) {
|
func InitPortalBackend() (Backend, error) {
|
||||||
return nil, UnsupportedPlatformError{errors.New("disabled")}
|
return nil, UnsupportedPlatformError{errors.New("disabled")}
|
||||||
}
|
}
|
||||||
|
|
@ -77,21 +77,21 @@ type keybdInput struct {
|
||||||
padding [8]byte
|
padding [8]byte
|
||||||
}
|
}
|
||||||
|
|
||||||
type windowsPlugin struct{}
|
type windowsBackend struct{}
|
||||||
|
|
||||||
func InitWindowsPlugin() (Plugin, error) {
|
func InitWindowsBackend() (Backend, error) {
|
||||||
p := &windowsPlugin{}
|
p := &windowsBackend{}
|
||||||
if err := sendInputProc.Find(); err != nil {
|
if err := sendInputProc.Find(); err != nil {
|
||||||
return nil, UnsupportedPlatformError{err}
|
return nil, UnsupportedPlatformError{err}
|
||||||
}
|
}
|
||||||
return p, nil
|
return p, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *windowsPlugin) Close() error {
|
func (p *windowsBackend) Close() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *windowsPlugin) sendInput(inputs []keybdInput) error {
|
func (p *windowsBackend) sendInput(inputs []keybdInput) error {
|
||||||
if len(inputs) == 0 {
|
if len(inputs) == 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
@ -103,7 +103,7 @@ func (p *windowsPlugin) sendInput(inputs []keybdInput) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *windowsPlugin) KeyboardText(text string) error {
|
func (p *windowsBackend) KeyboardText(text string) error {
|
||||||
inputs := make([]keybdInput, 0, len(text)*2)
|
inputs := make([]keybdInput, 0, len(text)*2)
|
||||||
for _, runeValue := range text {
|
for _, runeValue := range text {
|
||||||
in := keybdInput{typ: inputKeyboard, wScan: uint16(runeValue), dwFlags: keyeventfUnicode}
|
in := keybdInput{typ: inputKeyboard, wScan: uint16(runeValue), dwFlags: keyeventfUnicode}
|
||||||
|
|
@ -117,7 +117,7 @@ func (p *windowsPlugin) KeyboardText(text string) error {
|
||||||
return p.sendInput(inputs)
|
return p.sendInput(inputs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *windowsPlugin) KeyboardKey(key Key) error {
|
func (p *windowsBackend) KeyboardKey(key Key) error {
|
||||||
input := keybdInput{typ: inputKeyboard}
|
input := keybdInput{typ: inputKeyboard}
|
||||||
if key == KeyVolumeMute {
|
if key == KeyVolumeMute {
|
||||||
input.wVk = vkVolumeMute
|
input.wVk = vkVolumeMute
|
||||||
|
|
@ -139,7 +139,7 @@ func (p *windowsPlugin) KeyboardKey(key Key) error {
|
||||||
return p.sendInput(inputs[:])
|
return p.sendInput(inputs[:])
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *windowsPlugin) PointerButton(button PointerButton, press bool) error {
|
func (p *windowsBackend) PointerButton(button PointerButton, press bool) error {
|
||||||
input := mouseInput{typ: inputMouse}
|
input := mouseInput{typ: inputMouse}
|
||||||
if button == PointerButtonLeft && press {
|
if button == PointerButtonLeft && press {
|
||||||
input.dwFlags = mouseeventfLeftdown
|
input.dwFlags = mouseeventfLeftdown
|
||||||
|
|
@ -163,7 +163,7 @@ func (p *windowsPlugin) PointerButton(button PointerButton, press bool) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *windowsPlugin) PointerMove(deltaX, deltaY int) error {
|
func (p *windowsBackend) PointerMove(deltaX, deltaY int) error {
|
||||||
input := mouseInput{
|
input := mouseInput{
|
||||||
typ: inputMouse,
|
typ: inputMouse,
|
||||||
dx: int32(deltaX),
|
dx: int32(deltaX),
|
||||||
|
|
@ -177,7 +177,7 @@ func (p *windowsPlugin) PointerMove(deltaX, deltaY int) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *windowsPlugin) PointerScroll(deltaHorizontal, deltaVertical int) error {
|
func (p *windowsBackend) PointerScroll(deltaHorizontal, deltaVertical int) error {
|
||||||
inputs := make([]mouseInput, 0, 2)
|
inputs := make([]mouseInput, 0, 2)
|
||||||
if deltaHorizontal != 0 {
|
if deltaHorizontal != 0 {
|
||||||
inputs = append(inputs, mouseInput{
|
inputs = append(inputs, mouseInput{
|
||||||
|
|
@ -204,6 +204,6 @@ func (p *windowsPlugin) PointerScroll(deltaHorizontal, deltaVertical int) error
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *windowsPlugin) PointerScrollFinish() error {
|
func (p *windowsBackend) PointerScrollFinish() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
@ -23,6 +23,6 @@ package main
|
||||||
|
|
||||||
import "errors"
|
import "errors"
|
||||||
|
|
||||||
func InitWindowsPlugin() (Plugin, error) {
|
func InitWindowsBackend() (Backend, error) {
|
||||||
return nil, UnsupportedPlatformError{errors.New("disabled")}
|
return nil, UnsupportedPlatformError{errors.New("disabled")}
|
||||||
}
|
}
|
||||||
|
|
@ -44,13 +44,13 @@ const (
|
||||||
var modifierIndices [6]uint = [...]uint{C.ShiftMapIndex, C.Mod1MapIndex,
|
var modifierIndices [6]uint = [...]uint{C.ShiftMapIndex, C.Mod1MapIndex,
|
||||||
C.Mod2MapIndex, C.Mod3MapIndex, C.Mod4MapIndex, C.Mod5MapIndex}
|
C.Mod2MapIndex, C.Mod3MapIndex, C.Mod4MapIndex, C.Mod5MapIndex}
|
||||||
|
|
||||||
type x11Plugin struct {
|
type x11Backend struct {
|
||||||
display *C.Display
|
display *C.Display
|
||||||
lock sync.Mutex
|
lock sync.Mutex
|
||||||
scrollHorizontal, scrollVertical int
|
scrollHorizontal, scrollVertical int
|
||||||
}
|
}
|
||||||
|
|
||||||
func InitX11Plugin() (Plugin, error) {
|
func InitX11Backend() (Backend, error) {
|
||||||
sessionType := os.Getenv("XDG_SESSION_TYPE")
|
sessionType := os.Getenv("XDG_SESSION_TYPE")
|
||||||
if sessionType != "" && sessionType != "x11" {
|
if sessionType != "" && sessionType != "x11" {
|
||||||
return nil, UnsupportedPlatformError{errors.New(fmt.Sprintf(
|
return nil, UnsupportedPlatformError{errors.New(fmt.Sprintf(
|
||||||
|
|
@ -61,10 +61,10 @@ func InitX11Plugin() (Plugin, error) {
|
||||||
return nil, UnsupportedPlatformError{
|
return nil, UnsupportedPlatformError{
|
||||||
errors.New("failed to connect to X server")}
|
errors.New("failed to connect to X server")}
|
||||||
}
|
}
|
||||||
return &x11Plugin{display: display}, nil
|
return &x11Backend{display: display}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *x11Plugin) Close() error {
|
func (p *x11Backend) Close() error {
|
||||||
p.lock.Lock()
|
p.lock.Lock()
|
||||||
defer p.lock.Unlock()
|
defer p.lock.Unlock()
|
||||||
if p.display == nil {
|
if p.display == nil {
|
||||||
|
|
@ -75,7 +75,7 @@ func (p *x11Plugin) Close() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *x11Plugin) findEmptyKeycodeLocked() (C.KeyCode, C.int, error) {
|
func (p *x11Backend) findEmptyKeycodeLocked() (C.KeyCode, C.int, error) {
|
||||||
var minKeycodes, maxKeycodes C.int
|
var minKeycodes, maxKeycodes C.int
|
||||||
C.XDisplayKeycodes(p.display, &minKeycodes, &maxKeycodes)
|
C.XDisplayKeycodes(p.display, &minKeycodes, &maxKeycodes)
|
||||||
var keysymsPerKeycode C.int
|
var keysymsPerKeycode C.int
|
||||||
|
|
@ -101,7 +101,7 @@ keycodes:
|
||||||
return 0, 0, errors.New("no empty keycode found")
|
return 0, 0, errors.New("no empty keycode found")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *x11Plugin) changeKeyMappingLocked(keysymsPerKeycode C.int,
|
func (p *x11Backend) changeKeyMappingLocked(keysymsPerKeycode C.int,
|
||||||
keycode C.KeyCode, keysym Keysym) {
|
keycode C.KeyCode, keysym Keysym) {
|
||||||
keycodeMapping := make([]C.KeySym, keysymsPerKeycode)
|
keycodeMapping := make([]C.KeySym, keysymsPerKeycode)
|
||||||
for i := range keycodeMapping {
|
for i := range keycodeMapping {
|
||||||
|
|
@ -112,7 +112,7 @@ func (p *x11Plugin) changeKeyMappingLocked(keysymsPerKeycode C.int,
|
||||||
C.XFlush(p.display)
|
C.XFlush(p.display)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *x11Plugin) getModKeycodesLocked() map[uint]C.KeyCode {
|
func (p *x11Backend) getModKeycodesLocked() map[uint]C.KeyCode {
|
||||||
modKeymap := C.XGetModifierMapping(p.display)
|
modKeymap := C.XGetModifierMapping(p.display)
|
||||||
defer C.XFreeModifiermap(modKeymap)
|
defer C.XFreeModifiermap(modKeymap)
|
||||||
modKeycodes := make(map[uint]C.KeyCode)
|
modKeycodes := make(map[uint]C.KeyCode)
|
||||||
|
|
@ -129,7 +129,7 @@ func (p *x11Plugin) getModKeycodesLocked() map[uint]C.KeyCode {
|
||||||
return modKeycodes
|
return modKeycodes
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *x11Plugin) findKeycodeLocked(keyboard C.XkbDescPtr,
|
func (p *x11Backend) findKeycodeLocked(keyboard C.XkbDescPtr,
|
||||||
modKeycodes map[uint]C.KeyCode, activeMods C.uint,
|
modKeycodes map[uint]C.KeyCode, activeMods C.uint,
|
||||||
keysym Keysym) (C.KeyCode, C.uint) {
|
keysym Keysym) (C.KeyCode, C.uint) {
|
||||||
keycode := C.XKeysymToKeycode(p.display, C.KeySym(keysym))
|
keycode := C.XKeysymToKeycode(p.display, C.KeySym(keysym))
|
||||||
|
|
@ -165,7 +165,7 @@ func (p *x11Plugin) findKeycodeLocked(keyboard C.XkbDescPtr,
|
||||||
return 0, 0
|
return 0, 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *x11Plugin) sendModsLocked(modKeycodes map[uint]C.KeyCode, mods C.uint,
|
func (p *x11Backend) sendModsLocked(modKeycodes map[uint]C.KeyCode, mods C.uint,
|
||||||
press bool) {
|
press bool) {
|
||||||
var pressC C.int = C.False
|
var pressC C.int = C.False
|
||||||
if press {
|
if press {
|
||||||
|
|
@ -178,7 +178,7 @@ func (p *x11Plugin) sendModsLocked(modKeycodes map[uint]C.KeyCode, mods C.uint,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *x11Plugin) keyboardKeys(keys []Keysym) error {
|
func (p *x11Backend) keyboardKeys(keys []Keysym) error {
|
||||||
p.lock.Lock()
|
p.lock.Lock()
|
||||||
defer p.lock.Unlock()
|
defer p.lock.Unlock()
|
||||||
if p.display == nil {
|
if p.display == nil {
|
||||||
|
|
@ -236,7 +236,7 @@ func (p *x11Plugin) keyboardKeys(keys []Keysym) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *x11Plugin) KeyboardText(text string) error {
|
func (p *x11Backend) KeyboardText(text string) error {
|
||||||
keys := make([]Keysym, 0, len(text))
|
keys := make([]Keysym, 0, len(text))
|
||||||
for _, runeValue := range text {
|
for _, runeValue := range text {
|
||||||
keysym, err := RuneToKeysym(runeValue)
|
keysym, err := RuneToKeysym(runeValue)
|
||||||
|
|
@ -248,7 +248,7 @@ func (p *x11Plugin) KeyboardText(text string) error {
|
||||||
return p.keyboardKeys(keys)
|
return p.keyboardKeys(keys)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *x11Plugin) KeyboardKey(key Key) error {
|
func (p *x11Backend) KeyboardKey(key Key) error {
|
||||||
keysym, err := KeyToKeysym(key)
|
keysym, err := KeyToKeysym(key)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
@ -257,7 +257,7 @@ func (p *x11Plugin) KeyboardKey(key Key) error {
|
||||||
return p.keyboardKeys(keys[:])
|
return p.keyboardKeys(keys[:])
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *x11Plugin) sendButton(button uint, press bool) error {
|
func (p *x11Backend) sendButton(button uint, press bool) error {
|
||||||
p.lock.Lock()
|
p.lock.Lock()
|
||||||
defer p.lock.Unlock()
|
defer p.lock.Unlock()
|
||||||
if p.display == nil {
|
if p.display == nil {
|
||||||
|
|
@ -275,7 +275,7 @@ func (p *x11Plugin) sendButton(button uint, press bool) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *x11Plugin) PointerButton(button PointerButton, press bool) error {
|
func (p *x11Backend) PointerButton(button PointerButton, press bool) error {
|
||||||
if button == PointerButtonLeft {
|
if button == PointerButtonLeft {
|
||||||
return p.sendButton(1, press)
|
return p.sendButton(1, press)
|
||||||
}
|
}
|
||||||
|
|
@ -288,7 +288,7 @@ func (p *x11Plugin) PointerButton(button PointerButton, press bool) error {
|
||||||
return errors.New("unsupported pointer button")
|
return errors.New("unsupported pointer button")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *x11Plugin) PointerMove(deltaX, deltaY int) error {
|
func (p *x11Backend) PointerMove(deltaX, deltaY int) error {
|
||||||
p.lock.Lock()
|
p.lock.Lock()
|
||||||
defer p.lock.Unlock()
|
defer p.lock.Unlock()
|
||||||
if p.display == nil {
|
if p.display == nil {
|
||||||
|
|
@ -299,7 +299,7 @@ func (p *x11Plugin) PointerMove(deltaX, deltaY int) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *x11Plugin) PointerScroll(deltaHorizontal, deltaVertical int) error {
|
func (p *x11Backend) PointerScroll(deltaHorizontal, deltaVertical int) error {
|
||||||
p.lock.Lock()
|
p.lock.Lock()
|
||||||
stepsHorizontal := (p.scrollHorizontal + deltaHorizontal) / scrollDiv
|
stepsHorizontal := (p.scrollHorizontal + deltaHorizontal) / scrollDiv
|
||||||
stepsVertical := (p.scrollVertical + deltaVertical) / scrollDiv
|
stepsVertical := (p.scrollVertical + deltaVertical) / scrollDiv
|
||||||
|
|
@ -335,7 +335,7 @@ func (p *x11Plugin) PointerScroll(deltaHorizontal, deltaVertical int) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *x11Plugin) PointerScrollFinish() error {
|
func (p *x11Backend) PointerScrollFinish() error {
|
||||||
p.lock.Lock()
|
p.lock.Lock()
|
||||||
defer p.lock.Unlock()
|
defer p.lock.Unlock()
|
||||||
p.scrollHorizontal = 0
|
p.scrollHorizontal = 0
|
||||||
|
|
@ -23,6 +23,6 @@ package main
|
||||||
|
|
||||||
import "errors"
|
import "errors"
|
||||||
|
|
||||||
func InitX11Plugin() (Plugin, error) {
|
func InitX11Backend() (Backend, error) {
|
||||||
return nil, UnsupportedPlatformError{errors.New("disabled")}
|
return nil, UnsupportedPlatformError{errors.New("disabled")}
|
||||||
}
|
}
|
||||||
36
main.go
36
main.go
|
|
@ -48,12 +48,12 @@ const (
|
||||||
version string = "0.0.10"
|
version string = "0.0.10"
|
||||||
)
|
)
|
||||||
|
|
||||||
func processCommand(plugin Plugin, command string) error {
|
func processCommand(backend Backend, command string) error {
|
||||||
if len(command) == 0 {
|
if len(command) == 0 {
|
||||||
return errors.New("empty command")
|
return errors.New("empty command")
|
||||||
}
|
}
|
||||||
if command == "sf" {
|
if command == "sf" {
|
||||||
return plugin.PointerScrollFinish()
|
return backend.PointerScrollFinish()
|
||||||
}
|
}
|
||||||
if command[0] == 't' {
|
if command[0] == 't' {
|
||||||
text := command[1:]
|
text := command[1:]
|
||||||
|
|
@ -63,7 +63,7 @@ func processCommand(plugin Plugin, command string) error {
|
||||||
if !utf8.ValidString(text) {
|
if !utf8.ValidString(text) {
|
||||||
return errors.New("invalid utf-8")
|
return errors.New("invalid utf-8")
|
||||||
}
|
}
|
||||||
return plugin.KeyboardText(text)
|
return backend.KeyboardText(text)
|
||||||
}
|
}
|
||||||
arguments := strings.Split(command[1:], ";")
|
arguments := strings.Split(command[1:], ";")
|
||||||
if command[0] == 'k' && len(arguments) != 1 ||
|
if command[0] == 'k' && len(arguments) != 1 ||
|
||||||
|
|
@ -78,17 +78,17 @@ func processCommand(plugin Plugin, command string) error {
|
||||||
if x < 0 || x >= int64(KeyLimit) {
|
if x < 0 || x >= int64(KeyLimit) {
|
||||||
return errors.New("unsupported key")
|
return errors.New("unsupported key")
|
||||||
}
|
}
|
||||||
return plugin.KeyboardKey(Key(x))
|
return backend.KeyboardKey(Key(x))
|
||||||
}
|
}
|
||||||
y, err := strconv.ParseInt(arguments[1], 10, 32)
|
y, err := strconv.ParseInt(arguments[1], 10, 32)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if command[0] == 'm' {
|
if command[0] == 'm' {
|
||||||
return plugin.PointerMove(int(x), int(y))
|
return backend.PointerMove(int(x), int(y))
|
||||||
}
|
}
|
||||||
if command[0] == 's' {
|
if command[0] == 's' {
|
||||||
return plugin.PointerScroll(int(x), int(y))
|
return backend.PointerScroll(int(x), int(y))
|
||||||
}
|
}
|
||||||
if command[0] == 'b' {
|
if command[0] == 'b' {
|
||||||
if x < 0 || x >= int64(PointerButtonLimit) {
|
if x < 0 || x >= int64(PointerButtonLimit) {
|
||||||
|
|
@ -98,7 +98,7 @@ func processCommand(plugin Plugin, command string) error {
|
||||||
if y == 0 {
|
if y == 0 {
|
||||||
b = false
|
b = false
|
||||||
}
|
}
|
||||||
return plugin.PointerButton(PointerButton(x), b)
|
return backend.PointerButton(PointerButton(x), b)
|
||||||
}
|
}
|
||||||
return errors.New("unsupported command")
|
return errors.New("unsupported command")
|
||||||
}
|
}
|
||||||
|
|
@ -171,25 +171,25 @@ func main() {
|
||||||
if secret == "" {
|
if secret == "" {
|
||||||
secret = secureRandBase64(defaultSecretLength)
|
secret = secureRandBase64(defaultSecretLength)
|
||||||
}
|
}
|
||||||
var plugin Plugin
|
var backend Backend
|
||||||
var pluginName string
|
var backendName string
|
||||||
platformErrors := ""
|
platformErrors := ""
|
||||||
for _, pluginInfo := range Plugins {
|
for _, backendInfo := range Backends {
|
||||||
pluginName = pluginInfo.Name
|
backendName = backendInfo.Name
|
||||||
var err error
|
var err error
|
||||||
plugin, err = pluginInfo.Init()
|
backend, err = backendInfo.Init()
|
||||||
if err == nil {
|
if err == nil {
|
||||||
break
|
break
|
||||||
} else if _, ok := err.(UnsupportedPlatformError); ok {
|
} else if _, ok := err.(UnsupportedPlatformError); ok {
|
||||||
platformErrors += fmt.Sprintf("%s plugin: %v\n", pluginName, err)
|
platformErrors += fmt.Sprintf("%s backend: %v\n", backendName, err)
|
||||||
} else {
|
} else {
|
||||||
log.Fatal(fmt.Sprintf("%s plugin: %v", pluginName, err))
|
log.Fatal(fmt.Sprintf("%s backend: %v", backendName, err))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if plugin == nil {
|
if backend == nil {
|
||||||
log.Fatal("unsupported platform:\n" + platformErrors)
|
log.Fatal("unsupported platform:\n" + platformErrors)
|
||||||
}
|
}
|
||||||
defer plugin.Close()
|
defer backend.Close()
|
||||||
authenticationChallenges := make(chan challenge, authenticationRateBurst)
|
authenticationChallenges := make(chan challenge, authenticationRateBurst)
|
||||||
go authenticationChallengeGenerator(secret, authenticationChallenges)
|
go authenticationChallengeGenerator(secret, authenticationChallenges)
|
||||||
listener, err := net.Listen("tcp", bind)
|
listener, err := net.Listen("tcp", bind)
|
||||||
|
|
@ -228,8 +228,8 @@ func main() {
|
||||||
if err := websocket.Message.Receive(ws, &message); err != nil {
|
if err := websocket.Message.Receive(ws, &message); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err := processCommand(plugin, message); err != nil {
|
if err := processCommand(backend, message); err != nil {
|
||||||
log.Print(fmt.Sprintf("%s plugin: %v", pluginName, err))
|
log.Print(fmt.Sprintf("%s backend: %v", backendName, err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue