From c7f2b6ad892c93b8b848d21835a4b093c424cae6 Mon Sep 17 00:00:00 2001 From: Ken Raeburn Date: Sat, 7 Nov 2015 03:06:32 -0500 Subject: [PATCH] Detect XCB and save a connection handle * configure.ac: If using X11, check for XCB libraries and header. * src/Makefile.in (XCB_LIBS): Define. (LIBX_EXTRA): Include it. * src/xterm.h [USE_XCB]: Include X11/Xlib-xcb.h. (struct x_display_info) [USE_XCB]: Add an XCB connection handle field. * src/xterm.c (x_term_init) [USE_XCB]: Initialize the new field. --- configure.ac | 15 +++++++++++++++ src/Makefile.in | 3 ++- src/xterm.c | 25 +++++++++++++++++++++++++ src/xterm.h | 8 ++++++++ 4 files changed, 50 insertions(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 5b2d9c7c59f..94ee9b7aa2b 100644 --- a/configure.ac +++ b/configure.ac @@ -3115,6 +3115,21 @@ if test "${HAVE_X11}" = "yes"; then fi fi +if test "${HAVE_X11}" = "yes"; then + AC_CHECK_HEADER(X11/Xlib-xcb.h, + AC_CHECK_LIB(xcb, xcb_translate_coordinates, HAVE_XCB=yes)) + if test "${HAVE_XCB}" = "yes"; then + AC_CHECK_LIB(X11-xcb, XGetXCBConnection, HAVE_X11_XCB=yes) + if test "${HAVE_X11_XCB}" = "yes"; then + AC_DEFINE(USE_XCB, 1, +[Define to 1 if you have the XCB library and X11-XCB library for mixed + X11/XCB programming.]) + XCB_LIBS="-lX11-xcb -lxcb" + AC_SUBST(XCB_LIBS) + fi + fi +fi + ### Use -lXpm if available, unless '--with-xpm=no'. ### mingw32 doesn't use -lXpm, since it loads the library dynamically. ### In the Cygwin-w32 build, we need to use /usr/include/noX/X11/xpm.h diff --git a/src/Makefile.in b/src/Makefile.in index f73575938d3..d667c55ee33 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -128,8 +128,9 @@ LIB_PTHREAD=@LIB_PTHREAD@ LIBIMAGE=@LIBTIFF@ @LIBJPEG@ @LIBPNG@ @LIBGIF@ @LIBXPM@ +XCB_LIBS=@XCB_LIBS@ XFT_LIBS=@XFT_LIBS@ -LIBX_EXTRA=-lX11 $(XFT_LIBS) +LIBX_EXTRA=-lX11 $(XCB_LIBS) $(XFT_LIBS) FONTCONFIG_CFLAGS = @FONTCONFIG_CFLAGS@ FONTCONFIG_LIBS = @FONTCONFIG_LIBS@ diff --git a/src/xterm.c b/src/xterm.c index 5756378bd3a..d1cf8e4d0c1 100644 --- a/src/xterm.c +++ b/src/xterm.c @@ -11773,6 +11773,9 @@ x_term_init (Lisp_Object display_name, char *xrm_option, char *resource_name) struct terminal *terminal; struct x_display_info *dpyinfo; XrmDatabase xrdb; +#ifdef USE_XCB + xcb_connection_t *xcb_conn; +#endif block_input (); @@ -11911,6 +11914,25 @@ x_term_init (Lisp_Object display_name, char *xrm_option, char *resource_name) return 0; } +#ifdef USE_XCB + xcb_conn = XGetXCBConnection (dpy); + if (xcb_conn == 0) + { +#ifdef USE_GTK + xg_display_close (dpy); +#else +#ifdef USE_X_TOOLKIT + XtCloseDisplay (dpy); +#else + XCloseDisplay (dpy); +#endif +#endif /* ! USE_GTK */ + + unblock_input (); + return 0; + } +#endif + /* We have definitely succeeded. Record the new connection. */ dpyinfo = xzalloc (sizeof *dpyinfo); @@ -11961,6 +11983,9 @@ x_term_init (Lisp_Object display_name, char *xrm_option, char *resource_name) dpyinfo->name_list_element = Fcons (display_name, Qnil); dpyinfo->display = dpy; dpyinfo->connection = ConnectionNumber (dpyinfo->display); +#ifdef USE_XCB + dpyinfo->xcb_connection = xcb_conn; +#endif /* http://lists.gnu.org/archive/html/emacs-devel/2015-11/msg00194.html */ dpyinfo->smallest_font_height = 1; diff --git a/src/xterm.h b/src/xterm.h index f7d2803ff29..192839b059e 100644 --- a/src/xterm.h +++ b/src/xterm.h @@ -87,6 +87,10 @@ typedef GtkWidget *xt_or_gtk_widget; #include #endif +#ifdef USE_XCB +#include +#endif + #include "dispextern.h" #include "termhooks.h" @@ -458,6 +462,10 @@ struct x_display_info #ifdef USE_CAIRO XExtCodes *ext_codes; #endif + +#ifdef USE_XCB + xcb_connection_t *xcb_connection; +#endif }; #ifdef HAVE_X_I18N -- 2.39.2