aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2021-04-07 06:07:43 +0000
committerDaniel Eklöf <daniel@ekloef.se>2021-04-18 18:07:29 +0000
commit292a7c5686d04160b4417ed5d57a9410ebf492cf (patch)
tree7e4098a31e231f4b9b5de191679abe5c17d5c50e
parentwayland: {xdg_,}output_*(): free old strings before assigning new ones (diff)
config/terminal: refactor: remove “default_*” color members from terminal struct
Access the original colors in the configuration instead.
-rw-r--r--config.c57
-rw-r--r--config.h3
-rw-r--r--osc.c16
-rw-r--r--render.c16
-rw-r--r--terminal.c51
-rw-r--r--terminal.h4
6 files changed, 61 insertions, 86 deletions
diff --git a/config.c b/config.c
index 6da5b68d..8809163c 100644
--- a/config.c
+++ b/config.c
@@ -857,22 +857,22 @@ parse_section_colors(const char *key, const char *value, struct config *conf,
if (strcmp(key, "foreground") == 0) color = &conf->colors.fg;
else if (strcmp(key, "background") == 0) color = &conf->colors.bg;
- else if (strcmp(key, "regular0") == 0) color = &conf->colors.regular[0];
- else if (strcmp(key, "regular1") == 0) color = &conf->colors.regular[1];
- else if (strcmp(key, "regular2") == 0) color = &conf->colors.regular[2];
- else if (strcmp(key, "regular3") == 0) color = &conf->colors.regular[3];
- else if (strcmp(key, "regular4") == 0) color = &conf->colors.regular[4];
- else if (strcmp(key, "regular5") == 0) color = &conf->colors.regular[5];
- else if (strcmp(key, "regular6") == 0) color = &conf->colors.regular[6];
- else if (strcmp(key, "regular7") == 0) color = &conf->colors.regular[7];
- else if (strcmp(key, "bright0") == 0) color = &conf->colors.bright[0];
- else if (strcmp(key, "bright1") == 0) color = &conf->colors.bright[1];
- else if (strcmp(key, "bright2") == 0) color = &conf->colors.bright[2];
- else if (strcmp(key, "bright3") == 0) color = &conf->colors.bright[3];
- else if (strcmp(key, "bright4") == 0) color = &conf->colors.bright[4];
- else if (strcmp(key, "bright5") == 0) color = &conf->colors.bright[5];
- else if (strcmp(key, "bright6") == 0) color = &conf->colors.bright[6];
- else if (strcmp(key, "bright7") == 0) color = &conf->colors.bright[7];
+ else if (strcmp(key, "regular0") == 0) color = &conf->colors.table[0];
+ else if (strcmp(key, "regular1") == 0) color = &conf->colors.table[1];
+ else if (strcmp(key, "regular2") == 0) color = &conf->colors.table[2];
+ else if (strcmp(key, "regular3") == 0) color = &conf->colors.table[3];
+ else if (strcmp(key, "regular4") == 0) color = &conf->colors.table[4];
+ else if (strcmp(key, "regular5") == 0) color = &conf->colors.table[5];
+ else if (strcmp(key, "regular6") == 0) color = &conf->colors.table[6];
+ else if (strcmp(key, "regular7") == 0) color = &conf->colors.table[7];
+ else if (strcmp(key, "bright0") == 0) color = &conf->colors.table[8 + 0];
+ else if (strcmp(key, "bright1") == 0) color = &conf->colors.table[8 + 1];
+ else if (strcmp(key, "bright2") == 0) color = &conf->colors.table[8 + 2];
+ else if (strcmp(key, "bright3") == 0) color = &conf->colors.table[8 + 3];
+ else if (strcmp(key, "bright4") == 0) color = &conf->colors.table[8 + 4];
+ else if (strcmp(key, "bright5") == 0) color = &conf->colors.table[8 + 5];
+ else if (strcmp(key, "bright6") == 0) color = &conf->colors.table[8 + 6];
+ else if (strcmp(key, "bright7") == 0) color = &conf->colors.table[8 + 7];
else if (strcmp(key, "selection-foreground") == 0) color = &conf->colors.selection_fg;
else if (strcmp(key, "selection-background") == 0) color = &conf->colors.selection_bg;
@@ -2211,7 +2211,7 @@ config_load(struct config *conf, const char *conf_path,
.colors = {
.fg = default_foreground,
.bg = default_background,
- .regular = {
+ .table = {
default_regular[0],
default_regular[1],
default_regular[2],
@@ -2220,8 +2220,7 @@ config_load(struct config *conf, const char *conf_path,
default_regular[5],
default_regular[6],
default_regular[7],
- },
- .bright = {
+
default_bright[0],
default_bright[1],
default_bright[2],
@@ -2287,6 +2286,26 @@ config_load(struct config *conf, const char *conf_path,
.notifications = tll_init(),
};
+ /* Initialize the color cube */
+ {
+ /* First 16 entries correspond to the "regular" and "bright"
+ * colors, and have already been initialized */
+
+ /* Then follows 216 RGB shades */
+ for (size_t r = 0; r < 6; r++) {
+ for (size_t g = 0; g < 6; g++) {
+ for (size_t b = 0; b < 6; b++) {
+ conf->colors.table[16 + r * 6 * 6 + g * 6 + b]
+ = r * 51 << 16 | g * 51 << 8 | b * 51;
+ }
+ }
+ }
+
+ /* And finally 24 shades of gray */
+ for (size_t i = 0; i < 24; i++)
+ conf->colors.table[232 + i] = i * 11 << 16 | i * 11 << 8 | i * 11;
+ }
+
conf->notify.raw_cmd = xstrdup(
"notify-send -a foot -i foot ${title} ${body}");
tokenize_cmdline(conf->notify.raw_cmd, &conf->notify.argv);
diff --git a/config.h b/config.h
index f8c7aaf0..696c57b6 100644
--- a/config.h
+++ b/config.h
@@ -123,8 +123,7 @@ struct config {
struct {
uint32_t fg;
uint32_t bg;
- uint32_t regular[8];
- uint32_t bright[8];
+ uint32_t table[256];
uint16_t alpha;
uint32_t selection_fg;
uint32_t selection_bg;
diff --git a/osc.c b/osc.c
index 68783701..524269ef 100644
--- a/osc.c
+++ b/osc.c
@@ -705,8 +705,8 @@ osc_dispatch(struct terminal *term)
LOG_DBG("resetting all colors");
for (size_t i = 0; i < ALEN(term->colors.table); i++) {
update_color_in_grids(
- term, term->colors.table[i], term->colors.default_table[i]);
- term->colors.table[i] = term->colors.default_table[i];
+ term, term->colors.table[i], term->conf->colors.table[i]);
+ term->colors.table[i] = term->conf->colors.table[i];
}
}
@@ -729,8 +729,8 @@ osc_dispatch(struct terminal *term)
LOG_DBG("resetting color #%u", idx);
update_color_in_grids(
- term, term->colors.table[idx], term->colors.default_table[idx]);
- term->colors.table[idx] = term->colors.default_table[idx];
+ term, term->colors.table[idx], term->conf->colors.table[idx]);
+ term->colors.table[idx] = term->conf->colors.table[idx];
}
}
@@ -741,14 +741,14 @@ osc_dispatch(struct terminal *term)
break;
case 110: /* Reset default text foreground color */
- LOG_DBG("resetting foreground");
- term->colors.fg = term->colors.default_fg;
+ LOG_DBG("resetting foreground color");
+ term->colors.fg = term->conf->colors.fg;
term_damage_view(term);
break;
case 111: /* Reset default text background color */
- LOG_DBG("resetting background");
- term->colors.bg = term->colors.default_bg;
+ LOG_DBG("resetting background color");
+ term->colors.bg = term->conf->colors.bg;
term_damage_view(term);
term_damage_margins(term);
break;
diff --git a/render.c b/render.c
index b857e360..a0c0696e 100644
--- a/render.c
+++ b/render.c
@@ -1450,7 +1450,7 @@ render_csd_title(struct terminal *term)
struct buffer *buf = shm_get_buffer(
term->wl->shm, info.width, info.height, cookie, false, 1);
- uint32_t _color = term->colors.default_fg;
+ uint32_t _color = term->conf->colors.fg;
uint16_t alpha = 0xffff;
if (term->conf->csd.color.title_set) {
@@ -1493,7 +1493,7 @@ render_csd_border(struct terminal *term, enum csd_surface surf_idx)
static void
render_csd_button_minimize(struct terminal *term, struct buffer *buf)
{
- pixman_color_t color = color_hex_to_pixman(term->colors.default_bg);
+ pixman_color_t color = color_hex_to_pixman(term->conf->colors.bg);
pixman_image_t *src = pixman_image_create_solid_fill(&color);
const int max_height = buf->height / 2;
@@ -1538,7 +1538,7 @@ static void
render_csd_button_maximize_maximized(
struct terminal *term, struct buffer *buf)
{
- pixman_color_t color = color_hex_to_pixman(term->colors.default_bg);
+ pixman_color_t color = color_hex_to_pixman(term->conf->colors.bg);
pixman_image_t *src = pixman_image_create_solid_fill(&color);
const int max_height = buf->height / 3;
@@ -1566,7 +1566,7 @@ static void
render_csd_button_maximize_window(
struct terminal *term, struct buffer *buf)
{
- pixman_color_t color = color_hex_to_pixman(term->colors.default_bg);
+ pixman_color_t color = color_hex_to_pixman(term->conf->colors.bg);
pixman_image_t *src = pixman_image_create_solid_fill(&color);
const int max_height = buf->height / 2;
@@ -1620,7 +1620,7 @@ render_csd_button_maximize(struct terminal *term, struct buffer *buf)
static void
render_csd_button_close(struct terminal *term, struct buffer *buf)
{
- pixman_color_t color = color_hex_to_pixman(term->colors.default_bg);
+ pixman_color_t color = color_hex_to_pixman(term->conf->colors.bg);
pixman_image_t *src = pixman_image_create_solid_fill(&color);
const int max_height = buf->height / 3;
@@ -1665,21 +1665,21 @@ render_csd_button(struct terminal *term, enum csd_surface surf_idx)
switch (surf_idx) {
case CSD_SURF_MINIMIZE:
- _color = term->colors.default_table[4]; /* blue */
+ _color = term->conf->colors.table[4]; /* blue */
is_set = term->conf->csd.color.minimize_set;
conf_color = &term->conf->csd.color.minimize;
is_active = term->active_surface == TERM_SURF_BUTTON_MINIMIZE;
break;
case CSD_SURF_MAXIMIZE:
- _color = term->colors.default_table[2]; /* green */
+ _color = term->conf->colors.table[2]; /* green */
is_set = term->conf->csd.color.maximize_set;
conf_color = &term->conf->csd.color.maximize;
is_active = term->active_surface == TERM_SURF_BUTTON_MAXIMIZE;
break;
case CSD_SURF_CLOSE:
- _color = term->colors.default_table[1]; /* red */
+ _color = term->conf->colors.table[1]; /* red */
is_set = term->conf->csd.color.close_set;
conf_color = &term->conf->csd.color.close;
is_active = term->active_surface == TERM_SURF_BUTTON_CLOSE;
diff --git a/terminal.c b/terminal.c
index 47c0e1ff..b55a63a9 100644
--- a/terminal.c
+++ b/terminal.c
@@ -544,25 +544,6 @@ fdm_app_sync_updates_timeout(
return true;
}
-static void
-initialize_color_cube(struct terminal *term)
-{
- /* First 16 entries have already been initialized from conf */
- for (size_t r = 0; r < 6; r++) {
- for (size_t g = 0; g < 6; g++) {
- for (size_t b = 0; b < 6; b++) {
- term->colors.default_table[16 + r * 6 * 6 + g * 6 + b]
- = r * 51 << 16 | g * 51 << 8 | b * 51;
- }
- }
- }
-
- for (size_t i = 0; i < 24; i++)
- term->colors.default_table[232 + i] = i * 11 << 16 | i * 11 << 8 | i * 11;
-
- memcpy(term->colors.table, term->colors.default_table, sizeof(term->colors.table));
-}
-
static bool
initialize_render_workers(struct terminal *term)
{
@@ -1100,27 +1081,6 @@ term_init(const struct config *conf, struct fdm *fdm, struct reaper *reaper,
.colors = {
.fg = conf->colors.fg,
.bg = conf->colors.bg,
- .default_fg = conf->colors.fg,
- .default_bg = conf->colors.bg,
- .default_table = {
- conf->colors.regular[0],
- conf->colors.regular[1],
- conf->colors.regular[2],
- conf->colors.regular[3],
- conf->colors.regular[4],
- conf->colors.regular[5],
- conf->colors.regular[6],
- conf->colors.regular[7],
-
- conf->colors.bright[0],
- conf->colors.bright[1],
- conf->colors.bright[2],
- conf->colors.bright[3],
- conf->colors.bright[4],
- conf->colors.bright[5],
- conf->colors.bright[6],
- conf->colors.bright[7],
- },
.alpha = conf->colors.alpha,
},
.origin = ORIGIN_ABSOLUTE,
@@ -1215,7 +1175,8 @@ term_init(const struct config *conf, struct fdm *fdm, struct reaper *reaper,
term->scale = it->item.scale;
}
- initialize_color_cube(term);
+ memcpy(term->colors.table, term->conf->colors.table,
+ sizeof(term->colors.table));
/* Initialize the Wayland window backend */
if ((term->window = wayl_win_init(term)) == NULL)
@@ -1714,10 +1675,10 @@ term_reset(struct terminal *term, bool hard)
term->flash.active = false;
term->blink.state = BLINK_ON;
fdm_del(term->fdm, term->blink.fd); term->blink.fd = -1;
- term->colors.fg = term->colors.default_fg;
- term->colors.bg = term->colors.default_bg;
- for (size_t i = 0; i < 256; i++)
- term->colors.table[i] = term->colors.default_table[i];
+ term->colors.fg = term->conf->colors.fg;
+ term->colors.bg = term->conf->colors.bg;
+ memcpy(term->colors.table, term->conf->colors.table,
+ sizeof(term->colors.table));
term->origin = ORIGIN_ABSOLUTE;
term->normal.cursor.lcf = false;
term->alt.cursor.lcf = false;
diff --git a/terminal.h b/terminal.h
index ce808ce8..7b463d22 100644
--- a/terminal.h
+++ b/terminal.h
@@ -407,10 +407,6 @@ struct terminal {
uint32_t bg;
uint32_t table[256];
uint16_t alpha;
-
- uint32_t default_fg;
- uint32_t default_bg;
- uint32_t default_table[256];
} colors;
enum cursor_style cursor_style;