mirror of
https://github.com/hyprwm/hyprpicker.git
synced 2024-12-22 14:19:48 +01:00
events: Use xkbcommon for keyboard event handling (#43)
This commit is contained in:
parent
7e1765f9f3
commit
94010d6b9a
6 changed files with 56 additions and 4 deletions
|
@ -41,7 +41,7 @@ add_compile_options(-Wall -Wextra -Wno-unused-parameter -Wno-unused-value -Wno-m
|
||||||
find_package(Threads REQUIRED)
|
find_package(Threads REQUIRED)
|
||||||
|
|
||||||
find_package(PkgConfig REQUIRED)
|
find_package(PkgConfig REQUIRED)
|
||||||
pkg_check_modules(deps REQUIRED IMPORTED_TARGET wayland-client wayland-protocols cairo pango pangocairo libjpeg)
|
pkg_check_modules(deps REQUIRED IMPORTED_TARGET wayland-client wayland-protocols xkbcommon cairo pango pangocairo libjpeg)
|
||||||
|
|
||||||
file(GLOB_RECURSE SRCFILES "src/*.cpp")
|
file(GLOB_RECURSE SRCFILES "src/*.cpp")
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
libselinux,
|
libselinux,
|
||||||
libsepol,
|
libsepol,
|
||||||
libthai,
|
libthai,
|
||||||
|
libxkbcommon,
|
||||||
pango,
|
pango,
|
||||||
pcre,
|
pcre,
|
||||||
utillinux,
|
utillinux,
|
||||||
|
@ -50,6 +51,7 @@ stdenv.mkDerivation {
|
||||||
wayland-scanner
|
wayland-scanner
|
||||||
wlroots
|
wlroots
|
||||||
libXdmcp
|
libXdmcp
|
||||||
|
libxkbcommon
|
||||||
utillinux
|
utillinux
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
|
@ -246,10 +246,46 @@ void Events::handlePointerButton(void* data, struct wl_pointer* wl_pointer, uint
|
||||||
g_pHyprpicker->finish();
|
g_pHyprpicker->finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Events::handleKeyboardKeymap(void* data, wl_keyboard* wl_keyboard, uint format, int fd, uint size) {}
|
void Events::handleKeyboardKeymap(void* data, wl_keyboard* wl_keyboard, uint format, int fd, uint size) {
|
||||||
|
if (!g_pHyprpicker->m_pXKBContext)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (format != WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1) {
|
||||||
|
Debug::log(ERR, "Could not recognise keymap format");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char* buf = (const char*)mmap(NULL, size, PROT_READ, MAP_SHARED, fd, 0);
|
||||||
|
if (buf == MAP_FAILED) {
|
||||||
|
Debug::log(ERR, "Failed to mmap xkb keymap: %d", errno);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
g_pHyprpicker->m_pXKBKeymap = xkb_keymap_new_from_buffer(g_pHyprpicker->m_pXKBContext, buf, size - 1, XKB_KEYMAP_FORMAT_TEXT_V1, XKB_KEYMAP_COMPILE_NO_FLAGS);
|
||||||
|
|
||||||
|
munmap((void*)buf, size);
|
||||||
|
close(fd);
|
||||||
|
|
||||||
|
if (!g_pHyprpicker->m_pXKBKeymap) {
|
||||||
|
Debug::log(ERR, "Failed to compile xkb keymap");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
g_pHyprpicker->m_pXKBState = xkb_state_new(g_pHyprpicker->m_pXKBKeymap);
|
||||||
|
if (!g_pHyprpicker->m_pXKBState) {
|
||||||
|
Debug::log(ERR, "Failed to create xkb state");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Events::handleKeyboardKey(void* data, struct wl_keyboard* keyboard, uint32_t serial, uint32_t time, uint32_t key, uint32_t state) {
|
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
|
if (state != WL_KEYBOARD_KEY_STATE_PRESSED)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (g_pHyprpicker->m_pXKBState) {
|
||||||
|
if (xkb_state_key_get_one_sym(g_pHyprpicker->m_pXKBState, key + 8) == XKB_KEY_Escape)
|
||||||
|
g_pHyprpicker->finish();
|
||||||
|
} else if (key == 1) // Assume keycode 1 is escape
|
||||||
g_pHyprpicker->finish();
|
g_pHyprpicker->finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -257,7 +293,12 @@ void Events::handleKeyboardEnter(void* data, wl_keyboard* wl_keyboard, uint seri
|
||||||
|
|
||||||
void Events::handleKeyboardLeave(void* data, wl_keyboard* wl_keyboard, uint serial, wl_surface* surface) {}
|
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::handleKeyboardModifiers(void* data, wl_keyboard* wl_keyboard, uint serial, uint mods_depressed, uint mods_latched, uint mods_locked, uint group) {
|
||||||
|
if (!g_pHyprpicker->m_pXKBState)
|
||||||
|
return;
|
||||||
|
|
||||||
|
xkb_state_update_mask(g_pHyprpicker->m_pXKBState, mods_depressed, mods_latched, mods_locked, 0, 0, group);
|
||||||
|
}
|
||||||
|
|
||||||
void Events::handleFrameDone(void* data, struct wl_callback* callback, uint32_t time) {
|
void Events::handleFrameDone(void* data, struct wl_callback* callback, uint32_t time) {
|
||||||
CLayerSurface* pLS = (CLayerSurface*)data;
|
CLayerSurface* pLS = (CLayerSurface*)data;
|
||||||
|
|
|
@ -8,6 +8,10 @@ void sigHandler(int sig) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void CHyprpicker::init() {
|
void CHyprpicker::init() {
|
||||||
|
m_pXKBContext = xkb_context_new(XKB_CONTEXT_NO_FLAGS);
|
||||||
|
if (!m_pXKBContext)
|
||||||
|
Debug::log(ERR, "Failed to create xkb context");
|
||||||
|
|
||||||
m_pWLDisplay = wl_display_connect(nullptr);
|
m_pWLDisplay = wl_display_connect(nullptr);
|
||||||
|
|
||||||
if (!m_pWLDisplay) {
|
if (!m_pWLDisplay) {
|
||||||
|
|
|
@ -26,6 +26,10 @@ class CHyprpicker {
|
||||||
zwlr_layer_shell_v1* m_pLayerShell;
|
zwlr_layer_shell_v1* m_pLayerShell;
|
||||||
zwlr_screencopy_manager_v1* m_pSCMgr;
|
zwlr_screencopy_manager_v1* m_pSCMgr;
|
||||||
|
|
||||||
|
xkb_context* m_pXKBContext = nullptr;
|
||||||
|
xkb_keymap* m_pXKBKeymap = nullptr;
|
||||||
|
xkb_state* m_pXKBState = nullptr;
|
||||||
|
|
||||||
eOutputMode m_bSelectedOutputMode = OUTPUT_HEX;
|
eOutputMode m_bSelectedOutputMode = OUTPUT_HEX;
|
||||||
|
|
||||||
bool m_bFancyOutput = true;
|
bool m_bFancyOutput = true;
|
||||||
|
|
|
@ -40,6 +40,7 @@ extern "C" {
|
||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <wayland-client.h>
|
#include <wayland-client.h>
|
||||||
|
#include <xkbcommon/xkbcommon.h>
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
|
|
Loading…
Reference in a new issue