aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPo Lu2022-01-31 20:21:04 +0800
committerPo Lu2022-01-31 20:21:04 +0800
commit46473a4eac2579b88ec843e1301eb2a89835e2ae (patch)
treef945e81e20b215f2f5cf2188b1ddf141415b75a9 /src
parent790ad61fcf91c75811ed30d21518e1dac99be044 (diff)
downloademacs-46473a4eac2579b88ec843e1301eb2a89835e2ae.tar.gz
emacs-46473a4eac2579b88ec843e1301eb2a89835e2ae.zip
Implement `alpha-background' on PGTK
* src/ftcrfont.c (ftcrfont_draw): Respect alpha-background where appropriate. * src/gtkutil.c (xg_create_frame_widgets): Swap some conditionals around to get the right visual and signal handlers on PGTK. (xg_widget_style_updated): Likewise. * src/pgtkfns.c (pgtk_set_alpha_background): New function. (pgtk_frame_parm_handlers): Add it instead of the generic param handler. (Fx_create_frame): Fix typo. * src/pgtkterm.c (pgtk_fill_rectangle): (pgtk_set_cr_source_with_gc_foreground): (pgtk_set_cr_source_with_gc_background): (pgtk_set_cr_source_with_color): New argument `respect_alpha_backend'. All callers changed. * src/pgtkterm.h: Update function prototypes.
Diffstat (limited to 'src')
-rw-r--r--src/ftcrfont.c4
-rw-r--r--src/gtkutil.c40
-rw-r--r--src/pgtkfns.c22
-rw-r--r--src/pgtkterm.c137
-rw-r--r--src/pgtkterm.h9
5 files changed, 130 insertions, 82 deletions
diff --git a/src/ftcrfont.c b/src/ftcrfont.c
index 558e44d5b91..c327146ba28 100644
--- a/src/ftcrfont.c
+++ b/src/ftcrfont.c
@@ -557,7 +557,7 @@ ftcrfont_draw (struct glyph_string *s,
557#ifdef HAVE_X_WINDOWS 557#ifdef HAVE_X_WINDOWS
558 x_set_cr_source_with_gc_background (f, s->gc); 558 x_set_cr_source_with_gc_background (f, s->gc);
559#else 559#else
560 pgtk_set_cr_source_with_color (f, s->xgcv.background); 560 pgtk_set_cr_source_with_color (f, s->xgcv.background, true);
561#endif 561#endif
562#else 562#else
563 struct face *face = s->face; 563 struct face *face = s->face;
@@ -589,7 +589,7 @@ ftcrfont_draw (struct glyph_string *s,
589#ifdef HAVE_X_WINDOWS 589#ifdef HAVE_X_WINDOWS
590 x_set_cr_source_with_gc_foreground (f, s->gc); 590 x_set_cr_source_with_gc_foreground (f, s->gc);
591#else 591#else
592 pgtk_set_cr_source_with_color (f, s->xgcv.foreground); 592 pgtk_set_cr_source_with_color (f, s->xgcv.foreground, false);
593#endif 593#endif
594#else 594#else
595 uint32_t col = s->hl == DRAW_CURSOR ? 595 uint32_t col = s->hl == DRAW_CURSOR ?
diff --git a/src/gtkutil.c b/src/gtkutil.c
index b961cdedca9..b59bf4ebad5 100644
--- a/src/gtkutil.c
+++ b/src/gtkutil.c
@@ -81,11 +81,11 @@ static void xg_im_context_commit (GtkIMContext *, gchar *, gpointer);
81static void xg_im_context_preedit_changed (GtkIMContext *, gpointer); 81static void xg_im_context_preedit_changed (GtkIMContext *, gpointer);
82static void xg_im_context_preedit_end (GtkIMContext *, gpointer); 82static void xg_im_context_preedit_end (GtkIMContext *, gpointer);
83static bool xg_widget_key_press_event_cb (GtkWidget *, GdkEvent *, gpointer); 83static bool xg_widget_key_press_event_cb (GtkWidget *, GdkEvent *, gpointer);
84#endif
84 85
85#if GTK_CHECK_VERSION (3, 10, 0) 86#if GTK_CHECK_VERSION (3, 10, 0)
86static void xg_widget_style_updated (GtkWidget *, gpointer); 87static void xg_widget_style_updated (GtkWidget *, gpointer);
87#endif 88#endif
88#endif
89 89
90#ifndef HAVE_GTK3 90#ifndef HAVE_GTK3
91 91
@@ -1464,13 +1464,6 @@ xg_create_frame_widgets (struct frame *f)
1464 } 1464 }
1465 else 1465 else
1466 wtop = gtk_window_new (type); 1466 wtop = gtk_window_new (type);
1467
1468#if GTK_CHECK_VERSION (3, 10, 0)
1469 g_signal_connect (G_OBJECT (wtop), "style-updated",
1470 G_CALLBACK (xg_widget_style_updated), f);
1471#endif
1472
1473 gtk_widget_set_app_paintable (wtop, f->alpha_background != 1.0);
1474#else 1467#else
1475 if (f->tooltip) 1468 if (f->tooltip)
1476 { 1469 {
@@ -1480,6 +1473,12 @@ xg_create_frame_widgets (struct frame *f)
1480 gtk_widget_add_events (wtop, GDK_ALL_EVENTS_MASK); 1473 gtk_widget_add_events (wtop, GDK_ALL_EVENTS_MASK);
1481#endif 1474#endif
1482 1475
1476 gtk_widget_set_app_paintable (wtop, f->alpha_background != 1.0);
1477#if GTK_CHECK_VERSION (3, 10, 0)
1478 g_signal_connect (G_OBJECT (wtop), "style-updated",
1479 G_CALLBACK (xg_widget_style_updated), f);
1480#endif
1481
1483 /* gtk_window_set_has_resize_grip is a Gtk+ 3.0 function but Ubuntu 1482 /* gtk_window_set_has_resize_grip is a Gtk+ 3.0 function but Ubuntu
1484 has backported it to Gtk+ 2.0 and they add the resize grip for 1483 has backported it to Gtk+ 2.0 and they add the resize grip for
1485 Gtk+ 2.0 applications also. But it has a bug that makes Emacs loop 1484 Gtk+ 2.0 applications also. But it has a bug that makes Emacs loop
@@ -1606,10 +1605,12 @@ xg_create_frame_widgets (struct frame *f)
1606 1605
1607 if (!visual) 1606 if (!visual)
1608 emacs_abort (); 1607 emacs_abort ();
1608#else
1609 GdkVisual *visual = gdk_screen_get_argb_visual (screen);
1610#endif
1609 1611
1610 gtk_widget_set_visual (wtop, visual); 1612 gtk_widget_set_visual (wtop, visual);
1611 gtk_widget_set_visual (wfixed, visual); 1613 gtk_widget_set_visual (wfixed, visual);
1612#endif
1613 1614
1614#ifndef HAVE_PGTK 1615#ifndef HAVE_PGTK
1615 /* Must realize the windows so the X window gets created. It is used 1616 /* Must realize the windows so the X window gets created. It is used
@@ -6398,6 +6399,7 @@ xg_filter_key (struct frame *frame, XEvent *xkey)
6398 6399
6399 return result; 6400 return result;
6400} 6401}
6402#endif
6401 6403
6402#if GTK_CHECK_VERSION (3, 10, 0) 6404#if GTK_CHECK_VERSION (3, 10, 0)
6403static void 6405static void
@@ -6406,12 +6408,20 @@ xg_widget_style_updated (GtkWidget *widget, gpointer user_data)
6406 struct frame *f = user_data; 6408 struct frame *f = user_data;
6407 6409
6408 if (f->alpha_background < 1.0) 6410 if (f->alpha_background < 1.0)
6409 XChangeProperty (FRAME_X_DISPLAY (f), 6411 {
6410 FRAME_X_WINDOW (f), 6412#ifndef HAVE_PGTK
6411 FRAME_DISPLAY_INFO (f)->Xatom_net_wm_opaque_region, 6413 XChangeProperty (FRAME_X_DISPLAY (f),
6412 XA_CARDINAL, 32, PropModeReplace, 6414 FRAME_X_WINDOW (f),
6413 NULL, 0); 6415 FRAME_DISPLAY_INFO (f)->Xatom_net_wm_opaque_region,
6414} 6416 XA_CARDINAL, 32, PropModeReplace,
6417 NULL, 0);
6418#else
6419 if (FRAME_GTK_OUTER_WIDGET (f)
6420 && gtk_widget_get_realized (FRAME_GTK_OUTER_WIDGET (f)))
6421 gdk_window_set_opaque_region (gtk_widget_get_window (FRAME_GTK_OUTER_WIDGET (f)),
6422 NULL);
6415#endif 6423#endif
6424 }
6425}
6416#endif 6426#endif
6417#endif /* USE_GTK */ 6427#endif /* USE_GTK */
diff --git a/src/pgtkfns.c b/src/pgtkfns.c
index 5980b31d6e2..c7987afc7db 100644
--- a/src/pgtkfns.c
+++ b/src/pgtkfns.c
@@ -235,6 +235,24 @@ x_set_background_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
235} 235}
236 236
237static void 237static void
238pgtk_set_alpha_background (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
239{
240 gui_set_alpha_background (f, arg, oldval);
241
242 /* This prevents GTK from painting the window's background, which
243 interferes with transparent background in some environments */
244
245 gtk_widget_set_app_paintable (FRAME_GTK_OUTER_WIDGET (f),
246 f->alpha_background != 1.0);
247
248 if (FRAME_GTK_OUTER_WIDGET (f)
249 && gtk_widget_get_realized (FRAME_GTK_OUTER_WIDGET (f))
250 && f->alpha_background != 1.0)
251 gdk_window_set_opaque_region (gtk_widget_get_window (FRAME_GTK_OUTER_WIDGET (f)),
252 NULL);
253}
254
255static void
238x_set_border_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval) 256x_set_border_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
239{ 257{
240 int pix; 258 int pix;
@@ -1043,7 +1061,7 @@ frame_parm_handler pgtk_frame_parm_handlers[] = {
1043 x_set_z_group, 1061 x_set_z_group,
1044 x_set_override_redirect, 1062 x_set_override_redirect,
1045 gui_set_no_special_glyphs, 1063 gui_set_no_special_glyphs,
1046 gui_set_alpha_background, 1064 pgtk_set_alpha_background,
1047}; 1065};
1048 1066
1049 1067
@@ -1668,7 +1686,7 @@ This function is an internal primitive--use `make-frame' instead. */ )
1668 RES_TYPE_NUMBER); 1686 RES_TYPE_NUMBER);
1669 gui_default_parameter (f, parms, Qalpha, Qnil, 1687 gui_default_parameter (f, parms, Qalpha, Qnil,
1670 "alpha", "Alpha", RES_TYPE_NUMBER); 1688 "alpha", "Alpha", RES_TYPE_NUMBER);
1671 gui_default_parameter (f, parms, Qalpha, Qnil, 1689 gui_default_parameter (f, parms, Qalpha_background, Qnil,
1672 "alphaBackground", "AlphaBackground", RES_TYPE_NUMBER); 1690 "alphaBackground", "AlphaBackground", RES_TYPE_NUMBER);
1673 1691
1674 if (!NILP (parent_frame)) 1692 if (!NILP (parent_frame))
diff --git a/src/pgtkterm.c b/src/pgtkterm.c
index efbeaafaf1a..9bb611e4c58 100644
--- a/src/pgtkterm.c
+++ b/src/pgtkterm.c
@@ -101,7 +101,8 @@ static void pgtk_delete_display (struct pgtk_display_info *dpyinfo);
101static void pgtk_clear_frame_area (struct frame *f, int x, int y, int width, 101static void pgtk_clear_frame_area (struct frame *f, int x, int y, int width,
102 int height); 102 int height);
103static void pgtk_fill_rectangle (struct frame *f, unsigned long color, int x, 103static void pgtk_fill_rectangle (struct frame *f, unsigned long color, int x,
104 int y, int width, int height); 104 int y, int width, int height,
105 bool respect_alpha_background);
105static void pgtk_clip_to_row (struct window *w, struct glyph_row *row, 106static void pgtk_clip_to_row (struct window *w, struct glyph_row *row,
106 enum glyph_row_area area, cairo_t * cr); 107 enum glyph_row_area area, cairo_t * cr);
107static struct frame *pgtk_any_window_to_frame (GdkWindow * window); 108static struct frame *pgtk_any_window_to_frame (GdkWindow * window);
@@ -1243,7 +1244,7 @@ pgtk_compute_glyph_string_overhangs (struct glyph_string *s)
1243static void 1244static void
1244x_clear_glyph_string_rect (struct glyph_string *s, int x, int y, int w, int h) 1245x_clear_glyph_string_rect (struct glyph_string *s, int x, int y, int w, int h)
1245{ 1246{
1246 pgtk_fill_rectangle (s->f, s->xgcv.background, x, y, w, h); 1247 pgtk_fill_rectangle (s->f, s->xgcv.background, x, y, w, h, true);
1247} 1248}
1248 1249
1249 1250
@@ -1328,13 +1329,13 @@ x_draw_glyph_string_background (struct glyph_string *s, bool force_p)
1328 1329
1329static void 1330static void
1330pgtk_draw_rectangle (struct frame *f, unsigned long color, int x, int y, 1331pgtk_draw_rectangle (struct frame *f, unsigned long color, int x, int y,
1331 int width, int height) 1332 int width, int height, bool respect_alpha_background)
1332{ 1333{
1333 cairo_t *cr; 1334 cairo_t *cr;
1334 1335
1335 cr = pgtk_begin_cr_clip (f); 1336 cr = pgtk_begin_cr_clip (f);
1336 pgtk_set_cr_source_with_color (f, color); 1337 pgtk_set_cr_source_with_color (f, color, true);
1337 cairo_rectangle (cr, x + 0.5, y + 0.5, width, height); 1338 cairo_rectangle (cr, x + 0.5, y + 0.5, width, respect_alpha_background);
1338 cairo_set_line_width (cr, 1); 1339 cairo_set_line_width (cr, 1);
1339 cairo_stroke (cr); 1340 cairo_stroke (cr);
1340 pgtk_end_cr_clip (f); 1341 pgtk_end_cr_clip (f);
@@ -1363,7 +1364,8 @@ x_draw_glyph_string_foreground (struct glyph_string *s)
1363 struct glyph *g = s->first_glyph + i; 1364 struct glyph *g = s->first_glyph + i;
1364 pgtk_draw_rectangle (s->f, 1365 pgtk_draw_rectangle (s->f,
1365 s->face->foreground, x, s->y, 1366 s->face->foreground, x, s->y,
1366 g->pixel_width - 1, s->height - 1); 1367 g->pixel_width - 1, s->height - 1,
1368 false);
1367 x += g->pixel_width; 1369 x += g->pixel_width;
1368 } 1370 }
1369 } 1371 }
@@ -1413,7 +1415,7 @@ x_draw_composite_glyph_string_foreground (struct glyph_string *s)
1413 { 1415 {
1414 if (s->cmp_from == 0) 1416 if (s->cmp_from == 0)
1415 pgtk_draw_rectangle (s->f, s->face->foreground, x, s->y, 1417 pgtk_draw_rectangle (s->f, s->face->foreground, x, s->y,
1416 s->width - 1, s->height - 1); 1418 s->width - 1, s->height - 1, false);
1417 } 1419 }
1418 else if (!s->first_glyph->u.cmp.automatic) 1420 else if (!s->first_glyph->u.cmp.automatic)
1419 { 1421 {
@@ -1555,7 +1557,8 @@ x_draw_glyphless_glyph_string_foreground (struct glyph_string *s)
1555 pgtk_draw_rectangle (s->f, s->face->foreground, 1557 pgtk_draw_rectangle (s->f, s->face->foreground,
1556 x, s->ybase - glyph->ascent, 1558 x, s->ybase - glyph->ascent,
1557 glyph->pixel_width - 1, 1559 glyph->pixel_width - 1,
1558 glyph->ascent + glyph->descent - 1); 1560 glyph->ascent + glyph->descent - 1,
1561 false);
1559 x += glyph->pixel_width; 1562 x += glyph->pixel_width;
1560 } 1563 }
1561} 1564}
@@ -1658,7 +1661,7 @@ x_fill_trapezoid_for_relief (struct frame *f, unsigned long color, int x,
1658 cairo_t *cr; 1661 cairo_t *cr;
1659 1662
1660 cr = pgtk_begin_cr_clip (f); 1663 cr = pgtk_begin_cr_clip (f);
1661 pgtk_set_cr_source_with_color (f, color); 1664 pgtk_set_cr_source_with_color (f, color, false);
1662 cairo_move_to (cr, top_p ? x : x + height, y); 1665 cairo_move_to (cr, top_p ? x : x + height, y);
1663 cairo_line_to (cr, x, y + height); 1666 cairo_line_to (cr, x, y + height);
1664 cairo_line_to (cr, top_p ? x + width - height : x + width, y + height); 1667 cairo_line_to (cr, top_p ? x + width - height : x + width, y + height);
@@ -1685,7 +1688,7 @@ x_erase_corners_for_relief (struct frame *f, unsigned long color, int x,
1685 int i; 1688 int i;
1686 1689
1687 cr = pgtk_begin_cr_clip (f); 1690 cr = pgtk_begin_cr_clip (f);
1688 pgtk_set_cr_source_with_color (f, color); 1691 pgtk_set_cr_source_with_color (f, color, false);
1689 for (i = 0; i < CORNER_LAST; i++) 1692 for (i = 0; i < CORNER_LAST; i++)
1690 if (corners & (1 << i)) 1693 if (corners & (1 << i))
1691 { 1694 {
@@ -1818,7 +1821,7 @@ x_draw_relief_rect (struct frame *f,
1818 if (left_p) 1821 if (left_p)
1819 { 1822 {
1820 pgtk_fill_rectangle (f, top_left_color, left_x, top_y, 1823 pgtk_fill_rectangle (f, top_left_color, left_x, top_y,
1821 vwidth, bottom_y + 1 - top_y); 1824 vwidth, bottom_y + 1 - top_y, false);
1822 if (top_p) 1825 if (top_p)
1823 corners |= 1 << CORNER_TOP_LEFT; 1826 corners |= 1 << CORNER_TOP_LEFT;
1824 if (bot_p) 1827 if (bot_p)
@@ -1827,7 +1830,7 @@ x_draw_relief_rect (struct frame *f,
1827 if (right_p) 1830 if (right_p)
1828 { 1831 {
1829 pgtk_fill_rectangle (f, bottom_right_color, right_x + 1 - vwidth, top_y, 1832 pgtk_fill_rectangle (f, bottom_right_color, right_x + 1 - vwidth, top_y,
1830 vwidth, bottom_y + 1 - top_y); 1833 vwidth, bottom_y + 1 - top_y, false);
1831 if (top_p) 1834 if (top_p)
1832 corners |= 1 << CORNER_TOP_RIGHT; 1835 corners |= 1 << CORNER_TOP_RIGHT;
1833 if (bot_p) 1836 if (bot_p)
@@ -1837,7 +1840,7 @@ x_draw_relief_rect (struct frame *f,
1837 { 1840 {
1838 if (!right_p) 1841 if (!right_p)
1839 pgtk_fill_rectangle (f, top_left_color, left_x, top_y, 1842 pgtk_fill_rectangle (f, top_left_color, left_x, top_y,
1840 right_x + 1 - left_x, hwidth); 1843 right_x + 1 - left_x, hwidth, false);
1841 else 1844 else
1842 x_fill_trapezoid_for_relief (f, top_left_color, left_x, top_y, 1845 x_fill_trapezoid_for_relief (f, top_left_color, left_x, top_y,
1843 right_x + 1 - left_x, hwidth, 1); 1846 right_x + 1 - left_x, hwidth, 1);
@@ -1847,7 +1850,7 @@ x_draw_relief_rect (struct frame *f,
1847 if (!left_p) 1850 if (!left_p)
1848 pgtk_fill_rectangle (f, bottom_right_color, left_x, 1851 pgtk_fill_rectangle (f, bottom_right_color, left_x,
1849 bottom_y + 1 - hwidth, right_x + 1 - left_x, 1852 bottom_y + 1 - hwidth, right_x + 1 - left_x,
1850 hwidth); 1853 hwidth, false);
1851 else 1854 else
1852 x_fill_trapezoid_for_relief (f, bottom_right_color, 1855 x_fill_trapezoid_for_relief (f, bottom_right_color,
1853 left_x, bottom_y + 1 - hwidth, 1856 left_x, bottom_y + 1 - hwidth,
@@ -1855,10 +1858,10 @@ x_draw_relief_rect (struct frame *f,
1855 } 1858 }
1856 if (left_p && vwidth > 1) 1859 if (left_p && vwidth > 1)
1857 pgtk_fill_rectangle (f, bottom_right_color, left_x, top_y, 1860 pgtk_fill_rectangle (f, bottom_right_color, left_x, top_y,
1858 1, bottom_y + 1 - top_y); 1861 1, bottom_y + 1 - top_y, false);
1859 if (top_p && hwidth > 1) 1862 if (top_p && hwidth > 1)
1860 pgtk_fill_rectangle (f, bottom_right_color, left_x, top_y, 1863 pgtk_fill_rectangle (f, bottom_right_color, left_x, top_y,
1861 right_x + 1 - left_x, 1); 1864 right_x + 1 - left_x, 1, false);
1862 if (corners) 1865 if (corners)
1863 { 1866 {
1864 x_erase_corners_for_relief (f, FRAME_BACKGROUND_PIXEL (f), left_x, 1867 x_erase_corners_for_relief (f, FRAME_BACKGROUND_PIXEL (f), left_x,
@@ -1893,23 +1896,25 @@ x_draw_box_rect (struct glyph_string *s,
1893 1896
1894 /* Top. */ 1897 /* Top. */
1895 pgtk_fill_rectangle (s->f, s->xgcv.foreground, 1898 pgtk_fill_rectangle (s->f, s->xgcv.foreground,
1896 left_x, top_y, right_x - left_x + 1, hwidth); 1899 left_x, top_y, right_x - left_x + 1, hwidth,
1900 false);
1897 1901
1898 /* Left. */ 1902 /* Left. */
1899 if (left_p) 1903 if (left_p)
1900 pgtk_fill_rectangle (s->f, s->xgcv.foreground, 1904 pgtk_fill_rectangle (s->f, s->xgcv.foreground,
1901 left_x, top_y, vwidth, bottom_y - top_y + 1); 1905 left_x, top_y, vwidth, bottom_y - top_y + 1,
1906 false);
1902 1907
1903 /* Bottom. */ 1908 /* Bottom. */
1904 pgtk_fill_rectangle (s->f, s->xgcv.foreground, 1909 pgtk_fill_rectangle (s->f, s->xgcv.foreground,
1905 left_x, bottom_y - hwidth + 1, right_x - left_x + 1, 1910 left_x, bottom_y - hwidth + 1, right_x - left_x + 1,
1906 hwidth); 1911 hwidth, false);
1907 1912
1908 /* Right. */ 1913 /* Right. */
1909 if (right_p) 1914 if (right_p)
1910 pgtk_fill_rectangle (s->f, s->xgcv.foreground, 1915 pgtk_fill_rectangle (s->f, s->xgcv.foreground,
1911 right_x - vwidth + 1, top_y, vwidth, 1916 right_x - vwidth + 1, top_y, vwidth,
1912 bottom_y - top_y + 1); 1917 bottom_y - top_y + 1, false);
1913 1918
1914 s->xgcv.foreground = foreground_backup; 1919 s->xgcv.foreground = foreground_backup;
1915 1920
@@ -1979,7 +1984,7 @@ x_draw_horizontal_wave (struct frame *f, unsigned long color, int x, int y,
1979 int xoffset, n; 1984 int xoffset, n;
1980 1985
1981 cr = pgtk_begin_cr_clip (f); 1986 cr = pgtk_begin_cr_clip (f);
1982 pgtk_set_cr_source_with_color (f, color); 1987 pgtk_set_cr_source_with_color (f, color, false);
1983 cairo_rectangle (cr, x, y, width, height); 1988 cairo_rectangle (cr, x, y, width, height);
1984 cairo_clip (cr); 1989 cairo_clip (cr);
1985 1990
@@ -2155,7 +2160,7 @@ x_cr_draw_image (struct frame *f, Emacs_GC *gc, cairo_pattern_t *image,
2155 cairo_rectangle (cr, dest_x, dest_y, width, height); 2160 cairo_rectangle (cr, dest_x, dest_y, width, height);
2156 else 2161 else
2157 { 2162 {
2158 pgtk_set_cr_source_with_gc_background (f, gc); 2163 pgtk_set_cr_source_with_gc_background (f, gc, false);
2159 cairo_rectangle (cr, dest_x, dest_y, width, height); 2164 cairo_rectangle (cr, dest_x, dest_y, width, height);
2160 cairo_fill_preserve (cr); 2165 cairo_fill_preserve (cr);
2161 } 2166 }
@@ -2172,7 +2177,7 @@ x_cr_draw_image (struct frame *f, Emacs_GC *gc, cairo_pattern_t *image,
2172 } 2177 }
2173 else 2178 else
2174 { 2179 {
2175 pgtk_set_cr_source_with_gc_foreground (f, gc); 2180 pgtk_set_cr_source_with_gc_foreground (f, gc, false);
2176 cairo_clip (cr); 2181 cairo_clip (cr);
2177 cairo_mask (cr, image); 2182 cairo_mask (cr, image);
2178 } 2183 }
@@ -2222,7 +2227,7 @@ x_draw_image_foreground (struct glyph_string *s)
2222 int relief = eabs (s->img->relief); 2227 int relief = eabs (s->img->relief);
2223 pgtk_draw_rectangle (s->f, s->xgcv.foreground, x - relief, y - relief, 2228 pgtk_draw_rectangle (s->f, s->xgcv.foreground, x - relief, y - relief,
2224 s->slice.width + relief*2 - 1, 2229 s->slice.width + relief*2 - 1,
2225 s->slice.height + relief*2 - 1); 2230 s->slice.height + relief*2 - 1, false);
2226 } 2231 }
2227 } 2232 }
2228 pgtk_end_cr_clip (s->f); 2233 pgtk_end_cr_clip (s->f);
@@ -2230,7 +2235,7 @@ x_draw_image_foreground (struct glyph_string *s)
2230 else 2235 else
2231 /* Draw a rectangle if image could not be loaded. */ 2236 /* Draw a rectangle if image could not be loaded. */
2232 pgtk_draw_rectangle (s->f, s->xgcv.foreground, x, y, 2237 pgtk_draw_rectangle (s->f, s->xgcv.foreground, x, y,
2233 s->slice.width - 1, s->slice.height - 1); 2238 s->slice.width - 1, s->slice.height - 1, false);
2234} 2239}
2235 2240
2236/* Draw image glyph string S. 2241/* Draw image glyph string S.
@@ -2375,7 +2380,8 @@ x_draw_stretch_glyph_string (struct glyph_string *s)
2375 } 2380 }
2376 else 2381 else
2377 { 2382 {
2378 pgtk_fill_rectangle (s->f, color, x, y, w, h); 2383 pgtk_fill_rectangle (s->f, color, x, y, w, h,
2384 false);
2379 } 2385 }
2380 2386
2381 pgtk_end_cr_clip (s->f); 2387 pgtk_end_cr_clip (s->f);
@@ -2601,11 +2607,13 @@ pgtk_draw_glyph_string (struct glyph_string *s)
2601 y = s->ybase + position; 2607 y = s->ybase + position;
2602 if (s->face->underline_defaulted_p) 2608 if (s->face->underline_defaulted_p)
2603 pgtk_fill_rectangle (s->f, s->xgcv.foreground, 2609 pgtk_fill_rectangle (s->f, s->xgcv.foreground,
2604 s->x, y, s->width, thickness); 2610 s->x, y, s->width, thickness,
2611 false);
2605 else 2612 else
2606 { 2613 {
2607 pgtk_fill_rectangle (s->f, s->face->underline_color, 2614 pgtk_fill_rectangle (s->f, s->face->underline_color,
2608 s->x, y, s->width, thickness); 2615 s->x, y, s->width, thickness,
2616 false);
2609 } 2617 }
2610 } 2618 }
2611 } 2619 }
@@ -2616,11 +2624,11 @@ pgtk_draw_glyph_string (struct glyph_string *s)
2616 2624
2617 if (s->face->overline_color_defaulted_p) 2625 if (s->face->overline_color_defaulted_p)
2618 pgtk_fill_rectangle (s->f, s->xgcv.foreground, s->x, s->y + dy, 2626 pgtk_fill_rectangle (s->f, s->xgcv.foreground, s->x, s->y + dy,
2619 s->width, h); 2627 s->width, h, false);
2620 else 2628 else
2621 { 2629 {
2622 pgtk_fill_rectangle (s->f, s->face->overline_color, s->x, 2630 pgtk_fill_rectangle (s->f, s->face->overline_color, s->x,
2623 s->y + dy, s->width, h); 2631 s->y + dy, s->width, h, false);
2624 } 2632 }
2625 } 2633 }
2626 2634
@@ -2641,11 +2649,11 @@ pgtk_draw_glyph_string (struct glyph_string *s)
2641 2649
2642 if (s->face->strike_through_color_defaulted_p) 2650 if (s->face->strike_through_color_defaulted_p)
2643 pgtk_fill_rectangle (s->f, s->xgcv.foreground, s->x, glyph_y + dy, 2651 pgtk_fill_rectangle (s->f, s->xgcv.foreground, s->x, glyph_y + dy,
2644 s->width, h); 2652 s->width, h, false);
2645 else 2653 else
2646 { 2654 {
2647 pgtk_fill_rectangle (s->f, s->face->strike_through_color, s->x, 2655 pgtk_fill_rectangle (s->f, s->face->strike_through_color, s->x,
2648 glyph_y + dy, s->width, h); 2656 glyph_y + dy, s->width, h, false);
2649 } 2657 }
2650 } 2658 }
2651 2659
@@ -2778,7 +2786,7 @@ x_draw_hollow_cursor (struct window *w, struct glyph_row *row)
2778 /* The foreground of cursor_gc is typically the same as the normal 2786 /* The foreground of cursor_gc is typically the same as the normal
2779 background color, which can cause the cursor box to be invisible. */ 2787 background color, which can cause the cursor box to be invisible. */
2780 cairo_t *cr = pgtk_begin_cr_clip (f); 2788 cairo_t *cr = pgtk_begin_cr_clip (f);
2781 pgtk_set_cr_source_with_color (f, FRAME_X_OUTPUT (f)->cursor_color); 2789 pgtk_set_cr_source_with_color (f, FRAME_X_OUTPUT (f)->cursor_color, false);
2782 2790
2783 /* When on R2L character, show cursor at the right edge of the 2791 /* When on R2L character, show cursor at the right edge of the
2784 glyph, unless the cursor box is as wide as the glyph or wider 2792 glyph, unless the cursor box is as wide as the glyph or wider
@@ -2792,7 +2800,7 @@ x_draw_hollow_cursor (struct window *w, struct glyph_row *row)
2792 } 2800 }
2793 /* Set clipping, draw the rectangle, and reset clipping again. */ 2801 /* Set clipping, draw the rectangle, and reset clipping again. */
2794 pgtk_clip_to_row (w, row, TEXT_AREA, cr); 2802 pgtk_clip_to_row (w, row, TEXT_AREA, cr);
2795 pgtk_draw_rectangle (f, FRAME_X_OUTPUT (f)->cursor_color, x, y, wd, h - 1); 2803 pgtk_draw_rectangle (f, FRAME_X_OUTPUT (f)->cursor_color, x, y, wd, h - 1, false);
2796 pgtk_end_cr_clip (f); 2804 pgtk_end_cr_clip (f);
2797} 2805}
2798 2806
@@ -2866,7 +2874,7 @@ x_draw_bar_cursor (struct window *w, struct glyph_row *row, int width,
2866 2874
2867 pgtk_fill_rectangle (f, color, x, 2875 pgtk_fill_rectangle (f, color, x,
2868 WINDOW_TO_FRAME_PIXEL_Y (w, w->phys_cursor.y), 2876 WINDOW_TO_FRAME_PIXEL_Y (w, w->phys_cursor.y),
2869 width, row->height); 2877 width, row->height, false);
2870 } 2878 }
2871 else /* HBAR_CURSOR */ 2879 else /* HBAR_CURSOR */
2872 { 2880 {
@@ -2887,7 +2895,7 @@ x_draw_bar_cursor (struct window *w, struct glyph_row *row, int width,
2887 pgtk_fill_rectangle (f, color, x, 2895 pgtk_fill_rectangle (f, color, x,
2888 WINDOW_TO_FRAME_PIXEL_Y (w, w->phys_cursor.y + 2896 WINDOW_TO_FRAME_PIXEL_Y (w, w->phys_cursor.y +
2889 row->height - width), 2897 row->height - width),
2890 w->phys_cursor_width - 1, width); 2898 w->phys_cursor_width - 1, width, false);
2891 } 2899 }
2892 2900
2893 pgtk_end_cr_clip (f); 2901 pgtk_end_cr_clip (f);
@@ -3241,7 +3249,7 @@ pgtk_draw_vertical_window_border (struct window *w, int x, int y0, int y1)
3241 3249
3242 face = FACE_FROM_ID_OR_NULL (f, VERTICAL_BORDER_FACE_ID); 3250 face = FACE_FROM_ID_OR_NULL (f, VERTICAL_BORDER_FACE_ID);
3243 if (face) 3251 if (face)
3244 pgtk_set_cr_source_with_color (f, face->foreground); 3252 pgtk_set_cr_source_with_color (f, face->foreground, false);
3245 3253
3246 cairo_rectangle (cr, x, y0, 1, y1 - y0); 3254 cairo_rectangle (cr, x, y0, 1, y1 - y0);
3247 cairo_fill (cr); 3255 cairo_fill (cr);
@@ -3272,32 +3280,32 @@ pgtk_draw_window_divider (struct window *w, int x0, int x1, int y0, int y1)
3272 if (y1 - y0 > x1 - x0 && x1 - x0 > 2) 3280 if (y1 - y0 > x1 - x0 && x1 - x0 > 2)
3273 /* Vertical. */ 3281 /* Vertical. */
3274 { 3282 {
3275 pgtk_set_cr_source_with_color (f, color_first); 3283 pgtk_set_cr_source_with_color (f, color_first, false);
3276 cairo_rectangle (cr, x0, y0, 1, y1 - y0); 3284 cairo_rectangle (cr, x0, y0, 1, y1 - y0);
3277 cairo_fill (cr); 3285 cairo_fill (cr);
3278 pgtk_set_cr_source_with_color (f, color); 3286 pgtk_set_cr_source_with_color (f, color, false);
3279 cairo_rectangle (cr, x0 + 1, y0, x1 - x0 - 2, y1 - y0); 3287 cairo_rectangle (cr, x0 + 1, y0, x1 - x0 - 2, y1 - y0);
3280 cairo_fill (cr); 3288 cairo_fill (cr);
3281 pgtk_set_cr_source_with_color (f, color_last); 3289 pgtk_set_cr_source_with_color (f, color_last, false);
3282 cairo_rectangle (cr, x1 - 1, y0, 1, y1 - y0); 3290 cairo_rectangle (cr, x1 - 1, y0, 1, y1 - y0);
3283 cairo_fill (cr); 3291 cairo_fill (cr);
3284 } 3292 }
3285 else if (x1 - x0 > y1 - y0 && y1 - y0 > 3) 3293 else if (x1 - x0 > y1 - y0 && y1 - y0 > 3)
3286 /* Horizontal. */ 3294 /* Horizontal. */
3287 { 3295 {
3288 pgtk_set_cr_source_with_color (f, color_first); 3296 pgtk_set_cr_source_with_color (f, color_first, false);
3289 cairo_rectangle (cr, x0, y0, x1 - x0, 1); 3297 cairo_rectangle (cr, x0, y0, x1 - x0, 1);
3290 cairo_fill (cr); 3298 cairo_fill (cr);
3291 pgtk_set_cr_source_with_color (f, color); 3299 pgtk_set_cr_source_with_color (f, color, false);
3292 cairo_rectangle (cr, x0, y0 + 1, x1 - x0, y1 - y0 - 2); 3300 cairo_rectangle (cr, x0, y0 + 1, x1 - x0, y1 - y0 - 2);
3293 cairo_fill (cr); 3301 cairo_fill (cr);
3294 pgtk_set_cr_source_with_color (f, color_last); 3302 pgtk_set_cr_source_with_color (f, color_last, false);
3295 cairo_rectangle (cr, x0, y1 - 1, x1 - x0, 1); 3303 cairo_rectangle (cr, x0, y1 - 1, x1 - x0, 1);
3296 cairo_fill (cr); 3304 cairo_fill (cr);
3297 } 3305 }
3298 else 3306 else
3299 { 3307 {
3300 pgtk_set_cr_source_with_color (f, color); 3308 pgtk_set_cr_source_with_color (f, color, false);
3301 cairo_rectangle (cr, x0, y0, x1 - x0, y1 - y0); 3309 cairo_rectangle (cr, x0, y0, x1 - x0, y1 - y0);
3302 cairo_fill (cr); 3310 cairo_fill (cr);
3303 } 3311 }
@@ -3520,7 +3528,7 @@ pgtk_cr_draw_image (struct frame *f, Emacs_GC * gc, cairo_pattern_t * image,
3520 cairo_rectangle (cr, dest_x, dest_y, width, height); 3528 cairo_rectangle (cr, dest_x, dest_y, width, height);
3521 else 3529 else
3522 { 3530 {
3523 pgtk_set_cr_source_with_gc_background (f, gc); 3531 pgtk_set_cr_source_with_gc_background (f, gc, false);
3524 cairo_rectangle (cr, dest_x, dest_y, width, height); 3532 cairo_rectangle (cr, dest_x, dest_y, width, height);
3525 cairo_fill_preserve (cr); 3533 cairo_fill_preserve (cr);
3526 } 3534 }
@@ -3536,7 +3544,7 @@ pgtk_cr_draw_image (struct frame *f, Emacs_GC * gc, cairo_pattern_t * image,
3536 } 3544 }
3537 else 3545 else
3538 { 3546 {
3539 pgtk_set_cr_source_with_gc_foreground (f, gc); 3547 pgtk_set_cr_source_with_gc_foreground (f, gc, false);
3540 cairo_clip (cr); 3548 cairo_clip (cr);
3541 cairo_mask (cr, image); 3549 cairo_mask (cr, image);
3542 } 3550 }
@@ -3568,7 +3576,7 @@ pgtk_draw_fringe_bitmap (struct window *w, struct glyph_row *row,
3568 } 3576 }
3569 else 3577 else
3570 { 3578 {
3571 pgtk_set_cr_source_with_color (f, face->background); 3579 pgtk_set_cr_source_with_color (f, face->background, true);
3572 cairo_rectangle (cr, p->bx, p->by, p->nx, p->ny); 3580 cairo_rectangle (cr, p->bx, p->by, p->nx, p->ny);
3573 cairo_fill (cr); 3581 cairo_fill (cr);
3574 } 3582 }
@@ -4970,11 +4978,11 @@ pgtk_handle_event (GtkWidget *widget, GdkEvent *event, gpointer *data)
4970 4978
4971static void 4979static void
4972pgtk_fill_rectangle (struct frame *f, unsigned long color, int x, int y, 4980pgtk_fill_rectangle (struct frame *f, unsigned long color, int x, int y,
4973 int width, int height) 4981 int width, int height, bool respect_alpha_background)
4974{ 4982{
4975 cairo_t *cr; 4983 cairo_t *cr;
4976 cr = pgtk_begin_cr_clip (f); 4984 cr = pgtk_begin_cr_clip (f);
4977 pgtk_set_cr_source_with_color (f, color); 4985 pgtk_set_cr_source_with_color (f, color, respect_alpha_background);
4978 cairo_rectangle (cr, x, y, width, height); 4986 cairo_rectangle (cr, x, y, width, height);
4979 cairo_fill (cr); 4987 cairo_fill (cr);
4980 pgtk_end_cr_clip (f); 4988 pgtk_end_cr_clip (f);
@@ -6913,7 +6921,8 @@ pgtk_clear_area (struct frame *f, int x, int y, int width, int height)
6913 eassert (width > 0 && height > 0); 6921 eassert (width > 0 && height > 0);
6914 6922
6915 cr = pgtk_begin_cr_clip (f); 6923 cr = pgtk_begin_cr_clip (f);
6916 pgtk_set_cr_source_with_color (f, FRAME_X_OUTPUT (f)->background_color); 6924 pgtk_set_cr_source_with_color (f, FRAME_X_OUTPUT (f)->background_color,
6925 true);
6917 cairo_rectangle (cr, x, y, width, height); 6926 cairo_rectangle (cr, x, y, width, height);
6918 cairo_fill (cr); 6927 cairo_fill (cr);
6919 pgtk_end_cr_clip (f); 6928 pgtk_end_cr_clip (f);
@@ -7095,25 +7104,39 @@ pgtk_end_cr_clip (struct frame *f)
7095} 7104}
7096 7105
7097void 7106void
7098pgtk_set_cr_source_with_gc_foreground (struct frame *f, Emacs_GC * gc) 7107pgtk_set_cr_source_with_gc_foreground (struct frame *f, Emacs_GC *gc,
7108 bool respects_alpha_background)
7099{ 7109{
7100 pgtk_set_cr_source_with_color (f, gc->foreground); 7110 pgtk_set_cr_source_with_color (f, gc->foreground,
7111 respects_alpha_background);
7101} 7112}
7102 7113
7103void 7114void
7104pgtk_set_cr_source_with_gc_background (struct frame *f, Emacs_GC * gc) 7115pgtk_set_cr_source_with_gc_background (struct frame *f, Emacs_GC *gc,
7116 bool respects_alpha_background)
7105{ 7117{
7106 pgtk_set_cr_source_with_color (f, gc->background); 7118 pgtk_set_cr_source_with_color (f, gc->background,
7119 respects_alpha_background);
7107} 7120}
7108 7121
7109void 7122void
7110pgtk_set_cr_source_with_color (struct frame *f, unsigned long color) 7123pgtk_set_cr_source_with_color (struct frame *f, unsigned long color,
7124 bool respects_alpha_background)
7111{ 7125{
7112 Emacs_Color col; 7126 Emacs_Color col;
7113 col.pixel = color; 7127 col.pixel = color;
7114 pgtk_query_color (f, &col); 7128 pgtk_query_color (f, &col);
7115 cairo_set_source_rgb (FRAME_CR_CONTEXT (f), col.red / 65535.0, 7129
7116 col.green / 65535.0, col.blue / 65535.0); 7130 if (!respects_alpha_background)
7131 cairo_set_source_rgb (FRAME_CR_CONTEXT (f), col.red / 65535.0,
7132 col.green / 65535.0, col.blue / 65535.0);
7133 else
7134 {
7135 cairo_set_source_rgba (FRAME_CR_CONTEXT (f), col.red / 65535.0,
7136 col.green / 65535.0, col.blue / 65535.0,
7137 f->alpha_background);
7138 cairo_set_operator (FRAME_CR_CONTEXT (f), CAIRO_OPERATOR_SOURCE);
7139 }
7117} 7140}
7118 7141
7119void 7142void
diff --git a/src/pgtkterm.h b/src/pgtkterm.h
index 42b03e315ef..4d2285cdb0a 100644
--- a/src/pgtkterm.h
+++ b/src/pgtkterm.h
@@ -591,12 +591,9 @@ extern void x_set_z_group (struct frame *f, Lisp_Object new_value,
591extern void pgtk_cr_update_surface_desired_size (struct frame *, int, int, bool); 591extern void pgtk_cr_update_surface_desired_size (struct frame *, int, int, bool);
592extern cairo_t *pgtk_begin_cr_clip (struct frame *f); 592extern cairo_t *pgtk_begin_cr_clip (struct frame *f);
593extern void pgtk_end_cr_clip (struct frame *f); 593extern void pgtk_end_cr_clip (struct frame *f);
594extern void pgtk_set_cr_source_with_gc_foreground (struct frame *f, 594extern void pgtk_set_cr_source_with_gc_foreground (struct frame *, Emacs_GC *, bool);
595 Emacs_GC * gc); 595extern void pgtk_set_cr_source_with_gc_background (struct frame *, Emacs_GC *, bool);
596extern void pgtk_set_cr_source_with_gc_background (struct frame *f, 596extern void pgtk_set_cr_source_with_color (struct frame *, unsigned long, bool);
597 Emacs_GC * gc);
598extern void pgtk_set_cr_source_with_color (struct frame *f,
599 unsigned long color);
600extern void pgtk_cr_draw_frame (cairo_t * cr, struct frame *f); 597extern void pgtk_cr_draw_frame (cairo_t * cr, struct frame *f);
601extern void pgtk_cr_destroy_frame_context (struct frame *f); 598extern void pgtk_cr_destroy_frame_context (struct frame *f);
602extern Lisp_Object pgtk_cr_export_frames (Lisp_Object frames, cairo_surface_type_t surface_type); 599extern Lisp_Object pgtk_cr_export_frames (Lisp_Object frames, cairo_surface_type_t surface_type);