Include super basic memory arena
This commit is contained in:
parent
b2fe2b09ef
commit
f460860e10
3 changed files with 65 additions and 10 deletions
26
wayland.c
26
wayland.c
|
|
@ -20,6 +20,7 @@
|
|||
#include "zwp-text-input-unstable-v3-protocol.h"
|
||||
// common headers for platform layer and application layer
|
||||
#include "input.h"
|
||||
#include "arena.h"
|
||||
|
||||
struct wl_compositor *compositor = NULL;
|
||||
struct wl_registry *registry = NULL;
|
||||
|
|
@ -48,6 +49,7 @@ struct xkb_keymap *xkb_keymap = NULL;
|
|||
EGLBoolean errcode = 0;
|
||||
bool running = true;
|
||||
input_t user_input = {};
|
||||
arena_t main_arena = {};
|
||||
|
||||
char *egl_s(int code)
|
||||
{
|
||||
|
|
@ -192,7 +194,7 @@ void keymap_callback(void *data, struct wl_keyboard *kb, uint format, int fd, ui
|
|||
xkb_keymap = xkb_keymap_new_from_string(xkb_context, mem, XKB_KEYMAP_FORMAT_TEXT_V1, XKB_KEYMAP_COMPILE_NO_FLAGS);
|
||||
munmap(mem, size);
|
||||
close(fd);
|
||||
|
||||
|
||||
if (!(xkb_state = xkb_state_new(xkb_keymap)))
|
||||
fprintf(stderr, "Could not initialize XKB state machine\n");
|
||||
}
|
||||
|
|
@ -205,9 +207,9 @@ void enter_callback(void *data, struct wl_keyboard* kb, uint serial, struct wl_s
|
|||
// NOTE: wl_array is a dynamic array as specified in wayland-util.h
|
||||
int32_t *pos = arr->data;
|
||||
// wl_keyboard is giving us all the currenly pressed keys anyways
|
||||
for (int i = 0; i < KEYBOARD_KEY_TOTAL)
|
||||
for (int i = 0; i < KEYBOARD_KEY_TOTAL; ++i)
|
||||
user_input.keys[i] = KEY_STATE_UNPRESSED;
|
||||
|
||||
|
||||
wl_array_for_each(pos, arr) {
|
||||
xkb_keysym_t sym = xkb_state_key_get_one_sym(xkb_state, (*pos) + 8);
|
||||
// TODO: Decide if we should also set KEY_STATE_HELD
|
||||
|
|
@ -351,6 +353,11 @@ void pointer_axis_relative_direction_callback(void *data, struct wl_pointer *poi
|
|||
int main()
|
||||
{
|
||||
fprintf(stdout, "Starting platform layer...\n");
|
||||
main_arena = arena_create(1*GB);
|
||||
if (!main_arena.begin)
|
||||
fprintf(stderr, "Could not reserve memory for main arena!\n");
|
||||
|
||||
|
||||
struct wl_display *display = wl_display_connect(NULL);
|
||||
if (!display)
|
||||
{
|
||||
|
|
@ -387,11 +394,11 @@ int main()
|
|||
.configure = xdg_toplevel_configure,
|
||||
.close = xdg_toplevel_close
|
||||
};
|
||||
|
||||
|
||||
const struct xdg_wm_base_listener xdg_wm_base_listener = {
|
||||
.ping = wayland_ping
|
||||
};
|
||||
|
||||
|
||||
if (xdg_toplevel_add_listener(xdg_toplevel, &xdg_toplevel_listener, NULL))
|
||||
fprintf(stderr, "Could not set XDG toplevel listener\n");
|
||||
if (xdg_wm_base_add_listener(wm_base, &xdg_wm_base_listener, NULL))
|
||||
|
|
@ -403,7 +410,7 @@ int main()
|
|||
}
|
||||
if (!(wl_pointer = wl_seat_get_pointer(wl_seat)))
|
||||
fprintf(stderr, "Could not get WL pointer\n");
|
||||
|
||||
|
||||
if (!zwp_text_input_manager_v3)
|
||||
fprintf(stderr, "Could not get ZWP text input manager\n");
|
||||
else if (!(zwp_text_input_v3 = zwp_text_input_manager_v3_get_text_input(zwp_text_input_manager_v3, wl_seat)))
|
||||
|
|
@ -417,7 +424,7 @@ int main()
|
|||
.delete_surrounding_text = zwp_text_input_v3_delete_surrounding_text_callback,
|
||||
.done = zwp_text_input_v3_done_callback
|
||||
};
|
||||
|
||||
|
||||
if (zwp_text_input_v3_add_listener(zwp_text_input_v3, &zwp_text_input_v3_listener, NULL))
|
||||
fprintf(stderr, "Could not add ZWP text input callback\n");
|
||||
|
||||
|
|
@ -440,7 +447,7 @@ int main()
|
|||
};
|
||||
if (wl_keyboard_add_listener(wl_keyboard, &wl_keyboard_listener, NULL))
|
||||
fprintf(stderr, "Could not set XKB keyboard listener\n");
|
||||
|
||||
|
||||
/* NOTE: Apparently wl_pointer added 'axis_value120' with v8 and 'axis_relative_direction' events with v9.
|
||||
Failing to provide callbacks for them crashes the client in runtime */
|
||||
const struct wl_pointer_listener wl_pointer_listener = {
|
||||
|
|
@ -478,7 +485,8 @@ int main()
|
|||
if (errcode != EGL_TRUE)
|
||||
fprintf(stderr, "ERR %s: Could not retrieve EGL config number\n", egl_s(errcode));
|
||||
|
||||
EGLConfig *configs = calloc(config_count, sizeof(EGLConfig));
|
||||
//EGLConfig *configs = calloc(config_count, sizeof(EGLConfig));
|
||||
EGLConfig *configs = arena_reserve(&main_arena, EGLConfig, config_count, ARENA_ZERO);
|
||||
|
||||
EGLint attr_list[] = {
|
||||
EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue