(Wayland) Use any display for initial metrics (#13417)

This commit is contained in:
Colin Kinloch 2021-12-26 03:53:57 +00:00 committed by GitHub
parent 26132a2330
commit 22df09885e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 50 additions and 18 deletions

View File

@ -126,8 +126,21 @@ static void gfx_ctx_wl_get_video_size(void *data,
{
gfx_ctx_wayland_data_t *wl = (gfx_ctx_wayland_data_t*)data;
*width = wl->width * wl->buffer_scale;
*height = wl->height * wl->buffer_scale;
if (wl->surface == NULL) {
output_info_t *oi, *tmp;
oi = wl->current_output;
// If window is not ready get any monitor
if (!oi)
wl_list_for_each_safe(oi, tmp, &wl->all_outputs, link)
break;
*width = oi->width;
*height = oi->height;
} else {
*width = wl->width * wl->buffer_scale;
*height = wl->height * wl->buffer_scale;
}
}
static void gfx_ctx_wl_destroy_resources(gfx_ctx_wayland_data_t *wl)
@ -270,25 +283,26 @@ static bool gfx_ctx_wl_get_metrics(void *data,
{
gfx_ctx_wayland_data_t *wl = (gfx_ctx_wayland_data_t*)data;
if ( !wl
|| !wl->current_output
|| wl->current_output->physical_width == 0
|| wl->current_output->physical_height == 0)
return false;
output_info_t *oi, *tmp;
oi = wl->current_output;
if (!oi)
wl_list_for_each_safe(oi, tmp, &wl->all_outputs, link)
break;
switch (type)
{
case DISPLAY_METRIC_MM_WIDTH:
*value = (float)wl->current_output->physical_width;
*value = (float)oi->physical_width;
break;
case DISPLAY_METRIC_MM_HEIGHT:
*value = (float)wl->current_output->physical_height;
*value = (float)oi->physical_height;
break;
case DISPLAY_METRIC_DPI:
*value = (float)wl->current_output->width * 25.4f /
(float)wl->current_output->physical_width;
*value = (float)oi->width * 25.4f /
(float)oi->physical_width;
break;
default:

View File

@ -109,8 +109,21 @@ static void gfx_ctx_wl_get_video_size(void *data,
{
gfx_ctx_wayland_data_t *wl = (gfx_ctx_wayland_data_t*)data;
*width = wl->width * wl->buffer_scale;
*height = wl->height * wl->buffer_scale;
if (wl->surface == NULL) {
output_info_t *oi, *tmp;
oi = wl->current_output;
// If window is not ready get any monitor
if (!oi)
wl_list_for_each_safe(oi, tmp, &wl->all_outputs, link)
break;
*width = oi->width;
*height = oi->height;
} else {
*width = wl->width * wl->buffer_scale;
*height = wl->height * wl->buffer_scale;
}
}
static void gfx_ctx_wl_destroy_resources(gfx_ctx_wayland_data_t *wl)
@ -264,21 +277,26 @@ static bool gfx_ctx_wl_get_metrics(void *data,
{
gfx_ctx_wayland_data_t *wl = (gfx_ctx_wayland_data_t*)data;
if (!wl || !wl->current_output || wl->current_output->physical_width == 0 || wl->current_output->physical_height == 0)
return false;
output_info_t *oi, *tmp;
oi = wl->current_output;
if (!oi)
wl_list_for_each_safe(oi, tmp, &wl->all_outputs, link)
break;
switch (type)
{
case DISPLAY_METRIC_MM_WIDTH:
*value = (float)wl->current_output->physical_width;
*value = (float)oi->physical_width;
break;
case DISPLAY_METRIC_MM_HEIGHT:
*value = (float)wl->current_output->physical_height;
*value = (float)oi->physical_height;
break;
case DISPLAY_METRIC_DPI:
*value = (float)wl->current_output->width * 25.4f / (float)wl->current_output->physical_width;
*value = (float)oi->width * 25.4f /
(float)oi->physical_width;
break;
default: