Handling Exposure-Events

This commit is contained in:
Axel Wagner 2010-07-26 23:51:51 +02:00
parent 0f4164dd0f
commit 3883ae2738
2 changed files with 43 additions and 1 deletions

View File

@ -2,7 +2,9 @@
#include <i3/ipc.h> #include <i3/ipc.h>
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
#include <stdlib.h>
#include <ev.h> #include <ev.h>
#include <xcb/xcb.h>
#include "ipc.h" #include "ipc.h"
#include "outputs.h" #include "outputs.h"
@ -10,6 +12,24 @@
#include "common.h" #include "common.h"
#include "xcb.h" #include "xcb.h"
void ev_prepare_cb(struct ev_loop *loop, ev_prepare *w, int revents) {
xcb_flush(xcb_connection);
}
void ev_check_cb(struct ev_loop *loop, ev_check *w, int revents) {
xcb_generic_event_t *event;
if ((event = xcb_poll_for_event(xcb_connection)) != NULL) {
switch (event->response_type & ~0x80) {
case XCB_EXPOSE:
draw_buttons();
}
free(event);
}
}
void xcb_io_cb(struct ev_loop *loop, ev_io *w, int revents) {
}
int main(int argc, char **argv) { int main(int argc, char **argv) {
main_loop = ev_default_loop(0); main_loop = ev_default_loop(0);
@ -18,11 +38,28 @@ int main(int argc, char **argv) {
subscribe_events(); subscribe_events();
ev_io *xcb_io = malloc(sizeof(ev_io));
ev_prepare *ev_prep = malloc(sizeof(ev_prepare));
ev_check *ev_chk = malloc(sizeof(ev_check));
ev_io_init(xcb_io, &xcb_io_cb, xcb_get_file_descriptor(xcb_connection), EV_READ);
ev_prepare_init(ev_prep, &ev_prepare_cb);
ev_check_init(ev_chk, &ev_check_cb);
ev_io_start(main_loop, xcb_io);
ev_prepare_start(main_loop, ev_prep);
ev_check_start(main_loop, ev_chk);
i3_send_msg(I3_IPC_MESSAGE_TYPE_GET_OUTPUTS, NULL); i3_send_msg(I3_IPC_MESSAGE_TYPE_GET_OUTPUTS, NULL);
i3_send_msg(I3_IPC_MESSAGE_TYPE_GET_WORKSPACES, NULL); i3_send_msg(I3_IPC_MESSAGE_TYPE_GET_WORKSPACES, NULL);
ev_loop(main_loop, 0); ev_loop(main_loop, 0);
ev_prepare_stop(main_loop, ev_prep);
ev_check_stop(main_loop, ev_chk);
FREE(ev_prep);
FREE(ev_chk);
ev_default_destroy(); ev_default_destroy();
clean_xcb(); clean_xcb();
free_outputs(); free_outputs();

View File

@ -19,6 +19,10 @@ uint32_t get_colorpixel(const char *s) {
return (r << 16 | g << 8 | b); return (r << 16 | g << 8 | b);
} }
void handle_xcb_event(xcb_generic_event_t ev) {
}
void init_xcb() { void init_xcb() {
/* FIXME: xcb_connect leaks Memory */ /* FIXME: xcb_connect leaks Memory */
xcb_connection = xcb_connect(NULL, NULL); xcb_connection = xcb_connect(NULL, NULL);
@ -77,8 +81,9 @@ void create_windows() {
printf("Creating Window for output %s\n", walk->name); printf("Creating Window for output %s\n", walk->name);
walk->bar = xcb_generate_id(xcb_connection); walk->bar = xcb_generate_id(xcb_connection);
mask = XCB_CW_BACK_PIXEL; mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
values[0] = xcb_screens->black_pixel; values[0] = xcb_screens->black_pixel;
values[1] = XCB_EVENT_MASK_EXPOSURE;
xcb_create_window(xcb_connection, xcb_create_window(xcb_connection,
xcb_screens->root_depth, xcb_screens->root_depth,
walk->bar, walk->bar,