Allow a single gradient per bg/state

This commit is contained in:
o9000 2017-02-19 19:33:45 +01:00
parent 15150fb577
commit 207129447d
7 changed files with 18 additions and 38 deletions

View file

@ -288,14 +288,12 @@ task_active_background_id = 2
systray_background_id = 0 systray_background_id = 0
clock_background_id = 0 clock_background_id = 0
</code></pre> </code></pre>
<p>Identifier 0 refers to a special background which is fully transparent, identifier 1 applies the first background defined in the config file etc.</p><h3 id="gradients">Gradients<a name="gradients" href="#gradients" class="md2man-permalink" title="permalink"></a></h3><p>(Available since 0.13.0)</p><p>Backgrounds also allow specifying one or more gradient layers <p>Identifier 0 refers to a special background which is fully transparent, identifier 1 applies the first background defined in the config file etc.</p><h3 id="gradients">Gradients<a name="gradients" href="#gradients" class="md2man-permalink" title="permalink"></a></h3><p>(Available since 0.13.0)</p><p>Backgrounds also allow specifying gradient layers
that are drawn on top of the solid color background.</p><p>First the user must define one or more gradients in the config file, that are drawn on top of the solid color background.</p><p>First the user must define one or more gradients in the config file,
each starting with <code>gradient = TYPE</code>. These must be added before backgrounds.</p><p>Then gradients can be added by index to backgrounds, each starting with <code>gradient = TYPE</code>. These must be added before backgrounds.</p><p>Then gradients can be added by index to backgrounds,
using the <code>gradient_id = INDEX</code>, <code>hover_gradient_id = INDEX</code> and using the <code>gradient_id = INDEX</code>, <code>hover_gradient_id = INDEX</code> and
<code>pressed_gradient_id = INDEX</code>, where <code>INDEX</code> is <code>pressed_gradient_id = INDEX</code>, where <code>INDEX</code> is
the gradient index, starting from 1. The <code>*gradient_id</code> option can be repeated the gradient index, starting from 1.</p><h4 id="simple-gradients">Simple gradients<a name="simple-gradients" href="#simple-gradients" class="md2man-permalink" title="permalink"></a></h4><p>These are gradients that vary from fixed control points (top-to-bottom, left-to-right
for the same background, which results in multiple gradients
being drawn on top of each other in the given order.</p><h4 id="simple-gradients">Simple gradients<a name="simple-gradients" href="#simple-gradients" class="md2man-permalink" title="permalink"></a></h4><p>These are gradients that vary from fixed control points (top-to-bottom, left-to-right
or center-to-corners). The user must specify the start and end colors, or center-to-corners). The user must specify the start and end colors,
and can optionally add extra color stops in between.</p><h5 id="vertical-gradient-with-color-varying-from-the-top-edge-to-the-bottom-edge-two-colors">Vertical gradient, with color varying from the top edge to the bottom edge, two colors<a name="vertical-gradient-with-color-varying-from-the-top-edge-to-the-bottom-edge-two-colors" href="#vertical-gradient-with-color-varying-from-the-top-edge-to-the-bottom-edge-two-colors" class="md2man-permalink" title="permalink"></a></h5><pre class="highlight plaintext"><code>gradient = vertical and can optionally add extra color stops in between.</p><h5 id="vertical-gradient-with-color-varying-from-the-top-edge-to-the-bottom-edge-two-colors">Vertical gradient, with color varying from the top edge to the bottom edge, two colors<a name="vertical-gradient-with-color-varying-from-the-top-edge-to-the-bottom-edge-two-colors" href="#vertical-gradient-with-color-varying-from-the-top-edge-to-the-bottom-edge-two-colors" class="md2man-permalink" title="permalink"></a></h5><pre class="highlight plaintext"><code>gradient = vertical
start_color = #rrggbb opacity start_color = #rrggbb opacity

View file

@ -179,7 +179,7 @@ Identifier 0 refers to a special background which is fully transparent, identifi
.PP .PP
(Available since 0.13.0) (Available since 0.13.0)
.PP .PP
Backgrounds also allow specifying one or more gradient layers Backgrounds also allow specifying gradient layers
that are drawn on top of the solid color background. that are drawn on top of the solid color background.
.PP .PP
First the user must define one or more gradients in the config file, First the user must define one or more gradients in the config file,
@ -188,9 +188,7 @@ each starting with \fB\fCgradient = TYPE\fR\&. These must be added before backgr
Then gradients can be added by index to backgrounds, Then gradients can be added by index to backgrounds,
using the \fB\fCgradient_id = INDEX\fR, \fB\fChover_gradient_id = INDEX\fR and using the \fB\fCgradient_id = INDEX\fR, \fB\fChover_gradient_id = INDEX\fR and
\fB\fCpressed_gradient_id = INDEX\fR, where \fB\fCINDEX\fR is \fB\fCpressed_gradient_id = INDEX\fR, where \fB\fCINDEX\fR is
the gradient index, starting from 1. The \fB\fC*gradient_id\fR option can be repeated the gradient index, starting from 1.
for the same background, which results in multiple gradients
being drawn on top of each other in the given order.
.SS Simple gradients .SS Simple gradients
.PP .PP
These are gradients that vary from fixed control points (top\-to\-bottom, left\-to\-right These are gradients that vary from fixed control points (top\-to\-bottom, left\-to\-right

View file

@ -142,7 +142,7 @@ Identifier 0 refers to a special background which is fully transparent, identifi
(Available since 0.13.0) (Available since 0.13.0)
Backgrounds also allow specifying one or more gradient layers Backgrounds also allow specifying gradient layers
that are drawn on top of the solid color background. that are drawn on top of the solid color background.
First the user must define one or more gradients in the config file, First the user must define one or more gradients in the config file,
@ -151,9 +151,7 @@ each starting with `gradient = TYPE`. These must be added before backgrounds.
Then gradients can be added by index to backgrounds, Then gradients can be added by index to backgrounds,
using the `gradient_id = INDEX`, `hover_gradient_id = INDEX` and using the `gradient_id = INDEX`, `hover_gradient_id = INDEX` and
`pressed_gradient_id = INDEX`, where `INDEX` is `pressed_gradient_id = INDEX`, where `INDEX` is
the gradient index, starting from 1. The `*gradient_id` option can be repeated the gradient index, starting from 1.
for the same background, which results in multiple gradients
being drawn on top of each other in the given order.
#### Simple gradients #### Simple gradients

View file

@ -318,19 +318,19 @@ void add_entry(char *key, char *value)
int id = atoi(value); int id = atoi(value);
id = (id < gradients->len && id >= 0) ? id : -1; id = (id < gradients->len && id >= 0) ? id : -1;
if (id >= 0) if (id >= 0)
bg->gradients[MOUSE_NORMAL] = g_list_append(bg->gradients[MOUSE_NORMAL], &g_array_index(gradients, GradientClass, id)); bg->gradients[MOUSE_NORMAL] = &g_array_index(gradients, GradientClass, id);
} else if (strcmp(key, "hover_gradient_id") == 0) { } else if (strcmp(key, "hover_gradient_id") == 0) {
Background *bg = &g_array_index(backgrounds, Background, backgrounds->len - 1); Background *bg = &g_array_index(backgrounds, Background, backgrounds->len - 1);
int id = atoi(value); int id = atoi(value);
id = (id < gradients->len && id >= 0) ? id : -1; id = (id < gradients->len && id >= 0) ? id : -1;
if (id >= 0) if (id >= 0)
bg->gradients[MOUSE_OVER] = g_list_append(bg->gradients[MOUSE_OVER], &g_array_index(gradients, GradientClass, id)); bg->gradients[MOUSE_OVER] = &g_array_index(gradients, GradientClass, id);
} else if (strcmp(key, "pressed_gradient_id") == 0) { } else if (strcmp(key, "pressed_gradient_id") == 0) {
Background *bg = &g_array_index(backgrounds, Background, backgrounds->len - 1); Background *bg = &g_array_index(backgrounds, Background, backgrounds->len - 1);
int id = atoi(value); int id = atoi(value);
id = (id < gradients->len && id >= 0) ? id : -1; id = (id < gradients->len && id >= 0) ? id : -1;
if (id >= 0) if (id >= 0)
bg->gradients[MOUSE_DOWN] = g_list_append(bg->gradients[MOUSE_DOWN], &g_array_index(gradients, GradientClass, id)); bg->gradients[MOUSE_DOWN] = &g_array_index(gradients, GradientClass, id);
} }
/* Gradients */ /* Gradients */

View file

@ -156,10 +156,7 @@ void cleanup_panel()
free_area(&panel_config.area); free_area(&panel_config.area);
if (backgrounds) { g_array_free(backgrounds, TRUE);
for (guint i = 0; i < backgrounds->len; i++)
cleanup_background(&g_array_index(backgrounds, Background, i));
}
backgrounds = NULL; backgrounds = NULL;
if (gradients) { if (gradients) {
for (guint i = 0; i < gradients->len; i++) for (guint i = 0; i < gradients->len; i++)

View file

@ -40,16 +40,6 @@ void init_background(Background *bg)
bg->border.mask = BORDER_TOP | BORDER_BOTTOM | BORDER_LEFT | BORDER_RIGHT; bg->border.mask = BORDER_TOP | BORDER_BOTTOM | BORDER_LEFT | BORDER_RIGHT;
} }
void cleanup_background(Background *bg)
{
if (debug_gradients)
fprintf(stderr, YELLOW "freeing gradient list %p" RESET "\n", (void*)bg->gradients);
for (int i = 0; i < MOUSE_STATE_COUNT; i++) {
g_list_free(bg->gradients[i]);
bg->gradients[i] = NULL;
}
}
void initialize_positions(void *obj, int offset) void initialize_positions(void *obj, int offset)
{ {
Area *a = (Area *)obj; Area *a = (Area *)obj;
@ -964,12 +954,12 @@ void instantiate_area_gradients(Area *area)
fprintf(stderr, "Initializing gradients for area %s\n", area->name); fprintf(stderr, "Initializing gradients for area %s\n", area->name);
for (int i = 0; i < MOUSE_STATE_COUNT; i++) { for (int i = 0; i < MOUSE_STATE_COUNT; i++) {
g_assert_null(area->gradient_instances_by_state[i]); g_assert_null(area->gradient_instances_by_state[i]);
for (GList *l = area->bg->gradients[i]; l; l = l->next) { GradientClass *g = area->bg->gradients[i];
GradientClass *g = (GradientClass *)l->data; if (!g)
GradientInstance *gi = (GradientInstance *)calloc(1, sizeof(GradientInstance)); continue;
instantiate_gradient(area, g, gi); GradientInstance *gi = (GradientInstance *)calloc(1, sizeof(GradientInstance));
area->gradient_instances_by_state[i] = g_list_append(area->gradient_instances_by_state[i], gi); instantiate_gradient(area, g, gi);
} area->gradient_instances_by_state[i] = g_list_append(area->gradient_instances_by_state[i], gi);
} }
} }

View file

@ -152,8 +152,8 @@ typedef struct Background {
// On mouse press // On mouse press
Color fill_color_pressed; Color fill_color_pressed;
Color border_color_pressed; Color border_color_pressed;
// Each list element is a pointer to a GradientClass (list can be empty), no ownership // Pointer to a GradientClass or NULL, no ownership
GList *gradients[MOUSE_STATE_COUNT]; GradientClass *gradients[MOUSE_STATE_COUNT];
} Background; } Background;
typedef enum Layout { typedef enum Layout {
@ -244,7 +244,6 @@ typedef struct Area {
// Initializes the Background member to default values. // Initializes the Background member to default values.
void init_background(Background *bg); void init_background(Background *bg);
void cleanup_background(Background *bg);
// Layout // Layout