mandelbrot-wl.h (2019B)
1 #ifndef MANDELBROT_WL_H 2 #define MANDELBROT_WL_H 3 4 #include <assert.h> 5 #include <errno.h> 6 #include <fcntl.h> 7 #include <inttypes.h> 8 #include <limits.h> 9 #include <stdarg.h> 10 #include <stdbool.h> 11 #include <stdint.h> 12 #include <stdio.h> 13 #include <stdlib.h> 14 #include <string.h> 15 #include <sys/mman.h> 16 #include <time.h> 17 #include <unistd.h> 18 19 #include <xkbcommon/xkbcommon.h> 20 #include <wayland-client.h> 21 #include <wayland-cursor.h> 22 #include "xdg-shell.h" 23 24 #define ARRLEN(arr) (sizeof (arr) / sizeof ((arr)[0])) 25 26 typedef int8_t b8; 27 typedef int32_t b32; 28 29 typedef uint8_t u8; 30 typedef uint16_t u16; 31 typedef uint32_t u32; 32 typedef uint64_t u64; 33 34 typedef int8_t s8; 35 typedef int16_t s16; 36 typedef int32_t s32; 37 typedef int64_t s64; 38 39 typedef float f32; 40 typedef double f64; 41 42 typedef union { 43 u32 v; 44 struct { u8 b, g, r, a; }; // NOTE: little-endian ARGB 45 } pixel_argb8888_t; 46 47 #define MAX_HEIGHT 1080 48 #define MAX_WIDTH 1920 49 #define MAX_BUFFER_SZ (MAX_HEIGHT * MAX_WIDTH * sizeof(pixel_argb8888_t)) 50 51 #define WL_SHM_POOL_SZ MAX_BUFFER_SZ 52 53 #define NSECS 1E9 54 55 enum pointer_ev_type : u32 { 56 POINTER_EV_ENTER = 1 << 0, 57 POINTER_EV_LEAVE = 1 << 1, 58 POINTER_EV_MOTION = 1 << 2, 59 POINTER_EV_BUTTON = 1 << 3, 60 POINTER_EV_AXIS = 1 << 4, 61 POINTER_EV_AXIS_SOURCE = 1 << 5, 62 POINTER_EV_AXIS_STOP = 1 << 6, 63 POINTER_EV_AXIS_DISCRETE = 1 << 7, 64 }; 65 66 struct pointer_ev { 67 u32 ev_mask; 68 wl_fixed_t px, py; 69 u32 button, button_state; 70 u32 time; 71 u32 serial; 72 struct { 73 b32 dirty; 74 wl_fixed_t value; 75 s32 discrete; 76 } axes[2]; 77 u32 axis_source; 78 }; 79 80 enum touch_ev_type : u32 { 81 TOUCH_EV_DOWN = 1 << 0, 82 TOUCH_EV_UP = 1 << 1, 83 TOUCH_EV_MOTION = 1 << 2, 84 TOUCH_EV_CANCEL = 1 << 3, 85 TOUCH_EV_SHAPE = 1 << 4, 86 TOUCH_EV_ORIENTATION = 1 << 5, 87 }; 88 89 struct touch_point { 90 b32 dirty; 91 s32 id; 92 u32 ev_mask; 93 wl_fixed_t px, py; 94 wl_fixed_t major, minor; 95 wl_fixed_t orientation; 96 }; 97 98 struct touch_ev { 99 u32 ev_mask; 100 u32 time; 101 u32 serial; 102 struct touch_point points[10]; // NOTE: arbitrary 10 because a human has 10 fingers 103 }; 104 105 #endif /* MANDELBROT_WL_H */