Add ncurses_enable_mouse ui option

This commit is contained in:
Maxime Coste 2015-10-02 13:52:41 +01:00
parent 0df72bd672
commit a6cd764042
2 changed files with 33 additions and 8 deletions

View File

@ -270,12 +270,7 @@ NCursesUI::NCursesUI()
use_default_colors(); use_default_colors();
set_escdelay(25); set_escdelay(25);
mousemask(ALL_MOUSE_EVENTS | REPORT_MOUSE_POSITION, nullptr); enable_mouse(true);
mouseinterval(0);
// force enable report mouse position
puts("\033[?1002h");
// force enable report focus events
puts("\033[?1004h");
signal(SIGWINCH, on_term_resize); signal(SIGWINCH, on_term_resize);
signal(SIGINT, [](int){}); signal(SIGINT, [](int){});
@ -287,8 +282,7 @@ NCursesUI::NCursesUI()
NCursesUI::~NCursesUI() NCursesUI::~NCursesUI()
{ {
puts("\033[?1004l"); enable_mouse(false);
puts("\033[?1002l");
const bool changed_color = can_change_color(); const bool changed_color = can_change_color();
endwin(); endwin();
if (changed_color) if (changed_color)
@ -930,6 +924,29 @@ void NCursesUI::abort()
endwin(); endwin();
} }
void NCursesUI::enable_mouse(bool enabled)
{
if (enabled == m_mouse_enabled)
return;
m_mouse_enabled = enabled;
if (enabled)
{
mousemask(ALL_MOUSE_EVENTS | REPORT_MOUSE_POSITION, nullptr);
mouseinterval(0);
// force enable report mouse position
puts("\033[?1002h");
// force enable report focus events
puts("\033[?1004h");
}
else
{
mousemask(0, nullptr);
puts("\033[?1004l");
puts("\033[?1002l");
}
}
void NCursesUI::set_ui_options(const Options& options) void NCursesUI::set_ui_options(const Options& options)
{ {
{ {
@ -955,6 +972,11 @@ void NCursesUI::set_ui_options(const Options& options)
} }
{ {
auto enable_mouse_it = options.find("ncurses_enable_mouse");
enable_mouse(enable_mouse_it == options.end() or
enable_mouse_it->value == "yes" or
enable_mouse_it->value == "true");
auto wheel_down_it = options.find("ncurses_wheel_down_button"); auto wheel_down_it = options.find("ncurses_wheel_down_button");
m_wheel_down_button = wheel_down_it != options.end() ? m_wheel_down_button = wheel_down_it != options.end() ?
str_to_int_ifp(wheel_down_it->value).value_or(2) : 2; str_to_int_ifp(wheel_down_it->value).value_or(2) : 2;

View File

@ -93,6 +93,9 @@ private:
bool m_status_on_top = false; bool m_status_on_top = false;
ConstArrayView<StringView> m_assistant; ConstArrayView<StringView> m_assistant;
void enable_mouse(bool enabled);
bool m_mouse_enabled = false;
int m_wheel_down_button = 2; int m_wheel_down_button = 2;
int m_wheel_up_button = 4; int m_wheel_up_button = 4;