diff options
| author | uint23 <72694427+uint23@users.noreply.github.com> | 2025-05-18 12:57:37 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-05-18 12:57:37 +0100 |
| commit | 6d9bf1e70d660ee0f8d2c6c6fa8c8b8e989d6b93 (patch) | |
| tree | 7304a4453413f55667728f0078a230be1719f07f | |
| parent | 29486b974b1f902254e1520fcc455fbda5e274d7 (diff) | |
| parent | a275a4a1b10f3939cbc9d0179298268c817b8f22 (diff) | |
Merge pull request #22 from werdl/main
Floating window toggle
| -rw-r--r-- | README.md | 1 | ||||
| -rw-r--r-- | src/defs.h | 1 | ||||
| -rw-r--r-- | src/parser.c | 25 | ||||
| -rw-r--r-- | src/sxwm.c | 40 |
4 files changed, 66 insertions, 1 deletions
@@ -89,6 +89,7 @@ The file uses a `key : value` format. Lines starting with `#` are ignored. | `resize_master_amount` | Integer | `1` | Percentage (%) to increase/decrease the master width when resizing. | | `snap_distance` | Integer | `5` | Pixels from screen edge before a floating window snaps to the edge. | | `motion_throttle` | Integer | `60` | Target updates per second for mouse drag operations (move/resize/swap). Set close to your monitor's refresh rate for smoother visuals. | +| `should_float` | String | `""` | A window to always flaot (eg. `st`). For multiple windows, add multiple options.| ### Keybindings @@ -87,6 +87,7 @@ typedef struct { int snap_distance; int bindsn; Binding binds[256]; + char *should_float[256]; } Config; typedef struct { diff --git a/src/parser.c b/src/parser.c index de63e8d..1ceb7e0 100644 --- a/src/parser.c +++ b/src/parser.c @@ -169,6 +169,12 @@ found: char line[512]; int lineno = 0; + int should_floatn = 0; + + for (int i = 0; i < 256; i++) { + cfg->should_float[i] = NULL; + } + while (fgets(line, sizeof line, f)) { lineno++; char *s = strip(line); @@ -221,6 +227,25 @@ found: else if (!strcmp(key, "snap_distance")) { cfg->snap_distance = atoi(rest); } + else if (!strcmp(key, "should_float")) { + // should_float: <window> + + if (should_floatn >= 256) { + fprintf(stderr, "sxwmrc:%d: too many should_float entries\n", lineno); + continue; + } + + char *win = strip(rest); + + cfg->should_float[should_floatn] = malloc(strlen(win) + 1); + if (!cfg->should_float[should_floatn]) { + fprintf(stderr, "sxwmrc:%d: out of memory\n", lineno); + break; + } + + strcpy(cfg->should_float[should_floatn], win); + should_floatn++; + } else if (!strcmp(key, "call") || !strcmp(key, "bind")) { char *mid = strchr(rest, ':'); if (!mid) { @@ -131,6 +131,8 @@ int reserve_right = 0; int reserve_top = 0; int reserve_bottom = 0; +Bool next_should_float = False; + Client *add_client(Window w, int ws) { Client *c = malloc(sizeof(Client)); @@ -188,6 +190,7 @@ Client *add_client(Window w, int ws) c->fixed = False; c->floating = False; + c->fullscreen = False; if (global_floating) { @@ -588,6 +591,12 @@ void hdl_keypress(XEvent *xev) switch (b->type) { case TYPE_CMD: spawn(b->action.cmd); + for (int j = 0; j < 256; j++) { + if (user_config.should_float[j] && !strcmp(user_config.should_float[j], b->action.cmd[0])) { + next_should_float = True; + break; + } + } break; case TYPE_FUNC: if (b->action.fn) @@ -723,7 +732,35 @@ void hdl_map_req(XEvent *xev) should_float = True; c->fixed = True; } - c->floating = should_float || global_floating; + + if (should_float || global_floating || next_should_float) { + c->floating = True; + + if (next_should_float) { + if (c->floating) { + XWindowAttributes wa; + XGetWindowAttributes(dpy, c->win, &wa); + c->x = wa.x; + c->y = wa.y; + c->w = wa.width; + c->h = wa.height; + + XConfigureWindow( + dpy, c->win, CWX | CWY | CWWidth | CWHeight, + &(XWindowChanges){.x = c->x, .y = c->y, .width = c->w, .height = c->h}); + } + + tile(); + update_borders(); + + if (c->floating) { + XRaiseWindow(dpy, c->win); + XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime); + } + next_should_float = False; + } + } + /* center floating windows & set border */ if (c->floating && !c->fullscreen) { @@ -1695,6 +1732,7 @@ int main(int ac, char **av) } } setup(); + printf("sxwm: starting...\n"); run(); return 0; } |
