Skip to content

Instantly share code, notes, and snippets.

@farhaven
Created March 23, 2025 17:29
Show Gist options
  • Save farhaven/d05ff41ec630385b04b6d5797f45ab6a to your computer and use it in GitHub Desktop.
Save farhaven/d05ff41ec630385b04b6d5797f45ab6a to your computer and use it in GitHub Desktop.
/// This is the C-header that I'm using
typedef struct Monitor Monitor;
typedef struct Client Client;
struct Client {
char name[256];
float mina, maxa;
int x, y, w, h;
int oldx, oldy, oldw, oldh;
int basew, baseh, incw, inch, maxw, maxh, minw, minh, hintsvalid;
int bw, oldbw;
unsigned int tags;
int isfixed, isfloating, isurgent, neverfocus, oldstate, isfullscreen, dontmanage;
Client *next;
Client *snext;
Monitor *mon;
Window win;
};
typedef struct {
const char *symbol;
void (*arrange)(Monitor *);
} Layout;
struct Monitor {
char ltsymbol[16];
float mfact;
int nmaster;
int num;
int by; /* bar geometry */
int mx, my, mw, mh; /* screen size */
int wx, wy, ww, wh; /* window area */
unsigned int seltags;
unsigned int sellt;
unsigned int tagset[2];
int showbar;
int topbar;
Client *clients;
Client *sel;
Client *stack;
Monitor *next;
Window barwin;
const Layout *lt[2];
};
/// It's used in Zig roughly like this
const _shared = @cImport({
@cInclude("X11/Xlib.h");
@cInclude("structs.h");
});
var mons = @extern(?*_shared.Monitor, .{
.name = "mons",
});
extern "c" fn unmanage(*_shared.Client, c_int) void;
/// and then later, also in Zig:
fn cleanup() void {
var m = mons;
while (m) |mm| {
while (mm.*.stack) |c| {
/// unmanage is a C-function
unmanage(c, 0);
}
m = mm.*.next;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment