aboutsummaryrefslogtreecommitdiff
path: root/src/tsar.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/tsar.c')
-rw-r--r--src/tsar.c118
1 files changed, 118 insertions, 0 deletions
diff --git a/src/tsar.c b/src/tsar.c
new file mode 100644
index 0000000..67b9e07
--- /dev/null
+++ b/src/tsar.c
@@ -0,0 +1,118 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <stdbool.h>
+#include <stdarg.h>
+#include <string.h>
+
+#include <xcb/xcb.h>
+// #include <X11/Xft/Xft.h>
+
+xcb_connection_t* connection;
+xcb_screen_t* screen;
+xcb_window_t win;
+xcb_gc_t rect_gc;
+xcb_gc_t text_gc;
+
+static int height = 16;
+static float width = 1;
+
+static int err_code = 1;
+
+void die(const char* fmt, ...) {
+ va_list args;
+ va_start(args, fmt);
+ vfprintf(stderr, fmt, args);
+ va_end(args);
+
+ putc('\n', stderr);
+
+ exit(err_code);
+}
+
+void draw_bar(void) {
+}
+
+void init(void) {
+ connection = xcb_connect(NULL, NULL);
+ screen = xcb_setup_roots_iterator(
+ xcb_get_setup(connection)
+ ).data;
+ win = xcb_generate_id(connection);
+
+ xcb_create_window(
+ connection,
+ XCB_COPY_FROM_PARENT,
+ win,
+ screen->root,
+ 0, 0,
+ 100, height,
+ 0,
+ XCB_WINDOW_CLASS_INPUT_OUTPUT,
+ screen->root_visual,
+ XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK,
+ (uint32_t[]){0x000000, XCB_EVENT_MASK_EXPOSURE}
+ );
+
+ xcb_font_t font = xcb_generate_id(connection);
+ const char font_name[] = "commit";
+ xcb_open_font(
+ connection,
+ font,
+ strlen(font_name),
+ font_name
+ );
+
+ text_gc = xcb_generate_id(connection);
+ xcb_create_gc(
+ connection,
+ text_gc,
+ win,
+ XCB_GC_FOREGROUND | XCB_GC_BACKGROUND | XCB_GC_FONT,
+ (uint32_t[]){0x000000, 0xFFFFFF, font}
+ );
+
+ xcb_close_font(connection, font);
+
+ rect_gc = xcb_generate_id(connection);
+ xcb_create_gc(
+ connection,
+ rect_gc,
+ win,
+ XCB_GC_FOREGROUND | XCB_GC_GRAPHICS_EXPOSURES,
+ (uint32_t[]){0xFF0000, 0}
+ );
+
+ xcb_map_window(connection, win);
+ xcb_flush(connection);
+}
+
+void deinit(void) {
+ xcb_disconnect(connection);
+}
+
+int main(void) {
+ init();
+
+ xcb_generic_event_t* ev;
+ while ((ev = xcb_wait_for_event(connection))) {
+ switch (ev->response_type & ~0x80) {
+ case XCB_EXPOSE: {
+ xcb_rectangle_t rect = {10, 50, 200, 200};
+ xcb_poly_rectangle(connection, win, rect_gc, 1, &rect);
+
+
+ const char text[] = "hello, world!";
+ xcb_image_text_8(connection, strlen(text), win, text_gc, 50, 50, text);
+
+ xcb_flush(connection);
+ break;
+ }
+ }
+
+ free(ev);
+ }
+
+ deinit();
+ return 0;
+}