Skip to content

Commit cc2e997

Browse files
committed
[lofi] disable mouse when in lofi
1 parent 9a19bd4 commit cc2e997

File tree

1 file changed

+36
-25
lines changed

1 file changed

+36
-25
lines changed

src/lnav.cc

Lines changed: 36 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1244,31 +1244,44 @@ VALUES ('org.lnav.mouse-support', -1, DATETIME('now', '+1 minute'),
12441244

12451245
auto sc = create_screen_res.unwrap();
12461246
auto inputready_fd = notcurses_inputready_fd(sc.get_notcurses());
1247+
auto& mouse_i = injector::get<xterm_mouse&>();
12471248

1248-
ec.ec_ui_callbacks.uc_pre_stdout_write = [&sc]() {
1249-
notcurses_leave_alternate_screen(sc.get_notcurses());
1250-
1251-
// notcurses sets stdio to non-blocking, which can cause an issue
1252-
// when writing since there is a chance of an EAGAIN happening
1253-
const auto fl = fcntl(STDOUT_FILENO, F_GETFL, 0);
1254-
fcntl(STDOUT_FILENO, F_SETFL, fl & ~O_NONBLOCK);
1255-
};
1256-
ec.ec_ui_callbacks.uc_post_stdout_write = [&sc]() {
1257-
const auto fl = fcntl(STDOUT_FILENO, F_GETFL, 0);
1258-
fcntl(STDOUT_FILENO, F_SETFL, fl | O_NONBLOCK);
1249+
auto ui_cb_mouse = false;
1250+
ec.ec_ui_callbacks.uc_pre_stdout_write
1251+
= [&sc, &mouse_i, &ui_cb_mouse]() {
1252+
ui_cb_mouse = mouse_i.is_enabled();
1253+
if (ui_cb_mouse) {
1254+
mouse_i.set_enabled(sc.get_notcurses(), false);
1255+
}
1256+
notcurses_leave_alternate_screen(sc.get_notcurses());
12591257

1260-
auto nci = ncinput{};
1261-
do {
1262-
notcurses_get_blocking(sc.get_notcurses(), &nci);
1263-
} while (nci.evtype == NCTYPE_RELEASE || ncinput_lock_p(&nci)
1264-
|| ncinput_modifier_p(&nci));
1265-
notcurses_enter_alternate_screen(sc.get_notcurses());
1266-
notcurses_refresh(sc.get_notcurses(), nullptr, nullptr);
1267-
// XXX doing this refresh twice since it doesn't seem to be enough
1268-
// to do it once...
1269-
notcurses_render(sc.get_notcurses());
1270-
notcurses_refresh(sc.get_notcurses(), nullptr, nullptr);
1271-
};
1258+
// notcurses sets stdio to non-blocking, which can cause an
1259+
// issue when writing since there is a chance of an EAGAIN
1260+
// happening
1261+
const auto fl = fcntl(STDOUT_FILENO, F_GETFL, 0);
1262+
fcntl(STDOUT_FILENO, F_SETFL, fl & ~O_NONBLOCK);
1263+
};
1264+
ec.ec_ui_callbacks.uc_post_stdout_write
1265+
= [&sc, &mouse_i, &ui_cb_mouse]() {
1266+
const auto fl = fcntl(STDOUT_FILENO, F_GETFL, 0);
1267+
fcntl(STDOUT_FILENO, F_SETFL, fl | O_NONBLOCK);
1268+
1269+
auto nci = ncinput{};
1270+
do {
1271+
notcurses_get_blocking(sc.get_notcurses(), &nci);
1272+
} while (nci.evtype == NCTYPE_RELEASE || ncinput_lock_p(&nci)
1273+
|| ncinput_modifier_p(&nci));
1274+
notcurses_enter_alternate_screen(sc.get_notcurses());
1275+
1276+
if (ui_cb_mouse) {
1277+
mouse_i.set_enabled(sc.get_notcurses(), true);
1278+
}
1279+
notcurses_refresh(sc.get_notcurses(), nullptr, nullptr);
1280+
// XXX doing this refresh twice since it doesn't seem to be
1281+
// enough to do it once...
1282+
notcurses_render(sc.get_notcurses());
1283+
notcurses_refresh(sc.get_notcurses(), nullptr, nullptr);
1284+
};
12721285
ec.ec_ui_callbacks.uc_redraw = [&sc]() {
12731286
notcurses_refresh(sc.get_notcurses(), nullptr, nullptr);
12741287
};
@@ -1277,8 +1290,6 @@ VALUES ('org.lnav.mouse-support', -1, DATETIME('now', '+1 minute'),
12771290

12781291
ui_periodic_timer::singleton();
12791292

1280-
auto& mouse_i = injector::get<xterm_mouse&>();
1281-
12821293
mouse_i.set_behavior(&lb);
12831294
mouse_i.set_enabled(
12841295
sc.get_notcurses(),

0 commit comments

Comments
 (0)