mirror of
https://codeberg.org/dnkl/yambar.git
synced 2025-04-22 12:25:38 +02:00
bar/wayland: guess scale when no 'output' has been configured
This commit is contained in:
parent
d80fbd4084
commit
31a4cddde3
1 changed files with 44 additions and 19 deletions
|
@ -392,11 +392,9 @@ output_scale(void *data, struct wl_output *wl_output, int32_t factor)
|
||||||
|
|
||||||
mon->scale = factor;
|
mon->scale = factor;
|
||||||
|
|
||||||
if (mon->backend->monitor == mon) {
|
if (mon->backend->monitor == mon)
|
||||||
mon->backend->scale = mon->scale;
|
|
||||||
update_size(mon->backend);
|
update_size(mon->backend);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static const struct wl_output_listener output_listener = {
|
static const struct wl_output_listener output_listener = {
|
||||||
|
@ -752,33 +750,67 @@ err:
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
guess_scale(const struct wayland_backend *backend)
|
||||||
|
{
|
||||||
|
if (tll_length(backend->monitors) == 0)
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
bool all_have_same_scale = true;
|
||||||
|
int last_scale = -1;
|
||||||
|
|
||||||
|
tll_foreach(backend->monitors, it) {
|
||||||
|
if (last_scale == -1)
|
||||||
|
last_scale = it->item.scale;
|
||||||
|
else if (last_scale != it->item.scale) {
|
||||||
|
all_have_same_scale = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (all_have_same_scale) {
|
||||||
|
assert(last_scale >= 1);
|
||||||
|
return last_scale;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
update_size(struct wayland_backend *backend)
|
update_size(struct wayland_backend *backend)
|
||||||
{
|
{
|
||||||
struct bar *_bar = backend->bar;
|
struct bar *_bar = backend->bar;
|
||||||
struct private *bar = _bar->private;
|
struct private *bar = _bar->private;
|
||||||
|
|
||||||
|
const struct monitor *mon = backend->monitor;
|
||||||
|
const int scale = mon != NULL ? mon->scale : guess_scale(backend);
|
||||||
|
|
||||||
|
if (backend->scale == scale)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
backend->scale = scale;
|
||||||
|
|
||||||
int height = bar->height_with_border;
|
int height = bar->height_with_border;
|
||||||
height /= backend->scale;
|
height /= scale;
|
||||||
height *= backend->scale;
|
height *= scale;
|
||||||
bar->height = height - 2 * bar->border.width;
|
bar->height = height - 2 * bar->border.width;
|
||||||
bar->height_with_border = height;
|
bar->height_with_border = height;
|
||||||
|
|
||||||
zwlr_layer_surface_v1_set_size(
|
zwlr_layer_surface_v1_set_size(
|
||||||
backend->layer_surface, 0, bar->height_with_border / backend->scale);
|
backend->layer_surface, 0, bar->height_with_border / scale);
|
||||||
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
|
||||||
? bar->border.bottom_margin
|
? bar->border.bottom_margin
|
||||||
: bar->border.top_margin))
|
: bar->border.top_margin))
|
||||||
/ backend->scale);
|
/ scale);
|
||||||
|
|
||||||
zwlr_layer_surface_v1_set_margin(
|
zwlr_layer_surface_v1_set_margin(
|
||||||
backend->layer_surface,
|
backend->layer_surface,
|
||||||
bar->border.top_margin / backend->scale,
|
bar->border.top_margin / scale,
|
||||||
bar->border.right_margin / backend->scale,
|
bar->border.right_margin / scale,
|
||||||
bar->border.bottom_margin / backend->scale,
|
bar->border.bottom_margin / scale,
|
||||||
bar->border.left_margin / backend->scale
|
bar->border.left_margin / scale
|
||||||
);
|
);
|
||||||
|
|
||||||
/* Trigger a 'configure' event, after which we'll have the width */
|
/* Trigger a 'configure' event, after which we'll have the width */
|
||||||
|
@ -1023,16 +1055,9 @@ surface_enter(void *data, struct wl_surface *wl_surface,
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (backend->monitor != mon) {
|
if (backend->monitor != mon) {
|
||||||
int old_scale = backend->monitor != NULL ? backend->monitor->scale : 1;
|
|
||||||
int new_scale = mon->scale;
|
|
||||||
|
|
||||||
backend->monitor = mon;
|
backend->monitor = mon;
|
||||||
|
|
||||||
if (old_scale != new_scale) {
|
|
||||||
backend->scale = mon->scale;
|
|
||||||
update_size(backend);
|
update_size(backend);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue