This is an automated email from the git hooks/post-receive script.

git pushed a commit to branch master
in repository terminology.

View the commit online.

commit 06cc65352424f7a996db7d5672ef7759c455a1c1
Author: Boris Faure <[email protected]>
AuthorDate: Fri Nov 27 21:18:18 2026 +0000

    termpty: report the text area in pixels through TIOCSWINSZ
    
    Fill ws_xpixel/ws_ypixel with cols * cell_w by rows * cell_h instead of
    0: programs divide the pixel fields by ws_col/ws_row to get the cell
    size back (ioctl_tty(2), tmux/tty.c), so the value must be the text
    area, exactly divisible. The fields are unsigned shorts, so a product
    that does not fit is reported as 0 rather than truncated; the products
    are computed in int64_t because long is 32 bits on 32-bit targets.
    
    The cell size is stored when termio recomputes the font cell and pushed
    with the next termpty_resize(), so a zoom that changes the grid sends a
    single TIOCSWINSZ (and SIGWINCH) instead of two. termio_config_set()
    only flags the size: that path (theme and background changes) never
    changes the font, and font changes go through termio_config_update(),
    which forces the resize that flushes a pending winsize.
    
    Without a pixel size, tmux sends CSI 18 t / CSI 14 t on every resize
    and, getting no reply, holds a lone Escape for 500 ms for up to 5
    seconds (tmux/tty.c, tty-keys.c).
---
 src/bin/termio.c        |  8 +++-
 src/bin/termpty.c       | 98 ++++++++++++++++++++++++++++++++++++++++++++++---
 src/bin/termpty.h       |  8 +++-
 src/bin/tytest.c        |  1 +
 src/bin/tytest_common.c |  2 +
 src/bin/unit_tests.h    |  1 +
 6 files changed, 110 insertions(+), 8 deletions(-)

diff --git a/src/bin/termio.c b/src/bin/termio.c
index 7f484981..12406574 100644
--- a/src/bin/termio.c
+++ b/src/bin/termio.c
@@ -785,6 +785,8 @@ termio_config_update(Evas_Object *obj)
    if (h < 1) h = 1;
    sd->font.chw = w;
    sd->font.chh = h;
+   if (sd->pty)
+     termpty_cell_size_set(sd->pty, w, h);
 
    evas_object_geometry_get(obj, NULL, NULL, &ow, &oh);
    termio_set_cursor_shape(obj, sd->config->cursor_shape);
@@ -834,6 +836,9 @@ termio_config_set(Evas_Object *obj, Config *config)
    if (h < 1) h = 1;
    sd->font.chw = w;
    sd->font.chh = h;
+   /* NULL while termio_add() is still building the pty */
+   if (sd->pty)
+     termpty_cell_size_set(sd->pty, w, h);
 
    sd->cursor.force = EINA_TRUE;
    termio_set_cursor_shape(obj, sd->cursor.shape);
@@ -4775,7 +4780,8 @@ termio_add(Evas_Object *win, Config *config,
                        _smart_cb_drop, obj);
 
    window_id = elm_win_window_id_get(win);
-   sd->pty = termpty_new(cmd, login_shell, cd, w, h, config, title,
+   sd->pty = termpty_new(cmd, login_shell, cd, w, h,
+                         sd->font.chw, sd->font.chh, config, title,
                          window_id);
    if (!sd->pty)
      {
diff --git a/src/bin/termpty.c b/src/bin/termpty.c
index c3c952dc..1d10734d 100644
--- a/src/bin/termpty.c
+++ b/src/bin/termpty.c
@@ -28,6 +28,8 @@
 #include <string.h>
 #include <errno.h>
 #include <unistd.h>
+#include <limits.h>
+#include <stdint.h>
 #include <termios.h>
 #if defined (__sun) || defined (__sun__)
 # include <stropts.h>
@@ -235,15 +237,26 @@ termpty_handle_buf(Termpty *ty, const Eina_Unicode *codepoints, int len)
      }
 }
 
+/* text area in pixels (grid * cell size), 0 when out of ushort range */
+static void
+_pty_winsize_fill(const Termpty *ty, struct winsize *sz)
+{
+   int64_t xp = (int64_t)ty->w * ty->cell_w;
+   int64_t yp = (int64_t)ty->h * ty->cell_h;
+
+   sz->ws_col = ty->w;
+   sz->ws_row = ty->h;
+   sz->ws_xpixel = ((xp >= 0) && (xp <= USHRT_MAX)) ? xp : 0;
+   sz->ws_ypixel = ((yp >= 0) && (yp <= USHRT_MAX)) ? yp : 0;
+}
+
 static void
 _pty_size(Termpty *ty)
 {
    struct winsize sz;
 
-   sz.ws_col = ty->w;
-   sz.ws_row = ty->h;
-   sz.ws_xpixel = 0;
-   sz.ws_ypixel = 0;
+   _pty_winsize_fill(ty, &sz);
+   ty->winsize_pending = EINA_FALSE;
    if (ty->fd >= 0)
      if (ioctl(ty->fd, TIOCSWINSZ, &sz) < 0)
        ERR(_("Size set ioctl failed: %s"), strerror(errno));
@@ -534,7 +547,8 @@ _is_shell_valid(const char *cmd)
 
 Termpty *
 termpty_new(const char *cmd, Eina_Bool login_shell, const char *cd,
-            int w, int h, Config *config, const char *title,
+            int w, int h, int cell_w, int cell_h,
+            Config *config, const char *title,
             Ecore_Window window_id)
 {
    Termpty *ty;
@@ -551,6 +565,9 @@ termpty_new(const char *cmd, Eina_Bool login_shell, const char *cd,
    ty->config = config;
    ty->w = w;
    ty->h = h;
+   /* before the fork, so the first TIOCSWINSZ already carries it */
+   ty->cell_w = cell_w;
+   ty->cell_h = cell_h;
    ty->backsize = config->scrollback;
 
    ty->screen = calloc(1, sizeof(Termcell) * ty->w * ty->h);
@@ -1508,6 +1525,17 @@ _backlog_remove_latest_nolock(Termpty *ty)
    termpty_save_free(ty, ts);
 }
 
+void
+termpty_cell_size_set(Termpty *ty, int cell_w, int cell_h)
+{
+   if ((ty->cell_w == cell_w) && (ty->cell_h == cell_h))
+     return;
+   ty->cell_w = cell_w;
+   ty->cell_h = cell_h;
+   /* the winsize follows with the next termpty_resize() */
+   ty->winsize_pending = EINA_TRUE;
+}
+
 void
 termpty_resize(Termpty *ty, int new_w, int new_h)
 {
@@ -1519,7 +1547,13 @@ termpty_resize(Termpty *ty, int new_w, int new_h)
        effective_old_h;
    int altbuf = 0;
    struct screen_info new_si = {.screen = NULL};
-   if ((ty->w == new_w) && (ty->h == new_h)) return;
+   if ((ty->w == new_w) && (ty->h == new_h))
+     {
+        /* same grid, but a new cell size still changes the pixel fields */
+        if (ty->winsize_pending)
+          _pty_size(ty);
+        return;
+     }
 
    /* A resize invalidates any in-flight sync window; the app will re-bracket. */
    if (ty->sync_output.active)
@@ -2154,6 +2188,8 @@ _ty_test_init(Termpty *ty, int w, int h)
    memset(ty, 0, sizeof(*ty));
    ty->w = w;
    ty->h = h;
+   ty->cell_w = TY_CH_W;
+   ty->cell_h = TY_CH_H;
    ty->fd = -1;
    ty->slavefd = -1;
    ty->pid = -1;
@@ -3414,6 +3450,56 @@ tytest_decarm(void)
    return 0;
 }
 
+int
+tytest_pty_winsize(void)
+{
+   Termpty ty;
+   struct winsize sz;
+
+   _ty_test_init(&ty, 80, 24);
+
+   /* a new cell size waits for the next resize, even on the same grid */
+   termpty_cell_size_set(&ty, 9, 18);
+   assert(ty.winsize_pending);
+   termpty_resize(&ty, ty.w, ty.h);
+   assert(!ty.winsize_pending);
+   /* 80x24 grid, 9x18 cells */
+   _pty_winsize_fill(&ty, &sz);
+   assert(sz.ws_col == 80);
+   assert(sz.ws_row == 24);
+   assert(sz.ws_xpixel == 720);
+   assert(sz.ws_ypixel == 432);
+
+   /* the test cell size, 7x15 */
+   termpty_cell_size_set(&ty, TY_CH_W, TY_CH_H);
+   _pty_winsize_fill(&ty, &sz);
+   assert(sz.ws_xpixel == 560);
+   assert(sz.ws_ypixel == 360);
+
+   /* the fill follows the grid */
+   termpty_resize(&ty, 100, 30);
+   _pty_winsize_fill(&ty, &sz);
+   assert(sz.ws_xpixel == 700);
+   assert(sz.ws_ypixel == 450);
+
+   /* cell size not known yet: 0, as before */
+   termpty_cell_size_set(&ty, 0, 0);
+   _pty_winsize_fill(&ty, &sz);
+   assert(sz.ws_xpixel == 0);
+   assert(sz.ws_ypixel == 0);
+
+   /* a product that does not fit an unsigned short: 0, not truncated */
+   termpty_cell_size_set(&ty, 200, 200);
+   ty.w = 400;
+   ty.h = 400;
+   _pty_winsize_fill(&ty, &sz);
+   assert(sz.ws_xpixel == 0);
+   assert(sz.ws_ypixel == 0);
+
+   _ty_test_shutdown(&ty);
+   return 0;
+}
+
 int
 tytest_color_scheme_notify(void)
 {
diff --git a/src/bin/termpty.h b/src/bin/termpty.h
index bc8b67f5..f7271ab8 100644
--- a/src/bin/termpty.h
+++ b/src/bin/termpty.h
@@ -243,6 +243,9 @@ struct tag_Termpty
     * coordinates that maps to a line in the backlog */
    Backlog_Beacon backlog_beacon;
    int w, h;
+   /* size of one character cell in pixels, 0 until termio reports it */
+   int cell_w, cell_h;
+   Eina_Bool winsize_pending;
    int fd, slavefd;
    struct ty_sb write_buffer;
    struct {
@@ -401,7 +404,8 @@ void       termpty_init(void);
 void       termpty_shutdown(void);
 
 Termpty   *termpty_new(const char *cmd, Eina_Bool login_shell, const char *cd,
-                       int w, int h, Config *config, const char *title,
+                       int w, int h, int cell_w, int cell_h,
+                       Config *config, const char *title,
                        Ecore_Window window_id);
 void       termpty_free(Termpty *ty);
 void       termpty_sync_output_reset(Termpty *ty);
@@ -421,6 +425,8 @@ ssize_t         termpty_row_length(Termpty *ty, int y);
 void       termpty_write(Termpty *ty, const char *input, int len);
 
 void       termpty_resize(Termpty *ty, int new_w, int new_h);
+/* store the cell size in pixels; the winsize follows on the next resize */
+void       termpty_cell_size_set(Termpty *ty, int cell_w, int cell_h);
 void       termpty_resize_tabs(Termpty *ty, int old_w, int new_w);
 void       termpty_backscroll_adjust(Termpty *ty, int *scroll);
 
diff --git a/src/bin/tytest.c b/src/bin/tytest.c
index 453a1c0e..0d16208a 100644
--- a/src/bin/tytest.c
+++ b/src/bin/tytest.c
@@ -99,6 +99,7 @@ static struct {
        { "decrqm", tytest_decrqm},
        { "kam", tytest_kam},
        { "decarm", tytest_decarm},
+       { "pty_winsize", tytest_pty_winsize},
        { "color_scheme_notify", tytest_color_scheme_notify},
        { "kitty_kbd_query", tytest_kitty_kbd_query},
        { "kitty_kbd_stack", tytest_kitty_kbd_stack},
diff --git a/src/bin/tytest_common.c b/src/bin/tytest_common.c
index efbbf8d9..72a51cdc 100644
--- a/src/bin/tytest_common.c
+++ b/src/bin/tytest_common.c
@@ -760,6 +760,8 @@ _termpty_init(Termpty *ty, Config *config)
    ty->config = config;
    ty->w = TY_W;
    ty->h = TY_H;
+   ty->cell_w = TY_CH_W;
+   ty->cell_h = TY_CH_H;
    ty->backsize = TY_BACKSIZE;
    termpty_resize_tabs(ty, 0, ty->w);
    termpty_reset_state(ty);
diff --git a/src/bin/unit_tests.h b/src/bin/unit_tests.h
index 63bf70aa..0604f017 100644
--- a/src/bin/unit_tests.h
+++ b/src/bin/unit_tests.h
@@ -72,6 +72,7 @@ int tytest_decrqss_settings(void);
 int tytest_decrqm(void);
 int tytest_kam(void);
 int tytest_decarm(void);
+int tytest_pty_winsize(void);
 int tytest_color_scheme_notify(void);
 int tytest_kitty_kbd_query(void);
 int tytest_kitty_kbd_stack(void);

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.

Reply via email to