开启 xcb 事件循环

This commit is contained in:
2025-08-12 20:46:47 +08:00
parent 943d566cef
commit 43ca95d2f4
3 changed files with 43 additions and 0 deletions

View File

@@ -2,10 +2,12 @@
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <xcb/xcb.h>
#include <xcb/xcb_aux.h>
#include <xcb/xcb_event.h>
#include <xcb/xcb_ewmh.h>
#include <xcb/xcb_icccm.h>
#include <xcb/xcb_image.h>
@@ -47,6 +49,11 @@ bool has_other_wm_running(void) {
return false;
}
/**
* @brief 获取 xcb 链接对应的文件描述符
*/
int get_xcb_connection_fd(void) { return xcb_get_file_descriptor(conn); }
/* xinerama 扩展是否激活 */
static bool xinerama_active(void) {
const char *name = "XINERAMA";
@@ -263,6 +270,16 @@ void free_window_list(window_list_t *window_list) {
free(window_list);
}
void start_xcb_event_loop(void) {
xcb_generic_event_t *event = NULL;
while ((event = xcb_poll_for_event(conn)) != NULL) {
uint8_t event_type = XCB_EVENT_RESPONSE_TYPE(event);
const char *label = xcb_event_get_label(event_type);
printf("================== %s ==================\n", label);
free(event);
}
}
void clean_xcb(void) {
if (wm_check_window != XCB_NONE) {
xcb_destroy_window(conn, wm_check_window);