Skip to content

Commit 234779f

Browse files
author
Yuuki Harano
authored
Merge pull request emacs-mirror#10 from fejfighter/pgtk-no-conn
Revert pgtkconn removal
2 parents fc4d0d1 + 3a7237c commit 234779f

File tree

5 files changed

+170
-6
lines changed

5 files changed

+170
-6
lines changed

configure.ac

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2822,7 +2822,7 @@ LIBS=$OLD_LIBS
28222822
PGTK_OBJ=
28232823
PGTK_LIBS=
28242824
if test "$window_system" = "pgtk"; then
2825-
PGTK_OBJ="pgtkfns.o pgtkterm.o pgtkselect.o pgtkmenu.o pgtkim.o xsettings.o"
2825+
PGTK_OBJ="pgtkconn.o pgtkfns.o pgtkterm.o pgtkselect.o pgtkmenu.o pgtkim.o xsettings.o"
28262826
PGTK_LIBS="$GTK_LIBS -ldl"
28272827
AC_DEFINE([HAVE_PGTK], 1, [Define to 1 if you have pure Gtk+-3.])
28282828
fi

src/pgtkconn.c

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
/* Pure Gtk+-3 communication module. -*- coding: utf-8 -*-
2+
3+
Copyright (C) 1989, 1993-1994, 2005-2006, 2008-2018 Free Software
4+
Foundation, Inc.
5+
6+
This file is part of GNU Emacs.
7+
8+
GNU Emacs is free software: you can redistribute it and/or modify
9+
it under the terms of the GNU General Public License as published by
10+
the Free Software Foundation, either version 3 of the License, or (at
11+
your option) any later version.
12+
13+
GNU Emacs is distributed in the hope that it will be useful,
14+
but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
GNU General Public License for more details.
17+
18+
You should have received a copy of the GNU General Public License
19+
along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
20+
21+
/* This should be the first include, as it may set up #defines affecting
22+
interpretation of even the system includes. */
23+
#include <config.h>
24+
25+
#include "lisp.h"
26+
#include "dynlib.h"
27+
#include "pgtkconn.h"
28+
29+
30+
/***
31+
* Detect socket to display server, with display type specific functions.
32+
***/
33+
34+
#ifdef GDK_WINDOWING_WAYLAND
35+
36+
#include <gdk/gdkwayland.h>
37+
38+
static int pgtk_detect_wayland_connection(dynlib_handle_ptr h, GdkDisplay *gdpy)
39+
{
40+
/* Check gdpy is an instance of GdkWaylandDisplay. */
41+
if (!GDK_IS_WAYLAND_DISPLAY (gdpy))
42+
return -1;
43+
44+
/* Obtain Wayland Display from GdkWaylandDisplay,
45+
and get file descriptor from it. */
46+
struct wl_display *dpy = gdk_wayland_display_get_wl_display (gdpy);
47+
48+
int (*fn)(void *) = dynlib_sym(h, "wl_display_get_fd");
49+
if (fn == NULL)
50+
return -1;
51+
return fn (dpy);
52+
}
53+
54+
#endif
55+
56+
#ifdef GDK_WINDOWING_X11
57+
58+
#include <gdk/gdkx.h>
59+
60+
static int pgtk_detect_x11_connection(dynlib_handle_ptr h, GdkDisplay *gdpy)
61+
{
62+
/* Check gdpy is an instance of GdkX11Display. */
63+
if (!GDK_IS_X11_DISPLAY (gdpy))
64+
return -1;
65+
66+
/* Obtain X Display from GdkX11Display, and get file descriptor from it. */
67+
Display *dpy = gdk_x11_display_get_xdisplay (gdpy);
68+
69+
int (*fn)(void *) = dynlib_sym(h, "XConnectionNumber");
70+
if (fn == NULL)
71+
return -1;
72+
return fn (dpy);
73+
}
74+
75+
#endif
76+
77+
int pgtk_detect_connection(GdkDisplay *gdpy)
78+
{
79+
static dynlib_handle_ptr h = NULL;
80+
int fd;
81+
82+
if (h == NULL) {
83+
if ((h = dynlib_open(NULL)) == NULL) {
84+
error("dynlib_open failed.");
85+
return -1;
86+
}
87+
}
88+
89+
#ifdef GDK_WINDOWING_X11
90+
if ((fd = pgtk_detect_x11_connection(h, gdpy)) != -1)
91+
return fd;
92+
#endif
93+
94+
#ifdef GDK_WINDOWING_WAYLAND
95+
if ((fd = pgtk_detect_wayland_connection(h, gdpy)) != -1)
96+
return fd;
97+
#endif
98+
99+
/* I don't know how to detect fd if using other backend. */
100+
101+
error("socket detection failed.");
102+
return -1;
103+
}

src/pgtkconn.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/* Definitions and headers for communication with pure Gtk+3.
2+
Copyright (C) 1989, 1993, 2005, 2008-2018 Free Software Foundation,
3+
Inc.
4+
5+
This file is part of GNU Emacs.
6+
7+
GNU Emacs is free software: you can redistribute it and/or modify
8+
it under the terms of the GNU General Public License as published by
9+
the Free Software Foundation, either version 3 of the License, or (at
10+
your option) any later version.
11+
12+
GNU Emacs is distributed in the hope that it will be useful,
13+
but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
GNU General Public License for more details.
16+
17+
You should have received a copy of the GNU General Public License
18+
along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
19+
20+
#ifdef HAVE_PGTK
21+
22+
#include <gdk/gdk.h>
23+
24+
extern int pgtk_detect_connection(GdkDisplay *gdpy);
25+
26+
#endif

src/pgtkterm.c

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
5858
#include "font.h"
5959
#include "xsettings.h"
6060
#include "pgtkselect.h"
61+
#include "pgtkconn.h"
6162

6263
#define STORE_KEYSYM_FOR_DEBUG(keysym) ((void)0)
6364

@@ -95,6 +96,7 @@ static void pgtk_clip_to_row (struct window *w, struct glyph_row *row,
9596
static struct frame *
9697
pgtk_any_window_to_frame (GdkWindow *window);
9798

99+
98100
static void evq_enqueue(union buffered_input_event *ev)
99101
{
100102
struct event_queue_t *evq = &event_q;
@@ -4302,7 +4304,17 @@ pgtk_delete_terminal (struct terminal *terminal)
43024304
dpyinfo->gdpy = NULL;
43034305
}
43044306

4305-
delete_keyboard_wait_descriptor(0);
4307+
/* ...but if called from x_connection_closed, the display may already
4308+
be closed and dpyinfo->display was set to 0 to indicate that. Since
4309+
X server is most likely gone, explicit close is the only reliable
4310+
way to continue and avoid Bug#19147. */
4311+
else if (dpyinfo->connection >= 0)
4312+
emacs_close (dpyinfo->connection);
4313+
4314+
/* No more input on this descriptor. */
4315+
delete_keyboard_wait_descriptor (dpyinfo->connection);
4316+
/* Mark as dead. */
4317+
dpyinfo->connection = -1;
43064318

43074319
pgtk_delete_display (dpyinfo);
43084320
unblock_input ();
@@ -6112,6 +6124,7 @@ pgtk_term_init (Lisp_Object display_name, char *resource_name)
61126124
static char *initial_display = NULL;
61136125
char *dpy_name;
61146126
Lisp_Object lisp_dpy_name = Qnil;
6127+
int conn_fd;
61156128

61166129
block_input ();
61176130

@@ -6127,6 +6140,11 @@ pgtk_term_init (Lisp_Object display_name, char *resource_name)
61276140
++x_initialized;
61286141
}
61296142

6143+
#if 0
6144+
if (! x_display_ok (SSDATA (display_name)))
6145+
error ("Display %s can't be opened", SSDATA (display_name));
6146+
#endif
6147+
61306148
dpy_name = SSDATA (display_name);
61316149
if (strlen(dpy_name) == 0 && initial_display != NULL)
61326150
dpy_name = initial_display;
@@ -6194,7 +6212,14 @@ pgtk_term_init (Lisp_Object display_name, char *resource_name)
61946212
return 0;
61956213
}
61966214

6215+
conn_fd = pgtk_detect_connection(dpy);
6216+
if (conn_fd < 0) {
6217+
unblock_input();
6218+
return 0;
6219+
}
6220+
61976221
/* We have definitely succeeded. Record the new connection. */
6222+
61986223
dpyinfo = xzalloc (sizeof *dpyinfo);
61996224
pgtk_initialize_display_info (dpyinfo);
62006225
terminal = pgtk_create_terminal (dpyinfo);
@@ -6226,6 +6251,7 @@ pgtk_term_init (Lisp_Object display_name, char *resource_name)
62266251

62276252
dpyinfo->name_list_element = Fcons (lisp_dpy_name, Qnil);
62286253
dpyinfo->gdpy = dpy;
6254+
dpyinfo->connection = conn_fd;
62296255

62306256
/* https://lists.gnu.org/r/emacs-devel/2015-11/msg00194.html */
62316257
dpyinfo->smallest_font_height = 1;
@@ -6271,10 +6297,16 @@ pgtk_term_init (Lisp_Object display_name, char *resource_name)
62716297

62726298
xsettings_initialize (dpyinfo);
62736299

6274-
/* According to w32term.c this will stop the emacs console handling
6275-
code from handling keyboard input when we want gtk to do that for
6276-
us */
6277-
add_keyboard_wait_descriptor (0);
6300+
/* This is only needed for distinguishing keyboard and process input. */
6301+
if (dpyinfo->connection != 0)
6302+
add_keyboard_wait_descriptor (dpyinfo->connection);
6303+
6304+
#ifdef F_SETOWN
6305+
fcntl (dpyinfo->connection, F_SETOWN, getpid ());
6306+
#endif /* ! defined (F_SETOWN) */
6307+
6308+
if (interrupt_input)
6309+
init_sigio (dpyinfo->connection);
62786310

62796311
pgtk_selection_init();
62806312

src/pgtkterm.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,9 @@ struct pgtk_display_info
131131
/* This says how to access this display in Gdk. */
132132
GdkDisplay *gdpy;
133133

134+
/* A connection number (file descriptor) for the display. */
135+
int connection;
136+
134137
/* This is a cons cell of the form (NAME . FONT-LIST-CACHE). */
135138
Lisp_Object name_list_element;
136139

0 commit comments

Comments
 (0)