mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
ea5517b270
* add xf86 input driver. * cleanup. * rewrite to unix socket PoC. * add input rebuild. * lint & docs. * add input driver struct. * comments, lint, socket name from config. * add touch events to webrtc. * switch to uint32. * misc update logging & linting, * fix screen size * set touchscreen as core pointer. * add touch to ws control. * SendCoreEvents. * extract to own xinput folder. * add debounce. * switch pressure to uint8. * check buffer size. * send touch events with system init.
171 lines
3.7 KiB
Go
171 lines
3.7 KiB
Go
package desktop
|
|
|
|
import (
|
|
"image"
|
|
"os/exec"
|
|
"regexp"
|
|
"time"
|
|
|
|
"github.com/demodesk/neko/pkg/types"
|
|
"github.com/demodesk/neko/pkg/xorg"
|
|
)
|
|
|
|
func (manager *DesktopManagerCtx) Move(x, y int) {
|
|
xorg.Move(x, y)
|
|
}
|
|
|
|
func (manager *DesktopManagerCtx) GetCursorPosition() (int, int) {
|
|
return xorg.GetCursorPosition()
|
|
}
|
|
|
|
func (manager *DesktopManagerCtx) Scroll(x, y int) {
|
|
xorg.Scroll(x, y)
|
|
}
|
|
|
|
func (manager *DesktopManagerCtx) ButtonDown(code uint32) error {
|
|
return xorg.ButtonDown(code)
|
|
}
|
|
|
|
func (manager *DesktopManagerCtx) KeyDown(code uint32) error {
|
|
return xorg.KeyDown(code)
|
|
}
|
|
|
|
func (manager *DesktopManagerCtx) ButtonUp(code uint32) error {
|
|
return xorg.ButtonUp(code)
|
|
}
|
|
|
|
func (manager *DesktopManagerCtx) KeyUp(code uint32) error {
|
|
return xorg.KeyUp(code)
|
|
}
|
|
|
|
func (manager *DesktopManagerCtx) ButtonPress(code uint32) error {
|
|
xorg.ResetKeys()
|
|
defer xorg.ResetKeys()
|
|
|
|
return xorg.ButtonDown(code)
|
|
}
|
|
|
|
func (manager *DesktopManagerCtx) KeyPress(codes ...uint32) error {
|
|
xorg.ResetKeys()
|
|
defer xorg.ResetKeys()
|
|
|
|
for _, code := range codes {
|
|
if err := xorg.KeyDown(code); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
if len(codes) > 1 {
|
|
time.Sleep(10 * time.Millisecond)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (manager *DesktopManagerCtx) ResetKeys() {
|
|
xorg.ResetKeys()
|
|
}
|
|
|
|
func (manager *DesktopManagerCtx) ScreenConfigurations() []types.ScreenSize {
|
|
var configs []types.ScreenSize
|
|
for _, size := range xorg.ScreenConfigurations {
|
|
for _, fps := range size.Rates {
|
|
// filter out all irrelevant rates
|
|
if fps > 60 || (fps > 30 && fps%10 != 0) {
|
|
continue
|
|
}
|
|
|
|
configs = append(configs, types.ScreenSize{
|
|
Width: size.Width,
|
|
Height: size.Height,
|
|
Rate: fps,
|
|
})
|
|
}
|
|
}
|
|
return configs
|
|
}
|
|
|
|
func (manager *DesktopManagerCtx) SetScreenSize(screenSize types.ScreenSize) (types.ScreenSize, error) {
|
|
mu.Lock()
|
|
manager.emmiter.Emit("before_screen_size_change")
|
|
|
|
defer func() {
|
|
manager.emmiter.Emit("after_screen_size_change")
|
|
mu.Unlock()
|
|
}()
|
|
|
|
screenSize, err := xorg.ChangeScreenSize(screenSize)
|
|
if err == nil {
|
|
// cache the new screen size
|
|
manager.screenSize = screenSize
|
|
}
|
|
|
|
return screenSize, err
|
|
}
|
|
|
|
func (manager *DesktopManagerCtx) GetScreenSize() types.ScreenSize {
|
|
return xorg.GetScreenSize()
|
|
}
|
|
|
|
func (manager *DesktopManagerCtx) SetKeyboardMap(kbd types.KeyboardMap) error {
|
|
// TOOD: Use native API.
|
|
cmd := exec.Command("setxkbmap", "-layout", kbd.Layout, "-variant", kbd.Variant)
|
|
_, err := cmd.Output()
|
|
return err
|
|
}
|
|
|
|
func (manager *DesktopManagerCtx) GetKeyboardMap() (*types.KeyboardMap, error) {
|
|
// TOOD: Use native API.
|
|
cmd := exec.Command("setxkbmap", "-query")
|
|
res, err := cmd.Output()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
kbd := types.KeyboardMap{}
|
|
|
|
re := regexp.MustCompile(`layout:\s+(.*)\n`)
|
|
arr := re.FindStringSubmatch(string(res))
|
|
if len(arr) > 1 {
|
|
kbd.Layout = arr[1]
|
|
}
|
|
|
|
re = regexp.MustCompile(`variant:\s+(.*)\n`)
|
|
arr = re.FindStringSubmatch(string(res))
|
|
if len(arr) > 1 {
|
|
kbd.Variant = arr[1]
|
|
}
|
|
|
|
return &kbd, nil
|
|
}
|
|
|
|
func (manager *DesktopManagerCtx) SetKeyboardModifiers(mod types.KeyboardModifiers) {
|
|
if mod.NumLock != nil {
|
|
xorg.SetKeyboardModifier(xorg.KbdModNumLock, *mod.NumLock)
|
|
}
|
|
|
|
if mod.CapsLock != nil {
|
|
xorg.SetKeyboardModifier(xorg.KbdModCapsLock, *mod.CapsLock)
|
|
}
|
|
}
|
|
|
|
func (manager *DesktopManagerCtx) GetKeyboardModifiers() types.KeyboardModifiers {
|
|
modifiers := xorg.GetKeyboardModifiers()
|
|
|
|
NumLock := (modifiers & xorg.KbdModNumLock) != 0
|
|
CapsLock := (modifiers & xorg.KbdModCapsLock) != 0
|
|
|
|
return types.KeyboardModifiers{
|
|
NumLock: &NumLock,
|
|
CapsLock: &CapsLock,
|
|
}
|
|
}
|
|
|
|
func (manager *DesktopManagerCtx) GetCursorImage() *types.CursorImage {
|
|
return xorg.GetCursorImage()
|
|
}
|
|
|
|
func (manager *DesktopManagerCtx) GetScreenshotImage() *image.RGBA {
|
|
return xorg.GetScreenshotImage()
|
|
}
|