swaybar: min_width and align
This commit is contained in:
parent
ac23fa5f20
commit
edd93b5b55
|
@ -414,9 +414,29 @@ void render() {
|
||||||
struct status_block *block = status_line->items[i];
|
struct status_block *block = status_line->items[i];
|
||||||
if (block->full_text && block->full_text[0]) {
|
if (block->full_text && block->full_text[0]) {
|
||||||
get_text_size(window, &width, &height, "%s", block->full_text);
|
get_text_size(window, &width, &height, "%s", block->full_text);
|
||||||
|
|
||||||
|
int textwidth = width;
|
||||||
|
|
||||||
|
if (width < block->min_width) {
|
||||||
|
width = block->min_width;
|
||||||
|
}
|
||||||
|
|
||||||
moved += width + block->separator_block_width;
|
moved += width + block->separator_block_width;
|
||||||
blockpos = window->width - margin - moved;
|
blockpos = window->width - margin - moved;
|
||||||
cairo_move_to(window->cairo, blockpos, margin);
|
|
||||||
|
int offset = 0;
|
||||||
|
|
||||||
|
if (strncmp(block->align, "left", 5) == 0) {
|
||||||
|
offset = blockpos;
|
||||||
|
}
|
||||||
|
else if (strncmp(block->align, "right", 5) == 0) {
|
||||||
|
offset = blockpos + width - textwidth;
|
||||||
|
}
|
||||||
|
else if (strncmp(block->align, "center", 6) == 0) {
|
||||||
|
offset = blockpos + (width - textwidth) / 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
cairo_move_to(window->cairo, offset, margin);
|
||||||
cairo_set_source_u32(window->cairo, block->color);
|
cairo_set_source_u32(window->cairo, block->color);
|
||||||
pango_printf(window, "%s", block->full_text);
|
pango_printf(window, "%s", block->full_text);
|
||||||
if (corner) {
|
if (corner) {
|
||||||
|
@ -425,9 +445,9 @@ void render() {
|
||||||
cairo_set_source_u32(window->cairo, colors.separator);
|
cairo_set_source_u32(window->cairo, colors.separator);
|
||||||
cairo_set_line_width(window->cairo, 1);
|
cairo_set_line_width(window->cairo, 1);
|
||||||
cairo_move_to(window->cairo, blockpos + width
|
cairo_move_to(window->cairo, blockpos + width
|
||||||
+ block->separator_block_width/2, margin);
|
+ block->separator_block_width/2, margin);
|
||||||
cairo_line_to(window->cairo, blockpos + width
|
cairo_line_to(window->cairo, blockpos + width
|
||||||
+ block->separator_block_width/2, window->height - margin);
|
+ block->separator_block_width/2, window->height - margin);
|
||||||
cairo_stroke(window->cairo);
|
cairo_stroke(window->cairo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -492,22 +512,6 @@ void free_status_block(void *item) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void parse_json(const char *text) {
|
void parse_json(const char *text) {
|
||||||
/* the array of objects looks like this:
|
|
||||||
* [ {
|
|
||||||
* "full_text": "E: 10.0.0.1 (1000 Mbit/s)",
|
|
||||||
* "short_text": "10.0.0.1",
|
|
||||||
* "color": "#00ff00",
|
|
||||||
* "min_width": 300,
|
|
||||||
* "align": "right",
|
|
||||||
* "urgent": false,
|
|
||||||
* "name": "ethernet",
|
|
||||||
* "instance": "eth0",
|
|
||||||
* "separator": true,
|
|
||||||
* "separator_block_width": 9
|
|
||||||
* },
|
|
||||||
* { ... }, ...
|
|
||||||
* ]
|
|
||||||
*/
|
|
||||||
json_object *results = json_tokener_parse(text);
|
json_object *results = json_tokener_parse(text);
|
||||||
if (!results) {
|
if (!results) {
|
||||||
sway_log(L_DEBUG, "xxx Failed to parse json");
|
sway_log(L_DEBUG, "xxx Failed to parse json");
|
||||||
|
@ -565,7 +569,15 @@ void parse_json(const char *text) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (min_width) {
|
if (min_width) {
|
||||||
new->min_width = json_object_get_int(min_width);
|
json_type type = json_object_get_type(min_width);
|
||||||
|
if (type == json_type_int) {
|
||||||
|
new->min_width = json_object_get_int(min_width);
|
||||||
|
}
|
||||||
|
else if (type == json_type_string) {
|
||||||
|
int width, height;
|
||||||
|
get_text_size(window, &width, &height, "%s", json_object_get_string(min_width));
|
||||||
|
new->min_width = width;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (align) {
|
if (align) {
|
||||||
|
|
Loading…
Reference in a new issue