1
0
Fork 0

Create X11 windows with a depth of 32-bits

This should fix the inability to create OpenGL contexts with alpha
channels in raw-gl-context, but it seems like that still needs a bit
more work.
This commit is contained in:
Robbert van der Helm 2022-02-07 13:13:28 +01:00
parent a8010016fb
commit 625fde7957

View file

@ -205,10 +205,39 @@ impl Window {
let window_info = WindowInfo::from_logical_size(options.size, scaling);
// The window need to have a depth of 32 so so we can create graphics contexts with alpha
// buffers
let mut depth = xcb::COPY_FROM_PARENT as u8;
let mut visual = xcb::COPY_FROM_PARENT as u32;
'match_visual: for candidate_depth in screen.allowed_depths() {
if candidate_depth.depth() != 32 {
continue;
}
for candidate_visual in candidate_depth.visuals() {
if candidate_visual.class() == xcb::VISUAL_CLASS_TRUE_COLOR as u8 {
depth = candidate_depth.depth();
visual = candidate_visual.visual_id();
break 'match_visual;
}
}
}
// For this 32-bith depth to work, you also need to define a color map and set a border
// pixel: https://cgit.freedesktop.org/xorg/xserver/tree/dix/window.c#n818
let colormap = xcb_connection.conn.generate_id();
xcb::create_colormap(
&xcb_connection.conn,
xcb::COLORMAP_ALLOC_NONE as u8,
colormap,
screen.root(),
visual,
);
let window_id = xcb_connection.conn.generate_id();
xcb::create_window_checked(
&xcb_connection.conn,
xcb::COPY_FROM_PARENT as u8,
depth,
window_id,
parent_id,
0, // x coordinate of the new window
@ -217,8 +246,9 @@ impl Window {
window_info.physical_size().height as u16, // window height
0, // window border
xcb::WINDOW_CLASS_INPUT_OUTPUT as u16,
if parent.is_some() { xcb::COPY_FROM_PARENT as u32 } else { screen.root_visual() },
&[(
visual,
&[
(
xcb::CW_EVENT_MASK,
xcb::EVENT_MASK_EXPOSURE
| xcb::EVENT_MASK_POINTER_MOTION
@ -227,8 +257,15 @@ impl Window {
| xcb::EVENT_MASK_KEY_PRESS
| xcb::EVENT_MASK_KEY_RELEASE
| xcb::EVENT_MASK_STRUCTURE_NOTIFY,
)],
).request_check().unwrap();
),
// As mentioend above, these two values are needed to be able to create a window
// with a dpeth of 32-bits when the parent window has a different depth
(xcb::CW_COLORMAP, colormap),
(xcb::CW_BORDER_PIXEL, 0),
],
)
.request_check()
.unwrap();
xcb::map_window(&xcb_connection.conn, window_id);