Format code
This commit is contained in:
parent
85b6d6ea9d
commit
6ef2be8776
6 changed files with 55 additions and 29 deletions
3
host.go
3
host.go
|
|
@ -74,7 +74,8 @@ func findDefaultHost() string {
|
|||
continue
|
||||
}
|
||||
for _, linkLocalPrefix := range []string{
|
||||
"169.254.", "fe8", "fe9", "fea", "feb"} {
|
||||
"169.254.", "fe8", "fe9", "fea", "feb",
|
||||
} {
|
||||
if strings.HasPrefix(ip.String(), linkLocalPrefix) {
|
||||
addIP(20, ip)
|
||||
continue addrs
|
||||
|
|
|
|||
|
|
@ -21,8 +21,10 @@ package inputcontrol
|
|||
|
||||
import "sort"
|
||||
|
||||
type PointerButton int
|
||||
type Key int
|
||||
type (
|
||||
PointerButton int
|
||||
Key int
|
||||
)
|
||||
|
||||
const (
|
||||
PointerButtonLeft PointerButton = iota
|
||||
|
|
|
|||
|
|
@ -88,12 +88,14 @@ func InitPortalController() (Controller, error) {
|
|||
"org.freedesktop.portal.RemoteDesktop.version")
|
||||
if err != nil {
|
||||
return nil, &UnsupportedPlatformError{
|
||||
fmt.Errorf("getting 'version' failed: %w", err)}
|
||||
fmt.Errorf("getting 'version' failed: %w", err),
|
||||
}
|
||||
}
|
||||
remoteDesktopVersion, ok := remoteDesktopVersionV.Value().(uint32)
|
||||
if !ok {
|
||||
return nil, &UnsupportedPlatformError{
|
||||
errors.New("unexpected 'version' type")}
|
||||
errors.New("unexpected 'version' type"),
|
||||
}
|
||||
}
|
||||
restoreTokenStore, err := func() (*secretStore, error) {
|
||||
if remoteDesktopVersion < 2 {
|
||||
|
|
@ -103,7 +105,7 @@ func InitPortalController() (Controller, error) {
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := os.MkdirAll(cacheDirectory, 0700); err != nil {
|
||||
if err := os.MkdirAll(cacheDirectory, 0o700); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
secret, err := retrieveSecret(bus)
|
||||
|
|
@ -120,17 +122,20 @@ func InitPortalController() (Controller, error) {
|
|||
"org.freedesktop.portal.RemoteDesktop.AvailableDeviceTypes")
|
||||
if err != nil {
|
||||
return nil, &UnsupportedPlatformError{
|
||||
fmt.Errorf("getting 'AvailableDeviceTypes' failed: %w", err)}
|
||||
fmt.Errorf("getting 'AvailableDeviceTypes' failed: %w", err),
|
||||
}
|
||||
}
|
||||
availableDeviceTypes, ok := availableDeviceTypesV.Value().(uint32)
|
||||
if !ok {
|
||||
return nil, &UnsupportedPlatformError{
|
||||
errors.New("unexpected 'AvailableDeviceTypes' return type")}
|
||||
errors.New("unexpected 'AvailableDeviceTypes' return type"),
|
||||
}
|
||||
}
|
||||
if availableDeviceTypes&deviceKeyboard == 0 ||
|
||||
availableDeviceTypes&devicePointer == 0 {
|
||||
return nil, &UnsupportedPlatformError{
|
||||
errors.New("keyboard or pointer source type not supported")}
|
||||
errors.New("keyboard or pointer source type not supported"),
|
||||
}
|
||||
}
|
||||
createSessionResults, err := checkResponse(getResponse(bus, portalDesktop,
|
||||
"org.freedesktop.portal.RemoteDesktop.CreateSession", 0,
|
||||
|
|
@ -138,12 +143,14 @@ func InitPortalController() (Controller, error) {
|
|||
))
|
||||
if err != nil {
|
||||
return nil, &UnsupportedPlatformError{
|
||||
fmt.Errorf("calling 'CreateSession' failed: %w", err)}
|
||||
fmt.Errorf("calling 'CreateSession' failed: %w", err),
|
||||
}
|
||||
}
|
||||
sessionHandleString, ok := createSessionResults["session_handle"].Value().(string)
|
||||
if !ok {
|
||||
return nil, &UnsupportedPlatformError{
|
||||
errors.New("unexpected 'session_handle' type in 'CreateSession' return value")}
|
||||
errors.New("unexpected 'session_handle' type in 'CreateSession' return value"),
|
||||
}
|
||||
}
|
||||
sessionHandle := dbus.ObjectPath(sessionHandleString)
|
||||
selectDevicesOptions := map[string]dbus.Variant{
|
||||
|
|
@ -165,7 +172,8 @@ func InitPortalController() (Controller, error) {
|
|||
))
|
||||
if err != nil {
|
||||
return nil, &UnsupportedPlatformError{
|
||||
fmt.Errorf("calling 'SelectDevices' failed: %w", err)}
|
||||
fmt.Errorf("calling 'SelectDevices' failed: %w", err),
|
||||
}
|
||||
}
|
||||
startResponseStatus, startResults, err := getResponse(bus, portalDesktop,
|
||||
"org.freedesktop.portal.RemoteDesktop.Start", 0,
|
||||
|
|
@ -173,7 +181,8 @@ func InitPortalController() (Controller, error) {
|
|||
)
|
||||
if err != nil {
|
||||
return nil, &UnsupportedPlatformError{
|
||||
fmt.Errorf("calling 'Start' failed: %w", err)}
|
||||
fmt.Errorf("calling 'Start' failed: %w", err),
|
||||
}
|
||||
}
|
||||
if startResponseStatus != 0 {
|
||||
return nil, errors.New("keyboard or pointer access denied")
|
||||
|
|
@ -186,14 +195,17 @@ func InitPortalController() (Controller, error) {
|
|||
devices, ok := startResults["devices"].Value().(uint32)
|
||||
if !ok {
|
||||
return nil, &UnsupportedPlatformError{
|
||||
errors.New("unexpected 'devices' type in 'Start' return value")}
|
||||
errors.New("unexpected 'devices' type in 'Start' return value"),
|
||||
}
|
||||
}
|
||||
if devices&deviceKeyboard == 0 || devices&devicePointer == 0 {
|
||||
return nil, errors.New("keyboard or pointer access denied")
|
||||
}
|
||||
cleanupBus = false
|
||||
return &portalController{bus: bus, portalDesktop: portalDesktop,
|
||||
sessionHandle: sessionHandle}, nil
|
||||
return &portalController{
|
||||
bus: bus, portalDesktop: portalDesktop,
|
||||
sessionHandle: sessionHandle,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func retrieveSecret(bus *dbus.Conn) ([]byte, error) {
|
||||
|
|
@ -267,11 +279,12 @@ func (s *secretStore) Store(data []byte) error {
|
|||
return err
|
||||
}
|
||||
ciphertext := s.aesgcm.Seal(nil, nonce, data, nil)
|
||||
return os.WriteFile(s.filename, slices.Concat(nonce, ciphertext), 0600)
|
||||
return os.WriteFile(s.filename, slices.Concat(nonce, ciphertext), 0o600)
|
||||
}
|
||||
|
||||
func getResponse(bus *dbus.Conn, object dbus.BusObject, method string,
|
||||
flags dbus.Flags, args ...interface{}) (uint32, map[string]dbus.Variant, error) {
|
||||
flags dbus.Flags, args ...interface{},
|
||||
) (uint32, map[string]dbus.Variant, error) {
|
||||
ch := make(chan *dbus.Signal, 512)
|
||||
bus.Signal(ch)
|
||||
defer bus.RemoveSignal(ch)
|
||||
|
|
|
|||
|
|
@ -25,10 +25,11 @@ package inputcontrol
|
|||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/bendahl/uinput"
|
||||
"log"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/bendahl/uinput"
|
||||
)
|
||||
|
||||
const shiftKeysDelay time.Duration = 50 * time.Millisecond
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ package inputcontrol
|
|||
// return DefaultRootWindow(dpy);
|
||||
// }
|
||||
import "C"
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
|
@ -46,8 +47,10 @@ const (
|
|||
scrollDiv int = 20
|
||||
)
|
||||
|
||||
var modifierIndices [6]uint = [...]uint{C.ShiftMapIndex, C.Mod1MapIndex,
|
||||
C.Mod2MapIndex, C.Mod3MapIndex, C.Mod4MapIndex, C.Mod5MapIndex}
|
||||
var modifierIndices [6]uint = [...]uint{
|
||||
C.ShiftMapIndex, C.Mod1MapIndex,
|
||||
C.Mod2MapIndex, C.Mod3MapIndex, C.Mod4MapIndex, C.Mod5MapIndex,
|
||||
}
|
||||
|
||||
type x11Controller struct {
|
||||
display *C.Display
|
||||
|
|
@ -63,13 +66,15 @@ func InitX11Controller() (Controller, error) {
|
|||
display := C.XOpenDisplay(nil)
|
||||
if display == nil {
|
||||
return nil, &UnsupportedPlatformError{
|
||||
errors.New("failed to connect to X server")}
|
||||
errors.New("failed to connect to X server"),
|
||||
}
|
||||
}
|
||||
p := &x11Controller{display: display}
|
||||
if p.xIsXwayland() {
|
||||
p.Close()
|
||||
return nil, &UnsupportedPlatformError{
|
||||
errors.New("X server is Xwayland")}
|
||||
errors.New("X server is Xwayland"),
|
||||
}
|
||||
}
|
||||
return p, nil
|
||||
}
|
||||
|
|
@ -140,7 +145,8 @@ keycodes:
|
|||
}
|
||||
|
||||
func (p *x11Controller) changeKeyMappingLocked(keysymsPerKeycode C.int,
|
||||
keycode C.KeyCode, keysym Keysym) {
|
||||
keycode C.KeyCode, keysym Keysym,
|
||||
) {
|
||||
keycodeMapping := make([]C.KeySym, keysymsPerKeycode)
|
||||
for i := range keycodeMapping {
|
||||
keycodeMapping[i] = C.KeySym(keysym)
|
||||
|
|
@ -169,7 +175,8 @@ func (p *x11Controller) getModKeycodesLocked() map[uint]C.KeyCode {
|
|||
|
||||
func (p *x11Controller) findKeycodeLocked(keyboard C.XkbDescPtr,
|
||||
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))
|
||||
if keycode == 0 {
|
||||
return 0, 0
|
||||
|
|
@ -204,7 +211,8 @@ func (p *x11Controller) findKeycodeLocked(keyboard C.XkbDescPtr,
|
|||
}
|
||||
|
||||
func (p *x11Controller) sendModsLocked(modKeycodes map[uint]C.KeyCode, mods C.uint,
|
||||
press bool) {
|
||||
press bool,
|
||||
) {
|
||||
var pressC C.int = C.False
|
||||
if press {
|
||||
pressC = C.True
|
||||
|
|
|
|||
7
main.go
7
main.go
|
|
@ -27,9 +27,6 @@ import (
|
|||
"errors"
|
||||
"flag"
|
||||
"fmt"
|
||||
"github.com/unrud/remote-touchpad/inputcontrol"
|
||||
"github.com/unrud/remote-touchpad/terminal"
|
||||
"golang.org/x/net/websocket"
|
||||
"log"
|
||||
mathrand "math/rand"
|
||||
"net"
|
||||
|
|
@ -39,6 +36,10 @@ import (
|
|||
"strings"
|
||||
"time"
|
||||
"unicode/utf8"
|
||||
|
||||
"github.com/unrud/remote-touchpad/inputcontrol"
|
||||
"github.com/unrud/remote-touchpad/terminal"
|
||||
"golang.org/x/net/websocket"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue