commit 9eede8d30b233bf3ee3c74fbbed3803540b556b5 from: Brett Fisher date: Wed May 13 18:48:00 2026 UTC bxwm.c: - Add state management and logic for integration with bxbar. - Add layout state to Client struct to track window geometry. - Implement arrange() to re-tile windows when work area changes. - Modify layout functions to update layout state instead of changing focus. - Set dock windows to persistent workspace -1. - Prevent dock windows from being moved or reassigned. - Spawn STATUSBAR command on startup via setup(). commit - 801fab761b523d968811e2c3d88a7a377dcb4975 commit + 9eede8d30b233bf3ee3c74fbbed3803540b556b5 blob - 8c2d515010933fbddb7f2346fc58bd29a1cd96d0 blob + f2036ceee0d2a17f9060e28eec8ee71c00c908af --- bxwm.c +++ bxwm.c @@ -15,12 +15,17 @@ #include "config.h" + +/* Layout types */ +enum { FLOAT, CENTER, LEFT_HALF, RIGHT_HALF, SMALL, MAXIMIZE }; + /* Types */ typedef struct { Window win; int focused; int ws; int is_dock; /* dock/bar window: no border, no positioning, no focus */ + int layout; /* Remember window geometry type */ } Client; /* Globals */ @@ -215,6 +220,8 @@ static void setup(void) { update_workarea(); + spawn(STATUSBAR); + #ifdef DEBUG fprintf(stderr, "bxwm: setup complete\n"); #endif @@ -274,6 +281,8 @@ static void manage(Window w) { win_x = wa_x + (wa_w - (win_w + 2 * BORDER_WIDTH)) / 2; win_y = wa_y + (wa_h - (win_h + 2 * BORDER_WIDTH)) / 2; + c->layout = SMALL; /* Default golden ratio placement */ + XWindowChanges wc = { .x = win_x, .y = win_y, @@ -328,6 +337,7 @@ static void center_window(Client *c) { int win_y = wa_y; if (!c) return; + c->layout = CENTER; #ifdef DEBUG fprintf(stderr, "bxwm: center 0x%lx\n", c->win); @@ -345,7 +355,6 @@ static void center_window(Client *c) { unsigned int mask = (CWX | CWY | CWWidth | CWHeight | CWBorderWidth | CWStackMode); XConfigureWindow(dpy, c->win, mask, &wc); } - focus_client(c); } static void left_half_window(Client *c) { @@ -354,6 +363,7 @@ static void left_half_window(Client *c) { int win_y = wa_y; if (!c) return; + c->layout = LEFT_HALF; #ifdef DEBUG fprintf(stderr, "bxwm: left 0x%lx\n", c->win); @@ -371,7 +381,6 @@ static void left_half_window(Client *c) { unsigned int mask = (CWX | CWY | CWWidth | CWHeight | CWBorderWidth | CWStackMode); XConfigureWindow(dpy, c->win, mask, &wc); } - focus_client(c); } static void right_half_window(Client *c) { @@ -380,7 +389,8 @@ static void right_half_window(Client *c) { int win_y = wa_y; if (!c) return; - + c->layout = RIGHT_HALF; + #ifdef DEBUG fprintf(stderr, "bxwm: right 0x%lx\n", c->win); #endif @@ -397,7 +407,6 @@ static void right_half_window(Client *c) { unsigned int mask = (CWX | CWY | CWWidth | CWHeight | CWBorderWidth | CWStackMode); XConfigureWindow(dpy, c->win, mask, &wc); } - focus_client(c); } static void small_window(Client *c) { @@ -405,7 +414,8 @@ static void small_window(Client *c) { int win_x, win_y; if (!c) return; - + c->layout = SMALL; + /* Step 1: Calculate height first (50% of screen, minus borders) */ win_h = (wa_h * INITIAL_HEIGHT) - (2 * BORDER_WIDTH); @@ -443,7 +453,6 @@ static void small_window(Client *c) { unsigned int mask = CWX | CWY | CWWidth | CWHeight | CWBorderWidth | CWStackMode; XConfigureWindow(dpy, c->win, mask, &wc); } - focus_client(c); } static void maximize_window(Client *c) { @@ -453,7 +462,8 @@ static void maximize_window(Client *c) { int win_y = wa_y; if (!c) return; - + c->layout = MAXIMIZE; + #ifdef DEBUG fprintf(stderr, "bxwm: maximize 0x%lx\n", c->win); #endif @@ -470,7 +480,6 @@ static void maximize_window(Client *c) { unsigned int mask = (CWX | CWY | CWWidth | CWHeight | CWBorderWidth | CWStackMode); XConfigureWindow(dpy, c->win, mask, &wc); } - focus_client(c); } static void close_window(Client *c) { @@ -836,6 +845,21 @@ static void update_client_list(void) { free(wins); } +static void arrange(void) { + unsigned int i; + for (i = 0; i < num_clients; i++) { + if (clients[i].ws == curws && !clients[i].is_dock) { + switch (clients[i].layout) { + case CENTER: center_window(&clients[i]); break; + case LEFT_HALF: left_half_window(&clients[i]); break; + case RIGHT_HALF: right_half_window(&clients[i]); break; + case SMALL: small_window(&clients[i]); break; + case MAXIMIZE: maximize_window(&clients[i]); break; + } + } + } +} + static void update_workarea(void) { unsigned long left = 0, right = 0, top = 0, bottom = 0; unsigned int i; @@ -892,6 +916,8 @@ static void update_workarea(void) { PropModeReplace, (unsigned char *)workareas, NUM_WORKSPACES * 4); free(workareas); + + arrange(); }