Use internal constants for pointer buttons, instead of x11 mapping
This commit is contained in:
parent
07678e56ab
commit
b3b068fe59
7 changed files with 54 additions and 30 deletions
File diff suppressed because one or more lines are too long
4
main.go
4
main.go
|
|
@ -84,14 +84,14 @@ func processCommand(plugin Plugin, command string) error {
|
||||||
return plugin.PointerScroll(int(x), int(y))
|
return plugin.PointerScroll(int(x), int(y))
|
||||||
}
|
}
|
||||||
if command[0] == 'b' {
|
if command[0] == 'b' {
|
||||||
if x <= 0 || x > 3 {
|
if x < 0 || x >= int64(PointerButtonLimit) {
|
||||||
return errors.New("unsupported pointer button")
|
return errors.New("unsupported pointer button")
|
||||||
}
|
}
|
||||||
b := true
|
b := true
|
||||||
if y == 0 {
|
if y == 0 {
|
||||||
b = false
|
b = false
|
||||||
}
|
}
|
||||||
return plugin.PointerButton(uint(x), b)
|
return plugin.PointerButton(PointerButton(x), b)
|
||||||
}
|
}
|
||||||
return errors.New("unsupported command")
|
return errors.New("unsupported command")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
11
plugin.go
11
plugin.go
|
|
@ -19,6 +19,15 @@
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
|
type PointerButton int
|
||||||
|
|
||||||
|
const (
|
||||||
|
PointerButtonLeft PointerButton = iota
|
||||||
|
PointerButtonRight
|
||||||
|
PointerButtonMiddle
|
||||||
|
PointerButtonLimit
|
||||||
|
)
|
||||||
|
|
||||||
type PluginInfo struct {
|
type PluginInfo struct {
|
||||||
Name string
|
Name string
|
||||||
Init func() (Plugin, error)
|
Init func() (Plugin, error)
|
||||||
|
|
@ -41,7 +50,7 @@ func (e UnsupportedPlatformError) Error() string {
|
||||||
type Plugin interface {
|
type Plugin interface {
|
||||||
Close() error
|
Close() error
|
||||||
KeyboardText(text string) error
|
KeyboardText(text string) error
|
||||||
PointerButton(button uint, press bool) error
|
PointerButton(button PointerButton, press bool) error
|
||||||
PointerMove(deltaX, deltaY int) error
|
PointerMove(deltaX, deltaY int) error
|
||||||
PointerScroll(deltaHorizontal, deltaVertical int) error
|
PointerScroll(deltaHorizontal, deltaVertical int) error
|
||||||
PointerScrollFinish() error
|
PointerScrollFinish() error
|
||||||
|
|
|
||||||
|
|
@ -208,18 +208,18 @@ func (p *portalPlugin) KeyboardText(text string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *portalPlugin) PointerButton(button uint, press bool) error {
|
func (p *portalPlugin) PointerButton(button PointerButton, press bool) error {
|
||||||
p.lock.RLock()
|
p.lock.RLock()
|
||||||
defer p.lock.RUnlock()
|
defer p.lock.RUnlock()
|
||||||
if p.bus == nil {
|
if p.bus == nil {
|
||||||
return errors.New("dbus connection closed")
|
return errors.New("dbus connection closed")
|
||||||
}
|
}
|
||||||
var btn int32
|
var btn int32
|
||||||
if button == 1 {
|
if button == PointerButtonLeft {
|
||||||
btn = btnLeft
|
btn = btnLeft
|
||||||
} else if button == 2 {
|
} else if button == PointerButtonMiddle {
|
||||||
btn = btnMiddle
|
btn = btnMiddle
|
||||||
} else if button == 3 {
|
} else if button == PointerButtonRight {
|
||||||
btn = btnRight
|
btn = btnRight
|
||||||
} else {
|
} else {
|
||||||
return errors.New("unsupported pointer button")
|
return errors.New("unsupported pointer button")
|
||||||
|
|
|
||||||
|
|
@ -106,21 +106,19 @@ func (p *windowsPlugin) KeyboardText(text string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *windowsPlugin) PointerButton(button uint, press bool) error {
|
func (p *windowsPlugin) PointerButton(button PointerButton, press bool) error {
|
||||||
input := mouseInput{
|
input := mouseInput{typ: inputMouse}
|
||||||
typ: inputMouse,
|
if button == PointerButtonLeft && press {
|
||||||
}
|
|
||||||
if button == 1 && press {
|
|
||||||
input.dwFlags = mouseeventfLeftdown
|
input.dwFlags = mouseeventfLeftdown
|
||||||
} else if button == 1 {
|
} else if button == PointerButtonLeft {
|
||||||
input.dwFlags = mouseeventfLeftup
|
input.dwFlags = mouseeventfLeftup
|
||||||
} else if button == 2 && press {
|
} else if button == PointerButtonMiddle && press {
|
||||||
input.dwFlags = mouseeventfMiddledown
|
input.dwFlags = mouseeventfMiddledown
|
||||||
} else if button == 2 {
|
} else if button == PointerButtonMiddle {
|
||||||
input.dwFlags = mouseeventfMiddleup
|
input.dwFlags = mouseeventfMiddleup
|
||||||
} else if button == 3 && press {
|
} else if button == PointerButtonRight && press {
|
||||||
input.dwFlags = mouseeventfRightdown
|
input.dwFlags = mouseeventfRightdown
|
||||||
} else if button == 3 {
|
} else if button == PointerButtonRight {
|
||||||
input.dwFlags = mouseeventfRightup
|
input.dwFlags = mouseeventfRightup
|
||||||
} else {
|
} else {
|
||||||
return errors.New("unsupported pointer button")
|
return errors.New("unsupported pointer button")
|
||||||
|
|
|
||||||
|
|
@ -135,7 +135,7 @@ keycodes:
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *x11Plugin) PointerButton(button uint, press bool) error {
|
func (p *x11Plugin) sendButton(button uint, press bool) error {
|
||||||
p.lock.Lock()
|
p.lock.Lock()
|
||||||
defer p.lock.Unlock()
|
defer p.lock.Unlock()
|
||||||
if p.display == nil {
|
if p.display == nil {
|
||||||
|
|
@ -153,6 +153,19 @@ func (p *x11Plugin) PointerButton(button uint, press bool) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *x11Plugin) PointerButton(button PointerButton, press bool) error {
|
||||||
|
if button == PointerButtonLeft {
|
||||||
|
return p.sendButton(1, press)
|
||||||
|
}
|
||||||
|
if button == PointerButtonRight {
|
||||||
|
return p.sendButton(3, press)
|
||||||
|
}
|
||||||
|
if button == PointerButtonMiddle {
|
||||||
|
return p.sendButton(2, press)
|
||||||
|
}
|
||||||
|
return errors.New("unsupported pointer button")
|
||||||
|
}
|
||||||
|
|
||||||
func (p *x11Plugin) PointerMove(deltaX, deltaY int) error {
|
func (p *x11Plugin) PointerMove(deltaX, deltaY int) error {
|
||||||
p.lock.Lock()
|
p.lock.Lock()
|
||||||
defer p.lock.Unlock()
|
defer p.lock.Unlock()
|
||||||
|
|
@ -177,10 +190,10 @@ func (p *x11Plugin) PointerScroll(deltaHorizontal, deltaVertical int) error {
|
||||||
stepsHorizontal = -stepsHorizontal
|
stepsHorizontal = -stepsHorizontal
|
||||||
}
|
}
|
||||||
for i := 0; i < stepsHorizontal; i++ {
|
for i := 0; i < stepsHorizontal; i++ {
|
||||||
if err := p.PointerButton(buttonHorizontal, true); err != nil {
|
if err := p.sendButton(buttonHorizontal, true); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := p.PointerButton(buttonHorizontal, false); err != nil {
|
if err := p.sendButton(buttonHorizontal, false); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -190,10 +203,10 @@ func (p *x11Plugin) PointerScroll(deltaHorizontal, deltaVertical int) error {
|
||||||
stepsVertical = -stepsVertical
|
stepsVertical = -stepsVertical
|
||||||
}
|
}
|
||||||
for i := 0; i < stepsVertical; i++ {
|
for i := 0; i < stepsVertical; i++ {
|
||||||
if err := p.PointerButton(buttonVertical, true); err != nil {
|
if err := p.sendButton(buttonVertical, true); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := p.PointerButton(buttonVertical, false); err != nil {
|
if err := p.sendButton(buttonVertical, false); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,10 @@ const POINTER_ACCELERATION = [
|
||||||
[553, 2]
|
[553, 2]
|
||||||
];
|
];
|
||||||
|
|
||||||
|
const POINTER_BUTTON_LEFT = 0;
|
||||||
|
const POINTER_BUTTON_RIGHT = 1;
|
||||||
|
const POINTER_BUTTON_MIDDLE = 2;
|
||||||
|
|
||||||
var ws;
|
var ws;
|
||||||
var pad;
|
var pad;
|
||||||
var padlabel;
|
var padlabel;
|
||||||
|
|
@ -141,7 +145,7 @@ function calculatePointerAccelerationMult(speed) {
|
||||||
|
|
||||||
function onDraggingTimeout() {
|
function onDraggingTimeout() {
|
||||||
draggingTimeout = null;
|
draggingTimeout = null;
|
||||||
ws.send("b1;0");
|
ws.send("b" + POINTER_BUTTON_LEFT + ";0");
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateMoveAndScroll() {
|
function updateMoveAndScroll() {
|
||||||
|
|
@ -215,20 +219,20 @@ function handleEnd(evt) {
|
||||||
}
|
}
|
||||||
if (ongoingTouches.length == 0 && touchReleasedCount >= 1 &&
|
if (ongoingTouches.length == 0 && touchReleasedCount >= 1 &&
|
||||||
dragging) {
|
dragging) {
|
||||||
ws.send("b1;0");
|
ws.send("b" + POINTER_BUTTON_LEFT + ";0");
|
||||||
}
|
}
|
||||||
if (ongoingTouches.length == 0 && touchReleasedCount >= 1 &&
|
if (ongoingTouches.length == 0 && touchReleasedCount >= 1 &&
|
||||||
!touchMoved && evt.timeStamp - touchStart < TOUCH_TIMEOUT) {
|
!touchMoved && evt.timeStamp - touchStart < TOUCH_TIMEOUT) {
|
||||||
var button = 0;
|
var button = 0;
|
||||||
if (touchReleasedCount == 1) {
|
if (touchReleasedCount == 1) {
|
||||||
button = 1;
|
button = POINTER_BUTTON_LEFT;
|
||||||
} else if (touchReleasedCount == 2) {
|
} else if (touchReleasedCount == 2) {
|
||||||
button = 3;
|
button = POINTER_BUTTON_RIGHT;
|
||||||
} else if (touchReleasedCount == 3) {
|
} else if (touchReleasedCount == 3) {
|
||||||
button = 2;
|
button = POINTER_BUTTON_MIDDLE;
|
||||||
}
|
}
|
||||||
ws.send("b" + button + ";1");
|
ws.send("b" + button + ";1");
|
||||||
if (button == 1) {
|
if (button == POINTER_BUTTON_LEFT) {
|
||||||
draggingTimeout = setTimeout(onDraggingTimeout, TOUCH_TIMEOUT);
|
draggingTimeout = setTimeout(onDraggingTimeout, TOUCH_TIMEOUT);
|
||||||
} else {
|
} else {
|
||||||
ws.send("b" + button + ";0");
|
ws.send("b" + button + ";0");
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue