types.h (2765B)
1 // types.h: function prototypes, structs and data types 2 typedef struct { 3 char *data; 4 uint8_t len; 5 } string; 6 7 static uint32_t wayland_current_id = 1; 8 9 static const uint32_t wayland_display_object_id = 1; 10 static const uint16_t wayland_wl_registry_event_global = 0; 11 static const uint16_t wayland_shm_pool_event_format = 0; 12 static const uint16_t wayland_wl_buffer_event_release = 0; 13 static const uint16_t wayland_xdg_wm_base_event_ping = 0; 14 static const uint16_t wayland_xdg_toplevel_event_configure = 0; 15 static const uint16_t wayland_xdg_toplevel_event_close = 1; 16 static const uint16_t wayland_xdg_surface_event_configure = 0; 17 static const uint16_t wayland_wl_display_get_registry_opcode = 1; 18 static const uint16_t wayland_wl_registry_bind_opcode = 0; 19 static const uint16_t wayland_wl_compositor_create_surface_opcode = 0; 20 static const uint16_t wayland_xdg_wm_base_pong_opcode = 3; 21 static const uint16_t wayland_xdg_surface_ack_configure_opcode = 4; 22 static const uint16_t wayland_wl_shm_create_pool_opcode = 0; 23 static const uint16_t wayland_xdg_wm_base_get_xdg_surface_opcode = 2; 24 static const uint16_t wayland_wl_shm_pool_create_buffer_opcode = 0; 25 static const uint16_t wayland_wl_surface_attach_opcode = 1; 26 static const uint16_t wayland_xdg_surface_get_toplevel_opcode = 1; 27 static const uint16_t wayland_wl_surface_commit_opcode = 6; 28 static const uint16_t wayland_wl_display_error_event = 0; 29 static const uint32_t wayland_format_xrgb8888 = 1; 30 static const uint32_t wayland_header_size = 8; 31 static const uint32_t color_channels = 4; 32 typedef enum state_state_t state_state_t; 33 34 enum state_state_t { 35 STATE_NONE, 36 STATE_SURFACE_ACKED_CONFIGURE, 37 STATE_SURFACE_ATTACHED, 38 }; 39 40 typedef struct state_t state_t; 41 struct state_t { 42 uint32_t wl_registry; 43 uint32_t wl_shm; 44 uint32_t wl_shm_pool; 45 uint32_t wl_buffer; 46 uint32_t xdg_wm_base; 47 uint32_t xdg_surface; 48 uint32_t wl_compositor; 49 uint32_t wl_surface; 50 uint32_t xdg_toplevel; 51 uint32_t stride; 52 uint32_t w; 53 uint32_t h; 54 uint32_t shm_pool_size; 55 int shm_fd; 56 uint8_t *shm_pool_data; 57 state_state_t state; 58 }; 59 60 // wl.c 61 int wayland_display_connect(string *wsp); 62 void wayland_handle_message(int fd, state_t *state, char **msg, 63 uint64_t *msg_len); 64 uint32_t wayland_wl_display_get_registry(int fd); 65 66 // buf.c 67 void buf_write_u32(char *buf, uint64_t *buf_size, uint64_t buf_cap, uint32_t x); 68 void buf_write_u16(char *buf, uint64_t *buf_size, uint64_t buf_cap, uint16_t x); 69 void buf_write_string(char *buf, uint64_t *buf_size, uint64_t buf_cap, 70 char *src, uint32_t src_len); 71 uint32_t buf_read_u32(char **buf, uint64_t *buf_size); 72 uint16_t buf_read_u16(char **buf, uint64_t *buf_size); 73 void buf_read_n(char **buf, uint64_t *buf_size, char *dst, uint64_t n);