From b8c01eacc80c2c41c36202aa4fa6284ac820ad2b Mon Sep 17 00:00:00 2001 From: nick black Date: Tue, 24 Aug 2021 01:30:22 -0400 Subject: [PATCH] tighten up include paths, libgpm connect #1986 --- CMakeLists.txt | 16 ++++++++---- src/info/main.c | 2 +- src/lib/gpm.c | 52 ++++++++++++++++++++++++++++++++++++++ src/lib/gpm.h | 30 ++++++++++++++++++++++ src/lib/internal.h | 19 +++++++++----- src/lib/notcurses.c | 6 ++--- src/lib/termdesc.c | 14 +++++----- src/lib/termdesc.h | 3 +++ src/media/ffmpeg.c | 4 +-- src/media/oiio-indep.c | 4 +-- src/media/oiio.cpp | 2 +- src/media/oiio.h | 2 +- src/media/shim.c | 2 +- src/tests/bitmap.cpp | 2 +- src/tests/cell.cpp | 2 +- src/tests/egcpool.cpp | 2 +- src/tests/fade.cpp | 1 - src/tests/fbuf.cpp | 2 +- src/tests/fds.cpp | 1 - src/tests/geom.cpp | 1 - src/tests/libunistring.cpp | 1 - src/tests/main.h | 2 +- src/tests/media.cpp | 2 +- src/tests/notcurses.cpp | 1 - src/tests/plane.cpp | 1 - src/tests/scrolling.cpp | 1 - src/tests/sixel.cpp | 2 +- src/tests/textlayout.cpp | 1 - src/tests/visual.cpp | 2 +- src/tests/wide.cpp | 1 - tools/builddef.h.in | 1 + 31 files changed, 136 insertions(+), 46 deletions(-) create mode 100644 src/lib/gpm.c create mode 100644 src/lib/gpm.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 1bc85a416..6b63ea09c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -202,6 +202,7 @@ set_target_properties(notcurses-core-static PROPERTIES OUTPUT_NAME notcurses-core ) target_include_directories(notcurses-core + BEFORE PRIVATE include src @@ -211,6 +212,7 @@ target_include_directories(notcurses-core "${ZLIB_INCLUDE_DIRS}" ) target_include_directories(notcurses-core-static + BEFORE PRIVATE include src @@ -225,6 +227,7 @@ target_link_libraries(notcurses-core "${TERMINFO_LIBRARIES}" "${LIBM}" "${unistring}" + "${gpm}" PUBLIC Threads::Threads "${LIBRT_LIBRARIES}" @@ -235,6 +238,7 @@ target_link_libraries(notcurses-core-static "${TERMINFO_STATIC_LIBRARIES}" "${LIBM}" "${unistring}" + "${gpm}" PUBLIC Threads::Threads "${LIBRT_LIBRARIES}" @@ -272,19 +276,19 @@ set_target_properties(notcurses-static PROPERTIES OUTPUT_NAME notcurses ) target_include_directories(notcurses + BEFORE PRIVATE include src - src/lib "${CMAKE_REQUIRED_INCLUDES}" "${PROJECT_BINARY_DIR}/include" "${TERMINFO_INCLUDE_DIRS}" ) target_include_directories(notcurses-static + BEFORE PRIVATE include src - src/lib "${CMAKE_REQUIRED_INCLUDES}" "${PROJECT_BINARY_DIR}/include" "${TERMINFO_INCLUDE_DIRS}" @@ -410,16 +414,19 @@ set_target_properties( OUTPUT_NAME "notcurses++") set(NCPP_INCLUDE_DIRS - include + "include" + "src" "${PROJECT_BINARY_DIR}/include" "${TERMINFO_INCLUDE_DIRS}" ) target_include_directories(notcurses++ + BEFORE PRIVATE ${NCPP_INCLUDE_DIRS} ) target_include_directories(notcurses++-static + BEFORE PRIVATE ${NCPP_INCLUDE_DIRS} ) @@ -552,7 +559,6 @@ target_compile_definitions(notcurses-info target_include_directories(notcurses-info PRIVATE src - src/lib include "${CMAKE_REQUIRED_INCLUDES}" "${PROJECT_BINARY_DIR}/include" @@ -661,12 +667,12 @@ if(${USE_DOCTEST}) file(GLOB TESTSRCS CONFIGURE_DEPENDS src/tests/*.cpp) add_executable(notcurses-tester ${TESTSRCS}) target_include_directories(notcurses-tester + BEFORE PRIVATE include src "${CMAKE_REQUIRED_INCLUDES}" "${PROJECT_BINARY_DIR}/include" - src/lib "${TERMINFO_INCLUDE_DIRS}" ) target_link_libraries(notcurses-tester diff --git a/src/info/main.c b/src/info/main.c index dab87e4bd..eb204c486 100644 --- a/src/info/main.c +++ b/src/info/main.c @@ -2,7 +2,7 @@ #include #include #include -#include "internal.h" // internal headers +#include "lib/internal.h" // internal headers static inline wchar_t capboolbool(unsigned utf8, bool cap){ diff --git a/src/lib/gpm.c b/src/lib/gpm.c new file mode 100644 index 000000000..f80dbe038 --- /dev/null +++ b/src/lib/gpm.c @@ -0,0 +1,52 @@ +#include "internal.h" +#ifdef USE_GPM +#undef buttons // defined by both term.h and gpm.h, ugh +#include +#include + +static Gpm_Connect gpmconn; // gpm server handle + +int gpm_connect(tinfo* ti){ + (void)ti; + gpm_zerobased = 1; + gpmconn.eventMask = ~0; + gpmconn.defaultMask = 0; + gpmconn.minMod = 0; + gpmconn.maxMod = ~0; + if(Gpm_Open(&gpmconn, 0) == -1){ + logerror("couldn't connect to gpm"); + return -1; + } + loginfo("connected to gpm on %d\n", gpm_fd); + return gpm_fd; +} + +int gpm_read(tinfo* ti, ncinput* ni){ + (void)ti; + (void)ni; + return -1; +} + +int gpm_close(tinfo* ti){ + (void)ti; + Gpm_Close(); + memset(&gpmconn, 0, sizeof(gpmconn)); + return 0; +} +#else +int gpm_connect(tinfo* ti){ + (void)ti; + return -1; +} + +int gpm_read(tinfo* ti, ncinput* ni){ + (void)ti; + (void)ni; + return -1; +} + +int gpm_close(tinfo* ti){ + (void)ti; + return -1; +} +#endif diff --git a/src/lib/gpm.h b/src/lib/gpm.h new file mode 100644 index 000000000..175cef712 --- /dev/null +++ b/src/lib/gpm.h @@ -0,0 +1,30 @@ +#ifndef NOTCURSES_GPM +#define NOTCURSES_GPM + +#ifdef __cplusplus +extern "C" { +#endif + +// internal header, not installed + +struct tinfo; +struct ncinput; + +// GPM ("General Purpose Mouse") provides an interface to mice in the Linux +// and FreeBSD consoles. The gpm server must be running; we do not attempt to +// start it. We must have been built with -DUSE_GPM. + +// Returns the poll()able file descriptor associated with gpm, or -1 on failure. +int gpm_connect(struct tinfo* ti); + +// Read from the gpm connection, which ought have been poll()ed. Translates +// the libgpm input to an ncinput. +int gpm_read(struct tinfo* ti, struct ncinput* ni); + +int gpm_close(struct tinfo* ti); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/lib/internal.h b/src/lib/internal.h index be17065c1..5d19227ff 100644 --- a/src/lib/internal.h +++ b/src/lib/internal.h @@ -32,10 +32,11 @@ extern "C" { #ifndef __MINGW64__ #include #endif -#include "termdesc.h" -#include "egcpool.h" -#include "sprite.h" -#include "fbuf.h" +#include "lib/termdesc.h" +#include "lib/egcpool.h" +#include "lib/sprite.h" +#include "lib/fbuf.h" +#include "lib/gpm.h" #define API __attribute__((visibility("default"))) #define ALLOC __attribute__((malloc)) __attribute__((warn_unused_result)) @@ -1142,7 +1143,10 @@ coerce_styles(fbuf* f, const tinfo* ti, uint16_t* curstyle, #define SET_SGR_MODE_MOUSE "1006" static inline int -mouse_enable(FILE* out){ +mouse_enable(tinfo* ti, FILE* out){ + if(ti->qterm == TERMINAL_LINUX){ + return gpm_connect(ti); + } // Sets the shift-escape option, allowing shift+mouse to override the standard // mouse protocol (mainly so copy-and-paste can still be performed). #define XTSHIFTESCAPE "\x1b[>1s" @@ -1153,7 +1157,10 @@ mouse_enable(FILE* out){ } static inline int -mouse_disable(fbuf* f){ +mouse_disable(tinfo* ti, fbuf* f){ + if(ti->qterm == TERMINAL_LINUX){ + return gpm_close(ti); + } return fbuf_emit(f, "\x1b[?" SET_BTN_EVENT_MOUSE ";" /*SET_FOCUS_EVENT_MOUSE ";" */SET_SGR_MODE_MOUSE "l"); } diff --git a/src/lib/notcurses.c b/src/lib/notcurses.c index 7f31f074e..a8b431741 100644 --- a/src/lib/notcurses.c +++ b/src/lib/notcurses.c @@ -90,7 +90,7 @@ notcurses_stop_minimal(void* vnc){ if(nc->tcache.pixel_shutdown){ ret |= nc->tcache.pixel_shutdown(f); } - ret |= mouse_disable(f); + ret |= mouse_disable(&nc->tcache, f); ret |= reset_term_attributes(&nc->tcache, f); if(nc->tcache.ttyfd >= 0){ if((esc = get_escape(&nc->tcache, ESCAPE_RMCUP))){ @@ -2262,7 +2262,7 @@ ncplane* ncplane_above(ncplane* n){ } int notcurses_mouse_enable(notcurses* n){ - if(mouse_enable(n->ttyfp)){ + if(mouse_enable(&n->tcache, n->ttyfp)){ return -1; } return 0; @@ -2275,7 +2275,7 @@ int notcurses_mouse_disable(notcurses* n){ if(fbuf_init_small(&f)){ return -1; } - if(mouse_disable(&f)){ + if(mouse_disable(&n->tcache, &f)){ fbuf_free(&f); return -1; } diff --git a/src/lib/termdesc.c b/src/lib/termdesc.c index 0b1b7e197..bdcbbf711 100644 --- a/src/lib/termdesc.c +++ b/src/lib/termdesc.c @@ -664,7 +664,7 @@ macos_early_matches(void){ int interrogate_terminfo(tinfo* ti, const char* termtype, FILE* out, unsigned utf8, unsigned noaltscreen, unsigned nocbreak, unsigned nonewfonts, int* cursor_y, int* cursor_x, ncsharedstats* stats){ - queried_terminals_e qterm = TERMINAL_UNKNOWN; + ti->qterm = TERMINAL_UNKNOWN; memset(ti, 0, sizeof(*ti)); // we don't need a controlling tty for everything we do; allow a failure here ti->ttyfd = get_tty_fd(out); @@ -672,19 +672,19 @@ int interrogate_terminfo(tinfo* ti, const char* termtype, FILE* out, unsigned ut size_t tableused = 0; const char* tname = NULL; #ifdef __APPLE__ - qterm = macos_early_matches(); + ti->qterm = macos_early_matches(); #elif defined(__MINGW64__) if(prepare_windows_terminal(ti, &tablelen, &tableused)){ return -1; } - qterm = TERMINAL_MSTERMINAL; + ti->qterm = TERMINAL_MSTERMINAL; (void)termtype; #elif defined(__linux__) ti->linux_fb_fd = -1; ti->linux_fbuffer = MAP_FAILED; // we might or might not program quadrants into the console font if(is_linux_console(ti->ttyfd)){ - qterm = TERMINAL_LINUX; + ti->qterm = TERMINAL_LINUX; } #endif #ifndef __MINGW64__ @@ -700,7 +700,7 @@ int interrogate_terminfo(tinfo* ti, const char* termtype, FILE* out, unsigned ut } // if we already know our terminal (e.g. on the linux console), there's no // need to send the identification queries. the controls are sufficient. - bool minimal = (qterm != TERMINAL_UNKNOWN); + bool minimal = (ti->qterm != TERMINAL_UNKNOWN); if(send_initial_queries(ti->ttyfd, minimal)){ return -1; } @@ -840,7 +840,7 @@ int interrogate_terminfo(tinfo* ti, const char* termtype, FILE* out, unsigned ut } *cursor_x = *cursor_y = -1; unsigned kittygraphs = 0; - if(ncinputlayer_init(ti, stdin, &qterm, &appsync_advertised, + if(ncinputlayer_init(ti, stdin, &ti->qterm, &appsync_advertised, cursor_y, cursor_x, stats, &kittygraphs)){ goto err; } @@ -863,7 +863,7 @@ int interrogate_terminfo(tinfo* ti, const char* termtype, FILE* out, unsigned ut } } bool invertsixel = false; - if(apply_term_heuristics(ti, tname, qterm, &tablelen, &tableused, + if(apply_term_heuristics(ti, tname, ti->qterm, &tablelen, &tableused, &invertsixel, nonewfonts)){ ncinputlayer_stop(&ti->input); goto err; diff --git a/src/lib/termdesc.h b/src/lib/termdesc.h index 0f9afca2f..dde4bc978 100644 --- a/src/lib/termdesc.h +++ b/src/lib/termdesc.h @@ -7,6 +7,8 @@ extern "C" { // internal header, not installed +#include "version.h" +#include "builddef.h" #include "input.h" #include #include @@ -185,6 +187,7 @@ typedef struct tinfo { int sprixel_scale_height; // sprixel must be a multiple of this many rows const char* termname; // terminal name from environment variables/init char* termversion; // terminal version (freeform) from query responses + queried_terminals_e qterm;// detected terminal class #ifndef __MINGW64__ struct termios tpreserved;// terminal state upon entry #endif diff --git a/src/media/ffmpeg.c b/src/media/ffmpeg.c index a23638f56..a651156b6 100644 --- a/src/media/ffmpeg.c +++ b/src/media/ffmpeg.c @@ -11,8 +11,8 @@ #include #include #include -#include "visual-details.h" -#include "internal.h" +#include "lib/visual-details.h" +#include "lib/internal.h" struct AVFormatContext; struct AVCodecContext; diff --git a/src/media/oiio-indep.c b/src/media/oiio-indep.c index 6d7613c4a..d7d92fd89 100644 --- a/src/media/oiio-indep.c +++ b/src/media/oiio-indep.c @@ -1,7 +1,7 @@ #include "builddef.h" #ifdef USE_OIIO -#include "visual-details.h" -#include "internal.h" +#include "lib/visual-details.h" +#include "lib/internal.h" #include "oiio.h" int oiio_blit_dispatch(struct ncplane* nc, const struct blitset* bset, diff --git a/src/media/oiio.cpp b/src/media/oiio.cpp index 1662d0efe..f0780b02c 100644 --- a/src/media/oiio.cpp +++ b/src/media/oiio.cpp @@ -5,7 +5,7 @@ #include #include #include -#include "visual-details.h" +#include "lib/visual-details.h" #include "oiio.h" typedef struct ncvisual_details { diff --git a/src/media/oiio.h b/src/media/oiio.h index 0d5d13e03..5ff31419e 100644 --- a/src/media/oiio.h +++ b/src/media/oiio.h @@ -5,7 +5,7 @@ extern "C" { #endif -#include "internal.h" +#include "lib/internal.h" int oiio_decode(ncvisual* nc); struct ncvisual_details* oiio_details_init(void); diff --git a/src/media/shim.c b/src/media/shim.c index 0b615f7e9..8b17c9dab 100644 --- a/src/media/shim.c +++ b/src/media/shim.c @@ -1,5 +1,5 @@ #include "notcurses/direct.h" -#include "internal.h" +#include "lib/internal.h" extern const ncvisual_implementation local_visual_implementation; diff --git a/src/tests/bitmap.cpp b/src/tests/bitmap.cpp index 206a3399a..e0651d2d8 100644 --- a/src/tests/bitmap.cpp +++ b/src/tests/bitmap.cpp @@ -1,5 +1,5 @@ #include "main.h" -#include "visual-details.h" +#include "lib/visual-details.h" #include TEST_CASE("Bitmaps") { diff --git a/src/tests/cell.cpp b/src/tests/cell.cpp index 0752e318c..f47058511 100644 --- a/src/tests/cell.cpp +++ b/src/tests/cell.cpp @@ -1,5 +1,5 @@ #include "main.h" -#include "egcpool.h" +#include "lib/egcpool.h" TEST_CASE("Cell") { auto nc_ = testing_notcurses(); diff --git a/src/tests/egcpool.cpp b/src/tests/egcpool.cpp index b460b0f09..c8ba03ed7 100644 --- a/src/tests/egcpool.cpp +++ b/src/tests/egcpool.cpp @@ -1,6 +1,6 @@ #include #include "main.h" -#include "egcpool.h" +#include "lib/egcpool.h" TEST_CASE("EGCpool") { egcpool pool_{}; diff --git a/src/tests/fade.cpp b/src/tests/fade.cpp index d5dc397d8..f46f58dd7 100644 --- a/src/tests/fade.cpp +++ b/src/tests/fade.cpp @@ -1,7 +1,6 @@ #include "main.h" #include #include -#include "internal.h" auto pulser(struct notcurses* nc, struct ncplane* ncp __attribute__ ((unused)), const struct timespec* ts __attribute__ ((unused)), void* curry) -> int { diff --git a/src/tests/fbuf.cpp b/src/tests/fbuf.cpp index 42e8389ca..510897e7d 100644 --- a/src/tests/fbuf.cpp +++ b/src/tests/fbuf.cpp @@ -1,5 +1,5 @@ #include "main.h" -#include "fbuf.h" +#include "lib/fbuf.h" TEST_CASE("Fbuf") { auto nc_ = testing_notcurses(); diff --git a/src/tests/fds.cpp b/src/tests/fds.cpp index d985300db..dc11cc66e 100644 --- a/src/tests/fds.cpp +++ b/src/tests/fds.cpp @@ -4,7 +4,6 @@ #include #include #include -#include "internal.h" #include static pthread_cond_t cond; diff --git a/src/tests/geom.cpp b/src/tests/geom.cpp index 89b6defae..b35b3f360 100644 --- a/src/tests/geom.cpp +++ b/src/tests/geom.cpp @@ -1,5 +1,4 @@ #include "main.h" -#include "internal.h" TEST_CASE("Geometry") { auto nc_ = testing_notcurses(); diff --git a/src/tests/libunistring.cpp b/src/tests/libunistring.cpp index a4bdf3f42..0c557ee83 100644 --- a/src/tests/libunistring.cpp +++ b/src/tests/libunistring.cpp @@ -1,5 +1,4 @@ #include "main.h" -#include "internal.h" // some simple tests to ensure the libunistring we've compiled/linked against // behaves as expected. diff --git a/src/tests/main.h b/src/tests/main.h index f5418e493..3517c577f 100644 --- a/src/tests/main.h +++ b/src/tests/main.h @@ -9,7 +9,7 @@ #include #include #include -#include "internal.h" +#include "lib/internal.h" struct free_deleter{ template diff --git a/src/tests/media.cpp b/src/tests/media.cpp index 9821ea17e..cff8bb3e3 100644 --- a/src/tests/media.cpp +++ b/src/tests/media.cpp @@ -1,5 +1,5 @@ #include "main.h" -#include "visual-details.h" +#include "lib/visual-details.h" #include #include diff --git a/src/tests/notcurses.cpp b/src/tests/notcurses.cpp index 1688e951a..d1c857ea1 100644 --- a/src/tests/notcurses.cpp +++ b/src/tests/notcurses.cpp @@ -2,7 +2,6 @@ #include #include #include "main.h" -#include "internal.h" TEST_CASE("NotcursesBase") { auto nc_ = testing_notcurses(); diff --git a/src/tests/plane.cpp b/src/tests/plane.cpp index af23488b4..be52be002 100644 --- a/src/tests/plane.cpp +++ b/src/tests/plane.cpp @@ -1,6 +1,5 @@ #include #include "main.h" -#include "internal.h" void BoxPermutationsRounded(struct notcurses* nc, struct ncplane* n, unsigned edges) { int dimx, dimy; diff --git a/src/tests/scrolling.cpp b/src/tests/scrolling.cpp index 7e5e9dfc2..92073707a 100644 --- a/src/tests/scrolling.cpp +++ b/src/tests/scrolling.cpp @@ -1,7 +1,6 @@ #include "main.h" #include #include -#include "internal.h" TEST_CASE("Scrolling") { auto nc_ = testing_notcurses(); diff --git a/src/tests/sixel.cpp b/src/tests/sixel.cpp index 625bff338..500ec76b1 100644 --- a/src/tests/sixel.cpp +++ b/src/tests/sixel.cpp @@ -1,5 +1,5 @@ #include "main.h" -#include "visual-details.h" +#include "lib/visual-details.h" #include #include diff --git a/src/tests/textlayout.cpp b/src/tests/textlayout.cpp index d6cab1bf3..24a43df78 100644 --- a/src/tests/textlayout.cpp +++ b/src/tests/textlayout.cpp @@ -1,5 +1,4 @@ #include "main.h" -#include "internal.h" TEST_CASE("TextLayout") { auto nc_ = testing_notcurses(); diff --git a/src/tests/visual.cpp b/src/tests/visual.cpp index 6599d2023..516e180ef 100644 --- a/src/tests/visual.cpp +++ b/src/tests/visual.cpp @@ -1,5 +1,5 @@ #include "main.h" -#include "visual-details.h" +#include "lib/visual-details.h" #include #include diff --git a/src/tests/wide.cpp b/src/tests/wide.cpp index 63213070f..6486de38e 100644 --- a/src/tests/wide.cpp +++ b/src/tests/wide.cpp @@ -1,7 +1,6 @@ #include #include #include "main.h" -#include "internal.h" const char SNAKE[] = "\xf0\x9f\x90\x8d"; // U+1F40D SNAKE const char SCORPION[] = "\xf0\x9f\xa6\x82"; // U+1F982 SCORPION diff --git a/tools/builddef.h.in b/tools/builddef.h.in index 8beabbdd0..967e470d0 100644 --- a/tools/builddef.h.in +++ b/tools/builddef.h.in @@ -1,5 +1,6 @@ // Populated by CMake; not installed #cmakedefine DFSG_BUILD +#cmakedefine USE_GPM #cmakedefine USE_QRCODEGEN #cmakedefine USE_READLINE // exclusive with USE_OIIO