import { Socket } from "node:net"; import { EventEmitter } from "node:events"; import { Wl_display, Wl_registry } from "../protocol/wayland.js"; import Wl_interface from "./interface.js"; import { EnumReduction, InterfaceDefinition, RequestDefinition } from "./definitions.js"; export default class Display extends EventEmitter { #private; protected readonly _maxId = 4278190079; constructor(s: Socket); /** * Initializes a wl_display. Loads the core protocol and binds to wl_registry to fetch the server's globals. */ init(): Promise; /** * Special handler for {@link https://wayland.app/protocols/wayland#wl_display:event:error wl_display::error} events * They are caught before being wired through the standard interface logic * to prevent confusion between "standard errors" (eg: bad usage of an interface) and protocol errors * * All errors can thus be caught using `display.on("error", err =>{})` * Remember that WaylandProtocolError are fatal and the connection will no longer be usable afterwards * * ```js * display.on("error", err =>{ * if(err.name == "WaylandProtocolError") console.error("FATAL ERROR", err); * else console.log("Usage error : ", err); * }); * ``` */ protected _handleProtocolError(msg: Buffer): void; protected _bindRegistry(registry: Wl_interface): void; /** * Return the first found available ID * @returns {number} an available ID */ protected nextId(): number; get wl_display(): Wl_display; get wl_registry(): Wl_registry; /** * Handles data received from the socket. It split individual messages and delegates parsing to `Display.onMessage()` */ protected onData: (d: Buffer) => void; /** * top-level message parsing and dispatching */ protected onMessage(id: number, evcode: number, msg: Buffer): boolean | undefined; /** * Load a protocol definition from a XML or JSON file * @param filepath path to the XML/JSON file to load */ load(interfaces: any[]): Promise; load(filepath: string): Promise; /** * Binds a global. see the [Wayland handbook](https://wayland-book.com/registry/binding.html) to learn how this works. * @see Wl_registry.bind() */ bind(iname: T["name"], version?: number): Promise; /** * Create a new interface, allocating it's ID automatically. * @internal It is normally not used directly, but through Display.bind that creates globals, then through the globals' requests that will call it as needed */ createInterface(name: string, version?: number): T; /** * Instanciate a server-created interface. * Like Display.createInterface but do not allocate an ID * Used internally and for server-created objects * @internal there is normally no use case for a user to call this directly */ registerInterface(id: number, name: string, version?: number): T; /** * Unreferences an object ID * Typically after it has been destroyed */ deleteId(id: number): void; /** * */ getObject(iName: string): Wl_interface | undefined; /** * Iterate over all registered objects */ objects(): Generator; getDefinition(name: string): InterfaceDefinition; getEnum(name: string): EnumReduction; /**List the name of all known globals */ listGlobals(): MapIterator; write(b: Buffer | string): Promise; /** * */ request(srcId: number, opcode: number, def: RequestDefinition, ...args: any[]): Promise; sync(): Promise; close(): Promise; }