diff options
| author | Mathias Fredriksson <mafredri@gmail.com> | 2022-02-08 23:50:49 +0200 | 
|---|---|---|
| committer | Mathias Fredriksson <mafredri@gmail.com> | 2022-02-08 23:51:02 +0200 | 
| commit | 2bf53f0397f16ee0367be99373b57dadf1742195 (patch) | |
| tree | 3669265f12b38742d86ef53a2d8f7f19096ea4ee /cmd/magic4linux | |
| parent | eb2617ac12b2432e8d8d22c7cae64b887d1c70e5 (diff) | |
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
Diffstat (limited to 'cmd/magic4linux')
| -rw-r--r-- | cmd/magic4linux/main.go | 23 | 
1 files changed, 20 insertions, 3 deletions
| 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:  		}  	} | 
