move some common color code to a function
This commit is contained in:
		
							parent
							
								
									5f9a4026e5
								
							
						
					
					
						commit
						94f52426d4
					
				
							
								
								
									
										41
									
								
								termite.c
									
									
									
									
									
								
							
							
						
						
									
										41
									
								
								termite.c
									
									
									
									
									
								
							@ -286,6 +286,20 @@ MAKE_GET_CONFIG_FUNCTION(integer, int)
 | 
				
			|||||||
MAKE_GET_CONFIG_FUNCTION(string, char *)
 | 
					MAKE_GET_CONFIG_FUNCTION(string, char *)
 | 
				
			||||||
MAKE_GET_CONFIG_FUNCTION(double, double)
 | 
					MAKE_GET_CONFIG_FUNCTION(double, double)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static bool get_config_color(GKeyFile *config, const char *key, GdkColor *color) {
 | 
				
			||||||
 | 
					    char *cfgstr;
 | 
				
			||||||
 | 
					    bool success = false;
 | 
				
			||||||
 | 
					    if (get_config_string(config, "colors", key, &cfgstr)) {
 | 
				
			||||||
 | 
					        if (gdk_color_parse(cfgstr, color)) {
 | 
				
			||||||
 | 
					            success = true;
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
 | 
					            g_printerr("invalid color string: %s\n", cfgstr);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        g_free(cfgstr);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    return success;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void load_config(GtkWindow *window, VteTerminal *vte,
 | 
					static void load_config(GtkWindow *window, VteTerminal *vte,
 | 
				
			||||||
                        gboolean *dynamic_title, gboolean *urgent_on_bell,
 | 
					                        gboolean *dynamic_title, gboolean *urgent_on_bell,
 | 
				
			||||||
                        gboolean *clickable_url, const char **term) {
 | 
					                        gboolean *clickable_url, const char **term) {
 | 
				
			||||||
@ -415,31 +429,16 @@ static void load_config(GtkWindow *window, VteTerminal *vte,
 | 
				
			|||||||
            vte_terminal_set_colors(vte, NULL, NULL, palette, 16);
 | 
					            vte_terminal_set_colors(vte, NULL, NULL, palette, 16);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (get_config_string(config, "colors", "foreground", &cfgstr)) {
 | 
					        if (get_config_color(config, "foreground", &color)) {
 | 
				
			||||||
            if (gdk_color_parse(cfgstr, &color)) {
 | 
					            vte_terminal_set_color_foreground(vte, &color);
 | 
				
			||||||
                vte_terminal_set_color_foreground(vte, &color);
 | 
					 | 
				
			||||||
            } else {
 | 
					 | 
				
			||||||
                g_printerr("invalid color string: %s\n", cfgstr);
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            g_free(cfgstr);
 | 
					 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (get_config_string(config, "colors", "background", &cfgstr)) {
 | 
					        if (get_config_color(config, "background", &color)) {
 | 
				
			||||||
            if (gdk_color_parse(cfgstr, &color)) {
 | 
					            vte_terminal_set_color_background(vte, &color);
 | 
				
			||||||
                vte_terminal_set_color_background(vte, &color);
 | 
					 | 
				
			||||||
            } else {
 | 
					 | 
				
			||||||
                g_printerr("invalid color string: %s\n", cfgstr);
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            g_free(cfgstr);
 | 
					 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (get_config_string(config, "colors", "cursor", &cfgstr)) {
 | 
					        if (get_config_color(config, "cursor", &color)) {
 | 
				
			||||||
            if (gdk_color_parse(cfgstr, &color)) {
 | 
					            vte_terminal_set_color_cursor(vte, &color);
 | 
				
			||||||
                vte_terminal_set_color_cursor(vte, &color);
 | 
					 | 
				
			||||||
            } else {
 | 
					 | 
				
			||||||
                g_printerr("invalid color string: %s\n", cfgstr);
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            g_free(cfgstr);
 | 
					 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    g_free(path);
 | 
					    g_free(path);
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user