foxygit / sxbar Log in
commit 13b64e9f216255210fe6289fbbb04509264d2a59
Author:     Abhinav <abhinav.prsai@gmail.com>
AuthorDate: Sun Jun 29 19:24:39 2025 +0100
Commit:     Abhinav <abhinav.prsai@gmail.com>
CommitDate: Sun Jun 29 19:24:39 2025 +0100

    general fixes:

    * purge static
    * add clang format file
    * fix Makefile
---
 .clang-format | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 Makefile      | 53 +++++++++++++++++++++++++++--------------
 src/config.h  | 30 ++++++++++++------------
 src/sxbar.c   | 75 +++++++++++++++++++++++++----------------------------------
 4 files changed, 148 insertions(+), 76 deletions(-)

diff --git a/.clang-format b/.clang-format
new file mode 100644
index 0000000..c3dcc85
--- /dev/null
+++ b/.clang-format
@@ -0,0 +1,66 @@
+---
+Language:        C
+
+# ---- Indentation ----
+UseTab:          ForIndentation
+TabWidth:        4
+IndentWidth:     4
+
+# ---- Line length ----
+ColumnLimit:     100
+
+# ---- Braces & Blocks ----
+InsertBraces:    true
+BraceWrapping:
+  AfterControlStatement:  false
+  BeforeElse:             true
+  AfterFunction:          true
+  AfterStruct:            true
+  AfterEnum:              true
+  SplitEmptyFunction:     true
+  SplitEmptyRecord:       true
+
+# ---- Spaces & Parens ----
+SpaceBeforeParens: ControlStatements
+SpaceBeforeParensOptions:
+  AfterControlStatements: true
+  AfterFunctionDefinitionName: false
+  AfterFunctionDeclarationName: false
+
+# ---- Comments ----
+ReflowComments:  Always
+SpacesInLineCommentPrefix:
+  Minimum:         1
+
+# ---- Includes ----
+SortIncludes:    CaseSensitive
+IncludeBlocks:   Preserve
+IncludeCategories:
+  - Regex:           '^"(llvm|llvm-c|clang|clang-c)/'
+    Priority:        2
+  - Regex:           '^(<|"(gtest|gmock|isl|json)/)'
+    Priority:        3
+  - Regex:           '.*'
+    Priority:        1
+
+# ---- Alignment ----
+AlignAfterOpenBracket:   DontAlign
+AlignOperands:           DontAlign
+AlignConsecutiveAssignments:
+  Enabled:         false
+AlignConsecutiveDeclarations:
+  Enabled:         false
+
+# ---- Additional C99-focused ----
+AllowShortFunctionsOnASingleLine: None
+AllowShortIfStatementsOnASingleLine: Never
+AllowShortLoopsOnASingleLine: false
+AllowShortCaseLabelsOnASingleLine: false
+
+# ---- Misc ----
+BreakBeforeBinaryOperators: All
+BreakBeforeTernaryOperators: true
+BreakStringLiterals: true
+MaxEmptyLinesToKeep: 1
+InsertNewlineAtEOF: false
+...
diff --git a/Makefile b/Makefile
index 65f5edc..2de826c 100644
--- a/Makefile
+++ b/Makefile
@@ -1,35 +1,52 @@
-CC = gcc
-CFLAGS = -Wall -Wextra -O3 -g -Isrc -march=native -flto -s -Os
-LDFLAGS = -lX11
+CC      ?= gcc
+CFLAGS  ?= -std=c99 -Wall -Wextra -O3 -Isrc
+LDFLAGS ?= -lX11 -lXinerama

-SRC_DIR = src
-SRC = $(wildcard $(SRC_DIR)/*.c)
-OBJ = $(SRC:.c=.o)
-BIN = sxbar
-PREFIX = /usr/local
+PREFIX  ?= /usr/local
+BIN     := sxbar
+SRC_DIR := src
+OBJ_DIR := build
+SRC     := $(wildcard $(SRC_DIR)/*.c)
+OBJ     := $(patsubst $(SRC_DIR)/%.c,$(OBJ_DIR)/%.o,$(SRC))
+DEP     := $(OBJ:.o=.d)
+
+MAN     := sxbar.1
+MAN_DIR := $(PREFIX)/share/man/man1

 all: $(BIN)

 $(BIN): $(OBJ)
-	$(CC) -o $@ $^ $(LDFLAGS)
+	$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
+
+$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c | $(OBJ_DIR)
+	@mkdir -p $(dir $@)
+	$(CC) $(CFLAGS) -MMD -MP -c -o $@ $<

-$(SRC_DIR)/%.o: $(SRC_DIR)/%.c
-	$(CC) $(CFLAGS) -c -o $@ $<
+-include $(DEP)
+
+$(OBJ_DIR):
+	@mkdir -p $@

 clean:
-	rm -f $(SRC_DIR)/*.o $(BIN)
+	@rm -rf $(OBJ_DIR) $(BIN)

 install: all
 	@echo "Installing $(BIN) to $(DESTDIR)$(PREFIX)/bin..."
-	@mkdir -p $(DESTDIR)$(PREFIX)/bin
-	@install -m 755 $(BIN) $(DESTDIR)$(PREFIX)/bin/$(BIN)
+	@mkdir -p "$(DESTDIR)$(PREFIX)/bin"
+	@install -m 755 $(BIN) "$(DESTDIR)$(PREFIX)/bin/$(BIN)"
+	@echo "Installing man page to $(DESTDIR)$(MAN_DIR)..."
+	@mkdir -p $(DESTDIR)$(MAN_DIR)
+	@install -m 644 $(MAN) $(DESTDIR)$(MAN_DIR)/
+	@echo "Copying default configuration to $(DESTDIR)$(PREFIX)/share/sxbarc..."
+	@mkdir -p "$(DESTDIR)$(PREFIX)/share"
+	@install -m 644 default_sxbarc "$(DESTDIR)$(PREFIX)/share/sxbarc"
 	@echo "Installation complete."

 uninstall:
 	@echo "Uninstalling $(BIN) from $(DESTDIR)$(PREFIX)/bin..."
-	@rm -f $(DESTDIR)$(PREFIX)/bin/$(BIN)
+	@rm -f "$(DESTDIR)$(PREFIX)/bin/$(BIN)"
+	@echo "Uninstalling man page from $(DESTDIR)$(MAN_DIR)..."
+	@rm -f $(DESTDIR)$(MAN_DIR)/$(MAN)
 	@echo "Uninstallation complete."

-clean-install: clean install
-
-.PHONY: all clean install uninstall clean-install
+.PHONY: all clean install uninstall
diff --git a/src/config.h b/src/config.h
index d605e37..f17952f 100644
--- a/src/config.h
+++ b/src/config.h
@@ -1,17 +1,17 @@
-#define BOTTOM_BAR		False
-#define BAR_HEIGHT		25
-#define BAR_VERT_PAD	15
-#define BAR_HORI_PAD	400
-#define BAR_BORDER		True
-#define BAR_BORDER_W	2
+#define BOTTOM_BAR      False
+#define BAR_HEIGHT      25
+#define BAR_VERT_PAD    15
+#define BAR_HORI_PAD    400
+#define BAR_BORDER      True
+#define BAR_BORDER_W    2

-#define BAR_COLOR_BG		"#56002e"
-#define BAR_COLOR_FG		"#ffffff"
-#define BAR_COLOR_BORDER	"#005577"
-#define BAR_FONT			"fixed"
-#define BAR_TEXT_PAD		10
+#define BAR_COLOR_BG        "#56002e"
+#define BAR_COLOR_FG        "#ffffff"
+#define BAR_COLOR_BORDER    "#005577"
+#define BAR_FONT            "fixed"
+#define BAR_TEXT_PAD        10

-#define BAR_WS_HIGHLIGHT_LEFT	"["
-#define BAR_WS_HIGHLIGHT_RIGHT	"]"
-#define BAR_WS_PADDING			10
-#define BAR_WS_SPACING			10
+#define BAR_WS_HIGHLIGHT_LEFT   "["
+#define BAR_WS_HIGHLIGHT_RIGHT  "]"
+#define BAR_WS_PADDING          10
+#define BAR_WS_SPACING          10
diff --git a/src/sxbar.c b/src/sxbar.c
index 3f7ada6..b9a7b88 100644
--- a/src/sxbar.c
+++ b/src/sxbar.c
@@ -1,8 +1,8 @@
+#define _POSIX_C_SOURCE 200809L
 #include <err.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <time.h>

 #include <X11/Xatom.h>
 #include <X11/Xlib.h>
@@ -10,30 +10,29 @@

 #include "defs.h"

-static void create_win(void);
-static int get_current_workspace(void);
-static char** get_workspace_name(int *count);
-static void hdl_dummy(XEvent *xev);
-static void hdl_expose(XEvent *xev);
-static void hdl_property(XEvent *xev);
-static ulong parse_col(const char *hex);
-static void run(void);
-static void setup(void);
-static void xev_cases(XEvent *xev);
-
-static EventHandler evtable[LASTEvent];
-static XFontStruct *font;
-static Display *dpy;
-static Window root, win;
-static GC gc;
-static uint scr;
-static ulong fg_col;
-static ulong bg_col;
-static ulong border_col;
+void create_win(void);
+int get_current_workspace(void);
+char** get_workspace_name(int *count);
+void hdl_dummy(XEvent *xev);
+void hdl_expose(XEvent *xev);
+void hdl_property(XEvent *xev);
+ulong parse_col(const char *hex);
+void run(void);
+void setup(void);
+void xev_cases(XEvent *xev);
+
+EventHandler evtable[LASTEvent];
+XFontStruct *font;
+Display *dpy;
+Window root, win;
+GC gc;
+uint scr;
+ulong fg_col;
+ulong bg_col;
+ulong border_col;
 #include "config.h"

-static void
-create_win(void)
+void create_win(void)
 {
 	int sw = DisplayWidth(dpy, scr);
 	int sh = DisplayHeight(dpy, scr);
@@ -93,8 +92,7 @@ create_win(void)
 	XSetFont(dpy, gc, font->fid);
 }

-static int
-get_current_workspace(void)
+int get_current_workspace(void)
 {
 	Atom actual_type;
 	int actual_format;
@@ -112,8 +110,7 @@ get_current_workspace(void)
 	return -1;
 }

-static char**
-get_workspace_name(int *count)
+char** get_workspace_name(int *count)
 {
 	Atom actual_type;
 	int actual_format;
@@ -143,14 +140,12 @@ get_workspace_name(int *count)
 	return NULL;
 }

-static void
-hdl_dummy(XEvent *xev)
+void hdl_dummy(XEvent *xev)
 {
 	(void) xev;
 }

-static void
-hdl_expose(XEvent *xev)
+void hdl_expose(XEvent *xev)
 {
 	(void) xev;
 	XClearWindow(dpy, win);
@@ -187,8 +182,7 @@ hdl_expose(XEvent *xev)
 			SXBAR_VERSION, strlen(SXBAR_VERSION));
 }

-static void
-hdl_property(XEvent *xev)
+void hdl_property(XEvent *xev)
 {
 	if (xev->xproperty.atom == XInternAtom(dpy, "_NET_CURRENT_DESKTOP", False)) {
 		XClearWindow(dpy, win);
@@ -198,8 +192,7 @@ hdl_property(XEvent *xev)
 	}
 }

-static ulong
-parse_col(const char *hex)
+ulong parse_col(const char *hex)
 {
 	XColor col;
 	Colormap cmap = DefaultColormap(dpy, DefaultScreen(dpy));
@@ -217,8 +210,7 @@ parse_col(const char *hex)
 	return col.pixel;
 }

-static void
-run(void)
+void run(void)
 {
 	XEvent xev;

@@ -228,8 +220,7 @@ run(void)
 	}
 }

-static void
-setup(void)
+void setup(void)
 {
 	if ((dpy = XOpenDisplay(NULL)) == 0)
 		errx(0, "can't open display. quitting...");
@@ -249,8 +240,7 @@ setup(void)
 	create_win();
 }

-static void
-xev_cases(XEvent *xev)
+void xev_cases(XEvent *xev)
 {
 	if (xev->type >= 0 && xev->type < LASTEvent)
 		evtable[xev->type](xev);
@@ -258,8 +248,7 @@ xev_cases(XEvent *xev)
 		printf("sxwm: invalid event type: %d\n", xev->type);
 }

-int
-main(int ac, char **av)
+int main(int ac, char **av)
 {
 	if (ac > 1) {
 		if (strcmp(av[1], "-v") == 0 || strcmp(av[1], "--version") == 0)