Skip to content

Instantly share code, notes, and snippets.

@psychon
Created March 15, 2015 11:14
Show Gist options
  • Save psychon/1405fbc8dd19efe92ae0 to your computer and use it in GitHub Desktop.
Save psychon/1405fbc8dd19efe92ae0 to your computer and use it in GitHub Desktop.
A quick hack to test alpha values for XCB_CW_BORDER_PIXEL and XCB_CW_BACK_PIXEL
#include <xcb/xcb.h>
#include <stdio.h>
#include <stdlib.h>
static void die(const char *msg)
{
fputs(msg, stderr);
exit(1);
}
static xcb_visualtype_t *draw_argb_visual(const xcb_screen_t *s)
{
xcb_depth_iterator_t depth_iter = xcb_screen_allowed_depths_iterator(s);
xcb_visualtype_iterator_t visual_iter;
if(depth_iter.data)
for(; depth_iter.rem; xcb_depth_next (&depth_iter))
if(depth_iter.data->depth == 32)
for(visual_iter = xcb_depth_visuals_iterator(depth_iter.data);
visual_iter.rem; xcb_visualtype_next (&visual_iter))
return visual_iter.data;
return NULL;
}
static xcb_window_t create_window(xcb_connection_t *c, xcb_screen_t *s)
{
xcb_window_t win;
xcb_visualtype_t *visual = draw_argb_visual(s);
xcb_colormap_t cmap;
if (!visual)
return XCB_NONE;
cmap = xcb_generate_id(c);
win = xcb_generate_id(c);
xcb_create_colormap(c, XCB_COLORMAP_ALLOC_NONE, cmap, s->root, visual->visual_id);
xcb_create_window(c, 32, win, s->root, 10, 10, 50, 50, 5, XCB_WINDOW_CLASS_INPUT_OUTPUT,
visual->visual_id,
XCB_CW_BACK_PIXEL | XCB_CW_BORDER_PIXEL | XCB_CW_OVERRIDE_REDIRECT | XCB_CW_EVENT_MASK | XCB_CW_COLORMAP,
(const uint32_t [])
{
0xaaaaaaaa,
0x88888888,
1,
XCB_EVENT_MASK_BUTTON_PRESS,
cmap
});
xcb_free_colormap(c, cmap);
return win;
}
static void event_loop(xcb_connection_t *c)
{
xcb_generic_event_t *event;
int done = 0;
while (!done && (event = xcb_wait_for_event(c)) != NULL) {
printf("Got event %d\n", event->response_type);
if (event->response_type == XCB_BUTTON_PRESS) {
puts("existing");
done = 1;
}
free(event);
xcb_flush(c);
}
}
int main()
{
const xcb_setup_t *setup;
xcb_window_t win;
xcb_connection_t *c;
xcb_screen_t *s;
c = xcb_connect(NULL, NULL);
setup = xcb_get_setup(c);
if (xcb_connection_has_error(c) || !setup)
die("Could not connect");
s = xcb_setup_roots_iterator(setup).data;
win = create_window(c, s);
if (!win)
die("could not create window");
xcb_map_window(c, win);
xcb_flush(c);
event_loop(c);
if (xcb_connection_has_error(c))
die("Connection has error?!");
xcb_disconnect(c);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment