MCPcopy Create free account
hub / github.com/RtlZeroMemory/Rezi / processEventBatch

Function processEventBatch

packages/core/src/app/createApp/eventLoop.ts:152–398  ·  view source on GitHub ↗
(
    batch: BackendEventBatch,
    releasedBatches: Set<BackendEventBatch>,
  )

Source from the content-addressed store, hash-verified

150 }
151
152 function processEventBatch(
153 batch: BackendEventBatch,
154 releasedBatches: Set<BackendEventBatch>,
155 ): void {
156 const release = releaseOnce(batch, releasedBatches);
157
158 const parseToken = perfMarkStart("event_parse");
159 const parsed = parseEventBatchV1(batch.bytes, {
160 maxTotalSize: options.config.maxEventBytes,
161 timeUnwrap: options.timeUnwrap,
162 });
163 perfMarkEnd("event_parse", parseToken);
164 if (!parsed.ok) {
165 release();
166 options.fatalNowOrEnqueue(
167 "ZRUI_PROTOCOL_ERROR",
168 `${parsed.error.code}: ${parsed.error.detail}`,
169 );
170 return;
171 }
172
173 const engineTruncated = (parsed.value.flags & 1) !== 0;
174 const droppedBatches = batch.droppedBatches;
175
176 try {
177 if (engineTruncated || droppedBatches > 0) {
178 if (!options.emit({ kind: "overrun", engineTruncated, droppedBatches })) return;
179 if (options.getRuntimeState() !== "Running") return;
180 }
181
182 for (const ev of parsed.value.events) {
183 const pairedShiftText =
184 pendingShiftTextPair !== null &&
185 ev.kind === "text" &&
186 ev.timeMs === pendingShiftTextPair.timeMs &&
187 ev.codepoint === pendingShiftTextPair.codepoint
188 ? pendingShiftTextPair
189 : null;
190 pendingShiftTextPair = null;
191
192 if (ev.kind === "key" || ev.kind === "text" || ev.kind === "paste" || ev.kind === "mouse") {
193 options.setInteractiveBudget(2);
194 }
195 options.noteBreadcrumbEvent(ev.kind);
196 if (!options.emit({ kind: "engine", event: ev })) return;
197 if (options.getRuntimeState() !== "Running") return;
198
199 if (ev.kind === "resize") {
200 const prev = options.getViewport();
201 if (prev === null || prev.cols !== ev.cols || prev.rows !== ev.rows) {
202 options.setViewport(Object.freeze({ cols: ev.cols, rows: ev.rows }));
203 if (options.widgetRenderer.hasViewportAwareComposites()) {
204 options.widgetRenderer.invalidateCompositeWidgets();
205 options.markDirty(DIRTY_LAYOUT | DIRTY_VIEW);
206 } else {
207 options.markDirty(DIRTY_LAYOUT);
208 }
209 }

Callers 1

processTurnFunction · 0.85

Calls 15

releaseOnceFunction · 0.85
perfMarkStartFunction · 0.85
parseEventBatchV1Function · 0.85
perfMarkEndFunction · 0.85
releaseFunction · 0.85
perfNowFunction · 0.85
isTopLevelRetryEventFunction · 0.85
isTopLevelQuitEventFunction · 0.85
resetChordStateFunction · 0.85
routeKeyEventFunction · 0.85
codepointToCtrlKeyCodeFunction · 0.85
codepointToKeyCodeFunction · 0.85

Tested by

no test coverage detected