From 2bf53f0397f16ee0367be99373b57dadf1742195 Mon Sep 17 00:00:00 2001 From: Mathias Fredriksson Date: Tue, 8 Feb 2022 23:50:49 +0200 Subject: Add support for mouse click and scroll wheel Requires the webos client to have support for these events, see: https://github.com/Wouterdek/magic4pc/pull/10 --- cmd/magic4linux/main.go | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) (limited to 'cmd') diff --git a/cmd/magic4linux/main.go b/cmd/magic4linux/main.go index 0275d64..a2775ac 100644 --- a/cmd/magic4linux/main.go +++ b/cmd/magic4linux/main.go @@ -36,6 +36,12 @@ func run(ctx context.Context) error { } defer kbd.Close() + mouse, err := uinput.CreateMouse("/dev/uinput", []byte("magic4linux-mouse")) + if err != nil { + return err + } + defer mouse.Close() + tp, err := uinput.CreateTouchPad("/dev/uinput", []byte("magic4linux-touchpad"), 0, 1920, 0, 1080) if err != nil { return err @@ -54,7 +60,7 @@ func run(ctx context.Context) error { return nil case dev := <-d.NextDevice(): - err = connect(ctx, dev, kbd, tp) + err = connect(ctx, dev, kbd, mouse, tp) if err != nil { log.Printf("connect: %v", err) } @@ -62,7 +68,7 @@ func run(ctx context.Context) error { } } -func connect(ctx context.Context, dev m4p.DeviceInfo, kbd uinput.Keyboard, tp uinput.TouchPad) error { +func connect(ctx context.Context, dev m4p.DeviceInfo, kbd uinput.Keyboard, mouse uinput.Mouse, tp uinput.TouchPad) error { addr := fmt.Sprintf("%s:%d", dev.IPAddr, dev.Port) log.Printf("connect: connecting to: %s", addr) @@ -160,11 +166,22 @@ func connect(ctx context.Context, dev m4p.DeviceInfo, kbd uinput.Keyboard, tp ui x := coordinate[0] y := coordinate[1] - fmt.Println("Move mouse", x, y) + // fmt.Println("Move mouse", x, y) tp.MoveTo(x, y) // log.Printf("connect: %d %d %#v %#v %#v %#v", returnValue, deviceID, coordinate, gyroscope, acceleration, quaternion) + case m4p.MouseMessage: + switch m.Mouse.Type { + case "mousedown": + tp.LeftPress() + case "mouseup": + tp.LeftRelease() + } + + case m4p.WheelMessage: + mouse.Wheel(false, m.Wheel.Delta) + default: } } -- cgit v1.2.3