commit e4195defd2a6d18367166b3572286aa1c5ab3a56
Author: uint23 <abhinav.prsai@gmail.com>
AuthorDate: Thu Apr 10 18:20:03 2025 +0100
Commit: uint23 <abhinav.prsai@gmail.com>
CommitDate: Thu Apr 10 18:20:03 2025 +0100
the dock now works on things like openbox
it is a proper dock now!
no text rendering etc but its a dock
next:
get tags working
---
src/config.h | 10 ++--
src/sxbar.c | 152 +++++++++++++++++++++++++++++++++++++++++++++++++----------
2 files changed, 131 insertions(+), 31 deletions(-)
diff --git a/src/config.h b/src/config.h
index a7795d8..dac372c 100644
--- a/src/config.h
+++ b/src/config.h
@@ -8,17 +8,17 @@
#define MAXBDRW 10 // The max border width of the bar
// Keybindings
-#define TOGGLE { ModMask|ShiftMask, XK_b, {.v=toggle}}
+//#define TOGGLE { ModMask|ShiftMask, XK_b, {.v=toggle}}
-static unsigned int topbar = 0; // Bar is at top (1) or bottom (0)
+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 = 20; // Vertical bar padding
-static unsigned int bdrw = 1; // Border width of the bar. Set to 0 for no border
+static unsigned int padv = 10; // Vertical bar padding
+static unsigned int bdrw = 0; // Border width of the bar. Set to 0 for no border
static const char colfg[] = "#ABCDEF"; // Foreground colour
-static const char colbg[] = "#090425"; // Background colour
+static const char colbg[] = "#555555"; // Background colour
static const char colbdr[] = "#090425"; // Border colour
// static const char *font = "terminus";
// static const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" };
diff --git a/src/sxbar.c b/src/sxbar.c
index 8f964f1..dbb30bc 100644
--- a/src/sxbar.c
+++ b/src/sxbar.c
@@ -1,7 +1,7 @@
+#include <X11/Xatom.h>
#include <X11/X.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
-#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <time.h>
@@ -25,42 +25,56 @@ typedef struct {
} Client;
// Function declerations
-static void createwin(void);
static void cleanup(void);
+static void createwin(void);
+static unsigned long getcol(const char *colstr);
static void run(void);
+static void setdock(void);
+static void sethints(void);
static void setup(void);
// Variables
+static unsigned long fgpx;
+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 Display *dpy;
+static Window barwin;
+static Window root;
// Functions
static void
createwin(void)
{
- barwin = XCreateSimpleWindow(
- dpy,
- root,
- barx, bary,
- barw, barh,
- bdrw,
- BlackPixel(dpy, scr),
- WhitePixel(dpy, scr)
- );
-
- XSelectInput(dpy, barwin,
- ExposureMask | KeyPressMask
- );
-
- XMapWindow(dpy, barwin);
- XRaiseWindow(dpy, barwin);
+ // Create the window
+ barwin = XCreateSimpleWindow(
+ dpy,
+ root,
+ barx, bary,
+ barw, barh,
+ bdrw,
+ bdrpx,
+ bgpx
+ );
+
+ XSelectInput(dpy, barwin,
+ ExposureMask | KeyPressMask
+ );
+
+ // Set dock properties BEFORE mapping
+ setdock();
+
+ // Map the window
+ XMapWindow(dpy, barwin);
+
+ // Make sure it's on top
+ XRaiseWindow(dpy, barwin);
+ XSync(dpy, False);
}
static void
@@ -70,6 +84,17 @@ cleanup(void)
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)
{
@@ -78,17 +103,88 @@ run(void)
for(;;) {
XNextEvent(dpy, &ev);
- if (ev.type == Expose) {
+
+ switch (ev.type) {
+ case Expose:
XFlush(dpy);
- } else if (ev.type == KeyPress) {
+ break;
+
+ case KeyPress:
return;
}
-
- usleep(SECOND(1));
}
}
-void
+static void
+setdock(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 void
+sethints(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);
+}
+
+static void
setup(void)
{
dpy = XOpenDisplay(NULL);
@@ -127,6 +223,10 @@ setup(void)
padv = MAXPADV;
if (padh > MAXPADH)
padh = MAXPADH;
+
+ fgpx = getcol(colfg);
+ bgpx = getcol(colbg);
+ bdrpx = getcol(colbdr);
}
int