开启 xcb 事件循环
This commit is contained in:
24
src/main.c
24
src/main.c
@@ -20,6 +20,9 @@ static gboolean update_wallpaper(gpointer user_data);
|
||||
static void set_wallpaper_by_index(uint32_t index);
|
||||
static wallpaper_config_t *parse_wallpaper_config(const char **wallpapers);
|
||||
static void free_wallpaper_config(wallpaper_config_t *wallpaper_config);
|
||||
static void init_xcb_event_loop(void);
|
||||
static gboolean handle_xcb_event(GIOChannel *channel, GIOCondition condition,
|
||||
gpointer userdata);
|
||||
static void cleanup(void);
|
||||
|
||||
static monitor_t *monitors = NULL;
|
||||
@@ -163,6 +166,25 @@ void free_wallpaper_config(wallpaper_config_t *wallpaper_config) {
|
||||
free(wallpaper_config);
|
||||
}
|
||||
|
||||
void init_xcb_event_loop(void) {
|
||||
GIOChannel *channel = g_io_channel_unix_new(get_xcb_connection_fd());
|
||||
g_io_channel_set_encoding(channel, NULL, NULL);
|
||||
GIOCondition cond = G_IO_IN | G_IO_HUP | G_IO_ERR;
|
||||
g_io_add_watch(channel, cond, handle_xcb_event, NULL);
|
||||
g_io_channel_unref(channel);
|
||||
}
|
||||
|
||||
gboolean handle_xcb_event(GIOChannel *channel, GIOCondition condition,
|
||||
gpointer userdata) {
|
||||
if ((condition & G_IO_HUP) || (condition & G_IO_ERR)) {
|
||||
g_main_loop_quit(loop);
|
||||
return false;
|
||||
}
|
||||
|
||||
start_xcb_event_loop();
|
||||
return true;
|
||||
}
|
||||
|
||||
void cleanup(void) {
|
||||
clean_xcb();
|
||||
|
||||
@@ -200,6 +222,8 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
free_window_list(window_list);
|
||||
|
||||
init_xcb_event_loop();
|
||||
|
||||
loop = g_main_loop_new(NULL, FALSE);
|
||||
g_main_loop_run(loop);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user