aboutsummaryrefslogtreecommitdiff
path: root/src/tsar.c
blob: 426ad358d45b5d26b1442c45aa48afe0919f25a7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#include <stdarg.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

#include <xcb/xcb.h>
// #include <X11/Xft/Xft.h>

#include "pipe.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_pipe();
  while (1) {
    await_change();
  }
  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;
}