bare-pointer 0.1.6 → 0.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/darwin.js +70 -8
- package/package.json +2 -2
package/lib/darwin.js
CHANGED
|
@@ -14,6 +14,8 @@ module.exports = class DarwinPointer {
|
|
|
14
14
|
this._window = null
|
|
15
15
|
this._point = null
|
|
16
16
|
this._press = 0
|
|
17
|
+
this._tap = null
|
|
18
|
+
this._monitor = null
|
|
17
19
|
}
|
|
18
20
|
|
|
19
21
|
size(view) {
|
|
@@ -66,19 +68,27 @@ module.exports = class DarwinPointer {
|
|
|
66
68
|
}
|
|
67
69
|
|
|
68
70
|
tap(view, x, y) {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
+
this._tap = {
|
|
72
|
+
window: view.window,
|
|
73
|
+
point: view.convertPointToView(x, y, null),
|
|
74
|
+
missed: false,
|
|
75
|
+
dropping: false
|
|
76
|
+
}
|
|
71
77
|
|
|
72
|
-
this.
|
|
78
|
+
if (this._monitor === null) {
|
|
79
|
+
this._monitor = AppKitEvent.addLocalMonitorForEventsMatchingMask(
|
|
80
|
+
MASK.LEFT_MOUSE_DOWN | MASK.LEFT_MOUSE_UP,
|
|
81
|
+
this._onevent.bind(this)
|
|
82
|
+
)
|
|
83
|
+
}
|
|
73
84
|
|
|
74
|
-
|
|
75
|
-
AppKitApplication.postEvent(this._event(TYPE.LEFT_MOUSE_DOWN, window, point), true)
|
|
85
|
+
this._post()
|
|
76
86
|
}
|
|
77
87
|
|
|
78
88
|
pending(view) {
|
|
79
89
|
const window = view.window
|
|
80
90
|
|
|
81
|
-
if (window === null) return
|
|
91
|
+
if (window === null || this._tap === null) return this._unmonitor()
|
|
82
92
|
|
|
83
93
|
const event = AppKitApplication.nextEventMatchingMask(
|
|
84
94
|
MASK.LEFT_MOUSE_DOWN | MASK.LEFT_MOUSE_UP,
|
|
@@ -87,10 +97,39 @@ module.exports = class DarwinPointer {
|
|
|
87
97
|
false
|
|
88
98
|
)
|
|
89
99
|
|
|
90
|
-
|
|
100
|
+
if (event !== null && event.windowNumber === window.windowNumber) return true
|
|
101
|
+
|
|
102
|
+
if (this._tap.missed) {
|
|
103
|
+
this._post()
|
|
104
|
+
|
|
105
|
+
return true
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
return this._unmonitor()
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
destroy() {
|
|
112
|
+
this._unmonitor()
|
|
91
113
|
}
|
|
92
114
|
|
|
93
|
-
|
|
115
|
+
_post() {
|
|
116
|
+
const { window, point } = this._tap
|
|
117
|
+
|
|
118
|
+
this._tap.missed = false
|
|
119
|
+
this._press++
|
|
120
|
+
|
|
121
|
+
AppKitApplication.postEvent(this._event(TYPE.LEFT_MOUSE_UP, window, point), true)
|
|
122
|
+
AppKitApplication.postEvent(this._event(TYPE.LEFT_MOUSE_DOWN, window, point), true)
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
_unmonitor() {
|
|
126
|
+
if (this._monitor !== null) AppKitEvent.removeMonitor(this._monitor)
|
|
127
|
+
|
|
128
|
+
this._monitor = null
|
|
129
|
+
this._tap = null
|
|
130
|
+
|
|
131
|
+
return false
|
|
132
|
+
}
|
|
94
133
|
|
|
95
134
|
_send(type, view, x, y) {
|
|
96
135
|
this._window = view.window
|
|
@@ -110,4 +149,27 @@ module.exports = class DarwinPointer {
|
|
|
110
149
|
this._press
|
|
111
150
|
)
|
|
112
151
|
}
|
|
152
|
+
|
|
153
|
+
_onevent(event) {
|
|
154
|
+
const tap = this._tap
|
|
155
|
+
|
|
156
|
+
if (tap === null || event.windowNumber !== tap.window.windowNumber) return event
|
|
157
|
+
|
|
158
|
+
if (event.type === TYPE.LEFT_MOUSE_UP) {
|
|
159
|
+
if (!tap.dropping) return event
|
|
160
|
+
|
|
161
|
+
tap.dropping = false
|
|
162
|
+
|
|
163
|
+
return null
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
const { x, y } = event.locationInWindow
|
|
167
|
+
|
|
168
|
+
if (Math.abs(x - tap.point.x) < 1 && Math.abs(y - tap.point.y) < 1) return event
|
|
169
|
+
|
|
170
|
+
tap.missed = true
|
|
171
|
+
tap.dropping = true
|
|
172
|
+
|
|
173
|
+
return null
|
|
174
|
+
}
|
|
113
175
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bare-pointer",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.7",
|
|
4
4
|
"description": "Simulated pointer input for testing Bare apps",
|
|
5
5
|
"exports": {
|
|
6
6
|
"./package": "./package.json",
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"homepage": "https://github.com/holepunchto/bare-pointer#readme",
|
|
49
49
|
"dependencies": {
|
|
50
50
|
"bare-animation-frame": "^0.1.1",
|
|
51
|
-
"bare-app-kit": "^0.3.
|
|
51
|
+
"bare-app-kit": "^0.3.4",
|
|
52
52
|
"bare-foundation": "^0.1.1",
|
|
53
53
|
"bare-ndk": "^0.3.4",
|
|
54
54
|
"bare-ui-kit-touch": "^0.1.0",
|