Add keyboard listener and listen to escape to quit hyprpicker (#20)

* Add keyboard listener and listen to escape for quit
This commit is contained in:
TheSunCat 2023-01-02 19:32:11 +01:00 committed by GitHub
parent aa3c2acd59
commit 422b36c125
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 39 additions and 1 deletions

View file

@ -78,6 +78,10 @@ void Events::handleCapabilities(void *data, wl_seat *wl_seat, uint32_t capabilit
Debug::log(CRIT, "Hyprpicker cannot work without a pointer!");
g_pHyprpicker->finish(1);
}
if (capabilities & WL_SEAT_CAPABILITY_KEYBOARD) {
wl_keyboard_add_listener(wl_seat_get_keyboard(wl_seat), &keyboardListener, wl_seat);
}
}
void Events::handlePointerEnter(void *data, struct wl_pointer *wl_pointer, uint32_t serial, struct wl_surface *surface, wl_fixed_t surface_x, wl_fixed_t surface_y) {
@ -256,6 +260,28 @@ void Events::handlePointerButton(void *data, struct wl_pointer *wl_pointer, uint
g_pHyprpicker->finish();
}
void Events::handleKeyboardKeymap(void* data, wl_keyboard* wl_keyboard, uint format, int fd, uint size) {
}
void Events::handleKeyboardKey(void *data, struct wl_keyboard *keyboard, uint32_t serial, uint32_t time, uint32_t key, uint32_t state) {
if (key == 1) // escape
g_pHyprpicker->finish();
}
void Events::handleKeyboardEnter(void* data, wl_keyboard* wl_keyboard, uint serial, wl_surface* surface, wl_array* keys) {
}
void Events::handleKeyboardLeave(void* data, wl_keyboard* wl_keyboard, uint serial, wl_surface* surface) {
}
void Events::handleKeyboardModifiers(void* data, wl_keyboard* wl_keyboard, uint serial, uint mods_depressed, uint mods_latched, uint mods_locked, uint group) {
}
void Events::handleFrameDone(void *data, struct wl_callback *callback, uint32_t time) {
CLayerSurface* pLS = (CLayerSurface*)data;

View file

@ -33,6 +33,16 @@ namespace Events {
void handlePointerLeave(void *data, struct wl_pointer *wl_pointer, uint32_t serial, struct wl_surface *surface);
void handleKeyboardKeymap(void* data, wl_keyboard* wl_keyboard, uint format, int fd, uint size);
void handleKeyboardKey(void *data, struct wl_keyboard *keyboard, uint32_t serial, uint32_t time, uint32_t key, uint32_t state);
void handleKeyboardEnter(void* data, wl_keyboard* wl_keyboard, uint serial, wl_surface* surface, wl_array* keys);
void handleKeyboardLeave(void* data, wl_keyboard* wl_keyboard, uint serial, wl_surface* surface);
void handleKeyboardModifiers(void* data, wl_keyboard* wl_keyboard, uint serial, uint mods_depressed, uint mods_latched, uint mods_locked, uint group);
void handleFrameDone(void *data, struct wl_callback *callback, uint32_t time);
void handleBufferRelease(void *data, struct wl_buffer *wl_buffer);
@ -55,6 +65,8 @@ namespace Events {
inline const wl_pointer_listener pointerListener = { .enter = handlePointerEnter, .leave = handlePointerLeave, .motion = handlePointerMotion, .button = handlePointerButton, .axis = handlePointerAxis };
inline const wl_keyboard_listener keyboardListener = { .keymap = handleKeyboardKeymap, .enter = handleKeyboardEnter,.leave = handleKeyboardLeave, .key = handleKeyboardKey, .modifiers = handleKeyboardModifiers };
inline const wl_callback_listener frameListener = { .done = handleFrameDone };
inline const wl_buffer_listener bufferListener = { .release = handleBufferRelease };