wayland: Implement GetDisplayDPI
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
diff --git a/src/video/wayland/SDL_waylandvideo.c b/src/video/wayland/SDL_waylandvideo.c
index 3812245..3f66a67 100644
--- a/src/video/wayland/SDL_waylandvideo.c
+++ b/src/video/wayland/SDL_waylandvideo.c
@@ -61,6 +61,9 @@ Wayland_VideoInit(_THIS);
static int
Wayland_GetDisplayBounds(_THIS, SDL_VideoDisplay *display, SDL_Rect *rect);
+static int
+Wayland_GetDisplayDPI(_THIS, SDL_VideoDisplay * sdl_display, float * ddpi, float * hdpi, float * vdpi);
+
static void
Wayland_VideoQuit(_THIS);
@@ -176,6 +179,7 @@ Wayland_CreateDevice(int devindex)
device->VideoInit = Wayland_VideoInit;
device->VideoQuit = Wayland_VideoQuit;
device->GetDisplayBounds = Wayland_GetDisplayBounds;
+ device->GetDisplayDPI = Wayland_GetDisplayDPI;
device->GetWindowWMInfo = Wayland_GetWindowWMInfo;
device->SuspendScreenSaver = Wayland_SuspendScreenSaver;
@@ -251,6 +255,8 @@ display_handle_geometry(void *data,
driverdata->x = x;
driverdata->y = y;
+ driverdata->physical_width = physical_width;
+ driverdata->physical_height = physical_height;
driverdata->placeholder.name = SDL_strdup(model);
driverdata->transform = transform;
}
@@ -309,9 +315,31 @@ display_handle_done(void *data,
if (driverdata->transform & WL_OUTPUT_TRANSFORM_90) {
mode.w = driverdata->height / driverdata->scale_factor;
mode.h = driverdata->width / driverdata->scale_factor;
+
+ driverdata->hdpi = driverdata->physical_height ?
+ (((float) driverdata->height) * 25.4f / driverdata->physical_height) :
+ 0.0f;
+ driverdata->vdpi = driverdata->physical_width ?
+ (((float) driverdata->width) * 25.4f / driverdata->physical_width) :
+ 0.0f;
+ driverdata->ddpi = SDL_ComputeDiagonalDPI(driverdata->height,
+ driverdata->width,
+ ((float) driverdata->physical_height) / 25.4f,
+ ((float) driverdata->physical_width) / 25.4f);
} else {
mode.w = driverdata->width / driverdata->scale_factor;
mode.h = driverdata->height / driverdata->scale_factor;
+
+ driverdata->hdpi = driverdata->physical_width ?
+ (((float) driverdata->width) * 25.4f / driverdata->physical_width) :
+ 0.0f;
+ driverdata->vdpi = driverdata->physical_height ?
+ (((float) driverdata->height) * 25.4f / driverdata->physical_height) :
+ 0.0f;
+ driverdata->ddpi = SDL_ComputeDiagonalDPI(driverdata->width,
+ driverdata->height,
+ ((float) driverdata->physical_width) / 25.4f,
+ ((float) driverdata->physical_height) / 25.4f);
}
mode.refresh_rate = driverdata->refresh / 1000; /* mHz to Hz */
mode.driverdata = driverdata->output;
@@ -511,6 +539,24 @@ Wayland_GetDisplayBounds(_THIS, SDL_VideoDisplay *display, SDL_Rect *rect)
return 0;
}
+static int
+Wayland_GetDisplayDPI(_THIS, SDL_VideoDisplay * sdl_display, float * ddpi, float * hdpi, float * vdpi)
+{
+ SDL_WaylandOutputData *driverdata = (SDL_WaylandOutputData *)sdl_display->driverdata;
+
+ if (ddpi) {
+ *ddpi = driverdata->ddpi;
+ }
+ if (hdpi) {
+ *hdpi = driverdata->hdpi;
+ }
+ if (vdpi) {
+ *vdpi = driverdata->vdpi;
+ }
+
+ return driverdata->ddpi != 0.0f ? 0 : SDL_SetError("Couldn't get DPI");
+}
+
void
Wayland_VideoQuit(_THIS)
{
diff --git a/src/video/wayland/SDL_waylandvideo.h b/src/video/wayland/SDL_waylandvideo.h
index 91dac36..11f0e59 100644
--- a/src/video/wayland/SDL_waylandvideo.h
+++ b/src/video/wayland/SDL_waylandvideo.h
@@ -94,6 +94,8 @@ typedef struct {
struct wl_output *output;
float scale_factor;
int x, y, width, height, refresh, transform;
+ int physical_width, physical_height;
+ float ddpi, hdpi, vdpi;
SDL_VideoDisplay placeholder;
SDL_bool done;
} SDL_WaylandOutputData;