summaryrefslogtreecommitdiffhomepage
path: root/tui/tui.h
diff options
context:
space:
mode:
authorSean Kurtz <seankurtz75@gmail.com>2026-11-25 21:55:37 -0600
committerSean Kurtz <seankurtz75@gmail.com>2026-11-25 21:56:07 -0600
commit8a85eb0a61c4deaa337f49f437e00710fc940556 (patch)
tree5a29d916b67da9a73be318c90271cb5656a5431d /tui/tui.h
parent431855189a87388c323787d668e0698cbfefef30 (diff)
downloadztop-feature/mouse.tar.gz
tui: mouse messages; ztop: clickable tabs, wheel, better helpfeature/mouse
Enable xterm SGR mouse reporting and decode it into TUI_MSG_MOUSE. ztop uses it for the view tabs, the storage sub-tabs, table rows and the wheel. The help panel now lists navigation explicitly, and the status line shows the keys for the current view.
Diffstat (limited to 'tui/tui.h')
-rw-r--r--tui/tui.h19
1 files changed, 16 insertions, 3 deletions
diff --git a/tui/tui.h b/tui/tui.h
index 9046620..90d569b 100644
--- a/tui/tui.h
+++ b/tui/tui.h
@@ -66,11 +66,19 @@ enum {
TUI_KEY_RESIZE,
TUI_KEY_TAB,
TUI_KEY_BACKTAB,
+ TUI_KEY_MOUSE,
};
#define TUI_MAX_W 500
#define TUI_MAX_H 200
+/** @brief One mouse event; coordinates are 0-based cells. */
+struct tui_mouse {
+ int x, y;
+ int button; /**< 0 left, 1 middle, 2 right, 64 wheel up, 65 wheel down */
+ bool release;
+};
+
struct tui {
int w, h;
int fd_in, fd_out;
@@ -83,6 +91,7 @@ struct tui {
int inlen;
char out[32768];
int olen;
+ struct tui_mouse mouse;
};
bool tui_alloc(struct tui *t, int w, int h);
@@ -109,12 +118,13 @@ int tui_key(struct tui *t, int timeout_ms);
/* ---- messages and the application loop ------------------------------- */
-enum tui_msg_type { TUI_MSG_KEY, TUI_MSG_RESIZE, TUI_MSG_TICK };
+enum tui_msg_type { TUI_MSG_KEY, TUI_MSG_RESIZE, TUI_MSG_TICK, TUI_MSG_MOUSE };
struct tui_msg {
enum tui_msg_type type;
- int key; /**< TUI_MSG_KEY: a byte or one of TUI_KEY_* */
- int w, h; /**< TUI_MSG_RESIZE: the new size */
+ int key; /**< TUI_MSG_KEY: a byte or one of TUI_KEY_* */
+ int w, h; /**< TUI_MSG_RESIZE: the new size */
+ struct tui_mouse mouse; /**< TUI_MSG_MOUSE */
};
struct tui_app {
@@ -173,6 +183,9 @@ bool tui_table_key(struct tui_table *tb, int key, int rows, int height);
int tui_tabs_draw(struct tui *t, int x, int y, const char *const *labels, int n,
int active);
+/** @brief Which tab covers cell @p x, or -1. Tabs start at column 0. */
+int tui_tabs_hit(int x, const char *const *labels, int n);
+
/** Cycle tabs with left/right/tab/backtab; true when it was consumed. */
bool tui_tabs_key(int key, int *active, int n);