Skip to content

Commit b50f513

Browse files
committed
Better mouse emulation in GUI
1 parent 21c9751 commit b50f513

1 file changed

Lines changed: 15 additions & 5 deletions

File tree

virtual_touchscreen.clj

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
(defn create-touchscreen-window [events]
6363
(def tracking-id (atom 1))
6464
(def currently-pressed (atom 0))
65+
(def master-slot (atom nil)) ;; the slot that it pressed first and used for mouse emulation
6566

6667
(defn send-string! [s]
6768
(locking events
@@ -70,9 +71,12 @@
7071

7172
(defn toucher-moved [i x y]
7273
;; Send select-slot, touch-x, touch-y, x and y for mouse emulation and sync messages
73-
(send-string! (format
74-
"s %d\nX %d\nY %d\nx %d\ny %d\nS 0\n"
75-
i, x, y, x, y)))
74+
(send-string!
75+
(if (or (= i @master-slot) (= nil @master-slot))
76+
(format "s %d\nX %d\nY %d\nx %d\ny %d\nS 0\n" i, x, y, x, y)
77+
(format "s %d\nX %d\nY %d\nS 0\n" i, x, y)
78+
)
79+
))
7680

7781
(defn toucher-active [i flag]
7882
;; Send select-slot, tracking-id, touch-major-axis, pressure, trigger-mouse-emu and sync messages
@@ -81,14 +85,20 @@
8185
part1 (format "s %d\nT %d\n0 10\n: 100\ne 0\n", i, @tracking-id)
8286
_ (swap! tracking-id (fn[i] (if (> i 10000) 1 (inc i))))
8387
part2 (if (= @currently-pressed 0)
84-
"d 0\nS 0\n"
88+
(do
89+
(swap! master-slot (fn[_] i))
90+
"d 0\nS 0\n"
91+
)
8592
"S 0\n")
8693
_ (swap! currently-pressed inc)
8794
] (str part1 part2)))
8895
(do (let [
8996
part1 (format "s %d\nT -1\n0 0\n: 0\ne 0\n", i)
9097
part2 (if (= @currently-pressed 1)
91-
"u 0\nS 0\n"
98+
(do
99+
(swap! master-slot (fn[_] nil))
100+
"u 0\nS 0\n"
101+
)
92102
"S 0\n")
93103
_ (swap! currently-pressed dec)
94104
] (str part1 part2))))))

0 commit comments

Comments
 (0)