Reorganize
2
host.go
|
|
@ -28,7 +28,7 @@ import (
|
||||||
|
|
||||||
const ipv4Rating int = +1
|
const ipv4Rating int = +1
|
||||||
|
|
||||||
func FindDefaultHost() string {
|
func findDefaultHost() string {
|
||||||
type hostsValue struct {
|
type hostsValue struct {
|
||||||
prio int
|
prio int
|
||||||
host string
|
host string
|
||||||
|
|
|
||||||
|
Before Width: | Height: | Size: 5.8 KiB After Width: | Height: | Size: 5.8 KiB |
|
Before Width: | Height: | Size: 5.6 KiB After Width: | Height: | Size: 5.6 KiB |
|
Before Width: | Height: | Size: 6.9 KiB After Width: | Height: | Size: 6.9 KiB |
|
Before Width: | Height: | Size: 4.4 KiB After Width: | Height: | Size: 4.4 KiB |
|
Before Width: | Height: | Size: 5.1 KiB After Width: | Height: | Size: 5.1 KiB |
|
Before Width: | Height: | Size: 5.1 KiB After Width: | Height: | Size: 5.1 KiB |
|
Before Width: | Height: | Size: 5.1 KiB After Width: | Height: | Size: 5.1 KiB |
|
Before Width: | Height: | Size: 5.1 KiB After Width: | Height: | Size: 5.1 KiB |
|
Before Width: | Height: | Size: 4.1 KiB After Width: | Height: | Size: 4.1 KiB |
|
Before Width: | Height: | Size: 8.1 KiB After Width: | Height: | Size: 8.1 KiB |
|
Before Width: | Height: | Size: 5.6 KiB After Width: | Height: | Size: 5.6 KiB |
|
Before Width: | Height: | Size: 4.2 KiB After Width: | Height: | Size: 4.2 KiB |
|
Before Width: | Height: | Size: 5.9 KiB After Width: | Height: | Size: 5.9 KiB |
|
Before Width: | Height: | Size: 5.3 KiB After Width: | Height: | Size: 5.3 KiB |
|
Before Width: | Height: | Size: 5.3 KiB After Width: | Height: | Size: 5.3 KiB |
|
Before Width: | Height: | Size: 5.6 KiB After Width: | Height: | Size: 5.6 KiB |
|
Before Width: | Height: | Size: 7.1 KiB After Width: | Height: | Size: 7.1 KiB |
|
Before Width: | Height: | Size: 6.8 KiB After Width: | Height: | Size: 6.8 KiB |
|
Before Width: | Height: | Size: 5.1 KiB After Width: | Height: | Size: 5.1 KiB |
|
Before Width: | Height: | Size: 5.1 KiB After Width: | Height: | Size: 5.1 KiB |
|
Before Width: | Height: | Size: 5.5 KiB After Width: | Height: | Size: 5.5 KiB |
|
Before Width: | Height: | Size: 5.2 KiB After Width: | Height: | Size: 5.2 KiB |
|
Before Width: | Height: | Size: 7.6 KiB After Width: | Height: | Size: 7.6 KiB |
|
Before Width: | Height: | Size: 5.3 KiB After Width: | Height: | Size: 5.3 KiB |
|
Before Width: | Height: | Size: 4.6 KiB After Width: | Height: | Size: 4.6 KiB |
|
|
@ -17,7 +17,7 @@
|
||||||
* along with Remote-Touchpad. If not, see <http://www.gnu.org/licenses/>.
|
* along with Remote-Touchpad. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package main
|
package inputcontrol
|
||||||
|
|
||||||
import "sort"
|
import "sort"
|
||||||
|
|
||||||
|
|
@ -19,7 +19,7 @@
|
||||||
* along with Remote-Touchpad. If not, see <http://www.gnu.org/licenses/>.
|
* along with Remote-Touchpad. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package main
|
package inputcontrol
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
|
@ -19,7 +19,7 @@
|
||||||
* along with Remote-Touchpad. If not, see <http://www.gnu.org/licenses/>.
|
* along with Remote-Touchpad. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package main
|
package inputcontrol
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
|
@ -19,7 +19,7 @@
|
||||||
* along with Remote-Touchpad. If not, see <http://www.gnu.org/licenses/>.
|
* along with Remote-Touchpad. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package main
|
package inputcontrol
|
||||||
|
|
||||||
// #cgo LDFLAGS: -lX11 -lXtst
|
// #cgo LDFLAGS: -lX11 -lXtst
|
||||||
// #include <X11/Xlib.h>
|
// #include <X11/Xlib.h>
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
// Code generated by keysyms.generator.go. DO NOT EDIT.
|
// Code generated by keysyms.generator.go. DO NOT EDIT.
|
||||||
//go:build portal || x11
|
//go:build portal || x11
|
||||||
|
|
||||||
package main
|
package inputcontrol
|
||||||
|
|
||||||
var keysymsMap = map[rune]Keysym{
|
var keysymsMap = map[rune]Keysym{
|
||||||
0x0008: 0x0000ff08,
|
0x0008: 0x0000ff08,
|
||||||
|
|
@ -103,7 +103,7 @@ func main() {
|
||||||
}
|
}
|
||||||
content := "// Code generated by keysyms.generator.go. DO NOT EDIT.\n" +
|
content := "// Code generated by keysyms.generator.go. DO NOT EDIT.\n" +
|
||||||
"//go:build portal || x11\n\n" +
|
"//go:build portal || x11\n\n" +
|
||||||
"package main\n\n" +
|
"package inputcontrol\n\n" +
|
||||||
"var keysymsMap = map[rune]Keysym{\n"
|
"var keysymsMap = map[rune]Keysym{\n"
|
||||||
keys := make([]rune, 0)
|
keys := make([]rune, 0)
|
||||||
for key := range keysymsMap {
|
for key := range keysymsMap {
|
||||||
|
|
@ -19,7 +19,7 @@
|
||||||
* along with Remote-Touchpad. If not, see <http://www.gnu.org/licenses/>.
|
* along with Remote-Touchpad. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package main
|
package inputcontrol
|
||||||
|
|
||||||
//go:generate go run keysyms.generator.go
|
//go:generate go run keysyms.generator.go
|
||||||
|
|
||||||
28
main.go
|
|
@ -27,6 +27,8 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/unrud/remote-touchpad/inputcontrol"
|
||||||
|
"github.com/unrud/remote-touchpad/terminal"
|
||||||
"golang.org/x/net/websocket"
|
"golang.org/x/net/websocket"
|
||||||
"log"
|
"log"
|
||||||
mathrand "math/rand"
|
mathrand "math/rand"
|
||||||
|
|
@ -57,7 +59,7 @@ type config struct {
|
||||||
MouseMoveSpeed float64 `json:"mouseMoveSpeed"`
|
MouseMoveSpeed float64 `json:"mouseMoveSpeed"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func processCommand(controller Controller, command string) error {
|
func processCommand(controller inputcontrol.Controller, command string) error {
|
||||||
if len(command) == 0 {
|
if len(command) == 0 {
|
||||||
return errors.New("empty command")
|
return errors.New("empty command")
|
||||||
}
|
}
|
||||||
|
|
@ -81,10 +83,10 @@ func processCommand(controller Controller, command string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if command[0] == 'k' {
|
if command[0] == 'k' {
|
||||||
if x < 0 || x >= int64(KeyLimit) {
|
if x < 0 || x >= int64(inputcontrol.KeyLimit) {
|
||||||
return errors.New("unsupported key")
|
return errors.New("unsupported key")
|
||||||
}
|
}
|
||||||
return controller.KeyboardKey(Key(x))
|
return controller.KeyboardKey(inputcontrol.Key(x))
|
||||||
}
|
}
|
||||||
y, err := strconv.ParseInt(arguments[1], 10, 32)
|
y, err := strconv.ParseInt(arguments[1], 10, 32)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -100,14 +102,14 @@ func processCommand(controller Controller, command string) error {
|
||||||
return controller.PointerScroll(int(x), int(y), true)
|
return controller.PointerScroll(int(x), int(y), true)
|
||||||
}
|
}
|
||||||
if command[0] == 'b' {
|
if command[0] == 'b' {
|
||||||
if x < 0 || x >= int64(PointerButtonLimit) {
|
if x < 0 || x >= int64(inputcontrol.PointerButtonLimit) {
|
||||||
return errors.New("unsupported pointer button")
|
return errors.New("unsupported pointer button")
|
||||||
}
|
}
|
||||||
b := true
|
b := true
|
||||||
if y == 0 {
|
if y == 0 {
|
||||||
b = false
|
b = false
|
||||||
}
|
}
|
||||||
return controller.PointerButton(PointerButton(x), b)
|
return controller.PointerButton(inputcontrol.PointerButton(x), b)
|
||||||
}
|
}
|
||||||
return errors.New("unsupported command")
|
return errors.New("unsupported command")
|
||||||
}
|
}
|
||||||
|
|
@ -148,7 +150,7 @@ func secureRandBase64(length int) string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
TerminalSetTitle(prettyAppName)
|
terminal.SetTitle(prettyAppName)
|
||||||
var bind, certFile, keyFile, secret string
|
var bind, certFile, keyFile, secret string
|
||||||
var showVersion bool
|
var showVersion bool
|
||||||
var config config
|
var config config
|
||||||
|
|
@ -177,19 +179,19 @@ func main() {
|
||||||
if secret == "" {
|
if secret == "" {
|
||||||
secret = secureRandBase64(defaultSecretLength)
|
secret = secureRandBase64(defaultSecretLength)
|
||||||
}
|
}
|
||||||
if len(Controllers) == 0 {
|
if len(inputcontrol.Controllers) == 0 {
|
||||||
log.Fatal("compiled without controller")
|
log.Fatal("compiled without controller")
|
||||||
}
|
}
|
||||||
var controller Controller
|
var controller inputcontrol.Controller
|
||||||
var controllerName string
|
var controllerName string
|
||||||
platformErrors := ""
|
platformErrors := ""
|
||||||
for _, controllerInfo := range Controllers {
|
for _, controllerInfo := range inputcontrol.Controllers {
|
||||||
controllerName = controllerInfo.Name
|
controllerName = controllerInfo.Name
|
||||||
var err error
|
var err error
|
||||||
controller, err = controllerInfo.Init()
|
controller, err = controllerInfo.Init()
|
||||||
if err == nil {
|
if err == nil {
|
||||||
break
|
break
|
||||||
} else if _, ok := err.(UnsupportedPlatformError); ok {
|
} else if _, ok := err.(inputcontrol.UnsupportedPlatformError); ok {
|
||||||
platformErrors += fmt.Sprintf("%s controller: %v\n", controllerName, err)
|
platformErrors += fmt.Sprintf("%s controller: %v\n", controllerName, err)
|
||||||
} else {
|
} else {
|
||||||
log.Fatalf("%s controller: %v", controllerName, err)
|
log.Fatalf("%s controller: %v", controllerName, err)
|
||||||
|
|
@ -218,11 +220,11 @@ func main() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if host == "" {
|
if host == "" {
|
||||||
host = FindDefaultHost()
|
host = findDefaultHost()
|
||||||
}
|
}
|
||||||
port := addr.Port
|
port := addr.Port
|
||||||
mux := http.NewServeMux()
|
mux := http.NewServeMux()
|
||||||
mux.Handle("/", http.FileServer(http.FS(WebdataFS)))
|
mux.Handle("/", http.FileServer(http.FS(webdataFS)))
|
||||||
mux.Handle("/ws", websocket.Handler(func(ws *websocket.Conn) {
|
mux.Handle("/ws", websocket.Handler(func(ws *websocket.Conn) {
|
||||||
var message string
|
var message string
|
||||||
challenge := <-authenticationChallenges
|
challenge := <-authenticationChallenges
|
||||||
|
|
@ -254,7 +256,7 @@ func main() {
|
||||||
}
|
}
|
||||||
url := fmt.Sprintf("%s://%s/#%s", scheme, domain, secret)
|
url := fmt.Sprintf("%s://%s/#%s", scheme, domain, secret)
|
||||||
fmt.Println(url)
|
fmt.Println(url)
|
||||||
if qrCode, err := GenerateQRCode(url, TerminalSupportsColor(os.Stdout.Fd())); err == nil {
|
if qrCode, err := terminal.GenerateQRCode(url, terminal.SupportsColor(os.Stdout.Fd())); err == nil {
|
||||||
fmt.Print(qrCode)
|
fmt.Print(qrCode)
|
||||||
} else {
|
} else {
|
||||||
log.Printf("QR code error: %v", err)
|
log.Printf("QR code error: %v", err)
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@
|
||||||
* along with Remote-Touchpad. If not, see <http://www.gnu.org/licenses/>.
|
* along with Remote-Touchpad. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package main
|
package terminal
|
||||||
|
|
||||||
import qrcode "github.com/skip2/go-qrcode"
|
import qrcode "github.com/skip2/go-qrcode"
|
||||||
|
|
||||||
|
|
@ -33,7 +33,7 @@ func qrCodeToString(bits [][]bool, colorize bool) string {
|
||||||
s := ""
|
s := ""
|
||||||
for y := -1; y < len(bits); y += 2 {
|
for y := -1; y < len(bits); y += 2 {
|
||||||
if colorize {
|
if colorize {
|
||||||
s += TerminalForegroundBlack + TerminalBackgroundWhite
|
s += ForegroundBlack + BackgroundWhite
|
||||||
}
|
}
|
||||||
for x := range bits[0] {
|
for x := range bits[0] {
|
||||||
upper := false
|
upper := false
|
||||||
|
|
@ -55,7 +55,7 @@ func qrCodeToString(bits [][]bool, colorize bool) string {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if colorize {
|
if colorize {
|
||||||
s += TerminalForegroundReset + TerminalBackgroundReset
|
s += ForegroundReset + BackgroundReset
|
||||||
}
|
}
|
||||||
s += "\n"
|
s += "\n"
|
||||||
}
|
}
|
||||||
|
|
@ -17,11 +17,11 @@
|
||||||
* along with Remote-Touchpad. If not, see <http://www.gnu.org/licenses/>.
|
* along with Remote-Touchpad. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package main
|
package terminal
|
||||||
|
|
||||||
const (
|
const (
|
||||||
TerminalForegroundBlack string = "\033[30m"
|
ForegroundBlack string = "\033[30m"
|
||||||
TerminalForegroundReset string = "\033[39m"
|
ForegroundReset string = "\033[39m"
|
||||||
TerminalBackgroundWhite string = "\033[47m"
|
BackgroundWhite string = "\033[47m"
|
||||||
TerminalBackgroundReset string = "\033[49m"
|
BackgroundReset string = "\033[49m"
|
||||||
)
|
)
|
||||||
|
|
@ -19,17 +19,17 @@
|
||||||
* along with Remote-Touchpad. If not, see <http://www.gnu.org/licenses/>.
|
* along with Remote-Touchpad. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package main
|
package terminal
|
||||||
|
|
||||||
// #include <unistd.h>
|
// #include <unistd.h>
|
||||||
import "C"
|
import "C"
|
||||||
import "os"
|
import "os"
|
||||||
|
|
||||||
func TerminalSupportsColor(fd uintptr) bool {
|
func SupportsColor(fd uintptr) bool {
|
||||||
return C.isatty(C.int(fd)) != 0
|
return C.isatty(C.int(fd)) != 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func TerminalSetTitle(title string) bool {
|
func SetTitle(title string) bool {
|
||||||
if C.isatty(C.int(os.Stdout.Fd())) != 0 {
|
if C.isatty(C.int(os.Stdout.Fd())) != 0 {
|
||||||
os.Stdout.Write([]byte("\x1b]2;" + title + "\x07"))
|
os.Stdout.Write([]byte("\x1b]2;" + title + "\x07"))
|
||||||
os.Stdout.Sync()
|
os.Stdout.Sync()
|
||||||
|
|
@ -17,7 +17,7 @@
|
||||||
* along with Remote-Touchpad. If not, see <http://www.gnu.org/licenses/>.
|
* along with Remote-Touchpad. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package main
|
package terminal
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
@ -36,13 +36,13 @@ var (
|
||||||
setConsoleTitleProc = kernel32DLL.NewProc("SetConsoleTitleW")
|
setConsoleTitleProc = kernel32DLL.NewProc("SetConsoleTitleW")
|
||||||
)
|
)
|
||||||
|
|
||||||
func TerminalSupportsColor(fd uintptr) bool {
|
func SupportsColor(fd uintptr) bool {
|
||||||
r, _, _ := setConsoleModeProc.Call(fd, uintptr(enableProcessedOuput|
|
r, _, _ := setConsoleModeProc.Call(fd, uintptr(enableProcessedOuput|
|
||||||
enableWrapAtEolOutput|enableVirtualTerminalProcessing))
|
enableWrapAtEolOutput|enableVirtualTerminalProcessing))
|
||||||
return r != 0
|
return r != 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func TerminalSetTitle(title string) bool {
|
func SetTitle(title string) bool {
|
||||||
r, _, _ := setConsoleTitleProc.Call(
|
r, _, _ := setConsoleTitleProc.Call(
|
||||||
uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(title))))
|
uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(title))))
|
||||||
return r != 0
|
return r != 0
|
||||||
|
|
@ -8,11 +8,11 @@ import (
|
||||||
|
|
||||||
//go:embed webdata/*
|
//go:embed webdata/*
|
||||||
var webdataFSWithPrefix embed.FS
|
var webdataFSWithPrefix embed.FS
|
||||||
var WebdataFS fs.FS
|
var webdataFS fs.FS
|
||||||
|
|
||||||
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)
|
||||||
}
|
}
|
||||||
|
|
|
||||||