aboutsummaryrefslogtreecommitdiffstats
path: root/src/server.c
diff options
context:
space:
mode:
authoruser <user@clank>2026-08-17 14:22:38 +0200
committeruser <user@clank>2026-08-17 14:22:38 +0200
commitec91ccffe631ae34b111bf6161fd0e3c487f684c (patch)
tree4a9fdbb720d9bf03edd5f538d1d87afd2bf51bfb /src/server.c
parentsl0ppty: clang-format, and a hook that runs it on what you staged (diff)
downloadslosh-ec91ccffe631ae34b111bf6161fd0e3c487f684c.tar.gz
slosh-ec91ccffe631ae34b111bf6161fd0e3c487f684c.tar.xz
slosh-ec91ccffe631ae34b111bf6161fd0e3c487f684c.zip
sl0ppty: clang-format the tree
The bumpy one. `make fmt` over every `.c` and `.h` outside `vendor/`: 32 files, 1,843 lines rewritten, no behaviour changed. Nothing here is worth reading -- the next commit adds it to `.git-blame-ignore-revs` so `git blame` walks past it. Two thirds of it is alignment the formatter now owns: trailing comments in a struct, continuation lines under a signature. The rest is the hand-packed tables opening up to one entry per line -- `ACTIONS`, `NAMED_KEYS`, `ACTION_HELP`. That is a real loss of density and a real gain in diffs: adding an action was a reflow of the block and is now one line. Anything worth keeping packed can be fenced with `// clang-format off`; nothing was, on the grounds that a table is the thing a formatter is for. **One change is not formatting.** `src/config.h` had three trailing comments glued onto one field: uint16_t hover_delay_ms; /* how long the pointer must rest to arm a guide */ /* how long an announcement stays up */ /* rows per wheel notch */ -- `toast_ms`'s and `scroll_lines`' comments, landed on their neighbour by an earlier edit, documenting the wrong things ever since. It is in this commit because it is what caught it: clang-format could not settle on that line, wrapping it one way and then re-indenting the wrap on a second pass, so `make fmt` was not idempotent. The comments are back where they belong and it is. Verified after the reformat, not before: `make clean && make all` is warning-free, `make retest` is 1801 checks green, and `make fmt` twice in a row changes nothing the second time. A formatter that alters behaviour would be worse than none, so the gate was the whole suite rather than a reading of the diff.
Diffstat (limited to '')
-rw-r--r--src/server.c122
1 files changed, 62 insertions, 60 deletions
diff --git a/src/server.c b/src/server.c
index f728036..398d279 100644
--- a/src/server.c
+++ b/src/server.c
@@ -216,8 +216,8 @@ static void watch_config(watchset_t *w) {
* a mistyped path should not leave a directory behind. */
if (i == 0) path_mkdirs(dir);
- int wd = inotify_add_watch(w->fd, dir,
- IN_CLOSE_WRITE | IN_MOVED_TO | IN_CREATE);
+ int wd =
+ inotify_add_watch(w->fd, dir, IN_CLOSE_WRITE | IN_MOVED_TO | IN_CREATE);
if (wd >= 0) {
bool have = false;
for (size_t k = 0; k < w->nwds; k++)
@@ -260,8 +260,10 @@ static bool watch_hit(const watchset_t *w, const char *name) {
* and set rather than inherited so it names the binary that actually made this
* pane, not one that made some pane somewhere. */
void session_env(const char *name) {
- if (name) setenv("SL0PPTY_SESSION", name, 1);
- else unsetenv("SL0PPTY_SESSION");
+ if (name)
+ setenv("SL0PPTY_SESSION", name, 1);
+ else
+ unsetenv("SL0PPTY_SESSION");
char self[512];
ssize_t sn = readlink("/proc/self/exe", self, sizeof self - 1);
if (sn > 0) {
@@ -276,7 +278,8 @@ int server_run(const char *name, const char *const argv[], uint16_t cols,
if (session_socket_path(name, path, sizeof path) != 0) return 1;
int lfd = listen_socket(path);
if (lfd < 0) {
- fprintf(stderr, "sl0ppty: cannot listen on %s: %s\n", path, strerror(errno));
+ fprintf(stderr, "sl0ppty: cannot listen on %s: %s\n", path,
+ strerror(errno));
return 1;
}
@@ -415,66 +418,65 @@ int server_run(const char *name, const char *const argv[], uint16_t cols,
bool closed = false;
while (!closed && msg_reader_next(&s.conns[ci].reader, &m)) {
switch (m.type) {
- case MSG_HELLO:
- case MSG_RESIZE:
- if (m.type == MSG_HELLO && !s.conns[ci].display) {
- /* now it is a client: the previous display is displaced */
- for (size_t j = 0; j < s.nconns; j++)
- if (j != ci && s.conns[j].display) {
- conn_drop(&s, j, EXIT_REPLACED);
- if (j < ci) ci--; /* the array compacted under us */
- break;
- }
- s.conns[ci].display = true;
- }
- if (m.len >= 4 && s.conns[ci].display) {
- uint16_t c = (uint16_t)(m.data[0] << 8 | m.data[1]);
- uint16_t rr = (uint16_t)(m.data[2] << 8 | m.data[3]);
- if (c && rr) {
- screen_resize(&s.screen, c, rr);
- app_resize(s.app, c, rr);
+ case MSG_HELLO:
+ case MSG_RESIZE:
+ if (m.type == MSG_HELLO && !s.conns[ci].display) {
+ /* now it is a client: the previous display is displaced */
+ for (size_t j = 0; j < s.nconns; j++)
+ if (j != ci && s.conns[j].display) {
+ conn_drop(&s, j, EXIT_REPLACED);
+ if (j < ci) ci--; /* the array compacted under us */
+ break;
}
- /* The cell size arrived with it, from a client new enough to
+ s.conns[ci].display = true;
+ }
+ if (m.len >= 4 && s.conns[ci].display) {
+ uint16_t c = (uint16_t)(m.data[0] << 8 | m.data[1]);
+ uint16_t rr = (uint16_t)(m.data[2] << 8 | m.data[3]);
+ if (c && rr) {
+ screen_resize(&s.screen, c, rr);
+ app_resize(s.app, c, rr);
+ }
+ /* The cell size arrived with it, from a client new enough to
* send one and a terminal willing to say. Zero means neither,
* and app_set_cell_px leaves the default standing. */
- if (m.len >= 8) {
- uint16_t cw = (uint16_t)(m.data[4] << 8 | m.data[5]);
- uint16_t ch = (uint16_t)(m.data[6] << 8 | m.data[7]);
- app_set_cell_px(s.app, cw, ch);
- }
+ if (m.len >= 8) {
+ uint16_t cw = (uint16_t)(m.data[4] << 8 | m.data[5]);
+ uint16_t ch = (uint16_t)(m.data[6] << 8 | m.data[7]);
+ app_set_cell_px(s.app, cw, ch);
}
- s.screen.force_full = true; /* a fresh client knows nothing */
- app_graphics_reset(s.app); /* including any image we had sent */
- pending_paint = true;
- next_frame = now_ms();
- break;
- case MSG_INPUT:
- if (!s.conns[ci].display) break; /* only the client types */
- input_feed(s.in, m.data, m.len, srv_event, &s);
- esc_due = now_ms() + ESC_MS;
- pending_paint = true;
- break;
- case MSG_DETACH:
- conn_drop(&s, ci, EXIT_DETACHED);
- closed = true;
- break;
- case MSG_CMD: {
- /* The same vocabulary the headless driver speaks (cmd.c), so a
- * script written against one works against the other. */
- bool q = false;
- char *reply =
- cmd_exec(s.app, &s.screen, s.in, (const char *)m.data, &q);
- const char *body = reply ? reply : "{\"error\":\"unknown command\"}";
- msg_send(s.conns[ci].fd, MSG_REPLY, body, strlen(body));
- free(reply);
- if (q) g_stop = 1;
- s.screen.force_full = true; /* it may have changed the layout */
- pending_paint = true;
- next_frame = now_ms();
- break;
}
- default:
- break;
+ s.screen.force_full = true; /* a fresh client knows nothing */
+ app_graphics_reset(s.app); /* including any image we had sent */
+ pending_paint = true;
+ next_frame = now_ms();
+ break;
+ case MSG_INPUT:
+ if (!s.conns[ci].display) break; /* only the client types */
+ input_feed(s.in, m.data, m.len, srv_event, &s);
+ esc_due = now_ms() + ESC_MS;
+ pending_paint = true;
+ break;
+ case MSG_DETACH:
+ conn_drop(&s, ci, EXIT_DETACHED);
+ closed = true;
+ break;
+ case MSG_CMD: {
+ /* The same vocabulary the headless driver speaks (cmd.c), so a
+ * script written against one works against the other. */
+ bool q = false;
+ char *reply =
+ cmd_exec(s.app, &s.screen, s.in, (const char *)m.data, &q);
+ const char *body = reply ? reply : "{\"error\":\"unknown command\"}";
+ msg_send(s.conns[ci].fd, MSG_REPLY, body, strlen(body));
+ free(reply);
+ if (q) g_stop = 1;
+ s.screen.force_full = true; /* it may have changed the layout */
+ pending_paint = true;
+ next_frame = now_ms();
+ break;
+ }
+ default: break;
}
}
if (!closed) ci++;