feat: Initial usage of xkb.
This commit is contained in:
@@ -11,6 +11,8 @@
|
||||
|
||||
#include <xdg-shell.h>
|
||||
#include <wayland-client.h>
|
||||
#include <xkbcommon/xkbcommon.h>
|
||||
#include <xkbcommon/xkbcommon-keysyms.h>
|
||||
|
||||
#include <tkeyboard.h>
|
||||
#include <tpointer.h>
|
||||
@@ -142,6 +144,18 @@ const struct wl_buffer_listener wl_buffer_listener = {
|
||||
|
||||
void redraw(); // forward declaration
|
||||
|
||||
static void handle_key(uint32_t key, uint32_t state, xkb_keysym_t sym, void *user_data)
|
||||
{
|
||||
(void)key;
|
||||
(void)user_data;
|
||||
|
||||
if (state == WL_KEYBOARD_KEY_STATE_PRESSED && sym == XKB_KEY_Escape)
|
||||
{
|
||||
printf("Escape pressed, exiting.\n");
|
||||
running = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void wl_callack_done(void *data, struct wl_callback *callback, uint32_t time)
|
||||
{
|
||||
if (canvas.frame)
|
||||
@@ -187,6 +201,7 @@ int main(void)
|
||||
wl_surface_commit(canvas.surface);
|
||||
|
||||
keyboard_data.keyboard = wl_seat_get_keyboard(wl_seat);
|
||||
keyboard_set_handler(&keyboard_data, handle_key, NULL);
|
||||
wl_keyboard_add_listener(keyboard_data.keyboard, &keyboard_listener, &keyboard_data);
|
||||
|
||||
pointer_init_cursor(&pointer_data, compositor, shm);
|
||||
@@ -230,6 +245,19 @@ int main(void)
|
||||
xdg_surface_destroy(xdg_surface);
|
||||
wl_surface_destroy(canvas.surface);
|
||||
wl_shm_pool_destroy(pool);
|
||||
wl_keyboard_destroy(keyboard_data.keyboard);
|
||||
if (keyboard_data.xkb_state != NULL)
|
||||
{
|
||||
xkb_state_unref(keyboard_data.xkb_state);
|
||||
}
|
||||
if (keyboard_data.xkb_keymap != NULL)
|
||||
{
|
||||
xkb_keymap_unref(keyboard_data.xkb_keymap);
|
||||
}
|
||||
if (keyboard_data.xkb_context != NULL)
|
||||
{
|
||||
xkb_context_unref(keyboard_data.xkb_context);
|
||||
}
|
||||
wl_registry_destroy(registry);
|
||||
wl_display_disconnect(display);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user