mirror of
https://github.com/yume-chan/ya-webadb.git
synced 2025-10-03 17:59:50 +02:00
refactor(scrcpy): rewrite option classes to improve tree-shaking
This commit is contained in:
parent
db8466f6ee
commit
92472007db
218 changed files with 5412 additions and 2380 deletions
50
libraries/scrcpy/src/1_25/impl/scroll-controller.ts
Normal file
50
libraries/scrcpy/src/1_25/impl/scroll-controller.ts
Normal file
|
@ -0,0 +1,50 @@
|
|||
import { getInt16, setInt16 } from "@yume-chan/no-data-view";
|
||||
import type { Field, StructInit } from "@yume-chan/struct";
|
||||
import { bipedal, struct, u16, u32, u8 } from "@yume-chan/struct";
|
||||
|
||||
import type { ScrcpyScrollController } from "../../base/index.js";
|
||||
import type { ScrcpyInjectScrollControlMessage } from "../../latest.js";
|
||||
|
||||
import { PrevImpl } from "./prev.js";
|
||||
|
||||
export const SignedFloat: Field<number, never, never> = {
|
||||
size: 2,
|
||||
serialize(value, { buffer, index, littleEndian }) {
|
||||
// https://github.com/Genymobile/scrcpy/blob/1f138aef41de651668043b32c4effc2d4adbfc44/app/src/util/binary.h#L51
|
||||
value = PrevImpl.clamp(value, -1, 1);
|
||||
value = value === 1 ? 0x7fff : value * 0x8000;
|
||||
setInt16(buffer, index, value, littleEndian);
|
||||
},
|
||||
deserialize: bipedal(function* (then, { reader, littleEndian }) {
|
||||
const data = yield* then(reader.readExactly(2));
|
||||
const value = getInt16(data, 0, littleEndian);
|
||||
// https://github.com/Genymobile/scrcpy/blob/1f138aef41de651668043b32c4effc2d4adbfc44/server/src/main/java/com/genymobile/scrcpy/Binary.java#L34
|
||||
return value === 0x7fff ? 1 : value / 0x8000;
|
||||
}),
|
||||
};
|
||||
|
||||
export const InjectScrollControlMessage = struct(
|
||||
{
|
||||
type: u8,
|
||||
pointerX: u32,
|
||||
pointerY: u32,
|
||||
screenWidth: u16,
|
||||
screenHeight: u16,
|
||||
scrollX: SignedFloat,
|
||||
scrollY: SignedFloat,
|
||||
buttons: u32,
|
||||
},
|
||||
{ littleEndian: false },
|
||||
);
|
||||
|
||||
export type InjectScrollControlMessage = StructInit<
|
||||
typeof InjectScrollControlMessage
|
||||
>;
|
||||
|
||||
export class ScrollController implements ScrcpyScrollController {
|
||||
serializeScrollMessage(
|
||||
message: ScrcpyInjectScrollControlMessage,
|
||||
): Uint8Array | undefined {
|
||||
return InjectScrollControlMessage.serialize(message);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue