main shar/altaica / compositor / src / protocol.zig
  1const wire = @import("wire.zig");
  2const ArgType = wire.ArgType;
  3
  4pub const Interface = enum(u8) {
  5    altaica_shm,
  6    altaica_shm_pool,
  7    wl_buffer,
  8    wl_callback,
  9    wl_compositor,
 10    wl_data_device,
 11    wl_data_device_manager,
 12    wl_data_offer,
 13    wl_data_source,
 14    wl_display,
 15    wl_fixes,
 16    wl_keyboard,
 17    wl_output,
 18    wl_pointer,
 19    wl_region,
 20    wl_registry,
 21    wl_seat,
 22    wl_shell,
 23    wl_shell_surface,
 24    wl_shm,
 25    wl_shm_pool,
 26    wl_subcompositor,
 27    wl_subsurface,
 28    wl_surface,
 29    wl_touch,
 30    wp_viewport,
 31    wp_viewporter,
 32    xdg_popup,
 33    xdg_positioner,
 34    xdg_surface,
 35    xdg_toplevel,
 36    xdg_wm_base,
 37};
 38
 39pub const MessageSig = struct {
 40    opcode: u16,
 41    args: []const ArgType,
 42};
 43
 44pub fn requestSig(iface: Interface, opcode: u16) ?[]const ArgType {
 45    const sigs = requestSigs(iface);
 46    for (sigs) |s| if (s.opcode == opcode) return s.args;
 47    return null;
 48}
 49
 50pub fn eventSig(iface: Interface, opcode: u16) ?[]const ArgType {
 51    const sigs = eventSigs(iface);
 52    for (sigs) |s| if (s.opcode == opcode) return s.args;
 53    return null;
 54}
 55
 56fn requestSigs(iface: Interface) []const MessageSig {
 57    return switch (iface) {
 58        .altaica_shm => &.{
 59            .{ .opcode = 0, .args = &.{.new_id, .int, .int, .uint} },
 60        },
 61        .altaica_shm_pool => &.{
 62            .{ .opcode = 0, .args = &.{.int, .int, .int, .int} },
 63            .{ .opcode = 1, .args = &.{.new_id, .int, .int, .int, .int} },
 64            .{ .opcode = 2, .args = &.{.int, .int} },
 65            .{ .opcode = 3, .args = &.{} },
 66        },
 67        .wl_buffer => &.{
 68            .{ .opcode = 0, .args = &.{} },
 69        },
 70        .wl_callback => &.{},
 71        .wl_compositor => &.{
 72            .{ .opcode = 0, .args = &.{.new_id} },
 73            .{ .opcode = 1, .args = &.{.new_id} },
 74            .{ .opcode = 2, .args = &.{} },
 75        },
 76        .wl_data_device => &.{
 77            .{ .opcode = 0, .args = &.{.object, .object, .object, .uint} },
 78            .{ .opcode = 1, .args = &.{.object, .uint} },
 79            .{ .opcode = 2, .args = &.{} },
 80        },
 81        .wl_data_device_manager => &.{
 82            .{ .opcode = 0, .args = &.{.new_id} },
 83            .{ .opcode = 1, .args = &.{.new_id, .object} },
 84            .{ .opcode = 2, .args = &.{} },
 85        },
 86        .wl_data_offer => &.{
 87            .{ .opcode = 0, .args = &.{.uint, .string} },
 88            .{ .opcode = 1, .args = &.{.string, .fd} },
 89            .{ .opcode = 2, .args = &.{} },
 90            .{ .opcode = 3, .args = &.{} },
 91            .{ .opcode = 4, .args = &.{.uint, .uint} },
 92        },
 93        .wl_data_source => &.{
 94            .{ .opcode = 0, .args = &.{.string} },
 95            .{ .opcode = 1, .args = &.{} },
 96            .{ .opcode = 2, .args = &.{.uint} },
 97        },
 98        .wl_display => &.{
 99            .{ .opcode = 0, .args = &.{.new_id} },
100            .{ .opcode = 1, .args = &.{.new_id} },
101        },
102        .wl_fixes => &.{
103            .{ .opcode = 0, .args = &.{} },
104            .{ .opcode = 1, .args = &.{.object} },
105            .{ .opcode = 2, .args = &.{.object, .uint} },
106        },
107        .wl_keyboard => &.{
108            .{ .opcode = 0, .args = &.{} },
109        },
110        .wl_output => &.{
111            .{ .opcode = 0, .args = &.{} },
112        },
113        .wl_pointer => &.{
114            .{ .opcode = 0, .args = &.{.uint, .object, .int, .int} },
115            .{ .opcode = 1, .args = &.{} },
116        },
117        .wl_region => &.{
118            .{ .opcode = 0, .args = &.{} },
119            .{ .opcode = 1, .args = &.{.int, .int, .int, .int} },
120            .{ .opcode = 2, .args = &.{.int, .int, .int, .int} },
121        },
122        .wl_registry => &.{
123            .{ .opcode = 0, .args = &.{.uint, .new_id} },
124        },
125        .wl_seat => &.{
126            .{ .opcode = 0, .args = &.{.new_id} },
127            .{ .opcode = 1, .args = &.{.new_id} },
128            .{ .opcode = 2, .args = &.{.new_id} },
129            .{ .opcode = 3, .args = &.{} },
130        },
131        .wl_shell => &.{
132            .{ .opcode = 0, .args = &.{.new_id, .object} },
133        },
134        .wl_shell_surface => &.{
135            .{ .opcode = 0, .args = &.{.uint} },
136            .{ .opcode = 1, .args = &.{.object, .uint} },
137            .{ .opcode = 2, .args = &.{.object, .uint, .uint} },
138            .{ .opcode = 3, .args = &.{} },
139            .{ .opcode = 4, .args = &.{.object, .int, .int, .uint} },
140            .{ .opcode = 5, .args = &.{.uint, .uint, .object} },
141            .{ .opcode = 6, .args = &.{.object, .uint, .object, .int, .int, .uint} },
142            .{ .opcode = 7, .args = &.{.object} },
143            .{ .opcode = 8, .args = &.{.string} },
144            .{ .opcode = 9, .args = &.{.string} },
145        },
146        .wl_shm => &.{
147            .{ .opcode = 0, .args = &.{.new_id, .fd, .int} },
148            .{ .opcode = 1, .args = &.{} },
149        },
150        .wl_shm_pool => &.{
151            .{ .opcode = 0, .args = &.{.new_id, .int, .int, .int, .int, .uint} },
152            .{ .opcode = 1, .args = &.{} },
153            .{ .opcode = 2, .args = &.{.int} },
154        },
155        .wl_subcompositor => &.{
156            .{ .opcode = 0, .args = &.{} },
157            .{ .opcode = 1, .args = &.{.new_id, .object, .object} },
158        },
159        .wl_subsurface => &.{
160            .{ .opcode = 0, .args = &.{} },
161            .{ .opcode = 1, .args = &.{.int, .int} },
162            .{ .opcode = 2, .args = &.{.object} },
163            .{ .opcode = 3, .args = &.{.object} },
164            .{ .opcode = 4, .args = &.{} },
165            .{ .opcode = 5, .args = &.{} },
166        },
167        .wl_surface => &.{
168            .{ .opcode = 0, .args = &.{} },
169            .{ .opcode = 1, .args = &.{.object, .int, .int} },
170            .{ .opcode = 2, .args = &.{.int, .int, .int, .int} },
171            .{ .opcode = 3, .args = &.{.new_id} },
172            .{ .opcode = 4, .args = &.{.object} },
173            .{ .opcode = 5, .args = &.{.object} },
174            .{ .opcode = 6, .args = &.{} },
175            .{ .opcode = 7, .args = &.{.int} },
176            .{ .opcode = 8, .args = &.{.int} },
177            .{ .opcode = 9, .args = &.{.int, .int, .int, .int} },
178            .{ .opcode = 10, .args = &.{.int, .int} },
179            .{ .opcode = 11, .args = &.{.new_id} },
180        },
181        .wl_touch => &.{
182            .{ .opcode = 0, .args = &.{} },
183        },
184        .wp_viewport => &.{
185            .{ .opcode = 0, .args = &.{} },
186            .{ .opcode = 1, .args = &.{.fixed, .fixed, .fixed, .fixed} },
187            .{ .opcode = 2, .args = &.{.int, .int} },
188        },
189        .wp_viewporter => &.{
190            .{ .opcode = 0, .args = &.{} },
191            .{ .opcode = 1, .args = &.{.new_id, .object} },
192        },
193        .xdg_popup => &.{
194            .{ .opcode = 0, .args = &.{} },
195            .{ .opcode = 1, .args = &.{.object, .uint} },
196            .{ .opcode = 2, .args = &.{.object, .uint} },
197        },
198        .xdg_positioner => &.{
199            .{ .opcode = 0, .args = &.{} },
200            .{ .opcode = 1, .args = &.{.int, .int} },
201            .{ .opcode = 2, .args = &.{.int, .int, .int, .int} },
202            .{ .opcode = 3, .args = &.{.uint} },
203            .{ .opcode = 4, .args = &.{.uint} },
204            .{ .opcode = 5, .args = &.{.uint} },
205            .{ .opcode = 6, .args = &.{.int, .int} },
206            .{ .opcode = 7, .args = &.{} },
207            .{ .opcode = 8, .args = &.{.int, .int} },
208            .{ .opcode = 9, .args = &.{.uint} },
209        },
210        .xdg_surface => &.{
211            .{ .opcode = 0, .args = &.{} },
212            .{ .opcode = 1, .args = &.{.new_id} },
213            .{ .opcode = 2, .args = &.{.new_id, .object, .object} },
214            .{ .opcode = 3, .args = &.{.int, .int, .int, .int} },
215            .{ .opcode = 4, .args = &.{.uint} },
216        },
217        .xdg_toplevel => &.{
218            .{ .opcode = 0, .args = &.{} },
219            .{ .opcode = 1, .args = &.{.object} },
220            .{ .opcode = 2, .args = &.{.string} },
221            .{ .opcode = 3, .args = &.{.string} },
222            .{ .opcode = 4, .args = &.{.object, .uint, .int, .int} },
223            .{ .opcode = 5, .args = &.{.object, .uint} },
224            .{ .opcode = 6, .args = &.{.object, .uint, .uint} },
225            .{ .opcode = 7, .args = &.{.int, .int} },
226            .{ .opcode = 8, .args = &.{.int, .int} },
227            .{ .opcode = 9, .args = &.{} },
228            .{ .opcode = 10, .args = &.{} },
229            .{ .opcode = 11, .args = &.{.object} },
230            .{ .opcode = 12, .args = &.{} },
231            .{ .opcode = 13, .args = &.{} },
232        },
233        .xdg_wm_base => &.{
234            .{ .opcode = 0, .args = &.{} },
235            .{ .opcode = 1, .args = &.{.new_id} },
236            .{ .opcode = 2, .args = &.{.new_id, .object} },
237            .{ .opcode = 3, .args = &.{.uint} },
238        },
239    };
240}
241
242fn eventSigs(iface: Interface) []const MessageSig {
243    return switch (iface) {
244        .altaica_shm => &.{},
245        .altaica_shm_pool => &.{},
246        .wl_buffer => &.{
247            .{ .opcode = 0, .args = &.{} },
248        },
249        .wl_callback => &.{
250            .{ .opcode = 0, .args = &.{.uint} },
251        },
252        .wl_compositor => &.{},
253        .wl_data_device => &.{
254            .{ .opcode = 0, .args = &.{.new_id} },
255            .{ .opcode = 1, .args = &.{.uint, .object, .fixed, .fixed, .object} },
256            .{ .opcode = 2, .args = &.{} },
257            .{ .opcode = 3, .args = &.{.uint, .fixed, .fixed} },
258            .{ .opcode = 4, .args = &.{} },
259            .{ .opcode = 5, .args = &.{.object} },
260        },
261        .wl_data_device_manager => &.{},
262        .wl_data_offer => &.{
263            .{ .opcode = 0, .args = &.{.string} },
264            .{ .opcode = 1, .args = &.{.uint} },
265            .{ .opcode = 2, .args = &.{.uint} },
266        },
267        .wl_data_source => &.{
268            .{ .opcode = 0, .args = &.{.string} },
269            .{ .opcode = 1, .args = &.{.string, .fd} },
270            .{ .opcode = 2, .args = &.{} },
271            .{ .opcode = 3, .args = &.{} },
272            .{ .opcode = 4, .args = &.{} },
273            .{ .opcode = 5, .args = &.{.uint} },
274        },
275        .wl_display => &.{
276            .{ .opcode = 0, .args = &.{.object, .uint, .string} },
277            .{ .opcode = 1, .args = &.{.uint} },
278        },
279        .wl_fixes => &.{},
280        .wl_keyboard => &.{
281            .{ .opcode = 0, .args = &.{.uint, .fd, .uint} },
282            .{ .opcode = 1, .args = &.{.uint, .object, .array} },
283            .{ .opcode = 2, .args = &.{.uint, .object} },
284            .{ .opcode = 3, .args = &.{.uint, .uint, .uint, .uint} },
285            .{ .opcode = 4, .args = &.{.uint, .uint, .uint, .uint, .uint} },
286            .{ .opcode = 5, .args = &.{.int, .int} },
287        },
288        .wl_output => &.{
289            .{ .opcode = 0, .args = &.{.int, .int, .int, .int, .int, .string, .string, .int} },
290            .{ .opcode = 1, .args = &.{.uint, .int, .int, .int} },
291            .{ .opcode = 2, .args = &.{} },
292            .{ .opcode = 3, .args = &.{.int} },
293            .{ .opcode = 4, .args = &.{.string} },
294            .{ .opcode = 5, .args = &.{.string} },
295        },
296        .wl_pointer => &.{
297            .{ .opcode = 0, .args = &.{.uint, .object, .fixed, .fixed} },
298            .{ .opcode = 1, .args = &.{.uint, .object} },
299            .{ .opcode = 2, .args = &.{.uint, .fixed, .fixed} },
300            .{ .opcode = 3, .args = &.{.uint, .uint, .uint, .uint} },
301            .{ .opcode = 4, .args = &.{.uint, .uint, .fixed} },
302            .{ .opcode = 5, .args = &.{} },
303            .{ .opcode = 6, .args = &.{.uint} },
304            .{ .opcode = 7, .args = &.{.uint, .uint} },
305            .{ .opcode = 8, .args = &.{.uint, .int} },
306            .{ .opcode = 9, .args = &.{.uint, .int} },
307            .{ .opcode = 10, .args = &.{.uint, .uint} },
308            .{ .opcode = 11, .args = &.{.fixed, .fixed} },
309        },
310        .wl_region => &.{},
311        .wl_registry => &.{
312            .{ .opcode = 0, .args = &.{.uint, .string, .uint} },
313            .{ .opcode = 1, .args = &.{.uint} },
314        },
315        .wl_seat => &.{
316            .{ .opcode = 0, .args = &.{.uint} },
317            .{ .opcode = 1, .args = &.{.string} },
318        },
319        .wl_shell => &.{},
320        .wl_shell_surface => &.{
321            .{ .opcode = 0, .args = &.{.uint} },
322            .{ .opcode = 1, .args = &.{.uint, .int, .int} },
323            .{ .opcode = 2, .args = &.{} },
324        },
325        .wl_shm => &.{
326            .{ .opcode = 0, .args = &.{.uint} },
327        },
328        .wl_shm_pool => &.{},
329        .wl_subcompositor => &.{},
330        .wl_subsurface => &.{},
331        .wl_surface => &.{
332            .{ .opcode = 0, .args = &.{.object} },
333            .{ .opcode = 1, .args = &.{.object} },
334            .{ .opcode = 2, .args = &.{.int} },
335            .{ .opcode = 3, .args = &.{.uint} },
336        },
337        .wl_touch => &.{
338            .{ .opcode = 0, .args = &.{.uint, .uint, .object, .int, .fixed, .fixed} },
339            .{ .opcode = 1, .args = &.{.uint, .uint, .int} },
340            .{ .opcode = 2, .args = &.{.uint, .int, .fixed, .fixed} },
341            .{ .opcode = 3, .args = &.{} },
342            .{ .opcode = 4, .args = &.{} },
343            .{ .opcode = 5, .args = &.{.int, .fixed, .fixed} },
344            .{ .opcode = 6, .args = &.{.int, .fixed} },
345        },
346        .wp_viewport => &.{},
347        .wp_viewporter => &.{},
348        .xdg_popup => &.{
349            .{ .opcode = 0, .args = &.{.int, .int, .int, .int} },
350            .{ .opcode = 1, .args = &.{} },
351            .{ .opcode = 2, .args = &.{.uint} },
352        },
353        .xdg_positioner => &.{},
354        .xdg_surface => &.{
355            .{ .opcode = 0, .args = &.{.uint} },
356        },
357        .xdg_toplevel => &.{
358            .{ .opcode = 0, .args = &.{.int, .int, .array} },
359            .{ .opcode = 1, .args = &.{} },
360            .{ .opcode = 2, .args = &.{.int, .int} },
361            .{ .opcode = 3, .args = &.{.array} },
362        },
363        .xdg_wm_base => &.{
364            .{ .opcode = 0, .args = &.{.uint} },
365        },
366    };
367}
368
369pub fn globalName(iface: Interface) []const u8 {
370    return switch (iface) {
371        .altaica_shm => "altaica_shm",
372        .altaica_shm_pool => "altaica_shm_pool",
373        .wl_buffer => "wl_buffer",
374        .wl_callback => "wl_callback",
375        .wl_compositor => "wl_compositor",
376        .wl_data_device => "wl_data_device",
377        .wl_data_device_manager => "wl_data_device_manager",
378        .wl_data_offer => "wl_data_offer",
379        .wl_data_source => "wl_data_source",
380        .wl_display => "wl_display",
381        .wl_fixes => "wl_fixes",
382        .wl_keyboard => "wl_keyboard",
383        .wl_output => "wl_output",
384        .wl_pointer => "wl_pointer",
385        .wl_region => "wl_region",
386        .wl_registry => "wl_registry",
387        .wl_seat => "wl_seat",
388        .wl_shell => "wl_shell",
389        .wl_shell_surface => "wl_shell_surface",
390        .wl_shm => "wl_shm",
391        .wl_shm_pool => "wl_shm_pool",
392        .wl_subcompositor => "wl_subcompositor",
393        .wl_subsurface => "wl_subsurface",
394        .wl_surface => "wl_surface",
395        .wl_touch => "wl_touch",
396        .wp_viewport => "wp_viewport",
397        .wp_viewporter => "wp_viewporter",
398        .xdg_popup => "xdg_popup",
399        .xdg_positioner => "xdg_positioner",
400        .xdg_surface => "xdg_surface",
401        .xdg_toplevel => "xdg_toplevel",
402        .xdg_wm_base => "xdg_wm_base",
403    };
404}
405
406pub fn globalVersion(iface: Interface) u32 {
407    return switch (iface) {
408        .altaica_shm => 1,
409        .altaica_shm_pool => 1,
410        .wl_buffer => 1,
411        .wl_callback => 1,
412        .wl_compositor => 7,
413        .wl_data_device => 4,
414        .wl_data_device_manager => 4,
415        .wl_data_offer => 4,
416        .wl_data_source => 4,
417        .wl_display => 1,
418        .wl_fixes => 2,
419        .wl_keyboard => 11,
420        .wl_output => 4,
421        .wl_pointer => 11,
422        .wl_region => 7,
423        .wl_registry => 1,
424        .wl_seat => 11,
425        .wl_shell => 1,
426        .wl_shell_surface => 1,
427        .wl_shm => 2,
428        .wl_shm_pool => 2,
429        .wl_subcompositor => 1,
430        .wl_subsurface => 1,
431        .wl_surface => 7,
432        .wl_touch => 11,
433        .wp_viewport => 1,
434        .wp_viewporter => 1,
435        .xdg_popup => 7,
436        .xdg_positioner => 7,
437        .xdg_surface => 7,
438        .xdg_toplevel => 7,
439        .xdg_wm_base => 7,
440    };
441}