commit 6cf5ebbc926076f18307acf2e4bc9571d979181c
Author: uint23 <https://uint23.xyz/>
AuthorDate: Sun Apr 20 08:40:35 2025 +0100
Commit: uint23 <https://uint23.xyz/>
CommitDate: Sun Apr 20 08:40:35 2025 +0100
restart!!!!!!!!!!!!!!!!!
---
src/config.h | 31 ++------
src/defs.h | 12 ++++
src/draw.c | 0
src/draw.h | 6 --
src/sxbar.c | 226 +++++------------------------------------------------------
src/utils.c | 16 -----
src/utils.h | 8 ---
7 files changed, 32 insertions(+), 267 deletions(-)
diff --git a/src/config.h b/src/config.h
index 08cc978..0147897 100644
--- a/src/config.h
+++ b/src/config.h
@@ -1,28 +1,5 @@
-// MIT License
-// See LICENSE for more information
-// Config file - see, it's not that difficult
-#define MAXPADV 500 // The vertical padding of the bar,
-#define MAXPADH 500 // The horizonral padding of the bar,
-#define MAXBARH 40 // The max height of the bar, this shouldn't really be more than 40
-#define MAXBDRW 10 // The max border width of the bar
-
-#include <X11/keysym.h>
-#define BUTTONLC 1 // Left click
-#define BUTTONMC 2 // Middle click
-#define BUTTONRC 3 // Right click
-
-// Keybindings
-//#define TOGGLE { ModMask|ShiftMask, XK_b, {.v=toggle}}
-
-static unsigned int topbar = 1; // Bar is at top (1) or bottom (0)
-static unsigned int centre = 1; // If using padding, this will centre your bar
-static unsigned int barh = 20; // Bar height
-static unsigned int padh = 400; // Horizontal bar padding
-static unsigned int padv = 10; // Vertical bar padding
-static unsigned int bdrw = 10; // Border width of the bar. Set to 0 for no border
-
-static const char colbg[] = "#A0A0DD"; // Background colour
-static const char colbdr[] = "#FF0000"; // Border colour
-// static const char *font = "terminus";
-static const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" };
+#define BAR_HEIGHT 10
+#define BAR_VERT_PAD 10
+#define BAR_HORI_PAD 100
+#define BAR_BORDER True
diff --git a/src/defs.h b/src/defs.h
new file mode 100644
index 0000000..48a7b55
--- /dev/null
+++ b/src/defs.h
@@ -0,0 +1,12 @@
+#ifndef DEFS_H
+#define DEFS_H
+
+#define uint unsigned int
+#define ulong unsigned long
+#define u_char unsigned char
+
+#define SXBAR_VERSION "sxbar ver. 0.1.1"
+#define SXBAR_AUTHOR "(C) Abhinav Prasai 2025"
+#define SXBAR_LICINFO "See LICENSE for more info"
+
+#endif
diff --git a/src/draw.c b/src/draw.c
deleted file mode 100644
index e69de29..0000000
diff --git a/src/draw.h b/src/draw.h
deleted file mode 100644
index 5ef1f51..0000000
--- a/src/draw.h
+++ /dev/null
@@ -1,6 +0,0 @@
-#ifndef DRAW_H
-#define DRAW_H
-
-static void drawbar();
-
-#endif
diff --git a/src/sxbar.c b/src/sxbar.c
index 28b02c1..8c10d20 100644
--- a/src/sxbar.c
+++ b/src/sxbar.c
@@ -1,220 +1,31 @@
-#include <X11/Xatom.h>
-#include <X11/X.h>
-#include <X11/Xlib.h>
-#include <X11/Xutil.h>
-#include <stdio.h>
+#include <err.h>
#include <string.h>
-#include <unistd.h>
-#include <time.h>
-#include "config.h"
-#include "utils.h"
-
-// Defs
-#define VERSION "0.1.0"
-#define LICENSE "This software is under the MIT License.\n\
-View the 'LICENSE' file for more info"
-#define AUTHOR "(C) Abhinav Prasai 2025"
-// Structs
-typedef union {
-
-} Args;
+#include <X11/Xlib.h>
-typedef struct {
- Window w;
- int tag;
-} Client;
+#include "defs.h"
-// Function declerations
-static void cleanup(void);
-static void createwin(void);
-static unsigned long getcol(const char *colstr);
-static void run(void);
-static void setatoms(void);
-static void sethints(void);
+static void create_win(void);
static void setup(void);
-// Variables
-static unsigned long bgpx;
-static unsigned long bdrpx;
-static unsigned int scrw;
-static unsigned int scrh;
-static unsigned int scr;
-static unsigned int barx;
-static unsigned int bary;
-static unsigned int barw;
static Display *dpy;
-static Window barwin;
static Window root;
-//static GC gc;
-
-// Functions
-static void
-createwin(void)
-{
- // Create the window
- barwin = XCreateSimpleWindow(
- dpy,
- root,
- barx, bary,
- barw, barh,
- bdrw,
- bdrpx,
- bgpx
- );
-
- XSelectInput(dpy, barwin,
- ExposureMask | KeyPressMask
- );
-
- setatoms();
- XMapWindow(dpy, barwin);
- XRaiseWindow(dpy, barwin);
- XSync(dpy, False);
-}
-
-static void
-cleanup(void)
-{
- XDestroyWindow(dpy, barwin);
- XCloseDisplay(dpy);
-}
-
-static unsigned long
-getcol(const char *colstr)
-{
- Colormap cmap = DefaultColormap(dpy, scr);
- XColor col;
- if (XAllocNamedColor(dpy, cmap, colstr, &col, &col) == 0)
- death("Error: can't alloc colour %s", colstr);
-
- return col.pixel;
-}
-
-static void
-run(void)
-{
- XEvent ev;
- createwin();
-
- for(;;) {
- XNextEvent(dpy, &ev);
-
- switch (ev.type) {
- case Expose:
- XFlush(dpy);
- break;
-
- case KeyPress:
- return;
- }
- }
-}
-
-static void
-setatoms(void)
-{
- Atom type, dock, state, sticky, strut, strutpartial, override;
- unsigned long strutvals[4] = {0}; // left, right, top, bottom
-
- if (topbar)
- strutvals[2] = barh;
- else
- strutvals[3] = barh;
-
- // Set window type to dock
- type = XInternAtom(dpy, "_NET_WM_WINDOW_TYPE", False);
- dock = XInternAtom(dpy, "_NET_WM_WINDOW_TYPE_DOCK", False);
- XChangeProperty(dpy, barwin, type, XA_ATOM, 32,
- PropModeReplace, (unsigned char *) &dock, 1);
-
- // Make it sticky
- state = XInternAtom(dpy, "_NET_WM_STATE", False);
- sticky = XInternAtom(dpy, "_NET_WM_STATE_STICKY", False);
- XChangeProperty(dpy, barwin, state, XA_ATOM, 32,
- PropModeReplace, (unsigned char *) &sticky, 1);
-
- // Set it to appear on all desktops
- Atom desktop = XInternAtom(dpy, "_NET_WM_DESKTOP", False);
- unsigned long alldesktops = 0xFFFFFFFF;
- XChangeProperty(dpy, barwin, desktop, XA_CARDINAL, 32,
- PropModeReplace, (unsigned char *)&alldesktops, 1);
-
- // Set basic strut
- strut = XInternAtom(dpy, "_NET_WM_STRUT", False);
- XChangeProperty(dpy, barwin, strut, XA_CARDINAL, 32,
- PropModeReplace, (unsigned char *)strutvals, 4);
-
- strutpartial = XInternAtom(dpy, "_NET_WM_STRUT_PARTIAL", False);
- unsigned long strutpartialvals[12] = {0};
- memcpy(strutpartialvals, strutvals, 4 * sizeof(unsigned long));
-
- if (topbar) {
- strutpartialvals[8] = 0;
- strutpartialvals[9] = scrw - 1;
- } else {
- strutpartialvals[10] = 0;
- strutpartialvals[11] = scrw - 1;
- }
- XChangeProperty(dpy, barwin, strutpartial, XA_CARDINAL, 32,
- PropModeReplace, (unsigned char *)strutpartialvals, 12);
-
- override = XInternAtom(dpy, "_NET_WM_WINDOW_TYPE_OVERRIDE", False);
- XChangeProperty(dpy, barwin, type, XA_ATOM, 32,
- PropModeAppend, (unsigned char *) &override, 1);
-
- sethints();
- XSync(dpy, False);
-}
+static uint scr;
static void
-sethints(void)
+create_win(void)
{
- XSizeHints hints;
- hints.flags = PPosition | PSize | PWinGravity;
- hints.x = barx;
- hints.y = bary;
- hints.width = barw;
- hints.height = barh;
- hints.win_gravity = topbar ? NorthWestGravity : SouthWestGravity;
- XSetWMNormalHints(dpy, barwin, &hints);
+ ulong fg = WhitePixel(dpy, scr);
+ ulong bg = BlackPixel(dpy, scr);
}
static void
setup(void)
{
- dpy = XOpenDisplay(NULL);
- if (dpy == 0)
- death("Failed to open display.");
-
- scr = DefaultScreen(dpy);
- scrw = DisplayWidth(dpy, scr);
- scrh = DisplayHeight(dpy, scr);
- root = RootWindow(dpy, scr);
-
- // Calculate bar y-position
- if (topbar)
- bary = padv ? padv : 0;
- else
- bary = padv ? scrh - barh - padv - bdrw :
- scrh - barh - bdrw;
-
- // Calculate bar x-position and width
- if (padh) {
- barx = centre ? padh : 0;
- barw = centre ? scrw - (padh * 2) : scrw - padh;
- } else {
- barx = 0;
- barw = scrw;
- }
-
- // Clamp dimensions
- if (barh > MAXBARH) barh = MAXBARH;
- if (padv > MAXPADV) padv = MAXPADV;
- if (padh > MAXPADH) padh = MAXPADH;
-
- bgpx = getcol(colbg);
- bdrpx = getcol(colbdr);
+ if ((dpy = XOpenDisplay(NULL)) == 0)
+ errx(0, "can't open display. quitting...");
+ root = XDefaultRootWindow(dpy);
+ scr = DefaultScreen(dpy);
}
int
@@ -222,15 +33,10 @@ main(int ac, char **av)
{
if (ac > 1) {
if (strcmp(av[1], "-v") == 0 || strcmp(av[1], "--version") == 0)
- death("sxbar ver. %s\n%s\n%s", VERSION, LICENSE, AUTHOR);
- if (strcmp(av[1], "-h") == 0 || strcmp(av[1], "--help") == 0)
- death("USEAGE:\n\t[-v || --version] is the only command..");
+ errx(0, "%s\n%s\n%s", SXBAR_VERSION, SXBAR_AUTHOR, SXBAR_LICINFO);
else
- death("USEAGE:\n\t[-v || --version] is the only command..");
- } else {
- setup();
- run();
- cleanup();
+ errx(0, "usage:\n[-v || --version]: See the version of sxbar");
}
- return 0;
+
+ setup();
}
diff --git a/src/utils.c b/src/utils.c
deleted file mode 100644
index 798782f..0000000
--- a/src/utils.c
+++ /dev/null
@@ -1,16 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <stdarg.h>
-
-void
-death(const char *fmt, ...)
-{
- va_list args;
- va_start(args, fmt);
-
- vfprintf(stderr, fmt, args);
- va_end(args);
-
- fprintf(stderr, "\n");
- exit(EXIT_FAILURE);
-}
diff --git a/src/utils.h b/src/utils.h
deleted file mode 100644
index 185e07f..0000000
--- a/src/utils.h
+++ /dev/null
@@ -1,8 +0,0 @@
-#ifndef UTILS_H
-#define UTILS_H
-#define SECOND(T) (T * 1000000)
-#define MSECOND(T) (T * 1000)
-
-void death(char* message, ...);
-
-#endif