diff options
author | emersion <contact@emersion.fr> | 2018-05-02 08:00:23 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-05-02 08:00:23 +0100 |
commit | fe9cc21ea70dc1a37cfadcb07b0abba3c5967211 (patch) | |
tree | 7ae5f7973d3aeef506252c1b9f72e1b110ffbcfe | |
parent | Merge pull request #1885 from thejan2009/master (diff) | |
parent | Support alpha in border colours (diff) | |
download | sway-fe9cc21ea70dc1a37cfadcb07b0abba3c5967211.tar.gz sway-fe9cc21ea70dc1a37cfadcb07b0abba3c5967211.tar.zst sway-fe9cc21ea70dc1a37cfadcb07b0abba3c5967211.zip |
Merge pull request #1886 from RyanDwyer/border-alpha
Support alpha in border colours
-rw-r--r-- | sway/commands/client.c | 15 | ||||
-rw-r--r-- | sway/desktop/output.c | 34 |
2 files changed, 30 insertions, 19 deletions
diff --git a/sway/commands/client.c b/sway/commands/client.c index 156ff95c..c3dc2ee2 100644 --- a/sway/commands/client.c +++ b/sway/commands/client.c | |||
@@ -8,7 +8,7 @@ static bool parse_color(char *hexstring, float dest[static 4]) { | |||
8 | return false; | 8 | return false; |
9 | } | 9 | } |
10 | 10 | ||
11 | if (strlen(hexstring) != 7) { | 11 | if (strlen(hexstring) != 7 && strlen(hexstring) != 9) { |
12 | return false; | 12 | return false; |
13 | } | 13 | } |
14 | 14 | ||
@@ -20,10 +20,15 @@ static bool parse_color(char *hexstring, float dest[static 4]) { | |||
20 | return false; | 20 | return false; |
21 | } | 21 | } |
22 | 22 | ||
23 | dest[0] = ((decimal >> 16) & 0xff) / 255.0; | 23 | if (strlen(hexstring) == 6) { |
24 | dest[1] = ((decimal >> 8) & 0xff) / 255.0; | 24 | // Add alpha |
25 | dest[2] = (decimal & 0xff) / 255.0; | 25 | decimal = (decimal << 8) | 0xff; |
26 | dest[3] = 1.0; | 26 | } |
27 | |||
28 | dest[0] = ((decimal >> 24) & 0xff) / 255.0; | ||
29 | dest[1] = ((decimal >> 16) & 0xff) / 255.0; | ||
30 | dest[2] = ((decimal >> 8) & 0xff) / 255.0; | ||
31 | dest[3] = (decimal & 0xff) / 255.0; | ||
27 | return true; | 32 | return true; |
28 | } | 33 | } |
29 | 34 | ||
diff --git a/sway/desktop/output.c b/sway/desktop/output.c index e0a211d1..4fff8cd3 100644 --- a/sway/desktop/output.c +++ b/sway/desktop/output.c | |||
@@ -232,10 +232,10 @@ static void render_container_simple_border_normal(struct sway_output *output, | |||
232 | wlr_backend_get_renderer(output->wlr_output->backend); | 232 | wlr_backend_get_renderer(output->wlr_output->backend); |
233 | struct wlr_box box; | 233 | struct wlr_box box; |
234 | float color[4]; | 234 | float color[4]; |
235 | color[3] = con->alpha; | ||
236 | 235 | ||
237 | // Child border - left edge | 236 | // Child border - left edge |
238 | memcpy(&color, colors->child_border, sizeof(float) * 3); | 237 | memcpy(&color, colors->child_border, sizeof(float) * 4); |
238 | color[3] *= con->alpha; | ||
239 | box.x = con->x; | 239 | box.x = con->x; |
240 | box.y = con->y + 1; | 240 | box.y = con->y + 1; |
241 | box.width = con->sway_view->border_thickness; | 241 | box.width = con->sway_view->border_thickness; |
@@ -246,10 +246,11 @@ static void render_container_simple_border_normal(struct sway_output *output, | |||
246 | 246 | ||
247 | // Child border - right edge | 247 | // Child border - right edge |
248 | if (con->parent->children->length == 1 && con->parent->layout == L_HORIZ) { | 248 | if (con->parent->children->length == 1 && con->parent->layout == L_HORIZ) { |
249 | memcpy(&color, colors->indicator, sizeof(float) * 3); | 249 | memcpy(&color, colors->indicator, sizeof(float) * 4); |
250 | } else { | 250 | } else { |
251 | memcpy(&color, colors->child_border, sizeof(float) * 3); | 251 | memcpy(&color, colors->child_border, sizeof(float) * 4); |
252 | } | 252 | } |
253 | color[3] *= con->alpha; | ||
253 | box.x = con->x + con->width - con->sway_view->border_thickness; | 254 | box.x = con->x + con->width - con->sway_view->border_thickness; |
254 | box.y = con->y + 1; | 255 | box.y = con->y + 1; |
255 | box.width = con->sway_view->border_thickness; | 256 | box.width = con->sway_view->border_thickness; |
@@ -260,10 +261,11 @@ static void render_container_simple_border_normal(struct sway_output *output, | |||
260 | 261 | ||
261 | // Child border - bottom edge | 262 | // Child border - bottom edge |
262 | if (con->parent->children->length == 1 && con->parent->layout == L_VERT) { | 263 | if (con->parent->children->length == 1 && con->parent->layout == L_VERT) { |
263 | memcpy(&color, colors->indicator, sizeof(float) * 3); | 264 | memcpy(&color, colors->indicator, sizeof(float) * 4); |
264 | } else { | 265 | } else { |
265 | memcpy(&color, colors->child_border, sizeof(float) * 3); | 266 | memcpy(&color, colors->child_border, sizeof(float) * 4); |
266 | } | 267 | } |
268 | color[3] *= con->alpha; | ||
267 | box.x = con->x; | 269 | box.x = con->x; |
268 | box.y = con->y + con->height - con->sway_view->border_thickness; | 270 | box.y = con->y + con->height - con->sway_view->border_thickness; |
269 | box.width = con->width; | 271 | box.width = con->width; |
@@ -273,7 +275,8 @@ static void render_container_simple_border_normal(struct sway_output *output, | |||
273 | output->wlr_output->transform_matrix); | 275 | output->wlr_output->transform_matrix); |
274 | 276 | ||
275 | // Single pixel bar above title | 277 | // Single pixel bar above title |
276 | memcpy(&color, colors->border, sizeof(float) * 3); | 278 | memcpy(&color, colors->border, sizeof(float) * 4); |
279 | color[3] *= con->alpha; | ||
277 | box.x = con->x; | 280 | box.x = con->x; |
278 | box.y = con->y; | 281 | box.y = con->y; |
279 | box.width = con->width; | 282 | box.width = con->width; |
@@ -292,7 +295,8 @@ static void render_container_simple_border_normal(struct sway_output *output, | |||
292 | output->wlr_output->transform_matrix); | 295 | output->wlr_output->transform_matrix); |
293 | 296 | ||
294 | // Title background | 297 | // Title background |
295 | memcpy(&color, colors->background, sizeof(float) * 3); | 298 | memcpy(&color, colors->background, sizeof(float) * 4); |
299 | color[3] *= con->alpha; | ||
296 | box.x = con->x + con->sway_view->border_thickness; | 300 | box.x = con->x + con->sway_view->border_thickness; |
297 | box.y = con->y + 1; | 301 | box.y = con->y + 1; |
298 | box.width = con->width - con->sway_view->border_thickness * 2; | 302 | box.width = con->width - con->sway_view->border_thickness * 2; |
@@ -314,10 +318,10 @@ static void render_container_simple_border_pixel(struct sway_output *output, | |||
314 | wlr_backend_get_renderer(output->wlr_output->backend); | 318 | wlr_backend_get_renderer(output->wlr_output->backend); |
315 | struct wlr_box box; | 319 | struct wlr_box box; |
316 | float color[4]; | 320 | float color[4]; |
317 | color[3] = con->alpha; | ||
318 | 321 | ||
319 | // Child border - left edge | 322 | // Child border - left edge |
320 | memcpy(&color, colors->child_border, sizeof(float) * 3); | 323 | memcpy(&color, colors->child_border, sizeof(float) * 4); |
324 | color[3] *= con->alpha; | ||
321 | box.x = con->x; | 325 | box.x = con->x; |
322 | box.y = con->y; | 326 | box.y = con->y; |
323 | box.width = con->sway_view->border_thickness; | 327 | box.width = con->sway_view->border_thickness; |
@@ -328,10 +332,11 @@ static void render_container_simple_border_pixel(struct sway_output *output, | |||
328 | 332 | ||
329 | // Child border - right edge | 333 | // Child border - right edge |
330 | if (con->parent->children->length == 1 && con->parent->layout == L_HORIZ) { | 334 | if (con->parent->children->length == 1 && con->parent->layout == L_HORIZ) { |
331 | memcpy(&color, colors->indicator, sizeof(float) * 3); | 335 | memcpy(&color, colors->indicator, sizeof(float) * 4); |
332 | } else { | 336 | } else { |
333 | memcpy(&color, colors->child_border, sizeof(float) * 3); | 337 | memcpy(&color, colors->child_border, sizeof(float) * 4); |
334 | } | 338 | } |
339 | color[3] *= con->alpha; | ||
335 | box.x = con->x + con->width - con->sway_view->border_thickness; | 340 | box.x = con->x + con->width - con->sway_view->border_thickness; |
336 | box.y = con->y; | 341 | box.y = con->y; |
337 | box.width = con->sway_view->border_thickness; | 342 | box.width = con->sway_view->border_thickness; |
@@ -351,10 +356,11 @@ static void render_container_simple_border_pixel(struct sway_output *output, | |||
351 | 356 | ||
352 | // Child border - bottom edge | 357 | // Child border - bottom edge |
353 | if (con->parent->children->length == 1 && con->parent->layout == L_VERT) { | 358 | if (con->parent->children->length == 1 && con->parent->layout == L_VERT) { |
354 | memcpy(&color, colors->indicator, sizeof(float) * 3); | 359 | memcpy(&color, colors->indicator, sizeof(float) * 4); |
355 | } else { | 360 | } else { |
356 | memcpy(&color, colors->child_border, sizeof(float) * 3); | 361 | memcpy(&color, colors->child_border, sizeof(float) * 4); |
357 | } | 362 | } |
363 | color[3] *= con->alpha; | ||
358 | box.x = con->x; | 364 | box.x = con->x; |
359 | box.y = con->y + con->height - con->sway_view->border_thickness; | 365 | box.y = con->y + con->height - con->sway_view->border_thickness; |
360 | box.width = con->width; | 366 | box.width = con->width; |