commit - 636fecc8d40f400c4f0dd34335d879b59a02eacc
commit + 78a11878fa94c94014b7a0364319fb5025821916
blob - f2036ceee0d2a17f9060e28eec8ee71c00c908af
blob + 1b19669b48acd0d65bfc6423ef3f8ff04efbe10b
--- bxwm.c
+++ bxwm.c
/*
+ * bxwm
+ *
* A very basic X window manager, a.k.a. Brett's X window manager.
* See LICENSE.md and README.md for details.
*/
#include <stdio.h>
#include <stdlib.h>
+#include <stdarg.h>
#include <unistd.h>
#include <signal.h>
#include <X11/Xlib.h>
#include "config.h"
-
/* Layout types */
enum { FLOAT, CENTER, LEFT_HALF, RIGHT_HALF, SMALL, MAXIMIZE };
/* ICCCM atoms */
static Atom wm_protocols, wm_delete_window;
-/* Function declarations */
+/* Forward function declarations */
+static void logmsg(const char *fmt, ...);
static void run(void);
static void cleanup(int status);
static void setup(void);
static void unmanage(Window w);
static void update_client_list(void);
-int main(void) {
+int
+main(void) {
signal(SIGTERM, cleanup);
dpy = XOpenDisplay(NULL);
if (!dpy) {
return 0;
}
-static void setup(void) {
+/* Uncomment to enable debug logging */
+/* #define DEBUG */
+
+#ifdef DEBUG
+static void
+logmsg(const char *fmt, ...) {
+ va_list ap;
+ va_start(ap, fmt);
+ fprintf(stderr, "bxwm: ");
+ vfprintf(stderr, fmt, ap);
+ va_end(ap);
+ fprintf(stderr, "\n");
+}
+#else
+static void logmsg(const char *fmt, ...) { (void)fmt; }
+#endif
+
+static void
+setup(void) {
XSetWindowAttributes wa;
Colormap cmap = DefaultColormap(dpy, DefaultScreen(dpy));
XColor color;
update_workarea();
spawn(STATUSBAR);
-
- #ifdef DEBUG
- fprintf(stderr, "bxwm: setup complete\n");
- #endif
}
-static void manage(Window w) {
+static void
+manage(Window w) {
XWindowAttributes wa;
XSetWindowAttributes attrs;
unsigned int win_w, win_h;
int win_x, win_y;
Client *c;
- #ifdef DEBUG
- fprintf(stderr, "bxwm: managing 0x%lx\n", w);
- #endif
+ logmsg("managing 0x%lx", w);
if (!XGetWindowAttributes(dpy, w, &wa))
return;
update_client_list();
}
-static void focus_client(Client *c) {
+static void
+focus_client(Client *c) {
Client *prev = focused_client;
if (prev) {
long active = c->win;
XChangeProperty(dpy, root, net_active_window, XA_WINDOW, 32,
PropModeReplace, (unsigned char *)&active, 1);
- #ifdef DEBUG
- fprintf(stderr, "bxwm: focused 0x%lx\n", c->win);
- #endif
+
+ logmsg("focused 0x%lx", c->win);
}
}
-static void center_window(Client *c) {
+static void
+center_window(Client *c) {
unsigned int win_w = (wa_w / 2) - (2 * BORDER_WIDTH);
int win_x = wa_x + (wa_w - (win_w + 2 * BORDER_WIDTH)) / 2;
int win_y = wa_y;
if (!c) return;
c->layout = CENTER;
- #ifdef DEBUG
- fprintf(stderr, "bxwm: center 0x%lx\n", c->win);
- #endif
-
{
XWindowChanges wc = {
.x = win_x,
}
}
-static void left_half_window(Client *c) {
+static void
+left_half_window(Client *c) {
unsigned int win_w = (wa_w / 2) - (2 * BORDER_WIDTH);
int win_x = wa_x;
int win_y = wa_y;
if (!c) return;
c->layout = LEFT_HALF;
- #ifdef DEBUG
- fprintf(stderr, "bxwm: left 0x%lx\n", c->win);
- #endif
-
{
XWindowChanges wc = {
.x = win_x,
}
}
-static void right_half_window(Client *c) {
+static void
+right_half_window(Client *c) {
unsigned int win_w = (wa_w / 2) - (2 * BORDER_WIDTH);
int win_x = wa_x + wa_w - win_w - (2 * BORDER_WIDTH);
int win_y = wa_y;
if (!c) return;
c->layout = RIGHT_HALF;
- #ifdef DEBUG
- fprintf(stderr, "bxwm: right 0x%lx\n", c->win);
- #endif
-
{
XWindowChanges wc = {
.x = win_x,
}
}
-static void small_window(Client *c) {
+static void
+small_window(Client *c) {
unsigned int win_w, win_h;
int win_x, win_y;
(screen height - total window height including borders) / 2 */
win_y = wa_y + (wa_h - (win_h + 2 * BORDER_WIDTH)) / 2;
-
- #ifdef DEBUG
- fprintf(stderr, "bxwm: small 0x%lx\n", c->win);
- #endif
-
{
XWindowChanges wc = {
.x = win_x,
}
}
-static void maximize_window(Client *c) {
+static void
+maximize_window(Client *c) {
unsigned int win_w = wa_w - (2 * BORDER_WIDTH);
unsigned int win_h = wa_h - (2 * BORDER_WIDTH);
int win_x = wa_x;
if (!c) return;
c->layout = MAXIMIZE;
- #ifdef DEBUG
- fprintf(stderr, "bxwm: maximize 0x%lx\n", c->win);
- #endif
-
{
XWindowChanges wc = {
.x = win_x,
}
}
-static void close_window(Client *c) {
+static void
+close_window(Client *c) {
if (!c) return;
int n;
XKillClient(dpy, c->win);
}
-static void focus_next(void) {
+static void
+focus_next(void) {
unsigned int i, idx, start;
int found = 0;
}
}
-static void focus_prev(void) {
+static void
+focus_prev(void) {
unsigned int i, idx, start;
int found = 0;
}
}
-static void view(int ws) {
+static void
+view(int ws) {
unsigned int i;
if (ws < 0 || ws >= NUM_WORKSPACES || ws == curws)
focus_next();
}
-static void movetows(int ws) {
+static void
+movetows(int ws) {
Client *c = focused_client;
int old_ws;
}
}
-static void unmanage(Window w) {
+static void
+unmanage(Window w) {
unsigned int i;
Client *c = NULL;
- #ifdef DEBUG
- fprintf(stderr, "bxwm: unmanage 0x%lx\n", w);
- #endif
+ logmsg("unmanage 0x%lx", w);
for (i = 0; i < num_clients; i++) {
if (clients[i].win == w) {
}
}
-static void spawn(const char *cmd) {
+static void
+spawn(const char *cmd) {
if (fork() == 0)
execl("/bin/sh", "sh", "-c", cmd, (char *)NULL);
}
-static int xerror(Display *dpy, XErrorEvent *ee) {
+static int
+xerror(Display *dpy, XErrorEvent *ee) {
char buf[1024];
XGetErrorText(dpy, ee->error_code, buf, sizeof(buf));
fprintf(stderr, "bxwm: X error: %s\n", buf);
return 0;
}
-static void run(void) {
+static void
+run(void) {
XEvent ev;
KeyCode kcodes[11];
KeyCode ws_codes[10];
}
}
-static void update_client_list(void) {
+static void
+update_client_list(void) {
Window *wins = NULL;
unsigned int i;
free(wins);
}
-static void arrange(void) {
+static void
+arrange(void) {
unsigned int i;
for (i = 0; i < num_clients; i++) {
if (clients[i].ws == curws && !clients[i].is_dock) {
}
}
-static void update_workarea(void) {
+static void
+update_workarea(void) {
unsigned long left = 0, right = 0, top = 0, bottom = 0;
unsigned int i;
Atom actual_type;
}
-static void cleanup(int status) {
+static void
+cleanup(int status) {
if (dpy) {
if (clients)
free(clients);