Reorganize

This commit is contained in:
Unrud 2022-06-20 01:19:08 +02:00
parent e29982dc00
commit 8a2a29c9d6
40 changed files with 39 additions and 37 deletions

View file

@ -28,7 +28,7 @@ import (
const ipv4Rating int = +1
func FindDefaultHost() string {
func findDefaultHost() string {
type hostsValue struct {
prio int
host string

View file

Before

Width:  |  Height:  |  Size: 5.8 KiB

After

Width:  |  Height:  |  Size: 5.8 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 5.6 KiB

After

Width:  |  Height:  |  Size: 5.6 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 6.9 KiB

After

Width:  |  Height:  |  Size: 6.9 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 4.4 KiB

After

Width:  |  Height:  |  Size: 4.4 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 5.1 KiB

After

Width:  |  Height:  |  Size: 5.1 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 5.1 KiB

After

Width:  |  Height:  |  Size: 5.1 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 5.1 KiB

After

Width:  |  Height:  |  Size: 5.1 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 5.1 KiB

After

Width:  |  Height:  |  Size: 5.1 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 4.1 KiB

After

Width:  |  Height:  |  Size: 4.1 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 8.1 KiB

After

Width:  |  Height:  |  Size: 8.1 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 5.6 KiB

After

Width:  |  Height:  |  Size: 5.6 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 4.2 KiB

After

Width:  |  Height:  |  Size: 4.2 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 5.9 KiB

After

Width:  |  Height:  |  Size: 5.9 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 7.1 KiB

After

Width:  |  Height:  |  Size: 7.1 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 6.8 KiB

After

Width:  |  Height:  |  Size: 6.8 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 5.1 KiB

After

Width:  |  Height:  |  Size: 5.1 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 5.1 KiB

After

Width:  |  Height:  |  Size: 5.1 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 5.5 KiB

After

Width:  |  Height:  |  Size: 5.5 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 5.2 KiB

After

Width:  |  Height:  |  Size: 5.2 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 4.6 KiB

After

Width:  |  Height:  |  Size: 4.6 KiB

Before After
Before After

View file

@ -17,7 +17,7 @@
* along with Remote-Touchpad. If not, see <http://www.gnu.org/licenses/>.
*/
package main
package inputcontrol
import "sort"

View file

@ -19,7 +19,7 @@
* along with Remote-Touchpad. If not, see <http://www.gnu.org/licenses/>.
*/
package main
package inputcontrol
import (
"errors"

View file

@ -19,7 +19,7 @@
* along with Remote-Touchpad. If not, see <http://www.gnu.org/licenses/>.
*/
package main
package inputcontrol
import (
"errors"

View file

@ -19,7 +19,7 @@
* along with Remote-Touchpad. If not, see <http://www.gnu.org/licenses/>.
*/
package main
package inputcontrol
// #cgo LDFLAGS: -lX11 -lXtst
// #include <X11/Xlib.h>

View file

@ -1,7 +1,7 @@
// Code generated by keysyms.generator.go. DO NOT EDIT.
//go:build portal || x11
package main
package inputcontrol
var keysymsMap = map[rune]Keysym{
0x0008: 0x0000ff08,

View file

@ -103,7 +103,7 @@ func main() {
}
content := "// Code generated by keysyms.generator.go. DO NOT EDIT.\n" +
"//go:build portal || x11\n\n" +
"package main\n\n" +
"package inputcontrol\n\n" +
"var keysymsMap = map[rune]Keysym{\n"
keys := make([]rune, 0)
for key := range keysymsMap {

View file

@ -19,7 +19,7 @@
* along with Remote-Touchpad. If not, see <http://www.gnu.org/licenses/>.
*/
package main
package inputcontrol
//go:generate go run keysyms.generator.go

28
main.go
View file

@ -27,6 +27,8 @@ 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"
@ -57,7 +59,7 @@ type config struct {
MouseMoveSpeed float64 `json:"mouseMoveSpeed"`
}
func processCommand(controller Controller, command string) error {
func processCommand(controller inputcontrol.Controller, command string) error {
if len(command) == 0 {
return errors.New("empty command")
}
@ -81,10 +83,10 @@ func processCommand(controller Controller, command string) error {
return err
}
if command[0] == 'k' {
if x < 0 || x >= int64(KeyLimit) {
if x < 0 || x >= int64(inputcontrol.KeyLimit) {
return errors.New("unsupported key")
}
return controller.KeyboardKey(Key(x))
return controller.KeyboardKey(inputcontrol.Key(x))
}
y, err := strconv.ParseInt(arguments[1], 10, 32)
if err != nil {
@ -100,14 +102,14 @@ func processCommand(controller Controller, command string) error {
return controller.PointerScroll(int(x), int(y), true)
}
if command[0] == 'b' {
if x < 0 || x >= int64(PointerButtonLimit) {
if x < 0 || x >= int64(inputcontrol.PointerButtonLimit) {
return errors.New("unsupported pointer button")
}
b := true
if y == 0 {
b = false
}
return controller.PointerButton(PointerButton(x), b)
return controller.PointerButton(inputcontrol.PointerButton(x), b)
}
return errors.New("unsupported command")
}
@ -148,7 +150,7 @@ func secureRandBase64(length int) string {
}
func main() {
TerminalSetTitle(prettyAppName)
terminal.SetTitle(prettyAppName)
var bind, certFile, keyFile, secret string
var showVersion bool
var config config
@ -177,19 +179,19 @@ func main() {
if secret == "" {
secret = secureRandBase64(defaultSecretLength)
}
if len(Controllers) == 0 {
if len(inputcontrol.Controllers) == 0 {
log.Fatal("compiled without controller")
}
var controller Controller
var controller inputcontrol.Controller
var controllerName string
platformErrors := ""
for _, controllerInfo := range Controllers {
for _, controllerInfo := range inputcontrol.Controllers {
controllerName = controllerInfo.Name
var err error
controller, err = controllerInfo.Init()
if err == nil {
break
} else if _, ok := err.(UnsupportedPlatformError); ok {
} else if _, ok := err.(inputcontrol.UnsupportedPlatformError); ok {
platformErrors += fmt.Sprintf("%s controller: %v\n", controllerName, err)
} else {
log.Fatalf("%s controller: %v", controllerName, err)
@ -218,11 +220,11 @@ func main() {
}
}
if host == "" {
host = FindDefaultHost()
host = findDefaultHost()
}
port := addr.Port
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) {
var message string
challenge := <-authenticationChallenges
@ -254,7 +256,7 @@ func main() {
}
url := fmt.Sprintf("%s://%s/#%s", scheme, domain, secret)
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)
} else {
log.Printf("QR code error: %v", err)

View file

@ -17,7 +17,7 @@
* along with Remote-Touchpad. If not, see <http://www.gnu.org/licenses/>.
*/
package main
package terminal
import qrcode "github.com/skip2/go-qrcode"
@ -33,7 +33,7 @@ func qrCodeToString(bits [][]bool, colorize bool) string {
s := ""
for y := -1; y < len(bits); y += 2 {
if colorize {
s += TerminalForegroundBlack + TerminalBackgroundWhite
s += ForegroundBlack + BackgroundWhite
}
for x := range bits[0] {
upper := false
@ -55,7 +55,7 @@ func qrCodeToString(bits [][]bool, colorize bool) string {
}
}
if colorize {
s += TerminalForegroundReset + TerminalBackgroundReset
s += ForegroundReset + BackgroundReset
}
s += "\n"
}

View file

@ -17,11 +17,11 @@
* along with Remote-Touchpad. If not, see <http://www.gnu.org/licenses/>.
*/
package main
package terminal
const (
TerminalForegroundBlack string = "\033[30m"
TerminalForegroundReset string = "\033[39m"
TerminalBackgroundWhite string = "\033[47m"
TerminalBackgroundReset string = "\033[49m"
ForegroundBlack string = "\033[30m"
ForegroundReset string = "\033[39m"
BackgroundWhite string = "\033[47m"
BackgroundReset string = "\033[49m"
)

View file

@ -19,17 +19,17 @@
* along with Remote-Touchpad. If not, see <http://www.gnu.org/licenses/>.
*/
package main
package terminal
// #include <unistd.h>
import "C"
import "os"
func TerminalSupportsColor(fd uintptr) bool {
func SupportsColor(fd uintptr) bool {
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 {
os.Stdout.Write([]byte("\x1b]2;" + title + "\x07"))
os.Stdout.Sync()

View file

@ -17,7 +17,7 @@
* along with Remote-Touchpad. If not, see <http://www.gnu.org/licenses/>.
*/
package main
package terminal
import (
"syscall"
@ -36,13 +36,13 @@ var (
setConsoleTitleProc = kernel32DLL.NewProc("SetConsoleTitleW")
)
func TerminalSupportsColor(fd uintptr) bool {
func SupportsColor(fd uintptr) bool {
r, _, _ := setConsoleModeProc.Call(fd, uintptr(enableProcessedOuput|
enableWrapAtEolOutput|enableVirtualTerminalProcessing))
return r != 0
}
func TerminalSetTitle(title string) bool {
func SetTitle(title string) bool {
r, _, _ := setConsoleTitleProc.Call(
uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(title))))
return r != 0

View file

@ -8,11 +8,11 @@ import (
//go:embed webdata/*
var webdataFSWithPrefix embed.FS
var WebdataFS fs.FS
var webdataFS fs.FS
func init() {
var err error
WebdataFS, err = fs.Sub(webdataFSWithPrefix, "webdata")
webdataFS, err = fs.Sub(webdataFSWithPrefix, "webdata")
if err != nil {
log.Fatal(err)
}