]> git.eshelyaron.com Git - emacs.git/commitdiff
Make interrupt input optionally work on PGTK
authorPo Lu <luangruo@yahoo.com>
Tue, 30 Nov 2021 01:34:24 +0000 (09:34 +0800)
committerPo Lu <luangruo@yahoo.com>
Tue, 30 Nov 2021 01:34:24 +0000 (09:34 +0800)
* 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.

src/pgtkterm.c
src/pgtkterm.h

index d9b2e385fc5b061605ad40617bf12e120cf0db2f..98143585cf9d7f0619ca276c28e8ae7394ed4793 100644 (file)
@@ -63,6 +63,10 @@ along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.  */
 #include "pgtkselect.h"
 #include "emacsgtkfixed.h"
 
+#ifdef GDK_WINDOWING_WAYLAND
+#include <gdk/gdkwayland.h>
+#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);
index 231c8e8706443e5451c3f66e7d1a5d0e8c384dd7..c16221da8324aa06c520dd6df786feeffdb93e1e 100644 (file)
@@ -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.  */