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

git pushed a commit to branch tymux-10-quiet-head
in repository terminology.

View the commit online.

commit 6d7ba1cdafa67648e86103ec5dad7c3d69e7e985
Author: Boris Faure <[email protected]>
AuthorDate: Sat Nov 14 10:23:25 2026 +0000

    termio: stop the cursor blink after a while without a key press
    
    The default theme animates the cursor blink, and while a terminal has
    the focus that animation redraws the canvas about 16 times a second,
    even when nothing else happens: an idle focused terminal never stops
    rendering.
    
    Stop the blink once cursor_blink_timeout seconds have passed without a
    key press, 10 by default as GTK does, and start it again on the next
    key press or focus in. 0 keeps the blink forever. Output does not
    count as activity: a cursor moved by a program stays solid, which is
    what one wants to watch anyway.
    
    The cursor is stopped with focus,out then focus,in,noblink, as a
    cursor shape change already does, so every theme supporting a steady
    cursor works unchanged. A shape change from an application does not
    restart the countdown, or a program sending DECSCUSR would keep the
    cursor blinking.
---
 src/bin/config.c           | 62 +++++++++++++++++++++++++++++++++--
 src/bin/config.h           |  1 +
 src/bin/options_behavior.c | 46 ++++++++++++++++++++++++++
 src/bin/termio.c           | 82 +++++++++++++++++++++++++++++++++++++++++++---
 src/bin/termiointernals.c  | 25 ++++++++++++++
 src/bin/termiointernals.h  |  8 +++++
 src/bin/tytest.c           |  2 ++
 src/bin/unit_tests.h       |  2 ++
 8 files changed, 221 insertions(+), 7 deletions(-)

diff --git a/src/bin/config.c b/src/bin/config.c
index b40293c4..be6d8902 100644
--- a/src/bin/config.c
+++ b/src/bin/config.c
@@ -7,7 +7,7 @@
 #include "colors.h"
 #include "theme.h"
 
-#define CONF_VER 33
+#define CONF_VER 34
 #define CONFIG_KEY "config"
 
 #define LIM(v, min, max) {if (v >= max) v = max; else if (v <= min) v = min;}
@@ -155,6 +155,9 @@ config_init(void)
      (edd_base, Config, "flicker_on_key", flicker_on_key, EET_T_UCHAR);
    EET_DATA_DESCRIPTOR_ADD_BASIC
      (edd_base, Config, "disable_cursor_blink", disable_cursor_blink, EET_T_UCHAR);
+   EET_DATA_DESCRIPTOR_ADD_BASIC
+     (edd_base, Config, "cursor_blink_timeout", cursor_blink_timeout,
+      EET_T_INT);
    EET_DATA_DESCRIPTOR_ADD_BASIC
      (edd_base, Config, "cursor_shape", cursor_shape, EET_T_INT);
    EET_DATA_DESCRIPTOR_ADD_BASIC
@@ -336,6 +339,7 @@ config_sync(const Config *config_src, Config *config)
    config->jump_on_change = config_src->jump_on_change;
    config->flicker_on_key = config_src->flicker_on_key;
    config->disable_cursor_blink = config_src->disable_cursor_blink;
+   config->cursor_blink_timeout = config_src->cursor_blink_timeout;
    config->cursor_shape = config_src->cursor_shape;
    config->disable_visual_bell = config_src->disable_visual_bell;
    config->bell_rings = config_src->bell_rings;
@@ -620,6 +624,7 @@ config_new(void)
         config->jump_on_keypress = EINA_TRUE;
         config->flicker_on_key = EINA_FALSE;
         config->disable_cursor_blink = EINA_FALSE;
+        config->cursor_blink_timeout = 10;
         config->cursor_shape = CURSOR_SHAPE_BLOCK;
         config->disable_visual_bell = EINA_FALSE;
         config->bell_rings = EINA_TRUE;
@@ -897,7 +902,11 @@ config_load(void)
                   config->notification_escapes = EINA_TRUE;
                   EINA_FALLTHROUGH;
                   /*pass through*/
-                case CONF_VER: /* 33 */
+                case 33:
+                  config->cursor_blink_timeout = 10;
+                  EINA_FALLTHROUGH;
+                  /*pass through*/
+                case CONF_VER: /* 34 */
                   /* selection_escapes used to gate reads too; a config
                    * with it off must not start answering read queries
                    * through the new ask default */
@@ -977,6 +986,7 @@ config_fork(const Config *config)
    CPY(jump_on_keypress);
    CPY(flicker_on_key);
    CPY(disable_cursor_blink);
+   CPY(cursor_blink_timeout);
    CPY(cursor_shape);
    CPY(disable_visual_bell);
    CPY(bell_rings);
@@ -1109,4 +1119,52 @@ tytest_config_erase_is_del_upgrade(void)
    free(saved_home);
    return 0;
 }
+
+static int
+_config_cursor_blink_timeout_after_reload(int version, int timeout)
+{
+   Config *config = config_new();
+   int reloaded;
+
+   config->version = version;
+   config->cursor_blink_timeout = timeout;
+   config_save(config);
+   config_del(config);
+
+   config = config_load();
+   assert(config->version == CONF_VER);
+   reloaded = config->cursor_blink_timeout;
+   config_del(config);
+   return reloaded;
+}
+
+int
+tytest_config_cursor_blink_timeout_upgrade(void)
+{
+   char dir[] = "/tmp/tytest-config-XXXXXX";
+   const char *old_home = getenv("XDG_CONFIG_HOME");
+   char *saved_home = old_home ? strdup(old_home) : NULL;
+   Config *config;
+
+   assert(mkdtemp(dir));
+   setenv("XDG_CONFIG_HOME", dir, 1);
+   config_init();
+
+   config = config_new();
+   assert(config->cursor_blink_timeout == 10);
+   config_del(config);
+   /* a config saved before the option existed has 0, blinking forever */
+   assert(_config_cursor_blink_timeout_after_reload(33, 0) == 10);
+   assert(_config_cursor_blink_timeout_after_reload(CONF_VER, 0) == 0);
+   assert(_config_cursor_blink_timeout_after_reload(CONF_VER, 25) == 25);
+
+   config_shutdown();
+   ecore_file_recursive_rm(dir);
+   if (saved_home)
+     setenv("XDG_CONFIG_HOME", saved_home, 1);
+   else
+     unsetenv("XDG_CONFIG_HOME");
+   free(saved_home);
+   return 0;
+}
 #endif
diff --git a/src/bin/config.h b/src/bin/config.h
index b4349f79..f6f6e1e8 100644
--- a/src/bin/config.h
+++ b/src/bin/config.h
@@ -91,6 +91,7 @@ struct tag_Config
    Eina_Bool         jump_on_change;
    Eina_Bool         flicker_on_key;
    Eina_Bool         disable_cursor_blink;
+   int               cursor_blink_timeout; /* seconds, 0 to never stop */
    int               cursor_shape;
    Eina_Bool         disable_visual_bell;
    Eina_Bool         bell_rings;
diff --git a/src/bin/options_behavior.c b/src/bin/options_behavior.c
index 627472a9..543c90b4 100644
--- a/src/bin/options_behavior.c
+++ b/src/bin/options_behavior.c
@@ -19,6 +19,7 @@ typedef struct tag_Behavior_Ctx {
      Evas_Object *op_w;
      Evas_Object *op_h;
      Evas_Object *op_wh_current;
+     Evas_Object *op_blink_timeout;
      Evas_Object *backlock_label;
      char *backlog_msg;
 } Behavior_Ctx;
@@ -307,6 +308,8 @@ _cursors_changed_cb(void *data, Evas_Object *obj,
 
    config->disable_cursor_blink = value % 2;
    config->cursor_shape = value / 2;
+   elm_object_disabled_set(ctx->op_blink_timeout,
+                           config->disable_cursor_blink);
 
    termio_config_update(ctx->term);
    windows_update();
@@ -314,6 +317,48 @@ _cursors_changed_cb(void *data, Evas_Object *obj,
 }
 
 
+static void
+_cb_op_behavior_cursor_blink_timeout(void *data,
+                                     Evas_Object *obj,
+                                     void *_event EINA_UNUSED)
+{
+   Behavior_Ctx *ctx = data;
+   Config *config = ctx->config;
+
+   config->cursor_blink_timeout = (int) elm_spinner_value_get(obj);
+   termio_config_update(ctx->term);
+   windows_update();
+   config_save(config);
+}
+
+static void
+_add_cursor_blink_timeout_option(Evas_Object *bx,
+                                 Behavior_Ctx *ctx)
+{
+   Evas_Object *o;
+
+   o = elm_label_add(bx);
+   evas_object_size_hint_weight_set(o, 0.0, 0.0);
+   evas_object_size_hint_align_set(o, 0.0, 0.5);
+   elm_object_text_set(o, _("Stop blinking after this long without a key press:"));
+   elm_box_pack_end(bx, o);
+   evas_object_show(o);
+
+   ctx->op_blink_timeout = o = elm_spinner_add(bx);
+   elm_spinner_editable_set(o, EINA_TRUE);
+   elm_spinner_min_max_set(o, 0.0, 3600.0);
+   elm_spinner_label_format_set(o, _("%1.0f s"));
+   elm_spinner_special_value_add(o, 0.0, _("Never"));
+   elm_spinner_value_set(o, ctx->config->cursor_blink_timeout);
+   elm_object_disabled_set(o, ctx->config->disable_cursor_blink);
+   evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, 0.0);
+   evas_object_size_hint_align_set(o, EVAS_HINT_FILL, 0.5);
+   elm_box_pack_end(bx, o);
+   evas_object_show(o);
+   evas_object_smart_callback_add(o, "delay,changed",
+                                  _cb_op_behavior_cursor_blink_timeout, ctx);
+}
+
 static void
 _add_cursors_option(Evas_Object *bx,
                     Behavior_Ctx *ctx)
@@ -500,6 +545,7 @@ options_behavior(Evas_Object *opbox, Evas_Object *term)
    OPTIONS_SEPARATOR;
 
    _add_cursors_option(bx, ctx);
+   _add_cursor_blink_timeout_option(bx, ctx);
 
    OPTIONS_CX(_("React to key presses (typing sounds and animations)"), flicker_on_key, 0);
    if (!multisense_available)
diff --git a/src/bin/termio.c b/src/bin/termio.c
index bcaade4e..7f484981 100644
--- a/src/bin/termio.c
+++ b/src/bin/termio.c
@@ -865,6 +865,63 @@ termio_get_cursor(const Evas_Object *obj)
    return sd->cursor.obj;
 }
 
+static Eina_Bool
+_cursor_blinks(const Termio *sd)
+{
+   return !sd->config->disable_cursor_blink && !sd->cursor.blink_expired;
+}
+
+static double
+_cursor_blink_left(const Termio *sd)
+{
+   return termio_cursor_blink_left(sd->config->cursor_blink_timeout,
+                                   ecore_loop_time_get() - sd->cursor.last_key);
+}
+
+static Eina_Bool
+_cb_cursor_blink_timeout(void *data)
+{
+   Termio *sd = data;
+   double left = _cursor_blink_left(sd);
+
+   if (left > 0.0)
+     {
+        ecore_timer_interval_set(sd->cursor.blink_timer, left);
+        return ECORE_CALLBACK_RENEW;
+     }
+   sd->cursor.blink_timer = NULL;
+   if (left < 0.0)
+     return ECORE_CALLBACK_CANCEL;
+   sd->cursor.blink_expired = EINA_TRUE;
+   edje_object_signal_emit(sd->cursor.obj, "focus,out", "terminology");
+   edje_object_signal_emit(sd->cursor.obj, "focus,in,noblink", "terminology");
+   return ECORE_CALLBACK_CANCEL;
+}
+
+/* A key press only records its time: the timer, when it fires, waits for
+ * whatever is left since the last one. */
+static void
+_cursor_blink_timer_update(Termio *sd)
+{
+   double left = _cursor_blink_left(sd);
+
+   if (sd->cursor.blink_timer)
+     ecore_timer_del(sd->cursor.blink_timer);
+   sd->cursor.blink_timer = NULL;
+   if (_cursor_blinks(sd) && (left >= 0.0))
+     sd->cursor.blink_timer = ecore_timer_add(left, _cb_cursor_blink_timeout,
+                                              sd);
+}
+
+static void
+_cursor_blink_unfocus(Termio *sd)
+{
+   if (sd->cursor.blink_timer)
+     ecore_timer_del(sd->cursor.blink_timer);
+   sd->cursor.blink_timer = NULL;
+   sd->cursor.blink_expired = EINA_FALSE;
+}
+
 void
 termio_set_cursor_shape(Evas_Object *obj, Cursor_Shape shape)
 {
@@ -886,10 +943,11 @@ termio_set_cursor_shape(Evas_Object *obj, Cursor_Shape shape)
    if (term_is_focused(sd->term))
      {
         edje_object_signal_emit(sd->cursor.obj, "focus,out", "terminology");
-        if (sd->config->disable_cursor_blink)
-          edje_object_signal_emit(sd->cursor.obj, "focus,in,noblink", "terminology");
-        else
+        if (_cursor_blinks(sd))
           edje_object_signal_emit(sd->cursor.obj, "focus,in", "terminology");
+        else
+          edje_object_signal_emit(sd->cursor.obj, "focus,in,noblink", "terminology");
+        _cursor_blink_timer_update(sd);
      }
 }
 
@@ -2894,8 +2952,7 @@ _cursor_focus_signals_emit(Termio *sd, Eina_Bool focused)
    const char *signals[2];
    int i, n;
 
-   n = termio_cursor_focus_signals_get(focused,
-                                       !sd->config->disable_cursor_blink,
+   n = termio_cursor_focus_signals_get(focused, _cursor_blinks(sd),
                                        !sd->config->disable_focus_visuals,
                                        signals);
    for (i = 0; i < n; i++)
@@ -2908,7 +2965,10 @@ termio_focus_in(Evas_Object *termio)
    Termio *sd = evas_object_smart_data_get(termio);
    EINA_SAFETY_ON_NULL_RETURN(sd);
 
+   sd->cursor.blink_expired = EINA_FALSE;
+   sd->cursor.last_key = ecore_loop_time_get();
    _cursor_focus_signals_emit(sd, EINA_TRUE);
+   _cursor_blink_timer_update(sd);
    if (!sd->win) return;
    termpty_focus_report(sd->pty, EINA_TRUE);
 }
@@ -2919,6 +2979,7 @@ termio_focus_out(Evas_Object *termio)
    Termio *sd = evas_object_smart_data_get(termio);
    EINA_SAFETY_ON_NULL_RETURN(sd);
 
+   _cursor_blink_unfocus(sd);
    _cursor_focus_signals_emit(sd, EINA_FALSE);
    if (!sd->win) return;
    sd->pty->selection.last_click = 0;
@@ -3859,6 +3920,7 @@ _smart_del(Evas_Object *obj)
    if (sd->mouse_move_job) ecore_job_del(sd->mouse_move_job);
    if (sd->mouseover_delay) ecore_timer_del(sd->mouseover_delay);
    if (sd->progress_stale_timer) ecore_timer_del(sd->progress_stale_timer);
+   if (sd->cursor.blink_timer) ecore_timer_del(sd->cursor.blink_timer);
    eina_stringshare_del(sd->font.name);
    if (sd->pty) termpty_free(sd->pty);
    eina_stringshare_del(sd->link.string);
@@ -4762,5 +4824,15 @@ termio_key_down(Evas_Object *termio,
      }
    if (sd->config->flicker_on_key)
      edje_object_signal_emit(sd->cursor.obj, "key,down", "terminology");
+   sd->cursor.last_key = ecore_loop_time_get();
+   if (sd->cursor.blink_expired)
+     {
+        sd->cursor.blink_expired = EINA_FALSE;
+        if (_cursor_blinks(sd))
+          {
+             edje_object_signal_emit(sd->cursor.obj, "focus,in", "terminology");
+             _cursor_blink_timer_update(sd);
+          }
+     }
    ev->event_flags = EVAS_EVENT_FLAG_ON_HOLD;
 }
diff --git a/src/bin/termiointernals.c b/src/bin/termiointernals.c
index 4eca5292..8ae19fa5 100644
--- a/src/bin/termiointernals.c
+++ b/src/bin/termiointernals.c
@@ -2991,6 +2991,16 @@ termio_cursor_focus_signals_get(Eina_Bool focused, Eina_Bool blink,
    return 2;
 }
 
+double
+termio_cursor_blink_left(int timeout, double since_key)
+{
+   if (timeout <= 0)
+     return -1.0;
+   if (since_key >= timeout)
+     return 0.0;
+   return timeout - since_key;
+}
+
 #if defined(BINARY_TYTEST)
 int
 tytest_cursor_focus_signals(void)
@@ -3022,5 +3032,20 @@ tytest_cursor_focus_signals(void)
 
    return 0;
 }
+
+int
+tytest_cursor_blink_left(void)
+{
+   assert(termio_cursor_blink_left(0, 0.0) < 0.0);
+   assert(termio_cursor_blink_left(0, 3600.0) < 0.0);
+   assert(termio_cursor_blink_left(-5, 1.0) < 0.0);
+
+   assert(termio_cursor_blink_left(10, 0.0) == 10.0);
+   assert(termio_cursor_blink_left(10, 4.0) == 6.0);
+   assert(termio_cursor_blink_left(10, 9.5) == 0.5);
+   assert(termio_cursor_blink_left(10, 10.0) == 0.0);
+   assert(termio_cursor_blink_left(10, 25.0) == 0.0);
+   return 0;
+}
 #endif
 /* }}} */
diff --git a/src/bin/termiointernals.h b/src/bin/termiointernals.h
index a0d0b31e..438b0856 100644
--- a/src/bin/termiointernals.h
+++ b/src/bin/termiointernals.h
@@ -53,7 +53,10 @@ struct tag_Termio
       Evas_Object *obj;
       int x, y;
       Cursor_Shape shape;
+      Ecore_Timer *blink_timer;
+      double last_key;
       Eina_Bool force : 1;
+      Eina_Bool blink_expired : 1;
    } cursor;
    struct {
       int cx, cy;
@@ -201,4 +204,9 @@ int
 termio_cursor_focus_signals_get(Eina_Bool focused, Eina_Bool blink,
                                 Eina_Bool focus_visuals,
                                 const char *signals[2]);
+/* Seconds the cursor keeps blinking, since_key seconds after the last key
+ * press: 0 once it must stop, negative when timeout is 0, blinking
+ * forever. */
+double
+termio_cursor_blink_left(int timeout, double since_key);
 #endif
diff --git a/src/bin/tytest.c b/src/bin/tytest.c
index fbd2d770..a36082b0 100644
--- a/src/bin/tytest.c
+++ b/src/bin/tytest.c
@@ -43,6 +43,7 @@ static struct {
 #endif
        { "block_render_idle", tytest_block_render_idle},
        { "cursor_focus_signals", tytest_cursor_focus_signals},
+       { "cursor_blink_left", tytest_cursor_blink_left},
        { "block_row_shifts", tytest_block_row_shifts},
        { "block_region_scrolls", tytest_block_region_scrolls},
        { "sb_add", tytest_sb_add},
@@ -105,6 +106,7 @@ static struct {
        { "keyin_backspace", tytest_keyin_backspace},
        { "keyin_keypad", tytest_keyin_keypad},
        { "config_erase_is_del_upgrade", tytest_config_erase_is_del_upgrade},
+       { "config_cursor_blink_timeout_upgrade", tytest_config_cursor_blink_timeout_upgrade},
        { "vs16_regression_no_scroll", tytest_vs16_regression_no_scroll},
        { "vs16_bare_narrow", tytest_vs16_bare_narrow},
        { "vs16_widens_one_call", tytest_vs16_widens_one_call},
diff --git a/src/bin/unit_tests.h b/src/bin/unit_tests.h
index c2b66d40..6f7ea90d 100644
--- a/src/bin/unit_tests.h
+++ b/src/bin/unit_tests.h
@@ -16,6 +16,7 @@ int tytest_truecolor_render(void);
 #endif
 int tytest_block_render_idle(void);
 int tytest_cursor_focus_signals(void);
+int tytest_cursor_blink_left(void);
 int tytest_block_row_shifts(void);
 int tytest_block_region_scrolls(void);
 int tytest_sb_add(void);
@@ -105,3 +106,4 @@ int tytest_keyin_modify_other_keys_level1(void);
 int tytest_keyin_backspace(void);
 int tytest_keyin_keypad(void);
 int tytest_config_erase_is_del_upgrade(void);
+int tytest_config_cursor_blink_timeout_upgrade(void);

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

Reply via email to