diff --git a/include/hexagram/window.h b/include/hexagram/window.h index 5f67dde..c0572cb 100644 --- a/include/hexagram/window.h +++ b/include/hexagram/window.h @@ -3,6 +3,8 @@ #include +#include + #define HEXAGRAM_WINDOW_EVENT_MASK (ButtonMotionMask | ButtonPressMask | \ ButtonReleaseMask | ExposureMask | \ StructureNotifyMask) @@ -16,10 +18,14 @@ hexagram_window *hexagram_window_new_x11(const char *display, unsigned int width, unsigned int height); +void hexagram_window_destroy(hexagram_window *window); + int hexagram_window_get_display_fd(hexagram_window *window); int hexagram_window_show(hexagram_window *window); -void hexagram_window_destroy(hexagram_window *window); +cairo_t *hexagram_window_create_bg_context(hexagram_window *window); + +cairo_t *hexagram_window_create_fg_context(hexagram_window *window); #endif /* _HEXAGRAM_WINDOW_H */ diff --git a/src/Makefile b/src/Makefile index c47ca6b..16c6034 100644 --- a/src/Makefile +++ b/src/Makefile @@ -4,8 +4,8 @@ INCLUDE_PATH = ../include HEADER_SUBDIR = hexagram CC = $(CROSS)cc -CFLAGS += -fPIC -I$(INCLUDE_PATH) -LDFLAGS = +CFLAGS += -fPIC -I$(INCLUDE_PATH) $(shell pkg-config --cflags cairo x11) +LDFLAGS = $(shell pkg-config --libs cairo x11) -lXext HEADERS = dict.h hash.h can.h capture.h pcapng.h module.h window.h sim.h HEADERS_LOCAL = util.h diff --git a/src/window.c b/src/window.c index b578b3e..3dafa2c 100644 --- a/src/window.c +++ b/src/window.c @@ -2,6 +2,7 @@ #include #include +#include #include @@ -25,6 +26,9 @@ struct _hexagram_window { XdbeBackBuffer buf; XdbeSwapInfo swapinfo; + + cairo_surface_t *surface_bg, + *surface_fg; }; hexagram_window *hexagram_window_new_x11(const char *display, @@ -90,8 +94,40 @@ hexagram_window *hexagram_window_new_x11(const char *display, goto error_x_create_gc; } + if ((window->surface_bg = cairo_xlib_surface_create(window->display, + window->bg, + DefaultVisual(window->display, + window->screen), + width, + height)) == NULL) { + goto error_cairo_xlib_surface_create_bg; + } + + cairo_xlib_surface_set_size(window->surface_bg, + window->width, + window->height); + + if ((window->surface_fg = cairo_xlib_surface_create(window->display, + window->buf, + DefaultVisual(window->display, + window->screen), + width, + height)) == NULL) { + goto error_cairo_xlib_surface_create_fg; + } + + cairo_xlib_surface_set_size(window->surface_fg, + window->width, + window->height); + return window; +error_cairo_xlib_surface_create_fg: + cairo_surface_destroy(window->surface_bg); + +error_cairo_xlib_surface_create_bg: + (void)XFreeGC(window->display, window->gc); + error_x_create_gc: (void)XFreePixmap(window->display, window->bg); @@ -113,6 +149,22 @@ error_malloc_window: return NULL; } +void hexagram_window_destroy(hexagram_window *window) { + cairo_surface_destroy(window->surface_fg); + cairo_surface_destroy(window->surface_bg); + + (void)XFreeGC(window->display, window->gc); + + (void)XFreePixmap(window->display, window->bg); + + if (window->buf != window->win) { + (void)XdbeDeallocateBackBufferName(window->display, window->buf); + } + + (void)XUnmapWindow(window->display, window->win); + (void)XDestroyWindow(window->display, window->win); +} + int hexagram_window_show(hexagram_window *window) { if (XSelectInput(window->display, window->win, ExposureMask | ButtonPressMask | KeyPressMask) == 0) { @@ -129,14 +181,10 @@ error_x: return -1; } -void hexagram_window_destroy(hexagram_window *window) { - (void)XFreeGC(window->display, window->gc); - - (void)XFreePixmap(window->display, window->bg); - - if (window->buf != window->win) { - (void)XdbeDeallocateBackBufferName(window->display, window->buf); - } - - XUnmapWindow(window->display, window->win); +cairo_t *hexagram_window_create_bg_context(hexagram_window *window) { + return cairo_create(window->surface_bg); +} + +cairo_t *hexagram_window_create_fg_context(hexagram_window *window) { + return cairo_create(window->surface_fg); }