fuck me in the ass

This commit is contained in:
nick black 2020-10-17 07:37:43 -04:00
parent 82af146192
commit 10a700ec7b
No known key found for this signature in database
GPG Key ID: 5F43400C21CBFACC
10 changed files with 41 additions and 137 deletions

View File

@ -27,7 +27,6 @@ option(USE_PANDOC "Build man pages and HTML reference with pandoc" ON)
option(USE_POC "Build small, uninstalled proof-of-concept binaries" ON)
option(USE_QRCODEGEN "Disable libqrcodegen QR code support" ON)
option(USE_STATIC "Build static libraries (in addition to shared)" ON)
option(USE_XCB "Disable xcb (might still be pulled in by other libs)" ON)
set(USE_MULTIMEDIA "ffmpeg" CACHE STRING "Multimedia engine, one of 'ffmpeg', 'oiio', or 'none'")
set_property(CACHE USE_MULTIMEDIA PROPERTY STRINGS ffmpeg oiio none)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS Debug Release MinSizeRel RelWithDebInfo Coverage)
@ -88,9 +87,6 @@ pkg_check_modules(OIIO REQUIRED OpenImageIO>=2.1)
set_property(GLOBAL APPEND PROPERTY PACKAGES_FOUND OpenImageIO)
endif()
find_library(MATH_LIBRARIES m)
if(${USE_XCB})
pkg_check_modules(XCB REQUIRED xcb>=1.14)
endif()
if(${USE_DOCTEST})
find_package(doctest 2.3.5)
set_package_properties(doctest PROPERTIES TYPE REQUIRED)
@ -235,14 +231,6 @@ target_link_libraries(notcurses-static PRIVATE ${OIIO_STATIC_LIBRARIES})
target_link_directories(notcurses PRIVATE ${OIIO_LIBRARY_DIRS})
target_link_directories(notcurses-static PRIVATE ${OIIO_STATIC_LIBRARY_DIRS})
endif()
if(${USE_XCB})
target_include_directories(notcurses PUBLIC "${XCB_INCLUDE_DIRS}")
target_include_directories(notcurses-static PUBLIC "${XCB_STATIC_INCLUDE_DIRS}")
target_link_libraries(notcurses PRIVATE ${XCB_LIBRARIES})
target_link_libraries(notcurses-static PRIVATE ${XCB_STATIC_LIBRARIES})
target_link_directories(notcurses PRIVATE ${XCB_LIBRARY_DIRS})
target_link_directories(notcurses-static PRIVATE ${XCB_STATIC_LIBRARY_DIRS})
endif()
# don't want these on freebsd
if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")

View File

@ -9,8 +9,6 @@ rearrangements of Notcurses.
* Add `ncinput_equal_p()` for comparison of `ncinput` structure data.
* `ncmenu_offer_input()` now recognizes the shortcuts for registered
sections, and will unroll the appropriate section when given input.
* Added `NCOPTION_NO_XCB_CONNECT` to prevent Notcurses from connecting to X
even when the `DISPLAY` environment variable is defined.
* Added `notcurses_title()` and `notcurses_set_title()`.
* 2.0.0 (2020-10-12) "Stankonia"

View File

@ -109,11 +109,6 @@ typedef enum {
// of the "alternate screen". This flag inhibits use of smcup/rmcup.
#define NCOPTION_NO_ALTERNATE_SCREEN 0x0040
// If the DISPLAY environment variable is defined, Notcurses will attempt to
// connect to the specified X.org server using xcb. Failure to do so will not
// halt Notcurses initialization, but this prevents the attempt from being made.
#define NCOPTION_NO_XCB_CONNECT 0x0100ull
// Configuration for notcurses_init().
typedef struct notcurses_options {
// The name of the terminfo database entry describing this terminal. If NULL,
@ -2838,10 +2833,8 @@ ncpixel_set_rgb8(uint32_t* pixel, int r, int g, int b){
## Windowing environments
When built with xcb support, Notcurses can make a connection to the X.Org
server specified by the `DISPLAY` environment variable. If the
`NCOPTION_NO_XCB_CONNECT` option is provided to `notcurses_init()`, no attempt
to connect will be made.
Some terminals support the OSC escape sequences to retrieve and set the
window title and icon.
```c
// Get and set the application presentation title (i.e. window title). Returns

View File

@ -18,7 +18,6 @@ notcurses_init - initialize a notcurses instance
#define NCOPTION_SUPPRESS_BANNERS 0x0020ull
#define NCOPTION_NO_ALTERNATE_SCREEN 0x0040ull
#define NCOPTION_NO_FONT_CHANGES 0x0080ull
#define NCOPTION_NO_XCB 0x0100ull
typedef enum {
NCLOGLEVEL_SILENT, // default. print nothing once fullscreen service begins
@ -136,10 +135,6 @@ zero. The following flags are defined:
* **NCOPTION_NO_FONT_CHANGES**: Do not touch the font. Notcurses might
otherwise attempt to extend the font, especially in the Linux console.
* **NCOPTION_NO_XCB_CONNECT**: Do not attempt to connect to X, even if the
**DISPLAY** environment variable is defined. Notcurses might otherwise
use xcb to establish a connection to the specified X.org server.
## Fatal signals
It is important to reset the terminal before exiting, whether terminating due

View File

@ -16,15 +16,10 @@ notcurses_windows - interaction with windowing environments
# DESCRIPTION
When used within a windowing environment (currently only the X.Org server is
supported), Notcurses provides functionality related to managing its own window
properties. These functions use the xcb asynchronous protocol to communicate
with the server, and thus ought not block. They are strictly best-effort, and
a successful return does not necessarily mean that the property change was
effected.
When compiled with xcb support, **notcurses_init** will check for the
**DISPLAY** environment variable. If this variable is defined, it will attempt
to establish a connection to the specified X.Org server.
supported) and a terminal emulator supporting the relevant OSC escape
sequences, Notcurses provides functionality related to managing its own
window's properties. They are strictly best-effort, and a successful return
does not necessarily mean that the property change was effected.
# RETURN VALUES
@ -32,25 +27,18 @@ The string returned by **notcurses_title** is heap-allocated and ought be
freed by the caller. It is encoded in UTF-8.
**notcurses_set_title** returns 0 on success, but this indicates only that the
request was dispatched.
escape was written to the terminal.
If run outside a windowing environment, or without an active connection, or
without xcb support in Notcurses, these functions always return failure.
If run outside a windowing environment, these functions always return failure.
# NOTES
The **NCOPTION_NO_XCB_CONNECT** flag can be provided to **notcurses_init** to
inhibit the xcb connection. In any case, **notcurses_init** always ignores a
failure to connect (a diagnostic might be printed).
Use of this functionality might conflict with the terminal emulator in
unpredictable ways.
Not all terminals support the OSC sequences used to retrieve and set window
properties (see **console_codes(4)**).
# BUGS
# SEE ALSO
**Xorg(1)**,
**notcurses(3)**,
**notcurses_init(3)**,
**xcb_change_property(3)**
**console_codes(4)**

View File

@ -21,12 +21,6 @@ const char* oiio_version(void);
#endif
#endif
#ifdef USE_XCB
#include <xcb/xcb.h>
#else
typedef void xcb_connection_t;
#endif
#include <term.h>
#include <time.h>
#include <stdio.h>
@ -337,7 +331,6 @@ typedef struct notcurses {
tinfo tcache; // terminfo cache
struct termios tpreserved; // terminal state upon entry
bool suppress_banner; // from notcurses_options
xcb_connection_t* xcb; // xcb connection to xorg server
// desired margins (best-effort only), copied in from notcurses_options
int margin_t, margin_b, margin_r, margin_l;
@ -515,7 +508,7 @@ tty_emit(const char* name __attribute__ ((unused)), const char* seq, int fd){
}
}while(written < slen);
if(written < slen){
//fprintf(stderr, "Error emitting %zub %s escape (%s)\n", strlen(seq), name, strerror(errno));
//fprintf(stderr, "Error emitting %zub %s escape (%s)\n", strlen(seq), name, strerror(errno));
return -1;
}
return 0;
@ -1043,11 +1036,6 @@ int ncinputlayer_init(ncinputlayer* nilayer, FILE* infp);
// FIXME absorb into ncinputlayer_init()
int cbreak_mode(int ttyfd, const struct termios* tpreserved);
// make an XCB connection to the X.Org server specified by DISPLAY, if that
// environment variable is defined (and we built in support for xcb).
int x_connect(notcurses* nc);
int x_disconnect(notcurses* nc);
#ifdef __cplusplus
}
#endif

View File

@ -893,7 +893,7 @@ notcurses* notcurses_init(const notcurses_options* opts, FILE* outfp){
fprintf(stderr, "Provided an illegal negative margin, refusing to start\n");
return NULL;
}
if(opts->flags > (NCOPTION_NO_XCB_CONNECT << 1u)){
if(opts->flags > (NCOPTION_NO_FONT_CHANGES << 1u)){
fprintf(stderr, "Provided an illegal Notcurses option, refusing to start\n");
return NULL;
}
@ -961,7 +961,6 @@ notcurses* notcurses_init(const notcurses_options* opts, FILE* outfp){
(opts->flags & NCOPTION_NO_WINCH_SIGHANDLER))){
goto err;
}
x_connect(ret);
int termerr;
if(setupterm(opts->termtype, ret->ttyfd, &termerr) != OK){
fprintf(stderr, "Terminfo error %d (see terminfo(3ncurses))\n", termerr);
@ -1133,7 +1132,6 @@ int notcurses_stop(notcurses* nc){
(nc->stashstats.cellelisions * 100.0) / (nc->stashstats.cellemissions + nc->stashstats.cellelisions));
}
}
x_disconnect(nc);
del_curterm(cur_term);
free(nc);
}

28
src/lib/osc.c Normal file
View File

@ -0,0 +1,28 @@
#include "internal.h"
// use the OSC escapes
char* notcurses_title(const notcurses* nc){
fprintf(stderr, "TTYFD: %d\n", nc->ttyfd);
if(nc->ttyfd < 0){
return NULL;
}
const char GETTITLE[] = "\x1b[21t";
if(tty_emit("gettitle", GETTITLE, nc->ttyfd)){
fprintf(stderr, "WE FAILED!\n");
return NULL;
}
char c;
ssize_t r;
while((r = read(nc->ttyfd, &c, 1)) == 1 || errno == EAGAIN){
if(r == 1){
fprintf(stderr, "GOT %c\n", c);
}
}
fprintf(stderr, "ERROR: %s\n", strerror(errno));
return NULL; // FIXME read it! through newline
}
int notcurses_set_title(notcurses* nc, const char* title){
return 0;
}

View File

@ -1,71 +0,0 @@
#include "builddef.h"
#include "internal.h"
#ifdef USE_XCB
int x_connect(notcurses* nc){
const char* disp = getenv("DISPLAY");
if(disp == NULL){
return -1;
}
nc->xcb = xcb_connect(NULL, NULL);
if(nc->xcb == NULL){
logwarn(nc, "Couldn't connect to X.Org at [%s]\n", disp);
return -1;
}
if(xcb_connection_has_error(nc->xcb)){
logwarn(nc, "xcb connection failed\n");
return -1;
}
return 0;
}
int x_disconnect(notcurses* nc){
if(nc->xcb){
xcb_disconnect(nc->xcb);
nc->xcb = NULL;
}
return 0;
}
char* notcurses_title(const notcurses* nc){
const xcb_window_t window = xcb_generate_id(nc->xcb);
xcb_get_property_cookie_t cookie = xcb_get_property(nc->xcb, 0, window, XCB_ATOM_WM_NAME, XCB_ATOM_STRING, 0, 0);
xcb_get_property_reply_t *reply = xcb_get_property_reply(nc->xcb, cookie, NULL);
if(reply == NULL){
return NULL;
}
int len = xcb_get_property_value_length(reply);
if(len == 0){
free(reply);
return NULL;
}
char* ret = strdup(xcb_get_property_value(reply));
free(reply);
return ret;
}
int notcurses_set_title(notcurses* nc, const char* title){
const xcb_window_t window = xcb_generate_id(nc->xcb);
return 0;
}
#else
int x_connect(notcurses* nc){
nc->xcb = NULL;
return -1;
}
char* notcurses_title(const notcurses* nc){
(void)nc;
return NULL;
}
int notcurses_set_title(notcurses* nc, const char* title){
(void)nc;
(void)title;
return -1;
}
int x_disconnect(notcurses* nc){
nc->xcb = NULL;
return -1;
}
#endif

View File

@ -1,7 +1,6 @@
// Populated by CMake; not installed
#cmakedefine DFSG_BUILD
#cmakedefine USE_QRCODEGEN
#cmakedefine USE_XCB
// exclusive with USE_OIIO
#cmakedefine USE_FFMPEG
// exclusive with USE_FFMPEG