mirror of
https://github.com/m1k1o/neko.git
synced 2025-07-19 01:28:43 +02:00
move server to server directory.
This commit is contained in:
parent
da45f62ca8
commit
cfb423b13d
211 changed files with 18 additions and 10 deletions
122
server/pkg/xinput/xinput.go
Normal file
122
server/pkg/xinput/xinput.go
Normal file
|
@ -0,0 +1,122 @@
|
|||
/* custom xf86 input driver communication protocol */
|
||||
package xinput
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
type driver struct {
|
||||
mu sync.Mutex
|
||||
socket string
|
||||
conn net.Conn
|
||||
|
||||
debounceTouchIds map[uint32]time.Time
|
||||
}
|
||||
|
||||
func NewDriver(socket string) Driver {
|
||||
return &driver{
|
||||
socket: socket,
|
||||
|
||||
debounceTouchIds: make(map[uint32]time.Time),
|
||||
}
|
||||
}
|
||||
|
||||
func (d *driver) Connect() error {
|
||||
c, err := net.Dial("unix", d.socket)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
d.conn = c
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *driver) Close() error {
|
||||
return d.conn.Close()
|
||||
}
|
||||
|
||||
func (d *driver) Debounce(duration time.Duration) {
|
||||
d.mu.Lock()
|
||||
defer d.mu.Unlock()
|
||||
|
||||
t := time.Now()
|
||||
for touchId, start := range d.debounceTouchIds {
|
||||
if t.Sub(start) < duration {
|
||||
continue
|
||||
}
|
||||
|
||||
msg := Message{
|
||||
_type: XI_TouchEnd,
|
||||
touchId: touchId,
|
||||
x: -1,
|
||||
y: -1,
|
||||
}
|
||||
_, _ = d.conn.Write(msg.Pack())
|
||||
delete(d.debounceTouchIds, touchId)
|
||||
}
|
||||
}
|
||||
|
||||
func (d *driver) TouchBegin(touchId uint32, x, y int, pressure uint8) error {
|
||||
d.mu.Lock()
|
||||
defer d.mu.Unlock()
|
||||
|
||||
if _, ok := d.debounceTouchIds[touchId]; ok {
|
||||
return fmt.Errorf("debounced touch id %v", touchId)
|
||||
}
|
||||
|
||||
d.debounceTouchIds[touchId] = time.Now()
|
||||
|
||||
msg := Message{
|
||||
_type: XI_TouchBegin,
|
||||
touchId: touchId,
|
||||
x: int32(x),
|
||||
y: int32(y),
|
||||
pressure: pressure,
|
||||
}
|
||||
_, err := d.conn.Write(msg.Pack())
|
||||
return err
|
||||
}
|
||||
|
||||
func (d *driver) TouchUpdate(touchId uint32, x, y int, pressure uint8) error {
|
||||
d.mu.Lock()
|
||||
defer d.mu.Unlock()
|
||||
|
||||
if _, ok := d.debounceTouchIds[touchId]; !ok {
|
||||
return fmt.Errorf("unknown touch id %v", touchId)
|
||||
}
|
||||
|
||||
d.debounceTouchIds[touchId] = time.Now()
|
||||
|
||||
msg := Message{
|
||||
_type: XI_TouchUpdate,
|
||||
touchId: touchId,
|
||||
x: int32(x),
|
||||
y: int32(y),
|
||||
pressure: pressure,
|
||||
}
|
||||
_, err := d.conn.Write(msg.Pack())
|
||||
return err
|
||||
}
|
||||
|
||||
func (d *driver) TouchEnd(touchId uint32, x, y int, pressure uint8) error {
|
||||
d.mu.Lock()
|
||||
defer d.mu.Unlock()
|
||||
|
||||
if _, ok := d.debounceTouchIds[touchId]; !ok {
|
||||
return fmt.Errorf("unknown touch id %v", touchId)
|
||||
}
|
||||
|
||||
delete(d.debounceTouchIds, touchId)
|
||||
|
||||
msg := Message{
|
||||
_type: XI_TouchEnd,
|
||||
touchId: touchId,
|
||||
x: int32(x),
|
||||
y: int32(y),
|
||||
pressure: pressure,
|
||||
}
|
||||
_, err := d.conn.Write(msg.Pack())
|
||||
return err
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue