aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPo Lu2022-02-19 20:05:18 +0800
committerPo Lu2022-02-19 20:07:54 +0800
commit88f591f389ba4ac13dd5aebfffa7863805758bcb (patch)
treee14be67c7a2d3f200ee69cb11df18c8cf256f41d /src
parentf687e62ac5dff18a81354e2a29f523c16e3446c3 (diff)
downloademacs-88f591f389ba4ac13dd5aebfffa7863805758bcb.tar.gz
emacs-88f591f389ba4ac13dd5aebfffa7863805758bcb.zip
Improve portability of alpha channel visual detection
* src/xfns.c (select_visual): Look for PictVisuals with an alpha channel instead of blindly assuming that 32 bit visuals have an alpha channel. (Fx_show_tip): Fix crash on some displays where child is None. * src/xterm.c (x_term_init): Initialize Xrender before calling select_visual.
Diffstat (limited to 'src')
-rw-r--r--src/xfns.c52
-rw-r--r--src/xterm.c31
2 files changed, 53 insertions, 30 deletions
diff --git a/src/xfns.c b/src/xfns.c
index 0a8d18d9187..b0e7af9d8fa 100644
--- a/src/xfns.c
+++ b/src/xfns.c
@@ -6574,28 +6574,45 @@ select_visual (struct x_display_info *dpyinfo)
6574 6574
6575 vinfo_template.screen = XScreenNumberOfScreen (screen); 6575 vinfo_template.screen = XScreenNumberOfScreen (screen);
6576 6576
6577#if !defined USE_X_TOOLKIT && !(defined USE_GTK && !defined HAVE_GTK3) 6577#if !defined USE_X_TOOLKIT && !(defined USE_GTK && !defined HAVE_GTK3) \
6578 /* First attempt to use 32-bit visual if available */ 6578 && defined HAVE_XRENDER
6579 6579 int i;
6580 vinfo_template.depth = 32; 6580 XRenderPictFormat *format;
6581 vinfo_template.class = TrueColor;
6582 6581
6583 vinfo = XGetVisualInfo (dpy, (VisualScreenMask 6582 /* First attempt to find a visual with an alpha mask if
6584 | VisualDepthMask 6583 available. That information is only available when the
6585 | VisualClassMask), 6584 render extension is present, and we cannot do much with such
6586 &vinfo_template, &n_visuals); 6585 a visual if it isn't. */
6587 6586
6588 if (n_visuals > 0 && vinfo) 6587 if (dpyinfo->xrender_supported_p)
6589 { 6588 {
6590 dpyinfo->n_planes = vinfo->depth;
6591 dpyinfo->visual = vinfo->visual;
6592 XFree (vinfo);
6593 return;
6594 }
6595 6589
6590 vinfo = XGetVisualInfo (dpy, VisualScreenMask,
6591 &vinfo_template, &n_visuals);
6592
6593 for (i = 0; i < n_visuals; ++i)
6594 {
6595 format = XRenderFindVisualFormat (dpy, vinfo[i].visual);
6596
6597 if (format && format->type == PictTypeDirect
6598 && format->direct.alphaMask)
6599 {
6600 dpyinfo->n_planes = vinfo[i].depth;
6601 dpyinfo->visual = vinfo[i].visual;
6602 dpyinfo->pict_format = format;
6603
6604 XFree (vinfo);
6605 return;
6606 }
6607 }
6608
6609 if (vinfo)
6610 XFree (vinfo);
6611 }
6596#endif /* !USE_X_TOOLKIT */ 6612#endif /* !USE_X_TOOLKIT */
6597 6613
6598 /* 32-bit visual not available, fallback to default visual */ 6614 /* Visual with alpha channel (or the Render extension) not
6615 available, fallback to default visual. */
6599 dpyinfo->visual = DefaultVisualOfScreen (screen); 6616 dpyinfo->visual = DefaultVisualOfScreen (screen);
6600 vinfo_template.visualid = XVisualIDFromVisual (dpyinfo->visual); 6617 vinfo_template.visualid = XVisualIDFromVisual (dpyinfo->visual);
6601 vinfo = XGetVisualInfo (dpy, VisualIDMask | VisualScreenMask, 6618 vinfo = XGetVisualInfo (dpy, VisualIDMask | VisualScreenMask,
@@ -8091,7 +8108,8 @@ Text larger than the specified size is clipped. */)
8091 FRAME_DISPLAY_INFO (f)->root_window, 8108 FRAME_DISPLAY_INFO (f)->root_window,
8092 FRAME_DISPLAY_INFO (f)->root_window, 8109 FRAME_DISPLAY_INFO (f)->root_window,
8093 root_x, root_y, &dest_x_return, 8110 root_x, root_y, &dest_x_return,
8094 &dest_y_return, &child)) 8111 &dest_y_return, &child)
8112 && child != None)
8095 { 8113 {
8096 /* But only if the child is not override-redirect, which can 8114 /* But only if the child is not override-redirect, which can
8097 happen if the pointer is above a menu. */ 8115 happen if the pointer is above a menu. */
diff --git a/src/xterm.c b/src/xterm.c
index 2dc420a8dee..e2ad0b48f58 100644
--- a/src/xterm.c
+++ b/src/xterm.c
@@ -15989,6 +15989,18 @@ x_term_init (Lisp_Object display_name, char *xrm_option, char *resource_name)
15989#else 15989#else
15990 dpyinfo->display->db = xrdb; 15990 dpyinfo->display->db = xrdb;
15991#endif 15991#endif
15992
15993#ifdef HAVE_XRENDER
15994 int event_base, error_base;
15995 dpyinfo->xrender_supported_p
15996 = XRenderQueryExtension (dpyinfo->display, &event_base, &error_base);
15997
15998 if (dpyinfo->xrender_supported_p)
15999 dpyinfo->xrender_supported_p
16000 = XRenderQueryVersion (dpyinfo->display, &dpyinfo->xrender_major,
16001 &dpyinfo->xrender_minor);
16002#endif
16003
15992 /* Put the rdb where we can find it in a way that works on 16004 /* Put the rdb where we can find it in a way that works on
15993 all versions. */ 16005 all versions. */
15994 dpyinfo->rdb = xrdb; 16006 dpyinfo->rdb = xrdb;
@@ -16004,19 +16016,12 @@ x_term_init (Lisp_Object display_name, char *xrm_option, char *resource_name)
16004 reset_mouse_highlight (&dpyinfo->mouse_highlight); 16016 reset_mouse_highlight (&dpyinfo->mouse_highlight);
16005 16017
16006#ifdef HAVE_XRENDER 16018#ifdef HAVE_XRENDER
16007 int event_base, error_base; 16019 if (dpyinfo->xrender_supported_p
16008 dpyinfo->xrender_supported_p 16020 /* This could already have been initialized by
16009 = XRenderQueryExtension (dpyinfo->display, &event_base, &error_base); 16021 `select_visual'. */
16010 16022 && !dpyinfo->pict_format)
16011 if (dpyinfo->xrender_supported_p) 16023 dpyinfo->pict_format = XRenderFindVisualFormat (dpyinfo->display,
16012 { 16024 dpyinfo->visual);
16013 if (!XRenderQueryVersion (dpyinfo->display, &dpyinfo->xrender_major,
16014 &dpyinfo->xrender_minor))
16015 dpyinfo->xrender_supported_p = false;
16016 else
16017 dpyinfo->pict_format = XRenderFindVisualFormat (dpyinfo->display,
16018 dpyinfo->visual);
16019 }
16020#endif 16025#endif
16021 16026
16022#ifdef HAVE_XSYNC 16027#ifdef HAVE_XSYNC