X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~mdw/git/disorder/blobdiff_plain/81cd18944f4b070511dd041902dc2c723a2669c4..33288048f694a84b9c40653f0b72b4ce44a94ab1:/disobedience/settings.c diff --git a/disobedience/settings.c b/disobedience/settings.c index 75f7396..a5ea53f 100644 --- a/disobedience/settings.c +++ b/disobedience/settings.c @@ -34,88 +34,12 @@ #include "split.h" #include -/** @brief Background colors for tools - menus, icons, etc. */ -GdkColor tool_bg = { 0, 0xDC00, 0xDA00, 0xD500 }; - -/** @brief Background color for active tool */ -GdkColor tool_active; - -/** @brief Foreground colors for tools */ -GdkColor tool_fg = { 0, 0x0000, 0x0000, 0x0000 }; - -/** @brief Foreground colors for inactive tools */ -GdkColor inactive_tool_fg = { 0, 0x8000, 0x8000, 0x8000 }; - -/** @brief Background color for the various layouts */ -GdkColor layout_bg = { 0, 0xFFFF, 0xFFFF, 0xFFFF }; - -/** @brief Title-row background color */ -GdkColor title_bg = { 0, 0x0000, 0x0000, 0x0000 }; - -/** @brief Title-row foreground color */ -GdkColor title_fg = { 0, 0xFFFF, 0xFFFF, 0xFFFF }; - -/** @brief Even-row background color */ -GdkColor even_bg = { 0, 0xFFFF, 0xEC00, 0xEBFF }; - -/** @brief Odd-row background color */ -GdkColor odd_bg = { 0, 0xFFFF, 0xFFFF, 0xFFFF }; - -/** @brief Active-row background color */ -GdkColor active_bg = { 0, 0xE000, 0xFFFF, 0xE000 }; - -/** @brief Item foreground color */ -GdkColor item_fg = { 0, 0x0000, 0x0000, 0x0000 }; - -/** @brief Selected background color */ -GdkColor selected_bg = { 0, 0x4B00, 0x6900, 0x8300 }; - -/** @brief Selected foreground color */ -GdkColor selected_fg = { 0, 0xFFFF, 0xFFFF, 0xFFFF }; - -/** @brief Search results */ -GdkColor search_bg = { 0, 0xFFFF, 0xFFFF, 0x0000 }; - -/** @brief Drag target color */ -GdkColor drag_target = { 0, 0x6666, 0x6666, 0x6666 }; - /** @brief HTML displayer */ const char *browser = BROWSER; -struct colordesc { - GdkColor *color; - const char *name; - const char *description; -}; - -#define COLOR(name, description) { &name, #name, description } - -/** @brief Table of configurable colors - * - * Some of the descriptions could be improve! - */ -static const struct colordesc colors[] = { - COLOR(tool_bg, "Tool background color"), - COLOR(tool_fg, "Tool foreground color"), - COLOR(layout_bg, "Layout background color"), - COLOR(title_bg, "Title row background color"), - COLOR(title_fg, "Title row foreground color"), - COLOR(even_bg, "Even row background color"), - COLOR(odd_bg, "Odd row background color"), - COLOR(active_bg, "Playing row background color"), - COLOR(item_fg, "Track foreground color"), - COLOR(selected_bg, "Selected item background color"), - COLOR(selected_fg, "Selected item foreground color"), - COLOR(search_bg, "Search result background color"), - COLOR(drag_target, "Drag target color"), -}; - -#define NCOLORS (sizeof colors / sizeof *colors) - void save_settings(void) { char *dir, *path, *tmp; FILE *fp = 0; - size_t n; byte_xasprintf(&dir, "%s/.disorder", getenv("HOME")); byte_xasprintf(&path, "%s/disobedience", dir); @@ -126,15 +50,7 @@ void save_settings(void) { tmp, strerror(errno)); goto done; } - for(n = 0; n < NCOLORS; ++n) - if(fprintf(fp, "color %-20s 0x%04X 0x%04X 0x%04X\n", colors[n].name, - colors[n].color->red, - colors[n].color->green, - colors[n].color->blue) < 0) { - fpopup_msg(GTK_MESSAGE_ERROR, "error writing to %s: %s", - tmp, strerror(errno)); - goto done; - } + /* TODO */ if(fclose(fp) < 0) { fpopup_msg(GTK_MESSAGE_ERROR, "error writing to %s: %s", tmp, strerror(errno)); @@ -157,7 +73,6 @@ static inline unsigned clamp(unsigned n) { void load_settings(void) { char *path, *line; FILE *fp; - size_t n; char **vec; int nvec; @@ -176,15 +91,7 @@ void load_settings(void) { error(0, "%s: malformed '%s' command", path, vec[0]); continue; } - for(n = 0; n < NCOLORS && strcmp(colors[n].name, vec[1]); ++n) - ; - if(n >= NCOLORS) { - error(0, "%s: unknown color '%s'", path, vec[1]); - continue; - } - colors[n].color->red = strtoul(vec[2], 0, 0); - colors[n].color->green = strtoul(vec[3], 0, 0); - colors[n].color->blue = strtoul(vec[4], 0, 0); + /* TODO */ } else /* mention errors but otherwise ignore them */ error(0, "%s: unknown command '%s'", path, vec[0]); @@ -195,10 +102,6 @@ void load_settings(void) { fclose(fp); } } - tool_active = tool_bg; - tool_active.red = clamp(105 * tool_active.red / 100); - tool_active.green = clamp(105 * tool_active.green / 100); - tool_active.blue = clamp(105 * tool_active.blue / 100); } /** @brief Callback used by set_tool_colors() */ @@ -211,14 +114,7 @@ static void set_tool_colors_callback(GtkWidget *w, void set_tool_colors(GtkWidget *w) { GtkWidget *child; - gtk_widget_modify_bg(w, GTK_STATE_NORMAL, &tool_bg); - gtk_widget_modify_bg(w, GTK_STATE_SELECTED, &selected_bg); - gtk_widget_modify_bg(w, GTK_STATE_PRELIGHT, &selected_bg); - gtk_widget_modify_bg(w, GTK_STATE_INSENSITIVE, &tool_bg); - gtk_widget_modify_fg(w, GTK_STATE_NORMAL, &tool_fg); - gtk_widget_modify_fg(w, GTK_STATE_SELECTED, &selected_fg); - gtk_widget_modify_fg(w, GTK_STATE_PRELIGHT, &selected_fg); - gtk_widget_modify_fg(w, GTK_STATE_INSENSITIVE, &inactive_tool_fg); + gtk_widget_set_style(w, tool_style); if(GTK_IS_CONTAINER(w)) gtk_container_foreach(GTK_CONTAINER(w), set_tool_colors_callback, 0); if(GTK_IS_MENU_ITEM(w) @@ -226,18 +122,79 @@ void set_tool_colors(GtkWidget *w) { set_tool_colors(child); } -/** @brief Set the colors for a slider */ -void set_slider_colors(GtkWidget *w) { - if(!w) - return; - gtk_widget_modify_bg(w, GTK_STATE_NORMAL, &tool_bg); - gtk_widget_modify_bg(w, GTK_STATE_ACTIVE, &tool_bg); - gtk_widget_modify_bg(w, GTK_STATE_SELECTED, &tool_active); - gtk_widget_modify_bg(w, GTK_STATE_PRELIGHT, &tool_active); - gtk_widget_modify_fg(w, GTK_STATE_NORMAL, &tool_fg); - gtk_widget_modify_fg(w, GTK_STATE_ACTIVE, &tool_fg); - gtk_widget_modify_fg(w, GTK_STATE_SELECTED, &tool_fg); - gtk_widget_modify_fg(w, GTK_STATE_PRELIGHT, &tool_fg); +/** @brief Default style for layouts */ +GtkStyle *layout_style; + +/** @brief Title-row style for layouts */ +GtkStyle *title_style; + +/** @brief Even-row style for layouts */ +GtkStyle *even_style; + +/** @brief Odd-row style for layouts */ +GtkStyle *odd_style; + +/** @brief Active-row style for layouts */ +GtkStyle *active_style; + +/** @brief Style for tools */ +GtkStyle *tool_style; + +/** @brief Style for search results */ +GtkStyle *search_style; + +/** @brief Style for drag targets */ +GtkStyle *drag_style; + +/** @brief Initialize styles */ +void init_styles(void) { + layout_style = gtk_style_new(); + title_style = gtk_style_new(); + even_style = gtk_style_new(); + odd_style = gtk_style_new(); + active_style = gtk_style_new(); + search_style = gtk_style_new(); + tool_style = gtk_style_new(); + drag_style = gtk_style_new(); + + /* Style defaults */ + + /* Layouts are basically black on white */ + layout_style->bg[GTK_STATE_NORMAL] = layout_style->white; + layout_style->fg[GTK_STATE_NORMAL] = layout_style->black; + + /* Title row is inverted */ + title_style->bg[GTK_STATE_NORMAL] = layout_style->fg[GTK_STATE_NORMAL]; + title_style->fg[GTK_STATE_NORMAL] = layout_style->bg[GTK_STATE_NORMAL]; + + /* Active row is pastel green */ + active_style->bg[GTK_STATE_NORMAL].red = 0xE000; + active_style->bg[GTK_STATE_NORMAL].green = 0xFFFF; + active_style->bg[GTK_STATE_NORMAL].blue = 0xE000; + active_style->fg[GTK_STATE_NORMAL] = layout_style->fg[GTK_STATE_NORMAL]; + + /* Even rows are pastel red */ + even_style->bg[GTK_STATE_NORMAL].red = 0xFFFF; + even_style->bg[GTK_STATE_NORMAL].green = 0xEC00; + even_style->bg[GTK_STATE_NORMAL].blue = 0xEC00; + even_style->fg[GTK_STATE_NORMAL] = layout_style->fg[GTK_STATE_NORMAL]; + + /* Odd rows match the underlying layout */ + odd_style->bg[GTK_STATE_NORMAL] = layout_style->bg[GTK_STATE_NORMAL]; + odd_style->fg[GTK_STATE_NORMAL] = layout_style->fg[GTK_STATE_NORMAL]; + + /* Search results have a yellow background */ + search_style->fg[GTK_STATE_NORMAL] = layout_style->fg[GTK_STATE_NORMAL]; + search_style->bg[GTK_STATE_NORMAL].red = 0xFFFF; + search_style->bg[GTK_STATE_NORMAL].green = 0xFFFF; + search_style->bg[GTK_STATE_NORMAL].blue = 0x0000; + + /* Drag targets are grey */ + drag_style->bg[GTK_STATE_NORMAL].red = 0x6666; + drag_style->bg[GTK_STATE_NORMAL].green = 0x6666; + drag_style->bg[GTK_STATE_NORMAL].blue = 0x6666; + + /* Tools we leave at GTK+ defaults */ } /*