free (clock_format_option);
s = weston_config_get_section(desktop->config, "shell", NULL, NULL);
- weston_config_section_get_uint(s, "panel-color",
- &panel->color, 0xaa000000);
+ weston_config_section_get_color(s, "panel-color",
+ &panel->color, 0xaa000000);
panel_add_launchers(panel, desktop);
s = weston_config_get_section(desktop->config, "shell", NULL, NULL);
weston_config_section_get_string(s, "background-image",
&background->image, NULL);
- weston_config_section_get_uint(s, "background-color",
- &background->color, 0);
+ weston_config_section_get_color(s, "background-color",
+ &background->color, 0x00000000);
weston_config_section_get_string(s, "background-type",
&type, "tile");
WL_EXPORT
int
+weston_config_section_get_color(struct weston_config_section *section,
+ const char *key,
+ uint32_t *color, uint32_t default_color)
+{
+ struct weston_config_entry *entry;
+ int len;
+ char *end;
+
+ entry = config_section_get_entry(section, key);
+ if (entry == NULL) {
+ *color = default_color;
+ errno = ENOENT;
+ return -1;
+ }
+
+ len = strlen(entry->value);
+ if (len == 1 && entry->value[0] == '0') {
+ *color = 0;
+ return 0;
+ } else if (len != 8 && len != 10) {
+ fprintf(stderr, "string '%s' is length %d\n", entry->value, len);
+ *color = default_color;
+ errno = EINVAL;
+ return -1;
+ }
+
+ errno = 0;
+ *color = strtoul(entry->value, &end, 16);
+ if (errno != 0 || end == entry->value || *end != '\0') {
+ *color = default_color;
+ errno = EINVAL;
+ return -1;
+ }
+
+ return 0;
+}
+
+WL_EXPORT
+int
weston_config_section_get_double(struct weston_config_section *section,
const char *key,
double *value, double default_value)
"zero=0\n"
"flag=false\n"
"\n"
+ "[colors]\n"
+ "none=0x00000000\n"
+ "low=0x11223344\n"
+ "high=0xff00ff00\n"
+ "oct=01234567\n"
+ "dec=12345670\n"
+ "short=1234567\n"
+ "\n"
"[stuff]\n"
"flag= true \n"
"\n"
};
static const char *section_names[] = {
- "foo", "bar", "stuff", "bucket", "bucket"
+ "foo", "bar", "colors", "stuff", "bucket", "bucket"
};
/*
while (weston_config_next_section(config, §ion, &name))
ZUC_ASSERT_STREQ(section_names[i++], name);
- ZUC_ASSERT_EQ(5, i);
+ ZUC_ASSERT_EQ(6, i);
}
ZUC_TEST_F(config_test_t1, test018, data)
ZUC_ASSERT_EQ(0, errno);
}
+ZUC_TEST_F(config_test_t1, test020, data)
+{
+ int r;
+ uint32_t n;
+ struct weston_config_section *section;
+ struct weston_config *config = data;
+
+ section = weston_config_get_section(config, "colors", NULL, NULL);
+ r = weston_config_section_get_color(section, "none", &n, 0xff336699);
+
+ ZUC_ASSERT_EQ(0, r);
+ ZUC_ASSERT_EQ(0x000000, n);
+ ZUC_ASSERT_EQ(0, errno);
+}
+
+ZUC_TEST_F(config_test_t1, test021, data)
+{
+ int r;
+ uint32_t n;
+ struct weston_config_section *section;
+ struct weston_config *config = data;
+
+ section = weston_config_get_section(config, "colors", NULL, NULL);
+ r = weston_config_section_get_color(section, "low", &n, 0xff336699);
+
+ ZUC_ASSERT_EQ(0, r);
+ ZUC_ASSERT_EQ(0x11223344, n);
+ ZUC_ASSERT_EQ(0, errno);
+}
+
+ZUC_TEST_F(config_test_t1, test022, data)
+{
+ int r;
+ uint32_t n;
+ struct weston_config_section *section;
+ struct weston_config *config = data;
+
+ section = weston_config_get_section(config, "colors", NULL, NULL);
+ r = weston_config_section_get_color(section, "high", &n, 0xff336699);
+
+ ZUC_ASSERT_EQ(0, r);
+ ZUC_ASSERT_EQ(0xff00ff00, n);
+ ZUC_ASSERT_EQ(0, errno);
+}
+
+ZUC_TEST_F(config_test_t1, test023, data)
+{
+ int r;
+ uint32_t n;
+ struct weston_config_section *section;
+ struct weston_config *config = data;
+
+ // Treat colors as hex values even if missing the leading 0x
+ section = weston_config_get_section(config, "colors", NULL, NULL);
+ r = weston_config_section_get_color(section, "oct", &n, 0xff336699);
+
+ ZUC_ASSERT_EQ(0, r);
+ ZUC_ASSERT_EQ(0x01234567, n);
+ ZUC_ASSERT_EQ(0, errno);
+}
+
+ZUC_TEST_F(config_test_t1, test024, data)
+{
+ int r;
+ uint32_t n;
+ struct weston_config_section *section;
+ struct weston_config *config = data;
+
+ // Treat colors as hex values even if missing the leading 0x
+ section = weston_config_get_section(config, "colors", NULL, NULL);
+ r = weston_config_section_get_color(section, "dec", &n, 0xff336699);
+
+ ZUC_ASSERT_EQ(0, r);
+ ZUC_ASSERT_EQ(0x12345670, n);
+ ZUC_ASSERT_EQ(0, errno);
+}
+
+ZUC_TEST_F(config_test_t1, test025, data)
+{
+ int r;
+ uint32_t n;
+ struct weston_config_section *section;
+ struct weston_config *config = data;
+
+ // 7-digit colors are not valid (most likely typos)
+ section = weston_config_get_section(config, "colors", NULL, NULL);
+ r = weston_config_section_get_color(section, "short", &n, 0xff336699);
+
+ ZUC_ASSERT_EQ(-1, r);
+ ZUC_ASSERT_EQ(0xff336699, n);
+ ZUC_ASSERT_EQ(EINVAL, errno);
+}
+
+ZUC_TEST_F(config_test_t1, test026, data)
+{
+ int r;
+ uint32_t n;
+ struct weston_config_section *section;
+ struct weston_config *config = data;
+
+ // String color names are unsupported
+ section = weston_config_get_section(config, "bucket", NULL, NULL);
+ r = weston_config_section_get_color(section, "color", &n, 0xff336699);
+
+ ZUC_ASSERT_EQ(-1, r);
+ ZUC_ASSERT_EQ(0xff336699, n);
+ ZUC_ASSERT_EQ(EINVAL, errno);
+}
+
ZUC_TEST_F(config_test_t2, doesnt_parse, data)
{
struct weston_config *config = data;