commit - 577714ad5aded98e7cf76260a1556660281292da
commit + 9ec8bc72c26d942a1a1338893604cc7d5719f1b7
blob - f9f45a5721bc59e0f599af975047dd0ab1bc1571
blob + ac2b77ea98854ffeded9adc10fba1b822bb4bd0e
--- bxbar.c
+++ bxbar.c
#include <unistd.h>
#include <err.h>
#include <errno.h>
+#include <locale.h>
#include <poll.h>
#include <signal.h>
#include <string.h>
static void cleanup(int status);
int main(void) {
+ setlocale(LC_CTYPE, "");
if (!(dpy = XOpenDisplay(NULL))) {
fprintf(stderr, "bxbar: cannot open display\n");
return 1;
return;
int y = (BAR_HEIGHT - (font->ascent + font->descent)) / 2 + font->ascent;
- int half_w = (screen_w / 2) - (PADDING * 2);
+ /* Measure inner gap: 2 spaces per side (4 total between sides) */
+ XGlyphInfo gap_ext;
+ XftTextExtents8(dpy, font, (FcChar8 *)" ", 2, &gap_ext);
+ int half_w = (screen_w / 2) - PADDING - gap_ext.width;
XGlyphInfo ext;
/* Find delimiter for left/right split */
while (*right == ' ')
right++;
+ logmsg("DEBUG: Left string is '%s', Right string is '%s'", left, right);
/* Left section — left-aligned */
int left_len = text_fit(left, strlen(left), half_w, &ext);
XftDrawStringUtf8(xft_draw, &color[0], font, PADDING, y,
blob - 49a72351d78295e0ec728fad37516674622b94c6
blob + 8fa6c143e0075ca003d757ad1ba6f17179818ac2
--- bxbarrc.lua
+++ bxbarrc.lua
#!/usr/bin/env lua5.4
--- bxbar-ctl
+-- bxbarrc.lua
-- Enforce Lua 5.4+
if not _VERSION:match("5.4") then
os.exit(1)
end
+local function find_battery_path()
+ local h = io.popen("ls /sys/class/power_supply/", "r")
+ if not h then return nil end
+ for entry in h:lines() do
+ local th = io.open("/sys/class/power_supply/" .. entry .. "/type", "r")
+ if th then
+ local dtype = th:read("*l")
+ th:close()
+ if dtype == "Battery" then
+ h:close()
+ return "/sys/class/power_supply/" .. entry
+ end
+ end
+ end
+ h:close()
+ return nil
+end
+
local function get_x11_info()
local h = io.popen("bxinfo", "r")
if not h then return "?", "" end
return ws_str, win_title
end
+local function get_battery(bat_path)
+ local h = io.open(bat_path .. "/capacity", "r")
+ local cap = h and h:read("*n") or 0
+ if h then h:close() end
+
+ h = io.open(bat_path .. "/status", "r")
+ local status = h and h:read("*l") or "Unknown"
+ if h then h:close() end
+
+-- local filled = math.floor(cap / 12.5)
+-- local bar = string.rep("|", filled) .. string.rep(" ", 8 - filled)
+ local filled = math.floor(cap / 25)
+ local bar = string.rep("|", filled) .. string.rep(" ", 4 - filled)
+ local charging = (status == "Charging") and "+" or ""
+
+ return "[" .. bar .. "] " .. cap .. "%" .. charging
+end
+
+-- Discover battery path once at startup
+local bat_path = find_battery_path()
+
+-- Main loop
while true do
local ws, title = get_x11_info()
- local dt = os.date("%Y-%m-%d %a %H:%M")
+ local dt = os.date("%Y-%m-%d %a %H:%M")
+ local bat = bat_path and get_battery(bat_path) or ""
- -- Left: workspaces + active title | Right: datetime (battery later)
- local left = ws .. " " .. title
- local right = dt
+ local left = ws .. " " .. title
+ local right = bat .. " " .. dt
- io.write(left .. " | " .. right .. "\n")
+ io.write(left .. string.char(1) .. right .. "\n")
io.flush()
os.execute("sleep 2")
end
blob - 66f877d5874f17deb59bbb405612c5cf59fc3bd4
blob + 4cbd713c3d6f0b24c25efc9122f76dcad8f751d8
--- config.def.h
+++ config.def.h
/*
* config.def.h for bxbar
*
- * A very basic X status bar, a.k.a. Brett's X bar.
+ * A very basic X status bar.
* See LICENSE.md and README.md for details.
*/
-#define BAR_HEIGHT 32
+#define BAR_HEIGHT 36
#define PADDING 4
#define BORDER_WIDTH 0 /* No borders initially */
#define BORDER_COLOR "#555555"
#define FG_COLOR "#ffffff"
#define BG_COLOR "#000000"
#define FONT "monospace:size=14"
-#define DELIMITER '|'
+#define DELIMITER '\x01'