aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJan D2011-03-08 09:34:55 +0100
committerJan D2011-03-08 09:34:55 +0100
commit0afb4571a7b54dc7693e605f7ec8a0a3a9251b4d (patch)
tree58fa84febc60c1bf678f3e5f72358968bd3eaeba /src
parent25bbfb31d5a71dee8d6049e9bbe10dd7d4b65db9 (diff)
downloademacs-0afb4571a7b54dc7693e605f7ec8a0a3a9251b4d.tar.gz
emacs-0afb4571a7b54dc7693e605f7ec8a0a3a9251b4d.zip
Updates for compiling with Gtk+ 3.0 (--with-x-toolkit=gtk3).
* configure.in: Require 3.0 for --with-gtk3. Add HAVE_GTK3. * doc/emacs/xresources.texi (GTK resources): ~/.emacs.d/gtkrc does not work for Gtk+ 3. * src/gtkutil.c: Include gtkx.h if HAVE_GTK3. If ! HAVE_GTK3, define gdk_window_get_screen, gdk_window_get_geometry, gdk_x11_window_lookup_for_display and GDK_KEY_g. (xg_set_screen): Use DEFAULT_GDK_DISPLAY. (xg_get_pixbuf_from_pixmap): New function. (xg_get_pixbuf_from_pix_and_mask): Change parameters from GdkPixmap to Pixmap, take frame as parameter, remove GdkColormap parameter. Call xg_get_pixbuf_from_pixmap instead of gdk_pixbuf_get_from_drawable. (xg_get_image_for_pixmap): Do not make GdkPixmaps, call xg_get_pixbuf_from_pix_and_mask with Pixmap parameters instead. (xg_check_special_colors): Use GtkStyleContext and its functions for HAVE_GTK3. (xg_prepare_tooltip, xg_hide_tooltip): Call gdk_window_get_screen. (xg_prepare_tooltip, create_dialog, menubar_map_cb) (xg_update_frame_menubar, xg_tool_bar_detach_callback) (xg_tool_bar_attach_callback, xg_update_tool_bar_sizes): Call gtk_widget_get_preferred_size. (xg_frame_resized): gdk_window_get_geometry only takes 5 parameters. (xg_win_to_widget, xg_event_is_for_menubar): Call gdk_x11_window_lookup_for_display. (xg_set_widget_bg): New function. (delete_cb): New function. (xg_create_frame_widgets): connect delete-event to delete_cb. Call xg_set_widget_bg. Only set backgrund pixmap for ! HAVE_GTK3 (xg_set_background_color): Call xg_set_widget_bg. (xg_set_frame_icon): Call xg_get_pixbuf_from_pix_and_mask. (xg_create_scroll_bar): vadj is a GtkAdjustment for HAVE_GTK3. Only call gtk_range_set_update_policy if ! HAVE_GTK3. (xg_make_tool_item): Only connect xg_tool_bar_item_expose_callback if ! HAVE_GTK3. (update_frame_tool_bar): Call gtk_widget_hide. (xg_initialize): Use GDK_KEY_g. * src/xmenu.c (menu_position_func): Call gtk_widget_get_preferred_size. * src/xsmfns.c (gdk_set_sm_client_id): Define to gdk_set_sm_client_id if ! HAVE_GTK3 (x_session_initialize): Call gdk_x11_set_sm_client_id. * src/xterm.c (XFillRectangle): Use cairo routines for HAVE_GTK3. (x_term_init): Disable Xinput(2) with GDK_CORE_DEVICE_EVENTS. Load ~/emacs.d/gtkrc only for ! HAVE_GTK3. * src/xterm.h (DEFAULT_GDK_DISPLAY): New define. (GDK_WINDOW_XID, gtk_widget_get_preferred_size): New defines for ! HAVE_GTK3. (GTK_WIDGET_TO_X_WIN): Use GDK_WINDOW_XID.
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog52
-rw-r--r--src/config.in3
-rw-r--r--src/gtkutil.c267
-rw-r--r--src/xmenu.c2
-rw-r--r--src/xsmfns.c6
-rw-r--r--src/xterm.c29
-rw-r--r--src/xterm.h13
7 files changed, 277 insertions, 95 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index b73e3d0c860..ff5ee064a92 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,55 @@
12011-03-08 Jan Djärv <jan.h.d@swipnet.se>
2
3 * xterm.h (DEFAULT_GDK_DISPLAY): New define.
4 (GDK_WINDOW_XID, gtk_widget_get_preferred_size): New defines
5 for ! HAVE_GTK3.
6 (GTK_WIDGET_TO_X_WIN): Use GDK_WINDOW_XID.
7
8 * xmenu.c (menu_position_func): Call gtk_widget_get_preferred_size.
9
10 * gtkutil.c: Include gtkx.h if HAVE_GTK3. If ! HAVE_GTK3, define
11 gdk_window_get_screen, gdk_window_get_geometry,
12 gdk_x11_window_lookup_for_display and GDK_KEY_g.
13 (xg_set_screen): Use DEFAULT_GDK_DISPLAY.
14 (xg_get_pixbuf_from_pixmap): New function.
15 (xg_get_pixbuf_from_pix_and_mask): Change parameters from GdkPixmap
16 to Pixmap, take frame as parameter, remove GdkColormap parameter.
17 Call xg_get_pixbuf_from_pixmap instead of
18 gdk_pixbuf_get_from_drawable.
19 (xg_get_image_for_pixmap): Do not make GdkPixmaps, call
20 xg_get_pixbuf_from_pix_and_mask with Pixmap parameters instead.
21 (xg_check_special_colors): Use GtkStyleContext and its functions
22 for HAVE_GTK3.
23 (xg_prepare_tooltip, xg_hide_tooltip): Call gdk_window_get_screen.
24 (xg_prepare_tooltip, create_dialog, menubar_map_cb)
25 (xg_update_frame_menubar, xg_tool_bar_detach_callback)
26 (xg_tool_bar_attach_callback, xg_update_tool_bar_sizes): Call
27 gtk_widget_get_preferred_size.
28 (xg_frame_resized): gdk_window_get_geometry only takes 5
29 parameters.
30 (xg_win_to_widget, xg_event_is_for_menubar): Call
31 gdk_x11_window_lookup_for_display.
32 (xg_set_widget_bg): New function.
33 (delete_cb): New function.
34 (xg_create_frame_widgets): connect delete-event to delete_cb.
35 Call xg_set_widget_bg. Only set backgrund pixmap for ! HAVE_GTK3
36 (xg_set_background_color): Call xg_set_widget_bg.
37 (xg_set_frame_icon): Call xg_get_pixbuf_from_pix_and_mask.
38 (xg_create_scroll_bar): vadj is a GtkAdjustment for HAVE_GTK3.
39 Only call gtk_range_set_update_policy if ! HAVE_GTK3.
40 (xg_make_tool_item): Only connect xg_tool_bar_item_expose_callback
41 if ! HAVE_GTK3.
42 (update_frame_tool_bar): Call gtk_widget_hide.
43 (xg_initialize): Use GDK_KEY_g.
44
45 * xsmfns.c (gdk_set_sm_client_id): Define to gdk_set_sm_client_id
46 if ! HAVE_GTK3
47 (x_session_initialize): Call gdk_x11_set_sm_client_id.
48
49 * xterm.c (XFillRectangle): Use cairo routines for HAVE_GTK3.
50 (x_term_init): Disable Xinput(2) with GDK_CORE_DEVICE_EVENTS.
51 Load ~/emacs.d/gtkrc only for ! HAVE_GTK3.
52
12011-03-08 Juanma Barranquero <lekktu@gmail.com> 532011-03-08 Juanma Barranquero <lekktu@gmail.com>
2 54
3 * w32xfns.c (select_palette): Check success of RealizePalette against 55 * w32xfns.c (select_palette): Check success of RealizePalette against
diff --git a/src/config.in b/src/config.in
index 7f33727c0b1..8889213b781 100644
--- a/src/config.in
+++ b/src/config.in
@@ -285,6 +285,9 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
285/* Define to 1 if you have the `grantpt' function. */ 285/* Define to 1 if you have the `grantpt' function. */
286#undef HAVE_GRANTPT 286#undef HAVE_GRANTPT
287 287
288/* Define to 1 if using GTK 3 or later. */
289#undef HAVE_GTK3
290
288/* Define to 1 if you have the `gtk_adjustment_get_page_size' function. */ 291/* Define to 1 if you have the `gtk_adjustment_get_page_size' function. */
289#undef HAVE_GTK_ADJUSTMENT_GET_PAGE_SIZE 292#undef HAVE_GTK_ADJUSTMENT_GET_PAGE_SIZE
290 293
diff --git a/src/gtkutil.c b/src/gtkutil.c
index 6ecd5d624af..b1ea6336eb6 100644
--- a/src/gtkutil.c
+++ b/src/gtkutil.c
@@ -40,6 +40,10 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
40#include <X11/Xft/Xft.h> 40#include <X11/Xft/Xft.h>
41#endif 41#endif
42 42
43#ifdef HAVE_GTK3
44#include <gtk/gtkx.h>
45#endif
46
43#define FRAME_TOTAL_PIXEL_HEIGHT(f) \ 47#define FRAME_TOTAL_PIXEL_HEIGHT(f) \
44 (FRAME_PIXEL_HEIGHT (f) + FRAME_MENUBAR_HEIGHT (f) + FRAME_TOOLBAR_HEIGHT (f)) 48 (FRAME_PIXEL_HEIGHT (f) + FRAME_MENUBAR_HEIGHT (f) + FRAME_TOOLBAR_HEIGHT (f))
45 49
@@ -69,6 +73,15 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
69#define remove_submenu(w) gtk_menu_item_remove_submenu ((w)) 73#define remove_submenu(w) gtk_menu_item_remove_submenu ((w))
70#endif 74#endif
71 75
76#ifndef HAVE_GTK3
77#define gdk_window_get_screen(w) gdk_drawable_get_screen (w)
78#define gdk_window_get_geometry(w, a, b, c, d) \
79 gdk_window_get_geometry (w, a, b, c, d, 0)
80#define gdk_x11_window_lookup_for_display(d, w) \
81 gdk_xid_table_lookup_for_display (d, w)
82#define GDK_KEY_g GDK_g
83#endif
84
72#define XG_BIN_CHILD(x) gtk_bin_get_child (GTK_BIN (x)) 85#define XG_BIN_CHILD(x) gtk_bin_get_child (GTK_BIN (x))
73 86
74 87
@@ -88,7 +101,7 @@ static GdkDisplay *gdpy_def;
88static void 101static void
89xg_set_screen (GtkWidget *w, FRAME_PTR f) 102xg_set_screen (GtkWidget *w, FRAME_PTR f)
90{ 103{
91 if (FRAME_X_DISPLAY (f) != GDK_DISPLAY ()) 104 if (FRAME_X_DISPLAY (f) != DEFAULT_GDK_DISPLAY ())
92 { 105 {
93 GdkDisplay *gdpy = gdk_x11_lookup_xdisplay (FRAME_X_DISPLAY (f)); 106 GdkDisplay *gdpy = gdk_x11_lookup_xdisplay (FRAME_X_DISPLAY (f));
94 GdkScreen *gscreen = gdk_display_get_default_screen (gdpy); 107 GdkScreen *gscreen = gdk_display_get_default_screen (gdpy);
@@ -229,29 +242,55 @@ xg_create_default_cursor (Display *dpy)
229 return gdk_cursor_new_for_display (gdpy, GDK_LEFT_PTR); 242 return gdk_cursor_new_for_display (gdpy, GDK_LEFT_PTR);
230} 243}
231 244
245static GdkPixbuf *
246xg_get_pixbuf_from_pixmap (FRAME_PTR f, Pixmap pix)
247{
248 int iunused;
249 GdkPixbuf *tmp_buf;
250 Window wunused;
251 unsigned int width, height, uunused;
252 XImage *xim;
253
254 XGetGeometry (FRAME_X_DISPLAY (f), pix, &wunused, &iunused, &iunused,
255 &width, &height, &uunused, &uunused);
256
257 xim = XGetImage (FRAME_X_DISPLAY (f), pix, 0, 0, width, height,
258 ~0, XYPixmap);
259 if (!xim) return 0;
260
261 tmp_buf = gdk_pixbuf_new_from_data (xim->data,
262 GDK_COLORSPACE_RGB,
263 FALSE,
264 xim->bitmap_unit,
265 (int) width,
266 (int) height,
267 xim->bytes_per_line,
268 NULL,
269 NULL);
270 XDestroyImage (xim);
271 return tmp_buf;
272}
273
232/* Apply GMASK to GPIX and return a GdkPixbuf with an alpha channel. */ 274/* Apply GMASK to GPIX and return a GdkPixbuf with an alpha channel. */
233 275
234static GdkPixbuf * 276static GdkPixbuf *
235xg_get_pixbuf_from_pix_and_mask (GdkPixmap *gpix, 277xg_get_pixbuf_from_pix_and_mask (FRAME_PTR f,
236 GdkPixmap *gmask, 278 Pixmap pix,
237 GdkColormap *cmap) 279 Pixmap mask)
238{ 280{
239 int width, height; 281 int width, height;
240 GdkPixbuf *icon_buf, *tmp_buf; 282 GdkPixbuf *icon_buf, *tmp_buf;
241 283
242 gdk_drawable_get_size (gpix, &width, &height); 284 tmp_buf = xg_get_pixbuf_from_pixmap (f, pix);
243 tmp_buf = gdk_pixbuf_get_from_drawable (NULL, gpix, cmap,
244 0, 0, 0, 0, width, height);
245 icon_buf = gdk_pixbuf_add_alpha (tmp_buf, FALSE, 0, 0, 0); 285 icon_buf = gdk_pixbuf_add_alpha (tmp_buf, FALSE, 0, 0, 0);
246 g_object_unref (G_OBJECT (tmp_buf)); 286 g_object_unref (G_OBJECT (tmp_buf));
247 287
248 if (gmask) 288 width = gdk_pixbuf_get_width (icon_buf);
289 height = gdk_pixbuf_get_height (icon_buf);
290
291 if (mask)
249 { 292 {
250 GdkPixbuf *mask_buf = gdk_pixbuf_get_from_drawable (NULL, 293 GdkPixbuf *mask_buf = xg_get_pixbuf_from_pixmap (f, mask);
251 gmask,
252 NULL,
253 0, 0, 0, 0,
254 width, height);
255 guchar *pixels = gdk_pixbuf_get_pixels (icon_buf); 294 guchar *pixels = gdk_pixbuf_get_pixels (icon_buf);
256 guchar *mask_pixels = gdk_pixbuf_get_pixels (mask_buf); 295 guchar *mask_pixels = gdk_pixbuf_get_pixels (mask_buf);
257 int rowstride = gdk_pixbuf_get_rowstride (icon_buf); 296 int rowstride = gdk_pixbuf_get_rowstride (icon_buf);
@@ -316,10 +355,6 @@ xg_get_image_for_pixmap (FRAME_PTR f,
316 GtkWidget *widget, 355 GtkWidget *widget,
317 GtkImage *old_widget) 356 GtkImage *old_widget)
318{ 357{
319 GdkPixmap *gpix;
320 GdkPixmap *gmask;
321 GdkDisplay *gdpy;
322 GdkColormap *cmap;
323 GdkPixbuf *icon_buf; 358 GdkPixbuf *icon_buf;
324 359
325 /* If we have a file, let GTK do all the image handling. 360 /* If we have a file, let GTK do all the image handling.
@@ -347,10 +382,6 @@ xg_get_image_for_pixmap (FRAME_PTR f,
347 on a monochrome display, and sometimes bad on all displays with 382 on a monochrome display, and sometimes bad on all displays with
348 certain themes. */ 383 certain themes. */
349 384
350 gdpy = gdk_x11_lookup_xdisplay (FRAME_X_DISPLAY (f));
351 gpix = gdk_pixmap_foreign_new_for_display (gdpy, img->pixmap);
352 gmask = img->mask ? gdk_pixmap_foreign_new_for_display (gdpy, img->mask) : 0;
353
354 /* This is a workaround to make icons look good on pseudo color 385 /* This is a workaround to make icons look good on pseudo color
355 displays. Apparently GTK expects the images to have an alpha 386 displays. Apparently GTK expects the images to have an alpha
356 channel. If they don't, insensitive and activated icons will 387 channel. If they don't, insensitive and activated icons will
@@ -360,18 +391,17 @@ xg_get_image_for_pixmap (FRAME_PTR f,
360 not associated with the img->pixmap. The img->pixmap may be removed 391 not associated with the img->pixmap. The img->pixmap may be removed
361 by clearing the image cache and then the tool bar redraw fails, since 392 by clearing the image cache and then the tool bar redraw fails, since
362 Gtk+ assumes the pixmap is always there. */ 393 Gtk+ assumes the pixmap is always there. */
363 cmap = gtk_widget_get_colormap (widget); 394 icon_buf = xg_get_pixbuf_from_pix_and_mask (f, img->pixmap, img->mask);
364 icon_buf = xg_get_pixbuf_from_pix_and_mask (gpix, gmask, cmap);
365
366 if (! old_widget)
367 old_widget = GTK_IMAGE (gtk_image_new_from_pixbuf (icon_buf));
368 else
369 gtk_image_set_from_pixbuf (old_widget, icon_buf);
370 395
371 g_object_unref (G_OBJECT (icon_buf)); 396 if (icon_buf)
397 {
398 if (! old_widget)
399 old_widget = GTK_IMAGE (gtk_image_new_from_pixbuf (icon_buf));
400 else
401 gtk_image_set_from_pixbuf (old_widget, icon_buf);
372 402
373 g_object_unref (G_OBJECT (gpix)); 403 g_object_unref (G_OBJECT (icon_buf));
374 if (gmask) g_object_unref (G_OBJECT (gmask)); 404 }
375 405
376 return GTK_WIDGET (old_widget); 406 return GTK_WIDGET (old_widget);
377} 407}
@@ -514,28 +544,43 @@ xg_check_special_colors (struct frame *f,
514 XColor *color) 544 XColor *color)
515{ 545{
516 int success_p = 0; 546 int success_p = 0;
517 if (FRAME_GTK_WIDGET (f)) 547 int get_bg = strcmp ("gtk_selection_bg_color", color_name) == 0;
518 { 548 int get_fg = !get_bg && strcmp ("gtk_selection_fg_color", color_name) == 0;
519 if (strcmp ("gtk_selection_bg_color", color_name) == 0) 549
520 { 550 if (! FRAME_GTK_WIDGET (f) || ! (get_bg || get_fg))
521 GtkStyle *gsty = gtk_widget_get_style (FRAME_GTK_WIDGET (f)); 551 return success_p;
522 color->red = gsty->bg[GTK_STATE_SELECTED].red; 552
523 color->green = gsty->bg[GTK_STATE_SELECTED].green; 553 BLOCK_INPUT;
524 color->blue = gsty->bg[GTK_STATE_SELECTED].blue; 554 {
525 color->pixel = gsty->bg[GTK_STATE_SELECTED].pixel; 555#ifdef HAVE_GTK3
526 success_p = 1; 556 GtkStyleContext *gsty
527 } 557 = gtk_widget_get_style_context (FRAME_GTK_OUTER_WIDGET (f));
528 else if (strcmp ("gtk_selection_fg_color", color_name) == 0) 558 GdkRGBA col;
529 { 559 char buf[64];
530 GtkStyle *gsty = gtk_widget_get_style (FRAME_GTK_WIDGET (f)); 560 int state = GTK_STATE_FLAG_SELECTED|GTK_STATE_FLAG_FOCUSED;
531 color->red = gsty->fg[GTK_STATE_SELECTED].red; 561 if (get_fg)
532 color->green = gsty->fg[GTK_STATE_SELECTED].green; 562 gtk_style_context_get_color (gsty, state, &col);
533 color->blue = gsty->fg[GTK_STATE_SELECTED].blue; 563 else
534 color->pixel = gsty->fg[GTK_STATE_SELECTED].pixel; 564 gtk_style_context_get_background_color (gsty, state, &col);
535 success_p = 1; 565
536 } 566 sprintf (buf, "rgbi:%lf/%lf/%lf", col.red, col.green, col.blue);
537 } 567 success_p = XParseColor (FRAME_X_DISPLAY (f), FRAME_X_COLORMAP (f),
568 buf, color);
569#else
570 GtkStyle *gsty = gtk_widget_get_style (FRAME_GTK_WIDGET (f));
571 GdkColor *grgb = get_bg
572 ? &gsty->bg[GTK_STATE_SELECTED]
573 : &gsty->fg[GTK_STATE_SELECTED];
574
575 color->red = grgb->red;
576 color->green = grgb->green;
577 color->blue = grgb->blue;
578 color->pixel = grgb->pixel;
579 success_p = 1;
580#endif
538 581
582 }
583 UNBLOCK_INPUT;
539 return success_p; 584 return success_p;
540} 585}
541 586
@@ -629,7 +674,7 @@ xg_prepare_tooltip (FRAME_PTR f,
629 encoded_string = ENCODE_UTF_8 (string); 674 encoded_string = ENCODE_UTF_8 (string);
630 widget = GTK_WIDGET (x->ttip_lbl); 675 widget = GTK_WIDGET (x->ttip_lbl);
631 gwin = gtk_widget_get_window (GTK_WIDGET (x->ttip_window)); 676 gwin = gtk_widget_get_window (GTK_WIDGET (x->ttip_window));
632 screen = gdk_drawable_get_screen (gwin); 677 screen = gdk_window_get_screen (gwin);
633 settings = gtk_settings_get_for_screen (screen); 678 settings = gtk_settings_get_for_screen (screen);
634 g_object_get (settings, "gtk-enable-tooltips", &tt_enabled, NULL); 679 g_object_get (settings, "gtk-enable-tooltips", &tt_enabled, NULL);
635 if (tt_enabled) 680 if (tt_enabled)
@@ -650,7 +695,7 @@ xg_prepare_tooltip (FRAME_PTR f,
650 gtk_tooltip_set_custom (x->ttip_widget, widget); 695 gtk_tooltip_set_custom (x->ttip_widget, widget);
651 696
652 gtk_tooltip_set_text (x->ttip_widget, SDATA (encoded_string)); 697 gtk_tooltip_set_text (x->ttip_widget, SDATA (encoded_string));
653 gtk_widget_size_request (GTK_WIDGET (x->ttip_window), &req); 698 gtk_widget_get_preferred_size (GTK_WIDGET (x->ttip_window), NULL, &req);
654 if (width) *width = req.width; 699 if (width) *width = req.width;
655 if (height) *height = req.height; 700 if (height) *height = req.height;
656 701
@@ -696,7 +741,7 @@ xg_hide_tooltip (FRAME_PTR f)
696 if (g_object_get_data (G_OBJECT (win), "restore-tt")) 741 if (g_object_get_data (G_OBJECT (win), "restore-tt"))
697 { 742 {
698 GdkWindow *gwin = gtk_widget_get_window (GTK_WIDGET (win)); 743 GdkWindow *gwin = gtk_widget_get_window (GTK_WIDGET (win));
699 GdkScreen *screen = gdk_drawable_get_screen (gwin); 744 GdkScreen *screen = gdk_window_get_screen (gwin);
700 GtkSettings *settings = gtk_settings_get_for_screen (screen); 745 GtkSettings *settings = gtk_settings_get_for_screen (screen);
701 g_object_set (settings, "gtk-enable-tooltips", TRUE, NULL); 746 g_object_set (settings, "gtk-enable-tooltips", TRUE, NULL);
702 } 747 }
@@ -797,7 +842,7 @@ xg_frame_resized (FRAME_PTR f, int pixelwidth, int pixelheight)
797 if (FRAME_GTK_WIDGET (f) && gtk_widget_get_mapped (FRAME_GTK_WIDGET (f))) 842 if (FRAME_GTK_WIDGET (f) && gtk_widget_get_mapped (FRAME_GTK_WIDGET (f)))
798 gdk_window_get_geometry (gtk_widget_get_window (FRAME_GTK_WIDGET (f)), 843 gdk_window_get_geometry (gtk_widget_get_window (FRAME_GTK_WIDGET (f)),
799 0, 0, 844 0, 0,
800 &pixelwidth, &pixelheight, 0); 845 &pixelwidth, &pixelheight);
801 else return; 846 else return;
802 } 847 }
803 848
@@ -910,8 +955,8 @@ xg_win_to_widget (Display *dpy, Window wdesc)
910 955
911 BLOCK_INPUT; 956 BLOCK_INPUT;
912 957
913 gdkwin = gdk_xid_table_lookup_for_display (gdk_x11_lookup_xdisplay (dpy), 958 gdkwin = gdk_x11_window_lookup_for_display (gdk_x11_lookup_xdisplay (dpy),
914 wdesc); 959 wdesc);
915 if (gdkwin) 960 if (gdkwin)
916 { 961 {
917 GdkEvent event; 962 GdkEvent event;
@@ -923,14 +968,29 @@ xg_win_to_widget (Display *dpy, Window wdesc)
923 return gwdesc; 968 return gwdesc;
924} 969}
925 970
926/* Fill in the GdkColor C so that it represents PIXEL. 971/* Set the background of widget W to PIXEL. */
927 W is the widget that color will be used for. Used to find colormap. */
928 972
929static void 973static void
930xg_pix_to_gcolor (GtkWidget *w, long unsigned int pixel, GdkColor *c) 974xg_set_widget_bg (FRAME_PTR f, GtkWidget *w, long unsigned int pixel)
931{ 975{
976#ifdef HAVE_GTK3
977 GdkRGBA bg;
978 XColor xbg;
979 xbg.pixel = pixel;
980 if (XQueryColor (FRAME_X_DISPLAY (f), FRAME_X_COLORMAP (f), &xbg))
981 {
982 bg.red = (double)xbg.red/65536.0;
983 bg.green = (double)xbg.green/65536.0;
984 bg.blue = (double)xbg.blue/65536.0;
985 bg.alpha = 1.0;
986 gtk_widget_override_background_color (w, GTK_STATE_FLAG_NORMAL, &bg);
987 }
988#else
989 GdkColor bg;
932 GdkColormap *map = gtk_widget_get_colormap (w); 990 GdkColormap *map = gtk_widget_get_colormap (w);
933 gdk_colormap_query_color (map, pixel, c); 991 gdk_colormap_query_color (map, pixel, &bg);
992 gtk_widget_modify_bg (FRAME_GTK_WIDGET (f), GTK_STATE_NORMAL, &bg);
993#endif
934} 994}
935 995
936/* Callback called when the gtk theme changes. 996/* Callback called when the gtk theme changes.
@@ -953,6 +1013,28 @@ style_changed_cb (GObject *go,
953 kbd_buffer_store_event (&event); 1013 kbd_buffer_store_event (&event);
954} 1014}
955 1015
1016/* Called when a delete-event occurs on WIDGET. */
1017
1018static gboolean
1019delete_cb (GtkWidget *widget,
1020 GdkEvent *event,
1021 gpointer user_data)
1022{
1023#ifdef HAVE_GTK3
1024 /* The event doesn't arrive in the normal event loop. Send event
1025 here. */
1026 FRAME_PTR f = (FRAME_PTR) user_data;
1027 struct input_event ie;
1028
1029 EVENT_INIT (ie);
1030 ie.kind = DELETE_WINDOW_EVENT;
1031 XSETFRAME (ie.frame_or_window, f);
1032 kbd_buffer_store_event (&ie);
1033#endif
1034
1035 return TRUE;
1036}
1037
956/* Create and set up the GTK widgets for frame F. 1038/* Create and set up the GTK widgets for frame F.
957 Return 0 if creation failed, non-zero otherwise. */ 1039 Return 0 if creation failed, non-zero otherwise. */
958 1040
@@ -962,7 +1044,6 @@ xg_create_frame_widgets (FRAME_PTR f)
962 GtkWidget *wtop; 1044 GtkWidget *wtop;
963 GtkWidget *wvbox, *whbox; 1045 GtkWidget *wvbox, *whbox;
964 GtkWidget *wfixed; 1046 GtkWidget *wfixed;
965 GdkColor bg;
966 GtkRcStyle *style; 1047 GtkRcStyle *style;
967 char *title = 0; 1048 char *title = 0;
968 1049
@@ -1029,7 +1110,7 @@ xg_create_frame_widgets (FRAME_PTR f)
1029 /* Add callback to do nothing on WM_DELETE_WINDOW. The default in 1110 /* Add callback to do nothing on WM_DELETE_WINDOW. The default in
1030 GTK is to destroy the widget. We want Emacs to do that instead. */ 1111 GTK is to destroy the widget. We want Emacs to do that instead. */
1031 g_signal_connect (G_OBJECT (wtop), "delete-event", 1112 g_signal_connect (G_OBJECT (wtop), "delete-event",
1032 G_CALLBACK (gtk_true), 0); 1113 G_CALLBACK (delete_cb), f);
1033 1114
1034 /* Convert our geometry parameters into a geometry string 1115 /* Convert our geometry parameters into a geometry string
1035 and specify it. 1116 and specify it.
@@ -1057,9 +1138,9 @@ xg_create_frame_widgets (FRAME_PTR f)
1057 1138
1058 /* Since GTK clears its window by filling with the background color, 1139 /* Since GTK clears its window by filling with the background color,
1059 we must keep X and GTK background in sync. */ 1140 we must keep X and GTK background in sync. */
1060 xg_pix_to_gcolor (wfixed, FRAME_BACKGROUND_PIXEL (f), &bg); 1141 xg_set_widget_bg (f, wfixed, FRAME_BACKGROUND_PIXEL (f));
1061 gtk_widget_modify_bg (wfixed, GTK_STATE_NORMAL, &bg);
1062 1142
1143#ifndef HAVE_GTK3
1063 /* Also, do not let any background pixmap to be set, this looks very 1144 /* Also, do not let any background pixmap to be set, this looks very
1064 bad as Emacs overwrites the background pixmap with its own idea 1145 bad as Emacs overwrites the background pixmap with its own idea
1065 of background color. */ 1146 of background color. */
@@ -1068,6 +1149,9 @@ xg_create_frame_widgets (FRAME_PTR f)
1068 /* Must use g_strdup because gtk_widget_modify_style does g_free. */ 1149 /* Must use g_strdup because gtk_widget_modify_style does g_free. */
1069 style->bg_pixmap_name[GTK_STATE_NORMAL] = g_strdup ("<none>"); 1150 style->bg_pixmap_name[GTK_STATE_NORMAL] = g_strdup ("<none>");
1070 gtk_widget_modify_style (wfixed, style); 1151 gtk_widget_modify_style (wfixed, style);
1152#else
1153 gtk_widget_set_can_focus (wfixed, TRUE);
1154#endif
1071 1155
1072#ifdef USE_GTK_TOOLTIP 1156#ifdef USE_GTK_TOOLTIP
1073 /* Steal a tool tip window we can move ourselves. */ 1157 /* Steal a tool tip window we can move ourselves. */
@@ -1224,11 +1308,8 @@ xg_set_background_color (FRAME_PTR f, long unsigned int bg)
1224{ 1308{
1225 if (FRAME_GTK_WIDGET (f)) 1309 if (FRAME_GTK_WIDGET (f))
1226 { 1310 {
1227 GdkColor gdk_bg;
1228
1229 BLOCK_INPUT; 1311 BLOCK_INPUT;
1230 xg_pix_to_gcolor (FRAME_GTK_WIDGET (f), bg, &gdk_bg); 1312 xg_set_widget_bg (f, FRAME_GTK_WIDGET (f), FRAME_BACKGROUND_PIXEL (f));
1231 gtk_widget_modify_bg (FRAME_GTK_WIDGET (f), GTK_STATE_NORMAL, &gdk_bg);
1232 UNBLOCK_INPUT; 1313 UNBLOCK_INPUT;
1233 } 1314 }
1234} 1315}
@@ -1240,11 +1321,10 @@ xg_set_background_color (FRAME_PTR f, long unsigned int bg)
1240void 1321void
1241xg_set_frame_icon (FRAME_PTR f, Pixmap icon_pixmap, Pixmap icon_mask) 1322xg_set_frame_icon (FRAME_PTR f, Pixmap icon_pixmap, Pixmap icon_mask)
1242{ 1323{
1243 GdkDisplay *gdpy = gdk_x11_lookup_xdisplay (FRAME_X_DISPLAY (f)); 1324 GdkPixbuf *gp = xg_get_pixbuf_from_pix_and_mask (f,
1244 GdkPixmap *gpix = gdk_pixmap_foreign_new_for_display (gdpy, icon_pixmap); 1325 icon_pixmap,
1245 GdkPixmap *gmask = gdk_pixmap_foreign_new_for_display (gdpy, icon_mask); 1326 icon_mask);
1246 GdkPixbuf *gp = xg_get_pixbuf_from_pix_and_mask (gpix, gmask, NULL); 1327 if (gp)
1247
1248 gtk_window_set_icon (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f)), gp); 1328 gtk_window_set_icon (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f)), gp);
1249} 1329}
1250 1330
@@ -1381,7 +1461,7 @@ create_dialog (widget_value *wv,
1381 /* Try to make dialog look better. Must realize first so 1461 /* Try to make dialog look better. Must realize first so
1382 the widget can calculate the size it needs. */ 1462 the widget can calculate the size it needs. */
1383 gtk_widget_realize (w); 1463 gtk_widget_realize (w);
1384 gtk_widget_size_request (w, &req); 1464 gtk_widget_get_preferred_size (w, NULL, &req);
1385 gtk_box_set_spacing (wvbox, req.height); 1465 gtk_box_set_spacing (wvbox, req.height);
1386 if (item->value && strlen (item->value) > 0) 1466 if (item->value && strlen (item->value) > 0)
1387 button_spacing = 2*req.width/strlen (item->value); 1467 button_spacing = 2*req.width/strlen (item->value);
@@ -3028,7 +3108,7 @@ menubar_map_cb (GtkWidget *w, gpointer user_data)
3028{ 3108{
3029 GtkRequisition req; 3109 GtkRequisition req;
3030 FRAME_PTR f = (FRAME_PTR) user_data; 3110 FRAME_PTR f = (FRAME_PTR) user_data;
3031 gtk_widget_size_request (w, &req); 3111 gtk_widget_get_preferred_size (w, NULL, &req);
3032 if (FRAME_MENUBAR_HEIGHT (f) != req.height) 3112 if (FRAME_MENUBAR_HEIGHT (f) != req.height)
3033 { 3113 {
3034 FRAME_MENUBAR_HEIGHT (f) = req.height; 3114 FRAME_MENUBAR_HEIGHT (f) = req.height;
@@ -3059,7 +3139,7 @@ xg_update_frame_menubar (FRAME_PTR f)
3059 3139
3060 g_signal_connect (x->menubar_widget, "map", G_CALLBACK (menubar_map_cb), f); 3140 g_signal_connect (x->menubar_widget, "map", G_CALLBACK (menubar_map_cb), f);
3061 gtk_widget_show_all (x->menubar_widget); 3141 gtk_widget_show_all (x->menubar_widget);
3062 gtk_widget_size_request (x->menubar_widget, &req); 3142 gtk_widget_get_preferred_size (x->menubar_widget, NULL, &req);
3063 3143
3064 /* If menu bar doesn't know its height yet, cheat a little so the frame 3144 /* If menu bar doesn't know its height yet, cheat a little so the frame
3065 doesn't jump so much when resized later in menubar_map_cb. */ 3145 doesn't jump so much when resized later in menubar_map_cb. */
@@ -3120,7 +3200,7 @@ xg_event_is_for_menubar (FRAME_PTR f, XEvent *event)
3120 return 0; 3200 return 0;
3121 3201
3122 gdpy = gdk_x11_lookup_xdisplay (FRAME_X_DISPLAY (f)); 3202 gdpy = gdk_x11_lookup_xdisplay (FRAME_X_DISPLAY (f));
3123 gw = gdk_xid_table_lookup_for_display (gdpy, event->xbutton.window); 3203 gw = gdk_x11_window_lookup_for_display (gdpy, event->xbutton.window);
3124 if (! gw) return 0; 3204 if (! gw) return 0;
3125 gevent.any.window = gw; 3205 gevent.any.window = gw;
3126 gwdesc = gtk_get_event_widget (&gevent); 3206 gwdesc = gtk_get_event_widget (&gevent);
@@ -3284,8 +3364,12 @@ xg_create_scroll_bar (FRAME_PTR f,
3284{ 3364{
3285 GtkWidget *wscroll; 3365 GtkWidget *wscroll;
3286 GtkWidget *webox; 3366 GtkWidget *webox;
3287 GtkObject *vadj;
3288 int scroll_id; 3367 int scroll_id;
3368#ifdef HAVE_GTK3
3369 GtkAdjustment *vadj;
3370#else
3371 GtkObject *vadj;
3372#endif
3289 3373
3290 /* Page, step increment values are not so important here, they 3374 /* Page, step increment values are not so important here, they
3291 will be corrected in x_set_toolkit_scroll_bar_thumb. */ 3375 will be corrected in x_set_toolkit_scroll_bar_thumb. */
@@ -3295,7 +3379,9 @@ xg_create_scroll_bar (FRAME_PTR f,
3295 wscroll = gtk_vscrollbar_new (GTK_ADJUSTMENT (vadj)); 3379 wscroll = gtk_vscrollbar_new (GTK_ADJUSTMENT (vadj));
3296 webox = gtk_event_box_new (); 3380 webox = gtk_event_box_new ();
3297 gtk_widget_set_name (wscroll, scroll_bar_name); 3381 gtk_widget_set_name (wscroll, scroll_bar_name);
3382#ifndef HAVE_GTK3
3298 gtk_range_set_update_policy (GTK_RANGE (wscroll), GTK_UPDATE_CONTINUOUS); 3383 gtk_range_set_update_policy (GTK_RANGE (wscroll), GTK_UPDATE_CONTINUOUS);
3384#endif
3299 g_object_set_data (G_OBJECT (wscroll), XG_FRAME_DATA, (gpointer)f); 3385 g_object_set_data (G_OBJECT (wscroll), XG_FRAME_DATA, (gpointer)f);
3300 3386
3301 scroll_id = xg_store_widget_in_map (wscroll); 3387 scroll_id = xg_store_widget_in_map (wscroll);
@@ -3793,8 +3879,8 @@ xg_tool_bar_detach_callback (GtkHandleBox *wbox,
3793 { 3879 {
3794 GtkRequisition req, req2; 3880 GtkRequisition req, req2;
3795 FRAME_X_OUTPUT (f)->toolbar_detached = 1; 3881 FRAME_X_OUTPUT (f)->toolbar_detached = 1;
3796 gtk_widget_size_request (GTK_WIDGET (wbox), &req); 3882 gtk_widget_get_preferred_size (GTK_WIDGET (wbox), NULL, &req);
3797 gtk_widget_size_request (w, &req2); 3883 gtk_widget_get_preferred_size (w, NULL, &req2);
3798 req.width -= req2.width; 3884 req.width -= req2.width;
3799 req.height -= req2.height; 3885 req.height -= req2.height;
3800 if (FRAME_TOOLBAR_TOP_HEIGHT (f) != 0) 3886 if (FRAME_TOOLBAR_TOP_HEIGHT (f) != 0)
@@ -3828,8 +3914,8 @@ xg_tool_bar_attach_callback (GtkHandleBox *wbox,
3828 { 3914 {
3829 GtkRequisition req, req2; 3915 GtkRequisition req, req2;
3830 FRAME_X_OUTPUT (f)->toolbar_detached = 0; 3916 FRAME_X_OUTPUT (f)->toolbar_detached = 0;
3831 gtk_widget_size_request (GTK_WIDGET (wbox), &req); 3917 gtk_widget_get_preferred_size (GTK_WIDGET (wbox), NULL, &req);
3832 gtk_widget_size_request (w, &req2); 3918 gtk_widget_get_preferred_size (w, NULL, &req2);
3833 req.width += req2.width; 3919 req.width += req2.width;
3834 req.height += req2.height; 3920 req.height += req2.height;
3835 if (FRAME_TOOLBAR_TOP_HEIGHT (f) != 0) 3921 if (FRAME_TOOLBAR_TOP_HEIGHT (f) != 0)
@@ -3894,6 +3980,7 @@ xg_tool_bar_help_callback (GtkWidget *w,
3894 3980
3895 Returns FALSE to tell GTK to keep processing this event. */ 3981 Returns FALSE to tell GTK to keep processing this event. */
3896 3982
3983#ifndef HAVE_GTK3
3897static gboolean 3984static gboolean
3898xg_tool_bar_item_expose_callback (GtkWidget *w, 3985xg_tool_bar_item_expose_callback (GtkWidget *w,
3899 GdkEventExpose *event, 3986 GdkEventExpose *event,
@@ -3902,7 +3989,6 @@ xg_tool_bar_item_expose_callback (GtkWidget *w,
3902 gint width, height; 3989 gint width, height;
3903 3990
3904 gdk_drawable_get_size (event->window, &width, &height); 3991 gdk_drawable_get_size (event->window, &width, &height);
3905
3906 event->area.x -= width > event->area.width ? width-event->area.width : 0; 3992 event->area.x -= width > event->area.width ? width-event->area.width : 0;
3907 event->area.y -= height > event->area.height ? height-event->area.height : 0; 3993 event->area.y -= height > event->area.height ? height-event->area.height : 0;
3908 3994
@@ -3914,6 +4000,7 @@ xg_tool_bar_item_expose_callback (GtkWidget *w,
3914 4000
3915 return FALSE; 4001 return FALSE;
3916} 4002}
4003#endif
3917 4004
3918#ifdef HAVE_GTK_ORIENTABLE_SET_ORIENTATION 4005#ifdef HAVE_GTK_ORIENTABLE_SET_ORIENTATION
3919#define toolbar_set_orientation(w, o) \ 4006#define toolbar_set_orientation(w, o) \
@@ -4063,13 +4150,14 @@ xg_make_tool_item (FRAME_PTR f,
4063 4150
4064 g_object_set_data (G_OBJECT (weventbox), XG_FRAME_DATA, (gpointer)f); 4151 g_object_set_data (G_OBJECT (weventbox), XG_FRAME_DATA, (gpointer)f);
4065 4152
4153#ifndef HAVE_GTK3
4066 /* Catch expose events to overcome an annoying redraw bug, see 4154 /* Catch expose events to overcome an annoying redraw bug, see
4067 comment for xg_tool_bar_item_expose_callback. */ 4155 comment for xg_tool_bar_item_expose_callback. */
4068 g_signal_connect (G_OBJECT (ti), 4156 g_signal_connect (G_OBJECT (ti),
4069 "expose-event", 4157 "expose-event",
4070 G_CALLBACK (xg_tool_bar_item_expose_callback), 4158 G_CALLBACK (xg_tool_bar_item_expose_callback),
4071 0); 4159 0);
4072 4160#endif
4073 gtk_tool_item_set_homogeneous (ti, FALSE); 4161 gtk_tool_item_set_homogeneous (ti, FALSE);
4074 4162
4075 /* Callback to save modifyer mask (Shift/Control, etc). GTK makes 4163 /* Callback to save modifyer mask (Shift/Control, etc). GTK makes
@@ -4153,7 +4241,7 @@ xg_update_tool_bar_sizes (FRAME_PTR f)
4153 GtkRequisition req; 4241 GtkRequisition req;
4154 int nl = 0, nr = 0, nt = 0, nb = 0; 4242 int nl = 0, nr = 0, nt = 0, nb = 0;
4155 4243
4156 gtk_widget_size_request (GTK_WIDGET (x->handlebox_widget), &req); 4244 gtk_widget_get_preferred_size (GTK_WIDGET (x->handlebox_widget), NULL, &req);
4157 if (x->toolbar_in_hbox) 4245 if (x->toolbar_in_hbox)
4158 { 4246 {
4159 int pos; 4247 int pos;
@@ -4203,7 +4291,6 @@ update_frame_tool_bar (FRAME_PTR f)
4203 GtkToolItem *ti; 4291 GtkToolItem *ti;
4204 GtkTextDirection dir; 4292 GtkTextDirection dir;
4205 int pack_tool_bar = x->handlebox_widget == NULL; 4293 int pack_tool_bar = x->handlebox_widget == NULL;
4206
4207 Lisp_Object style; 4294 Lisp_Object style;
4208 int text_image, horiz; 4295 int text_image, horiz;
4209 4296
@@ -4551,13 +4638,13 @@ xg_initialize (void)
4551 /* Make dialogs close on C-g. Since file dialog inherits from 4638 /* Make dialogs close on C-g. Since file dialog inherits from
4552 dialog, this works for them also. */ 4639 dialog, this works for them also. */
4553 binding_set = gtk_binding_set_by_class (g_type_class_ref (GTK_TYPE_DIALOG)); 4640 binding_set = gtk_binding_set_by_class (g_type_class_ref (GTK_TYPE_DIALOG));
4554 gtk_binding_entry_add_signal (binding_set, GDK_g, GDK_CONTROL_MASK, 4641 gtk_binding_entry_add_signal (binding_set, GDK_KEY_g, GDK_CONTROL_MASK,
4555 "close", 0); 4642 "close", 0);
4556 4643
4557 /* Make menus close on C-g. */ 4644 /* Make menus close on C-g. */
4558 binding_set = gtk_binding_set_by_class (g_type_class_ref 4645 binding_set = gtk_binding_set_by_class (g_type_class_ref
4559 (GTK_TYPE_MENU_SHELL)); 4646 (GTK_TYPE_MENU_SHELL));
4560 gtk_binding_entry_add_signal (binding_set, GDK_g, GDK_CONTROL_MASK, 4647 gtk_binding_entry_add_signal (binding_set, GDK_KEY_g, GDK_CONTROL_MASK,
4561 "cancel", 0); 4648 "cancel", 0);
4562} 4649}
4563 4650
diff --git a/src/xmenu.c b/src/xmenu.c
index 934db0f0406..8967437a376 100644
--- a/src/xmenu.c
+++ b/src/xmenu.c
@@ -1390,7 +1390,7 @@ menu_position_func (GtkMenu *menu, gint *x, gint *y, gboolean *push_in, gpointer
1390 1390
1391 /* Check if there is room for the menu. If not, adjust x/y so that 1391 /* Check if there is room for the menu. If not, adjust x/y so that
1392 the menu is fully visible. */ 1392 the menu is fully visible. */
1393 gtk_widget_size_request (GTK_WIDGET (menu), &req); 1393 gtk_widget_get_preferred_size (GTK_WIDGET (menu), NULL, &req);
1394 if (data->x + req.width > disp_width) 1394 if (data->x + req.width > disp_width)
1395 *x -= data->x + req.width - disp_width; 1395 *x -= data->x + req.width - disp_width;
1396 if (data->y + req.height > disp_height) 1396 if (data->y + req.height > disp_height)
diff --git a/src/xsmfns.c b/src/xsmfns.c
index 825cec451d9..f3879dbcec0 100644
--- a/src/xsmfns.c
+++ b/src/xsmfns.c
@@ -41,6 +41,10 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
41#include "process.h" 41#include "process.h"
42#include "keyboard.h" 42#include "keyboard.h"
43 43
44#ifndef HAVE_GTK3
45#define gdk_x11_set_sm_client_id(w) gdk_set_sm_client_id (w)
46#endif
47
44/* This is the event used when SAVE_SESSION_EVENT occurs. */ 48/* This is the event used when SAVE_SESSION_EVENT occurs. */
45 49
46static struct input_event emacs_event; 50static struct input_event emacs_event;
@@ -459,7 +463,7 @@ x_session_initialize (struct x_display_info *dpyinfo)
459#ifdef USE_GTK 463#ifdef USE_GTK
460 /* GTK creats a leader window by itself, but we need to tell 464 /* GTK creats a leader window by itself, but we need to tell
461 it about our client_id. */ 465 it about our client_id. */
462 gdk_set_sm_client_id (client_id); 466 gdk_x11_set_sm_client_id (client_id);
463#else 467#else
464 create_client_leader_window (dpyinfo, client_id); 468 create_client_leader_window (dpyinfo, client_id);
465#endif 469#endif
diff --git a/src/xterm.c b/src/xterm.c
index 909b6978f5a..bb792d8b9a7 100644
--- a/src/xterm.c
+++ b/src/xterm.c
@@ -3021,6 +3021,17 @@ XTflash (struct frame *f)
3021 /* Use Gdk routines to draw. This way, we won't draw over scroll bars 3021 /* Use Gdk routines to draw. This way, we won't draw over scroll bars
3022 when the scroll bars and the edit widget share the same X window. */ 3022 when the scroll bars and the edit widget share the same X window. */
3023 GdkWindow *window = gtk_widget_get_window (FRAME_GTK_WIDGET (f)); 3023 GdkWindow *window = gtk_widget_get_window (FRAME_GTK_WIDGET (f));
3024#ifdef HAVE_GTK3
3025 cairo_t *cr = gdk_cairo_create (window);
3026 cairo_set_source_rgb (cr, 1, 1, 1);
3027 cairo_set_operator (cr, CAIRO_OPERATOR_DIFFERENCE);
3028#define XFillRectangle(d, win, gc, x, y, w, h) \
3029 do { \
3030 cairo_rectangle (cr, x, y, w, h); \
3031 cairo_fill (cr); \
3032 } \
3033 while (0)
3034#else /* ! HAVE_GTK3 */
3024 GdkGCValues vals; 3035 GdkGCValues vals;
3025 GdkGC *gc; 3036 GdkGC *gc;
3026 vals.foreground.pixel = (FRAME_FOREGROUND_PIXEL (f) 3037 vals.foreground.pixel = (FRAME_FOREGROUND_PIXEL (f)
@@ -3030,7 +3041,8 @@ XTflash (struct frame *f)
3030 &vals, GDK_GC_FUNCTION | GDK_GC_FOREGROUND); 3041 &vals, GDK_GC_FUNCTION | GDK_GC_FOREGROUND);
3031#define XFillRectangle(d, win, gc, x, y, w, h) \ 3042#define XFillRectangle(d, win, gc, x, y, w, h) \
3032 gdk_draw_rectangle (window, gc, TRUE, x, y, w, h) 3043 gdk_draw_rectangle (window, gc, TRUE, x, y, w, h)
3033#else 3044#endif /* ! HAVE_GTK3 */
3045#else /* ! USE_GTK */
3034 GC gc; 3046 GC gc;
3035 3047
3036 /* Create a GC that will use the GXxor function to flip foreground 3048 /* Create a GC that will use the GXxor function to flip foreground
@@ -3151,7 +3163,11 @@ XTflash (struct frame *f)
3151 width, height - 2 * FRAME_INTERNAL_BORDER_WIDTH (f)); 3163 width, height - 2 * FRAME_INTERNAL_BORDER_WIDTH (f));
3152 3164
3153#ifdef USE_GTK 3165#ifdef USE_GTK
3166#ifdef HAVE_GTK3
3167 cairo_destroy (cr);
3168#else
3154 g_object_unref (G_OBJECT (gc)); 3169 g_object_unref (G_OBJECT (gc));
3170#endif
3155#undef XFillRectangle 3171#undef XFillRectangle
3156#else 3172#else
3157 XFreeGC (FRAME_X_DISPLAY (f), gc); 3173 XFreeGC (FRAME_X_DISPLAY (f), gc);
@@ -9863,6 +9879,13 @@ x_term_init (Lisp_Object display_name, char *xrm_option, char *resource_name)
9863 9879
9864 XSetLocaleModifiers (""); 9880 XSetLocaleModifiers ("");
9865 9881
9882 /* Emacs can only handle core input events, so make sure
9883 Gtk doesn't use Xinput or Xinput2 extensions. */
9884 {
9885 static char fix_events[] = "GDK_CORE_DEVICE_EVENTS=1";
9886 putenv (fix_events);
9887 }
9888
9866 /* Work around GLib bug that outputs a faulty warning. See 9889 /* Work around GLib bug that outputs a faulty warning. See
9867 https://bugzilla.gnome.org/show_bug.cgi?id=563627. */ 9890 https://bugzilla.gnome.org/show_bug.cgi?id=563627. */
9868 id = g_log_set_handler ("GLib", G_LOG_LEVEL_WARNING | G_LOG_FLAG_FATAL 9891 id = g_log_set_handler ("GLib", G_LOG_LEVEL_WARNING | G_LOG_FLAG_FATAL
@@ -9874,11 +9897,12 @@ x_term_init (Lisp_Object display_name, char *xrm_option, char *resource_name)
9874 fixup_locale (); 9897 fixup_locale ();
9875 xg_initialize (); 9898 xg_initialize ();
9876 9899
9877 dpy = GDK_DISPLAY (); 9900 dpy = DEFAULT_GDK_DISPLAY ();
9878 9901
9879 /* NULL window -> events for all windows go to our function */ 9902 /* NULL window -> events for all windows go to our function */
9880 gdk_window_add_filter (NULL, event_handler_gdk, NULL); 9903 gdk_window_add_filter (NULL, event_handler_gdk, NULL);
9881 9904
9905#if GTK_MAJOR_VERSION <= 2 && GTK_MINOR_VERSION <= 90
9882 /* Load our own gtkrc if it exists. */ 9906 /* Load our own gtkrc if it exists. */
9883 { 9907 {
9884 const char *file = "~/.emacs.d/gtkrc"; 9908 const char *file = "~/.emacs.d/gtkrc";
@@ -9890,6 +9914,7 @@ x_term_init (Lisp_Object display_name, char *xrm_option, char *resource_name)
9890 if (! NILP (abs_file) && !NILP (Ffile_readable_p (abs_file))) 9914 if (! NILP (abs_file) && !NILP (Ffile_readable_p (abs_file)))
9891 gtk_rc_parse (SSDATA (abs_file)); 9915 gtk_rc_parse (SSDATA (abs_file));
9892 } 9916 }
9917#endif
9893 9918
9894 XSetErrorHandler (x_error_handler); 9919 XSetErrorHandler (x_error_handler);
9895 XSetIOErrorHandler (x_io_error_quitter); 9920 XSetIOErrorHandler (x_io_error_quitter);
diff --git a/src/xterm.h b/src/xterm.h
index 48d68557796..ee17cfe2bd5 100644
--- a/src/xterm.h
+++ b/src/xterm.h
@@ -675,9 +675,20 @@ enum
675#define gtk_adjustment_get_upper(w) ((w)->upper) 675#define gtk_adjustment_get_upper(w) ((w)->upper)
676#endif 676#endif
677 677
678#ifdef HAVE_GTK3
679#define DEFAULT_GDK_DISPLAY() \
680 gdk_x11_display_get_xdisplay (gdk_display_get_default ())
681#else
682#undef GDK_WINDOW_XID
683#define GDK_WINDOW_XID(w) GDK_WINDOW_XWINDOW (w)
684#define DEFAULT_GDK_DISPLAY() GDK_DISPLAY ()
685#define gtk_widget_get_preferred_size(a, ign, b) \
686 gtk_widget_size_request(a, b)
687#endif
688
678#define GTK_WIDGET_TO_X_WIN(w) \ 689#define GTK_WIDGET_TO_X_WIN(w) \
679 ((w) && gtk_widget_get_window (w) \ 690 ((w) && gtk_widget_get_window (w) \
680 ? GDK_WINDOW_XWINDOW (gtk_widget_get_window (w)) : 0) 691 ? GDK_WINDOW_XID (gtk_widget_get_window (w)) : 0)
681 692
682#define FRAME_GTK_OUTER_WIDGET(f) ((f)->output_data.x->widget) 693#define FRAME_GTK_OUTER_WIDGET(f) ((f)->output_data.x->widget)
683#define FRAME_GTK_WIDGET(f) ((f)->output_data.x->edit_widget) 694#define FRAME_GTK_WIDGET(f) ((f)->output_data.x->edit_widget)