x11: Add function to know whether a client X11 window has an alpha channel

Since the windows created by the frames client will have a RGBA visual, we
no longer can perform simple tests about whether the window is opaque. For
that, we will need to additionally know whether the client-side window has
a visual with an alpha channel.

Reviewed-by: Michel Dänzer <mdaenzer@redhat.com>
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2758>
This commit is contained in:
Carlos Garnacho 2022-12-13 13:41:22 +01:00
parent 1f51dfa112
commit 07e1f87e3b
2 changed files with 29 additions and 0 deletions

View File

@ -4331,3 +4331,30 @@ meta_window_x11_check_update_resize (MetaWindow *window)
window->display->grab_latest_motion_x, window->display->grab_latest_motion_x,
window->display->grab_latest_motion_y); window->display->grab_latest_motion_y);
} }
gboolean
meta_window_x11_has_alpha_channel (MetaWindow *window)
{
MetaX11Display *x11_display = window->display->x11_display;
int n_xvisuals;
gboolean has_alpha;
XVisualInfo *xvisual_info;
XVisualInfo template = {
.visualid = XVisualIDFromVisual (window->xvisual),
};
xvisual_info = XGetVisualInfo (meta_x11_display_get_xdisplay (x11_display),
VisualIDMask,
&template,
&n_xvisuals);
if (!xvisual_info)
return FALSE;
has_alpha = (xvisual_info->depth >
__builtin_popcount (xvisual_info->red_mask |
xvisual_info->green_mask |
xvisual_info->blue_mask));
XFree (xvisual_info);
return has_alpha;
}

View File

@ -107,4 +107,6 @@ gboolean meta_window_x11_is_awaiting_sync_response (MetaWindow *window);
void meta_window_x11_check_update_resize (MetaWindow *window); void meta_window_x11_check_update_resize (MetaWindow *window);
gboolean meta_window_x11_has_alpha_channel (MetaWindow *window);
#endif #endif