mirror of
https://codeberg.org/dnkl/yambar.git
synced 2025-04-28 04:35:41 +02:00
Fixes for size setting and config
+ height is optional + width is optional + make location enum into bitmask
This commit is contained in:
parent
033f21a1f2
commit
37b5b02fc4
6 changed files with 51 additions and 74 deletions
63
bar/bar.c
63
bar/bar.c
|
@ -62,7 +62,7 @@ accum_heights(const struct section *s, const struct private *b,
|
|||
if (e->height > 0)
|
||||
*out = act(*out, b->top_spacing + e->height + b->bottom_spacing);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Add action */
|
||||
|
@ -169,41 +169,6 @@ min_bar_height (const struct private *b)
|
|||
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
|
||||
begin_expose_mods(const struct section *s)
|
||||
{
|
||||
|
@ -221,9 +186,9 @@ begin_expose_mods(const struct section *s)
|
|||
static void
|
||||
bar_recalc_size(struct private *bar)
|
||||
{
|
||||
LOG_INFO("Bar width auto? %s",
|
||||
LOG_DBG("Bar width auto? %s",
|
||||
bar->width < 0 ? "yes" : "no");
|
||||
LOG_INFO("Bar height auto? %s",
|
||||
LOG_DBG("Bar height auto? %s",
|
||||
bar->height < 0 ? "yes" : "no");
|
||||
|
||||
begin_expose_mods(&(bar->left));
|
||||
|
@ -231,30 +196,28 @@ bar_recalc_size(struct private *bar)
|
|||
begin_expose_mods(&(bar->right));
|
||||
|
||||
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 =
|
||||
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
|
||||
bar->height_with_border =
|
||||
max_bar_height(bar) + bar->border.top_width + bar->border.bottom_width;
|
||||
bar->height_with_border = 0;
|
||||
} else
|
||||
bar->height_with_border =
|
||||
bar->height + bar->border.top_width + bar->border.bottom_width;
|
||||
|
||||
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 =
|
||||
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
|
||||
bar->width_with_border =
|
||||
max_bar_width(bar) + bar->border.left_width + bar->border.right_width;
|
||||
bar->width_with_border = 0;
|
||||
}else
|
||||
bar->width_with_border =
|
||||
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);
|
||||
LOG_INFO("Bar height calculated size %d",
|
||||
LOG_DBG("Bar height calculated size %d",
|
||||
bar->height);
|
||||
}
|
||||
|
||||
|
@ -293,7 +256,7 @@ expose(const struct bar *_bar)
|
|||
|
||||
int left_width, center_width, right_width;
|
||||
calculate_widths(bar, &left_width, ¢er_width, &right_width);
|
||||
|
||||
# if 0
|
||||
int y = bar->border.top_width;
|
||||
int x = bar->border.left_width + bar->left_margin - bar->left_spacing;
|
||||
pixman_region32_t clip;
|
||||
|
@ -335,7 +298,7 @@ expose(const struct bar *_bar)
|
|||
if (e->width > 0)
|
||||
x += bar->left_spacing + e->width + bar->right_spacing;
|
||||
}
|
||||
|
||||
#endif
|
||||
bar->backend.iface->commit(_bar);
|
||||
}
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ struct 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_backend { BAR_BACKEND_AUTO, BAR_BACKEND_XCB, BAR_BACKEND_WAYLAND };
|
||||
|
||||
|
|
|
@ -1044,16 +1044,28 @@ update_size(struct wayland_backend *backend)
|
|||
|
||||
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
|
||||
// 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(
|
||||
backend->layer_surface,
|
||||
(bar->height_with_border + (bar->location == BAR_TOP
|
||||
|
@ -1076,15 +1088,12 @@ update_size(struct wayland_backend *backend)
|
|||
bar->border.bottom_margin / scale,
|
||||
bar->border.left_margin / scale
|
||||
);
|
||||
|
||||
/* 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;
|
||||
}
|
||||
// TODO: Figure out why not setting width & height
|
||||
// make the bar fail to appear. Don't want to have to do this
|
||||
bar->width = backend->width - (bar->border.left_width + bar->border.right_width);
|
||||
bar->height = backend->height - (bar->border.top_width + bar->border.bottom_width);
|
||||
|
||||
/* Reload buffers */
|
||||
if (backend->next_buffer != NULL)
|
||||
|
|
|
@ -421,7 +421,7 @@ verify_bar_border(keychain_t *chain, const struct yml_node *node)
|
|||
static bool
|
||||
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
|
||||
|
@ -442,9 +442,10 @@ conf_verify_bar(const struct yml_node *bar)
|
|||
chain_push(&chain, "bar");
|
||||
|
||||
static const struct attr_info attrs[] = {
|
||||
{"height", true, &conf_verify_unsigned},
|
||||
{"location", true, &verify_bar_location},
|
||||
{"background", true, &conf_verify_color},
|
||||
{"height", false, &conf_verify_unsigned},
|
||||
{"width", false, &conf_verify_unsigned},
|
||||
|
||||
{"monitor", false, &conf_verify_string},
|
||||
{"layer", false, &verify_bar_layer},
|
||||
|
|
13
config.c
13
config.c
|
@ -289,11 +289,14 @@ conf_to_bar(const struct yml_node *bar, enum bar_backend backend)
|
|||
/*
|
||||
* Required attributes
|
||||
*/
|
||||
|
||||
const struct yml_node *location = yml_get_value(bar, "location");
|
||||
conf.location = strcmp(yml_value_as_string(location), "top") == 0
|
||||
? BAR_TOP : BAR_BOTTOM;
|
||||
|
||||
const char *location_str = yml_value_as_string(location);
|
||||
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");
|
||||
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");
|
||||
if (width != NULL)
|
||||
conf.width = yml_value_as_int(height);
|
||||
conf.width = yml_value_as_int(width);
|
||||
else
|
||||
conf.width = -1; // Represents 'auto' width
|
||||
|
||||
|
|
|
@ -136,9 +136,10 @@ content(struct module *mod)
|
|||
m->state == STATE_DISCHARGING ? "discharging" :
|
||||
"unknown"),
|
||||
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),
|
||||
},
|
||||
.count = 6,
|
||||
.count = 7,
|
||||
};
|
||||
|
||||
mtx_unlock(&mod->lock);
|
||||
|
|
Loading…
Add table
Reference in a new issue