From 2211b8a66235cc05f75f82c73850d9646ad4d04a Mon Sep 17 00:00:00 2001 From: Unrud Date: Mon, 21 Feb 2022 22:30:28 +0100 Subject: [PATCH] Remove disabled backends --- backend.go | 15 +++++++++++---- backend_portal.go | 4 ++++ backend_portal_disabled.go | 28 ---------------------------- backend_windows.go | 4 ++++ backend_windows_disabled.go | 28 ---------------------------- backend_x11.go | 4 ++++ backend_x11_disabled.go | 28 ---------------------------- 7 files changed, 23 insertions(+), 88 deletions(-) delete mode 100644 backend_portal_disabled.go delete mode 100644 backend_windows_disabled.go delete mode 100644 backend_x11_disabled.go diff --git a/backend.go b/backend.go index 732ea6b..f749138 100644 --- a/backend.go +++ b/backend.go @@ -19,6 +19,8 @@ package main +import "sort" + type PointerButton int type Key int @@ -54,12 +56,17 @@ const ( type BackendInfo struct { Name string Init func() (Backend, error) + + priority int } -var Backends []BackendInfo = []BackendInfo{ - {"X11", InitX11Backend}, - {"RemoteDesktop portal", InitPortalBackend}, - {"Windows", InitWindowsBackend}, +var Backends []BackendInfo + +func RegisterBackend(name string, init func() (Backend, error), priority int) { + Backends = append(Backends, BackendInfo{name, init, priority}) + sort.SliceStable(Backends, func(i, j int) bool { + return Backends[i].priority < Backends[j].priority + }) } type UnsupportedPlatformError struct { diff --git a/backend_portal.go b/backend_portal.go index d4d9bc7..d4662ea 100644 --- a/backend_portal.go +++ b/backend_portal.go @@ -48,6 +48,10 @@ type portalBackend struct { lock sync.RWMutex } +func init() { + RegisterBackend("RemoteDesktop portal", InitPortalBackend, 1) +} + func InitPortalBackend() (Backend, error) { bus, err := dbus.SessionBusPrivate() if err != nil { diff --git a/backend_portal_disabled.go b/backend_portal_disabled.go deleted file mode 100644 index 05ca72f..0000000 --- a/backend_portal_disabled.go +++ /dev/null @@ -1,28 +0,0 @@ -// +build !portal - -/* - * Copyright (c) 2018 Unrud - * - * 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 . - */ - -package main - -import "errors" - -func InitPortalBackend() (Backend, error) { - return nil, UnsupportedPlatformError{errors.New("disabled")} -} diff --git a/backend_windows.go b/backend_windows.go index 49b4faa..272f764 100644 --- a/backend_windows.go +++ b/backend_windows.go @@ -91,6 +91,10 @@ type keybdInput struct { type windowsBackend struct{} +func init() { + RegisterBackend("Windows", InitWindowsBackend, 0) +} + func InitWindowsBackend() (Backend, error) { p := &windowsBackend{} if err := sendInputProc.Find(); err != nil { diff --git a/backend_windows_disabled.go b/backend_windows_disabled.go deleted file mode 100644 index b0051b0..0000000 --- a/backend_windows_disabled.go +++ /dev/null @@ -1,28 +0,0 @@ -// +build !windows - -/* - * Copyright (c) 2018 Unrud - * - * 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 . - */ - -package main - -import "errors" - -func InitWindowsBackend() (Backend, error) { - return nil, UnsupportedPlatformError{errors.New("disabled")} -} diff --git a/backend_x11.go b/backend_x11.go index 3eec2ee..499f316 100644 --- a/backend_x11.go +++ b/backend_x11.go @@ -50,6 +50,10 @@ type x11Backend struct { scrollHorizontal, scrollVertical int } +func init() { + RegisterBackend("X11", InitX11Backend, 0) +} + func InitX11Backend() (Backend, error) { sessionType := os.Getenv("XDG_SESSION_TYPE") if sessionType != "" && sessionType != "x11" { diff --git a/backend_x11_disabled.go b/backend_x11_disabled.go deleted file mode 100644 index 11a8234..0000000 --- a/backend_x11_disabled.go +++ /dev/null @@ -1,28 +0,0 @@ -// +build !x11 - -/* - * Copyright (c) 2018 Unrud - * - * 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 . - */ - -package main - -import "errors" - -func InitX11Backend() (Backend, error) { - return nil, UnsupportedPlatformError{errors.New("disabled")} -}