diff options
| author | Tim Culverhouse <tim@timculverhouse.com> | 2026-07-28 19:16:05 +0000 |
|---|---|---|
| committer | Daniel Eklöf <daniel@ekloef.se> | 2026-07-30 12:18:58 +0000 |
| commit | 8db88cceb758b5be23e7db1fe74a48102ab07dc0 (patch) | |
| tree | 2741b009de1520e2203d4b6695073422c77df738 | |
| parent | changelog: add missing bug reference (diff) | |
terminal: add visibility reports
Applications cannot infer whether their terminal view is observable from
keyboard focus alone, so they may continue expensive rendering while the
surface is hidden.
Implement private mode 2033 and the one-shot visibility query. Report
Wayland xdg_toplevel suspension as not visible and otherwise remain
conservative by treating the terminal as potentially visible.
Amp-Thread-ID: https://ampcode.com/threads/T-019fb2b7-f245-7124-a69a-1484812532bb
Co-authored-by: Amp <amp@ampcode.com>
| -rw-r--r-- | CHANGELOG.md | 3 | ||||
| -rw-r--r-- | csi.c | 13 | ||||
| -rw-r--r-- | doc/foot-ctlseqs.7.scd | 12 | ||||
| -rw-r--r-- | terminal.c | 9 | ||||
| -rw-r--r-- | terminal.h | 3 | ||||
| -rw-r--r-- | wayland.c | 8 | ||||
| -rw-r--r-- | wayland.h | 2 |
7 files changed, 49 insertions, 1 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 5e6723c8..6f3c05a7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -76,6 +76,9 @@ * Command line option `--class`, an alias for `--app-id`. Intended to be used by scripts and similar that wants to launch terminal instances in a terminal agnostic way ([#2368][2368]). +* Support for [terminal visibility + reports](https://rockorager.dev/misc/visibility-reports/), using the + Wayland `xdg_toplevel` suspended state. [2368]: https://codeberg.org/dnkl/foot/issues/2368 @@ -569,6 +569,12 @@ decset_decrst(struct terminal *term, unsigned param, bool enable) term->report_theme_changes = enable; break; + case 2033: + term->visibility_reports = enable; + if (enable) + term_send_visibility_report(term); + break; + case 2048: if (enable) term_enable_size_notifications(term); @@ -664,6 +670,7 @@ decrqm(const struct terminal *term, unsigned param) ? DECRPM_PERMANENTLY_RESET : decrpm(term->grapheme_shaping); case 2031: return decrpm(term->report_theme_changes); + case 2033: return decrpm(term->visibility_reports); case 2048: return decrpm(term->size_notifications); case 8452: return decrpm(term->sixel.cursor_right_of_graphics); case 737769: return decrpm(term_ime_is_enabled(term)); @@ -710,6 +717,7 @@ xtsave(struct terminal *term, unsigned param) case 2026: term->xtsave.app_sync_updates = term->render.app_sync_updates.enabled; break; case 2027: term->xtsave.grapheme_shaping = term->grapheme_shaping; break; case 2031: term->xtsave.report_theme_changes = term->report_theme_changes; break; + case 2033: term->xtsave.visibility_reports = term->visibility_reports; break; case 2048: term->xtsave.size_notifications = term->size_notifications; break; case 8452: term->xtsave.sixel_cursor_right_of_graphics = term->sixel.cursor_right_of_graphics; break; case 737769: term->xtsave.ime = term_ime_is_enabled(term); break; @@ -755,6 +763,7 @@ xtrestore(struct terminal *term, unsigned param) case 2026: enable = term->xtsave.app_sync_updates; break; case 2027: enable = term->xtsave.grapheme_shaping; break; case 2031: enable = term->xtsave.report_theme_changes; break; + case 2033: enable = term->xtsave.visibility_reports; break; case 2048: enable = term->xtsave.size_notifications; break; case 8452: enable = term->xtsave.sixel_cursor_right_of_graphics; break; case 737769: enable = term->xtsave.ime; break; @@ -1590,6 +1599,10 @@ csi_dispatch(struct terminal *term, uint8_t final) term_to_slave(term, reply, chars); break; } + + case 998: + term_send_visibility_report(term); + break; } break; } diff --git a/doc/foot-ctlseqs.7.scd b/doc/foot-ctlseqs.7.scd index 40906ebf..192628cd 100644 --- a/doc/foot-ctlseqs.7.scd +++ b/doc/foot-ctlseqs.7.scd @@ -340,6 +340,12 @@ that corresponds to one of the following modes: | 2031 : contour : Request color theme updates +| 2033 +: rockorager +: Request terminal visibility reports. Enabling this mode immediately reports + the current visibility as *CSI ? 999 ; 1|2 n*, where *1* means potentially + visible and *2* means not visible. Further reports are sent whenever the + visibility changes. | 2048 : TODO : In-band window resize notifications @@ -667,6 +673,12 @@ manipulation sequences. The generic format is: 997 ; 1|2 n*, where *1* means dark and *2* light. By convention, the primary theme in foot is considered dark, and the alternative theme light. +| \\E[ ? 998 n +: Query terminal visibility +: rockorager +: The current terminal visibility is reported as *CSI ? 999 ; 1|2 n*, where + *1* means potentially visible and *2* means not visible. This does not enable + private mode 2033. # OSC @@ -2110,6 +2110,7 @@ term_reset(struct terminal *term, bool hard) term->insert_mode = false; term->bracketed_paste = false; term->focus_events = false; + term->visibility_reports = false; term->num_lock_modifier = true; term->bell_action_enabled = true; term->mouse_tracking = MOUSE_NONE; @@ -3316,6 +3317,14 @@ term_visual_focus_out(struct terminal *term) } void +term_send_visibility_report(struct terminal *term) +{ + term_to_slave( + term, + !term->window->is_suspended ? "\033[?999;1n" : "\033[?999;2n", 9); +} + +void term_kbd_focus_in(struct terminal *term) { if (term->kbd_focus) @@ -439,6 +439,7 @@ struct terminal { bool reverse_wrap; bool bracketed_paste; bool focus_events; + bool visibility_reports; bool alt_scrolling; bool modify_other_keys_2; /* True when modifyOtherKeys=2 (i.e. "CSI >4;2m") */ enum cursor_origin origin; @@ -523,6 +524,7 @@ struct terminal { bool cursor_blink:1; bool bracketed_paste:1; bool focus_events:1; + bool visibility_reports:1; bool alt_scrolling:1; //bool mouse_x10:1; bool mouse_click:1; @@ -927,6 +929,7 @@ void term_restore_cursor(struct terminal *term, const struct cursor *cursor); void term_visual_focus_in(struct terminal *term); void term_visual_focus_out(struct terminal *term); +void term_send_visibility_report(struct terminal *term); void term_kbd_focus_in(struct terminal *term); void term_kbd_focus_out(struct terminal *term); void term_mouse_down( @@ -871,7 +871,7 @@ xdg_toplevel_configure(void *data, struct xdg_toplevel *xdg_toplevel, bool is_constrained_bottom = false; bool is_constrained_left = false; bool is_constrained_right = false; - bool is_suspended UNUSED = false; + bool is_suspended = false; #if defined(LOG_ENABLE_DBG) && LOG_ENABLE_DBG char state_str[2048]; @@ -951,6 +951,7 @@ xdg_toplevel_configure(void *data, struct xdg_toplevel *xdg_toplevel, struct wl_window *win = data; win->configure.is_activated = is_activated; + win->configure.is_suspended = is_suspended; win->configure.is_fullscreen = is_fullscreen; win->configure.is_maximized = is_maximized; win->configure.is_resizing = is_resizing; @@ -1078,6 +1079,7 @@ xdg_surface_configure(void *data, struct xdg_surface *xdg_surface, bool wasnt_configured = !win->is_configured; bool was_resizing = win->is_resizing; bool was_fullscreen = win->is_fullscreen; + bool was_suspended = win->is_suspended; bool csd_was_enabled = win->csd_mode == CSD_YES && !win->is_fullscreen; int new_width = win->configure.width; int new_height = win->configure.height; @@ -1086,6 +1088,7 @@ xdg_surface_configure(void *data, struct xdg_surface *xdg_surface, win->is_maximized = win->configure.is_maximized; win->is_fullscreen = win->configure.is_fullscreen; win->is_resizing = win->configure.is_resizing; + win->is_suspended = win->configure.is_suspended; win->is_tiled_top = win->configure.is_tiled_top; win->is_tiled_bottom = win->configure.is_tiled_bottom; @@ -1148,6 +1151,9 @@ xdg_surface_configure(void *data, struct xdg_surface *xdg_surface, else term_visual_focus_out(term); + if (was_suspended != win->is_suspended && term->visibility_reports) + term_send_visibility_report(term); + /* * Update opaque region if fullscreen state changed, also need to * render, since we use different buffer types with and without @@ -411,6 +411,7 @@ struct wl_window { bool is_fullscreen; bool is_maximized; bool is_resizing; + bool is_suspended; bool is_tiled_top; bool is_tiled_bottom; bool is_tiled_left; @@ -426,6 +427,7 @@ struct wl_window { int width; int height; bool is_activated:1; + bool is_suspended:1; bool is_fullscreen:1; bool is_maximized:1; bool is_resizing:1; |
