diff --git a/kitty/fast_data_types.pyi b/kitty/fast_data_types.pyi index 122bd5c1e..b8870a81a 100644 --- a/kitty/fast_data_types.pyi +++ b/kitty/fast_data_types.pyi @@ -1077,6 +1077,7 @@ class Screen: cursor_key_mode: bool auto_repeat_enabled: bool render_unfocused_cursor: bool + track_activity: bool last_reported_cwd: Optional[bytes] def __init__( diff --git a/kitty/screen.c b/kitty/screen.c index 2c8215458..92e34f623 100644 --- a/kitty/screen.c +++ b/kitty/screen.c @@ -161,6 +161,7 @@ new_screen_object(PyTypeObject *type, PyObject *args, PyObject UNUSED *kwds) { reset_vt_parser(self->vt_parser); self->callbacks = callbacks; Py_INCREF(callbacks); + self->track_activity = true; self->test_child = test_child; Py_INCREF(test_child); self->cursor = alloc_cursor(); @@ -1241,7 +1242,7 @@ draw_combining_char(Screen *self, text_loop_state *s, char_type ch) { static void screen_on_input(Screen *self) { - if (!self->has_activity_since_last_focus && !self->has_focus && self->callbacks != Py_None) { + if (self->track_activity && !self->has_activity_since_last_focus && !self->has_focus && self->callbacks != Py_None) { PyObject *ret = PyObject_CallMethod(self->callbacks, "on_activity_since_last_focus", NULL); if (ret == NULL) PyErr_Print(); else { @@ -7235,6 +7236,7 @@ static PyGetSetDef getsetters[] = { static PyMemberDef members[] = { {"callbacks", T_OBJECT_EX, offsetof(Screen, callbacks), 0, "callbacks"}, + {"track_activity", T_BOOL, offsetof(Screen, track_activity), 0, "track_activity"}, {"cursor", T_OBJECT_EX, offsetof(Screen, cursor), READONLY, "cursor"}, {"vt_parser", T_OBJECT_EX, offsetof(Screen, vt_parser), READONLY, "vt_parser"}, {"last_reported_cwd", T_OBJECT, offsetof(Screen, last_reported_cwd), READONLY, "last_reported_cwd"}, diff --git a/kitty/screen.h b/kitty/screen.h index 91dc924a2..262503380 100644 --- a/kitty/screen.h +++ b/kitty/screen.h @@ -160,6 +160,7 @@ typedef struct { bool has_focus; uint8_t visibility_state; // 0 = unknown, 1 = potentially visible, 2 = not visible bool has_activity_since_last_focus; + bool track_activity; hyperlink_id_type active_hyperlink_id; HYPERLINK_POOL_HANDLE hyperlink_pool; ANSIBuf as_ansi_buf; diff --git a/kitty/window.py b/kitty/window.py index 5d6812429..c0d352da5 100644 --- a/kitty/window.py +++ b/kitty/window.py @@ -812,6 +812,7 @@ class Window: cell_width, cell_height = cell_size_for_window(self.os_window_id) opts = get_options() self.screen: Screen = Screen(self, 24, 80, opts.scrollback_lines, cell_width, cell_height, self.id) + self.screen.track_activity = bool(opts.tab_activity_symbol) if copy_colors_from is not None: self.screen.copy_colors_from(copy_colors_from.screen) self.remote_control_passwords = remote_control_passwords @@ -901,6 +902,7 @@ class Window: def apply_options(self, is_active: bool) -> None: self.update_effective_padding() + self.screen.track_activity = bool(get_options().tab_activity_symbol) self.screen.color_profile.reload_from_opts() @property diff --git a/kitty_tests/screen.py b/kitty_tests/screen.py index 7e0ba1738..136b3d4c9 100644 --- a/kitty_tests/screen.py +++ b/kitty_tests/screen.py @@ -2259,6 +2259,18 @@ class TestScreen(BaseTest): sc(2, 1, 2, 3, slot=slot) sc(5, 13, slot=slot) + def test_activity_tracking(self): + s = self.create_screen() + calls = [] + s.callbacks.on_activity_since_last_focus = lambda: calls.append(1) or False + s.focus_changed(False) + s.track_activity = False + parse_bytes(s, b'\x1b[31ma\x1b[mb') + self.ae(len(calls), 0) + s.track_activity = True + parse_bytes(s, b'\x1b[31ma\x1b[mb') + self.ae(len(calls), 2) + def test_soft_reset(self): SOFT_RESET = b'\x1b[!p' # DECSTR sequence