diff options
| author | iamcheeseman <[hidden email]> | 2026-03-01 09:57:00 -0500 |
|---|---|---|
| committer | iamcheeseman <[hidden email]> | 2026-03-01 09:57:00 -0500 |
| commit | c5a9d10e55b15f128c7215d64bbd9e8161345e16 (patch) | |
| tree | 5764b2d0372cb1750c9910d7b0026b6f29050cfe | |
| parent | 41175c11234c0a2a83257beb86694f3af129a689 (diff) | |
Create bar window
| -rw-r--r-- | Makefile | 4 | ||||
| -rw-r--r-- | src/tsar.c | 118 |
2 files changed, 47 insertions, 75 deletions
@@ -1,6 +1,6 @@ CC=cc -CFLAGS+=-std=c99 -pedantic -Wall -Wextra -O2 -LDFLAGS+=-lX11 -lxcb +CFLAGS+=-std=c99 -pedantic -Wall -Wextra -O2 -I/usr/include/freetype2 +LDFLAGS+=-lX11 -lXft TSAR_OUT=tsarbar @@ -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(); |
