Skip to content
This repository has been archived by the owner on Jul 18, 2024. It is now read-only.

Add pointer to xf86 input driver #56

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions pkg/xinput/dummy.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,19 @@ func (d *dummy) TouchUpdate(touchId uint32, x, y int, pressure uint8) error {
func (d *dummy) TouchEnd(touchId uint32, x, y int, pressure uint8) error {
return nil
}

func (d *dummy) Move(x, y int) error {
return nil
}

func (d *dummy) ButtonDown(button uint32) error {
return nil
}

func (d *dummy) ButtonUp(button uint32) error {
return nil
}

func (d *dummy) Scroll(x, y int) error {
return nil
}
28 changes: 22 additions & 6 deletions pkg/xinput/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,23 @@ const (
)

const (
XI_TouchBegin = 18
XI_TouchUpdate = 19
XI_TouchEnd = 20
msgTouchBegin = 1
msgTouchUpdate = 2
msgTouchEndWithPayload = 3
msgTouchEndWithoutPayload = 4
msgPointerMotion = 5
msgButtonDown = 6
msgButtonUp = 7
msgScrollMotion = 8
)

type Message struct {
_type uint16
touchId uint32
x int32 // can be negative?
y int32 // can be negative?
x int32
y int32
pressure uint8
button uint32
}

func (msg *Message) Unpack(buffer []byte) {
Expand All @@ -28,10 +34,11 @@ func (msg *Message) Unpack(buffer []byte) {
msg.x = int32(buffer[3]) | (int32(buffer[4]) << 8) | (int32(buffer[5]) << 16) | (int32(buffer[6]) << 24)
msg.y = int32(buffer[7]) | (int32(buffer[8]) << 8) | (int32(buffer[9]) << 16) | (int32(buffer[10]) << 24)
msg.pressure = uint8(buffer[11])
msg.button = uint32(buffer[12]) | (uint32(buffer[13]) << 8) | (uint32(buffer[14]) << 16) | (uint32(buffer[15]) << 24)
}

func (msg *Message) Pack() []byte {
var buffer [12]byte
var buffer [16]byte

buffer[0] = byte(msg._type)
buffer[1] = byte(msg.touchId)
Expand All @@ -45,6 +52,10 @@ func (msg *Message) Pack() []byte {
buffer[9] = byte(msg.y >> 16)
buffer[10] = byte(msg.y >> 24)
buffer[11] = byte(msg.pressure)
buffer[12] = byte(msg.button)
buffer[13] = byte(msg.button >> 8)
buffer[14] = byte(msg.button >> 16)
buffer[15] = byte(msg.button >> 24)

return buffer[:]
}
Expand All @@ -58,4 +69,9 @@ type Driver interface {
TouchBegin(touchId uint32, x, y int, pressure uint8) error
TouchUpdate(touchId uint32, x, y int, pressure uint8) error
TouchEnd(touchId uint32, x, y int, pressure uint8) error
// mouse events
Move(x, y int) error
ButtonDown(button uint32) error
ButtonUp(button uint32) error
Scroll(x, y int) error
}
48 changes: 42 additions & 6 deletions pkg/xinput/xinput.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,8 @@ func (d *driver) Debounce(duration time.Duration) {
}

msg := Message{
_type: XI_TouchEnd,
_type: msgTouchEndWithoutPayload,
touchId: touchId,
x: -1,
y: -1,
}
_, _ = d.conn.Write(msg.Pack())
delete(d.debounceTouchIds, touchId)
Expand All @@ -69,7 +67,7 @@ func (d *driver) TouchBegin(touchId uint32, x, y int, pressure uint8) error {
d.debounceTouchIds[touchId] = time.Now()

msg := Message{
_type: XI_TouchBegin,
_type: msgTouchBegin,
touchId: touchId,
x: int32(x),
y: int32(y),
Expand All @@ -90,7 +88,7 @@ func (d *driver) TouchUpdate(touchId uint32, x, y int, pressure uint8) error {
d.debounceTouchIds[touchId] = time.Now()

msg := Message{
_type: XI_TouchUpdate,
_type: msgTouchUpdate,
touchId: touchId,
x: int32(x),
y: int32(y),
Expand All @@ -111,7 +109,7 @@ func (d *driver) TouchEnd(touchId uint32, x, y int, pressure uint8) error {
delete(d.debounceTouchIds, touchId)

msg := Message{
_type: XI_TouchEnd,
_type: msgTouchEndWithPayload,
touchId: touchId,
x: int32(x),
y: int32(y),
Expand All @@ -120,3 +118,41 @@ func (d *driver) TouchEnd(touchId uint32, x, y int, pressure uint8) error {
_, err := d.conn.Write(msg.Pack())
return err
}

func (d *driver) Move(x, y int) error {
msg := Message{
_type: msgPointerMotion,
x: int32(x),
y: int32(y),
}
_, err := d.conn.Write(msg.Pack())
return err
}

func (d *driver) ButtonDown(button uint32) error {
msg := Message{
_type: msgButtonDown,
button: button,
}
_, err := d.conn.Write(msg.Pack())
return err
}

func (d *driver) ButtonUp(button uint32) error {
msg := Message{
_type: msgButtonUp,
button: button,
}
_, err := d.conn.Write(msg.Pack())
return err
}

func (d *driver) Scroll(x, y int) error {
msg := Message{
_type: msgScrollMotion,
x: int32(x),
y: int32(y),
}
_, err := d.conn.Write(msg.Pack())
return err
}
Loading