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