2 * This file is part of Disobedience
3 * Copyright (C) 2007 Richard Kettlewell
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 /** @file disobedience/appearance.c
21 * @brief Visual appearance of Disobedience
23 * Originally I attempted to use a built-in rc file to configure
24 * Disobedience's colors. This is quite convenient but fails in the
25 * face of themes, as the theme settings override the application
28 * This file therefore collects all the colors of the Disobedience UI
29 * and (in time) will have a configuration dialog too.
32 #include "disobedience.h"
33 #include "inputline.h"
37 /** @brief Background colors for tools - menus, icons, etc. */
38 GdkColor tool_bg
= { 0, 0xDC00, 0xDA00, 0xD500 };
40 /** @brief Background color for active tool */
43 /** @brief Foreground colors for tools */
44 GdkColor tool_fg
= { 0, 0x0000, 0x0000, 0x0000 };
46 /** @brief Foreground colors for inactive tools */
47 GdkColor inactive_tool_fg
= { 0, 0x8000, 0x8000, 0x8000 };
49 /** @brief Background color for the various layouts */
50 GdkColor layout_bg
= { 0, 0xFFFF, 0xFFFF, 0xFFFF };
52 /** @brief Title-row background color */
53 GdkColor title_bg
= { 0, 0x0000, 0x0000, 0x0000 };
55 /** @brief Title-row foreground color */
56 GdkColor title_fg
= { 0, 0xFFFF, 0xFFFF, 0xFFFF };
58 /** @brief Even-row background color */
59 GdkColor even_bg
= { 0, 0xFFFF, 0xEC00, 0xEBFF };
61 /** @brief Odd-row background color */
62 GdkColor odd_bg
= { 0, 0xFFFF, 0xFFFF, 0xFFFF };
64 /** @brief Active-row background color */
65 GdkColor active_bg
= { 0, 0xE000, 0xFFFF, 0xE000 };
67 /** @brief Item foreground color */
68 GdkColor item_fg
= { 0, 0x0000, 0x0000, 0x0000 };
70 /** @brief Selected background color */
71 GdkColor selected_bg
= { 0, 0x4B00, 0x6900, 0x8300 };
73 /** @brief Selected foreground color */
74 GdkColor selected_fg
= { 0, 0xFFFF, 0xFFFF, 0xFFFF };
76 /** @brief Search results */
77 GdkColor search_bg
= { 0, 0xFFFF, 0xFFFF, 0x0000 };
79 /** @brief Drag target color */
80 GdkColor drag_target
= { 0, 0x6666, 0x6666, 0x6666 };
85 const char *description
;
88 #define COLOR(name, description) { &name, #name, description }
90 /** @brief Table of configurable colors
92 * Some of the descriptions could be improve!
94 static const struct colordesc colors
[] = {
95 COLOR(tool_bg
, "Tool background color"),
96 COLOR(tool_fg
, "Tool foreground color"),
97 COLOR(layout_bg
, "Layout background color"),
98 COLOR(title_bg
, "Title row background color"),
99 COLOR(title_fg
, "Title row foreground color"),
100 COLOR(even_bg
, "Even row background color"),
101 COLOR(odd_bg
, "Odd row background color"),
102 COLOR(active_bg
, "Playing row background color"),
103 COLOR(item_fg
, "Track foreground color"),
104 COLOR(selected_bg
, "Selected item background color"),
105 COLOR(selected_fg
, "Selected item foreground color"),
106 COLOR(search_bg
, "Search result background color"),
107 COLOR(drag_target
, "Drag target color"),
110 #define NCOLORS (sizeof colors / sizeof *colors)
112 void save_appearance(void) {
113 char *dir
, *path
, *tmp
;
117 byte_xasprintf(&dir
, "%s/.disorder", getenv("HOME"));
118 byte_xasprintf(&path
, "%s/disobedience", dir
);
119 byte_xasprintf(&tmp
, "%s.tmp", path
);
120 mkdir(dir
, 02700); /* make sure directory exists */
121 if(!(fp
= fopen(tmp
, "w"))) {
122 fpopup_msg(GTK_MESSAGE_ERROR
, "error opening %s: %s",
123 tmp
, strerror(errno
));
126 for(n
= 0; n
< NCOLORS
; ++n
)
127 if(fprintf(fp
, "color %-20s 0x%04X 0x%04X 0x%04X\n", colors
[n
].name
,
128 colors
[n
].color
->red
,
129 colors
[n
].color
->green
,
130 colors
[n
].color
->blue
) < 0) {
131 fpopup_msg(GTK_MESSAGE_ERROR
, "error writing to %s: %s",
132 tmp
, strerror(errno
));
136 fpopup_msg(GTK_MESSAGE_ERROR
, "error writing to %s: %s",
137 tmp
, strerror(errno
));
142 if(rename(tmp
, path
) < 0)
143 fpopup_msg(GTK_MESSAGE_ERROR
, "error renaming %s to %s: %s",
144 tmp
, path
, strerror(errno
));
150 static inline unsigned clamp(unsigned n
) {
151 return n
> 0xFFFF ?
0xFFFF : n
;
154 void load_appearance(void) {
161 byte_xasprintf(&path
, "%s/.disorder/disobedience", getenv("HOME"));
162 if(!(fp
= fopen(path
, "r"))) {
164 fpopup_msg(GTK_MESSAGE_ERROR
, "error opening %s: %s",
165 path
, strerror(errno
));
167 while(!inputline(path
, fp
, &line
, '\n')) {
168 if(!(vec
= split(line
, &nvec
, SPLIT_COMMENTS
|SPLIT_QUOTES
, 0, 0))
171 if(!strcmp(vec
[0], "color")) {
173 error(0, "%s: malformed '%s' command", path
, vec
[0]);
176 for(n
= 0; n
< NCOLORS
&& strcmp(colors
[n
].name
, vec
[1]); ++n
)
179 error(0, "%s: unknown color '%s'", path
, vec
[1]);
182 colors
[n
].color
->red
= strtoul(vec
[2], 0, 0);
183 colors
[n
].color
->green
= strtoul(vec
[3], 0, 0);
184 colors
[n
].color
->blue
= strtoul(vec
[4], 0, 0);
186 /* mention errors but otherwise ignore them */
187 error(0, "%s: unknown command '%s'", path
, vec
[0]);
190 fpopup_msg(GTK_MESSAGE_ERROR
, "error reading %s: %s",
191 path
, strerror(errno
));
195 tool_active
= tool_bg
;
196 tool_active
.red
= clamp(105 * tool_active
.red
/ 100);
197 tool_active
.green
= clamp(105 * tool_active
.green
/ 100);
198 tool_active
.blue
= clamp(105 * tool_active
.blue
/ 100);
201 /** @brief Callback used by set_tool_colors() */
202 static void set_tool_colors_callback(GtkWidget
*w
,
203 gpointer
attribute((unused
)) data
) {
207 /** @brief Recursively set tool widget colors */
208 void set_tool_colors(GtkWidget
*w
) {
211 gtk_widget_modify_bg(w
, GTK_STATE_NORMAL
, &tool_bg
);
212 gtk_widget_modify_bg(w
, GTK_STATE_SELECTED
, &selected_bg
);
213 gtk_widget_modify_bg(w
, GTK_STATE_PRELIGHT
, &selected_bg
);
214 gtk_widget_modify_bg(w
, GTK_STATE_INSENSITIVE
, &tool_bg
);
215 gtk_widget_modify_fg(w
, GTK_STATE_NORMAL
, &tool_fg
);
216 gtk_widget_modify_fg(w
, GTK_STATE_SELECTED
, &selected_fg
);
217 gtk_widget_modify_fg(w
, GTK_STATE_PRELIGHT
, &selected_fg
);
218 gtk_widget_modify_fg(w
, GTK_STATE_INSENSITIVE
, &inactive_tool_fg
);
219 if(GTK_IS_CONTAINER(w
))
220 gtk_container_foreach(GTK_CONTAINER(w
), set_tool_colors_callback
, 0);
221 if(GTK_IS_MENU_ITEM(w
)
222 && (child
= gtk_menu_item_get_submenu(GTK_MENU_ITEM(w
))))
223 set_tool_colors(child
);
226 /** @brief Set the colors for a slider */
227 void set_slider_colors(GtkWidget
*w
) {
230 gtk_widget_modify_bg(w
, GTK_STATE_NORMAL
, &tool_bg
);
231 gtk_widget_modify_bg(w
, GTK_STATE_ACTIVE
, &tool_bg
);
232 gtk_widget_modify_bg(w
, GTK_STATE_SELECTED
, &tool_active
);
233 gtk_widget_modify_bg(w
, GTK_STATE_PRELIGHT
, &tool_active
);
234 gtk_widget_modify_fg(w
, GTK_STATE_NORMAL
, &tool_fg
);
235 gtk_widget_modify_fg(w
, GTK_STATE_ACTIVE
, &tool_fg
);
236 gtk_widget_modify_fg(w
, GTK_STATE_SELECTED
, &tool_fg
);
237 gtk_widget_modify_fg(w
, GTK_STATE_PRELIGHT
, &tool_fg
);