Skip to content

Commit

Permalink
added w_last_used to struct window_S
Browse files Browse the repository at this point in the history
  • Loading branch information
Iraq Jaber authored and Iraq Jaber committed May 14, 2024
1 parent 2f47929 commit e915146
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions runtime/lua/vim/_meta/builtin_types.lua
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
--- @field winid integer
--- @field winnr integer
--- @field winrow integer
--- @field lastused integer

--- @class vim.fn.sign_define.dict
--- @field text string
Expand Down
2 changes: 2 additions & 0 deletions src/nvim/buffer_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -1328,4 +1328,6 @@ struct window_S {
StlClickDefinition *w_statuscol_click_defs;
// Size of the w_statuscol_click_defs array
size_t w_statuscol_click_defs_size;

time_t w_last_used; // time when the window was last used
};
1 change: 1 addition & 0 deletions src/nvim/eval/window.c
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ static dict_T *get_win_info(win_T *wp, int16_t tpnr, int16_t winnr)
tv_dict_add_nr(dict, S_LEN("textoff"), win_col_off(wp));
tv_dict_add_nr(dict, S_LEN("terminal"), bt_terminal(wp->w_buffer));
tv_dict_add_nr(dict, S_LEN("quickfix"), bt_quickfix(wp->w_buffer));
tv_dict_add_nr(dict, S_LEN("lastused"), wp->w_last_used);
tv_dict_add_nr(dict, S_LEN("loclist"),
(bt_quickfix(wp->w_buffer) && wp->w_llist_ref != NULL));

Expand Down
3 changes: 3 additions & 0 deletions src/nvim/window.c
Original file line number Diff line number Diff line change
Expand Up @@ -2435,6 +2435,8 @@ void leaving_window(win_T *const win)
void entering_window(win_T *const win)
FUNC_ATTR_NONNULL_ALL
{
win->w_last_used = time(NULL);

// Only matters for a prompt window.
if (!bt_prompt(win->w_buffer)) {
return;
Expand Down Expand Up @@ -2468,6 +2470,7 @@ void win_init_empty(win_T *wp)
wp->w_topfill = 0;
wp->w_botline = 2;
wp->w_valid = 0;
wp->w_last_used = 0;
wp->w_s = &wp->w_buffer->b_s;
}

Expand Down
8 changes: 8 additions & 0 deletions test.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
vim.keymap.set("n", "<C-h>", function()
local bufnr = vim.api.nvim_get_current_buf()
local bufInfo = vim.fn.getbufinfo(bufnr)
local winid = bufInfo[1].windows[1]
local wininfo = vim.fn.getwininfo(winid)
print(wininfo[1].lastused)
end,
{ silent = true, noremap = true })

0 comments on commit e915146

Please sign in to comment.