keep xkb progress

This commit is contained in:
2025-11-22 22:59:15 +08:00
parent edda316709
commit 88bf451cd4
4 changed files with 57 additions and 0 deletions

View File

@@ -32,6 +32,7 @@ add_executable(${APP_NAME}
xwindow.c xwindow.c
event.c event.c
action.c action.c
xkb.c
) )
# use C23 # use C23
@@ -50,6 +51,8 @@ pkg_check_modules(deps REQUIRED
xcb-randr xcb-randr
xcb-xfixes xcb-xfixes
xcb-xinerama xcb-xinerama
xcb-xkb
xkbcommon-x11
cairo cairo
cairo-xcb cairo-xcb

View File

@@ -2,6 +2,7 @@
#include <stdint.h> #include <stdint.h>
#include <xcb/xcb_keysyms.h> #include <xcb/xcb_keysyms.h>
#include <xkbcommon/xkbcommon.h>
#include "types.h" #include "types.h"
@@ -25,6 +26,10 @@ typedef struct wm_t {
bool have_xfixes; bool have_xfixes;
bool have_xinerama; bool have_xinerama;
bool have_randr; bool have_randr;
bool have_xkb;
struct xkb_context *xkb_ctx;
struct xkb_state *xkb_state;
color_set_t color_set; color_set_t color_set;
} wm_t; } wm_t;

45
src/xkb.c Normal file
View File

@@ -0,0 +1,45 @@
#include "xkb.h"
#include <xcb/xcb.h>
#include <xcb/xkb.h>
#include <xkbcommon/xkbcommon-x11.h>
#include <xkbcommon/xkbcommon.h>
#include "utils.h"
#include "wm.h"
static void xkb_fill_state(void) {}
static void xkb_init_keymap(void) {
wm.xkb_ctx = xkb_context_new(XKB_CONTEXT_NO_FLAGS);
if (!wm.xkb_ctx) fatal("Cannot get XKB context");
xkb_fill_state();
}
static void xkb_free_keymap(void) {
xkb_state_unref(wm.xkb_state);
xkb_context_unref(wm.xkb_ctx);
}
void xkb_init(void) {
wm.have_xkb = xkb_x11_setup_xkb_extension(
wm.xcb_conn, XKB_X11_MIN_MAJOR_XKB_VERSION, XKB_X11_MIN_MINOR_XKB_VERSION,
XKB_X11_SETUP_XKB_EXTENSION_NO_FLAGS, nullptr, nullptr, nullptr, nullptr);
if (!wm.have_xkb) {
warn("XKB not found or not supported");
xkb_init_keymap();
return;
}
xcb_discard_reply(wm.xcb_conn,
xcb_xkb_per_client_flags(
wm.xcb_conn, XCB_XKB_ID_USE_CORE_KBD,
XCB_XKB_PER_CLIENT_FLAG_DETECTABLE_AUTO_REPEAT,
XCB_XKB_PER_CLIENT_FLAG_DETECTABLE_AUTO_REPEAT, 0, 0, 0)
.sequence);
xkb_init_keymap();
}
void xkb_free(void) { xkb_free_keymap(); }

4
src/xkb.h Normal file
View File

@@ -0,0 +1,4 @@
#pragma once
void xkb_init(void);
void xkb_free(void);