mirror of
https://github.com/gwenhael-le-moine/sway-patched-tray-menu.git
synced 2024-12-26 21:58:08 +01:00
swaybar: properly draw blocks with transparent black border
while the draw itself is a no-op, alignment must still be accounted this requires more signalling about the blocks (border_set; was the border set?)
This commit is contained in:
parent
a345180520
commit
033061aee6
3 changed files with 41 additions and 34 deletions
|
@ -19,6 +19,7 @@ struct i3bar_block {
|
||||||
// Airblader features
|
// Airblader features
|
||||||
uint32_t background;
|
uint32_t background;
|
||||||
uint32_t border;
|
uint32_t border;
|
||||||
|
bool border_set;
|
||||||
int border_top;
|
int border_top;
|
||||||
int border_bottom;
|
int border_bottom;
|
||||||
int border_left;
|
int border_left;
|
||||||
|
|
|
@ -28,6 +28,19 @@ void i3bar_block_unref(struct i3bar_block *block) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool i3bar_parse_json_color(json_object *json, uint32_t *color) {
|
||||||
|
if (!json) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *hexstring = json_object_get_string(json);
|
||||||
|
bool color_set = parse_color(hexstring, color);
|
||||||
|
if (!color_set) {
|
||||||
|
sway_log(SWAY_ERROR, "Ignoring invalid block hexadecimal color string: %s", hexstring);
|
||||||
|
}
|
||||||
|
return color_set;
|
||||||
|
}
|
||||||
|
|
||||||
static void i3bar_parse_json(struct status_line *status,
|
static void i3bar_parse_json(struct status_line *status,
|
||||||
struct json_object *json_array) {
|
struct json_object *json_array) {
|
||||||
struct i3bar_block *block, *tmp;
|
struct i3bar_block *block, *tmp;
|
||||||
|
@ -68,13 +81,7 @@ static void i3bar_parse_json(struct status_line *status,
|
||||||
strdup(json_object_get_string(full_text)) : NULL;
|
strdup(json_object_get_string(full_text)) : NULL;
|
||||||
block->short_text = short_text ?
|
block->short_text = short_text ?
|
||||||
strdup(json_object_get_string(short_text)) : NULL;
|
strdup(json_object_get_string(short_text)) : NULL;
|
||||||
if (color) {
|
block->color_set = i3bar_parse_json_color(color, &block->color);
|
||||||
const char *hexstring = json_object_get_string(color);
|
|
||||||
block->color_set = parse_color(hexstring, &block->color);
|
|
||||||
if (!block->color_set) {
|
|
||||||
sway_log(SWAY_ERROR, "Invalid block color: %s", hexstring);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (min_width) {
|
if (min_width) {
|
||||||
json_type type = json_object_get_type(min_width);
|
json_type type = json_object_get_type(min_width);
|
||||||
if (type == json_type_int) {
|
if (type == json_type_int) {
|
||||||
|
@ -100,14 +107,8 @@ static void i3bar_parse_json(struct status_line *status,
|
||||||
block->separator_block_width = separator_block_width ?
|
block->separator_block_width = separator_block_width ?
|
||||||
json_object_get_int(separator_block_width) : 9;
|
json_object_get_int(separator_block_width) : 9;
|
||||||
// Airblader features
|
// Airblader features
|
||||||
const char *hex = background ? json_object_get_string(background) : NULL;
|
i3bar_parse_json_color(background, &block->background);
|
||||||
if (hex && !parse_color(hex, &block->background)) {
|
block->border_set = i3bar_parse_json_color(border, &block->border);
|
||||||
sway_log(SWAY_ERROR, "Ignoring invalid block background: %s", hex);
|
|
||||||
}
|
|
||||||
hex = border ? json_object_get_string(border) : NULL;
|
|
||||||
if (hex && !parse_color(hex, &block->border)) {
|
|
||||||
sway_log(SWAY_ERROR, "Ignoring invalid block border: %s", hex);
|
|
||||||
}
|
|
||||||
block->border_top = border_top ? json_object_get_int(border_top) : 1;
|
block->border_top = border_top ? json_object_get_int(border_top) : 1;
|
||||||
block->border_bottom = border_bottom ?
|
block->border_bottom = border_bottom ?
|
||||||
json_object_get_int(border_bottom) : 1;
|
json_object_get_int(border_bottom) : 1;
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
#include "swaybar/ipc.h"
|
#include "swaybar/ipc.h"
|
||||||
#include "swaybar/render.h"
|
#include "swaybar/render.h"
|
||||||
#include "swaybar/status_line.h"
|
#include "swaybar/status_line.h"
|
||||||
|
#include "log.h"
|
||||||
#if HAVE_TRAY
|
#if HAVE_TRAY
|
||||||
#include "swaybar/tray/tray.h"
|
#include "swaybar/tray/tray.h"
|
||||||
#endif
|
#endif
|
||||||
|
@ -215,11 +216,11 @@ static uint32_t render_status_block(struct render_context *ctx,
|
||||||
}
|
}
|
||||||
|
|
||||||
*x -= width;
|
*x -= width;
|
||||||
if ((block->border || block->urgent) && block->border_left > 0) {
|
if ((block->border_set || block->urgent) && block->border_left > 0) {
|
||||||
*x -= (block->border_left + margin);
|
*x -= (block->border_left + margin);
|
||||||
block_width += block->border_left + margin;
|
block_width += block->border_left + margin;
|
||||||
}
|
}
|
||||||
if ((block->border || block->urgent) && block->border_right > 0) {
|
if ((block->border_set || block->urgent) && block->border_right > 0) {
|
||||||
*x -= (block->border_right + margin);
|
*x -= (block->border_right + margin);
|
||||||
block_width += block->border_right + margin;
|
block_width += block->border_right + margin;
|
||||||
}
|
}
|
||||||
|
@ -273,18 +274,20 @@ static uint32_t render_status_block(struct render_context *ctx,
|
||||||
|
|
||||||
uint32_t border_color = block->urgent
|
uint32_t border_color = block->urgent
|
||||||
? config->colors.urgent_workspace.border : block->border;
|
? config->colors.urgent_workspace.border : block->border;
|
||||||
if (border_color && block->border_top > 0) {
|
if (block->border_set || block->urgent) {
|
||||||
render_sharp_line(cairo, border_color, x_pos, y_pos,
|
if (block->border_top > 0) {
|
||||||
block_width, block->border_top);
|
render_sharp_line(cairo, border_color, x_pos, y_pos,
|
||||||
}
|
block_width, block->border_top);
|
||||||
if (border_color && block->border_bottom > 0) {
|
}
|
||||||
render_sharp_line(cairo, border_color, x_pos,
|
if (block->border_bottom > 0) {
|
||||||
y_pos + render_height - block->border_bottom,
|
render_sharp_line(cairo, border_color, x_pos,
|
||||||
block_width, block->border_bottom);
|
y_pos + render_height - block->border_bottom,
|
||||||
}
|
block_width, block->border_bottom);
|
||||||
if (border_color && block->border_left > 0) {
|
}
|
||||||
render_sharp_line(cairo, border_color, x_pos, y_pos,
|
if (block->border_left > 0) {
|
||||||
block->border_left, render_height);
|
render_sharp_line(cairo, border_color, x_pos, y_pos,
|
||||||
|
block->border_left, render_height);
|
||||||
|
}
|
||||||
x_pos += block->border_left + margin;
|
x_pos += block->border_left + margin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -307,10 +310,12 @@ static uint32_t render_status_block(struct render_context *ctx,
|
||||||
render_text(cairo, config->font, 1, block->markup, "%s", text);
|
render_text(cairo, config->font, 1, block->markup, "%s", text);
|
||||||
x_pos += width;
|
x_pos += width;
|
||||||
|
|
||||||
if (border_color && block->border_right > 0) {
|
if (block->border_set || block->urgent) {
|
||||||
x_pos += margin;
|
x_pos += margin;
|
||||||
render_sharp_line(cairo, border_color, x_pos, y_pos,
|
if (block->border_right > 0) {
|
||||||
block->border_right, render_height);
|
render_sharp_line(cairo, border_color, x_pos, y_pos,
|
||||||
|
block->border_right, render_height);
|
||||||
|
}
|
||||||
x_pos += block->border_right;
|
x_pos += block->border_right;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -375,10 +380,10 @@ static void predict_status_block_pos(cairo_t *cairo,
|
||||||
}
|
}
|
||||||
|
|
||||||
*x -= width;
|
*x -= width;
|
||||||
if ((block->border || block->urgent) && block->border_left > 0) {
|
if ((block->border_set || block->urgent) && block->border_left > 0) {
|
||||||
*x -= (block->border_left + margin);
|
*x -= (block->border_left + margin);
|
||||||
}
|
}
|
||||||
if ((block->border || block->urgent) && block->border_right > 0) {
|
if ((block->border_set || block->urgent) && block->border_right > 0) {
|
||||||
*x -= (block->border_right + margin);
|
*x -= (block->border_right + margin);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue