Fixes for size setting and config

+ height is optional
+ width is optional
+ make location enum into bitmask
This commit is contained in:
Kyle Gunger 2023-01-17 21:23:47 -05:00
parent 033f21a1f2
commit 37b5b02fc4
6 changed files with 51 additions and 74 deletions

View file

@ -62,7 +62,7 @@ accum_heights(const struct section *s, const struct private *b,
if (e->height > 0) if (e->height > 0)
*out = act(*out, b->top_spacing + e->height + b->bottom_spacing); *out = act(*out, b->top_spacing + e->height + b->bottom_spacing);
} }
} }
/* Add action */ /* Add action */
@ -169,41 +169,6 @@ min_bar_height (const struct private *b)
return min; return min;
} }
/*
* Calculate the minimum width the bar needs to be to show all particles.
* This assumes the bar is at the left or right of screen.
* NOTE: begin_expose() must have been called
*/
static int
max_bar_width (const struct private *b)
{
int max = 0;
accum_widths(&(b->left), b, &max, &add);
accum_widths(&(b->center), b, &max, &add);
accum_widths(&(b->right), b, &max, &add);
LOG_INFO("Max: %d", max);
return max;
}
/*
* Calculate the minimum height the bar needs to be to show all particles.
* This assumes the bar is at the top or bottom of the screen.
* NOTE: begin_expose() must have been called
*/
static int
max_bar_height (const struct private *b)
{
int max = 0;
accum_heights(&(b->left), b, &max, &add);
accum_heights(&(b->center), b, &max, &add);
accum_heights(&(b->right), b, &max, &add);
return max;
}
static void static void
begin_expose_mods(const struct section *s) begin_expose_mods(const struct section *s)
{ {
@ -221,9 +186,9 @@ begin_expose_mods(const struct section *s)
static void static void
bar_recalc_size(struct private *bar) bar_recalc_size(struct private *bar)
{ {
LOG_INFO("Bar width auto? %s", LOG_DBG("Bar width auto? %s",
bar->width < 0 ? "yes" : "no"); bar->width < 0 ? "yes" : "no");
LOG_INFO("Bar height auto? %s", LOG_DBG("Bar height auto? %s",
bar->height < 0 ? "yes" : "no"); bar->height < 0 ? "yes" : "no");
begin_expose_mods(&(bar->left)); begin_expose_mods(&(bar->left));
@ -231,30 +196,28 @@ bar_recalc_size(struct private *bar)
begin_expose_mods(&(bar->right)); begin_expose_mods(&(bar->right));
if (bar->height < 0){ if (bar->height < 0){
if (bar->location == BAR_TOP || bar->location == BAR_BOTTOM) if ((bar->location & (BAR_TOP | BAR_BOTTOM)) == bar->location)
bar->height_with_border = bar->height_with_border =
min_bar_height(bar) + bar->border.top_width + bar->border.bottom_width; min_bar_height(bar) + bar->border.top_width + bar->border.bottom_width;
else else
bar->height_with_border = bar->height_with_border = 0;
max_bar_height(bar) + bar->border.top_width + bar->border.bottom_width;
} else } else
bar->height_with_border = bar->height_with_border =
bar->height + bar->border.top_width + bar->border.bottom_width; bar->height + bar->border.top_width + bar->border.bottom_width;
if (bar->width < 0){ if (bar->width < 0){
if (bar->location == BAR_LEFT || bar->location == BAR_RIGHT) if ((bar->location & (BAR_LEFT | BAR_RIGHT)) == bar->location)
bar->width_with_border = bar->width_with_border =
min_bar_width(bar) + bar->border.left_width + bar->border.right_width; min_bar_width(bar) + bar->border.left_width + bar->border.right_width;
else else
bar->width_with_border = bar->width_with_border = 0;
max_bar_width(bar) + bar->border.left_width + bar->border.right_width;
}else }else
bar->width_with_border = bar->width_with_border =
bar->width + bar->border.top_width + bar->border.bottom_width; bar->width + bar->border.top_width + bar->border.bottom_width;
LOG_INFO("Bar width calculated size %d", LOG_DBG("Bar width calculated size %d",
bar->width); bar->width);
LOG_INFO("Bar height calculated size %d", LOG_DBG("Bar height calculated size %d",
bar->height); bar->height);
} }
@ -293,7 +256,7 @@ expose(const struct bar *_bar)
int left_width, center_width, right_width; int left_width, center_width, right_width;
calculate_widths(bar, &left_width, &center_width, &right_width); calculate_widths(bar, &left_width, &center_width, &right_width);
# if 0
int y = bar->border.top_width; int y = bar->border.top_width;
int x = bar->border.left_width + bar->left_margin - bar->left_spacing; int x = bar->border.left_width + bar->left_margin - bar->left_spacing;
pixman_region32_t clip; pixman_region32_t clip;
@ -335,7 +298,7 @@ expose(const struct bar *_bar)
if (e->width > 0) if (e->width > 0)
x += bar->left_spacing + e->width + bar->right_spacing; x += bar->left_spacing + e->width + bar->right_spacing;
} }
#endif
bar->backend.iface->commit(_bar); bar->backend.iface->commit(_bar);
} }

View file

@ -17,7 +17,7 @@ struct bar {
const char *(*output_name)(const struct bar *bar); const char *(*output_name)(const struct bar *bar);
}; };
enum bar_location { BAR_TOP, BAR_BOTTOM, BAR_LEFT, BAR_RIGHT }; enum bar_location { BAR_TOP = 0b1, BAR_BOTTOM = 0b10, BAR_LEFT = 0b100, BAR_RIGHT = 0b1000 };
enum bar_layer { BAR_LAYER_TOP, BAR_LAYER_BOTTOM }; enum bar_layer { BAR_LAYER_TOP, BAR_LAYER_BOTTOM };
enum bar_backend { BAR_BACKEND_AUTO, BAR_BACKEND_XCB, BAR_BACKEND_WAYLAND }; enum bar_backend { BAR_BACKEND_AUTO, BAR_BACKEND_XCB, BAR_BACKEND_WAYLAND };

View file

@ -1044,16 +1044,28 @@ update_size(struct wayland_backend *backend)
backend->scale = scale; backend->scale = scale;
int height = bar->height < 0 ? 0 : bar->height_with_border;
int width = bar->width < 0 ? 0 : bar->width_with_border;
LOG_INFO("Attempting to set %dx%d", width, height);
// TODO: Somehow set up width and height properly // TODO: Somehow set up width and height properly
// I need to read more to understand how bar->width and bar->height are used // I need to read more to understand how bar->width and bar->height are used
zwlr_layer_surface_v1_set_size(backend->layer_surface, width / scale, height / scale); zwlr_layer_surface_v1_set_size(
backend->layer_surface,
bar->width_with_border / scale,
bar->height_with_border / scale
);
if (bar->location == BAR_TOP || bar->location == BAR_BOTTOM) { /* Trigger a 'configure' event, after which we'll have the width */
wl_surface_commit(backend->surface);
wl_display_roundtrip(backend->display);
if (backend->width == -1 || backend->height == -1) {
LOG_ERR("failed to get panel size");
return false;
}
LOG_INFO("backend size: %dx%d", backend->width, backend->height);
bar->width_with_border = backend->width;
bar->height_with_border = backend->height;
if (bar->location & (BAR_TOP | BAR_BOTTOM)) {
zwlr_layer_surface_v1_set_exclusive_zone( zwlr_layer_surface_v1_set_exclusive_zone(
backend->layer_surface, backend->layer_surface,
(bar->height_with_border + (bar->location == BAR_TOP (bar->height_with_border + (bar->location == BAR_TOP
@ -1077,14 +1089,11 @@ update_size(struct wayland_backend *backend)
bar->border.left_margin / scale bar->border.left_margin / scale
); );
/* Trigger a 'configure' event, after which we'll have the width */
wl_surface_commit(backend->surface); wl_surface_commit(backend->surface);
wl_display_roundtrip(backend->display); // TODO: Figure out why not setting width & height
// make the bar fail to appear. Don't want to have to do this
if (backend->width == -1 || backend->height == -1) { bar->width = backend->width - (bar->border.left_width + bar->border.right_width);
LOG_ERR("failed to get panel size"); bar->height = backend->height - (bar->border.top_width + bar->border.bottom_width);
return false;
}
/* Reload buffers */ /* Reload buffers */
if (backend->next_buffer != NULL) if (backend->next_buffer != NULL)

View file

@ -421,7 +421,7 @@ verify_bar_border(keychain_t *chain, const struct yml_node *node)
static bool static bool
verify_bar_location(keychain_t *chain, const struct yml_node *node) verify_bar_location(keychain_t *chain, const struct yml_node *node)
{ {
return conf_verify_enum(chain, node, (const char *[]){"top", "bottom"}, 2); return conf_verify_enum(chain, node, (const char *[]){"top", "left", "right", "bottom"}, 4);
} }
static bool static bool
@ -442,9 +442,10 @@ conf_verify_bar(const struct yml_node *bar)
chain_push(&chain, "bar"); chain_push(&chain, "bar");
static const struct attr_info attrs[] = { static const struct attr_info attrs[] = {
{"height", true, &conf_verify_unsigned},
{"location", true, &verify_bar_location}, {"location", true, &verify_bar_location},
{"background", true, &conf_verify_color}, {"background", true, &conf_verify_color},
{"height", false, &conf_verify_unsigned},
{"width", false, &conf_verify_unsigned},
{"monitor", false, &conf_verify_string}, {"monitor", false, &conf_verify_string},
{"layer", false, &verify_bar_layer}, {"layer", false, &verify_bar_layer},

View file

@ -289,11 +289,14 @@ conf_to_bar(const struct yml_node *bar, enum bar_backend backend)
/* /*
* Required attributes * Required attributes
*/ */
const struct yml_node *location = yml_get_value(bar, "location"); const struct yml_node *location = yml_get_value(bar, "location");
conf.location = strcmp(yml_value_as_string(location), "top") == 0 const char *location_str = yml_value_as_string(location);
? BAR_TOP : BAR_BOTTOM; conf.location = strcmp(location_str, "top") == 0
? BAR_TOP
: strcmp(location_str, "left") == 0
? BAR_LEFT
: strcmp(location_str, "right") == 0
? BAR_RIGHT : BAR_BOTTOM;
const struct yml_node *background = yml_get_value(bar, "background"); const struct yml_node *background = yml_get_value(bar, "background");
conf.background = conf_to_color(background); conf.background = conf_to_color(background);
@ -309,7 +312,7 @@ conf_to_bar(const struct yml_node *bar, enum bar_backend backend)
const struct yml_node *width = yml_get_value(bar, "width"); const struct yml_node *width = yml_get_value(bar, "width");
if (width != NULL) if (width != NULL)
conf.width = yml_value_as_int(height); conf.width = yml_value_as_int(width);
else else
conf.width = -1; // Represents 'auto' width conf.width = -1; // Represents 'auto' width

View file

@ -136,9 +136,10 @@ content(struct module *mod)
m->state == STATE_DISCHARGING ? "discharging" : m->state == STATE_DISCHARGING ? "discharging" :
"unknown"), "unknown"),
tag_new_int_range(mod, "capacity", m->capacity, 0, 100), tag_new_int_range(mod, "capacity", m->capacity, 0, 100),
tag_new_int_range(mod, "charge", 50, 0, 100),
tag_new_string(mod, "estimate", estimate), tag_new_string(mod, "estimate", estimate),
}, },
.count = 6, .count = 7,
}; };
mtx_unlock(&mod->lock); mtx_unlock(&mod->lock);