aboutsummaryrefslogtreecommitdiff
path: root/src/tsar.c
diff options
context:
space:
mode:
authoriamcheeseman <[hidden email]>2026-03-01 09:57:00 -0500
committeriamcheeseman <[hidden email]>2026-03-01 09:57:00 -0500
commitc5a9d10e55b15f128c7215d64bbd9e8161345e16 (patch)
tree5764b2d0372cb1750c9910d7b0026b6f29050cfe /src/tsar.c
parent41175c11234c0a2a83257beb86694f3af129a689 (diff)
Create bar window
Diffstat (limited to 'src/tsar.c')
-rw-r--r--src/tsar.c118
1 files changed, 45 insertions, 73 deletions
diff --git a/src/tsar.c b/src/tsar.c
index 426ad35..d492e30 100644
--- a/src/tsar.c
+++ b/src/tsar.c
@@ -5,19 +5,18 @@
#include <string.h>
#include <unistd.h>
-#include <xcb/xcb.h>
-// #include <X11/Xft/Xft.h>
+#include <X11/Xft/Xft.h>
+#include <X11/Xlib.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;
+Display* display;
+Window win;
+GC gc;
-static int height = 16;
-static float width = 1;
+static int height = 17;
+static int width = 1000;
+static float width_ratio = 1;
static int err_code = 1;
@@ -36,87 +35,60 @@ 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);
+ display = XOpenDisplay(NULL);
+ if (display == NULL) {
+ die("could not open X display");
+ }
- 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}
- );
+ XSetWindowAttributes win_attr = {
+ .override_redirect = 1,
+ .background_pixel = 0x202020,
+ .event_mask = ExposureMask | PropertyChangeMask,
+ };
- xcb_font_t font = xcb_generate_id(connection);
- const char font_name[] = "commit";
- xcb_open_font(
- connection,
- font,
- strlen(font_name),
- font_name
- );
+ Screen* screen = DefaultScreenOfDisplay(display);
+ width = WidthOfScreen(screen);
- 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}
+ win = XCreateWindow(
+ display,
+ DefaultRootWindow(display),
+ 0, 0,
+ width, height,
+ 0,
+ CopyFromParent,
+ InputOutput,
+ CopyFromParent,
+ CWOverrideRedirect | CWBackPixel | CWEventMask,
+ &win_attr
);
- xcb_close_font(connection, font);
+ XMapRaised(display, win);
- rect_gc = xcb_generate_id(connection);
- xcb_create_gc(
- connection,
- rect_gc,
- win,
- XCB_GC_FOREGROUND | XCB_GC_GRAPHICS_EXPOSURES,
- (uint32_t[]){0xFF0000, 0}
- );
+ gc = XCreateGC(display, win, 0, NULL);
+ XSetForeground(display, gc, 0xFFFFFF);
- xcb_map_window(connection, win);
- xcb_flush(connection);
+ XFlush(display);
}
void deinit(void) {
- xcb_disconnect(connection);
+ XUnmapWindow(display, win);
+ XDestroyWindow(display, win);
}
int main(void) {
- init_pipe();
- while (1) {
- await_change();
- }
+ // init_pipe();
+ // while (true) {
+ // 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);
+ while (true) {
+ XEvent ev;
+ XNextEvent(display, &ev);
- xcb_flush(connection);
- break;
- }
- }
+ XDrawLine(display, win, gc, 0, 0, width, height);
- free(ev);
+ XFlush(display);
}
deinit();