aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoruser <user@clank>2026-08-15 11:32:47 +0200
committeruser <user@clank>2026-08-15 11:32:47 +0200
commitd006c523de132dafa5748345ceb22f4a9f5d4cd4 (patch)
treeb81b8481a9a48bd770a0f30df66f1da8d2f7a7f7
parentsl0ppty: C-a ? shows every binding you have (diff)
downloadslosh-d006c523de132dafa5748345ceb22f4a9f5d4cd4.tar.gz
slosh-d006c523de132dafa5748345ceb22f4a9f5d4cd4.tar.xz
slosh-d006c523de132dafa5748345ceb22f4a9f5d4cd4.zip
sl0ppty: modals get their own surface, and dim what is behind them
Two things wrong with the first one, and both are about it being a modal rather than a pane that happens to float. The close button was invisible. It was drawn in the pane button colour on the finder background, and in the default theme those are the same value -- #45454a on #45454a -- so it only appeared when the pointer landed on it and the hover colour took over. That is the hazard of borrowing names from another surface: each one is right, and together they are nothing. A modal is its own surface now, with its own names (modal_bg, modal_fg, modal_border, modal_title, modal_button, modal_button_hover), a dark panel a shade lighter than the dimmed screen, a border in the accent, and a button chosen to be visible *without* the pointer on it. All six themes set them. And nothing behind it moved, so it read as another pane rather than as something in front. There is a scrim now, `modal_scrim` (0..255, 120 by default), and the pleasing part is that it is not a new mechanism: it is the shader pass aimed at the screen instead of at a pane. Same dim, same materialisation of default colours, no special case. It goes down after everything else is painted and before the modal, so the modal is the only thing at full brightness -- which is the whole idea, and is asserted rather than assumed. The shape is now reusable: modal_frame() draws the box, title, close button and hit, and returns the rect inside it; draw_scrim() is one line above it. The next modal is a function call and looks the same as this one. The finder is deliberately left alone. It is a picker rather than a modal -- it navigates, where a modal here dismisses on any key -- so unifying them would be making two things one because they are both rectangles.
-rw-r--r--HANDOVER.md23
-rw-r--r--config/config.kdl23
-rw-r--r--contrib/themes/amber.kdl8
-rw-r--r--contrib/themes/mono.kdl8
-rw-r--r--contrib/themes/paper.kdl8
-rw-r--r--contrib/themes/phosphor.kdl8
-rw-r--r--contrib/themes/sl0p.kdl8
-rw-r--r--contrib/themes/slate.kdl8
-rw-r--r--src/app.c175
-rw-r--r--src/config.c23
-rw-r--r--src/config.h14
-rw-r--r--tests/test_help.py76
12 files changed, 322 insertions, 60 deletions
diff --git a/HANDOVER.md b/HANDOVER.md
index bd04ef0..1950872 100644
--- a/HANDOVER.md
+++ b/HANDOVER.md
@@ -216,6 +216,25 @@ no cursor". The graphics stream now opens with DECSC and closes with DECRC,
and emits nothing at all when there is nothing to say. Any future
after-the-frame output owes the same debt.
+## Modals
+
+`modal_frame()` draws the surface and `draw_scrim()` pushes back what is
+behind it; the cheatsheet is the first thing to use them and is meant to be
+the shape the next one copies. Two things it got wrong first, both worth not
+repeating:
+
+- **it borrowed colours from another surface.** The close button was the pane
+ button colour on the finder background, which are the same value in the
+ default theme, so it was invisible until hovered. A modal is its own
+ surface and now has its own `modal_*` names. When you add a surface, give
+ it names; when you reuse names, check what they resolve to *together*.
+- **the scrim is the shader pass, aimed at the screen.** Nothing about it is
+ special-cased, which is why it dims chrome as happily as contents — but it
+ also means the whole screen's unset colours get materialised through
+ `default_fg`/`default_bg` while a modal is up, so a terminal whose real
+ background differs from the configured one shifts slightly. Documented next
+ to `modal_scrim` rather than hidden.
+
## Things left on the table
- **A `reload` keybinding.** The config watcher made it less pressing.
@@ -238,6 +257,10 @@ after-the-frame output owes the same debt.
pane. Hot-swapping would need every shader reference to be indirected
through the registry, which is a real change and not obviously worth it.
- **Per-row shader dispatch** — see the numbers above.
+- **The finder is not a modal** and predates `modal_frame()`. It keeps its own
+ `finder_*` colours and its own box. Moving it over would unify two overlay
+ looks into one; it was left alone because it is a picker rather than a
+ modal — it navigates, and modals here dismiss on any key.
- **The cell size is not queried, only received.** If a client's terminal
reports no pixel size in `TIOCGWINSZ`, we keep the 8x16 default rather than
asking it with `CSI 14 t`/`CSI 16 t`. Doing that properly means the client
diff --git a/config/config.kdl b/config/config.kdl
index dd50cdd..bfeebb6 100644
--- a/config/config.kdl
+++ b/config/config.kdl
@@ -163,6 +163,16 @@ hover_delay_ms 250
// program calls itself.
double_click_ms 400
+// How far everything behind a modal (the cheatsheet, C-a ?) is pushed back,
+// 0..255, and 0 for not at all. A modal floating over a screen as bright as
+// it is reads as another pane rather than as something in front.
+//
+// It is the shader pass aimed at the whole screen, so the same caveat applies
+// as for shaders: cells with no colour of their own are resolved through
+// theme's default_fg/default_bg first, and if those do not match your
+// terminal's real colours the screen will shift slightly while a modal is up.
+modal_scrim 120
+
// Extra shaders can be loaded from shared libraries: any `*.so` in the
// directory below that exports a sl0ppty shader plugin. Once loaded they are
// named here exactly like a built-in. Default: a `shaders` directory beside
@@ -382,6 +392,19 @@ theme {
minbar "#45454a"
minbar_hover "#ff5fd7"
+ // ── modals: a surface that floats over the layout ───────────────────────
+ // Named apart from the pane colours they resemble because a modal is a
+ // different surface: opaque, on top of everything, and legible against a
+ // background that has been dimmed underneath it. (The first version drew
+ // the close button in the pane button colour on the finder background,
+ // which are the same value — an invisible button until you hovered it.)
+ modal_bg "#1c1c22" // a shade lighter than the dimmed screen
+ modal_fg "#e8e8ea"
+ modal_border "#ff5fd7"
+ modal_title "#ffffff"
+ modal_button "#8a8a95" // visible *without* the pointer on it
+ modal_button_hover "#ff5fd7"
+
// ── the pane finder ─────────────────────────────────────────────────────
finder_fg "#ffffff"
finder_bg "#45454a"
diff --git a/contrib/themes/amber.kdl b/contrib/themes/amber.kdl
index b4d6849..1f9b7d4 100644
--- a/contrib/themes/amber.kdl
+++ b/contrib/themes/amber.kdl
@@ -64,4 +64,12 @@ theme {
pane_button_hover "#ffb000"
minbar "#6b4a00"
minbar_hover "#ffb000"
+
+ // a modal floating over the layout (the cheatsheet, C-a ?)
+ modal_bg "#1e1200"
+ modal_fg "#ffe0a0"
+ modal_border "#ffb000"
+ modal_title "#fff2d6"
+ modal_button "#9a7526"
+ modal_button_hover "#ffb000"
}
diff --git a/contrib/themes/mono.kdl b/contrib/themes/mono.kdl
index 2a478d5..28469cd 100644
--- a/contrib/themes/mono.kdl
+++ b/contrib/themes/mono.kdl
@@ -64,4 +64,12 @@ theme {
pane_button_hover "#e4e4e4"
minbar "#585858"
minbar_hover "#e4e4e4"
+
+ // a modal floating over the layout (the cheatsheet, C-a ?)
+ modal_bg "#1a1a1a"
+ modal_fg "#e4e4e4"
+ modal_border "#e4e4e4"
+ modal_title "#ffffff"
+ modal_button "#9a9a9a"
+ modal_button_hover "#ffffff"
}
diff --git a/contrib/themes/paper.kdl b/contrib/themes/paper.kdl
index e24fb44..82fc5b3 100644
--- a/contrib/themes/paper.kdl
+++ b/contrib/themes/paper.kdl
@@ -64,4 +64,12 @@ theme {
pane_button_hover "#0057b8"
minbar "#9aa0a6"
minbar_hover "#0057b8"
+
+ // a modal floating over the layout (the cheatsheet, C-a ?)
+ modal_bg "#f2f2ee"
+ modal_fg "#1a1a1a"
+ modal_border "#0057b8"
+ modal_title "#000000"
+ modal_button "#6b7178"
+ modal_button_hover "#0057b8"
}
diff --git a/contrib/themes/phosphor.kdl b/contrib/themes/phosphor.kdl
index d27529b..e992dfb 100644
--- a/contrib/themes/phosphor.kdl
+++ b/contrib/themes/phosphor.kdl
@@ -64,4 +64,12 @@ theme {
pane_button_hover "#33ff66"
minbar "#1f5b32"
minbar_hover "#33ff66"
+
+ // a modal floating over the layout (the cheatsheet, C-a ?)
+ modal_bg "#08160d"
+ modal_fg "#b9ffcc"
+ modal_border "#33ff66"
+ modal_title "#e6ffee"
+ modal_button "#4f8f63"
+ modal_button_hover "#33ff66"
}
diff --git a/contrib/themes/sl0p.kdl b/contrib/themes/sl0p.kdl
index 19c9dee..304f21a 100644
--- a/contrib/themes/sl0p.kdl
+++ b/contrib/themes/sl0p.kdl
@@ -64,4 +64,12 @@ theme {
pane_button_hover "#ff5fd7"
minbar "#45454a"
minbar_hover "#ff5fd7"
+
+ // a modal floating over the layout (the cheatsheet, C-a ?)
+ modal_bg "#1c1c22"
+ modal_fg "#e8e8ea"
+ modal_border "#ff5fd7"
+ modal_title "#ffffff"
+ modal_button "#8a8a95"
+ modal_button_hover "#ff5fd7"
}
diff --git a/contrib/themes/slate.kdl b/contrib/themes/slate.kdl
index eccf8af..9e19792 100644
--- a/contrib/themes/slate.kdl
+++ b/contrib/themes/slate.kdl
@@ -64,4 +64,12 @@ theme {
pane_button_hover "#7aa2f7"
minbar "#3b4261"
minbar_hover "#7aa2f7"
+
+ // a modal floating over the layout (the cheatsheet, C-a ?)
+ modal_bg "#1f2130"
+ modal_fg "#c0caf5"
+ modal_border "#7aa2f7"
+ modal_title "#ffffff"
+ modal_button "#6b7394"
+ modal_button_hover "#7aa2f7"
}
diff --git a/src/app.c b/src/app.c
index ab2e425..213dc53 100644
--- a/src/app.c
+++ b/src/app.c
@@ -99,6 +99,12 @@ bool app_reload_config(char *err, size_t errcap) {
#define MINBAR_HOVER (CFG.minbar_hover)
#define HINT_C (CFG.hint)
#define DEAD_C (CFG.dead)
+#define MODAL_FG (CFG.modal_fg)
+#define MODAL_BG (CFG.modal_bg)
+#define MODAL_BORDER (CFG.modal_border)
+#define MODAL_TITLE (CFG.modal_title)
+#define MODAL_BTN (CFG.modal_button)
+#define MODAL_BTN_HOVER (CFG.modal_button_hover)
static const color_t NO_COLOR = {0};
@@ -3052,6 +3058,90 @@ static size_t help_rows(help_row_t *out, size_t cap) {
return n;
}
+/* ---- modals -------------------------------------------------------------
+ *
+ * A surface that floats over the layout: everything behind it is pushed back,
+ * it is opaque, it wears a pane's frame so it plainly belongs to this program,
+ * and it owns the topmost hits while it is up. The cheatsheet is the first
+ * one; the shape is here rather than inside it so the second one costs a
+ * function call and looks the same.
+ */
+
+/* Push the whole screen back, so what floats reads as being in front.
+ *
+ * This is the shader pass, aimed at the screen instead of a pane: the same
+ * dim, the same materialisation of "terminal default" colours (without which
+ * the chrome would not darken at all, since most of it has no colour of its
+ * own). Nothing about it is special-cased, which is the nice part -- a scrim
+ * is just a colour pass with everything in its rect. */
+static void draw_scrim(app_t *a, screen_t *s) {
+ if (!CFG.modal_scrim) return;
+ shader_t dim;
+ if (!shader_make(&dim, "dim", (color_t){0}, CFG.modal_scrim)) return;
+ shade_ctx_t base = {
+ .now_ms = now_ms_(),
+ .default_fg = CFG.default_fg,
+ .default_bg = CFG.default_bg,
+ };
+ shade_apply(s, &dim, 1, 0, 0, s->cols, s->rows, &base);
+}
+
+/* The frame every modal wears: an opaque box with a pane's corners, a title
+ * in the top rule and a close button where a pane keeps one. Returns the rect
+ * *inside* it, which is all a caller should care about. */
+static rect_t modal_frame(app_t *a, screen_t *s, uint16_t w, uint16_t h,
+ const char *title, const char *close_action) {
+ if (w > s->cols) w = s->cols;
+ if (h > s->rows) h = s->rows;
+ uint16_t x = (uint16_t)((s->cols - w) / 2), y = (uint16_t)((s->rows - h) / 2);
+ uint16_t x1 = (uint16_t)(x + w - 1), y1 = (uint16_t)(y + h - 1);
+
+ /* Opaque, or the panes underneath read through it: a modal you can see a
+ * shell prompt through is a modal nobody trusts. */
+ for (uint16_t yy = y; yy < y + h; yy++)
+ for (uint16_t xx = x; xx < x + w; xx++)
+ screen_text(s, xx, yy, " ", NO_COLOR, MODAL_BG, 0);
+
+ const char *tl = CFG.rounded ? "\u256d" : "\u250c", *tr = CFG.rounded ? "\u256e" : "\u2510";
+ const char *bl = CFG.rounded ? "\u2570" : "\u2514", *br = CFG.rounded ? "\u256f" : "\u2518";
+ screen_text(s, x, y, tl, MODAL_BORDER, MODAL_BG, 0);
+ screen_text(s, x1, y, tr, MODAL_BORDER, MODAL_BG, 0);
+ screen_text(s, x, y1, bl, MODAL_BORDER, MODAL_BG, 0);
+ screen_text(s, x1, y1, br, MODAL_BORDER, MODAL_BG, 0);
+ for (uint16_t xx = (uint16_t)(x + 1); xx < x1; xx++) {
+ screen_text(s, xx, y, "\u2500", MODAL_BORDER, MODAL_BG, 0);
+ screen_text(s, xx, y1, "\u2500", MODAL_BORDER, MODAL_BG, 0);
+ }
+ for (uint16_t yy = (uint16_t)(y + 1); yy < y1; yy++) {
+ screen_text(s, x, yy, "\u2502", MODAL_BORDER, MODAL_BG, 0);
+ screen_text(s, x1, yy, "\u2502", MODAL_BORDER, MODAL_BG, 0);
+ }
+
+ if (title && *title && w > cells(title) + 4) {
+ char buf[80];
+ snprintf(buf, sizeof buf, " %s ", title);
+ screen_text(s, (uint16_t)(x + (w - cells(buf)) / 2), y, buf, MODAL_TITLE,
+ MODAL_BG, ATTR_BOLD);
+ }
+
+ /* The close button a pane has, in the place a pane keeps it. Two cells of
+ * target for a one-cell mark, for the reason the frame's own buttons are
+ * three: a one-cell target is a thing you miss with a mouse. */
+ if (close_action && w > 10) {
+ uint16_t bw = (uint16_t)(cells(CFG.close_mark) + 1);
+ uint16_t bx = (uint16_t)(x1 - bw);
+ bool hot = ptr_on(a, bx, y, bw, 1);
+ char cell[24];
+ snprintf(cell, sizeof cell, "%s ", CFG.close_mark);
+ screen_text(s, bx, y, cell, hot ? MODAL_BTN_HOVER : MODAL_BTN, MODAL_BG,
+ hot ? ATTR_BOLD : 0);
+ hit_add(&s->hits, bx, y, bw, 1, close_action);
+ }
+
+ return (rect_t){(uint16_t)(x + 1), (uint16_t)(y + 1), (uint16_t)(w - 2),
+ (uint16_t)(h - 2)};
+}
+
/* Draw at most `limit` columns of `text`, cut on a character boundary.
*
* The box is clamped to the screen, so on a small terminal the rows are wider
@@ -3104,88 +3194,48 @@ static void draw_help(app_t *a, screen_t *s) {
}
uint16_t body = (uint16_t)(cw[0] + (two ? cw[1] + 4 : 0));
- uint16_t w = (uint16_t)(body + 6);
size_t left_n = two ? split : n, right_n = two ? n - split : 0;
uint16_t lines = (uint16_t)(left_n > right_n ? left_n : right_n);
- uint16_t h = (uint16_t)(lines + 6);
- if (w > s->cols) w = s->cols;
- if (h > s->rows) h = s->rows;
- uint16_t x = (uint16_t)((s->cols - w) / 2), y = (uint16_t)((s->rows - h) / 2);
- /* Opaque, or the panes underneath read through it: a modal that you can see
- * a shell prompt through is a modal nobody trusts. */
- for (uint16_t yy = y; yy < y + h; yy++)
- for (uint16_t xx = x; xx < x + w; xx++)
- screen_text(s, xx, yy, " ", NO_COLOR, FINDER_BG, 0);
-
- /* The same frame a pane wears, for the same reason a dialog wears the
- * window chrome of its platform: it belongs to this program. */
- const char *tl = CFG.rounded ? "\u256d" : "\u250c", *tr = CFG.rounded ? "\u256e" : "\u2510";
- const char *bl = CFG.rounded ? "\u2570" : "\u2514", *br = CFG.rounded ? "\u256f" : "\u2518";
- uint16_t x1 = (uint16_t)(x + w - 1), y1 = (uint16_t)(y + h - 1);
- screen_text(s, x, y, tl, FRAME_FOCUS, FINDER_BG, 0);
- screen_text(s, x1, y, tr, FRAME_FOCUS, FINDER_BG, 0);
- screen_text(s, x, y1, bl, FRAME_FOCUS, FINDER_BG, 0);
- screen_text(s, x1, y1, br, FRAME_FOCUS, FINDER_BG, 0);
- for (uint16_t xx = (uint16_t)(x + 1); xx < x1; xx++) {
- screen_text(s, xx, y, "\u2500", FRAME_FOCUS, FINDER_BG, 0);
- screen_text(s, xx, y1, "\u2500", FRAME_FOCUS, FINDER_BG, 0);
- }
- for (uint16_t yy = (uint16_t)(y + 1); yy < y1; yy++) {
- screen_text(s, x, yy, "\u2502", FRAME_FOCUS, FINDER_BG, 0);
- screen_text(s, x1, yy, "\u2502", FRAME_FOCUS, FINDER_BG, 0);
- }
-
- const char *title = " keys ";
- uint16_t tx = (uint16_t)(x + (w - cells(title)) / 2);
- screen_text(s, tx, y, title, TITLE_FOCUS, FINDER_BG, ATTR_BOLD);
-
- /* The close button a pane has, in the place a pane has it. */
- if (w > 10) {
- uint16_t bx = (uint16_t)(x1 - 2);
- bool hot = ptr_on(a, bx, y, 2, 1);
- screen_text(s, bx, y, CFG.close_mark, hot ? PANE_BTN_HOVER : PANE_BTN,
- FINDER_BG, hot ? ATTR_BOLD : 0);
- hit_add(&s->hits, bx, y, 2, 1, "closehelp");
- }
+ rect_t in = modal_frame(a, s, (uint16_t)(body + 6), (uint16_t)(lines + 6),
+ "keys", "closehelp");
+ uint16_t x1 = (uint16_t)(in.x + in.w); /* the right border */
/* Everything here is prefix-then-key, and saying so once beats repeating
* the prefix on thirty rows. */
- char lead[80];
- char pfx[24];
+ char lead[80], pfx[24];
config_chord_name(CFG.prefix_key, CFG.prefix_mods, pfx, sizeof pfx);
snprintf(lead, sizeof lead, "%s then:", pfx);
- help_text(s, (uint16_t)(x + 3), (uint16_t)(y + 2), lead,
- (uint16_t)(w > 6 ? w - 6 : 0), HINT_C, FINDER_BG, 0);
+ help_text(s, (uint16_t)(in.x + 2), (uint16_t)(in.y + 1), lead, in.w, HINT_C,
+ MODAL_BG, 0);
for (size_t i = 0; i < n; i++) {
bool right = two && i >= split;
size_t row = right ? i - split : i;
- if ((uint16_t)(row + 4) >= h - 1) continue;
- uint16_t rx = (uint16_t)(x + 3 + (right ? cw[0] + 4 : 0));
- uint16_t ry = (uint16_t)(y + 4 + row);
+ uint16_t ry = (uint16_t)(in.y + 3 + row);
+ if (ry >= in.y + in.h) continue;
+ uint16_t rx = (uint16_t)(in.x + 2 + (right ? cw[0] + 4 : 0));
/* Everything is cut at the frame, and the left column additionally at the
* right one, so a clamped box loses words rather than its border. */
- uint16_t room = (uint16_t)(x1 > rx + 1 ? x1 - rx - 1 : 0);
- if (two && !right && cw[0] + 4 < room) room = (uint16_t)(cw[0] + 2);
+ uint16_t room = (uint16_t)(x1 > rx ? x1 - rx : 0);
+ if (two && !right && cw[0] + 2 < room) room = (uint16_t)(cw[0] + 2);
if (!rows[i].group) {
- help_text(s, rx, ry, rows[i].label, room, TITLE_FOCUS, FINDER_BG,
+ help_text(s, rx, ry, rows[i].label, room, MODAL_TITLE, MODAL_BG,
ATTR_BOLD);
continue;
}
- help_text(s, rx, ry, rows[i].chord, room, TITLE_FOCUS, FINDER_BG, 0);
+ help_text(s, rx, ry, rows[i].chord, room, MODAL_TITLE, MODAL_BG, 0);
uint16_t lx = (uint16_t)(rx + kw[right ? 1 : 0] + 2);
- help_text(s, lx, ry, rows[i].label,
- (uint16_t)(x1 > lx + 1 ? x1 - lx - 1 : 0), FINDER_FG, FINDER_BG,
- 0);
+ help_text(s, lx, ry, rows[i].label, (uint16_t)(x1 > lx ? x1 - lx : 0),
+ MODAL_FG, MODAL_BG, 0);
}
const char *foot = " any key closes this ";
- if (w > cells(foot) + 4)
- screen_text(s, (uint16_t)(x + (w - cells(foot)) / 2), y1, foot, HINT_C,
- FINDER_BG, 0);
+ if (in.w > cells(foot))
+ screen_text(s, (uint16_t)(in.x + (in.w - cells(foot)) / 2),
+ (uint16_t)(in.y + in.h), foot, HINT_C, MODAL_BG, 0);
}
static void draw_finder(app_t *a, screen_t *s) {
@@ -3384,8 +3434,13 @@ void app_compose(app_t *a, screen_t *s) {
draw_status_line(a, s);
if (a->finder) draw_finder(a, s); /* painted last, so its hits win */
/* And the modal on top of even that: it is the only thing that can be
- * interacted with while it is up, so it owns the topmost hits. */
- if (a->help) draw_help(a, s);
+ * interacted with while it is up, so it owns the topmost hits. The scrim
+ * goes down first, over everything already painted — including the finder,
+ * if that happened to be open. */
+ if (a->help) {
+ draw_scrim(a, s);
+ draw_help(a, s);
+ }
draw_toasts(a, s); /* and above even that: it is transient */
}
diff --git a/src/config.c b/src/config.c
index 4406443..bdff0a6 100644
--- a/src/config.c
+++ b/src/config.c
@@ -222,6 +222,7 @@ void config_defaults(config_t *c) {
c->toast_ms = 2500;
c->hover_delay_ms = 250;
c->double_click_ms = 400;
+ c->modal_scrim = 120;
c->status_bar = true;
c->status_line = true;
/* Deliberately wider than the panes' own margin (gap * gap_aspect = 2), so
@@ -327,6 +328,18 @@ void config_defaults(config_t *c) {
c->bell = accent;
c->dead = rgb(0xff, 0x87, 0x5f);
+
+ /* A surface, not a hole: lighter than the dimmed screen behind it, with a
+ * border in the accent so the edge is never in doubt. The button is a grey
+ * that is *visible* on that surface — the first version used the pane
+ * button colour, which is the same value as the old background it was drawn
+ * on, so it only appeared when you hovered it. */
+ c->modal_bg = rgb(0x1c, 0x1c, 0x22);
+ c->modal_fg = rgb(0xe8, 0xe8, 0xea);
+ c->modal_border = accent;
+ c->modal_title = bright;
+ c->modal_button = rgb(0x8a, 0x8a, 0x95);
+ c->modal_button_hover = accent;
c->hint = bright;
c->minbar = dim;
c->minbar_hover = accent;
@@ -618,6 +631,10 @@ bool config_load(config_t *c, const char *path, char *err, size_t errcap) {
c->hover_delay_ms);
c->double_click_ms = (uint16_t)kdl_arg_int(kdl_child(root, "double_click_ms"),
0, c->double_click_ms);
+ {
+ long v = kdl_arg_int(kdl_child(root, "modal_scrim"), 0, c->modal_scrim);
+ c->modal_scrim = (uint8_t)(v < 0 ? 0 : v > 255 ? 255 : v);
+ }
const char *sh = kdl_arg(kdl_child(root, "shell"), 0, NULL);
@@ -719,6 +736,12 @@ bool config_load(config_t *c, const char *path, char *err, size_t errcap) {
{"finder_sel_fg", &c->finder_sel_fg},
{"finder_sel_bg", &c->finder_sel_bg},
{"bell", &c->bell},
+ {"modal_fg", &c->modal_fg},
+ {"modal_bg", &c->modal_bg},
+ {"modal_border", &c->modal_border},
+ {"modal_title", &c->modal_title},
+ {"modal_button", &c->modal_button},
+ {"modal_button_hover", &c->modal_button_hover},
{"dead", &c->dead},
{"hint", &c->hint},
{"minbar", &c->minbar},
diff --git a/src/config.h b/src/config.h
index 6dd470d..889c16b 100644
--- a/src/config.h
+++ b/src/config.h
@@ -126,6 +126,10 @@ typedef struct {
uint16_t toast_ms;
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 */
uint16_t double_click_ms; /* how close two clicks must be to be a double */
+ /* How far everything behind a modal is pushed back, 0..255, 0 being off.
+ * A modal that floats over a screen as bright as it is reads as another
+ * pane rather than as something in front. */
+ uint8_t modal_scrim;
/* Shader strengths, 0..255, 0 being off. Ambient dimming is a taste and is
* off by default; the drag greying is transient and on. */
/* Colour passes every pane gets, in the order they were written. Ordinary
@@ -222,6 +226,16 @@ typedef struct {
/* the hint in the middle of the status line */
color_t hint;
+ /* Modals: a surface that floats over the layout, with its own frame. Named
+ * separately from the pane colours it resembles because it is a different
+ * *surface* — it sits on top of everything, it is opaque, and it has to
+ * stay legible against a background that has been dimmed underneath it.
+ * Borrowing the pane button colour here is what made the close button
+ * invisible: dim on dim. */
+ color_t modal_fg, modal_bg;
+ color_t modal_border, modal_title;
+ color_t modal_button, modal_button_hover;
+
/* announcements */
color_t toast_fg, toast_bg;
diff --git a/tests/test_help.py b/tests/test_help.py
index c070ac5..b121284 100644
--- a/tests/test_help.py
+++ b/tests/test_help.py
@@ -48,6 +48,82 @@ def test_it_opens_and_lists_the_bindings():
check("shows arrows as arrows", "←" in screen and "→" in screen, screen)
+def style(snap, x, y):
+ run = snap.style_at(x, y)
+ return (run or {}).get("fg"), (run or {}).get("bg")
+
+
+def modal_top(snap):
+ for y, line in enumerate(snap.text):
+ if "keys" in line and "\u256d" in line:
+ return y, line
+ return None, None
+
+
+def test_the_close_button_can_be_seen_without_hovering_it():
+ """It was drawn in the pane button colour on the finder background, which
+ are the same value: invisible until the pointer happened to land on it."""
+ with Session(SH, cols=92, rows=28) as s:
+ s.settle()
+ snap = open_help(s)
+ y, line = modal_top(snap)
+ check("the modal has a top border", y is not None, snap.screen())
+ x = line.rindex("x")
+ fg, bg = style(snap, x, y)
+ check("the close button is not its own background", fg != bg,
+ f"fg {fg} bg {bg}")
+ check("and it is registered as a target",
+ snap.hit_at(x, y) == "closehelp", str(snap.hit_at(x, y)))
+
+
+def test_the_close_button_closes_it():
+ with Session(SH, cols=92, rows=28) as s:
+ s.settle()
+ snap = open_help(s)
+ y, line = modal_top(snap)
+ s.click(line.rindex("x"), y)
+ s.settle()
+ check("clicking the button puts it away",
+ "split into columns" not in s.snapshot().screen())
+
+
+def test_what_is_behind_is_pushed_back():
+ with Session(SH, cols=100, rows=30) as s:
+ s.settle()
+ before = s.snapshot()
+ pos = before.find("pane 1/1")
+ check("the status line is there", pos is not None, before.screen())
+ x, y = pos[0] + 1, pos[1]
+ lit = style(before, x, y)
+
+ after = open_help(s)
+ dimmed = style(after, x, y)
+ check("the screen behind the modal is dimmed", dimmed != lit,
+ f"{lit} -> {dimmed}")
+
+ # And the modal itself is not: it is drawn after the scrim, which is
+ # the whole point of the ordering. Sampled on the title rather than on
+ # a corner, because the modal's top row can sit on a pane's border row
+ # and then the line has two of those.
+ my, line = modal_top(after)
+ tx = line.index("keys")
+ check("the modal is not dimmed with it",
+ style(after, tx, my)[0] == "#ffffff", str(style(after, tx, my)))
+
+
+def test_the_scrim_can_be_turned_off():
+ conf = cfg("modal_scrim 0\n")
+ with Session(SH, cols=100, rows=30, config=conf) as s:
+ s.settle()
+ before = s.snapshot()
+ x, y = before.find("pane 1/1")[0] + 1, before.find("pane 1/1")[1]
+ lit = style(before, x, y)
+ after = open_help(s)
+ check("nothing behind it changes", style(after, x, y) == lit,
+ f"{lit} -> {style(after, x, y)}")
+ check("but the modal is still up", "split into columns" in after.screen())
+
+
def test_any_key_dismisses_it_and_does_nothing_else():
with Session(SH, cols=92, rows=28) as s:
s.settle()