@@ -12,15 +12,15 @@ pub(super) struct WindowVisualConfig {
1212
1313 pub visual_depth : u8 ,
1414 pub visual_id : Visualid ,
15- pub is_copy_from_parent : bool ,
15+ pub color_map : Option < Colormap > ,
1616}
1717
1818// TODO: make visual negotiation actually check all of a visual's parameters
1919impl WindowVisualConfig {
2020 #[ cfg( feature = "opengl" ) ]
2121 pub fn find_best_visual_config_for_gl (
2222 connection : & XcbConnection , gl_config : Option < crate :: gl:: GlConfig > ,
23- ) -> Self {
23+ ) -> Result < Self , Box < dyn Error > > {
2424 let Some ( gl_config) = gl_config else { return Self :: find_best_visual_config ( connection) } ;
2525
2626 // SAFETY: TODO
@@ -29,24 +29,24 @@ impl WindowVisualConfig {
2929 }
3030 . expect ( "Could not fetch framebuffer config" ) ;
3131
32- Self {
32+ Ok ( Self {
3333 fb_config : Some ( fb_config) ,
3434 visual_depth : window_config. depth ,
3535 visual_id : window_config. visual ,
36- is_copy_from_parent : false ,
37- }
36+ color_map : Some ( create_color_map ( connection , window_config . visual ) ? ) ,
37+ } )
3838 }
3939
40- pub fn find_best_visual_config ( connection : & XcbConnection ) -> Self {
40+ pub fn find_best_visual_config ( connection : & XcbConnection ) -> Result < Self , Box < dyn Error > > {
4141 match find_visual_for_depth ( connection. screen ( ) , 32 ) {
42- None => Self :: copy_from_parent ( ) ,
43- Some ( visual_id) => Self {
42+ None => Ok ( Self :: copy_from_parent ( ) ) ,
43+ Some ( visual_id) => Ok ( Self {
4444 #[ cfg( feature = "opengl" ) ]
4545 fb_config : None ,
4646 visual_id,
4747 visual_depth : 32 ,
48- is_copy_from_parent : false ,
49- } ,
48+ color_map : Some ( create_color_map ( connection , visual_id ) ? ) ,
49+ } ) ,
5050 }
5151 }
5252
@@ -56,29 +56,25 @@ impl WindowVisualConfig {
5656 fb_config : None ,
5757 visual_depth : COPY_FROM_PARENT as u8 ,
5858 visual_id : COPY_FROM_PARENT ,
59- is_copy_from_parent : true ,
59+ color_map : None ,
6060 }
6161 }
62+ }
6263
63- // For this 32-bit depth to work, you also need to define a color map and set a border
64- // pixel: https://cgit.freedesktop.org/xorg/xserver/tree/dix/window.c#n818
65- pub fn create_color_map (
66- & self , connection : & XcbConnection ,
67- ) -> Result < Option < Colormap > , Box < dyn Error > > {
68- if self . is_copy_from_parent {
69- return Ok ( None ) ;
70- }
71-
72- let colormap = connection. conn2 . generate_id ( ) ?;
73- connection. conn2 . create_colormap (
74- ColormapAlloc :: NONE ,
75- colormap,
76- connection. screen ( ) . root ,
77- self . visual_id ,
78- ) ?;
64+ // For this 32-bit depth to work, you also need to define a color map and set a border
65+ // pixel: https://cgit.freedesktop.org/xorg/xserver/tree/dix/window.c#n818
66+ pub fn create_color_map (
67+ connection : & XcbConnection , visual_id : Visualid ,
68+ ) -> Result < Colormap , Box < dyn Error > > {
69+ let colormap = connection. conn2 . generate_id ( ) ?;
70+ connection. conn2 . create_colormap (
71+ ColormapAlloc :: NONE ,
72+ colormap,
73+ connection. screen ( ) . root ,
74+ visual_id,
75+ ) ?;
7976
80- Ok ( Some ( colormap) )
81- }
77+ Ok ( colormap)
8278}
8379
8480fn find_visual_for_depth ( screen : & Screen , depth : u8 ) -> Option < Visualid > {
0 commit comments