From: Po Lu Date: Tue, 30 Nov 2021 01:34:24 +0000 (+0800) Subject: Make interrupt input optionally work on PGTK X-Git-Tag: emacs-29.0.90~3641 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=b3277883f35c5ac9980b4ef05dc99fa8b5ce6792;p=emacs.git Make interrupt input optionally work on PGTK * src/pgtkterm.c (pgtk_delete_terminal): Close display fd if it exists. (pgtk_term_init): Set up interrupt handling for display fd if available. * src/pgtkterm.h (struct pgtk_display_info): Add `connection' field. --- diff --git a/src/pgtkterm.c b/src/pgtkterm.c index d9b2e385fc5..98143585cf9 100644 --- a/src/pgtkterm.c +++ b/src/pgtkterm.c @@ -63,6 +63,10 @@ along with GNU Emacs. If not, see . */ #include "pgtkselect.h" #include "emacsgtkfixed.h" +#ifdef GDK_WINDOWING_WAYLAND +#include +#endif + #define STORE_KEYSYM_FOR_DEBUG(keysym) ((void)0) #define FRAME_CR_CONTEXT(f) ((f)->output_data.pgtk->cr_context) @@ -4320,6 +4324,11 @@ pgtk_delete_terminal (struct terminal *terminal) dpyinfo->gdpy = NULL; } + if (dpyinfo->connection >= 0) + emacs_close (dpyinfo->connection); + + dpyinfo->connection = -1; + delete_keyboard_wait_descriptor (0); pgtk_delete_display (dpyinfo); @@ -6285,6 +6294,7 @@ pgtk_term_init (Lisp_Object display_name, char *resource_name) static int x_initialized = 0; static unsigned x_display_id = 0; static char *initial_display = NULL; + static dynlib_handle_ptr *handle = NULL; char *dpy_name; Lisp_Object lisp_dpy_name = Qnil; @@ -6456,6 +6466,49 @@ pgtk_term_init (Lisp_Object display_name, char *resource_name) dpyinfo->scroll.x_per_char = 2; dpyinfo->scroll.y_per_line = 2; + dpyinfo->connection = -1; + + if (!handle) + handle = dynlib_open (NULL); + +#ifdef GDK_WINDOWING_X11 + if (!strcmp (G_OBJECT_TYPE_NAME (dpy), "GdkX11Display") && handle) + { + void *(*gdk_x11_display_get_xdisplay) (GdkDisplay *) + = dynlib_sym (handle, "gdk_x11_display_get_xdisplay"); + int (*x_connection_number) (void *) + = dynlib_sym (handle, "XConnectionNumber"); + + if (x_connection_number + && gdk_x11_display_get_xdisplay) + dpyinfo->connection + = x_connection_number (gdk_x11_display_get_xdisplay (dpy)); + } +#endif + +#ifdef GDK_WINDOWING_WAYLAND + if (GDK_IS_WAYLAND_DISPLAY (dpy) && handle) + { + struct wl_display *wl_dpy = gdk_wayland_display_get_wl_display (dpy); + int (*display_get_fd) (struct wl_display *) + = dynlib_sym (handle, "wl_display_get_fd"); + + if (display_get_fd) + dpyinfo->connection = display_get_fd (wl_dpy); + } +#endif + + if (dpyinfo->connection >= 0) + { + add_keyboard_wait_descriptor (dpyinfo->connection); +#ifdef F_SETOWN + fcntl (dpyinfo->connection, F_SETOWN, getpid ()); +#endif /* ! defined (F_SETOWN) */ + + if (interrupt_input) + init_sigio (dpyinfo->connection); + } + x_setup_pointer_blanking (dpyinfo); xsettings_initialize (dpyinfo); diff --git a/src/pgtkterm.h b/src/pgtkterm.h index 231c8e87064..c16221da832 100644 --- a/src/pgtkterm.h +++ b/src/pgtkterm.h @@ -238,6 +238,8 @@ struct pgtk_display_info double acc_x, acc_y; double x_per_char, y_per_line; } scroll; + + int connection; }; /* This is a chain of structures for all the PGTK displays currently in use. */