bare-pointer 0.1.6 → 0.1.8
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/lib/linux.js +29 -0
- package/package.json +3 -3
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/lib/linux.js
CHANGED
|
@@ -10,6 +10,21 @@ module.exports = class LinuxPointer {
|
|
|
10
10
|
return [view.width, view.height]
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
+
covered(view, x, y) {
|
|
14
|
+
const point = this._point(view, x, y)
|
|
15
|
+
const root = this._display.defaultRootWindow
|
|
16
|
+
const window = this._toplevel(view.native.surface.xid)
|
|
17
|
+
|
|
18
|
+
const { child } = this._display.translateCoordinates(root, root, point.x, point.y)
|
|
19
|
+
|
|
20
|
+
if (child === window) return false
|
|
21
|
+
|
|
22
|
+
this._display.raiseWindow(window)
|
|
23
|
+
this._display.sync()
|
|
24
|
+
|
|
25
|
+
return true
|
|
26
|
+
}
|
|
27
|
+
|
|
13
28
|
watch(view, onhidden) {
|
|
14
29
|
const window = view.native
|
|
15
30
|
|
|
@@ -48,6 +63,20 @@ module.exports = class LinuxPointer {
|
|
|
48
63
|
this._display.close()
|
|
49
64
|
}
|
|
50
65
|
|
|
66
|
+
// A window manager can put the window in a frame of its own, which is what is
|
|
67
|
+
// stacked among the other windows.
|
|
68
|
+
_toplevel(window) {
|
|
69
|
+
const root = this._display.defaultRootWindow
|
|
70
|
+
|
|
71
|
+
while (true) {
|
|
72
|
+
const { parent } = this._display.queryTree(window)
|
|
73
|
+
|
|
74
|
+
if (parent === root) return window
|
|
75
|
+
|
|
76
|
+
window = parent
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
51
80
|
_move(view, x, y) {
|
|
52
81
|
const point = this._point(view, x, y)
|
|
53
82
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bare-pointer",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.8",
|
|
4
4
|
"description": "Simulated pointer input for testing Bare apps",
|
|
5
5
|
"exports": {
|
|
6
6
|
"./package": "./package.json",
|
|
@@ -48,13 +48,13 @@
|
|
|
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",
|
|
55
55
|
"bare-user32": "^0.1.1",
|
|
56
56
|
"bare-win-ui": "^0.3.7",
|
|
57
|
-
"bare-x11": "^0.1.
|
|
57
|
+
"bare-x11": "^0.1.1",
|
|
58
58
|
"bare-x11-xtest": "^0.1.0"
|
|
59
59
|
},
|
|
60
60
|
"devDependencies": {
|