*drive-thru whale plays a tune, water in its blowhole moves up and down*

This commit is contained in:
XANTRONIX Development 2019-05-27 23:05:25 -05:00
parent c54a59da72
commit 853ba89db0
3 changed files with 67 additions and 13 deletions

View file

@ -3,6 +3,8 @@
#include <X11/Xlib.h> #include <X11/Xlib.h>
#include <cairo.h>
#define HEXAGRAM_WINDOW_EVENT_MASK (ButtonMotionMask | ButtonPressMask | \ #define HEXAGRAM_WINDOW_EVENT_MASK (ButtonMotionMask | ButtonPressMask | \
ButtonReleaseMask | ExposureMask | \ ButtonReleaseMask | ExposureMask | \
StructureNotifyMask) StructureNotifyMask)
@ -16,10 +18,14 @@ hexagram_window *hexagram_window_new_x11(const char *display,
unsigned int width, unsigned int width,
unsigned int height); unsigned int height);
void hexagram_window_destroy(hexagram_window *window);
int hexagram_window_get_display_fd(hexagram_window *window); int hexagram_window_get_display_fd(hexagram_window *window);
int hexagram_window_show(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 */ #endif /* _HEXAGRAM_WINDOW_H */

View file

@ -4,8 +4,8 @@ INCLUDE_PATH = ../include
HEADER_SUBDIR = hexagram HEADER_SUBDIR = hexagram
CC = $(CROSS)cc CC = $(CROSS)cc
CFLAGS += -fPIC -I$(INCLUDE_PATH) CFLAGS += -fPIC -I$(INCLUDE_PATH) $(shell pkg-config --cflags cairo x11)
LDFLAGS = 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 = dict.h hash.h can.h capture.h pcapng.h module.h window.h sim.h
HEADERS_LOCAL = util.h HEADERS_LOCAL = util.h

View file

@ -2,6 +2,7 @@
#include <X11/Xlib.h> #include <X11/Xlib.h>
#include <X11/extensions/Xdbe.h> #include <X11/extensions/Xdbe.h>
#include <cairo-xlib.h>
#include <hexagram/window.h> #include <hexagram/window.h>
@ -25,6 +26,9 @@ struct _hexagram_window {
XdbeBackBuffer buf; XdbeBackBuffer buf;
XdbeSwapInfo swapinfo; XdbeSwapInfo swapinfo;
cairo_surface_t *surface_bg,
*surface_fg;
}; };
hexagram_window *hexagram_window_new_x11(const char *display, 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; 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; 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: error_x_create_gc:
(void)XFreePixmap(window->display, window->bg); (void)XFreePixmap(window->display, window->bg);
@ -113,6 +149,22 @@ error_malloc_window:
return NULL; 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) { int hexagram_window_show(hexagram_window *window) {
if (XSelectInput(window->display, window->win, if (XSelectInput(window->display, window->win,
ExposureMask | ButtonPressMask | KeyPressMask) == 0) { ExposureMask | ButtonPressMask | KeyPressMask) == 0) {
@ -129,14 +181,10 @@ error_x:
return -1; return -1;
} }
void hexagram_window_destroy(hexagram_window *window) { cairo_t *hexagram_window_create_bg_context(hexagram_window *window) {
(void)XFreeGC(window->display, window->gc); return cairo_create(window->surface_bg);
(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_fg_context(hexagram_window *window) {
return cairo_create(window->surface_fg);
} }