diff options
| author | Chong Yidong | 2008-10-07 17:46:48 +0000 |
|---|---|---|
| committer | Chong Yidong | 2008-10-07 17:46:48 +0000 |
| commit | c1ffddfc861c87e113ea87616c649e467655e575 (patch) | |
| tree | e1356647b23642c79f82129271c5351f95a5b2a8 | |
| parent | 5762590b5c7cc44684f3f026c3b979de03d343f0 (diff) | |
| download | emacs-c1ffddfc861c87e113ea87616c649e467655e575.tar.gz emacs-c1ffddfc861c87e113ea87616c649e467655e575.zip | |
(xg_display_open): Reset default display if none exists.
(xg_display_close): Allow Emacs to close all displays (bug#985).
| -rw-r--r-- | src/gtkutil.c | 43 |
1 files changed, 17 insertions, 26 deletions
diff --git a/src/gtkutil.c b/src/gtkutil.c index 16c34325644..a28156ca4e9 100644 --- a/src/gtkutil.c +++ b/src/gtkutil.c | |||
| @@ -53,13 +53,11 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ | |||
| 53 | 53 | ||
| 54 | #ifdef HAVE_GTK_MULTIDISPLAY | 54 | #ifdef HAVE_GTK_MULTIDISPLAY |
| 55 | 55 | ||
| 56 | /* Gtk does not work well without any display open. Emacs may close | 56 | /* Keep track of the default display, or NULL if there is none. Emacs |
| 57 | all its displays. In that case, keep a display around just for | 57 | may close all its displays. */ |
| 58 | the purpose of having one. */ | ||
| 59 | 58 | ||
| 60 | static GdkDisplay *gdpy_def; | 59 | static GdkDisplay *gdpy_def; |
| 61 | 60 | ||
| 62 | |||
| 63 | /* Return the GdkDisplay that corresponds to the X display DPY. */ | 61 | /* Return the GdkDisplay that corresponds to the X display DPY. */ |
| 64 | 62 | ||
| 65 | static GdkDisplay * | 63 | static GdkDisplay * |
| @@ -121,8 +119,11 @@ xg_display_open (display_name, dpy) | |||
| 121 | GdkDisplay *gdpy; | 119 | GdkDisplay *gdpy; |
| 122 | 120 | ||
| 123 | gdpy = gdk_display_open (display_name); | 121 | gdpy = gdk_display_open (display_name); |
| 124 | *dpy = gdpy ? GDK_DISPLAY_XDISPLAY (gdpy) : NULL; | 122 | if (!gdpy_def) |
| 123 | gdk_display_manager_set_default_display (gdk_display_manager_get (), | ||
| 124 | gdpy); | ||
| 125 | 125 | ||
| 126 | *dpy = gdpy ? GDK_DISPLAY_XDISPLAY (gdpy) : NULL; | ||
| 126 | return gdpy != NULL; | 127 | return gdpy != NULL; |
| 127 | 128 | ||
| 128 | #else /* not HAVE_GTK_MULTIDISPLAY */ | 129 | #else /* not HAVE_GTK_MULTIDISPLAY */ |
| @@ -140,40 +141,30 @@ xg_display_close (Display *dpy) | |||
| 140 | #ifdef HAVE_GTK_MULTIDISPLAY | 141 | #ifdef HAVE_GTK_MULTIDISPLAY |
| 141 | GdkDisplay *gdpy = gdk_x11_lookup_xdisplay (dpy); | 142 | GdkDisplay *gdpy = gdk_x11_lookup_xdisplay (dpy); |
| 142 | 143 | ||
| 143 | /* If this is the default display, we must change it before calling | 144 | /* If this is the default display, try to change it before closing. |
| 144 | dispose, otherwise it will crash on some Gtk+ versions. */ | 145 | If there is no other display to use, gdpy_def is set to NULL, and |
| 146 | the next call to xg_display_open resets the default display. */ | ||
| 145 | if (gdk_display_get_default () == gdpy) | 147 | if (gdk_display_get_default () == gdpy) |
| 146 | { | 148 | { |
| 147 | struct x_display_info *dpyinfo; | 149 | struct x_display_info *dpyinfo; |
| 148 | Display *new_dpy = 0; | 150 | GdkDisplay *gdpy_new = NULL; |
| 149 | GdkDisplay *gdpy_new; | ||
| 150 | 151 | ||
| 151 | /* Find another display. */ | 152 | /* Find another display. */ |
| 152 | for (dpyinfo = x_display_list; dpyinfo; dpyinfo = dpyinfo->next) | 153 | for (dpyinfo = x_display_list; dpyinfo; dpyinfo = dpyinfo->next) |
| 153 | if (dpyinfo->display != dpy) | 154 | if (dpyinfo->display != dpy) |
| 154 | { | 155 | { |
| 155 | new_dpy = dpyinfo->display; | 156 | gdpy_new = gdk_x11_lookup_xdisplay (dpyinfo->display); |
| 157 | gdk_display_manager_set_default_display (gdk_display_manager_get (), | ||
| 158 | gdpy_new); | ||
| 156 | break; | 159 | break; |
| 157 | } | 160 | } |
| 158 | 161 | gdpy_def = gdpy_new; | |
| 159 | if (new_dpy) | ||
| 160 | gdpy_new = gdk_x11_lookup_xdisplay (new_dpy); | ||
| 161 | else | ||
| 162 | { | ||
| 163 | if (!gdpy_def) | ||
| 164 | gdpy_def = gdk_display_open (gdk_display_get_name (gdpy)); | ||
| 165 | gdpy_new = gdpy_def; | ||
| 166 | } | ||
| 167 | |||
| 168 | gdk_display_manager_set_default_display (gdk_display_manager_get (), | ||
| 169 | gdpy_new); | ||
| 170 | } | 162 | } |
| 171 | 163 | ||
| 172 | /* GTK 2.2-2.8 has a bug that makes gdk_display_close crash (bug | ||
| 173 | http://bugzilla.gnome.org/show_bug.cgi?id=85715). This way | ||
| 174 | we can continue running, but there will be memory leaks. */ | ||
| 175 | |||
| 176 | #if GTK_MAJOR_VERSION == 2 && GTK_MINOR_VERSION < 10 | 164 | #if GTK_MAJOR_VERSION == 2 && GTK_MINOR_VERSION < 10 |
| 165 | /* GTK 2.2-2.8 has a bug that makes gdk_display_close crash (bug | ||
| 166 | http://bugzilla.gnome.org/show_bug.cgi?id=85715). This way we | ||
| 167 | can continue running, but there will be memory leaks. */ | ||
| 177 | g_object_run_dispose (G_OBJECT (gdpy)); | 168 | g_object_run_dispose (G_OBJECT (gdpy)); |
| 178 | #else | 169 | #else |
| 179 | /* This seems to be fixed in GTK 2.10. */ | 170 | /* This seems to be fixed in GTK 2.10. */ |