@@ -90,7 +90,12 @@ impl GridWM {
9090 } ) ;
9191 let config = Config :: from_file ( & config_path) ?;
9292
93- let ( background_gc, bar_gc) = match create_bar_gc ( display, & config) {
93+ let ( background_gc, bar_gc) = match create_gc (
94+ display,
95+ config. bar . background_color . clone ( ) ,
96+ config. bar . text_color . clone ( ) ,
97+ "bar" ,
98+ ) {
9499 Some ( dat) => dat,
95100 None => {
96101 error ! ( "failed to create bar and background gc. exiting." ) ;
@@ -1133,31 +1138,36 @@ impl GridWM {
11331138 }
11341139}
11351140
1136- // returns (background_gc, bar_gc )
1137- fn create_bar_gc (
1141+ // returns (background_gc, content_gc )
1142+ fn create_gc (
11381143 display : * mut x11:: xlib:: _XDisplay ,
1139- config : & Config ,
1144+ background_hex : String ,
1145+ content_hex : String ,
1146+ target : & str ,
11401147) -> Option < ( xlib:: GC , xlib:: GC ) > {
11411148 unsafe {
11421149 let root = XDefaultRootWindow ( display) ;
11431150 let screen = XDefaultScreen ( display) ;
1144- let mut bar_color : XColor = std:: mem:: zeroed ( ) ;
1151+ let mut content_color : XColor = std:: mem:: zeroed ( ) ;
11451152 let mut background_color: XColor = std:: mem:: zeroed ( ) ;
11461153
1147- let bar_hex_str = match CString :: new ( config . bar . text_color . clone ( ) ) {
1154+ let content_hex_str = match CString :: new ( content_hex ) {
11481155 Ok ( hex_str) => hex_str,
11491156 Err ( e) => {
1150- error ! ( "failed to convert bar text color str to cstring: {}" , e) ;
1157+ error ! (
1158+ "failed to convert {} text color str to cstring: {}" ,
1159+ target, e
1160+ ) ;
11511161 return None ;
11521162 }
11531163 } ;
11541164
1155- let background_hex_str = match CString :: new ( config . bar . background_color . clone ( ) ) {
1165+ let background_hex_str = match CString :: new ( background_hex ) {
11561166 Ok ( hex_str) => hex_str,
11571167 Err ( e) => {
11581168 error ! (
1159- "failed to convert bar background color str to cstring: {}" ,
1160- e
1169+ "failed to convert {} background color str to cstring: {}" ,
1170+ target , e
11611171 ) ;
11621172 return None ;
11631173 }
@@ -1166,11 +1176,11 @@ fn create_bar_gc(
11661176 if XParseColor (
11671177 display,
11681178 XDefaultColormap ( display, screen) ,
1169- bar_hex_str . as_ptr ( ) ,
1170- & mut bar_color ,
1179+ content_hex_str . as_ptr ( ) ,
1180+ & mut content_color ,
11711181 ) != 1
11721182 {
1173- error ! ( "failed to parse bar text color" ) ;
1183+ error ! ( "failed to parse {} text color" , target ) ;
11741184 }
11751185
11761186 if XParseColor (
@@ -1180,19 +1190,23 @@ fn create_bar_gc(
11801190 & mut background_color,
11811191 ) != 1
11821192 {
1183- error ! ( "failed to parse bar background color" ) ;
1193+ error ! ( "failed to parse {} background color" , target ) ;
11841194 }
11851195
1186- XAllocColor ( display, XDefaultColormap ( display, screen) , & mut bar_color) ;
1196+ XAllocColor (
1197+ display,
1198+ XDefaultColormap ( display, screen) ,
1199+ & mut content_color,
1200+ ) ;
11871201
11881202 XAllocColor (
11891203 display,
11901204 XDefaultColormap ( display, screen) ,
11911205 & mut background_color,
11921206 ) ;
11931207
1194- let bar_gcv = XGCValues {
1195- foreground : bar_color . pixel ,
1208+ let content_gcv = XGCValues {
1209+ foreground : content_color . pixel ,
11961210 background : 0 ,
11971211 font : 0 ,
11981212 ..std:: mem:: zeroed ( )
@@ -1205,11 +1219,11 @@ fn create_bar_gc(
12051219 ..std:: mem:: zeroed ( )
12061220 } ;
12071221
1208- let bar_gc = xlib:: XCreateGC (
1222+ let content_gc = xlib:: XCreateGC (
12091223 display,
12101224 root,
12111225 GCForeground as u64 ,
1212- & bar_gcv as * const _ as * mut _ ,
1226+ & content_gcv as * const _ as * mut _ ,
12131227 ) ;
12141228
12151229 let background_gc = xlib:: XCreateGC (
@@ -1219,7 +1233,7 @@ fn create_bar_gc(
12191233 & background_gcv as * const _ as * mut _ ,
12201234 ) ;
12211235
1222- Some ( ( background_gc, bar_gc ) )
1236+ Some ( ( background_gc, content_gc ) )
12231237 }
12241238}
12251239
0 commit comments