Compare commits

..

No commits in common. "master" and "v1.4.4" have entirely different histories.

23 changed files with 209 additions and 808 deletions

View file

@ -23,7 +23,7 @@ jobs:
with: with:
go-version: stable go-version: stable
check-latest: true check-latest: true
- run: sudo apt install libxrandr-dev libxtst-dev libxt-dev - run: sudo apt install libxrandr-dev libxtst-dev
if: ${{ contains(matrix.tags, 'x11') }} if: ${{ contains(matrix.tags, 'x11') }}
- name: Go Format - name: Go Format
@ -38,6 +38,10 @@ jobs:
- name: Go Build - name: Go Build
run: go build ./... run: go build ./...
- name: Go Test
run: go test ./...
if: ${{ matrix.os != 'linux' }}
- name: Go Test (with data race detection) - name: Go Test (with data race detection)
run: go test -race ./... run: go test -race ./...
if: ${{ matrix.os == 'linux' }} if: ${{ matrix.os == 'linux' }}

11
.gitignore vendored
View file

@ -1,11 +0,0 @@
# Binaries
remote-touchpad
# Systemd service state
.remote-touchpad.service.state
# Logs and run files
.rts-log
# Environment files
.env

View file

@ -1,41 +1,5 @@
# Changelog # Changelog
## 1.5.4 (2026-08-02)
* Improve X11 keyboard input
* Update dependencies
## 1.5.3 (2025-12-24)
* Update dependencies
## 1.5.2 (2025-10-12)
* Update dependencies
## 1.5.0 (2025-03-18)
* Add restore token support for the remote desktop portal
* Update dependencies
## 1.4.8 (2024-09-01)
* Update dependencies
## 1.4.7 (2024-08-30)
* Update dependencies
## 1.4.6 (2024-02-06)
* Prevent incorrect MIME types
## 1.4.5 (2024-01-31)
* Keep text input open after sending
* Workaround for virtual keyboard covering buttons (Chromium & iOS)
* Enable hardware keyboard input in mouse mode
## 1.4.4 (2024-01-23) ## 1.4.4 (2024-01-23)
* Fix Xwayland detection on newer servers * Fix Xwayland detection on newer servers

View file

@ -12,45 +12,8 @@ Supports Flatpak's RemoteDesktop portal (for Wayland), Windows and X11.
* [Snap](https://snapcraft.io/remote-touchpad) * [Snap](https://snapcraft.io/remote-touchpad)
* [Windows](https://github.com/Unrud/remote-touchpad/releases/latest) * [Windows](https://github.com/Unrud/remote-touchpad/releases/latest)
* Golang: * Golang:
* Portal & uinput & X11: * Portal & uinput & X11: `go install -tags portal,uinput,x11 github.com/unrud/remote-touchpad@latest`
* Windows: `go install github.com/unrud/remote-touchpad@latest`
```sh
go install -tags portal,uinput,x11 github.com/unrud/remote-touchpad@latest
```
* Windows:
```sh
go install github.com/unrud/remote-touchpad@latest
```
## Linux User Service Installation
To install remote-touchpad as a user-specific systemd service (no root access required):
1. Clone the repository and navigate to the project directory:
```sh
git clone https://github.com/Unrud/remote-touchpad.git
cd remote-touchpad
```
2. Install the service using the provided wrapper script (no sudo required):
```sh
./rts install
```
3. Access the service:
* View service status: `./rts status`
* Get URL: `./rts url`
* View logs: `./rts log`
* Stop service: `./rts stop`
* Start service: `./rts start`
* Restart service: `./rts restart`
* Uninstall: `./rts uninstall`
The service will run in the background and maintain a persistent connection with URL and QR code accessible via the `url` command.
## Screenshots ## Screenshots

View file

@ -17,72 +17,8 @@
<launchable type="desktop-id">com.github.unrud.RemoteTouchpad.desktop</launchable> <launchable type="desktop-id">com.github.unrud.RemoteTouchpad.desktop</launchable>
<url type="bugtracker">https://github.com/Unrud/remote-touchpad/issues</url> <url type="bugtracker">https://github.com/Unrud/remote-touchpad/issues</url>
<url type="homepage">https://github.com/Unrud/remote-touchpad</url> <url type="homepage">https://github.com/Unrud/remote-touchpad</url>
<url type="vcs-browser">https://github.com/Unrud/remote-touchpad</url> <developer_name>Unrud</developer_name>
<developer_name translate="no">Unrud</developer_name>
<developer id="io.github.unrud">
<name translate="no">Unrud</name>
</developer>
<releases> <releases>
<release version="1.5.4" date="2026-08-02">
<description>
<ul>
<li>Improve X11 keyboard input</li>
<li>Update dependencies</li>
</ul>
</description>
</release>
<release version="1.5.3" date="2025-12-24">
<description>
<ul>
<li>Update dependencies</li>
</ul>
</description>
</release>
<release version="1.5.2" date="2025-10-12">
<description>
<ul>
<li>Update dependencies</li>
</ul>
</description>
</release>
<release version="1.5.0" date="2025-03-18">
<description>
<ul>
<li>Add restore token support for the remote desktop portal</li>
<li>Update dependencies</li>
</ul>
</description>
</release>
<release version="1.4.8" date="2024-09-01">
<description>
<ul>
<li>Update dependencies</li>
</ul>
</description>
</release>
<release version="1.4.7" date="2024-08-30">
<description>
<ul>
<li>Update dependencies</li>
</ul>
</description>
</release>
<release version="1.4.6" date="2024-02-06">
<description>
<ul>
<li>Prevent incorrect MIME types</li>
</ul>
</description>
</release>
<release version="1.4.5" date="2024-01-31">
<description>
<ul>
<li>Keep text input open after sending</li>
<li>Workaround for virtual keyboard covering buttons (Chromium &amp; iOS)</li>
<li>Enable hardware keyboard input in mouse mode</li>
</ul>
</description>
</release>
<release version="1.4.4" date="2024-01-23"> <release version="1.4.4" date="2024-01-23">
<description> <description>
<ul> <ul>
@ -373,16 +309,16 @@
</releases> </releases>
<screenshots> <screenshots>
<screenshot type="default"> <screenshot type="default">
<image>https://raw.githubusercontent.com/Unrud/remote-touchpad/v1.5.4/screenshots/1.png</image> <image>https://raw.githubusercontent.com/Unrud/remote-touchpad/v1.4.4/screenshots/1.png</image>
</screenshot> </screenshot>
<screenshot> <screenshot>
<image>https://raw.githubusercontent.com/Unrud/remote-touchpad/v1.5.4/screenshots/2.png</image> <image>https://raw.githubusercontent.com/Unrud/remote-touchpad/v1.4.4/screenshots/2.png</image>
</screenshot> </screenshot>
<screenshot> <screenshot>
<image>https://raw.githubusercontent.com/Unrud/remote-touchpad/v1.5.4/screenshots/3.png</image> <image>https://raw.githubusercontent.com/Unrud/remote-touchpad/v1.4.4/screenshots/3.png</image>
</screenshot> </screenshot>
<screenshot> <screenshot>
<image>https://raw.githubusercontent.com/Unrud/remote-touchpad/v1.5.4/screenshots/4.png</image> <image>https://raw.githubusercontent.com/Unrud/remote-touchpad/v1.4.4/screenshots/4.png</image>
</screenshot> </screenshot>
</screenshots> </screenshots>
<content_rating type="oars-1.1"/> <content_rating type="oars-1.1"/>

View file

@ -1,6 +1,6 @@
app-id: com.github.unrud.RemoteTouchpad app-id: com.github.unrud.RemoteTouchpad
runtime: org.freedesktop.Platform runtime: org.freedesktop.Platform
runtime-version: '25.08' runtime-version: '23.08'
sdk: org.freedesktop.Sdk sdk: org.freedesktop.Sdk
command: remote-touchpad command: remote-touchpad
sdk-extensions: sdk-extensions:
@ -8,17 +8,19 @@ sdk-extensions:
finish-args: finish-args:
- --socket=fallback-x11 - --socket=fallback-x11
- --socket=wayland - --socket=wayland
- --share=ipc # Required by Flathub linter
- --share=network - --share=network
modules: modules:
- name: remote-touchpad - name: remote-touchpad
sources: sources:
- type: git - type: git
path: .. path: ..
- type: shell
commands:
- . /usr/lib/sdk/golang/enable.sh; go mod vendor -e
- type: git - type: git
url: https://github.com/godbus/dbus url: https://github.com/godbus/dbus
tag: v5.2.2 tag: v5.1.0
commit: a8ac15ba63645f02ffd57f4b443203279ab40b30 commit: e523abc905595cf17fb0001a7d77eaaddfaa216d
dest: vendor/github.com/godbus/dbus/v5 dest: vendor/github.com/godbus/dbus/v5
- type: git - type: git
url: https://github.com/skip2/go-qrcode url: https://github.com/skip2/go-qrcode
@ -26,17 +28,9 @@ modules:
dest: vendor/github.com/skip2/go-qrcode dest: vendor/github.com/skip2/go-qrcode
- type: git - type: git
url: https://github.com/golang/net url: https://github.com/golang/net
tag: v0.57.0 tag: v0.20.0
commit: b8f09f6f062ceb4531b7af4bd17a5c8fe9c4b2b5 commit: cb5b10f0bbc51089bf49030ce3bd43bbfee08c23
dest: vendor/golang.org/x/net dest: vendor/golang.org/x/net
- type: git
url: https://github.com/golang/sys
tag: v0.47.0
commit: 9e7e939dcafac07e8ab4cffa6e5fc74908413f00
dest: vendor/golang.org/x/sys
- type: file
path: modules.txt
dest: vendor
buildsystem: simple buildsystem: simple
build-commands: build-commands:
- . /usr/lib/sdk/golang/enable.sh; go build -tags portal,x11 - . /usr/lib/sdk/golang/enable.sh; go build -tags portal,x11

View file

@ -1,17 +0,0 @@
# github.com/bendahl/uinput v1.7.0
## explicit; go 1.13
github.com/bendahl/uinput
# github.com/godbus/dbus/v5 v5.2.2
## explicit; go 1.20
github.com/godbus/dbus/v5
# github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e
## explicit; go 1.13
github.com/skip2/go-qrcode
github.com/skip2/go-qrcode/bitset
github.com/skip2/go-qrcode/reedsolomon
# golang.org/x/net v0.57.0
## explicit; go 1.25.0
golang.org/x/net/websocket
# golang.org/x/sys v0.47.0
## explicit; go 1.25.0
golang.org/x/sys/unix

8
go.mod
View file

@ -1,12 +1,10 @@
module github.com/unrud/remote-touchpad module github.com/unrud/remote-touchpad
go 1.25.5 go 1.20
require ( require (
github.com/bendahl/uinput v1.7.0 github.com/bendahl/uinput v1.7.0
github.com/godbus/dbus/v5 v5.2.2 github.com/godbus/dbus/v5 v5.1.0
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e
golang.org/x/net v0.57.0 golang.org/x/net v0.20.0
) )
require golang.org/x/sys v0.47.0 // indirect

10
go.sum
View file

@ -1,10 +1,8 @@
github.com/bendahl/uinput v1.7.0 h1:nA4fm8Wu8UYNOPykIZm66nkWEyvxzfmJ8YC02PM40jg= github.com/bendahl/uinput v1.7.0 h1:nA4fm8Wu8UYNOPykIZm66nkWEyvxzfmJ8YC02PM40jg=
github.com/bendahl/uinput v1.7.0/go.mod h1:Np7w3DINc9wB83p12fTAM3DPPhFnAKP0WTXRqCQJ6Z8= github.com/bendahl/uinput v1.7.0/go.mod h1:Np7w3DINc9wB83p12fTAM3DPPhFnAKP0WTXRqCQJ6Z8=
github.com/godbus/dbus/v5 v5.2.2 h1:TUR3TgtSVDmjiXOgAAyaZbYmIeP3DPkld3jgKGV8mXQ= github.com/godbus/dbus/v5 v5.1.0 h1:4KLkAxT3aOY8Li4FRJe/KvhoNFFxo0m6fNuFUO8QJUk=
github.com/godbus/dbus/v5 v5.2.2/go.mod h1:3AAv2+hPq5rdnr5txxxRwiGjPXamgoIHgz9FPBfOp3c= github.com/godbus/dbus/v5 v5.1.0/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e h1:MRM5ITcdelLK2j1vwZ3Je0FKVCfqOLp5zO6trqMLYs0= github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e h1:MRM5ITcdelLK2j1vwZ3Je0FKVCfqOLp5zO6trqMLYs0=
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e/go.mod h1:XV66xRDqSt+GTGFMVlhk3ULuV0y9ZmzeVGR4mloJI3M= github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e/go.mod h1:XV66xRDqSt+GTGFMVlhk3ULuV0y9ZmzeVGR4mloJI3M=
golang.org/x/net v0.57.0 h1:K5+3DljvIuDG9/Jv9rvyMywYNFCQ9RSUY6OOTTkT+tE= golang.org/x/net v0.20.0 h1:aCL9BSgETF1k+blQaYUBx9hJ9LOGP3gAVemcZlf1Kpo=
golang.org/x/net v0.57.0/go.mod h1:KpXc8iv+r3XplLAG/f7Jsf9RPszJzdR0f58q9vGOuEU= golang.org/x/net v0.20.0/go.mod h1:z8BVo6PvndSri0LbOE3hAn0apkU+1YvI6E70E9jsnvY=
golang.org/x/sys v0.47.0 h1:o7XGOvZQCADBQQ4Y7VNq2dRWQR7JmOUW8Kxx4ZsNgWs=
golang.org/x/sys v0.47.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=

View file

@ -74,8 +74,7 @@ func findDefaultHost() string {
continue continue
} }
for _, linkLocalPrefix := range []string{ for _, linkLocalPrefix := range []string{
"169.254.", "fe8", "fe9", "fea", "feb", "169.254.", "fe8", "fe9", "fea", "feb"} {
} {
if strings.HasPrefix(ip.String(), linkLocalPrefix) { if strings.HasPrefix(ip.String(), linkLocalPrefix) {
addIP(20, ip) addIP(20, ip)
continue addrs continue addrs

View file

@ -21,10 +21,8 @@ package inputcontrol
import "sort" import "sort"
type ( type PointerButton int
PointerButton int type Key int
Key int
)
const ( const (
PointerButtonLeft PointerButton = iota PointerButtonLeft PointerButton = iota

View file

@ -22,19 +22,8 @@
package inputcontrol package inputcontrol
import ( import (
"crypto/aes"
"crypto/cipher"
"crypto/hkdf"
"crypto/rand"
"crypto/sha256"
"errors" "errors"
"fmt" "fmt"
"io"
"log"
"os"
"path/filepath"
"slices"
"github.com/godbus/dbus/v5" "github.com/godbus/dbus/v5"
) )
@ -45,8 +34,6 @@ const (
btnReleased uint32 = 0 btnReleased uint32 = 0
btnPressed uint32 = 1 btnPressed uint32 = 1
untilRevoked uint32 = 2
// linux/input-event-codes.h // linux/input-event-codes.h
btnLeft int32 = 0x110 btnLeft int32 = 0x110
btnRight int32 = 0x111 btnRight int32 = 0x111
@ -55,7 +42,7 @@ const (
type portalController struct { type portalController struct {
bus *dbus.Conn bus *dbus.Conn
portalDesktop dbus.BusObject remoteDesktop dbus.BusObject
sessionHandle dbus.ObjectPath sessionHandle dbus.ObjectPath
} }
@ -82,209 +69,85 @@ func InitPortalController() (Controller, error) {
if err != nil { if err != nil {
return nil, &UnsupportedPlatformError{err} return nil, &UnsupportedPlatformError{err}
} }
portalDesktop := bus.Object("org.freedesktop.portal.Desktop", remoteDesktop := bus.Object("org.freedesktop.portal.Desktop",
"/org/freedesktop/portal/desktop") "/org/freedesktop/portal/desktop")
remoteDesktopVersionV, err := portalDesktop.GetProperty( availableDeviceTypesV, err := remoteDesktop.GetProperty(
"org.freedesktop.portal.RemoteDesktop.version")
if err != nil {
return nil, &UnsupportedPlatformError{
fmt.Errorf("getting 'version' failed: %w", err),
}
}
remoteDesktopVersion, ok := remoteDesktopVersionV.Value().(uint32)
if !ok {
return nil, &UnsupportedPlatformError{
errors.New("unexpected 'version' type"),
}
}
restoreTokenStore, err := func() (*secretStore, error) {
if remoteDesktopVersion < 2 {
return nil, nil
}
cacheDirectory, err := os.UserCacheDir()
if err != nil {
return nil, err
}
if err := os.MkdirAll(cacheDirectory, 0o700); err != nil {
return nil, err
}
secret, err := retrieveSecret(bus)
if err != nil {
return nil, err
}
return newSecretStore(secret,
filepath.Join(cacheDirectory, "remote-touchpad.portal-restore-token.bin"))
}()
if err != nil {
log.Printf("Skipping restore token: %v", err)
}
availableDeviceTypesV, err := portalDesktop.GetProperty(
"org.freedesktop.portal.RemoteDesktop.AvailableDeviceTypes") "org.freedesktop.portal.RemoteDesktop.AvailableDeviceTypes")
if err != nil { if err != nil {
return nil, &UnsupportedPlatformError{ return nil, &UnsupportedPlatformError{err}
fmt.Errorf("getting 'AvailableDeviceTypes' failed: %w", err),
}
} }
availableDeviceTypes, ok := availableDeviceTypesV.Value().(uint32) availableDeviceTypes, ok := availableDeviceTypesV.Value().(uint32)
if !ok { if !ok {
return nil, &UnsupportedPlatformError{ return nil, &UnsupportedPlatformError{
errors.New("unexpected 'AvailableDeviceTypes' return type"), errors.New("unexpected 'AvailableDeviceTypes' return type")}
}
} }
if availableDeviceTypes&deviceKeyboard == 0 || if availableDeviceTypes&deviceKeyboard == 0 ||
availableDeviceTypes&devicePointer == 0 { availableDeviceTypes&devicePointer == 0 {
return nil, &UnsupportedPlatformError{ 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, inVardict := make(map[string]dbus.Variant)
"org.freedesktop.portal.RemoteDesktop.CreateSession", 0, inVardict["session_handle_token"] = dbus.MakeVariant("t")
map[string]dbus.Variant{"session_handle_token": dbus.MakeVariant("t")}, result, outVardict, err := getResponse(bus, remoteDesktop,
)) "org.freedesktop.portal.RemoteDesktop.CreateSession", 0, inVardict)
if err != nil { if err != nil {
return nil, &UnsupportedPlatformError{ return nil, &UnsupportedPlatformError{err}
fmt.Errorf("calling 'CreateSession' failed: %w", err),
}
} }
sessionHandleString, ok := createSessionResults["session_handle"].Value().(string) if result != 0 {
return nil, &UnsupportedPlatformError{
fmt.Errorf("Calling 'CreateSession' failed (%v)", result)}
}
sessionHandleV, ok := outVardict["session_handle"]
if !ok { if !ok {
return nil, &UnsupportedPlatformError{ return nil, &UnsupportedPlatformError{
errors.New("unexpected 'session_handle' type in 'CreateSession' return value"), errors.New("'session_handle' missing from 'CreateSession' return value")}
}
} }
sessionHandle := dbus.ObjectPath(sessionHandleString) sessionHandleS, ok := sessionHandleV.Value().(string)
selectDevicesOptions := map[string]dbus.Variant{ if !ok {
"types": dbus.MakeVariant(deviceKeyboard | devicePointer),
}
if restoreTokenStore != nil {
if restoreToken, err := restoreTokenStore.Load(); err != nil {
if !errors.Is(err, os.ErrNotExist) {
log.Printf("Failed to load restore token: %v", err)
}
} else if len(restoreToken) > 0 {
selectDevicesOptions["restore_token"] = dbus.MakeVariant(string(restoreToken))
}
selectDevicesOptions["persist_mode"] = dbus.MakeVariant(untilRevoked)
}
_, err = checkResponse(getResponse(bus, portalDesktop,
"org.freedesktop.portal.RemoteDesktop.SelectDevices", 0,
sessionHandle, selectDevicesOptions,
))
if err != nil {
return nil, &UnsupportedPlatformError{ return nil, &UnsupportedPlatformError{
fmt.Errorf("calling 'SelectDevices' failed: %w", err), errors.New("unexpected 'session_handle' type in 'CreateSession' return value")}
}
} }
startResponseStatus, startResults, err := getResponse(bus, portalDesktop, sessionHandle := dbus.ObjectPath(sessionHandleS)
"org.freedesktop.portal.RemoteDesktop.Start", 0, inVardict = make(map[string]dbus.Variant)
sessionHandle, "", map[string]dbus.Variant{}, inVardict["types"] = dbus.MakeVariant(deviceKeyboard | devicePointer)
) result, outVardict, err = getResponse(bus, remoteDesktop,
"org.freedesktop.portal.RemoteDesktop.SelectDevices", 0, sessionHandle, inVardict)
if err != nil { if err != nil {
return nil, &UnsupportedPlatformError{ return nil, &UnsupportedPlatformError{err}
fmt.Errorf("calling 'Start' failed: %w", err),
}
} }
if startResponseStatus != 0 { if result != 0 {
return nil, &UnsupportedPlatformError{
fmt.Errorf("Calling 'SelectDevices' failed (%v)", result)}
}
inVardict = make(map[string]dbus.Variant)
result, outVardict, err = getResponse(bus, remoteDesktop,
"org.freedesktop.portal.RemoteDesktop.Start", 0, sessionHandle, "", inVardict)
if err != nil {
return nil, &UnsupportedPlatformError{err}
}
if result != 0 {
return nil, errors.New("keyboard or pointer access denied") return nil, errors.New("keyboard or pointer access denied")
} }
if restoreToken, _ := startResults["restore_token"].Value().(string); restoreTokenStore != nil { devicesV, ok := outVardict["devices"]
if err := restoreTokenStore.Store([]byte(restoreToken)); err != nil {
log.Printf("Failed to store restore token: %v", err)
}
}
devices, ok := startResults["devices"].Value().(uint32)
if !ok { if !ok {
return nil, &UnsupportedPlatformError{ return nil, &UnsupportedPlatformError{
errors.New("unexpected 'devices' type in 'Start' return value"), errors.New("'devices' missing from 'Start' return value")}
} }
devices, ok := devicesV.Value().(uint32)
if !ok {
return nil, &UnsupportedPlatformError{
errors.New("unexpected 'devices' type in 'Start' return value")}
} }
if devices&deviceKeyboard == 0 || devices&devicePointer == 0 { if devices&deviceKeyboard == 0 || devices&devicePointer == 0 {
return nil, errors.New("keyboard or pointer access denied") return nil, errors.New("keyboard or pointer access denied")
} }
cleanupBus = false cleanupBus = false
return &portalController{ return &portalController{bus: bus, remoteDesktop: remoteDesktop,
bus: bus, portalDesktop: portalDesktop, sessionHandle: sessionHandle}, nil
sessionHandle: sessionHandle,
}, nil
}
func retrieveSecret(bus *dbus.Conn) ([]byte, error) {
portalDesktop := bus.Object("org.freedesktop.portal.Desktop",
"/org/freedesktop/portal/desktop")
secretReader, secretWriter, err := os.Pipe()
if err != nil {
return nil, err
}
defer secretReader.Close()
defer secretWriter.Close()
if _, err := checkResponse(getResponse(bus, portalDesktop,
"org.freedesktop.portal.Secret.RetrieveSecret", 0,
dbus.UnixFD(secretWriter.Fd()), map[string]dbus.Variant{},
)); err != nil {
return nil, fmt.Errorf("calling 'RetrieveSecret' failed: %w", err)
}
if err := secretWriter.Close(); err != nil {
return nil, err
}
secret, err := io.ReadAll(secretReader)
if err != nil {
return nil, err
}
if len(secret) < 16 {
return nil, fmt.Errorf("'RetrieveSecret' returned too few bytes (%d)", len(secret))
}
return secret, err
}
type secretStore struct {
aesgcm cipher.AEAD
filename string
}
func newSecretStore(key []byte, filename string) (*secretStore, error) {
derivedKey, err := hkdf.Key(sha256.New, key, nil, "", 32)
if err != nil {
return nil, err
}
block, err := aes.NewCipher(derivedKey)
if err != nil {
return nil, err
}
aesgcm, err := cipher.NewGCM(block)
if err != nil {
return nil, err
}
return &secretStore{
aesgcm: aesgcm,
filename: filename,
}, nil
}
func (s *secretStore) Load() ([]byte, error) {
data, err := os.ReadFile(s.filename)
if err != nil {
return nil, err
}
if len(data) < s.aesgcm.NonceSize() {
return nil, errors.New("invalid ciphertext")
}
nonce := data[:s.aesgcm.NonceSize()]
ciphertext := data[len(nonce):]
return s.aesgcm.Open(nil, nonce, ciphertext, nil)
}
func (s *secretStore) Store(data []byte) error {
nonce := make([]byte, s.aesgcm.NonceSize())
if _, err := io.ReadFull(rand.Reader, nonce); err != nil {
return err
}
ciphertext := s.aesgcm.Seal(nil, nonce, data, nil)
return os.WriteFile(s.filename, slices.Concat(nonce, ciphertext), 0o600)
} }
func getResponse(bus *dbus.Conn, object dbus.BusObject, method string, func getResponse(bus *dbus.Conn, object dbus.BusObject, method string,
flags dbus.Flags, args ...interface{}, flags dbus.Flags, args ...interface{}) (uint32, map[string]dbus.Variant, error) {
) (uint32, map[string]dbus.Variant, error) {
ch := make(chan *dbus.Signal, 512) ch := make(chan *dbus.Signal, 512)
bus.Signal(ch) bus.Signal(ch)
defer bus.RemoveSignal(ch) defer bus.RemoveSignal(ch)
@ -296,39 +159,32 @@ func getResponse(bus *dbus.Conn, object dbus.BusObject, method string,
s := <-ch s := <-ch
if s.Path == requestPath && s.Name == "org.freedesktop.portal.Request.Response" { if s.Path == requestPath && s.Name == "org.freedesktop.portal.Request.Response" {
if len(s.Body) != 2 { if len(s.Body) != 2 {
return 0, nil, fmt.Errorf("unexpected 'Response' return length (%d)", len(s.Body)) return 0, nil, errors.New("unexpected 'Response' return length")
} }
responseStatus, ok := s.Body[0].(uint32) result, ok := s.Body[0].(uint32)
if !ok { if !ok {
return 0, nil, errors.New("unexpected 'Response' return type") return 0, nil, errors.New("unexpected 'Response' return type")
} }
results, ok := s.Body[1].(map[string]dbus.Variant) outVardict, ok := s.Body[1].(map[string]dbus.Variant)
if !ok { if !ok {
return 0, nil, errors.New("unexpected 'Response' return type") return 0, nil, errors.New("unexpected 'Response' return type")
} }
return responseStatus, results, nil return result, outVardict, nil
} }
} }
} }
func checkResponse(responseStatus uint32, results map[string]dbus.Variant, err error) (map[string]dbus.Variant, error) {
if err == nil && responseStatus != 0 {
err = fmt.Errorf("unexpected 'Response' status (%d)", responseStatus)
}
return results, err
}
func (p *portalController) Close() error { func (p *portalController) Close() error {
return p.bus.Close() return p.bus.Close()
} }
func (p *portalController) keyboardKeys(keys []Keysym) error { func (p *portalController) keyboardKeys(keys []Keysym) error {
inVardict := make(map[string]dbus.Variant)
for _, keysym := range keys { for _, keysym := range keys {
for _, state := range [...]uint32{btnPressed, btnReleased} { for _, state := range [...]uint32{btnPressed, btnReleased} {
if err := p.portalDesktop.Call( if err := p.remoteDesktop.Call(
"org.freedesktop.portal.RemoteDesktop.NotifyKeyboardKeysym", 0, "org.freedesktop.portal.RemoteDesktop.NotifyKeyboardKeysym",
p.sessionHandle, map[string]dbus.Variant{}, keysym, state, 0, p.sessionHandle, inVardict, keysym, state).Store(); err != nil {
).Store(); err != nil {
return err return err
} }
} }
@ -373,27 +229,28 @@ func (p *portalController) PointerButton(button PointerButton, press bool) error
if press { if press {
state = btnPressed state = btnPressed
} }
if err := p.portalDesktop.Call("org.freedesktop.portal.RemoteDesktop.NotifyPointerButton", 0, inVardict := make(map[string]dbus.Variant)
p.sessionHandle, map[string]dbus.Variant{}, btn, state, if err := p.remoteDesktop.Call("org.freedesktop.portal.RemoteDesktop.NotifyPointerButton",
).Store(); err != nil { 0, p.sessionHandle, inVardict, btn, state).Store(); err != nil {
return err return err
} }
return nil return nil
} }
func (p *portalController) PointerMove(deltaX, deltaY int) error { func (p *portalController) PointerMove(deltaX, deltaY int) error {
if err := p.portalDesktop.Call("org.freedesktop.portal.RemoteDesktop.NotifyPointerMotion", 0, inVardict := make(map[string]dbus.Variant)
p.sessionHandle, map[string]dbus.Variant{}, float64(deltaX), float64(deltaY), if err := p.remoteDesktop.Call("org.freedesktop.portal.RemoteDesktop.NotifyPointerMotion",
).Store(); err != nil { 0, p.sessionHandle, inVardict, float64(deltaX), float64(deltaY)).Store(); err != nil {
return err return err
} }
return nil return nil
} }
func (p *portalController) PointerScroll(deltaHorizontal, deltaVertical int, finish bool) error { func (p *portalController) PointerScroll(deltaHorizontal, deltaVertical int, finish bool) error {
if err := p.portalDesktop.Call("org.freedesktop.portal.RemoteDesktop.NotifyPointerAxis", 0, inVardict := make(map[string]dbus.Variant)
p.sessionHandle, map[string]dbus.Variant{"finish": dbus.MakeVariant(finish)}, float64(deltaHorizontal), float64(deltaVertical), inVardict["finish"] = dbus.MakeVariant(finish)
).Store(); err != nil { if err := p.remoteDesktop.Call("org.freedesktop.portal.RemoteDesktop.NotifyPointerAxis",
0, p.sessionHandle, inVardict, float64(deltaHorizontal), float64(deltaVertical)).Store(); err != nil {
return err return err
} }
return nil return nil

View file

@ -25,11 +25,10 @@ package inputcontrol
import ( import (
"errors" "errors"
"fmt" "fmt"
"github.com/bendahl/uinput"
"log" "log"
"os" "os"
"time" "time"
"github.com/bendahl/uinput"
) )
const shiftKeysDelay time.Duration = 50 * time.Millisecond const shiftKeysDelay time.Duration = 50 * time.Millisecond

View file

@ -32,12 +32,9 @@ package inputcontrol
// return DefaultRootWindow(dpy); // return DefaultRootWindow(dpy);
// } // }
import "C" import "C"
import ( import (
"errors" "errors"
"fmt" "fmt"
"maps"
"slices"
"strings" "strings"
"sync" "sync"
"time" "time"
@ -45,18 +42,12 @@ import (
) )
const ( const (
keyboardMappingDelay time.Duration = 200 * time.Millisecond keyboardMappingDelay time.Duration = 500 * time.Millisecond
scrollDiv int = 20 scrollDiv int = 20
) )
var modifierIndexes = [...]int{ var modifierIndices [6]uint = [...]uint{C.ShiftMapIndex, C.Mod1MapIndex,
C.ShiftMapIndex, C.Mod2MapIndex, C.Mod3MapIndex, C.Mod4MapIndex, C.Mod5MapIndex}
C.Mod1MapIndex,
C.Mod2MapIndex,
C.Mod3MapIndex,
C.Mod4MapIndex,
C.Mod5MapIndex,
}
type x11Controller struct { type x11Controller struct {
display *C.Display display *C.Display
@ -72,15 +63,13 @@ func InitX11Controller() (Controller, error) {
display := C.XOpenDisplay(nil) display := C.XOpenDisplay(nil)
if display == nil { if display == nil {
return nil, &UnsupportedPlatformError{ return nil, &UnsupportedPlatformError{
errors.New("failed to connect to X server"), errors.New("failed to connect to X server")}
}
} }
p := &x11Controller{display: display} p := &x11Controller{display: display}
if p.xIsXwayland() { if p.xIsXwayland() {
p.Close() p.Close()
return nil, &UnsupportedPlatformError{ return nil, &UnsupportedPlatformError{
errors.New("X server is Xwayland"), errors.New("X server is Xwayland")}
}
} }
return p, nil return p, nil
} }
@ -124,68 +113,53 @@ func (p *x11Controller) Close() error {
return nil return nil
} }
func (p *x11Controller) findEmptyKeycodeLocked() (keycode C.KeyCode, keysymsPerKeycode int, err error) { func (p *x11Controller) 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 keysymsPerKeycodeC C.int var keysymsPerKeycode C.int
keysyms := C.XGetKeyboardMapping( keysyms := C.XGetKeyboardMapping(p.display, C.KeyCode(minKeycodes),
p.display, maxKeycodes-minKeycodes+1, &keysymsPerKeycode)
C.KeyCode(minKeycodes),
maxKeycodes-minKeycodes+1,
&keysymsPerKeycodeC,
)
if keysyms == nil { if keysyms == nil {
return 0, 0, errors.New("failed to get keyboard mapping") return 0, 0, errors.New("failed to get keyboard mapping")
} }
defer C.XFree(unsafe.Pointer(keysyms)) defer C.XFree(unsafe.Pointer(keysyms))
keysymsPerKeycode = int(keysymsPerKeycodeC)
keycodes: keycodes:
for keycode := int(minKeycodes); keycode <= int(maxKeycodes); keycode++ { for keycode := C.KeyCode(minKeycodes); keycode <= C.KeyCode(maxKeycodes); keycode++ {
for i := range keysymsPerKeycode { for i := 0; i < int(keysymsPerKeycode); i++ {
keysymsIndex := (keycode-int(minKeycodes))*keysymsPerKeycode + i keysymsIndex := int(keycode-
keysym := *(*C.KeySym)(unsafe.Pointer( C.KeyCode(minKeycodes))*int(keysymsPerKeycode) + i
uintptr(unsafe.Pointer(keysyms)) + keysym := *(*C.KeySym)(unsafe.Pointer(uintptr(unsafe.Pointer(keysyms)) +
uintptr(keysymsIndex)*unsafe.Sizeof(*keysyms), uintptr(keysymsIndex)*unsafe.Sizeof(*keysyms)))
))
if keysym != 0 { if keysym != 0 {
continue keycodes continue keycodes
} }
} }
return C.KeyCode(keycode), keysymsPerKeycode, nil return keycode, keysymsPerKeycode, nil
} }
return 0, 0, errors.New("no empty keycode found") return 0, 0, errors.New("no empty keycode found")
} }
func (p *x11Controller) changeKeyMappingLocked( func (p *x11Controller) changeKeyMappingLocked(keysymsPerKeycode C.int,
keycode C.KeyCode, keysymsPerKeycode int, 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 {
keycodeMapping[i] = C.KeySym(keysym) keycodeMapping[i] = C.KeySym(keysym)
} }
C.XChangeKeyboardMapping( C.XChangeKeyboardMapping(p.display, C.int(keycode), keysymsPerKeycode,
p.display, (*C.KeySym)(unsafe.Pointer(&keycodeMapping[0])), 1)
C.int(keycode), C.XFlush(p.display)
C.int(keysymsPerKeycode),
(*C.KeySym)(unsafe.Pointer(&keycodeMapping[0])),
1,
)
C.XSync(p.display, C.False)
} }
func (p *x11Controller) getModKeycodesLocked() map[uint]C.KeyCode { func (p *x11Controller) 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)
for _, modIndex := range modifierIndexes { for _, modIndex := range modifierIndices {
for i := range int(modKeymap.max_keypermod) { for i := 0; i < int(modKeymap.max_keypermod); i++ {
keycodeIndex := modIndex*int(modKeymap.max_keypermod) + i keycode := *(*C.KeyCode)(unsafe.Pointer(uintptr(unsafe.Pointer(modKeymap.modifiermap)) +
keycode := *(*C.KeyCode)(unsafe.Pointer( uintptr(uint(modIndex)*uint(modKeymap.max_keypermod)+uint(i))))
uintptr(unsafe.Pointer(modKeymap.modifiermap)) +
uintptr(keycodeIndex)*unsafe.Sizeof(*modKeymap.modifiermap),
))
if keycode != 0 { if keycode != 0 {
modKeycodes[1<<modIndex] = keycode modKeycodes[1<<uint(modIndex)] = keycode
break break
} }
} }
@ -193,39 +167,50 @@ func (p *x11Controller) getModKeycodesLocked() map[uint]C.KeyCode {
return modKeycodes return modKeycodes
} }
func (p *x11Controller) findKeycodeLocked( func (p *x11Controller) findKeycodeLocked(keyboard C.XkbDescPtr,
keyboard C.XkbDescPtr, modKeycodes map[uint]C.KeyCode, activeMods uint, keysym Keysym, modKeycodes map[uint]C.KeyCode, activeMods C.uint,
) (keycode C.KeyCode, mods uint) { keysym Keysym) (C.KeyCode, C.uint) {
keycode = C.XKeysymToKeycode(p.display, C.KeySym(keysym)) keycode := C.XKeysymToKeycode(p.display, C.KeySym(keysym))
if keycode == 0 { if keycode == 0 {
return 0, 0 return 0, 0
} }
for activeModBitmap := range uint(1) << len(modKeycodes) { var alwaysActiveMods C.uint
mods := activeMods for modIndex := uint(0); modIndex < 8; modIndex++ {
for i, mod := range slices.Sorted(maps.Keys(modKeycodes)) { mod := uint(1) << modIndex
if activeModBitmap&(1<<i) != 0 { if _, modAvailable := modKeycodes[mod]; !modAvailable {
mods ^= mod alwaysActiveMods |= activeMods & C.uint(mod)
}
} }
var retMods C.uint }
var retKeysym C.KeySym _, shiftModAvailable := modKeycodes[C.ShiftMask]
C.XkbTranslateKeyCode(keyboard, keycode, C.uint(mods), &retMods, &retKeysym) for _, modIndex := range modifierIndices {
if retKeysym == C.KeySym(keysym) { var mod C.uint
return keycode, mods if modIndex != C.ShiftMapIndex {
mod = 1 << modIndex
}
for _, shiftMod := range [...]C.uint{0, C.ShiftMask} {
if shiftMod != 0 && !shiftModAvailable {
continue
}
mods := alwaysActiveMods | shiftMod | mod
var retMods C.uint
var retKeysym C.KeySym
C.XkbTranslateKeyCode(keyboard, keycode, mods, &retMods, &retKeysym)
if retKeysym == C.KeySym(keysym) {
return keycode, mods
}
} }
} }
return 0, 0 return 0, 0
} }
func (p *x11Controller) sendModsLocked( func (p *x11Controller) sendModsLocked(modKeycodes map[uint]C.KeyCode, mods C.uint,
modKeycodes map[uint]C.KeyCode, mods uint, press bool, press bool) {
) {
var pressC C.int = C.False var pressC C.int = C.False
if press { if press {
pressC = C.True pressC = C.True
} }
for mod, keycode := range modKeycodes { for mod, keycode := range modKeycodes {
if mods&mod != 0 { if mods&C.uint(mod) != 0 {
C.XTestFakeKeyEvent(p.display, C.uint(keycode), pressC, 0) C.XTestFakeKeyEvent(p.display, C.uint(keycode), pressC, 0)
} }
} }
@ -246,22 +231,17 @@ func (p *x11Controller) keyboardKeys(keys []Keysym) error {
C.XkbCompatMapMask|C.XkbGeometryMask, C.XkbUseCoreKbd) C.XkbCompatMapMask|C.XkbGeometryMask, C.XkbUseCoreKbd)
defer C.XkbFreeKeyboard(keyboard, C.XkbAllComponentsMask, C.True) defer C.XkbFreeKeyboard(keyboard, C.XkbAllComponentsMask, C.True)
var emptyKeycode C.KeyCode var emptyKeycode C.KeyCode
var keysymsPerKeycode int var keysymsPerKeycode C.int
for _, keysym := range keys { for _, keysym := range keys {
var root, child C.Window var root, child C.Window
var rootX, rootY, x, y C.int var rootX, rootY, x, y C.int
var activeModsC C.uint var activeMods C.uint
C.XQueryPointer( C.XSync(p.display, C.False)
p.display, C.XQueryPointer(p.display, rootWindow, &root, &child, &rootX, &rootY,
rootWindow, &x, &y, &activeMods)
&root, &child, keycode, mods := p.findKeycodeLocked(keyboard, modKeycodes, activeMods,
&rootX, &rootY, keysym)
&x, &y, var pressMods, releaseMods C.uint
&activeModsC,
)
activeMods := uint(activeModsC)
keycode, mods := p.findKeycodeLocked(keyboard, modKeycodes, activeMods, keysym)
var pressMods, releaseMods uint
if keycode == 0 { if keycode == 0 {
if emptyKeycode == 0 { if emptyKeycode == 0 {
var err error var err error
@ -269,10 +249,12 @@ func (p *x11Controller) keyboardKeys(keys []Keysym) error {
if err != nil { if err != nil {
return err return err
} }
defer p.changeKeyMappingLocked(emptyKeycode, keysymsPerKeycode, 0) defer p.changeKeyMappingLocked(keysymsPerKeycode, emptyKeycode, 0)
} }
keycode = emptyKeycode keycode = emptyKeycode
p.changeKeyMappingLocked(keycode, keysymsPerKeycode, keysym) p.changeKeyMappingLocked(keysymsPerKeycode, keycode, keysym)
// race condition!
time.Sleep(keyboardMappingDelay)
} else { } else {
pressMods = mods & ^activeMods pressMods = mods & ^activeMods
releaseMods = activeMods & ^mods releaseMods = activeMods & ^mods
@ -283,7 +265,7 @@ func (p *x11Controller) keyboardKeys(keys []Keysym) error {
C.XTestFakeKeyEvent(p.display, C.uint(keycode), C.False, 0) C.XTestFakeKeyEvent(p.display, C.uint(keycode), C.False, 0)
p.sendModsLocked(modKeycodes, pressMods, false) p.sendModsLocked(modKeycodes, pressMods, false)
p.sendModsLocked(modKeycodes, releaseMods, true) p.sendModsLocked(modKeycodes, releaseMods, true)
C.XSync(p.display, C.False) C.XFlush(p.display)
if keycode == emptyKeycode { if keycode == emptyKeycode {
// race condition! // race condition!
time.Sleep(keyboardMappingDelay) time.Sleep(keyboardMappingDelay)
@ -327,7 +309,7 @@ func (p *x11Controller) sendButton(button uint, press bool) error {
pressC = C.True pressC = C.True
} }
C.XTestFakeButtonEvent(p.display, C.uint(button), pressC, 0) C.XTestFakeButtonEvent(p.display, C.uint(button), pressC, 0)
C.XSync(p.display, C.False) C.XFlush(p.display)
return nil return nil
} }
@ -351,7 +333,7 @@ func (p *x11Controller) PointerMove(deltaX, deltaY int) error {
return errors.New("X server connection closed") return errors.New("X server connection closed")
} }
C.XTestFakeRelativeMotionEvent(p.display, C.int(deltaX), C.int(deltaY), 0) C.XTestFakeRelativeMotionEvent(p.display, C.int(deltaX), C.int(deltaY), 0)
C.XSync(p.display, C.False) C.XFlush(p.display)
return nil return nil
} }
@ -372,7 +354,7 @@ func (p *x11Controller) PointerScroll(deltaHorizontal, deltaVertical int, finish
buttonHorizontal = 6 buttonHorizontal = 6
stepsHorizontal = -stepsHorizontal stepsHorizontal = -stepsHorizontal
} }
for range stepsHorizontal { for i := 0; i < stepsHorizontal; i++ {
if err := p.sendButton(buttonHorizontal, true); err != nil { if err := p.sendButton(buttonHorizontal, true); err != nil {
return err return err
} }
@ -385,7 +367,7 @@ func (p *x11Controller) PointerScroll(deltaHorizontal, deltaVertical int, finish
buttonVertical = 4 buttonVertical = 4
stepsVertical = -stepsVertical stepsVertical = -stepsVertical
} }
for range stepsVertical { for i := 0; i < stepsVertical; i++ {
if err := p.sendButton(buttonVertical, true); err != nil { if err := p.sendButton(buttonVertical, true); err != nil {
return err return err
} }

View file

@ -27,6 +27,9 @@ import (
"errors" "errors"
"flag" "flag"
"fmt" "fmt"
"github.com/unrud/remote-touchpad/inputcontrol"
"github.com/unrud/remote-touchpad/terminal"
"golang.org/x/net/websocket"
"log" "log"
mathrand "math/rand" mathrand "math/rand"
"net" "net"
@ -36,10 +39,6 @@ import (
"strings" "strings"
"time" "time"
"unicode/utf8" "unicode/utf8"
"github.com/unrud/remote-touchpad/inputcontrol"
"github.com/unrud/remote-touchpad/terminal"
"golang.org/x/net/websocket"
) )
const ( const (
@ -48,7 +47,7 @@ const (
authenticationRateBurst int = 10 authenticationRateBurst int = 10
challengeLength int = 8 challengeLength int = 8
defaultBind string = ":0" defaultBind string = ":0"
version string = "1.5.4" version string = "1.4.4"
prettyAppName string = "Remote Touchpad" prettyAppName string = "Remote Touchpad"
) )

View file

@ -1,12 +0,0 @@
[Unit]
Description=Remote Touchpad Service
After=network.target
[Service]
Type=simple
ExecStart=%h/.local/bin/remote-touchpad
Restart=always
RestartSec=5s
[Install]
WantedBy=default.target

149
rts
View file

@ -1,149 +0,0 @@
#!/bin/bash
# Remote Touchpad CLI Wrapper
# Provides easy access to remote-touchpad service
SERVICE_NAME="remote-touchpad"
SERVICE_USER="$USER"
install() {
echo "Installing remote-touchpad as a user systemd service..."
# Check if Go is installed
if ! command -v go &> /dev/null; then
echo "Error: Go is not installed. Please install Go first."
return 1
fi
echo "Building remote-touchpad binary..."
go build -tags portal,uinput,x11 -o remote-touchpad
if [ ! -f "remote-touchpad" ]; then
echo "Error: Failed to build remote-touchpad binary"
return 1
fi
# Setup directories
mkdir -p ~/.local/bin ~/.config/systemd/user
echo "Installing service files..."
cp remote-touchpad ~/.local/bin/ || echo "Error: cp to ~/.local/bin failed"
cp remote-touchpad.service ~/.config/systemd/user/ || echo "Error: cp to ~/.config/systemd/user failed"
echo "Enabling and starting service..."
systemctl --user daemon-reload
systemctl --user enable --now ${SERVICE_NAME}.service
echo "✓ remote-touchpad user service installed and started"
echo ""
echo "Use './rts status' to check the service"
echo "Use './rts url' to get the connection URL"
}
start() {
systemctl --user start ${SERVICE_NAME}.service
echo "Started remote-touchpad service"
}
stop() {
systemctl --user stop ${SERVICE_NAME}.service
echo "Stopped remote-touchpad service"
}
status() {
systemctl --user status ${SERVICE_NAME}.service --no-pager
}
restart() {
systemctl --user restart ${SERVICE_NAME}.service
echo "Restarted remote-touchpad service"
}
url() {
# Extract URL from service logs
echo "Fetching remote-touchpad URL..."
local url=$(journalctl --user -u ${SERVICE_NAME}.service -n 100 --no-pager 2>/dev/null | grep -oE "http://[^ ]+|https://[^ ]+" | tail -1)
if [ -n "$url" ]; then
echo "Remote Touchpad URL: $url"
# Generate QR code if qrencode is available
if command -v qrencode &> /dev/null; then
echo "Generating QR code..."
echo "$url" | qrencode -t ansiutf8
else
echo "QR code generation requires qrencode. Install it with:"
echo " sudo apt-get install qrencode # Debian/Ubuntu"
echo " sudo dnf install qrencode # Fedora"
echo " brew install qrencode # macOS"
fi
else
echo "Could not find URL in service logs. Is the service running?"
fi
}
log() {
echo "Viewing remote-touchpad service logs..."
journalctl --user -u ${SERVICE_NAME}.service --no-pager
}
uninstall() {
echo "Uninstalling remote-touchpad..."
systemctl --user stop ${SERVICE_NAME}.service
systemctl --user disable ${SERVICE_NAME}.service
rm -f ~/.config/systemd/user/${SERVICE_NAME}.service
rm -f ~/.local/bin/remote-touchpad
systemctl --user daemon-reload
echo "✓ remote-touchpad uninstalled"
}
help() {
echo "Remote Touchpad CLI Wrapper"
echo ""
echo "Usage: rts [command]"
echo ""
echo "Commands:"
echo " install - Install remote-touchpad as a systemd user service"
echo " start - Start the remote-touchpad service"
echo " stop - Stop the remote-touchpad service"
echo " status - Check service status"
echo " restart - Restart the service"
echo " url - Show the remote-touchpad URL"
echo " log - View service logs"
echo " uninstall - Uninstall the service"
echo " help - Show this help message"
}
# Main command handler
case "$1" in
install)
install
;;
start)
start
;;
stop)
stop
;;
status)
status
;;
restart)
restart
;;
url)
url
;;
log)
log
;;
uninstall)
uninstall
;;
help|--help|-h|"")
help
;;
*)
echo "Unknown command: $1"
help
exit 1
;;
esac

View file

@ -1,21 +1,17 @@
# Build by running `snapcraft`. # Build by running "snapcraft".
# WARNING: # WARNING:
# Snapcraft uses caching for already build steps but it's buggy and can cause strange problems. # Snapcraft uses caching for already build steps but it's buggy and can cause strange problems.
# Clean the cache by running `snapcraft clean`. # Clean the cache by running "snapcraft clean".
name: remote-touchpad name: remote-touchpad
license: GPL-3.0+ license: GPL-3.0+
grade: stable grade: stable
adopt-info: remote-touchpad adopt-info: remote-touchpad
base: core24 base: core20
confinement: strict confinement: strict
platforms:
amd64:
arm64:
apps: apps:
remote-touchpad: remote-touchpad:
command: bin/remote-touchpad command: bin/remote-touchpad
@ -30,7 +26,7 @@ apps:
- desktop - desktop
- x11 - x11
common-id: com.github.unrud.RemoteTouchpad common-id: com.github.unrud.RemoteTouchpad
desktop: usr/share/applications/com.github.unrud.RemoteTouchpad.desktop desktop: share/applications/com.github.unrud.RemoteTouchpad.desktop
parts: parts:
remote-touchpad: remote-touchpad:
@ -40,8 +36,6 @@ parts:
- x11 - x11
source: . source: .
source-type: git source-type: git
build-snaps:
- go
build-packages: build-packages:
- gcc - gcc
- libc6-dev - libc6-dev
@ -52,10 +46,14 @@ parts:
- libxt6 - libxt6
- libxrandr2 - libxrandr2
- libxtst6 - libxtst6
override-pull: |
snapcraftctl pull
# WORKAROUND: Point icon directly to SVG otherwise snapcraft can't find it
sed -e 's|Icon=com.github.unrud.RemoteTouchpad|Icon=/usr/share/icons/hicolor/scalable/apps/com.github.unrud.RemoteTouchpad.svg|' -i desktop/com.github.unrud.RemoteTouchpad.desktop
override-build: | override-build: |
craftctl default snapcraftctl build
install -Dm0755 -t "${CRAFT_PART_INSTALL}/bin" desktop/remote-touchpad-wait-on-error install -Dm0755 -t "${SNAPCRAFT_PART_INSTALL}/bin" desktop/remote-touchpad-wait-on-error
install -Dm0644 -t "${CRAFT_PART_INSTALL}/usr/share/metainfo" desktop/com.github.unrud.RemoteTouchpad.metainfo.xml install -Dm0644 -t "${SNAPCRAFT_PART_INSTALL}/usr/share/metainfo" desktop/com.github.unrud.RemoteTouchpad.metainfo.xml
install -Dm0644 -t "${CRAFT_PART_INSTALL}/usr/share/applications" desktop/com.github.unrud.RemoteTouchpad.desktop install -Dm0644 -t "${SNAPCRAFT_PART_INSTALL}/usr/share/applications" desktop/com.github.unrud.RemoteTouchpad.desktop
install -Dm0644 -t "${CRAFT_PART_INSTALL}/usr/share/icons/hicolor/scalable/apps" desktop/com.github.unrud.RemoteTouchpad.svg install -Dm0644 -t "${SNAPCRAFT_PART_INSTALL}/usr/share/icons/hicolor/scalable/apps" desktop/com.github.unrud.RemoteTouchpad.svg
parse-info: [usr/share/metainfo/com.github.unrud.RemoteTouchpad.metainfo.xml] parse-info: [usr/share/metainfo/com.github.unrud.RemoteTouchpad.metainfo.xml]

View file

@ -1,52 +1,19 @@
/*
* Copyright (c) 2024 Unrud <unrud@outlook.com>
*
* This file is part of Remote-Touchpad.
*
* Remote-Touchpad is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Remote-Touchpad is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Remote-Touchpad. If not, see <http://www.gnu.org/licenses/>.
*/
package main package main
import ( import (
"embed" "embed"
"io/fs" "io/fs"
"log" "log"
"mime"
) )
//go:embed webdata/* //go:embed webdata/*
var webdataFSWithPrefix embed.FS var webdataFSWithPrefix embed.FS
var webdataFS fs.FS var webdataFS fs.FS
var webdataTypes = map[string]string{
".css": "text/css; charset=utf-8",
".html": "text/html; charset=utf-8",
".mjs": "text/javascript; charset=utf-8",
".png": "image/png",
".woff": "font/woff",
}
func init() { func init() {
var err error var err error
webdataFS, err = fs.Sub(webdataFSWithPrefix, "webdata") webdataFS, err = fs.Sub(webdataFSWithPrefix, "webdata")
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
for ext, typ := range webdataTypes {
if err := mime.AddExtensionType(ext, typ); err != nil {
log.Fatal(err)
}
}
} }

View file

@ -57,13 +57,12 @@ export default class UI {
(target) => target.classList.contains("touch-input")); (target) => target.classList.contains("touch-input"));
document.addEventListener("mousedown", this.#handleMousedown.bind(this)); document.addEventListener("mousedown", this.#handleMousedown.bind(this));
document.addEventListener("touchend", this.#handleTouchend.bind(this)); document.addEventListener("touchend", this.#handleTouchend.bind(this));
textInput.addEventListener("input", () => { this.#updateTextInput(); }); textInput.addEventListener("input", this.#handleTextInput.bind(this));
sendText.addEventListener("click", this.#handleSendText.bind(this)); sendText.addEventListener("click", this.#handleSendText.bind(this));
window.addEventListener("popstate", () => { this.#update(); }); window.addEventListener("popstate", () => { this.#update(); });
compat.addFullscreenchangeEventListener(() => { this.#update(); }); compat.addFullscreenchangeEventListener(() => { this.#update(); });
compat.addPointerlockchangeEventListener(() => { this.#update(); }); compat.addPointerlockchangeEventListener(() => { this.#update(); });
for (const button of buttons) { for (const button of buttons) {
button.setAttribute("tabindex", "-1");
button.addEventListener("click", this.#handleButtonClick.bind(this)); button.addEventListener("click", this.#handleButtonClick.bind(this));
} }
this.#update(); this.#update();
@ -98,13 +97,8 @@ export default class UI {
} }
} }
#updateTextInput(newValue = null) { #handleTextInput() {
if (newValue != null) {
textInput.value = newValue;
}
sessionStorage.setItem("text-input", textInput.value); sessionStorage.setItem("text-input", textInput.value);
sendText.textContent = sendText.getAttribute(`data-${textInput.value ? "send" : "back"}-content`);
textInput.focus();
} }
#handleButtonClick(event) { #handleButtonClick(event) {
@ -118,10 +112,10 @@ export default class UI {
// normalize line endings // normalize line endings
const text = textInput.value.replace(/\r\n?/g, "\n"); const text = textInput.value.replace(/\r\n?/g, "\n");
this.#inputController.keyboardText(text); this.#inputController.keyboardText(text);
this.#updateTextInput(""); textInput.value = "";
} else { this.#handleTextInput();
history.back();
} }
history.back();
} }
#showScene(scene) { #showScene(scene) {
@ -165,7 +159,8 @@ export default class UI {
showTextInput() { showTextInput() {
this.#showScene(textInputScene); this.#showScene(textInputScene);
this.#updateTextInput(sessionStorage.getItem("text-input") || ""); textInput.value = sessionStorage.getItem("text-input") || "";
textInput.focus();
if (history.state != "text-input") { if (history.state != "text-input") {
history.pushState("text-input", ""); history.pushState("text-input", "");
} }

View file

@ -1,7 +1,7 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no, interactive-widget=resizes-content"> <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=0">
<script src="app/main.mjs" type="module"></script> <script src="app/main.mjs" type="module"></script>
<title>Remote Touchpad</title> <title>Remote Touchpad</title>
<link href="main.css" media="screen" rel="stylesheet"> <link href="main.css" media="screen" rel="stylesheet">
@ -28,7 +28,7 @@
<textarea class="grow" cols=1 rows=1></textarea> <textarea class="grow" cols=1 rows=1></textarea>
<div class="buttons"> <div class="buttons">
<button onclick="app.showKeys('text-input', 1)"></button> <button onclick="app.showKeys('text-input', 1)"></button>
<button class="grow" id="send-text" data-send-content="➣" data-back-content="⯇"></button> <button class="grow" id="send-text"></button>
</div> </div>
</div> </div>
@ -95,6 +95,6 @@
<button class="top left" onclick="history.back()"></button> <button class="top left" onclick="history.back()"></button>
</div> </div>
<div id="mouse" class="scene keyboard-input allow-fullscreen"> <div id="mouse" class="scene allow-keyboard allow-fullscreen">
<p class="background">Mouse</p> <p class="background">Mouse</p>
</div> </div>

View file

@ -153,10 +153,6 @@ textarea {
padding: 0 0.5rem; padding: 0 0.5rem;
} }
textarea:focus {
outline: none;
}
#keys { #keys {
padding: 0; padding: 0;
justify-content: end; justify-content: end;
@ -181,48 +177,33 @@ textarea:focus {
align-items: stretch; align-items: stretch;
padding: 0; padding: 0;
gap: 0; gap: 0;
flex-direction: row;
}
#text-input .buttons {
flex-direction: column;
} }
#text-input .buttons > button { #text-input .buttons > button {
border-top: none; border-bottom: none;
border-right: none; border-right: none;
} }
#text-input .buttons > button:last-child { #text-input .buttons > button:first-child {
border-bottom: none; border-left: none;
} }
/* Only Safari for iOS */ @media (min-aspect-ratio: 4/3) {
@supports (-webkit-touch-callout: none) {
/* Virtual keyboard can overlay content */
#text-input .buttons > button:last-child {
display: flex;
padding-top: 0.2em;
justify-content: center;
}
}
/* Portrait orientation (not for Safari on iOS) */
@supports not (-webkit-touch-callout: none) { @media (max-aspect-ratio: 4/3) {
#text-input { #text-input {
flex-direction: column;
}
#text-input .buttons {
flex-direction: row; flex-direction: row;
} }
#text-input .buttons > button { #text-input .buttons {
flex-direction: column;
}
#text-input .buttons > button,
#text-input .buttons > button:first-child {
border-top: 1px solid black; border-top: 1px solid black;
border-bottom: none; border-left: 1px solid black;
} }
#text-input .buttons > button:first-child { #text-input .buttons > button:first-child {
border-left: none; border-top: none;
} }
} } }

View file

@ -1,42 +0,0 @@
/*
* Copyright (c) 2024 Unrud <unrud@outlook.com>
*
* This file is part of Remote-Touchpad.
*
* Remote-Touchpad is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Remote-Touchpad is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Remote-Touchpad. If not, see <http://www.gnu.org/licenses/>.
*/
package main
import (
"fmt"
"io/fs"
"path/filepath"
"testing"
)
func TestWebdataTypesCompleteness(t *testing.T) {
if err := fs.WalkDir(webdataFS, ".", func(_ string, d fs.DirEntry, err error) error {
if err != nil || d.IsDir() {
return err
}
ext := filepath.Ext(d.Name())
if _, haveType := webdataTypes[ext]; !haveType {
return fmt.Errorf("missing mime type for extension %#v", ext)
}
return nil
}); err != nil {
t.Fatal(err)
}
}