aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Djärv2003-11-16 16:05:24 +0000
committerJan Djärv2003-11-16 16:05:24 +0000
commit810f2256ba03de93679ae73c02512f0da0fd1c7b (patch)
tree7d140900a63b082cbfb00d296c3b5eb30e398080
parent0bdd0f79978c5f7e6a94cde0e5fc94040de3ca66 (diff)
downloademacs-810f2256ba03de93679ae73c02512f0da0fd1c7b.tar.gz
emacs-810f2256ba03de93679ae73c02512f0da0fd1c7b.zip
Implement multiple display handling for GTK.
-rw-r--r--src/ChangeLog52
-rw-r--r--src/gtkutil.c244
-rw-r--r--src/gtkutil.h9
-rw-r--r--src/xdisp.c4
-rw-r--r--src/xfns.c38
-rw-r--r--src/xmenu.c7
-rw-r--r--src/xterm.c212
-rw-r--r--src/xterm.h5
8 files changed, 411 insertions, 160 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index 41aa2cd35fa..23ccec9571f 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,55 @@
12003-11-16 Jan Dj,Ad(Brv <jan.h.d@swipnet.se>
2
3 * xfns.c (x_window_to_frame, x_any_window_to_frame)
4 (x_non_menubar_window_to_frame, x_menubar_window_to_frame)
5 (x_top_window_to_frame): Add Display* argument to xg_win_to_widget.
6 (x_create_bitmap_mask, xg_set_icon, create_frame_xic)
7 (xic_set_statusarea, x_window, gif_load): Formatting adjustments.
8
9 * xterm.h (struct x_display_info): New field xg_cursor for GTK.
10
11 * xterm.c: Add Display * to x_window_to_scroll_bar declaration.
12 (XTmouse_position, handle_one_xevent): Pass Display* to
13 x_window_to_scroll_bar.
14 (x_window_to_scroll_bar): Take a Display* argument.
15 Check that display for frame is equal to Display* argument.
16 (event_handler_gdk): current_dpyinfo removed. Get dpyinfo from
17 x_display_info_for_display instead. Use Display in xev instead
18 of GDK_DISPLAY.
19 (x_dispatch_event): Call x_display_info_for_display.
20 (XTread_socket): Move GTK part out of loop. current_dpyinfo removed.
21 (x_connection_closed): Call xg_display_close for GTK.
22 (x_term_init): Call xg_display_open for additional displays.
23 Initiate dpyinfo->xg_cursor with call to xg_create_default_cursor
24 for GTK.
25
26 * xmenu.c (single_menu_item, mouse_position_for_popup)
27 (x_activate_menubar): Formatting adjustments.
28
29 * xdisp.c (update_tool_bar, redisplay_tool_bar): Formatting
30 adjustments.
31
32 * gtkutil.c (xg_get_gdk_display, xg_set_screen, xg_display_open)
33 (xg_display_close, xg_create_default_cursor)
34 (xg_get_gdk_pixmap_and_mask): New functions for multiple display
35 handling.
36 (xg_left_ptr_cursor): Removed.
37 (xg_set_cursor): cursor changed to GdkCursor*. Do not create
38 cursor here.
39 (xg_win_to_widget): Take Display* argument, call
40 gdk_xid_table_lookup_for_display.
41 (xg_create_frame_widgets, xg_get_file_name, create_menus)
42 (xg_create_widget, xg_modify_menubar_widgets): Call xg_set_screen.
43 (xg_create_widget, xg_create_scroll_bar): Use xg_cursor
44 in FRAME_X_DISPLAY_INFO.
45 (xg_get_scroll_id_for_window): Take Display* argument.
46 (update_frame_tool_bar): Call xg_get_gdk_pixmap_and_mask.
47 (xg_initialize): xg_left_ptr_cursor removed.
48
49 * gtkutil.h: xg_get_scroll_id_for_window, xg_win_to_widget takes
50 Display* argument also. Declare xg_display_open,
51 xg_display_close, xg_create_default_cursor.
52
12003-11-14 Jan Dj,Ad(Brv <jan.h.d@swipnet.se> 532003-11-14 Jan Dj,Ad(Brv <jan.h.d@swipnet.se>
2 54
3 * xterm.c (x_detect_focus_change): Do not change focus frame for 55 * xterm.c (x_detect_focus_change): Do not change focus frame for
diff --git a/src/gtkutil.c b/src/gtkutil.c
index b37e69481b8..4fc3351ab7e 100644
--- a/src/gtkutil.c
+++ b/src/gtkutil.c
@@ -36,9 +36,128 @@ Boston, MA 02111-1307, USA. */
36#include "coding.h" 36#include "coding.h"
37#include <gdk/gdkkeysyms.h> 37#include <gdk/gdkkeysyms.h>
38 38
39
39#define FRAME_TOTAL_PIXEL_HEIGHT(f) \ 40#define FRAME_TOTAL_PIXEL_HEIGHT(f) \
40 (FRAME_PIXEL_HEIGHT (f) + FRAME_MENUBAR_HEIGHT (f) + FRAME_TOOLBAR_HEIGHT (f)) 41 (FRAME_PIXEL_HEIGHT (f) + FRAME_MENUBAR_HEIGHT (f) + FRAME_TOOLBAR_HEIGHT (f))
41 42
43
44/***********************************************************************
45 Display handling functions
46 ***********************************************************************/
47
48#ifdef HAVE_GTK_MULTIDISPLAY
49
50/* Return the GdkDisplay that corresponds to the X display DPY. */
51static GdkDisplay *
52xg_get_gdk_display (dpy)
53 Display *dpy;
54{
55 return gdk_x11_lookup_xdisplay (dpy);
56}
57
58/* When the GTK widget W is to be created on a display for F that
59 is not the default display, set the display for W.
60 W can be a GtkMenu or a GtkWindow widget. */
61static void
62xg_set_screen (w, f)
63 GtkWidget *w;
64 FRAME_PTR f;
65{
66 if (FRAME_X_DISPLAY (f) != GDK_DISPLAY ())
67 {
68 GdkDisplay *gdpy = gdk_x11_lookup_xdisplay (FRAME_X_DISPLAY (f));
69 GdkScreen *gscreen = gdk_display_get_default_screen (gdpy);
70
71 if (GTK_IS_MENU (w))
72 gtk_menu_set_screen (GTK_MENU (w), gscreen);
73 else
74 gtk_window_set_screen (GTK_WINDOW (w), gscreen);
75 }
76}
77
78
79#else /* not HAVE_GTK_MULTIDISPLAY */
80
81/* Make some defines so we can use the GTK 2.2 functions when
82 compiling with GTK 2.0. */
83#define xg_set_screen(w, f)
84#define gdk_xid_table_lookup_for_display(dpy, w) gdk_xid_table_lookup (w)
85#define gdk_pixmap_foreign_new_for_display(dpy, p) gdk_pixmap_foreign_new (p)
86#define gdk_cursor_new_for_display(dpy, c) gdk_cursor_new (c)
87#define gdk_x11_lookup_xdisplay(dpy) 0
88#define GdkDisplay void
89
90#endif /* not HAVE_GTK_MULTIDISPLAY */
91
92/* Open a display named by DISPLAY_NAME. The display is returned in *DPY.
93 *DPY is set to NULL if the display can't be opened.
94
95 Returns non-zero if display could be opened, zero if display could not
96 be opened, and less than zero if the GTK version doesn't support
97 multipe displays. */
98int
99xg_display_open (display_name, dpy)
100 char *display_name;
101 Display **dpy;
102{
103#ifdef HAVE_GTK_MULTIDISPLAY
104 GdkDisplay *gdpy;
105
106 gdpy = gdk_display_open (display_name);
107 *dpy = gdpy ? GDK_DISPLAY_XDISPLAY (gdpy) : NULL;
108
109 return gdpy != NULL;
110
111#else /* not HAVE_GTK_MULTIDISPLAY */
112
113 return -1;
114#endif /* not HAVE_GTK_MULTIDISPLAY */
115}
116
117
118void
119xg_display_close (Display *dpy)
120{
121#ifdef HAVE_GTK_MULTIDISPLAY
122 GdkDisplay *gdpy = gdk_x11_lookup_xdisplay (dpy);
123
124 /* GTK 2.2 has a bug that makes gdk_display_close crash (bug
125 http://bugzilla.gnome.org/show_bug.cgi?id=85715). This way
126 we can continue running, but there will be memory leaks. */
127
128#if GTK_MAJOR_VERSION == 2 && GTK_MINOR_VERSION < 4
129
130 /* If this is the default display, we must change it before calling
131 dispose, otherwise it will crash. */
132 if (gdk_display_get_default () == gdpy)
133 {
134 struct x_display_info *dpyinfo;
135 Display *new_dpy = 0;
136 GdkDisplay *gdpy_new;
137
138 /* Find another display. */
139 for (dpyinfo = x_display_list; dpyinfo; dpyinfo = dpyinfo->next)
140 if (dpyinfo->display != dpy)
141 {
142 new_dpy = dpyinfo->display;
143 break;
144 }
145
146 if (! new_dpy) return; /* Emacs will exit anyway. */
147
148 gdpy_new = gdk_x11_lookup_xdisplay (new_dpy);
149 gdk_display_manager_set_default_display (gdk_display_manager_get (),
150 gdpy_new);
151 }
152
153 g_object_run_dispose (G_OBJECT (gdpy));
154
155#else
156 /* I hope this will be fixed in GTK 2.4. It is what bug 85715 says. */
157 gdk_display_close (gdpy);
158#endif
159#endif /* HAVE_GTK_MULTIDISPLAY */
160}
42 161
43 162
44/*********************************************************************** 163/***********************************************************************
@@ -48,10 +167,6 @@ Boston, MA 02111-1307, USA. */
48 NULL if no timer is started. */ 167 NULL if no timer is started. */
49static struct atimer *xg_timer; 168static struct atimer *xg_timer;
50 169
51/* The cursor used for scroll bars and popup menus.
52 We only have one cursor for all scroll bars and all popup menus. */
53static GdkCursor *xg_left_ptr_cursor;
54
55 170
56/* The next two variables and functions are taken from lwlib. */ 171/* The next two variables and functions are taken from lwlib. */
57static widget_value *widget_value_free_list; 172static widget_value *widget_value_free_list;
@@ -103,24 +218,48 @@ free_widget_value (wv)
103 } 218 }
104} 219}
105 220
106/* Set *CURSOR on W and all widgets W contain. We must do like this
107 for scroll bars and menu because they create widgets internally,
108 and it is those widgets that are visible.
109 221
110 If *CURSOR is NULL, create a GDK_LEFT_PTR cursor and set *CURSOR to 222/* Create and return the cursor to be used for popup menus and
111 the created cursor. */ 223 scroll bars on display DPY. */
112void 224GdkCursor *
225xg_create_default_cursor (dpy)
226 Display *dpy;
227{
228 GdkDisplay *gdpy = gdk_x11_lookup_xdisplay (dpy);
229 return gdk_cursor_new_for_display (gdpy, GDK_LEFT_PTR);
230}
231
232/* For the image defined in IMG, make and return a GdkPixmap for
233 the pixmap in *GPIX, and a GdkBitmap for the mask in *GMASK.
234 If IMG has no mask, *GMASK is set to NULL.
235 The image is defined on the display where frame F is. */
236static void
237xg_get_gdk_pixmap_and_mask (f, img, gpix, gmask)
238 FRAME_PTR f;
239 struct image *img;
240 GdkPixmap **gpix;
241 GdkBitmap **gmask;
242{
243 GdkDisplay *gdpy = gdk_x11_lookup_xdisplay (FRAME_X_DISPLAY (f));
244
245 *gpix = gdk_pixmap_foreign_new_for_display (gdpy, img->pixmap);
246 *gmask = img->mask ?
247 (GdkBitmap*) gdk_pixmap_foreign_new_for_display (gdpy, img->mask)
248 : 0;
249}
250
251
252/* Set CURSOR on W and all widgets W contain. We must do like this
253 for scroll bars and menu because they create widgets internally,
254 and it is those widgets that are visible. */
255static void
113xg_set_cursor (w, cursor) 256xg_set_cursor (w, cursor)
114 GtkWidget *w; 257 GtkWidget *w;
115 GdkCursor **cursor; 258 GdkCursor *cursor;
116{ 259{
117 GList *children = gdk_window_peek_children (w->window); 260 GList *children = gdk_window_peek_children (w->window);
118 261
119 /* Create the cursor unless already created. */ 262 gdk_window_set_cursor (w->window, cursor);
120 if (! *cursor)
121 *cursor = gdk_cursor_new (GDK_LEFT_PTR);
122
123 gdk_window_set_cursor (w->window, *cursor);
124 263
125 /* The scroll bar widget has more than one GDK window (had to look at 264 /* The scroll bar widget has more than one GDK window (had to look at
126 the source to figure this out), and there is no way to set cursor 265 the source to figure this out), and there is no way to set cursor
@@ -128,7 +267,7 @@ xg_set_cursor (w, cursor)
128 Ditto for menus. */ 267 Ditto for menus. */
129 268
130 for ( ; children; children = g_list_next (children)) 269 for ( ; children; children = g_list_next (children))
131 gdk_window_set_cursor (GDK_WINDOW (children->data), *cursor); 270 gdk_window_set_cursor (GDK_WINDOW (children->data), cursor);
132} 271}
133 272
134/* Timer function called when a timeout occurs for xg_timer. 273/* Timer function called when a timeout occurs for xg_timer.
@@ -381,20 +520,23 @@ xg_frame_set_char_size (f, cols, rows)
381 cancel_mouse_face (f); 520 cancel_mouse_face (f);
382} 521}
383 522
384/* Convert an X Window WSESC to its corresponding GtkWidget. 523/* Convert an X Window WSESC on display DPY to its corresponding GtkWidget.
385 Must be done like this, because GtkWidget:s can have "hidden" 524 Must be done like this, because GtkWidget:s can have "hidden"
386 X Window that aren't accessible. 525 X Window that aren't accessible.
387 526
388 Return 0 if no widget match WDESC. */ 527 Return 0 if no widget match WDESC. */
389GtkWidget * 528GtkWidget *
390xg_win_to_widget (wdesc) 529xg_win_to_widget (dpy, wdesc)
530 Display *dpy;
391 Window wdesc; 531 Window wdesc;
392{ 532{
393 gpointer gdkwin; 533 gpointer gdkwin;
394 GtkWidget *gwdesc = 0; 534 GtkWidget *gwdesc = 0;
395 535
396 BLOCK_INPUT; 536 BLOCK_INPUT;
397 gdkwin = gdk_xid_table_lookup (wdesc); 537
538 gdkwin = gdk_xid_table_lookup_for_display (gdk_x11_lookup_xdisplay (dpy),
539 wdesc);
398 if (gdkwin) 540 if (gdkwin)
399 { 541 {
400 GdkEvent event; 542 GdkEvent event;
@@ -429,9 +571,9 @@ xg_pix_to_gcolor (w, pixel, c)
429 Return TRUE to tell GTK that this expose event has been fully handeled 571 Return TRUE to tell GTK that this expose event has been fully handeled
430 and that GTK shall do nothing more with it. */ 572 and that GTK shall do nothing more with it. */
431static gboolean 573static gboolean
432xg_fixed_handle_expose(GtkWidget *widget, 574xg_fixed_handle_expose (GtkWidget *widget,
433 GdkEventExpose *event, 575 GdkEventExpose *event,
434 gpointer user_data) 576 gpointer user_data)
435{ 577{
436 GList *iter; 578 GList *iter;
437 579
@@ -483,6 +625,8 @@ xg_create_frame_widgets (f)
483 BLOCK_INPUT; 625 BLOCK_INPUT;
484 626
485 wtop = gtk_window_new (GTK_WINDOW_TOPLEVEL); 627 wtop = gtk_window_new (GTK_WINDOW_TOPLEVEL);
628 xg_set_screen (wtop, f);
629
486 wvbox = gtk_vbox_new (FALSE, 0); 630 wvbox = gtk_vbox_new (FALSE, 0);
487 wfixed = gtk_fixed_new (); /* Must have this to place scroll bars */ 631 wfixed = gtk_fixed_new (); /* Must have this to place scroll bars */
488 632
@@ -512,7 +656,8 @@ xg_create_frame_widgets (f)
512 656
513 gtk_fixed_set_has_window (GTK_FIXED (wfixed), TRUE); 657 gtk_fixed_set_has_window (GTK_FIXED (wfixed), TRUE);
514 658
515 gtk_widget_set_size_request (wfixed, FRAME_PIXEL_WIDTH (f), FRAME_PIXEL_HEIGHT (f)); 659 gtk_widget_set_size_request (wfixed, FRAME_PIXEL_WIDTH (f),
660 FRAME_PIXEL_HEIGHT (f));
516 661
517 gtk_container_add (GTK_CONTAINER (wtop), wvbox); 662 gtk_container_add (GTK_CONTAINER (wtop), wvbox);
518 gtk_box_pack_end (GTK_BOX (wvbox), wfixed, TRUE, TRUE, 0); 663 gtk_box_pack_end (GTK_BOX (wvbox), wfixed, TRUE, TRUE, 0);
@@ -963,6 +1108,8 @@ xg_get_file_name (f, prompt, default_filename, mustmatch_p)
963 filewin = gtk_file_selection_new (prompt); 1108 filewin = gtk_file_selection_new (prompt);
964 filesel = GTK_FILE_SELECTION (filewin); 1109 filesel = GTK_FILE_SELECTION (filewin);
965 1110
1111 xg_set_screen (filewin, f);
1112
966 gtk_widget_set_name (filewin, "emacs-filedialog"); 1113 gtk_widget_set_name (filewin, "emacs-filedialog");
967 1114
968 gtk_window_set_transient_for (GTK_WINDOW (filewin), 1115 gtk_window_set_transient_for (GTK_WINDOW (filewin),
@@ -1500,7 +1647,11 @@ create_menus (data, f, select_cb, deactivate_cb, highlight_cb,
1500 1647
1501 if (! topmenu) 1648 if (! topmenu)
1502 { 1649 {
1503 if (! menu_bar_p) wmenu = gtk_menu_new (); 1650 if (! menu_bar_p)
1651 {
1652 wmenu = gtk_menu_new ();
1653 xg_set_screen (wmenu, f);
1654 }
1504 else wmenu = gtk_menu_bar_new (); 1655 else wmenu = gtk_menu_bar_new ();
1505 1656
1506 /* Put cl_data on the top menu for easier access. */ 1657 /* Put cl_data on the top menu for easier access. */
@@ -1618,12 +1769,11 @@ xg_create_widget (type, name, f, val,
1618 if (strcmp (type, "dialog") == 0) 1769 if (strcmp (type, "dialog") == 0)
1619 { 1770 {
1620 w = create_dialog (val, select_cb, deactivate_cb); 1771 w = create_dialog (val, select_cb, deactivate_cb);
1772 xg_set_screen (w, f);
1621 gtk_window_set_transient_for (GTK_WINDOW (w), 1773 gtk_window_set_transient_for (GTK_WINDOW (w),
1622 GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f))); 1774 GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f)));
1623 gtk_window_set_destroy_with_parent (GTK_WINDOW (w), TRUE); 1775 gtk_window_set_destroy_with_parent (GTK_WINDOW (w), TRUE);
1624 1776 gtk_widget_set_name (w, "emacs-dialog");
1625 if (w)
1626 gtk_widget_set_name (w, "emacs-dialog");
1627 } 1777 }
1628 else if (menu_bar_p || pop_up_p) 1778 else if (menu_bar_p || pop_up_p)
1629 { 1779 {
@@ -1645,7 +1795,7 @@ xg_create_widget (type, name, f, val,
1645 { 1795 {
1646 /* Must realize so the GdkWindow inside the widget is created. */ 1796 /* Must realize so the GdkWindow inside the widget is created. */
1647 gtk_widget_realize (w); 1797 gtk_widget_realize (w);
1648 xg_set_cursor (w, &xg_left_ptr_cursor); 1798 xg_set_cursor (w, FRAME_X_DISPLAY_INFO (f)->xg_cursor);
1649 } 1799 }
1650 } 1800 }
1651 else 1801 else
@@ -2261,7 +2411,10 @@ xg_modify_menubar_widgets (menubar, f, val, deep_p,
2261 a new menu bar item, it has no sub menu yet. So we set the 2411 a new menu bar item, it has no sub menu yet. So we set the
2262 newly created sub menu under witem. */ 2412 newly created sub menu under witem. */
2263 if (newsub != sub) 2413 if (newsub != sub)
2264 gtk_menu_item_set_submenu (witem, newsub); 2414 {
2415 xg_set_screen (newsub, f);
2416 gtk_menu_item_set_submenu (witem, newsub);
2417 }
2265 } 2418 }
2266 } 2419 }
2267 2420
@@ -2417,16 +2570,17 @@ xg_get_widget_from_map (idx)
2417 return 0; 2570 return 0;
2418} 2571}
2419 2572
2420/* Return the scrollbar id for X Window WID. 2573/* Return the scrollbar id for X Window WID on display DPY.
2421 Return -1 if WID not in id_to_widget. */ 2574 Return -1 if WID not in id_to_widget. */
2422int 2575int
2423xg_get_scroll_id_for_window (wid) 2576xg_get_scroll_id_for_window (dpy, wid)
2577 Display *dpy;
2424 Window wid; 2578 Window wid;
2425{ 2579{
2426 int idx; 2580 int idx;
2427 GtkWidget *w; 2581 GtkWidget *w;
2428 2582
2429 w = xg_win_to_widget (wid); 2583 w = xg_win_to_widget (dpy, wid);
2430 2584
2431 if (w) 2585 if (w)
2432 { 2586 {
@@ -2533,7 +2687,7 @@ xg_create_scroll_bar (f, bar, scroll_callback, scroll_bar_name)
2533 wscroll, -1, -1); 2687 wscroll, -1, -1);
2534 2688
2535 /* Set the cursor to an arrow. */ 2689 /* Set the cursor to an arrow. */
2536 xg_set_cursor (wscroll, &xg_left_ptr_cursor); 2690 xg_set_cursor (wscroll, FRAME_X_DISPLAY_INFO (f)->xg_cursor);
2537 2691
2538 SET_SCROLL_BAR_X_WINDOW (bar, scroll_id); 2692 SET_SCROLL_BAR_X_WINDOW (bar, scroll_id);
2539} 2693}
@@ -2952,8 +3106,8 @@ xg_tool_bar_item_expose_callback (w, event, client_data)
2952 event->area.x -= width > event->area.width ? width-event->area.width : 0; 3106 event->area.x -= width > event->area.width ? width-event->area.width : 0;
2953 event->area.y -= height > event->area.height ? height-event->area.height : 0; 3107 event->area.y -= height > event->area.height ? height-event->area.height : 0;
2954 3108
2955 event->area.x = max(0, event->area.x); 3109 event->area.x = max (0, event->area.x);
2956 event->area.y = max(0, event->area.y); 3110 event->area.y = max (0, event->area.y);
2957 3111
2958 event->area.width = max (width, event->area.width); 3112 event->area.width = max (width, event->area.width);
2959 event->area.height = max (height, event->area.height); 3113 event->area.height = max (height, event->area.height);
@@ -2975,7 +3129,7 @@ xg_tool_bar_expose_callback (w, event, client_data)
2975 GdkEventExpose *event; 3129 GdkEventExpose *event;
2976 gpointer client_data; 3130 gpointer client_data;
2977{ 3131{
2978 update_frame_tool_bar((FRAME_PTR)client_data); 3132 update_frame_tool_bar ((FRAME_PTR) client_data);
2979 return FALSE; 3133 return FALSE;
2980} 3134}
2981 3135
@@ -3108,11 +3262,12 @@ update_frame_tool_bar (f)
3108 3262
3109 if (! wicon) 3263 if (! wicon)
3110 { 3264 {
3111 GdkPixmap *gpix = gdk_pixmap_foreign_new (img->pixmap); 3265 GdkPixmap *gpix;
3112 GdkBitmap *gmask = img->mask ? 3266 GdkBitmap *gmask;
3113 (GdkBitmap*) gdk_pixmap_foreign_new (img->mask) : 0; 3267 GtkWidget *w;
3114 3268
3115 GtkWidget *w = gtk_image_new_from_pixmap (gpix, gmask); 3269 xg_get_gdk_pixmap_and_mask (f, img, &gpix, &gmask);
3270 w = gtk_image_new_from_pixmap (gpix, gmask);
3116 gtk_toolbar_append_item (GTK_TOOLBAR (x->toolbar_widget), 3271 gtk_toolbar_append_item (GTK_TOOLBAR (x->toolbar_widget),
3117 0, 0, 0, 3272 0, 0, 0,
3118 w, 3273 w,
@@ -3170,10 +3325,10 @@ update_frame_tool_bar (f)
3170 3325
3171 if (old_img != img->pixmap) 3326 if (old_img != img->pixmap)
3172 { 3327 {
3173 GdkPixmap *gpix = gdk_pixmap_foreign_new (img->pixmap); 3328 GdkPixmap *gpix;
3174 GdkBitmap *gmask = img->mask ? 3329 GdkBitmap *gmask;
3175 (GdkBitmap*) gdk_pixmap_foreign_new (img->mask) : 0;
3176 3330
3331 xg_get_gdk_pixmap_and_mask (f, img, &gpix, &gmask);
3177 gtk_image_set_from_pixmap (wimage, gpix, gmask); 3332 gtk_image_set_from_pixmap (wimage, gpix, gmask);
3178 } 3333 }
3179 3334
@@ -3241,7 +3396,6 @@ void
3241xg_initialize () 3396xg_initialize ()
3242{ 3397{
3243 xg_ignore_gtk_scrollbar = 0; 3398 xg_ignore_gtk_scrollbar = 0;
3244 xg_left_ptr_cursor = 0;
3245 xg_detached_menus = 0; 3399 xg_detached_menus = 0;
3246 xg_menu_cb_list.prev = xg_menu_cb_list.next = 3400 xg_menu_cb_list.prev = xg_menu_cb_list.next =
3247 xg_menu_item_cb_list.prev = xg_menu_item_cb_list.next = 0; 3401 xg_menu_item_cb_list.prev = xg_menu_item_cb_list.next = 0;
diff --git a/src/gtkutil.h b/src/gtkutil.h
index 5864a334edc..b31ec8c2a1f 100644
--- a/src/gtkutil.h
+++ b/src/gtkutil.h
@@ -152,7 +152,7 @@ extern int xg_update_frame_menubar P_ ((FRAME_PTR f));
152 152
153extern int xg_have_tear_offs P_ ((void)); 153extern int xg_have_tear_offs P_ ((void));
154 154
155extern int xg_get_scroll_id_for_window P_ ((Window wid)); 155extern int xg_get_scroll_id_for_window P_ ((Display *dpy, Window wid));
156 156
157extern void xg_create_scroll_bar P_ ((FRAME_PTR f, 157extern void xg_create_scroll_bar P_ ((FRAME_PTR f,
158 struct scroll_bar *bar, 158 struct scroll_bar *bar,
@@ -184,7 +184,12 @@ extern void xg_resize_widgets P_ ((FRAME_PTR f,
184 int pixelheight)); 184 int pixelheight));
185extern void xg_frame_cleared P_ ((FRAME_PTR f)); 185extern void xg_frame_cleared P_ ((FRAME_PTR f));
186extern void xg_frame_set_char_size P_ ((FRAME_PTR f, int cols, int rows)); 186extern void xg_frame_set_char_size P_ ((FRAME_PTR f, int cols, int rows));
187extern GtkWidget * xg_win_to_widget P_ ((Window)); 187extern GtkWidget * xg_win_to_widget P_ ((Display *dpy, Window wdesc));
188
189extern int xg_display_open P_ ((char *display_name, Display **dpy));
190extern void xg_display_close P_ ((Display *dpy));
191extern GdkCursor * xg_create_default_cursor P_ ((Display *dpy));
192
188extern int xg_create_frame_widgets P_ ((FRAME_PTR f)); 193extern int xg_create_frame_widgets P_ ((FRAME_PTR f));
189extern void x_wm_set_size_hint P_ ((FRAME_PTR f, 194extern void x_wm_set_size_hint P_ ((FRAME_PTR f,
190 long flags, 195 long flags,
diff --git a/src/xdisp.c b/src/xdisp.c
index e1b13323255..8b026fefa9e 100644
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -8142,7 +8142,7 @@ update_tool_bar (f, save_match_data)
8142 int save_match_data; 8142 int save_match_data;
8143{ 8143{
8144#ifdef USE_GTK 8144#ifdef USE_GTK
8145 int do_update = FRAME_EXTERNAL_TOOL_BAR(f); 8145 int do_update = FRAME_EXTERNAL_TOOL_BAR (f);
8146#else 8146#else
8147 int do_update = WINDOWP (f->tool_bar_window) 8147 int do_update = WINDOWP (f->tool_bar_window)
8148 && WINDOW_TOTAL_LINES (XWINDOW (f->tool_bar_window)) > 0; 8148 && WINDOW_TOTAL_LINES (XWINDOW (f->tool_bar_window)) > 0;
@@ -8539,7 +8539,7 @@ redisplay_tool_bar (f)
8539 int change_height_p = 0; 8539 int change_height_p = 0;
8540 8540
8541#ifdef USE_GTK 8541#ifdef USE_GTK
8542 if (FRAME_EXTERNAL_TOOL_BAR(f)) 8542 if (FRAME_EXTERNAL_TOOL_BAR (f))
8543 update_frame_tool_bar (f); 8543 update_frame_tool_bar (f);
8544 return 0; 8544 return 0;
8545#endif 8545#endif
diff --git a/src/xfns.c b/src/xfns.c
index e4742b1d36d..cd50cbbc919 100644
--- a/src/xfns.c
+++ b/src/xfns.c
@@ -308,7 +308,7 @@ x_window_to_frame (dpyinfo, wdesc)
308#ifdef USE_GTK 308#ifdef USE_GTK
309 if (f->output_data.x->edit_widget) 309 if (f->output_data.x->edit_widget)
310 { 310 {
311 GtkWidget *gwdesc = xg_win_to_widget (wdesc); 311 GtkWidget *gwdesc = xg_win_to_widget (dpyinfo->display, wdesc);
312 struct x_output *x = f->output_data.x; 312 struct x_output *x = f->output_data.x;
313 if (gwdesc != 0 && gwdesc == x->edit_widget) 313 if (gwdesc != 0 && gwdesc == x->edit_widget)
314 return f; 314 return f;
@@ -352,7 +352,7 @@ x_any_window_to_frame (dpyinfo, wdesc)
352 else if (x->widget) 352 else if (x->widget)
353 { 353 {
354#ifdef USE_GTK 354#ifdef USE_GTK
355 GtkWidget *gwdesc = xg_win_to_widget (wdesc); 355 GtkWidget *gwdesc = xg_win_to_widget (dpyinfo->display, wdesc);
356 if (gwdesc != 0 356 if (gwdesc != 0
357 && (gwdesc == x->widget 357 && (gwdesc == x->widget
358 || gwdesc == x->edit_widget 358 || gwdesc == x->edit_widget
@@ -404,7 +404,7 @@ x_non_menubar_window_to_frame (dpyinfo, wdesc)
404 else if (x->widget) 404 else if (x->widget)
405 { 405 {
406#ifdef USE_GTK 406#ifdef USE_GTK
407 GtkWidget *gwdesc = xg_win_to_widget (wdesc); 407 GtkWidget *gwdesc = xg_win_to_widget (dpyinfo->display, wdesc);
408 if (gwdesc != 0 408 if (gwdesc != 0
409 && (gwdesc == x->widget 409 && (gwdesc == x->widget
410 || gwdesc == x->edit_widget 410 || gwdesc == x->edit_widget
@@ -448,7 +448,7 @@ x_menubar_window_to_frame (dpyinfo, wdesc)
448#ifdef USE_GTK 448#ifdef USE_GTK
449 if (x->menubar_widget) 449 if (x->menubar_widget)
450 { 450 {
451 GtkWidget *gwdesc = xg_win_to_widget (wdesc); 451 GtkWidget *gwdesc = xg_win_to_widget (dpyinfo->display, wdesc);
452 int found = 0; 452 int found = 0;
453 453
454 BLOCK_INPUT; 454 BLOCK_INPUT;
@@ -494,7 +494,7 @@ x_top_window_to_frame (dpyinfo, wdesc)
494 { 494 {
495 /* This frame matches if the window is its topmost widget. */ 495 /* This frame matches if the window is its topmost widget. */
496#ifdef USE_GTK 496#ifdef USE_GTK
497 GtkWidget *gwdesc = xg_win_to_widget (wdesc); 497 GtkWidget *gwdesc = xg_win_to_widget (dpyinfo->display, wdesc);
498 if (gwdesc == x->widget) 498 if (gwdesc == x->widget)
499 return f; 499 return f;
500#else 500#else
@@ -762,7 +762,7 @@ static void x_destroy_x_image P_ ((XImage *ximg));
762 It's nicer with some borders in this context */ 762 It's nicer with some borders in this context */
763 763
764int 764int
765x_create_bitmap_mask(f, id) 765x_create_bitmap_mask (f, id)
766 struct frame *f; 766 struct frame *f;
767 int id; 767 int id;
768{ 768{
@@ -780,9 +780,9 @@ x_create_bitmap_mask(f, id)
780 if (!(id > 0)) 780 if (!(id > 0))
781 return -1; 781 return -1;
782 782
783 pixmap = x_bitmap_pixmap(f, id); 783 pixmap = x_bitmap_pixmap (f, id);
784 width = x_bitmap_width(f, id); 784 width = x_bitmap_width (f, id);
785 height = x_bitmap_height(f, id); 785 height = x_bitmap_height (f, id);
786 786
787 BLOCK_INPUT; 787 BLOCK_INPUT;
788 ximg = XGetImage (FRAME_X_DISPLAY (f), pixmap, 0, 0, width, height, 788 ximg = XGetImage (FRAME_X_DISPLAY (f), pixmap, 0, 0, width, height,
@@ -799,7 +799,7 @@ x_create_bitmap_mask(f, id)
799 UNBLOCK_INPUT; 799 UNBLOCK_INPUT;
800 if (!result) 800 if (!result)
801 { 801 {
802 XDestroyImage(ximg); 802 XDestroyImage (ximg);
803 return -1; 803 return -1;
804 } 804 }
805 805
@@ -838,7 +838,7 @@ x_create_bitmap_mask(f, id)
838 dpyinfo->bitmaps[id - 1].mask = mask; 838 dpyinfo->bitmaps[id - 1].mask = mask;
839 839
840 XDestroyImage (ximg); 840 XDestroyImage (ximg);
841 x_destroy_x_image(mask_img); 841 x_destroy_x_image (mask_img);
842 842
843 return 0; 843 return 0;
844} 844}
@@ -1106,7 +1106,7 @@ static Lisp_Object x_find_image_file P_ ((Lisp_Object file));
1106 may be any format that GdkPixbuf knows about, i.e. not just bitmaps. */ 1106 may be any format that GdkPixbuf knows about, i.e. not just bitmaps. */
1107 1107
1108int 1108int
1109xg_set_icon(f, file) 1109xg_set_icon (f, file)
1110 FRAME_PTR f; 1110 FRAME_PTR f;
1111 Lisp_Object file; 1111 Lisp_Object file;
1112{ 1112{
@@ -2458,8 +2458,8 @@ create_frame_xic (f)
2458 2458
2459 xic = XCreateIC (xim, 2459 xic = XCreateIC (xim,
2460 XNInputStyle, xic_style, 2460 XNInputStyle, xic_style,
2461 XNClientWindow, FRAME_X_WINDOW(f), 2461 XNClientWindow, FRAME_X_WINDOW (f),
2462 XNFocusWindow, FRAME_X_WINDOW(f), 2462 XNFocusWindow, FRAME_X_WINDOW (f),
2463 XNStatusAttributes, status_attr, 2463 XNStatusAttributes, status_attr,
2464 XNPreeditAttributes, preedit_attr, 2464 XNPreeditAttributes, preedit_attr,
2465 NULL); 2465 NULL);
@@ -2550,7 +2550,7 @@ xic_set_statusarea (f)
2550 XFree (needed); 2550 XFree (needed);
2551 2551
2552 attr = XVaCreateNestedList (0, XNArea, &area, NULL); 2552 attr = XVaCreateNestedList (0, XNArea, &area, NULL);
2553 XSetICValues(xic, XNStatusAttributes, attr, NULL); 2553 XSetICValues (xic, XNStatusAttributes, attr, NULL);
2554 XFree (attr); 2554 XFree (attr);
2555} 2555}
2556 2556
@@ -2793,7 +2793,7 @@ x_window (f, window_prompting, minibuffer_only)
2793 { 2793 {
2794 /* XIM server might require some X events. */ 2794 /* XIM server might require some X events. */
2795 unsigned long fevent = NoEventMask; 2795 unsigned long fevent = NoEventMask;
2796 XGetICValues(FRAME_XIC (f), XNFilterEvents, &fevent, NULL); 2796 XGetICValues (FRAME_XIC (f), XNFilterEvents, &fevent, NULL);
2797 attributes.event_mask |= fevent; 2797 attributes.event_mask |= fevent;
2798 } 2798 }
2799#endif /* HAVE_X_I18N */ 2799#endif /* HAVE_X_I18N */
@@ -2847,7 +2847,7 @@ if (use_xim)
2847 { 2847 {
2848 /* XIM server might require some X events. */ 2848 /* XIM server might require some X events. */
2849 unsigned long fevent = NoEventMask; 2849 unsigned long fevent = NoEventMask;
2850 XGetICValues(FRAME_XIC (f), XNFilterEvents, &fevent, NULL); 2850 XGetICValues (FRAME_XIC (f), XNFilterEvents, &fevent, NULL);
2851 2851
2852 if (fevent != NoEventMask) 2852 if (fevent != NoEventMask)
2853 { 2853 {
@@ -2911,7 +2911,7 @@ x_window (f)
2911 { 2911 {
2912 /* XIM server might require some X events. */ 2912 /* XIM server might require some X events. */
2913 unsigned long fevent = NoEventMask; 2913 unsigned long fevent = NoEventMask;
2914 XGetICValues(FRAME_XIC (f), XNFilterEvents, &fevent, NULL); 2914 XGetICValues (FRAME_XIC (f), XNFilterEvents, &fevent, NULL);
2915 attributes.event_mask |= fevent; 2915 attributes.event_mask |= fevent;
2916 attribute_mask = CWEventMask; 2916 attribute_mask = CWEventMask;
2917 XChangeWindowAttributes (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), 2917 XChangeWindowAttributes (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
@@ -9166,7 +9166,7 @@ gif_load (f, img)
9166 memsrc.len = SBYTES (specified_data); 9166 memsrc.len = SBYTES (specified_data);
9167 memsrc.index = 0; 9167 memsrc.index = 0;
9168 9168
9169 gif = DGifOpen(&memsrc, gif_read_from_memory); 9169 gif = DGifOpen (&memsrc, gif_read_from_memory);
9170 if (!gif) 9170 if (!gif)
9171 { 9171 {
9172 image_error ("Cannot open memory source `%s'", img->spec, Qnil); 9172 image_error ("Cannot open memory source `%s'", img->spec, Qnil);
diff --git a/src/xmenu.c b/src/xmenu.c
index 14f7485759b..3e99a1c506d 100644
--- a/src/xmenu.c
+++ b/src/xmenu.c
@@ -610,7 +610,7 @@ single_menu_item (key, item, dummy, skp_v)
610#endif /* not HAVE_BOXES */ 610#endif /* not HAVE_BOXES */
611 611
612#if ! defined (USE_X_TOOLKIT) && ! defined (USE_GTK) 612#if ! defined (USE_X_TOOLKIT) && ! defined (USE_GTK)
613 if (!NILP(map)) 613 if (!NILP (map))
614 /* Indicate visually that this is a submenu. */ 614 /* Indicate visually that this is a submenu. */
615 item_string = concat2 (item_string, build_string (" >")); 615 item_string = concat2 (item_string, build_string (" >"));
616#endif 616#endif
@@ -696,7 +696,7 @@ list_of_items (pane)
696 the scroll bar or the edit window. Fx_popup_menu needs to be 696 the scroll bar or the edit window. Fx_popup_menu needs to be
697 sure it is the edit window. */ 697 sure it is the edit window. */
698static void 698static void
699mouse_position_for_popup(f, x, y) 699mouse_position_for_popup (f, x, y)
700 FRAME_PTR f; 700 FRAME_PTR f;
701 int *x; 701 int *x;
702 int *y; 702 int *y;
@@ -1217,7 +1217,8 @@ x_activate_menubar (f)
1217 return; 1217 return;
1218 1218
1219#ifdef USE_GTK 1219#ifdef USE_GTK
1220 if (! xg_win_to_widget (f->output_data.x->saved_menu_event->xany.window)) 1220 if (! xg_win_to_widget (FRAME_X_DISPLAY (f),
1221 f->output_data.x->saved_menu_event->xany.window))
1221 return; 1222 return;
1222#endif 1223#endif
1223 1224
diff --git a/src/xterm.c b/src/xterm.c
index 85beb00eb52..a5f6c959cec 100644
--- a/src/xterm.c
+++ b/src/xterm.c
@@ -357,7 +357,7 @@ static void x_flush P_ ((struct frame *f));
357static void x_update_begin P_ ((struct frame *)); 357static void x_update_begin P_ ((struct frame *));
358static void x_update_window_begin P_ ((struct window *)); 358static void x_update_window_begin P_ ((struct window *));
359static void x_after_update_window_line P_ ((struct glyph_row *)); 359static void x_after_update_window_line P_ ((struct glyph_row *));
360static struct scroll_bar *x_window_to_scroll_bar P_ ((Window)); 360static struct scroll_bar *x_window_to_scroll_bar P_ ((Display *, Window));
361static void x_scroll_bar_report_motion P_ ((struct frame **, Lisp_Object *, 361static void x_scroll_bar_report_motion P_ ((struct frame **, Lisp_Object *,
362 enum scroll_bar_part *, 362 enum scroll_bar_part *,
363 Lisp_Object *, Lisp_Object *, 363 Lisp_Object *, Lisp_Object *,
@@ -3777,7 +3777,9 @@ XTmouse_position (fp, insist, bar_window, part, x, y, time)
3777 /* If not, is it one of our scroll bars? */ 3777 /* If not, is it one of our scroll bars? */
3778 if (! f1) 3778 if (! f1)
3779 { 3779 {
3780 struct scroll_bar *bar = x_window_to_scroll_bar (win); 3780 struct scroll_bar *bar;
3781
3782 bar = x_window_to_scroll_bar (FRAME_X_DISPLAY (*fp), win);
3781 3783
3782 if (bar) 3784 if (bar)
3783 { 3785 {
@@ -3848,18 +3850,20 @@ XTmouse_position (fp, insist, bar_window, part, x, y, time)
3848 3850
3849/* Scroll bar support. */ 3851/* Scroll bar support. */
3850 3852
3851/* Given an X window ID, find the struct scroll_bar which manages it. 3853/* Given an X window ID and a DISPLAY, find the struct scroll_bar which
3854 manages it.
3852 This can be called in GC, so we have to make sure to strip off mark 3855 This can be called in GC, so we have to make sure to strip off mark
3853 bits. */ 3856 bits. */
3854 3857
3855static struct scroll_bar * 3858static struct scroll_bar *
3856x_window_to_scroll_bar (window_id) 3859x_window_to_scroll_bar (display, window_id)
3860 Display *display;
3857 Window window_id; 3861 Window window_id;
3858{ 3862{
3859 Lisp_Object tail; 3863 Lisp_Object tail;
3860 3864
3861#ifdef USE_GTK 3865#ifdef USE_GTK
3862 window_id = (Window) xg_get_scroll_id_for_window (window_id); 3866 window_id = (Window) xg_get_scroll_id_for_window (display, window_id);
3863#endif /* USE_GTK */ 3867#endif /* USE_GTK */
3864 3868
3865 for (tail = Vframe_list; 3869 for (tail = Vframe_list;
@@ -3873,6 +3877,9 @@ x_window_to_scroll_bar (window_id)
3873 if (! GC_FRAMEP (frame)) 3877 if (! GC_FRAMEP (frame))
3874 abort (); 3878 abort ();
3875 3879
3880 if (FRAME_X_DISPLAY (XFRAME (frame)) != display)
3881 continue;
3882
3876 /* Scan this frame's scroll bar list for a scroll bar with the 3883 /* Scan this frame's scroll bar list for a scroll bar with the
3877 right window ID. */ 3884 right window ID. */
3878 condemned = FRAME_CONDEMNED_SCROLL_BARS (XFRAME (frame)); 3885 condemned = FRAME_CONDEMNED_SCROLL_BARS (XFRAME (frame));
@@ -5669,7 +5676,6 @@ x_filter_event (dpyinfo, event)
5669#endif 5676#endif
5670 5677
5671#ifdef USE_GTK 5678#ifdef USE_GTK
5672static struct x_display_info *current_dpyinfo;
5673static struct input_event **current_bufp; 5679static struct input_event **current_bufp;
5674static int *current_numcharsp; 5680static int *current_numcharsp;
5675static int current_count; 5681static int current_count;
@@ -5684,26 +5690,34 @@ event_handler_gdk (gxev, ev, data)
5684 GdkEvent *ev; 5690 GdkEvent *ev;
5685 gpointer data; 5691 gpointer data;
5686{ 5692{
5687 XEvent *xev = (XEvent*)gxev; 5693 XEvent *xev = (XEvent *) gxev;
5688 5694
5689 if (current_numcharsp) 5695 if (current_numcharsp)
5690 { 5696 {
5697 struct x_display_info *dpyinfo;
5698
5699 dpyinfo = x_display_info_for_display (xev->xany.display);
5700
5691#ifdef HAVE_X_I18N 5701#ifdef HAVE_X_I18N
5692 /* Filter events for the current X input method. 5702 /* Filter events for the current X input method.
5693 GTK calls XFilterEvent but not for key press and release, 5703 GTK calls XFilterEvent but not for key press and release,
5694 so we do it here. */ 5704 so we do it here. */
5695 if (xev->type == KeyPress || xev->type == KeyRelease) 5705 if (xev->type == KeyPress || xev->type == KeyRelease)
5696 if (x_filter_event (current_dpyinfo, xev)) 5706 if (dpyinfo && x_filter_event (dpyinfo, xev))
5697 return GDK_FILTER_REMOVE; 5707 return GDK_FILTER_REMOVE;
5698#endif 5708#endif
5699 current_count += handle_one_xevent (current_dpyinfo, 5709
5700 xev, 5710 if (! dpyinfo)
5701 current_bufp, 5711 current_finish = X_EVENT_NORMAL;
5702 current_numcharsp, 5712 else
5703 &current_finish); 5713 current_count += handle_one_xevent (dpyinfo,
5714 xev,
5715 current_bufp,
5716 current_numcharsp,
5717 &current_finish);
5704 } 5718 }
5705 else 5719 else
5706 current_finish = x_dispatch_event (xev, GDK_DISPLAY ()); 5720 current_finish = x_dispatch_event (xev, xev->xany.display);
5707 5721
5708 if (current_finish == X_EVENT_GOTO_OUT || current_finish == X_EVENT_DROP) 5722 if (current_finish == X_EVENT_GOTO_OUT || current_finish == X_EVENT_DROP)
5709 return GDK_FILTER_REMOVE; 5723 return GDK_FILTER_REMOVE;
@@ -6043,7 +6057,8 @@ handle_one_xevent (dpyinfo, eventp, bufp_r, numcharsp, finish)
6043 /* Dispatch event to the widget. */ 6057 /* Dispatch event to the widget. */
6044 goto OTHER; 6058 goto OTHER;
6045#else /* not USE_TOOLKIT_SCROLL_BARS */ 6059#else /* not USE_TOOLKIT_SCROLL_BARS */
6046 bar = x_window_to_scroll_bar (event.xexpose.window); 6060 bar = x_window_to_scroll_bar (event.xexpose.display,
6061 event.xexpose.window);
6047 6062
6048 if (bar) 6063 if (bar)
6049 x_scroll_bar_expose (bar, &event); 6064 x_scroll_bar_expose (bar, &event);
@@ -6669,7 +6684,7 @@ handle_one_xevent (dpyinfo, eventp, bufp_r, numcharsp, finish)
6669 /* Window will be selected only when it is not selected now and 6684 /* Window will be selected only when it is not selected now and
6670 last mouse movement event was not in it. Minibuffer window 6685 last mouse movement event was not in it. Minibuffer window
6671 will be selected iff it is active. */ 6686 will be selected iff it is active. */
6672 if (WINDOWP(window) 6687 if (WINDOWP (window)
6673 && !EQ (window, last_window) 6688 && !EQ (window, last_window)
6674 && !EQ (window, selected_window) 6689 && !EQ (window, selected_window)
6675 && numchars > 0) 6690 && numchars > 0)
@@ -6688,7 +6703,8 @@ handle_one_xevent (dpyinfo, eventp, bufp_r, numcharsp, finish)
6688 { 6703 {
6689#ifndef USE_TOOLKIT_SCROLL_BARS 6704#ifndef USE_TOOLKIT_SCROLL_BARS
6690 struct scroll_bar *bar 6705 struct scroll_bar *bar
6691 = x_window_to_scroll_bar (event.xmotion.window); 6706 = x_window_to_scroll_bar (event.xmotion.display,
6707 event.xmotion.window);
6692 6708
6693 if (bar) 6709 if (bar)
6694 x_scroll_bar_note_movement (bar, &event); 6710 x_scroll_bar_note_movement (bar, &event);
@@ -6851,7 +6867,8 @@ handle_one_xevent (dpyinfo, eventp, bufp_r, numcharsp, finish)
6851 else 6867 else
6852 { 6868 {
6853 struct scroll_bar *bar 6869 struct scroll_bar *bar
6854 = x_window_to_scroll_bar (event.xbutton.window); 6870 = x_window_to_scroll_bar (event.xbutton.display,
6871 event.xbutton.window);
6855 6872
6856#ifdef USE_TOOLKIT_SCROLL_BARS 6873#ifdef USE_TOOLKIT_SCROLL_BARS
6857 /* Make the "Ctrl-Mouse-2 splits window" work for toolkit 6874 /* Make the "Ctrl-Mouse-2 splits window" work for toolkit
@@ -7012,9 +7029,7 @@ x_dispatch_event (event, display)
7012 EVENT_INIT (*bufpp); 7029 EVENT_INIT (*bufpp);
7013 bufpp = bufp; 7030 bufpp = bufp;
7014 7031
7015 for (dpyinfo = x_display_list; dpyinfo; dpyinfo = dpyinfo->next) 7032 dpyinfo = x_display_info_for_display (display);
7016 if (dpyinfo->display == display)
7017 break;
7018 7033
7019 if (dpyinfo) 7034 if (dpyinfo)
7020 { 7035 {
@@ -7116,30 +7131,7 @@ XTread_socket (sd, bufp, numchars, expected)
7116 UNBLOCK_INPUT; 7131 UNBLOCK_INPUT;
7117#endif 7132#endif
7118 7133
7119#ifdef USE_GTK 7134#ifndef USE_GTK
7120 /* For GTK we must use the GTK event loop. But XEvents gets passed
7121 to our filter function above, and then to the big event switch.
7122 We use a bunch of globals to communicate with our filter function,
7123 that is kind of ugly, but it works. */
7124 current_dpyinfo = dpyinfo;
7125
7126 while (gtk_events_pending ())
7127 {
7128 current_count = count;
7129 current_numcharsp = &numchars;
7130 current_bufp = &bufp;
7131
7132 gtk_main_iteration ();
7133
7134 count = current_count;
7135 current_bufp = 0;
7136 current_numcharsp = 0;
7137
7138 if (current_finish == X_EVENT_GOTO_OUT)
7139 goto out;
7140 }
7141
7142#else /* not USE_GTK */
7143 while (XPending (dpyinfo->display)) 7135 while (XPending (dpyinfo->display))
7144 { 7136 {
7145 int finish; 7137 int finish;
@@ -7162,8 +7154,35 @@ XTread_socket (sd, bufp, numchars, expected)
7162 if (finish == X_EVENT_GOTO_OUT) 7154 if (finish == X_EVENT_GOTO_OUT)
7163 goto out; 7155 goto out;
7164 } 7156 }
7165#endif /* USE_GTK */ 7157#endif /* not USE_GTK */
7158 }
7159
7160#ifdef USE_GTK
7161
7162 /* For GTK we must use the GTK event loop. But XEvents gets passed
7163 to our filter function above, and then to the big event switch.
7164 We use a bunch of globals to communicate with our filter function,
7165 that is kind of ugly, but it works.
7166
7167 There is no way to do one display at the time, GTK just does events
7168 from all displays. */
7169
7170 while (gtk_events_pending ())
7171 {
7172 current_count = count;
7173 current_numcharsp = &numchars;
7174 current_bufp = &bufp;
7175
7176 gtk_main_iteration ();
7177
7178 count = current_count;
7179 current_bufp = 0;
7180 current_numcharsp = 0;
7181
7182 if (current_finish == X_EVENT_GOTO_OUT)
7183 break;
7166 } 7184 }
7185#endif /* USE_GTK */
7167 7186
7168 out:; 7187 out:;
7169 7188
@@ -7482,13 +7501,13 @@ x_bitmap_icon (f, file)
7482 if (STRINGP (file)) 7501 if (STRINGP (file))
7483 { 7502 {
7484#ifdef USE_GTK 7503#ifdef USE_GTK
7485 /* Use gtk_window_set_icon_from_file() if available, 7504 /* Use gtk_window_set_icon_from_file () if available,
7486 It's not restricted to bitmaps */ 7505 It's not restricted to bitmaps */
7487 if (xg_set_icon(f, file)) 7506 if (xg_set_icon (f, file))
7488 return 0; 7507 return 0;
7489#endif /* USE_GTK */ 7508#endif /* USE_GTK */
7490 bitmap_id = x_create_bitmap_from_file (f, file); 7509 bitmap_id = x_create_bitmap_from_file (f, file);
7491 x_create_bitmap_mask(f, bitmap_id); 7510 x_create_bitmap_mask (f, bitmap_id);
7492 } 7511 }
7493 else 7512 else
7494 { 7513 {
@@ -7498,7 +7517,7 @@ x_bitmap_icon (f, file)
7498 FRAME_X_DISPLAY_INFO (f)->icon_bitmap_id 7517 FRAME_X_DISPLAY_INFO (f)->icon_bitmap_id
7499 = x_create_bitmap_from_data (f, gnu_bits, 7518 = x_create_bitmap_from_data (f, gnu_bits,
7500 gnu_width, gnu_height); 7519 gnu_width, gnu_height);
7501 x_create_bitmap_mask(f, FRAME_X_DISPLAY_INFO (f)->icon_bitmap_id); 7520 x_create_bitmap_mask (f, FRAME_X_DISPLAY_INFO (f)->icon_bitmap_id);
7502 } 7521 }
7503 7522
7504 /* The first time we create the GNU bitmap and mask, 7523 /* The first time we create the GNU bitmap and mask,
@@ -7767,6 +7786,11 @@ x_connection_closed (dpy, error_message)
7767 } 7786 }
7768#endif 7787#endif
7769 7788
7789#ifdef USE_GTK
7790 if (dpyinfo)
7791 xg_display_close (dpyinfo->display);
7792#endif
7793
7770 /* Indicate that this display is dead. */ 7794 /* Indicate that this display is dead. */
7771 if (dpyinfo) 7795 if (dpyinfo)
7772 dpyinfo->display = 0; 7796 dpyinfo->display = 0;
@@ -10211,60 +10235,65 @@ x_term_init (display_name, xrm_option, resource_name)
10211 char **argv2 = argv; 10235 char **argv2 = argv;
10212 GdkAtom atom; 10236 GdkAtom atom;
10213 10237
10214 /* GTK 2.0 can only handle one display, GTK 2.2 can handle more 10238 if (x_initialized++ > 1)
10215 than one, but this remains to be implemented. */ 10239 {
10216 if (x_initialized > 1) 10240 /* Opening another display. If xg_display_open returns less
10217 error ("Sorry, the GTK port can only handle one display."); 10241 than zero, we are probably on GTK 2.0, which can only handle
10218 ++x_initialized; 10242 one display. GTK 2.2 or later can handle more than one. */
10219 10243 if (xg_display_open (SDATA (display_name), &dpy) < 0)
10220 for (argc = 0; argc < NUM_ARGV; ++argc) 10244 error ("Sorry, this version of GTK can only handle one display");
10221 argv[argc] = 0; 10245 }
10246 else
10247 {
10248 for (argc = 0; argc < NUM_ARGV; ++argc)
10249 argv[argc] = 0;
10222 10250
10223 argc = 0; 10251 argc = 0;
10224 argv[argc++] = initial_argv[0]; 10252 argv[argc++] = initial_argv[0];
10225 10253
10226 if (! NILP (display_name)) 10254 if (! NILP (display_name))
10227 { 10255 {
10228 argv[argc++] = "--display"; 10256 argv[argc++] = "--display";
10229 argv[argc++] = SDATA (display_name); 10257 argv[argc++] = SDATA (display_name);
10230 } 10258 }
10231 10259
10232 argv[argc++] = "--name"; 10260 argv[argc++] = "--name";
10233 argv[argc++] = resource_name; 10261 argv[argc++] = resource_name;
10234 10262
10235#ifdef HAVE_X11R5 10263#ifdef HAVE_X11R5
10236 XSetLocaleModifiers (""); 10264 XSetLocaleModifiers ("");
10237#endif 10265#endif
10238 10266
10239 gtk_init (&argc, &argv2); 10267 gtk_init (&argc, &argv2);
10240 10268
10241 /* gtk_init does set_locale. We must fix locale after calling it. */ 10269 /* gtk_init does set_locale. We must fix locale after calling it. */
10242 fixup_locale (); 10270 fixup_locale ();
10243 xg_initialize (); 10271 xg_initialize ();
10244 10272
10245 dpy = GDK_DISPLAY (); 10273 dpy = GDK_DISPLAY ();
10246 10274
10247 /* NULL window -> events for all windows go to our function */ 10275 /* NULL window -> events for all windows go to our function */
10248 gdk_window_add_filter (NULL, event_handler_gdk, NULL); 10276 gdk_window_add_filter (NULL, event_handler_gdk, NULL);
10249 10277
10250 /* Load our own gtkrc if it exists. */ 10278 /* Load our own gtkrc if it exists. */
10251 { 10279 {
10252 struct gcpro gcpro1, gcpro2; 10280 struct gcpro gcpro1, gcpro2;
10253 char *file = "~/.emacs.d/gtkrc"; 10281 char *file = "~/.emacs.d/gtkrc";
10254 Lisp_Object s, abs_file; 10282 Lisp_Object s, abs_file;
10255 10283
10256 GCPRO2 (s, abs_file); 10284 GCPRO2 (s, abs_file);
10257 s = make_string (file, strlen (file)); 10285 s = make_string (file, strlen (file));
10258 abs_file = Fexpand_file_name(s, Qnil); 10286 abs_file = Fexpand_file_name (s, Qnil);
10259 10287
10260 if (! NILP (abs_file) && !NILP (Ffile_readable_p (abs_file))) 10288 if (! NILP (abs_file) && !NILP (Ffile_readable_p (abs_file)))
10261 gtk_rc_parse (SDATA (abs_file)); 10289 gtk_rc_parse (SDATA (abs_file));
10262 10290
10263 UNGCPRO; 10291 UNGCPRO;
10264 } 10292 }
10265 10293
10266 XSetErrorHandler (x_error_handler); 10294 XSetErrorHandler (x_error_handler);
10267 XSetIOErrorHandler (x_io_error_quitter); 10295 XSetIOErrorHandler (x_io_error_quitter);
10296 }
10268 } 10297 }
10269#else /* not USE_GTK */ 10298#else /* not USE_GTK */
10270#ifdef USE_X_TOOLKIT 10299#ifdef USE_X_TOOLKIT
@@ -10385,6 +10414,11 @@ x_term_init (display_name, xrm_option, resource_name)
10385 x_find_modifier_meanings (dpyinfo); 10414 x_find_modifier_meanings (dpyinfo);
10386 10415
10387 /* Get the scroll bar cursor. */ 10416 /* Get the scroll bar cursor. */
10417#ifdef USE_GTK
10418 /* We must create a GTK cursor, it is required for GTK widgets. */
10419 dpyinfo->xg_cursor = xg_create_default_cursor (dpyinfo->display);
10420#endif /* USE_GTK */
10421
10388 dpyinfo->vertical_scroll_bar_cursor 10422 dpyinfo->vertical_scroll_bar_cursor
10389 = XCreateFontCursor (dpyinfo->display, XC_sb_v_double_arrow); 10423 = XCreateFontCursor (dpyinfo->display, XC_sb_v_double_arrow);
10390 10424
diff --git a/src/xterm.h b/src/xterm.h
index fbd268abda2..104f5f8d76e 100644
--- a/src/xterm.h
+++ b/src/xterm.h
@@ -189,6 +189,11 @@ struct x_display_info
189 /* The cursor to use for vertical scroll bars. */ 189 /* The cursor to use for vertical scroll bars. */
190 Cursor vertical_scroll_bar_cursor; 190 Cursor vertical_scroll_bar_cursor;
191 191
192#ifdef USE_GTK
193 /* The GDK cursor for scroll bars and popup menus. */
194 GdkCursor *xg_cursor;
195#endif
196
192 /* X Resource data base */ 197 /* X Resource data base */
193 XrmDatabase xrdb; 198 XrmDatabase xrdb;
194 199