summaryrefslogtreecommitdiff
path: root/src/scapx.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/scapx.c')
-rw-r--r--src/scapx.c89
1 files changed, 89 insertions, 0 deletions
diff --git a/src/scapx.c b/src/scapx.c
new file mode 100644
index 0000000..09b597e
--- /dev/null
+++ b/src/scapx.c
@@ -0,0 +1,89 @@
+// std
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+// local
+#include "scapx.h"
+#include "defs.h"
+
+// TODO: move this all to x.c
+
+static Server_context_t *init_XCB_server();
+static xcb_window_t create_win(Server_context_t *info);
+
+static Server_context_t *init_XCB_server()
+{
+ Server_context_t *info;
+
+ if (!(info = malloc(sizeof(Server_context_t)))) {
+ fprintf(stderr, "memory allocation failed.\n");
+ return NULL;
+ }
+
+ info->con = xcb_connect(NULL, &info->scr_nbr);
+ if (xcb_connection_has_error(info->con) > 0) {
+ fprintf(stderr, "Error opening display.\n");
+ free(info);
+ return NULL;
+ }
+
+ info->iter = xcb_setup_roots_iterator(xcb_get_setup(info->con));
+ for (; info->iter.rem; --info->scr_nbr, xcb_screen_next(&info->iter))
+ if (info->scr_nbr == 0) {
+ info->scr = info->iter.data;
+ break;
+ }
+
+ return info;
+}
+
+static xcb_window_t create_win(Server_context_t *info)
+{
+ xcb_gcontext_t gc;
+ xcb_window_t win;
+ u32 vmask, vlist[2];
+
+ // create gc
+ win = info->scr->root;
+ gc = xcb_generate_id(info->con);
+ vmask = XCB_GC_FOREGROUND | XCB_GC_GRAPHICS_EXPOSURES;
+ vlist[0] = info->scr->black_pixel;
+ vlist[1] = 0;
+ xcb_create_gc (info->con, gc, win, vmask, vlist);
+
+ // create window
+ win = xcb_generate_id(info->con);
+ vmask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
+ vlist[0] = info->scr->white_pixel;
+ vlist[1] = XCB_EVENT_MASK_EXPOSURE;
+
+ xcb_create_window(info->con,
+ XCB_COPY_FROM_PARENT,
+ win,
+ info->scr->root,
+ 0, 0,
+ 150, 150,
+ 10,
+ XCB_WINDOW_CLASS_INPUT_OUTPUT,
+ info->scr->root_visual,
+ vmask, vlist
+ );
+ xcb_map_window(info->con, win);
+ xcb_flush(info->con);
+
+ return win;
+}
+
+int main(int argc, char **argv)
+{
+ // TODO: Parse flags
+
+ Server_context_t *serv_context = init_XCB_server();
+ xcb_drawable_t win = create_win(serv_context);
+ pause();
+
+ xcb_disconnect(serv_context->con);
+ free(serv_context);
+ return 0;
+}