bare-pointer 0.1.5 → 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.
Files changed (2) hide show
  1. package/lib/darwin.js +84 -10
  2. package/package.json +3 -2
package/lib/darwin.js CHANGED
@@ -1,6 +1,7 @@
1
1
  const AnimationFrameProvider = require('bare-animation-frame')
2
2
  const AppKitApplication = require('bare-app-kit/application')
3
3
  const AppKitEvent = require('bare-app-kit/event')
4
+ const FoundationProcessInfo = require('bare-foundation/process-info')
4
5
 
5
6
  const { TYPE, MASK } = AppKitEvent
6
7
 
@@ -12,6 +13,9 @@ module.exports = class DarwinPointer {
12
13
  constructor() {
13
14
  this._window = null
14
15
  this._point = null
16
+ this._press = 0
17
+ this._tap = null
18
+ this._monitor = null
15
19
  }
16
20
 
17
21
  size(view) {
@@ -50,6 +54,8 @@ module.exports = class DarwinPointer {
50
54
  }
51
55
 
52
56
  down(view, x, y) {
57
+ this._press++
58
+
53
59
  this._send(TYPE.LEFT_MOUSE_DOWN, view, x, y)
54
60
  }
55
61
 
@@ -62,19 +68,27 @@ module.exports = class DarwinPointer {
62
68
  }
63
69
 
64
70
  tap(view, x, y) {
65
- const window = view.window
66
- const point = view.convertPointToView(x, y, null)
71
+ this._tap = {
72
+ window: view.window,
73
+ point: view.convertPointToView(x, y, null),
74
+ missed: false,
75
+ dropping: false
76
+ }
67
77
 
68
- // Ahead of anything already queued that could take the window off key, as
69
- // the first press in a window that is not key only makes it key.
70
- AppKitApplication.postEvent(this._event(TYPE.LEFT_MOUSE_UP, window, point), true)
71
- AppKitApplication.postEvent(this._event(TYPE.LEFT_MOUSE_DOWN, window, point), true)
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
+ }
84
+
85
+ this._post()
72
86
  }
73
87
 
74
88
  pending(view) {
75
89
  const window = view.window
76
90
 
77
- if (window === null) return false
91
+ if (window === null || this._tap === null) return this._unmonitor()
78
92
 
79
93
  const event = AppKitApplication.nextEventMatchingMask(
80
94
  MASK.LEFT_MOUSE_DOWN | MASK.LEFT_MOUSE_UP,
@@ -83,10 +97,39 @@ module.exports = class DarwinPointer {
83
97
  false
84
98
  )
85
99
 
86
- return event !== null && event.windowNumber === window.windowNumber
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()
113
+ }
114
+
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)
87
123
  }
88
124
 
89
- destroy() {}
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
+ }
90
133
 
91
134
  _send(type, view, x, y) {
92
135
  this._window = view.window
@@ -96,6 +139,37 @@ module.exports = class DarwinPointer {
96
139
  }
97
140
 
98
141
  _event(type, window, point) {
99
- return AppKitEvent.mouseEvent(type, point.x, point.y, 0, 0, window.windowNumber)
142
+ return AppKitEvent.mouseEvent(
143
+ type,
144
+ point.x,
145
+ point.y,
146
+ 0,
147
+ FoundationProcessInfo.processInfo.systemUptime,
148
+ window.windowNumber,
149
+ this._press
150
+ )
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
100
174
  }
101
175
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bare-pointer",
3
- "version": "0.1.5",
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,8 @@
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.3",
51
+ "bare-app-kit": "^0.3.4",
52
+ "bare-foundation": "^0.1.1",
52
53
  "bare-ndk": "^0.3.4",
53
54
  "bare-ui-kit-touch": "^0.1.0",
54
55
  "bare-user32": "^0.1.1",