From 7c21f1ad1663c340afe3c18bba02d13a626abce8 Mon Sep 17 00:00:00 2001 From: XANTRONIX Development Date: Tue, 28 May 2019 00:41:54 -0500 Subject: [PATCH] *The Cheat cries* --- examples/cluster.c | 56 ++++++++++------------------------------------ 1 file changed, 12 insertions(+), 44 deletions(-) diff --git a/examples/cluster.c b/examples/cluster.c index 2bc5d60..9097054 100644 --- a/examples/cluster.c +++ b/examples/cluster.c @@ -12,6 +12,7 @@ #include #include +#include static void draw_needle(cairo_t *cr, double x, @@ -228,69 +229,44 @@ static void update_gauge_cluster(cairo_t *cr, int main(int argc, char **argv) { Display *display; - Window win; Pixmap bg; - XdbeBackBuffer buf; - GC gc; fd_set rfds, rready; hexagram_can_if *can_if; + hexagram_window *window; int screen, fd, fd2, width = 1024, height = 480; - int major, minor; - - XGCValues values = { - .foreground = 0x000000, - .background = 0xffffff, - .graphics_exposures = 0 - }; - - XdbeSwapInfo swapinfo; - cairo_surface_t *sfc; cairo_t *cr; if ((can_if = hexagram_can_if_open("vcan0")) == NULL) exit(1); - if ((display = XOpenDisplay(NULL)) == NULL) + if ((window = hexagram_window_new_x11(NULL, width, height)) == NULL) exit(1); - if (XdbeQueryExtension(display, &major, &minor)) - printf("Xdbe %d.%d supported\n", major, minor); - else - exit(1); + display = window->display; + screen = window->screen; fd = hexagram_can_if_fd(can_if); - fd2 = ConnectionNumber(display); + fd2 = hexagram_window_display_fd(window); - screen = DefaultScreen(display); - - win = XCreateSimpleWindow(display, DefaultRootWindow(display), 0, 0, width, height, 0, 0, 0); - buf = XdbeAllocateBackBufferName(display, win, XdbeBackground); - - swapinfo.swap_window = win; - swapinfo.swap_action = XdbeBackground; - - gc = XCreateGC(display, win, GCForeground | GCBackground | GCGraphicsExposures, &values); - bg = XCreatePixmap(display, win, width, height, 24); + bg = window->bg; /* * Draw the background layer */ draw_gauge_cluster_bg(bg, display, screen, width, height); - printf("XSelectInput %d\n", XSelectInput(display, win, ExposureMask | ButtonPressMask | KeyPressMask)); - XMapWindow(display, win); + hexagram_window_show(window); /* * Set up the foreground surface */ - sfc = cairo_xlib_surface_create(display, buf, DefaultVisual(display, screen), width, height); - cairo_xlib_surface_set_size(sfc, width, height); + sfc = window->surface_fg; cr = cairo_create(sfc); @@ -314,13 +290,7 @@ int main(int argc, char **argv) { case Expose: fprintf(stderr, "Event %d\n", e.type); - XCopyArea(display, bg, win, gc, - e.xexpose.x, - e.xexpose.y, - e.xexpose.width, - e.xexpose.height, - e.xexpose.x, - e.xexpose.y); + hexagram_window_refresh_bg(window); break; @@ -345,13 +315,11 @@ int main(int argc, char **argv) { hexagram_can_if_read(can_if, &frame); if (frame.can_id == 0x280) { - XCopyArea(display, bg, buf, gc, 0, 0, - width, height, - 0, 0); + hexagram_window_refresh_bg(window); update_gauge_cluster(cr, &frame, 0, 0, width, height); - XdbeSwapBuffers(display, &swapinfo, 1); + hexagram_window_swap_buffer(window); } } }