@asdf-overlay/electron 1.2.5 → 2.0.0
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/index.d.ts +18 -1
- package/lib/input.d.ts +2 -3
- package/lib/input.js +27 -32
- package/lib/surface.d.ts +4 -5
- package/lib/surface.js +12 -12
- package/package.json +8 -8
package/lib/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Overlay } from '@asdf-overlay/core';
|
|
1
|
+
import type { Overlay, SurfaceInfo } from '@asdf-overlay/core';
|
|
2
2
|
/**
|
|
3
3
|
* Describe a window in `Overlay`.
|
|
4
4
|
*/
|
|
@@ -12,3 +12,20 @@ export type OverlayWindow = {
|
|
|
12
12
|
*/
|
|
13
13
|
id: number;
|
|
14
14
|
};
|
|
15
|
+
/**
|
|
16
|
+
* Describe a surface in `Overlay`.
|
|
17
|
+
*/
|
|
18
|
+
export type OverlaySurface = {
|
|
19
|
+
/**
|
|
20
|
+
* Associated `Overlay` instance.
|
|
21
|
+
*/
|
|
22
|
+
overlay: Overlay;
|
|
23
|
+
/**
|
|
24
|
+
* Surface id.
|
|
25
|
+
*/
|
|
26
|
+
id: bigint;
|
|
27
|
+
/**
|
|
28
|
+
* Surface info.
|
|
29
|
+
*/
|
|
30
|
+
info: SurfaceInfo;
|
|
31
|
+
};
|
package/lib/input.d.ts
CHANGED
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
import { type WebContents } from 'electron';
|
|
2
2
|
import type { OverlayWindow } from './index.js';
|
|
3
|
-
import type { CursorInput, KeyboardInput } from '@asdf-overlay/core
|
|
3
|
+
import type { CursorInput, KeyboardInput } from '@asdf-overlay/core';
|
|
4
4
|
/**
|
|
5
5
|
* Connection from a overlay window to a Electron window.
|
|
6
6
|
*/
|
|
7
7
|
export declare class ElectronOverlayInput {
|
|
8
8
|
private readonly window;
|
|
9
9
|
private readonly contents;
|
|
10
|
+
private readonly scaleFactor;
|
|
10
11
|
private readonly cursorInputHandler;
|
|
11
12
|
private readonly keyboardInputHandler;
|
|
12
13
|
private readonly cursorChangedHandler;
|
|
13
|
-
private readonly displayMetricsChangedHandler;
|
|
14
|
-
private screenScaleFactor;
|
|
15
14
|
private constructor();
|
|
16
15
|
/**
|
|
17
16
|
* Connect overlay inputs to a Electron `WebContents`.
|
package/lib/input.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {} from 'electron';
|
|
2
2
|
import { mapCssCursor, mapKeycode } from './input/conv.js';
|
|
3
3
|
import { Cursor } from '@asdf-overlay/core';
|
|
4
4
|
/**
|
|
@@ -7,60 +7,55 @@ import { Cursor } from '@asdf-overlay/core';
|
|
|
7
7
|
export class ElectronOverlayInput {
|
|
8
8
|
window;
|
|
9
9
|
contents;
|
|
10
|
+
scaleFactor;
|
|
10
11
|
cursorInputHandler;
|
|
11
12
|
keyboardInputHandler;
|
|
12
13
|
cursorChangedHandler;
|
|
13
|
-
|
|
14
|
-
screenScaleFactor;
|
|
15
|
-
constructor(window, contents) {
|
|
14
|
+
constructor(window, contents, scaleFactor) {
|
|
16
15
|
this.window = window;
|
|
17
16
|
this.contents = contents;
|
|
17
|
+
this.scaleFactor = scaleFactor;
|
|
18
18
|
this.window = { ...window };
|
|
19
|
-
this.
|
|
20
|
-
screen.addListener('display-metrics-changed', this.displayMetricsChangedHandler = () => {
|
|
21
|
-
this.screenScaleFactor = screen.getPrimaryDisplay().scaleFactor;
|
|
22
|
-
});
|
|
23
|
-
this.window.overlay.event.on('cursor_input', this.cursorInputHandler = (id, input) => {
|
|
19
|
+
this.window.overlay.event.on('window_cursor_input', this.cursorInputHandler = (id, input) => {
|
|
24
20
|
if (id !== window.id) {
|
|
25
21
|
return;
|
|
26
22
|
}
|
|
27
23
|
this.sendCursorInput(input);
|
|
28
24
|
});
|
|
29
|
-
this.window.overlay.event.on('
|
|
25
|
+
this.window.overlay.event.on('window_keyboard_input', this.keyboardInputHandler = (id, input) => {
|
|
30
26
|
if (id !== window.id) {
|
|
31
27
|
return;
|
|
32
28
|
}
|
|
33
29
|
this.sendKeyboardInput(input);
|
|
34
30
|
});
|
|
35
31
|
this.contents.on('cursor-changed', this.cursorChangedHandler = (_, type) => {
|
|
36
|
-
void this.window.overlay.setBlockingCursor(
|
|
32
|
+
void this.window.overlay.setBlockingCursor(mapCssCursor(type));
|
|
37
33
|
});
|
|
38
34
|
}
|
|
39
35
|
/**
|
|
40
36
|
* Connect overlay inputs to a Electron `WebContents`.
|
|
41
37
|
*/
|
|
42
38
|
static connect(window, contents) {
|
|
43
|
-
return new ElectronOverlayInput({ ...window }, contents);
|
|
39
|
+
return new ElectronOverlayInput({ ...window }, contents, 1.0 /* todo */);
|
|
44
40
|
}
|
|
45
41
|
/**
|
|
46
42
|
* Disconnect overlay inputs.
|
|
47
43
|
*/
|
|
48
44
|
async disconnect() {
|
|
49
|
-
|
|
50
|
-
this.window.overlay.event.off('
|
|
51
|
-
this.window.overlay.event.off('keyboard_input', this.keyboardInputHandler);
|
|
45
|
+
this.window.overlay.event.off('window_cursor_input', this.cursorInputHandler);
|
|
46
|
+
this.window.overlay.event.off('window_keyboard_input', this.keyboardInputHandler);
|
|
52
47
|
this.contents.off('cursor-changed', this.cursorChangedHandler);
|
|
53
48
|
try {
|
|
54
|
-
await this.window.overlay.setBlockingCursor(
|
|
49
|
+
await this.window.overlay.setBlockingCursor(Cursor.Default);
|
|
55
50
|
}
|
|
56
51
|
catch {
|
|
57
52
|
//
|
|
58
53
|
}
|
|
59
54
|
}
|
|
60
55
|
clickCounts = [];
|
|
61
|
-
processCursorAction(
|
|
56
|
+
processCursorAction(input_kind, x, y, globalX, globalY, movementX, movementY) {
|
|
62
57
|
let button;
|
|
63
|
-
switch (
|
|
58
|
+
switch (input_kind.action) {
|
|
64
59
|
case 'Left': {
|
|
65
60
|
button = 'left';
|
|
66
61
|
break;
|
|
@@ -82,8 +77,8 @@ export class ElectronOverlayInput {
|
|
|
82
77
|
return;
|
|
83
78
|
}
|
|
84
79
|
}
|
|
85
|
-
if (
|
|
86
|
-
const clickCount =
|
|
80
|
+
if (input_kind.state.type === 'Pressed') {
|
|
81
|
+
const clickCount = input_kind.state.clickCount;
|
|
87
82
|
this.clickCounts.push(clickCount);
|
|
88
83
|
this.contents.sendInputEvent({
|
|
89
84
|
type: 'mouseDown',
|
|
@@ -99,7 +94,7 @@ export class ElectronOverlayInput {
|
|
|
99
94
|
});
|
|
100
95
|
}
|
|
101
96
|
else {
|
|
102
|
-
const clickCount = this.clickCounts.pop() ??
|
|
97
|
+
const clickCount = this.clickCounts.pop() ?? 0;
|
|
103
98
|
this.contents.sendInputEvent({
|
|
104
99
|
type: 'mouseUp',
|
|
105
100
|
button,
|
|
@@ -119,13 +114,13 @@ export class ElectronOverlayInput {
|
|
|
119
114
|
y: 0,
|
|
120
115
|
};
|
|
121
116
|
sendCursorInput(input) {
|
|
122
|
-
const x = input.
|
|
123
|
-
const y = input.
|
|
124
|
-
const globalX = input.
|
|
125
|
-
const globalY = input.
|
|
117
|
+
const x = input.x / this.scaleFactor;
|
|
118
|
+
const y = input.y / this.scaleFactor;
|
|
119
|
+
const globalX = input.x / this.scaleFactor;
|
|
120
|
+
const globalY = input.y / this.scaleFactor;
|
|
126
121
|
const movementX = globalX - this.lastWindowCursor.x;
|
|
127
122
|
const movementY = globalY - this.lastWindowCursor.y;
|
|
128
|
-
switch (input.kind) {
|
|
123
|
+
switch (input.kind.type) {
|
|
129
124
|
case 'Enter': {
|
|
130
125
|
this.contents.sendInputEvent({
|
|
131
126
|
type: 'mouseEnter',
|
|
@@ -167,10 +162,10 @@ export class ElectronOverlayInput {
|
|
|
167
162
|
}
|
|
168
163
|
case 'Scroll': {
|
|
169
164
|
let scroll;
|
|
170
|
-
if (input.axis === 'Y') {
|
|
165
|
+
if (input.kind.axis === 'Y') {
|
|
171
166
|
scroll = {
|
|
172
167
|
type: 'mouseWheel',
|
|
173
|
-
deltaY: input.delta,
|
|
168
|
+
deltaY: input.kind.delta,
|
|
174
169
|
x,
|
|
175
170
|
y,
|
|
176
171
|
globalX,
|
|
@@ -183,7 +178,7 @@ export class ElectronOverlayInput {
|
|
|
183
178
|
else {
|
|
184
179
|
scroll = {
|
|
185
180
|
type: 'mouseWheel',
|
|
186
|
-
deltaX: input.delta,
|
|
181
|
+
deltaX: input.kind.delta,
|
|
187
182
|
x,
|
|
188
183
|
y,
|
|
189
184
|
globalX,
|
|
@@ -197,7 +192,7 @@ export class ElectronOverlayInput {
|
|
|
197
192
|
break;
|
|
198
193
|
}
|
|
199
194
|
case 'Action': {
|
|
200
|
-
this.processCursorAction(input, x, y, globalX, globalY, movementX, movementY);
|
|
195
|
+
this.processCursorAction(input.kind, x, y, globalX, globalY, movementX, movementY);
|
|
201
196
|
break;
|
|
202
197
|
}
|
|
203
198
|
}
|
|
@@ -256,7 +251,7 @@ export class ElectronOverlayInput {
|
|
|
256
251
|
}
|
|
257
252
|
}
|
|
258
253
|
sendKeyboardInput(input) {
|
|
259
|
-
switch (input.
|
|
254
|
+
switch (input.type) {
|
|
260
255
|
case 'Key': {
|
|
261
256
|
const keyCode = mapKeycode(input.key.code);
|
|
262
257
|
if (!keyCode) {
|
|
@@ -286,7 +281,7 @@ export class ElectronOverlayInput {
|
|
|
286
281
|
}
|
|
287
282
|
}
|
|
288
283
|
processIme(input) {
|
|
289
|
-
if (input.ime.
|
|
284
|
+
if (input.ime.type !== 'Commit') {
|
|
290
285
|
return;
|
|
291
286
|
}
|
|
292
287
|
for (const ch of input.ime.text) {
|
package/lib/surface.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { WebContents } from 'electron';
|
|
2
|
-
import type { OverlayWindow } from './index.js';
|
|
3
2
|
import EventEmitter from 'node:events';
|
|
4
|
-
import {
|
|
3
|
+
import type { OverlaySurface } from './index.js';
|
|
5
4
|
type Emitter = EventEmitter<{
|
|
6
5
|
/**
|
|
7
6
|
* An error has been occured while copying to overlay surface.
|
|
@@ -12,19 +11,19 @@ type Emitter = EventEmitter<{
|
|
|
12
11
|
* Connection from a Electron offscreen window to a overlay surface.
|
|
13
12
|
*/
|
|
14
13
|
export declare class ElectronOverlaySurface {
|
|
15
|
-
private readonly
|
|
14
|
+
private readonly surface;
|
|
16
15
|
private readonly contents;
|
|
17
16
|
/**
|
|
18
17
|
* Events during paints.
|
|
19
18
|
*/
|
|
20
19
|
readonly events: Emitter;
|
|
21
20
|
private handler;
|
|
22
|
-
private readonly
|
|
21
|
+
private readonly inner;
|
|
23
22
|
private constructor();
|
|
24
23
|
/**
|
|
25
24
|
* Connect Electron `WebContents` surface to target overlay window.
|
|
26
25
|
*/
|
|
27
|
-
static connect(
|
|
26
|
+
static connect(surface: OverlaySurface, contents: WebContents): ElectronOverlaySurface;
|
|
28
27
|
/**
|
|
29
28
|
* Disconnect surface from Electron window and clear overlay surface.
|
|
30
29
|
*/
|
package/lib/surface.js
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
1
|
import EventEmitter from 'node:events';
|
|
2
|
-
import { OverlaySurface } from '@asdf-overlay/core';
|
|
2
|
+
import { OverlaySurface as CoreOverlaySurface } from '@asdf-overlay/core';
|
|
3
3
|
/**
|
|
4
4
|
* Connection from a Electron offscreen window to a overlay surface.
|
|
5
5
|
*/
|
|
6
6
|
export class ElectronOverlaySurface {
|
|
7
|
-
|
|
7
|
+
surface;
|
|
8
8
|
contents;
|
|
9
9
|
/**
|
|
10
10
|
* Events during paints.
|
|
11
11
|
*/
|
|
12
12
|
events = new EventEmitter();
|
|
13
13
|
handler;
|
|
14
|
-
|
|
15
|
-
constructor(
|
|
16
|
-
this.
|
|
14
|
+
inner;
|
|
15
|
+
constructor(surface, contents) {
|
|
16
|
+
this.surface = surface;
|
|
17
17
|
this.contents = contents;
|
|
18
|
-
this.
|
|
18
|
+
this.inner = new CoreOverlaySurface(surface.info.gpuId);
|
|
19
19
|
this.handler = (e, rect, image) => {
|
|
20
20
|
try {
|
|
21
21
|
const update = e.texture ? this.paintAccelerated(e.texture) : this.paintSoftware(rect, image);
|
|
22
22
|
if (update) {
|
|
23
|
-
this.
|
|
23
|
+
this.surface.overlay.updateHandle(this.surface.id, update)
|
|
24
24
|
.catch((e) => this.events.emit('error', e));
|
|
25
25
|
}
|
|
26
26
|
}
|
|
@@ -34,15 +34,15 @@ export class ElectronOverlaySurface {
|
|
|
34
34
|
/**
|
|
35
35
|
* Connect Electron `WebContents` surface to target overlay window.
|
|
36
36
|
*/
|
|
37
|
-
static connect(
|
|
38
|
-
return new ElectronOverlaySurface({ ...
|
|
37
|
+
static connect(surface, contents) {
|
|
38
|
+
return new ElectronOverlaySurface({ ...surface }, contents);
|
|
39
39
|
}
|
|
40
40
|
/**
|
|
41
41
|
* Disconnect surface from Electron window and clear overlay surface.
|
|
42
42
|
*/
|
|
43
43
|
async disconnect() {
|
|
44
44
|
this.contents.off('paint', this.handler);
|
|
45
|
-
await this.
|
|
45
|
+
await this.surface.overlay.updateHandle(this.surface.id, { type: 'None' });
|
|
46
46
|
}
|
|
47
47
|
/**
|
|
48
48
|
* Copy overlay texture in gpu accelerated shared texture mode.
|
|
@@ -56,7 +56,7 @@ export class ElectronOverlaySurface {
|
|
|
56
56
|
}
|
|
57
57
|
const rect = info.metadata.captureUpdateRect ?? info.contentRect;
|
|
58
58
|
// update only changed part
|
|
59
|
-
return this.
|
|
59
|
+
return this.inner.updateNtShtex(info.codedSize.width, info.codedSize.height, info.handle.ntHandle, {
|
|
60
60
|
dstX: rect.x,
|
|
61
61
|
dstY: rect.y,
|
|
62
62
|
src: rect,
|
|
@@ -76,6 +76,6 @@ export class ElectronOverlaySurface {
|
|
|
76
76
|
return null;
|
|
77
77
|
}
|
|
78
78
|
// TODO:: update only changed part
|
|
79
|
-
return this.
|
|
79
|
+
return this.inner.updateBitmap(image.getSize().width, image.toBitmap());
|
|
80
80
|
}
|
|
81
81
|
}
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@asdf-overlay/electron",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "Asdf overlay Electron integration",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"types": "./lib/index.d.ts",
|
|
7
7
|
"type": "module",
|
|
8
|
-
"author": "storycraft <
|
|
8
|
+
"author": "storycraft <me@pancake.sh>",
|
|
9
9
|
"homepage": "https://github.com/storycraft/asdf-overlay#readme",
|
|
10
10
|
"license": "MIT OR Apache-2.0",
|
|
11
11
|
"bugs": {
|
|
@@ -29,15 +29,15 @@
|
|
|
29
29
|
"lib/**/*"
|
|
30
30
|
],
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@types/node": "^
|
|
33
|
-
"typescript": "^
|
|
32
|
+
"@types/node": "^22.13.14",
|
|
33
|
+
"typescript": "^7.0.2"
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": {
|
|
36
|
-
"electron": "^
|
|
37
|
-
"@asdf-overlay/core": "
|
|
36
|
+
"electron": "^43.3.0",
|
|
37
|
+
"@asdf-overlay/core": "2.0.0"
|
|
38
38
|
},
|
|
39
39
|
"scripts": {
|
|
40
|
-
"build:
|
|
41
|
-
"build": "npm run build:
|
|
40
|
+
"build:publish": "tsc",
|
|
41
|
+
"build": "npm run build:publish"
|
|
42
42
|
}
|
|
43
43
|
}
|