Refactor resize handling in NCursesUI
This commit is contained in:
parent
3fe8446065
commit
130b22ff74
|
@ -239,11 +239,6 @@ void on_term_resize(int)
|
|||
EventManager::instance().force_signal(0);
|
||||
}
|
||||
|
||||
void on_sigint(int)
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
NCursesUI::NCursesUI()
|
||||
: m_stdin_watcher{0, [this](FDWatcher&, EventMode mode) {
|
||||
if (m_input_callback)
|
||||
|
@ -262,16 +257,17 @@ NCursesUI::NCursesUI()
|
|||
use_default_colors();
|
||||
set_escdelay(25);
|
||||
|
||||
signal(SIGWINCH, on_term_resize);
|
||||
signal(SIGINT, on_sigint);
|
||||
|
||||
mousemask(ALL_MOUSE_EVENTS | REPORT_MOUSE_POSITION, nullptr);
|
||||
mouseinterval(0);
|
||||
// force enable report mouse position
|
||||
puts("\033[?1002h");
|
||||
update_dimensions();
|
||||
|
||||
wrefresh(stdscr);
|
||||
signal(SIGWINCH, on_term_resize);
|
||||
signal(SIGINT, [](int){});
|
||||
|
||||
check_resize(true);
|
||||
|
||||
redraw();
|
||||
}
|
||||
|
||||
NCursesUI::~NCursesUI()
|
||||
|
@ -326,17 +322,6 @@ static CharCoord window_pos(WINDOW* win)
|
|||
return pos;
|
||||
}
|
||||
|
||||
void NCursesUI::update_dimensions()
|
||||
{
|
||||
m_dimensions = window_size(stdscr);
|
||||
|
||||
if (m_window)
|
||||
delwin(m_window);
|
||||
m_window = (NCursesWin*)newwin((int)m_dimensions.line, (int)m_dimensions.column, 0, 0);
|
||||
|
||||
--m_dimensions.line;
|
||||
}
|
||||
|
||||
void NCursesUI::draw_line(const DisplayLine& line, CharCount col_index,
|
||||
const Face& default_face) const
|
||||
{
|
||||
|
@ -440,22 +425,32 @@ void NCursesUI::draw_status(const DisplayLine& status_line,
|
|||
m_dirty = true;
|
||||
}
|
||||
|
||||
void NCursesUI::check_resize()
|
||||
void NCursesUI::check_resize(bool force)
|
||||
{
|
||||
if (resize_pending)
|
||||
{
|
||||
int fd = open("/dev/tty", O_RDWR);
|
||||
if (not force and not resize_pending)
|
||||
return;
|
||||
|
||||
resize_pending = 0;
|
||||
|
||||
const int fd = open("/dev/tty", O_RDWR);
|
||||
auto close_fd = on_scope_end([fd]{ close(fd); });
|
||||
winsize ws;
|
||||
if (ioctl(fd, TIOCGWINSZ, (void*)&ws) == 0)
|
||||
{
|
||||
close(fd);
|
||||
resizeterm(ws.ws_row, ws.ws_col);
|
||||
update_dimensions();
|
||||
resize_term(ws.ws_row, ws.ws_col);
|
||||
|
||||
if (m_window)
|
||||
delwin(m_window);
|
||||
m_window = (NCursesWin*)newwin(ws.ws_row, ws.ws_col, 0, 0);
|
||||
|
||||
m_dimensions = CharCoord{ws.ws_row-1, ws.ws_col};
|
||||
}
|
||||
ungetch(KEY_RESIZE);
|
||||
else
|
||||
kak_assert(false);
|
||||
|
||||
m_dirty = true;
|
||||
resize_pending = false;
|
||||
}
|
||||
ungetch(KEY_RESIZE);
|
||||
wrefresh(stdscr);
|
||||
}
|
||||
|
||||
bool NCursesUI::is_key_available()
|
||||
|
@ -496,7 +491,10 @@ Key NCursesUI::get_key()
|
|||
if (c > 0 and c < 27)
|
||||
{
|
||||
if (c == CTRL('l'))
|
||||
redrawwin(stdscr);
|
||||
{
|
||||
redrawwin(m_window);
|
||||
redraw();
|
||||
}
|
||||
if (c == CTRL('z'))
|
||||
{
|
||||
raise(SIGTSTP);
|
||||
|
|
|
@ -52,7 +52,7 @@ public:
|
|||
|
||||
static void abort();
|
||||
private:
|
||||
void check_resize();
|
||||
void check_resize(bool force = false);
|
||||
void redraw();
|
||||
void draw_line(const DisplayLine& line, CharCount col_index,
|
||||
const Face& default_face) const;
|
||||
|
@ -62,7 +62,6 @@ private:
|
|||
NCursesWin* m_window = nullptr;
|
||||
|
||||
CharCoord m_dimensions;
|
||||
void update_dimensions();
|
||||
|
||||
NCursesWin* m_menu_win = nullptr;
|
||||
Vector<String> m_items;
|
||||
|
|
Loading…
Reference in New Issue
Block a user