aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/bardata.c58
-rw-r--r--src/bardata.h9
-rw-r--r--src/tsar.c6
-rw-r--r--src/tsar.h8
4 files changed, 69 insertions, 12 deletions
diff --git a/src/bardata.c b/src/bardata.c
index 507d8f9..19fedcc 100644
--- a/src/bardata.c
+++ b/src/bardata.c
@@ -8,8 +8,7 @@
#include "pipe.h"
#include "tsar.h"
-int fontsize = 16;
-color_t default_fg, default_bg;
+color_t default_fg = {.pixel=0xFFFFFF}, default_bg = {.pixel=0x202020};
int bar_height = 20;
// Global state, oh naur D:
@@ -89,6 +88,34 @@ void set_layout(char argv[MAX_ARGS][MAX_ARG_LEN], int argc) {
}
}
+color_t parse_color(const char* col_str) {
+ color_t col = {0};
+
+ if (col_str[0] == '#') {
+ col_str++;
+ }
+
+ col.pixel = strtol(col_str, NULL, 16);
+ col.color.red = (col.pixel >> 16) & 0xFF;
+ col.color.green = (col.pixel >> 8) & 0xFF;
+ col.color.blue = (col.pixel) & 0xFF;
+ col.color.alpha = 255;
+
+ printf(
+ "%lx %lx %lx %lx %d %d %d %d\n",
+ col.pixel,
+ col.pixel >> 16 & 0xFF,
+ col.pixel >> 8 & 0xFF,
+ col.pixel & 0xFF,
+ col.color.red,
+ col.color.green,
+ col.color.blue,
+ col.color.alpha
+ );
+
+ return col;
+}
+
void set_config(char argv[MAX_ARGS][MAX_ARG_LEN], int argc) {
char *var = argv[1];
if (strcmp(var, "height") == 0) {
@@ -100,13 +127,30 @@ void set_config(char argv[MAX_ARGS][MAX_ARG_LEN], int argc) {
bar_height = new_bar_height;
}
if (strcmp(var, "font") == 0) {
- // fontsize = atoi(argv[2]);
load_font(argv[2]);
}
- if (strcmp(var, "background") == 0) {
-
+ if (strcmp(var, "background") == 0 || strcmp(var, "bg") == 0) {
+ default_bg = parse_color(argv[2]);
+ XSetWindowAttributes win_attr = {
+ .background_pixel = default_bg.pixel,
+ };
+ XChangeWindowAttributes(display, win, CWBackPixel, &win_attr);
}
- if (strcmp(var, "foreground") == 0) {
-
+ if (strcmp(var, "foreground") == 0 || strcmp(var, "fg") == 0) {
+ default_fg = parse_color(argv[2]);
+ XftColorFree(
+ display,
+ DefaultVisual(display, DefaultScreen(display)),
+ DefaultColormap(display, DefaultScreen(display)),
+ &xft_fg_color
+ );
+
+ XftColorAllocName(
+ display,
+ DefaultVisual(display, DefaultScreen(display)),
+ DefaultColormap(display, DefaultScreen(display)),
+ argv[2],
+ &xft_fg_color
+ );
}
}
diff --git a/src/bardata.h b/src/bardata.h
index 874f7c6..426f736 100644
--- a/src/bardata.h
+++ b/src/bardata.h
@@ -1,9 +1,14 @@
#ifndef BAR_H
#define BAR_H
-#include "pipe.h"
+
#include <inttypes.h>
-typedef uint32_t color_t;
+#include <X11/Xft/Xft.h>
+
+#include "pipe.h"
+
+typedef XftColor color_t;
+
typedef enum {
SIDE_LEFT,
SIDE_CENTER,
diff --git a/src/tsar.c b/src/tsar.c
index 99fa8aa..b4eb199 100644
--- a/src/tsar.c
+++ b/src/tsar.c
@@ -17,7 +17,7 @@ Window win;
GC gc;
XftFont* font = NULL;
-XftColor fg_color;
+XftColor xft_fg_color;
static int bar_width = 1000;
static float width_ratio = 1;
@@ -91,7 +91,7 @@ void init_x(void) {
DefaultVisual(display, DefaultScreen(display)),
DefaultColormap(display, DefaultScreen(display)),
"#FFFFFF",
- &fg_color
+ &xft_fg_color
);
gc = XCreateGC(display, win, 0, NULL);
@@ -118,7 +118,7 @@ void draw_text(const char* text, int x, int y) {
);
int dy = y + (bar_height - font->height) / 2 + font->ascent;
- XftDrawString8(xft_draw, &fg_color, font, x, dy, (const FcChar8*)text, strlen(text));
+ XftDrawString8(xft_draw, &xft_fg_color, font, x, dy, (const FcChar8*)text, strlen(text));
XftDrawDestroy(xft_draw);
}
diff --git a/src/tsar.h b/src/tsar.h
index 1c9e60b..c91af4a 100644
--- a/src/tsar.h
+++ b/src/tsar.h
@@ -1,6 +1,14 @@
#ifndef TSAR_H
#define TSAR_H
+#include <X11/Xlib.h>
+#include <X11/Xft/Xft.h>
+
+extern Display* display;
+extern Window win;
+extern XftColor xft_fg_color;
+
void load_font(const char* font_name);
+XSetWindowAttributes get_window_attr(unsigned long color);
#endif