From 8eda2dc6e83d151deec05aab1957141b45bde050 Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Mon, 21 Mar 2022 16:48:49 -0400 Subject: [PATCH] Set display depths based on the actual screen color space. Fixes #10. --- xlib/Color.cpp | 17 +++++++++++++++++ xlib/Color.h | 1 + xlib/Display.cpp | 4 ++-- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/xlib/Color.cpp b/xlib/Color.cpp index 3b7fa45..4568d22 100644 --- a/xlib/Color.cpp +++ b/xlib/Color.cpp @@ -39,6 +39,23 @@ _x_color_space_for(Visual* v, int bits_per_pixel) } } +int +_x_depth_for_color_space(color_space space) +{ + switch (space) { + case B_GRAY1: return 1; + case B_GRAY8: return 8; + case B_RGB15: return 15; + case B_RGB16: return 16; + case B_RGB24: return 24; + case B_RGB32: return 32; + case B_RGBA32: return 32; + default: + debugger("Unsupported color space!"); + return 24; + } +} + static int FindColor(const char *name, XColor *def) { diff --git a/xlib/Color.h b/xlib/Color.h index 823af06..d85bb8a 100644 --- a/xlib/Color.h +++ b/xlib/Color.h @@ -38,3 +38,4 @@ _x_pixel_to_rgb(unsigned long color, bool alpha = false) } color_space _x_color_space_for(Visual* v, int bits_per_pixel); +int _x_depth_for_color_space(color_space space); diff --git a/xlib/Display.cpp b/xlib/Display.cpp index 021739a..e6b20bd 100644 --- a/xlib/Display.cpp +++ b/xlib/Display.cpp @@ -101,14 +101,14 @@ set_display(Display* dpy) memset(slist, 0, sizeof(Screen)); - dlist[0].depth = 24; + dlist[0].depth = _x_depth_for_color_space(screen.ColorSpace()); dlist[0].nvisuals = 1; dlist[0].visuals = vlist; vlist[0].ext_data = NULL; vlist[0].visualid = 0; vlist[0].c_class = TrueColor; - vlist[0].bits_per_rgb = 24; + vlist[0].bits_per_rgb = dlist[0].depth; vlist[0].map_entries = 256; _x_get_rgb_masks(&vlist[0]);