aboutsummaryrefslogtreecommitdiffstats
path: root/src/app_layout.c
diff options
context:
space:
mode:
authoruser <user@clank>2026-09-29 14:26:18 +0200
committeruser <user@clank>2026-09-29 14:26:18 +0200
commit43fa063445821470cbf55f85aa8116c11470396f (patch)
tree1612fa68b3aa70bf75a9ec28a76cbd8d05f9264d /src/app_layout.c
parentpanes: $SLOSH_PANE, so a program knows which pane it is in (diff)
downloadslosh-43fa063445821470cbf55f85aa8116c11470396f.tar.gz
slosh-43fa063445821470cbf55f85aa8116c11470396f.tar.xz
slosh-43fa063445821470cbf55f85aa8116c11470396f.zip
panes: read and write a pane by id, without taking focus
`raw` wrote into the focused pane and `snapshot` composited the active tab, so driving a pane anywhere else meant focusing it or selecting its tab first. Both of those move the view of whoever is watching, and both lose to anybody doing the same thing at the same time. `raw` now takes an `id` (0 is the focused pane, as before), and `capture` answers one pane's viewport as text -- from the pane's own terminal, so it works for a pane in a background tab, changes no focus, and leaves the human's selection alone. It builds its selection as a snapshot rather than setting one on the terminal, because a read with a visible side effect is not a read. `capture` tells "no such pane" apart from "that pane is empty": a caller polling a dead id would otherwise wait forever on a pane that is quiet because it is gone.
Diffstat (limited to 'src/app_layout.c')
-rw-r--r--src/app_layout.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/app_layout.c b/src/app_layout.c
index 4de1bf3..7979b08 100644
--- a/src/app_layout.c
+++ b/src/app_layout.c
@@ -559,6 +559,31 @@ void app_write_focused(app_t *a, const void *buf, size_t len) {
if (cur(a)->focus) pane_write(cur(a)->focus->pane, buf, len);
}
+/* The same, into a pane named by id -- the one a caller can use without first
+ * stealing focus from whoever has it. `id` 0 means the focused pane, as
+ * everywhere. False when there is no such pane, so a script that names one
+ * that has gone hears about it instead of writing into a stranger's shell. */
+bool app_write_pane(app_t *a, uint32_t id, const void *buf, size_t len) {
+ if (!id) {
+ if (!cur(a)->focus) return false;
+ pane_write(cur(a)->focus->pane, buf, len);
+ return true;
+ }
+ node_t *n = pane_by_id(a, id);
+ if (!n || n->kind != NODE_LEAF) return false;
+ pane_write(n->pane, buf, len);
+ return true;
+}
+
+/* One pane's viewport as text, by id (0 = focused). NULL when there is no such
+ * pane or nothing to read; caller frees. Reads the pane's own terminal, so a
+ * pane in a tab nobody is looking at answers exactly as one on screen does. */
+char *app_pane_text(app_t *a, uint32_t id) {
+ node_t *n = id ? pane_by_id(a, id) : cur(a)->focus;
+ if (!n || n->kind != NODE_LEAF) return NULL;
+ return pane_viewport_text(n->pane);
+}
+
void app_resize(app_t *a, uint16_t cols, uint16_t rows) {
a->cols = cols;
a->rows = rows;
@@ -1174,6 +1199,13 @@ bool app_pane_floating(app_t *a, uint32_t id) {
return n && n->floating;
}
+/* Is there a pane with this id at all, in any tab. So a reply can tell "gone"
+ * apart from "empty", which are the same answer to a caller reading text. */
+bool app_pane_exists(app_t *a, uint32_t id) {
+ node_t *n = id ? pane_by_id(a, id) : (a->ntabs ? cur(a)->focus : NULL);
+ return n && n->kind == NODE_LEAF;
+}
+
/* Float a pane *at* a rect: the script's version of the drag. Already
* floating, it is re-placed without a toggle — a placement is a statement
* about where, not about whether — and the intent is kept exactly as asked