@asdf-overlay/electron 1.0.0 → 1.0.2
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/input.d.ts +3 -1
- package/lib/input.js +46 -34
- package/package.json +2 -2
package/lib/input.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type WebContents } from 'electron';
|
|
2
2
|
import type { OverlayWindow } from './index.js';
|
|
3
3
|
import type { CursorInput, KeyboardInput } from '@asdf-overlay/core/input';
|
|
4
4
|
/**
|
|
@@ -10,6 +10,8 @@ export declare class ElectronOverlayInput {
|
|
|
10
10
|
private readonly cursorInputHandler;
|
|
11
11
|
private readonly keyboardInputHandler;
|
|
12
12
|
private readonly cursorChangedHandler;
|
|
13
|
+
private readonly displayMetricsChangedHandler;
|
|
14
|
+
private screenScaleFactor;
|
|
13
15
|
private constructor();
|
|
14
16
|
/**
|
|
15
17
|
* Connect overlay inputs to a Electron `WebContents`.
|
package/lib/input.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { screen } from 'electron';
|
|
1
2
|
import { mapCssCursor, mapKeycode } from './input/conv.js';
|
|
2
3
|
import { Cursor } from '@asdf-overlay/core';
|
|
3
4
|
/**
|
|
@@ -9,10 +10,16 @@ export class ElectronOverlayInput {
|
|
|
9
10
|
cursorInputHandler;
|
|
10
11
|
keyboardInputHandler;
|
|
11
12
|
cursorChangedHandler;
|
|
13
|
+
displayMetricsChangedHandler;
|
|
14
|
+
screenScaleFactor;
|
|
12
15
|
constructor(window, contents) {
|
|
13
16
|
this.window = window;
|
|
14
17
|
this.contents = contents;
|
|
15
18
|
this.window = { ...window };
|
|
19
|
+
this.screenScaleFactor = screen.getPrimaryDisplay().scaleFactor;
|
|
20
|
+
screen.addListener('display-metrics-changed', this.displayMetricsChangedHandler = () => {
|
|
21
|
+
this.screenScaleFactor = screen.getPrimaryDisplay().scaleFactor;
|
|
22
|
+
});
|
|
16
23
|
this.window.overlay.event.on('cursor_input', this.cursorInputHandler = (id, input) => {
|
|
17
24
|
if (id !== window.id) {
|
|
18
25
|
return;
|
|
@@ -39,6 +46,7 @@ export class ElectronOverlayInput {
|
|
|
39
46
|
* Disconnect overlay inputs.
|
|
40
47
|
*/
|
|
41
48
|
async disconnect() {
|
|
49
|
+
screen.removeListener('display-metrics-changed', this.displayMetricsChangedHandler);
|
|
42
50
|
this.window.overlay.event.off('cursor_input', this.cursorInputHandler);
|
|
43
51
|
this.window.overlay.event.off('keyboard_input', this.keyboardInputHandler);
|
|
44
52
|
this.contents.off('cursor-changed', this.cursorChangedHandler);
|
|
@@ -50,7 +58,7 @@ export class ElectronOverlayInput {
|
|
|
50
58
|
}
|
|
51
59
|
}
|
|
52
60
|
clickCounts = [];
|
|
53
|
-
processCursorAction(input, movementX, movementY) {
|
|
61
|
+
processCursorAction(input, x, y, globalX, globalY, movementX, movementY) {
|
|
54
62
|
let button;
|
|
55
63
|
switch (input.action) {
|
|
56
64
|
case 'Left': {
|
|
@@ -81,10 +89,10 @@ export class ElectronOverlayInput {
|
|
|
81
89
|
type: 'mouseDown',
|
|
82
90
|
button,
|
|
83
91
|
clickCount,
|
|
84
|
-
x
|
|
85
|
-
y
|
|
86
|
-
globalX
|
|
87
|
-
globalY
|
|
92
|
+
x,
|
|
93
|
+
y,
|
|
94
|
+
globalX,
|
|
95
|
+
globalY,
|
|
88
96
|
movementX,
|
|
89
97
|
movementY,
|
|
90
98
|
modifiers: this.modifiers,
|
|
@@ -96,10 +104,10 @@ export class ElectronOverlayInput {
|
|
|
96
104
|
type: 'mouseUp',
|
|
97
105
|
button,
|
|
98
106
|
clickCount,
|
|
99
|
-
x
|
|
100
|
-
y
|
|
101
|
-
globalX
|
|
102
|
-
globalY
|
|
107
|
+
x,
|
|
108
|
+
y,
|
|
109
|
+
globalX,
|
|
110
|
+
globalY,
|
|
103
111
|
movementX,
|
|
104
112
|
movementY,
|
|
105
113
|
modifiers: this.modifiers,
|
|
@@ -111,16 +119,20 @@ export class ElectronOverlayInput {
|
|
|
111
119
|
y: 0,
|
|
112
120
|
};
|
|
113
121
|
sendCursorInput(input) {
|
|
114
|
-
const
|
|
115
|
-
const
|
|
122
|
+
const x = input.clientX / this.screenScaleFactor;
|
|
123
|
+
const y = input.clientY / this.screenScaleFactor;
|
|
124
|
+
const globalX = input.windowX / this.screenScaleFactor;
|
|
125
|
+
const globalY = input.windowY / this.screenScaleFactor;
|
|
126
|
+
const movementX = globalX - this.lastWindowCursor.x;
|
|
127
|
+
const movementY = globalY - this.lastWindowCursor.y;
|
|
116
128
|
switch (input.kind) {
|
|
117
129
|
case 'Enter': {
|
|
118
130
|
this.contents.sendInputEvent({
|
|
119
131
|
type: 'mouseEnter',
|
|
120
|
-
x
|
|
121
|
-
y
|
|
122
|
-
globalX
|
|
123
|
-
globalY
|
|
132
|
+
x,
|
|
133
|
+
y,
|
|
134
|
+
globalX,
|
|
135
|
+
globalY,
|
|
124
136
|
movementX,
|
|
125
137
|
movementY,
|
|
126
138
|
modifiers: this.modifiers,
|
|
@@ -130,10 +142,10 @@ export class ElectronOverlayInput {
|
|
|
130
142
|
case 'Leave': {
|
|
131
143
|
this.contents.sendInputEvent({
|
|
132
144
|
type: 'mouseLeave',
|
|
133
|
-
x
|
|
134
|
-
y
|
|
135
|
-
globalX
|
|
136
|
-
globalY
|
|
145
|
+
x,
|
|
146
|
+
y,
|
|
147
|
+
globalX,
|
|
148
|
+
globalY,
|
|
137
149
|
movementX,
|
|
138
150
|
movementY,
|
|
139
151
|
modifiers: this.modifiers,
|
|
@@ -143,10 +155,10 @@ export class ElectronOverlayInput {
|
|
|
143
155
|
case 'Move': {
|
|
144
156
|
this.contents.sendInputEvent({
|
|
145
157
|
type: 'mouseMove',
|
|
146
|
-
x
|
|
147
|
-
y
|
|
148
|
-
globalX
|
|
149
|
-
globalY
|
|
158
|
+
x,
|
|
159
|
+
y,
|
|
160
|
+
globalX,
|
|
161
|
+
globalY,
|
|
150
162
|
movementX,
|
|
151
163
|
movementY,
|
|
152
164
|
modifiers: this.modifiers,
|
|
@@ -159,10 +171,10 @@ export class ElectronOverlayInput {
|
|
|
159
171
|
scroll = {
|
|
160
172
|
type: 'mouseWheel',
|
|
161
173
|
deltaY: input.delta,
|
|
162
|
-
x
|
|
163
|
-
y
|
|
164
|
-
globalX
|
|
165
|
-
globalY
|
|
174
|
+
x,
|
|
175
|
+
y,
|
|
176
|
+
globalX,
|
|
177
|
+
globalY,
|
|
166
178
|
movementX,
|
|
167
179
|
movementY,
|
|
168
180
|
modifiers: this.modifiers,
|
|
@@ -172,10 +184,10 @@ export class ElectronOverlayInput {
|
|
|
172
184
|
scroll = {
|
|
173
185
|
type: 'mouseWheel',
|
|
174
186
|
deltaX: input.delta,
|
|
175
|
-
x
|
|
176
|
-
y
|
|
177
|
-
globalX
|
|
178
|
-
globalY
|
|
187
|
+
x,
|
|
188
|
+
y,
|
|
189
|
+
globalX,
|
|
190
|
+
globalY,
|
|
179
191
|
movementX,
|
|
180
192
|
movementY,
|
|
181
193
|
modifiers: this.modifiers,
|
|
@@ -185,12 +197,12 @@ export class ElectronOverlayInput {
|
|
|
185
197
|
break;
|
|
186
198
|
}
|
|
187
199
|
case 'Action': {
|
|
188
|
-
this.processCursorAction(input, movementX, movementY);
|
|
200
|
+
this.processCursorAction(input, x, y, globalX, globalY, movementX, movementY);
|
|
189
201
|
break;
|
|
190
202
|
}
|
|
191
203
|
}
|
|
192
|
-
this.lastWindowCursor.x =
|
|
193
|
-
this.lastWindowCursor.y =
|
|
204
|
+
this.lastWindowCursor.x = globalX;
|
|
205
|
+
this.lastWindowCursor.y = globalY;
|
|
194
206
|
}
|
|
195
207
|
modifiersMap = {
|
|
196
208
|
shift: false,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@asdf-overlay/electron",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "Asdf overlay Electron integration",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"types": "./lib/index.d.ts",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": {
|
|
36
36
|
"electron": "^37.3.1",
|
|
37
|
-
"@asdf-overlay/core": "1.0.
|
|
37
|
+
"@asdf-overlay/core": "1.0.2"
|
|
38
38
|
},
|
|
39
39
|
"scripts": {
|
|
40
40
|
"build:dist": "tsc",
|