From dd7006c850e1f973c214f70eee87a054b00f19e7 Mon Sep 17 00:00:00 2001 From: nicm Date: Fri, 26 Feb 2021 07:53:26 +0000 Subject: Add a couple of format variables for active and last window index. --- format.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'format.c') diff --git a/format.c b/format.c index a9694bab..00413bae 100644 --- a/format.c +++ b/format.c @@ -2099,6 +2099,28 @@ format_cb_version(__unused struct format_tree *ft) return (xstrdup(getversion())); } +/* Callback for active_window_index. */ +static void * +format_cb_active_window_index(struct format_tree *ft) +{ + if (ft->s != NULL) + return (format_printf("%u", ft->s->curw->idx)); + return (NULL); +} + +/* Callback for last_window_index. */ +static void * +format_cb_last_window_index(struct format_tree *ft) +{ + struct winlink *wl; + + if (ft->s != NULL) { + wl = RB_MAX(winlinks, &ft->s->windows); + return (format_printf("%u", wl->idx)); + } + return (NULL); +} + /* Callback for window_active. */ static void * format_cb_window_active(struct format_tree *ft) @@ -2496,6 +2518,9 @@ struct format_table_entry { * Only variables which are added by the caller go into the tree. */ static const struct format_table_entry format_table[] = { + { "active_window_index", FORMAT_TABLE_STRING, + format_cb_active_window_index + }, { "alternate_on", FORMAT_TABLE_STRING, format_cb_alternate_on }, @@ -2631,6 +2656,9 @@ static const struct format_table_entry format_table[] = { { "keypad_flag", FORMAT_TABLE_STRING, format_cb_keypad_flag }, + { "last_window_index", FORMAT_TABLE_STRING, + format_cb_last_window_index + }, { "mouse_all_flag", FORMAT_TABLE_STRING, format_cb_mouse_all_flag }, -- cgit