From e6116fde2b84522a72002dbad1d00a7d3f97c751 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Tue, 15 Feb 2022 11:37:50 +0000 Subject: [PATCH] enhanced the build files with X11 check --- hio/bin/Makefile.am | 11 +- hio/bin/Makefile.in | 63 +++++-- hio/bin/te.c | 420 +++++++++++++++++++++++++++++++++++++++++++ hio/configure | 56 ++++++ hio/configure.ac | 3 + hio/lib/hio-cfg.h.in | 3 + 6 files changed, 542 insertions(+), 14 deletions(-) create mode 100644 hio/bin/te.c diff --git a/hio/bin/Makefile.am b/hio/bin/Makefile.am index a3d23e1..b488bcd 100644 --- a/hio/bin/Makefile.am +++ b/hio/bin/Makefile.am @@ -15,7 +15,16 @@ hio_execd_SOURCES = execd.c hio_execd_CPPFLAGS = $(CPPFLAGS_COMMON) hio_execd_CFLAGS = $(CFLAGS_COMMON) hio_execd_LDFLAGS = $(LDFLAGS_COMMON) -hio_execd_LDADD = $(LIBADD_COMMON) +hio_execd_LDADD = $(LIBADD_COMMON) + +if HAVE_X11_LIB +bin_PROGRAMS += hio-te +hio_te_SOURCES = te.c +hio_te_CPPFLAGS = $(CPPFLAGS_COMMON) +hio_te_CFLAGS = $(CFLAGS_COMMON) +hio_te_LDFLAGS = $(LDFLAGS_COMMON) +hio_te_LDADD = $(LIBADD_COMMON) -lX11 +endif bin_PROGRAMS += hio-t01 hio_t01_SOURCES = t01.c diff --git a/hio/bin/Makefile.in b/hio/bin/Makefile.in index d155e72..e1d4c68 100644 --- a/hio/bin/Makefile.in +++ b/hio/bin/Makefile.in @@ -88,12 +88,13 @@ PRE_UNINSTALL = : POST_UNINSTALL = : build_triplet = @build@ host_triplet = @host@ -bin_PROGRAMS = hio-execd$(EXEEXT) hio-t01$(EXEEXT) hio-t02$(EXEEXT) \ - hio-t03$(EXEEXT) hio-t04$(EXEEXT) hio-t05$(EXEEXT) \ - hio-t06$(EXEEXT) -@ENABLE_MARIADB_TRUE@am__append_1 = $(MARIADB_CFLAGS) -@ENABLE_MARIADB_TRUE@am__append_2 = $(MARIADB_LDFLAGS) -@ENABLE_MARIADB_TRUE@am__append_3 = $(MARIADB_LIBS) +bin_PROGRAMS = hio-execd$(EXEEXT) $(am__EXEEXT_1) hio-t01$(EXEEXT) \ + hio-t02$(EXEEXT) hio-t03$(EXEEXT) hio-t04$(EXEEXT) \ + hio-t05$(EXEEXT) hio-t06$(EXEEXT) +@HAVE_X11_LIB_TRUE@am__append_1 = hio-te +@ENABLE_MARIADB_TRUE@am__append_2 = $(MARIADB_CFLAGS) +@ENABLE_MARIADB_TRUE@am__append_3 = $(MARIADB_LDFLAGS) +@ENABLE_MARIADB_TRUE@am__append_4 = $(MARIADB_LIBS) subdir = bin ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 am__aclocal_m4_deps = $(top_srcdir)/m4/ax_check_sign.m4 \ @@ -109,6 +110,7 @@ mkinstalldirs = $(install_sh) -d CONFIG_HEADER = $(top_builddir)/lib/hio-cfg.h CONFIG_CLEAN_FILES = CONFIG_CLEAN_VPATH_FILES = +@HAVE_X11_LIB_TRUE@am__EXEEXT_1 = hio-te$(EXEEXT) am__installdirs = "$(DESTDIR)$(bindir)" PROGRAMS = $(bin_PROGRAMS) am_hio_execd_OBJECTS = hio_execd-execd.$(OBJEXT) @@ -159,6 +161,13 @@ hio_t06_DEPENDENCIES = $(LIBADD_COMMON) hio_t06_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ $(LIBTOOLFLAGS) --mode=link $(CCLD) $(hio_t06_CFLAGS) \ $(CFLAGS) $(hio_t06_LDFLAGS) $(LDFLAGS) -o $@ +am__hio_te_SOURCES_DIST = te.c +@HAVE_X11_LIB_TRUE@am_hio_te_OBJECTS = hio_te-te.$(OBJEXT) +hio_te_OBJECTS = $(am_hio_te_OBJECTS) +@HAVE_X11_LIB_TRUE@hio_te_DEPENDENCIES = $(LIBADD_COMMON) +hio_te_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ + $(LIBTOOLFLAGS) --mode=link $(CCLD) $(hio_te_CFLAGS) $(CFLAGS) \ + $(hio_te_LDFLAGS) $(LDFLAGS) -o $@ AM_V_P = $(am__v_P_@AM_V@) am__v_P_ = $(am__v_P_@AM_DEFAULT_V@) am__v_P_0 = false @@ -177,7 +186,8 @@ am__maybe_remake_depfiles = depfiles am__depfiles_remade = ./$(DEPDIR)/hio_execd-execd.Po \ ./$(DEPDIR)/hio_t01-t01.Po ./$(DEPDIR)/hio_t02-t02.Po \ ./$(DEPDIR)/hio_t03-t03.Po ./$(DEPDIR)/hio_t04-t04.Po \ - ./$(DEPDIR)/hio_t05-t05.Po ./$(DEPDIR)/hio_t06-t06.Po + ./$(DEPDIR)/hio_t05-t05.Po ./$(DEPDIR)/hio_t06-t06.Po \ + ./$(DEPDIR)/hio_te-te.Po am__mv = mv -f COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) @@ -199,10 +209,11 @@ am__v_CCLD_0 = @echo " CCLD " $@; am__v_CCLD_1 = SOURCES = $(hio_execd_SOURCES) $(hio_t01_SOURCES) $(hio_t02_SOURCES) \ $(hio_t03_SOURCES) $(hio_t04_SOURCES) $(hio_t05_SOURCES) \ - $(hio_t06_SOURCES) + $(hio_t06_SOURCES) $(hio_te_SOURCES) DIST_SOURCES = $(hio_execd_SOURCES) $(hio_t01_SOURCES) \ $(hio_t02_SOURCES) $(hio_t03_SOURCES) $(hio_t04_SOURCES) \ - $(hio_t05_SOURCES) $(hio_t06_SOURCES) + $(hio_t05_SOURCES) $(hio_t06_SOURCES) \ + $(am__hio_te_SOURCES_DIST) am__can_run_installinfo = \ case $$AM_UPDATE_INFO_DIR in \ n|no|NO) false;; \ @@ -383,7 +394,12 @@ hio_execd_SOURCES = execd.c hio_execd_CPPFLAGS = $(CPPFLAGS_COMMON) hio_execd_CFLAGS = $(CFLAGS_COMMON) hio_execd_LDFLAGS = $(LDFLAGS_COMMON) -hio_execd_LDADD = $(LIBADD_COMMON) +hio_execd_LDADD = $(LIBADD_COMMON) +@HAVE_X11_LIB_TRUE@hio_te_SOURCES = te.c +@HAVE_X11_LIB_TRUE@hio_te_CPPFLAGS = $(CPPFLAGS_COMMON) +@HAVE_X11_LIB_TRUE@hio_te_CFLAGS = $(CFLAGS_COMMON) +@HAVE_X11_LIB_TRUE@hio_te_LDFLAGS = $(LDFLAGS_COMMON) +@HAVE_X11_LIB_TRUE@hio_te_LDADD = $(LIBADD_COMMON) -lX11 hio_t01_SOURCES = t01.c hio_t01_CPPFLAGS = $(CPPFLAGS_COMMON) hio_t01_CFLAGS = $(CFLAGS_COMMON) @@ -401,9 +417,9 @@ hio_t03_LDFLAGS = $(LDFLAGS_COMMON) hio_t03_LDADD = $(LIBADD_COMMON) hio_t04_SOURCES = t04.c hio_t04_CPPFLAGS = $(CPPFLAGS_COMMON) -hio_t04_CFLAGS = $(CFLAGS_COMMON) $(am__append_1) -hio_t04_LDFLAGS = $(LDFLAGS_COMMON) $(am__append_2) -hio_t04_LDADD = $(LIBADD_COMMON) $(am__append_3) +hio_t04_CFLAGS = $(CFLAGS_COMMON) $(am__append_2) +hio_t04_LDFLAGS = $(LDFLAGS_COMMON) $(am__append_3) +hio_t04_LDADD = $(LIBADD_COMMON) $(am__append_4) hio_t05_SOURCES = t05.c hio_t05_CPPFLAGS = $(CPPFLAGS_COMMON) hio_t05_CFLAGS = $(CFLAGS_COMMON) @@ -525,6 +541,10 @@ hio-t06$(EXEEXT): $(hio_t06_OBJECTS) $(hio_t06_DEPENDENCIES) $(EXTRA_hio_t06_DEP @rm -f hio-t06$(EXEEXT) $(AM_V_CCLD)$(hio_t06_LINK) $(hio_t06_OBJECTS) $(hio_t06_LDADD) $(LIBS) +hio-te$(EXEEXT): $(hio_te_OBJECTS) $(hio_te_DEPENDENCIES) $(EXTRA_hio_te_DEPENDENCIES) + @rm -f hio-te$(EXEEXT) + $(AM_V_CCLD)$(hio_te_LINK) $(hio_te_OBJECTS) $(hio_te_LDADD) $(LIBS) + mostlyclean-compile: -rm -f *.$(OBJEXT) @@ -538,6 +558,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hio_t04-t04.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hio_t05-t05.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hio_t06-t06.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hio_te-te.Po@am__quote@ # am--include-marker $(am__depfiles_remade): @$(MKDIR_P) $(@D) @@ -667,6 +688,20 @@ hio_t06-t06.obj: t06.c @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(hio_t06_CPPFLAGS) $(CPPFLAGS) $(hio_t06_CFLAGS) $(CFLAGS) -c -o hio_t06-t06.obj `if test -f 't06.c'; then $(CYGPATH_W) 't06.c'; else $(CYGPATH_W) '$(srcdir)/t06.c'; fi` +hio_te-te.o: te.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(hio_te_CPPFLAGS) $(CPPFLAGS) $(hio_te_CFLAGS) $(CFLAGS) -MT hio_te-te.o -MD -MP -MF $(DEPDIR)/hio_te-te.Tpo -c -o hio_te-te.o `test -f 'te.c' || echo '$(srcdir)/'`te.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/hio_te-te.Tpo $(DEPDIR)/hio_te-te.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='te.c' object='hio_te-te.o' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(hio_te_CPPFLAGS) $(CPPFLAGS) $(hio_te_CFLAGS) $(CFLAGS) -c -o hio_te-te.o `test -f 'te.c' || echo '$(srcdir)/'`te.c + +hio_te-te.obj: te.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(hio_te_CPPFLAGS) $(CPPFLAGS) $(hio_te_CFLAGS) $(CFLAGS) -MT hio_te-te.obj -MD -MP -MF $(DEPDIR)/hio_te-te.Tpo -c -o hio_te-te.obj `if test -f 'te.c'; then $(CYGPATH_W) 'te.c'; else $(CYGPATH_W) '$(srcdir)/te.c'; fi` +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/hio_te-te.Tpo $(DEPDIR)/hio_te-te.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='te.c' object='hio_te-te.obj' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(hio_te_CPPFLAGS) $(CPPFLAGS) $(hio_te_CFLAGS) $(CFLAGS) -c -o hio_te-te.obj `if test -f 'te.c'; then $(CYGPATH_W) 'te.c'; else $(CYGPATH_W) '$(srcdir)/te.c'; fi` + mostlyclean-libtool: -rm -f *.lo @@ -807,6 +842,7 @@ distclean: distclean-am -rm -f ./$(DEPDIR)/hio_t04-t04.Po -rm -f ./$(DEPDIR)/hio_t05-t05.Po -rm -f ./$(DEPDIR)/hio_t06-t06.Po + -rm -f ./$(DEPDIR)/hio_te-te.Po -rm -f Makefile distclean-am: clean-am distclean-compile distclean-generic \ distclean-tags @@ -859,6 +895,7 @@ maintainer-clean: maintainer-clean-am -rm -f ./$(DEPDIR)/hio_t04-t04.Po -rm -f ./$(DEPDIR)/hio_t05-t05.Po -rm -f ./$(DEPDIR)/hio_t06-t06.Po + -rm -f ./$(DEPDIR)/hio_te-te.Po -rm -f Makefile maintainer-clean-am: distclean-am maintainer-clean-generic diff --git a/hio/bin/te.c b/hio/bin/te.c new file mode 100644 index 0000000..d33406d --- /dev/null +++ b/hio/bin/te.c @@ -0,0 +1,420 @@ +/* minimal terminal emulator - based on eduterm (https://www.uninformativ.de/git/eduterm/file/README.html) */ + +#include +#include +#include +#include +#include +#include + +#include +#include + +#include +#include + + +struct X11 +{ + int fd; + Display *dpy; + int screen; + Window root; + + Window termwin; + GC termgc; + unsigned long col_fg, col_bg; + int w, h; + + XFontStruct *xfont; + int font_width, font_height; + + char *buf; + int buf_w, buf_h; + int buf_x, buf_y; +}; + +struct pair_t +{ + struct X11* x11; + hio_syshnd_t pty; +}; + +#if 0 +int term_set_size(struct PTY *pty, struct X11 *x11) +{ + struct winsize ws = { + .ws_col = x11->buf_w, + .ws_row = x11->buf_h, + }; + + /* This is the very same ioctl that normal programs use to query the + * window size. Normal programs are actually able to do this, too, + * but it makes little sense: Setting the size has no effect on the + * PTY driver in the kernel (it just keeps a record of it) or the + * terminal emulator. IIUC, all that's happening is that subsequent + * ioctls will report the new size -- until another ioctl sets a new + * size. + * + * I didn't see any response to ioctls of normal programs in any of + * the popular terminals (XTerm, VTE, st). They are not informed by + * the kernel when a normal program issues an ioctl like that. + * + * On the other hand, if we were to issue this ioctl during runtime + * and the size actually changed, child programs would get a + * SIGWINCH. */ + if (ioctl(pty->master, TIOCSWINSZ, &ws) == -1) + { + perror("ioctl(TIOCSWINSZ)"); + return 0; + } + + return 1; +} +#endif + +void x11_key (XKeyEvent *ev, struct X11* x11, int pty_fd) +{ + char buf[32]; + KeySym ksym; + int len; + + len = XLookupString(ev, buf, HIO_SIZEOF(buf), &ksym, 0); + if (len > 0) write (pty_fd, buf, len); +} + +void x11_redraw(struct X11 *x11) +{ + int x, y; + char buf[1]; + + XSetForeground(x11->dpy, x11->termgc, x11->col_bg); + XFillRectangle(x11->dpy, x11->termwin, x11->termgc, 0, 0, x11->w, x11->h); + + XSetForeground(x11->dpy, x11->termgc, x11->col_fg); + for (y = 0; y < x11->buf_h; y++) + { + #if 0 + for (x = 0; x < x11->buf_w; x++) + { + buf[0] = x11->buf[y * x11->buf_w + x]; + if (!iscntrl(buf[0])) + { + XDrawString(x11->dpy, x11->termwin, x11->termgc, + x * x11->font_width, + y * x11->font_height + x11->xfont->ascent, + buf, 1); + } + } + #else + XDrawString(x11->dpy, x11->termwin, x11->termgc, + 0 * x11->font_width, + y * x11->font_height + x11->xfont->ascent, + &x11->buf[y * x11->buf_w], x11->buf_w); + #endif + } + + /* draw a cursor */ + XSetForeground(x11->dpy, x11->termgc, x11->col_fg); + XFillRectangle(x11->dpy, x11->termwin, x11->termgc, + x11->buf_x * x11->font_width, + x11->buf_y * x11->font_height, + x11->font_width, x11->font_height); + + XSync(x11->dpy, False); + //XFlush (x11->dpy); +} + +int x11_setup(struct X11 *x11) +{ + Colormap cmap; + XColor color; + XSetWindowAttributes wa = { + .background_pixmap = ParentRelative, + .event_mask = KeyPressMask | KeyReleaseMask | ExposureMask, + }; + + x11->dpy = XOpenDisplay(NULL); + if (x11->dpy == NULL) + { + fprintf(stderr, "Cannot open display\n"); + return -1; + } + + x11->screen = DefaultScreen(x11->dpy); + x11->root = RootWindow(x11->dpy, x11->screen); + x11->fd = ConnectionNumber(x11->dpy); + + x11->xfont = XLoadQueryFont(x11->dpy, "fixed"); + if (x11->xfont == NULL) + { + fprintf(stderr, "Could not load font\n"); + return -1; + } + x11->font_width = XTextWidth(x11->xfont, "m", 1); + x11->font_height = x11->xfont->ascent + x11->xfont->descent; + + cmap = DefaultColormap(x11->dpy, x11->screen); + + if (!XAllocNamedColor(x11->dpy, cmap, "#000000", &color, &color)) + { + fprintf(stderr, "Could not load bg color\n"); + return -1; + } + x11->col_bg = color.pixel; + + if (!XAllocNamedColor(x11->dpy, cmap, "#aaaaaa", &color, &color)) + { + fprintf(stderr, "Could not load fg color\n"); + return -1; + } + x11->col_fg = color.pixel; + + /* The terminal will have a fixed size of 80x25 cells. This is an + * arbitrary number. No resizing has been implemented and child + * processes can't even ask us for the current size (for now). + * + * buf_x, buf_y will be the current cursor position. */ + x11->buf_w = 80; + x11->buf_h = 25; + x11->buf_x = 0; + x11->buf_y = 0; + x11->buf = malloc(x11->buf_w * x11->buf_h); + if (x11->buf == NULL) + { + perror("calloc"); + return -1; + } + memset (x11->buf, ' ', x11->buf_w * x11->buf_h); + + x11->w = x11->buf_w * x11->font_width; + x11->h = x11->buf_h * x11->font_height; + + x11->termwin = XCreateWindow(x11->dpy, x11->root, + 0, 0, + x11->w, x11->h, + 0, + DefaultDepth(x11->dpy, x11->screen), + CopyFromParent, + DefaultVisual(x11->dpy, x11->screen), + CWBackPixmap | CWEventMask, + &wa); + XStoreName(x11->dpy, x11->termwin, "et"); + XMapWindow(x11->dpy, x11->termwin); + x11->termgc = XCreateGC(x11->dpy, x11->termwin, 0, NULL); + + XSync(x11->dpy, False); + + return 0; +} + +void x11_cleanup (struct X11* x11) +{ + XFreeGC (x11->dpy, x11->termgc); + XDestroyWindow (x11->dpy, x11->termwin); + XFreeFont (x11->dpy, x11->xfont); + XCloseDisplay (x11->dpy); + free (x11->buf); +} + +int pty_on_read (hio_dev_pty_t* dev, const void* data, hio_iolen_t len) +{ + hio_iolen_t x; + const hio_uint8_t* buf = (const hio_uint8_t*)data; + int just_wrapped = 0; + struct pair_t* p = hio_dev_pty_getxtn(dev); + struct X11* x11 = p->x11; + + for (x = 0; x < len; x++) + { + if (buf[x] == '\r') + { + x11->buf_x = 0; + } + else if (buf[x] == '\b') + { + if(x11->buf_x > 0) + { + x11->buf[x11->buf_y * x11->buf_w + x11->buf_x] = ' '; + x11->buf_x--; + } + } + else if (buf[x] == '\7') + { + /* beep */ + } + else + { + if (buf[x] != '\n') + { + /* If this is a regular byte, store it and advance + * the cursor one cell "to the right". This might + * actually wrap to the next line, see below. */ + x11->buf[x11->buf_y * x11->buf_w + x11->buf_x] = buf[x]; + x11->buf_x++; + + if (x11->buf_x >= x11->buf_w) + { + x11->buf_x = 0; + x11->buf_y++; + just_wrapped = 1; + } + else + just_wrapped = 0; + } + else if (!just_wrapped) + { + /* We read a newline and we did *not* implicitly + * wrap to the next line with the last byte we read. + * This means we must *now* advance to the next + * line. + * + * This is the same behaviour that most other + * terminals have: If you print a full line and then + * a newline, they "ignore" that newline. (Just + * think about it: A full line of text could always + * wrap to the next line implicitly, so that + * additional newline could cause the cursor to jump + * to the next line *again*.) */ + x11->buf_y++; + just_wrapped = 0; + } + + /* We now check if "the next line" is actually outside + * of the buffer. If it is, we shift the entire content + * one line up and then stay in the very last line. + * + * After the memmove(), the last line still has the old + * content. We must clear it. */ + if (x11->buf_y >= x11->buf_h) + { + int i; + memmove(x11->buf, &x11->buf[x11->buf_w], x11->buf_w * (x11->buf_h - 1)); + x11->buf_y = x11->buf_h - 1; + for (i = 0; i < x11->buf_w; i++) x11->buf[x11->buf_y * x11->buf_w + i] = ' '; + } + } + } + + x11_redraw (x11); + return 0; +} + +int pty_on_write (hio_dev_pty_t* dev, hio_iolen_t wrlen, void* wrctx) +{ + return 0; +} + +void pty_on_close (hio_dev_pty_t* dev) +{ + printf (">> pty closed....\n"); + hio_stop (hio_dev_pty_gethio(dev), HIO_STOPREQ_TERMINATION); +} + + +int shw_on_ready (hio_dev_shw_t* dev, int events) +{ + struct pair_t* p = hio_dev_shw_getxtn(dev); + struct X11* x11 = p->x11; + + /* consume data here beforehand. don't let the hio loop + * read the data */ + XEvent ev; + while (XPending(x11->dpy)) + { + XNextEvent(x11->dpy, &ev); + switch (ev.type) + { + case Expose: + x11_redraw (x11); + break; + case KeyPress: + x11_key (&ev.xkey, x11, p->pty); + break; + } + } + + /* no output via hio on the x11 connection. so let's not care about it. */ + return 0; /* don't invoke the read method */ +} + +int shw_on_read (hio_dev_shw_t* dev, const void* data, hio_iolen_t len) +{ + return 0; +} + +int shw_on_write (hio_dev_shw_t* dev, hio_iolen_t wrlen, void* wrctx) +{ + return 0; +} + +void shw_on_close (hio_dev_shw_t* dev) +{ + printf (">> shw closed....\n"); +} + +int main() +{ + hio_t* hio = HIO_NULL; + struct X11 x11; + hio_dev_pty_t* pty; + hio_dev_shw_t* shw; + + hio = hio_open(HIO_NULL, 0, HIO_NULL, HIO_FEATURE_ALL, 512, HIO_NULL); + if (!hio) + { + printf ("Cannot open hio\n"); + return -1; + } + + hio_setoption (hio, HIO_LOG_TARGET_BCSTR, "/dev/stderr"); + + if (x11_setup(&x11) <= -1) return -1; + + { + hio_dev_pty_make_t pi; + struct pair_t* pair; + + memset (&pi, 0, HIO_SIZEOF(pi)); + pi.cmd = "/bin/ksh"; + pi.flags = 0; + pi.on_write = pty_on_write; + pi.on_read = pty_on_read; + pi.on_close = pty_on_close; + pty = hio_dev_pty_make(hio, HIO_SIZEOF(*pair), &pi); + + pair = hio_dev_pty_getxtn(pty); + pair->x11 = &x11; + pair->pty = hio_dev_pty_getsyshnd(pty); + + /* + if (!term_set_size(&pty, &x11)) + return 1; + */ + } + + { + hio_dev_shw_make_t si; + struct pair_t* pair; + + memset (&si, 0, HIO_SIZEOF(si)); + si.hnd = ConnectionNumber(x11.dpy); + si.flags = HIO_DEV_SHW_KEEP_OPEN_ON_CLOSE | HIO_DEV_SHW_DISABLE_OUT | HIO_DEV_SHW_DISABLE_STREAM; + si.on_ready = shw_on_ready; + si.on_write = shw_on_write; + si.on_read = shw_on_read; + si.on_close = shw_on_close; + shw = hio_dev_shw_make(hio, HIO_SIZEOF(*pair), &si); + + pair = hio_dev_shw_getxtn(shw); + pair->x11 = &x11; + pair->pty = hio_dev_pty_getsyshnd(pty); + } + + hio_loop (hio); + + if (hio) hio_close (hio); + + x11_cleanup (&x11); + return 0; +} diff --git a/hio/configure b/hio/configure index 3659183..b49cb0c 100755 --- a/hio/configure +++ b/hio/configure @@ -644,6 +644,8 @@ PACKAGE_VERSION_PATCH PACKAGE_VERSION_MINOR PACKAGE_VERSION_MAJOR QUADMATH_LIBS +HAVE_X11_LIB_FALSE +HAVE_X11_LIB_TRUE MARIADB_LIBS MARIADB_LDFLAGS MARIADB_CFLAGS @@ -15963,6 +15965,56 @@ $as_echo "no" >&6; } +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for XOpenDisplay in -lX11" >&5 +$as_echo_n "checking for XOpenDisplay in -lX11... " >&6; } +if ${ac_cv_lib_X11_XOpenDisplay+:} false; then : + $as_echo_n "(cached) " >&6 +else + ac_check_lib_save_LIBS=$LIBS +LIBS="-lX11 $LIBS" +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char XOpenDisplay (); +int +main () +{ +return XOpenDisplay (); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + ac_cv_lib_X11_XOpenDisplay=yes +else + ac_cv_lib_X11_XOpenDisplay=no +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_X11_XOpenDisplay" >&5 +$as_echo "$ac_cv_lib_X11_XOpenDisplay" >&6; } +if test "x$ac_cv_lib_X11_XOpenDisplay" = xyes; then : + +$as_echo "#define HAVE_X11_LIB 1" >>confdefs.h + +fi + + if test "x${ac_cv_lib_X11_XOpenDisplay}" = "xyes"; then + HAVE_X11_LIB_TRUE= + HAVE_X11_LIB_FALSE='#' +else + HAVE_X11_LIB_TRUE='#' + HAVE_X11_LIB_FALSE= +fi + ac_header_dirent=no for ac_hdr in dirent.h sys/ndir.h sys/dir.h ndir.h; do @@ -19356,6 +19408,10 @@ if test -z "${ENABLE_MARIADB_TRUE}" && test -z "${ENABLE_MARIADB_FALSE}"; then as_fn_error $? "conditional \"ENABLE_MARIADB\" was never defined. Usually this means the macro was only invoked conditionally." "$LINENO" 5 fi +if test -z "${HAVE_X11_LIB_TRUE}" && test -z "${HAVE_X11_LIB_FALSE}"; then + as_fn_error $? "conditional \"HAVE_X11_LIB\" was never defined. +Usually this means the macro was only invoked conditionally." "$LINENO" 5 +fi if test -z "${ENABLE_LIBUNWIND_TRUE}" && test -z "${ENABLE_LIBUNWIND_FALSE}"; then as_fn_error $? "conditional \"ENABLE_LIBUNWIND\" was never defined. diff --git a/hio/configure.ac b/hio/configure.ac index dbd5f8a..36a86ed 100644 --- a/hio/configure.ac +++ b/hio/configure.ac @@ -315,6 +315,9 @@ fi dnl libmariadb AX_LIB_MARIADB +dnl X11 library +AC_CHECK_LIB([X11], [XOpenDisplay], [AC_DEFINE([HAVE_X11_LIB], [1], [libX11 is available])] ) +AM_CONDITIONAL(HAVE_X11_LIB, test "x${ac_cv_lib_X11_XOpenDisplay}" = "xyes") AC_STRUCT_DIRENT_D_TYPE AC_CHECK_MEMBERS([DIR.d_fd, DIR.dd_fd],,,[[#include ]]) diff --git a/hio/lib/hio-cfg.h.in b/hio/lib/hio-cfg.h.in index 1c15eec..7681638 100644 --- a/hio/lib/hio-cfg.h.in +++ b/hio/lib/hio-cfg.h.in @@ -528,6 +528,9 @@ /* Define to 1 if you have the `writev' function. */ #undef HAVE_WRITEV +/* libX11 is available */ +#undef HAVE_X11_LIB + /* Define to 1 if you have the `_vsnprintf' function. */ #undef HAVE__VSNPRINTF