bar: set clip region before calling the particles’ expose() methods

This ensures particles that are “too wide” doesn’t try to render
outside the bar, possibly overrunning both margins and borders. Or
worse, crashes yambar.

Closes #198
This commit is contained in:
Daniel Eklöf 2022-06-05 00:33:30 +02:00
parent a8994b9268
commit 9353aa14fe
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
2 changed files with 15 additions and 0 deletions

View file

@ -93,11 +93,14 @@
* examples/dwl-tags: updated parsing of `output` name ([#178][178]).
* sway-xkb: dont crash when Sway sends an _”added”_ event for a
device yambar is already tracking ([#177][177]).
* Crash when a particle is “too wide”, and tries to render outside the
bar ([#198][198]).
[169]: https://codeberg.org/dnkl/yambar/issues/169
[172]: https://codeberg.org/dnkl/yambar/issues/172
[178]: https://codeberg.org/dnkl/yambar/issues/178
[177]: https://codeberg.org/dnkl/yambar/issues/177
[198]: https://codeberg.org/dnkl/yambar/issues/198
### Security

View file

@ -134,6 +134,18 @@ expose(const struct bar *_bar)
int y = bar->border.top_width;
int x = bar->border.left_width + bar->left_margin - bar->left_spacing;
pixman_region32_t clip;
pixman_region32_init_rect(
&clip,
bar->border.left_width + bar->left_margin,
bar->border.top_width,
(bar->width -
bar->left_margin - bar->right_margin -
bar->border.left_width - bar->border.right_width),
bar->height);
pixman_image_set_clip_region32(pix, &clip);
pixman_region32_fini(&clip);
for (size_t i = 0; i < bar->left.count; i++) {
const struct exposable *e = bar->left.exps[i];
e->expose(e, pix, x + bar->left_spacing, y, bar->height);