事件适配器适配 XCB_MAPPING_NOTIFY 和 XCB_BUTTON_PRESS 事件

This commit is contained in:
2025-09-30 21:40:12 +08:00
parent 0626a4c512
commit 6d9ff81f78
2 changed files with 31 additions and 7 deletions

View File

@@ -40,8 +40,15 @@ typedef enum notify_detail_t {
notify_detail_none = 7, notify_detail_none = 7,
} notify_detail_t; } notify_detail_t;
typedef enum mapping_t {
MAPPING_MODIFIER = 0,
MAPPING_KEYBOARD = 1,
MAPPING_POINTER = 2
} mapping_t;
typedef struct mapping_notify_event_t { typedef struct mapping_notify_event_t {
event_type_t type; event_type_t type;
mapping_t request;
} mapping_notify_event_t; } mapping_notify_event_t;
typedef struct key_press_event_t { typedef struct key_press_event_t {
@@ -52,6 +59,10 @@ typedef struct key_press_event_t {
typedef struct button_press_event_t { typedef struct button_press_event_t {
event_type_t type; event_type_t type;
xcb_window_t window;
xcb_window_t root;
int32_t x, y, root_x, root_y;
uint32_t time; /* 时间戳单位ms */
} button_press_event_t; } button_press_event_t;
typedef struct configure_request_event_t { typedef struct configure_request_event_t {

View File

@@ -18,11 +18,13 @@ struct event_adapter_t {
static void convert_event(xcb_generic_event_t *xcb_event, static void convert_event(xcb_generic_event_t *xcb_event,
generic_event_t *event) { generic_event_t *event) {
uint8_t event_type = XCB_EVENT_RESPONSE_TYPE(xcb_event); uint8_t event_type = XCB_EVENT_RESPONSE_TYPE(xcb_event);
const char *label = xcb_event_get_label(event_type);
switch (event_type) { switch (event_type) {
case XCB_MAPPING_NOTIFY: case XCB_MAPPING_NOTIFY: {
event->type = EVENT_TYPE_MAPPING_NOTIFY; xcb_mapping_notify_event_t *ev = (xcb_mapping_notify_event_t *)xcb_event;
event->mapping_notify.type = EVENT_TYPE_MAPPING_NOTIFY;
event->mapping_notify.request = ev->request;
break; break;
}
case XCB_KEY_PRESS: { case XCB_KEY_PRESS: {
xcb_key_press_event_t *ev = (xcb_key_press_event_t *)xcb_event; xcb_key_press_event_t *ev = (xcb_key_press_event_t *)xcb_event;
int col = ev->state & XCB_MOD_MASK_2 ? 1 : 0; int col = ev->state & XCB_MOD_MASK_2 ? 1 : 0;
@@ -32,9 +34,18 @@ static void convert_event(xcb_generic_event_t *xcb_event,
event->key_press.modifiers = ev->state; event->key_press.modifiers = ev->state;
break; break;
} }
case XCB_BUTTON_PRESS: case XCB_BUTTON_PRESS: {
event->type = EVENT_TYPE_BUTTON_PRESS; xcb_button_press_event_t *ev = (xcb_button_press_event_t *)xcb_event;
event->button_press.type = EVENT_TYPE_BUTTON_PRESS;
event->button_press.window = ev->event;
event->button_press.root = ev->root;
event->button_press.x = ev->event_x;
event->button_press.y = ev->event_y;
event->button_press.root_x = ev->root_x;
event->button_press.root_y = ev->root_y;
event->button_press.time = ev->time;
break; break;
}
case XCB_CONFIGURE_REQUEST: { case XCB_CONFIGURE_REQUEST: {
xcb_configure_request_event_t *ev = xcb_configure_request_event_t *ev =
(xcb_configure_request_event_t *)xcb_event; (xcb_configure_request_event_t *)xcb_event;
@@ -66,7 +77,8 @@ static void convert_event(xcb_generic_event_t *xcb_event,
event->unmap_notify.type = EVENT_TYPE_UNMAP_NOTIFY; event->unmap_notify.type = EVENT_TYPE_UNMAP_NOTIFY;
event->unmap_notify.window = ev->window; event->unmap_notify.window = ev->window;
event->unmap_notify.send_event = XCB_EVENT_SENT(ev); event->unmap_notify.send_event = XCB_EVENT_SENT(ev);
} break; break;
}
case XCB_DESTROY_NOTIFY: { case XCB_DESTROY_NOTIFY: {
xcb_destroy_notify_event_t *ev = (xcb_destroy_notify_event_t *)xcb_event; xcb_destroy_notify_event_t *ev = (xcb_destroy_notify_event_t *)xcb_event;
event->destroy_notify.type = EVENT_TYPE_DESTROY_NOTIFY; event->destroy_notify.type = EVENT_TYPE_DESTROY_NOTIFY;
@@ -127,7 +139,8 @@ static void convert_event(xcb_generic_event_t *xcb_event,
event->type = -1; event->type = -1;
return; return;
} }
if (event->type != EVENT_TYPE_MOTION_NOTIFY) { if (event->type) {
const char *label = xcb_event_get_label(event_type);
logger("========================== %s ==========================\n", label); logger("========================== %s ==========================\n", label);
} }
} }